Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ef8bcd6

Browse files
author
sewardj
committedSep 3, 2014
Improvements for Android:
* All Linux targets: add minimal ioctl support for the ION_IOC family * Android targets: change proprietary-ioctl support for GPUs from being a build-time #define kludge to being controlled by --kernel-variant, as it should be. Update documentation accordingly. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14440 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent eac1291 commit ef8bcd6

File tree

10 files changed

+243
-151
lines changed

10 files changed

+243
-151
lines changed
 

‎NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ significantly improved relative to the 3.9.0 release.
2727

2828
* Both 32- and 64-bit executables are supported on MacOSX 10.8 and 10.9.
2929

30+
* Configuration for and running on Android targets has changed.
31+
See README.android in the source tree for details.
32+
3033
* ================== DEPRECATED FEATURES =================
3134

3235
* --db-attach is now deprecated and will be removed in the next

‎README.android

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11

2-
How to cross-compile for Android. These notes were last updated on
3-
17 Feb 2012, for Valgrind SVN revision 12390/2257.
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.
45

5-
This is known to work at least for :
6-
ARM:
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:
713
Android 4.0.3 running on a (rooted, AOSP build) Nexus S.
814
Android 4.0.3 running on Motorola Xoom.
915
Android 4.0.3 running on android arm emulator.
@@ -34,7 +40,7 @@ install them are described in README.android_emulator.
3440

3541
You can get android-ndk-r6 from
3642
http://dl.google.com/android/ndk/android-ndk-r6-linux-x86.tar.bz2
37-
Install it somewhere. Doesn't matter where. Then do this:
43+
Install it somewhere. Doesn't matter where. Then:
3844

3945

4046
# Modify this (obviously). Note, this "export" command is only done
@@ -44,25 +50,12 @@ Install it somewhere. Doesn't matter where. Then do this:
4450
export NDKROOT=/path/to/android-ndk-r6
4551

4652

47-
# Modify this too. Tell the build system which Android hardware you
48-
# are building for. It needs to know this so it can compile in
49-
# support for the right Android-hw-specific ioctls. (sigh.) As with
50-
# NDKROOT above, this is merely to avoid repeated typing; none of the
51-
# commands read it.
52-
#
53-
# Currently the supported values are: nexus_s pandaboard
54-
# So choose one of the below:
55-
#
56-
export HWKIND=nexus_s # Samsung Nexus S; also Xoom (for now)
57-
export HWKIND=generic # A generic Android device. eg, Pandaboard
58-
export HWKIND=emulator # Android emulator
59-
6053
# Then cd to the root of your Valgrind source tree.
6154
#
6255
cd /path/to/valgrind/source/tree
6356

6457

65-
# After this point, you don't need to modify anything; just copy and
58+
# After this point, you don't need to modify anything. Just copy and
6659
# paste the commands below.
6760

6861

@@ -83,6 +76,7 @@ export AR=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin
8376
export LD=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ld
8477
export CC=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-gcc
8578

79+
8680
# Do configuration stuff. Don't mess with the --prefix in the
8781
# configure command below, even if you think it's wrong.
8882
# You may need to set the --with-tmpdir path to something
@@ -94,7 +88,7 @@ export CC=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin
9488
./autogen.sh
9589

9690
# for ARM
97-
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \
91+
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
9892
CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
9993
./configure --prefix=/data/local/Inst \
10094
--host=armv7-unknown-linux --target=armv7-unknown-linux \
@@ -103,19 +97,20 @@ CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HW
10397
# It is not clear what this platform nr really is.
10498

10599
# for x86
106-
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -DANDROID_HARDWARE_$HWKIND" \
100+
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86" \
107101
CFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -fno-pic" \
108102
./configure --prefix=/data/local/Inst \
109103
--host=i686-android-linux --target=i686-android-linux \
110104
--with-tmpdir=/sdcard
111105

112106
# for MIPS32
113-
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips -DANDROID_HARDWARE_$HWKIND" \
107+
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips" \
114108
CFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips" \
115109
./configure --prefix=/data/local/Inst \
116110
--host=mipsel-linux-android --target=mipsel-linux-android \
117111
--with-tmpdir=/sdcard
118112

113+
119114
# At the end of the configure run, a few lines of details
120115
# are printed. Make sure that you see these two lines:
121116
#
@@ -148,8 +143,26 @@ make -j2 install DESTDIR=`pwd`/Inst
148143
#
149144
adb push Inst /
150145

151-
# To run (on the device)
152-
/data/local/Inst/bin/valgrind [the usual args etc]
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]
153166

154167

155168
# Once you're up and running, a handy modify-V-rebuild-reinstall

‎README.android_emulator

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ adb shell
6161
adb push Inst /
6262

6363

64+
# IMPORTANT: when running Valgrind, you may need give it the flag
65+
#
66+
# --kernel-variant=android-emulator-no-hw-tls
67+
#
68+
# since otherwise it may crash at startup.
69+
# See README.android for details.
70+
71+
6472
# if you need to debug:
6573
# You have on the android side a gdbserver
6674
# on the device side:

‎coregrind/m_main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ static void usage_NORETURN ( Bool debug_help )
179179
" where hint is one of lax-ioctls fuse-compatible enable-outer\n"
180180
" no-inner-prefix no-nptl-pthread-stackcache none\n"
181181
" --fair-sched=no|yes|try schedule threads fairly on multicore systems [no]\n"
182-
" --kernel-variant=variant1,variant2,... handle non-standard kernel"
183-
" variants [none]\n"
184-
" where variant is one of bproc none\n"
182+
" --kernel-variant=variant1,variant2,...\n"
183+
" handle non-standard kernel variants [none]\n"
184+
" where variant is one of:\n"
185+
" bproc android-emulator-no-hw-tls\n"
186+
" android-gpu-sgx5xx android-gpu-adreno3xx none\n"
185187
" --merge-recursive-frames=<number> merge frames between identical\n"
186188
" program counters in max <number> frames) [0]\n"
187189
" --num-transtab-sectors=<number> size of translated code cache [%d]\n"
@@ -627,7 +629,11 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd,
627629
VG_(clo_smc_check),
628630
Vg_SmcAllNonFile);
629631

630-
else if VG_USETX_CLO (arg, "--kernel-variant", "bproc",
632+
else if VG_USETX_CLO (arg, "--kernel-variant",
633+
"bproc,"
634+
"android-emulator-no-hw-tls,"
635+
"android-gpu-sgx5xx,"
636+
"android-gpu-adreno3xx",
631637
VG_(clo_kernel_variant)) {}
632638

633639
else if VG_BOOL_CLO(arg, "--dsymutil", VG_(clo_dsymutil)) {}

‎coregrind/m_syswrap/syswrap-arm-linux.c

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -280,41 +280,43 @@ static void assign_guest_tls(ThreadId tid, Addr tlsptr)
280280
static SysRes sys_set_tls ( ThreadId tid, Addr tlsptr )
281281
{
282282
assign_guest_tls(tid, tlsptr);
283-
#if defined(ANDROID_HARDWARE_emulator)
284-
/* Android emulator does not provide an hw tls register.
285-
So, the tls register is emulated by the kernel.
286-
This emulated value is set by the __NR_ARM_set_tls syscall.
287-
The emulated value must be read by the kernel helper function
288-
located at 0xffff0fe0.
283+
284+
if (KernelVariantiS(KernelVariant_android_emulator_no_hw_tls,
285+
VG_(clo_kernel_variant))) {
286+
/* Android emulator does not provide an hw tls register.
287+
So, the tls register is emulated by the kernel.
288+
This emulated value is set by the __NR_ARM_set_tls syscall.
289+
The emulated value must be read by the kernel helper function
290+
located at 0xffff0fe0.
289291
290-
The emulated tlsptr is located at 0xffff0ff0
291-
(so slightly after the kernel helper function).
292-
Note that applications are not supposed to read this directly.
292+
The emulated tlsptr is located at 0xffff0ff0
293+
(so slightly after the kernel helper function).
294+
Note that applications are not supposed to read this directly.
293295
294-
For compatibility : if there is a hw tls register, the kernel
295-
will put at 0xffff0fe0 the instructions to read it, so
296-
as to have old applications calling the kernel helper
297-
working properly.
298-
299-
For having emulated guest TLS working correctly with
300-
Valgrind, it is needed to execute the syscall to set
301-
the emulated TLS value in addition to the assignment
302-
of TPIDRURO.
303-
304-
Note: the below means that if we need thread local storage
305-
for Valgrind host, then there will be a conflict between
306-
the need of the guest tls and of the host tls.
307-
If all the guest code would cleanly call 0xffff0fe0,
308-
then we might maybe intercept this. However, at least
309-
__libc_preinit reads directly 0xffff0ff0.
310-
*/
311-
/* ??? might call the below if auxv->u.a_val & VKI_HWCAP_TLS ???
312-
Unclear if real hardware having tls hw register sets
313-
VKI_HWCAP_TLS. */
314-
return VG_(do_syscall1) (__NR_ARM_set_tls, tlsptr);
315-
#else
316-
return VG_(mk_SysRes_Success)( 0 );
317-
#endif
296+
For compatibility : if there is a hw tls register, the kernel
297+
will put at 0xffff0fe0 the instructions to read it, so
298+
as to have old applications calling the kernel helper
299+
working properly.
300+
301+
For having emulated guest TLS working correctly with
302+
Valgrind, it is needed to execute the syscall to set
303+
the emulated TLS value in addition to the assignment
304+
of TPIDRURO.
305+
306+
Note: the below means that if we need thread local storage
307+
for Valgrind host, then there will be a conflict between
308+
the need of the guest tls and of the host tls.
309+
If all the guest code would cleanly call 0xffff0fe0,
310+
then we might maybe intercept this. However, at least
311+
__libc_preinit reads directly 0xffff0ff0.
312+
*/
313+
/* ??? might call the below if auxv->u.a_val & VKI_HWCAP_TLS ???
314+
Unclear if real hardware having tls hw register sets
315+
VKI_HWCAP_TLS. */
316+
return VG_(do_syscall1) (__NR_ARM_set_tls, tlsptr);
317+
} else {
318+
return VG_(mk_SysRes_Success)( 0 );
319+
}
318320
}
319321

320322
/* ---------------------------------------------------------------------

0 commit comments

Comments
 (0)
Please sign in to comment.