[PATCH 33744] Check if a section has non-zero linked_to before using it
H.J. Lu
hjl.tools@gmail.com
Sat Jan 10 09:31:51 GMT 2026
On Sat, Jan 10, 2026, 2:54 PM Zheng Bao <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.
> 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>
>
> 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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20260110/606524e3/attachment.htm>
More information about the Binutils
mailing list