From: Roland McGrath Date: Thu, 9 Apr 2009 00:52:33 +0000 (-0700) Subject: Make dwfl_module_getsym yield shndx -1 for any non-allocated section. X-Git-Tag: elfutils-0.141~25^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=68f29f9019cc75044394eb5572e9ab0157cfb707;p=thirdparty%2Felfutils.git Make dwfl_module_getsym yield shndx -1 for any non-allocated section. --- diff --git a/libdwfl/dwfl_module_getsym.c b/libdwfl/dwfl_module_getsym.c index 8f02d71fc..816d21433 100644 --- a/libdwfl/dwfl_module_getsym.c +++ b/libdwfl/dwfl_module_getsym.c @@ -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) { diff --git a/libdwfl/libdwfl.h b/libdwfl/libdwfl.h index b6ae77658..91d438024 100644 --- a/libdwfl/libdwfl.h +++ b/libdwfl/libdwfl.h @@ -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);