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 | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 6 | These notes were last updated on 3 Sept 2014, for Valgrind SVN |
| 7 | revision 14439/2941. |
| 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 | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 28 | On android-arm, GDBserver might insert breaks at wrong addresses. |
philippe | 77c1185 | 2012-07-18 23:01:02 +0000 | [diff] [blame] | 29 | Feedback on this welcome. |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 30 | |
| 31 | Other configurations and toolchains might work, but haven't been tested. |
sewardj | 0a64a7a | 2012-02-17 15:13:55 +0000 | [diff] [blame] | 32 | Feedback is welcome. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 33 | |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 34 | |
sewardj | 0a64a7a | 2012-02-17 15:13:55 +0000 | [diff] [blame] | 35 | You need the android-ndk-r6 native development kit. r6b and r7 |
| 36 | give a non-completely-working build; see |
| 37 | http://code.google.com/p/android/issues/detail?id=23203 |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 38 | For the android emulator, the versions needed and how to |
| 39 | install them are described in README.android_emulator. |
sewardj | 0a64a7a | 2012-02-17 15:13:55 +0000 | [diff] [blame] | 40 | |
sewardj | da0b940 | 2014-05-13 09:29:33 +0000 | [diff] [blame] | 41 | You can get android-ndk-r6 from |
| 42 | http://dl.google.com/android/ndk/android-ndk-r6-linux-x86.tar.bz2 |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 43 | Install it somewhere. Doesn't matter where. Then: |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 44 | |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 45 | |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 46 | # 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. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 49 | # |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 50 | export NDKROOT=/path/to/android-ndk-r6 |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 51 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 52 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 53 | # Then cd to the root of your Valgrind source tree. |
| 54 | # |
| 55 | cd /path/to/valgrind/source/tree |
| 56 | |
| 57 | |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 58 | # After this point, you don't need to modify anything. Just copy and |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 59 | # paste the commands below. |
| 60 | |
| 61 | |
| 62 | # Set up toolchain paths. |
| 63 | # |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 64 | # For ARM |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 65 | export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar |
| 66 | export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld |
| 67 | export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc |
| 68 | |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 69 | # For x86 |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 70 | export AR=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ar |
| 71 | export LD=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ld |
| 72 | export CC=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc |
| 73 | |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 74 | # For MIPS32 |
| 75 | export AR=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ar |
| 76 | export LD=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ld |
| 77 | 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] | 78 | |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 79 | |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 80 | # Do configuration stuff. Don't mess with the --prefix in the |
| 81 | # configure command below, even if you think it's wrong. |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 82 | # You may need to set the --with-tmpdir path to something |
sewardj | 1b3a7a4 | 2011-10-26 15:10:49 +0000 | [diff] [blame] | 83 | # different if /sdcard doesn't work on the device -- this is |
sewardj | fb9c962 | 2011-09-27 11:54:01 +0000 | [diff] [blame] | 84 | # a known cause of difficulties. |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 85 | |
philippe | 7d9b41b | 2012-09-11 19:53:01 +0000 | [diff] [blame] | 86 | # The below re-generates configure, Makefiles, ... |
| 87 | # This is not needed if you start from a release tarball. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 88 | ./autogen.sh |
| 89 | |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 90 | # for ARM |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 91 | CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \ |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 92 | CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \ |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 93 | ./configure --prefix=/data/local/Inst \ |
| 94 | --host=armv7-unknown-linux --target=armv7-unknown-linux \ |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 95 | --with-tmpdir=/sdcard |
philippe | eeb0733 | 2012-07-04 21:59:29 +0000 | [diff] [blame] | 96 | # note: on android emulator, android-14 platform was also tested and works. |
| 97 | # It is not clear what this platform nr really is. |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 98 | |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 99 | # for x86 |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 100 | CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86" \ |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 101 | 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 | |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 106 | # for MIPS32 |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 107 | CPPFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips" \ |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 108 | 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 | |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 113 | |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 114 | # At the end of the configure run, a few lines of details |
| 115 | # are printed. Make sure that you see these two lines: |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 116 | # |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 117 | # For ARM: |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 118 | # Platform variant: android |
| 119 | # Primary -DVGPV string: -DVGPV_arm_linux_android=1 |
sewardj | ca456c7 | 2012-08-05 13:44:15 +0000 | [diff] [blame] | 120 | # |
philippe | 5d5dd8e | 2012-08-05 00:08:25 +0000 | [diff] [blame] | 121 | # For x86: |
| 122 | # Platform variant: android |
| 123 | # Primary -DVGPV string: -DVGPV_x86_linux_android=1 |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 124 | # |
dejanj | 9c6b05d | 2013-12-27 09:06:55 +0000 | [diff] [blame] | 125 | # For mips32: |
| 126 | # Platform variant: android |
| 127 | # Primary -DVGPV string: -DVGPV_mips32_linux_android=1 |
| 128 | # |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 129 | # 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 |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 135 | # |
| 136 | make -j2 |
| 137 | make -j2 install DESTDIR=`pwd`/Inst |
sewardj | 37ed97b | 2011-07-12 13:34:31 +0000 | [diff] [blame] | 138 | |
| 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 | # |
| 144 | adb push Inst / |
| 145 | |
sewardj | 4450a0e | 2014-09-03 15:19:25 +0000 | [diff] [blame] | 146 | |
| 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] |
sewardj | a0b4dbc | 2011-09-10 11:28:51 +0000 | [diff] [blame] | 166 | |
| 167 | |
| 168 | # Once you're up and running, a handy modify-V-rebuild-reinstall |
| 169 | # command line (on the host, of course) is |
| 170 | # |
| 171 | mq -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. |