make tests/run-make/used-proc-macro more reliable#155436
make tests/run-make/used-proc-macro more reliable#155436japaric wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
r? @mejrs rustbot has assigned @mejrs. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
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
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
| #[used] | ||
| #[no_mangle] // so we can refer to this variable by name from the proc-macro library |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yeah, #[used] would no longer have much of an effect now.
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
| // 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() }; |
There was a problem hiding this comment.
#[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.
the test was relying on the linker not discarding the
#[used]symbolthis commit modifies the proc macro to read the
#[used]symbol to ensure it is not discarded by the linkerfixes #155434