From 6398ac7e8b9dc8992bc375e401943915a41952c8 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 10 Jul 2025 11:15:16 +0930 Subject: [PATCH] gas v850 md_convert_frag 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 | 6 +-- gas/config/tc-crx.c | 6 +-- gas/config/tc-mn10200.c | 1 - gas/config/tc-mn10300.c | 1 - gas/config/tc-sh.c | 3 -- gas/config/tc-v850.c | 86 ++++++++++++++++------------------------- 6 files changed, 39 insertions(+), 64 deletions(-) diff --git a/gas/config/tc-cr16.c b/gas/config/tc-cr16.c index 5bf088d5736..99bc1bdd506 100644 --- a/gas/config/tc-cr16.c +++ b/gas/config/tc-cr16.c @@ -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: diff --git a/gas/config/tc-crx.c b/gas/config/tc-crx.c index d5eb9db5ab8..e51921441b0 100644 --- a/gas/config/tc-crx.c +++ b/gas/config/tc-crx.c @@ -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: diff --git a/gas/config/tc-mn10200.c b/gas/config/tc-mn10200.c index 210e9b016fc..1eb470295a4 100644 --- a/gas/config/tc-mn10200.c +++ b/gas/config/tc-mn10200.c @@ -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, diff --git a/gas/config/tc-mn10300.c b/gas/config/tc-mn10300.c index a1d89f09f16..db87d523f46 100644 --- a/gas/config/tc-mn10300.c +++ b/gas/config/tc-mn10300.c @@ -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, diff --git a/gas/config/tc-sh.c b/gas/config/tc-sh.c index 56535830b87..551d8e8b24d 100644 --- a/gas/config/tc-sh.c +++ b/gas/config/tc-sh.c @@ -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); diff --git a/gas/config/tc-v850.c b/gas/config/tc-v850.c index 8a86b1d2b89..f73c3bfbab3 100644 --- a/gas/config/tc-v850.c +++ b/gas/config/tc-v850.c @@ -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); } -- 2.47.2