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

Dynamic linker detection does not work #21

Closed
kknives opened this issue May 18, 2023 · 2 comments
Closed

Dynamic linker detection does not work #21

kknives opened this issue May 18, 2023 · 2 comments

Comments

@kknives
Copy link

kknives commented May 18, 2023

When using the overlay to compile a dynamically linked binary, the host's linker is used.

zig-out/bin/rs-zig: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.10.0, with debug_info, not stripped

This leads to GLIBC version mismatch when running the binary

/home/sga/code/rs-zig/zig-out/bin/rs-zig: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.36' not found (required by /nix/store/yazs3bdl481s2kyffgsa825ihy1adn8f-gcc-12.2.0-lib/lib/libstdc++.so.6)
/home/sga/code/rs-zig/zig-out/bin/rs-zig: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_ABI_DT_RELR' not found (required by /nix/store/yaz7pyf0ah88g2v505l38n0f3wg2vzdj-glibc-2.37-8/lib/libm.so.6)
/home/sga/code/rs-zig/zig-out/bin/rs-zig: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_ABI_DT_RELR' not found (required by /nix/store/yaz7pyf0ah88g2v505l38n0f3wg2vzdj-glibc-2.37-8/lib/libpthread.so.0)

According to this answer, the unstable channel fixes this by applying a patch.
But as this overlay does not build from source, it may not work here.

@mitchellh
Copy link
Owner

mitchellh commented May 18, 2023

Oof. Yeah I can't do anything about this, but if there isn't an issue open I bet you the Zig folks might be interested in hearing about this, there are a decent number of Nix users over there.

EDIT: This explains a ton of things to me since I've experienced this before.

@dermetfan
Copy link

I worked around this by running zig through proot to effectively apply nixpkgs' patch at runtime:

zig = inputs.zig-overlay.packages.${system}.master.overrideAttrs (oldAttrs: {
  installPhase = ''
    ${oldAttrs.installPhase}

    mv $out/bin/{zig,.zig-unwrapped}

    cat > $out/bin/zig <<EOF
    #! ${lib.getExe pkgs.dash}
    exec ${lib.getExe pkgs.proot} \\
      --bind=${pkgs.coreutils}/bin/env:/usr/bin/env \\
      $out/bin/.zig-unwrapped "\$@"
    EOF
    chmod +x $out/bin/zig
  '';
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants