Skip to content

Start to use C++ 17 STL in superpmi #116422

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

huoyaoyuan
Copy link
Member

@huoyaoyuan huoyaoyuan commented Jun 9, 2025

As discussed in #112419, there should not be blocker for adopting C++ 17 in development environment. SuperPMI is I/O intensive and can be simplified significantly with std::filesystem.

The end goal is to eliminate PAL simulation of Windows I/O functions. This PR acts as a first step to adopt STL in the dll shim entries.

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 9, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 9, 2025
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Comment on lines +19 to +24
std::filesystem::path g_realJitPath{""}; // Destructable objects will be cleaned up and won't leak
std::filesystem::path g_logPath{""};
std::filesystem::path g_HomeDirectory{""};
std::filesystem::path g_DefaultRealJitPath{""};

void SetDefaultPaths()
std::unique_ptr<MethodCallSummarizer> g_globalContext = nullptr;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://learn.microsoft.com/windows/win32/dlls/dllmain and other documentations I can find, constructors/destructors for global objects with be respected by dll/so unloading. I haven't test it though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global destructors are a bug farm. The problem is that they run while the other threads are stopped at random spot (on Windows) and while other threads are running (on non-Windows). Every time we happen to introduce one by mistake, we end up deleting it later to fix intermittent hangs and crashes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it compare to DllMain (DETACH)? The counter shim writes statistics on unload, which is simulated by PAL. Is there better approach?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DllMain (DETACH)

It has the same problems

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does is mean that things won't be worse if we replace existing DllMain with global objects? Currently the DllMain of JIT is doing shutdown.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the DllMain of JIT is doing shutdown.

If I am reading the code correctly, DllMain of JIT is only called on Windows. It is never called on non-Windows.

Does is mean that things won't be worse if we replace existing DllMain with global objects?

I would expect it to be fine for superpmi. I am not sure about regular JIT.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am reading the code correctly, DllMain of JIT is only called on Windows. It is never called on non-Windows.

JIT is loaded by CLRLoadLibrary in LoadAndInitializeJIT, which is implemented in PAL with LoadLibraryExW and does DllMain simulation. It's never unloaded though, but if it is, the DllMain will also be called by PAL.

@huoyaoyuan
Copy link
Member Author

It seems that our linux glibc x64/x86/arm64 build environment aren't ready for C++ 17 STL. Is it because we are targeting the runtime version of lowest supported OS?

@janvorli
Copy link
Member

janvorli commented Jun 9, 2025

We use Ubuntu 22.04 18.04 as cross build target for arm64. That one doesn't have support for c++17. So unless we decided to raise the minimum supported OSes in .NET, we are blocked.

@huoyaoyuan
Copy link
Member Author

Is it OK to use some polyfill for superPMI only? We don't need strict compatibility or reliability here.

If this is too flaky, I can remove C++ 17 usage and convert to C++ 11 STL instad.

@jkotas
Copy link
Member

jkotas commented Jun 10, 2025

I can remove C++ 17 usage and convert to C++ 11 STL instad.

What would you have to give up on by converting to C++ 11?

@huoyaoyuan
Copy link
Member Author

What would you have to give up on by converting to C++ 11?

Everything in std::filesystem, currently just path that automatically converts to platform-native encoding. In superpmi it should be fine to use ANSI variants on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants