Mangle rustc_std_internal_symbols functions#127173
Conversation
|
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
|
Some changes occurred in compiler/rustc_codegen_gcc |
This comment has been minimized.
This comment has been minimized.
aea9a3c to
db57b2a
Compare
This comment has been minimized.
This comment has been minimized.
db57b2a to
4859689
Compare
This comment has been minimized.
This comment has been minimized.
|
☔ The latest upstream changes (presumably #127162) made this pull request unmergeable. Please resolve the merge conflicts. |
4859689 to
10bad43
Compare
This comment has been minimized.
This comment has been minimized.
|
The Miri subtree was changed cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
|
r? compiler |
|
Opened rust-lang/miri#3724 with some miri changes that can be made independently of this PR. |
Use the symbol_name query instead of trying to infer from the link_name attribute This prevents the calculated name from going out of sync with exported_symbols. It also avoids having to special case the panic_impl lang item. It also makes it easier to fix miri with rust-lang/rust#127173.
|
☔ The latest upstream changes (presumably #125507) made this pull request unmergeable. Please resolve the merge conflicts. |
Use the symbol_name query instead of trying to infer from the link_name attribute This prevents the calculated name from going out of sync with exported_symbols. It also avoids having to special case the panic_impl lang item. It also makes it easier to fix miri with rust-lang#127173.
e1d353a to
f8f4b88
Compare
This comment has been minimized.
This comment has been minimized.
f8f4b88 to
266c7c2
Compare
This comment has been minimized.
This comment has been minimized.
266c7c2 to
9c91546
Compare
There was a problem hiding this comment.
The changes here look like they will end up calling mangle_internal_symbol around 10 times for every single time that a shim is invoked in Miri. That does not seem great?
There was a problem hiding this comment.
Right. Didn't think about that. I guess it would be possible to first check if the unmangled name is a substring and only then call mangle_internal_symbol.
There was a problem hiding this comment.
Having a cache for the mangled name in Miri would also work, and would avoid having to rely on any particular property of the mangled name.
| } | ||
|
|
||
| let attrs = tcx.codegen_fn_attrs(def_id); | ||
| // FIXME use tcx.symbol_name(instance) instead |
There was a problem hiding this comment.
I'm not sure how to understand this comment. Is there some reason this can't just be changed now?
There was a problem hiding this comment.
iter_exported_symbols returns DefId's, not Instance's like tcx.symbol_name() needs.
There was a problem hiding this comment.
These are monomorphic symbols though, right? So we could use Instance::mono.
|
Oh man, this broke some things for us. We have a pipeline where we need to link a static Rust library to a full Rust program (we had been doing symbol renaming to get this functional) as we need different sanitization levels between the two. cc @tokatoka @rmalmain, this is our CI failure w/ libafl_libfuzzer. |
|
@addisoncrump It sounds like you are deep in unspecified territory and are bypassing things that have been explicitly introduced to avoid unstable implementation details leaking out. This is definitely off-label usage of rustc. Might be worth having a discussion on Zulip or so to figure out if there isn't a less cursed way to support your usecase. |
Please don't comment on an already merged PR, it's impossible to find and has no visibility. Consider opening an issue or zulip thread if you want to discuss your use case. |
Yup, we slammed this one together because of some niche linkage requirements from a sanitizer. I'll ask on Zulip, but we had previously discussed this with others and this was the best conclusion we came up with 🙃
Sure, we figured this change was generally accepted and our use case is outside of what is considered normally permissible. Just left a comment as that: a comment. No action required, we work around it. |
|
I've opened a Zulip thread for this discussion: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Linking.20Rust.20libraries.20with.20different.20sanitizers |
|
This PR broke panic handlers that also happen to have #[panic_handler]
#[no_mangle]
fn panic(info: &PanicInfo) -> ! {
todo!()
}Removing the rust-osdev/bootloader v0.9 is affected by this issue: rust-osdev/bootloader#499. |
This was brought up on Zulip, would you mind following up there? #t-compiler > no_mangle rust_begin_unwind |
|
fwiw, chromium is also broken by this due to defining the allocator functions in c++: https://crbug.com/407024458 |
|
Right, I did at some point see that Chromium defined them in C++, but completely forgot about it. Are you able to fix this on your end before the next stable release of rustc? If not I could add a temporary exception for mangling of the allocator symbols. This exception will have to be removed at some point though. |
|
Can't Chromium define The |
If the fix Ralf suggested works out, I think we're good.
I'm not an expert on our Rust build, but yes that sounds like a good solution. Based on https://source.chromium.org/chromium/chromium/src/+/main:build/rust/std/remap_alloc.cc;l=61 it sounds like that was already the plan, but we didn't get to it yet :) |
IIUC (*) Because linking is the only step when
FWIW having Chromium provide a weak definition of
I don't know. Is there another mechanism that Chromium can use to ask (Chromium doesn't use the stable release of |
|
If you're using a nightly rustc, maybe we can gate this temporary work-around on a But yeah someone will have to push on #73632 to solve this properly. That might make a good project goal for 2025h2, if the Chromium team is willing to put in the work. :) |
|
|
That would be very helpful for us. Thanks! |
This reduces the risk of issues when using a staticlib or rust dylib compiled with a different rustc version in a rust program. Currently this will either (in the case of staticlib) cause a linker error due to duplicate symbol definitions, or (in the case of rust dylibs) cause rustc_std_internal_symbols functions to be silently overridden. As rust gets more commonly used inside the implementation of libraries consumed with a C interface (like Spidermonkey, Ruby YJIT (curently has to do partial linking of all rust code to hide all symbols not part of the C api), the Rusticl OpenCL implementation in mesa) this is becoming much more of an issue. With this PR the only symbols remaining with an unmangled name are rust_eh_personality (LLVM doesn't allow renaming it) and
__rust_no_alloc_shim_is_unstable.Helps mitigate #104707
try-job: aarch64-gnu-debug
try-job: aarch64-apple
try-job: x86_64-apple-1
try-job: x86_64-mingw-1
try-job: i686-mingw-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: test-various
try-job: armhf-gnu