Skip to content

Commit 143bf95

Browse files
authored
[hwasan] Don't check code model if there are no globals (#131152)
Currently, the code model check is always performed even if there are no globals, because: 1) the HWASan compiler pass always leaves a note 2) the HWASan runtime always performs the check if there is a HWASan globals note. This unnecessarily adds a 2**32 byte size limit. This patch elides the check if the globals note doesn't actually contain globals, thus allowing larger libraries to be successfully instrumented without globals. Sent from my iPhone
1 parent b003fac commit 143bf95

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

compiler-rt/lib/hwasan/hwasan_globals.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,21 @@ ArrayRef<const hwasan_global> HwasanGlobalsFor(ElfW(Addr) base,
7373
continue;
7474
}
7575

76-
// Only libraries with instrumented globals need to be checked against the
77-
// code model since they use relocations that aren't checked at link time.
78-
CheckCodeModel(base, phdr, phnum);
79-
8076
auto *global_note = reinterpret_cast<const hwasan_global_note *>(desc);
8177
auto *globals_begin = reinterpret_cast<const hwasan_global *>(
8278
note + global_note->begin_relptr);
8379
auto *globals_end = reinterpret_cast<const hwasan_global *>(
8480
note + global_note->end_relptr);
8581

82+
// Only libraries with instrumented globals need to be checked against the
83+
// code model since they use relocations that aren't checked at link time.
84+
//
85+
// There is always a HWASan globals note ("Create the note even if we
86+
// aren't instrumenting globals." - HWAddressSanitizer.cpp), but we can
87+
// elide the code model check if there are no globals.
88+
if (globals_begin != globals_end)
89+
CheckCodeModel(base, phdr, phnum);
90+
8691
return {globals_begin, globals_end};
8792
}
8893
}

0 commit comments

Comments
 (0)