Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upDon't set the linkage_name for static variables #46457
Conversation
rust-highfive
assigned
pnkfelix
Dec 3, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
kennytm
added
the
S-waiting-on-review
label
Dec 3, 2017
m4b
referenced this pull request
Dec 4, 2017
Open
DWARF: `no_mangle` items are given mangled `linkage_name`s and namespace scopes #46487
shepmaster
added
the
T-compiler
label
Dec 9, 2017
This comment has been minimized.
This comment has been minimized.
|
Ping from triage! It's been over 7 days since we heard from reviewer @pnkfelix. Please assign a new reviewer @rust-lang/compiler. |
This comment has been minimized.
This comment has been minimized.
|
@m4b Can you squash your commits into one? I'd also like to see some capitalization on the comments, as the is apparently the style rustc goes for. |
This comment has been minimized.
This comment has been minimized.
|
Not my area of expertise, but it looks good to merge after @Zoxc comments are addressed. |
This comment has been minimized.
This comment has been minimized.
|
@Zoxc sure - but just curious doesn’t git allow to squash automatically ? Or does that not integrate with bors? (I know next to nothing about rust + bors merging, review commands, etc) |
This comment has been minimized.
This comment has been minimized.
|
@m4b Squashing commits is a destructive operation (it destroys history), so it would be terrible if it was done automatically. |
This comment has been minimized.
This comment has been minimized.
|
No I mean when I merge PRs in my repos it allows me to squash their PR into a single commit (essentially what you’re asking me to do manually). Hence my question is why can’t the PR merger just do it. It’s not a big deal was just wondering if there’s some other reason I’m not seeing |
m4b
force-pushed the
m4b:no_mangle_static
branch
from
590d1fa
to
fbac12b
Dec 9, 2017
This comment has been minimized.
This comment has been minimized.
|
I think @m4b is referring to the Settings > Options > Merge Button > "Allow squash merging" option that Github has for each repository. We use it all the time where I work, but I think it wasn't on by default and we had to go turn it on (and eventually we even disabled "Allow merge commits" so that we can't ever forget to squash a PR). I have no idea if the Rust team has considered enabling that option, but if contributors are expected to manually squash their PRs today then it'd probably be an improvement. |
This comment has been minimized.
This comment has been minimized.
There is no project-wide blanket rule for squashing. I believe the general idea is to have commits that "tell a cohesive story". A series of "oh, fixed that test, addressed review" isn't that useful long term, but neither is a single 10KLOC commit that is "I changed a bunch of stuff". I don't know what was here before, but at first approximation a commit that is "+18 −7" seems unlikely to need multiple commits. |
This comment has been minimized.
This comment has been minimized.
Rust doesn't use the standard GitHub merge process, so any such functionality would need to be added to bors, yes. |
This comment has been minimized.
This comment has been minimized.
|
As @shepmaster is alluding to sometimes you do want to keep the commit history for a given PR, so making bors do it on its own would be detrimental. @alexcrichton could you take a look at this PR? It seems reasonable to me. |
This comment has been minimized.
This comment has been minimized.
|
We should also check that this behaves correctly for CodeView debug information. |
This comment has been minimized.
This comment has been minimized.
|
We should probably just add tests in general for this stuff ;) |
This comment has been minimized.
This comment has been minimized.
|
@m4b Yeah. You can add a gdb test for this at least (see https://github.com/rust-lang/rust/tree/master/src/test/debuginfo), assuming there's some observable difference in gdb. |
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
michaelwoerister
and unassigned
pnkfelix
Dec 10, 2017
This comment has been minimized.
This comment has been minimized.
|
@m4b, thanks for the PR! The code looks good to me. If you could find a way to test in a |
This comment has been minimized.
This comment has been minimized.
|
I added a file based off of other files in the suggested directory, but I'm going to need someone to explain to me how debuginfo tests work. Specifically, I changed: https://github.com//m4b/rust/blob/fbac12b980a06c4f2e8efb4eee6974507b38e979/src/test/debuginfo/gdb-pretty-struct-and-enums-pre-gdb-7-7.rs#L23 To not the expected value and running
which makes me suspicious that my test is doing anything in the first place. |
This comment has been minimized.
This comment has been minimized.
|
@tromey does the rust gdb language setting hardcode namespace assumptions? I'm seeing really weird behavior by the rust language setting, e.g.: For a simple rust program: #[no_mangle]
pub static TEST: u64 = 0xdeadbeef;
pub fn main() {
println!("{}", TEST);
}we see this (correct) debuginfo:
which matches the c++ output for no-mangled static variables. However, consider this gdb transcript:
It seems like there is something wrong with the rust language setting in gdb, since even the c and c++ language settings allow the symbol to be properly printed... |
tromey
reviewed
Dec 13, 2017
| // gdb-check:$1 = 3735928559 | ||
|
|
||
| // gdb-command: ptype NO_MANGLE_DEADBEEF | ||
| // gdb-check:$2 = u6 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
m4b
Dec 13, 2017
Author
Contributor
Ha yup sorry was trying to get tests to fail on my machine as per above comment, will fix
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
m4b
Dec 13, 2017
Author
Contributor
Yes but it doesn’t on my local machine, using above instructions. I do not know why...
m4b
force-pushed the
m4b:no_mangle_static
branch
from
0660e4c
to
ee84cf3
Dec 13, 2017
This comment has been minimized.
This comment has been minimized.
It shouldn't but I think the best thing would be if you could email me the executable and then I'll just debug gdb and see what is going on. |
This comment has been minimized.
This comment has been minimized.
|
If someone could help explain the CI failure I’m at a total loss. I don’t see any expected output, it says the test panicked (I don’t even know what that means in this context) and as I wrote above I’m unable to even get tests running on my local machine. :headache: |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
I debugged this a bit in gdb and I now wonder if a different approach would be preferable for this patch (plus maybe a gdb extension as well). gdb's expression parser tries to implement rust-like semantics. And, while "no mangle" affects the linkage name, I don't think it affects the name of the item as known to Rust. That is, I think the linkage name is If that's so, then I think it would be better to keep The gdb extension then would be to allow referring to items by linkage name in the Rust expression parser. In my test with g++ this is somewhat consistent with what C++ does. (g++ doesn't seem to emit the linkage name, but surely that's a g++ bug)
|
This comment has been minimized.
This comment has been minimized.
This is a very interesting point actually. To extrapolate a bit, iiuc, there's tension here between rusts linkage/crate module and binary linkage models. E.g., if I define This closely mirrors the usage you gave with the cpp code, so I think I agree that the namespace should be included. However, for cases like when you have the following in your crate: extern "C" {
static FOO: u64;
}I think this matches the C++ case of an unnamespaced static variable, and this should definitely not have a namespace (it literally gets defined at link time, with that exact name, with no module prefixes and explodes when there are multiple symbols). So the problem still remains that the rust gdb extension is not capable of printing unnamespaced statics for some reason (which I'll note was the original impetus of the issue). Since the c and c++ gdb extensions have no issue, and report it as a static variable with debugging info, but when switching to the rust language setting the variable either disappears or reports it has no debugging info, this strongly suggests to me the extension is failing in these cases and should be fixed (and not worked around). I would be happy to take a look at this if you're busy and could give me an initial pointer to take a look at.
Why ? This seems to exactly match expectations and the dwarf spec - its linkage name would have to be just its name, in which case it is omitted. clang also agrees, and does not emit a linkage name. |
m4b
force-pushed the
m4b:no_mangle_static
branch
3 times, most recently
from
15b51a4
to
038aae0
Dec 15, 2017
This comment has been minimized.
This comment has been minimized.
|
This is with the latest changes:
Which is the same situation as before w.r.t. gdb not working only in rust language mode. The dwarf info is correct:
@tromey its clear to me this is entirely a gdb issue that needs to be resolved over there and theres nothing more to be done on rustc's or this PRs end. I propose to merge this once (I ask again) someone can help to explain the build failure to me. EDIT: For completeness, here is the g++ debug info for the c++ file above:
Actually, I just realized we don't emit file and line attributes for the namespace; I'm not sure why that would cause a problem rust side, but it is important to note that it is slightly different. Nevertheless I think this should be merged |
This comment has been minimized.
This comment has been minimized.
|
So what exactly is the state here? The build error looks like just the new debuginfo test failing. Do you think there is another version of the test that would pass? Setting the language in the test after "run" looks like a potential race condition. I'm trying to reproduce this locally at the moment. |
This comment has been minimized.
This comment has been minimized.
|
@m4b I cannot reproduce the error locally. You could try to move the |
This comment has been minimized.
This comment has been minimized.
|
@michaelwoerister ok, will try; thanks for looking into this! Alternatively, could add different print and wait until the debugging issues in gets figured out, and then update back to what it is now. |
m4b
force-pushed the
m4b:no_mangle_static
branch
4 times, most recently
from
a827264
to
1310588
Dec 15, 2017
This comment has been minimized.
This comment has been minimized.
I don't actually know this area of Rust, but the question really revolves around the language semantics of
The way I see it is that C++ source refers to this as I'd appreciate your thoughts on this. TBH I was surprised that that C++ snippet compiled at all, since my mental model didn't allow for extern C objects in namespaces. So maybe I'm further confused somewhere. |
m4b
force-pushed the
m4b:no_mangle_static
branch
from
1310588
to
500dc14
Dec 20, 2017
This comment has been minimized.
This comment has been minimized.
|
@michaelwoerister I removed the test file; I cannot get it working and I can't repro here so i'm at a loss.
I am not even remotely a C++ expert but afaik, extern C in C++ affects the linkage model, not the namespace; so I believe you can have two extern C for a symbol Similar things go for rust, e.g., stuff like this happens: das-labor/panopticon#314 (comment) (tl;dr two different versions of goblin were getting pulled into the binary project, and since they both I'll email you the latest binary; as I said, I think the gdb plugin for rust language settings has a bug, and isn't displaying it properly, as the c++/c correctly access everything, as I pasted above. |
This comment has been minimized.
This comment has been minimized.
|
Based on 10.5/6 of the C++17 draft, C++ allows multiple declarations with C linkage in different namespaces, but these refer to the same function, and there can still only one be definition. I think a similar thing in rust would be: mod foo {
extern {
pub fn test();
}
}
pub mod bar {
#[no_mangle]
pub fn test() {
println!("test");
}
}
fn main() {
unsafe { foo::test(); }
} |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Dec 20, 2017
kennytm
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Dec 20, 2017
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit 500dc14
into
rust-lang:master
Dec 20, 2017
m4b
deleted the
m4b:no_mangle_static
branch
Dec 20, 2017
This comment has been minimized.
This comment has been minimized.
|
@philipc thanks for the example, that aligns with what my understanding for rust cases has come to. Unfortunately, and I suspect for many others (but this is obviously speculation) when I write no mangle I go to a “c place” in my mind and would never expect the no mangle to have a namespace prefix, and hence when I pop open gdb I’d just expect to write the bare, unmangled name. I don’t know a good solution/compromise for this at the moment. Maybe there is none and it’s just education that everything is namespaced in rust at the debugging level ? |
This comment has been minimized.
This comment has been minimized.
|
I've pushed a gdb patch to address one of the issues pointed out by this PR: https://sourceware.org/ml/gdb-patches/2018-01/msg00418.html I'm not sure I covered everything, so if you know of something more, please ping me. Thanks! |
m4b commentedDec 3, 2017
•
edited
For
no_manglestatics:This matches C++ output, which does not set the linkage_name and is not scoped:
e.g. c++:
and (now) Rust: