RISC-V: Do not go beyond a label when disassembling data
Checks
Commit Message
Calculating data length to disassemble defaults to 4, but stop_vma is
set to the next symbol so that the disassembler will not read beyond it.
This causes an "Address out of bounds" error if the next symbol is less
than 4 bytes away from the data to be disassembled.
opcodes/ChangeLog:
* riscv-dis.c (riscv_data_length): Do not go beyond stop_vma.
gas/ChangeLog:
* testsuite/gas/riscv/mapping-dis.d: Updated and added new testcase.
* testsuite/gas/riscv/mapping-symbols.d: Likewise.
* testsuite/gas/riscv/mapping.s: Added new testcase.
---
gas/testsuite/gas/riscv/mapping-dis.d | 9 +++++++++
gas/testsuite/gas/riscv/mapping-symbols.d | 4 ++++
gas/testsuite/gas/riscv/mapping.s | 6 ++++++
opcodes/riscv-dis.c | 4 +++-
4 files changed, 22 insertions(+), 1 deletion(-)
--
2.34.1
Comments
On Mon, Jun 3, 2024 at 5:42 PM Joseph Faulls <Joseph.Faulls@imgtec.com>
wrote:
> +.section .text.data.label
> +addi a0, zero, 1
> +.short 3 # $d, dumped as .short due to label
> +label:
> +.word 4
>
I expect the data should dump as .word before .short when porting the
mapping symbol from arm/aarch64 to risc-v. Not sure if we should dump
data, which is placed in text, while considering labels.
Thanks
Nelson
@@ -26,6 +26,15 @@ Disassembly of section .text.data:
[ ]+[0-9a-f]+:[ ]+4509[ ]+li[ ]+a0,2
[ ]+[0-9a-f]+:[ ]+05000302[ ]+.word[ ]+0x05000302
+Disassembly of section .text.data.label:
+
+0+000 <label-0x4>:
+[ ]+[0-9a-f]+:[ ]+4505[ ]+li[ ]+a0,1
+[ ]+[0-9a-f]+:[ ]+0003[ ]+.short[ ]+0x0003
+
+0+004 <label>:
+[ ]+[0-9a-f]+:[ ]+00000004[ ]+.word[ ]+0x00000004
+
Disassembly of section .text.odd.align.start.insn:
0+000 <.text.odd.align.start.insn>:
@@ -17,6 +17,10 @@ SYMBOL TABLE:
0+00 l .text.data 0+00 \$d
0+08 l .text.data 0+00 \$xrv32i2p1_c2p0
0+0c l .text.data 0+00 \$d
+0+00 l d .text.data.label 0+00 .text.data.label
+0+00 l .text.data.label 0+00 \$xrv32i2p1_c2p0
+0+02 l .text.data.label 0+00 \$d
+0+04 l .text.data.label 0+00 label
0+00 l d .text.odd.align.start.insn 0+00 .text.odd.align.start.insn
0+00 l .text.odd.align.start.insn 0+00 \$xrv32i2p1_c2p0
0+02 l .text.odd.align.start.insn 0+00 \$d
@@ -32,6 +32,12 @@ addi a0, zero, 2 # $x, but same as previous addi, so removed
.byte 5
.option pop
+.section .text.data.label
+addi a0, zero, 1
+.short 3 # $d, dumped as .short due to label
+label:
+.word 4
+
.section .text.odd.align.start.insn, "ax"
.option push
.option norelax
@@ -1169,7 +1169,9 @@ riscv_data_length (bfd_vma memaddr,
bfd_vma length;
bool found = false;
- length = 4;
+ length = info->stop_vma - memaddr;
+ if (length > 4)
+ length = 4;
if (info->symtab_size != 0
&& bfd_asymbol_flavour (*info->symtab) == bfd_target_elf_flavour
&& last_map_symbol >= 0)