Skip to content

Commit 87b9c09

Browse files
committed
Remove support for decompressing dylib metadata
We haven't been compressing dylib metadata for a while now. Removing decompression support will regress error messages about an incompatible rustc version being used, but dylibs are pretty rare anyway.
1 parent 4d296ea commit 87b9c09

File tree

4 files changed

+4
-35
lines changed

4 files changed

+4
-35
lines changed

Cargo.lock

-7
Original file line numberDiff line numberDiff line change
@@ -4004,7 +4004,6 @@ dependencies = [
40044004
"rustc_span",
40054005
"rustc_target",
40064006
"rustc_type_ir",
4007-
"snap",
40084007
"tempfile",
40094008
"tracing",
40104009
]
@@ -4889,12 +4888,6 @@ version = "1.13.2"
48894888
source = "registry+https://github.com/rust-lang/crates.io-index"
48904889
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
48914890

4892-
[[package]]
4893-
name = "snap"
4894-
version = "1.1.1"
4895-
source = "registry+https://github.com/rust-lang/crates.io-index"
4896-
checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b"
4897-
48984891
[[package]]
48994892
name = "socket2"
49004893
version = "0.5.7"

compiler/rustc_metadata/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ rustc_session = { path = "../rustc_session" }
2727
rustc_span = { path = "../rustc_span" }
2828
rustc_target = { path = "../rustc_target" }
2929
rustc_type_ir = { path = "../rustc_type_ir" }
30-
snap = "1"
3130
tempfile = "3.2"
3231
tracing = "0.1"
3332
# tidy-alphabetical-end

compiler/rustc_metadata/src/locator.rs

+4-25
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
//! metadata::locator or metadata::creader for all the juicy details!
214214
215215
use std::borrow::Cow;
216-
use std::io::{Read, Result as IoResult, Write};
216+
use std::io::{Result as IoResult, Write};
217217
use std::ops::Deref;
218218
use std::path::{Path, PathBuf};
219219
use std::{cmp, fmt};
@@ -232,7 +232,6 @@ use rustc_session::utils::CanonicalizedPath;
232232
use rustc_span::Span;
233233
use rustc_span::symbol::Symbol;
234234
use rustc_target::spec::{Target, TargetTriple};
235-
use snap::read::FrameDecoder;
236235
use tracing::{debug, info};
237236

238237
use crate::creader::{Library, MetadataLoader};
@@ -792,7 +791,6 @@ fn get_metadata_section<'p>(
792791
CrateFlavor::Dylib => {
793792
let buf =
794793
loader.get_dylib_metadata(target, filename).map_err(MetadataError::LoadFailure)?;
795-
// The header is uncompressed
796794
let header_len = METADATA_HEADER.len();
797795
// header + u64 length of data
798796
let data_start = header_len + 8;
@@ -806,37 +804,18 @@ fn get_metadata_section<'p>(
806804
)));
807805
}
808806

809-
// Length of the compressed stream - this allows linkers to pad the section if they want
807+
// Length of the metadata - this allows linkers to pad the section if they want
810808
let Ok(len_bytes) =
811809
<[u8; 8]>::try_from(&buf[header_len..cmp::min(data_start, buf.len())])
812810
else {
813811
return Err(MetadataError::LoadFailure(
814812
"invalid metadata length found".to_string(),
815813
));
816814
};
817-
let compressed_len = u64::from_le_bytes(len_bytes) as usize;
815+
let metadata_len = u64::from_le_bytes(len_bytes) as usize;
818816

819817
// Header is okay -> inflate the actual metadata
820-
let compressed_bytes = buf.slice(|buf| &buf[data_start..(data_start + compressed_len)]);
821-
if &compressed_bytes[..cmp::min(METADATA_HEADER.len(), compressed_bytes.len())]
822-
== METADATA_HEADER
823-
{
824-
// The metadata was not actually compressed.
825-
compressed_bytes
826-
} else {
827-
debug!("inflating {} bytes of compressed metadata", compressed_bytes.len());
828-
// Assume the decompressed data will be at least the size of the compressed data, so we
829-
// don't have to grow the buffer as much.
830-
let mut inflated = Vec::with_capacity(compressed_bytes.len());
831-
FrameDecoder::new(&*compressed_bytes).read_to_end(&mut inflated).map_err(|_| {
832-
MetadataError::LoadFailure(format!(
833-
"failed to decompress metadata: {}",
834-
filename.display()
835-
))
836-
})?;
837-
838-
slice_owned(inflated, Deref::deref)
839-
}
818+
buf.slice(|buf| &buf[data_start..(data_start + metadata_len)])
840819
}
841820
CrateFlavor::Rmeta => {
842821
// mmap the file, because only a small fraction of it is read.

src/tools/tidy/src/deps.rs

-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ const EXCEPTIONS: ExceptionList = &[
100100
("rustc_apfloat", "Apache-2.0 WITH LLVM-exception"), // rustc (license is the same as LLVM uses)
101101
("ryu", "Apache-2.0 OR BSL-1.0"), // BSL is not acceptble, but we use it under Apache-2.0 // cargo/... (because of serde)
102102
("self_cell", "Apache-2.0"), // rustc (fluent translations)
103-
("snap", "BSD-3-Clause"), // rustc
104103
("wasi-preview1-component-adapter-provider", "Apache-2.0 WITH LLVM-exception"), // rustc
105104
// tidy-alphabetical-end
106105
];
@@ -390,7 +389,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
390389
"sharded-slab",
391390
"shlex",
392391
"smallvec",
393-
"snap",
394392
"stable_deref_trait",
395393
"stacker",
396394
"static_assertions",

0 commit comments

Comments
 (0)