Created
December 18, 2025 23:23
-
-
Save kammce/e5fcdf9ded398df80a93610f56a7226a to your computer and use it in GitHub Desktop.
Minimum code to override the terminate handler for both LLVM and GCC. Don't forget to add the --wrap linker arguments, otherwise, this will not work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <exception> | |
| std::terminate_handler halt = +[]() { while (true) { continue; } }; | |
| extern "C" { | |
| #if defined(__clang__) | |
| // Terminate symbol within LLVM | |
| // NOTE: Add linker argument: -Wl,--wrap=__cxa_terminate_handler | |
| std::terminate_handler __wrap___cxa_terminate_handler = halt; | |
| #elif defined(__GNUC__) | |
| // Terminate symbol within GCC (within the __cxxabiv1 namespace) | |
| // NOTE: Add linker argument: -Wl,--wrap=_ZN10__cxxabiv119__terminate_handlerE | |
| std::terminate_handler __wrap__ZN10__cxxabiv119__terminate_handlerE = halt; | |
| #endif | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment