From c099cfab061e8464141a1cf85c2bd09536a311d0 Mon Sep 17 00:00:00 2001 From: Sebastian Wicki Date: Mon, 21 Sep 2015 19:16:24 +0200 Subject: [PATCH] Add support for the rumprun unikernel For most parts, rumprun currently looks like NetBSD, as they share the same libc and drivers. However, being a unikernel, rumprun does not support process management, signals or virtual memory, so related functions might fail at runtime. Stack guards are disabled exactly for this reason. Code for rumprun is always cross-compiled, it uses always static linking and needs a custom linker. --- configure | 6 ++++ mk/cfg/x86_64-rumprun-netbsd.mk | 24 +++++++++++++ src/liblibc/lib.rs | 6 +++- src/librustc_back/target/mod.rs | 1 + .../target/x86_64_rumprun_netbsd.rs | 35 +++++++++++++++++++ src/libstd/lib.rs | 1 + src/libstd/sys/common/libunwind.rs | 10 +++++- src/libstd/sys/unix/stack_overflow.rs | 4 +-- src/libstd/sys/unix/thread.rs | 4 +-- 9 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 mk/cfg/x86_64-rumprun-netbsd.mk create mode 100644 src/librustc_back/target/x86_64_rumprun_netbsd.rs diff --git a/configure b/configure index 1d95965150cae..fa2117dcc1d3d 100755 --- a/configure +++ b/configure @@ -1295,6 +1295,12 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake putvar CFG_MSVC_LIB_PATH_${bits} ;; + *-rumprun-netbsd) + step_msg "targeting rumprun-netbsd, disabling jemalloc" + CFG_DISABLE_JEMALLOC=1 + putvar CFG_DISABLE_JEMALLOC + ;; + *) ;; esac diff --git a/mk/cfg/x86_64-rumprun-netbsd.mk b/mk/cfg/x86_64-rumprun-netbsd.mk new file mode 100644 index 0000000000000..5894805e3e5c9 --- /dev/null +++ b/mk/cfg/x86_64-rumprun-netbsd.mk @@ -0,0 +1,24 @@ +# x86_64-rumprun-netbsd configuration +CROSS_PREFIX_x86_64-rumprun-netbsd=x86_64-rumprun-netbsd- +CC_x86_64-rumprun-netbsd=gcc +CXX_x86_64-rumprun-netbsd=g++ +CPP_x86_64-rumprun-netbsd=gcc -E +AR_x86_64-rumprun-netbsd=ar +CFG_INSTALL_ONLY_RLIB_x86_64-rumprun-netbsd = 1 +CFG_LIB_NAME_x86_64-rumprun-netbsd=lib$(1).so +CFG_STATIC_LIB_NAME_x86_64-rumprun-netbsd=lib$(1).a +CFG_LIB_GLOB_x86_64-rumprun-netbsd=lib$(1)-*.so +CFG_JEMALLOC_CFLAGS_x86_64-rumprun-netbsd := -m64 +CFG_GCCISH_CFLAGS_x86_64-rumprun-netbsd := -Wall -Werror -g -fPIC -m64 +CFG_GCCISH_CXXFLAGS_x86_64-rumprun-netbsd := +CFG_GCCISH_LINK_FLAGS_x86_64-rumprun-netbsd := +CFG_GCCISH_DEF_FLAG_x86_64-rumprun-netbsd := +CFG_LLC_FLAGS_x86_64-rumprun-netbsd := +CFG_INSTALL_NAME_x86_64-rumprun-netbsd = +CFG_EXE_SUFFIX_x86_64-rumprun-netbsd = +CFG_WINDOWSY_x86_64-rumprun-netbsd := +CFG_UNIXY_x86_64-rumprun-netbsd := 1 +CFG_LDPATH_x86_64-rumprun-netbsd := +CFG_RUN_x86_64-rumprun-netbsd=$(2) +CFG_RUN_TARG_x86_64-rumprun-netbsd=$(call CFG_RUN_x86_64-rumprun-netbsd,,$(2)) +CFG_GNU_TRIPLE_x86_64-rumprun-netbsd := x86_64-rumprun-netbsd diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 2ee69543c3cf3..f75851506c279 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -24,6 +24,7 @@ html_playground_url = "https://play.rust-lang.org/", issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")] #![cfg_attr(test, feature(test))] +#![feature(cfg_target_vendor)] //! Bindings for the C standard library and other platform libraries //! @@ -143,7 +144,10 @@ pub use funcs::bsd43::*; // On NaCl, these libraries are static. Thus it would be a Bad Idea to link them // in when creating a test crate. -#[cfg(not(any(windows, target_env = "musl", all(target_os = "nacl", test))))] +#[cfg(not(any(windows, + target_env = "musl", + all(target_os = "nacl", test), + all(target_os = "netbsd", target_vendor = "rumprun"))))] #[link(name = "c")] #[link(name = "m")] extern {} diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index b5847b98af1f6..be404fc97ce08 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -411,6 +411,7 @@ impl Target { x86_64_unknown_bitrig, x86_64_unknown_openbsd, x86_64_unknown_netbsd, + x86_64_rumprun_netbsd, x86_64_apple_darwin, i686_apple_darwin, diff --git a/src/librustc_back/target/x86_64_rumprun_netbsd.rs b/src/librustc_back/target/x86_64_rumprun_netbsd.rs new file mode 100644 index 0000000000000..d63ad53cc2bb9 --- /dev/null +++ b/src/librustc_back/target/x86_64_rumprun_netbsd.rs @@ -0,0 +1,35 @@ +// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use target::Target; + +pub fn target() -> Target { + let mut base = super::netbsd_base::opts(); + base.pre_link_args.push("-m64".to_string()); + base.linker = "x86_64-rumprun-netbsd-gcc".to_string(); + base.ar = "x86_64-rumprun-netbsd-ar".to_string(); + + base.dynamic_linking = false; + base.has_rpath = false; + base.position_independent_executables = false; + base.disable_redzone = true; + base.no_default_libraries = false; + + Target { + llvm_target: "x86_64-rumprun-netbsd".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + arch: "x86_64".to_string(), + target_os: "netbsd".to_string(), + target_env: "".to_string(), + target_vendor: "rumprun".to_string(), + options: base, + } +} diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index c67a4182f54cb..9129ffcc21182 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -204,6 +204,7 @@ #![feature(associated_consts)] #![feature(borrow_state)] #![feature(box_syntax)] +#![feature(cfg_target_vendor)] #![feature(char_from_unchecked)] #![feature(char_internals)] #![feature(clone_from_slice)] diff --git a/src/libstd/sys/common/libunwind.rs b/src/libstd/sys/common/libunwind.rs index c6bffb0f733ee..da7ebbf4ed39f 100644 --- a/src/libstd/sys/common/libunwind.rs +++ b/src/libstd/sys/common/libunwind.rs @@ -108,10 +108,18 @@ extern {} #[link(name = "unwind", kind = "static")] extern {} -#[cfg(any(target_os = "android", target_os = "netbsd", target_os = "openbsd"))] +#[cfg(any(target_os = "android", target_os = "openbsd"))] #[link(name = "gcc")] extern {} +#[cfg(all(target_os = "netbsd", not(target_vendor = "rumprun")))] +#[link(name = "gcc")] +extern {} + +#[cfg(all(target_os = "netbsd", target_vendor = "rumprun"))] +#[link(name = "unwind")] +extern {} + #[cfg(target_os = "dragonfly")] #[link(name = "gcc_pic")] extern {} diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index 441313bc63993..f5fd11b61b1e6 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -34,7 +34,7 @@ impl Drop for Handler { #[cfg(any(target_os = "linux", target_os = "macos", target_os = "bitrig", - target_os = "netbsd", + all(target_os = "netbsd", not(target_vendor = "rumprun")), target_os = "openbsd"))] mod imp { use super::Handler; @@ -143,7 +143,7 @@ mod imp { #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "bitrig", - target_os = "netbsd", + all(target_os = "netbsd", not(target_vendor = "rumprun")), target_os = "openbsd")))] mod imp { use ptr; diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 83e0a03a2341e..50e01ecf9fa98 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -174,7 +174,7 @@ impl Drop for Thread { #[cfg(all(not(target_os = "linux"), not(target_os = "macos"), not(target_os = "bitrig"), - not(target_os = "netbsd"), + not(all(target_os = "netbsd", not(target_vendor = "rumprun"))), not(target_os = "openbsd")))] pub mod guard { pub unsafe fn current() -> Option { None } @@ -185,7 +185,7 @@ pub mod guard { #[cfg(any(target_os = "linux", target_os = "macos", target_os = "bitrig", - target_os = "netbsd", + all(target_os = "netbsd", not(target_vendor = "rumprun")), target_os = "openbsd"))] #[allow(unused_imports)] pub mod guard {