Auto merge of #118491 - cuviper:aarch64-stack-probes, r=wesleywiser

Enable stack probes on aarch64 for LLVM 18

I tested this on `aarch64-unknown-linux-gnu` with LLVM main (~18).

cc #77071, to be closed once we upgrade our LLVM submodule.
This commit is contained in:
bors 2023-12-14 02:01:13 +00:00
commit e6d1b0ec98
33 changed files with 86 additions and 65 deletions

View File

@ -1,8 +1,8 @@
use std::{borrow::Cow, env};
use crate::spec::{add_link_args, add_link_args_iter};
use crate::spec::{cvs, Cc, DebuginfoKind, FramePointer, LinkArgs};
use crate::spec::{LinkerFlavor, Lld, SplitDebuginfo, StaticCow, Target, TargetOptions};
use crate::spec::{cvs, Cc, DebuginfoKind, FramePointer, LinkArgs, LinkerFlavor, Lld};
use crate::spec::{SplitDebuginfo, StackProbeType, StaticCow, Target, TargetOptions};
#[cfg(test)]
mod tests;
@ -81,6 +81,14 @@ impl Arch {
Arm64_sim => "apple-a12",
}
}
fn stack_probes(self) -> StackProbeType {
match self {
Armv7k | Armv7s => StackProbeType::None,
Arm64 | Arm64e | Arm64_32 | I386 | I686 | X86_64 | X86_64h | X86_64_sim
| X86_64_macabi | Arm64_macabi | Arm64_sim => StackProbeType::Inline,
}
}
}
fn pre_link_args(os: &'static str, arch: Arch, abi: &'static str) -> LinkArgs {
@ -147,6 +155,7 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
abi_return_struct_as_int: true,
emit_debug_gdb_scripts: false,
eh_frame_header: false,
stack_probes: arch.stack_probes(),
debuginfo_kind: DebuginfoKind::DwarfDsym,
// The historical default for macOS targets is to run `dsymutil` which

View File

@ -1,5 +1,5 @@
use crate::abi::Endian;
use crate::spec::{base, Target, TargetOptions};
use crate::spec::{base, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
Target {
@ -10,6 +10,7 @@ pub fn target() -> Target {
options: TargetOptions {
features: "+v8a,+outline-atomics".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
mcount: "\u{1}_mcount".into(),
endian: Endian::Big,
..base::linux_gnu::opts()

View File

@ -1,5 +1,5 @@
use crate::abi::Endian;
use crate::spec::{base, Target, TargetOptions};
use crate::spec::{base, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
let mut base = base::linux_gnu::opts();
@ -13,6 +13,7 @@ pub fn target() -> Target {
options: TargetOptions {
abi: "ilp32".into(),
features: "+v8a,+outline-atomics".into(),
stack_probes: StackProbeType::Inline,
mcount: "\u{1}_mcount".into(),
endian: Endian::Big,
..base

View File

@ -1,5 +1,5 @@
use crate::abi::Endian;
use crate::spec::{base, Target, TargetOptions};
use crate::spec::{base, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
Target {
@ -10,6 +10,7 @@ pub fn target() -> Target {
options: TargetOptions {
mcount: "__mcount".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
endian: Endian::Big,
..base::netbsd::opts()
},

View File

@ -1,4 +1,4 @@
use crate::spec::{base, RelocModel, Target, TargetOptions};
use crate::spec::{base, RelocModel, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
let base = base::solid::opts("asp3");
@ -13,6 +13,7 @@ pub fn target() -> Target {
relocation_model: RelocModel::Static,
disable_redzone: true,
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
..base
},
}

View File

@ -1,4 +1,4 @@
use crate::spec::{base, SanitizerSet, Target, TargetOptions};
use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions};
// See https://developer.android.com/ndk/guides/abis.html#arm64-v8a
// for target ABI requirements.
@ -14,6 +14,7 @@ pub fn target() -> Target {
// As documented in https://developer.android.com/ndk/guides/cpu-features.html
// the neon (ASIMD) and FP must exist on all android aarch64 targets.
features: "+v8a,+neon,+fp-armv8".into(),
stack_probes: StackProbeType::Inline,
supported_sanitizers: SanitizerSet::CFI
| SanitizerSet::HWADDRESS
| SanitizerSet::MEMTAG

View File

@ -1,4 +1,6 @@
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelroLevel, Target, TargetOptions};
use crate::spec::{
Cc, LinkerFlavor, Lld, PanicStrategy, RelroLevel, StackProbeType, Target, TargetOptions,
};
const LINKER_SCRIPT: &str = include_str!("./aarch64_nintendo_switch_freestanding_linker_script.ld");
@ -16,6 +18,7 @@ pub fn target() -> Target {
link_script: Some(LINKER_SCRIPT.into()),
os: "horizon".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
panic_strategy: PanicStrategy::Abort,
position_independent_executables: true,
dynamic_linking: true,

View File

@ -1,4 +1,4 @@
use crate::spec::{base, SanitizerSet, Target, TargetOptions};
use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
Target {
@ -9,6 +9,7 @@ pub fn target() -> Target {
options: TargetOptions {
features: "+v8a".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
supported_sanitizers: SanitizerSet::ADDRESS
| SanitizerSet::CFI
| SanitizerSet::MEMORY

View File

@ -1,4 +1,4 @@
use crate::spec::{base, SanitizerSet, Target, TargetOptions};
use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
Target {
@ -9,6 +9,7 @@ pub fn target() -> Target {
options: TargetOptions {
features: "+v8a".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
supported_sanitizers: SanitizerSet::ADDRESS
| SanitizerSet::CFI
| SanitizerSet::SHADOWCALLSTACK,

View File

@ -1,4 +1,4 @@
use crate::spec::{base, Target, TargetOptions};
use crate::spec::{base, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
Target {
@ -9,6 +9,7 @@ pub fn target() -> Target {
options: TargetOptions {
features: "+v8a,+strict-align,+neon,+fp-armv8".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
..base::hermit::opts()
},
}

View File

@ -1,4 +1,4 @@
use crate::spec::{base, SanitizerSet, Target, TargetOptions};
use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
Target {
@ -10,6 +10,7 @@ pub fn target() -> Target {
features: "+v8a,+outline-atomics".into(),
mcount: "\u{1}_mcount".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
supported_sanitizers: SanitizerSet::ADDRESS
| SanitizerSet::CFI
| SanitizerSet::LEAK

View File

@ -1,4 +1,4 @@
use crate::spec::{base, Target, TargetOptions};
use crate::spec::{base, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
Target {
@ -10,6 +10,7 @@ pub fn target() -> Target {
abi: "ilp32".into(),
features: "+v8a,+outline-atomics".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
mcount: "\u{1}_mcount".into(),
..base::linux_gnu::opts()
},

View File

@ -1,10 +1,11 @@
use crate::spec::{base, SanitizerSet, Target, TargetOptions};
use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
let mut base = base::linux_musl::opts();
base.max_atomic_width = Some(128);
base.supports_xray = true;
base.features = "+v8a".into();
base.stack_probes = StackProbeType::Inline;
base.supported_sanitizers = SanitizerSet::ADDRESS
| SanitizerSet::CFI
| SanitizerSet::LEAK

View File

@ -1,5 +1,5 @@
use crate::spec::SanitizerSet;
use crate::spec::{base, Target, TargetOptions};
use crate::spec::{base, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
let mut base = base::linux_ohos::opts();
@ -14,6 +14,7 @@ pub fn target() -> Target {
options: TargetOptions {
features: "+reserve-x18".into(),
mcount: "\u{1}_mcount".into(),
stack_probes: StackProbeType::Inline,
supported_sanitizers: SanitizerSet::ADDRESS
| SanitizerSet::CFI
| SanitizerSet::LEAK

View File

@ -1,4 +1,4 @@
use crate::spec::{base, Target, TargetOptions};
use crate::spec::{base, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
Target {
@ -10,6 +10,7 @@ pub fn target() -> Target {
features: "+v8a".into(),
mcount: "__mcount".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
..base::netbsd::opts()
},
}

View File

@ -7,7 +7,8 @@
// For example, `-C target-cpu=cortex-a53`.
use crate::spec::{
Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, Target, TargetOptions,
Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, StackProbeType, Target,
TargetOptions,
};
pub fn target() -> Target {
@ -24,6 +25,7 @@ pub fn target() -> Target {
relocation_model: RelocModel::Static,
disable_redzone: true,
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
panic_strategy: PanicStrategy::Abort,
..Default::default()
};

View File

@ -6,7 +6,9 @@
//
// For example, `-C target-cpu=cortex-a53`.
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
use crate::spec::{
Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, StackProbeType, Target, TargetOptions,
};
pub fn target() -> Target {
let opts = TargetOptions {
@ -17,6 +19,7 @@ pub fn target() -> Target {
relocation_model: RelocModel::Static,
disable_redzone: true,
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
panic_strategy: PanicStrategy::Abort,
..Default::default()
};

View File

@ -1,4 +1,4 @@
use crate::spec::{base, Target, TargetOptions};
use crate::spec::{base, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
Target {
@ -9,6 +9,7 @@ pub fn target() -> Target {
options: TargetOptions {
features: "+v8a".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
..base::openbsd::opts()
},
}

View File

@ -1,8 +1,9 @@
use crate::spec::{base, Target};
use crate::spec::{base, StackProbeType, Target};
pub fn target() -> Target {
let mut base = base::redox::opts();
base.max_atomic_width = Some(128);
base.stack_probes = StackProbeType::Inline;
base.features = "+v8a".into();
Target {

View File

@ -1,9 +1,10 @@
use crate::spec::{base, Target};
use crate::spec::{base, StackProbeType, Target};
pub fn target() -> Target {
let mut base = base::teeos::opts();
base.features = "+strict-align,+neon,+fp-armv8".into();
base.max_atomic_width = Some(128);
base.stack_probes = StackProbeType::Inline;
Target {
llvm_target: "aarch64-unknown-none".into(),

View File

@ -1,4 +1,4 @@
use crate::spec::{base, Target, TargetOptions};
use crate::spec::{base, StackProbeType, Target, TargetOptions};
pub fn target() -> Target {
Target {
@ -9,6 +9,7 @@ pub fn target() -> Target {
options: TargetOptions {
features: "+v8a".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
..base::vxworks::opts()
},
}

View File

@ -1,5 +1,5 @@
use crate::spec::base::apple::{ios_sim_llvm_target, opts, Arch};
use crate::spec::{StackProbeType, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};
pub fn target() -> Target {
let arch = Arch::I386;
@ -14,10 +14,6 @@ pub fn target() -> Target {
f64:32:64-f80:128-n8:16:32-S128"
.into(),
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(64),
stack_probes: StackProbeType::Inline,
..opts("ios", arch)
},
options: TargetOptions { max_atomic_width: Some(64), ..opts("ios", arch) },
}
}

View File

@ -1,5 +1,5 @@
use crate::spec::base::apple::{macos_llvm_target, opts, Arch};
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions};
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, TargetOptions};
pub fn target() -> Target {
// ld64 only understands i386 and not i686
@ -7,7 +7,6 @@ pub fn target() -> Target {
let mut base = opts("macos", arch);
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::Inline;
base.frame_pointer = FramePointer::Always;
Target {

View File

@ -1,6 +1,6 @@
use crate::spec::base::apple::{macos_llvm_target, opts, Arch};
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, SanitizerSet};
use crate::spec::{StackProbeType, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};
pub fn target() -> Target {
let arch = Arch::X86_64;
@ -8,7 +8,6 @@ pub fn target() -> Target {
base.max_atomic_width = Some(128); // penryn+ supports cmpxchg16b
base.frame_pointer = FramePointer::Always;
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m64"]);
base.stack_probes = StackProbeType::Inline;
base.supported_sanitizers =
SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK | SanitizerSet::THREAD;

View File

@ -1,5 +1,5 @@
use crate::spec::base::apple::{ios_sim_llvm_target, opts, Arch};
use crate::spec::{SanitizerSet, StackProbeType, Target, TargetOptions};
use crate::spec::{SanitizerSet, Target, TargetOptions};
pub fn target() -> Target {
let arch = Arch::X86_64_sim;
@ -12,10 +12,6 @@ pub fn target() -> Target {
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
.into(),
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
..base
},
options: TargetOptions { max_atomic_width: Some(128), ..base },
}
}

View File

@ -1,5 +1,5 @@
use crate::spec::base::apple::{opts, Arch};
use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target, TargetOptions};
use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, Target, TargetOptions};
pub fn target() -> Target {
let llvm_target = "x86_64-apple-ios14.0-macabi";
@ -15,10 +15,6 @@ pub fn target() -> Target {
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
.into(),
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
..base
},
options: TargetOptions { max_atomic_width: Some(128), ..base },
}
}

View File

@ -1,5 +1,5 @@
use crate::spec::base::apple::{opts, tvos_sim_llvm_target, Arch};
use crate::spec::{StackProbeType, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};
pub fn target() -> Target {
let arch = Arch::X86_64_sim;
@ -9,10 +9,6 @@ pub fn target() -> Target {
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
.into(),
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
..opts("tvos", arch)
},
options: TargetOptions { max_atomic_width: Some(128), ..opts("tvos", arch) },
}
}

View File

@ -1,5 +1,5 @@
use crate::spec::base::apple::{opts, watchos_sim_llvm_target, Arch};
use crate::spec::{StackProbeType, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};
pub fn target() -> Target {
let arch = Arch::X86_64_sim;
@ -9,10 +9,6 @@ pub fn target() -> Target {
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
.into(),
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
..opts("watchos", arch)
},
options: TargetOptions { max_atomic_width: Some(128), ..opts("watchos", arch) },
}
}

View File

@ -1,6 +1,6 @@
use crate::spec::base::apple::{macos_llvm_target, opts, Arch};
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, SanitizerSet};
use crate::spec::{StackProbeType, Target, TargetOptions};
use crate::spec::{Target, TargetOptions};
pub fn target() -> Target {
let arch = Arch::X86_64h;
@ -8,7 +8,6 @@ pub fn target() -> Target {
base.max_atomic_width = Some(128);
base.frame_pointer = FramePointer::Always;
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m64"]);
base.stack_probes = StackProbeType::Inline;
base.supported_sanitizers =
SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK | SanitizerSet::THREAD;

View File

@ -1,10 +1,12 @@
// revisions: x86_64 i686
// revisions: x86_64 i686 aarch64
// assembly-output: emit-asm
//[x86_64] compile-flags: --target x86_64-unknown-linux-gnu
//[x86_64] compile-flags: --target x86_64-unknown-linux-gnu -C llvm-args=-x86-asm-syntax=intel
//[x86_64] needs-llvm-components: x86
//[i686] compile-flags: --target i686-unknown-linux-gnu
//[i686] compile-flags: --target i686-unknown-linux-gnu -C llvm-args=-x86-asm-syntax=intel
//[i686] needs-llvm-components: x86
// compile-flags: -C llvm-args=-x86-asm-syntax=intel
//[aarch64] compile-flags: --target aarch64-unknown-linux-gnu
//[aarch64] needs-llvm-components: aarch64
//[aarch64] min-llvm-version: 18
#![feature(no_core, lang_items)]
#![crate_type = "lib"]
@ -28,6 +30,7 @@ pub fn small_stack_probe(x: u8, f: fn(&mut [u8; 8192])) {
// CHECK-NOT: __rust_probestack
// x86_64: sub rsp, 4096
// i686: sub esp, 4096
// aarch64: sub sp, sp, #1, lsl #12
f(&mut [x; 8192]);
}
@ -37,5 +40,6 @@ pub fn big_stack_probe(x: u8, f: fn(&[u8; 65536])) {
// CHECK-NOT: __rust_probestack
// x86_64: sub rsp, 4096
// i686: sub esp, 4096
// aarch64: sub sp, sp, #1, lsl #12
f(&mut [x; 65536]);
}

View File

@ -2,7 +2,9 @@
// or `StackProbeType::InlineOrCall` when running on newer LLVM.
// compile-flags: -C no-prepopulate-passes
// revisions: powerpc powerpc64 powerpc64le s390x i686 x86_64
// revisions: aarch64 powerpc powerpc64 powerpc64le s390x i686 x86_64
//[aarch64] compile-flags: --target aarch64-unknown-linux-gnu
//[aarch64] needs-llvm-components: aarch64
//[powerpc] compile-flags: --target powerpc-unknown-linux-gnu
//[powerpc] needs-llvm-components: powerpc
//[powerpc64] compile-flags: --target powerpc64-unknown-linux-gnu

View File

@ -1,5 +1,7 @@
// revisions: x32 x64
// revisions: aarch64 x32 x64
// run-pass
//[aarch64] only-aarch64
//[aarch64] min-llvm-version: 18
//[x32] only-x86
//[x64] only-x86_64
// ignore-sgx no processes

View File

@ -1,5 +1,7 @@
// revisions: x32 x64
// revisions: aarch64 x32 x64
// run-pass
//[aarch64] only-aarch64
//[aarch64] min-llvm-version: 18
//[x32] only-x86
//[x64] only-x86_64
// ignore-emscripten no processes