This is an archive of the discontinued LLVM Phabricator instance.

Delete 'llvm.asan.globals' for global metadata.
ClosedPublic

Authored by hctim on Jun 15 2022, 3:51 PM.

Details

Summary

Now that we have the sanitizer metadata that is actually on the global
variable, and now that we use debuginfo in order to do symbolization of
globals, we can delete the 'llvm.asan.globals' IR synthesis.

This patch deletes the 'location' part of the __asan_global that's
embedded in the binary as well, because it's unnecessary. This saves
about ~1.7% of the optimised non-debug with-asserts clang binary.

Diff Detail

Event Timeline

hctim created this revision.Jun 15 2022, 3:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2022, 3:51 PM
hctim requested review of this revision.Jun 15 2022, 3:51 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptJun 15 2022, 3:51 PM
Herald added subscribers: llvm-commits, Restricted Project, cfe-commits. · View Herald Transcript
hctim updated this revision to Diff 437385.Jun 15 2022, 3:55 PM

Small test fix.

This saves about ~0.275% of the optimised clang binary.

Worth clarifying a bit which -O level and whether -g is used.

hctim added a comment.Jun 23 2022, 5:13 PM

This saves about ~0.275% of the optimised clang binary.

Worth clarifying a bit which -O level and whether -g is used.

clang-15 binary, no -g, -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE=Release:

Before: 1041657808
After: 1024109680

Not sure what led to the original measurement, but seems like this saves ~1.7% of binary size for ASan. I'll update the description.

hctim edited the summary of this revision. (Show Details)Jun 23 2022, 5:13 PM
hctim updated this revision to Diff 439880.Jun 24 2022, 1:42 PM

Rebase on main / landed changes.

vitalybuka added inline comments.Jun 24 2022, 2:13 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
2100

was this demanded before?

2330

MD was fine, less changed lines

hctim marked 2 inline comments as done.Jun 24 2022, 3:58 PM
hctim added inline comments.
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
2100

removed, think this got accidentally added during a sweep of demangling names for the produced metadata, which is necessary now that clang doesn't produce the info.

2330

done

hctim updated this revision to Diff 439912.Jun 24 2022, 3:59 PM
hctim marked 2 inline comments as done.

Vitaly's comments - round 1.

The rest is LGTM

clang/lib/CodeGen/SanitizerMetadata.cpp
67–72

I recommend to move this change into another patch

and it should probably be:
Meta.IsDynInit &= IsDynInit && FsanitizeArgument.has(SanitizerKind::Address) && !Meta.NoAddress && !CGM.isInNoSanitizeLis;

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
34

Please don't demangle in this patch, or keep as close as possible to the current behaviour
Also isn't demangling by compliler-rt is better? mangled form is shorter.

1355–1359

I believe previous was like this.
if you want to change that lets do another patch.

2330

Constant::getNullValue

hctim updated this revision to Diff 439918.Jun 24 2022, 4:33 PM
hctim marked 3 inline comments as done.

Vitaly's comments, round 2.

clang/lib/CodeGen/SanitizerMetadata.cpp
67–72

sure, will punt to follow-up patch (leaving comment open, will close it out when i've added the dependency)

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
34

as discussed, current descriptor has the demangled name because it's provided by clang frontend in llvm.asan.globals.

to keep this migration as close to the original as possible, keeping demangle of names in descriptors here, but added a TODO for follow-up work to instead demangle in the runtime.

1355–1359

refactored it slightly, it's clear to me now (and IMHO much clearer to reason about, i suck at flipping multiple conditions in my head) that it's the same code

vitalybuka accepted this revision.Jun 24 2022, 4:46 PM
vitalybuka added inline comments.
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
1355–1359

Before: G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
Now: G->hasInitializer() && !(G->hasSanitizerMetadata() && G->getSanitizerMetadata().IsDynInit)

Which is fine, because previously NoMD == !IsDynInit

So logic-wise this version is LGTM
equivalent one-liner is even cleaner:
return G->hasInitializer() && !(G->hasSanitizerMetadata() && G->getSanitizerMetadata().IsDynInit)

This revision is now accepted and ready to land.Jun 24 2022, 4:46 PM
vitalybuka added inline comments.Jun 24 2022, 4:47 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
1355–1359

Before: G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;

"Before" is "Before the patch"

hctim marked 3 inline comments as done.
hctim added inline comments.
clang/lib/CodeGen/SanitizerMetadata.cpp
67–72

(punted to D128672)

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
1355–1359

I personally find the multi-liner much easier to read than the one-liner, okay to leave?

vitalybuka added inline comments.Jun 27 2022, 2:33 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
1355–1359

up to you

This revision was landed with ongoing or failed builds.Jun 27 2022, 2:57 PM
This revision was automatically updated to reflect the committed changes.
hctim marked an inline comment as done.
thakis added a subscriber: thakis.Jun 27 2022, 11:02 PM

Looks like this breaks check-clang on windows: http://45.33.8.238/win/61067/step_7.txt

Please take a look and revert for now if it takes a while to fix.

Looks like this breaks check-clang on windows: http://45.33.8.238/win/61067/step_7.txt

Please take a look and revert for now if it takes a while to fix.

Thanks. Added a2095d1aff84. Bot looks green now: http://45.33.8.238/win/61118/summary.html