Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang Driver: Simplify Gentoo gcc-config detection #57570

Open
MaskRay opened this issue Sep 5, 2022 · 2 comments
Open

Clang Driver: Simplify Gentoo gcc-config detection #57570

MaskRay opened this issue Sep 5, 2022 · 2 comments
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl'

Comments

@MaskRay
Copy link
Member

MaskRay commented Sep 5, 2022

On Gentoo Linux, Clang Driver tries to pick the GCC installation as selected by gcc-config.
It reads $sysroot/etc/env.d/gcc/config-$CandidateTriple}, does some parsing, and selects the desired GCC installation.
See Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig in https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/Gnu.cpp

It tries to be permissive with --target= by detecting several aliases. I think these aliases detection should be removed.

    GentooTestTriples.push_back(TargetTriple.str());
    // Check rest of triples.
    GentooTestTriples.append(ExtraTripleAliases.begin(),
                             ExtraTripleAliases.end());
    GentooTestTriples.append(CandidateTripleAliases.begin(),
                             CandidateTripleAliases.end());

The code parses CURRENT=, LDPATH=, etc, which does not look very pretty. I am considering adding --gcc-install-dir= (https://reviews.llvm.org/D133329).

With the option,

  • make gcc-config provide a configuration file specifying --gcc-install-dir= (https://bugs.gentoo.org/868639)
  • configure sys-devel/clang with an appropriate CLANG_CONFIG_FILE_SYSTEM_DIR. Change clang to a shell script which invokes ${default_triple}-clang. This is because xxx-clang loads xxx.cfg while clang doesn't.
  • Remove Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig
@MaskRay MaskRay added the clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' label Sep 5, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 5, 2022

@llvm/issue-subscribers-clang-driver

@thesamesam
Copy link
Member

thesamesam commented Sep 13, 2022

It'd be less disruptive if we could make clang load a config file as well: https://reviews.llvm.org/D109621.

I've actually just hit a need for that because of https://bugs.gentoo.org/870001. Clang does not include <stdc-predefs.h> by default, so it's broken on e.g. musl.

gentoo-bot pushed a commit to gentoo/gcc-config that referenced this issue Oct 9, 2022
* Set '--gcc-install-dir' for Clang to direct it to the currently
  active GCC installation.

* Only write to /etc/clang/gentoo-gcc-install.cfg if it already exists
  to allow us to back out the change gracefully (by stopping installation
  in sys-devel/clang-common) as there's some concerns wrt sysroot compatibility.

Bug: llvm/llvm-project#57570
Bug: https://bugs.gentoo.org/868639
Signed-off-by: Sam James <sam@gentoo.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl'
Projects
None yet
Development

No branches or pull requests

3 participants