]> git.lizzy.rs Git - rust.git/commitdiff
Introduce temporary target feature crt_static_respected
authorSamuel Holland <samuel@sholland.org>
Tue, 22 Aug 2017 21:24:29 +0000 (16:24 -0500)
committerSamuel Holland <samuel@sholland.org>
Tue, 22 Aug 2017 21:24:29 +0000 (16:24 -0500)
This feature allows targets to opt in to full support of the crt-static
feature. Currently, crt-static is allowed on all targets, even those
that really can't or really shouldn't support it. This works because it
is very loose in the specification of its effects. Changing the behavior
of crt-static to be more strict in how it chooses libraries and links
executables would likely cause compilation to fail on these platforms.

To avoid breaking existing uses of crt-static, whitelist targets that
support the new, stricter behavior. For all other targets, this changes
crt-static from being "mostly a no-op" to "explicitly a no-op".

src/librustc/session/mod.rs
src/librustc_back/target/linux_musl_base.rs
src/librustc_back/target/mod.rs
src/librustc_back/target/windows_msvc_base.rs
src/librustc_driver/target_features.rs

index a3aa7594c6c2dbd229a5f6f774f21021ef5b25ca..23dcaf27c2c704502a3d4609bf2e8bf491813b30 100644 (file)
@@ -430,6 +430,15 @@ pub fn overflow_checks(&self) -> bool {
     }
 
     pub fn crt_static(&self) -> bool {
+        // If the target does not opt in to crt-static support, use its default.
+        if self.target.target.options.crt_static_respected {
+            self.crt_static_feature()
+        } else {
+            self.target.target.options.crt_static_default
+        }
+    }
+
+    pub fn crt_static_feature(&self) -> bool {
         let requested_features = self.opts.cg.target_feature.split(',');
         let found_negative = requested_features.clone().any(|r| r == "-crt-static");
         let found_positive = requested_features.clone().any(|r| r == "+crt-static");
index 236f2c1ef0aa3a983b1b3df47eca904fa8264d22..e77a40e3a3aa9c0c8e531ff52b154c479b5ad2f8 100644 (file)
@@ -69,6 +69,8 @@ pub fn opts() -> TargetOptions {
 
     // These targets statically link libc by default
     base.crt_static_default = true;
+    // These targets allow the user to choose between static and dynamic linking.
+    base.crt_static_respected = true;
 
     base
 }
index 08b94d5a01cb7c86ef6364278bdfec715e408ce7..0ff633ffe37747dbaacdaa082b1a7692255fed4c 100644 (file)
@@ -418,6 +418,8 @@ pub struct TargetOptions {
 
     /// Whether or not the CRT is statically linked by default.
     pub crt_static_default: bool,
+    /// Whether or not crt-static is respected by the compiler (or is a no-op).
+    pub crt_static_respected: bool,
 
     /// Whether or not stack probes (__rust_probestack) are enabled
     pub stack_probes: bool,
@@ -479,6 +481,7 @@ fn default() -> TargetOptions {
             panic_strategy: PanicStrategy::Unwind,
             abi_blacklist: vec![],
             crt_static_default: false,
+            crt_static_respected: false,
             stack_probes: false,
         }
     }
@@ -715,6 +718,7 @@ macro_rules! key {
         key!(min_atomic_width, Option<u64>);
         try!(key!(panic_strategy, PanicStrategy));
         key!(crt_static_default, bool);
+        key!(crt_static_respected, bool);
         key!(stack_probes, bool);
 
         if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
@@ -903,6 +907,7 @@ macro_rules! target_option_val {
         target_option_val!(max_atomic_width);
         target_option_val!(panic_strategy);
         target_option_val!(crt_static_default);
+        target_option_val!(crt_static_respected);
         target_option_val!(stack_probes);
 
         if default.abi_blacklist != self.options.abi_blacklist {
index c07321e418e64eb5ebf3a4b07f556533591357f8..f44a9b44426d88349375661d69591205c4b0b151 100644 (file)
@@ -63,6 +63,7 @@ pub fn opts() -> TargetOptions {
         is_like_windows: true,
         is_like_msvc: true,
         pre_link_args: args,
+        crt_static_respected: true,
 
         .. Default::default()
     }
index 4616db3ae8746a8e35cdbe4314f533d260473073..96264472b5f8e53e0fe752afd6f5d174ef6ebcdf 100644 (file)
@@ -25,7 +25,7 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {
         cfg.insert((tf, Some(feat)));
     }
 
-    if sess.crt_static() {
+    if sess.crt_static_feature() {
         cfg.insert((tf, Some(Symbol::intern("crt-static"))));
     }
 }