Problems linking a program which uses __declspec( thread ) as a DLL

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

I have a program which uses thread local storage which is allocated
with __declspec( thread ).

If I link it one way everything is fine, the program starts up and
runs properly. If I change the set of .obj's being linked to either
produce a DLL or swap in a different main() function, I get the
following errors:

myprog.obj(dzz.obj) : error LNK2014: TLS relative fixup overflow; .tls
section ('_b_dzlog') is too large
myprog.obj(dzz.obj) : error LNK2014: TLS relative fixup overflow; .tls
section ('_b_dzlog') is too large
myprog.obj(dzz.obj) : error LNK2014: TLS relative fixup overflow; .tls
section ('_b_dzlog') is too large
myprog.obj(dzz.obj) : error LNK2014: TLS relative fixup overflow; .tls
section ('_b_dzlog') is too large
LINK : fatal error LNK1165: link failed because of fixup errors

While the error message here seems obvious, the tls section
is too large, the link map shows that the TLS is less than 32KB.
(cf
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/LNK2014.asp)

From the link map:
Start Length Name Class
0004:00000000 00000001H .tls DATA
0004:00000004 0000007cH .stls DATA
0004:00000080 00001370H .tls$ DATA
0004:000013f0 00000001H .tls$ZZZ DATA

This is on Windows XP using the C compiler from
Visual Studio .NET 2003.

C:\>cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

The following builds without error:
cl /nologo main.obj sdir.obj myprog.obj mylib.obj -o myprog -Fmmyprog.map
msvcrt.lib advapi32.lib kernel32.lib ws2_32.lib winspool.lib clusapi.lib
resutils.lib psapi.lib mypro.res
-link /pdb:myprog.pdb /pdbstripped:myprogstripped.pdb /ltcg /nologo
/release /debug /nodefaultlib:libc.lib

In the above list, main.obj, sdir.obj and mylib.obj are all single
C files.

myprog.obj is created from:
lib /nologo /ltcg /OUT:myprog.obj <large list of .obj files>

The errors occur if I change the link command by either:

a) remove main.obj and add /DLL and /DEF:<.def> file
b) replace main.obj with 'newmain.obj' where newmain.obj has
a main() and some other code. main.c is just a call to the main
entry point in the program to provide a default .exe.
 
Back
Top