Reset libc targetSdkVersion

 This will let libc/linker know which sdk version
 is targeted by the app. This is needed to work around
 incorrect DT_NEEDED entries in old apps.

Bug: http://b/21364029
Change-Id: I2f2907104106aac6c8831381ca171dc0302e6a9d
(cherry picked from commit 15efde2badd80b8b124f8e1444165e4afbac17f0)
diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc
index 9736e15..a172197 100644
--- a/runtime/native/dalvik_system_VMRuntime.cc
+++ b/runtime/native/dalvik_system_VMRuntime.cc
@@ -16,6 +16,9 @@
 
 #include "dalvik_system_VMRuntime.h"
 
+#ifdef HAVE_ANDROID_OS
+extern "C" void android_set_application_target_sdk_version(uint32_t version);
+#endif
 #include <limits.h>
 #include <ScopedUtfChars.h>
 
@@ -192,6 +195,12 @@
   // Note that targetSdkVersion may be CUR_DEVELOPMENT (10000).
   // Note that targetSdkVersion may be 0, meaning "current".
   Runtime::Current()->SetTargetSdkVersion(target_sdk_version);
+
+#ifdef HAVE_ANDROID_OS
+  // This part is letting libc/dynamic linker know about current app's
+  // target sdk version to enable compatibility workarounds.
+  android_set_application_target_sdk_version(static_cast<uint32_t>(target_sdk_version));
+#endif
 }
 
 static void VMRuntime_registerNativeAllocation(JNIEnv* env, jobject, jint bytes) {