<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/100500>100500</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLJIT::deinitialize not running static dtors in LLVM-17
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
xybu
</td>
</tr>
</table>
<pre>
So I have a program that highly resembles the [LLJITWithInitializers.cpp](https://github.com/llvm/llvm-project/blob/main/llvm/examples/OrcV2Examples/LLJITWithInitializers/LLJITWithInitializers.cpp) example except that we expose all symbols in process memory to JIT space.
Recently we're upgrading from LLVM-15 to LLVM-17 and found that our unit tests involving static dtors are broken. It appears that
* static dtors in JITed module don't run anymore with LLJIT::deinitialize(JD)
* Something generated by JIT is attached to the real __cxa_atexit() which causes segfault during shutdown.
I was looking through the commits in Orc but too many to find something relevant.
Then I searched __cxa_atexit in the repo and found this comment about LocalCXXRuntimeOverrides in [ExecutionUtils.h](https://github.com/llvm/llvm-project/blob/2ba1aeed2efd8156717886f89f6d4270b1df7a18/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h#L163) which seems to describe exactly what's happening. With LLJIT most details are sealed and we only call the clean interface.
I tried to do `CXXRuntimeoverrides.enable(llJIT_->getMainJITDylib(), *mangle_)` but got `Duplicate definition of symbol '__dso_handle'` for now. Still looking.
Platform is Linux x86_64.
I'm running out of ideas so wonder if any expert is aware of some changes to LLJIT that require users to do something different / explicit to handle static dtors or atexit() gracefully. Any help is super appreciated. Thank you!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVc2O2zgTfBr60ogh0T_yHHyYZMaABw7yIZkvyc1okS2JG4rUkk3_7NMvKM-M42BzWOzFtmixWV1dVcQYTeuI1mLxXiweJpi482F9OtdpUnt9Xn_xsIUODwQIQ_BtwB64Q4bOtJ09Q6BIfW0pAncEYvF-t3vaPn8z3G2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