public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH 02/11] x86: i386_generate_nops() may not derive decisions from global variables
Date: Wed, 27 Sep 2023 17:48:15 +0200	[thread overview]
Message-ID: <85a2958d-3a80-7bbc-ffa3-4078f34eeef2@suse.com> (raw)
In-Reply-To: <7ce54bc2-fef2-d2e4-21fd-202fdead0c20@suse.com>

What matters is what was in effect at the time the original directive
was issued. Later changes to global state (bitness or ISA) must not
affect what code is generated.

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -1434,7 +1434,7 @@ i386_generate_nops (fragS *fragP, char *
      When -march= or .arch is used, we can't use anything beyond
      cpu_arch_isa_flags.   */
 
-  if (flag_code == CODE_16BIT)
+  if (fragP->tc_frag_data.code == CODE_16BIT)
     {
       patt = f16_patt;
       max_single_nop_size = sizeof (f16_patt) / sizeof (f16_patt[0]);
@@ -1446,7 +1446,7 @@ i386_generate_nops (fragS *fragP, char *
       if (fragP->tc_frag_data.isa == PROCESSOR_UNKNOWN)
 	{
 	  /* PROCESSOR_UNKNOWN means that all ISAs may be used.  */
-	  switch (cpu_arch_tune)
+	  switch (fragP->tc_frag_data.tune)
 	    {
 	    case PROCESSOR_UNKNOWN:
 	      /* We use cpu_arch_isa_flags to check if we SHOULD
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -148,6 +148,7 @@ if [gas_32_check] then {
     run_dump_test "nops-7"
     run_dump_test "nops-8"
     run_dump_test "nops-9"
+    run_dump_test "nops-10"
     run_dump_test "noreg16"
     run_list_test "noreg16"
     run_dump_test "noreg16-data32"
--- /dev/null
+++ b/gas/testsuite/gas/i386/nops-10.d
@@ -0,0 +1,13 @@
+#objdump: -drw
+#name: nops 10
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+0+ <default>:
+[ 	]*[a-f0-9]+:	0f be f0             	movsbl %al,%esi
+[ 	]*[a-f0-9]+:	8d b4 26 00 00 00 00 	lea    0x0\(%esi,%eiz,1\),%esi
+[ 	]*[a-f0-9]+:	8d b6 00 00 00 00    	lea    0x0\(%esi\),%esi
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/i386/nops-10.s
@@ -0,0 +1,6 @@
+	.text
+default:
+	movsbl %al,%esi
+	.p2align 4
+
+	.code16
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-nops-6.d
@@ -0,0 +1,13 @@
+#objdump: -drw
+#name: x86-64 nops 6
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+0+ <default>:
+[ 	]*[a-f0-9]+:	0f be f0             	movsbl %al,%esi
+[ 	]*[a-f0-9]+:	66 66 2e 0f 1f 84 00 00 00 00 00 	data16 cs nopw (0x)?0\(%rax,%rax,1\)
+[ 	]*[a-f0-9]+:	66 90                	xchg   %ax,%ax
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-nops-6.s
@@ -0,0 +1,7 @@
+	.text
+default:
+	movsbl %al,%esi
+	.p2align 4
+
+	.code32
+	.arch generic32
--- a/gas/testsuite/gas/i386/x86-64.exp
+++ b/gas/testsuite/gas/i386/x86-64.exp
@@ -116,6 +116,7 @@ run_dump_test "x86-64-nops-4-core2"
 run_dump_test "x86-64-nops-4-k8"
 run_dump_test "x86-64-nops-5"
 run_dump_test "x86-64-nops-5-k8"
+run_dump_test "x86-64-nops-6"
 run_dump_test "x86-64-nops-7"
 run_dump_test "x86-64-sysenter"
 run_dump_test "x86-64-sysenter-intel"


  parent reply	other threads:[~2023-09-27 15:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-27 15:46 [PATCH 00/11] x86: NOP emission adjustments Jan Beulich
2023-09-27 15:47 ` [PATCH 01/11] x86: record flag_code in tc_frag_data Jan Beulich
2023-09-27 15:48 ` Jan Beulich [this message]
2023-09-27 15:48 ` [PATCH 03/11] x86: don't use 32-bit LEA as NOP surrogate in 64-bit code Jan Beulich
2023-09-27 15:49 ` [PATCH 04/11] x86: don't use operand size override with NOP in 16-bit code Jan Beulich
2023-09-27 15:50 ` [PATCH 05/11] x86: respect ".arch nonop" when selecting which NOPs to emit Jan Beulich
2023-09-27 15:50 ` [PATCH 06/11] x86: i686 != PentiumPro Jan Beulich
2023-09-27 15:51 ` [PATCH 07/11] x86: don't record full i386_cpu_flags in struct i386_tc_frag_data Jan Beulich
2023-09-27 15:51 ` [PATCH 08/11] x86: add a few more NOP patterns Jan Beulich
2023-09-27 15:52 ` [PATCH 09/11] x86: fold a few of the "alternative" " Jan Beulich
2023-09-27 15:52 ` [PATCH 10/11] x86: fold NOP testcase expectations where possible Jan Beulich
2023-09-27 15:53 ` [PATCH 11/11] gas: make .nops output visible in listing Jan Beulich
2023-09-27 15:59 ` [PATCH 00/11] x86: NOP emission adjustments 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=85a2958d-3a80-7bbc-ffa3-4078f34eeef2@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).