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)
{
/* 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
/* 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);