| Issue |
52940
|
| Summary |
Trying to add an object file into the LLVM JIT [Execution Engine]
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
MuhammedElsaid
|
Trying to add an object file that was generated from a module into the execution engine. The execution engine runs another module which access this module's object file
theModule->setTargetTriple(sys::getDefaultTargetTriple());
std::string Error;
auto Target = TargetRegistry::lookupTarget(TargetTriple, Error);
if (!Target) {
errs() << Error;
return 1;
}
auto CPU = "generic";
auto Features = "";
TargetOptions opt;
auto RM = Optional<Reloc::Model>(Reloc::Static);
TargetMachine* TheTargetMachine = Target->createTargetMachine(TargetTriple, CPU, Features, opt, RM, None, CodeGenOpt::Level::Aggressive);
theModule->setDataLayout(TheTargetMachine->createDataLayout());
std::error_code EC;
std::string fullPath = path
.append(".o");
raw_fd_ostream dest(fullPath, EC, sys::fs::OF_None);
if (EC) {
errs() << "Could not open file: " << EC.message();
return 1;
}
legacy::PassManager pass;
if (TheTargetMachine->addPassesToEmitFile(pass, dest, nullptr, CGFT_ObjectFile)) {
errs() << "TheTargetMachine can't emit a file of this type";
return 1;
}
pass.run(*theModule);
dest.flush();
ErrorOr<std::unique_ptr<MemoryBuffer>> buffer =
MemoryBuffer::getFile(fullPath .c_str());
if (auto error = buffer.getError()) {
// handle error
printf("Error %s\n", error.message().c_str());
exit(1);
}
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()));
EE->addObjectFile(std::move(owningObject));
The Exception:
**/llvm-project/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp:300: void llvm::RuntimeDyldELF::resolveX86_64Relocation(const llvm::SectionEntry &, uint64_t, uint64_t, uint32_t, int64_t, uint64_t): Assertion `(Type == ELF::R_X86_64_32 && (Value <= UINT32_MAX)) || (Type == ELF::R_X86_64_32S && ((int64_t)Value <= INT32_MAX && (int64_t)Value >= INT32_MIN))' failed.**
Running LLVM-13git
Ubuntu 20.04.3 LTS (GNU/Linux 4.4.0 x86_64)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs