From 7c15a22a9c2890424f03976a7a8997f22d8111ee Mon Sep 17 00:00:00 2001 From: Zequan Wu Date: Wed, 6 Mar 2024 11:53:21 -0500 Subject: [PATCH 1/2] [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 b9642ca7f6810..f2bb02efa5007 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; From 62bf8db0f80f8a094d1f3edd49ca0d3d14e864f4 Mon Sep 17 00:00:00 2001 From: Zequan Wu Date: Wed, 6 Mar 2024 12:05:10 -0500 Subject: [PATCH 2/2] use static const. --- compiler-rt/lib/profile/InstrProfilingPlatformWindows.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c b/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c index f2bb02efa5007..9421f67b768e0 100644 --- a/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c +++ b/compiler-rt/lib/profile/InstrProfilingPlatformWindows.c @@ -98,7 +98,7 @@ ValueProfNode *EndVNode = &VNodesEnd; #define BUILD_ID_LEN 16 COMPILER_RT_WEAK uint8_t __buildid[BUILD_ID_LEN] = {0}; COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) { - uint8_t zeros[BUILD_ID_LEN] = {0}; + 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)