[all-commits] [llvm/llvm-project] 4d6389: [SanitizerCoverage] Drop !associated on metadata s...

Fangrui Song via All-commits all-commits at lists.llvm.org
Thu Feb 25 11:59:42 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4d63892acb17ba8ee5b146e83d38f244d8d92222
      https://github.com/llvm/llvm-project/commit/4d63892acb17ba8ee5b146e83d38f244d8d92222
  Author: Fangrui Song <i at maskray.me>
  Date:   2021-02-25 (Thu, 25 Feb 2021)

  Changed paths:
    M llvm/include/llvm/Transforms/Instrumentation.h
    M llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
    M llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
    M llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
    M llvm/test/Instrumentation/SanitizerCoverage/inline-bool-flag.ll
    R llvm/test/Instrumentation/SanitizerCoverage/interposable-symbol-nocomdat.ll
    A llvm/test/Instrumentation/SanitizerCoverage/interposable-symbol.ll
    M llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard.ll

  Log Message:
  -----------
  [SanitizerCoverage] Drop !associated on metadata sections

In SanitizerCoverage, the metadata sections (`__sancov_guards`,
`__sancov_cntrs`, `__sancov_bools`) are referenced by functions.  After
inlining, such a `__sancov_*` section can be referenced by more than one
functions, but its sh_link still refers to the original function's section.
(Note: a SHF_LINK_ORDER section referenced by a section other than its linked-to
section violates the invariant.)

If the original function's section is discarded (e.g. LTO internalization +
`ld.lld --gc-sections`), ld.lld may report a `sh_link points to discarded section` error.

This above reasoning means that `!associated` is not appropriate to be called by
an inlinable function. Non-interposable functions are inline candidates, so we
have to drop `!associated`. A `__sancov_pcs` is not referenced by other sections
but is expected to parallel a metadata section, so we have to make sure the two
sections are retained or discarded at the same time. A section group does the
trick.  (Note: we have a module ctor, so `getUniqueModuleId` guarantees to
return a non-empty string, and `GetOrCreateFunctionComdat` guarantees to return
non-null.)

For interposable functions, we could keep using `!associated`, but
LTO can change the linkage to `internal` and allow such functions to be inlinable,
so we have to drop `!associated`, too. To not interfere with section
group resolution, we need to use the `noduplicates` variant (section group flag 0).
(This allows us to get rid of the ModuleID parameter.)
In -fno-pie and -fpie code (mostly dso_local), instrumented interposable
functions have WeakAny/LinkOnceAny linkages, which are rare. So the
section group header overload should be low.

This patch does not change the object file output for COFF (where `!associated` is ignored).

Reviewed By: morehouse, rnk, vitalybuka

Differential Revision: https://reviews.llvm.org/D97430




More information about the All-commits mailing list