From: <AWL...@ao...> - 2003-06-17 02:31:55
|
Hi, A while ago I reported trouble with __CTOR_LIST__ to this list in 'Oh I've got those GNU GCC and ld linkage to MS .LIB blues...' I am happy to report that I have traced it to what is apparently a bug in the GNU binutils ld i386-pe ldscript. Specifically, for reasons unknown(*) to me, the __CTOR_LIST__ symbol may not be correctly aligned, causing padding between the symbol and the following appended .ctors sections, which will break the code in __do_global_ctors, and almost certainly cause the program to crash on startup. (* To the best of my knowledge, the symbol is not aligned because there is no particular garentee that it be aligned in the linker script. However, it is a mystery to me how this hasn't happened to anyone before.. My hypothesis is that this is because I am linking against MSVC-generated objects [read the above-mentioned post for details] which don't enforce the same alignment requirements as GCC/GAS.) The fix is to insert a statement in the linker script that forces __CTOR_LIST__ to be aligned. This is a no-op if it is already aligned. My patch against the default MinGW binutils-2.13.90-20030111-1-src: *** i386pe.x.old Sun Jun 15 07:02:05 2003 --- i386pe.x Sun Jun 15 07:18:19 2003 *************** SECTIONS *** 11,16 **** --- 11,17 ---- *(SORT(.text$*)) *(.glue_7t) *(.glue_7) + . = ALIGN(0x100); ___CTOR_LIST__ = .; __CTOR_LIST__ = . ; LONG (-1); *(SORT(.ctors.*)); *(.ctors); *(.ctor); LONG (0); ___DTOR_LIST__ = .; __DTOR_LIST__ = . ; Unfortunately, when I attempt to test this, MinGW sh crashes when trying trying to recompile binutils (apparently not caused by this patch): ar cru libintl.a intl-compat.o bindtextdom.o dcgettext.o dgettext.o gettext.o finddomain.o loadmsgcat.o localealias.o textdomain.o l10nflist.o explodename.o 0 [main] sh 2080 open_stackdumpfile: Dumping stack trace to sh.exe.stackdump ranlib libintl.a 0 [main] sh 3564 open_stackdumpfile: Dumping stack trace to sh.exe.stackdump make[1]: *** [libintl.a] Segmentation fault (core dumped) make[1]: Leaving directory `/c/aaronwl/cs/src/mingw/official/src/binutils/binutils-ctorfix/intl' make: *** [all-intl] Error 2 This appears to be related to the bug reported in 'How to build a cross compiler,' but I don't understand how to work around it. (How do maintainers compile binutils?) However, applying the patch manually to a user linker script fixes the constructor list problem just fine. So, if someone could help me get all this working, that would be great. Also, should this patch be submitted to the GNU binutils guys? Any hints for that? For an unrelated vanity question, can anyone recommend a GUI threaded mail reader for Win32 or Unix/X? (if replying just about this, dont bother CC'ing the list :)) Thanks, Aaron |