[Mono-dev] small footprint mono / AOT
jonpryor at vt.edu
Wed Aug 24 15:10:02 EDT 2011
On Aug 24, 2011, at 2:03 PM, Jonathan Shore wrote:
> I have somewhat unusual requirements whereby need to have a minimal footprint, native, statically compiled app. (well yes they mostly intersect with embedded applications, but with some further requirements).
These are somewhat conflicting. :-)
The closest/easiest would be to use mkbundle:
This allows you to create a single native binary that contains all app dependencies, e.g.
# hw.exe contains ye normal "Hello, world!" app
$ mkbundle -o hw --deps --static -z hw.exe
$ ldd hw
linux-vdso.so.1 => (0x00007ffffe9a4000)
libz.so.1 => /lib64/libz.so.1 (0x00007fbf887e3000)
libm.so.6 => /lib64/libm.so.6 (0x00007fbf8858c000)
librt.so.1 => /lib64/librt.so.1 (0x00007fbf88383000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fbf8817f000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fbf87f62000)
libc.so.6 => /lib64/libc.so.6 (0x00007fbf87bf5000)
However, it's not without its own limitations:
$ ls -hl hw
-rwxr-xr-x 1 jon users 14M Aug 24 14:56 hw
This could be shrunk by providing your own libmono.a (custom compile), and using a linker to strip out the unneeded parts of mscorlib.dll; mkbundle just copies (and compresses) the assemblies, it doesn't link them to remove unneeded code.
You would also need to do this for each native platform -- Windows, Linux, etc. -- and the Windows mkbundle build is known to have problems (i.e. plan on spending time getting it working). (OS X doesn't even work for me when I just tried it.)
So, it's native, statically compiled, and minimal deps. Additionally, no Mono install or GAC is required. Minimal footprint? Not so much, but you can improve it.
(Improve by how much? For comparison, MonoTouch and Mono for Android apps clock in at a minimum of ~4MB, with no external dependencies, but both use a linker in order to remove unneeded IL.)
> • is System.dll the same as mscorlib.dll (one being mono's and the other MS's)? Or are both of these needed?
They are separate assemblies, with a separate set of types. System.dll in no way duplicates or replaces mscorlib.dll (and vice versa).
Are both needed? It depends on the app. You always need mscorlib.dll, but if you don't reference any types from System.dll, then you don't need it. Most System.IO and most System.Collections types are in mscorlib.dll.
> • is there a tool to build a special trimmed System.dll just to use the classes and descendents used by my application? (I just use basic types + System.Collections + System.IO)
Though I don't know why that page mentions mkbundle support for linking; afaict, mkbundle doesn't support linking assemblies, just bundling them into the native app.
> • are there any dependencies on shared libraries with a libmono.a linkage (on linux and windows)?
Yes, but only libs that come with the OS, e.g. KERNEL32.DLL (LoadLibrary, etc.). See above `ldd` output for Linux dependencies.
> • are there any other files required besides System.dll (and my app dll), once libmono is linked to a host C-based application?
Depends on your app and the assemblies you use. If you use Mono.Posix.dll, you need libMonoPosixHelper.so. I believe System.IO.Compression also depends on an external native lib that you would need to distribute with your app.
> • can an AOT+libmono embedded app run with no gac or specific dependencies, other than System.dll known to be in an arbitrary location?
More information about the Mono-devel-list