+2018-12-10  Jim Wilson  <jimw@sifive.com>
+
+       PR gas/23954
+       * config/tc-riscv.c (my_getSmallExpression): Expand comment for
+       register support.  Set expr_end if parse a register.
+       (riscv_ip) <'u'>: Break if imm_expr is not a symbol or constant.
+       * testsuite/gas/riscv/auipc-parsing.d: New.
+       * testsuite/gas/riscv/auipc-parsing.l: New.
+       * testsuite/gas/riscv/auipc-parsing.s: New.
+
 2018-12-09  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR gas/23968
 
   unsigned crux_depth, str_depth, regno;
   char *crux;
 
-  /* First, check for integer registers.  */
+  /* First, check for integer registers.  No callers can accept a reg, but
+     we need to avoid accidentally creating a useless undefined symbol below,
+     if this is an instruction pattern that can't match.  A glibc build fails
+     if this is removed.  */
   if (reg_lookup (&str, RCLASS_GPR, ®no))
     {
       ep->X_op = O_register;
       ep->X_add_number = regno;
+      expr_end = str;
       return 0;
     }
 
                  *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;