diff options
author | Peter Zotov <whitequark@whitequark.org> | 2015-11-09 06:57:29 +0000 |
---|---|---|
committer | Peter Zotov <whitequark@whitequark.org> | 2015-11-09 06:57:29 +0000 |
commit | 543f848fed3cf09c176e9ab94236adf8237628b8 (patch) | |
tree | 7a0371a4ebd3fc9970f0c0ba5b5788f89f4b7733 /src/DwarfParser.hpp | |
parent | 4831fd9b93e382cc57e900be287b7cdf40e8ac26 (diff) |
Make it possible to use libunwind without heap.
This patch allows to use libunwind on bare-metal systems that do not
include malloc/free by conditionally turning off nonessential
functionality that requires these functions.
The disabled functionality includes:
* the .cfi_remember_state and .cfi_restore_state instructions;
* the DWARF FDE cache.
The .cfi_{remember,restore}_state instructions don't seem to be used
by contemporary compilers. None of the LLVM backends emit it.
The DWARF FDE cache is bypassed if _LIBUNWIND_NO_HEAP is defined.
Specifically, entries are never added to it, so the search begins
and ends at the statically allocated, empty initial cache.
Such heap-less libunwind on a bare metal system is successfully used
in the ARTIQ project[1], and it is my hope that it will be useful
elsewhere.
[1]: http://m-labs.hk/artiq
Differential Revision: http://reviews.llvm.org/D11897
git-svn-id: https://llvm.org/svn/llvm-project/libunwind/trunk@252452 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'src/DwarfParser.hpp')
-rw-r--r-- | src/DwarfParser.hpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/DwarfParser.hpp b/src/DwarfParser.hpp index 26993c4..a19f051 100644 --- a/src/DwarfParser.hpp +++ b/src/DwarfParser.hpp @@ -380,7 +380,9 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions, uint64_t length; uint8_t opcode = addressSpace.get8(p); uint8_t operand; +#if !defined(_LIBUNWIND_NO_HEAP) PrologInfoStackEntry *entry; +#endif ++p; switch (opcode) { case DW_CFA_nop: @@ -492,6 +494,7 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions, fprintf(stderr, "DW_CFA_register(reg=%" PRIu64 ", reg2=%" PRIu64 ")\n", reg, reg2); break; +#if !defined(_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 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions, 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); |