[cfe-dev] [clang][main] Does not detect embed gcc toolchain

Fangrui Song via cfe-dev cfe-dev at lists.llvm.org
Thu Apr 8 09:54:23 PDT 2021


On 2021-04-08, David Blaikie wrote:
>Ray - I think you've been doing some work related to toolchain
>discovery stuff recently, might this be related?
>
>On Thu, Apr 8, 2021 at 6:25 AM Andi-Bogdan Postelnicu via cfe-dev
><cfe-dev at lists.llvm.org> wrote:
>>
>> Hello,
>>
>> I’m building clang main, revision b785e03612d76145c58cb31b6fd6911a5e41e8e3,  and I’m adding to lib folder gcc toolchain 7.4.0, so the folder layout is:
>>
>> clang/lib/gcc/x86_64-unknown-linux-gnu/7.4.0
>>
>> Unfortunately when I want to build on linux debian and I do a verbose build clang doesn’t seem able to find the gcc version that I’ve shipped it with:
>>
>> clang version 13.0.0 (E4V8ZoJsR3qTRv_zx8MEpA)
>> Target: x86_64-unknown-linux-gnu
>> Thread model: posix
>> InstalledDir: /home/someuser/clang/clang/bin
>> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
>> Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
>> Candidate multilib: .;@m64
>> Selected multilib: .;@m64
>>
>> Doing the same thing but building the official clang 11.0.1 I’m seeing normal results:
>>
>> clang version 11.0.1 (NZ4C_ZaZTQmrQM25NeOO0Q)
>> Target: x86_64-unknown-linux-gnu
>> Thread model: posix
>> InstalledDir: /home/someuser/mozilla/clang/clang-11/clang/bin
>> Found candidate GCC installation: /home/someuser/clang/clang-11/clang/bin/../lib/gcc/x86_64-unknown-linux-gnu/7.4.0
>> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
>> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.2
>> Selected GCC installation: /home/someuser/clang/clang-11/clang/bin/../lib/gcc/x86_64-unknown-linux-gnu/7.4.0
>> Candidate multilib: .;@m64
>> Candidate multilib: 32;@m32
>> Selected multilib: .;@m64
>>
>> Has anyone confronted with this lately?
>>
>> Many thanks

The GCC installation detection logic is in Generic_GCC::GCCInstallationDetector::init.

If --sysroot is not empty (or unspecified and cmake DEFAULT_SYSROOT is not empty), the search order is: $sysroot/usr $sysroot dir(clang)/..
otherwise dir(clang)/.. $sysroot/usr $sysroot

Before 13.0.0 Clang picked the search directory with the largest GCC
version.  This made the behavior less predictable, e.g. if your system
version is larger than 7.4.0, you would end up with the system gcc.

The new behavior stops at the first search directory with a GCC installation.
In your case, instead of relying on dir(clang)/.. (the behavior may be
questionable), specifying --gcc-toolchain=/home/someuser/clang/clang-11/clang
is more robost (if you can find lib/gcc{,-cross}/$triple in that directory).


More information about the cfe-dev mailing list