|
From: <sv...@va...> - 2012-07-04 21:59:37
|
philippe 2012-07-04 22:59:29 +0100 (Wed, 04 Jul 2012)
New Revision: 12710
Log:
fix 302709 valgrind for ARM needs extra tls support for android emulator
Allow Valgrind to run on android emulator.
+ added README.android_emulator giving some details about versions used.
Added files:
trunk/README.android_emulator
Modified files:
trunk/NEWS
trunk/README.android
trunk/coregrind/m_initimg/initimg-linux.c
trunk/coregrind/m_syswrap/syswrap-arm-linux.c
trunk/coregrind/m_syswrap/syswrap-linux.c
trunk/coregrind/vg_preloaded.c
trunk/docs/internals/3_7_BUGSTATUS.txt
trunk/docs/xml/dist-docs.xml
Modified: trunk/docs/internals/3_7_BUGSTATUS.txt (+0 -1)
===================================================================
--- trunk/docs/internals/3_7_BUGSTATUS.txt 2012-07-04 21:30:47 +01:00 (rev 12709)
+++ trunk/docs/internals/3_7_BUGSTATUS.txt 2012-07-04 22:59:29 +01:00 (rev 12710)
@@ -251,7 +251,6 @@
302578] New: Unrecognized isntruction 0xc5 0x32 0xc2 0xca 0x09 vcmpngess
302630] New: Memcheck on ultithreaded program fails with Assertion 'sizeof(UWord) == sizeof(UInt)' failed in m_syscall.c
302700] New: Assertion 'srcix >= 0 && srcix < VG_(sizeXA)(srcxa)' failed.
-302709] New: valgrind for ARM needs extra tls support for android emulator under Linux
302800] New: valgrind change the operator new's alloctor into system's
-- Sat 30 June 2012, near midnight.
Modified: trunk/README.android (+15 -5)
===================================================================
--- trunk/README.android 2012-07-04 21:30:47 +01:00 (rev 12709)
+++ trunk/README.android 2012-07-04 22:59:29 +01:00 (rev 12710)
@@ -2,15 +2,23 @@
How to cross-compile for Android. These notes were last updated on
17 Feb 2012, for Valgrind SVN revision 12390/2257.
-This is known to work at least for Android 4.0.3 running on a (rooted,
-AOSP build) Nexus S and also on the same on Motorola Xoom. Android
-2.3.4 on Nexus S worked at some time in the past. Other
-configurations and toolchains might work, but haven't been tested.
+This is known to work at least for :
+ Android 4.0.3 running on a (rooted, AOSP build) Nexus S.
+ Android 4.0.3 running on Motorola Xoom.
+ Android 4.0.3 running on android emulator.
+
+Android 2.3.4 on Nexus S worked at some time in the past.
+It is known not to work on Android 4.1 running on android emulator.
+
+Other configurations and toolchains might work, but haven't been tested.
Feedback is welcome.
+
You need the android-ndk-r6 native development kit. r6b and r7
give a non-completely-working build; see
http://code.google.com/p/android/issues/detail?id=23203
+For the android emulator, the versions needed and how to
+install them are described in README.android_emulator.
Install it somewhere. Doesn't matter where. Then do this:
@@ -33,6 +41,7 @@
#
export HWKIND=nexus_s # Samsung Nexus S; also Xoom (for now)
export HWKIND=pandaboard # Pandaboard running Linaro Android
+export HWKIND=emulator # Android emulator
# Then cd to the root of your Valgrind source tree.
#
@@ -63,8 +72,9 @@
./configure --prefix=/data/local/Inst \
--host=armv7-unknown-linux --target=armv7-unknown-linux \
--with-tmpdir=/sdcard
+# note: on android emulator, android-14 platform was also tested and works.
+# It is not clear what this platform nr really is.
-
# At the end of the configure run, a few lines of details
# are printed. Make sure that you see these two lines:
#
Modified: trunk/coregrind/m_syswrap/syswrap-arm-linux.c (+48 -4)
===================================================================
--- trunk/coregrind/m_syswrap/syswrap-arm-linux.c 2012-07-04 21:30:47 +01:00 (rev 12709)
+++ trunk/coregrind/m_syswrap/syswrap-arm-linux.c 2012-07-04 22:59:29 +01:00 (rev 12710)
@@ -151,6 +151,7 @@
// forward declarations
static void setup_child ( ThreadArchState*, ThreadArchState* );
+static void assign_guest_tls(ThreadId ctid, Addr tlsptr);
static SysRes sys_set_tls ( ThreadId tid, Addr tlsptr );
/*
@@ -233,9 +234,8 @@
VG_TRACK ( pre_thread_ll_create, ptid, ctid );
if (flags & VKI_CLONE_SETTLS) {
- res = sys_set_tls(ctid, child_tls);
- if (sr_isError(res))
- goto out;
+ /* Just assign the tls pointer in the guest TPIDRURO. */
+ assign_guest_tls(ctid, child_tls);
}
flags &= ~VKI_CLONE_SETTLS;
@@ -282,10 +282,53 @@
child->vex_shadow2 = parent->vex_shadow2;
}
+static void assign_guest_tls(ThreadId tid, Addr tlsptr)
+{
+ VG_(threads)[tid].arch.vex.guest_TPIDRURO = tlsptr;
+}
+
+/* Assigns tlsptr to the guest TPIDRURO.
+ If needed for the specific hardware, really executes
+ the set_tls syscall.
+*/
static SysRes sys_set_tls ( ThreadId tid, Addr tlsptr )
{
- VG_(threads)[tid].arch.vex.guest_TPIDRURO = tlsptr;
+ assign_guest_tls(tid, tlsptr);
+#if defined(ANDROID_HARDWARE_emulator)
+ /* Android emulator does not provide an hw tls register.
+ So, the tls register is emulated by the kernel.
+ This emulated value is set by the __NR_ARM_set_tls syscall.
+ The emulated value must be read by the kernel helper function
+ located at 0xffff0fe0.
+
+ The emulated tlsptr is located at 0xffff0ff0
+ (so slightly after the kernel helper function).
+ Note that applications are not supposed to read this directly.
+
+ For compatibility : if there is a hw tls register, the kernel
+ will put at 0xffff0fe0 the instructions to read it, so
+ as to have old applications calling the kernel helper
+ working properly.
+
+ For having emulated guest TLS working correctly with
+ Valgrind, it is needed to execute the syscall to set
+ the emulated TLS value in addition to the assignment
+ of TPIDRURO.
+
+ Note: the below means that if we need thread local storage
+ for Valgrind host, then there will be a conflict between
+ the need of the guest tls and of the host tls.
+ If all the guest code would cleanly call 0xffff0fe0,
+ then we might maybe intercept this. However, at least
+ __libc_preinit reads directly 0xffff0ff0.
+ */
+ /* ??? might call the below if auxv->u.a_val & VKI_HWCAP_TLS ???
+ Unclear if real hardware having tls hw register sets
+ VKI_HWCAP_TLS. */
+ return VG_(do_syscall1) (__NR_ARM_set_tls, tlsptr);
+#else
return VG_(mk_SysRes_Success)( 0 );
+#endif
}
/* ---------------------------------------------------------------------
@@ -1242,6 +1285,7 @@
PRE(sys_set_tls)
{
+ PRINT("set_tls (%lx)",ARG1);
PRE_REG_READ1(long, "set_tls", unsigned long, addr);
SET_STATUS_from_SysRes( sys_set_tls( tid, ARG1 ) );
Modified: trunk/coregrind/m_syswrap/syswrap-linux.c (+7 -0)
===================================================================
--- trunk/coregrind/m_syswrap/syswrap-linux.c 2012-07-04 21:30:47 +01:00 (rev 12709)
+++ trunk/coregrind/m_syswrap/syswrap-linux.c 2012-07-04 22:59:29 +01:00 (rev 12710)
@@ -5536,6 +5536,13 @@
/* END Pandaboard specific ioctls */
+# elif defined(ANDROID_HARDWARE_emulator)
+
+ /* BEGIN emulator specific ioctls */
+ /* currently none are known */
+ /* END emulator specific ioctls */
+
+
# else /* no ANDROID_HARDWARE_anything defined */
# warning ""
Modified: trunk/coregrind/m_initimg/initimg-linux.c (+9 -0)
===================================================================
--- trunk/coregrind/m_initimg/initimg-linux.c 2012-07-04 21:30:47 +01:00 (rev 12709)
+++ trunk/coregrind/m_initimg/initimg-linux.c 2012-07-04 22:59:29 +01:00 (rev 12710)
@@ -690,6 +690,15 @@
"ARM has-neon from-auxv: %s\n",
has_neon ? "YES" : "NO");
VG_(machine_arm_set_has_NEON)( has_neon );
+ #define VKI_HWCAP_TLS 32768
+ Bool has_tls = (auxv->u.a_val & VKI_HWCAP_TLS) > 0;
+ VG_(debugLog)(2, "initimg",
+ "ARM has-tls from-auxv: %s\n",
+ has_tls ? "YES" : "NO");
+ /* If real hw sets properly HWCAP_TLS, we might
+ use this info to decide to really execute set_tls syscall
+ in syswrap-arm-linux.c rather than to base this on
+ conditional compilation. */
}
# endif
break;
Added: trunk/README.android_emulator (+75 -0)
===================================================================
--- trunk/README.android_emulator 2012-07-04 21:30:47 +01:00 (rev 12709)
+++ trunk/README.android_emulator 2012-07-04 22:59:29 +01:00 (rev 12710)
@@ -0,0 +1,75 @@
+
+How to install and run an android emulator.
+
+mkdir android # or any other place you prefer
+cd android
+
+# download java JDK
+# http://www.oracle.com/technetwork/java/javase/downloads/index.html
+# download android SDK
+# http://developer.android.com/sdk/index.html
+# download android NDK
+# http://developer.android.com/sdk/ndk/index.html
+
+# versions I used:
+# jdk-7u4-linux-i586.tar.gz
+# android-ndk-r8-linux-x86.tar.bz2
+# android-sdk_r18-linux.tgz
+
+# install jdk
+tar xzf jdk-7u4-linux-i586.tar.gz
+
+# install sdk
+tar xzf android-sdk_r18-linux.tgz
+
+# install ndk
+tar xjf android-ndk-r8-linux-x86.tar.bz2
+
+
+# setup PATH to use the installed software:
+export SDKROOT=$HOME/android/android-sdk-linux
+export PATH=$PATH:$SDKROOT/tools:$SDKROOT/platform-tools
+export NDKROOT=$HOME/android/android-ndk-r8
+
+# install android platforms you want by starting:
+android
+# (from $SDKROOT/tools)
+
+# select the platforms you need
+# I selected and installed:
+# Android 4.0.3 (API 15)
+# Upgraded then to the newer version available:
+# Android sdk 20
+# Android platform tools 12
+
+# Android 4.1 (API 16) does not work.
+
+# then define a virtual device:
+Tools -> Manage AVDs...
+# I define an AVD Name with 64 Mb SD Card, (4.0.3, api 15)
+# rest is default
+
+
+# compile and make install Valgrind, following README.android
+
+
+# Start your android emulator (it takes some time).
+# You can use adb shell to get a shell on the device
+# and see it is working. Note that I usually get
+# one or two time out from adb shell before it works
+adb shell
+
+# Once the emulator is ready, push your Valgrind to the emulator:
+adb push Inst /
+
+
+# if you need to debug:
+# You have on the android side a gdbserver
+# on the device side:
+gdbserver :1234 your_exe
+
+# on the host side:
+adb forward tcp:1234 tcp:1234
+$HOME/android/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb your_exe
+target remote :1234
+
Modified: trunk/docs/xml/dist-docs.xml (+10 -0)
===================================================================
--- trunk/docs/xml/dist-docs.xml 2012-07-04 21:30:47 +01:00 (rev 12709)
+++ trunk/docs/xml/dist-docs.xml 2012-07-04 22:59:29 +01:00 (rev 12710)
@@ -95,6 +95,16 @@
</literallayout>
</chapter>
+ <chapter id="dist.readme-android_emulator"
+ xreflabel="Readme Android Emulator">
+ <title>README.android_emulator</title>
+ <literallayout>
+ <xi:include href="../../README.android_emulator"
+ parse="text"
+ xmlns:xi="http://www.w3.org/2001/XInclude" />
+ </literallayout>
+ </chapter>
+
<chapter id="dist.readme-mips"
xreflabel="Readme MIPS">
<title>README.mips</title>
Modified: trunk/coregrind/vg_preloaded.c (+21 -0)
===================================================================
--- trunk/coregrind/vg_preloaded.c 2012-07-04 21:30:47 +01:00 (rev 12709)
+++ trunk/coregrind/vg_preloaded.c 2012-07-04 22:59:29 +01:00 (rev 12710)
@@ -89,6 +89,27 @@
return (void*)result;
}
+#if defined(ANDROID_HARDWARE_emulator)
+/* When running on android emulator, we get the following error when doing
+ ./valgrind date
+
+ link_image[1921]: 494 could not load needed library
+ '/data/local/Inst/lib/valgrind/vgpreload_core-arm-linux.so' for 'date'
+ (reloc_library[1285]: 494 cannot locate '__cxa_finalize'...
+ )CANNOT LINK EXECUTABLE
+
+ This problem is bypassed by adding the below function.
+ Do not ask me to explain neither the problem nor the solution.
+*/
+extern void __cxa_finalize(void);
+void __cxa_finalize(void)
+{
+ // ??? what should we do here ? Silently do nothing looks not sane.
+ // So, try to crash:
+ *(volatile int *)0 = 'x';
+}
+#endif
+
#elif defined(VGO_darwin)
#include "config.h" /* VERSION */
Modified: trunk/NEWS (+1 -0)
===================================================================
--- trunk/NEWS 2012-07-04 21:30:47 +01:00 (rev 12709)
+++ trunk/NEWS 2012-07-04 22:59:29 +01:00 (rev 12710)
@@ -213,6 +213,7 @@
302536 Fix for the POWER Valgrind regression test: memcheck-ISA2.0.
302656 Unhandled instruction (vcvtsi2ssq)
== 273475 (canonical avx)
+302709 valgrind for ARM needs extra tls support for android emulator under Linux
Release 3.7.0 (5 November 2011)
|