blob: 01cd2fa2178dedb10588a0449d2a4f48d0487bfa [file] [log] [blame]
sewardj37ed97b2011-07-12 13:34:31 +00001
sewardj4450a0e2014-09-03 15:19:25 +00002How to cross-compile and run on Android. Please read to the end,
3since there are important details further down regarding crash
4avoidance and GPU support.
sewardj37ed97b2011-07-12 13:34:31 +00005
sewardj26ed4192014-11-04 17:44:21 +00006These notes were last updated on 4 Nov 2014, for Valgrind SVN
7revision 14689/2987.
sewardj4450a0e2014-09-03 15:19:25 +00008
9These instructions are known to work, or have worked at some time in
10the past, for:
11
12arm:
philippeeeb07332012-07-04 21:59:29 +000013 Android 4.0.3 running on a (rooted, AOSP build) Nexus S.
14 Android 4.0.3 running on Motorola Xoom.
philippe5d5dd8e2012-08-05 00:08:25 +000015 Android 4.0.3 running on android arm emulator.
philippe77c11852012-07-18 23:01:02 +000016 Android 4.1 running on android emulator.
sewardjca456c72012-08-05 13:44:15 +000017 Android 2.3.4 on Nexus S worked at some time in the past.
philippe77c11852012-07-18 23:01:02 +000018
philippe5d5dd8e2012-08-05 00:08:25 +000019x86:
philippe5d5dd8e2012-08-05 00:08:25 +000020 Android 4.0.3 running on android x86 emulator.
21
dejanj9c6b05d2013-12-27 09:06:55 +000022mips32:
23 Android 4.1.2 running on android mips emulator.
24 Android 4.2.2 running on android mips emulator.
25 Android 4.3 running on android mips emulator.
26 Android 4.0.4 running on BROADCOM bcm7425
27
sewardj26ed4192014-11-04 17:44:21 +000028arm64:
29 Android 4.5 (?) running on ARM Juno
30
sewardjca456c72012-08-05 13:44:15 +000031On android-arm, GDBserver might insert breaks at wrong addresses.
philippe77c11852012-07-18 23:01:02 +000032Feedback on this welcome.
philippeeeb07332012-07-04 21:59:29 +000033
34Other configurations and toolchains might work, but haven't been tested.
sewardj0a64a7a2012-02-17 15:13:55 +000035Feedback is welcome.
sewardj37ed97b2011-07-12 13:34:31 +000036
sewardj26ed4192014-11-04 17:44:21 +000037Toolchain:
philippeeeb07332012-07-04 21:59:29 +000038
sewardj26ed4192014-11-04 17:44:21 +000039 For arm32, x86 and mips32 you need the android-ndk-r6 native
40 development kit. r6b and r7 give a non-completely-working build;
41 see http://code.google.com/p/android/issues/detail?id=23203
42 For the android emulator, the versions needed and how to install
43 them are described in README.android_emulator.
sewardj0a64a7a2012-02-17 15:13:55 +000044
sewardj26ed4192014-11-04 17:44:21 +000045 You can get android-ndk-r6 from
46 http://dl.google.com/android/ndk/android-ndk-r6-linux-x86.tar.bz2
47
48 For arm64 (aarch64) you need the android-ndk-r10c NDK, from
49 http://dl.google.com/android/ndk/android-ndk-r10c-linux-x86_64.bin
50
51Install the NDK somewhere. Doesn't matter where. Then:
sewardj37ed97b2011-07-12 13:34:31 +000052
sewardj37ed97b2011-07-12 13:34:31 +000053
sewardjfb9c9622011-09-27 11:54:01 +000054# Modify this (obviously). Note, this "export" command is only done
55# so as to reduce the amount of typing required. None of the commands
56# below read it as part of their operation.
sewardj37ed97b2011-07-12 13:34:31 +000057#
sewardj26ed4192014-11-04 17:44:21 +000058export NDKROOT=/path/to/android-ndk-r<version>
sewardj37ed97b2011-07-12 13:34:31 +000059
sewardja0b4dbc2011-09-10 11:28:51 +000060
sewardja0b4dbc2011-09-10 11:28:51 +000061# Then cd to the root of your Valgrind source tree.
62#
63cd /path/to/valgrind/source/tree
64
65
sewardj4450a0e2014-09-03 15:19:25 +000066# After this point, you don't need to modify anything. Just copy and
sewardjfb9c9622011-09-27 11:54:01 +000067# paste the commands below.
68
69
70# Set up toolchain paths.
71#
sewardjca456c72012-08-05 13:44:15 +000072# For ARM
sewardjfb9c9622011-09-27 11:54:01 +000073export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
74export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
75export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
76
sewardjca456c72012-08-05 13:44:15 +000077# For x86
philippe5d5dd8e2012-08-05 00:08:25 +000078export AR=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ar
79export LD=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ld
80export CC=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc
81
dejanj9c6b05d2013-12-27 09:06:55 +000082# For MIPS32
83export AR=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ar
84export LD=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ld
85export CC=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-gcc
sewardjfb9c9622011-09-27 11:54:01 +000086
sewardj26ed4192014-11-04 17:44:21 +000087# For ARM64 (AArch64)
88export AR=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar
89export LD=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld
90export CC=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc
91
sewardj4450a0e2014-09-03 15:19:25 +000092
sewardja0b4dbc2011-09-10 11:28:51 +000093# Do configuration stuff. Don't mess with the --prefix in the
94# configure command below, even if you think it's wrong.
sewardjfb9c9622011-09-27 11:54:01 +000095# You may need to set the --with-tmpdir path to something
sewardj1b3a7a42011-10-26 15:10:49 +000096# different if /sdcard doesn't work on the device -- this is
sewardjfb9c9622011-09-27 11:54:01 +000097# a known cause of difficulties.
sewardja0b4dbc2011-09-10 11:28:51 +000098
philippe7d9b41b2012-09-11 19:53:01 +000099# The below re-generates configure, Makefiles, ...
100# This is not needed if you start from a release tarball.
sewardj37ed97b2011-07-12 13:34:31 +0000101./autogen.sh
102
philippe5d5dd8e2012-08-05 00:08:25 +0000103# for ARM
sewardj4450a0e2014-09-03 15:19:25 +0000104CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
sewardja0b4dbc2011-09-10 11:28:51 +0000105 CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
sewardj37ed97b2011-07-12 13:34:31 +0000106 ./configure --prefix=/data/local/Inst \
107 --host=armv7-unknown-linux --target=armv7-unknown-linux \
sewardja0b4dbc2011-09-10 11:28:51 +0000108 --with-tmpdir=/sdcard
philippeeeb07332012-07-04 21:59:29 +0000109# note: on android emulator, android-14 platform was also tested and works.
110# It is not clear what this platform nr really is.
sewardj37ed97b2011-07-12 13:34:31 +0000111
philippe5d5dd8e2012-08-05 00:08:25 +0000112# for x86
sewardj4450a0e2014-09-03 15:19:25 +0000113CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86" \
philippe5d5dd8e2012-08-05 00:08:25 +0000114 CFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -fno-pic" \
115 ./configure --prefix=/data/local/Inst \
116 --host=i686-android-linux --target=i686-android-linux \
117 --with-tmpdir=/sdcard
118
dejanj9c6b05d2013-12-27 09:06:55 +0000119# for MIPS32
sewardj4450a0e2014-09-03 15:19:25 +0000120CPPFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips" \
dejanj9c6b05d2013-12-27 09:06:55 +0000121 CFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips" \
122 ./configure --prefix=/data/local/Inst \
123 --host=mipsel-linux-android --target=mipsel-linux-android \
124 --with-tmpdir=/sdcard
125
sewardj26ed4192014-11-04 17:44:21 +0000126# for ARM64 (AArch64)
127CPPFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm64" \
128 CFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm64" \
129 ./configure --prefix=/data/local/Inst \
130 --host=aarch64-unknown-linux --target=aarch64-unknown-linux \
131 --with-tmpdir=/sdcard
132
sewardj4450a0e2014-09-03 15:19:25 +0000133
sewardj37ed97b2011-07-12 13:34:31 +0000134# At the end of the configure run, a few lines of details
135# are printed. Make sure that you see these two lines:
sewardjca456c72012-08-05 13:44:15 +0000136#
philippe5d5dd8e2012-08-05 00:08:25 +0000137# For ARM:
sewardj37ed97b2011-07-12 13:34:31 +0000138# Platform variant: android
139# Primary -DVGPV string: -DVGPV_arm_linux_android=1
sewardjca456c72012-08-05 13:44:15 +0000140#
philippe5d5dd8e2012-08-05 00:08:25 +0000141# For x86:
142# Platform variant: android
143# Primary -DVGPV string: -DVGPV_x86_linux_android=1
sewardj37ed97b2011-07-12 13:34:31 +0000144#
dejanj9c6b05d2013-12-27 09:06:55 +0000145# For mips32:
146# Platform variant: android
147# Primary -DVGPV string: -DVGPV_mips32_linux_android=1
148#
sewardj26ed4192014-11-04 17:44:21 +0000149# For ARM64 (AArch64):
150# Platform variant: android
151# Primary -DVGPV string: -DVGPV_arm64_linux_android=1
152#
sewardj37ed97b2011-07-12 13:34:31 +0000153# If you see anything else at this point, something is wrong, and
154# either the build will fail, or will succeed but you'll get something
155# which won't work.
156
157
158# Build, and park the install tree in `pwd`/Inst
sewardja0b4dbc2011-09-10 11:28:51 +0000159#
sewardj26ed4192014-11-04 17:44:21 +0000160make -j4
161make -j4 install DESTDIR=`pwd`/Inst
sewardj37ed97b2011-07-12 13:34:31 +0000162
163
164# To get the install tree onto the device:
165# (I don't know why it's not "adb push Inst /data/local", but this
166# formulation does appear to put the result in /data/local/Inst.)
167#
168adb push Inst /
169
sewardj4450a0e2014-09-03 15:19:25 +0000170
171# To run (on the device). There are two things you need to consider:
172#
173# (1) if you are running on the Android emulator, Valgrind may crash
174# at startup. This is because the emulator (for ARM) may not be
175# simulating a hardware TLS register. To get around this, run
176# Valgrind with:
177# --kernel-variant=android-emulator-no-hw-tls
178#
179# (2) if you are running a real device, you need to tell Valgrind
180# what GPU it has, so Valgrind knows how to handle custom GPU
181# ioctls. You can choose one of the following:
182# --kernel-variant=android-gpu-sgx5xx # PowerVR SGX 5XX series
183# --kernel-variant=android-gpu-adreno3xx # Qualcomm Adreno 3XX series
184# If you don't choose one, the program will still run, but Memcheck
185# may report false errors after the program performs GPU-specific ioctls.
186#
187# Anyway: to run on the device:
188#
189/data/local/Inst/bin/valgrind [kernel variant args] [the usual args etc]
sewardja0b4dbc2011-09-10 11:28:51 +0000190
191
192# Once you're up and running, a handy modify-V-rebuild-reinstall
193# command line (on the host, of course) is
194#
195mq -j2 && mq -j2 install DESTDIR=`pwd`/Inst && adb push Inst /
196#
197# where 'mq' is an alias for 'make --quiet'.
198
199
200# One common cause of runs failing at startup is the inability of
201# Valgrind to find a suitable temporary directory. On the device,
202# there doesn't seem to be any one location which we always have
203# permission to write to. The instructions above use /sdcard. If
204# that doesn't work for you, and you're Valgrinding one specific
205# application which is already installed, you could try using its
206# temporary directory, in /data/data, for example
207# /data/data/org.mozilla.firefox_beta.
208#
209# Using /system/bin/logcat on the device is helpful for diagnosing
210# these kinds of problems.