[InstrProf] Use separate comdat group for data and counters
Summary:
I hadn't realized that instrumentation runs before inlining, so we can't
use the function as the comdat group. Doing so can create relocations
against discarded sections when references to discarded __profc_
variables are inlined into functions outside the function's comdat
group.
In the future, perhaps we should consider standardizing the comdat group
names that ELF and COFF use. It will save object file size, since
__profv_$sym won't appear in the symbol table again.
Reviewers: xur, vsk
Subscribers: eraman, hiraditya, cfe-commits, #sanitizers, llvm-commits
Tags: #clang, #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D58737
llvm-svn: 355044
2019-02-28 07:38:44 +08:00
|
|
|
// Test that the instrumentation puts the right linkage on the profile data for
|
|
|
|
// inline functions.
|
[InstrProf] Implement static profdata registration
Summary:
The motivating use case is eliminating duplicate profile data registered
for the same inline function in two object files. Before this change,
users would observe multiple symbol definition errors with VC link, but
links with LLD would succeed.
Users (Mozilla) have reported that PGO works well with clang-cl and LLD,
but when using LLD without this static registration, we would get into a
"relocation against a discarded section" situation. I'm not sure what
happens in that situation, but I suspect that duplicate, unused profile
information was retained. If so, this change will reduce the size of
such binaries with LLD.
Now, Windows uses static registration and is in line with all the other
platforms.
Reviewers: davidxl, wmi, inglorion, void, calixte
Subscribers: mgorny, krytarowski, eraman, fedor.sergeev, hiraditya, #sanitizers, dmajor, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D57929
llvm-svn: 353547
2019-02-09 03:03:50 +08:00
|
|
|
// RUN: %clang_profgen -g -fcoverage-mapping -c -o %t1.o %s -DOBJECT_1
|
|
|
|
// RUN: %clang_profgen -g -fcoverage-mapping -c -o %t2.o %s
|
|
|
|
// RUN: %clang_profgen -g -fcoverage-mapping %t1.o %t2.o -o %t.exe
|
|
|
|
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.exe
|
|
|
|
// RUN: llvm-profdata show %t.profraw -all-functions | FileCheck %s
|
|
|
|
|
[InstrProf] Use separate comdat group for data and counters
Summary:
I hadn't realized that instrumentation runs before inlining, so we can't
use the function as the comdat group. Doing so can create relocations
against discarded sections when references to discarded __profc_
variables are inlined into functions outside the function's comdat
group.
In the future, perhaps we should consider standardizing the comdat group
names that ELF and COFF use. It will save object file size, since
__profv_$sym won't appear in the symbol table again.
Reviewers: xur, vsk
Subscribers: eraman, hiraditya, cfe-commits, #sanitizers, llvm-commits
Tags: #clang, #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D58737
llvm-svn: 355044
2019-02-28 07:38:44 +08:00
|
|
|
// Again, with optimizations and inlining. This tests that we use comdats
|
|
|
|
// correctly.
|
|
|
|
// RUN: %clang_profgen -O2 -g -fcoverage-mapping -c -o %t1.o %s -DOBJECT_1
|
|
|
|
// RUN: %clang_profgen -O2 -g -fcoverage-mapping -c -o %t2.o %s
|
|
|
|
// RUN: %clang_profgen -g -fcoverage-mapping %t1.o %t2.o -o %t.exe
|
|
|
|
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.exe
|
|
|
|
// RUN: llvm-profdata show %t.profraw -all-functions | FileCheck %s
|
[InstrProf] Implement static profdata registration
Summary:
The motivating use case is eliminating duplicate profile data registered
for the same inline function in two object files. Before this change,
users would observe multiple symbol definition errors with VC link, but
links with LLD would succeed.
Users (Mozilla) have reported that PGO works well with clang-cl and LLD,
but when using LLD without this static registration, we would get into a
"relocation against a discarded section" situation. I'm not sure what
happens in that situation, but I suspect that duplicate, unused profile
information was retained. If so, this change will reduce the size of
such binaries with LLD.
Now, Windows uses static registration and is in line with all the other
platforms.
Reviewers: davidxl, wmi, inglorion, void, calixte
Subscribers: mgorny, krytarowski, eraman, fedor.sergeev, hiraditya, #sanitizers, dmajor, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D57929
llvm-svn: 353547
2019-02-09 03:03:50 +08:00
|
|
|
|
|
|
|
// CHECK: {{.*}}foo{{.*}}:
|
|
|
|
// CHECK-NEXT: Hash:
|
|
|
|
// CHECK-NEXT: Counters: 1
|
|
|
|
// CHECK-NEXT: Function count: 1
|
|
|
|
// CHECK: {{.*}}inline_wrapper{{.*}}:
|
|
|
|
// CHECK-NEXT: Hash:
|
|
|
|
// CHECK-NEXT: Counters: 1
|
|
|
|
// CHECK-NEXT: Function count: 2
|
|
|
|
// CHECK: main:
|
|
|
|
// CHECK-NEXT: Hash:
|
|
|
|
// CHECK-NEXT: Counters: 1
|
|
|
|
// CHECK-NEXT: Function count: 1
|
|
|
|
|
|
|
|
extern "C" int puts(const char *);
|
|
|
|
|
|
|
|
inline void inline_wrapper(const char *msg) {
|
|
|
|
puts(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void foo();
|
|
|
|
|
|
|
|
#ifdef OBJECT_1
|
|
|
|
void foo() {
|
|
|
|
inline_wrapper("foo");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
int main() {
|
|
|
|
inline_wrapper("main");
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#endif
|