You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Confusing warning when using link_section on extern static #136220
warning: attribute should be applied to a functionor static
--><source>:10:5
|
10 |#[unsafe(link_section = ".buffer")]| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11 | pub static mut a: [u8; 1024];| ----------------------------- not a functionor static
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: `#[warn(unused_attributes)]` on by default
warning: 1 warning emitted
Desired output
Not sure if the attribute should be allowed on extern statics... but if the answer is no, the warning should still be reworded to avoid saying that an extern static is "not a static".
LLVM reference suggest that an explicit section is significant on declarations:
Either global variable definitions or declarations may have an explicit section to be placed in and may have an optional explicit alignment specified. If there is a mismatch between the explicit or inferred section information for the variable declaration and its definition the resulting behavior is undefined.
External declarations may have an explicit section specified. Section information is retained in LLVM IR for targets that make use of this information. Attaching section information to an external declaration is an assertion that its definition is located in the specified section. If the definition is located in a different section, the behavior is undefined.
Compiling playground v0.0.1 (/playground)warning: `extern` declarations without an explicit ABI are deprecated --> src/lib.rs:1:8 |1 | unsafe extern { | ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | = note: `#[warn(missing_abi)]` on by defaultwarning: the `link_section` attribute cannot be used on foreign statics --> src/lib.rs:2:14 |2 | #[unsafe(link_section = ".buffer")] | ^^^^^^^^^^^^ | = help: the `link_section` attribute can be applied to functions and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: `#[warn(unused_attributes)]` (part of `#[warn(unused)]`) on by default
Awesome, indeed wasn't aware of this issue but my refactor of the relevant code happened to fix it. This doesn't seem to have a test yet, feel free someone to go do that :3
Looks like this one already has a test: #162665 added tests/ui/attributes/positions/link-section.rs, which links back to this issue. I think this can be closed.
Activity
Noratrieb commentedon Jan 29, 2025
This attribute does not make sense for external statics, it only makes sense for defined statics as it controls where they end up.
tmiasko commentedon Jan 29, 2025
LLVM reference suggest that an explicit section is significant on declarations:
chenyukang commentedon Sep 9, 2026
this seems fixed by #145085
now the output is:
cc @JonathanBrouwer
JonathanBrouwer commentedon Sep 11, 2026
Awesome, indeed wasn't aware of this issue but my refactor of the relevant code happened to fix it. This doesn't seem to have a test yet, feel free someone to go do that :3
Rollup merge of rust-lang#162665 - kulinsky:test-link-section-foreign…
Rollup merge of rust-lang#162665 - kulinsky:test-link-section-foreign…
Unrolled build for #162665 in rollup 162728
machinedramon commentedon Oct 18, 2026
Looks like this one already has a test: #162665 added
tests/ui/attributes/positions/link-section.rs, which links back to this issue. I think this can be closed.