From patchwork Wed Aug 14 20:25:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitar Dimitrov X-Patchwork-Id: 95868 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8E5443858D34 for ; Wed, 14 Aug 2024 20:26:01 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from server28.superhosting.bg (server28.superhosting.bg [217.174.156.11]) by sourceware.org (Postfix) with ESMTPS id 532013858D20 for ; Wed, 14 Aug 2024 20:25:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 532013858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dinux.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dinux.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 532013858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.174.156.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723667136; cv=none; b=K7+glhdEtddI3SI/wB0tR1hSb7oBLKQZPGXYM6ZbrpERl04FnDhpelpkXHD2mo+NquHKJDDV5hc4TjpdryFrbK+accXLZIa+wAU9MGkDcI8RZcZg2JKY0wYcpgaZiwmM0WKB85f/j1aC3sCnLrBvTUwAKo5oBOFACO3kVAwMUzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723667136; c=relaxed/simple; bh=XYBh3KyNT6jOnDjn08JtWGdxb7qT4oD26N47NKLbFms=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=IbyHhX6Ror7Lrd3AJ4ueCXNABcto4QHRqHtnmYMU9ToqMqK8RDu0B2d/MX2UZsO4sUr5mt82IGdHPV+M57nUOcs+g71izF9R18dlnp5UV/P1sPiUa5Da6F0Tbw+ySMLSddG4xH3ZzmJojnVGI+KGTcCOVBSn8X8NT3YVC34rAhQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dinux.eu; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=R534ErlTLg2EgDgR133y+h5XOaezgtuPc/wKQ8H1maU=; b=PBqdcsoGZyUKlHr7il36PAys14 6TUAyQWEa8R52dKr4NMIigiHpHDDRUbUm9tZY21QKMUKR4xLGUQLzesBnYM/irHGAlcmzG1VtZcqT 2GzDaFXoSihOMMHqlx1b/eLJGUGo1G5hR2idnp8JZeVxJ72HYBN0bimW1e1kSxqP4mXnTRDMF7dtT pcv/TOAVIaE7DCpuf39RlBBg1Op/3J2+g1aLtLgsIqvVlXYsdGpP5kwPWii391/l5U2kbv/dCZWNf a0G0mZq4tVlajsGoDdJQ0hcCl0o3O15eIedHRionNkGd961HXIRp0e50H3989TlG4RLYUYnR9QP4E YYnzOIzg==; Received: from 95-42-20-142.ip.btc-net.bg ([95.42.20.142]:45430 helo=kendros.lan) by server28.superhosting.bg with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1seKYk-00014t-0s; Wed, 14 Aug 2024 23:25:32 +0300 From: Dimitar Dimitrov To: binutils@sourceware.org Cc: Dimitar Dimitrov Subject: [PATCH] gas: pru: Fix trailing whitespace handling Date: Wed, 14 Aug 2024 23:25:21 +0300 Message-ID: <20240814202521.1066938-1-dimitar@dinux.eu> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server28.superhosting.bg X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - dinux.eu X-Get-Message-Sender-Via: server28.superhosting.bg: authenticated_id: dimitar@dinux.eu X-Authenticated-Sender: server28.superhosting.bg: dimitar@dinux.eu X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org With commit 6ae8a30d44f016cafb46a75843b5109316eb1996, arguments followed by a C-style comment ended up with a trailing space. That extra space character confused the PRU register name matching, leading to spurious errors about unrecognized registers. This affected existing code like newlib's setjmp.s for pru. Fix by stripping the trailing whitespace for any argument. Even with 6ae8a30d44f016cafb46a75843b5109316eb1996 reverted, this patch is safe to be applied. Successfully regression-tested with GCC and newlib testsuites for pru-unknown-elf. Signed-off-by: Dimitar Dimitrov --- gas/config/tc-pru.c | 9 ++++++++- gas/testsuite/gas/pru/pr32073.d | 11 +++++++++++ gas/testsuite/gas/pru/pr32073.s | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gas/testsuite/gas/pru/pr32073.d create mode 100644 gas/testsuite/gas/pru/pr32073.s diff --git a/gas/config/tc-pru.c b/gas/config/tc-pru.c index 99a3c1ef88c..f0bbc5b17ef 100644 --- a/gas/config/tc-pru.c +++ b/gas/config/tc-pru.c @@ -1400,7 +1400,7 @@ pru_parse_args (pru_insn_infoS *insn ATTRIBUTE_UNUSED, char *argstr, { char *p; char *end = NULL; - int i; + int i, len; p = argstr; i = 0; bool terminate = false; @@ -1437,6 +1437,13 @@ pru_parse_args (pru_insn_infoS *insn ATTRIBUTE_UNUSED, char *argstr, as_bad (_("too many arguments")); } + /* Strip trailing whitespace. */ + len = strlen (parsed_args[i]); + for (char *temp = parsed_args[i] + len - 1; + len && ISSPACE (*temp); + temp--, len--) + *temp = '\0'; + if (*parsestr == '\0' || (p != NULL && *p == '\0')) terminate = true; ++i; diff --git a/gas/testsuite/gas/pru/pr32073.d b/gas/testsuite/gas/pru/pr32073.d new file mode 100644 index 00000000000..ac353bd8209 --- /dev/null +++ b/gas/testsuite/gas/pru/pr32073.d @@ -0,0 +1,11 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: whitespace parsing + +# Test the whitespace parsing + +.*: +file format elf32-pru + +Disassembly of section .text: +0+0000 <[^>]*> 1300e2e1 mov r1, sp +0+0004 <[^>]*> 1300e2e1 mov r1, sp +0+0008 <[^>]*> 1300e2e1 mov r1, sp diff --git a/gas/testsuite/gas/pru/pr32073.s b/gas/testsuite/gas/pru/pr32073.s new file mode 100644 index 00000000000..ebfab2367a6 --- /dev/null +++ b/gas/testsuite/gas/pru/pr32073.s @@ -0,0 +1,6 @@ +# Source file used to test the whitespace parsing. + +foo: + mov r1 /* comment */, r2 /* ... */ + mov r1 /* comment */, r2 /* ... */ + mov /* x */ r1 /* comment */ , r2 /* ... */