public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: <binutils@sourceware.org>
Subject: Re: [PATCH] i386: Don't add 0x66 prefix to IRET for .code16gcc
Date: Thu, 02 May 2019 07:43:00 -0000	[thread overview]
Message-ID: <5CCA9F8C020000780022B08B@prv1-mh.provo.novell.com> (raw)
In-Reply-To: <CAMe9rOoR4qt3eb9eyduZao8qJk-pHDn3bCMb7r7ANzt=SBjEsw@mail.gmail.com>

>>> On 30.04.19 at 17:48, <hjl.tools@gmail.com> wrote:
> On Mon, Apr 29, 2019 at 11:44 PM Jan Beulich <JBeulich@suse.com> wrote:
>>
>> >>> On 29.04.19 at 19:13, <hjl.tools@gmail.com> wrote:
>> > On Mon, Apr 29, 2019 at 9:11 AM Jan Beulich <JBeulich@suse.com> wrote:
>> >>
>> >> >>> On 29.04.19 at 18:02, <hjl.tools@gmail.com> wrote:
>> >> > On Mon, Apr 29, 2019 at 8:25 AM Jan Beulich <JBeulich@suse.com> wrote:
>> >> >>
>> >> >> >>> On 29.04.19 at 17:09, <hjl.tools@gmail.com> wrote:
>> >> >> > On Mon, Apr 29, 2019 at 12:01 AM Jan Beulich <JBeulich@suse.com> wrote:
>> >> >> >> >>> On 26.04.19 at 19:22, <hjl.tools@gmail.com> wrote:
>> >> >> >> > The .code16gcc directive supports 16bit mode with 32-bit address.  Since
>> >> >> >> > IRET (opcode 0xcf) in 16bit mode returns from an interrupt in 16bit mode,
>> >> >> >> > we shouldn't add 0x66 prefix for IRET.
>> >> >> >> >
>> >> >> >> >       PR gas/24485
>> >> >> >> >       * config/tc-i386.c (process_suffix): Don't add DATA_PREFIX_OPCODE
>> >> >> >> >       to IRET for .code16gcc.
>> >> >> >>
>> >> >> >> This, at the very least, needs to be accompanied by a warning:
>> >> >> >
>> >> >> > This patch fixes:
>> >> >> >[...]
>> >> >> >> As the bug report validly says, the changed behavior is what is
>> >> >> >> wanted only "almost always". The report even mentions the
>> >> >> >> (supposedly uncommon) case: Code manually building a frame
>> >> >> >> and IRETing to it will now be silently(!) broken.
>> >> >> >
>> >> >> > The .code16gcc directive is to support "gcc -m16".   Any other purposes
>> >> >> > are not supported.
>> >> >>
>> >> >> But you realize that people may use inline assembly?
>> >> >
>> >> > Inline assembly with the .code16gcc directive in an interrupt
>> >> > handler? It is a supported usage?
>> >>
>> >> I don't know, but I see no reasons why it would not be. Note
>> >> that I didn't mention "in an interrupt handler" - I can see uses
>> >> for manually created frames to IRET to elsewhere.
>> >>
>> >> >> >> In fact I think the better solution would be to reject ambiguous
>> >> >> >> code by demanding a suffix in all cases in .code16gcc mode.
>> >> >> >
>> >> >> > This may break existing codes.
>> >> >>
>> >> >> Of course, but breaking things at build time (with a proper
>> >> >> diagnostic) that's better than silently breaking things at
>> >> >> runtime. At the very least you can't claim it would break the
>> >> >> supposedly common case, as that was already broken (and
>> >> >> hence your fix). So the difference between suggested
>> >> >> and current behavior is that right now there's silent latent
>> >> >> breakage, whereas otherwise people would be made aware
>> >> >> of there being a problem they need to address by changing
>> >> >> some of their code.
>> >> >
>> >> > Assembler has no way to know if an assembly sequence is
>> >> > correct and it shouldn't issue a warning for "gcc -m16" just
>> >> > because the same instruction may be incorrect.
>> >>
>> >> I disagree: In this case, the assembler simply can't decide
>> >> whether adding an operand size override is correct. Instead
>> >> of silently doing the opposite of what has been done for
>> >> many years, it should point out that it needs programmer
>> >> guidance.
>> >>
>> >
>> > So the specific case is
>> >
>> > 1. Programming in 16-bit mode with GCC using "gcc -m16".
>> > 2. Manually create a 32-bit stack frame for a function with 32-bit iret.
>> > 3. Implement such a function with .code16gcc and "iret".
>> > 4. Jump to such a function.
>>
>> Yes. And note that the PUSHes potentially involved in step 2
>> default to 32-bit operand size, i.e. there's then a mixture of
>> requirements as to whether suffixes are needed on the insns.
>>
>> In the end, just like for your address size override fix for
>> scatter/gather insns a few weeks back, I think this is again a
>> case which would better be fixed in the compiler (making it
>> emit the needed suffix) than in the assembler.
>>
> 
> I am checking in this patch.

Thanks much.

Jan

      reply	other threads:[~2019-05-02  7:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-26 17:22 H.J. Lu
2019-04-29  7:01 ` Jan Beulich
2019-04-29 15:09   ` H.J. Lu
2019-04-29 15:25     ` Jan Beulich
2019-04-29 16:03       ` H.J. Lu
2019-04-29 16:11         ` Jan Beulich
2019-04-29 17:13           ` H.J. Lu
2019-04-30  6:44             ` Jan Beulich
2019-04-30 15:49               ` H.J. Lu
2019-05-02  7:43                 ` Jan Beulich [this message]

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=5CCA9F8C020000780022B08B@prv1-mh.provo.novell.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).