From 25c1bfe175fbdeb3ba67d9365a554602937c25a7 Mon Sep 17 00:00:00 2001 From: Michael Neumann Date: Fri, 19 Dec 2014 13:05:06 +0100 Subject: [PATCH 1/2] Several fixes for DragonFly (rebase) --- mk/cfg/x86_64-unknown-dragonfly.mk | 6 +++--- src/etc/snapshot.py | 3 +++ src/liblibc/lib.rs | 12 ++++++++++++ src/librustc_back/rpath.rs | 17 +---------------- src/librustc_back/target/dragonfly_base.rs | 11 ++++++++--- .../target/x86_64_unknown_dragonfly.rs | 11 ++++++++--- src/libstd/sys/unix/os.rs | 12 +++++++++++- 7 files changed, 46 insertions(+), 26 deletions(-) diff --git a/mk/cfg/x86_64-unknown-dragonfly.mk b/mk/cfg/x86_64-unknown-dragonfly.mk index 05414c79dd7..9665b5c7802 100644 --- a/mk/cfg/x86_64-unknown-dragonfly.mk +++ b/mk/cfg/x86_64-unknown-dragonfly.mk @@ -7,9 +7,9 @@ CFG_LIB_NAME_x86_64-unknown-dragonfly=lib$(1).so CFG_STATIC_LIB_NAME_x86_64-unknown-dragonfly=lib$(1).a CFG_LIB_GLOB_x86_64-unknown-dragonfly=lib$(1)-*.so CFG_LIB_DSYM_GLOB_x86_64-unknown-dragonfly=$(1)-*.dylib.dSYM -CFG_JEMALLOC_CFLAGS_x86_64-unknown-dragonfly := -I/usr/include -I/usr/local/include $(CFLAGS) -CFG_GCCISH_CFLAGS_x86_64-unknown-dragonfly := -Wall -Werror -g -fPIC -I/usr/include -I/usr/local/include $(CFLAGS) -CFG_GCCISH_LINK_FLAGS_x86_64-unknown-dragonfly := -shared -fPIC -g -pthread -lrt +CFG_JEMALLOC_CFLAGS_x86_64-unknown-dragonfly := -m64 -I/usr/include -I/usr/local/include $(CFLAGS) +CFG_GCCISH_CFLAGS_x86_64-unknown-dragonfly := -Wall -Werror -g -fPIC -m64 -I/usr/include -I/usr/local/include $(CFLAGS) +CFG_GCCISH_LINK_FLAGS_x86_64-unknown-dragonfly := -shared -fPIC -g -pthread -lrt -m64 CFG_GCCISH_DEF_FLAG_x86_64-unknown-dragonfly := -Wl,--export-dynamic,--dynamic-list= CFG_GCCISH_PRE_LIB_FLAGS_x86_64-unknown-dragonfly := -Wl,-whole-archive CFG_GCCISH_POST_LIB_FLAGS_x86_64-unknown-dragonfly := -Wl,-no-whole-archive diff --git a/src/etc/snapshot.py b/src/etc/snapshot.py index cb99da8092d..8f45f7f1af2 100644 --- a/src/etc/snapshot.py +++ b/src/etc/snapshot.py @@ -37,6 +37,7 @@ snapshot_files = { "macos": ["bin/rustc"], "winnt": ["bin/rustc.exe"], "freebsd": ["bin/rustc"], + "dragonfly": ["bin/rustc"], } winnt_runtime_deps_32 = ["libgcc_s_dw2-1.dll", @@ -86,6 +87,8 @@ def get_kernel(triple): return "macos" if os_name == "freebsd": return "freebsd" + if os_name == "dragonfly": + return "dragonfly" return "linux" def get_cpu(triple): diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 6ab00cfe8fa..7dcdc08943f 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -1095,6 +1095,7 @@ pub mod types { pub type sighandler_t = size_t; } pub mod bsd44 { + use types::common::c95::{c_void}; use types::os::arch::c95::{c_char, c_int, c_uint}; pub type socklen_t = u32; @@ -1167,6 +1168,17 @@ pub mod types { pub sun_family: sa_family_t, pub sun_path: [c_char, ..104] } + #[repr(C)] + #[deriving(Copy)] pub struct ifaddrs { + pub ifa_next: *mut ifaddrs, + pub ifa_name: *mut c_char, + pub ifa_flags: c_uint, + pub ifa_addr: *mut sockaddr, + pub ifa_netmask: *mut sockaddr, + pub ifa_dstaddr: *mut sockaddr, + pub ifa_data: *mut c_void + } + } } diff --git a/src/librustc_back/rpath.rs b/src/librustc_back/rpath.rs index 1f8549098d9..10ba023c619 100644 --- a/src/librustc_back/rpath.rs +++ b/src/librustc_back/rpath.rs @@ -215,22 +215,7 @@ mod test { } #[test] - #[cfg(target_os = "freebsd")] - fn test_rpath_relative() { - let config = &mut RPathConfig { - used_crates: Vec::new(), - has_rpath: true, - is_like_osx: false, - out_filename: Path::new("bin/rustc"), - get_install_prefix_lib_path: || panic!(), - realpath: |p| Ok(p.clone()) - }; - let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); - assert_eq!(res, "$ORIGIN/../lib"); - } - - #[test] - #[cfg(target_os = "dragonfly")] + #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] fn test_rpath_relative() { let config = &mut RPathConfig { used_crates: Vec::new(), diff --git a/src/librustc_back/target/dragonfly_base.rs b/src/librustc_back/target/dragonfly_base.rs index 4e982b2b76e..79d79b7e736 100644 --- a/src/librustc_back/target/dragonfly_base.rs +++ b/src/librustc_back/target/dragonfly_base.rs @@ -17,13 +17,18 @@ pub fn opts() -> TargetOptions { dynamic_linking: true, executables: true, morestack: true, + linker_is_gnu: true, has_rpath: true, pre_link_args: vec!( "-L/usr/local/lib".to_string(), - "-L/usr/local/lib/gcc47".to_string(), - "-L/usr/local/lib/gcc44".to_string(), + "-L/usr/lib/gcc47".to_string(), + // GNU-style linkers will use this to omit linking to libraries + // which don't actually fulfill any relocations, but only for + // libraries which follow this flag. Thus, use it before + // specifying libraries to link to. + "-Wl,--as-needed".to_string(), ), - + position_independent_executables: true, .. Default::default() } } diff --git a/src/librustc_back/target/x86_64_unknown_dragonfly.rs b/src/librustc_back/target/x86_64_unknown_dragonfly.rs index 79f09a3b00b..75dbff9428b 100644 --- a/src/librustc_back/target/x86_64_unknown_dragonfly.rs +++ b/src/librustc_back/target/x86_64_unknown_dragonfly.rs @@ -11,13 +11,18 @@ use target::Target; pub fn target() -> Target { + let mut base = super::dragonfly_base::opts(); + base.pre_link_args.push("-m64".to_string()); + Target { - data_layout: "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_string(), + data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\ + f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-\ + s0:64:64-f80:128:128-n8:16:32:64-S128".to_string(), llvm_target: "x86_64-unknown-dragonfly".to_string(), target_endian: "little".to_string(), - target_word_size: "32".to_string(), + target_word_size: "64".to_string(), arch: "x86_64".to_string(), target_os: "dragonfly".to_string(), - options: super::dragonfly_base::opts() + options: base, } } diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 0ed079df55b..4c1ec4cc858 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -172,7 +172,7 @@ pub fn join_paths(paths: &[T]) -> Result, &'static st Ok(joined) } -#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] +#[cfg(target_os = "freebsd")] pub fn load_self() -> Option> { unsafe { use libc::funcs::bsd44::*; @@ -198,6 +198,16 @@ pub fn load_self() -> Option> { } } +#[cfg(target_os = "dragonfly")] +fn load_self() -> Option> { + use std::io; + + match io::fs::readlink(&Path::new("/proc/curproc/file")) { + Ok(path) => Some(path.into_vec()), + Err(..) => None + } +} + #[cfg(any(target_os = "linux", target_os = "android"))] pub fn load_self() -> Option> { use std::io; From 4c3a8f17cc4bb4b68a910e028b50463d73429add Mon Sep 17 00:00:00 2001 From: Michael Neumann Date: Fri, 19 Dec 2014 22:19:37 +0100 Subject: [PATCH 2/2] load_self() needs to be public --- src/libstd/sys/unix/os.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 4c1ec4cc858..f1663df6a9b 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -199,7 +199,7 @@ pub fn load_self() -> Option> { } #[cfg(target_os = "dragonfly")] -fn load_self() -> Option> { +pub fn load_self() -> Option> { use std::io; match io::fs::readlink(&Path::new("/proc/curproc/file")) {