This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Bug with dlopen() and fork()
- From: Jaime Fabregas Fernandez <jaime dot fabregas at tarlogic dot com>
- To: cygwin at cygwin dot com
- Date: Thu, 20 Feb 2014 14:16:44 +0100
- Subject: Re: Bug with dlopen() and fork()
- Authentication-results: sourceware.org; auth=none
- References: <CAMzR4E7ngKr5HN=QEZXLUuy0VxGbD_xDN7UaTKPmfbmmD8Bz0A at mail dot gmail dot com>
Hello Corinna,
As you've checked, this behaviour doesn't appear with dll's created by
gcc, but it does with Visual Studio C++.
That minimal example compiled with VS will result in the freeze of the
child process.
================ testlib.h ======================
#ifdef TESTLIB_EXPORTS
#define TEST_API extern "C" __declspec(dllexport)
#else
#define TEST_API extern "C" __declspec(dllimport)
#endif
TEST_API int mylib_open (const char *foo);
=============================================
=============== testlib.cpp ======================
#include "stdafx.h"
#include "testLib.h"
int
mylib_open (const char *foo)
{
return 1;
}
==============================================
I've tested several compiler and linker options with same result.
Any ideas?
> On Feb 19 14:38, Jaime Fabregas Fernandez wrote:
>> Library references loaded by a process using dlopen() and dlsym() are
>> no more valid in child processes after running a fork(). Calls from
>> child process will never return.
>>
>> I've searched for a similar problem in the mailing lists and found
>> this unanswered thread from 2001:
>>
>> http://cygwin.com/ml/cygwin/2001-02/msg01225.html
>>
>>
>> I'm running cygwin64. This behaviour can be checked with the following
>> test program:
>>
>> ========================================================
>> #include <stdio.h>
>> #include <dlfcn.h>
>>
>> int (*myopen)(const char *);
>>
>> main(){
>> void *handle;
>> int ret;
>> handle = dlopen("my_lib.dll", RTLD_LAZY);
>> myopen = dlsym(handle, "mylib_open");
>>
>> if( ! fork() ){
>> ret = myopen("");
>> printf("This printf never shows, call to myopen will
>> block for ever\n");
>> }
>> else{
>> ret = myopen("");
>> printf("%i\n", ret);
>> sleep(1);
>> }
>> }
>> ========================================================
>>
>> Same program runs correctly (showing the two printf's) in a Linux environment.
>
> Works for me with 64 bit Cygwin. I used this as DLL:
>
> $ cat > my_lib.c <<EOF
> int
> mylib_open (const char *foo)
> {
> return 1;
> }
> $ gcc -shared -o my_lib.dll my_lib.c
> $ gcc -g -o my_tst my_tst.c <- That's your above testcase
> $ uname -a
> CYGWIN_NT-6.3 vmbert8164 1.7.28(0.271/5/3) 2014-02-04 16:01 x86_64 Cygwin
> $ ./my_tst
> 1
> This printf never shows, call to myopen will block for ever
> $
>
>
> Corinna
>
> --
> Corinna Vinschen Please, send mails regarding Cygwin to
> Cygwin Maintainer cygwin AT cygwin DOT com
> Red Hat
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple