Bootstrap fails with linker error while running on non-NixOS Nix environment (WSL2 Ubuntu)

Hi. I'm trying to build the Rust compiler using toolchains installed by Nix on non-NixOS Linux (WSL2 Ubuntu). However, when I run ./, the command fails to bootstrap with the following error:

[nix-shell:~/rust]$ ./
info: Downloading and building bootstrap before processing --help
      command. See src/bootstrap/ for help with common
Updating only changed submodules
Submodules updated in 0.01 seconds
   Compiling proc-macro-error v1.0.4
   Compiling serde v1.0.125
error: /lib/x86_64-linux-gnu/ version `GLIBC_2.32' not found (required by /home/pan/rust/build/bootstrap/debug/deps/
   --> /home/pan/.cargo/registry/src/
284 | pub use proc_macro_error_attr::proc_macro_error;
    |         ^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: could not compile `proc-macro-error`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: /lib/x86_64-linux-gnu/ version `GLIBC_2.32' not found (required by /home/pan/rust/build/bootstrap/debug/deps/
   --> /home/pan/.cargo/registry/src/
293 | extern crate serde_derive;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: build failed
failed to run: /home/pan/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path /home/pan/rust/src/bootstrap/Cargo.toml

I am confused because the error message points to the system libc, but when I use ldd it points to the libc managed by Nix.

[nix-shell:~/rust]$ ldd build/bootstrap/debug/deps/ (0x00007ffc33bfb000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f09c0618000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f09c05f7000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f09c05f2000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f09c0431000)
        /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib64/ (0x00007f09c0d5e000)
[nix-shell:~/rust]$ ldd build/x86_64-unknown-linux-gnu/stage0/bin/cargo (0x00007ffe47739000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fa0fda28000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fa0fda1d000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fa0fd9fc000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fa0fd8b9000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fa0fd8b4000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fa0fd6f3000)
        /lib64/ => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib64/ (0x00007fa0feaad000)

Do you have any idea what is the cause of this problem?

Glibc uses symbol versioning. This means that if you link against a certain version of glibc, you must use at least this version at runtime. NixOS likely has a more recent version of glibc than Ubuntu. This means that you can't use executables built on NixOS on Ubuntu. The standard solution for this is building inside a container (or nix environment I think) that has an older glibc version installed. The rustc CI uses CentOS I think as they use a pretty old version of glibc.

1 Like

I guess I'm hitting this:

According to these issues, the cause of this problem seems to be the mismatch between glibc used for building proc macros and used by rustc's dlopen invocation. However, both proc macro and rustc seem to be linked against the same glibc (installed by Nix), and this glibc does support GLIBC_2_32:

[nix-shell:~/rust]$ ldd ./build/x86_64-unknown-linux-gnu/stage0/bin/rustc (0x00007fd499819000) => /home/pan/rust/./build/x86_64-unknown-linux-gnu/stage0/bin/../lib/ (0x00007fd495a7f000) => /home/pan/rust/./build/x86_64-unknown-linux-gnu/stage0/bin/../lib/ (0x00007fd495703000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fd4956e2000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fd4956d7000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fd4956d2000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fd495511000) => /home/pan/rust/./build/x86_64-unknown-linux-gnu/stage0/bin/../lib/../lib/ (0x00007fd4902e8000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fd4902ce000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007fd49018b000)
        /lib64/ => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib64/ (0x00007fd49981b000) => not found
[nix-shell:~/rust]$ ldd ./build/bootstrap/debug/deps/ (0x00007ffc6fffc000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f1538de8000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f1538dc7000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f1538dc2000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f1538c01000)
        /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib64/ (0x00007f1539055000)

I don't get why system libc (/lib/x86_64-linux-gnu/ is used and appears in the error message in the first place😅

I don't think I'm using binaries built on NixOS but bootstrapping binaries automatically downloaded by

Yes, at runtime. However, your error:

indicates that the system libc is being used during the build. I suspect that your Nix environment is either not set up properly or rpath entries are missing.

1 Like

I found that LD_TRACE_LOADED_OBJECTS=1 and ldd return different libc paths for the bootstrap rustc😂

[nix-shell:~/rust]$ LD_TRACE_LOADED_OBJECTS=1 ./build/x86_64-unknown-linux-gnu/stage0/bin/rustc (0x00007ffd63d88000) => /home/pan/rust/build/x86_64-unknown-linux-gnu/stage0/bin/../lib/ (0x00007f5b8e049000) => /home/pan/rust/build/x86_64-unknown-linux-gnu/stage0/bin/../lib/ (0x00007f5b8dccd000) => /lib/x86_64-linux-gnu/ (0x00007f5b8dca2000) => /lib/x86_64-linux-gnu/ (0x00007f5b8dc97000) => /lib/x86_64-linux-gnu/ (0x00007f5b8dc91000) => /lib/x86_64-linux-gnu/ (0x00007f5b8da9f000) => /home/pan/rust/build/x86_64-unknown-linux-gnu/stage0/bin/../lib/../lib/ (0x00007f5b88876000) => /lib/x86_64-linux-gnu/ (0x00007f5b8885b000) => /lib/x86_64-linux-gnu/ (0x00007f5b8870c000)
        /lib64/ (0x00007f5b9196d000) => /lib/x86_64-linux-gnu/ (0x00007f5b886f0000)

[nix-shell:~/rust]$ ldd ./build/x86_64-unknown-linux-gnu/stage0/bin/rustc (0x00007ffca0eb4000) => /home/pan/rust/./build/x86_64-unknown-linux-gnu/stage0/bin/../lib/ (0x00007f5119adc000) => /home/pan/rust/./build/x86_64-unknown-linux-gnu/stage0/bin/../lib/ (0x00007f5119760000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f511973f000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f5119734000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f511972f000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f511956e000) => /home/pan/rust/./build/x86_64-unknown-linux-gnu/stage0/bin/../lib/../lib/ (0x00007f5114345000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f511432b000) => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/ (0x00007f51141e8000)
        /lib64/ => /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib64/ (0x00007f511d873000) => not found

So yes, system libc is used by rustc. Then I need to find a way to override these paths...

Bootstrap patches rustc automatically on NixOS. It probably doesn't do this for you. The normal way to patch it for Nix would be using patchelf to override the interpreter and append the rpath. It is probably easier to convince bootstrap that you are on NixOS though. I think removing

will do the trick.

1 Like

Commenting out these lines did the trick. Thanks! It makes sense that the bootstrap binaries were not patched because my environment is a usual Linux with Nix, not NixOS.

Now I am wondering if it would be a good idea to send a patch to add a config that overrides this check to compile rustc with Nix's toolchain.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.