blob: 891dcb3078f2409262d4a819f38551ea084570bf [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
sewardj4450a0e2014-09-03 15:19:25 +00006These notes were last updated on 3 Sept 2014, for Valgrind SVN
7revision 14439/2941.
8
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
sewardjca456c72012-08-05 13:44:15 +000028On android-arm, GDBserver might insert breaks at wrong addresses.
philippe77c11852012-07-18 23:01:02 +000029Feedback on this welcome.
philippeeeb07332012-07-04 21:59:29 +000030
31Other configurations and toolchains might work, but haven't been tested.
sewardj0a64a7a2012-02-17 15:13:55 +000032Feedback is welcome.
sewardj37ed97b2011-07-12 13:34:31 +000033
philippeeeb07332012-07-04 21:59:29 +000034
sewardj0a64a7a2012-02-17 15:13:55 +000035You need the android-ndk-r6 native development kit. r6b and r7
36give a non-completely-working build; see
37http://code.google.com/p/android/issues/detail?id=23203
philippeeeb07332012-07-04 21:59:29 +000038For the android emulator, the versions needed and how to
39install them are described in README.android_emulator.
sewardj0a64a7a2012-02-17 15:13:55 +000040
sewardjda0b9402014-05-13 09:29:33 +000041You can get android-ndk-r6 from
42http://dl.google.com/android/ndk/android-ndk-r6-linux-x86.tar.bz2
sewardj4450a0e2014-09-03 15:19:25 +000043Install it somewhere. Doesn't matter where. Then:
sewardj37ed97b2011-07-12 13:34:31 +000044
sewardj37ed97b2011-07-12 13:34:31 +000045
sewardjfb9c9622011-09-27 11:54:01 +000046# Modify this (obviously). Note, this "export" command is only done
47# so as to reduce the amount of typing required. None of the commands
48# below read it as part of their operation.
sewardj37ed97b2011-07-12 13:34:31 +000049#
sewardja0b4dbc2011-09-10 11:28:51 +000050export NDKROOT=/path/to/android-ndk-r6
sewardj37ed97b2011-07-12 13:34:31 +000051
sewardja0b4dbc2011-09-10 11:28:51 +000052
sewardja0b4dbc2011-09-10 11:28:51 +000053# Then cd to the root of your Valgrind source tree.
54#
55cd /path/to/valgrind/source/tree
56
57
sewardj4450a0e2014-09-03 15:19:25 +000058# After this point, you don't need to modify anything. Just copy and
sewardjfb9c9622011-09-27 11:54:01 +000059# paste the commands below.
60
61
62# Set up toolchain paths.
63#
sewardjca456c72012-08-05 13:44:15 +000064# For ARM
sewardjfb9c9622011-09-27 11:54:01 +000065export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
66export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
67export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
68
sewardjca456c72012-08-05 13:44:15 +000069# For x86
philippe5d5dd8e2012-08-05 00:08:25 +000070export AR=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ar
71export LD=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ld
72export CC=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc
73
dejanj9c6b05d2013-12-27 09:06:55 +000074# For MIPS32
75export AR=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ar
76export LD=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ld
77export CC=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-gcc
sewardjfb9c9622011-09-27 11:54:01 +000078
sewardj4450a0e2014-09-03 15:19:25 +000079
sewardja0b4dbc2011-09-10 11:28:51 +000080# Do configuration stuff. Don't mess with the --prefix in the
81# configure command below, even if you think it's wrong.
sewardjfb9c9622011-09-27 11:54:01 +000082# You may need to set the --with-tmpdir path to something
sewardj1b3a7a42011-10-26 15:10:49 +000083# different if /sdcard doesn't work on the device -- this is
sewardjfb9c9622011-09-27 11:54:01 +000084# a known cause of difficulties.
sewardja0b4dbc2011-09-10 11:28:51 +000085
philippe7d9b41b2012-09-11 19:53:01 +000086# The below re-generates configure, Makefiles, ...
87# This is not needed if you start from a release tarball.
sewardj37ed97b2011-07-12 13:34:31 +000088./autogen.sh
89
philippe5d5dd8e2012-08-05 00:08:25 +000090# for ARM
sewardj4450a0e2014-09-03 15:19:25 +000091CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
sewardja0b4dbc2011-09-10 11:28:51 +000092 CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
sewardj37ed97b2011-07-12 13:34:31 +000093 ./configure --prefix=/data/local/Inst \
94 --host=armv7-unknown-linux --target=armv7-unknown-linux \
sewardja0b4dbc2011-09-10 11:28:51 +000095 --with-tmpdir=/sdcard
philippeeeb07332012-07-04 21:59:29 +000096# note: on android emulator, android-14 platform was also tested and works.
97# It is not clear what this platform nr really is.
sewardj37ed97b2011-07-12 13:34:31 +000098
philippe5d5dd8e2012-08-05 00:08:25 +000099# for x86
sewardj4450a0e2014-09-03 15:19:25 +0000100CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86" \
philippe5d5dd8e2012-08-05 00:08:25 +0000101 CFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -fno-pic" \
102 ./configure --prefix=/data/local/Inst \
103 --host=i686-android-linux --target=i686-android-linux \
104 --with-tmpdir=/sdcard
105
dejanj9c6b05d2013-12-27 09:06:55 +0000106# for MIPS32
sewardj4450a0e2014-09-03 15:19:25 +0000107CPPFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips" \
dejanj9c6b05d2013-12-27 09:06:55 +0000108 CFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips" \
109 ./configure --prefix=/data/local/Inst \
110 --host=mipsel-linux-android --target=mipsel-linux-android \
111 --with-tmpdir=/sdcard
112
sewardj4450a0e2014-09-03 15:19:25 +0000113
sewardj37ed97b2011-07-12 13:34:31 +0000114# At the end of the configure run, a few lines of details
115# are printed. Make sure that you see these two lines:
sewardjca456c72012-08-05 13:44:15 +0000116#
philippe5d5dd8e2012-08-05 00:08:25 +0000117# For ARM:
sewardj37ed97b2011-07-12 13:34:31 +0000118# Platform variant: android
119# Primary -DVGPV string: -DVGPV_arm_linux_android=1
sewardjca456c72012-08-05 13:44:15 +0000120#
philippe5d5dd8e2012-08-05 00:08:25 +0000121# For x86:
122# Platform variant: android
123# Primary -DVGPV string: -DVGPV_x86_linux_android=1
sewardj37ed97b2011-07-12 13:34:31 +0000124#
dejanj9c6b05d2013-12-27 09:06:55 +0000125# For mips32:
126# Platform variant: android
127# Primary -DVGPV string: -DVGPV_mips32_linux_android=1
128#
sewardj37ed97b2011-07-12 13:34:31 +0000129# If you see anything else at this point, something is wrong, and
130# either the build will fail, or will succeed but you'll get something
131# which won't work.
132
133
134# Build, and park the install tree in `pwd`/Inst
sewardja0b4dbc2011-09-10 11:28:51 +0000135#
136make -j2
137make -j2 install DESTDIR=`pwd`/Inst
sewardj37ed97b2011-07-12 13:34:31 +0000138
139
140# To get the install tree onto the device:
141# (I don't know why it's not "adb push Inst /data/local", but this
142# formulation does appear to put the result in /data/local/Inst.)
143#
144adb push Inst /
145
sewardj4450a0e2014-09-03 15:19:25 +0000146
147# To run (on the device). There are two things you need to consider:
148#
149# (1) if you are running on the Android emulator, Valgrind may crash
150# at startup. This is because the emulator (for ARM) may not be
151# simulating a hardware TLS register. To get around this, run
152# Valgrind with:
153# --kernel-variant=android-emulator-no-hw-tls
154#
155# (2) if you are running a real device, you need to tell Valgrind
156# what GPU it has, so Valgrind knows how to handle custom GPU
157# ioctls. You can choose one of the following:
158# --kernel-variant=android-gpu-sgx5xx # PowerVR SGX 5XX series
159# --kernel-variant=android-gpu-adreno3xx # Qualcomm Adreno 3XX series
160# If you don't choose one, the program will still run, but Memcheck
161# may report false errors after the program performs GPU-specific ioctls.
162#
163# Anyway: to run on the device:
164#
165/data/local/Inst/bin/valgrind [kernel variant args] [the usual args etc]
sewardja0b4dbc2011-09-10 11:28:51 +0000166
167
168# Once you're up and running, a handy modify-V-rebuild-reinstall
169# command line (on the host, of course) is
170#
171mq -j2 && mq -j2 install DESTDIR=`pwd`/Inst && adb push Inst /
172#
173# where 'mq' is an alias for 'make --quiet'.
174
175
176# One common cause of runs failing at startup is the inability of
177# Valgrind to find a suitable temporary directory. On the device,
178# there doesn't seem to be any one location which we always have
179# permission to write to. The instructions above use /sdcard. If
180# that doesn't work for you, and you're Valgrinding one specific
181# application which is already installed, you could try using its
182# temporary directory, in /data/data, for example
183# /data/data/org.mozilla.firefox_beta.
184#
185# Using /system/bin/logcat on the device is helpful for diagnosing
186# these kinds of problems.