Skip to content
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

Enable stack probes on aarch64 for LLVM 18 #118491

Merged
merged 2 commits into from
Dec 14, 2023
Merged
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
13 changes: 11 additions & 2 deletions compiler/rustc_target/src/spec/base/apple/mod.rs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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()
},
Original file line number Diff line number Diff line change
@@ -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
},
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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()
},
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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()
},
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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()
},
}
Original file line number Diff line number Diff line change
@@ -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()
};
Original file line number Diff line number Diff line change
@@ -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()
};
Original file line number Diff line number Diff line change
@@ -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()
},
}
Original file line number Diff line number Diff line change
@@ -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 {
Original file line number Diff line number Diff line change
@@ -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(),
Original file line number Diff line number Diff line change
@@ -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()
},
}
8 changes: 2 additions & 6 deletions compiler/rustc_target/src/spec/targets/i386_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -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) },
}
}
3 changes: 1 addition & 2 deletions compiler/rustc_target/src/spec/targets/i686_apple_darwin.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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
let arch = Arch::I386;
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 {
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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;
let mut base = opts("macos", arch);
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;

8 changes: 2 additions & 6 deletions compiler/rustc_target/src/spec/targets/x86_64_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -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 },
}
}
Original file line number Diff line number Diff line change
@@ -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 },
}
}
8 changes: 2 additions & 6 deletions compiler/rustc_target/src/spec/targets/x86_64_apple_tvos.rs
Original file line number Diff line number Diff line change
@@ -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) },
}
}
Original file line number Diff line number Diff line change
@@ -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) },
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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;
let mut base = opts("macos", arch);
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;

Original file line number Diff line number Diff line change
@@ -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]);
}
4 changes: 3 additions & 1 deletion tests/codegen/stack-probes-inline.rs
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion tests/ui/abi/stack-probes-lto.rs
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion tests/ui/abi/stack-probes.rs
Original file line number Diff line number Diff line change
@@ -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