Skip to content

Commit a461699

Browse files
committed
wip
1 parent b9c4435 commit a461699

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

.github/workflows/main.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ jobs:
5050
os: macos-15
5151
- target: aarch64-unknown-linux-gnu
5252
os: ubuntu-24.04-arm
53+
- target: aarch64-unknown-linux-gnu
54+
os: ubuntu-24.04-arm
55+
flags: -Z branch-protection=bti
56+
- target: aarch64-unknown-linux-gnu
57+
os: ubuntu-24.04-arm
58+
flags: -Z branch-protection=pac-ret,bti
59+
- target: aarch64-unknown-linux-gnu
60+
os: ubuntu-24.04-arm
61+
flags: -Z branch-protection=pac-ret,bti,b-key
62+
- target: aarch64-unknown-linux-gnu
63+
os: ubuntu-24.04 # QEMU
64+
- target: aarch64-unknown-linux-gnu
65+
os: ubuntu-24.04 # QEMU
66+
flags: -Z branch-protection=bti
67+
- target: aarch64-unknown-linux-gnu
68+
os: ubuntu-24.04 # QEMU
69+
flags: -Z branch-protection=pac-ret,bti
70+
- target: aarch64-unknown-linux-gnu
71+
os: ubuntu-24.04 # QEMU
72+
flags: -Z branch-protection=pac-ret,bti,b-key
5373
- target: aarch64-pc-windows-msvc
5474
os: windows-11-arm
5575
- target: arm-unknown-linux-gnueabi
@@ -174,11 +194,15 @@ jobs:
174194
if: matrix.os != 'ubuntu-24.04'
175195
shell: bash
176196
run: ./ci/run.sh ${{ matrix.target }}
197+
env:
198+
RUSTFLAGS: ${{ matrix.flags }} ${{ env.RUSTFLAGS }}
177199

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

183207
- name: Print test logs if available
184208
if: always()

compiler-builtins/build.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ fn main() {
2121
println!("cargo::rustc-check-cfg=cfg(kernel_user_helpers)");
2222
println!("cargo::rustc-check-cfg=cfg(feature, values(\"mem-unaligned\"))");
2323

24+
branch_protection_cfg();
25+
2426
// Emscripten's runtime includes all the builtins
2527
if target.os == "emscripten" {
2628
return;
@@ -180,6 +182,25 @@ fn configure_check_cfg() {
180182
// FIXME: these come from libm and should be changed there
181183
println!("cargo::rustc-check-cfg=cfg(feature, values(\"checked\"))");
182184
println!("cargo::rustc-check-cfg=cfg(assert_no_panic)");
185+
186+
println!("cargo::rustc-check-cfg=cfg(branch_protection, values(\"pac-ret\",\"bti\"))");
187+
}
188+
189+
fn branch_protection_cfg() {
190+
// flags: -Z branch-protection=pac-ret,bti,b-key
191+
if let Some(rustflags) = env::var_os("CARGO_ENCODED_RUSTFLAGS") {
192+
for mut flag in rustflags.to_string_lossy().split('\x1f') {
193+
if flag.starts_with("-Z") {
194+
flag = &flag["-Z".len()..];
195+
}
196+
if let Some(branch_protection) = flag.strip_prefix("branch-protection=") {
197+
for x in branch_protection.split(",") {
198+
println!("cargo:rustc-cfg=branch_protection=\"{x}\"")
199+
}
200+
return;
201+
}
202+
}
203+
}
183204
}
184205

185206
#[cfg(feature = "c")]

compiler-builtins/src/aarch64_outline_atomics.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,28 @@ foreach_ldadd!(add);
401401
foreach_ldclr!(and);
402402
foreach_ldeor!(xor);
403403
foreach_ldset!(or);
404+
405+
core::arch::global_asm!(
406+
"
407+
.pushsection .note.gnu.property, \"a\"
408+
.balign 8
409+
.word 4
410+
.word 0x10
411+
.word 0x5 // NT_GNU_PROPERTY_TYPE_0
412+
.asciz \"GNU\"
413+
.word 0xc0000000 // GNU_PROPERTY_AARCH64_FEATURE_1_AND
414+
.word 4
415+
",
416+
#[cfg(all(branch_protection = "bti", branch_protection = "pac-ret"))]
417+
".word 3",
418+
#[cfg(all(not(branch_protection = "bti"), branch_protection = "pac-ret"))]
419+
".word 2",
420+
#[cfg(all(branch_protection = "bti", not(branch_protection = "pac-ret")))]
421+
".word 1",
422+
#[cfg(all(not(branch_protection = "bti"), not(branch_protection = "pac-ret")))]
423+
".word 0",
424+
"
425+
.word 0
426+
.popsection
427+
"
428+
);

0 commit comments

Comments
 (0)