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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id 5FD7B7ED5C for ; Tue, 31 Jul 2012 15:11:26 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of anil@recoil.org) identity=pra; client-ip=89.16.177.154; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="anil@recoil.org"; x-sender="anil@recoil.org"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of anil@recoil.org) identity=mailfrom; client-ip=89.16.177.154; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="anil@recoil.org"; x-sender="anil@recoil.org"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@dark.recoil.org) identity=helo; client-ip=89.16.177.154; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="anil@recoil.org"; x-sender="postmaster@dark.recoil.org"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CABvZF1BZELGagWdsb2JhbAArGqhSkUUBARYmJ4IgAQEEATo0CwULCyUhRRIGExKFf4FtAwYKBymyRwMfiTmLSYYpYAOVR4EUkVmBXg X-IronPort-AV: E=Sophos;i="4.77,686,1336341600"; d="scan'208";a="152116499" Received: from recoil.dh.bytemark.co.uk (HELO dark.recoil.org) ([89.16.177.154]) by mail4-smtp-sop.national.inria.fr with SMTP; 31 Jul 2012 15:11:10 +0200 Received: (qmail 20357 invoked by uid 634); 31 Jul 2012 13:11:09 -0000 X-Spam-Level: * X-Spam-Check-By: dark.recoil.org Received: from no-dns-yet.demon.co.uk (HELO [192.168.14.78]) (62.49.66.12) (smtp-auth username remote@recoil.org, mechanism cram-md5) by dark.recoil.org (qpsmtpd/0.84) with ESMTPA; Tue, 31 Jul 2012 14:11:08 +0100 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.0 \(1485\)) From: Anil Madhavapeddy In-Reply-To: <4350198.FKG0AFFZGv@arges> Date: Tue, 31 Jul 2012 14:11:06 +0100 Cc: caml-list@inria.fr Content-Transfer-Encoding: quoted-printable Message-Id: <3E83E531-7394-43A0-A070-0FCE4DD11696@recoil.org> References: <4350198.FKG0AFFZGv@arges> To: Georg Martius X-Mailer: Apple Mail (2.1485) X-Virus-Checked: Checked by ClamAV on dark.recoil.org Subject: Re: [Caml-list] Segmentationfault on 64bit when called from C Interesting; I'm seeing a similar issue that could be to do with the framet= able not being initialised soon enough on OSX Mountain Lion. It only manifests = when recording backtraces in native mode, but I haven't quite had the time to ch= ase it down fully yet. However, the below bug report does show where you can i= nit the frametable earlier to work around the bug. http://caml.inria.fr/mantis/view.php?id=3D5700 -anil On 31 Jul 2012, at 13:17, Georg Martius wrote: > Dear all, >=20 > I experienced a very intricate bug in the 64bit runtime that took me some= days=20 > to nail down. I submitted a bug report #5707.=20 > Here is what I found: When ocaml code is compiled as as a libary and call= ed=20 > from C++ under 64bit I get a broken stack for functions with more than 8= =20 > parameters. I compiled ocaml 3.12.1 version with -fPIC. BTW: everthing wo= rks=20 > fine on 32bit. >=20 > The problem occurs when a function with more than 8 parameters is called.= The=20 > last parameters do have the right value. If afterwards a reference is acc= essed=20 > then a segmentation fault occurs, see the code below. >=20 > Here the code: (in the bug report I also attached a tar file) > ---- m1.ml ------------------ > module M2 =3D struct > let v =3D ref 0;; >=20 > let foo p1 p2 p3 p4 p5 p6 p7 p8 p9 =3D > prerr_endline "start"; > print_endline (string_of_int p1); > print_endline (string_of_int p2); > print_endline (string_of_int p3); > print_endline (string_of_int p4); > print_endline (string_of_int p5); > print_endline (string_of_int p6); > print_endline (string_of_int p7); > print_endline (string_of_int p8); > print_endline (string_of_int p9); > print_endline (string_of_int !v); > prerr_endline "end"; > ;; > end;; >=20 >=20 > let test i : unit =3D > print_endline ("Initialising: " ^ (string_of_int i)); > M2.foo 1 2 3 4 5 6 7 8 9; > ;; >=20 > (* test 10;;*) >=20 > let _ =3D Callback.register "test" test;; > ----- end m1.ml >=20 > ----- interface.c > #include > #include >=20 > #include "interface.h" >=20 > void ocaml_initialize(char** argv){ > caml_main(argv); > } >=20 > void ocaml_test(){ > value* test_pointer =3D caml_named_value("test"); > caml_callback(*test_pointer, Val_int(11)); > } > ------ end interface.c >=20 > ----- interface.h > void ocaml_initialize(char** argv); >=20 > void ocaml_test(); > ----- end interface.h >=20 > You need ocaml to be compiled with -fPIC on order to be able to generate = a=20 > shared libary on 64bit, as written in the INSTALL > ./configure -cc "gcc -fPIC" -aspp "gcc -c -fPIC" >=20 > ocamlopt -o libmytest.so -ccopt -shared interface.c m1.ml > g++ -Wall main.cpp -lmytest -o test > ./test > ---- output: > Initialising: 11 > start > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 70367718054944 > Segmentation fault (core dumped) > --- end outpuyt >=20 > Some Observations: > Calling it natively as an ocaml executable works. > Commenting the access to !v removes the segmentation fault but still the= =20 > values are wrong. > Uncommenting line "test 10", causes the error already at this call and th= e=20 > subsequent call from C runs fine! >=20 > Best regards, > Georg >=20 >=20 > --=20 > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >=20