From d85c258fd1e7459cc8085b5f364e356f50b490a4 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Wed, 19 May 2021 10:14:00 -0700 Subject: [PATCH] [profile] Don't publish VMO if there are no counters If there are no counters, there's no need to publish the VMO. Differential Revision: https://reviews.llvm.org/D102786 --- compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c b/compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c index d8b7fa21d2573..0e62861d1b923 100644 --- a/compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c +++ b/compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c @@ -126,13 +126,20 @@ void __llvm_profile_initialize(void) { const __llvm_profile_data *DataBegin = __llvm_profile_begin_data(); const __llvm_profile_data *DataEnd = __llvm_profile_end_data(); + const uint64_t *CountersBegin = __llvm_profile_begin_counters(); + const uint64_t *CountersEnd = __llvm_profile_end_counters(); const uint64_t DataSize = __llvm_profile_get_data_size(DataBegin, DataEnd); const uint64_t CountersOffset = sizeof(__llvm_profile_header) + (DataSize * sizeof(__llvm_profile_data)); + uint64_t CountersSize = CountersEnd - CountersBegin; + + /* Don't publish a VMO if there are no counters. */ + if (!CounterSize) + return; zx_status_t Status; - /* Create VMO to hold the profile data. */ + /* Create a VMO to hold the profile data. */ zx_handle_t Vmo = ZX_HANDLE_INVALID; Status = _zx_vmo_create(0, ZX_VMO_RESIZABLE, &Vmo); if (Status != ZX_OK) {