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 C71107ED5C for ; Tue, 31 Jul 2012 14:58:22 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=pra; client-ip=212.227.17.9; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=mailfrom; client-ip=212.227.17.9; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of postmaster@moutng.kundenserver.de designates 212.227.17.9 as permitted sender) identity=helo; client-ip=212.227.17.9; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="postmaster@moutng.kundenserver.de"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai0CAJnVF1DU4xEJk2dsb2JhbABFhXizfSIBAQEBCQkoAySCIQEFI1YQCxoCJgICVwYTCYYIggAHqGqTX4EhiiiFd4ESA41CiRmER40TgV0 X-IronPort-AV: E=Sophos;i="4.77,686,1336341600"; d="scan'208";a="152115051" Received: from moutng.kundenserver.de ([212.227.17.9]) by mail4-smtp-sop.national.inria.fr with ESMTP; 31 Jul 2012 14:58:22 +0200 Received: from office1.lan.sumadev.de (dslb-094-219-223-014.pools.arcor-ip.net [94.219.223.14]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0MY28S-1TI8ir0MPA-00Uwso; Tue, 31 Jul 2012 14:58:21 +0200 Received: from [192.168.5.106] (dslb-094-219-223-014.pools.arcor-ip.net [94.219.223.14]) by office1.lan.sumadev.de (Postfix) with ESMTPSA id C1438C00D1; Tue, 31 Jul 2012 14:58:20 +0200 (CEST) From: Gerd Stolpmann To: Georg Martius Cc: caml-list@inria.fr In-Reply-To: <4350198.FKG0AFFZGv@arges> References: <4350198.FKG0AFFZGv@arges> Content-Type: text/plain; charset="UTF-8" Date: Tue, 31 Jul 2012 14:59:14 +0200 Message-ID: <1343739554.17140.423.camel@thinkpad> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:swfIKy2uo42EEQnBk4Z7sz1/GjEWPqJTYrSSdECvDuk bkL1nyuoppKAxUVBhXGBvaRsOMsZilmIs3JGrfzH0iDoClPeCH j/pMR4zsPmU+HfU8OA9dvnW1rPhMBZdRvzWe1lG3acNqlMcQnv w0XkjkDrTu/xlRdd4/73PqFYlCf0EOByl8wW/nJqZCLgqVCTes VNu+jQoiHgNYHpRsFXj4th9kND6x3L54bZbG1f25xPUDKV2Rnz eFlYDIH2AvTNdHGJ9dcAHBno/+LFmZOoRiRjtuazVXqC6ySM+b yMYOD97Utfn6BbE8F2zpoenb8WIjjT0hoCyk/53rI7zeUjWKFO S4voP++KAKomZQEkdqfzOHujVnA7lw4ZzY3lOm8t1 Subject: Re: [Caml-list] Segmentationfault on 64bit when called from C Just a rough guess: The frametable is not initialized. Quite funny that it crashes so quickly. (Maybe more is not initialized, maybe the heap register, so it crashes at the first allocation.) You cannot just link Ocaml code without adding the frametable. This is a description of how the stack and the CPU registers are used at runtime. If it is missing the OCaml runtime thinks that the Ocaml code is C code, and applies the wrong conventions. The -shared switch generates a library that is prepared to be loaded with Dynlink. Dynlink registers the frametable. You should consider using -output-obj to create a library that can be loaded without such tricks (see section 18.7.5 of the Ocaml manual). Gerd Am Dienstag, den 31.07.2012, 14:17 +0200 schrieb Georg Martius: > Dear all, > > I experienced a very intricate bug in the 64bit runtime that took me some days > to nail down. I submitted a bug report #5707. > Here is what I found: When ocaml code is compiled as as a libary and called > from C++ under 64bit I get a broken stack for functions with more than 8 > parameters. I compiled ocaml 3.12.1 version with -fPIC. BTW: everthing works > fine on 32bit. > > The problem occurs when a function with more than 8 parameters is called. The > last parameters do have the right value. If afterwards a reference is accessed > then a segmentation fault occurs, see the code below. > > Here the code: (in the bug report I also attached a tar file) > ---- m1.ml ------------------ > module M2 = struct > let v = ref 0;; > > let foo p1 p2 p3 p4 p5 p6 p7 p8 p9 = > 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;; > > > let test i : unit = > print_endline ("Initialising: " ^ (string_of_int i)); > M2.foo 1 2 3 4 5 6 7 8 9; > ;; > > (* test 10;;*) > > let _ = Callback.register "test" test;; > ----- end m1.ml > > ----- interface.c > #include > #include > > #include "interface.h" > > void ocaml_initialize(char** argv){ > caml_main(argv); > } > > void ocaml_test(){ > value* test_pointer = caml_named_value("test"); > caml_callback(*test_pointer, Val_int(11)); > } > ------ end interface.c > > ----- interface.h > void ocaml_initialize(char** argv); > > void ocaml_test(); > ----- end interface.h > > You need ocaml to be compiled with -fPIC on order to be able to generate a > shared libary on 64bit, as written in the INSTALL > ./configure -cc "gcc -fPIC" -aspp "gcc -c -fPIC" > > 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 > > Some Observations: > Calling it natively as an ocaml executable works. > Commenting the access to !v removes the segmentation fault but still the > values are wrong. > Uncommenting line "test 10", causes the error already at this call and the > subsequent call from C runs fine! > > Best regards, > Georg > > -- ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de Creator of GODI and camlcity.org. Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de *** Searching for new projects! Need consulting for system *** programming in Ocaml? Gerd Stolpmann can help you. ------------------------------------------------------------