We cannot link to the function because if the function gets discarded,
we'll end up with and invalid link which leads to a linker error:
sh_link points to discarded section
| Paths 
 |  Differential  D95930  
[InstrProfiling] Use self-link for counter metadata AbandonedPublic Authored by phosek on Feb 3 2021, 1:10 AM. 
Details 
 Summary We cannot link to the function because if the function gets discarded, sh_link points to discarded section 
Diff Detail 
 
Unit TestsFailed Event TimelineComment Actions 
 If the text section .text.foo gets discarded, the __profc_foo section should get discarded, too. Comment Actions 
 Could it be because we discard COMDAT sections early on when reading input files, so later the __profc_foo section doesn't get collected by GC because it's a C identifier and considered a GC root? Comment Actions COMDAT and GC are orthogonal. COMDAT selection runs before GC. Every section flag except SHF_GROUP should be retained. Do you have an object file to demonstrate the GC issue? 
Revision Contents 
 
Diff 321026 llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
 llvm/test/Instrumentation/InstrProfiling/icall.ll
 llvm/test/Instrumentation/InstrProfiling/linkage.ll
 llvm/test/Transforms/PGOProfile/associated.ll
 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||