[llvm-dev] "corrupted size vs. prev_size" when calling ExecutionSession::lookup()

Stefan Gränitz via llvm-dev llvm-dev at lists.llvm.org
Thu Sep 19 05:53:23 PDT 2019


Hi Yafei

What JIT backend do you use in lli? The default is still MCJIT!
https://github.com/llvm/llvm-project/blob/13bdae8541c3/llvm/tools/lli/lli.cpp#L88

I think -jit-kind=orc-lazy gives ORCv2 behavior.

Cheers

On 19/09/2019 14:02, Yafei Liu via llvm-dev wrote:

> Hi, I wrote a compiler that generate IR code and run it on the JIT,
> and there randomly crashed due to "corrupted size vs. prev_size"
> depends on the IR code generated from the source code.
>
> Here's how I created the JIT:
>
>
>     llvm::InitializeNativeTarget();
>       llvm::InitializeNativeTargetAsmPrinter();
>       llvm::InitializeNativeTargetAsmParser();
>       // create jit
>       llvm::orc::ExecutionSession ES;
>       llvm::orc::RTDyldObjectLinkingLayer ObjectLayer(ES,
>                                                       []() { return
>     std::make_unique<llvm::SectionMemoryManager>(); });
>       auto JTMB = llvm::orc::JITTargetMachineBuilder::detectHost();
>       auto DL = JTMB->getDefaultDataLayoutForTarget();
>       llvm::orc::IRCompileLayer CompileLayer(ES, ObjectLayer,
>     llvm::orc::ConcurrentIRCompiler(std::move(*JTMB)));
>       llvm::orc::MangleAndInterner Mangle(ES, *DL);
>       ES.getMainJITDylib().setGenerator(
>          
>     llvm::cantFail(llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(*DL)));
>
>     // ... large part to generate IR code
>     .
>
>       if (llvm::verifyModule(*AST::getModule(), &llvm::errs())) {
>         return 0;
>       } else {
>         std::cout << "Verified success\n";
>       }
>
>       // run the generated IR code
>       llvm::cantFail(CompileLayer.add(ES.getMainJITDylib(),
>                                      
>     llvm::orc::ThreadSafeModule(std::move(AST::takeModule()),
>                                                                  
>     AST::takeContext())));
>
>       auto symbol = llvm::cantFail(ES.lookup({&ES.getMainJITDylib()},
>     Mangle("main")));
>
>       int (*entry)() = (decltype(entry)) symbol.getAddress();
>       std::cout << entry() << std::endl;
>
>
> and the "corrupted size vs. prev_size" will happen if the IR code is this:
>
>     ; ModuleID = 'top'
>     source_filename = "top"
>
>     @0 = global [3 x i32] [i32 1, i32 2, i32 3]
>
>     define i32 @main() {
>       %1 = alloca i32
>       store i32 0, i32* %1
>       br label %2
>
>     ; <label>:2:                                      ; preds = %0
>       %3 = load i32, i32* %1
>       ret i32 %3
>     }
>
> I put this IR code to lli, and it works fine.
>
> So any idea why I get "corrupted size vs. prev_size" when
> calling calling ExecutionSession::lookup()?
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-- 
https://flowcrypt.com/pub/stefan.graenitz@gmail.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190919/833a2d9c/attachment.html>


More information about the llvm-dev mailing list