Skip to content

Commit c0e3b4f

Browse files
committed
Move link_args to MaybeLazy - part 2
Remove add_pre_link_args and replace it with explicit call to MaybeLazy::lazy(|| TargetOptions::link_args(...))
1 parent 982f4ba commit c0e3b4f

File tree

65 files changed

+395
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+395
-226
lines changed

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

+24-20
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,34 @@
99
// the timer-interrupt. Device-drivers are required to use polling-based models. Furthermore, all
1010
// code runs in the same environment, no process separation is supported.
1111

12-
use crate::spec::{base, LinkerFlavor, Lld, PanicStrategy, StackProbeType, TargetOptions};
12+
use crate::spec::{
13+
base, LinkerFlavor, Lld, MaybeLazy, PanicStrategy, StackProbeType, TargetOptions,
14+
};
1315

1416
pub fn opts() -> TargetOptions {
1517
let mut base = base::msvc::opts();
1618

17-
base.add_pre_link_args(
18-
LinkerFlavor::Msvc(Lld::No),
19-
&[
20-
// Non-standard subsystems have no default entry-point in PE+ files. We have to define
21-
// one. "efi_main" seems to be a common choice amongst other implementations and the
22-
// spec.
23-
"/entry:efi_main",
24-
// COFF images have a "Subsystem" field in their header, which defines what kind of
25-
// program it is. UEFI has 3 fields reserved, which are EFI_APPLICATION,
26-
// EFI_BOOT_SERVICE_DRIVER, and EFI_RUNTIME_DRIVER. We default to EFI_APPLICATION,
27-
// which is very likely the most common option. Individual projects can override this
28-
// with custom linker flags.
29-
// The subsystem-type only has minor effects on the application. It defines the memory
30-
// regions the application is loaded into (runtime-drivers need to be put into
31-
// reserved areas), as well as whether a return from the entry-point is treated as
32-
// exit (default for applications).
33-
"/subsystem:efi_application",
34-
],
35-
);
19+
base.pre_link_args = MaybeLazy::lazy(|| {
20+
TargetOptions::link_args(
21+
LinkerFlavor::Msvc(Lld::No),
22+
&[
23+
// Non-standard subsystems have no default entry-point in PE+ files. We have to define
24+
// one. "efi_main" seems to be a common choice amongst other implementations and the
25+
// spec.
26+
"/entry:efi_main",
27+
// COFF images have a "Subsystem" field in their header, which defines what kind of
28+
// program it is. UEFI has 3 fields reserved, which are EFI_APPLICATION,
29+
// EFI_BOOT_SERVICE_DRIVER, and EFI_RUNTIME_DRIVER. We default to EFI_APPLICATION,
30+
// which is very likely the most common option. Individual projects can override this
31+
// with custom linker flags.
32+
// The subsystem-type only has minor effects on the application. It defines the memory
33+
// regions the application is loaded into (runtime-drivers need to be put into
34+
// reserved areas), as well as whether a return from the entry-point is treated as
35+
// exit (default for applications).
36+
"/subsystem:efi_application",
37+
],
38+
)
39+
});
3640

3741
TargetOptions {
3842
os: "uefi".into(),
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use crate::spec::{base, LinkerFlavor, Lld, TargetOptions};
1+
use crate::spec::{base, LinkerFlavor, Lld, MaybeLazy, TargetOptions};
22

33
pub fn opts() -> TargetOptions {
44
let mut opts = base::windows_msvc::opts();
55

66
opts.abi = "uwp".into();
77
opts.vendor = "uwp".into();
8-
opts.add_pre_link_args(LinkerFlavor::Msvc(Lld::No), &["/APPCONTAINER", "mincore.lib"]);
8+
opts.pre_link_args = MaybeLazy::lazy(|| {
9+
TargetOptions::link_args(LinkerFlavor::Msvc(Lld::No), &["/APPCONTAINER", "mincore.lib"])
10+
});
911

1012
opts
1113
}

compiler/rustc_target/src/spec/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2361,10 +2361,6 @@ impl TargetOptions {
23612361
link_args
23622362
}
23632363

2364-
fn add_pre_link_args(&mut self, flavor: LinkerFlavor, args: &[&'static str]) {
2365-
add_link_args(&mut self.pre_link_args, flavor, args);
2366-
}
2367-
23682364
fn update_from_cli(&mut self) {
23692365
self.linker_flavor = LinkerFlavor::from_cli_json(
23702366
self.linker_flavor_json,

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use crate::spec::{base, Cc, LinkerFlavor, SanitizerSet, Target};
1+
use crate::spec::{base, Cc, LinkerFlavor, MaybeLazy, SanitizerSet, Target, TargetOptions};
22

33
pub fn target() -> Target {
44
let mut base = base::illumos::opts();
5-
base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), &["-std=c99"]);
5+
base.pre_link_args =
6+
MaybeLazy::lazy(|| TargetOptions::link_args(LinkerFlavor::Unix(Cc::Yes), &["-std=c99"]));
67
base.max_atomic_width = Some(128);
78
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI;
89
base.features = "+v8a".into();

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// This defines the aarch64 target for UEFI systems as described in the UEFI specification. See the
22
// uefi-base module for generic UEFI options.
33

4-
use crate::spec::{base, LinkerFlavor, Lld, Target};
4+
use crate::spec::{base, LinkerFlavor, Lld, MaybeLazy, Target, TargetOptions};
55

66
pub fn target() -> Target {
77
let mut base = base::uefi_msvc::opts();
88

99
base.max_atomic_width = Some(128);
10-
base.add_pre_link_args(LinkerFlavor::Msvc(Lld::No), &["/machine:arm64"]);
10+
base.pre_link_args = MaybeLazy::lazy(|| {
11+
TargetOptions::link_args(LinkerFlavor::Msvc(Lld::No), &["/machine:arm64"])
12+
});
1113
base.features = "+v8a".into();
1214

1315
Target {

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{base, Cc, LinkerFlavor, Lld, SanitizerSet, Target, TargetOptions};
1+
use crate::spec::{base, Cc, LinkerFlavor, Lld, MaybeLazy, SanitizerSet, Target, TargetOptions};
22

33
// This target if is for the baseline of the Android v7a ABI
44
// in thumb mode. It's named armv7-* instead of thumbv7-*
@@ -10,7 +10,9 @@ use crate::spec::{base, Cc, LinkerFlavor, Lld, SanitizerSet, Target, TargetOptio
1010

1111
pub fn target() -> Target {
1212
let mut base = base::android::opts();
13-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-march=armv7-a"]);
13+
base.pre_link_args = MaybeLazy::lazy(|| {
14+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-march=armv7-a"])
15+
});
1416
Target {
1517
llvm_target: "armv7-none-linux-android".into(),
1618
metadata: crate::spec::TargetMetadata {

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ pub fn target() -> Target {
88

99
let mut base = opts(OS, ARCH, MaybeLazy::lazy(|| pre_link_args(OS, ARCH)));
1010
base.max_atomic_width = Some(64);
11-
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m32"]);
11+
base.pre_link_args = MaybeLazy::lazy(|| {
12+
TargetOptions::link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m32"])
13+
});
1214
base.frame_pointer = FramePointer::Always;
1315

1416
Target {

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::spec::{base, Cc, FramePointer, LinkerFlavor, Lld, Target};
1+
use crate::spec::{
2+
add_link_args, base, Cc, FramePointer, LinkerFlavor, Lld, MaybeLazy, Target, TargetOptions,
3+
};
24

35
pub fn target() -> Target {
46
let mut base = base::windows_gnu::opts();
@@ -9,11 +11,18 @@ pub fn target() -> Target {
911

1012
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
1113
// space available to x86 Windows binaries on x86_64.
12-
base.add_pre_link_args(
13-
LinkerFlavor::Gnu(Cc::No, Lld::No),
14-
&["-m", "i386pe", "--large-address-aware"],
15-
);
16-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-Wl,--large-address-aware"]);
14+
base.pre_link_args = MaybeLazy::lazy(|| {
15+
let mut pre_link_args = TargetOptions::link_args(
16+
LinkerFlavor::Gnu(Cc::No, Lld::No),
17+
&["-m", "i386pe", "--large-address-aware"],
18+
);
19+
add_link_args(
20+
&mut pre_link_args,
21+
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
22+
&["-Wl,--large-address-aware"],
23+
);
24+
pre_link_args
25+
});
1726

1827
Target {
1928
llvm_target: "i686-pc-windows-gnu".into(),

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{base, Cc, FramePointer, LinkerFlavor, Lld, Target};
1+
use crate::spec::{base, Cc, FramePointer, LinkerFlavor, Lld, MaybeLazy, Target, TargetOptions};
22

33
pub fn target() -> Target {
44
let mut base = base::windows_gnullvm::opts();
@@ -9,10 +9,12 @@ pub fn target() -> Target {
99

1010
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
1111
// space available to x86 Windows binaries on x86_64.
12-
base.add_pre_link_args(
13-
LinkerFlavor::Gnu(Cc::No, Lld::No),
14-
&["-m", "i386pe", "--large-address-aware"],
15-
);
12+
base.pre_link_args = MaybeLazy::lazy(|| {
13+
TargetOptions::link_args(
14+
LinkerFlavor::Gnu(Cc::No, Lld::No),
15+
&["-m", "i386pe", "--large-address-aware"],
16+
)
17+
});
1618

1719
Target {
1820
llvm_target: "i686-pc-windows-gnu".into(),

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

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
use crate::spec::{base, LinkerFlavor, Lld, SanitizerSet, Target};
1+
use crate::spec::{base, LinkerFlavor, Lld, MaybeLazy, SanitizerSet, Target, TargetOptions};
22

33
pub fn target() -> Target {
44
let mut base = base::windows_msvc::opts();
55
base.cpu = "pentium4".into();
66
base.max_atomic_width = Some(64);
77
base.supported_sanitizers = SanitizerSet::ADDRESS;
88

9-
base.add_pre_link_args(
10-
LinkerFlavor::Msvc(Lld::No),
11-
&[
12-
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
13-
// space available to x86 Windows binaries on x86_64.
14-
"/LARGEADDRESSAWARE",
15-
// Ensure the linker will only produce an image if it can also produce a table of
16-
// the image's safe exception handlers.
17-
// https://docs.microsoft.com/en-us/cpp/build/reference/safeseh-image-has-safe-exception-handlers
18-
"/SAFESEH",
19-
],
20-
);
9+
base.pre_link_args = MaybeLazy::lazy(|| {
10+
TargetOptions::link_args(
11+
LinkerFlavor::Msvc(Lld::No),
12+
&[
13+
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
14+
// space available to x86 Windows binaries on x86_64.
15+
"/LARGEADDRESSAWARE",
16+
// Ensure the linker will only produce an image if it can also produce a table of
17+
// the image's safe exception handlers.
18+
// https://docs.microsoft.com/en-us/cpp/build/reference/safeseh-image-has-safe-exception-handlers
19+
"/SAFESEH",
20+
],
21+
)
22+
});
2123

2224
Target {
2325
llvm_target: "i686-pc-windows-msvc".into(),

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use crate::spec::{base, Cc, LinkerFlavor, Lld, StackProbeType, Target};
1+
use crate::spec::{base, Cc, LinkerFlavor, Lld, MaybeLazy, StackProbeType, Target, TargetOptions};
22

33
pub fn target() -> Target {
44
let mut base = base::freebsd::opts();
55
base.cpu = "pentium4".into();
66
base.max_atomic_width = Some(64);
7-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-znotext"]);
7+
base.pre_link_args = MaybeLazy::lazy(|| {
8+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-znotext"])
9+
});
810
base.stack_probes = StackProbeType::Inline;
911

1012
Target {

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use crate::spec::{base, Cc, LinkerFlavor, Lld, StackProbeType, Target};
1+
use crate::spec::{base, Cc, LinkerFlavor, Lld, MaybeLazy, StackProbeType, Target, TargetOptions};
22

33
pub fn target() -> Target {
44
let mut base = base::haiku::opts();
55
base.cpu = "pentium4".into();
66
base.max_atomic_width = Some(64);
7-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
7+
base.pre_link_args = MaybeLazy::lazy(|| {
8+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"])
9+
});
810
base.stack_probes = StackProbeType::Inline;
911

1012
Target {

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use crate::spec::{base, Cc, LinkerFlavor, Lld, StackProbeType, Target};
1+
use crate::spec::{base, Cc, LinkerFlavor, Lld, MaybeLazy, StackProbeType, Target, TargetOptions};
22

33
pub fn target() -> Target {
44
let mut base = base::hurd_gnu::opts();
55
base.cpu = "pentiumpro".into();
66
base.max_atomic_width = Some(64);
7-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
7+
base.pre_link_args = MaybeLazy::lazy(|| {
8+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"])
9+
});
810
base.stack_probes = StackProbeType::Inline;
911

1012
Target {

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
use crate::spec::{base, Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target};
1+
use crate::spec::{
2+
base, Cc, LinkerFlavor, Lld, MaybeLazy, SanitizerSet, StackProbeType, Target, TargetOptions,
3+
};
24

35
pub fn target() -> Target {
46
let mut base = base::linux_gnu::opts();
57
base.cpu = "pentium4".into();
68
base.max_atomic_width = Some(64);
79
base.supported_sanitizers = SanitizerSet::ADDRESS;
8-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
10+
base.pre_link_args = MaybeLazy::lazy(|| {
11+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"])
12+
});
913
base.stack_probes = StackProbeType::Inline;
1014

1115
Target {

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
use crate::spec::{base, Cc, FramePointer, LinkerFlavor, Lld, StackProbeType, Target};
1+
use crate::spec::{
2+
base, Cc, FramePointer, LinkerFlavor, Lld, MaybeLazy, StackProbeType, Target, TargetOptions,
3+
};
24

35
pub fn target() -> Target {
46
let mut base = base::linux_musl::opts();
57
base.cpu = "pentium4".into();
68
base.max_atomic_width = Some(64);
7-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-melf_i386"]);
9+
base.pre_link_args = MaybeLazy::lazy(|| {
10+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-melf_i386"])
11+
});
812
base.stack_probes = StackProbeType::Inline;
913

1014
// The unwinder used by i686-unknown-linux-musl, the LLVM libunwind

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use crate::spec::{base, Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions};
1+
use crate::spec::{base, Cc, LinkerFlavor, Lld, MaybeLazy, StackProbeType, Target, TargetOptions};
22

33
pub fn target() -> Target {
44
let mut base = base::netbsd::opts();
55
base.cpu = "pentium4".into();
66
base.max_atomic_width = Some(64);
7-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
7+
base.pre_link_args = MaybeLazy::lazy(|| {
8+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"])
9+
});
810
base.stack_probes = StackProbeType::Inline;
911

1012
Target {

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use crate::spec::{base, Cc, LinkerFlavor, Lld, StackProbeType, Target};
1+
use crate::spec::{base, Cc, LinkerFlavor, Lld, MaybeLazy, StackProbeType, Target, TargetOptions};
22

33
pub fn target() -> Target {
44
let mut base = base::openbsd::opts();
55
base.cpu = "pentium4".into();
66
base.max_atomic_width = Some(64);
7-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-fuse-ld=lld"]);
7+
base.pre_link_args = MaybeLazy::lazy(|| {
8+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-fuse-ld=lld"])
9+
});
810
base.stack_probes = StackProbeType::Inline;
911

1012
Target {

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::spec::{base, Cc, FramePointer, LinkerFlavor, Lld, Target};
1+
use crate::spec::{
2+
add_link_args, base, Cc, FramePointer, LinkerFlavor, Lld, MaybeLazy, Target, TargetOptions,
3+
};
24

35
pub fn target() -> Target {
46
let mut base = base::windows_uwp_gnu::opts();
@@ -8,11 +10,18 @@ pub fn target() -> Target {
810

911
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
1012
// space available to x86 Windows binaries on x86_64.
11-
base.add_pre_link_args(
12-
LinkerFlavor::Gnu(Cc::No, Lld::No),
13-
&["-m", "i386pe", "--large-address-aware"],
14-
);
15-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-Wl,--large-address-aware"]);
13+
base.pre_link_args = MaybeLazy::lazy(|| {
14+
let mut pre_link_args = TargetOptions::link_args(
15+
LinkerFlavor::Gnu(Cc::No, Lld::No),
16+
&["-m", "i386pe", "--large-address-aware"],
17+
);
18+
add_link_args(
19+
&mut pre_link_args,
20+
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
21+
&["-Wl,--large-address-aware"],
22+
);
23+
pre_link_args
24+
});
1625

1726
Target {
1827
llvm_target: "i686-pc-windows-gnu".into(),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{base, LinkerFlavor, Lld, Target};
1+
use crate::spec::{base, LinkerFlavor, Lld, MaybeLazy, Target, TargetOptions};
22

33
pub fn target() -> Target {
44
let mut base = base::windows_msvc::opts();

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use crate::spec::{base, Cc, LinkerFlavor, Lld, StackProbeType, Target};
1+
use crate::spec::{base, Cc, LinkerFlavor, Lld, MaybeLazy, StackProbeType, Target, TargetOptions};
22

33
pub fn target() -> Target {
44
let mut base = base::vxworks::opts();
55
base.cpu = "pentium4".into();
66
base.max_atomic_width = Some(64);
7-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
7+
base.pre_link_args = MaybeLazy::lazy(|| {
8+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"])
9+
});
810
base.stack_probes = StackProbeType::Inline;
911

1012
Target {

0 commit comments

Comments
 (0)