-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
Description
Problem
-Zchecksum-hash-algorithm writes magic comments to dep-info files to info build tool like Cargo about source file checksum and file length
# checksum:{checksum_hash} file_len:{file_len} {path}
rust/compiler/rustc_interface/src/passes.rs
Lines 747 to 758 in d6deffe
| // If caller requested this information, add special comments about source file checksums. | |
| // These are not necessarily the same checksums as was used in the debug files. | |
| if sess.opts.unstable_opts.checksum_hash_algorithm().is_some() { | |
| files | |
| .iter() | |
| .filter_map(|(path, file_len, hash_algo)| { | |
| hash_algo.map(|hash_algo| (path, file_len, hash_algo)) | |
| }) | |
| .try_for_each(|(path, file_len, checksum_hash)| { | |
| writeln!(file, "# checksum:{checksum_hash} file_len:{file_len} {path}") | |
| })?; | |
| } |
However, the above code uses SourceFile.source_len from SourceMap that the length of the file is normalized length (BOM-removed, newline normalized). That makes external tools harder to verify the checksum, as they need to follow all the normalizations rustc did to compute exact the same checksum
Possible solution
Instead of using normalized file length, SourceFile should keep the original file length, and serialize it to dep-info file correctly.
Meta
rustc 1.93.0-nightly (bd3ac0330 2025-11-01)
Cargo issue: rust-lang/cargo#16253
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.