[all-commits] [llvm/llvm-project] 955845: [SanitizerCoverage] Make __start_/__stop_ symbols ...

Fangrui Song via All-commits all-commits at lists.llvm.org
Thu Mar 18 16:46:23 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9558456b5370e64560e76f6580b979fccadd4744
      https://github.com/llvm/llvm-project/commit/9558456b5370e64560e76f6580b979fccadd4744
  Author: Fangrui Song <i at maskray.me>
  Date:   2021-03-18 (Thu, 18 Mar 2021)

  Changed paths:
    M llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
    M llvm/test/Instrumentation/SanitizerCoverage/inline-8bit-counters.ll
    M llvm/test/Instrumentation/SanitizerCoverage/inline-bool-flag.ll
    M llvm/test/Instrumentation/SanitizerCoverage/pc-table.ll

  Log Message:
  -----------
  [SanitizerCoverage] Make __start_/__stop_ symbols extern_weak

On ELF, we place the metadata sections (`__sancov_guards`, `__sancov_cntrs`,
`__sancov_bools`, `__sancov_pcs` in section groups (either `comdat any` or
`comdat noduplicates`).

With `--gc-sections`, LLD since D96753 and GNU ld `-z start-stop-gc` may garbage
collect such sections. If all `__sancov_bools` are discarded, LLD will error
`error: undefined hidden symbol: __start___sancov_cntrs` (other sections are similar).

```
% cat a.c
void discarded() {}
% clang -fsanitize-coverage=func,trace-pc-guard -fpic -fvisibility=hidden a.c -shared -fuse-ld=lld -Wl,--gc-sections
...
ld.lld: error: undefined hidden symbol: __start___sancov_guards
>>> referenced by a.c
>>>               /tmp/a-456662.o:(sancov.module_ctor_trace_pc_guard)
```

Use the `extern_weak` linkage (lowered to undefined weak symbols) to avoid the
undefined error.

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




More information about the All-commits mailing list