Tested with the following program:
static volatile int* x = nullptr; void throws() __attribute__((noinline)) { if (getpid() == 0) return; throw "error"; } void maybe_throws() __attribute__((noinline)) { volatile int y = 1; x = &y; throws(); y = 2; } int main(int argc, char** argv) { int y; try { maybe_throws(); } catch (const char* e) { //printf("Caught\n"); } y = *x; printf("%d\n", y); // should be MTE failure. return 0; }
Built using clang++ -c -O2 -target aarch64-linux -fexceptions -march=armv8-a+memtag -fsanitize=memtag-heap,memtag-stack
Currently only Android implements runtime support for MTE stack tagging.
Without this change, we crash on __cxa_get_globals when trying to catch
the exception (because the stack frame __cxa_get_globals frame will fail due
to tags left behind on the stack). With this change, we crash on the y = *x;
as expected, because the stack frame has been untagged, but the pointer hasn't.
-16ULL