GCC gives C code built with -fexceptions, and cleanup-only functions after link-time optimization, the C personality __gcc_personality_v0. The unwinder accepted only its own C++ personality, so an exception thrown through such a frame was never caught. libc now provides the C personality, which never catches and installs the frame's cleanup landing pad in the cleanup phase, and the unwinder calls it for those frames.
14 lines
457 B
C
14 lines
457 B
C
struct CleanupCounter { int* count; };
|
|
|
|
static void Leave(struct CleanupCounter* counter) { ++*counter->count; }
|
|
|
|
void CallWithCleanup(void (*function)(void), int* count) {
|
|
struct CleanupCounter counter __attribute__((cleanup(Leave))) = {count};
|
|
function();
|
|
}
|
|
|
|
void CallAroundCleanup(void (*before)(void), void (*within)(void), int* count) {
|
|
before();
|
|
struct CleanupCounter counter __attribute__((cleanup(Leave))) = {count};
|
|
within();
|
|
}
|