Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: "Bauer, Christoph" <Christoph.Bauer@lms-gmbh.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] OCaml-3.08.1/MinGW: alloc_tuple fails
Date: Fri, 15 Oct 2004 17:04:12 +0200	[thread overview]
Message-ID: <20041015150412.GA9521@yquem.inria.fr> (raw)
In-Reply-To: <D981925B4F2CD611870300E0184CEE9B0157F303@kaiserslautern1.lms-gmbh.de>

> A program (from the OCam'Ole package) segfaults in a alloc_tuple call.
> This behavior is shown only with native compilation.

There have been many theories on what could be wrong in the C
function you showed.  However, I believe the problem comes from the
way you link it with the native code produced by ocamlopt:

> gcc -mno-cygwin -c -shared -O  -mms-bitfields -DCAML_DLL -DDLL=1 -I
> c:/ocamlmgw/lib test.cpp -D_DEBUG -g
> gcc -shared -mno-cygwin -mms-bitfields -I C:/ocamlmgw/lib -o dlltest.dll
> -Wl,--out-implib,libtest.a test.o c:/ocamlmgw/lib/ocamlrun.a

By linking with the import library ocamlrun.a, you bind your C code to
the bytecode Caml runtime system.  Any program that links with
dlltest.dll will cause ocamlrun.dll to be loaded, and your test.c code
will use the alloc_tuple() function from ocamlrun.dll.

This is fine if you later use dlltest.dll with an ocamlc-compiled
program, since the latter also uses ocamlrun.dll as its runtime
system.

This is wrong if you use dlltest.dll with an ocamlopt-compiled
program, as in

    ocamlopt -ccopt dlltest.dll -ccopt -g -o test_it.exe test_it.ml

since the latter is statically linked with a different runtime system
(libasmrun.a, the native-code runtime system).  You get two different
runtime systems that don't "speak" to each other.

So, there is no way you can use the same DLL with both bytecode and
native-code.  

You should however be able to compile your test.c code to a static
library (libtest.a).  This static lib is not pre-bound to a particular
version of the runtime system.  So,

   ocamlc -custom .... libtest.a

will link everything with the bytecode runtime system, and

   ocamlopt ... libtest.a

will link everything with the native-code runtime system.

More generally speaking, given the way Windows DLLs work, I don't
think it is possible at all to put Caml-C stub code in a DLL and pass
that DLL to ocamlopt.  Static linking is your friend here.

- Xavier Leroy

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2004-10-15 15:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-14 13:23 Bauer, Christoph
2004-10-15 13:20 ` Damien Doligez
2004-10-15 13:45   ` Olivier Andrieu
2004-10-15 14:49     ` Damien Doligez
2004-10-16 23:56       ` Erik de Castro Lopo
2004-10-15 15:04 ` Xavier Leroy [this message]
2004-10-14 14:59 AW: " Bauer, Christoph
2004-10-14 16:19 ` Richard Jones

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=20041015150412.GA9521@yquem.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=Christoph.Bauer@lms-gmbh.de \
    --cc=caml-list@inria.fr \
    /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