Skip to content

Commit

Permalink
[native] Native call tracing infra + native build system overhaul (#8857
Browse files Browse the repository at this point in the history
)

Context: #8800
Context: 8bc7a3e
Context: 6836818
Context: libunwind/libunwind#702

Begin adding native method call tracing infrastructure based on
[libunwind][0], initially used in tracing the reasons for why
[Blazor][1] apps break when LLVM marshal methods are enabled
(8bc7a3e, 6836818).  The utility of such infrastructure, however,
is beyond just that particular task; it should be available for
general use by both us and applications.

Method call tracing support is not enabled by default.
To enable it, set the `$(_AndroidEnableNativeStackTracing)` MSBuild
property to `true`.  This will enable the ability to print native, 
managed and Java stack traces by invoking the `monodroid_log_traces`
function from either managed or native application code.

Additionally, change the directory layout for native code.

Previously, `src/monodroid` would produce *five* native libs:

  * `libmono-android.debug.so`
  * `libmono-android.release.so`
  * `libxa-internal-api.so`
  * `libxamarin-app.so`
  * `libxamarin-debug-app-helper.so`

This made for a large `src/monodroid/CMakeLists.txt`, complicating
maintenance.  We had considered trying to move these into separate
`src/LIBRARY-NAME` directories, but it makes things easier with
CMake if we introduce an intermediate directory.

Introduce a new `src/native` directory, to hold native binaries:

  * `src/native/monodroid`: new location for `libmono-android.*.so`

  * `src/native/xamarin-debug-app-helper`: source for
    `libxamarin-debug-app-helper.so`, containing code moved from
    previous `src/monodroid`

  * `src/native/xamarin-app-stub`: source for the "stub"
    `libxamarin-app.so`; the "real" one is produced in the app build.

Some `src/native/*` directories produce libraries (`.so` files). and
some produce *static* archives (`.a` files) to simplify using code
across native libraries.

A [cmake-presets file][2] is processed by `xaprepare`, to create a
`src/native/CMakePresets.json` which contains all the version-specific
bits replacements such as Android API levels, paths to utilities etc.

Developers can create a `src/native/CMakeUserPresets.json` file to
provide local modifications to config options within
`src/native/CMakePresets.json.in`.

Other changes:

  * `src/native/libunwind/fixes/aarch64/Gos-linux.c` is an altered
    copy of [`libunwind/src/aarch64/Gos-linux.c`][3] in order to
    workaround libunwind/libunwind#702.

  * *Begin* turning some instance member functions into static member
    functions, as we don't otherwise need instances of those classes.

  * Begin using `std::source_location` for better crash messages,
    instead of using `__FILE__` and `__LINE__`.

  * Fix endless recursion from a typo in `Util::ends_with()` overload.

[0]: https://github.com/libunwind/libunwind
[1]: https://learn.microsoft.com/aspnet/core/blazor/hybrid/tutorials/maui?view=aspnetcore-8.0
[2]: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html
[3]: https://github.com/libunwind/libunwind/blob/9cc4d98b22ae57bc1d8c253988feb85d4298a634/src/aarch64/Gos-linux.c
  • Loading branch information
grendello authored May 16, 2024
1 parent 478de4c commit a7b5768
Show file tree
Hide file tree
Showing 132 changed files with 4,561 additions and 3,072 deletions.
26 changes: 13 additions & 13 deletions .gdn/policheck/source.gdnsuppress
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"default": {
"name": "default",
"createdDate": "2023-02-22 23:55:29Z",
"lastUpdatedDate": "2024-02-22 21:40:38Z"
"lastUpdatedDate": "2024-04-22 13:40:30Z"
}
},
"results": {
Expand Down Expand Up @@ -101,43 +101,43 @@
"justification": "Reference to an Android logging function.",
"createdDate": "2023-02-22 23:55:29Z"
},
"a2b4d032c59a9d1211d218c3cd550cf8febb369941d70284d07d03ebee855bc0": {
"signature": "a2b4d032c59a9d1211d218c3cd550cf8febb369941d70284d07d03ebee855bc0",
"bca629d8e7888af4116b013c6585b78d0908d248a80138339e0eb1620832eb10": {
"signature": "bca629d8e7888af4116b013c6585b78d0908d248a80138339e0eb1620832eb10",
"alternativeSignatures": [
"9feaec8a73b72e0d212c0e18d863e4fe16ff010c5d33cf8d47d8b0f465cc4c5e"
"f35d63032e4f346c1afcc299d50eb17a0a05ecea81ba3025f14c7fbf78b10100"
],
"memberOf": [
"default"
],
"justification": "Reference to find first set bit function.",
"createdDate": "2023-02-22 23:55:29Z"
},
"1c87b45a6044d205dc3f3562f349c238f7cabe22b4609da762df9dc44151e9fb": {
"signature": "1c87b45a6044d205dc3f3562f349c238f7cabe22b4609da762df9dc44151e9fb",
"dc43990fd9fa6a44f2fb2fffcb0497571af4379f23090482035d79a98970e7ae": {
"signature": "dc43990fd9fa6a44f2fb2fffcb0497571af4379f23090482035d79a98970e7ae",
"alternativeSignatures": [
"9feaec8a73b72e0d212c0e18d863e4fe16ff010c5d33cf8d47d8b0f465cc4c5e"
"f35d63032e4f346c1afcc299d50eb17a0a05ecea81ba3025f14c7fbf78b10100"
],
"memberOf": [
"default"
],
"justification": "Reference to find first set bit function.",
"createdDate": "2023-02-22 23:55:29Z"
},
"a6639098c4785509a4215c9e2fc10f82c06fce461915dc11a00227ddec558845": {
"signature": "a6639098c4785509a4215c9e2fc10f82c06fce461915dc11a00227ddec558845",
"eb60d4f1e48ca85ad5fa4a413d8ff76c4975bccb12931f51179d67c24a82f354": {
"signature": "eb60d4f1e48ca85ad5fa4a413d8ff76c4975bccb12931f51179d67c24a82f354",
"alternativeSignatures": [
"9feaec8a73b72e0d212c0e18d863e4fe16ff010c5d33cf8d47d8b0f465cc4c5e"
"f35d63032e4f346c1afcc299d50eb17a0a05ecea81ba3025f14c7fbf78b10100"
],
"memberOf": [
"default"
],
"justification": "Reference to find first set bit function.",
"createdDate": "2023-02-22 23:55:29Z"
},
"f94ede7b396cb54934db2084f0879cd31a17ce2584eb01e0bfcd35324a724c31": {
"signature": "f94ede7b396cb54934db2084f0879cd31a17ce2584eb01e0bfcd35324a724c31",
"bb80a900ad96e4833eb7f54f55723a3425e846a290dd62b709d4714952cd9d45": {
"signature": "bb80a900ad96e4833eb7f54f55723a3425e846a290dd62b709d4714952cd9d45",
"alternativeSignatures": [
"9feaec8a73b72e0d212c0e18d863e4fe16ff010c5d33cf8d47d8b0f465cc4c5e"
"f35d63032e4f346c1afcc299d50eb17a0a05ecea81ba3025f14c7fbf78b10100"
],
"memberOf": [
"default"
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@
[submodule "external/constexpr-xxh3"]
path = external/constexpr-xxh3
url = https://github.com/chys87/constexpr-xxh3.git
[submodule "external/libunwind"]
path = external/libunwind
url = https://github.com/libunwind/libunwind.git
branch = master
6 changes: 6 additions & 0 deletions Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
<IgnoreMaxMonoVersion Condition=" '$(IgnoreMaxMonoVersion)' == '' ">True</IgnoreMaxMonoVersion>
<OpenTKSourceDirectory>$(MSBuildThisFileDirectory)external\opentk</OpenTKSourceDirectory>
<SqliteSourceDirectory Condition=" '$(SqliteSourceDirectory)' == '' ">$(MSBuildThisFileDirectory)external\sqlite</SqliteSourceDirectory>
<LibUnwindSourceDirectory Condition=" '$(LibUnwindSourceDirectory)' == '' ">$(MSBuildThisFileDirectory)external\libunwind</LibUnwindSourceDirectory>
<LibUnwindGeneratedHeadersDirectory Condition=" '$(LibUnwindGeneratedHeadersDirectory)' == '' ">$(BootstrapOutputDirectory)\libunwind</LibUnwindGeneratedHeadersDirectory>
<LZ4SourceDirectory Condition=" '$(LZ4SourceDirectory)' == '' ">$(MSBuildThisFileDirectory)external\lz4</LZ4SourceDirectory>
<XamarinAndroidSourcePath>$(MSBuildThisFileDirectory)</XamarinAndroidSourcePath>
<ThirdPartySourcePath>$(MSBuildThisFileDirectory)src-ThirdParty\</ThirdPartySourcePath>
<AllSupported32BitTargetAndroidAbis>armeabi-v7a;x86</AllSupported32BitTargetAndroidAbis>
Expand Down Expand Up @@ -144,6 +147,9 @@
<JavaInteropFullPath>$([System.IO.Path]::GetFullPath ('$(JavaInteropSourceDirectory)'))</JavaInteropFullPath>
<MonoSourceFullPath>$([System.IO.Path]::GetFullPath ('$(MonoSourceDirectory)'))</MonoSourceFullPath>
<SqliteSourceFullPath>$([System.IO.Path]::GetFullPath ('$(SqliteSourceDirectory)'))</SqliteSourceFullPath>
<LibUnwindSourceFullPath>$([System.IO.Path]::GetFullPath ('$(LibUnwindSourceDirectory)'))</LibUnwindSourceFullPath>
<LibUnwindGeneratedHeadersFullPath>$([System.IO.Path]::GetFullPath ('$(LibUnwindGeneratedHeadersDirectory)'))</LibUnwindGeneratedHeadersFullPath>
<LZ4SourceFullPath>$([System.IO.Path]::GetFullPath ('$(LZ4SourceDirectory)'))</LZ4SourceFullPath>
<OpenTKSourceFullPath>$([System.IO.Path]::GetFullPath ('$(OpenTKSourceDirectory)'))</OpenTKSourceFullPath>
<JavaInteropTargetFrameworkVersion>net8.0</JavaInteropTargetFrameworkVersion>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Android.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.Diagnost
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.Cecil", "external\Java.Interop\src\Java.Interop.Tools.Cecil\Java.Interop.Tools.Cecil.csproj", "{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "monodroid", "src\monodroid\monodroid.csproj", "{53EE4C57-1C03-405A-8243-8DA539546C88}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "native", "src\native\native.csproj", "{53EE4C57-1C03-405A-8243-8DA539546C88}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}"
EndProject
Expand Down
1 change: 0 additions & 1 deletion build-tools/cmake/xa_common.cmake

This file was deleted.

Loading

0 comments on commit a7b5768

Please sign in to comment.