-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[RFC] [clang][Toolchain] Treat "pc"/"unknown" vendor interchangeable #97802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Azat Khuzhin (azat) ChangesRight now if you have runtime libraries under 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 Fixes: #95792 Full diff: https://github.com/llvm/llvm-project/pull/97802.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 977e08390800d7..716cbfb43232b6 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 00000000000000..a7e9bb80b0f2d6
--- /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
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
dd290dd
to
c2d4c46
Compare
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
c2d4c46
to
1d78d83
Compare
I've excluded new test for windows (https://buildkite.com/llvm-project/github-pull-requests/builds/78458) |
How is Rust built? If the system compiler-rt libraries are installed to If we don't consider Rust, Clang itself can find the library whether or not "pc" or "unknown" is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
The problem is not only with Rust, it is any invocation with non-default Here is an example of a problem (assuming
Maybe you have better/proper idea on how this should be addressed? |
@MaskRay you still think that it does not worth to make this two targets ( |
If you specify the wrong If you mix target triples for LTO you will get warnings:
Try fixing the build system issue instead:) I hope that we don't make Clang less strict. |
But isn't this odd, that you depends on |
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.
Fixes: #95792