Skip to content

Commit

Permalink
rustc: Change the filename of compressed bitcode
Browse files Browse the repository at this point in the history
Fixes #12992
Store compressed bitcode files in rlibs with a different extension. Compression doesn't interfere with --emit=bc.
Regression test compares outputs.
  • Loading branch information
pczarn committed Mar 23, 2014
1 parent 11c6817 commit f0f5072
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,16 +937,18 @@ fn link_rlib<'a>(sess: &'a Session,
// For LTO purposes, the bytecode of this library is also inserted
// into the archive.
let bc = obj_filename.with_extension("bc");
let bc_deflated = obj_filename.with_extension("bc.deflate");
match fs::File::open(&bc).read_to_end().and_then(|data| {
fs::File::create(&bc).write(flate::deflate_bytes(data).as_slice())
fs::File::create(&bc_deflated).write(flate::deflate_bytes(data).as_slice())
}) {
Ok(()) => {}
Err(e) => {
sess.err(format!("failed to compress bytecode: {}", e));
sess.abort_if_errors()
}
}
a.add_file(&bc, false);
a.add_file(&bc_deflated, false);
remove(sess, &bc_deflated);
if !sess.opts.cg.save_temps &&
!sess.opts.output_types.contains(&OutputTypeBitcode) {
remove(sess, &bc);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,

let archive = ArchiveRO::open(&path).expect("wanted an rlib");
debug!("reading {}", name);
let bc = time(sess.time_passes(), format!("read {}.bc", name), (), |_|
archive.read(format!("{}.bc", name)));
let bc = bc.expect("missing bytecode in archive!");
let bc = time(sess.time_passes(), format!("read {}.bc.deflate", name), (), |_|
archive.read(format!("{}.bc.deflate", name)));
let bc = bc.expect("missing compressed bytecode in archive!");
let bc = time(sess.time_passes(), format!("inflate {}.bc", name), (), |_|
flate::inflate_bytes(bc));
let ptr = bc.as_slice().as_ptr();
Expand Down
4 changes: 3 additions & 1 deletion src/test/run-make/output-type-permutations/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ all:
rm $(TMPDIR)/bar
$(RUSTC) foo.rs --emit=asm,ir,bc,obj,link --crate-type=staticlib
rm $(TMPDIR)/bar.ll
rm $(TMPDIR)/bar.bc
rm $(TMPDIR)/bar.s
rm $(TMPDIR)/bar.o
rm $(TMPDIR)/$(call STATICLIB_GLOB,bar)
Expand All @@ -37,6 +36,9 @@ all:
rm $(TMPDIR)/foo
$(RUSTC) foo.rs --crate-type=bin -o $(TMPDIR)/foo
rm $(TMPDIR)/foo
mv $(TMPDIR)/bar.bc $(TMPDIR)/foo.bc
$(RUSTC) foo.rs --emit=bc,link --crate-type=rlib
cmp $(TMPDIR)/foo.bc $(TMPDIR)/bar.bc
rm $(TMPDIR)/bar.bc
rm $(TMPDIR)/foo.bc
rm $(TMPDIR)/$(call RLIB_GLOB,bar)

9 comments on commit f0f5072

@bors
Copy link
Contributor

@bors bors commented on f0f5072 Mar 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at pczarn@f0f5072

@bors
Copy link
Contributor

@bors bors commented on f0f5072 Mar 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pczarn/rust/build-rlib = f0f5072 into auto

@bors
Copy link
Contributor

@bors bors commented on f0f5072 Mar 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pczarn/rust/build-rlib = f0f5072 merged ok, testing candidate = e5bce54d

@bors
Copy link
Contributor

@bors bors commented on f0f5072 Mar 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on f0f5072 Mar 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at pczarn@f0f5072

@bors
Copy link
Contributor

@bors bors commented on f0f5072 Mar 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pczarn/rust/build-rlib = f0f5072 into auto

@bors
Copy link
Contributor

@bors bors commented on f0f5072 Mar 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pczarn/rust/build-rlib = f0f5072 merged ok, testing candidate = 841f31e

@bors
Copy link
Contributor

@bors bors commented on f0f5072 Mar 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on f0f5072 Mar 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 841f31e

Please sign in to comment.