[elbe-devel] [PATCH 7/8] makofiles toolchain-shar-extract.sh.mako: improve the relocation code
Torben Hohn
torben.hohn at linutronix.de
Tue May 14 14:29:03 CEST 2019
there is no distinction between target and native executables made.
All executables were patched with the native interpreter and x86_64
specific rpaths.
The relocation code also only handles executables and does not set the
rpath of shared objects.
Fix that by building lists of native_executables, native_elf_files (exes
and shared objects), and target_elf_files.
For elf files the rpath is setup, and executables also get the interpreter
setup.
The code also handles ld scripts like libpthread.so and libc6.so which
are relocated using "sed -i".
target_executable_files are not supported yet, because they need the
target ld-linux.so to exist. However, this case can not happen yet,
because the host sysroot can not be multiarch, yet.
Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
elbepack/makofiles/toolchain-shar-extract.sh.mako | 49 +++++++++++++++++++++--
1 file changed, 45 insertions(+), 4 deletions(-)
diff --git a/elbepack/makofiles/toolchain-shar-extract.sh.mako b/elbepack/makofiles/toolchain-shar-extract.sh.mako
index 9384591a2..01a4dfaac 100644
--- a/elbepack/makofiles/toolchain-shar-extract.sh.mako
+++ b/elbepack/makofiles/toolchain-shar-extract.sh.mako
@@ -287,12 +287,29 @@ if [ "$dl_path" = "" ] ; then
echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!"
exit 1
fi
-executable_files=$($SUDO_EXEC find $native_sysroot -type f \
+native_executable_files=$($SUDO_EXEC find $native_sysroot -type f \
\( -perm -0100 -o -perm -0010 -o -perm -0001 \) \
- -exec sh -c "file {} | grep -Pi ': elf (32|64)-bit' > /dev/null" \; \
+ -exec sh -c "file {} | grep -P ': ELF 64-bit LSB (shared object|pie executable|executable), x86-64, .*, interpreter' > /dev/null" \; \
-printf "'%h/%f' ")
-if [ "x$executable_files" = "x" ]; then
+native_elf_files=$($SUDO_EXEC find $native_sysroot -type f \
+ -exec sh -c "file {} | grep -P ': ELF 64-bit LSB (shared object|pie executable|executable), x86-64' > /dev/null" \; \
+ -printf "'%h/%f' ")
+
+target_executable_files=$($SUDO_EXEC find $native_sysroot -type f \
+ \( -perm -0100 -o -perm -0010 -o -perm -0001 \) \
+ -exec sh -c "file {} | grep -P ': ELF (64|32)-bit LSB (shared object|pie executable|executable), ${target_elfcode}, .*, interpreter' > /dev/null" \; \
+ -printf "'%h/%f' ")
+
+target_elf_files=$($SUDO_EXEC find $native_sysroot -type f \
+ -exec sh -c "file {} | grep -P ': ELF (64|32)-bit LSB (shared object|pie executable|executable), ${target_elfcode},' > /dev/null" \; \
+ -printf "'%h/%f' ")
+
+ascii_so_files=$($SUDO_EXEC find $native_sysroot -type f -name "*.so" \
+ -exec sh -c "file {} | grep -P ': ASCII text' > /dev/null" \; \
+ -printf "'%h/%f' ")
+
+if [ "x$native_executable_files" = "x" ]; then
echo "SDK relocate failed, could not get executalbe files"
exit 1
fi
@@ -312,14 +329,38 @@ if [ x\$PATCHELF = "x" ]; then
exit 1
fi
-for exe in $executable_files; do
+for exe in $native_executable_files; do
if [ \`readlink -f \$exe\` == \`readlink -f $dl_path\` ]; then
echo SKIP \$exe
else
\$PATCHELF --set-interpreter $dl_path \$exe
+ fi
+done
+
+for exe in $native_elf_files; do
+ if [ \`readlink -f \$exe\` == \`readlink -f $dl_path\` ]; then
+ echo SKIP \$exe
+ else
\$PATCHELF --set-rpath $native_sysroot/usr/lib/x86_64-linux-gnu:$native_sysroot/lib/x86_64-linux-gnu/:$native_sysroot/usr/lib:$native_sysroot/lib \$exe
fi
done
+
+# TODO: target_executable files do not exist yet,
+# to handle these we would need proper identification
+# of the target interpreter.
+#
+# the difference to the native interpreter is, that the
+# target interpreter does not necessarily exist.
+#
+# do not skip the interpreter, and do not handle target_executable
+# files yet.
+for exe in $target_elf_files; do
+ \$PATCHELF --set-rpath $native_sysroot/usr/lib/${real_multimach_target_sys}/:$native_sysroot/lib/${real_multimach_target_sys}/:$native_sysroot/usr/lib:$native_sysroot/lib \$exe
+done
+
+for exe in $ascii_so_files; do
+ sed -i "s%/usr/%$native_sysroot/usr/%g" \$exe
+done
EOF
$SUDO_EXEC mv $tdir/relocate_sdk.sh ${"$"}{env_setup_script%/*}/relocate_sdk.sh
--
2.11.0
More information about the elbe-devel
mailing list