tags:

views:

208

answers:

3

I wanted to test Mono AOT, so I wrote a simple console application with MonoDevelop:

using System;

namespace abc
{
    public class Program
    {
     public static void Main()
     {
      Console.WriteLine("Hello World!");
     }
    }
}

It created a file named "abc.exe" in bin/debug. When I try to do:

mono abc.exe

it worked. So, I tried to AOT it. I did:

mono --aot abc.exe

it created me a file named abc.exe.so. When I try to start it, it throws an "Segmentation fault (core dumped)" error. Heres the output of mono --aot:

Code: 51 Info: 5 Ex Info: 8 Unwind Info: 31 Class Info: 30 PLT: 2 GOT Info: 11 GOT Info Offsets: 16 GOT: 20 Offsets: 48
Compiled 2 out of 3 methods (66%)
1 methods have other problems (33%)
Methods without GOT slots: 1 (33%)
Direct calls: 0 (100%)
JIT time: 1 ms, Generation time: 0 ms, Assembly+Link time: 0 ms.

How can I fix it?

Thanks.

+1  A: 

What is your environment and Mono version?

AOT only works on x86, x86-64, and ARM, and only on Linux and maybe Mac.

If you are on one of these platforms and on the latest Mono version (2.6) then it sounds like a bug that should probably be filed at http://www.mono-project.com/Bugs.

jpobst
+1  A: 

You shouldn't start the output .so file, just run mono on the original managed .exe and it will pick up the AOT file automatically.

skolima
+1  A: 

What skolima said was right, it is quite odd that he got down-voted.

You are not supposed to use directly the output generated by Mono's AOT compiler.

Mono's AOT compilation is a process that caches the output of JIT compilation and leaves it in a shared library that is loaded by the Mono runtime on demand. The .so file that is generated contains the pre-compiled code and the metadata necessary to be consumed by the runtime.

To use the AOT file, you just invoke your program like this:

mono program.exe

Mono will load the metadata from program.exe and probe for the existence of a program.exe.so to avoid doing just-in-time compilation at runtime, and instead use the code from the .so file. The same process is applied to any libraries referenced.

Even Mono's full static compilation mode produces code that requires the original .exe file to be present.

If what you wanted to achieve was a native executable, you could try the mkbundle command which packages the Mono runtime and your program into a single executable.

miguel.de.icaza