From 3aa2d05a728216bbb99dbb5718be9bb36429cf41 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Thu, 18 May 2017 15:07:59 +0100 Subject: [PATCH] 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. --- ld/ChangeLog | 14 ++++++++++++++ ld/ld.texinfo | 11 ++++++----- ld/ldfile.c | 2 ++ ld/ldlang.c | 7 +++++-- ld/ldlex.l | 5 +++++ ld/testsuite/ld-scripts/sysroot-prefix.exp | 9 ++++++++- 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index 9e5b66be233..097afac378d 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,17 @@ +2017-05-18 Nick Clifton + + 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 * emultempl/elf32.em: Don't compare boolean values against TRUE or FALSE. diff --git a/ld/ld.texinfo b/ld/ld.texinfo index 653bfb83a44..9a72cb9e4db 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 0943bb2dfa0..3b37a0a3e26 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 266c099f5a8..ed7e5525ed0 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 fa9b9244261..acba1a2b4b6 100644 --- a/ld/ldlex.l +++ b/ld/ldlex.l @@ -376,6 +376,11 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)* return NAME; } "="{FILENAMECHAR1}{FILENAMECHAR}* { +/* Filename to be prefixed by --sysroot or when non-sysrooted, nothing. */ + yylval.name = xstrdup (yytext); + return NAME; + } +"$SYSROOT"{FILENAMECHAR1}{FILENAMECHAR}* { /* Filename to be prefixed by --sysroot or when non-sysrooted, nothing. */ yylval.name = xstrdup (yytext); return NAME; diff --git a/ld/testsuite/ld-scripts/sysroot-prefix.exp b/ld/testsuite/ld-scripts/sysroot-prefix.exp index 0fc322eb5c7..e08429f151f 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. -- 2.30.2