[release/6.0] [MonoVM] Fix calculation of code size for AOT assemblies mixing JIT and LLVM #58503
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #58491 to release/6.0
/cc @lambdageek @filipnavara
Customer Impact
iOS apps built with LLVM are compiled into several Mach-O object files. These files are linked together using a native linker. When using LLVM AOT to publish iOS apps, two object files are created for each input assembly: an object file generated by LLVM, and an object file generated by mini. The mini-generated symbols and LLVM-generated symbols are separately colocated in the output binary, rather than being interleaved per-assembly.
This breaks exception handling: the AOT runtime assumes that, for each assembly, mini-generated and LLVM-generated code will be adjacent in memory. When this assumption is violated, the unwinder is fed bogus data, and any exception thrown by or meant to be caught by an LLVM-generated function will instead trigger the fallback unhandled exception handler and crash the app.
Testing
CI. Successful manual validation on an iPhone SE with the following test case: https://gist.github.com/imhameed/ccd542f151624c6399bd6d5c0f74b085
Risk
Moderate. The fix is in a part of the AOT runtime that runs early during app startup, but the exception handling failures might happen much later, making potential regressions difficult to diagnose.
As a fallback, it is possible to use Mono mini AOT compilation instead of LLVM AOT.