public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Let '^' through the lexer
@ 2023-07-12 13:56 Michael Matz
  2023-07-12 23:02 ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Matz @ 2023-07-12 13:56 UTC (permalink / raw)
  To: binutils

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?


Ciao,
Michael.

---
 ld/ld.texi | 22 ++++++++++++----------
 ld/ldlex.l |  1 +
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/ld/ld.texi b/ld/ld.texi
index aa8b1aa86eb..8f82fe5a92f 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -6826,11 +6826,12 @@ precedence      associativity   Operators                Notes
 4               left            >>  <<
 5               left            ==  !=  >  <  <=  >=
 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)
 (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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-14  3:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-12 13:56 [PATCH] Let '^' through the lexer Michael Matz
2023-07-12 23:02 ` Alan Modra
2023-07-13  7:54   ` Jan Beulich
2023-07-13 10:20     ` Alan Modra
2023-07-13 16:02       ` Michael Matz
2023-07-14  3:32         ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).