This is an archive of the discontinued LLVM Phabricator instance.

[asan] Instrument comdat globals on COFF targets
ClosedPublic

Authored by rnk on Jun 6 2018, 12:03 PM.

Details

Summary

If we can use comdats, then we can make it so that the global metadata
is thrown away if the prevailing definition of the global was
uninstrumented. I have only tested this on COFF targets, but in theory,
there is no reason that we cannot also do this for ELF.

This will allow us to re-enable string merging with ASan on Windows,
reducing the binary size cost of ASan on Windows.

Event Timeline

rnk created this revision.Jun 6 2018, 12:03 PM
pcc added a subscriber: pcc.Jun 6 2018, 12:12 PM

there is no reason that we cannot also do this for ELF.

I thought we were already using !associated (which translates into SHF_LINK_ORDER) on ELF?

Yes, and we put all globals in comdats, too. See AddressSanitizerModule::InstrumentGlobalsELF.

rnk added a comment.Jun 6 2018, 12:58 PM
In D47841#1123978, @pcc wrote:

there is no reason that we cannot also do this for ELF.

I thought we were already using !associated (which translates into SHF_LINK_ORDER) on ELF?

We use that in addition to setting the comdat group. I think !associated is only really needed to make --gc-sections work. The comdat group is what allows us to mix instrumented and uninstrumented globals and not worry about which one prevails.

Anyway, it's just a matter of changing isOSBinFormatCOFF to supportsCOMDAT() to enable it for ELF. I've gotten in trouble in the past for claiming to know more about ELF than I really do, so I'd rather commit that as a separate, easily revertable one line change.

rnk added a comment.Jun 7 2018, 6:02 PM

Think we should go for it?

eugenis accepted this revision.Jun 8 2018, 9:45 AM

Sounds like a good idea.

This revision is now accepted and ready to land.Jun 8 2018, 9:45 AM
This revision was automatically updated to reflect the committed changes.