[PATCH] D130902: [llvm-objdump,ARM] Fix big-endian AArch32 disassembly.

Simon Tatham via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 1 07:31:24 PDT 2022


simon_tatham created this revision.
simon_tatham added reviewers: DavidSpickett, ostannard, MaskRay.
Herald added subscribers: StephenFan, rupprecht, hiraditya, kristof.beyls, emaste.
Herald added a reviewer: jhenderson.
Herald added a project: All.
simon_tatham requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The ABI for big-endian AArch32, as specified by AAELF32, is above-
averagely complicated. Relocatable object files are expected to store
instruction encodings in byte order matching the ELF file's endianness
(so, big-endian for a BE ELF file). But executable images can
//either// do that //or// store instructions little-endian regardless
of data and ELF endianness (to support BE32 and BE8 platforms
respectively). They signal the latter by setting the EF_ARM_BE8 flag
in the ELF header.

(In the case of the Thumb instruction set, this all means that each
16-bit halfword of a Thumb instruction is stored in one or other
endianness. The two halfwords of a 32-bit Thumb instruction must
appear in the same order no matter what, because the first halfword is
the one that must avoid overlapping the encoding of any 16-bit Thumb
instruction.)

llvm-objdump was unconditionally expecting Arm instructions to be
stored little-endian. So it would correctly disassemble a BE8 image,
but if you gave it a BE32 image or a BE object file, it would retrieve
every instruction in byte-swapped form and disassemble it to
nonsense. (Even an object file output by LLVM itself, because
ARMMCCodeEmitter outputs instructions big-endian in big-endian mode,
which is correct for writing an object file.)

This patch allows llvm-objdump to correctly disassemble all three of
those classes of Arm ELF file. It does it by introducing a new
SubtargetFeature for big-endian instructions, setting it from the ELF
image type and flags during llvm-objdump setup, and teaching both
ARMDisassembler and llvm-objdump itself to pay attention to it when
retrieving instruction data from a section being disassembled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130902

Files:
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/lib/ObjectYAML/ELFYAML.cpp
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
  llvm/test/tools/llvm-objdump/ELF/ARM/be-object-disasm.test
  llvm/test/tools/llvm-objdump/ELF/ARM/be32-image-disasm.test
  llvm/test/tools/llvm-objdump/ELF/ARM/be8-image-disasm.test
  llvm/tools/llvm-objdump/llvm-objdump.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130902.449015.patch
Type: text/x-patch
Size: 11705 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220801/d3fad6c7/attachment.bin>


More information about the llvm-commits mailing list