[Dwarf-Discuss] Section offset values

Jakub Křoustek ikroustek at fit.vutbr.cz
Mon Oct 25 06:52:14 PDT 2010


On 25.10.2010 14:44, Jonas Maebe wrote:
> 
> On 25 Oct 2010, at 14:31, Jakub Křoustek wrote:
> 
>> As I read in the DWARF Debugging Standard, the ".long .Ldebug_info0"
>> attribute in section .debug_pubnames means "The offset from the
>> beginning of the .debug_info section ...". But the ".long" directive
>> tells the assembler to store absolute address of the .Ldebug_info0 label
>> (as is usual in most assemblers), not the section relative address,
>> which will look like:
>>
>> .long .Ldebug_info0-.Ldebug_info0
>>
>> My question is: how will the assembler figure out that it must store an
>> address from the beginning of a section and not an absolute address?
> 
> It doesn't. For some reason, ELF (at least on Linux and FreeBSD) simply
> does not follow the DWARF standard in this respect and stores absolute
> addresses for the address of the abbreviation table and the
> DW_AT_stmt_list attribute.
> 
> 
> Jonas

Thank you for reply. But in case of debug_info_offset attribute in
.debug_pubnames section, if I look in the resulting ELF binary, the
attribute contains correct (i.e. section relative) value.

For example take MIPS Linux ELF application created by more modules
(Compilation units) and compiled with gcc 4.4.1:

//mips-elf-readelf -wi test
The section .debug_info contains:

  Compilation Unit @ offset 0x0:
   Length:        0x6e (32-bit)
...
  Compilation Unit @ offset 0x72:
   Length:        0xb8 (32-bit)
...
  Compilation Unit @ offset 0x12e:
   Length:        0xe0 (32-bit)
...

//mips-elf-objdump -j .debug_pubnames -s test
                           0x72
                          /
0000 00000017 00020000 00720000 00bc0000  .........r......
0010 00296d61 696e0000 00000000 00002c00  .)main........,.
                0x12e
               /
0020 02000001 2e000000 e4000000 29717569  ............)qui
...

So the assembler correctly translated ".long .Ldebug_info0" (".4byte
.Ldebug_info0" in case of MIPS assembler) into value 0x72 and to 0x12e
in another module. I'm just curious how is it possible :)

BTW: readelf and objdump utilities have no problem with reading such
binaries, but that is not possible if you put absolute addresses instead
of section relative address.

Jakub



More information about the Dwarf-Discuss mailing list