-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
naked functions: emit .private_extern on macos
#148339
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 comment has been minimized.
This comment has been minimized.
| // 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).
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.
I think this is fine for now. We can always revise it later if it becomes a problem.
|
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. |
|
@Amanieu will you be able to review this? it is starting to block some things apparently. |
|
@bors r+ |
…ern, r=Amanieu naked functions: emit `.private_extern` on macos fixes rust-lang#148307 Emit `.private_extern` on macos when the naked function uses `Linkage::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`
…uwer Rollup of 11 pull requests Successful merges: - #144113 (Impls and impl items inherit `dead_code` lint level of the corresponding traits and trait items) - #148339 (naked functions: emit `.private_extern` on macos) - #149880 (rustc_codegen_llvm: update alignment for double on AIX) - #150122 (Refactor function names of `rustc_ast_lowering`) - #150412 (use PIDFD_GET_INFO ioctl when available) - #150670 (THIR pattern building: Move all `thir::Pat` creation into `rustc_mir_build::thir::pattern`) - #150695 (MGCA: pretty printing for struct expressions and tuple calls ) - #150698 (Improve comment clarity in candidate_may_shadow) - #150706 (Update wasm-component-ld) - #150707 (Fix ICE when transmute Assume field is invalid) - #150708 (Enable merge queue in new bors) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 11 pull requests Successful merges: - #144113 (Impls and impl items inherit `dead_code` lint level of the corresponding traits and trait items) - #148339 (naked functions: emit `.private_extern` on macos) - #149880 (rustc_codegen_llvm: update alignment for double on AIX) - #150122 (Refactor function names of `rustc_ast_lowering`) - #150412 (use PIDFD_GET_INFO ioctl when available) - #150670 (THIR pattern building: Move all `thir::Pat` creation into `rustc_mir_build::thir::pattern`) - #150695 (MGCA: pretty printing for struct expressions and tuple calls ) - #150698 (Improve comment clarity in candidate_may_shadow) - #150706 (Update wasm-component-ld) - #150707 (Fix ICE when transmute Assume field is invalid) - #150708 (Enable merge queue in new bors) r? `@ghost` `@rustbot` modify labels: rollup
|
…ern, r=Amanieu naked functions: emit `.private_extern` on macos fixes rust-lang#148307 Emit `.private_extern` on macos when the naked function uses `Linkage::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`
|
@bors retry |
|
Oh oops got sniped by #150729 lmao |
naked functions: emit `.private_extern` on macos fixes #148307 Emit `.private_extern` on macos when the naked function uses `Linkage::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`
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
💔 Test failed - checks-actions |
|
Hmm, this PR makes changes for macos only, so I'd guess this is a spurious failure? |
|
@bors2 try job=dist-powerpc64-linux |
|
Unknown command "2". Run |
This comment has been minimized.
This comment has been minimized.
naked functions: emit `.private_extern` on macos try-job: dist-powerpc64-linux
|
@bors r=Amanieu |
|
💡 This pull request was already approved, no need to approve it again.
|
This comment has been minimized.
This comment has been minimized.
|
A job failed! Check out the build log: (web) (plain enhanced) (plain) Click to see the possible cause of the failure (guessed by this bot) |
|
Finished benchmarking commit (fecb335): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 3.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 487.524s -> 473.64s (-2.85%) |
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