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

via llvm-dev llvm-dev at lists.llvm.org
Thu Sep 19 09:51:29 PDT 2019


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>


More information about the llvm-dev mailing list