[compiler-rt] 0ebb756 - [hwasan] Add __hwasan_init constructor to runtime lib.
Mitch Phillips via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 4 11:18:40 PDT 2021
Author: Mitch Phillips
Date: 2021-08-04T11:18:23-07:00
New Revision: 0ebb75608759cc1ee1016699e15d03e8e3f30d14
URL: https://github.com/llvm/llvm-project/commit/0ebb75608759cc1ee1016699e15d03e8e3f30d14
DIFF: https://github.com/llvm/llvm-project/commit/0ebb75608759cc1ee1016699e15d03e8e3f30d14.diff
LOG: [hwasan] Add __hwasan_init constructor to runtime lib.
Found by an Android toolchain upgrade, inherited module constructors
(like init_have_lse_atomics from the builtins) can sneak into the hwasan
runtime. If these inherited constructors call hwasanified libc
functions, then the HWASan runtime isn't setup enough, and the code
crashes.
Mark the initialized as a high-priority initializer to fix this.
Reviewed By: pcc, yabinc
Differential Revision: https://reviews.llvm.org/D107391
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 cbe0dee66dcda..e687f56b63f59 100644
--- a/compiler-rt/lib/hwasan/hwasan.cpp
+++ b/compiler-rt/lib/hwasan/hwasan.cpp
@@ -319,7 +319,7 @@ void __hwasan_init_static() {
InitializeSingleGlobal(global);
}
-void __hwasan_init() {
+__attribute__((constructor(0))) void __hwasan_init() {
CHECK(!hwasan_init_is_running);
if (hwasan_inited) return;
hwasan_init_is_running = 1;
More information about the llvm-commits
mailing list