Skip to content

Commit 99557fc

Browse files
committed
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. Update to libc 0.2.78, 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.
1 parent 5fdf436 commit 99557fc

File tree

4 files changed

+3
-3
lines changed

4 files changed

+3
-3
lines changed

compiler/rustc_target/src/spec/android_base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ pub fn opts() -> TargetOptions {
1212
base.position_independent_executables = true;
1313
base.has_elf_tls = false;
1414
base.requires_uwtable = true;
15+
base.crt_static_respected = false;
1516
base
1617
}

compiler/rustc_target/src/spec/linux_base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub fn opts() -> TargetOptions {
2828
position_independent_executables: true,
2929
relro_level: RelroLevel::Full,
3030
has_elf_tls: true,
31+
crt_static_respected: true,
3132
..Default::default()
3233
}
3334
}

compiler/rustc_target/src/spec/linux_musl_base.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ pub fn opts() -> TargetOptions {
1010

1111
// These targets statically link libc by default
1212
base.crt_static_default = true;
13-
// These targets allow the user to choose between static and dynamic linking.
14-
base.crt_static_respected = true;
1513

1614
base
1715
}

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
1616
panic_unwind = { path = "../panic_unwind", optional = true }
1717
panic_abort = { path = "../panic_abort" }
1818
core = { path = "../core" }
19-
libc = { version = "0.2.77", default-features = false, features = ['rustc-dep-of-std'] }
19+
libc = { version = "0.2.78", default-features = false, features = ['rustc-dep-of-std'] }
2020
compiler_builtins = { version = "0.1.35" }
2121
profiler_builtins = { path = "../profiler_builtins", optional = true }
2222
unwind = { path = "../unwind" }

0 commit comments

Comments
 (0)