<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Orc C Bindings crash on platforms without lazy loading support"
   href="https://bugs.llvm.org/show_bug.cgi?id=36896">36896</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Orc C Bindings crash on platforms without lazy loading support
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>OrcJIT
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>andres@anarazel.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi,

Even when not using LLVMOrcAddLazilyCompiledIR() Orc crashes on platforms
without indirect stub support. The reason for that is that its constructor
dereferences a nullptr functor (IndirectStubsMgrBuilder):

  OrcCBindingsStack(TargetMachine &TM,
                    std::unique_ptr<CompileCallbackMgr> CCMgr,
                    IndirectStubsManagerBuilder IndirectStubsMgrBuilder)
      : ES(SSP), DL(TM.createDataLayout()),
        IndirectStubsMgr(IndirectStubsMgrBuilder()), CCMgr(std::move(CCMgr)),

which is invoked by:

LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM) {
  TargetMachine *TM2(unwrap(TM));

  Triple T(TM2->getTargetTriple());

  auto CompileCallbackMgr = orc::createLocalCompileCallbackManager(T, 0);
  auto IndirectStubsMgrBuilder =
      orc::createLocalIndirectStubsManagerBuilder(T);

  OrcCBindingsStack *JITStack = new OrcCBindingsStack(
      *TM2, std::move(CompileCallbackMgr), IndirectStubsMgrBuilder);

  return wrap(JITStack);
}


std::function<std::unique_ptr<IndirectStubsManager>()>
createLocalIndirectStubsManagerBuilder(const Triple &T) {
  switch (T.getArch()) {
    default: return nullptr;
...
}

So, if any orc is used on a platform (e.g. powerpc) without stub support, orc
can't be used in eager support either.

It's not hard to fix this.  We can either make
createLocalIndirectSubsManagerBuilder() return
orc::LocalIndirectStubsManager<orc::OrcGenericABI>>(); or have the C stack not
construct IndirectStubsMgr until necessary.  Any preference?

I'd be awesome if we could get this fixed for 6.1, this is currently breaking
postgres' JIT on PPC.

I'm planning to update the orc unittests so a) they actually test aarch64,
given that that should now be fully supported. b) split the tests into indirect
/ no jit at all capability, so crashes like this can be detected automatically
in the future.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>