]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Add support for linking arbitrary objects
authorAlex Crichton <alex@alexcrichton.com>
Wed, 22 Apr 2015 01:00:16 +0000 (18:00 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 27 Apr 2015 17:11:15 +0000 (10:11 -0700)
MUSL for example provides its own start/end objects in place of the standard
ones shipped by gcc.

src/librustc_back/target/mod.rs
src/librustc_back/target/x86_64_unknown_linux_musl.rs
src/librustc_trans/back/link.rs

index c32eacda2a2529d68d17881042ba02b4f6ca2205..3a79ae3e7c01b6e8116f47904f33b769ff8b917b 100644 (file)
@@ -91,14 +91,22 @@ pub struct Target {
 pub struct TargetOptions {
     /// Linker to invoke. Defaults to "cc".
     pub linker: String,
-    /// Linker arguments that are unconditionally passed *before* any user-defined libraries.
+    /// Linker arguments that are unconditionally passed *before* any
+    /// user-defined libraries.
     pub pre_link_args: Vec<String>,
-    /// Linker arguments that are unconditionally passed *after* any user-defined libraries.
+    /// Linker arguments that are unconditionally passed *after* any
+    /// user-defined libraries.
     pub post_link_args: Vec<String>,
-    /// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults to "default".
+    /// Objects to link before and after all others, always found within the
+    /// sysroot folder.
+    pub pre_link_objects: Vec<String>,
+    pub post_link_objects: Vec<String>,
+    /// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults
+    /// to "default".
     pub cpu: String,
-    /// Default target features to pass to LLVM. These features will *always* be passed, and cannot
-    /// be disabled even via `-C`. Corresponds to `llc -mattr=$features`.
+    /// Default target features to pass to LLVM. These features will *always* be
+    /// passed, and cannot be disabled even via `-C`. Corresponds to `llc
+    /// -mattr=$features`.
     pub features: String,
     /// Whether dynamic linking is available on this target. Defaults to false.
     pub dynamic_linking: bool,
@@ -183,6 +191,8 @@ fn default() -> TargetOptions {
             has_rpath: false,
             no_compiler_rt: false,
             position_independent_executables: false,
+            pre_link_objects: Vec::new(),
+            post_link_objects: Vec::new(),
         }
     }
 }
index 74d61e90f67fe9f3489c867d96b563b34a35120d..3debad2e8f2013daef0b27cd330caf71e1808356 100644 (file)
@@ -13,7 +13,6 @@
 pub fn target() -> Target {
     let mut base = super::linux_base::opts();
     base.cpu = "x86-64".to_string();
-    base.linker = "musl-gcc".to_string();
     base.pre_link_args.push("-m64".to_string());
 
     // Make sure that the linker/gcc really don't pull in anything, including
index b53be98a06cc30198f16c20db0234319c5fde7af..c72072f06965096488b14541ee982668f32c3a7e 100644 (file)
@@ -794,13 +794,21 @@ fn link_natively(sess: &Session, trans: &CrateTranslation, dylib: bool,
     let pname = get_cc_prog(sess);
     let mut cmd = Command::new(&pname[..]);
 
+    let root = sess.target_filesearch(PathKind::Native).get_lib_path();
     cmd.args(&sess.target.target.options.pre_link_args);
+    for obj in &sess.target.target.options.pre_link_objects {
+        cmd.arg(root.join(obj));
+    }
+
     link_args(&mut cmd, sess, dylib, tmpdir.path(),
               trans, obj_filename, out_filename);
-    cmd.args(&sess.target.target.options.post_link_args);
     if !sess.target.target.options.no_compiler_rt {
         cmd.arg("-lcompiler-rt");
     }
+    for obj in &sess.target.target.options.post_link_objects {
+        cmd.arg(root.join(obj));
+    }
+    cmd.args(&sess.target.target.options.post_link_args);
 
     if sess.opts.debugging_opts.print_link_args {
         println!("{:?}", &cmd);