From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH 5/6] x86: adjust NOP generation after potential non-insn
Date: Fri, 24 Nov 2023 10:05:31 +0100 [thread overview]
Message-ID: <6186c042-e778-470f-a995-1522aca041ea@suse.com> (raw)
In-Reply-To: <f5b4b6f8-4553-459e-a5ea-35b14055be77@suse.com>
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.
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -1529,6 +1529,14 @@ i386_generate_nops (fragS *fragP, char *
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. */
--- 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)
next prev parent reply other threads:[~2023-11-24 9:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-24 9:02 [PATCH 0/6] correct and further utilize x86'es last-insn tracking Jan Beulich
2023-11-24 9:03 ` [PATCH 1/6] x86: last-insn recording should be per-section Jan Beulich
2023-11-24 9:04 ` [PATCH 3/6] gas: no md_cons_align() for .nop{,s} Jan Beulich
2023-11-24 13:29 ` [PATCH 1/6] x86: last-insn recording should be per-section Jan Beulich
2023-11-24 9:03 ` [PATCH 2/6] x86: suppress optimization after potential non-insn Jan Beulich
2023-11-24 9:05 ` [PATCH 4/6] x86: i386_cons_align() badly affects diagnostics Jan Beulich
2023-11-24 9:05 ` Jan Beulich [this message]
2023-11-24 9:06 ` [PATCH 6/6] gas: drop unused fields from struct segment_info_struct Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6186c042-e778-470f-a995-1522aca041ea@suse.com \
--to=jbeulich@suse.com \
--cc=binutils@sourceware.org \
--cc=hjl.tools@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).