[compiler-rt] bb8230b - [sanitizer] Internalize .preinit_array variables
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 12 11:15:50 PDT 2024
Author: Fangrui Song
Date: 2024-07-12T11:15:46-07:00
New Revision: bb8230bb2bcc9b68fbe9b9c02ac1c85dee4c80a0
URL: https://github.com/llvm/llvm-project/commit/bb8230bb2bcc9b68fbe9b9c02ac1c85dee4c80a0
DIFF: https://github.com/llvm/llvm-project/commit/bb8230bb2bcc9b68fbe9b9c02ac1c85dee4c80a0.diff
LOG: [sanitizer] Internalize .preinit_array variables
We can use an internal linkage variable to make it clear the variable is
not exported. The special section .preinit_array is a GC root.
Pull Request: https://github.com/llvm/llvm-project/pull/98584
Added:
Modified:
compiler-rt/lib/asan/asan_preinit.cpp
compiler-rt/lib/hwasan/hwasan_preinit.cpp
compiler-rt/lib/lsan/lsan_preinit.cpp
compiler-rt/lib/memprof/memprof_preinit.cpp
compiler-rt/lib/rtsan/rtsan_preinit.cpp
compiler-rt/lib/tsan/rtl/tsan_preinit.cpp
compiler-rt/lib/ubsan/ubsan_init_standalone_preinit.cpp
compiler-rt/test/tsan/Linux/check_preinit.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_preinit.cpp b/compiler-rt/lib/asan/asan_preinit.cpp
index b07556ec96f8f..a4923124519b9 100644
--- a/compiler-rt/lib/asan/asan_preinit.cpp
+++ b/compiler-rt/lib/asan/asan_preinit.cpp
@@ -15,10 +15,8 @@
using namespace __asan;
#if SANITIZER_CAN_USE_PREINIT_ARRAY
- // The symbol is called __local_asan_preinit, because it's not intended to be
- // exported.
- // This code linked into the main executable when -fsanitize=address is in
- // the link flags. It can only use exported interface functions.
- __attribute__((section(".preinit_array"), used))
- void (*__local_asan_preinit)(void) = __asan_init;
+// This section is linked into the main executable when -fsanitize=hwaddress is
+// specified to perform initialization at a very early stage.
+__attribute__((section(".preinit_array"), used)) static auto preinit =
+ __asan_init;
#endif
diff --git a/compiler-rt/lib/hwasan/hwasan_preinit.cpp b/compiler-rt/lib/hwasan/hwasan_preinit.cpp
index 8c9c95f413be3..8da47b5a2b786 100644
--- a/compiler-rt/lib/hwasan/hwasan_preinit.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_preinit.cpp
@@ -14,10 +14,8 @@
#include "sanitizer_common/sanitizer_internal_defs.h"
#if SANITIZER_CAN_USE_PREINIT_ARRAY
-// The symbol is called __local_hwasan_preinit, because it's not intended to
-// be exported.
-// This code linked into the main executable when -fsanitize=hwaddress is in
-// the link flags. It can only use exported interface functions.
-__attribute__((section(".preinit_array"), used)) static void (
- *__local_hwasan_preinit)(void) = __hwasan_init;
+// This section is linked into the main executable when -fsanitize=hwaddress is
+// specified to perform initialization at a very early stage.
+__attribute__((section(".preinit_array"), used)) static auto preinit =
+ __hwasan_init;
#endif
diff --git a/compiler-rt/lib/lsan/lsan_preinit.cpp b/compiler-rt/lib/lsan/lsan_preinit.cpp
index cd94e1e8718e6..30e90f7286499 100644
--- a/compiler-rt/lib/lsan/lsan_preinit.cpp
+++ b/compiler-rt/lib/lsan/lsan_preinit.cpp
@@ -14,8 +14,8 @@
#include "lsan.h"
#if SANITIZER_CAN_USE_PREINIT_ARRAY
- // We force __lsan_init to be called before anyone else by placing it into
- // .preinit_array section.
- __attribute__((section(".preinit_array"), used))
- void (*__local_lsan_preinit)(void) = __lsan_init;
+// This section is linked into the main executable when -fsanitize=leak is
+// specified to perform initialization at a very early stage.
+__attribute__((section(".preinit_array"), used)) static auto preinit =
+ __lsan_init;
#endif
diff --git a/compiler-rt/lib/memprof/memprof_preinit.cpp b/compiler-rt/lib/memprof/memprof_preinit.cpp
index 7092cd4ee5564..ad62a99c44c76 100644
--- a/compiler-rt/lib/memprof/memprof_preinit.cpp
+++ b/compiler-rt/lib/memprof/memprof_preinit.cpp
@@ -15,9 +15,8 @@
using namespace __memprof;
#if SANITIZER_CAN_USE_PREINIT_ARRAY
-// The symbol is called __local_memprof_preinit, because it's not intended to
-// be exported. This code linked into the main executable when -fmemory-profile
-// is in the link flags. It can only use exported interface functions.
-__attribute__((section(".preinit_array"),
- used)) void (*__local_memprof_preinit)(void) = __memprof_preinit;
+// This section is linked into the main executable when -fmemory-profile is
+// specified to perform initialization at a very early stage.
+__attribute__((section(".preinit_array"), used)) static auto preinit =
+ __memprof_preinit;
#endif
diff --git a/compiler-rt/lib/rtsan/rtsan_preinit.cpp b/compiler-rt/lib/rtsan/rtsan_preinit.cpp
index 8cea61c3ea8b7..1307268951fbc 100644
--- a/compiler-rt/lib/rtsan/rtsan_preinit.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_preinit.cpp
@@ -13,11 +13,9 @@
#if SANITIZER_CAN_USE_PREINIT_ARRAY
-// The symbol is called __local_rtsan_preinit, because it's not intended to be
-// exported.
-// This code is linked into the main executable when -fsanitize=realtime is in
-// the link flags. It can only use exported interface functions.
-__attribute__((section(".preinit_array"),
- used)) void (*__local_rtsan_preinit)(void) = __rtsan_init;
+// This section is linked into the main executable when -fsanitize=realtime is
+// specified to perform initialization at a very early stage.
+__attribute__((section(".preinit_array"), used)) static auto preinit =
+ __rtsan_init;
#endif
diff --git a/compiler-rt/lib/tsan/rtl/tsan_preinit.cpp b/compiler-rt/lib/tsan/rtl/tsan_preinit.cpp
index 205bdbf93b201..69700f2dde24d 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_preinit.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_preinit.cpp
@@ -16,11 +16,9 @@
#if SANITIZER_CAN_USE_PREINIT_ARRAY
-// The symbol is called __local_tsan_preinit, because it's not intended to be
-// exported.
-// This code linked into the main executable when -fsanitize=thread is in
-// the link flags. It can only use exported interface functions.
-__attribute__((section(".preinit_array"), used))
-void (*__local_tsan_preinit)(void) = __tsan_init;
+// This section is linked into the main executable when -fsanitize=thread is
+// specified to perform initialization at a very early stage.
+__attribute__((section(".preinit_array"), used)) static auto preinit =
+ __tsan_init;
#endif
diff --git a/compiler-rt/lib/ubsan/ubsan_init_standalone_preinit.cpp b/compiler-rt/lib/ubsan/ubsan_init_standalone_preinit.cpp
index fabbf919a4022..8a2a631834b94 100644
--- a/compiler-rt/lib/ubsan/ubsan_init_standalone_preinit.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_init_standalone_preinit.cpp
@@ -30,6 +30,6 @@ static void PreInitAsStandalone() {
} // namespace __ubsan
-__attribute__((section(".preinit_array"), used)) void (*__local_ubsan_preinit)(
- void) = __ubsan::PreInitAsStandalone;
+__attribute__((section(".preinit_array"), used)) static auto preinit =
+ __ubsan::PreInitAsStandalone;
#endif // SANITIZER_CAN_USE_PREINIT_ARRAY
diff --git a/compiler-rt/test/tsan/Linux/check_preinit.cpp b/compiler-rt/test/tsan/Linux/check_preinit.cpp
index b5f63d3d4b9e3..3b197139f3672 100644
--- a/compiler-rt/test/tsan/Linux/check_preinit.cpp
+++ b/compiler-rt/test/tsan/Linux/check_preinit.cpp
@@ -2,7 +2,7 @@
// RUN: %t.so && \
// RUN: %clang_tsan -O1 %s %t.so -o %t && %run %t 2>&1 | FileCheck %s
// RUN: llvm-objdump -t %t | FileCheck %s --check-prefix=CHECK-DUMP
-// CHECK-DUMP: {{[.]preinit_array.*__local_tsan_preinit}}
+// CHECK-DUMP: {{[.]preinit_array.*preinit}}
// SANITIZER_CAN_USE_PREINIT_ARRAY is undefined on android.
// UNSUPPORTED: android
More information about the llvm-commits
mailing list