Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -1328,10 +1328,8 @@ } Cmd->Phdrs = readOutputSectionPhdrs(); - if (skip("=")) - Cmd->Filler = readOutputSectionFiller(next()); - else if (peek().startswith("=")) - Cmd->Filler = readOutputSectionFiller(next().drop_front()); + if (peek().startswith("=")) + Cmd->Filler = readOutputSectionFiller(nextJoined()); return Cmd; } @@ -1652,15 +1650,8 @@ std::vector ScriptParser::readOutputSectionPhdrs() { std::vector Phdrs; - while (!Error && peek().startswith(":")) { - StringRef Tok = next(); - Tok = (Tok.size() == 1) ? next() : Tok.substr(1); - if (Tok.empty()) { - setError("section header name is empty"); - break; - } - Phdrs.push_back(Tok); - } + while (!Error && peek().startswith(":")) + Phdrs.push_back(nextJoined()); return Phdrs; } Index: ELF/ScriptParser.h =================================================================== --- ELF/ScriptParser.h +++ ELF/ScriptParser.h @@ -28,6 +28,7 @@ static StringRef skipSpace(StringRef S); bool atEOF(); StringRef next(); + StringRef nextJoined(); StringRef peek(); bool skip(StringRef Tok); void expect(StringRef Expect); Index: ELF/ScriptParser.cpp =================================================================== --- ELF/ScriptParser.cpp +++ ELF/ScriptParser.cpp @@ -129,6 +129,13 @@ return Tokens[Pos++]; } +StringRef ScriptParserBase::nextJoined() { + StringRef Tok = next(); + if (Tok.size() == 1) + return next(); + return Tok.drop_front(std::min(Tok.size(), (size_t)1)); +} + StringRef ScriptParserBase::peek() { StringRef Tok = next(); if (Error)