Bug#639818: gcc-4.6: bad DWARF3 debug DW_AT_location for local variable on armel
Followup-For: Bug #639818
Package: gcc-4.6
Version: 4.6.1-4
*** Please type your report below this line ***
"gcc -g -O" sometimes gives incorrect DWARF3 debug info for the DW_AT_location
of an on-stack local variable on armel architecture.
=====bug2.c
extern void ext(char *);
void croak ( char *p )
{
ext(p);
*(char *)p += 42;
}
void baz ( void )
{
int v1;
v1 = 1;
{
char v2[10]; // not a multiple of 4
v2[0] = 2;
croak( &v2[0] );
}
croak( (char*)&v1 );
}
int main ( void )
{
baz();
return 0;
}
=====end bug2.c
Compile with "gcc -g -c -S -O bug2.c" and inspect generated code.
Note my annotations after "#":
=====bug2.s
.align 2
.global baz
.type baz, %function
baz:
.LFB1:
.loc 1 10 0
.cfi_startproc
@ Function supports interworking.
@ args = 0, pretend = 0, frame = 16
@ frame_needed = 0, uses_anonymous_args = 0
str lr, [sp, #-4]!
.LCFI1:
.cfi_def_cfa_offset 4
.cfi_offset 14, -4
sub sp, sp, #20
.LCFI2:
.cfi_def_cfa_offset 24 # total sp displacement is 24 bytes
.loc 1 12 0
mov r3, #1
str r3, [sp, #12] # v1 DW_AT_location should be (12 - 24) = -12
.LVL2:
.LBB2:
.loc 1 15 0
add r0, sp, #16
mov r3, #2
strb r3, [r0, #-16]! # v2 DW_AT_location should be (16 - 16 - 24) = -24
.loc 1 16 0
mov r0, sp
bl croak
.LBE2:
.loc 1 18 0
add r0, sp, #12
bl croak
.loc 1 19 0
add sp, sp, #20
ldr lr, [sp], #4
bx lr
.cfi_endproc
.LFE1:
.size baz, .-baz
[[snip]]
.uleb128 0x7
.ascii "v1\000"
.byte 0x1
.byte 0xb
.4byte 0x97
.byte 0x2
.byte 0x91
.sleb128 -20 # ERROR: v1 DW_AT_location is -20; should be -12
.uleb128 0x8
.4byte .LBB2
.4byte .LBE2
.uleb128 0x7
.ascii "v2\000"
.byte 0x1
.byte 0xe
.4byte 0x9e
.byte 0x2
.byte 0x91
.sleb128 -24 # OK: v2 DW_AT_location is -24
.byte 0
.byte 0
=====
The error is confirmed by assembling "gcc -c bug2.s", then dumping the debug info:
===== readelf -wlLiaprmfFsoRt bug2.o >bug2.elf
<2><72>: Abbrev Number: 7 (DW_TAG_variable)
<73> DW_AT_name : v1
<76> DW_AT_decl_file : 1
<77> DW_AT_decl_line : 11
<78> DW_AT_type : <0x97>
<7c> DW_AT_location : 2 byte block: 91 6c (DW_OP_fbreg: -20) # should be -12
<2><7f>: Abbrev Number: 8 (DW_TAG_lexical_block)
<80> DW_AT_low_pc : 0x30
<84> DW_AT_high_pc : 0x44
<3><88>: Abbrev Number: 7 (DW_TAG_variable)
<89> DW_AT_name : v2
<8c> DW_AT_decl_file : 1
<8d> DW_AT_decl_line : 14
<8e> DW_AT_type : <0x9e>
<92> DW_AT_location : 2 byte block: 91 68 (DW_OP_fbreg: -24) # OK
=====
-- System Information:
Debian Release: wheezy/sid
APT prefers oldstable
APT policy: (500, 'oldstable'), (500, 'testing')
Architecture: armel (armv5tel)
Kernel: Linux 2.6.32-5-kirkwood
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages gcc-4.6 depends on:
ii binutils 2.21.52.20110606-2 The GNU assembler, linker and bina
ii cpp-4.6 4.6.1-4 GNU C preprocessor
ii gcc-4.6-base 4.6.1-4 GCC, the GNU Compiler Collection (
ii libc6 2.13-21 Embedded GNU C Library: Shared lib
ii libcloog-ppl0 0.15.9-3 the Chunky Loop Generator (runtime
ii libgcc1 1:4.6.1-4 GCC support library
ii libgmp10 2:5.0.2+dfsg-1 Multiprecision arithmetic library
ii libgmpxx4ldbl 2:5.0.2+dfsg-1 Multiprecision arithmetic library
ii libgomp1 4.6.1-4 GCC OpenMP (GOMP) support library
ii libmpc2 0.9-3 multiple precision complex floatin
ii libmpfr4 3.0.1-6 multiple precision floating-point
ii libppl-c4 0.11.2-4 Parma Polyhedra Library (C interfa
ii libppl9 0.11.2-4 Parma Polyhedra Library (runtime l
ii libstdc++6 4.6.1-4 GNU Standard C++ Library v3
ii zlib1g 1:1.2.3.4.dfsg-3 compression library - runtime
Versions of packages gcc-4.6 recommends:
ii libc6-dev 2.13-21 Embedded GNU C Library: Developmen
Versions of packages gcc-4.6 suggests:
pn binutils-gold <none> (no description available)
pn gcc-4.6-doc <none> (no description available)
pn gcc-4.6-locales <none> (no description available)
ii libgcc1-dbg 1:4.6.1-4 GCC support library (debug symbols
ii libgomp1-dbg 4.6.1-4 GCC OpenMP (GOMP) support library
pn libmudflap0-4.6-dev <none> (no description available)
ii libmudflap0-dbg 4.6.1-4 GCC mudflap shared support librari
pn libquadmath-dbg <none> (no description available)
-- no debconf information
Reply to: