# # Cross compile from linux for mingw32 don't init the ctors from crtend.o! # Every 'throw' in a program crashes with a "NULL-Pointer read". # # >>> Source line: gcc-3.3.1-20030804-1/libstdc++-v3/libsupc++/eh_throw.cc:64 >>> # header->unexpectedHandler = __unexpected_handler; # <<< snip <<< # # "__unexpected_handler" is a macro to variable "__w32_sharedptr_unexpected", # and there was not init. Internal function "_w32_sharedptr_initialize" was # not called before main starts. # # This is the standard function tree, started from a section .ctors in # crtend.o: # __reg_frame_ctor # __do_frame_init # __w32_sharedptr_initialize # __register_frame_info # # Problem is, that "*crtend.o(.ctors)" in linker script does not include the # function pointer to "__reg_frame_ctor". With other words: The default # linker script from mingw32 not loads contructors from crtend.o. This is a # ultra big BUG! # # >>> cat sample.cc >>> #|int main(void) #|{ #| try { #| throw "End!"; #| } catch (...) { #| return 1; #| } #| return 0; #|} # <<< end cat <<< # # Build it with linker map # i686-pc-mingw32-g++ -Wl,-M -Wl,--verbose -o sample.exe sample.cc # # See the emtpy section .ctors for crtend.o: # >>> old bad map file >>> # 0x00406c80 __CTOR_LIST__ = . # 0x00406c80 0x4 LONG 0xffffffff # *(EXCLUDE_FILE(*crtend.o) .ctors) # *(.ctor) # *(SORT(.ctors.*)) # *crtend.o(.ctors) # 0x00406c84 0x4 LONG 0x0 # 0x00406c88 ___DTOR_LIST__ = . # <<< snip map <<< # # With these patch shows good, for sample: # >>> new good map file >>> # 0x00406c80 __CTOR_LIST__ = . # 0x00406c80 0x4 LONG 0xffffffff # *(EXCLUDE_FILE(*crtend.o) .ctors) # *(.ctor) # *(SORT(.ctors.*)) # *(.ctors) # .ctors 0x00406c84 0x4 /home/hn/CoLinux/mingw32/lib/gcc-lib/i686-pc-mingw32/3.3.1/crtend.o # 0x00406c88 0x4 LONG 0x0 # 0x00406c8c ___DTOR_LIST__ = . # <<< snip map <<< # # Henry Nestler --- binutils-2.15.91-20040904-1/ld/scripttempl/pe.sc.old +++ binutils-2.15.91-20040904-1/ld/scripttempl/pe.sc @@ -66,14 +66,14 @@ *(EXCLUDE_FILE (*crtend.o) .ctors); *(.ctor); *(SORT(.ctors.*)); - *crtend.o (.ctors); + *(.ctors); LONG (0); } ${CONSTRUCTING+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ; LONG (-1); *(EXCLUDE_FILE (*crtend.o) .dtors); *(.dtor); *(SORT(.dtors.*)); - *crtend.o (.dtors); + *(.dtors); LONG (0); } ${RELOCATING+ *(.fini)} /* ??? Why is .gcc_exc here? */