diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-06-23 00:21:56 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-06-23 00:21:56 +0000 |
commit | f3b7e66c5de750c61e082c6f8175a064b38114c8 (patch) | |
tree | b704864b4d2d154fa5b199651a2643c5842b0afd | |
parent | 4029f919437d5b2a19802f1666390c75fca0221d (diff) | |
parent | ed2adb9d03e5d783d723ae07ffeca02ae0ed11eb (diff) | |
download | bionic-f3b7e66c5de750c61e082c6f8175a064b38114c8.tar.gz |
Merge "Snap for 7478747 from 80c506f854945f86c4bff99688f26b8857b6bbb2 to ndk-release-r23" into ndk-release-r23
-rw-r--r-- | apex/Android.bp | 1 | ||||
-rw-r--r-- | libc/Android.bp | 4 | ||||
-rw-r--r-- | libc/bionic/malloc_heapprofd.cpp | 10 | ||||
-rw-r--r-- | libc/bionic/pthread_create.cpp | 5 | ||||
-rw-r--r-- | libc/include/stdlib.h | 2 | ||||
-rw-r--r-- | libc/include/sys/select.h | 18 | ||||
-rw-r--r-- | linker/Android.bp | 6 | ||||
-rw-r--r-- | linker/arch/arm64/linker_wrapper_begin.S | 30 | ||||
-rw-r--r-- | linker/arch/x86_64/linker_wrapper_begin.S | 30 | ||||
-rw-r--r-- | linker/linker_wrapper.cpp | 14 | ||||
-rw-r--r-- | tests/dl_test.cpp | 15 | ||||
-rw-r--r-- | tests/malloc_test.cpp | 2 | ||||
-rw-r--r-- | tests/stack_unwinding_test.cpp | 23 |
13 files changed, 122 insertions, 38 deletions
diff --git a/apex/Android.bp b/apex/Android.bp index 90a14b245..4879f474c 100644 --- a/apex/Android.bp +++ b/apex/Android.bp @@ -58,6 +58,7 @@ apex { "bionic-linker-config", ], updatable: false, + generate_hashtree: false, } sdk { diff --git a/libc/Android.bp b/libc/Android.bp index 892262173..fd1ce8126 100644 --- a/libc/Android.bp +++ b/libc/Android.bp @@ -1776,10 +1776,6 @@ cc_library { "com.android.runtime", ], - // Sorting bss symbols by size usually results in less dirty pages at run - // time, because small symbols are grouped together. - sort_bss_symbols_by_size: true, - lto: { never: true, }, diff --git a/libc/bionic/malloc_heapprofd.cpp b/libc/bionic/malloc_heapprofd.cpp index 198bcbab7..741b45e98 100644 --- a/libc/bionic/malloc_heapprofd.cpp +++ b/libc/bionic/malloc_heapprofd.cpp @@ -325,12 +325,12 @@ void HeapprofdRememberHookConflict() { static void CommonInstallHooks(libc_globals* globals) { void* impl_handle = atomic_load(&gHeapprofdHandle); - bool reusing_handle = impl_handle != nullptr; - if (!reusing_handle) { + if (impl_handle == nullptr) { impl_handle = LoadSharedLibrary(kHeapprofdSharedLib, kHeapprofdPrefix, &globals->malloc_dispatch_table); if (impl_handle == nullptr) { return; } + atomic_store(&gHeapprofdHandle, impl_handle); } else if (!InitSharedLibrary(impl_handle, kHeapprofdSharedLib, kHeapprofdPrefix, &globals->malloc_dispatch_table)) { return; } @@ -341,11 +341,7 @@ static void CommonInstallHooks(libc_globals* globals) { // MaybeModifyGlobals locks at this point. atomic_store(&gPreviousDefaultDispatchTable, GetDefaultDispatchTable()); - if (FinishInstallHooks(globals, nullptr, kHeapprofdPrefix)) { - atomic_store(&gHeapprofdHandle, impl_handle); - } else if (!reusing_handle) { - dlclose(impl_handle); - } + FinishInstallHooks(globals, nullptr, kHeapprofdPrefix); } void HeapprofdInstallHooksAtInit(libc_globals* globals) { diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp index 46d9e8672..121b26f82 100644 --- a/libc/bionic/pthread_create.cpp +++ b/libc/bionic/pthread_create.cpp @@ -331,6 +331,11 @@ void __set_stack_and_tls_vma_name(bool is_main_thread) { extern "C" int __rt_sigprocmask(int, const sigset64_t*, sigset64_t*, size_t); __attribute__((no_sanitize("hwaddress"))) +#ifdef __aarch64__ +// This function doesn't return, but it does appear in stack traces. Avoid using return PAC in this +// function because we may end up resetting IA, which may confuse unwinders due to mismatching keys. +__attribute__((target("branch-protection=bti"))) +#endif static int __pthread_start(void* arg) { pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(arg); diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index d7fdb4a52..583287f42 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -41,7 +41,7 @@ __BEGIN_DECLS #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 -__noreturn void abort(void); +__noreturn void abort(void) __attribute__((__nomerge__)); __noreturn void exit(int __status); #if __ANDROID_API__ >= 21 __noreturn void _Exit(int __status) __INTRODUCED_IN(21); diff --git a/libc/include/sys/select.h b/libc/include/sys/select.h index 79fc28d6b..65571eb19 100644 --- a/libc/include/sys/select.h +++ b/libc/include/sys/select.h @@ -101,31 +101,37 @@ int __FD_ISSET_chk(int, const fd_set*, size_t) __INTRODUCED_IN(21); /** * [select(2)](http://man7.org/linux/man-pages/man2/select.2.html) waits on a - * set of file descriptors. Use poll() instead. + * set of file descriptors. + * + * Use poll() instead. * * Returns the number of ready file descriptors on success, 0 for timeout, * and returns -1 and sets `errno` on failure. */ -int select(int __fd_count, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, struct timeval* __timeout); +int select(int __max_fd_plus_one, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, struct timeval* __timeout); /** * [pselect(2)](http://man7.org/linux/man-pages/man2/select.2.html) waits on a - * set of file descriptors. Use ppoll() instead. + * set of file descriptors. + * + * Use ppoll() instead. * * Returns the number of ready file descriptors on success, 0 for timeout, * and returns -1 and sets `errno` on failure. */ -int pselect(int __fd_count, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, const struct timespec* __timeout, const sigset_t* __mask); +int pselect(int __max_fd_plus_one, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, const struct timespec* __timeout, const sigset_t* __mask); /** * [pselect64(2)](http://man7.org/linux/man-pages/man2/select.2.html) waits on a - * set of file descriptors. Use ppoll64() instead. + * set of file descriptors. + * + * Use ppoll64() instead. * * Returns the number of ready file descriptors on success, 0 for timeout, * and returns -1 and sets `errno` on failure. * * Available since API level 28. */ -int pselect64(int __fd_count, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, const struct timespec* __timeout, const sigset64_t* __mask) __INTRODUCED_IN(28); +int pselect64(int __max_fd_plus_one, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, const struct timespec* __timeout, const sigset64_t* __mask) __INTRODUCED_IN(28); __END_DECLS diff --git a/linker/Android.bp b/linker/Android.bp index 4a5bf44a6..5b06e3c4d 100644 --- a/linker/Android.bp +++ b/linker/Android.bp @@ -55,15 +55,13 @@ cc_object { ], arch: { arm64: { - srcs: ["arch/arm64/begin.S"], + srcs: ["arch/arm64/linker_wrapper_begin.S"], }, x86_64: { - srcs: ["arch/x86_64/begin.S"], + srcs: ["arch/x86_64/linker_wrapper_begin.S"], }, }, - prefix_symbols: "__dlwrap_", - header_libs: ["libc_headers"], // We need to access Bionic private headers in the linker. diff --git a/linker/arch/arm64/linker_wrapper_begin.S b/linker/arch/arm64/linker_wrapper_begin.S new file mode 100644 index 000000000..90c53a26a --- /dev/null +++ b/linker/arch/arm64/linker_wrapper_begin.S @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#define _start __dlwrap__start +#include "begin.S" diff --git a/linker/arch/x86_64/linker_wrapper_begin.S b/linker/arch/x86_64/linker_wrapper_begin.S new file mode 100644 index 000000000..90c53a26a --- /dev/null +++ b/linker/arch/x86_64/linker_wrapper_begin.S @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#define _start __dlwrap__start +#include "begin.S" diff --git a/linker/linker_wrapper.cpp b/linker/linker_wrapper.cpp index fc673aa83..5ee2d3ee2 100644 --- a/linker/linker_wrapper.cpp +++ b/linker/linker_wrapper.cpp @@ -28,11 +28,13 @@ #include "private/KernelArgumentBlock.h" -extern const char linker_offset; +// The offset from the linker's original program header load addresses to +// the load addresses when embedded into a binary. Set by the extract_linker +// tool. +extern const char __dlwrap_linker_offset; -// This will be replaced by host_bionic_inject, but must be non-zero -// here so that it's placed in the data section. -uintptr_t original_start = 42; +// The real entry point of the binary to use after linker bootstrapping. +__LIBC_HIDDEN__ extern "C" void _start(); /* Find the load bias and base address of an executable or shared object loaded * by the kernel. The ELF file's PHDR table must have a PT_PHDR entry. @@ -63,7 +65,7 @@ extern "C" ElfW(Addr) __linker_init(void* raw_args) { reinterpret_cast<ElfW(Phdr)*>(args.getauxval(AT_PHDR)), args.getauxval(AT_PHNUM), &base_addr, &load_bias); - ElfW(Addr) linker_addr = base_addr + reinterpret_cast<uintptr_t>(&linker_offset); + ElfW(Addr) linker_addr = base_addr + reinterpret_cast<uintptr_t>(&__dlwrap_linker_offset); ElfW(Addr) linker_entry_offset = reinterpret_cast<ElfW(Ehdr)*>(linker_addr)->e_entry; for (ElfW(auxv_t)* v = args.auxv; v->a_type != AT_NULL; ++v) { @@ -73,7 +75,7 @@ extern "C" ElfW(Addr) __linker_init(void* raw_args) { } if (v->a_type == AT_ENTRY) { // Set AT_ENTRY to the proper entry point - v->a_un.a_val = base_addr + original_start; + v->a_un.a_val = reinterpret_cast<ElfW(Addr)>(&_start); } } diff --git a/tests/dl_test.cpp b/tests/dl_test.cpp index 766f27a0b..47bf13374 100644 --- a/tests/dl_test.cpp +++ b/tests/dl_test.cpp @@ -264,8 +264,11 @@ static void create_ld_config_file(const char* config_file) { #endif #if defined(__BIONIC__) -static bool is_debuggable_build() { - return android::base::GetBoolProperty("ro.debuggable", false); +// This test can't rely on ro.debuggable, because it might have been forced on +// in a user build ("Force Debuggable"). In that configuration, ro.debuggable is +// true, but Bionic's LD_CONFIG_FILE testing support is still disabled. +static bool is_user_build() { + return android::base::GetProperty("ro.build.type", "user") == std::string("user"); } #endif @@ -282,7 +285,7 @@ static bool is_debuggable_build() { TEST(dl, exec_with_ld_config_file) { #if defined(__BIONIC__) SKIP_WITH_HWASAN << "libclang_rt.hwasan is not found with custom ld config"; - if (!is_debuggable_build()) { + if (is_user_build()) { GTEST_SKIP() << "LD_CONFIG_FILE is not supported on user build"; } std::string helper = GetTestlibRoot() + @@ -319,7 +322,7 @@ TEST(dl, exec_with_ld_config_file) { TEST(dl, exec_with_ld_config_file_with_ld_preload) { #if defined(__BIONIC__) SKIP_WITH_HWASAN << "libclang_rt.hwasan is not found with custom ld config"; - if (!is_debuggable_build()) { + if (is_user_build()) { GTEST_SKIP() << "LD_CONFIG_FILE is not supported on user build"; } std::string helper = GetTestlibRoot() + @@ -356,8 +359,8 @@ TEST(dl, disable_ld_config_file) { // This test is only for CTS. GTEST_SKIP() << "test is not supported with root uid"; } - if (is_debuggable_build()) { - GTEST_SKIP() << "test is not supported on debuggable build"; + if (!is_user_build()) { + GTEST_SKIP() << "test requires user build"; } std::string error_message = std::string("CANNOT LINK EXECUTABLE ") + diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp index d73f2436d..30da5c32f 100644 --- a/tests/malloc_test.cpp +++ b/tests/malloc_test.cpp @@ -1355,6 +1355,8 @@ TEST(malloc, disable_mte) { TEST(malloc, allocation_slack) { #if defined(__BIONIC__) + SKIP_WITH_NATIVE_BRIDGE; // http://b/189606147 + bool allocator_scudo; GetAllocatorVersion(&allocator_scudo); if (!allocator_scudo) { diff --git a/tests/stack_unwinding_test.cpp b/tests/stack_unwinding_test.cpp index 0ff6f30a6..2f891a6e1 100644 --- a/tests/stack_unwinding_test.cpp +++ b/tests/stack_unwinding_test.cpp @@ -66,13 +66,28 @@ static int noinline unwind_one_frame_deeper() { return count; } -TEST(stack_unwinding, easy) { +static void UnwindTest() { int count = 0; _Unwind_Backtrace(FrameCounter, &count); int deeper_count = unwind_one_frame_deeper(); ASSERT_EQ(count + 1, deeper_count); } +TEST(stack_unwinding, easy) { + UnwindTest(); +} + +TEST(stack_unwinding, thread) { + pthread_t thread; + ASSERT_EQ(0, pthread_create(&thread, nullptr, [](void*) -> void* { + UnwindTest(); + return nullptr; + }, nullptr)); + void *retval; + ASSERT_EQ(0, pthread_join(thread, &retval)); + EXPECT_EQ(nullptr, retval); +} + struct UnwindData { volatile bool signal_handler_complete = false; int expected_frame_count = 0; @@ -98,7 +113,7 @@ static void verify_unwind_data(const UnwindData& unwind_data) { EXPECT_EQ(unwind_data.handler_frame_count + 1, unwind_data.handler_one_deeper_frame_count); } -static void noinline UnwindTest() { +static void noinline SignalUnwindTest() { g_unwind_data = {}; _Unwind_Backtrace(FrameCounter, &g_unwind_data.expected_frame_count); @@ -114,12 +129,12 @@ static void noinline UnwindTest() { TEST(stack_unwinding, unwind_through_signal_frame) { ScopedSignalHandler ssh(SIGUSR1, UnwindSignalHandler); - UnwindTest(); + SignalUnwindTest(); } // On LP32, the SA_SIGINFO flag gets you __restore_rt instead of __restore. TEST(stack_unwinding, unwind_through_signal_frame_SA_SIGINFO) { ScopedSignalHandler ssh(SIGUSR1, UnwindSignalHandler, SA_SIGINFO); - UnwindTest(); + SignalUnwindTest(); } |