[PATCH 33744] Check if a section has non-zero linked_to before using it
Jan Beulich
jbeulich@suse.com
Mon Jan 12 16:31:46 GMT 2026
On 10.01.2026 11:23, Zheng Bao wrote:
> Updated, including bugzilla ticket.
Hmm, I'm pretty sure ...
> ________________________________
> From: H.J. Lu <hjl.tools@gmail.com>
> Sent: Saturday, January 10, 2026 9:31 AM
> To: Zheng Bao <fishbaoz@hotmail.com>
> Cc: Binutils <binutils@sourceware.org>
> Subject: Re: [PATCH 33744] Check if a section has non-zero linked_to before using it
>
> On Sat, Jan 10, 2026, 2:54 PM Zheng Bao <fishbaoz@hotmail.com<mailto:fishbaoz@hotmail.com>> wrote:
> https://sourceware.org/bugzilla/show_bug.cgi?id=33744
>
> gas:bfd: Check if a section has non-zero linked_to before using it
>
> The symbol in the section header should be assigned at
> building stage. So it should be section like ".data".
> The section where the symbol is defined should have output
> section. But it is not enough. The common section has output
> section which will not be written into any target section.
> If the symbol is in common section, the linked_to is pointer
> NULL and a segmentation fault comes up.
>
> Test suite:
> .section __patchable_funrtion_entries,"awo",%progbits,foo
> .dc.a .LPFE1
> .comm foo,8
>
> This test should be included in the patch.
... this was meant as "included as a new testcase", not just by extending
the description.
Jan
> The changes in _bfd_elf_copy_special_section_fields is a similar
> change. It also need to check before using it.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33744
> Signed-off-by: Zheng Bao <fishbaoz@hotmail.com<mailto:fishbaoz@hotmail.com>>
>
> diff --git a/bfd/elf.c b/bfd/elf.c
> index 8b6dd3ce370..41d550205ae 100644
> --- a/bfd/elf.c
> +++ b/bfd/elf.c
> @@ -4322,7 +4322,8 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info)
> s = kept;
> }
> /* Handle objcopy. */
> - else if (s->output_section == NULL)
> + else if (s->output_section == NULL
> + || elf_section_data(s->output_section) == NULL)
> {
> _bfd_error_handler
> /* xgettext:c-format */
> @@ -13831,7 +13832,8 @@ _bfd_elf_copy_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
>
> if (isection == NULL
> || isection->bfd_section == NULL
> - || isection->bfd_section->output_section == NULL)
> + || isection->bfd_section->output_section == NULL
> + || elf_section_data(isection->bfd_section->output_section) == NULL)
> {
> _bfd_error_handler
> /* xgettext:c-format */
> diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
> index 579c1df2dc3..fb082e4c0c5 100644
> --- a/gas/config/obj-elf.c
> +++ b/gas/config/obj-elf.c
> @@ -2508,6 +2508,8 @@ set_additional_section_info (bfd *abfd,
> sec->map_head.linked_to_symbol_name,
> bfd_section_name (sec));
> else
> + /* TODO: If the symbol is defined in common section, it can not
> + * be initialized at linking stage. */
> elf_linked_to_section (sec) = S_GET_SEGMENT (linked_to_sym);
> }
>
>
> Not sure if posting to bugzilla is enough. So I also send to the maillist.
> Please review.
>
> Zheng
>
>
More information about the Binutils
mailing list