public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
To: cygwin@cygwin.com
Subject: Re: Using cygwin-dll with msvc-exe
Date: Fri, 26 Jun 2020 11:32:03 -0600	[thread overview]
Message-ID: <56b93fc2-1a64-4d53-5ce5-5038b263d251@SystematicSw.ab.ca> (raw)
In-Reply-To: <00a401d64b9c$9958e6d0$cc0ab470$@gmail.com>

On 2020-06-26 03:31, Kristian Ivarsson via Cygwin wrote:
> Our task is to use an own cygwin-gcc-dll imported and used in a msvc-exe
> (64-bit-system)
> According to https://cygwin.com/faq.html#faq.programming.msvc-gcc-objects it
> seems like it would be possible by doing it like
> https://cygwin.com/cygwin-ug-net/dll.html
> The msvc-exe compiles and links with no problems, but crashes during start
> up in runtime (as soon as there are any reference to the (extern "C")
> functions in the DLL (they aren't even called))
> We're linking agains the import .lib and using implicit loading (i.e. no
> LoadLibrary)
> The console output is:
> ...
>    $ /cygdrive/c/Repos/Trunk/Debug64/my_msvc_program.exe
>          0 [main] my_msvc_program (17392) child_copy: cygheap read copy
> failed, 0x180343408..0x18036E1D8, done 0, windows pid 17392, Win32 error 6
>        582 [main] my_msvc_program (17392)
> C:\Repos\Trunk\Debug64\my_msvc_program.exe: *** fatal error - ccalloc would
> have returned NULL
> ...
> A snippet from strace output is:
> ...
>      193    5437 [main] my_msvc_program (12608) fhandler_pipe::create:
> CreateFile: name \\.\pipe\cygwin-e022582115c10879-12608-sigwait
>      198    5635 [main] my_msvc_program (12608) fhandler_pipe::create: pipe
> write handle 0x130
>      171    5806 [main] my_msvc_program (12608) dll_crt0_0: finished
> dll_crt0_0 initialization
>    --- Process 12608 thread 2084 created
>     1050    6856 [sig] my_msvc_program (12608) wait_sig: entering ReadFile
> loop, my_readsig 0x12C, my_sendsig 0x130
>    --- Process 12608, exception c0000005 at 00000004a9e3b012
> ...
> I guess I'm experiencing the same issue as
> https://stackoverflow.com/questions/25787344/using-dll-compiled-with-cygwin-
> inside-visual-studio-2010 (it is using explicit loading of the DLL though)
> Just linking the dll works fine, but as soon as a symbol is referenced, it
> seems like the linker/loader make things end up in a weird way. The only odd
> thing I can see is that the loader (ldd) finds our dll before cygwin1.dll
> and thus our own dll is loaded before cygwin.dll
> So, should it be possible to use cygwin-gcc-built-dll:s in msvc-built-exe:s
> (or msvc-built-dll:s) ? If so, does anyone have a qualified idea of what
> might be missing/wrong in what we're doing ?

They have incompatible internal startup and runtime environments including stuff
like initialization, signal, and exit function handling (cygwin/newlib/gcc vs
Windows/APIs/VC) although Cygwin can build Windows-loadable dlls and
Windows-runnable exes and call Windows (system) dlls that don't depend on msvcrt.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in IEC units and prefixes, physical quantities in SI.]

  parent reply	other threads:[~2020-06-26 17:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-26  9:31 sten.kristian.ivarsson
2020-06-26 17:13 ` Andrey Repin
2020-06-30  7:19   ` Sv: " sten.kristian.ivarsson
2020-06-26 17:32 ` Brian Inglis [this message]
2020-06-30  7:15   ` sten.kristian.ivarsson
2020-06-30 14:45     ` Brian Inglis

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=56b93fc2-1a64-4d53-5ce5-5038b263d251@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).