Skip to content

Commit 1d78d83

Browse files
committed
[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
1 parent 687531f commit 1d78d83

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,26 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
765765
if (auto Path = getPathForTriple(getTriple()))
766766
return *Path;
767767

768+
// Treat "pc" and "unknown" vendors interchangeable
769+
switch (getTriple().getVendor()) {
770+
case Triple::UnknownVendor: {
771+
llvm::Triple TripleFallback = Triple;
772+
TripleFallback.setVendor(Triple::PC);
773+
if (auto Path = getPathForTriple(TripleFallback))
774+
return *Path;
775+
break;
776+
}
777+
case Triple::PC: {
778+
llvm::Triple TripleFallback = Triple;
779+
TripleFallback.setVendor(Triple::UnknownVendor);
780+
if (auto Path = getPathForTriple(TripleFallback))
781+
return *Path;
782+
break;
783+
}
784+
default:
785+
break;
786+
}
787+
768788
// When building with per target runtime directories, various ways of naming
769789
// the Arm architecture may have been normalised to simply "arm".
770790
// For example "armv8l" (Armv8 AArch32 little endian) is replaced with "arm".
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// UNSUPPORTED: system-windows
2+
3+
// RUN: %clang -### %s -fsanitize=address --target=x86_64-pc-linux-gnu 2>&1 | FileCheck -check-prefix=CHECK-ASAN-PC %s
4+
// CHECK-ASAN-PC: x86_64-unknown-linux-gnu/libclang_rt.asan_static.a
5+
// RUN: %clang -### %s -fsanitize=address --target=x86_64-unknown-linux-gnu 2>&1 | FileCheck -check-prefix=CHECK-ASAN-UNKNOWN %s
6+
// CHECK-ASAN-UNKNOWN: x86_64-unknown-linux-gnu/libclang_rt.asan_static.a

0 commit comments

Comments
 (0)