From 5f49bdc4f55e93c53b56be01d2e18afe0efa0b19 Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Wed, 3 Aug 2022 13:55:28 +0900 Subject: [PATCH] RISC-V: Print using .dword on RV64 `riscv_disassemble_data' has an ability to print 8-byte data with .dword but this is not utilized. This is possibly because, XLEN was not set before disassembling an instruction. Since prerequisite commits now set XLEN in `riscv_get_disassembler', it's now safe to use .dword on RV64. gas/ChangeLog: * testsuite/gas/riscv/mapping-04b.d: Change to use RV64I. Check that .dword is actually used. * testsuite/gas/riscv/mapping-norelax-04b.d: Likewise. * testsuite/gas/riscv/mapping-04b-32.d: New test, the same as mapping-04b except it uses RV32I and .dword should not be used. opcodes/ChangeLog: * riscv-dis.c (riscv_data_length): Print using .dword on RV64. --- gas/testsuite/gas/riscv/mapping-04b-32.d | 23 +++++++++++++++++++ gas/testsuite/gas/riscv/mapping-04b.d | 8 +++---- gas/testsuite/gas/riscv/mapping-norelax-04b.d | 8 +++---- opcodes/riscv-dis.c | 11 +++++++-- 4 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 gas/testsuite/gas/riscv/mapping-04b-32.d diff --git a/gas/testsuite/gas/riscv/mapping-04b-32.d b/gas/testsuite/gas/riscv/mapping-04b-32.d new file mode 100644 index 00000000000..103665cbdc1 --- /dev/null +++ b/gas/testsuite/gas/riscv/mapping-04b-32.d @@ -0,0 +1,23 @@ +#as: -march=rv32i +#source: mapping-04.s +#objdump: -d + +.*:[ ]+file format .* + + +Disassembly of section .text: + +0+000 <.text>: +[ ]+0:[ ]+00001001[ ]+.word[ ]+0x00001001 +[ ]+4:[ ]+00001001[ ]+.word[ ]+0x00001001 +[ ]+8:[ ]+00000001[ ]+.word[ ]+0x00000001 +[ ]+c:[ ]+00[ ]+.byte[ ]+0x00 +[ ]+d:[ ]+00000013[ ]+nop +[ ]+11:[ ]+00a50533[ ]+add[ ]+a0,a0,a0 +[ ]+15:[ ]+20022002[ ]+.word[ ]+0x20022002 +[ ]+19:[ ]+20022002[ ]+.word[ ]+0x20022002 +[ ]+1d:[ ]+2002[ ]+.short[ ]+0x2002 +[ ]+1f:[ ]+00b585b3[ ]+add[ ]+a1,a1,a1 +[ ]+23:[ ]+0000[ ]+.2byte[ ]+0x0 +[ ]+25:[ ]+0000[ ]+.2byte[ ]+0x0 +#... diff --git a/gas/testsuite/gas/riscv/mapping-04b.d b/gas/testsuite/gas/riscv/mapping-04b.d index 54bd0afb6c4..12ec7a112dc 100644 --- a/gas/testsuite/gas/riscv/mapping-04b.d +++ b/gas/testsuite/gas/riscv/mapping-04b.d @@ -1,4 +1,4 @@ -#as: +#as: -march=rv64i #source: mapping-04.s #objdump: -d @@ -8,14 +8,12 @@ Disassembly of section .text: 0+000 <.text>: -[ ]+0:[ ]+00001001[ ]+.word[ ]+0x00001001 -[ ]+4:[ ]+00001001[ ]+.word[ ]+0x00001001 +[ ]+0:[ ]+0000100100001001[ ]+.dword[ ]+0x0000100100001001 [ ]+8:[ ]+00000001[ ]+.word[ ]+0x00000001 [ ]+c:[ ]+00[ ]+.byte[ ]+0x00 [ ]+d:[ ]+00000013[ ]+nop [ ]+11:[ ]+00a50533[ ]+add[ ]+a0,a0,a0 -[ ]+15:[ ]+20022002[ ]+.word[ ]+0x20022002 -[ ]+19:[ ]+20022002[ ]+.word[ ]+0x20022002 +[ ]+15:[ ]+2002200220022002[ ]+.dword[ ]+0x2002200220022002 [ ]+1d:[ ]+2002[ ]+.short[ ]+0x2002 [ ]+1f:[ ]+00b585b3[ ]+add[ ]+a1,a1,a1 [ ]+23:[ ]+0000[ ]+.2byte[ ]+0x0 diff --git a/gas/testsuite/gas/riscv/mapping-norelax-04b.d b/gas/testsuite/gas/riscv/mapping-norelax-04b.d index be668f29220..660a1f43660 100644 --- a/gas/testsuite/gas/riscv/mapping-norelax-04b.d +++ b/gas/testsuite/gas/riscv/mapping-norelax-04b.d @@ -1,4 +1,4 @@ -#as: -mno-relax +#as: -march=rv64i -mno-relax #source: mapping-04.s #objdump: -d @@ -8,15 +8,13 @@ Disassembly of section .text: 0+000 <.text>: -[ ]+0:[ ]+00001001[ ]+.word[ ]+0x00001001 -[ ]+4:[ ]+00001001[ ]+.word[ ]+0x00001001 +[ ]+0:[ ]+0000100100001001[ ]+.dword[ ]+0x0000100100001001 [ ]+8:[ ]+00000001[ ]+.word[ ]+0x00000001 [ ]+c:[ ]+00[ ]+.byte[ ]+0x00 [ ]+d:[ ]+00[ ]+.byte[ ]+0x00 [ ]+e:[ ]+0001[ ]+.2byte[ ]+0x1 [ ]+10:[ ]+00a50533[ ]+add[ ]+a0,a0,a0 -[ ]+14:[ ]+20022002[ ]+.word[ ]+0x20022002 -[ ]+18:[ ]+20022002[ ]+.word[ ]+0x20022002 +[ ]+14:[ ]+2002200220022002[ ]+.dword[ ]+0x2002200220022002 [ ]+1c:[ ]+2002[ ]+.short[ ]+0x2002 [ ]+1e:[ ]+00b585b3[ ]+add[ ]+a1,a1,a1 [ ]+22:[ ]+0001[ ]+.2byte[ ]+0x1 diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index bda48eac847..217363a8e27 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -1000,7 +1000,7 @@ riscv_data_length (bfd_vma memaddr, bfd_vma length; bool found = false; - length = 4; + length = xlen > 32 ? 8 : 4; if (info->symtab_size != 0 && bfd_asymbol_flavour (*info->symtab) == bfd_target_elf_flavour && last_map_symbol >= 0) @@ -1027,7 +1027,14 @@ riscv_data_length (bfd_vma memaddr, offset -= memaddr; length = (offset < length) ? offset : length; } - length = length == 3 ? 2 : length; + static const bfd_vma aligned_length[] = { + /* [0..0] */ 0, + /* [1..1] */ 1, + /* [2..3] */ 2, 2, + /* [4..7] */ 4, 4, 4, 4, + /* [8..8] */ 8, + }; + length = aligned_length[length]; return length; }