Repository navigation
fix(libc): give Windows frames without a DWARF record their function range from native unwind data - #24502
Conversation
…range from native unwind data A Windows frame without a DWARF record (every host frame of an SEH build such as MSYS2, and system DLLs on every Windows build) took only its start from RtlLookupFunctionEntry: the cursor's getInfo reported end 0 and no segment, and _Unwind_FindEnclosingFunction returned 0. Both now use the start and end of the RUNTIME_FUNCTION RtlLookupFunctionEntry returns, as LLVM 18.1.8 getInfoFromSEH does, with the image base as the segment. A chained fragment reports its own range. The DWARF lookup is unchanged. unwind_cursor accepts a frame without an FDE on SEH toolchains, as it does for macOS compact unwind, and still requires start < ip < end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012VfFiztpSXVYPt12tPKGzZ
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against d420c8304c:
- Conventions:
tools/check_conventions.pypassed. - Build:
unwind_cursor_testsbuilt cleanly. - CTest (
unwind_cursor,unwind_cursor_get_register,unwind_cursor_get_float_register,unwind_cursor_set_register,unwind_cursor_set_float_register):1/5 Test #1400: unwind_cursor_get_float_register ... Passed 0.03 sec 2/5 Test #1401: unwind_cursor_set_register ......... Passed 0.03 sec 3/5 Test #1399: unwind_cursor_get_register ......... Passed 0.03 sec 4/5 Test #1398: unwind_cursor ...................... Passed 0.03 sec 5/5 Test #1402: unwind_cursor_set_float_register ... Passed 0.02 sec 100% tests passed, 0 tests failed out of 5 - Negative control: with
core/libs/prx/libc/src/exception/Unwind.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/5 Test #1399: unwind_cursor_get_register ......... Passed 0.02 sec 2/5 Test #1401: unwind_cursor_set_register ......... Passed 0.02 sec 3/5 Test #1400: unwind_cursor_get_float_register ... Passed 0.02 sec 4/5 Test #1398: unwind_cursor ...................... Passed 0.02 sec 5/5 Test #1402: unwind_cursor_set_float_register ... Passed 0.01 sec 100% tests passed, 0 tests failed out of 5 - Code reading:
- Verified core/libs/prx/libc/src/exception/Unwind.cpp: NativeFunctionStart correctly queries RtlLookupFunctionEntry with imageBase and computes imageBase + function->BeginAddress with proper null checking
- Verified VirtualUnwind populates context.regionEnd (imageBase + function->EndAddress) and context.segment (imageBase) matching the libunwind AbstractUnwindCursor getInfo layout
- Verified _Unwind_FindEnclosingFunction_nid_postfix correctly subtracts 1 from pc (context.registers[16] - 1) before lookup on Windows under #ifdef _WIN32 to ensure return addresses map to the calling function, with clean fallback to 0 on non-Windows/no record
- Verified docs/dev/debt/changes/fix-libc-unwind-seh-function-range.md follows technical debt fragment conventions and correctly records the behavior difference from LLVM 18.1.8 and SEH chained entry handling
- Verified core/libs/tests/UnwindCursor.cpp correctly tests the native SEH / compact unwind path without FDE when defined(SEH) or defined(APPLE)
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head d420c8304c743864224bdf33ab127423b6dcbb6a. I read the prepared description, commit list, manifest, diff, and all three changed files. No tests or builds were run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and source review | passed | Three changed files read |
| Tests and builds | not run | Author-reported Windows results not independently verified |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full test suite, Windows execution, CI evidence, and Linux/macOS builds were not independently verified. The review bundle included all changed files; no changed files were excluded.
To get this to a good state
Nothing is required.
|
A Windows run with the other toolchain, in case it is useful next to the MSYS2 UCRT64 results. Windows 11, WinLibs GCC 15 Release, head
So with WinLibs the two failing checks from the description do not fail on I did not check why this toolchain's host functions still get their range on AI-assisted: yes |
|
Native SEH unwind verification. Both AI-assisted with OpenAI Codex. |
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
What
unwind_cursorandunwind_enclosing_functionfail on every Windows build with an SEH toolchain (MSYS2 UCRT64 GCC):unwind cursor check failed: getInfo gives the range of the function holding the IPenclosing function check failed: an address inside a function reports that function's first byteWith an SEH toolchain, the host binaries carry only
.pdata/.xdataand no.eh_frame, soDecodeFramefinds no DWARF record for a host function. Stepping already falls back toRtlVirtualUnwind(VirtualUnwind), but:getInfogot only the start from that fallback: end 0, segment 0;_Unwind_FindEnclosingFunctionused onlyDecodeFrameand returned 0.The same happens on every Windows build, WinLibs included, for any frame without a DWARF record, such as frames in system DLLs (ntdll, kernel32).
For a Windows frame without a DWARF record:
VirtualUnwindalso sets the region end (EndAddressof theRUNTIME_FUNCTIONthatRtlLookupFunctionEntryreturns) and the segment (image base). The only reader of these two fields is the cursor'sgetInfo. The personality and LSDA path readsregion,textBaseanddataBase, which are unchanged._Unwind_FindEnclosingFunctionfalls back to theBeginAddressof theRUNTIME_FUNCTIONholding the address minus one, the same address rule as the DWARF lookup.UNW_FLAG_CHAININFO) reports its own range, not the primary entry's. That matches how LLVM 18.1.8getInfoFromSEHtakes the range (libunwind/src/UnwindCursor.hpp), and it keepsgetInfo's start equal to_Unwind_GetRegionStart. GCC emits no chained entries: none inlibc.prx(3824 entries) or the test executables.getInforeports format 0 and no unwind info for these frames, as for macOS compact unwind (7d6091c). LLVM reports theRUNTIME_FUNCTIONand its size there. This is recorded as a difference in the debt entry.Sources: x64 exception handling (
RUNTIME_FUNCTION, chained unwind info) and LLVM 18.1.8UnwindCursor.hpp. There is no console behaviour to match: console code has no SEH frames.The DWARF lookup is unchanged. Every new line in
Unwind.cppis inside#ifdef _WIN32and runs only afterDecodeFramehas found no record. On Linux and macOS,_Unwind_FindEnclosingFunctionstill returns 0 whenDecodeFramefails; only the order of its two return statements changed.unwind_cursoraccepts a frame without an FDE on SEH toolchains, as it already does for macOS compact unwind. It still requiresstart == probe && start < ip && ip < end. The two debt entries (cursor slots,_Unwind_FindEnclosingFunction) are updated through a fragment.Related: #24354 (same SEH toolchain cause, test-side), #24358.
Tested
Windows 11 Pro 26H2 (10.0.26300), MSYS2 UCRT64 GCC 16.2.0 (SEH), Release, branch on
mainc8f72e9:unwind_cursorandunwind_enclosing_functionpass 10/10 each. Onmainthey pass 0/10, with the messages above.unwind_cursor_*_registertests still pass.tools/select_tests.pyfor this change (6369 of 6511,--timeout 120,-j16): 7 failures, all failing onmainhere too:agc_process_sampler_stack(fixed by test(libSceAgcDriver): check the sampled caller through native unwind data on SEH toolchains #24354)agc_driver_stencil_plane_memory,agc_driver_store_over_untracked,agc_driver_msaa_dcc_unwatch,agc_storage_write_back_host_retileguest_raise_short_sleep,guest_raise_short_sleep_without_wake(guest_raise_short_sleep: unhandled single step at Aps5RedirectedEntryStub on Windows #24358; the second fails 3/3 in a-j16subset onmainand passes alone on both)agc_process_sampler_stack,unwind_cursorandunwind_enclosing_functionpass 10/10 each.CI evidence:
windowsjob passes both tests onmainpushes, for example:guest_appcontent_download_0)WinLibs not tested locally, CI covers it. Linux and macOS were not built locally; their code is unchanged apart from the reordered return in
_Unwind_FindEnclosingFunction.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)