diff --git a/src/librustc_target/spec/harvey_base.rs b/src/librustc_target/spec/harvey_base.rs new file mode 100644 index 0000000000000..856567ac8a918 --- /dev/null +++ b/src/librustc_target/spec/harvey_base.rs @@ -0,0 +1,33 @@ +use crate::spec::{LinkArgs, LinkerFlavor, RelroLevel, TargetOptions}; + +pub fn opts() -> TargetOptions { + let mut args = LinkArgs::new(); + args.insert( + LinkerFlavor::Gcc, + vec![ + // We want to be able to strip as much executable code as possible + // from the linker command line, and this flag indicates to the + // linker that it can avoid linking in dynamic libraries that don't + // actually satisfy any symbols up to that point (as with many other + // resolutions the linker does). This option only applies to all + // following libraries so we're sure to pass it as one of the first + // arguments. + "-Wl,--as-needed".to_string(), + // Always enable NX protection when it is available + "-Wl,-z,noexecstack".to_string(), + ], + ); + + TargetOptions { + dynamic_linking: false, + executables: true, + target_family: Some("unix".to_string()), + linker_is_gnu: true, + has_rpath: true, + pre_link_args: args, + position_independent_executables: true, + relro_level: RelroLevel::Full, + has_elf_tls: false, + ..Default::default() + } +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 29250f21383be..cec119e13f331 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -57,6 +57,7 @@ mod freebsd_base; mod freestanding_base; mod fuchsia_base; mod haiku_base; +mod harvey_base; mod hermit_base; mod hermit_kernel_base; mod illumos_base; @@ -574,6 +575,8 @@ supported_targets! { ("i686-unknown-haiku", i686_unknown_haiku), ("x86_64-unknown-haiku", x86_64_unknown_haiku), + ("x86_64-unknown-harvey", x86_64_unknown_harvey), + ("x86_64-apple-darwin", x86_64_apple_darwin), ("i686-apple-darwin", i686_apple_darwin), diff --git a/src/librustc_target/spec/x86_64_harvey.rs b/src/librustc_target/spec/x86_64_harvey.rs new file mode 100644 index 0000000000000..880cc078d5bc2 --- /dev/null +++ b/src/librustc_target/spec/x86_64_harvey.rs @@ -0,0 +1,32 @@ +// This defines the x86_64 target for the Harvey Kernel. See the harvey-kernel-base module for +// generic Harvey kernel options. Note that in Harvey, as in Plan 9 and Go, we call x86_64 +// amd64. + +use crate::spec::{CodeModel, LinkerFlavor, Target, TargetResult}; + +pub fn target() -> TargetResult { + let mut base = super::harvey_kernel_base::opts(); + base.cpu = "x86-64".to_string(); + base.max_atomic_width = Some(64); + base.features = + "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float" + .to_string(); + base.code_model = Some(CodeModel::Kernel); + base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string()); + + Ok(Target { + llvm_target: "x86_64-elf".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + .to_string(), + target_os: "none".to_string(), + target_env: "gnu".to_string(), + target_vendor: "unknown".to_string(), + arch: "x86_64".to_string(), + linker_flavor: LinkerFlavor::Gcc, + + options: base, + }) +} diff --git a/src/librustc_target/spec/x86_64_unknown_harvey.rs b/src/librustc_target/spec/x86_64_unknown_harvey.rs new file mode 100644 index 0000000000000..3b9d281ef8708 --- /dev/null +++ b/src/librustc_target/spec/x86_64_unknown_harvey.rs @@ -0,0 +1,24 @@ +use crate::spec::{LinkerFlavor, Target, TargetResult}; + +pub fn target() -> TargetResult { + let mut base = super::harvey_base::opts(); + base.cpu = "x86-64".to_string(); + base.max_atomic_width = Some(64); + base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string()); + base.stack_probes = true; + + Ok(Target { + llvm_target: "x86_64-unknown-harvey-gnu".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + .to_string(), + arch: "x86_64".to_string(), + target_os: "harvey".to_string(), + target_env: "gnu".to_string(), + target_vendor: "unknown".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: base, + }) +}