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

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 6 08:56:26 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-pgo

Author: Zequan Wu (ZequanWu)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/84196.diff


1 Files Affected:

- (modified) compiler-rt/lib/profile/InstrProfilingPlatformWindows.c (+3-2) 


``````````diff
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;

``````````

</details>


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


More information about the llvm-commits mailing list