Remove any trailing directory separator from ld_canon_sysroot and adjust ld_canon_sys...
authorDouglas B Rupp <rupp@adacore.com>
Wed, 28 Feb 2018 11:44:26 +0000 (11:44 +0000)
committerNick Clifton <nickc@redhat.com>
Wed, 28 Feb 2018 11:44:26 +0000 (11:44 +0000)
The problem was the ld expect libiberty/lrealpath() to always return a
path, but in some cases it returns a prefix. It seemed like too much of
an earthquake to propose a fix to lrealpath.

* ldmain.c (main): Remove directory separator, if any, from the
end of the canonicalized sysroot.

ld/ChangeLog
ld/ldmain.c

index 07c86efc061db91d38ffabeb2ecf66a41c052f21..f6b7508163f1e3d4fb2c467dc809a8a81d13d0d2 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-28  Douglas B Rupp  <rupp@adacore.com>
+
+       * ldmain.c (main): Remove directory separator, if any, from the
+       end of the canonicalized sysroot.
+
 2018-02-27  H.J. Lu  <hongjiu.lu@intel.com>
 
        * NEWS: Mention --enable-separate-code.
index b6914db5da98da4275739a61b14d0150b4209395..6527613c983a1c33152090eb26579832424dcd68 100644 (file)
@@ -228,7 +228,14 @@ main (int argc, char **argv)
   if (*ld_sysroot)
     ld_canon_sysroot = lrealpath (ld_sysroot);
   if (ld_canon_sysroot)
-    ld_canon_sysroot_len = strlen (ld_canon_sysroot);
+    {
+      ld_canon_sysroot_len = strlen (ld_canon_sysroot);
+
+      /* is_sysrooted_pathname() relies on no trailing dirsep.  */
+      if (ld_canon_sysroot_len > 0
+         && IS_DIR_SEPARATOR (ld_canon_sysroot [ld_canon_sysroot_len - 1]))
+        ld_canon_sysroot [--ld_canon_sysroot_len] = '\0';
+    }
   else
     ld_canon_sysroot_len = -1;