[PATCH] RISC-V: Do not go beyond a label when disassembling data
Joseph Faulls
Joseph.Faulls@imgtec.com
Wed Jun 12 15:32:45 GMT 2024
Ping
________________________________
From: Joseph Faulls
Sent: 03 June 2024 10:42 AM
To: binutils@sourceware.org <binutils@sourceware.org>
Cc: palmer@rivosinc.com <palmer@rivosinc.com>; nelson@rivosinc.com <nelson@rivosinc.com>; patrick@rivosinc.com <patrick@rivosinc.com>
Subject: [PATCH] RISC-V: Do not go beyond a label when disassembling data
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(-)
diff --git a/gas/testsuite/gas/riscv/mapping-dis.d b/gas/testsuite/gas/riscv/mapping-dis.d
index b1a26fbd151..5c908d52ec6 100644
--- a/gas/testsuite/gas/riscv/mapping-dis.d
+++ b/gas/testsuite/gas/riscv/mapping-dis.d
@@ -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>:
diff --git a/gas/testsuite/gas/riscv/mapping-symbols.d b/gas/testsuite/gas/riscv/mapping-symbols.d
index 6af825d8ad3..3cf8893ed0c 100644
--- a/gas/testsuite/gas/riscv/mapping-symbols.d
+++ b/gas/testsuite/gas/riscv/mapping-symbols.d
@@ -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
diff --git a/gas/testsuite/gas/riscv/mapping.s b/gas/testsuite/gas/riscv/mapping.s
index 3014a69e792..2e8f3166ef7 100644
--- a/gas/testsuite/gas/riscv/mapping.s
+++ b/gas/testsuite/gas/riscv/mapping.s
@@ -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
diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index e6596c47423..55d8baa5ce9 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -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)
--
2.34.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20240612/e437e893/attachment-0001.htm>
More information about the Binutils
mailing list