bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/25561] New: Incorrect DWARF info emitted when variable removed d


From: chrisc112358 at gmail dot com
Subject: [Bug ld/25561] New: Incorrect DWARF info emitted when variable removed due to --gc-sections
Date: Sat, 15 Feb 2020 20:54:50 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=25561

            Bug ID: 25561
           Summary: Incorrect DWARF info emitted when variable removed due
                    to --gc-sections
           Product: binutils
           Version: 2.33
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: chrisc112358 at gmail dot com
  Target Milestone: ---

Overview:

The "DW_AT_location" of a variable which is discarded as a result of using the
CFLAG -fdata-sections and the LDFLAG --gc-sections will be incorrectly set to
0. 

This will lead to incorrect results when trying to display the information for
the variable from a debugger.

Steps to Reproduce:

============================================================
// main.c
int *const g_const_variable = ((int *)0x40010000UL);

void main(void) {
  *g_const_variable = 10;
}
============================================================
$ mkdir -p build
$ arm-none-eabi-gcc -g -fdata-sections -nostdlib
-Wl,--gc-sections,-Map,build/example.map -Wl,-emain -Wl,-Ttext=0x0 main.c -o
build/example.elf
$ arm-none-eabi-readelf --debug-dump build/example.elf > build/dwarf_dump.txt
============================================================
Inspecting build/dwarf_dump.txt I see an incorrect "DW_AT_location" of 0 for
g_const_variable:

 <1><25>: Abbrev Number: 2 (DW_TAG_variable)
    <26>   DW_AT_name        : (indirect string, offset: 0x0): g_const_variable
    <2a>   DW_AT_decl_file   : 1
    <2b>   DW_AT_decl_line   : 1
    <2c>   DW_AT_decl_column : 12
    <2d>   DW_AT_type        : <0x3d>
    <31>   DW_AT_external    : 1
    <31>   DW_AT_location    : 5 byte block: 3 0 0 0 0  (DW_OP_addr: 0)
============================================================
In gdb you will see incorrect data displayed when viewing the variable
(gdb) p g_const_variable
$2 = (volatile int * const) 0xe52db004
(gdb) p &g_const_variable
$3 = (volatile int * const *) 0x0 <main>
============================================================

Expected Results:

I would expect the g_const_variable debug info to either be stripped from the
DWARF section or the DW_AT_location to be encoded such that the pointer address
can be recovered by a debugger.

Additional Notes:

I was using the latest release of the ARM gcc toolchain for testing
(https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)
but I tried some other gcc/ld versions as well and was seeing the same result

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]