History

Fix bounds checking after concurrently commit

herman ten brugge committed 6 years ago

Commit a0bc1491 parent 72729d86 files · +31 −31Browse files

Unified · Split

6 files
  1. i386-gen.c +10 −10
  2. tcc.h +1 −1
  3. tccelf.c +1 −1
  4. tests/Makefile +8 −4
  5. tests/tcctest.c +1 −5
  6. x86_64-gen.c +10 −10
i386-gen.c+10−10
@@ -1052,7 +1052,7 @@ ST_FUNC void ggoto(void) · 1051 unmodified lines
10521052 /* bound check support functions */
10531053 #ifdef CONFIG_TCC_BCHECK
10541054
1055−ST_FUNC void tcc_add_bcheck(TCCState *s1)
1055+ST_FUNC void tcc_add_bcheck(TCCState *s1, Section *bound_sec, Section *sym_sec)
10561056 {
10571057 addr_t *ptr;
10581058 int loc_glob;
@@ -1062,14 +1062,14 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 3 unmodified lines
10621062 if (0 == s1->do_bounds_check)
10631063 return;
10641064 /* XXX: add an object file to do that */
1065− ptr = section_ptr_add(bounds_section, sizeof(*ptr));
1065+ ptr = section_ptr_add(bound_sec, sizeof(*ptr));
10661066 *ptr = 0;
10671067 loc_glob = s1->output_type != TCC_OUTPUT_MEMORY ? STB_LOCAL : STB_GLOBAL;
1068− bsym_index = set_elf_sym(symtab_section, 0, 0,
1068+ bsym_index = set_elf_sym(sym_sec, 0, 0,
10691069 ELFW(ST_INFO)(loc_glob, STT_NOTYPE), 0,
1070− bounds_section->sh_num, "__bounds_start");
1070+ bound_sec->sh_num, "__bounds_start");
10711071 /* pull bcheck.o from libtcc1.a */
1072− sym_index = set_elf_sym(symtab_section, 0, 0,
1072+ sym_index = set_elf_sym(sym_sec, 0, 0,
10731073 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
10741074 SHN_UNDEF, "__bound_init");
10751075 if (s1->output_type != TCC_OUTPUT_MEMORY) {
@@ -1085,22 +1085,22 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 9 unmodified lines
10851085 pinit = section_ptr_add(init_section, 5);
10861086 pinit[0] = 0xe8;
10871087 write32le(pinit + 1, -4);
1088− put_elf_reloc(symtab_section, init_section,
1088+ put_elf_reloc(sym_sec, init_section,
10891089 init_section->data_offset - 4, R_386_PC32, sym_index);
10901090 /* R_386_PC32 = R_X86_64_PC32 = 2 */
10911091 pinit = section_ptr_add(init_section, 6);
10921092 pinit[0] = 0xb8; /* mov xx,%eax */
10931093 write32le(pinit + 1, 0);
10941094 pinit[5] = 0x50; /* push %eax */
1095− put_elf_reloc(symtab_section, init_section,
1095+ put_elf_reloc(sym_sec, init_section,
10961096 init_section->data_offset - 5, R_386_32, bsym_index);
1097− sym_index = set_elf_sym(symtab_section, 0, 0,
1097+ sym_index = set_elf_sym(sym_sec, 0, 0,
10981098 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
10991099 SHN_UNDEF, "__bounds_add_static_var");
11001100 pinit = section_ptr_add(init_section, 5);
11011101 pinit[0] = 0xe8;
11021102 write32le(pinit + 1, -4);
1103− put_elf_reloc(symtab_section, init_section,
1103+ put_elf_reloc(sym_sec, init_section,
11041104 init_section->data_offset - 4, R_386_PC32, sym_index);
11051105 /* R_386_PC32 = R_X86_64_PC32 = 2 */
11061106 pinit = section_ptr_add(init_section, 3);
@@ -1109,7 +1109,7 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 2 unmodified lines
11091109 pinit[2] = 0x04;
11101110 #ifdef TCC_TARGET_PE
11111111 {
1112− int init_index = set_elf_sym(symtab_section,
1112+ int init_index = set_elf_sym(sym_sec,
11131113 0, 0,
11141114 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
11151115 init_section->sh_num, "__init_start");
tcc.h+1−1
@@ -1249,7 +1249,7 @@ ST_FUNC int tcc_add_crt(TCCState *s, const char *filename); · 1248 unmodified lines
12491249 #endif
12501250 ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
12511251 #ifdef CONFIG_TCC_BCHECK
1252−ST_FUNC void tcc_add_bcheck(TCCState *s1);
1252+ST_FUNC void tcc_add_bcheck(TCCState *s1, Section *bound_sec, Section *sym_sec);
12531253 #endif
12541254 ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
12551255 PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);
tccelf.c+1−1
@@ -1320,7 +1320,7 @@ ST_FUNC void tcc_add_runtime(TCCState *s1) · 1319 unmodified lines
13201320 {
13211321 s1->filetype = 0;
13221322 #ifdef CONFIG_TCC_BCHECK
1323− tcc_add_bcheck(s1);
1323+ tcc_add_bcheck(s1, bounds_section, symtab_section);
13241324 #endif
13251325 tcc_add_pragma_libs(s1);
13261326 #ifndef TCC_TARGET_PE
tests/Makefile+8−4
@@ -30,11 +30,14 @@ BTESTS = test1b test3b btest · 29 unmodified lines
3030 # btest -- works on i386 (including win32)
3131
3232 # bounds-checking is supported only on i386
33−ifneq ($(ARCH),i386)
34− TESTS := $(filter-out $(BTESTS),$(TESTS))
33+ifeq ($(ARCH),i386)
34+ TESTS += $(BTESTS)
35+endif
36+ifeq ($(ARCH),x86_64)
37+ TESTS += $(BTESTS)
3538 endif
3639 ifdef CONFIG_WIN32
37− TESTS := $(filter-out $(BTESTS),$(TESTS))
40+ TESTS += $(BTESTS)
3841 endif
3942 ifdef CONFIG_OSX # -run only
4043 TESTS := hello-run libtest tests2-dir pp-dir
@@ -158,7 +161,8 @@ BOUNDS_FAIL= 2 5 6 7 9 11 12 13 15 17 · 117 unmodified lines
158161
159162 btest: boundtest.c
160163 @echo ------------ $@ ------------
161− @for i in $(BOUNDS_OK); do \
164+ @ulimit -c 0; \
165+ for i in $(BOUNDS_OK); do \
162166 echo ; echo --- boundtest $$i ---; \
163167 if $(TCC) -b -run $< $$i ; then \
164168 echo succeeded as expected; \
tests/tcctest.c+1−5
@@ -3886,11 +3886,9 @@ void builtin_frame_address_test(void) · 3885 unmodified lines
38863886
38873887 printf("str: %s\n", str);
38883888 #ifndef __riscv
3889−#ifndef __BOUNDS_CHECKING_ON
38903889 bfa1(str-fp0);
38913890 #endif
38923891 #endif
3893−#endif
38943892 }
38953893
38963894 char via_volatile (char i)
@@ -3966,12 +3964,11 @@ int force_get_order(unsigned long s) · 69 unmodified lines
39663964 return __get_order(s);
39673965 }
39683966
3969−#define pv(m) printf(sizeof (s->m + 0) == 8 ? "%016lx\n" : "%02x\n", s->m)
3967+#define pv(m) printf(sizeof (s->m + 0) == 8 ? "%016llx\n" : "%02x\n", s->m)
39703968
39713969 /* Test failed when using bounds checking */
39723970 void bounds_check1_test (void)
39733971 {
3974−#ifndef __arm__ /* gcc bug om arm */
39753972 struct s {
39763973 int x;
39773974 long long y;
@@ -3980,5 +3977,4 @@ void bounds_check1_test (void) · 2 unmodified lines
39803977 s->y = 20;
39813978 pv(x);
39823979 pv(y);
3983−#endif
39843980 }
x86_64-gen.c+10−10
@@ -652,7 +652,7 @@ static void gen_bounds_call(int v) · 651 unmodified lines
652652 #endif
653653 }
654654
655−ST_FUNC void tcc_add_bcheck(TCCState *s1)
655+ST_FUNC void tcc_add_bcheck(TCCState *s1, Section *bound_sec, Section *sym_sec)
656656 {
657657 addr_t *ptr;
658658 int loc_glob;
@@ -662,14 +662,14 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 3 unmodified lines
662662 if (0 == s1->do_bounds_check)
663663 return;
664664 /* XXX: add an object file to do that */
665− ptr = section_ptr_add(bounds_section, sizeof(*ptr));
665+ ptr = section_ptr_add(bound_sec, sizeof(*ptr));
666666 *ptr = 0;
667667 loc_glob = s1->output_type != TCC_OUTPUT_MEMORY ? STB_LOCAL : STB_GLOBAL;
668− bsym_index = set_elf_sym(symtab_section, 0, 0,
668+ bsym_index = set_elf_sym(sym_sec, 0, 0,
669669 ELFW(ST_INFO)(loc_glob, STT_NOTYPE), 0,
670− bounds_section->sh_num, "__bounds_start");
670+ bound_sec->sh_num, "__bounds_start");
671671 /* pull bcheck.o from libtcc1.a */
672− sym_index = set_elf_sym(symtab_section, 0, 0,
672+ sym_index = set_elf_sym(sym_sec, 0, 0,
673673 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
674674 SHN_UNDEF, "__bound_init");
675675 if (s1->output_type != TCC_OUTPUT_MEMORY) {
@@ -690,7 +690,7 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 14 unmodified lines
690690 pinit = section_ptr_add(init_section, 5);
691691 pinit[0] = 0xe8;
692692 write32le(pinit + 1, -4);
693− put_elf_reloc(symtab_section, init_section,
693+ put_elf_reloc(sym_sec, init_section,
694694 init_section->data_offset - 4, R_386_PC32, sym_index);
695695 /* R_386_PC32 = R_X86_64_PC32 = 2 */
696696 pinit = section_ptr_add(init_section, 13);
@@ -706,20 +706,20 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 9 unmodified lines
706706 pinit[11] = 0x89;
707707 pinit[12] = 0xc7;
708708 #endif
709− put_elf_reloc(symtab_section, init_section,
709+ put_elf_reloc(sym_sec, init_section,
710710 init_section->data_offset - 11, R_X86_64_64, bsym_index);
711− sym_index = set_elf_sym(symtab_section, 0, 0,
711+ sym_index = set_elf_sym(sym_sec, 0, 0,
712712 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
713713 SHN_UNDEF, "__bounds_add_static_var");
714714 pinit = section_ptr_add(init_section, 5);
715715 pinit[0] = 0xe8;
716716 write32le(pinit + 1, -4);
717− put_elf_reloc(symtab_section, init_section,
717+ put_elf_reloc(sym_sec, init_section,
718718 init_section->data_offset - 4, R_386_PC32, sym_index);
719719 /* R_386_PC32 = R_X86_64_PC32 = 2 */
720720 #ifdef TCC_TARGET_PE
721721 {
722− int init_index = set_elf_sym(symtab_section,
722+ int init_index = set_elf_sym(sym_sec,
723723 0, 0,
724724 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
725725 init_section->sh_num, "__init_start");

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