mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Add support for SHA256 source file hashing for LLVM 11+.
This commit is contained in:
parent
5565241f65
commit
3296d5ca7b
35
Cargo.lock
35
Cargo.lock
@ -1883,6 +1883,17 @@ dependencies = [
|
||||
"opaque-debug 0.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "md-5"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15"
|
||||
dependencies = [
|
||||
"block-buffer 0.9.0",
|
||||
"digest 0.9.0",
|
||||
"opaque-debug 0.3.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mdbook"
|
||||
version = "0.4.3"
|
||||
@ -2411,7 +2422,7 @@ checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d"
|
||||
dependencies = [
|
||||
"maplit",
|
||||
"pest",
|
||||
"sha-1",
|
||||
"sha-1 0.8.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3225,14 +3236,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c267f15c3cfc82a8a441d2bf86bcccf299d1eb625822468e3d8ee6f7c5a1c89"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"md-5",
|
||||
"md-5 0.8.0",
|
||||
"rustc-ap-rustc_arena",
|
||||
"rustc-ap-rustc_data_structures",
|
||||
"rustc-ap-rustc_index",
|
||||
"rustc-ap-rustc_macros",
|
||||
"rustc-ap-rustc_serialize",
|
||||
"scoped-tls",
|
||||
"sha-1",
|
||||
"sha-1 0.8.2",
|
||||
"tracing",
|
||||
"unicode-width",
|
||||
]
|
||||
@ -4069,14 +4080,15 @@ name = "rustc_span"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"md-5",
|
||||
"md-5 0.9.1",
|
||||
"rustc_arena",
|
||||
"rustc_data_structures",
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
"rustc_serialize",
|
||||
"scoped-tls",
|
||||
"sha-1",
|
||||
"sha-1 0.9.1",
|
||||
"sha2",
|
||||
"tracing",
|
||||
"unicode-width",
|
||||
]
|
||||
@ -4422,6 +4434,19 @@ dependencies = [
|
||||
"opaque-debug 0.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha-1"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "170a36ea86c864a3f16dd2687712dd6646f7019f301e57537c7f4dc9f5916770"
|
||||
dependencies = [
|
||||
"block-buffer 0.9.0",
|
||||
"cfg-if 0.1.10",
|
||||
"cpuid-bool",
|
||||
"digest 0.9.0",
|
||||
"opaque-debug 0.3.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.9.1"
|
||||
|
@ -805,6 +805,7 @@ fn file_metadata_raw(
|
||||
let kind = match hash.kind {
|
||||
rustc_span::SourceFileHashAlgorithm::Md5 => llvm::ChecksumKind::MD5,
|
||||
rustc_span::SourceFileHashAlgorithm::Sha1 => llvm::ChecksumKind::SHA1,
|
||||
rustc_span::SourceFileHashAlgorithm::Sha256 => llvm::ChecksumKind::SHA256,
|
||||
};
|
||||
(kind, hex_encode(hash.hash_bytes()))
|
||||
}
|
||||
|
@ -557,6 +557,7 @@ pub enum ChecksumKind {
|
||||
None,
|
||||
MD5,
|
||||
SHA1,
|
||||
SHA256,
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
@ -648,6 +648,7 @@ enum class LLVMRustChecksumKind {
|
||||
None,
|
||||
MD5,
|
||||
SHA1,
|
||||
SHA256,
|
||||
};
|
||||
|
||||
static Optional<DIFile::ChecksumKind> fromRust(LLVMRustChecksumKind Kind) {
|
||||
@ -658,6 +659,10 @@ static Optional<DIFile::ChecksumKind> fromRust(LLVMRustChecksumKind Kind) {
|
||||
return DIFile::ChecksumKind::CSK_MD5;
|
||||
case LLVMRustChecksumKind::SHA1:
|
||||
return DIFile::ChecksumKind::CSK_SHA1;
|
||||
#if (LLVM_VERSION_MAJOR >= 11)
|
||||
case LLVMRustChecksumKind::SHA256:
|
||||
return DIFile::ChecksumKind::CSK_SHA256;
|
||||
#endif
|
||||
default:
|
||||
report_fatal_error("bad ChecksumKind.");
|
||||
}
|
||||
|
@ -1068,7 +1068,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
||||
span_free_formats: bool = (false, parse_bool, [UNTRACKED],
|
||||
"exclude spans when debug-printing compiler state (default: no)"),
|
||||
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
|
||||
"hash algorithm of source files in debug info (`md5`, or `sha1`)"),
|
||||
"hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"),
|
||||
strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
|
||||
"tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
|
||||
symbol_mangling_version: SymbolManglingVersion = (SymbolManglingVersion::Legacy,
|
||||
|
@ -17,5 +17,6 @@ scoped-tls = "1.0"
|
||||
unicode-width = "0.1.4"
|
||||
cfg-if = "0.1.2"
|
||||
tracing = "0.1"
|
||||
sha-1 = "0.8"
|
||||
md-5 = "0.8"
|
||||
sha-1 = "0.9"
|
||||
sha2 = "0.9"
|
||||
md-5 = "0.9"
|
||||
|
@ -59,6 +59,7 @@ use std::str::FromStr;
|
||||
use md5::Md5;
|
||||
use sha1::Digest;
|
||||
use sha1::Sha1;
|
||||
use sha2::Sha256;
|
||||
|
||||
use tracing::debug;
|
||||
|
||||
@ -1040,6 +1041,7 @@ pub struct OffsetOverflowError;
|
||||
pub enum SourceFileHashAlgorithm {
|
||||
Md5,
|
||||
Sha1,
|
||||
Sha256,
|
||||
}
|
||||
|
||||
impl FromStr for SourceFileHashAlgorithm {
|
||||
@ -1049,6 +1051,7 @@ impl FromStr for SourceFileHashAlgorithm {
|
||||
match s {
|
||||
"md5" => Ok(SourceFileHashAlgorithm::Md5),
|
||||
"sha1" => Ok(SourceFileHashAlgorithm::Sha1),
|
||||
"sha256" => Ok(SourceFileHashAlgorithm::Sha256),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
@ -1061,7 +1064,7 @@ rustc_data_structures::impl_stable_hash_via_hash!(SourceFileHashAlgorithm);
|
||||
#[derive(HashStable_Generic, Encodable, Decodable)]
|
||||
pub struct SourceFileHash {
|
||||
pub kind: SourceFileHashAlgorithm,
|
||||
value: [u8; 20],
|
||||
value: [u8; 32],
|
||||
}
|
||||
|
||||
impl SourceFileHash {
|
||||
@ -1077,6 +1080,9 @@ impl SourceFileHash {
|
||||
SourceFileHashAlgorithm::Sha1 => {
|
||||
value.copy_from_slice(&Sha1::digest(data));
|
||||
}
|
||||
SourceFileHashAlgorithm::Sha256 => {
|
||||
value.copy_from_slice(&Sha256::digest(data));
|
||||
}
|
||||
}
|
||||
hash
|
||||
}
|
||||
@ -1096,6 +1102,7 @@ impl SourceFileHash {
|
||||
match self.kind {
|
||||
SourceFileHashAlgorithm::Md5 => 16,
|
||||
SourceFileHashAlgorithm::Sha1 => 20,
|
||||
SourceFileHashAlgorithm::Sha256 => 32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ The tracking issue for this feature is: [#70401](https://github.com/rust-lang/ru
|
||||
|
||||
The `-Z src-hash-algorithm` compiler flag controls which algorithm is used when hashing each source file. The hash is stored in the debug info and can be used by a debugger to verify the source code matches the executable.
|
||||
|
||||
Supported hash algorithms are: `md5`, and `sha1`. Note that not all hash algorithms are supported by all debug info formats.
|
||||
Supported hash algorithms are: `md5`, `sha1`, and `sha256`. Note that not all hash algorithms are supported by all debug info formats.
|
||||
|
||||
By default, the compiler chooses the hash algorithm based on the target specification.
|
||||
|
@ -0,0 +1,7 @@
|
||||
// compile-flags: -g -Z src-hash-algorithm=sha256
|
||||
// min-llvm-version: 11.0
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
pub fn test() {}
|
||||
// CHECK: checksumkind: CSK_SHA256
|
@ -80,6 +80,7 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
|
||||
"cloudabi",
|
||||
"cmake",
|
||||
"compiler_builtins",
|
||||
"cpuid-bool",
|
||||
"crc32fast",
|
||||
"crossbeam-deque",
|
||||
"crossbeam-epoch",
|
||||
@ -160,6 +161,7 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"sha-1",
|
||||
"sha2",
|
||||
"smallvec",
|
||||
"snap",
|
||||
"stable_deref_trait",
|
||||
|
Loading…
Reference in New Issue
Block a user