[MLton] Embedded MLton

Matthew Fluet fluet at tti-c.org
Tue Aug 19 17:04:58 PDT 2008


On Sun, 20 Jul 2008, Wesley W. Terpstra wrote:
> What options can I use to convince MLton to output small executables?
> Ideally I'd like to get hello-world to below 100k. With static linking of
> all but libc/m it is currently 260k.

You can try adjusting the various inlining and code-duplication 
threshholds.  But, that often as much hurts code size, because there is a 
win in trimming unused code paths after inlining.

Also, in a hello-world program, the majority executable will come from the 
libraries (libmlton and libgmp), not from the individual program.  For 
example, on amd64-linux (with libgmp shared):

[fluet at shadow temp]$ cat z.sml
val () = print "Hello world!\n"
[fluet at shadow temp]$ mlton -keep o z.sml
[fluet at shadow temp]$ size z.0.o z.1.o z
    text    data     bss     dec     hex filename
    2465    6136       2    8603    219b z.0.o
   33411      19       0   33430    8296 z.1.o
  122157    7296   10208  139661   2218d z

So approx 66% comes from libmlton.a.  The garbage collector probably 
contributes the most from libmlton.a to the executable.

> I already tried removing all unused symbols from libgmp.a and libmlton.a.
> The benefit was not spectacular, only 40k. libgmp.a already includes each
> function in a separate file so static linking drops all the unneeded
> methods. Similarly, most of the basis wrapper functions are dropped.

Right.  You are left with the garbage collector.  There are some features 
that you might be willing to disable for an embedded system (for example, 
the hash-consing collection is rarely used), but you would need to build a 
customized libmlton.a for that.




More information about the MLton mailing list