Skip to content

thirdparty: add tccmacho page_count patch for macOS 27 bss (vlang/v#29744) - #109

Merged
JalonSolov merged 1 commit into
vlang:thirdparty-macos-arm64from
quaesitor-scientiam:tccmacho-page-count-filesize
Oct 25, 2026
Merged

JalonSolov merged 1 commit into
vlang:thirdparty-macos-arm64from
quaesitor-scientiam:tccmacho-page-count-filesize

Conversation

@quaesitor-scientiam

Copy link
Copy Markdown

Summary

Adds the tccmacho.c patch from vlang/v#29744 as patches/tccmacho-page-count-filesize.diff, so it can be reviewed against this branch's TinyCC commit (85ba3ae8).

On macOS 27 (arm64), TCC-linked binaries can start with garbage in __bss. With CONFIG_NEW_MACHO, page_count for __DATA is computed from vmsize, so chained starts list the zero-fill __bss pages. dyld maps listed pages from the file, so those pages hold the bytes that follow __DATA, not zeros. The patch computes page_count from filesize and skips segments with no file-backed pages.

What this PR does not do

  • It does not change build.sh. The README and the script header say build.sh is a historical copy and is not meant to be edited, so the apply step belongs in the V repo's thirdparty/build_scripts/thirdparty-macos-arm64_tcc.sh.
  • It does not include a rebuilt tcc.exe. The bundle needs a rebuild from patched source through CI, not from a local build.

Evidence (local, macOS 27.0.1 arm64)

  • Patch applies cleanly to 85ba3ae8 (git apply --check).
  • Repro with initialized data: unpatched 85ba3ae8 with chained fixups prints garbage in bss (nonzero=95071); --config-new_macho=no and the patched build print zeros.
  • Repro with __DATA file size 0 (the page_count == 0 skip path): patched build prints zeros.
  • cmd/v built with the patched TCC: version and hello world work.

Known limits

  • Only tested on arm64 macOS 27.0.1.
  • Adversarial review (17 candidates, 1 survived) found a pre-existing low-severity issue: page_count is stored in a uint16_t with no bound check, so a __DATA segment above about 1 GiB wraps. The patch does not make this worse.
  • The patch is not upstream in TinyCC yet.
  • Not confirmed from source: whether dyld treats seg_info_offset == 0 as "no fixup starts" for skipped segments.

Test plan

  • CI rebuild of thirdparty-macos-arm64 with the patch applied, then run the repro above against the new bundle
  • make and v up on macOS 27 with the new bundle

🤖 Generated with Claude Code

…9744)

Carry the tccmacho.c patch from vlang/v#29744 so it can be reviewed
against this branch's TinyCC commit (85ba3ae8).

With CONFIG_NEW_MACHO, page_count for __DATA is computed from vmsize,
so chained-starts list the zero-fill __bss pages. macOS 27 dyld maps
listed pages from the file, so __bss can hold the bytes that follow
the segment (the start of __LINKEDIT) instead of zeros. The patch
computes page_count from filesize and skips segments with no
file-backed pages.

This commit only adds the patch file. It does not change build.sh,
which is a historical copy and not meant to be edited. The V repo's
build script must apply it before the next bundle rebuild.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>

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

No open issues 🎉

What changed in this PR

Adds a TinyCC tccmacho.c patch file to fix chained-fixups page counting on macOS 27 by basing fixup page counts on file-backed pages (filesize) rather than virtual size (vmsize), avoiding __bss being incorrectly page-initialized from the file.

Changes:

  • Add patches/tccmacho-page-count-filesize.diff containing the tccmacho.c modifications from vlang/v#29744.
  • Compute chained-starts page_count from filesize and skip segments with zero file-backed pages.
File Description
patches/​tccmacho-page-count-filesize.diff Introduces the patch that changes fixup page counting to be based on file-backed pages and skips non-file-backed segments.

Review effort: Lite

@JalonSolov
JalonSolov merged commit 0561493 into vlang:thirdparty-macos-arm64 Oct 25, 2026
1 check failed
JalonSolov pushed a commit 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>
medvednikov added a commit that referenced this pull request Nov 19, 2026
…OLDER=thirdparty/tcc bash thirdparty/build_scripts/thirdparty-macos-arm64_tcc.sh` (#120)

Rebuild the macOS arm64 bundle at TinyCC mob 0f004a08. The previous tcc.exe was the
2026-07-28 build of 85ba3ae8; the recipe changes since then (#109/#110 tccmacho patch, #118
--config-new_macho=no) were never applied to a published binary.

0f004a08 contains 70adbb12 (arm64: fix sp offsets of 4096 and more in arm64_spoff). With the
old tcc.exe, tests2/153_large_struct_args.c segfaults; with this one it matches its .expect.

update_tccbin.yml cannot publish this managed bundle (the recipe refuses non-deferred builds,
and monthly candidate composition needs a producer toolchain observation the base manifest
does not have). So this was built by hand with vlang/v master f56fcbbaaa's recipe in deferred
mode (TCCBIN_DEFER_COMMIT=1), MACOSX_DEPLOYMENT_TARGET=11.0 (minos 11.0, as before), Apple
clang 21 on macOS 27.2 arm64. The libgc files, README.md, build.sh and patches are unchanged.

automation/bundle-manifest.json: inventory/outputs sha256 updated for the rebuilt files, and
lib/bcheck_run.o (new in this TinyCC) added. Policy fields (recipe, sources, probes, contract)
are unchanged.

Checked locally: tccbin_tests (hello, gc_alloc, crash) pass with libgc.dylib; V master builds
itself with -cc tcc for two generations; `v -cc tcc test` over builtin, strings, os, math,
time, sync, x/json2, regex, encoding: 451 passed, 0 failed.
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