Skip to content

Ask only tslang's own pointer type_info for its box thunk (Linux) - #358

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix-linux-foreign-pointer-catch
Sep 24, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix-linux-foreign-pointer-catch

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

An untyped catch (e) on Linux treated every exception whose type_info is a __pointer_type_info as a tslang class, and called the box thunk it loads from a fifth field (#351). Only tslang's _ZTIP<n><name> has that field.

A C++ throw "boom" (_ZTIPKc) from a linked native library read past the end of libstdc++'s type_info and called whatever it found there: a segfault inside the __pointer_type_info vtable, reproduced. The same applied to any pointer to a C++ class, and to a type_info emitted before the field existed.

  • tslang's pointer type_info now sets a bit of its own in __flags (0x40000000). libstdc++ defines only the low qualifier bits. A throw and its catch emit their type_infos alike, so libstdc++'s qualifier check still sees equal flags.
  • The catch reads the thunk field only when that bit is set. Any other pointer exception is boxed as an opaque value.

Verification

  • New Linux-only test test-jit-foreign-throw-catch. A small C++ library (foreign-throw/foreign_throw.cpp, built by the tester's CMake) throws a const char*, a pointer to a C++ struct and an int into untyped catches. Beside them, a tslang class must still box as itself (instanceof). On main it segfaults.
  • Linux (WSL): 2854/2854 passed.
  • Windows Release: 2859/2859 passed (the code path is Itanium-only).

🤖 Generated with Claude Code

An untyped `catch (e)` on Linux took every exception whose type_info is
a __pointer_type_info for a tslang class, and called the box thunk it
loads from a fifth field. Only tslang's _ZTIP<n><name> has that field.
A C++ `throw "boom"` (`_ZTIPKc`) from a linked native library read past
the end of libstdc++'s type_info and called what it found: a segfault in
the __pointer_type_info vtable. The same held for any pointer to a C++
class, and for a type_info emitted before the field existed.

tslang's pointer type_info now sets a bit of its own in __flags
(0x40000000; libstdc++ defines only the low qualifier bits), and the
catch reads the thunk field only when that bit is set. Anything else is
boxed as an opaque value. A throw and its catch emit their type_infos
alike, so libstdc++'s qualifier check still sees equal flags.

New Linux-only test test-jit-foreign-throw-catch: a small C++ library
throws a const char*, a pointer to a C++ struct and an int into untyped
catches, beside a tslang class that must still box as itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit d84483f into main Sep 24, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-linux-foreign-pointer-catch branch September 24, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant