[PATCH v1 3/5] ld: fix segfault on discarded input sections not fitting in memory regions
Matthieu Longo
matthieu.longo@arm.com
Mon Oct 13 15:24:33 GMT 2025
On 2025-09-26 14:18, Jan Beulich wrote:
> On 18.09.2025 17:06, Matthieu Longo wrote:
>> In the case of non-contiguous memory regions, if an input section did not
>> fit in any of the designated memory regions, the linker marked it as
>> discarded, and warn_non_contiguous_discards() would only issue warning on
>> it, relying on later unresolved symbol errors to terminate the process
>> before a crash occur. This approach was insufficient, and crashes did occur
>> on AArch64.
>>
>> This patch renames warn_non_contiguous_discards () to a name that does not
>> contain "discard" as it created some confusion with the /DISCARD/ output
>> section. It also promotes the warnings to errors, and ensures that the
>> link process terminates cleanly if any input section is not allocated to
>> an output section.
>> It also updates an AArch32 test expectations to match the corrected
>> behavior. Tests for the crash cases are added in a subsequent patch.
>
> Looks okay to me, just one style nit:
>
>> @@ -8242,10 +8247,15 @@ warn_non_contiguous_discards (void)
>>
>> for (asection *s = file->the_bfd->sections; s != NULL; s = s->next)
>> if (s->output_section == NULL && !s->veneer)
>> - einfo (_("%P: warning: --enable-non-contiguous-regions "
>> - "discards section `%pA' from `%pB'\n"),
>> - s, file->the_bfd);
>> + {
>> + einfo (_("%P: error: --enable-non-contiguous-regions was not able "
>> + "to allocate the input section `%pA' (%pB) to an output "
>> + "section\n"), s, file->the_bfd);
>
> Please retain original line splitting (no new arguments on the same line as
> an already split argument).
>
> Jan
Fixed in the next revision.
Matthieu
More information about the Binutils
mailing list