From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
To: cygwin@cygwin.com
Subject: Re: Problem with differences with DLOPEN / DLSYM compared to ubuntu (16.04) / debian (stretch).
Date: Thu, 21 Sep 2017 05:53:00 -0000 [thread overview]
Message-ID: <ae56ae3c-e0ec-9a83-f94c-5242ad43e75c@SystematicSw.ab.ca> (raw)
In-Reply-To: <374c9eed-e6bf-76c6-ffc3-cec5c97116a5@dronecode.org.uk>
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 <iostream>
> #include <memory>
> #include <dlfcn.h>
>
> 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
next prev parent reply other threads:[~2017-09-21 5:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-15 1:15 Kaz Kylheku
2017-09-15 13:51 ` Gary Schneir
2017-09-15 16:07 ` cyg Simple
2017-09-15 16:59 ` Jon Turney
2017-09-21 5:53 ` Brian Inglis [this message]
2017-09-21 0:11 ` Kaz Kylheku
-- strict thread matches above, loose matches on Subject: below --
2017-09-14 15:45 Gary Schneir
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ae56ae3c-e0ec-9a83-f94c-5242ad43e75c@SystematicSw.ab.ca \
--to=brian.inglis@systematicsw.ab.ca \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).