Using = to refer to the sysroot prefix in both the -L option and the INPUT command is not very expressive/mnemonic. It would seem useful to additionall support $SYSROOT similarly to $ORIGIN and $LIB.
Created attachment 9924 [details] Proposed patch Hi Rainer, Does this work for you ? Cheers Nick
Hi Nick, sorry for the very long delay in replying ;-( Yes, works like a charm, thanks. Btw., do you have any idea how widespread the use of '=' for the sysroot prefix is? It's kinda hard to search for -L = ... I've only noticed it very recently. There's work going on to implement --sysroot in Solaris ld, and the question poses itself if there's much point in supporting the '=' form or just going for $SYSROOT here. Besides, while were at --sysroot, did you have a chance to have a look at PR ld/21250. Thanks a lot. Rainer
The master branch has been updated by Nick Clifton <nickc@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3aa2d05a728216bbb99dbb5718be9bb36429cf41 commit 3aa2d05a728216bbb99dbb5718be9bb36429cf41 Author: Nick Clifton <nickc@redhat.com> Date: Thu May 18 15:07:59 2017 +0100 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.
(In reply to Rainer Orth from comment #2) Hi Rainer, > Yes, works like a charm, thanks. Great - I have checked the patch in. > Btw., do you have any idea how widespread the use of '=' for the sysroot > prefix is? Hmm, I was going to say not a lot, but then I remembered that GCC uses it: https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html So maybe it is more widespread than we realise. > Besides, while were at --sysroot, did you have a chance to have a look > at PR ld/21250. I looked at it, shuddered, and looked away. :-} I suspect that that PR will turn out to be a can of worms, so I was going to treat it as low priority unless other people notice and complain too. Cheers Nick
Hi Nick, > Great - I have checked the patch in. excellent, thanks. >> Btw., do you have any idea how widespread the use of '=' for the sysroot >> prefix is? > > Hmm, I was going to say not a lot, but then I remembered that GCC uses it: > > https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html Maybe I'm blind, but where did you see that? I've also looked at GCC mainline invoke.text and found nothing, neither with -L nor anywhere sysroot is described. I'd have been surprised to find pure linker option descriptions repeated in the GCC manual, so I didn't even think to look. > So maybe it is more widespread than we realise. Which would be a pity ;-) >> Besides, while were at --sysroot, did you have a chance to have a look >> at PR ld/21250. > > I looked at it, shuddered, and looked away. :-} I suspect that that PR > will turn out to be a can of worms, so I was going to treat it as low > priority unless other people notice and complain too. Understood. It took me completely off guard since gcc's --sysroot support works just the way I expected (no headers found outside of the sysroot prefix), while gld may behave otherwise. This is particularly ugly if you're cross-linking for say a different OS version where the native libraries do work, but may contain more (or less) functions than desired for the target OS version. In a real cross environment, where host and target differ, you will get an error instead of links succeeding silently when they shouldn't... Rainer
Hi Rainer, >> Hmm, I was going to say not a lot, but then I remembered that GCC uses it: >> >> https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html > > Maybe I'm blind, but where did you see that? Umm, do you mean "where in that web page do I see an '=' prefix being used to indicate that a sysroot should be used ?" Then, right at the start: -idirafter dir Add the directory dir to the list of directories to be searched for header files during preprocessing. If dir begins with ‘=’, then the ‘=’ is replaced by the sysroot prefix; see --sysroot and -isysroot. If you mean, "where does this information come from ?" The have a look in gcc/doc/cppdiropts.texi. > I'd have been surprised to find pure linker option descriptions repeated > in the GCC manual, so I didn't even think to look. Well to be honest it is talking about the c-preprocessor include path options rather than the linker search path, but I think that it establishes a principle which users will expect to be followed. IE if include paths can use a '=' prefix then library search paths should be able to as well. Cheers Nick
> --- Comment #6 from Nick Clifton <nickc at redhat dot com> --- Hi Nick, >>> Hmm, I was going to say not a lot, but then I remembered that GCC uses it: >>> >>> https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html >> >> Maybe I'm blind, but where did you see that? > > Umm, do you mean "where in that web page do I see an '=' prefix being used > to indicate that a sysroot should be used ?" Then, right at the start: > > -idirafter dir > > Add the directory dir to the list of directories to be searched > for header files during preprocessing. If dir begins with ‘=’, > then the ‘=’ is replaced by the sysroot prefix; see --sysroot and -isysroot. ah, silly me, I just thought to look at -L and friends. >> I'd have been surprised to find pure linker option descriptions repeated >> in the GCC manual, so I didn't even think to look. > > Well to be honest it is talking about the c-preprocessor include path options > rather than the linker search path, but I think that it establishes a principle > which users will expect to be followed. IE if include paths can use a '=' > prefix > then library search paths should be able to as well. Indeed, everything else would be just confusing. This pretty much rules out deprecating '=' in either gld or gcc, obviously. I'll look into supporting $SYSROOT in gcc for symmetry, but that's about it. Thanks for your patience ;-) Rainer