[llvm-dev] Have LLD load a file through memory (original) (raw)
Frank Winter via llvm-dev llvm-dev at lists.llvm.org
Thu Aug 12 14:21:47 PDT 2021
- Previous message: [llvm-dev] [Job Ad] HPE Cray Compiling Environment: Compiler Optimization Engineer
- Next message: [llvm-dev] Have LLD load a file through memory
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi.
I'm trying to use LLD to get it's input file from a string in memory instead of a file.
My use case is a JIT compiler (IR --> AMD GCN ISA) where calling the linker to make it a loadable object via system() is hitting a bug (somewhere in the system).
Here's what I do:
- With the AMDGPU backend I write the output to a string
- I sneak in this string into LLD via an added access function.
- Since LLD invocation is only used in this form: ld.lld -shared k.o -o k.so I modified 'elf::readFile' to
std::string tmp = qdp_jit_get_object(); // this retrieves the sneaky string
llvm::outs() << "size = " << tmp.size() << "\n";
std::unique_ptr mb = MemoryBuffer::getMemBuffer( StringRef( tmp.c_str() , tmp.length() ) );
MemoryBufferRef mbref = mb->getMemBufferRef();
return mbref;
When I then call LLD via lld:🧝:link, I get
size = 2192 ld: error: :1: unknown directive:
A�E�A�E�@���?V@���?V�3��������}j<������� �J�0�ւ���j� ^
This is how the string containing the object was created:
string str_obj; llvm::raw_string_ostream rss(str_obj); llvm::buffer_ostream bos(rss);
if (TargetMachine->addPassesToEmitFile(CodeGenPasses, bos, nullptr, llvm::CodeGenFileType::CGFT_ObjectFile ))
CodeGenPasses.run(*Mod);
Is there anything wrong how I turn the string into a MemoryBuffer so that the link fails?
Thanks, Frank
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210812/94c4ae50/attachment.html>
- Previous message: [llvm-dev] [Job Ad] HPE Cray Compiling Environment: Compiler Optimization Engineer
- Next message: [llvm-dev] Have LLD load a file through memory
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]