tcc failed to run with bounds checking enabled because the functions rt_wait_sem, rt_post_sem and _rt_error where defined twice. This is solved by making them weak in tccrun.c Also a nested lock was present when setting TCC_BOUNDS_PRINT_CALLS=1 This is solved in lib/bt-exe.c by moving lock/unlock code. Also added a testcase in tests/Makefile to test tcc with bounds checking enabled.
Showing the changes to lib (1 of 3 files). Show all
Unified · Split
| @@ -18,7 +18,6 @@ void __bt_init(rt_context *p, int is_exe) · 17 unmodified lines | ||
| 18 | 18 | __attribute__((weak)) int main(); |
| 19 | 19 | __attribute__((weak)) void __bound_init(void*, int); |
| 20 | 20 | |
| 21 | − WAIT_SEM(&rt_sem); | |
| 22 | 21 | //fprintf(stderr, "__bt_init %d %p %p %p\n", is_exe, p, p->stab_sym, p->bounds_start), fflush(stderr); |
| 23 | 22 | |
| 24 | 23 | /* call __bound_init here due to redirection of sigaction */ |
| @@ -27,13 +26,14 @@ void __bt_init(rt_context *p, int is_exe) · 2 unmodified lines | ||
| 27 | 26 | __bound_init(p->bounds_start, -1); |
| 28 | 27 | |
| 29 | 28 | /* add to chain */ |
| 29 | + WAIT_SEM(&rt_sem); | |
| 30 | 30 | p->next = g_rc, g_rc = p; |
| 31 | − if (is_exe) { | |
| 31 | + if (is_exe) | |
| 32 | 32 | /* we are the executable (not a dll) */ |
| 33 | 33 | p->top_func = main; |
| 34 | − set_exception_handler(); | |
| 35 | − } | |
| 36 | 34 | POST_SEM(&rt_sem); |
| 35 | + if (is_exe) | |
| 36 | + set_exception_handler(); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | __declspec(dllexport) |
| @@ -42,13 +42,13 @@ void __bt_exit(rt_context *p) · 2 unmodified lines | ||
| 42 | 42 | struct rt_context *rc, **pp; |
| 43 | 43 | __attribute__((weak)) void __bound_exit_dll(void*); |
| 44 | 44 | |
| 45 | − WAIT_SEM(&rt_sem); | |
| 46 | 45 | //fprintf(stderr, "__bt_exit %d %p\n", !!p->top_func, p); |
| 47 | 46 | |
| 48 | 47 | if (p->bounds_start) |
| 49 | 48 | __bound_exit_dll(p->bounds_start); |
| 50 | 49 | |
| 51 | 50 | /* remove from chain */ |
| 51 | + WAIT_SEM(&rt_sem); | |
| 52 | 52 | for (pp = &g_rc; rc = *pp, rc; pp = &rc->next) |
| 53 | 53 | if (rc == p) { |
| 54 | 54 | *pp = rc->next; |