From 084f6ec9af0c054f0386a13f62daf0790d6244ae Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Thu, 12 Oct 2017 13:32:45 -0700 Subject: [PATCH 1/3] Don't use PR_SET_DUMPABLE to prevent crash dumping in death tests. Bug: http://b/27833000 Test: bionic-unit-tests are way faster Change-Id: I6ae029edcd4c4b4b0dfaf613fc17c208d3cb24d1 --- tests/BionicDeathTest.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/BionicDeathTest.h b/tests/BionicDeathTest.h index 31d2d6e8c..3e8d7b231 100644 --- a/tests/BionicDeathTest.h +++ b/tests/BionicDeathTest.h @@ -17,25 +17,29 @@ #ifndef BIONIC_TESTS_BIONIC_DEATH_TEST_H_ #define BIONIC_TESTS_BIONIC_DEATH_TEST_H_ -#include +#include -#include +#include class BionicDeathTest : public testing::Test { protected: virtual void SetUp() { // Suppress debuggerd stack traces. Too slow. - old_dumpable_ = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0); - prctl(PR_SET_DUMPABLE, 0, 0, 0, 0); - ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) { + struct sigaction action = {}; + action.sa_handler = SIG_DFL; + sigaction(signo, &action, &previous_); + } } virtual void TearDown() { - prctl(PR_SET_DUMPABLE, old_dumpable_, 0, 0, 0, 0); + for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) { + sigaction(signo, &previous_, nullptr); + } } private: - int old_dumpable_; + struct sigaction previous_; }; #endif // BIONIC_TESTS_BIONIC_DEATH_TEST_H_ From a0f6dc577e1bf63e199599d8dc79311a3083aec2 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Thu, 12 Oct 2017 13:34:12 -0700 Subject: [PATCH 2/3] Trivial style fix. Test: none Change-Id: I710d29293171c6160558dab66c515eae16b92923 --- libc/async_safe/include/async_safe/log.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/async_safe/include/async_safe/log.h b/libc/async_safe/include/async_safe/log.h index 2f5474292..10833e488 100644 --- a/libc/async_safe/include/async_safe/log.h +++ b/libc/async_safe/include/async_safe/log.h @@ -92,7 +92,7 @@ int async_safe_format_buffer_va_list(char* buffer, size_t buffer_size, const cha int async_safe_format_fd(int fd, const char* format , ...) __printflike(2, 3); int async_safe_format_log(int pri, const char* tag, const char* fmt, ...) __printflike(3, 4); -int async_safe_format_log_va_list( int pri, const char* tag, const char* fmt, va_list ap); +int async_safe_format_log_va_list(int pri, const char* tag, const char* fmt, va_list ap); int async_safe_write_log(int pri, const char* tag, const char* msg); #define CHECK(predicate) \ From 0e0e370154ea478c9d7102061cbb62d9bfea6c1d Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Thu, 12 Oct 2017 13:34:42 -0700 Subject: [PATCH 3/3] Add libc_nopthread. Add a static library containing the non-pthread dependent parts of libc. Bug: http://b/64400027 Test: sailfish boots Test: bionic-unit-tests32/64, no new failures Test: bionic-unit-tests-static32/64, no new failures Change-Id: I93dc3811acddad7936d11b369b98cefd945ee2d5 --- libc/Android.bp | 39 ++++++++++++++++++++++++++------------ libc/bionic/icu_static.cpp | 2 +- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/libc/Android.bp b/libc/Android.bp index e37ae089d..81135eafa 100644 --- a/libc/Android.bp +++ b/libc/Android.bp @@ -21,7 +21,6 @@ libc_common_src_files = [ "stdio/stdio_ext.cpp", "stdio/vfscanf.c", "stdio/vfwscanf.c", - "stdlib/atexit.c", "stdlib/exit.c", ] @@ -887,11 +886,6 @@ cc_library_static { cc_library_static { defaults: ["libc_defaults"], srcs: [ - // The following implementations depend on pthread data, so we can't - // include them in libc_ndk.a. - "bionic/__cxa_thread_atexit_impl.cpp", - "bionic/fork.cpp", - // The data that backs getauxval is initialized in the libc init // functions which are invoked by the linker. If this file is included // in libc_ndk.a, only one of the copies of the global data will be @@ -1396,7 +1390,6 @@ cc_library_static { "bionic/__gnu_basename.cpp", "bionic/__libc_current_sigrtmax.cpp", "bionic/__libc_current_sigrtmin.cpp", - "bionic/__set_errno.cpp", "bionic/abort.cpp", "bionic/accept.cpp", "bionic/accept4.cpp", @@ -1565,6 +1558,10 @@ cc_library_static { "bionic/wctype.cpp", "bionic/wcwidth.cpp", "bionic/wmempcpy.cpp", + + // This contains a weak stub implementation of __find_icu_symbol for wctype.cpp, + // which will be overridden by the actual one in libc.so. + "bionic/icu_static.cpp", ], multilib: { @@ -1619,6 +1616,12 @@ cc_library_static { "bionic/pthread_setschedparam.cpp", "bionic/pthread_sigmask.cpp", "bionic/pthread_spinlock.cpp", + + // The following implementations depend on pthread data or implementation, + // so we can't include them in libc_ndk.a. + "bionic/__cxa_thread_atexit_impl.cpp", + "stdlib/atexit.c", + "bionic/fork.cpp", ], cppflags: ["-Wold-style-cast"], @@ -1632,6 +1635,7 @@ cc_library_static { cc_library_static { defaults: ["libc_defaults"], + srcs: ["bionic/__set_errno.cpp"], arch: { arm: { srcs: ["arch-arm/syscalls/**/*.S"], @@ -1731,9 +1735,8 @@ cc_library_static { } // ======================================================== -// libc_common.a +// libc_nopthread.a // ======================================================== - cc_library_static { defaults: ["libc_defaults"], srcs: libc_common_src_files, @@ -1742,7 +1745,7 @@ cc_library_static { srcs: libc_common_src_files_32, }, }, - name: "libc_common", + name: "libc_nopthread", whole_static_libs: [ "libc_bionic", @@ -1757,7 +1760,6 @@ cc_library_static { "libc_openbsd", "libc_openbsd_large_stack", "libc_openbsd_ndk", - "libc_pthread", "libc_stack_protector", "libc_syscalls", "libc_tzcode", @@ -1771,6 +1773,20 @@ cc_library_static { }, } +// ======================================================== +// libc_common.a +// ======================================================== + +cc_library_static { + defaults: ["libc_defaults"], + name: "libc_common", + + whole_static_libs: [ + "libc_nopthread", + "libc_pthread", + ], +} + // ======================================================== // libc_nomalloc.a // ======================================================== @@ -1825,7 +1841,6 @@ cc_library { static: { srcs: [ "bionic/dl_iterate_phdr_static.cpp", - "bionic/icu_static.cpp", "bionic/malloc_common.cpp", ], cflags: ["-DLIBC_STATIC"], diff --git a/libc/bionic/icu_static.cpp b/libc/bionic/icu_static.cpp index cf24a381c..e81e291c7 100644 --- a/libc/bionic/icu_static.cpp +++ b/libc/bionic/icu_static.cpp @@ -29,6 +29,6 @@ #include "private/icu.h" // We don't have dlopen/dlsym for static binaries yet. -void* __find_icu_symbol(const char*) { +__attribute__((weak)) void* __find_icu_symbol(const char*) { return nullptr; }