From 02dc92c7309e295c75cc2a54b59a3b3d4b540e82 Mon Sep 17 00:00:00 2001 From: jakub Date: Mon, 18 Nov 2013 17:15:07 +0000 Subject: * elf.c (SHN_UNDEF): Define. (elf_initialize_syminfo): Add base_address argument. Ignore symbols with st_shndx == SHN_UNDEF. Add base_address to address fields. (elf_add): Adjust caller. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@204975 138bc75d-0d04-0410-961f-82ee72b054a4 --- libbacktrace/ChangeLog | 5 +++++ libbacktrace/elf.c | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'libbacktrace') diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index b7169da6108..c06194df3e4 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,5 +1,10 @@ 2013-11-18 Jakub Jelinek + * elf.c (SHN_UNDEF): Define. + (elf_initialize_syminfo): Add base_address argument. Ignore symbols + with st_shndx == SHN_UNDEF. Add base_address to address fields. + (elf_add): Adjust caller. + * elf.c (phdr_callback): Process info->dlpi_addr == 0 normally. 2013-11-16 Ian Lance Taylor diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c index 9a0fd70aed0..659b349f73b 100644 --- a/libbacktrace/elf.c +++ b/libbacktrace/elf.c @@ -98,6 +98,7 @@ dl_iterate_phdr (int (*callback) (struct dl_phdr_info *, #undef EV_CURRENT #undef SHN_LORESERVE #undef SHN_XINDEX +#undef SHN_UNDEF #undef SHT_SYMTAB #undef SHT_STRTAB #undef SHT_DYNSYM @@ -183,6 +184,7 @@ typedef struct { b_elf_wxword sh_entsize; /* Entry size if section holds table */ } b_elf_shdr; /* Elf_Shdr. */ +#define SHN_UNDEF 0x0000 /* Undefined section */ #define SHN_LORESERVE 0xFF00 /* Begin range of reserved indices */ #define SHN_XINDEX 0xFFFF /* Section index is held elsewhere */ @@ -342,6 +344,7 @@ elf_symbol_search (const void *vkey, const void *ventry) static int elf_initialize_syminfo (struct backtrace_state *state, + uintptr_t base_address, const unsigned char *symtab_data, size_t symtab_size, const unsigned char *strtab, size_t strtab_size, backtrace_error_callback error_callback, @@ -365,7 +368,8 @@ elf_initialize_syminfo (struct backtrace_state *state, int info; info = sym->st_info & 0xf; - if (info == STT_FUNC || info == STT_OBJECT) + if ((info == STT_FUNC || info == STT_OBJECT) + && sym->st_shndx != SHN_UNDEF) ++elf_symbol_count; } @@ -385,6 +389,8 @@ elf_initialize_syminfo (struct backtrace_state *state, info = sym->st_info & 0xf; if (info != STT_FUNC && info != STT_OBJECT) continue; + if (sym->st_shndx == SHN_UNDEF) + continue; if (sym->st_name >= strtab_size) { error_callback (data, "symbol string index out of range", 0); @@ -393,7 +399,7 @@ elf_initialize_syminfo (struct backtrace_state *state, return 0; } elf_symbols[j].name = (const char *) strtab + sym->st_name; - elf_symbols[j].address = sym->st_value; + elf_symbols[j].address = sym->st_value + base_address; elf_symbols[j].size = sym->st_size; ++j; } @@ -733,7 +739,7 @@ elf_add (struct backtrace_state *state, int descriptor, uintptr_t base_address, if (sdata == NULL) goto fail; - if (!elf_initialize_syminfo (state, + if (!elf_initialize_syminfo (state, base_address, symtab_view.data, symtab_shdr->sh_size, strtab_view.data, strtab_shdr->sh_size, error_callback, data, sdata)) -- cgit v1.2.3