[compiler-rt] r204514 - InstrProf: Change magic number to have non-text characters

Duncan P. N. Exon Smith dexonsmith at apple.com
Fri Mar 21 13:42:40 PDT 2014


Author: dexonsmith
Date: Fri Mar 21 15:42:40 2014
New Revision: 204514

URL: http://llvm.org/viewvc/llvm-project?rev=204514&view=rev
Log:
InstrProf: Change magic number to have non-text characters

Include non-text characters in the magic number so that text files can't
match.

<rdar://problem/15950346>

Modified:
    compiler-rt/trunk/lib/profile/InstrProfiling.c

Modified: compiler-rt/trunk/lib/profile/InstrProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.c?rev=204514&r1=204513&r2=204514&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.c Fri Mar 21 15:42:40 2014
@@ -11,16 +11,23 @@
 #include <string.h>
 
 uint64_t __llvm_profile_get_magic(void) {
-  /* Magic number to detect file format and endianness. */
+  /* Magic number to detect file format and endianness.
+   *
+   * Use 255 at one end, since no UTF-8 file can use that character.  Avoid 0,
+   * so that utilities like strings doesn't grab it as a string.  129 is high
+   * enough to be interesting.
+   *
+   * Use "lprofr" in the centre to stand for "LLVM Profile Raw".
+   */
   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;
 }
 
 uint64_t __llvm_profile_get_version(void) {





More information about the llvm-commits mailing list