On Wed, 2009-07-08 at 16:45 +0200, Danny Backx wrote: > On Wed, 2009-07-08 at 15:21 +0100, Dave Korn wrote: > > So, how do those addresses relate to where the DLL actually is loaded in > > memory? I'm assuming not much, given that it crashes, which would imply > > something had gone very very wrong at the link stage. Where is the DLL > > actually located in memory? What's in the .o file corresponding to those > > locations above, and what kind of reloc does it have? > > The "very very wrong at the link stage" statement may be accurate. But > my x86 assembler dates back to the days of the 8088 so I'm guessing a > bit.
Trying to dig deeper ;-) The gdb session shows that the last addresses execution passes through are 0x401083 and 0x401092. The former of those addresses looks like the start of the constructor function generated in the C++ compiler (one per source, called __static_initialization_and_destruction_*, see gcc-4.4.0/gcc/cp/decl2.c). 0040107d <__Z41__static_initialization_and_destruction_0ii>: 40107d: 55 push %ebp 40107e: 89 e5 mov %esp,%ebp 401080: 83 ec 18 sub $0x18,%esp 401083: 83 7d 08 01 cmpl $0x1,0x8(%ebp) 401087: 75 15 jne 40109e <__fu2___ZNSt8ios_base4InitC1Ev+0x4> 401089: 81 7d 0c ff ff 00 00 cmpl $0xffff,0xc(%ebp) 401090: 75 0c jne 40109e <__fu2___ZNSt8ios_base4InitC1Ev+0x4> 401092: c7 04 24 00 40 40 00 movl $0x404000,(%esp) 401099: e8 92 40 00 00 call 405130 <__imp___ZNSt8ios_base4InitC1Ev> 0040109a <__fu2___ZNSt8ios_base4InitC1Ev>: 40109a: 92 xchg %eax,%edx 40109b: 40 inc %eax 40109c: 00 00 add %al,(%eax) 40109e: 83 7d 08 00 cmpl $0x0,0x8(%ebp) 4010a2: 75 15 jne 4010b9 <__fu3___ZNSt8ios_base4InitD1Ev+0x4> 4010a4: 81 7d 0c ff ff 00 00 cmpl $0xffff,0xc(%ebp) 4010ab: 75 0c jne 4010b9 <__fu3___ZNSt8ios_base4InitD1Ev+0x4> 4010ad: c7 04 24 00 40 40 00 movl $0x404000,(%esp) 4010b4: e8 7b 40 00 00 call 405134 <__imp___ZNSt8ios_base4InitD1Ev> 004010b5 <__fu3___ZNSt8ios_base4InitD1Ev>: 4010b5: 7b 40 jnp 4010f7 <__pei386_runtime_relocator+0x3> 4010b7: 00 00 add %al,(%eax) 4010b9: c9 leave 4010ba: c3 ret The second is inside that function, just before it calls a function at 0x405130, this is the constructor. Note that a bit lower, there is similar code for the destructor, calling 0x405134. The symbols shown for these addresses by objdump are __imp followed by a mangled version of ios_base::Init . The code there is very interesting : I would expect that executing an "in" statement would fail :-) 00405130 <__imp___ZNSt8ios_base4InitC1Ev>: 405130: e4 51 in $0x51,%al ... 00405134 <__imp___ZNSt8ios_base4InitD1Ev>: 405134: 00 52 00 add %dl,0x0(%edx) ... This is obviously where it goes wrong. With my limited knowledge of how ld works and how src/binutils/ld/pe-dll.c does its thing, I can't say immediately what should happen here. The comments at the top of pe-dll.c seem to imply that the stuff at 0x405130 should not be code, but a data structure. Also when looking at how a call to GetModuleFileName is resolved, it would appear that the "call 0x405130" statement is wrong, it should be "call *0x405130". <<evidence : calling GetModuleFileName>> 40139b: 8d 9d e8 fb ff ff lea -0x418(%ebp),%ebx 4013a1: 89 5c 24 04 mov %ebx,0x4(%esp) 4013a5: c7 04 24 00 00 00 00 movl $0x0,(%esp) 4013ac: e8 b3 02 00 00 call 401664 <_GetModuleFileNameW> 4013b1: 89 c7 mov %eax,%edi 00401664 <_GetModuleFileNameW>: 401664: ff 25 f8 50 40 00 jmp *0x4050f8 40166a: 90 nop 40166b: 90 nop 004050f8 <__imp__GetModuleFileNameW>: 4050f8: 44 inc %esp 4050f9: 51 push %ecx ... <<end of evidence>> Suggestions, anyone ? Danny pavilion: {309} i386-mingw32ce-gdb hello.exe GNU gdb 6.8 Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=i686-pc-linux-gnu --target=i386-mingw32ce"... (gdb) target remote ebox:9999 Remote debugging using ebox:9999 [New Thread 88473610] Error while mapping shared library sections: \network\x86\libgcc_s_sjlj-1.dll: No such file or directory. Error while mapping shared library sections: libstdc++-6.dll: No such file or directory. Error while mapping shared library sections: \Windows\coredll.dll: No such file or directory. Symbol file not found for \network\x86\libgcc_s_sjlj-1.dll Symbol file not found for libstdc++-6.dll Symbol file not found for \Windows\coredll.dll WinMainCRTStartup (hInst=0x545000a, hPrevInst=0x0, lpCmdLine=0x2201fc70, nCmdShow=5) at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/crt3.c:35 35 { Current language: auto; currently c (gdb) s 41 _fpreset (); /* Supplied by the runtime library. */ (gdb) 44 _pei386_runtime_relocator (); (gdb) _pei386_runtime_relocator () at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/pseudo-reloc.c:33 33 for (r = (runtime_pseudo_reloc*) start; r < (runtime_pseudo_reloc*) end; r++) (gdb) 46 } (gdb) WinMainCRTStartup (hInst=0x545000a, hPrevInst=0x0, lpCmdLine=0x2201fc70, nCmdShow=5) at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/crt3.c:49 49 __atexit_init(); (gdb) __atexit_init () at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/atexit.c:65 65 first_atexit = (p_atexit_fn*) malloc (32 * sizeof (p_atexit_fn)); (gdb) 66 if (first_atexit == NULL ) /* can't allocate memory */ (gdb) 73 *first_atexit = NULL; (gdb) 74 next_atexit = first_atexit; (gdb) 76 } (gdb) WinMainCRTStartup (hInst=0x545000a, hPrevInst=0x0, lpCmdLine=0x2201fc70, nCmdShow=5) at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/crt3.c:54 54 __gccmain(); (gdb) __gccmain () at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/gccmain.c:79 79 if (!initialized) (gdb) 81 initialized = 1; (gdb) 86 } (gdb) __gccmain () at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/gccmain.c:83 83 __mingw_do_global_ctors (); (gdb) __mingw_do_global_ctors () at /home/danny/src/cegcc/svn.sf.net/cegcc/trunk/cegcc/src/mingw/gccmain.c:40 40 { (gdb) 41 unsigned long nptrs = (unsigned long) __CTOR_LIST__[0]; (gdb) 49 if (nptrs == -1) (gdb) 58 for (i = nptrs; i >= 1; i--) (gdb) 60 __CTOR_LIST__[i] (); (gdb) global constructors keyed to main () at hello.C:8 8 } Current language: auto; currently c++ (gdb) __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at hello.C:8 8 } (gdb) info registers eax 0x2 2 ecx 0x0 0 edx 0x0 0 ebx 0x1 1 esp 0x2201fb30 0x2201fb30 ebp 0x2201fb48 0x2201fb48 esi 0x401698 4200088 edi 0x2201fc38 570555448 eip 0x401083 0x401083 <__static_initialization_and_destruction_0+6> eflags 0x3206 [ PF IF #12 #13 ] cs 0x3b 59 ss 0x43 67 ds 0x40 64 es 0x40 64 fs 0x60 96 gs 0x0 0 (gdb) s 72 static ios_base::Init __ioinit; (gdb) info registers eax 0x2 2 ecx 0x0 0 edx 0x0 0 ebx 0x1 1 esp 0x2201fb30 0x2201fb30 ebp 0x2201fb48 0x2201fb48 esi 0x401698 4200088 edi 0x2201fc38 570555448 eip 0x401092 0x401092 <__static_initialization_and_destruction_0+21> eflags 0x3246 [ PF ZF IF #12 #13 ] cs 0x3b 59 ss 0x43 67 ds 0x40 64 es 0x40 64 fs 0x60 96 gs 0x0 0 (gdb) s Program received signal SIGSEGV, Segmentation fault. 0x423517be in ?? () (gdb) info registers eax 0x2 2 ecx 0x0 0 edx 0x0 0 ebx 0x1 1 esp 0x2201fb2c 0x2201fb2c ebp 0x2201fb48 0x2201fb48 esi 0x401698 4200088 edi 0x2201fc38 570555448 eip 0x423517be 0x423517be eflags 0x3246 [ PF ZF IF #12 #13 ] cs 0x3b 59 ss 0x43 67 ds 0x40 64 es 0x40 64 fs 0x60 96 gs 0x0 0 (gdb) -- Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info ------------------------------------------------------------------------------ _______________________________________________ Cegcc-devel mailing list Cegcc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cegcc-devel