Compile external module for Android - android

I am trying to compile a driver as a loadable module but whenever I adb shell into my phone and do an insmod test.ko I get the error message insmod: failed to load /data/local/tmp/test.ko: Exec format error. Grep'ing dmesg I find the following log: test: no symbol version for module_layout.
I've done quite a bit of googling [Ref] [Ref] [Ref] [Ref] [Ref] and reading the linux kbuild documentation txt files [Ref] [Ref] to no avail, so if someone knows the answer it'd be fab :) (I've only referenced the most helpful links I found).
What I've done so far is this:
I have an Qualcomm Aurora checkout and in the kernel directory I type the following
cp arch/arm64/configs/gemini_user_defconfig .config [B]# Has CONFIG_MODVERSIONS enabled and MODULE_SIG*=n[/B]
yes "" | make oldconfig ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
make prepare ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
make scripts ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
make modules ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
I have my PATH set to point to /MyAOSBDir/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin so I pick up the correct toolchain.
At this point appears to be well. In my kernel directory I have Module.symvers, so I appear to be set.
Now to the directory I have set up outside of this build tree with a dummy test... The Makefile looks like this:
KERNEL_DIR:=/solomon-build/MiNote2AOSB/kernel/
obj-m += test.o
PWD := $(shell pwd)
.PHONY: all
all:
$(MAKE) M=$(PWD) ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- -C $(KERNEL_DIR) modules V=1
clean:
$(MAKE) M=$(PWD) -C $(KERNEL_DIR) clean
The driver is just a dummy:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
static int __init hello_start(void)
{
printk(KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye world\n");
}
module_init(hello_start);
module_exit(hello_end);
I do make make all at the comment line and get this output:
make M=/solomon-build/build_mxt_kmod ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- -C /solomon-build/MiNote2AOSB/kernel/ modules V=1
make[1]: Entering directory `/solomon-build/MiNote2AOSB/kernel'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || ( \
echo >&2; \
echo >&2 " ERROR: Kernel configuration is invalid."; \
echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo >&2 ; \
/bin/false)
mkdir -p /solomon-build/build_mxt_kmod/.tmp_versions ; rm -f /solomon-build/build_mxt_kmod/.tmp_versions/*
make -f ./scripts/Makefile.build obj=/solomon-build/build_mxt_kmod
./scripts/gcc-wrapper.py aarch64-linux-android-gcc -Wp,-MD,/solomon-build/build_mxt_kmod/.test.o.d -nostdinc -isystem /solomon-build/MiNote2AOSB/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/../lib/gcc/aarch64-linux-android/4.9.x-google/include -I./arch/arm64/include -Iarch/arm64/include/generated -Iinclude -I./arch/arm64/include/uapi -Iarch/arm64/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -mgeneral-regs-only -fno-pic -fno-delete-null-pointer-checks -Os -Wno-maybe-uninitialized --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(test)" -D"KBUILD_MODNAME=KBUILD_STR(test)" -c -o /solomon-build/build_mxt_kmod/.tmp_test.o /solomon-build/build_mxt_kmod/test.c
(cat /dev/null; echo kernel//solomon-build/build_mxt_kmod/test.ko;) > /solomon-build/build_mxt_kmod/modules.order
make -f ./scripts/Makefile.modpost
find /solomon-build/build_mxt_kmod/.tmp_versions -name '*.mod' | xargs -r grep -h '\.ko$' | sort -u | sed 's/\.ko$/.o/' | scripts/mod/modpost -m -i ./Module.symvers -I /solomon-build/build_mxt_kmod/Module.symvers -o /solomon-build/build_mxt_kmod/Module.symvers -S -E -w -s -T -
./scripts/gcc-wrapper.py aarch64-linux-android-gcc -Wp,-MD,/solomon-build/build_mxt_kmod/.test.mod.o.d -nostdinc -isystem /solomon-build/MiNote2AOSB/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/../lib/gcc/aarch64-linux-android/4.9.x-google/include -I./arch/arm64/include -Iarch/arm64/include/generated -Iinclude -I./arch/arm64/include/uapi -Iarch/arm64/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -mgeneral-regs-only -fno-pic -fno-delete-null-pointer-checks -Os -Wno-maybe-uninitialized --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(test.mod)" -D"KBUILD_MODNAME=KBUILD_STR(test)" -DMODULE -c -o /solomon-build/build_mxt_kmod/test.mod.o /solomon-build/build_mxt_kmod/test.mod.c
aarch64-linux-android-ld -EL -r -T ./scripts/module-common.lds --build-id --fix-cortex-a53-843419 -o /solomon-build/build_mxt_kmod/test.ko /solomon-build/build_mxt_kmod/test.o /solomon-build/build_mxt_kmod/test.mod.o
make[1]: Leaving directory `/solomon-build/MiNote2AOSB/kernel'
So, there are no messages saying there is a missing Module.symvers, so that's good, and I do get a built .ko file.
What I don't understand is the message ERROR: Kernel configuration is invalid. The files it is talking about exist, so I know they have been created in my kernel build.
Anyway, trying to insmod this onto the phone gives the message I mentioned previously. If I cat Module.symvers I see:
0xff924338 backlight_force_update drivers/video/backlight/backlight EXPORT_SYMBOL
0x30254daf test_iosched_register block/test-iosched EXPORT_SYMBOL
<snip>
0xdd502540 backlight_device_unregister drivers/video/backlight/backlight EXPORT_SYMBOL
0x9939eba0 backlight_unregister_notifier drivers/video/backlight/backlight EXPORT_SYMBOL
So no symbol module_layout in the file, and thus no CRC, which is what I presume is creating the error message?
Any clues would be much appreciated, thank you.
Oh I should also mention that the module and kernel vermagic match:
# modinfo /data/local/tmp/test.ko
filename: /data/local/tmp/test.ko
depends:
vermagic: 3.18.20-mytestkernel-perf-g671c431-dirty SMP preempt mod_unload modversions aarch64
# uname -a
Linux localhost 3.18.20-mytestkernel-perf-g671c431-dirty #1 SMP PREEMPT Mon Jun 5 15:46:13 BST 2017 aarch64
*EDIT - FOUND SOLUTION - NEW QUESTON *:
I've gotten much further since posting. What I realised was, was that the compilation of the kernel using the Android build system is producing a radically different Module.symvers one from my method above (for some reason it took a while for the penny to drop and for me to check the Andoird build output - duh!). In fact, I've realised I always had the Module.symvers file, it was just located in ../out/target/product/msm8996/obj/KERNEL_OBJ/Module.symvers relative to the kernel dir. Copying this file into kernel and re-running my module build now produces a module that loads correctly :)
So, I guess the question becomes, why do the two files differ? What is Android doing differently? I assume it is setting up some more detailed config, but how/what/why?

So, the answer was relatively simple in the end...
I just use the normal Android build process of sourcing envsetup.sh, running lunch and then building the kernel:
. build/envsetup.sh
lunch msm8996-userdebug
make kernel -j16
(Remember to make sure in your .config file to set CONFIG_MODULES=y and set any kernel drivers to =m if you want them as modules).
In the separate directory, not in the Android build tree I now have my new module and the following Makefile, which now looks like this:
MY_ANDROID_ROOT_DIR :=/path/to/my/android/checkout
KERNEL_DIR:=$(MY_ANDROID_ROOT_DIR)/kernel
obj-m += my_driver.o
PWD := $(shell pwd)
.PHONY: all
all:
$(MAKE) \
M=$(PWD) \
ARCH=arm64 \
CROSS_COMPILE=aarch64-linux-android- \
-C $(KERNEL_DIR) \
modules \
V=1 \
O=$(MY_ANDROID_ROOT_DIR)/out/target/product/msm8996/obj/KERNEL_OBJ
clean:
$(MAKE) M=$(PWD) -C $(KERNEL_DIR) clean
The make all output will still be in your modules directory (not the Android output dir).
This is basically identical to all of the examples relating to pure Linux builds. The only extra bit of information I needed to provide was where the Android build system output its build files, which is O=$(MY_ANDROID_ROOT_DIR)/out/target/product/<your-product>/obj/KERNEL_OBJ.
The O= define tells Make where to find the output of the kernel build.
The 'V=1` define tells Make to output verbose build information.
modules is a kernel target that will build you module defined in the Makefile variable obj-m. This variable "specifies the object files which are built as loadable kernel modules".
Now my modules build fine and I don't need to worry about independently compiling the kernel or anything like that to fix missing file messages (although it will still output about autoconf.h, which I don't understand because it exists in my tree and doesn't seem to stop my modules working).
PS If you module includes more than one file define obj-m += my_driver.o and then my_driver-m:= <extra objects>.

Related

Android- Qt - Protobuf: Compiling protobuf with ndk's prebuilt toolchains

I'm currently porting an application written in Qt5 to Android.
I have installed Qt5 through its official installer, along with the AndroidSdk through Android Studio.
I can compile, deploy and execute a Qt5/Qml application on an Android target.
However, the application I am porting uses Protobuf, therefore I want to cross-compile this library with the compiler Qt is using to package it with my application.
I have successfully built protobuf with a standalone toolchain following this resource : https://developers.google.com/cardboard/develop/c/protobuf
But when using the toolchain Qt5 uses I am not able to build the protobuf library.
A sample from my application's working compile commands:
/home/cfv/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -c -D__ANDROID_API__=21 -target armv7-none-linux-androideabi -gcc-toolchain /home/cfv/Android/Sdk/ndk/20.0.5594570/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -fno-limit-debug-info -DANDROID_HAS_WSTRING --sysroot=/home/cfv/Android/Sdk/ndk/20.0.5594570/sysroot -isystem /home/cfv/Android/Sdk/ndk/20.0.5594570/sysroot/usr/include/arm-linux-androideabi -isystem /home/cfv/Android/Sdk/ndk/20.0.5594570/sources/cxx-stl/llvm-libc++/include -isystem /home/cfv/Android/Sdk/ndk/20.0.5594570/sources/android/support/include -isystem /home/cfv/Android/Sdk/ndk/20.0.5594570/sources/cxx-stl/llvm-libc++abi/include -fstack-protector-strong -DANDROID -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-builtin-memmove -fPIC -Wl,Bsymbolic -g -g -marm -O0 -std=gnu++1z -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CONCURRENT_LIB -DQT_CORE_LIB -I../NaioCompanion -I. -I/opt/Qt/5.13.0/android_armv7/include -I/opt/Qt/5.13.0/android_armv7/include/QtQuick -I/opt/Qt/5.13.0/android_armv7/include/QtGui -I/opt/Qt/5.13.0/android_armv7/include/QtQml -I/opt/Qt/5.13.0/android_armv7/include/QtNetwork -I/opt/Qt/5.13.0/android_armv7/include/QtConcurrent -I/opt/Qt/5.13.0/android_armv7/include/QtCore -I. -I/opt/Qt/5.13.0/android_armv7/mkspecs/android-clang -o xxx.o ../NaioCompanion/Publisher.cpp
The build script I uses for Protobuf, tweaked from the resource cited above:
export build_dir=`pwd`/../protobuf-for-android-with-qt5-toolchain/
export NDK=/home/cfv/Android/Sdk/ndk/20.0.5594570/
export sysroot=/home/cfv/Android/Sdk/ndk/20.0.5594570/platforms/android-21/arch-arm
export PATH=/home/cfv/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/bin/:$PATH
export CC="/home/cfv/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --sysroot=$sysroot"
export CXX="/home/cfv/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --sysroot=$sysroot"
./configure \
--host=arm-linux-androideabi \
--with-protoc=protoc \
--with-sysroot="$sysroot" \
--disable-shared \
--prefix="$build_dir/armeabi-v7a" \
--enable-cross-compile \
CFLAGS="-D__ANDROID_API__=21 -target armv7-none-linux-androideabi -march=armv7-a" \
CXXFLAGS="-frtti -fexceptions -target armv7-none-linux-androideabi -D__ANDROID_API__=21" \
LIBS="-llog -lz"
make -j2
make install
the output:
checking whether to enable maintainer-specific portions of Makefiles... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... arm-unknown-linux-androideabi
checking target system type... arm-unknown-linux-androideabi
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-linux-androideabi-strip... arm-linux-androideabi-strip
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether UID '1000' is supported by ustar format... yes
checking whether GID '1000' is supported by ustar format... yes
checking how to create a ustar tar archive... gnutar
checking for arm-linux-androideabi-gcc... /home/cfv/Android/Sdk/ndk/20.0.5594570/toolchains /llvm/prebuilt/linux-x86_64/bin/clang --sysroot=/home/cfv/Android/Sdk/ndk/20.0.5594570/platforms/android-21/arch-arm
checking whether the C compiler works... no
configure: error: in `/home/cfv/projects/ext/try-to-build-protobuf/protobuf':
configure: error: C compiler cannot create executables
See `config.log' for more details
make: *** No targets specified and no makefile found. Stop.
make: *** No rule to make target 'install'. Stop.
And the config.log details:
configure:3866: checking whether the C compiler works
configure:3888: /home/cfv/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --sysroot=/home/cfv/Android/Sdk/ndk/20.0.5594570/platforms/android-21/arch-arm -D__ANDROID_API__=21 -target armv7-none-linux-androideabi -march=armv7-a -nostdlib++ -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -Wl,--exclude-libs,libunwind.a conftest.c -llog -lz >&5
clang: warning: argument unused during compilation: '-nostdlib++' [-Wunused-command-line-argument]
/home/cfv/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lunwind
/home/cfv/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lunwind
clang: error: linker command failed with exit code 1 (use -v to see invocation)
configure:3892: $? = 1
configure:3930: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "Protocol Buffers"
| #define PACKAGE_TARNAME "protobuf"
| #define PACKAGE_VERSION "3.6.0"
| #define PACKAGE_STRING "Protocol Buffers 3.6.0"
| #define PACKAGE_BUGREPORT "protobuf#googlegroups.com"
| #define PACKAGE_URL ""
| #define PACKAGE "protobuf"
| #define VERSION "3.6.0"
| /* end confdefs.h. */
|
| int
| main ()
| {
|
| ;
| return 0;
| }
configure:3935: error: in `/home/cfv/projects/ext/try-to-build-protobuf/protobuf':
configure:3937: error: C compiler cannot create executables
I think I am missing some compiler options (I especially am suspicious about -Wl,--exclude-libs,libunwind.a) but I have been struggling with it all day and this is way over my comfort zone.
Has anyone ever had a similar issue, and would be able to help me ?

bz2 module fails when building Python 3.7

I'm trying to cross compile Python 3.7 for Android. I see in my output that bz2 if failing with the following error
building '_bz2' extension
/home/dematic/SPE/python3-android/sdk/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -isystem /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/include -isystem /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/include/openssl -no-integrated-as -I. -I./Include -target aarch64-none-linux-androideabi22 -target aarch64-none-linux-androideabi22 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -fPIC -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -I./Include -I. -I/home/dematic/SPE/python3-android/src/Python-3.7.3/Include -I/home/dematic/SPE/python3-android/src/Python-3.7.3 -c /home/dematic/SPE/python3-android/src/Python-3.7.3/Modules/_bz2module.c -o build/temp.linux-aarch64-3.7/home/dematic/SPE/python3-android/src/Python-3.7.3/Modules/_bz2module.o
/home/dematic/SPE/python3-android/sdk/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -isystem /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/include -isystem /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/include/openssl -no-integrated-as -shared -target aarch64-none-linux-androideabi22 -fuse-ld=lld -L /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/lib -target aarch64-none-linux-androideabi22 -fuse-ld=lld -L /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/lib -target aarch64-none-linux-androideabi22 -fuse-ld=lld -L /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/lib -fPIC -target aarch64-none-linux-androideabi22 build/temp.linux-aarch64-3.7/home/dematic/SPE/python3-android/src/Python-3.7.3/Modules/_bz2module.o -L. -L/home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/lib -lbz2 -lpython3.7m -o build/lib.linux-aarch64-3.7/_bz2.cpython-37m.so
ld.lld: error: /home/dematic/SPE/python3-android/build/19c-22-aarch64-linux-androideabi-4.9/lib/libbz2.a(bzlib.o) is incompatible with aarch64linux
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am building bzip2 1.0.6 without any issues, but I assume I'm not linking to it correctly or some other issue. Is there some sort of other architecture I'm supposed to be building?
This is the project I'm trying to build with
https://github.com/GRRedWings/python3-android
I'm trying to cross compile Python 3.7 for Android. I see in my output that bz2 if failing with the following error
The Bzip2 makefiles are not written for cross-compiles. They effectively ignore a user's flags like CFLAGS and LDFLAGS. The makefiles actually blows away a user's CFLAGS and sets it to CFLAGS=-Wall -Winline -O2 -g $(BIGFILES). Your flags like -target aarch64-none-linux-androideabi22 are not used.
There are two Makefiles in play. One is called Makefile and it builds the static library, if I recall correctly. The second is Makefile-libbz2_so, and it build the shared object. You need to fix the omissions and apply the fixes to both makefiles.
You should probably use a patched Bzip like bzip2-noloader. It honors a user's CFLAGS, CXXFLAGS, LDFLAGS, etc. The check-in of interest is Commit 34d170f31106.
The makefile recipes in bzip2-noloader look similar to the following. They preserve Seward's original settings in BZIP_CFLAGS. But they also utilize CPPFLAGS and allow a user override in CFLAGS. The override will pickup your flags like -target aarch64-none-linux-androideabi22.
blocksort.o: blocksort.c
$(CC) $(CPPFLAGS) $(BZIP_CFLAGS) $(CFLAGS) -c blocksort.c
Programs use LDFLAGS as expected:
bzip2: libbz2.a bzip2.o
$(CC) $(CPPFLAGS) $(BZIP_CFLAGS) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2
Finally, the bzip2-noloader fork also honor's PREFIX, DESTDIR, etc. So you can perform staged installs, too.
I am building bzip2 1.0.6 without any issues ...
You are probably building for i686 or x86_64, and not Aarch64. The problem does not surface until link time. You can use objdump to inspect the object files, if interested.
Also note the makefile does this:
CC=gcc
AR=ar
RANLIB=ranlib
LDFLAGS=
You may need to tweak those variable assignments, too. Sometimes ar and ranlib use unusual names, like ranlib-5.0. And also be sure the tools are on-path.
The way to write makefiles to avoid these sorts of problems is detailed at 7.2.3 Variables for Specifying Commands in the GNU Coding Standards. The short of it is, (1) leave CFLAGS (and friends) for the user; and (2) if a flag is needed, then always supply it.
The GNU Coding Standards uses this as an example:
CFLAGS = -g
ALL_CFLAGS = -I. $(CFLAGS)
.c.o:
$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
Users can override the default CFLAGS of -g, and -I is always added because it is needed for the compile.

Android valgrind build fails

Hello I'm trying to build valgrind for android-arm. On Linux Mint 13 it fails with:
$ make
echo "# This is a generated file, composed of the following suppression rules:" > default.supp
echo "# " exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp >> default.supp
cat exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp >> default.supp
make all-recursive
make[1]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1'
Making all in include
make[2]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/include'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/include'
Making all in VEX
make[2]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make all-am
make[3]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../include -I../VEX/pub -DVGA_arm=1 -DVGO_linux=1 -DVGP_arm_linux=1 -DVGPV_arm_linux_vanilla=1 -Ipriv -m32 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wno-format-zero-length -fno-strict-aliasing -fno-builtin -marm -mcpu=cortex-a8 -Wbad-function-cast -Wcast-qual -Wcast-align -fstrict-aliasing -Wno-long-long -Wno-pointer-sign -fno-stack-protector -MT libvex_arm_linux_a-main_globals.o -MD -MP -MF .deps/libvex_arm_linux_a-main_globals.Tpo -c -o libvex_arm_linux_a-main_globals.o `test -f 'priv/main_globals.c' || echo './'`priv/main_globals.c
gcc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’ instead
cc1: error: unrecognised command line option ‘-marm’
priv/main_globals.c:1:0: error: bad value (cortex-a8) for -mtune= switch
make[3]: *** [libvex_arm_linux_a-main_globals.o] Error 1
make[3]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1'
make: *** [all] Error 2
I am using ndk-r8e and valgrind 3.8.1. The configure ends with:
Maximum build arch: arm
Primary build arch: arm
Secondary build arch:
Build OS: linux
Primary build target: ARM_LINUX
Secondary build target:
Platform variant: vanilla
Primary -DVGPV string: -DVGPV_arm_linux_vanilla=1
Default supp files: exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp
What can I do to fix this? Alternatively, are there any pre-built android-arm valgrind binaries that I can use?
For building and installing Valgrind for Android use the bash script below, which I prefer to call build_valgrind.sh
To run with RUN_HELLO_JNI_THROUGH_VALGRIND=true you need two additional scripts (bootstrap_valgrind.sh, start_valgrind.sh) in the directory you run the script below from.
Running the script with the RUN_HELLO_JNI_THROUGH_VALGRIND=true flag will build the hello-jni application from the samples directory inside the Android NDK HOME, deploy it to the phone and run it through Valgrind, using either callgrind or memcheck tool, which you can specify in the start_valgrind.sh script.
The other two scripts are described here: https://stackoverflow.com/a/19235439/313113
Here's my directory structure:
|-- build_valgrind.sh (the script below)
|-- bootstrap_valgrind.sh (second script from https://stackoverflow.com/a/19235439/313113)
|-- start_valgrind.sh (first script from https://stackoverflow.com/a/19235439/313113)
|-- valgrind-3.10.0 (will be extracted by build_valgrind.sh)
`-- valgrind-3.10.0.tar.bz2 (will be downloaded by build_valgrind.sh)
I've tested that its working (memcheck and callgrind tools) on a Samsung Galaxy Nexus device with CyanogenMod 10.2.1 and Android 4.3.1 and CyanogenMod 11 20140804 snapshot, Android 4.4.4
You can see the file size of the generated output with: adb shell ls -lR "/sdcard/*grind*"
The build_valgrind.sh script:
#!/usr/bin/env bash
#set -x
function extract()
{
if [ -f "$1" ] ; then
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "$1 cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
RUN_HELLO_JNI_THROUGH_VALGRIND=true
VALGRIND_VERSION="3.10.0"
VALGRIND_EXTENSION=".tar.bz2"
VALGRIND_DIRECTORY="valgrind-${VALGRIND_VERSION}"
VALGRIND_TARBALL="valgrind-${VALGRIND_VERSION}${VALGRIND_EXTENSION}"
# Only download Valgrind tarball again if not already downloaded
if [[ ! -f "${VALGRIND_TARBALL}" ]]; then
wget -v -nc "http://valgrind.org/downloads/${VALGRIND_TARBALL}"
fi
# Only extract Valgrind tarball again if not already extracted
if [[ ! -d "$VALGRIND_DIRECTORY" ]]; then
extract "$VALGRIND_TARBALL"
fi
# Ensure ANDROID_NDK_HOME is set
if [[ ! -z "$ANDROID_NDK_HOME" ]]; then
export ANDROID_NDK_HOME="$HOME/Software/Android/android-ndk-r10c"
fi
# Ensure ANDOID_SDK_HOME is set
if [[ ! -z "$ANDROID_SDK_HOME" ]]; then
export ANDROID_SDK_HOME="$HOME/Software/Android/android-sdk/"
fi
if [[ ! -d "$VALGRIND_DIRECTORY" ]];
then
echo "Problem with extracting Valgrind from $VALGRIND_TARBALL into $VALGRIND_DIRECTORY!!!"
exit -1
fi
# Move to extracted directory
cd "$VALGRIND_DIRECTORY"
# ARM Toolchain
ARCH_ABI="arm-linux-androideabi-4.9"
export AR="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
export LD="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld"
export CC="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
export CXX="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++"
[[ ! -d "$ANDROID_NDK_HOME" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] && echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure ANDROID_NDK_HOME is defined also" && exit -1
# Configure build
export HWKIND="nexus_s"
ANDROID_PLATFORM=android-18
export CPPFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm -DANDROID_HARDWARE_$HWKIND"
export CFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm"
# BUG: For some reason file command is unable to detect if the file does not exist with ! -f , it says it doesn't exist even when it does!!!
BUILD=false
if [[ "${VALGRIND_DIRECTORY}/Inst/data/local/Inst/bin/valgrind" = *"No such file or directory"* ]]; then
BUILD=true
fi
if [[ "$BUILD" = true ]];
then
./configure --prefix="/data/local/Inst" \
--host="armv7-unknown-linux" \
--target="armv7-unknown-linux" \
--with-tmpdir="/sdcard "
[[ $? -ne 0 ]] && echo "Can't configure!" && exit -1
# Determine the number of jobs (commands) to be run simultaneously by GNU Make
NO_CPU_CORES=$(grep -c ^processor /proc/cpuinfo)
if [ $NO_CPU_CORES -le 8 ]; then
JOBS=$(($NO_CPU_CORES+1))
else
JOBS=${NO_CPU_CORES}
fi
# Compile Valgrind
make -j "${JOBS}"
[[ $? -ne 0 ]] && echo "Can't compile!" && exit -1
# Install Valgrind locally
make -j "${JOBS}" install DESTDIR="$(pwd)/Inst"
[[ $? -ne 0 ]] && echo "Can't install!" && exit -1
fi
# Push local Valgrind installtion to the phone
if [[ $(adb shell ls -ld /data/local/Inst/bin/valgrind) = *"No such file or directory"* ]];
then
adb root
adb remount
adb shell "[ ! -d /data/local/Inst ] && mkdir /data/local/Inst"
adb push Inst /
adb shell "ls -l /data/local/Inst"
# Ensure Valgrind on the phone is running
adb shell "/data/local/Inst/bin/valgrind --version"
# Add Valgrind executable to PATH (this might fail)
adb shell "export PATH=$PATH:/data/local/Inst/bin/"
fi
if [ $RUN_HELLO_JNI_THROUGH_VALGRIND = true ]; then
PACKAGE="com.example.hellojni"
# The location of the Hello JNI sample application
HELLO_JNI_PATH="$ANDROID_NDK_HOME/samples/hello-jni"
pushd "$HELLO_JNI_PATH"
# Update build target to the desired Android SDK version
ANDROID_PROJECT_TARGET="android-18"
android update project --target "$ANDROID_PROJECT_TARGET" --path . --name hello-jni --subprojects
# Enable Android NDK build with Ant
echo '<?xml version="1.0" encoding="utf-8"?>
<project name="HelloJni" basedir="." default="debug">
<target name="-pre-build">
<exec executable="${ndk.dir}/ndk-build" failonerror="true"/>
</target>
<target name="clean" depends="android_rules.clean">
<exec executable="${ndk.dir}/ndk-build" failonerror="true">
<arg value="clean"/>
</exec>
</target>
</project>
' > "custom_rules.xml"
# Set NDK HOME for Ant (only if not already set)
if ! grep -P -q "ndk.dir=.+" "local.properties" ; then
echo -e "\nndk.dir=$ANDROID_NDK_HOME" >> "local.properties"
fi
# Fix for Java 8 warning (warning: [options] source value 1.5 is obsolete and will be removed in a future release)
echo "java.compilerargs=-Xlint:-options" >> "ant.properties"
# Workaround INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES error
adb uninstall "$PACKAGE"
# Build Hello JNI project in debug mode and install it on the device
ant clean && ant debug && ant installd
popd
cd ..
# Start HelloJNI app
adb shell am start -a android.intent.action.MAIN -n $PACKAGE/.HelloJni
# Make the script executable
chmod a+x bootstrap_valgrind.sh
# Run application through Valgrind on the phone
/usr/bin/env bash bootstrap_valgrind.sh
adb shell ls -lR "/sdcard/*grind*"
adb shell ls -lR "/storage/sdcard0/*grind*"
adb shell ls -lR "/storage/sdcard1/*grind*"
fi
exit 0
This gets valgrind to compile for me on linux. (using android-ndk-r8e and valgrind-3.8.1)
There was no need to run autogen.sh since I downloaded the tar ball from the website.
Also make sure the TOOLCHAIN= line points to a valid toolchain.
export NDK_HOME=$HOME/Downloads/android-ndk-r8e
export HWKIND=generic
export TOOLCHAIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi
export AR=$TOOLCHAIN-ar
export LD=$TOOLCHAIN-ld
export CC=$TOOLCHAIN-gcc
CPPFLAGS="--sysroot=$NDK_HOME/platforms/android-14/arch-arm -DANDROID_HARDWARE_$HWKIND" \
CFLAGS="--sysroot=$NDK_HOME/platforms/android-14/arch-arm" \
./configure --prefix=/data/local/Inst \
--host=armv7-unknown-linux --target=armv7-unknown-linux \
--with-tmpdir=/sdcard
make
It eventually came up with a compile error saying
$NDK_HOME/platforms/android-14/arch-arm/usr/include/elf.h:58:3: error: unknown type name 'uint32_t'
It seem like someone forgot to add #include <stdint.h> somewhere. To fix this I edited $NDK_HOME/platforms/android-14/arch-arm/usr/include/elf.h and added #include <stdint.h> to the include section of this header. NOTE: This is probably not the best fix but it is the one that I came up with that fixed the compilation errors.
On mac I was able to get it to compile up until the unknown type uint32_t part by changing how the configure script checks the kernel version.
Inside the configure script search of a line kernel=`uname -r` and change it to kernel=3.9.2. (There are two kernel=`uname -r` lines replace the first one or both if you feel like it)
This stops the configure script from looking at the host kernel when deciding how it should build valgrind. (uname -r grabs the host kernel)
I believe adding the #include <stdint.h> to elf.h should work on mac to but I have not tested it.
in android tutorial one option is missed
RANLIB, after I set it - I finally compiled valgrind-3.11.0 on osx for android
#/bin/sh
echo "NKDROOT: " $NDKROOT
export ANRDOID_TOOLCHAIN="arm-linux-androideabi-4.9"
# Set up toolchain paths.
#
# For ARM
export AR=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ar
export LD=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ld
export CC=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc
export CXX=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++
export RANLIB=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ranlib
echo "AR: " $AR
echo "LD: " $LD
echo "CC: " $CC
echo "CXX: " $CXX
[[ ! -d "$NDKROOT" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] && echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure NDKROOT is defined also" && exit -1
./autogen.sh
#if [ $? -ne 0 ]
#then
# exit 1
#else
# echo "autogen success!"
#fi
# for ARM
ANDROID_PLATFORM=android-3
ANDROID_SYSROOT="$NDKROOT/platforms/${ANDROID_PLATFORM}/arch-arm"
echo "SYSROOT: " $ANDROID_SYSROOT
export HWKIND=generic
export CPPFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export CFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export LDFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export ARFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
./configure \
--prefix=/data/local/Inst \
--host=armv7-unknown-linux --target=armv7-unknown-linux \
--with-tmpdir=/sdcard
if [ $? -ne 0 ]
then
exit 1
else
echo "configure success!"
fi
# note: on android emulator, android-14 platform was also tested and works.
# It is not clear what this platform nr really is.
make -j7
if [ $? -ne 0 ]
then
exit 1
else
echo "build success!"
fi
make -j7 install DESTDIR=`pwd`/Inst
The problem I had was that the configure script was ignoring the environment variables. To configure the make file I instead did this:
sudo ./configure --prefix=/data/local/Inst --host=armv7-unknown-linux --target=armv7-unknown-linux --with-tmpdir=/sdcard0 CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" CC=$CC LD=$LD AR=$AR
This ensures the variables are set properly and works with Linux Mint 13. It does not work on OSX Mountain Lion however. I'd advise anyone using OSX without access to a linux installation to try using linux on a virtual machine.

Compile command-line C application with Android NDK

I am trying to compile Frotz to run in a terminal emulator so it will execute on my Android Ice Cream Sandwich smartphone. Frotz is an open source Z-Machine interpreter for playing interactive fiction and is basically just a command-line application. I have done the following:
Downloaded Android NDK (android-ndk-r8d) and extracted it on my Windows 7 laptop. (Extracted to c:\android\android-ndk-r8d)
Downloaded and installed Cygwin, including all development packages. (So make is installed)
Using Cygwin, navigate to the folder containing the extracted Frotz makefile and source folder and try to execute make.
When I try run make, I encounter issues relating to curses.h not being found (but this issue is not the focus of this question; maybe a point for a followup question). When I do make dumb (which compiles a simplified version of Frotz), the compile succeeds and I am able to run it within Cygwin. But if I copy the compiled command-line application to the phone and try execute it, I get the following error:
not executable: magic 4D5A
I suspect the problem here is that the executable is now not compiled for the Arm architecture. The make file has the following line in it:
CC = gcc
which I have tried changing to:
CC = /cygdrive/c/android/android-ndk-r8d/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-gcc.exe
But now when I execute make, I get the following error message:
fatal error: signal.h: No such file or directory
I am very new to C development (and Android) and struggling to figure out how to change the makefile so that it will compile correctly for Android. I will include the complete makefile below and will appreciate whatever help anyone can offer in getting this to correctly compile for Android.
The complete Frotz makefile:
# Define your C compiler. I recommend gcc if you have it.
# MacOS users should use "cc" even though it's really "gcc".
#
CC = gcc
#CC = cc
# Define your optimization flags. Most compilers understand -O and -O2,
# Standard (note: Solaris on UltraSparc using gcc 2.8.x might not like this.)
#
OPTS = -O2
# Pentium with gcc 2.7.0 or better
#OPTS = -O2 -fomit-frame-pointer -malign-functions=2 -malign-loops=2 \
#-malign-jumps=2
# Define where you want Frotz installed. Usually this is /usr/local
PREFIX = /usr/local
MAN_PREFIX = $(PREFIX)
#MAN_PREFIX = /usr/local/share
CONFIG_DIR = $(PREFIX)/etc
#CONFIG_DIR = /etc
# Define where you want Frotz to look for frotz.conf.
#
CONFIG_DIR = /usr/local/etc
#CONFIG_DIR = /etc
#CONFIG_DIR = /usr/pkg/etc
#CONFIG_DIR =
# Uncomment this if you want color support. Most, but not all curses
# libraries that work with Frotz will support color.
#
COLOR_DEFS = -DCOLOR_SUPPORT
# Uncomment this if you have an OSS soundcard driver and want classical
# Infocom sound support.
#
#SOUND_DEFS = -DOSS_SOUND
# Uncomment this too if you're running BSD of some sort and are using
# the OSS sound driver.
#
#SOUND_LIB = -lossaudio
# Define your sound device
# This should probably be a command-line/config-file option.
#
#SOUND_DEV = /dev/dsp
#SOUND_DEV = /dev/sound
#SOUND_DEV = /dev/audio
# If your vendor-supplied curses library won't work, uncomment the
# location where ncurses.h is.
#
#INCL = -I/usr/local/include
#INCL = -I/usr/pkg/include
#INCL = -I/usr/freeware/include
#INCL = -I/5usr/include
#INCL = -I/path/to/ncurses.h
# If your vendor-supplied curses library won't work, uncomment the
# location where the ncurses library is.
#
#LIB = -L/usr/local/lib
#LIB = -L/usr/pkg/lib
#LIB = -L/usr/freeware/lib
#LIB = -L/5usr/lib
#LIB = -L/path/to/libncurses.so
# One of these must always be uncommented. If your vendor-supplied
# curses library won't work, comment out the first option and uncomment
# the second.
#
CURSES = -lcurses
#CURSES = -lncurses
# Uncomment this if your need to use ncurses instead of the
# vendor-supplied curses library. This just tells the compile process
# which header to include, so don't worry if ncurses is all you have
# (like on Linux). You'll be fine.
#
#CURSES_DEF = -DUSE_NCURSES_H
# Uncomment this if you're compiling Unix Frotz on a machine that lacks
# the memmove(3) system call. If you don't know what this means, leave it
# alone.
#
#MEMMOVE_DEF = -DNO_MEMMOVE
# Uncomment this if for some wacky reason you want to compile Unix Frotz
# under Cygwin under Windoze. This sort of thing is not reccomended.
#
#EXTENSION = .exe
#####################################################
# Nothing under this line should need to be changed.
#####################################################
SRCDIR = src
VERSION = 2.43d
NAME = frotz
BINNAME = $(NAME)
DISTFILES = bugtest
DISTNAME = $(BINNAME)-$(VERSION)
distdir = $(DISTNAME)
COMMON_DIR = $(SRCDIR)/common
COMMON_TARGET = $(SRCDIR)/frotz_common.a
COMMON_OBJECT = $(COMMON_DIR)/buffer.o \
$(COMMON_DIR)/err.o \
$(COMMON_DIR)/fastmem.o \
$(COMMON_DIR)/files.o \
$(COMMON_DIR)/hotkey.o \
$(COMMON_DIR)/input.o \
$(COMMON_DIR)/main.o \
$(COMMON_DIR)/math.o \
$(COMMON_DIR)/object.o \
$(COMMON_DIR)/process.o \
$(COMMON_DIR)/quetzal.o \
$(COMMON_DIR)/random.o \
$(COMMON_DIR)/redirect.o \
$(COMMON_DIR)/screen.o \
$(COMMON_DIR)/sound.o \
$(COMMON_DIR)/stream.o \
$(COMMON_DIR)/table.o \
$(COMMON_DIR)/text.o \
$(COMMON_DIR)/variable.o
CURSES_DIR = $(SRCDIR)/curses
CURSES_TARGET = $(SRCDIR)/frotz_curses.a
CURSES_OBJECT = $(CURSES_DIR)/ux_init.o \
$(CURSES_DIR)/ux_input.o \
$(CURSES_DIR)/ux_pic.o \
$(CURSES_DIR)/ux_screen.o \
$(CURSES_DIR)/ux_text.o \
$(CURSES_DIR)/ux_audio_none.o \
$(CURSES_DIR)/ux_audio_oss.o
DUMB_DIR = $(SRCDIR)/dumb
DUMB_TARGET = $(SRCDIR)/frotz_dumb.a
DUMB_OBJECT = $(DUMB_DIR)/dumb_init.o \
$(DUMB_DIR)/dumb_input.o \
$(DUMB_DIR)/dumb_output.o \
$(DUMB_DIR)/dumb_pic.o
TARGETS = $(COMMON_TARGET) $(CURSES_TARGET)
OPT_DEFS = -DCONFIG_DIR="\"$(CONFIG_DIR)\"" $(CURSES_DEF) \
-DVERSION="\"$(VERSION)\"" -DSOUND_DEV="\"$(SOUND_DEV)\""
COMP_DEFS = $(OPT_DEFS) $(COLOR_DEFS) $(SOUND_DEFS) $(SOUNDCARD) \
$(MEMMOVE_DEF)
FLAGS = $(OPTS) $(COMP_DEFS) $(INCL)
$(NAME): $(NAME)-curses
$(NAME)-curses: soundcard.h $(COMMON_TARGET) $(CURSES_TARGET)
$(CC) -o $(BINNAME)$(EXTENSION) $(TARGETS) $(LIB) $(CURSES) \
$(SOUND_LIB)
all: $(NAME) d$(NAME)
dumb: $(NAME)-dumb
d$(NAME): $(NAME)-dumb
$(NAME)-dumb: $(COMMON_TARGET) $(DUMB_TARGET)
$(CC) -o d$(BINNAME)$(EXTENSION) $(COMMON_TARGET) \
$(DUMB_TARGET) $(LIB)
.SUFFIXES:
.SUFFIXES: .c .o .h
.c.o:
$(CC) $(FLAGS) $(CFLAGS) -o $# -c $<
# If you're going to make this target manually, you'd better know which
# config target to make first.
#
common_lib: $(COMMON_TARGET)
$(COMMON_TARGET): $(COMMON_OBJECT)
#echo
#echo "Archiving common code..."
ar rc $(COMMON_TARGET) $(COMMON_OBJECT)
ranlib $(COMMON_TARGET)
#echo
curses_lib: config_curses $(CURSES_TARGET)
$(CURSES_TARGET): $(CURSES_OBJECT)
#echo
#echo "Archiving curses interface code..."
ar rc $(CURSES_TARGET) $(CURSES_OBJECT)
ranlib $(CURSES_TARGET)
#echo
dumb_lib: $(DUMB_TARGET)
$(DUMB_TARGET): $(DUMB_OBJECT)
#echo
#echo "Archiving dumb interface code..."
ar rc $(DUMB_TARGET) $(DUMB_OBJECT)
ranlib $(DUMB_TARGET)
#echo
soundcard.h:
#if [ ! -f $(SRCDIR)/soundcard.h ] ; then \
sh $(SRCDIR)/misc/findsound.sh $(SRCDIR); \
fi
install: $(NAME)
strip $(BINNAME)$(EXTENSION)
install -d $(PREFIX)/bin
install -d $(MAN_PREFIX)/man/man6
install -c -m 755 $(BINNAME)$(EXTENSION) $(PREFIX)/bin
install -c -m 644 doc/$(NAME).6 $(MAN_PREFIX)/man/man6
uninstall:
rm -f $(PREFIX)/bin/$(NAME)
rm -f $(MAN_PREFIX)/man/man6/$(NAME).6
deinstall: uninstall
install_dumb: d$(NAME)
strip d$(BINNAME)$(EXTENSION)
install -d $(PREFIX)/bin
install -d $(MAN_PREFIX)/man/man6
install -c -m 755 d$(BINNAME)$(EXTENSION) $(PREFIX)/bin
install -c -m 644 doc/d$(NAME).6 $(MAN_PREFIX)/man/man6
uninstall_dumb:
rm -f $(PREFIX)/bin/d$(NAME)
rm -f $(MAN_PREFIX)/man/man6/d$(NAME).6
deinstall_dumb: uninstall_dumb
distro: dist
dist: distclean
mkdir $(distdir)
#for file in `ls`; do \
if test $$file != $(distdir); then \
cp -Rp $$file $(distdir)/$$file; \
fi; \
done
find $(distdir) -type l -exec rm -f {} \;
tar chof $(distdir).tar $(distdir)
gzip -f --best $(distdir).tar
rm -rf $(distdir)
#echo
#echo "$(distdir).tar.gz created"
#echo
clean:
rm -f $(SRCDIR)/*.h $(SRCDIR)/*.a
rm -f $(COMMON_DIR)/*.o $(CURSES_DIR)/*.o $(DUMB_DIR)/*.o
distclean: clean
rm -f $(BINNAME)$(EXTENSION) d$(BINNAME)$(EXTENSION)
rm -f $(BINNAME).exe $(BINNAME).bak $(BINNAME).lib
rm -f *core $(SRCDIR)/*core
-rm -rf $(distdir)
-rm -f $(distdir).tar $(distdir).tar.gz
realclean: distclean
clobber: distclean
help:
#echo
#echo "Targets:"
#echo " frotz"
#echo " dfrotz"
#echo " install"
#echo " uninstall"
#echo " clean"
#echo " distclean"
#echo
With android-ndk-r8d, you don't need cygwin: make can be found in c:\android\android-ndk-r8d\prebuilt\windows32\bin.
Anyways, to use a makefile, you should follow the instructions in c:\android\android-ndk-r8d\STANDALONE-TOOLCHAIN.html

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