Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mono AOT Segmentation Fault - Strange Problem

Tags:

c#

mono

aot

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.

like image 771
Alon Gubkin Avatar asked Dec 25 '09 23:12

Alon Gubkin


3 Answers

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.

like image 149
miguel.de.icaza Avatar answered Oct 11 '22 06:10

miguel.de.icaza


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.

like image 40
skolima Avatar answered Oct 11 '22 08:10

skolima


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.

like image 20
jpobst Avatar answered Oct 11 '22 07:10

jpobst