Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ jobs:
os: macos-15
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
flags: -Z branch-protection=bti -C link-arg=-Wl,-z,force-bti
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
flags: -Z branch-protection=pac-ret,bti -C link-arg=-Wl,-z,force-bti
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
flags: -Z branch-protection=pac-ret,bti,b-key -C link-arg=-Wl,-z,force-bti
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04 # QEMU
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04 # QEMU
flags: -Z branch-protection=bti -C link-arg=-Wl,-z,force-bti
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04 # QEMU
flags: -Z branch-protection=pac-ret,bti -C link-arg=-Wl,-z,force-bti
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04 # QEMU
flags: -Z branch-protection=pac-ret,bti,b-key -C link-arg=-Wl,-z,force-bti
- target: aarch64-pc-windows-msvc
os: windows-11-arm
- target: arm-unknown-linux-gnueabi
Expand Down Expand Up @@ -174,11 +194,15 @@ jobs:
if: matrix.os != 'ubuntu-24.04'
shell: bash
run: ./ci/run.sh ${{ matrix.target }}
env:
RUSTFLAGS: ${{ matrix.flags }} ${{ env.RUSTFLAGS }}

# Otherwise we use our docker containers to run builds
- name: Run in Docker
if: matrix.os == 'ubuntu-24.04'
run: ./ci/run-docker.sh ${{ matrix.target }}
env:
RUSTFLAGS: ${{ matrix.flags }} ${{ env.RUSTFLAGS }}

- name: Print test logs if available
if: always()
Expand Down
21 changes: 21 additions & 0 deletions compiler-builtins/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ fn main() {
println!("cargo::rustc-check-cfg=cfg(kernel_user_helpers)");
println!("cargo::rustc-check-cfg=cfg(feature, values(\"mem-unaligned\"))");

branch_protection_cfg();

// Emscripten's runtime includes all the builtins
if target.os == "emscripten" {
return;
Expand Down Expand Up @@ -180,6 +182,25 @@ fn configure_check_cfg() {
// FIXME: these come from libm and should be changed there
println!("cargo::rustc-check-cfg=cfg(feature, values(\"checked\"))");
println!("cargo::rustc-check-cfg=cfg(assert_no_panic)");

println!("cargo::rustc-check-cfg=cfg(branch_protection, values(\"pac-ret\",\"bti\"))");
}

fn branch_protection_cfg() {
// flags: -Z branch-protection=pac-ret,bti,b-key
if let Some(rustflags) = env::var_os("CARGO_ENCODED_RUSTFLAGS") {
for mut flag in rustflags.to_string_lossy().split('\x1f') {
if flag.starts_with("-Z") {
flag = &flag["-Z".len()..];
}
if let Some(branch_protection) = flag.strip_prefix("branch-protection=") {
for x in branch_protection.split(",") {
println!("cargo:rustc-cfg=branch_protection=\"{x}\"")
}
return;
}
}
}
}

#[cfg(feature = "c")]
Expand Down
29 changes: 29 additions & 0 deletions compiler-builtins/src/aarch64_outline_atomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ macro_rules! compare_and_swap {
) -> int_ty!($bytes) {
// We can't use `AtomicI8::compare_and_swap`; we *are* compare_and_swap.
core::arch::naked_asm! {
"hint #34", // BTI c
// CAS s(0), s(1), [x2]; if LSE supported.
try_lse_op!("cas", $ordering, $bytes, 0, 1, [x2]),
// UXT s(tmp0), s(0)
Expand Down Expand Up @@ -213,6 +214,7 @@ macro_rules! compare_and_swap_i128 {
expected: i128, desired: i128, ptr: *mut i128
) -> i128 {
core::arch::naked_asm! {
"hint #34", // BTI c
// CASP x0, x1, x2, x3, [x4]; if LSE supported.
try_lse_op!("cas", $ordering, 16, 0, 1, 2, 3, [x4]),
"mov x16, x0",
Expand Down Expand Up @@ -245,6 +247,7 @@ macro_rules! swap {
left: int_ty!($bytes), right_ptr: *mut int_ty!($bytes)
) -> int_ty!($bytes) {
core::arch::naked_asm! {
"hint #34", // BTI c
// SWP s(0), s(0), [x1]; if LSE supported.
try_lse_op!("swp", $ordering, $bytes, 0, 0, [x1]),
// mov s(tmp0), s(0)
Expand Down Expand Up @@ -273,6 +276,7 @@ macro_rules! fetch_op {
val: int_ty!($bytes), ptr: *mut int_ty!($bytes)
) -> int_ty!($bytes) {
core::arch::naked_asm! {
"hint #34", // BTI c
// LSEOP s(0), s(0), [x1]; if LSE supported.
try_lse_op!($lse_op, $ordering, $bytes, 0, 0, [x1]),
// mov s(tmp0), s(0)
Expand Down Expand Up @@ -397,3 +401,28 @@ foreach_ldadd!(add);
foreach_ldclr!(and);
foreach_ldeor!(xor);
foreach_ldset!(or);

core::arch::global_asm!(
"
.pushsection .note.gnu.property, \"a\"
.balign 8
.word 4
.word 0x10
.word 0x5 // NT_GNU_PROPERTY_TYPE_0
.asciz \"GNU\"
.word 0xc0000000 // GNU_PROPERTY_AARCH64_FEATURE_1_AND
.word 4
",
#[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",
Comment on lines +416 to +423
Copy link
Contributor

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

Suggested change
#[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",
),

"
.word 0
.popsection
"
);
Loading