]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
alpha, bfd: Fixes for ALPHA_R_OP_STORE
authorJanne Ramstedt <janne.ramstedt@aniway.fi>
Sun, 25 May 2025 17:17:20 +0000 (20:17 +0300)
committerAlan Modra <amodra@gmail.com>
Mon, 26 May 2025 09:01:35 +0000 (18:31 +0930)
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.

bfd/coff-alpha.c

index e2f1a4d28080383f4f29396ed2d9d1d30f9a9dad..60d85bbf7078e922ff80a5e0355aaca5508c8250 100644 (file)
@@ -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);