]> 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`

1  2 
src/etc/zsh/_rust
src/librustc/back/link.rs
src/librustc/driver/session.rs

diff --combined src/etc/zsh/_rust
index 44e2ecc4d3842fbcd1c8dfffb0bce23186f4b650,0a5bfdb4ebb9d1e3e9d6d19bf9f6aca5bdb97a1b..f966d8f30055d156bc2278084ec79176209e15fc
@@@ -36,11 -36,12 +36,12 @@@ _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=(
      'attribute-usage[detects bad use of attributes]'
 -    'ctypes[proper use of std::libc types in foreign modules]'
 +    'ctypes[proper use of libc types in foreign modules]'
      'dead-assignment[detect assignments that will never be read]'
      'dead-code[detect piece of code that will never be used]'
      'default-type-param-usage[prevents explicitly setting a type parameter with a default]'
index 19ec2d465c2dac74af5c07bcbd4c01e3fa89d3c3,9e9602556d49b500b2982e8d25dbbd5e3de98177..073ca45c89d574138a12c2f145c91b54aa649b0c
@@@ -102,7 -102,7 +102,7 @@@ pub mod write 
  
      use std::c_str::ToCStr;
      use std::io::Process;
 -    use std::libc::{c_uint, c_int};
 +    use libc::{c_uint, c_int};
      use std::str;
  
      // On android, we by default compile for armv7 processors. This enables
                               (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,
@@@ -1127,33 -1140,6 +1140,33 @@@ fn link_args(sess: &Session
          // DWARF stack unwinding will not work.
          // This behavior may be overridden by --link-args "-static-libgcc"
          args.push(~"-shared-libgcc");
 +
 +        // And here, we see obscure linker flags #45. On windows, it has been
 +        // found to be necessary to have this flag to compile liblibc.
 +        //
 +        // First a bit of background. On Windows, the file format is not ELF,
 +        // but COFF (at least according to LLVM). COFF doesn't officially allow
 +        // for section names over 8 characters, apparently. Our metadata
 +        // section, ".note.rustc", you'll note is over 8 characters.
 +        //
 +        // On more recent versions of gcc on mingw, apparently the section name
 +        // is *not* truncated, but rather stored elsewhere in a separate lookup
 +        // table. On older versions of gcc, they apparently always truncated the
 +        // section names (at least in some cases). Truncating the section name
 +        // actually creates "invalid" objects [1] [2], but only for some
 +        // introspection tools, not in terms of whether it can be loaded.
 +        //
 +        // Long story shory, passing this flag forces the linker to *not*
 +        // truncate section names (so we can find the metadata section after
 +        // it's compiled). The real kicker is that rust compiled just fine on
 +        // windows for quite a long time *without* this flag, so I have no idea
 +        // why it suddenly started failing for liblibc. Regardless, we
 +        // definitely don't want section name truncation, so we're keeping this
 +        // flag for windows.
 +        //
 +        // [1] - https://sourceware.org/bugzilla/show_bug.cgi?id=13130
 +        // [2] - https://code.google.com/p/go/issues/detail?id=2139
 +        args.push(~"-Wl,--enable-long-section-names");
      }
  
      if sess.targ_cfg.os == abi::OsAndroid {
index c25a2e79824bbf1ee2821e3970a7ced8cf288a2a,80003892301d584bbbd070450f1662989faa97db..a412742ab3a3612076dbe9e3d15ffd7bd4dfcc06
@@@ -232,9 -232,6 +232,9 @@@ impl Session 
      pub fn span_end_note(&self, sp: Span, msg: &str) {
          self.diagnostic().span_end_note(sp, msg)
      }
 +    pub fn fileline_note(&self, sp: Span, msg: &str) {
 +        self.diagnostic().fileline_note(sp, msg)
 +    }
      pub fn note(&self, msg: &str) {
          self.diagnostic().handler().note(msg)
      }
@@@ -458,6 -455,8 +458,8 @@@ cgoptions!
          "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