[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
This commit is contained in:
Mitch Phillips 2021-08-04 11:03:24 -07:00
parent 440d9712eb
commit 0ebb756087
1 changed files with 1 additions and 1 deletions

View File

@ -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;