Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Executable size?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@o...>
Subject: Re: [Caml-list] Executable size?
On Sun, 2003-11-16 at 02:01, John J Lee wrote:
> On Sat, 16 Nov 2003, skaller wrote:
> [...]
> > A very large number of people do in fact build C all the
> > time without any runtime library at all: embedded systems
> > typically don't use any runtime.
> 
> When you say "runtime", do you mean stuff like libc.so, or libgcc.a, or
> both?

Neither, crt0 is the key. It isn't a library, but initialisation
code.

> When, if ever, can you avoid linking with libgcc.a (or its equivalent)?
> What do you lose by not linking with it?

You cannot make a traditional 'main' program without some
runtime support. This does things like pass command line
arguments to 'main'. It also sets up registers for the
generated code. For example on the x86 it is common
to set all the segment registers equal. The startup
code may also set up the floating point unit, signal
handlers, etc.

However, no 'library' code is ever required by ISO C
programs unless you actually call the functions or
refer to some variable. Still, if you consider
say 'errno', evil as it is, you might refer to it
even if you never do any file IO, so it had better
be correctly initialised.

Finally, even if you don't do IO, something like
an 'assert' macro might, so perhaps *some* initialisation
of some thing might be done in case you use them,
with the compiler not really knowing if it is necessary or not.

In C++, some initialisation for exception handling, RTTI,
and other stuff may be needed .. even if you don't use it,
it may be included *in case* you use it. In particular,
this may be necessary if you dynamically link to a shared
library that does use these features, and they're global
and have to be set up on startup (RTTI and exception handling
spring to mind here ..)

Even on embedded systems, there is usually initialisation
code, though it is often hand written by the client 
(in assembler).

Finally, there is a special case where you must NOT
use a runtime library, even on a hosted machine.

And that is when bootstrapping the compiler and compiling
the run time :-)

> I don't ask for any practical reason, just to try and sort out how O'Caml,
> C and C++ differ here.

Well, for Ocaml the gc must be set up. In addition, signal and
thread handling might have to be initialised. Perhaps some
data such as command line arguments is fetched by startup
code, whether or not you actually try to access it.

The principal difference between Ocaml and C is that
C is designed to be able to generate things like Linux
kernels, and you certainly don't want to use the standard C
library doing that: you're trying instead to build particular
machine code in a 'high level way', and need to actually
write all the functions you need yourself... since it is
this kernel that actually provides some of the resources
accessed by user space C libraries :-)

Ocaml doesn't try to be a systems programming language,
that's the difference.


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners