From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 02E917ED5C for ; Tue, 31 Jul 2012 16:29:41 +0200 (CEST) X-IronPort-AV: E=Sophos;i="4.77,686,1336341600"; d="scan'208";a="168686982" Received: from estephe.inria.fr (HELO [128.93.11.95]) ([128.93.11.95]) by mail1-relais-roc.national.inria.fr with ESMTP; 31 Jul 2012 16:29:40 +0200 Message-ID: <5017EBD4.9080904@inria.fr> Date: Tue, 31 Jul 2012 16:29:40 +0200 From: Xavier Leroy User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: caml-list@inria.fr References: <4350198.FKG0AFFZGv@arges> <1343739554.17140.423.camel@thinkpad> <4123447.LCvNL5nQdx@arges> In-Reply-To: <4123447.LCvNL5nQdx@arges> X-Enigmail-Version: 1.5pre Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Segmentationfault on 64bit when called from C On Tuesday 31 July 2012 14:59:14 Gerd Stolpmann wrote: > The -shared switch generates a library that is prepared to be loaded > with Dynlink. Dynlink registers the frametable. You're right that .so libraries produced by -shared should only be used in conjunction with Dynlink. However, in this case the frame table isn't the culprit, as the crash occurs before the GC even has a chance to run. On 07/31/2012 04:03 PM, Georg Martius wrote: > ocamlopt -output-obj -o camlcode.o interface.c m1.ml > gcc -fPIC -g -Wall -c -I/usr/local/lib/ocaml interface.c > gcc -fPIC -o test main.c camlcode.o interface.o -L/usr/local/lib/ocaml -lunix > -lm -lasmrun -ldl > > works, but > ocamlopt -o libmytest.so -output-obj interface.c m1.ml > gcc -Wall main.c -lmytest -o test > does not! Is it clear why it doesn't work? See my comments on PR#5707. In the latter case, the dynamic loader is invoked and trashes registers r10 and r11, which ocamlopt uses to pass arguments to your "foo" function. We'll have to come up with a better choice of parameter registers. > So I get away with static linking for now. Please do if at all possible. ocamlopt was designed for static linking, and the relatively recent addition of dynamic linking support isn't completely mature yet. - Xavier Leroy