public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] x86: adjust NOP generation after potential non-insn
@ 2023-12-01  7:30 Jan Beulich
  0 siblings, 0 replies; only message in thread
From: Jan Beulich @ 2023-12-01  7:30 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0aa5d0c9e90a2bf26a99a0354ef500e971341de8

commit 0aa5d0c9e90a2bf26a99a0354ef500e971341de8
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Dec 1 08:29:11 2023 +0100

    x86: adjust NOP generation after potential non-insn
    
    Just like avoiding to do certain transformations potentially affected by
    stand-alone prefixes or direct data emission, also avoid emitting
    optimized NOPs right afterwards; insert a plain old NOP first in such
    cases.

Diff:
---
 gas/config/tc-i386.c | 8 ++++++++
 gas/config/tc-i386.h | 6 +++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index e984923ec35..4f3864f2ba7 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -1529,6 +1529,14 @@ i386_generate_nops (fragS *fragP, char *where, offsetT count, int limit)
   else if (fragP->fr_type != rs_machine_dependent)
     fragP->fr_var = count;
 
+  /* Emit a plain NOP first when the last thing we saw may not have been
+     a proper instruction (e.g. a stand-alone prefix or .byte).  */
+  if (!fragP->tc_frag_data.last_insn_normal)
+    {
+      *where++ = 0x90;
+      --count;
+    }
+
   if ((count / max_single_nop_size) > max_number_of_nops)
     {
       /* Generate jump over NOPs.  */
diff --git a/gas/config/tc-i386.h b/gas/config/tc-i386.h
index c3022149fbe..6d6f0b93681 100644
--- a/gas/config/tc-i386.h
+++ b/gas/config/tc-i386.h
@@ -321,6 +321,7 @@ struct i386_tc_frag_data
   unsigned int branch_type : 3;
   unsigned int cpunop : 1;
   unsigned int isanop : 1;
+  unsigned int last_insn_normal : 1;
 };
 
 /* We need to emit the right NOP pattern in .align frags.  This is
@@ -347,7 +348,10 @@ struct i386_tc_frag_data
      (FRAGP)->tc_frag_data.cmp_size = 0;			\
      (FRAGP)->tc_frag_data.classified = 0;			\
      (FRAGP)->tc_frag_data.branch_type = 0;			\
-     (FRAGP)->tc_frag_data.mf_type = 0;			\
+     (FRAGP)->tc_frag_data.mf_type = 0;				\
+     (FRAGP)->tc_frag_data.last_insn_normal			\
+	= (seg_info(now_seg)->tc_segment_info_data.last_insn.kind \
+	   == last_insn_other);					\
    }								\
  while (0)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-01  7:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-01  7:30 [binutils-gdb] x86: adjust NOP generation after potential non-insn Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).