bfd_vma plt_off)
{
int stub_align;
- unsigned stub_size = plt_stub_size (htab, stub_entry, plt_off);
+ unsigned stub_size;
bfd_vma stub_off = stub_entry->group->stub_sec->size;
if (htab->params->plt_stub_align >= 0)
}
stub_align = 1 << -htab->params->plt_stub_align;
+ stub_size = plt_stub_size (htab, stub_entry, plt_off);
if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align)
> ((stub_size - 1) & -stub_align))
return stub_align - (stub_off & (stub_align - 1));
struct ppc_link_hash_table *htab;
bfd_byte *loc;
bfd_byte *p;
- bfd_vma dest, off;
+ bfd_vma targ, off;
Elf_Internal_Rela *r;
asection *plt;
if (htab == NULL)
return FALSE;
- /* Make a note of the offset within the stubs for this entry. */
- stub_entry->stub_offset = stub_entry->group->stub_sec->size;
+ BFD_ASSERT (stub_entry->stub_offset >= stub_entry->group->stub_sec->size);
loc = stub_entry->group->stub_sec->contents + stub_entry->stub_offset;
htab->stub_count[stub_entry->stub_type - 1] += 1;
case ppc_stub_long_branch:
case ppc_stub_long_branch_r2off:
/* Branches are relative. This is where we are going to. */
- dest = (stub_entry->target_value
+ targ = (stub_entry->target_value
+ stub_entry->target_section->output_offset
+ stub_entry->target_section->output_section->vma);
- dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
- off = dest;
+ targ += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
/* And this is where we are coming from. */
- off -= (stub_entry->stub_offset
- + stub_entry->group->stub_sec->output_offset
- + stub_entry->group->stub_sec->output_section->vma);
+ off = (stub_entry->stub_offset
+ + stub_entry->group->stub_sec->output_offset
+ + stub_entry->group->stub_sec->output_section->vma);
+ off = targ - off;
p = loc;
if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
return FALSE;
r->r_offset = p - 4 - stub_entry->group->stub_sec->contents;
r->r_info = ELF64_R_INFO (0, R_PPC64_REL24);
- r->r_addend = dest;
+ r->r_addend = targ;
if (stub_entry->h != NULL)
{
struct elf_link_hash_entry **hashes;
return FALSE;
}
- dest = (stub_entry->target_value
+ targ = (stub_entry->target_value
+ stub_entry->target_section->output_offset
+ stub_entry->target_section->output_section->vma);
if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
- dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
+ targ += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
- bfd_put_64 (htab->brlt->owner, dest,
+ bfd_put_64 (htab->brlt->owner, targ,
htab->brlt->contents + br_entry->offset);
if (br_entry->iter == htab->stub_iteration)
+ htab->brlt->output_offset
+ htab->brlt->output_section->vma);
rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
- rela.r_addend = dest;
+ rela.r_addend = targ;
rl = htab->relbrlt->contents;
rl += (htab->relbrlt->reloc_count++
+ htab->brlt->output_offset
+ htab->brlt->output_section->vma);
r->r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
- r->r_addend = dest;
+ r->r_addend = targ;
}
}
- dest = (br_entry->offset
+ targ = (br_entry->offset
+ htab->brlt->output_offset
+ htab->brlt->output_section->vma);
- off = (dest
- - elf_gp (info->output_bfd)
- - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ off = (elf_gp (info->output_bfd)
+ + htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ off = targ - off;
if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
{
if (stub_entry->stub_type == ppc_stub_plt_branch_r2off)
r[0].r_offset += 4;
r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
- r[0].r_addend = dest;
+ r[0].r_addend = targ;
if (PPC_HA (off) != 0)
{
r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
}
/* Now build the stub. */
- dest = stub_entry->plt_ent->plt.offset & ~1;
- if (dest >= (bfd_vma) -2)
+ targ = stub_entry->plt_ent->plt.offset & ~1;
+ if (targ >= (bfd_vma) -2)
abort ();
plt = htab->elf.splt;
else
plt = htab->pltlocal;
}
+ targ += plt->output_offset + plt->output_section->vma;
- dest += plt->output_offset + plt->output_section->vma;
-
- off = (dest
- - elf_gp (info->output_bfd)
- - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ off = (elf_gp (info->output_bfd)
+ + htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ off = targ - off;
if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
{
return FALSE;
}
- if (htab->params->plt_stub_align != 0)
- {
- unsigned pad = plt_stub_pad (htab, stub_entry, off);
-
- stub_entry->group->stub_sec->size += pad;
- stub_entry->stub_offset = stub_entry->group->stub_sec->size;
- loc += pad;
- }
-
r = NULL;
if (info->emitrelocations)
{
r[0].r_offset = loc - stub_entry->group->stub_sec->contents;
if (bfd_big_endian (info->output_bfd))
r[0].r_offset += 2;
- r[0].r_addend = dest;
+ r[0].r_addend = targ;
}
if (stub_entry->h != NULL
&& (stub_entry->h == htab->tls_get_addr_fd
return FALSE;
}
- stub_entry->group->stub_sec->size += p - loc;
+ stub_entry->group->stub_sec->size = stub_entry->stub_offset + (p - loc);
if (htab->params->emit_stub_syms)
{
struct ppc_stub_hash_entry *stub_entry;
struct bfd_link_info *info;
struct ppc_link_hash_table *htab;
- bfd_vma off;
+ bfd_vma targ, off;
int size;
/* Massage our args to the form they really have. */
if (htab == NULL)
return FALSE;
+ /* Make a note of the offset within the stubs for this entry. */
+ stub_entry->stub_offset = stub_entry->group->stub_sec->size;
+
if (stub_entry->h != NULL
&& stub_entry->h->save_res
&& stub_entry->h->elf.root.type == bfd_link_hash_defined
|| stub_entry->stub_type == ppc_stub_plt_call_r2save)
{
asection *plt;
- off = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1;
- if (off >= (bfd_vma) -2)
+ targ = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1;
+ if (targ >= (bfd_vma) -2)
abort ();
plt = htab->elf.splt;
if (!htab->elf.dynamic_sections_created
else
plt = htab->pltlocal;
}
- off += (plt->output_offset
- + plt->output_section->vma
- - elf_gp (info->output_bfd)
- - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ targ += plt->output_offset + plt->output_section->vma;
+
+ off = (elf_gp (info->output_bfd)
+ + htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ off = targ - off;
+
+ if (htab->params->plt_stub_align != 0)
+ {
+ unsigned pad = plt_stub_pad (htab, stub_entry, off);
+
+ stub_entry->group->stub_sec->size += pad;
+ stub_entry->stub_offset = stub_entry->group->stub_sec->size;
+ }
size = plt_stub_size (htab, stub_entry, off);
+
if (stub_entry->h != NULL
&& (stub_entry->h == htab->tls_get_addr_fd
|| stub_entry->h == htab->tls_get_addr)
&& (ALWAYS_EMIT_R2SAVE
|| stub_entry->stub_type == ppc_stub_plt_call_r2save))
stub_entry->group->tls_get_addr_opt_bctrl
- = stub_entry->group->stub_sec->size + size - 5 * 4;
+ = stub_entry->stub_offset + size - 5 * 4;
- if (htab->params->plt_stub_align)
- size += plt_stub_pad (htab, stub_entry, off);
if (info->emitrelocations)
{
stub_entry->group->stub_sec->reloc_count
bfd_vma r2off = 0;
bfd_vma local_off = 0;
- off = (stub_entry->target_value
- + stub_entry->target_section->output_offset
- + stub_entry->target_section->output_section->vma);
- off -= (stub_entry->group->stub_sec->size
- + stub_entry->group->stub_sec->output_offset
- + stub_entry->group->stub_sec->output_section->vma);
+ targ = (stub_entry->target_value
+ + stub_entry->target_section->output_offset
+ + stub_entry->target_section->output_section->vma);
+ off = (stub_entry->stub_offset
+ + stub_entry->group->stub_sec->output_offset
+ + stub_entry->group->stub_sec->output_section->vma);
/* Reset the stub type from the plt variant in case we now
can reach with a shorter stub. */
size += 4;
if (PPC_LO (r2off) != 0)
size += 4;
- off -= size - 4;
+ off += size - 4;
}
+ off = targ - off;
local_off = PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
}
stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch;
- off = (br_entry->offset
- + htab->brlt->output_offset
- + htab->brlt->output_section->vma
- - elf_gp (info->output_bfd)
- - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ targ = (br_entry->offset
+ + htab->brlt->output_offset
+ + htab->brlt->output_section->vma);
+ off = (elf_gp (info->output_bfd)
+ + htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ off = targ - off;
if (info->emitrelocations)
{
Disassembly of section \.text:
+.* <.*\.plt_call\.foo>:
+.*: (18 00 41 f8|f8 41 00 18) std r2,24\(r1\)
+.*: (28 80 82 e9|e9 82 80 28) ld r12,-32728\(r2\)
+.*: (a6 03 89 7d|7d 89 03 a6) mtctr r12
+.*: (20 04 80 4e|4e 80 04 20) bctr
+ \.\.\.
+
.* <.*\.plt_call\.__tls_get_addr_opt@@GLIBC_2\.22>:
.*: (00 00 63 e9|e9 63 00 00) ld r11,0\(r3\)
.*: (08 00 83 e9|e9 83 00 08) ld r12,8\(r3\)
.*: (a6 02 68 7d|7d 68 02 a6) mflr r11
.*: (08 00 61 f9|f9 61 00 08) std r11,8\(r1\)
.*: (18 00 41 f8|f8 41 00 18) std r2,24\(r1\)
-.*: (28 80 82 e9|e9 82 80 28) ld r12,-32728\(r2\)
+.*: (30 80 82 e9|e9 82 80 30) ld r12,-32720\(r2\)
.*: (a6 03 89 7d|7d 89 03 a6) mtctr r12
.*: (21 04 80 4e|4e 80 04 21) bctrl
.*: (18 00 41 e8|e8 41 00 18) ld r2,24\(r1\)
.*: (08 00 61 e9|e9 61 00 08) ld r11,8\(r1\)
.*: (a6 03 68 7d|7d 68 03 a6) mtlr r11
.*: (20 00 80 4e|4e 80 00 20) blr
+ \.\.\.
.* <_start>:
.*: (08 80 62 38|38 62 80 08) addi r3,r2,-32760
-.*: (b9 ff ff 4b|4b ff ff b9) bl .*
+.*: (9d ff ff 4b|4b ff ff 9d) bl .* <.*\.plt_call\.__tls_get_addr_opt@@GLIBC_2\.22>
+.*: (00 00 00 60|60 00 00 00) nop
+.*: (75 ff ff 4b|4b ff ff 75) bl .* <.*\.plt_call\.foo>
+.*: (18 00 41 e8|e8 41 00 18) ld r2,24\(r1\)
.*: (00 00 00 60|60 00 00 00) nop
.*
.*
.*: (08 00 6b e9|e9 6b 00 08) ld r11,8\(r11\)
.*: (20 04 80 4e|4e 80 04 20) bctr
+.* <foo@plt>:
+.* (c8 ff ff 4b|4b ff ff c8) b .*
+
.* <__tls_get_addr_opt@plt>:
-.*: (c8 ff ff 4b|4b ff ff c8) b .*
+.*: (c4 ff ff 4b|4b ff ff c4) b .*