This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Remove asserts from the disassembler.
ClosedPublic

Authored by stefanp on May 2 2023, 6:15 PM.

Details

Reviewers
lei
nemanjai
amyk
Group Reviewers
Restricted Project
Commits
rG11fbd0c6abc9: [PowerPC] Remove asserts from the disassembler.
Summary

My previous patch had added a couple of asserts to the disassembler.
The problem with this is that the disassembler is not just used for the
text section it is also used to disassemble the data section of an
object where the bytes do not necessarily represent instructions. If the
data in the data section happens to look like an illegal instruction
then llvm-objdump will assert on data because it is finding an illegal
instruction that is not actually an instruction at all.

Diff Detail

Event Timeline

stefanp created this revision.May 2 2023, 6:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2023, 6:15 PM
stefanp requested review of this revision.May 2 2023, 6:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2023, 6:15 PM
stefanp added a reviewer: Restricted Project.May 2 2023, 6:15 PM
shchenz added inline comments.May 10 2023, 7:58 PM
llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp
121

Little confused. From the function name and its parameter seems like this function should only be called for instructions. Is it possible that there is a wrong call to this function? For example, for data, we should not decode fpr RC as there is no RC for data at all?

amyk added a comment.May 18 2023, 7:32 AM

Could we also update the description of the patch to specify what My previous patch means (as in, which patch)?

llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-dfp.txt
27 ↗(On Diff #518928)

Might be a silly question, but I have a clarification question.
Is the goal here, we want the disassembler to still continue decoding an instruction (even if it is invalid/illegal), but cannot have it assert? Does anything special need to happen after we have decoded an illegal instruction?

barannikov88 added inline comments.May 18 2023, 7:49 AM
llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp
118

The removed assertion should have been changed to if (...) return DecodeStatus::Fail; so that random data is not decoded into invalid instructions.
The added test should be a negative one.

Please note that this assert can trip even when disassembling with --disassemble and not just -disassemble-all. Namely, the offending word can appear in the text section (for example, the AIX traceback table, etc.).
This is very similar to https://reviews.llvm.org/rGc86f8d4276ae

llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp
118–119

Lets not just remove these. Please change it to something like:

if (RegNo > 30 || (RegNo & 1))
  return MCDisassembler::Fail;
nemanjai added inline comments.May 18 2023, 8:00 AM
llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp
86

While we're at it, we can turn this one into a disassembly failure rather than an assert.

351

While we're at it, we can turn this one into a disassembly failure rather than an assert.

stefanp updated this revision to Diff 523887.May 19 2023, 12:07 PM

Added the conditions so that we return DecodeStatus::Fail instead of asserting.

llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp
121

It is not an incorrect call to the function. The disassembler will call this whenever it tries to disassemble anything that looks like it might be an instruction. As other people in the comments mentioned I need to stop the assert and instead just return a failure to disassemble.

llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-dfp.txt
27 ↗(On Diff #518928)

No, we don't want to decode an incorrect instruction. The initial issue was that we would decode an instruction that was part of the data section or (as Nemanja pointed out) part of the AIX traceback table and those bytes just happened to look like an instruction but an invalid instruction. When I had the asserts in there the disassembler would assert and we don't want that.

nemanjai added inline comments.May 19 2023, 5:39 PM
llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp
351

Did you just miss this one or is there a reason you didn't address this comment?

stefanp updated this revision to Diff 524728.May 23 2023, 8:05 AM

Updated one assert that I missed.

stefanp added inline comments.May 23 2023, 8:06 AM
llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp
351

Sorry, I did miss this one.

nemanjai accepted this revision.May 23 2023, 2:07 PM

LGTM. Thanks for fixing these.

This revision is now accepted and ready to land.May 23 2023, 2:07 PM
stefanp updated this revision to Diff 525246.May 24 2023, 10:22 AM

Rebased to top of main.

This revision was landed with ongoing or failed builds.May 24 2023, 10:22 AM
This revision was automatically updated to reflect the committed changes.