8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
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 ;
14
15
use driver:: driver:: { CrateTranslation , OutputFilenames , Input , FileInput } ;
15
16
use driver:: config:: NoDebugInfo ;
16
17
use driver:: session:: Session ;
17
18
use driver:: config;
18
- use lib:: llvm:: llvm;
19
- use lib:: llvm:: ModuleRef ;
20
- use lib;
19
+ use llvm;
20
+ use llvm:: ModuleRef ;
21
21
use metadata:: common:: LinkMeta ;
22
22
use metadata:: { encoder, cstore, filesearch, csearch, loader, creader} ;
23
23
use middle:: trans:: context:: CrateContext ;
@@ -29,6 +29,7 @@ use util::sha2::{Digest, Sha256};
29
29
30
30
use std:: c_str:: { ToCStr , CString } ;
31
31
use std:: char;
32
+ use std:: collections:: HashSet ;
32
33
use std:: io:: { fs, TempDir , Command } ;
33
34
use std:: io;
34
35
use std:: ptr;
@@ -70,11 +71,11 @@ pub fn llvm_err(sess: &Session, msg: String) -> ! {
70
71
71
72
pub fn write_output_file (
72
73
sess : & Session ,
73
- target : lib :: llvm:: TargetMachineRef ,
74
- pm : lib :: llvm:: PassManagerRef ,
74
+ target : llvm:: TargetMachineRef ,
75
+ pm : llvm:: PassManagerRef ,
75
76
m : ModuleRef ,
76
77
output : & Path ,
77
- file_type : lib :: llvm:: FileType ) {
78
+ file_type : llvm:: FileType ) {
78
79
unsafe {
79
80
output. with_c_str ( |output| {
80
81
let result = llvm:: LLVMRustWriteOutputFile (
@@ -88,18 +89,17 @@ pub fn write_output_file(
88
89
89
90
pub mod write {
90
91
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 } ;
96
97
use driver:: driver:: { CrateTranslation , OutputFilenames } ;
97
98
use driver:: config:: NoDebugInfo ;
98
99
use driver:: session:: Session ;
99
100
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 } ;
103
103
use util:: common:: time;
104
104
use syntax:: abi;
105
105
@@ -152,10 +152,10 @@ pub mod write {
152
152
}
153
153
154
154
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 ,
159
159
} ;
160
160
let use_softfp = sess. opts . cg . soft_float ;
161
161
@@ -172,10 +172,10 @@ pub mod write {
172
172
let fdata_sections = ffunction_sections;
173
173
174
174
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 ,
179
179
_ => {
180
180
sess. err ( format ! ( "{} is not a valid relocation mode" ,
181
181
sess. opts
@@ -195,7 +195,7 @@ pub mod write {
195
195
target_feature ( sess) . with_c_str ( |features| {
196
196
llvm:: LLVMRustCreateTargetMachine (
197
197
t, cpu, features,
198
- lib :: llvm:: CodeModelDefault ,
198
+ llvm:: CodeModelDefault ,
199
199
reloc_model,
200
200
opt_level,
201
201
true /* EnableSegstk */ ,
@@ -320,7 +320,7 @@ pub mod write {
320
320
} ;
321
321
with_codegen ( tm, llmod, trans. no_builtins , |cpm| {
322
322
write_output_file ( sess, tm, cpm, llmod, & path,
323
- lib :: llvm:: AssemblyFile ) ;
323
+ llvm:: AssemblyFile ) ;
324
324
} ) ;
325
325
}
326
326
OutputTypeObject => {
@@ -338,7 +338,7 @@ pub mod write {
338
338
Some ( ref path) => {
339
339
with_codegen ( tm, llmod, trans. no_builtins , |cpm| {
340
340
write_output_file ( sess, tm, cpm, llmod, path,
341
- lib :: llvm:: ObjectFile ) ;
341
+ llvm:: ObjectFile ) ;
342
342
} ) ;
343
343
}
344
344
None => { }
@@ -350,7 +350,7 @@ pub mod write {
350
350
. with_extension ( "metadata.o" ) ;
351
351
write_output_file ( sess, tm, cpm,
352
352
trans. metadata_module , & out,
353
- lib :: llvm:: ObjectFile ) ;
353
+ llvm:: ObjectFile ) ;
354
354
} )
355
355
}
356
356
} ) ;
@@ -455,29 +455,29 @@ pub mod write {
455
455
} ) ;
456
456
}
457
457
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 ,
460
460
llmod : ModuleRef ,
461
- opt : lib :: llvm:: CodeGenOptLevel ,
461
+ opt : llvm:: CodeGenOptLevel ,
462
462
no_builtins : bool ) {
463
463
// Create the PassManagerBuilder for LLVM. We configure it with
464
464
// reasonable defaults and prepare it to actually populate the pass
465
465
// manager.
466
466
let builder = llvm:: LLVMPassManagerBuilderCreate ( ) ;
467
467
match opt {
468
- lib :: llvm:: CodeGenLevelNone => {
468
+ llvm:: CodeGenLevelNone => {
469
469
// Don't add lifetime intrinsics at O0
470
470
llvm:: LLVMRustAddAlwaysInlinePass ( builder, false ) ;
471
471
}
472
- lib :: llvm:: CodeGenLevelLess => {
472
+ llvm:: CodeGenLevelLess => {
473
473
llvm:: LLVMRustAddAlwaysInlinePass ( builder, true ) ;
474
474
}
475
475
// numeric values copied from clang
476
- lib :: llvm:: CodeGenLevelDefault => {
476
+ llvm:: CodeGenLevelDefault => {
477
477
llvm:: LLVMPassManagerBuilderUseInlinerWithThreshold ( builder,
478
478
225 ) ;
479
479
}
480
- lib :: llvm:: CodeGenLevelAggressive => {
480
+ llvm:: CodeGenLevelAggressive => {
481
481
llvm:: LLVMPassManagerBuilderUseInlinerWithThreshold ( builder,
482
482
275 ) ;
483
483
}
@@ -611,7 +611,7 @@ pub fn build_link_meta(sess: &Session, krate: &ast::Crate,
611
611
name : String ) -> LinkMeta {
612
612
let r = LinkMeta {
613
613
crate_name : name,
614
- crate_hash : Svh :: calculate ( sess, krate) ,
614
+ crate_hash : Svh :: calculate ( & sess. opts . cg . metadata , krate) ,
615
615
} ;
616
616
info ! ( "{}" , r) ;
617
617
return r;
@@ -963,6 +963,17 @@ fn link_binary_output(sess: &Session,
963
963
out_filename
964
964
}
965
965
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
+
966
977
// Create an 'rlib'
967
978
//
968
979
// An rlib in its current incarnation is essentially a renamed .a file. The
@@ -973,7 +984,15 @@ fn link_rlib<'a>(sess: &'a Session,
973
984
trans : Option < & CrateTranslation > , // None == no metadata/bytecode
974
985
obj_filename : & Path ,
975
986
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) ;
977
996
978
997
for & ( ref l, kind) in sess. cstore . get_used_libraries ( ) . borrow ( ) . iter ( ) {
979
998
match kind {
@@ -1387,7 +1406,24 @@ fn link_args(cmd: &mut Command,
1387
1406
// where extern libraries might live, based on the
1388
1407
// addl_lib_search_paths
1389
1408
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 ( ) ) ;
1391
1427
}
1392
1428
1393
1429
// 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,
1545
1581
sess. abort_if_errors ( ) ;
1546
1582
}
1547
1583
}
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) ;
1549
1593
archive. remove_file ( format ! ( "{}.o" , name) . as_slice ( ) ) ;
1550
1594
let files = archive. files ( ) ;
1551
1595
if files. iter ( ) . any ( |s| s. as_slice ( ) . ends_with ( ".o" ) ) {
0 commit comments