Skip to content
forked from rust-lang/rust
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8d00669

Browse files
committedAug 7, 2024
Auto merge of rust-lang#128783 - GuillaumeGomez:rollup-2kvpg7s, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - rust-lang#128206 (Make create_dll_import_lib easier to implement) - rust-lang#128424 (minor `effects` cleanups) - rust-lang#128527 (More information for fully-qualified suggestion when there are multiple impls) - rust-lang#128656 (Enable msvc for run-make/rust-lld) - rust-lang#128683 (bootstrap: clear miri's ui test deps when rustc changes) - rust-lang#128700 (Migrate `simd-ffi` `run-make` test to rmake) - rust-lang#128753 (Don't arbitrarily choose one upper bound for hidden captured region error message) - rust-lang#128757 (Migrate `pgo-gen-lto` `run-make` test to rmake) - rust-lang#128758 (Specify a minimum supported version for VxWorks) Failed merges: - rust-lang#128679 (codegen: better centralize function declaration attribute computation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9bad7ba + 920cb64 commit 8d00669

File tree

34 files changed

+566
-473
lines changed

34 files changed

+566
-473
lines changed
 

‎Cargo.lock

+3-12
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ dependencies = [
205205

206206
[[package]]
207207
name = "ar_archive_writer"
208-
version = "0.3.0"
208+
version = "0.3.3"
209209
source = "registry+https://github.com/rust-lang/crates.io-index"
210-
checksum = "f8412a2d690663356cba5a2532f3ed55d1e8090743bc6695b88403b27df67733"
210+
checksum = "3f2bcb7cf51decfbbfc7ef476e28b0775b13e5eb1190f8b7df145cd53d4f4374"
211211
dependencies = [
212-
"object 0.35.0",
212+
"object 0.36.2",
213213
]
214214

215215
[[package]]
@@ -2454,15 +2454,6 @@ dependencies = [
24542454
"ruzstd 0.5.0",
24552455
]
24562456

2457-
[[package]]
2458-
name = "object"
2459-
version = "0.35.0"
2460-
source = "registry+https://github.com/rust-lang/crates.io-index"
2461-
checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e"
2462-
dependencies = [
2463-
"memchr",
2464-
]
2465-
24662457
[[package]]
24672458
name = "object"
24682459
version = "0.36.2"

‎compiler/rustc_ast_lowering/src/item.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
16681668
}),
16691669
)),
16701670
)),
1671-
// FIXME(effects) we might not need a default.
16721671
default: Some(default_ct),
16731672
is_host_effect: true,
16741673
synthetic: true,

‎compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,26 @@ impl<'tcx> RegionInferenceContext<'tcx> {
225225

226226
// Find something that we can name
227227
let upper_bound = self.approx_universal_upper_bound(vid);
228-
let upper_bound = &self.definitions[upper_bound];
229-
match upper_bound.external_name {
230-
Some(reg) => reg,
231-
None => {
232-
// Nothing exact found, so we pick the first one that we find.
233-
let scc = self.constraint_sccs.scc(vid);
234-
for vid in self.rev_scc_graph.as_ref().unwrap().upper_bounds(scc) {
235-
match self.definitions[vid].external_name {
236-
None => {}
237-
Some(region) if region.is_static() => {}
238-
Some(region) => return region,
239-
}
240-
}
241-
region
242-
}
228+
if let Some(universal_region) = self.definitions[upper_bound].external_name {
229+
return universal_region;
230+
}
231+
232+
// Nothing exact found, so we pick a named upper bound, if there's only one.
233+
// If there's >1 universal region, then we probably are dealing w/ an intersection
234+
// region which cannot be mapped back to a universal.
235+
// FIXME: We could probably compute the LUB if there is one.
236+
let scc = self.constraint_sccs.scc(vid);
237+
let upper_bounds: Vec<_> = self
238+
.rev_scc_graph
239+
.as_ref()
240+
.unwrap()
241+
.upper_bounds(scc)
242+
.filter_map(|vid| self.definitions[vid].external_name)
243+
.filter(|r| !r.is_static())
244+
.collect();
245+
match &upper_bounds[..] {
246+
[universal_region] => *universal_region,
247+
_ => region,
243248
}
244249
}
245250
_ => region,

‎compiler/rustc_codegen_cranelift/src/archive.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::{Path, PathBuf};
1+
use std::path::Path;
22

33
use rustc_codegen_ssa::back::archive::{
44
ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
@@ -16,10 +16,9 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
1616
&self,
1717
sess: &Session,
1818
_lib_name: &str,
19-
_dll_imports: &[rustc_session::cstore::DllImport],
20-
_tmpdir: &Path,
21-
_is_direct_dependency: bool,
22-
) -> PathBuf {
19+
_import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
20+
_output_path: &Path,
21+
) {
2322
sess.dcx().fatal("raw-dylib is not yet supported by rustc_codegen_cranelift");
2423
}
2524
}
+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use std::path::{Path, PathBuf};
1+
use std::path::Path;
22

33
use rustc_codegen_ssa::back::archive::{
44
ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
55
};
6-
use rustc_session::cstore::DllImport;
76
use rustc_session::Session;
87

98
pub(crate) struct ArArchiveBuilderBuilder;
@@ -17,10 +16,9 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
1716
&self,
1817
_sess: &Session,
1918
_lib_name: &str,
20-
_dll_imports: &[DllImport],
21-
_tmpdir: &Path,
22-
_is_direct_dependency: bool,
23-
) -> PathBuf {
19+
_import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
20+
_output_path: &Path,
21+
) {
2422
unimplemented!("creating dll imports is not yet supported");
2523
}
2624
}

‎compiler/rustc_codegen_llvm/messages.ftl

-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
codegen_llvm_copy_bitcode = failed to copy bitcode to object file: {$err}
22
3-
codegen_llvm_dlltool_fail_import_library =
4-
Dlltool could not create import library with {$dlltool_path} {$dlltool_args}:
5-
{$stdout}
6-
{$stderr}
7-
83
codegen_llvm_dynamic_linking_with_lto =
94
cannot prefer dynamic linking when performing LTO
105
.note = only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO
116
12-
codegen_llvm_error_calling_dlltool =
13-
Error calling dlltool '{$dlltool_path}': {$error}
147
158
codegen_llvm_error_creating_import_library =
169
Error creating import library for {$lib_name}: {$error}
1710
18-
codegen_llvm_error_writing_def_file =
19-
Error writing .DEF file: {$error}
20-
2111
codegen_llvm_fixed_x18_invalid_arch = the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture
2212
2313
codegen_llvm_from_llvm_diag = {$message}

‎compiler/rustc_codegen_llvm/src/back/archive.rs

+19-154
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
//! A helper class for dealing with static archives
22
3-
use std::ffi::{c_char, c_void, CStr, CString, OsString};
3+
use std::ffi::{c_char, c_void, CStr, CString};
44
use std::path::{Path, PathBuf};
5-
use std::{env, io, mem, ptr, str};
5+
use std::{io, mem, ptr, str};
66

77
use rustc_codegen_ssa::back::archive::{
8-
try_extract_macho_fat_archive, ArArchiveBuilder, ArchiveBuildFailure, ArchiveBuilder,
9-
ArchiveBuilderBuilder, ObjectReader, UnknownArchiveKind, DEFAULT_OBJECT_READER,
8+
create_mingw_dll_import_lib, try_extract_macho_fat_archive, ArArchiveBuilder,
9+
ArchiveBuildFailure, ArchiveBuilder, ArchiveBuilderBuilder, ObjectReader, UnknownArchiveKind,
10+
DEFAULT_OBJECT_READER,
1011
};
11-
use rustc_session::cstore::DllImport;
12+
use rustc_codegen_ssa::common;
1213
use rustc_session::Session;
1314
use tracing::trace;
1415

15-
use crate::common;
16-
use crate::errors::{
17-
DlltoolFailImportLibrary, ErrorCallingDllTool, ErrorCreatingImportLibrary, ErrorWritingDEFFile,
18-
};
16+
use crate::errors::ErrorCreatingImportLibrary;
1917
use crate::llvm::archive_ro::{ArchiveRO, Child};
2018
use crate::llvm::{self, ArchiveKind, LLVMMachineType, LLVMRustCOFFShortExport};
2119

@@ -121,116 +119,21 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
121119
&self,
122120
sess: &Session,
123121
lib_name: &str,
124-
dll_imports: &[DllImport],
125-
tmpdir: &Path,
126-
is_direct_dependency: bool,
127-
) -> PathBuf {
128-
let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
129-
let output_path = tmpdir.join(format!("{lib_name}{name_suffix}.lib"));
130-
131-
let target = &sess.target;
132-
let mingw_gnu_toolchain = common::is_mingw_gnu_toolchain(target);
133-
134-
let import_name_and_ordinal_vector: Vec<(String, Option<u16>)> = dll_imports
135-
.iter()
136-
.map(|import: &DllImport| {
137-
if sess.target.arch == "x86" {
138-
(
139-
common::i686_decorated_name(import, mingw_gnu_toolchain, false),
140-
import.ordinal(),
141-
)
142-
} else {
143-
(import.name.to_string(), import.ordinal())
144-
}
145-
})
146-
.collect();
147-
148-
if mingw_gnu_toolchain {
122+
import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
123+
output_path: &Path,
124+
) {
125+
if common::is_mingw_gnu_toolchain(&sess.target) {
149126
// The binutils linker used on -windows-gnu targets cannot read the import
150127
// libraries generated by LLVM: in our attempts, the linker produced an .EXE
151128
// that loaded but crashed with an AV upon calling one of the imported
152129
// functions. Therefore, use binutils to create the import library instead,
153130
// by writing a .DEF file to the temp dir and calling binutils's dlltool.
154-
let def_file_path = tmpdir.join(format!("{lib_name}{name_suffix}.def"));
155-
156-
let def_file_content = format!(
157-
"EXPORTS\n{}",
158-
import_name_and_ordinal_vector
159-
.into_iter()
160-
.map(|(name, ordinal)| {
161-
match ordinal {
162-
Some(n) => format!("{name} @{n} NONAME"),
163-
None => name,
164-
}
165-
})
166-
.collect::<Vec<String>>()
167-
.join("\n")
131+
create_mingw_dll_import_lib(
132+
sess,
133+
lib_name,
134+
import_name_and_ordinal_vector,
135+
output_path,
168136
);
169-
170-
match std::fs::write(&def_file_path, def_file_content) {
171-
Ok(_) => {}
172-
Err(e) => {
173-
sess.dcx().emit_fatal(ErrorWritingDEFFile { error: e });
174-
}
175-
};
176-
177-
// --no-leading-underscore: For the `import_name_type` feature to work, we need to be
178-
// able to control the *exact* spelling of each of the symbols that are being imported:
179-
// hence we don't want `dlltool` adding leading underscores automatically.
180-
let dlltool = find_binutils_dlltool(sess);
181-
let temp_prefix = {
182-
let mut path = PathBuf::from(&output_path);
183-
path.pop();
184-
path.push(lib_name);
185-
path
186-
};
187-
// dlltool target architecture args from:
188-
// https://github.com/llvm/llvm-project-release-prs/blob/llvmorg-15.0.6/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp#L69
189-
let (dlltool_target_arch, dlltool_target_bitness) = match sess.target.arch.as_ref() {
190-
"x86_64" => ("i386:x86-64", "--64"),
191-
"x86" => ("i386", "--32"),
192-
"aarch64" => ("arm64", "--64"),
193-
"arm" => ("arm", "--32"),
194-
_ => panic!("unsupported arch {}", sess.target.arch),
195-
};
196-
let mut dlltool_cmd = std::process::Command::new(&dlltool);
197-
dlltool_cmd
198-
.arg("-d")
199-
.arg(def_file_path)
200-
.arg("-D")
201-
.arg(lib_name)
202-
.arg("-l")
203-
.arg(&output_path)
204-
.arg("-m")
205-
.arg(dlltool_target_arch)
206-
.arg("-f")
207-
.arg(dlltool_target_bitness)
208-
.arg("--no-leading-underscore")
209-
.arg("--temp-prefix")
210-
.arg(temp_prefix);
211-
212-
match dlltool_cmd.output() {
213-
Err(e) => {
214-
sess.dcx().emit_fatal(ErrorCallingDllTool {
215-
dlltool_path: dlltool.to_string_lossy(),
216-
error: e,
217-
});
218-
}
219-
// dlltool returns '0' on failure, so check for error output instead.
220-
Ok(output) if !output.stderr.is_empty() => {
221-
sess.dcx().emit_fatal(DlltoolFailImportLibrary {
222-
dlltool_path: dlltool.to_string_lossy(),
223-
dlltool_args: dlltool_cmd
224-
.get_args()
225-
.map(|arg| arg.to_string_lossy())
226-
.collect::<Vec<_>>()
227-
.join(" "),
228-
stdout: String::from_utf8_lossy(&output.stdout),
229-
stderr: String::from_utf8_lossy(&output.stderr),
230-
})
231-
}
232-
_ => {}
233-
}
234137
} else {
235138
// we've checked for \0 characters in the library name already
236139
let dll_name_z = CString::new(lib_name).unwrap();
@@ -242,9 +145,9 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
242145
trace!(" output_path {}", output_path.display());
243146
trace!(
244147
" import names: {}",
245-
dll_imports
148+
import_name_and_ordinal_vector
246149
.iter()
247-
.map(|import| import.name.to_string())
150+
.map(|(name, _ordinal)| name.clone())
248151
.collect::<Vec<_>>()
249152
.join(", "),
250153
);
@@ -281,9 +184,7 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
281184
error: llvm::last_error().unwrap_or("unknown LLVM error".to_string()),
282185
});
283186
}
284-
};
285-
286-
output_path
187+
}
287188
}
288189
}
289190

@@ -457,39 +358,3 @@ impl<'a> LlvmArchiveBuilder<'a> {
457358
fn string_to_io_error(s: String) -> io::Error {
458359
io::Error::new(io::ErrorKind::Other, format!("bad archive: {s}"))
459360
}
460-
461-
fn find_binutils_dlltool(sess: &Session) -> OsString {
462-
assert!(sess.target.options.is_like_windows && !sess.target.options.is_like_msvc);
463-
if let Some(dlltool_path) = &sess.opts.cg.dlltool {
464-
return dlltool_path.clone().into_os_string();
465-
}
466-
467-
let tool_name: OsString = if sess.host.options.is_like_windows {
468-
// If we're compiling on Windows, always use "dlltool.exe".
469-
"dlltool.exe"
470-
} else {
471-
// On other platforms, use the architecture-specific name.
472-
match sess.target.arch.as_ref() {
473-
"x86_64" => "x86_64-w64-mingw32-dlltool",
474-
"x86" => "i686-w64-mingw32-dlltool",
475-
"aarch64" => "aarch64-w64-mingw32-dlltool",
476-
477-
// For non-standard architectures (e.g., aarch32) fallback to "dlltool".
478-
_ => "dlltool",
479-
}
480-
}
481-
.into();
482-
483-
// NOTE: it's not clear how useful it is to explicitly search PATH.
484-
for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
485-
let full_path = dir.join(&tool_name);
486-
if full_path.is_file() {
487-
return full_path.into_os_string();
488-
}
489-
}
490-
491-
// The user didn't specify the location of the dlltool binary, and we weren't able
492-
// to find the appropriate one on the PATH. Just return the name of the tool
493-
// and let the invocation fail with a hopefully useful error message.
494-
tool_name
495-
}

‎compiler/rustc_codegen_llvm/src/callee.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
//! and methods are represented as just a fn ptr and not a full
55
//! closure.
66
7+
use rustc_codegen_ssa::common;
78
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt};
89
use rustc_middle::ty::{self, Instance, TypeVisitableExt};
910
use tracing::debug;
1011

1112
use crate::context::CodegenCx;
1213
use crate::value::Value;
13-
use crate::{attributes, common, llvm};
14+
use crate::{attributes, llvm};
1415

1516
/// Codegens a reference to a fn/method item, monomorphizing and
1617
/// inlining as it goes.
@@ -46,7 +47,7 @@ pub fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) ->
4647
} else {
4748
let instance_def_id = instance.def_id();
4849
let llfn = if tcx.sess.target.arch == "x86"
49-
&& let Some(dllimport) = common::get_dllimport(tcx, instance_def_id, sym)
50+
&& let Some(dllimport) = crate::common::get_dllimport(tcx, instance_def_id, sym)
5051
{
5152
// Fix for https://github.com/rust-lang/rust/issues/104453
5253
// On x86 Windows, LLVM uses 'L' as the prefix for any private
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.