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

"H.J. Lu" <[email protected]> Thu, 30 Jul 2026 14:24:39 +0800
Newsgroups gmane.comp.gnu.binutils
Message-ID <CAMe9rOqXoU7=Cx8MkN5NpZXfL8JVZOC9DQJu9Sn-LGGP5CAiHQ@mail.gmail.com>
On Thu, Jul 30, 2026 at 10:38=E2=80=AFAM Alan Modra <[email protected]> wrot=
e:
>
> 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 >=3D (bfd_vma) -2)
            abort ();

in elf_x86_64_relocate_section since x86-64 linker has

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

I will move the check to x86 backend.


--=20
H.J.