]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
RISC-V: Fix lui argument parsing.
authorJim Wilson <jimw@sifive.com>
Thu, 30 May 2019 22:23:10 +0000 (15:23 -0700)
committerJim Wilson <jimw@sifive.com>
Thu, 30 May 2019 22:23:10 +0000 (15:23 -0700)
This fixes a bug reported on the riscv.org sw-dev mailing list.  This
rejects "lui x1,symbol", as a symbol should only be accepted here when
used inside %hi().  Without the fix, this gets assembled as "lui x1,0"
with no relocation which is clearly wrong.

gas/
* config/tc-riscv.c (riscv_ip) <'u'>: Move O_constant check inside if
statement.  Delete O_symbol and O_constant check after if statement.
* testsuite/gas/riscv/auipc-parsing.s: Test lui with missing %hi.
* testsuite/gas/riscv/auipc-parsing.l: Update.

gas/ChangeLog
gas/config/tc-riscv.c
gas/testsuite/gas/riscv/auipc-parsing.l
gas/testsuite/gas/riscv/auipc-parsing.s

index 7de5247623402a9b2bdbf68910365a7d92b6250c..d46026565c38088337ec0ed00212a3acf405276a 100644 (file)
@@ -1,3 +1,10 @@
+2019-05-30  Jim Wilson  <jimw@sifive.com>
+
+       * config/tc-riscv.c (riscv_ip) <'u'>: Move O_constant check inside if
+       statement.  Delete O_symbol and O_constant check after if statement.
+       * testsuite/gas/riscv/auipc-parsing.s: Test lui with missing %hi.
+       * testsuite/gas/riscv/auipc-parsing.l: Update.
+
 2019-05-28  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR gas/24625
index 99b007f59f19d0d79a49384d991a288ce544862a..f0c1f4ca75cd65203778083270d7af6f806d33c7 100644 (file)
@@ -1952,9 +1952,11 @@ branch:
 
            case 'u':           /* Upper 20 bits.  */
              p = percent_op_utype;
-             if (!my_getSmallExpression (imm_expr, imm_reloc, s, p)
-                 && imm_expr->X_op == O_constant)
+             if (!my_getSmallExpression (imm_expr, imm_reloc, s, p))
                {
+                 if (imm_expr->X_op != O_constant)
+                   break;
+
                  if (imm_expr->X_add_number < 0
                      || imm_expr->X_add_number >= (signed)RISCV_BIGIMM_REACH)
                    as_bad (_("lui expression not in range 0..1048575"));
@@ -1962,9 +1964,6 @@ branch:
                  *imm_reloc = BFD_RELOC_RISCV_HI20;
                  imm_expr->X_add_number <<= RISCV_IMM_BITS;
                }
-             /* The 'u' format specifier must be a symbol or a constant.  */
-             if (imm_expr->X_op != O_symbol && imm_expr->X_op != O_constant)
-               break;
              s = expr_end;
              continue;
 
index df41e0e2f9f9b46f0b0af67983e31e25885e5363..54eedcbf04fab862c735f58ac4a6d5824e7a5ac5 100644 (file)
@@ -1,3 +1,5 @@
 .*: Assembler messages:
 .*: Error: illegal operands `auipc x8,x9'
 .*: Error: illegal operands `lui x10,x11'
+.*: Error: illegal operands `auipc x12,symbol'
+.*: Error: illegal operands `lui x13,symbol'
index f580869cbede0e3ea4d6d1f3ab348f7bcda0d3ab..7af4df9ede1472186e4dbb52dd795a3cbd05a343 100644 (file)
@@ -1,3 +1,6 @@
 # Don't accept a register for 'u' operands.
        auipc   x8,x9
        lui     x10,x11
+# Don't accept a symbol without %hi() for 'u' operands.
+       auipc   x12,symbol
+       lui     x13,symbol