[PATCH] D110188: [WIP][compiler-rt][profile] Fixes for failing profile tests

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 21 11:08:24 PDT 2021


leonardchan created this revision.
Herald added subscribers: hiraditya, dberris.
leonardchan requested review of this revision.
Herald added projects: Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110188

Files:
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/lib/profile/InstrProfilingWriter.c
  compiler-rt/test/profile/Linux/corrupted-profile.c
  llvm/lib/ProfileData/InstrProfReader.cpp


Index: llvm/lib/ProfileData/InstrProfReader.cpp
===================================================================
--- llvm/lib/ProfileData/InstrProfReader.cpp
+++ llvm/lib/ProfileData/InstrProfReader.cpp
@@ -380,7 +380,9 @@
   auto PaddingSize = getNumPaddingBytes(NamesSize);
 
   // Profile data starts after profile header and binary ids if exist.
-  ptrdiff_t DataOffset = sizeof(RawInstrProf::Header) + BinaryIdsSize;
+  ptrdiff_t DataOffset = sizeof(RawInstrProf::Header) + BinaryIdsSize +
+                         getNumPaddingBytes(BinaryIdsSize);
+
   ptrdiff_t CountersOffset =
       DataOffset + DataSizeInBytes + PaddingBytesBeforeCounters;
   ptrdiff_t NamesOffset = CountersOffset + (sizeof(uint64_t) * CountersSize) +
Index: compiler-rt/test/profile/Linux/corrupted-profile.c
===================================================================
--- compiler-rt/test/profile/Linux/corrupted-profile.c
+++ compiler-rt/test/profile/Linux/corrupted-profile.c
@@ -1,6 +1,6 @@
 // RUN: rm -f %t.profraw
 // RUN: touch %t.profraw
-// RUN: %clang_profgen -o %t %s
+// RUN: %clang_profgen -Wl,--build-id=none -o %t %s
 // RUN: %t %t.profraw
 // RUN: %t %t.profraw modifyfile
 // RUN: cp %t.profraw %t.profraw.old
Index: compiler-rt/lib/profile/InstrProfilingWriter.c
===================================================================
--- compiler-rt/lib/profile/InstrProfilingWriter.c
+++ compiler-rt/lib/profile/InstrProfilingWriter.c
@@ -295,16 +295,18 @@
     return -1;
 
   /* Write the binary id lengths and data. */
-  if (__llvm_write_binary_ids(Writer) == -1)
+  int BinaryIdsSize;
+  if ((BinaryIdsSize = __llvm_write_binary_ids(Writer)) == -1)
     return -1;
 
   /* Write the profile data. */
   ProfDataIOVec IOVecData[] = {
+      {NULL, sizeof(uint8_t), __llvm_profile_get_num_padding_bytes(BinaryIdsSize), 1},
       {DataBegin, sizeof(__llvm_profile_data), DataSize, 0},
       {NULL, sizeof(uint8_t), PaddingBytesBeforeCounters, 1},
       {CountersBegin, sizeof(uint64_t), CountersSize, 0},
       {NULL, sizeof(uint8_t), PaddingBytesAfterCounters, 1},
-      {SkipNameDataWrite ? NULL : NamesBegin, sizeof(uint8_t), NamesSize, 0},
+      {/*SkipNameDataWrite ? NULL :*/ NamesBegin, sizeof(uint8_t), NamesSize, 0},
       {NULL, sizeof(uint8_t), PaddingBytesAfterNames, 1}};
   if (Writer->Write(Writer, IOVecData, sizeof(IOVecData) / sizeof(*IOVecData)))
     return -1;
Index: compiler-rt/lib/profile/InstrProfilingMerge.c
===================================================================
--- compiler-rt/lib/profile/InstrProfilingMerge.c
+++ compiler-rt/lib/profile/InstrProfilingMerge.c
@@ -44,9 +44,10 @@
   /* Check profile header only for now  */
   __llvm_profile_header *Header = (__llvm_profile_header *)ProfileData;
   __llvm_profile_data *SrcDataStart, *SrcDataEnd, *SrcData, *DstData;
+  int BinaryIdsPadding = __llvm_profile_get_num_padding_bytes(Header->BinaryIdsSize);
   SrcDataStart =
       (__llvm_profile_data *)(ProfileData + sizeof(__llvm_profile_header) +
-                              Header->BinaryIdsSize);
+                              Header->BinaryIdsSize + BinaryIdsPadding);
   SrcDataEnd = SrcDataStart + Header->DataSize;
 
   if (ProfileSize < sizeof(__llvm_profile_header))
@@ -101,9 +102,10 @@
   const char *SrcValueProfDataStart, *SrcValueProfData;
   uintptr_t CountersDelta = Header->CountersDelta;
 
+  int BinaryIdsPadding = __llvm_profile_get_num_padding_bytes(Header->BinaryIdsSize);
   SrcDataStart =
       (__llvm_profile_data *)(ProfileData + sizeof(__llvm_profile_header) +
-                              Header->BinaryIdsSize);
+                              Header->BinaryIdsSize + BinaryIdsPadding);
   SrcDataEnd = SrcDataStart + Header->DataSize;
   SrcCountersStart = (uint64_t *)SrcDataEnd;
   SrcNameStart = (const char *)(SrcCountersStart + Header->CountersSize);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110188.373991.patch
Type: text/x-patch
Size: 3857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210921/b30a24b1/attachment.bin>


More information about the llvm-commits mailing list