https://github.com/am11 updated https://github.com/llvm/llvm-project/pull/206477
>From 67c487c5e3df39375424ee18affb601aaae35070 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <[email protected]> Date: Mon, 29 Jun 2026 16:02:53 +0300 Subject: [PATCH 1/2] [Driver] Find vendor-prefixed musl GCC toolchains --- clang/lib/Driver/ToolChains/Gnu.cpp | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index b58c10145e7f3..0f42ec188424d 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2206,6 +2206,38 @@ void Generic_GCC::GCCInstallationDetector::init( for (StringRef Candidate : CandidateTripleAliases) ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, false, GCCDirExists, GCCCrossDirExists); + + // Some musl distributions embed a vendor name in their GCC triple that a + // neutral --target cannot spell. For example Alpine ships its toolchain + // under <arch>-alpine-linux-musl[abi] (e.g. aarch64-alpine-linux-musl, + // armv7-alpine-linux-musleabihf), so --target=aarch64-linux-musl or + // --target=armv7-linux-musleabihf would otherwise fail to find it. + // Enumerate the GCC triple directories and try any entry whose + // architecture, OS and environment match the target, ignoring the vendor + // field. ScanLibDirForGCCTriple already de-duplicates installations, so + // candidates also covered above are harmless. Skip this when the user + // pinned an explicit --gcc-triple. + if (TargetTriple.isMusl() && !Args.hasArg(options::OPT_gcc_triple_EQ)) { + for (const char *GCCDir : {"/gcc", "/gcc-cross"}) { + if ((StringRef(GCCDir) == "/gcc" && !GCCDirExists) || + (StringRef(GCCDir) == "/gcc-cross" && !GCCCrossDirExists)) + continue; + std::error_code EC; + for (llvm::vfs::directory_iterator + LI = VFS.dir_begin(LibDir + GCCDir, EC), + LE; + !EC && LI != LE; LI = LI.increment(EC)) { + StringRef Name = llvm::sys::path::filename(LI->path()); + llvm::Triple CandidateTriple(Name); + if (CandidateTriple.getArch() == TargetTriple.getArch() && + CandidateTriple.getOS() == TargetTriple.getOS() && + CandidateTriple.getEnvironment() == + TargetTriple.getEnvironment()) + ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Name, false, + GCCDirExists, GCCCrossDirExists); + } + } + } } for (StringRef Suffix : CandidateBiarchLibDirs) { const std::string LibDir = Prefix + Suffix.str(); >From 8305cbdda6059d3cb1cb405945649dd4bf968696 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <[email protected]> Date: Mon, 29 Jun 2026 16:04:09 +0300 Subject: [PATCH 2/2] . --- .../Driver/linux-musl-alpine-gcc-detect.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 clang/test/Driver/linux-musl-alpine-gcc-detect.c diff --git a/clang/test/Driver/linux-musl-alpine-gcc-detect.c b/clang/test/Driver/linux-musl-alpine-gcc-detect.c new file mode 100644 index 0000000000000..a902bad65f442 --- /dev/null +++ b/clang/test/Driver/linux-musl-alpine-gcc-detect.c @@ -0,0 +1,23 @@ +// Alpine Linux ships its GCC toolchain under a vendor-prefixed musl triple +// (e.g. aarch64-alpine-linux-musl, armv7-alpine-linux-musleabihf). Verify that +// a neutral --target=<arch>-linux-musl[abi] still locates it, matching the +// behavior of the exact Alpine triple. +// See https://github.com/llvm/llvm-project/issues/89146 + +// RUN: %clang -### %s --target=aarch64-linux-musl --rtlib=libgcc -no-pie \ +// RUN: --sysroot=%S/Inputs/alpine_aarch64_musl_tree 2>&1 \ +// RUN: | FileCheck --check-prefix=AARCH64 %s +// RUN: %clang -### %s --target=aarch64-alpine-linux-musl --rtlib=libgcc -no-pie \ +// RUN: --sysroot=%S/Inputs/alpine_aarch64_musl_tree 2>&1 \ +// RUN: | FileCheck --check-prefix=AARCH64 %s +// AARCH64: "{{[^"]*}}/usr/lib/gcc/aarch64-alpine-linux-musl/13.2.1{{/|\\\\}}crtbegin.o" + +// RUN: %clang -### %s --target=armv7-linux-musleabihf --rtlib=libgcc -no-pie \ +// RUN: --sysroot=%S/Inputs/alpine_armv7_musl_tree 2>&1 \ +// RUN: | FileCheck --check-prefix=ARMHF %s +// RUN: %clang -### %s --target=armv7-alpine-linux-musleabihf --rtlib=libgcc -no-pie \ +// RUN: --sysroot=%S/Inputs/alpine_armv7_musl_tree 2>&1 \ +// RUN: | FileCheck --check-prefix=ARMHF %s +// ARMHF: "{{[^"]*}}/usr/lib/gcc/armv7-alpine-linux-musleabihf/13.2.1{{/|\\\\}}crtbegin.o" + +int main(void) {} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
