InstrProf: Change magic number to have non-text characters
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 21 Mar 2014 20:42:37 +0000 (20:42 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 21 Mar 2014 20:42:37 +0000 (20:42 +0000)
Include non-text characters in the magic number so that text files can't
match.

<rdar://problem/15950346>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204513 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ProfileData/InstrProfReader.cpp
test/tools/llvm-profdata/Inputs/binary.profdata
test/tools/llvm-profdata/raw-magic-but-no-header.test

index a95d9bc3b08a709d23435101b74ad4c363f3f1b1..f923ad2ddd9cc95bb77db4b0548ee332196743c3 100644 (file)
@@ -90,14 +90,14 @@ RawInstrProfReader::RawInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer)
 
 static uint64_t getRawMagic() {
   return
-    uint64_t('l') << 56 |
-    uint64_t('p') << 48 |
-    uint64_t('r') << 40 |
-    uint64_t('o') << 32 |
-    uint64_t('f') << 24 |
-    uint64_t('r') << 16 |
-    uint64_t('a') <<  8 |
-    uint64_t('w');
+    uint64_t(255) << 56 |
+    uint64_t('l') << 48 |
+    uint64_t('p') << 40 |
+    uint64_t('r') << 32 |
+    uint64_t('o') << 24 |
+    uint64_t('f') << 16 |
+    uint64_t('r') <<  8 |
+    uint64_t(129);
 }
 
 bool RawInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) {
index 156c483d15f1979512b7599f89bfdba1e2d08bd8..e8cef21de5f258c5e08a1089280f282be0a77455 100644 (file)
Binary files a/test/tools/llvm-profdata/Inputs/binary.profdata and b/test/tools/llvm-profdata/Inputs/binary.profdata differ
index e899ece2755e293f523bd500198f40006263b998..6db723c3e25339d656e6d0a11b60618f020e01c5 100644 (file)
@@ -1,6 +1,6 @@
-RUN: printf "warforpl" > %t
+RUN: printf '\201rforpl\377' > %t
 RUN: not llvm-profdata show %t 2>&1 | FileCheck %s
-RUN: printf "lprofraw" > %t
+RUN: printf '\377lprofr\201' > %t
 RUN: not llvm-profdata show %t 2>&1 | FileCheck %s
 
 CHECK: error: {{.+}}: Invalid header