public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Michael Matz <matz@suse.de>
Cc: Jan Beulich <jbeulich@suse.com>, Binutils <binutils@sourceware.org>
Subject: Re: [PATCH 3/6] x86: harmonize disp with imm handling
Date: Tue, 22 Jun 2021 07:01:54 -0700	[thread overview]
Message-ID: <CAMe9rOpbWh1i__tC8Te94esTUOh7RzouzYF0hwxdzradSP5-DA@mail.gmail.com> (raw)
In-Reply-To: <alpine.LSU.2.22.394.2106221303010.6035@wotan.suse.de>

On Tue, Jun 22, 2021 at 6:22 AM Michael Matz <matz@suse.de> wrote:
>
> Hello,
>
> On Fri, 18 Jun 2021, H.J. Lu via Binutils wrote:
>
> > > You realize that for the purpose of the test case the -0xffffffff is
> > > an over-simplification of what might appear in "real" code, don't
> > > you? It also feels as if you didn't really read my earlier remark:
> >
> > I don't think treating -0xffffffff as 1 here helps anyone.
>
> The assembler should not be too much in the business of constraining users
> with well-intended but badly implemented rules.  The -0xffffffff isn't
> actually a literal, it's an (assembler) operation applied to a literal.
> The wraparound that does or doesn't happen is _internal_ to the assembler,
> the hardware doesn't enter the picture.  -0xffffffff only means '1'
> because the assembler internally represents this as 32bit entity, again
> without the hardware mattering.  (And if it were using a different-sized
> internal field it would or wouldn't warn on different input ranges, and if
> that size then depends on how BFD is configured that would be very bad).
>
> Further it's quite probable that the '-' actually comes from e.g. a macro
> expansion, it's for instance feasible to write a macro that offsets
> something by a constant in both directions:
>
> #define sub2(reg, B, D) \
>   movq D(B), reg \
>   addq -D(B), reg
>
> Now it's completely opaque why the user should be warned about this:
>
>   sub2(%rax, %rdi, 0xffffffff)
>
> but not about this:
>
>   sub2(%rax, %rdi, 1)
>
> What you are saying is equivalent to say to also warn about uses of '--1',
> after all the user "should have simply used "1"'.  Extended such makes it
> obvious that the warning is unwarranted, because then there wouldn't even
> be a work-around for the above situation anymore, you can't write
> sub2(%rax,%rdi,0xffffffff) and you can't write sub2(%rax,%rdi,-1).
>
> I would perhaps agree that if a user literally would write '-0xffffffff'
> except in a testcase that a warning might be appropriate, in something
> that's designed to teach good style to assembler programmers perhaps.  But
> not in GNU as.  It would be a warning that can't be silenced and happens
> in perfectly valid code, so, no.
>
> All in all: I think the assembler should be entirely silent about any of
> these literals modified by assembler operations.

A 32bit displacement is signed with R_X86_64_32S.  For

mov disp(%rax), %eax

should linker issue an error if disp == -0xffffffff?

-- 
H.J.

  reply	other threads:[~2021-06-22 14:02 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-14 10:23 [PATCH 0/6] x86: further value overflow diagnostic adjustments Jan Beulich
2021-06-14 10:24 ` [PATCH 1/6] x86: off-by-1 in offset_in_range() Jan Beulich
2021-06-17 14:40   ` H.J. Lu
2021-06-18 10:48     ` Jan Beulich
2021-06-14 10:25 ` [PATCH 2/6] x86: make offset_in_range()'s warning contents useful (again) Jan Beulich
2021-06-17 14:40   ` H.J. Lu
2021-06-14 10:25 ` [PATCH 3/6] x86: harmonize disp with imm handling Jan Beulich
2021-06-17 14:46   ` H.J. Lu
2021-06-17 14:57     ` Jan Beulich
2021-06-17 16:00       ` H.J. Lu
2021-06-17 16:05         ` Jan Beulich
2021-06-17 16:12           ` H.J. Lu
2021-06-18  9:03             ` Jan Beulich
2021-06-18 14:12               ` H.J. Lu
2021-06-18 14:52                 ` Jan Beulich
2021-06-18 15:41                   ` H.J. Lu
2021-06-21  6:36                     ` Jan Beulich
2021-06-21 13:26                       ` H.J. Lu
2021-06-21 15:05                         ` Jan Beulich
2021-06-22 13:22                     ` Michael Matz
2021-06-22 14:01                       ` H.J. Lu [this message]
2021-06-22 14:32                         ` Jan Beulich
2021-06-22 14:35                         ` Michael Matz
2021-06-14 10:26 ` [PATCH 4/6] x86: slightly simplify offset_in_range() Jan Beulich
2021-06-17 14:46   ` H.J. Lu
2021-06-14 10:26 ` [PATCH 5/6] x86: simplify .dispNN setting Jan Beulich
2021-06-17 14:47   ` H.J. Lu
2021-06-14 10:26 ` [PATCH 6/6] x86: bring "gas --help" output for --32 etc in sync with reality Jan Beulich
2021-06-17 14:48   ` H.J. Lu
2021-06-14 14:41 ` [PATCH 0/6] x86: further value overflow diagnostic adjustments 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=CAMe9rOpbWh1i__tC8Te94esTUOh7RzouzYF0hwxdzradSP5-DA@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=jbeulich@suse.com \
    --cc=matz@suse.de \
    /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).