[lld] [LLD] Fix crash on parsing ':ALIGN' in linker script (PR #146723)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 2 13:00:55 PDT 2025


================
@@ -1229,6 +1229,9 @@ SymbolAssignment *ScriptParser::readSymbolAssignment(StringRef name) {
 // This is an operator-precedence parser to parse a linker
 // script expression.
 Expr ScriptParser::readExpr() {
+  // Do not try to read expression if an error has already been encountered.
+  if (atEOF())
----------------
parth-07 wrote:

> Assuming this is related to the patch. It may be that we've terminated too early before enough context for the error message can be accumulated. Which may mean that the check needs to be put closer to the point where an infinite loop may occur. Or we need a different approach.

Yes, it was related to the patch. Thank you for sharing your thoughts. It turned out the error was due to the return value of `getExpr()` in the error path. The return value was an empty function object. It should be a 0-value equivalent of the `lld::elf::Expr`. I have fixed the issue. 

https://github.com/llvm/llvm-project/pull/146723


More information about the llvm-commits mailing list