summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDmitriy Ivanov <dimitry@google.com>2014-06-29 12:28:37 -0700
committerDmitriy Ivanov <dimitry@google.com>2014-07-01 10:25:54 -0700
commitd97e9f546ea195686a78e539315b273393609b9e (patch)
tree07ee416c8dc3795436726a3f820b44c939191c5d /tests
parent4ec3bc83c632132bda915d00b5bc716dc6ab8dd8 (diff)
downloadbionic-d97e9f546ea195686a78e539315b273393609b9e.zip
bionic-d97e9f546ea195686a78e539315b273393609b9e.tar.gz
bionic-d97e9f546ea195686a78e539315b273393609b9e.tar.bz2
Add support for protected local symbol lookup.
Bug: http://code.google.com/p/android/issues/detail?id=66048 Change-Id: Ib334223df27adad9477fb241ab099c5e26df4a7d
Diffstat (limited to 'tests')
-rw-r--r--tests/dlfcn_test.cpp14
-rw-r--r--tests/libs/Android.mk14
-rw-r--r--tests/libs/dlsym_local_symbol.map22
-rw-r--r--tests/libs/dlsym_local_symbol_private.cpp24
-rw-r--r--tests/libs/dlsym_local_symbol_public.cpp47
5 files changed, 121 insertions, 0 deletions
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index 8b89183..18963cf 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -50,6 +50,20 @@ TEST(dlfcn, dlsym_in_self) {
ASSERT_EQ(0, dlclose(self));
}
+TEST(dlfcn, dlsym_local_symbol) {
+ void* handle = dlopen("libtest_local_symbol.so", RTLD_NOW);
+ ASSERT_TRUE(handle != NULL);
+ dlerror();
+ void* sym = dlsym(handle, "private_taxicab_number");
+ ASSERT_TRUE(sym == NULL);
+ ASSERT_STREQ("undefined symbol: private_taxicab_number", dlerror());
+
+ uint32_t (*f)(void);
+ f = reinterpret_cast<uint32_t (*)(void)>(dlsym(handle, "dlsym_local_symbol_get_taxicab_number_using_dlsym"));
+ ASSERT_TRUE(f != NULL);
+ ASSERT_EQ(1729, f());
+}
+
TEST(dlfcn, dlopen_noload) {
void* handle = dlopen("libtest_simple.so", RTLD_NOW | RTLD_NOLOAD);
ASSERT_TRUE(handle == NULL);
diff --git a/tests/libs/Android.mk b/tests/libs/Android.mk
index 67ea562..efce5b5 100644
--- a/tests/libs/Android.mk
+++ b/tests/libs/Android.mk
@@ -88,6 +88,20 @@ build_type := target
build_target := SHARED_LIBRARY
include $(TEST_PATH)/Android.build.mk
+# -----------------------------------------------------------------------------
+# Library used to test local symbol lookup
+# -----------------------------------------------------------------------------
+libtest_local_symbol_src_files := \
+ dlsym_local_symbol_private.cpp \
+ dlsym_local_symbol_public.cpp
+
+module := libtest_local_symbol
+build_target := SHARED_LIBRARY
+libtest_local_symbol_ldflags := -Wl,--version-script=$(LOCAL_PATH)/dlsym_local_symbol.map
+libtest_local_symbol_cppflags := -std=gnu++11
+libtest_local_symbol_shared_libraries_target := libdl
+build_type := target
+include $(TEST_PATH)/Android.build.mk
# -----------------------------------------------------------------------------
# Library used by atexit tests
diff --git a/tests/libs/dlsym_local_symbol.map b/tests/libs/dlsym_local_symbol.map
new file mode 100644
index 0000000..58a2299
--- /dev/null
+++ b/tests/libs/dlsym_local_symbol.map
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+LIBTEST_LOCAL_SYMBOL_1.0 {
+ global:
+ dlsym_local_symbol_get_taxicab_number;
+ dlsym_local_symbol_get_taxicab_number_using_dlsym;
+ local:
+ *;
+};
diff --git a/tests/libs/dlsym_local_symbol_private.cpp b/tests/libs/dlsym_local_symbol_private.cpp
new file mode 100644
index 0000000..2587508
--- /dev/null
+++ b/tests/libs/dlsym_local_symbol_private.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2014 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 <stdlib.h>
+#include <dlfcn.h>
+#include <stdio.h>
+
+// This symbol is declared local in
+// the linker version map: libdlsym_local_symbol.map.
+// It should not be visible from the outside.
+extern "C" const uint32_t __attribute__ ((visibility ("protected"))) private_taxicab_number = 1729;
diff --git a/tests/libs/dlsym_local_symbol_public.cpp b/tests/libs/dlsym_local_symbol_public.cpp
new file mode 100644
index 0000000..d9da32a
--- /dev/null
+++ b/tests/libs/dlsym_local_symbol_public.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2014 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 <stdlib.h>
+#include <dlfcn.h>
+#include <stdio.h>
+
+extern const uint32_t private_taxicab_number;
+
+extern "C" {
+uint32_t dlsym_local_symbol_get_taxicab_number();
+uint32_t dlsym_local_symbol_get_taxicab_number_using_dlsym();
+}
+
+uint32_t dlsym_local_symbol_get_taxicab_number() {
+ return private_taxicab_number;
+}
+
+// Let's make sure that dlsym works correctly for local symbol
+uint32_t dlsym_local_symbol_get_taxicab_number_using_dlsym() {
+ dlerror();
+ uint32_t* ptr = reinterpret_cast<uint32_t*>(dlsym(RTLD_DEFAULT, "private_taxicab_number"));
+ if (ptr == nullptr) {
+ const char* dlerr = dlerror();
+ if (dlerr != nullptr) {
+ fprintf(stderr, "dlsym error: %s\n", dlerr);
+ } else {
+ fprintf(stderr, "dlsym returned NULL with no dlerror.\n");
+ }
+ return 0;
+ }
+
+ return *ptr;
+}