aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2017-05-18 15:07:59 +0100
committerNick Clifton <nickc@redhat.com>2017-05-18 15:07:59 +0100
commit3aa2d05a728216bbb99dbb5718be9bb36429cf41 (patch)
tree634ea00884160b88e1c0c55154b963ab3652e077
parent59cc050d893d1e8c75547de950a35e809588f12f (diff)
downloadgdb-3aa2d05a728216bbb99dbb5718be9bb36429cf41.zip
gdb-3aa2d05a728216bbb99dbb5718be9bb36429cf41.tar.gz
gdb-3aa2d05a728216bbb99dbb5718be9bb36429cf41.tar.bz2
Treat a prefix of "$SYSROOT" in the same way as "=" when parsing linker search paths.
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.
-rw-r--r--ld/ChangeLog14
-rw-r--r--ld/ld.texinfo11
-rw-r--r--ld/ldfile.c2
-rw-r--r--ld/ldlang.c7
-rw-r--r--ld/ldlex.l5
-rw-r--r--ld/testsuite/ld-scripts/sysroot-prefix.exp9
6 files changed, 40 insertions, 8 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 9e5b66b..097afac 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -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.
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 653bfb8..9a72cb9 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -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
diff --git a/ld/ldfile.c b/ld/ldfile.c
index 0943bb2..3b37a0a 100644
--- a/ld/ldfile.c
+++ b/ld/ldfile.c
@@ -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);
}
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 266c099..ed7e552 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -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
diff --git a/ld/ldlex.l b/ld/ldlex.l
index fa9b924..acba1a2 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -380,6 +380,11 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
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;
+ }
<BOTH,INPUTLIST>"-l"{FILENAMECHAR}+ {
yylval.name = xstrdup (yytext + 2);
return LNAME;
diff --git a/ld/testsuite/ld-scripts/sysroot-prefix.exp b/ld/testsuite/ld-scripts/sysroot-prefix.exp
index 0fc322e..e08429f 100644
--- a/ld/testsuite/ld-scripts/sysroot-prefix.exp
+++ b/ld/testsuite/ld-scripts/sysroot-prefix.exp
@@ -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.