Toshiyasu Morita via llvm-dev
2017-Mar-08 23:29 UTC
[llvm-dev] LLVMGetBitcodeModuleInContext2 problem
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>
Friedman, Eli via llvm-dev
2017-Mar-08 23:40 UTC
[llvm-dev] LLVMGetBitcodeModuleInContext2 problem
On 3/8/2017 3:29 PM, Toshiyasu Morita via llvm-dev wrote:> > 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);LLVMCreateMemoryBufferWithContentsOfFile takes a path. -Eli -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Toshiyasu Morita via llvm-dev
2017-Mar-08 23:44 UTC
[llvm-dev] LLVMGetBitcodeModuleInContext2 problem
> > > module_path = LLVMCreateMemoryBufferWithMemoryRange(path, > strlen(path), "path", 1); >LLVMCreateMemoryBufferWithContentsOfFile takes a path. Erm...no...the code is calling LLVMCreateMemoryBufferWithMemoryRange, not LLVMCreateMemoryBufferWithContentsOfFile... Or do you mean I need to load the module into memory before calling LLVMGetBitcodeModuleInContext2? Toshi On Wed, Mar 8, 2017 at 3:40 PM, Friedman, Eli <efriedma at codeaurora.org> wrote:> On 3/8/2017 3:29 PM, Toshiyasu Morita via llvm-dev wrote: > >> >> 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); >> > > LLVMCreateMemoryBufferWithContentsOfFile takes a path. > > -Eli > > -- > Employee of Qualcomm Innovation Center, Inc. > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux > Foundation Collaborative Project > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170308/a53ba2dc/attachment.html>