Skip to content

Allow interop resolvers to return self handle - #78004

Merged
lambdageek merged 5 commits into
dotnet:mainfrom
am11:feature/mono/interop
Nov 23, 2022
Merged

Allow interop resolvers to return self handle#78004
lambdageek merged 5 commits into
dotnet:mainfrom
am11:feature/mono/interop

Conversation

@am11

@am11am11 commented Nov 8, 2022

Copy link
Copy Markdown
Member

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.

@ghostghost added area-AssemblyLoader-mono community-contribution Indicates that the PR has been added by a community member labels Nov 8, 2022
@ghost

ghost commented Nov 8, 2022

Copy link
Copy Markdown

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

am11 commented Nov 8, 2022

Copy link
Copy Markdown
MemberAuthor

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

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

@lambdageek

Copy link
Copy Markdown
Member

@am11@vargaz I think we should back port

@lambdageek

Copy link
Copy Markdown
Member

/backport to release/7.0

@github-actions

Copy link
Copy Markdown
Contributor

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

@am11

am11 commented Nov 14, 2022

Copy link
Copy Markdown
MemberAuthor

@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
Copy Markdown
Member

/azp run runtime-extra-platforms

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@akoeplinger

Copy link
Copy Markdown
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

am11 commented Nov 15, 2022

Copy link
Copy Markdown
MemberAuthor

@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
Copy Markdown
Member

/azp run runtime-android

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@lambdageek

Copy link
Copy Markdown
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

am11 commented Nov 15, 2022

Copy link
Copy Markdown
MemberAuthor

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

am11 commented Nov 15, 2022

Copy link
Copy Markdown
MemberAuthor
 [ 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
am11force-pushed the feature/mono/interop branch from 4156ab6 to 2443e43CompareNovember 16, 2022 17:33
@am11

am11 commented Nov 16, 2022

Copy link
Copy Markdown
MemberAuthor

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. 🙂

@am11
am11force-pushed the feature/mono/interop branch from 2443e43 to b3473b5CompareNovember 16, 2022 17:45
@lambdageek

Copy link
Copy Markdown
Member

/azp run runtime-android

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@am11

am11 commented Nov 16, 2022

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
Member

/azp run runtime-android

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@am11

am11 commented Nov 22, 2022

Copy link
Copy Markdown
MemberAuthor

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

@lambdageek

Copy link
Copy Markdown
Member

/azp run runtime-android

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@lambdageek

Copy link
Copy Markdown
Member

/backport to release/7.0

@github-actions

Copy link
Copy Markdown
Contributor

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

@lambdageek

Copy link
Copy Markdown
Member

/azp run runtime-androidemulator

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@lambdageek

Copy link
Copy Markdown
Member

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

@lambdageek
lambdageek merged commit 11ca24d into dotnet:mainNov 23, 2022
@am11
am11 deleted the feature/mono/interop branch November 23, 2022 23:46
@ghostghost locked as resolved and limited conversation to collaborators Dec 24, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-AssemblyLoader-monocommunity-contributionIndicates 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

@am11@lambdageek@akoeplinger