Skip to content

Commit 91b1f80

Browse files
Rollup merge of rust-lang#156548 - jchlanda:jakub/pac_lib, r=davidtwco
Library support for aarch64-unknown-linux-pauthtest target This is a follow up to rust-lang#155722, adding library support for the target.
2 parents 19290a1 + b749630 commit 91b1f80

4 files changed

Lines changed: 55 additions & 4 deletions

File tree

library/std/src/sys/personality/gcc.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,35 @@ cfg_select! {
204204
}
205205
}
206206
_ => {
207+
#[rustc_force_inline]
208+
unsafe fn sign_lpad(context: *mut uw::_Unwind_Context, lpad: *const u8) -> *const u8 {
209+
cfg_select! {
210+
all(target_abi = "pauthtest", target_arch = "aarch64") => {
211+
// DWARF register number for SP on AArch64.
212+
const SP_REG: i32 = 31;
213+
214+
unsafe {
215+
let sp = uw::_Unwind_GetGR(context, SP_REG).addr() as u64;
216+
let mut addr = lpad.addr();
217+
218+
// `pacib` corresponds to `ptrauth_key_process_dependent_code` in <ptrauth.h>.
219+
core::arch::asm!(
220+
"pacib {addr}, {sp}",
221+
addr = inout(reg) addr,
222+
sp = in(reg) sp,
223+
options(nostack, preserves_flags)
224+
);
225+
226+
lpad.with_addr(addr)
227+
}
228+
}
229+
_ => {
230+
let _ = context;
231+
lpad
232+
}
233+
}
234+
}
235+
207236
/// Default personality routine, which is used directly on most targets
208237
/// and indirectly on Windows x86_64 and AArch64 via SEH.
209238
unsafe extern "C" fn rust_eh_personality_impl(
@@ -239,7 +268,8 @@ cfg_select! {
239268
exception_object.cast(),
240269
);
241270
uw::_Unwind_SetGR(context, UNWIND_DATA_REG.1, core::ptr::null());
242-
uw::_Unwind_SetIP(context, lpad);
271+
let maybe_signed_lpad = sign_lpad(context, lpad);
272+
uw::_Unwind_SetIP(context, maybe_signed_lpad);
243273
uw::_URC_INSTALL_CONTEXT
244274
}
245275
EHAction::Terminate => uw::_URC_FATAL_PHASE2_ERROR,

library/std/tests/pipe_subprocess.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ fn main() {
1313

1414
fn parent() {
1515
let me = env::current_exe().unwrap();
16+
// If a custom `runner` is set up for the current target, we'll be
17+
// executing `./runner ./test`, not just `./test`. For such a case,
18+
// use the same arguments for child to avoid executing `runner`
19+
// without an actual executable.
20+
let args = env::args();
1621

1722
let (rx, tx) = pipe().unwrap();
1823
assert!(
1924
process::Command::new(me)
25+
.args(args)
2026
.env("I_AM_THE_CHILD", "1")
2127
.stdout(tx)
2228
.status()

library/std/tests/process_spawning.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ fn issue_15149() {
2626
env::join_paths(paths).unwrap()
2727
};
2828

29-
let child_output =
30-
process::Command::new("mytest").env("PATH", &path).arg("child").output().unwrap();
29+
// If a custom `runner` is set up for the current target, we'll be executing `./runner ./test`,
30+
// not just `./test`. For such a case, use the same arguments for child to avoid executing
31+
// `runner` without an actual executable.
32+
let args = env::args();
33+
let child_output = process::Command::new("mytest")
34+
.args(args)
35+
.env("PATH", &path)
36+
.arg("child")
37+
.output()
38+
.unwrap();
3139

3240
assert!(
3341
child_output.status.success(),

library/unwind/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ cfg_select! {
5656
}
5757
}
5858

59-
#[cfg(target_env = "musl")]
59+
// `target_abi = "pauthtest"` is currently only used by the Linux/musl
60+
// `aarch64-unknown-linux-pauthtest` target. That target only supports unwinding
61+
// via libunwind.
62+
#[cfg(target_abi = "pauthtest")]
63+
#[link(name = "unwind")]
64+
unsafe extern "C" {}
65+
66+
#[cfg(all(target_env = "musl", not(target_abi = "pauthtest")))]
6067
cfg_select! {
6168
all(feature = "llvm-libunwind", feature = "system-llvm-libunwind") => {
6269
compile_error!("`llvm-libunwind` and `system-llvm-libunwind` cannot be enabled at the same time");

0 commit comments

Comments
 (0)