2020-01-17 21:58:39 +00:00
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
/* for linking rt_printline and the signal/exception handler
|
|
|
|
from tccrun.c into executables. */
|
|
|
|
|
|
|
|
#define CONFIG_TCC_BACKTRACE_ONLY
|
2023-03-31 16:20:49 +00:00
|
|
|
#define ONE_SOURCE 1
|
|
|
|
#define pstrcpy tcc_pstrcpy
|
2020-01-17 21:58:39 +00:00
|
|
|
#include "../tccrun.c"
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
# define __declspec(n)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__declspec(dllexport)
|
2024-02-11 12:13:13 +00:00
|
|
|
void __bt_init(rt_context *p, int is_exe)
|
2020-01-17 21:58:39 +00:00
|
|
|
{
|
|
|
|
__attribute__((weak)) int main();
|
2020-05-22 03:06:08 +00:00
|
|
|
__attribute__((weak)) void __bound_init(void*, int);
|
2024-02-11 12:13:13 +00:00
|
|
|
|
|
|
|
//fprintf(stderr, "__bt_init %d %p %p %p\n", is_exe, p, p->stab_sym, p->bounds_start), fflush(stderr);
|
|
|
|
|
Add dwarf support
The new gcc12 release does not support stabs any more.
This was a good reason to add support for dwarf.
The stabs code still works and is used if configure option --dwarf
is not used.
Tested on x86_64, i386, arm, arm64, riscv64 with dwarf-5.
Some debuggers may not support dwarf-5. Try using older dwarf versions
i that case.
The tccmacho.c code probably need some support for dwarf.
arm-gen.c, arm64-gen.c, i386-gen.c, riscv64-gen.c, x86_64-gen.
- fix get_sym_ref symbol size
arm-link.c, arm64-link.c, i386-link.c, riscv64-link.c, x86_64-link.c
- add R_DATA_32U
libtcc.c:
- parse -gdwarf option
tcc.c:
- add dwarf option
tcc.h:
- add dwarf option and sections
tccelf.c:
- init dwarf sections
- avoid adding sh_addr for dwarf sections
- remove dwarf relocs for output dll
- add dwarf sections for tccrun
tccgen.c:
- add dwarf defines + global data
- add dwarf_* functions
- mix dwarf code with stabs code
- a trick is used to emit function name in .debug_line section so
only this section has to be parsed instead of .debug_info and
.debug_abbrev.
- fix init debug_modes
tccrun.c:
- add dwarf sections in rt_context
- init them in tcc_run
- add new dwarf code rt_printline_dwarf to find file/function
dwarf.h:
- New file
tcc-doc.texi:
- document dwarf
configure:
- add dwarf option
lib/Makefile
- change -gstabs into -gdwarf
lib/bt-exe.c, tests/tests2/Makefile, tests/tests2/126_bound_global:
- Add __bound_init call
- Add new testcase to test it
2022-05-05 07:10:37 +00:00
|
|
|
/* call __bound_init here due to redirection of sigaction */
|
|
|
|
/* needed to add global symbols */
|
2024-02-11 12:13:13 +00:00
|
|
|
if (p->bounds_start)
|
Add dwarf support
The new gcc12 release does not support stabs any more.
This was a good reason to add support for dwarf.
The stabs code still works and is used if configure option --dwarf
is not used.
Tested on x86_64, i386, arm, arm64, riscv64 with dwarf-5.
Some debuggers may not support dwarf-5. Try using older dwarf versions
i that case.
The tccmacho.c code probably need some support for dwarf.
arm-gen.c, arm64-gen.c, i386-gen.c, riscv64-gen.c, x86_64-gen.
- fix get_sym_ref symbol size
arm-link.c, arm64-link.c, i386-link.c, riscv64-link.c, x86_64-link.c
- add R_DATA_32U
libtcc.c:
- parse -gdwarf option
tcc.c:
- add dwarf option
tcc.h:
- add dwarf option and sections
tccelf.c:
- init dwarf sections
- avoid adding sh_addr for dwarf sections
- remove dwarf relocs for output dll
- add dwarf sections for tccrun
tccgen.c:
- add dwarf defines + global data
- add dwarf_* functions
- mix dwarf code with stabs code
- a trick is used to emit function name in .debug_line section so
only this section has to be parsed instead of .debug_info and
.debug_abbrev.
- fix init debug_modes
tccrun.c:
- add dwarf sections in rt_context
- init them in tcc_run
- add new dwarf code rt_printline_dwarf to find file/function
dwarf.h:
- New file
tcc-doc.texi:
- document dwarf
configure:
- add dwarf option
lib/Makefile
- change -gstabs into -gdwarf
lib/bt-exe.c, tests/tests2/Makefile, tests/tests2/126_bound_global:
- Add __bound_init call
- Add new testcase to test it
2022-05-05 07:10:37 +00:00
|
|
|
__bound_init(p->bounds_start, -1);
|
2024-02-11 12:13:13 +00:00
|
|
|
|
|
|
|
/* add to chain */
|
2024-02-14 09:00:22 +00:00
|
|
|
rt_wait_sem();
|
2024-02-11 12:13:13 +00:00
|
|
|
p->next = g_rc, g_rc = p;
|
2024-02-14 09:00:22 +00:00
|
|
|
rt_post_sem();
|
|
|
|
if (is_exe) {
|
2024-02-11 12:13:13 +00:00
|
|
|
/* we are the executable (not a dll) */
|
|
|
|
p->top_func = main;
|
2024-02-15 06:17:15 +00:00
|
|
|
set_exception_handler();
|
2024-02-14 09:00:22 +00:00
|
|
|
}
|
2020-01-17 21:58:39 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 05:40:14 +00:00
|
|
|
__declspec(dllexport)
|
|
|
|
void __bt_exit(rt_context *p)
|
|
|
|
{
|
2024-02-11 12:13:13 +00:00
|
|
|
struct rt_context *rc, **pp;
|
2022-05-19 05:40:14 +00:00
|
|
|
__attribute__((weak)) void __bound_exit_dll(void*);
|
|
|
|
|
2024-02-11 12:13:13 +00:00
|
|
|
//fprintf(stderr, "__bt_exit %d %p\n", !!p->top_func, p);
|
|
|
|
|
2022-07-09 10:10:08 +00:00
|
|
|
if (p->bounds_start)
|
2024-02-11 12:13:13 +00:00
|
|
|
__bound_exit_dll(p->bounds_start);
|
|
|
|
|
|
|
|
/* remove from chain */
|
2024-02-14 09:00:22 +00:00
|
|
|
rt_wait_sem();
|
2024-02-11 12:13:13 +00:00
|
|
|
for (pp = &g_rc; rc = *pp, rc; pp = &rc->next)
|
|
|
|
if (rc == p) {
|
|
|
|
*pp = rc->next;
|
|
|
|
break;
|
|
|
|
}
|
2024-02-14 09:00:22 +00:00
|
|
|
rt_post_sem();
|
2022-05-19 05:40:14 +00:00
|
|
|
}
|
|
|
|
|
2020-01-17 21:58:39 +00:00
|
|
|
/* copy a string and truncate it. */
|
2022-05-09 15:02:09 +00:00
|
|
|
ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s)
|
2020-01-17 21:58:39 +00:00
|
|
|
{
|
|
|
|
int l = strlen(s);
|
|
|
|
if (l >= buf_size)
|
|
|
|
l = buf_size - 1;
|
|
|
|
memcpy(buf, s, l);
|
|
|
|
buf[l] = 0;
|
|
|
|
return buf;
|
|
|
|
}
|