jrtc27 created this revision. jrtc27 added reviewers: jroelofs, abidh, manojgupta, asb, luismarques. Herald added subscribers: frasercrmck, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, niosHD, sabuasal, simoncook, johnrusso, rbar, dberris, ki.stfu. jrtc27 requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
LibraryPaths is rather underused in Clang, unlike FilePaths. The latter notably includes the sysroot for bare-metal toolchains, so this allows compiler-rt to be found alongside the other libraries shipped as part of a sysroot rather than requiring it to be bundled with Clang, allowing bare-metal sysroots to behave much more like real OS sysroots. This is particularly useful for RISC-V where there is an abundance of possible ISA and ABI choices, but the architecture suffix added to the library name only captures the architectural word size. Putting them in ISA and ABI-specific sysroots is the easiest way to allow multiple configurations to coexist on the system given that such sysroots already must exist with the system headers and precompiled libc. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D98113 Files: clang/lib/Driver/ToolChain.cpp clang/test/Driver/Inputs/baremetal_sysroot_with_compiler_rt/lib/libclang_rt.builtins-riscv64.a clang/test/Driver/baremetal-sysroot-with-compiler-rt.c Index: clang/test/Driver/baremetal-sysroot-with-compiler-rt.c =================================================================== --- /dev/null +++ clang/test/Driver/baremetal-sysroot-with-compiler-rt.c @@ -0,0 +1,6 @@ +// RUN: %clang -target riscv64 \ +// RUN: --sysroot=%S/Inputs/baremetal_sysroot_with_compiler_rt \ +// RUN: -rtlib=compiler-rt \ +// RUN: -print-libgcc-file-name \ +// RUN: | FileCheck %s +// CHECK: {{.*[/\\]}}Inputs/baremetal_sysroot_with_compiler_rt{{[/\\]}}lib{{[/\\]}}libclang_rt.builtins-riscv64.a Index: clang/lib/Driver/ToolChain.cpp =================================================================== --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -459,12 +459,22 @@ // Check for runtime files in the new layout without the architecture first. std::string CRTBasename = buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false); - for (const auto &LibPath : getLibraryPaths()) { - SmallString<128> P(LibPath); - llvm::sys::path::append(P, CRTBasename); - if (getVFS().exists(P)) - return std::string(P.str()); - } + auto SearchPaths = [&](const llvm::SmallVectorImpl<std::string> &Paths) + -> llvm::Optional<std::string> { + for (const auto &LibPath : Paths) { + SmallString<128> P(LibPath); + llvm::sys::path::append(P, CRTBasename); + if (getVFS().exists(P)) + return std::string(P.str()); + } + return None; + }; + + if (auto P = SearchPaths(getLibraryPaths())) + return *P; + + if (auto P = SearchPaths(getFilePaths())) + return *P; // Fall back to the old expected compiler-rt name if the new one does not // exist.
Index: clang/test/Driver/baremetal-sysroot-with-compiler-rt.c =================================================================== --- /dev/null +++ clang/test/Driver/baremetal-sysroot-with-compiler-rt.c @@ -0,0 +1,6 @@ +// RUN: %clang -target riscv64 \ +// RUN: --sysroot=%S/Inputs/baremetal_sysroot_with_compiler_rt \ +// RUN: -rtlib=compiler-rt \ +// RUN: -print-libgcc-file-name \ +// RUN: | FileCheck %s +// CHECK: {{.*[/\\]}}Inputs/baremetal_sysroot_with_compiler_rt{{[/\\]}}lib{{[/\\]}}libclang_rt.builtins-riscv64.a Index: clang/lib/Driver/ToolChain.cpp =================================================================== --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -459,12 +459,22 @@ // Check for runtime files in the new layout without the architecture first. std::string CRTBasename = buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false); - for (const auto &LibPath : getLibraryPaths()) { - SmallString<128> P(LibPath); - llvm::sys::path::append(P, CRTBasename); - if (getVFS().exists(P)) - return std::string(P.str()); - } + auto SearchPaths = [&](const llvm::SmallVectorImpl<std::string> &Paths) + -> llvm::Optional<std::string> { + for (const auto &LibPath : Paths) { + SmallString<128> P(LibPath); + llvm::sys::path::append(P, CRTBasename); + if (getVFS().exists(P)) + return std::string(P.str()); + } + return None; + }; + + if (auto P = SearchPaths(getLibraryPaths())) + return *P; + + if (auto P = SearchPaths(getFilePaths())) + return *P; // Fall back to the old expected compiler-rt name if the new one does not // exist.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits