Skip to content

Commit 21e1cd9

Browse files
committed
Auto merge of rust-lang#85531 - luqmana:flip-gc, r=petrochenkov
Swap TargetOptions::linker_is_gnu default from false to true and update targets as appropriate. rust-lang#85274 gated the `--gc-sections` flag on targets that specified `linker_is_gnu` to stop us from passing it to incompatible linkers. But that had the unintended effect of the flag no longer being passed on targets for which it is valid and hence caused a regression in binary size. Given that most `ld`-style linkers are GNU compatible, this change flips our default for `linker_is_gnu` from false to true. That also means updating the targets that relied on the previous default: * Apple * Illumos * L4Re (not sure about this one) * MSVC * NvtPtx * Solaris Fixes rust-lang#85519
2 parents 51d1610 + 3221a5e commit 21e1cd9

27 files changed

+8
-22
lines changed

compiler/rustc_target/src/spec/aarch64_unknown_none.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub fn target() -> Target {
1616
executables: true,
1717
relocation_model: RelocModel::Static,
1818
disable_redzone: true,
19-
linker_is_gnu: true,
2019
max_atomic_width: Some(128),
2120
panic_strategy: PanicStrategy::Abort,
2221
unsupported_abis: super::arm_base::unsupported_abis(),

compiler/rustc_target/src/spec/aarch64_unknown_none_softfloat.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub fn target() -> Target {
1616
executables: true,
1717
relocation_model: RelocModel::Static,
1818
disable_redzone: true,
19-
linker_is_gnu: true,
2019
max_atomic_width: Some(128),
2120
panic_strategy: PanicStrategy::Abort,
2221
unsupported_abis: super::arm_base::unsupported_abis(),

compiler/rustc_target/src/spec/apple_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn opts(os: &str) -> TargetOptions {
2222
// macOS has -dead_strip, which doesn't rely on function_sections
2323
function_sections: false,
2424
dynamic_linking: true,
25+
linker_is_gnu: false,
2526
executables: true,
2627
families: vec!["unix".to_string()],
2728
is_like_osx: true,

compiler/rustc_target/src/spec/avr_gnu_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub fn target(target_cpu: String) -> Target {
1616

1717
linker: Some("avr-gcc".to_owned()),
1818
executables: true,
19-
linker_is_gnu: true,
2019
eh_frame_header: false,
2120
pre_link_args: vec![(LinkerFlavor::Gcc, vec![format!("-mmcu={}", target_cpu)])]
2221
.into_iter()

compiler/rustc_target/src/spec/dragonfly_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub fn opts() -> TargetOptions {
66
dynamic_linking: true,
77
executables: true,
88
families: vec!["unix".to_string()],
9-
linker_is_gnu: true,
109
has_rpath: true,
1110
position_independent_executables: true,
1211
relro_level: RelroLevel::Full,

compiler/rustc_target/src/spec/freebsd_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub fn opts() -> TargetOptions {
66
dynamic_linking: true,
77
executables: true,
88
families: vec!["unix".to_string()],
9-
linker_is_gnu: true,
109
has_rpath: true,
1110
position_independent_executables: true,
1211
eliminate_frame_pointer: false, // FIXME 43575

compiler/rustc_target/src/spec/fuchsia_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub fn opts() -> TargetOptions {
2727
executables: true,
2828
families: vec!["unix".to_string()],
2929
is_like_fuchsia: true,
30-
linker_is_gnu: true,
3130
pre_link_args,
3231
pre_link_objects: crt_objects::new(&[
3332
(LinkOutputKind::DynamicNoPicExe, &["Scrt1.o"]),

compiler/rustc_target/src/spec/haiku_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub fn opts() -> TargetOptions {
77
executables: true,
88
families: vec!["unix".to_string()],
99
relro_level: RelroLevel::Full,
10-
linker_is_gnu: true,
1110
..Default::default()
1211
}
1312
}

compiler/rustc_target/src/spec/hermit_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub fn opts() -> TargetOptions {
1313
linker: Some("rust-lld".to_owned()),
1414
executables: true,
1515
has_elf_tls: true,
16-
linker_is_gnu: true,
1716
pre_link_args,
1817
panic_strategy: PanicStrategy::Abort,
1918
position_independent_executables: true,

compiler/rustc_target/src/spec/hermit_kernel_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub fn opts() -> TargetOptions {
1414
linker: Some("rust-lld".to_owned()),
1515
executables: true,
1616
has_elf_tls: true,
17-
linker_is_gnu: true,
1817
pre_link_args,
1918
panic_strategy: PanicStrategy::Abort,
2019
position_independent_executables: true,

compiler/rustc_target/src/spec/illumos_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub fn opts() -> TargetOptions {
3333
has_rpath: true,
3434
families: vec!["unix".to_string()],
3535
is_like_solaris: true,
36+
linker_is_gnu: false,
3637
limit_rdylib_exports: false, // Linker doesn't support this
3738
eliminate_frame_pointer: false,
3839
eh_frame_header: false,

compiler/rustc_target/src/spec/l4re_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn opts() -> TargetOptions {
2020
executables: true,
2121
panic_strategy: PanicStrategy::Abort,
2222
linker: Some("ld".to_string()),
23+
linker_is_gnu: false,
2324
families: vec!["unix".to_string()],
2425
..Default::default()
2526
}

compiler/rustc_target/src/spec/linux_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub fn opts() -> TargetOptions {
66
dynamic_linking: true,
77
executables: true,
88
families: vec!["unix".to_string()],
9-
linker_is_gnu: true,
109
has_rpath: true,
1110
position_independent_executables: true,
1211
relro_level: RelroLevel::Full,

compiler/rustc_target/src/spec/linux_kernel_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub fn opts() -> TargetOptions {
88
// don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved
99
stack_probes: StackProbeType::Call,
1010
eliminate_frame_pointer: false,
11-
linker_is_gnu: true,
1211
position_independent_executables: true,
1312
needs_plt: true,
1413
relro_level: RelroLevel::Full,

compiler/rustc_target/src/spec/mipsel_sony_psp.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub fn target() -> Target {
2121
cpu: "mips2".to_string(),
2222
executables: true,
2323
linker: Some("rust-lld".to_owned()),
24-
linker_is_gnu: true,
2524
relocation_model: RelocModel::Static,
2625

2726
// PSP FPU only supports single precision floats.

compiler/rustc_target/src/spec/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ pub struct TargetOptions {
10861086
/// Version of DWARF to use if not using the default.
10871087
/// Useful because some platforms (osx, bsd) only want up to DWARF2.
10881088
pub dwarf_version: Option<u32>,
1089-
/// Whether the linker support GNU-like arguments such as -O. Defaults to false.
1089+
/// Whether the linker support GNU-like arguments such as -O. Defaults to true.
10901090
pub linker_is_gnu: bool,
10911091
/// The MinGW toolchain has a known issue that prevents it from correctly
10921092
/// handling COFF object files with more than 2<sup>15</sup> sections. Since each weak
@@ -1307,7 +1307,7 @@ impl Default for TargetOptions {
13071307
is_like_fuchsia: false,
13081308
is_like_wasm: false,
13091309
dwarf_version: None,
1310-
linker_is_gnu: false,
1310+
linker_is_gnu: true,
13111311
allows_weak_linkage: true,
13121312
has_rpath: false,
13131313
no_default_libraries: true,

compiler/rustc_target/src/spec/msvc_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn opts() -> TargetOptions {
1616
is_like_windows: true,
1717
is_like_msvc: true,
1818
lld_flavor: LldFlavor::Link,
19+
linker_is_gnu: false,
1920
pre_link_args,
2021
abi_return_struct_as_int: true,
2122
emit_debug_gdb_scripts: false,

compiler/rustc_target/src/spec/netbsd_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub fn opts() -> TargetOptions {
66
dynamic_linking: true,
77
executables: true,
88
families: vec!["unix".to_string()],
9-
linker_is_gnu: true,
109
no_default_libraries: false,
1110
has_rpath: true,
1211
position_independent_executables: true,

compiler/rustc_target/src/spec/nvptx64_nvidia_cuda.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub fn target() -> Target {
1414
linker_flavor: LinkerFlavor::PtxLinker,
1515
// The linker can be installed from `crates.io`.
1616
linker: Some("rust-ptx-linker".to_string()),
17+
linker_is_gnu: false,
1718

1819
// With `ptx-linker` approach, it can be later overridden via link flags.
1920
cpu: "sm_30".to_string(),

compiler/rustc_target/src/spec/openbsd_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub fn opts() -> TargetOptions {
66
dynamic_linking: true,
77
executables: true,
88
families: vec!["unix".to_string()],
9-
linker_is_gnu: true,
109
has_rpath: true,
1110
abi_return_struct_as_int: true,
1211
position_independent_executables: true,

compiler/rustc_target/src/spec/redox_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub fn opts() -> TargetOptions {
77
dynamic_linking: true,
88
executables: true,
99
families: vec!["unix".to_string()],
10-
linker_is_gnu: true,
1110
has_rpath: true,
1211
position_independent_executables: true,
1312
relro_level: RelroLevel::Full,

compiler/rustc_target/src/spec/solaris_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub fn opts() -> TargetOptions {
88
has_rpath: true,
99
families: vec!["unix".to_string()],
1010
is_like_solaris: true,
11+
linker_is_gnu: false,
1112
limit_rdylib_exports: false, // Linker doesn't support this
1213
eh_frame_header: false,
1314

compiler/rustc_target/src/spec/thumbv4t_none_eabi.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub fn target() -> Target {
2828
options: TargetOptions {
2929
linker_flavor: LinkerFlavor::Ld,
3030
linker: Some("arm-none-eabi-ld".to_string()),
31-
linker_is_gnu: true,
3231

3332
// extra args passed to the external assembler (assuming `arm-none-eabi-as`):
3433
// * activate t32/a32 interworking

compiler/rustc_target/src/spec/vxworks_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub fn opts() -> TargetOptions {
1010
dynamic_linking: true,
1111
executables: true,
1212
families: vec!["unix".to_string()],
13-
linker_is_gnu: true,
1413
has_rpath: true,
1514
has_elf_tls: true,
1615
crt_static_default: true,

compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub fn target() -> Target {
3434
// functionality, and a .wasm file.
3535
exe_suffix: ".js".to_string(),
3636
linker: None,
37-
linker_is_gnu: true,
3837
is_like_emscripten: true,
3938
panic_strategy: PanicStrategy::Unwind,
4039
post_link_args,

compiler/rustc_target/src/spec/windows_gnu_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ pub fn opts() -> TargetOptions {
6666
// FIXME(#13846) this should be enabled for windows
6767
function_sections: false,
6868
linker: Some("gcc".to_string()),
69-
linker_is_gnu: true,
7069
dynamic_linking: true,
7170
executables: true,
7271
dll_prefix: String::new(),

compiler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ pub fn target() -> Target {
5757
vendor: "fortanix".into(),
5858
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
5959
executables: true,
60-
linker_is_gnu: true,
6160
linker: Some("rust-lld".to_owned()),
6261
max_atomic_width: Some(64),
6362
cpu: "x86-64".into(),

0 commit comments

Comments
 (0)