-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix handling of x18 in AArch64 inline assembly on ohos/trusty or with -Zfixed-x18 #133463
base: master
Are you sure you want to change the base?
Conversation
These commits modify compiler targets. Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
a43aa35
to
0c8db6e
Compare
This comment has been minimized.
This comment has been minimized.
0c8db6e
to
85b9750
Compare
cc @Darksonn (who added -Zfixed-x18 in #124655) |
This comment has been minimized.
This comment has been minimized.
85b9750
to
f4b01b5
Compare
This comment has been minimized.
This comment has been minimized.
f4b01b5
to
687dc19
Compare
pub(crate) fn target_reserves_x18(target: &Target, target_features: &FxIndexSet<Symbol>) -> bool { | ||
// See isX18ReservedByDefault in LLVM for targets reserve x18 by default: | ||
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/TargetParser/AArch64TargetParser.cpp#L102-L105 | ||
// Note that +reserve-x18 is currently not set for the above targets. | ||
target.os == "android" | ||
|| target.os == "fuchsia" | ||
|| target.env == "ohos" | ||
|| target.is_like_osx | ||
|| target.is_like_windows | ||
|| target_features.contains(&sym::reserve_x18) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to avoid duplicating this logic? It seems prone to getting out of sync with llvm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of a good way to avoid the duplication unfortunately.
This seems correct as far as Trusty is concerned, thanks @taiki-e for addressing this ❤️ I wasn't aware of this when I added the Trusty targets, but as far as I know we don't directly use the |
@bors r+ |
Currently AArch64 inline assembly allows using x18 on ohos/trusty or with -Zfixed-x18.
rust/compiler/rustc_target/src/asm/aarch64.rs
Lines 74 to 76 in 7db7489
However, x18 is reserved in these environments and should not be allowed in the input/output operands of inline assemblies as it is in Android, Windows, etc..
rust/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_ohos.rs
Line 19 in 7db7489
rust/compiler/rustc_target/src/spec/targets/aarch64_unknown_trusty.rs
Line 18 in 7db7489
rust/compiler/rustc_codegen_llvm/src/llvm_util.rs
Lines 764 to 771 in 7db7489
(As for ohos, +reserve-x18 is redundant since 7a966b9 that starting using llvm's ohos targets. So removed it from target-spec.)
This fix may potentially break the code for tier 2 target (aarch64-unknown-linux-ohos). (As for others, aarch64-unknown-trusty is tier 3 and -Zfixed-x18 is unstable so breaking them should be fine.)
However, in any case, it seems suspicious that the code that is broken by this was sound.
r? @Amanieu
@rustbot label O-AArch64 +A-inline-assembly