From e22701ee8a8246e9648a60ebdbed2c415c103c91 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Mon, 23 Oct 2017 14:25:08 -0700 Subject: [PATCH] libbacktrace: remove exit time destructors. If libbacktrace is statically linked into a library that interposes libc, exit-time destructors can lead to a segfault upon exit if static variables are used after their destruction. Remove the one use of a static variable (with inconsequential performance impact of less than 1us per backtrace), and enable -Wexit-time-destructors to ensure this stays fixed in the future. Test: mma Change-Id: Icdaf1cf1c1f166cf501d9ecd1983c44e4305f7e9 --- libbacktrace/Android.bp | 4 ++++ libbacktrace/UnwindStack.cpp | 2 +- libunwindstack/Android.bp | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libbacktrace/Android.bp b/libbacktrace/Android.bp index ed1018302..0b2ce1dff 100644 --- a/libbacktrace/Android.bp +++ b/libbacktrace/Android.bp @@ -73,6 +73,10 @@ cc_library { defaults: ["libbacktrace_common"], host_supported: true, + cflags: [ + "-Wexit-time-destructors", + ], + srcs: [ "BacktraceMap.cpp", ], diff --git a/libbacktrace/UnwindStack.cpp b/libbacktrace/UnwindStack.cpp index 62e453fb8..d17c211d0 100644 --- a/libbacktrace/UnwindStack.cpp +++ b/libbacktrace/UnwindStack.cpp @@ -45,7 +45,7 @@ bool Backtrace::Unwind(unwindstack::Regs* regs, BacktraceMap* back_map, std::vector* frames, size_t num_ignore_frames) { - static std::vector skip_names{"libunwindstack.so", "libbacktrace.so"}; + std::vector skip_names{"libunwindstack.so", "libbacktrace.so"}; UnwindStackMap* stack_map = reinterpret_cast(back_map); auto process_memory = stack_map->process_memory(); unwindstack::Unwinder unwinder(MAX_BACKTRACE_FRAMES + num_ignore_frames, stack_map->stack_maps(), diff --git a/libunwindstack/Android.bp b/libunwindstack/Android.bp index e687a6895..c885c3f9b 100644 --- a/libunwindstack/Android.bp +++ b/libunwindstack/Android.bp @@ -65,6 +65,10 @@ cc_library { "Symbols.cpp", ], + cflags: [ + "-Wexit-time-destructors", + ], + target: { // Always disable optimizations for host to make it easier to debug. host: {