]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-bionic.git/commitdiff
Merge "Yet another relocation test"
authorDmitriy Ivanov <dimitry@google.com>
Wed, 19 Nov 2014 19:35:59 +0000 (19:35 +0000)
committerGerrit Code Review <noreply-gerritcodereview@google.com>
Wed, 19 Nov 2014 19:35:59 +0000 (19:35 +0000)
tests/Android.build.mk
tests/dlfcn_test.cpp
tests/libs/Android.build.dlopen_check_order_reloc_siblings.mk
tests/libs/dlopen_check_order_reloc_grandchild_answer.cpp [new file with mode: 0644]
tests/libs/dlopen_check_order_reloc_grandchild_answer_impl.cpp [new file with mode: 0644]

index 0754a7bf98e5b0a6588fcebaf6b5b21eb6e98edc..5b2b41728373e764bb44e01e668cc3581081a2ee 100644 (file)
@@ -42,6 +42,8 @@ endif
 
 LOCAL_FORCE_STATIC_EXECUTABLE := $($(module)_force_static_executable)
 
+LOCAL_ALLOW_UNDEFINED_SYMBOLS := $($(module)_allow_undefined_symbols)
+
 ifneq ($($(module)_multilib),)
     LOCAL_MULTILIB := $($(module)_multilib)
 endif
index 88f0b197c4cc31d0105c536aedc8b59673c7b292..ea20869d01a10f026b7f96ab9734926c61d9f19b 100644 (file)
@@ -278,6 +278,44 @@ TEST(dlfcn, dlopen_check_order_reloc_siblings_with_preload) {
   ASSERT_EQ(0, dlclose(handle));
 }
 
+TEST(dlfcn, dlopen_check_order_reloc_grandchild) {
+  // This is how this one works:
+  // we lookup and call grandchild_get_answer which is defined in '_2.so'
+  // and in turn calls external get_answer_impl() defined in '_c_1.so and _c_2.so'
+  // the correct _impl() is implemented by '_c_1.so';
+  //
+  // Here is the picture of subtree:
+  //
+  // libtest_check_order_reloc_siblings.so
+  // |
+  // +-> ..._2.so <- grandchild_get_answer()
+  //     |
+  //     +-> ..._c.so <- empty
+  //     |   |
+  //     |   +-> _c_1.so <- exports correct answer_impl()
+  //     |   |
+  //     |   +-> _c_2.so <- exports incorrect answer_impl()
+  //     |
+  //     +-> ..._d.so <- empty
+
+  void* handle = dlopen("libtest_check_order_reloc_siblings.so", RTLD_NOW | RTLD_NOLOAD);
+  ASSERT_TRUE(handle == nullptr);
+#ifdef __BIONIC__
+  // TODO: glibc returns nullptr on dlerror() here. Is it bug?
+  ASSERT_STREQ("dlopen failed: library \"libtest_check_order_reloc_siblings.so\" wasn't loaded and RTLD_NOLOAD prevented it", dlerror());
+#endif
+
+  handle = dlopen("libtest_check_order_reloc_siblings.so", RTLD_NOW | RTLD_LOCAL);
+  ASSERT_TRUE(handle != nullptr) << dlerror();
+
+  typedef int (*fn_t) (void);
+  fn_t fn = reinterpret_cast<fn_t>(dlsym(handle, "check_order_reloc_grandchild_get_answer"));
+  ASSERT_TRUE(fn != nullptr) << dlerror();
+  ASSERT_EQ(42, fn());
+
+  ASSERT_EQ(0, dlclose(handle));
+}
+
 TEST(dlfcn, dlopen_check_order_reloc_nephew) {
   // This is how this one works:
   // we lookup and call nephew_get_answer which is defined in '_2.so'
index 0f1a2b4dab582691190e015de76b4dfb5c16ed35..bd35a51a19cc7caf882d6cac28b173bc33eb29c3 100644 (file)
@@ -37,12 +37,13 @@ include $(LOCAL_PATH)/Android.build.testlib.mk
 # ..._2.so - empty
 # -----------------------------------------------------------------------------
 libtest_check_order_reloc_siblings_2_src_files := \
-    empty.cpp
+    dlopen_check_order_reloc_grandchild_answer.cpp
 
 libtest_check_order_reloc_siblings_2_shared_libraries := \
     libtest_check_order_reloc_siblings_c \
     libtest_check_order_reloc_siblings_d
 
+libtest_check_order_reloc_siblings_2_allow_undefined_symbols := true
 module := libtest_check_order_reloc_siblings_2
 include $(LOCAL_PATH)/Android.build.testlib.mk
 
@@ -86,6 +87,10 @@ libtest_check_order_reloc_siblings_c_src_files := \
     dlopen_check_order_reloc_answer_impl.cpp
 
 libtest_check_order_reloc_siblings_c_cflags := -D__ANSWER=2
+libtest_check_order_reloc_siblings_c_shared_libraries := \
+    libtest_check_order_reloc_siblings_c_1 \
+    libtest_check_order_reloc_siblings_c_2
+
 module := libtest_check_order_reloc_siblings_c
 include $(LOCAL_PATH)/Android.build.testlib.mk
 
@@ -118,6 +123,26 @@ libtest_check_order_reloc_siblings_f_src_files := \
 module := libtest_check_order_reloc_siblings_f
 include $(LOCAL_PATH)/Android.build.testlib.mk
 
+# -----------------------------------------------------------------------------
+# ..._c_1.so
+# -----------------------------------------------------------------------------
+libtest_check_order_reloc_siblings_c_1_src_files := \
+    dlopen_check_order_reloc_grandchild_answer_impl.cpp
+
+libtest_check_order_reloc_siblings_c_1_cflags := -D__ANSWER=42
+module := libtest_check_order_reloc_siblings_c_1
+include $(LOCAL_PATH)/Android.build.testlib.mk
+
+# -----------------------------------------------------------------------------
+# ..._c_2.so
+# -----------------------------------------------------------------------------
+libtest_check_order_reloc_siblings_c_2_src_files := \
+    dlopen_check_order_reloc_grandchild_answer_impl.cpp
+
+libtest_check_order_reloc_siblings_c_2_cflags := -D__ANSWER=0
+module := libtest_check_order_reloc_siblings_c_2
+include $(LOCAL_PATH)/Android.build.testlib.mk
+
 # -----------------------------------------------------------------------------
 # libtest_check_order_reloc_siblings.so
 # -----------------------------------------------------------------------------
diff --git a/tests/libs/dlopen_check_order_reloc_grandchild_answer.cpp b/tests/libs/dlopen_check_order_reloc_grandchild_answer.cpp
new file mode 100644 (file)
index 0000000..afb5f2c
--- /dev/null
@@ -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.
+ */
+
+extern "C" int check_order_reloc_grandchild_get_answer_impl();
+
+extern "C" int check_order_reloc_grandchild_get_answer() {
+  return check_order_reloc_grandchild_get_answer_impl();
+}
+
diff --git a/tests/libs/dlopen_check_order_reloc_grandchild_answer_impl.cpp b/tests/libs/dlopen_check_order_reloc_grandchild_answer_impl.cpp
new file mode 100644 (file)
index 0000000..32d2b24
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+
+extern "C" int check_order_reloc_grandchild_get_answer_impl() {
+  return __ANSWER;
+}