[binutils-gdb] alpha, bfd: Fixes for ALPHA_R_OP_STORE

Alan Modra amodra@sourceware.org
Mon May 26 09:11:16 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3e02c4891dcb37a0a12cff53232342f6d160b2c5

commit 3e02c4891dcb37a0a12cff53232342f6d160b2c5
Author: Janne Ramstedt <janne.ramstedt@aniway.fi>
Date:   Sun May 25 20:17:20 2025 +0300

    alpha, bfd: Fixes for ALPHA_R_OP_STORE
    
    ALPHA_R_OP_STORE copies one byte too many and also will cause out of
    range error when it tries to copy from the end of section.  Since
    "endbyte" is already rounded to next full byte, there is enough bits
    to copy and the additional "+ 1" is erroneous in bytes count.  I also
    believe size is incorrectly decreased.

Diff:
---
 bfd/coff-alpha.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/bfd/coff-alpha.c b/bfd/coff-alpha.c
index e2f1a4d2808..60d85bbf707 100644
--- a/bfd/coff-alpha.c
+++ b/bfd/coff-alpha.c
@@ -1007,7 +1007,7 @@ alpha_ecoff_get_relocated_section_contents (bfd *abfd,
 	    unsigned int size = rel->addend & 0xff;
 	    unsigned int startbyte = offset >> 3;
 	    unsigned int endbyte = (offset + size + 7) >> 3;
-	    unsigned int bytes = endbyte + 1 - startbyte;
+	    unsigned int bytes = endbyte - startbyte;
 
 	    if (bytes <= 8
 		&& rel->address + startbyte + bytes >= rel->address
@@ -1019,7 +1019,6 @@ alpha_ecoff_get_relocated_section_contents (bfd *abfd,
 		  val = (val << 8) | data[rel->address + startbyte + off];
 
 		offset -= startbyte << 3;
-		size -= startbyte << 3;
 		uint64_t mask = (((uint64_t) 1 << size) - 1) << offset;
 		val = (val & ~mask) | ((stack[--tos] << offset) & mask);
 
@@ -1781,7 +1780,7 @@ alpha_relocate_section (bfd *output_bfd,
 	    {
 	      unsigned int startbyte = r_offset >> 3;
 	      unsigned int endbyte = (r_offset + r_size + 7) >> 3;
-	      unsigned int bytes = endbyte + 1 - startbyte;
+	      unsigned int bytes = endbyte - startbyte;
 
 	      if (bytes <= 8
 		  && r_vaddr >= input_section->vma
@@ -1795,7 +1794,6 @@ alpha_relocate_section (bfd *output_bfd,
 		    val = (val << 8) | p[startbyte + off];
 
 		  r_offset -= startbyte << 3;
-		  r_size -= startbyte << 3;
 		  uint64_t mask = (((uint64_t) 1 << r_size) - 1) << r_offset;
 		  val = (val & ~mask) | ((stack[--tos] << r_offset) & mask);


More information about the Binutils-cvs mailing list