History

Undo part of incr_offset patch.

The incr_offset offset code was not working with bounds checking. So I reverted part of tccgen.c. See new test code 132. Also added some debugging code that prints location of bounds checking calls. Needed this to find the problem. See lib/bcheck.c, lib/bt-dll.c, lib/bt-exe.c, lib/bt-log.c, tccrun.c

herman ten brugge committed 3 years ago

Commit 598134f1 parent d1c10778 files · +96 −5Browse files

Showing the changes to lib (4 of 8 files). Show all

Unified · Split

4 files
  1. lib/bcheck.c +9 −1
  2. lib/bt-dll.c +1 −0
  3. lib/bt-exe.c +2 −0
  4. lib/bt-log.c +10 −0
lib/bcheck.c+9−1
@@ -41,7 +41,7 @@ · 40 unmodified lines
4141 #define BOUND_STATISTIC (1)
4242
4343 #if BOUND_DEBUG
44− #define dprintf(a...) if (print_calls) fprintf(a)
44+ #define dprintf(a...) if (print_calls) { bounds_loc; fprintf(a); }
4545 #else
4646 #define dprintf(a...)
4747 #endif
@@ -446,6 +446,7 @@ static unsigned long long bound_splay_delete; · 398 unmodified lines
446446 #endif
447447
448448 int tcc_backtrace(const char *fmt, ...);
449+void tcc_location(const char *fmt);
449450
450451 /* print a bound error message */
451452 #define bound_warning(...) \
@@ -462,6 +463,13 @@ int tcc_backtrace(const char *fmt, ...); · 10 unmodified lines
462463 exit(255); \
463464 } while (0)
464465
466+#define bounds_loc \
467+ do { \
468+ WAIT_SEM (); \
469+ tcc_location("^bcheck.c^"); \
470+ POST_SEM (); \
471+ } while (0)
472+
465473 static void bound_alloc_error(const char *s)
466474 {
467475 fprintf(stderr,"FATAL: %s\n",s);
lib/bt-dll.c+1−0
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 REDIR(__bt_init) \
99 REDIR(__bt_exit) \
1010 REDIR(tcc_backtrace) \
11+ REDIR(tcc_location) \
1112 \
1213 REDIR(__bound_ptr_add) \
1314 REDIR(__bound_ptr_indir1) \
lib/bt-exe.c+2−0
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 #include "../tccrun.c"
99
1010 int (*__rt_error)(void*, void*, const char *, va_list);
11+void (*__rt_location)(void*, void*, const char *);
1112 __attribute__((weak)) void __bound_checking_lock(void);
1213 __attribute__((weak)) void __bound_checking_unlock(void);
1314
@@ -33,6 +34,7 @@ void __bt_init(rt_context *p, int num_callers) · 19 unmodified lines
3334 rc->num_callers = num_callers - 1;
3435 rc->top_func = main;
3536 __rt_error = _rt_error;
37+ __rt_location = _rt_location;
3638 set_exception_handler();
3739 } else {
3840 p->next = rc->next, rc->next = p;
lib/bt-log.c+10−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
66 #include <string.h>
77
88 int (*__rt_error)(void*, void*, const char *, va_list);
9+void (*__rt_location)(void*, void*, const char *);
910
1011 #ifdef _WIN32
1112 # define DLL_EXPORT __declspec(dllexport)
@@ -42,6 +43,15 @@ DLL_EXPORT int tcc_backtrace(const char *fmt, ...) · 30 unmodified lines
4243 return ret;
4344 }
4445
46+DLL_EXPORT void tcc_location(const char *fmt)
47+{
48+ if (__rt_location) {
49+ void *fp = __builtin_frame_address(1);
50+ void *ip = __builtin_return_address(0);
51+ __rt_location(fp, ip, fmt);
52+ }
53+}
54+
4555 #if (defined(__GNUC__) && (__GNUC__ >= 6)) || defined(__clang__)
4656 #pragma GCC diagnostic pop
4757 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t