Fix ORC runtime ELF atexit implementation.
The current ELF atexit implementation in the ORC runtime (as of 7b83f69db4a) is:
int __orc_rt_elfnix_atexit(void (*func)(void *)) {
auto &PlatformRTState = ELFNixPlatformRuntimeState::get();
return ELFNixPlatformRuntimeState::get().registerAtExit(
func, NULL, PlatformRTState.getPlatformJDDSOHandle());
}
But there's no reason to assume that func is in the Platform JITDylib, the common case is that it will not be (now that both LLJIT and the llvm-jitlink tool place the ORC runtime code in a separate JITDylib from the "main" code by default).
A better implementation would be:
int __orc_rt_elfnix_atexit(void (*func)(void *)) {
auto &PlatformRTState = ELFNixPlatformRuntimeState::get();
Dl_info Info;
if (!dladdr(func, &Info))
return -1; // Could not identify address. Error out.
return ELFNixPlatformRuntimeState::get().registerAtExit(
func, NULL, Info.dli_fbase);
}
but we'll need a JIT dladdr implementation before we can do that.
@llvm/issue-subscribers-orcjit
Author: None (lhames)
int __orc_rt_elfnix_atexit(void (*func)(void *)) {
auto &PlatformRTState = ELFNixPlatformRuntimeState::get();
return ELFNixPlatformRuntimeState::get().registerAtExit(
func, NULL, PlatformRTState.getPlatformJDDSOHandle());
}
But there's no reason to assume that func is in the Platform JITDylib, the common case is that it will not be (now that both LLJIT and the llvm-jitlink tool place the ORC runtime code in a separate JITDylib from the "main" code by default).
A better implementation would be:
int __orc_rt_elfnix_atexit(void (*func)(void *)) {
auto &PlatformRTState = ELFNixPlatformRuntimeState::get();
Dl_info Info;
if (!dladdr(func, &Info))
return -1; // Could not identify address. Error out.
return ELFNixPlatformRuntimeState::get().registerAtExit(
func, NULL, Info.dli_fbase);
}
but we'll need a JIT dladdr implementation before we can do that.
Commit b4e19155171e disabled the compiler-rt/test/orc/TestCases/Linux/ppc64/trivial-atexit.S and compiler-rt/test/orc/TestCases/Linux/x86-64/trivial-atexit.S tests due to this issue. Those tests should be re-enabled once this issue is fixed.
request to be assigned