]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #13340 : FlaPer87/rust/code-model, r=cmr
authorbors <bors@rust-lang.org>
Sun, 6 Apr 2014 14:06:36 +0000 (07:06 -0700)
committerbors <bors@rust-lang.org>
Sun, 6 Apr 2014 14:06:36 +0000 (07:06 -0700)
Rust currently defaults to `RelocPIC` regardless. This patch adds a new
codegen option that allows choosing different relocation-model. The
available models are:

    - default (Use the target-specific default model)
    - static
    - pic
    - no-pic

For a more detailed information use `llc --help`

src/etc/zsh/_rust
src/librustc/back/link.rs
src/librustc/driver/session.rs
src/test/run-make/relocation-model/Makefile [new file with mode: 0644]
src/test/run-make/relocation-model/foo.rs [new file with mode: 0644]

index 44e2ecc4d3842fbcd1c8dfffb0bce23186f4b650..f966d8f30055d156bc2278084ec79176209e15fc 100644 (file)
@@ -36,6 +36,7 @@ _rustc_opts_switches=(
     --target'[Target triple cpu-manufacturer-kernel\[-os\] to compile]'
     --target-cpu'[Select target processor (llc -mcpu=help for details)]'
     --target-feature'[Target specific attributes (llc -mattr=help for details)]'
+    --relocation-model'[Relocation model (llc --help for details)]'
     {-v,--version}'[Print version info and exit]'
 )
 _rustc_opts_lint=(
index 19ec2d465c2dac74af5c07bcbd4c01e3fa89d3c3..073ca45c89d574138a12c2f145c91b54aa649b0c 100644 (file)
@@ -152,13 +152,26 @@ pub fn run_passes(sess: &Session,
                              (sess.targ_cfg.os == abi::OsMacos &&
                               sess.targ_cfg.arch == abi::X86_64);
 
+            let reloc_model = match sess.opts.cg.relocation_model.as_slice() {
+                "pic" => lib::llvm::RelocPIC,
+                "static" => lib::llvm::RelocStatic,
+                "default" => lib::llvm::RelocDefault,
+                "dynamic-no-pic" => lib::llvm::RelocDynamicNoPic,
+                _ => {
+                    sess.err(format!("{} is not a valid relocation mode",
+                             sess.opts.cg.relocation_model));
+                    sess.abort_if_errors();
+                    return;
+                }
+            };
+
             let tm = sess.targ_cfg.target_strs.target_triple.with_c_str(|t| {
                 sess.opts.cg.target_cpu.with_c_str(|cpu| {
                     target_feature(sess).with_c_str(|features| {
                         llvm::LLVMRustCreateTargetMachine(
                             t, cpu, features,
                             lib::llvm::CodeModelDefault,
-                            lib::llvm::RelocPIC,
+                            reloc_model,
                             opt_level,
                             true,
                             use_softfp,
index c25a2e79824bbf1ee2821e3970a7ced8cf288a2a..a412742ab3a3612076dbe9e3d15ffd7bd4dfcc06 100644 (file)
@@ -458,6 +458,8 @@ fn parse_list(slot: &mut Vec<~str>, v: Option<&str>)
         "prefer dynamic linking to static linking"),
     no_integrated_as: bool = (false, parse_bool,
         "use an external assembler rather than LLVM's integrated one"),
+    relocation_model: ~str = (~"pic", parse_string,
+         "choose the relocation model to use (llc -relocation-model for details)"),
 )
 
 // Seems out of place, but it uses session, so I'm putting it here
diff --git a/src/test/run-make/relocation-model/Makefile b/src/test/run-make/relocation-model/Makefile
new file mode 100644 (file)
index 0000000..2fcdd32
--- /dev/null
@@ -0,0 +1,15 @@
+-include ../tools.mk
+
+all:
+       $(RUSTC) -C relocation-model=dynamic-no-pic foo.rs
+       $(call RUN,foo)
+
+       $(RUSTC) -C relocation-model=default foo.rs
+       $(call RUN,foo)
+
+       $(RUSTC) -C relocation-model=static foo.rs
+       $(call RUN,foo)
+
+       $(RUSTC) -C relocation-model=default --crate-type=dylib foo.rs
+       $(RUSTC) -C relocation-model=static --crate-type=dylib foo.rs
+       $(RUSTC) -C relocation-model=dynamic-no-pic --crate-type=dylib foo.rs
diff --git a/src/test/run-make/relocation-model/foo.rs b/src/test/run-make/relocation-model/foo.rs
new file mode 100644 (file)
index 0000000..e06d81c
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub fn main() {}