Skip to content

Commit e5f5895

Browse files
committed
Almost fix i686
1 parent eeef857 commit e5f5895

File tree

2 files changed

+10
-6
lines changed
  • compiler/rustc_codegen_llvm/src/back
  • src/test/run-make/raw-dylib-alt-calling-convention

2 files changed

+10
-6
lines changed

compiler/rustc_codegen_llvm/src/back/archive.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
164164
.iter()
165165
.map(|import: &DllImport| {
166166
if self.config.sess.target.arch == "x86" {
167-
LlvmArchiveBuilder::i686_decorated_name(import).into_string().unwrap()
167+
LlvmArchiveBuilder::i686_decorated_name(import, true).into_string().unwrap()
168168
} else {
169169
import.name.to_string()
170170
}
@@ -320,13 +320,17 @@ impl<'a> LlvmArchiveBuilder<'a> {
320320
}
321321
}
322322

323-
fn i686_decorated_name(import: &DllImport) -> CString {
323+
fn i686_decorated_name(import: &DllImport, mingw: bool) -> CString {
324324
let name = import.name;
325+
// MinGW doesn't want `_` prefix for `.def` file
326+
let prefix = if mingw { "" } else { "_" };
325327
// We verified during construction that `name` does not contain any NULL characters, so the
326328
// conversion to CString is guaranteed to succeed.
327329
CString::new(match import.calling_convention {
328-
DllCallingConvention::C => format!("_{}", name),
329-
DllCallingConvention::Stdcall(arg_list_size) => format!("_{}@{}", name, arg_list_size),
330+
DllCallingConvention::C => format!("{}{}", prefix, name),
331+
DllCallingConvention::Stdcall(arg_list_size) => {
332+
format!("{}{}@{}", prefix, name, arg_list_size)
333+
}
330334
DllCallingConvention::Fastcall(arg_list_size) => format!("@{}@{}", name, arg_list_size),
331335
DllCallingConvention::Vectorcall(arg_list_size) => {
332336
format!("{}@@{}", name, arg_list_size)

src/test/run-make/raw-dylib-alt-calling-convention/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Test the behavior of #[link(.., kind = "raw-dylib")] with alternative calling conventions.
22

3-
# only-i686-pc-windows-msvc
3+
# only-i686-pc-windows-gnu
44

55
-include ../../run-make-fulldeps/tools.mk
66

77
all:
88
$(call COMPILE_OBJ,"$(TMPDIR)"/extern.obj,extern.c)
9-
$(CC) "$(TMPDIR)"/extern.obj -link -dll -out:"$(TMPDIR)"/extern.dll
9+
$(CC) "$(TMPDIR)"/extern.obj -shared -o "$(TMPDIR)"/extern.dll
1010
$(RUSTC) --crate-type lib --crate-name raw_dylib_alt_calling_convention_test lib.rs
1111
$(RUSTC) --crate-type bin driver.rs -L "$(TMPDIR)"
1212
"$(TMPDIR)"/driver > "$(TMPDIR)"/output.txt

0 commit comments

Comments
 (0)