sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 1 | |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 2 | How to cross-compile and run on Android. Please read to the end, |
| 3 | since there are important details further down regarding crash |
| 4 | avoidance and GPU support. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 5 | |
sewardj | 26ed419 | 2014-11-04 17:44:21 +0000 | [diff] [blame] | 6 | These notes were last updated on 4 Nov 2014, for Valgrind SVN |
| 7 | revision 14689/2987. |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 8 | |
| 9 | These instructions are known to work, or have worked at some time in |
| 10 | the past, for: |
| 11 | |
| 12 | arm: |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 13 | Android 4.0.3 running on a (rooted, AOSP build) Nexus S. |
| 14 | Android 4.0.3 running on Motorola Xoom. |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 15 | Android 4.0.3 running on android arm emulator. |
philippe | 77c1185 | 2012-07-18 23:01:02 +0000 | [diff] [blame] | 16 | Android 4.1 running on android emulator. |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 17 | Android 2.3.4 on Nexus S worked at some time in the past. |
philippe | 77c1185 | 2012-07-18 23:01:02 +0000 | [diff] [blame] | 18 | |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 19 | x86: |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 20 | Android 4.0.3 running on android x86 emulator. |
| 21 | |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 22 | mips32: |
| 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 | |
sewardj | 26ed419 | 2014-11-04 17:44:21 +0000 | [diff] [blame] | 28 | arm64: |
| 29 | Android 4.5 (?) running on ARM Juno |
| 30 | |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 31 | On android-arm, GDBserver might insert breaks at wrong addresses. |
philippe | 77c1185 | 2012-07-18 23:01:02 +0000 | [diff] [blame] | 32 | Feedback on this welcome. |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 33 | |
| 34 | Other configurations and toolchains might work, but haven't been tested. |
sewardj | 0a64a7a | 2012-02-17 15:13:55 +0000 | [diff] [blame] | 35 | Feedback is welcome. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 36 | |
sewardj | 26ed419 | 2014-11-04 17:44:21 +0000 | [diff] [blame] | 37 | Toolchain: |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 38 | |
sewardj | 26ed419 | 2014-11-04 17:44:21 +0000 | [diff] [blame] | 39 | 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. |
sewardj | 0a64a7a | 2012-02-17 15:13:55 +0000 | [diff] [blame] | 44 | |
sewardj | 26ed419 | 2014-11-04 17:44:21 +0000 | [diff] [blame] | 45 | 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 | |
| 51 | Install the NDK somewhere. Doesn't matter where. Then: |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 52 | |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 53 | |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 54 | # 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. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 57 | # |
sewardj | 26ed419 | 2014-11-04 17:44:21 +0000 | [diff] [blame] | 58 | export NDKROOT=/path/to/android-ndk-r<version> |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 59 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 60 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 61 | # Then cd to the root of your Valgrind source tree. |
| 62 | # |
| 63 | cd /path/to/valgrind/source/tree |
| 64 | |
| 65 | |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 66 | # After this point, you don't need to modify anything. Just copy and |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 67 | # paste the commands below. |
| 68 | |
| 69 | |
| 70 | # Set up toolchain paths. |
| 71 | # |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 72 | # For ARM |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 73 | export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar |
| 74 | export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld |
| 75 | export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc |
| 76 | |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 77 | # For x86 |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 78 | export AR=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ar |
| 79 | export LD=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ld |
| 80 | export CC=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc |
| 81 | |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 82 | # For MIPS32 |
| 83 | export AR=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ar |
| 84 | export LD=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ld |
| 85 | export CC=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-gcc |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 86 | |
sewardj | 26ed419 | 2014-11-04 17:44:21 +0000 | [diff] [blame] | 87 | # For ARM64 (AArch64) |
| 88 | export AR=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar |
| 89 | export LD=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld |
| 90 | export CC=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc |
| 91 | |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 92 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 93 | # Do configuration stuff. Don't mess with the --prefix in the |
| 94 | # configure command below, even if you think it's wrong. |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 95 | # You may need to set the --with-tmpdir path to something |
sewardj | 1b3a7a4 | 2011-10-26 15:10:49 +0000 | [diff] [blame] | 96 | # different if /sdcard doesn't work on the device -- this is |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 97 | # a known cause of difficulties. |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 98 | |
philippe | 7d9b41b | 2012-09-11 19:53:01 +0000 | [diff] [blame] | 99 | # The below re-generates configure, Makefiles, ... |
| 100 | # This is not needed if you start from a release tarball. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 101 | ./autogen.sh |
| 102 | |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 103 | # for ARM |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 104 | CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \ |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 105 | CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \ |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 106 | ./configure --prefix=/data/local/Inst \ |
| 107 | --host=armv7-unknown-linux --target=armv7-unknown-linux \ |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 108 | --with-tmpdir=/sdcard |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 109 | # note: on android emulator, android-14 platform was also tested and works. |
| 110 | # It is not clear what this platform nr really is. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 111 | |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 112 | # for x86 |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 113 | CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86" \ |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 114 | 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 | |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 119 | # for MIPS32 |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 120 | CPPFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips" \ |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 121 | 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 | |
sewardj | 26ed419 | 2014-11-04 17:44:21 +0000 | [diff] [blame] | 126 | # for ARM64 (AArch64) |
| 127 | CPPFLAGS="--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 | |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 133 | |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 134 | # At the end of the configure run, a few lines of details |
| 135 | # are printed. Make sure that you see these two lines: |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 136 | # |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 137 | # For ARM: |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 138 | # Platform variant: android |
| 139 | # Primary -DVGPV string: -DVGPV_arm_linux_android=1 |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 140 | # |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 141 | # For x86: |
| 142 | # Platform variant: android |
| 143 | # Primary -DVGPV string: -DVGPV_x86_linux_android=1 |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 144 | # |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 145 | # For mips32: |
| 146 | # Platform variant: android |
| 147 | # Primary -DVGPV string: -DVGPV_mips32_linux_android=1 |
| 148 | # |
sewardj | 26ed419 | 2014-11-04 17:44:21 +0000 | [diff] [blame] | 149 | # For ARM64 (AArch64): |
| 150 | # Platform variant: android |
| 151 | # Primary -DVGPV string: -DVGPV_arm64_linux_android=1 |
| 152 | # |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 153 | # 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 |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 159 | # |
sewardj | 26ed419 | 2014-11-04 17:44:21 +0000 | [diff] [blame] | 160 | make -j4 |
| 161 | make -j4 install DESTDIR=`pwd`/Inst |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 162 | |
| 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 | # |
| 168 | adb push Inst / |
| 169 | |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 170 | |
| 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] |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 190 | |
| 191 | |
| 192 | # Once you're up and running, a handy modify-V-rebuild-reinstall |
| 193 | # command line (on the host, of course) is |
| 194 | # |
| 195 | mq -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. |