Skip to content

Commit c628985

Browse files
committed
Move computation of decorated names out of the create_dll_import_lib method
1 parent 16b1b60 commit c628985

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

compiler/rustc_codegen_cranelift/src/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
1616
&self,
1717
sess: &Session,
1818
_lib_name: &str,
19-
_dll_imports: &[rustc_session::cstore::DllImport],
19+
_import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
2020
_output_path: &Path,
2121
) {
2222
sess.dcx().fatal("raw-dylib is not yet supported by rustc_codegen_cranelift");

compiler/rustc_codegen_gcc/src/archive.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use rustc_codegen_ssa::back::archive::{
55
};
66
use rustc_session::Session;
77

8-
use rustc_session::cstore::DllImport;
9-
108
pub(crate) struct ArArchiveBuilderBuilder;
119

1210
impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
@@ -18,7 +16,7 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
1816
&self,
1917
_sess: &Session,
2018
_lib_name: &str,
21-
_dll_imports: &[DllImport],
19+
_import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
2220
_output_path: &Path,
2321
) {
2422
unimplemented!("creating dll imports is not yet supported");

compiler/rustc_codegen_llvm/src/back/archive.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_codegen_ssa::back::archive::{
2020
use rustc_codegen_ssa::common;
2121
use tracing::trace;
2222

23-
use rustc_session::cstore::DllImport;
2423
use rustc_session::Session;
2524

2625
/// Helper for adding many files to an archive.
@@ -123,26 +122,12 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
123122
&self,
124123
sess: &Session,
125124
lib_name: &str,
126-
dll_imports: &[DllImport],
125+
import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
127126
output_path: &Path,
128127
) {
129128
let target = &sess.target;
130129
let mingw_gnu_toolchain = common::is_mingw_gnu_toolchain(target);
131130

132-
let import_name_and_ordinal_vector: Vec<(String, Option<u16>)> = dll_imports
133-
.iter()
134-
.map(|import: &DllImport| {
135-
if sess.target.arch == "x86" {
136-
(
137-
common::i686_decorated_name(import, mingw_gnu_toolchain, false),
138-
import.ordinal(),
139-
)
140-
} else {
141-
(import.name.to_string(), import.ordinal())
142-
}
143-
})
144-
.collect();
145-
146131
if mingw_gnu_toolchain {
147132
// The binutils linker used on -windows-gnu targets cannot read the import
148133
// libraries generated by LLVM: in our attempts, the linker produced an .EXE
@@ -240,9 +225,9 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
240225
trace!(" output_path {}", output_path.display());
241226
trace!(
242227
" import names: {}",
243-
dll_imports
228+
import_name_and_ordinal_vector
244229
.iter()
245-
.map(|import| import.name.to_string())
230+
.map(|(name, _ordinal)| name.clone())
246231
.collect::<Vec<_>>()
247232
.join(", "),
248233
);

compiler/rustc_codegen_ssa/src/back/archive.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_data_structures::fx::FxIndexSet;
22
use rustc_data_structures::memmap::Mmap;
3-
use rustc_session::cstore::DllImport;
43
use rustc_session::Session;
54
use rustc_span::symbol::Symbol;
65

@@ -32,7 +31,7 @@ pub trait ArchiveBuilderBuilder {
3231
&self,
3332
sess: &Session,
3433
lib_name: &str,
35-
dll_imports: &[DllImport],
34+
import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
3635
output_path: &Path,
3736
);
3837

compiler/rustc_codegen_ssa/src/back/link.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ use super::linker::{self, Linker};
3636
use super::metadata::{create_wrapper_file, MetadataPosition};
3737
use super::rpath::{self, RPathConfig};
3838
use crate::{
39-
errors, looks_like_rust_object_file, CodegenResults, CompiledModule, CrateInfo, NativeLib,
39+
common, errors, looks_like_rust_object_file, CodegenResults, CompiledModule, CrateInfo,
40+
NativeLib,
4041
};
4142

4243
use cc::windows_registry;
@@ -497,10 +498,26 @@ fn create_dll_import_libs<'a>(
497498
let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
498499
let output_path = tmpdir.join(format!("{raw_dylib_name}{name_suffix}.lib"));
499500

501+
let mingw_gnu_toolchain = common::is_mingw_gnu_toolchain(&sess.target);
502+
503+
let import_name_and_ordinal_vector: Vec<(String, Option<u16>)> = raw_dylib_imports
504+
.iter()
505+
.map(|import: &DllImport| {
506+
if sess.target.arch == "x86" {
507+
(
508+
common::i686_decorated_name(import, mingw_gnu_toolchain, false),
509+
import.ordinal(),
510+
)
511+
} else {
512+
(import.name.to_string(), import.ordinal())
513+
}
514+
})
515+
.collect();
516+
500517
archive_builder_builder.create_dll_import_lib(
501518
sess,
502519
&raw_dylib_name,
503-
&raw_dylib_imports,
520+
import_name_and_ordinal_vector,
504521
&output_path,
505522
);
506523

0 commit comments

Comments
 (0)