If dlopen() for the first DLL is called in the constructor of another
(second) DLL, the constructor for the first DLL is called twice, once
called via cygwin_attach_dll() called from LoadLibrary(), and again
from dll_list::init(). That is, the DLL with DLL_LOAD does not need
dll::init() in dll_list::init(). This issue was found when debugging
the issue: https://cygwin.com/pipermail/cygwin/2025-October/258877.html
This patch remove dll::init() call in dll_list::init() for DLL_LOAD.

Fixes: 2eb392bd77de ("dll_init.cc: Revamp.  Use new classes.")
Reviewed-by:
Signed-off-by: Takashi Yano <[email protected]>
---
 winsup/cygwin/dll_init.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/dll_init.cc b/winsup/cygwin/dll_init.cc
index b6ab4ed11..996f00a44 100644
--- a/winsup/cygwin/dll_init.cc
+++ b/winsup/cygwin/dll_init.cc
@@ -610,9 +610,10 @@ dll_list::init ()
   /* Walk the dll chain, initializing each dll */
   dll *d = &start;
   dll_global_dtors_recorded = d->next != NULL;
-  /* Init linked and early loaded Cygwin DLLs. */
+  /* Init linked Cygwin DLLs. As for loaded DLLs, dll::init() is already
+     called via _cygwin_dll_entry called from LoadLibrary(). */
   while ((d = d->next))
-    if (d->type == DLL_LINK || d->type == DLL_LOAD)
+    if (d->type == DLL_LINK)
       d->init ();
 }
 
-- 
2.51.0

Reply via email to