Reputation: 649
On Arch-Linux when linking an object file with ld
to a dynamically linked ELF executable, it uses /lib/ld64.so.1
as the default dynamic linker. However, my dynamic linker is /lib/ld-2.26.so
from Glibc.
I know, that I can specify the dynamic linker to ld
with the --dynamic-linker
option, but how can I ensure, that when compiling for other Linux distributions, the correct dynamic linker is found. In other words: how can I find the correct name of the dynamic linker on Linux?
Upvotes: 0
Views: 844
Reputation: 364180
Link with gcc -nostartfiles
or gcc -nostdlib
instead of using ld
directly.
(With -no-pie
or -pie
if you want to make that choice explicit).
The system gcc knows the right path for the ELF interpreter.
Or to find out what the right path is, file /bin/ls
and parse the output. On my Arch Linux system, it includes ... dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2,
Other programs include readelf -p /bin/ls
, and ldd /bin/ls
also includes the right path.
(But note that ldd
includes the right path even if you use it on an ELF executable that has the wrong path; /bin/ldd
is a shell script that works by running the ELF interpreter on an executable with special args, so the shell script contains paths to try, and the runtime dynamic linker doesn't look for itself because it's already running. You can use file
or readelf -a
to inspect executables to check for the right path, but not ldd
.)
Upvotes: 1