Skip to content

Commit

Permalink
Auto merge of #85531 - luqmana:flip-gc, r=petrochenkov
Browse files Browse the repository at this point in the history
Swap TargetOptions::linker_is_gnu default from false to true and update targets as appropriate.

#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 #85519
  • Loading branch information
bors committed May 22, 2021
2 parents 51d1610 + 3221a5e commit 21e1cd9
Show file tree
Hide file tree
Showing 27 changed files with 8 additions and 22 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/aarch64_unknown_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub fn target() -> Target {
executables: true,
relocation_model: RelocModel::Static,
disable_redzone: true,
linker_is_gnu: true,
max_atomic_width: Some(128),
panic_strategy: PanicStrategy::Abort,
unsupported_abis: super::arm_base::unsupported_abis(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub fn target() -> Target {
executables: true,
relocation_model: RelocModel::Static,
disable_redzone: true,
linker_is_gnu: true,
max_atomic_width: Some(128),
panic_strategy: PanicStrategy::Abort,
unsupported_abis: super::arm_base::unsupported_abis(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/apple_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn opts(os: &str) -> TargetOptions {
// macOS has -dead_strip, which doesn't rely on function_sections
function_sections: false,
dynamic_linking: true,
linker_is_gnu: false,
executables: true,
families: vec!["unix".to_string()],
is_like_osx: true,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/avr_gnu_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub fn target(target_cpu: String) -> Target {

linker: Some("avr-gcc".to_owned()),
executables: true,
linker_is_gnu: true,
eh_frame_header: false,
pre_link_args: vec![(LinkerFlavor::Gcc, vec![format!("-mmcu={}", target_cpu)])]
.into_iter()
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/dragonfly_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub fn opts() -> TargetOptions {
dynamic_linking: true,
executables: true,
families: vec!["unix".to_string()],
linker_is_gnu: true,
has_rpath: true,
position_independent_executables: true,
relro_level: RelroLevel::Full,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/freebsd_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub fn opts() -> TargetOptions {
dynamic_linking: true,
executables: true,
families: vec!["unix".to_string()],
linker_is_gnu: true,
has_rpath: true,
position_independent_executables: true,
eliminate_frame_pointer: false, // FIXME 43575
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/fuchsia_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub fn opts() -> TargetOptions {
executables: true,
families: vec!["unix".to_string()],
is_like_fuchsia: true,
linker_is_gnu: true,
pre_link_args,
pre_link_objects: crt_objects::new(&[
(LinkOutputKind::DynamicNoPicExe, &["Scrt1.o"]),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/haiku_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub fn opts() -> TargetOptions {
executables: true,
families: vec!["unix".to_string()],
relro_level: RelroLevel::Full,
linker_is_gnu: true,
..Default::default()
}
}
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/hermit_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub fn opts() -> TargetOptions {
linker: Some("rust-lld".to_owned()),
executables: true,
has_elf_tls: true,
linker_is_gnu: true,
pre_link_args,
panic_strategy: PanicStrategy::Abort,
position_independent_executables: true,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/hermit_kernel_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub fn opts() -> TargetOptions {
linker: Some("rust-lld".to_owned()),
executables: true,
has_elf_tls: true,
linker_is_gnu: true,
pre_link_args,
panic_strategy: PanicStrategy::Abort,
position_independent_executables: true,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/illumos_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub fn opts() -> TargetOptions {
has_rpath: true,
families: vec!["unix".to_string()],
is_like_solaris: true,
linker_is_gnu: false,
limit_rdylib_exports: false, // Linker doesn't support this
eliminate_frame_pointer: false,
eh_frame_header: false,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/l4re_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn opts() -> TargetOptions {
executables: true,
panic_strategy: PanicStrategy::Abort,
linker: Some("ld".to_string()),
linker_is_gnu: false,
families: vec!["unix".to_string()],
..Default::default()
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/linux_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub fn opts() -> TargetOptions {
dynamic_linking: true,
executables: true,
families: vec!["unix".to_string()],
linker_is_gnu: true,
has_rpath: true,
position_independent_executables: true,
relro_level: RelroLevel::Full,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/linux_kernel_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub fn opts() -> TargetOptions {
// don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved
stack_probes: StackProbeType::Call,
eliminate_frame_pointer: false,
linker_is_gnu: true,
position_independent_executables: true,
needs_plt: true,
relro_level: RelroLevel::Full,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/mipsel_sony_psp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub fn target() -> Target {
cpu: "mips2".to_string(),
executables: true,
linker: Some("rust-lld".to_owned()),
linker_is_gnu: true,
relocation_model: RelocModel::Static,

// PSP FPU only supports single precision floats.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ pub struct TargetOptions {
/// Version of DWARF to use if not using the default.
/// Useful because some platforms (osx, bsd) only want up to DWARF2.
pub dwarf_version: Option<u32>,
/// Whether the linker support GNU-like arguments such as -O. Defaults to false.
/// Whether the linker support GNU-like arguments such as -O. Defaults to true.
pub linker_is_gnu: bool,
/// The MinGW toolchain has a known issue that prevents it from correctly
/// handling COFF object files with more than 2<sup>15</sup> sections. Since each weak
Expand Down Expand Up @@ -1307,7 +1307,7 @@ impl Default for TargetOptions {
is_like_fuchsia: false,
is_like_wasm: false,
dwarf_version: None,
linker_is_gnu: false,
linker_is_gnu: true,
allows_weak_linkage: true,
has_rpath: false,
no_default_libraries: true,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/msvc_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn opts() -> TargetOptions {
is_like_windows: true,
is_like_msvc: true,
lld_flavor: LldFlavor::Link,
linker_is_gnu: false,
pre_link_args,
abi_return_struct_as_int: true,
emit_debug_gdb_scripts: false,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/netbsd_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub fn opts() -> TargetOptions {
dynamic_linking: true,
executables: true,
families: vec!["unix".to_string()],
linker_is_gnu: true,
no_default_libraries: false,
has_rpath: true,
position_independent_executables: true,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/nvptx64_nvidia_cuda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn target() -> Target {
linker_flavor: LinkerFlavor::PtxLinker,
// The linker can be installed from `crates.io`.
linker: Some("rust-ptx-linker".to_string()),
linker_is_gnu: false,

// With `ptx-linker` approach, it can be later overridden via link flags.
cpu: "sm_30".to_string(),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/openbsd_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub fn opts() -> TargetOptions {
dynamic_linking: true,
executables: true,
families: vec!["unix".to_string()],
linker_is_gnu: true,
has_rpath: true,
abi_return_struct_as_int: true,
position_independent_executables: true,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/redox_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub fn opts() -> TargetOptions {
dynamic_linking: true,
executables: true,
families: vec!["unix".to_string()],
linker_is_gnu: true,
has_rpath: true,
position_independent_executables: true,
relro_level: RelroLevel::Full,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/solaris_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub fn opts() -> TargetOptions {
has_rpath: true,
families: vec!["unix".to_string()],
is_like_solaris: true,
linker_is_gnu: false,
limit_rdylib_exports: false, // Linker doesn't support this
eh_frame_header: false,

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/thumbv4t_none_eabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub fn target() -> Target {
options: TargetOptions {
linker_flavor: LinkerFlavor::Ld,
linker: Some("arm-none-eabi-ld".to_string()),
linker_is_gnu: true,

// extra args passed to the external assembler (assuming `arm-none-eabi-as`):
// * activate t32/a32 interworking
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/vxworks_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub fn opts() -> TargetOptions {
dynamic_linking: true,
executables: true,
families: vec!["unix".to_string()],
linker_is_gnu: true,
has_rpath: true,
has_elf_tls: true,
crt_static_default: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub fn target() -> Target {
// functionality, and a .wasm file.
exe_suffix: ".js".to_string(),
linker: None,
linker_is_gnu: true,
is_like_emscripten: true,
panic_strategy: PanicStrategy::Unwind,
post_link_args,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/windows_gnu_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ pub fn opts() -> TargetOptions {
// FIXME(#13846) this should be enabled for windows
function_sections: false,
linker: Some("gcc".to_string()),
linker_is_gnu: true,
dynamic_linking: true,
executables: true,
dll_prefix: String::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub fn target() -> Target {
vendor: "fortanix".into(),
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
executables: true,
linker_is_gnu: true,
linker: Some("rust-lld".to_owned()),
max_atomic_width: Some(64),
cpu: "x86-64".into(),
Expand Down

0 comments on commit 21e1cd9

Please sign in to comment.