|
@@ -21,52 +21,33 @@
|
|
#include <memory>
|
|
#include <memory>
|
|
|
|
|
|
using namespace clang;
|
|
using namespace clang;
|
|
|
|
+using namespace clang::SanitizerKind;
|
|
using namespace clang::driver;
|
|
using namespace clang::driver;
|
|
using namespace llvm::opt;
|
|
using namespace llvm::opt;
|
|
|
|
|
|
-static const SanitizerMask NeedsUbsanRt =
|
|
|
|
- SanitizerKind::Undefined | SanitizerKind::Integer |
|
|
|
|
- SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
|
|
|
|
- SanitizerKind::CFI;
|
|
|
|
-static const SanitizerMask NeedsUbsanCxxRt =
|
|
|
|
- SanitizerKind::Vptr | SanitizerKind::CFI;
|
|
|
|
-static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr;
|
|
|
|
-static const SanitizerMask NotAllowedWithMinimalRuntime = SanitizerKind::Vptr;
|
|
|
|
-static const SanitizerMask RequiresPIE =
|
|
|
|
- SanitizerKind::DataFlow | SanitizerKind::HWAddress | SanitizerKind::Scudo;
|
|
|
|
-static const SanitizerMask NeedsUnwindTables =
|
|
|
|
- SanitizerKind::Address | SanitizerKind::HWAddress | SanitizerKind::Thread |
|
|
|
|
- SanitizerKind::Memory | SanitizerKind::DataFlow;
|
|
|
|
-static const SanitizerMask SupportsCoverage =
|
|
|
|
- SanitizerKind::Address | SanitizerKind::HWAddress |
|
|
|
|
- SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress |
|
|
|
|
- SanitizerKind::Memory | SanitizerKind::KernelMemory | SanitizerKind::Leak |
|
|
|
|
- SanitizerKind::Undefined | SanitizerKind::Integer |
|
|
|
|
- SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
|
|
|
|
- SanitizerKind::DataFlow | SanitizerKind::Fuzzer |
|
|
|
|
- SanitizerKind::FuzzerNoLink;
|
|
|
|
-static const SanitizerMask RecoverableByDefault =
|
|
|
|
- SanitizerKind::Undefined | SanitizerKind::Integer |
|
|
|
|
- SanitizerKind::ImplicitConversion | SanitizerKind::Nullability;
|
|
|
|
-static const SanitizerMask Unrecoverable =
|
|
|
|
- SanitizerKind::Unreachable | SanitizerKind::Return;
|
|
|
|
-static const SanitizerMask AlwaysRecoverable =
|
|
|
|
- SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress;
|
|
|
|
-static const SanitizerMask LegacyFsanitizeRecoverMask =
|
|
|
|
- SanitizerKind::Undefined | SanitizerKind::Integer;
|
|
|
|
-static const SanitizerMask NeedsLTO = SanitizerKind::CFI;
|
|
|
|
-static const SanitizerMask TrappingSupported =
|
|
|
|
- (SanitizerKind::Undefined & ~SanitizerKind::Vptr) |
|
|
|
|
- SanitizerKind::UnsignedIntegerOverflow | SanitizerKind::ImplicitConversion |
|
|
|
|
- SanitizerKind::Nullability | SanitizerKind::LocalBounds |
|
|
|
|
- SanitizerKind::CFI;
|
|
|
|
-static const SanitizerMask TrappingDefault = SanitizerKind::CFI;
|
|
|
|
-static const SanitizerMask CFIClasses =
|
|
|
|
- SanitizerKind::CFIVCall | SanitizerKind::CFINVCall |
|
|
|
|
- SanitizerKind::CFIMFCall | SanitizerKind::CFIDerivedCast |
|
|
|
|
- SanitizerKind::CFIUnrelatedCast;
|
|
|
|
-static const SanitizerMask CompatibleWithMinimalRuntime =
|
|
|
|
- TrappingSupported | SanitizerKind::Scudo | SanitizerKind::ShadowCallStack;
|
|
|
|
|
|
+enum : SanitizerMask {
|
|
|
|
+ NeedsUbsanRt = Undefined | Integer | ImplicitConversion | Nullability | CFI,
|
|
|
|
+ NeedsUbsanCxxRt = Vptr | CFI,
|
|
|
|
+ NotAllowedWithTrap = Vptr,
|
|
|
|
+ NotAllowedWithMinimalRuntime = Vptr,
|
|
|
|
+ RequiresPIE = DataFlow | HWAddress | Scudo,
|
|
|
|
+ NeedsUnwindTables = Address | HWAddress | Thread | Memory | DataFlow,
|
|
|
|
+ SupportsCoverage = Address | HWAddress | KernelAddress | KernelHWAddress |
|
|
|
|
+ Memory | KernelMemory | Leak | Undefined | Integer |
|
|
|
|
+ ImplicitConversion | Nullability | DataFlow | Fuzzer |
|
|
|
|
+ FuzzerNoLink,
|
|
|
|
+ RecoverableByDefault = Undefined | Integer | ImplicitConversion | Nullability,
|
|
|
|
+ Unrecoverable = Unreachable | Return,
|
|
|
|
+ AlwaysRecoverable = KernelAddress | KernelHWAddress,
|
|
|
|
+ LegacyFsanitizeRecoverMask = Undefined | Integer,
|
|
|
|
+ NeedsLTO = CFI,
|
|
|
|
+ TrappingSupported = (Undefined & ~Vptr) | UnsignedIntegerOverflow |
|
|
|
|
+ ImplicitConversion | Nullability | LocalBounds | CFI,
|
|
|
|
+ TrappingDefault = CFI,
|
|
|
|
+ CFIClasses =
|
|
|
|
+ CFIVCall | CFINVCall | CFIMFCall | CFIDerivedCast | CFIUnrelatedCast,
|
|
|
|
+ CompatibleWithMinimalRuntime = TrappingSupported | Scudo | ShadowCallStack,
|
|
|
|
+};
|
|
|
|
|
|
enum CoverageFeature {
|
|
enum CoverageFeature {
|
|
CoverageFunc = 1 << 0,
|
|
CoverageFunc = 1 << 0,
|
|
@@ -119,15 +100,13 @@ static void addDefaultBlacklists(const Driver &D, SanitizerMask Kinds,
|
|
struct Blacklist {
|
|
struct Blacklist {
|
|
const char *File;
|
|
const char *File;
|
|
SanitizerMask Mask;
|
|
SanitizerMask Mask;
|
|
- } Blacklists[] = {{"asan_blacklist.txt", SanitizerKind::Address},
|
|
|
|
- {"hwasan_blacklist.txt", SanitizerKind::HWAddress},
|
|
|
|
- {"msan_blacklist.txt", SanitizerKind::Memory},
|
|
|
|
- {"tsan_blacklist.txt", SanitizerKind::Thread},
|
|
|
|
- {"dfsan_abilist.txt", SanitizerKind::DataFlow},
|
|
|
|
- {"cfi_blacklist.txt", SanitizerKind::CFI},
|
|
|
|
- {"ubsan_blacklist.txt", SanitizerKind::Undefined |
|
|
|
|
- SanitizerKind::Integer |
|
|
|
|
- SanitizerKind::Nullability}};
|
|
|
|
|
|
+ } Blacklists[] = {{"asan_blacklist.txt", Address},
|
|
|
|
+ {"hwasan_blacklist.txt", HWAddress},
|
|
|
|
+ {"msan_blacklist.txt", Memory},
|
|
|
|
+ {"tsan_blacklist.txt", Thread},
|
|
|
|
+ {"dfsan_abilist.txt", DataFlow},
|
|
|
|
+ {"cfi_blacklist.txt", CFI},
|
|
|
|
+ {"ubsan_blacklist.txt", Undefined | Integer | Nullability}};
|
|
|
|
|
|
for (auto BL : Blacklists) {
|
|
for (auto BL : Blacklists) {
|
|
if (!(Kinds & BL.Mask))
|
|
if (!(Kinds & BL.Mask))
|
|
@@ -137,7 +116,7 @@ static void addDefaultBlacklists(const Driver &D, SanitizerMask Kinds,
|
|
llvm::sys::path::append(Path, "share", BL.File);
|
|
llvm::sys::path::append(Path, "share", BL.File);
|
|
if (llvm::sys::fs::exists(Path))
|
|
if (llvm::sys::fs::exists(Path))
|
|
BlacklistFiles.push_back(Path.str());
|
|
BlacklistFiles.push_back(Path.str());
|
|
- else if (BL.Mask == SanitizerKind::CFI)
|
|
|
|
|
|
+ else if (BL.Mask == CFI)
|
|
// If cfi_blacklist.txt cannot be found in the resource dir, driver
|
|
// If cfi_blacklist.txt cannot be found in the resource dir, driver
|
|
// should fail.
|
|
// should fail.
|
|
D.Diag(clang::diag::err_drv_no_such_file) << Path;
|
|
D.Diag(clang::diag::err_drv_no_such_file) << Path;
|
|
@@ -157,10 +136,10 @@ static SanitizerMask setGroupBits(SanitizerMask Kinds) {
|
|
|
|
|
|
static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
|
|
static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
|
|
const llvm::opt::ArgList &Args) {
|
|
const llvm::opt::ArgList &Args) {
|
|
- SanitizerMask TrapRemove; // During the loop below, the accumulated set of
|
|
|
|
|
|
+ SanitizerMask TrapRemove = 0; // During the loop below, the accumulated set of
|
|
// sanitizers disabled by the current sanitizer
|
|
// sanitizers disabled by the current sanitizer
|
|
// argument or any argument after it.
|
|
// argument or any argument after it.
|
|
- SanitizerMask TrappingKinds;
|
|
|
|
|
|
+ SanitizerMask TrappingKinds = 0;
|
|
SanitizerMask TrappingSupportedWithGroups = setGroupBits(TrappingSupported);
|
|
SanitizerMask TrappingSupportedWithGroups = setGroupBits(TrappingSupported);
|
|
|
|
|
|
for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend();
|
|
for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend();
|
|
@@ -184,12 +163,11 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
|
|
options::OPT_fsanitize_undefined_trap_on_error)) {
|
|
options::OPT_fsanitize_undefined_trap_on_error)) {
|
|
Arg->claim();
|
|
Arg->claim();
|
|
TrappingKinds |=
|
|
TrappingKinds |=
|
|
- expandSanitizerGroups(SanitizerKind::UndefinedGroup & ~TrapRemove) &
|
|
|
|
- ~TrapRemove;
|
|
|
|
|
|
+ expandSanitizerGroups(UndefinedGroup & ~TrapRemove) & ~TrapRemove;
|
|
} else if (Arg->getOption().matches(
|
|
} else if (Arg->getOption().matches(
|
|
options::OPT_fno_sanitize_undefined_trap_on_error)) {
|
|
options::OPT_fno_sanitize_undefined_trap_on_error)) {
|
|
Arg->claim();
|
|
Arg->claim();
|
|
- TrapRemove |= expandSanitizerGroups(SanitizerKind::UndefinedGroup);
|
|
|
|
|
|
+ TrapRemove |= expandSanitizerGroups(UndefinedGroup);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -211,13 +189,13 @@ bool SanitizerArgs::needsUbsanRt() const {
|
|
}
|
|
}
|
|
|
|
|
|
bool SanitizerArgs::needsCfiRt() const {
|
|
bool SanitizerArgs::needsCfiRt() const {
|
|
- return !(Sanitizers.Mask & SanitizerKind::CFI & ~TrapSanitizers.Mask) &&
|
|
|
|
- CfiCrossDso && !ImplicitCfiRuntime;
|
|
|
|
|
|
+ return !(Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso &&
|
|
|
|
+ !ImplicitCfiRuntime;
|
|
}
|
|
}
|
|
|
|
|
|
bool SanitizerArgs::needsCfiDiagRt() const {
|
|
bool SanitizerArgs::needsCfiDiagRt() const {
|
|
- return (Sanitizers.Mask & SanitizerKind::CFI & ~TrapSanitizers.Mask) &&
|
|
|
|
- CfiCrossDso && !ImplicitCfiRuntime;
|
|
|
|
|
|
+ return (Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso &&
|
|
|
|
+ !ImplicitCfiRuntime;
|
|
}
|
|
}
|
|
|
|
|
|
bool SanitizerArgs::requiresPIE() const {
|
|
bool SanitizerArgs::requiresPIE() const {
|
|
@@ -225,26 +203,24 @@ bool SanitizerArgs::requiresPIE() const {
|
|
}
|
|
}
|
|
|
|
|
|
bool SanitizerArgs::needsUnwindTables() const {
|
|
bool SanitizerArgs::needsUnwindTables() const {
|
|
- return static_cast<bool>(Sanitizers.Mask & NeedsUnwindTables);
|
|
|
|
|
|
+ return Sanitizers.Mask & NeedsUnwindTables;
|
|
}
|
|
}
|
|
|
|
|
|
-bool SanitizerArgs::needsLTO() const {
|
|
|
|
- return static_cast<bool>(Sanitizers.Mask & NeedsLTO);
|
|
|
|
-}
|
|
|
|
|
|
+bool SanitizerArgs::needsLTO() const { return Sanitizers.Mask & NeedsLTO; }
|
|
|
|
|
|
SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
const llvm::opt::ArgList &Args) {
|
|
const llvm::opt::ArgList &Args) {
|
|
- SanitizerMask AllRemove; // During the loop below, the accumulated set of
|
|
|
|
|
|
+ SanitizerMask AllRemove = 0; // During the loop below, the accumulated set of
|
|
// sanitizers disabled by the current sanitizer
|
|
// sanitizers disabled by the current sanitizer
|
|
// argument or any argument after it.
|
|
// argument or any argument after it.
|
|
- SanitizerMask AllAddedKinds; // Mask of all sanitizers ever enabled by
|
|
|
|
|
|
+ SanitizerMask AllAddedKinds = 0; // Mask of all sanitizers ever enabled by
|
|
// -fsanitize= flags (directly or via group
|
|
// -fsanitize= flags (directly or via group
|
|
// expansion), some of which may be disabled
|
|
// expansion), some of which may be disabled
|
|
// later. Used to carefully prune
|
|
// later. Used to carefully prune
|
|
// unused-argument diagnostics.
|
|
// unused-argument diagnostics.
|
|
- SanitizerMask DiagnosedKinds; // All Kinds we have diagnosed up to now.
|
|
|
|
|
|
+ SanitizerMask DiagnosedKinds = 0; // All Kinds we have diagnosed up to now.
|
|
// Used to deduplicate diagnostics.
|
|
// Used to deduplicate diagnostics.
|
|
- SanitizerMask Kinds;
|
|
|
|
|
|
+ SanitizerMask Kinds = 0;
|
|
const SanitizerMask Supported = setGroupBits(TC.getSupportedSanitizers());
|
|
const SanitizerMask Supported = setGroupBits(TC.getSupportedSanitizers());
|
|
|
|
|
|
CfiCrossDso = Args.hasFlag(options::OPT_fsanitize_cfi_cross_dso,
|
|
CfiCrossDso = Args.hasFlag(options::OPT_fsanitize_cfi_cross_dso,
|
|
@@ -319,12 +295,12 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
// identifiers.
|
|
// identifiers.
|
|
// Fixing both of those may require changes to the cross-DSO CFI
|
|
// Fixing both of those may require changes to the cross-DSO CFI
|
|
// interface.
|
|
// interface.
|
|
- if (CfiCrossDso && (Add & SanitizerKind::CFIMFCall & ~DiagnosedKinds)) {
|
|
|
|
|
|
+ if (CfiCrossDso && (Add & CFIMFCall & ~DiagnosedKinds)) {
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
<< "-fsanitize=cfi-mfcall"
|
|
<< "-fsanitize=cfi-mfcall"
|
|
<< "-fsanitize-cfi-cross-dso";
|
|
<< "-fsanitize-cfi-cross-dso";
|
|
- Add &= ~SanitizerKind::CFIMFCall;
|
|
|
|
- DiagnosedKinds |= SanitizerKind::CFIMFCall;
|
|
|
|
|
|
+ Add &= ~CFIMFCall;
|
|
|
|
+ DiagnosedKinds |= CFIMFCall;
|
|
}
|
|
}
|
|
|
|
|
|
if (SanitizerMask KindsToDiagnose = Add & ~Supported & ~DiagnosedKinds) {
|
|
if (SanitizerMask KindsToDiagnose = Add & ~Supported & ~DiagnosedKinds) {
|
|
@@ -338,7 +314,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
// Test for -fno-rtti + explicit -fsanitizer=vptr before expanding groups
|
|
// Test for -fno-rtti + explicit -fsanitizer=vptr before expanding groups
|
|
// so we don't error out if -fno-rtti and -fsanitize=undefined were
|
|
// so we don't error out if -fno-rtti and -fsanitize=undefined were
|
|
// passed.
|
|
// passed.
|
|
- if ((Add & SanitizerKind::Vptr) && (RTTIMode == ToolChain::RM_Disabled)) {
|
|
|
|
|
|
+ if ((Add & Vptr) && (RTTIMode == ToolChain::RM_Disabled)) {
|
|
if (const llvm::opt::Arg *NoRTTIArg = TC.getRTTIArg()) {
|
|
if (const llvm::opt::Arg *NoRTTIArg = TC.getRTTIArg()) {
|
|
assert(NoRTTIArg->getOption().matches(options::OPT_fno_rtti) &&
|
|
assert(NoRTTIArg->getOption().matches(options::OPT_fno_rtti) &&
|
|
"RTTI disabled without -fno-rtti option?");
|
|
"RTTI disabled without -fno-rtti option?");
|
|
@@ -353,7 +329,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
}
|
|
}
|
|
|
|
|
|
// Take out the Vptr sanitizer from the enabled sanitizers
|
|
// Take out the Vptr sanitizer from the enabled sanitizers
|
|
- AllRemove |= SanitizerKind::Vptr;
|
|
|
|
|
|
+ AllRemove |= Vptr;
|
|
}
|
|
}
|
|
|
|
|
|
Add = expandSanitizerGroups(Add);
|
|
Add = expandSanitizerGroups(Add);
|
|
@@ -366,14 +342,14 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
Add &= ~NotAllowedWithMinimalRuntime;
|
|
Add &= ~NotAllowedWithMinimalRuntime;
|
|
}
|
|
}
|
|
if (CfiCrossDso)
|
|
if (CfiCrossDso)
|
|
- Add &= ~SanitizerKind::CFIMFCall;
|
|
|
|
|
|
+ Add &= ~CFIMFCall;
|
|
Add &= Supported;
|
|
Add &= Supported;
|
|
|
|
|
|
- if (Add & SanitizerKind::Fuzzer)
|
|
|
|
- Add |= SanitizerKind::FuzzerNoLink;
|
|
|
|
|
|
+ if (Add & Fuzzer)
|
|
|
|
+ Add |= FuzzerNoLink;
|
|
|
|
|
|
// Enable coverage if the fuzzing flag is set.
|
|
// Enable coverage if the fuzzing flag is set.
|
|
- if (Add & SanitizerKind::FuzzerNoLink) {
|
|
|
|
|
|
+ if (Add & FuzzerNoLink) {
|
|
CoverageFeatures |= CoverageInline8bitCounters | CoverageIndirCall |
|
|
CoverageFeatures |= CoverageInline8bitCounters | CoverageIndirCall |
|
|
CoverageTraceCmp | CoveragePCTable;
|
|
CoverageTraceCmp | CoveragePCTable;
|
|
// Due to TLS differences, stack depth tracking is only enabled on Linux
|
|
// Due to TLS differences, stack depth tracking is only enabled on Linux
|
|
@@ -390,42 +366,23 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
}
|
|
}
|
|
|
|
|
|
std::pair<SanitizerMask, SanitizerMask> IncompatibleGroups[] = {
|
|
std::pair<SanitizerMask, SanitizerMask> IncompatibleGroups[] = {
|
|
- std::make_pair(SanitizerKind::Address,
|
|
|
|
- SanitizerKind::Thread | SanitizerKind::Memory),
|
|
|
|
- std::make_pair(SanitizerKind::Thread, SanitizerKind::Memory),
|
|
|
|
- std::make_pair(SanitizerKind::Leak,
|
|
|
|
- SanitizerKind::Thread | SanitizerKind::Memory),
|
|
|
|
- std::make_pair(SanitizerKind::KernelAddress,
|
|
|
|
- SanitizerKind::Address | SanitizerKind::Leak |
|
|
|
|
- SanitizerKind::Thread | SanitizerKind::Memory),
|
|
|
|
- std::make_pair(SanitizerKind::HWAddress,
|
|
|
|
- SanitizerKind::Address | SanitizerKind::Thread |
|
|
|
|
- SanitizerKind::Memory | SanitizerKind::KernelAddress),
|
|
|
|
- std::make_pair(SanitizerKind::Efficiency,
|
|
|
|
- SanitizerKind::Address | SanitizerKind::HWAddress |
|
|
|
|
- SanitizerKind::Leak | SanitizerKind::Thread |
|
|
|
|
- SanitizerKind::Memory | SanitizerKind::KernelAddress),
|
|
|
|
- std::make_pair(SanitizerKind::Scudo,
|
|
|
|
- SanitizerKind::Address | SanitizerKind::HWAddress |
|
|
|
|
- SanitizerKind::Leak | SanitizerKind::Thread |
|
|
|
|
- SanitizerKind::Memory | SanitizerKind::KernelAddress |
|
|
|
|
- SanitizerKind::Efficiency),
|
|
|
|
- std::make_pair(SanitizerKind::SafeStack,
|
|
|
|
- SanitizerKind::Address | SanitizerKind::HWAddress |
|
|
|
|
- SanitizerKind::Leak | SanitizerKind::Thread |
|
|
|
|
- SanitizerKind::Memory | SanitizerKind::KernelAddress |
|
|
|
|
- SanitizerKind::Efficiency),
|
|
|
|
- std::make_pair(SanitizerKind::KernelHWAddress,
|
|
|
|
- SanitizerKind::Address | SanitizerKind::HWAddress |
|
|
|
|
- SanitizerKind::Leak | SanitizerKind::Thread |
|
|
|
|
- SanitizerKind::Memory | SanitizerKind::KernelAddress |
|
|
|
|
- SanitizerKind::Efficiency | SanitizerKind::SafeStack),
|
|
|
|
- std::make_pair(SanitizerKind::KernelMemory,
|
|
|
|
- SanitizerKind::Address | SanitizerKind::HWAddress |
|
|
|
|
- SanitizerKind::Leak | SanitizerKind::Thread |
|
|
|
|
- SanitizerKind::Memory | SanitizerKind::KernelAddress |
|
|
|
|
- SanitizerKind::Efficiency | SanitizerKind::Scudo |
|
|
|
|
- SanitizerKind::SafeStack)};
|
|
|
|
|
|
+ std::make_pair(Address, Thread | Memory),
|
|
|
|
+ std::make_pair(Thread, Memory),
|
|
|
|
+ std::make_pair(Leak, Thread | Memory),
|
|
|
|
+ std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
|
|
|
|
+ std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
|
|
|
|
+ std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
|
|
|
|
+ KernelAddress),
|
|
|
|
+ std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
|
|
|
|
+ KernelAddress | Efficiency),
|
|
|
|
+ std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
|
|
|
|
+ KernelAddress | Efficiency),
|
|
|
|
+ std::make_pair(KernelHWAddress, Address | HWAddress | Leak | Thread |
|
|
|
|
+ Memory | KernelAddress | Efficiency |
|
|
|
|
+ SafeStack),
|
|
|
|
+ std::make_pair(KernelMemory, Address | HWAddress | Leak | Thread |
|
|
|
|
+ Memory | KernelAddress | Efficiency |
|
|
|
|
+ Scudo | SafeStack)};
|
|
// Enable toolchain specific default sanitizers if not explicitly disabled.
|
|
// Enable toolchain specific default sanitizers if not explicitly disabled.
|
|
SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
|
|
SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
|
|
|
|
|
|
@@ -441,8 +398,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
|
|
|
|
// We disable the vptr sanitizer if it was enabled by group expansion but RTTI
|
|
// We disable the vptr sanitizer if it was enabled by group expansion but RTTI
|
|
// is disabled.
|
|
// is disabled.
|
|
- if ((Kinds & SanitizerKind::Vptr) && (RTTIMode == ToolChain::RM_Disabled)) {
|
|
|
|
- Kinds &= ~SanitizerKind::Vptr;
|
|
|
|
|
|
+ if ((Kinds & Vptr) && (RTTIMode == ToolChain::RM_Disabled)) {
|
|
|
|
+ Kinds &= ~Vptr;
|
|
}
|
|
}
|
|
|
|
|
|
// Check that LTO is enabled if we need it.
|
|
// Check that LTO is enabled if we need it.
|
|
@@ -451,12 +408,12 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
<< lastArgumentForMask(D, Args, Kinds & NeedsLTO) << "-flto";
|
|
<< lastArgumentForMask(D, Args, Kinds & NeedsLTO) << "-flto";
|
|
}
|
|
}
|
|
|
|
|
|
- if ((Kinds & SanitizerKind::ShadowCallStack) &&
|
|
|
|
|
|
+ if ((Kinds & ShadowCallStack) &&
|
|
TC.getTriple().getArch() == llvm::Triple::aarch64 &&
|
|
TC.getTriple().getArch() == llvm::Triple::aarch64 &&
|
|
!llvm::AArch64::isX18ReservedByDefault(TC.getTriple()) &&
|
|
!llvm::AArch64::isX18ReservedByDefault(TC.getTriple()) &&
|
|
!Args.hasArg(options::OPT_ffixed_x18)) {
|
|
!Args.hasArg(options::OPT_ffixed_x18)) {
|
|
D.Diag(diag::err_drv_argument_only_allowed_with)
|
|
D.Diag(diag::err_drv_argument_only_allowed_with)
|
|
- << lastArgumentForMask(D, Args, Kinds & SanitizerKind::ShadowCallStack)
|
|
|
|
|
|
+ << lastArgumentForMask(D, Args, Kinds & ShadowCallStack)
|
|
<< "-ffixed-x18";
|
|
<< "-ffixed-x18";
|
|
}
|
|
}
|
|
|
|
|
|
@@ -464,12 +421,12 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
// c++abi-specific parts of UBSan runtime, and they are not provided by the
|
|
// c++abi-specific parts of UBSan runtime, and they are not provided by the
|
|
// toolchain. We don't have a good way to check the latter, so we just
|
|
// toolchain. We don't have a good way to check the latter, so we just
|
|
// check if the toolchan supports vptr.
|
|
// check if the toolchan supports vptr.
|
|
- if (~Supported & SanitizerKind::Vptr) {
|
|
|
|
|
|
+ if (~Supported & Vptr) {
|
|
SanitizerMask KindsToDiagnose = Kinds & ~TrappingKinds & NeedsUbsanCxxRt;
|
|
SanitizerMask KindsToDiagnose = Kinds & ~TrappingKinds & NeedsUbsanCxxRt;
|
|
// The runtime library supports the Microsoft C++ ABI, but only well enough
|
|
// The runtime library supports the Microsoft C++ ABI, but only well enough
|
|
// for CFI. FIXME: Remove this once we support vptr on Windows.
|
|
// for CFI. FIXME: Remove this once we support vptr on Windows.
|
|
if (TC.getTriple().isOSWindows())
|
|
if (TC.getTriple().isOSWindows())
|
|
- KindsToDiagnose &= ~SanitizerKind::CFI;
|
|
|
|
|
|
+ KindsToDiagnose &= ~CFI;
|
|
if (KindsToDiagnose) {
|
|
if (KindsToDiagnose) {
|
|
SanitizerSet S;
|
|
SanitizerSet S;
|
|
S.Mask = KindsToDiagnose;
|
|
S.Mask = KindsToDiagnose;
|
|
@@ -498,8 +455,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
|
|
|
|
// Parse -f(no-)?sanitize-recover flags.
|
|
// Parse -f(no-)?sanitize-recover flags.
|
|
SanitizerMask RecoverableKinds = RecoverableByDefault | AlwaysRecoverable;
|
|
SanitizerMask RecoverableKinds = RecoverableByDefault | AlwaysRecoverable;
|
|
- SanitizerMask DiagnosedUnrecoverableKinds;
|
|
|
|
- SanitizerMask DiagnosedAlwaysRecoverableKinds;
|
|
|
|
|
|
+ SanitizerMask DiagnosedUnrecoverableKinds = 0;
|
|
|
|
+ SanitizerMask DiagnosedAlwaysRecoverableKinds = 0;
|
|
for (const auto *Arg : Args) {
|
|
for (const auto *Arg : Args) {
|
|
const char *DeprecatedReplacement = nullptr;
|
|
const char *DeprecatedReplacement = nullptr;
|
|
if (Arg->getOption().matches(options::OPT_fsanitize_recover)) {
|
|
if (Arg->getOption().matches(options::OPT_fsanitize_recover)) {
|
|
@@ -582,7 +539,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
}
|
|
}
|
|
|
|
|
|
// Parse -f[no-]sanitize-memory-track-origins[=level] options.
|
|
// Parse -f[no-]sanitize-memory-track-origins[=level] options.
|
|
- if (AllAddedKinds & SanitizerKind::Memory) {
|
|
|
|
|
|
+ if (AllAddedKinds & Memory) {
|
|
if (Arg *A =
|
|
if (Arg *A =
|
|
Args.getLastArg(options::OPT_fsanitize_memory_track_origins_EQ,
|
|
Args.getLastArg(options::OPT_fsanitize_memory_track_origins_EQ,
|
|
options::OPT_fsanitize_memory_track_origins,
|
|
options::OPT_fsanitize_memory_track_origins,
|
|
@@ -610,19 +567,19 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
MsanUseAfterDtor = false;
|
|
MsanUseAfterDtor = false;
|
|
}
|
|
}
|
|
|
|
|
|
- if (AllAddedKinds & SanitizerKind::Thread) {
|
|
|
|
- TsanMemoryAccess = Args.hasFlag(
|
|
|
|
- options::OPT_fsanitize_thread_memory_access,
|
|
|
|
- options::OPT_fno_sanitize_thread_memory_access, TsanMemoryAccess);
|
|
|
|
- TsanFuncEntryExit = Args.hasFlag(
|
|
|
|
- options::OPT_fsanitize_thread_func_entry_exit,
|
|
|
|
- options::OPT_fno_sanitize_thread_func_entry_exit, TsanFuncEntryExit);
|
|
|
|
- TsanAtomics =
|
|
|
|
- Args.hasFlag(options::OPT_fsanitize_thread_atomics,
|
|
|
|
- options::OPT_fno_sanitize_thread_atomics, TsanAtomics);
|
|
|
|
|
|
+ if (AllAddedKinds & Thread) {
|
|
|
|
+ TsanMemoryAccess = Args.hasFlag(options::OPT_fsanitize_thread_memory_access,
|
|
|
|
+ options::OPT_fno_sanitize_thread_memory_access,
|
|
|
|
+ TsanMemoryAccess);
|
|
|
|
+ TsanFuncEntryExit = Args.hasFlag(options::OPT_fsanitize_thread_func_entry_exit,
|
|
|
|
+ options::OPT_fno_sanitize_thread_func_entry_exit,
|
|
|
|
+ TsanFuncEntryExit);
|
|
|
|
+ TsanAtomics = Args.hasFlag(options::OPT_fsanitize_thread_atomics,
|
|
|
|
+ options::OPT_fno_sanitize_thread_atomics,
|
|
|
|
+ TsanAtomics);
|
|
}
|
|
}
|
|
|
|
|
|
- if (AllAddedKinds & SanitizerKind::CFI) {
|
|
|
|
|
|
+ if (AllAddedKinds & CFI) {
|
|
// Without PIE, external function address may resolve to a PLT record, which
|
|
// Without PIE, external function address may resolve to a PLT record, which
|
|
// can not be verified by the target module.
|
|
// can not be verified by the target module.
|
|
NeedPIE |= CfiCrossDso;
|
|
NeedPIE |= CfiCrossDso;
|
|
@@ -646,7 +603,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
<< "-fsanitize-minimal-runtime"
|
|
<< "-fsanitize-minimal-runtime"
|
|
<< lastArgumentForMask(D, Args, IncompatibleMask);
|
|
<< lastArgumentForMask(D, Args, IncompatibleMask);
|
|
|
|
|
|
- SanitizerMask NonTrappingCfi = Kinds & SanitizerKind::CFI & ~TrappingKinds;
|
|
|
|
|
|
+ SanitizerMask NonTrappingCfi = Kinds & CFI & ~TrappingKinds;
|
|
if (NonTrappingCfi)
|
|
if (NonTrappingCfi)
|
|
D.Diag(clang::diag::err_drv_argument_only_allowed_with)
|
|
D.Diag(clang::diag::err_drv_argument_only_allowed_with)
|
|
<< "fsanitize-minimal-runtime"
|
|
<< "fsanitize-minimal-runtime"
|
|
@@ -734,7 +691,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
|
|
|
|
ImplicitCfiRuntime = TC.getTriple().isAndroid();
|
|
ImplicitCfiRuntime = TC.getTriple().isAndroid();
|
|
|
|
|
|
- if (AllAddedKinds & SanitizerKind::Address) {
|
|
|
|
|
|
+ if (AllAddedKinds & Address) {
|
|
NeedPIE |= TC.getTriple().isOSFuchsia();
|
|
NeedPIE |= TC.getTriple().isOSFuchsia();
|
|
if (Arg *A =
|
|
if (Arg *A =
|
|
Args.getLastArg(options::OPT_fsanitize_address_field_padding)) {
|
|
Args.getLastArg(options::OPT_fsanitize_address_field_padding)) {
|
|
@@ -756,7 +713,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
case options::OPT__SLASH_LDd:
|
|
case options::OPT__SLASH_LDd:
|
|
D.Diag(clang::diag::err_drv_argument_not_allowed_with)
|
|
D.Diag(clang::diag::err_drv_argument_not_allowed_with)
|
|
<< WindowsDebugRTArg->getAsString(Args)
|
|
<< WindowsDebugRTArg->getAsString(Args)
|
|
- << lastArgumentForMask(D, Args, SanitizerKind::Address);
|
|
|
|
|
|
+ << lastArgumentForMask(D, Args, Address);
|
|
D.Diag(clang::diag::note_drv_address_sanitizer_debug_runtime);
|
|
D.Diag(clang::diag::note_drv_address_sanitizer_debug_runtime);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -785,7 +742,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
AsanUseAfterScope = false;
|
|
AsanUseAfterScope = false;
|
|
}
|
|
}
|
|
|
|
|
|
- if (AllAddedKinds & SanitizerKind::HWAddress) {
|
|
|
|
|
|
+ if (AllAddedKinds & HWAddress) {
|
|
if (Arg *HwasanAbiArg =
|
|
if (Arg *HwasanAbiArg =
|
|
Args.getLastArg(options::OPT_fsanitize_hwaddress_abi_EQ)) {
|
|
Args.getLastArg(options::OPT_fsanitize_hwaddress_abi_EQ)) {
|
|
HwasanAbi = HwasanAbiArg->getValue();
|
|
HwasanAbi = HwasanAbiArg->getValue();
|
|
@@ -797,7 +754,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (AllAddedKinds & SanitizerKind::SafeStack) {
|
|
|
|
|
|
+ if (AllAddedKinds & SafeStack) {
|
|
// SafeStack runtime is built into the system on Fuchsia.
|
|
// SafeStack runtime is built into the system on Fuchsia.
|
|
SafeStackRuntime = !TC.getTriple().isOSFuchsia();
|
|
SafeStackRuntime = !TC.getTriple().isOSFuchsia();
|
|
}
|
|
}
|
|
@@ -817,7 +774,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
|
|
static std::string toString(const clang::SanitizerSet &Sanitizers) {
|
|
static std::string toString(const clang::SanitizerSet &Sanitizers) {
|
|
std::string Res;
|
|
std::string Res;
|
|
#define SANITIZER(NAME, ID) \
|
|
#define SANITIZER(NAME, ID) \
|
|
- if (Sanitizers.has(SanitizerKind::ID)) { \
|
|
|
|
|
|
+ if (Sanitizers.has(ID)) { \
|
|
if (!Res.empty()) \
|
|
if (!Res.empty()) \
|
|
Res += ","; \
|
|
Res += ","; \
|
|
Res += NAME; \
|
|
Res += NAME; \
|
|
@@ -979,8 +936,7 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
|
|
// https://github.com/google/sanitizers/issues/373
|
|
// https://github.com/google/sanitizers/issues/373
|
|
// We can't make this conditional on -fsanitize=leak, as that flag shouldn't
|
|
// We can't make this conditional on -fsanitize=leak, as that flag shouldn't
|
|
// affect compilation.
|
|
// affect compilation.
|
|
- if (Sanitizers.has(SanitizerKind::Memory) ||
|
|
|
|
- Sanitizers.has(SanitizerKind::Address))
|
|
|
|
|
|
+ if (Sanitizers.has(Memory) || Sanitizers.has(Address))
|
|
CmdArgs.push_back("-fno-assume-sane-operator-new");
|
|
CmdArgs.push_back("-fno-assume-sane-operator-new");
|
|
|
|
|
|
// Require -fvisibility= flag on non-Windows when compiling if vptr CFI is
|
|
// Require -fvisibility= flag on non-Windows when compiling if vptr CFI is
|
|
@@ -1003,18 +959,18 @@ SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A,
|
|
A->getOption().matches(options::OPT_fsanitize_trap_EQ) ||
|
|
A->getOption().matches(options::OPT_fsanitize_trap_EQ) ||
|
|
A->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) &&
|
|
A->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) &&
|
|
"Invalid argument in parseArgValues!");
|
|
"Invalid argument in parseArgValues!");
|
|
- SanitizerMask Kinds;
|
|
|
|
|
|
+ SanitizerMask Kinds = 0;
|
|
for (int i = 0, n = A->getNumValues(); i != n; ++i) {
|
|
for (int i = 0, n = A->getNumValues(); i != n; ++i) {
|
|
const char *Value = A->getValue(i);
|
|
const char *Value = A->getValue(i);
|
|
SanitizerMask Kind;
|
|
SanitizerMask Kind;
|
|
// Special case: don't accept -fsanitize=all.
|
|
// Special case: don't accept -fsanitize=all.
|
|
if (A->getOption().matches(options::OPT_fsanitize_EQ) &&
|
|
if (A->getOption().matches(options::OPT_fsanitize_EQ) &&
|
|
0 == strcmp("all", Value))
|
|
0 == strcmp("all", Value))
|
|
- Kind = SanitizerMask();
|
|
|
|
|
|
+ Kind = 0;
|
|
// Similarly, don't accept -fsanitize=efficiency-all.
|
|
// Similarly, don't accept -fsanitize=efficiency-all.
|
|
else if (A->getOption().matches(options::OPT_fsanitize_EQ) &&
|
|
else if (A->getOption().matches(options::OPT_fsanitize_EQ) &&
|
|
0 == strcmp("efficiency-all", Value))
|
|
0 == strcmp("efficiency-all", Value))
|
|
- Kind = SanitizerMask();
|
|
|
|
|
|
+ Kind = 0;
|
|
else
|
|
else
|
|
Kind = parseSanitizerValue(Value, /*AllowGroups=*/true);
|
|
Kind = parseSanitizerValue(Value, /*AllowGroups=*/true);
|
|
|
|
|