msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.22k stars 1.19k forks source link

mingw-w64-crt-git: ID2D1HwndRenderTarget_GetSize() SIGSERV with gcc 9.2 #5984

Open udbr opened 4 years ago

udbr commented 4 years ago

Building the WIC Image Viewer Using Direct2D Sample, converted to C, using MSYS2 mingw-w64 x86_64 packages, tested with multiple gcc versions.

The program compiles without a problem in any version of GCC tested.

The function ID2D1HwndRenderTarget_GetSize(m_pRT) causes a SIGSERV on gcc 9.1 and 9.2, whereas works as expected on 8.1, 8.2 and 8.2.1.

Upon debugging, i can see gcc 9.x changed something in its calling convention, as shown in the assembly below.

For the working gcc 8.x.x, rax contain a pointer to GetSize(), while rcx and rdx contain m_pRT address: <+388>: mov -0x10(%rbp),%rax <+392>: mov 0x18(%rax),%rax <+396>: mov (%rax),%rax <+399>: mov 0x1a8(%rax),%rax //rax loaded with GetSize() <+406>: mov -0x10(%rbp),%rdx <+410>: mov 0x18(%rdx),%rdx // rdx loaded with m_pRT <+414>: mov %rdx,%rcx <+417>: callq *%rax <+419>: mov %rax,-0xb0(%rbp)

For the non working gcc 9.x, rdx contains the pointer to GetSize() and rax and rcx contains m_pRT address: <+396>: mov -0x10(%rbp),%rax <+400>: mov 0x18(%rax),%rax <+404>: mov (%rax),%rax <+407>: mov 0x1a8(%rax),%rdx <+414>: mov -0x10(%rbp),%rax <+418>: mov 0x18(%rax),%rax <+422>: mov %rax,%rcx <+425>: callq *%rdx <+427>: mov %rax,-0xb0(%rbp)

But if i change the code simulating the 8.x behaviour of gcc, the program runs perfectly as expected, with both gcc 9.1 and 9.2.

//D2D1_SIZE_F rtSize = ID2D1HwndRenderTarget_GetSize(m_pRT); D2D1_SIZE_F rtSize; asm("mov -0x10(%rbp),%rax"); asm("mov 0x18(%rax),%rax"); asm("mov (%rax),%rax"); asm("mov 0x1a8(%rax),%rax"); asm("mov -0x10(%rbp),%rdx"); asm("mov 0x18(%rdx),%rdx"); asm("mov %rdx,%rcx"); asm("callq *%rax"); asm("mov %rax,-0xb0(%rbp)");

I suspect the problem might lie with the libd2d1.a which is incompatible with the current gcc 9.x. I tried to recompile the crt-git package but cant for the love of the gods get it to build.

ZachBacon commented 4 years ago

This should also be reported to the mingw-w64 mailing list as well, there maybe something that wasn't properly done yet for that. https://sourceforge.net/projects/mingw-w64/lists/mingw-w64-public

udbr commented 4 years ago

@ZachBacon I'll try reporting it there, although I'm not sure it applies there, since I think they're still using gcc 8.x which doesn't show the symptoms.

Meanwhile, I was able to rebuild the crt-git package locally with gcc 9.2, yet it still causes the SIGSERV, so I'm at a loss.

I also tested with a i686 build of the program, and it didnt show the problem with any version of gcc, including both 9.1 and 9.2

ZachBacon commented 4 years ago

@udbr doesn't matter, It's still an issue that needs to be reported since it is the main project. Now it's just a matter of time before someone comments on it.