This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch 1/4] Fix dwfl_module_addrsym for minidebuginfo


Hi Mark,

jankratochvil/xauxfile

the existing condition is clearly wrong:
	((size_t) i < mod->syments ? mod->symfile : &mod->aux_sym)

Additionally same_section() cannot compare section number from file X with
section number from file Y, it is moreover done just for caching/performance
reasons.  My fix there is performance-suboptimal but still only twice as slow
as it could be, I think.

The existing code worked due to a luck.  This fix does not have a new testcase
but the later testcase for ppc64 .opd FAILs without this fix so it gets tested
somehow.

The added function i_to_symfile() is deleted in the next patch so its content
does not matter much I think.


Thanks,
Jan

commit 7a58010a1862eaa3f7292b387347ecae6178243a
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Wed Nov 6 20:23:44 2013 +0100

    Fix dwfl_module_addrsym for minidebuginfo
    
    libdwfl/
    2013-11-06  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.
    
    Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>

diff --git a/libdwfl/dwfl_module_addrsym.c b/libdwfl/dwfl_module_addrsym.c
index 732b698..3d19943 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]