History

Make tcc work after self-compiling with bounds-check enabled

For vstack Fabrice used the trick to initialize vtop to &vstack[-1], so that on first push, vtop becomes &vstack[0] and a value is also stored there - everything works. Except that when tcc is compiled with bounds-checking enabled, vstack - 1 returns INVALID_POINTER and oops... Let's workaround it with artificial 1 vstack slot which will not be used, but only serve as an indicator that pointing to &vstack[-1] is ok. Now, tcc, after being self-compiled with -b works: $ ./tcc -B. -o tccb -DONE_SOURCE -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" tcc.c -ldl $ cd tests $ ../tcc -B.. -run tcctest.c >1 $ ../tccb -B.. -run tcctest.c >2 $ diff -u 1 2 and note, tcc's compilation speed is not affected: $ ./tcc -B. -bench -DONE_SOURCE -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" -c tcc.c before: 8270 idents, 47221 lines, 1527730 bytes, 0.152 s, 309800 lines/s, 10.0 MB/s after: 8271 idents, 47221 lines, 1527733 bytes, 0.152 s, 310107 lines/s, 10.0 MB/s But note, that `tcc -b -run tcc` is still broken - for example it crashes on $ cat x.c double get100 () { return 100.0; } $ ./tcc -B. -b -DTCC_TARGET_I386 -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" -run \ -DONE_SOURCE ./tcc.c -B. -c x.c Runtime error: dereferencing invalid pointer ./tccpp.c:1953: at 0xa7beebdf parse_number() (included from ./libtcc.c, ./tcc.c) ./tccpp.c:3003: by 0xa7bf0708 next() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:4465: by 0xa7bfe348 block() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:4440: by 0xa7bfe212 block() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:5529: by 0xa7c01929 gen_function() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:5767: by 0xa7c02602 decl0() (included from ./libtcc.c, ./tcc.c) that's because lib/bcheck.c runtime needs more fixes -- see next patches.

Kirill Smelkov committed 13 years ago

Commit 43a11a71 parent 05b02a53 files · +3 −3Browse files

Unified · Split

3 files
  1. tcc.h +2 −1
  2. tccgen.c +1 −1
  3. tccpp.c +0 −1
tcc.h+2−1
@@ -1135,7 +1135,8 @@ ST_DATA Sym *local_label_stack; · 1134 unmodified lines
1135ST_DATA Sym *global_label_stack;1135ST_DATA Sym *global_label_stack;
1136ST_DATA Sym *define_stack;1136ST_DATA Sym *define_stack;
1137ST_DATA CType char_pointer_type, func_old_type, int_type, size_type;1137ST_DATA CType char_pointer_type, func_old_type, int_type, size_type;
1138ST_DATA SValue vstack[VSTACK_SIZE], *vtop;1138ST_DATA SValue __vstack[1+/*to make bcheck happy*/ VSTACK_SIZE], *vtop;
1139#define vstack (__vstack + 1)
1139ST_DATA int rsym, anon_sym, ind, loc;1140ST_DATA int rsym, anon_sym, ind, loc;
1140 1141
1141ST_DATA int const_wanted; /* true if constant wanted */1142ST_DATA int const_wanted; /* true if constant wanted */
tccgen.c+1−1
@@ -55,7 +55,7 @@ ST_DATA Sym *define_stack; · 54 unmodified lines
55ST_DATA Sym *global_label_stack;55ST_DATA Sym *global_label_stack;
56ST_DATA Sym *local_label_stack;56ST_DATA Sym *local_label_stack;
57 57
58ST_DATA SValue vstack[VSTACK_SIZE], *vtop;58ST_DATA SValue __vstack[1+VSTACK_SIZE], *vtop;
59 59
60ST_DATA int const_wanted; /* true if constant wanted */60ST_DATA int const_wanted; /* true if constant wanted */
61ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */61ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
tccpp.c+0−1
@@ -3041,7 +3041,6 @@ ST_FUNC void preprocess_init(TCCState *s1) · 3040 unmodified lines
3041 s1->ifdef_stack_ptr = s1->ifdef_stack;3041 s1->ifdef_stack_ptr = s1->ifdef_stack;
3042 file->ifdef_stack_ptr = s1->ifdef_stack_ptr;3042 file->ifdef_stack_ptr = s1->ifdef_stack_ptr;
3043 3043
3044 /* XXX: not ANSI compliant: bound checking says error */
3045 vtop = vstack - 1;3044 vtop = vstack - 1;
3046 s1->pack_stack[0] = 0;3045 s1->pack_stack[0] = 0;
3047 s1->pack_stack_ptr = s1->pack_stack;3046 s1->pack_stack_ptr = s1->pack_stack;

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