misc: Use RPATH to avoid having tests to set LD_LIBRARY_PATH

Instead of each binary launcher having to check if there is a lib/
directory and then setting a LD_LIBRARY_PATH we can use an RPATH and
know these binaries pick-up the right libraries.

This requires I6e4ad2e3855af7bcefc22d4190cc4e6f58581857.

Change-Id: If771767dd82662e13b6b10ee7a8b8d0c84dcbdb1
This commit is contained in:
Holger Hans Peter Freyther 2018-11-04 14:43:17 +00:00 committed by Holger Freyther
parent b656432701
commit 9cf1c8afde
1 changed files with 26 additions and 0 deletions

View File

@ -175,6 +175,31 @@ prune_files() {
done
}
add_rpath() {
# Adds an RPATH to executables in bin/ or sbin/ to search for the
# (Osmocom) libraries in `dirname /proc/self/exe`/../lib/. Adds an
# RPATH to a library to search in the same directory as the library.
#
# NOTE: Binaries should not have the SUID bit set and should run as the
# user executing the binary.
#
# NOTE: $ORIGIN is not a shell variable but a feature of the dynamic
# linker that will be expanded at runtime. For details see:
# http://man7.org/linux/man-pages/man8/ld.so.8.html
#
# Add an rpath relative to the binary and library if the directory
# exists.
if [ -d bin/ ]; then
find bin -depth -type f -exec patchelf --set-rpath '$ORIGIN/../lib/' {} \;
fi
if [ -d sbin/ ]; then
find sbin -depth -type f -exec patchelf --set-rpath '$ORIGIN/../lib/' {} \;
fi
if [ -d lib/ ]; then
find lib -depth -type f -name "lib*.so.*" -exec patchelf --set-rpath '$ORIGIN/' {} \;
fi
}
create_bin_tgz() {
# build the archive that is going to be copied to the tester
@ -190,6 +215,7 @@ create_bin_tgz() {
prune_files sbin "$wanted_binaries_sbin"
cd "$prefix_real"
add_rpath
this="$name.build-${BUILD_NUMBER-$(date +%Y-%m-%d_%H_%M_%S)}"
tar="${this}.tgz"
tar czf "$base/$tar" *