Skip to content

Encapsulate global random seed in a function#28979

Merged
kunal-vaishnavi merged 1 commit into
microsoft:mainfrom
raagrawal:patch-1
Jun 16, 2026
Merged

Encapsulate global random seed in a function#28979
kunal-vaishnavi merged 1 commit into
microsoft:mainfrom
raagrawal:patch-1

Conversation

@raagrawal

Copy link
Copy Markdown
Contributor

Refactor global random seed management to use a function for better encapsulation.

Description

Convert the file-scope static to a function-local static in GetGlobalRandomSeed(), deferring initialization to first use. No API or behavioral change; all callers use GetRandomSeed()/SetRandomSeed() which remain identical.

Motivation and Context

The global g_random_seed was initialized via std::chrono::system_clock::now() at static construction time. When the ORT DLL is loaded dynamically (e.g., via LoadLibraryExW in the fuzzer), this triggers an ASan initialization-order-fiasco: ORT's _GLOBAL__sub_I_random_seed.cc calls std::chrono::system_clock::now() before libc++'s chrono.cpp globals (GetSystemTimeAsFileTimeFunc) are initialized.

Refactor global random seed management to use a function for better encapsulation.
@kunal-vaishnavi kunal-vaishnavi enabled auto-merge (squash) June 16, 2026 17:50
@kunal-vaishnavi kunal-vaishnavi merged commit 6f691bf into microsoft:main Jun 16, 2026
85 of 86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants