Skip to content

Commit 8315167

Browse files
[Driver][RISCV] Fix incorrect compiler-rt path override in BareMetal toolchain after RISCVToolChain removal (#146849)
The RISCVToolChain, which was removed in commit f8cb798, used a different compiler-rt path relative to the resource-dir when GCCInstallation was valid. However, this behavior was unintentionally overridden when it was merged into the BareMetal toolchain. This patch restores the correct path handling logic. After this fix - With valid GCCInstallation `<resource-dir>/<llvm-rel-ver>/lib/<target-triple>libclang_rt.builtins.a` Without valid GCCInstallation `<resource-dir>/<llvm-rel-ver>/lib/baremetal/libclang_rt.builtins-<target>.a`
1 parent ae44138 commit 8315167

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

clang/lib/Driver/ToolChains/BareMetal.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ std::string BareMetal::computeSysRoot() const {
206206
return computeClangRuntimesSysRoot(D, /*IncludeTriple*/ true);
207207
}
208208

209+
std::string BareMetal::getCompilerRTPath() const {
210+
const Driver &D = getDriver();
211+
if (IsGCCInstallationValid || detectGCCToolchainAdjacent(getDriver())) {
212+
SmallString<128> Path(D.ResourceDir);
213+
llvm::sys::path::append(Path, "lib");
214+
return std::string(Path.str());
215+
}
216+
return ToolChain::getCompilerRTPath();
217+
}
218+
209219
static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs,
210220
const Multilib &Multilib,
211221
StringRef InstallPath,

clang/lib/Driver/ToolChains/BareMetal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF {
7676
addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
7777
llvm::opt::ArgStringList &CC1Args) const override;
7878
std::string computeSysRoot() const override;
79+
std::string getCompilerRTPath() const override;
7980
SanitizerMask getSupportedSanitizers() const override;
8081

8182
SmallVector<std::string>

clang/test/Driver/print-libgcc-file-name-clangrt.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@
6363
// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir 2>&1 \
6464
// RUN: | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET %s
6565
// CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET: libclang_rt.builtins.a
66+
67+
// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name \
68+
// RUN: --target=riscv32-unknown-elf \
69+
// RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
70+
// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
71+
// RUN: --gcc-toolchain=%S/Inputs/basic_riscv32_tree 2>&1 \
72+
// RUN: | FileCheck --check-prefix=CHECK-CLANGRT-RISCV-BAREMETAL %s
73+
// CHECK-CLANGRT-RISCV-BAREMETAL-NOT: baremetal{{/|\\}}libclang_rt.builtins-riscv32.a
74+
// CHECK-CLANGRT-RISCV-BAREMETAL: libclang_rt.builtins.a

0 commit comments

Comments
 (0)