[PATCH] fine control sysroot runtime behavior

Benda Xu heroxbd@gentoo.org
Mon Dec 1 10:07:00 GMT 2014


This is a rebase of patch submitted in

  http://article.gmane.org/gmane.comp.gnu.binutils/63137

to the HEAD of git repository.

The feature sysroot originally for cross compiling has two parts. The
first is to prepend lib path, done in configure phase, which we call
"configure-time sysroot". The second is to prepend rpath in libraries
and path inside ld scripts when ld is called, which we call "runtime
sysroot".

In case of cross compilation, both are needed.  While in case
of native sysroot, which runs userland in a directory prefix natively,
only configure-time sysroot is needed.

Here we add an additional option of --enable-runtime-sysroot to fine
control such features.
---
 ChangeLog             | 10 ++++++++++
 ld/configure.ac       | 12 ++++++++++++
 ld/emultempl/elf32.em | 10 +++++++++-
 ld/ld.texinfo         | 19 ++++++++++---------
 ld/ldfile.c           |  4 ++++
 5 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 381f255..b393fe2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2014-12-01  Benda Xu  <heroxbd@gentoo.org>
+
+        * ld/configure.ac: add enable-runtime-sysroot to control the
+        macro ENABLE_RUNTIME_SYSROOT
+        * ld/emultempl/elf32.em: only prepend rpath with sysroot when
+        ENABLE_RUNTIME_SYSROOT is defined
+        * ld/ldfile.c: only prepend lib path with sysroot when
+        ENABLE_RUNTIME_SYSROOT is defined
+        * ld/ld.texinfo: document this new behavior for ld script
+
 2014-11-24  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* libtool.m4: Updated from GCC trunk.
diff --git a/ld/configure.ac b/ld/configure.ac
index 1bddfc9..9ff7f2f 100644
--- a/ld/configure.ac
+++ b/ld/configure.ac
@@ -94,6 +94,18 @@ AC_SUBST(use_sysroot)
 AC_SUBST(TARGET_SYSTEM_ROOT)
 AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
 
+AC_ARG_ENABLE(runtime-sysroot,
+[AS_HELP_STRING([--enable-runtime-sysroot],
+		 [prepend sysroot to libpath in ld script and rpath,
+                 only used in addition to --with-sysroot (default is yes)])],
+[case "${enableval}" in
+  no) ;;
+  *) AC_DEFINE(ENABLE_RUNTIME_SYSROOT, [], \
+               [prepend sysroot to libpath in ld script and rpath]) ;;
+esac],
+AC_DEFINE(ENABLE_RUNTIME_SYSROOT, [], \
+          [prepend sysroot to libpath in ld script and rpath]))
+
 dnl Use --enable-gold to decide if this linker should be the default.
 dnl "install_as_default" is set to false if gold is the default linker.
 dnl "installed_linker" is the installed BFD linker name.
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 137446f..fe5e58b 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -526,7 +526,10 @@ static char *
 gld${EMULATION_NAME}_add_sysroot (const char *path)
 {
   int len, colons, i;
-  char *ret, *p;
+  char *ret;
+
+#ifdef ENABLE_RUNTIME_SYSROOT
+  char *p;
 
   len = strlen (path);
   colons = 0;
@@ -554,6 +557,11 @@ gld${EMULATION_NAME}_add_sysroot (const char *path)
       *p++ = path[i++];
 
   *p = 0;
+#else
+  ret = xmalloc (strlen (path) + 1);
+  strcpy (ret, path);
+#endif
+
   return ret;
 }
 
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 502582c..4ff99c9 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -3141,15 +3141,16 @@ then you can put @samp{INPUT (subr.o)} in your linker script.
 In fact, if you like, you can list all of your input files in the linker
 script, and then invoke the linker with nothing but a @samp{-T} option.
 
-In case a @dfn{sysroot prefix} is configured, and the filename starts
-with the @samp{/} character, and the script being processed was
-located inside the @dfn{sysroot prefix}, the filename will be looked
-for in the @dfn{sysroot prefix}.  Otherwise, the linker will try to
-open the file in the current directory.  If it is not found, the
-linker will search through the archive library search path.
-The @dfn{sysroot prefix} can also be forced by specifying @code{=}
-as the first character in the filename path.  See also the
-description of @samp{-L} in @ref{Options,,Command Line Options}.
+In case a @dfn{sysroot prefix} is configured without explict
+--disable-runtime-sysroot, and the filename starts with the @samp{/}
+character, and the script being processed was located inside the
+@dfn{sysroot prefix}, the filename will be looked for in the
+@dfn{sysroot prefix}.  Otherwise, the linker will try to open the file
+in the current directory.  If it is not found, the linker will search
+through the archive library search path.  The @dfn{sysroot prefix} can
+also be forced by specifying @code{=} as the first character in the
+filename path.  See also the description of @samp{-L} in
+@ref{Options,,Command Line Options}.
 
 If you use @samp{INPUT (-l@var{file})}, @command{ld} will transform the
 name to @code{lib@var{file}.a}, as with the command line argument
diff --git a/ld/ldfile.c b/ld/ldfile.c
index 782ed7f..f6bc3aa 100644
--- a/ld/ldfile.c
+++ b/ld/ldfile.c
@@ -461,7 +461,11 @@ try_open (const char *name, bfd_boolean *sysrooted)
   result = fopen (name, "r");
 
   if (result != NULL)
+#ifdef ENABLE_RUNTIME_SYSROOT
     *sysrooted = is_sysrooted_pathname (name);
+#else
+    *sysrooted = 0;
+#endif
 
   if (verbose)
     {
-- 
2.1.3



More information about the Binutils mailing list