From f25639596a289544da8190fdda995e423dcc3dd7 Mon Sep 17 00:00:00 2001 From: turistu <128076160+turistu@users.noreply.github.com> Date: Sat, 15 Apr 2023 11:30:25 +0300 Subject: [PATCH 1/6] fix build with CC=ANDROID-NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang ./configure .. when determining the compiler for -m32 on aarch64, first look for one similarly named with s/aarch64/armv7a/ and s/android/&eabi/ --- configure.ac | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index b43c6f630..32ca6c81f 100644 --- a/configure.ac +++ b/configure.ac @@ -770,23 +770,28 @@ Valid options are: yes, no, check, m32, mx32.]) [enable_mpers=yes]) AS_IF([test x$arch = xaarch64], - [# So far, only aarch64 needs a separate compiler for its compat - # personality (which is AArch32, that is more or less ARMv7 EABI) - # - # Some heuristics regarding possible compiler name: - # Debian: arm-linux-gnueabi{,hf}-gcc - # SuSE: arm7{,hl}-linux-gnueabi-gcc - # Red Hat: arm-redhat-linux-gnu-gcc - # Fedora: arm-linux-gnu-gcc - # ALT: armh-alt-linux-gnueabi-gcc - m4_foreach([triplet1], [arm, arm7, arm7hl, armh], dnl - [m4_foreach([triplet2], [, $host_vendor-], dnl - [m4_foreach([triplet3], [gnu, gnueabi, gnueabihf], dnl - [m4_foreach([triplet_cc], [gcc, cc], dnl - [m4_append([arm_compat_compilers], dnl - triplet1[-]triplet2[linux-]triplet3[-]triplet_cc)])])])]) - AC_CHECK_PROGS(CC_FOR_M32, arm_compat_compilers) - AS_IF([test -n "$CC_FOR_M32"], + [# So far, only aarch64 needs a separate compiler for its compat + # personality (which is AArch32, that is more or less ARMv7 EABI) + # First try $CC with 'aarch64' replaced with 'arm' and 'android' + # replaced with 'androideabi' + cc=${CC%/aarch64-*}/armv7a-${CC##*/aarch64-} + cc=${cc%-android*}-androideabi${cc##*-android} + AS_IF([$cc --version >/dev/null],[CC_FOR_M32=$cc],[ + # Some heuristics regarding possible compiler name: + # Debian: arm-linux-gnueabi{,hf}-gcc + # SuSE: arm7{,hl}-linux-gnueabi-gcc + # Red Hat: arm-redhat-linux-gnu-gcc + # Fedora: arm-linux-gnu-gcc + # ALT: armh-alt-linux-gnueabi-gcc + m4_foreach([triplet1], [arm, arm7, arm7hl, armh], dnl + [m4_foreach([triplet2], [, $host_vendor-], dnl + [m4_foreach([triplet3], [gnu, gnueabi, gnueabihf], dnl + [m4_foreach([triplet_cc], [gcc, cc], dnl + [m4_append([arm_compat_compilers], dnl + triplet1[-]triplet2[linux-]triplet3[-]triplet_cc)])])])]) + AC_CHECK_PROGS(CC_FOR_M32, arm_compat_compilers)]) + AS_UNSET(cc) + AS_IF([test -n "$CC_FOR_M32"], [: ${CPP_FOR_M32=$CC_FOR_M32 -E} : ${CFLAGS_FOR_M32=-std=gnu99} : ${CPPFLAGS_FOR_M32=} From 7ec3cc6786f242c75c35f2259e7f054b92a90cc4 Mon Sep 17 00:00:00 2001 From: turistu <128076160+turistu@users.noreply.github.com> Date: Sat, 15 Apr 2023 11:32:14 +0300 Subject: [PATCH 2/6] fix build with CC=ANDROID-NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang ./configure .. header include hell --- src/defs.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/defs.h b/src/defs.h index 9376d8f30..49bf2c9ce 100644 --- a/src/defs.h +++ b/src/defs.h @@ -914,7 +914,7 @@ str_strip_prefix_len(const char *str, const char *prefix, size_t prefix_len) * part. */ # define QUOTE_HEXSTR_MASK (0x3 << QUOTE_HEXSTR_SHIFT) -static_assert((NUM_HEXSTR_OPTS - 1) <= (QUOTE_HEXSTR_MASK >> QUOTE_HEXSTR_SHIFT), +_Static_assert((NUM_HEXSTR_OPTS - 1) <= (QUOTE_HEXSTR_MASK >> QUOTE_HEXSTR_SHIFT), "xflag options do not fit into QUOTE_HEXSTR_MASK"); # define QUOTE_HEXSTR_NONE (HEXSTR_NONE << QUOTE_HEXSTR_SHIFT) @@ -2158,4 +2158,15 @@ print_big_u64_addr(const uint64_t addr) # include "syscall.h" # endif +#ifdef __ANDROID__ +/* pulled in by stdio.h, clash with bundled/linux/include/uapi/linux/fs.h */ +#undef RENAME_EXCHANGE +#undef RENAME_WHITEOUT +#undef RENAME_NOREPLACE + +/* defined in linux/in.h on android; shadowed by its bundled/... counterpart */ +typedef uint32_t in_addr_t; + +#endif + #endif /* !STRACE_DEFS_H */ From fe1b2207af87042f04cd5594c02f69d1fca58d01 Mon Sep 17 00:00:00 2001 From: turistu <128076160+turistu@users.noreply.github.com> Date: Sat, 15 Apr 2023 11:32:58 +0300 Subject: [PATCH 3/6] fix build with CC=ANDROID-NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang ./configure .. fix the errors triggered by -Wundef and -Wunused- with -Werror --- src/sigreturn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sigreturn.c b/src/sigreturn.c index 996bd5540..474776eed 100644 --- a/src/sigreturn.c +++ b/src/sigreturn.c @@ -16,7 +16,7 @@ #endif /* The following function might be unused, hence the inline qualifier. */ -static inline void +static inline void __attribute__((unused)) print_sigmask_addr_size(const void *const addr, const unsigned int size) { tprint_struct_begin(); From 22c689075ee5e2c263f6e709135f56abd1b37eb8 Mon Sep 17 00:00:00 2001 From: turistu <128076160+turistu@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:51:02 +0300 Subject: [PATCH 4/6] kill mx32 personality support on android x86_64 keep only m32 when called with the -mx32 option, the ndk's clang cross compiler driver ends up running the system's gcc YUCK --- configure.ac | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 32ca6c81f..998f0cf9a 100644 --- a/configure.ac +++ b/configure.ac @@ -808,7 +808,10 @@ m4_foreach([pers], [M32, MX32], dnl AC_SUBST(var[_FOR_]pers)])]) st_MPERS([m32], [aarch64|powerpc64|s390x|sparc64|tile|x32|x86_64]) -st_MPERS([mx32], [x86_64]) +case $host_os in +linux-android*) st_MPERS([mx32], [none]);; +*) st_MPERS([mx32], [x86_64]) ;; +esac AC_ARG_ENABLE([install-tests], [AS_HELP_STRING([--enable-install-tests=yes|no], From 013f96691389ddda14cd64dbfede0ceb55a6a8a0 Mon Sep 17 00:00:00 2001 From: turistu <128076160+turistu@users.noreply.github.com> Date: Thu, 8 Aug 2024 03:16:38 +0300 Subject: [PATCH 5/6] The _Nonnull attribute from android's headers[1] in newer ndks (r27) breaks the get_cpu_size() kludge. "fix" it with another kludge [1] https://android-review.googlesource.com/c/platform/bionic/+/2496358/3/libc/include/sched.h --- src/affinity.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/affinity.c b/src/affinity.c index 7dacb4c40..52a67e9db 100644 --- a/src/affinity.c +++ b/src/affinity.c @@ -27,10 +27,17 @@ get_cpuset_size(void) * This undocumented kernel feature can be used to probe * the kernel and find out the minimal valid cpuset size * without allocating any memory for the CPU affinity mask. + * */ cpuset_size = 128; + /* + * As an extra kludge, use a dummy variable in order + * to dodge the _Nonnull pointer attribute from + * sched_getaffinity()'s declaration + */ + cpu_set_t *nullptr = NULL; while (cpuset_size && - sched_getaffinity(0, cpuset_size, NULL) == -1 && + sched_getaffinity(0, cpuset_size, nullptr) == -1 && EINVAL == errno) { cpuset_size <<= 1; } From cc343ea6ea34d57c1ac87f19f29a128ee24b38ee Mon Sep 17 00:00:00 2001 From: turistu <128076160+turistu@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:37:19 +0200 Subject: [PATCH 6/6] apparently they made "nullptr" a keyword in C23 use null_ptr instead --- src/affinity.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/affinity.c b/src/affinity.c index 52a67e9db..0ef5438df 100644 --- a/src/affinity.c +++ b/src/affinity.c @@ -35,9 +35,9 @@ get_cpuset_size(void) * to dodge the _Nonnull pointer attribute from * sched_getaffinity()'s declaration */ - cpu_set_t *nullptr = NULL; + cpu_set_t *null_ptr = NULL; while (cpuset_size && - sched_getaffinity(0, cpuset_size, nullptr) == -1 && + sched_getaffinity(0, cpuset_size, null_ptr) == -1 && EINVAL == errno) { cpuset_size <<= 1; }