about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2020-09-20 23:02:38 -0700
committerJosh Triplett <josh@joshtriplett.org>2020-10-04 22:12:08 -0700
commita3944a0abd134a0f2bcba656fcf9c487ed9fcbaf (patch)
treead7c1afc14ae33c5916f4bd31872ffd6217fdd22
parent9d952cbe953468be20bbe4404ffc55cb39bfb96e (diff)
downloadrust-a3944a0abd134a0f2bcba656fcf9c487ed9fcbaf.tar.gz
rust-a3944a0abd134a0f2bcba656fcf9c487ed9fcbaf.zip
Support static linking with glibc and target-feature=+crt-static
With this change, it's possible to build on a linux-gnu target and pass
RUSTFLAGS='-C target-feature=+crt-static' or the equivalent via a
`.cargo/config.toml` file, and get a statically linked executable.

This requires libc 0.2.79, which adds support for static linking with
glibc.

Add `crt_static_respected` to the `linux_base` target spec.

Update `android_base` and `linux_musl_base` accordingly. Avoid enabling
crt_static_respected on Android platforms, since that hasn't been
tested.
-rw-r--r--compiler/rustc_target/src/spec/android_base.rs1
-rw-r--r--compiler/rustc_target/src/spec/linux_base.rs1
-rw-r--r--compiler/rustc_target/src/spec/linux_musl_base.rs2
3 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_target/src/spec/android_base.rs b/compiler/rustc_target/src/spec/android_base.rs
index 0ea99af83a1..bb11ce8ef28 100644
--- a/compiler/rustc_target/src/spec/android_base.rs
+++ b/compiler/rustc_target/src/spec/android_base.rs
@@ -12,5 +12,6 @@ pub fn opts() -> TargetOptions {
     base.position_independent_executables = true;
     base.has_elf_tls = false;
     base.requires_uwtable = true;
+    base.crt_static_respected = false;
     base
 }
diff --git a/compiler/rustc_target/src/spec/linux_base.rs b/compiler/rustc_target/src/spec/linux_base.rs
index 52892fc3592..7ad972b0692 100644
--- a/compiler/rustc_target/src/spec/linux_base.rs
+++ b/compiler/rustc_target/src/spec/linux_base.rs
@@ -28,6 +28,7 @@ pub fn opts() -> TargetOptions {
         position_independent_executables: true,
         relro_level: RelroLevel::Full,
         has_elf_tls: true,
+        crt_static_respected: true,
         ..Default::default()
     }
 }
diff --git a/compiler/rustc_target/src/spec/linux_musl_base.rs b/compiler/rustc_target/src/spec/linux_musl_base.rs
index b90e91d2901..16cc3b762f6 100644
--- a/compiler/rustc_target/src/spec/linux_musl_base.rs
+++ b/compiler/rustc_target/src/spec/linux_musl_base.rs
@@ -10,8 +10,6 @@ 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
 }