Repository navigation
ex_stack: report an unhandled exception instead of terminating in libc++abi - #1302
Conversation
…c++abi
Under ex_stack a Modula-3 exception that no handler catches reaches
std::terminate, which prints "libc++abi: terminating due to uncaught
exception of type _M3Exc" and aborts, without the runtime-error report
("Unhandled exception: Main.a", file and line). m3tests r001, r003,
r004 and r005 failed for it on ARM64_DARWIN.
- RTExStackC.c installs a std::terminate handler that recovers the
escaping _M3Exc by re-throwing it and hands its activation to the new
RTException.ReportUnhandled.
- ReportUnhandled records the exception as un_except/un_arg, as
DefaultBackstop does, and reports it through Crash without re-raising
(a throw from inside terminate would recurse).
- RTExStack.DumpStack prints the libunwind stack dump only under
@M3stackdump or @M3debugex, as under ex_frame; it had printed it on
every crash, which the reference outputs don't include.
Ported from the msir branch (f096d61), where the handler is in each
target's RTStackC.c; here it is in the target-independent RTExStackC.c.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| struct _M3TerminateInstaller { | ||
| _M3TerminateInstaller() { std::set_terminate(_m3_terminate_handler); } | ||
| }; | ||
| _M3TerminateInstaller _m3_terminate_installer; |
There was a problem hiding this comment.
Just be aware, that..hand waving vagueness, Visual C++ LTCG link time codegen somehow sometimes breaks static initializers.
I'm afraid I do not have details.
I just don't know when it breaks them.
I know some code bases avoid LTCG for this reason.
And other code bases move the static initializers to files without LTCG.
Specifically the two code bases are msvcrt.dll (not LTCG) and ucrtbase.dll (static initializers in separate files without LTCG).
Modula-3, you know, would have you put this in a module initializer, which it hooks up itself, via the entry point that Modula-3 perhaps demands control of.
I am surprised you did't use that mechanism, though I realize that would just then "bridge" over to C++.
A C++ static initializer is not dependable everywhere (e.g. under Visual C++ link-time code generation), so RTExStackC.c now exports RTStack__InstallTerminateHandler, and RTExStack's module body calls it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Good point, thanks. A C++ static initializer was the convenient way to install the handler, but there's no need to depend on it. I've changed it to the Modula-3 way you suggest: |
…, LOOPHOLE fix Brings in #1271 (ex_stack target-independent), #1294/#1299 (unused base pointer), #1295, #1296 (_m3_caught local), #1297, #1298, the RTStackC include fix and #1300 (LOOPHOLE between a float and a packed integer, with m3test p308). Conflicts: - RTStackC.c (ARM64_DARWIN, AMD64_DARWIN, AMD64_LINUX): take master's; RTStack__ThrowM3Exc now lives in ex_stack/RTExStackC.c (#1271). msir's terminate backstop moves there too, as in #1302 (text identical, so the merge of #1302 will be clean). - RTExStack.m3: master's (no Has_walker assertion, #1271) plus msir's @M3stackdump switch. - LoopholeExpr.m3: both import lists. - m3tests m3makefile: msir's p300 to p304 and master's p305 to p308. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I think it was probably OK. There's other wierdness in the linking model through time. |
| or TRY/FINALLY handler. Only meaningful when Has_walker () = TRUE and the | ||
| M3C backend generates C++ try/catch for exception handling. *) | ||
|
|
||
| <*EXTERNAL "RTStack__InstallTerminateHandler" *> |
There was a problem hiding this comment.
Once or twice in the past, without fully understanding the situation, I have had problems where I named the C function exactly like Modula-3, in this form.
For that reason I have taken to using a single underscore in C.
Again, like the other comment, this is not a fully confident statement, but suspicions and incomplete memories.
Maybe we should just follow your way and see what happens. :)
|
Thanks Jay. Moving the install into RTExStack's module body leaves the static-initializer question moot, LTCG or not. On the double underscore: 🤖 Generated with Claude Code |
Brings in #1302 (report an unhandled ex_stack exception), the RTStack and RTMachine consolidation (#1312-#1319), #1307 (Copy_n's sub-byte mask), #1309, #1323/#1324, #1331, #1332, #1334 and #1335. Conflicts, all in favour of master's versions: - RTException, RTExStack, RTExStackC.c: #1302 is the upstreamed form of msir's unhandled-exception report; master installs the terminate handler by an explicit call from RTExStack's body rather than a C++ static initializer. - runtime/common/m3makefile: RTStackCommon.c moved to separate Has_walker files (#1316). - m3tests: keep master's p309 alongside msir's p303 and p304. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under
ex_stack, a Modula-3 exception that no handler catches reachesstd::terminate. The program then dies withinstead of the usual runtime-error report:
m3tests r001, r003, r004 and r005 fail on master for this reason on ARM64_DARWIN, and so probably on every
ex_stacktarget. This has likely been the case sinceex_stackmoved to C++ EH in May, but I haven't bisected it.Changes
ex_stack/RTExStackC.cinstalls astd::terminatehandler. It recovers the escaping_M3Excby re-throwing it, then passes its activation toRTException.ReportUnhandled. Anything else falls through toabort()as before.RTException.ReportUnhandled(new) records the exception asun_except/un_arg, asDefaultBackstopdoes. It reports throughCrashand does not re-raise, since a throw from insideterminatewould recurse.RTExStack.DumpStackprints the libunwind stack dump only under@M3stackdumpor@M3debugex, as underex_frame. Before, it printed one on every crash, and the reference outputs don't include it.This is ported from the msir branch (f096d61), where it has been in use since July. There the handler is in each target's
RTStackC.c. Since #1271 it belongs in the target-independentRTExStackC.c, so it appears once.Testing (ARM64_DARWIN, C backend). Two
concierge.py upgradepasses, the second self-hosted, then m3tests:🤖 Generated with Claude Code