Link to Link 6
Thanks to everyone who asked, I’m not dead. Well, not yet.
This year, I’m again involved in Google’s Summer of Code, working for the Mono project on the CIL Linker. A CIL Linker? What’s that? According to this page, here is a definition:
The idea is to create a “linker” for assemblies in Mono. The goal is to only ship the minimal possible set of functions that a set of programs might require to run as opposed to the full libraries.
So this “linker” is now working, more or less. You can find the code in the module /cecil/linker of Mono’s SVN.
If ever you want to try to compile it from the sources, you’ll have to checkout the lib module also, as it contains the library Cecil that I use to manipulate the assemblies that have to be linked.
Let me show you what it can do. Let’s link the linker!
porte:/tmp/linker jbevain$ ls -l total 856 -rwxr-xr-x 1 jbevain jbevain 395776 Aug 21 13:03 Mono.Cecil.dll -rwxr-xr-x 1 jbevain jbevain 38912 Aug 21 13:03 linker.exe porte:/tmp/linker jbevain$ mono linker.exe Mono CIL Linker linker [options] -x|-a file --about About the Mono CIL Linker --version Print the version number of the Mono CIL Linker -out Specify the output directory, default to . -p Preserve the core libraries, true or false, default to true -x Link from an XML descriptor -a Link from an assembly you have to choose one from -x and -a but not both porte:/tmp/linker jbevain$ mono linker.exe -out linker_only -a linker.exe porte:/tmp/linker jbevain$ ls -l linker_only/ total 8232 -rw-r--r-- 1 jbevain wheel 364032 Aug 21 13:12 Mono.Cecil.dll -rwxr-xr-x 1 jbevain wheel 1068544 Aug 21 13:12 System.Xml.dll -rwxr-xr-x 1 jbevain wheel 760320 Aug 21 13:12 System.dll -rwxr-xr-x 1 jbevain wheel 38912 Aug 21 13:12 linker.exe -rwxr-xr-x 1 jbevain wheel 1975296 Aug 21 13:12 mscorlib.dll
So, what happened here is that the linker linked itself, plus third parties libraries, but without touching to the core. This could be useful to reduce the size of an application. But another goal of the linker is to create the really minimal set of assemblies in used. So let’s link the core also!
porte:/tmp/linker jbevain$ mono linker.exe -out linker_core -a linker.exe -p false porte:/tmp/linker jbevain$ ls -l linker_core/ total 4792 -rw-r--r-- 1 jbevain wheel 364032 Aug 21 13:15 Mono.Cecil.dll -rw-r--r-- 1 jbevain wheel 552448 Aug 21 13:15 System.Xml.dll -rw-r--r-- 1 jbevain wheel 117248 Aug 21 13:15 System.dll -rwxr-xr-x 1 jbevain wheel 38912 Aug 21 13:15 linker.exe -rw-r--r-- 1 jbevain wheel 1372672 Aug 21 13:15 mscorlib.dll
Et voilĂ , the core has been linked as well. Watch the size of the assemblies! Now what about using this linked linker! I’ll keep it simple for the moment, let’s link a simple hello world using this new linker:
porte:/tmp/linker/linker_core jbevain$ export MONO_PATH="/tmp/linker/linker_core/" porte:/tmp/linker/linker_core jbevain$ mono linker.exe -out hello -a hello.exe porte:/tmp/linker/linker_core jbevain$ cd hello porte:/tmp/linker/linker_core jbevain$ export MONO_PATH="/tmp/linker/linker_core/hello" porte:/tmp/linker/linker_core/hello jbevain$ ls hello.exe mscorlib.dll porte:/tmp/linker/linker_core/hello jbevain$ mono hello.exe Hello World!
Pretty cool huh? I ever you want to give it a try and link the core, you have to know that you’re going to face some bugs, due to the fact that I modify the corlib. But heh, that’s a good start for the linker isn’t it?
Trackbacks
Use the following link to trackback from your own site:
http://evain.net/blog/articles/trackback/201

so cooool. Just a small question when a core dll use an esternal dll, what linker do?
For example , I have a winform hello word. It will reduce size of system.winform.dll but what will be done about libgdi+ ?
duff: it will link every assembly needed by your application. System.Windows.Forms.dll references libgdi+? Then libgdi+ will be linked as well.
this is exciting news! is it possible to link required code of depencies into the new assembly? it would also be cool if the linked assembly would be a single native ELF file, that includes everything needed, from monoruntime over new linked code to metadata.
d: no, it’s not possible to merge assemblies for the moment, but we could imagine that at some point, the linker could do that.
Concerning the native part of the linking, please have a look at:
http://tirania.org/blog/archive/2004/Dec-01.html
Cool huh? :)
This is VERY, VERY, cool. Great work!
I’m curious is the linker mono specific or can it be used on the MS Framework also?
Nick: Thanks!
Actually the linker can be used on the .net framework, but there is two problems:
- we loose strong names during the link, so as we don’t have the private key of the framework, we can’t resign them. - I don’t know any way to tell the .net framework to use the new core libraries, except to write a new CLR host… And the first problem is the blocker.
So the linker on .net is only useful to strip down third party libraries.