bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mempcpy on Android


From: Bruno Haible
Subject: Re: mempcpy on Android
Date: Sat, 03 Nov 2018 10:45:36 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-137-generic; KDE/5.18.0; x86_64; ; )

Hi Reuben,

> I noticed a crash in a program using glob, on a line that calls mempcpy. I
> then noticed the following:
> 
> glob.c:836:21: warning: implicit declaration of function 'mempcpy' is
> invalid in C99 [-Wimplicit-function-declaration]
>                 d = mempcpy (dirname, p->pw_dir, home_len);
>                     ^
> glob.c:836:19: warning: incompatible integer to pointer conversion
> assigning to 'char *' from 'int' [-Wint-conversion]
>                 d = mempcpy (dirname, p->pw_dir, home_len);
>                   ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> (and a bunch of other warnings). So I think this explains the crash.
> 
> The reason this happens is that mempcpy is only declared in Android's
> string.h #if __ANDROID_API__ >= 23
> 
> I see that the availability of this and many other Android APIs is
> documented, but
> 
> The gnulib documentation mentions this feature of Bionic (Android's libc),
> but doesn't seem to do anything about it. I guess it needs to test whether
> all of these functions are declared, rather than merely whether they exist
> in libc? Something similar is already done for truncate (commit a0f15cb).
> 
> I am using Termux as my programming environment on Android, which defines
> __ANDROID_API__ to 21.

You should get a link error, not a crash, in this situation.
And m4/mempcpy.m4 relies on the link error, in order to detect that mempcpy
is missing.

Could it be that the Android libraries that you are linking with are not
in sync with the __ANDROID_API__ that you set?

I am using this script for compiling natively to Android 4.3:

===================== Initialization =====================
ANDROID_SDK=.../android/sdk
ANDROID_API=18 # See https://en.wikipedia.org/wiki/Android_version_history

PATH="${ANDROID_SDK}/cmake/3.6.4111459/bin:$PATH"
PATH="${ANDROID_SDK}/ndk-bundle/prebuilt/linux-x86_64/bin:$PATH"
PATH="${ANDROID_SDK}/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH"
PATH="${ANDROID_SDK}/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"

# Use GCC, not clang.
# Leads to compilation errors when using mmap and largefile:
# error: call to 'mmap' declared with attribute error: mmap is not available 
with _FILE_OFFSET_BITS=64 when using GCC until android-21. Either raise your 
minSdkVersion, disable _FILE_OFFSET_BITS=64, or switch to Clang.
CC="arm-linux-androideabi-gcc --sysroot=${ANDROID_SDK}/sdk/ndk-bundle/sysroot 
-isystem ${ANDROID_SDK}/ndk-bundle/sysroot/usr/include -isystem 
${ANDROID_SDK}/ndk-bundle/sysroot/usr/include/arm-linux-androideabi 
-B${ANDROID_SDK}/ndk-bundle/platforms/android-${ANDROID_API}/arch-arm/usr/lib 
-D__ANDROID_API__=${ANDROID_API}"
CXX="arm-linux-androideabi-g++ --sysroot=${ANDROID_SDK}/sdk/ndk-bundle/sysroot 
-isystem ${ANDROID_SDK}/ndk-bundle/sysroot/usr/include -isystem 
${ANDROID_SDK}/ndk-bundle/sysroot/usr/include/arm-linux-androideabi 
-B${ANDROID_SDK}/ndk-bundle/platforms/android-${ANDROID_API}/arch-arm/usr/lib 
-D__ANDROID_API__=${ANDROID_API}"
export CC CXX

===================== Configuration =====================
#!/bin/sh
if test -f configure; then
  dir='.'
else
  dir='..'
fi
${dir}/configure --prefix=/inst-android43 --host=arm-linux-androideabi \
                 CPPFLAGS="-I/inst-android43/include -Wall" \
                 LDFLAGS="-L/inst-android43/lib" \
                 "$@"

Bruno





reply via email to

[Prev in Thread] Current Thread [Next in Thread]