Re: Use stub bfd for dynobj

Alan Modra <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
On Thu, Aug 20, 2026 at 11:49:46AM +0200, Andreas Schwab wrote:
> You can find /home/schwab/ld-test.tar.xz on cfarm13.cfarm.net which
> contains the input files and a script to reproduce the issue.

Thanks.  It is an ordering problem.

This loop in elflink.c:_bfd_elf_final_link
  for (o = obfd->sections; o != NULL; o = o->next)
    {
      for (p = o->map_head.link_order; p != NULL; p = p->next)
	{
	  if (p->type == bfd_indirect_link_order
	      && (bfd_get_flavour ((sub = p->u.indirect.section->owner))
		  == bfd_target_elf_flavour)
	      && elf_elfheader (sub)->e_ident[EI_CLASS] == obed->s->elfclass)
	    {
	      if (! sub->output_has_begun)
		{
		  if (! elf_link_input_bfd (&flinfo, sub))
		    goto error_return;
		  sub->output_has_begun = true;
		}
	    }
passes the "linker stubs" to elf_link_input_bfd much earlier when
dynobj is using the stub bfd.  That's because .interp is early in the
output bfd sections and dynobj provides .interp.  So the stubs get
written out early, before _bfd_aarch64_erratum_843419_branch_to_stub
has a chance to copy the insn to the stub.

Prior to commit e189bfd9b4 the "linker stubs" bfd typically was passed
to elf_link_input_bfd when the output bfd .text section was reached,
and that mostly allowed _bfd_aarch64_erratum_843419_branch_to_stub to
work.  It's quite fragile though, and certainly could be broken with
user linker scripts.

-- 
Alan Modra
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.