Using LD_PRELOAD mixed 64bit/32bit environment in Linux
By specifying full path to the library, you don't let dynamic linker to adjust it's search path according to binaries architecture. Define only library name and let linker to pick the correct library for you. E.g.:
$ LD_PRELOAD=lib_init.so ./hello32
will search for lib_init.so in /lib, while
$ LD_PRELOAD=lib_init.so ./hello64
will search in /lib64
How to apply LD_PRELOAD only to target program?
It looks like you can set QEMU_SET_ENV=LD_PRELOAD=./malloc.so
in the environment to affect the process.
I'll note that you can similarly unset environment variables for the target by setting QEMU_UNSET_ENV=FOO,BAR
.
How does LD_PRELOAD='/something/$LIB/libmyx.so' myprogram expand under different conditions?
$LIB
documentation from ld.so
man:
https://man7.org/linux/man-pages/man8/ld.so.8.html
$LIB (or equivalently ${LIB})
This expands to lib or lib64 depending on the architecture
(e.g., on x86-64, it expands to lib64 and on x86-32, it
expands to lib).
This is not completely true and actual values can be different. E.g. you are running a nativesdk binary from OpenEmbedded SDK. As you've noticed the SDK uses its own ld.so
. That ld.so
is not configured for multilib support and it expects to have only one lib
directory with 64-bit libraries. That's why it resolves $LIB
to lib
.
You can see default library directory definition (BASELIB
) here:
http://git.openembedded.org/openembedded-core/tree/meta/conf/bitbake.conf#n12
Using 32bit .lib library in a 64bit application
You don't have any other alternative; you cannot load a 32-bit assembly in a 64-bit program, so you'll need to create a 32 bit application that your 64 bit application can talk to somehow. There are lots of ways to do IPC, so find one that works for you.
How is linux simultaneously 32bit and 64bit? Or is that something handled in glibc?
The cpu can execute both 64 and 32bit instructions and the kernel can switch between modes. The only limitation is that you cannot link 32bit programs against 64bit libraries so you must have both 32 and 64bit versions of libc, etc. installed.
Related Topics
Gcc: Putchar(Char) in Inline Assembly
Boost with Qt Creator and Linux
Merge Files with Bash by Primary Key
Emulating Slurm on Ubuntu 16.04
Connect to Host Localhost Port 22: Connection Refused
How to Diff Directories Over Ssh
What's the Difference Between "Env" and "Set" (On MAC Os X or Linux)
Exclude All Permission Denied Messages from "Du"
Buffered Asynchronous File I/O on Linux
How to Stop a Running R Command in Linux Other Than with Ctrl + C
Git Sparse-Checkout Ignore Specific File Type
Is Stack Memory Contiguous Physically in Linux
Gdb: Redirect Target Stdout Temporarly
Determining the Path That a Yum Package Installed To
Does Os X Have an Equivalent to /Dev/Shm
Postgresql Won't Start: "Server.Key" Has Group or World Access