[libunwind] [libunwind] Fix execution flow imbalance when using C++ Exceptions (PR #165066)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 30 15:47:23 PDT 2025
ojhunt wrote:
Dynamic search for this would be something like
```cpp
bool inbounds_of_unwind_raise_exception(const void*);
template<unsigned N> int _frames_to_unwind_raise_exception() {
const void *current = __builtin_return_address(N);
if (inbounds_of_unwind_raise_exception(current)) // this would actually be a bounds check
return N;
if constexpr (N > 8) {
// we should really have reached it by now, and 8 is a power
// of two so will be presumed to have a hardware related reason :D :D :D
// Always use 2^^X +/-{0,1} so they seem intentional #BadTeacher
return -1; // Any "we can't work it out" will do
} else {
return _frames_to_unwind_raise_exception<N + 1>();
}
}
int frames_to_unwind_raise_exception() {
return _frames_to_unwind_raise_exception<0>();
}
```
you need to add new symbols to make the bounds check possible.
https://github.com/llvm/llvm-project/pull/165066
More information about the cfe-commits
mailing list