From 041d8e899f5eecd435844ce5ad86dd2aadea3a46 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 22 Aug 2013 13:46:47 -0700 Subject: [PATCH] Allow metadata to be not compressed --- Makefile.in | 6 ++++++ configure | 4 +++- src/librustc/driver/driver.rs | 7 ++++++- src/librustc/driver/session.rs | 2 ++ src/librustc/metadata/encoder.rs | 16 +++++++++++++--- src/librustc/metadata/loader.rs | 25 +++++++++++++++++++------ src/librustc/middle/trans/base.rs | 1 + 7 files changed, 50 insertions(+), 11 deletions(-) diff --git a/Makefile.in b/Makefile.in index a9a41a073d0..fb0bb6ff379 100644 --- a/Makefile.in +++ b/Makefile.in @@ -107,6 +107,12 @@ else CFG_GCCISH_CFLAGS += -DRUST_NDEBUG endif +ifndef CFG_ENABLE_COMPRESS_METADATA + # XXX: After snapshots extend this to all stages + RUSTFLAGS_STAGE1 += --no-compress-metadata + RUSTFLAGS_STAGE2 += --no-compress-metadata +endif + ifdef SAVE_TEMPS CFG_RUSTC_FLAGS += --save-temps endif diff --git a/configure b/configure index f070ae37dda..8a7a2bae4ea 100755 --- a/configure +++ b/configure @@ -381,7 +381,9 @@ opt mingw-cross 0 "cross-compile for win32 using mingw" opt clang 0 "prefer clang to gcc for building the runtime" opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds" opt local-rust 0 "use an installed rustc rather than downloading a snapshot" -opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched kernels)" +opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched + kernels)" +opt compress-metadata 0 "compress crate metadata" valopt prefix "/usr/local" "set installation prefix" valopt local-rust-root "/usr/local" "set prefix for local rust binary" valopt llvm-root "" "set LLVM root" diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 1ddebbb4280..bba818c7c9d 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -718,6 +718,8 @@ pub fn build_session_options(binary: @str, let android_cross_path = getopts::opt_maybe_str( matches, "android-cross-path"); + let no_compress_metadata = opt_present(matches, "no-compress-metadata"); + let custom_passes = match getopts::opt_maybe_str(matches, "passes") { None => ~[], Some(s) => { @@ -752,7 +754,8 @@ pub fn build_session_options(binary: @str, parse_only: parse_only, no_trans: no_trans, debugging_opts: debugging_opts, - android_cross_path: android_cross_path + android_cross_path: android_cross_path, + no_compress_metadata: no_compress_metadata }; return sopts; } @@ -870,6 +873,8 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] { for details)", "FEATURE"), optopt("", "android-cross-path", "The path to the Android NDK", "PATH"), + optflag("", "no-compress-metadata", + "Do not compress crate metadata (make builds a little faster)"), optflagopt("W", "warn", "Set lint warnings", "OPT"), optmulti("A", "allow", diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 50b29ff16be..e70ac52a0f5 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -166,6 +166,7 @@ pub struct options { no_trans: bool, debugging_opts: uint, android_cross_path: Option<~str>, + no_compress_metadata: bool } pub struct crate_metadata { @@ -350,6 +351,7 @@ pub fn basic_options() -> @options { no_trans: false, debugging_opts: 0u, android_cross_path: None, + no_compress_metadata: false } } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 1e9214e666b..3ada5592f75 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -64,6 +64,7 @@ pub struct EncodeParams<'self> { cstore: @mut cstore::CStore, encode_inlined_item: encode_inlined_item<'self>, reachable: @mut HashSet, + compress: bool } struct Stats { @@ -1567,7 +1568,7 @@ pub static metadata_encoding_version : &'static [u8] = 0x75, //'u' as u8, 0x73, //'s' as u8, 0x74, //'t' as u8, - 0, 0, 0, 1 ]; + 0, 0, 0, 2 ]; pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] { let wr = @io::BytesWriter::new(); @@ -1594,6 +1595,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] { encode_inlined_item, link_meta, reachable, + compress, _ } = parms; let type_abbrevs = @mut HashMap::new(); @@ -1679,9 +1681,17 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] { wr.write(&[0u8, 0u8, 0u8, 0u8]); let writer_bytes: &mut ~[u8] = wr.bytes; + let compression_flag = if compress { [1u8] } else { [0u8] }; - metadata_encoding_version.to_owned() + - flate::deflate_bytes(*writer_bytes) + if compress { + metadata_encoding_version.to_owned() + + compression_flag.to_owned() + + flate::deflate_bytes(*writer_bytes) + } else { + metadata_encoding_version.to_owned() + + compression_flag.to_owned() + + *writer_bytes + } } // Get the encoded string for a type diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index d0060931a66..f374ce2c19a 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -228,13 +228,26 @@ fn get_metadata_section(os: os, } if !version_ok { return None; } - let cvbuf1 = ptr::offset(cvbuf, vlen as int); - debug!("inflating %u bytes of compressed metadata", - csz - vlen); - do vec::raw::buf_as_slice(cvbuf1, csz-vlen) |bytes| { - let inflated = flate::inflate_bytes(bytes); - found = Some(@(inflated)); + assert!(csz >= vlen + 1); + + let must_decompress = *ptr::offset(cvbuf, vlen as int) == 1; + let cvbuf1 = ptr::offset(cvbuf, vlen as int + 1); + + do vec::raw::buf_as_slice(cvbuf1, csz-vlen-1) |bytes| { + if must_decompress { + debug!("inflating %u bytes of compressed metadata", + csz - vlen); + let inflated = flate::inflate_bytes(bytes); + found = Some(@(inflated)); + } else { + // Copy the byte vector as fast as possible + let mut buf = vec::with_capacity(bytes.len()); + vec::raw::set_len(&mut buf, bytes.len()); + vec::raw::copy_memory(buf, bytes, bytes.len()); + found = Some(@buf) + } } + if found != None { return found; } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index f19decaa38c..85db79ca54b 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2907,6 +2907,7 @@ pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::encode_ cstore: cx.sess.cstore, encode_inlined_item: ie, reachable: cx.reachable, + compress: !cx.sess.opts.no_compress_metadata } }