Final link failed (with CARGO_INCREMENTAL)

215d53c
Opened by Michal 'vorner' Vaner at 2019-06-17 20:32:04

Sometimes (it's not always reproducible and it doesn't happen with some specific code), I get a linker error complaining undefined references to rust functions in my project, something like this:

  = note: /home/vorner/work/pakon/aggregator/target/debug/deps/aggregator-57e8a9355952fffd.aggregator-keeper-query-tests.o: In function `aggregator::keeper::query::tests::time_to_system':
          /home/vorner/work/pakon/aggregator/src/keeper/query.rs:414: undefined reference to `aggregator::keeper::query::Time::to_absolute::h1a0a7dea62a07bb1'
          /home/vorner/work/pakon/aggregator/src/keeper/query.rs:421: undefined reference to `aggregator::keeper::query::Time::to_absolute::h1a0a7dea62a07bb1'
          /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/vorner/work/pakon/aggregator/target/debug/deps/aggregator-57e8a9355952fffd: hidden symbol `_ZN10aggregator6keeper5query4Time11to_absolute17h1a0a7dea62a07bb1E' isn't defined
          /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: final link failed: Bad value
          collect2: error: ld returned 1 exit status

They don't go away even when I modify the sources and try to compile again. These things help:

  • Running cargo clean and trying again.
  • Running the compilation without CARGO_INCREMENTAL (I have it set in my environment).

Therefore, I believe sometimes rustc produces and stores part of the compilation without the function present and tries to reuse it next time. I further suspect this might happen when the function is unused at the first compilation, but then I add a test that uses it ‒ maybe some kind of optimisation producing the module (or struct's impl) without the code for the unused function and caching it, not noticing it is missing the next time.

It happens more often when I code with cargo watch --no-restart -x test --all in a separate terminal and save the file often (maybe simply because the compilation is run more often).

$ rustc --version --verbose
rustc 1.21.0-nightly (aac223f4f 2017-07-30)
binary: rustc
commit-hash: aac223f4f5d5ca979c694b614d4db37a7200528d
commit-date: 2017-07-30
host: x86_64-unknown-linux-gnu
release: 1.21.0-nightly
LLVM version: 4.0
  1. I think I just encountered this at work. I thought I'd try using CARGO_INCREMENTAL and nightly to help speed up poor compile times and encountered this when trying to run tests with cargo --test. Interestingly everything else works perfectly (cargo --test --release, cargo build, etc). I'll see if shows itself again after doing a full cargo clean.


    Incremental compilation is awesome by the way, great work! It drops a 2-5 minute cargo build --release when I make a change down to about 15 seconds :)

    Michael Bryan at 2017-11-07 07:34:23

  2. I get this all the time when working on my project.

    Gui Andrade at 2019-01-09 05:43:57

  3. Hmm, still? I must not have seen this thing for ages.

    Michal 'vorner' Vaner at 2019-01-12 14:23:44

  4. Yeah, it happens every once in every 15 or so edit-compile cycles when working on my repo here.

    Gui Andrade at 2019-01-12 16:46:44