This is an archive of the discontinued LLVM Phabricator instance.

[X86] Fix MCSymbolizer interface for X86Disassembler
ClosedPublic

Authored by maksfb on Mar 5 2022, 10:48 PM.

Details

Summary

Fix a number of issues with MCSymbolizer::tryAddingSymbolicOperand()
in X86Disassembler:

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

Diff Detail

Event Timeline

maksfb created this revision.Mar 5 2022, 10:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2022, 10:48 PM
maksfb requested review of this revision.Mar 5 2022, 10:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2022, 10:48 PM
Amir accepted this revision.Mar 5 2022, 11:27 PM
Amir added a subscriber: skan.

This is awesome!
LGTM but let's add @skan in the loop.

This revision is now accepted and ready to land.Mar 5 2022, 11:27 PM
skan added a reviewer: skan.Mar 6 2022, 5:50 PM
skan added inline comments.
llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
1992–1994

I am confused what you are fixing here. But it's not a clean fix at least, the comments of the function is not updated. Could you provide a LIT test?

llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
80–86

Why redefine the function here?

maksfb added inline comments.Mar 6 2022, 6:07 PM
llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
1992–1994

If you check MCDisassembler::tryAddingSymbolicOperand() and MCSymbolizer interface, both expect instruction length to be passed to the user, but X86Disassembler is passing the size of the immediate. There's no current user of this interface on X86, hence I've added the unit test. https://reviews.llvm.org/D120928 includes the usage and a LIT test. Good point about the comments for the local tryAddingSymbolicOperand().

llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
80–86

This is the user of the interface for the unit test. It overrides a pure virtual function.

maksfb updated this revision to Diff 413326.Mar 6 2022, 6:11 PM

Fix comments.

skan added inline comments.Mar 6 2022, 6:41 PM
llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
1992–1994

If what you say is true, I can not see any value of the static version tryAddingSymbolicOperand. Why not just remove it?

llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
91–92

I think this unittest in the wrong place. You test X86MCSymbolizerTest here, which is defined in this unittest. It's meaningless. This unnit test should be added in D120928 and tests the real X86MCSymbolizer.

maksfb added inline comments.Mar 6 2022, 6:51 PM
llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
1992–1994

It's likely there for historical reasons that I'm unaware of. I'm fine with removing it in a separate commit since it's not a part of the fix.

llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
91–92

This diff clearly fixes an existing interface and needs a test and the only test possible is the unit test.

The only question is if this interface fix should be committed separately from its usage in D120928. I'm fine either way, but I can see a theoretical benefit in the split of commits.

skan added inline comments.Mar 6 2022, 7:22 PM
llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
91–92

Question: which line of X86MCDisassemblerTest.cpp would fail w/o this patch?

maksfb added inline comments.Mar 6 2022, 7:57 PM
llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
91–92

Most of expects.

skan accepted this revision.Mar 6 2022, 8:15 PM

Thanks. LGTM

maksfb added a comment.Mar 6 2022, 8:26 PM

Cool. Thanks for the review.

This revision was landed with ongoing or failed builds.Mar 7 2022, 10:28 AM
This revision was automatically updated to reflect the committed changes.