Repository navigation
tcc: count only file-backed pages in chained-fixups page_count (#29744) #31146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JalonSolov
merged 1 commit into
vlang:master
from
quaesitor-scientiam:fix/tccmacho-page-count-macos27
Oct 26, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
thirdparty/build_scripts/patches/tccmacho-page-count-filesize.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| diff --git a/tccmacho.c b/tccmacho.c | ||
| index cee09fd7..ecd467da 100644 | ||
| --- a/tccmacho.c | ||
| +++ b/tccmacho.c | ||
| @@ -1272,6 +1272,15 @@ const struct { | ||
| #define N_SEGMENT (sizeof(all_segment)/sizeof(all_segment[0])) | ||
|
|
||
| #ifdef CONFIG_NEW_MACHO | ||
| +/* Only the pages of a segment that are backed by the file can hold fixups. | ||
| + dyld's page-in linking maps every page listed in a segment's chained starts | ||
| + from the file, so listing the zero-fill tail (__bss) as well would fill it | ||
| + with the bytes that follow the segment in the file, instead of zeros. */ | ||
| +static int fixup_page_count(struct segment_command_64 *seg) | ||
| +{ | ||
| + return (seg->filesize + SEG_PAGE_SIZE - 1) / SEG_PAGE_SIZE; | ||
| +} | ||
| + | ||
| static void calc_fixup_size(TCCState *s1, struct macho *mo) | ||
| { | ||
| int i, size; | ||
| @@ -1279,7 +1288,9 @@ static void calc_fixup_size(TCCState *s1, struct macho *mo) | ||
| size = (sizeof(struct dyld_chained_fixups_header) + 7) & -8; | ||
| size += (sizeof(struct dyld_chained_starts_in_image) + (mo->nseg - 1) * sizeof(uint32_t) + 7) & -8; | ||
| for (i = (s1->output_type == TCC_OUTPUT_EXE); i < mo->nseg - 1; i++) { | ||
| - int page_count = (get_segment(mo, i)->vmsize + SEG_PAGE_SIZE - 1) / SEG_PAGE_SIZE; | ||
| + int page_count = fixup_page_count(get_segment(mo, i)); | ||
| + if (page_count == 0) | ||
| + continue; | ||
| size += (sizeof(struct dyld_chained_starts_in_segment) + (page_count - 1) * sizeof(uint16_t) + 7) & -8; | ||
| } | ||
| size += mo->n_bind * sizeof (struct dyld_chained_import) + 1; | ||
| @@ -2059,10 +2070,13 @@ ST_FUNC void bind_rebase_import(TCCState *s1, struct macho *mo) | ||
| data += (size + 7) & -8; | ||
| image->seg_count = mo->nseg; | ||
| for (i = (s1->output_type == TCC_OUTPUT_EXE); i < mo->nseg - 1; i++) { | ||
| + seg = get_segment(mo, i); | ||
| + page_count = fixup_page_count(seg); | ||
| + /* No file-backed pages, so no fixups: an offset of 0 says so. */ | ||
| + if (page_count == 0) | ||
| + continue; | ||
| image->seg_info_offset[i] = (data - mo->chained_fixups->data) - | ||
| header->starts_offset; | ||
| - seg = get_segment(mo, i); | ||
| - page_count = (seg->vmsize + SEG_PAGE_SIZE - 1) / SEG_PAGE_SIZE; | ||
| size = sizeof(struct dyld_chained_starts_in_segment) + | ||
| (page_count - 1) * sizeof(uint16_t); | ||
| segment = (struct dyld_chained_starts_in_segment *) data; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.