From d3d28f0623ea047702d2579df42ba0c09a6689a7 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 30 Jan 2022 07:11:51 -0800 Subject: [PATCH] Update to NDK r23b Credits: @yujincheng08 Close #5193 --- build.py | 4 +-- gradle.properties | 4 +-- native/jni/Application.mk | 9 ++++-- native/jni/external/busybox | 2 +- native/jni/external/libcxx | 2 +- .../external/systemproperties/prop_area.cpp | 8 ++--- native/jni/init/twostage.cpp | 8 ----- native/jni/lto_fix.lds | 12 +++++++ native/jni/utils/misc.hpp | 2 +- native/jni/utils/missing.cpp | 31 ++++++++++++++++--- 10 files changed, 55 insertions(+), 27 deletions(-) create mode 100644 native/jni/lto_fix.lds diff --git a/build.py b/build.py index 849abc7b0..2024e8c46 100755 --- a/build.py +++ b/build.py @@ -405,7 +405,7 @@ def cleanup(args): def setup_ndk(args): os_name = platform.system().lower() ndk_ver = config['ndkVersion'] - url = f'https://dl.google.com/android/repository/android-ndk-r{ndk_ver}-{os_name}-x86_64.zip' + url = f'https://dl.google.com/android/repository/android-ndk-r{ndk_ver}-{os_name}.zip' ndk_zip = url.split('/')[-1] header(f'* Downloading {ndk_zip}') @@ -417,7 +417,7 @@ def setup_ndk(args): with zipfile.ZipFile(ndk_zip, 'r') as zf: for info in zf.infolist(): vprint(f'Extracting {info.filename}') - if info.external_attr == 2716663808: # symlink + if info.external_attr >> 28 == 0xA: # symlink src = zf.read(info).decode("utf-8") dest = op.join(ndk_root, info.filename) os.symlink(src, dest) diff --git a/gradle.properties b/gradle.properties index ed0d8164c..82ea5e669 100644 --- a/gradle.properties +++ b/gradle.properties @@ -29,5 +29,5 @@ android.nonTransitiveRClass=true # Magisk magisk.stubVersion=24 magisk.versionCode=24101 -magisk.ndkVersion=21e -magisk.fullNdkVersion=21.4.7075529 +magisk.ndkVersion=23b +magisk.fullNdkVersion=23.1.7779620 diff --git a/native/jni/Application.mk b/native/jni/Application.mk index c772cbe69..e06a38703 100644 --- a/native/jni/Application.mk +++ b/native/jni/Application.mk @@ -1,15 +1,18 @@ APP_ABI := armeabi-v7a arm64-v8a x86 x86_64 APP_CFLAGS := -Wall -Oz -fomit-frame-pointer -flto APP_LDFLAGS := -flto -APP_CPPFLAGS := -std=c++17 +APP_CPPFLAGS := -std=c++20 APP_STL := none APP_PLATFORM := android-21 APP_THIN_ARCHIVE := true APP_STRIP_MODE := --strip-all +ifndef B_SHARED +# Fix static variables' ctor/dtor when using LTO +# See: https://github.com/android/ndk/issues/1461 +APP_LDFLAGS += -T jni/lto_fix.lds ifneq ($(TARGET_ARCH),arm64) ifneq ($(TARGET_ARCH),x86_64) -ifndef B_SHARED # Disable fortify on static 32-bit targets APP_CFLAGS += -D_FORTIFY_SOURCE=0 -Wno-macro-redefined endif @@ -18,7 +21,7 @@ endif # Busybox should use stock libc.a ifdef B_BB -APP_PLATFORM := android-22 +APP_PLATFORM := android-24 ifeq ($(OS),Windows_NT) APP_SHORT_COMMANDS := true endif diff --git a/native/jni/external/busybox b/native/jni/external/busybox index c4f0c98ae..e68ef0927 160000 --- a/native/jni/external/busybox +++ b/native/jni/external/busybox @@ -1 +1 @@ -Subproject commit c4f0c98aeb9902aff5104a7519261022709d26a5 +Subproject commit e68ef0927385fb72a3fd414e206f915f4517b79f diff --git a/native/jni/external/libcxx b/native/jni/external/libcxx index b74fd5905..0aa67c3ff 160000 --- a/native/jni/external/libcxx +++ b/native/jni/external/libcxx @@ -1 +1 @@ -Subproject commit b74fd5905f1064c1a33b213fca58b45441651ad1 +Subproject commit 0aa67c3ffea069bdb58fe3b5e7aad06934afb292 diff --git a/native/jni/external/systemproperties/prop_area.cpp b/native/jni/external/systemproperties/prop_area.cpp index 77722bb08..36eac7fb9 100644 --- a/native/jni/external/systemproperties/prop_area.cpp +++ b/native/jni/external/systemproperties/prop_area.cpp @@ -384,21 +384,21 @@ bool prop_area::prune_node(prop_bt * const node) { bool is_leaf = true; if (atomic_load_explicit(&node->children, memory_order_relaxed) != 0) { if (prune_node(to_prop_bt(&node->children))) { - atomic_store_explicit(&node->children, 0, memory_order_release); + atomic_store_explicit(&node->children, 0u, memory_order_release); } else { is_leaf = false; } } if (atomic_load_explicit(&node->left, memory_order_relaxed) != 0) { if (prune_node(to_prop_bt(&node->left))) { - atomic_store_explicit(&node->left, 0, memory_order_release); + atomic_store_explicit(&node->left, 0u, memory_order_release); } else { is_leaf = false; } } if (atomic_load_explicit(&node->right, memory_order_relaxed) != 0) { if (prune_node(to_prop_bt(&node->right))) { - atomic_store_explicit(&node->right, 0, memory_order_release); + atomic_store_explicit(&node->right, 0u, memory_order_release); } else { is_leaf = false; } @@ -425,7 +425,7 @@ bool prop_area::rm(const char *name, bool trim_node) { } // De-reference the existing property ASAP - atomic_store_explicit(&node->prop, 0, memory_order_release); + atomic_store_explicit(&node->prop, 0u, memory_order_release); if (info) { // Wipe out the old info diff --git a/native/jni/init/twostage.cpp b/native/jni/init/twostage.cpp index ad8db1aef..1863378ee 100644 --- a/native/jni/init/twostage.cpp +++ b/native/jni/init/twostage.cpp @@ -1,11 +1,3 @@ -// Force using legacy_signal_inlines.h -#define __ANDROID_API_BACKUP__ __ANDROID_API__ -#undef __ANDROID_API__ -#define __ANDROID_API__ 20 -#include -#undef __ANDROID_API__ -#define __ANDROID_API__ __ANDROID_API_BACKUP__ - #include #include #include diff --git a/native/jni/lto_fix.lds b/native/jni/lto_fix.lds new file mode 100644 index 000000000..7f329730f --- /dev/null +++ b/native/jni/lto_fix.lds @@ -0,0 +1,12 @@ +SECTIONS { + .init_array : { + *(SORT_BY_INIT_PRIORITY(.init_array.*)) + *(EXCLUDE_FILE(*crtend_android.o) .init_array) + } +} INSERT AFTER .fini_array; +SECTIONS { + .fini_array : { + *(SORT_BY_INIT_PRIORITY(.fini_array.*)) + *(EXCLUDE_FILE(*crtend_android.o) .fini_array) + } +} INSERT BEFORE .init_array; diff --git a/native/jni/utils/misc.hpp b/native/jni/utils/misc.hpp index 9e1916ec4..de422af63 100644 --- a/native/jni/utils/misc.hpp +++ b/native/jni/utils/misc.hpp @@ -175,8 +175,8 @@ template void exec_command_async(Args &&...args) { const char *argv[] = {args..., nullptr}; exec_t exec { + .fork = fork_dont_care, .argv = argv, - .fork = fork_dont_care }; exec_command(exec); } diff --git a/native/jni/utils/missing.cpp b/native/jni/utils/missing.cpp index 41f3d1e8f..c4c11156f 100644 --- a/native/jni/utils/missing.cpp +++ b/native/jni/utils/missing.cpp @@ -10,8 +10,8 @@ extern "C" { -/* Original source: https://github.com/freebsd/freebsd/blob/master/contrib/file/src/getline.c - * License: BSD, full copyright notice please check original source */ +// Original source: https://github.com/freebsd/freebsd/blob/master/contrib/file/src/getline.c +// License: BSD, full copyright notice please check original source ssize_t getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp) { char *ptr, *eptr; @@ -53,8 +53,8 @@ ssize_t getline(char **buf, size_t *bufsiz, FILE *fp) { return getdelim(buf, bufsiz, '\n', fp); } -/* Original source: https://android.googlesource.com/platform/bionic/+/master/libc/bionic/mntent.cpp - * License: AOSP, full copyright notice please check original source */ +// Original source: https://android.googlesource.com/platform/bionic/+/master/libc/bionic/mntent.cpp +// License: AOSP, full copyright notice please check original source struct mntent *getmntent_r(FILE *fp, struct mntent *e, char *buf, int buf_len) { memset(e, 0, sizeof(*e)); @@ -143,7 +143,28 @@ int ftruncate64(int fd, off64_t length) { #endif #if !defined(__LP64__) -void android_set_abort_message(const char *msg) {} +void android_set_abort_message(const char *) {} + +// Original source: +int sigaddset(sigset_t *set, int signum) { + /* Signal numbers start at 1, but bit positions start at 0. */ + int bit = signum - 1; + auto *local_set = (unsigned long *)set; + if (set == nullptr || bit < 0 || bit >= (int)(8 * sizeof(sigset_t))) { + errno = EINVAL; + return -1; + } + local_set[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT); + return 0; +} +int sigemptyset(sigset_t *set) { + if (set == nullptr) { + errno = EINVAL; + return -1; + } + memset(set, 0, sizeof(sigset_t)); + return 0; +} #endif } // extern "C"