Skip to content

Commit 59dfde7

Browse files
committed
[clang] enable sanitizers for hexagon
1 parent f288032 commit 59dfde7

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

clang/lib/Driver/ToolChains/Hexagon.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ void hexagon::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
146146
"-mcpu=hexagon" +
147147
toolchains::HexagonToolChain::GetTargetCPUVersion(Args)));
148148

149+
addSanitizerRuntimes(HTC, Args, CmdArgs);
150+
149151
if (Output.isFilename()) {
150152
CmdArgs.push_back("-o");
151153
CmdArgs.push_back(Output.getFilename());
@@ -223,6 +225,8 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
223225
bool UseShared = IsShared && !IsStatic;
224226
StringRef CpuVer = toolchains::HexagonToolChain::GetTargetCPUVersion(Args);
225227

228+
bool NeedsSanitizerDeps = addSanitizerRuntimes(HTC, Args, CmdArgs);
229+
226230
//----------------------------------------------------------------------------
227231
// Silence warnings for various options
228232
//----------------------------------------------------------------------------
@@ -288,6 +292,12 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
288292
AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
289293

290294
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
295+
if (NeedsSanitizerDeps) {
296+
linkSanitizerRuntimeDeps(HTC, CmdArgs);
297+
298+
CmdArgs.push_back("-lunwind");
299+
}
300+
291301
CmdArgs.push_back("-lclang_rt.builtins-hexagon");
292302
CmdArgs.push_back("-lc");
293303
}
@@ -450,6 +460,13 @@ Optional<unsigned> HexagonToolChain::getSmallDataThreshold(
450460
return None;
451461
}
452462

463+
std::string HexagonToolChain::getCompilerRTPath() const {
464+
SmallString<128> Dir(getDriver().SysRoot);
465+
llvm::sys::path::append(Dir, "usr", "lib");
466+
Dir += SelectedMultilib.gccSuffix();
467+
return std::string(Dir.str());
468+
}
469+
453470
void HexagonToolChain::getHexagonLibraryPaths(const ArgList &Args,
454471
ToolChain::path_list &LibPaths) const {
455472
const Driver &D = getDriver();

clang/lib/Driver/ToolChains/Hexagon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class LLVM_LIBRARY_VISIBILITY HexagonToolChain : public Linux {
104104
void getHexagonLibraryPaths(const llvm::opt::ArgList &Args,
105105
ToolChain::path_list &LibPaths) const;
106106

107+
std::string getCompilerRTPath() const override;
108+
107109
static bool isAutoHVXEnabled(const llvm::opt::ArgList &Args);
108110
static const StringRef GetDefaultCPU();
109111
static const StringRef GetTargetCPUVersion(const llvm::opt::ArgList &Args);

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
694694
getTriple().getArch() == llvm::Triple::thumbeb;
695695
const bool IsRISCV64 = getTriple().getArch() == llvm::Triple::riscv64;
696696
const bool IsSystemZ = getTriple().getArch() == llvm::Triple::systemz;
697+
const bool IsHexagon = getTriple().getArch() == llvm::Triple::hexagon;
697698
SanitizerMask Res = ToolChain::getSupportedSanitizers();
698699
Res |= SanitizerKind::Address;
699700
Res |= SanitizerKind::PointerCompare;
@@ -707,7 +708,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
707708
if (IsX86_64 || IsMIPS64 || IsAArch64)
708709
Res |= SanitizerKind::DataFlow;
709710
if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch || IsPowerPC64 ||
710-
IsRISCV64 || IsSystemZ)
711+
IsRISCV64 || IsSystemZ || IsHexagon)
711712
Res |= SanitizerKind::Leak;
712713
if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64 || IsSystemZ)
713714
Res |= SanitizerKind::Thread;
@@ -716,7 +717,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
716717
if (IsX86 || IsX86_64)
717718
Res |= SanitizerKind::Function;
718719
if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsMIPS || IsArmArch ||
719-
IsPowerPC64)
720+
IsPowerPC64 || IsHexagon)
720721
Res |= SanitizerKind::Scudo;
721722
if (IsX86_64 || IsAArch64) {
722723
Res |= SanitizerKind::HWAddress;

0 commit comments

Comments
 (0)