diff options
| author | Igor Kudrin <ikudrin@accesssoftek.com> | 2023-10-29 01:04:24 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-29 01:04:24 +0700 |
| commit | b1554fe080e8b074a30f2a4cb88666bdb7b1ce9e (patch) | |
| tree | ca2886acc6b52b1627c1ccfc6ab6fc8635247c90 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
| parent | 497b2ebb9edcfd5315586b796f47589e9820b4b9 (diff) | |
[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
```
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
0 files changed, 0 insertions, 0 deletions
