Repository navigation
Closed
Description
When using opteadm as a Git dependency in a project's Cargo.toml, we get linking errors. Things seem to work fine if the dependency is specified as a local, path-dependency. To reproduce, create a new binary:
$ cargo new --bin tst
With a Cargo.toml that looks like this:
[package]
name = "tst"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
opteadm = { git = "https://github.com/oxidecomputer/opte" }
I have the following minimal binary, in `src/main.rs:
fn main() {
let _ = opteadm::OpteAdm::open(opteadm::OpteAdm::DLD_CTL).unwrap();
}
Running the package's binary fails at link:
bnaecker@feldspar : ~/tst $ cargo +nightly run
Compiling tst v0.1.0 (/home/bnaecker/tst)
error: linking with `gcc` failed: exit status: 1
|
= note: "gcc" "-m64" "-std=c99" "/home/bnaecker/tst/target/debug/deps/tst-9d56c2ce4c177f1f.1gpqo5y6xwwh5ghs.rcgu.o" "/home/bnaecker/tst/target/debug/deps/tst-9d56c2ce4c177f1f.2j9b0easpuy3lmkm.rcgu.o" "/home/bnaecker/tst/target/debug/deps/tst-9d56c2ce4c177f1f.3gn43d55b54eesvf.rcgu.o" "/home/bnaecker/tst/target/debug/deps/tst-9d56c2ce4c177f1f.4au4nef3u6uykb3q.rcgu.o" "/home/bnaecker/tst/target/debug/deps/tst-9d56c2ce4c177f1f.4mo6zhonh6hibyme.rcgu.o" "/home/bnaecker/tst/target/debug/deps/tst-9d56c2ce4c177f1f.50oco8jau4nggglf.rcgu.o" "/home/bnaecker/tst/target/debug/deps/tst-9d56c2ce4c177f1f.a259uc1t2xr6vh4.rcgu.o" "/home/bnaecker/tst/target/debug/deps/tst-9d56c2ce4c177f1f.2xbcavjzg20r3tv7.rcgu.o" "-Wl,-z,ignore" "-L" "/home/bnaecker/tst/target/debug/deps" "-L" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib" "-Wl,-Bstatic" "/home/bnaecker/tst/target/debug/deps/libopteadm-ed4ebec202f4ac04.rlib" "/home/bnaecker/tst/target/debug/deps/liblibnet-20746b65a0c1aa47.rlib" "/home/bnaecker/tst/target/debug/deps/libnvpair-86698e07c8e6b879.rlib" "/home/bnaecker/tst/target/debug/deps/libnvpair_sys-3e491215f55562c3.rlib" "/home/bnaecker/tst/target/debug/deps/libforeign_types-f6b5afca31338a66.rlib" "/home/bnaecker/tst/target/debug/deps/libforeign_types_shared-984e5c51ce0f0c58.rlib" "/home/bnaecker/tst/target/debug/deps/libcstr_argument-785ee624af9de0c7.rlib" "/home/bnaecker/tst/target/debug/deps/libdlpi-f4fb8d05033217fb.rlib" "/home/bnaecker/tst/target/debug/deps/libnum_enum-a64b76e4a2b44370.rlib" "/home/bnaecker/tst/target/debug/deps/libsocket2-3b283ba9cd497e9e.rlib" "/home/bnaecker/tst/target/debug/deps/librusty_doors-524916c6b781492a.rlib" "/home/bnaecker/tst/target/debug/deps/libtracing-1c68e7f070b67704.rlib" "/home/bnaecker/tst/target/debug/deps/libcfg_if-385d26aca7d14e58.rlib" "/home/bnaecker/tst/target/debug/deps/libpin_project_lite-e8973c22a90577a2.rlib" "/home/bnaecker/tst/target/debug/deps/libtracing_core-50fa0fee84c6871d.rlib" "/home/bnaecker/tst/target/debug/deps/libcolored-9ea2386075d15489.rlib" "/home/bnaecker/tst/target/debug/deps/liblazy_static-caa99a9868af65b8.rlib" "/home/bnaecker/tst/target/debug/deps/libatty-217d37554bdf695c.rlib" "/home/bnaecker/tst/target/debug/deps/libopte_core-a9eafd55fd492016.rlib" "/home/bnaecker/tst/target/debug/deps/libanymap-94932fbd822a3e35.rlib" "/home/bnaecker/tst/target/debug/deps/libhashbrown-3ee81738fb11b578.rlib" "/home/bnaecker/tst/target/debug/deps/libahash-ea0262c66585ff9d.rlib" "/home/bnaecker/tst/target/debug/deps/libconst_random-14582242ea0e6c2a.rlib" "/home/bnaecker/tst/target/debug/deps/libpostcard-326332b7e9cab1aa.rlib" "/home/bnaecker/tst/target/debug/deps/libpostcard_cobs-4ead32620f584b18.rlib" "/home/bnaecker/tst/target/debug/deps/libheapless-5be6cd8261e12d53.rlib" "/home/bnaecker/tst/target/debug/deps/libstable_deref_trait-4cb687aceacb3a68.rlib" "/home/bnaecker/tst/target/debug/deps/libspin-b099bce116728165.rlib" "/home/bnaecker/tst/target/debug/deps/liblock_api-e698df25da0759aa.rlib" "/home/bnaecker/tst/target/debug/deps/libscopeguard-565e32347529b480.rlib" "/home/bnaecker/tst/target/debug/deps/libhash32-d0c190669e230bb4.rlib" "/home/bnaecker/tst/target/debug/deps/libillumos_ddi_dki-fe86c4415ee25292.rlib" "/home/bnaecker/tst/target/debug/deps/libsmoltcp-04f056c6b52ce7e2.rlib" "/home/bnaecker/tst/target/debug/deps/libbitflags-4d03e45c250cd080.rlib" "/home/bnaecker/tst/target/debug/deps/libmanaged-e2cfc91f6b787f02.rlib" "/home/bnaecker/tst/target/debug/deps/libzerocopy-2c8bd96196aba031.rlib" "/home/bnaecker/tst/target/debug/deps/libbyteorder-29a584d9778948bf.rlib" "/home/bnaecker/tst/target/debug/deps/libcstr_core-aed24baeafd4485e.rlib" "/home/bnaecker/tst/target/debug/deps/libmemchr-cb2aa58c9d871d55.rlib" "/home/bnaecker/tst/target/debug/deps/libcty-7cb5ecde0a0226c6.rlib" "/home/bnaecker/tst/target/debug/deps/libcfg_if-2f8775f3389269f7.rlib" "/home/bnaecker/tst/target/debug/deps/libthiserror-25ae4b3190cc3750.rlib" "/home/bnaecker/tst/target/debug/deps/libserde-c681115829c41256.rlib" "/home/bnaecker/tst/target/debug/deps/liblibc-13410709f55ff750.rlib" "-Wl,--start-group" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libstd-44ba11e7caeaa97b.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libpanic_unwind-f60c11ce2f3f2894.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libobject-2a6d17abf086d4e8.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libmemchr-28283bcf356a6b99.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libaddr2line-d4af3a6747ce39f4.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libgimli-abfba83daab33417.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/librustc_demangle-6d4e3a5e28938bae.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libstd_detect-188bd3d8afd99339.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libhashbrown-6205af1a1ba2b4fd.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libminiz_oxide-eb705613be612b49.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libadler-ccf005443048da69.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/librustc_std_workspace_alloc-5612a94d775dd7c1.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libunwind-45f9a318a4ba05a2.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libcfg_if-809e9a5223a42ae2.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/liblibc-8c850a53a00b4798.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/liballoc-9421d8315ee29563.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/librustc_std_workspace_core-5a6b7292ae0792e1.rlib" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libcore-bb36fb4d6ea14041.rlib" "-Wl,--end-group" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib/libcompiler_builtins-e250b29d90c73633.rlib" "-Wl,-Bdynamic" "-lkstat" "-lnvpair" "-lzfs" "-ldlpi" "-ldoor" "-lsendfile" "-llgrp" "-lsocket" "-lposix4" "-lpthread" "-lresolv" "-lnsl" "-lumem" "-lgcc_s" "-lm" "-lrt" "-lpthread" "-lc" "-lssp" "-L" "/home/bnaecker/.rustup/toolchains/nightly-x86_64-unknown-illumos/lib/rustlib/x86_64-unknown-illumos/lib" "-o" "/home/bnaecker/tst/target/debug/deps/tst-9d56c2ce4c177f1f" "-nodefaultlibs"
= note: Undefined first referenced
symbol in file
nodev /home/bnaecker/tst/target/debug/deps/libillumos_ddi_dki-fe86c4415ee25292.rlib(illumos_ddi_dki-fe86c4415ee25292.illumos_ddi_dki.30bde569-cgu.0.rcgu.o)
nulldev /home/bnaecker/tst/target/debug/deps/libillumos_ddi_dki-fe86c4415ee25292.rlib(illumos_ddi_dki-fe86c4415ee25292.illumos_ddi_dki.30bde569-cgu.0.rcgu.o)
ld: fatal: symbol referencing errors. No output written to /home/bnaecker/tst/target/debug/deps/tst-9d56c2ce4c177f1f
collect2: error: ld returned 1 exit status
error: could not compile `tst` due to previous error
Cloning this repo and specifying it as a path dependency builds just fine. Changing the one dependency in Cargo.toml to:
opteadm = { path = "../opte/opteadm" }
we can build and run the binary successfully:
bnaecker@feldspar : ~/tst $ cargo +nightly run
Compiling tst v0.1.0 (/home/bnaecker/tst)
Finished dev [unoptimized + debuginfo] target(s) in 0.80s
Running `target/debug/tst`
Metadata
Metadata
Assignees
Labels
No labels
Activity
rzezeski commentedon Apr 5, 2022
So I initially thought this was because opte is not a workspace, and when pulling it in via git it was treating it as one (and that was causing issues), but even after converting opte to a partial workspace (where ddi, opte-core, and opteadm are packages in the workspace), I still hit this linker error (versus when pulling opteadm in directly via a
path).I used
truss -f -a -t execto compare the exact invocations ofldfor both the git case and path case. They are identical. But for some reason in the git case it wantsnodevin the final object final, and I have no idea why. If I look at the binary for the path case it has nothing for the symbolnodev.Versus the git case:
The only difference I can see between the two is that in the good (path) case it has incremental objects for ddi:
But there is no such thing for the bad (git) case.
This all feels like some inside baseball between cargo/rustc and how it builds up these objects and invokes the linker that is beyond my understanding on how to debug.
The real solution to this problem, once again, is that an API layer needs to be defined that insulates a client from all this crap. There is absolutely no reason for
nodev()to be on the scene as that is a purely kernel driver concern. However, there is a hack that can be done in order to make forward progress until that separation happens.This tells
ld(1)to ignore the case where a symbol is undefined.rzezeski commentedon Apr 11, 2022
This appears to be fixed on my end with #109 in place. @bnaecker when you have opte successfully imported as a git dep in sled-agent go ahead and close this out.
bnaecker commentedon Apr 11, 2022
Yep, I can confirm that this allows me to build the sled agent locally, using
opteandopte-ioctlas a git dependency. Closing.rzezeski commentedon Apr 27, 2022
So this issue is rearing its ugly head again though in a slightly different context (seems to have nothing to do with how opte is being imported into another project). Like, I know what ld is telling me, but I just don't understand why this has only sort of become a thing until now, and seems to be dependent on mysterious things (which means it's probably a subtle environment thing or a race).
https://buildomat.eng.oxide.computer/wg/0/details/01G1NHXQ7NBK0PQQECAPPP44GN/1GzRnEpM9I2HabKeiO4o57z4941O0SpeQRlFgQBS3TlM06Xr/01G1NHY02RTJFFC1G7CCG4YPEW
XXX test theory around #88
rzezeski commentedon Apr 28, 2022
This issue should probably be retitled or a new issue created in its place as the underlying problem seems to be a bit more general than originally described. I'm wrapped up with jury duty right now so don't quite have the time to organize my thoughts like I normally would, but there's two things thoughts I've had thus far.
I know at some point rustc/cargo reintroduced incremental builds, which implicitly bumped
codegen-unitsfrom16to256. This directly effects the number of args passed told; I thought perhaps this would be part of the issue. However, my test in XXX test theory around #88 #137 seems to show otherwise (though we may want to setcodegen-unitsto1in thereleaseprofile anyways).The toolchain installed by buildomat changed between the successful builds and the first failed build I encountered while working on the
opte-128-go-publicbranch.comit
abc6bba95edaaf5a65822892944dc45852a46663on master:https://buildomat.eng.oxide.computer/wg/0/details/01G1CDTF8ERR6XGKV5T37XFMDS/gsPm1g8s1czbn44mumxNAZE26kaQTjCQktKZYK4kG0OnqXdX/01G1CDTQF0FQWBV3NTP513MK2J
commit
b26a50712d50c0147a723bf9a1fcb5ec98ddfb5einopte-128-go-publicbranch where I first saw this issue return.https://buildomat.eng.oxide.computer/wg/0/details/01G1NHXQ7NBK0PQQECAPPP44GN/1GzRnEpM9I2HabKeiO4o57z4941O0SpeQRlFgQBS3TlM06Xr/01G1NK0N1Y36FSCGH4MGBR0BZE
rzezeski commentedon Apr 28, 2022
Okay, I have replicated this issue locally by bumping my toolchain on
midgar(a Helios host).Toolchain I've been building on for last N weeks:
Toolchain I updated to:
Output of running
optetests.So at least I have a reliable way to reproduce now and examine locally. My focus (when I get some free time) will be looking at the gcc/ld invocation differences between the two and if there's any difference between the codegen units. It would probably also make sense to set the
codegen-unitsto1since that doesn't seem to make a difference but should make debugging easier by greatly reducing the amount of args passed to gcc/ld.bnaecker commentedon Aug 18, 2022
We've not hit this in a while. We'll obviously bring it back if anyone sees it again.
rzezeski commentedon Aug 26, 2022
Upon bumping the rust toolchain I have hit this issue once again.
https://buildomat.eng.oxide.computer/wg/0/details/01GBC8R0R6MA6MD6JK2EJGYPM8/LW0v1PwjJVo1MTeCpLdFq2kmIoY5fWCbJJ110FW1DqzZrlzZ/01GBC8R9PKT501RGTNWMYH6HDF#S276
I also reproduced this locally on my Helios box. An additional data point I noticed:
cargo build --releaseof theoptecrate just fine.cargo build testof theoptecrate fails with the above linker error.The rust version being used:
[-]Linking failures when using crate as a git dependency[/-][+]Linking failures[/+]rzezeski commentedon Aug 27, 2022
By the powers of
truss -f -t exec -aand the dtracepauseaction I have finally arrived at an answer to this years biggest OPTE mystery.2022-04-22to2022-08-08.cargo testfor theoptecrate.cargo build, that succeeds just fine. Okay so it builds just fine, but I can't run test. What's the difference?cargo buildyou're just getting a shared library/archive/rlib, but since cargo says "compiling" for both that obvious fact got lost on me).nodev()symbol it's talking about is a kernel-only symbol, so it makes sense why the linker won't find it when trying to compile a userland test program.truss -f -t exec -aatcargo testto see exactly what it's executing and what it's passing told. I run this for both the older and newer toolchain and compare the output./tmp/rust<XXX>/objects.o.objects.obeing referenced, I see nothing for it being generated (I would have expected somegcc/ldexec somewhere).symbols.o:UNDEFand 2) many of them are theno_manglesymbols I expose inillumos-ddi-dki.symbols.o.nodev(), that makes sense, but how did I get here?no_manglesymbol, in an attempt to force the linker to resolve them from the archives that follow (as arguments to the linker)no_manglesymbols that I have declared inillumos-ddi-dki, which is a dep ofopte, andcargo testis trying to compile/link it so that it can run the test programextern "C"functions defined in Rust in order to satisfy the type system, but they all map to the illumos kernelnodev()symbol.nulldev(), so now the linker needs to track that down...but it can't because we are compiling this as a userland executableIn short, this has always been a problem with the way I structured things in
illumos-ddi-dkiand exposed them toopte, but this problem wasn't exposed until the rust toolchain got this new "synthetic object" hack. This is obvious in hindsight, but was easy to miss thanks to many confounding factors.The solution will involve restructuring how symbols are exposed from
illumos-ddi-dki. I haven't thought out the specifics yet. One option might be to only have it as a dep in a non-std/non-test compilation env, but there are a few types that opte relies on during testing which would have to be replicated, like themblk_t. Another option is to add astdfeature and only expose those few types needed for testing, and then hide everything else. Then make sure thatstdis enabled when being compiled for the purposes of testing by opte (I think there's a way to tell cargo to do this). There may be other options too, I just haven't thought it through enough yet.Linking failures #88
Linking failures #88
Linking failures #88
rzezeski commentedon Aug 30, 2022
Addressed in 365cfd6.