Fix sdk_x86 build

Change-Id: Ia90843046f3a48e01076786b7d9f0b3135f09e41
diff --git a/build/Android.common.mk b/build/Android.common.mk
index ea024d1..16df8de 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -214,18 +214,34 @@
 	src/logging_android.cc \
 	src/monitor_android.cc \
 	src/runtime_android.cc \
-	src/thread_android.cc \
-	src/thread_arm.cc \
-	src/runtime_support_arm.S
+	src/thread_android.cc
+
+ifeq ($(TARGET_ARCH),arm)
+LIBART_TARGET_SRC_FILES += src/runtime_support_arm.S src/thread_arm.cc
+else # TARGET_ARCH != arm
+ifeq ($(TARGET_ARCH),x86)
+LIBART_TARGET_SRC_FILES += src/runtime_support_x86.S src/thread_x86.cc
+else # TARGET_ARCH != x86
+ifeq ($(TARGET_ARCH),mips)
+LIBART_TARGET_SRC_FILES += src/runtime_support_mips.S src/thread_mips.cc
+else # TARGET_ARCH != mips
+$(error unsupported TARGET_ARCH=$(TARGET_ARCH))
+endif # TARGET_ARCH != mips
+endif # TARGET_ARCH != x86
+endif # TARGET_ARCH != arm
 
 LIBART_HOST_SRC_FILES := \
 	$(LIBART_COMMON_SRC_FILES) \
 	src/logging_linux.cc \
 	src/monitor_linux.cc \
 	src/runtime_linux.cc \
-	src/thread_linux.cc \
-	src/thread_x86.cc \
-	src/runtime_support_x86.S
+	src/thread_linux.cc
+
+ifeq ($(TARGET_ARCH),x86)
+LIBART_HOST_SRC_FILES += src/runtime_support_x86.S src/thread_x86.cc
+else # TARGET_ARCH != x86
+$(error unsupported HOST_ARCH=$(HOST_ARCH))
+endif # TARGET_ARCH != x86
 
 LIBARTTEST_COMMON_SRC_FILES := \
 	test/StackWalk/stack_walk_jni.cc \
diff --git a/src/common_test.h b/src/common_test.h
index bb79a70..6fafb30 100644
--- a/src/common_test.h
+++ b/src/common_test.h
@@ -79,10 +79,12 @@
       c = 0;
       // prevent g < 0 which would potentially allow an overflow later
       if (--g < 0) {
+        *dst_size = 0;
         return NULL;
       }
     } else if (g != 3) {
       // we only allow = to be at the end
+      *dst_size = 0;
       return NULL;
     }
     t = (t << 6) | c;
@@ -98,11 +100,14 @@
     }
   }
   if (y != 0) {
+    *dst_size = 0;
     return NULL;
   }
   UniquePtr<byte[]> dst(new byte[tmp.size()]);
   if (dst_size != NULL) {
     *dst_size = tmp.size();
+  } else {
+    *dst_size = 0;
   }
   std::copy(tmp.begin(), tmp.end(), dst.get());
   return dst.release();
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 1f37037..f2a3b9c 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -115,6 +115,12 @@
 
   return reinterpret_cast<T>(ref);
 }
+// Explicit instantiations
+template jclass AddLocalReference<jclass>(JNIEnv* public_env, const Object* const_obj);
+template jobject AddLocalReference<jobject>(JNIEnv* public_env, const Object* const_obj);
+template jobjectArray AddLocalReference<jobjectArray>(JNIEnv* public_env, const Object* const_obj);
+template jstring AddLocalReference<jstring>(JNIEnv* public_env, const Object* const_obj);
+template jthrowable AddLocalReference<jthrowable>(JNIEnv* public_env, const Object* const_obj);
 
 // For external use.
 template<typename T>
diff --git a/src/thread_x86.cc b/src/thread_x86.cc
index 85da1f3..30caaec 100644
--- a/src/thread_x86.cc
+++ b/src/thread_x86.cc
@@ -30,6 +30,11 @@
 #include <asm/ldt.h>
 #endif
 
+// TODO: add SYS_modify_ldt definition to bionic
+#ifndef SYS_modify_ldt
+#define SYS_modify_ldt __NR_modify_ldt
+#endif
+
 namespace art {
 
 void Thread::InitCpu() {