Skip to content

Conversation

iximeow
Copy link
Contributor

@iximeow iximeow commented Sep 28, 2025

helps #146169 not be as painful: fixes the illumos regression in #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 #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. #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?

@rustbot
Copy link
Collaborator

rustbot commented Sep 28, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Sep 28, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 28, 2025

Noratrieb is not on the review rotation at the moment.
They may take a while to respond.

@workingjubilee
Copy link
Member

Hm. Isn't used(linker) simply broken on illumos? Is there a purpose to adding a variant to UsedBy when used(linker) remains incorrectly behaving?

@iximeow
Copy link
Contributor Author

iximeow commented Sep 28, 2025

i didn't think we can get at the target OS while parsing used, mainly. and it seems a bit funky to parse attributes in a target-sensitive way like that, but i have no sense for how normal that would be to do?

@workingjubilee
Copy link
Member

Wouldn't it be simpler to only change codegen_attrs.rs?

@iximeow
Copy link
Contributor Author

iximeow commented Sep 28, 2025

in a "lines changed" sense, yes, i suppose? as a very infrequent contributor and a basically-never-touched-parsing contributor, i primarily want to make a change that is not surprising to regular contributors.

if you're saying that this is surprising, and you would expect codegen_attrs.rs to care about the target OS (and presumably it'd be available under cx somewhere here), i'm happy to make that change. the diff here is what i thought would be least surprising, happy to defer to whatever makes more sense to the regular readers here.

@workingjubilee
Copy link
Member

sorry, I meant in cg_ssa specifically. adding a variant during option parsing to bypass broken behavior on a target where the behavior for one of the variants is already broken and will remain broken is what puzzles me.

@iximeow
Copy link
Contributor Author

iximeow commented Sep 28, 2025

by cg_ssa we can't distinguish between the source having been #[used] or #[used(linker)]. so to reinterpret UsedBy::Linker as USED_COMPILER there would make #[used(linker)] in source pretty awkward. i recognize that #[used(linker)] is unstable but it feels more fitting to warn about it than silently downgrade it.

so that's how i ended up agreeing with bjorn3 on a third variant here. and separately i figure i'll add a warning if UsedBy::Linker makes it to codegen on illumos?

(relatedly, i'm not totally sure that -z ignore does what we want with illumos' ld, but i haven't experimented much. if it doesn't and it makes sense to condition that on is-Solaris-like-and-not-illumos, then #[used(linker)] is trivially satisfied as USED_COMPILER. but i think the status quo is that -z ignore means a #[used(linker)] section could end up GC'd. that's also something i want to follow up on but.. i figure one thing at a time)

@rust-log-analyzer

This comment has been minimized.

@iximeow
Copy link
Contributor Author

iximeow commented Sep 28, 2025

hm. i'd missed that moving from passing to failing among the other failures on illumos, i suppose i should have run ./x test on a tier 1 target too :)

@jdonszelmann
Copy link
Contributor

This seems like the right solution to me (having written most attribute parsers, but not this one specifically. Did review it at the time). Parsing it to a form that's target agnostic but let's you still decode which form it was (Any) and then choosing what to do with it in SSA. r=me for the attribute parsing stuff if you need my blessing nora

@workingjubilee
Copy link
Member

by cg_ssa we can't distinguish between the source having been #[used] or #[used(linker)]. so to reinterpret UsedBy::Linker as USED_COMPILER there would make #[used(linker)] in source pretty awkward. i recognize that #[used(linker)] is unstable but it feels more fitting to warn about it than silently downgrade it.

Yes, it's mostly a matter of taste then. If people prefer this route then that's fine, as it does reflect the source most closely during parsing before it reaches codegen.

Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, can you clean up the commits to squash the third one into the first one? Then we can merge it

View changes since this review

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
rust-lang#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.
rust-lang#146169 describes this
unfortunate circumstance.
@iximeow iximeow force-pushed the ixi/illumos-used-attr branch from 6451592 to c721fa2 Compare October 3, 2025 22:14
@iximeow
Copy link
Contributor Author

iximeow commented Oct 3, 2025

i went ahead and squashed all three since it feels like there's no use for the intermediate handles-warnings-bad state. thanks for the reviews 🙏

@Noratrieb
Copy link
Member

Makes sense, thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Oct 4, 2025

📌 Commit c721fa2 has been approved by Noratrieb

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 Oct 4, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 4, 2025
…oratrieb

interpret `#[used]` as `#[used(compiler)]` on illumos

helps rust-lang#146169 not be as painful: fixes the illumos regression in rust-lang#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 rust-lang#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. rust-lang#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?
bors added a commit that referenced this pull request Oct 4, 2025
Rollup of 14 pull requests

Successful merges:

 - #142670 (Document fully-qualified syntax in `as`' keyword doc)
 - #145685 (add CloneFromCell and Cell::get_cloned)
 - #146330 (Bump unicode_data and printables to version 17.0.0)
 - #146451 (Fix atan2 inaccuracy in documentation)
 - #146479 (add mem::conjure_zst)
 - #146874 (compiler: Hint at multiple crate versions if trait impl is for wrong ADT )
 - #147117 (interpret `#[used]` as `#[used(compiler)]` on illumos)
 - #147190 (std: `sys::net` cleanups)
 - #147251 (Do not assert that a change in global cache only happens when concurrent)
 - #147280 (Return to needs-llvm-components being info-only)
 - #147288 (compiletest: Make `DirectiveLine` responsible for name/value splitting)
 - #147309 (Add documentation about unwinding to wasm targets)
 - #147315 (bless autodiff batching test)
 - #147323 (Fix top level ui tests check in tidy)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 4, 2025
…oratrieb

interpret `#[used]` as `#[used(compiler)]` on illumos

helps rust-lang#146169 not be as painful: fixes the illumos regression in rust-lang#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 rust-lang#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. rust-lang#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?
bors added a commit that referenced this pull request Oct 4, 2025
Rollup of 11 pull requests

Successful merges:

 - #142670 (Document fully-qualified syntax in `as`' keyword doc)
 - #145685 (add CloneFromCell and Cell::get_cloned)
 - #146330 (Bump unicode_data and printables to version 17.0.0)
 - #146451 (Fix atan2 inaccuracy in documentation)
 - #146479 (add mem::conjure_zst)
 - #147117 (interpret `#[used]` as `#[used(compiler)]` on illumos)
 - #147190 (std: `sys::net` cleanups)
 - #147251 (Do not assert that a change in global cache only happens when concurrent)
 - #147280 (Return to needs-llvm-components being info-only)
 - #147288 (compiletest: Make `DirectiveLine` responsible for name/value splitting)
 - #147315 (bless autodiff batching test)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 4, 2025
…oratrieb

interpret `#[used]` as `#[used(compiler)]` on illumos

helps rust-lang#146169 not be as painful: fixes the illumos regression in rust-lang#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 rust-lang#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. rust-lang#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?
bors added a commit that referenced this pull request Oct 4, 2025
Rollup of 10 pull requests

Successful merges:

 - #142670 (Document fully-qualified syntax in `as`' keyword doc)
 - #145685 (add CloneFromCell and Cell::get_cloned)
 - #146330 (Bump unicode_data and printables to version 17.0.0)
 - #146451 (Fix atan2 inaccuracy in documentation)
 - #146479 (add mem::conjure_zst)
 - #147117 (interpret `#[used]` as `#[used(compiler)]` on illumos)
 - #147190 (std: `sys::net` cleanups)
 - #147251 (Do not assert that a change in global cache only happens when concurrent)
 - #147280 (Return to needs-llvm-components being info-only)
 - #147315 (bless autodiff batching test)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3f7b8c5 into rust-lang:master Oct 4, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 4, 2025
rust-timer added a commit that referenced this pull request Oct 4, 2025
Rollup merge of #147117 - iximeow:ixi/illumos-used-attr, r=Noratrieb

interpret `#[used]` as `#[used(compiler)]` on illumos

helps #146169 not be as painful: fixes the illumos regression in #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 #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. #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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) 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