Summary: While disassembling instructions, we need to replace certain immediate operands with symbols. This symbolizing process relies on reading relocations against instructions. However, some X86 instructions can have multiple immediate operands and up to two relocations against them. Thus, correctly matching a relocation to an operand is not always possible without knowing the operand offset within the instruction. Luckily, LLVM provides an interface for passing the required info from the disassembler via a virtual MCSymbolizer class. Creating a target-specific version allows a precise matching of relocations to operands. This diff adds X86MCSymbolizer class that performs X86-specific symbolizing (currently limited to non-branch instructions). Reviewers: yota9, Amir, ayermolo, rafauler, zr33 Differential Revision: https://reviews.llvm.org/D120928
44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
//===- bolt/Target/X86/X86MCSymbolizer.h ------------------------*- C++ -*-===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef BOLT_CORE_X86MCSYMBOLIZER_H
|
|
#define BOLT_CORE_X86MCSYMBOLIZER_H
|
|
|
|
#include "bolt/Core/BinaryFunction.h"
|
|
#include "llvm/MC/MCDisassembler/MCSymbolizer.h"
|
|
|
|
namespace llvm {
|
|
namespace bolt {
|
|
|
|
class X86MCSymbolizer : public MCSymbolizer {
|
|
protected:
|
|
BinaryFunction &Function;
|
|
|
|
public:
|
|
X86MCSymbolizer(BinaryFunction &Function)
|
|
: MCSymbolizer(*Function.getBinaryContext().Ctx.get(), nullptr),
|
|
Function(Function) {}
|
|
|
|
X86MCSymbolizer(const X86MCSymbolizer &) = delete;
|
|
X86MCSymbolizer &operator=(const X86MCSymbolizer &) = delete;
|
|
virtual ~X86MCSymbolizer();
|
|
|
|
bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &CStream,
|
|
int64_t Value, uint64_t Address, bool IsBranch,
|
|
uint64_t Offset, uint64_t OpSize,
|
|
uint64_t InstSize) override;
|
|
|
|
void tryAddingPcLoadReferenceComment(raw_ostream &CStream, int64_t Value,
|
|
uint64_t Address) override;
|
|
};
|
|
|
|
} // namespace bolt
|
|
} // namespace llvm
|
|
|
|
#endif
|