88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- use back:: archive:: { Archive , METADATA_FILENAME } ;
12- use back:: rpath;
13- use back:: svh:: Svh ;
11+ use super :: archive:: { Archive , ArchiveConfig , METADATA_FILENAME } ;
12+ use super :: rpath;
13+ use super :: rpath:: RPathConfig ;
14+ use super :: svh:: Svh ;
1415use driver:: driver:: { CrateTranslation , OutputFilenames , Input , FileInput } ;
1516use driver:: config:: NoDebugInfo ;
1617use driver:: session:: Session ;
1718use driver:: config;
18- use lib:: llvm:: llvm;
19- use lib:: llvm:: ModuleRef ;
20- use lib;
19+ use llvm;
20+ use llvm:: ModuleRef ;
2121use metadata:: common:: LinkMeta ;
2222use metadata:: { encoder, cstore, filesearch, csearch, loader, creader} ;
2323use middle:: trans:: context:: CrateContext ;
@@ -29,6 +29,7 @@ use util::sha2::{Digest, Sha256};
2929
3030use std:: c_str:: { ToCStr , CString } ;
3131use std:: char;
32+ use std:: collections:: HashSet ;
3233use std:: io:: { fs, TempDir , Command } ;
3334use std:: io;
3435use std:: ptr;
@@ -70,11 +71,11 @@ pub fn llvm_err(sess: &Session, msg: String) -> ! {
7071
7172pub fn write_output_file (
7273 sess : & Session ,
73- target : lib :: llvm:: TargetMachineRef ,
74- pm : lib :: llvm:: PassManagerRef ,
74+ target : llvm:: TargetMachineRef ,
75+ pm : llvm:: PassManagerRef ,
7576 m : ModuleRef ,
7677 output : & Path ,
77- file_type : lib :: llvm:: FileType ) {
78+ file_type : llvm:: FileType ) {
7879 unsafe {
7980 output. with_c_str ( |output| {
8081 let result = llvm:: LLVMRustWriteOutputFile (
@@ -88,18 +89,17 @@ pub fn write_output_file(
8889
8990pub mod write {
9091
91- use back :: lto;
92- use back :: link :: { write_output_file, OutputType } ;
93- use back :: link :: { OutputTypeAssembly , OutputTypeBitcode } ;
94- use back :: link :: { OutputTypeExe , OutputTypeLlvmAssembly } ;
95- use back :: link :: { OutputTypeObject } ;
92+ use super :: super :: lto;
93+ use super :: { write_output_file, OutputType } ;
94+ use super :: { OutputTypeAssembly , OutputTypeBitcode } ;
95+ use super :: { OutputTypeExe , OutputTypeLlvmAssembly } ;
96+ use super :: { OutputTypeObject } ;
9697 use driver:: driver:: { CrateTranslation , OutputFilenames } ;
9798 use driver:: config:: NoDebugInfo ;
9899 use driver:: session:: Session ;
99100 use driver:: config;
100- use lib:: llvm:: llvm;
101- use lib:: llvm:: { ModuleRef , TargetMachineRef , PassManagerRef } ;
102- use lib;
101+ use llvm;
102+ use llvm:: { ModuleRef , TargetMachineRef , PassManagerRef } ;
103103 use util:: common:: time;
104104 use syntax:: abi;
105105
@@ -152,10 +152,10 @@ pub mod write {
152152 }
153153
154154 let opt_level = match sess. opts . optimize {
155- config:: No => lib :: llvm:: CodeGenLevelNone ,
156- config:: Less => lib :: llvm:: CodeGenLevelLess ,
157- config:: Default => lib :: llvm:: CodeGenLevelDefault ,
158- config:: Aggressive => lib :: llvm:: CodeGenLevelAggressive ,
155+ config:: No => llvm:: CodeGenLevelNone ,
156+ config:: Less => llvm:: CodeGenLevelLess ,
157+ config:: Default => llvm:: CodeGenLevelDefault ,
158+ config:: Aggressive => llvm:: CodeGenLevelAggressive ,
159159 } ;
160160 let use_softfp = sess. opts . cg . soft_float ;
161161
@@ -172,10 +172,10 @@ pub mod write {
172172 let fdata_sections = ffunction_sections;
173173
174174 let reloc_model = match sess. opts . cg . relocation_model . as_slice ( ) {
175- "pic" => lib :: llvm:: RelocPIC ,
176- "static" => lib :: llvm:: RelocStatic ,
177- "default" => lib :: llvm:: RelocDefault ,
178- "dynamic-no-pic" => lib :: llvm:: RelocDynamicNoPic ,
175+ "pic" => llvm:: RelocPIC ,
176+ "static" => llvm:: RelocStatic ,
177+ "default" => llvm:: RelocDefault ,
178+ "dynamic-no-pic" => llvm:: RelocDynamicNoPic ,
179179 _ => {
180180 sess. err ( format ! ( "{} is not a valid relocation mode" ,
181181 sess. opts
@@ -195,7 +195,7 @@ pub mod write {
195195 target_feature ( sess) . with_c_str ( |features| {
196196 llvm:: LLVMRustCreateTargetMachine (
197197 t, cpu, features,
198- lib :: llvm:: CodeModelDefault ,
198+ llvm:: CodeModelDefault ,
199199 reloc_model,
200200 opt_level,
201201 true /* EnableSegstk */ ,
@@ -320,7 +320,7 @@ pub mod write {
320320 } ;
321321 with_codegen ( tm, llmod, trans. no_builtins , |cpm| {
322322 write_output_file ( sess, tm, cpm, llmod, & path,
323- lib :: llvm:: AssemblyFile ) ;
323+ llvm:: AssemblyFile ) ;
324324 } ) ;
325325 }
326326 OutputTypeObject => {
@@ -338,7 +338,7 @@ pub mod write {
338338 Some ( ref path) => {
339339 with_codegen ( tm, llmod, trans. no_builtins , |cpm| {
340340 write_output_file ( sess, tm, cpm, llmod, path,
341- lib :: llvm:: ObjectFile ) ;
341+ llvm:: ObjectFile ) ;
342342 } ) ;
343343 }
344344 None => { }
@@ -350,7 +350,7 @@ pub mod write {
350350 . with_extension ( "metadata.o" ) ;
351351 write_output_file ( sess, tm, cpm,
352352 trans. metadata_module , & out,
353- lib :: llvm:: ObjectFile ) ;
353+ llvm:: ObjectFile ) ;
354354 } )
355355 }
356356 } ) ;
@@ -455,29 +455,29 @@ pub mod write {
455455 } ) ;
456456 }
457457
458- unsafe fn populate_llvm_passes ( fpm : lib :: llvm:: PassManagerRef ,
459- mpm : lib :: llvm:: PassManagerRef ,
458+ unsafe fn populate_llvm_passes ( fpm : llvm:: PassManagerRef ,
459+ mpm : llvm:: PassManagerRef ,
460460 llmod : ModuleRef ,
461- opt : lib :: llvm:: CodeGenOptLevel ,
461+ opt : llvm:: CodeGenOptLevel ,
462462 no_builtins : bool ) {
463463 // Create the PassManagerBuilder for LLVM. We configure it with
464464 // reasonable defaults and prepare it to actually populate the pass
465465 // manager.
466466 let builder = llvm:: LLVMPassManagerBuilderCreate ( ) ;
467467 match opt {
468- lib :: llvm:: CodeGenLevelNone => {
468+ llvm:: CodeGenLevelNone => {
469469 // Don't add lifetime intrinsics at O0
470470 llvm:: LLVMRustAddAlwaysInlinePass ( builder, false ) ;
471471 }
472- lib :: llvm:: CodeGenLevelLess => {
472+ llvm:: CodeGenLevelLess => {
473473 llvm:: LLVMRustAddAlwaysInlinePass ( builder, true ) ;
474474 }
475475 // numeric values copied from clang
476- lib :: llvm:: CodeGenLevelDefault => {
476+ llvm:: CodeGenLevelDefault => {
477477 llvm:: LLVMPassManagerBuilderUseInlinerWithThreshold ( builder,
478478 225 ) ;
479479 }
480- lib :: llvm:: CodeGenLevelAggressive => {
480+ llvm:: CodeGenLevelAggressive => {
481481 llvm:: LLVMPassManagerBuilderUseInlinerWithThreshold ( builder,
482482 275 ) ;
483483 }
@@ -611,7 +611,7 @@ pub fn build_link_meta(sess: &Session, krate: &ast::Crate,
611611 name : String ) -> LinkMeta {
612612 let r = LinkMeta {
613613 crate_name : name,
614- crate_hash : Svh :: calculate ( sess, krate) ,
614+ crate_hash : Svh :: calculate ( & sess. opts . cg . metadata , krate) ,
615615 } ;
616616 info ! ( "{}" , r) ;
617617 return r;
@@ -963,6 +963,17 @@ fn link_binary_output(sess: &Session,
963963 out_filename
964964}
965965
966+ fn archive_search_paths ( sess : & Session ) -> Vec < Path > {
967+ let mut rustpath = filesearch:: rust_path ( ) ;
968+ rustpath. push ( sess. target_filesearch ( ) . get_lib_path ( ) ) ;
969+ // FIXME: Addl lib search paths are an unordered HashSet?
970+ // Shouldn't this search be done in some order?
971+ let addl_lib_paths: HashSet < Path > = sess. opts . addl_lib_search_paths . borrow ( ) . clone ( ) ;
972+ let mut search: Vec < Path > = addl_lib_paths. move_iter ( ) . collect ( ) ;
973+ search. push_all ( rustpath. as_slice ( ) ) ;
974+ return search;
975+ }
976+
966977// Create an 'rlib'
967978//
968979// An rlib in its current incarnation is essentially a renamed .a file. The
@@ -973,7 +984,15 @@ fn link_rlib<'a>(sess: &'a Session,
973984 trans : Option < & CrateTranslation > , // None == no metadata/bytecode
974985 obj_filename : & Path ,
975986 out_filename : & Path ) -> Archive < ' a > {
976- let mut a = Archive :: create ( sess, out_filename, obj_filename) ;
987+ let handler = & sess. diagnostic ( ) . handler ;
988+ let config = ArchiveConfig {
989+ handler : handler,
990+ dst : out_filename. clone ( ) ,
991+ lib_search_paths : archive_search_paths ( sess) ,
992+ os : sess. targ_cfg . os ,
993+ maybe_ar_prog : sess. opts . cg . ar . clone ( )
994+ } ;
995+ let mut a = Archive :: create ( config, obj_filename) ;
977996
978997 for & ( ref l, kind) in sess. cstore . get_used_libraries ( ) . borrow ( ) . iter ( ) {
979998 match kind {
@@ -1387,7 +1406,24 @@ fn link_args(cmd: &mut Command,
13871406 // where extern libraries might live, based on the
13881407 // addl_lib_search_paths
13891408 if sess. opts . cg . rpath {
1390- cmd. args ( rpath:: get_rpath_flags ( sess, out_filename) . as_slice ( ) ) ;
1409+ let sysroot = sess. sysroot ( ) ;
1410+ let target_triple = sess. opts . target_triple . as_slice ( ) ;
1411+ let get_install_prefix_lib_path = || {
1412+ let install_prefix = option_env ! ( "CFG_PREFIX" ) . expect ( "CFG_PREFIX" ) ;
1413+ let tlib = filesearch:: relative_target_lib_path ( sysroot, target_triple) ;
1414+ let mut path = Path :: new ( install_prefix) ;
1415+ path. push ( & tlib) ;
1416+
1417+ path
1418+ } ;
1419+ let rpath_config = RPathConfig {
1420+ os : sess. targ_cfg . os ,
1421+ used_crates : sess. cstore . get_used_crates ( cstore:: RequireDynamic ) ,
1422+ out_filename : out_filename. clone ( ) ,
1423+ get_install_prefix_lib_path : get_install_prefix_lib_path,
1424+ realpath : :: util:: fs:: realpath
1425+ } ;
1426+ cmd. args ( rpath:: get_rpath_flags ( rpath_config) . as_slice ( ) ) ;
13911427 }
13921428
13931429 // compiler-rt contains implementations of low-level LLVM helpers. This is
@@ -1545,7 +1581,15 @@ fn add_upstream_rust_crates(cmd: &mut Command, sess: &Session,
15451581 sess. abort_if_errors ( ) ;
15461582 }
15471583 }
1548- let mut archive = Archive :: open ( sess, dst. clone ( ) ) ;
1584+ let handler = & sess. diagnostic ( ) . handler ;
1585+ let config = ArchiveConfig {
1586+ handler : handler,
1587+ dst : dst. clone ( ) ,
1588+ lib_search_paths : archive_search_paths ( sess) ,
1589+ os : sess. targ_cfg . os ,
1590+ maybe_ar_prog : sess. opts . cg . ar . clone ( )
1591+ } ;
1592+ let mut archive = Archive :: open ( config) ;
15491593 archive. remove_file ( format ! ( "{}.o" , name) . as_slice ( ) ) ;
15501594 let files = archive. files ( ) ;
15511595 if files. iter ( ) . any ( |s| s. as_slice ( ) . ends_with ( ".o" ) ) {
0 commit comments