[patch 2/3] ppc64 .opd: Provide elf_scnfindvma

Jan Kratochvil jan.kratochvil at redhat.com
Fri Dec 14 19:34:52 UTC 2012


Hi,

jankratochvil/symrefactor-scnfindvma

it just provides a part of existing code as a public function called
in [patch 3/3].  I understand it has no meaning on its own.


Thanks,
Jan


commit 4299e5860e94c012cadfc6af7ae10facc9c5b6ed
Author: Jan Kratochvil <jan.kratochvil at redhat.com>
Date:   Fri Dec 14 20:07:14 2012 +0100

    libdwfl/
    	* dwfl_module_addrsym.c (dwfl_module_addrsym): Call elf_scnfindvma
    	where is the code from here moved out.
    
    libelf/
    	* Makefile.am (libelf_a_SOURCES): Add elf_scnfindvma.c.
    	* elf_scnfindvma.c: New file.
    	* libelf.h (elf_scnfindvma): New declaration.
    	* libelf.map (ELFUTILS_1.156): New with elf_scnfindvma.
    
    Signed-off-by: Jan Kratochvil <jan.kratochvil at redhat.com>

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index bbe2255..8caf083 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,10 @@
 2012-12-14  Jan Kratochvil  <jan.kratochvil at redhat.com>
 
+	* dwfl_module_addrsym.c (dwfl_module_addrsym): Call elf_scnfindvma
+	where is the code from here moved out.
+
+2012-12-14  Jan Kratochvil  <jan.kratochvil at 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.
diff --git a/libdwfl/dwfl_module_addrsym.c b/libdwfl/dwfl_module_addrsym.c
index e7c42da..d2316c6 100644
--- a/libdwfl/dwfl_module_addrsym.c
+++ b/libdwfl/dwfl_module_addrsym.c
@@ -51,20 +51,8 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
       if (addr_shndx == SHN_UNDEF)
 	{
 	  GElf_Addr mod_addr = dwfl_deadjust_st_value (mod, addr);
-	  Elf_Scn *scn = NULL;
-	  addr_shndx = SHN_ABS;
-	  while ((scn = elf_nextscn (mod->symfile->elf, scn)) != NULL)
-	    {
-	      GElf_Shdr shdr_mem;
-	      GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
-	      if (likely (shdr != NULL)
-		  && mod_addr >= shdr->sh_addr
-		  && mod_addr < shdr->sh_addr + shdr->sh_size)
-		{
-		  addr_shndx = elf_ndxscn (scn);
-		  break;
-		}
-	    }
+	  Elf_Scn *scn = elf_scnfindvma (mod->symfile->elf, mod_addr);
+	  addr_shndx = scn == NULL ? SHN_ABS : elf_ndxscn (scn);
 	}
 
       return shndx == addr_shndx;
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 4a9e358..4ff36f5 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,10 @@
+2012-12-14  Jan Kratochvil  <jan.kratochvil at redhat.com>
+
+	* Makefile.am (libelf_a_SOURCES): Add elf_scnfindvma.c.
+	* elf_scnfindvma.c: New file.
+	* libelf.h (elf_scnfindvma): New declaration.
+	* libelf.map (ELFUTILS_1.156): New with elf_scnfindvma.
+
 2012-09-17  Petr Machata  <pmachata at redhat.com>
 
 	* elf.h: Update from glibc.
diff --git a/libelf/Makefile.am b/libelf/Makefile.am
index 5903ea8..4b83e23 100644
--- a/libelf/Makefile.am
+++ b/libelf/Makefile.am
@@ -90,7 +90,7 @@ libelf_a_SOURCES = elf_version.c elf_hash.c elf_error.c elf_fill.c \
 		   elf32_offscn.c elf64_offscn.c gelf_offscn.c \
 		   elf_getaroff.c \
 		   elf_gnu_hash.c \
-		   elf_scnshndx.c
+		   elf_scnshndx.c elf_scnfindvma.c
 
 if !MUDFLAP
 libelf_pic_a_SOURCES =
diff --git a/libelf/elf_scnfindvma.c b/libelf/elf_scnfindvma.c
new file mode 100644
index 0000000..b543819
--- /dev/null
+++ b/libelf/elf_scnfindvma.c
@@ -0,0 +1,52 @@
+/* Get section containing VMA address.  Return NULL otherwise.
+   Copyright (C) 2012 Red Hat, Inc.
+   This file is part of elfutils.
+   Contributed by Ulrich Drepper <drepper at redhat.com>, 1998.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "libelfP.h"
+
+
+Elf_Scn *
+elf_scnfindvma (Elf *__elf, GElf_Addr __vma)
+{
+  Elf_Scn *scn = NULL;
+  while ((scn = elf_nextscn (__elf, scn)) != NULL)
+    {
+      GElf_Shdr shdr_mem;
+      GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
+      if (likely (shdr != NULL)
+	  && __vma >= shdr->sh_addr
+	  && __vma < shdr->sh_addr + shdr->sh_size)
+	break;
+    }
+  return scn;
+}
+INTDEF(elf_scnfindvma)
diff --git a/libelf/libelf.h b/libelf/libelf.h
index 5a2b3af..1dd5d2f 100644
--- a/libelf/libelf.h
+++ b/libelf/libelf.h
@@ -219,6 +219,11 @@ extern Elf64_Phdr *elf64_newphdr (Elf *__elf, size_t __cnt);
 /* Get section at INDEX.  */
 extern Elf_Scn *elf_getscn (Elf *__elf, size_t __index);
 
+/* Get section containing VMA address.  Return NULL otherwise.
+   GElf_Addr type cannot be used here for __vma due to include
+   interdependencies.  */
+extern Elf_Scn *elf_scnfindvma (Elf *__elf, Elf64_Addr __vma);
+
 /* Get section at OFFSET.  */
 extern Elf_Scn *elf32_offscn (Elf *__elf, Elf32_Off __offset);
 /* Similar bug this time the binary calls is ELFCLASS64.  */
diff --git a/libelf/libelf.map b/libelf/libelf.map
index de6d912..ec288fe 100644
--- a/libelf/libelf.map
+++ b/libelf/libelf.map
@@ -138,3 +138,8 @@ ELFUTILS_1.6 {
   global:
     elf_getphdrnum;
 } ELFUTILS_1.5;
+
+ELFUTILS_1.156 {
+  global:
+    elf_scnfindvma;
+} ELFUTILS_1.6;


More information about the elfutils-devel mailing list