File tree 5 files changed +43
-1
lines changed
test/run-make/relocation-model
5 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ _rustc_opts_switches=(
36
36
--target'[Target triple cpu-manufacturer-kernel\[-os\] to compile]'
37
37
--target-cpu'[Select target processor (llc -mcpu=help for details)]'
38
38
--target-feature'[Target specific attributes (llc -mattr=help for details)]'
39
+ --relocation-model'[Relocation model (llc --help for details)]'
39
40
{-v,--version}'[Print version info and exit]'
40
41
)
41
42
_rustc_opts_lint=(
Original file line number Diff line number Diff line change @@ -152,13 +152,26 @@ pub mod write {
152
152
( sess. targ_cfg . os == abi:: OsMacos &&
153
153
sess. targ_cfg . arch == abi:: X86_64 ) ;
154
154
155
+ let reloc_model = match sess. opts . cg . relocation_model . as_slice ( ) {
156
+ "pic" => lib:: llvm:: RelocPIC ,
157
+ "static" => lib:: llvm:: RelocStatic ,
158
+ "default" => lib:: llvm:: RelocDefault ,
159
+ "dynamic-no-pic" => lib:: llvm:: RelocDynamicNoPic ,
160
+ _ => {
161
+ sess. err ( format ! ( "{} is not a valid relocation mode" ,
162
+ sess. opts. cg. relocation_model) ) ;
163
+ sess. abort_if_errors ( ) ;
164
+ return ;
165
+ }
166
+ } ;
167
+
155
168
let tm = sess. targ_cfg . target_strs . target_triple . with_c_str ( |t| {
156
169
sess. opts . cg . target_cpu . with_c_str ( |cpu| {
157
170
target_feature ( sess) . with_c_str ( |features| {
158
171
llvm:: LLVMRustCreateTargetMachine (
159
172
t, cpu, features,
160
173
lib:: llvm:: CodeModelDefault ,
161
- lib :: llvm :: RelocPIC ,
174
+ reloc_model ,
162
175
opt_level,
163
176
true ,
164
177
use_softfp,
Original file line number Diff line number Diff line change @@ -458,6 +458,8 @@ cgoptions!(
458
458
" prefer dynamic linking to static linking"),
459
459
no_integrated_as: bool = (false, parse_bool,
460
460
" use an external assembler rather than LLVM ' s integrated one"),
461
+ relocation_model: ~str = (~" pic", parse_string,
462
+ " choose the relocation model to use ( llc -relocation-model for details) "),
461
463
)
462
464
463
465
// Seems out of place, but it uses session, so I'm putting it here
Original file line number Diff line number Diff line change
1
+ -include ../tools.mk
2
+
3
+ all :
4
+ $(RUSTC ) -C relocation-model=dynamic-no-pic foo.rs
5
+ $(call RUN,foo)
6
+
7
+ $(RUSTC) -C relocation-model=default foo.rs
8
+ $(call RUN,foo)
9
+
10
+ $(RUSTC) -C relocation-model=static foo.rs
11
+ $(call RUN,foo)
12
+
13
+ $(RUSTC) -C relocation-model=default --crate-type=dylib foo.rs
14
+ $(RUSTC) -C relocation-model=static --crate-type=dylib foo.rs
15
+ $(RUSTC) -C relocation-model=dynamic-no-pic --crate-type=dylib foo.rs
Original file line number Diff line number Diff line change
1
+ // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ pub fn main ( ) { }
You can’t perform that action at this time.
0 commit comments