How do I install the 32-bit dynamic linker on 64-bit NixOS?
I need that to use mksdcard from the Android SDK. Currently, when I run that executable, the system reports «No such file or directory». For Debian, one can install ia32-libs. On Ubuntu, the package is called libc6-i386 . How do I get the file /lib/ld-linux.so.2 on NixOS?
What do you mean by 32-bit runtime linker? Are you saying you want to know how to install a 32-bit version of ld ? Usually you’d just have ld link 32-bit libraries/objects. What are trying to do with the «32-bit runtime linker» that you are not able to do now?
@ssnobody, sorry, I should have said «dynamic linker», but I think «runtime» makes more sense. The file is called /lib64/ld-linux-x86-64.so.2 for 64-bit executables and /lib/ld-linux.so.2 for 32-bit. I confirmed this by compiling a sample C program with and without -m32 and then running ldd on it.
@ssnobody regarding your question «what are you trying to do [. ] that you are not able to do now»: With a 32-bit dynamic linker, I can execute dynamically linked 32-bit executables.
3 Answers 3
NixOS does not natively have multiarch support.
The only Nix package which contains the 32-bit ELF interpreter ld-linux.so.2 file is the i386 version of glibc.
Luckily, we can work around the issue by borrowing the package from debian.
- Install dpkg : nix-env -i dpkg
- Download the libc-i386 package for 64-bit systems from debian: curl -O http://ftp.us.debian.org/debian/pool/main/e/eglibc/libc6-i386_2.11.3-4_amd64.deb
- Extract that package: dpkg -x libc6-i386_2.11.3-4_amd64.deb libc6-i386
- Run mksdcard with 32-bit ELF interpreter: ./libc6-i386/lib32/ld-linux.so.2 /path/to/mksdcard
One way to be able to run things like mksdcard via ./mksdcard is to patch them using patchelf installed via: nix-env -i patchelf
You can then do something like patchelf —set—interpreter /path/to/libc6-i386/lib32/ld-linux.so.2 /path/to/mksdcard
Otherwise, you may try to place symlinks to your ld-linux.so.2 in the places where ldd is telling you it expects them.
[root@nixos:/tmp]# ./libc6-i386/lib32/ld-linux.so.2 Usage: ld.so [OPTION]. EXECUTABLE-FILE [ARGS-FOR-PROGRAM. ] You have invoked `ld.so', the helper program for shared library executables. This program usually lives in the file `/lib/ld.so', and special directives in executable files using ELF shared libraries tell the system's program loader to load the helper program from this file. This helper program loads the shared libraries needed by the program executable, prepares the program to run, and runs it. You may invoke this helper program directly from the command line to load and run an ELF executable file; this is like executing that file itself, but always uses this helper program from the file you specified, instead of the helper program file specified in the executable file you run. This is mostly of use for maintainers to test new versions of this helper program; chances are you did not intend to run this program. --list list all dependencies and how they are resolved --verify verify that given object really is a dynamically linked object we can handle --library-path PATH use given PATH instead of content of the environment variable LD_LIBRARY_PATH --inhibit-rpath LIST ignore RUNPATH and RPATH information in object names in LIST --audit LIST use objects named in LIST as auditors
Thread: 32 bit compile on 64 bit, ld issue
Spilled the Beans
32 bit compile on 64 bit, ld issue
ok I’m compiling my 32 bit program on my 64 bit machine.
I was doing this in a virtual machine 32 bit environment but I’m tired of testing my kernel in Bochs IN another virtual machine.
So i used the -m32 switch for gcc and everything is working well there (I’m not using any standard library I’m turning all the pre-main stub stuff that is used to set up for a specific os work off etc etc etc).
So gcc _is_ working, I’m getting i386 object files. now over to ld, why am i using ld? because i’m also using nasm and a custom object generator tool from a custom language. _all_ object files are being outputted correctly, and link perfectly within the 32 bit environment.
when i switch to the 64 bit environment ld is not linking them together into an elf file. i’ve specified elf32_i386 as the output format with the
flag but ld just seems to be ignoring it. any hints?
-c -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -Wall -Wextra -Werror -nostartfiles -nodefaultlibs
Just to stem off the ‘are you sure your compiling to 32bit and not using standard libraries’ questions.
ld: i386 architecture of input file `x' is incompatible with i386:x86-64 output
where x is every object file.
I’m even using the highest error level because I’m a masochist
thank you for any suggestions or links to where i could possibly resolve this.
I have a feeling I’m just doing something very silly.
Last edited by addmoreice; February 17th, 2009 at 02:18 AM . Reason: cleaned up post for easier reading
Spilled the Beans
Re: 32 bit compile on 64 bit, ld issue
ok the issue is that the newest version of ld uses -melf_i386 flag to indicate file output type. even though this is not apparently mentioned in the manual (i found it in some obscure Japanese forum on using ld, ugg!)
my kernel now compiles. i now have bochs related issues to solve before i can confirm that everything worked (but it looks like it worked!)
Spilled the Beans