2014-06-04 17:47:15 +02:00
|
|
|
//===--- ARMWinEHPrinter.h - Windows on ARM Unwind Information Printer ----===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-06-04 17:47:15 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 18:26:38 +02:00
|
|
|
#ifndef LLVM_TOOLS_LLVM_READOBJ_ARMWINEHPRINTER_H
|
|
|
|
#define LLVM_TOOLS_LLVM_READOBJ_ARMWINEHPRINTER_H
|
2014-06-04 17:47:15 +02:00
|
|
|
|
2014-06-04 18:03:18 +02:00
|
|
|
#include "llvm/Object/COFF.h"
|
2014-06-04 17:47:15 +02:00
|
|
|
#include "llvm/Support/ErrorOr.h"
|
2016-05-03 02:28:04 +02:00
|
|
|
#include "llvm/Support/ScopedPrinter.h"
|
2014-06-04 17:47:15 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace ARM {
|
|
|
|
namespace WinEH {
|
|
|
|
class RuntimeFunction;
|
2020-09-04 22:42:22 +02:00
|
|
|
class RuntimeFunctionARM64;
|
2014-06-04 17:47:15 +02:00
|
|
|
|
|
|
|
class Decoder {
|
|
|
|
static const size_t PDataEntrySize;
|
|
|
|
|
2016-05-03 02:28:04 +02:00
|
|
|
ScopedPrinter &SW;
|
2014-06-04 17:47:15 +02:00
|
|
|
raw_ostream &OS;
|
2018-10-24 02:03:34 +02:00
|
|
|
bool isAArch64;
|
2014-06-04 17:47:15 +02:00
|
|
|
|
|
|
|
struct RingEntry {
|
|
|
|
uint8_t Mask;
|
|
|
|
uint8_t Value;
|
2018-10-24 02:03:34 +02:00
|
|
|
uint8_t Length;
|
2014-09-11 23:46:33 +02:00
|
|
|
bool (Decoder::*Routine)(const uint8_t *, unsigned &, unsigned, bool);
|
2014-06-04 17:47:15 +02:00
|
|
|
};
|
|
|
|
static const RingEntry Ring[];
|
2018-10-24 02:03:34 +02:00
|
|
|
static const RingEntry Ring64[];
|
2014-06-04 17:47:15 +02:00
|
|
|
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_0xxxxxxx(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_10Lxxxxx(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_1100xxxx(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11010Lxx(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11011Lxx(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11100xxx(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_111010xx(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_1110110L(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11101110(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11101111(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11110101(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11110110(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11110111(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11111000(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11111001(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11111010(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11111011(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11111100(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11111101(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11111110(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
2014-09-11 23:46:33 +02:00
|
|
|
bool opcode_11111111(const uint8_t *Opcodes, unsigned &Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
|
2018-10-24 02:03:34 +02:00
|
|
|
// ARM64 unwind codes start here.
|
|
|
|
bool opcode_alloc_s(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
|
|
|
|
bool Prologue);
|
|
|
|
bool opcode_save_r19r20_x(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_save_fplr(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_save_fplr_x(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_alloc_m(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
|
|
|
|
bool Prologue);
|
|
|
|
bool opcode_save_regp(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_save_regp_x(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_save_reg(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_save_reg_x(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_save_lrpair(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_save_fregp(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_save_fregp_x(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_save_freg(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_save_freg_x(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_alloc_l(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
|
|
|
|
bool Prologue);
|
|
|
|
bool opcode_setfp(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
|
|
|
|
bool Prologue);
|
|
|
|
bool opcode_addfp(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
|
|
|
|
bool Prologue);
|
|
|
|
bool opcode_nop(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
|
|
|
|
bool Prologue);
|
|
|
|
bool opcode_end(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
|
|
|
|
bool Prologue);
|
|
|
|
bool opcode_end_c(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
|
|
|
|
bool Prologue);
|
|
|
|
bool opcode_save_next(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
2020-08-15 23:26:24 +02:00
|
|
|
bool opcode_trap_frame(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_machine_frame(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
|
|
|
bool opcode_context(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
|
|
|
|
bool Prologue);
|
|
|
|
bool opcode_clear_unwound_to_call(const uint8_t *Opcodes, unsigned &Offset,
|
|
|
|
unsigned Length, bool Prologue);
|
2018-10-24 02:03:34 +02:00
|
|
|
|
2014-09-11 23:46:33 +02:00
|
|
|
void decodeOpcodes(ArrayRef<uint8_t> Opcodes, unsigned Offset,
|
2014-06-04 17:47:15 +02:00
|
|
|
bool Prologue);
|
|
|
|
|
|
|
|
void printRegisters(const std::pair<uint16_t, uint32_t> &RegisterMask);
|
|
|
|
|
|
|
|
ErrorOr<object::SectionRef>
|
|
|
|
getSectionContaining(const object::COFFObjectFile &COFF, uint64_t Address);
|
|
|
|
|
|
|
|
ErrorOr<object::SymbolRef>
|
|
|
|
getSymbol(const object::COFFObjectFile &COFF, uint64_t Address,
|
|
|
|
bool FunctionOnly = false);
|
|
|
|
|
|
|
|
ErrorOr<object::SymbolRef>
|
|
|
|
getRelocatedSymbol(const object::COFFObjectFile &COFF,
|
|
|
|
const object::SectionRef &Section, uint64_t Offset);
|
|
|
|
|
Reapply [llvm-readobj] [ARMWinEH] Fix handling of relocations and symbol offsets
When looking up data referenced from pdata/xdata structures, the
referenced data can be found in two different ways:
- For an unrelocated object file, it's located via a relocation
- For a relocated, linked image, the data is referenced with an
(image relative) absolute address
For the latter case, the absolute address can optionally be
described with a symbol.
For the case of an object file, there's two offsets involved; one
immediate offset encoded in the data location that is modified by
the relocation, and a section offset in the symbol.
Previously, for the ExceptionRecord field, we printed the offset
from the symbol (only) but used the immediate offset ignoring
the symbol's address (using only the symbol's section) for printing
the exception data.
Add a helper method for doing the lookup and address calculation,
for simplifying the calling code and making all the cases consistent.
This addresses an existing FIXME comment, fixing printing of the
exception data for cases where relocations point at individual
symbols in the xdata section (which is what MSVC generates) instead of
all relocations pointing at the start of the xdata section (which is
what LLVM generates).
This also fixes printing of the function name for packed entries in
linked images.
Relanded with a format string fix in the formatSymbol function; one
can't use %X as format string for an uint64_t. That bug has been
present since this code was added in e6971cab306cd.
Differential Revision: https://reviews.llvm.org/D100305
2021-04-12 11:49:17 +02:00
|
|
|
ErrorOr<object::SymbolRef>
|
|
|
|
getSymbolForLocation(const object::COFFObjectFile &COFF,
|
|
|
|
const object::SectionRef &Section,
|
|
|
|
uint64_t OffsetInSection, uint64_t ImmediateOffset,
|
|
|
|
uint64_t &SymbolAddress, uint64_t &SymbolOffset,
|
|
|
|
bool FunctionOnly = false);
|
|
|
|
|
2021-04-12 13:13:32 +02:00
|
|
|
object::SymbolRef getPreferredSymbol(const object::COFFObjectFile &COFF,
|
|
|
|
object::SymbolRef Sym);
|
|
|
|
|
2014-06-04 17:47:15 +02:00
|
|
|
bool dumpXDataRecord(const object::COFFObjectFile &COFF,
|
|
|
|
const object::SectionRef &Section,
|
|
|
|
uint64_t FunctionAddress, uint64_t VA);
|
|
|
|
bool dumpUnpackedEntry(const object::COFFObjectFile &COFF,
|
|
|
|
const object::SectionRef Section, uint64_t Offset,
|
|
|
|
unsigned Index, const RuntimeFunction &Entry);
|
|
|
|
bool dumpPackedEntry(const object::COFFObjectFile &COFF,
|
|
|
|
const object::SectionRef Section, uint64_t Offset,
|
|
|
|
unsigned Index, const RuntimeFunction &Entry);
|
2020-09-04 22:42:22 +02:00
|
|
|
bool dumpPackedARM64Entry(const object::COFFObjectFile &COFF,
|
|
|
|
const object::SectionRef Section, uint64_t Offset,
|
|
|
|
unsigned Index, const RuntimeFunctionARM64 &Entry);
|
2014-06-04 17:47:15 +02:00
|
|
|
bool dumpProcedureDataEntry(const object::COFFObjectFile &COFF,
|
|
|
|
const object::SectionRef Section, unsigned Entry,
|
|
|
|
ArrayRef<uint8_t> Contents);
|
|
|
|
void dumpProcedureData(const object::COFFObjectFile &COFF,
|
|
|
|
const object::SectionRef Section);
|
|
|
|
|
|
|
|
public:
|
2018-10-24 02:03:34 +02:00
|
|
|
Decoder(ScopedPrinter &SW, bool isAArch64) : SW(SW),
|
|
|
|
OS(SW.getOStream()),
|
|
|
|
isAArch64(isAArch64) {}
|
2019-05-02 12:32:03 +02:00
|
|
|
Error dumpProcedureData(const object::COFFObjectFile &COFF);
|
2014-06-04 17:47:15 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|