Fix bounds checking after concurrently commit

mob
herman ten brugge 2019-12-11 12:07:48 +01:00
parent 72729d8e36
commit a0bc149b0c
6 changed files with 31 additions and 31 deletions

View File

@ -1052,7 +1052,7 @@ ST_FUNC void ggoto(void)
/* bound check support functions */
#ifdef CONFIG_TCC_BCHECK
ST_FUNC void tcc_add_bcheck(TCCState *s1)
ST_FUNC void tcc_add_bcheck(TCCState *s1, Section *bound_sec, Section *sym_sec)
{
addr_t *ptr;
int loc_glob;
@ -1062,14 +1062,14 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1)
if (0 == s1->do_bounds_check)
return;
/* XXX: add an object file to do that */
ptr = section_ptr_add(bounds_section, sizeof(*ptr));
ptr = section_ptr_add(bound_sec, sizeof(*ptr));
*ptr = 0;
loc_glob = s1->output_type != TCC_OUTPUT_MEMORY ? STB_LOCAL : STB_GLOBAL;
bsym_index = set_elf_sym(symtab_section, 0, 0,
bsym_index = set_elf_sym(sym_sec, 0, 0,
ELFW(ST_INFO)(loc_glob, STT_NOTYPE), 0,
bounds_section->sh_num, "__bounds_start");
bound_sec->sh_num, "__bounds_start");
/* pull bcheck.o from libtcc1.a */
sym_index = set_elf_sym(symtab_section, 0, 0,
sym_index = set_elf_sym(sym_sec, 0, 0,
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
SHN_UNDEF, "__bound_init");
if (s1->output_type != TCC_OUTPUT_MEMORY) {
@ -1085,22 +1085,22 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1)
pinit = section_ptr_add(init_section, 5);
pinit[0] = 0xe8;
write32le(pinit + 1, -4);
put_elf_reloc(symtab_section, init_section,
put_elf_reloc(sym_sec, init_section,
init_section->data_offset - 4, R_386_PC32, sym_index);
/* R_386_PC32 = R_X86_64_PC32 = 2 */
pinit = section_ptr_add(init_section, 6);
pinit[0] = 0xb8; /* mov xx,%eax */
write32le(pinit + 1, 0);
pinit[5] = 0x50; /* push %eax */
put_elf_reloc(symtab_section, init_section,
put_elf_reloc(sym_sec, init_section,
init_section->data_offset - 5, R_386_32, bsym_index);
sym_index = set_elf_sym(symtab_section, 0, 0,
sym_index = set_elf_sym(sym_sec, 0, 0,
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
SHN_UNDEF, "__bounds_add_static_var");
pinit = section_ptr_add(init_section, 5);
pinit[0] = 0xe8;
write32le(pinit + 1, -4);
put_elf_reloc(symtab_section, init_section,
put_elf_reloc(sym_sec, init_section,
init_section->data_offset - 4, R_386_PC32, sym_index);
/* R_386_PC32 = R_X86_64_PC32 = 2 */
pinit = section_ptr_add(init_section, 3);
@ -1109,7 +1109,7 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1)
pinit[2] = 0x04;
#ifdef TCC_TARGET_PE
{
int init_index = set_elf_sym(symtab_section,
int init_index = set_elf_sym(sym_sec,
0, 0,
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
init_section->sh_num, "__init_start");

2
tcc.h
View File

@ -1249,7 +1249,7 @@ ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
#endif
ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
#ifdef CONFIG_TCC_BCHECK
ST_FUNC void tcc_add_bcheck(TCCState *s1);
ST_FUNC void tcc_add_bcheck(TCCState *s1, Section *bound_sec, Section *sym_sec);
#endif
ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);

View File

@ -1320,7 +1320,7 @@ ST_FUNC void tcc_add_runtime(TCCState *s1)
{
s1->filetype = 0;
#ifdef CONFIG_TCC_BCHECK
tcc_add_bcheck(s1);
tcc_add_bcheck(s1, bounds_section, symtab_section);
#endif
tcc_add_pragma_libs(s1);
#ifndef TCC_TARGET_PE

View File

@ -30,11 +30,14 @@ BTESTS = test1b test3b btest
# btest -- works on i386 (including win32)
# bounds-checking is supported only on i386
ifneq ($(ARCH),i386)
TESTS := $(filter-out $(BTESTS),$(TESTS))
ifeq ($(ARCH),i386)
TESTS += $(BTESTS)
endif
ifeq ($(ARCH),x86_64)
TESTS += $(BTESTS)
endif
ifdef CONFIG_WIN32
TESTS := $(filter-out $(BTESTS),$(TESTS))
TESTS += $(BTESTS)
endif
ifdef CONFIG_OSX # -run only
TESTS := hello-run libtest tests2-dir pp-dir
@ -158,7 +161,8 @@ BOUNDS_FAIL= 2 5 6 7 9 11 12 13 15 17
btest: boundtest.c
@echo ------------ $@ ------------
@for i in $(BOUNDS_OK); do \
@ulimit -c 0; \
for i in $(BOUNDS_OK); do \
echo ; echo --- boundtest $$i ---; \
if $(TCC) -b -run $< $$i ; then \
echo succeeded as expected; \

View File

@ -3886,11 +3886,9 @@ void builtin_frame_address_test(void)
printf("str: %s\n", str);
#ifndef __riscv
#ifndef __BOUNDS_CHECKING_ON
bfa1(str-fp0);
#endif
#endif
#endif
}
char via_volatile (char i)
@ -3966,12 +3964,11 @@ int force_get_order(unsigned long s)
return __get_order(s);
}
#define pv(m) printf(sizeof (s->m + 0) == 8 ? "%016lx\n" : "%02x\n", s->m)
#define pv(m) printf(sizeof (s->m + 0) == 8 ? "%016llx\n" : "%02x\n", s->m)
/* Test failed when using bounds checking */
void bounds_check1_test (void)
{
#ifndef __arm__ /* gcc bug om arm */
struct s {
int x;
long long y;
@ -3980,5 +3977,4 @@ void bounds_check1_test (void)
s->y = 20;
pv(x);
pv(y);
#endif
}

View File

@ -652,7 +652,7 @@ static void gen_bounds_call(int v)
#endif
}
ST_FUNC void tcc_add_bcheck(TCCState *s1)
ST_FUNC void tcc_add_bcheck(TCCState *s1, Section *bound_sec, Section *sym_sec)
{
addr_t *ptr;
int loc_glob;
@ -662,14 +662,14 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1)
if (0 == s1->do_bounds_check)
return;
/* XXX: add an object file to do that */
ptr = section_ptr_add(bounds_section, sizeof(*ptr));
ptr = section_ptr_add(bound_sec, sizeof(*ptr));
*ptr = 0;
loc_glob = s1->output_type != TCC_OUTPUT_MEMORY ? STB_LOCAL : STB_GLOBAL;
bsym_index = set_elf_sym(symtab_section, 0, 0,
bsym_index = set_elf_sym(sym_sec, 0, 0,
ELFW(ST_INFO)(loc_glob, STT_NOTYPE), 0,
bounds_section->sh_num, "__bounds_start");
bound_sec->sh_num, "__bounds_start");
/* pull bcheck.o from libtcc1.a */
sym_index = set_elf_sym(symtab_section, 0, 0,
sym_index = set_elf_sym(sym_sec, 0, 0,
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
SHN_UNDEF, "__bound_init");
if (s1->output_type != TCC_OUTPUT_MEMORY) {
@ -690,7 +690,7 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1)
pinit = section_ptr_add(init_section, 5);
pinit[0] = 0xe8;
write32le(pinit + 1, -4);
put_elf_reloc(symtab_section, init_section,
put_elf_reloc(sym_sec, init_section,
init_section->data_offset - 4, R_386_PC32, sym_index);
/* R_386_PC32 = R_X86_64_PC32 = 2 */
pinit = section_ptr_add(init_section, 13);
@ -706,20 +706,20 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1)
pinit[11] = 0x89;
pinit[12] = 0xc7;
#endif
put_elf_reloc(symtab_section, init_section,
put_elf_reloc(sym_sec, init_section,
init_section->data_offset - 11, R_X86_64_64, bsym_index);
sym_index = set_elf_sym(symtab_section, 0, 0,
sym_index = set_elf_sym(sym_sec, 0, 0,
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
SHN_UNDEF, "__bounds_add_static_var");
pinit = section_ptr_add(init_section, 5);
pinit[0] = 0xe8;
write32le(pinit + 1, -4);
put_elf_reloc(symtab_section, init_section,
put_elf_reloc(sym_sec, init_section,
init_section->data_offset - 4, R_386_PC32, sym_index);
/* R_386_PC32 = R_X86_64_PC32 = 2 */
#ifdef TCC_TARGET_PE
{
int init_index = set_elf_sym(symtab_section,
int init_index = set_elf_sym(sym_sec,
0, 0,
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
init_section->sh_num, "__init_start");