Make sure globals created by UBSan are not instrumented by ASan.

Summary:
This change adds description of globals created by UBSan
instrumentation (UBSan handlers, type descriptors, filenames) to
llvm.asan.globals metadata, effectively "blacklisting" them. This can
dramatically decrease the data section in binaries built with UBSan+ASan,
as UBSan tends to create a lot of handlers, and ASan instrumentation
increases the global size to at least 64 bytes.

Test Plan: clang regression test suite

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits, byoungyoung, kcc

Differential Revision: http://reviews.llvm.org/D4575

llvm-svn: 213392
This commit is contained in:
Alexey Samsonov
2014-07-18 17:50:06 +00:00
parent 5450240219
commit 6c12414358
4 changed files with 40 additions and 10 deletions

View File

@@ -1951,11 +1951,11 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
void CodeGenModule::reportGlobalToASan(llvm::GlobalVariable *GV,
SourceLocation Loc, StringRef Name,
bool IsDynInit) {
bool IsDynInit, bool IsBlacklisted) {
if (!LangOpts.Sanitize.Address)
return;
IsDynInit &= !SanitizerBL.isIn(*GV, "init");
bool IsBlacklisted = SanitizerBL.isIn(*GV);
IsBlacklisted |= SanitizerBL.isIn(*GV);
llvm::GlobalVariable *LocDescr = nullptr;
llvm::GlobalVariable *GlobalName = nullptr;
@@ -2008,6 +2008,13 @@ void CodeGenModule::reportGlobalToASan(llvm::GlobalVariable *GV,
reportGlobalToASan(GV, D.getLocation(), OS.str(), IsDynInit);
}
void CodeGenModule::disableSanitizerForGlobal(llvm::GlobalVariable *GV) {
// For now, just make sure the global is not modified by the ASan
// instrumentation.
if (LangOpts.Sanitize.Address)
reportGlobalToASan(GV, SourceLocation(), "", false, true);
}
static bool isVarDeclStrongDefinition(const VarDecl *D, bool NoCommon) {
// Don't give variables common linkage if -fno-common was specified unless it
// was overridden by a NoCommon attribute.