Skip to content

Truncate IR dump basenames to respect NAME_MAX#1650

Open
npiesco wants to merge 1 commit intorust-lang:mainfrom
npiesco:truncate-ir-dump-basenames
Open

Truncate IR dump basenames to respect NAME_MAX#1650
npiesco wants to merge 1 commit intorust-lang:mainfrom
npiesco:truncate-ir-dump-basenames

Conversation

@npiesco
Copy link
Copy Markdown

@npiesco npiesco commented Apr 23, 2026

Resolves the // FIXME work around filename too long errors in src/pretty_clif.rs.

When --emit=llvm-ir is used with cg_clif, symbol-mangled basenames can exceed the filesystem per-component limit (255B on ext4/XFS/APFS, 143B on HFS+, 255 UTF-16 on NTFS). File::create returns ENAMETOOLONG; the current early_warn path silently drops the dump.

This patch truncates only names that would fail:

  • ≤ 200 bytes: pass through unchanged (zero overhead, borrowed Cow).
  • Longer: rewritten to <first 160 bytes of stem>_h<16-hex-FNV-1a-64 over the full stem>.<exts>.
  • Extension chains (.opt.clif, .unopt.clif, .vcode) preserved.
  • Char-boundary-safe truncation.

Called inside write_ir_file, so both write_clif_file and the vcode writer in base.rs benefit uniformly.

Supersedes #1649 (closed). Happy to adjust the shape on review feedback.

Symbol-mangled Rust names can easily exceed the per-component filename
length limit enforced by most filesystems (255 bytes on ext4/XFS/Btrfs,
143 on HFS+, 255 UTF-16 code units on NTFS), causing `File::create`
in `write_ir_file` to fail with ENAMETOOLONG when `--emit=llvm-ir`
is passed so cg_clif dumps CLIF/vcode per function. The previous code
carried a `FIXME work around filename too long errors` marker.

This change introduces `truncate_ir_basename`: names `\u{2264}` 200
bytes pass through unchanged; longer names are rewritten to
`<first 160 bytes of stem>_h<16-hex-FNV-1a-64 of full stem>.<exts>`.
The hash is computed over the original stem, so the transformation is
deterministic and collision-resistant (any two distinct inputs map to
distinct outputs with overwhelming probability). Extension suffix
chains such as `.opt.clif`, `.unopt.clif`, and `.vcode` are
preserved, so downstream tooling keying off the extension is unaffected.

The function is invoked inside `write_ir_file` so that every caller
(`write_clif_file` for CLIF dumps and the vcode dump in `base.rs`)
benefits uniformly, and the FIXME at the top of `write_clif_file` is
removed.
@npiesco
Copy link
Copy Markdown
Author

npiesco commented Apr 23, 2026

@folkertdev @Urgau — tagging you for a second pair of eyes since #1649 closed with a "not quite the right approach" note but no concrete alternative. Open to reshaping on feedback; the core point is that the current early_warn drop-on-ENAMETOOLONG silently loses requested IR dumps.

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