[llvm-dev] LLVMGetBitcodeModuleInContext2 problem

Toshiyasu Morita via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 8 15:29:07 PST 2017


I'm trying to use LLVMGetBitcodeModuleInContext2 to load a .bc file.
However, it's not working.

The code looks something like this:

void llvm_load_IR_library(char *path)

{
        LLVMContextRef global_context;
        LLVMMemoryBufferRef module_path;
        LLVMModuleRef ir_lib_module;
        bool flag;

        module_path = LLVMCreateMemoryBufferWithMemoryRange(path,
strlen(path), "path", 1);

        global_context = LLVMGetGlobalContext();

        flag = LLVMGetBitcodeModuleInContext2(global_context, module_path,
&ir_lib_module);

        printf("LLVMGetBitcodeModuleInContet2() returned %d\n", flag);
}

When this code is called, this is printed:

error: Invalid bitcode signature

from what I can tell, the bitcode file is correct:

00000000  42 43 c0 de 35 14 00 00  05 00 00 00 62 0c 30 24
|BC..5.......b.0$|
...

This seems to match this code:

/// Helper to read the header common to all bitcode files.
static bool hasValidBitcodeHeader(BitstreamCursor &Stream) {
  // Sniff for the signature.
  if (Stream.Read(8) != 'B' ||
      Stream.Read(8) != 'C' ||
      Stream.Read(4) != 0x0 ||
      Stream.Read(4) != 0xC ||
      Stream.Read(4) != 0xE ||
      Stream.Read(4) != 0xD)
    return false;
  return true;
}

I'm out of ideas. Anything obvious I'm doing wrong?

Toshi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170308/f4250a0d/attachment.html>


More information about the llvm-dev mailing list