[binutils-gdb] Simplify --sysroot=/

Alan Modra amodra@sourceware.org
Mon Oct 29 07:54:00 GMT 2018


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=55d5520ae35a2b0ce788bd6d43dd619043e887f7

commit 55d5520ae35a2b0ce788bd6d43dd619043e887f7
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Oct 29 18:09:39 2018 +1030

    Simplify --sysroot=/
    
    Prepending '/' to absolute paths doesn't gain us much, and results in
    the current implementation of --trace emitting silly path-in-sysroot
    output, eg.
    /lib/ld-linux-x86-64.so.2 (//lib/ld-linux-x86-64.so.2)
    
    	* ldmain.c (get_sysroot): Return "" for "--sysroot=/".

Diff:
---
 ld/ChangeLog |  4 ++++
 ld/ldmain.c  | 22 +++++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 4dfd2e8..d2700bc 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,5 +1,9 @@
 2018-10-29  Alan Modra  <amodra@gmail.com>
 
+	* ldmain.c (get_sysroot): Return "" for "--sysroot=/".
+
+2018-10-29  Alan Modra  <amodra@gmail.com>
+
 	* Makefile.am (ei386beos.c, ei386go32.c): Correct dependencies.
 	* Makefile.in: Regenerate.
 	* scripttempl/elf.sc (.note.gnu.build-id, .eh_frame_hdr): Set
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 4641920..6f3ce6f 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -584,21 +584,25 @@ static const char *
 get_sysroot (int argc, char **argv)
 {
   int i;
-  const char *path;
+  const char *path = NULL;
 
   for (i = 1; i < argc; i++)
     if (CONST_STRNEQ (argv[i], "--sysroot="))
-      return argv[i] + strlen ("--sysroot=");
+      path = argv[i] + strlen ("--sysroot=");
 
-  path = get_relative_sysroot (BINDIR);
-  if (path)
-    return path;
+  if (!path)
+    path = get_relative_sysroot (BINDIR);
 
-  path = get_relative_sysroot (TOOLBINDIR);
-  if (path)
-    return path;
+  if (!path)
+    path = get_relative_sysroot (TOOLBINDIR);
+
+  if (!path)
+    path = TARGET_SYSTEM_ROOT;
+
+  if (IS_DIR_SEPARATOR (*path) && path[1] == 0)
+    path = "";
 
-  return TARGET_SYSTEM_ROOT;
+  return path;
 }
 
 /* We need to find any explicitly given emulation in order to initialize the



More information about the Binutils-cvs mailing list