Integrated: 8346383: Cannot use DllMain in libdt_socket for static builds

Magnus Ihse Bursie ihse at openjdk.org
Mon Jan 13 21:25:44 UTC 2025


On Tue, 17 Dec 2024 11:10:01 GMT, Magnus Ihse Bursie <ihse at openjdk.org> wrote:

> To be able to properly support static builds on Windows in [JDK-8346377](https://bugs.openjdk.org/browse/JDK-8346377), we cannot use `DllMain`, for two reasons:
> 
> 1) This is not called for statically linked libraries, and
> 2) There are multiple `DllMain` definitions throughout the JDK native libraries, causing name collisions.
> 
> While it could have been possible to keep the `DllMain` function for non-static builds and just use an alternative solution for static builds, I think it is preferable to have a single solution that works as well for both static and dynamic builds.
> 
> On top of this, the existing solution was contrary to [Microsoft recommendations](https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsacleanup), which state: "The WSACleanup function typically leads to protocol-specific helper DLLs being unloaded. As a result, the WSACleanup function should not be called from the DllMain function in a application DLL. This can potentially cause deadlocks. "

This pull request has now been integrated.

Changeset: d3a7ac22
Author:    Magnus Ihse Bursie <ihse at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/d3a7ac22c9b0a131d2e45bf2d7c5ce8b9e3e3bdd
Stats:     42 lines in 4 files changed: 19 ins; 13 del; 10 mod

8346383: Cannot use DllMain in libdt_socket for static builds

Reviewed-by: dholmes, sspitsyn

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

PR: https://git.openjdk.org/jdk/pull/22789


More information about the serviceability-dev mailing list