Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Linker] Do not keep a private member of a non-prevailing comdat group (
#69143) `IRMover` links in referenced private global values unconditionally, see `IRLinker::shouldLink()`. If they are part of a non-prevailing comdat, this leads to duplication of the values. Full and Thin LTO avoid duplication by changing the linkage of members of non-prevailing comdat groups to `available_externally`, which was implemented in https://reviews.llvm.org/D34803 and https://reviews.llvm.org/D135427. This patch does the same for `Linker`, but limits the effect only to private members without aliases to minimize interference. Motivation example: ``` > cat foo.h inline int foo(int a) { return a + 1; } > cat bar.cpp #include "foo.h" int bar(int a) { return foo(a + 1); } > cat main.cpp #include "foo.h" int bar(int a); int main(int argc, const char* argv[]) { return bar(argc) + foo(argc); } > clang++ -c -flto -fprofile-instr-generate main.cpp -o main.o > clang++ -c -flto -fprofile-instr-generate bar.cpp -o bar.o > clang++ -fuse-ld=lld -fprofile-instr-generate main.o bar.o -o test1 > ./test1 > llvm-profdata merge --text default.profraw -o - _Z3fooi # Counter Values: 2 > llvm-link main.o bar.o -o combined.o > clang++ -fuse-ld=lld -fprofile-instr-generate combined.o -o test2 > ./test2 > llvm-profdata merge --text default.profraw -o - _Z3fooi # Counter Values: 4 ```
- Loading branch information