Skip to content

Commit

Permalink
[clang] enable sanitizers for hexagon
Browse files Browse the repository at this point in the history
  • Loading branch information
androm3da committed Aug 18, 2021
1 parent f288032 commit 59dfde7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions clang/lib/Driver/ToolChains/Hexagon.cpp
Expand Up @@ -146,6 +146,8 @@ void hexagon::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
"-mcpu=hexagon" +
toolchains::HexagonToolChain::GetTargetCPUVersion(Args)));

addSanitizerRuntimes(HTC, Args, CmdArgs);

if (Output.isFilename()) {
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
Expand Down Expand Up @@ -223,6 +225,8 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
bool UseShared = IsShared && !IsStatic;
StringRef CpuVer = toolchains::HexagonToolChain::GetTargetCPUVersion(Args);

bool NeedsSanitizerDeps = addSanitizerRuntimes(HTC, Args, CmdArgs);

//----------------------------------------------------------------------------
// Silence warnings for various options
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -288,6 +292,12 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);

if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
if (NeedsSanitizerDeps) {
linkSanitizerRuntimeDeps(HTC, CmdArgs);

CmdArgs.push_back("-lunwind");
}

CmdArgs.push_back("-lclang_rt.builtins-hexagon");
CmdArgs.push_back("-lc");
}
Expand Down Expand Up @@ -450,6 +460,13 @@ Optional<unsigned> HexagonToolChain::getSmallDataThreshold(
return None;
}

std::string HexagonToolChain::getCompilerRTPath() const {
SmallString<128> Dir(getDriver().SysRoot);
llvm::sys::path::append(Dir, "usr", "lib");
Dir += SelectedMultilib.gccSuffix();
return std::string(Dir.str());
}

void HexagonToolChain::getHexagonLibraryPaths(const ArgList &Args,
ToolChain::path_list &LibPaths) const {
const Driver &D = getDriver();
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/Hexagon.h
Expand Up @@ -104,6 +104,8 @@ class LLVM_LIBRARY_VISIBILITY HexagonToolChain : public Linux {
void getHexagonLibraryPaths(const llvm::opt::ArgList &Args,
ToolChain::path_list &LibPaths) const;

std::string getCompilerRTPath() const override;

static bool isAutoHVXEnabled(const llvm::opt::ArgList &Args);
static const StringRef GetDefaultCPU();
static const StringRef GetTargetCPUVersion(const llvm::opt::ArgList &Args);
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Driver/ToolChains/Linux.cpp
Expand Up @@ -694,6 +694,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
getTriple().getArch() == llvm::Triple::thumbeb;
const bool IsRISCV64 = getTriple().getArch() == llvm::Triple::riscv64;
const bool IsSystemZ = getTriple().getArch() == llvm::Triple::systemz;
const bool IsHexagon = getTriple().getArch() == llvm::Triple::hexagon;
SanitizerMask Res = ToolChain::getSupportedSanitizers();
Res |= SanitizerKind::Address;
Res |= SanitizerKind::PointerCompare;
Expand All @@ -707,7 +708,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
if (IsX86_64 || IsMIPS64 || IsAArch64)
Res |= SanitizerKind::DataFlow;
if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch || IsPowerPC64 ||
IsRISCV64 || IsSystemZ)
IsRISCV64 || IsSystemZ || IsHexagon)
Res |= SanitizerKind::Leak;
if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64 || IsSystemZ)
Res |= SanitizerKind::Thread;
Expand All @@ -716,7 +717,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
if (IsX86 || IsX86_64)
Res |= SanitizerKind::Function;
if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsMIPS || IsArmArch ||
IsPowerPC64)
IsPowerPC64 || IsHexagon)
Res |= SanitizerKind::Scudo;
if (IsX86_64 || IsAArch64) {
Res |= SanitizerKind::HWAddress;
Expand Down

0 comments on commit 59dfde7

Please sign in to comment.