Skip to content

Commit e3bcddb

Browse files
committed
Auto merge of #31078 - nbaksalyar:illumos, r=alexcrichton
This pull request adds support for [Illumos](http://illumos.org/)-based operating systems: SmartOS, OpenIndiana, and others. For now it's x86-64 only, as I'm not sure if 32-bit installations are widespread. This PR is based on #28589 by @potatosalad, and also closes #21000, #25845, and #25846. Required changes in libc are already merged: rust-lang/libc#138 Here's a snapshot required to build a stage0 compiler: https://s3-eu-west-1.amazonaws.com/nbaksalyar/rustc-sunos-snapshot.tar.gz It passes all checks from `make check`. There are some changes I'm not quite sure about, e.g. macro usage in `src/libstd/num/f64.rs` and `DirEntry` structure in `src/libstd/sys/unix/fs.rs`, so any comments on how to rewrite it better would be greatly appreciated. Also, LLVM configure script might need to be patched to build it successfully, or a pre-built libLLVM should be used. Some details can be found here: https://llvm.org/bugs/show_bug.cgi?id=25409 Thanks! r? @brson
2 parents 18c1781 + fae883c commit e3bcddb

36 files changed

+412
-38
lines changed

configure

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#!/bin/sh
22

3+
# /bin/sh on Solaris is not a POSIX compatible shell, but /usr/bin/bash is.
4+
if [ `uname -s` = 'SunOS' -a "${POSIX_SHELL}" != "true" ]; then
5+
POSIX_SHELL="true"
6+
export POSIX_SHELL
7+
exec /usr/bin/env bash $0 "$@"
8+
fi
9+
unset POSIX_SHELL # clear it so if we invoke other scripts, they run as bash as well
10+
311
msg() {
412
echo "configure: $*"
513
}
@@ -416,6 +424,11 @@ case $CFG_OSTYPE in
416424
CFG_OSTYPE=apple-darwin
417425
;;
418426

427+
SunOS)
428+
CFG_OSTYPE=sun-solaris
429+
CFG_CPUTYPE=$(isainfo -n)
430+
;;
431+
419432
MINGW*)
420433
# msys' `uname` does not print gcc configuration, but prints msys
421434
# configuration. so we cannot believe `uname -m`:

mk/cfg/x86_64-sun-solaris.mk

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# x86_64-sun-solaris configuration
2+
CROSS_PREFIX_x86_64-sun-solaris=x86_64-sun-solaris2.11-
3+
CC_x86_64-sun-solaris=$(CC)
4+
CXX_x86_64-sun-solaris=$(CXX)
5+
CPP_x86_64-sun-solaris=$(CPP)
6+
AR_x86_64-sun-solaris=$(AR)
7+
CFG_LIB_NAME_x86_64-sun-solaris=lib$(1).so
8+
CFG_STATIC_LIB_NAME_x86_64-sun-solaris=lib$(1).a
9+
CFG_LIB_GLOB_x86_64-sun-solaris=lib$(1)-*.so
10+
CFG_LIB_DSYM_GLOB_x86_64-sun-solaris=$(1)-*.dylib.dSYM
11+
CFG_JEMALLOC_CFLAGS_x86_64-sun-solaris := -I/usr/local/include $(CFLAGS)
12+
CFG_GCCISH_CFLAGS_x86_64-sun-solaris := -Wall -Werror -g -D_POSIX_PTHREAD_SEMANTICS -fPIC -I/usr/local/include $(CFLAGS)
13+
CFG_GCCISH_LINK_FLAGS_x86_64-sun-solaris := -shared -fPIC -g -pthread -lrt
14+
CFG_GCCISH_DEF_FLAG_x86_64-sun-solaris := -Wl,--export-dynamic,--dynamic-list=
15+
CFG_LLC_FLAGS_x86_64-sun-solaris :=
16+
CFG_INSTALL_NAME_x86_64-sun-solaris =
17+
CFG_EXE_SUFFIX_x86_64-sun-solaris :=
18+
CFG_WINDOWSY_x86_64-sun-solaris :=
19+
CFG_UNIXY_x86_64-sun-solaris := 1
20+
CFG_LDPATH_x86_64-sun-solaris :=
21+
CFG_RUN_x86_64-sun-solaris=$(2)
22+
CFG_RUN_TARG_x86_64-sun-solaris=$(call CFG_RUN_x86_64-sun-solaris,,$(2))
23+
CFG_GNU_TRIPLE_x86_64-sun-solaris := x86_64-sun-solaris

src/compiletest/util.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const OS_TABLE: &'static [(&'static str, &'static str)] = &[
2525
("openbsd", "openbsd"),
2626
("win32", "windows"),
2727
("windows", "windows"),
28+
("solaris", "solaris"),
2829
];
2930

3031
const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[

src/etc/local_stage0.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LIB_PREFIX=lib
1818

1919
OS=`uname -s`
2020
case $OS in
21-
("Linux"|"FreeBSD"|"DragonFly"|"Bitrig"|"OpenBSD")
21+
("Linux"|"FreeBSD"|"DragonFly"|"Bitrig"|"OpenBSD"|"SunOS")
2222
BIN_SUF=
2323
LIB_SUF=.so
2424
;;

src/etc/snapshot.py

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def scrub(b):
4848
"macos": ["bin/rustc"],
4949
"netbsd": ["bin/rustc"],
5050
"openbsd": ["bin/rustc"],
51+
"solaris": ["bin/rustc"],
5152
"winnt": ["bin/rustc.exe"],
5253
}
5354

src/librustc_back/target/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ mod freebsd_base;
5959
mod linux_base;
6060
mod openbsd_base;
6161
mod netbsd_base;
62+
mod solaris_base;
6263
mod windows_base;
6364
mod windows_msvc_base;
6465

@@ -155,6 +156,10 @@ pub struct TargetOptions {
155156
/// Whether the target toolchain is like OSX's. Only useful for compiling against iOS/OS X, in
156157
/// particular running dsymutil and some other stuff like `-dead_strip`. Defaults to false.
157158
pub is_like_osx: bool,
159+
/// Whether the target toolchain is like Solaris's.
160+
/// Only useful for compiling against Illumos/Solaris,
161+
/// as they have a different set of linker flags. Defaults to false.
162+
pub is_like_solaris: bool,
158163
/// Whether the target toolchain is like Windows'. Only useful for compiling against Windows,
159164
/// only really used for figuring out how to find libraries, since Windows uses its own
160165
/// library naming convention. Defaults to false.
@@ -227,6 +232,7 @@ impl Default for TargetOptions {
227232
staticlib_suffix: ".a".to_string(),
228233
target_family: None,
229234
is_like_osx: false,
235+
is_like_solaris: false,
230236
is_like_windows: false,
231237
is_like_android: false,
232238
is_like_msvc: false,
@@ -447,6 +453,8 @@ impl Target {
447453
armv7_apple_ios,
448454
armv7s_apple_ios,
449455

456+
x86_64_sun_solaris,
457+
450458
x86_64_pc_windows_gnu,
451459
i686_pc_windows_gnu,
452460

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::TargetOptions;
12+
use std::default::Default;
13+
14+
pub fn opts() -> TargetOptions {
15+
TargetOptions {
16+
linker: "cc".to_string(),
17+
dynamic_linking: true,
18+
executables: true,
19+
has_rpath: true,
20+
is_like_solaris: true,
21+
archive_format: "gnu".to_string(),
22+
exe_allocation_crate: super::maybe_jemalloc(),
23+
24+
.. Default::default()
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::Target;
12+
13+
pub fn target() -> Target {
14+
let mut base = super::solaris_base::opts();
15+
base.pre_link_args.push("-m64".to_string());
16+
17+
Target {
18+
llvm_target: "x86_64-pc-solaris".to_string(),
19+
target_endian: "little".to_string(),
20+
target_pointer_width: "64".to_string(),
21+
arch: "x86_64".to_string(),
22+
target_os: "solaris".to_string(),
23+
target_env: "".to_string(),
24+
target_vendor: "sun".to_string(),
25+
options: base,
26+
}
27+
}

src/librustc_trans/back/linker.rs

+3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ impl<'a> Linker for GnuLinker<'a> {
131131
// insert it here.
132132
if self.sess.target.target.options.is_like_osx {
133133
self.cmd.arg("-Wl,-dead_strip");
134+
} else if self.sess.target.target.options.is_like_solaris {
135+
self.cmd.arg("-Wl,-z");
136+
self.cmd.arg("-Wl,ignore");
134137

135138
// If we're building a dylib, we don't use --gc-sections because LLVM
136139
// has already done the best it can do, and we also don't want to

src/librustdoc/flock.rs

+19
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ mod imp {
111111
pub const F_SETLKW: libc::c_int = 9;
112112
}
113113

114+
#[cfg(target_os = "solaris")]
115+
mod os {
116+
use libc;
117+
118+
pub struct flock {
119+
pub l_type: libc::c_short,
120+
pub l_whence: libc::c_short,
121+
pub l_start: libc::off_t,
122+
pub l_len: libc::off_t,
123+
pub l_sysid: libc::c_int,
124+
pub l_pid: libc::pid_t,
125+
}
126+
127+
pub const F_WRLCK: libc::c_short = 2;
128+
pub const F_UNLCK: libc::c_short = 3;
129+
pub const F_SETLK: libc::c_int = 6;
130+
pub const F_SETLKW: libc::c_int = 7;
131+
}
132+
114133
pub struct Lock {
115134
fd: libc::c_int,
116135
}

src/libstd/dynamic_lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ mod tests {
172172
target_os = "dragonfly",
173173
target_os = "bitrig",
174174
target_os = "netbsd",
175-
target_os = "openbsd"))]
175+
target_os = "openbsd",
176+
target_os = "solaris"))]
176177
#[allow(deprecated)]
177178
fn test_errors_do_not_crash() {
178179
use path::Path;
@@ -195,7 +196,8 @@ mod tests {
195196
target_os = "dragonfly",
196197
target_os = "bitrig",
197198
target_os = "netbsd",
198-
target_os = "openbsd"))]
199+
target_os = "openbsd",
200+
target_os = "solaris"))]
199201
mod dl {
200202
use prelude::v1::*;
201203

src/libstd/env.rs

+12
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ pub mod consts {
640640
/// - bitrig
641641
/// - netbsd
642642
/// - openbsd
643+
/// - solaris
643644
/// - android
644645
/// - windows
645646
#[stable(feature = "env", since = "1.0.0")]
@@ -800,6 +801,17 @@ mod os {
800801
pub const EXE_EXTENSION: &'static str = "";
801802
}
802803

804+
#[cfg(target_os = "solaris")]
805+
mod os {
806+
pub const FAMILY: &'static str = "unix";
807+
pub const OS: &'static str = "solaris";
808+
pub const DLL_PREFIX: &'static str = "lib";
809+
pub const DLL_SUFFIX: &'static str = ".so";
810+
pub const DLL_EXTENSION: &'static str = "so";
811+
pub const EXE_SUFFIX: &'static str = "";
812+
pub const EXE_EXTENSION: &'static str = "";
813+
}
814+
803815
#[cfg(target_os = "windows")]
804816
mod os {
805817
pub const FAMILY: &'static str = "windows";

src/libstd/num/f64.rs

+28-3
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ impl f64 {
511511
#[stable(feature = "rust1", since = "1.0.0")]
512512
#[inline]
513513
pub fn ln(self) -> f64 {
514-
unsafe { intrinsics::logf64(self) }
514+
self.log_wrapper(|n| { unsafe { intrinsics::logf64(n) } })
515515
}
516516

517517
/// Returns the logarithm of the number with respect to an arbitrary base.
@@ -546,7 +546,7 @@ impl f64 {
546546
#[stable(feature = "rust1", since = "1.0.0")]
547547
#[inline]
548548
pub fn log2(self) -> f64 {
549-
unsafe { intrinsics::log2f64(self) }
549+
self.log_wrapper(|n| { unsafe { intrinsics::log2f64(n) } })
550550
}
551551

552552
/// Returns the base 10 logarithm of the number.
@@ -562,7 +562,7 @@ impl f64 {
562562
#[stable(feature = "rust1", since = "1.0.0")]
563563
#[inline]
564564
pub fn log10(self) -> f64 {
565-
unsafe { intrinsics::log10f64(self) }
565+
self.log_wrapper(|n| { unsafe { intrinsics::log10f64(n) } })
566566
}
567567

568568
/// Converts radians to degrees.
@@ -1065,6 +1065,31 @@ impl f64 {
10651065
pub fn atanh(self) -> f64 {
10661066
0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
10671067
}
1068+
1069+
// Solaris/Illumos requires a wrapper around log, log2, and log10 functions
1070+
// because of their non-standard behavior (e.g. log(-n) returns -Inf instead
1071+
// of expected NaN).
1072+
fn log_wrapper<F: Fn(f64) -> f64>(self, log_fn: F) -> f64 {
1073+
if !cfg!(target_os = "solaris") {
1074+
log_fn(self)
1075+
} else {
1076+
if self.is_finite() {
1077+
if self > 0.0 {
1078+
log_fn(self)
1079+
} else if self == 0.0 {
1080+
NEG_INFINITY // log(0) = -Inf
1081+
} else {
1082+
NAN // log(-n) = NaN
1083+
}
1084+
} else if self.is_nan() {
1085+
self // log(NaN) = NaN
1086+
} else if self > 0.0 {
1087+
self // log(Inf) = Inf
1088+
} else {
1089+
NAN // log(-Inf) = NaN
1090+
}
1091+
}
1092+
}
10681093
}
10691094

10701095
#[cfg(test)]

src/libstd/os/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ pub use sys::ext as windows;
3030
#[cfg(target_os = "nacl")] pub mod nacl;
3131
#[cfg(target_os = "netbsd")] pub mod netbsd;
3232
#[cfg(target_os = "openbsd")] pub mod openbsd;
33+
#[cfg(target_os = "solaris")] pub mod solaris;
3334

3435
pub mod raw;

src/libstd/os/solaris/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Solaris-specific definitions
12+
13+
#![stable(feature = "raw_ext", since = "1.1.0")]
14+
15+
pub mod raw;
16+
17+
#[stable(feature = "raw_ext", since = "1.1.0")]
18+
pub mod fs {
19+
#[stable(feature = "raw_ext", since = "1.1.0")]
20+
pub use sys::fs::MetadataExt;
21+
}

0 commit comments

Comments
 (0)