[PATCH] D110188: [compiler-rt][profile] Add padding after binary IDs

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 22 16:48:41 PDT 2021


leonardchan updated this revision to Diff 374400.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110188/new/

https://reviews.llvm.org/D110188

Files:
  compiler-rt/lib/profile/InstrProfilingPlatformLinux.c


Index: compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
===================================================================
--- compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
+++ compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
@@ -142,7 +142,9 @@
 
 /*
  * Helper function that iterates through notes section and find build ids.
- * If writer is given, write binary ids into profiles.
+ * If writer is given, write binary ids into profiles. This also takes into
+ * account padding which may need to be added after the binary IDs to ensure
+ * 8-byte alignment.
  * If an error happens while writing, return -1.
  */
 static int WriteBinaryIds(ProfDataWriter *Writer, const ElfW(Nhdr) * Note,
@@ -160,7 +162,17 @@
     Note = (const ElfW(Nhdr) *)((const char *)(Note) + NoteOffset);
   }
 
-  return TotalBinaryIdsSize;
+  uint8_t BinaryIdsPadding =
+      __llvm_profile_get_num_padding_bytes(TotalBinaryIdsSize);
+  if (Writer) {
+    ProfDataIOVec BinaryIdIOVec[] = {
+        {NULL, sizeof(uint8_t), BinaryIdsPadding, 1}
+    };
+    if (Writer->Write(Writer, BinaryIdIOVec, sizeof(BinaryIdIOVec) / sizeof(*BinaryIdIOVec)))
+      return -1;
+  }
+
+  return TotalBinaryIdsSize + BinaryIdsPadding;
 }
 
 /*


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


More information about the llvm-commits mailing list