-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong calling convention on using ffi of extern mod #9055
Comments
(The example worked on 0.7.) |
Interesting. cc me. |
I tried to make a workaround by wrapping a.rs: #[crate_type = "lib"];
pub use std::ptr;
pub use std::libc::*;
pub use std::libc::types::os::arch::extra::*;
extern "stdcall" {
fn MessageBoxW(hWnd: HANDLE, lpText: LPCWSTR, lpCaption: LPCWSTR, uType: c_uint) -> c_int;
}
pub trait Dummy {}
pub trait Window {
fn message_box(&self);
}
impl<D: Dummy> Window for D {
fn message_box(&self) {
#[fixed_stack_segment];
unsafe { MessageBoxW(ptr::mut_null(), ptr::null(), ptr::null(), 0 as c_uint); }
}
} b.rs: extern mod a;
use a::*;
struct D;
impl Dummy for D;
fn main() {
let x = D;
x.message_box();
} which occurs same callconv issue. |
It occurs on generic functions, not only on generic impls: a.rs: #[crate_type = "lib"];
use std::ptr;
pub use std::libc::*;
pub use std::libc::types::os::arch::extra::*;
extern "stdcall" {
fn MessageBoxW(hWnd: HANDLE, lpText: LPCWSTR, lpCaption: LPCWSTR, uType: c_uint) -> c_int;
}
pub fn g<T>() {
#[fixed_stack_segment];
unsafe { MessageBoxW(ptr::mut_null(), ptr::null(), ptr::null(), 0 as c_uint); }
} b.rs: extern mod a;
fn main() {
a::g::<int>();
} This means |
From #8203 bors log, it is broken somewhere between 0.7 and 2246d56. |
You could narrow it down with |
Beforehand it was assumed that the standard cdecl abi was used for all extern fns of extern crates, but this reads the abi of the extern fn type and declares the function in the local crate with the appropriate type. I was trying to think of how to write a test for this, but I was just drawing up blanks :(. Are there standard functions in libc which are not of the cdecl abi? If so we could try linking to them and make sure that the cal completes successfully. Otherwise, I manually verified that the function was declared correctly by looking at the llvm assembly. cc #9055 (I'm not sure if this will fix that issue)
#9196 fixed all three examples. closing! |
…on, r=Manishearth update node.js version in `remark.yml` Optional chain (`?.`) is available in `node v14`, but node version in CI is `node v12`, so CI is failed now. ref: https://github.com/rust-lang/rust-clippy/runs/7059529735?check_suite_focus=true optional chain: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#browser_compatibility Corresponding PR (maybe) remarkjs/remark#1007 changelog: None
Here's an example on win32.
a.rs:
Build a.rs as shared library.
b.rs:
Building b.rs I got linking failure:
LLVM IR has some interesting point:
so rustc generates correct
call
, but wrongdeclare
(no callconv).Frankly I don't even know if it's ok to use foreign fn from extern module. I'm also confused that there is no need to add
pub
atMessageBoxW
declaration.The text was updated successfully, but these errors were encountered: