Boost logo

Boost :

Subject: [boost] [thread] Any way to avoid creating the .tls section on Windows
From: Rush Manbert (rush_at_[hidden])
Date: 2010-08-27 11:23:01

Yet another bizarre question... (the easy ones have all been answered by now)

This is a Windows-specific question.

We build a dll that is loaded with the LoadLibrary function. Indirectly (through a third-party library), that dll links against the boost thread library.

For reasons that I won't go into, the existence of the .tls section in the resulting binary is problematic for us. I looked at the code and found this comment inside the file tss_pe.cpp:

            //The following line has an important side effect:
            //if the TLS directory is not already there, it will
            //be created by the linker. In other words, it forces a tls
            //directory to be generated by the linker even when static tls
            //(i.e. __declspec(thread)) is not used.
            //The volatile should prevent the optimizer
            //from removing the reference.

I'm not much of a Windows guy and I currently don't understand what is going on in tss_pe.cpp. I did a search of the boost sources and I don't find __declspec(thread) used anywhere, which was encouraging.

I'm wondering two things:

1) Why does the code force a .tls section to be created, even when static tls is not being used?

2) If we know that static tls is not used in any of the code, is it safe to remove the .tls section from the PE file? (We know a lot about manipulating PE files, so definitely know how to do this.)

We have experimented with removing the .tls section by hand and running the dll, and everything seems to work, but I'm really hoping that Anthony Williams might take pity on me and provide some information.


Boost list run by bdawes at, gregod at, cpdaniel at, john at