@@ -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 tok2 );
95
+ bool readSectionDirective (OutputSection *cmd, StringRef tok );
96
96
void readSectionAddressType (OutputSection *cmd);
97
97
OutputDesc *readOverlaySectionDescription ();
98
98
OutputDesc *readOutputSectionDescription (StringRef outSec);
@@ -873,14 +873,11 @@ constexpr std::pair<const char *, unsigned> typeMap[] = {
873
873
// Tries to read the special directive for an output section definition which
874
874
// can be one of following: "(NOLOAD)", "(COPY)", "(INFO)", "(OVERLAY)", and
875
875
// "(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" )
881
879
return false ;
882
880
883
- expect (" (" );
884
881
if (consume (" NOLOAD" )) {
885
882
cmd->type = SHT_NOBITS;
886
883
cmd->typeIsSet = true ;
@@ -919,19 +916,22 @@ bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok2) {
919
916
// https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
920
917
// https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
921
918
void ScriptParser::readSectionAddressType (OutputSection *cmd) {
922
- if (peek () == " (" ) {
919
+ if (consume ( " (" ) ) {
923
920
// Temporarily set inExpr to support TYPE=<value> without spaces.
924
921
SaveAndRestore saved (inExpr, true );
925
- if (readSectionDirective (cmd, peek2 ()))
922
+ if (readSectionDirective (cmd, peek ()))
926
923
return ;
924
+ cmd->addrExpr = readExpr ();
925
+ expect (" )" );
926
+ } else {
927
+ cmd->addrExpr = readExpr ();
927
928
}
928
- cmd->addrExpr = readExpr ();
929
929
930
- if (peek () == " (" ) {
930
+ if (consume ( " (" ) ) {
931
931
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 );
935
935
}
936
936
}
937
937
0 commit comments