[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 11:42:53 PDT 2021
leonardchan updated this revision to Diff 374307.
leonardchan retitled this revision from "[WIP][compiler-rt][profile] Fixes for failing profile tests" to "[compiler-rt][profile] Add padding after binary IDs".
leonardchan edited the summary of this revision.
leonardchan added a reviewer: davidxl.
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
@@ -163,6 +163,29 @@
return TotalBinaryIdsSize;
}
+/**
+ * Helper function that writes binary ids into profiles, but also takes into
+ * account padding after the ids to ensure the next section is 8-byte aligned.
+ * If an error happens while writing, return -1.
+ */
+static int WriteBinaryIdsWithPadding(ProfDataWriter *Writer, const ElfW(Nhdr) * Note,
+ const ElfW(Nhdr) * NotesEnd) {
+ int BinaryIdsSize = WriteBinaryIds(Writer, Note, NotesEnd);
+ if (BinaryIdsSize == -1)
+ return -1;
+
+ uint8_t BinaryIdsPadding = __llvm_profile_get_num_padding_bytes(BinaryIdsSize);
+ if (Writer) {
+ ProfDataIOVec BinaryIdIOVec[] = {
+ {NULL, sizeof(uint8_t), BinaryIdsPadding, 1}
+ };
+ if (Writer->Write(Writer, BinaryIdIOVec, sizeof(BinaryIdIOVec) / sizeof(*BinaryIdIOVec)))
+ return -1;
+ }
+
+ return BinaryIdsSize + BinaryIdsPadding;
+}
+
/*
* Write binary ids into profiles if writer is given.
* Return the total size of binary ids.
@@ -185,7 +208,7 @@
(const ElfW(Nhdr) *)((uintptr_t)ElfHeader + ProgramHeader[I].p_offset);
const ElfW(Nhdr) *NotesEnd =
(const ElfW(Nhdr) *)((const char *)(Note) + ProgramHeader[I].p_filesz);
- return WriteBinaryIds(Writer, Note, NotesEnd);
+ return WriteBinaryIdsWithPadding(Writer, Note, NotesEnd);
}
return 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110188.374307.patch
Type: text/x-patch
Size: 1605 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210922/6e55a2d6/attachment.bin>
More information about the llvm-commits
mailing list