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 {
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 {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits