@@ -846,7 +846,7 @@ fn link_binary_output(sess: &Session,
846
846
847
847
match crate_type {
848
848
session:: CrateTypeRlib => {
849
- link_rlib ( sess, Some ( trans) , & obj_filename, & out_filename) ;
849
+ link_rlib ( sess, Some ( ( trans, id ) ) , & obj_filename, & out_filename) ;
850
850
}
851
851
session:: CrateTypeStaticlib => {
852
852
link_staticlib ( sess, & obj_filename, & out_filename) ;
@@ -869,7 +869,8 @@ fn link_binary_output(sess: &Session,
869
869
// all of the object files from native libraries. This is done by unzipping
870
870
// native libraries and inserting all of the contents into this archive.
871
871
fn link_rlib < ' a > ( sess : & ' a Session ,
872
- trans : Option < & CrateTranslation > , // None == no metadata/bytecode
872
+ // None == no metadata/bytecode
873
+ trans : Option < ( & CrateTranslation , & CrateId ) > ,
873
874
obj_filename : & Path ,
874
875
out_filename : & Path ) -> Archive < ' a > {
875
876
let mut a = Archive :: create ( sess, out_filename, obj_filename) ;
@@ -905,7 +906,7 @@ fn link_rlib<'a>(sess: &'a Session,
905
906
// Basically, all this means is that this code should not move above the
906
907
// code above.
907
908
match trans {
908
- Some ( trans) => {
909
+ Some ( ( trans, id ) ) => {
909
910
// Instead of putting the metadata in an object file section, rlibs
910
911
// contain the metadata in a separate file. We use a temp directory
911
912
// here so concurrent builds in the same directory don't try to use
@@ -925,11 +926,15 @@ fn link_rlib<'a>(sess: &'a Session,
925
926
remove ( sess, & metadata) ;
926
927
927
928
// For LTO purposes, the bytecode of this library is also inserted
928
- // into the archive.
929
+ // into the archive. Note that we ensure that the bytecode has the
930
+ // same name as the crate id's name because it's how we'll search
931
+ // for the bytecode later on.
929
932
let bc = obj_filename. with_extension ( "bc" ) ;
930
- let bc_deflated = obj_filename. with_extension ( "bc.deflate" ) ;
933
+ let bc_deflated = tmpdir. path ( ) . join ( id. name . as_slice ( ) )
934
+ . with_extension ( "bc.deflate" ) ;
931
935
match fs:: File :: open ( & bc) . read_to_end ( ) . and_then ( |data| {
932
- fs:: File :: create ( & bc_deflated) . write ( flate:: deflate_bytes ( data) . as_slice ( ) )
936
+ let bytes = flate:: deflate_bytes ( data) ;
937
+ fs:: File :: create ( & bc_deflated) . write ( bytes. as_slice ( ) )
933
938
} ) {
934
939
Ok ( ( ) ) => { }
935
940
Err ( e) => {
@@ -938,7 +943,6 @@ fn link_rlib<'a>(sess: &'a Session,
938
943
}
939
944
}
940
945
a. add_file ( & bc_deflated, false ) ;
941
- remove ( sess, & bc_deflated) ;
942
946
if !sess. opts . cg . save_temps &&
943
947
!sess. opts . output_types . contains ( & OutputTypeBitcode ) {
944
948
remove ( sess, & bc) ;
0 commit comments