[BOLT] Add new class for symbolizing X86 instructions
authorMaksim Panchenko <maks@fb.com>
Wed, 23 Feb 2022 03:06:25 +0000 (19:06 -0800)
committerMaksim Panchenko <maks@fb.com>
Wed, 1 Jun 2022 00:48:19 +0000 (17:48 -0700)
commite290133c76edb35483cf3280ef59c207af4e29f4
treea3cdba7548598050f7c7a8472a172e3c80a91e6f
parent79e3d57f52284c7d911724ef6298f765c747c20d
[BOLT] Add new class for symbolizing X86 instructions

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
bolt/include/bolt/Core/BinaryContext.h
bolt/include/bolt/Core/BinaryFunction.h
bolt/include/bolt/Core/MCPlusBuilder.h
bolt/lib/Core/BinaryContext.cpp
bolt/lib/Core/BinaryFunction.cpp
bolt/lib/Core/CMakeLists.txt
bolt/lib/Target/X86/CMakeLists.txt
bolt/lib/Target/X86/X86MCPlusBuilder.cpp
bolt/lib/Target/X86/X86MCSymbolizer.cpp [new file with mode: 0644]
bolt/lib/Target/X86/X86MCSymbolizer.h [new file with mode: 0644]
bolt/test/X86/double-rel.s [new file with mode: 0644]