Skip to content

Commit a3944a0

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. 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.
1 parent 9d952cb commit a3944a0

File tree

3 files changed

+2
-2
lines changed

3 files changed

+2
-2
lines changed

compiler/rustc_target/src/spec/android_base.rs

+1
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

+1
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

-2
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
}

0 commit comments

Comments
 (0)