[SanitizerCoverage] Clarify llvm.used/llvm.compiler.used and partially fix unmatched...
authorFangrui Song <i@maskray.me>
Fri, 26 Feb 2021 19:10:02 +0000 (11:10 -0800)
committerFangrui Song <i@maskray.me>
Fri, 26 Feb 2021 19:10:03 +0000 (11:10 -0800)
commitb55f29c194d31cb51096d80b5e2710fc3385a7ef
tree4d842824b954de99986d5871a449e0fe73268818
parentb18f14d6897b9e9f34ffd0d8ed46b8ac596fbf05
[SanitizerCoverage] Clarify llvm.used/llvm.compiler.used and partially fix unmatched metadata sections on Windows

`__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:`.

Reviewed By: morehouse, vitalybuka

Differential Revision: https://reviews.llvm.org/D97432
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard.ll