public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Do not go beyond a label when disassembling data
@ 2024-06-03  9:42 Joseph Faulls
  2024-06-12 15:32 ` Joseph Faulls
  2024-06-18  3:56 ` Nelson Chu
  0 siblings, 2 replies; 3+ messages in thread
From: Joseph Faulls @ 2024-06-03  9:42 UTC (permalink / raw)
  To: binutils; +Cc: palmer, nelson, patrick

[-- Attachment #1: Type: text/plain, Size: 3497 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: Do not go beyond a label when disassembling data
  2024-06-03  9:42 [PATCH] RISC-V: Do not go beyond a label when disassembling data Joseph Faulls
@ 2024-06-12 15:32 ` Joseph Faulls
  2024-06-18  3:56 ` Nelson Chu
  1 sibling, 0 replies; 3+ messages in thread
From: Joseph Faulls @ 2024-06-12 15:32 UTC (permalink / raw)
  To: binutils; +Cc: palmer, nelson, patrick

[-- Attachment #1: Type: text/plain, Size: 3854 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: Do not go beyond a label when disassembling data
  2024-06-03  9:42 [PATCH] RISC-V: Do not go beyond a label when disassembling data Joseph Faulls
  2024-06-12 15:32 ` Joseph Faulls
@ 2024-06-18  3:56 ` Nelson Chu
  1 sibling, 0 replies; 3+ messages in thread
From: Nelson Chu @ 2024-06-18  3:56 UTC (permalink / raw)
  To: Joseph Faulls; +Cc: binutils, palmer, patrick

[-- Attachment #1: Type: text/plain, Size: 456 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-18  3:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-03  9:42 [PATCH] RISC-V: Do not go beyond a label when disassembling data Joseph Faulls
2024-06-12 15:32 ` Joseph Faulls
2024-06-18  3:56 ` Nelson Chu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).