[js@convergence.de: binutils-2.11.92.0.12.3 gas MIPS bug: nested parens in %hi]

H . J . Lu hjl@lucon.org
Tue Jan 8 16:42:00 GMT 2002


On Tue, Jan 08, 2002 at 02:10:09PM -0800, H . J . Lu wrote:
> Any ideas?
> 

I am forwarding a patch here.


H.J.
---
> ---
> ----- Forwarded message from Johannes Stezenbach <js@convergence.de> -----
> 
> Delivered-To: hjl@lucon.org
> Date: Tue, 8 Jan 2002 22:18:23 +0100
> From: Johannes Stezenbach <js@convergence.de>
> To: "H . J . Lu" <hjl@lucon.org>
> Cc: Jun Sun <jsun@mvista.com>
> Subject: binutils-2.11.92.0.12.3 gas MIPS bug: nested parens in %hi
> User-Agent: Mutt/1.3.25i
> 
> Hello H. J.,
> 
> the assembler of binutils-2.11.92.0.12.3 for MIPS has a bug which
> shows up when parsing percent-ops like %hi and %lo with
> nested parentheses, e.g.
> 
>    lui t0, %hi((0xa0000000 + 0x10001000))
> 
> produces parsing errors because of unmatched parens
> (sorry, I don't have the exact error message right now).
> 
> Code like that is output from the preprocessor for
> linux/arch/mips/vr4181/common/int_handler.S in
> http://linux-mips.sourceforge.net/, which has
> 
>    lui     t3,%hi(VR4181_SYSINT1REG)
> 
> where linux/include/asm-mips/vr4181/vr4181.h has
> 
>   #ifndef _LANGUAGE_ASSEMBLY
>   #define __preg16        (volatile unsigned short*)
>   #else
>   #define __preg16
>   #endif
>   #define VR4181_SYSINT1REG       __preg16(KSEG1 + 0x0A000080)    /* Level 1 System interrupt register 1 (R) */
> 
> 
> AFAIK this used to work with binutils-2.10.91.0.2.
> 
> I attempted to fix this problem (patch attached), but unfortunately
> my understanding of gas' expression parser is very limited.
> My patch is thus more a workaround-hack than a fix.
> 
> I tried hard to figure out how my_getSmallExpression() in
> gas/config/tc-mips.c works for nested precent-ops, but
> either I failed or the thing is totally broken.
> 
> I dont't know all the details of the MIPS assembler syntax,
> but wouldn't it be the right way to use expr() (in gas/expr.c) for
> parsing, and provide support for percent-ops via the
> md_operand() hook?  This should work since is_name_beginner('%')
> returns FALSE and LITERAL_PREFIXPERCENT_BIN is #undef'd.
> 
> 
> Regards,
> Johannes
> 
-------------- next part --------------
--- binutils-2.11.92.0.12.3/gas/config/tc-mips.c.orig	Tue Jan  8 11:56:48 2002
+++ binutils-2.11.92.0.12.3/gas/config/tc-mips.c	Tue Jan  8 12:16:14 2002
@@ -9287,7 +9287,20 @@
 	}
 
       /* Some other expression in the braces.  */
-      *len = strcspn (*str, ")") + 1;
+      /* Attempt to find the matching parenthesis. */
+      {
+	int pcnt = 1;
+	char *s;
+
+	*len = 0;
+	for (s = *str; *s && pcnt; s++, (*len)++)
+	  {
+	    if (*s == '(')
+	      pcnt++;
+	    else if (*s == ')')
+	      pcnt--;
+	  }
+      }
     }
   /* Check for percent_op.  */
   else if (*str[0] == '%')
@@ -9373,7 +9386,7 @@
 	}
       else
 	{
-	  expr_end = strchr (str, ')') + 1;
+	  expr_end = str + len;
 	}
       c = oldc;
     }


More information about the Binutils mailing list