There are cases where one might want to run programs with the GNU ABI on
an Android device, such as running Gentoo Prefix inside an Android app
like Termux that provides a POSIX-like environment. This mostly works
out-of-the-box; however, there are certain edge cases when running on a
system with an Android kernel/userspace. Most notably, only certain
syscalls are allowed under Android's seccomp policy, with all others
blocked by default, even if the kernel would otherwise support it.
Glibc's modus operandi when running under Linux is to try to perform the
newer syscall first, and if it is not supported by the kernel, fall back
to the older implementation. Under this seccomp policy this doesn't
work, and programs are simply terminated without being given a chance to
fall back. To make Glibc and other software avoid performing these
syscalls when running Android, we must let them know at configure time
that the target system does not allow performing these syscalls. Setting
the vendor to "android" lets us tell the software that even though the
GNU ABI is in effect, certain restrictions are present due to running on
Android.

Android only supports aarch64, arm, i*86 and x86_64 arches, therefore
the vendor is only set there.

* config.guess (*-android-linux-*): Recognize.

Signed-off-by: sin-ack <sin-...@protonmail.com>
---
 config.guess | 36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/config.guess b/config.guess
index 48a6846..f3407f6 100755
--- a/config.guess
+++ b/config.guess
@@ -4,7 +4,7 @@
 
 # shellcheck disable=SC2006,SC2268 # see below for rationale
 
-timestamp='2024-07-27'
+timestamp='2025-04-05'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -191,6 +191,20 @@ Linux|GNU|GNU/*)
        if [ "$LIBC" = unknown ]; then
                LIBC=gnu
        fi
+
+    # Check if we're actually running on an Android system. It's possible that 
the user
+    # wants to use the GNU ABI, but is actually running on Android. There is a 
certain
+    # amount of caution that must be taken due to the seccomp policy present 
on Android
+    # systems, which prevents certain syscalls from being even attempted, thus 
we must
+    # differentiate between a regular Linux system and Android.
+    VENDOR=unknown
+    if test -c "/dev/ashmem"; then
+        # /dev/ashmem is an Android-specific shared memory device.
+        VENDOR=android
+    elif test -f "/system/bin/linker"; then
+        # The Android dynamic linker must always be present on Android systems.
+        VENDOR=android
+    fi
        ;;
 esac
 
@@ -1004,11 +1018,11 @@ EOF
                eabi | eabihf) CPU=armv8l; LIBCABI=$LIBC$ABI ;;
            esac
        fi
-       GUESS=$CPU-unknown-linux-$LIBCABI
+       GUESS=$CPU-$VENDOR-linux-$LIBCABI
        ;;
     aarch64_be:Linux:*:*)
        UNAME_MACHINE=aarch64_be
-       GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
+       GUESS=$UNAME_MACHINE-$VENDOR-linux-$LIBC
        ;;
     alpha:Linux:*:*)
        case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 
2>/dev/null` in
@@ -1032,14 +1046,14 @@ EOF
        if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
            | grep -q __ARM_EABI__
        then
-           GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
+               GUESS=$UNAME_MACHINE-$VENDOR-linux-$LIBC
        else
            if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
                | grep -q __ARM_PCS_VFP
            then
-               GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi
+               GUESS=$UNAME_MACHINE-$VENDOR-linux-${LIBC}eabi
            else
-               GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf
+               GUESS=$UNAME_MACHINE-$VENDOR-linux-${LIBC}eabihf
            fi
        fi
        ;;
@@ -1062,7 +1076,10 @@ EOF
        GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
        ;;
     i*86:Linux:*:*)
-       GUESS=$UNAME_MACHINE-pc-linux-$LIBC
+       if [ "$VENDOR" = unknown ]; then
+               VENDOR=pc
+       fi
+       GUESS=$UNAME_MACHINE-$VENDOR-linux-$LIBC
        ;;
     ia64:Linux:*:*)
        GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
@@ -1214,7 +1231,10 @@ EOF
                x32) LIBCABI=${LIBC}x32 ;;
            esac
        fi
-       GUESS=$CPU-pc-linux-$LIBCABI
+       if [ "$VENDOR" = unknown ]; then
+               VENDOR=pc
+       fi
+       GUESS=$CPU-$VENDOR-linux-$LIBCABI
        ;;
     xtensa*:Linux:*:*)
        GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
-- 
2.45.3



  • [PATCH] config.guess: ... Patches for the config.guess and config.sub scripts

Reply via email to