]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Treat a prefix of "$SYSROOT" in the same way as "=" when parsing linker search paths.
authorNick Clifton <nickc@redhat.com>
Thu, 18 May 2017 14:07:59 +0000 (15:07 +0100)
committerNick Clifton <nickc@redhat.com>
Thu, 18 May 2017 14:07:59 +0000 (15:07 +0100)
PR ld/21251
* ldfile.c (ldfile_add_library_path): If the path starts with
$SYSROOT then use the sysroot as the real prefix.
* ldlang.c (lang_add_input_file): Treat $SYSROOT in the same
way as =.
* ldlex.l: Add $SYSROOT as allow prefix for a filename.
* ld.texinfo (-L): Document that $SYSROOT acts like = when
prefixing a library search path.
(INPUT): Likewise.
* testsuite/ld-scripts/sysroot-prefix.exp: Add $SYSROOT prefix
tests.

ld/ChangeLog
ld/ld.texinfo
ld/ldfile.c
ld/ldlang.c
ld/ldlex.l
ld/testsuite/ld-scripts/sysroot-prefix.exp

index 9e5b66be233fd67df385318234af6e2515d4601d..097afac378d8da6293f3c98a5718fa47c5fefccc 100644 (file)
@@ -1,3 +1,17 @@
+2017-05-18  Nick Clifton  <nickc@redhat.com>
+
+       PR ld/21251
+       * ldfile.c (ldfile_add_library_path): If the path starts with
+       $SYSROOT then use the sysroot as the real prefix.
+       * ldlang.c (lang_add_input_file): Treat $SYSROOT in the same
+       way as =.
+       * ldlex.l: Add $SYSROOT as allow prefix for a filename.
+       * ld.texinfo (-L): Document that $SYSROOT acts like = when
+       prefixing a library search path.
+       (INPUT): Likewise.
+       * testsuite/ld-scripts/sysroot-prefix.exp: Add $SYSROOT prefix
+       tests.
+
 2017-05-18  Alan Modra  <amodra@gmail.com>
 
        * emultempl/elf32.em: Don't compare boolean values against TRUE or FALSE.
index 653bfb83a4456bb8a3790ffa108188d2ad272380..9a72cb9e4db5ac87c2cafe3580bf8be1ba44d736 100644 (file)
@@ -705,9 +705,9 @@ order in which the options appear.  @option{-L} options do not affect
 how @command{ld} searches for a linker script unless @option{-T}
 option is specified.
 
-If @var{searchdir} begins with @code{=}, then the @code{=} will be replaced
-by the @dfn{sysroot prefix}, controlled by the @samp{--sysroot} option, or
-specified when the linker is configured.
+If @var{searchdir} begins with @code{=} or @code{$SYSROOT}, then this
+prefix will be replaced by the @dfn{sysroot prefix}, controlled by the
+@samp{--sysroot} option, or specified when the linker is configured.
 
 @ifset UsesEnvVars
 The default set of paths searched (without being specified with
@@ -3393,8 +3393,9 @@ 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}.
+as the first character in the filename path, or prefixing the filename
+path with @code{$SYSROOT}.  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
index 0943bb2dfa0fcc40565133773e86f72cf04d19f8..3b37a0a3e2636b2ac3b04e0ec074d14fbfa5315b 100644 (file)
@@ -112,6 +112,8 @@ ldfile_add_library_path (const char *name, bfd_boolean cmdline)
      now.  */
   if (name[0] == '=')
     new_dirs->name = concat (ld_sysroot, name + 1, (const char *) NULL);
+  else if (CONST_STRNEQ (name, "$SYSROOT"))
+    new_dirs->name = concat (ld_sysroot, name + strlen ("$SYSROOT"), (const char *) NULL);
   else
     new_dirs->name = xstrdup (name);
 }
index 266c099f5a8e5a899b5798f5c73412273b2a66bf..ed7e5525ed06ecff730d40d0bb2e7863227dc032 100644 (file)
@@ -1138,11 +1138,14 @@ lang_add_input_file (const char *name,
                     lang_input_file_enum_type file_type,
                     const char *target)
 {
-  if (name != NULL && *name == '=')
+  if (name != NULL
+      && (*name == '=' || CONST_STRNEQ (name, "$SYSROOT")))
     {
       lang_input_statement_type *ret;
       char *sysrooted_name
-       = concat (ld_sysroot, name + 1, (const char *) NULL);
+       = concat (ld_sysroot,
+                 name + (*name == '=' ? 1 : strlen ("$SYSROOT")),
+                 (const char *) NULL);
 
       /* We've now forcibly prepended the sysroot, making the input
         file independent of the context.  Therefore, temporarily
index fa9b92442617c8eae4eaeb0ab34e570ff9b3c484..acba1a2b4b63c1f8c28d463cb6f4b71c7f05d2bf 100644 (file)
@@ -376,6 +376,11 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
                                  return NAME;
                                }
 <INPUTLIST>"="{FILENAMECHAR1}{FILENAMECHAR}*   {
+/* Filename to be prefixed by --sysroot or when non-sysrooted, nothing.  */
+                                yylval.name = xstrdup (yytext);
+                                 return NAME;
+                               }
+<INPUTLIST>"$SYSROOT"{FILENAMECHAR1}{FILENAMECHAR}*    {
 /* Filename to be prefixed by --sysroot or when non-sysrooted, nothing.  */
                                 yylval.name = xstrdup (yytext);
                                  return NAME;
index 0fc322eb5c7cc176bc184617e5fe7836b97d53d3..e08429f151f156bb243b97225d86adb3769056ed 100644 (file)
@@ -76,16 +76,23 @@ set sysroot_prefix_tests {
     {7 "root-anchored but -Lpath" "/sysroot/" {} "cannot find"}
     {7 "full-path" "@cwd@/sysroot/" {} ""}
     {7 "root-anchored =-prefixed -Lpath" "=/sysroot/" {} "cannot find"}
-    {7 "full-path =-prefixed with empty" "=@cwd@/sysroot/" "--sysroot=" ""}
+    {7 "root-anchored $SYSROOT-prefixed -Lpath" "$SYSROOT/sysroot/" {} "cannot find"}
     {7 "plain =-prefixed with empty" "=sysroot/" "--sysroot=" ""}
+    {7 "plain $SYSROOT-prefixed with empty" "$SYSROOTsysroot/" "--sysroot=" ""}
     {6 "root-anchored but script outside sysroot" "/" "--sysroot=@cwd@/sysroot" "cannot find"}
     {6 "root-anchored and script inside sysroot" "/sysroot/" "--sysroot=@cwd@" ""}
     {6 "root-anchored =-prefixed script outside" "=/" "--sysroot=@cwd@/sysroot" ""}
+    {6 "root-anchored $SYSROOT-prefixed script outside" "$SYSROOT/" "--sysroot=@cwd@/sysroot" ""}
     {6 "root-anchored =-prefixed script inside" "=/sysroot/" "--sysroot=@cwd@" ""}
+    {6 "root-anchored $SYSROOT-prefixed script inside" "$SYSROOT/sysroot/" "--sysroot=@cwd@" ""}
     {2 "plain =-prefixed without but -Lpath" "=sysroot/" {} "cannot find"}
+    {2 "plain $SYSROOT-prefixed without but -Lpath" "$SYSROOTsysroot/" {} "cannot find"}
     {2 "full-path =-prefixed without" "=@cwd@/sysroot/" {} "cannot find"}
+    {2 "full-path $SYSROOT-prefixed without" "$SYSROOT@cwd@/sysroot/" {} "cannot find"}
     {1 "plain =-prefixed -Lpath" "=sysroot/" {} ""}
+    {1 "plain $SYSROOT-prefixed -Lpath" "$SYSROOTsysroot/" {} ""}
     {1 "full-path =-prefixed without" "=@cwd@/sysroot/" {} ""}
+    {1 "full-path $SYSROOT-prefixed without" "$SYSROOT@cwd@/sysroot/" {} ""}
 }
 
 # May have to provide a target-specific assembler option for some targets.