-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Target features getting erased when using #[export_name]
with names of LLVM intrinsics
#140822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The example on godbolt has been producing llvm IR, but refused to codegen between The earlier change in (full list of PRs in nightly-2018-07-13)
so this was never been a rustc native behaviour, and we've always relied on LLVM to catch this (until recently). cc @nikic I'm not quite sure how @rustbot label: +A-llvm |
If you look closely, you can see that the function exported with the existing llvm intrinsic name has different target features than the other ones (in your example, the Without the target feature thing, this isn't formally a "bug", just surprising (but predictable) behavior. When the target features get erased, it will start to throw rustc-LLVM errors because the inside block uses |
Creating a definition for an intrinsic is invalid LLVM IR, the rest is not really relevant. The Rust frontend must generate an error when trying to use an export_name starting with |
TIL Rust "supports"
#[export_name]
with names of LLVM intrinsics! The following code compiles no problem(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 withllvm.
), which will mean reverting to pre-1.29.0 behavior.@rustbot label T-compiler
The text was updated successfully, but these errors were encountered: