patchelf to change ld-linux-xxx with new glibc on old system/Centos7-RHEL7.x

####### patchelf
##  Change ld-linux-XXXX.so
###  Change  with new glibc version 

[lake@Centos7 hello]$ pwd
/home/lake/extra/source/hello

### Centos7/RHEL7.x glibc is 2.17 NOT 2.18/2.19 
[lake@Centos7 hello]$ rpm -qf  /lib64/libc.so.6
glibc-2.17-78.el7.x86_64
[lake@Centos7 hello]$


[lake@Centos7 hello]$ gcc hello.c

[lake@Centos7 hello]$ ldd a.out
        linux-vdso.so.1 =>  (0x00007ffe6399b000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fed54155000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fed54548000)  
[lake@Centos7 hello]$ ls -l
total 4796
-rwxr-xr-x 1 lake lake    8551 Jan 21 16:30 a.out 
-rw-r--r-- 1 lake lake      84 Jul  7  2020 hello.c 
lrwxrwxrwx 1 lake lake      35 Jan 21 16:33 x86_64-linux-glibc2.19-4.8  
[lake@Centos7 hello]$ pwd
/home/lake/extra/source/hello
[lake@Centos7 hello]$ gcc  hello.c   -Wl,--rpath="/home/lake/extra/source/hello/x86_64-linux-glibc2.19-4.8/sysroot/usr/lib/:/home/lake/extra/source/hello/x86_64-linux-glibc2.19-4.8/x86_64-linux/lib64"    -Wl,--dynamic-linker=/home/lake/extra/source/hello/x86_64-linux-glibc2.19-4.8/sysroot/usr/lib/ld-linux-x86-64.so.2
[lake@Centos7 hello]$ ldd  a.out
        linux-vdso.so.1 =>  (0x00007ffec99d0000)
        libc.so.6 => /home/lake/extra/source/hello/x86_64-linux-glibc2.19-4.8/sysroot/usr/lib/libc.so.6 (0x00007fc506956000)
        /home/lake/extra/source/hello/x86_64-linux-glibc2.19-4.8/sysroot/usr/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007fc506d1d000)
[lake@Centos7 hello]$ ./a.out
Hello world 
[lake@Centos7 hello]$












[lake@Centos7 hello]$ gcc hello.c

[lake@Centos7 hello]$ cp ../others_tools/patchelf  .
[lake@Centos7 hello]$ ls
a.out   hello.c   patchelf  x86_64-linux-glibc2.19-4.8 
[lake@Centos7 hello]$ pwd
/home/lake/extra/source/hello
[lake@Centos7 hello]$ ls -l
total 4928
-rwxr-xr-x 1 lake lake   12647 Jan 21 16:41 a.out
-rw-r--r-- 1 lake lake      84 Jul  7  2020 hello.c
-rwxr-xr-x 1 lake lake  128776 Jan 21 16:38 patchelf
lrwxrwxrwx 1 lake lake      35 Jan 21 16:33 x86_64-linux-glibc2.19-4.8  
[lake@Centos7 hello]$


[lake@Centos7 hello]$ ldd  a.out
        linux-vdso.so.1 =>  (0x00007ffc386da000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f9929bf2000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f9929fe5000)


[lake@Centos7 hello]$ ./patchelf    --set-interpreter  /home/lake/extra/source/hello/x86_64-linux-glibc2.19-4.8/sysroot/usr/lib/ld-linux-x86-64.so.2   ./a.out
[lake@Centos7 hello]$ ldd  a.out
        linux-vdso.so.1 =>  (0x00007fff873fe000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f9f8ae45000)
        /home/lake/extra/source/hello/x86_64-linux-glibc2.19-4.8/sysroot/usr/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f9f8b238000)
[lake@Centos7 hello]$ ./a.out
./a.out: relocation error: /lib64/libc.so.6: symbol _dl_starting_up, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference
[lake@Centos7 hello]$ ./patchelf   --set-rpath   "/home/lake/extra/source/hello/x86_64-linux-glibc2.19-4.8/sysroot/usr/lib/:/home/lake/extra/source/hello/x86_64-linux-glibc2.19-4.8/x86_64-linux/lib64"    ./a.out
[lake@Centos7 hello]$ ldd  a.out
        linux-vdso.so.1 =>  (0x00007ffe05150000)
        libc.so.6 => /home/lake/extra/source/hello/x86_64-linux-glibc2.19-4.8/sysroot/usr/lib/libc.so.6 (0x00007f700effc000)
        /home/lake/extra/source/hello/x86_64-linux-glibc2.19-4.8/sysroot/usr/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f700f3c3000)
[lake@Centos7 hello]$ ./a.out
Hello world 
[lake@Centos7 hello]$

猜你喜欢

转载自blog.csdn.net/hushui/article/details/112966663
old