@@ -92,7 +92,7 @@ class ScriptParser final : ScriptLexer {
92
92
SymbolAssignment *readSymbolAssignment (StringRef name);
93
93
ByteCommand *readByteCommand (StringRef tok);
94
94
std::array<uint8_t , 4 > readFill ();
95
- bool readSectionDirective (OutputSection *cmd, StringRef tok1, StringRef tok2);
95
+ bool readSectionDirective (OutputSection *cmd, StringRef tok2);
96
96
void readSectionAddressType (OutputSection *cmd);
97
97
OutputDesc *readOverlaySectionDescription ();
98
98
OutputDesc *readOutputSectionDescription (StringRef outSec);
@@ -875,9 +875,7 @@ constexpr std::pair<const char *, unsigned> typeMap[] = {
875
875
// "(TYPE=<value>)".
876
876
// Tok1 and Tok2 are next 2 tokens peeked. See comment for
877
877
// 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) {
881
879
if (tok2 != " NOLOAD" && tok2 != " COPY" && tok2 != " INFO" &&
882
880
tok2 != " OVERLAY" && tok2 != " TYPE" )
883
881
return false ;
@@ -921,16 +919,20 @@ bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok1, Stri
921
919
// https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
922
920
// https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
923
921
void 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
+ }
931
928
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
+ }
934
936
}
935
937
936
938
static Expr checkAlignment (Expr e, std::string &loc) {
0 commit comments