Skip to content

SysTools.Ar: trim Apple-ranlib wasm member padding - #192

Draft
hamishmack wants to merge 1 commit into
stable-ghc-9.14from
wip/hkm/js-ar-darwin-ranlib-padding
Draft

SysTools.Ar: trim Apple-ranlib wasm member padding#192
hamishmack wants to merge 1 commit into
stable-ghc-9.14from
wip/hkm/js-ar-darwin-ranlib-padding

Conversation

@hamishmack

Copy link
Copy Markdown

Apple's ranlib (cctools; the default ranlib on darwin, which cabal runs after ar on macOS build hosts) pads each archive member's data to an 8-byte boundary with '\n' bytes and counts that padding into the header's size field. Mach-O readers tolerate the trailing bytes, but the JS backend extracts C-bits wasm objects from package archives and hands them to emscripten, where wasm-ld fails with "section too large" on the padding.

Recover a wasm member's true length by walking its section table (a 1-byte id plus a ULEB128 length each) and drop the trailing '\n' padding when the payload is a WebAssembly module. Non-wasm members are returned unchanged.

Apple's ranlib (cctools; the default `ranlib` on darwin, which cabal runs
after `ar` on macOS build hosts) pads each archive member's data to an
8-byte boundary with '\n' bytes and counts that padding into the header's
size field. Mach-O readers tolerate the trailing bytes, but the JS backend
extracts C-bits wasm objects from package archives and hands them to
emscripten, where wasm-ld fails with "section too large" on the padding.

Recover a wasm member's true length by walking its section table (a 1-byte
id plus a ULEB128 length each) and drop the trailing '\n' padding when the
payload is a WebAssembly module. Non-wasm members are returned unchanged.
@hamishmack
hamishmack force-pushed the wip/hkm/js-ar-darwin-ranlib-padding branch from 3c31791 to 0c4ac52 Compare July 15, 2026 04:21
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