aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlas, Zdenek <zden3k@gmail.com>2016-11-09 00:22:28 -0800
committerPavlas, Zdenek <zden3k@gmail.com>2016-11-09 01:04:45 -0800
commitcdf715a0b5bf26f6e19dfd75fdbf23deffcc6d1c (patch)
treeecd3e75d051da8f5ba9b625ee24148fab4c22ba5
parent3054a76249d1f0690984027db73a94995300cac2 (diff)
downloadtinycc-cdf715a0b5bf26f6e19dfd75fdbf23deffcc6d1c.tar.gz
tinycc-cdf715a0b5bf26f6e19dfd75fdbf23deffcc6d1c.tar.bz2
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]; }
-rw-r--r--i386-gen.c14
-rw-r--r--x86_64-gen.c2
2 files changed, 9 insertions, 7 deletions
diff --git a/i386-gen.c b/i386-gen.c
index faac055..d9c4dde 100644
--- a/i386-gen.c
+++ b/i386-gen.c
@@ -107,6 +107,7 @@ static unsigned long func_sub_sp_offset;
static int func_ret_sub;
#ifdef CONFIG_TCC_BCHECK
static addr_t func_bound_offset;
+static unsigned long func_bound_ind;
#endif
/* XXX: make it faster ? */
@@ -611,9 +612,10 @@ ST_FUNC void gfunc_prolog(CType *func_type)
#ifdef CONFIG_TCC_BCHECK
/* leave some room for bound checking code */
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); /* call to function */
- func_bound_offset = lbounds_section->data_offset;
}
#endif
}
@@ -629,27 +631,27 @@ ST_FUNC void gfunc_epilog(void)
addr_t saved_ind;
addr_t *bounds_ptr;
Sym *sym_data;
+
/* add end of table info */
bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
*bounds_ptr = 0;
+
/* generate bound local allocation */
saved_ind = ind;
- ind = func_sub_sp_offset;
+ ind = func_bound_ind;
sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
func_bound_offset, lbounds_section->data_offset);
greloc(cur_text_section, sym_data,
ind + 1, R_386_32);
oad(0xb8, 0); /* mov %eax, xxx */
gen_static_call(TOK___bound_local_new);
-
ind = saved_ind;
+
/* generate bound check local freeing */
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 %eax, xxx */
gen_static_call(TOK___bound_local_delete);
-
o(0x585a); /* restore returned value, if any */
}
#endif
diff --git a/x86_64-gen.c b/x86_64-gen.c
index dd52e4a..a33bb48 100644
--- a/x86_64-gen.c
+++ b/x86_64-gen.c
@@ -1658,7 +1658,7 @@ void gfunc_epilog(void)
o(0x5250); /* save returned value, if any */
greloc(cur_text_section, sym_data, ind + 1, R_386_32);
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);
o(0x585a); /* restore returned value, if any */
}