-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Unable to export unmangled dll entry points for stdcall #17806
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
Comments
All dllexport'ed functions are usually "mangled" in that way. It's not rust-specific; gcc does same and I think msvc link.exe does too. |
This is a LLVM issue - it mangles stdcall symbols so that the
|
An updated command line,
I am not an expert on stdcall, but it would seem that the EDIT: Also, I did do this on Linux, as I assumed that the ABI is the important part here, not Windows specifically. That could be a wrong assumption, I am terrible at Windows stuff :( |
The |
What would be cool is if, for the |
I have inverse problem: I try to set exported name with "@" symbol. So, with gnu toolchain I create fork like:
And it works correctly. This code also works with msvc amd64 toolchain. But on msvc x86 toolchain I can't find way to get exported name like "_AbortCompilerPass@4". I try to use:
But MS linker ignored all @4 in all variants :( |
I created simple example with my issue: https://github.com/bozaro/rust-msvcdll
For toolchains:
I try to implement wrapper for Visual Studio compiler plugin: Also looks like removing
|
Also in ideal world I want one of two options:
At this moment:
|
@bozaro I think the #[export_name = "\x01AbortCompilerPass"] The leading "1 byte" tells LLVM to disable all name mangling. |
@alexcrichton: @bozaro problem is the opposite. Currently (rust 1.11) |
Here's an update on what the current situation is for the example in the original post using
This is what is exported from the DLL itself: Now in @bozaro 's case, |
Oh! Sorry I misinterpreted this issue totally. This is probably because we don't use |
@alexcrichton If we want to do this properly, we'll need to distinguish between the name exported from the import library and the name exported from the DLL itself, and unfortunately |
Triage: no changes I'm aware of |
was this ever fixed? |
^ having this issue and cant find a working workaround, tried everything from renaming to using \x01 |
Just got bitten by this. |
If you need to do some very specific renaming (adding the "@12", etc), you can use this workaround in If overrides the This isn't without downsides: It'll override any transitive exports from dependencies your library has, unless you explicitly re-add them. As such, this might not work for every use case. This is undoubtedly an unstable hack around the problem. It also only works with MSVC [target.i686-pc-windows-msvc]
rustflags = [
# Allows us to export the correct stdcall symbol names for Windows 32-bit binaries.
# Rust has no way to explicitly export a symbol named "_RVExtension@12", it cuts off the @12.
# This overrides the linker's /DEF argument, to force it to export the symbols we want.
"-Clink-arg=/DEF:Win32.def",
# Generate a map file so we can see what symbols exist, and what we're exporting. (NOT REQUIRED)
"-Clink-arg=/MAP:SymbolInfo.map",
# Add exported symbol info to the map file (NOT REQUIRED)
"-Clink-arg=/MAPINFO:EXPORTS"
] Contents of Win32.def are exports which exactly match the private symbols rustc produced (visible in that map file that gets dumped)
|
Hi.
After some questions on IRC I think this might be a bug or at least a missing feature:
I'd like to export functions with a name of my choosing. I knew about #[no_mangle] and learned about #[export_name] on IRC, but both fail to work in my case.
Code/test.rs:
Build with
rustc --cratetype dylib test.rs
Result:

So, every single stdcall entry point follows the name@sizeofarguments convention. I have a number of DLLs right in front of me (not based on rust) that export stdcall entries and DON'T use that convention. In fact, I'm reasonably sure that most of the windows API is both using stdcall and exporting 'unmangled' names.
Can I create something similar with rust? Am I missing another attribute? Should no_mangle work in these cases? Should export_name?
The text was updated successfully, but these errors were encountered: