Skip to content

Commit

Permalink
Clang/Gnu: Scan GCC with triple without vendor if vendor is unknown
Browse files Browse the repository at this point in the history
If ScanLibDirForGCCTriple with target triple fails, let's try the triple with
vendor stripped if vendor is unknown.

Debian always uses triples without a vendor section. In general, triples without
a vendor section is the most similar aliases than any other aliases.

To archive this, we add a private member TripleNoVendor to
GCCInstallationDetector.

This modification makes testcases riscv32-toolchain.c and riscv64-toolchain.c
fail. The reason is that they are wrong: --triple riscv64-unknown-elf tries
to use riscv64-unknown-linux-gnu first.

This patch accidentally fixes this problem.

We also drop the path delimiter pattern {{/|\\\\}}, as these 2 tests are
disabled on Windows, and in fact the positions of this pattern are not
correct.

Reviewed by: MaskRay

Differential Revision: https://reviews.llvm.org/D158183
  • Loading branch information
wzssyqa authored and brad0 committed Aug 22, 2023
1 parent c467245 commit 6ee3b24
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 99 deletions.
8 changes: 8 additions & 0 deletions clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,10 @@ void Generic_GCC::GCCInstallationDetector::init(
CandidateTripleAliases, CandidateBiarchLibDirs,
CandidateBiarchTripleAliases);

TripleNoVendor = TargetTriple.getArchName().str() + "-" +
TargetTriple.getOSAndEnvironmentName().str();
StringRef TripleNoVendorRef(TripleNoVendor);

// If --gcc-install-dir= is specified, skip filesystem detection.
if (const Arg *A =
Args.getLastArg(clang::driver::options::OPT_gcc_install_dir_EQ);
Expand Down Expand Up @@ -2170,6 +2174,10 @@ void Generic_GCC::GCCInstallationDetector::init(
// Try to match the exact target triple first.
ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, TargetTriple.str(),
false, GCCDirExists, GCCCrossDirExists);
// If vendor is unknown, let's try triple without vendor.
if (TargetTriple.getVendor() == llvm::Triple::UnknownVendor)
ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, TripleNoVendorRef,
false, GCCDirExists, GCCCrossDirExists);
// Try rest of possible triples.
for (StringRef Candidate : ExtraTripleAliases) // Try these first.
ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, false,
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/ToolChains/Gnu.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
void print(raw_ostream &OS) const;

private:
std::string TripleNoVendor;
static void
CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
const llvm::Triple &BiarchTriple,
Expand Down

0 comments on commit 6ee3b24

Please sign in to comment.