Skip to content

Commit 59854df

Browse files
authored
Solarish-ish: define _REENTRANT by default (#1496)
1 parent c319011 commit 59854df

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,24 @@ impl Build {
24832483
}
24842484
}
24852485

2486+
if target.os == "solaris" || target.os == "illumos" {
2487+
// On Solaris and illumos, multi-threaded C programs must be built with `_REENTRANT`
2488+
// defined. This configures headers to define APIs appropriately for multi-threaded
2489+
// use. This is documented in threads(7), see also https://illumos.org/man/7/threads.
2490+
//
2491+
// If C code is compiled without multi-threading support but does use multiple threads,
2492+
// incorrect behavior may result. One extreme example is that on some systems the
2493+
// global errno may be at the same address as the process' first thread's errno; errno
2494+
// clobbering may occur to disastrous effect. Conversely, if _REENTRANT is defined
2495+
// while it is not actually needed, system headers may define some APIs suboptimally
2496+
// but will not result in incorrect behavior. Other code *should* be reasonable under
2497+
// such conditions.
2498+
//
2499+
// We're typically building C code to eventually link into a Rust program. Many Rust
2500+
// programs are multi-threaded in some form. So, set the flag by default.
2501+
cmd.args.push("-D_REENTRANT".into());
2502+
}
2503+
24862504
if target.vendor == "apple" {
24872505
self.apple_flags(cmd)?;
24882506
}

0 commit comments

Comments
 (0)