Yafei Liu via llvm-dev
2019-Sep-19 12:02 UTC
[llvm-dev] "corrupted size vs. prev_size" when calling ExecutionSession::lookup()
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()? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190919/0b4d5eec/attachment-0001.html>
Stefan Gränitz via llvm-dev
2019-Sep-19 12:53 UTC
[llvm-dev] "corrupted size vs. prev_size" when calling ExecutionSession::lookup()
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 at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190919/833a2d9c/attachment.html>
via llvm-dev
2019-Sep-19 16:51 UTC
[llvm-dev] "corrupted size vs. prev_size" when calling ExecutionSession::lookup()
Hello Yafei, Could you open a bug report with the reproducer? This may expose an issue that shares the same root cause with PR35547 which gets a little bit tricky to reproduce. -Yuanfang From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Yafei Liu via llvm-dev Sent: Thursday, September 19, 2019 5:03 AM To: llvm-dev <llvm-dev at lists.llvm.org> Subject: [llvm-dev] "corrupted size vs. prev_size" when calling ExecutionSession::lookup() 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()? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190919/9af29784/attachment.html>
Yafei Liu via llvm-dev
2019-Sep-20 01:40 UTC
[llvm-dev] "corrupted size vs. prev_size" when calling ExecutionSession::lookup()
HI Stefan, I'm new to llvm JIT, I *think *I used the ORC JIT, because I use the library orcjit in CmakeList, and the namespace of JIT is llvm::orc, any change I got MCJIT be mistake? On Fri, Sep 20, 2019 at 12:51 AM <Yuanfang.Chen at sony.com> wrote:> Hello Yafei, > > > > Could you open a bug report with the reproducer? This may expose an issue > that shares the same root cause with PR35547 which gets a little bit tricky > to reproduce. > > > > -Yuanfang > > > > *From:* llvm-dev <llvm-dev-bounces at lists.llvm.org> *On Behalf Of *Yafei > Liu via llvm-dev > *Sent:* Thursday, September 19, 2019 5:03 AM > *To:* llvm-dev <llvm-dev at lists.llvm.org> > *Subject:* [llvm-dev] "corrupted size vs. prev_size" when calling > ExecutionSession::lookup() > > > > 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()? >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190920/c692247e/attachment-0001.html>