Further rs_code_align support refinement
Alan Modra
amodra@gmail.com
Wed May 28 11:39:26 GMT 2025
More information about the Binutils mailing list
Wed May 28 11:39:26 GMT 2025
- Previous message (by thread): PR 33029 segv in dwarf2_finish with --gdwarf-5
- Next message (by thread): [PATCH v2] aarch64: Support for FEAT_LSFE
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Don't write the repeating nop pattern if it won't be used.
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index 9005fc77eb1..5d35a900326 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -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.
diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index ad4eef4bc04..44020e3140b 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -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.
diff --git a/gas/config/tc-epiphany.c b/gas/config/tc-epiphany.c
index be3235ae70a..4a027e9f31d 100644
--- a/gas/config/tc-epiphany.c
+++ b/gas/config/tc-epiphany.c
@@ -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);
+ }
}
/* Read a comma separated incrementing list of register names
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 73d552edb13..723f02159d4 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -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];
diff --git a/gas/config/tc-metag.c b/gas/config/tc-metag.c
index 195e6a4040f..09ee5c3acea 100644
--- a/gas/config/tc-metag.c
+++ b/gas/config/tc-metag.c
@@ -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 *
diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c
index 26172e54b3a..3c16216f531 100644
--- a/gas/config/tc-nds32.c
+++ b/gas/config/tc-nds32.c
@@ -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 */
diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index eef82d70169..b59a2f59a1d 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -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;
--
Alan Modra
- Previous message (by thread): PR 33029 segv in dwarf2_finish with --gdwarf-5
- Next message (by thread): [PATCH v2] aarch64: Support for FEAT_LSFE
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list