Skip to content

Commit

Permalink
Fixes #14515: Relink aix binaries with absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
peckpeck committed Mar 21, 2019
1 parent 251ebf6 commit ec68c63
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rudder-agent/SOURCES/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ endif

# Strip binaries
ifeq (aix,$(OS_FAMILY))
# find $(DESTDIR) -type f | xargs file | grep -E "executable|shared object" | cut -f 1 -d : | xargs strip 2> /dev/null || true
./absolute-aix-path $(DESTDIR)
find $(DESTDIR) -type f | xargs file | grep -E "executable|shared object" | cut -f 1 -d : | xargs strip 2> /dev/null || true
echo done
else
find $(DESTDIR) -type f -print0 | xargs -0 file | grep -E "executable|shared object" | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
Expand Down
49 changes: 49 additions & 0 deletions rudder-agent/SOURCES/absolute-aix-path
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

set -e

# relink all binaries from a given directory to use abslute library path for rudder embedded libraries
dir="$1"
if [ "${dir}" = "" ]
then
echo "Usage $0 <rudder directory>"
exit 1
fi

# force ldd to load proper libraries
export LIBPATH="${dir}/lib:/usr/lib:/lib"

# point real /opt/rudder/lib to $dir
if [ -e "/opt/ruder/lib" ]
then
echo "Rudder must no be installed on this machine"
exit 1
fi
mkdir -p /opt/rudder
ln -s "${dir}" /opt/rudder/lib

# list unstripped binaries
files=$(for i in ${dir}/bin/*; do file $i; done | grep "executable.*not stripped" | sed 's/:.*//')

# list binaries wth rudder dependencies
binaries=$(for f in ${files}
do
if ldd "${f}" | grep ${dir}/lib > /dev/null
then
echo "${f}"
fi
done)

for f in ${binaries}
do
echo $f
dest=$(mktemp)
# extract rudder dependencies with full path to final destination
path=$(ldd "${f}" | grep " ${dir}/lib" | sed 's/(.*//' | sort -u | sed "s|${dir}|/opt/rudder/|")
# extract other dependencies with library name
lib=$(ldd "${f}" | grep -e " /usr/lib/lib" -e " /lib/lib" | sed 's|.*/lib/lib\([^.]*\).*|-l\1|' | sort -u)
# relink with static paths and proper libpath (just in case)
ld -bipath -bsvr4 -blibpath:/opt/rudder/bin:/urs/lib:/lib ${lib} -o "${dest}" "${f}" ${path} && mv "${dest}" "${f}"
done

rm /opt/rudder/lib

0 comments on commit ec68c63

Please sign in to comment.