Skip to content

Warn when gold was used as the linker #141750

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Noratrieb
Copy link
Member

@Noratrieb Noratrieb commented May 29, 2025

gold has been deprecated recently and is known to behave incorrectly around Rust programs, including miscompiling #[used(linker)]. Tell people to switch to a different linker instead.

closes #141748

r? bjorn3

@rustbot
Copy link
Collaborator

rustbot commented May 29, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@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 May 29, 2025
@Noratrieb
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 29, 2025
@bors
Copy link
Collaborator

bors commented May 29, 2025

⌛ Trying commit 7c8e56f with merge a1b2ee8...

bors added a commit that referenced this pull request May 29, 2025
Warn when gold was used as the linker

gold has been deprecated recently and is known to behave incorrectly around Rust programs, including miscompiling `#[used(linker)]`. Tell people to switch to a different linker instead.

closes #141748

opening mostly for perf for now, but feel free to review

r? bjorn3
@bors
Copy link
Collaborator

bors commented May 30, 2025

☀️ Try build successful - checks-actions
Build commit: a1b2ee8 (a1b2ee8ad9b4320eb93b75718abce55aefc79a6b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a1b2ee8): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

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

Max RSS (memory usage)

Results (primary -0.9%, secondary -1.2%)

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.3% [0.5%, 2.5%] 3
Improvements ✅
(primary)
-0.9% [-0.9%, -0.9%] 1
Improvements ✅
(secondary)
-1.6% [-8.0%, -0.5%] 15
All ❌✅ (primary) -0.9% [-0.9%, -0.9%] 1

Cycles

Results (secondary 0.2%)

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.0% [0.4%, 3.0%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.1% [-1.7%, -0.4%] 5
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 780.508s -> 779.064s (-0.19%)
Artifact size: 368.46 MiB -> 368.53 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 30, 2025
@bjorn3
Copy link
Member

bjorn3 commented May 30, 2025

This seems to consistently regress linking time by about 1ms.

@Noratrieb
Copy link
Member Author

I've thought that this sort of detection may also be useful in the future to emit a warning if #[used] was used with a version of bfd that doesn't support it.

@Noratrieb
Copy link
Member Author

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented May 30, 2025

⌛ Trying commit 70950cc with merge 389e842

rust-bors bot added a commit that referenced this pull request May 30, 2025
Warn when gold was used as the linker

gold has been deprecated recently and is known to behave incorrectly around Rust programs, including miscompiling `#[used(linker)]`. Tell people to switch to a different linker instead.

closes #141748

opening mostly for perf for now, but feel free to review

r? bjorn3
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 30, 2025
@rust-bors
Copy link

rust-bors bot commented May 30, 2025

☀️ Try build successful

  • CI
    Build commit: 389e842 (389e842a17838b2376420ea608ff25de9e819e1a)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (389e842): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

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

Max RSS (memory usage)

Results (secondary 0.3%)

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.9% [0.4%, 3.0%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.3% [-2.6%, -0.4%] 3
All ❌✅ (primary) - - 0

Cycles

Results (secondary -0.2%)

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.9% [0.5%, 1.6%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.7% [-1.4%, -0.4%] 9
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: missing data
Artifact size: 370.19 MiB -> 370.19 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 30, 2025
@Noratrieb
Copy link
Member Author

👍 on your commit, would be nice to squash before merge

gold has been deprecated recently and is known to behave incorrectly
around Rust programs, including miscompiling `#[used(linker)]`.
Tell people to switch to a different linker instead.

Co-Authored-By: bjorn3 <17426603+bjorn3@users.noreply.github.com>
@bjorn3
Copy link
Member

bjorn3 commented May 31, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented May 31, 2025

📌 Commit ba5a744 has been approved by bjorn3

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 May 31, 2025
@Noratrieb
Copy link
Member Author

@bors r-
I've thought about this again and investigated what the gold issue was exactly in the first place. It looks like the problem was that gold was essentially deleting .init_array entries that it saw if they had SHF_GNU_RETAIN (despite those being considered a GC root by the linker, so previously without SHF_GNU_RETAIN it worked fine). This was fixed in binutils 2.36 (incidentally the same version that also added SHF_GNU_RETAIN support to bfd ld in the first place), after which gold supports SHF_GNU_RETAIN just fine.
So I think this blanket warning doesn't really make sense, I think we should only warn on old gold versions. Binutils <2.36 is still around (for example on Debian 11), so a warning may still make sense, but I don't think the warning is really useful for most users. It is true that it's deprecated, but I don't think rustc should complain to users that they're using a deprecated linker, I think rustc should only protect them from miscompilations.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 31, 2025
@bjorn3
Copy link
Member

bjorn3 commented May 31, 2025

If rustc doesn't warn about newer gold versions anymore, I think the sanity check in bootstrap should instead because of #139425.

@Noratrieb
Copy link
Member Author

We could be even more clever to detect whether #[used(linker)] was used anywhere in the crate graph, but I feel like that might be a bit too much complexity, as it would require encoding new metadata.

@Noratrieb
Copy link
Member Author

Looks like the version embedded in the binary is the gold version, not the binutils version. And the way that is versioned, is uh

GNU gold (GNU Binutils for Debian 2.35.2) 1.16

GNU gold (GNU Binutils 2.44) 1.16

bad news. the gold version is very bad news.

@Noratrieb
Copy link
Member Author

so I think just warning for every version is fine. it's deprecated (and apparently literally no longer included in the latest binutils source tarball), so we can't really have a "false positive" in that sense. no one should be using it.

@bjorn3
Copy link
Member

bjorn3 commented Jun 2, 2025

Given the above, let's approve it again :)

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 2, 2025

📌 Commit ba5a744 has been approved by bjorn3

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Emit a warning when gold is used as the linker
5 participants