http://sourceware.org/bugzilla/show_bug.cgi?id=12614
Summary: mingw ld omits needed jump stubs in link involving --start/end-group Product: binutils Version: unspecified Status: NEW Severity: normal Priority: P2 Component: ld AssignedTo: unassig...@sources.redhat.com ReportedBy: dklprogramm...@web.de Created attachment 5337 --> http://sourceware.org/bugzilla/attachment.cgi?id=5337 Example with makefile Related to a patch that was applied to ld between binutils 2.17 and 2.18: "Eliminate redundant jump stubs on windows/cygwin/MinGW" <http://sourceware.org/ml/binutils/2007-01/msg00162.html> See also: <http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/pe-dll.c?cvsroot=src#rev1.95> <http://sourceware.org/git/?p=binutils.git;a=commit;h=6fd5362b96f51a2763e1a55e6cc78e604f369957> It appears that ld accidentally excludes jump stubs from an import library, when linking like this: main.o -( libfoo.dll.a test.o -) where main.o references a symbol from the import library, and test.o uses a second symbol from the import library. In that case the jump stub for the second symbol (referenced only by test.o) is not included into the executable. If only test.o but not main.o reference a symbol in the import library, the problem does not occur. (Using __declspec(dllimport) on the symbol referenced in test.o prevents running into this issue completely.) Here is an example; it requires a toolchain targetting mingw32: $ cat main.c void test(); void bar(); void mainCRTStartup() { test(); bar(); } $ cat test.c void foo(); void test() { foo(); } $ cat foo.def LIBRARY foo.dll EXPORTS foo bar $ i586-mingw32msvc-gcc -Wall -c main.c -o main.o $ i586-mingw32msvc-gcc -Wall -c test.c -o test.o $ i586-mingw32msvc-dlltool --input-def foo.def --output-lib libfoo.dll.a $ i586-mingw32msvc-ld -o good.exe main.o test.o libfoo.dll.a $ i586-mingw32msvc-ld -o bad.exe main.o "-(" libfoo.dll.a test.o "-)" $ i586-mingw32msvc-objdump -D good.exe > good-disasm.txt $ i586-mingw32msvc-objdump -D bad.exe > bad-disasm.txt Excerpt from good-disasm.txt: 00401000 <_mainCRTStartup>: 401000: 55 push %ebp 401001: 89 e5 mov %esp,%ebp 401003: 83 ec 08 sub $0x8,%esp 401006: e8 09 00 00 00 call 401014 <_test> 40100b: e8 14 00 00 00 call 401024 <_bar> 401010: c9 leave 401011: c3 ret 401012: 90 nop 401013: 90 nop 00401014 <_test>: 401014: 55 push %ebp 401015: 89 e5 mov %esp,%ebp 401017: 83 ec 08 sub $0x8,%esp 40101a: e8 0d 00 00 00 call 40102c <_foo> 40101f: c9 leave 401020: c3 ret 401021: 90 nop 401022: 90 nop 401023: 90 nop 00401024 <_bar>: 401024: ff 25 34 20 40 00 jmp *0x402034 40102a: 90 nop 40102b: 90 nop 0040102c <_foo>: 40102c: ff 25 38 20 40 00 jmp *0x402038 401032: 90 nop 401033: 90 nop Excerpt from bad-disasm.txt: 00401000 <_mainCRTStartup>: 401000: 55 push %ebp 401001: 89 e5 mov %esp,%ebp 401003: 83 ec 08 sub $0x8,%esp 401006: e8 11 00 00 00 call 40101c <_test> 40100b: e8 04 00 00 00 call 401014 <_bar> 401010: c9 leave 401011: c3 ret 401012: 90 nop 401013: 90 nop 00401014 <_bar>: 401014: ff 25 34 20 40 00 jmp *0x402034 40101a: 90 nop 40101b: 90 nop 0040101c <_test>: 40101c: 55 push %ebp 40101d: 89 e5 mov %esp,%ebp 40101f: 83 ec 08 sub $0x8,%esp 401022: e8 d9 ef bf ff call 0 <_foo> 401027: c9 leave 401028: c3 ret 401029: 90 nop 40102a: 90 nop 40102b: 90 nop Notice that in bad.exe the <_foo> stub is not present, and there is a 'call 0' in <_test>. -- Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-binutils