[PATCH] elf: Handle the section flag 'o' linked to special sections
H.J. Lu
hjl.tools@gmail.com
Sun Jan 11 04:03:19 GMT 2026
On Sat, Jan 10, 2026 at 6:23 PM Zheng Bao <fishbaoz@hotmail.com> wrote:
>
> Updated, including bugzilla ticket.
>
> Zheng
>
> ________________________________
> 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> 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>
>
The patch is wrong. Here is a simple fix with tests.
--
H.J.
Call _bfd_elf_section_from_bfd_section to get the sh_link value from
the section flag 'o' directive, which may point to special sections,
like SHN_ABS or SHN_COMM. Update readelf to print the special section
names in the sh_link field.
bfd/
PR gas/33744
* elf.c (assign_section_numbers): Call
_bfd_elf_section_from_bfd_section to get the sh_link value.
binutils/
PR gas/33744
* readelf.c (special_defined_section_index): New.
(get_32bit_section_headers): Don't warn special section indexes
in the sh_link field.
(get_64bit_section_headers): Likewise.
(process_section_headers): Print special section names.
gas/
PR gas/33744
* testsuite/gas/elf/elf.exp: Run PR gas/33744 tests.
* testsuite/gas/elf/sh-link-abs-1.d: New file.
* testsuite/gas/elf/sh-link-abs-2.d: Likewise.
* testsuite/gas/elf/sh-link-abs-3-32.d: Likewise.
* testsuite/gas/elf/sh-link-abs-3-64.d: Likewise.
* testsuite/gas/elf/sh-link-abs-4-32.d: Likewise.
* testsuite/gas/elf/sh-link-abs-4-64.d: Likewise.
* testsuite/gas/elf/sh-link-abs.s: Likewise.
* testsuite/gas/elf/sh-link-common-1.d: Likewise.
* testsuite/gas/elf/sh-link-common-2.d: Likewise.
* testsuite/gas/elf/sh-link-common-3-32.d: Likewise.
* testsuite/gas/elf/sh-link-common-3-64.d: Likewise.
* testsuite/gas/elf/sh-link-common-4-32.d: Likewise.
* testsuite/gas/elf/sh-link-common-4-64.d: Likewise.
* testsuite/gas/elf/sh-link-common.s: Likewise.
* testsuite/gas/elf/sh-link-large-common-1.d: Likewise.
* testsuite/gas/elf/sh-link-large-common-2.d: Likewise.
* testsuite/gas/elf/sh-link-large-common-3.d: Likewise.
* testsuite/gas/elf/sh-link-large-common-4.d: Likewise.
* testsuite/gas/elf/sh-link-large-common.s: Likewise.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-elf-Handle-the-section-flag-o-linked-to-special-sect.patch
Type: text/x-patch
Size: 20115 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20260111/f7d08aee/attachment-0001.bin>
More information about the Binutils
mailing list