Target features getting erased when using `#[export_name]` with names of LLVM intrinsics
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
TIL Rust "supports" #[export_name] with names of LLVM intrinsics! The following code compiles no problem
#[unsafe(export_name = "llvm.x86.rdtsc")]
fn foo() {
// ...
}
(FYI llvm.x86.rdtsc is a very real LLVM intrinsic, used to read the timestamp counter value in x86)
which imo should be hard error anyway. But then if we combine this monstrosity with #[target_feature] (or -C target-feature for that matter), all the target feature data for that function is erased. This is possible even in stable Rust, both in debug and release profile.
Godbolt link https://godbolt.org/z/h7jdrsY54
Meta
Doing a naive bisect on Godbolt, I found out that this bug was introduced in 1.29.0!!
https://godbolt.org/z/8M9a4vs9Y
The solution is probably just disallow any #[export_name]'s that try to masquerade as LLVM intrinsics (i.e. name starts with llvm.), which will mean reverting to pre-1.29.0 behavior.
@rustbot label T-compiler
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
Reproduce the provided Rust snippet and compare the Godbolt results for current Rust and the 1.29.0 regression link, including #[export_name] with #[target_feature]. Then trace the compiler handling of exported names and target features; done means LLVM-intrinsic-looking export names are rejected and target feature data is no longer erased.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100