Skip to content

Commit a040142

Browse files
Urgaupetrochenkov
authored andcommitted
WIP
1 parent 20ba13c commit a040142

File tree

115 files changed

+1097
-662
lines changed

Some content is hidden

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

115 files changed

+1097
-662
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ fn add_pre_link_objects(
18571857
// FIXME: we are currently missing some infra here (per-linker-flavor CRT objects),
18581858
// so Fuchsia has to be special-cased.
18591859
let opts = &sess.target;
1860-
let empty = Default::default();
1860+
let empty = CrtObjects::default();
18611861
let objects = if self_contained {
18621862
&opts.pre_link_objects_self_contained
18631863
} else if !(sess.target.os == "fuchsia" && matches!(flavor, LinkerFlavor::Gnu(Cc::Yes, _))) {

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::abi::Endian;
2-
use crate::spec::{crt_objects, cvs, Cc, CodeModel, LinkOutputKind, LinkerFlavor, TargetOptions};
2+
use crate::spec::{crt_objects, cvs, Cc, CodeModel, LinkOutputKind, LinkerFlavor};
3+
use crate::spec::{MaybeLazy, TargetOptions};
34

45
pub fn opts() -> TargetOptions {
56
TargetOptions {
@@ -22,10 +23,12 @@ pub fn opts() -> TargetOptions {
2223
is_like_aix: true,
2324
default_dwarf_version: 3,
2425
function_sections: true,
25-
pre_link_objects: crt_objects::new(&[
26-
(LinkOutputKind::DynamicNoPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
27-
(LinkOutputKind::DynamicPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
28-
]),
26+
pre_link_objects: MaybeLazy::lazy(|| {
27+
crt_objects::new(&[
28+
(LinkOutputKind::DynamicNoPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
29+
(LinkOutputKind::DynamicPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
30+
])
31+
}),
2932
dll_suffix: ".a".into(),
3033
..Default::default()
3134
}

compiler/rustc_target/src/spec/base/apple/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{borrow::Cow, env};
22

3-
use crate::spec::{add_link_args, add_link_args_iter};
3+
use crate::spec::{add_link_args, add_link_args_iter, MaybeLazy};
44
use crate::spec::{cvs, Cc, DebuginfoKind, FramePointer, LinkArgs, LinkerFlavor, Lld};
55
use crate::spec::{SplitDebuginfo, StackProbeType, StaticCow, Target, TargetOptions};
66

@@ -94,7 +94,7 @@ impl TargetAbi {
9494
}
9595
}
9696

97-
fn pre_link_args(os: &'static str, arch: Arch, abi: TargetAbi) -> LinkArgs {
97+
pub fn pre_link_args(os: &'static str, arch: Arch, abi: TargetAbi) -> LinkArgs {
9898
let platform_name: StaticCow<str> = match abi {
9999
TargetAbi::Normal => os.into(),
100100
TargetAbi::Simulator => format!("{os}-simulator").into(),
@@ -140,7 +140,12 @@ fn pre_link_args(os: &'static str, arch: Arch, abi: TargetAbi) -> LinkArgs {
140140
args
141141
}
142142

143-
pub fn opts(os: &'static str, arch: Arch, abi: TargetAbi) -> TargetOptions {
143+
pub fn opts(
144+
os: &'static str,
145+
arch: Arch,
146+
abi: TargetAbi,
147+
pre_link_args: MaybeLazy<LinkArgs>,
148+
) -> TargetOptions {
144149
TargetOptions {
145150
abi: abi.target_abi().into(),
146151
os: os.into(),
@@ -151,7 +156,7 @@ pub fn opts(os: &'static str, arch: Arch, abi: TargetAbi) -> TargetOptions {
151156
// macOS has -dead_strip, which doesn't rely on function_sections
152157
function_sections: false,
153158
dynamic_linking: true,
154-
pre_link_args: pre_link_args(os, arch, abi),
159+
pre_link_args,
155160
families: cvs!["unix"],
156161
is_like_osx: true,
157162
// LLVM notes that macOS 10.11+ and iOS 9+ default

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use crate::spec::{Cc, LinkerFlavor, Lld, RelocModel, Target, TargetOptions};
1+
use crate::spec::{Cc, LinkerFlavor, Lld, MaybeLazy, RelocModel, Target, TargetOptions};
22
use object::elf;
33

44
/// A base target for AVR devices using the GNU toolchain.
55
///
66
/// Requires GNU avr-gcc and avr-binutils on the host system.
7-
/// FIXME: Remove the second parameter when const string concatenation is possible.
8-
pub fn target(target_cpu: &'static str, mmcu: &'static str) -> Target {
7+
pub fn target(target_cpu: &'static str) -> Target {
98
Target {
109
arch: "avr".into(),
1110
metadata: crate::spec::TargetMetadata {
@@ -24,11 +23,12 @@ pub fn target(target_cpu: &'static str, mmcu: &'static str) -> Target {
2423

2524
linker: Some("avr-gcc".into()),
2625
eh_frame_header: false,
27-
pre_link_args: TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[mmcu]),
28-
late_link_args: TargetOptions::link_args(
29-
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
30-
&["-lgcc"],
31-
),
26+
pre_link_args: MaybeLazy::lazy(|| {
27+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-mmcu=atmega328"])
28+
}),
29+
late_link_args: MaybeLazy::lazy(|| {
30+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-lgcc"])
31+
}),
3232
max_atomic_width: Some(16),
3333
atomic_cas: false,
3434
relocation_model: RelocModel::Static,

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::{
2-
crt_objects, cvs, Cc, FramePointer, LinkOutputKind, LinkerFlavor, Lld, TargetOptions,
2+
crt_objects, cvs, Cc, FramePointer, LinkOutputKind, LinkerFlavor, Lld, MaybeLazy, TargetOptions,
33
};
44

55
pub fn opts() -> TargetOptions {
@@ -8,22 +8,24 @@ pub fn opts() -> TargetOptions {
88
// so we only list them for ld/lld.
99
//
1010
// https://github.com/llvm/llvm-project/blob/db9322b2066c55254e7691efeab863f43bfcc084/clang/lib/Driver/ToolChains/Fuchsia.cpp#L31
11-
let pre_link_args = TargetOptions::link_args(
12-
LinkerFlavor::Gnu(Cc::No, Lld::No),
13-
&[
14-
"--build-id",
15-
"--hash-style=gnu",
16-
"-z",
17-
"max-page-size=4096",
18-
"-z",
19-
"now",
20-
"-z",
21-
"rodynamic",
22-
"-z",
23-
"separate-loadable-segments",
24-
"--pack-dyn-relocs=relr",
25-
],
26-
);
11+
let pre_link_args = MaybeLazy::lazy(|| {
12+
TargetOptions::link_args(
13+
LinkerFlavor::Gnu(Cc::No, Lld::No),
14+
&[
15+
"--build-id",
16+
"--hash-style=gnu",
17+
"-z",
18+
"max-page-size=4096",
19+
"-z",
20+
"now",
21+
"-z",
22+
"rodynamic",
23+
"-z",
24+
"separate-loadable-segments",
25+
"--pack-dyn-relocs=relr",
26+
],
27+
)
28+
});
2729

2830
TargetOptions {
2931
os: "fuchsia".into(),
@@ -32,12 +34,14 @@ pub fn opts() -> TargetOptions {
3234
dynamic_linking: true,
3335
families: cvs!["unix"],
3436
pre_link_args,
35-
pre_link_objects: crt_objects::new(&[
36-
(LinkOutputKind::DynamicNoPicExe, &["Scrt1.o"]),
37-
(LinkOutputKind::DynamicPicExe, &["Scrt1.o"]),
38-
(LinkOutputKind::StaticNoPicExe, &["Scrt1.o"]),
39-
(LinkOutputKind::StaticPicExe, &["Scrt1.o"]),
40-
]),
37+
pre_link_objects: MaybeLazy::lazy(|| {
38+
crt_objects::new(&[
39+
(LinkOutputKind::DynamicNoPicExe, &["Scrt1.o"]),
40+
(LinkOutputKind::DynamicPicExe, &["Scrt1.o"]),
41+
(LinkOutputKind::StaticNoPicExe, &["Scrt1.o"]),
42+
(LinkOutputKind::StaticPicExe, &["Scrt1.o"]),
43+
])
44+
}),
4145
position_independent_executables: true,
4246
has_thread_local: true,
4347
frame_pointer: FramePointer::NonLeaf,

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
use crate::spec::{cvs, Cc, FramePointer, LinkerFlavor, TargetOptions};
1+
use crate::spec::{cvs, Cc, FramePointer, LinkerFlavor, MaybeLazy, TargetOptions};
22

33
pub fn opts() -> TargetOptions {
4-
let late_link_args = TargetOptions::link_args(
5-
LinkerFlavor::Unix(Cc::Yes),
6-
&[
7-
// The illumos libc contains a stack unwinding implementation, as
8-
// does libgcc_s. The latter implementation includes several
9-
// additional symbols that are not always in base libc. To force
10-
// the consistent use of just one unwinder, we ensure libc appears
11-
// after libgcc_s in the NEEDED list for the resultant binary by
12-
// ignoring any attempts to add it as a dynamic dependency until the
13-
// very end.
14-
// FIXME: This should be replaced by a more complete and generic
15-
// mechanism for controlling the order of library arguments passed
16-
// to the linker.
17-
"-lc",
18-
// LLVM will insert calls to the stack protector functions
19-
// "__stack_chk_fail" and "__stack_chk_guard" into code in native
20-
// object files. Some platforms include these symbols directly in
21-
// libc, but at least historically these have been provided in
22-
// libssp.so on illumos and Solaris systems.
23-
"-lssp",
24-
],
25-
);
4+
let late_link_args = MaybeLazy::lazy(|| {
5+
TargetOptions::link_args(
6+
LinkerFlavor::Unix(Cc::Yes),
7+
&[
8+
// The illumos libc contains a stack unwinding implementation, as
9+
// does libgcc_s. The latter implementation includes several
10+
// additional symbols that are not always in base libc. To force
11+
// the consistent use of just one unwinder, we ensure libc appears
12+
// after libgcc_s in the NEEDED list for the resultant binary by
13+
// ignoring any attempts to add it as a dynamic dependency until the
14+
// very end.
15+
// FIXME: This should be replaced by a more complete and generic
16+
// mechanism for controlling the order of library arguments passed
17+
// to the linker.
18+
"-lc",
19+
// LLVM will insert calls to the stack protector functions
20+
// "__stack_chk_fail" and "__stack_chk_guard" into code in native
21+
// object files. Some platforms include these symbols directly in
22+
// libc, but at least historically these have been provided in
23+
// libssp.so on illumos and Solaris systems.
24+
"-lssp",
25+
],
26+
)
27+
});
2628

2729
TargetOptions {
2830
os: "illumos".into(),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::spec::crt_objects;
2-
use crate::spec::{base, LinkSelfContainedDefault, TargetOptions};
2+
use crate::spec::{base, LinkSelfContainedDefault, MaybeLazy, TargetOptions};
33

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

77
base.env = "musl".into();
8-
base.pre_link_objects_self_contained = crt_objects::pre_musl_self_contained();
9-
base.post_link_objects_self_contained = crt_objects::post_musl_self_contained();
8+
base.pre_link_objects_self_contained = MaybeLazy::lazy(crt_objects::pre_musl_self_contained);
9+
base.post_link_objects_self_contained = MaybeLazy::lazy(crt_objects::post_musl_self_contained);
1010
base.link_self_contained = LinkSelfContainedDefault::InferredForMusl;
1111

1212
// These targets statically link libc by default

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use crate::spec::{DebuginfoKind, LinkerFlavor, Lld, SplitDebuginfo, TargetOptions};
1+
use crate::spec::{DebuginfoKind, LinkerFlavor, Lld, MaybeLazy, SplitDebuginfo, TargetOptions};
22
use std::borrow::Cow;
33

44
pub fn opts() -> TargetOptions {
55
// Suppress the verbose logo and authorship debugging output, which would needlessly
66
// clog any log files.
7-
let pre_link_args = TargetOptions::link_args(LinkerFlavor::Msvc(Lld::No), &["/NOLOGO"]);
7+
let pre_link_args =
8+
MaybeLazy::lazy(|| TargetOptions::link_args(LinkerFlavor::Msvc(Lld::No), &["/NOLOGO"]));
89

910
TargetOptions {
1011
linker_flavor: LinkerFlavor::Msvc(Lld::No),

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
use crate::spec::{add_link_args, Cc, LinkerFlavor, Lld, PanicStrategy, RelroLevel, TargetOptions};
1+
use crate::spec::{
2+
add_link_args, Cc, LinkerFlavor, Lld, MaybeLazy, PanicStrategy, RelroLevel, TargetOptions,
3+
};
24

35
pub fn opts() -> TargetOptions {
4-
let lld_args = &["-zmax-page-size=4096", "-znow", "-ztext", "--execute-only"];
5-
let cc_args = &["-Wl,-zmax-page-size=4096", "-Wl,-znow", "-Wl,-ztext", "-mexecute-only"];
6-
7-
let mut pre_link_args = TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), lld_args);
8-
add_link_args(&mut pre_link_args, LinkerFlavor::Gnu(Cc::Yes, Lld::No), cc_args);
6+
let pre_link_args = MaybeLazy::lazy(|| {
7+
let lld_args = &["-zmax-page-size=4096", "-znow", "-ztext", "--execute-only"];
8+
let cc_args = &["-Wl,-zmax-page-size=4096", "-Wl,-znow", "-Wl,-ztext", "-mexecute-only"];
9+
let mut pre_link_args =
10+
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), lld_args);
11+
add_link_args(&mut pre_link_args, LinkerFlavor::Gnu(Cc::Yes, Lld::No), cc_args);
12+
pre_link_args
13+
});
914

1015
TargetOptions {
1116
os: "teeos".into(),

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,33 @@
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::{base, LinkerFlavor, Lld, MaybeLazy};
13+
use crate::spec::{PanicStrategy, StackProbeType, TargetOptions};
1314

1415
pub fn opts() -> TargetOptions {
1516
let mut base = base::msvc::opts();
1617

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

3740
TargetOptions {
3841
os: "uefi".into(),

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::spec::{
2-
add_link_args, cvs, Cc, LinkSelfContainedDefault, LinkerFlavor, PanicStrategy, RelocModel,
3-
TargetOptions, TlsModel,
2+
add_link_args, cvs, Cc, LinkSelfContainedDefault, LinkerFlavor, MaybeLazy, PanicStrategy,
3+
RelocModel, TargetOptions, TlsModel,
44
};
55

66
pub fn options() -> TargetOptions {
@@ -48,8 +48,11 @@ pub fn options() -> TargetOptions {
4848
};
4949
}
5050

51-
let mut pre_link_args = TargetOptions::link_args(LinkerFlavor::WasmLld(Cc::No), args!(""));
52-
add_link_args(&mut pre_link_args, LinkerFlavor::WasmLld(Cc::Yes), args!("-Wl,"));
51+
let pre_link_args = MaybeLazy::lazy(|| {
52+
let mut pre_link_args = TargetOptions::link_args(LinkerFlavor::WasmLld(Cc::No), args!(""));
53+
add_link_args(&mut pre_link_args, LinkerFlavor::WasmLld(Cc::Yes), args!("-Wl,"));
54+
pre_link_args
55+
});
5356

5457
TargetOptions {
5558
is_like_wasm: true,

0 commit comments

Comments
 (0)