-
Notifications
You must be signed in to change notification settings - Fork 13.9k
naked functions: emit .private_extern on macos
#148339
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
base: master
Are you sure you want to change the base?
Conversation
|
Some changes occurred in compiler/rustc_codegen_ssa |
|
Is this really only an issue on macOS? I would have assumes this is an issue on all platforms. |
|
The reproduction given in the issue builds successfully for me on linux. I did just notice that we do already have rust/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs Lines 245 to 248 in 73e6c9e
That clearly did not actually trigger in this case. Is that right? |
|
Yeah, the issue here I believe is that rustc correctly computes the symbol visibility for the naked function as private, but then when ThinLTO decides to inline the caller of the naked function, it is unable to change the naked function to be public (+ add a |
Hmm, we do emit the following: rust/compiler/rustc_middle/src/mir/mono.rs Lines 151 to 159 in 6a884ad
but apparently that is not enough. Is |
|
That gets overridden at rust/compiler/rustc_monomorphize/src/partitioning.rs Lines 583 to 586 in 6a884ad
|
502098d to
d96ae8f
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| // write nothing | ||
| // LTO can fail when internal linkage is used. | ||
| emit_fatal("naked functions may not have internal linkage") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this too strict? We could allow it, but I think this is only reachable now with an explicit linkage attribute (which is unstable).
|
I think the issue with inlining is bigger than that and we effectively have to always use global visibility for naked functions. Consider |
If rustc considers the caller to be cross-crate codegenable, it would already mark the callee as public be it a regular function be it a naked function. The problematic case is where the codegen backend decides to inline a function into another codegen unit when rustc didn't consider it cross-crate codegenable. This can only happen within a single dylib through ThinLTO, not between dylibs. And it is only an issue for naked functions as ThinLTO can't make the function public itself as it would do for regular functions. |
fixes #148307
Emit
.private_externon macos when the naked function usesLinkage::Internal. Failing to do so can cause issues with LTO.The documentation on this directive is kind of sparse, but I believe this is at least not incorrect, and does fix the issue.
r? @Amanieu
cc @bjorn3