[Dwarf-Discuss] compilation unit base address related questions

Stoyan Shopov stoyan.shopov at gmail.com
Tue May 26 11:47:11 PDT 2009


Hi, guys, this is my first post on this mailing list. English is not my
native language, so please don't be too harsh if I err too much and you have
a tough time following me.

I have a question regarding the usage of compilation unit base address
computaions. The bottom line of my copy of the dwarf 3 standard document
reads "december 2005" - hope that's the latest one, and on page number 41 -
that should be the very last paragraph of section "3.1.1. Normal and partial
compilation unit entries" (xpdf reports this as page 53), written is
(verbatim):

"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."

That said, on page 26 (xpdf says 38) - section "2.6.6. Location Lists", I
can read:
"Location lists are used in place of location expressions whenever the
object whose location is
being described can change location during its lifetime."

My experience says C-language automatic variables, and frame base locations
are just one such artefacts that can change locations during their lifetimes
(please correct me if I am wrong!), so I decided to see what gcc does with
this concoction - a compilation unit spanning non-contiguous address ranges,
along with location lists describing the frame base address of a routine. I
coded this simple C program:

void sec1 (void) __attribute__ ((section (".sec1")));
void sec1 (void) {}
void sec2 (void) __attribute__ ((section (".sec2")));
void sec2 (void) {}

intending to create two different program sections containing two (very
empty) routines; I compiled this with:

gcc -g -nostdlib -o prog.elf prog.c

Then, I ran dwarfdump -a prog.elf, which said, amongst other things:
.debug_info

COMPILE_UNIT<header overall offset = 0>:
<0><   11>    DW_TAG_compile_unit
        DW_AT_stmt_list             0
        DW_AT_producer              GNU C 4.1.2 (Gentoo 4.1.2 p1.1)
        DW_AT_language              DW_LANG_C89
        DW_AT_name                  sec.c
        DW_AT_comp_dir
/home/shopov/src/gear-201108/engine/target_test

LOCAL_SYMBOLS:
<1><  103>    DW_TAG_subprogram
        DW_AT_external              yes(1)
        DW_AT_name                  sec1
        DW_AT_decl_file             1
/home/shopov/src/gear-201108/engine/target_test/sec.c
        DW_AT_decl_line             2
        DW_AT_prototyped            yes(1)
        DW_AT_low_pc                0x8048094
        DW_AT_high_pc               0x8048099
        DW_AT_frame_base            <loclist with 3 entries follows>
            [ 0]<lowpc=0x8048094><highpc=0x8048095>DW_OP_breg4+4
            [ 1]<lowpc=0x8048095><highpc=0x8048097>DW_OP_breg4+8
            [ 2]<lowpc=0x8048097><highpc=0x8048099>DW_OP_breg5+8
<1><  125>    DW_TAG_subprogram
        DW_AT_external              yes(1)
        DW_AT_name                  sec2
        DW_AT_decl_file             1
/home/shopov/src/gear-201108/engine/target_test/sec.c
        DW_AT_decl_line             4
        DW_AT_prototyped            yes(1)
        DW_AT_low_pc                0x8048099
        DW_AT_high_pc               0x804809e
        DW_AT_frame_base            <loclist with 3 entries follows>
            [ 0]<lowpc=0x8048099><highpc=0x804809a>DW_OP_breg4+4
            [ 1]<lowpc=0x804809a><highpc=0x804809c>DW_OP_breg4+8
            [ 2]<lowpc=0x804809c><highpc=0x804809e>DW_OP_breg5+8

----------------------- more follows

Easily seen is that any mentions of DW_AT_low_pc or DW_AT_ranges are forfeit
in the COMPILE_UNIT description
DIE.

My question is - is this correct? After all, the result of my efforts is a
perfectly valid executable file, the frame base
lists look perfectly all right as well (they don't overlap, are at sane
virtual address locations for my operating
environment, etc.), yet - according to standard (as I get it) - as the value
of the DW_AT_low_pc attribute,
is NOT present, the base address of the compilation unit is NOT defined
(i.e. it is undefined). If it is undefined,
then any DWARF entry defined in terms of the base address of that
compilation unit - which (as I get it - the frame base in this
minimalistic example is) is not valid. How come that?

Please note that this example may be probably invalid for execution (read -
can't run). It segfaults at my premises.

It's apparent that I am missing quite some things - please, guys, direct me.

Best regards to all of you, guys, and greetings from Bulgaria,
Health and luck to you all,

Stoyan Shopov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dwarfstd.org/private.cgi/dwarf-discuss-dwarfstd.org/attachments/20090526/6d4e19f5/attachment-0001.htm>


More information about the Dwarf-Discuss mailing list