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.
This commit is contained in:
Josh Triplett 2020-09-20 23:02:38 -07:00
parent 9d952cbe95
commit a3944a0abd
3 changed files with 2 additions and 2 deletions

View File

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

View File

@ -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()
}
}

View File

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