English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
No unused code linking?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-11-09 (12:43)
From: malc <malc@p...>
Subject: Re: [Caml-list] No unused code linking?
On Wed, 9 Nov 2005, Dmitry Bely wrote:

> malc <malc@pulsesoft.com> writes:
>>> I am thinking of reducing the size of ocamlopt-generated executables that
>>> easily grows to 1Mb and above. The problem as I see it is that any module is
>>> linked as a single whole (as all its functions are placed into the single
>>> object file), no matter what is actually used. So almost all
>>> stdlib/otherlibs become quickly linked into even not very complex project.
>>> In C world there is a solution that lets the linker to do its job smartly
>>> for monolitic object files: place each function into the separate section
>>> (gcc's "-ffunction-sections" or msvc's "-Gy" options) and then ask linker
>>> to eliminate unused sections during the link stage. Can anything similar be
>>> done with Ocamlopt compiler?
>>> Of course, placing each function into the separate section is not a problem -
>>> modifications of the code generator would be minimal. The real problem are
>>> the frame tables - the single table references all functions in the
>>> module. Maybe they can be split and linked separately? What Ocaml
>>> developers think of that?
>> I have played with this idea myself, the problem is not only frametables
>> but also the module header (which more or less contains pointers to all
>> externally visible(don't take my word on it, been a while, might as well
>> be ALL) symbols.
> IMHO, each header item can be placed into the separate DATA section, so
> it's not the real problem (the frame table is).

No it can not. The moduler header must be contiguous and not rearranged by
linker. In absence of .cmx (and name -> mangled name table) OCaml uses the
header to call functions by position. Thus, as it is now, no part of
header can be eliminated, which in reality means that almost everything,
from linkers perspective, is reachable and can not be removed by 

>> All in all this would require quite an effort in restructuring almost
>> everything. I wouldn't count on it.
> Probably you are right, but I still hope for a miracle :-)

Right rigth, that's exactly what's required