[PATCH v1] ld: fix segfault when linker script is not found
Jan Beulich
jbeulich@suse.com
Tue Sep 9 10:43:22 GMT 2025
On 04.09.2025 17:19, Matthieu Longo wrote:
> ld previously crashed with a segmentation fault if the specified linker
> script could not be found. Surprisingly, ldfile_find_command_file() has
> never covered the very common case where an invalid filename was set.
Imo that's not a correct way to put it. You may want to take a look at the
2.40 variant of the function, where everything was still fine afaics. It
was a later addition which wasn't done as carefully as would have been
needed. (The same change also looks to have introduced a UBSAN issue, in
that struct script_name_list has an array-of-1-element field instead of a
flexible array member.)
> --- /dev/null
> +++ b/ld/testsuite/ld-scripts/linker-script-not-found.d
> @@ -0,0 +1,3 @@
> +#source: default-script.s
> +#ld: -T misspelled.ld
> +#error: cannot open linker script file misspelled\.ld: No such file or directory$
Everything up to the latter colon is fine, but can we really expect the
potentially libc-provided error message to exactly match "No such file or
directory"? (I'm not even entirely certain whether ENOENT is the only
possible errno value that can come back here.)
Jan
More information about the Binutils
mailing list