binutils: apply RPATH fixes from our libtool patches

We don't autoreconf/libtoolize binutils as it has very strict requirements, so
extend our patching of the stock libtool to include two fixes to RPATH
behaviour, as part of the solution to ensure that native binaries don't have
RPATHs pointing at the host system's /usr/lib.

This generally doesn't cause a problem but it can cause some binaries (such as
ar) to abort on startup:

./x86_64-pokysdk-linux-ar: relocation error: /usr/lib/libc.so.6: symbol
_dl_starting_up, version GLIBC_PRIVATE not defined in file ld-linux.so.2 with
link time reference

The situation here is that ar is built and as it links to the host libc/loader
has an RPATH for /usr/lib.  If tmp is wiped and then binutils is installed from
sstate relocation occurs and the loader changed to the sysroot, but there
remains a RPATH for /usr/lib.  This means that the sysroot loader is used with
the host libc, which can be incompatible.  By telling libtool that the host
library paths are in the default search path, and ensuring that all default
search paths are not added as RPATHs by libtool, the result is a binary that
links to what it should be linking to and nothing else.

[ YOCTO #9287 ]

(From OE-Core rev: 6b201081b622cc083cc2b1a8ad99d6f7d2bea480)

Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ross Burton 2016-10-03 15:16:32 +01:00 committed by Richard Purdie
parent 55e8c3a9f9
commit 0c9ba38d92
2 changed files with 101 additions and 0 deletions

View File

@ -33,6 +33,7 @@ SRC_URI = "\
file://0011-Change-default-emulation-for-mips64-linux.patch \
file://0012-Add-support-for-Netlogic-XLP.patch \
file://0013-fix-the-incorrect-assembling-for-ppc-wait-mnemonic.patch \
file://0014-libtool-remove-rpath.patch \
"
S = "${WORKDIR}/git"

View File

@ -0,0 +1,100 @@
Apply these patches from our libtool patches as not only are redundant RPATHs a
waste of space but they can cause incorrect linking when native packages are
restored from sstate.
fix-rpath.patch:
We don't want to add RPATHS which match default linker
search paths, they're a waste of space. This patch
filters libtools list and removes the ones we don't need.
norm-rpath.patch:
Libtool may be passed link paths of the form "/usr/lib/../lib", which
fool its detection code into thinking it should be included as an
RPATH in the generated binary. Normalize before comparision.
Upstream-Status: Inappropriate
Signed-off-by: Ross Burton <ross.burton@intel.com>
diff --git a/ltmain.sh b/ltmain.sh
index 683317c..860a16a 100644
--- a/ltmain.sh
+++ b/ltmain.sh
@@ -8053,8 +8053,14 @@ EOF
esac
fi
else
- eval flag=\"$hardcode_libdir_flag_spec\"
- func_append dep_rpath " $flag"
+ # We only want to hardcode in an rpath if it isn't in the
+ # default dlsearch path.
+ case " $sys_lib_dlsearch_path " in
+ *" $libdir "*) ;;
+ *) eval flag=\"$hardcode_libdir_flag_spec\"
+ func_append dep_rpath " $flag"
+ ;;
+ esac
fi
elif test -n "$runpath_var"; then
case "$perm_rpath " in
@@ -8790,8 +8796,14 @@ EOF
esac
fi
else
- eval flag=\"$hardcode_libdir_flag_spec\"
- func_append rpath " $flag"
+ # We only want to hardcode in an rpath if it isn't in the
+ # default dlsearch path.
+ case " $sys_lib_dlsearch_path " in
+ *" $libdir "*) ;;
+ *) eval flag=\"$hardcode_libdir_flag_spec\"
+ rpath+=" $flag"
+ ;;
+ esac
fi
elif test -n "$runpath_var"; then
case "$perm_rpath " in
@@ -8841,8 +8853,14 @@ EOF
esac
fi
else
- eval flag=\"$hardcode_libdir_flag_spec\"
- func_append rpath " $flag"
+ # We only want to hardcode in an rpath if it isn't in the
+ # default dlsearch path.
+ case " $sys_lib_dlsearch_path " in
+ *" $libdir "*) ;;
+ *) eval flag=\"$hardcode_libdir_flag_spec\"
+ func_append rpath " $flag"
+ ;;
+ esac
fi
elif test -n "$runpath_var"; then
case "$finalize_perm_rpath " in
diff --git a/ltmain.sh b/ltmain.sh
index 683317c..860a16a 100644
--- a/ltmain.sh
+++ b/ltmain.sh
@@ -8055,8 +8055,10 @@ EOF
else
# We only want to hardcode in an rpath if it isn't in the
# default dlsearch path.
+ func_normal_abspath "$libdir"
+ libdir_norm=$func_normal_abspath_result
case " $sys_lib_dlsearch_path " in
- *" $libdir "*) ;;
+ *" $libdir_norm "*) ;;
*) eval flag=\"$hardcode_libdir_flag_spec\"
func_append dep_rpath " $flag"
;;
@@ -8798,8 +8800,10 @@ EOF
else
# We only want to hardcode in an rpath if it isn't in the
# default dlsearch path.
+ func_normal_abspath "$libdir"
+ libdir_norm=$func_normal_abspath_result
case " $sys_lib_dlsearch_path " in
- *" $libdir "*) ;;
+ *" $libdir_norm "*) ;;
*) eval flag=\"$hardcode_libdir_flag_spec\"
rpath+=" $flag"
;;