[PATCH] Let '^' through the lexer

Alan Modra amodra@gmail.com
Wed Jul 12 23:02:58 GMT 2023


On Wed, Jul 12, 2023 at 01:56:54PM +0000, Michael Matz via Binutils wrote:
> so that the (existing) code in parser and expression evaluator
> actually get to see it and handle it as XOR.
> ---
> 
> A colleague was asking me about why XOR is missing from linker scripts and 
> I initially wanted to say "but it is supported, only undocumented", 
> because I distinctly remembered the code handling XOR in the expression 
> parser and evaluator.  But ... he was right.  The lexer unhelpfully 
> doesn't let '^' through and just spits out a "unrecognized character" 
> error.
> 
> This is the case since the dawn of time it seems (ldgram end ldexp 
> handling it, but ldlex not), but I don't see a reason.  While '^' 
> might also be a meta-character in other lexer modes, that's no different 
> from, say, '?' and '*'.  So, let's just handle it as well, document it, 
> and leave it be :-)
> 
> (I have looked around for a testcase that systematically tests the 
> expression syntax in linker scripts.  I can't find one, so I haven't added 
> a case for this one either).
> 
> This is regtested on x86-64-linux only, my test-everything setup is 
> missing right now.  Assuming that that works as well, okay for master?

OK, but..

> --- a/ld/ld.texi
> +++ b/ld/ld.texi
> @@ -6826,11 +6826,12 @@ precedence      associativity   Operators                Notes
>  4               left            >>  <<
>  5               left            ==  !=  >  <  <=  >=

Since you're adjusting this table, can you fix the precedence above?
== and != are lower precedence than the other relational operators.

>  6               left            &
> -7               left            |
> -8               left            &&
> -9               left            ||
> -10              right           ? :
> -11              right           &=  +=  -=  *=  /=       (2)
> +7               left            ^
> +8               left            |
> +9               left            &&
> +10              left            ||
> +11              right           ? :
> +12              right           &=  +=  -=  *=  /=       (2)

This line misses some assignment operators supported by ldgram.y.
It should be += -= *= /= <<= >>= &= |=

>  (lowest)
>  @end smallexample
>  Notes:
> @@ -6858,11 +6859,12 @@ height2pt&\omit&&\omit&&\omit&\cr
>  &4&&left&&>>         <<&\cr
>  &5&&left&&==         !=       >      <      <=      >=&\cr
>  &6&&left&&\&&\cr
> -&7&&left&&|&\cr
> -&8&&left&&{\&\&}&\cr
> -&9&&left&&||&\cr
> -&10&&right&&?        :&\cr
> -&11&&right&&\qquad\&=      +=       -=     *=     /=\qquad\ddag&\cr
> +&7&&left&&^&\cr
> +&8&&left&&|&\cr
> +&9&&left&&{\&\&}&\cr
> +&10&&left&&||&\cr
> +&11&&right&&?        :&\cr
> +&12&&right&&\qquad\&=      +=       -=     *=     /=\qquad\ddag&\cr
>  &lowest&&&&&\cr
>  height2pt&\omit&&\omit&&\omit&\cr}
>  \hrule}
> diff --git a/ld/ldlex.l b/ld/ldlex.l
> index 1a6be1b6af2..9cb002452d8 100644
> --- a/ld/ldlex.l
> +++ b/ld/ldlex.l
> @@ -247,6 +247,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
>  <EXPRESSION,MRI>"/"			{ RTOKEN('/'); }
>  <EXPRESSION,MRI>"%"			{ RTOKEN('%'); }
>  <EXPRESSION,MRI>"<"			{ RTOKEN('<'); }
> +<EXPRESSION,MRI>"^"			{ RTOKEN('^'); }
>  <SCRIPT,EXPRESSION,MRI,WILD>"="		{ RTOKEN('='); }
>  <SCRIPT,EXPRESSION,MRI,WILD>"}"		{ RTOKEN('}'); }
>  <SCRIPT,EXPRESSION,MRI,WILD>"{"		{ RTOKEN('{'); }
> -- 
> 2.39.1

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list