Open keith opened 3 years ago
This could be a consequence of autolinking info not being picked up by the JIT linker. @lhames
Those failure modes are different. On Linux it's failing to resolve atexit and terminating cleanly with an error. On Darwin it's crashing.
I'm not sure why atexit wouldn't be found on Linux – from memory Immediate mode is dlsym'ing to find process symbols and I would have expected all processes to contain atexit. It's a good thing we don't find the process atexit symbol though, because...
On Darwin we are finding the process atexit symbol and calling it registering to register the handler, but that's not what we want: the JIT'd code will have been torn down by the time the containing process runs the atexit handlers.
I think the best solution is to update Swift Immediate mode to use the ORC runtime, and teach the ORC runtime to interpose atexit (it's already interposing __cxa_atexit for C++ destructors – atexit should be even easier). Darwin platform support is already in-tree in LLVM, we just need to add atexit interposition. Linux platform support should land in the LLVM mainline later today or tomorrow (good timing!).
The ORC runtime lives in compiler-rt these days, right? Should we start turning on `COMPILER_RT_BUILD_ORC`?
It should build by default if you're building the compiler-rt project, unless you explicitly disable it.
If you're building compiler-rt and the ORC runtime isn't showing up please let me know. (And in that case you probably can explicitly enable it as a workaround).
@swift-ci create
Environment
Xcode 12.5.1 (12E507)Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 2fb980592e70fa6a0d23375733021075Issue Description:
With this code:
You get this crash:
When you compile the file and run the produced binary instead, it does not crash:
You get the same behavior on Linux: