Skip to content

Commit ee623fd

Browse files
committed
Further rs_code_align support refinement
Don't write the repeating nop pattern if it won't be used.
1 parent 1c96b46 commit ee623fd

File tree

7 files changed

+39
-17
lines changed

7 files changed

+39
-17
lines changed

gas/config/tc-aarch64.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9058,11 +9058,15 @@ aarch64_handle_align (fragS * fragP)
90589058
#endif
90599059
memset (p, 0, fix);
90609060
p += fix;
9061+
bytes -= fix;
90619062
fragP->fr_fix += fix;
90629063
}
90639064

9064-
memcpy (p, aarch64_noop, noop_size);
9065-
fragP->fr_var = noop_size;
9065+
if (bytes != 0)
9066+
{
9067+
fragP->fr_var = noop_size;
9068+
memcpy (p, aarch64_noop, noop_size);
9069+
}
90669070
}
90679071

90689072
/* Perform target specific initialisation of a frag.

gas/config/tc-arm.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26602,7 +26602,6 @@ arm_handle_align (fragS * fragP)
2660226602

2660326603
bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
2660426604
p = fragP->fr_literal + fragP->fr_fix;
26605-
fix = 0;
2660626605

2660726606
gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
2660826607

@@ -26633,9 +26632,9 @@ arm_handle_align (fragS * fragP)
2663326632
#endif
2663426633
}
2663526634

26636-
if (bytes & (noop_size - 1))
26635+
fix = bytes & (noop_size - 1);
26636+
if (fix != 0)
2663726637
{
26638-
fix = bytes & (noop_size - 1);
2663926638
#ifdef OBJ_ELF
2664026639
insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
2664126640
#endif
@@ -26660,8 +26659,11 @@ arm_handle_align (fragS * fragP)
2666026659
}
2666126660

2666226661
fragP->fr_fix += fix;
26663-
fragP->fr_var = noop_size;
26664-
memcpy (p, noop, noop_size);
26662+
if (bytes != 0)
26663+
{
26664+
fragP->fr_var = noop_size;
26665+
memcpy (p, noop, noop_size);
26666+
}
2666526667
}
2666626668

2666726669
/* Perform target specific initialisation of a frag.

gas/config/tc-epiphany.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,15 @@ epiphany_handle_align (fragS *fragp)
326326
if (bytes & 1)
327327
{
328328
*p++ = 0;
329+
bytes--;
329330
fragp->fr_fix++;
330331
}
331332

332-
memcpy (p, nop_pattern, 2);
333-
fragp->fr_var = 2;
333+
if (bytes != 0)
334+
{
335+
fragp->fr_var = 2;
336+
memcpy (p, nop_pattern, 2);
337+
}
334338
}
335339

336340
/* Read a comma separated incrementing list of register names

gas/config/tc-i386.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,9 +1775,11 @@ i386_generate_nops (fragS *fragP, char *where, offsetT count, int limit)
17751775
included in fr_fix. The repeating larger nop only needs to
17761776
be written once to the frag memory. */
17771777
fragP->fr_fix = where - fragP->fr_literal;
1778-
fragP->fr_var = limit;
17791778
if (count != 0)
1780-
count = limit;
1779+
{
1780+
fragP->fr_var = limit;
1781+
count = limit;
1782+
}
17811783
}
17821784

17831785
const unsigned char *nops = patt[limit - 1];

gas/config/tc-metag.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6853,11 +6853,15 @@ metag_handle_align (fragS * fragP)
68536853
{
68546854
memset (p, 0, fix);
68556855
p += fix;
6856+
bytes -= fix;
68566857
fragP->fr_fix += fix;
68576858
}
68586859

6859-
memcpy (p, noop, 4);
6860-
fragP->fr_var = 4;
6860+
if (bytes != 0)
6861+
{
6862+
fragP->fr_var = 4;
6863+
memcpy (p, noop, 4);
6864+
}
68616865
}
68626866

68636867
static char *

gas/config/tc-nds32.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,12 +4657,16 @@ nds32_handle_align (fragS *fragp)
46574657
BFD_RELOC_NDS32_INSN16);
46584658
memcpy (p, nop16, 2);
46594659
p += 2;
4660+
bytes -= 2;
46604661
fix += 2;
46614662
}
46624663
fragp->fr_fix += fix;
46634664

4664-
fragp->fr_var = 4;
4665-
memcpy (p, nop32, 4);
4665+
if (bytes != 0)
4666+
{
4667+
fragp->fr_var = 4;
4668+
memcpy (p, nop32, 4);
4669+
}
46664670
}
46674671

46684672
/* md_flush_pending_output */

gas/config/tc-ppc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6887,15 +6887,17 @@ ppc_handle_align (segT sec, struct frag *fragP)
68876887
{
68886888
valueT count = (fragP->fr_next->fr_address
68896889
- (fragP->fr_address + fragP->fr_fix));
6890+
if (count == 0)
6891+
return;
6892+
68906893
char *dest = fragP->fr_literal + fragP->fr_fix;
68916894
enum ppc_nop_encoding_for_rs_align_code nop_select = *dest & 0xff;
68926895

68936896
/* Pad with zeros if not inserting a whole number of instructions.
68946897
We could pad with zeros up to an instruction boundary then follow
68956898
with nops but odd counts indicate data in an executable section
68966899
so padding with zeros is most appropriate. */
6897-
if (count == 0
6898-
|| (nop_select == PPC_NOP_VLE ? (count & 1) != 0 : (count & 3) != 0))
6900+
if (nop_select == PPC_NOP_VLE ? (count & 1) != 0 : (count & 3) != 0)
68996901
{
69006902
*dest = 0;
69016903
return;

0 commit comments

Comments
 (0)