Skip to content

Commit

Permalink
Remove support for decompressing dylib metadata
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bjorn3 committed Oct 31, 2024
1 parent 4d296ea commit 87b9c09
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 35 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4004,7 +4004,6 @@ dependencies = [
"rustc_span",
"rustc_target",
"rustc_type_ir",
"snap",
"tempfile",
"tracing",
]
Expand Down Expand Up @@ -4889,12 +4888,6 @@ version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"

[[package]]
name = "snap"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b"

[[package]]
name = "socket2"
version = "0.5.7"
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
rustc_type_ir = { path = "../rustc_type_ir" }
snap = "1"
tempfile = "3.2"
tracing = "0.1"
# tidy-alphabetical-end
29 changes: 4 additions & 25 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
//! metadata::locator or metadata::creader for all the juicy details!
use std::borrow::Cow;
use std::io::{Read, Result as IoResult, Write};
use std::io::{Result as IoResult, Write};
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::{cmp, fmt};
Expand All @@ -232,7 +232,6 @@ use rustc_session::utils::CanonicalizedPath;
use rustc_span::Span;
use rustc_span::symbol::Symbol;
use rustc_target::spec::{Target, TargetTriple};
use snap::read::FrameDecoder;
use tracing::{debug, info};

use crate::creader::{Library, MetadataLoader};
Expand Down Expand Up @@ -792,7 +791,6 @@ fn get_metadata_section<'p>(
CrateFlavor::Dylib => {
let buf =
loader.get_dylib_metadata(target, filename).map_err(MetadataError::LoadFailure)?;
// The header is uncompressed
let header_len = METADATA_HEADER.len();
// header + u64 length of data
let data_start = header_len + 8;
Expand All @@ -806,37 +804,18 @@ fn get_metadata_section<'p>(
)));
}

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

// Header is okay -> inflate the actual metadata
let compressed_bytes = buf.slice(|buf| &buf[data_start..(data_start + compressed_len)]);
if &compressed_bytes[..cmp::min(METADATA_HEADER.len(), compressed_bytes.len())]
== METADATA_HEADER
{
// The metadata was not actually compressed.
compressed_bytes
} else {
debug!("inflating {} bytes of compressed metadata", compressed_bytes.len());
// Assume the decompressed data will be at least the size of the compressed data, so we
// don't have to grow the buffer as much.
let mut inflated = Vec::with_capacity(compressed_bytes.len());
FrameDecoder::new(&*compressed_bytes).read_to_end(&mut inflated).map_err(|_| {
MetadataError::LoadFailure(format!(
"failed to decompress metadata: {}",
filename.display()
))
})?;

slice_owned(inflated, Deref::deref)
}
buf.slice(|buf| &buf[data_start..(data_start + metadata_len)])
}
CrateFlavor::Rmeta => {
// mmap the file, because only a small fraction of it is read.
Expand Down
2 changes: 0 additions & 2 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ const EXCEPTIONS: ExceptionList = &[
("rustc_apfloat", "Apache-2.0 WITH LLVM-exception"), // rustc (license is the same as LLVM uses)
("ryu", "Apache-2.0 OR BSL-1.0"), // BSL is not acceptble, but we use it under Apache-2.0 // cargo/... (because of serde)
("self_cell", "Apache-2.0"), // rustc (fluent translations)
("snap", "BSD-3-Clause"), // rustc
("wasi-preview1-component-adapter-provider", "Apache-2.0 WITH LLVM-exception"), // rustc
// tidy-alphabetical-end
];
Expand Down Expand Up @@ -390,7 +389,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
"sharded-slab",
"shlex",
"smallvec",
"snap",
"stable_deref_trait",
"stacker",
"static_assertions",
Expand Down

0 comments on commit 87b9c09

Please sign in to comment.