Skip to content

Commit

Permalink
Support static linking with glibc and target-feature=+crt-static
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshtriplett committed Oct 5, 2020
1 parent 9d952cb commit a3944a0
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 2 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/android_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/linux_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
2 changes: 0 additions & 2 deletions compiler/rustc_target/src/spec/linux_musl_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit a3944a0

Please sign in to comment.