Skip to content

Commit

Permalink
Rollup merge of #133386 - wesleywiser:update_musl_base_crt_default, r…
Browse files Browse the repository at this point in the history
…=jieyouxu

Update linux_musl base to dynamically link the crt by default

However, don't change the behavior of any existing targets at this time. For targets that used the old default, explicitly set `crt_static_default = true`.

This makes it easier for new targets to use the correct defaults while leaving the changing of individual targets to future PRs.

Related to rust-lang/compiler-team#422
  • Loading branch information
matthiaskrgr authored Dec 14, 2024
2 parents f96fdab + 3f3ee2d commit 1c24da6
Show file tree
Hide file tree
Showing 24 changed files with 99 additions and 7 deletions.
3 changes: 0 additions & 3 deletions compiler/rustc_target/src/spec/base/linux_musl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ pub(crate) fn opts() -> TargetOptions {
base.post_link_objects_self_contained = crt_objects::post_musl_self_contained();
base.link_self_contained = LinkSelfContainedDefault::InferredForMusl;

// These targets statically link libc by default
base.crt_static_default = true;

base
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub(crate) fn target() -> Target {
| SanitizerSet::MEMORY
| SanitizerSet::THREAD;

// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;

Target {
llvm_target: "aarch64-unknown-linux-musl".into(),
metadata: crate::spec::TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub(crate) fn target() -> Target {
features: "+strict-align,+v6".into(),
max_atomic_width: Some(64),
mcount: "\u{1}mcount".into(),
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
crt_static_default: true,
..base::linux_musl::opts()
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub(crate) fn target() -> Target {
features: "+strict-align,+v6,+vfp2,-d32".into(),
max_atomic_width: Some(64),
mcount: "\u{1}mcount".into(),
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
crt_static_default: true,
..base::linux_musl::opts()
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub(crate) fn target() -> Target {
max_atomic_width: Some(32),
mcount: "\u{1}mcount".into(),
has_thumb_interworking: true,
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
crt_static_default: true,
..base::linux_musl::opts()
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub(crate) fn target() -> Target {
features: "+v7,+thumb2,+soft-float,-neon".into(),
max_atomic_width: Some(64),
mcount: "\u{1}mcount".into(),
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
crt_static_default: true,
..base::linux_musl::opts()
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub(crate) fn target() -> Target {
features: "+v7,+vfp3,-d32,+thumb2,-neon".into(),
max_atomic_width: Some(64),
mcount: "\u{1}mcount".into(),
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
crt_static_default: true,
..base::linux_musl::opts()
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ pub(crate) fn target() -> Target {
let mut base = super::i686_unknown_linux_musl::target();
base.cpu = "pentium".into();
base.llvm_target = "i586-unknown-linux-musl".into();
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;
base
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub(crate) fn target() -> Target {
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-melf_i386"]);
base.stack_probes = StackProbeType::Inline;
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;

// The unwinder used by i686-unknown-linux-musl, the LLVM libunwind
// implementation, apparently relies on frame pointers existing... somehow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub(crate) fn target() -> Target {
base.cpu = "mips64r2".into();
base.features = "+mips64r2,+soft-float".into();
base.max_atomic_width = Some(64);
base.crt_static_default = false;

Target {
// LLVM doesn't recognize "muslabi64" yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub(crate) fn target() -> Target {
abi: "abi64".into(),
endian: Endian::Big,
mcount: "_mcount".into(),
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
crt_static_default: true,
..base
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub(crate) fn target() -> Target {
base.cpu = "mips64r2".into();
base.features = "+mips64r2".into();
base.max_atomic_width = Some(64);
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;
Target {
// LLVM doesn't recognize "muslabi64" yet.
llvm_target: "mips64el-unknown-linux-musl".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub(crate) fn target() -> Target {
base.cpu = "mips32r2".into();
base.features = "+mips32r2,+soft-float".into();
base.max_atomic_width = Some(32);
base.crt_static_default = false;
Target {
llvm_target: "mips-unknown-linux-musl".into(),
metadata: crate::spec::TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub(crate) fn target() -> Target {
base.cpu = "mips32r2".into();
base.features = "+mips32r2,+soft-float".into();
base.max_atomic_width = Some(32);
base.crt_static_default = false;
Target {
llvm_target: "mipsel-unknown-linux-musl".into(),
metadata: crate::spec::TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub(crate) fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;

Target {
llvm_target: "powerpc64-unknown-linux-musl".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub(crate) fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;

Target {
llvm_target: "powerpc64le-unknown-linux-musl".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub(crate) fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
base.max_atomic_width = Some(32);
base.stack_probes = StackProbeType::Inline;
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;

Target {
llvm_target: "powerpc-unknown-linux-musl".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub(crate) fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-mspe"]);
base.max_atomic_width = Some(32);
base.stack_probes = StackProbeType::Inline;
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;

Target {
llvm_target: "powerpc-unknown-linux-muslspe".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub(crate) fn target() -> Target {
llvm_abiname: "ilp32d".into(),
max_atomic_width: Some(32),
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
crt_static_default: true,
..base::linux_musl::opts()
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub(crate) fn target() -> Target {
llvm_abiname: "lp64d".into(),
max_atomic_width: Some(64),
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
crt_static_default: false,
..base::linux_musl::opts()
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub(crate) fn target() -> Target {
base.stack_probes = StackProbeType::Inline;
base.supported_sanitizers =
SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::MEMORY | SanitizerSet::THREAD;
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;

Target {
llvm_target: "s390x-unknown-linux-musl".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub(crate) fn target() -> Target {
features: "+v7,+thumb-mode,+thumb2,+vfp3,+neon".into(),
max_atomic_width: Some(64),
mcount: "\u{1}mcount".into(),
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
crt_static_default: true,
..base::linux_musl::opts()
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub(crate) fn target() -> Target {
| SanitizerSet::MEMORY
| SanitizerSet::THREAD;
base.supports_xray = true;
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;

Target {
llvm_target: "x86_64-unknown-linux-musl".into(),
Expand Down
62 changes: 62 additions & 0 deletions tests/run-make/musl-default-linking/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use run_make_support::{rustc, serde_json};

// Please do NOT add more targets to this list!
// Per https://github.com/rust-lang/compiler-team/issues/422,
// we should be trying to move these targets to dynamically link
// musl libc by default.
static LEGACY_STATIC_LINKING_TARGETS: &[&'static str] = &[
"aarch64-unknown-linux-musl",
"arm-unknown-linux-musleabi",
"arm-unknown-linux-musleabihf",
"armv5te-unknown-linux-musleabi",
"armv7-unknown-linux-musleabi",
"armv7-unknown-linux-musleabihf",
"i586-unknown-linux-musl",
"i686-unknown-linux-musl",
"mips64-unknown-linux-musl",
"mips64-unknown-linux-muslabi64",
"mips64el-unknown-linux-muslabi64",
"powerpc-unknown-linux-musl",
"powerpc-unknown-linux-muslspe",
"powerpc64-unknown-linux-musl",
"powerpc64le-unknown-linux-musl",
"riscv32gc-unknown-linux-musl",
"s390x-unknown-linux-musl",
"thumbv7neon-unknown-linux-musleabihf",
"x86_64-unknown-linux-musl",
];

fn main() {
let targets = rustc().print("target-list").run().stdout_utf8();

for target in targets.lines() {
let abi = target.split('-').last().unwrap();

if !abi.starts_with("musl") {
continue;
}

let target_spec_json = rustc()
.print("target-spec-json")
.target(target)
.arg("-Zunstable-options")
.run()
.stdout_utf8();

let target_spec: serde_json::Value =
serde_json::from_str(&target_spec_json).expect("failed to parse target-spec-json");
let default = &target_spec["crt-static-default"];

// If the value is `null`, then the default to dynamically link from
// musl_base was not overriden.
if default.is_null() {
continue;
}

if default.as_bool().expect("wasn't a boolean")
&& !LEGACY_STATIC_LINKING_TARGETS.contains(&target)
{
panic!("{target} statically links musl libc when it should dynamically link it");
}
}
}

0 comments on commit 1c24da6

Please sign in to comment.