Skip to content

tcc: count only file-backed pages in chained-fixups page_count (#29744) - #31146

Merged
JalonSolov merged 1 commit into
vlang:masterfrom
quaesitor-scientiam:fix/tccmacho-page-count-macos27
Oct 26, 2026
Merged

JalonSolov merged 1 commit into
vlang:masterfrom
quaesitor-scientiam:fix/tccmacho-page-count-macos27

Conversation

@quaesitor-scientiam

Copy link
Copy Markdown
Contributor

Summary

  • On macOS 27, TinyCC's chained-fixups writer sizes the __DATA segment's page_count from vmsize, so the zero-fill __bss pages are listed as file-backed. dyld then maps them from the file instead of zero-filling, which gives garbage globals (macOS 27 arm64: bundled TCC links binaries with garbage in __bss (v up hangs, make panics) #29744).
  • This adds thirdparty/build_scripts/patches/tccmacho-page-count-filesize.diff, which counts ceil(filesize / SEG_PAGE_SIZE) pages and skips segments with no file-backed pages.
  • The arm64 TCC build script applies it after checking out TCC_COMMIT.

Important: the patch is inert for this script's output

The arm64 script configures TinyCC with --config-new_macho=no, which does not use chained fixups. The patch is compiled in but has no effect on this bundle. It is kept as defense in depth for builds that keep chained fixups.

The fix that actually matters for the prebuilt bundle is the TinyCC-side patch proposed in vlang/tccbin#109. This PR does not replace it.

Provenance

The recorded TinyCC commit hash does not reflect the applied patch. A build from that hash plus this patch is not byte-identical to a build from the hash alone.

Test plan

  • Patch applied to TinyCC mob 43c7708b and 85ba3ae8 in scratch (earlier session)
  • Patch applies to TinyCC mob 43c7708b in a clean clone (not re-run)
  • Arm64 bundle built by the script on macOS 27 runs the v globals repro correctly
  • tccbin_workflow_preservation_test.sh (fails on macOS for an unrelated stat -c reason; pre-existing)

Caveat: git apply --check only works inside a TinyCC clone, not from the V repo root.

🤖 Generated with Claude Code

…#29744)

On macOS 27, TinyCC's chained-fixups writer sizes the __DATA segment's
page_count from vmsize, so the zero-fill __bss pages are listed as
file-backed. dyld then maps them from the file instead of zero-filling,
which gives garbage globals.

Add a patch that counts ceil(filesize / SEG_PAGE_SIZE) pages and skips
segments with no file-backed pages. Apply it after checkout of
TCC_COMMIT in the arm64 TCC build script.

The script configures TinyCC with --config-new_macho=no, so the patch
is compiled but inactive for this bundle. It is kept as defense in
depth for builds that keep chained fixups. The recorded TCC commit hash
does not reflect the applied patch.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
@quaesitor-scientiam quaesitor-scientiam self-assigned this Oct 25, 2026
@JalonSolov
JalonSolov requested a balanced review from Copilot October 25, 2026 22:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

1 open issue
What changed in this PR

Adds a defensive TinyCC patch to fix chained-fixups segment page counting on macOS 27, and applies it in the macOS arm64 TinyCC build script to prevent __bss zero-fill pages from being treated as file-backed.

Changes:

  • Apply a TinyCC source patch during the macOS arm64 TinyCC build to correct chained-fixups page_count behavior.
  • Introduce a TinyCC patch that computes fixup pages from filesize (file-backed pages) and skips segments with zero file-backed pages.
File Description
thirdparty/​build_scripts/​thirdparty-macos-arm64_tcc.sh Applies the new TinyCC patch after checkout to harden against chained-fixups mis-sizing issues.
thirdparty/​build_scripts/​patches/​tccmacho-page-count-filesize.diff Patch adjusting tccmacho.c chained-fixups logic to count only file-backed pages and skip non-file-backed segments.

Review effort: Lite

@JalonSolov
JalonSolov merged commit b4a4130 into vlang:master Oct 26, 2026
19 of 97 checks passed
@quaesitor-scientiam
quaesitor-scientiam deleted the fix/tccmacho-page-count-macos27 branch October 26, 2026 00:36
JalonSolov pushed a commit to vlang/tccbin that referenced this pull request Oct 27, 2026
)

PR #109 added patches/tccmacho-page-count-filesize.diff but nothing
applied it, so the bundle built from TCC 85ba3ae8 was unchanged. Apply
the patch from the V repo's copy after the TCC_COMMIT checkout, before
configure. The configure step keeps --config-new_macho=yes, so the
patch is active for this bundle.

The V repo copy of this script (thirdparty/build_scripts/
thirdparty-macos-arm64_tcc.sh) applies the same patch, but with
--config-new_macho=no, where it does nothing. Keep the two in sync.
This script now needs the V checkout to contain the patch file
(vlang/v#31146 or a branch that has it).

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
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.

3 participants