public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ld: -rpath/-rpath_link must search under sysroot
  2012-08-23  3:12 [PATCH 0/1] ld: -rpath/-rpath_link must search under sysroot Andy Ross
@ 2012-08-22 21:41 ` Andy Ross
  2012-08-23 17:46   ` [PATCH] ld: -rpath " Andy Ross
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Ross @ 2012-08-22 21:41 UTC (permalink / raw)
  To: binutils

The -rpath and -rpath_link arguments would search the host filesystem
for libraries, even when a sysroot was defined.  For cross toolchains
with targets compatible with the host architecture this can find
incorrect libraries.

Signed-off-by: Andy Ross <andy.ross@windriver.com>
---
 ld/emultempl/elf32.em | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index de51050..79c5bca 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1257,15 +1257,23 @@ EOF
 fi
 fragment <<EOF
 
-	  if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
-						  &n, force))
-	    break;
+	  if (command_line.rpath_link) {
+	    char *tmprp = gld${EMULATION_NAME}_add_sysroot (command_line.rpath_link);
+	    found = gld${EMULATION_NAME}_search_needed (tmprp, &n, force);
+	    free(tmprp);
+	    if (found)
+	      break;
+	  }
 EOF
 if [ "x${USE_LIBPATH}" = xyes ] ; then
 fragment <<EOF
-	  if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
-						  &n, force))
-	    break;
+	  if (command_line.rpath) {
+	    char *tmprp = gld${EMULATION_NAME}_add_sysroot (command_line.rpath);
+	    found = gld${EMULATION_NAME}_search_needed (tmprp, &n, force);
+	    free(tmprp);
+	    if (found)
+	      break;
+	  }
 EOF
 fi
 if [ "x${NATIVE}" = xyes ] ; then
-- 
1.7.11.2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 0/1] ld: -rpath/-rpath_link must search under sysroot
@ 2012-08-23  3:12 Andy Ross
  2012-08-22 21:41 ` [PATCH] " Andy Ross
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Ross @ 2012-08-23  3:12 UTC (permalink / raw)
  To: binutils

This bug (basically that -rpath ignores the sysroot when modifying the
search path) came up in the context of openembedded/Yocto, where it's
fairly routine to be building with a sysroot-enabled cross toolchain
on a host architecture that matches the target.  In those
circumstances, it's possible to pick up a host library by accident and
break the build with version skew.

Andy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ld: -rpath must search under sysroot
  2012-08-22 21:41 ` [PATCH] " Andy Ross
@ 2012-08-23 17:46   ` Andy Ross
  2012-08-24  6:04     ` Andy Ross
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Ross @ 2012-08-23 17:46 UTC (permalink / raw)
  To: binutils

Resend with changes.

This reverts the -rpath-link half of the patch.  It was added for
symmetry, but of course I rapidly found a spot in the wild where
-rpath-link was being passed a relative directory inside the build
tree, so interpreting inside sysroot isn't correct per curent usage.

And of course -rpath-link never added the sysroot anyway, so anyone
using it sucessfully must already be prepending the appropriate path.
Clearly compatibility is more important.

Andy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] ld: -rpath must search under sysroot
  2012-08-23 17:46   ` [PATCH] ld: -rpath " Andy Ross
@ 2012-08-24  6:04     ` Andy Ross
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Ross @ 2012-08-24  6:04 UTC (permalink / raw)
  To: binutils

The -rpath argument would search the host filesystem for libraries,
even when a sysroot was defined.  For cross toolchains with targets
compatible with the host architecture this can find incorrect
libraries.  Leave -rpath-link unmodified, as build systems in the wild
are already using this to point to host directories.

Signed-off-by: Andy Ross <andy.ross@windriver.com>
---
 ld/emultempl/elf32.em | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index de51050..35e0e7e 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1263,9 +1263,13 @@ fragment <<EOF
 EOF
 if [ "x${USE_LIBPATH}" = xyes ] ; then
 fragment <<EOF
-	  if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
-						  &n, force))
-	    break;
+	  if (command_line.rpath) {
+	    char *tmprp = gld${EMULATION_NAME}_add_sysroot (command_line.rpath);
+	    found = gld${EMULATION_NAME}_search_needed (tmprp, &n, force);
+	    free(tmprp);
+	    if (found)
+	      break;
+	  }
 EOF
 fi
 if [ "x${NATIVE}" = xyes ] ; then
-- 
1.7.11.2

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-08-23 17:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-23  3:12 [PATCH 0/1] ld: -rpath/-rpath_link must search under sysroot Andy Ross
2012-08-22 21:41 ` [PATCH] " Andy Ross
2012-08-23 17:46   ` [PATCH] ld: -rpath " Andy Ross
2012-08-24  6:04     ` Andy Ross

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).