]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Further rs_code_align support refinement
authorAlan Modra <amodra@gmail.com>
Sun, 25 May 2025 02:16:05 +0000 (11:46 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 28 May 2025 11:40:48 +0000 (21:10 +0930)
Don't write the repeating nop pattern if it won't be used.

gas/config/tc-aarch64.c
gas/config/tc-arm.c
gas/config/tc-epiphany.c
gas/config/tc-i386.c
gas/config/tc-metag.c
gas/config/tc-nds32.c
gas/config/tc-ppc.c

index 9005fc77eb1bb21804609c740e9e09a0a618498b..5d35a900326668017551975f0e54ac098312130c 100644 (file)
@@ -9058,11 +9058,15 @@ aarch64_handle_align (fragS * fragP)
 #endif
       memset (p, 0, fix);
       p += fix;
+      bytes -= fix;
       fragP->fr_fix += fix;
     }
 
-  memcpy (p, aarch64_noop, noop_size);
-  fragP->fr_var = noop_size;
+  if (bytes != 0)
+    {
+      fragP->fr_var = noop_size;
+      memcpy (p, aarch64_noop, noop_size);
+    }
 }
 
 /* Perform target specific initialisation of a frag.
index ad4eef4bc04e2ed5ef385a40c3bc157428b57f00..44020e3140b6acf55ad6bf265079a4a0e7416c78 100644 (file)
@@ -26602,7 +26602,6 @@ arm_handle_align (fragS * fragP)
 
   bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
   p = fragP->fr_literal + fragP->fr_fix;
-  fix = 0;
 
   gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
 
@@ -26633,9 +26632,9 @@ arm_handle_align (fragS * fragP)
 #endif
     }
 
-  if (bytes & (noop_size - 1))
+  fix = bytes & (noop_size - 1);
+  if (fix != 0)
     {
-      fix = bytes & (noop_size - 1);
 #ifdef OBJ_ELF
       insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
 #endif
@@ -26660,8 +26659,11 @@ arm_handle_align (fragS * fragP)
     }
 
   fragP->fr_fix += fix;
-  fragP->fr_var = noop_size;
-  memcpy (p, noop, noop_size);
+  if (bytes != 0)
+    {
+      fragP->fr_var = noop_size;
+      memcpy (p, noop, noop_size);
+    }
 }
 
 /* Perform target specific initialisation of a frag.
index be3235ae70a702da9afe4749751d073affaec039..4a027e9f31d2d8c0959ce5146222b7194d617c45 100644 (file)
@@ -326,11 +326,15 @@ epiphany_handle_align (fragS *fragp)
   if (bytes & 1)
     {
       *p++ = 0;
+      bytes--;
       fragp->fr_fix++;
     }
 
-  memcpy (p, nop_pattern, 2);
-  fragp->fr_var = 2;
+  if (bytes != 0)
+    {
+      fragp->fr_var = 2;
+      memcpy (p, nop_pattern, 2);
+    }
 }
 \f
 /* Read a comma separated incrementing list of register names
index 73d552edb1391fcb8de6c3f5c43942f7fdfdf99e..723f02159d48fc7c0a519369f29da3b113102704 100644 (file)
@@ -1775,9 +1775,11 @@ i386_generate_nops (fragS *fragP, char *where, offsetT count, int limit)
         included in fr_fix.  The repeating larger nop only needs to
         be written once to the frag memory.  */
       fragP->fr_fix = where - fragP->fr_literal;
-      fragP->fr_var = limit;
       if (count != 0)
-       count = limit;
+       {
+         fragP->fr_var = limit;
+         count = limit;
+       }
     }
 
   const unsigned char *nops = patt[limit - 1];
index 195e6a4040fc8b3695ec7eb27a208f96a98b7f54..09ee5c3acea3ffbc98b9a4de657783fbf64af8b7 100644 (file)
@@ -6853,11 +6853,15 @@ metag_handle_align (fragS * fragP)
     {
       memset (p, 0, fix);
       p += fix;
+      bytes -= fix;
       fragP->fr_fix += fix;
     }
 
-  memcpy (p, noop, 4);
-  fragP->fr_var = 4;
+  if (bytes != 0)
+    {
+      fragP->fr_var = 4;
+      memcpy (p, noop, 4);
+    }
 }
 
 static char *
index 26172e54b3a5e0147f4e8209d395d8550baa617d..3c16216f531c153ffd0f351b1ba4862a916639b2 100644 (file)
@@ -4657,12 +4657,16 @@ nds32_handle_align (fragS *fragp)
                   BFD_RELOC_NDS32_INSN16);
       memcpy (p, nop16, 2);
       p += 2;
+      bytes -= 2;
       fix += 2;
     }
   fragp->fr_fix += fix;
 
-  fragp->fr_var = 4;
-  memcpy (p, nop32, 4);
+  if (bytes != 0)
+    {
+      fragp->fr_var = 4;
+      memcpy (p, nop32, 4);
+    }
 }
 
 /* md_flush_pending_output  */
index eef82d70169fc8c1bfacc5dc7a096e05c896d25b..b59a2f59a1d39ecc77c7281728a8d294da40c238 100644 (file)
@@ -6887,6 +6887,9 @@ ppc_handle_align (segT sec, struct frag *fragP)
 {
   valueT count = (fragP->fr_next->fr_address
                  - (fragP->fr_address + fragP->fr_fix));
+  if (count == 0)
+    return;
+
   char *dest = fragP->fr_literal + fragP->fr_fix;
   enum ppc_nop_encoding_for_rs_align_code nop_select = *dest & 0xff;
 
@@ -6894,8 +6897,7 @@ ppc_handle_align (segT sec, struct frag *fragP)
      We could pad with zeros up to an instruction boundary then follow
      with nops but odd counts indicate data in an executable section
      so padding with zeros is most appropriate.  */
-  if (count == 0
-      || (nop_select == PPC_NOP_VLE ? (count & 1) != 0 : (count & 3) != 0))
+  if (nop_select == PPC_NOP_VLE ? (count & 1) != 0 : (count & 3) != 0)
     {
       *dest = 0;
       return;