mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
[asan] don't instrument module CTORs that may be run before asan.module_ctor. This fixes asan running together -coverage
llvm-svn: 218421
This commit is contained in:
parent
0589111019
commit
8fdd214f67
@ -71,7 +71,7 @@ static const uintptr_t kRetiredStackFrameMagic = 0x45E0360E;
|
||||
|
||||
static const char *const kAsanModuleCtorName = "asan.module_ctor";
|
||||
static const char *const kAsanModuleDtorName = "asan.module_dtor";
|
||||
static const int kAsanCtorAndDtorPriority = 1;
|
||||
static const uint64_t kAsanCtorAndDtorPriority = 1;
|
||||
static const char *const kAsanReportErrorTemplate = "__asan_report_";
|
||||
static const char *const kAsanReportLoadN = "__asan_report_load_n";
|
||||
static const char *const kAsanReportStoreN = "__asan_report_store_n";
|
||||
@ -928,10 +928,12 @@ void AddressSanitizerModule::createInitializerPoisonCalls(
|
||||
ConstantStruct *CS = cast<ConstantStruct>(OP);
|
||||
|
||||
// Must have a function or null ptr.
|
||||
// (CS->getOperand(0) is the init priority.)
|
||||
if (Function* F = dyn_cast<Function>(CS->getOperand(1))) {
|
||||
if (F->getName() != kAsanModuleCtorName)
|
||||
poisonOneInitializer(*F, ModuleName);
|
||||
if (F->getName() == kAsanModuleCtorName) continue;
|
||||
ConstantInt *Priority = dyn_cast<ConstantInt>(CS->getOperand(0));
|
||||
// Don't instrument CTORs that will run before asan.module_ctor.
|
||||
if (Priority->getLimitedValue() <= kAsanCtorAndDtorPriority) continue;
|
||||
poisonOneInitializer(*F, ModuleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,29 +25,39 @@ entry:
|
||||
ret void
|
||||
}
|
||||
|
||||
@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
|
||||
@llvm.global_ctors = appending global [2 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @__late_ctor }, { i32, void ()* } { i32 0, void ()* @__early_ctor }]
|
||||
|
||||
define internal void @_GLOBAL__I_a() sanitize_address section ".text.startup" {
|
||||
define internal void @__late_ctor() sanitize_address section ".text.startup" {
|
||||
entry:
|
||||
call void @__cxx_global_var_init()
|
||||
ret void
|
||||
}
|
||||
|
||||
; Clang indicated that @xxx was dynamically initailized.
|
||||
; __asan_{before,after}_dynamic_init should be called from _GLOBAL__I_a
|
||||
; __asan_{before,after}_dynamic_init should be called from __late_ctor
|
||||
|
||||
; CHECK: define internal void @_GLOBAL__I_a
|
||||
; CHECK-LABEL: define internal void @__late_ctor
|
||||
; CHECK-NOT: ret
|
||||
; CHECK: call void @__asan_before_dynamic_init
|
||||
; CHECK: call void @__cxx_global_var_init
|
||||
; CHECK: call void @__asan_after_dynamic_init
|
||||
; CHECK: ret
|
||||
|
||||
; CTOR with priority 0 should not be instrumented.
|
||||
define internal void @__early_ctor() sanitize_address section ".text.startup" {
|
||||
entry:
|
||||
call void @__cxx_global_var_init()
|
||||
ret void
|
||||
}
|
||||
; CHECK-LABEL: define internal void @__early_ctor
|
||||
; CHECK-NOT: __asan
|
||||
; CHECK: ret
|
||||
|
||||
; Check that xxx is instrumented.
|
||||
define void @touch_xxx() sanitize_address {
|
||||
store i32 0, i32 *@xxx, align 4
|
||||
ret void
|
||||
; CHECK: define void @touch_xxx
|
||||
; CHECK-LABEL: touch_xxx
|
||||
; CHECK: call void @__asan_report_store4
|
||||
; CHECK: ret void
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user