Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static initialization fiasco problem with the logger and code calling into it from other TUs #358

Merged
merged 6 commits into from
Feb 22, 2023

Conversation

asklar
Copy link
Member

@asklar asklar commented Feb 20, 2023

There is currently a dependency between the order of dynamic initializers for the logger and things that call into it, like CpuREP (see #356 for a related issue). This can result in crashes because the order of dynamic initializers across translation units is not deterministic in C++.

The fix is to access the logger via a function call that allows us to defer the logger initialization until it is needed (in a thread-safe manner). Using "magic statics" to do that.

An app will now be able to customize the log level (to suppress logging from dynamic initializers) by exporting a function with a certain name, which we will look up during GetLogger():

App code:

extern "C" __declspec(dllexport) LogLevel SPTAG_GetLoggerLevel() 
{ 
    return LogLevel::Empty;
}

Fixes #356

@asklar asklar changed the title Addresses static initialization fiasco problem with the logger and code calling into it from other translation units Fix static initialization fiasco problem with the logger and code calling into it from other TUs Feb 20, 2023
@asklar asklar force-pushed the user/asklar/deferredLogger branch from ad9e9d9 to b797613 Compare February 21, 2023 20:29
@PhilipBAdams PhilipBAdams merged commit a5bd48e into microsoft:main Feb 22, 2023
@asklar asklar deleted the user/asklar/deferredLogger branch August 29, 2023 15:06
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.

Logger is not configurable until after it's been used
2 participants