@@ -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 tok2 );
95+ bool readSectionDirective (OutputSection *cmd, StringRef tok );
9696 void readSectionAddressType (OutputSection *cmd);
9797 OutputDesc *readOverlaySectionDescription ();
9898 OutputDesc *readOutputSectionDescription (StringRef outSec);
@@ -873,14 +873,11 @@ constexpr std::pair<const char *, unsigned> typeMap[] = {
873873// Tries to read the special directive for an output section definition which
874874// can be one of following: "(NOLOAD)", "(COPY)", "(INFO)", "(OVERLAY)", and
875875// "(TYPE=<value>)".
876- // Tok1 and Tok2 are next 2 tokens peeked. See comment for
877- // readSectionAddressType below.
878- bool ScriptParser::readSectionDirective (OutputSection *cmd, StringRef tok2) {
879- if (tok2 != " NOLOAD" && tok2 != " COPY" && tok2 != " INFO" &&
880- tok2 != " OVERLAY" && tok2 != " TYPE" )
876+ bool ScriptParser::readSectionDirective (OutputSection *cmd, StringRef tok) {
877+ if (tok != " NOLOAD" && tok != " COPY" && tok != " INFO" && tok != " OVERLAY" &&
878+ tok != " TYPE" )
881879 return false ;
882880
883- expect (" (" );
884881 if (consume (" NOLOAD" )) {
885882 cmd->type = SHT_NOBITS;
886883 cmd->typeIsSet = true ;
@@ -919,19 +916,22 @@ bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok2) {
919916// https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
920917// https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
921918void ScriptParser::readSectionAddressType (OutputSection *cmd) {
922- if (peek () == " (" ) {
919+ if (consume ( " (" ) ) {
923920 // Temporarily set inExpr to support TYPE=<value> without spaces.
924921 SaveAndRestore saved (inExpr, true );
925- if (readSectionDirective (cmd, peek2 ()))
922+ if (readSectionDirective (cmd, peek ()))
926923 return ;
924+ cmd->addrExpr = readExpr ();
925+ expect (" )" );
926+ } else {
927+ cmd->addrExpr = readExpr ();
927928 }
928- cmd->addrExpr = readExpr ();
929929
930- if (peek () == " (" ) {
930+ if (consume ( " (" ) ) {
931931 SaveAndRestore saved (inExpr, true );
932- StringRef tok2 = peek2 ();
933- if (!readSectionDirective (cmd, tok2 ))
934- setError (" unknown section directive: " + tok2 );
932+ StringRef tok = peek ();
933+ if (!readSectionDirective (cmd, tok ))
934+ setError (" unknown section directive: " + tok );
935935 }
936936}
937937
0 commit comments