Mono AOT 分段错误 - 奇怪的问题

发布于 2024-08-16 06:05:32 字数 867 浏览 5 评论 0 原文

我想测试 Mono AOT,所以我用 MonoDevelop 编写了一个简单的控制台应用程序:

using System;

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

它在 bin/debug 中创建了一个名为“abc.exe”的文件。当我尝试这样做时:

mono abc.exe

它成功了。所以,我尝试AOT它。我这样做了:

mono --aot abc.exe

它为我创建了一个名为 abc.exe.so 的文件。当我尝试启动它时,它会抛出“分段错误(核心转储)”错误。这是 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.

我该如何修复它?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

回眸一笑 2024-08-23 06:05:32

斯科利马说的是对的,他被否决了,这很奇怪。

您不应该直接使用 Mono 的 AOT 编译器生成的输出。

Mono 的 AOT 编译是一个缓存 JIT 编译输出并将其保留在共享库中的过程,该共享库由 Mono 运行时按需加载。生成的 .so 文件包含预编译的代码和运行时使用所需的元数据。

要使用 AOT 文件,您只需像这样调用程序:

mono program.exe

Mono 将从 program.exe 加载元数据并探测 program.exe.so 是否存在,以避免在运行时进行即时编译,而是使用 .so 文件中的代码。相同的过程适用于引用的任何库。

即使 Mono 的完全静态编译模式生成的代码也需要原始 .exe 文件存在。

如果您想要实现的是本机可执行文件,您可以尝试 mkbundle 命令,它将 Mono 运行时和您的程序打包成单个可执行文件。

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.

此生挚爱伱 2024-08-23 06:05:32

您不应该启动输出 .so 文件,只需在原始托管 .exe 上运行 mono,它就会自动获取 AOT 文件。

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.

小忆控 2024-08-23 06:05:32

你的环境和Mono版本是什么?

AOT 仅适用于 x86、x86-64 和 ARM,并且仅适用于 Linux,也许还有 Mac。

如果您使用的是这些平台之一并且使用的是最新的 Mono 版本 (2.6),那么这听起来像是一个错误,应该在 http://www.mono-project.com/Bugs

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文