[compiler-rt][hwasan] Do not call InitLoadedGlobals in __hwasan_init
authorLeonard Chan <leonardchan@google.com>
Tue, 8 Nov 2022 23:06:19 +0000 (23:06 +0000)
committerLeonard Chan <leonardchan@google.com>
Wed, 9 Nov 2022 19:47:05 +0000 (19:47 +0000)
Fuchsia's libc provides a new hook (__sanitizer_module_loaded) which calls
hwasan_library_loaded in the startup path which will register globals in
loaded modules.

Differential Revision: https://reviews.llvm.org/D137676

compiler-rt/lib/hwasan/hwasan.cpp

index bb946c2..9db4fb0 100644 (file)
@@ -340,7 +340,13 @@ __attribute__((constructor(0))) void __hwasan_init() {
   DisableCoreDumperIfNecessary();
 
   InitInstrumentation();
-  InitLoadedGlobals();
+  if constexpr (!SANITIZER_FUCHSIA) {
+    // Fuchsia's libc provides a hook (__sanitizer_module_loaded) that runs on
+    // the startup path which calls into __hwasan_library_loaded on all
+    // initially loaded modules, so explicitly registering the globals here
+    // isn't needed.
+    InitLoadedGlobals();
+  }
 
   // Needs to be called here because flags()->random_tags might not have been
   // initialized when InitInstrumentation() was called.