On 2017/2/7 0:26, Hannes Domani wrote:
> Hello
>
>
> Does delay-loading work with 32bit executables?
>
> In the following example it crashes for me on the dll_function() call.
> I've used i686-6.3.0-release-win32-dwarf-rt_v5-rev1.7z for my tests.
I compiled the program and it did crash. The assembly code generated 
looks like this:

     00401570 | push    ebp                        | int main(){
     00401571 | mov     ebp, esp                   |
     00401573 | and     esp, FFFFFFF0              |
     00401576 | call    app.401700                 |   __main();
     0040157B | mov     eax, dword ptr ds:[407204] |
     00401580 | call    eax                        |
     00401582 | mov     eax, 0                     |   return 0;
     00401587 | leave                              |
     00401588 | ret                                | }

     0040158C | push    ecx                        |
     0040158D | push    edx                        |
     0040158E | push    eax                        |
     0040158F | push    <app.sub_402DB0>           |
     00401594 | call    app.4026A0                 |
     00401599 | pop     edx                        |
     0040159A | pop     ecx                        |
     0040159B | jmp     eax                        |

The pointer at address 407204 should be a pointer to the DLL loader 
function initially, which is located at 0040158C. The pointer here is 
initially null and results in jumping to address zero, hence the crash.

In addition to that, the assembly code of the DLL loader function is 
incorrect. The DLL loader function requires the caller to pass the 
address of the function pointer above (which is 407204) via the EAX 
register. That is, the first instruction at 0040158C should have been 
`lea eax, dword ptr ds:[407204]`.

Compiling app.c with `-S -masm=intel` produces the following assembly 
code, with directives removed:

     _main:
        push    ebp
        mov     ebp, esp
        and     esp, -16
        call    ___main
        mov     eax, DWORD PTR __imp__dll_function
        call    eax
        mov     eax, 0
        leave
        ret

The DLL loader function `__imp__dll_function` seems not generated by the 
compiler. So it seems that dlltool for i686 isn't generating correct 
machine code for delay-loaded functions.

-- 
Best regards,
LH_Mouse


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to