-
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
MSVC: Avoid using jmp stubs for dll function imports #84758
Conversation
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
Second commit looks good to me -- thank you. Could I get a sanity check from some Windows pros on the reasoning in #84758 (comment) and the content of f66c678353407015a8f795f2683f7688759b2b72? @rustbot ping windows |
Hey Windows Group! This bug has been identified as a good "Windows candidate". cc @arlosi @danielframpton @gdr-at-ms @kennykerr @luqmana @lzybkr @nico-abram @retep998 @rylev @sivadeilra @wesleywiser |
The extern block includes BCryptGenRandom, which according to msdn is in Bcrypt.dll, not kernel32 (Like the link attribute says). Is that correct? |
This is true. However, Rust's That said, it might be worth separating them properly for the sake of documentation and future proofing. |
It would help to avoid confusion here, by using the correct DLL name. My team is working on implementing the raw-dylib support for Windows, so that the |
This avoids using jmp stubs when calling functions exported from a dll.
Ok, I've changed the second commit to use the proper import libraries. Note that #84794 somewhat mitigates the previous issue with duplicate import names, so long as the duplicate At some point during copy/pasting parts around rustfmt got hold of it, which makes the diff a bit noisier than I'd like. I can try to separate out the formatting changes if that's a problem. |
Btw, in case it helps anyone test my working, here's the powershell commands I'm using to verify the difference this PR makes:
I'm using the "Developer Powershell for VS 2019" but only so dumpbin is in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@bors r+ |
📌 Commit fc40aa0 has been approved by |
// >= Vista / Server 2008 | ||
// https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsymboliclinkw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why u deleted this comments (and lower)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that only Windows 7+ is supported the detailed version info seems redundant.
Rollup of 6 pull requests Successful merges: - rust-lang#84758 (MSVC: Avoid using jmp stubs for dll function imports) - rust-lang#85288 (add an example to explain std::io::Read::read returning 0 in some cases) - rust-lang#85334 (Add doc aliases to `unit`) - rust-lang#85525 (Fix my mailmap entry) - rust-lang#85571 (Remove surplus prepend LinkedList fn) - rust-lang#85575 (Fix auto-hide for implementations and implementors.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Windows import libraries contain two symbols for every function:
__imp_FunctionName
andFunctionName
(whereFunctionName
is the name of the function to be imported).__imp_FunctionName
contains the address of the imported function. This will be filled in by the Windows executable loader at runtime.FunctionName
contains a jmp stub that simply jumps to the address given by__imp_FunctionName
. E.g. it's a function that solely contains a single jmp instruction:When using an external DLL function in Rust, by default the linker will link to FunctionName, causing a bit of indirection at runtime. In Microsoft's C++ it's possible to instead tell it to insert calls to the address in
__imp_FunctionName
by using the__declspec(dllimport)
attribute. In Rust it's possible to get effectively the same behaviour using the#[link]
attribute onextern
blocks.The second commit also merges multiple
extern
blocks into one block. This is because otherwise Rust will currently create duplicate linker arguments for each block. In this case having duplicates shouldn't matter much other than the noise when displaying the linker command.