在 2025-3-6 17:51, Jacek Caban 写道:
On 5.03.2025 03:25, LIU Hao wrote:
Second, in the future, if `IMAGE_GUARD_PROTECT_DELAYLOAD_IAT` is specified in `GuardFlags` of the load config directory of an image, the delay-load IAT can also be made read-only, which may also require this change.


I think that when MSVC does this, it also places the delay-load IAT in a separate page to ensure that changing its protection doesn’t affect other data. Modifying the protection of a random page that happens to contain the delay-load IAT doesn’t seem correct.

When GNU LD is in use, the IAT goes into its own `.idata` section and not into `.rdata`. Right now it can be assumed that this code can't modify protection of user data.

BTW since it restores the old protection, if the IAT for some reason becomes writeable, it will not be made back read-only.


Relying on __delayLoadHelper2 behavior specific to mingw-w64 comes with drawbacks. As I mentioned earlier, an application can forward the call to ResolveDelayLoadedAPI, which will bypass this change and fail to work, while it previously worked with earlier binutils.

That works. You can try the attached program.


Overall, since we agree that the issue lies with binutils, I believe it should be fixed there rather than working around it in mingw-w64-crt.

I am afraid it would be a massive change and we are too late about it. There seems to be quite a little dark magic about `.idata$[234567]` sections in LD linker scripts, which prevents the section-renaming technique that you committed it to Wine, from working.



--
Best regards,
LIU Hao
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#include <winsock2.h>
#include <stdio.h>

int
main(void)
  {
    fprintf(stderr, "first\n");
    SetLastError(123);
    fprintf(stderr, "WSAGetLastError = %d\n", WSAGetLastError());
    fprintf(stderr, "second\n");
  }
#!/bin/sh -ex

dlltool -nn -d ws2_32.def -y delay_ws2_32.a
#                         -y  delay import library
#                         -l  ordinary import library

gcc -g delay.c delay_ws2_32.a -o delay.exe
./delay.exe
LIBRARY "WS2_32.DLL"
EXPORTS
  WSAGetLastError

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to