[all-commits] [llvm/llvm-project] 923a3c: [LLD] Fix crash on parsing ':ALIGN' in linker scri...

Parth via All-commits all-commits at lists.llvm.org
Sun Jul 6 10:23:11 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 923a3cc160a14e61bd2847f9b011bb4d6ce4fc71
      https://github.com/llvm/llvm-project/commit/923a3cc160a14e61bd2847f9b011bb4d6ce4fc71
  Author: Parth <partharora99160808 at gmail.com>
  Date:   2025-07-06 (Sun, 06 Jul 2025)

  Changed paths:
    M lld/ELF/ScriptParser.cpp
    M lld/test/ELF/linkerscript/align-section.test

  Log Message:
  -----------
  [LLD] Fix crash on parsing ':ALIGN' in linker script (#146723)

The linker was crashing due to stack overflow when parsing ':ALIGN' in
an output section description. This commit fixes the linker script
parser so that the crash does not happen.

The root cause of the stack overflow is how we parse expressions
(readExpr) in linker script and the behavior of ScriptLexer::expect(...)
utility. ScriptLexer::expect does not do anything if errors have already
been encountered during linker script parsing. In particular, it never
increments the current token position in the script file, even if the
current token is the same as the expected token. This causes an infinite
call cycle on parsing an expression such as '(4096)' when an error has
already been encountered.

readExpr() calls readPrimary()
readPrimary() calls readParenExpr()

readParenExpr():

  expect("("); // no-op, current token still points to '('
  Expression *E = readExpr(); // The cycle continues...

Closes #146722

Signed-off-by: Parth Arora <partaror at qti.qualcomm.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list