Skip to content

Commit 364f36d

Browse files
committed
Generic linker flavors
1 parent 9b9bee4 commit 364f36d

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

compiler/rustc_target/src/spec/mod.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ pub enum LinkerFlavorCli {
144144
Bpf,
145145
Ptx,
146146

147+
// Generic (unstable) flavors.
148+
Any(Cc, Lld),
149+
147150
// Legacy stable values
148151
Gcc,
149152
Ld,
@@ -162,7 +165,8 @@ impl LinkerFlavorCli {
162165
| LinkerFlavorCli::Msvc(Lld::Yes)
163166
| LinkerFlavorCli::EmCc
164167
| LinkerFlavorCli::Bpf
165-
| LinkerFlavorCli::Ptx => true,
168+
| LinkerFlavorCli::Ptx
169+
| LinkerFlavorCli::Any(..) => true,
166170
LinkerFlavorCli::Gcc
167171
| LinkerFlavorCli::Ld
168172
| LinkerFlavorCli::Lld(..)
@@ -223,6 +227,15 @@ impl LinkerFlavor {
223227
LinkerFlavorCli::Bpf => LinkerFlavor::Bpf,
224228
LinkerFlavorCli::Ptx => LinkerFlavor::Ptx,
225229

230+
// Generic flavors
231+
LinkerFlavorCli::Any(cc, lld) => match lld_flavor {
232+
LldFlavor::Ld if is_gnu => LinkerFlavor::Gnu(cc, lld),
233+
LldFlavor::Ld64 => LinkerFlavor::Darwin(cc, lld),
234+
LldFlavor::Wasm => LinkerFlavor::WasmLld(cc),
235+
LldFlavor::Ld => LinkerFlavor::Unix(cc),
236+
LldFlavor::Link => LinkerFlavor::Msvc(lld),
237+
},
238+
226239
// Below: legacy stable values
227240
LinkerFlavorCli::Gcc => match lld_flavor {
228241
LldFlavor::Ld if is_gnu => LinkerFlavor::Gnu(Cc::Yes, Lld::No),
@@ -289,6 +302,9 @@ impl LinkerFlavor {
289302
LinkerFlavorCli::EmCc => (Some(Cc::Yes), Some(Lld::Yes)),
290303
LinkerFlavorCli::Bpf | LinkerFlavorCli::Ptx => (None, None),
291304

305+
// Generic flavors
306+
LinkerFlavorCli::Any(cc, lld) => (Some(cc), Some(lld)),
307+
292308
// Below: legacy stable values
293309
LinkerFlavorCli::Gcc => (Some(Cc::Yes), None),
294310
LinkerFlavorCli::Ld => (Some(Cc::No), Some(Lld::No)),
@@ -503,6 +519,14 @@ linker_flavor_cli_impls! {
503519
(LinkerFlavorCli::Bpf) "bpf"
504520
(LinkerFlavorCli::Ptx) "ptx"
505521

522+
// Generic flavors
523+
(LinkerFlavorCli::Any(Cc::No, Lld::No)) "*"
524+
(LinkerFlavorCli::Any(Cc::No, Lld::Yes)) "*-lld"
525+
(LinkerFlavorCli::Any(Cc::Yes, Lld::No)) "*-cc"
526+
(LinkerFlavorCli::Any(Cc::Yes, Lld::Yes)) "*-lld-cc"
527+
(LinkerFlavorCli::Any(Cc::Clang, Lld::No)) "*-clang"
528+
(LinkerFlavorCli::Any(Cc::Clang, Lld::Yes)) "*-lld-clang"
529+
506530
// Legacy stable flavors
507531
(LinkerFlavorCli::Gcc) "gcc"
508532
(LinkerFlavorCli::Ld) "ld"

tests/run-make/rust-lld/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ include ../tools.mk
44
# needs-rust-lld
55
# ignore-s390x lld does not yet support s390x as target
66
all:
7-
RUSTC_LOG=rustc_codegen_ssa::back::link=info $(RUSTC) -Clink-self-contained=+linker -Clinker-flavor=gnu-lld-cc -Zunstable-options -Clink-args=-Wl,-v main.rs 2> $(TMPDIR)/output.txt
7+
RUSTC_LOG=rustc_codegen_ssa::back::link=info $(RUSTC) -Clink-self-contained=+linker -Clinker-flavor=*-lld-cc -Zunstable-options -Clink-args=-Wl,-v main.rs 2> $(TMPDIR)/output.txt
88
$(CGREP) -e "^LLD [0-9]+\.[0-9]+\.[0-9]+" < $(TMPDIR)/output.txt

0 commit comments

Comments
 (0)