diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp --- a/clang/lib/Driver/ToolChain.cpp +++ b/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 &Paths) + -> llvm::Optional { + 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. diff --git a/clang/test/Driver/Inputs/baremetal_sysroot_with_compiler_rt/lib/libclang_rt.builtins-riscv64.a b/clang/test/Driver/Inputs/baremetal_sysroot_with_compiler_rt/lib/libclang_rt.builtins-riscv64.a new file mode 100644 diff --git a/clang/test/Driver/baremetal-sysroot-with-compiler-rt.c b/clang/test/Driver/baremetal-sysroot-with-compiler-rt.c new file mode 100644 --- /dev/null +++ b/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.a