ld previously crashed with a segmentation fault if the specified linker
script could not be found. The issue seems to have been introduced
recently by
d048eee2910 [1].
This patch adds a check to ensure that a filename was found after
searching the possible prefixes. If no filename was found, the function
returns NULL, and ldfile_open_command_file_1() emits a proper fatal
error message.
This change prevents the crash and provides a clear diagnostic.
A new generic test was also added to cover this error case.
[1]: https://inbox.sourceware.org/binutils/
20250812143757.
3565482-1-hjl
.tools@gmail.com/
/* Restore the original path list. */
*search_tail_ptr = NULL;
+ if (!filename)
+ return NULL;
+
success:
/* PR 24576: Catch the case where the user has accidentally included
the same linker script twice. */
--- /dev/null
+#source: default-script.s
+#ld: -T misspelled.ld
+#error: cannot open linker script file misspelled\.ld: .*\Z
run_dump_test "ld-version-2"
run_dump_test "pr24576-1"
run_dump_test "pr24576-2"
+run_dump_test "linker-script-not-found"
run_dump_test "segment-start" {{name (default)}}
run_dump_test "segment-start" {{name (overridden)} \