Call __hwasan_init_static() during libc startup in statically linked executables.
__hwasan_init() was segfaulting when called from here because it
was calling into libc functions which required more of libc to be
initialized. Instead, call __hwasan_init_static(), which does a
minimal amount of initialization for statically linked executables,
just enough that we can run instrumented code. __hwasan_init() itself
will end up being called later (most likely from a global ctor)
after libc is fully initialized.
We'll need to wait for LLVM r352816+r352823 to land in our toolchain
before landing this.
Change-Id: I12ffc7e08f6dd161e4ff2088f8d56265af7baedf
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index 41f100d..b4bddce 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -202,7 +202,7 @@
exit(slingshot(args.argc, args.argv, args.envp));
}
-extern "C" void __hwasan_init();
+extern "C" void __hwasan_init_static();
__attribute__((no_sanitize("hwaddress")))
__noreturn void __libc_init(void* raw_args,
@@ -214,8 +214,9 @@
// Install main thread TLS early. It will be initialized later in __libc_init_main_thread. For now
// all we need is access to TLS_SLOT_SANITIZER.
__set_tls(&temp_tcb.tls_slot(0));
- // Initialize HWASan. This sets up TLS_SLOT_SANITIZER, among other things.
- __hwasan_init();
+ // Initialize HWASan enough to run instrumented code. This sets up TLS_SLOT_SANITIZER, among other
+ // things.
+ __hwasan_init_static();
// We are ready to run HWASan-instrumented code, proceed with libc initialization...
#endif
__real_libc_init(raw_args, onexit, slingshot, structors, &temp_tcb);