-
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
Add -Zfixed-x18
#124655
Merged
Merged
Add -Zfixed-x18
#124655
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
40f0172
Add -Zfixed-x18
Darksonn 518becf
Fail on non-aarch64 targets
Darksonn b780fa9
Use an error struct instead of a panic
Darksonn 0ce51f5
Remove fixed_x18.aarch64.stderr
Darksonn 7677ff2
Remove aarch64 from revisions list
Darksonn 4aafecb
Simplify check for unsupported architectures
Darksonn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# `fixed-x18` | ||
|
||
This option prevents the compiler from using the x18 register. It is only | ||
supported on aarch64. | ||
|
||
From the [ABI spec][arm-abi]: | ||
|
||
> X18 is the platform register and is reserved for the use of platform ABIs. | ||
> This is an additional temporary register on platforms that don't assign a | ||
> special meaning to it. | ||
|
||
This flag only has an effect when the x18 register would otherwise be considered | ||
a temporary register. When the flag is applied, x18 is always a reserved | ||
register. | ||
|
||
This flag is intended for use with the shadow call stack sanitizer. Generally, | ||
when that sanitizer is enabled, the x18 register is used to store a pointer to | ||
the shadow stack. Enabling this flag prevents the compiler from overwriting the | ||
shadow stack pointer with temporary data, which is necessary for the sanitizer | ||
to work correctly. | ||
|
||
Currently, the `-Zsanitizer=shadow-call-stack` flag is only supported on | ||
platforms that always treat x18 as a reserved register, and the `-Zfixed-x18` | ||
flag is not required to use the sanitizer on such platforms. However, the | ||
sanitizer may be supported on targets where this is not the case in the future. | ||
|
||
It is undefined behavior for `-Zsanitizer=shadow-call-stack` code to call into | ||
code where x18 is a temporary register. On the other hand, when you are *not* | ||
using the shadow call stack sanitizer, compilation units compiled with and | ||
without the `-Zfixed-x18` flag are compatible with each other. | ||
|
||
[arm-abi]: https://developer.arm.com/documentation/den0024/a/The-ABI-for-ARM-64-bit-Architecture/Register-use-in-the-AArch64-Procedure-Call-Standard/Parameters-in-general-purpose-registers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Test that the `reserve-x18` target feature is (not) emitted when | ||
// the `-Zfixed-x18` flag is (not) set. | ||
|
||
//@ revisions: unset set | ||
//@ needs-llvm-components: aarch64 | ||
//@ compile-flags: --target aarch64-unknown-none | ||
//@ [set] compile-flags: -Zfixed-x18 | ||
|
||
#![crate_type = "lib"] | ||
#![feature(no_core, lang_items)] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
#[no_mangle] | ||
pub fn foo() { | ||
// CHECK: @foo() unnamed_addr #0 | ||
|
||
// unset-NOT: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+reserve-x18{{.*}} } | ||
// set: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+reserve-x18{{.*}} } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: the `-Zfixed-x18` flag is not supported on the `x86_64` architecture | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: the `-Zfixed-x18` flag is not supported on the `arm` architecture | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: the `-Zfixed-x18` flag is not supported on the `x86` architecture | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: the `-Zfixed-x18` flag is not supported on the `riscv32` architecture | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: the `-Zfixed-x18` flag is not supported on the `riscv64` architecture | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// This tests that -Zfixed-x18 causes a compilation failure on targets other than aarch64. | ||
// Behavior on aarch64 is tested by tests/codegen/fixed-x18.rs. | ||
// | ||
//@ revisions: x64 i686 aarch64 arm riscv32 riscv64 | ||
// | ||
//@ compile-flags: -Zfixed-x18 | ||
//@ [x64] needs-llvm-components: x86 | ||
//@ [x64] compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=rlib | ||
//@ [i686] needs-llvm-components: x86 | ||
//@ [i686] compile-flags: --target=i686-unknown-linux-gnu --crate-type=rlib | ||
//@ [arm] needs-llvm-components: arm | ||
//@ [arm] compile-flags: --target=armv7-unknown-linux-gnueabihf --crate-type=rlib | ||
//@ [riscv32] needs-llvm-components: riscv | ||
//@ [riscv32] compile-flags: --target=riscv32i-unknown-none-elf --crate-type=rlib | ||
//@ [riscv64] needs-llvm-components: riscv | ||
//@ [riscv64] compile-flags: --target=riscv64gc-unknown-none-elf --crate-type=rlib | ||
|
||
#![crate_type = "lib"] | ||
#![feature(no_core, lang_items)] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: the `-Zfixed-x18` flag is not supported on the `x86_64` architecture | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 used
emit_fatal
here because withemit_err
, the error is printed twice.