Skip to content

Commit

Permalink
[CHERI-RISC-V] Use suffixed sanitizer libraries for purecap
Browse files Browse the repository at this point in the history
Since both the plain RISC-V and purecap RISC-V compiler-rt libraries will
be installed to the same directory we have to use a different name for
the purecap ones. This patch uses a "c" suffix for the purecap ones.
  • Loading branch information
arichardson committed Sep 30, 2021
1 parent de6704f commit f5ac08e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
22 changes: 14 additions & 8 deletions clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ Tool *ToolChain::getTool(Action::ActionClass AC) const {
llvm_unreachable("Invalid tool kind.");
}

static StringRef getArchNameForCompilerRTLib(const ToolChain &TC,
const ArgList &Args) {
static std::string getArchNameForCompilerRTLib(const ToolChain &TC,
const ArgList &Args) {
const llvm::Triple &Triple = TC.getTriple();
bool IsWindows = Triple.isOSWindows();

Expand All @@ -398,15 +398,21 @@ static StringRef getArchNameForCompilerRTLib(const ToolChain &TC,
if (TC.getArch() == llvm::Triple::x86 && Triple.isAndroid())
return "i686";

if (Triple.isMIPS() && Triple.getEnvironment() == llvm::Triple::CheriPurecap) {
assert(Triple.getSubArch() != llvm::Triple::NoSubArch && "purecap triple should have subarch");
return Triple.getArchName();
if (Triple.isMIPS() && TC.isCheriPurecap()) {
// Purecap MIPS uses mips64c128 as the library name.
assert(Triple.getSubArch() != llvm::Triple::NoSubArch &&
"purecap triple should have subarch");
return Triple.getArchName().str();
}

if (TC.getArch() == llvm::Triple::x86_64 && Triple.isX32())
return "x32";

return llvm::Triple::getArchTypeName(TC.getArch());
std::string Result = llvm::Triple::getArchTypeName(TC.getArch()).str();
// For other purecap architectures we append a single "c" to the library name.
if (TC.isCheriPurecap())
Result += "c";
return Result;
}

StringRef ToolChain::getOSLibName() const {
Expand Down Expand Up @@ -473,9 +479,9 @@ std::string ToolChain::buildCompilerRTBasename(const llvm::opt::ArgList &Args,

std::string ArchAndEnv;
if (AddArch) {
StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
std::string Arch = getArchNameForCompilerRTLib(*this, Args);
const char *Env = TT.isAndroid() ? "-android" : "";
ArchAndEnv = ("-" + Arch + Env).str();
ArchAndEnv = "-" + Arch + Env;
}
return (Prefix + Twine("clang_rt.") + Component + ArchAndEnv + Suffix).str();
}
Expand Down
8 changes: 4 additions & 4 deletions clang/test/Driver/cheri/freebsd-sanitizer-libnames.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
// UBSAN-SAME: "-fsanitize-recover=alignment,array-bounds,
// UBSAN-NEXT: "/usr/bin/ld"
// UBSAN-RISCV64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-riscv64.a"
// UBSAN-PURECAP-RISCV64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-riscv64.a"
// UBSAN-PURECAP-RISCV64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-riscv64c.a"
// UBSAN-RISCV32-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-riscv32.a"
// UBSAN-PURECAP-RISCV32-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-riscv32.a"
// UBSAN-PURECAP-RISCV32-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-riscv32c.a"
// UBSAN-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-mips64.a"
// UBSAN-PURECAP-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_standalone-mips64c128.a"

Expand All @@ -40,9 +40,9 @@
// UBSAN-MINIMAL-SAME: "-fsanitize-recover=alignment,array-bounds,
// UBSAN-MINIMAL-NEXT: "/usr/bin/ld"
// UBSAN-MINIMAL-RISCV64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-riscv64.a"
// UBSAN-MINIMAL-PURECAP-RISCV64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-riscv64.a"
// UBSAN-MINIMAL-PURECAP-RISCV64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-riscv64c.a"
// UBSAN-MINIMAL-RISCV32-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-riscv32.a"
// UBSAN-MINIMAL-PURECAP-RISCV32-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-riscv32.a"
// UBSAN-MINIMAL-PURECAP-RISCV32-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-riscv32c.a"
// UBSAN-MINIMAL-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-mips64.a"
// UBSAN-MINIMAL-PURECAP-MIPS64-SAME: "[[RESOURCE_DIR]]/lib/freebsd/libclang_rt.ubsan_minimal-mips64c128.a"

Expand Down

0 comments on commit f5ac08e

Please sign in to comment.