forked from foss-for-synopsys-dwc-arc-processors/toolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrel-rpaths.sh
executable file
·71 lines (56 loc) · 2.04 KB
/
rel-rpaths.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
# Script to set RPATHs to be relative in shared binaries
# Copyright (C) 2012-2016 Synopsys Inc.
# Contributor Simon Cook <[email protected]>
# Contributor Anton Kolesov <[email protected]>
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
# This should be run in the INSTALL directory, so there should be a bin
# subdirectory.
REPLACEDIR=$1
cd ${REPLACEDIR}
# Get a suitable SED
if [ x`uname -s` = "xDarwin" ]
then
# You can install gsed with 'brew install gnu-sed'
SED=gsed
else
SED=sed
fi
if ! [ -d bin ]; then
echo "\`$REPLACEDIR' is not a toolchain installation directory."
exit 1
fi
# We need patchelf for this to install
which patchelf > /dev/null 2>&1
if [ $? -gt 0 ]; then
echo "patchelf needs to be installed"
exit 1
fi
# Get list of x86/x86_64 executables
files=$(find -type f -exec file {} \; | \
grep -e 'ELF 32-bit LSB executable, Intel 80386' \
-e 'ELF 64-bit LSB\s*executable, x86-64' \
-e 'ELF 64-bit LSB executable, AMD x86-64' | \
${SED} -e 's/:.*$//')
for f in $files; do
echo $f
RPATH=$(readelf -d "${f}" | grep 'Library rpath\|Library runpath')
# If no RPATH, continue
if [ $? -gt 0 ]; then
continue
fi
# Build a relative directory
RELDIR=`echo ${f#./} | ${SED} -e 's#[^/]##g' | ${SED} -e 's#/#/..#g'`
RPATH=$(echo "${RPATH}" | ${SED} "s#.*\[${REPLACEDIR}\(.*\)\]#\$ORIGIN${RELDIR}\1#")
patchelf --set-rpath "${RPATH}" ${f}
done
# vim: noexpandtab sts=4 ts=8: