I recently discovered that `.profraw` headers are expected to be 8 byte
aligned.
https://github.com/llvm/llvm-project/blob/
643ba926c1f618401c86dc37e659df795db2e1a0/llvm/lib/ProfileData/InstrProfReader.cpp#L503-L506
When function entry coverage mode is used, function counters are single
bytes, so it is likely that the size of the counters section is not 8
byte aligned. We can add padding after the counters section to guarantee
this.
Reviewed By: kyulee, gulfem
Differential Revision: https://reviews.llvm.org/D152479
uint64_t *PaddingBytesAfterNames) {
if (!needsCounterPadding()) {
*PaddingBytesBeforeCounters = 0;
- *PaddingBytesAfterCounters = 0;
+ *PaddingBytesAfterCounters =
+ __llvm_profile_get_num_padding_bytes(CountersSize);
*PaddingBytesAfterNames = __llvm_profile_get_num_padding_bytes(NamesSize);
return;
}
--- /dev/null
+# When linking an instrumented shared libary, the produced raw profile may have
+# multiple headers which must be 8 byte aligned. Check that the counter section
+# sizes are 8 byte aligned when using function entry coverage by attempting to
+# merge the raw profile.
+
+RUN: mkdir -p %t.d
+RUN: %clang_pgogen -mllvm -pgo-function-entry-coverage -o %t.d/libfoo.so -fPIC -shared %S/../Inputs/instrprof-shared-lib.c
+RUN: %clang_pgogen -mllvm -pgo-function-entry-coverage -o %t -L%t.d -rpath %t.d -lfoo %S/../Inputs/instrprof-shared-main.c
+RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
+RUN: llvm-profdata merge -o %t.profdata %t.profraw
+RUN: llvm-profdata show --covered %t.profdata | FileCheck %s
+
+CHECK-DAG: main
+CHECK-DAG: foo