null symbols cause unsoundness with extern static
Open
Nobody has claimed this yet.
A-docs
C-bug
T-compiler
T-lang
T-spec
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Pointers to external statics are incorrectly assumed to be non-null and well-aligned. Edition 2024 marking extern as unsafe does help, but there is no documentation mentioning this, and this still works in 2021 despite forbidding unsafe_code.
#![forbid(unsafe_code)]
extern "C" {
static mut GLIBC_PRIVATE: u8;
static perror: u64;
}
fn main() {
let x = std::ptr::NonNull::new(&raw mut GLIBC_PRIVATE).unwrap();
println!("{x:?}"); // 0x0
let y = &raw const perror;
println!("{y:?} {}", y.is_aligned()); // 0x7c5aa9e5ea93 true
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the linked Rust Playground example in release mode under Edition 2021, then compare the behavior with Edition 2024 and #![forbid(unsafe_code)]. The report names no source files or tests, and completion is not defined; maintainers first need to decide whether the fix belongs in compiler behavior, language rules, or documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100