-
Notifications
You must be signed in to change notification settings - Fork 4.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
Redirect DllImport of hostpolicy to the main executable when it's embedded #40014
Redirect DllImport of hostpolicy to the main executable when it's embedded #40014
Conversation
Tagging subscribers to this area: @swaroop-sridhar, @agocke |
src/coreclr/src/vm/dllimport.cpp
Outdated
@@ -6328,6 +6331,19 @@ namespace | |||
} | |||
#endif | |||
|
|||
if (g_hostpolicy_embedded) | |||
{ | |||
#if defined(TARGET_LINUX) |
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.
Would it be a good idea to invert this condition to make this logic future proof; such that all OS except Windows get libhostpolicy
?
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.
Yes, I think everything but Windows should use libhostpolicy
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 this actually the name used in this context? - not libhostpolicy.so
or something with a path?
In the case above we could, in theory, see different file names, but we intentionally only recognize the form used in Interop.Libraries.cs
.
Jut wonder whether there is anything to worry about hostpolicy naming.
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.
The story is the same - we don't expect any other code but corelib to call into hostpolicy directly, so these strings need to match what's in Interop.Libraries
, but nothing else.
I fixed the condition to be for Windows - should also fix the build failures in CI
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.
LGTM
src/coreclr/src/vm/dllimport.cpp
Outdated
if (g_hostpolicy_embedded) | ||
{ | ||
#ifdef TARGET_WINDOWS | ||
if (wcscmp(wszLibName, W("hostpolicy.dll")) == 0) { |
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.
nit: {
on its own line for consistency.
@BruceForstall can you please take a look why the formatting job is failing on this PR? The changes don't touch JIT code. And the generated patch file is empty (0 bytes). |
Windows formatting job failure is unrelated to PR changes, failing in every PR. See #40034. |
Thanks @am11 - I'm trying to figure out the other failures now... |
Something weird is happening. One of the tests is failing with:
But looking at the code runtime/src/tests/Interop/COM/NativeClients/Primitives/Client.cpp Lines 24 to 45 in 7242e14
There's no way it returns exit code 3. |
The |
It is an assert - but seems valid - debugging through it right now. |
The test is mocking hostpolicy - so maybe there's something going on there (although I would not expect to affect non-single-file builds at all, given that the embedded variables should be false in that case) |
Found it - uninitialized variable (I've been working in C# for way too long now, forgot all of the C++ gotchas)... I can only wish for default compiler settings which would definitely show this as a warning. |
Heh, it's C++ which first says |
In this case (on my machine anyway) it initialized to magical 204 (literally) - and since conditions treat anything non-zero as true.... |
Networking test failures are being fixed in #40070. |
We have all reasonable C++ warnings turned on. C++ compilers do not seem to provide warning to catch this type of problem. Neither
|
It's great that we have warnings on... and not so great that the compiler doesn't have a way to warn on this (I guess it is a hard problem in C++). I definitely didn't mean to downplay our efforts on the codebase... |
For
singlefilehost
thehostpolicy
is statically linked into the executable, so we need to apply similar logic to other statically linked libraries by redirectingDllImport
loads to the main executable module.Because this happens also on Windows, the coreclr itself doesn't know statically (unlike on Linux where we link coreclr statically as well, so we can hardcode this knowledge). So the hostpolicy must pass this information to the runtime via a new runtime property.
Tested both on Windows and Linux.
Fixes #39907