]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Make dwfl_module_getsym yield shndx -1 for any non-allocated section.
authorRoland McGrath <roland@redhat.com>
Thu, 9 Apr 2009 00:52:33 +0000 (17:52 -0700)
committerRoland McGrath <roland@redhat.com>
Thu, 9 Apr 2009 00:52:33 +0000 (17:52 -0700)
libdwfl/dwfl_module_getsym.c
libdwfl/libdwfl.h

index 8f02d71fcb720dcebe9b8a40d71bc0d79cafa568..816d21433c0327ebb3b619350a8c68523f413b51 100644 (file)
@@ -75,7 +75,20 @@ dwfl_module_getsym (Dwfl_Module *mod, int ndx,
     shndx = sym->st_shndx;
 
   if (shndxp != NULL)
-    *shndxp = shndx;
+    {
+      *shndxp = shndx;
+
+      /* Yield -1 in case of a non-SHF_ALLOC section.  */
+      if (sym->st_shndx == SHN_XINDEX
+         || (sym->st_shndx < SHN_LORESERVE && sym->st_shndx != SHN_UNDEF))
+       {
+         GElf_Shdr shdr_mem;
+         GElf_Shdr *shdr = gelf_getshdr (elf_getscn (mod->symfile->elf, shndx),
+                                         &shdr_mem);
+         if (unlikely (shdr == NULL) || !(shdr->sh_flags & SHF_ALLOC))
+           *shndxp = (GElf_Word) -1;
+       }
+    }
 
   switch (sym->st_shndx)
     {
index b6ae776581f1318fa6a85bc5e67308c86150ceb9..91d43802499dca3dbb46058639e1e59d53cefffc 100644 (file)
@@ -1,5 +1,5 @@
 /* Interfaces for libdwfl.
-   Copyright (C) 2005, 2006, 2007, 2008 Red Hat, Inc.
+   Copyright (C) 2005-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -423,10 +423,11 @@ extern int dwfl_module_getsymtab (Dwfl_Module *mod);
 
 /* Fetch one entry from the module's symbol table.  On errors, returns
    NULL.  If successful, fills in *SYM and returns the string for st_name.
-   This works like gelf_getsym except that st_value is always adjusted
-   to an absolute value based on the module's location.  If SHNDXP is
-   non-null, it's set with the section index (whether from st_shndx or
-   extended index table).  */
+   This works like gelf_getsym except that st_value is always adjusted to
+   an absolute value based on the module's location, when the symbol is in
+   an SHF_ALLOC section.  If SHNDXP is non-null, it's set with the section
+   index (whether from st_shndx or extended index table); in case of a
+   symbol in a non-allocated section, *SHNDXP is instead set to -1.  */
 extern const char *dwfl_module_getsym (Dwfl_Module *mod, int ndx,
                                       GElf_Sym *sym, GElf_Word *shndxp)
   __nonnull_attribute__ (3);