Merge "Count references for groups instead of instances"
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "gtest_ex.h"
|
||||
#include "private/ScopeGuard.h"
|
||||
|
||||
#include <string>
|
||||
@@ -362,6 +363,48 @@ TEST(dlfcn, dlopen_check_order_reloc_nephew) {
|
||||
ASSERT_EQ(0, dlclose(handle));
|
||||
}
|
||||
|
||||
TEST(dlfcn, check_unload_after_reloc) {
|
||||
// This is how this one works:
|
||||
// libtest_two_parents_parent1 <- answer_impl() used by libtest_two_parents_child
|
||||
// |
|
||||
// +-> libtest_two_parents_child
|
||||
//
|
||||
// libtest_two_parents_parent2 <- answer_impl() not used by libtest_two_parents_child
|
||||
// |
|
||||
// +-> libtest_two_parents_child
|
||||
//
|
||||
// Test dlopens parent1 which loads and relocates libtest_two_parents_child.so
|
||||
// as a second step it dlopens parent2 and dlcloses parent1...
|
||||
|
||||
test_isolated([] {
|
||||
void* handle = dlopen("libtest_two_parents_parent1.so", RTLD_NOW | RTLD_LOCAL);
|
||||
ASSERT_TRUE(handle != nullptr) << dlerror();
|
||||
|
||||
void* handle2 = dlopen("libtest_two_parents_parent2.so", RTLD_NOW | RTLD_LOCAL);
|
||||
ASSERT_TRUE(handle2 != nullptr) << dlerror();
|
||||
|
||||
typedef int (*fn_t) (void);
|
||||
fn_t fn = reinterpret_cast<fn_t>(dlsym(handle2, "check_order_reloc_get_answer"));
|
||||
ASSERT_TRUE(fn != nullptr) << dlerror();
|
||||
ASSERT_EQ(42, fn());
|
||||
|
||||
ASSERT_EQ(0, dlclose(handle));
|
||||
|
||||
handle = dlopen("libtest_two_parents_parent1.so", RTLD_NOW | RTLD_LOCAL | RTLD_NOLOAD);
|
||||
ASSERT_TRUE(handle != nullptr);
|
||||
ASSERT_EQ(0, dlclose(handle));
|
||||
|
||||
fn = reinterpret_cast<fn_t>(dlsym(handle2, "check_order_reloc_get_answer"));
|
||||
ASSERT_TRUE(fn != nullptr) << dlerror();
|
||||
ASSERT_EQ(42, fn());
|
||||
|
||||
ASSERT_EQ(0, dlclose(handle2));
|
||||
|
||||
handle = dlopen("libtest_two_parents_parent1.so", RTLD_NOW | RTLD_LOCAL | RTLD_NOLOAD);
|
||||
ASSERT_TRUE(handle == nullptr);
|
||||
});
|
||||
}
|
||||
|
||||
extern "C" int check_order_reloc_root_get_answer_impl() {
|
||||
return 42;
|
||||
}
|
||||
@@ -442,25 +485,25 @@ TEST(dlfcn, dlopen_check_rtld_global) {
|
||||
// libtest_with_dependency_loop_b.so -> libtest_with_dependency_loop_c.so ->
|
||||
// libtest_with_dependency_loop_a.so
|
||||
TEST(dlfcn, dlopen_check_loop) {
|
||||
void* handle = dlopen("libtest_with_dependency_loop.so", RTLD_NOW);
|
||||
#if defined(__BIONIC__)
|
||||
ASSERT_TRUE(handle == nullptr);
|
||||
ASSERT_STREQ("dlopen failed: recursive link to \"libtest_with_dependency_loop_a.so\"", dlerror());
|
||||
// This symbol should never be exposed
|
||||
void* f = dlsym(RTLD_DEFAULT, "dlopen_test_invalid_function");
|
||||
ASSERT_TRUE(f == nullptr);
|
||||
ASSERT_SUBSTR("undefined symbol: dlopen_test_invalid_function", dlerror());
|
||||
test_isolated([] {
|
||||
void* handle = dlopen("libtest_with_dependency_loop.so", RTLD_NOW);
|
||||
ASSERT_TRUE(handle != nullptr) << dlerror();
|
||||
void* f = dlsym(handle, "dlopen_test_loopy_function");
|
||||
ASSERT_TRUE(f != nullptr) << dlerror();
|
||||
EXPECT_TRUE(reinterpret_cast<bool (*)(void)>(f)());
|
||||
ASSERT_EQ(0, dlclose(handle));
|
||||
|
||||
// dlopen second time to make sure that the library wasn't loaded even though dlopen returned null.
|
||||
// This may happen if during cleanup the root library or one of the depended libs were not removed
|
||||
// from soinfo list.
|
||||
handle = dlopen("libtest_with_dependency_loop.so", RTLD_NOW | RTLD_NOLOAD);
|
||||
ASSERT_TRUE(handle == nullptr);
|
||||
ASSERT_STREQ("dlopen failed: library \"libtest_with_dependency_loop.so\" wasn't loaded and RTLD_NOLOAD prevented it", dlerror());
|
||||
#else // glibc allows recursive links
|
||||
ASSERT_TRUE(handle != nullptr);
|
||||
dlclose(handle);
|
||||
// dlopen second time to make sure that the library was unloaded correctly
|
||||
handle = dlopen("libtest_with_dependency_loop.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_with_dependency_loop.so\" wasn't loaded and RTLD_NOLOAD prevented it", dlerror());
|
||||
#endif
|
||||
|
||||
handle = dlopen("libtest_with_dependency_a.so", RTLD_NOW | RTLD_NOLOAD);
|
||||
ASSERT_TRUE(handle == nullptr);
|
||||
});
|
||||
}
|
||||
|
||||
TEST(dlfcn, dlopen_nodelete) {
|
||||
|
||||
52
tests/libs/Android.build.dlopen_2_parents_reloc.mk
Normal file
52
tests/libs/Android.build.dlopen_2_parents_reloc.mk
Normal file
@@ -0,0 +1,52 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Libraries used by dlfcn tests to verify local group ref_counting
|
||||
# libtest_two_parents*.so
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# ..._child.so - correct answer
|
||||
# -----------------------------------------------------------------------------
|
||||
libtest_two_parents_child_src_files := \
|
||||
dlopen_2_parents_reloc_answer.cpp
|
||||
|
||||
module := libtest_two_parents_child
|
||||
include $(LOCAL_PATH)/Android.build.testlib.mk
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# ..._parent1.so - correct answer
|
||||
# -----------------------------------------------------------------------------
|
||||
libtest_two_parents_parent1_src_files := \
|
||||
dlopen_check_order_reloc_answer_impl.cpp
|
||||
|
||||
libtest_two_parents_parent1_shared_libraries := libtest_two_parents_child
|
||||
libtest_two_parents_parent1_cflags := -D__ANSWER=42
|
||||
module := libtest_two_parents_parent1
|
||||
include $(LOCAL_PATH)/Android.build.testlib.mk
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# ..._parent2.so - incorrect answer
|
||||
# -----------------------------------------------------------------------------
|
||||
libtest_two_parents_parent2_src_files := \
|
||||
dlopen_check_order_reloc_answer_impl.cpp
|
||||
|
||||
libtest_two_parents_parent2_shared_libraries := libtest_two_parents_child
|
||||
libtest_two_parents_parent2_cflags := -D__ANSWER=1
|
||||
module := libtest_two_parents_parent2
|
||||
include $(LOCAL_PATH)/Android.build.testlib.mk
|
||||
|
||||
@@ -21,6 +21,7 @@ common_cppflags += -std=gnu++11
|
||||
common_additional_dependencies := \
|
||||
$(LOCAL_PATH)/Android.mk \
|
||||
$(LOCAL_PATH)/Android.build.dlext_testzip.mk \
|
||||
$(LOCAL_PATH)/Android.build.dlopen_2_parents_reloc.mk \
|
||||
$(LOCAL_PATH)/Android.build.dlopen_check_order_dlsym.mk \
|
||||
$(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_siblings.mk \
|
||||
$(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_main_executable.mk \
|
||||
@@ -165,6 +166,11 @@ libtest_nodelete_dt_flags_1_ldflags := -Wl,-z,nodelete
|
||||
module := libtest_nodelete_dt_flags_1
|
||||
include $(LOCAL_PATH)/Android.build.testlib.mk
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Build library with two parents
|
||||
# -----------------------------------------------------------------------------
|
||||
include $(LOCAL_PATH)/Android.build.dlopen_2_parents_reloc.mk
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Build libtest_check_order_dlsym.so with its dependencies.
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -185,7 +191,7 @@ include $(LOCAL_PATH)/Android.build.dlopen_check_order_reloc_main_executable.mk
|
||||
#
|
||||
# libtest_with_dependency_loop -> a -> b -> c -> a
|
||||
# -----------------------------------------------------------------------------
|
||||
libtest_with_dependency_loop_src_files := dlopen_testlib_invalid.cpp
|
||||
libtest_with_dependency_loop_src_files := dlopen_testlib_loopy_root.cpp
|
||||
|
||||
libtest_with_dependency_loop_shared_libraries := \
|
||||
libtest_with_dependency_loop_a
|
||||
@@ -196,7 +202,7 @@ include $(LOCAL_PATH)/Android.build.testlib.mk
|
||||
# -----------------------------------------------------------------------------
|
||||
# libtest_with_dependency_loop_a.so
|
||||
# -----------------------------------------------------------------------------
|
||||
libtest_with_dependency_loop_a_src_files := dlopen_testlib_invalid.cpp
|
||||
libtest_with_dependency_loop_a_src_files := dlopen_testlib_loopy_a.cpp
|
||||
|
||||
libtest_with_dependency_loop_a_shared_libraries := \
|
||||
libtest_with_dependency_loop_b_tmp
|
||||
@@ -209,7 +215,7 @@ include $(LOCAL_PATH)/Android.build.testlib.mk
|
||||
#
|
||||
# this is temporary placeholder - will be removed
|
||||
# -----------------------------------------------------------------------------
|
||||
libtest_with_dependency_loop_b_tmp_src_files := dlopen_testlib_invalid.cpp
|
||||
libtest_with_dependency_loop_b_tmp_src_files := dlopen_testlib_loopy_invalid.cpp
|
||||
libtest_with_dependency_loop_b_tmp_ldflags := -Wl,-soname=libtest_with_dependency_loop_b.so
|
||||
|
||||
module := libtest_with_dependency_loop_b_tmp
|
||||
@@ -218,7 +224,7 @@ include $(LOCAL_PATH)/Android.build.testlib.mk
|
||||
# -----------------------------------------------------------------------------
|
||||
# libtest_with_dependency_loop_b.so
|
||||
# -----------------------------------------------------------------------------
|
||||
libtest_with_dependency_loop_b_src_files := dlopen_testlib_invalid.cpp
|
||||
libtest_with_dependency_loop_b_src_files := dlopen_testlib_loopy_b.cpp
|
||||
libtest_with_dependency_loop_b_shared_libraries := libtest_with_dependency_loop_c
|
||||
|
||||
module := libtest_with_dependency_loop_b
|
||||
@@ -227,7 +233,7 @@ include $(LOCAL_PATH)/Android.build.testlib.mk
|
||||
# -----------------------------------------------------------------------------
|
||||
# libtest_with_dependency_loop_c.so
|
||||
# -----------------------------------------------------------------------------
|
||||
libtest_with_dependency_loop_c_src_files := dlopen_testlib_invalid.cpp
|
||||
libtest_with_dependency_loop_c_src_files := dlopen_testlib_loopy_c.cpp
|
||||
|
||||
libtest_with_dependency_loop_c_shared_libraries := \
|
||||
libtest_with_dependency_loop_a
|
||||
|
||||
23
tests/libs/dlopen_2_parents_reloc_answer.cpp
Normal file
23
tests/libs/dlopen_2_parents_reloc_answer.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 __attribute__((weak)) check_order_reloc_get_answer_impl() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int check_order_reloc_get_answer() {
|
||||
return check_order_reloc_get_answer_impl();
|
||||
}
|
||||
25
tests/libs/dlopen_testlib_loopy_a.cpp
Normal file
25
tests/libs/dlopen_testlib_loopy_a.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
extern "C" bool __attribute__((weak)) dlopen_test_loopy_function_impl() {
|
||||
return false;
|
||||
}
|
||||
|
||||
extern "C" bool dlopen_test_loopy_function() {
|
||||
return dlopen_test_loopy_function_impl();
|
||||
}
|
||||
21
tests/libs/dlopen_testlib_loopy_b.cpp
Normal file
21
tests/libs/dlopen_testlib_loopy_b.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
extern "C" bool dlopen_test_loopy_function_impl() {
|
||||
return false;
|
||||
}
|
||||
21
tests/libs/dlopen_testlib_loopy_c.cpp
Normal file
21
tests/libs/dlopen_testlib_loopy_c.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
extern "C" bool dlopen_test_loopy_function_impl() {
|
||||
return false;
|
||||
}
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// This file is used for libraries that are not supposed to
|
||||
// be successfully loaded/linked - therefore, this function should
|
||||
// not be visible via dlsym - (we are going to use this fact in tests)
|
||||
extern "C" int dlopen_test_invalid_function() {
|
||||
// This library should never be loaded
|
||||
static void __attribute__((constructor)) panic() {
|
||||
abort();
|
||||
}
|
||||
|
||||
21
tests/libs/dlopen_testlib_loopy_root.cpp
Normal file
21
tests/libs/dlopen_testlib_loopy_root.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
extern "C" bool dlopen_test_loopy_function_impl() {
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user