public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Subject: [PATCH 5/6] x86: never set i386_cpu_flags' "unused" field
Date: Wed, 16 Mar 2022 09:48:15 +0100	[thread overview]
Message-ID: <9fb1a22d-0f0e-fa4b-dd13-7913bac81462@suse.com> (raw)
In-Reply-To: <93cecdf2-b805-4508-9e34-89fd0011ccc9@suse.com>

Setting this field risks cpu_flags_all_zero() mistakenly returning
"false" when the object passed in was e.g. the result of ANDing together
two objects which had the bit set, or ANDNing together an object with
the field set and one with the field clear.

While there also avoid setting CpuNo64: Like Cpu64 this is driven
differently anyway and hence shouldn't be set anywhere by default.

Note that the moving of the two items in i386-gen.c's cpu_flags[] is
only for documentation purposes (and slight reducing of overhead), as
the fields are sorted anyway upon program start.

--- a/opcodes/i386-gen.c
+++ b/opcodes/i386-gen.c
@@ -628,8 +628,6 @@ static bitfield cpu_flags[] =
   BITFIELD (CpuPREFETCHWT1),
   BITFIELD (CpuSE1),
   BITFIELD (CpuCLWB),
-  BITFIELD (Cpu64),
-  BITFIELD (CpuNo64),
   BITFIELD (CpuMPX),
   BITFIELD (CpuAVX512IFMA),
   BITFIELD (CpuAVX512VBMI),
@@ -676,6 +674,8 @@ static bitfield cpu_flags[] =
   BITFIELD (CpuINVLPGB),
   BITFIELD (CpuTLBSYNC),
   BITFIELD (CpuSNP),
+  BITFIELD (Cpu64),
+  BITFIELD (CpuNo64),
 #ifdef CpuUnused
   BITFIELD (CpuUnused),
 #endif
@@ -1068,9 +1068,10 @@ process_i386_cpu_flag (FILE *table, char
       else
 	next = flag + 1;
 
-      /* First we turn on everything except for cpu64.  */
+      /* First we turn on everything except for cpu64, cpuno64, and - if
+         present - the padding field.  */
       for (i = 0; i < ARRAY_SIZE (flags); i++)
-	if (flags[i].position != Cpu64)
+	if (flags[i].position < Cpu64)
 	  flags[i].value = 1;
 
       /* Turn off selective bits.  */
--- a/opcodes/i386-opc.h
+++ b/opcodes/i386-opc.h
@@ -272,6 +272,9 @@ enum
   CpuTLBSYNC,
   /* SNP instructions required */
   CpuSNP,
+
+  /* NOTE: These last three items need to remain last and in this order. */
+
   /* 64bit support required  */
   Cpu64,
   /* Not supported in the 64bit mode  */
@@ -417,6 +420,7 @@ typedef union i386_cpu_flags
       unsigned int cpuinvlpgb:1;
       unsigned int cputlbsync:1;
       unsigned int cpusnp:1;
+      /* NOTE: These last three fields need to remain last and in this order. */
       unsigned int cpu64:1;
       unsigned int cpuno64:1;
 #ifdef CpuUnused


  parent reply	other threads:[~2022-03-16  8:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16  8:42 [PATCH 0/6] x86: drop L1OM/K1OM from gas plus associated tidying Jan Beulich
2022-03-16  8:45 ` [PATCH 1/6] x86: assorted IAMCU CPU checking fixes Jan Beulich
2022-03-16  8:46 ` [PATCH 2/6] x86: drop L1OM/K1OM support from gas Jan Beulich
2022-03-16  8:46 ` [PATCH 3/6] x86: add another IAMCU testcase Jan Beulich
2022-05-18 17:46   ` H.J. Lu
2022-03-16  8:47 ` [PATCH 4/6] x86: unify CPU flag on/off processing Jan Beulich
2022-03-16  8:48 ` Jan Beulich [this message]
2022-03-16  8:48 ` [PATCH 6/6] x86: don't accept base architectures as extensions Jan Beulich
2022-03-16 17:11 ` [PATCH 0/6] x86: drop L1OM/K1OM from gas plus associated tidying H.J. Lu
2022-03-17  8:32   ` Jan Beulich
2022-03-17 15:11     ` H.J. Lu

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=9fb1a22d-0f0e-fa4b-dd13-7913bac81462@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    /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).