[compiler-rt] 6ebf7cd - [InstrProf][compiler-rt] Fix counter section alignment issue

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 8 17:26:25 PDT 2023


Author: Ellis Hoag
Date: 2023-06-08T17:26:18-07:00
New Revision: 6ebf7cd7ed1b6502b3b18985f06b213a53381097

URL: https://github.com/llvm/llvm-project/commit/6ebf7cd7ed1b6502b3b18985f06b213a53381097
DIFF: https://github.com/llvm/llvm-project/commit/6ebf7cd7ed1b6502b3b18985f06b213a53381097.diff

LOG: [InstrProf][compiler-rt] Fix counter section alignment issue

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

Added: 
    compiler-rt/test/profile/Posix/instrprof-shared-entry-coverage.test

Modified: 
    compiler-rt/lib/profile/InstrProfilingBuffer.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/profile/InstrProfilingBuffer.c b/compiler-rt/lib/profile/InstrProfilingBuffer.c
index 57f8b68919b11..61ac5d9c02850 100644
--- a/compiler-rt/lib/profile/InstrProfilingBuffer.c
+++ b/compiler-rt/lib/profile/InstrProfilingBuffer.c
@@ -107,7 +107,8 @@ void __llvm_profile_get_padding_sizes_for_counters(
     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
index 0000000000000..887bc506c436e
--- /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


        


More information about the llvm-commits mailing list