i386 + bcheck: fix __bound_local_new
With -b, this produces garbage. Code to call __bound_local_new is put at wrong place, overwriting the regparam setup code. Fix copied from x86_64-gen.c. void __attribute__((regparm(3))) fun(int unused) { char local[1]; }
This commit is contained in:
parent
3054a76249
commit
cdf715a0b5
2 changed files with 9 additions and 7 deletions
14
i386-gen.c
14
i386-gen.c
|
@ -107,6 +107,7 @@ static unsigned long func_sub_sp_offset;
|
||||||
static int func_ret_sub;
|
static int func_ret_sub;
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
static addr_t func_bound_offset;
|
static addr_t func_bound_offset;
|
||||||
|
static unsigned long func_bound_ind;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* XXX: make it faster ? */
|
/* XXX: make it faster ? */
|
||||||
|
@ -611,9 +612,10 @@ ST_FUNC void gfunc_prolog(CType *func_type)
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
/* leave some room for bound checking code */
|
/* leave some room for bound checking code */
|
||||||
if (tcc_state->do_bounds_check) {
|
if (tcc_state->do_bounds_check) {
|
||||||
|
func_bound_offset = lbounds_section->data_offset;
|
||||||
|
func_bound_ind = ind;
|
||||||
oad(0xb8, 0); /* lbound section pointer */
|
oad(0xb8, 0); /* lbound section pointer */
|
||||||
oad(0xb8, 0); /* call to function */
|
oad(0xb8, 0); /* call to function */
|
||||||
func_bound_offset = lbounds_section->data_offset;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -629,27 +631,27 @@ ST_FUNC void gfunc_epilog(void)
|
||||||
addr_t saved_ind;
|
addr_t saved_ind;
|
||||||
addr_t *bounds_ptr;
|
addr_t *bounds_ptr;
|
||||||
Sym *sym_data;
|
Sym *sym_data;
|
||||||
|
|
||||||
/* add end of table info */
|
/* add end of table info */
|
||||||
bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
|
bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
|
||||||
*bounds_ptr = 0;
|
*bounds_ptr = 0;
|
||||||
|
|
||||||
/* generate bound local allocation */
|
/* generate bound local allocation */
|
||||||
saved_ind = ind;
|
saved_ind = ind;
|
||||||
ind = func_sub_sp_offset;
|
ind = func_bound_ind;
|
||||||
sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
|
sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
|
||||||
func_bound_offset, lbounds_section->data_offset);
|
func_bound_offset, lbounds_section->data_offset);
|
||||||
greloc(cur_text_section, sym_data,
|
greloc(cur_text_section, sym_data,
|
||||||
ind + 1, R_386_32);
|
ind + 1, R_386_32);
|
||||||
oad(0xb8, 0); /* mov %eax, xxx */
|
oad(0xb8, 0); /* mov %eax, xxx */
|
||||||
gen_static_call(TOK___bound_local_new);
|
gen_static_call(TOK___bound_local_new);
|
||||||
|
|
||||||
ind = saved_ind;
|
ind = saved_ind;
|
||||||
|
|
||||||
/* generate bound check local freeing */
|
/* generate bound check local freeing */
|
||||||
o(0x5250); /* save returned value, if any */
|
o(0x5250); /* save returned value, if any */
|
||||||
greloc(cur_text_section, sym_data,
|
greloc(cur_text_section, sym_data, ind + 1, R_386_32);
|
||||||
ind + 1, R_386_32);
|
|
||||||
oad(0xb8, 0); /* mov %eax, xxx */
|
oad(0xb8, 0); /* mov %eax, xxx */
|
||||||
gen_static_call(TOK___bound_local_delete);
|
gen_static_call(TOK___bound_local_delete);
|
||||||
|
|
||||||
o(0x585a); /* restore returned value, if any */
|
o(0x585a); /* restore returned value, if any */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1658,7 +1658,7 @@ void gfunc_epilog(void)
|
||||||
o(0x5250); /* save returned value, if any */
|
o(0x5250); /* save returned value, if any */
|
||||||
greloc(cur_text_section, sym_data, ind + 1, R_386_32);
|
greloc(cur_text_section, sym_data, ind + 1, R_386_32);
|
||||||
oad(0xb8, 0); /* mov xxx, %rax */
|
oad(0xb8, 0); /* mov xxx, %rax */
|
||||||
o(0xc78948); /* mov %rax,%rdi ## first arg in %rdi, this must be ptr */
|
o(0xc78948); /* mov %rax,%rdi # first arg in %rdi, this must be ptr */
|
||||||
gen_static_call(TOK___bound_local_delete);
|
gen_static_call(TOK___bound_local_delete);
|
||||||
o(0x585a); /* restore returned value, if any */
|
o(0x585a); /* restore returned value, if any */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue