This is an archive of the discontinued LLVM Phabricator instance.

[SanitizerCoverage] Clarify llvm.used/llvm.compiler.used and partially fix unmatched metadata sections on Windows
ClosedPublic

Authored by MaskRay on Feb 24 2021, 6:02 PM.

Details

Summary

__sancov_pcs parallels the other metadata section(s). While some optimizers
(e.g. GlobalDCE) respect linker semantics for comdat and retain or discard the
sections as a unit, some (e.g. GlobalOpt/ConstantMerge) do not. So we have to
conservatively retain all unconditionally in the compiler.

When a comdat is used, the COFF/ELF linkers' GC semantics ensure the
associated parallel array elements are retained or discarded together,
so llvm.compiler.used is sufficient.

Otherwise (MachO (see rL311955/rL311959), COFF special case where comdat is not
used), we have to use llvm.used to conservatively make all sections retain by
the linker. This will fix the Windows problem once internal linkage GlobalObject's in llvm.used are retained via /INCLUDE:.

Diff Detail

Event Timeline

MaskRay created this revision.Feb 24 2021, 6:02 PM
MaskRay requested review of this revision.Feb 24 2021, 6:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2021, 6:02 PM
morehouse added inline comments.Feb 25 2021, 8:43 AM
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
684

Don't we still need compiler used? https://llvm.org/docs/LangRef.html#associated-metadata

Also even without this change they are only marked "used" on Mac currently, IIRC due to GC issues with their linker.

696

What happened to the associated metadata that's added here at ToT?

MaskRay updated this revision to Diff 326458.Feb 25 2021, 11:44 AM
MaskRay retitled this revision from [SanitizerCoverage] Don't use llvm.used if comdat to [SanitizerCoverage] Clarify llvm.used/llvm.compiler.used and fix unmatched metadata sections on Windows.
MaskRay edited the summary of this revision. (Show Details)

Fix a bug on Windows

MaskRay marked 2 inline comments as done.Feb 25 2021, 11:47 AM
MaskRay added inline comments.
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
684

Yes, I realized that llvm.compiler.used is needed to prevent agggressive optimizations from GlobalOpt/ConstantMerge.

I clarified why llvm.used is used - and use it on a case which may be an existing bug on Wondows.

696

I think !associated cannot be used when inlining is possible. See D97430.

This means even interposable linkages (which are normally not inlinable) can be inlined with LTO, so !associated cannot be used at all.

MaskRay marked 2 inline comments as done.Feb 25 2021, 11:48 AM
This revision is now accepted and ready to land.Feb 25 2021, 11:54 AM
MaskRay edited the summary of this revision. (Show Details)Feb 25 2021, 12:02 PM
vitalybuka accepted this revision.Feb 25 2021, 12:09 PM
MaskRay edited the summary of this revision. (Show Details)Feb 26 2021, 11:06 AM
MaskRay retitled this revision from [SanitizerCoverage] Clarify llvm.used/llvm.compiler.used and fix unmatched metadata sections on Windows to [SanitizerCoverage] Clarify llvm.used/llvm.compiler.used and partially fix unmatched metadata sections on Windows.Feb 26 2021, 11:09 AM
MaskRay edited the summary of this revision. (Show Details)
This revision was landed with ongoing or failed builds.Feb 26 2021, 11:10 AM
This revision was automatically updated to reflect the committed changes.