From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2e.google.com (mail-vs1-xe2e.google.com [IPv6:2607:f8b0:4864:20::e2e]) by sourceware.org (Postfix) with ESMTPS id B2FEC3858D35 for ; Fri, 25 Feb 2022 13:38:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B2FEC3858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-vs1-xe2e.google.com with SMTP id u10so5512462vsu.13 for ; Fri, 25 Feb 2022 05:38:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ahYILYL6jrCcr/E6YKNXgdzQf5qt+NJvv/yFcDhNluQ=; b=WzN9d+Wh2yFC4dafXtYp1He9NOV/6R9VJB/Lyo7ii3n9/RbvD1r++XfcL/k2SySnvb m/EVTM1niVd00X4JQchsvH1XuSMO7XVy0NGjYmHp6U0qhnYQkQHaeG4OGjMgW7WAlEe/ QFVuapmzqWtSWX5vLaWT0hmK7ljQYEJaI6odCp/LuphlX9elrK2BvHJCX0aAJpRGNRVx yfk88Riw4wAptcPhQKW+2V94/LS6OiT3JvPP0S1M5lpBo9Z3ZLhcp9LZ37sSnAkDOD7c zpaulSkwIazpYVadUNblGYfyB4TQxTulB+08RviKe/Y1z+2o8CVZi+wq871UAW6GYe2c mPZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ahYILYL6jrCcr/E6YKNXgdzQf5qt+NJvv/yFcDhNluQ=; b=5WMqjOcQuu3HQNCGitNdUCV3VZZtTjPkhckSf9vNDDukOkBef+KRbvUg4srBnQTVZ0 xXoqAYyEIOshxg9JzyJ1M8c0pnO6whlJsFvV1LTboiZeRUTvhx1H+TbhcnE65DqH1NIU 8tLE5IETecNJ5VIuYp41qziBy5wHdaJwRNT/c13qwtAUXmcDoiwvUbElK0KXefGImZVn umQhG4B+6YSdfIxiY7abUL3B3E6PC7J6Zq0W1cGycZDjTRdFmumNjxE9RtpdryftOqMH av/CQWvu91GKn9E0lCyZ8W1W44rGqjA4+XXJ3kc8COkpgwurFlqALoKL4dZPl9h1jOO7 RbHw== X-Gm-Message-State: AOAM5314gcIZgxPOa77pFp1ejUFyKEj1MtGuRKpjg6Pe5D3Rh9mAk6xN yeOhJx2jk6uKXh6L6A1cPfxxpLBymYru/RHmujtlAw== X-Google-Smtp-Source: ABdhPJyB204IVaBu/xkEAe09JG4jk0DxM+lv4aY3ujoxynjvTJ1cEDLqsvrMnFxsu9bsPvOX3x5kc/Uy6eY79BWHLao= X-Received: by 2002:a05:6102:34d6:b0:31b:91c5:41f4 with SMTP id a22-20020a05610234d600b0031b91c541f4mr3085649vst.36.1645796327281; Fri, 25 Feb 2022 05:38:47 -0800 (PST) MIME-Version: 1.0 References: <6d807b33-5409-b728-7d1e-9fef8a16490b@suse.com> In-Reply-To: <6d807b33-5409-b728-7d1e-9fef8a16490b@suse.com> From: Nelson Chu Date: Fri, 25 Feb 2022 21:38:36 +0800 Message-ID: Subject: Re: [PATCH] RISC-V: make .insn actually work for 64-bit insns To: Jan Beulich Cc: Binutils , Palmer Dabbelt , Andrew Waterman , Jim Wilson Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Feb 2022 13:38:49 -0000 On Fri, Feb 25, 2022 at 7:06 PM Jan Beulich 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 >