[PATCH] Cygwin: autoload: drop the unused no_resolve_on_fork parameter
Aswin Kalies Ramkumar Mangayarkarasi <[email protected]>
| Newsgroups | gmane.os.cygwin.patches |
|---|---|
| Message-ID | <PN3P287MB13209A14DE960126F3311558F7A62@PN3P287MB1320.INDP287.PROD.OUTLOOK.COM> |
Hi Jon,
This is the second half of the split you asked for in
https://cygwin.com/pipermail/cygwin-patches/2026q3/015146.html
You wrote:
> the "fix ws2_32 chained init on AArch64" part of this looks
> reasonable and doesn't seem to be connected. Can you submit that
> as a separate patch?
The ws2_32 half went out separately as
https://cygwin.com/pipermail/cygwin-patches/2026q3/015160.html
This patch is the remaining part: removing the no_resolve_on_fork
macro parameter. It carries no ws2_32 changes and does not depend
on that patch; the two can go in in either order.
On the earlier thread we said the flag was never consumed but did
not identify when that became true. It was commit 105f79b489d5
("Drop use_dont_resolve_hack flag", Jun 2016), which removed the
only reader:
if (!h && handle && wincap.use_dont_resolve_hack ()
&& GetLastError () == ERROR_INVALID_ADDRESS)
h = LoadLibraryExW (dll_path, NULL, DONT_RESOLVE_DLL_REFERENCES);
The "&& handle" there was what the sentinel fed. Once that went,
the only remaining reader of the field became
else if ((uintptr_t) dll->handle <= 1)
in std_dll_init, which treats 1 exactly as it treats 0. So the
nineteen winmm entries primed with 1 behave identically to every
other DLL, and nothing else in the tree examines the field.
The patch drops the parameter, initialises the slot to 0
unconditionally, and simplifies the two tests to !dll->handle,
which is equivalent once the field can no longer hold 1. No
functional change.
Thanks and Regards,
Aswin Kalies
Inline patch
---
winsup/cygwin/autoload.cc | 58 +++++++++++++++++++--------------------
1 file changed, 29 insertions(+), 29 deletions(-)
diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index 7054511b6..37c4a3438 100644
--- a/winsup/cygwin/autoload.cc
+++ b/winsup/cygwin/autoload.cc
@@ -85,13 +85,13 @@ bool NO_COPY wsock_started;
The macro WORD64 stands in for .quad/.xword, and .balign (which means
"align to N bytes" on all targets, unlike .align) is used for
alignment. */
-#define LoadDLLprime(dllname, init_also, no_resolve_on_fork) __asm__ ("\n\
+#define LoadDLLprime(dllname, init_also) __asm__ ("\n\
.ifndef " #dllname "_primed \n\
.section .data_cygwin_nocopy,\"w\" \n\
.balign 8 \n\
." #dllname "_info: \n\
" WORD64 " _std_dll_init \n\
- " WORD64 " " #no_resolve_on_fork " \n\
+ " WORD64 " 0 \n\
.long -1 \n\
.balign 8 \n\
" WORD64 " " #init_also " \n\
@@ -108,12 +108,12 @@ bool NO_COPY wsock_started;
#define LoadDLLfuncEx(name, dllname, notimp) \
LoadDLLfuncEx2(name, dllname, notimp, 0)
#define LoadDLLfuncEx2(name, dllname, notimp, err) \
- LoadDLLfuncEx3(name, dllname, notimp, err, 0)
+ LoadDLLfuncEx3(name, dllname, notimp, err)
/* Main DLL setup stuff. */
#if defined(__x86_64__)
-#define LoadDLLfuncEx3(name, dllname, notimp, err, no_resolve_on_fork) \
- LoadDLLprime (dllname, dll_func_load, no_resolve_on_fork) \
+#define LoadDLLfuncEx3(name, dllname, notimp, err) \
+ LoadDLLprime (dllname, dll_func_load) \
__asm__ (" \n\
.section ." #dllname "_autoload_text,\"wx\" \n\
.global " #name " \n\
@@ -138,8 +138,8 @@ _win32_" #name ": \n\
.text \n\
");
#elif defined(__aarch64__)
-#define LoadDLLfuncEx3(name, dllname, notimp, err, no_resolve_on_fork) \
- LoadDLLprime (dllname, dll_func_load, no_resolve_on_fork) \
+#define LoadDLLfuncEx3(name, dllname, notimp, err) \
+ LoadDLLprime (dllname, dll_func_load) \
__asm__ ( "\n\
.section ." #dllname "_autoload_text,\"wx\" \n\
.global " #name " \n\
@@ -438,7 +438,7 @@ std_dll_init (struct func_info *func)
yield ();
}
while (InterlockedIncrement (&dll->here));
- else if ((uintptr_t) dll->handle <= 1)
+ else if (!dll->handle)
{
fenv_t fpuenv;
fegetenv (&fpuenv);
@@ -461,7 +461,7 @@ std_dll_init (struct func_info *func)
if (i < RETRY_COUNT)
yield ();
}
- if ((uintptr_t) dll->handle <= 1)
+ if (!dll->handle)
{
if ((func->decoration & 1))
dll->handle = INVALID_HANDLE_VALUE;
@@ -534,7 +534,7 @@ wsock_init (struct func_info *func)
return ret.ll;
}
-LoadDLLprime (ws2_32, _wsock_init, 0)
+LoadDLLprime (ws2_32, _wsock_init)
LoadDLLfunc (CheckTokenMembership, advapi32)
LoadDLLfunc (CreateProcessAsUserW, advapi32)
@@ -711,25 +711,25 @@ LoadDLLfuncEx2 (CreateProfile, userenv, 1, 1)
LoadDLLfunc (DestroyEnvironmentBlock, userenv)
LoadDLLfunc (LoadUserProfileW, userenv)
-LoadDLLfuncEx3 (waveInAddBuffer, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveInClose, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveInGetNumDevs, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveInOpen, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveInPrepareHeader, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveInReset, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveInStart, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveInUnprepareHeader, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveOutClose, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveOutGetNumDevs, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveOutGetVolume, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveOutOpen, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveOutPrepareHeader, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveOutReset, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveOutSetVolume, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveOutUnprepareHeader, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveOutWrite, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveOutMessage, winmm, 1, 0, 1)
-LoadDLLfuncEx3 (waveOutGetDevCapsA, winmm, 1, 0, 1)
+LoadDLLfuncEx3 (waveInAddBuffer, winmm, 1, 0)
+LoadDLLfuncEx3 (waveInClose, winmm, 1, 0)
+LoadDLLfuncEx3 (waveInGetNumDevs, winmm, 1, 0)
+LoadDLLfuncEx3 (waveInOpen, winmm, 1, 0)
+LoadDLLfuncEx3 (waveInPrepareHeader, winmm, 1, 0)
+LoadDLLfuncEx3 (waveInReset, winmm, 1, 0)
+LoadDLLfuncEx3 (waveInStart, winmm, 1, 0)
+LoadDLLfuncEx3 (waveInUnprepareHeader, winmm, 1, 0)
+LoadDLLfuncEx3 (waveOutClose, winmm, 1, 0)
+LoadDLLfuncEx3 (waveOutGetNumDevs, winmm, 1, 0)
+LoadDLLfuncEx3 (waveOutGetVolume, winmm, 1, 0)
+LoadDLLfuncEx3 (waveOutOpen, winmm, 1, 0)
+LoadDLLfuncEx3 (waveOutPrepareHeader, winmm, 1, 0)
+LoadDLLfuncEx3 (waveOutReset, winmm, 1, 0)
+LoadDLLfuncEx3 (waveOutSetVolume, winmm, 1, 0)
+LoadDLLfuncEx3 (waveOutUnprepareHeader, winmm, 1, 0)
+LoadDLLfuncEx3 (waveOutWrite, winmm, 1, 0)
+LoadDLLfuncEx3 (waveOutMessage, winmm, 1, 0)
+LoadDLLfuncEx3 (waveOutGetDevCapsA, winmm, 1, 0)
LoadDLLfunc (accept, ws2_32)
LoadDLLfunc (bind, ws2_32)
--
2.49.0.windows.1
cygwin-autoload-drop-no_resolve_on_fork.patch
(application/octet-stream, 6.4 KB)
From d44418333e5e047694b2bf880c50df65aa505a8d Mon Sep 17 00:00:00 2001 From: Aswin Kalies Ramkumar Mangayarkarasi <[email protected]> Date: Tue, 18 Aug 2026 10:09:27 +0530 Subject: [PATCH] Cygwin: autoload: drop the unused no_resolve_on_fork parameter The second word of each DLL info block is initialised from the no_resolve_on_fork macro parameter and lands in dll_info::handle. Its only consumer was the DONT_RESOLVE_DLL_REFERENCES retry in dll_load, if (!h && handle && wincap.use_dont_resolve_hack () && GetLastError () == ERROR_INVALID_ADDRESS) h = LoadLibraryExW (dll_path, NULL, DONT_RESOLVE_DLL_REFERENCES); which commit 105f79b489d5 ("Drop use_dont_resolve_hack flag") removed in 2016. The value has been dead ever since: the nineteen winmm entries are the only ones primed with 1, and the sole remaining test, else if ((uintptr_t) dll->handle <= 1) in std_dll_init, treats 1 exactly as it treats 0, so those entries behave identically to every other DLL. Drop the parameter from LoadDLLprime and LoadDLLfuncEx3, initialise the slot to 0 unconditionally, and simplify the two tests to !dll->handle now that the field can never hold 1. No functional change. Signed-off-by: Aswin Kalies <[email protected]> --- winsup/cygwin/autoload.cc | 58 +++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index 7054511b6..37c4a3438 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -85,13 +85,13 @@ bool NO_COPY wsock_started; The macro WORD64 stands in for .quad/.xword, and .balign (which means "align to N bytes" on all targets, unlike .align) is used for alignment. */ -#define LoadDLLprime(dllname, init_also, no_resolve_on_fork) __asm__ ("\n\ +#define LoadDLLprime(dllname, init_also) __asm__ ("\n\ .ifndef " #dllname "_primed \n\ .section .data_cygwin_nocopy,\"w\" \n\ .balign 8 \n\ ." #dllname "_info: \n\ " WORD64 " _std_dll_init \n\ - " WORD64 " " #no_resolve_on_fork " \n\ + " WORD64 " 0 \n\ .long -1 \n\ .balign 8 \n\ " WORD64 " " #init_also " \n\ @@ -108,12 +108,12 @@ bool NO_COPY wsock_started; #define LoadDLLfuncEx(name, dllname, notimp) \ LoadDLLfuncEx2(name, dllname, notimp, 0) #define LoadDLLfuncEx2(name, dllname, notimp, err) \ - LoadDLLfuncEx3(name, dllname, notimp, err, 0) + LoadDLLfuncEx3(name, dllname, notimp, err) /* Main DLL setup stuff. */ #if defined(__x86_64__) -#define LoadDLLfuncEx3(name, dllname, notimp, err, no_resolve_on_fork) \ - LoadDLLprime (dllname, dll_func_load, no_resolve_on_fork) \ +#define LoadDLLfuncEx3(name, dllname, notimp, err) \ + LoadDLLprime (dllname, dll_func_load) \ __asm__ (" \n\ .section ." #dllname "_autoload_text,\"wx\" \n\ .global " #name " \n\ @@ -138,8 +138,8 @@ _win32_" #name ": \n\ .text \n\ "); #elif defined(__aarch64__) -#define LoadDLLfuncEx3(name, dllname, notimp, err, no_resolve_on_fork) \ - LoadDLLprime (dllname, dll_func_load, no_resolve_on_fork) \ +#define LoadDLLfuncEx3(name, dllname, notimp, err) \ + LoadDLLprime (dllname, dll_func_load) \ __asm__ ( "\n\ .section ." #dllname "_autoload_text,\"wx\" \n\ .global " #name " \n\ @@ -438,7 +438,7 @@ std_dll_init (struct func_info *func) yield (); } while (InterlockedIncrement (&dll->here)); - else if ((uintptr_t) dll->handle <= 1) + else if (!dll->handle) { fenv_t fpuenv; fegetenv (&fpuenv); @@ -461,7 +461,7 @@ std_dll_init (struct func_info *func) if (i < RETRY_COUNT) yield (); } - if ((uintptr_t) dll->handle <= 1) + if (!dll->handle) { if ((func->decoration & 1)) dll->handle = INVALID_HANDLE_VALUE; @@ -534,7 +534,7 @@ wsock_init (struct func_info *func) return ret.ll; } -LoadDLLprime (ws2_32, _wsock_init, 0) +LoadDLLprime (ws2_32, _wsock_init) LoadDLLfunc (CheckTokenMembership, advapi32) LoadDLLfunc (CreateProcessAsUserW, advapi32) @@ -711,25 +711,25 @@ LoadDLLfuncEx2 (CreateProfile, userenv, 1, 1) LoadDLLfunc (DestroyEnvironmentBlock, userenv) LoadDLLfunc (LoadUserProfileW, userenv) -LoadDLLfuncEx3 (waveInAddBuffer, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveInClose, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveInGetNumDevs, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveInOpen, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveInPrepareHeader, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveInReset, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveInStart, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveInUnprepareHeader, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveOutClose, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveOutGetNumDevs, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveOutGetVolume, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveOutOpen, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveOutPrepareHeader, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveOutReset, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveOutSetVolume, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveOutUnprepareHeader, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveOutWrite, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveOutMessage, winmm, 1, 0, 1) -LoadDLLfuncEx3 (waveOutGetDevCapsA, winmm, 1, 0, 1) +LoadDLLfuncEx3 (waveInAddBuffer, winmm, 1, 0) +LoadDLLfuncEx3 (waveInClose, winmm, 1, 0) +LoadDLLfuncEx3 (waveInGetNumDevs, winmm, 1, 0) +LoadDLLfuncEx3 (waveInOpen, winmm, 1, 0) +LoadDLLfuncEx3 (waveInPrepareHeader, winmm, 1, 0) +LoadDLLfuncEx3 (waveInReset, winmm, 1, 0) +LoadDLLfuncEx3 (waveInStart, winmm, 1, 0) +LoadDLLfuncEx3 (waveInUnprepareHeader, winmm, 1, 0) +LoadDLLfuncEx3 (waveOutClose, winmm, 1, 0) +LoadDLLfuncEx3 (waveOutGetNumDevs, winmm, 1, 0) +LoadDLLfuncEx3 (waveOutGetVolume, winmm, 1, 0) +LoadDLLfuncEx3 (waveOutOpen, winmm, 1, 0) +LoadDLLfuncEx3 (waveOutPrepareHeader, winmm, 1, 0) +LoadDLLfuncEx3 (waveOutReset, winmm, 1, 0) +LoadDLLfuncEx3 (waveOutSetVolume, winmm, 1, 0) +LoadDLLfuncEx3 (waveOutUnprepareHeader, winmm, 1, 0) +LoadDLLfuncEx3 (waveOutWrite, winmm, 1, 0) +LoadDLLfuncEx3 (waveOutMessage, winmm, 1, 0) +LoadDLLfuncEx3 (waveOutGetDevCapsA, winmm, 1, 0) LoadDLLfunc (accept, ws2_32) LoadDLLfunc (bind, ws2_32) -- 2.49.0.windows.1