From b9ef0bdea80a1a7c227a68d7406a378b0e4ead4b Mon Sep 17 00:00:00 2001 From: Sam Schweigel Date: Wed, 2 Jul 2025 11:02:35 -0700 Subject: [PATCH] Fix data race in jl_new_module__ identifier by tsan --- src/module.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/module.c b/src/module.c index b0e3efb92fd5d..69ed05eacf05f 100644 --- a/src/module.c +++ b/src/module.c @@ -482,9 +482,10 @@ static jl_module_t *jl_new_module__(jl_sym_t *name, jl_module_t *parent) m->parent = parent ? parent : m; m->istopmod = 0; m->uuid = uuid_zero; - static unsigned int mcounter; // simple counter backup, in case hrtime is not incrementing + static _Atomic(unsigned int) mcounter; // simple counter backup, in case hrtime is not incrementing + unsigned int count = jl_atomic_fetch_add_relaxed(&mcounter, 1); // TODO: this is used for ir decompression and is liable to hash collisions so use more of the bits - m->build_id.lo = bitmix(jl_hrtime() + (++mcounter), jl_rand()); + m->build_id.lo = bitmix(jl_hrtime() + count, jl_rand()); if (!m->build_id.lo) m->build_id.lo++; // build id 0 is invalid m->build_id.hi = ~(uint64_t)0;