From 028709cbe7d9ae196e5fe67300ff1c818af7cc3c Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Mon, 24 Jul 2023 22:51:51 +0200 Subject: [PATCH 1/7] Bump NDK to r26 Changes: https://github.com/android/ndk/wiki/Changelog-r26#announcements NDK r26 has the following changes which are interesting to us: * libc++ has been updated. The NDK's libc++ now comes directly from our LLVM toolchain, so every future LLVM update is also a libc++ update. * Updated LLVM to clang-r487747c, based on LLVM 17 development The `libc++` update brings internal implementation changes, and as the result we no longer need to partially instantiate a couple of classes previously underlying the `vector` and `basic_string` implementations. --- .../xaprepare/ConfigAndData/BuildAndroidPlatforms.cs | 4 ++-- src/monodroid/CMakeLists.txt | 1 - src/monodroid/jni/cxx-abi/string.cc | 1 - src/monodroid/jni/cxx-abi/vector.cc | 12 ------------ 4 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 src/monodroid/jni/cxx-abi/vector.cc diff --git a/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs b/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs index b721305778b..f539d2d5263 100644 --- a/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs +++ b/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs @@ -5,8 +5,8 @@ namespace Xamarin.Android.Prepare { class BuildAndroidPlatforms { - public const string AndroidNdkVersion = "25c"; - public const string AndroidNdkPkgRevision = "25.2.9519653"; + public const string AndroidNdkVersion = "26-beta1"; + public const string AndroidNdkPkgRevision = "26.0.10404224-beta1"; public const int NdkMinimumAPI = 21; public const int NdkMinimumAPILegacy32 = 19; diff --git a/src/monodroid/CMakeLists.txt b/src/monodroid/CMakeLists.txt index 1e36816bed3..b0c29911830 100644 --- a/src/monodroid/CMakeLists.txt +++ b/src/monodroid/CMakeLists.txt @@ -521,7 +521,6 @@ if(ANDROID) ${BIONIC_SOURCES_DIR}/cxa_guard.cc ${SOURCES_DIR}/cxx-abi/string.cc ${SOURCES_DIR}/cxx-abi/terminate.cc - ${SOURCES_DIR}/cxx-abi/vector.cc ) endif() else() diff --git a/src/monodroid/jni/cxx-abi/string.cc b/src/monodroid/jni/cxx-abi/string.cc index 53b5731defc..30d528e14ac 100644 --- a/src/monodroid/jni/cxx-abi/string.cc +++ b/src/monodroid/jni/cxx-abi/string.cc @@ -7,7 +7,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template class __attribute__ ((__visibility__("hidden"))) __basic_string_common; template class __attribute__ ((__visibility__("hidden"))) basic_string; _LIBCPP_END_NAMESPACE_STD diff --git a/src/monodroid/jni/cxx-abi/vector.cc b/src/monodroid/jni/cxx-abi/vector.cc deleted file mode 100644 index 277224ae0a5..00000000000 --- a/src/monodroid/jni/cxx-abi/vector.cc +++ /dev/null @@ -1,12 +0,0 @@ -// -// Defining the macro will make the the explicit instantations below truely hidden -// -#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS - -#include - -_LIBCPP_BEGIN_NAMESPACE_STD - -template class __attribute__ ((__visibility__("hidden"))) __vector_base_common; - -_LIBCPP_END_NAMESPACE_STD From e7b6e65bb07b1ca7e7bc0c4cae2ea17ea733a25f Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Tue, 25 Jul 2023 18:31:57 +0200 Subject: [PATCH 2/7] NDK r26 no longer has API-19, the minimum level is 21 --- .../Tests/Xamarin.Android.Build.Tests/Tasks/NdkUtilTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/NdkUtilTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/NdkUtilTests.cs index b5a8df827ac..25d67d0e4c5 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/NdkUtilTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/NdkUtilTests.cs @@ -41,7 +41,7 @@ public void TestNdkUtil () Assert.IsTrue (ndk.ValidateNdkPlatform (arch, enableLLVM: false)); Assert.AreEqual (0, errors.Count, "NdkTools.ValidateNdkPlatform should not have returned false."); int level = ndk.GetMinimumApiLevelFor (arch); - int expected = 19; + int expected = 21; Assert.AreEqual (expected, level, $"Min Api Level for {arch} should be {expected}."); var compilerNoQuotes = ndk.GetToolPath (NdkToolKind.CompilerC, arch, level); Assert.AreEqual (0, errors.Count, "NdkTools.GetToolPath should not have errored."); From b6f9c5f6f67ada8df957e87236097d35a812a1e5 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Tue, 25 Jul 2023 23:12:01 +0200 Subject: [PATCH 3/7] API 21 is the minimal one --- .../xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs b/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs index f539d2d5263..6b672772717 100644 --- a/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs +++ b/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs @@ -8,7 +8,7 @@ class BuildAndroidPlatforms public const string AndroidNdkVersion = "26-beta1"; public const string AndroidNdkPkgRevision = "26.0.10404224-beta1"; public const int NdkMinimumAPI = 21; - public const int NdkMinimumAPILegacy32 = 19; + public const int NdkMinimumAPILegacy32 = 21; public static readonly List AllPlatforms = new List { new AndroidPlatform (apiName: "", apiLevel: 1, platformID: "1"), From 65deb57a75900c47eace302ac2314db024fd7a07 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Mon, 4 Sep 2023 10:37:35 +0200 Subject: [PATCH 4/7] Bump NDK to rc1 --- .../xaprepare/ConfigAndData/BuildAndroidPlatforms.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs b/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs index 6b672772717..62776a06480 100644 --- a/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs +++ b/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs @@ -5,8 +5,8 @@ namespace Xamarin.Android.Prepare { class BuildAndroidPlatforms { - public const string AndroidNdkVersion = "26-beta1"; - public const string AndroidNdkPkgRevision = "26.0.10404224-beta1"; + public const string AndroidNdkVersion = "26-rc1"; + public const string AndroidNdkPkgRevision = "26.0.10636728"; public const int NdkMinimumAPI = 21; public const int NdkMinimumAPILegacy32 = 21; From 61dda75999a1541c7b981bca6234a95f68a58ff8 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Tue, 19 Sep 2023 16:41:51 +0200 Subject: [PATCH 5/7] Bump to the final NDK r26 release --- .../xaprepare/ConfigAndData/BuildAndroidPlatforms.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs b/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs index 62776a06480..442a897ef6a 100644 --- a/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs +++ b/build-tools/xaprepare/xaprepare/ConfigAndData/BuildAndroidPlatforms.cs @@ -5,8 +5,8 @@ namespace Xamarin.Android.Prepare { class BuildAndroidPlatforms { - public const string AndroidNdkVersion = "26-rc1"; - public const string AndroidNdkPkgRevision = "26.0.10636728"; + public const string AndroidNdkVersion = "26"; + public const string AndroidNdkPkgRevision = "26.0.10792818"; public const int NdkMinimumAPI = 21; public const int NdkMinimumAPILegacy32 = 21; From 0e608c4ed2c32c3ea383d23024f0b676f22699b5 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Tue, 19 Sep 2023 22:15:46 +0200 Subject: [PATCH 6/7] Prevent a build error on CI jni/reuse-threads.c(102,107): error GC3C66DD4: call to undeclared library function 'strerror' with type 'char *(int)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] jni/reuse-threads.c(302,36): error G59A96D9D: incompatible function pointer types passing 'int (void *)' to parameter of type 'void * _Nonnull (* _Nonnull)(void * _Nonnull)' [-Wincompatible-function-pointer-types] --- tests/Mono.Android-Tests/jni/reuse-threads.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/Mono.Android-Tests/jni/reuse-threads.c b/tests/Mono.Android-Tests/jni/reuse-threads.c index 07223a60f37..f8916226d88 100644 --- a/tests/Mono.Android-Tests/jni/reuse-threads.c +++ b/tests/Mono.Android-Tests/jni/reuse-threads.c @@ -75,6 +75,7 @@ #include #include #include +#include #include #include #include @@ -206,15 +207,18 @@ rt_invoke_callback_on_new_thread (CB cb) return 0; } +static int _register_retval = 0; + /* We return -2 for errors, because -1 is reserved for the pthreads PTHREAD_CANCELED special value, indicating that the * thread was canceled. */ -static int +static void _register_type_from_new_thread (void *data) { RegisterFromThreadContext *context = (RegisterFromThreadContext*)data; if (context == NULL) { - return -100; + _register_retval = -100; + pthread_exit (&_register_retval); } JNIEnv *env = _get_env ("_register_type_from_new_thread"); @@ -227,7 +231,8 @@ _register_type_from_new_thread (void *data) (*env)->ExceptionClear (env); } - return -101; + _register_retval = -101; + pthread_exit (&_register_retval); } int ret = 0; @@ -286,7 +291,8 @@ _register_type_from_new_thread (void *data) cleanup: (*env)->PopLocalFrame (env, NULL); - return ret; + _register_retval = ret; + pthread_exit (&_register_retval); } JNIEXPORT int JNICALL From 24301bba6bd35ce2bf164a51b64b6b7baf3c1cc7 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Wed, 20 Sep 2023 09:08:32 +0200 Subject: [PATCH 7/7] Fixlets Fix a typo in function return type and go back to `return` statements with proper casts. Fix some compiler warnings --- tests/Mono.Android-Tests/jni/reuse-threads.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/Mono.Android-Tests/jni/reuse-threads.c b/tests/Mono.Android-Tests/jni/reuse-threads.c index f8916226d88..a88574d94c0 100644 --- a/tests/Mono.Android-Tests/jni/reuse-threads.c +++ b/tests/Mono.Android-Tests/jni/reuse-threads.c @@ -211,14 +211,13 @@ static int _register_retval = 0; /* We return -2 for errors, because -1 is reserved for the pthreads PTHREAD_CANCELED special value, indicating that the * thread was canceled. */ -static void +static void* _register_type_from_new_thread (void *data) { RegisterFromThreadContext *context = (RegisterFromThreadContext*)data; if (context == NULL) { - _register_retval = -100; - pthread_exit (&_register_retval); + return (void*)(intptr_t)-100; } JNIEnv *env = _get_env ("_register_type_from_new_thread"); @@ -231,8 +230,7 @@ _register_type_from_new_thread (void *data) (*env)->ExceptionClear (env); } - _register_retval = -101; - pthread_exit (&_register_retval); + return (void*)(intptr_t)-101; } int ret = 0; @@ -291,8 +289,7 @@ _register_type_from_new_thread (void *data) cleanup: (*env)->PopLocalFrame (env, NULL); - _register_retval = ret; - pthread_exit (&_register_retval); + return (void*)(intptr_t)ret; } JNIEXPORT int JNICALL @@ -318,10 +315,10 @@ rt_register_type_on_new_thread (const char *java_type_name, jobject class_loader return -201; } - if ((int)tr == -1 /* PTHREAD_CANCELED - not defined in bionic */) { + if ((int)(intptr_t)tr == -1 /* PTHREAD_CANCELED - not defined in bionic */) { __android_log_print (ANDROID_LOG_INFO, "XA/RuntimeTest", "RegisterOnNewThread: worker thread was canceled"); return -202; } - return (int)tr; + return (int)(intptr_t)tr; }