[PATCH v2 1/5] ld: fix segfault caused by untagged stub sections

Jan Beulich jbeulich@suse.com
Wed Oct 15 13:03:39 GMT 2025


On 14.10.2025 12:46, Matthieu Longo wrote:
> In the case of non-contiguous memory regions, a far-call stub section
> must be assigned to the memory of the section it was originally emitted
> for. If the stub section does not fit, the section is marked as dropped,
> and removed later. To emit a useful message to the user, however, a stub
> section needs to be discernible from sections originating from input
> objects.
> 
> Previously [1], this distinction was made using the SEC_LINKER_CREATED
> flag only in the AArch32 backend handler <arch>_add_stub_section. Other
> backends that didn't set this flag on their stub sections skipped required
> checks in ld/ldlang.c:size_input_section(). On AArch64, this caused the
> linker to proceed into code paths that assumed output sections were set,
> instead of reporting fatal errors, and ultimately led to a segmentation
> fault.
> 
> However, the SEC_LINKER_CREATED flag does not solely indicate that a
> section was created by the linker. Its original meaning also meant that
> the section should not be handled by the generic relocation code. Reusing
> this flag to identify stub sections, while it appeared to fix the issue,
> introduced unintended side effects. On PowerPC, for instance, it skipped
> relocations present in the stubs and interpreted them as absolute
> addresses.
> 
> This patch proposes a new attribute 'veneer', indicating that a section
> contains branch veneers. The attribute is set on AArch32, AArch64 and
> PowerPC immediately after the creation of the stub section. Others
> architectures are left unchanged, as they do not appear to support
> non-contiguous memory regions (no tests were found to verify the fix).
> Additionally, the diagnostic message was improved when a stub cannot be
> placed in the same memory region as its referencing code.
> 
> [1]: abf874a, Add support for non-contiguous memory regions.

Provided sufficiently wide testing (as also indicated by Christophe), okay.

> --- a/bfd/bfd-in2.h
> +++ b/bfd/bfd-in2.h
> @@ -702,6 +702,12 @@ typedef struct bfd_section
>    /* Nonzero if section contents should not be freed.  */
>    unsigned int alloced:1;
>  
> +  /* Indicate that the section contains branch veneers.  This is used when
> +     support for non-contiguous memory regions is enabled.  The veneers have
> +     to be allocated to the same memory region as the code they are refered
> +     by, i.e. they cannot be moved to a subsequent memory region.  */
> +  unsigned int veneer : 1;

General remark: Now that we use C99, bit fields like this one would likely
better be bool.

Jan


More information about the Binutils mailing list