Skip to content
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

Allow interop resolvers to return self handle #78004

Merged
merged 5 commits into from Nov 23, 2022

Conversation

am11
Copy link
Member

@am11 am11 commented Nov 8, 2022

When user-defined resolvers return self handle via GetMainProgramHandle(), we lookup the cached handle in mono and fail to find one because internal_module is not cached in native_library_module_map.

Fix is to test the resolver returned handle against self; before the map lookup (which happens under the lock).

Close #77985.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Nov 8, 2022
@ghost
Copy link

ghost commented Nov 8, 2022

Tagging subscribers to this area:
See info in area-owners.md if you want to be subscribed.

Issue Details

When user-defined resolvers return self handle via GetMainProgramHandle(), we lookup the cached handle in mono and fail to find one because internal_module is not cached in native_library_module_map.

Fix is to test the resolver returned handle against self; before the map lookup (which happens under the lock).

Close #77985.

Author: am11
Assignees: -
Labels:

area-AssemblyLoader-mono

Milestone: -

@am11
Copy link
Member Author

am11 commented Nov 8, 2022

@lambdageek, @vargaz, candidate of backport? (GetMainProgramHandle is a new API in 7.0)

wasm failures are preexisting: #64188, #76454, #78017

@lambdageek
Copy link
Member

@am11 @vargaz I think we should back port

@lambdageek
Copy link
Member

/backport to release/7.0

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2022

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3419652288

@am11
Copy link
Member Author

am11 commented Nov 14, 2022

@lambdageek, could you please run the Android pipeline (/azp run runtime-extra-platforms) against this PR? I think Android test runner will fail here as well. I'll then push a fix to verify it works (#78018 (comment)).

@lambdageek
Copy link
Member

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@akoeplinger
Copy link
Member

On main we can also do /azp run runtime-android to only run the android jobs.
I've looked at the test results from the runtime-extra-platforms jobs that are already in and they are indeed the same as @am11 suspected.

In general we should try to avoid merging a backport for PRs that weren't yet merged to main, we'd probably have caught this earlier.

@am11
Copy link
Member Author

am11 commented Nov 15, 2022

@lambdageek, could you re-run the leg? The tests are passing locally now. For the internal call, we needed to continue looking up in the map.

@lambdageek
Copy link
Member

/azp run runtime-android

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lambdageek
Copy link
Member

@am11 I've been meaning to ask: would it be possible to add a unit test for #77985? probably something using the remote executor would work, and looking for some C standard lib function (like _malloc ?) on non-Windows?

@am11
Copy link
Member Author

am11 commented Nov 15, 2022

For some reason, it wasn't failing the debug build ./build.sh mono+libs -os Android with missing data type (gboolean).🤔 Fixed in 4156ab6.

@lambdageek, sure. I will add a case in resolver tests.

@am11
Copy link
Member Author

am11 commented Nov 15, 2022

  [ 17%] Building C object mono/mini/CMakeFiles/monosgen-objects.dir/__/metadata/sgen-mono.c.o
  /Users/adeel/projects/runtime/src/mono/mono/metadata/native-library.c:677:138: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
  netcore_resolve_with_dll_import_resolver_nofail (MonoAssemblyLoadContext *alc, MonoAssembly *assembly, const char *scope, guint32 flags, is_internal)

Wimplicit-int should be an error in local builds as well, IMO.

@am11
Copy link
Member Author

am11 commented Nov 16, 2022

Added a test and rebased. I had to change the way we resolve self handle on Android: use dlopen(NULL, RTLD_NOW) instead of setting it to RTLD_DEFAULT, which is null on 64-bit platforms and RTLD_NOW is what they use for handle to self.

@lambdageek, please azp run again. 🙂

@lambdageek
Copy link
Member

/azp run runtime-android

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@am11
Copy link
Member Author

am11 commented Nov 16, 2022

Thank you. So Android legs were green. I have disabled the new test on Windows and monointerpreter:

  • free is not availabe in the self image on Windows (which is OK and aligns with @lambdageek's expectation for the test)
  • monointerpreter is not OK, but that is a preexisting problem. Calling free on self handle via P/Invoke breaks IL interpreter on all mono supported OS. We should fix it (separately; not part of this PR).

@lambdageek
Copy link
Member

/azp run runtime-android

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@am11
Copy link
Member Author

am11 commented Nov 22, 2022

@lambdageek, it's green (including Android AOT offsets). Good to merge & backport now? :)

@lambdageek
Copy link
Member

/azp run runtime-android

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lambdageek
Copy link
Member

/backport to release/7.0

@github-actions
Copy link
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3534964800

@lambdageek
Copy link
Member

/azp run runtime-androidemulator

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lambdageek
Copy link
Member

New test passed on Android emulator. LGTM. Thanks @am11

@lambdageek lambdageek merged commit 11ca24d into dotnet:main Nov 23, 2022
@am11 am11 deleted the feature/mono/interop branch November 23, 2022 23:46
@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-AssemblyLoader-mono community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle returned GetMainProgramHandle() not sufficient for resolving statically linked native symbols on iOS
3 participants