Message ID | 20231210094132.3236040-1-mengqinggang@loongson.cn |
---|---|
State | Accepted |
Headers |
Return-Path: <binutils-bounces+ouuuleilei=gmail.com@sourceware.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6438775vqy; Sun, 10 Dec 2023 01:41:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOq+Lw6qjb4Ix9ycLynPn8DcWEwXlY4i0ymAL8070bYpDxowoVcN5WUmHbKoeujYlsJRJW X-Received: by 2002:a05:6214:1930:b0:67a:a721:f342 with SMTP id es16-20020a056214193000b0067aa721f342mr3039937qvb.130.1702201304109; Sun, 10 Dec 2023 01:41:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702201304; cv=pass; d=google.com; s=arc-20160816; b=flRcSfyl5JtUAhJVqDLTvC+X2kNWIcsLt7HZHnn5UfYwZseEVVJIkts8K33VvBWM9V 2m93XviahshaCRw6Gaee5W4vq/jJdXaTLAn5EBLM5alAj54M6CpapgbrZR91UaTW3YNd oPD1kdXVUa43cBDw7I1QWNytlWF38BsBXdBXxpCwJfiFMhiShsIau7JmWIIE/nn75Iho mbJKCrFczFLmDfYa61a1IDyCBzzj7L9a6IM3B3TO+VZZKw64Cgo9BlBqzCq/6uAjG7DJ RL5K3RpeMQe70ZkRV77wwx8qyw03tPYZNR72pYuBDT1JrEhMqF3gNl+3m61IVaBk6S4+ 5ujQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=IWF+R/4mIkDzJkushlXCCI3bUHYhZecpfwQrNRaEfGo=; fh=IjBrBzj0HafC7UFRTZLmdEImc4JDKXFiCrZAu8bdkFw=; b=oMOSUH8luWx3J+AMgi150n+yrcfznr7YA7XlHULNMCL/SRA5AZKAzFjOiDWXD7MC0h KN2NGF32XShnjEVa7joaQm4uV+SPt1/GVhhogeBypb4KdfuGKED1JFxWic3AvCskWmJo uHGGryXUUo8wLq1vP3JYc9TxPVPsRYF1LZ3W7o96IPkoEomt/t2ok8Tfli4uPcSfW1B/ 9IuZBxmEfD+PRE5Pz/7/QvRCOoCQQ74UA0ePmaohYz/6p09uvCBADvu0fFfyH7u4CQ7O 5zhdiBFS++o9IyypYUXI2Vmlw+sFiym6ahUFDgEETuHT3QCzdCIP4eDETI2E8YEFfRs3 eHVQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r17-20020a0cf811000000b0067a9a7a845esi6081156qvn.174.2023.12.10.01.41.44 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 01:41:44 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB4F8385840A for <ouuuleilei@gmail.com>; Sun, 10 Dec 2023 09:41:43 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id A2D0E3858D1E for <binutils@sourceware.org>; Sun, 10 Dec 2023 09:41:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2D0E3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A2D0E3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702201300; cv=none; b=APIIj1ppPRsfSBtyNEWHeads9irZNYeuBUYnE+AQswkt7wcwkgMV+aUWt29OF/tLlkNCgcFwabjo9ptcW+oBEu/43W+P6QEyeObjNz2m1cY/VTbLwEsyufqtwDEaxg8Wu5jRaXSuZTPj6oaeJ1I26zGHhpxgMos5eWGKTSOvdeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702201300; c=relaxed/simple; bh=Tw9ZvMWu0eJlQxanJ62jwDTiJZdCCYSpnauSdX8uSBk=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=M6hbTRCwBU0PpoyvTlXN6r9lxxeOTPfTcrS7ZBXcu7fXmyGR75ODgAM8Suj7dMzYDF1Oljy+EWWtl122CaZSTYZi/BCG9RyXZnSMSE+cOFkKlHapwKQph43isstUc+pNJMGwSVb7REmbsd6hY0YQTRLCJIJ8WMWS7LV8s5igRVI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8Cx7+vOh3VlblJAAA--.62289S3; Sun, 10 Dec 2023 17:41:35 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxXNzOh3VlSlRaAA--.2778S2; Sun, 10 Dec 2023 17:41:34 +0800 (CST) From: mengqinggang <mengqinggang@loongson.cn> To: binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, liuzhensong@loongson.cn, cailulu@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com, luweining@loongson.cn, wanglei@loongson.cn, hejinyang@loongson.cn, mengqinggang <mengqinggang@loongson.cn> Subject: [PATCH v1] LoongArch: Add support for <b ".L1"> and <beq, $t0, $t1, ".L1"> Date: Sun, 10 Dec 2023 17:41:32 +0800 Message-Id: <20231210094132.3236040-1-mengqinggang@loongson.cn> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8AxXNzOh3VlSlRaAA--.2778S2 X-CM-SenderInfo: 5phqw15lqjwttqj6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoW7AFWkGr4kWF17CFyrJw1DArc_yoW8AFykpF y8ZF4SkF4kKFs7Jrnru3y3XFn7Ja1xWF4a9a1ftrn2yFn7Xry0v34rt34fXFW3t3yYk34F qrs5WFWjqF18JwcCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUk0b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4j6r4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc 02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAF wI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7V AKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6x IIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x 0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxU7XTmDUUUU X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, 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 <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784887434718470558 X-GMAIL-MSGID: 1784887434718470558 |
Series |
[v1] LoongArch: Add support for <b ".L1"> and <beq, $t0, $t1, ".L1">
|
|
Checks
Context | Check | Description |
---|---|---|
snail/binutils-gdb-check | success | Github commit url |
Commit Message
mengqinggang
Dec. 10, 2023, 9:41 a.m. UTC
Support symbol names enclosed in double quotation marks. --- .../gas/loongarch/double_quotation_marks.d | 13 +++++++++++++ .../gas/loongarch/double_quotation_marks.s | 2 ++ opcodes/loongarch-coder.c | 7 +++++++ 3 files changed, 22 insertions(+) create mode 100644 gas/testsuite/gas/loongarch/double_quotation_marks.d create mode 100644 gas/testsuite/gas/loongarch/double_quotation_marks.s
Comments
On Sun, Dec 10, 2023 at 05:41:32PM +0800, mengqinggang wrote: > Support symbol names enclosed in double quotation marks. > --- a/opcodes/loongarch-coder.c > +++ b/opcodes/loongarch-coder.c > @@ -264,6 +264,13 @@ loongarch_split_args_by_comma (char *args, const char *arg_strs[]) > else > *args = '\0', arg_strs[num++] = args + 1; > } > + > + if (*(args-1) == '"') > + { > + *(args-1) = '\0'; > + arg_strs[num-1] = arg_strs[num-1] + 1; > + } > + > arg_strs[num] = NULL; > return num; > } This results in buffer overflows running the testsuite. /build/gas-san/loongarch32-elf/gas/testsuite/../../binutils/objdump -dr tmpdir/64_pcrel.o > tmpdir/dump.out Executing on host: sh -c {/build/gas-san/loongarch32-elf/gas/testsuite/../../binutils/objdump -dr tmpdir/64_pcrel.o > tmpdir/dump.out 2>dump.tmp} /dev/null (timeout = 300) spawn [open ...] exited abnormally with 1, output:================================================================= ==3602547==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000006f at pc 0x5600d00b56c0 bp 0x7ffe37855240 sp 0x7ffe37855230 READ of size 1 at 0x60200000006f thread T0 #0 0x5600d00b56bf in loongarch_split_args_by_comma /home/alan/src/binutils-gdb/opcodes/loongarch-coder.c:268
On Thu, Dec 14, 2023 at 12:06:49PM +1030, Alan Modra wrote: > On Sun, Dec 10, 2023 at 05:41:32PM +0800, mengqinggang wrote: > > Support symbol names enclosed in double quotation marks. > > > --- a/opcodes/loongarch-coder.c > > +++ b/opcodes/loongarch-coder.c > > @@ -264,6 +264,13 @@ loongarch_split_args_by_comma (char *args, const char *arg_strs[]) > > else > > *args = '\0', arg_strs[num++] = args + 1; > > } > > + > > + if (*(args-1) == '"') > > + { > > + *(args-1) = '\0'; > > + arg_strs[num-1] = arg_strs[num-1] + 1; > > + } > > + > > arg_strs[num] = NULL; > > return num; > > } > > This results in buffer overflows running the testsuite. This fixes the buffer overflow added in commit 22b78fad28, and a few other problems. Committed. * loongarch-coder.c (loongarch_split_args_by_comma): Don't overflow buffer when args == "". Don't remove unbalanced quotes. Don't trim last arg if max number of args exceeded. diff --git a/opcodes/loongarch-coder.c b/opcodes/loongarch-coder.c index 672a468b3f4..b68352769ca 100644 --- a/opcodes/loongarch-coder.c +++ b/opcodes/loongarch-coder.c @@ -255,22 +255,24 @@ loongarch_split_args_by_comma (char *args, const char *arg_strs[]) size_t num = 0; if (*args) - arg_strs[num++] = args; - for (; *args; args++) - if (*args == ',') - { - if (MAX_ARG_NUM_PLUS_2 - 1 == num) - break; - else - *args = '\0', arg_strs[num++] = args + 1; - } - - if (*(args-1) == '"') { - *(args-1) = '\0'; - arg_strs[num-1] = arg_strs[num-1] + 1; - } + arg_strs[num++] = args; + for (; *args; args++) + if (*args == ',') + { + if (MAX_ARG_NUM_PLUS_2 - 1 == num) + goto out; + *args = '\0'; + arg_strs[num++] = args + 1; + } + if (*(args - 1) == '"' && *arg_strs[num - 1] == '"') + { + *(args - 1) = '\0'; + arg_strs[num - 1] += 1; + } + } + out: arg_strs[num] = NULL; return num; }
This adds some extra features 1) All args have double-quotes removed, not just the last one, and 2) Commas now are allowed as part of a double-quote string. I am not sure this change in behaviour is wanted (ie. it's not an obvious bug fix to me), so I'll leave it to the loongarch maintainers to decide whether this patch goes in. * loongarch-coder.c (loongarch_split_args_by_comma): Support quotes in more than just last arg. Commas inside quotes are not arg delimiters. diff --git a/opcodes/loongarch-coder.c b/opcodes/loongarch-coder.c index b68352769ca..1bff3b005f9 100644 --- a/opcodes/loongarch-coder.c +++ b/opcodes/loongarch-coder.c @@ -18,6 +18,7 @@ along with this program; see the file COPYING3. If not, see <http://www.gnu.org/licenses/>. */ #include "sysdep.h" +#include <stdbool.h> #include "opcode/loongarch.h" int @@ -256,12 +257,20 @@ loongarch_split_args_by_comma (char *args, const char *arg_strs[]) if (*args) { + bool inquote = false; arg_strs[num++] = args; for (; *args; args++) - if (*args == ',') + if (*args == '"') + inquote = !inquote; + else if (*args == ',' && !inquote) { if (MAX_ARG_NUM_PLUS_2 - 1 == num) goto out; + if (*(args - 1) == '"' && *arg_strs[num] == '"') + { + *(args - 1) = '\0'; + arg_strs[num] += 1; + } *args = '\0'; arg_strs[num++] = args + 1; }
To consistent with other architectures, we don't need to support quoted registers. The second feature is a good idea and it can be merged. Thank you very much. 在 2023/12/25 上午8:01, Alan Modra 写道: > This adds some extra features > 1) All args have double-quotes removed, not just the last one, and > 2) Commas now are allowed as part of a double-quote string. > > I am not sure this change in behaviour is wanted (ie. it's not an > obvious bug fix to me), so I'll leave it to the loongarch maintainers > to decide whether this patch goes in. > > * loongarch-coder.c (loongarch_split_args_by_comma): Support > quotes in more than just last arg. Commas inside quotes are > not arg delimiters. > > diff --git a/opcodes/loongarch-coder.c b/opcodes/loongarch-coder.c > index b68352769ca..1bff3b005f9 100644 > --- a/opcodes/loongarch-coder.c > +++ b/opcodes/loongarch-coder.c > @@ -18,6 +18,7 @@ > along with this program; see the file COPYING3. If not, > see <http://www.gnu.org/licenses/>. */ > #include "sysdep.h" > +#include <stdbool.h> > #include "opcode/loongarch.h" > > int > @@ -256,12 +257,20 @@ loongarch_split_args_by_comma (char *args, const char *arg_strs[]) > > if (*args) > { > + bool inquote = false; > arg_strs[num++] = args; > for (; *args; args++) > - if (*args == ',') > + if (*args == '"') > + inquote = !inquote; > + else if (*args == ',' && !inquote) > { > if (MAX_ARG_NUM_PLUS_2 - 1 == num) > goto out; > + if (*(args - 1) == '"' && *arg_strs[num] == '"') > + { > + *(args - 1) = '\0'; > + arg_strs[num] += 1; > + } > *args = '\0'; > arg_strs[num++] = args + 1; > } >
diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.d b/gas/testsuite/gas/loongarch/double_quotation_marks.d new file mode 100644 index 00000000000..a42534b94a4 --- /dev/null +++ b/gas/testsuite/gas/loongarch/double_quotation_marks.d @@ -0,0 +1,13 @@ +#as: +#objdump: -dr + +.*:[ ]+file format .* + + +Disassembly of section .text: + +.* <.text>: +[ ]+0:[ ]+50000000[ ]+b[ ]+0[ ]+# 0x0 +[ ]+0: R_LARCH_B26[ ]+.L1 +[ ]+4:[ ]+5800018d[ ]+beq[ ]+\$t0, \$t1, 0[ ]+# 0x4 +[ ]+4: R_LARCH_B16[ ]+.L1 diff --git a/gas/testsuite/gas/loongarch/double_quotation_marks.s b/gas/testsuite/gas/loongarch/double_quotation_marks.s new file mode 100644 index 00000000000..f8b63074150 --- /dev/null +++ b/gas/testsuite/gas/loongarch/double_quotation_marks.s @@ -0,0 +1,2 @@ +b ".L1" +beq $r12, $r13, ".L1" diff --git a/opcodes/loongarch-coder.c b/opcodes/loongarch-coder.c index a68ae1c3106..672a468b3f4 100644 --- a/opcodes/loongarch-coder.c +++ b/opcodes/loongarch-coder.c @@ -264,6 +264,13 @@ loongarch_split_args_by_comma (char *args, const char *arg_strs[]) else *args = '\0', arg_strs[num++] = args + 1; } + + if (*(args-1) == '"') + { + *(args-1) = '\0'; + arg_strs[num-1] = arg_strs[num-1] + 1; + } + arg_strs[num] = NULL; return num; }