Bug 42300 - Having LIBRARY_PATH set but with null contents, makes gcc read ./specs
Summary: Having LIBRARY_PATH set but with null contents, makes gcc read ./specs
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 4.4.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-05 16:43 UTC by Lluís Batlle i Rossell
Modified: 2021-10-03 18:34 UTC (History)
2 users (show)

See Also:
Host: x86_64-linux
Target: x86_64-linux or any target for a cross-compiler
Build: x86_64-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Patch for LIBRARY_PATH parser (556 bytes, patch)
2021-10-03 18:34 UTC, Ryan Sundberg
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Lluís Batlle i Rossell 2009-12-05 16:43:32 UTC
I think that a LIBRARY_PATH set, but without any contents (as done in shell with LIBRARY_PATH= ) will make gcc read the specs file from the directory '.'.
Having no LIBRARY_PATH in the environment does not make gcc read ./specs.

For example. this can break the build of a cross-compiler with g++, because the g++ is compiled with the build gcc after building the cross-gcc, which created a 'specs' file in the current directory (build/gcc).
In this build, the built-in specs in the build gcc should be used, and not those of the cross compiler (./specs).

This can be reproduced trying to make a g++ cross-compiler with the LIBRARY_PATH environment variable set but with a null string content.

I could reproduce this with gcc 4.3.4 too, either a native or a cross compiler.

If it is a feature, I think the LIBRARY_PATH section in the gcc manual should explain about this, because I would expect this behaviour only under LIBRARY_PATH=.
Comment 1 Andrew Pinski 2009-12-06 08:59:26 UTC
specs files are no longer generated by default.
Comment 2 Ryan Sundberg 2021-10-03 18:34:16 UTC
Created attachment 51541 [details]
Patch for LIBRARY_PATH parser
Comment 3 Ryan Sundberg 2021-10-03 18:34:25 UTC
I've stumbled upon this 30 year old bug also while trying to build a gcc cross compiler. The behavior is that LIBRARY_PATH="" is different than having LIBRARY_PATH not set at all in the environment. As Lluis said in 2009, LIBRARY_PATH="" behaves as if LIBRARY_PATH=".". See the attached minimal example:

$ unset LIBRARY_PATH

$ gcc --print-search-dirs
install: /usr/lib/gcc/x86_64-linux-gnu/9/
programs: =/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/
libraries: =/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/9/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/9/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/


$ LIBRARY_PATH= gcc --print-search-dirs
install: /usr/lib/gcc/x86_64-linux-gnu/9/
programs: =/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/bin/
libraries: =./x86_64-linux-gnu/9/:./x86_64-linux-gnu/:./../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/9/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/9/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:./:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/

Notice that the search paths are different, the latter including ":./:" in the search path. If you happen to have a "specs" file in the search path (such as when building gcc) it will be accidentally loaded by GCC and can result in obscure errors (such as missing crt0.o, etc, depending on what is in the spec file).