Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no_mangle static symbols have improper debug info #33172

Closed
m4b opened this issue Apr 23, 2016 · 10 comments · Fixed by #97085
Closed

no_mangle static symbols have improper debug info #33172

m4b opened this issue Apr 23, 2016 · 10 comments · Fixed by #97085
Assignees
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@m4b
Copy link
Contributor

m4b commented Apr 23, 2016

Repro

  1. cargo new --bin static

  2. cd static

  3. add the following code to main.rs:

    #[no_mangle]
    pub static TEST: u64 = 0xdeadbeef;
    
    pub fn main() {
    println!("TEST: {}", TEST);
    }
  4. cargo build

  5. gdb target/debug/static

  6. break static::main

  7. r

  8. whatis TEST

  9. output: type = <data variable, no debug info>

  10. frown

When TEST is a repr(C) struct, etc., this makes debugging extraordinarily difficult and laborious.

Actual Use Case

I'm implementing the gdb debugger interface specified in /usr/include/link.h, which requires a single symbol, _r_debug to be present in the _DYNAMIC array.

(The symbol is actually not exported either, roughly GLOBAL and in the _DYNAMIC array, which I get around by using a --dynamic-list flag to the linker.)

I don't get around the lack of debug symbols at all, which vexes me.

@nagisa nagisa added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Apr 23, 2016
@tromey
Copy link
Contributor

tromey commented Apr 24, 2016

This is issue #32574.

Note that gdb supports a second, improved interface to detecting shared library events. I don't remember exactly when this went in but here's one of the series; if you're interested this should help find the final patches:

http://www.cygwin.com/ml/gdb-patches/2012-07/msg00157.html

There's a Rust crate for making stap-style probes.

@Mark-Simulacrum
Copy link
Member

I'm going to close in favor of #32574. Thanks for the issue, though.

@m4b
Copy link
Contributor Author

m4b commented Dec 2, 2017

I believe that we should re-open this issue in light of #46453

@m4b m4b changed the title static symbols do not have debug info no_mangle static symbols have improper debug info Dec 2, 2017
@Mark-Simulacrum
Copy link
Member

Doesn't #46453 already cover the problem listed here? Or is it different? If it's different I'm happy to reopen.

@m4b
Copy link
Contributor Author

m4b commented Dec 3, 2017

I think that this is actually an extra bug, in that the no_mangle seems to be ignored and it is given linkage_name, whereas it shouldn't receive any at all.

Even if #46453 is fixed, I believe this issue will persist, because it would still be given a mangled linkage_name which will reference a symbol that won't ever exist, since the name isn't mangled in the symbol table, and hence it shouldn't be given one at all.

Does that make sense?

@m4b
Copy link
Contributor Author

m4b commented Dec 3, 2017

To illustrate, here is the rust no_mangle static version:

DW_TAG_variable [3]  
  DW_AT_name [DW_FORM_strp]	( .debug_str[0x00000061] = "TEST")
  DW_AT_type [DW_FORM_ref4]	(cu + 0x0049 => {0x00000049})
  DW_AT_external [DW_FORM_flag_present]	(true)
  DW_AT_decl_file [DW_FORM_data1]	("/home/m4b/tmp/bad_debug/test.rs")
  DW_AT_decl_line [DW_FORM_data1]	(8)
  DW_AT_alignment [DW_FORM_udata]	(1)
  DW_AT_location [DW_FORM_exprloc]	(<0x9> 03 c0 65 05 00 00 00 00 00 )
  DW_AT_linkage_name [DW_FORM_strp]	( .debug_str[0x00000066] = "_ZN4test4TESTE")

and the C++ unmangled static:

DW_TAG_variable [9]  
  DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000053] = "TEST")
  DW_AT_type [DW_FORM_ref4]       (cu + 0x0048 => {0x00000048})
  DW_AT_external [DW_FORM_flag_present]   (true)
  DW_AT_decl_file [DW_FORM_data1] ("/home/m4b/tmp/bad_debug/test.cpp")
  DW_AT_decl_line [DW_FORM_data1] (14)
  DW_AT_location [DW_FORM_exprloc]        (<0x9> 03 40 10 20 00 00 00 00 00 )

Iiuc, everything is perfectly correct, except we just have to not emit the DW_AT_linkage_name in no_mangle cases.

@hanna-kruppe
Copy link
Contributor

I believe that a "principled" fix for #46453 would also automatically solve this issue. There's already code in the compiler that computes the real symbol name of all the functions and statics we emit. Using that code for the DWARF linkage_name would give the right linkage_name to all symbols, no_mangle ones included. That would set a linkage_name identical to the DWARF name, which would differ from C++, but I can't imagine that would cause harm?

@tromey
Copy link
Contributor

tromey commented Dec 3, 2017

That would set a linkage_name identical to the DWARF name, which would differ from C++, but I can't imagine that would cause harm?

It should be fine, but in cases where the two are equal, it is fine to omit the linkage name, and this uses less space. This is what C compilers do.

@hanna-kruppe
Copy link
Contributor

Regardless, that's just a small if. The important part is unifying the symbol/linkage name computation.

m4b added a commit to m4b/rust that referenced this issue Dec 20, 2017
@XAMPPRocky XAMPPRocky added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jan 22, 2018
@wesleywiser
Copy link
Member

Visited during the wg-debugging triage meeting and this seems to have been resolved. @rylev is going to add a regression test.

@wesleywiser wesleywiser added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label May 16, 2022
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this issue Jun 21, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 21, 2022
Add a test for issue rust-lang#33172

Adds a test confirming that rust-lang#33172 has been fixed.

CDB has some surprising results as it looks like the supposedly unmangled static's symbol name is prefixed when it shouldn't be.

r? ``@wesleywiser``

Closes rust-lang#33172
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jun 24, 2022
Add a test for issue rust-lang#33172

Adds a test confirming that rust-lang#33172 has been fixed.

CDB has some surprising results as it looks like the supposedly unmangled static's symbol name is prefixed when it shouldn't be.

r? `@wesleywiser`

Closes rust-lang#33172
compiler-errors added a commit to compiler-errors/rust that referenced this issue Jun 25, 2022
Add a test for issue rust-lang#33172

Adds a test confirming that rust-lang#33172 has been fixed.

CDB has some surprising results as it looks like the supposedly unmangled static's symbol name is prefixed when it shouldn't be.

r? ``@wesleywiser``

Closes rust-lang#33172
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jun 25, 2022
Add a test for issue rust-lang#33172

Adds a test confirming that rust-lang#33172 has been fixed.

CDB has some surprising results as it looks like the supposedly unmangled static's symbol name is prefixed when it shouldn't be.

r? ```@wesleywiser```

Closes rust-lang#33172
bors pushed a commit to rust-lang-ci/rust that referenced this issue Aug 5, 2022
@bors bors closed this as completed in 6bcf01a Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants