diff options
Diffstat (limited to 'tests/libs')
-rw-r--r-- | tests/libs/Android.build.dlext_testzip.mk | 41 | ||||
-rw-r--r-- | tests/libs/Android.build.testlib.mk | 22 | ||||
-rw-r--r-- | tests/libs/Android.mk | 227 | ||||
-rw-r--r-- | tests/libs/dlopen_testlib_answer.cpp | 25 | ||||
-rw-r--r-- | tests/libs/dlopen_testlib_ifunc.c | 65 | ||||
-rw-r--r-- | tests/libs/dlopen_testlib_invalid.cpp | 24 | ||||
-rw-r--r-- | tests/libs/dlopen_testlib_relo_check_dt_needed_order.cpp | 21 | ||||
-rw-r--r-- | tests/libs/dlopen_testlib_relo_check_dt_needed_order_1.cpp | 19 | ||||
-rw-r--r-- | tests/libs/dlopen_testlib_relo_check_dt_needed_order_2.cpp | 19 | ||||
-rw-r--r-- | tests/libs/dlopen_testlib_simple.cpp | 1 |
10 files changed, 443 insertions, 21 deletions
diff --git a/tests/libs/Android.build.dlext_testzip.mk b/tests/libs/Android.build.dlext_testzip.mk new file mode 100644 index 0000000..d05927e --- /dev/null +++ b/tests/libs/Android.build.dlext_testzip.mk @@ -0,0 +1,41 @@ +# +# 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. +# + +# ----------------------------------------------------------------------------- +# Library used by dlext tests - zipped and aligned +# ----------------------------------------------------------------------------- + +include $(CLEAR_VARS) + +LOCAL_MODULE_CLASS := SHARED_LIBRARIES +LOCAL_MODULE := libdlext_test_fd_zipaligned +LOCAL_MODULE_SUFFIX := .zip +LOCAL_MODULE_TAGS := tests +LOCAL_MODULE_PATH := $($(bionic_2nd_arch_prefix)TARGET_OUT_DATA_NATIVE_TESTS)/libdlext_test_fd +LOCAL_2ND_ARCH_VAR_PREFIX := $(bionic_2nd_arch_prefix) + +include $(BUILD_SYSTEM)/base_rules.mk + +my_shared_libs := \ + $($(bionic_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/libdlext_test_fd.so + +$(LOCAL_BUILT_MODULE): PRIVATE_ALIGNMENT := 4096 # PAGE_SIZE +$(LOCAL_BUILT_MODULE) : $(my_shared_libs) | $(ZIPALIGN) + @echo "Zipalign $(PRIVATE_ALIGNMENT): $@" + $(hide) rm -rf $(dir $@) && mkdir -p $(dir $@) + $(hide) cp $^ $(dir $@) + $(hide) (cd $(dir $@) && touch empty_file.txt && zip -rD0 $(notdir $@).unaligned empty_file.txt *.so) + $(hide) $(ZIPALIGN) $(PRIVATE_ALIGNMENT) $@.unaligned $@ diff --git a/tests/libs/Android.build.testlib.mk b/tests/libs/Android.build.testlib.mk new file mode 100644 index 0000000..5b688e4 --- /dev/null +++ b/tests/libs/Android.build.testlib.mk @@ -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. +# + +build_target := SHARED_LIBRARY +build_type := host +include $(TEST_PATH)/Android.build.mk +build_type := target +include $(TEST_PATH)/Android.build.mk + diff --git a/tests/libs/Android.mk b/tests/libs/Android.mk index 75df539..af3e070 100644 --- a/tests/libs/Android.mk +++ b/tests/libs/Android.mk @@ -17,6 +17,13 @@ LOCAL_PATH := $(call my-dir) TEST_PATH := $(LOCAL_PATH)/.. +common_cppflags += -std=gnu++11 +common_additional_dependencies := \ + $(LOCAL_PATH)/Android.mk \ + $(LOCAL_PATH)/Android.build.dlext_testzip.mk \ + $(LOCAL_PATH)/Android.build.testlib.mk \ + $(TEST_PATH)/Android.build.mk + # ----------------------------------------------------------------------------- # Library used by dlfcn tests. # ----------------------------------------------------------------------------- @@ -29,9 +36,7 @@ no-elf-hash-table-library_ldflags := \ module := no-elf-hash-table-library module_tag := optional -build_type := target -build_target := SHARED_LIBRARY -include $(TEST_PATH)/Android.build.mk +include $(LOCAL_PATH)/Android.build.testlib.mk endif # ----------------------------------------------------------------------------- @@ -45,15 +50,13 @@ libdlext_test_ldflags := \ module := libdlext_test module_tag := optional -build_type := target -build_target := SHARED_LIBRARY -include $(TEST_PATH)/Android.build.mk +include $(LOCAL_PATH)/Android.build.testlib.mk # ----------------------------------------------------------------------------- # create symlink to libdlext_test.so for symlink test # ----------------------------------------------------------------------------- # Use = instead of := to defer the evaluation of $@ -$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD = \ +$(TARGET_OUT)/lib/libdlext_test.so: PRIVATE_POST_INSTALL_CMD = \ $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so ifneq ($(TARGET_2ND_ARCH),) @@ -62,6 +65,13 @@ $(TARGET_OUT)/lib64/libdlext_test.so: PRIVATE_POST_INSTALL_CMD = \ $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so endif +# host symlinks +$(HOST_OUT)/lib64/libdlext_test.so: PRIVATE_POST_INSTALL_CMD = \ + $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so + +$(HOST_OUT)/lib/libdlext_test.so: PRIVATE_POST_INSTALL_CMD = \ + $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so + # ----------------------------------------------------------------------------- # Library used by dlext tests - without GNU RELRO program header # ----------------------------------------------------------------------------- @@ -91,15 +101,175 @@ build_target := SHARED_LIBRARY include $(TEST_PATH)/Android.build.mk # ----------------------------------------------------------------------------- +# Library used by dlext tests - zipped and aligned +# ----------------------------------------------------------------------------- +include $(CLEAR_VARS) +bionic_2nd_arch_prefix := +include $(LOCAL_PATH)/Android.build.dlext_testzip.mk +ifneq ($(TARGET_2ND_ARCH),) + bionic_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX) + include $(LOCAL_PATH)/Android.build.dlext_testzip.mk +endif + +# ----------------------------------------------------------------------------- # Library used by dlfcn tests # ----------------------------------------------------------------------------- libtest_simple_src_files := \ dlopen_testlib_simple.cpp module := libtest_simple -build_type := target -build_target := SHARED_LIBRARY -include $(TEST_PATH)/Android.build.mk +include $(LOCAL_PATH)/Android.build.testlib.mk + +# ----------------------------------------------------------------------------- +# Libraries used by dlfcn tests to verify correct load order: +# libtest_check_order_2_right.so +# ----------------------------------------------------------------------------- +libtest_check_order_2_right_src_files := \ + dlopen_testlib_answer.cpp + +libtest_check_order_2_right_cflags := -D__ANSWER=42 +module := libtest_check_order_2_right +include $(LOCAL_PATH)/Android.build.testlib.mk + +# ----------------------------------------------------------------------------- +# libtest_check_order_a.so +# ----------------------------------------------------------------------------- +libtest_check_order_a_src_files := \ + dlopen_testlib_answer.cpp + +libtest_check_order_a_cflags := -D__ANSWER=1 +module := libtest_check_order_a +include $(LOCAL_PATH)/Android.build.testlib.mk + +# ----------------------------------------------------------------------------- +# libtest_check_order_b.so +# ----------------------------------------------------------------------------- +libtest_check_order_b_src_files := \ + dlopen_testlib_answer.cpp + +libtest_check_order_b_cflags := -D__ANSWER=2 -D__ANSWER2=43 +module := libtest_check_order_b +include $(LOCAL_PATH)/Android.build.testlib.mk + +# ----------------------------------------------------------------------------- +# libtest_check_order_c.so +# ----------------------------------------------------------------------------- +libtest_check_order_3_c_src_files := \ + dlopen_testlib_answer.cpp + +libtest_check_order_3_c_cflags := -D__ANSWER=3 +module := libtest_check_order_3_c +include $(LOCAL_PATH)/Android.build.testlib.mk + +# ----------------------------------------------------------------------------- +# libtest_check_order_d.so +# ----------------------------------------------------------------------------- +libtest_check_order_d_src_files := \ + dlopen_testlib_answer.cpp + +libtest_check_order_d_shared_libraries := libtest_check_order_b +libtest_check_order_d_cflags := -D__ANSWER=4 -D__ANSWER2=4 +module := libtest_check_order_d +include $(LOCAL_PATH)/Android.build.testlib.mk + +# ----------------------------------------------------------------------------- +# libtest_check_order_left.so +# ----------------------------------------------------------------------------- +libtest_check_order_1_left_src_files := \ + empty.cpp + +libtest_check_order_1_left_shared_libraries := libtest_check_order_a libtest_check_order_b + +module := libtest_check_order_1_left +include $(LOCAL_PATH)/Android.build.testlib.mk + +# ----------------------------------------------------------------------------- +# libtest_check_order.so +# ----------------------------------------------------------------------------- +libtest_check_order_src_files := \ + empty.cpp + +libtest_check_order_shared_libraries := libtest_check_order_1_left \ + libtest_check_order_2_right libtest_check_order_3_c + +module := libtest_check_order +include $(LOCAL_PATH)/Android.build.testlib.mk + +# ----------------------------------------------------------------------------- +# Library with dependency loop used by dlfcn tests +# +# libtest_with_dependency_loop -> a -> b -> c -> a +# ----------------------------------------------------------------------------- +libtest_with_dependency_loop_src_files := dlopen_testlib_invalid.cpp + +libtest_with_dependency_loop_shared_libraries := \ + libtest_with_dependency_loop_a + +module := libtest_with_dependency_loop +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_shared_libraries := \ + libtest_with_dependency_loop_b_tmp + +module := libtest_with_dependency_loop_a +include $(LOCAL_PATH)/Android.build.testlib.mk + +# ----------------------------------------------------------------------------- +# libtest_with_dependency_loop_b.so +# +# 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_ldflags := -Wl,-soname=libtest_with_dependency_loop_b.so + +module := libtest_with_dependency_loop_b_tmp +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_shared_libraries := libtest_with_dependency_loop_c + +module := libtest_with_dependency_loop_b +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_shared_libraries := \ + libtest_with_dependency_loop_a + +module := libtest_with_dependency_loop_c +include $(LOCAL_PATH)/Android.build.testlib.mk + +# ----------------------------------------------------------------------------- +# libtest_relo_check_dt_needed_order.so +# | +# +-> libtest_relo_check_dt_needed_order_1.so +# | +# +-> libtest_relo_check_dt_needed_order_2.so +# ----------------------------------------------------------------------------- +libtest_relo_check_dt_needed_order_shared_libraries := \ + libtest_relo_check_dt_needed_order_1 libtest_relo_check_dt_needed_order_2 + +libtest_relo_check_dt_needed_order_src_files := dlopen_testlib_relo_check_dt_needed_order.cpp +libtest_relo_check_dt_needed_order_1_src_files := dlopen_testlib_relo_check_dt_needed_order_1.cpp +libtest_relo_check_dt_needed_order_2_src_files := dlopen_testlib_relo_check_dt_needed_order_2.cpp + +module := libtest_relo_check_dt_needed_order +include $(LOCAL_PATH)/Android.build.testlib.mk +module := libtest_relo_check_dt_needed_order_1 +include $(LOCAL_PATH)/Android.build.testlib.mk +module := libtest_relo_check_dt_needed_order_2 +include $(LOCAL_PATH)/Android.build.testlib.mk # ----------------------------------------------------------------------------- # Library with dependency used by dlfcn tests @@ -110,10 +280,33 @@ libtest_with_dependency_src_files := \ libtest_with_dependency_shared_libraries := libdlext_test module := libtest_with_dependency -build_type := target +include $(LOCAL_PATH)/Android.build.testlib.mk + +# ----------------------------------------------------------------------------- +# Library used by ifunc tests +# ----------------------------------------------------------------------------- +libtest_ifunc_src_files := \ + dlopen_testlib_ifunc.c + +libtest_ifunc_clang_host := false +module := libtest_ifunc build_target := SHARED_LIBRARY + +build_type := host include $(TEST_PATH)/Android.build.mk +ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) + ifeq ($(TARGET_ARCH),arm64) + libtest_ifunc_multilib := 64 + # TODO: This is a workaround - remove it once gcc + # removes its Android ifunc checks + libtest_ifunc_cflags := -mglibc + endif + + build_type := target + include $(TEST_PATH)/Android.build.mk +endif + # ----------------------------------------------------------------------------- # Library used by atexit tests # ----------------------------------------------------------------------------- @@ -122,11 +315,7 @@ libtest_atexit_src_files := \ atexit_testlib.cpp module := libtest_atexit -build_target := SHARED_LIBRARY -build_type := target -include $(TEST_PATH)/Android.build.mk -build_type := host -include $(TEST_PATH)/Android.build.mk +include $(LOCAL_PATH)/Android.build.testlib.mk # ----------------------------------------------------------------------------- # Library with weak function @@ -135,8 +324,4 @@ libtest_dlsym_weak_func_src_files := \ dlsym_weak_function.cpp module := libtest_dlsym_weak_func -build_target := SHARED_LIBRARY -build_type := target -include $(TEST_PATH)/Android.build.mk -build_type := host -include $(TEST_PATH)/Android.build.mk +include $(LOCAL_PATH)/Android.build.testlib.mk diff --git a/tests/libs/dlopen_testlib_answer.cpp b/tests/libs/dlopen_testlib_answer.cpp new file mode 100644 index 0000000..a4d7504 --- /dev/null +++ b/tests/libs/dlopen_testlib_answer.cpp @@ -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. + */ + +extern "C" int dlopen_test_get_answer() { + return __ANSWER; +} + +#ifdef __ANSWER2 +extern "C" int dlopen_test_get_answer2() { + return __ANSWER2; +} +#endif diff --git a/tests/libs/dlopen_testlib_ifunc.c b/tests/libs/dlopen_testlib_ifunc.c new file mode 100644 index 0000000..b68a3dd --- /dev/null +++ b/tests/libs/dlopen_testlib_ifunc.c @@ -0,0 +1,65 @@ +/* + * 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 <stdio.h> +#include <stdlib.h> + +static int g_flag = 0; + +static void __attribute__((constructor)) init_flag() { + g_flag = 1; +} + +static const char* is_ctor_called() __attribute__ ((ifunc("is_ctor_called_ifun"))); + +const char* foo() __attribute__ ((ifunc ("foo_ifunc"))); + +// Static linker creates GLOBAL/IFUNC symbol and JUMP_SLOT relocation type for plt segment +const char* is_ctor_called_jump_slot() __attribute__ ((ifunc("is_ctor_called_ifun"))); + +const char* is_ctor_called_irelative() { + // Call internal ifunc-resolved function with IRELATIVE reloc + return is_ctor_called(); +} + +const char* return_true() { + return "true"; +} + +const char* return_false() { + return "false"; +} + +const char* f1() { + return "unset"; +} + +const char* f2() { + return "set"; +} + +void* is_ctor_called_ifun() { + return g_flag == 0 ? return_false : return_true; +} + +void* foo_ifunc() { + char* choice = getenv("IFUNC_CHOICE"); + return choice == NULL ? f1 : f2; +} + +const char* foo_library() { + return foo(); +} diff --git a/tests/libs/dlopen_testlib_invalid.cpp b/tests/libs/dlopen_testlib_invalid.cpp new file mode 100644 index 0000000..f2039c6 --- /dev/null +++ b/tests/libs/dlopen_testlib_invalid.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> + +// 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() { + abort(); +} diff --git a/tests/libs/dlopen_testlib_relo_check_dt_needed_order.cpp b/tests/libs/dlopen_testlib_relo_check_dt_needed_order.cpp new file mode 100644 index 0000000..d8fb543 --- /dev/null +++ b/tests/libs/dlopen_testlib_relo_check_dt_needed_order.cpp @@ -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. + */ + +extern "C" int relo_test_get_answer_lib(); + +extern "C" int relo_test_get_answer() { + return relo_test_get_answer_lib(); +} diff --git a/tests/libs/dlopen_testlib_relo_check_dt_needed_order_1.cpp b/tests/libs/dlopen_testlib_relo_check_dt_needed_order_1.cpp new file mode 100644 index 0000000..4c877d0 --- /dev/null +++ b/tests/libs/dlopen_testlib_relo_check_dt_needed_order_1.cpp @@ -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 relo_test_get_answer_lib() { + return 1; +} diff --git a/tests/libs/dlopen_testlib_relo_check_dt_needed_order_2.cpp b/tests/libs/dlopen_testlib_relo_check_dt_needed_order_2.cpp new file mode 100644 index 0000000..10288a0 --- /dev/null +++ b/tests/libs/dlopen_testlib_relo_check_dt_needed_order_2.cpp @@ -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 relo_test_get_answer_lib() { + return 2; +} diff --git a/tests/libs/dlopen_testlib_simple.cpp b/tests/libs/dlopen_testlib_simple.cpp index afe54b4..bf750b2 100644 --- a/tests/libs/dlopen_testlib_simple.cpp +++ b/tests/libs/dlopen_testlib_simple.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include <stdint.h> #include <stdlib.h> uint32_t dlopen_testlib_taxicab_number = 1729; |