[lld] [ELF] PHDRS update while condition and phdrs.s unclose2.lds output (PR #100918)
Hongyu Chen via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 28 13:09:24 PDT 2024
yugier wrote:
> Using `till(";")` for the inner loop would cause inferior diagnostics for the following case:
>
> ```
> ld.lld: error: 1.lds:1: unexpected header attribute: }
> >>> PHDRS {all PT_LOAD FILEHDR PHDRS }
> >>>
> ```
>
> something like `expected ';'` would be better
I was trying to figure out a better way for this but its difficult to have a clean code unless we have more states to help us to identify if current token is an identifier/operator/symbol.
```
void ScriptParser::readPhdrs() {
expect("{");
while (auto tok = till("}")) {
PhdrsCommand cmd;
cmd.name = tok;
cmd.type = readPhdrType();
while (!atEOF()) {
if (consume("FILEHDR"))
cmd.hasFilehdr = true;
else if (consume("PHDRS"))
cmd.hasPhdrs = true;
else if (consume("AT"))
cmd.lmaExpr = readParenExpr();
else if (consume("FLAGS"))
cmd.flags = readParenExpr()().getValue();
else
break;
//setError("unexpected header attribute: " + next());
}
expect(";");
script->phdrsCommands.push_back(cmd);
}
}
```
Without a clear state the code above is the one i can think about the most concise one but we need to modify the error message.
https://github.com/llvm/llvm-project/pull/100918
More information about the llvm-commits
mailing list