[compiler-rt] f2b4b54 - [HWASAN] Init lsan and install at_exit hook
Kirill Stoimenov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 18 17:40:31 PST 2023
Author: Kirill Stoimenov
Date: 2023-01-19T01:40:17Z
New Revision: f2b4b544174bd06a29a2db26f56e68444fa14204
URL: https://github.com/llvm/llvm-project/commit/f2b4b544174bd06a29a2db26f56e68444fa14204
DIFF: https://github.com/llvm/llvm-project/commit/f2b4b544174bd06a29a2db26f56e68444fa14204.diff
LOG: [HWASAN] Init lsan and install at_exit hook
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D141146
Added:
Modified:
compiler-rt/lib/hwasan/hwasan.cpp
compiler-rt/lib/hwasan/hwasan.h
compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
compiler-rt/lib/hwasan/hwasan_interceptors.cpp
compiler-rt/lib/hwasan/hwasan_linux.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/hwasan/hwasan.cpp b/compiler-rt/lib/hwasan/hwasan.cpp
index 70d123b0b1e6..cdf231c2547e 100644
--- a/compiler-rt/lib/hwasan/hwasan.cpp
+++ b/compiler-rt/lib/hwasan/hwasan.cpp
@@ -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;
diff --git a/compiler-rt/lib/hwasan/hwasan.h b/compiler-rt/lib/hwasan/hwasan.h
index ef4055a50ef2..c3d71a28142f 100644
--- a/compiler-rt/lib/hwasan/hwasan.h
+++ b/compiler-rt/lib/hwasan/hwasan.h
@@ -144,6 +144,8 @@ void HwasanOnDeadlySignal(int signo, void *info, void *context);
void HwasanInstallAtForkHandler();
+void InstallAtExitCheckLeaks();
+
void UpdateMemoryUsage();
void AppendToErrorMessageBuffer(const char *buffer);
diff --git a/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp b/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
index cdee4f476cb0..d1696f8aa796 100644
--- a/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
@@ -185,6 +185,8 @@ void InstallAtExitHandler() {}
void HwasanInstallAtForkHandler() {}
+void InstallAtExitCheckLeaks() {}
+
void InitializeOsSupport() {
#ifdef __aarch64__
uint32_t features = 0;
diff --git a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
index c67927dc9f60..05bf3f29eca3 100644
--- a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
@@ -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;
}
diff --git a/compiler-rt/lib/hwasan/hwasan_linux.cpp b/compiler-rt/lib/hwasan/hwasan_linux.cpp
index 88ccfde007d3..d3e4b5390e82 100644
--- a/compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -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
More information about the llvm-commits
mailing list