public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Problems using a DLL with Cygwin 64 bit
@ 2015-12-17 11:00 Philip Taylor
  2015-12-17 12:43 ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Philip Taylor @ 2015-12-17 11:00 UTC (permalink / raw)
  To: cygwin

Environment:
Windows 7 (64 bit)
Cygwin 64 bit
GCC version: 4.9.3

To make use of a Prosilica camera, I am having to build applications using an 
externally supplied DLL (from the camera manufacturer, with no source code) in 
Cygwin64 and Cygwin32.  I am using the appropriate 32 or 64 bit version of the DLL, 
as supplied.

The most difficult problem encountered is when using Cygwin 64 bit. I was initially 
unable to link but, using pexports and dlltool, I managed to create a .lib file with 
which I linked OK. This got rid of the initial link failure message "error adding 
symbols: File in wrong format."

But having linked successfully, the application now crashes on startup:

$ ../../bin/cygwin-x86_64/prosilicaApp.exe
   6 [main] prosilicaApp (96896) 
C:\cygwin64\home\EPICS\R3.14.12.5\modules\areaDetector\2-2\ADProsilica\2-1\iocs\prosilicaIOC\bin\cygwin-x86_64\prosilicaApp.exe: 

*** fatal error - cygheap base mismatch detected - 0x1802FA400/0x6EA400.
This problem is probably due to using incompatible versions of the cygwin DLL.
Search for cygwin1.dll using the Windows Start->Find/Search facility
and delete all but the most recent version.  The most recent version *should*
reside in x:\cygwin\bin, where 'x' is the drive on which you have
installed the cygwin distribution.  Rebooting is also suggested if you
are unable to find another cygwin DLL.
Segmentation fault

The reference to cygwin DLL in the long error message appears spurious - there is 
only one cygwin DLL in my system and there are no problems running other Cygwin 
applications in the same environment.

I have tried with 2 different versions of the manufacturer's DLL. The same error 
occurs, but with different addresses shown in the "mismatch detected" message.

The error does not occur with a 32 bit Cygwin installation.

Any idea why this error is occurring only with 64 bit Cygwin?

Philip Taylor

(Observatory Sciences Ltd)

--
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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems using a DLL with Cygwin 64 bit
  2015-12-17 11:00 Problems using a DLL with Cygwin 64 bit Philip Taylor
@ 2015-12-17 12:43 ` Corinna Vinschen
  0 siblings, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2015-12-17 12:43 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 3067 bytes --]

On Dec 17 11:00, Philip Taylor wrote:
> Environment:
> Windows 7 (64 bit)
> Cygwin 64 bit
> GCC version: 4.9.3
> 
> To make use of a Prosilica camera, I am having to build applications using
> an externally supplied DLL (from the camera manufacturer, with no source
> code) in Cygwin64 and Cygwin32.  I am using the appropriate 32 or 64 bit
> version of the DLL, as supplied.

I take it you simply linked against the Cygwin DLL?  You're not trying
to load the Cygwin DLL at runtime dynamically?  All bets are off in the
latter case.

> The most difficult problem encountered is when using Cygwin 64 bit. I was
> initially unable to link but, using pexports and dlltool, I managed to
> create a .lib file with which I linked OK. This got rid of the initial link
> failure message "error adding symbols: File in wrong format."

Linking against the externally supplied DLL you mean?  I hope you didn't
create another link lib for Cygwin...

> But having linked successfully, the application now crashes on startup:
> 
> $ ../../bin/cygwin-x86_64/prosilicaApp.exe
>   6 [main] prosilicaApp (96896) C:\cygwin64\home\EPICS\R3.14.12.5\modules\areaDetector\2-2\ADProsilica\2-1\iocs\prosilicaIOC\bin\cygwin-x86_64\prosilicaApp.exe:
> 
> *** fatal error - cygheap base mismatch detected - 0x1802FA400/0x6EA400.
> This problem is probably due to using incompatible versions of the cygwin DLL.
> Search for cygwin1.dll using the Windows Start->Find/Search facility
> and delete all but the most recent version.  The most recent version *should*
> reside in x:\cygwin\bin, where 'x' is the drive on which you have
> installed the cygwin distribution.  Rebooting is also suggested if you
> are unable to find another cygwin DLL.
> Segmentation fault
> 
> The reference to cygwin DLL in the long error message appears spurious -
> there is only one cygwin DLL in my system and there are no problems running
> other Cygwin applications in the same environment.

It is spurious in this case.  The Cygwin DLL is supposed to be located
at address 0x180040000.  The cygheap location is dependend on that since
it's immediately attached to the DLL.  It appears that, after either
forking or execing the application, the Cygwin DLL gets loaded to an
address 0x600000 or something like that.  Why this happens, I have no
idea.  Off the top of my head it points to a few possible reasons:

- The externally supplied DLL has been loaded to the 0x180000000 range.
  In that casse you should rebase it to an address which does not
  collide with other Cygwin DLLs.  An address < 0x80000000 or
  > 0x7FF000000000 would make sense.

- The externally supplied DLL has loaded data to an address in
  the 0x180000000 range, which would be weird, but is possible.

- Your application has been built with ASLR enabled.  Remove the flag
  (peflags -d0 your_app.exe) and try again.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems using a DLL with Cygwin 64 bit
  2015-12-18 14:11 Philip Taylor
  2015-12-18 14:42 ` Eliot Moss
@ 2015-12-18 15:34 ` Corinna Vinschen
  1 sibling, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2015-12-18 15:34 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2173 bytes --]

On Dec 18 14:11, Philip Taylor wrote:
> 
> Thank you for the reply. My situation is this: I was supplied Windows 32-bit
> and 64-bit .dll and .lib files by the manufacturer, which I believe were
> created using MS Visual Studio. These are to enable me to use the API for
> this camera from my software.
> 
> Building using GCC tools with cygwin, my initial attempt at linking with
> this API library failed with the message : "error adding symbols: File in
> wrong format.".
> 
> I then discovered that by creating and using a new .lib file for this API
> DLL, using the pexports and dlltools utilities, I could get the link to
> succeed.
> 
> Then (under 64 bit Cygwin) I got the message "*** fatal error - cygheap base
> mismatch detected".

Yeah, that's what I was trying tro explain in my first reply.  Did you
see the three potential problems I outlined?  You'll have to debug what
the actual problem is.

> What exactly did you mean by "You're not trying to load the Cygwin DLL at
> runtime dynamically?". I am trying to build this application under Cygwin in
> the same way as many others, which all run OK,

The Cygwin DLL is the core DLL providing the POSIX environment
(/usr/bin/cygwin1.dll).  If you build a normal application under Cygwin,
you link against the Cygwin DLL the usual way and that's fine.  "at
runtime dynamically" means, your application is a native, non-Cygwin
binary and you try to load the Cygwin DLL at runtime via the Windows
call LoadLibrary (kind of like dlopen()).  Given your description that's
not the case for you, so nothing to worry about.  Just ignore this.

But that gives me an idea.  Assuming you don't link against this camera
DLL, but rather use dlopen/dlsym to fetch and use the entry points to
that DLL, does it work then?  That would be another thing you could try.

But I assume there's something simple going on.  Try if one of my
other points give a clue.  You could also run your applications under
strace or GDB...


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems using a DLL with Cygwin 64 bit
  2015-12-18 14:11 Philip Taylor
@ 2015-12-18 14:42 ` Eliot Moss
  2015-12-18 15:34 ` Corinna Vinschen
  1 sibling, 0 replies; 5+ messages in thread
From: Eliot Moss @ 2015-12-18 14:42 UTC (permalink / raw)
  To: cygwin

On 12/18/2015 9:11 AM, Philip Taylor wrote:
>
> Thank you for the reply. My situation is this: I was supplied Windows 32-bit and 64-bit .dll and
> .lib files by the manufacturer, which I believe were created using MS Visual Studio. These are to
> enable me to use the API for this camera from my software.
>
> Building using GCC tools with cygwin, my initial attempt at linking with this API library failed
> with the message : "error adding symbols: File in wrong format.".
>
> I then discovered that by creating and using a new .lib file for this API DLL, using the pexports
> and dlltools utilities, I could get the link to succeed.
>
> Then (under 64 bit Cygwin) I got the message "*** fatal error - cygheap base mismatch detected".
>
> What exactly did you mean by "You're not trying to load the Cygwin DLL at runtime dynamically?". I
> am trying to build this application under Cygwin in the same way as many others, which all run OK,

If you have a Windows native DLL, you might do better using MinGW and its tools rather than Cygwin,
though Cygwin experts may be able to clarify this point.

Regards -- Eliot Moss

--
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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems using a DLL with Cygwin 64 bit
@ 2015-12-18 14:11 Philip Taylor
  2015-12-18 14:42 ` Eliot Moss
  2015-12-18 15:34 ` Corinna Vinschen
  0 siblings, 2 replies; 5+ messages in thread
From: Philip Taylor @ 2015-12-18 14:11 UTC (permalink / raw)
  To: cygwin


Thank you for the reply. My situation is this: I was supplied Windows 32-bit and 
64-bit .dll and .lib files by the manufacturer, which I believe were created using 
MS Visual Studio. These are to enable me to use the API for this camera from my 
software.

Building using GCC tools with cygwin, my initial attempt at linking with this API 
library failed with the message : "error adding symbols: File in wrong format.".

I then discovered that by creating and using a new .lib file for this API DLL, using 
the pexports and dlltools utilities, I could get the link to succeed.

Then (under 64 bit Cygwin) I got the message "*** fatal error - cygheap base 
mismatch detected".

What exactly did you mean by "You're not trying to load the Cygwin DLL at runtime 
dynamically?". I am trying to build this application under Cygwin in the same way as 
many others, which all run OK,


Philip Taylor


--
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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-12-18 15:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-17 11:00 Problems using a DLL with Cygwin 64 bit Philip Taylor
2015-12-17 12:43 ` Corinna Vinschen
2015-12-18 14:11 Philip Taylor
2015-12-18 14:42 ` Eliot Moss
2015-12-18 15:34 ` Corinna Vinschen

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).