This is an archive of the discontinued LLVM Phabricator instance.

[MCDisassembler] Disambiguate Size parameter in tryAddingSymbolicOperand()
ClosedPublic

Authored by maksfb on May 20 2022, 4:13 PM.

Details

Summary

MCSymbolizer::tryAddingSymbolicOperand() overloaded the Size parameter
to specify either the instruction size or the operand size depending on
the architecture. However, for proper symbolic disassembly on X86, we
need to know both sizes, as an instruction can have two operands and
the instruction size cannot be calculated based on an operand offset
and its size. Hence, split Size into OpSize and InstSize.

For X86, the new interface allows to fix a couple of issues:

  • Correctly adjust the value of PC-relative operands.
  • Set operand size to zero when the operand is specified implicitly.

Diff Detail

Event Timeline

maksfb created this revision.May 20 2022, 4:13 PM
Herald added a reviewer: MaskRay. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
maksfb requested review of this revision.May 20 2022, 4:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 20 2022, 4:13 PM

Original attempt to fix X86 issue was committed and reverted in https://reviews.llvm.org/D121065. This is a proper fix that changes the interface.

MaskRay added inline comments.May 21 2022, 10:30 AM
llvm/unittests/MC/X86/CMakeLists.txt
11

Add X86Info

otherwise -DBUILD_SHARED_LIBS=on build will have a link error.

llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
26

or use x86_64-unknown-elf

63

Place X86MCSymbolizerTest in an anonymous namespace, too.

95

Delete

122

Consider testing something more complex, like 291(%rax,%r14,8)

128

Additionally test InstSize

137

Suggest reordering the instructions from simple to complex.

However, for proper symbolic disassembly on X86 we need to know both sizes.

Add some description why it is the case. IIUC InstSize allows we to know the size of the only operand. If there are multiple operands, we don't know their sizes.

MaskRay added inline comments.May 21 2022, 10:33 AM
llvm/unittests/MC/X86/CMakeLists.txt
2

Delete

Fix MCSymbolizer::tryAddingSymbolicOperand() interface

Add OpSize parameter to MCSymbolizer::tryAddingSymbolicOperand. "Fix" isn't clear.

maksfb marked 8 inline comments as done.May 23 2022, 1:04 PM

Thank you for the review.

llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
128

InstSize is checked in checkBytes().

maksfb updated this revision to Diff 431460.May 23 2022, 1:04 PM
maksfb marked an inline comment as done.

Address feedback.

MaskRay accepted this revision.May 23 2022, 1:49 PM

Perhaps wait a day or so in case others have opinions.

llvm/lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp
78

The official syntax is /*InstSize=*/0

This revision is now accepted and ready to land.May 23 2022, 1:49 PM
maksfb updated this revision to Diff 431482.May 23 2022, 2:33 PM
maksfb marked an inline comment as done.

Fix in-line comments.

skan added inline comments.May 23 2022, 6:36 PM
llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp
512

Why is "0" used as argument here? Is it unused?

llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
54

Is this function unused?

maksfb marked an inline comment as done.May 23 2022, 7:12 PM
maksfb added inline comments.
llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp
512

Correct. Although for SPARC it's safe to use 4.

llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
54

Yes, thanks.

maksfb updated this revision to Diff 431556.May 23 2022, 7:12 PM
maksfb marked an inline comment as done.

Address comments.

skan accepted this revision.May 23 2022, 8:31 PM

LGTM for X86 part.

maksfb updated this revision to Diff 431801.May 24 2022, 2:42 PM
maksfb retitled this revision from [MCDisassembler] Fix MCSymbolizer::tryAddingSymbolicOperand() interface to [MCDisassembler] Disambiguate Size parameter in tryAddingSymbolicOperand().
maksfb edited the summary of this revision. (Show Details)

Rebase.