RISC-V: tighten post-relocation-operator separator expectation

Message ID e1da592f-5c5b-418b-a25b-afeeb0691ea7@suse.com
State Unresolved
Headers
Series RISC-V: tighten post-relocation-operator separator expectation |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Jan Beulich April 28, 2023, 12:57 p.m. UTC
  As per the spec merely a blank isn't okay as a separator, the operand
to the relocation function ought to be parenthesized. Enforcing this
then also eliminates an inconsistency in that

	lui	t0, %hi sym
	lui	t0, %hi 0x1000

were accepted, but

	lui	t0, %hi +sym
	lui	t0, %hi -0x1000

were not.
  

Comments

Nelson Chu May 4, 2023, 8:16 a.m. UTC | #1
Thanks for helping to fix this :)

Nelson

On Fri, Apr 28, 2023 at 8:57 PM Jan Beulich <jbeulich@suse.com> wrote:

> As per the spec merely a blank isn't okay as a separator, the operand
> to the relocation function ought to be parenthesized. Enforcing this
> then also eliminates an inconsistency in that
>
>         lui     t0, %hi sym
>         lui     t0, %hi 0x1000
>
> were accepted, but
>
>         lui     t0, %hi +sym
>         lui     t0, %hi -0x1000
>
> were not.
>
> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -2200,7 +2200,9 @@ parse_relocation (char **str, bfd_reloc_
>        {
>         size_t len = 1 + strlen (percent_op->str);
>
> -       if (!ISSPACE ((*str)[len]) && (*str)[len] != '(')
> +       while (ISSPACE ((*str)[len]))
> +         ++len;
> +       if ((*str)[len] != '(')
>           continue;
>
>         *str += len;
> --- a/gas/testsuite/gas/riscv/auipc-parsing.l
> +++ b/gas/testsuite/gas/riscv/auipc-parsing.l
> @@ -3,3 +3,5 @@
>  .*: Error: illegal operands `lui x10,x11'
>  .*: Error: illegal operands `auipc x12,symbol'
>  .*: Error: illegal operands `lui x13,symbol'
> +.*: Error: illegal operands `auipc x14,%hi symbol'
> +.*: Error: illegal operands `lui x15,%hi symbol'
> --- a/gas/testsuite/gas/riscv/auipc-parsing.s
> +++ b/gas/testsuite/gas/riscv/auipc-parsing.s
> @@ -4,3 +4,6 @@
>  # Don't accept a symbol without %hi() for 'u' operands.
>         auipc   x12,symbol
>         lui     x13,symbol
> +# Don't accept reloc functions without parentheses.
> +       auipc   x14,%hi symbol
> +       lui     x15,%hi symbol
>
  

Patch

--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -2200,7 +2200,9 @@  parse_relocation (char **str, bfd_reloc_
       {
 	size_t len = 1 + strlen (percent_op->str);
 
-	if (!ISSPACE ((*str)[len]) && (*str)[len] != '(')
+	while (ISSPACE ((*str)[len]))
+	  ++len;
+	if ((*str)[len] != '(')
 	  continue;
 
 	*str += len;
--- a/gas/testsuite/gas/riscv/auipc-parsing.l
+++ b/gas/testsuite/gas/riscv/auipc-parsing.l
@@ -3,3 +3,5 @@ 
 .*: Error: illegal operands `lui x10,x11'
 .*: Error: illegal operands `auipc x12,symbol'
 .*: Error: illegal operands `lui x13,symbol'
+.*: Error: illegal operands `auipc x14,%hi symbol'
+.*: Error: illegal operands `lui x15,%hi symbol'
--- a/gas/testsuite/gas/riscv/auipc-parsing.s
+++ b/gas/testsuite/gas/riscv/auipc-parsing.s
@@ -4,3 +4,6 @@ 
 # Don't accept a symbol without %hi() for 'u' operands.
 	auipc	x12,symbol
 	lui	x13,symbol
+# Don't accept reloc functions without parentheses.
+	auipc	x14,%hi symbol
+	lui	x15,%hi symbol