[PATCH v3 1/2] arm, objdump: Make objdump use bfd's machine detection to drive disassembly

Richard Earnshaw (lists) Richard.Earnshaw@arm.com
Tue Nov 5 17:08:26 GMT 2024


On 01/11/2024 10:26, Andre Vieira wrote:
> 
> For any elf target, disable an old piece of code that forced disassembly to
> disassemble for 'unknown architecture' which once upon a time meant it would
> disassemble ANY arm instruction.  This is no longer true with the addition of
> Armv8.1-M Mainline, as there are conflicting encodings for different thumb
> instructions.
> 
> BFD however can detect what architecture the object file was assembled for
> using information in the notes section.  So if available, we use that,
> otherwise we default to the old 'unknown' behaviour.
> 
> With the changes above code, a mode changing 'bx lr' assembled for armv4 with
> the option --fix-v4bx will result in an object file that is recognized by bfd
> as one for the armv4 architecture.  The disassembler now disassembles this
> encoding as a BX even for Armv4 architectures, but warns the user when
> disassembling for Armv4 that this instruction is only valid from Armv4T
> onwards.
> 
> Remove the unused and wrongfully defined ARM_ARCH_V8A_CRC, and
> define and use a ARM_ARCH_V8R_CRC to make sure instructions enabled by
> -march=armv8-r+crc are disassembled correctly.
> 
> Patch up some of the tests cases, see a brief explanation for each below.
> 
> inst.d:
> This test checks the assembly & disassembly of basic instructions in armv3m. I
> changed the expected behaviour for teqp, cmnp cmpp and testp instructions to
> properly print p when disassembling, whereas before, in the 'unknown' case it
> would disassemble these as UNPREDICTABLE as they were changed in later
> architectures.
> 
> nops.d:
> Was missing an -march, added one to make sure we were testing the right
> behavior of NOP<c> instructions.
> 
> unpredictable.d:
> Was missing an -march, added armv6 as that reproduced the behaviour being
> tested.
> ---
>  gas/testsuite/gas/arm/inst.d          | 32 +++++++++++++--------------
>  gas/testsuite/gas/arm/nops.d          |  1 +
>  gas/testsuite/gas/arm/unpredictable.d |  1 +
>  gas/testsuite/gas/arm/v4bx.d          |  2 +-
>  include/opcode/arm.h                  |  4 ++--
>  ld/testsuite/ld-arm/armv4-bx.d        |  4 ++--
>  opcodes/arm-dis.c                     | 22 ++++++++++++++----
>  7 files changed, 41 insertions(+), 25 deletions(-)
> 

-      if ((info->flags & USER_SPECIFIED_MACHINE_TYPE) == 0)
+      if (info->flavour != bfd_target_elf_flavour
+	  && (info->flags & USER_SPECIFIED_MACHINE_TYPE) == 0)

Perhaps you should mention in the comment below that elf objects have build attributes that carry the extra information we need.

Otherwise this is OK (though you might want to address HP's comment re your commit message).

R.



More information about the Binutils mailing list