[MLton] Embedded MLton

Adam Goode adam at spicenitz.org
Fri Jul 25 10:54:55 PDT 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.
> 
> 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.
> 
> 

Hi,

This seems quite interesting.

There are two things I could think of worth trying:

1. Compile mlton with -ffunction-sections and -fdata-sections, then link 
with --gc-sections (gcc option is -Wl,--gc-sections). This may save 
space or may even bloat space, but it is worth investigating. Also, try 
compiling everything with -Os. It is also worth seeing if mlton's 
invocation of gcc can be safely augmented with these options. Finally, 
look into the -combine and -fwhole-program gcc options.

2. Make libmlton a dynamic library. You'll get no benefit if you are 
installing only 1 program, but it will start to pay off after installing 
a few. You can try this without too much hassle for testing, and if it 
becomes useful, only later look into the ABI issues of having a 
persistent libmlton installed on a system. (For your embedded device, 
this probably won't matter.) I'd be interested in having a shared 
libmlton on Fedora, since it makes executables smaller and makes various 
gdb and debugging things easier (separate debuginfo packages don't work 
with static libraries).

Both of these techniques can work with each other, and may both give 
benefits. One more thing, if you try the dynamic library route, making a 
proper set of function exports and using hidden visibility will probably 
lead to even more benefit. http://gcc.gnu.org/wiki/Visibility


Looking forward to your results!


Thanks,

Adam


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
Url : http://mlton.org/pipermail/mlton/attachments/20080725/fad10b5f/signature.pgp


More information about the MLton mailing list