X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:reply-to:subject:to:references:from:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=XZ27jbhNZCST5Lhc w7iwHY5aFq2NxpfwWS4t2dtc+TMlA76npSbLVj1amZHGPbQczAbaYFE7CfK4ggdh /90Dpst2GyC6gUZ1zRdLHTjNz5uLwzyqsCtBL4fdm2HO97l0QzhgUnHcqn4vsehb 8iApes9m9SBsDOQV6GUrt09h4gA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:reply-to:subject:to:references:from:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=MadW4WpD4KF1NIJzRL6jfJ SmWnQ=; b=nQRoRspHTO6syrgFRmrkXwyPXL07I0c2vAqIvQq6FAwTAxZ2+5NGiA jowR7CfPOlQDQO5j0i5EowIxindwPSq4s09m9V/u/xeBz2/1A2RkX1/DJBkkIQux aT0XTlBQMfIyePdsquuCZqL6Vdba8U05yBTvKFDbrHy2UvpWhEHpo= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=H*R:D*ca, rude, H*r:ip*192.168.1.100, his X-HELO: smtp-out-no.shaw.ca X-Authority-Analysis: v=2.2 cv=a+JAzQaF c=1 sm=1 tr=0 a=MVEHjbUiAHxQW0jfcDq5EA==:117 a=MVEHjbUiAHxQW0jfcDq5EA==:17 a=IkcTkHD0fZMA:10 a=mDV3o1hIAAAA:8 a=q9qNZd-tvjV1Kgmlg6AA:9 a=QEXdDO2ut3YA:10 a=_FVE-zBwftR9WsbkzFJk:22 Reply-To: Brian DOT Inglis AT SystematicSw DOT ab DOT ca Subject: Re: Problem with differences with DLOPEN / DLSYM compared to ubuntu (16.04) / debian (stretch). To: cygwin AT cygwin DOT com References: <94ac1558-0d01-2325-5a91-92e8b867a5bd AT gmail DOT com> <374c9eed-e6bf-76c6-ffc3-cec5c97116a5 AT dronecode DOT org DOT uk> From: Brian Inglis Message-ID: Date: Wed, 20 Sep 2017 23:53:21 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <374c9eed-e6bf-76c6-ffc3-cec5c97116a5@dronecode.org.uk> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfGlrkBaDfIubhQ/D86nYwWfL+/ql5/4vHCAgnpIqBh+ePWUk6nMcKTsRkbFFcleMxcWXbKJS5FL1f1qzjNquqU9YysNNf46Tq1z5Tb4A2YQzTHpV2CS8 ENO3HqovU7iXbAs8H3COT5i97+hTfSuAlw0nFZkILaOrghPzmuQNH/faFR546ajuR6NvQX71DOrKfQ== X-IsSubscribed: yes Note-from-DJ: This may be spam On 2017-09-15 10:59, Jon Turney wrote: > On 15/09/2017 17:07, cyg Simple wrote: >> Please consider using an interleaving method of posting on this list. >> Top posting is considered rude. >> >> On 9/15/2017 9:51 AM, Gary Schneir wrote: >>> Thanks for the response but I am a little confused by it.  If Cygwin is >>> supposed to provide POSIX API functionality and DLOPEN / DLSYM are >>> supported in CYGWIN, then I shouldn't care about the underlying >>> complexity or restrictions of running within the Windows environment and >>> using DLLs.  The behavior should be the same as in other POSIX environments. >> >> You presented your case well and I was waiting on someone familiar with >> the code to respond.  I'm not sure that would be Kaz, he was just trying >> to be helpful from his experiences.  I agree with your surmise that >> Cygwin should perform similar results as Linux in this case. > > ... > >>> If you are saying that I did not include some sort of >>> __declspec(dllexport) directive in my code so that it can find my >>> symbols, that is something else but you indicate that you think cygwin >>> hides that complexity in shared libraries. >> >> Actually it would be binutils, regardless of Cygwin or MinGW, that is >> trying to hide the complexity of needing to supply the >> __declspec([export|import]) declarations.  The logic for that is a bit >> confusing but if none is given then all symbols are exported. > > You need to decorate the symbols you wish to be visible with '__attribute__ > ((dllexport))' or '__declspec(dllexport)' (MSVC syntax which is also supported > by gcc) > > See [1] for an example of this done portably > > [1] https://gcc.gnu.org/wiki/Visibility > > Alternatively, you can use the ld flag --export-all-symbols (cf. with the ELF > option --export-dynamic, which I think you must be using to get the observed > behaviour on linux) to make all symbols visible. > > Taking your example, and making it compilable: > > $ cat dlopen.cc > #include > #include > #include > > void * handle, * symbol; > const char * errorStr; > > int main() > { >   /* get access to the executable's symbol table */ >   handle = dlopen(NULL, RTLD_LAZY); >   errorStr = dlerror(); > >   if (errorStr) >     { >       std::clog << "dlopen error '" << errorStr << "'" << std::endl; >     } >   if (handle) >     { >       std::clog << "handle ok " << std::endl; >     } >   else >     { >       std::clog << "handle NULL " << std::endl; >     } > >   /* look up the from_string function */ >   symbol = dlsym(handle, "functionname"); >   errorStr = dlerror(); > >   if (symbol) >     { >       std::clog << "dlsym symbol ok " << std::endl; >     } >   else >     { >       std::clog << "dlsym symbol NULL " << std::endl; >     } >   if (errorStr) >     { >       std::clog << "dlsym error '" << errorStr << "'" << std::endl; >     } > } > > extern "C" __attribute__ ((dllexport)) > void functionname() > { > } > > $ g++ dlopen.cc -o dlopen > > $ ./dlopen > handle ok > dlsym symbol ok No really comparable as the OP example was in a .dll/.so. You would have to make your main e.g test, build into a dll, and call from a separate main program. The issue appears to be that dlopen( NULL, ...) should work as if it was a reference to the dll containing the call, not the main program. -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada -- 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