GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gccrs

gccrs: Supports `#[used]` attribute variants and feature gating.

GCC Rust frontend now recognizes the `#[used]` attribute and its argument variant, enabling feature gating for its usage.

This commit enhances the GCC Rust frontend’s attribute handling by recognizing both the basic #[used] attribute and its argument-based variant, gated by feature(used_with_arg). The feature gating logic for the used attribute on static items is now implemented. While this commit adds recognition and gating, the actual backend implementation for preserving the static item is noted as a future step.

In Details

gccrs: This commit introduces support for the #[used] attribute and its argument-variant in the GCC Rust frontend, linked to the used_with_arg feature gate. The FeatureGate::check_used_attribute function is new, and the FeatureGate::visit method is updated to handle this. The used attribute handler in rust-builtin-attribute-checker.cc is also added. This prepares the ground for the backend implementation that will ensure static items are not optimized away, as discussed in rust-compile-item.cc.

For Context
#[used] attribute
A Rust attribute that prevents the compiler or linker from removing a static variable, even if it appears unused. This is crucial for embedded systems and kernel development where such variables might be accessed indirectly or by external tools.
feature gate
A mechanism in Rust to control the availability of unstable or experimental language features. Features can be "active" or "incomplete," affecting how they are processed by the compiler.
static item
A value with static lifetime, typically a constant or a mutable static variable, declared using the static keyword in Rust.
Filed Under: gccrsrustattributefeature gate