[Dwarf-Discuss] compilation unit base address related questions

Michael Eager eager@eagercon.com
Wed May 27 11:54:28 GMT 2009

Stoyan Shopov wrote:
> Thank you very much for your answers. I am not sure if replying directly 
> to dwarf-discuss at lists.dwarfstd.org 
> <mailto:dwarf-discuss at lists.dwarfstd.org> with the subject "Re: 
> [Dwarf-Discuss] compilation unit base address related questions" is ok - 
> I hope it works and this message will go into the proper thread (to be 
> honest, I have never used such mailing lists...).

It works fine.

>     DW_AT_low_pc gives the address where the *code* for a compilation unit
>     or a function is loaded.  It is not related to the location of *data*.
> I probably have not been clear enough. Section 2.6.6 - Location Lists 
> (in the dwarf 3 standard) says:
> "The applicable base address of a location list entry is determined by 
> the closest preceding base address 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 (see Section 3.1)."
> And once more, section 3.1:
> "The base address of a compilation unit is defined as the value of the 
> DW_AT_low_pc attribute, if present; otherwise, it is undefined. If the 
> base address is undefined, then any DWARF entry or structure defined in 
> terms of the base address of that compilation unit is not valid."
> So, it may be said that DW_AT_low_pc is indirectly related to the 
> location of data (say, a frame base for some function) via this scheme:
> DW_AT_low_pc ---> defines the base address for the compilation unit ---> 
> serves as base address of location list entries ---> location lists 
> describe location of data

A location list tells you how to find the specified data which may
vary at different times during the program's execution.

The location list entry consists of two parts.  The first part (the
start and end offset) are the range of PC values where the location list
is valid.  The second part is an expression used to compute the
location of data.

The start and end offsets are relative to the base address for the
location list, which defaults to the start of the compilation unit.

The base address is not used in the computation of the data location.

> I wondered what happens if DW_AT_low_pc is missing (and thus the 
> compilation unit base address is undefined) - which turned out to be an 
> old GCC deficiency.

GCC is generating relocatable values for the start/end offset.
It would be more efficient (from a linker point of view) to generate
a single base address location list entry with a single relocation,
followed by non-relocated offsets.

It's arguable that GCC is generating incorrect DWARF. Or perhaps
the description of base address is not quite correct.

>     What DWARF entry do you believe is not well defined?
> Well, location lists - e.g. frame base addresses. Here is a dwarfdump 
> sample for the C program
> int main(void) { return 1: }
> dwarfdump output (some lines omitted):
> .debug_info
> COMPILE_UNIT<header overall offset = 0>:
> <0><   11>      DW_TAG_compile_unit
> ........................................................................
>                 DW_AT_high_pc               0x80480ad
>                 DW_AT_low_pc                0x8048094
> ........................................................................
> <1><   92>      DW_TAG_subprogram
>                 DW_AT_name                  main
>                 DW_AT_low_pc                0x8048094
>                 DW_AT_high_pc               0x80480ad
>                 DW_AT_frame_base            <loclist with 5 entries follows>
>                         [ 0]<lowpc=0x0><highpc=0x4>DW_OP_breg4+4
>                         [ 1]<lowpc=0x4><highpc=0xa>DW_OP_reg1
>                         [ 2]<lowpc=0xa><highpc=0xb>DW_OP_breg4+4
>                         [ 3]<lowpc=0xb><highpc=0xd>DW_OP_breg4+8
>                         [ 4]<lowpc=0xd><highpc=0x19>DW_OP_breg5+8
> Here, the first frame base location list entry reads: "[ 
> 0]<lowpc=0x0><highpc=0x4>DW_OP_breg4+4" - that is: when the program 
> counter is in the half-open interval [0; 4) - the frame base register 
> equals the value of the expression "DW_OP_breg4+4". However, the 
> addresses in the mentioned interval must be offset by the compilation 
> unit base address - in this case 0x8048094.

Correct.  This is exactly what the text in section 2.2.6 which you
quoted says to do.

Michael Eager	 eager at eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077

More information about the Dwarf-discuss mailing list