diff options
| author | bors <bors@rust-lang.org> | 2025-03-08 12:30:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-03-08 12:30:31 +0000 |
| commit | 79b43dfde9dd1e3bed3c6ef7e9cfc708422f671f (patch) | |
| tree | e24140795e20b8859c497e2557bac36c31a88c7a /compiler/rustc_codegen_ssa/src/back/link.rs | |
| parent | cdd8af229960d05c8dfe5ca3e5f5e2066e676213 (diff) | |
| parent | 6576d35aef7f448c4f2322ffc87375fd0ff01c48 (diff) | |
| download | rust-79b43dfde9dd1e3bed3c6ef7e9cfc708422f671f.tar.gz rust-79b43dfde9dd1e3bed3c6ef7e9cfc708422f671f.zip | |
Auto merge of #138208 - jhpratt:rollup-hlqyu51, r=jhpratt
Rollup of 5 pull requests Successful merges: - #136642 (Put the alloc unit tests in a separate alloctests package) - #137528 (Windows: Fix error in `fs::rename` on Windows 1607) - #137685 (self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux) - #137757 (On long spans, trim the middle of them to make them fit in the terminal width) - #138189 (Mention `env` and `option_env` macros in `std::env::var` docs) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/back/link.rs')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index a170b2e3b6a..3407117a06e 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -3382,6 +3382,35 @@ fn add_lld_args( // this, `wasm-component-ld`, which is overridden if this option is passed. if !sess.target.is_like_wasm { cmd.cc_arg("-fuse-ld=lld"); + + // On ELF platforms like at least x64 linux, GNU ld and LLD have opposite defaults on some + // section garbage-collection features. For example, the somewhat popular `linkme` crate and + // its dependents rely in practice on this difference: when using lld, they need `-z + // nostart-stop-gc` to prevent encapsulation symbols and sections from being + // garbage-collected. + // + // More information about all this 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 + // + // So when using lld, we restore, for now, the traditional behavior to help migration, but + // will remove it in the future. + // Since this only disables an optimization, it shouldn't create issues, but is in theory + // slightly suboptimal. However, it: + // - doesn't have any visible impact on our benchmarks + // - reduces the need to disable lld for the crates that depend on this + // + // Note that lld can detect some cases where this difference is relied on, and emits a + // dedicated error to add this link arg. We could make use of this error to emit an FCW. As + // of writing this, we don't do it, because lld is already enabled by default on nightly + // without this mitigation: no working project would see the FCW, so we do this to help + // stabilization. + // + // FIXME: emit an FCW if linking fails due its absence, and then remove this link-arg in the + // future. + if sess.target.llvm_target == "x86_64-unknown-linux-gnu" { + cmd.link_arg("-znostart-stop-gc"); + } } if !flavor.is_gnu() { |
