Auto merge of #132402 - bjorn3:remove_snap_decompression, r=jieyouxu,Veykril
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. Fixes https://github.com/rust-lang/rust-analyzer/issues/18451
This commit is contained in:
commit
145f9cf95d
@ -4006,7 +4006,6 @@ dependencies = [
|
|||||||
"rustc_span",
|
"rustc_span",
|
||||||
"rustc_target",
|
"rustc_target",
|
||||||
"rustc_type_ir",
|
"rustc_type_ir",
|
||||||
"snap",
|
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
@ -4891,12 +4890,6 @@ version = "1.13.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "snap"
|
|
||||||
version = "1.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "socket2"
|
name = "socket2"
|
||||||
version = "0.5.7"
|
version = "0.5.7"
|
||||||
|
@ -27,7 +27,6 @@ rustc_session = { path = "../rustc_session" }
|
|||||||
rustc_span = { path = "../rustc_span" }
|
rustc_span = { path = "../rustc_span" }
|
||||||
rustc_target = { path = "../rustc_target" }
|
rustc_target = { path = "../rustc_target" }
|
||||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||||
snap = "1"
|
|
||||||
tempfile = "3.2"
|
tempfile = "3.2"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
# tidy-alphabetical-end
|
# tidy-alphabetical-end
|
||||||
|
@ -213,7 +213,7 @@
|
|||||||
//! metadata::locator or metadata::creader for all the juicy details!
|
//! metadata::locator or metadata::creader for all the juicy details!
|
||||||
|
|
||||||
use std::borrow::Cow;
|
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::ops::Deref;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::{cmp, fmt};
|
use std::{cmp, fmt};
|
||||||
@ -232,7 +232,6 @@
|
|||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_target::spec::{Target, TargetTriple};
|
use rustc_target::spec::{Target, TargetTriple};
|
||||||
use snap::read::FrameDecoder;
|
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use crate::creader::{Library, MetadataLoader};
|
use crate::creader::{Library, MetadataLoader};
|
||||||
@ -792,7 +791,6 @@ fn get_metadata_section<'p>(
|
|||||||
CrateFlavor::Dylib => {
|
CrateFlavor::Dylib => {
|
||||||
let buf =
|
let buf =
|
||||||
loader.get_dylib_metadata(target, filename).map_err(MetadataError::LoadFailure)?;
|
loader.get_dylib_metadata(target, filename).map_err(MetadataError::LoadFailure)?;
|
||||||
// The header is uncompressed
|
|
||||||
let header_len = METADATA_HEADER.len();
|
let header_len = METADATA_HEADER.len();
|
||||||
// header + u64 length of data
|
// header + u64 length of data
|
||||||
let data_start = header_len + 8;
|
let data_start = header_len + 8;
|
||||||
@ -806,7 +804,7 @@ 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) =
|
let Ok(len_bytes) =
|
||||||
<[u8; 8]>::try_from(&buf[header_len..cmp::min(data_start, buf.len())])
|
<[u8; 8]>::try_from(&buf[header_len..cmp::min(data_start, buf.len())])
|
||||||
else {
|
else {
|
||||||
@ -814,29 +812,10 @@ fn get_metadata_section<'p>(
|
|||||||
"invalid metadata length found".to_string(),
|
"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
|
// Header is okay -> inflate the actual metadata
|
||||||
let compressed_bytes = buf.slice(|buf| &buf[data_start..(data_start + compressed_len)]);
|
buf.slice(|buf| &buf[data_start..(data_start + metadata_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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
CrateFlavor::Rmeta => {
|
CrateFlavor::Rmeta => {
|
||||||
// mmap the file, because only a small fraction of it is read.
|
// mmap the file, because only a small fraction of it is read.
|
||||||
|
@ -1364,7 +1364,6 @@ dependencies = [
|
|||||||
"proc-macro-api",
|
"proc-macro-api",
|
||||||
"proc-macro-test",
|
"proc-macro-test",
|
||||||
"ra-ap-rustc_lexer",
|
"ra-ap-rustc_lexer",
|
||||||
"snap",
|
|
||||||
"span",
|
"span",
|
||||||
"stdx",
|
"stdx",
|
||||||
"syntax-bridge",
|
"syntax-bridge",
|
||||||
@ -1888,12 +1887,6 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "snap"
|
|
||||||
version = "1.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "span"
|
name = "span"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
@ -145,7 +145,6 @@ smallvec = { version = "1.10.0", features = [
|
|||||||
"const_generics",
|
"const_generics",
|
||||||
] }
|
] }
|
||||||
smol_str = "0.3.2"
|
smol_str = "0.3.2"
|
||||||
snap = "1.1.0"
|
|
||||||
text-size = "1.1.1"
|
text-size = "1.1.1"
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-tree = "0.3.0"
|
tracing-tree = "0.3.0"
|
||||||
|
@ -16,7 +16,6 @@ doctest = false
|
|||||||
object.workspace = true
|
object.workspace = true
|
||||||
libloading.workspace = true
|
libloading.workspace = true
|
||||||
memmap2.workspace = true
|
memmap2.workspace = true
|
||||||
snap.workspace = true
|
|
||||||
|
|
||||||
stdx.workspace = true
|
stdx.workspace = true
|
||||||
tt.workspace = true
|
tt.workspace = true
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
use memmap2::Mmap;
|
use memmap2::Mmap;
|
||||||
use object::read::{File as BinaryFile, Object, ObjectSection};
|
use object::read::{File as BinaryFile, Object, ObjectSection};
|
||||||
use paths::AbsPath;
|
use paths::AbsPath;
|
||||||
use snap::read::FrameDecoder as SnapDecoder;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -123,9 +122,8 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
|
|||||||
let version = u32::from_be_bytes([dot_rustc[4], dot_rustc[5], dot_rustc[6], dot_rustc[7]]);
|
let version = u32::from_be_bytes([dot_rustc[4], dot_rustc[5], dot_rustc[6], dot_rustc[7]]);
|
||||||
// Last supported version is:
|
// Last supported version is:
|
||||||
// https://github.com/rust-lang/rust/commit/b94cfefc860715fb2adf72a6955423d384c69318
|
// https://github.com/rust-lang/rust/commit/b94cfefc860715fb2adf72a6955423d384c69318
|
||||||
let (snappy_portion, bytes_before_version) = match version {
|
let (mut metadata_portion, bytes_before_version) = match version {
|
||||||
5 | 6 => (&dot_rustc[8..], 13),
|
8 => {
|
||||||
7 | 8 => {
|
|
||||||
let len_bytes = &dot_rustc[8..12];
|
let len_bytes = &dot_rustc[8..12];
|
||||||
let data_len = u32::from_be_bytes(len_bytes.try_into().unwrap()) as usize;
|
let data_len = u32::from_be_bytes(len_bytes.try_into().unwrap()) as usize;
|
||||||
(&dot_rustc[12..data_len + 12], 13)
|
(&dot_rustc[12..data_len + 12], 13)
|
||||||
@ -143,13 +141,6 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut uncompressed: Box<dyn Read> = if &snappy_portion[0..4] == b"rust" {
|
|
||||||
// Not compressed.
|
|
||||||
Box::new(snappy_portion)
|
|
||||||
} else {
|
|
||||||
Box::new(SnapDecoder::new(snappy_portion))
|
|
||||||
};
|
|
||||||
|
|
||||||
// We're going to skip over the bytes before the version string, so basically:
|
// We're going to skip over the bytes before the version string, so basically:
|
||||||
// 8 bytes for [b'r',b'u',b's',b't',0,0,0,5]
|
// 8 bytes for [b'r',b'u',b's',b't',0,0,0,5]
|
||||||
// 4 or 8 bytes for [crate root bytes]
|
// 4 or 8 bytes for [crate root bytes]
|
||||||
@ -157,11 +148,11 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
|
|||||||
// so 13 or 17 bytes in total, and we should check the last of those bytes
|
// so 13 or 17 bytes in total, and we should check the last of those bytes
|
||||||
// to know the length
|
// to know the length
|
||||||
let mut bytes = [0u8; 17];
|
let mut bytes = [0u8; 17];
|
||||||
uncompressed.read_exact(&mut bytes[..bytes_before_version])?;
|
metadata_portion.read_exact(&mut bytes[..bytes_before_version])?;
|
||||||
let length = bytes[bytes_before_version - 1];
|
let length = bytes[bytes_before_version - 1];
|
||||||
|
|
||||||
let mut version_string_utf8 = vec![0u8; length as usize];
|
let mut version_string_utf8 = vec![0u8; length as usize];
|
||||||
uncompressed.read_exact(&mut version_string_utf8)?;
|
metadata_portion.read_exact(&mut version_string_utf8)?;
|
||||||
let version_string = String::from_utf8(version_string_utf8);
|
let version_string = String::from_utf8(version_string_utf8);
|
||||||
version_string.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
version_string.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,6 @@
|
|||||||
("rustc_apfloat", "Apache-2.0 WITH LLVM-exception"), // rustc (license is the same as LLVM uses)
|
("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)
|
("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)
|
("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
|
("wasi-preview1-component-adapter-provider", "Apache-2.0 WITH LLVM-exception"), // rustc
|
||||||
// tidy-alphabetical-end
|
// tidy-alphabetical-end
|
||||||
];
|
];
|
||||||
@ -163,7 +162,6 @@
|
|||||||
("rustc_apfloat", "Apache-2.0 WITH LLVM-exception"),
|
("rustc_apfloat", "Apache-2.0 WITH LLVM-exception"),
|
||||||
("ryu", "Apache-2.0 OR BSL-1.0"), // BSL is not acceptble, but we use it under Apache-2.0
|
("ryu", "Apache-2.0 OR BSL-1.0"), // BSL is not acceptble, but we use it under Apache-2.0
|
||||||
("scip", "Apache-2.0"),
|
("scip", "Apache-2.0"),
|
||||||
("snap", "BSD-3-Clause"),
|
|
||||||
// tidy-alphabetical-end
|
// tidy-alphabetical-end
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -391,7 +389,6 @@
|
|||||||
"sharded-slab",
|
"sharded-slab",
|
||||||
"shlex",
|
"shlex",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"snap",
|
|
||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
"stacker",
|
"stacker",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
|
Loading…
Reference in New Issue
Block a user