diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index c9ba7527afb28..3fcd023ad1854 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -285,6 +285,9 @@ unwind_append_if(LIBUNWIND_CXX_FLAGS LIBUNWIND_HAS_EHSC_FLAG -EHsc) unwind_append_if(LIBUNWIND_C_FLAGS LIBUNWIND_HAS_FUNWIND_TABLES -funwind-tables) +# Ensure that we don't depend on C++ standard library. +unwind_append_if(LIBUNWIND_CXX_FLAGS LIBUNWIND_HAS_NOSTDINCXX_FLAG -nostdinc++) + # Assert string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) if (LIBUNWIND_ENABLE_ASSERTIONS) @@ -339,28 +342,6 @@ endif() include_directories(include) -find_path( - LIBUNWIND_LIBCXX_INCLUDES_INTERNAL - __libcpp_version - PATHS ${LLVM_MAIN_SRC_DIR}/projects/libcxx/include - ${LLVM_MAIN_SRC_DIR}/runtimes/libcxx/include - ${LLVM_MAIN_SRC_DIR}/../libcxx/include - NO_DEFAULT_PATH - NO_CMAKE_FIND_ROOT_PATH - ) -if ((NOT LIBUNWIND_STANDALONE_BUILD OR HAVE_LIBCXX) AND - IS_DIRECTORY "${LIBUNWIND_LIBCXX_INCLUDES_INTERNAL}") - set(LIBUNWIND_CXX_INCLUDE_PATHS_DEFAULT "${LIBUNWIND_LIBCXX_INCLUDES_INTERNAL}") -endif() - -set(LIBUNWIND_CXX_INCLUDE_PATHS "${LIBUNWIND_CXX_INCLUDE_PATHS_DEFAULT}" CACHE PATH - "Paths to C++ header directories separated by ';'.") - -if (NOT LIBUNWIND_CXX_INCLUDE_PATHS STREQUAL "") - list(APPEND LIBUNWIND_CXX_FLAGS -nostdinc++) - include_directories("${LIBUNWIND_CXX_INCLUDE_PATHS}") -endif() - add_subdirectory(src) if (LIBUNWIND_INCLUDE_DOCS) diff --git a/libunwind/src/Unwind-EHABI.cpp b/libunwind/src/Unwind-EHABI.cpp index f37732c6ac86f..7cbb2352b45ff 100644 --- a/libunwind/src/Unwind-EHABI.cpp +++ b/libunwind/src/Unwind-EHABI.cpp @@ -21,8 +21,6 @@ #include #include -#include - #include "config.h" #include "libunwind.h" #include "libunwind_ext.h" diff --git a/libunwind/src/Unwind-seh.cpp b/libunwind/src/Unwind-seh.cpp index 190bd75cd602d..c93b13e7f54a2 100644 --- a/libunwind/src/Unwind-seh.cpp +++ b/libunwind/src/Unwind-seh.cpp @@ -50,6 +50,10 @@ using namespace libunwind; /// Class of foreign exceptions based on unrecognized SEH exceptions. static const uint64_t kSEHExceptionClass = 0x434C4E4753454800; // CLNGSEH\0 +// libunwind does not and should not depend on C++ library which means that we +// need our own declaration of global placement new. +void *operator new(size_t, void*); + /// Exception cleanup routine used by \c _GCC_specific_handler to /// free foreign exceptions. static void seh_exc_cleanup(_Unwind_Reason_Code urc, _Unwind_Exception *exc) { diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp index d5602d4c4ba00..94be8d2ec0a7d 100644 --- a/libunwind/src/UnwindCursor.hpp +++ b/libunwind/src/UnwindCursor.hpp @@ -12,7 +12,6 @@ #ifndef __UNWINDCURSOR_HPP__ #define __UNWINDCURSOR_HPP__ -#include #include #include #include @@ -106,7 +105,6 @@ class _LIBUNWIND_HIDDEN DwarfFDECache { static void dyldUnloadHook(const struct mach_header *mh, intptr_t slide); static bool _registeredForDyldUnloads; #endif - // Can't use std::vector<> here because this code is below libc++. static entry *_buffer; static entry *_bufferUsed; static entry *_bufferEnd; @@ -1229,7 +1227,6 @@ template struct EHABISectionIterator { typedef EHABISectionIterator _Self; - typedef std::random_access_iterator_tag iterator_category; typedef typename A::pint_t value_type; typedef typename A::pint_t* pointer; typedef typename A::pint_t& reference; @@ -1283,6 +1280,29 @@ struct EHABISectionIterator { const UnwindInfoSections* _sects; }; +namespace { + +template +EHABISectionIterator EHABISectionUpperBound( + EHABISectionIterator first, + EHABISectionIterator last, + typename A::pint_t value) { + size_t len = last - first; + while (len > 0) { + size_t l2 = len / 2; + EHABISectionIterator m = first + l2; + if (value < *m) { + len = l2; + } else { + first = ++m; + len -= l2 + 1; + } + } + return first; +} + +} + template bool UnwindCursor::getInfoFromEHABISection( pint_t pc, @@ -1294,7 +1314,7 @@ bool UnwindCursor::getInfoFromEHABISection( if (begin == end) return false; - EHABISectionIterator itNextPC = std::upper_bound(begin, end, pc); + EHABISectionIterator itNextPC = EHABISectionUpperBound(begin, end, pc); if (itNextPC == begin) return false; EHABISectionIterator itThisPC = itNextPC - 1; @@ -1304,8 +1324,7 @@ bool UnwindCursor::getInfoFromEHABISection( // in the table, we don't really know the function extent and have to choose a // value for nextPC. Choosing max() will allow the range check during trace to // succeed. - pint_t nextPC = (itNextPC == end) ? std::numeric_limits::max() - : itNextPC.functionAddress(); + pint_t nextPC = (itNextPC == end) ? UINTPTR_MAX : itNextPC.functionAddress(); pint_t indexDataAddr = itThisPC.dataAddress(); if (indexDataAddr == 0) diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp index a8f48350d2d2b..823bc40c542c8 100644 --- a/libunwind/src/libunwind.cpp +++ b/libunwind/src/libunwind.cpp @@ -12,10 +12,6 @@ #include -#ifndef NDEBUG -#include // getenv -#endif - #include "libunwind_ext.h" #include "config.h" @@ -28,6 +24,10 @@ using namespace libunwind; +// libunwind does not and should not depend on C++ library which means that we +// need our own declaration of global placement new. +void *operator new(size_t, void*); + /// internal object to represent this processes address space LocalAddressSpace LocalAddressSpace::sThisAddressSpace;