tccdbg.c: new file

Better avoid global variables, at least in new code.

tccdbg.c hopefully should be logically identical to the
former parts in tccgen/elf.c (s1 tccstate added in some
places)

tccelf.c: dwarf linkage seems special per dwarf rather
than special per target.
This commit is contained in:
grischka 2022-05-09 17:02:09 +02:00
parent 56481d554f
commit 2caaff20fb
15 changed files with 2239 additions and 2123 deletions

View File

@ -183,7 +183,7 @@ endif
# include custom configuration (see make help)
-include config-extra.mak
CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccdbg.c tccelf.c tccasm.c tccrun.c
CORE_FILES += tcc.h config.h libtcc.h tcctok.h
i386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
i386-win32_FILES = $(i386_FILES) tccpe.c

View File

@ -4,7 +4,6 @@
/* relocation type for 32 bit data relocation */
#define R_DATA_32 R_ARM_ABS32
#define R_DATA_32U R_ARM_ABS32
#define R_DATA_PTR R_ARM_ABS32
#define R_JMP_SLOT R_ARM_JUMP_SLOT
#define R_GLOB_DAT R_ARM_GLOB_DAT

View File

@ -3,7 +3,6 @@
#define EM_TCC_TARGET EM_AARCH64
#define R_DATA_32 R_AARCH64_ABS32
#define R_DATA_32U R_AARCH64_ABS32
#define R_DATA_PTR R_AARCH64_ABS64
#define R_JMP_SLOT R_AARCH64_JUMP_SLOT
#define R_GLOB_DAT R_AARCH64_GLOB_DAT

View File

@ -4,7 +4,6 @@
/* relocation type for 32 bit data relocation */
#define R_DATA_32 R_C60_32
#define R_DATA_32U R_C60_32
#define R_DATA_PTR R_C60_32
#define R_JMP_SLOT R_C60_JMP_SLOT
#define R_GLOB_DAT R_C60_GLOB_DAT

2
configure vendored
View File

@ -489,6 +489,7 @@ echo "/* Automatically generated by configure - do not modify */" > $TMPH
print_inc CONFIG_SYSROOT "$sysroot"
test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR "$tccdir"
print_inc DWARF_VERSION "$dwarf" num
print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude"
print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
@ -497,7 +498,6 @@ print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
print_mak CONFIG_LDDIR "$tcc_lddir"
print_mak CONFIG_TRIPLET "$triplet"
print_mak TCC_CPU_VERSION "$cpuver" num
print_mak CONFIG_DWARF "$dwarf"
echo "ARCH=$cpu" >> config.mak
echo "TARGETOS=$targetos" >> config.mak

View File

@ -4,7 +4,6 @@
/* relocation type for 32 bit data relocation */
#define R_DATA_32 R_386_32
#define R_DATA_32U R_386_32
#define R_DATA_PTR R_386_32
#define R_JMP_SLOT R_386_JMP_SLOT
#define R_GLOB_DAT R_386_GLOB_DAT

View File

@ -3,6 +3,7 @@
from tccrun.c into executables. */
#define CONFIG_TCC_BACKTRACE_ONLY
#define ONE_SOURCE 0
#include "../tccrun.c"
int (*__rt_error)(void*, void*, const char *, va_list);
@ -35,7 +36,7 @@ void __bt_init(rt_context *p, int num_callers)
}
/* copy a string and truncate it. */
static char *pstrcpy(char *buf, size_t buf_size, const char *s)
ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s)
{
int l = strlen(s);
if (l >= buf_size)

View File

@ -21,6 +21,7 @@
#if !defined ONE_SOURCE || ONE_SOURCE
#include "tccpp.c"
#include "tccgen.c"
#include "tccdbg.c"
#include "tccasm.c"
#include "tccelf.c"
#include "tccrun.c"
@ -851,7 +852,7 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
/* free runtime memory */
tcc_run_free(s1);
#endif
tcc_free(s1->dState);
tcc_free(s1);
#ifdef MEM_DEBUG
if (0 == --nb_states)
@ -876,7 +877,7 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
#endif
if (s->do_debug) {
/* add debug sections */
tccelf_stab_new(s);
tcc_debug_new(s);
}
if (output_type == TCC_OUTPUT_OBJ) {
/* always elf for objects */
@ -1706,12 +1707,6 @@ static void args_parser_listfile(TCCState *s,
*pargc = s->argc = argc, *pargv = s->argv = argv;
}
#ifdef CONFIG_DWARF
#define DWARF_VERSION atoi(CONFIG_DWARF)
#else
#define DWARF_VERSION 0
#endif
PUB_FUNC int tcc_parse_args(TCCState *s, int *pargc, char ***pargv, int optind)
{
TCCState *s1 = s;
@ -1823,11 +1818,8 @@ reparse:
case TCC_OPTION_g:
s->do_debug = 1;
s->dwarf = DWARF_VERSION;
if (*optarg == 'd') {
s->dwarf = 5;
if (!strncmp(optarg,"dwarf-",6))
s->dwarf = atoi(optarg + 6);
}
if (strstart("dwarf-", &optarg))
s->dwarf = atoi(optarg);
break;
case TCC_OPTION_c:
x = TCC_OUTPUT_OBJ;

View File

@ -3,7 +3,6 @@
#define EM_TCC_TARGET EM_RISCV
#define R_DATA_32 R_RISCV_32
#define R_DATA_32U R_RISCV_32
#define R_DATA_PTR R_RISCV_64
#define R_JMP_SLOT R_RISCV_JUMP_SLOT
#define R_GLOB_DAT R_RISCV_64

98
tcc.h
View File

@ -899,10 +899,6 @@ struct TCCState {
Section **priv_sections;
int nb_priv_sections; /* number of private sections */
/* got & plt handling */
Section *got;
Section *plt;
/* predefined sections */
Section *text_section, *data_section, *rodata_section, *bss_section;
Section *common_section;
@ -912,10 +908,16 @@ struct TCCState {
Section *bounds_section; /* contains global data bound description */
Section *lbounds_section; /* contains local data bound description */
#endif
/* test coverage */
Section *tcov_section;
/* symbol sections */
/* symbol section */
Section *symtab_section;
/* temporary dynamic symbol sections (for dll loading) */
Section *dynsymtab_section;
/* exported dynamic symbol section */
Section *dynsym;
/* copy of the global symtab_section variable */
Section *symtab;
/* got & plt handling */
Section *got, *plt;
/* debug sections */
Section *stab_section;
Section *dwarf_info_section;
@ -924,15 +926,14 @@ struct TCCState {
Section *dwarf_aranges_section;
Section *dwarf_str_section;
Section *dwarf_line_str_section;
int dwlo, dwhi; /* dwarf section range */
/* test coverage */
Section *tcov_section;
/* debug state */
struct _tccdbg *dState;
/* Is there a new undefined sym since last new_undef_sym() */
int new_undef_sym;
/* temporary dynamic symbol sections (for dll loading) */
Section *dynsymtab_section;
/* exported dynamic symbol section */
Section *dynsym;
/* copy of the global symtab_section variable */
Section *symtab;
/* extra attributes (eg. GOT/PLT value) for symtab symbols */
struct sym_attr *sym_attrs;
int nb_sym_attrs;
@ -1400,14 +1401,9 @@ ST_DATA int global_expr; /* true if compound literals must be allocated globall
ST_DATA CType func_vt; /* current function return type (used by return instruction) */
ST_DATA int func_var; /* true if current function is variadic */
ST_DATA int func_vc;
ST_DATA int func_ind;
ST_DATA const char *funcname;
ST_FUNC void tcc_debug_start(TCCState *s1);
ST_FUNC void tcc_debug_end(TCCState *s1);
ST_FUNC void tcc_debug_bincl(TCCState *s1);
ST_FUNC void tcc_debug_eincl(TCCState *s1);
ST_FUNC void tcc_debug_putfile(TCCState *s1, const char *filename);
ST_FUNC void tccgen_init(TCCState *s1);
ST_FUNC int tccgen_compile(TCCState *s1);
ST_FUNC void tccgen_finish(TCCState *s1);
@ -1502,7 +1498,6 @@ typedef struct {
ST_FUNC void tccelf_new(TCCState *s);
ST_FUNC void tccelf_delete(TCCState *s);
ST_FUNC void tccelf_stab_new(TCCState *s);
ST_FUNC void tccelf_begin_file(TCCState *s1);
ST_FUNC void tccelf_end_file(TCCState *s1);
#ifdef CONFIG_TCC_BCHECK
@ -1522,10 +1517,6 @@ ST_FUNC int find_elf_sym(Section *s, const char *name);
ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, addr_t addend);
ST_FUNC void put_stabs(TCCState *s1, const char *str, int type, int other, int desc, unsigned long value);
ST_FUNC void put_stabs_r(TCCState *s1, const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index);
ST_FUNC void put_stabn(TCCState *s1, int type, int other, int desc, int value);
ST_FUNC void resolve_common_syms(TCCState *s1);
ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve);
ST_FUNC void relocate_sections(TCCState *s1);
@ -1781,6 +1772,54 @@ ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option);
ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename);
#endif
/* ------------ tccdbg.c ------------ */
ST_FUNC void tcc_debug_new(TCCState *s);
ST_FUNC void tcc_debug_start(TCCState *s1);
ST_FUNC void tcc_debug_end(TCCState *s1);
ST_FUNC void tcc_debug_bincl(TCCState *s1);
ST_FUNC void tcc_debug_eincl(TCCState *s1);
ST_FUNC void tcc_debug_putfile(TCCState *s1, const char *filename);
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_debug_funcstart(TCCState *s1, Sym *sym);
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_typedef(TCCState *s1, Sym *sym);
ST_FUNC void tcc_debug_stabn(TCCState *s1, int type, int value);
ST_FUNC void tcc_debug_fix_anon(TCCState *s1, CType *t);
ST_FUNC void tcc_tcov_start(TCCState *s1);
ST_FUNC void tcc_tcov_end(TCCState *s1);
ST_FUNC void tcc_tcov_check_line(TCCState *s1, int start);
ST_FUNC void tcc_tcov_block_end(TCCState *s1, int line);
ST_FUNC void tcc_tcov_block_begin(TCCState *s1);
ST_FUNC void tcc_tcov_reset_ind(TCCState *s1);
#define stab_section s1->stab_section
#define stabstr_section stab_section->link
#define tcov_section s1->tcov_section
#define dwarf_info_section s1->dwarf_info_section
#define dwarf_abbrev_section s1->dwarf_abbrev_section
#define dwarf_line_section s1->dwarf_line_section
#define dwarf_aranges_section s1->dwarf_aranges_section
#define dwarf_str_section s1->dwarf_str_section
#define dwarf_line_str_section s1->dwarf_line_str_section
#ifndef DWARF_VERSION
# define DWARF_VERSION 0
#endif
#if defined TCC_TARGET_PE
# define R_DATA_32DW 'Z' /* fake code to avoid DLL relocs */
#elif defined TCC_TARGET_X86_64
# define R_DATA_32DW R_X86_64_32
#else
# define R_DATA_32DW R_DATA_32
#endif
/********************************************************/
#if CONFIG_TCC_SEMLOCK
#if defined _WIN32
@ -1820,16 +1859,7 @@ ST_FUNC void post_sem(TCCSem *p);
#define cur_text_section TCC_STATE_VAR(cur_text_section)
#define bounds_section TCC_STATE_VAR(bounds_section)
#define lbounds_section TCC_STATE_VAR(lbounds_section)
#define tcov_section TCC_STATE_VAR(tcov_section)
#define symtab_section TCC_STATE_VAR(symtab_section)
#define stab_section TCC_STATE_VAR(stab_section)
#define stabstr_section stab_section->link
#define dwarf_info_section TCC_STATE_VAR(dwarf_info_section)
#define dwarf_abbrev_section TCC_STATE_VAR(dwarf_abbrev_section)
#define dwarf_line_section TCC_STATE_VAR(dwarf_line_section)
#define dwarf_aranges_section TCC_STATE_VAR(dwarf_aranges_section)
#define dwarf_str_section TCC_STATE_VAR(dwarf_str_section)
#define dwarf_line_str_section TCC_STATE_VAR(dwarf_line_str_section)
#define gnu_ext TCC_STATE_VAR(gnu_ext)
#define tcc_error_noabort TCC_SET_STATE(_tcc_error_noabort)
#define tcc_error TCC_SET_STATE(_tcc_error)

2088
tccdbg.c Normal file

File diff suppressed because it is too large Load Diff

139
tccelf.c
View File

@ -47,8 +47,6 @@ struct sym_version {
/* section is dynsymtab_section */
#define SHF_DYNSYM 0x40000000
#define DWARF_DEBUG(s) (!strncmp((s), ".debug_", sizeof(".debug_")-1))
/* ------------------------------------------------------------------------- */
ST_FUNC void tccelf_new(TCCState *s)
@ -95,50 +93,6 @@ ST_FUNC void tccelf_bounds_new(TCCState *s)
}
#endif
ST_FUNC void tccelf_stab_new(TCCState *s)
{
TCCState *s1 = s;
int shf = 0;
#ifdef CONFIG_TCC_BACKTRACE
/* include stab info with standalone backtrace support */
if (s->do_backtrace && s->output_type != TCC_OUTPUT_MEMORY)
shf = SHF_ALLOC | SHF_WRITE; // SHF_WRITE needed for musl/SELINUX
#endif
if (s->dwarf) {
dwarf_info_section =
new_section(s, ".debug_info", SHT_PROGBITS, shf);
dwarf_abbrev_section =
new_section(s, ".debug_abbrev", SHT_PROGBITS, shf);
dwarf_line_section =
new_section(s, ".debug_line", SHT_PROGBITS, shf);
dwarf_aranges_section =
new_section(s, ".debug_aranges", SHT_PROGBITS, shf);
shf |= SHF_MERGE | SHF_STRINGS;
dwarf_str_section =
new_section(s, ".debug_str", SHT_PROGBITS, shf);
dwarf_str_section->sh_entsize = 1;
dwarf_info_section->sh_addralign =
dwarf_abbrev_section->sh_addralign =
dwarf_line_section->sh_addralign =
dwarf_aranges_section->sh_addralign =
dwarf_str_section->sh_addralign = 1;
if (s1->dwarf >= 5) {
dwarf_line_str_section =
new_section(s, ".debug_line_str", SHT_PROGBITS, shf);
dwarf_line_str_section->sh_entsize = 1;
dwarf_line_str_section->sh_addralign = 1;
}
}
else {
stab_section = new_section(s, ".stab", SHT_PROGBITS, shf);
stab_section->sh_entsize = sizeof(Stab_Sym);
stab_section->sh_addralign = sizeof ((Stab_Sym*)0)->n_value;
stab_section->link = new_section(s, ".stabstr", SHT_STRTAB, shf);
/* put first entry */
put_stabs(s, "", 0, 0, 0, 0);
}
}
static void free_section(Section *s)
{
tcc_free(s->data);
@ -710,7 +664,6 @@ ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size,
}
esym->st_other = (esym->st_other & ~ELFW(ST_VISIBILITY)(-1))
| new_vis;
other = esym->st_other; /* in case we have to patch esym */
if (shndx == SHN_UNDEF) {
/* ignore adding of undefined symbol if the
corresponding symbol is already defined */
@ -745,13 +698,13 @@ ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size,
tcc_error_noabort("'%s' defined twice", name);
}
} else {
esym->st_other = other;
do_patch:
esym->st_info = ELFW(ST_INFO)(sym_bind, sym_type);
esym->st_shndx = shndx;
s1->new_undef_sym = 1;
esym->st_value = value;
esym->st_size = size;
esym->st_other = other;
}
} else {
do_def:
@ -799,50 +752,6 @@ ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
put_elf_reloca(symtab, s, offset, type, symbol, 0);
}
/* put stab debug information */
ST_FUNC void put_stabs(TCCState *s1, const char *str, int type, int other, int desc,
unsigned long value)
{
Stab_Sym *sym;
unsigned offset;
if (type == N_SLINE
&& (offset = stab_section->data_offset)
&& (sym = (Stab_Sym*)(stab_section->data + offset) - 1)
&& sym->n_type == type
&& sym->n_value == value) {
/* just update line_number in previous entry */
sym->n_desc = desc;
return;
}
sym = section_ptr_add(stab_section, sizeof(Stab_Sym));
if (str) {
sym->n_strx = put_elf_str(stab_section->link, str);
} else {
sym->n_strx = 0;
}
sym->n_type = type;
sym->n_other = other;
sym->n_desc = desc;
sym->n_value = value;
}
ST_FUNC void put_stabs_r(TCCState *s1, const char *str, int type, int other, int desc,
unsigned long value, Section *sec, int sym_index)
{
put_elf_reloc(symtab_section, stab_section,
stab_section->data_offset + 8,
sizeof ((Stab_Sym*)0)->n_value == PTR_SIZE ? R_DATA_PTR : R_DATA_32,
sym_index);
put_stabs(s1, str, type, other, desc, value);
}
ST_FUNC void put_stabn(TCCState *s1, int type, int other, int desc, int value)
{
put_stabs(s1, NULL, type, other, desc, value);
}
ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc)
{
int n;
@ -973,10 +882,8 @@ ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve)
sym->st_value = 0;
else
tcc_error_noabort("undefined symbol '%s'", name);
} else if (sh_num < SHN_LORESERVE &&
/* Debug dwarf relocations must be relative to start section.
This only happens when backtrace is used. */
(sym->st_name || !DWARF_DEBUG(s1->sections[sym->st_shndx]->name))) {
} else if (sh_num < SHN_LORESERVE) {
/* add section base */
sym->st_value += s1->sections[sym->st_shndx]->sh_addr;
}
@ -993,6 +900,7 @@ static void relocate_section(TCCState *s1, Section *s, Section *sr)
int type, sym_index;
unsigned char *ptr;
addr_t tgt, addr;
int is_dwarf = s->sh_num >= s1->dwlo && s->sh_num < s1->dwhi;
qrel = (ElfW_Rel *)sr->data;
for_each_elem(sr, 0, rel, ElfW_Rel) {
@ -1004,6 +912,12 @@ static void relocate_section(TCCState *s1, Section *s, Section *sr)
#if SHT_RELX == SHT_RELA
tgt += rel->r_addend;
#endif
if (is_dwarf && type == R_DATA_32DW
&& sym->st_shndx >= s1->dwlo && sym->st_shndx < s1->dwhi) {
/* dwarf section relocation to each other */
add32le(ptr, tgt - s1->sections[sym->st_shndx]->sh_addr);
continue;
}
addr = s->sh_addr + rel->r_offset;
relocate(s1, rel, type, ptr, addr, tgt);
}
@ -1362,7 +1276,7 @@ ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, addr_t
if (sec && offs == -1)
offs = sec->data_offset;
return set_elf_sym(symtab_section, offs, 0,
ELFW(ST_INFO)(name && !strstr(name, "__dwarf") ? STB_GLOBAL : STB_LOCAL, STT_NOTYPE), 0, shn, name);
ELFW(ST_INFO)(name ? STB_GLOBAL : STB_LOCAL, STT_NOTYPE), 0, shn, name);
}
static void add_init_array_defines(TCCState *s1, const char *section_name)
@ -1440,10 +1354,10 @@ static void tcc_compile_string_no_debug(TCCState *s, const char *str)
}
#ifdef CONFIG_TCC_BACKTRACE
static void put_ptr(TCCState *s1, Section *s, int offs, const char *name)
static void put_ptr(TCCState *s1, Section *s, int offs)
{
int c;
c = set_global_sym(s1, name, s, offs);
c = set_global_sym(s1, NULL, s, offs);
s = data_section;
put_elf_reloc (s1->symtab, s, s->data_offset, R_DATA_PTR, c);
section_ptr_add(s, PTR_SIZE);
@ -1461,28 +1375,29 @@ ST_FUNC void tcc_add_btstub(TCCState *s1)
o = s->data_offset;
/* create (part of) a struct rt_context (see tccrun.c) */
if (s1->dwarf) {
put_ptr(s1, dwarf_line_section, 0, "__dwarf_line");
put_ptr(s1, dwarf_line_section, -1, "__dwarf_line_end");
put_ptr(s1, dwarf_line_section, 0);
put_ptr(s1, dwarf_line_section, -1);
if (s1->dwarf >= 5)
put_ptr(s1, dwarf_line_str_section, 0, "__dwarf_line_str");
put_ptr(s1, dwarf_line_str_section, 0);
else
put_ptr(s1, dwarf_str_section, 0, "__dwarf_str");
put_ptr(s1, text_section, 0, "__dwarf_text");
put_ptr(s1, dwarf_str_section, 0);
put_ptr(s1, text_section, 0);
}
else {
put_ptr(s1, stab_section, 0, NULL);
put_ptr(s1, stab_section, -1, NULL);
put_ptr(s1, stab_section->link, 0, NULL);
else
{
put_ptr(s1, stab_section, 0);
put_ptr(s1, stab_section, -1);
put_ptr(s1, stab_section->link, 0);
section_ptr_add(s, PTR_SIZE);
}
/* skip esym_start/esym_end/elf_str (not loaded) */
section_ptr_add(s, 3 * PTR_SIZE);
/* prog_base : local nameless symbol with offset 0 at SHN_ABS */
put_ptr(s1, NULL, 0, NULL);
put_ptr(s1, NULL, 0);
n = 2 * PTR_SIZE;
#ifdef CONFIG_TCC_BCHECK
if (s1->do_bounds_check) {
put_ptr(s1, bounds_section, 0, NULL);
put_ptr(s1, bounds_section, 0);
n -= PTR_SIZE;
}
#endif
@ -1906,8 +1821,6 @@ static int set_sec_sizes(TCCState *s1)
/* when generating a DLL, we include relocations but
we may patch them */
if (file_type == TCC_OUTPUT_DLL
/* Do not include dwarf relocatable sections. */
&& !DWARF_DEBUG(s1->sections[s->sh_info]->name)
&& (s1->sections[s->sh_info]->sh_flags & SHF_ALLOC)) {
int count = prepare_dynamic_rel(s1, s);
if (count) {
@ -3022,7 +2935,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1,
strcmp(strsec + sh->sh_name, ".stabstr")
)
continue;
if (seencompressed && DWARF_DEBUG(strsec + sh->sh_name))
if (seencompressed && 0 == strncmp(strsec + sh->sh_name, ".debug_", 7))
continue;
sh = &shdr[i];

1939
tccgen.c

File diff suppressed because it is too large Load Diff

View File

@ -180,10 +180,12 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv)
if (s1->dwarf) {
rc->dwarf_line = dwarf_line_section->data;
rc->dwarf_line_end = dwarf_line_section->data + dwarf_line_section->data_offset;
rc->dwarf_line_str = dwarf_line_str_section->data;
if (dwarf_line_str_section)
rc->dwarf_line_str = dwarf_line_str_section->data;
rc->dwarf_text = text_section->sh_addr;
}
else {
else
{
rc->stab_sym = (Stab_Sym *)stab_section->data;
rc->stab_sym_end = (Stab_Sym *)(stab_section->data + stab_section->data_offset);
rc->stab_str = (char *)stab_section->link->data;
@ -443,6 +445,21 @@ static int rt_printf(const char *fmt, ...)
return r;
}
static char *rt_elfsym(rt_context *rc, addr_t wanted_pc, addr_t *func_addr)
{
ElfW(Sym) *esym;
for (esym = rc->esym_start + 1; esym < rc->esym_end; ++esym) {
int type = ELFW(ST_TYPE)(esym->st_info);
if ((type == STT_FUNC || type == STT_GNU_IFUNC)
&& wanted_pc >= esym->st_value
&& wanted_pc < esym->st_value + esym->st_size) {
*func_addr = esym->st_value;
return rc->elf_str + esym->st_name;
}
}
return NULL;
}
#define INCLUDE_STACK_SIZE 32
/* print the position in the source file of PC value 'pc' by reading
@ -455,7 +472,6 @@ static addr_t rt_printline (rt_context *rc, addr_t wanted_pc,
const char *incl_files[INCLUDE_STACK_SIZE];
int incl_index, last_incl_index, len, last_line_num, i;
const char *str, *p;
ElfW(Sym) *esym;
Stab_Sym *sym;
next:
@ -545,24 +561,14 @@ next:
func_name[0] = '\0';
func_addr = 0;
last_incl_index = 0;
/* we try symtab symbols (no line number info) */
for (esym = rc->esym_start + 1; esym < rc->esym_end; ++esym) {
int type = ELFW(ST_TYPE)(esym->st_info);
if (type == STT_FUNC || type == STT_GNU_IFUNC) {
if (wanted_pc >= esym->st_value &&
wanted_pc < esym->st_value + esym->st_size) {
pstrcpy(func_name, sizeof(func_name),
rc->elf_str + esym->st_name);
func_addr = esym->st_value;
goto found;
}
}
p = rt_elfsym(rc, wanted_pc, &func_addr);
if (p) {
pstrcpy(func_name, sizeof func_name, p);
goto found;
}
if ((rc = rc->next))
goto next;
found:
i = last_incl_index;
if (i > 0) {
@ -588,6 +594,9 @@ found:
return func_addr;
}
/* ------------------------------------------------------------- */
/* rt_printline - dwarf version */
#define MAX_128 ((8 * sizeof (long long) + 6) / 7)
#define DIR_TABLE_SIZE (64)
@ -689,7 +698,6 @@ static addr_t rt_printline_dwarf (rt_context *rc, addr_t wanted_pc,
int line;
char *filename;
char *function;
ElfW(Sym) *esym;
next:
ln = rc->dwarf_line;
@ -698,7 +706,7 @@ next:
filename_size = 0;
last_pc = 0;
pc = 0;
func_addr = -1;
func_addr = 0;
line = 1;
filename = NULL;
function = NULL;
@ -922,25 +930,13 @@ next_line:
}
filename = NULL;
function = NULL;
func_addr = -1;
func_addr = 0;
/* we try symtab symbols (no line number info) */
for (esym = rc->esym_start + 1; esym < rc->esym_end; ++esym) {
int type = ELFW(ST_TYPE)(esym->st_info);
if (type == STT_FUNC || type == STT_GNU_IFUNC) {
if (wanted_pc >= esym->st_value &&
wanted_pc < esym->st_value + esym->st_size) {
function = rc->elf_str + esym->st_name;
func_addr = esym->st_value;
goto found;
}
}
}
function = rt_elfsym(rc, wanted_pc, &func_addr);
if (function)
goto found;
if ((rc = rc->next))
goto next;
found:
if (filename) {
if (skip[0] && strstr(filename, skip))
@ -952,6 +948,7 @@ found:
rt_printf("%s %s", msg, function ? function : "???");
return (addr_t)func_addr;
}
/* ------------------------------------------------------------- */
static int rt_get_caller_pc(addr_t *paddr, rt_context *rc, int level);

View File

@ -4,7 +4,6 @@
/* relocation type for 32 bit data relocation */
#define R_DATA_32 R_X86_64_32S
#define R_DATA_32U R_X86_64_32
#define R_DATA_PTR R_X86_64_64
#define R_JMP_SLOT R_X86_64_JUMP_SLOT
#define R_GLOB_DAT R_X86_64_GLOB_DAT