summaryrefslogtreecommitdiff
path: root/libdwfl/dwfl_module_addrsym.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdwfl/dwfl_module_addrsym.c')
-rw-r--r--libdwfl/dwfl_module_addrsym.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/libdwfl/dwfl_module_addrsym.c b/libdwfl/dwfl_module_addrsym.c
index 732b6983..3d199437 100644
--- a/libdwfl/dwfl_module_addrsym.c
+++ b/libdwfl/dwfl_module_addrsym.c
@@ -41,6 +41,7 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
/* Return true iff we consider ADDR to lie in the same section as SYM. */
GElf_Word addr_shndx = SHN_UNDEF;
+ struct dwfl_file *addr_symfile = NULL;
inline bool same_section (const GElf_Sym *sym, struct dwfl_file *symfile,
GElf_Word shndx)
{
@@ -49,11 +50,12 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
return sym->st_value == addr;
/* Figure out what section ADDR lies in. */
- if (addr_shndx == SHN_UNDEF)
+ if (addr_shndx == SHN_UNDEF || addr_symfile != symfile)
{
GElf_Addr mod_addr = dwfl_deadjust_st_value (mod, symfile, addr);
Elf_Scn *scn = NULL;
addr_shndx = SHN_ABS;
+ addr_symfile = symfile;
while ((scn = elf_nextscn (symfile->elf, scn)) != NULL)
{
GElf_Shdr shdr_mem;
@@ -68,7 +70,7 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
}
}
- return shndx == addr_shndx;
+ return shndx == addr_shndx && addr_symfile == symfile;
}
/* Keep track of the closest symbol we have seen so far.
@@ -84,6 +86,20 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
/* Keep track of the lowest address a relevant sizeless symbol could have. */
GElf_Addr min_label = 0;
+ inline struct dwfl_file *i_to_symfile (int ndx)
+ {
+ int skip_aux_zero = (mod->syments > 0 && mod->aux_syments > 0) ? 1 : 0;
+ if (ndx < mod->first_global)
+ return mod->symfile; // main symbol table (locals).
+ else if (ndx < mod->first_global + mod->aux_first_global - skip_aux_zero)
+ return &mod->aux_sym; // aux symbol table (locals).
+ else if ((size_t) ndx
+ < mod->syments + mod->aux_first_global - skip_aux_zero)
+ return mod->symfile; // main symbol table (globals).
+ else
+ return &mod->aux_sym; // aux symbol table (globals).
+ }
+
/* Look through the symbol table for a matching symbol. */
inline void search_table (int start, int end)
{
@@ -136,11 +152,7 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
}
else if (closest_name == NULL
&& sym.st_value >= min_label
- && same_section (&sym,
- ((size_t) i < mod->syments
- ? mod->symfile
- : &mod->aux_sym),
- shndx))
+ && same_section (&sym, i_to_symfile (i), shndx))
{
/* Handwritten assembly symbols sometimes have no
st_size. If no symbol with proper size includes