[compiler-rt] 6bc9c8d - [compiler-rt][profile] Add padding after binary IDs
Leonard Chan via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 23 10:30:32 PDT 2021
Author: Leonard Chan
Date: 2021-09-23T10:29:24-07:00
New Revision: 6bc9c8dfe32cc4662f2ed9041af527f69dfff13b
URL: https://github.com/llvm/llvm-project/commit/6bc9c8dfe32cc4662f2ed9041af527f69dfff13b
DIFF: https://github.com/llvm/llvm-project/commit/6bc9c8dfe32cc4662f2ed9041af527f69dfff13b.diff
LOG: [compiler-rt][profile] Add padding after binary IDs
Some tests with binary IDs would fail with error: no profile can be merged.
This is because raw profiles could have unaligned headers when emitting binary
IDs. This means padding should be emitted after binary IDs are emitted to
ensure everything else is aligned. This patch accounts for that padding in
__llvm_write_binary_ids.
Differential Revision: https://reviews.llvm.org/D110188
Added:
Modified:
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
Removed:
################################################################################
diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
index 5d47083b8bfe7..03cbd3312df4b 100644
--- a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
@@ -142,7 +142,9 @@ static int WriteBinaryIdForNote(ProfDataWriter *Writer,
/*
* 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 @@ static int WriteBinaryIds(ProfDataWriter *Writer, const ElfW(Nhdr) * Note,
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;
}
/*
More information about the llvm-commits
mailing list