void ScriptParser::readGroup() {
expect("(");
while (!Error && !consume(")")) {
- StringRef Tok = next();
- if (Tok == "AS_NEEDED")
+ if (consume("AS_NEEDED"))
readAsNeeded();
else
- addFile(unquote(Tok));
+ addFile(unquote(next()));
}
}
// Error checking only for now.
expect("(");
skip();
- StringRef Tok = next();
- if (Tok == ")")
+ if (consume(")"))
return;
- if (Tok != ",") {
- setError("unexpected token: " + Tok);
- return;
- }
+ expect(",");
skip();
expect(",");
skip();
void ScriptParser::readPhdrs() {
expect("{");
while (!Error && !consume("}")) {
- StringRef Tok = next();
Script->Opt.PhdrsCommands.push_back(
- {Tok, PT_NULL, false, false, UINT_MAX, nullptr});
- PhdrsCommand &PhdrCmd = Script->Opt.PhdrsCommands.back();
+ {next(), PT_NULL, false, false, UINT_MAX, nullptr});
+ PhdrsCommand &PhdrCmd = Script->Opt.PhdrsCommands.back();
PhdrCmd.Type = readPhdrType();
- do {
- Tok = next();
- if (Tok == ";")
- break;
- if (Tok == "FILEHDR")
+
+ while (!Error && !consume(";")) {
+ if (consume("FILEHDR"))
PhdrCmd.HasFilehdr = true;
- else if (Tok == "PHDRS")
+ else if (consume("PHDRS"))
PhdrCmd.HasPhdrs = true;
- else if (Tok == "AT")
+ else if (consume("AT"))
PhdrCmd.LMAExpr = readParenExpr();
- else if (Tok == "FLAGS") {
- expect("(");
- // Passing 0 for the value of dot is a bit of a hack. It means that
- // we accept expressions like ".|1".
- PhdrCmd.Flags = readExpr()().getValue();
- expect(")");
- } else
- setError("unexpected header attribute: " + Tok);
- } while (!Error);
+ else if (consume("FLAGS"))
+ PhdrCmd.Flags = readParenExpr()().getValue();
+ else
+ setError("unexpected header attribute: " + next());
+ }
}
}
void ScriptParser::readSections() {
Script->Opt.HasSections = true;
+
// -no-rosegment is used to avoid placing read only non-executable sections in
// their own segment. We do the same if SECTIONS command is present in linker
// script. See comment for computeFlags().
expect(",");
StringRef Msg = unquote(next());
expect(")");
+
return [=] {
if (!E().getValue())
error(Msg);
Cmd->Location = getCurrentLocation();
// Read an address expression.
- // https://sourceware.org/binutils/docs/ld/Output-Section-Address.html#Output-Section-Address
+ // https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
if (peek() != ":")
Cmd->AddrExpr = readExpr();
StringRef Tok = next();
if (Tok == ";") {
// Empty commands are allowed. Do nothing here.
- } else if (SymbolAssignment *Assignment = readProvideOrAssignment(Tok)) {
- Cmd->Commands.push_back(Assignment);
+ } else if (SymbolAssignment *Assign = readProvideOrAssignment(Tok)) {
+ Cmd->Commands.push_back(Assign);
} else if (BytesDataCommand *Data = readBytesDataCommand(Tok)) {
Cmd->Commands.push_back(Data);
} else if (Tok == "ASSERT") {
}
static Expr combine(StringRef Op, Expr L, Expr R) {
- if (Op == "*")
- return [=] { return mul(L(), R()); };
- if (Op == "/") {
- return [=] { return div(L(), R()); };
- }
if (Op == "+")
return [=] { return add(L(), R()); };
if (Op == "-")
return [=] { return sub(L(), R()); };
+ if (Op == "*")
+ return [=] { return mul(L(), R()); };
+ if (Op == "/")
+ return [=] { return div(L(), R()); };
if (Op == "<<")
return [=] { return L().getValue() << R().getValue(); };
if (Op == ">>")
}
BytesDataCommand *ScriptParser::readBytesDataCommand(StringRef Tok) {
- int Size = StringSwitch<unsigned>(Tok)
+ int Size = StringSwitch<int>(Tok)
.Case("BYTE", 1)
.Case("SHORT", 2)
.Case("LONG", 4)
if (Tok == "ALIGN") {
expect("(");
Expr E = readExpr();
- if (consume(",")) {
- Expr E2 = readExpr();
- expect(")");
- return [=] { return alignTo(E().getValue(), E2().getValue()); };
- }
+ if (consume(")"))
+ return [=] { return alignTo(Script->getDot(), E().getValue()); };
+ expect(",");
+ Expr E2 = readExpr();
expect(")");
- return [=] { return alignTo(Script->getDot(), E().getValue()); };
+ return [=] { return alignTo(E().getValue(), E2().getValue()); };
}
if (Tok == "ALIGNOF") {
StringRef Name = readParenLiteral();
uint64_t ScriptParser::readMemoryAssignment(StringRef S1, StringRef S2,
StringRef S3) {
- if (!(consume(S1) || consume(S2) || consume(S3))) {
+ if (!consume(S1) && !consume(S2) && !consume(S3)) {
setError("expected one of: " + S1 + ", " + S2 + ", or " + S3);
return 0;
}