This repository provides a sample to replicate the MinGW delay loading issue.
So far, this issue has been found to happen when trying to link with the
wininet, virtdisk, uxtheme libraries. The use of InternetCrackUrlA()
from wininet is only provided here as an example, as many more calls and
DLLs are affected.
An initial discussion of the issue, on the MinGW mailing list, can be found here.
Two "workarounds" have been found to alleviate the issue:
-
Redefining
DECLSPEC_IMPORTto use__attribute__((visibility("hidden")))instead of__declspec (dllimport). However, this kind of workaround is problematic as, for instance, MinGW'swindows.hheader doest itself include more headers that useDECLSPEC_IMPORT, which mean redefining the macro before the relevant header inclusion is tricky. -
Adding explicit references to the symbols that the linker appears to ignore (in this example
_InternetCrackUrlA@16) so that they aren't discarded. Likewise, this workaround is problematic, as, even outside of having to identify all the problematic function calls, one must make sure these additional intrinsic function calls are referenced by the application or added as-uparameters when invokingld, and since the decorations are not the same for 32 and 64 bit, one cannot just use a single common 32 + 64 bit implementation...
- Clone https://github.com/pbatard/delayload.git (this repository)
- From a MinGW32 (32-bit) prompt, issue
make. - Run
./delayload.exeand observe the crash. - To test with the workarounds, issue
make cleanand then eithermake WORKAROUND1ormake WORKAROUND2.