[compiler-rt] c579c65 - [compiler-rt][profile] Make corrupted-profile.c more robust
Leonard Chan via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 23 17:17:58 PDT 2021
Author: Leonard Chan
Date: 2021-09-23T17:16:47-07:00
New Revision: c579c658cd42034449d4fa19f28b43f2082c0991
URL: https://github.com/llvm/llvm-project/commit/c579c658cd42034449d4fa19f28b43f2082c0991
DIFF: https://github.com/llvm/llvm-project/commit/c579c658cd42034449d4fa19f28b43f2082c0991.diff
LOG: [compiler-rt][profile] Make corrupted-profile.c more robust
This test specifically checks that profiles are not mergeable if there's a
change in the CounterPtr in the profile header. The test manually changes
CounterPtr by explicitly calling memset on some offset into the profile file.
This test would fail if binary IDs were emitted because the offset calculation
does not take into account the binary ID sizes.
This patch updates the test to use types provided in profile/InstrProfData.inc
to make it more resistant to profile layout changes.
Differential Revision: https://reviews.llvm.org/D110277
Added:
Modified:
compiler-rt/test/profile/Linux/corrupted-profile.c
Removed:
################################################################################
diff --git a/compiler-rt/test/profile/Linux/corrupted-profile.c b/compiler-rt/test/profile/Linux/corrupted-profile.c
index cbc37aca2ee28..bc2ccdb32706f 100644
--- a/compiler-rt/test/profile/Linux/corrupted-profile.c
+++ b/compiler-rt/test/profile/Linux/corrupted-profile.c
@@ -19,6 +19,21 @@
#include <fcntl.h>
#include <unistd.h>
+enum ValueKind {
+#define VALUE_PROF_KIND(Enumerator, Value, Descr) Enumerator = Value,
+#include "profile/InstrProfData.inc"
+};
+
+typedef struct __llvm_profile_header {
+#define INSTR_PROF_RAW_HEADER(Type, Name, Initializer) Type Name;
+#include "profile/InstrProfData.inc"
+} __llvm_profile_header;
+
+typedef void *IntPtrT;
+typedef struct __llvm_profile_data {
+#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name;
+#include "profile/InstrProfData.inc"
+} __llvm_profile_data;
void __llvm_profile_set_file_object(FILE* File, int EnableMerge);
@@ -42,10 +57,11 @@ int main(int argc, char** argv) {
if (Buf == MAP_FAILED)
bail("mmap");
- // We're trying to make the first CounterPtr invalid.
- // 11 64-bit words as header.
- // CounterPtr is the third 64-bit word field.
- memset(&Buf[11 * 8 + 2 * 8], 0xAB, 8);
+ __llvm_profile_header *Header = (__llvm_profile_header *)Buf;
+ __llvm_profile_data *SrcDataStart =
+ (__llvm_profile_data *)(Buf + sizeof(__llvm_profile_header) +
+ Header->BinaryIdsSize);
+ memset(&SrcDataStart->CounterPtr, 0xAB, sizeof(SrcDataStart->CounterPtr));
if (munmap(Buf, FileSize))
bail("munmap");
More information about the llvm-commits
mailing list