Skip to content

Impure path used during linking of unikernel image #2310

@mazunki

Description

@mazunki

Attempting to build example/ (through nix-shell ./shell.nix) on Gentoo gives the following errors:

ld.lld: error: /nix/store/wkn6ivpdjri06sjig43k43n72cidzb4p-includeos-static-x86_64-unknown-linux-musl-dev/libcxx/lib/libc++.a(cxa_exception_storage.cpp.o): unable to find library from dependent library specifier: pthread
ld.lld: error: /nix/store/wkn6ivpdjri06sjig43k43n72cidzb4p-includeos-static-x86_64-unknown-linux-musl-dev/libcxx/lib/libc++.a(fallback_malloc.cpp.o): unable to find library from dependent library specifier: pthread
ld.lld: error: /nix/store/wkn6ivpdjri06sjig43k43n72cidzb4p-includeos-static-x86_64-unknown-linux-musl-dev/libcxx/lib/libc++.a(memory.cpp.o): unable to find library from dependent library specifier: pthread
ld.lld: error: /nix/store/wkn6ivpdjri06sjig43k43n72cidzb4p-includeos-static-x86_64-unknown-linux-musl-dev/libcxx/lib/libc++.a(mutex.cpp.o): unable to find library from dependent library specifier: pthread
ld.lld: error: /nix/store/wkn6ivpdjri06sjig43k43n72cidzb4p-includeos-static-x86_64-unknown-linux-musl-dev/libcxx/lib/libc++.a(cxa_guard.cpp.o): unable to find library from dependent library specifier: pthread
ld.lld: error: /nix/store/wkn6ivpdjri06sjig43k43n72cidzb4p-includeos-static-x86_64-unknown-linux-musl-dev/libcxx/lib/libc++.a(condition_variable.cpp.o): unable to find library from dependent library specifier: pthread
ld.lld: error: /nix/store/wkn6ivpdjri06sjig43k43n72cidzb4p-includeos-static-x86_64-unknown-linux-musl-dev/libcxx/lib/libc++.a(thread.cpp.o): unable to find library from dependent library specifier: pthread
ld.lld: error: /nix/store/wkn6ivpdjri06sjig43k43n72cidzb4p-includeos-static-x86_64-unknown-linux-musl-dev/libunwind/lib/libunwind.a(libunwind.cpp.o): unable to find library from dependent library specifier: dl
ld.lld: error: /nix/store/wkn6ivpdjri06sjig43k43n72cidzb4p-includeos-static-x86_64-unknown-linux-musl-dev/libunwind/lib/libunwind.a(libunwind.cpp.o): unable to find library from dependent library specifier: pthread

On other projects adding set(CMAKE_LINKER_TYPE LLD) to example/CMakeLists.txt fixes this issue (is this the correct solution?), but here this raises another warning: ld.lld: error: unknown argument '-fuse-ld=lld'.

Instead, I can add -DCMAKE_LINKER="$(command -v ld)" to shell.nix, which seems to fix it, but that feels like a dirty hack:

diff --git a/shell.nix b/shell.nix
index b26dbef07..ad3075213 100644
--- a/shell.nix
+++ b/shell.nix
@@ -64,7 +64,7 @@ includeos.pkgs.mkShell.override { inherit (includeos) stdenv; } rec {
         pushd "$BUILDPATH"
     fi
     cmake "$unikernel" -DARCH=x86_64 -DINCLUDEOS_PACKAGE=${includeos} -DCMAKE_MODULE_PATH=${includeos}/cmake \
-                     -DFOR_PRODUCTION=OFF
+                     -DFOR_PRODUCTION=OFF -DCMAKE_LINKER="$(command -v ld)"
     make -j $NIX_BUILD_CORES
     echo -e "\n====================== IncludeOS nix-shell ====================="
     if [ -z "${buildpath}" ]; then

Why is Nix picking an impure linker (i.e. /usr/lib/llvm/20/bin/ld.lld) unless explicitly telling it to use LLD, despite running nix-shell --pure? Is there a better solution than hardcoding the linker path through the cmake call?

None of this is necessary on NixOS. I haven't tested on other non-Gentoo systems, but I would imagine I'm not alone with this issue, and I feel like we should prevent this issue from our side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions