diff --git a/compiler-rt/lib/memprof/memprof_allocator.cpp b/compiler-rt/lib/memprof/memprof_allocator.cpp --- a/compiler-rt/lib/memprof/memprof_allocator.cpp +++ b/compiler-rt/lib/memprof/memprof_allocator.cpp @@ -75,7 +75,7 @@ // _memprof_preinit is called via the preinit_array, which subsequently calls // malloc. Since this is before _dl_init calls VDSO_SETUP, sched_getcpu // will seg fault as the address of __vdso_getcpu will be null. - if (!memprof_init_done) + if (!memprof_inited) return -1; return sched_getcpu(); } @@ -445,8 +445,7 @@ u64 user_requested_size = atomic_exchange(&m->user_requested_size, 0, memory_order_acquire); - if (memprof_inited && memprof_init_done && - atomic_load_relaxed(&constructed) && + if (memprof_inited && atomic_load_relaxed(&constructed) && !atomic_load_relaxed(&destructing)) { u64 c = GetShadowCount(p, user_requested_size); long curtime = GetTimestamp(); diff --git a/compiler-rt/lib/memprof/memprof_internal.h b/compiler-rt/lib/memprof/memprof_internal.h --- a/compiler-rt/lib/memprof/memprof_internal.h +++ b/compiler-rt/lib/memprof/memprof_internal.h @@ -76,7 +76,6 @@ extern int memprof_inited; extern int memprof_timestamp_inited; -extern int memprof_init_done; // Used to avoid infinite recursion in __memprof_init(). extern bool memprof_init_is_running; extern void (*death_callback)(void); diff --git a/compiler-rt/lib/memprof/memprof_rtl.cpp b/compiler-rt/lib/memprof/memprof_rtl.cpp --- a/compiler-rt/lib/memprof/memprof_rtl.cpp +++ b/compiler-rt/lib/memprof/memprof_rtl.cpp @@ -65,7 +65,6 @@ // -------------------------- Globals --------------------- {{{1 int memprof_inited; -int memprof_init_done; bool memprof_init_is_running; int memprof_timestamp_inited; long memprof_init_timestamp_s; @@ -195,11 +194,6 @@ InitializeAllocator(); - // On Linux MemprofThread::ThreadStart() calls malloc() that's why - // memprof_inited should be set to 1 prior to initializing the threads. - memprof_inited = 1; - memprof_init_is_running = false; - if (flags()->atexit) Atexit(memprof_atexit); @@ -218,7 +212,8 @@ VReport(1, "MemProfiler Init done\n"); - memprof_init_done = 1; + memprof_init_is_running = false; + memprof_inited = 1; } void MemprofInitTime() {