Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 78d0184

Browse files
committedJan 31, 2016
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 9041b93 + bb6e646 commit 78d0184

File tree

36 files changed

+415
-37
lines changed

36 files changed

+415
-37
lines changed
 

‎configure

Lines changed: 13 additions & 0 deletions
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

Lines changed: 23 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 26 additions & 0 deletions
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+
}
Lines changed: 27 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 19 additions & 0 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ pub mod consts {
642642
/// - bitrig
643643
/// - netbsd
644644
/// - openbsd
645+
/// - solaris
645646
/// - android
646647
/// - windows
647648
#[stable(feature = "env", since = "1.0.0")]
@@ -802,6 +803,17 @@ mod os {
802803
pub const EXE_EXTENSION: &'static str = "";
803804
}
804805

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

‎src/libstd/num/f64.rs

Lines changed: 28 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 21 additions & 0 deletions
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+
}

‎src/libstd/os/solaris/raw.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 raw type definitions
12+
13+
#![stable(feature = "raw_ext", since = "1.1.0")]
14+
15+
use os::raw::c_long;
16+
use os::unix::raw::{uid_t, gid_t};
17+
18+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64;
19+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u32;
20+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64;
21+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type fflags_t = u32;
22+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = i64;
23+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32;
24+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32;
25+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64;
26+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
27+
28+
#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize;
29+
30+
#[repr(C)]
31+
#[derive(Clone)]
32+
#[stable(feature = "raw_ext", since = "1.1.0")]
33+
pub struct stat {
34+
#[stable(feature = "raw_ext", since = "1.1.0")]
35+
pub st_dev: dev_t,
36+
#[stable(feature = "raw_ext", since = "1.1.0")]
37+
pub st_ino: ino_t,
38+
#[stable(feature = "raw_ext", since = "1.1.0")]
39+
pub st_mode: mode_t,
40+
#[stable(feature = "raw_ext", since = "1.1.0")]
41+
pub st_nlink: nlink_t,
42+
#[stable(feature = "raw_ext", since = "1.1.0")]
43+
pub st_uid: uid_t,
44+
#[stable(feature = "raw_ext", since = "1.1.0")]
45+
pub st_gid: gid_t,
46+
#[stable(feature = "raw_ext", since = "1.1.0")]
47+
pub st_rdev: dev_t,
48+
#[stable(feature = "raw_ext", since = "1.1.0")]
49+
pub st_size: off_t,
50+
#[stable(feature = "raw_ext", since = "1.1.0")]
51+
pub st_atime: time_t,
52+
#[stable(feature = "raw_ext", since = "1.1.0")]
53+
pub st_atime_nsec: c_long,
54+
#[stable(feature = "raw_ext", since = "1.1.0")]
55+
pub st_mtime: time_t,
56+
#[stable(feature = "raw_ext", since = "1.1.0")]
57+
pub st_mtime_nsec: c_long,
58+
#[stable(feature = "raw_ext", since = "1.1.0")]
59+
pub st_ctime: time_t,
60+
#[stable(feature = "raw_ext", since = "1.1.0")]
61+
pub st_ctime_nsec: c_long,
62+
#[stable(feature = "raw_ext", since = "1.1.0")]
63+
pub st_blksize: blksize_t,
64+
#[stable(feature = "raw_ext", since = "1.1.0")]
65+
pub st_blocks: blkcnt_t,
66+
#[stable(feature = "raw_ext", since = "1.1.0")]
67+
pub __unused: [u8; 16]
68+
}

‎src/libstd/rtdeps.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ extern {}
3939
#[link(name = "pthread")]
4040
extern {}
4141

42+
#[cfg(target_os = "solaris")]
43+
#[link(name = "socket")]
44+
#[link(name = "posix4")]
45+
#[link(name = "pthread")]
46+
extern {}
47+
4248
// For PNaCl targets, nacl_io is a Pepper wrapper for some IO functions
4349
// missing (ie always error) in Newlib.
4450
#[cfg(all(target_os = "nacl", not(test)))]

‎src/libstd/sys/common/args.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub fn clone() -> Option<Vec<Vec<u8>>> { imp::clone() }
3838
target_os = "dragonfly",
3939
target_os = "bitrig",
4040
target_os = "netbsd",
41-
target_os = "openbsd"))]
41+
target_os = "openbsd",
42+
target_os = "solaris"))]
4243
mod imp {
4344
use prelude::v1::*;
4445

‎src/libstd/sys/common/libunwind.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub type _Unwind_Exception_Cleanup_Fn =
102102

103103
#[cfg_attr(any(all(target_os = "linux", not(target_env = "musl")),
104104
target_os = "freebsd",
105+
target_os = "solaris",
105106
all(target_os = "linux", target_env = "musl", not(target_arch = "x86_64"))),
106107
link(name = "gcc_s"))]
107108
#[cfg_attr(all(target_os = "linux", target_env = "musl", target_arch = "x86_64", not(test)),

‎src/libstd/sys/unix/fd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ impl FileDesc {
5050
Ok(ret as usize)
5151
}
5252

53-
#[cfg(not(target_env = "newlib"))]
53+
#[cfg(not(any(target_env = "newlib", target_os = "solaris")))]
5454
pub fn set_cloexec(&self) {
5555
unsafe {
5656
let ret = libc::ioctl(self.fd, libc::FIOCLEX);
5757
debug_assert_eq!(ret, 0);
5858
}
5959
}
60-
#[cfg(target_env = "newlib")]
60+
#[cfg(any(target_env = "newlib", target_os = "solaris"))]
6161
pub fn set_cloexec(&self) {
6262
unsafe {
6363
let previous = libc::fcntl(self.fd, libc::F_GETFD);

‎src/libstd/sys/unix/fs.rs

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use os::unix::prelude::*;
1414
use ffi::{CString, CStr, OsString, OsStr};
1515
use fmt;
1616
use io::{self, Error, ErrorKind, SeekFrom};
17-
use libc::{dirent, readdir_r};
18-
use libc::{self, c_int, off_t, mode_t};
17+
use libc::{self, dirent, c_int, off_t, mode_t};
1918
use mem;
2019
use path::{Path, PathBuf};
2120
use ptr;
@@ -25,6 +24,10 @@ use sys::platform::raw;
2524
use sys::{cvt, cvt_r};
2625
use sys_common::{AsInner, FromInner};
2726
use vec::Vec;
27+
#[cfg(target_os = "solaris")]
28+
use core_collections::borrow::ToOwned;
29+
#[cfg(target_os = "solaris")]
30+
use boxed::Box;
2831

2932
pub struct File(FileDesc);
3033

@@ -46,6 +49,12 @@ unsafe impl Sync for Dir {}
4649
pub struct DirEntry {
4750
entry: dirent,
4851
root: Arc<PathBuf>,
52+
// We need to store an owned copy of the directory name
53+
// on Solaris because a) it uses a zero-length array to
54+
// store the name, b) its lifetime between readdir calls
55+
// is not guaranteed.
56+
#[cfg(target_os = "solaris")]
57+
name: Box<[u8]>
4958
}
5059

5160
#[derive(Clone)]
@@ -132,6 +141,36 @@ impl FromInner<raw::mode_t> for FilePermissions {
132141
impl Iterator for ReadDir {
133142
type Item = io::Result<DirEntry>;
134143

144+
#[cfg(target_os = "solaris")]
145+
fn next(&mut self) -> Option<io::Result<DirEntry>> {
146+
unsafe {
147+
loop {
148+
// Although readdir_r(3) would be a correct function to use here because
149+
// of the thread safety, on Illumos the readdir(3C) function is safe to use
150+
// in threaded applications and it is generally preferred over the
151+
// readdir_r(3C) function.
152+
let entry_ptr = libc::readdir(self.dirp.0);
153+
if entry_ptr.is_null() {
154+
return None
155+
}
156+
157+
let name = (*entry_ptr).d_name.as_ptr();
158+
let namelen = libc::strlen(name) as usize;
159+
160+
let ret = DirEntry {
161+
entry: *entry_ptr,
162+
name: ::slice::from_raw_parts(name as *const u8,
163+
namelen as usize).to_owned().into_boxed_slice(),
164+
root: self.root.clone()
165+
};
166+
if ret.name_bytes() != b"." && ret.name_bytes() != b".." {
167+
return Some(Ok(ret))
168+
}
169+
}
170+
}
171+
}
172+
173+
#[cfg(not(target_os = "solaris"))]
135174
fn next(&mut self) -> Option<io::Result<DirEntry>> {
136175
unsafe {
137176
let mut ret = DirEntry {
@@ -140,7 +179,7 @@ impl Iterator for ReadDir {
140179
};
141180
let mut entry_ptr = ptr::null_mut();
142181
loop {
143-
if readdir_r(self.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 {
182+
if libc::readdir_r(self.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 {
144183
return Some(Err(Error::last_os_error()))
145184
}
146185
if entry_ptr.is_null() {
@@ -174,6 +213,12 @@ impl DirEntry {
174213
lstat(&self.path())
175214
}
176215

216+
#[cfg(target_os = "solaris")]
217+
pub fn file_type(&self) -> io::Result<FileType> {
218+
stat(&self.path()).map(|m| m.file_type())
219+
}
220+
221+
#[cfg(not(target_os = "solaris"))]
177222
pub fn file_type(&self) -> io::Result<FileType> {
178223
match self.entry.d_type {
179224
libc::DT_CHR => Ok(FileType { mode: libc::S_IFCHR }),
@@ -189,7 +234,8 @@ impl DirEntry {
189234

190235
#[cfg(any(target_os = "macos",
191236
target_os = "ios",
192-
target_os = "linux"))]
237+
target_os = "linux",
238+
target_os = "solaris"))]
193239
pub fn ino(&self) -> raw::ino_t {
194240
self.entry.d_ino
195241
}
@@ -234,6 +280,10 @@ impl DirEntry {
234280
CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes()
235281
}
236282
}
283+
#[cfg(target_os = "solaris")]
284+
fn name_bytes(&self) -> &[u8] {
285+
&*self.name
286+
}
237287
}
238288

239289
impl OpenOptions {

‎src/libstd/sys/unix/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use ops::Neg;
2525
#[cfg(target_os = "nacl")] pub use os::nacl as platform;
2626
#[cfg(target_os = "netbsd")] pub use os::netbsd as platform;
2727
#[cfg(target_os = "openbsd")] pub use os::openbsd as platform;
28+
#[cfg(target_os = "solaris")] pub use os::solaris as platform;
2829

2930
pub mod backtrace;
3031
pub mod condvar;

‎src/libstd/sys/unix/os.rs

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub fn errno() -> i32 {
4545
target_os = "android",
4646
target_env = "newlib"),
4747
link_name = "__errno")]
48+
#[cfg_attr(target_os = "solaris", link_name = "___errno")]
4849
#[cfg_attr(target_os = "dragonfly", link_name = "__dfly_error")]
4950
#[cfg_attr(any(target_os = "macos",
5051
target_os = "ios",
@@ -257,6 +258,30 @@ pub fn current_exe() -> io::Result<PathBuf> {
257258
}
258259
}
259260

261+
#[cfg(any(target_os = "solaris"))]
262+
pub fn current_exe() -> io::Result<PathBuf> {
263+
extern {
264+
fn getexecname() -> *const c_char;
265+
}
266+
unsafe {
267+
let path = getexecname();
268+
if path.is_null() {
269+
Err(io::Error::last_os_error())
270+
} else {
271+
let filename = CStr::from_ptr(path).to_bytes();
272+
let path = PathBuf::from(<OsStr as OsStrExt>::from_bytes(filename));
273+
274+
// Prepend a current working directory to the path if
275+
// it doesn't contain an absolute pathname.
276+
if filename[0] == b'/' {
277+
Ok(path)
278+
} else {
279+
getcwd().map(|cwd| cwd.join(path))
280+
}
281+
}
282+
}
283+
}
284+
260285
pub struct Args {
261286
iter: vec::IntoIter<OsString>,
262287
_dont_send_or_sync_me: *mut (),
@@ -359,6 +384,7 @@ pub fn args() -> Args {
359384
target_os = "bitrig",
360385
target_os = "netbsd",
361386
target_os = "openbsd",
387+
target_os = "solaris",
362388
target_os = "nacl"))]
363389
pub fn args() -> Args {
364390
use sys_common;
@@ -481,6 +507,28 @@ pub fn home_dir() -> Option<PathBuf> {
481507
fallback()
482508
}).map(PathBuf::from);
483509

510+
#[cfg(not(target_os = "solaris"))]
511+
unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd,
512+
buf: &mut Vec<c_char>) -> Option<()> {
513+
let mut result = ptr::null_mut();
514+
match libc::getpwuid_r(me, passwd, buf.as_mut_ptr(),
515+
buf.capacity() as libc::size_t,
516+
&mut result) {
517+
0 if !result.is_null() => Some(()),
518+
_ => None
519+
}
520+
}
521+
522+
#[cfg(target_os = "solaris")]
523+
unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd,
524+
buf: &mut Vec<c_char>) -> Option<()> {
525+
// getpwuid_r semantics is different on Illumos/Solaris:
526+
// http://illumos.org/man/3c/getpwuid_r
527+
let result = libc::getpwuid_r(me, passwd, buf.as_mut_ptr(),
528+
buf.capacity() as libc::size_t);
529+
if result.is_null() { None } else { Some(()) }
530+
}
531+
484532
#[cfg(any(target_os = "android",
485533
target_os = "ios",
486534
target_os = "nacl"))]
@@ -497,16 +545,14 @@ pub fn home_dir() -> Option<PathBuf> {
497545
loop {
498546
let mut buf = Vec::with_capacity(amt);
499547
let mut passwd: libc::passwd = mem::zeroed();
500-
let mut result = ptr::null_mut();
501-
match libc::getpwuid_r(me, &mut passwd, buf.as_mut_ptr(),
502-
buf.capacity() as libc::size_t,
503-
&mut result) {
504-
0 if !result.is_null() => {}
505-
_ => return None
548+
549+
if getpwduid_r(me, &mut passwd, &mut buf).is_some() {
550+
let ptr = passwd.pw_dir as *const _;
551+
let bytes = CStr::from_ptr(ptr).to_bytes().to_vec();
552+
return Some(OsStringExt::from_vec(bytes))
553+
} else {
554+
return None;
506555
}
507-
let ptr = passwd.pw_dir as *const _;
508-
let bytes = CStr::from_ptr(ptr).to_bytes().to_vec();
509-
return Some(OsStringExt::from_vec(bytes))
510556
}
511557
}
512558
}

‎src/libstd/sys/unix/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn os2c(s: &OsStr) -> CString {
9393
pub struct ExitStatus(c_int);
9494

9595
#[cfg(any(target_os = "linux", target_os = "android",
96-
target_os = "nacl"))]
96+
target_os = "nacl", target_os = "solaris"))]
9797
mod status_imp {
9898
pub fn WIFEXITED(status: i32) -> bool { (status & 0xff) == 0 }
9999
pub fn WEXITSTATUS(status: i32) -> i32 { (status >> 8) & 0xff }

‎src/libstd/sys/unix/stack_overflow.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl Drop for Handler {
3939
target_os = "bitrig",
4040
target_os = "dragonfly",
4141
target_os = "freebsd",
42+
target_os = "solaris",
4243
all(target_os = "netbsd", not(target_vendor = "rumprun")),
4344
target_os = "openbsd"))]
4445
mod imp {
@@ -167,6 +168,7 @@ mod imp {
167168
target_os = "bitrig",
168169
target_os = "dragonfly",
169170
target_os = "freebsd",
171+
target_os = "solaris",
170172
all(target_os = "netbsd", not(target_vendor = "rumprun")),
171173
target_os = "openbsd")))]
172174
mod imp {

‎src/libstd/sys/unix/thread.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use prelude::v1::*;
1212

1313
use alloc::boxed::FnBox;
1414
use cmp;
15-
#[cfg(not(target_env = "newlib"))]
15+
#[cfg(not(any(target_env = "newlib", target_os = "solaris")))]
1616
use ffi::CString;
1717
use io;
1818
use libc;
@@ -122,9 +122,9 @@ impl Thread {
122122
carg.as_ptr() as *mut libc::c_void);
123123
}
124124
}
125-
#[cfg(target_env = "newlib")]
126-
pub unsafe fn set_name(_name: &str) {
127-
// Newlib has no way to set a thread name.
125+
#[cfg(any(target_env = "newlib", target_os = "solaris"))]
126+
pub fn set_name(_name: &str) {
127+
// Newlib and Illumos has no way to set a thread name.
128128
}
129129

130130
pub fn sleep(dur: Duration) {
@@ -170,7 +170,8 @@ impl Drop for Thread {
170170
not(target_os = "macos"),
171171
not(target_os = "bitrig"),
172172
not(all(target_os = "netbsd", not(target_vendor = "rumprun"))),
173-
not(target_os = "openbsd")))]
173+
not(target_os = "openbsd"),
174+
not(target_os = "solaris")))]
174175
#[cfg_attr(test, allow(dead_code))]
175176
pub mod guard {
176177
pub unsafe fn current() -> Option<usize> { None }
@@ -182,7 +183,8 @@ pub mod guard {
182183
target_os = "macos",
183184
target_os = "bitrig",
184185
all(target_os = "netbsd", not(target_vendor = "rumprun")),
185-
target_os = "openbsd"))]
186+
target_os = "openbsd",
187+
target_os = "solaris"))]
186188
#[cfg_attr(test, allow(dead_code))]
187189
pub mod guard {
188190
use prelude::v1::*;
@@ -194,7 +196,8 @@ pub mod guard {
194196

195197
#[cfg(any(target_os = "macos",
196198
target_os = "bitrig",
197-
target_os = "openbsd"))]
199+
target_os = "openbsd",
200+
target_os = "solaris"))]
198201
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
199202
current().map(|s| s as *mut libc::c_void)
200203
}
@@ -253,6 +256,13 @@ pub mod guard {
253256
Some(stackaddr as usize + offset * psize)
254257
}
255258

259+
#[cfg(target_os = "solaris")]
260+
pub unsafe fn current() -> Option<usize> {
261+
let mut current_stack: libc::stack_t = ::mem::zeroed();
262+
assert_eq!(libc::stack_getbounds(&mut current_stack), 0);
263+
Some(current_stack.ss_sp as usize)
264+
}
265+
256266
#[cfg(target_os = "macos")]
257267
pub unsafe fn current() -> Option<usize> {
258268
Some((libc::pthread_get_stackaddr_np(libc::pthread_self()) as libc::size_t -

‎src/libsyntax/abi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub enum Os {
2828
OsNetbsd,
2929
OsOpenbsd,
3030
OsNaCl,
31+
OsSolaris,
3132
}
3233

3334
#[derive(PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Clone, Copy, Debug)]
@@ -147,6 +148,7 @@ impl fmt::Display for Os {
147148
OsNetbsd => "netbsd".fmt(f),
148149
OsOpenbsd => "openbsd".fmt(f),
149150
OsNaCl => "nacl".fmt(f),
151+
OsSolaris => "solaris".fmt(f),
150152
}
151153
}
152154
}

‎src/libtest/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,8 @@ fn get_concurrency() -> usize {
927927
#[cfg(any(target_os = "linux",
928928
target_os = "macos",
929929
target_os = "ios",
930-
target_os = "android"))]
930+
target_os = "android",
931+
target_os = "solaris"))]
931932
fn num_cpus() -> usize {
932933
unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as usize }
933934
}

‎src/test/debuginfo/gdb-pretty-struct-and-enums-pre-gdb-7-7.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
// ignore-bitrig
12+
// ignore-solaris
1213
// ignore-windows failing on win32 bot
1314
// ignore-freebsd: gdb package too new
1415
// ignore-tidy-linelength

‎src/test/run-make/issue-22131/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ all: foo.rs
44
$(RUSTC) --cfg 'feature="bar"' --crate-type lib foo.rs
55
$(HOST_RPATH_ENV) $(RUSTDOC) --test --cfg 'feature="bar"' \
66
-L $(TMPDIR) foo.rs |\
7-
grep --quiet 'test foo_0 ... ok'
7+
grep -q 'test foo_0 ... ok'

‎src/test/run-make/target-specs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
all:
33
$(RUSTC) foo.rs --target=my-awesome-platform.json --crate-type=lib --emit=asm
44
grep -q -v morestack < $(TMPDIR)/foo.s
5-
$(RUSTC) foo.rs --target=my-invalid-platform.json 2>&1 | grep --quiet "Error loading target specification"
5+
$(RUSTC) foo.rs --target=my-invalid-platform.json 2>&1 | grep -q "Error loading target specification"
66
$(RUSTC) foo.rs --target=my-incomplete-platform.json 2>&1 | grep 'Field llvm-target'
77
RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=my-awesome-platform --crate-type=lib --emit=asm
88
RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=x86_64-unknown-linux-gnu --crate-type=lib --emit=asm

‎src/test/run-make/tools.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ ifeq ($(UNAME),Bitrig)
8383
EXTRACFLAGS := -lm -lpthread
8484
EXTRACXXFLAGS := -lc++ -lc++abi
8585
else
86+
ifeq ($(UNAME),SunOS)
87+
EXTRACFLAGS := -lm -lpthread -lposix4 -lsocket
88+
else
8689
ifeq ($(UNAME),OpenBSD)
8790
EXTRACFLAGS := -lm -lpthread
8891
RUSTC := $(RUSTC) -C linker="$(word 1,$(CC:ccache=))"
@@ -94,6 +97,7 @@ endif
9497
endif
9598
endif
9699
endif
100+
endif
97101

98102
REMOVE_DYLIBS = rm $(TMPDIR)/$(call DYLIB_GLOB,$(1))
99103
REMOVE_RLIBS = rm $(TMPDIR)/$(call RLIB_GLOB,$(1))

‎src/test/run-make/use-extern-for-plugins/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-include ../tools.mk
22

3-
SKIP_OS := 'FreeBSD OpenBSD Bitrig'
3+
SKIP_OS := 'FreeBSD OpenBSD Bitrig SunOS'
44

55
ifneq ($(UNAME),$(findstring $(UNAME),$(SKIP_OS)))
66

‎src/test/run-pass/intrinsic-alignment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ mod rusti {
2323
target_os = "freebsd",
2424
target_os = "dragonfly",
2525
target_os = "netbsd",
26-
target_os = "openbsd"))]
26+
target_os = "openbsd",
27+
target_os = "solaris"))]
2728
mod m {
2829
#[main]
2930
#[cfg(target_arch = "x86")]

‎src/test/run-pass/rec-align-u64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ struct Outer {
4141
target_os = "freebsd",
4242
target_os = "dragonfly",
4343
target_os = "netbsd",
44-
target_os = "openbsd"))]
44+
target_os = "openbsd",
45+
target_os = "solaris"))]
4546
mod m {
4647
#[cfg(target_arch = "x86")]
4748
pub mod m {

‎src/test/run-pass/x86stdcall.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ pub fn main() {
3737
target_os = "bitrig",
3838
target_os = "netbsd",
3939
target_os = "openbsd",
40-
target_os = "android"))]
40+
target_os = "android",
41+
target_os = "solaris"))]
4142
pub fn main() { }

0 commit comments

Comments
 (0)
Please sign in to comment.