[PATCH] D110277: [compiler-rt][profile] Make corrupted-profile.c more robuset

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 23 16:09:32 PDT 2021


leonardchan updated this revision to Diff 374687.
leonardchan retitled this revision from "[compiler-rt][profile] Account for binary IDs size in test" to "[compiler-rt][profile] Make corrupted-profile.c more robuset".
leonardchan edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110277

Files:
  compiler-rt/test/profile/Linux/corrupted-profile.c


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
@@ -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,15 +57,11 @@
     if (Buf == MAP_FAILED)
       bail("mmap");
 
-    // The binary IDs size is the 3rd uint64_t in the header. This size should
-    // already account for padding.
-    uint64_t BinaryIdsSize;
-    memcpy(&BinaryIdsSize, &Buf[2 * 8], sizeof(BinaryIdsSize));
-
-    // 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 + BinaryIdsSize + 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");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110277.374687.patch
Type: text/x-patch
Size: 1732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210923/35c3c96b/attachment.bin>


More information about the llvm-commits mailing list