-
Notifications
You must be signed in to change notification settings - Fork 287
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
Use delayed loading for windows #404
Conversation
I think it might be better to add |
I think it should be part of the documentation on the website, but couldn't find where to change that. |
Oh yea that's even better. I'm the maintainer of the docs so I'll PR there after this is merged. |
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.
There should probably be an opt-out. See bnoordhuis/node-heapdump@78056ec1 for an example where the delayed loading hook had to be disabled.
#include <delayimp.h> | ||
#include <string.h> | ||
|
||
extern "C" FARPROC WINAPI __load_exe_hook(unsigned int, DelayLoadInfo*); |
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.
You don't need to export the symbol, only __pfnDliNotifyHook2
needs to be exported. Just this should suffice:
static FARPROC WINAPI __load_exe_hook(unsigned int event, DelayLoadInfo* info) {
// ...
}
decltype(__pfnDliNotifyHook2) __pfnDliNotifyHook2 = __load_exe_hook;
By the way, I think you could turn this into a .rs file. You'd probably have to provide definitions of dliNotePreLoadLibrary
and DelayLoadInfo
though, so it might be not be shorter.
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.
Much better, thanks!
I have no idea how to write those definitions they're pretty complicated to me. And as neon-runtime already includes c code anyways, i figured a little more shouldn't be a problem. Though of course pure rust is nicer.
Optionally removing it is as simple as removing .cargo/config
(though the hook then still gets needlessly compiled in neon-runtime) as long as it's documented it's there i think it shouldn't be an issue.
Hello @dherman , do you have any plans to review and merge it to the master branch in the nearest time? |
@jrd-rocks Thanks for this contribution! Are you still interested in working on this? If so, I have some notes on simplifications. Thanks, again!
env: {
...process.env,
RUSTFLAGS: '-C link-arg=win_delay_load_hook.obj -C link-arg=delayimp.lib -C link-arg=/DELAYLOAD:node.exe'
} I've got a hacked together branch and validates this approach works, but it needs to be done properly. https://github.com/kjvalencik/neon/tree/windows-electron |
I was trying to get this going, just to be clear: I'll need to use the I'll be happy to try and dive into neon to try and get the needed changes in assuming i can get them going (so far still seeing |
@joshuef Yes, you would also need to use the |
@joshuef Are you on the neon Slack? I'm not a windows developer and it would be helpful if you are able to test my work. Thanks! |
Electron on windows needs to use delayed loading. For node.js delayed loading works as well (it's the default when building with node.gyp)
For full details see https://github.com/jrd-rocks/neon/blob/electron_delay_hook/README%20ELECTRON%204.md #389
The neon command that creates a default project still needs fixing to add a .cargo/config file with the linker command.Never mind that, i updated the cli script as well (a breeze after figuring out the linker delay load black magic)