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

Only allow compiler_builtins to call LLVM intrinsics, not any link_name function #123347

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Apr 2, 2024

This is another case of accidental reliance on inline(never) like I rooted out in #118770. Without this PR, attempting to build some large programs with -Zcross-crate-inline-threshold=yes with a sysroot also compiled with that flag will result in linker errors like this:

  = note: /usr/bin/ld: /tmp/cargo-installNrfN4T/x86_64-unknown-linux-gnu/release/deps/libcompiler_builtins-d2a9b69f4e45b883.rlib(compiler_builtins-d2a9b69f4e45b883.compiler_builtins.dbbc6c2ca970faa4-cgu.0.rcgu.o): in function `core::panicking::panic_fmt':
          /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:72:(.text.unlikely._ZN4core9panicking9panic_fmt17ha407cc99e97c942fE+0x31): undefined reference to `rust_begin_unwind'

With -Zcross-crate-inline-threshold=yes we can inline panic_fmt into compiler_builtins. Then we end up with a call to an upstream monomorphization, but one that has a link_name set. But unlike LLVM's magic intrinsic names, this link name is going to make it to the linker, and then we have a problem.

This logic looks scuffed, but also we're doing this in 4 other places. Don't know if that means it's good or bad.

if fx.tcx.symbol_name(instance).name.starts_with("llvm.") {

let links_to_llvm = link_name.is_some_and(|val| val.as_str().starts_with("llvm."));

if name.as_str().starts_with("llvm.") {

if name.starts_with("llvm.") {

@rustbot
Copy link
Collaborator

rustbot commented Apr 2, 2024

r? @Nadrieril

rustbot has assigned @Nadrieril.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 2, 2024
@Nadrieril
Copy link
Member

r? compiler

@rustbot rustbot assigned BoxyUwU and unassigned Nadrieril Apr 2, 2024
@Noratrieb
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 2, 2024

📌 Commit 748dba2 has been approved by Nilstrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 2, 2024
@bors
Copy link
Contributor

bors commented Apr 2, 2024

⌛ Testing commit 748dba2 with merge 0e682e9...

@bors
Copy link
Contributor

bors commented Apr 2, 2024

☀️ Test successful - checks-actions
Approved by: Nilstrieb
Pushing 0e682e9 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 2, 2024
@bors bors merged commit 0e682e9 into rust-lang:master Apr 2, 2024
12 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 2, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0e682e9): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.6% [-2.6%, -2.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.6% [-2.6%, -2.6%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.7% [1.4%, 2.0%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 666.146s -> 667.665s (0.23%)
Artifact size: 315.65 MiB -> 315.66 MiB (0.00%)

@saethlin saethlin deleted the only-allow-upstream-llvm-calls branch April 2, 2024 14:13
@BoxyUwU BoxyUwU assigned Noratrieb and unassigned BoxyUwU Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants