[PATCH] D137381: [clang][compiler-rt] Exception escape out of an non-unwinding function is an undefined behaviour

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 4 04:41:02 PDT 2022


lebedev.ri added a comment.

In D137381#3907104 <https://reviews.llvm.org/D137381#3907104>, @MaskRay wrote:

> In your example, `clang++ a.cc; ./a.out` gives a libstdc++ error:
>
>   terminate called after throwing an instance of 'int'
>
> libc++'s is similar.

That's great, but just a symptom of misreduced testcase.
The whole problem is that in the original bug *no* abort happened at runtime,
the program terminated successfully, with a mysterious leak.

> footgun is nounwind (due to the GNU pure attribute), so Clang uses `call` instead of `invoke` and the function call is described by a call site entry with a zero action_record_offset (i.e. not a handler) in `.gcc_except_table`.
> In `_Unwind_RaiseException` called by `__cxa_throw`, the missing exception handler causes `__terminate`.
>
> `g++ a.cc; ./a.out` succeeds, because its `footgun` call is caught by `catch (...)`. (Perhaps GCC doesn't have Clang's nounwind optimization.)
>
> The patch doesn't implement the runtime correctly (I get a linker error) so I cannot try it out. How expensive is your instrumentation?
> Does it work with `-fno-exceptions` intermediate functions? (Unwinding through such functions should fail as well). Note that this check can be done today,without any instrumentation: just use `-fno-asynchronous-unwind-tables` (for some targets which default to async unwind tables (aarch64,x86,etc)).
> If the process installs a SIGABRT signal handler, the stack trace can be printed when `__terminate` calls `abort`.

I find this comment non-welcoming and discouraging.
I just wanted to get something posted when i had something to post already. All of this needs a bit more time.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137381/new/

https://reviews.llvm.org/D137381



More information about the llvm-commits mailing list