From be9b58aebb69c84d049afbde977042db2d6a7cbb Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Sat, 4 Jul 2020 09:45:45 -0700 Subject: [PATCH 1/4] Support for Harvey. Harvey is Plan 9 with GPL. Signed-off-by: Ronald G. Minnich --- src/librustc_target/spec/mod.rs | 3 +++ src/librustc_target/spec/x86_64_harvey.rs | 32 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/librustc_target/spec/x86_64_harvey.rs 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..9ff60de15f97f --- /dev/null +++ b/src/librustc_target/spec/x86_64_harvey.rs @@ -0,0 +1,32 @@ +// This defines the amd64 target for the Linux Kernel. See the linux-kernel-base module for +// generic Linux kernel options. + +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 { + // FIXME: Some dispute, the linux-on-clang folks think this should use "Linux" + 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, + }) +} From 03e36657f786edc797583463b34b95e7aa2595b1 Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Sat, 4 Jul 2020 09:57:45 -0700 Subject: [PATCH 2/4] add Harvey spec file for x86_64 Signed-off-by: Ronald G. Minnich --- .../spec/x86_64_unknown_harvey.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/librustc_target/spec/x86_64_unknown_harvey.rs 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..87bb433373270 --- /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: "linux".to_string(), + target_env: "gnu".to_string(), + target_vendor: "unknown".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: base, + }) +} From fec90cd0293f0d08529be40547d921a2a13b70d5 Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Sat, 4 Jul 2020 10:07:34 -0700 Subject: [PATCH 3/4] add the harvey_base.rs Derived from Linux, with dynamic linking set to false and elf TLS set to false (not sure on that second one). Signed-off-by: Ronald G. Minnich --- src/librustc_target/spec/harvey_base.rs | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/librustc_target/spec/harvey_base.rs 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() + } +} From 0b8264c6e224d751d0e0464a1dfcd845070d447f Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Sat, 4 Jul 2020 10:43:09 -0700 Subject: [PATCH 4/4] adjust a few more things, add some explanations. Signed-off-by: Ronald G. Minnich --- src/librustc_target/spec/x86_64_harvey.rs | 6 +++--- src/librustc_target/spec/x86_64_unknown_harvey.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc_target/spec/x86_64_harvey.rs b/src/librustc_target/spec/x86_64_harvey.rs index 9ff60de15f97f..880cc078d5bc2 100644 --- a/src/librustc_target/spec/x86_64_harvey.rs +++ b/src/librustc_target/spec/x86_64_harvey.rs @@ -1,5 +1,6 @@ -// This defines the amd64 target for the Linux Kernel. See the linux-kernel-base module for -// generic Linux kernel options. +// 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}; @@ -14,7 +15,6 @@ pub fn target() -> TargetResult { base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string()); Ok(Target { - // FIXME: Some dispute, the linux-on-clang folks think this should use "Linux" llvm_target: "x86_64-elf".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), diff --git a/src/librustc_target/spec/x86_64_unknown_harvey.rs b/src/librustc_target/spec/x86_64_unknown_harvey.rs index 87bb433373270..3b9d281ef8708 100644 --- a/src/librustc_target/spec/x86_64_unknown_harvey.rs +++ b/src/librustc_target/spec/x86_64_unknown_harvey.rs @@ -15,7 +15,7 @@ pub fn target() -> TargetResult { 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: "linux".to_string(), + target_os: "harvey".to_string(), target_env: "gnu".to_string(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc,