Skip to content

Commit

Permalink
Auto merge of rust-lang#118491 - cuviper:aarch64-stack-probes, r=wesl…
Browse files Browse the repository at this point in the history
…eywiser

Enable stack probes on aarch64 for LLVM 18

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

cc rust-lang#77071, to be closed once we upgrade our LLVM submodule.
  • Loading branch information
bors committed Dec 14, 2023
2 parents 5f73b00 + 233de9d commit e6d1b0e
Show file tree
Hide file tree
Showing 33 changed files with 86 additions and 65 deletions.
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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
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 {
Expand All @@ -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()
Expand Down
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();
Expand All @@ -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
Expand Down
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 {
Expand All @@ -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()
},
Expand Down
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");
Expand All @@ -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
},
}
Expand Down
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.
Expand All @@ -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
Expand Down
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");

Expand All @@ -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,
Expand Down
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 {
Expand All @@ -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
Expand Down
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 {
Expand All @@ -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,
Expand Down
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 {
Expand All @@ -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()
},
}
Expand Down
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 {
Expand All @@ -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
Expand Down
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 {
Expand All @@ -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()
},
Expand Down
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
Expand Down
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();
Expand All @@ -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
Expand Down
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 {
Expand All @@ -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()
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
};
Expand Down
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 {
Expand All @@ -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()
},
}
Expand Down
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 {
Expand Down
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(),
Expand Down
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 {
Expand All @@ -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()
},
}
Expand Down
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;
Expand All @@ -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 {
Expand Down
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;

Expand Down
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;
Expand All @@ -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 },
}
}
Loading

0 comments on commit e6d1b0e

Please sign in to comment.