You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On FreeBSD, libzfs_core needs to link to libzutil. zfs-core-sys/build.rs does indeed specify that correctly. However, the resulting binaries don't end up linked to libzutil. It seems like rustc ignores the -l zutil option because the Rust code doesn't have direct references to libzutil, and Rust doesn't consider transitive linking dependencies. Probably related to bazelbuild/rules_rust#78 .
However, apply this stupid little patch to the source tree, which calls a libzutil function that does literally nothing, and magically the binaries are all correctly linked:
diff --git a/zfs-core-sys/src/lib.rs b/zfs-core-sys/src/lib.rs
index 2d6a893..d1c85d1 100644
--- a/zfs-core-sys/src/lib.rs+++ b/zfs-core-sys/src/lib.rs@@ -6,3 +6,11 @@ extern crate nvpair_sys as nvpair;
use nvpair::*;
include!("bindings.rs");
+++extern "C" {+ /// This function does literally nothing on FreeBSD, but we must reference+ /// it so the optimizer doesn't "helpfully" remove the linkage to+ /// libzutil.so.+ pub fn zfs_dev_flush(fd: i32) -> i32;+}diff --git a/zfs-core/src/lib.rs b/zfs-core/src/lib.rs
index e56222c..29f38c0 100644
--- a/zfs-core/src/lib.rs+++ b/zfs-core/src/lib.rs@@ -146,6 +146,7 @@ impl Zfs {
/// Create a handle to the Zfs subsystem
#[doc(alias = "libzfs_core_init")]
pub fn new() -> io::Result<Self> {
+ unsafe { sys::zfs_dev_flush(0); }
let v = unsafe { sys::libzfs_core_init() };
if v != 0 {
66: Fix linking to libzutil on FreeBSD r=jmesmon a=asomers
Rust needs to use -as-needed when linking to transitive dependencies.
At least, on some targets. It's undocumented which targets require
that. This option is not documented in the Cargo Book, only in the RFC
Book:
https://rust-lang.github.io/rfcs/2951-native-link-modifiers.htmlFixes#65
Co-authored-by: Alan Somers <[email protected]>
On FreeBSD, libzfs_core needs to link to libzutil. zfs-core-sys/build.rs does indeed specify that correctly. However, the resulting binaries don't end up linked to libzutil. It seems like rustc ignores the
-l zutil
option because the Rust code doesn't have direct references to libzutil, and Rust doesn't consider transitive linking dependencies. Probably related to bazelbuild/rules_rust#78 .To demonstrate the problem:
However, apply this stupid little patch to the source tree, which calls a libzutil function that does literally nothing, and magically the binaries are all correctly linked:
The text was updated successfully, but these errors were encountered: