Bug 23982 - dwarf_formref_die() does not support DW_FORM_indirect
Summary: dwarf_formref_die() does not support DW_FORM_indirect
Status: RESOLVED FIXED
Alias: None
Product: elfutils
Classification: Unclassified
Component: libdw (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-13 17:21 UTC by Andreas Kromke
Modified: 2021-09-03 13:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Kromke 2018-12-13 17:21:36 UTC
This kind of indirect form is generated by some ARM compilers.

A temporary workaround might be:


Dwarf_Attribute *attr = dwarf_attr_integrate(die, DW_AT_type, &attr_mem);
if (attr != NULL)
{
    unsigned int whatform = dwarf_whatform(attr);
    while(whatform == DW_FORM_indirect)
    {
        uint64_t val;
        const unsigned char *p = (const unsigned char *) attr->valp;
        get_uleb128_unchecked(val, p);
        whatform = (unsigned int) val;
        attr_mem.form = whatform;
        attr_mem.valp = (void *) p;
    }
    Dwarf_Die *type = dwarf_formref_die(attr, type_die);
...


However, this method is rather ugly, because it needs the internal function get_uleb128_unchecked().
Comment 1 Mark Wielaard 2018-12-25 16:47:42 UTC
I don't believe I have ever seen a DWARF producer that uses DW_FORM_indirect, I wouldn't be surprised if other libdw function don't handle it correctly too.

Do you have an example file that shows DW_FORM_indirect being used? What producer generated it?
Comment 2 Andreas Kromke 2019-01-02 17:12:02 UTC
Unfortunately I cannot provide the example file (due to legal restrictions), but I can tell that the producer is the following:

"ARM C/C++ Compiler, 5.03 [Build 76]"

The machine is (obviously) ARM.

Here someone already mentioned the problem:

http://lists.gnu.org/archive/html/bug-gdb/2000-11/msg00009.html
Comment 3 Mark Wielaard 2019-01-13 16:39:18 UTC
As with your other bug without at least some example DWARF files this will be somewhat hard to support. I think I know what would be needed, but without actual testcases it will be hard to get right.
Comment 4 Mark Wielaard 2021-09-03 13:49:03 UTC
This was implemented by:

commit d63b26b8d21fb554049789290cd245cbe0446735
Author: Omar Sandoval <osandov@fb.com>
Date:   Fri Apr 23 16:36:15 2021 -0700

    libdw: handle DW_FORM_indirect when reading attributes
    
    Whenever we encounter an attribute with DW_FORM_indirect, we need to
    read its true form from the DIE data. Then, we can continue normally.
    This adds support to the most obvious places: __libdw_find_attr() and
    dwarf_getattrs(). There may be more places that need to be updated.
    
    I encountered this when inspecting a file that was processed by our BOLT
    tool: https://github.com/facebookincubator/BOLT. This also adds a couple
    of test cases using a file generated by that tool.
    
    Signed-off-by: Omar Sandoval <osandov@fb.com>