Skip to content

Commit 84abffd

Browse files
authored
Merge pull request #11 from petrhosek/unwind-cherry-pick
Drop the dependency on <algorithm>, add placement new inline
2 parents 1f484cb + 63090cf commit 84abffd

File tree

5 files changed

+36
-34
lines changed

5 files changed

+36
-34
lines changed

libunwind/CMakeLists.txt

+3-22
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ unwind_append_if(LIBUNWIND_CXX_FLAGS LIBUNWIND_HAS_EHSC_FLAG -EHsc)
285285

286286
unwind_append_if(LIBUNWIND_C_FLAGS LIBUNWIND_HAS_FUNWIND_TABLES -funwind-tables)
287287

288+
# Ensure that we don't depend on C++ standard library.
289+
unwind_append_if(LIBUNWIND_CXX_FLAGS LIBUNWIND_HAS_NOSTDINCXX_FLAG -nostdinc++)
290+
288291
# Assert
289292
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
290293
if (LIBUNWIND_ENABLE_ASSERTIONS)
@@ -339,28 +342,6 @@ endif()
339342

340343
include_directories(include)
341344

342-
find_path(
343-
LIBUNWIND_LIBCXX_INCLUDES_INTERNAL
344-
__libcpp_version
345-
PATHS ${LLVM_MAIN_SRC_DIR}/projects/libcxx/include
346-
${LLVM_MAIN_SRC_DIR}/runtimes/libcxx/include
347-
${LLVM_MAIN_SRC_DIR}/../libcxx/include
348-
NO_DEFAULT_PATH
349-
NO_CMAKE_FIND_ROOT_PATH
350-
)
351-
if ((NOT LIBUNWIND_STANDALONE_BUILD OR HAVE_LIBCXX) AND
352-
IS_DIRECTORY "${LIBUNWIND_LIBCXX_INCLUDES_INTERNAL}")
353-
set(LIBUNWIND_CXX_INCLUDE_PATHS_DEFAULT "${LIBUNWIND_LIBCXX_INCLUDES_INTERNAL}")
354-
endif()
355-
356-
set(LIBUNWIND_CXX_INCLUDE_PATHS "${LIBUNWIND_CXX_INCLUDE_PATHS_DEFAULT}" CACHE PATH
357-
"Paths to C++ header directories separated by ';'.")
358-
359-
if (NOT LIBUNWIND_CXX_INCLUDE_PATHS STREQUAL "")
360-
list(APPEND LIBUNWIND_CXX_FLAGS -nostdinc++)
361-
include_directories("${LIBUNWIND_CXX_INCLUDE_PATHS}")
362-
endif()
363-
364345
add_subdirectory(src)
365346

366347
if (LIBUNWIND_INCLUDE_DOCS)

libunwind/src/Unwind-EHABI.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <stdlib.h>
2222
#include <string.h>
2323

24-
#include <type_traits>
25-
2624
#include "config.h"
2725
#include "libunwind.h"
2826
#include "libunwind_ext.h"

libunwind/src/Unwind-seh.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ using namespace libunwind;
5050
/// Class of foreign exceptions based on unrecognized SEH exceptions.
5151
static const uint64_t kSEHExceptionClass = 0x434C4E4753454800; // CLNGSEH\0
5252

53+
// libunwind does not and should not depend on C++ library which means that we
54+
// need our own declaration of global placement new.
55+
void *operator new(size_t, void*);
56+
5357
/// Exception cleanup routine used by \c _GCC_specific_handler to
5458
/// free foreign exceptions.
5559
static void seh_exc_cleanup(_Unwind_Reason_Code urc, _Unwind_Exception *exc) {

libunwind/src/UnwindCursor.hpp

+25-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#ifndef __UNWINDCURSOR_HPP__
1313
#define __UNWINDCURSOR_HPP__
1414

15-
#include <algorithm>
1615
#include <stdint.h>
1716
#include <stdio.h>
1817
#include <stdlib.h>
@@ -106,7 +105,6 @@ class _LIBUNWIND_HIDDEN DwarfFDECache {
106105
static void dyldUnloadHook(const struct mach_header *mh, intptr_t slide);
107106
static bool _registeredForDyldUnloads;
108107
#endif
109-
// Can't use std::vector<> here because this code is below libc++.
110108
static entry *_buffer;
111109
static entry *_bufferUsed;
112110
static entry *_bufferEnd;
@@ -1229,7 +1227,6 @@ template<typename A>
12291227
struct EHABISectionIterator {
12301228
typedef EHABISectionIterator _Self;
12311229

1232-
typedef std::random_access_iterator_tag iterator_category;
12331230
typedef typename A::pint_t value_type;
12341231
typedef typename A::pint_t* pointer;
12351232
typedef typename A::pint_t& reference;
@@ -1283,6 +1280,29 @@ struct EHABISectionIterator {
12831280
const UnwindInfoSections* _sects;
12841281
};
12851282

1283+
namespace {
1284+
1285+
template <typename A>
1286+
EHABISectionIterator<A> EHABISectionUpperBound(
1287+
EHABISectionIterator<A> first,
1288+
EHABISectionIterator<A> last,
1289+
typename A::pint_t value) {
1290+
size_t len = last - first;
1291+
while (len > 0) {
1292+
size_t l2 = len / 2;
1293+
EHABISectionIterator<A> m = first + l2;
1294+
if (value < *m) {
1295+
len = l2;
1296+
} else {
1297+
first = ++m;
1298+
len -= l2 + 1;
1299+
}
1300+
}
1301+
return first;
1302+
}
1303+
1304+
}
1305+
12861306
template <typename A, typename R>
12871307
bool UnwindCursor<A, R>::getInfoFromEHABISection(
12881308
pint_t pc,
@@ -1294,7 +1314,7 @@ bool UnwindCursor<A, R>::getInfoFromEHABISection(
12941314
if (begin == end)
12951315
return false;
12961316

1297-
EHABISectionIterator<A> itNextPC = std::upper_bound(begin, end, pc);
1317+
EHABISectionIterator<A> itNextPC = EHABISectionUpperBound(begin, end, pc);
12981318
if (itNextPC == begin)
12991319
return false;
13001320
EHABISectionIterator<A> itThisPC = itNextPC - 1;
@@ -1304,8 +1324,7 @@ bool UnwindCursor<A, R>::getInfoFromEHABISection(
13041324
// in the table, we don't really know the function extent and have to choose a
13051325
// value for nextPC. Choosing max() will allow the range check during trace to
13061326
// succeed.
1307-
pint_t nextPC = (itNextPC == end) ? std::numeric_limits<pint_t>::max()
1308-
: itNextPC.functionAddress();
1327+
pint_t nextPC = (itNextPC == end) ? UINTPTR_MAX : itNextPC.functionAddress();
13091328
pint_t indexDataAddr = itThisPC.dataAddress();
13101329

13111330
if (indexDataAddr == 0)

libunwind/src/libunwind.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
#include <libunwind.h>
1414

15-
#ifndef NDEBUG
16-
#include <cstdlib> // getenv
17-
#endif
18-
1915
#include "libunwind_ext.h"
2016
#include "config.h"
2117

@@ -28,6 +24,10 @@
2824

2925
using namespace libunwind;
3026

27+
// libunwind does not and should not depend on C++ library which means that we
28+
// need our own declaration of global placement new.
29+
void *operator new(size_t, void*);
30+
3131
/// internal object to represent this processes address space
3232
LocalAddressSpace LocalAddressSpace::sThisAddressSpace;
3333

0 commit comments

Comments
 (0)