fix(relinker): accept a zero-size TLS export at the end of the macOS TLS block #10946
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10946"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-25T11:18:02Z.
What
WriteMacOsImagerefused a TLS export whosest_valueequals PT_TLSp_memsz:relinker --macosexited 2 withFAIL: Guest TLS export is outside the TLS block: _shared#guestfor a guest module insce_module/(PT_TLS memsz 0x40, STT_TLS export at 0x40, size 0) and withFAIL: Guest TLS export is outside the TLS block: _FixtureTlsfor an executable relinked with--skip-sce-module(PT_TLS memsz 16, export at 16, size 0), while Linux (for the executable also with--lazy-binding) and--windowsexited 0 on both inputs. Both inputs pass the earlier bounds, which allowvalue <= p_memszandsize <= p_memsz - value:GuestImageReader.cpp:192(TLS symbol exceeds TLS segment) for guest modules, and for executables the pipeline'sExecutable TLS export exceeds PT_TLS(#10646) andMacOsMachOPatcher.cpp:91(macOS executable TLS export exceeds PT_TLS). These two callers are the only code that fillsTlsExports, andScanTlsrejects a second PT_TLS, so the deleted check was reached only forvalue == p_memsz, including value 0 in an empty PT_TLS that code accesses (0 >= 0).variable.Offset >= tls.Tls->MemorySizecheck inMacOsImage.cppis deleted; the bound ofGuestImageReaderandMacOsMachOPatcherapplies unchanged, and the messageGuest TLS export is outside the TLS blockno longer exists. gABI allowsst_size0, and an STT_TLSst_valueis an offset into the TLS template, so offsetp_memszis the end of the block, as on Linux and Windows. The export's__APS5DATAentry now holds (TLS descriptor,p_memsz).Guest TLS export has no TLS block(no PT_TLS, or an empty one without TLS accesses) is unchanged. Changing>=to>was not done, since that check could never fire.test_macos_tls_exports.py,--macosonly: guest module exports at 0x3f/size 1 and 0x40/size 0, executable exports at 15/0 and 16/0, and an executable with an empty PT_TLS (memsz 0, align 1,mov rax, fs:[0]at the entry) and an export at 0/0. Each must exit 0, and the export's__APS5DATAentry must hold (__APS5DATAvmaddr + 0x20, value). A control guest export at 0x40/size 1 must exit 2 withTLS symbol exceeds TLS segment: sharedand write no module. On untouched code the test fails atguest-endwith exit 2 andGuest TLS export is outside the TLS block: _shared#guest. The test importsconvert,executableandexportsfromtest_macos_executable_exports.py; #10646 changed only that file'smain().pr_overlap.pyreports no shared lines with open pull requests that merge withmain. It cannot compare this branch with #9408 and #10249 (MacOsImage.cpp) and with #5021, #6713 and #9408 (core/relinker/CMakeLists.txt), because those do not merge withmain. Checked by hand: #9408 changesMacOsImage.cppat line 494 (thetlsExportsslot, moved only with--trace-imports) and #10249 at line 595, not the deleted line 516; theirCMakeLists.txthunks sit next tomacos_output,elf_headerandlinux_trace_imports, not next tomacos_tls_overlap, after which this PR registersmacos_tls_exports. The test also importsMachOfromtest_macos_output.py(#10712 adds lines tocheck_optionsonly) and usesfixture()throughexecutable()andmain_fixture()(#10402 changes itse_entry, which both overwrite).Tested
Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew, macOS outputs inspected as Mach-O files, not run.macos_tls_exportson untouchedc7d6660ef8fails withAssertionError: ('guest-end', 2, 'FAIL: Guest TLS export is outside the TLS block: _shared#guest ...'); with the change it passes in 0.8 s. On the earlier baseacbfd7c7fea scratch driver ran all six inputs on both builds: on untouched code the guest 0x40/0, executable 16/0 and empty-PT_TLS 0/0 inputs exit 2 with--macos(... _shared#guest,... _FixtureTls,... _FixtureTls) and 0 on Linux,--lazy-binding(executables) and--windows; with the change all three exit 0 on every target run, with macOS entries (0x140012020, 0x40), (0x140011020, 16) and (0x140011020, 0). The 0x3f/1 and 15/0 inputs convert on both builds with the same entries, and 0x40/1 fails on every target on both builds.ctest -j 4 -R '^(macos_|guest_tls$|guest_module_dir|empty_tls$|executable_tls_relocations$|linux_executable_exports$|tls_function_coverage_)': 48 tests passed in 30.0 s, among themmacos_tls_exports(0.4 s),macos_executable_exports(0.4 s),macos_empty_tls(0.3 s),macos_tls_overlap(0.2 s),macos_tls_alu(0.3 s),macos_output(0.6 s),macos_gs_traps(0.9 s),guest_tls(1.7 s),guest_module_directories(2.0 s),executable_tls_relocations(1.5 s) and the 33tls_function_coverage_*tests.ctest --test-dir build-relinker -j 3onc7d6660ef8: 262 tests, 258 passed,long_pathsskipped; failures known on this machine onmainas well:select_tests(Windows symlink fixture),patch_advisor_unit(path with spaces);shader_cache_runtime_sourcestimed out at 180 s under load and passed alone in 108.8 s16ff208dc3(#10646 merged) and rebuilt: the 13 tests matchingmacos|executable_export_bounds|guest_tls|empty_tls|linux_executable_exportspassed again, includingmacos_tls_exportsand #10646'sexecutable_export_bounds.python tools/check_conventions.py --base upstream/mainwith this title and description passed.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:18:55Z.
Review: CHANGES_REQUESTED
I found one blocking issue in the new boundary test. The fixture declares the TLS symbol at offset 0x40 with size 0, equal to the TLS memory size, but still rejects via only? The guest-side check actually permits equality (), so the observed failure from the local base executable is expected and does not test the changed macOS writer. I am not requesting a product change on that basis. However, the hosted Conventions job fails because the PR body has no nonempty section (). Please fill in the required template and rerun it. I have not approved pending that required description correction.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:18:58Z.
Review: CHANGES_REQUESTED
I found one validation issue in the new boundary test. The
guest-endcase exercises the guest reader's acceptance of a zero-size symbol at the TLS block end; that reader's bound check already permitsvalue == MemorySize, so the local base executable's rejection is expected and does not exercise this PR's macOS writer change. I am not requesting a product change on that basis.The hosted Conventions job does fail because the PR body has no nonempty
Whatsection (40188284382). Please fill in the required template and rerun it. I have not approved pending that required description correction.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:19:29Z.
Review: COMMENTED
Thanks for filling the required What section. The Conventions run attached to this head still reports failure from the earlier template check; please rerun it after the edit so the updated body is validated. The relinker matrix is still running, so I will wait for those results before reviewing the product change.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:21:28Z.
Review: COMMENTED
I found one validation issue in the new boundary test. The
guest-endcase exercises the guest reader's acceptance of a zero-size symbol at the TLS block end; that reader's bound check already permitsvalue == MemorySize, so the local base executable's rejection is expected and does not exercise this PR's macOS writer change. I am not requesting a product change on that basis.The hosted Conventions job does fail because the PR body has no nonempty
Whatsection (40188284382). Please fill in the required template and rerun it. I have not approved pending that required description correction.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:25:34Z.
Review: APPROVED
Reviewed exact head
81f6b28. The writer no longer rejects an export offset equal to TLS memory size, while the guest reader retains its / bounds check, so a zero-size symbol at the block end is accepted and a positive-size overrun remains rejected. The new fixture covers end offsets for guest modules and executables, empty TLS, and an out-of-range positive-size symbol. Local conventions and diff checks pass. The available local relinker binary is built from an older base and cannot validate the changed writer, so I did not count its expected failure as PR evidence. Hosted Linux, Windows, macOS x86_64 and ASan relinker jobs passed; macOS arm64 was still queued when checked. The PR body’s updated Conventions run passes.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:25:38Z.
Review: APPROVED
Reviewed exact head
81f6b28. The writer no longer rejects an export offset equal to TLS memory size, while the guest reader retains itsvalue > MemorySize/size > MemorySize - valuebounds check, so a zero-size symbol at the block end is accepted and a positive-size overrun remains rejected. The new fixture covers end offsets for guest modules and executables, empty TLS, and an out-of-range positive-size symbol. Local conventions and diff checks pass. The available local relinker binary is built from an older base and cannot validate the changed writer, so I did not count its expectedguest-endfailure as PR evidence. Hosted Linux, Windows, macOS x86_64 and ASan relinker jobs passed; macOS arm64 was still queued when checked. The PR body’s updated Conventions run passes.