llvm-project
67130d0f - [TSan][Darwin] Preserve atexit callback image identity on Darwin (#237166)

Commit
6 days ago
[TSan][Darwin] Preserve atexit callback image identity on Darwin (#237166) On Darwin, TSan registers its `atexit` wrapper with a null DSO. If a dylib registers a callback with `atexit` and is then unloaded, libc cannot tie the wrapper to that image, so `dlclose` does not run the callback. It runs at process exit instead, after the dylib's code is gone, and can crash there. This change uses `dladdr` to find the image that contains the callback and passes its base address to the existing explicit-DSO `__cxa_atexit` wrapper. Other platforms keep the null DSO. A new Darwin test checks that the callback runs before `dlclose` returns and that a later process-exit callback still runs. `atexit4.cpp` now accepts either wrapper name in the race report, because on Darwin the report shows `cxa_at_exit_callback_installed_at`. The new test fails without the change and passes with it on macOS arm64 and the iOS Simulator. All seven `--filter=atexit` lit tests pass on both.
Author
Parents
Loading