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.
This commit is contained in:
Nick Clifton
2017-05-18 15:07:59 +01:00
parent 59cc050d89
commit 3aa2d05a72
6 changed files with 40 additions and 8 deletions

View 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> 2017-05-18 Alan Modra <amodra@gmail.com>
* emultempl/elf32.em: Don't compare boolean values against TRUE or FALSE. * emultempl/elf32.em: Don't compare boolean values against TRUE or FALSE.

View 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} how @command{ld} searches for a linker script unless @option{-T}
option is specified. option is specified.
If @var{searchdir} begins with @code{=}, then the @code{=} will be replaced If @var{searchdir} begins with @code{=} or @code{$SYSROOT}, then this
by the @dfn{sysroot prefix}, controlled by the @samp{--sysroot} option, or prefix will be replaced by the @dfn{sysroot prefix}, controlled by the
specified when the linker is configured. @samp{--sysroot} option, or specified when the linker is configured.
@ifset UsesEnvVars @ifset UsesEnvVars
The default set of paths searched (without being specified with 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 open the file in the current directory. If it is not found, the
linker will search through the archive library search path. linker will search through the archive library search path.
The @dfn{sysroot prefix} can also be forced by specifying @code{=} The @dfn{sysroot prefix} can also be forced by specifying @code{=}
as the first character in the filename path. See also the as the first character in the filename path, or prefixing the filename
description of @samp{-L} in @ref{Options,,Command Line Options}. 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 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 name to @code{lib@var{file}.a}, as with the command line argument

View File

@ -112,6 +112,8 @@ ldfile_add_library_path (const char *name, bfd_boolean cmdline)
now. */ now. */
if (name[0] == '=') if (name[0] == '=')
new_dirs->name = concat (ld_sysroot, name + 1, (const char *) NULL); 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 else
new_dirs->name = xstrdup (name); new_dirs->name = xstrdup (name);
} }

View File

@ -1138,11 +1138,14 @@ lang_add_input_file (const char *name,
lang_input_file_enum_type file_type, lang_input_file_enum_type file_type,
const char *target) const char *target)
{ {
if (name != NULL && *name == '=') if (name != NULL
&& (*name == '=' || CONST_STRNEQ (name, "$SYSROOT")))
{ {
lang_input_statement_type *ret; lang_input_statement_type *ret;
char *sysrooted_name 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 /* We've now forcibly prepended the sysroot, making the input
file independent of the context. Therefore, temporarily file independent of the context. Therefore, temporarily

View File

@ -376,6 +376,11 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
return NAME; return NAME;
} }
<INPUTLIST>"="{FILENAMECHAR1}{FILENAMECHAR}* { <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. */ /* Filename to be prefixed by --sysroot or when non-sysrooted, nothing. */
yylval.name = xstrdup (yytext); yylval.name = xstrdup (yytext);
return NAME; return NAME;

View File

@ -76,16 +76,23 @@ set sysroot_prefix_tests {
{7 "root-anchored but -Lpath" "/sysroot/" {} "cannot find"} {7 "root-anchored but -Lpath" "/sysroot/" {} "cannot find"}
{7 "full-path" "@cwd@/sysroot/" {} ""} {7 "full-path" "@cwd@/sysroot/" {} ""}
{7 "root-anchored =-prefixed -Lpath" "=/sysroot/" {} "cannot find"} {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 =-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 but script outside sysroot" "/" "--sysroot=@cwd@/sysroot" "cannot find"}
{6 "root-anchored and script inside sysroot" "/sysroot/" "--sysroot=@cwd@" ""} {6 "root-anchored and script inside sysroot" "/sysroot/" "--sysroot=@cwd@" ""}
{6 "root-anchored =-prefixed script outside" "=/" "--sysroot=@cwd@/sysroot" ""} {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 =-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 =-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 =-prefixed without" "=@cwd@/sysroot/" {} "cannot find"}
{2 "full-path $SYSROOT-prefixed without" "$SYSROOT@cwd@/sysroot/" {} "cannot find"}
{1 "plain =-prefixed -Lpath" "=sysroot/" {} ""} {1 "plain =-prefixed -Lpath" "=sysroot/" {} ""}
{1 "plain $SYSROOT-prefixed -Lpath" "$SYSROOTsysroot/" {} ""}
{1 "full-path =-prefixed without" "=@cwd@/sysroot/" {} ""} {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. # May have to provide a target-specific assembler option for some targets.