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 3/4] Provide elf_scnfindvma


Hi Mark,

jankratochvil/xauxfile-filep-scnfindvma

obsoletes:
	[patch 2/3] ppc64 .opd: Provide elf_scnfindvma
	https://lists.fedorahosted.org/pipermail/elfutils-devel/2012-December/002842.html

it is just a code refactorization, no code change happens.

elf_scnfindvma() will get used in [patch 4/4].


Thanks,
Jan

commit 311207bda9a23a6216b30337baca8bf79a696265
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Mon Nov 4 18:23:49 2013 +0100

    Provide elf_scnfindvma
    
    libdwfl/
    2013-11-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
    
    	Provide elf_scnfindvma.
    	* dwfl_module_addrsym.c (dwfl_module_addrsym) (same_section): Call
    	elf_scnfindvma where is the code from here moved out.
    
    libelf/
    2013-11-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
    
    	Provide elf_scnfindvma.
    	* 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@redhat.com>

diff --git a/libdwfl/dwfl_module_addrsym.c b/libdwfl/dwfl_module_addrsym.c
index d9eb0a2..2926726 100644
--- a/libdwfl/dwfl_module_addrsym.c
+++ b/libdwfl/dwfl_module_addrsym.c
@@ -53,21 +53,9 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
       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;
+	  Elf_Scn *scn = elf_scnfindvma (symfile->elf, mod_addr);
+	  addr_shndx = scn == NULL ? SHN_ABS : elf_ndxscn (scn);
 	  addr_symfile = symfile;
-	  while ((scn = elf_nextscn (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;
-		}
-	    }
 	}
 
       return shndx == addr_shndx && addr_symfile == symfile;
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..04fd451
--- /dev/null
+++ b/libelf/elf_scnfindvma.c
@@ -0,0 +1,52 @@
+/* Get section containing VMA address.  Return NULL otherwise.
+   Copyright (C) 2013 Red Hat, Inc.
+   This file is part of elfutils.
+   Contributed by Ulrich Drepper <drepper@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..199bcfb 100644
--- a/libelf/libelf.map
+++ b/libelf/libelf.map
@@ -138,3 +138,8 @@ ELFUTILS_1.6 {
   global:
     elf_getphdrnum;
 } ELFUTILS_1.5;
+
+ELFUTILS_1.158 {
+  global:
+    elf_scnfindvma;
+} ELFUTILS_1.6;

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