Comment 9 for bug 1701798

Revision history for this message
Bruno Haible (bruno-clisp) wrote :

Re #4:
> 2) files like /etc/ld.so.cache (and other things the dynamic linker uses) are not in the -L directory but are in the host
> 3) the ld.so.cache format is not endian-agnostic
> 4) glibc's dynamic linker code does not ignore a wrong-endian ld.so.cache but crashes instead

Indeed the problem is with /etc/ld.so.cache, and ONLY /etc/ld.so.cache. When I hack the do_openat function in linux-user/syscall.c, to pretend that no /etc/ld.so.cache exists, - see attached hide-ld.so.cache.diff - the dynamically-linked binaries work (except the s390x case, which you identified as a different issue):

$ QEMU_LD_PREFIX=/usr/sparc64-linux-gnu ~/inst-qemu/2.10+-20171107/bin/qemu-sparc64 hello.sparc64
Hello world
$ QEMU_LD_PREFIX=/usr/mips-linux-gnu ~/inst-qemu/2.10+-20171107/bin/qemu-mips hello.mips
Hello world
$ QEMU_LD_PREFIX=/usr/mips64-linux-gnuabi64 ~/inst-qemu/2.10+-20171107/bin/qemu-mips64 hello.mips64
Hello world
$ QEMU_LD_PREFIX=/usr/powerpc-linux-gnu ~/inst-qemu/2.10+-20171107/bin/qemu-ppc hello.powerpc
Hello world
$ QEMU_LD_PREFIX=/usr/powerpc64-linux-gnu ~/inst-qemu/2.10+-20171107/bin/qemu-ppc64 hello.powerpc64
Hello world
$ QEMU_LD_PREFIX=/usr/s390x-linux-gnu ~/inst-qemu/2.10+-20171107/bin/qemu-s390x hello.s390x
Killed
$ QEMU_LD_PREFIX=/usr/hppa-linux-gnu ~/inst-qemu/2.10+-20171107/bin/qemu-hppa hello.hppa
Hello world
$ QEMU_LD_PREFIX=/usr/m68k-linux-gnu QEMU_CPU=m68020 ~/inst-qemu/2.10+-20171107/bin/qemu-m68k hello.m68k
Hello world

Hurray! This bug that has seriously limited the value of linux-user emulation is now gone for me!

> Can you check whether these work if you copy the QEMU and the dynamically linked target binary into a chroot

This is way too cumbersome for me:
  - Need to copy my workspaces into specific file locations on the disk,
  - Need to use 'chroot' command before anything else,
  - Need to use a statically-linked qemu.

> Personally I think that (4) is a glibc bug...

Maybe, but if you can fix it in 5 to 10 lines code in qemu, I doubt it's worth reporting it to the glibc people.

Small improvement: In my hack, I just pretended /etc/ld.so.cache is absent. Possibly it's better to map it to $QEMU_LD_PREFIX/etc/ld.so.cache .