RFR: 8346388: Cannot use DllMain in libawt for static builds

Magnus Ihse Bursie ihse at openjdk.org
Tue Jan 14 10:49:43 UTC 2025


On Wed, 18 Dec 2024 19:53:10 GMT, Magnus Ihse Bursie <ihse at openjdk.org> wrote:

> > I do read your comment about not knowing when the static destructors are called vs the DllMain on shutdown, but surely this _is_ well defined ?
> 
> That is possible. It could be just that I have failed to locate the documentation about this.

Here is the documentation: (from https://learn.microsoft.com/en-us/cpp/build/run-time-library-behavior?view=msvc-170; thanks @dholmes-ora for the link)

"The VCRuntime library provides an entry-point function called _DllMainCRTStartup to handle default initialization and termination operations. On process attach, the _DllMainCRTStartup function sets up buffer security checks, initializes the CRT and other libraries, initializes run-time type information, initializes and calls constructors for static and non-local data, initializes thread-local storage, increments an internal static counter for each attach, and then calls a user- or library-supplied DllMain. On process detach, the function goes through these steps in reverse. It calls DllMain, decrements the internal counter, calls destructors, calls CRT termination functions and registered atexit functions, and notifies any other libraries of termination."

The TL;DR is that `DllMain` with `DLL_PROCESS_DETACH` happens before static destructors.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/22790#issuecomment-2589586521


More information about the client-libs-dev mailing list