Skip to content

feat(coff): per-function sections, honor scope:local#3

Merged
bwrsandman merged 3 commits into
openblack:coff_prototypefrom
bwrsandman:coff-function-sections
Jul 18, 2026
Merged

feat(coff): per-function sections, honor scope:local#3
bwrsandman merged 3 commits into
openblack:coff_prototypefrom
bwrsandman:coff-function-sections

Conversation

@bwrsandman

Copy link
Copy Markdown
Member
  • write_coff cuts code sections at function-symbol boundaries so each function gets its own .text section (MSVC /Gy style). Tooling then sees exact per-function sizes instead of sizes inferred from symbol gaps, which included alignment padding. Inter-function padding and trailing jump tables stay attached to the preceding chunk and non-first chunks use alignment 1, so relinked output is unchanged. Gated by new ProjectConfig field function_sections (default true).
  • scope:local now emits IMAGE_SYM_CLASS_STATIC even with export_all; the globalize pass still promotes cross-unit-referenced locals to external first, so links are unaffected.
  • resolve_link_order warns clearly when a unit has non-contiguous ranges within one section instead of a cryptic cycle warning.
  • docs/coff.md documents COFF-specific semantics: section layout, symbol visibility, re-split requirements, non-contiguous units.

Verified on BW1W120: relinked exe and LHAudio.dll byte-identical to originals with function_sections on and off; multi-function objects show one .text section per function; scope:local symbols emit STATIC.

bwrsandman and others added 3 commits July 16, 2026 21:26
- write_coff cuts code sections at function-symbol boundaries so each
  function gets its own .text section (MSVC /Gy style). Tooling then
  sees exact per-function sizes instead of sizes inferred from symbol
  gaps, which included alignment padding. Inter-function padding and
  trailing jump tables stay attached to the preceding chunk and
  non-first chunks use alignment 1, so relinked output is unchanged.
  Gated by new ProjectConfig field function_sections (default true).
- scope:local now emits IMAGE_SYM_CLASS_STATIC even with export_all;
  the globalize pass still promotes cross-unit-referenced locals to
  external first, so links are unaffected.
- resolve_link_order warns clearly when a unit has non-contiguous
  ranges within one section instead of a cryptic cycle warning.
- docs/coff.md documents COFF-specific semantics: section layout,
  symbol visibility, re-split requirements, non-contiguous units.

Verified on BW1W120: relinked exe and LHAudio.dll byte-identical to
originals with function_sections on and off; multi-function objects
show one .text section per function; scope:local symbols emit STATIC.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Re-emit compiler comment strings left in the PE header padding (leaked
Intel #pragma comment(exestr) directives) as -?comment .drectve
directives so a comment-aware linker reproduces them, instead of a
hardcoded post-link patch.

Comment ranges are declared in the splits file like any segment
(type:comment, shared in Sections: or under a unit), read via
read_comment_regions and skipped by apply_splits. Each is attributed to
its owning unit and emitted into that unit's object; unattributed ones
go in a shared comment object linked first (lowest header address).
type:comment declarations round-trip through a splits-file rewrite.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
obj_path_for_unit returns a native path (backslash-separated on
Windows); normalize separators before comparing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bwrsandman
bwrsandman merged commit 17f5a6a into openblack:coff_prototype Jul 18, 2026
15 checks passed
@bwrsandman
bwrsandman deleted the coff-function-sections branch July 18, 2026 12:19
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.

1 participant