这是indexloc提供的服务,不要输入任何密码
Skip to content

-Zchecksum-hash-algorithm used normalized file size in dep-info #148934

@weihanglo

Description

@weihanglo

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}

// 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)

6d41834

Cargo issue: rust-lang/cargo#16253

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions