[Dwarf-Discuss] compilation unit base address related questions

Stoyan Shopov stoyan.shopov@gmail.com
Wed May 27 09:18:38 GMT 2009

Thank you very much for your answers. I am not sure if replying directly to
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...).

2009/5/26 Roland McGrath <roland at redhat.com> wrote:
> You then cited that the CU has
> no DW_AT_ranges attribute.  That is completely irrelevant to the question
> of a CU base address.  Indeed, the CU in your example ought to have a
> DW_AT_ranges attribute and it is some old GCC bug that it has none.
> Thanks,
> Roland

Agreed, it is indeed irrelevant. It also seems that the missing address
ranges are some old GCC misbehavior, the examples I posted used gcc 4.1.2, I
tried GCC 4.3.2 today and the address ranges got properly generated.

2009/5/26 Michael Eager <eager at eagercon.com> wrote:

> 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

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

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

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):


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.

In the examples I gave for the non-contiguous compilation unit, no such base
address was present, so I wondered if this is normal, but as it turns out,
this is maybe just some GCC deficiency that has already been resolved.

2009/5/26 Jason Merrill <jason at redhat.com>

> The frame base for a function is not defined in terms of the base address
> of the compilation unit.

Yes, again - I have not been too clear. I hope it is now clear what I meant
with the examples I gave (frame base address as a function of the program
counter address within a subroutine - and this address within the subroutine
is actually defined in terms of the base address of the compilation unit).

By the way, is anybody aware of an example where GCC is emits machine code
for some function that spans several, non-contiguous address ranges - is GCC
capable of doing this?


Stoyan Shopov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dwarfstd.org/private.cgi/dwarf-discuss-dwarfstd.org/attachments/20090527/7afcfec3/attachment.htm>

More information about the Dwarf-discuss mailing list