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 C686D7ED5C for ; Tue, 31 Jul 2012 14:17:43 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of georg.martius@web.de) identity=pra; client-ip=194.95.184.44; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="georg.martius@web.de"; x-sender="georg.martius@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of georg.martius@web.de) identity=mailfrom; client-ip=194.95.184.44; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="georg.martius@web.de"; x-sender="georg.martius@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mailhost.mis.mpg.de) identity=helo; client-ip=194.95.184.44; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="georg.martius@web.de"; x-sender="postmaster@mailhost.mis.mpg.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AroGAOzLF1DCX7gs/2dsb2JhbABFiCSxUYEHgmF7FR8BhnGBbAETmiqXdh+KBo82gxwDlluOeYJhgV0 X-IronPort-AV: E=Sophos;i="4.77,682,1336341600"; d="scan'208";a="168671487" Received: from mailhost.mis.mpg.de ([194.95.184.44]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 31 Jul 2012 14:17:43 +0200 Received: from twww.mis.mpg.de (twww.mis.mpg.de [194.95.185.34]) by mailhost.mis.mpg.de (8.13.8/8.13.8) with ESMTP id q6VCHeDm025801 for ; Tue, 31 Jul 2012 14:17:40 +0200 (MEST) Received: from arges.localnet (pcserv1n12.mis.mpg.de [141.5.26.82]) (authenticated bits=0) by twww.mis.mpg.de (8.14.4/8.14.4) with ESMTP id q6VCHgic015976 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 31 Jul 2012 14:17:42 +0200 (MEST) From: Georg Martius To: caml-list@inria.fr Date: Tue, 31 Jul 2012 14:17:45 +0200 Message-ID: <4350198.FKG0AFFZGv@arges> User-Agent: KMail/4.8.4 (Linux/3.2.0-27-generic; KDE/4.8.4; x86_64; ; ) MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-MIS-Check-Sender: OK, relay allowed from this IP.OK, user martius() has authenticated himself with LOGIN. Subject: [Caml-list] Segmentationfault on 64bit when called from C 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