Skip to content

make tests/run-make/used-proc-macro more reliable#155436

Open
japaric wants to merge 1 commit intorust-lang:mainfrom
ferrocene:gh155434
Open

make tests/run-make/used-proc-macro more reliable#155436
japaric wants to merge 1 commit intorust-lang:mainfrom
ferrocene:gh155434

Conversation

@japaric
Copy link
Copy Markdown
Contributor

@japaric japaric commented Apr 17, 2026

the test was relying on the linker not discarding the #[used] symbol

this commit modifies the proc macro to read the #[used] symbol to ensure it is not discarded by the linker

fixes #155434

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs 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 Apr 17, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 17, 2026

r? @mejrs

rustbot has assigned @mejrs.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 72 candidates
  • Random selection from 19 candidates

@rustbot

This comment has been minimized.

the test was relying on the linker not discarding the `#[used]` symbol

this commit modifies the proc macro to read the `#[used]` symbol to ensure it
is not discarded by the linker
Xylakant pushed a commit to ferrocene/ferrocene that referenced this pull request Apr 17, 2026
the test was relying on the linker not discarding the `#[used]` symbol

this commit modifies the proc macro to read the `#[used]` symbol to ensure it
is not discarded by the linker

cherry-picked from upstream, see rust-lang/rust#155436
Copy link
Copy Markdown
Contributor

@mejrs mejrs left a comment

Choose a reason for hiding this comment

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

Comment on lines 3 to +4
#[used]
#[no_mangle] // so we can refer to this variable by name from the proc-macro library
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't #[no_mangle] imply #[used]?

This is not my area of expertise but it looks like you can drop the #[used] attribute (and adjust the comments appropriately). Please correct me if I'm wrong.

Copy link
Copy Markdown
Member

@bjorn3 bjorn3 Apr 17, 2026

Choose a reason for hiding this comment

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

Yeah, #[used] would no longer have much of an effect now.

Xylakant pushed a commit to ferrocene/ferrocene that referenced this pull request Apr 17, 2026
the test was relying on the linker not discarding the `#[used]` symbol

this commit modifies the proc macro to read the `#[used]` symbol to ensure it
is not discarded by the linker

cherry-picked from upstream, see rust-lang/rust#155436
@mejrs mejrs 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-review Status: Awaiting review from the assignee but also interested parties. labels Apr 17, 2026
Comment on lines +14 to +19
// read the symbol otherwise the _linker_ may discard it
// `#[used]` only preserves the symbol up to the compiler output (.o file)
// which is then passed to the linker. the linker is free to discard the
// `#[used]` symbol if it's not accessed/referred-to by other object
// files (crates)
let symbol_value = unsafe { core::ptr::addr_of!(VERY_IMPORTANT_SYMBOL).read_volatile() };
Copy link
Copy Markdown
Member

@bjorn3 bjorn3 Apr 17, 2026

Choose a reason for hiding this comment

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

#[used] is an alias for #[used(linker)] since #140872, which should prevent the linker from discarding it. In either case now that you added a reference to it in another crate, this test is no longer testing #[used] as it should. The linker error that you observed is a genuine bug that this test caught. This bug should be fixed instead of changing the test.

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

tests/run-make/used-proc-macro is flaky as it relies on linker behavior

4 participants