[AD] [ alleg-Bugs-3394253 ] TLS-related crash with Windows XP and 2003

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Bugs item #3394253, was opened at 2011-08-18 21:06
Message generated for change (Comment added) made by konforce
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105665&aid=3394253&group_id=5665

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Windows
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Peterix (peterix)
Assigned to: Nobody/Anonymous (nobody)
Summary: TLS-related crash with Windows XP and 2003

Initial Comment:
Hello, I'm using Allegro 5 for some very weird things in very weird ways :)
Basic design is like this:
I have a game I have no sources for, but it uses SDL, I replace SDL with my own library, which then acts as a plugin loader. One of the plugins then uses Allegro to paint a nice isometric view of the game world (as opposed to the game's ASCII codes). On windows, this uses the LoadLibrary call, in turn also loading Allegro.

The issue is that XP and 2003 have broken implicit TLS when the library that uses TLS is loaded this way, leading to crashes on the first Allegro call.

Some links related to the issue:
http://msdn.microsoft.com/en-us/library/ms684175%28v=vs.85%29.aspx
http://www.nynaeve.net/?p=187

----------------------------------------------------------------------

>Comment By: Matthew Leverton (konforce)
Date: 2011-08-20 12:30

Message:
See http://www.allegro.cc/forums/thread/607408 for context on why it was
disabled.

----------------------------------------------------------------------

Comment By: Peterix (peterix)
Date: 2011-08-20 11:29

Message:
Ok. I solved the problem, but I had to make some changes to the build
system and allegro code.

It really didn't want me to use DLL TLS.

So, first I fixed the build system - even if I set WANT_DLL_TLS, it turned
it off behind my back.
In CMakeLists.txt replace:
174 	if(WIN32)
175 	if(WANT_DLL_TLS AND SHARED)
176 	set(ALLEGRO_CFG_DLL_TLS 1)
177 	endif(WANT_DLL_TLS AND SHARED)
178 	endif(WIN32)
179 	
180 	if(MSVC)
181 	# MSVC never needs DLL TLS and it just confuses
182 	set(ALLEGRO_CFG_DLL_TLS 0)
183 	set(COMPILER_MSVC 1)
184 	set(ALLEGRO_MSVC 1)

with this:
174 	if(WIN32)
175 	if(WANT_DLL_TLS)
176 	set(ALLEGRO_CFG_DLL_TLS 1)
177 	endif(WANT_DLL_TLS)
178 	endif(WIN32)
179 	
180 	if(MSVC)
181 	set(COMPILER_MSVC 1)
182 	set(ALLEGRO_MSVC 1)

From tls.c remove:
135 	// FIXME: The TLS implementation below only works for dynamic linking
136 	// right now - instead of using DllMain we should simply initialize
137 	// on first request.
138 	#ifdef ALLEGRO_STATICLINK
139 	#undef ALLEGRO_CFG_DLL_TLS
140 	#endif

Then it's possible to build allegro as a set of static libs, where they
use explicit TLS and can be linked with a plugin library that works on
Windows XP.

What was the real problem here? I guess not respecting the options
selected by the user. When I select that I want DLL TLS with a STATIC
build, I mean it and I don't need the build system or the library to second
guess my decision :)

----------------------------------------------------------------------

Comment By: Peterix (peterix)
Date: 2011-08-18 21:20

Message:
Awesome, I'll try that.

----------------------------------------------------------------------

Comment By: Trent Gamblin (trentg)
Date: 2011-08-18 21:15

Message:
When building Allegro, there is a cmake flag, WANT_DLL_TLS that forces the
use of DllMain and the TlsAlloc and the like functions. You may have to
build the library yourself as I believe the prebuilt binaries (at least the
MSVC ones, but probably not the older MinGW ones) use implicit TLS. From my
quick look at your first link, that should fix this particular problem.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105665&aid=3394253&group_id=5665




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/