[LLVMdev] load bytecode from string for jiting problem

Willy WOLFF willy.wolff at etu.unistra.fr
Thu Mar 13 07:02:25 PDT 2014


Hello,

I having a weird problem while writing a bytecode module to a string,
and after read/parse it for unsing on a jit.

I write a pass to export function to module, and put this module inside
a global variable.
I use WriteBitcodeToFile for this.
For debuging, after this write, I try to load the exported module with
parseBitcodeFile.
This two step works.



After, while the compiled program is running, I try to read and parse
this global variable for jiting the function.

1) I read the global variable with
  StringRef sr (gv, gv_length);

2) I manually test this bytecode by
(inspired by  inline bool isRawBitcode(const unsigned char *BufPtr,
const unsigned char *BufEnd) at
http://llvm.org/docs/doxygen/html/ReaderWriter_8h_source.html#l00067)
  if (sr.str()[0] == 'B')
    std::cout << "B ok\n";
  if (sr.str()[1] == 'C')
    std::cout << "C ok\n";
  if (sr.str()[2] == (char) 0xc0)
    std::cout << "0xc0 ok\n";
  if (sr.str()[3] == (char) 0xde)
    std::cout << "0xde ok\n";

3) I try to parse the gv by
  MemoryBuffer* mbjit = MemoryBuffer::getMemBuffer (sr.str());
  LLVMContext& context = getGlobalContext();
  ErrorOr<Module*> ModuleOrErr = parseBitcodeFile (mbjit, context);
  if (error_code EC = ModuleOrErr.getError())
  {
    std::cout << ModuleOrErr.getError().message() << "\n";
    assert(false);
  }




This is the execution result:
B ok
C ok
0xc0 ok
0xde ok
Invalid bitcode signature



Ok is not working :/
But why ???



For debuging, between 2) and 3), I export the readed module and write to
a file on my hard drive,
and try llvm-dis, and the dissasembly of the module works.

Wath's wrong? Any idea for solve this problem?

Thanks you very much.

Regards,
Willy



More information about the llvm-dev mailing list