[MacPorts] #69138: rust @1.75.0 : Does not build on macOS 10.11.6 - missing _getentropy and _clock_gettime
MacPorts
noreply at macports.org
Mon May 27 15:43:43 UTC 2024
#69138: rust @1.75.0 : Does not build on macOS 10.11.6 - missing _getentropy and
_clock_gettime
------------------------+---------------------------------
Reporter: snowflake | Owner: MarcusCalhoun-Lopez
Type: defect | Status: closed
Priority: Normal | Milestone:
Component: ports | Version: 2.8.99
Resolution: fixed | Keywords:
Port: rust |
------------------------+---------------------------------
Comment (by mqudsi):
Not sure if I should comment here or possibly open a different issue, but
is there any way for the legacy-support shims to be visible to downstream
users of `rustc` linking against its standard library?
For example, the `rand` crate assumes that since `rustc` bumped its
minimum supported macOS version to one with `_getentropy()` and
`_clock_gettime()`, it can just call them. But that causes undefined
symbol linker errors even when using a macports legacy-support-infused
rust toolchain (rust/cargo 1.78.0 under 10.10) to build the project with
the `rand` dependency. As `rand` is quite a foundational crate, this
limits compatibility significantly (the last `rand` version without the
hard `_getentropy()` dependency was 0.7.x which is not semver-compatible
with the current 0.8.x rand releases and requires a lot of hacking to
dependent projects to get them to run under 0.7.x).
Is there any way we can make the legacy support `_getentroy()` and
`_clock_gettime()` shims transitively visible to its dependents?
The linker error:
{{{
error: linking with `cc` failed: exit status: 1
<snip>
Undefined symbols for architecture x86_64:
"_clock_gettime", referenced from:
std::sys::pal::unix::time::Timespec::now::hf41285c15e0a285b
(.llvm.4974563244208805110) in libstd-dea1dec033daebae.rlib(std-
dea1dec033daebae.std.4e58b1c7d3f5f121-cgu.05.rcgu.o)
"_getentropy", referenced from:
std::sys::pal::unix::rand::imp::fill_bytes::h39617d8376b4a809 in libstd-
dea1dec033daebae.rlib(std-
dea1dec033daebae.std.4e58b1c7d3f5f121-cgu.14.rcgu.o)
}}}
As an fyi/aside, I tried to define my own `_gentropy()` shim in rust (in
the same project that uses `rand`), but it doesn't work as the linker is
searching for a dynamically exported symbol and is not considering static
symbols exported by the same project (this kind of stuff used to work in
C++ — or maybe it's actually a macOS-specific limitation that stops it
from working?):
{{{#!rust
#[no_mangle]
pub unsafe fn _getentropy(buf: *mut core::ffi::c_void, buflen: usize) ->
core::ffi::c_int {
use std::io::Read;
let slice = std::slice::from_raw_parts_mut(buf as *mut u8, buflen);
let mut rand = match std::fs::File::open("/dev/urandom") {
Ok(file) => file,
Err(_) => return -1,
};
match rand.read_exact(slice) {
Ok(_) => 0,
_ => -1,
}
}
}}}
--
Ticket URL: <https://trac.macports.org/ticket/69138#comment:21>
MacPorts <https://www.macports.org/>
Ports system for macOS
More information about the macports-tickets
mailing list