aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2009-03-04 05:50:50 +0000
committerAlan Modra <amodra@gmail.com>2009-03-04 05:50:50 +0000
commit727fc41e077139570ea8b8ddfd6c546b2a55627c (patch)
treecb2e0c6f5409224e1658daa9ca5b8e8fea3a4503 /bfd
parent51dec22749b3733b1fa3df0c1290a50967887ccf (diff)
downloadgdb-727fc41e077139570ea8b8ddfd6c546b2a55627c.zip
gdb-727fc41e077139570ea8b8ddfd6c546b2a55627c.tar.gz
gdb-727fc41e077139570ea8b8ddfd6c546b2a55627c.tar.bz2
include/elf/
* ppc.h (R_PPC_TLSGD, R_PPC_TLSLD): Add new relocs. * ppc64.h (R_PPC64_TLSGD, R_PPC64_TLSLD): Add new relocs. bfd/ * reloc.c (BFD_RELOC_PPC_TLSGD, BFD_RELOC_PPC_TLSLD): New. * section.c (struct bfd_section): Add has_tls_get_addr_call. (BFD_FAKE_SECTION): Init new flag. * ecoff.c (bfd_debug_section): Likewise. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. * elf32-ppc.c (ppc_elf_howto_raw): Add R_PPC_TLSGD and R_PPC_TLSLD. (ppc_elf_reloc_type_lookup): Handle new relocs. (ppc_elf_check_relocs): Set has_tls_get_addr_call on finding such without marker relocs. (ppc_elf_tls_optimize): Allow out-of-order __tls_get_addr relocs if section has no old-style calls. (ppc_elf_relocate_section): Set tls_mask for non-tls relocs too. Don't try to optimize new-style __tls_get_addr call when handling arg setup relocs. Instead do so for R_PPC_TLSGD and R_PPC_TLSLD relocs. * elf64-ppc.c (ppc64_elf_howto_raw): Add R_PPC64_TLSGD, R_PPC64_TLSLD. (ppc64_elf_reloc_type_lookup): Handle new relocs. (ppc64_elf_check_relocs): Set has_tls_get_addr_call on finding such without marker relocs. (ppc64_elf_tls_optimize): Allow out-of-order __tls_get_addr relocs if section has no old-style calls. Set toc_ref for new relocs as appropriate. (ppc64_elf_relocate_section): Set tls_mask for non-tls relocs too. Don't try to optimize new-style __tls_get_addr call when handling arg setup relocs. Instead do so for R_PPC_TLSGD and R_PPC_TLSLD relocs. gas/ * config/tc-ppc.c (ppc_elf_suffix): Error if ppc32 tls got relocs have non-zero addend. (md_assemble): Parse args of __tls_get_addr calls. (md_apply_fix): Handle BFD_RELOC_PPC_TLSGD and BFD_RELOC_PPC_TLSLD. ld/testsuite/ * ld-powerpc/tlsmark.s, * ld-powerpc/tlsmark.d: New test. * ld-powerpc/tlsmark32.s, * ld-powerpc/tlsmark32.d: New test. * ld-powerpc/powerpc.exp: Run them.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog30
-rw-r--r--bfd/bfd-in2.h13
-rw-r--r--bfd/ecoff.c11
-rw-r--r--bfd/elf32-ppc.c192
-rw-r--r--bfd/elf64-ppc.c280
-rw-r--r--bfd/libbfd.h2
-rw-r--r--bfd/reloc.c4
-rw-r--r--bfd/section.c13
8 files changed, 459 insertions, 86 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 817726f..444d13e 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,35 @@
2009-03-04 Alan Modra <amodra@bigpond.net.au>
+ * reloc.c (BFD_RELOC_PPC_TLSGD, BFD_RELOC_PPC_TLSLD): New.
+ * section.c (struct bfd_section): Add has_tls_get_addr_call.
+ (BFD_FAKE_SECTION): Init new flag.
+ * ecoff.c (bfd_debug_section): Likewise.
+ * bfd-in2.h: Regenerate.
+ * libbfd.h: Regenerate.
+ * elf32-ppc.c (ppc_elf_howto_raw): Add R_PPC_TLSGD and R_PPC_TLSLD.
+ (ppc_elf_reloc_type_lookup): Handle new relocs.
+ (ppc_elf_check_relocs): Set has_tls_get_addr_call on finding such
+ without marker relocs.
+ (ppc_elf_tls_optimize): Allow out-of-order __tls_get_addr relocs
+ if section has no old-style calls.
+ (ppc_elf_relocate_section): Set tls_mask for non-tls relocs too.
+ Don't try to optimize new-style __tls_get_addr call when handling
+ arg setup relocs. Instead do so for R_PPC_TLSGD and R_PPC_TLSLD
+ relocs.
+ * elf64-ppc.c (ppc64_elf_howto_raw): Add R_PPC64_TLSGD, R_PPC64_TLSLD.
+ (ppc64_elf_reloc_type_lookup): Handle new relocs.
+ (ppc64_elf_check_relocs): Set has_tls_get_addr_call on finding such
+ without marker relocs.
+ (ppc64_elf_tls_optimize): Allow out-of-order __tls_get_addr relocs
+ if section has no old-style calls. Set toc_ref for new relocs as
+ appropriate.
+ (ppc64_elf_relocate_section): Set tls_mask for non-tls relocs too.
+ Don't try to optimize new-style __tls_get_addr call when handling
+ arg setup relocs. Instead do so for R_PPC_TLSGD and R_PPC_TLSLD
+ relocs.
+
+2009-03-04 Alan Modra <amodra@bigpond.net.au>
+
PR 6768
* configure.in: Test for ld --as-needed support. Link shared
libbfd against libm.
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index be35ac4..e7942c3 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -1343,6 +1343,9 @@ typedef struct bfd_section
/* Nonzero if this section has TLS related relocations. */
unsigned int has_tls_reloc:1;
+ /* Nonzero if this section has a call to __tls_get_addr. */
+ unsigned int has_tls_get_addr_call:1;
+
/* Nonzero if this section has a gp reloc. */
unsigned int has_gp_reloc:1;
@@ -1603,11 +1606,11 @@ extern asection bfd_ind_section;
/* segment_mark, sec_info_type, use_rela_p, has_tls_reloc, */ \
0, 0, 0, 0, \
\
- /* has_gp_reloc, need_finalize_relax, reloc_done, */ \
- 0, 0, 0, \
+ /* has_tls_get_addr_call, has_gp_reloc, need_finalize_relax, */ \
+ 0, 0, 0, \
\
- /* vma, lma, size, rawsize */ \
- 0, 0, 0, 0, \
+ /* reloc_done, vma, lma, size, rawsize */ \
+ 0, 0, 0, 0, 0, \
\
/* output_offset, output_section, alignment_power, */ \
0, (struct bfd_section *) &SEC, 0, \
@@ -2928,6 +2931,8 @@ relaxation. */
/* PowerPC and PowerPC64 thread-local storage relocations. */
BFD_RELOC_PPC_TLS,
+ BFD_RELOC_PPC_TLSGD,
+ BFD_RELOC_PPC_TLSLD,
BFD_RELOC_PPC_DTPMOD,
BFD_RELOC_PPC_TPREL16,
BFD_RELOC_PPC_TPREL16_LO,
diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index a78273e..4d27740 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -1,6 +1,7 @@
/* Generic ECOFF (Extended-COFF) routines.
Copyright 1990, 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
- 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+ 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+ Free Software Foundation, Inc.
Original version by Per Bothner.
Full support added by Ian Lance Taylor, ian@cygnus.com.
@@ -59,10 +60,10 @@ static asection bfd_debug_section =
0, 0, 1,
/* segment_mark, sec_info_type, use_rela_p, has_tls_reloc, */
0, 0, 0, 0,
- /* has_gp_reloc, need_finalize_relax, reloc_done, */
- 0, 0, 0,
- /* vma, lma, size, rawsize, */
- 0, 0, 0, 0,
+ /* has_tls_get_addr_call, has_gp_reloc, need_finalize_relax, */
+ 0, 0, 0,
+ /* reloc_done, vma, lma, size, rawsize, */
+ 0, 0, 0, 0, 0,
/* output_offset, output_section, alignment_power, */
0, NULL, 0,
/* relocation, orelocation, reloc_count, filepos, rel_filepos, */
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index ac416ba..5db64b0 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -753,7 +753,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
0xffff, /* dst_mask */
FALSE), /* pcrel_offset */
- /* Marker reloc for TLS. */
+ /* Marker relocs for TLS. */
HOWTO (R_PPC_TLS,
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
@@ -768,6 +768,34 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
0, /* dst_mask */
FALSE), /* pcrel_offset */
+ HOWTO (R_PPC_TLSGD,
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_PPC_TLSGD", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_PPC_TLSLD,
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_PPC_TLSLD", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
/* Computes the load module index of the load module that contains the
definition of its TLS sym. */
HOWTO (R_PPC_DTPMOD32,
@@ -1531,6 +1559,8 @@ ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
+ case BFD_RELOC_PPC_TLSGD: r = R_PPC_TLSGD; break;
+ case BFD_RELOC_PPC_TLSLD: r = R_PPC_TLSLD; break;
case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
@@ -3288,6 +3318,7 @@ ppc_elf_check_relocs (bfd *abfd,
const Elf_Internal_Rela *rel;
const Elf_Internal_Rela *rel_end;
asection *got2, *sreloc;
+ struct elf_link_hash_entry *tga;
if (info->relocatable)
return TRUE;
@@ -3313,6 +3344,8 @@ ppc_elf_check_relocs (bfd *abfd,
ppc_elf_howto_init ();
htab = ppc_elf_hash_table (info);
+ tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
+ FALSE, FALSE, TRUE);
symtab_hdr = &elf_symtab_hdr (abfd);
sym_hashes = elf_sym_hashes (abfd);
got2 = bfd_get_section_by_name (abfd, ".got2");
@@ -3324,7 +3357,7 @@ ppc_elf_check_relocs (bfd *abfd,
unsigned long r_symndx;
enum elf_ppc_reloc_type r_type;
struct elf_link_hash_entry *h;
- int tls_type = 0;
+ int tls_type;
r_symndx = ELF32_R_SYM (rel->r_info);
if (r_symndx < symtab_hdr->sh_info)
@@ -3351,9 +3384,44 @@ ppc_elf_check_relocs (bfd *abfd,
BFD_ASSERT (h == htab->elf.hgot);
}
+ tls_type = 0;
r_type = ELF32_R_TYPE (rel->r_info);
+ if (h != NULL && h == tga)
+ switch (r_type)
+ {
+ default:
+ break;
+
+ case R_PPC_PLTREL24:
+ case R_PPC_LOCAL24PC:
+ case R_PPC_REL24:
+ case R_PPC_REL14:
+ case R_PPC_REL14_BRTAKEN:
+ case R_PPC_REL14_BRNTAKEN:
+ case R_PPC_ADDR24:
+ case R_PPC_ADDR14:
+ case R_PPC_ADDR14_BRTAKEN:
+ case R_PPC_ADDR14_BRNTAKEN:
+ if (rel != relocs
+ && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD
+ || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD))
+ /* We have a new-style __tls_get_addr call with a marker
+ reloc. */
+ ;
+ else
+ /* Mark this section as having an old-style call. */
+ sec->has_tls_get_addr_call = 1;
+ break;
+ }
+
switch (r_type)
{
+ case R_PPC_TLSGD:
+ case R_PPC_TLSLD:
+ /* These special tls relocs tie a call to __tls_get_addr with
+ its parameter symbol. */
+ break;
+
case R_PPC_GOT_TLSLD16:
case R_PPC_GOT_TLSLD16_LO:
case R_PPC_GOT_TLSLD16_HI:
@@ -3607,7 +3675,7 @@ ppc_elf_check_relocs (bfd *abfd,
/* This refers only to functions defined in the shared library. */
case R_PPC_LOCAL24PC:
- if (h && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
+ if (h != NULL && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
{
htab->plt_type = PLT_OLD;
htab->old_bfd = abfd;
@@ -4484,7 +4552,8 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
if (pass == 0)
{
- if (!expecting_tls_get_addr)
+ if (!expecting_tls_get_addr
+ || !sec->has_tls_get_addr_call)
continue;
if (rel + 1 < relend
@@ -6234,16 +6303,13 @@ ppc_elf_relocate_section (bfd *output_bfd,
for the final instruction stream. */
tls_mask = 0;
tls_gd = 0;
- if (IS_PPC_TLS_RELOC (r_type))
+ if (h != NULL)
+ tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
+ else if (local_got_offsets != NULL)
{
- if (h != NULL)
- tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
- else if (local_got_offsets != NULL)
- {
- char *lgot_masks;
- lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
- tls_mask = lgot_masks[r_symndx];
- }
+ char *lgot_masks;
+ lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
+ tls_mask = lgot_masks[r_symndx];
}
/* Ensure reloc mapping code below stays sane. */
@@ -6361,7 +6427,17 @@ ppc_elf_relocate_section (bfd *output_bfd,
bfd_vma offset;
tls_ldgd_opt:
- offset = rel[1].r_offset;
+ offset = (bfd_vma) -1;
+ /* If not using the newer R_PPC_TLSGD/LD to mark
+ __tls_get_addr calls, we must trust that the call
+ stays with its arg setup insns, ie. that the next
+ reloc is the __tls_get_addr call associated with
+ the current reloc. Edit both insns. */
+ if (input_section->has_tls_get_addr_call
+ && rel + 1 < relend
+ && branch_reloc_hash_match (input_bfd, rel + 1,
+ htab->tls_get_addr))
+ offset = rel[1].r_offset;
if ((tls_mask & tls_gd) != 0)
{
/* IE */
@@ -6369,9 +6445,14 @@ ppc_elf_relocate_section (bfd *output_bfd,
contents + rel->r_offset - d_offset);
insn1 &= (1 << 26) - 1;
insn1 |= 32 << 26; /* lwz */
- insn2 = 0x7c631214; /* add 3,3,2 */
- rel[1].r_info
- = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info), R_PPC_NONE);
+ if (offset != (bfd_vma) -1)
+ {
+ rel[1].r_info
+ = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info),
+ R_PPC_NONE);
+ insn2 = 0x7c631214; /* add 3,3,2 */
+ bfd_put_32 (output_bfd, insn2, contents + offset);
+ }
r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
+ R_PPC_GOT_TPREL16);
rel->r_info = ELF32_R_INFO (r_symndx, r_type);
@@ -6380,7 +6461,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
{
/* LE */
insn1 = 0x3c620000; /* addis 3,2,0 */
- insn2 = 0x38630000; /* addi 3,3,0 */
if (tls_gd == 0)
{
/* Was an LD reloc. */
@@ -6399,14 +6479,17 @@ ppc_elf_relocate_section (bfd *output_bfd,
}
r_type = R_PPC_TPREL16_HA;
rel->r_info = ELF32_R_INFO (r_symndx, r_type);
- rel[1].r_info = ELF32_R_INFO (r_symndx,
- R_PPC_TPREL16_LO);
- rel[1].r_offset += d_offset;
- rel[1].r_addend = rel->r_addend;
+ if (offset != (bfd_vma) -1)
+ {
+ rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
+ rel[1].r_offset = offset + d_offset;
+ rel[1].r_addend = rel->r_addend;
+ insn2 = 0x38630000; /* addi 3,3,0 */
+ bfd_put_32 (output_bfd, insn2, contents + offset);
+ }
}
bfd_put_32 (output_bfd, insn1,
contents + rel->r_offset - d_offset);
- bfd_put_32 (output_bfd, insn2, contents + offset);
if (tls_gd == 0)
{
/* We changed the symbol on an LD reloc. Start over
@@ -6416,6 +6499,66 @@ ppc_elf_relocate_section (bfd *output_bfd,
}
}
break;
+
+ case R_PPC_TLSGD:
+ if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
+ {
+ unsigned int insn2;
+ bfd_vma offset = rel->r_offset;
+
+ if ((tls_mask & TLS_TPRELGD) != 0)
+ {
+ /* IE */
+ r_type = R_PPC_NONE;
+ insn2 = 0x7c631214; /* add 3,3,2 */
+ }
+ else
+ {
+ /* LE */
+ r_type = R_PPC_TPREL16_LO;
+ rel->r_offset += d_offset;
+ insn2 = 0x38630000; /* addi 3,3,0 */
+ }
+ rel->r_info = ELF32_R_INFO (r_symndx, r_type);
+ bfd_put_32 (output_bfd, insn2, contents + offset);
+ /* Zap the reloc on the _tls_get_addr call too. */
+ BFD_ASSERT (offset == rel[1].r_offset);
+ rel[1].r_info = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info),
+ R_PPC_NONE);
+ }
+ break;
+
+ case R_PPC_TLSLD:
+ if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
+ {
+ unsigned int insn2;
+
+ for (r_symndx = 0;
+ r_symndx < symtab_hdr->sh_info;
+ r_symndx++)
+ if (local_sections[r_symndx] == sec)
+ break;
+ if (r_symndx >= symtab_hdr->sh_info)
+ r_symndx = 0;
+ rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
+ if (r_symndx != 0)
+ rel->r_addend -= (local_syms[r_symndx].st_value
+ + sec->output_offset
+ + sec->output_section->vma);
+
+ rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
+ rel->r_offset += d_offset;
+ insn2 = 0x38630000; /* addi 3,3,0 */
+ bfd_put_32 (output_bfd, insn2,
+ contents + rel->r_offset - d_offset);
+ /* Zap the reloc on the _tls_get_addr call too. */
+ BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset);
+ rel[1].r_info = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info),
+ R_PPC_NONE);
+ rel--;
+ continue;
+ }
+ break;
}
/* Handle other relocations that tweak non-addend part of insn. */
@@ -6468,6 +6611,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
case R_PPC_NONE:
case R_PPC_TLS:
+ case R_PPC_TLSGD:
+ case R_PPC_TLSLD:
case R_PPC_EMB_MRKREF:
case R_PPC_GNU_VTINHERIT:
case R_PPC_GNU_VTENTRY:
@@ -6509,6 +6654,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
case R_PPC_GOT16_LO:
case R_PPC_GOT16_HI:
case R_PPC_GOT16_HA:
+ tls_mask = 0;
dogot:
{
/* Relocation is to the entry for this symbol in the global
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index 703a2b3..1873728 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -1235,7 +1235,7 @@ static reloc_howto_type ppc64_elf_howto_raw[] = {
0xfffc, /* dst_mask */
FALSE), /* pcrel_offset */
- /* Marker reloc for TLS. */
+ /* Marker relocs for TLS. */
HOWTO (R_PPC64_TLS,
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
@@ -1250,6 +1250,34 @@ static reloc_howto_type ppc64_elf_howto_raw[] = {
0, /* dst_mask */
FALSE), /* pcrel_offset */
+ HOWTO (R_PPC64_TLSGD,
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_PPC64_TLSGD", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_PPC64_TLSLD,
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_PPC64_TLSLD", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
/* Computes the load module index of the load module that contains the
definition of its TLS sym. */
HOWTO (R_PPC64_DTPMOD64,
@@ -2031,6 +2059,10 @@ ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
break;
case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS;
break;
+ case BFD_RELOC_PPC_TLSGD: r = R_PPC64_TLSGD;
+ break;
+ case BFD_RELOC_PPC_TLSLD: r = R_PPC64_TLSLD;
+ break;
case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64;
break;
case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16;
@@ -4644,7 +4676,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
unsigned long r_symndx;
struct elf_link_hash_entry *h;
enum elf_ppc64_reloc_type r_type;
- int tls_type = 0;
+ int tls_type;
struct _ppc64_elf_section_data *ppc64_sec;
r_symndx = ELF64_R_SYM (rel->r_info);
@@ -4658,9 +4690,42 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
h = (struct elf_link_hash_entry *) h->root.u.i.link;
}
+ tls_type = 0;
r_type = ELF64_R_TYPE (rel->r_info);
+ if (h != NULL && (h == tga || h == dottga))
+ switch (r_type)
+ {
+ default:
+ break;
+
+ case R_PPC64_REL24:
+ case R_PPC64_REL14:
+ case R_PPC64_REL14_BRTAKEN:
+ case R_PPC64_REL14_BRNTAKEN:
+ case R_PPC64_ADDR24:
+ case R_PPC64_ADDR14:
+ case R_PPC64_ADDR14_BRTAKEN:
+ case R_PPC64_ADDR14_BRNTAKEN:
+ if (rel != relocs
+ && (ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSGD
+ || ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSLD))
+ /* We have a new-style __tls_get_addr call with a marker
+ reloc. */
+ ;
+ else
+ /* Mark this section as having an old-style call. */
+ sec->has_tls_get_addr_call = 1;
+ break;
+ }
+
switch (r_type)
{
+ case R_PPC64_TLSGD:
+ case R_PPC64_TLSLD:
+ /* These special tls relocs tie a call to __tls_get_addr with
+ its parameter symbol. */
+ break;
+
case R_PPC64_GOT_TLSLD16:
case R_PPC64_GOT_TLSLD16_LO:
case R_PPC64_GOT_TLSLD16_HI:
@@ -7072,6 +7137,8 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
case R_PPC64_TOC16:
case R_PPC64_TOC16_LO:
case R_PPC64_TLS:
+ case R_PPC64_TLSGD:
+ case R_PPC64_TLSLD:
if (sym_sec == NULL || sym_sec != toc)
continue;
@@ -7092,7 +7159,9 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
value += rel->r_addend;
BFD_ASSERT (value < toc->size && value % 8 == 0);
toc_ref_index = value / 8;
- if (r_type == R_PPC64_TLS)
+ if (r_type == R_PPC64_TLS
+ || r_type == R_PPC64_TLSGD
+ || r_type == R_PPC64_TLSLD)
{
toc_ref[toc_ref_index] = 1;
continue;
@@ -7157,7 +7226,8 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
if (pass == 0)
{
- if (!expecting_tls_get_addr)
+ if (!expecting_tls_get_addr
+ || !sec->has_tls_get_addr_call)
continue;
if (rel + 1 < relend
@@ -7276,18 +7346,18 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
free (relstart);
}
- if (toc_ref != NULL)
- free (toc_ref);
+ if (toc_ref != NULL)
+ free (toc_ref);
- if (locsyms != NULL
- && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms))
- {
- if (!info->keep_memory)
- free (locsyms);
- else
- elf_symtab_hdr (ibfd).contents = (unsigned char *) locsyms;
- }
- }
+ if (locsyms != NULL
+ && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms))
+ {
+ if (!info->keep_memory)
+ free (locsyms);
+ else
+ elf_symtab_hdr (ibfd).contents = (unsigned char *) locsyms;
+ }
+ }
return TRUE;
}
@@ -10288,28 +10358,28 @@ ppc64_elf_relocate_section (bfd *output_bfd,
tls_mask = 0;
tls_gd = 0;
toc_symndx = 0;
- if (IS_PPC64_TLS_RELOC (r_type))
+ if (h != NULL)
+ tls_mask = h->tls_mask;
+ else if (local_got_ents != NULL)
{
- if (h != NULL)
- tls_mask = h->tls_mask;
- else if (local_got_ents != NULL)
- {
- char *lgot_masks;
- lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info);
- tls_mask = lgot_masks[r_symndx];
- }
- if (tls_mask == 0 && r_type == R_PPC64_TLS)
- {
- /* Check for toc tls entries. */
- char *toc_tls;
+ char *lgot_masks;
+ lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info);
+ tls_mask = lgot_masks[r_symndx];
+ }
+ if (tls_mask == 0
+ && (r_type == R_PPC64_TLS
+ || r_type == R_PPC64_TLSGD
+ || r_type == R_PPC64_TLSLD))
+ {
+ /* Check for toc tls entries. */
+ char *toc_tls;
- if (!get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
- &local_syms, rel, input_bfd))
- return FALSE;
+ if (!get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
+ &local_syms, rel, input_bfd))
+ return FALSE;
- if (toc_tls)
- tls_mask = *toc_tls;
- }
+ if (toc_tls)
+ tls_mask = *toc_tls;
}
/* Check that tls relocs are used with tls syms, and non-tls
@@ -10324,7 +10394,10 @@ ppc64_elf_relocate_section (bfd *output_bfd,
|| (sym_type == STT_SECTION
&& (sec->flags & SEC_THREAD_LOCAL) != 0))))
{
- if (r_type == R_PPC64_TLS && tls_mask != 0)
+ if (tls_mask != 0
+ && (r_type == R_PPC64_TLS
+ || r_type == R_PPC64_TLSGD
+ || r_type == R_PPC64_TLSLD))
/* R_PPC64_TLS is OK against a symbol in the TOC. */
;
else
@@ -10520,9 +10593,18 @@ ppc64_elf_relocate_section (bfd *output_bfd,
bfd_vma offset;
tls_ldgd_opt:
- /* We know that the next reloc is on a tls_get_addr
- call, since ppc64_elf_tls_optimize checks this. */
- offset = rel[1].r_offset;
+ offset = (bfd_vma) -1;
+ /* If not using the newer R_PPC64_TLSGD/LD to mark
+ __tls_get_addr calls, we must trust that the call
+ stays with its arg setup insns, ie. that the next
+ reloc is the __tls_get_addr call associated with
+ the current reloc. Edit both insns. */
+ if (input_section->has_tls_get_addr_call
+ && rel + 1 < relend
+ && branch_reloc_hash_match (input_bfd, rel + 1,
+ htab->tls_get_addr,
+ htab->tls_get_addr_fd))
+ offset = rel[1].r_offset;
if ((tls_mask & tls_gd) != 0)
{
/* IE */
@@ -10531,8 +10613,9 @@ ppc64_elf_relocate_section (bfd *output_bfd,
insn1 &= (1 << 26) - (1 << 2);
insn1 |= 58 << 26; /* ld */
insn2 = 0x7c636a14; /* add 3,3,13 */
- rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel[1].r_info),
- R_PPC64_NONE);
+ if (offset != (bfd_vma) -1)
+ rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel[1].r_info),
+ R_PPC64_NONE);
if ((tls_mask & TLS_EXPLICIT) == 0)
r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
+ R_PPC64_GOT_TPREL16_DS);
@@ -10570,34 +10653,131 @@ ppc64_elf_relocate_section (bfd *output_bfd,
}
r_type = R_PPC64_TPREL16_HA;
rel->r_info = ELF64_R_INFO (r_symndx, r_type);
- rel[1].r_info = ELF64_R_INFO (r_symndx,
- R_PPC64_TPREL16_LO);
- rel[1].r_offset += d_offset;
- rel[1].r_addend = rel->r_addend;
+ if (offset != (bfd_vma) -1)
+ {
+ rel[1].r_info = ELF64_R_INFO (r_symndx,
+ R_PPC64_TPREL16_LO);
+ rel[1].r_offset = offset + d_offset;
+ rel[1].r_addend = rel->r_addend;
+ }
}
bfd_put_32 (output_bfd, insn1,
contents + rel->r_offset - d_offset);
+ if (offset != (bfd_vma) -1)
+ {
+ insn3 = bfd_get_32 (output_bfd,
+ contents + offset + 4);
+ if (insn3 == NOP
+ || insn3 == CROR_151515 || insn3 == CROR_313131)
+ {
+ rel[1].r_offset += 4;
+ bfd_put_32 (output_bfd, insn2, contents + offset + 4);
+ insn2 = NOP;
+ }
+ bfd_put_32 (output_bfd, insn2, contents + offset);
+ }
+ if ((tls_mask & tls_gd) == 0
+ && (tls_gd == 0 || toc_symndx != 0))
+ {
+ /* We changed the symbol. Start over in order
+ to get h, sym, sec etc. right. */
+ rel--;
+ continue;
+ }
+ }
+ break;
+
+ case R_PPC64_TLSGD:
+ if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
+ {
+ unsigned int insn2, insn3;
+ bfd_vma offset = rel->r_offset;
+
+ if ((tls_mask & TLS_TPRELGD) != 0)
+ {
+ /* IE */
+ r_type = R_PPC64_NONE;
+ insn2 = 0x7c636a14; /* add 3,3,13 */
+ }
+ else
+ {
+ /* LE */
+ if (toc_symndx != 0)
+ {
+ r_symndx = toc_symndx;
+ rel->r_addend = toc_addend;
+ }
+ r_type = R_PPC64_TPREL16_LO;
+ rel->r_offset = offset + d_offset;
+ insn2 = 0x38630000; /* addi 3,3,0 */
+ }
+ rel->r_info = ELF64_R_INFO (r_symndx, r_type);
+ /* Zap the reloc on the _tls_get_addr call too. */
+ BFD_ASSERT (offset == rel[1].r_offset);
+ rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel[1].r_info),
+ R_PPC64_NONE);
insn3 = bfd_get_32 (output_bfd,
contents + offset + 4);
if (insn3 == NOP
|| insn3 == CROR_151515 || insn3 == CROR_313131)
{
- rel[1].r_offset += 4;
+ rel->r_offset += 4;
bfd_put_32 (output_bfd, insn2, contents + offset + 4);
insn2 = NOP;
}
bfd_put_32 (output_bfd, insn2, contents + offset);
- if ((tls_mask & tls_gd) == 0
- && (tls_gd == 0 || toc_symndx != 0))
+ if ((tls_mask & TLS_TPRELGD) == 0 && toc_symndx != 0)
{
- /* We changed the symbol. Start over in order
- to get h, sym, sec etc. right. */
rel--;
continue;
}
}
break;
+ case R_PPC64_TLSLD:
+ if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
+ {
+ unsigned int insn2, insn3;
+ bfd_vma offset = rel->r_offset;
+
+ if (toc_symndx)
+ sec = local_sections[toc_symndx];
+ for (r_symndx = 0;
+ r_symndx < symtab_hdr->sh_info;
+ r_symndx++)
+ if (local_sections[r_symndx] == sec)
+ break;
+ if (r_symndx >= symtab_hdr->sh_info)
+ r_symndx = 0;
+ rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
+ if (r_symndx != 0)
+ rel->r_addend -= (local_syms[r_symndx].st_value
+ + sec->output_offset
+ + sec->output_section->vma);
+
+ r_type = R_PPC64_TPREL16_LO;
+ rel->r_info = ELF64_R_INFO (r_symndx, r_type);
+ rel->r_offset = offset + d_offset;
+ /* Zap the reloc on the _tls_get_addr call too. */
+ BFD_ASSERT (offset == rel[1].r_offset);
+ rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel[1].r_info),
+ R_PPC64_NONE);
+ insn2 = 0x38630000; /* addi 3,3,0 */
+ insn3 = bfd_get_32 (output_bfd,
+ contents + offset + 4);
+ if (insn3 == NOP
+ || insn3 == CROR_151515 || insn3 == CROR_313131)
+ {
+ rel->r_offset += 4;
+ bfd_put_32 (output_bfd, insn2, contents + offset + 4);
+ insn2 = NOP;
+ }
+ bfd_put_32 (output_bfd, insn2, contents + offset);
+ rel--;
+ continue;
+ }
+ break;
+
case R_PPC64_DTPMOD64:
if (rel + 1 < relend
&& rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
@@ -10851,6 +11031,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
case R_PPC64_NONE:
case R_PPC64_TLS:
+ case R_PPC64_TLSGD:
+ case R_PPC64_TLSLD:
case R_PPC64_GNU_VTINHERIT:
case R_PPC64_GNU_VTENTRY:
continue;
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index 5814863..9d83209 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -1201,6 +1201,8 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
"BFD_RELOC_PPC64_PLTGOT16_DS",
"BFD_RELOC_PPC64_PLTGOT16_LO_DS",
"BFD_RELOC_PPC_TLS",
+ "BFD_RELOC_PPC_TLSGD",
+ "BFD_RELOC_PPC_TLSLD",
"BFD_RELOC_PPC_DTPMOD",
"BFD_RELOC_PPC_TPREL16",
"BFD_RELOC_PPC_TPREL16_LO",
diff --git a/bfd/reloc.c b/bfd/reloc.c
index 9e61025..5e10e7e 100644
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -2711,6 +2711,10 @@ ENUMDOC
ENUM
BFD_RELOC_PPC_TLS
ENUMX
+ BFD_RELOC_PPC_TLSGD
+ENUMX
+ BFD_RELOC_PPC_TLSLD
+ENUMX
BFD_RELOC_PPC_DTPMOD
ENUMX
BFD_RELOC_PPC_TPREL16
diff --git a/bfd/section.c b/bfd/section.c
index cadba6b..d804dd6 100644
--- a/bfd/section.c
+++ b/bfd/section.c
@@ -1,6 +1,6 @@
/* Object file "section" support for the BFD library.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+ 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
Free Software Foundation, Inc.
Written by Cygnus Support.
@@ -382,6 +382,9 @@ CODE_FRAGMENT
. {* Nonzero if this section has TLS related relocations. *}
. unsigned int has_tls_reloc:1;
.
+. {* Nonzero if this section has a call to __tls_get_addr. *}
+. unsigned int has_tls_get_addr_call:1;
+.
. {* Nonzero if this section has a gp reloc. *}
. unsigned int has_gp_reloc:1;
.
@@ -642,11 +645,11 @@ CODE_FRAGMENT
. {* segment_mark, sec_info_type, use_rela_p, has_tls_reloc, *} \
. 0, 0, 0, 0, \
. \
-. {* has_gp_reloc, need_finalize_relax, reloc_done, *} \
-. 0, 0, 0, \
+. {* has_tls_get_addr_call, has_gp_reloc, need_finalize_relax, *} \
+. 0, 0, 0, \
. \
-. {* vma, lma, size, rawsize *} \
-. 0, 0, 0, 0, \
+. {* reloc_done, vma, lma, size, rawsize *} \
+. 0, 0, 0, 0, 0, \
. \
. {* output_offset, output_section, alignment_power, *} \
. 0, (struct bfd_section *) &SEC, 0, \