File tree Expand file tree Collapse file tree 5 files changed +43
-1
lines changed
test/run-make/relocation-model Expand file tree Collapse file tree 5 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ _rustc_opts_switches=(
3636 --target'[Target triple cpu-manufacturer-kernel\[-os\] to compile]'
3737 --target-cpu'[Select target processor (llc -mcpu=help for details)]'
3838 --target-feature'[Target specific attributes (llc -mattr=help for details)]'
39+ --relocation-model'[Relocation model (llc --help for details)]'
3940 {-v,--version}'[Print version info and exit]'
4041)
4142_rustc_opts_lint=(
Original file line number Diff line number Diff line change @@ -152,13 +152,26 @@ pub mod write {
152152 ( sess. targ_cfg . os == abi:: OsMacos &&
153153 sess. targ_cfg . arch == abi:: X86_64 ) ;
154154
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+
155168 let tm = sess. targ_cfg . target_strs . target_triple . with_c_str ( |t| {
156169 sess. opts . cg . target_cpu . with_c_str ( |cpu| {
157170 target_feature ( sess) . with_c_str ( |features| {
158171 llvm:: LLVMRustCreateTargetMachine (
159172 t, cpu, features,
160173 lib:: llvm:: CodeModelDefault ,
161- lib :: llvm :: RelocPIC ,
174+ reloc_model ,
162175 opt_level,
163176 true ,
164177 use_softfp,
Original file line number Diff line number Diff line change @@ -455,6 +455,8 @@ cgoptions!(
455455 " prefer dynamic linking to static linking"),
456456 no_integrated_as: bool = (false, parse_bool,
457457 " use an external assembler rather than LLVM ' s integrated one"),
458+ relocation_model: ~str = (~" pic", parse_string,
459+ " choose the relocation model to use ( llc -relocation-model for details) "),
458460)
459461
460462// 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