Re: mempcpy on Android
On Sat, 3 Nov 2018 at 14:09, Bruno Haible wrote: > Reuben Thomas wrote: > > I'm compiling with clang natively in Termux. All the options are set by > > Termux. __ANDROID_API__ in particular is set by a Termux header that is > > included by most of the system headers, in this case string.h. The -L > > options again are all default. > > And the -L options apparently point to a library that contains mempcpy, > which means an Android API >= 23, although said Termux header defines > __ANDROID_API__ to a value < 23 ? That's an inconsistent setup that would > cause us an inordinate amount of effort to support. > Thanks. I dug around but neither searching online or in the Termux packaging code reveals how Termux's version of the NDK selects the API level of the libc. (Unless the situation is that there's only one? In which case the solution would be to set `__ANDROID_API__` to match it, as per this issue: https://github.com/termux/termux-packages/issues/2469 ) If you have any knowledge about this it would be good to know! For the moment my workaround is to configure projects with `CPPFLAGS=-D__ANDROID_API__=`. -- https://rrt.sc3d.org
Re: mempcpy on Android
Reuben Thomas wrote: > I'm compiling with clang natively in Termux. All the options are set by > Termux. __ANDROID_API__ in particular is set by a Termux header that is > included by most of the system headers, in this case string.h. The -L > options again are all default. And the -L options apparently point to a library that contains mempcpy, which means an Android API >= 23, although said Termux header defines __ANDROID_API__ to a value < 23 ? That's an inconsistent setup that would cause us an inordinate amount of effort to support. You are better off using either a cross-compilation environment, or correcting the -L options of clang so that they point to a native library that matches the header. Bruno
Re: mempcpy on Android
On Sat, 3 Nov 2018, 12:28 Bruno Haible Reuben Thomas wrote: > > > You need to use the same Android API value in > > > - the -D__ANDROID_API__=${ANDROID_API} option > > > - the > > > > -B${ANDROID_SDK}/ndk-bundle/platforms/android-${ANDROID_API}/arch-arm/usr/lib > > > option > > > > > > as I showed in the intialization script. > > > > > > > Since I'm not setting the API version at all, that implies there's a bug > in > > the configuration of Termux? > > How does your compilation environment look like? > Do you compile natively inside Termux? Or do you do a cross-compilation? > Are you using gcc or clang? > Who has defined the __ANDROID_API__ value and the -L options in your > compilation environment? > I'm compiling with clang natively in Termux. All the options are set by Termux. __ANDROID_API__ in particular is set by a Termux header that is included by most of the system headers, in this case string.h. The -L options again are all default.
Re: mempcpy on Android
Reuben Thomas wrote: > > You need to use the same Android API value in > > - the -D__ANDROID_API__=${ANDROID_API} option > > - the > > -B${ANDROID_SDK}/ndk-bundle/platforms/android-${ANDROID_API}/arch-arm/usr/lib > > option > > > > as I showed in the intialization script. > > > > Since I'm not setting the API version at all, that implies there's a bug in > the configuration of Termux? How does your compilation environment look like? Do you compile natively inside Termux? Or do you do a cross-compilation? Are you using gcc or clang? Who has defined the __ANDROID_API__ value and the -L options in your compilation environment? Bruno
Re: mempcpy on Android
[Re-adding bug-gnulib, sorry!] On Sat, 3 Nov 2018, 11:32 Bruno Haible > > Could it be that the Android libraries that you are linking with are > not > > > in sync with the __ANDROID_API__ that you set? > > > > > > > That's right. I use the default Termux setting of __ANDROID_API__. I > > presume this is made so that binaries will work on earlier versions of > > Android. > > You need to use the same Android API value in > - the -D__ANDROID_API__=${ANDROID_API} option > - the > -B${ANDROID_SDK}/ndk-bundle/platforms/android-${ANDROID_API}/arch-arm/usr/lib > option > > as I showed in the intialization script. > Since I'm not setting the API version at all, that implies there's a bug in the configuration of Termux?
Re: mempcpy on Android
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