[compiler-rt] dc3069d - [NFC][hwasan][Fuchsia] Instead wrap contents of InitLoadedGlobals with if constexpr (!SANITIZER_FUCHSIA)

Leonard Chan via llvm-commits llvm-commits at lists.llvm.org
Wed May 17 11:46:30 PDT 2023


Author: Leonard Chan
Date: 2023-05-17T18:45:44Z
New Revision: dc3069dadf6fd4eece82936fe913dc8310a24cd0

URL: https://github.com/llvm/llvm-project/commit/dc3069dadf6fd4eece82936fe913dc8310a24cd0
DIFF: https://github.com/llvm/llvm-project/commit/dc3069dadf6fd4eece82936fe913dc8310a24cd0.diff

LOG: [NFC][hwasan][Fuchsia] Instead wrap contents of InitLoadedGlobals with if constexpr (!SANITIZER_FUCHSIA)

This prevents spamming the build log with unused InitLoadedGlobals when building fuchsia runtimes.

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

Added: 
    

Modified: 
    compiler-rt/lib/hwasan/hwasan.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan.cpp b/compiler-rt/lib/hwasan/hwasan.cpp
index 238fcc4d61853..b64e52cbb95f6 100644
--- a/compiler-rt/lib/hwasan/hwasan.cpp
+++ b/compiler-rt/lib/hwasan/hwasan.cpp
@@ -290,14 +290,20 @@ static bool InitializeSingleGlobal(const hwasan_global &global) {
 }
 
 static void InitLoadedGlobals() {
-  dl_iterate_phdr(
-      [](dl_phdr_info *info, size_t /* size */, void * /* data */) -> int {
-        for (const hwasan_global &global : HwasanGlobalsFor(
-                 info->dlpi_addr, info->dlpi_phdr, info->dlpi_phnum))
-          InitializeSingleGlobal(global);
-        return 0;
-      },
-      nullptr);
+  // 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.
+  if constexpr (!SANITIZER_FUCHSIA) {
+    dl_iterate_phdr(
+        [](dl_phdr_info *info, size_t /* size */, void * /* data */) -> int {
+          for (const hwasan_global &global : HwasanGlobalsFor(
+                   info->dlpi_addr, info->dlpi_phdr, info->dlpi_phnum))
+            InitializeSingleGlobal(global);
+          return 0;
+        },
+        nullptr);
+  }
 }
 
 // Prepare to run instrumented code on the main thread.
@@ -364,13 +370,7 @@ __attribute__((constructor(0))) void __hwasan_init() {
   DisableCoreDumperIfNecessary();
 
   InitInstrumentation();
-  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();
-  }
+  InitLoadedGlobals();
 
   // Needs to be called here because flags()->random_tags might not have been
   // initialized when InitInstrumentation() was called.


        


More information about the llvm-commits mailing list