---------- Forwarded message ----------
From: "Abuse 007" <firstname.lastname@example.org>
Date: Dec 6, 2012 11:25 AM
Subject: TLS Callback Access Violation
I am trying to cross-compile from Linux to Windows using MinGW.
I'm using i686-mingw32-gcc (Gentoo Hardened 4.7.2 p1.3, pie-0.5.5) 4.7.2.
I have simple code: -
int WINAPI WinMain (HINSTANCE hInstance,
int iCmdShow )
MessageBox (NULL, "Hello", "Hello Demo", MB_OK );
When I run it in Wine I get an unhandled exception page fault on reading 0x00408000 from 0x00407fff.
When I run it on Windows XP SP3 (32-bit) it crashes with exception code 0xc0000005 (Access Violation).
When I compile it using the Microsoft Compiler, with a reference to User32.lib, the code compiles fine and runs properly.
When I debug the MinGW produced executable, one of the TLS Callbacks (there are two, plus the WinMainCTRStartup entry point), eventually calls TlsStart which is all NULLs. It executes until it reaches the end of the page, the last mapped byte being at address 0x00407fff, it tries to fetch the next instruction at 0x00408000 which causes the exception since it's not mapped.
It seems the TLS code in MinGW is broken and generating faulty code that causes the executable to crash.
Is it possible to disable TLS in MinGW? I couldn't find the option.
Alternatively is it possible to get MinGW to produce TLS callbacks that terminate/return properly without causing the process to crash?