Skip to content

Commit ebab240

Browse files
committed
Apply several fixes for Illumos support
1 parent f189d7a commit ebab240

File tree

5 files changed

+79
-44
lines changed

5 files changed

+79
-44
lines changed

configure

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/sh
22

3-
# /bin/sh on Solaris is not a POSIX compatible shell, but /usr/bin/ksh is.
3+
# /bin/sh on Solaris is not a POSIX compatible shell, but /usr/bin/bash is.
44
if [ `uname -s` = 'SunOS' -a "${POSIX_SHELL}" != "true" ]; then
55
POSIX_SHELL="true"
66
export POSIX_SHELL
7-
exec /usr/bin/bash $0 "$@"
7+
exec /usr/bin/env bash $0 "$@"
88
fi
9-
unset POSIX_SHELL # clear it so if we invoke other scripts, they run as ksh as well
9+
unset POSIX_SHELL # clear it so if we invoke other scripts, they run as bash as well
1010

1111
msg() {
1212
echo "configure: $*"

src/librustc_back/target/x86_64_sun_solaris.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use target::Target;
1313
pub fn target() -> Target {
1414
let mut base = super::sunos_base::opts();
1515
base.pre_link_args.push("-m64".to_string());
16-
base.pre_link_args.push("-lsocket".to_string());
17-
base.pre_link_args.push("-lposix4".to_string());
1816

1917
Target {
2018
llvm_target: "x86_64-pc-solaris2.11".to_string(),

src/libstd/num/f64.rs

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -84,38 +84,6 @@ mod cmath {
8484
}
8585
}
8686

87-
#[cfg(not(target_os = "sunos"))]
88-
macro_rules! log_wrapper {
89-
($num:ident, $f:ident) => (
90-
unsafe { intrinsics::$f($num) }
91-
)
92-
}
93-
94-
// Illumos requires a wrapper around log, log2, and log10 functions
95-
// because of non-standard behavior (e.g. log(-n) returns -Inf instead
96-
// of expected NaN).
97-
#[cfg(target_os = "sunos")]
98-
macro_rules! log_wrapper {
99-
($num:ident, $f:ident) => (
100-
if $num.is_finite() {
101-
if $num > 0.0 {
102-
return unsafe { intrinsics::$f($num) }
103-
}
104-
return if $num == 0.0 {
105-
NEG_INFINITY // log(0) = -Inf
106-
} else {
107-
NAN // log(-ve) = NaN
108-
}
109-
} else if $num.is_nan() {
110-
$num // log(NaN) = NaN
111-
} else if $num > 0.0 {
112-
$num // log(Inf) = Inf
113-
} else {
114-
return NAN // log(-Inf) = NaN
115-
}
116-
)
117-
}
118-
11987
#[cfg(not(test))]
12088
#[lang = "f64"]
12189
impl f64 {
@@ -543,7 +511,28 @@ impl f64 {
543511
#[stable(feature = "rust1", since = "1.0.0")]
544512
#[inline]
545513
pub fn ln(self) -> f64 {
546-
log_wrapper!(self, logf64)
514+
if !cfg!(target_os = "sunos") {
515+
unsafe { intrinsics::logf64(self) }
516+
} else {
517+
// Illumos requires a wrapper around log, log2, and log10 functions
518+
// because of their non-standard behavior (e.g. log(-n) returns -Inf instead
519+
// of expected NaN).
520+
if self.is_finite() {
521+
if self > 0.0 {
522+
unsafe { intrinsics::logf64(self) }
523+
} else if self == 0.0 {
524+
NEG_INFINITY // log(0) = -Inf
525+
} else {
526+
NAN // log(-n) = NaN
527+
}
528+
} else if self.is_nan() {
529+
self // log(NaN) = NaN
530+
} else if self > 0.0 {
531+
self // log(Inf) = Inf
532+
} else {
533+
NAN // log(-Inf) = NaN
534+
}
535+
}
547536
}
548537

549538
/// Returns the logarithm of the number with respect to an arbitrary base.
@@ -578,7 +567,27 @@ impl f64 {
578567
#[stable(feature = "rust1", since = "1.0.0")]
579568
#[inline]
580569
pub fn log2(self) -> f64 {
581-
log_wrapper!(self, log2f64)
570+
if !cfg!(target_os = "sunos") {
571+
unsafe { intrinsics::log2f64(self) }
572+
} else {
573+
// Illumos requires a wrapper around the log2 function because of
574+
// its non-standard behavior
575+
if self.is_finite() {
576+
if self > 0.0 {
577+
unsafe { intrinsics::log2f64(self) }
578+
} else if self == 0.0 {
579+
NEG_INFINITY // log2(0) = -Inf
580+
} else {
581+
NAN // log2(-n) = NaN
582+
}
583+
} else if self.is_nan() {
584+
self // log2(NaN) = NaN
585+
} else if self > 0.0 {
586+
self // log2(Inf) = Inf
587+
} else {
588+
NAN // log2(-Inf) = NaN
589+
}
590+
}
582591
}
583592

584593
/// Returns the base 10 logarithm of the number.
@@ -594,7 +603,27 @@ impl f64 {
594603
#[stable(feature = "rust1", since = "1.0.0")]
595604
#[inline]
596605
pub fn log10(self) -> f64 {
597-
log_wrapper!(self, log10f64)
606+
if !cfg!(target_os = "sunos") {
607+
unsafe { intrinsics::log10f64(self) }
608+
} else {
609+
// Illumos requires a wrapper around the log10 function because of
610+
// its non-standard behavior.
611+
if self.is_finite() {
612+
if self > 0.0 {
613+
unsafe { intrinsics::log10f64(self) }
614+
} else if self == 0.0 {
615+
NEG_INFINITY // log10(0) = -Inf
616+
} else {
617+
NAN // log10(-n) = NaN
618+
}
619+
} else if self.is_nan() {
620+
self // log10(NaN) = NaN
621+
} else if self > 0.0 {
622+
self // log10(Inf) = Inf
623+
} else {
624+
NAN // log10(-Inf) = NaN
625+
}
626+
}
598627
}
599628

600629
/// Converts radians to degrees.

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 = "sunos")]
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/unix/os.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,14 @@ pub fn current_exe() -> io::Result<PathBuf> {
269269
Err(io::Error::last_os_error())
270270
} else {
271271
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.
272276
if filename[0] == b'/' {
273-
Ok(PathBuf::from(<OsStr as OsStrExt>::from_bytes(filename)))
277+
Ok(path)
274278
} else {
275-
// Prepend current working directory to the path if
276-
// it doesn't contain an absolute pathname.
277-
return getcwd().map(|cwd| cwd.join(<OsStr as OsStrExt>::from_bytes(filename)))
279+
getcwd().map(|cwd| cwd.join(path))
278280
}
279281
}
280282
}

0 commit comments

Comments
 (0)