Problems with dwarf-getmacros test

Ulf Hermann ulf.hermann@qt.io
Wed May 10 17:09:00 GMT 2017


>>> Do you have the whole call stack of that failed __libdw_read_offset
>>> call? Which source line in tests/dwarf-getmacros.c prints the "(null)"?
>
> Actually I just managed to catch a backtrace by inserting an infinite
> loop at the point where it would normally return -1. It turns out the
> address we are looking for is not in the IDX_debug_info section, but in
> the IDX_debug_macro section (which by itself isn't all that surprising,
> but if that is a rule, how can this code ever work??).

The likely solution of the mystery is this piece of code in 
__libdw_in_section:

if (unlikely (addr < data->d_buf)
       || unlikely (data->d_size - (addr - data->d_buf) < size))
     {
       __libdw_seterrno (DWARF_E_INVALID_OFFSET);
       return false;
     }

If addr < data->d_buf we fail immediately. That's what's happening to me 
sometimes. However, if addr > data->d_buf, then it's likely much bigger, 
as the allocations of the different sections are unrelated. data->d_size 
is always 159 in this test case. Therefore, data->d_size - (addr - 
data->d_buf) will produce something negative, which then gets compared 
to a size_t, forcing it to overflow. size is 4, so this case never gets 
detected.

Ulf



More information about the Elfutils-devel mailing list