rust/compiler/rustc_codegen_ssa/src
Matthias Krüger 3f7b8c5198
Rollup merge of #147117 - iximeow:ixi/illumos-used-attr, r=Noratrieb
interpret `#[used]` as `#[used(compiler)]` on illumos

helps rust-lang/rust#146169 not be as painful: fixes the illumos regression in rust-lang/rust#140872, but `#[used(linker)]` is still erroneous on illumos generally.

illumos' `ld` does not support a flag like either SHF_GNU_RETAIN or SHF_SUNW_NODISCARD, so there is no way to communicate `#[used(linker)]` for that target. Setting `USED_LINKER` to try results in LLVM setting SHF_SUNW_NODISCARD for Solaris-like targets, which is an unknown section header flag for illumos `ld` and prevents sections from being merged that otherwise would.

As a motivating example, the `inventory` crate produces `#[used]` items to merge into `.init_array`. Because those items have an unknown section header flag they are not merged with the default `.init_array` with `frame_dummy`, and end up never executed.

Downgrading `#[used]` to `#[used(compiler)]` on illumos keeps so-attributed items as preserved as they had been before https://github.com/rust-lang/rust/pull/140872. As was the case before that change, because rustc passes `-z ignore` to illumos `ld`, it's possible that `used` sections are GC'd at link time. https://github.com/rust-lang/rust/issues/146169 describes this unfortunate circumstance.

----

as it turns out, `tests/ui/attributes/used_with_archive.rs` had broken on `x86_64-unknown-illumos`, and this patch fixes it. the trials and tribulations of tier 2 :(

r? ````@Noratrieb```` probably?
2025-10-04 17:11:11 +02:00
..
back Don't enable shared memory with Wasm atomics 2025-10-01 15:36:47 +02:00
debuginfo Flatten ifs in rustc_codegen_ssa 2025-03-17 18:56:52 +00:00
mir debuginfo: Use LocalRef to simplify reference debuginfos 2025-10-03 08:08:22 +08:00
traits codegen: Generate dbg_value for the ref statement 2025-10-02 14:55:51 +08:00
assert_module_sources.rs Print CGU reuse statistics when -Zprint-mono-items is enabled 2025-08-04 15:43:50 +02:00
base.rs port #[debugger_visualizer] to the new attribute system 2025-09-21 21:30:16 -07:00
codegen_attrs.rs interpret #[used] as #[used(compiler)] on illumos 2025-10-03 22:03:24 +00:00
common.rs Move NativeLibKind from rustc_session to rustc_hir 2025-08-27 20:24:59 +02:00
errors.rs Set lto="fat" automatically when compiling with RUSTFLAGS="-Zautodiff=Enable". 2025-09-18 15:26:14 +08:00
lib.rs Ensure fat LTO doesn't merge everything into the allocator module 2025-09-06 13:31:41 +00:00
meth.rs Remove DynKind 2025-09-17 04:46:46 +02:00
mono_item.rs Port the #[linkage] attribute to the new attribute system 2025-08-13 21:01:37 +02:00
size_of_val.rs remove explicit deref of AbiAlign for most methods 2025-09-28 15:02:14 -07:00
target_features.rs Add an experimental unsafe(force_target_feature) attribute. 2025-08-22 01:26:26 +02:00