[all-commits] [llvm/llvm-project] b1554f: [Linker] Do not keep a private member of a non-pre...
Igor Kudrin via All-commits
all-commits at lists.llvm.org
Sat Oct 28 11:04:38 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b1554fe080e8b074a30f2a4cb88666bdb7b1ce9e
https://github.com/llvm/llvm-project/commit/b1554fe080e8b074a30f2a4cb88666bdb7b1ce9e
Author: Igor Kudrin <ikudrin at accesssoftek.com>
Date: 2023-10-29 (Sun, 29 Oct 2023)
Changed paths:
M llvm/lib/Linker/LinkModules.cpp
M llvm/test/Linker/comdat-nonprevailing-decl.ll
Log Message:
-----------
[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
```
More information about the All-commits
mailing list