public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Joseph Faulls <Joseph.Faulls@imgtec.com>
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: Re: [PATCH] RISC-V: Do not go beyond a label when disassembling data
Date: Wed, 12 Jun 2024 15:32:45 +0000	[thread overview]
Message-ID: <LO4P265MB5914EB734E362B39629F0B1280C02@LO4P265MB5914.GBRP265.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <LO4P265MB5914F23AC24D70E2BAB89F1680FF2@LO4P265MB5914.GBRP265.PROD.OUTLOOK.COM>

[-- 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

  reply	other threads:[~2024-06-12 15:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-03  9:42 Joseph Faulls
2024-06-12 15:32 ` Joseph Faulls [this message]
2024-06-18  3:56 ` Nelson Chu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=LO4P265MB5914EB734E362B39629F0B1280C02@LO4P265MB5914.GBRP265.PROD.OUTLOOK.COM \
    --to=joseph.faulls@imgtec.com \
    --cc=binutils@sourceware.org \
    --cc=nelson@rivosinc.com \
    --cc=palmer@rivosinc.com \
    --cc=patrick@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).