From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7867) id 648EF38708A4; Tue, 18 Jun 2024 02:41:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 648EF38708A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1718678495; bh=U3LkbdCZWLtm0JsjlurcP89muNugPNbSs4AnsKh1whM=; h=From:To:Subject:Date:From; b=EoD4iRJkEmdOyj1VZr9tm4kNdh3DuZZZLTbTjpGWCT+MUSOtrpTeKWQt7f1k4gQ99 fFL0XbjrstBQ4VhnRvC0zZYKHaYi2dtzVVEcPqbodzERSzCxyBstGiZhDRSJJNNaYm lF7yEjFpRbMsGklyfph/euh+1byWm5nXlpfyrPEo= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: liu & zhensong To: binutils-cvs@sourceware.org Subject: [binutils-gdb] LoongArch: add .option directive X-Act-Checkin: binutils-gdb X-Git-Author: Lulu Cai X-Git-Refname: refs/heads/master X-Git-Oldrev: 6a4f078b5b8b442f474a8af804c316783d216a4e X-Git-Newrev: 8864c4afdf2ff75e7edda6075286e07b9714ce12 Message-Id: <20240618024135.648EF38708A4@sourceware.org> Date: Tue, 18 Jun 2024 02:41:35 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8864c4afdf2f= f75e7edda6075286e07b9714ce12 commit 8864c4afdf2ff75e7edda6075286e07b9714ce12 Author: Lulu Cai Date: Tue May 21 10:14:27 2024 +0800 LoongArch: add .option directive =20 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. =20 .option can accept 4 parameters: =20 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. =20 relax norelax Enables or disables relaxation. Diff: --- gas/config/tc-loongarch.c | 59 ++++++++++++++++++= ++++ gas/testsuite/gas/loongarch/loongarch.exp | 1 + gas/testsuite/gas/loongarch/pseudo_op_option.d | 36 +++++++++++++ gas/testsuite/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(+) 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 (); } =20 +struct LARCH_option_stack +{ + struct LARCH_option_stack *next; + struct loongarch_ASEs_option options; +}; + +static struct LARCH_option_stack *LARCH_opts_stack =3D 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 =3D input_line_pointer, ch; + while (!is_end_of_line[(unsigned char) *input_line_pointer]) + ++input_line_pointer; + ch =3D *input_line_pointer; + *input_line_pointer =3D '\0'; + + if (strcmp (name, "relax") =3D=3D 0) + LARCH_opts.relax =3D 1; + else if (strcmp (name, "norelax") =3D=3D 0) + LARCH_opts.relax =3D 0; + else if (strcmp (name, "push") =3D=3D 0) + { + struct LARCH_option_stack *s; + + s =3D XNEW (struct LARCH_option_stack); + s->next =3D LARCH_opts_stack; + s->options =3D LARCH_opts; + LARCH_opts_stack =3D s; + } + else if (strcmp (name, "pop") =3D=3D 0) + { + struct LARCH_option_stack *s; + + s =3D LARCH_opts_stack; + if (s =3D=3D NULL) + as_bad (_(".option pop with no .option push")); + else + { + LARCH_opts_stack =3D s->next; + LARCH_opts =3D s->options; + free (s); + } + } + else + { + as_warn (_("unrecognized .option directive: %s"), name); + } + *input_line_pointer =3D ch; + demand_empty_rest_of_line (); +} + static const pseudo_typeS loongarch_pseudo_table[] =3D { { "dword", cons, 8 }, @@ -548,6 +606,7 @@ static const pseudo_typeS loongarch_pseudo_table[] =3D { "half", cons, 2 }, { "dtprelword", s_dtprel, 4 }, { "dtpreldword", s_dtprel, 8 }, + { "option", s_loongarch_option, 0}, { NULL, NULL, 0 }, }; =20 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*-*-*] { =20 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/test= suite/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/test= suite/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