diff --git a/compiler-rt/lib/hwasan/hwasan.cpp b/compiler-rt/lib/hwasan/hwasan.cpp index 41c0c8b51fdfbbccd7664ec55cf4f006fc1beff5..44fd2f2b03b12ee0c103411b9298d4f45f9f8b91 100644 --- a/compiler-rt/lib/hwasan/hwasan.cpp +++ b/compiler-rt/lib/hwasan/hwasan.cpp @@ -355,8 +355,9 @@ __attribute__((constructor(0))) void __hwasan_init() { InitializeInterceptors(); InstallDeadlySignalHandlers(HwasanOnDeadlySignal); - InstallAtExitHandler(); // Needs __cxa_atexit interceptor. - + if (flags()->atexit) { // OHOS_LOCAL + InstallAtExitHandler(); // Needs __cxa_atexit interceptor. + } InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir); HwasanTSDInit(); diff --git a/compiler-rt/test/hwasan/TestCases/atexit.c b/compiler-rt/test/hwasan/TestCases/atexit.c new file mode 100644 index 0000000000000000000000000000000000000000..9873c2ef270a802d68d7f1161f2650fbf32f769c --- /dev/null +++ b/compiler-rt/test/hwasan/TestCases/atexit.c @@ -0,0 +1,26 @@ +// RUN: %clang_hwasan %s -o %t && %env_hwasan_opts=atexit=1:print_module_map=1 %run %t 2>&1 | FileCheck %s +// REQUIRES: stable-runtime +// OHOS_LOCAL + +#include +#include +#include + +#include + +void *InvalidFreeThread(void *arg) { + char * volatile x = (char*)malloc(10); + x[5] = 0; + free(x); + return NULL; +} + +int main() { + __hwasan_enable_allocator_tagging(); + pthread_t t; + pthread_create(&t, NULL, InvalidFreeThread, NULL); + pthread_join(t, NULL); + // Hwasan prints memory map in exit, check it here. + // CHECK-DAG: Process memory map follows + // CHECK-DAG: End of process memory map +}