]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas v850 md_convert_frag
authorAlan Modra <amodra@gmail.com>
Thu, 10 Jul 2025 01:45:16 +0000 (11:15 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 10 Jul 2025 22:53:40 +0000 (08:23 +0930)
The v850 md_convert_frag function oddly calls subseg_change twice
(commit 1cd986c58543).  Neither call is needed, because that is done
in size_seg.

Convert the fr_opcode fixup field back (to an opindex, not fx_r_type)
using a cast rather than a union, since we used casts when setting up
those values.  I guess the union was added to silence compiler
warnings about wrong-size casts, but unfortunately results in the
wrong value being retrieved on big-endian hosts.

Change "buffer" to a char* as there is no need to make it an
unsigned char*, and that way requires fewer casts.  Finally, fix
formatting and use uintptr_t when make the rs_machine_dependent frags.

Remove subseg_change calls from cr16, crx, mn10200, mn10300, and sh
md_convert_frag too.

gas/config/tc-cr16.c
gas/config/tc-crx.c
gas/config/tc-mn10200.c
gas/config/tc-mn10300.c
gas/config/tc-sh.c
gas/config/tc-v850.c

index 5bf088d573608a1561a1aa2976a8a2e38d2a0d2b..99bc1bdd506e1f0d2a86dc38b06946a4f320346e 100644 (file)
@@ -636,15 +636,15 @@ md_estimate_size_before_relax (fragS *fragp, asection *seg)
 }
 
 void
-md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, fragS *fragP)
+md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
+                asection *sec ATTRIBUTE_UNUSED,
+                fragS *fragP)
 {
   /* 'opcode' points to the start of the instruction, whether
      we need to change the instruction's fixed encoding.  */
   char *opcode = &fragP->fr_literal[0] + fragP->fr_fix;
   bfd_reloc_code_real_type reloc;
 
-  subseg_change (sec, 0);
-
   switch (fragP->fr_subtype)
     {
     case 0:
index d5eb9db5ab808086deffc1a4df0e88d037873829..e51921441b02c3862571a370f383c23045024097 100644 (file)
@@ -368,15 +368,15 @@ md_estimate_size_before_relax (fragS *fragp, asection *seg)
 }
 
 void
-md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, fragS *fragP)
+md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
+                asection *sec ATTRIBUTE_UNUSED,
+                fragS *fragP)
 {
   /* 'opcode' points to the start of the instruction, whether
      we need to change the instruction's fixed encoding.  */
   char *opcode = &fragP->fr_literal[0] + fragP->fr_fix;
   bfd_reloc_code_real_type reloc;
 
-  subseg_change (sec, 0);
-
   switch (fragP->fr_subtype)
     {
     case 0:
index 210e9b016fc6d44781baf9048984ad6ab22ef571..1eb470295a4430cd58426e61ab4182bcc4bd4a94 100644 (file)
@@ -328,7 +328,6 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
   static unsigned long label_count = 0;
   char buf[40];
 
-  subseg_change (sec, 0);
   if (fragP->fr_subtype == 0)
     {
       fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
index a1d89f09f165b21d9af71b051317a199d4e75b29..db87d523f46c3058f4901bb874bd16dc15bdbb70 100644 (file)
@@ -466,7 +466,6 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
   static unsigned long label_count = 0;
   char buf[40];
 
-  subseg_change (sec, 0);
   if (fragP->fr_subtype == 0)
     {
       fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
index 56535830b87f427f0e8b1ecd01915c30ed93c88e..551d8e8b24d8211b384aaba0ff1f5a0a4eb4835a 100644 (file)
@@ -3018,7 +3018,6 @@ md_convert_frag (bfd *headers ATTRIBUTE_UNUSED, segT seg, fragS *fragP)
     {
     case C (COND_JUMP, COND8):
     case C (COND_JUMP_DELAY, COND8):
-      subseg_change (seg, 0);
       fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
               1, BFD_RELOC_SH_PCDISP8BY2);
       fragP->fr_fix += 2;
@@ -3026,7 +3025,6 @@ md_convert_frag (bfd *headers ATTRIBUTE_UNUSED, segT seg, fragS *fragP)
       break;
 
     case C (UNCOND_JUMP, UNCOND12):
-      subseg_change (seg, 0);
       fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
               1, BFD_RELOC_SH_PCDISP12BY2);
       fragP->fr_fix += 2;
@@ -3082,7 +3080,6 @@ md_convert_frag (bfd *headers ATTRIBUTE_UNUSED, segT seg, fragS *fragP)
           its delay-slot insn already makes the branch reach.  */
 
        /* Build a relocation to six / four bytes farther on.  */
-       subseg_change (seg, 0);
        fix_new (fragP, fragP->fr_fix, 2, section_symbol (seg),
                 fragP->fr_address + fragP->fr_fix + (delay ? 4 : 6),
                 1, BFD_RELOC_SH_PCDISP8BY2);
index 8a86b1d2b8973272245af66bec64f2317f67aa63..f73c3bfbab33de548f26201d2ef0a346091b67cd 100644 (file)
@@ -1673,42 +1673,29 @@ md_atof (int type, char *litp, int *sizep)
 
 void
 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
-                asection *sec,
+                asection *sec ATTRIBUTE_UNUSED,
                 fragS *fragP)
 {
-  union u
-  {
-    bfd_reloc_code_real_type fx_r_type;
-    char * fr_opcode;
-  }
-  opcode_converter;
-  subseg_change (sec, 0);
-
-  opcode_converter.fr_opcode = fragP->fr_opcode;
-
-  subseg_change (sec, 0);
+  unsigned int opindex = (uintptr_t) fragP->fr_opcode;
 
   if (fragP->fr_subtype == SUBYPTE_LOOP_16_22)
     {
       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
-              fragP->fr_offset, 1,
-              BFD_RELOC_UNUSED + opcode_converter.fx_r_type);
+              fragP->fr_offset, 1, BFD_RELOC_UNUSED + opindex);
       fragP->fr_fix += 4;
     }
   else if (fragP->fr_subtype == SUBYPTE_LOOP_16_22 + 1)
     {
-      unsigned char * buffer =
-       (unsigned char *) (fragP->fr_fix + &fragP->fr_literal[0]);
-      int loop_reg = (buffer[0] & 0x1f);
+      char *buffer = fragP->fr_literal + fragP->fr_fix;
+      int loop_reg = buffer[0] & 0x1f;
 
       /* Add -1.reg.  */
-      md_number_to_chars ((char *) buffer, 0x025f | (loop_reg << 11), 2);
+      md_number_to_chars (buffer, 0x025f | (loop_reg << 11), 2);
       /* Now create the conditional branch + fixup to the final target.  */
       /* 0x000107ea = bne LBL(disp17).  */
-      md_number_to_chars ((char *) buffer + 2, 0x000107ea, 4);
+      md_number_to_chars (buffer + 2, 0x000107ea, 4);
       fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
-              fragP->fr_offset, 1,
-              BFD_RELOC_V850_17_PCREL);
+              fragP->fr_offset, 1, BFD_RELOC_V850_17_PCREL);
       fragP->fr_fix += 6;
     }
   /* In range conditional or unconditional branch.  */
@@ -1725,8 +1712,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
 
     {
       fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
-              fragP->fr_offset, 1,
-              BFD_RELOC_UNUSED + opcode_converter.fx_r_type);
+              fragP->fr_offset, 1, BFD_RELOC_UNUSED + opindex);
       fragP->fr_fix += 2;
     }
   /* V850e2r-v3 17bit conditional branch.  */
@@ -1735,8 +1721,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
           || fragP->fr_subtype == SUBYPTE_SA_9_17_22 + 1
           || fragP->fr_subtype == SUBYPTE_SA_9_17_22_32 + 1)
     {
-      unsigned char *buffer =
-       (unsigned char *) (fragP->fr_fix + &fragP->fr_literal[0]);
+      char *buffer = fragP->fr_literal + fragP->fr_fix;
 
       buffer[0] &= 0x0f;       /* Use condition.  */
       buffer[0] |= 0xe0;
@@ -1744,7 +1729,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
 
       /* Now create the unconditional branch + fixup to the final
         target.  */
-      md_number_to_chars ((char *) buffer + 2, 0x0001, 2);
+      md_number_to_chars (buffer + 2, 0x0001, 2);
       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
               fragP->fr_offset, 1, BFD_RELOC_V850_17_PCREL);
       fragP->fr_fix += 4;
@@ -1755,8 +1740,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
           || fragP->fr_subtype == SUBYPTE_COND_9_17_22 + 2
           || fragP->fr_subtype == SUBYPTE_COND_9_17_22_32 + 2)
     {
-      unsigned char *buffer =
-       (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
+      char *buffer = fragP->fr_literal + fragP->fr_fix;
 
       /* Reverse the condition of the first branch.  */
       buffer[0] ^= 0x08;
@@ -1769,7 +1753,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
 
       /* Now create the unconditional branch + fixup to the final
         target.  */
-      md_number_to_chars ((char *) buffer + 2, 0x00000780, 4);
+      md_number_to_chars (buffer + 2, 0x00000780, 4);
       fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
               fragP->fr_offset, 1, BFD_RELOC_V850_22_PCREL);
       fragP->fr_fix += 6;
@@ -1778,8 +1762,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
   else if (fragP->fr_subtype == SUBYPTE_COND_9_22_32 + 2
           || fragP->fr_subtype == SUBYPTE_COND_9_17_22_32 + 3)
     {
-      unsigned char *buffer =
-       (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
+      char *buffer = fragP->fr_literal + fragP->fr_fix;
 
       /* Reverse the condition of the first branch.  */
       buffer[0] ^= 0x08;
@@ -1792,7 +1775,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
 
       /* Now create the unconditional branch + fixup to the final
         target.  */
-      md_number_to_chars ((char *) buffer + 2, 0x02e0, 2);
+      md_number_to_chars (buffer + 2, 0x02e0, 2);
       fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
               fragP->fr_offset + 2, 1, BFD_RELOC_V850_32_PCREL);
       fragP->fr_fix += 8;
@@ -1820,8 +1803,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
           || fragP->fr_subtype == SUBYPTE_SA_9_17_22 + 2
           || fragP->fr_subtype == SUBYPTE_SA_9_17_22_32 + 2)
     {
-      unsigned char *buffer =
-       (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
+      char *buffer = fragP->fr_literal + fragP->fr_fix;
 
       /* bsa .+4 */
       buffer[0] &= 0x8f;
@@ -1829,23 +1811,21 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
       buffer[1] &= 0x07;
 
       /* br .+6 */
-      md_number_to_chars ((char *) buffer + 2, 0x05b5, 2);
+      md_number_to_chars (buffer + 2, 0x05b5, 2);
 
       /* Now create the unconditional branch + fixup to the final
         target.  */
       /* jr SYM */
-      md_number_to_chars ((char *) buffer + 4, 0x00000780, 4);
+      md_number_to_chars (buffer + 4, 0x00000780, 4);
       fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
-              fragP->fr_offset, 1,
-              BFD_RELOC_V850_22_PCREL);
+              fragP->fr_offset, 1, BFD_RELOC_V850_22_PCREL);
       fragP->fr_fix += 8;
     }
   /* Out of range SA conditional branch.  Emit a branch around a 32bit jump.  */
   else if (fragP->fr_subtype == SUBYPTE_SA_9_22_32 + 2
           || fragP->fr_subtype == SUBYPTE_SA_9_17_22_32 + 3)
     {
-      unsigned char *buffer =
-       (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
+      char *buffer = fragP->fr_literal + fragP->fr_fix;
 
       /* bsa .+2 */
       buffer[0] &= 0x8f;
@@ -1853,12 +1833,12 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
       buffer[1] &= 0x07;
 
       /* br .+8 */
-      md_number_to_chars ((char *) buffer + 2, 0x05c5, 2);
+      md_number_to_chars (buffer + 2, 0x05c5, 2);
 
       /* Now create the unconditional branch + fixup to the final
         target.  */
       /* jr SYM */
-      md_number_to_chars ((char *) buffer + 4, 0x02e0, 2);
+      md_number_to_chars (buffer + 4, 0x02e0, 2);
       fix_new (fragP, fragP->fr_fix + 6, 4, fragP->fr_symbol,
               fragP->fr_offset + 2, 1, BFD_RELOC_V850_32_PCREL);
 
@@ -3068,7 +3048,7 @@ md_assemble (char *str)
              f = frag_var (rs_machine_dependent, 6, 2, SUBYPTE_LOOP_16_22,
                            fixups[0].exp.X_add_symbol,
                            fixups[0].exp.X_add_number,
-                           (char *)(intptr_t) fixups[0].opindex);
+                           (char *) (uintptr_t) fixups[0].opindex);
              md_number_to_chars (f, insn, insn_size);
              md_number_to_chars (f+4, 0, 4);
            }
@@ -3085,7 +3065,7 @@ md_assemble (char *str)
              f = frag_var (rs_machine_dependent, 4, 2, SUBYPTE_UNCOND_9_22,
                            fixups[0].exp.X_add_symbol,
                            fixups[0].exp.X_add_number,
-                           (char *)(intptr_t) fixups[0].opindex);
+                           (char *) (uintptr_t) fixups[0].opindex);
              md_number_to_chars (f, insn, insn_size);
              md_number_to_chars (f + 2, 0, 2);
            }
@@ -3094,7 +3074,7 @@ md_assemble (char *str)
              f = frag_var (rs_machine_dependent, 6, 4, SUBYPTE_UNCOND_9_22_32,
                            fixups[0].exp.X_add_symbol,
                            fixups[0].exp.X_add_number,
-                           (char *)(intptr_t) fixups[0].opindex);
+                           (char *) (uintptr_t) fixups[0].opindex);
              md_number_to_chars (f, insn, insn_size);
              md_number_to_chars (f + 2, 0, 4);
            }
@@ -3111,7 +3091,7 @@ md_assemble (char *str)
                      f = frag_var (rs_machine_dependent, 8, 6, SUBYPTE_SA_9_17_22,
                                    fixups[0].exp.X_add_symbol,
                                    fixups[0].exp.X_add_number,
-                                   (char *)(intptr_t) fixups[0].opindex);
+                                   (char *) (uintptr_t) fixups[0].opindex);
                      md_number_to_chars (f, insn, insn_size);
                      md_number_to_chars (f + 2, 0, 6);
                    }
@@ -3120,7 +3100,7 @@ md_assemble (char *str)
                      f = frag_var (rs_machine_dependent, 6, 4, SUBYPTE_COND_9_17_22,
                                    fixups[0].exp.X_add_symbol,
                                    fixups[0].exp.X_add_number,
-                                   (char *)(intptr_t) fixups[0].opindex);
+                                   (char *) (uintptr_t) fixups[0].opindex);
                      md_number_to_chars (f, insn, insn_size);
                      md_number_to_chars (f + 2, 0, 4);
                    }
@@ -3132,7 +3112,7 @@ md_assemble (char *str)
                      f = frag_var (rs_machine_dependent, 8, 6, SUBYPTE_SA_9_22,
                                    fixups[0].exp.X_add_symbol,
                                    fixups[0].exp.X_add_number,
-                                   (char *)(intptr_t) fixups[0].opindex);
+                                   (char *) (uintptr_t) fixups[0].opindex);
                      md_number_to_chars (f, insn, insn_size);
                      md_number_to_chars (f + 2, 0, 6);
                    }
@@ -3141,7 +3121,7 @@ md_assemble (char *str)
                      f = frag_var (rs_machine_dependent, 6, 4, SUBYPTE_COND_9_22,
                                    fixups[0].exp.X_add_symbol,
                                    fixups[0].exp.X_add_number,
-                                   (char *)(intptr_t) fixups[0].opindex);
+                                   (char *) (uintptr_t) fixups[0].opindex);
                      md_number_to_chars (f, insn, insn_size);
                      md_number_to_chars (f + 2, 0, 4);
                    }
@@ -3156,7 +3136,7 @@ md_assemble (char *str)
                      f = frag_var (rs_machine_dependent, 10, 8, SUBYPTE_SA_9_17_22_32,
                                    fixups[0].exp.X_add_symbol,
                                    fixups[0].exp.X_add_number,
-                                   (char *)(intptr_t) fixups[0].opindex);
+                                   (char *) (uintptr_t) fixups[0].opindex);
                      md_number_to_chars (f, insn, insn_size);
                      md_number_to_chars (f + 2, 0, 8);
                    }
@@ -3165,7 +3145,7 @@ md_assemble (char *str)
                      f = frag_var (rs_machine_dependent, 8, 6, SUBYPTE_COND_9_17_22_32,
                                    fixups[0].exp.X_add_symbol,
                                    fixups[0].exp.X_add_number,
-                                   (char *)(intptr_t) fixups[0].opindex);
+                                   (char *) (uintptr_t) fixups[0].opindex);
                      md_number_to_chars (f, insn, insn_size);
                      md_number_to_chars (f + 2, 0, 6);
                    }
@@ -3177,7 +3157,7 @@ md_assemble (char *str)
                      f = frag_var (rs_machine_dependent, 10, 8, SUBYPTE_SA_9_22_32,
                                    fixups[0].exp.X_add_symbol,
                                    fixups[0].exp.X_add_number,
-                                   (char *)(intptr_t) fixups[0].opindex);
+                                   (char *) (uintptr_t) fixups[0].opindex);
                      md_number_to_chars (f, insn, insn_size);
                      md_number_to_chars (f + 2, 0, 8);
                    }
@@ -3186,7 +3166,7 @@ md_assemble (char *str)
                      f = frag_var (rs_machine_dependent, 8, 6, SUBYPTE_COND_9_22_32,
                                    fixups[0].exp.X_add_symbol,
                                    fixups[0].exp.X_add_number,
-                                   (char *)(intptr_t) fixups[0].opindex);
+                                   (char *) (uintptr_t) fixups[0].opindex);
                      md_number_to_chars (f, insn, insn_size);
                      md_number_to_chars (f + 2, 0, 6);
                    }