Evan Burkitt | 18 Nov 23:26

[threads] contention for MSCRT's_pRawDllMain hook in static library

I'm using VS2005 to compile a DLL that links with the MFC DLL and also the static Boost threads library. I've upgraded from Boost v1.34.1 to v1.37 and now the threads library's use of MSCRT's _pRawDllMain hook interferes with MFC's use of the hook to point to its _RawDllMain export. I've come up with a workaround of a library that exports _pRawDllMain and links to _RawDllMain in the MFC DLL and an export I've added to the threads library that calls its dll_callback() function. I just can't get the MS linker to cooperate.

If I put my library ahead of the threads library in the command line the linker complains of a multiply-defined symbol. If I put the threads library ahead of my library the linker uses the threads library _pRawDllMain export and ignores mine. Only if I remove the _pRawDllMain export from the threads library entirely does the linker use mine. I would like to leave the _pRawDllMain export in the threads library so that it will still work in my library's absence but I can't figure out what makes it so attractive to the linker.

I realize this isn't, strictly speaking, a Boost issue, but the problem arose because of a change to Boost and I know there are a lot of smart people here. :)>

-evan

_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Anthony Williams | 19 Nov 00:51

Re: [threads] contention for MSCRT's_pRawDllMain hook in static library

"Evan Burkitt" <eburkitt <at> gmail.com> writes:

> I'm using VS2005 to compile a DLL that links with the MFC DLL and also the
> static Boost threads library. I've upgraded from Boost v1.34.1 to v1.37 and
> now the threads library's use of MSCRT's _pRawDllMain hook interferes with
> MFC's use of the hook to point to its _RawDllMain export. I've come up with
> a workaround of a library that exports _pRawDllMain and links to _RawDllMain
> in the MFC DLL and an export I've added to the threads library that calls
> its dll_callback() function. I just can't get the MS linker to cooperate.

I figured this would conflict with something. I didn't realise it
would be MFC :-(

I use this hook to allow a DLL that is statically linked with
Boost.Thread to correctly clean up thread local data, since Windows
doesn't call the TLS callbacks for DLLs but it *does* call the DLL
entry point.

> If I put my library ahead of the threads library in the command line the
> linker complains of a multiply-defined symbol. If I put the threads library
> ahead of my library the linker uses the threads library _pRawDllMain export
> and ignores mine. Only if I remove the _pRawDllMain export from the threads
> library entirely does the linker use mine. I would like to leave the
> _pRawDllMain export in the threads library so that it will still work in my
> library's absence but I can't figure out what makes it so attractive to the
> linker.

The _pRawDllMain export in Boost.Thread is in the same .obj file as
other code that is needed.

If you move it out from tss_pe.cpp to its own .cpp file it might work.

Anthony
--

-- 
Anthony Williams
Author of C++ Concurrency in Action | http://www.manning.com/williams

Custom Software Development | http://www.justsoftwaresolutions.co.uk
Just Software Solutions Ltd, Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK
Evan Burkitt | 19 Nov 05:36

Re: [threads] contention for MSCRT's_pRawDllMain hook in static library

"Anthony Williams" <anthony.ajw <at> gmail.com> wrote in message 
news:u1vx8lhj0.fsf <at> gmail.com...
> "Evan Burkitt" <eburkitt <at> gmail.com> writes:
>
>> If I put my library ahead of the threads library in the command line the
>> linker complains of a multiply-defined symbol. If I put the threads 
>> library
>> ahead of my library the linker uses the threads library _pRawDllMain 
>> export
>> and ignores mine. Only if I remove the _pRawDllMain export from the 
>> threads
>> library entirely does the linker use mine. I would like to leave the
>> _pRawDllMain export in the threads library so that it will still work in 
>> my
>> library's absence but I can't figure out what makes it so attractive to 
>> the
>> linker.
>
> The _pRawDllMain export in Boost.Thread is in the same .obj file as
> other code that is needed.

Ah! That makes sense.
>
> If you move it out from tss_pe.cpp to its own .cpp file it might work.

It didn't. I put the _pRawDllMain export and the dll_callback() function it 
points to in their own file, but the linker still complained. What does work 
is link's /force:multiple command line switch. This makes my library order 
fiddling work, so I can live with it for now.

Obviously it would be nice to figure out a way to automate the linking. Off 
the top of my head, creating a separate static library for DLLs that use the 
MFC DLL is one solution, with code in dll_callback() inside a #ifdef _AFXDLL 
conditional to pass control to an extern "C" _RawDllMain. Maybe something 
cleverer will come to mind after a night's sleep.

Thanks for your help.

-evan 

Gmane