Location lists again

Daniel Berlin dberlin@dberlin.org
Thu Feb 13 16:43:00 GMT 2003


On Thursday, February 13, 2003, at 11:28  AM, Michal Ludvig wrote:

> Hi Daniel,
> I propose a small modification to .debug_loc output. Now it's 
> generated in a form of:
>         .section        .debug_loc,"",@progbits
> .LLST0:
>         .quad   .LVL0-.text     # Location list begin address (*.LLST0)
>         .quad   .LVL1-.text     # Location list end address (*.LLST0)
>         .value  0x1     # Location expression size
>         .byte   0x55    # DW_OP_reg5
> [...]
>
> So the address range is recorded as offsets from beginning of .text 
> section in a given .o file.

Which is correct.

> When I link several of .o files together, these offsets don't get 
> updated to reflect curent position and current offset in the resulting 
> binary.

They shouldn't. They default to being based off the base address of the 
compilation unit they are associated with.
Thus, the reason they subtract .text is because they belong to a 
compilation unit whose base address is .text.

"
A location list entry consists of:

1.  A beginning address. This address is relative to the applicable 
base address of the compilation unit referencing this location list. It 
marks the beginning of the address range over which the location is 
valid.
"

> Would it be possible to change the output to absolute addresses?

Err, no, actually.  That would make them invalid.
What I can do (going by the standard) actually won't help you. :(
I can output needless base address selection entries for .text, but 
it's still going to display them in readelf as pure offsets, not the 
actual addresses.

("The applicable base address of a location list entry is determined by 
the closest preceding baseaddress selection entry (see below) in the 
same location list. If there is no such selection entry,then the 
applicable base address defaults to the base address of the compilation 
unit (seeSection 3.1).

In the case of a compilation unit where all of the machine code is 
contained in a single contiguous section, no base address selection 
entry is needed.")

It doesn't help a debugger to do base selection entries for .text (we 
do output them if we need  a base address of some other section, which 
can happen with -ffunction-sections), since it knows the right base 
address anyway.


>
>         .section        .debug_loc,"",@progbits
> .LLST0:
>         .quad   .LVL0   # Location list begin address (*.LLST0)
>         .quad   .LVL1   # Location list end address (*.LLST0)
>         .value  0x1     # Location expression size
>         .byte   0x55    # DW_OP_reg5
> [...]
>
> This way the addresses would be correctly updated on linking.

They are correct, though readelf -w will only show the offsets, because 
it doesn't know what CU they go with (IE debug_loc parsing is 
completely removed from debug_info parsing).

When a debugger actually loads them, it is supposed to add the base 
address of the CU to each one.
> If I manually change the .s file generated from .c, remove '-.text' 
> and compile it seems to work perfectly.
>
> Thanks in advance!
>
> Michal Ludvig
> -- 
> * SuSE CR, s.r.o     * mludvig@suse.cz
> * (+420) 296.545.373 * http://www.suse.cz
>



More information about the Gcc mailing list