]> git.lizzy.rs Git - rust.git/commitdiff
trans: Clean up handling the LLVM data layout
authorAlex Crichton <alex@alexcrichton.com>
Thu, 16 Jul 2015 22:48:16 +0000 (15:48 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 17 Jul 2015 03:25:52 +0000 (20:25 -0700)
Turns out for OSX our data layout was subtly wrong and the LLVM update must have
exposed this. Instead of fixing this I've removed all data layouts from the
compiler to just use the defaults that LLVM provides for all targets. All data
layouts (and a number of dead modules) are removed from the compiler here.
Custom target specifications can still provide a custom data layout, but it is
now an optional key as the default will be used if one isn't specified.

45 files changed:
src/librustc/lib.rs
src/librustc_back/arm.rs [deleted file]
src/librustc_back/lib.rs
src/librustc_back/mips.rs [deleted file]
src/librustc_back/mipsel.rs [deleted file]
src/librustc_back/target/aarch64_apple_ios.rs
src/librustc_back/target/aarch64_linux_android.rs
src/librustc_back/target/aarch64_unknown_linux_gnu.rs
src/librustc_back/target/arm_linux_androideabi.rs
src/librustc_back/target/arm_unknown_linux_gnueabi.rs
src/librustc_back/target/arm_unknown_linux_gnueabihf.rs
src/librustc_back/target/armv7_apple_ios.rs
src/librustc_back/target/armv7s_apple_ios.rs
src/librustc_back/target/i386_apple_ios.rs
src/librustc_back/target/i686_apple_darwin.rs
src/librustc_back/target/i686_pc_windows_gnu.rs
src/librustc_back/target/i686_pc_windows_msvc.rs
src/librustc_back/target/i686_unknown_dragonfly.rs
src/librustc_back/target/i686_unknown_freebsd.rs
src/librustc_back/target/i686_unknown_linux_gnu.rs
src/librustc_back/target/mips_unknown_linux_gnu.rs
src/librustc_back/target/mipsel_unknown_linux_gnu.rs
src/librustc_back/target/mod.rs
src/librustc_back/target/powerpc_unknown_linux_gnu.rs
src/librustc_back/target/x86_64_apple_darwin.rs
src/librustc_back/target/x86_64_apple_ios.rs
src/librustc_back/target/x86_64_pc_windows_gnu.rs
src/librustc_back/target/x86_64_pc_windows_msvc.rs
src/librustc_back/target/x86_64_unknown_bitrig.rs
src/librustc_back/target/x86_64_unknown_dragonfly.rs
src/librustc_back/target/x86_64_unknown_freebsd.rs
src/librustc_back/target/x86_64_unknown_linux_gnu.rs
src/librustc_back/target/x86_64_unknown_linux_musl.rs
src/librustc_back/target/x86_64_unknown_netbsd.rs
src/librustc_back/target/x86_64_unknown_openbsd.rs
src/librustc_back/target_strs.rs [deleted file]
src/librustc_back/x86.rs [deleted file]
src/librustc_back/x86_64.rs [deleted file]
src/librustc_llvm/lib.rs
src/librustc_trans/back/write.rs
src/librustc_trans/lib.rs
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/context.rs
src/librustc_trans/trans/machine.rs
src/rustllvm/PassWrapper.cpp

index f1984708b663aacb9a4360f9620112b1b4b03886..7d50e6f6917ccf47b77cdb723f558b9943ed636c 100644 (file)
 
 pub mod back {
     pub use rustc_back::abi;
-    pub use rustc_back::arm;
-    pub use rustc_back::mips;
-    pub use rustc_back::mipsel;
     pub use rustc_back::rpath;
     pub use rustc_back::svh;
-    pub use rustc_back::target_strs;
-    pub use rustc_back::x86;
-    pub use rustc_back::x86_64;
 }
 
 pub mod ast_map;
diff --git a/src/librustc_back/arm.rs b/src/librustc_back/arm.rs
deleted file mode 100644 (file)
index 9e288f6..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright 2012-2015 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.
-
-use target_strs;
-use syntax::abi;
-
-pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t {
-    let cc_args = if target_triple.contains("thumb") {
-        vec!("-mthumb".to_string())
-    } else {
-        vec!("-marm".to_string())
-    };
-    return target_strs::t {
-        module_asm: "".to_string(),
-
-        data_layout: match target_os {
-          abi::OsMacos => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsiOS => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsWindows => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsLinux => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsAndroid => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsFreebsd | abi::OsDragonfly | abi::OsBitrig | abi::OsOpenbsd | abi::OsNetbsd => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-        },
-
-        target_triple: target_triple,
-
-        cc_args: cc_args,
-    };
-}
index ef5ba625e114b68bfef689aa4416e904fbf4a6a6..ecba37c23153d8c97f149f48a54463dcc50f88d6 100644 (file)
 
 pub mod abi;
 pub mod tempdir;
-pub mod arm;
-pub mod mips;
-pub mod mipsel;
 pub mod rpath;
 pub mod sha2;
 pub mod svh;
-pub mod target_strs;
-pub mod x86;
-pub mod x86_64;
 pub mod target;
diff --git a/src/librustc_back/mips.rs b/src/librustc_back/mips.rs
deleted file mode 100644 (file)
index e1edff8..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2012-2015 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.
-
-use target_strs;
-use syntax::abi;
-
-pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t {
-    return target_strs::t {
-        module_asm: "".to_string(),
-
-        data_layout: match target_os {
-          abi::OsMacos => {
-            "E-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsiOS => {
-            "E-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsWindows => {
-            "E-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsLinux => {
-            "E-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsAndroid => {
-            "E-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsBitrig | abi::OsDragonfly | abi::OsFreebsd | abi::OsNetbsd | abi::OsOpenbsd => {
-            "E-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-        },
-
-        target_triple: target_triple,
-
-        cc_args: Vec::new(),
-    };
-}
diff --git a/src/librustc_back/mipsel.rs b/src/librustc_back/mipsel.rs
deleted file mode 100644 (file)
index ca52a9e..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2012-2015 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.
-
-use target_strs;
-use syntax::abi;
-
-pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t {
-    return target_strs::t {
-        module_asm: "".to_string(),
-
-        data_layout: match target_os {
-          abi::OsMacos => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsiOS => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsWindows => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsLinux => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsAndroid => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-
-          abi::OsFreebsd | abi::OsDragonfly | abi::OsBitrig | abi::OsOpenbsd | abi::OsNetbsd => {
-            "e-p:32:32:32\
-                -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                -f32:32:32-f64:64:64\
-                -v64:64:64-v128:64:128\
-                -a:0:64-n32".to_string()
-          }
-        },
-
-        target_triple: target_triple,
-
-        cc_args: Vec::new(),
-    };
-}
index dd6bc672a03d996ab8d1cf390eac171cef3696e5..e87cb43128d24fc1efffd5d53c16b3673fc91d95 100644 (file)
 
 pub fn target() -> Target {
     Target {
-        // reference layout: e-m:o-i64:64-i128:128-n32:64-S128
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                      i128:128-f32:32:32-f64:64:64-v64:64:64-v128:128:128-\
-                      a:0:64-n32:64-S128".to_string(),
         llvm_target: "arm64-apple-ios".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index 67194e7ac5c7c8c43832803f755df8aae57081a5..8c350e8b28750ef3ec9f04682a257de05b715468 100644 (file)
@@ -12,9 +12,6 @@
 
 pub fn target() -> Target {
     Target {
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                      f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                      n32:64-S128".to_string(),
         llvm_target: "aarch64-linux-android".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index 18e67d066d03632f8c148a54c03326411364fc44..ed79caf486942158402e23ce2d47ce527b923ab8 100644 (file)
@@ -13,9 +13,6 @@
 pub fn target() -> Target {
     let base = super::linux_base::opts();
     Target {
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                      f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                      n32:64-S128".to_string(),
         llvm_target: "aarch64-unknown-linux-gnu".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index cbaa2b205b05512c36f660e5d10ec2a989653b86..0770fe70e8a5780b69c6e28739fca356d9def1fa 100644 (file)
@@ -15,9 +15,6 @@ pub fn target() -> Target {
     base.features = "+v7".to_string();
 
     Target {
-        data_layout: "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                      f32:32:32-f64:64:64-v64:64:64-v128:64:128-a:0:64-\
-                      n32".to_string(),
         llvm_target: "arm-linux-androideabi".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index 30015c4a7e6ff0ef1a34a6b04fd36ea956162ffd..084f989277f317024220d1290a180deda2339d2d 100644 (file)
 pub fn target() -> Target {
     let base = super::linux_base::opts();
     Target {
-        data_layout: "e-p:32:32:32\
-                      -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                      -f32:32:32-f64:64:64\
-                      -v64:64:64-v128:64:128\
-                      -a:0:64-n32".to_string(),
         llvm_target: "arm-unknown-linux-gnueabi".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index 8f8c7114e6effa537c55bdeec16fa3b0ccb3a304..08f1aa5ade848c6c9d6503c44d463b3b61f0a9db 100644 (file)
 pub fn target() -> Target {
     let base = super::linux_base::opts();
     Target {
-        data_layout: "e-p:32:32:32\
-                      -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                      -f32:32:32-f64:64:64\
-                      -v64:64:64-v128:64:128\
-                      -a:0:64-n32".to_string(),
         llvm_target: "arm-unknown-linux-gnueabihf".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index 3b55993659de24c132dbbb585b7fb7832b44c9c3..a6d649ea162f93be4cab857075cf4af188055781 100644 (file)
@@ -13,7 +13,6 @@
 
 pub fn target() -> Target {
     Target {
-        data_layout: "e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(),
         llvm_target: "armv7-apple-ios".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index 5a67e3fe127d6f375bb7018a9ccf7b45da1ddce4..264385512added148a0519249939a5bcfee2711e 100644 (file)
@@ -13,7 +13,6 @@
 
 pub fn target() -> Target {
     Target {
-        data_layout: "e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(),
         llvm_target: "armv7s-apple-ios".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index a9a073e2a8c64ae3db1c0394edc549f430b38329..d17aa915461df369a192a5bf13c88f303cea204a 100644 (file)
 
 pub fn target() -> Target {
     Target {
-        data_layout: "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16\
-                      -i32:32:32-i64:32:64\
-                      -f32:32:32-f64:32:64-v64:64:64\
-                      -v128:128:128-a:0:64-f80:128:128\
-                      -n8:16:32".to_string(),
         llvm_target: "i386-apple-ios".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index 47b329982d43e29383a77083d92c556c7e835a85..9fe15e76942863c7ada3bf69aa878905f8e3ccb2 100644 (file)
@@ -16,11 +16,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m32".to_string());
 
     Target {
-        data_layout: "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16\
-                      -i32:32:32-i64:32:64\
-                      -f32:32:32-f64:32:64-v64:64:64\
-                      -v128:128:128-a:0:64-f80:128:128\
-                      -n8:16:32".to_string(),
         llvm_target: "i686-apple-darwin".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index 9e2aa20085c3634f1dde00f97e1eb0def39a5ecf..ae1b4d450a58e93792f636f42e9ac966720a0308 100644 (file)
@@ -24,7 +24,6 @@ pub fn target() -> Target {
     options.pre_link_args.push("-shared-libgcc".to_string());
 
     Target {
-        data_layout: "e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32".to_string(),
         llvm_target: "i686-pc-windows-gnu".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index d71aa1526660e13846828924fa93ee0978902fa1..f2ae799bd2438185bcae77d0f17f785c003dae3a 100644 (file)
@@ -15,7 +15,6 @@ pub fn target() -> Target {
     base.cpu = "i686".to_string();
 
     Target {
-        data_layout: "e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32".to_string(),
         llvm_target: "i686-pc-windows-msvc".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index ecabe71ad4c6c635ef279472ac60868a6cdd38c2..f2478e6d0dbfeb37cfe8765013a60a5aafc2d2c7 100644 (file)
@@ -16,7 +16,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m32".to_string());
 
     Target {
-        data_layout: "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_string(),
         llvm_target: "i686-unknown-dragonfly".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index d3477402cefb7412be106460f7b99a808a41d8d1..68fee41e2cfa531c31f09f4c3a88f23cafda7c11 100644 (file)
@@ -17,7 +17,6 @@ pub fn target() -> Target {
     base.morestack = false;
 
     Target {
-        data_layout: "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_string(),
         llvm_target: "i686-unknown-freebsd".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index 21094ad905e90f5c281c8d451fa44fb676b97399..074d5b2b9ed228d5be4995a2f78c5e0d55b77b18 100644 (file)
@@ -16,7 +16,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m32".to_string());
 
     Target {
-        data_layout: "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_string(),
         llvm_target: "i686-unknown-linux-gnu".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index 4662ff1958ba87de61a7d1922324e047f7185f90..3f3da6d6c9136aa86448c17ead7d1d761b37b021 100644 (file)
 
 pub fn target() -> Target {
     Target {
-        data_layout: "E-p:32:32:32\
-                      -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                      -f32:32:32-f64:64:64\
-                      -v64:64:64-v128:64:128\
-                      -a:0:64-n32".to_string(),
         llvm_target: "mips-unknown-linux-gnu".to_string(),
         target_endian: "big".to_string(),
         target_pointer_width: "32".to_string(),
index 80e38c5ddea98e61cdc65bcdb8d94371b11f4373..d7f286c8aa4085beda3357ee7c6cbb9b062a2785 100644 (file)
 
 pub fn target() -> Target {
     Target {
-        data_layout: "e-p:32:32:32\
-                      -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\
-                      -f32:32:32-f64:64:64\
-                      -v64:64:64-v128:64:128\
-                      -a:0:64-n32".to_string(),
         llvm_target: "mipsel-unknown-linux-gnu".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "32".to_string(),
index 185d1c9428e86106f00b37499b9c7632fd6a150c..39e42913ff6745e4389001908b80804bb95e2a16 100644 (file)
@@ -67,8 +67,6 @@
 /// Every field here must be specified, and has no default value.
 #[derive(Clone, Debug)]
 pub struct Target {
-    /// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
-    pub data_layout: String,
     /// Target triple to pass to LLVM.
     pub llvm_target: String,
     /// String to use as the `target_endian` `cfg` variable.
@@ -92,6 +90,8 @@ pub struct Target {
 /// these try to take "minimal defaults" that don't assume anything about the runtime they run in.
 #[derive(Clone, Debug)]
 pub struct TargetOptions {
+    /// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
+    pub data_layout: String,
     /// Linker to invoke. Defaults to "cc".
     pub linker: String,
     /// Archive utility to use when managing archives. Defaults to "ar".
@@ -178,6 +178,7 @@ impl Default for TargetOptions {
     /// incomplete, and if used for compilation, will certainly not work.
     fn default() -> TargetOptions {
         TargetOptions {
+            data_layout: String::new(),
             linker: "cc".to_string(),
             ar: "ar".to_string(),
             pre_link_args: Vec::new(),
@@ -245,7 +246,6 @@ pub fn from_json(obj: Json) -> Target {
         };
 
         let mut base = Target {
-            data_layout: get_req_field("data-layout"),
             llvm_target: get_req_field("llvm-target"),
             target_endian: get_req_field("target-endian"),
             target_pointer_width: get_req_field("target-pointer-width"),
@@ -289,6 +289,7 @@ macro_rules! key {
         key!(staticlib_prefix);
         key!(staticlib_suffix);
         key!(features);
+        key!(data_layout);
         key!(dynamic_linking, bool);
         key!(executables, bool);
         key!(morestack, bool);
index 3a2b4bd16065ef38e892a78415b4d0f4cc75b39a..896824eba0e56b627bbb4ce14ae0caf6f745d11d 100644 (file)
@@ -15,7 +15,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m32".to_string());
 
     Target {
-        data_layout: "E-S8-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_string(),
         llvm_target: "powerpc-unknown-linux-gnu".to_string(),
         target_endian: "big".to_string(),
         target_pointer_width: "32".to_string(),
index 89a67da2d8bbcf9b677553c31287036004fd85b2..ef40c2f2006e1628086bdb2906f30d6748b6118b 100644 (file)
@@ -17,9 +17,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m64".to_string());
 
     Target {
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                      f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                      s0:64:64-f80:128:128-n8:16:32:64".to_string(),
         llvm_target: "x86_64-apple-darwin".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index 74491629ed8592faf1e53115f5dbfc7890756f17..7aca8c554dab63dd27c6d9b980dc1a1f3b464ceb 100644 (file)
@@ -13,9 +13,6 @@
 
 pub fn target() -> Target {
     Target {
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                      f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-\
-                      s0:64:64-f80:128:128-n8:16:32:64".to_string(),
         llvm_target: "x86_64-apple-ios".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index bea7d16e9dfadd83897082db1e9218f3ea2e4305..e4d7b4bc9b024fab54df64f1d57958039c556098 100644 (file)
@@ -18,10 +18,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m64".to_string());
 
     Target {
-        // FIXME: Test this. Copied from linux (#2398)
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                      f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                      s0:64:64-f80:128:128-n8:16:32:64-S128".to_string(),
         llvm_target: "x86_64-pc-windows-gnu".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index f7c3ca4b3f6edd61d41975cfba58fec7f5f23853..addaaeb1b636da2cf7353eed6b96eeca3942cd43 100644 (file)
@@ -15,13 +15,6 @@ pub fn target() -> Target {
     base.cpu = "x86-64".to_string();
 
     Target {
-        // This is currently in sync with the specification for
-        // x86_64-pc-windows-gnu but there's a comment in that file questioning
-        // whether this is valid or not. Sounds like the two should stay in sync
-        // at least for now.
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                      f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                      s0:64:64-f80:128:128-n8:16:32:64-S128".to_string(),
         llvm_target: "x86_64-pc-windows-msvc".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index 201c56b2e15c682b991738e9306332b331f467e4..6ecf885aba38eff9cf1f1e9441001c32ccf3a3ca 100644 (file)
@@ -15,9 +15,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m64".to_string());
 
     Target {
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                     f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-\
-                     s0:64:64-f80:128:128-n8:16:32:64-S128".to_string(),
         llvm_target: "x86_64-unknown-bitrig".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index c590f0297b948a03648ac04b4c482d8ebb8c3935..f0e665967ec6f3fd2b77304ce1ec28f584b79543 100644 (file)
@@ -16,9 +16,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m64".to_string());
 
     Target {
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                     f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                     s0:64:64-f80:128:128-n8:16:32:64-S128".to_string(),
         llvm_target: "x86_64-unknown-dragonfly".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index 0d8ea90a2ab04921d0371cbe94f6244c273b1d15..f742ebfde1d2c314fdf2e28e54c72d38e76f8613 100644 (file)
@@ -16,9 +16,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m64".to_string());
 
     Target {
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                     f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                     s0:64:64-f80:128:128-n8:16:32:64-S128".to_string(),
         llvm_target: "x86_64-unknown-freebsd".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index ba945afc5649b38f70750eea70bda88479f72aff..4749e481fd85534724ff1bba722cd73ffc9e557f 100644 (file)
@@ -16,9 +16,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m64".to_string());
 
     Target {
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                      f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                      s0:64:64-f80:128:128-n8:16:32:64-S128".to_string(),
         llvm_target: "x86_64-unknown-linux-gnu".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index 3debad2e8f2013daef0b27cd330caf71e1808356..c66192c28b13d7ce1ef2ddddd1f03dd891ba679c 100644 (file)
@@ -70,9 +70,6 @@ pub fn target() -> Target {
     base.position_independent_executables = false;
 
     Target {
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                      f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                      s0:64:64-f80:128:128-n8:16:32:64-S128".to_string(),
         llvm_target: "x86_64-unknown-linux-musl".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index 3f5bd39949ab60e9066fddfe5e54872ed31ba102..e13e58e3a186d163d22cc7a3dfc3c0491dad20c9 100644 (file)
@@ -15,9 +15,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m64".to_string());
 
     Target {
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                     f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                     s0:64:64-f80:128:128-n8:16:32:64-S128".to_string(),
         llvm_target: "x86_64-unknown-netbsd".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
index 7f64259adf9f8cf0c581a0e50d7a00a014b353a0..a404db48b22bb38875769d86e8d82b675e46ccf8 100644 (file)
@@ -15,9 +15,6 @@ pub fn target() -> Target {
     base.pre_link_args.push("-m64".to_string());
 
     Target {
-        data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                     f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                     s0:64:64-f80:128:128-n8:16:32:64-S128".to_string(),
         llvm_target: "x86_64-unknown-openbsd".to_string(),
         target_endian: "little".to_string(),
         target_pointer_width: "64".to_string(),
diff --git a/src/librustc_back/target_strs.rs b/src/librustc_back/target_strs.rs
deleted file mode 100644 (file)
index 7928f3d..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2012 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.
-
-#![allow(non_camel_case_types)]
-
-pub struct t {
-    pub module_asm: String,
-    pub data_layout: String,
-    pub target_triple: String,
-    pub cc_args: Vec<String> ,
-}
diff --git a/src/librustc_back/x86.rs b/src/librustc_back/x86.rs
deleted file mode 100644 (file)
index 46e0a83..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2012-2015 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.
-
-
-use target_strs;
-use syntax::abi;
-
-pub fn get_target_strs(target_triple: String, target_os: abi::Os)
-                       -> target_strs::t {
-    return target_strs::t {
-        module_asm: "".to_string(),
-
-        data_layout: match target_os {
-          abi::OsMacos => {
-            "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16\
-                -i32:32:32-i64:32:64\
-                -f32:32:32-f64:32:64-v64:64:64\
-                -v128:128:128-a:0:64-f80:128:128\
-                -n8:16:32".to_string()
-          }
-
-          abi::OsiOS => {
-            "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16\
-                -i32:32:32-i64:32:64\
-                -f32:32:32-f64:32:64-v64:64:64\
-                -v128:128:128-a:0:64-f80:128:128\
-                -n8:16:32".to_string()
-          }
-
-          abi::OsWindows => {
-            "e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32".to_string()
-          }
-
-          abi::OsLinux => {
-            "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_string()
-          }
-          abi::OsAndroid => {
-            "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_string()
-          }
-
-          abi::OsFreebsd | abi::OsDragonfly | abi::OsBitrig | abi::OsOpenbsd | abi::OsNetbsd => {
-            "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_string()
-          }
-
-        },
-
-        target_triple: target_triple,
-
-        cc_args: vec!("-m32".to_string()),
-    };
-}
diff --git a/src/librustc_back/x86_64.rs b/src/librustc_back/x86_64.rs
deleted file mode 100644 (file)
index abdcd56..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2012-2015 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.
-
-
-use target_strs;
-use syntax::abi;
-
-pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t {
-    return target_strs::t {
-        module_asm: "".to_string(),
-
-        data_layout: match target_os {
-          abi::OsMacos => {
-            "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                s0:64:64-f80:128:128-n8:16:32:64".to_string()
-          }
-
-          abi::OsiOS => {
-            "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                s0:64:64-f80:128:128-n8:16:32:64".to_string()
-          }
-
-          abi::OsWindows => {
-            // FIXME: Test this. Copied from Linux (#2398)
-            "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                s0:64:64-f80:128:128-n8:16:32:64-S128".to_string()
-          }
-
-          abi::OsLinux => {
-            "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                s0:64:64-f80:128:128-n8:16:32:64-S128".to_string()
-          }
-          abi::OsAndroid => {
-            "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                s0:64:64-f80:128:128-n8:16:32:64-S128".to_string()
-          }
-
-          abi::OsBitrig | abi::OsDragonfly | abi::OsFreebsd | abi::OsNetbsd | abi::OsOpenbsd => {
-            "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
-                f32:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-\
-                s0:64:64-f80:128:128-n8:16:32:64-S128".to_string()
-          }
-
-        },
-
-        target_triple: target_triple,
-
-        cc_args: vec!("-m64".to_string()),
-    };
-}
index 051cc1c5bb2485544f07dd1e92ea5e3502d2b4de..7734704b021a851a66b5396343acfdbd0671b1c9 100644 (file)
@@ -2134,6 +2134,10 @@ pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
                                     Name: *const c_char,
                                     Child: ArchiveChildRef) -> RustArchiveMemberRef;
     pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
+
+    pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef,
+                                                  TM: TargetMachineRef);
+    pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
 }
 
 // LLVM requires symbols from this library, but apparently they're not printed
index 0a9db8a651e65d0ab1d37ec6e211c6c995d2aafc..1f97a9b93edf5d9cb49db077e4fa3adffbfadcf3 100644 (file)
@@ -163,7 +163,7 @@ fn get_llvm_opt_level(optimize: config::OptLevel) -> llvm::CodeGenOptLevel {
     }
 }
 
-fn create_target_machine(sess: &Session) -> TargetMachineRef {
+pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
     let reloc_model_arg = match sess.opts.cg.relocation_model {
         Some(ref s) => &s[..],
         None => &sess.target.target.options.relocation_model[..],
@@ -591,10 +591,6 @@ pub fn run_passes(sess: &Session,
     // Sanity check
     assert!(trans.modules.len() == sess.opts.cg.codegen_units);
 
-    unsafe {
-        configure_llvm(sess);
-    }
-
     let tm = create_target_machine(sess);
 
     // Figure out what we actually need to build.
@@ -943,10 +939,7 @@ pub fn run_assembler(sess: &Session, outputs: &OutputFilenames) {
     }
 }
 
-unsafe fn configure_llvm(sess: &Session) {
-    use std::sync::Once;
-    static INIT: Once = Once::new();
-
+pub unsafe fn configure_llvm(sess: &Session) {
     let mut llvm_c_strs = Vec::new();
     let mut llvm_args = Vec::new();
 
@@ -968,46 +961,44 @@ unsafe fn configure_llvm(sess: &Session) {
         }
     }
 
-    INIT.call_once(|| {
-        llvm::LLVMInitializePasses();
-
-        // Only initialize the platforms supported by Rust here, because
-        // using --llvm-root will have multiple platforms that rustllvm
-        // doesn't actually link to and it's pointless to put target info
-        // into the registry that Rust cannot generate machine code for.
-        llvm::LLVMInitializeX86TargetInfo();
-        llvm::LLVMInitializeX86Target();
-        llvm::LLVMInitializeX86TargetMC();
-        llvm::LLVMInitializeX86AsmPrinter();
-        llvm::LLVMInitializeX86AsmParser();
-
-        llvm::LLVMInitializeARMTargetInfo();
-        llvm::LLVMInitializeARMTarget();
-        llvm::LLVMInitializeARMTargetMC();
-        llvm::LLVMInitializeARMAsmPrinter();
-        llvm::LLVMInitializeARMAsmParser();
-
-        llvm::LLVMInitializeAArch64TargetInfo();
-        llvm::LLVMInitializeAArch64Target();
-        llvm::LLVMInitializeAArch64TargetMC();
-        llvm::LLVMInitializeAArch64AsmPrinter();
-        llvm::LLVMInitializeAArch64AsmParser();
-
-        llvm::LLVMInitializeMipsTargetInfo();
-        llvm::LLVMInitializeMipsTarget();
-        llvm::LLVMInitializeMipsTargetMC();
-        llvm::LLVMInitializeMipsAsmPrinter();
-        llvm::LLVMInitializeMipsAsmParser();
-
-        llvm::LLVMInitializePowerPCTargetInfo();
-        llvm::LLVMInitializePowerPCTarget();
-        llvm::LLVMInitializePowerPCTargetMC();
-        llvm::LLVMInitializePowerPCAsmPrinter();
-        llvm::LLVMInitializePowerPCAsmParser();
-
-        llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int,
-                                     llvm_args.as_ptr());
-    });
+    llvm::LLVMInitializePasses();
+
+    // Only initialize the platforms supported by Rust here, because
+    // using --llvm-root will have multiple platforms that rustllvm
+    // doesn't actually link to and it's pointless to put target info
+    // into the registry that Rust cannot generate machine code for.
+    llvm::LLVMInitializeX86TargetInfo();
+    llvm::LLVMInitializeX86Target();
+    llvm::LLVMInitializeX86TargetMC();
+    llvm::LLVMInitializeX86AsmPrinter();
+    llvm::LLVMInitializeX86AsmParser();
+
+    llvm::LLVMInitializeARMTargetInfo();
+    llvm::LLVMInitializeARMTarget();
+    llvm::LLVMInitializeARMTargetMC();
+    llvm::LLVMInitializeARMAsmPrinter();
+    llvm::LLVMInitializeARMAsmParser();
+
+    llvm::LLVMInitializeAArch64TargetInfo();
+    llvm::LLVMInitializeAArch64Target();
+    llvm::LLVMInitializeAArch64TargetMC();
+    llvm::LLVMInitializeAArch64AsmPrinter();
+    llvm::LLVMInitializeAArch64AsmParser();
+
+    llvm::LLVMInitializeMipsTargetInfo();
+    llvm::LLVMInitializeMipsTarget();
+    llvm::LLVMInitializeMipsTargetMC();
+    llvm::LLVMInitializeMipsAsmPrinter();
+    llvm::LLVMInitializeMipsAsmParser();
+
+    llvm::LLVMInitializePowerPCTargetInfo();
+    llvm::LLVMInitializePowerPCTarget();
+    llvm::LLVMInitializePowerPCTargetMC();
+    llvm::LLVMInitializePowerPCAsmPrinter();
+    llvm::LLVMInitializePowerPCAsmParser();
+
+    llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int,
+                                 llvm_args.as_ptr());
 }
 
 unsafe fn populate_llvm_passes(fpm: llvm::PassManagerRef,
index 0e425e1fd991029e66ef37b24a08a8194493f7b6..af894b218eff8e87e76c7103da155d91e5a9df27 100644 (file)
 
 pub mod back {
     pub use rustc_back::abi;
-    pub use rustc_back::arm;
-    pub use rustc_back::mips;
-    pub use rustc_back::mipsel;
     pub use rustc_back::rpath;
     pub use rustc_back::svh;
-    pub use rustc_back::target_strs;
-    pub use rustc_back::x86;
-    pub use rustc_back::x86_64;
 
     pub mod archive;
     pub mod linker;
index edb61b0d3cf384cfb8aaf882a05e452c8e65c290..4aeba2fe062872fc93a519ef83bbff8c07c3e5c2 100644 (file)
@@ -2666,6 +2666,8 @@ pub fn trans_crate(tcx: &ty::ctxt, analysis: ty::CrateAnalysis) -> CrateTranslat
                 // cannot proceed despite the Once not running more than once.
                 POISONED = true;
             }
+
+            ::back::write::configure_llvm(&tcx.sess);
         });
 
         if POISONED {
index cf9d70cc65727098e9dc957410434ac22c0b4a79..5a4bd7ff3a18468847b5bcb47ef974c1b7557ad5 100644 (file)
@@ -10,8 +10,6 @@
 
 use llvm;
 use llvm::{ContextRef, ModuleRef, ValueRef, BuilderRef};
-use llvm::TargetData;
-use llvm::mk_target_data;
 use metadata::common::LinkMeta;
 use middle::def::ExportMap;
 use middle::traits;
@@ -83,7 +81,6 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> {
 pub struct LocalCrateContext<'tcx> {
     llmod: ModuleRef,
     llcx: ContextRef,
-    td: TargetData,
     tn: TypeNames,
     externs: RefCell<ExternMap>,
     item_vals: RefCell<NodeMap<ValueRef>>,
@@ -226,9 +223,15 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR
     let mod_name = CString::new(mod_name).unwrap();
     let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
 
-    let data_layout = sess.target.target.data_layout.as_bytes();
-    let data_layout = CString::new(data_layout).unwrap();
-    llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
+    let custom_data_layout = &sess.target.target.options.data_layout[..];
+    if custom_data_layout.len() > 0 {
+        let data_layout = CString::new(custom_data_layout).unwrap();
+        llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
+    } else {
+        let tm = ::back::write::create_target_machine(sess);
+        llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
+        llvm::LLVMRustDisposeTargetMachine(tm);
+    }
 
     let llvm_target = sess.target.target.llvm_target.as_bytes();
     let llvm_target = CString::new(llvm_target).unwrap();
@@ -419,13 +422,6 @@ fn new<'a>(shared: &SharedCrateContext<'a, 'tcx>,
         unsafe {
             let (llcx, llmod) = create_context_and_module(&shared.tcx.sess, name);
 
-            let td = mk_target_data(&shared.tcx
-                                          .sess
-                                          .target
-                                          .target
-                                          .data_layout
-                                          );
-
             let dbg_cx = if shared.tcx.sess.opts.debuginfo != NoDebugInfo {
                 Some(debuginfo::CrateDebugContext::new(llmod))
             } else {
@@ -435,7 +431,6 @@ fn new<'a>(shared: &SharedCrateContext<'a, 'tcx>,
             let mut local_ccx = LocalCrateContext {
                 llmod: llmod,
                 llcx: llcx,
-                td: td,
                 tn: TypeNames::new(),
                 externs: RefCell::new(FnvHashMap()),
                 item_vals: RefCell::new(NodeMap()),
@@ -581,8 +576,8 @@ pub fn llcx(&self) -> ContextRef {
         self.local.llcx
     }
 
-    pub fn td<'a>(&'a self) -> &'a TargetData {
-        &self.local.td
+    pub fn td(&self) -> llvm::TargetDataRef {
+        unsafe { llvm::LLVMRustGetModuleDataLayout(self.llmod()) }
     }
 
     pub fn tn<'a>(&'a self) -> &'a TypeNames {
index 39bc547a1a764d40cb42123b2df0c522efead0cf..691fba42d57051e9aa74757d0b28fd8f1630e494 100644 (file)
@@ -27,7 +27,7 @@
 // Returns the number of bytes clobbered by a Store to this type.
 pub fn llsize_of_store(cx: &CrateContext, ty: Type) -> llsize {
     unsafe {
-        return llvm::LLVMStoreSizeOfType(cx.td().lltd, ty.to_ref());
+        return llvm::LLVMStoreSizeOfType(cx.td(), ty.to_ref());
     }
 }
 
@@ -35,7 +35,7 @@ pub fn llsize_of_store(cx: &CrateContext, ty: Type) -> llsize {
 // array of T. This is the "ABI" size. It includes any ABI-mandated padding.
 pub fn llsize_of_alloc(cx: &CrateContext, ty: Type) -> llsize {
     unsafe {
-        return llvm::LLVMABISizeOfType(cx.td().lltd, ty.to_ref());
+        return llvm::LLVMABISizeOfType(cx.td(), ty.to_ref());
     }
 }
 
@@ -51,7 +51,7 @@ pub fn llsize_of_alloc(cx: &CrateContext, ty: Type) -> llsize {
 // below.
 pub fn llsize_of_real(cx: &CrateContext, ty: Type) -> llsize {
     unsafe {
-        let nbits = llvm::LLVMSizeOfTypeInBits(cx.td().lltd, ty.to_ref());
+        let nbits = llvm::LLVMSizeOfTypeInBits(cx.td(), ty.to_ref());
         if nbits & 7 != 0 {
             // Not an even number of bytes, spills into "next" byte.
             1 + (nbits >> 3)
@@ -64,7 +64,7 @@ pub fn llsize_of_real(cx: &CrateContext, ty: Type) -> llsize {
 /// Returns the "real" size of the type in bits.
 pub fn llbitsize_of_real(cx: &CrateContext, ty: Type) -> llbits {
     unsafe {
-        llvm::LLVMSizeOfTypeInBits(cx.td().lltd, ty.to_ref())
+        llvm::LLVMSizeOfTypeInBits(cx.td(), ty.to_ref())
     }
 }
 
@@ -86,7 +86,7 @@ pub fn llsize_of(cx: &CrateContext, ty: Type) -> ValueRef {
 // allocations inside a stack frame, which LLVM has a free hand in.
 pub fn llalign_of_pref(cx: &CrateContext, ty: Type) -> llalign {
     unsafe {
-        return llvm::LLVMPreferredAlignmentOfType(cx.td().lltd, ty.to_ref());
+        return llvm::LLVMPreferredAlignmentOfType(cx.td(), ty.to_ref());
     }
 }
 
@@ -95,13 +95,13 @@ pub fn llalign_of_pref(cx: &CrateContext, ty: Type) -> llalign {
 // and similar ABI-mandated things.
 pub fn llalign_of_min(cx: &CrateContext, ty: Type) -> llalign {
     unsafe {
-        return llvm::LLVMABIAlignmentOfType(cx.td().lltd, ty.to_ref());
+        return llvm::LLVMABIAlignmentOfType(cx.td(), ty.to_ref());
     }
 }
 
 pub fn llelement_offset(cx: &CrateContext, struct_ty: Type, element: usize) -> u64 {
     unsafe {
-        return llvm::LLVMOffsetOfElement(cx.td().lltd,
+        return llvm::LLVMOffsetOfElement(cx.td(),
                                          struct_ty.to_ref(),
                                          element as u32);
     }
index 2c0240eb8f92bac7476ff00467bbb5a6b5e8d430..6513fdfd2f2c19251df063caab0ada32cd271089 100644 (file)
@@ -21,6 +21,8 @@
 #else
 #include "llvm/Target/TargetLibraryInfo.h"
 #endif
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
 
 
@@ -327,3 +329,28 @@ LLVMRustMarkAllFunctionsNounwind(LLVMModuleRef M) {
         }
     }
 }
+
+extern "C" void
+LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
+                                       LLVMTargetMachineRef TMR) {
+    TargetMachine *Target = unwrap(TMR);
+#if LLVM_VERSION_MINOR >= 7
+    if (const DataLayout *DL = Target->getDataLayout())
+        unwrap(Module)->setDataLayout(*DL);
+#elif LLVM_VERSION_MINOR >= 6
+    if (const DataLayout *DL = Target->getSubtargetImpl()->getDataLayout())
+        unwrap(Module)->setDataLayout(DL);
+#else
+    if (const DataLayout *DL = Target->getDataLayout())
+        unwrap(Module)->setDataLayout(DL);
+#endif
+}
+
+extern "C" LLVMTargetDataRef
+LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
+#if LLVM_VERSION_MINOR >= 7
+    return wrap(&unwrap(M)->getDataLayout());
+#else
+    return wrap(unwrap(M)->getDataLayout());
+#endif
+}