[PATCH] libdwelf: New DWARF ELF Low-level Functions. Add dwelf_elf_gnu_debuglink.

Mark Wielaard mjw at redhat.com
Mon Apr 14 13:44:18 UTC 2014


On Mon, 2014-04-14 at 09:52 +0200, Florian Weimer wrote:
> On 04/12/2014 12:30 AM, Mark Wielaard wrote:
> > +const char *
> > +dwelf_elf_gnu_debuglink (Elf *elf, GElf_Word *crc)
> > +{
> > +  size_t shstrndx;
> > +  if (elf_getshdrstrndx (elf, &shstrndx) < 0)
> > +    return NULL;
> > +
> > +  Elf_Scn *scn = NULL;
> > +  while ((scn = elf_nextscn (elf, scn)) != NULL)
> > +    {
> > +      GElf_Shdr shdr_mem;
> > +      GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
> > +      if (shdr == NULL)
> > +        return NULL;
> > +
> > +      const char *name = elf_strptr (elf, shstrndx, shdr->sh_name);
> > +      if (name == NULL)
> > +        return NULL;
> > +
> > +      if (!strcmp (name, ".gnu_debuglink"))
> > +        break;
> > +    }
> > +
> > +  if (scn == NULL)
> > +    return NULL;
> 
> I think this should be part of a separate helper function because I need 
> pretty much the same loop for implementing debugaltlink access.

You mean we should provide a Elf_Scn *dwelf_elf_scn_byname (Elf *elf,
const char *name)? That does make some sense. You often do that because
(unfortunately) debug sections are only identified by name. I'll suggest
a patch.

But I am not sure why dwelf_dwarf_gnu_debugaltlink (as I would call it)
would use or need it. Your patch (IMHO nicely) gets that section already
through the (internal libdw) dwarf_scnnames.

> Perhaps dwelf_elf_gnu_debuglink should extract the data from an Elf_Scn 
> pointer, relying on the caller to locate the section?  On the other 
> hand, that would make this convenience function more difficult to use.

Yes, I don't think that is a good idea. It is hardly a convenience
function anymore if we strip the convenient part of it :)

Cheers,

Mark



More information about the elfutils-devel mailing list