[clang] [RFC] [clang][Toolchain] Treat "pc"/"unknown" vendor interchangeable (PR #97802)
Azat Khuzhin via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 5 02:26:06 PDT 2024
https://github.com/azat created https://github.com/llvm/llvm-project/pull/97802
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
>From dd290ddc48fd60d29e2c0eb839f9e9a08746d5f2 Mon Sep 17 00:00:00 2001
From: Azat Khuzhin <a3at.mail at 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 | 21 +++++++++++++++++++++
clang/test/Driver/pc-unknown-toolchain.c | 4 ++++
2 files changed, 25 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..716cbfb43232b 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -765,6 +765,27 @@ 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..a7e9bb80b0f2d
--- /dev/null
+++ b/clang/test/Driver/pc-unknown-toolchain.c
@@ -0,0 +1,4 @@
+// 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
More information about the cfe-commits
mailing list