What do you mean, linking? 7

Posted by Jb Evain Fri, 08 Jun 2007 21:25:00 GMT

According to my blog, it’s been 24 days that I’ve joined the Mono Team at Novell, and I haven’t yet blogged about what I am doing there.

Appart from a week in Seattle with Rodrigo and Miguel, where we’ve been attending a Compiler Lab hosted by Microsoft, I’ve been mainly working on the linker.

The linker is something Miguel wants to have since quite a bit of time, as one can find references to it on his blog in posts that are almost three years old. Thanks to the Google Summer of Code 2006, I started working on it.

To make it short, here is a definition of what a linker is, here is the definition extracted from its page on the Mono wiki:

The linker is a tool one can use to only ship the minimal possible set of functions that a set of programs might require to run as opposed to the full libraries.
Writing a linker is not very hard. It’s basically a mark and sweep operation, but the mark operation have to be very intrusive, and you have to dig in every piece of metadata so you don’t forget any type, or any methods. Plus, there is also a few types in the BCL that are used inside the runtime (like StackOverflowException for instance), and some of them with a field layout that is tied to an unmanaged representation in the runtime (AppDomain for instance). That makes it very easy to forget something.

But today, after much fighting, I managed to have a non-trivial application working after a complete linking of itself and the base class library. This application is now famous, and have been used by thousands of users to test if their own application could be run of Mono. You’ve recognized MoMa. It maybe looks like a simple application, but it uses stuff like System.Windows.Forms, System.Web.WebServices or even Mono.Cecil to do its job. And all it all, it’s not that simple, believe me.

So, here is a little table where I’ve gathered some data about the size of the assemblies referenced by MoMa, before, and after having ben linked:
before after assembly
---------------------------------------
  9K  5.5K  Accessibility.dll
129K   34K  ICSharpCode.SharpZipLib.dll
 40K   24K  MoMA.Analyzer.dll
 44K   33K  MoMA.exe
350K  277K  Mono.Cecil.dll
 70K  5.0K  Mono.Data.Tds.dll
172K   15K  Mono.Posix.dll
282K  7.5K  Mono.Security.dll
2.4M  1.9M  mscorlib.dll
115K   75K  System.Configuration.dll
778K  354K  System.Data.dll
1.4M  679K  System.dll
429K  201K  System.Drawing.dll
 45K  6.5K  System.EnterpriseServices.dll
129K  7.5K  System.Security.dll
 26K  6.5K  System.Transactions.dll
1.9M  676K  System.Web.dll
342K   88K  System.Web.Services.dll
2.9M  1.8M  System.Windows.Forms.dll
1.2M  834K  System.Xml.dll
----------
 13M    7M
So for the MoMa case, it’s almost a reduction of half the size of the binaries needed to run it. Pretty good heh?

That’s really convenient for people who embed Mono for the sake of running their own application. By using the linker, they can ship with only what they need to run their application.

Next time, I’ll tell you about some limitations of the linker, and the solution to get over them.

Trackbacks

Use the following link to trackback from your own site:
http://evain.net/blog/articles/trackback/408

  1. Linker and mkbundle From Duff show
    Linker is a beautiful tool build by JB based on Cecil lib. It inspect assembly to get what external call is used and reduce all assembly to have the smaller one. The best friend application of linker is mkbundle which can ship all assembly/exe in ...
Comments

Leave a response

  1. Avatar
    Bertrand Le Roy Fri, 08 Jun 2007 22:18:56 GMT

    Tu passes une semaine Ă Seattle sans t’arrĂȘter boire un cafĂ© avec les français du coin? Tss.

  2. Avatar
    German Viscuso Sat, 09 Jun 2007 00:00:48 GMT

    Hi Jb!

    Nice job. You need to capitalize the last A in the MoMA link for it to work otherwise it’s a broken link.

    Best regards!

    German

  3. Avatar
    Marcos Meli Sat, 09 Jun 2007 04:50:37 GMT

    Excellent Work =)

    I was just begining with Cecil and I said:

    “What about open an EXE, and remove the Types in all the reference assemblies that are not used” :P

    And later I enter your blog to know if there is a way to found dependences, and walla, and article about a linker, very funny to me, maybe because Im drinking wine too :P

    GREAT WORK DUDE YOU LIBRARY ROCKS !!

    There is any reason to dont have some XML comments ?? I can help a bit using GhostDoc to generate at least some docs

    See ya Open Source Developer http://www.filehelpers.com

  4. Avatar
    onur Sat, 09 Jun 2007 13:13:07 GMT

    How this is different from mkbundle and will we be able to link on windows too ? You know, since gnome now ships with mono, usually embedding mono is not a serious concern. But we really need some stuff in windows cause not every windows has .net/mono runtime within.

  5. Avatar
    she Sat, 09 Jun 2007 21:06:32 GMT

    This sounds promising, maybe not only for embedded usage but to anyone who likes to have (and keep) things small and lean :)

  6. Avatar
    IG Sun, 10 Jun 2007 19:38:55 GMT

    after linking my app, do I still need to mkbundle it to make it run natively ?

  7. Avatar
    duff Mon, 11 Jun 2007 10:30:34 GMT

    The linker is beautiful. Alan have use it to reduce the size of MonoTorrent and it is amazing.

    Hope you will continue to work on it ;) It is a useful tool to avoid the install of any framework (.NET or mono). It is super when it is used with mkbundle…

Comments