Skip to content

[hwasan] Don't check code model if there are no globals #131152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions compiler-rt/lib/hwasan/hwasan_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,21 @@ ArrayRef<const hwasan_global> HwasanGlobalsFor(ElfW(Addr) base,
continue;
}

// Only libraries with instrumented globals need to be checked against the
// code model since they use relocations that aren't checked at link time.
CheckCodeModel(base, phdr, phnum);

auto *global_note = reinterpret_cast<const hwasan_global_note *>(desc);
auto *globals_begin = reinterpret_cast<const hwasan_global *>(
note + global_note->begin_relptr);
auto *globals_end = reinterpret_cast<const hwasan_global *>(
note + global_note->end_relptr);

// Only libraries with instrumented globals need to be checked against the
// code model since they use relocations that aren't checked at link time.
//
// There is always a HWASan globals note ("Create the note even if we
// aren't instrumenting globals." - HWAddressSanitizer.cpp), but we can
// elide the code model check if there are no globals.
if (globals_begin != globals_end)
CheckCodeModel(base, phdr, phnum);

return {globals_begin, globals_end};
}
}
Expand Down