summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitriy Ivanov <dimitry@google.com>2015-05-21 17:43:49 -0700
committerDmitriy Ivanov <dimitry@google.com>2015-05-27 16:20:16 -0700
commitd8ead18145cba98fdc7256f9a0e69b8c1c90cd1c (patch)
tree4bc17de556189b41aedc1bd275066974d6089fcb
parent15309fde91b3989a1af139db422acf68e16a9258 (diff)
downloadbionic-d8ead18145cba98fdc7256f9a0e69b8c1c90cd1c.tar.gz
bionic-d8ead18145cba98fdc7256f9a0e69b8c1c90cd1c.tar.bz2
bionic-d8ead18145cba98fdc7256f9a0e69b8c1c90cd1c.zip
Add functions to provide target sdk version
Bug: http://b/21364029 Change-Id: I8648d1bff6c8fd6e7cd12da7f128e048b9f2829a (cherry picked from commit 79fd668bb4ddb22432eeda2ebd8d10359013d9a8)
-rw-r--r--libdl/Android.mk2
-rw-r--r--libdl/libdl.c4
-rw-r--r--libdl/libdl.map39
-rw-r--r--linker/Android.mk1
-rw-r--r--linker/dlfcn.cpp40
-rw-r--r--linker/linker.h3
-rw-r--r--linker/linker_sdk_versions.cpp29
-rw-r--r--tests/Android.mk3
-rw-r--r--tests/libdl_test.cpp32
9 files changed, 138 insertions, 15 deletions
diff --git a/libdl/Android.mk b/libdl/Android.mk
index 2a0724a0b..7b97dc4ad 100644
--- a/libdl/Android.mk
+++ b/libdl/Android.mk
@@ -15,7 +15,7 @@ include $(CLEAR_VARS)
#
# DO NOT REMOVE --exclude-libs!
-LOCAL_LDFLAGS := -Wl,--exclude-libs=libgcc.a
+LOCAL_LDFLAGS := -Wl,--exclude-libs=libgcc.a -Wl,--version-script=$(LOCAL_PATH)/libdl.map
# for x86, exclude libgcc_eh.a for the same reasons as above
LOCAL_LDFLAGS_x86 := -Wl,--exclude-libs=libgcc_eh.a
diff --git a/libdl/libdl.c b/libdl/libdl.c
index dca51b0b0..9a858a36e 100644
--- a/libdl/libdl.c
+++ b/libdl/libdl.c
@@ -17,6 +17,7 @@
#include <dlfcn.h>
#include <link.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <android/dlext.h>
// These are stubs for functions that are actually defined
@@ -38,3 +39,6 @@ void android_get_LD_LIBRARY_PATH(char* buffer __unused, size_t buffer_size __unu
void android_update_LD_LIBRARY_PATH(const char* ld_library_path __unused) { }
void* android_dlopen_ext(const char* filename __unused, int flag __unused, const android_dlextinfo* extinfo __unused) { return 0; }
+
+void android_set_application_target_sdk_version(uint32_t target __unused) { }
+uint32_t android_get_application_target_sdk_version() { return 0; }
diff --git a/libdl/libdl.map b/libdl/libdl.map
new file mode 100644
index 000000000..a911cb67a
--- /dev/null
+++ b/libdl/libdl.map
@@ -0,0 +1,39 @@
+#
+# Copyright (C) 2015 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.
+#
+
+LIBC {
+ global:
+ android_dlopen_ext;
+ dl_iterate_phdr;
+# begin arm-only
+ dl_unwind_find_exidx;
+# end arm-only
+ dladdr;
+ dlclose;
+ dlerror;
+ dlopen;
+ dlsym;
+ local:
+ *;
+};
+
+LIBC_PRIVATE {
+ global:
+ android_get_application_target_sdk_version;
+ android_set_application_target_sdk_version;
+ android_get_LD_LIBRARY_PATH;
+ android_update_LD_LIBRARY_PATH;
+} LIBC;
diff --git a/linker/Android.mk b/linker/Android.mk
index 4a7da7608..00add7da9 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -7,6 +7,7 @@ LOCAL_SRC_FILES:= \
dlfcn.cpp \
linker.cpp \
linker_allocator.cpp \
+ linker_sdk_versions.cpp \
linker_block_allocator.cpp \
linker_environ.cpp \
linker_libc_support.c \
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index 057c2173c..8fafded6a 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -157,6 +157,14 @@ int dlclose(void* handle) {
return 0;
}
+void android_set_application_target_sdk_version(uint32_t target) {
+ set_application_target_sdk_version(target);
+}
+
+uint32_t android_get_application_target_sdk_version() {
+ return get_application_target_sdk_version();
+}
+
// name_offset: starting index of the name in libdl_info.strtab
#define ELF32_SYM_INITIALIZER(name_offset, value, shndx) \
{ name_offset, \
@@ -176,19 +184,21 @@ int dlclose(void* handle) {
/* st_size */ 0, \
}
+static const char ANDROID_LIBDL_STRTAB[] =
+ // 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667777777777888888888899999 99999
+ // 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890123456789012345678901234 56789
+ "dlopen\0dlclose\0dlsym\0dlerror\0dladdr\0android_update_LD_LIBRARY_PATH\0android_get_LD_LIBRARY_PATH\0dl_it"
+ // 00000000001 1111111112222222222 3333333333444444444455555555556666666666777 777777788888888889999999999
+ // 01234567890 1234567890123456789 0123456789012345678901234567890123456789012 345678901234567890123456789
+ "erate_phdr\0android_dlopen_ext\0android_set_application_target_sdk_version\0android_get_application_tar"
+ // 0000000000111111
+ // 0123456789012345
+ "get_sdk_version\0"
#if defined(__arm__)
- // 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667777777777888888888899999 9999900000000001 1111111112222222222 333333333344444444445
- // 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890123456789012345678901234 5678901234567890 1234567890123456789 012345678901234567890
-# define ANDROID_LIBDL_STRTAB \
- "dlopen\0dlclose\0dlsym\0dlerror\0dladdr\0android_update_LD_LIBRARY_PATH\0android_get_LD_LIBRARY_PATH\0dl_iterate_phdr\0android_dlopen_ext\0dl_unwind_find_exidx\0"
-#elif defined(__aarch64__) || defined(__i386__) || defined(__mips__) || defined(__x86_64__)
- // 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667777777777888888888899999 9999900000000001 1111111112222222222
- // 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890123456789012345678901234 5678901234567890 1234567890123456789
-# define ANDROID_LIBDL_STRTAB \
- "dlopen\0dlclose\0dlsym\0dlerror\0dladdr\0android_update_LD_LIBRARY_PATH\0android_get_LD_LIBRARY_PATH\0dl_iterate_phdr\0android_dlopen_ext\0"
-#else
-# error Unsupported architecture. Only arm, arm64, mips, mips64, x86 and x86_64 are presently supported.
+ // 216
+ "dl_unwind_find_exidx\0"
#endif
+ ;
static ElfW(Sym) g_libdl_symtab[] = {
// Total length of libdl_info.strtab, including trailing 0.
@@ -205,8 +215,10 @@ static ElfW(Sym) g_libdl_symtab[] = {
ELFW(SYM_INITIALIZER)( 67, &android_get_LD_LIBRARY_PATH, 1),
ELFW(SYM_INITIALIZER)( 95, &dl_iterate_phdr, 1),
ELFW(SYM_INITIALIZER)(111, &android_dlopen_ext, 1),
+ ELFW(SYM_INITIALIZER)(130, &android_set_application_target_sdk_version, 1),
+ ELFW(SYM_INITIALIZER)(173, &android_get_application_target_sdk_version, 1),
#if defined(__arm__)
- ELFW(SYM_INITIALIZER)(130, &dl_unwind_find_exidx, 1),
+ ELFW(SYM_INITIALIZER)(216, &dl_unwind_find_exidx, 1),
#endif
};
@@ -223,9 +235,9 @@ static ElfW(Sym) g_libdl_symtab[] = {
// Note that adding any new symbols here requires stubbing them out in libdl.
static unsigned g_libdl_buckets[1] = { 1 };
#if defined(__arm__)
-static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0 };
+static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0 };
#else
-static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0 };
#endif
static uint8_t __libdl_info_buf[sizeof(soinfo)] __attribute__((aligned(8)));
diff --git a/linker/linker.h b/linker/linker.h
index c7118ea6a..04b584ed5 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -429,4 +429,7 @@ extern "C" void notify_gdb_of_libraries();
char* linker_get_error_buffer();
size_t linker_get_error_buffer_size();
+void set_application_target_sdk_version(uint32_t target);
+uint32_t get_application_target_sdk_version();
+
#endif
diff --git a/linker/linker_sdk_versions.cpp b/linker/linker_sdk_versions.cpp
new file mode 100644
index 000000000..c73eb38d9
--- /dev/null
+++ b/linker/linker_sdk_versions.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2015 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 "linker.h"
+#include <atomic>
+
+static std::atomic<uint32_t> g_target_sdk_version;
+
+void set_application_target_sdk_version(uint32_t target) {
+ g_target_sdk_version = target;
+}
+
+uint32_t get_application_target_sdk_version() {
+ return g_target_sdk_version;
+}
+
diff --git a/tests/Android.mk b/tests/Android.mk
index 14f0d324c..0f3454cbf 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -49,6 +49,9 @@ endif
test_cppflags = \
-std=gnu++11 \
+libBionicStandardTests_src_files_target := \
+ libdl_test.cpp \
+
libBionicStandardTests_src_files := \
arpa_inet_test.cpp \
buffer_tests.cpp \
diff --git a/tests/libdl_test.cpp b/tests/libdl_test.cpp
new file mode 100644
index 000000000..9aab87b88
--- /dev/null
+++ b/tests/libdl_test.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2015 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 <gtest/gtest.h>
+
+extern "C" uint32_t android_get_application_target_sdk_version();
+extern "C" void android_set_application_target_sdk_version(uint32_t target);
+
+TEST(libdl, application_sdk_versions_smoke) {
+ // Check initial values
+ ASSERT_EQ(0U, android_get_application_target_sdk_version());
+
+ android_set_application_target_sdk_version(20U);
+ ASSERT_EQ(20U, android_get_application_target_sdk_version());
+
+ android_set_application_target_sdk_version(22U);
+ ASSERT_EQ(22U, android_get_application_target_sdk_version());
+}
+