NixOS / patchelf

A small utility to modify the dynamic linker and RPATH of ELF executables
GNU General Public License v3.0
3.58k stars 486 forks source link

relocation error #154

Closed IronsDu closed 6 years ago

IronsDu commented 6 years ago

I use this script pach my file (complier by gcc 7.3).

Script:

#!/bin/bash -e
[ -n "$1" ] || set -- a.out
mkdir -p ./lib/ #<copy the libraries here
#use ldd to resolve the libs and use `patchelf --print-needed to filter out
# "magic" libs kernel-interfacing libs such as linux-vdso.so, ld-linux-x86-65.so or libpthread
# which you probably should not relativize anyway
join \
    <(ldd "$1" |awk '{if(substr($3,0,1)=="/") print $1,$3}' |sort) \
    <(patchelf --print-needed "$1" |sort) |cut -d\  -f2 |

#copy the lib selection to ./lib
xargs -d '\n' -I{} cp --copy-contents {} ./lib
#make the relative lib paths override the system lib path
patchelf --set-rpath "\$ORIGIN/lib" "$1"

The Dev machine info:

root@PC-201803231633:/mnt/d/dev/intellectual_talent/linux_build# gcc --version
gcc (Ubuntu 7.3.0-16ubuntu3~16.04.1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root@PC-201803231633:/mnt/d/dev/intellectual_talent/linux_build# uname -a
Linux PC-201803231633 4.4.0-17134-Microsoft #137-Microsoft Thu Jun 14 18:46:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux

But running on gcc 4.8, cause error:

relocation error: /root/il/lib/libc.so.6: symbol _dl_find_dso_for_object, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference

The target system info;

[root@VM_0_109_centos ~/il]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@VM_0_109_centos ~/il]# uname -a
Linux VM_0_109_centos 3.10.107-1-tlinux2_kvm_guest-0046 #1 SMP Wed Dec 27 10:57:04 CST 2017 x86_64 x86_64 x86_64 GNU/Linux

Can you help me?

IronsDu commented 6 years ago

[root@VM_0_109_centos ~/il]# strings ./lib/libc.so.6 | grep GLIBC GLIBC_2.2.5 GLIBC_2.2.6 GLIBC_2.3 GLIBC_2.3.2 GLIBC_2.3.3 GLIBC_2.3.4 GLIBC_2.4 GLIBC_2.5 GLIBC_2.6 GLIBC_2.7 GLIBC_2.8 GLIBC_2.9 GLIBC_2.10 GLIBC_2.11 GLIBC_2.12 GLIBC_2.13 GLIBC_2.14 GLIBC_2.15 GLIBC_2.16 GLIBC_2.17 GLIBC_2.18 GLIBC_2.22 GLIBC_2.23 GLIBC_PRIVATE GNU C Library (Ubuntu GLIBC 2.23-0ubuntu10) stable release version 2.23, by Roland McGrath et al.

IronsDu commented 6 years ago

I am running success after ·patchelf --set-interpreter ./lib/ld-linux-x86-64.so.2 ./match_server