From 5d0ed830d362fb8bb200a4f52bf973ba30920802 Mon Sep 17 00:00:00 2001 From: Nelson Chu Date: Fri, 21 May 2021 15:40:33 +0800 Subject: [PATCH] RISC-V: PR25212, Report errors for invalid march and mabi combinations. This patch clarify the following invalid combinations of march and mabi, * ilp32f/lp64f abi without f extension. * ilp32d/lp64d abi without d extension. * ilp32q/lp64q abi without q extension. * e extension with any abi except ilp32e GNU assembler reports errors when finding the above invalid combinations. But LLVM-MC reports warnings and ignores these invalid cases. It help to set the correct ilp32/lp64/ilp32e abi according to rv32/rv64/rve. This looks good and convenient, so perhaps we can do the same things. However, if you don't set the mabi, GNU assembler also try to set the suitable ABI according to march/elf-attribute. Compared to LLVM-MC, we will choose double/quad abi if d/f extension is set. gas/ PR 25212 * config/tc-riscv.c (riscv_set_abi_by_arch): If -mabi isn't set, we will choose ilp32e abi for rv32e. Besides, report errors for the invalid march and mabi combinations. * testsuite/gas/riscv/mabi-attr-rv32e.s: New testcase. Only accept ilp32e abi for rve extension. * testsuite/gas/riscv/mabi-fail-rv32e-lp64f.d: Likewise. * testsuite/gas/riscv/mabi-fail-rv32e-lp64f.l: Likewise. * testsuite/gas/riscv/mabi-fail-rv32e-lp64d.d: Likewise. * testsuite/gas/riscv/mabi-fail-rv32e-lp64d.l: Likewise. * testsuite/gas/riscv/mabi-fail-rv32e-lp64d.q: Likewise. * testsuite/gas/riscv/mabi-fail-rv32e-lp64d.q: Likewise. Renamed all mabi testcases to their march-mabi settings. --- gas/ChangeLog | 16 ++++++++++++++++ gas/config/tc-riscv.c | 18 ++++++++++++++++++ gas/testsuite/gas/riscv/mabi-attr-rv32e.s | 1 + .../{mabi-attr-01.s => mabi-attr-rv32i.s} | 0 .../{mabi-attr-02.s => mabi-attr-rv32id.s} | 0 .../{mabi-attr-03.s => mabi-attr-rv64iq.s} | 0 gas/testsuite/gas/riscv/mabi-fail-01.d | 3 --- gas/testsuite/gas/riscv/mabi-fail-02.d | 3 --- .../gas/riscv/mabi-fail-rv32e-lp64d.d | 3 +++ .../gas/riscv/mabi-fail-rv32e-lp64d.l | 4 ++++ .../gas/riscv/mabi-fail-rv32e-lp64f.d | 3 +++ .../gas/riscv/mabi-fail-rv32e-lp64f.l | 4 ++++ .../gas/riscv/mabi-fail-rv32e-lp64q.d | 3 +++ .../gas/riscv/mabi-fail-rv32e-lp64q.l | 4 ++++ gas/testsuite/gas/riscv/mabi-fail-rv32i-lp64.d | 3 +++ .../{mabi-fail-01.l => mabi-fail-rv32i-lp64.l} | 0 .../gas/riscv/mabi-fail-rv64iq-ilp32.d | 3 +++ ...mabi-fail-02.l => mabi-fail-rv64iq-ilp32.l} | 0 ...i-attr-01a.d => mabi-noabi-attr-rv32i-01.d} | 4 ++-- ...i-attr-01b.d => mabi-noabi-attr-rv32i-02.d} | 4 ++-- ...-attr-02a.d => mabi-noabi-attr-rv32id-01.d} | 2 +- ...-attr-02b.d => mabi-noabi-attr-rv32id-02.d} | 2 +- ...-attr-03a.d => mabi-noabi-attr-rv64iq-01.d} | 2 +- ...-attr-03b.d => mabi-noabi-attr-rv64iq-02.d} | 2 +- ...abi-march-01.d => mabi-noabi-march-rv32i.d} | 0 ...bi-march-02.d => mabi-noabi-march-rv32id.d} | 2 +- ...bi-march-03.d => mabi-noabi-march-rv64iq.d} | 2 +- 27 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 gas/testsuite/gas/riscv/mabi-attr-rv32e.s rename gas/testsuite/gas/riscv/{mabi-attr-01.s => mabi-attr-rv32i.s} (100%) rename gas/testsuite/gas/riscv/{mabi-attr-02.s => mabi-attr-rv32id.s} (100%) rename gas/testsuite/gas/riscv/{mabi-attr-03.s => mabi-attr-rv64iq.s} (100%) delete mode 100644 gas/testsuite/gas/riscv/mabi-fail-01.d delete mode 100644 gas/testsuite/gas/riscv/mabi-fail-02.d create mode 100644 gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64d.d create mode 100644 gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64d.l create mode 100644 gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64f.d create mode 100644 gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64f.l create mode 100644 gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64q.d create mode 100644 gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64q.l create mode 100644 gas/testsuite/gas/riscv/mabi-fail-rv32i-lp64.d rename gas/testsuite/gas/riscv/{mabi-fail-01.l => mabi-fail-rv32i-lp64.l} (100%) create mode 100644 gas/testsuite/gas/riscv/mabi-fail-rv64iq-ilp32.d rename gas/testsuite/gas/riscv/{mabi-fail-02.l => mabi-fail-rv64iq-ilp32.l} (100%) rename gas/testsuite/gas/riscv/{mabi-noabi-attr-01a.d => mabi-noabi-attr-rv32i-01.d} (58%) rename gas/testsuite/gas/riscv/{mabi-noabi-attr-01b.d => mabi-noabi-attr-rv32i-02.d} (71%) rename gas/testsuite/gas/riscv/{mabi-noabi-attr-02a.d => mabi-noabi-attr-rv32id-01.d} (82%) rename gas/testsuite/gas/riscv/{mabi-noabi-attr-02b.d => mabi-noabi-attr-rv32id-02.d} (86%) rename gas/testsuite/gas/riscv/{mabi-noabi-attr-03a.d => mabi-noabi-attr-rv64iq-01.d} (82%) rename gas/testsuite/gas/riscv/{mabi-noabi-attr-03b.d => mabi-noabi-attr-rv64iq-02.d} (86%) rename gas/testsuite/gas/riscv/{mabi-noabi-march-01.d => mabi-noabi-march-rv32i.d} (100%) rename gas/testsuite/gas/riscv/{mabi-noabi-march-02.d => mabi-noabi-march-rv32id.d} (85%) rename gas/testsuite/gas/riscv/{mabi-noabi-march-03.d => mabi-noabi-march-rv64iq.d} (84%) diff --git a/gas/ChangeLog b/gas/ChangeLog index cf135d98d51..bc7a00fb223 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,19 @@ +2021-05-24 Nelson Chu + + PR 25212 + * config/tc-riscv.c (riscv_set_abi_by_arch): If -mabi isn't set, we + will choose ilp32e abi for rv32e. Besides, report errors for the + invalid march and mabi combinations. + * testsuite/gas/riscv/mabi-attr-rv32e.s: New testcase. Only accept + ilp32e abi for rve extension. + * testsuite/gas/riscv/mabi-fail-rv32e-lp64f.d: Likewise. + * testsuite/gas/riscv/mabi-fail-rv32e-lp64f.l: Likewise. + * testsuite/gas/riscv/mabi-fail-rv32e-lp64d.d: Likewise. + * testsuite/gas/riscv/mabi-fail-rv32e-lp64d.l: Likewise. + * testsuite/gas/riscv/mabi-fail-rv32e-lp64d.q: Likewise. + * testsuite/gas/riscv/mabi-fail-rv32e-lp64d.q: Likewise. + Renamed all mabi testcases to their march-mabi settings. + 2021-05-22 Alan Modra PR 25599 diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 3fff33e9a11..a76e53d51c3 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -441,6 +441,8 @@ riscv_set_abi_by_arch (void) riscv_set_abi (xlen, FLOAT_ABI_QUAD, false); else if (riscv_subset_supports ("d")) riscv_set_abi (xlen, FLOAT_ABI_DOUBLE, false); + else if (riscv_subset_supports ("e")) + riscv_set_abi (xlen, FLOAT_ABI_SOFT, true); else riscv_set_abi (xlen, FLOAT_ABI_SOFT, false); } @@ -451,6 +453,22 @@ riscv_set_abi_by_arch (void) as_bad ("can't have %d-bit ABI on %d-bit ISA", abi_xlen, xlen); else if (abi_xlen < xlen) as_bad ("%d-bit ABI not yet supported on %d-bit ISA", abi_xlen, xlen); + + if (riscv_subset_supports ("e") && !rve_abi) + as_bad ("only the ilp32e ABI is supported for e extension"); + + if (float_abi == FLOAT_ABI_SINGLE + && !riscv_subset_supports ("f")) + as_bad ("ilp32f/lp64f ABI can't be used when f extension " + "isn't supported"); + else if (float_abi == FLOAT_ABI_DOUBLE + && !riscv_subset_supports ("d")) + as_bad ("ilp32d/lp64d ABI can't be used when d extension " + "isn't supported"); + else if (float_abi == FLOAT_ABI_QUAD + && !riscv_subset_supports ("q")) + as_bad ("ilp32q/lp64q ABI can't be used when q extension " + "isn't supported"); } /* Update the EF_RISCV_FLOAT_ABI field of elf_flags. */ diff --git a/gas/testsuite/gas/riscv/mabi-attr-rv32e.s b/gas/testsuite/gas/riscv/mabi-attr-rv32e.s new file mode 100644 index 00000000000..846c0236bcb --- /dev/null +++ b/gas/testsuite/gas/riscv/mabi-attr-rv32e.s @@ -0,0 +1 @@ + .attribute arch,"rv32e" diff --git a/gas/testsuite/gas/riscv/mabi-attr-01.s b/gas/testsuite/gas/riscv/mabi-attr-rv32i.s similarity index 100% rename from gas/testsuite/gas/riscv/mabi-attr-01.s rename to gas/testsuite/gas/riscv/mabi-attr-rv32i.s diff --git a/gas/testsuite/gas/riscv/mabi-attr-02.s b/gas/testsuite/gas/riscv/mabi-attr-rv32id.s similarity index 100% rename from gas/testsuite/gas/riscv/mabi-attr-02.s rename to gas/testsuite/gas/riscv/mabi-attr-rv32id.s diff --git a/gas/testsuite/gas/riscv/mabi-attr-03.s b/gas/testsuite/gas/riscv/mabi-attr-rv64iq.s similarity index 100% rename from gas/testsuite/gas/riscv/mabi-attr-03.s rename to gas/testsuite/gas/riscv/mabi-attr-rv64iq.s diff --git a/gas/testsuite/gas/riscv/mabi-fail-01.d b/gas/testsuite/gas/riscv/mabi-fail-01.d deleted file mode 100644 index 78049349330..00000000000 --- a/gas/testsuite/gas/riscv/mabi-fail-01.d +++ /dev/null @@ -1,3 +0,0 @@ -#as: -march-attr -mabi=lp64d -#source: mabi-attr-01.s -#error_output: mabi-fail-01.l diff --git a/gas/testsuite/gas/riscv/mabi-fail-02.d b/gas/testsuite/gas/riscv/mabi-fail-02.d deleted file mode 100644 index 2d6cfb02465..00000000000 --- a/gas/testsuite/gas/riscv/mabi-fail-02.d +++ /dev/null @@ -1,3 +0,0 @@ -#as: -march-attr -mabi=ilp32 -#source: mabi-attr-03.s -#error_output: mabi-fail-02.l diff --git a/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64d.d b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64d.d new file mode 100644 index 00000000000..04d402aa976 --- /dev/null +++ b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64d.d @@ -0,0 +1,3 @@ +#as: -march-attr -mabi=lp64d +#source: mabi-attr-rv32e.s +#error_output: mabi-fail-rv32e-lp64d.l diff --git a/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64d.l b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64d.l new file mode 100644 index 00000000000..f7306cb24d2 --- /dev/null +++ b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64d.l @@ -0,0 +1,4 @@ +.*Assembler messages: +.*Error: can't have 64-bit ABI on 32-bit ISA +.*Error: only the ilp32e ABI is supported for e extension +.*Error: ilp32d/lp64d ABI can't be used when d extension isn't supported diff --git a/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64f.d b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64f.d new file mode 100644 index 00000000000..b7a346465c7 --- /dev/null +++ b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64f.d @@ -0,0 +1,3 @@ +#as: -march-attr -mabi=lp64f +#source: mabi-attr-rv32e.s +#error_output: mabi-fail-rv32e-lp64f.l diff --git a/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64f.l b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64f.l new file mode 100644 index 00000000000..706690ac9c6 --- /dev/null +++ b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64f.l @@ -0,0 +1,4 @@ +.*Assembler messages: +.*Error: can't have 64-bit ABI on 32-bit ISA +.*Error: only the ilp32e ABI is supported for e extension +.*Error: ilp32f/lp64f ABI can't be used when f extension isn't supported diff --git a/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64q.d b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64q.d new file mode 100644 index 00000000000..e5d3c4e5d15 --- /dev/null +++ b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64q.d @@ -0,0 +1,3 @@ +#as: -march-attr -mabi=lp64q +#source: mabi-attr-rv32e.s +#error_output: mabi-fail-rv32e-lp64q.l diff --git a/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64q.l b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64q.l new file mode 100644 index 00000000000..ab64b1546f6 --- /dev/null +++ b/gas/testsuite/gas/riscv/mabi-fail-rv32e-lp64q.l @@ -0,0 +1,4 @@ +.*Assembler messages: +.*Error: can't have 64-bit ABI on 32-bit ISA +.*Error: only the ilp32e ABI is supported for e extension +.*Error: ilp32q/lp64q ABI can't be used when q extension isn't supported diff --git a/gas/testsuite/gas/riscv/mabi-fail-rv32i-lp64.d b/gas/testsuite/gas/riscv/mabi-fail-rv32i-lp64.d new file mode 100644 index 00000000000..469a53611fb --- /dev/null +++ b/gas/testsuite/gas/riscv/mabi-fail-rv32i-lp64.d @@ -0,0 +1,3 @@ +#as: -march-attr -mabi=lp64 +#source: mabi-attr-rv32i.s +#error_output: mabi-fail-rv32i-lp64.l diff --git a/gas/testsuite/gas/riscv/mabi-fail-01.l b/gas/testsuite/gas/riscv/mabi-fail-rv32i-lp64.l similarity index 100% rename from gas/testsuite/gas/riscv/mabi-fail-01.l rename to gas/testsuite/gas/riscv/mabi-fail-rv32i-lp64.l diff --git a/gas/testsuite/gas/riscv/mabi-fail-rv64iq-ilp32.d b/gas/testsuite/gas/riscv/mabi-fail-rv64iq-ilp32.d new file mode 100644 index 00000000000..e3155f48956 --- /dev/null +++ b/gas/testsuite/gas/riscv/mabi-fail-rv64iq-ilp32.d @@ -0,0 +1,3 @@ +#as: -march-attr -mabi=ilp32 +#source: mabi-attr-rv64iq.s +#error_output: mabi-fail-rv64iq-ilp32.l diff --git a/gas/testsuite/gas/riscv/mabi-fail-02.l b/gas/testsuite/gas/riscv/mabi-fail-rv64iq-ilp32.l similarity index 100% rename from gas/testsuite/gas/riscv/mabi-fail-02.l rename to gas/testsuite/gas/riscv/mabi-fail-rv64iq-ilp32.l diff --git a/gas/testsuite/gas/riscv/mabi-noabi-attr-01a.d b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv32i-01.d similarity index 58% rename from gas/testsuite/gas/riscv/mabi-noabi-attr-01a.d rename to gas/testsuite/gas/riscv/mabi-noabi-attr-rv32i-01.d index 11d3ed91617..b58b9043729 100644 --- a/gas/testsuite/gas/riscv/mabi-noabi-attr-01a.d +++ b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv32i-01.d @@ -1,6 +1,6 @@ -#as: -march-attr -march=rv64ifd +#as: -march-attr -march=rv64id #readelf: -h -#source: mabi-attr-01.s +#source: mabi-attr-rv32i.s ELF Header: #... diff --git a/gas/testsuite/gas/riscv/mabi-noabi-attr-01b.d b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv32i-02.d similarity index 71% rename from gas/testsuite/gas/riscv/mabi-noabi-attr-01b.d rename to gas/testsuite/gas/riscv/mabi-noabi-attr-rv32i-02.d index b50ac3c240a..56dcd0ff31a 100644 --- a/gas/testsuite/gas/riscv/mabi-noabi-attr-01b.d +++ b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv32i-02.d @@ -1,6 +1,6 @@ -#as: -march-attr -march=rv64ifd +#as: -march-attr -march=rv64id #objdump: -d -#source: mabi-attr-01.s +#source: mabi-attr-rv32i.s .*:[ ]+file format elf32.* diff --git a/gas/testsuite/gas/riscv/mabi-noabi-attr-02a.d b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv32id-01.d similarity index 82% rename from gas/testsuite/gas/riscv/mabi-noabi-attr-02a.d rename to gas/testsuite/gas/riscv/mabi-noabi-attr-rv32id-01.d index 9668066aadd..425e5d15e32 100644 --- a/gas/testsuite/gas/riscv/mabi-noabi-attr-02a.d +++ b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv32id-01.d @@ -1,6 +1,6 @@ #as: -march-attr -march=rv64i #readelf: -h -#source: mabi-attr-02.s +#source: mabi-attr-rv32id.s ELF Header: #... diff --git a/gas/testsuite/gas/riscv/mabi-noabi-attr-02b.d b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv32id-02.d similarity index 86% rename from gas/testsuite/gas/riscv/mabi-noabi-attr-02b.d rename to gas/testsuite/gas/riscv/mabi-noabi-attr-rv32id-02.d index a69d0bc8db4..8b7ee68c12d 100644 --- a/gas/testsuite/gas/riscv/mabi-noabi-attr-02b.d +++ b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv32id-02.d @@ -1,6 +1,6 @@ #as: -march-attr -march=rv64i #objdump: -d -#source: mabi-attr-02.s +#source: mabi-attr-rv32id.s .*:[ ]+file format elf32.* diff --git a/gas/testsuite/gas/riscv/mabi-noabi-attr-03a.d b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv64iq-01.d similarity index 82% rename from gas/testsuite/gas/riscv/mabi-noabi-attr-03a.d rename to gas/testsuite/gas/riscv/mabi-noabi-attr-rv64iq-01.d index 4392b5cf088..0251a009c84 100644 --- a/gas/testsuite/gas/riscv/mabi-noabi-attr-03a.d +++ b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv64iq-01.d @@ -1,6 +1,6 @@ #as: -march-attr -march=rv32i #readelf: -h -#source: mabi-attr-03.s +#source: mabi-attr-rv64iq.s ELF Header: #... diff --git a/gas/testsuite/gas/riscv/mabi-noabi-attr-03b.d b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv64iq-02.d similarity index 86% rename from gas/testsuite/gas/riscv/mabi-noabi-attr-03b.d rename to gas/testsuite/gas/riscv/mabi-noabi-attr-rv64iq-02.d index 917ab8c131d..6a33ba0f15e 100644 --- a/gas/testsuite/gas/riscv/mabi-noabi-attr-03b.d +++ b/gas/testsuite/gas/riscv/mabi-noabi-attr-rv64iq-02.d @@ -1,6 +1,6 @@ #as: -march-attr -march=rv32i #objdump: -d -#source: mabi-attr-03.s +#source: mabi-attr-rv64iq.s .*:[ ]+file format elf64.* diff --git a/gas/testsuite/gas/riscv/mabi-noabi-march-01.d b/gas/testsuite/gas/riscv/mabi-noabi-march-rv32i.d similarity index 100% rename from gas/testsuite/gas/riscv/mabi-noabi-march-01.d rename to gas/testsuite/gas/riscv/mabi-noabi-march-rv32i.d diff --git a/gas/testsuite/gas/riscv/mabi-noabi-march-02.d b/gas/testsuite/gas/riscv/mabi-noabi-march-rv32id.d similarity index 85% rename from gas/testsuite/gas/riscv/mabi-noabi-march-02.d rename to gas/testsuite/gas/riscv/mabi-noabi-march-rv32id.d index 453fe7b07e2..9ef28abade2 100644 --- a/gas/testsuite/gas/riscv/mabi-noabi-march-02.d +++ b/gas/testsuite/gas/riscv/mabi-noabi-march-rv32id.d @@ -1,4 +1,4 @@ -#as: -march=rv32ifd +#as: -march=rv32id #readelf: -h #source: empty.s diff --git a/gas/testsuite/gas/riscv/mabi-noabi-march-03.d b/gas/testsuite/gas/riscv/mabi-noabi-march-rv64iq.d similarity index 84% rename from gas/testsuite/gas/riscv/mabi-noabi-march-03.d rename to gas/testsuite/gas/riscv/mabi-noabi-march-rv64iq.d index ab2ffc351a0..3de0eb7743b 100644 --- a/gas/testsuite/gas/riscv/mabi-noabi-march-03.d +++ b/gas/testsuite/gas/riscv/mabi-noabi-march-rv64iq.d @@ -1,4 +1,4 @@ -#as: -march=rv64ifdq +#as: -march=rv64iq #readelf: -h #source: empty.s -- 2.30.2