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/3] ppc64 .opd: Refactor syments/first_global


Hi,

jankratochvil/symrefactor

currently SYMENTS is the total number of symbols and FIRST_GLOBAL is somehow
the first half of local symbols from SYMENTS.

But it is difficult to extend it so that there can be multiple providers of
local and global symbols, for both ppc64 .opd resolver and possible
"minidebuginfo" provider.

This patch should not change any behavior.


Thanks,
Jan


commit d40e96c75d838215863f96d91f851e45c046b5d3
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Fri Dec 14 19:45:32 2012 +0100

    libdwfl/
    	* dwfl_module_addrsym.c (dwfl_module_addrsym): Replace the usse of
    	Dwfl_Module->first_global by Dwfl_Module->symlocals.  Delete the
    	first_global comment, move part of it to struct Dwfl_Module.
    	* dwfl_module_getdwarf.c (load_symtab): Replace parameters syments and
    	first_global by symlocals and symglobals.  Update their use therein.
    	(find_dynsym): Replace the use of Dwfl_Module->syments by
    	Dwfl_Module->symglobals.
    	(find_symtab): Replace first_global initialization by two asserts on
    	symlocals and symglobals.  Update the load_symtab caller.
    	(dwfl_module_getsymtab): Replace the usse of Dwfl_Module->syments by
    	Dwfl_Module->symlocals and Dwfl_Module->symglobals.
    	* libdwflP.h (struct Dwfl_Module): Replace fields syments and
    	first_global by symlocals and symglobals.  Add here a part of comment
    	from dwfl_module_addrsym.
    	* relocate.c (resolve_symbol): Replace Dwfl_Module->syments by a call
    	to dwfl_module_getsymtab.  Change ndx variable type to signed int.
    
    Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 896ae39..bbe2255 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,22 @@
+2012-12-14  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* dwfl_module_addrsym.c (dwfl_module_addrsym): Replace the usse of
+	Dwfl_Module->first_global by Dwfl_Module->symlocals.  Delete the
+	first_global comment, move part of it to struct Dwfl_Module.
+	* dwfl_module_getdwarf.c (load_symtab): Replace parameters syments and
+	first_global by symlocals and symglobals.  Update their use therein.
+	(find_dynsym): Replace the use of Dwfl_Module->syments by
+	Dwfl_Module->symglobals.
+	(find_symtab): Replace first_global initialization by two asserts on
+	symlocals and symglobals.  Update the load_symtab caller.
+	(dwfl_module_getsymtab): Replace the usse of Dwfl_Module->syments by
+	Dwfl_Module->symlocals and Dwfl_Module->symglobals.
+	* libdwflP.h (struct Dwfl_Module): Replace fields syments and
+	first_global by symlocals and symglobals.  Add here a part of comment
+	from dwfl_module_addrsym.
+	* relocate.c (resolve_symbol): Replace Dwfl_Module->syments by a call
+	to dwfl_module_getsymtab.  Change ndx variable type to signed int.
+
 2012-12-11  Mark Wielaard  <mjw@redhat.com>
 
 	* linux-kernel-modules.c (report_kernel): Only free fname if
diff --git a/libdwfl/dwfl_module_addrsym.c b/libdwfl/dwfl_module_addrsym.c
index fdc95fc..e7c42da 100644
--- a/libdwfl/dwfl_module_addrsym.c
+++ b/libdwfl/dwfl_module_addrsym.c
@@ -168,17 +168,14 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
 	}
     }
 
-  /* First go through global symbols.  mod->first_global is setup by
-     dwfl_module_getsymtab to the index of the first global symbol in
-     the module's symbol table, or -1 when unknown.  All symbols with
-     local binding come first in the symbol table, then all globals.  */
-  search_table (mod->first_global < 0 ? 1 : mod->first_global, syments);
+  /* First go through global symbols.  */
+  search_table (mod->symlocals, syments);
 
   /* If we found nothing searching the global symbols, then try the locals.
      Unless we have a global sizeless symbol that matches exactly.  */
-  if (closest_name == NULL && mod->first_global > 1
+  if (closest_name == NULL && mod->symlocals > 1
       && (sizeless_name == NULL || sizeless_sym.st_value != addr))
-    search_table (1, mod->first_global);
+    search_table (1, mod->symlocals);
 
   /* If we found no proper sized symbol to use, fall back to the best
      candidate sizeless symbol we found, if any.  */
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
index 025cb8a..f816f2c 100644
--- a/libdwfl/dwfl_module_getdwarf.c
+++ b/libdwfl/dwfl_module_getdwarf.c
@@ -550,7 +550,7 @@ find_debuginfo (Dwfl_Module *mod)
 static Dwfl_Error
 load_symtab (struct dwfl_file *file, struct dwfl_file **symfile,
 	     Elf_Scn **symscn, Elf_Scn **xndxscn,
-	     size_t *syments, int *first_global, GElf_Word *strshndx)
+	     size_t *symlocals, size_t *symglobals, GElf_Word *strshndx)
 {
   bool symtab = false;
   Elf_Scn *scn = NULL;
@@ -565,8 +565,8 @@ load_symtab (struct dwfl_file *file, struct dwfl_file **symfile,
 	    *symscn = scn;
 	    *symfile = file;
 	    *strshndx = shdr->sh_link;
-	    *syments = shdr->sh_size / shdr->sh_entsize;
-	    *first_global = shdr->sh_info;
+	    *symlocals = shdr->sh_info;
+	    *symglobals = (shdr->sh_size / shdr->sh_entsize) - *symlocals;
 	    if (*xndxscn != NULL)
 	      return DWFL_E_NOERROR;
 	    break;
@@ -578,7 +578,7 @@ load_symtab (struct dwfl_file *file, struct dwfl_file **symfile,
 	    *symscn = scn;
 	    *symfile = file;
 	    *strshndx = shdr->sh_link;
-	    *syments = shdr->sh_size / shdr->sh_entsize;
+	    *symglobals = shdr->sh_size / shdr->sh_entsize;
 	    break;
 
 	  case SHT_SYMTAB_SHNDX:
@@ -718,11 +718,11 @@ find_dynsym (Dwfl_Module *mod)
 					   entsz == 4 ? ELF_T_WORD
 					   : ELF_T_XWORD);
 	      if (data != NULL)
-		mod->syments = (entsz == 4
-				? *(const GElf_Word *) data->d_buf
-				: *(const GElf_Xword *) data->d_buf);
+		mod->symglobals = (entsz == 4
+				   ? *(const GElf_Word *) data->d_buf
+				   : *(const GElf_Xword *) data->d_buf);
 	    }
-	  if (offs[i_gnu_hash] != 0 && mod->syments == 0)
+	  if (offs[i_gnu_hash] != 0 && mod->symglobals == 0)
 	    {
 	      /* In the new format, we can derive it with some work.  */
 
@@ -769,7 +769,7 @@ find_dynsym (Dwfl_Module *mod)
 			  if (data != NULL
 			      && (*(const Elf32_Word *) data->d_buf & 1u))
 			    {
-			      mod->syments = maxndx + 1;
+			      mod->symglobals = maxndx + 1;
 			      break;
 			    }
 			  ++maxndx;
@@ -778,18 +778,18 @@ find_dynsym (Dwfl_Module *mod)
 		    }
 		}
 	    }
-	  if (offs[i_strtab] > offs[i_symtab] && mod->syments == 0)
-	    mod->syments = ((offs[i_strtab] - offs[i_symtab])
-			    / gelf_fsize (mod->main.elf,
-					  ELF_T_SYM, 1, EV_CURRENT));
+	  if (offs[i_strtab] > offs[i_symtab] && mod->symglobals == 0)
+	    mod->symglobals = ((offs[i_strtab] - offs[i_symtab])
+			       / gelf_fsize (mod->main.elf,
+					     ELF_T_SYM, 1, EV_CURRENT));
 
-	  if (mod->syments > 0)
+	  if (mod->symglobals > 0)
 	    {
 	      mod->symdata = elf_getdata_rawchunk (mod->main.elf,
 						   offs[i_symtab],
 						   gelf_fsize (mod->main.elf,
 							       ELF_T_SYM,
-							       mod->syments,
+							       mod->symglobals,
 							       EV_CURRENT),
 						   ELF_T_SYM);
 	      if (mod->symdata != NULL)
@@ -827,13 +827,14 @@ find_symtab (Dwfl_Module *mod)
   if (mod->symerr != DWFL_E_NOERROR)
     return;
 
-  mod->first_global = -1; /* Unknown, unless explicitly set by load_symtab.  */
+  assert (mod->symlocals == 0);
+  assert (mod->symglobals == 0);
 
   /* First see if the main ELF file has the debugging information.  */
   Elf_Scn *symscn = NULL, *xndxscn = NULL;
   GElf_Word strshndx;
   mod->symerr = load_symtab (&mod->main, &mod->symfile, &symscn,
-			     &xndxscn, &mod->syments, &mod->first_global,
+			     &xndxscn, &mod->symlocals, &mod->symglobals,
 			     &strshndx);
   switch (mod->symerr)
     {
@@ -853,8 +854,8 @@ find_symtab (Dwfl_Module *mod)
 
 	case DWFL_E_NOERROR:
 	  mod->symerr = load_symtab (&mod->debug, &mod->symfile, &symscn,
-				     &xndxscn, &mod->syments,
-				     &mod->first_global, &strshndx);
+				     &xndxscn, &mod->symlocals,
+				     &mod->symglobals, &strshndx);
 	  break;
 
 	case DWFL_E_CB:		/* The find_debuginfo hook failed.  */
@@ -1067,7 +1068,7 @@ dwfl_module_getsymtab (Dwfl_Module *mod)
 
   find_symtab (mod);
   if (mod->symerr == DWFL_E_NOERROR)
-    return mod->syments;
+    return mod->symlocals + mod->symglobals;
 
   __libdwfl_seterrno (mod->symerr);
   return -1;
diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h
index 806ebcd..360e1ef 100644
--- a/libdwfl/libdwflP.h
+++ b/libdwfl/libdwflP.h
@@ -152,10 +152,12 @@ struct Dwfl_Module
 
   struct dwfl_file *symfile;	/* Either main or debug.  */
   Elf_Data *symdata;		/* Data in the ELF symbol table section.  */
-  size_t syments;		/* sh_size / sh_entsize of that section.  */
-  int first_global;		/* Index of first global symbol of table.  */
   Elf_Data *symstrdata;		/* Data for its string table.  */
   Elf_Data *symxndxdata;	/* Data in the extended section index table. */
+  /* All symbols with local binding come first in the symbol table,
+     then all globals.  */
+  size_t symlocals;		/* Local symbols in SYMDATA.  */
+  size_t symglobals;		/* Global symbols in SYMDATA.  */
 
   Dwarf *dw;			/* libdw handle for its debugging info.  */
 
diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c
index 2c24bd5..70715cc 100644
--- a/libdwfl/relocate.c
+++ b/libdwfl/relocate.c
@@ -223,7 +223,7 @@ resolve_symbol (Dwfl_Module *referer, struct reloc_symtab_cache *symtab,
 		&& m->symerr != DWFL_E_NO_SYMTAB)
 	      return m->symerr;
 
-	    for (size_t ndx = 1; ndx < m->syments; ++ndx)
+	    for (int ndx = 1; ndx < INTUSE(dwfl_module_getsymtab) (m); ++ndx)
 	      {
 		sym = gelf_getsymshndx (m->symdata, m->symxndxdata,
 					ndx, sym, &shndx);

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