Skip to content

Commit 613238b

Browse files
authored
Unrolled build for rust-lang#133386
Rollup merge of rust-lang#133386 - wesleywiser:update_musl_base_crt_default, r=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
2 parents 85641f7 + 3f3ee2d commit 613238b

24 files changed

+99
-7
lines changed

compiler/rustc_target/src/spec/base/linux_musl.rs

-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@ pub(crate) fn opts() -> TargetOptions {
88
base.post_link_objects_self_contained = crt_objects::post_musl_self_contained();
99
base.link_self_contained = LinkSelfContainedDefault::InferredForMusl;
1010

11-
// These targets statically link libc by default
12-
base.crt_static_default = true;
13-
1411
base
1512
}

compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_musl.rs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pub(crate) fn target() -> Target {
1212
| SanitizerSet::MEMORY
1313
| SanitizerSet::THREAD;
1414

15+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
16+
base.crt_static_default = true;
17+
1518
Target {
1619
llvm_target: "aarch64-unknown-linux-musl".into(),
1720
metadata: crate::spec::TargetMetadata {

compiler/rustc_target/src/spec/targets/arm_unknown_linux_musleabi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub(crate) fn target() -> Target {
2222
features: "+strict-align,+v6".into(),
2323
max_atomic_width: Some(64),
2424
mcount: "\u{1}mcount".into(),
25+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
26+
crt_static_default: true,
2527
..base::linux_musl::opts()
2628
},
2729
}

compiler/rustc_target/src/spec/targets/arm_unknown_linux_musleabihf.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub(crate) fn target() -> Target {
2222
features: "+strict-align,+v6,+vfp2,-d32".into(),
2323
max_atomic_width: Some(64),
2424
mcount: "\u{1}mcount".into(),
25+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
26+
crt_static_default: true,
2527
..base::linux_musl::opts()
2628
},
2729
}

compiler/rustc_target/src/spec/targets/armv5te_unknown_linux_musleabi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub(crate) fn target() -> Target {
2323
max_atomic_width: Some(32),
2424
mcount: "\u{1}mcount".into(),
2525
has_thumb_interworking: true,
26+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
27+
crt_static_default: true,
2628
..base::linux_musl::opts()
2729
},
2830
}

compiler/rustc_target/src/spec/targets/armv7_unknown_linux_musleabi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub(crate) fn target() -> Target {
2626
features: "+v7,+thumb2,+soft-float,-neon".into(),
2727
max_atomic_width: Some(64),
2828
mcount: "\u{1}mcount".into(),
29+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
30+
crt_static_default: true,
2931
..base::linux_musl::opts()
3032
},
3133
}

compiler/rustc_target/src/spec/targets/armv7_unknown_linux_musleabihf.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub(crate) fn target() -> Target {
2525
features: "+v7,+vfp3,-d32,+thumb2,-neon".into(),
2626
max_atomic_width: Some(64),
2727
mcount: "\u{1}mcount".into(),
28+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
29+
crt_static_default: true,
2830
..base::linux_musl::opts()
2931
},
3032
}

compiler/rustc_target/src/spec/targets/i586_unknown_linux_musl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ pub(crate) fn target() -> Target {
44
let mut base = super::i686_unknown_linux_musl::target();
55
base.cpu = "pentium".into();
66
base.llvm_target = "i586-unknown-linux-musl".into();
7+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
8+
base.crt_static_default = true;
79
base
810
}

compiler/rustc_target/src/spec/targets/i686_unknown_linux_musl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub(crate) fn target() -> Target {
66
base.max_atomic_width = Some(64);
77
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-melf_i386"]);
88
base.stack_probes = StackProbeType::Inline;
9+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
10+
base.crt_static_default = true;
911

1012
// The unwinder used by i686-unknown-linux-musl, the LLVM libunwind
1113
// implementation, apparently relies on frame pointers existing... somehow.

compiler/rustc_target/src/spec/targets/mips64_openwrt_linux_musl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub(crate) fn target() -> Target {
88
base.cpu = "mips64r2".into();
99
base.features = "+mips64r2,+soft-float".into();
1010
base.max_atomic_width = Some(64);
11-
base.crt_static_default = false;
1211

1312
Target {
1413
// LLVM doesn't recognize "muslabi64" yet.

compiler/rustc_target/src/spec/targets/mips64_unknown_linux_muslabi64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub(crate) fn target() -> Target {
2222
abi: "abi64".into(),
2323
endian: Endian::Big,
2424
mcount: "_mcount".into(),
25+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
26+
crt_static_default: true,
2527
..base
2628
},
2729
}

compiler/rustc_target/src/spec/targets/mips64el_unknown_linux_muslabi64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ pub(crate) fn target() -> Target {
55
base.cpu = "mips64r2".into();
66
base.features = "+mips64r2".into();
77
base.max_atomic_width = Some(64);
8+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
9+
base.crt_static_default = true;
810
Target {
911
// LLVM doesn't recognize "muslabi64" yet.
1012
llvm_target: "mips64el-unknown-linux-musl".into(),

compiler/rustc_target/src/spec/targets/mips_unknown_linux_musl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub(crate) fn target() -> Target {
66
base.cpu = "mips32r2".into();
77
base.features = "+mips32r2,+soft-float".into();
88
base.max_atomic_width = Some(32);
9-
base.crt_static_default = false;
109
Target {
1110
llvm_target: "mips-unknown-linux-musl".into(),
1211
metadata: crate::spec::TargetMetadata {

compiler/rustc_target/src/spec/targets/mipsel_unknown_linux_musl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ pub(crate) fn target() -> Target {
55
base.cpu = "mips32r2".into();
66
base.features = "+mips32r2,+soft-float".into();
77
base.max_atomic_width = Some(32);
8-
base.crt_static_default = false;
98
Target {
109
llvm_target: "mipsel-unknown-linux-musl".into(),
1110
metadata: crate::spec::TargetMetadata {

compiler/rustc_target/src/spec/targets/powerpc64_unknown_linux_musl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ pub(crate) fn target() -> Target {
77
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
88
base.max_atomic_width = Some(64);
99
base.stack_probes = StackProbeType::Inline;
10+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
11+
base.crt_static_default = true;
1012

1113
Target {
1214
llvm_target: "powerpc64-unknown-linux-musl".into(),

compiler/rustc_target/src/spec/targets/powerpc64le_unknown_linux_musl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub(crate) fn target() -> Target {
66
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
77
base.max_atomic_width = Some(64);
88
base.stack_probes = StackProbeType::Inline;
9+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
10+
base.crt_static_default = true;
911

1012
Target {
1113
llvm_target: "powerpc64le-unknown-linux-musl".into(),

compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_musl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub(crate) fn target() -> Target {
66
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
77
base.max_atomic_width = Some(32);
88
base.stack_probes = StackProbeType::Inline;
9+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
10+
base.crt_static_default = true;
911

1012
Target {
1113
llvm_target: "powerpc-unknown-linux-musl".into(),

compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_muslspe.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub(crate) fn target() -> Target {
66
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-mspe"]);
77
base.max_atomic_width = Some(32);
88
base.stack_probes = StackProbeType::Inline;
9+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
10+
base.crt_static_default = true;
911

1012
Target {
1113
llvm_target: "powerpc-unknown-linux-muslspe".into(),

compiler/rustc_target/src/spec/targets/riscv32gc_unknown_linux_musl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub(crate) fn target() -> Target {
2323
llvm_abiname: "ilp32d".into(),
2424
max_atomic_width: Some(32),
2525
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
26+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
27+
crt_static_default: true,
2628
..base::linux_musl::opts()
2729
},
2830
}

compiler/rustc_target/src/spec/targets/riscv64gc_unknown_linux_musl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub(crate) fn target() -> Target {
2121
llvm_abiname: "lp64d".into(),
2222
max_atomic_width: Some(64),
2323
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
24-
crt_static_default: false,
2524
..base::linux_musl::opts()
2625
},
2726
}

compiler/rustc_target/src/spec/targets/s390x_unknown_linux_musl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub(crate) fn target() -> Target {
1212
base.stack_probes = StackProbeType::Inline;
1313
base.supported_sanitizers =
1414
SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::MEMORY | SanitizerSet::THREAD;
15+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
16+
base.crt_static_default = true;
1517

1618
Target {
1719
llvm_target: "s390x-unknown-linux-musl".into(),

compiler/rustc_target/src/spec/targets/thumbv7neon_unknown_linux_musleabihf.rs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub(crate) fn target() -> Target {
2929
features: "+v7,+thumb-mode,+thumb2,+vfp3,+neon".into(),
3030
max_atomic_width: Some(64),
3131
mcount: "\u{1}mcount".into(),
32+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
33+
crt_static_default: true,
3234
..base::linux_musl::opts()
3335
},
3436
}

compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_musl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub(crate) fn target() -> Target {
1414
| SanitizerSet::MEMORY
1515
| SanitizerSet::THREAD;
1616
base.supports_xray = true;
17+
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
18+
base.crt_static_default = true;
1719

1820
Target {
1921
llvm_target: "x86_64-unknown-linux-musl".into(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use run_make_support::{rustc, serde_json};
2+
3+
// Please do NOT add more targets to this list!
4+
// Per https://github.com/rust-lang/compiler-team/issues/422,
5+
// we should be trying to move these targets to dynamically link
6+
// musl libc by default.
7+
static LEGACY_STATIC_LINKING_TARGETS: &[&'static str] = &[
8+
"aarch64-unknown-linux-musl",
9+
"arm-unknown-linux-musleabi",
10+
"arm-unknown-linux-musleabihf",
11+
"armv5te-unknown-linux-musleabi",
12+
"armv7-unknown-linux-musleabi",
13+
"armv7-unknown-linux-musleabihf",
14+
"i586-unknown-linux-musl",
15+
"i686-unknown-linux-musl",
16+
"mips64-unknown-linux-musl",
17+
"mips64-unknown-linux-muslabi64",
18+
"mips64el-unknown-linux-muslabi64",
19+
"powerpc-unknown-linux-musl",
20+
"powerpc-unknown-linux-muslspe",
21+
"powerpc64-unknown-linux-musl",
22+
"powerpc64le-unknown-linux-musl",
23+
"riscv32gc-unknown-linux-musl",
24+
"s390x-unknown-linux-musl",
25+
"thumbv7neon-unknown-linux-musleabihf",
26+
"x86_64-unknown-linux-musl",
27+
];
28+
29+
fn main() {
30+
let targets = rustc().print("target-list").run().stdout_utf8();
31+
32+
for target in targets.lines() {
33+
let abi = target.split('-').last().unwrap();
34+
35+
if !abi.starts_with("musl") {
36+
continue;
37+
}
38+
39+
let target_spec_json = rustc()
40+
.print("target-spec-json")
41+
.target(target)
42+
.arg("-Zunstable-options")
43+
.run()
44+
.stdout_utf8();
45+
46+
let target_spec: serde_json::Value =
47+
serde_json::from_str(&target_spec_json).expect("failed to parse target-spec-json");
48+
let default = &target_spec["crt-static-default"];
49+
50+
// If the value is `null`, then the default to dynamically link from
51+
// musl_base was not overriden.
52+
if default.is_null() {
53+
continue;
54+
}
55+
56+
if default.as_bool().expect("wasn't a boolean")
57+
&& !LEGACY_STATIC_LINKING_TARGETS.contains(&target)
58+
{
59+
panic!("{target} statically links musl libc when it should dynamically link it");
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)