Yet another relocation test

This time we check if a -> b -> c function in 'a' relocates against
 implementation in 'c'.

Change-Id: I528180c3efd346bd447ea0237e5a8a0ac3cc031f
This commit is contained in:
Dmitriy Ivanov 2014-11-18 17:26:31 -08:00
parent 27aa9c5b50
commit 7699d13a74
5 changed files with 107 additions and 1 deletions

View 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

View 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'

View 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
# -----------------------------------------------------------------------------

View File

@ -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();
}

View File

@ -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;
}