]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Fix dwfl_module_addrsym for minidebuginfo
authorJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 13 Nov 2013 18:58:06 +0000 (19:58 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 13 Nov 2013 18:58:06 +0000 (19:58 +0100)
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
libdwfl/ChangeLog
libdwfl/dwfl_module_addrsym.c

index 467b4869cdf570997b6214f6b17e25a44485eaca..282f0112ba02cd9da7a4d44d4db593f0b73caab3 100644 (file)
@@ -1,3 +1,12 @@
+2013-11-13  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       Fix dwfl_module_addrsym for minidebuginfo.
+       * dwfl_module_addrsym.c (dwfl_module_addrsym): New variable
+       addr_symfile.
+       (dwfl_module_addrsym) (same_section): Use it.
+       (dwfl_module_addrsym) (i_to_symfile): New function.
+       (dwfl_module_addrsym) (search_table): Use it.
+
 2013-11-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
            Mark Wielaard  <mjw@redhat.com>
 
index 732b6983ae44ccb8014865609b2dc0de432fa133..3d199437037e1f6702a4f9e3f6afda755afdb142 100644 (file)
@@ -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