Bug 12835 - crossbinutils produces broken mingw64 binaries.
Summary: crossbinutils produces broken mingw64 binaries.
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-01 20:02 UTC by Pawel Sikora
Modified: 2011-06-05 11:22 UTC (History)
0 users

See Also:
Host: x86_64-gnu-linux
Target: x86_64-pc-mingw32
Build: x86_64-gnu-linux
Last reconfirmed:


Attachments
testcase (532.80 KB, application/x-gzip)
2011-06-01 20:02 UTC, Pawel Sikora
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel Sikora 2011-06-01 20:02:34 UTC
Created attachment 5762 [details]
testcase

Hi,

during investigating the http://gcc.gnu.org/PR47308 i've discovered that
executable linked by toolchain hosted on windows looks/works fine while
executable linked by crossmingw64 toolchain (host:linux, target:mingw64)
is corrupted in some way.

attached testcase contains objects compiled on linux crosstoolchain
and executables linked on both platforms.

loading both execs to gdb on windows shows difference:

D:\>mingw64\bin\gdb main-dw3-linked-on-linux.exe

Breakpoint 1, 0x0000000000401550 in main ()
(gdb) disassemble
Dump of assembler code for function main():
=> 0x0000000000401550 <+0>:     push   %rbp
   0x0000000000401551 <+1>:     push   %r15
   0x0000000000401553 <+3>:     push   %r14
   0x0000000000401555 <+5>:     push   %r13
   0x0000000000401557 <+7>:     push   %r12
   0x0000000000401559 <+9>:     push   %rdi
   0x000000000040155a <+10>:    push   %rsi
   0x000000000040155b <+11>:    push   %rbx
   0x000000000040155c <+12>:    sub    $0x158,%rsp
   0x0000000000401563 <+19>:    lea    0x80(%rsp),%rbp
   0x000000000040156b <+27>:    movaps %xmm6,0x30(%rbp)
   0x000000000040156f <+31>:    movaps %xmm7,0x40(%rbp)
   0x0000000000401573 <+35>:    movaps %xmm8,0x50(%rbp)
   0x0000000000401578 <+40>:    movaps %xmm9,0x60(%rbp)
   0x000000000040157d <+45>:    movaps %xmm10,0x70(%rbp)
   0x0000000000401582 <+50>:    movaps %xmm11,0x80(%rbp)
   0x000000000040158a <+58>:    movaps %xmm12,0x90(%rbp)
   0x0000000000401592 <+66>:    movaps %xmm13,0xa0(%rbp)
   0x000000000040159a <+74>:    movaps %xmm14,0xb0(%rbp)
   0x00000000004015a2 <+82>:    movaps %xmm15,0xc0(%rbp)
   0x00000000004015aa <+90>:    Dwarf Error: Cannot find signatured DIE referenced from DIE at 0x20c [in module D:\main-dw3-linked-on-linux.exe]


D:\>mingw64\bin\gdb main-dw3-linked-on-windows.exe

Breakpoint 1, 0x0000000000401550 in main ()
(gdb) disassemble
Dump of assembler code for function main():
=> 0x0000000000401550 <+0>:     push   %rbp
   0x0000000000401551 <+1>:     push   %r15
   0x0000000000401553 <+3>:     push   %r14
   0x0000000000401555 <+5>:     push   %r13
   0x0000000000401557 <+7>:     push   %r12
   0x0000000000401559 <+9>:     push   %rdi
   0x000000000040155a <+10>:    push   %rsi
   0x000000000040155b <+11>:    push   %rbx
   0x000000000040155c <+12>:    sub    $0x158,%rsp
   0x0000000000401563 <+19>:    lea    0x80(%rsp),%rbp
   0x000000000040156b <+27>:    movaps %xmm6,0x30(%rbp)
   0x000000000040156f <+31>:    movaps %xmm7,0x40(%rbp)
   0x0000000000401573 <+35>:    movaps %xmm8,0x50(%rbp)
   0x0000000000401578 <+40>:    movaps %xmm9,0x60(%rbp)
   0x000000000040157d <+45>:    movaps %xmm10,0x70(%rbp)
   0x0000000000401582 <+50>:    movaps %xmm11,0x80(%rbp)
   0x000000000040158a <+58>:    movaps %xmm12,0x90(%rbp)
   0x0000000000401592 <+66>:    movaps %xmm13,0xa0(%rbp)
   0x000000000040159a <+74>:    movaps %xmm14,0xb0(%rbp)
   0x00000000004015a2 <+82>:    movaps %xmm15,0xc0(%rbp)
   0x00000000004015aa <+90>:
    lea    0xadbf(%rip),%rax        # 0x40c370 <__cxxabiv1::__gxx_personality_sj0(int, _Unwind_Action, _Unwind_Exception_Class, _Unwind_Exception*, _U
nwind_Context*)>
   0x00000000004015b1 <+97>:    mov    %rax,-0x20(%rbp)
   0x00000000004015b5 <+101>:   lea    0xb564(%rip),%rax        # 0x40cb20 <___DTOR_LIST__+16>
   0x00000000004015bc <+108>:   mov    %rax,-0x18(%rbp)
   0x00000000004015c0 <+112>:   lea    -0x10(%rbp),%rax
   (...)

to reproduce the bug you need to compile and link testcase
on linux (runme.sh) and later relink on windows (runme.cmd).
Comment 1 Pawel Sikora 2011-06-04 17:25:26 UTC
btw, 'objdump -p' shows differences in sections:

(linked-on-linux -> linked-on-windows)

-SizeOfCode             0000be00
-SizeOfInitializedData  00016400
+SizeOfCode             0000bc00
+SizeOfInitializedData  00016000

-Entry 3 0000000000016000 000009e4 Exception Directory [.pdata]
+Entry 3 0000000000016000 000009cc Exception Directory [.pdata]
Comment 2 Pawel Sikora 2011-06-05 11:22:41 UTC
not a linker bug.
my libstdc++ --enable-cxx-flags='-gdwarf-4 -g2' breaks the world.