Skip to content

Commit c79d6be

Browse files
committed
Auto merge of #109982 - durin42:plt-no-x86_64-only, r=nikic
rustc_session: default to -Z plt=yes on non-x86_64 Per the discussion in #106380 plt=no isn't a great default, and rust-lang/compiler-team#581 decided that the default should be PLT=yes for everything except x86_64. Not everyone agrees about the x86_64 part of this change, but this at least is an improvement in the state of things without changing the x86_64 situation, so I've attempted making this change in the name of not letting the perfect be the enemy of the good. Please let me know if I've messed this up somehow - I'm not wholly confident I got this right. r? `@nikic`
2 parents 54d6738 + 52d50fb commit c79d6be

30 files changed

+54
-29
lines changed

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ options! {
16131613
plt: Option<bool> = (None, parse_opt_bool, [TRACKED],
16141614
"whether to use the PLT when calling into shared libraries;
16151615
only has effect for PIC code on systems with ELF binaries
1616-
(default: PLT is disabled if full relro is enabled)"),
1616+
(default: PLT is disabled if full relro is enabled on x86_64)"),
16171617
polonius: bool = (false, parse_bool, [TRACKED],
16181618
"enable polonius-based borrow-checker (default: no)"),
16191619
polymorphize: bool = (false, parse_bool, [TRACKED],

compiler/rustc_session/src/session.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1009,11 +1009,11 @@ impl Session {
10091009
self.edition().rust_2024()
10101010
}
10111011

1012-
/// Returns `true` if we cannot skip the PLT for shared library calls.
1012+
/// Returns `true` if we should use the PLT for shared library calls.
10131013
pub fn needs_plt(&self) -> bool {
1014-
// Check if the current target usually needs PLT to be enabled.
1014+
// Check if the current target usually wants PLT to be enabled.
10151015
// The user can use the command line flag to override it.
1016-
let needs_plt = self.target.needs_plt;
1016+
let want_plt = self.target.plt_by_default;
10171017

10181018
let dbg_opts = &self.opts.unstable_opts;
10191019

@@ -1025,8 +1025,8 @@ impl Session {
10251025
let full_relro = RelroLevel::Full == relro_level;
10261026

10271027
// If user didn't explicitly forced us to use / skip the PLT,
1028-
// then try to skip it where possible.
1029-
dbg_opts.plt.unwrap_or(needs_plt || !full_relro)
1028+
// then use it unless the target doesn't want it by default or the full relro forces it on.
1029+
dbg_opts.plt.unwrap_or(want_plt || !full_relro)
10301030
}
10311031

10321032
/// Checks if LLVM lifetime markers should be emitted.

compiler/rustc_target/src/spec/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ pub struct TargetOptions {
16701670
pub static_position_independent_executables: bool,
16711671
/// Determines if the target always requires using the PLT for indirect
16721672
/// library calls or not. This controls the default value of the `-Z plt` flag.
1673-
pub needs_plt: bool,
1673+
pub plt_by_default: bool,
16741674
/// Either partial, full, or off. Full RELRO makes the dynamic linker
16751675
/// resolve all symbols at startup and marks the GOT read-only before
16761676
/// starting the program, preventing overwriting the GOT.
@@ -1992,7 +1992,7 @@ impl Default for TargetOptions {
19921992
no_default_libraries: true,
19931993
position_independent_executables: false,
19941994
static_position_independent_executables: false,
1995-
needs_plt: false,
1995+
plt_by_default: true,
19961996
relro_level: RelroLevel::None,
19971997
pre_link_objects: Default::default(),
19981998
post_link_objects: Default::default(),
@@ -2665,7 +2665,7 @@ impl Target {
26652665
key!(no_default_libraries, bool);
26662666
key!(position_independent_executables, bool);
26672667
key!(static_position_independent_executables, bool);
2668-
key!(needs_plt, bool);
2668+
key!(plt_by_default, bool);
26692669
key!(relro_level, RelroLevel)?;
26702670
key!(archive_format);
26712671
key!(allow_asm, bool);
@@ -2921,7 +2921,7 @@ impl ToJson for Target {
29212921
target_option_val!(no_default_libraries);
29222922
target_option_val!(position_independent_executables);
29232923
target_option_val!(static_position_independent_executables);
2924-
target_option_val!(needs_plt);
2924+
target_option_val!(plt_by_default);
29252925
target_option_val!(relro_level);
29262926
target_option_val!(archive_format);
29272927
target_option_val!(allow_asm);

compiler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub fn target() -> Target {
6363
linker: Some("rust-lld".into()),
6464
max_atomic_width: Some(64),
6565
cpu: "x86-64".into(),
66+
plt_by_default: false,
6667
features: "+rdrnd,+rdseed,+lvi-cfi,+lvi-load-hardening".into(),
6768
llvm_args: cvs!["--x86-experimental-lvi-inline-asm-hardening"],
6869
position_independent_executables: true,

compiler/rustc_target/src/spec/x86_64_linux_android.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target, T
33
pub fn target() -> Target {
44
let mut base = super::android_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
// https://developer.android.com/ndk/guides/abis.html#86-64
78
base.features = "+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt".into();
89
base.max_atomic_width = Some(64);

compiler/rustc_target/src/spec/x86_64_pc_nto_qnx710.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub fn target() -> Target {
1010
arch: "x86_64".into(),
1111
options: TargetOptions {
1212
cpu: "x86-64".into(),
13+
plt_by_default: false,
1314
max_atomic_width: Some(64),
1415
pre_link_args: TargetOptions::link_args(
1516
LinkerFlavor::Gnu(Cc::Yes, Lld::No),

compiler/rustc_target/src/spec/x86_64_pc_solaris.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub fn target() -> Target {
44
let mut base = super::solaris_base::opts();
55
base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), &["-m64"]);
66
base.cpu = "x86-64".into();
7+
base.plt_by_default = false;
78
base.vendor = "pc".into();
89
base.max_atomic_width = Some(64);
910
base.stack_probes = StackProbeType::X86;

compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, Target};
33
pub fn target() -> Target {
44
let mut base = super::windows_gnu_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
// Use high-entropy 64 bit address space for ASLR
78
base.add_pre_link_args(
89
LinkerFlavor::Gnu(Cc::No, Lld::No),

compiler/rustc_target/src/spec/x86_64_pc_windows_gnullvm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, Target};
33
pub fn target() -> Target {
44
let mut base = super::windows_gnullvm_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
78
base.max_atomic_width = Some(64);
89
base.linker = Some("x86_64-w64-mingw32-clang".into());

compiler/rustc_target/src/spec/x86_64_pc_windows_msvc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::Target;
33
pub fn target() -> Target {
44
let mut base = super::windows_msvc_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78

89
Target {

compiler/rustc_target/src/spec/x86_64_sun_solaris.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub fn target() -> Target {
44
let mut base = super::solaris_base::opts();
55
base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), &["-m64"]);
66
base.cpu = "x86-64".into();
7+
base.plt_by_default = false;
78
base.vendor = "sun".into();
89
base.max_atomic_width = Some(64);
910
base.stack_probes = StackProbeType::X86;

compiler/rustc_target/src/spec/x86_64_unknown_dragonfly.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target};
33
pub fn target() -> Target {
44
let mut base = super::dragonfly_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
89
base.stack_probes = StackProbeType::X86;

compiler/rustc_target/src/spec/x86_64_unknown_freebsd.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target};
33
pub fn target() -> Target {
44
let mut base = super::freebsd_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
89
base.stack_probes = StackProbeType::X86;

compiler/rustc_target/src/spec/x86_64_unknown_fuchsia.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{SanitizerSet, StackProbeType, Target};
33
pub fn target() -> Target {
44
let mut base = super::fuchsia_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.stack_probes = StackProbeType::X86;
89
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI;

compiler/rustc_target/src/spec/x86_64_unknown_haiku.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target};
33
pub fn target() -> Target {
44
let mut base = super::haiku_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
89
base.stack_probes = StackProbeType::X86;

compiler/rustc_target/src/spec/x86_64_unknown_hermit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{StackProbeType, Target};
33
pub fn target() -> Target {
44
let mut base = super::hermit_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.features = "+rdrnd,+rdseed".into();
89
base.stack_probes = StackProbeType::X86;

compiler/rustc_target/src/spec/x86_64_unknown_illumos.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub fn target() -> Target {
44
let mut base = super::illumos_base::opts();
55
base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), &["-m64", "-std=c99"]);
66
base.cpu = "x86-64".into();
7+
base.plt_by_default = false;
78
base.max_atomic_width = Some(64);
89
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
910

compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{PanicStrategy, Target};
33
pub fn target() -> Target {
44
let mut base = super::l4re_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.panic_strategy = PanicStrategy::Abort;
89

compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target};
33
pub fn target() -> Target {
44
let mut base = super::linux_gnu_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
89
base.stack_probes = StackProbeType::X86;

compiler/rustc_target/src/spec/x86_64_unknown_linux_gnux32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn target() -> Target {
1010
base.has_thread_local = false;
1111
// BUG(GabrielMajeri): disabling the PLT on x86_64 Linux with x32 ABI
1212
// breaks code gen. See LLVM bug 36743
13-
base.needs_plt = true;
13+
base.plt_by_default = true;
1414

1515
Target {
1616
llvm_target: "x86_64-unknown-linux-gnux32".into(),

compiler/rustc_target/src/spec/x86_64_unknown_linux_musl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target};
33
pub fn target() -> Target {
44
let mut base = super::linux_musl_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
89
base.stack_probes = StackProbeType::X86;

compiler/rustc_target/src/spec/x86_64_unknown_netbsd.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target, T
33
pub fn target() -> Target {
44
let mut base = super::netbsd_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
89
base.stack_probes = StackProbeType::X86;

compiler/rustc_target/src/spec/x86_64_unknown_none.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use super::{RelroLevel, SanitizerSet, StackProbeType, Target, TargetOptions};
1010
pub fn target() -> Target {
1111
let opts = TargetOptions {
1212
cpu: "x86-64".into(),
13+
plt_by_default: false,
1314
max_atomic_width: Some(64),
1415
stack_probes: StackProbeType::X86,
1516
position_independent_executables: true,

compiler/rustc_target/src/spec/x86_64_unknown_openbsd.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target};
33
pub fn target() -> Target {
44
let mut base = super::openbsd_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
89
base.stack_probes = StackProbeType::X86;

compiler/rustc_target/src/spec/x86_64_unknown_redox.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target};
33
pub fn target() -> Target {
44
let mut base = super::redox_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
89
base.stack_probes = StackProbeType::X86;

compiler/rustc_target/src/spec/x86_64_unknown_uefi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::spec::Target;
1010
pub fn target() -> Target {
1111
let mut base = super::uefi_msvc_base::opts();
1212
base.cpu = "x86-64".into();
13+
base.plt_by_default = false;
1314
base.max_atomic_width = Some(64);
1415

1516
// We disable MMX and SSE for now, even though UEFI allows using them. Problem is, you have to

compiler/rustc_target/src/spec/x86_64_uwp_windows_gnu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, Target};
33
pub fn target() -> Target {
44
let mut base = super::windows_uwp_gnu_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
// Use high-entropy 64 bit address space for ASLR
78
base.add_pre_link_args(
89
LinkerFlavor::Gnu(Cc::No, Lld::No),

compiler/rustc_target/src/spec/x86_64_uwp_windows_msvc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::Target;
33
pub fn target() -> Target {
44
let mut base = super::windows_uwp_msvc_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78

89
Target {

compiler/rustc_target/src/spec/x86_64_wrs_vxworks.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target};
33
pub fn target() -> Target {
44
let mut base = super::vxworks_base::opts();
55
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
67
base.max_atomic_width = Some(64);
78
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
89
base.stack_probes = StackProbeType::X86;

tests/codegen/stack-protector.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@
1010
pub fn foo() {
1111
// CHECK: @foo() unnamed_addr #0
1212

13-
// all-NOT: attributes #0 = { {{.*}} sspstrong {{.*}} }
14-
// all-NOT: attributes #0 = { {{.*}} ssp {{.*}} }
15-
// all: attributes #0 = { {{.*}} sspreq {{.*}} }
16-
// all-NOT: attributes #0 = { {{.*}} sspstrong {{.*}} }
17-
// all-NOT: attributes #0 = { {{.*}} ssp {{.*}} }
13+
// all-NOT: attributes #0 = { {{.*}}sspstrong {{.*}} }
14+
// all-NOT: attributes #0 = { {{.*}}ssp {{.*}} }
15+
// all: attributes #0 = { {{.*}}sspreq {{.*}} }
16+
// all-NOT: attributes #0 = { {{.*}}sspstrong {{.*}} }
17+
// all-NOT: attributes #0 = { {{.*}}ssp {{.*}} }
1818

19-
// strong-NOT: attributes #0 = { {{.*}} sspreq {{.*}} }
20-
// strong-NOT: attributes #0 = { {{.*}} ssp {{.*}} }
21-
// strong: attributes #0 = { {{.*}} sspstrong {{.*}} }
22-
// strong-NOT: attributes #0 = { {{.*}} sspreq {{.*}} }
23-
// strong-NOT: attributes #0 = { {{.*}} ssp {{.*}} }
19+
// strong-NOT: attributes #0 = { {{.*}}sspreq {{.*}} }
20+
// strong-NOT: attributes #0 = { {{.*}}ssp {{.*}} }
21+
// strong: attributes #0 = { {{.*}}sspstrong {{.*}} }
22+
// strong-NOT: attributes #0 = { {{.*}}sspreq {{.*}} }
23+
// strong-NOT: attributes #0 = { {{.*}}ssp {{.*}} }
2424

25-
// basic-NOT: attributes #0 = { {{.*}} sspreq {{.*}} }
26-
// basic-NOT: attributes #0 = { {{.*}} sspstrong {{.*}} }
27-
// basic: attributes #0 = { {{.*}} ssp {{.*}} }
28-
// basic-NOT: attributes #0 = { {{.*}} sspreq {{.*}} }
29-
// basic-NOT: attributes #0 = { {{.*}} sspstrong {{.*}} }
25+
// basic-NOT: attributes #0 = { {{.*}}sspreq {{.*}} }
26+
// basic-NOT: attributes #0 = { {{.*}}sspstrong {{.*}} }
27+
// basic: attributes #0 = { {{.*}}ssp {{.*}} }
28+
// basic-NOT: attributes #0 = { {{.*}}sspreq {{.*}} }
29+
// basic-NOT: attributes #0 = { {{.*}}sspstrong {{.*}} }
3030

31-
// none-NOT: attributes #0 = { {{.*}} sspreq {{.*}} }
32-
// none-NOT: attributes #0 = { {{.*}} sspstrong {{.*}} }
33-
// none-NOT: attributes #0 = { {{.*}} ssp {{.*}} }
31+
// none-NOT: attributes #0 = { {{.*}}sspreq {{.*}} }
32+
// none-NOT: attributes #0 = { {{.*}}sspstrong {{.*}} }
33+
// none-NOT: attributes #0 = { {{.*}}ssp {{.*}} }
3434
}

0 commit comments

Comments
 (0)