如何在基于LLVM MCJIT的JIT中解析当前过程符号? [英] How to resolve current process symbols in LLVM MCJIT based JIT?

查看:123
本文介绍了如何在基于LLVM MCJIT的JIT中解析当前过程符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个基于MCJIT的简单JIT(在Rust中实现万花筒教程精确的).我正在使用SectionMemoryManager :: getSymbolAddress进行符号解析.它可以从库中看到符号(例如sin函数),但无法解析程序中的函数(全局,用nm可见,用T标记).这是预期的行为吗?还是应该在我的代码中出现一些错误?

I'm creating a simple MCJIT based JIT (implementing Kaleidoscope tutorial in Rust to be more precise). I'm using SectionMemoryManager::getSymbolAddress for symbol resolution. It sees symbols from libraries (e.g. sin function), but fails to resolve functions from my program (global, visible with nm, marked there by T). Is this the expected behavior? Or should it be some error in my code?

如果这是预期的行为,那么如何正确解析当前过程中的符号?我现在使用LLVMAddSymbol从过程中添加符号,因此分辨率开始起作用.这是正确的解决方案吗?

If this is the expected behavior, how should I properly resolve symbols from the current process? I'm adding symbols from the process with LLVMAddSymbol now, so resolution starts to work. Is this the right solution?

对于那些会读我代码的人.符号的问题与名称处理无关,因为当我尝试使SectionMemoryManager :: getSymbolAddress工作时,我使用了no_mangle指令,因此它们的命名正确.

For those, who'll read my code. The problem with symbols is not related with the name mangling, as when I tried to make SectionMemoryManager::getSymbolAddress work, I used no_mangle directive, so they were named properly.

推荐答案

感谢Lang Hames,他在其他地方回答了我的问题.如果有人会和我看同样的问题,我会在这里给出答案:

Thanks to Lang Hames, he has answered my question in other place. I cite the answer here for the case if somebody will look at the same problem as me:

回答您的问题:SectionMemoryManager::getSymbolAddress最终(通过RTDyldMemoryManager基类)调用llvm::sys::DynamicLibrary::SearchForAddressOfSymbol,该代码在所有先前加载的动态库中搜索该符号.您可以在JIT初始化过程中调用llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr)(在对getSymbolAddress的任何调用之前)将程序的符号导入到DynamicLibrary的符号表中.

In answer to your question: SectionMemoryManager::getSymbolAddress eventually (through the RTDyldMemoryManager base class) makes a call to llvm::sys::DynamicLibrary::SearchForAddressOfSymbol, which searches all previously loaded dynamic libraries for the symbol. You can call to llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr) as part of your JIT initialisation (before any calls to getSymbolAddress) to import the program's symbols into DynamicLibrary's symbol tables.

如果您真的想将程序中的所有功能公开给JIT代码,这是一个不错的方法.如果您只想公开一组有限的运行时函数,则可以将它们放在共享库中,然后加载它们.

If you really want to expose all functions in your program to the JIT'd code this is a good way to go. If you only want to expose a limited set of runtime functions you can put them in a shared library and just load that.

这篇关于如何在基于LLVM MCJIT的JIT中解析当前过程符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆