Why was exec_elf.h removed from the Android NDK? - android

Looking in Android NDK r12, I can see that there are differences in the header files under platforms/android-{API level}/{arch}/usr/include/sys. For API levels 19 and below, the file exec_elf.h exists, but appears to have been removed after that. There are a number of other differences where files were added or removed, but I'm interested in exec_elf.h because it defines a particular macro:
#define ELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
This macro is used in the ICU source, and my cross-compiled build of ICU fails if I use a toolchain with the API target set to anything after 19. The build fails with these errors:
arm-linux-androideabi-clang ... icu/source/tools/toolutil/pkg_genc.c
icu/source/tools/toolutil/pkg_genc.c:869:13: warning: implicit declaration of function 'ELF64_ST_INFO' is invalid in C99 [-Wimplicit-function-declaration]
ELF64_ST_INFO(STB_GLOBAL, STT_OBJECT),
^
icu/source/tools/toolutil/pkg_genc.c:869:13: error: initializer element is not a compile-time constant
ELF64_ST_INFO(STB_GLOBAL, STT_OBJECT),
^~~~~~~~~~~~~~~~~~~
icu/source/tools/toolutil/pkg_genc.c:987:13: error: initializer element is not a compile-time constant
ELF64_ST_INFO(STB_GLOBAL, STT_OBJECT),
The compile line is as follows:
android-toolchain/bin/arm-linux-androideabi-clang -D_REENTRANT -DU_HAVE_ELF_H=1 \
-DU_HAVE_ATOMIC=1 -Iicu/source/common -Iicu/source/i18n \
-DU_BUILD="x86_64-apple-darwin15.2.0" -DU_HOST="arm-unknown-linux-androideabi" \
-DU_CC="android-toolchain/bin/arm-linux-androideabi-clang" \
-DU_CXX="android-toolchain/bin/arm-linux-androideabi-clang++" \
-DUNISTR_FROM_CHAR_EXPLICIT=explicit -DUNISTR_FROM_STRING_EXPLICIT=explicit \
-DU_ATTRIBUTE_DEPRECATED= -DU_TOOLUTIL_IMPLEMENTATION -O3 -O2 -pipe -fsigned-char \
-fPIC -D__ANDROID__ -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -std=c99 \
-Wall -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -c \
-DPIC -fPIC -o pkg_genc.o icu/source/tools/toolutil/pkg_genc.c
I can get the build to succeed by adding the definition of ELF64_ST_INFO at the top of pkg_genc.c, so I'm pretty positive that the lack of the definition of this macro in the Android system headers is the issue. Does anyone know why this changed across API levels? Is this difference intentional, or is this a bug in the NDK?

This was a bug in the NDK. To illustrate the importance of filing bugs, this was filed 8 hours ago and we already have a fix going through presubmit: https://github.com/android-ndk/ndk/issues/377. The fix should be available in r15 beta 2, due out at I/O (17 May).

Related

Updating application with C++ native library to NDK 18, cmake isn't including required sysroot platform include directory

I have an Android application, developed with Android Studio, that is using a very old build system - NDK 14 with CMake 3.6 and AGP 3.5. I'm trying to update it to NDK 18 (I eventually want to update it to latest NDK, but baby steps) using CMake 3.18.1 and AGP 4.2.2 with Gradle 6.7.1, but the build fails due to errors finding a system include file asm/types.h.
Looking at the clang++ compile command that CMake generates, it is clearly missing the ${SYSROOT}/usr/include/<platform-abi> directory.
My CMake (which worked well for NDK 14 with CMake 3.6.1) has these lines:
if(${CMAKE_ANDROID_ARCH_ABI} STREQUAL arm64-v8a)
include_directories(${ANDROID_SYSROOT}/usr/include/aarch64-linux-android)
elseif(${CMAKE_ANDROID_ARCH_ABI} STREQUAL x86_64)
include_directories(${ANDROID_SYSROOT}/usr/include/x86_64-linux-android)
endif()
Running CMake with --trace-expand, I can see it correctly parses those lines:
…
… arm64Release|arm64-v8a :/home/…/myapp/mynativelib/CMakeLists.txt(5):
if(arm64-v8a STREQUAL arm64-v8a )
… arm64Release|arm64-v8a :/home/…/myapp/mynativelib/CMakeLists.txt(6):
include_directories(/home/…/Android/Sdk/ndk/18.1.5063045/sysroot/usr/include/aarch64-linux-android )
…
But the build.ninja file generated does not have this include directory - it contains compile directives that look like so:
build CMakeFiles/mynativelib.dir/home/…/mynativelib/MyClass.cpp.o: \
CXX_COMPILER__mynativelib_Debug /home/…/mynativelib/MyClass.cpp || \
cmake_object_order_depends_target_mynativelib
DEFINES = -DANDROID -DCMAKE_BUILD_TYPE=Debug -DDEBUG -DMIXIT=0 -DNDEBUG -DRELEASE=0 … -D__GXX_EXPERIMENTAL_CXX0X__ -D__STDC_CONSTANT_MACROS
DEP_FILE = CMakeFiles/mynativelib.dir/home/…/mynativelib/MyClass.cpp.o.d
FLAGS = -std=c++14 -fno-stack-protector -ffor-scope -fexceptions -O0 -fno-limit-debug-info \
-fPIC -fno-stack-protector -fpic -ffunction-sections -funwind-tables -no-canonical-prefixes \
-Os -fomit-frame-pointer -fomit-frame-pointer -UNDEBUG -fno-omit-frame-pointer -Ijni -Wformat \
-Wa,--noexecstack -fno-stack-protector -std=c++14
INCLUDES = -I/home/…/Android/Sdk/ndk/18.1.5063045/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/include \
-I../../../../../../../some-custom-include-from-cmake \
-isystem /home/…/Android/Sdk/ndk/18.1.5063045/sources/cxx-stl/llvm-libc++/include
-isystem /home/…/Android/Sdk/ndk/18.1.5063045/sources/cxx-stl/llvm-libc++abi/include
OBJECT_DIR = CMakeFiles/mynativelib.dir
OBJECT_FILE_DIR = CMakeFiles/mynativelib.dir/home/…/mynativelib
I can see that the build command include the some-custom-include-from-cmake include directory, that is added in my CMakeLists.txt file, as well as all the cxx-stl/llvm-libc++ includes that are also added in the CMakeLists.txt file, but the /usr/include/<android-abi> platform include dir is missing.
Even if I use the include_directories(${ANDROID_SYSROOT}/usr/include/aarch64-linux-android) command without the if check, right near where the other include_directories() commands that do make it into the build file, it is still missing from the build file. I even tried to add the -I flag directly using set(CMAKE_CXX_FLAGS) and that didn't cause the required include dir to be listed.
OTOH, if I change the include_directories(${ANDROID_SYSROOT}…) to be something that doesn't start with ${ANDROID_SYSROOT}, or points to a non-existing directory - then whatever I put there does make it to the build.ninja file.
Looks like something is very purposefully removing include directories that are in ${ANDROID_SYSROOT} maybe?

newlib.h: No such file or directory in ffmpeg

I am getting this error
/AppData/Local/Temp/ffconf.dkWUWsGo.c:1:20: fatal error: newlib.h: No such file or directory
#include <newlib.h>
while compiling for ffmpeg.
check_cpp_condition newlib.h defined _NEWLIB_VERSION check_cpp BEGIN
/tmp/ffconf.dkWUWsGo.c
1 #include
2 #if !(defined _NEWLIB_VERSION)
3 #error "unsatisfied condition: defined _NEWLIB_VERSION"
4 #endif END /tmp/ffconf.dkWUWsGo.c D:/android-ndk-r10b/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/arm-linux-androideabi-gcc
--sysroot=D:/android-ndk-r10b/platforms/android-8/arch-arm/ -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 -mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=armv7-a -march=armv7-a -std=c99 -E -o /tmp/ffconf.BMIcTDua.o /tmp/ffconf.dkWUWsGo.c C:/Users/vmewada/AppData/Local/Temp/ffconf.dkWUWsGo.c:1:20: fatal
error: newlib.h: No such file or directory #include
^ compilation terminated.
From the path you provided, I guess the file is not present there anymore, because the Temp folder is used for temporary files. Probably you opened an archive (.zip, .rar, .tar, .jar), and after you closed it, the temporary files were deleted. Extract the files to a permanent directory from where you can use them.
As far as I understand from the error log you are trying to cross compile FFmpeg for Android, but I am not sure if Android NDK has a prebuilt newlib version shipped with it. You could check the corresponding platform directory in NDK if it has the include or library, but my assumption is that you will have to build newlib for ARM before you can do this. Btw - last time I compiled FFmpeg for Android I didn't have the issues you got - are you using a correct target? Maybe the newlib is imported because of a wrong architecture.

how to force "./configure" to stop using -pthread during compilation?

I am trying to cross-compile something for Android, which has pthread support but does NOT use -pthread when compiling and linking. If you try to use -pthread, compilation using the cross-compiler will fail.
When trying to cross-compile something by first using the 'configure' tool, it keeps trying to use -pthread to do things like "check for gethostbyname" and therefore my configure fails:
configure:21229: checking for gethostbyname
configure:21229: /mnt/hgfs/Documents/thesis/android-wmon/core/android-wireshark/agcc \
-o conftest -D_U_="__attribute__((unused))" -g -O2 -Wall -W -Wextra \
-Wdeclaration-after-statement -Wendif-labels -Wpointer-arith \
-Wno-pointer-sign -Warray-bounds -Wcast-align -Wformat-security \
-fexcess-precision=fast -I/usr/local/include -pthread \
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
-I/usr/local/include -Wl,--as-needed -L/usr/local/lib conftest.c >&5
arm-eabi-gcc: error: unrecognized option '-pthread'
I cannot find where it picks up this flag from, and how I can get it to stop doing that. I do not see it in configure anywhere, so it must be dynamically generating it. I just can't seem to find where it does this so I can remove it from whatever variable it is stored within configure.
Well, it's a hack but it seems as though you can manipulate CFLAGS before it tries the link test:
ac_fn_c_try_link ()
{
CFLAGS="${CFLAGS/-pthread/}"
... that is in 'configure'

Cross compiling GCC with newlib for ARM: how to specify GCC options like -march?

I've compiled GCC along with newlib on Mac OS X for ARM targets. However, libc.a was compiled with -fshort-enums, and I don't want that because when I compile stuff for ARM, I use -fno-short-enums. This conflicts, of course:
ld: warning: /var/folders/9m/2wnjp9zd71x13cpdpf16y_4r0000gn/T//ccQuEnp6.o uses 32-bit enums yet the output is to use variable-size enums; use of enum values across objects may fail
Every time I try to run a "Hello, World!" executable, it segfaults. Could this be the reason?
Here's the command I used to compile hello.c:
arm-eabi-gcc \
hello.c -o hello \
/Users/user/gcc-arm-install/arm-eabi/lib/crt0.o \
/Users/user/gcc-arm-install/lib/gcc/arm-eabi/4.7.0/crtbegin.o \
/Users/user/gcc-arm-install/lib/gcc/arm-eabi/4.7.0/crti.o \
/Users/user/gcc-arm-install/lib/gcc/arm-eabi/4.7.0/crtn.o \
/Users/user/gcc-arm-install/lib/gcc/arm-eabi/4.7.0/crtend.o \
-v -nostdinc -nostdlib -static \
-march=armv7-a -mno-thumb-interwork -marm -mfpu=neon -mfloat-abi=softfp -fpic \
-ffunction-sections -fno-short-enums -fno-rtti -fno-exceptions \
-I/Users/user/gcc-arm-install/lib/gcc/arm-eabi/4.7.0/include \
-I/Users/user/gcc-arm-install/lib/gcc/arm-eabi/4.7.0/include-fixed \
-I/Users/user/gcc-arm-install/arm-eabi/include \
-I/Users/user/gcc-arm-install/arm-eabi/sys-include \
-L/Users/user/gcc-arm-install/arm-eabi/lib \
-L/Users/user/gcc-arm-install/lib/gcc/arm-eabi/4.7.0 \
-lm -lc -lgcc
Update:
Okay, I think I've narrowed the problem down to the combination of newlib's libc and the startup files (crt0.o). I tried compiling a test app with GCC 4.7.0 using libc.a and startup files from the Android NDK, and that worked on the phone when compiled static. In fact, it worked even though ld complained again about libgcc using "variable-size enums" (i.e., not compiled with -fno-short-enums like everything else). So, my hypothesis about -fno-short-enums being the culprit in my earlier crashing binaries was incorrect.
Here's what's working:
Binutils and GCC 4.7.0 compiled from source for target "arm-linux-eabi." I configured GCC using --with-newlib (newlib and libgloss in GCC's source tree). So, GCC was actually built with newlib and installed along with newlib, and it generates working binaries as long as I don't actually link with newlib's libc. At present, I must use libc from the Andoid NDK and its startup files instead.
My compile script looks something like this. The include and library paths point to the NDK includes and libc:
NDK_PATH="/Users/user/SOURCE/android-ndk-r8/platforms/android-9/arch-arm"
CFLAGS="-nostdinc -nostdlib -static -fno-short-enums -lc -lgcc -lc"
gcc $NDK_PATH/usr/lib/crtbegin_static.o \
hello.c -o hello $CFLAGS \
$NDK_PATH/usr/lib/crtend_android.o
I still want to get binaries compiled statically with newlib's libc working. Back to shell scripting...
For work I cross-build for the Cortex-M3 platform, and I also use newlib. The following links may be helpful for you:
http://frank.harvard.edu/~coldwell/toolchain/
http://www.microbuilder.eu/Tutorials/SoftwareDevelopment/BuildingGCCToolchain.aspx
Although the following link is specific to Cortex-M3, it may provide some insight for you, I used it to script my toolchain build:
http://www.johannes-bauer.com/mcus/cortex/?menuid=5
Your newlib may have been miscompiled (maybe with the host compiler? Highly unlikely since it links, but hey it's possible).
I think you could first write a shell script to choose the work env, like you will work under gcc or arm-gcc. in this script, you could make an alternative lib link to different lib you want, like if you login and choose gcc, the lib file will be normal libc and if you choose arm-gcc, the lib will be the different one

error linking to libgcc.a when cross-compiling for Android, but symbols exists?

I am trying to cross-compile a very simple program for Android that worked with android-ndk-r6b and prior, but does not work on android-ndk-r7 and newer:
int main() {
;
return 0;
}
I was able to do so using an "agcc" script on an older version of Android that can be found here. I'm sincerely not trying to use an Android.mk file to build this. I know I can, but this is part of something much larger I'm working on. So take it for face-value that I am trying to cross-compile this in a different way.
Anyway, I try to build and get:
$ arm-eabi-gcc -o test test.c
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/ld: warning: /tmp/cc00QD3x.o uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail
/tmp/cc00QD3x.o:(.ARM.exidx.text.main+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
collect2: ld returned 1 exit status
So, the key error is the undefined reference to __aeabi_unwind_cpp_pr0.
After doing some digging, this symbol is in libgcc.a which I am linking to:
$ arm-eabi-nm /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/libgcc.a | grep __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
00000590 T __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
U __aeabi_unwind_cpp_pr0
It has a 'T' which tells me that it is in the code somewhere, right?
Here is the verbose output of arm-eabi-gcc which shows I am in fact linking to this library:
Using built-in specs.
Target: arm-eabi
Configured with: /home/jingyu/projects/gcc/android-toolchainsrc/build/../gcc/gcc-4.4.3/configure --prefix=/usr/local --target=arm-eabi --host=x86_64-linux-gnu --build=x86_64-linux-gnu --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/home/jingyu/projects/gcc/toolchain_build/obj/temp-install --with-mpfr=/home/jingyu/projects/gcc/toolchain_build/obj/temp-install --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --with-float=soft --with-fpu=vfp --with-arch=armv5te --enable-target-optspace --with-abi=aapcs --with-gcc-version=4.4.3 --with-binutils-version=2.19 --with-gmp-version=4.2.4 --with-mpfr-version=2.4.1 --with-gdb-version=7.1.x --with-arch=armv5te --with-multilib-list=mandroid --with-sysroot=/usr/local/google/home/android/cupcake_rel_root --program-transform-name='s&^&arm-eabi-&'
Thread model: single
gcc version 4.4.3 (GCC)
COLLECT_GCC_OPTIONS='-o' 'test' '-I/home/gnychis/Documents/android/os/system/core/include' '-I/home/gnychis/Documents/android/os/hardware/libhardware/include' '-I/home/gnychis/Documents/android/os/hardware/ril/include' '-I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include' '-I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include' '-I/home/gnychis/Documents/android/os/frameworks/base/include' '-I/home/gnychis/Documents/android/os/external/skia/include' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include' '-I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include' '-I/home/gnychis/Documents/android/os/bionic/libc/include' '-I/home/gnychis/Documents/android/os/bionic/libstdc++/include' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/common' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm' '-I/home/gnychis/Documents/android/os/bionic/libm/include' '-I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm' '-I/home/gnychis/Documents/android/os/bionic/libthread_db/include' '-I/home/gnychis/Documents/android/os/bionic/libm/arm' '-I/home/gnychis/Documents/android/os/bionic/libm' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates' '-D__ARM_ARCH_5__' '-D__ARM_ARCH_5T__' '-D__ARM_ARCH_5E__' '-D__ARM_ARCH_5TE__' '-DANDROID' '-DSK_RELEASE' '-DNDEBUG' '-UDEBUG' '-march=armv5te' '-mtune=xscale' '-msoft-float' '-mthumb-interwork' '-fpic' '-fno-exceptions' '-ffunction-sections' '-funwind-tables' '-fstack-protector' '-fmessage-length=0' '-Bdynamic' '-L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib' '-nostdlib' '-v' '-mfpu=vfp' '-mabi=aapcs'
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/arm-eabi/4.4.3/cc1 -quiet -v -I/home/gnychis/Documents/android/os/system/core/include -I/home/gnychis/Documents/android/os/hardware/libhardware/include -I/home/gnychis/Documents/android/os/hardware/ril/include -I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include -I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include -I/home/gnychis/Documents/android/os/frameworks/base/include -I/home/gnychis/Documents/android/os/external/skia/include -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include -I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include -I/home/gnychis/Documents/android/os/bionic/libc/include -I/home/gnychis/Documents/android/os/bionic/libstdc++/include -I/home/gnychis/Documents/android/os/bionic/libc/kernel/common -I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm -I/home/gnychis/Documents/android/os/bionic/libm/include -I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm -I/home/gnychis/Documents/android/os/bionic/libthread_db/include -I/home/gnychis/Documents/android/os/bionic/libm/arm -I/home/gnychis/Documents/android/os/bionic/libm -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates -iprefix /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/ -D__USES_INITFINI__ -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DSK_RELEASE -DNDEBUG -UDEBUG test.c -quiet -dumpbase test.c -march=armv5te -mtune=xscale -msoft-float -mthumb-interwork -mfpu=vfp -mabi=aapcs -auxbase test -version -fpic -fno-exceptions -ffunction-sections -funwind-tables -fstack-protector -fmessage-length=0 -o /tmp/ccIIp1N2.s
GNU C (GCC) version 4.4.3 (arm-eabi)
compiled by GNU C version 4.2.4 (Ubuntu 4.2.4-1ubuntu4), GMP version 4.2.4, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128206
ignoring nonexistent directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/include"
ignoring nonexistent directory "/usr/local/google/home/android/cupcake_rel_root/usr/local/include"
ignoring duplicate directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/../../lib/gcc/arm-eabi/4.4.3/include"
ignoring duplicate directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/../../lib/gcc/arm-eabi/4.4.3/include-fixed"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/../../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/include"
ignoring nonexistent directory "/usr/local/google/home/android/cupcake_rel_root/usr/include"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/out/target/product/generic/obj/include"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm"
ignoring nonexistent directory "/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates"
#include "..." search starts here:
#include <...> search starts here:
/home/gnychis/Documents/android/os/system/core/include
/home/gnychis/Documents/android/os/hardware/libhardware/include
/home/gnychis/Documents/android/os/hardware/ril/include
/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include
/home/gnychis/Documents/android/os/dalvik/libnativehelper/include
/home/gnychis/Documents/android/os/frameworks/base/include
/home/gnychis/Documents/android/os/external/skia/include
/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include
/home/gnychis/Documents/android/os/bionic/libc/include
/home/gnychis/Documents/android/os/bionic/libstdc++/include
/home/gnychis/Documents/android/os/bionic/libc/kernel/common
/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm
/home/gnychis/Documents/android/os/bionic/libm/include
/home/gnychis/Documents/android/os/bionic/libthread_db/include
/home/gnychis/Documents/android/os/bionic/libm/arm
/home/gnychis/Documents/android/os/bionic/libm
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/include
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/include-fixed
End of search list.
GNU C (GCC) version 4.4.3 (arm-eabi)
compiled by GNU C version 4.2.4 (Ubuntu 4.2.4-1ubuntu4), GMP version 4.2.4, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128206
Compiler executable checksum: c575b4a30c8a516a84cf6e49f2cb23d1
COLLECT_GCC_OPTIONS='-o' 'test' '-I/home/gnychis/Documents/android/os/system/core/include' '-I/home/gnychis/Documents/android/os/hardware/libhardware/include' '-I/home/gnychis/Documents/android/os/hardware/ril/include' '-I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include' '-I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include' '-I/home/gnychis/Documents/android/os/frameworks/base/include' '-I/home/gnychis/Documents/android/os/external/skia/include' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include' '-I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include' '-I/home/gnychis/Documents/android/os/bionic/libc/include' '-I/home/gnychis/Documents/android/os/bionic/libstdc++/include' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/common' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm' '-I/home/gnychis/Documents/android/os/bionic/libm/include' '-I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm' '-I/home/gnychis/Documents/android/os/bionic/libthread_db/include' '-I/home/gnychis/Documents/android/os/bionic/libm/arm' '-I/home/gnychis/Documents/android/os/bionic/libm' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates' '-D__ARM_ARCH_5__' '-D__ARM_ARCH_5T__' '-D__ARM_ARCH_5E__' '-D__ARM_ARCH_5TE__' '-DANDROID' '-DSK_RELEASE' '-DNDEBUG' '-UDEBUG' '-march=armv5te' '-mtune=xscale' '-msoft-float' '-mthumb-interwork' '-fpic' '-fno-exceptions' '-ffunction-sections' '-funwind-tables' '-fstack-protector' '-fmessage-length=0' '-Bdynamic' '-L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib' '-nostdlib' '-v' '-mfpu=vfp' '-mabi=aapcs'
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/as -v -I/home/gnychis/Documents/android/os/system/core/include -I/home/gnychis/Documents/android/os/hardware/libhardware/include -I/home/gnychis/Documents/android/os/hardware/ril/include -I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include -I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include -I/home/gnychis/Documents/android/os/frameworks/base/include -I/home/gnychis/Documents/android/os/external/skia/include -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include -I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include -I/home/gnychis/Documents/android/os/bionic/libc/include -I/home/gnychis/Documents/android/os/bionic/libstdc++/include -I/home/gnychis/Documents/android/os/bionic/libc/kernel/common -I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm -I/home/gnychis/Documents/android/os/bionic/libm/include -I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm -I/home/gnychis/Documents/android/os/bionic/libthread_db/include -I/home/gnychis/Documents/android/os/bionic/libm/arm -I/home/gnychis/Documents/android/os/bionic/libm -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates -march=armv5te -mthumb-interwork -mfloat-abi=soft -mfpu=vfp -meabi=5 -o /tmp/ccGAKjxX.o /tmp/ccIIp1N2.s
GNU assembler version 2.19 (arm-eabi) using BFD version (GNU Binutils) 2.19
COMPILER_PATH=/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/arm-eabi/4.4.3/:/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/:/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/
LIBRARY_PATH=/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/:/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/:/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/lib/
COLLECT_GCC_OPTIONS='-o' 'test' '-I/home/gnychis/Documents/android/os/system/core/include' '-I/home/gnychis/Documents/android/os/hardware/libhardware/include' '-I/home/gnychis/Documents/android/os/hardware/ril/include' '-I/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include' '-I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include' '-I/home/gnychis/Documents/android/os/frameworks/base/include' '-I/home/gnychis/Documents/android/os/external/skia/include' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include' '-I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include' '-I/home/gnychis/Documents/android/os/bionic/libc/include' '-I/home/gnychis/Documents/android/os/bionic/libstdc++/include' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/common' '-I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm' '-I/home/gnychis/Documents/android/os/bionic/libm/include' '-I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm' '-I/home/gnychis/Documents/android/os/bionic/libthread_db/include' '-I/home/gnychis/Documents/android/os/bionic/libm/arm' '-I/home/gnychis/Documents/android/os/bionic/libm' '-I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates' '-D__ARM_ARCH_5__' '-D__ARM_ARCH_5T__' '-D__ARM_ARCH_5E__' '-D__ARM_ARCH_5TE__' '-DANDROID' '-DSK_RELEASE' '-DNDEBUG' '-UDEBUG' '-march=armv5te' '-mtune=xscale' '-msoft-float' '-mthumb-interwork' '-fpic' '-fno-exceptions' '-ffunction-sections' '-funwind-tables' '-fstack-protector' '-fmessage-length=0' '-Bdynamic' '-L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib' '-nostdlib' '-v' '-mfpu=vfp' '-mabi=aapcs'
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/arm-eabi/4.4.3/collect2 --sysroot=/usr/local/google/home/android/cupcake_rel_root -X -o test -L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib -L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3 -L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc -L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/lib -T /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/arm-eabi/lib/ldscripts/armelf.x -dynamic-linker /system/bin/linker --gc-sections -z nocopyreloc --no-undefined -rpath-link=/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib /home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtend_android.o /home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib32/libiberty.a /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/libgcc.a -lc -lm /tmp/ccGAKjxX.o
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/ld: warning: /tmp/ccGAKjxX.o uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail
/tmp/ccGAKjxX.o:(.ARM.exidx.text.main+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
collect2: ld returned 1 exit status
So I'm just a bit unsure why I am getting this undefined reference. I have used this same method of cross-compiling with a slightly different version of Android and had no issue.
Does anything stand out to anyone?
EDIT: The actual command generated is the following:
arm-eabi-gcc -o test -I/home/gnychis/Documents/android/os/system/core/include -I/home/gnychis/Documents/android/os/hardware/libhardware/include -I/home/gnychis/Documents/android/os/hardware/ril/include -I/home/gnychis/Documents/android/os/dalvik/libnativehelper/include -I/home/gnychis/Documents/android/os/frameworks/base/include -I/home/gnychis/Documents/android/os/external/skia/include -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/include -I/home/gnychis/Documents/android/os/bionic/libc/arch-arm/include -I/home/gnychis/Documents/android/os/bionic/libc/include -I/home/gnychis/Documents/android/os/bionic/libstdc++/include -I/home/gnychis/Documents/android/os/bionic/libc/kernel/common -I/home/gnychis/Documents/android/os/bionic/libc/kernel/arch-arm -I/home/gnychis/Documents/android/os/bionic/libm/include -I/home/gnychis/Documents/android/os/bionic/libm/include/arch/arm -I/home/gnychis/Documents/android/os/bionic/libthread_db/include -I/home/gnychis/Documents/android/os/bionic/libm/arm -I/home/gnychis/Documents/android/os/bionic/libm -I/home/gnychis/Documents/android/os/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DSK_RELEASE -DNDEBUG -include /home/gnychis/Documents/android/os/system/core/include/arch/linux-arm/AndroidConfig.h -UDEBUG -march=armv5te -mtune=xscale -msoft-float -mthumb-interwork -fpic -fno-exceptions -ffunction-sections -funwind-tables -fstack-protector -fmessage-length=0 -Bdynamic -Wl,-T,/home/gnychis/Documents/android/os/build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -Wl,--no-undefined -Wl,-rpath-link=/home/gnychis/Documents/android/os/../android-ndk-r7b/platforms/android-9/arch-arm/usr/lib -L/home/gnychis/Documents/android/os/../android-ndk-r7b/platforms/android-9/arch-arm/usr/lib -nostdlib /home/gnychis/Documents/android/os/../android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtend_android.o /home/gnychis/Documents/android/os/../android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/libgcc.a -lc -lm test.c
Here's your link like, broken out into multiple lines for clarity:
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../libexec/gcc/arm-eabi/4.4.3/collect2 \
--sysroot=/usr/local/google/home/android/cupcake_rel_root \
-X \
-o test \
-L/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib \
-L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3 \
-L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc
-L/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/lib
-T /home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/arm-eabi/lib/ldscripts/armelf.x \
-dynamic-linker /system/bin/linker \
--gc-sections \
-z nocopyreloc \
--no-undefined \
-rpath-link=/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib \
/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtend_android.o \
/home/gnychis/Documents/android/android-ndk-r7b/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o \
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib32/libiberty.a \
/home/gnychis/Documents/android/os/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/libgcc.a \
-lc \
-lm \
/tmp/ccGAKjxX.o
As you can see, your own object file (the temporary one) is the very last item on the command line. This is just wrong. It needs to be before the libraries, at least, if it is to link correctly.
Basically, your agcc script is passing -nostdlib (which says that you know better) and then passing the libraries manually, but doing it in completely the wrong order. If you fix this, all should be well.
Link order is very important. Objects and libraries that provide symbols must be linked after objects and libraries that require symbols.
There were certain versions of the tools that could tolerate bad ordering, but I think that was a bug, or mis-feature, because newer toolchains cannot, and should not. Presumably this script was written for one of those.
Where to find: __aeabi_unwind_cpp_pr0 and other mysterious, undefined functions
(I had a similar problem error to what you describe, but found a different solution, that may be helpful to you or others)
I found 'libgccunwind.a' library in the Google NDK package which defines a number of these mysterious functions (they are functions referenced by libc.a and other libraries in the NDK package, but not defined in a standard library) I found them defined in a libgccunwind.a library in:
\sources\android\gccunwind\libs\armeabi
NM shows that they are defined in that lib from an 'unwind-arm.o' file:
nm libgccunwind.a
unwind-arm.o:
U _GLOBAL_OFFSET_TABLE_
00000cf8 T _Unwind_Complete
00000cfc T _Unwind_DeleteException
00000ba4 T _Unwind_GetCFA
00000408 t _Unwind_GetGR
00000474 t _Unwind_SetGR
000003c4 T _Unwind_VRS_Get
0000084c T _Unwind_VRS_Pop
00000430 T _Unwind_VRS_Set
00000844 T __aeabi_unwind_cpp_pr0
0000083c W __aeabi_unwind_cpp_pr1
00000834 W __aeabi_unwind_cpp_pr2
w __cxa_begin_cleanup
w __cxa_call_unexpected
w __cxa_type_match
U __exidx_end
U __exidx_start
00000d1c T __gnu_Unwind_Backtrace
w __gnu_Unwind_Find_exidx
Independant of the libgccunwind.a above, I searched for __aeabi_unwind_cpp_pr0 and unwind-arm.c and unwind.c, and found various c source, for example:
http://lxr.free-electrons.com/source/arch/arm/kernel/unwind.c?a=arm
http://opensource.apple.com/source/gcc/gcc-5646/gcc/config/arm/unwind-arm.c
These programs seem to be derived from a similar source. My guess is that these 'unwind_cpp' (and related functions) are called by the functions in libc.a when a function returns or on certain events so that these functions can perform some debugging or tracing operation.
In any event, adding that directory in a -L linker option and -lgccunwind linker option (after the -lc linker option) allowed the linker to find those 'undefined' functions -- and let me get to the next problem I have in cross compiling to ARM systems.

Categories

Resources