llvm JIT add library to module

不想你离开。 提交于 2019-12-05 14:07:50

You need to teach your JIT engine about other symbols explicitly.

If they are in a dynamic library (dylib, so, dll) then you can just call

sys::DynamicLibrary::LoadLibraryPermanently("path_to_some.dylib")

with a path to the dynamic library.

If the symbols are in an object file or an archive, then it requires a bit more work: you would need to load them into memory and add to the ExecutionEngine using its APIs.

Here is an example for an object file:

std::string objectFileName("some_object_file.o");

ErrorOr<std::unique_ptr<MemoryBuffer>> buffer =
  MemoryBuffer::getFile(objectFileName.c_str());

if (!buffer) {
  // handle error
}

Expected<std::unique_ptr<ObjectFile>> objectOrError =
  ObjectFile::createObjectFile(buffer.get()->getMemBufferRef());

if (!objectOrError) {
  // handle error
}

std::unique_ptr<ObjectFile> objectFile(std::move(objectOrError.get()));

auto owningObject = OwningBinary<ObjectFile>(std::move(objectFile),
                                             std::move(buffer.get()));

executionEngine.addObjectFile(std::move(owningObject));

For archives replace template types ObjectFile with Archive, and call

executionEngine.addArchive(std::move(owningArchive));

at the end.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!