[compiler-rt] c371ee9 - [Profile][Windows] Fix flakyness when checking existence of binary id (#84196)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 6 09:08:53 PST 2024


Author: Zequan Wu
Date: 2024-03-06T12:08:50-05:00
New Revision: c371ee9da9c4fa4b682baf47ce5c2a6b6f4c74bc

URL: https://github.com/llvm/llvm-project/commit/c371ee9da9c4fa4b682baf47ce5c2a6b6f4c74bc
DIFF: https://github.com/llvm/llvm-project/commit/c371ee9da9c4fa4b682baf47ce5c2a6b6f4c74bc.diff

LOG: [Profile][Windows] Fix flakyness when checking existence of binary id (#84196)

There is a small chance that binary id starting with 0 (1/256). It is
not sufficient to just check the first byte.

Added: 
    

Modified: 
    compiler-rt/lib/profile/InstrProfilingPlatformWindows.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c b/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c
index b9642ca7f6810f..9421f67b768e0d 100644
--- a/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c
@@ -96,9 +96,10 @@ ValueProfNode *EndVNode = &VNodesEnd;
 /* lld-link provides __buildid symbol which ponits to the 16 bytes build id when
  * using /build-id flag. https://lld.llvm.org/windows_support.html#lld-flags */
 #define BUILD_ID_LEN 16
-COMPILER_RT_WEAK uint8_t __buildid[BUILD_ID_LEN];
+COMPILER_RT_WEAK uint8_t __buildid[BUILD_ID_LEN] = {0};
 COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
-  if (*__buildid) {
+  static const uint8_t zeros[BUILD_ID_LEN] = {0};
+  if (memcmp(__buildid, zeros, BUILD_ID_LEN) != 0) {
     if (Writer &&
         lprofWriteOneBinaryId(Writer, BUILD_ID_LEN, __buildid, 0) == -1)
       return -1;


        


More information about the llvm-commits mailing list