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

Exit with quick_exit when using debug UCRT #109006

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

Conversation

MichalStrehovsky
Copy link
Member

Resolves #108640.

Cc @dotnet/ilc-contrib @janvorli

@jkotas
Copy link
Member

jkotas commented Oct 18, 2024

I expect that this will break tracing tests. Tracing depends on C runtime shutdown notification to close the session:

atexit(&OnProcessExit);

Also, the same fundamental problem exists in regular coreclr as well.

@janvorli
Copy link
Member

It seems that the only way to fix the problem and keep the cleanup at exit untouched would be to link to ucrt dynamically. The cleanup then occurs in DllMain of the library on DLL_PROCESS_DETACH.

@janvorli
Copy link
Member

I meant the low level CRT cleanup, not the atexit stuff.

@filipnavara
Copy link
Member

filipnavara commented Oct 20, 2024

Tracing depends on C runtime shutdown notification to close the session

Playing the devil's advocate, you can always make that a at_quick_exit.

Ah, damn, that's C++ and not in ucrt, so that would not help.

@jkotas
Copy link
Member

jkotas commented Oct 20, 2024

Ah, damn, that's C++ and not in ucrt, so that would not help.

There is no C++ in the mix. Neither atexit or at_quick_exit are directly exposed by the ucrt.dll. They are statically linked stubs that use CRT global state for .exes and module-local state for .dlls. For example:

  • Exiting via quick_exit from main still runs atexit handlers registered in other .dlls in the process, but it does not run at_quick_exit handlers registered in other .dlls in the process
  • Exiting via quick_exit from .dll with statically linked CRT (the "global" state is module-local with static linking) runs at_quick_exit handlers registered in the given .dll, but it does not run atexit nor at_quick_exit handlers registered by the .exe

@jkotas
Copy link
Member

jkotas commented Oct 20, 2024

/azp run runtime-nativeaot-outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkotas
Copy link
Member

jkotas commented Oct 20, 2024

/azp run runtime-nativeaot-outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkotas
Copy link
Member

jkotas commented Oct 21, 2024

It looks like we do not have any diagnostics tests that would be sensitive for improperly closed eventpipe sessions.

I think we should also update #109006 (comment) to register the callbacks using at_quick_exit .

Looks good to me otherwise.

@teo-tsirpanis
Copy link
Contributor

link to ucrt dynamically

Why don't we do it currently?

@jkotas
Copy link
Member

jkotas commented Oct 24, 2024

Why don't we do it currently?

We do not dynamically link to debug CRT to save us from troubles with deploying it to CI machines.

We do dynamically link to release CRT (ie the shipping bits link to release CRT).

@teo-tsirpanis
Copy link
Contributor

Thanks, I remember trying to link some static libraries with dynamic CRT linkage and getting errors related to static/dynamic CRT mismatch. But that was years ago and I will try it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test failure: JIT/jit64/mcc/interop/mcc_i03/mcc_i03.cmd
5 participants