This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: linker issue on ppc64el?
- From: Alan Modra <amodra at gmail dot com>
- To: Matthias Klose <doko at debian dot org>
- Cc: binutils at sourceware dot org
- Date: Wed, 14 Mar 2018 22:30:37 +1030
- Subject: Re: linker issue on ppc64el?
- Authentication-results: sourceware.org; auth=none
- References: <ea6a257d-3601-4900-642a-7d576375244b@debian.org>
On Wed, Mar 14, 2018 at 09:27:18AM +0100, Matthias Klose wrote:
> Hi Alan,
>
> would it be possible to have a look at
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=886264
>
> The bug report has an analysis, but no easy reproducer. The binutils 2.30 branch
> is used.
I think I see the problem.
This calculation in relocate_section
if (stub_entry->stub_type == ppc_stub_save_res)
relocation += (stub_sec->output_offset
+ stub_sec->output_section->vma
+ stub_sec->size - htab->sfpr->size
- htab->sfpr->output_offset
- htab->sfpr->output_section->vma);
to adjust from the original out-of-line save/restore function address
in sfpr to a copy at the end of stub_sec goes wrong when stub_sec is
padded, because the copy is no longer at the end of stub_sec. The
solution is to pad before copying sfpr, so the copy is always at the
end of stub_sec.
* elf64-ppc.c (sfpr_define): Adjust for stub_sec size having
sfpr size added before defining alias symbols.
(ppc64_elf_build_stubs): Add stub section padding before
copying sfpr contents and defining save/restore alias symbols.
The bug has been lurking since git commit a4b6fadd50, 2015-09-01, but
likely only became evident since git commit 2420fff633, 2017-09-09,
when plt stub alignment was enabled by default.
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index 44237bc..889bdb0 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -6660,7 +6660,7 @@ sfpr_define (struct bfd_link_info *info,
{
s->root.type = bfd_link_hash_defined;
s->root.u.def.section = stub_sec;
- s->root.u.def.value = (stub_sec->size
+ s->root.u.def.value = (stub_sec->size - htab->sfpr->size
+ h->elf.root.u.def.value);
s->ref_regular = 1;
s->def_regular = 1;
@@ -13247,20 +13247,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
for (group = htab->group; group != NULL; group = group->next)
if (group->needs_save_res)
- {
- stub_sec = group->stub_sec;
- memcpy (stub_sec->contents + stub_sec->size, htab->sfpr->contents,
- htab->sfpr->size);
- if (htab->params->emit_stub_syms)
- {
- unsigned int i;
-
- for (i = 0; i < ARRAY_SIZE (save_res_funcs); i++)
- if (!sfpr_define (info, &save_res_funcs[i], stub_sec))
- return FALSE;
- }
- stub_sec->size += htab->sfpr->size;
- }
+ group->stub_sec->size += htab->sfpr->size;
if (htab->relbrlt != NULL)
htab->relbrlt->reloc_count = 0;
@@ -13274,6 +13261,22 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
}
for (group = htab->group; group != NULL; group = group->next)
+ if (group->needs_save_res)
+ {
+ stub_sec = group->stub_sec;
+ memcpy (stub_sec->contents + stub_sec->size - htab->sfpr->size,
+ htab->sfpr->contents, htab->sfpr->size);
+ if (htab->params->emit_stub_syms)
+ {
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE (save_res_funcs); i++)
+ if (!sfpr_define (info, &save_res_funcs[i], stub_sec))
+ return FALSE;
+ }
+ }
+
+ for (group = htab->group; group != NULL; group = group->next)
if ((stub_sec = group->stub_sec) != NULL)
{
stub_sec_count += 1;
--
Alan Modra
Australia Development Lab, IBM