diff --git a/compiler-rt/lib/profile/InstrProfilingBuffer.c b/compiler-rt/lib/profile/InstrProfilingBuffer.c --- a/compiler-rt/lib/profile/InstrProfilingBuffer.c +++ b/compiler-rt/lib/profile/InstrProfilingBuffer.c @@ -107,7 +107,8 @@ 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; } diff --git a/compiler-rt/test/profile/Posix/instrprof-shared-entry-coverage.test b/compiler-rt/test/profile/Posix/instrprof-shared-entry-coverage.test new file mode 100644 --- /dev/null +++ b/compiler-rt/test/profile/Posix/instrprof-shared-entry-coverage.test @@ -0,0 +1,14 @@ +# 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