summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libdwfl/dwfl_module_getsym.c15
-rw-r--r--libdwfl/libdwfl.h11
2 files changed, 20 insertions, 6 deletions
diff --git a/libdwfl/dwfl_module_getsym.c b/libdwfl/dwfl_module_getsym.c
index 8f02d71f..816d2143 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 b6ae7765..91d43802 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);