llvm-project/llvm/test/LTO
Fangrui Song 4fbe33593c [LTO] Make local linkage GlobalValue in non-prevailing COMDAT available_externally
See the updated linkonce_resolution_comdat.ll. For a local linkage GV in a
non-prevailing COMDAT, it remains defined while its leader has been made
available_externally. This violates the COMDAT rule that its members must be
retained or discarded as a unit.

To fix this, update the regular LTO change D34803 to track local linkage
GlobalValues, and port the code to ThinLTO (GlobalAliases are not handled.)

Fix https://github.com/llvm/llvm-project/issues/58215:
as a size optimization, we place private `__profd_` in a COMDAT with a
`__profc_` key. When FuncImport.cpp makes `__profc_` available_externally due to
a non-prevailing COMDAT, `__profd_` incorrectly remains private. This change
makes the `__profd_` available_externally.

```
cat > c.h <<'eof'
extern void bar();
inline __attribute__((noinline)) void foo() {}
eof
cat > m1.cc <<'eof'
#include "c.h"
int main() {
  bar();
  foo();
}
eof
cat > m2.cc <<'eof'
#include "c.h"
__attribute__((noinline)) void bar() {
  foo();
}
eof

clang -O2 -fprofile-generate=./t m1.cc m2.cc -flto -fuse-ld=lld -o t_gen
rm -fr t && ./t_gen && llvm-profdata show -function=foo t/default_*.profraw
# one _Z3foov

clang -O2 -fprofile-generate=./t m1.cc m2.cc -flto=thin -fuse-ld=lld -o t_gen
rm -fr t && ./t_gen && llvm-profdata show -function=foo t/default_*.profraw
# one _Z3foov
```

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D135427
2022-10-08 11:09:43 -07:00
..
AArch64 Support the min of module flags when linking, use for AArch64 BTI/PAC-RET 2022-04-13 09:31:51 +02:00
ARM
PowerPC [libLTO] Set data-sections by default in libLTO. 2022-07-27 09:39:39 -05:00
Resolution/X86 [LTO] Make local linkage GlobalValue in non-prevailing COMDAT available_externally 2022-10-08 11:09:43 -07:00
X86 [WPD] Use new llvm.public.type.test intrinsic for potentially publicly visible classes 2022-07-26 08:01:08 -07:00