In -fprofile-instr-generate compilation, to remove the redundant profile variables for the COMDAT functions, these variables are placed in the same COMDAT group as its associated function.
This way when the COMDAT function is not picked by the linker, those profile variables will also not be output in the final binary.
One problem here is that we lose the ability to link the objects built w and w/o -fprofile-instr-generate. The linker may choose one version of COMDAT that not expanded (i.e. not built with -fprofile-instr-generate). All the references to the variables
become dangling. The result binary will segfalut. If ld.gold is used, we usually see a warning like:
foo.o:foo.bc:function __llvm_profile_register_functions: warning: relocation refers to discarded section
This patch puts the profile variables for COMDAT functions to its
own COMDAT group to avoid the problem.