I want to run and debug a 32-bit binary on a 64-bit machine.
I can successfully run it with steam-run ./binary.
But I want to run it directly like ./binary. (this is needed because I need to debug it with a library that doesn’t do follow-fork-mode child so it debugs steam-run)
Nix-ld
I have nix-ld enabled. I saw here that I need to patch nixpkgs to have nix-ld support other systems, but I’m not sure how to do it. Maybe nixpkgs.overlay, but I tried searching how the contributer does it in its nixos-config, but he just uses the nix-ld.systems option without the patch it seems to me.
Nix shell
Apart from nix-ld I checked out steam-run and it seems to use bwrap and fhsEnv, so I was thinking:
how do I create a nix shell where I specify the 32 bit loader and the 32 bit libraries I need and then enter it and just run the binary?
i386 nixpkgs
My binary depends on /lib/ld-linux.so.2 and libm.so.6.
I tried downloading the loader manually and using it
> ./libc6-i386/usr/lib32/ld-linux.so.2 ./binary
./binary: error while loading shared libraries: libm.so.6: cannot open shared object file: No such file or directory
but then I couldn’t find the 32 bit version of libm with nix-locate:
> nix-locate libm.so.6
rocmPackages.clang.out 0 s /nix/store/khd9h2x0h08sipn0hpdzf3d4k27zlphx-rocm-toolchain/lib/libm.so.6
glibc_multi.static 0 s /nix/store/gmbmw0npjz8f952pbmb9q5qy3fxvdj52-glibc-multi-2.40-66-static/lib/libm.so.6
glibc_multi.static 0 s /nix/store/gmbmw0npjz8f952pbmb9q5qy3fxvdj52-glibc-multi-2.40-66-static/lib64/libm.so.6
glibc_memusage.debug 0 s /nix/store/kh5fhigrhgsd3yazbdl2s0k6fgws1sgi-glibc-gd-2.40-66-debug/lib/debug/libm.so.6
glibc.out 1,029,504 x /nix/store/xx7cm72qy2c0643cm1ipngd87aqwkcdp-glibc-2.40-66/lib/libm.so.6
glibc_memusage.out 1,029,504 x /nix/store/hmkdsnrj4zbk05y7kxc5rkwsy2jsx7l5-glibc-gd-2.40-66/lib/libm.so.6
glibc.debug 0 s /nix/store/5l3npiqzwglfxxvv1mdrkyf9rqr5mdqf-glibc-2.40-66-debug/lib/debug/libm.so.6
glibc_multi.out 0 s /nix/store/l7jr2nsnmr380cwya9mszzw3bh07rnfd-glibc-multi-2.40-66/lib/libm.so.6
This don’t work for example:
> LD_LIBRARY_PATH=/nix/store/l7jr2nsnmr380cwya9mszzw3bh07rnfd-glibc-multi-2.40-66/lib/:$LD_LIBRARY_PATH ./libc6-i386/usr/lib32/ld-linux.so.2 ./binary
./binary: error while loading shared libraries: libm.so.6: wrong ELF class: ELFCLASS64
i686pkgs
I also saw somewhere pkgs.pkgsi686Linux but on search https://search.nixos.org/ it doesn’t appear. What is going on? Are the 32 bit version packages in there?