-
Notifications
You must be signed in to change notification settings - Fork 258
WIP: Use BTI c in aarch64_outline_atomic.rs #1063
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
base: main
Are you sure you want to change the base?
Conversation
|
grep'ing compiler-builtins, I don't see any mention of bti at all. Maybe instead of adding |
|
For normal Rust functions, the BTI c should be inserted by the compiler as needed. For global assemblies, the BTI c should be explicitly written within the assembly as needed. However, it is unclear whose responsibility it should be for naked functions (what we use for outline_atomic). At least currently, the naked function does nothing, but -Z branch-protection is unstable so we can change its behavior. |
| #[cfg(all(branch_protection = "bti", branch_protection = "pac-ret"))] | ||
| ".word 3", | ||
| #[cfg(all(not(branch_protection = "bti"), branch_protection = "pac-ret"))] | ||
| ".word 2", | ||
| #[cfg(all(branch_protection = "bti", not(branch_protection = "pac-ret")))] | ||
| ".word 1", | ||
| #[cfg(all(not(branch_protection = "bti"), not(branch_protection = "pac-ret")))] | ||
| ".word 0", |
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 think cfg_select would be nicer here
| #[cfg(all(branch_protection = "bti", branch_protection = "pac-ret"))] | |
| ".word 3", | |
| #[cfg(all(not(branch_protection = "bti"), branch_protection = "pac-ret"))] | |
| ".word 2", | |
| #[cfg(all(branch_protection = "bti", not(branch_protection = "pac-ret")))] | |
| ".word 1", | |
| #[cfg(all(not(branch_protection = "bti"), not(branch_protection = "pac-ret")))] | |
| ".word 0", | |
| cfg_select! ( | |
| all(branch_protection = "bti", branch_protection = "pac-ret") => ".word 3", | |
| branch_protection = "pac-ret" => ".word 2", | |
| branch_protection = "bti" => ".word 1", | |
| _ => ".word 0", | |
| ), |
|
I'm not that familiar with how this works, but generally the aim is to make naked functions "just work". So I'd say naked functions should support the flag. |
|
There was some discussion about naked functions vs. bti on the llvm side: llvm/llvm-project#56369 but it didn't conclude. I'm not actually sure what the current behavior is. |
|
Rust naked functions are entirely distinct from LLVM naked functions. We lower them to a block of global assembly + an |
|
I would actually prefer not having a BTI automatically inserted at the start of naked functions. The main purpose of naked functions is to support custom calling conventions which cannot be otherwise supported by the Rust compiler. In those cases we don't want to mess with what the user is intending for these functions to contain. |
|
Ah, I misunderstood: this actually adds instructions. Then I agree that we should not add that. And then |
|
Is there any reason these functions need to be naked at all? They don't use a custom calling convention and could just be implemented using plain |
Potential fix for rust-lang/rust#151486.
TODO: