From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id B9B55BB9C for ; Wed, 16 Nov 2005 02:55:11 +0100 (CET) Received: from ash25e.internode.on.net (ash25e.internode.on.net [203.16.214.182]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jAG1t972025996 for ; Wed, 16 Nov 2005 02:55:10 +0100 Received: from rosella (ppp7-104.lns1.syd7.internode.on.net [59.167.7.104]) by ash25e.internode.on.net (8.12.9/8.12.6) with ESMTP id jAG1t3aE096499; Wed, 16 Nov 2005 12:25:04 +1030 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Re: [Caml-list] bytecode apps without stdlib/pervasives From: skaller To: Jonathan Roewen Cc: caml-list@yquem.inria.fr In-Reply-To: References: Content-Type: text/plain Date: Wed, 16 Nov 2005 12:55:02 +1100 Message-Id: <1132106102.9002.50.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 437A917D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 bytecode:01 stdlib:01 pervasives:01 exn:01 compiler:01 ocaml:01 stdlib:01 ocamlc:01 -nostdlib:01 binary:01 flags:01 -nostdlib:01 pervasives:01 flags:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Wed, 2005-11-16 at 11:45 +1300, Jonathan Roewen wrote: > Hi, > > I have a simple ML file (test.ml): > > external raise : exn -> 'a = "%raise";; > > raise End_of_file;; > > so I can check how the compiler does things (like if predefined ocaml > symbols are still present without stdlib present), and compile as: > > ocamlc -nostdlib -nopervasives test.ml, which generates a.out. > > when I run it, I get error: "-bash: ./a.out: cannot execute binary > file" (btw, generates expected behabiour without those flags) > > why can't it execute it? can we only use -nostdlib as long as we > provide our own pervasives module? You need to link in the C startup code manually, and pass whatever flags are need to the linker to tell it how to make an executable. My system has: /usr/lib/gcc/x86_64-linux-gnu/4.0.2/crtbegin.o /usr/lib/gcc/x86_64-linux-gnu/4.0.2/crtbeginS.o /usr/lib/gcc/x86_64-linux-gnu/4.0.2/crtbeginT.o /usr/lib/gcc/x86_64-linux-gnu/4.0.2/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.0.2/crtendS.o /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtn.o /usr/lib/gcrt1.o /usr/lib/Mcrt1.o /usr/lib/Scrt1.o here you can see the unresolved external 'main': skaller@rosella:/work/felix/flx$ nm /usr/lib/crt1.o 0000000000000000 D __data_start 0000000000000000 W data_start 0000000000000000 R _IO_stdin_used U __libc_csu_fini U __libc_csu_init U __libc_start_main U main 0000000000000000 T _start Exactly how the linker 'marks' a generated binary 'executable' I don't know -- just linking in the startup/termination code may not be enough. >>From my ld manpage: OPTIONS The linker supports a plethora of command-line options, but in actual practice few of them are used in any particular context. For instance, a frequent use of ld is to link standard Unix object files on a standard, supported Unix system. On such a system, to link a file "hello.o": ld -o /lib/crt0.o hello.o -lc This tells ld to produce a file called output as the result of linking the file "/lib/crt0.o" with "hello.o" and the library "libc.a", which will come from the standard search directories. (See the discussion of the -l option below.) Note of course all this is for starting up C or C++ programs. How Ocaml works is a mystery .. :) -- John Skaller Felix, successor to C++: http://felix.sf.net