[mercury-users] why the executable file (hello) takes 1.2 Mbs?

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Jun 22 18:28:38 AEST 2001

On 21-Jun-2001, Vladimir L. Korobkov <korobkov at alarnet.com> wrote:
> I've installed Mercury 0.10.1, the installation has been done succesfully.
> In order to test it, I've started the following program:
> %>mmc  hello.m  (to  get  the  Hello World string to the terminal, very
> small size source file hello.m)
> Everything was OK and I've got the executable hello file.
> The question is why the executable file (hello) takes 1.2 Mbs?
> I have:
> Solaris 8 (x86);
> gcc-2.95.3
> GNU make 3.79.1

Firstly I should note that we do a lot better on other platforms;
part of the problem here is just that Solaris/x86 is not a commonly
used platform and so we haven't optimized things as well on that
platform as we have on others.

The size is due to the whole of the Mercury standard library being
linked into your executable.

There's several things which can be done to avoid this.
The one which would have the most impact is to use dynamic linking,
so that the standard library is not included in your executable.
On several platforms, e.g. Solaris/SPARC, the Mercury compiler
does this by default.  There's a little bit of code in configure.in
which determines whether or not to enable dynamic linking and
what options etc. need to be passed to the C compiler to support it.
Enabling support for dynamic linking on Solaris/x86 might be as simple
as adding a case for *86-*-solaris* and using the same code there
as is used for sparc-sun-solaris*.  Or something different might be needed.
I'm not sure.

Another thing that can be done is to build the standard library with
`--split-c-files'.  This ensures that only those parts of the standard
library which are actually referenced by your application will be linked in.
The INSTALL file describes how to do this:

#          If Mercury does not support shared libraries on your system,
#          you may want to use the command `mmake install_split_library' to
#          build and install a version of the Mercury libraries using the
#          `--split-c-files' option to avoid linking in unused procedures.
#          This can reduce the size of a hello world executable from ~400k
#          to ~120k.  (The only reason this is not the default is that
#          installing the split libraries takes quite a long time.  As a
#          compromise, the command `mmake install_split_library LIBGRADES='
#          will install a split version of the library just for the
#          default grade.)

P.S. You should also try running `strip' and/or `strip --strip-unneeded'
(the latter requires GNU strip, which is part of GNU binutils) on the
executable.  That may reduce the size.  But I think that on Solaris
the Mercury compiler should normally do `strip' by default.

Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list