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

Yafei Liu via llvm-dev
Thu, 19 Sep 2019 12:02:52 -0000

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

; :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>