Why do I get different results when running a program with ld-linux.so and when changing the interpreter with patchelf?
-1
votes
1
answer
305
views
What's the difference between running a program with ld + --library-path
and with changing the loader with patchelf?
To illustrate, here is a binary that wouldn't run as is, presumably because of lack of recent versions of libraries:
$ ~/DOWNLOADS/APPS/magick
/tmp/.mount_magickXiWzgy/usr/bin/magick: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /tmp/.mount_magickXiWzgy/usr/lib/libMagickCore-7.Q16HDRI.so.10)
/tmp/.mount_magickXiWzgy/usr/bin/magick: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by /tmp/.mount_magickXiWzgy/usr/lib/libMagickCore-7.Q16HDRI.so.10)
/tmp/.mount_magickXiWzgy/usr/bin/magick: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /tmp/.mount_magickXiWzgy/usr/lib/liblcms2.so.2)
...
$
I tried to run it with 3 other loaders and library paths, (core18, core20 and core22). Got ELF file ABI version invalid each time.
$ /snap/core18/current/lib64/ld-linux-x86-64.so.2 --library-path /snap/core18/current/usr/lib/x86_64-linux-gnu/ ~/DOWNLOADS/APPS/magick
/home/ychaouche/DOWNLOADS/APPS/magick: error while loading shared libraries: /home/ychaouche/DOWNLOADS/APPS/magick: ELF file ABI version invalid
$ /snap/core20/current/lib64/ld-linux-x86-64.so.2 --library-path /snap/core20/current/usr/lib/x86_64-linux-gnu/ ~/DOWNLOADS/APPS/magick
/home/ychaouche/DOWNLOADS/APPS/magick: error while loading shared libraries: /home/ychaouche/DOWNLOADS/APPS/magick: ELF file ABI version invalid
$ /snap/core22/current/lib64/ld-linux-x86-64.so.2 --library-path /snap/core22/current/usr/lib/x86_64-linux-gnu/ ~/DOWNLOADS/APPS/magick
/home/ychaouche/DOWNLOADS/APPS/magick: error while loading shared libraries: /home/ychaouche/DOWNLOADS/APPS/magick: ELF file ABI version invalid
$
Then got a Segmentation fault when I tried to run it after changing the loader and the rpath directly in the binary with patchelf,
like so:
$ patchelf --set-interpreter /snap/core18/current/lib64/ld-linux-x86-64.so.2 --set-rpath /snap/core18/current/usr/lib/x86_64-linux-gnu/ magick
$ ./magick
Segmentation fault
$ ldd magick
not a dynamic executable
$
even ldd fails to recognize it as a dynamic executable, although readelf can read it.
here's output of ldd as requested by @user10489
$ file DOWNLOADS/APPS/magick
DOWNLOADS/APPS/magick: ELF 64-bit LSB executable, x86-64, version 1, dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=9fdbc145689e0fb79cb7291203431012ae8e1911, stripped
$
My question is why do I have ELF file ABI version invalid when specifying the loader from the command line, and a segmentation fault when changing the loader (and rpath) inside the binary?
Asked by ychaouche
(1033 rep)
Jan 4, 2024, 03:42 PM
Last activity: Jan 8, 2024, 04:06 PM
Last activity: Jan 8, 2024, 04:06 PM