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

self-contained linker: conservatively default to -znostart-stop-gc on x64 linux #137685

Merged
merged 1 commit into from
Mar 8, 2025

Conversation

lqd
Copy link
Member

@lqd lqd commented Feb 26, 2025

To help stabilization, this PR disables an LLD optimization on x64 linux with respect to --gc-sections and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using linkme, which doesn't work with lld or on nightly, need to disable lld.

More information about all this, and the historical differences, can be found in:

This optimization has no visible impact on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without -znostart-stop-gc, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable.

I've tested that this correctly links on linkme examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for -znostart-stop-gc to only impact this... It should of course be doable though, maybe @Kobzol will look into it if they have time.

r? @petrochenkov

@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 Feb 26, 2025
@lqd
Copy link
Member Author

lqd commented Feb 26, 2025

Sanity check perf run:

@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 Feb 26, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2025
self-contained linker: conservatively default to `-znostart-stop-gc`

To help stabilization, this PR disables an LLD optimization with respect to `--gc-sections` and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using [linkme](https://github.com/dtolnay/linkme), which [doesn't work with lld](dtolnay/linkme#63) or on nightly, need to disable lld.

This optimization has [no visible impact](rust-lang#112049 (comment)) on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without `-znostart-stop-gc`, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable.

I've tested that this correctly links on `linkme` examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for `-znostart-stop-gc` to only impact this... It should of course be doable though, maybe `@Kobzol` will look into it if they have time.

r? `@petrochenkov`
@bors
Copy link
Contributor

bors commented Feb 26, 2025

⌛ Trying commit 762fdf6 with merge ced69ff...

@bors
Copy link
Contributor

bors commented Feb 26, 2025

☀️ Try build successful - checks-actions
Build commit: ced69ff (ced69fff94a2a0d15512ca568f4fd890ebcc4f23)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ced69ff): comparison URL.

Overall result: no relevant changes - 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 benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary 3.4%, secondary -2.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)
3.4% [3.4%, 3.4%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) 3.4% [3.4%, 3.4%] 1

Cycles

Results (secondary 1.7%)

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.7%, 1.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 771.284s -> 771.237s (-0.01%)
Artifact size: 361.94 MiB -> 361.93 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 26, 2025
@mati865
Copy link
Contributor

mati865 commented Feb 27, 2025

Even better than emitting FCWs would be fixing LLD. Wild linker had the same issue, but the fix was quite easy: davidlattimore/wild#460

@Kobzol
Copy link
Contributor

Kobzol commented Feb 27, 2025

LLD has said on several occasions that they won't fix this, as they don't consider it to be an issue (https://lld.llvm.org/ELF/start-stop-gc.html). We're kind of being overly conservative here.

@lqd
Copy link
Member Author

lqd commented Feb 27, 2025

Even better than emitting FCWs would be fixing LLD

To be clear, there is nothing to fix in either linkers per se: they both implement the two behaviors of conservative and precise GC. The default value is just different, GNU ld defaults to -z nostart-stop-gc while lld now defaults to -z start-stop-gc.

It's more of a difference of opinion, which is why I described this as disabling a size optimization. It just helps stabilization, to remove a concern of these different defaults, and delay possible FCWs and wait periods to where it's needed.

We could equally do nothing and take the breakage.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 27, 2025

📌 Commit 762fdf6 has been approved by petrochenkov

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 27, 2025

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@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 Feb 27, 2025
@compiler-errors
Copy link
Member

@bors rollup-

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 2, 2025
self-contained linker: conservatively default to `-znostart-stop-gc`

To help stabilization, this PR disables an LLD optimization with respect to `--gc-sections` and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using [linkme](https://github.com/dtolnay/linkme), which [doesn't work with lld](dtolnay/linkme#63) or on nightly, need to disable lld.

More information about all this, and the historical differences, can be found in:
- https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
- https://lld.llvm.org/ELF/start-stop-gc

This optimization has [no visible impact](rust-lang#137685 (comment)) on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without `-znostart-stop-gc`, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable.

I've tested that this correctly links on `linkme` examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for `-znostart-stop-gc` to only impact this... It should of course be doable though, maybe `@Kobzol` will look into it if they have time.

r? `@petrochenkov`
tgross35 added a commit to tgross35/rust that referenced this pull request Mar 2, 2025
self-contained linker: conservatively default to `-znostart-stop-gc`

To help stabilization, this PR disables an LLD optimization with respect to `--gc-sections` and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using [linkme](https://github.com/dtolnay/linkme), which [doesn't work with lld](dtolnay/linkme#63) or on nightly, need to disable lld.

More information about all this, and the historical differences, can be found in:
- https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
- https://lld.llvm.org/ELF/start-stop-gc

This optimization has [no visible impact](rust-lang#137685 (comment)) on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without `-znostart-stop-gc`, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable.

I've tested that this correctly links on `linkme` examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for `-znostart-stop-gc` to only impact this... It should of course be doable though, maybe ``@Kobzol`` will look into it if they have time.

r? ``@petrochenkov``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 3, 2025
self-contained linker: conservatively default to `-znostart-stop-gc`

To help stabilization, this PR disables an LLD optimization with respect to `--gc-sections` and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using [linkme](https://github.com/dtolnay/linkme), which [doesn't work with lld](dtolnay/linkme#63) or on nightly, need to disable lld.

More information about all this, and the historical differences, can be found in:
- https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
- https://lld.llvm.org/ELF/start-stop-gc

This optimization has [no visible impact](rust-lang#137685 (comment)) on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without `-znostart-stop-gc`, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable.

I've tested that this correctly links on `linkme` examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for `-znostart-stop-gc` to only impact this... It should of course be doable though, maybe ```@Kobzol``` will look into it if they have time.

r? ```@petrochenkov```
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#132388 (Implement `#[cfg]` in `where` clauses)
 - rust-lang#134900 (Fix parsing of ranges after unary operators)
 - rust-lang#136938 (Remove `:` from `stack-protector-heuristics-effect.rs` Filecheck Pattern)
 - rust-lang#137054 (Make phantom variance markers transparent)
 - rust-lang#137525 (Simplify parallelization in test-float-parse)
 - rust-lang#137618 (Skip `tidy` in pre-push hook if the user is deleting a remote branch)
 - rust-lang#137685 (self-contained linker: conservatively default to `-znostart-stop-gc`)
 - rust-lang#137741 (Stop using `hash_raw_entry` in `CodegenCx::const_str`)
 - rust-lang#137849 (Revert "Remove Win SDK 10.0.26100.0 from CI")
 - rust-lang#137862 (ensure we always print all --print options in help)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#132388 (Implement `#[cfg]` in `where` clauses)
 - rust-lang#134900 (Fix parsing of ranges after unary operators)
 - rust-lang#136938 (Remove `:` from `stack-protector-heuristics-effect.rs` Filecheck Pattern)
 - rust-lang#137054 (Make phantom variance markers transparent)
 - rust-lang#137525 (Simplify parallelization in test-float-parse)
 - rust-lang#137618 (Skip `tidy` in pre-push hook if the user is deleting a remote branch)
 - rust-lang#137685 (self-contained linker: conservatively default to `-znostart-stop-gc`)
 - rust-lang#137741 (Stop using `hash_raw_entry` in `CodegenCx::const_str`)
 - rust-lang#137849 (Revert "Remove Win SDK 10.0.26100.0 from CI")
 - rust-lang#137862 (ensure we always print all --print options in help)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Mar 4, 2025
This will help stabilization of lld.
@lqd lqd force-pushed the nostart-stop-gc branch from 762fdf6 to e0b7577 Compare March 5, 2025 09:15
@lqd
Copy link
Member Author

lqd commented Mar 5, 2025

So it's not the serialized vs rollup state, it's some combination of lld + unknown flag + cc + apple causing an error.

rust-lld: error: unknown argument '-znostart-stop-gc'

The flag is for ELF, but it should be fine as lld accepts unknown z flag and emits warnings for them.

% ~/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin/gcc-ld/ld.lld -zbla
rust-lld: warning: unknown -z value: bla

I suspect some issue on osx in passing the flag all the way down to the linker, as the error shows an unknown argument instead of an unknown -z value. -znostart-stop-gc looks to also be known: if you use it you don't get the "unknown -z value" warning.

In any case, we don't need to care: to avoid this entirely, and since the flag is only for ELF, I've limited this change to x64 linux only (and if others want to expand this to other ELF targets needing it it'll be easy to add).

Now that CI has passed, we can re-test on the apple test builders, but nothing changes there.
@bors try

@bors
Copy link
Contributor

bors commented Mar 5, 2025

⌛ Trying commit e0b7577 with merge 1bde034...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 5, 2025
self-contained linker: conservatively default to `-znostart-stop-gc`

To help stabilization, this PR disables an LLD optimization with respect to `--gc-sections` and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using [linkme](https://github.com/dtolnay/linkme), which [doesn't work with lld](dtolnay/linkme#63) or on nightly, need to disable lld.

More information about all this, and the historical differences, can be found in:
- https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
- https://lld.llvm.org/ELF/start-stop-gc

This optimization has [no visible impact](rust-lang#137685 (comment)) on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without `-znostart-stop-gc`, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable.

I've tested that this correctly links on `linkme` examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for `-znostart-stop-gc` to only impact this... It should of course be doable though, maybe `@Kobzol` will look into it if they have time.

r? `@petrochenkov`

try-job: x86_64-apple-1
try-job: x86_64-apple-2
try-job: aarch64-apple
@bors
Copy link
Contributor

bors commented Mar 5, 2025

☀️ Try build successful - checks-actions
Build commit: 1bde034 (1bde034beaed9c69d278c01f0f5f39660140fb72)

@lqd lqd changed the title self-contained linker: conservatively default to -znostart-stop-gc self-contained linker: conservatively default to -znostart-stop-gc on x64 linux Mar 5, 2025
@lqd
Copy link
Member Author

lqd commented Mar 5, 2025

CI passed on linux, and on the apple builders. I've updated the name and description to mention this is now for x64 linux only, as explained above.

Let's have a final look over.
@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 5, 2025
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 5, 2025

📌 Commit e0b7577 has been approved by petrochenkov

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 Mar 5, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Mar 5, 2025
self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux

To help stabilization, this PR disables an LLD optimization on  x64 linux with respect to `--gc-sections` and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using [linkme](https://github.com/dtolnay/linkme), which [doesn't work with lld](dtolnay/linkme#63) or on nightly, need to disable lld.

More information about all this, and the historical differences, can be found in:
- https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
- https://lld.llvm.org/ELF/start-stop-gc

This optimization has [no visible impact](rust-lang#137685 (comment)) on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without `-znostart-stop-gc`, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable.

I've tested that this correctly links on `linkme` examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for `-znostart-stop-gc` to only impact this... It should of course be doable though, maybe `@Kobzol` will look into it if they have time.

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 5, 2025
Rollup of 29 pull requests

Successful merges:

 - rust-lang#135733 (Implement `&pin const self` and `&pin mut self` sugars)
 - rust-lang#137107 (Override default `Write` methods for cursor-like types)
 - rust-lang#137303 (Remove `MaybeForgetReturn` suggestion)
 - rust-lang#137327 (Undeprecate env::home_dir)
 - rust-lang#137358 (Match Ergonomics 2024: add context and examples to the unstable book)
 - rust-lang#137534 ([rustdoc] hide item that is not marked as doc(inline) and whose src is doc(hidden))
 - rust-lang#137565 (Try to point of macro expansion from resolver and method errors if it involves macro var)
 - rust-lang#137612 (Update bootstrap to edition 2024)
 - rust-lang#137637 (Check dyn flavor before registering upcast goal on wide pointer cast in MIR typeck)
 - rust-lang#137643 (Add DWARF test case for non-C-like `repr128` enums)
 - rust-lang#137685 (self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux)
 - rust-lang#137744 (Re-add `Clone`-derive on `Thir`)
 - rust-lang#137758 (fix usage of ty decl macro fragments in attributes)
 - rust-lang#137764 (Ensure that negative auto impls are always applicable)
 - rust-lang#137772 (Fix char count in `Display` for `ByteStr`)
 - rust-lang#137798 (ci: use ubuntu 24 on arm large runner)
 - rust-lang#137802 (miri native-call support: all previously exposed provenance is accessible to the callee)
 - rust-lang#137805 (adjust Layout debug printing to match the internal field name)
 - rust-lang#137808 (Do not require that unsafe fields lack drop glue)
 - rust-lang#137820 (Clarify why InhabitedPredicate::instantiate_opt exists)
 - rust-lang#137825 (Provide more context on resolve error caused from incorrect RTN)
 - rust-lang#137827 (Add timestamp to unstable feature usage metrics)
 - rust-lang#137832 (Fix crash in BufReader::peek())
 - rust-lang#137910 (Improve error message for `AsyncFn` trait failure for RPIT)
 - rust-lang#137920 (interpret/provenance_map: consistently use range_is_empty)
 - rust-lang#138038 (Update `compiler-builtins` to 0.1.151)
 - rust-lang#138046 (trim channel value in `get_closest_merge_commit`)
 - rust-lang#138052 (strip `-Wlinker-messages` wrappers from `rust-lld` rmake test)
 - rust-lang#138053 (Increase the max. custom try jobs requested to `20`)

r? `@ghost`
`@rustbot` modify labels: rollup
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Mar 5, 2025
self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux

To help stabilization, this PR disables an LLD optimization on  x64 linux with respect to `--gc-sections` and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using [linkme](https://github.com/dtolnay/linkme), which [doesn't work with lld](dtolnay/linkme#63) or on nightly, need to disable lld.

More information about all this, and the historical differences, can be found in:
- https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
- https://lld.llvm.org/ELF/start-stop-gc

This optimization has [no visible impact](rust-lang#137685 (comment)) on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without `-znostart-stop-gc`, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable.

I've tested that this correctly links on `linkme` examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for `-znostart-stop-gc` to only impact this... It should of course be doable though, maybe ``@Kobzol`` will look into it if they have time.

r? ``@petrochenkov``
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Mar 7, 2025
self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux

To help stabilization, this PR disables an LLD optimization on  x64 linux with respect to `--gc-sections` and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using [linkme](https://github.com/dtolnay/linkme), which [doesn't work with lld](dtolnay/linkme#63) or on nightly, need to disable lld.

More information about all this, and the historical differences, can be found in:
- https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
- https://lld.llvm.org/ELF/start-stop-gc

This optimization has [no visible impact](rust-lang#137685 (comment)) on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without `-znostart-stop-gc`, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable.

I've tested that this correctly links on `linkme` examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for `-znostart-stop-gc` to only impact this... It should of course be doable though, maybe ```@Kobzol``` will look into it if they have time.

r? ```@petrochenkov```
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 7, 2025
…mpiler-errors

Rollup of 8 pull requests

Successful merges:

 - rust-lang#136642 (Put the alloc unit tests in a separate alloctests package)
 - rust-lang#137337 (Add verbatim linker to AIXLinker)
 - rust-lang#137363 (compiler: factor Windows x86-32 ABI impl into its own file)
 - rust-lang#137685 (self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux)
 - rust-lang#138000 (atomic: clarify that failing conditional RMW operations are not 'writes')
 - rust-lang#138063 (Improve `-Zunpretty=hir` for parsed attrs)
 - rust-lang#138137 (setTargetTriple now accepts Triple rather than string)
 - rust-lang#138173 (Delay bug for negative auto trait rather than ICEing)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2025
Rollup of 5 pull requests

Successful merges:

 - rust-lang#136642 (Put the alloc unit tests in a separate alloctests package)
 - rust-lang#137528 (Windows: Fix error in `fs::rename` on Windows 1607)
 - rust-lang#137685 (self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux)
 - rust-lang#137757 (On long spans, trim the middle of them to make them fit in the terminal width)
 - rust-lang#138189 (Mention `env` and `option_env` macros in `std::env::var` docs)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit dfae8e8 into rust-lang:master Mar 8, 2025
7 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 8, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2025
Rollup merge of rust-lang#137685 - lqd:nostart-stop-gc, r=petrochenkov

self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux

To help stabilization, this PR disables an LLD optimization on  x64 linux with respect to `--gc-sections` and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using [linkme](https://github.com/dtolnay/linkme), which [doesn't work with lld](dtolnay/linkme#63) or on nightly, need to disable lld.

More information about all this, and the historical differences, can be found in:
- https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
- https://lld.llvm.org/ELF/start-stop-gc

This optimization has [no visible impact](rust-lang#137685 (comment)) on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without `-znostart-stop-gc`, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable.

I've tested that this correctly links on `linkme` examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for `-znostart-stop-gc` to only impact this... It should of course be doable though, maybe ````@Kobzol```` will look into it if they have time.

r? ````@petrochenkov````
@lqd lqd deleted the nostart-stop-gc branch March 8, 2025 15:38
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.

10 participants