Skip to content

coff split: let the linker regenerate a PE export table - #11

Merged
handsomematt merged 1 commit into
coff_prototypefrom
pe-export-directives
Oct 11, 2026
Merged

handsomematt merged 1 commit into
coff_prototypefrom
pe-export-directives

Conversation

@handsomematt

Copy link
Copy Markdown
Member

Adds a generate_exports module option: the linker builds the image's export directory instead of the split objects carrying the original's bytes. Needs openblack/llvm-project#4 for the vc6 layout.

What changes

  • Directives: each split object gets a -export: directive for every symbol it defines that the image exports under that name.
    • Data exports get ,DATA.
    • An incrementally linked image exports through @ILT+n_ jump thunks, which become -export:name=@ILT+n_name.
    • The split fails if an export has no symbol of that name at its address. The fix there is a symbols.txt name or alias, for example for functions folded by link.exe's /OPT:ICF.
  • Linker args: args.rsp gains /DEF:exports.def, whose LIBRARY line carries the original DLL name, and /TIMESTAMP: with the original directory's link time.
  • Fold: coff fold keeps a recompiled unit's -export: directives for such a module. Without the option it still drops them, as in v0.0.33.
  • Splits: they must leave the original table out of the linked units; bw1-decomp carves an .edata region and holds that unit back.

Testing

  • cargo test: 32 pass, including new tests for the directives (plain, C name, @ILT thunk, ,DATA, a missing export), the .drectve that write_coff emits, and fold keeping exports.
  • clippy has no diagnostics on the changed lines.
  • bw1-decomp BW1W120 with a local build of lld: Lay out export and import tables like vc6 link.exe on i386 llvm-project#4:
    • LHAudio, LHLog, LHMultiplayer and LHDialog link their export tables from these directives;
    • all 15 build.sha1 hashes match.

🤖 Generated with Claude Code

A module with `generate_exports: true` gets its export directory from the
linker instead of carrying the original's bytes:

- Each split object carries a `-export:` directive for every symbol it
  defines that the image exports by that name (`,DATA` for data). An
  incrementally linked image exports through its `@ILT+n_` thunks, so
  those become `-export:name=@ilt+n_name`.
- args.rsp names the original DLL through a generated exports.def
  (LIBRARY) and stamps the link with the directory's timestamp.
- `coff fold` keeps a recompiled unit's own export directives for such a
  module.

The splits must leave the original export table out of the linked units.
@handsomematt
handsomematt merged commit 5aef02c into coff_prototype Oct 11, 2026
30 checks passed
@bwrsandman
bwrsandman deleted the pe-export-directives branch October 13, 2026 11:33
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