forked from OSchip/llvm-project
[Sanitizer] Get rid of Symbolizer::Get() and Symbolizer::GetOrNull().
We may as well just use Symbolizer::GetOrInit() in all the cases. Don't call Symbolizer::Get() early in tools initialization: these days it doesn't do any important setup work, and we may as well create the symbolizer the first time it's actually needed. llvm-svn: 217558
This commit is contained in:
parent
d0ec5ab948
commit
611c906cb3
|
|
@ -200,7 +200,7 @@ static const char *MaybeDemangleGlobalName(const char *name) {
|
|||
else if (SANITIZER_WINDOWS && name[0] == '\01' && name[1] == '?')
|
||||
should_demangle = true;
|
||||
|
||||
return should_demangle ? Symbolizer::Get()->Demangle(name) : name;
|
||||
return should_demangle ? Symbolizer::GetOrInit()->Demangle(name) : name;
|
||||
}
|
||||
|
||||
// Check if the global is a zero-terminated ASCII string. If so, print it.
|
||||
|
|
|
|||
|
|
@ -646,12 +646,8 @@ static void AsanInitInternal() {
|
|||
AsanTSDInit(PlatformTSDDtor);
|
||||
InstallDeadlySignalHandlers(AsanOnSIGSEGV);
|
||||
|
||||
// Allocator should be initialized before starting external symbolizer, as
|
||||
// fork() on Mac locks the allocator.
|
||||
InitializeAllocator();
|
||||
|
||||
Symbolizer::GetOrInit();
|
||||
|
||||
// On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited
|
||||
// should be set to 1 prior to initializing the threads.
|
||||
asan_inited = 1;
|
||||
|
|
|
|||
|
|
@ -50,8 +50,6 @@ extern "C" void __lsan_init() {
|
|||
ThreadStart(tid, GetTid());
|
||||
SetCurrentThread(tid);
|
||||
|
||||
Symbolizer::GetOrInit();
|
||||
|
||||
if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit)
|
||||
Atexit(DoLeakCheck);
|
||||
lsan_inited = true;
|
||||
|
|
|
|||
|
|
@ -462,8 +462,8 @@ static Suppression *GetSuppressionForAddr(uptr addr) {
|
|||
// Suppress by module name.
|
||||
const char *module_name;
|
||||
uptr module_offset;
|
||||
if (Symbolizer::Get()->GetModuleNameAndOffsetForPC(addr, &module_name,
|
||||
&module_offset) &&
|
||||
if (Symbolizer::GetOrInit()
|
||||
->GetModuleNameAndOffsetForPC(addr, &module_name, &module_offset) &&
|
||||
SuppressionContext::Get()->Match(module_name, SuppressionLeak, &s))
|
||||
return s;
|
||||
|
||||
|
|
@ -471,7 +471,7 @@ static Suppression *GetSuppressionForAddr(uptr addr) {
|
|||
static const uptr kMaxAddrFrames = 16;
|
||||
InternalScopedBuffer<AddressInfo> addr_frames(kMaxAddrFrames);
|
||||
for (uptr i = 0; i < kMaxAddrFrames; i++) new (&addr_frames[i]) AddressInfo();
|
||||
uptr addr_frames_num = Symbolizer::Get()->SymbolizePC(
|
||||
uptr addr_frames_num = Symbolizer::GetOrInit()->SymbolizePC(
|
||||
addr, addr_frames.data(), kMaxAddrFrames);
|
||||
for (uptr i = 0; i < addr_frames_num; i++) {
|
||||
if (SuppressionContext::Get()->Match(addr_frames[i].function,
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@
|
|||
#include "sanitizer_common.h"
|
||||
#include "sanitizer_flags.h"
|
||||
#include "sanitizer_libc.h"
|
||||
#include "sanitizer_stacktrace.h"
|
||||
#include "sanitizer_symbolizer.h"
|
||||
|
||||
namespace __sanitizer {
|
||||
|
||||
|
|
@ -197,21 +195,6 @@ void ReportErrorSummary(const char *error_type, const char *file,
|
|||
ReportErrorSummary(buff.data());
|
||||
}
|
||||
|
||||
void ReportErrorSummary(const char *error_type, StackTrace *stack) {
|
||||
if (!common_flags()->print_summary)
|
||||
return;
|
||||
AddressInfo ai;
|
||||
#if !SANITIZER_GO
|
||||
if (stack->size > 0 && Symbolizer::Get()->CanReturnFileLineInfo()) {
|
||||
// Currently, we include the first stack frame into the report summary.
|
||||
// Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
|
||||
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
|
||||
Symbolizer::Get()->SymbolizePC(pc, &ai, 1);
|
||||
}
|
||||
#endif
|
||||
ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
|
||||
}
|
||||
|
||||
LoadedModule::LoadedModule(const char *module_name, uptr base_address) {
|
||||
full_name_ = internal_strdup(module_name);
|
||||
base_address_ = base_address;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
#include "sanitizer_common.h"
|
||||
#include "sanitizer_flags.h"
|
||||
#include "sanitizer_stacktrace.h"
|
||||
#include "sanitizer_symbolizer.h"
|
||||
|
||||
namespace __sanitizer {
|
||||
|
||||
|
|
@ -47,6 +49,21 @@ void SetSandboxingCallback(void (*f)()) {
|
|||
sandboxing_callback = f;
|
||||
}
|
||||
|
||||
void ReportErrorSummary(const char *error_type, StackTrace *stack) {
|
||||
if (!common_flags()->print_summary)
|
||||
return;
|
||||
AddressInfo ai;
|
||||
#if !SANITIZER_GO
|
||||
if (stack->size > 0 && Symbolizer::GetOrInit()->CanReturnFileLineInfo()) {
|
||||
// Currently, we include the first stack frame into the report summary.
|
||||
// Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
|
||||
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
|
||||
Symbolizer::GetOrInit()->SymbolizePC(pc, &ai, 1);
|
||||
}
|
||||
#endif
|
||||
ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
void NOINLINE
|
||||
|
|
|
|||
|
|
@ -423,8 +423,7 @@ void PrepareForSandboxing(__sanitizer_sandbox_arguments *args) {
|
|||
MemoryMappingLayout::CacheMemoryMappings();
|
||||
// Same for /proc/self/exe in the symbolizer.
|
||||
#if !SANITIZER_GO
|
||||
if (Symbolizer *sym = Symbolizer::GetOrNull())
|
||||
sym->PrepareForSandboxing();
|
||||
Symbolizer::GetOrInit()->PrepareForSandboxing();
|
||||
CovPrepareForSandboxing(args);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,17 +22,6 @@ Symbolizer *Symbolizer::symbolizer_;
|
|||
StaticSpinMutex Symbolizer::init_mu_;
|
||||
LowLevelAllocator Symbolizer::symbolizer_allocator_;
|
||||
|
||||
Symbolizer *Symbolizer::GetOrNull() {
|
||||
SpinMutexLock l(&init_mu_);
|
||||
return symbolizer_;
|
||||
}
|
||||
|
||||
Symbolizer *Symbolizer::Get() {
|
||||
SpinMutexLock l(&init_mu_);
|
||||
RAW_CHECK_MSG(symbolizer_ != 0, "Using uninitialized symbolizer!");
|
||||
return symbolizer_;
|
||||
}
|
||||
|
||||
Symbolizer *Symbolizer::Disable() {
|
||||
CHECK_EQ(0, symbolizer_);
|
||||
// Initialize a dummy symbolizer.
|
||||
|
|
|
|||
|
|
@ -72,12 +72,6 @@ struct DataInfo {
|
|||
|
||||
class Symbolizer {
|
||||
public:
|
||||
/// Returns platform-specific implementation of Symbolizer. The symbolizer
|
||||
/// must be initialized (with init or disable) before calling this function.
|
||||
static Symbolizer *Get();
|
||||
/// Returns platform-specific implementation of Symbolizer, or null if not
|
||||
/// initialized.
|
||||
static Symbolizer *GetOrNull();
|
||||
/// Initialize and return platform-specific implementation of symbolizer
|
||||
/// (if it wasn't already initialized).
|
||||
static Symbolizer *GetOrInit();
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ ReportStack *SymbolizeCode(uptr addr) {
|
|||
InternalScopedBuffer<AddressInfo> addr_frames(kMaxAddrFrames);
|
||||
for (uptr i = 0; i < kMaxAddrFrames; i++)
|
||||
new(&addr_frames[i]) AddressInfo();
|
||||
uptr addr_frames_num = Symbolizer::Get()->SymbolizePC(
|
||||
uptr addr_frames_num = Symbolizer::GetOrInit()->SymbolizePC(
|
||||
addr, addr_frames.data(), kMaxAddrFrames);
|
||||
if (addr_frames_num == 0)
|
||||
return NewReportStackEntry(addr);
|
||||
|
|
@ -132,7 +132,7 @@ ReportStack *SymbolizeCode(uptr addr) {
|
|||
|
||||
ReportLocation *SymbolizeData(uptr addr) {
|
||||
DataInfo info;
|
||||
if (!Symbolizer::Get()->SymbolizeData(addr, &info))
|
||||
if (!Symbolizer::GetOrInit()->SymbolizeData(addr, &info))
|
||||
return 0;
|
||||
ReportLocation *ent = (ReportLocation*)internal_alloc(MBlockReportStack,
|
||||
sizeof(ReportLocation));
|
||||
|
|
@ -148,7 +148,7 @@ ReportLocation *SymbolizeData(uptr addr) {
|
|||
}
|
||||
|
||||
void SymbolizeFlush() {
|
||||
Symbolizer::Get()->Flush();
|
||||
Symbolizer::GetOrInit()->Flush();
|
||||
}
|
||||
|
||||
} // namespace __tsan
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ Location __ubsan::getFunctionLocation(uptr Loc, const char **FName) {
|
|||
InitIfNecessary();
|
||||
|
||||
AddressInfo Info;
|
||||
if (!Symbolizer::Get()->SymbolizePC(Loc, &Info, 1) || !Info.module ||
|
||||
if (!Symbolizer::GetOrInit()->SymbolizePC(Loc, &Info, 1) || !Info.module ||
|
||||
!*Info.module)
|
||||
return Location(Loc);
|
||||
|
||||
|
|
@ -148,7 +148,7 @@ static void renderText(const char *Message, const Diag::Arg *Args) {
|
|||
Printf("%s", A.String);
|
||||
break;
|
||||
case Diag::AK_Mangled: {
|
||||
Printf("'%s'", Symbolizer::Get()->Demangle(A.String));
|
||||
Printf("'%s'", Symbolizer::GetOrInit()->Demangle(A.String));
|
||||
break;
|
||||
}
|
||||
case Diag::AK_SInt:
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ void __ubsan::InitIfNecessary() {
|
|||
// in this function.
|
||||
SanitizerToolName = "UndefinedBehaviorSanitizer";
|
||||
InitializeCommonFlags();
|
||||
Symbolizer::GetOrInit();
|
||||
}
|
||||
// Initialize UBSan-specific flags.
|
||||
InitializeFlags();
|
||||
|
|
|
|||
Loading…
Reference in New Issue