[PATCH v3 2/6] libdw: Add dwarf_getalt, dwarf_setalt

Florian Weimer fweimer at redhat.com
Thu Apr 17 15:33:12 UTC 2014


On 04/17/2014 05:17 PM, Mark Wielaard wrote:
> Hi Florian,
>
> Looks good, just some nitpicks.
>
> On Tue, 2014-04-15 at 14:31 +0200, Florian Weimer wrote:
>> +++ b/libdw/dwarf_getalt.c
>> @@ -0,0 +1,42 @@
>> +/* Create descriptor from ELF descriptor for processing file.
>
> This isn't a great description.
>
>> diff --git a/libdw/dwarf_setalt.c b/libdw/dwarf_setalt.c
>> +/* Create descriptor from ELF descriptor for processing file.
>
> Same here.

I'm now using the first sentence from the comments in the header file:

/* Retrieves the DWARF descriptor for debugaltlink data.

/* Provides the data referenced by the .gnu_debugaltlink section.

>> +void
>> +dwarf_setalt (Dwarf *main, Dwarf *alt)
>> +{
>> +  if (main->free_alt)
>> +    INTUSE (dwarf_end) (main->alt_dwarf);
>> +  main->free_alt = false;
>> +  main->alt_dwarf = alt;
>> +}
>> +INTDEF (dwarf_setalt)
>
> Two questions. I think either answer is fine, but it should be
> explicitly said/documented.
> 1) Should we verify the underlying ELF files to see whether there is
> a .gnu_debugaltlink with matching build_id in the alt file? If not then
> we should document that the user is responsible for the sanity checking.

I don't think we should.  I think build IDs are optional, and we do not 
have sufficient information about the file paths to check that they match.

> 2) Should we allow resetting the alt file once set? If we do, like here,
> we should add a warning to dwarf_getalt that dwarf_setalt might
> reset/end the underlying Dwarf.

But it doesn't—dwarf_setalt does not take ownership.  I tried to make 
this more clear:

/* Retrieves the DWARF descriptor for debugaltlink data.  Returns NULL
    if no alternate debug data has been supplied.  Unless the
    debugaltlink data was provided by calling dwarf_setalt, a call to
    dwarf_end (MAIN) will deallocate it, invalidating the returned
    pointer.  */
extern Dwarf *dwarf_getalt (Dwarf *main);

/* Provides the data referenced by the .gnu_debugaltlink section.  The
    caller should check that MAIN and ALT match (i.e., they have the
    same build ID).  It is the responsibility of the caller to ensure
    that the data referenced by ALT stays valid while it is used by
    MAIN, until dwarf_setalt is called on MAIN with a different
    descriptor, or dwarf_end.  */
extern void dwarf_setalt (Dwarf *main, Dwarf *alt);


-- 
Florian Weimer / Red Hat Product Security Team


More information about the elfutils-devel mailing list