From: SF/projects/mingw n. l. <min...@li...> - 2013-01-11 18:10:07
|
Bugs item #917257, was opened at 2004-03-16 03:57 Message generated for change (Settings changed) made by earnie You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=917257&group_id=2435 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed Resolution: None Priority: 5 Private: No Submitted By: Sebastian Tusk (sebastiantusk) Assigned to: Nobody/Anonymous (nobody) Summary: optimization bug - wrong indirection with shared libraries Initial Comment: I have here a problem with optimization option -O1 generates corrupt code. Using a linux(debian-unstable) machine to cross-compile for windows the below shown sample code gives strange results with -O1. Without -O1 anything seems fine. Two calls into a shared library are in the sample code. In this case the library is Python but it happens also with xerxces. The problem is not restricted to function calls. Pointers to variables in the shared library causes the problem too. As you may notice from the below shown assembler output the first call (Py_Initialize()) is compiled into 004012ba a1b4404000 mov eax,[image00400000+0x40b4 (004040b4)] 004012bf ffd0 call eax for the unoptimized version and 004012ba ff15b4404000 call dword ptr [image00400000+0x40b4 (004040b4)] for the optimized. That is correct and works. But the second call (Py_InitModule4( NULL, NULL, NULL, NULL, 0x123 )) is compiled into 004012c5 c744241023010000 mov dword ptr [esp+0x10],0x123 004012cd c744240c00000000 mov dword ptr [esp+0xc],0x0 004012d5 c744240800000000 mov dword ptr [esp+0x8],0x0 004012dd c744240400000000 mov dword ptr [esp+0x4],0x0 004012e5 c7042400000000 mov dword ptr [esp],0x0 004012ec a1b0404000 mov eax,[image00400000+0x40b0 (004040b0)] 004012f1 ffd0 call eax for the unoptimized version and 004012c4 c744241023010000 mov dword ptr [esp+0x10],0x123 004012cc c744240c00000000 mov dword ptr [esp+0xc],0x0 004012d4 c744240800000000 mov dword ptr [esp+0x8],0x0 004012dc c744240400000000 mov dword ptr [esp+0x4],0x0 004012e4 c7042400000000 mov dword ptr [esp],0x0 004012eb e8c02d0000 call image00400000+0x40b0 (004040b0) for the optimized. You see that the optimized call doesn't have the indirection necessary to call a function in a shared library. The same indirection that is done correctly in the first call (Py_Initialize()). The program crashes at this point as you may imagine. I have no idea for which calls the problem occurs. Some calls work some not. I think this is a compiler bug but maybe I overlook something. Should I post this mail to the gcc developers too? Regards, Sebastian *** compiler command g++ -b i586-mingw32msvc -V 3.3.1 -I../the_fall/libs/Python-2.2.3/Include -masm=intel test2.cpp -fno-exceptions -L../libs/Python-2.2.3/libs/ -lpython22 *** sample code #include <windows.h> #include "Python.h" int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { asm( "nop; nop; nop; int 3" ); Py_Initialize(); asm( "nop; nop; nop; int 3" ); Py_InitModule4( NULL, NULL, NULL, NULL, 0x123 ); asm( "nop; nop; nop; int 3" ); return 0; } *** without -O1 option 004012b6 90 nop 004012b7 90 nop 004012b8 90 nop 004012b9 cc int 3 004012ba a1b4404000 mov eax,[image00400000+0x40b4 (004040b4)] 004012bf ffd0 call eax 004012c1 90 nop 004012c2 90 nop 004012c3 90 nop 004012c4 cc int 3 004012c5 c744241023010000 mov dword ptr [esp+0x10],0x123 004012cd c744240c00000000 mov dword ptr [esp+0xc],0x0 004012d5 c744240800000000 mov dword ptr [esp+0x8],0x0 004012dd c744240400000000 mov dword ptr [esp+0x4],0x0 004012e5 c7042400000000 mov dword ptr [esp],0x0 004012ec a1b0404000 mov eax,[image00400000+0x40b0 (004040b0)] 004012f1 ffd0 call eax 004012f3 90 nop 004012f4 90 nop 004012f5 90 nop 004012f6 cc int 3 *** with -O1 option 004012b6 90 nop 004012b7 90 nop 004012b8 90 nop 004012b9 cc int 3 004012ba ff15b4404000 call dword ptr [image00400000+0x40b4 (004040b4)] 004012c0 90 nop 004012c1 90 nop 004012c2 90 nop 004012c3 cc int 3 004012c4 c744241023010000 mov dword ptr [esp+0x10],0x123 004012cc c744240c00000000 mov dword ptr [esp+0xc],0x0 004012d4 c744240800000000 mov dword ptr [esp+0x8],0x0 004012dc c744240400000000 mov dword ptr [esp+0x4],0x0 004012e4 c7042400000000 mov dword ptr [esp],0x0 004012eb e8c02d0000 call image00400000+0x40b0 (004040b0) 004012f0 90 nop 004012f1 90 nop 004012f2 90 nop 004012f3 cc int 3 ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2004-03-16 11:52 Message: Logged In: YES user_id=11494 This is what I get with g++-3.4.0 at -O1 -masm=intel Danny .file "test2.ii" .intel_syntax .text .align 2 .globl _WinMain@16 .def _WinMain@16; .scl 2; .type 32; .endef _WinMain@16: push ebp mov ebp, esp sub esp, 24 /APP nop; nop; nop; int 3 /NO_APP call [DWORD PTR __imp__Py_Initialize] /APP nop; nop; nop; int 3 /NO_APP mov DWORD PTR [esp+16], 291 mov DWORD PTR [esp+12], 0 mov DWORD PTR [esp+8], 0 mov DWORD PTR [esp+4], 0 mov DWORD PTR [esp], 0 call DWORD PTR __imp__Py_InitModule4 /APP nop; nop; nop; int 3 /NO_APP mov eax, 0 leave ret 16 ---------------------------------------------------------------------- Comment By: Sebastian Tusk (sebastiantusk) Date: 2004-03-16 07:05 Message: Logged In: YES user_id=999113 I have found that ommitting the -masm=intel command line option solves the problem. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=917257&group_id=2435 |