Hi,
Sorry for delays, I am OOO and traveling.
Re your patch "tsan: support C++ exceptions"
(
https://reviews.llvm.org/D10740). It has several problems:
1. It will not fix the problem if we don't return from the function
that catches an exception. Consider that we catch an exception and
then call throwing function again without returning. First, we will
have bogus stacks in reports since we don't remove stale frames from
shadow stack. Second, if this happens in a loop we will overflow
shadow stack.
2. Identifying frames by PC is wrong in presence of indirect calls.
Consider that function A makes an indirect call to B, then B calls A,
then A makes indirect call to C (at the same PC). The stack looks as
A->B->A->C. Now C throws and B catches an exception. Exit from B will
obtain return PC in A and unwind shadow stack up to it. However, it
will find the wrong A -- the second one, while it was called from the
first A.
3. FWIW it slows down normal execution.
2 can be fixed if we use SP as frame identifier. However, we still
have problem 1 and 3. Plus we we have doubled memory consumption for
shadow stack as we need to remember both PC and SP.
Emitting cleanup landing pads (
https://reviews.llvm.org/D10740) looks
much more reliable to me, because we are playing by the exception
rules rather than trying to hack something on the side. And it also
does not slow down execution, nor increase memory consumption.
But it turned out to be not trivial as expected initially, and I never
had time to finish it. If you want to pick it up, it would be great.
Exceptions are an important part of C++. Reid gave some hints in the
comments. And you can also grep llvm code for CreateLandingPad and
__gcc_personality_v0.