[libunwind] r282575 - [libunwind] Add support for a single-threaded libunwind build
Asiri Rathnayake via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 28 03:57:15 PDT 2016
Author: asiri
Date: Wed Sep 28 05:57:15 2016
New Revision: 282575
URL: http://llvm.org/viewvc/llvm-project?rev=282575&view=rev
Log:
[libunwind] Add support for a single-threaded libunwind build
The EHABI unwinder is thread-agnostic, SJLJ unwinder and the DWARF unwinder have
a couple of pthread dependencies.
This patch makes it possible to build the whole of libunwind for a
single-threaded environment.
Reviewers: compnerd
Differential revision: https://reviews.llvm.org/D24984
Modified:
libunwind/trunk/CMakeLists.txt
libunwind/trunk/src/CMakeLists.txt
libunwind/trunk/src/UnwindCursor.hpp
libunwind/trunk/src/Unwind_AppleExtras.cpp
libunwind/trunk/src/config.h
Modified: libunwind/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libunwind/trunk/CMakeLists.txt?rev=282575&r1=282574&r2=282575&view=diff
==============================================================================
--- libunwind/trunk/CMakeLists.txt (original)
+++ libunwind/trunk/CMakeLists.txt Wed Sep 28 05:57:15 2016
@@ -107,6 +107,7 @@ option(LIBUNWIND_ENABLE_SHARED "Build li
option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON)
option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF)
option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF)
+option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON)
set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
@@ -242,6 +243,11 @@ if (NOT LIBUNWIND_ENABLE_CROSS_UNWINDING
list(APPEND LIBUNWIND_COMPILE_FLAGS -D_LIBUNWIND_IS_NATIVE_ONLY)
endif()
+# Threading-support
+if (NOT LIBUNWIND_ENABLE_THREADS)
+ list(APPEND LIBUNWIND_COMPILE_FLAGS -D_LIBUNWIND_HAS_NO_THREADS)
+endif()
+
# ARM WMMX register support
if (LIBUNWIND_ENABLE_ARM_WMMX)
# __ARM_WMMX is a compiler pre-define (as per the ACLE 2.0). Clang does not
Modified: libunwind/trunk/src/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/CMakeLists.txt?rev=282575&r1=282574&r2=282575&view=diff
==============================================================================
--- libunwind/trunk/src/CMakeLists.txt (original)
+++ libunwind/trunk/src/CMakeLists.txt Wed Sep 28 05:57:15 2016
@@ -53,7 +53,9 @@ set(LIBUNWIND_SOURCES
set(libraries ${LIBUNWINDCXX_ABI_LIBRARIES})
append_if(libraries LIBUNWIND_HAS_C_LIB c)
append_if(libraries LIBUNWIND_HAS_DL_LIB dl)
-append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
+if (LIBUNWIND_ENABLE_THREADS)
+ append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
+endif()
# Setup flags.
append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_FPIC_FLAG -fPIC)
Modified: libunwind/trunk/src/UnwindCursor.hpp
URL: http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindCursor.hpp?rev=282575&r1=282574&r2=282575&view=diff
==============================================================================
--- libunwind/trunk/src/UnwindCursor.hpp (original)
+++ libunwind/trunk/src/UnwindCursor.hpp Wed Sep 28 05:57:15 2016
@@ -16,7 +16,9 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <pthread.h>
+#ifndef _LIBUNWIND_HAS_NO_THREADS
+ #include <pthread.h>
+#endif
#include <unwind.h>
#ifdef __APPLE__
@@ -60,7 +62,9 @@ private:
// These fields are all static to avoid needing an initializer.
// There is only one instance of this class per process.
+#ifndef _LIBUNWIND_HAS_NO_THREADS
static pthread_rwlock_t _lock;
+#endif
#ifdef __APPLE__
static void dyldUnloadHook(const struct mach_header *mh, intptr_t slide);
static bool _registeredForDyldUnloads;
@@ -87,8 +91,10 @@ DwarfFDECache<A>::_bufferEnd = &_initial
template <typename A>
typename DwarfFDECache<A>::entry DwarfFDECache<A>::_initialBuffer[64];
+#ifndef _LIBUNWIND_HAS_NO_THREADS
template <typename A>
pthread_rwlock_t DwarfFDECache<A>::_lock = PTHREAD_RWLOCK_INITIALIZER;
+#endif
#ifdef __APPLE__
template <typename A>
Modified: libunwind/trunk/src/Unwind_AppleExtras.cpp
URL: http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/Unwind_AppleExtras.cpp?rev=282575&r1=282574&r2=282575&view=diff
==============================================================================
--- libunwind/trunk/src/Unwind_AppleExtras.cpp (original)
+++ libunwind/trunk/src/Unwind_AppleExtras.cpp Wed Sep 28 05:57:15 2016
@@ -185,21 +185,29 @@ bool checkKeyMgrRegisteredFDEs(uintptr_t
#if !defined(FOR_DYLD) && _LIBUNWIND_BUILD_SJLJ_APIS
-#include <System/pthread_machdep.h>
+#ifndef _LIBUNWIND_HAS_NO_THREADS
+ #include <System/pthread_machdep.h>
+#else
+ _Unwind_FunctionContext *fc_ = nullptr;
+#endif
// Accessors to get get/set linked list of frames for sjlj based execeptions.
_LIBUNWIND_HIDDEN
struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() {
+#ifndef _LIBUNWIND_HAS_NO_THREADS
return (struct _Unwind_FunctionContext *)
_pthread_getspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key);
+#else
+ return fc_;
+#endif
}
_LIBUNWIND_HIDDEN
void __Unwind_SjLj_SetTopOfFunctionStack(struct _Unwind_FunctionContext *fc) {
+#ifndef _LIBUNWIND_HAS_NO_THREADS
_pthread_setspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key, fc);
+#else
+ fc_ = fc;
+#endif
}
#endif
-
-
-
-
Modified: libunwind/trunk/src/config.h
URL: http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/config.h?rev=282575&r1=282574&r2=282575&view=diff
==============================================================================
--- libunwind/trunk/src/config.h (original)
+++ libunwind/trunk/src/config.h Wed Sep 28 05:57:15 2016
@@ -85,13 +85,20 @@
} while (0)
#define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__)
+#if defined(_LIBUNWIND_HAS_NO_THREADS)
+ // only used with pthread calls, not needed for the single-threaded builds
+ #define _LIBUNWIND_LOG_NON_ZERO(x)
+#endif
+
// Macros that define away in non-Debug builds
#ifdef NDEBUG
#define _LIBUNWIND_DEBUG_LOG(msg, ...)
#define _LIBUNWIND_TRACE_API(msg, ...)
#define _LIBUNWIND_TRACING_UNWINDING 0
#define _LIBUNWIND_TRACE_UNWINDING(msg, ...)
- #define _LIBUNWIND_LOG_NON_ZERO(x) x
+ #ifndef _LIBUNWIND_LOG_NON_ZERO
+ #define _LIBUNWIND_LOG_NON_ZERO(x) x
+ #endif
#else
#ifdef __cplusplus
extern "C" {
@@ -102,12 +109,14 @@
}
#endif
#define _LIBUNWIND_DEBUG_LOG(msg, ...) _LIBUNWIND_LOG(msg, __VA_ARGS__)
- #define _LIBUNWIND_LOG_NON_ZERO(x) \
- do { \
- int _err = x; \
- if ( _err != 0 ) \
- _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \
- } while (0)
+ #ifndef _LIBUNWIND_LOG_NON_ZERO
+ #define _LIBUNWIND_LOG_NON_ZERO(x) \
+ do { \
+ int _err = x; \
+ if ( _err != 0 ) \
+ _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \
+ } while (0)
+ #endif
#define _LIBUNWIND_TRACE_API(msg, ...) \
do { \
if ( logAPIs() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \
More information about the cfe-commits
mailing list