This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Add new class for symbolizing X86 instructions
ClosedPublic

Authored by maksfb on Mar 3 2022, 11:29 AM.

Details

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 with 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).

Diff Detail

Event Timeline

maksfb created this revision.Mar 3 2022, 11:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 11:29 AM
maksfb requested review of this revision.Mar 3 2022, 11:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 11:29 AM
Amir added a comment.Mar 3 2022, 12:29 PM

Would be best to split out X86Disassembler.cpp changes if they're fixing some bugs and provide a test case for them separately.

maksfb added a comment.Mar 3 2022, 1:29 PM

Would be best to split out X86Disassembler.cpp changes if they're fixing some bugs and provide a test case for them separately.

As far as I can tell, the features are exposed only via virtual class/interface. BOLT has a concrete X86 implementation that is being tested with regression tests.

rafauler accepted this revision.Mar 7 2022, 4:56 PM

LGTM. Nice!

This revision is now accepted and ready to land.Mar 7 2022, 4:56 PM
maksfb updated this revision to Diff 433238.May 31 2022, 5:16 PM

Ignore implicit operands in X86MCSymbolizer::tryAddingSymbolicOperand().

This revision was automatically updated to reflect the committed changes.