]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
fix 302709 valgrind for ARM needs extra tls support for android emulator
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Wed, 4 Jul 2012 21:59:29 +0000 (21:59 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Wed, 4 Jul 2012 21:59:29 +0000 (21:59 +0000)
Allow Valgrind to run on android emulator.
+ added README.android_emulator giving some details about versions used.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12710

NEWS
README.android
README.android_emulator [new file with mode: 0644]
coregrind/m_initimg/initimg-linux.c
coregrind/m_syswrap/syswrap-arm-linux.c
coregrind/m_syswrap/syswrap-linux.c
coregrind/vg_preloaded.c
docs/internals/3_7_BUGSTATUS.txt
docs/xml/dist-docs.xml

diff --git a/NEWS b/NEWS
index a5825ab7523d874b825b977c56fa4f54ed2aa437..3a212de497b016827ef50f737e769e0269e9ef0c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -213,6 +213,7 @@ n-i-bz  Fix assert in gdbserver for watchpoints watching the same address
 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)
index 3c2eba09a70242317aab2c6053dc39d7a3d7706d..9c43d7ee7946d8ab2e524587578ffc55b98bd524 100644 (file)
@@ -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 NDKROOT=/path/to/android-ndk-r6
 #
 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,7 +72,8 @@ CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HW
    ./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:
diff --git a/README.android_emulator b/README.android_emulator
new file mode 100644 (file)
index 0000000..4808c48
--- /dev/null
@@ -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
+
index 8acc7b0f51c11b2f7ce4c8c1b1a73ca49f787a9a..691b381a9492b50344f025aff05e6644de196641 100644 (file)
@@ -690,6 +690,15 @@ Addr setup_client_stack( void*  init_sp,
                                "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;
index e01bbaf57a163fd2524293d6ee0bb380bc5eb100..3792a8c0fba0e943ad887f4cb77fa8072d727975 100644 (file)
@@ -151,6 +151,7 @@ asm(
 
 // 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 @@ static SysRes do_clone ( ThreadId ptid,
    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 @@ void setup_child ( /*OUT*/ ThreadArchState *child,
    child->vex_shadow2 = parent->vex_shadow2;
 }
 
-static SysRes sys_set_tls ( ThreadId tid, Addr tlsptr )
+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 )
+{
+   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_sigsuspend)
 
 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 ) );
index ce716782d52541d258f94b6cd086a0118bde9c4e..ba84641b8eb2fa422d3f1ed786f950f8aa18f376 100644 (file)
@@ -5536,6 +5536,13 @@ POST(sys_ioctl)
    /* 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 ""
index 24a8f71674fb6edd1314af78c5ec509f729f187c..03038acb73d73287389ca95731644aabc35f73a1 100644 (file)
@@ -89,6 +89,27 @@ void * VG_NOTIFY_ON_LOAD(ifunc_wrapper) (void)
     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 */
index df55c7f730c435be8397dffdede1b7edf522242a..bfad790d36a847a1c51dc5c0b9b4900450c20203 100644 (file)
@@ -251,7 +251,6 @@ get fixed.
 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.
index ad2c9a28cd174411a34911beae3b79d1d02ad870..083a86040e7dd4c3d11b9de18885f4a4fdb7d976 100644 (file)
     </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>