forked from OSchip/llvm-project
[clang][patch] Inclusive language, modify filename SanitizerBlacklist.h to NoSanitizeList.h
This patch responds to a comment from @vitalybuka in D96203: suggestion to do the change incrementally, and start by modifying this file name. I modified the file name and made the other changes that follow from that rename. Reviewers: vitalybuka, echristo, MaskRay, jansvoboda11, aaron.ballman Differential Revision: https://reviews.llvm.org/D96974
This commit is contained in:
parent
1cd2a5a7da
commit
e64fcdf8d5
|
@ -34,10 +34,10 @@
|
|||
#include "clang/Basic/LLVM.h"
|
||||
#include "clang/Basic/LangOptions.h"
|
||||
#include "clang/Basic/Linkage.h"
|
||||
#include "clang/Basic/NoSanitizeList.h"
|
||||
#include "clang/Basic/OperatorKinds.h"
|
||||
#include "clang/Basic/PartialDiagnostic.h"
|
||||
#include "clang/Basic/ProfileList.h"
|
||||
#include "clang/Basic/SanitizerBlacklist.h"
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include "clang/Basic/Specifiers.h"
|
||||
#include "clang/Basic/XRayLists.h"
|
||||
|
@ -562,9 +562,9 @@ private:
|
|||
/// this ASTContext object.
|
||||
LangOptions &LangOpts;
|
||||
|
||||
/// Blacklist object that is used by sanitizers to decide which
|
||||
/// NoSanitizeList object that is used by sanitizers to decide which
|
||||
/// entities should not be instrumented.
|
||||
std::unique_ptr<SanitizerBlacklist> SanitizerBL;
|
||||
std::unique_ptr<NoSanitizeList> NoSanitizeL;
|
||||
|
||||
/// Function filtering mechanism to determine whether a given function
|
||||
/// should be imbued with the XRay "always" or "never" attributes.
|
||||
|
@ -691,9 +691,7 @@ public:
|
|||
return LangOpts.CPlusPlus || LangOpts.RecoveryAST;
|
||||
}
|
||||
|
||||
const SanitizerBlacklist &getSanitizerBlacklist() const {
|
||||
return *SanitizerBL;
|
||||
}
|
||||
const NoSanitizeList &getNoSanitizeList() const { return *NoSanitizeL; }
|
||||
|
||||
const XRayFunctionFilter &getXRayFilter() const {
|
||||
return *XRayFilter;
|
||||
|
|
|
@ -264,9 +264,9 @@ public:
|
|||
/// Set of enabled sanitizers.
|
||||
SanitizerSet Sanitize;
|
||||
|
||||
/// Paths to blacklist files specifying which objects
|
||||
/// Paths to files specifying which objects
|
||||
/// (files, functions, variables) should not be instrumented.
|
||||
std::vector<std::string> SanitizerBlacklistFiles;
|
||||
std::vector<std::string> NoSanitizeFiles;
|
||||
|
||||
/// Paths to the XRay "always instrument" files specifying which
|
||||
/// objects (files, functions, variables) should be imbued with the XRay
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
//===--- NoSanitizeList.h - List of ignored entities for sanitizers --*- C++
|
||||
//-*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// User-provided list of ignored entities used to disable/alter
|
||||
// instrumentation done in sanitizers.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#ifndef LLVM_CLANG_BASIC_NOSANITIZELIST_H
|
||||
#define LLVM_CLANG_BASIC_NOSANITIZELIST_H
|
||||
|
||||
#include "clang/Basic/LLVM.h"
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace clang {
|
||||
|
||||
class SanitizerMask;
|
||||
class SourceManager;
|
||||
class SanitizerSpecialCaseList;
|
||||
|
||||
class NoSanitizeList {
|
||||
std::unique_ptr<SanitizerSpecialCaseList> SSCL;
|
||||
SourceManager &SM;
|
||||
|
||||
public:
|
||||
NoSanitizeList(const std::vector<std::string> &NoSanitizeListPaths,
|
||||
SourceManager &SM);
|
||||
~NoSanitizeList();
|
||||
bool containsGlobal(SanitizerMask Mask, StringRef GlobalName,
|
||||
StringRef Category = StringRef()) const;
|
||||
bool containsType(SanitizerMask Mask, StringRef MangledTypeName,
|
||||
StringRef Category = StringRef()) const;
|
||||
bool containsFunction(SanitizerMask Mask, StringRef FunctionName) const;
|
||||
bool containsFile(SanitizerMask Mask, StringRef FileName,
|
||||
StringRef Category = StringRef()) const;
|
||||
bool containsLocation(SanitizerMask Mask, SourceLocation Loc,
|
||||
StringRef Category = StringRef()) const;
|
||||
};
|
||||
|
||||
} // end namespace clang
|
||||
|
||||
#endif
|
|
@ -1,49 +0,0 @@
|
|||
//===--- SanitizerBlacklist.h - Blacklist for sanitizers --------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// User-provided blacklist used to disable/alter instrumentation done in
|
||||
// sanitizers.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#ifndef LLVM_CLANG_BASIC_SANITIZERBLACKLIST_H
|
||||
#define LLVM_CLANG_BASIC_SANITIZERBLACKLIST_H
|
||||
|
||||
#include "clang/Basic/LLVM.h"
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace clang {
|
||||
|
||||
class SanitizerMask;
|
||||
class SourceManager;
|
||||
class SanitizerSpecialCaseList;
|
||||
|
||||
class SanitizerBlacklist {
|
||||
std::unique_ptr<SanitizerSpecialCaseList> SSCL;
|
||||
SourceManager &SM;
|
||||
|
||||
public:
|
||||
SanitizerBlacklist(const std::vector<std::string> &BlacklistPaths,
|
||||
SourceManager &SM);
|
||||
~SanitizerBlacklist();
|
||||
bool isBlacklistedGlobal(SanitizerMask Mask, StringRef GlobalName,
|
||||
StringRef Category = StringRef()) const;
|
||||
bool isBlacklistedType(SanitizerMask Mask, StringRef MangledTypeName,
|
||||
StringRef Category = StringRef()) const;
|
||||
bool isBlacklistedFunction(SanitizerMask Mask, StringRef FunctionName) const;
|
||||
bool isBlacklistedFile(SanitizerMask Mask, StringRef FileName,
|
||||
StringRef Category = StringRef()) const;
|
||||
bool isBlacklistedLocation(SanitizerMask Mask, SourceLocation Loc,
|
||||
StringRef Category = StringRef()) const;
|
||||
};
|
||||
|
||||
} // end namespace clang
|
||||
|
||||
#endif
|
|
@ -56,8 +56,8 @@
|
|||
#include "clang/Basic/LangOptions.h"
|
||||
#include "clang/Basic/Linkage.h"
|
||||
#include "clang/Basic/Module.h"
|
||||
#include "clang/Basic/NoSanitizeList.h"
|
||||
#include "clang/Basic/ObjCRuntime.h"
|
||||
#include "clang/Basic/SanitizerBlacklist.h"
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "clang/Basic/Specifiers.h"
|
||||
|
@ -961,7 +961,7 @@ ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM,
|
|||
DependentTemplateSpecializationTypes(this_()), AutoTypes(this_()),
|
||||
SubstTemplateTemplateParmPacks(this_()),
|
||||
CanonTemplateTemplateParms(this_()), SourceMgr(SM), LangOpts(LOpts),
|
||||
SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFiles, SM)),
|
||||
NoSanitizeL(new NoSanitizeList(LangOpts.NoSanitizeFiles, SM)),
|
||||
XRayFilter(new XRayFunctionFilter(LangOpts.XRayAlwaysInstrumentFiles,
|
||||
LangOpts.XRayNeverInstrumentFiles,
|
||||
LangOpts.XRayAttrListFiles, SM)),
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
#include "clang/Basic/LangOptions.h"
|
||||
#include "clang/Basic/Linkage.h"
|
||||
#include "clang/Basic/Module.h"
|
||||
#include "clang/Basic/NoSanitizeList.h"
|
||||
#include "clang/Basic/PartialDiagnostic.h"
|
||||
#include "clang/Basic/SanitizerBlacklist.h"
|
||||
#include "clang/Basic/Sanitizers.h"
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
|
@ -4594,7 +4594,7 @@ bool RecordDecl::mayInsertExtraPadding(bool EmitRemark) const {
|
|||
(SanitizerKind::Address | SanitizerKind::KernelAddress);
|
||||
if (!EnabledAsanMask || !Context.getLangOpts().SanitizeAddressFieldPadding)
|
||||
return false;
|
||||
const auto &Blacklist = Context.getSanitizerBlacklist();
|
||||
const auto &NoSanitizeList = Context.getNoSanitizeList();
|
||||
const auto *CXXRD = dyn_cast<CXXRecordDecl>(this);
|
||||
// We may be able to relax some of these requirements.
|
||||
int ReasonToReject = -1;
|
||||
|
@ -4610,12 +4610,11 @@ bool RecordDecl::mayInsertExtraPadding(bool EmitRemark) const {
|
|||
ReasonToReject = 4; // has trivial destructor.
|
||||
else if (CXXRD->isStandardLayout())
|
||||
ReasonToReject = 5; // is standard layout.
|
||||
else if (Blacklist.isBlacklistedLocation(EnabledAsanMask, getLocation(),
|
||||
else if (NoSanitizeList.containsLocation(EnabledAsanMask, getLocation(),
|
||||
"field-padding"))
|
||||
ReasonToReject = 6; // is in an excluded file.
|
||||
else if (Blacklist.isBlacklistedType(EnabledAsanMask,
|
||||
getQualifiedNameAsString(),
|
||||
"field-padding"))
|
||||
else if (NoSanitizeList.containsType(
|
||||
EnabledAsanMask, getQualifiedNameAsString(), "field-padding"))
|
||||
ReasonToReject = 7; // The type is excluded.
|
||||
|
||||
if (EmitRemark) {
|
||||
|
|
|
@ -60,7 +60,7 @@ add_clang_library(clangBasic
|
|||
OpenMPKinds.cpp
|
||||
OperatorPrecedence.cpp
|
||||
ProfileList.cpp
|
||||
SanitizerBlacklist.cpp
|
||||
NoSanitizeList.cpp
|
||||
SanitizerSpecialCaseList.cpp
|
||||
Sanitizers.cpp
|
||||
SourceLocation.cpp
|
||||
|
|
|
@ -28,7 +28,7 @@ void LangOptions::resetNonModularOptions() {
|
|||
#include "clang/Basic/LangOptions.def"
|
||||
|
||||
// These options do not affect AST generation.
|
||||
SanitizerBlacklistFiles.clear();
|
||||
NoSanitizeFiles.clear();
|
||||
XRayAlwaysInstrumentFiles.clear();
|
||||
XRayNeverInstrumentFiles.clear();
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
//===--- NoSanitizeList.cpp - Ignored list for sanitizers ----------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// User-provided ignore-list used to disable/alter instrumentation done in
|
||||
// sanitizers.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "clang/Basic/NoSanitizeList.h"
|
||||
#include "clang/Basic/FileManager.h"
|
||||
#include "clang/Basic/SanitizerSpecialCaseList.h"
|
||||
#include "clang/Basic/Sanitizers.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
|
||||
using namespace clang;
|
||||
|
||||
NoSanitizeList::NoSanitizeList(const std::vector<std::string> &NoSanitizePaths,
|
||||
SourceManager &SM)
|
||||
: SSCL(SanitizerSpecialCaseList::createOrDie(
|
||||
NoSanitizePaths, SM.getFileManager().getVirtualFileSystem())),
|
||||
SM(SM) {}
|
||||
|
||||
NoSanitizeList::~NoSanitizeList() = default;
|
||||
|
||||
bool NoSanitizeList::containsGlobal(SanitizerMask Mask, StringRef GlobalName,
|
||||
StringRef Category) const {
|
||||
return SSCL->inSection(Mask, "global", GlobalName, Category);
|
||||
}
|
||||
|
||||
bool NoSanitizeList::containsType(SanitizerMask Mask, StringRef MangledTypeName,
|
||||
StringRef Category) const {
|
||||
return SSCL->inSection(Mask, "type", MangledTypeName, Category);
|
||||
}
|
||||
|
||||
bool NoSanitizeList::containsFunction(SanitizerMask Mask,
|
||||
StringRef FunctionName) const {
|
||||
return SSCL->inSection(Mask, "fun", FunctionName);
|
||||
}
|
||||
|
||||
bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
|
||||
StringRef Category) const {
|
||||
return SSCL->inSection(Mask, "src", FileName, Category);
|
||||
}
|
||||
|
||||
bool NoSanitizeList::containsLocation(SanitizerMask Mask, SourceLocation Loc,
|
||||
StringRef Category) const {
|
||||
return Loc.isValid() &&
|
||||
containsFile(Mask, SM.getFilename(SM.getFileLoc(Loc)), Category);
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
//===--- SanitizerBlacklist.cpp - Blacklist for sanitizers ----------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// User-provided blacklist used to disable/alter instrumentation done in
|
||||
// sanitizers.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "clang/Basic/SanitizerBlacklist.h"
|
||||
#include "clang/Basic/FileManager.h"
|
||||
#include "clang/Basic/SanitizerSpecialCaseList.h"
|
||||
#include "clang/Basic/Sanitizers.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
|
||||
using namespace clang;
|
||||
|
||||
SanitizerBlacklist::SanitizerBlacklist(
|
||||
const std::vector<std::string> &BlacklistPaths, SourceManager &SM)
|
||||
: SSCL(SanitizerSpecialCaseList::createOrDie(
|
||||
BlacklistPaths, SM.getFileManager().getVirtualFileSystem())),
|
||||
SM(SM) {}
|
||||
|
||||
SanitizerBlacklist::~SanitizerBlacklist() = default;
|
||||
|
||||
bool SanitizerBlacklist::isBlacklistedGlobal(SanitizerMask Mask,
|
||||
StringRef GlobalName,
|
||||
StringRef Category) const {
|
||||
return SSCL->inSection(Mask, "global", GlobalName, Category);
|
||||
}
|
||||
|
||||
bool SanitizerBlacklist::isBlacklistedType(SanitizerMask Mask,
|
||||
StringRef MangledTypeName,
|
||||
StringRef Category) const {
|
||||
return SSCL->inSection(Mask, "type", MangledTypeName, Category);
|
||||
}
|
||||
|
||||
bool SanitizerBlacklist::isBlacklistedFunction(SanitizerMask Mask,
|
||||
StringRef FunctionName) const {
|
||||
return SSCL->inSection(Mask, "fun", FunctionName);
|
||||
}
|
||||
|
||||
bool SanitizerBlacklist::isBlacklistedFile(SanitizerMask Mask,
|
||||
StringRef FileName,
|
||||
StringRef Category) const {
|
||||
return SSCL->inSection(Mask, "src", FileName, Category);
|
||||
}
|
||||
|
||||
bool SanitizerBlacklist::isBlacklistedLocation(SanitizerMask Mask,
|
||||
SourceLocation Loc,
|
||||
StringRef Category) const {
|
||||
return Loc.isValid() &&
|
||||
isBlacklistedFile(Mask, SM.getFilename(SM.getFileLoc(Loc)), Category);
|
||||
}
|
||||
|
|
@ -362,8 +362,7 @@ static void addDataFlowSanitizerPass(const PassManagerBuilder &Builder,
|
|||
const PassManagerBuilderWrapper &BuilderWrapper =
|
||||
static_cast<const PassManagerBuilderWrapper&>(Builder);
|
||||
const LangOptions &LangOpts = BuilderWrapper.getLangOpts();
|
||||
PM.add(
|
||||
createDataFlowSanitizerLegacyPassPass(LangOpts.SanitizerBlacklistFiles));
|
||||
PM.add(createDataFlowSanitizerLegacyPassPass(LangOpts.NoSanitizeFiles));
|
||||
}
|
||||
|
||||
static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple,
|
||||
|
@ -1132,7 +1131,7 @@ static void addSanitizers(const Triple &TargetTriple,
|
|||
HWASanPass(SanitizerKind::KernelHWAddress, true);
|
||||
|
||||
if (LangOpts.Sanitize.has(SanitizerKind::DataFlow)) {
|
||||
MPM.addPass(DataFlowSanitizerPass(LangOpts.SanitizerBlacklistFiles));
|
||||
MPM.addPass(DataFlowSanitizerPass(LangOpts.NoSanitizeFiles));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2776,7 +2776,7 @@ void CodeGenFunction::EmitVTablePtrCheck(const CXXRecordDecl *RD,
|
|||
}
|
||||
|
||||
std::string TypeName = RD->getQualifiedNameAsString();
|
||||
if (getContext().getSanitizerBlacklist().isBlacklistedType(M, TypeName))
|
||||
if (getContext().getNoSanitizeList().containsType(M, TypeName))
|
||||
return;
|
||||
|
||||
SanitizerScope SanScope(this);
|
||||
|
@ -2829,8 +2829,8 @@ bool CodeGenFunction::ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD) {
|
|||
return false;
|
||||
|
||||
std::string TypeName = RD->getQualifiedNameAsString();
|
||||
return !getContext().getSanitizerBlacklist().isBlacklistedType(
|
||||
SanitizerKind::CFIVCall, TypeName);
|
||||
return !getContext().getNoSanitizeList().containsType(SanitizerKind::CFIVCall,
|
||||
TypeName);
|
||||
}
|
||||
|
||||
llvm::Value *CodeGenFunction::EmitVTableTypeCheckedLoad(
|
||||
|
@ -2852,8 +2852,8 @@ llvm::Value *CodeGenFunction::EmitVTableTypeCheckedLoad(
|
|||
|
||||
std::string TypeName = RD->getQualifiedNameAsString();
|
||||
if (SanOpts.has(SanitizerKind::CFIVCall) &&
|
||||
!getContext().getSanitizerBlacklist().isBlacklistedType(
|
||||
SanitizerKind::CFIVCall, TypeName)) {
|
||||
!getContext().getNoSanitizeList().containsType(SanitizerKind::CFIVCall,
|
||||
TypeName)) {
|
||||
EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIVCall),
|
||||
SanitizerHandler::CFICheckFail, {}, {});
|
||||
}
|
||||
|
|
|
@ -388,43 +388,43 @@ llvm::Function *CodeGenModule::CreateGlobalInitOrCleanUpFunction(
|
|||
Fn->setDoesNotThrow();
|
||||
|
||||
if (getLangOpts().Sanitize.has(SanitizerKind::Address) &&
|
||||
!isInSanitizerBlacklist(SanitizerKind::Address, Fn, Loc))
|
||||
!isInNoSanitizeList(SanitizerKind::Address, Fn, Loc))
|
||||
Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
|
||||
|
||||
if (getLangOpts().Sanitize.has(SanitizerKind::KernelAddress) &&
|
||||
!isInSanitizerBlacklist(SanitizerKind::KernelAddress, Fn, Loc))
|
||||
!isInNoSanitizeList(SanitizerKind::KernelAddress, Fn, Loc))
|
||||
Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
|
||||
|
||||
if (getLangOpts().Sanitize.has(SanitizerKind::HWAddress) &&
|
||||
!isInSanitizerBlacklist(SanitizerKind::HWAddress, Fn, Loc))
|
||||
!isInNoSanitizeList(SanitizerKind::HWAddress, Fn, Loc))
|
||||
Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
|
||||
|
||||
if (getLangOpts().Sanitize.has(SanitizerKind::KernelHWAddress) &&
|
||||
!isInSanitizerBlacklist(SanitizerKind::KernelHWAddress, Fn, Loc))
|
||||
!isInNoSanitizeList(SanitizerKind::KernelHWAddress, Fn, Loc))
|
||||
Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
|
||||
|
||||
if (getLangOpts().Sanitize.has(SanitizerKind::MemTag) &&
|
||||
!isInSanitizerBlacklist(SanitizerKind::MemTag, Fn, Loc))
|
||||
!isInNoSanitizeList(SanitizerKind::MemTag, Fn, Loc))
|
||||
Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
|
||||
|
||||
if (getLangOpts().Sanitize.has(SanitizerKind::Thread) &&
|
||||
!isInSanitizerBlacklist(SanitizerKind::Thread, Fn, Loc))
|
||||
!isInNoSanitizeList(SanitizerKind::Thread, Fn, Loc))
|
||||
Fn->addFnAttr(llvm::Attribute::SanitizeThread);
|
||||
|
||||
if (getLangOpts().Sanitize.has(SanitizerKind::Memory) &&
|
||||
!isInSanitizerBlacklist(SanitizerKind::Memory, Fn, Loc))
|
||||
!isInNoSanitizeList(SanitizerKind::Memory, Fn, Loc))
|
||||
Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
|
||||
|
||||
if (getLangOpts().Sanitize.has(SanitizerKind::KernelMemory) &&
|
||||
!isInSanitizerBlacklist(SanitizerKind::KernelMemory, Fn, Loc))
|
||||
!isInNoSanitizeList(SanitizerKind::KernelMemory, Fn, Loc))
|
||||
Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
|
||||
|
||||
if (getLangOpts().Sanitize.has(SanitizerKind::SafeStack) &&
|
||||
!isInSanitizerBlacklist(SanitizerKind::SafeStack, Fn, Loc))
|
||||
!isInNoSanitizeList(SanitizerKind::SafeStack, Fn, Loc))
|
||||
Fn->addFnAttr(llvm::Attribute::SafeStack);
|
||||
|
||||
if (getLangOpts().Sanitize.has(SanitizerKind::ShadowCallStack) &&
|
||||
!isInSanitizerBlacklist(SanitizerKind::ShadowCallStack, Fn, Loc))
|
||||
!isInNoSanitizeList(SanitizerKind::ShadowCallStack, Fn, Loc))
|
||||
Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
|
||||
|
||||
return Fn;
|
||||
|
|
|
@ -826,9 +826,9 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
|
|||
CGM.getCXXABI().getMangleContext().mangleCXXRTTI(Ty.getUnqualifiedType(),
|
||||
Out);
|
||||
|
||||
// Blacklist based on the mangled type.
|
||||
if (!CGM.getContext().getSanitizerBlacklist().isBlacklistedType(
|
||||
SanitizerKind::Vptr, Out.str())) {
|
||||
// Contained in NoSanitizeList based on the mangled type.
|
||||
if (!CGM.getContext().getNoSanitizeList().containsType(SanitizerKind::Vptr,
|
||||
Out.str())) {
|
||||
llvm::hash_code TypeHash = hash_value(Out.str());
|
||||
|
||||
// Load the vptr, and compute hash_16_bytes(TypeHash, vptr).
|
||||
|
@ -3389,7 +3389,7 @@ void CodeGenFunction::EmitCfiCheckFail() {
|
|||
StartFunction(GlobalDecl(), CGM.getContext().VoidTy, F, FI, Args,
|
||||
SourceLocation());
|
||||
|
||||
// This function should not be affected by blacklist. This function does
|
||||
// This function is not affected by NoSanitizeList. This function does
|
||||
// not have a source location, but "src:*" would still apply. Revert any
|
||||
// changes to SanOpts made in StartFunction.
|
||||
SanOpts = CGM.getLangOpts().Sanitize;
|
||||
|
|
|
@ -711,14 +711,14 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
|
|||
CurFnInfo = &FnInfo;
|
||||
assert(CurFn->isDeclaration() && "Function already has body?");
|
||||
|
||||
// If this function has been blacklisted for any of the enabled sanitizers,
|
||||
// If this function is ignored for any of the enabled sanitizers,
|
||||
// disable the sanitizer for the function.
|
||||
do {
|
||||
#define SANITIZER(NAME, ID) \
|
||||
if (SanOpts.empty()) \
|
||||
break; \
|
||||
if (SanOpts.has(SanitizerKind::ID)) \
|
||||
if (CGM.isInSanitizerBlacklist(SanitizerKind::ID, Fn, Loc)) \
|
||||
if (CGM.isInNoSanitizeList(SanitizerKind::ID, Fn, Loc)) \
|
||||
SanOpts.set(SanitizerKind::ID, false);
|
||||
|
||||
#include "clang/Basic/Sanitizers.def"
|
||||
|
|
|
@ -2459,29 +2459,28 @@ void CodeGenModule::AddGlobalAnnotations(const ValueDecl *D,
|
|||
Annotations.push_back(EmitAnnotateAttr(GV, I, D->getLocation()));
|
||||
}
|
||||
|
||||
bool CodeGenModule::isInSanitizerBlacklist(SanitizerMask Kind,
|
||||
llvm::Function *Fn,
|
||||
SourceLocation Loc) const {
|
||||
const auto &SanitizerBL = getContext().getSanitizerBlacklist();
|
||||
// Blacklist by function name.
|
||||
if (SanitizerBL.isBlacklistedFunction(Kind, Fn->getName()))
|
||||
bool CodeGenModule::isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn,
|
||||
SourceLocation Loc) const {
|
||||
const auto &NoSanitizeL = getContext().getNoSanitizeList();
|
||||
// NoSanitize by function name.
|
||||
if (NoSanitizeL.containsFunction(Kind, Fn->getName()))
|
||||
return true;
|
||||
// Blacklist by location.
|
||||
// NoSanitize by location.
|
||||
if (Loc.isValid())
|
||||
return SanitizerBL.isBlacklistedLocation(Kind, Loc);
|
||||
return NoSanitizeL.containsLocation(Kind, Loc);
|
||||
// If location is unknown, this may be a compiler-generated function. Assume
|
||||
// it's located in the main file.
|
||||
auto &SM = Context.getSourceManager();
|
||||
if (const auto *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
|
||||
return SanitizerBL.isBlacklistedFile(Kind, MainFile->getName());
|
||||
return NoSanitizeL.containsFile(Kind, MainFile->getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CodeGenModule::isInSanitizerBlacklist(llvm::GlobalVariable *GV,
|
||||
SourceLocation Loc, QualType Ty,
|
||||
StringRef Category) const {
|
||||
// For now globals can be blacklisted only in ASan and KASan.
|
||||
bool CodeGenModule::isInNoSanitizeList(llvm::GlobalVariable *GV,
|
||||
SourceLocation Loc, QualType Ty,
|
||||
StringRef Category) const {
|
||||
// For now globals can be ignored only in ASan and KASan.
|
||||
const SanitizerMask EnabledAsanMask =
|
||||
LangOpts.Sanitize.Mask &
|
||||
(SanitizerKind::Address | SanitizerKind::KernelAddress |
|
||||
|
@ -2489,22 +2488,22 @@ bool CodeGenModule::isInSanitizerBlacklist(llvm::GlobalVariable *GV,
|
|||
SanitizerKind::MemTag);
|
||||
if (!EnabledAsanMask)
|
||||
return false;
|
||||
const auto &SanitizerBL = getContext().getSanitizerBlacklist();
|
||||
if (SanitizerBL.isBlacklistedGlobal(EnabledAsanMask, GV->getName(), Category))
|
||||
const auto &NoSanitizeL = getContext().getNoSanitizeList();
|
||||
if (NoSanitizeL.containsGlobal(EnabledAsanMask, GV->getName(), Category))
|
||||
return true;
|
||||
if (SanitizerBL.isBlacklistedLocation(EnabledAsanMask, Loc, Category))
|
||||
if (NoSanitizeL.containsLocation(EnabledAsanMask, Loc, Category))
|
||||
return true;
|
||||
// Check global type.
|
||||
if (!Ty.isNull()) {
|
||||
// Drill down the array types: if global variable of a fixed type is
|
||||
// blacklisted, we also don't instrument arrays of them.
|
||||
// not sanitized, we also don't instrument arrays of them.
|
||||
while (auto AT = dyn_cast<ArrayType>(Ty.getTypePtr()))
|
||||
Ty = AT->getElementType();
|
||||
Ty = Ty.getCanonicalType().getUnqualifiedType();
|
||||
// We allow to blacklist only record types (classes, structs etc.)
|
||||
// Only record types (classes, structs etc.) are ignored.
|
||||
if (Ty->isRecordType()) {
|
||||
std::string TypeStr = Ty.getAsString(getContext().getPrintingPolicy());
|
||||
if (SanitizerBL.isBlacklistedType(EnabledAsanMask, TypeStr, Category))
|
||||
if (NoSanitizeL.containsType(EnabledAsanMask, TypeStr, Category))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "clang/Basic/ABI.h"
|
||||
#include "clang/Basic/LangOptions.h"
|
||||
#include "clang/Basic/Module.h"
|
||||
#include "clang/Basic/SanitizerBlacklist.h"
|
||||
#include "clang/Basic/NoSanitizeList.h"
|
||||
#include "clang/Basic/TargetInfo.h"
|
||||
#include "clang/Basic/XRayLists.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
|
@ -1267,12 +1267,11 @@ public:
|
|||
/// annotations are emitted during finalization of the LLVM code.
|
||||
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
|
||||
|
||||
bool isInSanitizerBlacklist(SanitizerMask Kind, llvm::Function *Fn,
|
||||
SourceLocation Loc) const;
|
||||
bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn,
|
||||
SourceLocation Loc) const;
|
||||
|
||||
bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc,
|
||||
QualType Ty,
|
||||
StringRef Category = StringRef()) const;
|
||||
bool isInNoSanitizeList(llvm::GlobalVariable *GV, SourceLocation Loc,
|
||||
QualType Ty, StringRef Category = StringRef()) const;
|
||||
|
||||
/// Imbue XRay attributes to a function, applying the always/never attribute
|
||||
/// lists in the process. Returns true if we did imbue attributes this way,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//===--- SanitizerMetadata.cpp - Blacklist for sanitizers -----------------===//
|
||||
//===--- SanitizerMetadata.cpp - Ignored entities for sanitizers ----------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
|
@ -34,15 +34,15 @@ void SanitizerMetadata::reportGlobalToASan(llvm::GlobalVariable *GV,
|
|||
bool IsExcluded) {
|
||||
if (!isAsanHwasanOrMemTag(CGM.getLangOpts().Sanitize))
|
||||
return;
|
||||
IsDynInit &= !CGM.isInSanitizerBlacklist(GV, Loc, Ty, "init");
|
||||
IsExcluded |= CGM.isInSanitizerBlacklist(GV, Loc, Ty);
|
||||
IsDynInit &= !CGM.isInNoSanitizeList(GV, Loc, Ty, "init");
|
||||
IsExcluded |= CGM.isInNoSanitizeList(GV, Loc, Ty);
|
||||
|
||||
llvm::Metadata *LocDescr = nullptr;
|
||||
llvm::Metadata *GlobalName = nullptr;
|
||||
llvm::LLVMContext &VMContext = CGM.getLLVMContext();
|
||||
if (!IsExcluded) {
|
||||
// Don't generate source location and global name if it is blacklisted -
|
||||
// it won't be instrumented anyway.
|
||||
// Don't generate source location and global name if it is on
|
||||
// the NoSanitizeList - it won't be instrumented anyway.
|
||||
LocDescr = getLocationMetadata(Loc);
|
||||
if (!Name.empty())
|
||||
GlobalName = llvm::MDString::get(VMContext, Name);
|
||||
|
|
|
@ -3607,7 +3607,7 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts,
|
|||
GenerateArg(Args, OPT_fsanitize_EQ, Sanitizer, SA);
|
||||
|
||||
// Conflating '-fsanitize-system-blacklist' and '-fsanitize-blacklist'.
|
||||
for (const std::string &F : Opts.SanitizerBlacklistFiles)
|
||||
for (const std::string &F : Opts.NoSanitizeFiles)
|
||||
GenerateArg(Args, OPT_fsanitize_blacklist, F, SA);
|
||||
|
||||
if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver3_8)
|
||||
|
@ -4006,12 +4006,11 @@ bool CompilerInvocation::ParseLangArgsImpl(LangOptions &Opts, ArgList &Args,
|
|||
// Parse -fsanitize= arguments.
|
||||
parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
|
||||
Diags, Opts.Sanitize);
|
||||
Opts.SanitizerBlacklistFiles = Args.getAllArgValues(OPT_fsanitize_blacklist);
|
||||
Opts.NoSanitizeFiles = Args.getAllArgValues(OPT_fsanitize_blacklist);
|
||||
std::vector<std::string> systemBlacklists =
|
||||
Args.getAllArgValues(OPT_fsanitize_system_blacklist);
|
||||
Opts.SanitizerBlacklistFiles.insert(Opts.SanitizerBlacklistFiles.end(),
|
||||
systemBlacklists.begin(),
|
||||
systemBlacklists.end());
|
||||
Opts.NoSanitizeFiles.insert(Opts.NoSanitizeFiles.end(),
|
||||
systemBlacklists.begin(), systemBlacklists.end());
|
||||
|
||||
if (Arg *A = Args.getLastArg(OPT_fclang_abi_compat_EQ)) {
|
||||
Opts.setClangABICompat(LangOptions::ClangABI::Latest);
|
||||
|
|
Loading…
Reference in New Issue