+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.
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
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
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);
}
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
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;
{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.