Commit 239f931
committed
wasm-split-cli: don't zero live, overlapping bytes when pruning dead data symbols
prune_main_symbols() zeroes each unreachable data symbol's own declared
byte range in the main module's data segment. LLVM/wasm-ld tail-merges
identical *suffixes* of NUL-terminated byte constants to save space - so a
short, dead symbol's declared range can be a byte-for-byte suffix of a
longer, still-live symbol's range, sharing the same storage. Zeroing the
dead symbol's range then silently truncates the live symbol's tail, since
the code has no notion that data symbols can overlap.
This specifically corrupts core::fmt::Arguments::template - a NUL-
terminated bytecode encoding of a format!() call's literal pieces and
placeholders (new in recent nightly std, replacing the classic
`pieces: &[&str]` slice) - precisely because it's NUL-terminated to make
this kind of tail-merging possible. Losing the tail means the
core::fmt::write interpreter reads a premature 0x00 and stops right after
the first placeholder, so a format!() call's output silently comes out
truncated after its first argument.
Fixed by computing which bytes are still claimed by a live (reachable)
data symbol before zeroing anything, and skipping those bytes specifically
when zeroing a dead symbol's range.1 parent 24f6a82 commit 239f931
1 file changed
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
495 | 519 | | |
496 | 520 | | |
497 | 521 | | |
| |||
517 | 541 | | |
518 | 542 | | |
519 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
520 | 549 | | |
521 | 550 | | |
522 | 551 | | |
| |||
0 commit comments