Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking errors on FreeBSD 13 #166

Closed
fabiojmendes opened this issue Feb 28, 2022 · 4 comments
Closed

Linking errors on FreeBSD 13 #166

fabiojmendes opened this issue Feb 28, 2022 · 4 comments
Assignees

Comments

@fabiojmendes
Copy link

fabiojmendes commented Feb 28, 2022

Describe the bug
Applications using libzetta-rs will fail to link on FreeBSD 13

To Reproduce
Create an application with:

Cargo.toml

[package]
name = "test-libzetta"
version = "0.1.0"
edition = "2021"

[dependencies]
libzetta = "0.2.3"

main.rs

use libzetta::zpool::{ZpoolEngine, ZpoolOpen3};

fn main() {
    let engine = ZpoolOpen3::default();
    println!("{:?}", engine.all());
}

Output of cargo build

cargo build
   Compiling test-libzetta v0.1.0 (/usr/home/fabio/test-libzetta)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.13vyoyvt6ut8qa5m.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.1g57q4l20h1sbylx.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.1hc5sscgiwlz5rt1.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.1no4ozf6fihavjsr.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.2eh76mkrra25xfho.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.2lqbqo1ixslvx3np.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.2q3ms8ajj197wbrc.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.2v34mcoc4aaskk2g.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.49ol8z3jsxvjced3.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.4c2kfi2vbw9lpczi.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.4ieoagz6eg9ydm6n.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.4mbepru4rnf3ae8j.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.4z2odpy993llm4j4.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.549sqzbjhbq31uxi.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.58vuh7cvh5xraki.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.adnfmifz9b85jrt.rcgu.o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c.wgzc6r635j683jj.rcgu.o" "-Wl,--as-needed" "-L" "/usr/home/fabio/test-libzetta/target/debug/deps" "-L" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib" "-Wl,-Bstatic" "/usr/home/fabio/test-libzetta/target/debug/deps/liblibzetta-c0c2208462155e81.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libslog_stdlog-85b853dad24924e9.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libslog_scope-d601b90eb7739643.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libarc_swap-9a387d037f68fa26.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/liblog-a130a30210216936.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libcfg_if-2ada713ecf57f413.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libonce_cell-3fc1e37316b7afbe.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libregex-0084bcafe3196267.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libaho_corasick-62a6f1e0526bee88.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libregex_syntax-fc96c88b97e40e22.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libzfs_core_sys-be88779150ee38a4.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/liblibnv-eecd169ea87f0f3c.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libnvpair_sys-25097b93b3c3b815.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libquick_error-7c9e55177c42b376.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libcstr_argument-df5b1e6dd8b365dd.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libmemchr-a756181dd69f6b5b.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libchrono-8ee1bb0565b54ad0.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libnum_integer-f1d8f2152308d647.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libnum_traits-de3d57bfaf559dc1.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libtime-74f52fdd3abe55e3.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/liblibc-ba129cd47f474334.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libbitflags-dc63c3b8344cec44.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libpest-a71e6afb5c619968.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libucd_trie-f00a496b54ceb183.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libstrum-11f00cc59eff11ac.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libslog-9087c004595a5123.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libquick_error-47745199a257fd1c.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/liblazy_static-2aa374100e33a63a.rlib" "/usr/home/fabio/test-libzetta/target/debug/deps/libderive_builder-16b8bd07c2d554a5.rlib" "-Wl,--start-group" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libstd-db85700b5100c208.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libpanic_unwind-49fd42a110084688.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libminiz_oxide-e7a0baf49db408ae.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libadler-c1e1fe663e9f22dd.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libobject-39a79c649c142089.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libmemchr-3779d4badebd9d41.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libaddr2line-7d901671e3110a8a.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libgimli-b3aca806e91bf121.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libstd_detect-386bd0661c47d9a4.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_demangle-ad743600e2db770d.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libhashbrown-178e77de45f627fb.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_std_workspace_alloc-034c9049396643d6.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libunwind-85a39d0fb36b02e1.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libcfg_if-5324df6b1bedd9cf.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/liblibc-87eed9dedb3d1454.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/liballoc-0b3e94b6f09c9394.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/librustc_std_workspace_core-9a4a1190b7fecb67.rlib" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libcore-9d06bd3c15aab7bc.rlib" "-Wl,--end-group" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib/libcompiler_builtins-99c13872153b3dea.rlib" "-Wl,-Bdynamic" "-lzfs_core" "-lnvpair" "-lzfs" "-lrt" "-lutil" "-lexecinfo" "-lkvm" "-lutil" "-lprocstat" "-lrt" "-ldevstat" "-lexecinfo" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lrt" "-lutil" "-lexecinfo" "-lkvm" "-lutil" "-lprocstat" "-lrt" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/home/fabio/.rustup/toolchains/stable-x86_64-unknown-freebsd/lib/rustlib/x86_64-unknown-freebsd/lib" "-o" "/usr/home/fabio/test-libzetta/target/debug/deps/test_libzetta-22c98f66717fc84c" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: ld: error: /usr/lib/libzfs_core.so: undefined reference to libspl_assertf [--no-allow-shlib-undefined]
          ld: error: /usr/lib/libzfs_core.so: undefined reference to zfs_ioctl_fd [--no-allow-shlib-undefined]
          cc: error: linker command failed with exit code 1 (use -v to see invocation)

  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `test-libzetta` due to previous error

Expected behavior
The application should compile and build without any issues

** Please complete the following information:**

  • OS: FreeBSD 13.0-RELEASE-p7
  • libZetta 0.2.3
  • cargo 1.58.0 (f01b232bc 2022-01-19)
  • rustc 1.58.1 (db9d1b20b 2022-01-20)
  • cc --version
    FreeBSD clang version 11.0.1 ([email protected]:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe)
    Target: x86_64-unknown-freebsd13.0
    Thread model: posix
    InstalledDir: /usr/bin

Additional context
There's a related issue on FreeBSD mailing list regarding these missing symbols

Workaround
As a workaround I'm linking these libs explicitly as instructed by the mailing list issue:
build.rs

fn main() {
    println!("cargo:rustc-link-lib=spl");
    println!("cargo:rustc-link-lib=zutil");
}

Now the application will compile and build without any issues:

cargo build
   Compiling test-libzetta v0.1.0 (/usr/home/fabio/test-libzetta)
     Finished dev [unoptimized + debuginfo] target(s) in 0.45s
@fabiojmendes
Copy link
Author

I would also like to volunteer to fix this bug, but I might need some mentoring. I'm not that experienced with building libs in rust.

@andoriyu
Copy link
Member

andoriyu commented Mar 3, 2022

@fabiojmendes Thanks for reporting this.

I believe this was fixed on FreeBSD side: https://reviews.freebsd.org/R10:9e9c651caceb9ecd17131e8bb29791ba4cf1cec7

We can totally add a workaround for this, though. I think fix is more appropriate for zfs-core-sys crate: https://github.com/jmesmon/rust-libzfs/blob/master/zfs-core-sys/build.rs#L115-L117

@unrelentingtech I thought this was not an issue anymore?

@valpackett
Copy link
Contributor

13.0-RELEASE-p7

The fix was cherry-picked into 13-STABLE, but I don't think that means it would land in a new -pX patch update, only in 13.1?

@andoriyu
Copy link
Member

andoriyu commented Mar 3, 2022

@fabiojmendes basically you need to add those lines to build.rs in crate that I linked.

Might worth reading uname -U and only print them if it's > 1300000. I believe FreeBSD 13.0 is where it got broken.

As a temp workaround, we can add them to this crate's build.rs and remove it once fix is released in sys crate.

bors bot added a commit to codyps/rust-libzfs that referenced this issue Mar 6, 2022
107: Workaround for missing libs on freebsd 13 r=jmesmon a=fabiojmendes

This pull request fixes linking issues on downstream libs on FreeBSD 13. See [libzetta-rs #166](Inner-Heaven/libzetta-rs#166) for details.

I also updated the url for grcov binary so the workflows will run.

Hopefully this workaround can be removed once this [issue is fixed](Inner-Heaven/libzetta-rs#166 (comment)) on FreeBSD side.

Co-authored-by: Fabio Mendes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants