caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Paul Steckler <steck@stecksoft.com>
To: caml-list@yquem.inria.fr
Subject: Re: Segfaults with Dynlink with OCaml 3.11
Date: Wed, 25 Aug 2010 14:00:30 +1000	[thread overview]
Message-ID: <AANLkTinxtK-ScwAHUyZ7-UVPtKVFtu0FYFrjo5UraiZo@mail.gmail.com> (raw)
In-Reply-To: <AANLkTin6GWH+Csz4QLVbfs4M7=+zD8PCNgfKwMDfT9_v@mail.gmail.com>

On Mon, Aug 23, 2010 at 8:57 PM, Paul Steckler <steck@stecksoft.com> wrote:
> I'm getting segmentation faults when using dynamically linked native
> code in 64-bit OCaml 3.11 running on Linux (Fedora 12 x64).

Many thanks to all who gave useful advice on tracking down this problem.

We have three chunks of C code we're calling, so we went through those
and audited our use of the FFI conventions.  Indeed, we found a number
of instances where we used return instead of CAMLreturn, and so on.

But the segfaults were occurring before our C code was ever called,
and before any code was called in OCaml packages we use that are
linked against C code, such as sqlite3.  So the segfaults occurred
even after patching our C code.

Today, I found the culprit.  Here's the pattern:

   dynamically load .cmxs file
   query list mutated by .cmxs file      (* no problem *)
   Gc.set { (Gc.get()) with Gc.minor_heap_size         = ...};
   Gc.set { (Gc.get()) with Gc.major_heap_increment = ... };
   query mutated list   (* segfault! *)

If I move the Gc.set's to the program initialization code, before the
loading of dynamic code, no segfaults occur.

Is this expected behavior?  I don't see caveats about interaction with
the garbage collector in the documentation for the Dynlink module, nor
anything about dynamic linking in the Gc module documentation.

-- Paul


  parent reply	other threads:[~2010-08-25  4:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-23 10:57 Paul Steckler
2010-08-23 11:06 ` [Caml-list] " Stéphane Glondu
2010-08-23 11:47   ` Paul Steckler
2010-08-23 12:05     ` Mark Shinwell
2010-08-23 12:12       ` Paul Steckler
2010-08-23 12:15         ` Daniel Bünzli
2010-08-23 12:28         ` Anil Madhavapeddy
2010-08-23 15:48         ` Stéphane Glondu
2010-08-25  4:00 ` Paul Steckler [this message]
2010-09-03 14:59   ` [Caml-list] " Damien Doligez

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=AANLkTinxtK-ScwAHUyZ7-UVPtKVFtu0FYFrjo5UraiZo@mail.gmail.com \
    --to=steck@stecksoft.com \
    --cc=caml-list@yquem.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;
as well as URLs for NNTP newsgroup(s).