summaryrefslogtreecommitdiff
path: root/bfd/elf64-ppc.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2015-08-18 16:43:18 +0930
committerAlan Modra <amodra@gmail.com>2015-08-18 16:43:18 +0930
commit43417696fe32416607940258ded622c121872515 (patch)
tree8e854fe8a7d0d996d5aeb32ef255a5a90808fcec /bfd/elf64-ppc.c
parentf6721e4955d86bf879b5225f2d128a5a8ddfcae8 (diff)
PPC64: Allow .TOC. in linker script to override backend calculated value
bfd/ * elf64-ppc.c (ppc64_elf_func_desc_adjust): Don't redefine .TOC. if already defined, and set linker_def. (ppc64_elf_set_toc): Use .TOC. value if defined other than by the backend. ld/ * ldexp.c (exp_fold_tree_1): Clear linker_def on symbol assignment.
Diffstat (limited to 'bfd/elf64-ppc.c')
-rw-r--r--bfd/elf64-ppc.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index e153ee484b..4db534491f 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -6945,11 +6945,16 @@ ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED,
_bfd_elf_link_hash_hide_symbol (info, htab->elf.hgot, TRUE);
/* Make .TOC. defined so as to prevent it being made dynamic.
The wrong value here is fixed later in ppc64_elf_set_toc. */
+ if (!htab->elf.hgot->def_regular
+ || htab->elf.hgot->root.type != bfd_link_hash_defined)
+ {
+ htab->elf.hgot->root.type = bfd_link_hash_defined;
+ htab->elf.hgot->root.u.def.value = 0;
+ htab->elf.hgot->root.u.def.section = bfd_abs_section_ptr;
+ htab->elf.hgot->def_regular = 1;
+ htab->elf.hgot->root.linker_def = 1;
+ }
htab->elf.hgot->type = STT_OBJECT;
- htab->elf.hgot->root.type = bfd_link_hash_defined;
- htab->elf.hgot->root.u.def.value = 0;
- htab->elf.hgot->root.u.def.section = bfd_abs_section_ptr;
- htab->elf.hgot->def_regular = 1;
htab->elf.hgot->other = ((htab->elf.hgot->other & ~ELF_ST_VISIBILITY (-1))
| STV_HIDDEN);
}
@@ -12539,6 +12544,34 @@ ppc64_elf_set_toc (struct bfd_link_info *info, bfd *obfd)
asection *s;
bfd_vma TOCstart, adjust;
+ if (info != NULL)
+ {
+ struct elf_link_hash_entry *h;
+ struct elf_link_hash_table *htab = elf_hash_table (info);
+
+ if (is_elf_hash_table (htab)
+ && htab->hgot != NULL)
+ h = htab->hgot;
+ else
+ {
+ h = elf_link_hash_lookup (htab, ".TOC.", FALSE, FALSE, TRUE);
+ if (is_elf_hash_table (htab))
+ htab->hgot = h;
+ }
+ if (h != NULL
+ && h->root.type == bfd_link_hash_defined
+ && !h->root.linker_def
+ && (!is_elf_hash_table (htab)
+ || h->def_regular))
+ {
+ TOCstart = (h->root.u.def.value - TOC_BASE_OFF
+ + h->root.u.def.section->output_offset
+ + h->root.u.def.section->output_section->vma);
+ _bfd_set_gp_value (obfd, TOCstart);
+ return TOCstart;
+ }
+ }
+
/* The TOC consists of sections .got, .toc, .tocbss, .plt in that
order. The TOC starts where the first of these sections starts. */
s = bfd_get_section_by_name (obfd, ".got");