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

Zequan Wu via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 6 08:55:54 PST 2024


https://github.com/ZequanWu created https://github.com/llvm/llvm-project/pull/84196

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

>From 7c15a22a9c2890424f03976a7a8997f22d8111ee Mon Sep 17 00:00:00 2001
From: Zequan Wu <zequanwu at google.com>
Date: Wed, 6 Mar 2024 11:53:21 -0500
Subject: [PATCH] [Profile][Windows] Fix flakyness when checking existence of
 binary id

---
 compiler-rt/lib/profile/InstrProfilingPlatformWindows.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c b/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c
index b9642ca7f6810f..f2bb02efa50078 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) {
+  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