From:
<smi...@at...> - 2007-02-23 16:43:53
|
Danny Smith wrote: > GCC will optimize something like this > printf ("a"); > to putchar > > Likewise with iostream char I/O/ > > Given the lack of documentation on the _MT preprocessor switch, maybe > the stdio optimizations > should be based on a runtime switch (_CRT_MT) which really does know > about thread support > > Danny This code seems to work fine with the unmodified GCC: VOID NTAPI tls_callback(PVOID dll_handle, DWORD reason, PVOID reserved) { printf("TLS callback! %d\n", reason); } DWORD tls_index = 0; PIMAGE_TLS_CALLBACK callbacks[] = { tls_callback, 0 }; extern "C" { IMAGE_TLS_DIRECTORY _tls_used = {0,0,(DWORD)&tls_index,(DWORD)callbacks,0,0}; } You can simply put whatever you want in `tls_callback', compile this into an object, and link that instead of `mingwm10.dll'. However, that is NOT the best solution. The best solution would be to be able to mark each callback function and each global TLS variable with some special keyword and have the compiler and linker write out all the PE structures (or have the linker recognise multiple `_tls_used' definitions). The PE format was designed to support an arbitrary number of such callbacks. Of course, if there is only one such callback in the executable, then the above works fine. Problem (mostly) solved. At least for Windows NT, 2000, XP and all later versions. As for Windows 98, 95 etc., well, gcc MIGHT need an option to link or not to link with `mingwm10.dll'. I'd prefer NOT linking be the default, but you may want to maintain backwards compatibility. I haven't tested this under MS-Windows-95 (or should I say MS-DOS-95?) so it might work anyway! |