If dlopen() for DLL A is called in constructor DLL B, the constructor
for DLL A 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: Mark Geisert <[email protected]>, Jon Turney 
<[email protected]>
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 5ef0fa875..e26457a69 100644
--- a/winsup/cygwin/dll_init.cc
+++ b/winsup/cygwin/dll_init.cc
@@ -612,9 +612,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