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