Skip to content

Commit dee7c7b

Browse files
committed
Sync from rust a50d721
2 parents bc9926a + 8224e72 commit dee7c7b

File tree

4 files changed

+16
-115
lines changed

4 files changed

+16
-115
lines changed

src/archive.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
254254
}
255255
}
256256
}
257+
258+
fn inject_dll_import_lib(
259+
&mut self,
260+
_lib_name: &str,
261+
_dll_imports: &[rustc_middle::middle::cstore::DllImport],
262+
_tmpdir: &rustc_data_structures::temp_dir::MaybeTempDir,
263+
) {
264+
bug!("injecting dll imports is not supported");
265+
}
257266
}
258267

259268
impl<'a> ArArchiveBuilder<'a> {

src/driver/aot.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,6 @@ pub(crate) fn run_aot(
177177
metadata: EncodedMetadata,
178178
need_metadata_module: bool,
179179
) -> Box<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>)> {
180-
use rustc_span::symbol::sym;
181-
182-
let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
183-
let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem);
184-
let windows_subsystem = subsystem.map(|subsystem| {
185-
if subsystem != sym::windows && subsystem != sym::console {
186-
tcx.sess.fatal(&format!(
187-
"invalid windows subsystem `{}`, only \
188-
`windows` and `console` are allowed",
189-
subsystem
190-
));
191-
}
192-
subsystem.to_string()
193-
});
194-
195180
let mut work_products = FxHashMap::default();
196181

197182
let cgus = if tcx.sess.opts.output_types.should_codegen() {
@@ -307,12 +292,10 @@ pub(crate) fn run_aot(
307292

308293
Box::new((
309294
CodegenResults {
310-
crate_name: tcx.crate_name(LOCAL_CRATE),
311295
modules,
312296
allocator_module,
313297
metadata_module,
314298
metadata,
315-
windows_subsystem,
316299
linker_info: LinkerInfo::new(tcx, crate::target_triple(tcx.sess).to_string()),
317300
crate_info: CrateInfo::new(tcx),
318301
},

src/lib.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ use rustc_codegen_ssa::traits::CodegenBackend;
2828
use rustc_codegen_ssa::CodegenResults;
2929
use rustc_errors::ErrorReported;
3030
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
31-
use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader};
32-
use rustc_middle::ty::query::Providers;
31+
use rustc_middle::middle::cstore::EncodedMetadata;
3332
use rustc_session::config::OutputFilenames;
3433
use rustc_session::Session;
3534

@@ -164,17 +163,14 @@ impl CodegenBackend for CraneliftCodegenBackend {
164163
}
165164
}
166165

167-
fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync> {
168-
Box::new(rustc_codegen_ssa::back::metadata::DefaultMetadataLoader)
169-
}
170-
171-
fn provide(&self, _providers: &mut Providers) {}
172-
fn provide_extern(&self, _providers: &mut Providers) {}
173-
174166
fn target_features(&self, _sess: &Session) -> Vec<rustc_span::Symbol> {
175167
vec![]
176168
}
177169

170+
fn print_version(&self) {
171+
println!("Cranelift version: {}", cranelift_codegen::VERSION);
172+
}
173+
178174
fn codegen_crate(
179175
&self,
180176
tcx: TyCtxt<'_>,
@@ -222,7 +218,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
222218
sess,
223219
&codegen_results,
224220
outputs,
225-
&codegen_results.crate_name.as_str(),
221+
&codegen_results.crate_info.local_crate_name.as_str(),
226222
);
227223

228224
Ok(())

src/toolchain.rs

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
33
use std::path::PathBuf;
44

5-
use rustc_middle::bug;
5+
use rustc_codegen_ssa::back::link::linker_and_flavor;
66
use rustc_session::Session;
7-
use rustc_target::spec::LinkerFlavor;
87

98
/// Tries to infer the path of a binary for the target toolchain from the linker name.
109
pub(crate) fn get_toolchain_binary(sess: &Session, tool: &str) -> PathBuf {
@@ -30,89 +29,3 @@ pub(crate) fn get_toolchain_binary(sess: &Session, tool: &str) -> PathBuf {
3029

3130
linker
3231
}
33-
34-
// Adapted from https://github.com/rust-lang/rust/blob/5db778affee7c6600c8e7a177c48282dab3f6292/src/librustc_codegen_ssa/back/link.rs#L848-L931
35-
fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
36-
fn infer_from(
37-
sess: &Session,
38-
linker: Option<PathBuf>,
39-
flavor: Option<LinkerFlavor>,
40-
) -> Option<(PathBuf, LinkerFlavor)> {
41-
match (linker, flavor) {
42-
(Some(linker), Some(flavor)) => Some((linker, flavor)),
43-
// only the linker flavor is known; use the default linker for the selected flavor
44-
(None, Some(flavor)) => Some((
45-
PathBuf::from(match flavor {
46-
LinkerFlavor::Em => {
47-
if cfg!(windows) {
48-
"emcc.bat"
49-
} else {
50-
"emcc"
51-
}
52-
}
53-
LinkerFlavor::Gcc => {
54-
if cfg!(any(target_os = "solaris", target_os = "illumos")) {
55-
// On historical Solaris systems, "cc" may have
56-
// been Sun Studio, which is not flag-compatible
57-
// with "gcc". This history casts a long shadow,
58-
// and many modern illumos distributions today
59-
// ship GCC as "gcc" without also making it
60-
// available as "cc".
61-
"gcc"
62-
} else {
63-
"cc"
64-
}
65-
}
66-
LinkerFlavor::Ld => "ld",
67-
LinkerFlavor::Msvc => "link.exe",
68-
LinkerFlavor::Lld(_) => "lld",
69-
LinkerFlavor::PtxLinker => "rust-ptx-linker",
70-
}),
71-
flavor,
72-
)),
73-
(Some(linker), None) => {
74-
let stem = linker.file_stem().and_then(|stem| stem.to_str()).unwrap_or_else(|| {
75-
sess.fatal("couldn't extract file stem from specified linker")
76-
});
77-
78-
let flavor = if stem == "emcc" {
79-
LinkerFlavor::Em
80-
} else if stem == "gcc"
81-
|| stem.ends_with("-gcc")
82-
|| stem == "clang"
83-
|| stem.ends_with("-clang")
84-
{
85-
LinkerFlavor::Gcc
86-
} else if stem == "ld" || stem == "ld.lld" || stem.ends_with("-ld") {
87-
LinkerFlavor::Ld
88-
} else if stem == "link" || stem == "lld-link" {
89-
LinkerFlavor::Msvc
90-
} else if stem == "lld" || stem == "rust-lld" {
91-
LinkerFlavor::Lld(sess.target.lld_flavor)
92-
} else {
93-
// fall back to the value in the target spec
94-
sess.target.linker_flavor
95-
};
96-
97-
Some((linker, flavor))
98-
}
99-
(None, None) => None,
100-
}
101-
}
102-
103-
// linker and linker flavor specified via command line have precedence over what the target
104-
// specification specifies
105-
if let Some(ret) = infer_from(sess, sess.opts.cg.linker.clone(), sess.opts.cg.linker_flavor) {
106-
return ret;
107-
}
108-
109-
if let Some(ret) = infer_from(
110-
sess,
111-
sess.target.linker.clone().map(PathBuf::from),
112-
Some(sess.target.linker_flavor),
113-
) {
114-
return ret;
115-
}
116-
117-
bug!("Not enough information provided to determine how to invoke the linker");
118-
}

0 commit comments

Comments
 (0)