mirror of
https://github.com/frida/tinycc
synced 2025-01-11 22:29:18 +03:00
tccgen.c: move 'alloca_used' complication to *-gen files
related to commit 8370bc03a1
This commit is contained in:
parent
8de7c092f0
commit
5bc1720776
13
i386-gen.c
13
i386-gen.c
@ -97,6 +97,7 @@ 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;
|
static unsigned long func_bound_ind;
|
||||||
|
static int func_bound_alloca_used;
|
||||||
static void gen_bounds_prolog(void);
|
static void gen_bounds_prolog(void);
|
||||||
static void gen_bounds_epilog(void);
|
static void gen_bounds_epilog(void);
|
||||||
#endif
|
#endif
|
||||||
@ -357,6 +358,10 @@ static void gcall_or_jmp(int is_jmp)
|
|||||||
/* constant and relocation case */
|
/* constant and relocation case */
|
||||||
greloc(cur_text_section, vtop->sym, ind + 1, R_386_PC32);
|
greloc(cur_text_section, vtop->sym, ind + 1, R_386_PC32);
|
||||||
oad(0xe8 + is_jmp, vtop->c.i - 4); /* call/jmp im */
|
oad(0xe8 + is_jmp, vtop->c.i - 4); /* call/jmp im */
|
||||||
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
|
if (tcc_state->do_bounds_check && vtop->sym->v == TOK_alloca)
|
||||||
|
func_bound_alloca_used = 1;
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* otherwise, indirect call */
|
/* otherwise, indirect call */
|
||||||
r = gv(RC_INT);
|
r = gv(RC_INT);
|
||||||
@ -588,9 +593,7 @@ ST_FUNC void gfunc_epilog(void)
|
|||||||
addr_t v, saved_ind;
|
addr_t v, saved_ind;
|
||||||
|
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
if (tcc_state->do_bounds_check &&
|
if (tcc_state->do_bounds_check)
|
||||||
(func_bound_offset != lbounds_section->data_offset ||
|
|
||||||
tcc_state->alloca_vla_used))
|
|
||||||
gen_bounds_epilog();
|
gen_bounds_epilog();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1068,6 +1071,7 @@ static void gen_bounds_prolog(void)
|
|||||||
/* leave some room for bound checking code */
|
/* leave some room for bound checking code */
|
||||||
func_bound_offset = lbounds_section->data_offset;
|
func_bound_offset = lbounds_section->data_offset;
|
||||||
func_bound_ind = ind;
|
func_bound_ind = ind;
|
||||||
|
func_bound_alloca_used = 0;
|
||||||
oad(0xb8, 0); /* lbound section pointer */
|
oad(0xb8, 0); /* lbound section pointer */
|
||||||
oad(0xb8, 0); /* call to function */
|
oad(0xb8, 0); /* call to function */
|
||||||
}
|
}
|
||||||
@ -1078,6 +1082,9 @@ static void gen_bounds_epilog(void)
|
|||||||
addr_t *bounds_ptr;
|
addr_t *bounds_ptr;
|
||||||
Sym *sym_data;
|
Sym *sym_data;
|
||||||
|
|
||||||
|
if (func_bound_offset == lbounds_section->data_offset && !func_bound_alloca_used)
|
||||||
|
return;
|
||||||
|
|
||||||
/* 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;
|
||||||
|
1
tcc.h
1
tcc.h
@ -838,7 +838,6 @@ struct TCCState {
|
|||||||
/* bound check related sections */
|
/* bound check related sections */
|
||||||
Section *bounds_section; /* contains global data bound description */
|
Section *bounds_section; /* contains global data bound description */
|
||||||
Section *lbounds_section; /* contains local data bound description */
|
Section *lbounds_section; /* contains local data bound description */
|
||||||
int alloca_vla_used;
|
|
||||||
#endif
|
#endif
|
||||||
/* symbol sections */
|
/* symbol sections */
|
||||||
Section *symtab_section;
|
Section *symtab_section;
|
||||||
|
11
tccgen.c
11
tccgen.c
@ -5914,11 +5914,6 @@ special_math_val:
|
|||||||
Sym *sa;
|
Sym *sa;
|
||||||
int nb_args, ret_nregs, ret_align, regsize, variadic;
|
int nb_args, ret_nregs, ret_align, regsize, variadic;
|
||||||
|
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
|
||||||
tcc_state->alloca_vla_used |= tcc_state->do_bounds_check &&
|
|
||||||
(vtop->r & VT_SYM) &&
|
|
||||||
vtop->sym->v == TOK_alloca;
|
|
||||||
#endif
|
|
||||||
/* function call */
|
/* function call */
|
||||||
if ((vtop->type.t & VT_BTYPE) != VT_FUNC) {
|
if ((vtop->type.t & VT_BTYPE) != VT_FUNC) {
|
||||||
/* pointer test (no array accepted) */
|
/* pointer test (no array accepted) */
|
||||||
@ -7913,9 +7908,6 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
|
|||||||
gen_vla_sp_save(addr);
|
gen_vla_sp_save(addr);
|
||||||
cur_scope->vla.loc = addr;
|
cur_scope->vla.loc = addr;
|
||||||
cur_scope->vla.num++;
|
cur_scope->vla.num++;
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
|
||||||
tcc_state->alloca_vla_used |= bcheck;
|
|
||||||
#endif
|
|
||||||
} else if (has_init) {
|
} else if (has_init) {
|
||||||
size_t oldreloc_offset = 0;
|
size_t oldreloc_offset = 0;
|
||||||
if (sec && sec->reloc)
|
if (sec && sec->reloc)
|
||||||
@ -7948,9 +7940,6 @@ static void gen_function(Sym *sym)
|
|||||||
cur_scope = root_scope = &f;
|
cur_scope = root_scope = &f;
|
||||||
|
|
||||||
nocode_wanted = 0;
|
nocode_wanted = 0;
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
|
||||||
tcc_state->alloca_vla_used = 0;
|
|
||||||
#endif
|
|
||||||
ind = cur_text_section->data_offset;
|
ind = cur_text_section->data_offset;
|
||||||
if (sym->a.aligned) {
|
if (sym->a.aligned) {
|
||||||
size_t newoff = section_add(cur_text_section, 0,
|
size_t newoff = section_add(cur_text_section, 0,
|
||||||
|
31
x86_64-gen.c
31
x86_64-gen.c
@ -146,6 +146,16 @@ ST_DATA const int reg_classes[NB_REGS] = {
|
|||||||
static unsigned long func_sub_sp_offset;
|
static unsigned long func_sub_sp_offset;
|
||||||
static int func_ret_sub;
|
static int func_ret_sub;
|
||||||
|
|
||||||
|
#if defined(CONFIG_TCC_BCHECK)
|
||||||
|
static addr_t func_bound_offset;
|
||||||
|
static unsigned long func_bound_ind;
|
||||||
|
static int func_bound_alloca_used;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TCC_TARGET_PE
|
||||||
|
static int func_scratch, func_alloca;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* XXX: make it faster ? */
|
/* XXX: make it faster ? */
|
||||||
ST_FUNC void g(int c)
|
ST_FUNC void g(int c)
|
||||||
{
|
{
|
||||||
@ -626,6 +636,10 @@ static void gcall_or_jmp(int is_jmp)
|
|||||||
greloca(cur_text_section, vtop->sym, ind + 1, R_X86_64_PLT32, (int)(vtop->c.i-4));
|
greloca(cur_text_section, vtop->sym, ind + 1, R_X86_64_PLT32, (int)(vtop->c.i-4));
|
||||||
#endif
|
#endif
|
||||||
oad(0xe8 + is_jmp, 0); /* call/jmp im */
|
oad(0xe8 + is_jmp, 0); /* call/jmp im */
|
||||||
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
|
if (tcc_state->do_bounds_check && vtop->sym->v == TOK_alloca)
|
||||||
|
func_bound_alloca_used = 1;
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* otherwise, indirect call */
|
/* otherwise, indirect call */
|
||||||
r = TREG_R11;
|
r = TREG_R11;
|
||||||
@ -637,8 +651,6 @@ static void gcall_or_jmp(int is_jmp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_TCC_BCHECK)
|
#if defined(CONFIG_TCC_BCHECK)
|
||||||
static addr_t func_bound_offset;
|
|
||||||
static unsigned long func_bound_ind;
|
|
||||||
|
|
||||||
static void gen_bounds_call(int v)
|
static void gen_bounds_call(int v)
|
||||||
{
|
{
|
||||||
@ -713,6 +725,7 @@ static void gen_bounds_prolog(void)
|
|||||||
/* leave some room for bound checking code */
|
/* leave some room for bound checking code */
|
||||||
func_bound_offset = lbounds_section->data_offset;
|
func_bound_offset = lbounds_section->data_offset;
|
||||||
func_bound_ind = ind;
|
func_bound_ind = ind;
|
||||||
|
func_bound_alloca_used = 0;
|
||||||
o(0xb848 + TREG_FASTCALL_1 * 0x100); /*lbound section pointer */
|
o(0xb848 + TREG_FASTCALL_1 * 0x100); /*lbound section pointer */
|
||||||
gen_le64 (0);
|
gen_le64 (0);
|
||||||
oad(0xb8, 0); /* call to function */
|
oad(0xb8, 0); /* call to function */
|
||||||
@ -724,6 +737,9 @@ static void gen_bounds_epilog(void)
|
|||||||
addr_t *bounds_ptr;
|
addr_t *bounds_ptr;
|
||||||
Sym *sym_data;
|
Sym *sym_data;
|
||||||
|
|
||||||
|
if (func_bound_offset == lbounds_section->data_offset && !func_bound_alloca_used)
|
||||||
|
return;
|
||||||
|
|
||||||
/* 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;
|
||||||
@ -750,8 +766,6 @@ static void gen_bounds_epilog(void)
|
|||||||
|
|
||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
|
|
||||||
static int func_scratch, func_alloca;
|
|
||||||
|
|
||||||
#define REGN 4
|
#define REGN 4
|
||||||
static const uint8_t arg_regs[REGN] = {
|
static const uint8_t arg_regs[REGN] = {
|
||||||
TREG_RCX, TREG_RDX, TREG_R8, TREG_R9
|
TREG_RCX, TREG_RDX, TREG_R8, TREG_R9
|
||||||
@ -948,7 +962,6 @@ void gfunc_call(int nb_args)
|
|||||||
if (tcc_state->do_bounds_check)
|
if (tcc_state->do_bounds_check)
|
||||||
gen_bounds_call(TOK___bound_alloca_nr); /* new region */
|
gen_bounds_call(TOK___bound_alloca_nr); /* new region */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
vtop--;
|
vtop--;
|
||||||
}
|
}
|
||||||
@ -1041,9 +1054,7 @@ void gfunc_epilog(void)
|
|||||||
loc = (loc & -16) - func_scratch;
|
loc = (loc & -16) - func_scratch;
|
||||||
|
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
if (tcc_state->do_bounds_check &&
|
if (tcc_state->do_bounds_check)
|
||||||
(func_bound_offset != lbounds_section->data_offset ||
|
|
||||||
tcc_state->alloca_vla_used))
|
|
||||||
gen_bounds_epilog();
|
gen_bounds_epilog();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1623,9 +1634,7 @@ void gfunc_epilog(void)
|
|||||||
int v, saved_ind;
|
int v, saved_ind;
|
||||||
|
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
if (tcc_state->do_bounds_check &&
|
if (tcc_state->do_bounds_check)
|
||||||
(func_bound_offset != lbounds_section->data_offset ||
|
|
||||||
tcc_state->alloca_vla_used))
|
|
||||||
gen_bounds_epilog();
|
gen_bounds_epilog();
|
||||||
#endif
|
#endif
|
||||||
o(0xc9); /* leave */
|
o(0xc9); /* leave */
|
||||||
|
Loading…
Reference in New Issue
Block a user