[PATCH] elf: Avoid relocating non-allocated code sections

H.J. Lu hjl.tools@gmail.com
Thu Jul 30 06:24:39 GMT 2026


On Thu, Jul 30, 2026 at 10:38 AM Alan Modra <amodra@gmail.com> wrote:
>
> On Thu, Jul 30, 2026 at 08:33:19AM +0800, H.J. Lu wrote:
> > Since non-allocated code sections can't be properly relocated, issue an
> > error on such input.
> >
> > PR ld/34444
> > * elflink.c (elf_link_input_bfd): Issue an error on a non-allocated
> > code section.
>
> This is not a proper fix for the bug, which is caused by a reloc offset
> out of range.  The weird flags are just something you see with fuzzed
> object files.  You could likely modify the flags to something more
> normal and would still see the buffer overflow.

If input code section doesn't have SEC_ALLOC, x86-64 linker may abort
at

          if (off >= (bfd_vma) -2)
            abort ();

in elf_x86_64_relocate_section since x86-64 linker has

  if ((input_section->flags & SEC_ALLOC) != 0
...
  if ((input_section->flags & SEC_ALLOC) == 0)

I will move the check to x86 backend.


-- 
H.J.


More information about the Binutils mailing list