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
1052/* bound check support functions */1052/* bound check support functions */
1053#ifdef CONFIG_TCC_BCHECK1053#ifdef CONFIG_TCC_BCHECK
1054 1054
1055ST_FUNC void tcc_add_bcheck(TCCState *s1)1055ST_FUNC void tcc_add_bcheck(TCCState *s1, Section *bound_sec, Section *sym_sec)
1056{1056{
1057 addr_t *ptr;1057 addr_t *ptr;
1058 int loc_glob;1058 int loc_glob;
@@ -1062,14 +1062,14 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 3 unmodified lines
1062 if (0 == s1->do_bounds_check)1062 if (0 == s1->do_bounds_check)
1063 return;1063 return;
1064 /* XXX: add an object file to do that */1064 /* 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));
1066 *ptr = 0;1066 *ptr = 0;
1067 loc_glob = s1->output_type != TCC_OUTPUT_MEMORY ? STB_LOCAL : STB_GLOBAL;1067 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,
1069 ELFW(ST_INFO)(loc_glob, STT_NOTYPE), 0,1069 ELFW(ST_INFO)(loc_glob, STT_NOTYPE), 0,
1070 bounds_section->sh_num, "__bounds_start");1070 bound_sec->sh_num, "__bounds_start");
1071 /* pull bcheck.o from libtcc1.a */1071 /* 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,
1073 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,1073 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
1074 SHN_UNDEF, "__bound_init");1074 SHN_UNDEF, "__bound_init");
1075 if (s1->output_type != TCC_OUTPUT_MEMORY) {1075 if (s1->output_type != TCC_OUTPUT_MEMORY) {
@@ -1085,22 +1085,22 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 9 unmodified lines
1085 pinit = section_ptr_add(init_section, 5);1085 pinit = section_ptr_add(init_section, 5);
1086 pinit[0] = 0xe8;1086 pinit[0] = 0xe8;
1087 write32le(pinit + 1, -4);1087 write32le(pinit + 1, -4);
1088 put_elf_reloc(symtab_section, init_section,1088 put_elf_reloc(sym_sec, init_section,
1089 init_section->data_offset - 4, R_386_PC32, sym_index);1089 init_section->data_offset - 4, R_386_PC32, sym_index);
1090 /* R_386_PC32 = R_X86_64_PC32 = 2 */1090 /* R_386_PC32 = R_X86_64_PC32 = 2 */
1091 pinit = section_ptr_add(init_section, 6);1091 pinit = section_ptr_add(init_section, 6);
1092 pinit[0] = 0xb8; /* mov xx,%eax */1092 pinit[0] = 0xb8; /* mov xx,%eax */
1093 write32le(pinit + 1, 0);1093 write32le(pinit + 1, 0);
1094 pinit[5] = 0x50; /* push %eax */1094 pinit[5] = 0x50; /* push %eax */
1095 put_elf_reloc(symtab_section, init_section,1095 put_elf_reloc(sym_sec, init_section,
1096 init_section->data_offset - 5, R_386_32, bsym_index);1096 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,
1098 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,1098 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
1099 SHN_UNDEF, "__bounds_add_static_var");1099 SHN_UNDEF, "__bounds_add_static_var");
1100 pinit = section_ptr_add(init_section, 5);1100 pinit = section_ptr_add(init_section, 5);
1101 pinit[0] = 0xe8;1101 pinit[0] = 0xe8;
1102 write32le(pinit + 1, -4);1102 write32le(pinit + 1, -4);
1103 put_elf_reloc(symtab_section, init_section,1103 put_elf_reloc(sym_sec, init_section,
1104 init_section->data_offset - 4, R_386_PC32, sym_index);1104 init_section->data_offset - 4, R_386_PC32, sym_index);
1105 /* R_386_PC32 = R_X86_64_PC32 = 2 */1105 /* R_386_PC32 = R_X86_64_PC32 = 2 */
1106 pinit = section_ptr_add(init_section, 3);1106 pinit = section_ptr_add(init_section, 3);
@@ -1109,7 +1109,7 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 2 unmodified lines
1109 pinit[2] = 0x04;1109 pinit[2] = 0x04;
1110#ifdef TCC_TARGET_PE1110#ifdef TCC_TARGET_PE
1111 {1111 {
1112 int init_index = set_elf_sym(symtab_section,1112 int init_index = set_elf_sym(sym_sec,
1113 0, 0,1113 0, 0,
1114 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,1114 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
1115 init_section->sh_num, "__init_start");1115 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
1249#endif1249#endif
1250ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);1250ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
1251#ifdef CONFIG_TCC_BCHECK1251#ifdef CONFIG_TCC_BCHECK
1252ST_FUNC void tcc_add_bcheck(TCCState *s1);1252ST_FUNC void tcc_add_bcheck(TCCState *s1, Section *bound_sec, Section *sym_sec);
1253#endif1253#endif
1254ST_FUNC void tcc_add_pragma_libs(TCCState *s1);1254ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
1255PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);1255PUB_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
1320{1320{
1321 s1->filetype = 0;1321 s1->filetype = 0;
1322#ifdef CONFIG_TCC_BCHECK1322#ifdef CONFIG_TCC_BCHECK
1323 tcc_add_bcheck(s1);1323 tcc_add_bcheck(s1, bounds_section, symtab_section);
1324#endif1324#endif
1325 tcc_add_pragma_libs(s1);1325 tcc_add_pragma_libs(s1);
1326#ifndef TCC_TARGET_PE1326#ifndef TCC_TARGET_PE
tests/Makefile+8−4
@@ -30,11 +30,14 @@ BTESTS = test1b test3b btest · 29 unmodified lines
30# btest -- works on i386 (including win32)30# btest -- works on i386 (including win32)
31 31
32# bounds-checking is supported only on i38632# bounds-checking is supported only on i386
33ifneq ($(ARCH),i386)33ifeq ($(ARCH),i386)
34 TESTS := $(filter-out $(BTESTS),$(TESTS))34 TESTS += $(BTESTS)
35endif
36ifeq ($(ARCH),x86_64)
37 TESTS += $(BTESTS)
35endif38endif
36ifdef CONFIG_WIN3239ifdef CONFIG_WIN32
37 TESTS := $(filter-out $(BTESTS),$(TESTS))40 TESTS += $(BTESTS)
38endif41endif
39ifdef CONFIG_OSX # -run only42ifdef CONFIG_OSX # -run only
40 TESTS := hello-run libtest tests2-dir pp-dir43 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
158 161
159btest: boundtest.c162btest: boundtest.c
160 @echo ------------ $@ ------------163 @echo ------------ $@ ------------
161 @for i in $(BOUNDS_OK); do \164 @ulimit -c 0; \
165 for i in $(BOUNDS_OK); do \
162 echo ; echo --- boundtest $$i ---; \166 echo ; echo --- boundtest $$i ---; \
163 if $(TCC) -b -run $< $$i ; then \167 if $(TCC) -b -run $< $$i ; then \
164 echo succeeded as expected; \168 echo succeeded as expected; \
tests/tcctest.c+1−5
@@ -3886,11 +3886,9 @@ void builtin_frame_address_test(void) · 3885 unmodified lines
3886 3886
3887 printf("str: %s\n", str);3887 printf("str: %s\n", str);
3888#ifndef __riscv3888#ifndef __riscv
3889#ifndef __BOUNDS_CHECKING_ON
3890 bfa1(str-fp0);3889 bfa1(str-fp0);
3891#endif3890#endif
3892#endif3891#endif
3893#endif
3894}3892}
3895 3893
3896char via_volatile (char i)3894char via_volatile (char i)
@@ -3966,12 +3964,11 @@ int force_get_order(unsigned long s) · 69 unmodified lines
3966 return __get_order(s);3964 return __get_order(s);
3967}3965}
3968 3966
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)
3970 3968
3971/* Test failed when using bounds checking */3969/* Test failed when using bounds checking */
3972void bounds_check1_test (void)3970void bounds_check1_test (void)
3973{3971{
3974#ifndef __arm__ /* gcc bug om arm */
3975 struct s {3972 struct s {
3976 int x;3973 int x;
3977 long long y;3974 long long y;
@@ -3980,5 +3977,4 @@ void bounds_check1_test (void) · 2 unmodified lines
3980 s->y = 20;3977 s->y = 20;
3981 pv(x);3978 pv(x);
3982 pv(y);3979 pv(y);
3983#endif
3984}3980}
x86_64-gen.c+10−10
@@ -652,7 +652,7 @@ static void gen_bounds_call(int v) · 651 unmodified lines
652#endif652#endif
653}653}
654 654
655ST_FUNC void tcc_add_bcheck(TCCState *s1)655ST_FUNC void tcc_add_bcheck(TCCState *s1, Section *bound_sec, Section *sym_sec)
656{656{
657 addr_t *ptr;657 addr_t *ptr;
658 int loc_glob;658 int loc_glob;
@@ -662,14 +662,14 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 3 unmodified lines
662 if (0 == s1->do_bounds_check)662 if (0 == s1->do_bounds_check)
663 return;663 return;
664 /* XXX: add an object file to do that */664 /* 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));
666 *ptr = 0;666 *ptr = 0;
667 loc_glob = s1->output_type != TCC_OUTPUT_MEMORY ? STB_LOCAL : STB_GLOBAL;667 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,
669 ELFW(ST_INFO)(loc_glob, STT_NOTYPE), 0,669 ELFW(ST_INFO)(loc_glob, STT_NOTYPE), 0,
670 bounds_section->sh_num, "__bounds_start");670 bound_sec->sh_num, "__bounds_start");
671 /* pull bcheck.o from libtcc1.a */671 /* 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,
673 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,673 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
674 SHN_UNDEF, "__bound_init");674 SHN_UNDEF, "__bound_init");
675 if (s1->output_type != TCC_OUTPUT_MEMORY) {675 if (s1->output_type != TCC_OUTPUT_MEMORY) {
@@ -690,7 +690,7 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 14 unmodified lines
690 pinit = section_ptr_add(init_section, 5);690 pinit = section_ptr_add(init_section, 5);
691 pinit[0] = 0xe8;691 pinit[0] = 0xe8;
692 write32le(pinit + 1, -4);692 write32le(pinit + 1, -4);
693 put_elf_reloc(symtab_section, init_section,693 put_elf_reloc(sym_sec, init_section,
694 init_section->data_offset - 4, R_386_PC32, sym_index);694 init_section->data_offset - 4, R_386_PC32, sym_index);
695 /* R_386_PC32 = R_X86_64_PC32 = 2 */695 /* R_386_PC32 = R_X86_64_PC32 = 2 */
696 pinit = section_ptr_add(init_section, 13);696 pinit = section_ptr_add(init_section, 13);
@@ -706,20 +706,20 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 9 unmodified lines
706 pinit[11] = 0x89;706 pinit[11] = 0x89;
707 pinit[12] = 0xc7;707 pinit[12] = 0xc7;
708#endif708#endif
709 put_elf_reloc(symtab_section, init_section,709 put_elf_reloc(sym_sec, init_section,
710 init_section->data_offset - 11, R_X86_64_64, bsym_index);710 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,
712 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,712 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
713 SHN_UNDEF, "__bounds_add_static_var");713 SHN_UNDEF, "__bounds_add_static_var");
714 pinit = section_ptr_add(init_section, 5);714 pinit = section_ptr_add(init_section, 5);
715 pinit[0] = 0xe8;715 pinit[0] = 0xe8;
716 write32le(pinit + 1, -4);716 write32le(pinit + 1, -4);
717 put_elf_reloc(symtab_section, init_section,717 put_elf_reloc(sym_sec, init_section,
718 init_section->data_offset - 4, R_386_PC32, sym_index);718 init_section->data_offset - 4, R_386_PC32, sym_index);
719 /* R_386_PC32 = R_X86_64_PC32 = 2 */719 /* R_386_PC32 = R_X86_64_PC32 = 2 */
720#ifdef TCC_TARGET_PE720#ifdef TCC_TARGET_PE
721 {721 {
722 int init_index = set_elf_sym(symtab_section,722 int init_index = set_elf_sym(sym_sec,
723 0, 0,723 0, 0,
724 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,724 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
725 init_section->sh_num, "__init_start");725 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