public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nelson Chu <nelson.chu@sifive.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Binutils <binutils@sourceware.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	 Andrew Waterman <andrew@sifive.com>,
	Jim Wilson <jim.wilson.gcc@gmail.com>
Subject: Re: [PATCH] RISC-V: make .insn actually work for 64-bit insns
Date: Fri, 25 Feb 2022 21:38:36 +0800	[thread overview]
Message-ID: <CAJYME4Gyjsxzj-u6KF2NVA7vdPZxyBP+6ZLmco7Mz_16PbU7sA@mail.gmail.com> (raw)
In-Reply-To: <6d807b33-5409-b728-7d1e-9fef8a16490b@suse.com>

On Fri, Feb 25, 2022 at 7:06 PM Jan Beulich <jbeulich@suse.com> wrote:
>
> Presently in this case, due to an undefined behavior shift, at least
> with x86 cross builds I'm observing:
>
> Error: value conflicts with instruction length `8,0x0000003f'
>
> Eliminate the UB and extend the respective testcase.
>
> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -3248,7 +3248,7 @@ riscv_ip_hardcode (char *str,
>    insn->match = values[num - 1];
>    create_insn (ip, insn);
>    unsigned int bytes = riscv_insn_length (insn->match);
> -  if (values[num - 1] >> (8 * bytes) != 0
> +  if ((bytes < sizeof(values[0]) && values[num - 1] >> (8 * bytes) != 0)
>        || (num == 2 && values[0] != bytes))
>      return _("value conflicts with instruction length");

I only considered 2/4 bytes instructions before, but forgot to think
that insn_t (uint_64) shifts 64 bit will be the original value (not
equal zero), so the previous check was dangerous.  We probably need to
consider the case that instruction length will be more than 64-bit in
the future, but now your fix should be enough and good to me.  Please
commit the patch when you think it's time.

Thanks
Nelson

> --- a/gas/testsuite/gas/riscv/insn.d
> +++ b/gas/testsuite/gas/riscv/insn.d
> @@ -71,5 +71,9 @@ Disassembly of section .text:
>  [^:]+:[        ]+00c58533[     ]+add[  ]+a0,a1,a2
>  [^:]+:[        ]+0001[         ]+nop
>  [^:]+:[        ]+00000013[     ]+nop
> +[^:]+:[        ]+001f 0000 0000[       ].*
> +[^:]+:[        ]+0000003f 00000000[    ].*
>  [^:]+:[        ]+0001[         ]+nop
>  [^:]+:[        ]+00000013[     ]+nop
> +[^:]+:[        ]+001f 0000 0000[       ].*
> +[^:]+:[        ]+0000003f 00000000[    ].*
> --- a/gas/testsuite/gas/riscv/insn.s
> +++ b/gas/testsuite/gas/riscv/insn.s
> @@ -56,5 +56,9 @@ target:
>
>         .insn 0x0001
>         .insn 0x00000013
> +       .insn 0x0000001f
> +       .insn 0x0000003f
>         .insn 0x2, 0x0001
>         .insn 0x4, 0x00000013
> +       .insn 6, 0x0000001f
> +       .insn 8, 0x0000003f
>

      reply	other threads:[~2022-02-25 13:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-25 11:06 Jan Beulich
2022-02-25 13:38 ` Nelson Chu [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=CAJYME4Gyjsxzj-u6KF2NVA7vdPZxyBP+6ZLmco7Mz_16PbU7sA@mail.gmail.com \
    --to=nelson.chu@sifive.com \
    --cc=andrew@sifive.com \
    --cc=binutils@sourceware.org \
    --cc=jbeulich@suse.com \
    --cc=jim.wilson.gcc@gmail.com \
    --cc=palmer@dabbelt.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).