Support getting/setting API level in static binaries.

Bug: http://b/27917272
Test: fixes static semaphore.sem_wait_no_EINTR_in_sdk_less_equal_than_23 test
Change-Id: Ifeeff20772ff0308aab9417d48671b604a3e9665
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index 93a63b5..d19dd28 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -113,6 +113,16 @@
   exit(slingshot(args.argc, args.argv, args.envp));
 }
 
+static uint32_t g_target_sdk_version{__ANDROID_API__};
+
+extern "C" uint32_t android_get_application_target_sdk_version() {
+  return g_target_sdk_version;
+}
+
 uint32_t bionic_get_application_target_sdk_version() {
-  return __ANDROID_API__;
+  return android_get_application_target_sdk_version();
+}
+
+extern "C" void android_set_application_target_sdk_version(uint32_t target) {
+  g_target_sdk_version = target;
 }
diff --git a/libdl/Android.bp b/libdl/Android.bp
index 082cdea..d5fae0e 100644
--- a/libdl/Android.bp
+++ b/libdl/Android.bp
@@ -74,7 +74,7 @@
         whole_static_libs: ["libdl_static"],
     },
     static: {
-        srcs: ["libdl_static.c"],
+        srcs: ["libdl_static.cpp"],
     },
     cflags: [
         "-Wall",
diff --git a/libdl/libdl_static.c b/libdl/libdl_static.c
deleted file mode 100644
index 0dbd73f..0000000
--- a/libdl/libdl_static.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dlfcn.h>
-#include <link.h>
-#include <stdlib.h>
-#include <stdbool.h>
-
-// Proxy calls to bionic loader
-void* dlopen(const char* filename __unused, int flag __unused) {
-  return NULL;
-}
-
-char* dlerror() {
-  return NULL;
-}
-
-void* dlsym(void* handle __unused, const char* symbol __unused) {
-  return NULL;
-}
-
-void* dlvsym(void* handle __unused,
-             const char* symbol __unused,
-             const char* version __unused) {
-  return NULL;
-}
-
-int dladdr(const void* addr __unused, Dl_info* info __unused) {
-  return 0;
-}
-
-int dlclose(void* handle __unused) {
-  return -1;
-}
-
-#if defined(__arm__)
-_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc __unused, int* pcount __unused) {
-  return 0;
-}
-#endif
-
-void android_set_application_target_sdk_version(uint32_t target __unused) {
-}
-
diff --git a/libdl/libdl_static.cpp b/libdl/libdl_static.cpp
new file mode 100644
index 0000000..7146762
--- /dev/null
+++ b/libdl/libdl_static.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlfcn.h>
+#include <link.h>
+#include <stdlib.h>
+
+void* dlopen(const char* /*filename*/, int /*flag*/) {
+  return nullptr;
+}
+
+char* dlerror() {
+  return nullptr;
+}
+
+void* dlsym(void* /*handle*/, const char* /*symbol*/) {
+  return nullptr;
+}
+
+void* dlvsym(void* /*handle*/, const char* /*symbol*/, const char* /*version*/) {
+  return nullptr;
+}
+
+int dladdr(const void* /*addr*/, Dl_info* /*info*/) {
+  return 0;
+}
+
+int dlclose(void* /*handle*/) {
+  return -1;
+}
+
+#if defined(__arm__)
+_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr /*pc*/, int* /*pcount*/) {
+  return 0;
+}
+#endif