[llvm] [hwasan] Add hwasan-all-globals option (PR #149621)
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 22 14:50:15 PDT 2025
================
@@ -1780,11 +1790,21 @@ void HWAddressSanitizer::instrumentGlobals() {
if (GV.hasCommonLinkage())
continue;
- // Globals with custom sections may be used in __start_/__stop_ enumeration,
- // which would be broken both by adding tags and potentially by the extra
- // padding/alignment that we insert.
- if (GV.hasSection())
- continue;
+ if (ClAllGlobals) {
+ // Avoid adding metadata emitted for the hwasan instrumentation itself.
+ // Code which makes assumptions about memory layout of globals between
+ // __start_<section>/__end_<section> linker-generated symbols may need
+ // manual adaptation.
+ auto Section = GV.getSection();
+ if (Section == "hwasan_globals" || Section == ".note.hwasan.globals")
----------------
pcc wrote:
No, the sanitizer passes are only run once (it's a bug otherwise). `instrumentGlobals` produces the list of globals to be instrumented before calling `instrumentGlobal` so I don't think the new globals should matter.
I was discussing this change with @fmayer and we think it needs to exclude globals in the `llvm.metadata` section, i.e. synthetic globals created for global constructors, destructors and globals with `__attribute__((used))`, among other things.
https://github.com/llvm/llvm-project/pull/149621
More information about the llvm-commits
mailing list