public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "andrew.cooper3 at citrix dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/104971] [9/10/11/12 Regression] Optimisation for __builtin_ia32_readeflags corrupts the stack
Date: Thu, 17 Mar 2022 20:49:26 +0000	[thread overview]
Message-ID: <bug-104971-4-8NhCpxrHU6@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104971-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104971

--- Comment #3 from Andrew Cooper <andrew.cooper3 at citrix dot com> ---
So yes - my experimentation did start from investigating the memory ordering
behaviour of these builtins, based on a thread on LKML.

The pushf in readflags and popf in writeflags have wildly different ordering
requirements, depending on which flags are wanted/modified.  AC for example
(and IF for kernels) need to not be reordered with respect to any memory
access.

As you observe, readflags in particular needs to not be reordered with any
instruction that modifies the arithmetic flags (which is most of them).

IMO, it would be safe to omit the pushf from readflags if the result is not not
used, because there are no unexpected side effects for pushf.

The same is not true of popf in writeflags, which has side effects even when
written twice with the same value.

  parent reply	other threads:[~2022-03-17 20:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17 18:49 [Bug middle-end/104971] New: " andrew.cooper3 at citrix dot com
2022-03-17 19:05 ` [Bug middle-end/104971] [9/10/11/12 Regression] " jakub at gcc dot gnu.org
2022-03-17 19:35 ` jakub at gcc dot gnu.org
2022-03-17 20:49 ` andrew.cooper3 at citrix dot com [this message]
2022-03-17 21:12 ` mpolacek at gcc dot gnu.org
2022-03-18 17:32 ` jakub at gcc dot gnu.org
2022-03-19 12:53 ` cvs-commit at gcc dot gnu.org
2022-03-25 16:31 ` [Bug middle-end/104971] [9/10/11 " cvs-commit at gcc dot gnu.org
2022-03-29  5:54 ` cvs-commit at gcc dot gnu.org
2022-03-30  8:17 ` [Bug middle-end/104971] [9/10 " jakub at gcc dot gnu.org
2022-05-10  8:25 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:25 ` cvs-commit at gcc dot gnu.org

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=bug-104971-4-8NhCpxrHU6@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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).