Link to Link 6

Posted by Jb Evain Mon, 21 Aug 2006 15:24:00 GMT

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?

Cecil and the Summer Of Code

Posted by Jb Evain Wed, 03 May 2006 19:26:00 GMT

Cecil is a project I started in November 2004. I worked on it’s write support during the Summer 2005, thanks to Google’s Summer Of Code.

During this first Summer Of Code, already one SoC project was using Cecil, and it’s now included in Gendarme

For the Summer Of Code 2006, a the whole set of suggestions about CIL (4 suggestions) requires to use Cecil.

What a promotion for my tool!

Mono and the Compact Framework in Love, Part Two 1

Posted by jbevain Fri, 31 Mar 2006 00:03:14 GMT


Few hours ago, I’ve discovered that in order to allow assemblies compiled on Mono to run over the Compact Framework, we needed to patch the assemblies so they use the public key of the Compact Framework instead of them of the .net framework.

First, I’ve written a patcher that changes in the raw image the references it founds. This solution was somewhat suboptimal because the .net framework uses two public keys, while the Compact Framework use only one.

So I had to write a more complex patcher. This new patcher is using Cecil (it requires a fresh SVN Head to compile), and map every known reference it can to its Compact Framework equivalent. It could be further modified to transform the assembly when needed. For instance, the System.Windows.Forms.DataGrid class is hosted in its own assembly on the Compact Framework. This patcher could create the reference when needed and make the DataGrid points to it.

Yet, I’m not sure it is worth the big effort to create a good patcher.

Mono and the Compact Framework in Love 1

Posted by jbevain Thu, 30 Mar 2006 22:15:49 GMT


Few persons expressed their interest on the mono-devel mailing list about the ability to run assemblies compiled using the Mono runtime over the Compact Framework. Those who tried to run such an assembly know that the program does not start.

I decided to have a look at it tonight. First I thought that Windows CE’s PELoader failed to load assemblies emitted by Mono because the order of a few things inside the .text section of the PE executable where different. Then it appears that the PE file was not the problem. The problem comes from the fact that the public keys used by the .net framework (and thus Mono) to sign the core libraries are different from the ones used for the Compact Framework.

To validate this assumption, I’ve manually modified the public key tokens of a simple windows forms assembly using an hex editor, and I’ve run it over the Compact Framework inside VS.NET 2003’s emulator. And it worked nicely :)

For those who are not willing to make those changes by hand, compilation after compilation, I’ve written a simple assembly patcher that you can find here: Mono Assembly to Compact Framework.

The only side effect of this hack is that Mono will let you compile things using methods that are not included in the Compact Framework, so take care, and have a look at the MSDN to see what you can use.

Update: this is deprecated in favor of a new version of the patcher.

Older posts: 1 ... 8 9 10 11