@@ -5,17 +5,13 @@ use std::path::{Path, PathBuf};
55use std:: { io, mem, ptr, str} ;
66
77use rustc_codegen_ssa:: back:: archive:: {
8- create_mingw_dll_import_lib, try_extract_macho_fat_archive, ArArchiveBuilder ,
9- ArchiveBuildFailure , ArchiveBuilder , ArchiveBuilderBuilder , ObjectReader , UnknownArchiveKind ,
10- DEFAULT_OBJECT_READER ,
8+ try_extract_macho_fat_archive, ArArchiveBuilder , ArchiveBuildFailure , ArchiveBuilder ,
9+ ArchiveBuilderBuilder , ObjectReader , UnknownArchiveKind , DEFAULT_OBJECT_READER ,
1110} ;
12- use rustc_codegen_ssa:: common;
1311use rustc_session:: Session ;
14- use tracing:: trace;
1512
16- use crate :: errors:: ErrorCreatingImportLibrary ;
1713use crate :: llvm:: archive_ro:: { ArchiveRO , Child } ;
18- use crate :: llvm:: { self , ArchiveKind , LLVMMachineType , LLVMRustCOFFShortExport } ;
14+ use crate :: llvm:: { self , ArchiveKind } ;
1915
2016/// Helper for adding many files to an archive.
2117#[ must_use = "must call build() to finish building the archive" ]
@@ -44,18 +40,6 @@ fn is_relevant_child(c: &Child<'_>) -> bool {
4440 }
4541}
4642
47- /// Map machine type strings to values of LLVM's MachineTypes enum.
48- fn llvm_machine_type ( cpu : & str ) -> LLVMMachineType {
49- match cpu {
50- "x86_64" => LLVMMachineType :: AMD64 ,
51- "x86" => LLVMMachineType :: I386 ,
52- "aarch64" => LLVMMachineType :: ARM64 ,
53- "arm64ec" => LLVMMachineType :: ARM64EC ,
54- "arm" => LLVMMachineType :: ARM ,
55- _ => panic ! ( "unsupported cpu type {cpu}" ) ,
56- }
57- }
58-
5943impl < ' a > ArchiveBuilder for LlvmArchiveBuilder < ' a > {
6044 fn add_archive (
6145 & mut self ,
@@ -116,78 +100,6 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
116100 Box :: new ( ArArchiveBuilder :: new ( sess, & LLVM_OBJECT_READER ) )
117101 }
118102 }
119-
120- fn create_dll_import_lib (
121- & self ,
122- sess : & Session ,
123- lib_name : & str ,
124- import_name_and_ordinal_vector : Vec < ( String , Option < u16 > ) > ,
125- output_path : & Path ,
126- ) {
127- if common:: is_mingw_gnu_toolchain ( & sess. target ) {
128- // The binutils linker used on -windows-gnu targets cannot read the import
129- // libraries generated by LLVM: in our attempts, the linker produced an .EXE
130- // that loaded but crashed with an AV upon calling one of the imported
131- // functions. Therefore, use binutils to create the import library instead,
132- // by writing a .DEF file to the temp dir and calling binutils's dlltool.
133- create_mingw_dll_import_lib (
134- sess,
135- lib_name,
136- import_name_and_ordinal_vector,
137- output_path,
138- ) ;
139- } else {
140- // we've checked for \0 characters in the library name already
141- let dll_name_z = CString :: new ( lib_name) . unwrap ( ) ;
142-
143- let output_path_z = rustc_fs_util:: path_to_c_string ( & output_path) ;
144-
145- trace ! ( "invoking LLVMRustWriteImportLibrary" ) ;
146- trace ! ( " dll_name {:#?}" , dll_name_z) ;
147- trace ! ( " output_path {}" , output_path. display( ) ) ;
148- trace ! (
149- " import names: {}" ,
150- import_name_and_ordinal_vector
151- . iter( )
152- . map( |( name, _ordinal) | name. clone( ) )
153- . collect:: <Vec <_>>( )
154- . join( ", " ) ,
155- ) ;
156-
157- // All import names are Rust identifiers and therefore cannot contain \0 characters.
158- // FIXME: when support for #[link_name] is implemented, ensure that the import names
159- // still don't contain any \0 characters. Also need to check that the names don't
160- // contain substrings like " @" or "NONAME" that are keywords or otherwise reserved
161- // in definition files.
162- let cstring_import_name_and_ordinal_vector: Vec < ( CString , Option < u16 > ) > =
163- import_name_and_ordinal_vector
164- . into_iter ( )
165- . map ( |( name, ordinal) | ( CString :: new ( name) . unwrap ( ) , ordinal) )
166- . collect ( ) ;
167-
168- let ffi_exports: Vec < LLVMRustCOFFShortExport > = cstring_import_name_and_ordinal_vector
169- . iter ( )
170- . map ( |( name_z, ordinal) | LLVMRustCOFFShortExport :: new ( name_z. as_ptr ( ) , * ordinal) )
171- . collect ( ) ;
172- let result = unsafe {
173- crate :: llvm:: LLVMRustWriteImportLibrary (
174- dll_name_z. as_ptr ( ) ,
175- output_path_z. as_ptr ( ) ,
176- ffi_exports. as_ptr ( ) ,
177- ffi_exports. len ( ) ,
178- llvm_machine_type ( & sess. target . arch ) as u16 ,
179- !sess. target . is_like_msvc ,
180- )
181- } ;
182-
183- if result == crate :: llvm:: LLVMRustResult :: Failure {
184- sess. dcx ( ) . emit_fatal ( ErrorCreatingImportLibrary {
185- lib_name,
186- error : llvm:: last_error ( ) . unwrap_or ( "unknown LLVM error" . to_string ( ) ) ,
187- } ) ;
188- }
189- }
190- }
191103}
192104
193105// The object crate doesn't know how to get symbols for LLVM bitcode and COFF bigobj files.
0 commit comments