[PATCH] D11897: [libunwind] Make it possible to use libunwind without heap.
whitequark via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 20 21:55:32 PDT 2015
whitequark updated this revision to Diff 35211.
whitequark added a comment.
I've tried to refactor this code to use a functor, but the functor would have to somehow gain access to the private fields of DwarfFDECache. Every solution I could imagine was far more contrived than a #ifdef; if you have a good one, I'm all ears.
In light of this and also the fact that there are more #ifdef's anyway in the DWARF parser, I've instead changed the patch to remove the heinous semicolon hack. Now it is just the body of add() which is conditionally included. This looks straightforward enough to me.
What do you think?
http://reviews.llvm.org/D11897
Files:
src/DwarfParser.hpp
src/UnwindCursor.hpp
src/libunwind.cpp
Index: src/libunwind.cpp
===================================================================
--- src/libunwind.cpp
+++ src/libunwind.cpp
@@ -304,7 +304,7 @@
#endif
-#if _LIBUNWIND_SUPPORT_DWARF_UNWIND
+#if !defined(_LIBUNWIND_NO_HEAP) && _LIBUNWIND_SUPPORT_DWARF_UNWIND
/// SPI: walks cached dwarf entries
_LIBUNWIND_EXPORT void unw_iterate_dwarf_unwind_cache(void (*func)(
unw_word_t ip_start, unw_word_t ip_end, unw_word_t fde, unw_word_t mh)) {
@@ -338,7 +338,7 @@
// fde is own mh_group
DwarfFDECache<LocalAddressSpace>::removeAllIn((LocalAddressSpace::pint_t)fde);
}
-#endif // _LIBUNWIND_SUPPORT_DWARF_UNWIND
+#endif // !defined(_LIBUNWIND_NO_HEAP) && _LIBUNWIND_SUPPORT_DWARF_UNWIND
Index: src/UnwindCursor.hpp
===================================================================
--- src/UnwindCursor.hpp
+++ src/UnwindCursor.hpp
@@ -114,6 +114,7 @@
template <typename A>
void DwarfFDECache<A>::add(pint_t mh, pint_t ip_start, pint_t ip_end,
pint_t fde) {
+#ifndef _LIBUNWIND_NO_HEAP
_LIBUNWIND_LOG_NON_ZERO(::pthread_rwlock_wrlock(&_lock));
if (_bufferUsed >= _bufferEnd) {
size_t oldSize = (size_t)(_bufferEnd - _buffer);
@@ -139,6 +140,7 @@
}
#endif
_LIBUNWIND_LOG_NON_ZERO(::pthread_rwlock_unlock(&_lock));
+#endif
}
template <typename A>
Index: src/DwarfParser.hpp
===================================================================
--- src/DwarfParser.hpp
+++ src/DwarfParser.hpp
@@ -380,7 +380,9 @@
uint64_t length;
uint8_t opcode = addressSpace.get8(p);
uint8_t operand;
+#ifndef _LIBUNWIND_NO_HEAP
PrologInfoStackEntry *entry;
+#endif
++p;
switch (opcode) {
case DW_CFA_nop:
@@ -492,6 +494,7 @@
fprintf(stderr, "DW_CFA_register(reg=%" PRIu64 ", reg2=%" PRIu64 ")\n",
reg, reg2);
break;
+#ifndef _LIBUNWIND_NO_HEAP
case DW_CFA_remember_state:
// avoid operator new, because that would be an upward dependency
entry = (PrologInfoStackEntry *)malloc(sizeof(PrologInfoStackEntry));
@@ -517,6 +520,7 @@
if (logDwarf)
fprintf(stderr, "DW_CFA_restore_state\n");
break;
+#endif
case DW_CFA_def_cfa:
reg = addressSpace.getULEB128(p, instructionsEnd);
offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11897.35211.patch
Type: text/x-patch
Size: 2326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150921/fa26f1a8/attachment.bin>
More information about the llvm-commits
mailing list