-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
Currently, the code model check is always performed even if there are no real globals, because the HWASan compiler pass always leaves a 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
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Thurston Dang (thurstond) ChangesCurrently, the code model check is always performed even if there are no real globals, because the HWASan compiler pass always leaves a 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 Full diff: https://github.com/llvm/llvm-project/pull/131152.diff 1 Files Affected:
diff --git a/compiler-rt/lib/hwasan/hwasan_globals.cpp b/compiler-rt/lib/hwasan/hwasan_globals.cpp
index 7e0f3df20dd05..e2723450e26ec 100644
--- a/compiler-rt/lib/hwasan/hwasan_globals.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_globals.cpp
@@ -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 real globals.
+ if (globals_begin != globals_end)
+ CheckCodeModel(base, phdr, phnum);
+
return {globals_begin, globals_end};
}
}
|
What makes a global real vs unreal? |
Zero-length globals aren't real, they can't hurt you except they can hurt because the runtime will still perform the code model check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A real good change.
nit: you still have "real" in the commit message
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
Currently, the code model check is always performed even if there are no globals, because:
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