diff options
| author | bors <bors@rust-lang.org> | 2021-07-09 23:24:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-09 23:24:21 +0000 |
| commit | 8d9d4c87d677552ae52e2d58034e4be199b5a6d2 (patch) | |
| tree | 634db4e9ad0c606cf2c95e7f256da1121b18fea9 /compiler/rustc_codegen_llvm/src | |
| parent | 240ff4c4a0d0936c9eeb783fa9ff5c0507a6ffb4 (diff) | |
| parent | a867dd4c7e65beb1453fcff9e252e7ab19f0e1d0 (diff) | |
| download | rust-8d9d4c87d677552ae52e2d58034e4be199b5a6d2.tar.gz rust-8d9d4c87d677552ae52e2d58034e4be199b5a6d2.zip | |
Auto merge of #86419 - ricobbe:raw-dylib-stdcall, r=petrochenkov
Add support for raw-dylib with stdcall, fastcall functions Next stage of work for #58713: allow `extern "stdcall"` and `extern "fastcall"` with `#[link(kind = "raw-dylib")]`. I've deliberately omitted support for vectorcall, as that doesn't currently work, and I wanted to get this out for review. (I haven't really investigated the vectorcall failure much yet, but at first (very cursory) glance it appears that the problem is elsewhere.)
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/back/archive.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/compiler/rustc_codegen_llvm/src/back/archive.rs b/compiler/rustc_codegen_llvm/src/back/archive.rs index 64416bced31..6ac7093b7de 100644 --- a/compiler/rustc_codegen_llvm/src/back/archive.rs +++ b/compiler/rustc_codegen_llvm/src/back/archive.rs @@ -12,7 +12,7 @@ use crate::llvm::{self, ArchiveKind, LLVMMachineType, LLVMRustCOFFShortExport}; use rustc_codegen_ssa::back::archive::{find_library, ArchiveBuilder}; use rustc_codegen_ssa::{looks_like_rust_object_file, METADATA_FILENAME}; use rustc_data_structures::temp_dir::MaybeTempDir; -use rustc_middle::middle::cstore::DllImport; +use rustc_middle::middle::cstore::{DllCallingConvention, DllImport}; use rustc_session::Session; use rustc_span::symbol::Symbol; @@ -208,10 +208,12 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> { // have any \0 characters let import_name_vector: Vec<CString> = dll_imports .iter() - .map(if self.config.sess.target.arch == "x86" { - |import: &DllImport| CString::new(format!("_{}", import.name.to_string())).unwrap() - } else { - |import: &DllImport| CString::new(import.name.to_string()).unwrap() + .map(|import: &DllImport| { + if self.config.sess.target.arch == "x86" { + LlvmArchiveBuilder::i686_decorated_name(import) + } else { + CString::new(import.name.to_string()).unwrap() + } }) .collect(); @@ -391,6 +393,21 @@ impl<'a> LlvmArchiveBuilder<'a> { ret } } + + fn i686_decorated_name(import: &DllImport) -> CString { + let name = import.name; + // We verified during construction that `name` does not contain any NULL characters, so the + // conversion to CString is guaranteed to succeed. + CString::new(match import.calling_convention { + DllCallingConvention::C => format!("_{}", name), + DllCallingConvention::Stdcall(arg_list_size) => format!("_{}@{}", name, arg_list_size), + DllCallingConvention::Fastcall(arg_list_size) => format!("@{}@{}", name, arg_list_size), + DllCallingConvention::Vectorcall(arg_list_size) => { + format!("{}@@{}", name, arg_list_size) + } + }) + .unwrap() + } } fn string_to_io_error(s: String) -> io::Error { |
