From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 317 invoked by alias); 22 May 2009 02:36:07 -0000 Received: (qmail 305 invoked by uid 22791); 22 May 2009 02:36:06 -0000 X-SWARE-Spam-Status: No, hits=0.3 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from s194.n227.vds2000.com (HELO pioneerwireless.ca) (64.6.227.194) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 22 May 2009 02:35:59 +0000 Received: (qmail 17225 invoked by uid 48); 21 May 2009 22:35:56 -0400 Received: from 24.139.16.66 ([24.139.16.66]) by webmail.pioneerwireless.ca (Horde MIME library) with HTTP; Thu, 21 May 2009 22:35:56 -0400 Message-ID: <20090521223556.den4t7suoccoskc0@webmail.pioneerwireless.ca> Date: Fri, 22 May 2009 02:36:00 -0000 From: "John E. Bossom" To: pthreads-win32@sourceware.org Subject: Re: Static Library Initialization (again?) References: <54b165660806171627i489ec78at85e8576762fe97af@mail.gmail.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable User-Agent: Internet Messaging Program (IMP) H3 (4.1.6) X-IsSubscribed: yes Mailing-List: contact pthreads-win32-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sourceware.org X-SW-Source: 2009/txt/msg00025.txt.bz2 >> Why can't DllMain be used for this? MSDN seems to imply that DllMain >> is called for static libraries >> (http://msdn.microsoft.com/en-us/library/ms682583.aspx): >> "The lpReserved parameter indicates whether the DLL is being loaded >> statically or dynamically." There are two ways you can use a "dynamic library" (i.e. DLL)... Statically link against it's implib and let the loader load it's DLL, or programmatically by name. This has nothing to do with an actual "static library" which is what this topic is about. Second, please beware that simply taking solutions from other open=20=20 source components has the potential to taint the intellectual property=20=20 rights of this open source component. open source doesn't mean free to=20=20 copy... both Google and Boost are released under license and use of=20=20 their code is subject to their respective license terms. pthreads-win32 had chosen to release under the LGPL in order to permit=20=20 use by commercial software in addition to open source projects.=20=20 However, commercial companies can come under fire for using open=20=20 source components with questionable lineage. Some commercial companies=20=20 will not touch an open source component if the maintainer does not=20=20 maintain a list of all contributors and can prove the code base is not=20=20 tainted. Respectfully, John E. Bossom Quoting Ramiro Polla : > Hi, > > On Tue, Jun 17, 2008 at 8:27 PM, Brian Cole wrote: >> It looks like I'm running into the same problem as others. I need to >> distribute a static library with pthreads-win32 included without >> requiring end-users of our library to call any pthreads-win32 specific >> attach or detach code. Based on previous posts to the mailing list it >> looks like the boost library has dealt with this before: >> http://sourceware.org/ml/pthreads-win32/2008/msg00022.html >> >> I also found this bit of code inside the Google performance tools: >> #ifdef _MSC_VER >> >> // This tells the linker to run these functions. >> #pragma data_seg(push, old_seg) >> #pragma data_seg(".CRT$XLB") >> static void (NTAPI *p_thread_callback)(HINSTANCE h, DWORD dwReason,=20=20 >> PVOID pv) >> =A0 =A0=3D on_tls_callback; >> #pragma data_seg(".CRT$XTU") >> static int (*p_process_term)(void) =3D on_process_term; >> #pragma data_seg(pop, old_seg) >> >> #else =A0// #ifdef _MSC_VER =A0[probably msys/mingw] >> >> // We have to try the DllMain solution here, because we can't use the >> // msvc-specific pragmas. >> >> >> #endif =A0// #ifdef _MSC_VER >> >> Any reason pthreads-win32 can't use these same mechanisms to=20=20=20 >> initialize itself? >> >> Why can't DllMain be used for this? MSDN seems to imply that DllMain >> is called for static libraries >> (http://msdn.microsoft.com/en-us/library/ms682583.aspx): >> "The lpReserved parameter indicates whether the DLL is being loaded >> statically or dynamically." >> >> I just looked through boost and found their implementation >> (boost-trunk/libs/thread/src/win32/tss_pe.cpp). Any objection to me >> creating a patch based on this code for pthreads-win32? > > I attached an ugly but working patch for this. I haven't tested > building pthreads with MSVC but the initialization code worked on a > standalone test app. > > I added a new make clean GC-autostatic to build the library. > > make clean GC-static tests pass. I also tested a bit with FFmpeg (but > not extensively). > > I'm sure it can be dramatically improved (comments, documentation, > stress test, etc), but as a start it's good enough. > > Ramiro Polla >