2

I'm running Linux on an x86_64 system. I have a Raspbian image mounted on /mnt. If I want run binaries under /mnt, I can chroot into the Rasbpian environment and the system will use qemu-arm-static to run the armhf binaries.

I can run a single binary outside of the chroot environment doing something like this:

qemu-arm -E LD_LIBRARY_PATH=/mnt/lib/arm-linux-gnueabihf/ \
  /mnt/lib/ld-linux-armhf.so.3 /mnt/bin/echo hello world

But is there a way to override the dynamic linker path (in this case, /lib/ld-linux-armhf.so.3) such that the first process can start additional arm binaries? For example, starting a shell works fine:

outside$ qemu-arm -E LD_LIBRARY_PATH=/mnt/lib/arm-linux-gnueabihf/ \
  -E PATH=/mnt/bin:/mnt/usr/bin \
  /mnt/lib/ld-linux-armhf.so.3 /mnt/bin/sh
$ echo hello world
hello world

But trying to spawn another binary fails:

$ ls
/lib/ld-linux-armhf.so.3: No such file or directory

Can I convince the kernel to find the dynamic linker (for arm binaries) in /mnt/lib/ld-linux-armhf.so.3 without running in a chroot'd environment?

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Hmm, there is some interesting discussion on this topic [over here](https://stackoverflow.com/questions/847179/multiple-glibc-libraries-on-a-single-host), and it looks like the answer is "no, you can't do that". In fact, I think I'm going to close this as a duplicate of that one. – larsks Dec 04 '17 at 01:20
  • That other question is about running a program natively, where indeed it isn't all that easy to do that. For QEMU, you can use the QEMU_LD_PREFIX environment variable to specify a directory where guest file operations should look first, which will include where the dynamic linker is looked for. The catch is that a long-standing bug in QEMU means that right now if you point -L at a full chroot directory it will hang, because it can't cope with symlinks in the directory. But it will work for a restricted sysroot setup. – Peter Maydell Dec 04 '17 at 11:30
  • I had actually started fiddling with `-L` before posting this question, but as you say, for this particular purpose (in which I have mounted a complete OS image) it simply doesn't work...which makes the solution here just another "how I run multiple glibcs" question. Is there an existing bug report for the `QEMU_LD_PREFIX` issue with symlinks? – larsks Dec 04 '17 at 13:25
  • https://bugs.launchpad.net/qemu/+bug/1245703 (there's a link at the bottom to a patch which has a plan for fixing it, though that patch has some issues) – Peter Maydell Dec 04 '17 at 14:49
  • Thanks! He said, adding words to make stackoverflow happy... – larsks Dec 04 '17 at 14:51

0 Answers0