https://github.com/azat updated https://github.com/llvm/llvm-project/pull/97802
>From 1d78d8362a4a10c8d8c2d5a78171e3fb5774daef Mon Sep 17 00:00:00 2001 From: Azat Khuzhin <a3at.m...@gmail.com> Date: Fri, 5 Jul 2024 11:15:15 +0200 Subject: [PATCH] [clang][Toolchain] Treat "pc"/"unknown" vendor interchangeable Right now if you have runtime libraries under lib/x86_64-unknown-linux-gnu you should use --target x86_64-unknown-linux-gnu, x86_64-pc-linux-gnu will not work. Treat the interchangeable so that you can use any. The initial reason for this patch is that debian packages uses x86_64-pc-linux-gnu, and after they enabled LLVM_ENABLE_PER_TARGET_RUNTIME_DIR [1], clang cannot find runtime libraries for sanitizers. [1]: https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/-/commit/9ca35f30383d89e4fdd45d15e0eb82c832df4b8c --- clang/lib/Driver/ToolChain.cpp | 20 ++++++++++++++++++++ clang/test/Driver/pc-unknown-toolchain.c | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100644 clang/test/Driver/pc-unknown-toolchain.c diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 977e08390800d..43ec3c234ba14 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -765,6 +765,26 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const { if (auto Path = getPathForTriple(getTriple())) return *Path; + // Treat "pc" and "unknown" vendors interchangeable + switch (getTriple().getVendor()) { + case Triple::UnknownVendor: { + llvm::Triple TripleFallback = Triple; + TripleFallback.setVendor(Triple::PC); + if (auto Path = getPathForTriple(TripleFallback)) + return *Path; + break; + } + case Triple::PC: { + llvm::Triple TripleFallback = Triple; + TripleFallback.setVendor(Triple::UnknownVendor); + if (auto Path = getPathForTriple(TripleFallback)) + return *Path; + break; + } + default: + break; + } + // When building with per target runtime directories, various ways of naming // the Arm architecture may have been normalised to simply "arm". // For example "armv8l" (Armv8 AArch32 little endian) is replaced with "arm". diff --git a/clang/test/Driver/pc-unknown-toolchain.c b/clang/test/Driver/pc-unknown-toolchain.c new file mode 100644 index 0000000000000..01eaebb6d0eec --- /dev/null +++ b/clang/test/Driver/pc-unknown-toolchain.c @@ -0,0 +1,6 @@ +// UNSUPPORTED: system-windows + +// RUN: %clang -### %s -fsanitize=address --target=x86_64-pc-linux-gnu 2>&1 | FileCheck -check-prefix=CHECK-ASAN-PC %s +// CHECK-ASAN-PC: x86_64-unknown-linux-gnu/libclang_rt.asan_static.a +// RUN: %clang -### %s -fsanitize=address --target=x86_64-unknown-linux-gnu 2>&1 | FileCheck -check-prefix=CHECK-ASAN-UNKNOWN %s +// CHECK-ASAN-UNKNOWN: x86_64-unknown-linux-gnu/libclang_rt.asan_static.a _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits