From patchwork Wed Jun 12 10:17:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cai X-Patchwork-Id: 91963 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 04DA038708D4 for ; Wed, 12 Jun 2024 10:17:57 +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 877AC3870870 for ; Wed, 12 Jun 2024 10:17:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 877AC3870870 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 877AC3870870 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=1718187450; cv=none; b=UUJ9ulvRNdUdHbg4+yUnF7p8wQs+E4MyU53akNQRcREKfO1rHt1pUjfC4FjzgBrFWedTiap0dkdbbHuoqlDhxr1GL1w82KaSSctBOdDvbX0v7E0RP6mB5xmmdkfvUm0R0b9rrkH+ZpsPQdk1AHTrXQO27LUO/9bF/vBbXytA2Xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718187450; c=relaxed/simple; bh=KlN7VInVRaBeVdwwYztplNL9Uw6pITm2alb4Bop09NI=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=dz48hx3DpcPCK9i3mReoREea7Lth9qyJ/vhw1+AlTXWXEY5S7Uw9dCrOM30CYyKrMKxBHC54hRWsyPT3lbZfTd7DTQ/p9Q3pvFzx6UAlJ3OoKDV6HcRnq3W5Q2bWRPLi7wU2mHaKhsZN2PUl5Q8AdPTZR+XmYGtI1ogaWH1p4rY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8CxyOm0dWlmKfMFAA--.11364S3; Wed, 12 Jun 2024 18:17:24 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxPMezdWlmxAcdAA--.6338S4; Wed, 12 Jun 2024 18:17:23 +0800 (CST) From: Lulu Cai To: binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, mengqinggang@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com, luweining@loongson.cn, hejinyang@loongson.cn, Lulu Cai Subject: [PATCH v2] LoongArch: add .option directive Date: Wed, 12 Jun 2024 18:17:22 +0800 Message-Id: <20240612101722.3736057-1-cailulu@loongson.cn> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxPMezdWlmxAcdAA--.6338S4 X-CM-SenderInfo: xfdlz3tox6z05rqj20fqof0/1tbiAQAGB2Zo-xQExAABsk X-Coremail-Antispam: 1Uk129KBj93XoW3JrWrZryktw13Wr1fAw4UWrX_yoWxJFW5pr yUZF12yFW8G3Z7Xr1UG3WrXw1fAws7KrWagFWftr4I9rsrtryjy348trZxWFW3Aw48C34S vF4rZ3WUWF1qy3XCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUvjb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU XVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AK xVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr 1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxU2MKZDUUU U X-Spam-Status: No, score=-13.2 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org In some cases we may want to use different options only for certain assembly, so the .option directive is added to control the assembler options. .option can accept 4 parameters: push pop Pushes or pops the current option stack. They limit the scope of option changes so that they do not affect other parts of the assembly file. relax norelax Enables or disables relaxation. --- Changes from v1: * Add and modify test cases. V1 link: https://sourceware.org/pipermail/binutils/2024-May/134440.html --- gas/config/tc-loongarch.c | 59 +++++++++++++++++++ gas/testsuite/gas/loongarch/loongarch.exp | 1 + .../gas/loongarch/pseudo_op_option.d | 36 +++++++++++ .../gas/loongarch/pseudo_op_option.s | 19 ++++++ .../gas/loongarch/pseudo_op_option_fail.l | 2 + .../gas/loongarch/pseudo_op_option_fail.s | 2 + 6 files changed, 119 insertions(+) create mode 100644 gas/testsuite/gas/loongarch/pseudo_op_option.d create mode 100644 gas/testsuite/gas/loongarch/pseudo_op_option.s create mode 100644 gas/testsuite/gas/loongarch/pseudo_op_option_fail.l create mode 100644 gas/testsuite/gas/loongarch/pseudo_op_option_fail.s diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index e7de9d86313..5ca33c6e2e8 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -541,6 +541,64 @@ s_dtprel (int bytes) demand_empty_rest_of_line (); } +struct LARCH_option_stack +{ + struct LARCH_option_stack *next; + struct loongarch_ASEs_option options; +}; + +static struct LARCH_option_stack *LARCH_opts_stack = NULL; + +/* Handle the .option pseudo-op. + The alignment of .align is done by R_LARCH_ALIGN at link time. + If the .align directive is within the range controlled by + .option norelax, that is, relax is turned off, R_LARCH_ALIGN + cannot be generated, which may cause ld to be unable to handle + the alignment. */ +static void +s_loongarch_option (int x ATTRIBUTE_UNUSED) +{ + char *name = input_line_pointer, ch; + while (!is_end_of_line[(unsigned char) *input_line_pointer]) + ++input_line_pointer; + ch = *input_line_pointer; + *input_line_pointer = '\0'; + + if (strcmp (name, "relax") == 0) + LARCH_opts.relax = 1; + else if (strcmp (name, "norelax") == 0) + LARCH_opts.relax = 0; + else if (strcmp (name, "push") == 0) + { + struct LARCH_option_stack *s; + + s = XNEW (struct LARCH_option_stack); + s->next = LARCH_opts_stack; + s->options = LARCH_opts; + LARCH_opts_stack = s; + } + else if (strcmp (name, "pop") == 0) + { + struct LARCH_option_stack *s; + + s = LARCH_opts_stack; + if (s == NULL) + as_bad (_(".option pop with no .option push")); + else + { + LARCH_opts_stack = s->next; + LARCH_opts = s->options; + free (s); + } + } + else + { + as_warn (_("unrecognized .option directive: %s"), name); + } + *input_line_pointer = ch; + demand_empty_rest_of_line (); +} + static const pseudo_typeS loongarch_pseudo_table[] = { { "dword", cons, 8 }, @@ -548,6 +606,7 @@ static const pseudo_typeS loongarch_pseudo_table[] = { "half", cons, 2 }, { "dtprelword", s_dtprel, 4 }, { "dtpreldword", s_dtprel, 8 }, + { "option", s_loongarch_option, 0}, { NULL, NULL, 0 }, }; diff --git a/gas/testsuite/gas/loongarch/loongarch.exp b/gas/testsuite/gas/loongarch/loongarch.exp index 8cfe0aba5eb..40d937f1c4b 100644 --- a/gas/testsuite/gas/loongarch/loongarch.exp +++ b/gas/testsuite/gas/loongarch/loongarch.exp @@ -35,5 +35,6 @@ if [istarget loongarch*-*-*] { if [istarget loongarch64-*-*] { run_list_test "illegal-operand" + run_list_test "pseudo_op_option_fail" } } diff --git a/gas/testsuite/gas/loongarch/pseudo_op_option.d b/gas/testsuite/gas/loongarch/pseudo_op_option.d new file mode 100644 index 00000000000..53921a1ebcb --- /dev/null +++ b/gas/testsuite/gas/loongarch/pseudo_op_option.d @@ -0,0 +1,36 @@ +#as: -mrelax +#objdump: -dr +#skip: loongarch32-*-* + +.*: file format .* + + +Disassembly of section .text: + +0.* <.text>: + 0: 1a000004 pcalau12i \$a0, 0 + 0: R_LARCH_PCALA_HI20 x + 0: R_LARCH_RELAX \*ABS\* + 4: 02c00084 addi.d \$a0, \$a0, 0 + 4: R_LARCH_PCALA_LO12 x + 4: R_LARCH_RELAX \*ABS\* + 8: 1a000004 pcalau12i \$a0, 0 + 8: R_LARCH_PCALA_HI20 x + c: 02c00084 addi.d \$a0, \$a0, 0 + c: R_LARCH_PCALA_LO12 x + 10: 1a000004 pcalau12i \$a0, 0 + 10: R_LARCH_PCALA_HI20 x + 10: R_LARCH_RELAX \*ABS\* + 14: 02c00084 addi.d \$a0, \$a0, 0 + 14: R_LARCH_PCALA_LO12 x + 14: R_LARCH_RELAX \*ABS\* + 18: 1a000004 pcalau12i \$a0, 0 + 18: R_LARCH_PCALA_HI20 x + 1c: 02c00084 addi.d \$a0, \$a0, 0 + 1c: R_LARCH_PCALA_LO12 x + 20: 1a000004 pcalau12i \$a0, 0 + 20: R_LARCH_PCALA_HI20 x + 20: R_LARCH_RELAX \*ABS\* + 24: 02c00084 addi.d \$a0, \$a0, 0 + 24: R_LARCH_PCALA_LO12 x + 24: R_LARCH_RELAX \*ABS\* diff --git a/gas/testsuite/gas/loongarch/pseudo_op_option.s b/gas/testsuite/gas/loongarch/pseudo_op_option.s new file mode 100644 index 00000000000..f21b72631a3 --- /dev/null +++ b/gas/testsuite/gas/loongarch/pseudo_op_option.s @@ -0,0 +1,19 @@ +# Gas enables relax by default. +# Push and pop can be nested, and each pop restores the options before +# the most recent push. + .text +.L1: + la.pcrel $a0,x + + .option push + .option norelax + la.pcrel $a0,x + + .option push + .option relax + la.pcrel $a0,x + .option pop + + la.pcrel $a0,x + .option pop + la.pcrel $a0,x diff --git a/gas/testsuite/gas/loongarch/pseudo_op_option_fail.l b/gas/testsuite/gas/loongarch/pseudo_op_option_fail.l new file mode 100644 index 00000000000..ffb9a72e46c --- /dev/null +++ b/gas/testsuite/gas/loongarch/pseudo_op_option_fail.l @@ -0,0 +1,2 @@ +.*: Assembler messages: +.*: Error: \.option pop with no \.option push diff --git a/gas/testsuite/gas/loongarch/pseudo_op_option_fail.s b/gas/testsuite/gas/loongarch/pseudo_op_option_fail.s new file mode 100644 index 00000000000..e368cdbab33 --- /dev/null +++ b/gas/testsuite/gas/loongarch/pseudo_op_option_fail.s @@ -0,0 +1,2 @@ + .text + .option pop