From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1386) id C50423858C30; Fri, 1 Dec 2023 07:30:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C50423858C30 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jan Beulich To: bfd-cvs@sourceware.org Subject: [binutils-gdb] x86: adjust NOP generation after potential non-insn X-Act-Checkin: binutils-gdb X-Git-Author: Jan Beulich X-Git-Refname: refs/heads/master X-Git-Oldrev: ce69d08114bbd64ba0bec60ba1e51438abbd45d6 X-Git-Newrev: 0aa5d0c9e90a2bf26a99a0354ef500e971341de8 Message-Id: <20231201073011.C50423858C30@sourceware.org> Date: Fri, 1 Dec 2023 07:30:11 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Dec 2023 07:30:11 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0aa5d0c9e90a= 2bf26a99a0354ef500e971341de8 commit 0aa5d0c9e90a2bf26a99a0354ef500e971341de8 Author: Jan Beulich Date: Fri Dec 1 08:29:11 2023 +0100 x86: adjust NOP generation after potential non-insn =20 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, offse= tT count, int limit) else if (fragP->fr_type !=3D rs_machine_dependent) fragP->fr_var =3D count; =20 + /* 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++ =3D 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; }; =20 /* 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 =3D 0; \ (FRAGP)->tc_frag_data.classified =3D 0; \ (FRAGP)->tc_frag_data.branch_type =3D 0; \ - (FRAGP)->tc_frag_data.mf_type =3D 0; \ + (FRAGP)->tc_frag_data.mf_type =3D 0; \ + (FRAGP)->tc_frag_data.last_insn_normal \ + =3D (seg_info(now_seg)->tc_segment_info_data.last_insn.kind \ + =3D=3D last_insn_other); \ } \ while (0)