[HWASAN] Init lsan and install at_exit hook

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D141146
This commit is contained in:
Kirill Stoimenov
2022-12-21 22:31:40 +00:00
parent ad4b66fd9b
commit f2b4b54417
5 changed files with 31 additions and 0 deletions

View File

@@ -388,10 +388,22 @@ __attribute__((constructor(0))) void __hwasan_init() {
HwasanAllocatorInit();
HwasanInstallAtForkHandler();
if (CAN_SANITIZE_LEAKS) {
__lsan::InitCommonLsan();
InstallAtExitCheckLeaks();
}
#if HWASAN_CONTAINS_UBSAN
__ubsan::InitAsPlugin();
#endif
if (CAN_SANITIZE_LEAKS) {
__lsan::ScopedInterceptorDisabler disabler;
Symbolizer::LateInitialize();
} else {
Symbolizer::LateInitialize();
}
VPrintf(1, "HWAddressSanitizer init done\n");
hwasan_init_is_running = 0;

View File

@@ -144,6 +144,8 @@ void HwasanOnDeadlySignal(int signo, void *info, void *context);
void HwasanInstallAtForkHandler();
void InstallAtExitCheckLeaks();
void UpdateMemoryUsage();
void AppendToErrorMessageBuffer(const char *buffer);

View File

@@ -185,6 +185,8 @@ void InstallAtExitHandler() {}
void HwasanInstallAtForkHandler() {}
void InstallAtExitCheckLeaks() {}
void InitializeOsSupport() {
#ifdef __aarch64__
uint32_t features = 0;

View File

@@ -220,6 +220,10 @@ INTERCEPTOR(void, longjmp, __hw_jmp_buf env, int val) {
namespace __hwasan {
int OnExit() {
if (CAN_SANITIZE_LEAKS && common_flags()->detect_leaks &&
__lsan::HasReportedLeaks()) {
return common_flags()->exitcode;
}
// FIXME: ask frontend whether we need to return failure.
return 0;
}

View File

@@ -541,6 +541,17 @@ void HwasanInstallAtForkHandler() {
pthread_atfork(before, after, after);
}
void InstallAtExitCheckLeaks() {
if (CAN_SANITIZE_LEAKS) {
if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) {
if (flags()->halt_on_error)
Atexit(__lsan::DoLeakCheck);
else
Atexit(__lsan::DoRecoverableLeakCheckVoid);
}
}
}
} // namespace __hwasan
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD