-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Public "stdcall" symbol not exported on cdylib on i686-pc-windows-gnu #50176
Comments
Here is a sample project to reproduce the bug: I can reproduce it using 'x86_64-pc-windows-gnu' target, but not 'x86_64-pc-windows-msvc'. The other interesting thing, is that in 'release' mode with
it is not reproduced. It happens only while 'debug' builds and 'release' builds with LTO turned off.
|
I can reproduce this for "system" calling convention. When using "C" calling convention the symbols are exported correctly. Happens for i686-pc-windows-gnu target, both debug and release. The x86_64-pc-windows-gnu target works. Tried it with different MinGW versions including cross-platform build (under Linux host). |
Did you ever find a workaround for this? I have a similar problem with the |
No solution with just cargo build. I do it with custom RUSTFLAGS and running build script for x86 target. RUSTFLAGS="-C link-arg=exports.def" exports.def contains symbols to be exported. |
@Dremon I am struggling with this for days. Thank you for your help. Do you happen to have an example project with an example |
It's pretty simple:
And the Rust code is: #[no_mangle]
pub unsafe extern "system" fn ExportedRustFunction1() {
} |
@Dremon With For me it still cannot find the symbols:
Perhaps they vanish or are optimized out before getting exported? |
It works with both x86_64- and i686-pc-windows-gnu (I only had this issue with i686 though). |
I think it will only work for the symbols from your crate, not for symbols from any dependencies. |
Yeah, that was what I was trying to accomplish. Thanks for your time. |
Triage: seems to work fine. Tested debug and release for each i686-pc-windows-gnu and x86_64-pc-windows-gnu using examples from #50176 (comment) and #50176 (comment) but could not reproduce any issue. |
I'll recheck if problem still take place with a last Rust release. |
Cargo.toml
Compilation:
@mati865, the issue is still in place. |
I've tried to update msys2 packages, but nothing has changed.
|
@dpelevin right, it was my oversight. I can reproduce your issue with Linux and MinGW targets so it appears to be different issue. I think I saw it reported somewhere but cannot find it. |
What Rust version was this fixed in? |
@YaLTeR I have no idea, with current nightly I'm getting:
|
rust-lang/rust#50176 has been fixed.
Seems to still be an issue on current beta. |
Actually doesn't work even on 1.44.0-nightly (74bd074 2020-04-03) on my CI. I can check manually on Windows. |
I've been cross compiling for i686 |
@YaLTeR example from this thread works fine for me. Could you check it yourself and open new issue with steps to reproduce?
Cargo.toml
src/lib.rs
|
I get the issue using the exact same setup as in the original post and as in your comment. Building in MSYS2 32-bit with the nightly-i686-pc-windows-gnu toolchain gives me a DLL without So the issue is very much still there. |
@YaLTeR is your |
Yes.
Well, it fails on my CI where the target program attempts to load the function at runtime and doesn't find it in the .dll (which works for all other variants of the toolchain). Here's what
And here's what it outputs for a good .dll (stable-x86_64):
|
@YaLTeR it looks good IMO. |
Oh, but I'm using #if defined(_WIN32) && !defined(_WIN64)
# define VS_CC __stdcall
#else
# define VS_CC
#endif It gives the desired behavior on all toolchains (including i686-msvc) except i686-gnu where the function is not visible or not exported or something. |
I don't know enough about stdcall convention to tell for sure but this may require import library without @Dylan-DPC please reopen this issue, sorry for the inconvenience. |
MinGW: enable dllexport/dllimport Fixes (only when using LLD) rust-lang#50176 Fixes rust-lang#72319 This makes `windows-gnu` on pair with `windows-msvc` when it comes to symbol exporting. For MinGW it means both good things like correctly working dllimport/dllexport, ability to link with LLD and bad things like rust-lang#27438. Not sure but maybe this should land behind unstable compiler option (`-Z`) or environment variable?
I am still experiencing this issue with stdcall not being exported on latest stable Rust version 1.69.0. Was this issue solved or worked around in some way i am not aware of? |
I'm making a cdylib crate which exports a function in the following manner:
The library is then supposed to be loaded by another program at runtime and the function dlsym'd from it.
This works everywhere (32/64-bit Linux, macOS, 32/64-bit Windows MSVC, 64-bit Windows GNU) except the
i686-pc-windows-gnu
target where the function isn't being exported from the resulting DLL for some reason.Minimal example is the code above in a clean crate with
crate-type = ["cdylib"]
.Possibly related: #50007, although for me the bug occurrs in both debug and release.
Rust: stable (1.25.0), beta, nightly.
The text was updated successfully, but these errors were encountered: