@@ -189,6 +189,15 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
189189 path. push ( lib_name) ;
190190 path
191191 } ;
192+ // dlltool target architecture args from:
193+ // https://github.com/llvm/llvm-project-release-prs/blob/llvmorg-15.0.6/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp#L69
194+ let ( dlltool_target_arch, dlltool_target_bitness) = match sess. target . arch . as_ref ( ) {
195+ "x86_64" => ( "i386:x86-64" , "--64" ) ,
196+ "x86" => ( "i386" , "--32" ) ,
197+ "aarch64" => ( "arm64" , "--64" ) ,
198+ "arm" => ( "arm" , "--32" ) ,
199+ _ => panic ! ( "unsupported arch {}" , sess. target. arch) ,
200+ } ;
192201 let result = std:: process:: Command :: new ( dlltool)
193202 . args ( [
194203 "-d" ,
@@ -197,6 +206,10 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
197206 lib_name,
198207 "-l" ,
199208 output_path. to_str ( ) . unwrap ( ) ,
209+ "-m" ,
210+ dlltool_target_arch,
211+ "-f" ,
212+ dlltool_target_bitness,
200213 "--no-leading-underscore" ,
201214 "--temp-prefix" ,
202215 temp_prefix. to_str ( ) . unwrap ( ) ,
@@ -422,24 +435,22 @@ fn find_binutils_dlltool(sess: &Session) -> OsString {
422435 return dlltool_path. clone ( ) . into_os_string ( ) ;
423436 }
424437
425- let mut tool_name: OsString = if sess. host . arch != sess. target . arch {
426- // We are cross-compiling, so we need the tool with the prefix matching our target
427- if sess. target . arch == "x86" {
428- "i686-w64-mingw32-dlltool"
429- } else {
430- "x86_64-w64-mingw32-dlltool"
431- }
438+ let tool_name: OsString = if sess. host . options . is_like_windows {
439+ // If we're compiling on Windows, always use "dlltool.exe".
440+ "dlltool.exe"
432441 } else {
433- // We are not cross-compiling, so we just want `dlltool`
434- "dlltool"
442+ // On other platforms, use the architecture-specific name.
443+ match sess. target . arch . as_ref ( ) {
444+ "x86_64" => "x86_64-w64-mingw32-dlltool" ,
445+ "x86" => "i686-w64-mingw32-dlltool" ,
446+ "aarch64" => "aarch64-w64-mingw32-dlltool" ,
447+
448+ // For non-standard architectures (e.g., aarch32) fallback to "dlltool".
449+ _ => "dlltool" ,
450+ }
435451 }
436452 . into ( ) ;
437453
438- if sess. host . options . is_like_windows {
439- // If we're compiling on Windows, add the .exe suffix
440- tool_name. push ( ".exe" ) ;
441- }
442-
443454 // NOTE: it's not clear how useful it is to explicitly search PATH.
444455 for dir in env:: split_paths ( & env:: var_os ( "PATH" ) . unwrap_or_default ( ) ) {
445456 let full_path = dir. join ( & tool_name) ;
0 commit comments