History

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]; }

Pavlas, Zdenek committed 10 years ago

Commit cdf715a1 parent 3054a762 files · +9 −7Browse files

Unified · Split

2 files
  1. i386-gen.c +8 −6
  2. x86_64-gen.c +1 −1
i386-gen.c+8−6
@@ -107,6 +107,7 @@ static unsigned long func_sub_sp_offset; · 106 unmodified lines
107107 static int func_ret_sub;
108108 #ifdef CONFIG_TCC_BCHECK
109109 static addr_t func_bound_offset;
110+static unsigned long func_bound_ind;
110111 #endif
111112
112113 /* XXX: make it faster ? */
@@ -611,9 +612,10 @@ ST_FUNC void gfunc_prolog(CType *func_type) · 498 unmodified lines
611612 #ifdef CONFIG_TCC_BCHECK
612613 /* leave some room for bound checking code */
613614 if (tcc_state->do_bounds_check) {
615+ func_bound_offset = lbounds_section->data_offset;
616+ func_bound_ind = ind;
614617 oad(0xb8, 0); /* lbound section pointer */
615618 oad(0xb8, 0); /* call to function */
616− func_bound_offset = lbounds_section->data_offset;
617619 }
618620 #endif
619621 }
@@ -629,27 +631,27 @@ ST_FUNC void gfunc_epilog(void) · 9 unmodified lines
629631 addr_t saved_ind;
630632 addr_t *bounds_ptr;
631633 Sym *sym_data;
634+
632635 /* add end of table info */
633636 bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
634637 *bounds_ptr = 0;
638+
635639 /* generate bound local allocation */
636640 saved_ind = ind;
637− ind = func_sub_sp_offset;
641+ ind = func_bound_ind;
638642 sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
639643 func_bound_offset, lbounds_section->data_offset);
640644 greloc(cur_text_section, sym_data,
641645 ind + 1, R_386_32);
642646 oad(0xb8, 0); /* mov %eax, xxx */
643647 gen_static_call(TOK___bound_local_new);
644−
645648 ind = saved_ind;
649+
646650 /* generate bound check local freeing */
647651 o(0x5250); /* save returned value, if any */
648− greloc(cur_text_section, sym_data,
649− ind + 1, R_386_32);
652+ greloc(cur_text_section, sym_data, ind + 1, R_386_32);
650653 oad(0xb8, 0); /* mov %eax, xxx */
651654 gen_static_call(TOK___bound_local_delete);
652−
653655 o(0x585a); /* restore returned value, if any */
654656 }
655657 #endif
x86_64-gen.c+1−1
@@ -1658,7 +1658,7 @@ void gfunc_epilog(void) · 1657 unmodified lines
16581658 o(0x5250); /* save returned value, if any */
16591659 greloc(cur_text_section, sym_data, ind + 1, R_386_32);
16601660 oad(0xb8, 0); /* mov xxx, %rax */
1661− o(0xc78948); /* mov %rax,%rdi ## first arg in %rdi, this must be ptr */
1661+ o(0xc78948); /* mov %rax,%rdi # first arg in %rdi, this must be ptr */
16621662 gen_static_call(TOK___bound_local_delete);
16631663 o(0x585a); /* restore returned value, if any */
16641664 }