[compiler-rt] r240586 - One more change required to build the sanitizers for iOS.
Chris Bieneman
beanz at apple.com
Wed Jun 24 13:13:45 PDT 2015
Author: cbieneman
Date: Wed Jun 24 15:13:44 2015
New Revision: 240586
URL: http://llvm.org/viewvc/llvm-project?rev=240586&view=rev
Log:
One more change required to build the sanitizers for iOS.
Summary: _Unwind_Backtrace is not available on iOS, so we should ifdef out the posix implementations of BufferedStackTrace::SlowUnwindStack and BufferedStackTrace::SlowUnwindStackWithContext on iOS.
Reviewers: samsonov
Reviewed By: samsonov
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D10696
Added:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc
- copied, changed from r240576, compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_posix_libcdep.cc
Removed:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_posix_libcdep.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=240586&r1=240585&r2=240586&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Wed Jun 24 15:13:44 2015
@@ -44,7 +44,7 @@ set(SANITIZER_LIBCDEP_SOURCES
sanitizer_symbolizer_libcdep.cc
sanitizer_symbolizer_posix_libcdep.cc
sanitizer_symbolizer_process_libcdep.cc
- sanitizer_unwind_posix_libcdep.cc)
+ sanitizer_unwind_linux_libcdep.cc)
# Explicitly list all sanitizer_common headers. Not all of these are
# included in sanitizer_common source files, but we need to depend on
Copied: compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc (from r240576, compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_posix_libcdep.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc?p2=compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc&p1=compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_posix_libcdep.cc&r1=240576&r2=240586&rev=240586&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_posix_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc Wed Jun 24 15:13:44 2015
@@ -1,4 +1,4 @@
-//===-- sanitizer_unwind_posix.cc ----------------------------------------===//
+//===-- sanitizer_unwind_linux_libcdep.cc ---------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -8,11 +8,11 @@
//===----------------------------------------------------------------------===//
//
// This file contains the unwind.h-based (aka "slow") stack unwinding routines
-// available to the tools on Linux, Android, FreeBSD and OS X.
+// available to the tools on Linux, Android, and FreeBSD.
//===----------------------------------------------------------------------===//
#include "sanitizer_platform.h"
-#if SANITIZER_POSIX
+#if SANITIZER_FREEBSD || SANITIZER_LINUX
#include "sanitizer_common.h"
#include "sanitizer_stacktrace.h"
@@ -155,4 +155,4 @@ void BufferedStackTrace::SlowUnwindStack
} // namespace __sanitizer
-#endif // SANITIZER_POSIX
+#endif // SANITIZER_FREEBSD || SANITIZER_LINUX
Removed: compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_posix_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_posix_libcdep.cc?rev=240585&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_posix_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_posix_libcdep.cc (removed)
@@ -1,158 +0,0 @@
-//===-- sanitizer_unwind_posix.cc ----------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file contains the unwind.h-based (aka "slow") stack unwinding routines
-// available to the tools on Linux, Android, FreeBSD and OS X.
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_platform.h"
-#if SANITIZER_POSIX
-#include "sanitizer_common.h"
-#include "sanitizer_stacktrace.h"
-
-#if SANITIZER_ANDROID
-#include <dlfcn.h> // for dlopen()
-#endif
-
-#if SANITIZER_FREEBSD
-#define _GNU_SOURCE // to declare _Unwind_Backtrace() from <unwind.h>
-#endif
-#include <unwind.h>
-
-namespace __sanitizer {
-
-//------------------------- SlowUnwindStack -----------------------------------
-
-typedef struct {
- uptr absolute_pc;
- uptr stack_top;
- uptr stack_size;
-} backtrace_frame_t;
-
-extern "C" {
-typedef void *(*acquire_my_map_info_list_func)();
-typedef void (*release_my_map_info_list_func)(void *map);
-typedef sptr (*unwind_backtrace_signal_arch_func)(
- void *siginfo, void *sigcontext, void *map_info_list,
- backtrace_frame_t *backtrace, uptr ignore_depth, uptr max_depth);
-acquire_my_map_info_list_func acquire_my_map_info_list;
-release_my_map_info_list_func release_my_map_info_list;
-unwind_backtrace_signal_arch_func unwind_backtrace_signal_arch;
-} // extern "C"
-
-#if SANITIZER_ANDROID
-void SanitizerInitializeUnwinder() {
- void *p = dlopen("libcorkscrew.so", RTLD_LAZY);
- if (!p) {
- VReport(1,
- "Failed to open libcorkscrew.so. You may see broken stack traces "
- "in SEGV reports.");
- return;
- }
- acquire_my_map_info_list =
- (acquire_my_map_info_list_func)(uptr)dlsym(p, "acquire_my_map_info_list");
- release_my_map_info_list =
- (release_my_map_info_list_func)(uptr)dlsym(p, "release_my_map_info_list");
- unwind_backtrace_signal_arch = (unwind_backtrace_signal_arch_func)(uptr)dlsym(
- p, "unwind_backtrace_signal_arch");
- if (!acquire_my_map_info_list || !release_my_map_info_list ||
- !unwind_backtrace_signal_arch) {
- VReport(1,
- "Failed to find one of the required symbols in libcorkscrew.so. "
- "You may see broken stack traces in SEGV reports.");
- acquire_my_map_info_list = 0;
- unwind_backtrace_signal_arch = 0;
- release_my_map_info_list = 0;
- }
-}
-#endif
-
-#ifdef __arm__
-#define UNWIND_STOP _URC_END_OF_STACK
-#define UNWIND_CONTINUE _URC_NO_REASON
-#else
-#define UNWIND_STOP _URC_NORMAL_STOP
-#define UNWIND_CONTINUE _URC_NO_REASON
-#endif
-
-uptr Unwind_GetIP(struct _Unwind_Context *ctx) {
-#if defined(__arm__) && !SANITIZER_MAC
- uptr val;
- _Unwind_VRS_Result res = _Unwind_VRS_Get(ctx, _UVRSC_CORE,
- 15 /* r15 = PC */, _UVRSD_UINT32, &val);
- CHECK(res == _UVRSR_OK && "_Unwind_VRS_Get failed");
- // Clear the Thumb bit.
- return val & ~(uptr)1;
-#else
- return _Unwind_GetIP(ctx);
-#endif
-}
-
-struct UnwindTraceArg {
- BufferedStackTrace *stack;
- u32 max_depth;
-};
-
-_Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, void *param) {
- UnwindTraceArg *arg = (UnwindTraceArg*)param;
- CHECK_LT(arg->stack->size, arg->max_depth);
- uptr pc = Unwind_GetIP(ctx);
- arg->stack->trace_buffer[arg->stack->size++] = pc;
- if (arg->stack->size == arg->max_depth) return UNWIND_STOP;
- return UNWIND_CONTINUE;
-}
-
-void BufferedStackTrace::SlowUnwindStack(uptr pc, u32 max_depth) {
- CHECK_GE(max_depth, 2);
- size = 0;
- UnwindTraceArg arg = {this, Min(max_depth + 1, kStackTraceMax)};
- _Unwind_Backtrace(Unwind_Trace, &arg);
- // We need to pop a few frames so that pc is on top.
- uptr to_pop = LocatePcInTrace(pc);
- // trace_buffer[0] belongs to the current function so we always pop it,
- // unless there is only 1 frame in the stack trace (1 frame is always better
- // than 0!).
- // 1-frame stacks don't normally happen, but this depends on the actual
- // unwinder implementation (libgcc, libunwind, etc) which is outside of our
- // control.
- if (to_pop == 0 && size > 1)
- to_pop = 1;
- PopStackFrames(to_pop);
- trace_buffer[0] = pc;
-}
-
-void BufferedStackTrace::SlowUnwindStackWithContext(uptr pc, void *context,
- u32 max_depth) {
- CHECK_GE(max_depth, 2);
- if (!unwind_backtrace_signal_arch) {
- SlowUnwindStack(pc, max_depth);
- return;
- }
-
- void *map = acquire_my_map_info_list();
- CHECK(map);
- InternalScopedBuffer<backtrace_frame_t> frames(kStackTraceMax);
- // siginfo argument appears to be unused.
- sptr res = unwind_backtrace_signal_arch(/* siginfo */ 0, context, map,
- frames.data(),
- /* ignore_depth */ 0, max_depth);
- release_my_map_info_list(map);
- if (res < 0) return;
- CHECK_LE((uptr)res, kStackTraceMax);
-
- size = 0;
- // +2 compensate for libcorkscrew unwinder returning addresses of call
- // instructions instead of raw return addresses.
- for (sptr i = 0; i < res; ++i)
- trace_buffer[size++] = frames[i].absolute_pc + 2;
-}
-
-} // namespace __sanitizer
-
-#endif // SANITIZER_POSIX
More information about the llvm-commits
mailing list