From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id 1108B385802F for ; Wed, 23 Feb 2022 01:47:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1108B385802F From: Tsukasa OI To: Tsukasa OI Cc: binutils@sourceware.org Subject: [PATCH 0/3] RISC-V: Make ISA parser stricter (with code clarity improvement) Date: Wed, 23 Feb 2022 10:47:21 +0900 Message-Id: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TO_EQ_FM_DIRECT_MX, 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: Wed, 23 Feb 2022 01:47:44 -0000 [note: my copyright assignment is already complete on 2022-01-19] Current GNU Toolchain accepts invalid RISC-V ISA string containing invalid underscores (double underscores or trailing underscore). This patchset will reject those. It's not sure that prohibiting those invalid patterns helps users from accident but would be better than nothing. As a part of this patchset, PATCH 1/3 removes unnecessary loop in the ISA string parser (riscv_parse_subset function). It is a requirement to reject invalid trailing underscore after a multi-letter extension but it also improves clarity of the code, regardless of whether invalid underscores are rejected. Removal of Unnecessary Loop (PATCH 1/3): riscv_parse_prefixed_ext function (formerly, riscv_parse_sv_or_non_std_ext function) used to parse multi-letter extension with SINGLE type of prefix ('Z', 'S', likewise...). At the time when this function is created, iterating over prefix type was absolutely necessary. However, commit e601909a3287bf541c6a7d82214bb387d2c76d82 ("RISC-V: Support to parse the multi-letter prefix in the architecture string.") by Nelson Chu changed the situation. Updated riscv_parse_prefixed_ext function now parses all prefix types in a single call and no longer requires a loop (in fact, this function is called only once and "while" loop in riscv_parse_subset function does not actually "loop"). I added trailing underscore-checking code (in PATCH 2/3) at the end of riscv_parse_prefixed_ext function. That means, my PATCH 2/3 assumes that riscv_parse_prefixed_ext is called only once. PATCH 1/3 ensures that riscv_parse_prefixed_ext is called only once and that improves the clarity, even without other patches. Invalid Double Underscores (Rejected in PATCH 2/3): multi-multi extensions (e.g. Zicsr and Zifencei) must be separated by AN underscore. Quoting ISA Manual (version 20191213), 27.6 "Additional Standard Extension Names": > Extensions with the “Z” prefix must be separated from other multi- > letter extensions by AN underscore, e.g., “RV32IMACZicsr_Zifencei”. 27.7 "Supervisor-level Instruction-Set Extensions": > Supervisor-level extensions must be separated from other multi-letter > extensions by AN underscore. 27.10 "Non-Standard Extension Names": > They must be separated from other multi-letter extensions by AN > underscore. Although multiple underscores are not explicitly prohibited to separate single-multi or single-single extension pairs, it's not natural to assume that multiple underscores are allowed here as "AN underscore" is required to avoid “P” extension ambiguity. 27.5 "Underscores": > Because the “P” extension for Packed SIMD can be confused for the > decimal point in a version number, it must be preceded by AN > underscore if it follows a number. Invalid Trailing Underscore (Rejected in PATCH 2/3): This is not allowed in any way because all underscores are intended to be used to separate ISA extensions. Tests (PATCH 3/3): New tests contain invalid ISA strings. Tsukasa OI (3): RISC-V: Remove a loop in the ISA parser RISC-V: Stricter underscore handling for ISA RISC-V: Tests for ISA string handling (underscore) bfd/elfxx-riscv.c | 36 ++++++++++++++----- .../riscv/march-fail-underscore-double-01.d | 3 ++ .../riscv/march-fail-underscore-double-02.d | 3 ++ .../riscv/march-fail-underscore-double-03.d | 3 ++ .../riscv/march-fail-underscore-double-04.d | 3 ++ .../riscv/march-fail-underscore-double-05.d | 3 ++ .../riscv/march-fail-underscore-double-06.d | 3 ++ .../riscv/march-fail-underscore-double-07.d | 3 ++ .../riscv/march-fail-underscore-double-08.d | 3 ++ .../gas/riscv/march-fail-underscore-double.l | 2 ++ .../riscv/march-fail-underscore-trailing-01.d | 3 ++ .../riscv/march-fail-underscore-trailing-02.d | 3 ++ .../riscv/march-fail-underscore-trailing-03.d | 3 ++ .../riscv/march-fail-underscore-trailing-04.d | 3 ++ .../riscv/march-fail-underscore-trailing.l | 2 ++ 15 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-01.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-02.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-03.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-04.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-05.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-06.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-07.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-08.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double.l create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-trailing-01.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-trailing-02.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-trailing-03.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-trailing-04.d create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-trailing.l base-commit: 3a3e333f65483b864bf2624392f8aa4a88c7a498 -- 2.32.0