[PATCH] D110663: [Driver] Support Debian multiarch style lib/clang/14.0.0/x86_64-linux-gnu runtime path

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 28 15:14:46 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: phosek, sylvestre.ledru.
Herald added a subscriber: pengfei.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is needed when config.guess is removed (D109837 <https://reviews.llvm.org/D109837>) and
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on is enabled.

If LLVM_DEFAULT_TARGET_TRIPLE is Debian multiarch style "x86_64-linux-gnu"
(`gcc -dumpmachine` output), CMake will install runtime libraries to
`lib/clang/14.0.0/x86_64-linux-gnu/` but `clang --print-runtime-dir` still use
`lib/clang/14.0.0/x86_64-known-linux-gnu/` (inferred from the normalized triple:
"x86_64-known-linux-gnu").

Alternative: it would probably be nice to not normalize triples in
`Driver.cpp:computeTargetTriple`, but the complexity would be very high.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110663

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/linux-per-target-runtime-dir.c


Index: clang/test/Driver/linux-per-target-runtime-dir.c
===================================================================
--- clang/test/Driver/linux-per-target-runtime-dir.c
+++ clang/test/Driver/linux-per-target-runtime-dir.c
@@ -25,3 +25,10 @@
 // RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-X8664 %s
 // CHECK-FILE-NAME-X8664: lib{{/|\\}}x86_64-unknown-linux-gnu{{/|\\}}libclang_rt.builtins.a
+
+/// On Debian, LLVM_DEFAULT_TARGET_TRIPLE may use Debian multiarch style "x86_64-linux-gnu".
+// RUN: %clangxx -### %s --target=x86_64-linux-gnu --sysroot=%S/Inputs/basic_linux_libcxx_tree \
+// RUN:   -ccc-install-dir %S/Inputs/basic_linux_libcxx_tree/usr/bin \
+// RUN:   -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir_debian \
+// RUN:   --rtlib=compiler-rt 2>&1 | FileCheck --check-prefix=CHECK-DEBIAN-X8664 %s
+// CHECK-DEBIAN-X8664: lib{{/|\\}}x86_64-linux-gnu{{/|\\}}libclang_rt.builtins.a
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -490,7 +490,18 @@
 std::string ToolChain::getRuntimePath() const {
   SmallString<128> P(D.ResourceDir);
   llvm::sys::path::append(P, "lib", getTripleString());
-  return std::string(P.str());
+  std::string Ret(P);
+  // When LLVM_DEFAULT_TARGET_TRIPLE uses Debian multiarch style
+  // "x86_64-linux-gnu" (no vendor part), use the unnormalized
+  // D.getTargetTriple() instead of the normalized getTripleString()
+  // ("x86_64-unknown-linux-gnu").
+  if (!getVFS().exists(Ret)) {
+    P.clear();
+    llvm::sys::path::append(P, D.ResourceDir, "lib", D.getTargetTriple());
+    if (getVFS().exists(P))
+      Ret = std::string(P);
+  }
+  return Ret;
 }
 
 std::string ToolChain::getStdlibPath() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110663.375719.patch
Type: text/x-patch
Size: 1880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210928/3cdd6b39/attachment-0001.bin>


More information about the cfe-commits mailing list