[InstrProfiling] Place __llvm_prf_vnodes and __llvm_prf_names in llvm.used on ELF
authorFangrui Song <i@maskray.me>
Wed, 3 Mar 2021 19:32:24 +0000 (11:32 -0800)
committerFangrui Song <i@maskray.me>
Wed, 3 Mar 2021 19:32:24 +0000 (11:32 -0800)
commita84f4fc0dfcd0c0d249c3071f9bc5de0c56b6cca
tree8e6b6e034e4e1df11f6cdb0c3b194d3ea561bd02
parent75df61e93d22c5225469142bf79592bce4ffb3de
[InstrProfiling] Place __llvm_prf_vnodes and __llvm_prf_names in llvm.used on ELF

`__llvm_prf_vnodes` and `__llvm_prf_names` are used by runtime but not
referenced via relocation in the translation unit.

With `-z start-stop-gc` (LLD 13 (D96914); GNU ld 2.37 https://sourceware.org/bugzilla/show_bug.cgi?id=27451),
the linker does not let `__start_/__stop_` references retain their sections.

Place `__llvm_prf_vnodes` and `__llvm_prf_names` in `llvm.used` to make
them retained by the linker.

This patch changes most existing `UsedVars` cases to `CompilerUsedVars`
to reflect the ideal state - if the binary format properly supports
section based GC (dead stripping), `llvm.compiler.used` should be sufficient.

`__llvm_prf_vnodes` and `__llvm_prf_names` are switched to `UsedVars`
since we want them to be unconditionally retained by both compiler and linker.

Behaviors on COFF/Mach-O are not affected.

Reviewed By: davidxl

Differential Revision: https://reviews.llvm.org/D97649
compiler-rt/test/profile/Linux/instrprof-value-merge-lld.c
llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Instrumentation/InstrProfiling/icall.ll