Skip to content

Conversation

@grendello
Copy link
Contributor

@grendello grendello commented May 18, 2018

NOTE: this PR can be merged ONLY after Xamarin.Android can update its Mono
to a version which includes this commit (the commit is now in the mono/2018-06 branch).
It would be best that Mono bump to pull the commit would be added to this PR, so that the tests succeed and we have no broken
builds.

Xamarin.Android side of the Mono's mkbundle update which makes it easier (and
safer) to introduce changes in the template generated by mkbundle when creating
the application bundle.

Code generated by mkbundle calls into the Mono runtime and in order for this to
work on Xamarin.Android, libmonodroid needs to properly initialize the bundle or
the application won't work (dlsym won't be able to find the Mono runtime
symbols). This has been done by patching the generated code using plain
search-and-replace which is very fragile even to the slightest changes and it
doesn't guarantee that any new additions won't break the Xamarin.Android
bundle (see #1651)

Mono's mkbundle has been updated (see mono/mono@170e944)
to support third parties, like Xamarin.Android, which need to use special
methods to initialize the bundle. The third party provides a small bit of source
code with a dispatch structure (mkbundle has its own default version of the
structure) which contains pointers to all the Mono runtime methods required by
the initialization code. The provided code is inserted by mkbundle in place of
its default version. If there are any incompatibilities between the two
structures (such as missing pointers, invalid signature, additional pointers
etc) then the bundle will not build, thus allowing the third party to notice the
problem early and update its version of the structure. Likewise, if the build
succeeds but the pointers aren't correctly initialized (i.e. they are null), a
runtime check will discover the fact and fail the application gracefully.

The bit of inserted code also contains platform-specific logging function in
place of the calls to fprintf used by mkbundle previously. For Xamarin.Android
it means that all the error messages will end up in logcat.

Xamarin.Android's version of the structure and the error logging function are
found in the mkbundle-api.h C header which is used both when building
libmonodroid (to ensure that when initializing the generated bundle libmonodroid
is ABI-compatible with it) and is copied to the framework directory to be used
when generating the application bundle.

Sample of XA-generated bundle code:
https://gist.github.com/grendello/465ecec96b3bee801e6bbc5a28019833

@grendello grendello added the do-not-merge PR should not be merged. label May 18, 2018
Xamarin.Android side of the Mono's mkbundle update which makes it easier (and
safer) to introduce changes in the template generated by mkbundle when creating
the application bundle.

Code generated by mkbundle calls into the Mono runtime and in order for this to
work on Xamarin.Android, libmonodroid needs to properly initialize the bundle or
the application won't work (`dlsym` won't be able to find the Mono runtime
symbols). This has been done by patching the generated code using plain
search-and-replace which is very fragile even to the slightest changes and it
doesn't guarantee that any new additions won't break the Xamarin.Android
bundle (see dotnet#1651)

Mono's mkbundle has been updated (see
mono/mono@170e944)
to support third parties, like Xamarin.Android, which need to use special
methods to initialize the bundle. The third party provides a small bit of source
code with a dispatch structure (mkbundle has its own default version of the
structure) which contains pointers to all the Mono runtime methods required by
the initialization code. The provided code is inserted by mkbundle in place of
its default version. If there are any incompatibilities between the two
structures (such as missing pointers, invalid signature, additional pointers
etc) then the bundle will not build, thus allowing the third party to notice the
problem early and update its version of the structure. Likewise, if the build
succeeds but the pointers aren't correctly initialized (i.e. they are `null`), a
runtime check will discover the fact and fail the application gracefully.

The bit of inserted code also contains platform-specific logging function in
place of the calls to `fprintf` used by mkbundle previously. For Xamarin.Android
it means that all the error messages will end up in logcat.

Xamarin.Android's version of the structure and the error logging function are
found in the `mkbundle-api.h` C header which is used *both* when building
libmonodroid (to ensure that when initializing the generated bundle libmonodroid
is ABI-compatible with it) and is copied to the framework directory to be used
when generating the application bundle.

Sample of XA-generated bundle code:
https://gist.github.com/grendello/465ecec96b3bee801e6bbc5a28019833
@luhenry
Copy link
Contributor

luhenry commented Aug 9, 2018

@grendello could you please confirm that this PR has already been merged into xamarin-android:master via #1503?

@grendello
Copy link
Contributor Author

Yes, this PR has already been merged elsewhere. Closing.

@grendello grendello closed this Sep 5, 2018
@grendello grendello deleted the mkbundle-interop branch September 5, 2018 10:41
@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

do-not-merge PR should not be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants