@@ -92,7 +92,7 @@ class ScriptParser final : ScriptLexer {
9292 SymbolAssignment *readSymbolAssignment (StringRef name);
9393 ByteCommand *readByteCommand (StringRef tok);
9494 std::array<uint8_t , 4 > readFill ();
95- bool readSectionDirective (OutputSection *cmd, StringRef tok1, StringRef tok2);
95+ bool readSectionDirective (OutputSection *cmd, StringRef tok2);
9696 void readSectionAddressType (OutputSection *cmd);
9797 OutputDesc *readOverlaySectionDescription ();
9898 OutputDesc *readOutputSectionDescription (StringRef outSec);
@@ -875,9 +875,7 @@ constexpr std::pair<const char *, unsigned> typeMap[] = {
875875// "(TYPE=<value>)".
876876// Tok1 and Tok2 are next 2 tokens peeked. See comment for
877877// readSectionAddressType below.
878- bool ScriptParser::readSectionDirective (OutputSection *cmd, StringRef tok1, StringRef tok2) {
879- if (tok1 != " (" )
880- return false ;
878+ bool ScriptParser::readSectionDirective (OutputSection *cmd, StringRef tok2) {
881879 if (tok2 != " NOLOAD" && tok2 != " COPY" && tok2 != " INFO" &&
882880 tok2 != " OVERLAY" && tok2 != " TYPE" )
883881 return false ;
@@ -921,16 +919,20 @@ bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok1, Stri
921919// https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
922920// https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
923921void ScriptParser::readSectionAddressType (OutputSection *cmd) {
924- // Temporarily set inExpr to support TYPE=<value> without spaces.
925- bool saved = std::exchange (inExpr, true );
926- bool isDirective = readSectionDirective (cmd, peek (), peek2 ());
927- inExpr = saved;
928- if (isDirective)
929- return ;
930-
922+ if (peek () == " (" ) {
923+ // Temporarily set inExpr to support TYPE=<value> without spaces.
924+ SaveAndRestore saved (inExpr, true );
925+ if (readSectionDirective (cmd, peek2 ()))
926+ return ;
927+ }
931928 cmd->addrExpr = readExpr ();
932- if (peek () == " (" && !readSectionDirective (cmd, " (" , peek2 ()))
933- setError (" unknown section directive: " + peek2 ());
929+
930+ if (peek () == " (" ) {
931+ SaveAndRestore saved (inExpr, true );
932+ StringRef tok2 = peek2 ();
933+ if (!readSectionDirective (cmd, tok2))
934+ setError (" unknown section directive: " + tok2);
935+ }
934936}
935937
936938static Expr checkAlignment (Expr e, std::string &loc) {
0 commit comments