incorrect DW_AT_location for static

183b68f
Opened by Tom Tromey at 2023-04-05 17:45:41

I'm using rust from the Fedora COPR:

bapiya. rustc --version
rustc 1.7.0 (a5d1e7a59 2016-02-29)

Consider this program:

pub static AA: i32 = 5;

fn main() {
}

I compile with -g and then examine the DWARF using readelf. I see:

 <2><2f>: Abbrev Number: 3 (DW_TAG_variable)
    <30>   DW_AT_name        : (indirect string, offset: 0x48): AA
    <34>   DW_AT_type        : <0x62>
    <38>   DW_AT_decl_file   : 1
    <39>   DW_AT_decl_line   : 1
    <3a>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 0 0  (DW_OP_addr: 0)
    <44>   DW_AT_linkage_name: (indirect string, offset: 0x4f): _ZN2b12AAE

Now, this variable is not actually emitted. There's no ELF symbol for it. Given this, it seems strange to emit DW_AT_linkage_name and DW_AT_location, especially considering that the latter is incorrect.

  1. Interesting. We are probably setting the static's linkage to private but don't take care of removing debuginfo for it and LLVM doesn't either.

    Michael Woerister at 2016-04-20 18:45:07

  2. #33172 has good reproduction instructions.

    Mark Rousskov at 2017-05-03 18:01:34

  3. Visited in wg-debugging's triage meeting. This still repros in 2022 but since it's just a matter of including more info than necessary, we don't believe this is breaking any debuggers so marking as P-low.

    Wesley Wiser at 2022-05-16 14:34:59