]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
ld: Issue an error if group nested too deeply
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 15 Aug 2025 13:18:30 +0000 (06:18 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 18 Aug 2025 12:13:57 +0000 (05:13 -0700)
commit4e46c5a14f39342897cfcb7ecb9c0270f30247f4
tree0898957c1ad6ddd58e06c5ef5fb1da224ed3997f
parent570f4c0c11910d845c35e94764ded54cb1111583
ld: Issue an error if group nested too deeply

If a linker script has a group nested too deeply by mistake, issue an
error instead of hanging forever without outputting any error message.

PR ld/33265
* ldlang.c (MAX_NESTED_GROUP_DEPTH): New.
(open_input_bfds): Add a pointer argument for the nested group
count.  Increment the count before the while loop and decrement
it after the loop.  Issue an error if the nested group count >=
MAX_NESTED_GROUP_DEPTH when processing input statement.
(lang_process): Update open_input_bfds calls.
(cmdline_emit_object_only_section): Likewise.
* testsuite/ld-scripts/libpr33265-1.a: New file.
* testsuite/ld-scripts/libpr33265-2.a: Likewise.
* testsuite/ld-scripts/libpr33265-3a.a: Likewise.
* testsuite/ld-scripts/libpr33265-3b.a: Likewise.
* testsuite/ld-scripts/libpr33265-3c.a: Likewise.
* testsuite/ld-scripts/pr33265-1.d: Likewise.
* testsuite/ld-scripts/pr33265-2.d: Likewise.
* testsuite/ld-scripts/pr33265-3.d: Likewise.
* testsuite/ld-scripts/script.exp: Run PR ld/33265 tests.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
ld/ldlang.c
ld/testsuite/ld-scripts/libpr33265-1.a [new file with mode: 0644]
ld/testsuite/ld-scripts/libpr33265-2.a [new file with mode: 0644]
ld/testsuite/ld-scripts/libpr33265-3a.a [new file with mode: 0644]
ld/testsuite/ld-scripts/libpr33265-3b.a [new file with mode: 0644]
ld/testsuite/ld-scripts/libpr33265-3c.a [new file with mode: 0644]
ld/testsuite/ld-scripts/pr33265-1.d [new file with mode: 0644]
ld/testsuite/ld-scripts/pr33265-2.d [new file with mode: 0644]
ld/testsuite/ld-scripts/pr33265-3.d [new file with mode: 0644]
ld/testsuite/ld-scripts/script.exp