Fix bounds checking without -run on macos

Update tccrun.c to detect rebase for dwarf debug info.
Enabled testcase 126 on macos.
Add prologue_end/epilogue_begin supoort in tcc.h, tccdbg.c, tccgen.c.
This commit is contained in:
herman ten brugge 2022-12-02 13:09:47 +01:00
parent ffbf6c26b2
commit 6b398686d6
5 changed files with 29 additions and 3 deletions

1
tcc.h
View file

@ -1795,6 +1795,7 @@ ST_FUNC void tcc_debug_putfile(TCCState *s1, const char *filename);
ST_FUNC void tcc_debug_line(TCCState *s1); ST_FUNC void tcc_debug_line(TCCState *s1);
ST_FUNC void tcc_add_debug_info(TCCState *s1, int param, Sym *s, Sym *e); ST_FUNC void tcc_add_debug_info(TCCState *s1, int param, Sym *s, Sym *e);
ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym); ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym);
ST_FUNC void tcc_debug_prolog_epilog(TCCState *s1, int value);
ST_FUNC void tcc_debug_funcend(TCCState *s1, int size); ST_FUNC void tcc_debug_funcend(TCCState *s1, int size);
ST_FUNC void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bind, int sym_type); ST_FUNC void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bind, int sym_type);
ST_FUNC void tcc_debug_typedef(TCCState *s1, Sym *sym); ST_FUNC void tcc_debug_typedef(TCCState *s1, Sym *sym);

View file

@ -971,6 +971,7 @@ ST_FUNC void tcc_debug_end(TCCState *s1)
tcc_free(dwarf_line.filename_table[i].name); tcc_free(dwarf_line.filename_table[i].name);
tcc_free(dwarf_line.filename_table); tcc_free(dwarf_line.filename_table);
dwarf_line_op(s1, DW_LNS_negate_stmt);
dwarf_line_op(s1, 0); // extended dwarf_line_op(s1, 0); // extended
dwarf_uleb128_op(s1, 1); // extended size dwarf_uleb128_op(s1, 1); // extended size
dwarf_line_op(s1, DW_LNE_end_sequence); dwarf_line_op(s1, DW_LNE_end_sequence);
@ -1827,7 +1828,9 @@ ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym)
if (s1->dwarf) { if (s1->dwarf) {
tcc_debug_line(s1); tcc_debug_line(s1);
dwarf_line_op(s1, DW_LNS_negate_stmt);
dwarf_line_op(s1, DW_LNS_copy); dwarf_line_op(s1, DW_LNS_copy);
dwarf_line_op(s1, DW_LNS_negate_stmt);
dwarf_info.func = sym; dwarf_info.func = sym;
dwarf_info.line = file->line_num; dwarf_info.line = file->line_num;
if (s1->do_backtrace) { if (s1->do_backtrace) {
@ -1852,6 +1855,16 @@ ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym)
} }
} }
ST_FUNC void tcc_debug_prolog_epilog(TCCState *s1, int value)
{
if (!s1->do_debug)
return;
if (s1->dwarf) {
dwarf_line_op(s1, value == 0 ? DW_LNS_set_prologue_end
: DW_LNS_set_epilogue_begin);
}
}
/* put function size */ /* put function size */
ST_FUNC void tcc_debug_funcend(TCCState *s1, int size) ST_FUNC void tcc_debug_funcend(TCCState *s1, int size)
{ {

View file

@ -8165,6 +8165,7 @@ static void gen_function(Sym *sym)
sym_push2(&local_stack, SYM_FIELD, 0, 0); sym_push2(&local_stack, SYM_FIELD, 0, 0);
local_scope = 1; /* for function parameters */ local_scope = 1; /* for function parameters */
gfunc_prolog(sym); gfunc_prolog(sym);
tcc_debug_prolog_epilog(tcc_state, 0);
local_scope = 0; local_scope = 0;
rsym = 0; rsym = 0;
clear_temp_local_var_list(); clear_temp_local_var_list();
@ -8174,6 +8175,7 @@ static void gen_function(Sym *sym)
nocode_wanted = 0; nocode_wanted = 0;
/* reset local stack */ /* reset local stack */
pop_local_syms(NULL, 0); pop_local_syms(NULL, 0);
tcc_debug_prolog_epilog(tcc_state, 1);
gfunc_epilog(); gfunc_epilog();
cur_text_section->data_offset = ind; cur_text_section->data_offset = ind;
local_scope = 0; local_scope = 0;

View file

@ -246,6 +246,11 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv)
rc->elf_str = (char *)symtab_section->link->data; rc->elf_str = (char *)symtab_section->link->data;
#if PTR_SIZE == 8 #if PTR_SIZE == 8
rc->prog_base = text_section->sh_addr & 0xffffffff00000000ULL; rc->prog_base = text_section->sh_addr & 0xffffffff00000000ULL;
#if defined TCC_TARGET_MACHO
if (s1->dwarf)
rc->prog_base = (addr_t) -1;
#else
#endif
#endif #endif
rc->top_func = tcc_get_symbol(s1, "main"); rc->top_func = tcc_get_symbol(s1, "main");
rc->num_callers = s1->rt_num_callers; rc->num_callers = s1->rt_num_callers;
@ -752,6 +757,9 @@ static addr_t rt_printline_dwarf (rt_context *rc, addr_t wanted_pc,
} filename_table[FILE_TABLE_SIZE]; } filename_table[FILE_TABLE_SIZE];
addr_t last_pc; addr_t last_pc;
addr_t pc; addr_t pc;
#if defined TCC_TARGET_MACHO
addr_t first_pc = 0;
#endif
addr_t func_addr; addr_t func_addr;
int line; int line;
char *filename; char *filename;
@ -910,6 +918,11 @@ check_pc:
pc = dwarf_read_4(cp, end); pc = dwarf_read_4(cp, end);
#else #else
pc = dwarf_read_8(cp, end); pc = dwarf_read_8(cp, end);
#endif
#if defined TCC_TARGET_MACHO
if (first_pc == 0 && rc->prog_base != (addr_t) -1)
first_pc += rc->prog_base - ((uint64_t)1 << 32);
pc += first_pc;
#endif #endif
opindex = 0; opindex = 0;
break; break;

View file

@ -58,9 +58,6 @@ ifneq (,$(filter OpenBSD FreeBSD NetBSD,$(TARGETOS)))
SKIP += 114_bound_signal.test # libc problem signal/fork SKIP += 114_bound_signal.test # libc problem signal/fork
SKIP += 116_bound_setjmp2.test # No TLS_FUNC/TLS_VAR in bcheck.c SKIP += 116_bound_setjmp2.test # No TLS_FUNC/TLS_VAR in bcheck.c
endif endif
ifneq (,$(filter Darwin,$(TARGETOS)))
SKIP += 126_bound_global.test # bt-exe.c problem on apple
endif
# Some tests might need arguments # Some tests might need arguments
ARGS = ARGS =