Automatic date update in version.in
[deliverable/binutils-gdb.git] / bfd / elf64-ppc.c
index 4eba829450845b0cfa3328aebb93328ca08e3e87..a4a05302a6ad17d1a8f918dae34203903808c149 100644 (file)
@@ -1,5 +1,5 @@
 /* PowerPC64-specific support for 64-bit ELF.
-   Copyright (C) 1999-2019 Free Software Foundation, Inc.
+   Copyright (C) 1999-2021 Free Software Foundation, Inc.
    Written by Linus Nordberg, Swox AB <info@swox.com>,
    based on elf32-ppc.c by Ian Lance Taylor.
    Largely rewritten by Alan Modra.
@@ -25,6 +25,9 @@
    http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
    http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html  */
 
+/* Don't generate unused section symbols.  */
+#define TARGET_KEEP_UNUSED_SECTION_SYMBOLS false
+
 #include "sysdep.h"
 #include <stdarg.h>
 #include "bfd.h"
@@ -35,6 +38,9 @@
 #include "elf64-ppc.h"
 #include "dwarf2.h"
 
+/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1.  */
+#define OCTETS_PER_BYTE(ABFD, SEC) 1
+
 static bfd_reloc_status_type ppc64_elf_ha_reloc
   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
 static bfd_reloc_status_type ppc64_elf_branch_reloc
@@ -56,7 +62,7 @@ static bfd_reloc_status_type ppc64_elf_prefix_reloc
 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
 static bfd_vma opd_entry_value
-  (asection *, bfd_vma, asection **, bfd_vma *, bfd_boolean);
+  (asection *, bfd_vma, asection **, bfd_vma *, bool);
 
 #define TARGET_LITTLE_SYM      powerpc_elf64_le_vec
 #define TARGET_LITTLE_NAME     "elf64-powerpcle"
@@ -111,7 +117,7 @@ static bfd_vma opd_entry_value
 #define elf_backend_adjust_dynamic_symbol     ppc64_elf_adjust_dynamic_symbol
 #define elf_backend_hide_symbol                      ppc64_elf_hide_symbol
 #define elf_backend_maybe_function_sym       ppc64_elf_maybe_function_sym
-#define elf_backend_always_size_sections      ppc64_elf_func_desc_adjust
+#define elf_backend_always_size_sections      ppc64_elf_edit
 #define elf_backend_size_dynamic_sections     ppc64_elf_size_dynamic_sections
 #define elf_backend_hash_symbol                      ppc64_elf_hash_symbol
 #define elf_backend_init_index_section       _bfd_elf_init_2_index_sections
@@ -122,6 +128,7 @@ static bfd_vma opd_entry_value
 #define elf_backend_finish_dynamic_sections   ppc64_elf_finish_dynamic_sections
 #define elf_backend_link_output_symbol_hook   ppc64_elf_output_symbol_hook
 #define elf_backend_special_sections         ppc64_elf_special_sections
+#define elf_backend_section_flags            ppc64_elf_section_flags
 #define elf_backend_merge_symbol_attribute    ppc64_elf_merge_symbol_attribute
 #define elf_backend_merge_symbol             ppc64_elf_merge_symbol
 #define elf_backend_get_reloc_section        bfd_get_section_by_name
@@ -207,9 +214,10 @@ static bfd_vma opd_entry_value
 #define PLD_R12_PC     0x04100000e5800000ULL
 #define PNOP           0x0700000000000000ULL
 
-/* __glink_PLTresolve stub instructions.  We enter with the index in R0.  */
+/* __glink_PLTresolve stub instructions.  We enter with the index in
+   R0 for ELFv1, and the address of a glink branch in R12 for ELFv2.  */
 #define GLINK_PLTRESOLVE_SIZE(htab)                    \
-  (8u + (htab->opd_abi ? 11 * 4 : 14 * 4))
+  (8u + (htab->opd_abi ? 11 * 4 : htab->has_plt_localentry0 ? 14 * 4 : 13 * 4))
                                        /* 0:                           */
                                        /*  .quad plt0-1f               */
                                        /* __glink:                     */
@@ -225,11 +233,14 @@ static bfd_vma opd_entry_value
                                        /*  mtctr %12                   */
                                        /*  ld %11,16(%11)              */
                                        /*  bctr                        */
-#define MFLR_R0                0x7c0802a6      /*  mflr %r0                    */
-#define MTLR_R0                0x7c0803a6      /*  mtlr %r0                    */
-#define SUB_R12_R12_R11        0x7d8b6050      /*  subf %r12,%r11,%r12         */
-#define ADDI_R0_R12    0x380c0000      /*  addi %r0,%r12,0             */
-#define SRDI_R0_R0_2   0x7800f082      /*  rldicl %r0,%r0,62,2         */
+
+#define MFLR_R0                0x7c0802a6      /* mflr %r0                     */
+#define MTLR_R0                0x7c0803a6      /* mtlr %r0                     */
+#define SUB_R12_R12_R11        0x7d8b6050      /* subf %r12,%r11,%r12          */
+#define ADDI_R0_R12    0x380c0000      /* addi %r0,%r12,0              */
+#define SRDI_R0_R0_2   0x7800f082      /* rldicl %r0,%r0,62,2          */
+#define LD_R0_0R11     0xe80b0000      /* ld %r0,0(%r11)               */
+#define ADD_R11_R0_R11 0x7d605a14      /* add %r11,%r0,%r11            */
 
 /* Pad with this.  */
 #define NOP            0x60000000
@@ -297,101 +308,101 @@ set_abiversion (bfd *abfd, int ver)
            complain, special_func)                             \
   HOWTO (type, rightshift, size, bitsize, pc_relative, 0,      \
         complain_overflow_ ## complain, special_func,          \
-        #type, FALSE, 0, mask, pc_relative)
+        #type, false, 0, mask, pc_relative)
 
 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max];
 
 static reloc_howto_type ppc64_elf_howto_raw[] =
 {
   /* This reloc does nothing.  */
-  HOW (R_PPC64_NONE, 3, 0, 0, 0, FALSE, dont,
+  HOW (R_PPC64_NONE, 3, 0, 0, 0, false, dont,
        bfd_elf_generic_reloc),
 
   /* A standard 32 bit relocation.  */
-  HOW (R_PPC64_ADDR32, 2, 32, 0xffffffff, 0, FALSE, bitfield,
+  HOW (R_PPC64_ADDR32, 2, 32, 0xffffffff, 0, false, bitfield,
        bfd_elf_generic_reloc),
 
   /* An absolute 26 bit branch; the lower two bits must be zero.
      FIXME: we don't check that, we just clear them.  */
-  HOW (R_PPC64_ADDR24, 2, 26, 0x03fffffc, 0, FALSE, bitfield,
+  HOW (R_PPC64_ADDR24, 2, 26, 0x03fffffc, 0, false, bitfield,
        bfd_elf_generic_reloc),
 
   /* A standard 16 bit relocation.  */
-  HOW (R_PPC64_ADDR16, 1, 16, 0xffff, 0, FALSE, bitfield,
+  HOW (R_PPC64_ADDR16, 1, 16, 0xffff, 0, false, bitfield,
        bfd_elf_generic_reloc),
 
   /* A 16 bit relocation without overflow.  */
-  HOW (R_PPC64_ADDR16_LO, 1, 16, 0xffff, 0, FALSE, dont,
+  HOW (R_PPC64_ADDR16_LO, 1, 16, 0xffff, 0, false, dont,
        bfd_elf_generic_reloc),
 
   /* Bits 16-31 of an address.  */
-  HOW (R_PPC64_ADDR16_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_ADDR16_HI, 1, 16, 0xffff, 16, false, signed,
        bfd_elf_generic_reloc),
 
   /* Bits 16-31 of an address, plus 1 if the contents of the low 16
      bits, treated as a signed number, is negative.  */
-  HOW (R_PPC64_ADDR16_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_ADDR16_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_ha_reloc),
 
   /* An absolute 16 bit branch; the lower two bits must be zero.
      FIXME: we don't check that, we just clear them.  */
-  HOW (R_PPC64_ADDR14, 2, 16, 0x0000fffc, 0, FALSE, signed,
+  HOW (R_PPC64_ADDR14, 2, 16, 0x0000fffc, 0, false, signed,
        ppc64_elf_branch_reloc),
 
   /* An absolute 16 bit branch, for which bit 10 should be set to
      indicate that the branch is expected to be taken.  The lower two
      bits must be zero.  */
-  HOW (R_PPC64_ADDR14_BRTAKEN, 2, 16, 0x0000fffc, 0, FALSE, signed,
+  HOW (R_PPC64_ADDR14_BRTAKEN, 2, 16, 0x0000fffc, 0, false, signed,
        ppc64_elf_brtaken_reloc),
 
   /* An absolute 16 bit branch, for which bit 10 should be set to
      indicate that the branch is not expected to be taken.  The lower
      two bits must be zero.  */
-  HOW (R_PPC64_ADDR14_BRNTAKEN, 2, 16, 0x0000fffc, 0, FALSE, signed,
+  HOW (R_PPC64_ADDR14_BRNTAKEN, 2, 16, 0x0000fffc, 0, false, signed,
        ppc64_elf_brtaken_reloc),
 
   /* A relative 26 bit branch; the lower two bits must be zero.  */
-  HOW (R_PPC64_REL24, 2, 26, 0x03fffffc, 0, TRUE, signed,
+  HOW (R_PPC64_REL24, 2, 26, 0x03fffffc, 0, true, signed,
        ppc64_elf_branch_reloc),
 
   /* A variant of R_PPC64_REL24, used when r2 is not the toc pointer.  */
-  HOW (R_PPC64_REL24_NOTOC, 2, 26, 0x03fffffc, 0, TRUE, signed,
+  HOW (R_PPC64_REL24_NOTOC, 2, 26, 0x03fffffc, 0, true, signed,
        ppc64_elf_branch_reloc),
 
   /* A relative 16 bit branch; the lower two bits must be zero.  */
-  HOW (R_PPC64_REL14, 2, 16, 0x0000fffc, 0, TRUE, signed,
+  HOW (R_PPC64_REL14, 2, 16, 0x0000fffc, 0, true, signed,
        ppc64_elf_branch_reloc),
 
   /* A relative 16 bit branch.  Bit 10 should be set to indicate that
      the branch is expected to be taken.  The lower two bits must be
      zero.  */
-  HOW (R_PPC64_REL14_BRTAKEN, 2, 16, 0x0000fffc, 0, TRUE, signed,
+  HOW (R_PPC64_REL14_BRTAKEN, 2, 16, 0x0000fffc, 0, true, signed,
        ppc64_elf_brtaken_reloc),
 
   /* A relative 16 bit branch.  Bit 10 should be set to indicate that
      the branch is not expected to be taken.  The lower two bits must
      be zero.  */
-  HOW (R_PPC64_REL14_BRNTAKEN, 2, 16, 0x0000fffc, 0, TRUE, signed,
+  HOW (R_PPC64_REL14_BRNTAKEN, 2, 16, 0x0000fffc, 0, true, signed,
        ppc64_elf_brtaken_reloc),
 
   /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
      symbol.  */
-  HOW (R_PPC64_GOT16, 1, 16, 0xffff, 0, FALSE, signed,
+  HOW (R_PPC64_GOT16, 1, 16, 0xffff, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
      the symbol.  */
-  HOW (R_PPC64_GOT16_LO, 1, 16, 0xffff, 0, FALSE, dont,
+  HOW (R_PPC64_GOT16_LO, 1, 16, 0xffff, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
      the symbol.  */
-  HOW (R_PPC64_GOT16_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_GOT16_HI, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
      the symbol.  */
-  HOW (R_PPC64_GOT16_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_GOT16_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* This is used only by the dynamic linker.  The symbol should exist
@@ -399,148 +410,148 @@ static reloc_howto_type ppc64_elf_howto_raw[] =
      dynamic linker copies the data addressed by the symbol from the
      shared library into the object, because the object being
      run has to have the data at some particular address.  */
-  HOW (R_PPC64_COPY, 0, 0, 0, 0, FALSE, dont,
+  HOW (R_PPC64_COPY, 0, 0, 0, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_ADDR64, but used when setting global offset table
      entries.  */
-  HOW (R_PPC64_GLOB_DAT, 4, 64, 0xffffffffffffffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_GLOB_DAT, 4, 64, 0xffffffffffffffffULL, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Created by the link editor.  Marks a procedure linkage table
      entry for a symbol.  */
-  HOW (R_PPC64_JMP_SLOT, 0, 0, 0, 0, FALSE, dont,
+  HOW (R_PPC64_JMP_SLOT, 0, 0, 0, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Used only by the dynamic linker.  When the object is run, this
      doubleword64 is set to the load address of the object, plus the
      addend.  */
-  HOW (R_PPC64_RELATIVE, 4, 64, 0xffffffffffffffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_RELATIVE, 4, 64, 0xffffffffffffffffULL, 0, false, dont,
        bfd_elf_generic_reloc),
 
   /* Like R_PPC64_ADDR32, but may be unaligned.  */
-  HOW (R_PPC64_UADDR32, 2, 32, 0xffffffff, 0, FALSE, bitfield,
+  HOW (R_PPC64_UADDR32, 2, 32, 0xffffffff, 0, false, bitfield,
        bfd_elf_generic_reloc),
 
   /* Like R_PPC64_ADDR16, but may be unaligned.  */
-  HOW (R_PPC64_UADDR16, 1, 16, 0xffff, 0, FALSE, bitfield,
+  HOW (R_PPC64_UADDR16, 1, 16, 0xffff, 0, false, bitfield,
        bfd_elf_generic_reloc),
 
   /* 32-bit PC relative.  */
-  HOW (R_PPC64_REL32, 2, 32, 0xffffffff, 0, TRUE, signed,
+  HOW (R_PPC64_REL32, 2, 32, 0xffffffff, 0, true, signed,
        bfd_elf_generic_reloc),
 
   /* 32-bit relocation to the symbol's procedure linkage table.  */
-  HOW (R_PPC64_PLT32, 2, 32, 0xffffffff, 0, FALSE, bitfield,
+  HOW (R_PPC64_PLT32, 2, 32, 0xffffffff, 0, false, bitfield,
        ppc64_elf_unhandled_reloc),
 
   /* 32-bit PC relative relocation to the symbol's procedure linkage table.
      FIXME: R_PPC64_PLTREL32 not supported.  */
-  HOW (R_PPC64_PLTREL32, 2, 32, 0xffffffff, 0, TRUE, signed,
+  HOW (R_PPC64_PLTREL32, 2, 32, 0xffffffff, 0, true, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
      the symbol.  */
-  HOW (R_PPC64_PLT16_LO, 1, 16, 0xffff, 0, FALSE, dont,
+  HOW (R_PPC64_PLT16_LO, 1, 16, 0xffff, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
      the symbol.  */
-  HOW (R_PPC64_PLT16_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_PLT16_HI, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
      the symbol.  */
-  HOW (R_PPC64_PLT16_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_PLT16_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* 16-bit section relative relocation.  */
-  HOW (R_PPC64_SECTOFF, 1, 16, 0xffff, 0, FALSE, signed,
+  HOW (R_PPC64_SECTOFF, 1, 16, 0xffff, 0, false, signed,
        ppc64_elf_sectoff_reloc),
 
   /* Like R_PPC64_SECTOFF, but no overflow warning.  */
-  HOW (R_PPC64_SECTOFF_LO, 1, 16, 0xffff, 0, FALSE, dont,
+  HOW (R_PPC64_SECTOFF_LO, 1, 16, 0xffff, 0, false, dont,
        ppc64_elf_sectoff_reloc),
 
   /* 16-bit upper half section relative relocation.  */
-  HOW (R_PPC64_SECTOFF_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_SECTOFF_HI, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_sectoff_reloc),
 
   /* 16-bit upper half adjusted section relative relocation.  */
-  HOW (R_PPC64_SECTOFF_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_SECTOFF_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_sectoff_ha_reloc),
 
   /* Like R_PPC64_REL24 without touching the two least significant bits.  */
-  HOW (R_PPC64_REL30, 2, 30, 0xfffffffc, 2, TRUE, dont,
+  HOW (R_PPC64_REL30, 2, 30, 0xfffffffc, 2, true, dont,
        bfd_elf_generic_reloc),
 
   /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI.  */
 
   /* A standard 64-bit relocation.  */
-  HOW (R_PPC64_ADDR64, 4, 64, 0xffffffffffffffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_ADDR64, 4, 64, 0xffffffffffffffffULL, 0, false, dont,
        bfd_elf_generic_reloc),
 
   /* The bits 32-47 of an address.  */
-  HOW (R_PPC64_ADDR16_HIGHER, 1, 16, 0xffff, 32, FALSE, dont,
+  HOW (R_PPC64_ADDR16_HIGHER, 1, 16, 0xffff, 32, false, dont,
        bfd_elf_generic_reloc),
 
   /* The bits 32-47 of an address, plus 1 if the contents of the low
      16 bits, treated as a signed number, is negative.  */
-  HOW (R_PPC64_ADDR16_HIGHERA, 1, 16, 0xffff, 32, FALSE, dont,
+  HOW (R_PPC64_ADDR16_HIGHERA, 1, 16, 0xffff, 32, false, dont,
        ppc64_elf_ha_reloc),
 
   /* The bits 48-63 of an address.  */
-  HOW (R_PPC64_ADDR16_HIGHEST, 1, 16, 0xffff, 48, FALSE, dont,
+  HOW (R_PPC64_ADDR16_HIGHEST, 1, 16, 0xffff, 48, false, dont,
        bfd_elf_generic_reloc),
 
   /* The bits 48-63 of an address, plus 1 if the contents of the low
      16 bits, treated as a signed number, is negative.  */
-  HOW (R_PPC64_ADDR16_HIGHESTA, 1, 16, 0xffff, 48, FALSE, dont,
+  HOW (R_PPC64_ADDR16_HIGHESTA, 1, 16, 0xffff, 48, false, dont,
        ppc64_elf_ha_reloc),
 
   /* Like ADDR64, but may be unaligned.  */
-  HOW (R_PPC64_UADDR64, 4, 64, 0xffffffffffffffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_UADDR64, 4, 64, 0xffffffffffffffffULL, 0, false, dont,
        bfd_elf_generic_reloc),
 
   /* 64-bit relative relocation.  */
-  HOW (R_PPC64_REL64, 4, 64, 0xffffffffffffffffULL, 0, TRUE, dont,
+  HOW (R_PPC64_REL64, 4, 64, 0xffffffffffffffffULL, 0, true, dont,
        bfd_elf_generic_reloc),
 
   /* 64-bit relocation to the symbol's procedure linkage table.  */
-  HOW (R_PPC64_PLT64, 4, 64, 0xffffffffffffffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_PLT64, 4, 64, 0xffffffffffffffffULL, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* 64-bit PC relative relocation to the symbol's procedure linkage
      table.  */
   /* FIXME: R_PPC64_PLTREL64 not supported.  */
-  HOW (R_PPC64_PLTREL64, 4, 64, 0xffffffffffffffffULL, 0, TRUE, dont,
+  HOW (R_PPC64_PLTREL64, 4, 64, 0xffffffffffffffffULL, 0, true, dont,
        ppc64_elf_unhandled_reloc),
 
   /* 16 bit TOC-relative relocation.  */
   /* R_PPC64_TOC16       47       half16*      S + A - .TOC.  */
-  HOW (R_PPC64_TOC16, 1, 16, 0xffff, 0, FALSE, signed,
+  HOW (R_PPC64_TOC16, 1, 16, 0xffff, 0, false, signed,
        ppc64_elf_toc_reloc),
 
   /* 16 bit TOC-relative relocation without overflow.  */
   /* R_PPC64_TOC16_LO    48       half16        #lo (S + A - .TOC.)  */
-  HOW (R_PPC64_TOC16_LO, 1, 16, 0xffff, 0, FALSE, dont,
+  HOW (R_PPC64_TOC16_LO, 1, 16, 0xffff, 0, false, dont,
        ppc64_elf_toc_reloc),
 
   /* 16 bit TOC-relative relocation, high 16 bits.  */
   /* R_PPC64_TOC16_HI    49       half16        #hi (S + A - .TOC.)  */
-  HOW (R_PPC64_TOC16_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_TOC16_HI, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_toc_reloc),
 
   /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
      contents of the low 16 bits, treated as a signed number, is
      negative.  */
   /* R_PPC64_TOC16_HA    50       half16        #ha (S + A - .TOC.)  */
-  HOW (R_PPC64_TOC16_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_TOC16_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_toc_ha_reloc),
 
   /* 64-bit relocation; insert value of TOC base (.TOC.).  */
   /* R_PPC64_TOC                 51       doubleword64  .TOC.  */
-  HOW (R_PPC64_TOC, 4, 64, 0xffffffffffffffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_TOC, 4, 64, 0xffffffffffffffffULL, 0, false, dont,
        ppc64_elf_toc64_reloc),
 
   /* Like R_PPC64_GOT16, but also informs the link editor that the
@@ -552,428 +563,428 @@ static reloc_howto_type ppc64_elf_howto_raw[] =
      The link editor may also skip all of this and just (c) emit a
      R_PPC64_GLOB_DAT to tie the symbol to the GOT entry.  */
   /* FIXME: R_PPC64_PLTGOT16 not implemented.  */
-    HOW (R_PPC64_PLTGOT16, 1, 16, 0xffff, 0, FALSE,signed,
+    HOW (R_PPC64_PLTGOT16, 1, 16, 0xffff, 0, false,signed,
          ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_PLTGOT16, but without overflow.  */
   /* FIXME: R_PPC64_PLTGOT16_LO not implemented.  */
-  HOW (R_PPC64_PLTGOT16_LO, 1, 16, 0xffff, 0, FALSE, dont,
+  HOW (R_PPC64_PLTGOT16_LO, 1, 16, 0xffff, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address.  */
   /* FIXME: R_PPC64_PLTGOT16_HI not implemented.  */
-  HOW (R_PPC64_PLTGOT16_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_PLTGOT16_HI, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
      1 if the contents of the low 16 bits, treated as a signed number,
      is negative.  */
   /* FIXME: R_PPC64_PLTGOT16_HA not implemented.  */
-  HOW (R_PPC64_PLTGOT16_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_PLTGOT16_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_ADDR16, but for instructions with a DS field.  */
-  HOW (R_PPC64_ADDR16_DS, 1, 16, 0xfffc, 0, FALSE, signed,
+  HOW (R_PPC64_ADDR16_DS, 1, 16, 0xfffc, 0, false, signed,
        bfd_elf_generic_reloc),
 
   /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field.  */
-  HOW (R_PPC64_ADDR16_LO_DS, 1, 16, 0xfffc, 0, FALSE, dont,
+  HOW (R_PPC64_ADDR16_LO_DS, 1, 16, 0xfffc, 0, false, dont,
        bfd_elf_generic_reloc),
 
   /* Like R_PPC64_GOT16, but for instructions with a DS field.  */
-  HOW (R_PPC64_GOT16_DS, 1, 16, 0xfffc, 0, FALSE, signed,
+  HOW (R_PPC64_GOT16_DS, 1, 16, 0xfffc, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_GOT16_LO, but for instructions with a DS field.  */
-  HOW (R_PPC64_GOT16_LO_DS, 1, 16, 0xfffc, 0, FALSE, dont,
+  HOW (R_PPC64_GOT16_LO_DS, 1, 16, 0xfffc, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_PLT16_LO, but for instructions with a DS field.  */
-  HOW (R_PPC64_PLT16_LO_DS, 1, 16, 0xfffc, 0, FALSE, dont,
+  HOW (R_PPC64_PLT16_LO_DS, 1, 16, 0xfffc, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_SECTOFF, but for instructions with a DS field.  */
-  HOW (R_PPC64_SECTOFF_DS, 1, 16, 0xfffc, 0, FALSE, signed,
+  HOW (R_PPC64_SECTOFF_DS, 1, 16, 0xfffc, 0, false, signed,
        ppc64_elf_sectoff_reloc),
 
   /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field.  */
-  HOW (R_PPC64_SECTOFF_LO_DS, 1, 16, 0xfffc, 0, FALSE, dont,
+  HOW (R_PPC64_SECTOFF_LO_DS, 1, 16, 0xfffc, 0, false, dont,
        ppc64_elf_sectoff_reloc),
 
   /* Like R_PPC64_TOC16, but for instructions with a DS field.  */
-  HOW (R_PPC64_TOC16_DS, 1, 16, 0xfffc, 0, FALSE, signed,
+  HOW (R_PPC64_TOC16_DS, 1, 16, 0xfffc, 0, false, signed,
        ppc64_elf_toc_reloc),
 
   /* Like R_PPC64_TOC16_LO, but for instructions with a DS field.  */
-  HOW (R_PPC64_TOC16_LO_DS, 1, 16, 0xfffc, 0, FALSE, dont,
+  HOW (R_PPC64_TOC16_LO_DS, 1, 16, 0xfffc, 0, false, dont,
        ppc64_elf_toc_reloc),
 
   /* Like R_PPC64_PLTGOT16, but for instructions with a DS field.  */
   /* FIXME: R_PPC64_PLTGOT16_DS not implemented.  */
-  HOW (R_PPC64_PLTGOT16_DS, 1, 16, 0xfffc, 0, FALSE, signed,
+  HOW (R_PPC64_PLTGOT16_DS, 1, 16, 0xfffc, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field.  */
   /* FIXME: R_PPC64_PLTGOT16_LO not implemented.  */
-  HOW (R_PPC64_PLTGOT16_LO_DS, 1, 16, 0xfffc, 0, FALSE, dont,
+  HOW (R_PPC64_PLTGOT16_LO_DS, 1, 16, 0xfffc, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Marker relocs for TLS.  */
-  HOW (R_PPC64_TLS, 2, 32, 0, 0, FALSE, dont,
+  HOW (R_PPC64_TLS, 2, 32, 0, 0, false, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_TLSGD, 2, 32, 0, 0, FALSE, dont,
+  HOW (R_PPC64_TLSGD, 2, 32, 0, 0, false, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_TLSLD, 2, 32, 0, 0, FALSE, dont,
+  HOW (R_PPC64_TLSLD, 2, 32, 0, 0, false, dont,
        bfd_elf_generic_reloc),
 
   /* Marker reloc for optimizing r2 save in prologue rather than on
      each plt call stub.  */
-  HOW (R_PPC64_TOCSAVE, 2, 32, 0, 0, FALSE, dont,
+  HOW (R_PPC64_TOCSAVE, 2, 32, 0, 0, false, dont,
        bfd_elf_generic_reloc),
 
   /* Marker relocs on inline plt call instructions.  */
-  HOW (R_PPC64_PLTSEQ, 2, 32, 0, 0, FALSE, dont,
+  HOW (R_PPC64_PLTSEQ, 2, 32, 0, 0, false, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_PLTCALL, 2, 32, 0, 0, FALSE, dont,
+  HOW (R_PPC64_PLTCALL, 2, 32, 0, 0, false, dont,
        bfd_elf_generic_reloc),
 
   /* Computes the load module index of the load module that contains the
      definition of its TLS sym.  */
-  HOW (R_PPC64_DTPMOD64, 4, 64, 0xffffffffffffffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_DTPMOD64, 4, 64, 0xffffffffffffffffULL, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Computes a dtv-relative displacement, the difference between the value
      of sym+add and the base address of the thread-local storage block that
      contains the definition of sym, minus 0x8000.  */
-  HOW (R_PPC64_DTPREL64, 4, 64, 0xffffffffffffffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_DTPREL64, 4, 64, 0xffffffffffffffffULL, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* A 16 bit dtprel reloc.  */
-  HOW (R_PPC64_DTPREL16, 1, 16, 0xffff, 0, FALSE, signed,
+  HOW (R_PPC64_DTPREL16, 1, 16, 0xffff, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like DTPREL16, but no overflow.  */
-  HOW (R_PPC64_DTPREL16_LO, 1, 16, 0xffff, 0, FALSE, dont,
+  HOW (R_PPC64_DTPREL16_LO, 1, 16, 0xffff, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like DTPREL16_LO, but next higher group of 16 bits.  */
-  HOW (R_PPC64_DTPREL16_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_DTPREL16_HI, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like DTPREL16_HI, but adjust for low 16 bits.  */
-  HOW (R_PPC64_DTPREL16_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_DTPREL16_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like DTPREL16_HI, but next higher group of 16 bits.  */
-  HOW (R_PPC64_DTPREL16_HIGHER, 1, 16, 0xffff, 32, FALSE, dont,
+  HOW (R_PPC64_DTPREL16_HIGHER, 1, 16, 0xffff, 32, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like DTPREL16_HIGHER, but adjust for low 16 bits.  */
-  HOW (R_PPC64_DTPREL16_HIGHERA, 1, 16, 0xffff, 32, FALSE, dont,
+  HOW (R_PPC64_DTPREL16_HIGHERA, 1, 16, 0xffff, 32, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like DTPREL16_HIGHER, but next higher group of 16 bits.  */
-  HOW (R_PPC64_DTPREL16_HIGHEST, 1, 16, 0xffff, 48, FALSE, dont,
+  HOW (R_PPC64_DTPREL16_HIGHEST, 1, 16, 0xffff, 48, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like DTPREL16_HIGHEST, but adjust for low 16 bits.  */
-  HOW (R_PPC64_DTPREL16_HIGHESTA, 1, 16, 0xffff, 48, FALSE, dont,
+  HOW (R_PPC64_DTPREL16_HIGHESTA, 1, 16, 0xffff, 48, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like DTPREL16, but for insns with a DS field.  */
-  HOW (R_PPC64_DTPREL16_DS, 1, 16, 0xfffc, 0, FALSE, signed,
+  HOW (R_PPC64_DTPREL16_DS, 1, 16, 0xfffc, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like DTPREL16_DS, but no overflow.  */
-  HOW (R_PPC64_DTPREL16_LO_DS, 1, 16, 0xfffc, 0, FALSE, dont,
+  HOW (R_PPC64_DTPREL16_LO_DS, 1, 16, 0xfffc, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Computes a tp-relative displacement, the difference between the value of
      sym+add and the value of the thread pointer (r13).  */
-  HOW (R_PPC64_TPREL64, 4, 64, 0xffffffffffffffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_TPREL64, 4, 64, 0xffffffffffffffffULL, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* A 16 bit tprel reloc.  */
-  HOW (R_PPC64_TPREL16, 1, 16, 0xffff, 0, FALSE, signed,
+  HOW (R_PPC64_TPREL16, 1, 16, 0xffff, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like TPREL16, but no overflow.  */
-  HOW (R_PPC64_TPREL16_LO, 1, 16, 0xffff, 0, FALSE, dont,
+  HOW (R_PPC64_TPREL16_LO, 1, 16, 0xffff, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like TPREL16_LO, but next higher group of 16 bits.  */
-  HOW (R_PPC64_TPREL16_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_TPREL16_HI, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like TPREL16_HI, but adjust for low 16 bits.  */
-  HOW (R_PPC64_TPREL16_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_TPREL16_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like TPREL16_HI, but next higher group of 16 bits.  */
-  HOW (R_PPC64_TPREL16_HIGHER, 1, 16, 0xffff, 32, FALSE, dont,
+  HOW (R_PPC64_TPREL16_HIGHER, 1, 16, 0xffff, 32, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like TPREL16_HIGHER, but adjust for low 16 bits.  */
-  HOW (R_PPC64_TPREL16_HIGHERA, 1, 16, 0xffff, 32, FALSE, dont,
+  HOW (R_PPC64_TPREL16_HIGHERA, 1, 16, 0xffff, 32, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like TPREL16_HIGHER, but next higher group of 16 bits.  */
-  HOW (R_PPC64_TPREL16_HIGHEST, 1, 16, 0xffff, 48, FALSE, dont,
+  HOW (R_PPC64_TPREL16_HIGHEST, 1, 16, 0xffff, 48, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like TPREL16_HIGHEST, but adjust for low 16 bits.  */
-  HOW (R_PPC64_TPREL16_HIGHESTA, 1, 16, 0xffff, 48, FALSE, dont,
+  HOW (R_PPC64_TPREL16_HIGHESTA, 1, 16, 0xffff, 48, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like TPREL16, but for insns with a DS field.  */
-  HOW (R_PPC64_TPREL16_DS, 1, 16, 0xfffc, 0, FALSE, signed,
+  HOW (R_PPC64_TPREL16_DS, 1, 16, 0xfffc, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like TPREL16_DS, but no overflow.  */
-  HOW (R_PPC64_TPREL16_LO_DS, 1, 16, 0xfffc, 0, FALSE, dont,
+  HOW (R_PPC64_TPREL16_LO_DS, 1, 16, 0xfffc, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
      with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
      to the first entry relative to the TOC base (r2).  */
-  HOW (R_PPC64_GOT_TLSGD16, 1, 16, 0xffff, 0, FALSE, signed,
+  HOW (R_PPC64_GOT_TLSGD16, 1, 16, 0xffff, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_TLSGD16, but no overflow.  */
-  HOW (R_PPC64_GOT_TLSGD16_LO, 1, 16, 0xffff, 0, FALSE, dont,
+  HOW (R_PPC64_GOT_TLSGD16_LO, 1, 16, 0xffff, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_TLSGD16_LO, but next higher group of 16 bits.  */
-  HOW (R_PPC64_GOT_TLSGD16_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_GOT_TLSGD16_HI, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_TLSGD16_HI, but adjust for low 16 bits.  */
-  HOW (R_PPC64_GOT_TLSGD16_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_GOT_TLSGD16_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
      with values (sym+add)@dtpmod and zero, and computes the offset to the
      first entry relative to the TOC base (r2).  */
-  HOW (R_PPC64_GOT_TLSLD16, 1, 16, 0xffff, 0, FALSE, signed,
+  HOW (R_PPC64_GOT_TLSLD16, 1, 16, 0xffff, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_TLSLD16, but no overflow.  */
-  HOW (R_PPC64_GOT_TLSLD16_LO, 1, 16, 0xffff, 0, FALSE, dont,
+  HOW (R_PPC64_GOT_TLSLD16_LO, 1, 16, 0xffff, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_TLSLD16_LO, but next higher group of 16 bits.  */
-  HOW (R_PPC64_GOT_TLSLD16_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_GOT_TLSLD16_HI, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_TLSLD16_HI, but adjust for low 16 bits.  */
-  HOW (R_PPC64_GOT_TLSLD16_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_GOT_TLSLD16_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
      the offset to the entry relative to the TOC base (r2).  */
-  HOW (R_PPC64_GOT_DTPREL16_DS, 1, 16, 0xfffc, 0, FALSE, signed,
+  HOW (R_PPC64_GOT_DTPREL16_DS, 1, 16, 0xfffc, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_DTPREL16_DS, but no overflow.  */
-  HOW (R_PPC64_GOT_DTPREL16_LO_DS, 1, 16, 0xfffc, 0, FALSE, dont,
+  HOW (R_PPC64_GOT_DTPREL16_LO_DS, 1, 16, 0xfffc, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits.  */
-  HOW (R_PPC64_GOT_DTPREL16_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_GOT_DTPREL16_HI, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_DTPREL16_HI, but adjust for low 16 bits.  */
-  HOW (R_PPC64_GOT_DTPREL16_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_GOT_DTPREL16_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
      offset to the entry relative to the TOC base (r2).  */
-  HOW (R_PPC64_GOT_TPREL16_DS, 1, 16, 0xfffc, 0, FALSE, signed,
+  HOW (R_PPC64_GOT_TPREL16_DS, 1, 16, 0xfffc, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_TPREL16_DS, but no overflow.  */
-  HOW (R_PPC64_GOT_TPREL16_LO_DS, 1, 16, 0xfffc, 0, FALSE, dont,
+  HOW (R_PPC64_GOT_TPREL16_LO_DS, 1, 16, 0xfffc, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits.  */
-  HOW (R_PPC64_GOT_TPREL16_HI, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_GOT_TPREL16_HI, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
   /* Like GOT_TPREL16_HI, but adjust for low 16 bits.  */
-  HOW (R_PPC64_GOT_TPREL16_HA, 1, 16, 0xffff, 16, FALSE, signed,
+  HOW (R_PPC64_GOT_TPREL16_HA, 1, 16, 0xffff, 16, false, signed,
        ppc64_elf_unhandled_reloc),
 
-  HOW (R_PPC64_JMP_IREL, 0, 0, 0, 0, FALSE, dont,
+  HOW (R_PPC64_JMP_IREL, 0, 0, 0, 0, false, dont,
        ppc64_elf_unhandled_reloc),
 
-  HOW (R_PPC64_IRELATIVE, 4, 64, 0xffffffffffffffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_IRELATIVE, 4, 64, 0xffffffffffffffffULL, 0, false, dont,
        bfd_elf_generic_reloc),
 
   /* A 16 bit relative relocation.  */
-  HOW (R_PPC64_REL16, 1, 16, 0xffff, 0, TRUE, signed,
+  HOW (R_PPC64_REL16, 1, 16, 0xffff, 0, true, signed,
        bfd_elf_generic_reloc),
 
   /* A 16 bit relative relocation without overflow.  */
-  HOW (R_PPC64_REL16_LO, 1, 16, 0xffff, 0, TRUE, dont,
+  HOW (R_PPC64_REL16_LO, 1, 16, 0xffff, 0, true, dont,
        bfd_elf_generic_reloc),
 
   /* The high order 16 bits of a relative address.  */
-  HOW (R_PPC64_REL16_HI, 1, 16, 0xffff, 16, TRUE, signed,
+  HOW (R_PPC64_REL16_HI, 1, 16, 0xffff, 16, true, signed,
        bfd_elf_generic_reloc),
 
   /* The high order 16 bits of a relative address, plus 1 if the contents of
      the low 16 bits, treated as a signed number, is negative.  */
-  HOW (R_PPC64_REL16_HA, 1, 16, 0xffff, 16, TRUE, signed,
+  HOW (R_PPC64_REL16_HA, 1, 16, 0xffff, 16, true, signed,
        ppc64_elf_ha_reloc),
 
-  HOW (R_PPC64_REL16_HIGH, 1, 16, 0xffff, 16, TRUE, dont,
+  HOW (R_PPC64_REL16_HIGH, 1, 16, 0xffff, 16, true, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_REL16_HIGHA, 1, 16, 0xffff, 16, TRUE, dont,
+  HOW (R_PPC64_REL16_HIGHA, 1, 16, 0xffff, 16, true, dont,
        ppc64_elf_ha_reloc),
 
-  HOW (R_PPC64_REL16_HIGHER, 1, 16, 0xffff, 32, TRUE, dont,
+  HOW (R_PPC64_REL16_HIGHER, 1, 16, 0xffff, 32, true, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_REL16_HIGHERA, 1, 16, 0xffff, 32, TRUE, dont,
+  HOW (R_PPC64_REL16_HIGHERA, 1, 16, 0xffff, 32, true, dont,
        ppc64_elf_ha_reloc),
 
-  HOW (R_PPC64_REL16_HIGHEST, 1, 16, 0xffff, 48, TRUE, dont,
+  HOW (R_PPC64_REL16_HIGHEST, 1, 16, 0xffff, 48, true, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_REL16_HIGHESTA, 1, 16, 0xffff, 48, TRUE, dont,
+  HOW (R_PPC64_REL16_HIGHESTA, 1, 16, 0xffff, 48, true, dont,
        ppc64_elf_ha_reloc),
 
   /* Like R_PPC64_REL16_HA but for split field in addpcis.  */
-  HOW (R_PPC64_REL16DX_HA, 2, 16, 0x1fffc1, 16, TRUE, signed,
+  HOW (R_PPC64_REL16DX_HA, 2, 16, 0x1fffc1, 16, true, signed,
        ppc64_elf_ha_reloc),
 
   /* A split-field reloc for addpcis, non-relative (gas internal use only).  */
-  HOW (R_PPC64_16DX_HA, 2, 16, 0x1fffc1, 16, FALSE, signed,
+  HOW (R_PPC64_16DX_HA, 2, 16, 0x1fffc1, 16, false, signed,
        ppc64_elf_ha_reloc),
 
   /* Like R_PPC64_ADDR16_HI, but no overflow.  */
-  HOW (R_PPC64_ADDR16_HIGH, 1, 16, 0xffff, 16, FALSE, dont,
+  HOW (R_PPC64_ADDR16_HIGH, 1, 16, 0xffff, 16, false, dont,
        bfd_elf_generic_reloc),
 
   /* Like R_PPC64_ADDR16_HA, but no overflow.  */
-  HOW (R_PPC64_ADDR16_HIGHA, 1, 16, 0xffff, 16, FALSE, dont,
+  HOW (R_PPC64_ADDR16_HIGHA, 1, 16, 0xffff, 16, false, dont,
        ppc64_elf_ha_reloc),
 
   /* Like R_PPC64_DTPREL16_HI, but no overflow.  */
-  HOW (R_PPC64_DTPREL16_HIGH, 1, 16, 0xffff, 16, FALSE, dont,
+  HOW (R_PPC64_DTPREL16_HIGH, 1, 16, 0xffff, 16, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_DTPREL16_HA, but no overflow.  */
-  HOW (R_PPC64_DTPREL16_HIGHA, 1, 16, 0xffff, 16, FALSE, dont,
+  HOW (R_PPC64_DTPREL16_HIGHA, 1, 16, 0xffff, 16, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_TPREL16_HI, but no overflow.  */
-  HOW (R_PPC64_TPREL16_HIGH, 1, 16, 0xffff, 16, FALSE, dont,
+  HOW (R_PPC64_TPREL16_HIGH, 1, 16, 0xffff, 16, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Like R_PPC64_TPREL16_HA, but no overflow.  */
-  HOW (R_PPC64_TPREL16_HIGHA, 1, 16, 0xffff, 16, FALSE, dont,
+  HOW (R_PPC64_TPREL16_HIGHA, 1, 16, 0xffff, 16, false, dont,
        ppc64_elf_unhandled_reloc),
 
   /* Marker reloc on ELFv2 large-model function entry.  */
-  HOW (R_PPC64_ENTRY, 2, 32, 0, 0, FALSE, dont,
+  HOW (R_PPC64_ENTRY, 2, 32, 0, 0, false, dont,
        bfd_elf_generic_reloc),
 
   /* Like ADDR64, but use local entry point of function.  */
-  HOW (R_PPC64_ADDR64_LOCAL, 4, 64, 0xffffffffffffffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_ADDR64_LOCAL, 4, 64, 0xffffffffffffffffULL, 0, false, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_PLTSEQ_NOTOC, 2, 32, 0, 0, FALSE, dont,
+  HOW (R_PPC64_PLTSEQ_NOTOC, 2, 32, 0, 0, false, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_PLTCALL_NOTOC, 2, 32, 0, 0, FALSE, dont,
+  HOW (R_PPC64_PLTCALL_NOTOC, 2, 32, 0, 0, false, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_PCREL_OPT, 2, 32, 0, 0, FALSE, dont,
+  HOW (R_PPC64_PCREL_OPT, 2, 32, 0, 0, false, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_D34, 4, 34, 0x3ffff0000ffffULL, 0, FALSE, signed,
+  HOW (R_PPC64_D34, 4, 34, 0x3ffff0000ffffULL, 0, false, signed,
        ppc64_elf_prefix_reloc),
 
-  HOW (R_PPC64_D34_LO, 4, 34, 0x3ffff0000ffffULL, 0, FALSE, dont,
+  HOW (R_PPC64_D34_LO, 4, 34, 0x3ffff0000ffffULL, 0, false, dont,
        ppc64_elf_prefix_reloc),
 
-  HOW (R_PPC64_D34_HI30, 4, 34, 0x3ffff0000ffffULL, 34, FALSE, dont,
+  HOW (R_PPC64_D34_HI30, 4, 34, 0x3ffff0000ffffULL, 34, false, dont,
        ppc64_elf_prefix_reloc),
 
-  HOW (R_PPC64_D34_HA30, 4, 34, 0x3ffff0000ffffULL, 34, FALSE, dont,
+  HOW (R_PPC64_D34_HA30, 4, 34, 0x3ffff0000ffffULL, 34, false, dont,
        ppc64_elf_prefix_reloc),
 
-  HOW (R_PPC64_PCREL34, 4, 34, 0x3ffff0000ffffULL, 0, TRUE, signed,
+  HOW (R_PPC64_PCREL34, 4, 34, 0x3ffff0000ffffULL, 0, true, signed,
        ppc64_elf_prefix_reloc),
 
-  HOW (R_PPC64_GOT_PCREL34, 4, 34, 0x3ffff0000ffffULL, 0, TRUE, signed,
+  HOW (R_PPC64_GOT_PCREL34, 4, 34, 0x3ffff0000ffffULL, 0, true, signed,
        ppc64_elf_unhandled_reloc),
 
-  HOW (R_PPC64_PLT_PCREL34, 4, 34, 0x3ffff0000ffffULL, 0, TRUE, signed,
+  HOW (R_PPC64_PLT_PCREL34, 4, 34, 0x3ffff0000ffffULL, 0, true, signed,
        ppc64_elf_unhandled_reloc),
 
-  HOW (R_PPC64_PLT_PCREL34_NOTOC, 4, 34, 0x3ffff0000ffffULL, 0, TRUE, signed,
+  HOW (R_PPC64_PLT_PCREL34_NOTOC, 4, 34, 0x3ffff0000ffffULL, 0, true, signed,
        ppc64_elf_unhandled_reloc),
 
-  HOW (R_PPC64_TPREL34, 4, 34, 0x3ffff0000ffffULL, 0, FALSE, signed,
+  HOW (R_PPC64_TPREL34, 4, 34, 0x3ffff0000ffffULL, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
-  HOW (R_PPC64_DTPREL34, 4, 34, 0x3ffff0000ffffULL, 0, FALSE, signed,
+  HOW (R_PPC64_DTPREL34, 4, 34, 0x3ffff0000ffffULL, 0, false, signed,
        ppc64_elf_unhandled_reloc),
 
-  HOW (R_PPC64_GOT_TLSGD34, 4, 34, 0x3ffff0000ffffULL, 0, TRUE, signed,
+  HOW (R_PPC64_GOT_TLSGD_PCREL34, 4, 34, 0x3ffff0000ffffULL, 0, true, signed,
        ppc64_elf_unhandled_reloc),
 
-  HOW (R_PPC64_GOT_TLSLD34, 4, 34, 0x3ffff0000ffffULL, 0, TRUE, signed,
+  HOW (R_PPC64_GOT_TLSLD_PCREL34, 4, 34, 0x3ffff0000ffffULL, 0, true, signed,
        ppc64_elf_unhandled_reloc),
 
-  HOW (R_PPC64_GOT_TPREL34, 4, 34, 0x3ffff0000ffffULL, 0, TRUE, signed,
+  HOW (R_PPC64_GOT_TPREL_PCREL34, 4, 34, 0x3ffff0000ffffULL, 0, true, signed,
        ppc64_elf_unhandled_reloc),
 
-  HOW (R_PPC64_GOT_DTPREL34, 4, 34, 0x3ffff0000ffffULL, 0, TRUE, signed,
+  HOW (R_PPC64_GOT_DTPREL_PCREL34, 4, 34, 0x3ffff0000ffffULL, 0, true, signed,
        ppc64_elf_unhandled_reloc),
 
-  HOW (R_PPC64_ADDR16_HIGHER34, 1, 16, 0xffff, 34, FALSE, dont,
+  HOW (R_PPC64_ADDR16_HIGHER34, 1, 16, 0xffff, 34, false, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_ADDR16_HIGHERA34, 1, 16, 0xffff, 34, FALSE, dont,
+  HOW (R_PPC64_ADDR16_HIGHERA34, 1, 16, 0xffff, 34, false, dont,
        ppc64_elf_ha_reloc),
 
-  HOW (R_PPC64_ADDR16_HIGHEST34, 1, 16, 0xffff, 50, FALSE, dont,
+  HOW (R_PPC64_ADDR16_HIGHEST34, 1, 16, 0xffff, 50, false, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_ADDR16_HIGHESTA34, 1, 16, 0xffff, 50, FALSE, dont,
+  HOW (R_PPC64_ADDR16_HIGHESTA34, 1, 16, 0xffff, 50, false, dont,
        ppc64_elf_ha_reloc),
 
-  HOW (R_PPC64_REL16_HIGHER34, 1, 16, 0xffff, 34, TRUE, dont,
+  HOW (R_PPC64_REL16_HIGHER34, 1, 16, 0xffff, 34, true, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_REL16_HIGHERA34, 1, 16, 0xffff, 34, TRUE, dont,
+  HOW (R_PPC64_REL16_HIGHERA34, 1, 16, 0xffff, 34, true, dont,
        ppc64_elf_ha_reloc),
 
-  HOW (R_PPC64_REL16_HIGHEST34, 1, 16, 0xffff, 50, TRUE, dont,
+  HOW (R_PPC64_REL16_HIGHEST34, 1, 16, 0xffff, 50, true, dont,
        bfd_elf_generic_reloc),
 
-  HOW (R_PPC64_REL16_HIGHESTA34, 1, 16, 0xffff, 50, TRUE, dont,
+  HOW (R_PPC64_REL16_HIGHESTA34, 1, 16, 0xffff, 50, true, dont,
        ppc64_elf_ha_reloc),
 
-  HOW (R_PPC64_D28, 4, 28, 0xfff0000ffffULL, 0, FALSE, signed,
+  HOW (R_PPC64_D28, 4, 28, 0xfff0000ffffULL, 0, false, signed,
        ppc64_elf_prefix_reloc),
 
-  HOW (R_PPC64_PCREL28, 4, 28, 0xfff0000ffffULL, 0, TRUE, signed,
+  HOW (R_PPC64_PCREL28, 4, 28, 0xfff0000ffffULL, 0, true, signed,
        ppc64_elf_prefix_reloc),
 
   /* GNU extension to record C++ vtable hierarchy.  */
-  HOW (R_PPC64_GNU_VTINHERIT, 0, 0, 0, 0, FALSE, dont,
+  HOW (R_PPC64_GNU_VTINHERIT, 0, 0, 0, 0, false, dont,
        NULL),
 
   /* GNU extension to record C++ vtable member usage.  */
-  HOW (R_PPC64_GNU_VTENTRY, 0, 0, 0, 0, FALSE, dont,
+  HOW (R_PPC64_GNU_VTENTRY, 0, 0, 0, 0, false, dont,
        NULL),
 };
 
@@ -995,8 +1006,7 @@ ppc_howto_init (void)
 }
 
 static reloc_howto_type *
-ppc64_elf_reloc_type_lookup (bfd *abfd,
-                            bfd_reloc_code_real_type code)
+ppc64_elf_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
 {
   enum elf_ppc64_reloc_type r = R_PPC64_NONE;
 
@@ -1276,13 +1286,13 @@ ppc64_elf_reloc_type_lookup (bfd *abfd,
       break;
     case BFD_RELOC_PPC64_DTPREL34:             r = R_PPC64_DTPREL34;
       break;
-    case BFD_RELOC_PPC64_GOT_TLSGD34:          r = R_PPC64_GOT_TLSGD34;
+    case BFD_RELOC_PPC64_GOT_TLSGD_PCREL34:    r = R_PPC64_GOT_TLSGD_PCREL34;
       break;
-    case BFD_RELOC_PPC64_GOT_TLSLD34:          r = R_PPC64_GOT_TLSLD34;
+    case BFD_RELOC_PPC64_GOT_TLSLD_PCREL34:    r = R_PPC64_GOT_TLSLD_PCREL34;
       break;
-    case BFD_RELOC_PPC64_GOT_TPREL34:          r = R_PPC64_GOT_TPREL34;
+    case BFD_RELOC_PPC64_GOT_TPREL_PCREL34:    r = R_PPC64_GOT_TPREL_PCREL34;
       break;
-    case BFD_RELOC_PPC64_GOT_DTPREL34:         r = R_PPC64_GOT_DTPREL34;
+    case BFD_RELOC_PPC64_GOT_DTPREL_PCREL34:   r = R_PPC64_GOT_DTPREL_PCREL34;
       break;
     case BFD_RELOC_PPC64_ADDR16_HIGHER34:      r = R_PPC64_ADDR16_HIGHER34;
       break;
@@ -1314,22 +1324,39 @@ ppc64_elf_reloc_type_lookup (bfd *abfd,
 };
 
 static reloc_howto_type *
-ppc64_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
-                            const char *r_name)
+ppc64_elf_reloc_name_lookup (bfd *abfd, const char *r_name)
 {
   unsigned int i;
+  static char *compat_map[][2] = {
+    { "R_PPC64_GOT_TLSGD34", "R_PPC64_GOT_TLSGD_PCREL34" },
+    { "R_PPC64_GOT_TLSLD34", "R_PPC64_GOT_TLSLD_PCREL34" },
+    { "R_PPC64_GOT_TPREL34", "R_PPC64_GOT_TPREL_PCREL34" },
+    { "R_PPC64_GOT_DTPREL34", "R_PPC64_GOT_DTPREL_PCREL34" }
+  };
 
   for (i = 0; i < ARRAY_SIZE (ppc64_elf_howto_raw); i++)
     if (ppc64_elf_howto_raw[i].name != NULL
        && strcasecmp (ppc64_elf_howto_raw[i].name, r_name) == 0)
       return &ppc64_elf_howto_raw[i];
 
+  /* Handle old names of relocations in case they were used by
+     .reloc directives.
+     FIXME: Remove this soon.  Mapping the reloc names is very likely
+     completely unnecessary.  */
+  for (i = 0; i < ARRAY_SIZE (compat_map); i++)
+    if (strcasecmp (compat_map[i][0], r_name) == 0)
+      {
+       _bfd_error_handler (_("warning: %s should be used rather than %s"),
+                           compat_map[i][1], compat_map[i][0]);
+       return ppc64_elf_reloc_name_lookup (abfd, compat_map[i][1]);
+      }
+
   return NULL;
 }
 
 /* Set the howto pointer for a PowerPC ELF reloc.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_info_to_howto (bfd *abfd, arelent *cache_ptr,
                         Elf_Internal_Rela *dst)
 {
@@ -1346,7 +1373,7 @@ ppc64_elf_info_to_howto (bfd *abfd, arelent *cache_ptr,
       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
                          abfd, type);
       bfd_set_error (bfd_error_bad_value);
-      return FALSE;
+      return false;
     }
   cache_ptr->howto = ppc64_elf_howto_table[type];
   if (cache_ptr->howto == NULL || cache_ptr->howto->name == NULL)
@@ -1355,10 +1382,10 @@ ppc64_elf_info_to_howto (bfd *abfd, arelent *cache_ptr,
       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
                          abfd, type);
       bfd_set_error (bfd_error_bad_value);
-      return FALSE;
+      return false;
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Handle the R_PPC64_ADDR16_HA and similar relocs.  */
@@ -1405,7 +1432,7 @@ ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
            + input_section->output_section->vma);
   value = (bfd_signed_vma) value >> 16;
 
-  octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  octets = reloc_entry->address * OCTETS_PER_BYTE (abfd, input_section);
   insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
   insn &= ~0x1fffc1;
   insn |= (value & 0xffc1) | ((value & 0x3e) << 15);
@@ -1429,7 +1456,7 @@ ppc64_elf_branch_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
     {
       bfd_vma dest = opd_entry_value (symbol->section,
                                      symbol->value + reloc_entry->addend,
-                                     NULL, NULL, FALSE);
+                                     NULL, NULL, false);
       if (dest != (bfd_vma) -1)
        reloc_entry->addend = dest - (symbol->value
                                      + symbol->section->output_section->vma
@@ -1471,7 +1498,7 @@ ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   enum elf_ppc64_reloc_type r_type;
   bfd_size_type octets;
   /* Assume 'at' branch hints.  */
-  bfd_boolean is_isa_v2 = TRUE;
+  bool is_isa_v2 = true;
 
   /* If this is a relocatable link (output_bfd test tells us), just
      call the generic function.  Any adjustment will be done at final
@@ -1480,7 +1507,7 @@ ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
     return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
                                  input_section, output_bfd, error_message);
 
-  octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  octets = reloc_entry->address * OCTETS_PER_BYTE (abfd, input_section);
   insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
   insn &= ~(0x01 << 21);
   r_type = reloc_entry->howto->type;
@@ -1630,7 +1657,7 @@ ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   if (TOCstart == 0)
     TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
 
-  octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  octets = reloc_entry->address * OCTETS_PER_BYTE (abfd, input_section);
   bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
   return bfd_reloc_ok;
 }
@@ -1691,10 +1718,12 @@ ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
 
   if (error_message != NULL)
     {
-      static char buf[60];
-      sprintf (buf, "generic linker can't handle %s",
-              reloc_entry->howto->name);
-      *error_message = buf;
+      static char *message;
+      free (message);
+      if (asprintf (&message, _("generic linker can't handle %s"),
+                   reloc_entry->howto->name) < 0)
+       message = NULL;
+      *error_message = message;
     }
   return bfd_reloc_dangerous;
 }
@@ -1797,7 +1826,7 @@ struct ppc64_elf_obj_tdata
 
 /* Override the generic function because we store some extras.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_mkobject (bfd *abfd)
 {
   return bfd_elf_allocate_object (abfd, sizeof (struct ppc64_elf_obj_tdata),
@@ -1807,11 +1836,11 @@ ppc64_elf_mkobject (bfd *abfd)
 /* Fix bad default arch selected for a 64 bit input bfd when the
    default is 32 bit.  Also select arch based on apuinfo.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_object_p (bfd *abfd)
 {
   if (!abfd->arch_info->the_default)
-    return TRUE;
+    return true;
 
   if (abfd->arch_info->bits_per_word == 32)
     {
@@ -1829,13 +1858,13 @@ ppc64_elf_object_p (bfd *abfd)
 
 /* Support for core dump NOTE sections.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
 {
   size_t offset, size;
 
   if (note->descsz != 504)
-    return FALSE;
+    return false;
 
   /* pr_cursig */
   elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
@@ -1852,11 +1881,11 @@ ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
                                          size, note->descpos + offset);
 }
 
-static bfd_boolean
+static bool
 ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
 {
   if (note->descsz != 136)
-    return FALSE;
+    return false;
 
   elf_tdata (abfd)->core->pid
     = bfd_get_32 (abfd, note->descdata + 24);
@@ -1865,7 +1894,7 @@ ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
   elf_tdata (abfd)->core->command
     = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
 
-  return TRUE;
+  return true;
 }
 
 static char *
@@ -1991,23 +2020,35 @@ struct _ppc64_elf_section_data
 #define ppc64_elf_section_data(sec) \
   ((struct _ppc64_elf_section_data *) elf_section_data (sec))
 
-static bfd_boolean
+static bool
 ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
 {
   if (!sec->used_by_bfd)
     {
       struct _ppc64_elf_section_data *sdata;
-      bfd_size_type amt = sizeof (*sdata);
+      size_t amt = sizeof (*sdata);
 
       sdata = bfd_zalloc (abfd, amt);
       if (sdata == NULL)
-       return FALSE;
+       return false;
       sec->used_by_bfd = sdata;
     }
 
   return _bfd_elf_new_section_hook (abfd, sec);
 }
 
+static bool
+ppc64_elf_section_flags (const Elf_Internal_Shdr *hdr)
+{
+  const char *name = hdr->bfd_section->name;
+
+  if (startswith (name, ".sbss")
+      || startswith (name, ".sdata"))
+    hdr->bfd_section->flags |= SEC_SMALL_DATA;
+
+  return true;
+}
+
 static struct _opd_sec_data *
 get_opd_info (asection * sec)
 {
@@ -2019,8 +2060,8 @@ get_opd_info (asection * sec)
 }
 \f
 /* Parameters for the qsort hook.  */
-static bfd_boolean synthetic_relocatable;
-static asection *synthetic_opd;
+static bool synthetic_relocatable;
+static const asection *synthetic_opd;
 
 /* qsort comparison function for ppc64_elf_get_synthetic_symtab.  */
 
@@ -2101,15 +2142,26 @@ compare_symbols (const void *ap, const void *bp)
   if ((a->flags & BSF_DYNAMIC) == 0 && (b->flags & BSF_DYNAMIC) != 0)
     return 1;
 
-  return a > b;
+  /* Finally, sort on where the symbol is in memory.  The symbols will
+     be in at most two malloc'd blocks, one for static syms, one for
+     dynamic syms, and we distinguish the two blocks above by testing
+     BSF_DYNAMIC.  Since we are sorting the symbol pointers which were
+     originally in the same order as the symbols (and we're not
+     sorting the symbols themselves), this ensures a stable sort.  */
+  if (a < b)
+    return -1;
+  if (a > b)
+    return 1;
+  return 0;
 }
 
 /* Search SYMS for a symbol of the given VALUE.  */
 
 static asymbol *
-sym_exists_at (asymbol **syms, long lo, long hi, unsigned int id, bfd_vma value)
+sym_exists_at (asymbol **syms, size_t lo, size_t hi, unsigned int id,
+              bfd_vma value)
 {
-  long mid;
+  size_t mid;
 
   if (id == (unsigned) -1)
     {
@@ -2144,7 +2196,7 @@ sym_exists_at (asymbol **syms, long lo, long hi, unsigned int id, bfd_vma value)
   return NULL;
 }
 
-static bfd_boolean
+static bool
 section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr)
 {
   bfd_vma vma = *(bfd_vma *) ptr;
@@ -2168,7 +2220,7 @@ ppc64_elf_get_synthetic_symtab (bfd *abfd,
   char *names;
   size_t symcount, codesecsym, codesecsymend, secsymend, opdsymend;
   asection *opd = NULL;
-  bfd_boolean relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
+  bool relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
   asymbol **syms;
   int abi = abiversion (abfd);
 
@@ -2250,7 +2302,8 @@ ppc64_elf_get_synthetic_symtab (bfd *abfd,
         sym->section directly.  With separate debug info files, the
         symbols will be extracted from the debug file while abfd passed
         to this function is the real binary.  */
-      if (strcmp (syms[i]->section->name, ".opd") == 0)
+      if ((syms[i]->flags & BSF_SECTION_SYM) != 0
+         && strcmp (syms[i]->section->name, ".opd") == 0)
        ++i;
       codesecsym = i;
 
@@ -2283,7 +2336,7 @@ ppc64_elf_get_synthetic_symtab (bfd *abfd,
 
   if (relocatable)
     {
-      bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
+      bool (*slurp_relocs) (bfd *, asection *, asymbol **, bool);
       arelent *r;
       size_t size;
       size_t relcount;
@@ -2296,7 +2349,7 @@ ppc64_elf_get_synthetic_symtab (bfd *abfd,
       if (relcount == 0)
        goto done;
 
-      if (!(*slurp_relocs) (abfd, opd, static_syms, FALSE))
+      if (!(*slurp_relocs) (abfd, opd, static_syms, false))
        {
          count = -1;
          goto done;
@@ -2382,7 +2435,7 @@ ppc64_elf_get_synthetic_symtab (bfd *abfd,
     }
   else
     {
-      bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
+      bool (*slurp_relocs) (bfd *, asection *, asymbol **, bool);
       bfd_byte *contents = NULL;
       size_t size;
       size_t plt_count = 0;
@@ -2395,8 +2448,7 @@ ppc64_elf_get_synthetic_symtab (bfd *abfd,
        free_contents_and_exit_err:
          count = -1;
        free_contents_and_exit:
-         if (contents)
-           free (contents);
+         free (contents);
          goto done;
        }
 
@@ -2489,7 +2541,7 @@ ppc64_elf_get_synthetic_symtab (bfd *abfd,
          if (relplt != NULL)
            {
              slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
-             if (!(*slurp_relocs) (abfd, relplt, dyn_syms, TRUE))
+             if (!(*slurp_relocs) (abfd, relplt, dyn_syms, true))
                goto free_contents_and_exit_err;
 
              plt_count = relplt->size / sizeof (Elf64_External_Rela);
@@ -2745,6 +2797,12 @@ must_be_dyn_reloc (struct bfd_link_info *info,
     case R_PPC64_REL32:
     case R_PPC64_REL64:
     case R_PPC64_REL30:
+    case R_PPC64_TOC16:
+    case R_PPC64_TOC16_DS:
+    case R_PPC64_TOC16_LO:
+    case R_PPC64_TOC16_HI:
+    case R_PPC64_TOC16_HA:
+    case R_PPC64_TOC16_LO_DS:
       return 0;
 
     case R_PPC64_TPREL16:
@@ -2768,20 +2826,20 @@ must_be_dyn_reloc (struct bfd_link_info *info,
 }
 
 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
-   copying dynamic variables from a shared lib into an app's dynbss
+   copying dynamic variables from a shared lib into an app's .dynbss
    section, and instead use a dynamic relocation to point into the
-   shared lib.  With code that gcc generates, it's vital that this be
-   enabled;  In the PowerPC64 ABI, the address of a function is actually
-   the address of a function descriptor, which resides in the .opd
-   section.  gcc uses the descriptor directly rather than going via the
-   GOT as some other ABI's do, which means that initialized function
-   pointers must reference the descriptor.  Thus, a function pointer
-   initialized to the address of a function in a shared library will
-   either require a copy reloc, or a dynamic reloc.  Using a copy reloc
-   redefines the function descriptor symbol to point to the copy.  This
-   presents a problem as a plt entry for that function is also
-   initialized from the function descriptor symbol and the copy reloc
-   may not be initialized first.  */
+   shared lib.  With code that gcc generates it is vital that this be
+   enabled;  In the PowerPC64 ELFv1 ABI the address of a function is
+   actually the address of a function descriptor which resides in the
+   .opd section.  gcc uses the descriptor directly rather than going
+   via the GOT as some other ABIs do, which means that initialized
+   function pointers reference the descriptor.  Thus, a function
+   pointer initialized to the address of a function in a shared
+   library will either require a .dynbss copy and a copy reloc, or a
+   dynamic reloc.  Using a .dynbss copy redefines the function
+   descriptor symbol to point to the copy.  This presents a problem as
+   a PLT entry for that function is also initialized from the function
+   descriptor symbol and the copy may not be initialized first.  */
 #define ELIMINATE_COPY_RELOCS 1
 
 /* Section name for stubs is the associated section name plus this
@@ -2797,8 +2855,8 @@ must_be_dyn_reloc (struct bfd_link_info *info,
    ppc_stub_plt_branch:
    Similar to the above, but a 24 bit branch in the stub section won't
    reach its destination.
-   .   addis   %r11,%r2,xxx@toc@ha
-   .   ld      %r12,xxx@toc@l(%r11)
+   .   addis   %r12,%r2,xxx@toc@ha
+   .   ld      %r12,xxx@toc@l(%r12)
    .   mtctr   %r12
    .   bctr
 
@@ -2824,8 +2882,8 @@ must_be_dyn_reloc (struct bfd_link_info *info,
 
    A ppc_stub_plt_branch with an r2 offset looks like:
    .   std     %r2,40(%r1)
-   .   addis   %r11,%r2,xxx@toc@ha
-   .   ld      %r12,xxx@toc@l(%r11)
+   .   addis   %r12,%r2,xxx@toc@ha
+   .   ld      %r12,xxx@toc@l(%r12)
    .   addis   %r2,%r2,off@ha
    .   addi    %r2,%r2,off@l
    .   mtctr   %r12
@@ -2881,7 +2939,7 @@ must_be_dyn_reloc (struct bfd_link_info *info,
    .   mtctr   %r12
    .   bctr
 
-   There are also ELFv1 powerxx variants of these stubs.
+   There are also ELFv1 power10 variants of these stubs.
    ppc_stub_long_branch_notoc:
    .   pla     %r12,dest@pcrel
    .   b       dest
@@ -2904,7 +2962,7 @@ must_be_dyn_reloc (struct bfd_link_info *info,
 
    In cases where the high instructions would add zero, they are
    omitted and following instructions modified in some cases.
-   For example, a powerxx ppc_stub_plt_call_notoc might simplify down
+   For example, a power10 ppc_stub_plt_call_notoc might simplify down
    to
    .   pld     %r12,xxx@pcrel
    .   mtctr   %r12
@@ -3043,9 +3101,6 @@ struct ppc_link_hash_entry
     struct ppc_link_hash_entry *next_dot_sym;
   } u;
 
-  /* Track dynamic relocs copied for this symbol.  */
-  struct elf_dyn_relocs *dyn_relocs;
-
   /* Link between function code and descriptor symbols.  */
   struct ppc_link_hash_entry *oh;
 
@@ -3092,6 +3147,18 @@ struct ppc_link_hash_entry
 #define NON_GOT        256     /* local symbol plt, not stored.  */
 };
 
+static inline struct ppc_link_hash_entry *
+ppc_elf_hash_entry (struct elf_link_hash_entry *ent)
+{
+  return (struct ppc_link_hash_entry *) ent;
+}
+
+static inline struct elf_link_hash_entry *
+elf_hash_entry (struct ppc_link_hash_entry *ent)
+{
+  return (struct elf_link_hash_entry *) ent;
+}
+
 /* ppc64 ELF linker hash table.  */
 
 struct ppc_link_hash_table
@@ -3154,6 +3221,9 @@ struct ppc_link_hash_table
   /* Shortcut to .__tls_get_addr and __tls_get_addr.  */
   struct ppc_link_hash_entry *tls_get_addr;
   struct ppc_link_hash_entry *tls_get_addr_fd;
+  struct ppc_link_hash_entry *tga_desc;
+  struct ppc_link_hash_entry *tga_desc_fd;
+  struct map_stub *tga_group;
 
   /* The size of reliplt used by got entry relocs.  */
   bfd_size_type got_reli_size;
@@ -3185,25 +3255,17 @@ struct ppc_link_hash_table
   /* Whether func_desc_adjust needs to be run over symbols.  */
   unsigned int need_func_desc_adj:1;
 
-  /* Whether there exist local gnu indirect function resolvers,
-     referenced by dynamic relocations.  */
-  unsigned int local_ifunc_resolver:1;
-  unsigned int maybe_local_ifunc_resolver:1;
-
   /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized.  */
   unsigned int has_plt_localentry0:1;
 
   /* Whether calls are made via the PLT from NOTOC functions.  */
   unsigned int notoc_plt:1;
 
-  /* Whether to use powerxx instructions in linkage stubs.  */
-  unsigned int powerxx_stubs:1;
+  /* Whether any code linked seems to be Power10.  */
+  unsigned int has_power10_relocs:1;
 
   /* Incremented every time we size stubs.  */
   unsigned int stub_iteration;
-
-  /* Small local sym cache.  */
-  struct sym_cache sym_cache;
 };
 
 /* Rename some of the generic section flags to better document how they
@@ -3212,8 +3274,9 @@ struct ppc_link_hash_table
 /* Nonzero if this section has TLS related relocations.  */
 #define has_tls_reloc sec_flg0
 
-/* Nonzero if this section has an old-style call to __tls_get_addr.  */
-#define has_tls_get_addr_call sec_flg1
+/* Nonzero if this section has a call to __tls_get_addr lacking marker
+   relocations.  */
+#define nomark_tls_get_addr sec_flg1
 
 /* Nonzero if this section has any toc or got relocs.  */
 #define has_toc_reloc sec_flg2
@@ -3229,8 +3292,9 @@ struct ppc_link_hash_table
 /* Get the ppc64 ELF linker hash table from a link_info structure.  */
 
 #define ppc_hash_table(p) \
-  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
-  == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
+  ((is_elf_hash_table ((p)->hash)                                      \
+    && elf_hash_table_id (elf_hash_table (p)) == PPC64_ELF_DATA)       \
+   ? (struct ppc_link_hash_table *) (p)->hash : NULL)
 
 #define ppc_stub_hash_lookup(table, string, create, copy) \
   ((struct ppc_stub_hash_entry *) \
@@ -3405,7 +3469,7 @@ static struct bfd_link_hash_table *
 ppc64_elf_link_hash_table_create (bfd *abfd)
 {
   struct ppc_link_hash_table *htab;
-  bfd_size_type amt = sizeof (struct ppc_link_hash_table);
+  size_t amt = sizeof (struct ppc_link_hash_table);
 
   htab = bfd_zmalloc (amt);
   if (htab == NULL)
@@ -3465,7 +3529,7 @@ ppc64_elf_link_hash_table_create (bfd *abfd)
 
 /* Create sections for linker generated code.  */
 
-static bfd_boolean
+static bool
 create_linkage_sections (bfd *dynobj, struct bfd_link_info *info)
 {
   struct ppc_link_hash_table *htab;
@@ -3481,27 +3545,27 @@ create_linkage_sections (bfd *dynobj, struct bfd_link_info *info)
       htab->sfpr = bfd_make_section_anyway_with_flags (dynobj, ".sfpr",
                                                       flags);
       if (htab->sfpr == NULL
-         || !bfd_set_section_alignment (dynobj, htab->sfpr, 2))
-       return FALSE;
+         || !bfd_set_section_alignment (htab->sfpr, 2))
+       return false;
     }
 
   if (bfd_link_relocatable (info))
-    return TRUE;
+    return true;
 
   /* Create .glink for lazy dynamic linking support.  */
   htab->glink = bfd_make_section_anyway_with_flags (dynobj, ".glink",
                                                    flags);
   if (htab->glink == NULL
-      || !bfd_set_section_alignment (dynobj, htab->glink, 3))
-    return FALSE;
+      || !bfd_set_section_alignment (htab->glink, 3))
+    return false;
 
   /* The part of .glink used by global entry stubs, separate so that
      it can be aligned appropriately without affecting htab->glink.  */
   htab->global_entry = bfd_make_section_anyway_with_flags (dynobj, ".glink",
                                                           flags);
   if (htab->global_entry == NULL
-      || !bfd_set_section_alignment (dynobj, htab->global_entry, 2))
-    return FALSE;
+      || !bfd_set_section_alignment (htab->global_entry, 2))
+    return false;
 
   if (!info->no_ld_generated_unwind_info)
     {
@@ -3511,23 +3575,23 @@ create_linkage_sections (bfd *dynobj, struct bfd_link_info *info)
                                                                 ".eh_frame",
                                                                 flags);
       if (htab->glink_eh_frame == NULL
-         || !bfd_set_section_alignment (dynobj, htab->glink_eh_frame, 2))
-       return FALSE;
+         || !bfd_set_section_alignment (htab->glink_eh_frame, 2))
+       return false;
     }
 
   flags = SEC_ALLOC | SEC_LINKER_CREATED;
   htab->elf.iplt = bfd_make_section_anyway_with_flags (dynobj, ".iplt", flags);
   if (htab->elf.iplt == NULL
-      || !bfd_set_section_alignment (dynobj, htab->elf.iplt, 3))
-    return FALSE;
+      || !bfd_set_section_alignment (htab->elf.iplt, 3))
+    return false;
 
   flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
           | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   htab->elf.irelplt
     = bfd_make_section_anyway_with_flags (dynobj, ".rela.iplt", flags);
   if (htab->elf.irelplt == NULL
-      || !bfd_set_section_alignment (dynobj, htab->elf.irelplt, 3))
-    return FALSE;
+      || !bfd_set_section_alignment (htab->elf.irelplt, 3))
+    return false;
 
   /* Create branch lookup table for plt_branch stubs.  */
   flags = (SEC_ALLOC | SEC_LOAD
@@ -3535,40 +3599,40 @@ create_linkage_sections (bfd *dynobj, struct bfd_link_info *info)
   htab->brlt = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt",
                                                   flags);
   if (htab->brlt == NULL
-      || !bfd_set_section_alignment (dynobj, htab->brlt, 3))
-    return FALSE;
+      || !bfd_set_section_alignment (htab->brlt, 3))
+    return false;
 
   /* Local plt entries, put in .branch_lt but a separate section for
      convenience.  */
   htab->pltlocal = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt",
                                                       flags);
   if (htab->pltlocal == NULL
-      || !bfd_set_section_alignment (dynobj, htab->pltlocal, 3))
-    return FALSE;
+      || !bfd_set_section_alignment (htab->pltlocal, 3))
+    return false;
 
   if (!bfd_link_pic (info))
-    return TRUE;
+    return true;
 
   flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
           | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   htab->relbrlt
     = bfd_make_section_anyway_with_flags (dynobj, ".rela.branch_lt", flags);
   if (htab->relbrlt == NULL
-      || !bfd_set_section_alignment (dynobj, htab->relbrlt, 3))
-    return FALSE;
+      || !bfd_set_section_alignment (htab->relbrlt, 3))
+    return false;
 
   htab->relpltlocal
     = bfd_make_section_anyway_with_flags (dynobj, ".rela.branch_lt", flags);
   if (htab->relpltlocal == NULL
-      || !bfd_set_section_alignment (dynobj, htab->relpltlocal, 3))
-    return FALSE;
+      || !bfd_set_section_alignment (htab->relpltlocal, 3))
+    return false;
 
-  return TRUE;
+  return true;
 }
 
 /* Satisfy the ELF linker by filling in some fields in our fake bfd.  */
 
-bfd_boolean
+bool
 ppc64_elf_init_stub_bfd (struct bfd_link_info *info,
                         struct ppc64_elf_params *params)
 {
@@ -3632,6 +3696,37 @@ ppc_stub_name (const asection *input_section,
   return stub_name;
 }
 
+/* If mixing power10 with non-power10 code and --power10-stubs is not
+   specified (or is auto) then calls using @notoc relocations that
+   need a stub will utilize power10 instructions in the stub, and
+   calls without @notoc relocations will not use power10 instructions.
+   The two classes of stubs are stored in separate stub_hash_table
+   entries having the same key string.  The two entries will always be
+   adjacent on entry->root.next chain, even if hash table resizing
+   occurs.  This function selects the correct entry to use.  */
+
+static struct ppc_stub_hash_entry *
+select_alt_stub (struct ppc_stub_hash_entry *entry, bool notoc)
+{
+  bool have_notoc;
+
+  have_notoc = (entry->stub_type == ppc_stub_plt_call_notoc
+               || entry->stub_type == ppc_stub_plt_branch_notoc
+               || entry->stub_type == ppc_stub_long_branch_notoc);
+
+  if (have_notoc != notoc)
+    {
+      const char *stub_name = entry->root.string;
+
+      entry = (struct ppc_stub_hash_entry *) entry->root.next;
+      if (entry != NULL
+         && entry->root.string != stub_name)
+       entry = NULL;
+    }
+
+  return entry;
+}
+
 /* Look up an entry in the stub hash.  Stub entries are cached because
    creating the stub name takes a bit of time.  */
 
@@ -3669,13 +3764,20 @@ ppc_get_stub_entry (const asection *input_section,
        return NULL;
 
       stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
-                                        stub_name, FALSE, FALSE);
+                                        stub_name, false, false);
       if (h != NULL)
        h->u.stub_cache = stub_entry;
 
       free (stub_name);
     }
 
+  if (stub_entry != NULL && htab->params->power10_stubs == -1)
+    {
+      bool notoc = ELF64_R_TYPE (rel->r_info) == R_PPC64_REL24_NOTOC;
+
+      stub_entry = select_alt_stub (stub_entry, notoc);
+    }
+
   return stub_entry;
 }
 
@@ -3718,7 +3820,7 @@ ppc_add_stub (const char *stub_name,
 
   /* Enter this entry into the linker stub hash table.  */
   stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
-                                    TRUE, FALSE);
+                                    true, false);
   if (stub_entry == NULL)
     {
       /* xgettext:c-format */
@@ -3735,7 +3837,7 @@ ppc_add_stub (const char *stub_name,
 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
    not already done.  */
 
-static bfd_boolean
+static bool
 create_got_section (bfd *abfd, struct bfd_link_info *info)
 {
   asection *got, *relgot;
@@ -3743,31 +3845,31 @@ create_got_section (bfd *abfd, struct bfd_link_info *info)
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
 
   if (!is_ppc64_elf (abfd))
-    return FALSE;
+    return false;
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   if (!htab->elf.sgot
       && !_bfd_elf_create_got_section (htab->elf.dynobj, info))
-    return FALSE;
+    return false;
 
   flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
           | SEC_LINKER_CREATED);
 
   got = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
   if (!got
-      || !bfd_set_section_alignment (abfd, got, 3))
-    return FALSE;
+      || !bfd_set_section_alignment (got, 3))
+    return false;
 
   relgot = bfd_make_section_anyway_with_flags (abfd, ".rela.got",
                                               flags | SEC_READONLY);
   if (!relgot
-      || !bfd_set_section_alignment (abfd, relgot, 3))
-    return FALSE;
+      || !bfd_set_section_alignment (relgot, 3))
+    return false;
 
   ppc64_elf_tdata (abfd)->got = got;
   ppc64_elf_tdata (abfd)->relgot = relgot;
-  return TRUE;
+  return true;
 }
 
 /* Follow indirect and warning symbol links.  */
@@ -3790,7 +3892,7 @@ elf_follow_link (struct elf_link_hash_entry *h)
 static inline struct ppc_link_hash_entry *
 ppc_follow_link (struct ppc_link_hash_entry *h)
 {
-  return (struct ppc_link_hash_entry *) follow_link (&h->elf.root);
+  return ppc_elf_hash_entry (elf_follow_link (&h->elf));
 }
 
 /* Merge PLT info on FROM with that on TO.  */
@@ -3837,8 +3939,8 @@ ppc64_elf_copy_indirect_symbol (struct bfd_link_info *info,
 {
   struct ppc_link_hash_entry *edir, *eind;
 
-  edir = (struct ppc_link_hash_entry *) dir;
-  eind = (struct ppc_link_hash_entry *) ind;
+  edir = ppc_elf_hash_entry (dir);
+  eind = ppc_elf_hash_entry (ind);
 
   edir->is_func |= eind->is_func;
   edir->is_func_descriptor |= eind->is_func_descriptor;
@@ -3864,20 +3966,20 @@ ppc64_elf_copy_indirect_symbol (struct bfd_link_info *info,
     return;
 
   /* Copy over any dynamic relocs we may have on the indirect sym.  */
-  if (eind->dyn_relocs != NULL)
+  if (ind->dyn_relocs != NULL)
     {
-      if (edir->dyn_relocs != NULL)
+      if (dir->dyn_relocs != NULL)
        {
          struct elf_dyn_relocs **pp;
          struct elf_dyn_relocs *p;
 
          /* Add reloc counts against the indirect sym to the direct sym
             list.  Merge any entries against the same section.  */
-         for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
+         for (pp = &ind->dyn_relocs; (p = *pp) != NULL; )
            {
              struct elf_dyn_relocs *q;
 
-             for (q = edir->dyn_relocs; q != NULL; q = q->next)
+             for (q = dir->dyn_relocs; q != NULL; q = q->next)
                if (q->sec == p->sec)
                  {
                    q->pc_count += p->pc_count;
@@ -3888,11 +3990,11 @@ ppc64_elf_copy_indirect_symbol (struct bfd_link_info *info,
              if (q == NULL)
                pp = &p->next;
            }
-         *pp = edir->dyn_relocs;
+         *pp = dir->dyn_relocs;
        }
 
-      edir->dyn_relocs = eind->dyn_relocs;
-      eind->dyn_relocs = NULL;
+      dir->dyn_relocs = ind->dyn_relocs;
+      ind->dyn_relocs = NULL;
     }
 
   /* Copy over got entries that we may have already seen to the
@@ -3954,8 +4056,8 @@ lookup_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab)
     {
       const char *fd_name = fh->elf.root.root.string + 1;
 
-      fdh = (struct ppc_link_hash_entry *)
-       elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE);
+      fdh = ppc_elf_hash_entry (elf_link_hash_lookup (&htab->elf, fd_name,
+                                                     false, false, false));
       if (fdh == NULL)
        return fdh;
 
@@ -3987,7 +4089,7 @@ make_fdh (struct bfd_link_info *info,
   if (!_bfd_generic_link_add_one_symbol (info, abfd,
                                         fh->elf.root.root.string + 1,
                                         flags, bfd_und_section_ptr, 0,
-                                        NULL, FALSE, FALSE, &bh))
+                                        NULL, false, false, &bh))
     return NULL;
 
   fdh = (struct ppc_link_hash_entry *) bh;
@@ -4003,7 +4105,7 @@ make_fdh (struct bfd_link_info *info,
 /* Fix function descriptor symbols defined in .opd sections to be
    function type.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_add_symbol_hook (bfd *ibfd,
                           struct bfd_link_info *info,
                           Elf_Internal_Sym *isym,
@@ -4026,7 +4128,7 @@ ppc64_elf_add_symbol_hook (bfd *ibfd,
       if (!bfd_link_relocatable (info)
          && (*sec)->reloc_count != 0
          && opd_entry_value (*sec, *value, &code_sec, NULL,
-                             FALSE) != (bfd_vma) -1
+                             false) != (bfd_vma) -1
          && discarded_section (code_sec))
        {
          *sec = bfd_und_section_ptr;
@@ -4051,42 +4153,42 @@ ppc64_elf_add_symbol_hook (bfd *ibfd,
          _bfd_error_handler (_("symbol '%s' has invalid st_other"
                                " for ABI version 1"), *name);
          bfd_set_error (bfd_error_bad_value);
-         return FALSE;
+         return false;
        }
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Merge non-visibility st_other attributes: local entry point.  */
 
 static void
 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry *h,
-                                 const Elf_Internal_Sym *isym,
-                                 bfd_boolean definition,
-                                 bfd_boolean dynamic)
+                                 unsigned int st_other,
+                                 bool definition,
+                                 bool dynamic)
 {
   if (definition && (!dynamic || !h->def_regular))
-    h->other = ((isym->st_other & ~ELF_ST_VISIBILITY (-1))
+    h->other = ((st_other & ~ELF_ST_VISIBILITY (-1))
                | ELF_ST_VISIBILITY (h->other));
 }
 
 /* Hook called on merging a symbol.  We use this to clear "fake" since
    we now have a real symbol.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_merge_symbol (struct elf_link_hash_entry *h,
                        const Elf_Internal_Sym *isym,
                        asection **psec ATTRIBUTE_UNUSED,
-                       bfd_boolean newdef ATTRIBUTE_UNUSED,
-                       bfd_boolean olddef ATTRIBUTE_UNUSED,
+                       bool newdef ATTRIBUTE_UNUSED,
+                       bool olddef ATTRIBUTE_UNUSED,
                        bfd *oldbfd ATTRIBUTE_UNUSED,
                        const asection *oldsec ATTRIBUTE_UNUSED)
 {
-  ((struct ppc_link_hash_entry *) h)->fake = 0;
+  ppc_elf_hash_entry (h)->fake = 0;
   if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)
-    ((struct ppc_link_hash_entry *) h)->non_zero_localentry = 1;
-  return TRUE;
+    ppc_elf_hash_entry (h)->non_zero_localentry = 1;
+  return true;
 }
 
 /* This function makes an old ABI object reference to ".bar" cause the
@@ -4094,17 +4196,18 @@ ppc64_elf_merge_symbol (struct elf_link_hash_entry *h,
    NAME is a symbol defined in an archive.  Return a symbol in the hash
    table that might be satisfied by the archive symbols.  */
 
-static struct elf_link_hash_entry *
+static struct bfd_link_hash_entry *
 ppc64_elf_archive_symbol_lookup (bfd *abfd,
                                 struct bfd_link_info *info,
                                 const char *name)
 {
-  struct elf_link_hash_entry *h;
+  struct bfd_link_hash_entry *h;
   char *dot_name;
   size_t len;
 
   h = _bfd_elf_archive_symbol_lookup (abfd, info, name);
   if (h != NULL
+      && ppc_hash_table (info) != NULL
       /* Don't return this sym if it is a fake function descriptor
         created by add_symbol_adjust.  */
       && !((struct ppc_link_hash_entry *) h)->fake)
@@ -4116,11 +4219,16 @@ ppc64_elf_archive_symbol_lookup (bfd *abfd,
   len = strlen (name);
   dot_name = bfd_alloc (abfd, len + 2);
   if (dot_name == NULL)
-    return (struct elf_link_hash_entry *) -1;
+    return (struct bfd_link_hash_entry *) -1;
   dot_name[0] = '.';
   memcpy (dot_name + 1, name, len + 1);
   h = _bfd_elf_archive_symbol_lookup (abfd, info, dot_name);
   bfd_release (abfd, dot_name);
+  if (h != NULL)
+    return h;
+
+  if (strcmp (name, "__tls_get_addr_opt") == 0)
+    h = _bfd_elf_archive_symbol_lookup (abfd, info, "__tls_get_addr_desc");
   return h;
 }
 
@@ -4133,7 +4241,7 @@ ppc64_elf_archive_symbol_lookup (bfd *abfd,
    most restrictive visibility of the function descriptor and the
    function entry symbol is used.  */
 
-static bfd_boolean
+static bool
 add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info)
 {
   struct ppc_link_hash_table *htab;
@@ -4143,14 +4251,14 @@ add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info)
     eh = (struct ppc_link_hash_entry *) eh->elf.root.u.i.link;
 
   if (eh->elf.root.type == bfd_link_hash_indirect)
-    return TRUE;
+    return true;
 
   if (eh->elf.root.root.string[0] != '.')
     abort ();
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   fdh = lookup_fdh (eh, htab);
   if (fdh == NULL
@@ -4164,7 +4272,7 @@ add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info)
         elsewhere.  */
       fdh = make_fdh (info, eh);
       if (fdh == NULL)
-       return FALSE;
+       return false;
     }
 
   if (fdh != NULL)
@@ -4196,17 +4304,17 @@ add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info)
              || eh->elf.def_regular))
        {
          if (!bfd_elf_link_record_dynamic_symbol (info, &fdh->elf))
-           return FALSE;
+           return false;
        }
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Set up opd section info and abiversion for IBFD, and process list
    of dot-symbols we made in link_hash_newfunc.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_before_check_relocs (bfd *ibfd, struct bfd_link_info *info)
 {
   struct ppc_link_hash_table *htab;
@@ -4226,7 +4334,7 @@ ppc64_elf_before_check_relocs (bfd *ibfd, struct bfd_link_info *info)
          _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
                              ibfd, abiversion (ibfd));
          bfd_set_error (bfd_error_bad_value);
-         return FALSE;
+         return false;
        }
     }
 
@@ -4246,7 +4354,7 @@ ppc64_elf_before_check_relocs (bfd *ibfd, struct bfd_link_info *info)
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return TRUE;
+    return true;
 
   if (opd != NULL && opd->size != 0
       && (ibfd->flags & DYNAMIC) == 0
@@ -4270,12 +4378,12 @@ ppc64_elf_before_check_relocs (bfd *ibfd, struct bfd_link_info *info)
       amt = OPD_NDX (opd->size) * sizeof (*opd_sym_map);
       opd_sym_map = bfd_zalloc (ibfd, amt);
       if (opd_sym_map == NULL)
-       return FALSE;
+       return false;
       ppc64_elf_section_data (opd)->u.opd.func_sec = opd_sym_map;
       relocs = _bfd_elf_link_read_relocs (ibfd, opd, NULL, NULL,
                                          info->keep_memory);
       if (relocs == NULL)
-       return FALSE;
+       return false;
       symtab_hdr = &elf_symtab_hdr (ibfd);
       rel_end = relocs + opd->reloc_count - 1;
       for (rel = relocs; rel < rel_end; rel++)
@@ -4290,12 +4398,13 @@ ppc64_elf_before_check_relocs (bfd *ibfd, struct bfd_link_info *info)
              Elf_Internal_Sym *isym;
              asection *s;
 
-             isym = bfd_sym_from_r_symndx (&htab->sym_cache, ibfd, r_symndx);
+             isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache, ibfd,
+                                           r_symndx);
              if (isym == NULL)
                {
                  if (elf_section_data (opd)->relocs != relocs)
                    free (relocs);
-                 return FALSE;
+                 return false;
                }
 
              s = bfd_section_from_elf_index (ibfd, isym->st_shndx);
@@ -4320,17 +4429,17 @@ ppc64_elf_before_check_relocs (bfd *ibfd, struct bfd_link_info *info)
        {
          htab->need_func_desc_adj = 1;
          if (!add_symbol_adjust (eh, info))
-           return FALSE;
+           return false;
        }
       p = &eh->u.next_dot_sym;
     }
-  return TRUE;
+  return true;
 }
 
 /* Undo hash table changes when an --as-needed input file is determined
    not to be needed.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_notice_as_needed (bfd *ibfd,
                            struct bfd_link_info *info,
                            enum notice_asneeded_action act)
@@ -4340,7 +4449,7 @@ ppc64_elf_notice_as_needed (bfd *ibfd,
       struct ppc_link_hash_table *htab = ppc_hash_table (info);
 
       if (htab == NULL)
-       return FALSE;
+       return false;
 
       htab->dot_syms = NULL;
     }
@@ -4396,15 +4505,15 @@ update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
          break;
       if (ent == NULL)
        {
-         bfd_size_type amt = sizeof (*ent);
+         size_t amt = sizeof (*ent);
          ent = bfd_alloc (abfd, amt);
          if (ent == NULL)
-           return FALSE;
+           return false;
          ent->next = local_got_ents[r_symndx];
          ent->addend = r_addend;
          ent->owner = abfd;
          ent->tls_type = tls_type;
-         ent->is_indirect = FALSE;
+         ent->is_indirect = false;
          ent->got.refcount = 0;
          local_got_ents[r_symndx] = ent;
        }
@@ -4418,7 +4527,7 @@ update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
   return local_plt + r_symndx;
 }
 
-static bfd_boolean
+static bool
 update_plt_info (bfd *abfd, struct plt_entry **plist, bfd_vma addend)
 {
   struct plt_entry *ent;
@@ -4428,20 +4537,20 @@ update_plt_info (bfd *abfd, struct plt_entry **plist, bfd_vma addend)
       break;
   if (ent == NULL)
     {
-      bfd_size_type amt = sizeof (*ent);
+      size_t amt = sizeof (*ent);
       ent = bfd_alloc (abfd, amt);
       if (ent == NULL)
-       return FALSE;
+       return false;
       ent->next = *plist;
       ent->addend = addend;
       ent->plt.refcount = 0;
       *plist = ent;
     }
   ent->plt.refcount += 1;
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 is_branch_reloc (enum elf_ppc64_reloc_type r_type)
 {
   return (r_type == R_PPC64_REL24
@@ -4459,7 +4568,7 @@ is_branch_reloc (enum elf_ppc64_reloc_type r_type)
 
 /* Relocs on inline plt call sequence insns prior to the call.  */
 
-static bfd_boolean
+static bool
 is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type)
 {
   return (r_type == R_PPC64_PLT16_HA
@@ -4476,7 +4585,7 @@ is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type)
    calculate needed space in the global offset table, procedure
    linkage table, and dynamic reloc sections.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
                        asection *sec, const Elf_Internal_Rela *relocs)
 {
@@ -4487,30 +4596,21 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
   const Elf_Internal_Rela *rel_end;
   asection *sreloc;
   struct elf_link_hash_entry *tga, *dottga;
-  bfd_boolean is_opd;
+  bool is_opd;
 
   if (bfd_link_relocatable (info))
-    return TRUE;
-
-  /* Don't do anything special with non-loaded, non-alloced sections.
-     In particular, any relocs in such sections should not affect GOT
-     and PLT reference counting (ie. we don't allow them to create GOT
-     or PLT entries), there's no possibility or desire to optimize TLS
-     relocs, and there's not much point in propagating relocs to shared
-     libs that the dynamic linker won't relocate.  */
-  if ((sec->flags & SEC_ALLOC) == 0)
-    return TRUE;
+    return true;
 
   BFD_ASSERT (is_ppc64_elf (abfd));
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
-                             FALSE, FALSE, TRUE);
+                             false, false, true);
   dottga = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
-                                FALSE, FALSE, TRUE);
+                                false, false, true);
   symtab_hdr = &elf_symtab_hdr (abfd);
   sym_hashes = elf_sym_hashes (abfd);
   sreloc = NULL;
@@ -4524,7 +4624,6 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
       int tls_type;
       struct _ppc64_elf_section_data *ppc64_sec;
       struct plt_entry **ifunc, **plt_list;
-      bfd_vma sym_addend;
 
       r_symndx = ELF64_R_SYM (rel->r_info);
       if (r_symndx < symtab_hdr->sh_info)
@@ -4538,8 +4637,6 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
            sec->has_toc_reloc = 1;
        }
 
-      tls_type = 0;
-      ifunc = NULL;
       r_type = ELF64_R_TYPE (rel->r_info);
       switch (r_type)
        {
@@ -4550,29 +4647,18 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        case R_PPC64_D28:
        case R_PPC64_TPREL34:
        case R_PPC64_DTPREL34:
-         htab->powerxx_stubs = 1;
-         /* Fall through.  */
-       default:
-         /* Somewhat foolishly, because the ABIs don't specifically
-            allow it, ppc64 gas and ld support GOT and PLT relocs
-            with non-zero addends where the addend results in
-            sym+addend being stored in the GOT or PLT entry.  This
-            can't be supported for pcrel relocs because the addend is
-            used to specify the pcrel offset.  */
-         sym_addend = rel->r_addend;
-         break;
-
        case R_PPC64_PCREL34:
        case R_PPC64_GOT_PCREL34:
-       case R_PPC64_GOT_TLSGD34:
-       case R_PPC64_GOT_TLSLD34:
-       case R_PPC64_GOT_TPREL34:
-       case R_PPC64_GOT_DTPREL34:
+       case R_PPC64_GOT_TLSGD_PCREL34:
+       case R_PPC64_GOT_TLSLD_PCREL34:
+       case R_PPC64_GOT_TPREL_PCREL34:
+       case R_PPC64_GOT_DTPREL_PCREL34:
        case R_PPC64_PLT_PCREL34:
        case R_PPC64_PLT_PCREL34_NOTOC:
        case R_PPC64_PCREL28:
-         htab->powerxx_stubs = 1;
-         sym_addend = 0;
+         htab->has_power10_relocs = 1;
+         break;
+       default:
          break;
        }
 
@@ -4603,6 +4689,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
          break;
        }
 
+      ifunc = NULL;
       if (h != NULL)
        {
          if (h->type == STT_GNU_IFUNC)
@@ -4613,21 +4700,22 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        }
       else
        {
-         Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+         Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
                                                          abfd, r_symndx);
          if (isym == NULL)
-           return FALSE;
+           return false;
 
          if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
            {
              ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
-                                            sym_addend,
+                                            rel->r_addend,
                                             NON_GOT | PLT_IFUNC);
              if (ifunc == NULL)
-               return FALSE;
+               return false;
            }
        }
 
+      tls_type = 0;
       switch (r_type)
        {
        case R_PPC64_TLSGD:
@@ -4635,12 +4723,12 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
          /* These special tls relocs tie a call to __tls_get_addr with
             its parameter symbol.  */
          if (h != NULL)
-           ((struct ppc_link_hash_entry *) h)->tls_mask |= TLS_TLS | TLS_MARK;
+           ppc_elf_hash_entry (h)->tls_mask |= TLS_TLS | TLS_MARK;
          else
            if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
-                                       sym_addend,
+                                       rel->r_addend,
                                        NON_GOT | TLS_TLS | TLS_MARK))
-             return FALSE;
+             return false;
          sec->has_tls_reloc = 1;
          break;
 
@@ -4648,7 +4736,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        case R_PPC64_GOT_TLSLD16_LO:
        case R_PPC64_GOT_TLSLD16_HI:
        case R_PPC64_GOT_TLSLD16_HA:
-       case R_PPC64_GOT_TLSLD34:
+       case R_PPC64_GOT_TLSLD_PCREL34:
          tls_type = TLS_TLS | TLS_LD;
          goto dogottls;
 
@@ -4656,7 +4744,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        case R_PPC64_GOT_TLSGD16_LO:
        case R_PPC64_GOT_TLSGD16_HI:
        case R_PPC64_GOT_TLSGD16_HA:
-       case R_PPC64_GOT_TLSGD34:
+       case R_PPC64_GOT_TLSGD_PCREL34:
          tls_type = TLS_TLS | TLS_GD;
          goto dogottls;
 
@@ -4664,7 +4752,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        case R_PPC64_GOT_TPREL16_LO_DS:
        case R_PPC64_GOT_TPREL16_HI:
        case R_PPC64_GOT_TPREL16_HA:
-       case R_PPC64_GOT_TPREL34:
+       case R_PPC64_GOT_TPREL_PCREL34:
          if (bfd_link_dll (info))
            info->flags |= DF_STATIC_TLS;
          tls_type = TLS_TLS | TLS_TPREL;
@@ -4674,7 +4762,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        case R_PPC64_GOT_DTPREL16_LO_DS:
        case R_PPC64_GOT_DTPREL16_HI:
        case R_PPC64_GOT_DTPREL16_HA:
-       case R_PPC64_GOT_DTPREL34:
+       case R_PPC64_GOT_DTPREL_PCREL34:
          tls_type = TLS_TLS | TLS_DTPREL;
        dogottls:
          sec->has_tls_reloc = 1;
@@ -4703,30 +4791,30 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
          if (ppc64_elf_tdata (abfd)->got == NULL
              && !create_got_section (abfd, info))
-           return FALSE;
+           return false;
 
          if (h != NULL)
            {
              struct ppc_link_hash_entry *eh;
              struct got_entry *ent;
 
-             eh = (struct ppc_link_hash_entry *) h;
+             eh = ppc_elf_hash_entry (h);
              for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next)
-               if (ent->addend == sym_addend
+               if (ent->addend == rel->r_addend
                    && ent->owner == abfd
                    && ent->tls_type == tls_type)
                  break;
              if (ent == NULL)
                {
-                 bfd_size_type amt = sizeof (*ent);
+                 size_t amt = sizeof (*ent);
                  ent = bfd_alloc (abfd, amt);
                  if (ent == NULL)
-                   return FALSE;
+                   return false;
                  ent->next = eh->elf.got.glist;
-                 ent->addend = sym_addend;
+                 ent->addend = rel->r_addend;
                  ent->owner = abfd;
                  ent->tls_type = tls_type;
-                 ent->is_indirect = FALSE;
+                 ent->is_indirect = false;
                  ent->got.refcount = 0;
                  eh->elf.got.glist = ent;
                }
@@ -4736,16 +4824,8 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
          else
            /* This is a global offset table entry for a local symbol.  */
            if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
-                                       sym_addend, tls_type))
-             return FALSE;
-
-         /* We may also need a plt entry if the symbol turns out to be
-            an ifunc.  */
-         if (h != NULL && !bfd_link_pic (info) && abiversion (abfd) != 1)
-           {
-             if (!update_plt_info (abfd, &h->plt.plist, sym_addend))
-               return FALSE;
-           }
+                                       rel->r_addend, tls_type))
+             return false;
          break;
 
        case R_PPC64_PLT16_HA:
@@ -4763,16 +4843,16 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
              h->needs_plt = 1;
              if (h->root.root.string[0] == '.'
                  && h->root.root.string[1] != '\0')
-               ((struct ppc_link_hash_entry *) h)->is_func = 1;
-             ((struct ppc_link_hash_entry *) h)->tls_mask |= PLT_KEEP;
+               ppc_elf_hash_entry (h)->is_func = 1;
+             ppc_elf_hash_entry (h)->tls_mask |= PLT_KEEP;
              plt_list = &h->plt.plist;
            }
          if (plt_list == NULL)
            plt_list = update_local_sym_info (abfd, symtab_hdr, r_symndx,
-                                             sym_addend,
+                                             rel->r_addend,
                                              NON_GOT | PLT_KEEP);
-         if (!update_plt_info (abfd, plt_list, sym_addend))
-           return FALSE;
+         if (!update_plt_info (abfd, plt_list, rel->r_addend))
+           return false;
          break;
 
          /* The following relocations don't need to propagate the
@@ -4828,7 +4908,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
                                      abfd, sec, rel->r_offset,
                                      ppc64_elf_howto_table[r_type]->name);
              bfd_set_error (bfd_error_bad_value);
-             return FALSE;
+             return false;
            }
          break;
 
@@ -4842,6 +4922,16 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        case R_PPC64_TOC16_HA:
        case R_PPC64_TOC16_LO_DS:
          sec->has_toc_reloc = 1;
+         if (h != NULL && bfd_link_executable (info))
+           {
+             /* We may need a copy reloc.  */
+             h->non_got_ref = 1;
+             /* Strongly prefer a copy reloc over a dynamic reloc.
+                glibc ld.so as of 2019-08 will error out if one of
+                these relocations is emitted.  */
+             h->needs_copy = 1;
+             goto dodyn;
+           }
          break;
 
          /* Marker reloc.  */
@@ -4852,14 +4942,14 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
             Reconstruct it for later use during GC.  */
        case R_PPC64_GNU_VTINHERIT:
          if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
-           return FALSE;
+           return false;
          break;
 
          /* This relocation describes which C++ vtable entries are actually
             used.  Record for later use during GC.  */
        case R_PPC64_GNU_VTENTRY:
          if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
-           return FALSE;
+           return false;
          break;
 
        case R_PPC64_REL14:
@@ -4881,10 +4971,10 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
              {
                Elf_Internal_Sym *isym;
 
-               isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+               isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
                                              abfd, r_symndx);
                if (isym == NULL)
-                 return FALSE;
+                 return false;
 
                dest = bfd_section_from_elf_index (abfd, isym->st_shndx);
              }
@@ -4908,7 +4998,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
              h->needs_plt = 1;
              if (h->root.root.string[0] == '.'
                  && h->root.root.string[1] != '\0')
-               ((struct ppc_link_hash_entry *) h)->is_func = 1;
+               ppc_elf_hash_entry (h)->is_func = 1;
 
              if (h == tga || h == dottga)
                {
@@ -4921,7 +5011,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
                    ;
                  else
                    /* Mark this section as having an old-style call.  */
-                   sec->has_tls_get_addr_call = 1;
+                   sec->nomark_tls_get_addr = 1;
                }
              plt_list = &h->plt.plist;
            }
@@ -4929,8 +5019,8 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
          /* We may need a .plt entry if the function this reloc
             refers to is in a shared lib.  */
          if (plt_list
-             && !update_plt_info (abfd, plt_list, sym_addend))
-           return FALSE;
+             && !update_plt_info (abfd, plt_list, rel->r_addend))
+           return false;
          break;
 
        case R_PPC64_ADDR14:
@@ -4966,15 +5056,11 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        dotlstoc:
          sec->has_tls_reloc = 1;
          if (h != NULL)
-           {
-             struct ppc_link_hash_entry *eh;
-             eh = (struct ppc_link_hash_entry *) h;
-             eh->tls_mask |= tls_type & 0xff;
-           }
+           ppc_elf_hash_entry (h)->tls_mask |= tls_type & 0xff;
          else
            if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
-                                       sym_addend, tls_type))
-             return FALSE;
+                                       rel->r_addend, tls_type))
+             return false;
 
          ppc64_sec = ppc64_elf_section_data (sec);
          if (ppc64_sec->sec_type != sec_toc)
@@ -4985,17 +5071,17 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
              amt = sec->size * sizeof (unsigned) / 8 + sizeof (unsigned);
              ppc64_sec->u.toc.symndx = bfd_zalloc (abfd, amt);
              if (ppc64_sec->u.toc.symndx == NULL)
-               return FALSE;
+               return false;
              amt = sec->size * sizeof (bfd_vma) / 8;
              ppc64_sec->u.toc.add = bfd_zalloc (abfd, amt);
              if (ppc64_sec->u.toc.add == NULL)
-               return FALSE;
+               return false;
              BFD_ASSERT (ppc64_sec->sec_type == sec_normal);
              ppc64_sec->sec_type = sec_toc;
            }
          BFD_ASSERT (rel->r_offset % 8 == 0);
          ppc64_sec->u.toc.symndx[rel->r_offset / 8] = r_symndx;
-         ppc64_sec->u.toc.add[rel->r_offset / 8] = sym_addend;
+         ppc64_sec->u.toc.add[rel->r_offset / 8] = rel->r_addend;
 
          /* Mark the second slot of a GD or LD entry.
             -1 to indicate GD and -2 to indicate LD.  */
@@ -5005,19 +5091,21 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
            ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -2;
          goto dodyn;
 
-       case R_PPC64_TPREL16:
-       case R_PPC64_TPREL16_LO:
        case R_PPC64_TPREL16_HI:
        case R_PPC64_TPREL16_HA:
-       case R_PPC64_TPREL16_DS:
-       case R_PPC64_TPREL16_LO_DS:
        case R_PPC64_TPREL16_HIGH:
        case R_PPC64_TPREL16_HIGHA:
        case R_PPC64_TPREL16_HIGHER:
        case R_PPC64_TPREL16_HIGHERA:
        case R_PPC64_TPREL16_HIGHEST:
        case R_PPC64_TPREL16_HIGHESTA:
+         sec->has_tls_reloc = 1;
+         /* Fall through.  */
        case R_PPC64_TPREL34:
+       case R_PPC64_TPREL16:
+       case R_PPC64_TPREL16_DS:
+       case R_PPC64_TPREL16_LO:
+       case R_PPC64_TPREL16_LO_DS:
          if (bfd_link_dll (info))
            info->flags |= DF_STATIC_TLS;
          goto dodyn;
@@ -5028,7 +5116,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
              && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC)
            {
              if (h != NULL)
-               ((struct ppc_link_hash_entry *) h)->is_func = 1;
+               ppc_elf_hash_entry (h)->is_func = 1;
            }
          /* Fall through.  */
 
@@ -5059,7 +5147,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
              /* We may need a .plt entry if this reloc refers to a
                 function in a shared lib.  */
              if (!update_plt_info (abfd, &h->plt.plist, 0))
-               return FALSE;
+               return false;
              h->pointer_equality_needed = 1;
            }
          /* Fall through.  */
@@ -5072,7 +5160,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        case R_PPC64_UADDR32:
        case R_PPC64_UADDR64:
        case R_PPC64_TOC:
-         if (h != NULL && !bfd_link_pic (info))
+         if (h != NULL && bfd_link_executable (info))
            /* We may need a copy reloc.  */
            h->non_got_ref = 1;
 
@@ -5102,17 +5190,14 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
             dynamic library if we manage to avoid copy relocs for the
             symbol.  */
        dodyn:
-         if ((bfd_link_pic (info)
-              && (must_be_dyn_reloc (info, r_type)
-                  || (h != NULL
-                      && (!SYMBOLIC_BIND (info, h)
-                          || h->root.type == bfd_link_hash_defweak
-                          || !h->def_regular))))
-             || (ELIMINATE_COPY_RELOCS
-                 && !bfd_link_pic (info)
-                 && h != NULL
-                 && (h->root.type == bfd_link_hash_defweak
-                     || !h->def_regular))
+         if ((h != NULL
+              && (h->root.type == bfd_link_hash_defweak
+                  || !h->def_regular))
+             || (h != NULL
+                 && !bfd_link_executable (info)
+                 && !SYMBOLIC_BIND (info, h))
+             || (bfd_link_pic (info)
+                 && must_be_dyn_reloc (info, r_type))
              || (!bfd_link_pic (info)
                  && ifunc != NULL))
            {
@@ -5122,10 +5207,10 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
              if (sreloc == NULL)
                {
                  sreloc = _bfd_elf_make_dynamic_reloc_section
-                   (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
+                   (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ true);
 
                  if (sreloc == NULL)
-                   return FALSE;
+                   return false;
                }
 
              /* If this is a global symbol, we count the number of
@@ -5135,13 +5220,13 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
                  struct elf_dyn_relocs *p;
                  struct elf_dyn_relocs **head;
 
-                 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
+                 head = &h->dyn_relocs;
                  p = *head;
                  if (p == NULL || p->sec != sec)
                    {
                      p = bfd_alloc (htab->elf.dynobj, sizeof *p);
                      if (p == NULL)
-                       return FALSE;
+                       return false;
                      p->next = *head;
                      *head = p;
                      p->sec = sec;
@@ -5159,15 +5244,15 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
                     easily.  Oh well.  */
                  struct ppc_dyn_relocs *p;
                  struct ppc_dyn_relocs **head;
-                 bfd_boolean is_ifunc;
+                 bool is_ifunc;
                  asection *s;
                  void *vpp;
                  Elf_Internal_Sym *isym;
 
-                 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+                 isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
                                                abfd, r_symndx);
                  if (isym == NULL)
-                   return FALSE;
+                   return false;
 
                  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
                  if (s == NULL)
@@ -5183,7 +5268,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
                    {
                      p = bfd_alloc (htab->elf.dynobj, sizeof *p);
                      if (p == NULL)
-                       return FALSE;
+                       return false;
                      p->next = *head;
                      *head = p;
                      p->sec = sec;
@@ -5200,26 +5285,26 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
        }
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Merge backend specific data from an object file to the output
    object file when linking.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 {
   bfd *obfd = info->output_bfd;
   unsigned long iflags, oflags;
 
   if ((ibfd->flags & BFD_LINKER_CREATED) != 0)
-    return TRUE;
+    return true;
 
   if (!is_ppc64_elf (ibfd) || !is_ppc64_elf (obfd))
-    return TRUE;
+    return true;
 
   if (!_bfd_generic_verify_endian_match (ibfd, info))
-    return FALSE;
+    return false;
 
   iflags = elf_elfheader (ibfd)->e_flags;
   oflags = elf_elfheader (obfd)->e_flags;
@@ -5230,7 +5315,7 @@ ppc64_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
        /* xgettext:c-format */
        (_("%pB uses unknown e_flags 0x%lx"), ibfd, iflags);
       bfd_set_error (bfd_error_bad_value);
-      return FALSE;
+      return false;
     }
   else if (iflags != oflags && iflags != 0)
     {
@@ -5239,17 +5324,17 @@ ppc64_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
        (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
         ibfd, iflags, oflags);
       bfd_set_error (bfd_error_bad_value);
-      return FALSE;
+      return false;
     }
 
   if (!_bfd_elf_ppc_merge_fp_attributes (ibfd, info))
-    return FALSE;
+    return false;
 
   /* Merge Tag_compatibility attributes and any common GNU ones.  */
   return _bfd_elf_merge_object_attributes (ibfd, info);
 }
 
-static bfd_boolean
+static bool
 ppc64_elf_print_private_bfd_data (bfd *abfd, void *ptr)
 {
   /* Print normal ELF private data.  */
@@ -5268,7 +5353,7 @@ ppc64_elf_print_private_bfd_data (bfd *abfd, void *ptr)
       fputc ('\n', file);
     }
 
-  return TRUE;
+  return true;
 }
 
 /* OFFSET in OPD_SEC specifies a function descriptor.  Return the address
@@ -5280,7 +5365,7 @@ opd_entry_value (asection *opd_sec,
                 bfd_vma offset,
                 asection **code_sec,
                 bfd_vma *code_off,
-                bfd_boolean in_code_sec)
+                bool in_code_sec)
 {
   bfd *opd_bfd = opd_sec->owner;
   Elf_Internal_Rela *relocs;
@@ -5338,7 +5423,7 @@ opd_entry_value (asection *opd_sec,
 
   relocs = ppc64_elf_tdata (opd_bfd)->opd.relocs;
   if (relocs == NULL)
-    relocs = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, TRUE);
+    relocs = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, true);
   /* PR 17512: file: df8e1fd6.  */
   if (relocs == NULL)
     return (bfd_vma) -1;
@@ -5449,14 +5534,25 @@ ppc64_elf_maybe_function_sym (const asymbol *sym, asection *sec,
                              bfd_vma *code_off)
 {
   bfd_size_type size;
+  elf_symbol_type * elf_sym = (elf_symbol_type *) sym;
 
   if ((sym->flags & (BSF_SECTION_SYM | BSF_FILE | BSF_OBJECT
                     | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC)) != 0)
     return 0;
 
-  size = 0;
-  if (!(sym->flags & BSF_SYNTHETIC))
-    size = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
+  size = (sym->flags & BSF_SYNTHETIC) ? 0 : elf_sym->internal_elf_sym.st_size;
+
+  /* In theory we should check that the symbol's type satisfies
+     _bfd_elf_is_function_type(), but there are some function-like
+     symbols which would fail this test.  (eg _start).  Instead
+     we check for hidden, local, notype symbols with zero size.
+     This type of symbol is generated by the annobin plugin for gcc
+     and clang, and should not be considered to be a function symbol.  */
+  if (size == 0
+      && ((sym->flags & (BSF_SYNTHETIC | BSF_LOCAL)) == BSF_LOCAL)
+      && ELF_ST_TYPE (elf_sym->internal_elf_sym.st_info) == STT_NOTYPE
+      && ELF_ST_VISIBILITY (elf_sym->internal_elf_sym.st_other) == STV_HIDDEN)
+    return 0;
 
   if (strcmp (sym->section->name, ".opd") == 0)
     {
@@ -5477,7 +5573,7 @@ ppc64_elf_maybe_function_sym (const asymbol *sym, asection *sec,
        }
 
       if (opd_entry_value (sym->section, symval,
-                          &sec, code_off, TRUE) == (bfd_vma) -1)
+                          &sec, code_off, true) == (bfd_vma) -1)
        return 0;
       /* An old ABI binary with dot-syms has a size of 24 on the .opd
         symbol.  This size has nothing to do with the code size of the
@@ -5500,30 +5596,30 @@ ppc64_elf_maybe_function_sym (const asymbol *sym, asection *sec,
        return 0;
       *code_off = sym->value;
     }
-  if (size == 0)
-    size = 1;
-  return size;
+
+  /* Do not return 0 for the function's size.  */
+  return size ? size : 1;
 }
 
 /* Return true if symbol is a strong function defined in an ELFv2
    object with st_other localentry bits of zero, ie. its local entry
    point coincides with its global entry point.  */
 
-static bfd_boolean
+static bool
 is_elfv2_localentry0 (struct elf_link_hash_entry *h)
 {
   return (h != NULL
          && h->type == STT_FUNC
          && h->root.type == bfd_link_hash_defined
          && (STO_PPC64_LOCAL_MASK & h->other) == 0
-         && !((struct ppc_link_hash_entry *) h)->non_zero_localentry
+         && !ppc_elf_hash_entry (h)->non_zero_localentry
          && is_ppc64_elf (h->root.u.def.section->owner)
          && abiversion (h->root.u.def.section->owner) >= 2);
 }
 
 /* Return true if symbol is defined in a regular object file.  */
 
-static bfd_boolean
+static bool
 is_static_defined (struct elf_link_hash_entry *h)
 {
   return ((h->root.type == bfd_link_hash_defined
@@ -5565,11 +5661,34 @@ defined_func_desc (struct ppc_link_hash_entry *fh)
   return NULL;
 }
 
-static bfd_boolean func_desc_adjust (struct elf_link_hash_entry *, void *);
+/* Given H is a symbol that satisfies is_static_defined, return the
+   value in the output file.  */
+
+static bfd_vma
+defined_sym_val (struct elf_link_hash_entry *h)
+{
+  return (h->root.u.def.section->output_section->vma
+         + h->root.u.def.section->output_offset
+         + h->root.u.def.value);
+}
+
+/* Return true if H matches __tls_get_addr or one of its variants.  */
+
+static bool
+is_tls_get_addr (struct elf_link_hash_entry *h,
+                struct ppc_link_hash_table *htab)
+{
+  return (h == elf_hash_entry (htab->tls_get_addr_fd)
+         || h == elf_hash_entry (htab->tga_desc_fd)
+         || h == elf_hash_entry (htab->tls_get_addr)
+         || h == elf_hash_entry (htab->tga_desc));
+}
+
+static bool func_desc_adjust (struct elf_link_hash_entry *, void *);
 
 /* Garbage collect sections, after first dealing with dot-symbols.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
 {
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
@@ -5598,8 +5717,8 @@ ppc64_elf_gc_keep (struct bfd_link_info *info)
       struct ppc_link_hash_entry *eh, *fh;
       asection *sec;
 
-      eh = (struct ppc_link_hash_entry *)
-       elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, TRUE);
+      eh = ppc_elf_hash_entry (elf_link_hash_lookup (&htab->elf, sym->name,
+                                                    false, false, true));
       if (eh == NULL)
        continue;
       if (eh->elf.root.type != bfd_link_hash_defined
@@ -5615,7 +5734,7 @@ ppc64_elf_gc_keep (struct bfd_link_info *info)
       else if (get_opd_info (eh->elf.root.u.def.section) != NULL
               && opd_entry_value (eh->elf.root.u.def.section,
                                   eh->elf.root.u.def.value,
-                                  &sec, NULL, FALSE) != (bfd_vma) -1)
+                                  &sec, NULL, false) != (bfd_vma) -1)
        sec->flags |= SEC_KEEP;
 
       sec = eh->elf.root.u.def.section;
@@ -5627,11 +5746,11 @@ ppc64_elf_gc_keep (struct bfd_link_info *info)
    building shared libraries, we must assume that any visible symbol is
    referenced.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry *h, void *inf)
 {
   struct bfd_link_info *info = (struct bfd_link_info *) inf;
-  struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
+  struct ppc_link_hash_entry *eh = ppc_elf_hash_entry (h);
   struct ppc_link_hash_entry *fdh;
   struct bfd_elf_dynamic_list *d = info->dynamic_list;
 
@@ -5642,6 +5761,9 @@ ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry *h, void *inf)
 
   if ((eh->elf.root.type == bfd_link_hash_defined
        || eh->elf.root.type == bfd_link_hash_defweak)
+      && (!eh->elf.start_stop
+         || eh->elf.root.ldscript_def
+         || !info->start_stop_gc)
       && ((eh->elf.ref_dynamic && !eh->elf.forced_local)
          || ((eh->elf.def_regular || ELF_COMMON_DEF_P (&eh->elf))
              && ELF_ST_VISIBILITY (eh->elf.other) != STV_INTERNAL
@@ -5673,11 +5795,11 @@ ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry *h, void *inf)
       else if (get_opd_info (eh->elf.root.u.def.section) != NULL
               && opd_entry_value (eh->elf.root.u.def.section,
                                   eh->elf.root.u.def.value,
-                                  &code_sec, NULL, FALSE) != (bfd_vma) -1)
+                                  &code_sec, NULL, false) != (bfd_vma) -1)
        code_sec->flags |= SEC_KEEP;
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Return the section that should be marked against GC for a given
@@ -5715,7 +5837,7 @@ ppc64_elf_gc_mark_hook (asection *sec,
            {
            case bfd_link_hash_defined:
            case bfd_link_hash_defweak:
-             eh = (struct ppc_link_hash_entry *) h;
+             eh = ppc_elf_hash_entry (h);
              fdh = defined_func_desc (eh);
              if (fdh != NULL)
                {
@@ -5741,7 +5863,7 @@ ppc64_elf_gc_mark_hook (asection *sec,
              else if (get_opd_info (eh->elf.root.u.def.section) != NULL
                       && opd_entry_value (eh->elf.root.u.def.section,
                                           eh->elf.root.u.def.value,
-                                          &rsec, NULL, FALSE) != (bfd_vma) -1)
+                                          &rsec, NULL, false) != (bfd_vma) -1)
                eh->elf.root.u.def.section->gc_mark = 1;
              else
                rsec = h->root.u.def.section;
@@ -5788,7 +5910,7 @@ struct sfpr_def_parms
    If STUB_SEC is non-null, define alias symbols in STUB_SEC
    instead.  */
 
-static bfd_boolean
+static bool
 sfpr_define (struct bfd_link_info *info,
             const struct sfpr_def_parms *parm,
             asection *stub_sec)
@@ -5796,11 +5918,11 @@ sfpr_define (struct bfd_link_info *info,
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
   unsigned int i;
   size_t len = strlen (parm->name);
-  bfd_boolean writing = FALSE;
+  bool writing = false;
   char sym[16];
 
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   memcpy (sym, parm->name, len);
   sym[len + 2] = 0;
@@ -5811,8 +5933,8 @@ sfpr_define (struct bfd_link_info *info,
 
       sym[len + 0] = i / 10 + '0';
       sym[len + 1] = i % 10 + '0';
-      h = (struct ppc_link_hash_entry *)
-       elf_link_hash_lookup (&htab->elf, sym, writing, TRUE, TRUE);
+      h = ppc_elf_hash_entry (elf_link_hash_lookup (&htab->elf, sym,
+                                                   writing, true, true));
       if (stub_sec != NULL)
        {
          if (h != NULL
@@ -5822,12 +5944,10 @@ sfpr_define (struct bfd_link_info *info,
              struct elf_link_hash_entry *s;
              char buf[32];
              sprintf (buf, "%08x.%s", stub_sec->id & 0xffffffff, sym);
-             s = elf_link_hash_lookup (&htab->elf, buf, TRUE, TRUE, FALSE);
+             s = elf_link_hash_lookup (&htab->elf, buf, true, true, false);
              if (s == NULL)
-               return FALSE;
-             if (s->root.type == bfd_link_hash_new
-                 || (s->root.type = bfd_link_hash_defined
-                     && s->root.u.def.section == stub_sec))
+               return false;
+             if (s->root.type == bfd_link_hash_new)
                {
                  s->root.type = bfd_link_hash_defined;
                  s->root.u.def.section = stub_sec;
@@ -5854,14 +5974,14 @@ sfpr_define (struct bfd_link_info *info,
              h->elf.type = STT_FUNC;
              h->elf.def_regular = 1;
              h->elf.non_elf = 0;
-             _bfd_elf_link_hash_hide_symbol (info, &h->elf, TRUE);
-             writing = TRUE;
+             _bfd_elf_link_hash_hide_symbol (info, &h->elf, true);
+             writing = true;
              if (htab->sfpr->contents == NULL)
                {
                  htab->sfpr->contents
                    = bfd_alloc (htab->elf.dynobj, SFPR_MAX);
                  if (htab->sfpr->contents == NULL)
-                   return FALSE;
+                   return false;
                }
            }
        }
@@ -5876,7 +5996,7 @@ sfpr_define (struct bfd_link_info *info,
        }
     }
 
-  return TRUE;
+  return true;
 }
 
 static bfd_byte *
@@ -6041,34 +6161,112 @@ restvr_tail (bfd *abfd, bfd_byte *p, int r)
   return p + 4;
 }
 
+#define STDU_R1_0R1    0xf8210001
+#define ADDI_R1_R1     0x38210000
+
+/* Emit prologue of wrapper preserving regs around a call to
+   __tls_get_addr_opt.  */
+
+static bfd_byte *
+tls_get_addr_prologue (bfd *obfd, bfd_byte *p, struct ppc_link_hash_table *htab)
+{
+  unsigned int i;
+
+  bfd_put_32 (obfd, MFLR_R0, p);
+  p += 4;
+  bfd_put_32 (obfd, STD_R0_0R1 + 16, p);
+  p += 4;
+
+  if (htab->opd_abi)
+    {
+      for (i = 4; i < 12; i++)
+       {
+         bfd_put_32 (obfd,
+                     STD_R0_0R1 | i << 21 | (-(13 - i) * 8 & 0xffff), p);
+         p += 4;
+       }
+      bfd_put_32 (obfd, STDU_R1_0R1 | (-128 & 0xffff), p);
+      p += 4;
+    }
+  else
+    {
+      for (i = 4; i < 12; i++)
+       {
+         bfd_put_32 (obfd,
+                     STD_R0_0R1 | i << 21 | (-(12 - i) * 8 & 0xffff), p);
+         p += 4;
+       }
+      bfd_put_32 (obfd, STDU_R1_0R1 | (-96 & 0xffff), p);
+      p += 4;
+    }
+  return p;
+}
+
+/* Emit epilogue of wrapper preserving regs around a call to
+   __tls_get_addr_opt.  */
+
+static bfd_byte *
+tls_get_addr_epilogue (bfd *obfd, bfd_byte *p, struct ppc_link_hash_table *htab)
+{
+  unsigned int i;
+
+  if (htab->opd_abi)
+    {
+      for (i = 4; i < 12; i++)
+       {
+         bfd_put_32 (obfd, LD_R0_0R1 | i << 21 | (128 - (13 - i) * 8), p);
+         p += 4;
+       }
+      bfd_put_32 (obfd, ADDI_R1_R1 | 128, p);
+      p += 4;
+    }
+  else
+    {
+      for (i = 4; i < 12; i++)
+       {
+         bfd_put_32 (obfd, LD_R0_0R1 | i << 21 | (96 - (12 - i) * 8), p);
+         p += 4;
+       }
+      bfd_put_32 (obfd, ADDI_R1_R1 | 96, p);
+      p += 4;
+    }
+  bfd_put_32 (obfd, LD_R0_0R1 | 16, p);
+  p += 4;
+  bfd_put_32 (obfd, MTLR_R0, p);
+  p += 4;
+  bfd_put_32 (obfd, BLR, p);
+  p += 4;
+  return p;
+}
+
 /* Called via elf_link_hash_traverse to transfer dynamic linking
    information on function code symbol entries to their corresponding
    function descriptor symbol entries.  */
 
-static bfd_boolean
+static bool
 func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
 {
   struct bfd_link_info *info;
   struct ppc_link_hash_table *htab;
   struct ppc_link_hash_entry *fh;
   struct ppc_link_hash_entry *fdh;
-  bfd_boolean force_local;
+  bool force_local;
 
-  fh = (struct ppc_link_hash_entry *) h;
+  fh = ppc_elf_hash_entry (h);
   if (fh->elf.root.type == bfd_link_hash_indirect)
-    return TRUE;
+    return true;
 
   if (!fh->is_func)
-    return TRUE;
+    return true;
 
   if (fh->elf.root.root.string[0] != '.'
       || fh->elf.root.root.string[1] == '\0')
-    return TRUE;
+    return true;
 
   info = inf;
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   /* Find the corresponding function descriptor symbol.  */
   fdh = lookup_fdh (fh, htab);
@@ -6085,7 +6283,7 @@ func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
       && opd_entry_value (fdh->elf.root.u.def.section,
                          fdh->elf.root.u.def.value,
                          &fh->elf.root.u.def.section,
-                         &fh->elf.root.u.def.value, FALSE) != (bfd_vma) -1)
+                         &fh->elf.root.u.def.value, false) != (bfd_vma) -1)
     {
       fh->elf.root.type = fdh->elf.root.type;
       fh->elf.forced_local = 1;
@@ -6101,7 +6299,7 @@ func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
        if (ent->plt.refcount > 0)
          break;
       if (ent == NULL)
-       return TRUE;
+       return true;
     }
 
   /* Create a descriptor as undefined if necessary.  */
@@ -6112,7 +6310,7 @@ func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
     {
       fdh = make_fdh (info, fh);
       if (fdh == NULL)
-       return FALSE;
+       return false;
     }
 
   /* We can't support overriding of symbols on a fake descriptor.  */
@@ -6120,7 +6318,7 @@ func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
       && fdh->fake
       && (fh->elf.root.type == bfd_link_hash_defined
          || fh->elf.root.type == bfd_link_hash_defweak))
-    _bfd_elf_link_hash_hide_symbol (info, &fdh->elf, TRUE);
+    _bfd_elf_link_hash_hide_symbol (info, &fdh->elf, true);
 
   /* Transfer dynamic linking information to the function descriptor.  */
   if (fdh != NULL)
@@ -6138,7 +6336,7 @@ func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
       if (!fdh->elf.forced_local
          && fh->elf.dynindx != -1)
        if (!bfd_elf_link_record_dynamic_symbol (info, &fdh->elf))
-         return FALSE;
+         return false;
     }
 
   /* Now that the info is on the function descriptor, clear the
@@ -6154,7 +6352,7 @@ func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
                 || fdh->elf.forced_local);
   _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
 
-  return TRUE;
+  return true;
 }
 
 static const struct sfpr_def_parms save_res_funcs[] =
@@ -6174,19 +6372,22 @@ static const struct sfpr_def_parms save_res_funcs[] =
   };
 
 /* Called near the start of bfd_elf_size_dynamic_sections.  We use
-   this hook to a) provide some gcc support functions, and b) transfer
-   dynamic linking information gathered so far on function code symbol
-   entries, to their corresponding function descriptor symbol entries.  */
+   this hook to a) run the edit functions in this file, b) provide
+   some gcc support functions, and c) transfer dynamic linking
+   information gathered so far on function code symbol entries, to
+   their corresponding function descriptor symbol entries.  */
 
-static bfd_boolean
-ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED,
-                           struct bfd_link_info *info)
+static bool
+ppc64_elf_edit (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
 {
   struct ppc_link_hash_table *htab;
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
+
+  /* Call back into the linker, which then runs the edit functions.  */
+  htab->params->edit ();
 
   /* Provide any missing _save* and _rest* functions.  */
   if (htab->sfpr != NULL)
@@ -6196,17 +6397,17 @@ ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED,
       htab->sfpr->size = 0;
       for (i = 0; i < ARRAY_SIZE (save_res_funcs); i++)
        if (!sfpr_define (info, &save_res_funcs[i], NULL))
-         return FALSE;
+         return false;
       if (htab->sfpr->size == 0)
        htab->sfpr->flags |= SEC_EXCLUDE;
     }
 
   if (bfd_link_relocatable (info))
-    return TRUE;
+    return true;
 
   if (htab->elf.hgot != NULL)
     {
-      _bfd_elf_link_hash_hide_symbol (info, htab->elf.hgot, TRUE);
+      _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
@@ -6229,80 +6430,59 @@ ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED,
       htab->need_func_desc_adj = 0;
     }
 
-  return TRUE;
-}
-
-/* Find dynamic relocs for H that apply to read-only sections.  */
-
-static asection *
-readonly_dynrelocs (struct elf_link_hash_entry *h)
-{
-  struct ppc_link_hash_entry *eh;
-  struct elf_dyn_relocs *p;
-
-  eh = (struct ppc_link_hash_entry *) h;
-  for (p = eh->dyn_relocs; p != NULL; p = p->next)
-    {
-      asection *s = p->sec->output_section;
-
-      if (s != NULL && (s->flags & SEC_READONLY) != 0)
-       return p->sec;
-    }
-  return NULL;
+  return true;
 }
 
 /* Return true if we have dynamic relocs against H or any of its weak
    aliases, that apply to read-only sections.  Cannot be used after
    size_dynamic_sections.  */
 
-static bfd_boolean
+static bool
 alias_readonly_dynrelocs (struct elf_link_hash_entry *h)
 {
-  struct ppc_link_hash_entry *eh;
-
-  eh = (struct ppc_link_hash_entry *) h;
+  struct ppc_link_hash_entry *eh = ppc_elf_hash_entry (h);
   do
     {
-      if (readonly_dynrelocs (&eh->elf))
-       return TRUE;
-      eh = (struct ppc_link_hash_entry *) eh->elf.u.alias;
+      if (_bfd_elf_readonly_dynrelocs (&eh->elf))
+       return true;
+      eh = ppc_elf_hash_entry (eh->elf.u.alias);
     }
   while (eh != NULL && &eh->elf != h);
 
-  return FALSE;
+  return false;
 }
 
 /* Return whether EH has pc-relative dynamic relocs.  */
 
-static bfd_boolean
+static bool
 pc_dynrelocs (struct ppc_link_hash_entry *eh)
 {
   struct elf_dyn_relocs *p;
 
-  for (p = eh->dyn_relocs; p != NULL; p = p->next)
+  for (p = eh->elf.dyn_relocs; p != NULL; p = p->next)
     if (p->pc_count != 0)
-      return TRUE;
-  return FALSE;
+      return true;
+  return false;
 }
 
 /* Return true if a global entry stub will be created for H.  Valid
    for ELFv2 before plt entries have been allocated.  */
 
-static bfd_boolean
+static bool
 global_entry_stub (struct elf_link_hash_entry *h)
 {
   struct plt_entry *pent;
 
   if (!h->pointer_equality_needed
       || h->def_regular)
-    return FALSE;
+    return false;
 
   for (pent = h->plt.plist; pent != NULL; pent = pent->next)
     if (pent->plt.refcount > 0
        && pent->addend == 0)
-      return TRUE;
+      return true;
 
-  return FALSE;
+  return false;
 }
 
 /* Adjust a symbol defined by a dynamic object and referenced by a
@@ -6311,7 +6491,7 @@ global_entry_stub (struct elf_link_hash_entry *h)
    change the definition to something the rest of the link can
    understand.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
                                 struct elf_link_hash_entry *h)
 {
@@ -6320,16 +6500,16 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   /* Deal with function syms.  */
   if (h->type == STT_FUNC
       || h->type == STT_GNU_IFUNC
       || h->needs_plt)
     {
-      bfd_boolean local = (((struct ppc_link_hash_entry *) h)->save_res
-                          || SYMBOL_CALLS_LOCAL (info, h)
-                          || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
+      bool local = (ppc_elf_hash_entry (h)->save_res
+                   || SYMBOL_CALLS_LOCAL (info, h)
+                   || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
       /* Discard dyn_relocs when non-pic if we've decided that a
         function symbol is local and not an ifunc.  We keep dynamic
         relocs for ifuncs when local rather than always emitting a
@@ -6342,7 +6522,7 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
       if (!bfd_link_pic (info)
          && h->type != STT_GNU_IFUNC
          && local)
-       ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
+       h->dyn_relocs = NULL;
 
       /* Clear procedure linkage table information for any symbol that
         won't need a .plt entry.  */
@@ -6354,7 +6534,7 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
          || (h->type != STT_GNU_IFUNC
              && local
              && (htab->can_convert_all_inline_plt
-                 || (((struct ppc_link_hash_entry *) h)->tls_mask
+                 || (ppc_elf_hash_entry (h)->tls_mask
                      & (TLS_TLS | PLT_KEEP)) != PLT_KEEP)))
        {
          h->plt.plist = NULL;
@@ -6372,7 +6552,7 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
             extra work in ld.so when resolving these symbols.  */
          if (global_entry_stub (h))
            {
-             if (!readonly_dynrelocs (h))
+             if (!_bfd_elf_readonly_dynrelocs (h))
                {
                  h->pointer_equality_needed = 0;
                  /* If we haven't seen a branch reloc and the symbol
@@ -6383,20 +6563,20 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
              else if (!bfd_link_pic (info))
                /* We are going to be defining the function symbol on the
                   plt stub, so no dyn_relocs needed when non-pic.  */
-               ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
+               h->dyn_relocs = NULL;
            }
 
          /* ELFv2 function symbols can't have copy relocs.  */
-         return TRUE;
+         return true;
        }
       else if (!h->needs_plt
-              && !readonly_dynrelocs (h))
+              && !_bfd_elf_readonly_dynrelocs (h))
        {
          /* If we haven't seen a branch reloc and the symbol isn't an
             ifunc then we don't need a plt entry.  */
          h->plt.plist = NULL;
          h->pointer_equality_needed = 0;
-         return TRUE;
+         return true;
        }
     }
   else
@@ -6413,21 +6593,21 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
       h->root.u.def.value = def->root.u.def.value;
       if (def->root.u.def.section == htab->elf.sdynbss
          || def->root.u.def.section == htab->elf.sdynrelro)
-       ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
-      return TRUE;
+       h->dyn_relocs = NULL;
+      return true;
     }
 
   /* If we are creating a shared library, we must presume that the
      only references to the symbol are via the global offset table.
      For such cases we need not do anything here; the relocations will
      be handled correctly by relocate_section.  */
-  if (bfd_link_pic (info))
-    return TRUE;
+  if (!bfd_link_executable (info))
+    return true;
 
   /* If there are no references to this symbol that do not use the
      GOT, we don't need to generate a copy reloc.  */
   if (!h->non_got_ref)
-    return TRUE;
+    return true;
 
   /* Don't generate a copy reloc for symbols defined in the executable.  */
   if (!h->def_dynamic || !h->ref_regular || h->def_regular
@@ -6437,22 +6617,34 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 
       /* If we don't find any dynamic relocs in read-only sections, then
         we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
-      || (ELIMINATE_COPY_RELOCS && !alias_readonly_dynrelocs (h))
+      || (ELIMINATE_COPY_RELOCS
+         && !h->needs_copy
+         && !alias_readonly_dynrelocs (h))
 
       /* Protected variables do not work with .dynbss.  The copy in
         .dynbss won't be used by the shared library with the protected
         definition for the variable.  Text relocations are preferable
         to an incorrect program.  */
       || h->protected_def)
-    return TRUE;
+    return true;
 
-  if (h->plt.plist != NULL)
+  if (h->type == STT_FUNC
+      || h->type == STT_GNU_IFUNC)
     {
-      /* We should never get here, but unfortunately there are versions
-        of gcc out there that improperly (for this ABI) put initialized
-        function pointers, vtable refs and suchlike in read-only
-        sections.  Allow them to proceed, but warn that this might
-        break at runtime.  */
+      /* .dynbss copies of function symbols only work if we have
+        ELFv1 dot-symbols.  ELFv1 compilers since 2004 default to not
+        use dot-symbols and set the function symbol size to the text
+        size of the function rather than the size of the descriptor.
+        That's wrong for copying a descriptor.  */
+      if (ppc_elf_hash_entry (h)->oh == NULL
+         || !(h->size == 24 || h->size == 16))
+       return true;
+
+      /* We should never get here, but unfortunately there are old
+        versions of gcc (circa gcc-3.2) that improperly for the
+        ELFv1 ABI put initialized function pointers, vtable refs and
+        suchlike in read-only sections.  Allow them to proceed, but
+        warn that this might break at runtime.  */
       info->callbacks->einfo
        (_("%P: copy reloc against `%pT' requires lazy plt linking; "
           "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
@@ -6491,7 +6683,7 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
     }
 
   /* We no longer want dyn_relocs.  */
-  ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
+  h->dyn_relocs = NULL;
   return _bfd_elf_adjust_dynamic_copy (info, h, s);
 }
 
@@ -6500,7 +6692,7 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 static void
 ppc64_elf_hide_symbol (struct bfd_link_info *info,
                       struct elf_link_hash_entry *h,
-                      bfd_boolean force_local)
+                      bool force_local)
 {
   struct ppc_link_hash_entry *eh;
   _bfd_elf_link_hash_hide_symbol (info, h, force_local);
@@ -6508,7 +6700,7 @@ ppc64_elf_hide_symbol (struct bfd_link_info *info,
   if (ppc_hash_table (info) == NULL)
     return;
 
-  eh = (struct ppc_link_hash_entry *) h;
+  eh = ppc_elf_hash_entry (h);
   if (eh->is_func_descriptor)
     {
       struct ppc_link_hash_entry *fh = eh->oh;
@@ -6531,8 +6723,8 @@ ppc64_elf_hide_symbol (struct bfd_link_info *info,
          p = eh->elf.root.root.string - 1;
          save = *p;
          *(char *) p = '.';
-         fh = (struct ppc_link_hash_entry *)
-           elf_link_hash_lookup (htab, p, FALSE, FALSE, FALSE);
+         fh = ppc_elf_hash_entry (elf_link_hash_lookup (htab, p, false,
+                                                        false, false));
          *(char *) p = save;
 
          /* Unfortunately, if it so happens that the string we were
@@ -6545,8 +6737,8 @@ ppc64_elf_hide_symbol (struct bfd_link_info *info,
              while (q >= eh->elf.root.root.string && *q == *p)
                --q, --p;
              if (q < eh->elf.root.root.string && *p == '.')
-               fh = (struct ppc_link_hash_entry *)
-                 elf_link_hash_lookup (htab, p, FALSE, FALSE, FALSE);
+               fh = ppc_elf_hash_entry (elf_link_hash_lookup (htab, p, false,
+                                                              false, false));
            }
          if (fh != NULL)
            {
@@ -6559,7 +6751,7 @@ ppc64_elf_hide_symbol (struct bfd_link_info *info,
     }
 }
 
-static bfd_boolean
+static bool
 get_sym_h (struct elf_link_hash_entry **hp,
           Elf_Internal_Sym **symp,
           asection **symsecp,
@@ -6594,12 +6786,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
        }
 
       if (tls_maskp != NULL)
-       {
-         struct ppc_link_hash_entry *eh;
-
-         eh = (struct ppc_link_hash_entry *) h;
-         *tls_maskp = &eh->tls_mask;
-       }
+       *tls_maskp = &ppc_elf_hash_entry (h)->tls_mask;
     }
   else
     {
@@ -6614,7 +6801,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
                                            symtab_hdr->sh_info,
                                            0, NULL, NULL, NULL);
          if (locsyms == NULL)
-           return FALSE;
+           return false;
          *locsymsp = locsyms;
        }
       sym = locsyms + r_symndx;
@@ -6646,7 +6833,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
          *tls_maskp = tls_mask;
        }
     }
-  return TRUE;
+  return true;
 }
 
 /* Returns TLS_MASKP for the given REL symbol.  Function return is 0 on
@@ -6756,7 +6943,7 @@ tocsave_find (struct ppc_link_hash_table *htab,
 /* Adjust all global syms defined in opd sections.  In gcc generated
    code for the old ABI, these will already have been done.  */
 
-static bfd_boolean
+static bool
 adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
 {
   struct ppc_link_hash_entry *eh;
@@ -6764,15 +6951,15 @@ adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
   struct _opd_sec_data *opd;
 
   if (h->root.type == bfd_link_hash_indirect)
-    return TRUE;
+    return true;
 
   if (h->root.type != bfd_link_hash_defined
       && h->root.type != bfd_link_hash_defweak)
-    return TRUE;
+    return true;
 
-  eh = (struct ppc_link_hash_entry *) h;
+  eh = ppc_elf_hash_entry (h);
   if (eh->adjust_done)
-    return TRUE;
+    return true;
 
   sym_sec = eh->elf.root.u.def.section;
   opd = get_opd_info (sym_sec);
@@ -6799,14 +6986,14 @@ adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
        eh->elf.root.u.def.value += adjust;
       eh->adjust_done = 1;
     }
-  return TRUE;
+  return true;
 }
 
 /* Handles decrementing dynamic reloc counts for the reloc specified by
    R_INFO in section SEC.  If LOCAL_SYMS is NULL, then H and SYM
    have already been determined.  */
 
-static bfd_boolean
+static bool
 dec_dynrel_count (bfd_vma r_info,
                  asection *sec,
                  struct bfd_link_info *info,
@@ -6823,7 +7010,17 @@ dec_dynrel_count (bfd_vma r_info,
   switch (r_type)
     {
     default:
-      return TRUE;
+      return true;
+
+    case R_PPC64_TOC16:
+    case R_PPC64_TOC16_DS:
+    case R_PPC64_TOC16_LO:
+    case R_PPC64_TOC16_HI:
+    case R_PPC64_TOC16_HA:
+    case R_PPC64_TOC16_LO_DS:
+      if (h == NULL)
+       return true;
+      break;
 
     case R_PPC64_TPREL16:
     case R_PPC64_TPREL16_LO:
@@ -6885,36 +7082,37 @@ dec_dynrel_count (bfd_vma r_info,
 
       r_symndx = ELF64_R_SYM (r_info);
       if (!get_sym_h (&h, &sym, &sym_sec, NULL, local_syms, r_symndx, ibfd))
-       return FALSE;
+       return false;
     }
 
-  if ((bfd_link_pic (info)
-       && (must_be_dyn_reloc (info, r_type)
-          || (h != NULL
-              && (!SYMBOLIC_BIND (info, h)
-                  || h->root.type == bfd_link_hash_defweak
-                  || !h->def_regular))))
-      || (ELIMINATE_COPY_RELOCS
-         && !bfd_link_pic (info)
-         && h != NULL
-         && (h->root.type == bfd_link_hash_defweak
-             || !h->def_regular)))
+  if ((h != NULL
+       && (h->root.type == bfd_link_hash_defweak
+          || !h->def_regular))
+      || (h != NULL
+         && !bfd_link_executable (info)
+         && !SYMBOLIC_BIND (info, h))
+      || (bfd_link_pic (info)
+         && must_be_dyn_reloc (info, r_type))
+      || (!bfd_link_pic (info)
+         && (h != NULL
+             ? h->type == STT_GNU_IFUNC
+             : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)))
     ;
   else
-    return TRUE;
+    return true;
 
   if (h != NULL)
     {
       struct elf_dyn_relocs *p;
       struct elf_dyn_relocs **pp;
-      pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
+      pp = &h->dyn_relocs;
 
       /* elf_gc_sweep may have already removed all dyn relocs associated
         with local syms for a given section.  Also, symbol flags are
         changed by elf_gc_sweep_symbol, confusing the test above.  Don't
         report a dynreloc miscount.  */
       if (*pp == NULL && info->gc_sections)
-       return TRUE;
+       return true;
 
       while ((p = *pp) != NULL)
        {
@@ -6925,7 +7123,7 @@ dec_dynrel_count (bfd_vma r_info,
              p->count -= 1;
              if (p->count == 0)
                *pp = p->next;
-             return TRUE;
+             return true;
            }
          pp = &p->next;
        }
@@ -6935,7 +7133,7 @@ dec_dynrel_count (bfd_vma r_info,
       struct ppc_dyn_relocs *p;
       struct ppc_dyn_relocs **pp;
       void *vpp;
-      bfd_boolean is_ifunc;
+      bool is_ifunc;
 
       if (local_syms == NULL)
        sym_sec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
@@ -6946,7 +7144,7 @@ dec_dynrel_count (bfd_vma r_info,
       pp = (struct ppc_dyn_relocs **) vpp;
 
       if (*pp == NULL && info->gc_sections)
-       return TRUE;
+       return true;
 
       is_ifunc = ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC;
       while ((p = *pp) != NULL)
@@ -6956,7 +7154,7 @@ dec_dynrel_count (bfd_vma r_info,
              p->count -= 1;
              if (p->count == 0)
                *pp = p->next;
-             return TRUE;
+             return true;
            }
          pp = &p->next;
        }
@@ -6966,7 +7164,7 @@ dec_dynrel_count (bfd_vma r_info,
   _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
                      sec->owner, sec);
   bfd_set_error (bfd_error_bad_value);
-  return FALSE;
+  return false;
 }
 
 /* Remove unused Official Procedure Descriptor entries.  Currently we
@@ -6975,17 +7173,17 @@ dec_dynrel_count (bfd_vma r_info,
    would be possible to remove many more entries for statically linked
    applications.  */
 
-bfd_boolean
+bool
 ppc64_elf_edit_opd (struct bfd_link_info *info)
 {
   bfd *ibfd;
-  bfd_boolean some_edited = FALSE;
+  bool some_edited = false;
   asection *need_pad = NULL;
   struct ppc_link_hash_table *htab;
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
     {
@@ -6994,7 +7192,7 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
       Elf_Internal_Shdr *symtab_hdr;
       Elf_Internal_Sym *local_syms;
       struct _opd_sec_data *opd;
-      bfd_boolean need_edit, add_aux_fields, broken;
+      bool need_edit, add_aux_fields, broken;
       bfd_size_type cnt_16b = 0;
 
       if (!is_ppc64_elf (ibfd))
@@ -7021,12 +7219,12 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
       relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
                                            info->keep_memory);
       if (relstart == NULL)
-       return FALSE;
+       return false;
 
       /* First run through the relocs to check they are sane, and to
         determine whether we need to edit this opd section.  */
-      need_edit = FALSE;
-      broken = FALSE;
+      need_edit = false;
+      broken = false;
       need_pad = sec;
       relend = relstart + sec->reloc_count;
       for (rel = relstart; rel < relend; )
@@ -7053,7 +7251,7 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
            broken_opd:
              _bfd_error_handler
                (_("%pB: .opd is not a regular array of opd entries"), ibfd);
-             broken = TRUE;
+             broken = true;
              break;
            }
 
@@ -7064,7 +7262,7 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
                /* xgettext:c-format */
                (_("%pB: unexpected reloc type %u in .opd section"),
                 ibfd, r_type);
-             broken = TRUE;
+             broken = true;
              break;
            }
 
@@ -7086,7 +7284,7 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
                /* xgettext:c-format */
                (_("%pB: undefined sym `%s' in .opd section"),
                 ibfd, sym_name);
-             broken = TRUE;
+             broken = true;
              break;
            }
 
@@ -7099,7 +7297,7 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
             which we test for via the output_section.  */
          if (sym_sec->owner != ibfd
              || sym_sec->output_section == bfd_abs_section_ptr)
-           need_edit = TRUE;
+           need_edit = true;
 
          rel += 2;
          if (rel + 1 == relend
@@ -7149,7 +7347,7 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
          opd = &ppc64_elf_section_data (sec)->u.opd;
          opd->adjust = bfd_zalloc (sec->owner, amt);
          if (opd->adjust == NULL)
-           return FALSE;
+           return false;
 
          /* This seems a waste of time as input .opd sections are all
             zeros as generated by gcc, but I suppose there's no reason
@@ -7160,15 +7358,13 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
              bfd_byte *loc;
              if (!bfd_malloc_and_get_section (ibfd, sec, &loc))
                {
-                 if (loc != NULL)
-                   free (loc);
+                 free (loc);
                error_ret:
-                 if (local_syms != NULL
-                     && symtab_hdr->contents != (unsigned char *) local_syms)
+                 if (symtab_hdr->contents != (unsigned char *) local_syms)
                    free (local_syms);
                  if (elf_section_data (sec)->relocs != relstart)
                    free (relstart);
-                 return FALSE;
+                 return false;
                }
              sec->contents = loc;
              sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
@@ -7181,7 +7377,7 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
            {
              new_contents = bfd_malloc (sec->size + cnt_16b * 8);
              if (new_contents == NULL)
-               return FALSE;
+               return false;
              need_pad = NULL;
            }
          wptr = new_contents;
@@ -7196,7 +7392,7 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
              Elf_Internal_Sym *sym;
              long opd_ent_size;
              Elf_Internal_Rela *next_rel;
-             bfd_boolean skip;
+             bool skip;
 
              r_symndx = ELF64_R_SYM (rel->r_info);
              if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
@@ -7224,7 +7420,7 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
              if (h != NULL
                  && h->root.root.string[0] == '.')
                {
-                 fdh = ((struct ppc_link_hash_entry *) h)->oh;
+                 fdh = ppc_elf_hash_entry (h)->oh;
                  if (fdh != NULL)
                    {
                      fdh = ppc_follow_link (fdh);
@@ -7327,7 +7523,7 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
             elf_bfd_final_link if we are emitting relocs.  */
          rel_hdr = _bfd_elf_single_rel_hdr (sec);
          rel_hdr->sh_size = sec->reloc_count * rel_hdr->sh_entsize;
-         some_edited = TRUE;
+         some_edited = true;
        }
       else if (elf_section_data (sec)->relocs != relstart)
        free (relstart);
@@ -7357,11 +7553,11 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
 
          p = bfd_malloc (need_pad->size + 8);
          if (p == NULL)
-           return FALSE;
+           return false;
 
          if (!bfd_get_section_contents (need_pad->owner, need_pad,
                                         p, 0, need_pad->size))
-           return FALSE;
+           return false;
 
          need_pad->contents = p;
          need_pad->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
@@ -7370,7 +7566,7 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
        {
          p = bfd_realloc (need_pad->contents, need_pad->size + 8);
          if (p == NULL)
-           return FALSE;
+           return false;
 
          need_pad->contents = p;
        }
@@ -7379,13 +7575,13 @@ ppc64_elf_edit_opd (struct bfd_link_info *info)
       need_pad->size += 8;
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Analyze inline PLT call relocations to see whether calls to locally
    defined functions can be converted to direct calls.  */
 
-bfd_boolean
+bool
 ppc64_elf_inline_plt (struct bfd_link_info *info)
 {
   struct ppc_link_hash_table *htab;
@@ -7395,7 +7591,7 @@ ppc64_elf_inline_plt (struct bfd_link_info *info)
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   /* A bl insn can reach -0x2000000 to 0x1fffffc.  The limit is
      reduced somewhat to cater for possible stubs that might be added
@@ -7430,7 +7626,7 @@ ppc64_elf_inline_plt (struct bfd_link_info *info)
   if (high_vma - low_vma < limit)
     {
       htab->can_convert_all_inline_plt = 1;
-      return TRUE;
+      return true;
     }
 
   /* Otherwise, go looking through relocs for cases where a direct
@@ -7467,10 +7663,10 @@ ppc64_elf_inline_plt (struct bfd_link_info *info)
            relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
                                                  info->keep_memory);
            if (relstart == NULL)
-             return FALSE;
+             return false;
 
            relend = relstart + sec->reloc_count;
-           for (rel = relstart; rel < relend; )
+           for (rel = relstart; rel < relend; rel++)
              {
                enum elf_ppc64_reloc_type r_type;
                unsigned long r_symndx;
@@ -7490,10 +7686,9 @@ ppc64_elf_inline_plt (struct bfd_link_info *info)
                  {
                    if (elf_section_data (sec)->relocs != relstart)
                      free (relstart);
-                   if (local_syms != NULL
-                       && symtab_hdr->contents != (bfd_byte *) local_syms)
+                   if (symtab_hdr->contents != (bfd_byte *) local_syms)
                      free (local_syms);
-                   return FALSE;
+                   return false;
                  }
 
                if (sym_sec != NULL && sym_sec->output_section != NULL)
@@ -7531,19 +7726,22 @@ ppc64_elf_inline_plt (struct bfd_link_info *info)
        }
     }
 
-  return TRUE;
+  return true;
 }
 
-/* Set htab->tls_get_addr and call the generic ELF tls_setup function.  */
+/* Set htab->tls_get_addr and various other info specific to TLS.
+   This needs to run before dynamic symbols are processed in
+   bfd_elf_size_dynamic_sections.  */
 
-asection *
+bool
 ppc64_elf_tls_setup (struct bfd_link_info *info)
 {
   struct ppc_link_hash_table *htab;
+  struct elf_link_hash_entry *tga, *tga_fd, *desc, *desc_fd;
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return NULL;
+    return false;
 
   if (abiversion (info->output_bfd) == 1)
     htab->opd_abi = 1;
@@ -7569,32 +7767,56 @@ ppc64_elf_tls_setup (struct bfd_link_info *info)
      --plt-localentry can cause trouble.  */
   if (htab->params->plt_localentry0 < 0)
     htab->params->plt_localentry0 = 0;
+  if (htab->params->plt_localentry0 && htab->has_power10_relocs)
+    {
+      /* The issue is that __glink_PLTresolve saves r2, which is done
+        because glibc ld.so _dl_runtime_resolve restores r2 to support
+        a glibc plt call optimisation where global entry code is
+        skipped on calls that resolve to the same binary.  The
+        __glink_PLTresolve save of r2 is incompatible with code
+        making tail calls, because the tail call might go via the
+        resolver and thus overwrite the proper saved r2.  */
+      _bfd_error_handler (_("warning: --plt-localentry is incompatible with "
+                           "power10 pc-relative code"));
+      htab->params->plt_localentry0 = 0;
+    }
   if (htab->params->plt_localentry0
       && elf_link_hash_lookup (&htab->elf, "GLIBC_2.26",
-                              FALSE, FALSE, FALSE) == NULL)
+                              false, false, false) == NULL)
     _bfd_error_handler
       (_("warning: --plt-localentry is especially dangerous without "
         "ld.so support to detect ABI violations"));
 
-  htab->tls_get_addr = ((struct ppc_link_hash_entry *)
-                       elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
-                                             FALSE, FALSE, TRUE));
+  tga = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
+                             false, false, true);
+  htab->tls_get_addr = ppc_elf_hash_entry (tga);
+
   /* Move dynamic linking info to the function descriptor sym.  */
-  if (htab->tls_get_addr != NULL)
-    func_desc_adjust (&htab->tls_get_addr->elf, info);
-  htab->tls_get_addr_fd = ((struct ppc_link_hash_entry *)
-                          elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
-                                                FALSE, FALSE, TRUE));
+  if (tga != NULL)
+    func_desc_adjust (tga, info);
+  tga_fd = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
+                                false, false, true);
+  htab->tls_get_addr_fd = ppc_elf_hash_entry (tga_fd);
+
+  desc = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr_desc",
+                              false, false, true);
+  htab->tga_desc = ppc_elf_hash_entry (desc);
+  if (desc != NULL)
+    func_desc_adjust (desc, info);
+  desc_fd = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_desc",
+                                 false, false, true);
+  htab->tga_desc_fd = ppc_elf_hash_entry (desc_fd);
+
   if (htab->params->tls_get_addr_opt)
     {
-      struct elf_link_hash_entry *opt, *opt_fd, *tga, *tga_fd;
+      struct elf_link_hash_entry *opt, *opt_fd;
 
       opt = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr_opt",
-                                 FALSE, FALSE, TRUE);
+                                 false, false, true);
       if (opt != NULL)
        func_desc_adjust (opt, info);
       opt_fd = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt",
-                                    FALSE, FALSE, TRUE);
+                                    false, false, true);
       if (opt_fd != NULL
          && (opt_fd->root.type == bfd_link_hash_defined
              || opt_fd->root.type == bfd_link_hash_defweak))
@@ -7603,24 +7825,49 @@ ppc64_elf_tls_setup (struct bfd_link_info *info)
             signalled by the presence of __tls_get_addr_opt, and we'll
             be calling __tls_get_addr via a plt call stub, then
             make __tls_get_addr point to __tls_get_addr_opt.  */
-         tga_fd = &htab->tls_get_addr_fd->elf;
-         if (htab->elf.dynamic_sections_created
-             && tga_fd != NULL
-             && (tga_fd->type == STT_FUNC
-                 || tga_fd->needs_plt)
-             && !(SYMBOL_CALLS_LOCAL (info, tga_fd)
-                  || UNDEFWEAK_NO_DYNAMIC_RELOC (info, tga_fd)))
+         if (!(htab->elf.dynamic_sections_created
+               && tga_fd != NULL
+               && (tga_fd->type == STT_FUNC
+                   || tga_fd->needs_plt)
+               && !(SYMBOL_CALLS_LOCAL (info, tga_fd)
+                    || UNDEFWEAK_NO_DYNAMIC_RELOC (info, tga_fd))))
+           tga_fd = NULL;
+         if (!(htab->elf.dynamic_sections_created
+               && desc_fd != NULL
+               && (desc_fd->type == STT_FUNC
+                   || desc_fd->needs_plt)
+               && !(SYMBOL_CALLS_LOCAL (info, desc_fd)
+                    || UNDEFWEAK_NO_DYNAMIC_RELOC (info, desc_fd))))
+           desc_fd = NULL;
+
+         if (tga_fd != NULL || desc_fd != NULL)
            {
-             struct plt_entry *ent;
+             struct plt_entry *ent = NULL;
 
-             for (ent = tga_fd->plt.plist; ent != NULL; ent = ent->next)
-               if (ent->plt.refcount > 0)
-                 break;
+             if (tga_fd != NULL)
+               for (ent = tga_fd->plt.plist; ent != NULL; ent = ent->next)
+                 if (ent->plt.refcount > 0)
+                   break;
+             if (ent == NULL && desc_fd != NULL)
+               for (ent = desc_fd->plt.plist; ent != NULL; ent = ent->next)
+                 if (ent->plt.refcount > 0)
+                   break;
              if (ent != NULL)
                {
-                 tga_fd->root.type = bfd_link_hash_indirect;
-                 tga_fd->root.u.i.link = &opt_fd->root;
-                 ppc64_elf_copy_indirect_symbol (info, opt_fd, tga_fd);
+                 if (tga_fd != NULL)
+                   {
+                     tga_fd->root.type = bfd_link_hash_indirect;
+                     tga_fd->root.u.i.link = &opt_fd->root;
+                     tga_fd->root.u.i.warning = NULL;
+                     ppc64_elf_copy_indirect_symbol (info, opt_fd, tga_fd);
+                   }
+                 if (desc_fd != NULL)
+                   {
+                     desc_fd->root.type = bfd_link_hash_indirect;
+                     desc_fd->root.u.i.link = &opt_fd->root;
+                     desc_fd->root.u.i.warning = NULL;
+                     ppc64_elf_copy_indirect_symbol (info, opt_fd, desc_fd);
+                   }
                  opt_fd->mark = 1;
                  if (opt_fd->dynindx != -1)
                    {
@@ -7629,27 +7876,52 @@ ppc64_elf_tls_setup (struct bfd_link_info *info)
                      _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
                                              opt_fd->dynstr_index);
                      if (!bfd_elf_link_record_dynamic_symbol (info, opt_fd))
-                       return NULL;
+                       return false;
                    }
-                 htab->tls_get_addr_fd
-                   = (struct ppc_link_hash_entry *) opt_fd;
-                 tga = &htab->tls_get_addr->elf;
-                 if (opt != NULL && tga != NULL)
+                 if (tga_fd != NULL)
                    {
-                     tga->root.type = bfd_link_hash_indirect;
-                     tga->root.u.i.link = &opt->root;
-                     ppc64_elf_copy_indirect_symbol (info, opt, tga);
-                     opt->mark = 1;
-                     _bfd_elf_link_hash_hide_symbol (info, opt,
-                                                     tga->forced_local);
-                     htab->tls_get_addr = (struct ppc_link_hash_entry *) opt;
+                     htab->tls_get_addr_fd = ppc_elf_hash_entry (opt_fd);
+                     tga = elf_hash_entry (htab->tls_get_addr);
+                     if (opt != NULL && tga != NULL)
+                       {
+                         tga->root.type = bfd_link_hash_indirect;
+                         tga->root.u.i.link = &opt->root;
+                         tga->root.u.i.warning = NULL;
+                         ppc64_elf_copy_indirect_symbol (info, opt, tga);
+                         opt->mark = 1;
+                         _bfd_elf_link_hash_hide_symbol (info, opt,
+                                                         tga->forced_local);
+                         htab->tls_get_addr = ppc_elf_hash_entry (opt);
+                       }
+                     htab->tls_get_addr_fd->oh = htab->tls_get_addr;
+                     htab->tls_get_addr_fd->is_func_descriptor = 1;
+                     if (htab->tls_get_addr != NULL)
+                       {
+                         htab->tls_get_addr->oh = htab->tls_get_addr_fd;
+                         htab->tls_get_addr->is_func = 1;
+                       }
                    }
-                 htab->tls_get_addr_fd->oh = htab->tls_get_addr;
-                 htab->tls_get_addr_fd->is_func_descriptor = 1;
-                 if (htab->tls_get_addr != NULL)
+                 if (desc_fd != NULL)
                    {
-                     htab->tls_get_addr->oh = htab->tls_get_addr_fd;
-                     htab->tls_get_addr->is_func = 1;
+                     htab->tga_desc_fd = ppc_elf_hash_entry (opt_fd);
+                     if (opt != NULL && desc != NULL)
+                       {
+                         desc->root.type = bfd_link_hash_indirect;
+                         desc->root.u.i.link = &opt->root;
+                         desc->root.u.i.warning = NULL;
+                         ppc64_elf_copy_indirect_symbol (info, opt, desc);
+                         opt->mark = 1;
+                         _bfd_elf_link_hash_hide_symbol (info, opt,
+                                                         desc->forced_local);
+                         htab->tga_desc = ppc_elf_hash_entry (opt);
+                       }
+                     htab->tga_desc_fd->oh = htab->tga_desc;
+                     htab->tga_desc_fd->is_func_descriptor = 1;
+                     if (htab->tga_desc != NULL)
+                       {
+                         htab->tga_desc->oh = htab->tga_desc_fd;
+                         htab->tga_desc->is_func = 1;
+                       }
                    }
                }
            }
@@ -7657,17 +7929,25 @@ ppc64_elf_tls_setup (struct bfd_link_info *info)
       else if (htab->params->tls_get_addr_opt < 0)
        htab->params->tls_get_addr_opt = 0;
     }
-  return _bfd_elf_tls_setup (info->output_bfd, info);
+
+  if (htab->tga_desc_fd != NULL
+      && htab->params->tls_get_addr_opt
+      && htab->params->no_tls_get_addr_regsave == -1)
+    htab->params->no_tls_get_addr_regsave = 0;
+
+  return true;
 }
 
 /* Return TRUE iff REL is a branch reloc with a global symbol matching
-   HASH1 or HASH2.  */
-
-static bfd_boolean
-branch_reloc_hash_match (const bfd *ibfd,
-                        const Elf_Internal_Rela *rel,
-                        const struct ppc_link_hash_entry *hash1,
-                        const struct ppc_link_hash_entry *hash2)
+   any of HASH1, HASH2, HASH3, or HASH4.  */
+
+static bool
+branch_reloc_hash_match (bfd *ibfd,
+                        Elf_Internal_Rela *rel,
+                        struct ppc_link_hash_entry *hash1,
+                        struct ppc_link_hash_entry *hash2,
+                        struct ppc_link_hash_entry *hash3,
+                        struct ppc_link_hash_entry *hash4)
 {
   Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
   enum elf_ppc64_reloc_type r_type = ELF64_R_TYPE (rel->r_info);
@@ -7680,10 +7960,13 @@ branch_reloc_hash_match (const bfd *ibfd,
 
       h = sym_hashes[r_symndx - symtab_hdr->sh_info];
       h = elf_follow_link (h);
-      if (h == &hash1->elf || h == &hash2->elf)
-       return TRUE;
+      if (h == elf_hash_entry (hash1)
+         || h == elf_hash_entry (hash2)
+         || h == elf_hash_entry (hash3)
+         || h == elf_hash_entry (hash4))
+       return true;
     }
-  return FALSE;
+  return false;
 }
 
 /* Run through all the TLS relocs looking for optimization
@@ -7693,7 +7976,7 @@ branch_reloc_hash_match (const bfd *ibfd,
    to know the tp offset, and we need to optimize before allocating
    dynamic relocations.  */
 
-bfd_boolean
+bool
 ppc64_elf_tls_optimize (struct bfd_link_info *info)
 {
   bfd *ibfd;
@@ -7703,11 +7986,13 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
   int pass;
 
   if (!bfd_link_executable (info))
-    return TRUE;
+    return true;
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
+
+  htab->do_tls_opt = 1;
 
   /* Make two passes over the relocs.  On the first pass, mark toc
      entries involved with tls relocs, and check that tls relocs
@@ -7727,7 +8012,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
          if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
            {
              Elf_Internal_Rela *relstart, *rel, *relend;
-             bfd_boolean found_tls_get_addr_arg = 0;
+             bool found_tls_get_addr_arg = 0;
 
              /* Read the relocations.  */
              relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
@@ -7735,7 +8020,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
              if (relstart == NULL)
                {
                  free (toc_ref);
-                 return FALSE;
+                 return false;
                }
 
              relend = relstart + sec->reloc_count;
@@ -7749,10 +8034,10 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                  unsigned char *tls_mask;
                  unsigned int tls_set, tls_clear, tls_type = 0;
                  bfd_vma value;
-                 bfd_boolean ok_tprel, is_local;
+                 bool ok_tprel, is_local;
                  long toc_ref_index = 0;
                  int expecting_tls_get_addr = 0;
-                 bfd_boolean ret = FALSE;
+                 bool ret = false;
 
                  r_symndx = ELF64_R_SYM (rel->r_info);
                  if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms,
@@ -7761,11 +8046,9 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                    err_free_rel:
                      if (elf_section_data (sec)->relocs != relstart)
                        free (relstart);
-                     if (toc_ref != NULL)
-                       free (toc_ref);
-                     if (locsyms != NULL
-                         && (elf_symtab_hdr (ibfd).contents
-                             != (unsigned char *) locsyms))
+                     free (toc_ref);
+                     if (elf_symtab_hdr (ibfd).contents
+                         != (unsigned char *) locsyms)
                        free (locsyms);
                      return ret;
                    }
@@ -7788,15 +8071,13 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                       STT_TLS.  So no need for .opd local sym adjust.  */
                    value = sym->st_value;
 
-                 ok_tprel = FALSE;
-                 is_local = FALSE;
-                 if (h == NULL
-                     || !h->def_dynamic)
+                 ok_tprel = false;
+                 is_local = SYMBOL_REFERENCES_LOCAL (info, h);
+                 if (is_local)
                    {
-                     is_local = TRUE;
                      if (h != NULL
                          && h->root.type == bfd_link_hash_undefweak)
-                       ok_tprel = TRUE;
+                       ok_tprel = true;
                      else if (sym_sec != NULL
                               && sym_sec->output_section != NULL)
                        {
@@ -7821,17 +8102,16 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                     setup insn.  If we don't find matching arg setup
                     relocs, don't do any tls optimization.  */
                  if (pass == 0
-                     && sec->has_tls_get_addr_call
+                     && sec->nomark_tls_get_addr
                      && h != NULL
-                     && (h == &htab->tls_get_addr->elf
-                         || h == &htab->tls_get_addr_fd->elf)
+                     && is_tls_get_addr (h, htab)
                      && !found_tls_get_addr_arg
                      && is_branch_reloc (r_type))
                    {
                      info->callbacks->minfo (_("%H __tls_get_addr lost arg, "
                                                "TLS optimization disabled\n"),
                                              ibfd, sec, rel->r_offset);
-                     ret = TRUE;
+                     ret = true;
                      goto err_free_rel;
                    }
 
@@ -7840,7 +8120,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                    {
                    case R_PPC64_GOT_TLSLD16:
                    case R_PPC64_GOT_TLSLD16_LO:
-                   case R_PPC64_GOT_TLSLD34:
+                   case R_PPC64_GOT_TLSLD_PCREL34:
                      expecting_tls_get_addr = 1;
                      found_tls_get_addr_arg = 1;
                      /* Fall through.  */
@@ -7861,7 +8141,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
 
                    case R_PPC64_GOT_TLSGD16:
                    case R_PPC64_GOT_TLSGD16_LO:
-                   case R_PPC64_GOT_TLSGD34:
+                   case R_PPC64_GOT_TLSGD_PCREL34:
                      expecting_tls_get_addr = 1;
                      found_tls_get_addr_arg = 1;
                      /* Fall through. */
@@ -7878,7 +8158,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                      tls_type = TLS_TLS | TLS_GD;
                      break;
 
-                   case R_PPC64_GOT_TPREL34:
+                   case R_PPC64_GOT_TPREL_PCREL34:
                    case R_PPC64_GOT_TPREL16_DS:
                    case R_PPC64_GOT_TPREL16_LO_DS:
                    case R_PPC64_GOT_TPREL16_HI:
@@ -7893,8 +8173,11 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                        }
                      continue;
 
-                   case R_PPC64_TLSGD:
                    case R_PPC64_TLSLD:
+                     if (!is_local)
+                       continue;
+                     /* Fall through.  */
+                   case R_PPC64_TLSGD:
                      if (rel + 1 < relend
                          && is_plt_seq_reloc (ELF64_R_TYPE (rel[1].r_info)))
                        {
@@ -8015,6 +8298,42 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                        }
                      break;
 
+                   case R_PPC64_TPREL16_HA:
+                     if (pass == 0)
+                       {
+                         unsigned char buf[4];
+                         unsigned int insn;
+                         bfd_vma off = rel->r_offset & ~3;
+                         if (!bfd_get_section_contents (ibfd, sec, buf,
+                                                        off, 4))
+                           goto err_free_rel;
+                         insn = bfd_get_32 (ibfd, buf);
+                         /* addis rt,13,imm */
+                         if ((insn & ((0x3fu << 26) | 0x1f << 16))
+                             != ((15u << 26) | (13 << 16)))
+                           {
+                             /* xgettext:c-format */
+                             info->callbacks->minfo
+                               (_("%H: warning: %s unexpected insn %#x.\n"),
+                                ibfd, sec, off, "R_PPC64_TPREL16_HA", insn);
+                             htab->do_tls_opt = 0;
+                           }
+                       }
+                     continue;
+
+                   case R_PPC64_TPREL16_HI:
+                   case R_PPC64_TPREL16_HIGH:
+                   case R_PPC64_TPREL16_HIGHA:
+                   case R_PPC64_TPREL16_HIGHER:
+                   case R_PPC64_TPREL16_HIGHERA:
+                   case R_PPC64_TPREL16_HIGHEST:
+                   case R_PPC64_TPREL16_HIGHESTA:
+                     /* These can all be used in sequences along with
+                        TPREL16_LO or TPREL16_LO_DS in ways we aren't
+                        able to verify easily.  */
+                     htab->do_tls_opt = 0;
+                     continue;
+
                    default:
                      continue;
                    }
@@ -8022,13 +8341,15 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                  if (pass == 0)
                    {
                      if (!expecting_tls_get_addr
-                         || !sec->has_tls_get_addr_call)
+                         || !sec->nomark_tls_get_addr)
                        continue;
 
                      if (rel + 1 < relend
                          && branch_reloc_hash_match (ibfd, rel + 1,
+                                                     htab->tls_get_addr_fd,
+                                                     htab->tga_desc_fd,
                                                      htab->tls_get_addr,
-                                                     htab->tls_get_addr_fd))
+                                                     htab->tga_desc))
                        {
                          if (expecting_tls_get_addr == 2)
                            {
@@ -8061,7 +8382,7 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                      info->callbacks->minfo (_("%H arg lost __tls_get_addr, "
                                                "TLS optimization disabled\n"),
                                              ibfd, sec, rel->r_offset);
-                     ret = TRUE;
+                     ret = true;
                      goto err_free_rel;
                    }
 
@@ -8074,24 +8395,38 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                     Disable optimization in this case.  */
                  if ((tls_clear & (TLS_GD | TLS_LD)) != 0
                      && (tls_set & TLS_EXPLICIT) == 0
-                     && !sec->has_tls_get_addr_call
+                     && !sec->nomark_tls_get_addr
                      && ((*tls_mask & (TLS_TLS | TLS_MARK))
                          != (TLS_TLS | TLS_MARK)))
                    continue;
 
-                 if (expecting_tls_get_addr)
+                 if (expecting_tls_get_addr == 1 + !sec->nomark_tls_get_addr)
                    {
                      struct plt_entry *ent = NULL;
 
-                     if (htab->tls_get_addr != NULL)
+                     if (htab->tls_get_addr_fd != NULL)
+                       for (ent = htab->tls_get_addr_fd->elf.plt.plist;
+                            ent != NULL;
+                            ent = ent->next)
+                         if (ent->addend == 0)
+                           break;
+
+                     if (ent == NULL && htab->tga_desc_fd != NULL)
+                       for (ent = htab->tga_desc_fd->elf.plt.plist;
+                            ent != NULL;
+                            ent = ent->next)
+                         if (ent->addend == 0)
+                           break;
+
+                     if (ent == NULL && htab->tls_get_addr != NULL)
                        for (ent = htab->tls_get_addr->elf.plt.plist;
                             ent != NULL;
                             ent = ent->next)
                          if (ent->addend == 0)
                            break;
 
-                     if (ent == NULL && htab->tls_get_addr_fd != NULL)
-                       for (ent = htab->tls_get_addr_fd->elf.plt.plist;
+                     if (ent == NULL && htab->tga_desc != NULL)
+                       for (ent = htab->tga_desc->elf.plt.plist;
                             ent != NULL;
                             ent = ent->next)
                          if (ent->addend == 0)
@@ -8136,13 +8471,13 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
                         we'll lose one or two dyn relocs.  */
                      if (!dec_dynrel_count (rel->r_info, sec, info,
                                             NULL, h, sym))
-                       return FALSE;
+                       return false;
 
                      if (tls_set == (TLS_EXPLICIT | TLS_GD))
                        {
                          if (!dec_dynrel_count ((rel + 1)->r_info, sec, info,
                                                 NULL, h, sym))
-                           return FALSE;
+                           return false;
                        }
                    }
 
@@ -8164,10 +8499,8 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
          }
       }
 
-  if (toc_ref != NULL)
-    free (toc_ref);
-  htab->do_tls_opt = 1;
-  return TRUE;
+  free (toc_ref);
+  return true;
 }
 
 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
@@ -8180,12 +8513,12 @@ struct adjust_toc_info
 {
   asection *toc;
   unsigned long *skip;
-  bfd_boolean global_toc_syms;
+  bool global_toc_syms;
 };
 
 enum toc_skip_enum { ref_from_discarded = 1, can_optimize = 2 };
 
-static bfd_boolean
+static bool
 adjust_toc_syms (struct elf_link_hash_entry *h, void *inf)
 {
   struct ppc_link_hash_entry *eh;
@@ -8194,11 +8527,11 @@ adjust_toc_syms (struct elf_link_hash_entry *h, void *inf)
 
   if (h->root.type != bfd_link_hash_defined
       && h->root.type != bfd_link_hash_defweak)
-    return TRUE;
+    return true;
 
-  eh = (struct ppc_link_hash_entry *) h;
+  eh = ppc_elf_hash_entry (h);
   if (eh->adjust_done)
-    return TRUE;
+    return true;
 
   if (eh->elf.root.u.def.section == toc_inf->toc)
     {
@@ -8221,78 +8554,98 @@ adjust_toc_syms (struct elf_link_hash_entry *h, void *inf)
       eh->adjust_done = 1;
     }
   else if (strcmp (eh->elf.root.u.def.section->name, ".toc") == 0)
-    toc_inf->global_toc_syms = TRUE;
+    toc_inf->global_toc_syms = true;
 
-  return TRUE;
+  return true;
 }
 
 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
    on a _LO variety toc/got reloc.  */
 
-static bfd_boolean
+static bool
 ok_lo_toc_insn (unsigned int insn, enum elf_ppc64_reloc_type r_type)
 {
-  return ((insn & (0x3f << 26)) == 12u << 26 /* addic */
-         || (insn & (0x3f << 26)) == 14u << 26 /* addi */
-         || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
-         || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
-         || (insn & (0x3f << 26)) == 36u << 26 /* stw */
-         || (insn & (0x3f << 26)) == 38u << 26 /* stb */
-         || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
-         || (insn & (0x3f << 26)) == 42u << 26 /* lha */
-         || (insn & (0x3f << 26)) == 44u << 26 /* sth */
-         || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
-         || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
-         || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
-         || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
-         || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
-         || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
-         || (insn & (0x3f << 26)) == 56u << 26 /* lq,lfq */
-         || ((insn & (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
+  return ((insn & (0x3fu << 26)) == 12u << 26 /* addic */
+         || (insn & (0x3fu << 26)) == 14u << 26 /* addi */
+         || (insn & (0x3fu << 26)) == 32u << 26 /* lwz */
+         || (insn & (0x3fu << 26)) == 34u << 26 /* lbz */
+         || (insn & (0x3fu << 26)) == 36u << 26 /* stw */
+         || (insn & (0x3fu << 26)) == 38u << 26 /* stb */
+         || (insn & (0x3fu << 26)) == 40u << 26 /* lhz */
+         || (insn & (0x3fu << 26)) == 42u << 26 /* lha */
+         || (insn & (0x3fu << 26)) == 44u << 26 /* sth */
+         || (insn & (0x3fu << 26)) == 46u << 26 /* lmw */
+         || (insn & (0x3fu << 26)) == 47u << 26 /* stmw */
+         || (insn & (0x3fu << 26)) == 48u << 26 /* lfs */
+         || (insn & (0x3fu << 26)) == 50u << 26 /* lfd */
+         || (insn & (0x3fu << 26)) == 52u << 26 /* stfs */
+         || (insn & (0x3fu << 26)) == 54u << 26 /* stfd */
+         || (insn & (0x3fu << 26)) == 56u << 26 /* lq,lfq */
+         || ((insn & (0x3fu << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
              /* Exclude lfqu by testing reloc.  If relocs are ever
                 defined for the reduced D field in psq_lu then those
                 will need testing too.  */
              && r_type != R_PPC64_TOC16_LO && r_type != R_PPC64_GOT16_LO)
-         || ((insn & (0x3f << 26)) == 58u << 26 /* ld,lwa */
+         || ((insn & (0x3fu << 26)) == 58u << 26 /* ld,lwa */
              && (insn & 1) == 0)
-         || (insn & (0x3f << 26)) == 60u << 26 /* stfq */
-         || ((insn & (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
+         || (insn & (0x3fu << 26)) == 60u << 26 /* stfq */
+         || ((insn & (0x3fu << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
              /* Exclude stfqu.  psq_stu as above for psq_lu.  */
              && r_type != R_PPC64_TOC16_LO && r_type != R_PPC64_GOT16_LO)
-         || ((insn & (0x3f << 26)) == 62u << 26 /* std,stq */
+         || ((insn & (0x3fu << 26)) == 62u << 26 /* std,stq */
              && (insn & 1) == 0));
 }
 
 /* PCREL_OPT in one instance flags to the linker that a pair of insns:
      pld ra,symbol@got@pcrel
-     load/store rt,0(ra)
+     load/store rt,off(ra)
    or
      pla ra,symbol@pcrel
-     load/store rt,0(ra)
+     load/store rt,off(ra)
    may be translated to
-     pload/pstore rt,symbol@pcrel
+     pload/pstore rt,symbol+off@pcrel
      nop.
    This function returns true if the optimization is possible, placing
-   the prefix insn in *PINSN1 and a NOP in *PINSN2.
+   the prefix insn in *PINSN1, a NOP in *PINSN2 and the offset in *POFF.
 
    On entry to this function, the linker has already determined that
    the pld can be replaced with pla: *PINSN1 is that pla insn,
    while *PINSN2 is the second instruction.  */
 
-static bfd_boolean
-xlate_pcrel_opt (uint64_t *pinsn1, uint64_t *pinsn2)
+static bool
+xlate_pcrel_opt (uint64_t *pinsn1, uint64_t *pinsn2, bfd_signed_vma *poff)
 {
-  uint32_t insn2 = *pinsn2 >> 32;
-  uint64_t i1new;
+  uint64_t insn1 = *pinsn1;
+  uint64_t insn2 = *pinsn2;
+  bfd_signed_vma off;
+
+  if ((insn2 & (63ULL << 58)) == 1ULL << 58)
+    {
+      /* Check that regs match.  */
+      if (((insn2 >> 16) & 31) != ((insn1 >> 21) & 31))
+       return false;
+
+      /* P8LS or PMLS form, non-pcrel.  */
+      if ((insn2 & (-1ULL << 50) & ~(1ULL << 56)) != (1ULL << 58))
+       return false;
+
+      *pinsn1 = (insn2 & ~(31 << 16) & ~0x3ffff0000ffffULL) | (1ULL << 52);
+      *pinsn2 = PNOP;
+      off = ((insn2 >> 16) & 0x3ffff0000ULL) | (insn2 & 0xffff);
+      *poff = (off ^ 0x200000000ULL) - 0x200000000ULL;
+      return true;
+    }
+
+  insn2 >>= 32;
 
   /* Check that regs match.  */
-  if (((insn2 >> 16) & 31) != ((*pinsn1 >> 21) & 31))
-    return FALSE;
+  if (((insn2 >> 16) & 31) != ((insn1 >> 21) & 31))
+    return false;
 
   switch ((insn2 >> 26) & 63)
     {
     default:
-      return FALSE;
+      return false;
 
     case 32: /* lwz */
     case 34: /* lbz */
@@ -8306,75 +8659,84 @@ xlate_pcrel_opt (uint64_t *pinsn1, uint64_t *pinsn2)
     case 52: /* stfs */
     case 54: /* stfd */
       /* These are the PMLS cases, where we just need to tack a prefix
-        on the insn.  Check that the D field is zero.  */
-      if ((insn2 & 0xffff) != 0)
-       return FALSE;
-      i1new = ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
+        on the insn.  */
+      insn1 = ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
               | (insn2 & ((63ULL << 26) | (31ULL << 21))));
+      off = insn2 & 0xffff;
       break;
 
     case 58: /* lwa, ld */
-      if ((insn2 & 0xfffd) != 0)
-       return FALSE;
-      i1new = ((1ULL << 58) | (1ULL << 52)
+      if ((insn2 & 1) != 0)
+       return false;
+      insn1 = ((1ULL << 58) | (1ULL << 52)
               | (insn2 & 2 ? 41ULL << 26 : 57ULL << 26)
               | (insn2 & (31ULL << 21)));
+      off = insn2 & 0xfffc;
       break;
 
     case 57: /* lxsd, lxssp */
-      if ((insn2 & 0xfffc) != 0 || (insn2 & 3) < 2)
-       return FALSE;
-      i1new = ((1ULL << 58) | (1ULL << 52)
+      if ((insn2 & 3) < 2)
+       return false;
+      insn1 = ((1ULL << 58) | (1ULL << 52)
               | ((40ULL | (insn2 & 3)) << 26)
               | (insn2 & (31ULL << 21)));
+      off = insn2 & 0xfffc;
       break;
 
     case 61: /* stxsd, stxssp, lxv, stxv  */
       if ((insn2 & 3) == 0)
-       return FALSE;
+       return false;
       else if ((insn2 & 3) >= 2)
        {
-         if ((insn2 & 0xfffc) != 0)
-           return FALSE;
-         i1new = ((1ULL << 58) | (1ULL << 52)
+         insn1 = ((1ULL << 58) | (1ULL << 52)
                   | ((44ULL | (insn2 & 3)) << 26)
                   | (insn2 & (31ULL << 21)));
+         off = insn2 & 0xfffc;
        }
       else
        {
-         if ((insn2 & 0xfff0) != 0)
-           return FALSE;
-         i1new = ((1ULL << 58) | (1ULL << 52)
+         insn1 = ((1ULL << 58) | (1ULL << 52)
                   | ((50ULL | (insn2 & 4) | ((insn2 & 8) >> 3)) << 26)
                   | (insn2 & (31ULL << 21)));
+         off = insn2 & 0xfff0;
        }
       break;
 
     case 56: /* lq */
-      if ((insn2 & 0xffff) != 0)
-       return FALSE;
-      i1new = ((1ULL << 58) | (1ULL << 52)
+      insn1 = ((1ULL << 58) | (1ULL << 52)
               | (insn2 & ((63ULL << 26) | (31ULL << 21))));
+      off = insn2 & 0xffff;
+      break;
+
+    case 6: /* lxvp, stxvp */
+      if ((insn2 & 0xe) != 0)
+       return false;
+      insn1 = ((1ULL << 58) | (1ULL << 52)
+              | ((insn2 & 1) == 0 ? 58ULL << 26 : 62ULL << 26)
+              | (insn2 & (31ULL << 21)));
+      off = insn2 & 0xfff0;
       break;
 
     case 62: /* std, stq */
-      if ((insn2 & 0xfffd) != 0)
-       return FALSE;
-      i1new = ((1ULL << 58) | (1ULL << 52)
+      if ((insn2 & 1) != 0)
+       return false;
+      insn1 = ((1ULL << 58) | (1ULL << 52)
               | ((insn2 & 2) == 0 ? 61ULL << 26 : 60ULL << 26)
               | (insn2 & (31ULL << 21)));
+      off = insn2 & 0xfffc;
       break;
     }
 
-  *pinsn1 = i1new;
+  *pinsn1 = insn1;
   *pinsn2 = (uint64_t) NOP << 32;
-  return TRUE;
+  *poff = (off ^ 0x8000) - 0x8000;
+  return true;
 }
 
 /* Examine all relocs referencing .toc sections in order to remove
    unused .toc entries.  */
 
-bfd_boolean
+bool
 ppc64_elf_edit_toc (struct bfd_link_info *info)
 {
   bfd *ibfd;
@@ -8382,7 +8744,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
 
   htab->do_toc_opt = 1;
-  toc_inf.global_toc_syms = TRUE;
+  toc_inf.global_toc_syms = true;
   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
     {
       asection *toc, *sec;
@@ -8419,7 +8781,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
              || (sec->flags & SEC_DEBUGGING) != 0)
            continue;
 
-         relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, FALSE);
+         relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, false);
          if (relstart == NULL)
            goto error_ret;
 
@@ -8576,19 +8938,15 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
       if (used == NULL)
        {
        error_ret:
-         if (local_syms != NULL
-             && symtab_hdr->contents != (unsigned char *) local_syms)
+         if (symtab_hdr->contents != (unsigned char *) local_syms)
            free (local_syms);
          if (sec != NULL
-             && relstart != NULL
              && elf_section_data (sec)->relocs != relstart)
            free (relstart);
-         if (toc_relocs != NULL
-             && elf_section_data (toc)->relocs != toc_relocs)
+         if (elf_section_data (toc)->relocs != toc_relocs)
            free (toc_relocs);
-         if (skip != NULL)
-           free (skip);
-         return FALSE;
+         free (skip);
+         return false;
        }
 
       /* Now check all kept sections that might reference the toc.
@@ -8749,7 +9107,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
          bfd_byte *contents, *src;
          unsigned long off;
          Elf_Internal_Sym *sym;
-         bfd_boolean local_toc_syms = FALSE;
+         bool local_toc_syms = false;
 
          /* Shuffle the toc contents, and at the same time convert the
             skip array from booleans into offsets.  */
@@ -8825,7 +9183,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
                    {
                      val = sym->st_value;
                      if (val != 0)
-                       local_toc_syms = TRUE;
+                       local_toc_syms = true;
                    }
 
                  val += rel->r_addend;
@@ -8915,7 +9273,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
            {
              toc_inf.toc = toc;
              toc_inf.skip = skip;
-             toc_inf.global_toc_syms = FALSE;
+             toc_inf.global_toc_syms = false;
              elf_link_hash_traverse (elf_hash_table (info), adjust_toc_syms,
                                      &toc_inf);
            }
@@ -8954,8 +9312,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
              rel_hdr->sh_size = toc->reloc_count * sz;
            }
        }
-      else if (toc_relocs != NULL
-              && elf_section_data (toc)->relocs != toc_relocs)
+      else if (elf_section_data (toc)->relocs != toc_relocs)
        free (toc_relocs);
 
       if (local_syms != NULL
@@ -9006,14 +9363,12 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
          if (relstart == NULL)
            {
            got_error_ret:
-             if (local_syms != NULL
-                 && symtab_hdr->contents != (unsigned char *) local_syms)
+             if (symtab_hdr->contents != (unsigned char *) local_syms)
                free (local_syms);
              if (sec != NULL
-                 && relstart != NULL
                  && elf_section_data (sec)->relocs != relstart)
                free (relstart);
-             return FALSE;
+             return false;
            }
 
          for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
@@ -9024,7 +9379,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
              asection *sym_sec;
              struct elf_link_hash_entry *h;
              struct got_entry *ent;
-             bfd_vma sym_addend, val, pc;
+             bfd_vma val, pc;
              unsigned char buf[8];
              unsigned int insn;
              enum {no_check, check_lo, check_ha} insn_check;
@@ -9070,7 +9425,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
                  insn = bfd_get_32 (ibfd, buf);
                  if (insn_check == check_lo
                      ? !ok_lo_toc_insn (insn, r_type)
-                     : ((insn & ((0x3f << 26) | 0x1f << 16))
+                     : ((insn & ((0x3fu << 26) | 0x1f << 16))
                         != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
                    {
                      char str[12];
@@ -9099,11 +9454,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
 
                case R_PPC64_GOT16_HA:
                case R_PPC64_GOT16_LO_DS:
-                 sym_addend = rel->r_addend;
-                 break;
-
                case R_PPC64_GOT_PCREL34:
-                 sym_addend = 0;
                  break;
                }
 
@@ -9117,6 +9468,9 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
                  || discarded_section (sym_sec))
                continue;
 
+             if ((h ? h->type : ELF_ST_TYPE (sym->st_info)) == STT_GNU_IFUNC)
+               continue;
+
              if (!SYMBOL_REFERENCES_LOCAL (info, h))
                continue;
 
@@ -9124,7 +9478,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
                val = h->root.u.def.value;
              else
                val = sym->st_value;
-             val += sym_addend;
+             val += rel->r_addend;
              val += sym_sec->output_section->vma + sym_sec->output_offset;
 
 /* Fudge factor to allow for the fact that the preliminary layout
@@ -9145,7 +9499,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
                                                 rel->r_offset & ~3, 4))
                    goto got_error_ret;
                  insn = bfd_get_32 (ibfd, buf);
-                 if (((insn & ((0x3f << 26) | 0x1f << 16))
+                 if (((insn & ((0x3fu << 26) | 0x1f << 16))
                       != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
                    continue;
                  break;
@@ -9158,7 +9512,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
                                                 rel->r_offset & ~3, 4))
                    goto got_error_ret;
                  insn = bfd_get_32 (ibfd, buf);
-                 if ((insn & (0x3f << 26 | 0x3)) != 58u << 26 /* ld */)
+                 if ((insn & (0x3fu << 26 | 0x3)) != 58u << 26 /* ld */)
                    continue;
                  break;
 
@@ -9175,7 +9529,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
                  if ((insn & (-1u << 18)) != ((1u << 26) | (1u << 20)))
                    continue;
                  insn = bfd_get_32 (ibfd, buf + 4);
-                 if ((insn & (0x3f << 26)) != 57u << 26)
+                 if ((insn & (0x3fu << 26)) != 57u << 26)
                    continue;
                  break;
                }
@@ -9189,7 +9543,7 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
                  ent = local_got_ents[r_symndx];
                }
              for (; ent != NULL; ent = ent->next)
-               if (ent->addend == sym_addend
+               if (ent->addend == rel->r_addend
                    && ent->owner == ibfd
                    && ent->tls_type == 0)
                  break;
@@ -9211,13 +9565,13 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
        }
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Return true iff input section I references the TOC using
    instructions limited to +/-32k offsets.  */
 
-bfd_boolean
+bool
 ppc64_elf_has_small_toc_reloc (asection *i)
 {
   return (is_ppc64_elf (i->owner)
@@ -9232,7 +9586,7 @@ allocate_got (struct elf_link_hash_entry *h,
              struct got_entry *gent)
 {
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
-  struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
+  struct ppc_link_hash_entry *eh = ppc_elf_hash_entry (h);
   int entsize = (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)
                 ? 16 : 8);
   int rentsize = (gent->tls_type & eh->tls_mask & TLS_GD
@@ -9248,7 +9602,7 @@ allocate_got (struct elf_link_hash_entry *h,
       htab->got_reli_size += rentsize;
     }
   else if (((bfd_link_pic (info)
-            && !((gent->tls_type & TLS_TPREL) != 0
+            && !(gent->tls_type != 0
                  && bfd_link_executable (info)
                  && SYMBOL_REFERENCES_LOCAL (info, h)))
            || (htab->elf.dynamic_sections_created
@@ -9276,14 +9630,14 @@ merge_got_entries (struct got_entry **pent)
            && ent2->tls_type == ent->tls_type
            && elf_gp (ent2->owner) == elf_gp (ent->owner))
          {
-           ent2->is_indirect = TRUE;
+           ent2->is_indirect = true;
            ent2->got.ent = ent;
          }
 }
 
 /* If H is undefined, make it dynamic if that makes sense.  */
 
-static bfd_boolean
+static bool
 ensure_undef_dynamic (struct bfd_link_info *info,
                      struct elf_link_hash_entry *h)
 {
@@ -9297,13 +9651,25 @@ ensure_undef_dynamic (struct bfd_link_info *info,
       && !h->forced_local
       && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
     return bfd_elf_link_record_dynamic_symbol (info, h);
-  return TRUE;
+  return true;
+}
+
+/* Choose whether to use htab->iplt or htab->pltlocal rather than the
+   usual htab->elf.splt section for a PLT entry.  */
+
+static inline
+bool use_local_plt (struct bfd_link_info *info,
+                          struct elf_link_hash_entry *h)
+{
+  return (h == NULL
+         || h->dynindx == -1
+         || !elf_hash_table (info)->dynamic_sections_created);
 }
 
 /* Allocate space in .plt, .got and associated reloc sections for
    dynamic relocs.  */
 
-static bfd_boolean
+static bool
 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 {
   struct bfd_link_info *info;
@@ -9313,14 +9679,14 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   struct got_entry **pgent, *gent;
 
   if (h->root.type == bfd_link_hash_indirect)
-    return TRUE;
+    return true;
 
   info = (struct bfd_link_info *) inf;
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
-  eh = (struct ppc_link_hash_entry *) h;
+  eh = ppc_elf_hash_entry (h);
   /* Run through the TLS GD got entries first if we're changing them
      to TPREL.  */
   if ((eh->tls_mask & (TLS_TLS | TLS_GDIE)) == (TLS_TLS | TLS_GDIE))
@@ -9354,7 +9720,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
     if (gent->got.refcount > 0)
       {
        if ((gent->tls_type & TLS_LD) != 0
-           && !h->def_dynamic)
+           && SYMBOL_REFERENCES_LOCAL (info, h))
          {
            ppc64_tlsld_got (gent->owner)->got.refcount += 1;
            *pgent = gent->next;
@@ -9371,9 +9737,10 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   for (gent = h->got.glist; gent != NULL; gent = gent->next)
     if (!gent->is_indirect)
       {
-       /* Make sure this symbol is output as a dynamic symbol.  */
+       /* Ensure we catch all the cases where this symbol should
+          be made dynamic.  */
        if (!ensure_undef_dynamic (info, h))
-         return FALSE;
+         return false;
 
        if (!is_ppc64_elf (gent->owner))
          abort ();
@@ -9385,19 +9752,19 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
      IFUNCs which are handled even in static executables.  */
   if (!htab->elf.dynamic_sections_created
       && h->type != STT_GNU_IFUNC)
-    eh->dyn_relocs = NULL;
+    h->dyn_relocs = NULL;
 
   /* Discard relocs on undefined symbols that must be local.  */
   else if (h->root.type == bfd_link_hash_undefined
           && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
-    eh->dyn_relocs = NULL;
+    h->dyn_relocs = NULL;
 
   /* Also discard relocs on undefined weak syms with non-default
      visibility, or when dynamic_undefined_weak says so.  */
   else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
-    eh->dyn_relocs = NULL;
+    h->dyn_relocs = NULL;
 
-  if (eh->dyn_relocs != NULL)
+  if (h->dyn_relocs != NULL)
     {
       struct elf_dyn_relocs *p, **pp;
 
@@ -9406,7 +9773,6 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
         be defined in regular objects.  For the normal shared case,
         discard space for relocs that have become local due to symbol
         visibility changes.  */
-
       if (bfd_link_pic (info))
        {
          /* Relocs that use pc_count are those that appear on a call
@@ -9418,7 +9784,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
             avoid writing weird assembly.  */
          if (SYMBOL_CALLS_LOCAL (info, h))
            {
-             for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
+             for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
                {
                  p->count -= p->pc_count;
                  p->pc_count = 0;
@@ -9429,35 +9795,42 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
                }
            }
 
-         if (eh->dyn_relocs != NULL)
+         if (h->dyn_relocs != NULL)
            {
-             /* Make sure this symbol is output as a dynamic symbol.  */
+             /* Ensure we catch all the cases where this symbol
+                should be made dynamic.  */
              if (!ensure_undef_dynamic (info, h))
-               return FALSE;
+               return false;
            }
        }
-      else if (ELIMINATE_COPY_RELOCS && h->type != STT_GNU_IFUNC)
+
+      /* For a fixed position executable, discard space for
+        relocs against symbols which are not dynamic.  */
+      else if (h->type != STT_GNU_IFUNC)
        {
-         /* For the non-pic case, discard space for relocs against
-            symbols which turn out to need copy relocs or are not
-            dynamic.  */
-         if (h->dynamic_adjusted
+         if ((h->dynamic_adjusted
+              || (h->ref_regular
+                  && h->root.type == bfd_link_hash_undefweak
+                  && (info->dynamic_undefined_weak > 0
+                      || !_bfd_elf_readonly_dynrelocs (h))))
              && !h->def_regular
              && !ELF_COMMON_DEF_P (h))
            {
-             /* Make sure this symbol is output as a dynamic symbol.  */
+             /* Ensure we catch all the cases where this symbol
+                should be made dynamic.  */
              if (!ensure_undef_dynamic (info, h))
-               return FALSE;
+               return false;
 
+             /* But if that didn't work out, discard dynamic relocs.  */
              if (h->dynindx == -1)
-               eh->dyn_relocs = NULL;
+               h->dyn_relocs = NULL;
            }
          else
-           eh->dyn_relocs = NULL;
+           h->dyn_relocs = NULL;
        }
 
       /* Finally, allocate space.  */
-      for (p = eh->dyn_relocs; p != NULL; p = p->next)
+      for (p = h->dyn_relocs; p != NULL; p = p->next)
        {
          asection *sreloc = elf_section_data (p->sec)->sreloc;
          if (eh->elf.type == STT_GNU_IFUNC)
@@ -9478,16 +9851,18 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
          && h->def_regular
          && !htab->elf.dynamic_sections_created
          && !htab->can_convert_all_inline_plt
-         && (((struct ppc_link_hash_entry *) h)->tls_mask
+         && (ppc_elf_hash_entry (h)->tls_mask
              & (TLS_TLS | PLT_KEEP)) == PLT_KEEP))
     {
       struct plt_entry *pent;
-      bfd_boolean doneone = FALSE;
+      bool doneone = false;
       for (pent = h->plt.plist; pent != NULL; pent = pent->next)
        if (pent->plt.refcount > 0)
          {
-           if (!htab->elf.dynamic_sections_created
-               || h->dynindx == -1)
+           if (!ensure_undef_dynamic (info, h))
+             return false;
+
+           if (use_local_plt (info, h))
              {
                if (h->type == STT_GNU_IFUNC)
                  {
@@ -9536,7 +9911,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
              }
            if (s != NULL)
              s->size += sizeof (Elf64_External_Rela);
-           doneone = TRUE;
+           doneone = true;
          }
        else
          pent->plt.offset = (bfd_vma) -1;
@@ -9552,7 +9927,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
       h->needs_plt = 0;
     }
 
-  return TRUE;
+  return true;
 }
 
 #define PPC_LO(v) ((v) & 0xffff)
@@ -9566,7 +9941,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
    to set up space for global entry stubs.  These are put in glink,
    after the branch table.  */
 
-static bfd_boolean
+static bool
 size_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
 {
   struct bfd_link_info *info;
@@ -9575,18 +9950,18 @@ size_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
   asection *s, *plt;
 
   if (h->root.type == bfd_link_hash_indirect)
-    return TRUE;
+    return true;
 
   if (!h->pointer_equality_needed)
-    return TRUE;
+    return true;
 
   if (h->def_regular)
-    return TRUE;
+    return true;
 
   info = inf;
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   s = htab->global_entry;
   plt = htab->elf.splt;
@@ -9633,52 +10008,25 @@ size_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
        s->size = stub_off + stub_size;
        break;
       }
-  return TRUE;
-}
-
-/* Set DF_TEXTREL if we find any dynamic relocs that apply to
-   read-only sections.  */
-
-static bfd_boolean
-maybe_set_textrel (struct elf_link_hash_entry *h, void *inf)
-{
-  asection *sec;
-
-  if (h->root.type == bfd_link_hash_indirect)
-    return TRUE;
-
-  sec = readonly_dynrelocs (h);
-  if (sec != NULL)
-    {
-      struct bfd_link_info *info = (struct bfd_link_info *) inf;
-
-      info->flags |= DF_TEXTREL;
-      info->callbacks->minfo (_("%pB: dynamic relocation against `%pT'"
-                               " in read-only section `%pA'\n"),
-                             sec->owner, h->root.root.string, sec);
-
-      /* Not an error, just cut short the traversal.  */
-      return FALSE;
-    }
-  return TRUE;
+  return true;
 }
 
 /* Set the sizes of the dynamic sections.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_size_dynamic_sections (bfd *output_bfd,
                                 struct bfd_link_info *info)
 {
   struct ppc_link_hash_table *htab;
   bfd *dynobj;
   asection *s;
-  bfd_boolean relocs;
+  bool relocs;
   bfd *ibfd;
   struct got_entry *first_tlsld;
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   dynobj = htab->elf.dynobj;
   if (dynobj == NULL)
@@ -9780,7 +10128,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
                        htab->got_reli_size += rel_size;
                      }
                    else if (bfd_link_pic (info)
-                            && !((ent->tls_type & TLS_TPREL) != 0
+                            && !(ent->tls_type != 0
                                  && bfd_link_executable (info)))
                      {
                        asection *srel = ppc64_elf_tdata (ibfd)->relgot;
@@ -9846,7 +10194,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
        {
          if (!htab->do_multi_toc && first_tlsld != NULL)
            {
-             ent->is_indirect = TRUE;
+             ent->is_indirect = true;
              ent->got.ent = first_tlsld;
            }
          else
@@ -9857,7 +10205,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
              ent->got.offset = s->size;
              ent->owner = ibfd;
              s->size += 16;
-             if (bfd_link_pic (info))
+             if (bfd_link_dll (info))
                {
                  asection *srel = ppc64_elf_tdata (ibfd)->relgot;
                  srel->size += sizeof (Elf64_External_Rela);
@@ -9870,7 +10218,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
 
   /* We now have determined the sizes of the various dynamic sections.
      Allocate memory for them.  */
-  relocs = FALSE;
+  relocs = false;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       if ((s->flags & SEC_LINKER_CREATED) == 0)
@@ -9897,12 +10245,12 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
            /* Not sized yet.  */
            continue;
        }
-      else if (CONST_STRNEQ (s->name, ".rela"))
+      else if (startswith (s->name, ".rela"))
        {
          if (s->size != 0)
            {
              if (s != htab->elf.srelplt)
-               relocs = TRUE;
+               relocs = true;
 
              /* We use the reloc_count field as a counter if we need
                 to copy relocs into the output file.  */
@@ -9946,7 +10294,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
         the GOT and .dynrelro.  */
       s->contents = bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
-       return FALSE;
+       return false;
     }
 
   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
@@ -9963,7 +10311,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
            {
              s->contents = bfd_zalloc (ibfd, s->size);
              if (s->contents == NULL)
-               return FALSE;
+               return false;
            }
        }
       s = ppc64_elf_tdata (ibfd)->relgot;
@@ -9975,8 +10323,8 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
            {
              s->contents = bfd_zalloc (ibfd, s->size);
              if (s->contents == NULL)
-               return FALSE;
-             relocs = TRUE;
+               return false;
+             relocs = true;
              s->reloc_count = 0;
            }
        }
@@ -9984,7 +10332,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
 
   if (htab->elf.dynamic_sections_created)
     {
-      bfd_boolean tls_opt;
+      bool tls_opt;
 
       /* Add some entries to the .dynamic section.  We fill in the
         values later, in ppc64_elf_finish_dynamic_sections, but we
@@ -9997,7 +10345,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
       if (bfd_link_executable (info))
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
+           return false;
        }
 
       if (htab->elf.splt != NULL && htab->elf.splt->size != 0)
@@ -10007,23 +10355,25 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
              || !add_dynamic_entry (DT_PLTREL, DT_RELA)
              || !add_dynamic_entry (DT_JMPREL, 0)
              || !add_dynamic_entry (DT_PPC64_GLINK, 0))
-           return FALSE;
+           return false;
        }
 
       if (NO_OPD_RELOCS && abiversion (output_bfd) <= 1)
        {
          if (!add_dynamic_entry (DT_PPC64_OPD, 0)
              || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
-           return FALSE;
+           return false;
        }
 
       tls_opt = (htab->params->tls_get_addr_opt
-                && htab->tls_get_addr_fd != NULL
-                && htab->tls_get_addr_fd->elf.plt.plist != NULL);
+                && ((htab->tls_get_addr_fd != NULL
+                     && htab->tls_get_addr_fd->elf.plt.plist != NULL)
+                    || (htab->tga_desc_fd != NULL
+                        && htab->tga_desc_fd->elf.plt.plist != NULL)));
       if (tls_opt || !htab->opd_abi)
        {
          if (!add_dynamic_entry (DT_PPC64_OPT, tls_opt ? PPC64_OPT_TLS : 0))
-           return FALSE;
+           return false;
        }
 
       if (relocs)
@@ -10031,34 +10381,35 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
          if (!add_dynamic_entry (DT_RELA, 0)
              || !add_dynamic_entry (DT_RELASZ, 0)
              || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
-           return FALSE;
+           return false;
 
          /* If any dynamic relocs apply to a read-only section,
             then we need a DT_TEXTREL entry.  */
          if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->elf, maybe_set_textrel, info);
+           elf_link_hash_traverse (&htab->elf,
+                                   _bfd_elf_maybe_set_textrel, info);
 
          if ((info->flags & DF_TEXTREL) != 0)
            {
              if (!add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
+               return false;
            }
        }
     }
 #undef add_dynamic_entry
 
-  return TRUE;
+  return true;
 }
 
 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_hash_symbol (struct elf_link_hash_entry *h)
 {
   if (h->plt.plist != NULL
       && !h->def_regular
       && !h->pointer_equality_needed)
-    return FALSE;
+    return false;
 
   return _bfd_elf_hash_symbol (h);
 }
@@ -10164,7 +10515,7 @@ ppc_type_of_stub (asection *input_sec,
    .   add/ldx %r12,%r11,%r12  */
 
 static bfd_byte *
-build_offset (bfd *abfd, bfd_byte *p, bfd_vma off, bfd_boolean load)
+build_offset (bfd *abfd, bfd_byte *p, bfd_vma off, bool load)
 {
   bfd_put_32 (abfd, MFLR_R12, p);
   p += 4;
@@ -10343,8 +10694,8 @@ emit_relocs_for_offset (struct bfd_link_info *info, Elf_Internal_Rela *r,
 }
 
 static bfd_byte *
-build_powerxx_offset (bfd *abfd, bfd_byte *p, bfd_vma off, int odd,
-                     bfd_boolean load)
+build_power10_offset (bfd *abfd, bfd_byte *p, bfd_vma off, int odd,
+                     bool load)
 {
   uint64_t insn;
   if (off - odd + (1ULL << 33) < 1ULL << 34)
@@ -10425,7 +10776,7 @@ build_powerxx_offset (bfd *abfd, bfd_byte *p, bfd_vma off, int odd,
 }
 
 static unsigned int
-size_powerxx_offset (bfd_vma off, int odd)
+size_power10_offset (bfd_vma off, int odd)
 {
   if (off - odd + (1ULL << 33) < 1ULL << 34)
     return odd + 8;
@@ -10436,7 +10787,7 @@ size_powerxx_offset (bfd_vma off, int odd)
 }
 
 static unsigned int
-num_relocs_for_powerxx_offset (bfd_vma off, int odd)
+num_relocs_for_power10_offset (bfd_vma off, int odd)
 {
   if (off - odd + (1ULL << 33) < 1ULL << 34)
     return 1;
@@ -10447,7 +10798,7 @@ num_relocs_for_powerxx_offset (bfd_vma off, int odd)
 }
 
 static Elf_Internal_Rela *
-emit_relocs_for_powerxx_offset (struct bfd_link_info *info,
+emit_relocs_for_power10_offset (struct bfd_link_info *info,
                                Elf_Internal_Rela *r, bfd_vma roff,
                                bfd_vma targ, bfd_vma off, int odd)
 {
@@ -10553,55 +10904,61 @@ eh_advance_size (unsigned int delta)
 static inline unsigned int
 plt_stub_size (struct ppc_link_hash_table *htab,
               struct ppc_stub_hash_entry *stub_entry,
-              bfd_vma off)
+              bfd_vma off,
+              unsigned int odd)
 {
   unsigned size;
 
   if (stub_entry->stub_type >= ppc_stub_plt_call_notoc)
     {
-      if (htab->powerxx_stubs)
-       {
-         bfd_vma start = (stub_entry->stub_offset
-                          + stub_entry->group->stub_sec->output_offset
-                          + stub_entry->group->stub_sec->output_section->vma);
-         if (stub_entry->stub_type > ppc_stub_plt_call_notoc)
-           start += 4;
-         size = 8 + size_powerxx_offset (off, start & 4);
-       }
+      if (htab->params->power10_stubs != 0)
+       size = 8 + size_power10_offset (off, odd);
       else
        size = 8 + size_offset (off - 8);
       if (stub_entry->stub_type > ppc_stub_plt_call_notoc)
        size += 4;
-      return size;
     }
-
-  size = 12;
-  if (ALWAYS_EMIT_R2SAVE
-      || stub_entry->stub_type == ppc_stub_plt_call_r2save)
-    size += 4;
-  if (PPC_HA (off) != 0)
-    size += 4;
-  if (htab->opd_abi)
+  else
     {
-      size += 4;
-      if (htab->params->plt_static_chain)
+      size = 12;
+      if (ALWAYS_EMIT_R2SAVE
+         || stub_entry->stub_type == ppc_stub_plt_call_r2save)
        size += 4;
-      if (htab->params->plt_thread_safe
-         && htab->elf.dynamic_sections_created
-         && stub_entry->h != NULL
-         && stub_entry->h->elf.dynindx != -1)
-       size += 8;
-      if (PPC_HA (off + 8 + 8 * htab->params->plt_static_chain) != PPC_HA (off))
+      if (PPC_HA (off) != 0)
        size += 4;
+      if (htab->opd_abi)
+       {
+         size += 4;
+         if (htab->params->plt_static_chain)
+           size += 4;
+         if (htab->params->plt_thread_safe
+             && htab->elf.dynamic_sections_created
+             && stub_entry->h != NULL
+             && stub_entry->h->elf.dynindx != -1)
+           size += 8;
+         if (PPC_HA (off + 8 + 8 * htab->params->plt_static_chain)
+             != PPC_HA (off))
+           size += 4;
+       }
     }
   if (stub_entry->h != NULL
-      && (stub_entry->h == htab->tls_get_addr_fd
-         || stub_entry->h == htab->tls_get_addr)
+      && is_tls_get_addr (&stub_entry->h->elf, htab)
       && htab->params->tls_get_addr_opt)
     {
-      size += 7 * 4;
-      if (stub_entry->stub_type == ppc_stub_plt_call_r2save)
-       size += 6 * 4;
+      if (!htab->params->no_tls_get_addr_regsave)
+       {
+         size += 30 * 4;
+         if (stub_entry->stub_type == ppc_stub_plt_call_r2save
+             || stub_entry->stub_type == ppc_stub_plt_call_both)
+           size += 4;
+       }
+      else
+       {
+         size += 7 * 4;
+         if (stub_entry->stub_type == ppc_stub_plt_call_r2save
+             || stub_entry->stub_type == ppc_stub_plt_call_both)
+           size += 6 * 4;
+       }
     }
   return size;
 }
@@ -10615,7 +10972,8 @@ plt_stub_size (struct ppc_link_hash_table *htab,
 static inline unsigned int
 plt_stub_pad (struct ppc_link_hash_table *htab,
              struct ppc_stub_hash_entry *stub_entry,
-             bfd_vma plt_off)
+             bfd_vma plt_off,
+             unsigned int odd)
 {
   int stub_align;
   unsigned stub_size;
@@ -10630,7 +10988,7 @@ plt_stub_pad (struct ppc_link_hash_table *htab,
     }
 
   stub_align = 1 << -htab->params->plt_stub_align;
-  stub_size = plt_stub_size (htab, stub_entry, plt_off);
+  stub_size = plt_stub_size (htab, stub_entry, plt_off, odd);
   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));
@@ -10645,20 +11003,20 @@ build_plt_stub (struct ppc_link_hash_table *htab,
                bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
 {
   bfd *obfd = htab->params->stub_bfd;
-  bfd_boolean plt_load_toc = htab->opd_abi;
-  bfd_boolean plt_static_chain = htab->params->plt_static_chain;
-  bfd_boolean plt_thread_safe = (htab->params->plt_thread_safe
-                                && htab->elf.dynamic_sections_created
-                                && stub_entry->h != NULL
-                                && stub_entry->h->elf.dynindx != -1);
-  bfd_boolean use_fake_dep = plt_thread_safe;
+  bool plt_load_toc = htab->opd_abi;
+  bool plt_static_chain = htab->params->plt_static_chain;
+  bool plt_thread_safe = (htab->params->plt_thread_safe
+                         && htab->elf.dynamic_sections_created
+                         && stub_entry->h != NULL
+                         && stub_entry->h->elf.dynindx != -1);
+  bool use_fake_dep = plt_thread_safe;
   bfd_vma cmp_branch_off = 0;
 
   if (!ALWAYS_USE_FAKE_DEP
       && plt_load_toc
       && plt_thread_safe
-      && !((stub_entry->h == htab->tls_get_addr_fd
-           || stub_entry->h == htab->tls_get_addr)
+      && !(stub_entry->h != NULL
+          && is_tls_get_addr (&stub_entry->h->elf, htab)
           && htab->params->tls_get_addr_opt))
     {
       bfd_vma pltoff = stub_entry->plt_ent->plt.offset & ~1;
@@ -10817,70 +11175,149 @@ build_plt_stub (struct ppc_link_hash_table *htab,
 
 /* Build a special .plt call stub for __tls_get_addr.  */
 
-#define LD_R11_0R3     0xe9630000
+#define LD_R0_0R3      0xe8030000
 #define LD_R12_0R3     0xe9830000
 #define MR_R0_R3       0x7c601b78
-#define CMPDI_R11_0    0x2c2b0000
+#define CMPDI_R0_0     0x2c200000
 #define ADD_R3_R12_R13 0x7c6c6a14
 #define BEQLR          0x4d820020
 #define MR_R3_R0       0x7c030378
-#define STD_R11_0R1    0xf9610000
 #define BCTRL          0x4e800421
-#define LD_R11_0R1     0xe9610000
-#define MTLR_R11       0x7d6803a6
 
-static inline bfd_byte *
-build_tls_get_addr_stub (struct ppc_link_hash_table *htab,
+static bfd_byte *
+build_tls_get_addr_head (struct ppc_link_hash_table *htab,
                         struct ppc_stub_hash_entry *stub_entry,
-                        bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
+                        bfd_byte *p)
 {
   bfd *obfd = htab->params->stub_bfd;
-  bfd_byte *loc = p;
 
-  bfd_put_32 (obfd, LD_R11_0R3 + 0, p),                p += 4;
+  bfd_put_32 (obfd, LD_R0_0R3 + 0, p),         p += 4;
   bfd_put_32 (obfd, LD_R12_0R3 + 8, p),                p += 4;
+  bfd_put_32 (obfd, CMPDI_R0_0, p),            p += 4;
   bfd_put_32 (obfd, MR_R0_R3, p),              p += 4;
-  bfd_put_32 (obfd, CMPDI_R11_0, p),           p += 4;
   bfd_put_32 (obfd, ADD_R3_R12_R13, p),                p += 4;
   bfd_put_32 (obfd, BEQLR, p),                 p += 4;
   bfd_put_32 (obfd, MR_R3_R0, p),              p += 4;
-  if (r != NULL)
-    r[0].r_offset += 7 * 4;
-  if (stub_entry->stub_type != ppc_stub_plt_call_r2save)
-    return build_plt_stub (htab, stub_entry, p, offset, r);
 
-  bfd_put_32 (obfd, MFLR_R11, p),              p += 4;
-  bfd_put_32 (obfd, STD_R11_0R1 + STK_LINKER (htab), p), p += 4;
+  if (!htab->params->no_tls_get_addr_regsave)
+    p = tls_get_addr_prologue (obfd, p, htab);
+  else if (stub_entry->stub_type == ppc_stub_plt_call_r2save
+          || stub_entry->stub_type == ppc_stub_plt_call_both)
+    {
+      bfd_put_32 (obfd, MFLR_R0, p);
+      p += 4;
+      bfd_put_32 (obfd, STD_R0_0R1 + STK_LINKER (htab), p);
+      p += 4;
+    }
+  return p;
+}
 
-  if (r != NULL)
-    r[0].r_offset += 2 * 4;
-  p = build_plt_stub (htab, stub_entry, p, offset, r);
-  bfd_put_32 (obfd, BCTRL, p - 4);
+static bfd_byte *
+build_tls_get_addr_tail (struct ppc_link_hash_table *htab,
+                        struct ppc_stub_hash_entry *stub_entry,
+                        bfd_byte *p,
+                        bfd_byte *loc)
+{
+  bfd *obfd = htab->params->stub_bfd;
 
-  bfd_put_32 (obfd, LD_R2_0R1 + STK_TOC (htab), p),    p += 4;
-  bfd_put_32 (obfd, LD_R11_0R1 + STK_LINKER (htab), p),        p += 4;
-  bfd_put_32 (obfd, MTLR_R11, p),              p += 4;
-  bfd_put_32 (obfd, BLR, p),                   p += 4;
+  if (!htab->params->no_tls_get_addr_regsave)
+    {
+      bfd_put_32 (obfd, BCTRL, p - 4);
+
+      if (stub_entry->stub_type == ppc_stub_plt_call_r2save
+         || stub_entry->stub_type == ppc_stub_plt_call_both)
+       {
+         bfd_put_32 (obfd, LD_R2_0R1 + STK_TOC (htab), p);
+         p += 4;
+       }
+      p = tls_get_addr_epilogue (obfd, p, htab);
+    }
+  else if (stub_entry->stub_type == ppc_stub_plt_call_r2save
+          || stub_entry->stub_type == ppc_stub_plt_call_both)
+    {
+      bfd_put_32 (obfd, BCTRL, p - 4);
+
+      bfd_put_32 (obfd, LD_R2_0R1 + STK_TOC (htab), p);
+      p += 4;
+      bfd_put_32 (obfd, LD_R0_0R1 + STK_LINKER (htab), p);
+      p += 4;
+      bfd_put_32 (obfd, MTLR_R0, p);
+      p += 4;
+      bfd_put_32 (obfd, BLR, p);
+      p += 4;
+    }
 
   if (htab->glink_eh_frame != NULL
       && htab->glink_eh_frame->size != 0)
     {
       bfd_byte *base, *eh;
-      unsigned int lr_used, delta;
 
       base = htab->glink_eh_frame->contents + stub_entry->group->eh_base + 17;
       eh = base + stub_entry->group->eh_size;
-      lr_used = stub_entry->stub_offset + (p - 20 - loc);
-      delta = lr_used - stub_entry->group->lr_restore;
-      stub_entry->group->lr_restore = lr_used + 16;
-      eh = eh_advance (htab->elf.dynobj, eh, delta);
-      *eh++ = DW_CFA_offset_extended_sf;
-      *eh++ = 65;
-      *eh++ = -(STK_LINKER (htab) / 8) & 0x7f;
-      *eh++ = DW_CFA_advance_loc + 4;
-      *eh++ = DW_CFA_restore_extended;
-      *eh++ = 65;
-      stub_entry->group->eh_size = eh - base;
+
+      if (!htab->params->no_tls_get_addr_regsave)
+       {
+         unsigned int cfa_updt, delta, i;
+
+         /* After the bctrl, lr has been modified so we need to emit
+            .eh_frame info saying the return address is on the stack.  In
+            fact we must put the EH info at or before the call rather
+            than after it, because the EH info for a call needs to be
+            specified by that point.
+            See libgcc/unwind-dw2.c execute_cfa_program.
+            Any stack pointer update must be described immediately after
+            the instruction making the change, and since the stdu occurs
+            after saving regs we put all the reg saves and the cfa
+            change there.  */
+         cfa_updt = stub_entry->stub_offset + 18 * 4;
+         delta = cfa_updt - stub_entry->group->lr_restore;
+         stub_entry->group->lr_restore
+           = stub_entry->stub_offset + (p - loc) - 4;
+         eh = eh_advance (htab->elf.dynobj, eh, delta);
+         *eh++ = DW_CFA_def_cfa_offset;
+         if (htab->opd_abi)
+           {
+             *eh++ = 128;
+             *eh++ = 1;
+           }
+         else
+           *eh++ = 96;
+         *eh++ = DW_CFA_offset_extended_sf;
+         *eh++ = 65;
+         *eh++ = (-16 / 8) & 0x7f;
+         for (i = 4; i < 12; i++)
+           {
+             *eh++ = DW_CFA_offset + i;
+             *eh++ = (htab->opd_abi ? 13 : 12) - i;
+           }
+         *eh++ = (DW_CFA_advance_loc
+                  + (stub_entry->group->lr_restore - 8 - cfa_updt) / 4);
+         *eh++ = DW_CFA_def_cfa_offset;
+         *eh++ = 0;
+         for (i = 4; i < 12; i++)
+           *eh++ = DW_CFA_restore + i;
+         *eh++ = DW_CFA_advance_loc + 2;
+         *eh++ = DW_CFA_restore_extended;
+         *eh++ = 65;
+         stub_entry->group->eh_size = eh - base;
+       }
+      else if (stub_entry->stub_type == ppc_stub_plt_call_r2save
+              || stub_entry->stub_type == ppc_stub_plt_call_both)
+       {
+         unsigned int lr_used, delta;
+
+         lr_used = stub_entry->stub_offset + (p - 20 - loc);
+         delta = lr_used - stub_entry->group->lr_restore;
+         stub_entry->group->lr_restore = lr_used + 16;
+         eh = eh_advance (htab->elf.dynobj, eh, delta);
+         *eh++ = DW_CFA_offset_extended_sf;
+         *eh++ = 65;
+         *eh++ = -(STK_LINKER (htab) / 8) & 0x7f;
+         *eh++ = DW_CFA_advance_loc + 4;
+         *eh++ = DW_CFA_restore_extended;
+         *eh++ = 65;
+         stub_entry->group->eh_size = eh - base;
+       }
     }
   return p;
 }
@@ -10919,7 +11356,7 @@ get_relocs (asection *sec, int count)
    forms, to the equivalent relocs against the global symbol given by
    STUB_ENTRY->H.  */
 
-static bfd_boolean
+static bool
 use_global_in_relocs (struct ppc_link_hash_table *htab,
                      struct ppc_stub_hash_entry *stub_entry,
                      Elf_Internal_Rela *r, unsigned int num_rel)
@@ -10943,7 +11380,7 @@ use_global_in_relocs (struct ppc_link_hash_table *htab,
       hsize = (htab->stub_globals + 1) * sizeof (*hashes);
       hashes = bfd_zalloc (htab->params->stub_bfd, hsize);
       if (hashes == NULL)
-       return FALSE;
+       return false;
       elf_sym_hashes (htab->params->stub_bfd) = hashes;
       htab->stub_globals = 1;
     }
@@ -10954,9 +11391,7 @@ use_global_in_relocs (struct ppc_link_hash_table *htab,
     h = ppc_follow_link (h->oh);
   BFD_ASSERT (h->elf.root.type == bfd_link_hash_defined
              || h->elf.root.type == bfd_link_hash_defweak);
-  symval = (h->elf.root.u.def.value
-           + h->elf.root.u.def.section->output_offset
-           + h->elf.root.u.def.section->output_section->vma);
+  symval = defined_sym_val (&h->elf);
   while (num_rel-- != 0)
     {
       r->r_info = ELF64_R_INFO (symndx, ELF64_R_TYPE (r->r_info));
@@ -10971,7 +11406,7 @@ use_global_in_relocs (struct ppc_link_hash_table *htab,
        r->r_addend -= symval;
       --r;
     }
-  return TRUE;
+  return true;
 }
 
 static bfd_vma
@@ -11009,13 +11444,14 @@ get_r2off (struct bfd_link_info *info,
   return r2off;
 }
 
-static bfd_boolean
+static bool
 ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 {
   struct ppc_stub_hash_entry *stub_entry;
   struct ppc_branch_hash_entry *br_entry;
   struct bfd_link_info *info;
   struct ppc_link_hash_table *htab;
+  bfd *obfd;
   bfd_byte *loc;
   bfd_byte *p, *relp;
   bfd_vma targ, off;
@@ -11023,14 +11459,34 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
   asection *plt;
   int num_rel;
   int odd;
+  bool is_tga;
 
   /* Massage our args to the form they really have.  */
   stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
   info = in_arg;
 
+  /* Fail if the target section could not be assigned to an output
+     section.  The user should fix his linker script.  */
+  if (stub_entry->target_section != NULL
+      && stub_entry->target_section->output_section == NULL
+      && info->non_contiguous_regions)
+    info->callbacks->einfo (_("%F%P: Could not assign '%pA' to an output section. "
+                             "Retry without --enable-non-contiguous-regions.\n"),
+                           stub_entry->target_section);
+
+  /* Same for the group.  */
+  if (stub_entry->group->stub_sec != NULL
+      && stub_entry->group->stub_sec->output_section == NULL
+      && info->non_contiguous_regions)
+    info->callbacks->einfo (_("%F%P: Could not assign group %pA target %pA to an "
+                             "output section. Retry without "
+                             "--enable-non-contiguous-regions.\n"),
+                           stub_entry->group->stub_sec,
+                           stub_entry->target_section);
+
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   BFD_ASSERT (stub_entry->stub_offset >= stub_entry->group->stub_sec->size);
   loc = stub_entry->group->stub_sec->contents + stub_entry->stub_offset;
@@ -11053,32 +11509,31 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
       off = targ - off;
 
       p = loc;
+      obfd = htab->params->stub_bfd;
       if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
        {
          bfd_vma r2off = get_r2off (info, stub_entry);
 
          if (r2off == (bfd_vma) -1)
            {
-             htab->stub_error = TRUE;
-             return FALSE;
+             htab->stub_error = true;
+             return false;
            }
-         bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), p);
+         bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p);
          p += 4;
          if (PPC_HA (r2off) != 0)
            {
-             bfd_put_32 (htab->params->stub_bfd,
-                         ADDIS_R2_R2 | PPC_HA (r2off), p);
+             bfd_put_32 (obfd, ADDIS_R2_R2 | PPC_HA (r2off), p);
              p += 4;
            }
          if (PPC_LO (r2off) != 0)
            {
-             bfd_put_32 (htab->params->stub_bfd,
-                         ADDI_R2_R2 | PPC_LO (r2off), p);
+             bfd_put_32 (obfd, ADDI_R2_R2 | PPC_LO (r2off), p);
              p += 4;
            }
          off -= p - loc;
        }
-      bfd_put_32 (htab->params->stub_bfd, B_DOT | (off & 0x3fffffc), p);
+      bfd_put_32 (obfd, B_DOT | (off & 0x3fffffc), p);
       p += 4;
 
       if (off + (1 << 25) >= (bfd_vma) (1 << 26))
@@ -11086,21 +11541,21 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
          _bfd_error_handler
            (_("long branch stub `%s' offset overflow"),
             stub_entry->root.string);
-         htab->stub_error = TRUE;
-         return FALSE;
+         htab->stub_error = true;
+         return false;
        }
 
       if (info->emitrelocations)
        {
          r = get_relocs (stub_entry->group->stub_sec, 1);
          if (r == NULL)
-           return FALSE;
+           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 = targ;
          if (stub_entry->h != NULL
              && !use_global_in_relocs (htab, stub_entry, r, 1))
-           return FALSE;
+           return false;
        }
       break;
 
@@ -11108,13 +11563,13 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
     case ppc_stub_plt_branch_r2off:
       br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
                                         stub_entry->root.string + 9,
-                                        FALSE, FALSE);
+                                        false, false);
       if (br_entry == NULL)
        {
          _bfd_error_handler (_("can't find branch stub `%s'"),
                              stub_entry->root.string);
-         htab->stub_error = TRUE;
-         return FALSE;
+         htab->stub_error = true;
+         return false;
        }
 
       targ = (stub_entry->target_value
@@ -11151,7 +11606,7 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
            {
              r = get_relocs (htab->brlt, 1);
              if (r == NULL)
-               return FALSE;
+               return false;
              /* brlt, being SEC_LINKER_CREATED does not go through the
                 normal reloc processing.  Symbols and offsets are not
                 translated from input file to output file form, so
@@ -11178,15 +11633,15 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
            (_("%P: linkage table error against `%pT'\n"),
             stub_entry->root.string);
          bfd_set_error (bfd_error_bad_value);
-         htab->stub_error = TRUE;
-         return FALSE;
+         htab->stub_error = true;
+         return false;
        }
 
       if (info->emitrelocations)
        {
          r = get_relocs (stub_entry->group->stub_sec, 1 + (PPC_HA (off) != 0));
          if (r == NULL)
-           return FALSE;
+           return false;
          r[0].r_offset = loc - stub_entry->group->stub_sec->contents;
          if (bfd_big_endian (info->output_bfd))
            r[0].r_offset += 2;
@@ -11204,19 +11659,17 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
        }
 
       p = loc;
+      obfd = htab->params->stub_bfd;
       if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
        {
          if (PPC_HA (off) != 0)
            {
-             bfd_put_32 (htab->params->stub_bfd,
-                         ADDIS_R12_R2 | PPC_HA (off), p);
+             bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (off), p);
              p += 4;
-             bfd_put_32 (htab->params->stub_bfd,
-                         LD_R12_0R12 | PPC_LO (off), p);
+             bfd_put_32 (obfd, LD_R12_0R12 | PPC_LO (off), p);
            }
          else
-           bfd_put_32 (htab->params->stub_bfd,
-                       LD_R12_0R2 | PPC_LO (off), p);
+           bfd_put_32 (obfd, LD_R12_0R2 | PPC_LO (off), p);
        }
       else
        {
@@ -11224,40 +11677,36 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 
          if (r2off == (bfd_vma) -1)
            {
-             htab->stub_error = TRUE;
-             return FALSE;
+             htab->stub_error = true;
+             return false;
            }
 
-         bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), p);
+         bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p);
          p += 4;
          if (PPC_HA (off) != 0)
            {
-             bfd_put_32 (htab->params->stub_bfd,
-                         ADDIS_R12_R2 | PPC_HA (off), p);
+             bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (off), p);
              p += 4;
-             bfd_put_32 (htab->params->stub_bfd,
-                         LD_R12_0R12 | PPC_LO (off), p);
+             bfd_put_32 (obfd, LD_R12_0R12 | PPC_LO (off), p);
            }
          else
-           bfd_put_32 (htab->params->stub_bfd, LD_R12_0R2 | PPC_LO (off), p);
+           bfd_put_32 (obfd, LD_R12_0R2 | PPC_LO (off), p);
 
          if (PPC_HA (r2off) != 0)
            {
              p += 4;
-             bfd_put_32 (htab->params->stub_bfd,
-                         ADDIS_R2_R2 | PPC_HA (r2off), p);
+             bfd_put_32 (obfd, ADDIS_R2_R2 | PPC_HA (r2off), p);
            }
          if (PPC_LO (r2off) != 0)
            {
              p += 4;
-             bfd_put_32 (htab->params->stub_bfd,
-                         ADDI_R2_R2 | PPC_LO (r2off), p);
+             bfd_put_32 (obfd, ADDI_R2_R2 | PPC_LO (r2off), p);
            }
        }
       p += 4;
-      bfd_put_32 (htab->params->stub_bfd, MTCTR_R12, p);
+      bfd_put_32 (obfd, MTCTR_R12, p);
       p += 4;
-      bfd_put_32 (htab->params->stub_bfd, BCTR, p);
+      bfd_put_32 (obfd, BCTR, p);
       p += 4;
       break;
 
@@ -11271,12 +11720,23 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
       off = (stub_entry->stub_offset
             + stub_entry->group->stub_sec->output_offset
             + stub_entry->group->stub_sec->output_section->vma);
+      obfd = htab->params->stub_bfd;
+      is_tga = ((stub_entry->stub_type == ppc_stub_plt_call_notoc
+                || stub_entry->stub_type == ppc_stub_plt_call_both)
+               && stub_entry->h != NULL
+               && is_tls_get_addr (&stub_entry->h->elf, htab)
+               && htab->params->tls_get_addr_opt);
+      if (is_tga)
+       {
+         p = build_tls_get_addr_head (htab, stub_entry, p);
+         off += p - loc;
+       }
       if (stub_entry->stub_type == ppc_stub_long_branch_both
          || stub_entry->stub_type == ppc_stub_plt_branch_both
          || stub_entry->stub_type == ppc_stub_plt_call_both)
        {
          off += 4;
-         bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), p);
+         bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p);
          p += 4;
        }
       if (stub_entry->stub_type >= ppc_stub_plt_call_notoc)
@@ -11286,9 +11746,7 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
            abort ();
 
          plt = htab->elf.splt;
-         if (!htab->elf.dynamic_sections_created
-             || stub_entry->h == NULL
-             || stub_entry->h->elf.dynindx == -1)
+         if (use_local_plt (info, elf_hash_entry (stub_entry->h)))
            {
              if (stub_entry->symtype == STT_GNU_IFUNC)
                plt = htab->elf.iplt;
@@ -11306,20 +11764,42 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 
       relp = p;
       num_rel = 0;
-      if (htab->powerxx_stubs)
+      if (htab->params->power10_stubs != 0)
        {
-         bfd_boolean load = stub_entry->stub_type >= ppc_stub_plt_call_notoc;
-         p = build_powerxx_offset (htab->params->stub_bfd, p, off, odd, load);
+         bool load = stub_entry->stub_type >= ppc_stub_plt_call_notoc;
+         p = build_power10_offset (obfd, p, off, odd, load);
        }
       else
        {
+         if (htab->glink_eh_frame != NULL
+             && htab->glink_eh_frame->size != 0)
+           {
+             bfd_byte *base, *eh;
+             unsigned int lr_used, delta;
+
+             base = (htab->glink_eh_frame->contents
+                     + stub_entry->group->eh_base + 17);
+             eh = base + stub_entry->group->eh_size;
+             lr_used = stub_entry->stub_offset + (p - loc) + 8;
+             delta = lr_used - stub_entry->group->lr_restore;
+             stub_entry->group->lr_restore = lr_used + 8;
+             eh = eh_advance (htab->elf.dynobj, eh, delta);
+             *eh++ = DW_CFA_register;
+             *eh++ = 65;
+             *eh++ = 12;
+             *eh++ = DW_CFA_advance_loc + 2;
+             *eh++ = DW_CFA_restore_extended;
+             *eh++ = 65;
+             stub_entry->group->eh_size = eh - base;
+           }
+
          /* The notoc stubs calculate their target (either a PLT entry or
             the global entry point of a function) relative to the PC
             returned by the "bcl" two instructions past the start of the
             sequence emitted by build_offset.  The offset is therefore 8
             less than calculated from the start of the sequence.  */
          off -= 8;
-         p = build_offset (htab->params->stub_bfd, p, off,
+         p = build_offset (obfd, p, off,
                            stub_entry->stub_type >= ppc_stub_plt_call_notoc);
        }
 
@@ -11331,22 +11811,24 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
                  + stub_entry->group->stub_sec->output_offset
                  + stub_entry->group->stub_sec->output_section->vma
                  + (p - loc));
-         bfd_put_32 (htab->params->stub_bfd,
-                     B_DOT | ((targ - from) & 0x3fffffc), p);
+         bfd_put_32 (obfd, B_DOT | ((targ - from) & 0x3fffffc), p);
        }
       else
        {
-         bfd_put_32 (htab->params->stub_bfd, MTCTR_R12, p);
+         bfd_put_32 (obfd, MTCTR_R12, p);
          p += 4;
-         bfd_put_32 (htab->params->stub_bfd, BCTR, p);
+         bfd_put_32 (obfd, BCTR, p);
        }
       p += 4;
 
+      if (is_tga)
+       p = build_tls_get_addr_tail (htab, stub_entry, p, loc);
+
       if (info->emitrelocations)
        {
          bfd_vma roff = relp - stub_entry->group->stub_sec->contents;
-         if (htab->powerxx_stubs)
-           num_rel += num_relocs_for_powerxx_offset (off, odd);
+         if (htab->params->power10_stubs != 0)
+           num_rel += num_relocs_for_power10_offset (off, odd);
          else
            {
              num_rel += num_relocs_for_offset (off);
@@ -11354,9 +11836,9 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
            }
          r = get_relocs (stub_entry->group->stub_sec, num_rel);
          if (r == NULL)
-           return FALSE;
-         if (htab->powerxx_stubs)
-           r = emit_relocs_for_powerxx_offset (info, r, roff, targ, off, odd);
+           return false;
+         if (htab->params->power10_stubs != 0)
+           r = emit_relocs_for_power10_offset (info, r, roff, targ, off, odd);
          else
            r = emit_relocs_for_offset (info, r, roff, targ, off);
          if (stub_entry->stub_type == ppc_stub_long_branch_notoc
@@ -11369,36 +11851,9 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
              r->r_addend = targ;
              if (stub_entry->h != NULL
                  && !use_global_in_relocs (htab, stub_entry, r, num_rel))
-               return FALSE;
+               return false;
            }
        }
-
-      if (!htab->powerxx_stubs
-         && htab->glink_eh_frame != NULL
-         && htab->glink_eh_frame->size != 0)
-       {
-         bfd_byte *base, *eh;
-         unsigned int lr_used, delta;
-
-         base = (htab->glink_eh_frame->contents
-                 + stub_entry->group->eh_base + 17);
-         eh = base + stub_entry->group->eh_size;
-         lr_used = stub_entry->stub_offset + 8;
-         if (stub_entry->stub_type == ppc_stub_long_branch_both
-             || stub_entry->stub_type == ppc_stub_plt_branch_both
-             || stub_entry->stub_type == ppc_stub_plt_call_both)
-           lr_used += 4;
-         delta = lr_used - stub_entry->group->lr_restore;
-         stub_entry->group->lr_restore = lr_used + 8;
-         eh = eh_advance (htab->elf.dynobj, eh, delta);
-         *eh++ = DW_CFA_register;
-         *eh++ = 65;
-         *eh++ = 12;
-         *eh++ = DW_CFA_advance_loc + 2;
-         *eh++ = DW_CFA_restore_extended;
-         *eh++ = 65;
-         stub_entry->group->eh_size = eh - base;
-       }
       break;
 
     case ppc_stub_plt_call:
@@ -11423,9 +11878,7 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
        abort ();
 
       plt = htab->elf.splt;
-      if (!htab->elf.dynamic_sections_created
-         || stub_entry->h == NULL
-         || stub_entry->h->elf.dynindx == -1)
+      if (use_local_plt (info, elf_hash_entry (stub_entry->h)))
        {
          if (stub_entry->symtype == STT_GNU_IFUNC)
            plt = htab->elf.iplt;
@@ -11447,8 +11900,8 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
             ? stub_entry->h->elf.root.root.string
             : "<local sym>");
          bfd_set_error (bfd_error_bad_value);
-         htab->stub_error = TRUE;
-         return FALSE;
+         htab->stub_error = true;
+         return false;
        }
 
       r = NULL;
@@ -11461,27 +11914,34 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
                                     && PPC_HA (off + 16) == PPC_HA (off))
                              : 1)));
          if (r == NULL)
-           return FALSE;
+           return false;
          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 = targ;
        }
-      if (stub_entry->h != NULL
-         && (stub_entry->h == htab->tls_get_addr_fd
-             || stub_entry->h == htab->tls_get_addr)
-         && htab->params->tls_get_addr_opt)
-       p = build_tls_get_addr_stub (htab, stub_entry, loc, off, r);
-      else
-       p = build_plt_stub (htab, stub_entry, loc, off, r);
+      p = loc;
+      obfd = htab->params->stub_bfd;
+      is_tga = (stub_entry->h != NULL
+               && is_tls_get_addr (&stub_entry->h->elf, htab)
+               && htab->params->tls_get_addr_opt);
+      if (is_tga)
+       {
+         p = build_tls_get_addr_head (htab, stub_entry, p);
+         if (r != NULL)
+           r[0].r_offset += p - loc;
+       }
+      p = build_plt_stub (htab, stub_entry, p, off, r);
+      if (is_tga)
+       p = build_tls_get_addr_tail (htab, stub_entry, p, loc);
       break;
 
     case ppc_stub_save_res:
-      return TRUE;
+      return true;
 
     default:
       BFD_FAIL ();
-      return FALSE;
+      return false;
     }
 
   stub_entry->group->stub_sec->size = stub_entry->stub_offset + (p - loc);
@@ -11508,13 +11968,13 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
       len2 = strlen (stub_entry->root.string);
       name = bfd_malloc (len1 + len2 + 2);
       if (name == NULL)
-       return FALSE;
+       return false;
       memcpy (name, stub_entry->root.string, 9);
       memcpy (name + 9, stub_str[stub_entry->stub_type - 1], len1);
       memcpy (name + len1 + 9, stub_entry->root.string + 8, len2 - 8 + 1);
-      h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
+      h = elf_link_hash_lookup (&htab->elf, name, true, false, false);
       if (h == NULL)
-       return FALSE;
+       return false;
       if (h->root.type == bfd_link_hash_new)
        {
          h->root.type = bfd_link_hash_defined;
@@ -11529,14 +11989,14 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
        }
     }
 
-  return TRUE;
+  return true;
 }
 
 /* As above, but don't actually build the stub.  Just bump offset so
    we know stub section sizes, and select plt_branch stubs where
    long_branch stubs won't do.  */
 
-static bfd_boolean
+static bool
 ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 {
   struct ppc_stub_hash_entry *stub_entry;
@@ -11552,7 +12012,26 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
+
+  /* Fail if the target section could not be assigned to an output
+     section.  The user should fix his linker script.  */
+  if (stub_entry->target_section != NULL
+      && stub_entry->target_section->output_section == NULL
+      && info->non_contiguous_regions)
+    info->callbacks->einfo (_("%F%P: Could not assign %pA to an output section. "
+                             "Retry without --enable-non-contiguous-regions.\n"),
+                           stub_entry->target_section);
+
+  /* Same for the group.  */
+  if (stub_entry->group->stub_sec != NULL
+      && stub_entry->group->stub_sec->output_section == NULL
+      && info->non_contiguous_regions)
+    info->callbacks->einfo (_("%F%P: Could not assign group %pA target %pA to an "
+                             "output section. Retry without "
+                             "--enable-non-contiguous-regions.\n"),
+                           stub_entry->group->stub_sec,
+                           stub_entry->target_section);
 
   /* Make a note of the offset within the stubs for this entry.  */
   stub_entry->stub_offset = stub_entry->group->stub_sec->size;
@@ -11566,7 +12045,7 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
         functions.  Instead, emit copies of the functions.  */
       stub_entry->group->needs_save_res = 1;
       stub_entry->stub_type = ppc_stub_save_res;
-      return TRUE;
+      return true;
     }
 
   switch (stub_entry->stub_type)
@@ -11594,8 +12073,8 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
          r2off = get_r2off (info, stub_entry);
          if (r2off == (bfd_vma) -1)
            {
-             htab->stub_error = TRUE;
-             return FALSE;
+             htab->stub_error = true;
+             return false;
            }
          size = 8;
          if (PPC_HA (r2off) != 0)
@@ -11617,13 +12096,13 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 
          br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
                                             stub_entry->root.string + 9,
-                                            TRUE, FALSE);
+                                            true, false);
          if (br_entry == NULL)
            {
              _bfd_error_handler (_("can't build branch stub `%s'"),
                                  stub_entry->root.string);
-             htab->stub_error = TRUE;
-             return FALSE;
+             htab->stub_error = true;
+             return false;
            }
 
          if (br_entry->iter != htab->stub_iteration)
@@ -11703,16 +12182,16 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
       if (info->emitrelocations)
        {
          unsigned int num_rel;
-         if (htab->powerxx_stubs)
-           num_rel = num_relocs_for_powerxx_offset (off, odd);
+         if (htab->params->power10_stubs != 0)
+           num_rel = num_relocs_for_power10_offset (off, odd);
          else
            num_rel = num_relocs_for_offset (off - 8);
          stub_entry->group->stub_sec->reloc_count += num_rel;
          stub_entry->group->stub_sec->flags |= SEC_RELOC;
        }
 
-      if (htab->powerxx_stubs)
-       extra = size_powerxx_offset (off, odd);
+      if (htab->params->power10_stubs != 0)
+       extra = size_power10_offset (off, odd);
       else
        extra = size_offset (off - 8);
       /* Include branch insn plus those in the offset sequence.  */
@@ -11722,7 +12201,7 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
         calculated.  */
       off -= extra;
 
-      if (!htab->powerxx_stubs)
+      if (htab->params->power10_stubs == 0)
        {
          /* After the bcl, lr has been modified so we need to emit
             .eh_frame info saying the return address is in r12.  */
@@ -11750,19 +12229,25 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 
     case ppc_stub_plt_call_notoc:
     case ppc_stub_plt_call_both:
-      off = (stub_entry->stub_offset
-            + stub_entry->group->stub_sec->output_offset
-            + stub_entry->group->stub_sec->output_section->vma);
+      lr_used = 0;
+      if (stub_entry->h != NULL
+         && is_tls_get_addr (&stub_entry->h->elf, htab)
+         && htab->params->tls_get_addr_opt)
+       {
+         lr_used += 7 * 4;
+         if (!htab->params->no_tls_get_addr_regsave)
+           lr_used += 11 * 4;
+         else if (stub_entry->stub_type == ppc_stub_plt_call_both)
+           lr_used += 2 * 4;
+       }
       if (stub_entry->stub_type == ppc_stub_plt_call_both)
-       off += 4;
+       lr_used += 4;
       targ = stub_entry->plt_ent->plt.offset & ~1;
       if (targ >= (bfd_vma) -2)
        abort ();
 
       plt = htab->elf.splt;
-      if (!htab->elf.dynamic_sections_created
-         || stub_entry->h == NULL
-         || stub_entry->h->elf.dynindx == -1)
+      if (use_local_plt (info, elf_hash_entry (stub_entry->h)))
        {
          if (stub_entry->symtype == STT_GNU_IFUNC)
            plt = htab->elf.iplt;
@@ -11770,38 +12255,41 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
            plt = htab->pltlocal;
        }
       targ += plt->output_offset + plt->output_section->vma;
+      off = (stub_entry->stub_offset
+            + stub_entry->group->stub_sec->output_offset
+            + stub_entry->group->stub_sec->output_section->vma
+            + lr_used);
       odd = off & 4;
       off = targ - off;
 
       if (htab->params->plt_stub_align != 0)
        {
-         unsigned pad = plt_stub_pad (htab, stub_entry, off);
+         unsigned pad = plt_stub_pad (htab, stub_entry, off, odd);
 
          stub_entry->group->stub_sec->size += pad;
          stub_entry->stub_offset = stub_entry->group->stub_sec->size;
          off -= pad;
+         odd ^= pad & 4;
        }
 
       if (info->emitrelocations)
        {
          unsigned int num_rel;
-         if (htab->powerxx_stubs)
-           num_rel = num_relocs_for_powerxx_offset (off, odd);
+         if (htab->params->power10_stubs != 0)
+           num_rel = num_relocs_for_power10_offset (off, odd);
          else
            num_rel = num_relocs_for_offset (off - 8);
          stub_entry->group->stub_sec->reloc_count += num_rel;
          stub_entry->group->stub_sec->flags |= SEC_RELOC;
        }
 
-      size = plt_stub_size (htab, stub_entry, off);
+      size = plt_stub_size (htab, stub_entry, off, odd);
 
-      if (!htab->powerxx_stubs)
+      if (htab->params->power10_stubs == 0)
        {
          /* After the bcl, lr has been modified so we need to emit
             .eh_frame info saying the return address is in r12.  */
-         lr_used = stub_entry->stub_offset + 8;
-         if (stub_entry->stub_type == ppc_stub_plt_call_both)
-           lr_used += 4;
+         lr_used += stub_entry->stub_offset + 8;
          /* The eh_frame info will consist of a DW_CFA_advance_loc or
             variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
             DW_CFA_restore_extended 65.  */
@@ -11809,6 +12297,30 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
          stub_entry->group->eh_size += eh_advance_size (delta) + 6;
          stub_entry->group->lr_restore = lr_used + 8;
        }
+      if ((stub_entry->stub_type == ppc_stub_plt_call_notoc
+          || stub_entry->stub_type == ppc_stub_plt_call_both)
+         && stub_entry->h != NULL
+         && is_tls_get_addr (&stub_entry->h->elf, htab)
+         && htab->params->tls_get_addr_opt)
+       {
+         if (!htab->params->no_tls_get_addr_regsave)
+           {
+             unsigned int cfa_updt = stub_entry->stub_offset + 18 * 4;
+             delta = cfa_updt - stub_entry->group->lr_restore;
+             stub_entry->group->eh_size += eh_advance_size (delta);
+             stub_entry->group->eh_size += htab->opd_abi ? 36 : 35;
+             stub_entry->group->lr_restore
+               = stub_entry->stub_offset + size - 4;
+           }
+         else if (stub_entry->stub_type == ppc_stub_plt_call_both)
+           {
+             lr_used = stub_entry->stub_offset + size - 20;
+             delta = lr_used - stub_entry->group->lr_restore;
+             stub_entry->group->eh_size += eh_advance_size (delta) + 6;
+             stub_entry->group->lr_restore
+               = stub_entry->stub_offset + size - 4;
+           }
+       }
       break;
 
     case ppc_stub_plt_call:
@@ -11817,9 +12329,7 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
       if (targ >= (bfd_vma) -2)
        abort ();
       plt = htab->elf.splt;
-      if (!htab->elf.dynamic_sections_created
-         || stub_entry->h == NULL
-         || stub_entry->h->elf.dynindx == -1)
+      if (use_local_plt (info, elf_hash_entry (stub_entry->h)))
        {
          if (stub_entry->symtype == STT_GNU_IFUNC)
            plt = htab->elf.iplt;
@@ -11834,7 +12344,7 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 
       if (htab->params->plt_stub_align != 0)
        {
-         unsigned pad = plt_stub_pad (htab, stub_entry, off);
+         unsigned pad = plt_stub_pad (htab, stub_entry, off, 0);
 
          stub_entry->group->stub_sec->size += pad;
          stub_entry->stub_offset = stub_entry->group->stub_sec->size;
@@ -11851,38 +12361,41 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
          stub_entry->group->stub_sec->flags |= SEC_RELOC;
        }
 
-      size = plt_stub_size (htab, stub_entry, off);
+      size = plt_stub_size (htab, stub_entry, off, 0);
 
       if (stub_entry->h != NULL
-         && (stub_entry->h == htab->tls_get_addr_fd
-             || stub_entry->h == htab->tls_get_addr)
+         && is_tls_get_addr (&stub_entry->h->elf, htab)
          && htab->params->tls_get_addr_opt
          && stub_entry->stub_type == ppc_stub_plt_call_r2save)
        {
-         /* After the bctrl, lr has been modified so we need to
-            emit .eh_frame info saying the return address is
-            on the stack.  In fact we put the EH info specifying
-            that the return address is on the stack *at* the
-            call rather than after it, because the EH info for a
-            call needs to be specified by that point.
-            See libgcc/unwind-dw2.c execute_cfa_program.  */
-         lr_used = stub_entry->stub_offset + size - 20;
-         /* The eh_frame info will consist of a DW_CFA_advance_loc
-            or variant, DW_CFA_offset_externed_sf, 65, -stackoff,
-            DW_CFA_advance_loc+4, DW_CFA_restore_extended, 65.  */
-         delta = lr_used - stub_entry->group->lr_restore;
-         stub_entry->group->eh_size += eh_advance_size (delta) + 6;
-         stub_entry->group->lr_restore = size - 4;
+         if (!htab->params->no_tls_get_addr_regsave)
+           {
+             /* Adjustments to r1 need to be described.  */
+             unsigned int cfa_updt = stub_entry->stub_offset + 18 * 4;
+             delta = cfa_updt - stub_entry->group->lr_restore;
+             stub_entry->group->eh_size += eh_advance_size (delta);
+             stub_entry->group->eh_size += htab->opd_abi ? 36 : 35;
+           }
+         else
+           {
+             lr_used = stub_entry->stub_offset + size - 20;
+             /* The eh_frame info will consist of a DW_CFA_advance_loc
+                or variant, DW_CFA_offset_externed_sf, 65, -stackoff,
+                DW_CFA_advance_loc+4, DW_CFA_restore_extended, 65.  */
+             delta = lr_used - stub_entry->group->lr_restore;
+             stub_entry->group->eh_size += eh_advance_size (delta) + 6;
+           }
+         stub_entry->group->lr_restore = stub_entry->stub_offset + size - 4;
        }
       break;
 
     default:
       BFD_FAIL ();
-      return FALSE;
+      return false;
     }
 
   stub_entry->group->stub_sec->size += size;
-  return TRUE;
+  return true;
 }
 
 /* Set up various things so that we can make a list of input sections
@@ -11893,7 +12406,7 @@ int
 ppc64_elf_setup_section_lists (struct bfd_link_info *info)
 {
   unsigned int id;
-  bfd_size_type amt;
+  size_t amt;
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
 
   if (htab == NULL)
@@ -11928,19 +12441,19 @@ ppc64_elf_start_multitoc_partition (struct bfd_link_info *info)
    and linker generated GOT section.  Group input bfds such that the toc
    within a group is less than 64k in size.  */
 
-bfd_boolean
+bool
 ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
 {
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
   bfd_vma addr, off, limit;
 
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   if (!htab->second_toc_pass)
     {
       /* Keep track of the first .toc or .got section for this input bfd.  */
-      bfd_boolean new_bfd = htab->toc_bfd != isec->owner;
+      bool new_bfd = htab->toc_bfd != isec->owner;
 
       if (new_bfd)
        {
@@ -11974,17 +12487,17 @@ ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
       if (new_bfd
          && elf_gp (isec->owner) != 0
          && elf_gp (isec->owner) != off)
-       return FALSE;
+       return false;
 
       elf_gp (isec->owner) = off;
-      return TRUE;
+      return true;
     }
 
   /* During the second pass toc_first_sec points to the start of
      a toc group, and toc_curr is used to track the old elf_gp.
      We use toc_bfd to ensure we only look at each bfd once.  */
   if (htab->toc_bfd == isec->owner)
-    return TRUE;
+    return true;
   htab->toc_bfd = isec->owner;
 
   if (htab->toc_first_sec == NULL
@@ -11998,55 +12511,55 @@ ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
   off = addr - elf_gp (info->output_bfd) + TOC_BASE_OFF;
   elf_gp (isec->owner) = off;
 
-  return TRUE;
+  return true;
 }
 
 /* Called via elf_link_hash_traverse to merge GOT entries for global
    symbol H.  */
 
-static bfd_boolean
+static bool
 merge_global_got (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
 {
   if (h->root.type == bfd_link_hash_indirect)
-    return TRUE;
+    return true;
 
   merge_got_entries (&h->got.glist);
 
-  return TRUE;
+  return true;
 }
 
 /* Called via elf_link_hash_traverse to allocate GOT entries for global
    symbol H.  */
 
-static bfd_boolean
+static bool
 reallocate_got (struct elf_link_hash_entry *h, void *inf)
 {
   struct got_entry *gent;
 
   if (h->root.type == bfd_link_hash_indirect)
-    return TRUE;
+    return true;
 
   for (gent = h->got.glist; gent != NULL; gent = gent->next)
     if (!gent->is_indirect)
       allocate_got (h, (struct bfd_link_info *) inf, gent);
-  return TRUE;
+  return true;
 }
 
 /* Called on the first multitoc pass after the last call to
    ppc64_elf_next_toc_section.  This function removes duplicate GOT
    entries.  */
 
-bfd_boolean
+bool
 ppc64_elf_layout_multitoc (struct bfd_link_info *info)
 {
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
   struct bfd *ibfd, *ibfd2;
-  bfd_boolean done_something;
+  bool done_something;
 
   htab->multi_toc_needed = htab->toc_curr != elf_gp (info->output_bfd);
 
   if (!htab->do_multi_toc)
-    return FALSE;
+    return false;
 
   /* Merge global sym got entries within a toc group.  */
   elf_link_hash_traverse (&htab->elf, merge_global_got, info);
@@ -12073,7 +12586,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
                  && ent2->got.offset != (bfd_vma) -1
                  && elf_gp (ibfd2) == elf_gp (ibfd))
                {
-                 ent2->is_indirect = TRUE;
+                 ent2->is_indirect = true;
                  ent2->got.ent = ent;
                }
            }
@@ -12152,7 +12665,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
                  htab->got_reli_size += rel_size;
                }
              else if (bfd_link_pic (info)
-                      && !((ent->tls_type & TLS_TPREL) != 0
+                      && !(ent->tls_type != 0
                            && bfd_link_executable (info)))
                {
                  asection *srel = ppc64_elf_tdata (ibfd)->relgot;
@@ -12178,7 +12691,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
          asection *s = ppc64_elf_tdata (ibfd)->got;
          ent->got.offset = s->size;
          s->size += 16;
-         if (bfd_link_pic (info))
+         if (bfd_link_dll (info))
            {
              asection *srel = ppc64_elf_tdata (ibfd)->relgot;
              srel->size += sizeof (Elf64_External_Rela);
@@ -12211,7 +12724,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
      on input sections.  */
   htab->toc_bfd = NULL;
   htab->toc_first_sec = NULL;
-  htab->second_toc_pass = TRUE;
+  htab->second_toc_pass = true;
   return done_something;
 }
 
@@ -12303,7 +12816,7 @@ toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec)
 
          /* Calls to dynamic lib functions go through a plt call stub
             that uses r2.  */
-         eh = (struct ppc_link_hash_entry *) h;
+         eh = ppc_elf_hash_entry (h);
          if (eh != NULL
              && (eh->elf.plt.plist != NULL
                  || (eh->oh != NULL
@@ -12352,7 +12865,7 @@ toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec)
                }
 
              dest = opd_entry_value (sym_sec, sym_value,
-                                     &sym_sec, NULL, FALSE);
+                                     &sym_sec, NULL, false);
              if (dest == (bfd_vma) -1)
                continue;
            }
@@ -12414,9 +12927,8 @@ toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec)
            }
        }
 
-      if (local_syms != NULL
-         && (elf_symtab_hdr (isec->owner).contents
-             != (unsigned char *) local_syms))
+      if (elf_symtab_hdr (isec->owner).contents
+         != (unsigned char *) local_syms)
        free (local_syms);
       if (elf_section_data (isec)->relocs != relstart)
        free (relstart);
@@ -12452,13 +12964,13 @@ toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec)
    Build lists of input sections to determine groupings between which
    we may insert linker stubs.  */
 
-bfd_boolean
+bool
 ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec)
 {
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
 
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   if ((isec->output_section->flags & SEC_CODE) != 0
       && isec->output_section->id < htab->sec_info_arr_size)
@@ -12482,7 +12994,7 @@ ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec)
            || isec->call_check_done))
        {
          if (toc_adjusting_stub_needed (info, isec) < 0)
-           return FALSE;
+           return false;
        }
       /* Make all sections use the TOC assigned for this object file.
         This will be wrong for pasted sections;  We fix that in
@@ -12492,13 +13004,13 @@ ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec)
     }
 
   htab->sec_info[isec->id].toc_off = htab->toc_curr;
-  return TRUE;
+  return true;
 }
 
 /* Check that all .init and .fini sections use the same toc, if they
    have toc relocs.  */
 
-static bfd_boolean
+static bool
 check_pasted_section (struct bfd_link_info *info, const char *name)
 {
   asection *o = bfd_get_section_by_name (info->output_bfd, name);
@@ -12515,7 +13027,7 @@ check_pasted_section (struct bfd_link_info *info, const char *name)
            if (toc_off == 0)
              toc_off = htab->sec_info[i->id].toc_off;
            else if (toc_off != htab->sec_info[i->id].toc_off)
-             return FALSE;
+             return false;
          }
 
       if (toc_off == 0)
@@ -12531,10 +13043,10 @@ check_pasted_section (struct bfd_link_info *info, const char *name)
        for (i = o->map_head.s; i != NULL; i = i->map_head.s)
          htab->sec_info[i->id].toc_off = toc_off;
     }
-  return TRUE;
+  return true;
 }
 
-bfd_boolean
+bool
 ppc64_elf_check_init_fini (struct bfd_link_info *info)
 {
   return (check_pasted_section (info, ".init")
@@ -12548,20 +13060,20 @@ ppc64_elf_check_init_fini (struct bfd_link_info *info)
    _init and _fini functions into multiple parts.  Putting a stub in
    the middle of a function is not a good idea.  */
 
-static bfd_boolean
+static bool
 group_sections (struct bfd_link_info *info,
                bfd_size_type stub_group_size,
-               bfd_boolean stubs_always_before_branch)
+               bool stubs_always_before_branch)
 {
   struct ppc_link_hash_table *htab;
   asection *osec;
-  bfd_boolean suppress_size_errors;
+  bool suppress_size_errors;
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
-  suppress_size_errors = FALSE;
+  suppress_size_errors = false;
   if (stub_group_size == 1)
     {
       /* Default values.  */
@@ -12569,7 +13081,7 @@ group_sections (struct bfd_link_info *info,
        stub_group_size = 0x1e00000;
       else
        stub_group_size = 0x1c00000;
-      suppress_size_errors = TRUE;
+      suppress_size_errors = true;
     }
 
   for (osec = info->output_bfd->sections; osec != NULL; osec = osec->next)
@@ -12585,7 +13097,7 @@ group_sections (struct bfd_link_info *info,
          asection *curr;
          asection *prev;
          bfd_size_type total;
-         bfd_boolean big_sec;
+         bool big_sec;
          bfd_vma curr_toc;
          struct map_stub *group;
          bfd_size_type group_size;
@@ -12623,7 +13135,7 @@ group_sections (struct bfd_link_info *info,
             than 2097152 bytes, or nearly 75000 plt call stubs.  */
          group = bfd_alloc (curr->owner, sizeof (*group));
          if (group == NULL)
-           return FALSE;
+           return false;
          group->link_sec = curr;
          group->stub_sec = NULL;
          group->needs_save_res = 0;
@@ -12664,7 +13176,7 @@ group_sections (struct bfd_link_info *info,
          tail = prev;
        }
     }
-  return TRUE;
+  return true;
 }
 
 static const unsigned char glink_eh_frame_cie[] =
@@ -12708,15 +13220,18 @@ maybe_strip_output (struct bfd_link_info *info, asection *isec)
    PC-relative calls to a target that is unreachable with a "bl"
    instruction.  */
 
-bfd_boolean
+bool
 ppc64_elf_size_stubs (struct bfd_link_info *info)
 {
   bfd_size_type stub_group_size;
-  bfd_boolean stubs_always_before_branch;
+  bool stubs_always_before_branch;
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
 
   if (htab == NULL)
-    return FALSE;
+    return false;
+
+  if (htab->params->power10_stubs == -1 && !htab->has_power10_relocs)
+    htab->params->power10_stubs = 0;
 
   if (htab->params->plt_thread_safe == -1 && !bfd_link_executable (info))
     htab->params->plt_thread_safe = 1;
@@ -12756,7 +13271,7 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
        {
          struct elf_link_hash_entry *h;
          h = elf_link_hash_lookup (&htab->elf, thread_starter[i],
-                                   FALSE, FALSE, TRUE);
+                                   false, false, true);
          htab->params->plt_thread_safe = h != NULL && h->ref_regular;
          if (htab->params->plt_thread_safe)
            break;
@@ -12769,7 +13284,41 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
     stub_group_size = htab->params->group_size;
 
   if (!group_sections (info, stub_group_size, stubs_always_before_branch))
-    return FALSE;
+    return false;
+
+  htab->tga_group = NULL;
+  if (!htab->params->no_tls_get_addr_regsave
+      && htab->tga_desc_fd != NULL
+      && (htab->tga_desc_fd->elf.root.type == bfd_link_hash_undefined
+         || htab->tga_desc_fd->elf.root.type == bfd_link_hash_undefweak)
+      && htab->tls_get_addr_fd != NULL
+      && is_static_defined (&htab->tls_get_addr_fd->elf))
+    {
+      asection *sym_sec, *code_sec, *stub_sec;
+      bfd_vma sym_value;
+      struct _opd_sec_data *opd;
+
+      sym_sec = htab->tls_get_addr_fd->elf.root.u.def.section;
+      sym_value = defined_sym_val (&htab->tls_get_addr_fd->elf);
+      code_sec = sym_sec;
+      opd = get_opd_info (sym_sec);
+      if (opd != NULL)
+       opd_entry_value (sym_sec, sym_value, &code_sec, NULL, false);
+      htab->tga_group = htab->sec_info[code_sec->id].u.group;
+      stub_sec = (*htab->params->add_stub_section) (".tga_desc.stub",
+                                                   htab->tga_group->link_sec);
+      if (stub_sec == NULL)
+       return false;
+      htab->tga_group->stub_sec = stub_sec;
+
+      htab->tga_desc_fd->elf.root.type = bfd_link_hash_defined;
+      htab->tga_desc_fd->elf.root.u.def.section = stub_sec;
+      htab->tga_desc_fd->elf.root.u.def.value = 0;
+      htab->tga_desc_fd->elf.type = STT_FUNC;
+      htab->tga_desc_fd->elf.def_regular = 1;
+      htab->tga_desc_fd->elf.non_elf = 0;
+      _bfd_elf_link_hash_hide_symbol (info, &htab->tga_desc_fd->elf, true);
+    }
 
 #define STUB_SHRINK_ITER 20
   /* Loop until no stubs added.  After iteration 20 of this loop we may
@@ -12844,7 +13393,7 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
                  bfd_vma sym_value, code_value;
                  bfd_vma destination;
                  unsigned long local_off;
-                 bfd_boolean ok_dest;
+                 bool ok_dest;
                  struct ppc_link_hash_entry *hash;
                  struct ppc_link_hash_entry *fdh;
                  struct elf_link_hash_entry *h;
@@ -12876,9 +13425,9 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
                  if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
                                  r_indx, input_bfd))
                    goto error_ret_free_internal;
-                 hash = (struct ppc_link_hash_entry *) h;
+                 hash = ppc_elf_hash_entry (h);
 
-                 ok_dest = FALSE;
+                 ok_dest = false;
                  fdh = NULL;
                  sym_value = 0;
                  if (hash == NULL)
@@ -12886,14 +13435,14 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
                      sym_value = sym->st_value;
                      if (sym_sec != NULL
                          && sym_sec->output_section != NULL)
-                       ok_dest = TRUE;
+                       ok_dest = true;
                    }
                  else if (hash->elf.root.type == bfd_link_hash_defined
                           || hash->elf.root.type == bfd_link_hash_defweak)
                    {
                      sym_value = hash->elf.root.u.def.value;
                      if (sym_sec->output_section != NULL)
-                       ok_dest = TRUE;
+                       ok_dest = true;
                    }
                  else if (hash->elf.root.type == bfd_link_hash_undefweak
                           || hash->elf.root.type == bfd_link_hash_undefined)
@@ -12911,7 +13460,7 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
                              sym_sec = fdh->elf.root.u.def.section;
                              sym_value = fdh->elf.root.u.def.value;
                              if (sym_sec->output_section != NULL)
-                               ok_dest = TRUE;
+                               ok_dest = true;
                            }
                          else
                            fdh = NULL;
@@ -12952,7 +13501,7 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
                          sym_value += adjust;
                        }
                      dest = opd_entry_value (sym_sec, sym_value,
-                                             &code_sec, &code_value, FALSE);
+                                             &code_sec, &code_value, false);
                      if (dest != (bfd_vma) -1)
                        {
                          destination = dest;
@@ -12995,10 +13544,10 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
                         fact a call needing a TOC adjustment.  */
                      if ((code_sec != NULL
                           && code_sec->output_section != NULL
-                          && (htab->sec_info[code_sec->id].toc_off
-                              != htab->sec_info[section->id].toc_off)
                           && (code_sec->has_toc_reloc
-                              || code_sec->makes_toc_func_call))
+                              || code_sec->makes_toc_func_call)
+                          && (htab->sec_info[code_sec->id].toc_off
+                              != htab->sec_info[section->id].toc_off))
                          || (((hash ? hash->elf.other : sym->st_other)
                               & STO_PPC64_LOCAL_MASK)
                              == 1 << STO_PPC64_LOCAL_BIT))
@@ -13012,8 +13561,7 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
                  if (stub_type != ppc_stub_plt_call
                      && stub_type != ppc_stub_plt_call_notoc
                      && hash != NULL
-                     && (hash == htab->tls_get_addr
-                         || hash == htab->tls_get_addr_fd)
+                     && is_tls_get_addr (&hash->elf, htab)
                      && section->has_tls_reloc
                      && irela != internal_relocs)
                    {
@@ -13023,7 +13571,8 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
                      if (!get_tls_mask (&tls_mask, NULL, NULL, &local_syms,
                                         irela - 1, input_bfd))
                        goto error_ret_free_internal;
-                     if ((*tls_mask & TLS_TLS) != 0)
+                     if ((*tls_mask & TLS_TLS) != 0
+                         && (*tls_mask & (TLS_GD | TLS_LD)) == 0)
                        continue;
                    }
 
@@ -13055,10 +13604,11 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
                    goto error_ret_free_internal;
 
                  stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
-                                                    stub_name, FALSE, FALSE);
+                                                    stub_name, false, false);
                  if (stub_entry != NULL)
                    {
                      enum ppc_stub_type old_type;
+
                      /* A stub has already been created, but it may
                         not be the required type.  We shouldn't be
                         transitioning from plt_call to long_branch
@@ -13066,6 +13616,39 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
                         upgrading from plt_call to plt_call_r2save or
                         from long_branch to long_branch_r2off.  */
                      free (stub_name);
+                     if (htab->params->power10_stubs == -1)
+                       {
+                         /* For --power10-stubs=auto, don't merge _notoc
+                            and other varieties of stubs.  (The _both
+                            variety won't be created.)  */
+                         bool notoc = r_type == R_PPC64_REL24_NOTOC;
+                         struct ppc_stub_hash_entry *alt_stub
+                           = select_alt_stub (stub_entry, notoc);
+
+                         if (alt_stub == NULL)
+                           {
+                             alt_stub = (struct ppc_stub_hash_entry *)
+                               stub_hash_newfunc (NULL,
+                                                  &htab->stub_hash_table,
+                                                  stub_entry->root.string);
+                             if (alt_stub == NULL)
+                               {
+                                 /* xgettext:c-format */
+                                 _bfd_error_handler
+                                   (_("%pB: cannot create stub entry %s"),
+                                    section->owner, stub_entry->root.string);
+                                 goto error_ret_free_internal;
+                               }
+                             *alt_stub = *stub_entry;
+                             stub_entry->root.next = &alt_stub->root;
+                             if (notoc)
+                               /* Sort notoc stubs first, for no good
+                                  reason.  */
+                               alt_stub = stub_entry;
+                             alt_stub->stub_type = stub_type;
+                           }
+                         stub_entry = alt_stub;
+                       }
                      old_type = stub_entry->stub_type;
                      switch (old_type)
                        {
@@ -13135,11 +13718,10 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
                      if (elf_section_data (section)->relocs == NULL)
                        free (internal_relocs);
                    error_ret_free_local:
-                     if (local_syms != NULL
-                         && (symtab_hdr->contents
-                             != (unsigned char *) local_syms))
+                     if (symtab_hdr->contents
+                         != (unsigned char *) local_syms)
                        free (local_syms);
-                     return FALSE;
+                     return false;
                    }
 
                  stub_entry->stub_type = stub_type;
@@ -13200,6 +13782,14 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
              stub_sec->flags &= ~SEC_RELOC;
            }
        }
+      if (htab->tga_group != NULL)
+       {
+         /* See emit_tga_desc and emit_tga_desc_eh_frame.  */
+         htab->tga_group->eh_size
+           = 1 + 2 + (htab->opd_abi != 0) + 3 + 8 * 2 + 3 + 8 + 3;
+         htab->tga_group->lr_restore = 23 * 4;
+         htab->tga_group->stub_sec->size = 24 * 4;
+       }
 
       if (htab->stub_iteration <= STUB_SHRINK_ITER
          || htab->brlt->rawsize < htab->brlt->size)
@@ -13263,7 +13853,9 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
              || (htab->stub_iteration > STUB_SHRINK_ITER
                  && htab->brlt->rawsize > htab->brlt->size))
          && (htab->glink_eh_frame == NULL
-             || htab->glink_eh_frame->rawsize == htab->glink_eh_frame->size))
+             || htab->glink_eh_frame->rawsize == htab->glink_eh_frame->size)
+         && (htab->tga_group == NULL
+             || htab->stub_iteration > 1))
        break;
 
       /* Ask the linker to do its stuff.  */
@@ -13284,7 +13876,7 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
         indexed in .eh_frame_hdr.  */
       p = bfd_zalloc (htab->glink_eh_frame->owner, htab->glink_eh_frame->size);
       if (p == NULL)
-       return FALSE;
+       return false;
       htab->glink_eh_frame->contents = p;
       last_fde = p;
       align = 4;
@@ -13339,11 +13931,11 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
          /* Augmentation.  */
          p += 1;
 
-         *p++ = DW_CFA_advance_loc + 1;
+         *p++ = DW_CFA_advance_loc + (htab->has_plt_localentry0 ? 3 : 2);
          *p++ = DW_CFA_register;
          *p++ = 65;
          *p++ = htab->opd_abi ? 12 : 0;
-         *p++ = DW_CFA_advance_loc + (htab->opd_abi ? 5 : 7);
+         *p++ = DW_CFA_advance_loc + (htab->opd_abi ? 4 : 2);
          *p++ = DW_CFA_restore_extended;
          *p++ = 65;
          p += ((24 + align - 1) & -align) - 24;
@@ -13359,10 +13951,12 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
     }
 
   maybe_strip_output (info, htab->brlt);
+  if (htab->relbrlt != NULL)
+    maybe_strip_output (info, htab->relbrlt);
   if (htab->glink_eh_frame != NULL)
     maybe_strip_output (info, htab->glink_eh_frame);
 
-  return TRUE;
+  return true;
 }
 
 /* Called after we have determined section placement.  If sections
@@ -13379,24 +13973,23 @@ ppc64_elf_set_toc (struct bfd_link_info *info, bfd *obfd)
       struct elf_link_hash_entry *h;
       struct elf_link_hash_table *htab = elf_hash_table (info);
 
-      if (is_elf_hash_table (htab)
+      if (is_elf_hash_table (&htab->root)
          && htab->hgot != NULL)
        h = htab->hgot;
       else
        {
-         h = elf_link_hash_lookup (htab, ".TOC.", FALSE, FALSE, TRUE);
-         if (is_elf_hash_table (htab))
+         h = (struct elf_link_hash_entry *)
+           bfd_link_hash_lookup (&htab->root, ".TOC.", false, false, true);
+         if (is_elf_hash_table (&htab->root))
            htab->hgot = h;
        }
       if (h != NULL
          && h->root.type == bfd_link_hash_defined
          && !h->root.linker_def
-         && (!is_elf_hash_table (htab)
+         && (!is_elf_hash_table (&htab->root)
              || 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);
+         TOCstart = defined_sym_val (h) - TOC_BASE_OFF;
          _bfd_set_gp_value (obfd, TOCstart);
          return TOCstart;
        }
@@ -13470,7 +14063,7 @@ ppc64_elf_set_toc (struct bfd_link_info *info, bfd *obfd)
          struct bfd_link_hash_entry *bh = NULL;
          _bfd_generic_link_add_one_symbol (info, obfd, ".TOC.", BSF_GLOBAL,
                                            s, TOC_BASE_OFF - adjust,
-                                           NULL, FALSE, FALSE, &bh);
+                                           NULL, false, false, &bh);
        }
     }
   return TOCstart;
@@ -13479,7 +14072,7 @@ ppc64_elf_set_toc (struct bfd_link_info *info, bfd *obfd)
 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
    write out any global entry stubs, and PLT relocations.  */
 
-static bfd_boolean
+static bool
 build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
 {
   struct bfd_link_info *info;
@@ -13488,12 +14081,12 @@ build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
   asection *s;
 
   if (h->root.type == bfd_link_hash_indirect)
-    return TRUE;
+    return true;
 
   info = inf;
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   for (ent = h->plt.plist; ent != NULL; ent = ent->next)
     if (ent->plt.offset != (bfd_vma) -1)
@@ -13504,8 +14097,7 @@ build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
        asection *plt, *relplt;
        bfd_byte *loc;
 
-       if (!htab->elf.dynamic_sections_created
-           || h->dynindx == -1)
+       if (use_local_plt (info, h))
          {
            if (!(h->def_regular
                  && (h->root.type == bfd_link_hash_defined
@@ -13515,7 +14107,7 @@ build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
              {
                plt = htab->elf.iplt;
                relplt = htab->elf.irelplt;
-               htab->local_ifunc_resolver = 1;
+               htab->elf.ifunc_resolvers = true;
                if (htab->opd_abi)
                  rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
                else
@@ -13535,10 +14127,7 @@ build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
                else
                  relplt = NULL;
              }
-           rela.r_addend = (h->root.u.def.value
-                            + h->root.u.def.section->output_offset
-                            + h->root.u.def.section->output_section->vma
-                            + ent->addend);
+           rela.r_addend = defined_sym_val (h) + ent->addend;
 
            if (relplt == NULL)
              {
@@ -13572,20 +14161,20 @@ build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
                   + ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE (htab))
                      / PLT_ENTRY_SIZE (htab) * sizeof (Elf64_External_Rela)));
            if (h->type == STT_GNU_IFUNC && is_static_defined (h))
-             htab->maybe_local_ifunc_resolver = 1;
+             htab->elf.ifunc_resolvers = true;
            bfd_elf64_swap_reloca_out (info->output_bfd, &rela, loc);
          }
       }
 
   if (!h->pointer_equality_needed)
-    return TRUE;
+    return true;
 
   if (h->def_regular)
-    return TRUE;
+    return true;
 
   s = htab->global_entry;
   if (s == NULL || s->size == 0)
-    return TRUE;
+    return true;
 
   for (ent = h->plt.plist; ent != NULL; ent = ent->next)
     if (ent->plt.offset != (bfd_vma) -1
@@ -13597,8 +14186,7 @@ build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
 
        p = s->contents + h->root.u.def.value;
        plt = htab->elf.splt;
-       if (!htab->elf.dynamic_sections_created
-           || h->dynindx == -1)
+       if (use_local_plt (info, h))
          {
            if (h->type == STT_GNU_IFUNC)
              plt = htab->elf.iplt;
@@ -13614,7 +14202,7 @@ build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
              (_("%P: linkage table error against `%pT'\n"),
               h->root.root.string);
            bfd_set_error (bfd_error_bad_value);
-           htab->stub_error = TRUE;
+           htab->stub_error = true;
          }
 
        htab->stub_count[ppc_stub_global_entry - 1] += 1;
@@ -13624,12 +14212,12 @@ build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
            char *name = bfd_malloc (sizeof "12345678.global_entry." + len);
 
            if (name == NULL)
-             return FALSE;
+             return false;
 
            sprintf (name, "%08x.global_entry.%s", s->id, h->root.root.string);
-           h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
+           h = elf_link_hash_lookup (&htab->elf, name, true, false, false);
            if (h == NULL)
-             return FALSE;
+             return false;
            if (h->root.type == bfd_link_hash_new)
              {
                h->root.type = bfd_link_hash_defined;
@@ -13656,12 +14244,12 @@ build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
        bfd_put_32 (s->owner, BCTR, p);
        break;
       }
-  return TRUE;
+  return true;
 }
 
 /* Write PLT relocs for locals.  */
 
-static bfd_boolean
+static bool
 write_plt_relocs_for_local_syms (struct bfd_link_info *info)
 {
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
@@ -13701,21 +14289,18 @@ write_plt_relocs_for_local_syms (struct bfd_link_info *info)
              if (!get_sym_h (NULL, &sym, &sym_sec, NULL, &local_syms,
                              lplt - local_plt, ibfd))
                {
-                 if (local_syms != NULL
-                     && symtab_hdr->contents != (unsigned char *) local_syms)
+                 if (symtab_hdr->contents != (unsigned char *) local_syms)
                    free (local_syms);
-                 return FALSE;
+                 return false;
                }
 
              val = sym->st_value + ent->addend;
-             if (ELF_ST_TYPE (sym->st_info) != STT_GNU_IFUNC)
-               val += PPC64_LOCAL_ENTRY_OFFSET (sym->st_other);
              if (sym_sec != NULL && sym_sec->output_section != NULL)
                val += sym_sec->output_offset + sym_sec->output_section->vma;
 
              if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
                {
-                 htab->local_ifunc_resolver = 1;
+                 htab->elf.ifunc_resolvers = true;
                  plt = htab->elf.iplt;
                  relplt = htab->elf.irelplt;
                }
@@ -13771,14 +14356,82 @@ write_plt_relocs_for_local_syms (struct bfd_link_info *info)
            symtab_hdr->contents = (unsigned char *) local_syms;
        }
     }
-  return TRUE;
+  return true;
+}
+
+/* Emit the static wrapper function preserving registers around a
+   __tls_get_addr_opt call.  */
+
+static bool
+emit_tga_desc (struct ppc_link_hash_table *htab)
+{
+  asection *stub_sec = htab->tga_group->stub_sec;
+  unsigned int cfa_updt = 11 * 4;
+  bfd_byte *p;
+  bfd_vma to, from, delta;
+
+  BFD_ASSERT (htab->tga_desc_fd->elf.root.type == bfd_link_hash_defined
+             && htab->tga_desc_fd->elf.root.u.def.section == stub_sec
+             && htab->tga_desc_fd->elf.root.u.def.value == 0);
+  to = defined_sym_val (&htab->tls_get_addr_fd->elf);
+  from = defined_sym_val (&htab->tga_desc_fd->elf) + cfa_updt;
+  delta = to - from;
+  if (delta + (1 << 25) >= 1 << 26)
+    {
+      _bfd_error_handler (_("__tls_get_addr call offset overflow"));
+      htab->stub_error = true;
+      return false;
+    }
+
+  p = stub_sec->contents;
+  p = tls_get_addr_prologue (htab->elf.dynobj, p, htab);
+  bfd_put_32 (stub_sec->owner, B_DOT | 1 | (delta & 0x3fffffc), p);
+  p += 4;
+  p = tls_get_addr_epilogue (htab->elf.dynobj, p, htab);
+  return stub_sec->size == (bfd_size_type) (p - stub_sec->contents);
+}
+
+/* Emit eh_frame describing the static wrapper function.  */
+
+static bfd_byte *
+emit_tga_desc_eh_frame (struct ppc_link_hash_table *htab, bfd_byte *p)
+{
+  unsigned int cfa_updt = 11 * 4;
+  unsigned int i;
+
+  *p++ = DW_CFA_advance_loc + cfa_updt / 4;
+  *p++ = DW_CFA_def_cfa_offset;
+  if (htab->opd_abi)
+    {
+      *p++ = 128;
+      *p++ = 1;
+    }
+  else
+    *p++ = 96;
+  *p++ = DW_CFA_offset_extended_sf;
+  *p++ = 65;
+  *p++ = (-16 / 8) & 0x7f;
+  for (i = 4; i < 12; i++)
+    {
+      *p++ = DW_CFA_offset + i;
+      *p++ = (htab->opd_abi ? 13 : 12) - i;
+    }
+  *p++ = DW_CFA_advance_loc + 10;
+  *p++ = DW_CFA_def_cfa_offset;
+  *p++ = 0;
+  for (i = 4; i < 12; i++)
+    *p++ = DW_CFA_restore + i;
+  *p++ = DW_CFA_advance_loc + 2;
+  *p++ = DW_CFA_restore_extended;
+  *p++ = 65;
+  return p;
 }
 
 /* Build all the stubs associated with the current output file.
    The stubs are kept in a hash table attached to the main linker
    hash table.  This function is called via gldelf64ppc_finish.  */
 
-bfd_boolean
+bool
 ppc64_elf_build_stubs (struct bfd_link_info *info,
                       char **stats)
 {
@@ -13789,7 +14442,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
   int stub_sec_count = 0;
 
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   /* Allocate memory to hold the linker stubs.  */
   for (group = htab->group; group != NULL; group = group->next)
@@ -13802,7 +14455,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
          stub_sec->contents = bfd_zalloc (htab->params->stub_bfd,
                                           stub_sec->size);
          if (stub_sec->contents == NULL)
-           return FALSE;
+           return false;
          stub_sec->size = 0;
        }
     }
@@ -13817,9 +14470,9 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
        {
          struct elf_link_hash_entry *h;
          h = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
-                                   TRUE, FALSE, FALSE);
+                                   true, false, false);
          if (h == NULL)
-           return FALSE;
+           return false;
          if (h->root.type == bfd_link_hash_new)
            {
              h->root.type = bfd_link_hash_defined;
@@ -13840,7 +14493,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
        {
          Elf_Internal_Rela *r = get_relocs (htab->glink, 1);
          if (r == NULL)
-           return FALSE;
+           return false;
          r->r_offset = (htab->glink->output_offset
                         + htab->glink->output_section->vma);
          r->r_info = ELF64_R_INFO (0, R_PPC64_REL64);
@@ -13875,23 +14528,60 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
        }
       else
        {
+         unsigned int insn;
+
+         /* 0:
+            .  .quad plt0-1f           # plt0 entry relative to 1:
+            #
+            # We get here with r12 initially @ a glink branch
+            # Load the address of _dl_runtime_resolve from plt0 and
+            # jump to it, with r0 set to the index of the PLT entry
+            # to be resolved and r11 the link map.
+            __glink_PLTresolve:
+            .  std %r2,24(%r1)         # optional
+            .  mflr %r0
+            .  bcl 20,31,1f
+            1:
+            .  mflr %r11
+            .  mtlr %r0
+            .  ld %r0,(0b-1b)(%r11)
+            .  sub %r12,%r12,%r11
+            .  add %r11,%r0,%r11
+            .  addi %r0,%r12,1b-2f
+            .  ld %r12,0(%r11)
+            .  srdi %r0,%r0,2
+            .  mtctr %r12
+            .  ld %r11,8(%r11)
+            .  bctr
+            2:
+            .  b __glink_PLTresolve
+            .  ...
+            .  b __glink_PLTresolve  */
+
+         if (htab->has_plt_localentry0)
+           {
+             bfd_put_32 (htab->glink->owner, STD_R2_0R1 + 24, p);
+             p += 4;
+           }
          bfd_put_32 (htab->glink->owner, MFLR_R0, p);
          p += 4;
          bfd_put_32 (htab->glink->owner, BCL_20_31, p);
          p += 4;
          bfd_put_32 (htab->glink->owner, MFLR_R11, p);
          p += 4;
-         bfd_put_32 (htab->glink->owner, STD_R2_0R1 + 24, p);
-         p += 4;
-         bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
-         p += 4;
          bfd_put_32 (htab->glink->owner, MTLR_R0, p);
          p += 4;
+         if (htab->has_plt_localentry0)
+           insn = LD_R0_0R11 | (-20 & 0xfffc);
+         else
+           insn = LD_R0_0R11 | (-16 & 0xfffc);
+         bfd_put_32 (htab->glink->owner, insn, p);
+         p += 4;
          bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p);
          p += 4;
-         bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
+         bfd_put_32 (htab->glink->owner, ADD_R11_R0_R11, p);
          p += 4;
-         bfd_put_32 (htab->glink->owner, ADDI_R0_R12 | (-48 & 0xffff), p);
+         bfd_put_32 (htab->glink->owner, ADDI_R0_R12 | (-44 & 0xffff), p);
          p += 4;
          bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
          p += 4;
@@ -13933,25 +14623,43 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
        }
     }
 
+  if (htab->tga_group != NULL)
+    {
+      htab->tga_group->lr_restore = 23 * 4;
+      htab->tga_group->stub_sec->size = 24 * 4;
+      if (!emit_tga_desc (htab))
+       return false;
+      if (htab->glink_eh_frame != NULL
+         && htab->glink_eh_frame->size != 0)
+       {
+         size_t align = 4;
+
+         p = htab->glink_eh_frame->contents;
+         p += (sizeof (glink_eh_frame_cie) + align - 1) & -align;
+         p += 17;
+         htab->tga_group->eh_size = emit_tga_desc_eh_frame (htab, p) - p;
+       }
+    }
+
   /* Build .glink global entry stubs, and PLT relocs for globals.  */
   elf_link_hash_traverse (&htab->elf, build_global_entry_stubs_and_plt, info);
 
   if (!write_plt_relocs_for_local_syms (info))
-    return FALSE;
+    return false;
 
   if (htab->brlt != NULL && htab->brlt->size != 0)
     {
       htab->brlt->contents = bfd_zalloc (htab->brlt->owner,
                                         htab->brlt->size);
       if (htab->brlt->contents == NULL)
-       return FALSE;
+       return false;
     }
   if (htab->relbrlt != NULL && htab->relbrlt->size != 0)
     {
       htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner,
                                            htab->relbrlt->size);
       if (htab->relbrlt->contents == NULL)
-       return FALSE;
+       return false;
     }
 
   /* Build the stubs as directed by the stub hash table.  */
@@ -13984,7 +14692,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
 
            for (i = 0; i < ARRAY_SIZE (save_res_funcs); i++)
              if (!sfpr_define (info, &save_res_funcs[i], stub_sec))
-               return FALSE;
+               return false;
          }
       }
 
@@ -14011,7 +14719,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
                _bfd_error_handler
                  (_("%s offset too large for .eh_frame sdata4 encoding"),
                   group->stub_sec->name);
-               return FALSE;
+               return false;
              }
            bfd_put_32 (htab->elf.dynobj, val, p + 8);
            p += (group->eh_size + 17 + 3) & -4;
@@ -14030,7 +14738,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
              _bfd_error_handler
                (_("%s offset too large for .eh_frame sdata4 encoding"),
                 htab->glink->name);
-             return FALSE;
+             return false;
            }
          bfd_put_32 (htab->elf.dynobj, val, p + 8);
          p += (24 + align - 1) & -align;
@@ -14049,53 +14757,57 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
 
   if (group != NULL)
     {
-      htab->stub_error = TRUE;
+      htab->stub_error = true;
       _bfd_error_handler (_("stubs don't match calculated size"));
     }
 
   if (htab->stub_error)
-    return FALSE;
+    return false;
 
   if (stats != NULL)
     {
-      size_t len;
-      *stats = bfd_malloc (500);
-      if (*stats == NULL)
-       return FALSE;
-
-      len = sprintf (*stats,
-                    ngettext ("linker stubs in %u group\n",
-                              "linker stubs in %u groups\n",
-                              stub_sec_count),
-                    stub_sec_count);
-      sprintf (*stats + len, _("  branch         %lu\n"
-                              "  branch toc adj %lu\n"
-                              "  branch notoc   %lu\n"
-                              "  branch both    %lu\n"
-                              "  long branch    %lu\n"
-                              "  long toc adj   %lu\n"
-                              "  long notoc     %lu\n"
-                              "  long both      %lu\n"
-                              "  plt call       %lu\n"
-                              "  plt call save  %lu\n"
-                              "  plt call notoc %lu\n"
-                              "  plt call both  %lu\n"
-                              "  global entry   %lu"),
-              htab->stub_count[ppc_stub_long_branch - 1],
-              htab->stub_count[ppc_stub_long_branch_r2off - 1],
-              htab->stub_count[ppc_stub_long_branch_notoc - 1],
-              htab->stub_count[ppc_stub_long_branch_both - 1],
-              htab->stub_count[ppc_stub_plt_branch - 1],
-              htab->stub_count[ppc_stub_plt_branch_r2off - 1],
-              htab->stub_count[ppc_stub_plt_branch_notoc - 1],
-              htab->stub_count[ppc_stub_plt_branch_both - 1],
-              htab->stub_count[ppc_stub_plt_call - 1],
-              htab->stub_count[ppc_stub_plt_call_r2save - 1],
-              htab->stub_count[ppc_stub_plt_call_notoc - 1],
-              htab->stub_count[ppc_stub_plt_call_both - 1],
-              htab->stub_count[ppc_stub_global_entry - 1]);
+      char *groupmsg;
+      if (asprintf (&groupmsg,
+                   ngettext ("linker stubs in %u group\n",
+                             "linker stubs in %u groups\n",
+                             stub_sec_count),
+                   stub_sec_count) < 0)
+       *stats = NULL;
+      else
+       {
+         if (asprintf (stats, _("%s"
+                                "  branch         %lu\n"
+                                "  branch toc adj %lu\n"
+                                "  branch notoc   %lu\n"
+                                "  branch both    %lu\n"
+                                "  long branch    %lu\n"
+                                "  long toc adj   %lu\n"
+                                "  long notoc     %lu\n"
+                                "  long both      %lu\n"
+                                "  plt call       %lu\n"
+                                "  plt call save  %lu\n"
+                                "  plt call notoc %lu\n"
+                                "  plt call both  %lu\n"
+                                "  global entry   %lu"),
+                       groupmsg,
+                       htab->stub_count[ppc_stub_long_branch - 1],
+                       htab->stub_count[ppc_stub_long_branch_r2off - 1],
+                       htab->stub_count[ppc_stub_long_branch_notoc - 1],
+                       htab->stub_count[ppc_stub_long_branch_both - 1],
+                       htab->stub_count[ppc_stub_plt_branch - 1],
+                       htab->stub_count[ppc_stub_plt_branch_r2off - 1],
+                       htab->stub_count[ppc_stub_plt_branch_notoc - 1],
+                       htab->stub_count[ppc_stub_plt_branch_both - 1],
+                       htab->stub_count[ppc_stub_plt_call - 1],
+                       htab->stub_count[ppc_stub_plt_call_r2save - 1],
+                       htab->stub_count[ppc_stub_plt_call_notoc - 1],
+                       htab->stub_count[ppc_stub_plt_call_both - 1],
+                       htab->stub_count[ppc_stub_global_entry - 1]) < 0)
+           *stats = NULL;
+         free (groupmsg);
+       }
     }
-  return TRUE;
+  return true;
 }
 
 /* What to do when ld finds relocations against symbols defined in
@@ -14116,6 +14828,66 @@ ppc64_elf_action_discarded (asection *sec)
   return _bfd_elf_default_action_discarded (sec);
 }
 
+/* These are the dynamic relocations supported by glibc.  */
+
+static bool
+ppc64_glibc_dynamic_reloc (enum elf_ppc64_reloc_type r_type)
+{
+  switch (r_type)
+    {
+    case R_PPC64_RELATIVE:
+    case R_PPC64_NONE:
+    case R_PPC64_ADDR64:
+    case R_PPC64_GLOB_DAT:
+    case R_PPC64_IRELATIVE:
+    case R_PPC64_JMP_IREL:
+    case R_PPC64_JMP_SLOT:
+    case R_PPC64_DTPMOD64:
+    case R_PPC64_DTPREL64:
+    case R_PPC64_TPREL64:
+    case R_PPC64_TPREL16_LO_DS:
+    case R_PPC64_TPREL16_DS:
+    case R_PPC64_TPREL16:
+    case R_PPC64_TPREL16_LO:
+    case R_PPC64_TPREL16_HI:
+    case R_PPC64_TPREL16_HIGH:
+    case R_PPC64_TPREL16_HA:
+    case R_PPC64_TPREL16_HIGHA:
+    case R_PPC64_TPREL16_HIGHER:
+    case R_PPC64_TPREL16_HIGHEST:
+    case R_PPC64_TPREL16_HIGHERA:
+    case R_PPC64_TPREL16_HIGHESTA:
+    case R_PPC64_ADDR16_LO_DS:
+    case R_PPC64_ADDR16_LO:
+    case R_PPC64_ADDR16_HI:
+    case R_PPC64_ADDR16_HIGH:
+    case R_PPC64_ADDR16_HA:
+    case R_PPC64_ADDR16_HIGHA:
+    case R_PPC64_REL30:
+    case R_PPC64_COPY:
+    case R_PPC64_UADDR64:
+    case R_PPC64_UADDR32:
+    case R_PPC64_ADDR32:
+    case R_PPC64_ADDR24:
+    case R_PPC64_ADDR16:
+    case R_PPC64_UADDR16:
+    case R_PPC64_ADDR16_DS:
+    case R_PPC64_ADDR16_HIGHER:
+    case R_PPC64_ADDR16_HIGHEST:
+    case R_PPC64_ADDR16_HIGHERA:
+    case R_PPC64_ADDR16_HIGHESTA:
+    case R_PPC64_ADDR14:
+    case R_PPC64_ADDR14_BRTAKEN:
+    case R_PPC64_ADDR14_BRNTAKEN:
+    case R_PPC64_REL32:
+    case R_PPC64_REL64:
+      return true;
+
+    default:
+      return false;
+    }
+}
+
 /* The RELOCATE_SECTION function is called by the ELF backend linker
    to handle the relocations for a section.
 
@@ -14145,7 +14917,7 @@ ppc64_elf_action_discarded (asection *sec)
    section, which means that the addend must be adjusted
    accordingly.  */
 
-static bfd_boolean
+static int
 ppc64_elf_relocate_section (bfd *output_bfd,
                            struct bfd_link_info *info,
                            bfd *input_bfd,
@@ -14165,10 +14937,11 @@ ppc64_elf_relocate_section (bfd *output_bfd,
   bfd_byte *loc;
   struct got_entry **local_got_ents;
   bfd_vma TOCstart;
-  bfd_boolean ret = TRUE;
-  bfd_boolean is_opd;
+  bool ret = true;
+  bool is_opd;
   /* Assume 'at' branch hints.  */
-  bfd_boolean is_isa_v2 = TRUE;
+  bool is_isa_v2 = true;
+  bool warned_dynamic = false;
   bfd_vma d_offset = (bfd_big_endian (input_bfd) ? 2 : 0);
 
   /* Initialize howto table if needed.  */
@@ -14177,16 +14950,16 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   /* Don't relocate stub sections.  */
   if (input_section->owner == htab->params->stub_bfd)
-    return TRUE;
+    return true;
 
   if (!is_ppc64_elf (input_bfd))
     {
       bfd_set_error (bfd_error_wrong_format);
-      return FALSE;
+      return false;
     }
 
   local_got_ents = elf_local_got_ents (input_bfd);
@@ -14213,8 +14986,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
       unsigned char tls_mask, tls_gd, tls_type;
       unsigned char sym_type;
       bfd_vma relocation;
-      bfd_boolean unresolved_reloc, save_unresolved_reloc;
-      bfd_boolean warned;
+      bool unresolved_reloc, save_unresolved_reloc;
+      bool warned;
       enum { DEST_NORMAL, DEST_OPD, DEST_STUB } reloc_dest;
       unsigned int insn;
       unsigned int mask;
@@ -14246,8 +15019,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
       sec = NULL;
       h_elf = NULL;
       sym_name = NULL;
-      unresolved_reloc = FALSE;
-      warned = FALSE;
+      unresolved_reloc = false;
+      warned = false;
 
       if (r_symndx < symtab_hdr->sh_info)
        {
@@ -14282,7 +15055,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        }
       else
        {
-         bfd_boolean ignored;
+         bool ignored;
 
          RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
                                   r_symndx, symtab_hdr, sym_hashes,
@@ -14318,7 +15091,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                  }
            }
        }
-      h = (struct ppc_link_hash_entry *) h_elf;
+      h = ppc_elf_hash_entry (h_elf);
 
       if (sec != NULL && discarded_section (sec))
        {
@@ -14347,7 +15120,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        {
          relocation = TOCstart + htab->sec_info[input_section->id].toc_off;
          sec = bfd_abs_section_ptr;
-         unresolved_reloc = FALSE;
+         unresolved_reloc = false;
        }
 
       /* TLS optimizations.  Replace instruction sequences and relocs
@@ -14377,7 +15150,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 
          if (!get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
                             &local_syms, rel, input_bfd))
-           return FALSE;
+           return false;
 
          if (toc_tls)
            tls_mask = *toc_tls;
@@ -14430,7 +15203,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 
        case R_PPC64_LO_DS_OPT:
          insn = bfd_get_32 (input_bfd, contents + rel->r_offset - d_offset);
-         if ((insn & (0x3f << 26)) != 58u << 26)
+         if ((insn & (0x3fu << 26)) != 58u << 26)
            abort ();
          insn += (14u << 26) - (58u << 26);
          bfd_put_32 (input_bfd, insn, contents + rel->r_offset - d_offset);
@@ -14450,7 +15223,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
            retval = get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
                                   &local_syms, rel, input_bfd);
            if (retval == 0)
-             return FALSE;
+             return false;
 
            if (toc_tls)
              {
@@ -14522,7 +15295,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
            }
          break;
 
-       case R_PPC64_GOT_TPREL34:
+       case R_PPC64_GOT_TPREL_PCREL34:
          if ((tls_mask & TLS_TLS) != 0
              && (tls_mask & TLS_TPREL) == 0)
            {
@@ -14572,7 +15345,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                  /* For pcrel IE to LE we already have the full
                     offset and thus don't need an addi here.  A nop
                     or mr will do.  */
-                 if ((insn & (0x3f << 26)) == 14 << 26)
+                 if ((insn & (0x3fu << 26)) == 14 << 26)
                    {
                      /* Extract regs from addi rt,ra,si.  */
                      unsigned int rt = (insn >> 21) & 0x1f;
@@ -14636,11 +15409,13 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                 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
+             if (input_section->nomark_tls_get_addr
                  && rel + 1 < relend
                  && branch_reloc_hash_match (input_bfd, rel + 1,
+                                             htab->tls_get_addr_fd,
+                                             htab->tga_desc_fd,
                                              htab->tls_get_addr,
-                                             htab->tls_get_addr_fd))
+                                             htab->tga_desc))
                offset = rel[1].r_offset;
              /* We read the low GOT_TLS (or TOC16) insn because we
                 need to keep the destination reg.  It may be
@@ -14652,7 +15427,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                {
                  /* IE */
                  insn1 &= (0x1f << 21) | (0x1f << 16);
-                 insn1 |= 58 << 26;    /* ld */
+                 insn1 |= 58u << 26;   /* ld */
                  insn2 = 0x7c636a14;   /* add 3,3,13 */
                  if (offset != (bfd_vma) -1)
                    rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
@@ -14713,7 +15488,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
            }
          break;
 
-       case R_PPC64_GOT_TLSGD34:
+       case R_PPC64_GOT_TLSGD_PCREL34:
          if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
            {
              pinsn = bfd_get_32 (input_bfd, contents + rel->r_offset);
@@ -14723,7 +15498,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                {
                  /* IE, pla -> pld  */
                  pinsn += (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
-                 r_type = R_PPC64_GOT_TPREL34;
+                 r_type = R_PPC64_GOT_TPREL_PCREL34;
                }
              else
                {
@@ -14739,7 +15514,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
            }
          break;
 
-       case R_PPC64_GOT_TLSLD34:
+       case R_PPC64_GOT_TLSLD_PCREL34:
          if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
            {
              pinsn = bfd_get_32 (input_bfd, contents + rel->r_offset);
@@ -15058,20 +15833,21 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                  || stub_entry->stub_type == ppc_stub_long_branch_r2off
                  || stub_entry->stub_type == ppc_stub_long_branch_both))
            {
-             bfd_boolean can_plt_call = FALSE;
+             bool can_plt_call = false;
 
              if (stub_entry->stub_type == ppc_stub_plt_call
                  && !htab->opd_abi
                  && htab->params->plt_localentry0 != 0
+                 && h != NULL
                  && is_elfv2_localentry0 (&h->elf))
                {
                  /* The function doesn't use or change r2.  */
-                 can_plt_call = TRUE;
+                 can_plt_call = true;
                }
              else if (r_type == R_PPC64_REL24_NOTOC)
                {
                  /* NOTOC calls don't need to restore r2.  */
-                 can_plt_call = TRUE;
+                 can_plt_call = true;
                }
 
              /* All of these stubs may modify r2, so there must be a
@@ -15090,14 +15866,13 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                      nop = bfd_get_32 (input_bfd,
                                        contents + rel->r_offset + 4);
                      if (nop == LD_R2_0R1 + STK_TOC (htab))
-                       can_plt_call = TRUE;
+                       can_plt_call = true;
                      else if (nop == NOP
                               || nop == CROR_151515
                               || nop == CROR_313131)
                        {
                          if (h != NULL
-                             && (h == htab->tls_get_addr_fd
-                                 || h == htab->tls_get_addr)
+                             && is_tls_get_addr (&h->elf, htab)
                              && htab->params->tls_get_addr_opt)
                            {
                              /* Special stub used, leave nop alone.  */
@@ -15106,7 +15881,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                            bfd_put_32 (input_bfd,
                                        LD_R2_0R1 + STK_TOC (htab),
                                        contents + rel->r_offset + 4);
-                         can_plt_call = TRUE;
+                         can_plt_call = true;
                        }
                    }
                }
@@ -15118,13 +15893,13 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                  if (*name == '.')
                    ++name;
 
-                 if (strncmp (name, "__libc_start_main", 17) == 0
+                 if (startswith (name, "__libc_start_main")
                      && (name[17] == 0 || name[17] == '@'))
                    {
                      /* Allow crt1 branch to go via a toc adjusting
                         stub.  Other calls that never return could do
                         the same, if we could detect such.  */
-                     can_plt_call = TRUE;
+                     can_plt_call = true;
                    }
                }
 
@@ -15146,10 +15921,10 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                                     - sec->output_section->vma
                                     - sec->output_offset);
 
-                     opd_entry_value (sec, off, &code_sec, NULL, FALSE);
+                     opd_entry_value (sec, off, &code_sec, NULL, false);
                    }
                  if (code_sec == input_section)
-                   can_plt_call = TRUE;
+                   can_plt_call = true;
                }
 
              if (!can_plt_call)
@@ -15169,13 +15944,13 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                       input_bfd, input_section, rel->r_offset, sym_name);
 
                  bfd_set_error (bfd_error_bad_value);
-                 ret = FALSE;
+                 ret = false;
                }
 
              if (can_plt_call
                  && stub_entry->stub_type >= ppc_stub_plt_call
                  && stub_entry->stub_type <= ppc_stub_plt_call_both)
-               unresolved_reloc = FALSE;
+               unresolved_reloc = false;
            }
 
          if ((stub_entry == NULL
@@ -15187,7 +15962,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
              bfd_vma off = (relocation + addend
                             - sec->output_section->vma
                             - sec->output_offset);
-             bfd_vma dest = opd_entry_value (sec, off, NULL, NULL, FALSE);
+             bfd_vma dest = opd_entry_value (sec, off, NULL, NULL, false);
              if (dest != (bfd_vma) -1)
                {
                  relocation = dest;
@@ -15257,23 +16032,25 @@ ppc64_elf_relocate_section (bfd *output_bfd,
              addend = 0;
              reloc_dest = DEST_STUB;
 
-             if (((stub_entry->stub_type == ppc_stub_plt_call
-                   && ALWAYS_EMIT_R2SAVE)
-                  || stub_entry->stub_type == ppc_stub_plt_call_r2save
-                  || stub_entry->stub_type == ppc_stub_plt_call_both)
-                 && !(h != NULL
-                      && (h == htab->tls_get_addr_fd
-                          || h == htab->tls_get_addr)
-                      && htab->params->tls_get_addr_opt)
-                 && rel + 1 < relend
-                 && rel[1].r_offset == rel->r_offset + 4
-                 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOCSAVE)
-               relocation += 4;
-             else if ((stub_entry->stub_type == ppc_stub_long_branch_both
-                       || stub_entry->stub_type == ppc_stub_plt_branch_both
-                       || stub_entry->stub_type == ppc_stub_plt_call_both)
-                      && r_type == R_PPC64_REL24_NOTOC)
-               relocation += 4;
+             if ((((stub_entry->stub_type == ppc_stub_plt_call
+                    && ALWAYS_EMIT_R2SAVE)
+                   || stub_entry->stub_type == ppc_stub_plt_call_r2save
+                   || stub_entry->stub_type == ppc_stub_plt_call_both)
+                  && rel + 1 < relend
+                  && rel[1].r_offset == rel->r_offset + 4
+                  && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOCSAVE)
+                 || ((stub_entry->stub_type == ppc_stub_long_branch_both
+                      || stub_entry->stub_type == ppc_stub_plt_branch_both
+                      || stub_entry->stub_type == ppc_stub_plt_call_both)
+                     && r_type == R_PPC64_REL24_NOTOC))
+               {
+                 /* Skip over the r2 store at the start of the stub.  */
+                 if (!(stub_entry->stub_type >= ppc_stub_plt_call
+                       && htab->params->tls_get_addr_opt
+                       && h != NULL
+                       && is_tls_get_addr (&h->elf, htab)))
+                   relocation += 4;
+               }
 
              if (r_type == R_PPC64_REL24_NOTOC
                  && (stub_entry->stub_type == ppc_stub_plt_call_notoc
@@ -15322,12 +16099,18 @@ ppc64_elf_relocate_section (bfd *output_bfd,
          break;
 
        case R_PPC64_GOT16_DS:
+         if ((h ? h->elf.type : ELF_ST_TYPE (sym->st_info)) == STT_GNU_IFUNC
+             || !htab->do_toc_opt)
+           break;
          from = TOCstart + htab->sec_info[input_section->id].toc_off;
          if (relocation + addend - from + 0x8000 < 0x10000
-             && SYMBOL_REFERENCES_LOCAL (info, &h->elf))
+             && sec != NULL
+             && sec->output_section != NULL
+             && !discarded_section (sec)
+             && (h == NULL || SYMBOL_REFERENCES_LOCAL (info, &h->elf)))
            {
              insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
-             if ((insn & (0x3f << 26 | 0x3)) == 58u << 26 /* ld */)
+             if ((insn & (0x3fu << 26 | 0x3)) == 58u << 26 /* ld */)
                {
                  insn += (14u << 26) - (58u << 26);
                  bfd_put_32 (input_bfd, insn, contents + (rel->r_offset & ~3));
@@ -15339,19 +16122,27 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 
        case R_PPC64_GOT16_LO_DS:
        case R_PPC64_GOT16_HA:
+         if ((h ? h->elf.type : ELF_ST_TYPE (sym->st_info)) == STT_GNU_IFUNC
+             || !htab->do_toc_opt)
+           break;
          from = TOCstart + htab->sec_info[input_section->id].toc_off;
          if (relocation + addend - from + 0x80008000ULL < 0x100000000ULL
-             && SYMBOL_REFERENCES_LOCAL (info, &h->elf))
+             && sec != NULL
+             && sec->output_section != NULL
+             && !discarded_section (sec)
+             && (h == NULL || SYMBOL_REFERENCES_LOCAL (info, &h->elf)))
            {
              insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
-             if ((insn & (0x3f << 26 | 0x3)) == 58u << 26 /* ld */)
+             if (r_type == R_PPC64_GOT16_LO_DS
+                 && (insn & (0x3fu << 26 | 0x3)) == 58u << 26 /* ld */)
                {
                  insn += (14u << 26) - (58u << 26);
                  bfd_put_32 (input_bfd, insn, contents + (rel->r_offset & ~3));
                  r_type = R_PPC64_TOC16_LO;
                  rel->r_info = ELF64_R_INFO (r_symndx, r_type);
                }
-             else if ((insn & (0x3f << 26)) == 15u << 26 /* addis */)
+             else if (r_type == R_PPC64_GOT16_HA
+                      && (insn & (0x3fu << 26)) == 15u << 26 /* addis */)
                {
                  r_type = R_PPC64_TOC16_HA;
                  rel->r_info = ELF64_R_INFO (r_symndx, r_type);
@@ -15360,32 +16151,41 @@ ppc64_elf_relocate_section (bfd *output_bfd,
          break;
 
        case R_PPC64_GOT_PCREL34:
+         if ((h ? h->elf.type : ELF_ST_TYPE (sym->st_info)) == STT_GNU_IFUNC
+             || !htab->do_toc_opt)
+           break;
          from = (rel->r_offset
                  + input_section->output_section->vma
                  + input_section->output_offset);
-         if (relocation - from + (1ULL << 33) < 1ULL << 34
-             && SYMBOL_REFERENCES_LOCAL (info, &h->elf))
-           {
-             offset = rel->r_offset;
-             pinsn = bfd_get_32 (input_bfd, contents + offset);
-             pinsn <<= 32;
-             pinsn |= bfd_get_32 (input_bfd, contents + offset + 4);
-             if ((pinsn & ((-1ULL << 50) | (63ULL << 26)))
-                  == ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
-               {
-                 /* Replace with paddi.  */
-                 pinsn += (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
-                 r_type = R_PPC64_PCREL34;
-                 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
-                 bfd_put_32 (input_bfd, pinsn >> 32, contents + offset);
-                 bfd_put_32 (input_bfd, pinsn, contents + offset + 4);
-                 goto pcrelopt;
-               }
-           }
-         break;
+         if (!(relocation - from + (1ULL << 33) < 1ULL << 34
+               && sec != NULL
+               && sec->output_section != NULL
+               && !discarded_section (sec)
+               && (h == NULL || SYMBOL_REFERENCES_LOCAL (info, &h->elf))))
+           break;
+
+         offset = rel->r_offset;
+         pinsn = bfd_get_32 (input_bfd, contents + offset);
+         pinsn <<= 32;
+         pinsn |= bfd_get_32 (input_bfd, contents + offset + 4);
+         if ((pinsn & ((-1ULL << 50) | (63ULL << 26)))
+             != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
+           break;
+
+         /* Replace with paddi.  */
+         pinsn += (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
+         r_type = R_PPC64_PCREL34;
+         rel->r_info = ELF64_R_INFO (r_symndx, r_type);
+         bfd_put_32 (input_bfd, pinsn >> 32, contents + offset);
+         bfd_put_32 (input_bfd, pinsn, contents + offset + 4);
+         /* Fall through.  */
 
        case R_PPC64_PCREL34:
-         if (SYMBOL_REFERENCES_LOCAL (info, &h->elf))
+         if (!htab->params->no_pcrel_opt
+             && rel + 1 < relend
+             && rel[1].r_offset == rel->r_offset
+             && rel[1].r_info == ELF64_R_INFO (0, R_PPC64_PCREL_OPT)
+             && (h == NULL || SYMBOL_REFERENCES_LOCAL (info, &h->elf)))
            {
              offset = rel->r_offset;
              pinsn = bfd_get_32 (input_bfd, contents + offset);
@@ -15395,32 +16195,37 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                   == ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
                       | (14ULL << 26) /* paddi */))
                {
-               pcrelopt:
-                 if (rel + 1 < relend
-                     && rel[1].r_offset == offset
-                     && rel[1].r_info == ELF64_R_INFO (0, R_PPC64_PCREL_OPT))
+                 bfd_vma off2 = rel[1].r_addend;
+                 if (off2 == 0)
+                   /* zero means next insn.  */
+                   off2 = 8;
+                 off2 += offset;
+                 if (off2 + 4 <= input_section->size)
                    {
-                     bfd_vma off2 = rel[1].r_addend;
-                     if (off2 == 0)
-                       /* zero means next insn.  */
-                       off2 = 8;
-                     off2 += offset;
-                     if (off2 + 4 <= input_section->size)
+                     uint64_t pinsn2;
+                     bfd_signed_vma addend_off;
+                     pinsn2 = bfd_get_32 (input_bfd, contents + off2);
+                     pinsn2 <<= 32;
+                     if ((pinsn2 & (63ULL << 58)) == 1ULL << 58)
                        {
-                         uint64_t pinsn2;
-                         pinsn2 = bfd_get_32 (input_bfd, contents + off2);
-                         pinsn2 <<= 32;
-                         if ((pinsn2 & (63ULL << 58)) == 1ULL << 58)
+                         if (off2 + 8 > input_section->size)
                            break;
-                         if (xlate_pcrel_opt (&pinsn, &pinsn2))
-                           {
-                             bfd_put_32 (input_bfd, pinsn >> 32,
-                                         contents + offset);
-                             bfd_put_32 (input_bfd, pinsn,
-                                         contents + offset + 4);
-                             bfd_put_32 (input_bfd, pinsn2 >> 32,
-                                         contents + off2);
-                           }
+                         pinsn2 |= bfd_get_32 (input_bfd,
+                                               contents + off2 + 4);
+                       }
+                     if (xlate_pcrel_opt (&pinsn, &pinsn2, &addend_off))
+                       {
+                         addend += addend_off;
+                         rel->r_addend = addend;
+                         bfd_put_32 (input_bfd, pinsn >> 32,
+                                     contents + offset);
+                         bfd_put_32 (input_bfd, pinsn,
+                                     contents + offset + 4);
+                         bfd_put_32 (input_bfd, pinsn2 >> 32,
+                                     contents + off2);
+                         if ((pinsn2 & (63ULL << 58)) == 1ULL << 58)
+                           bfd_put_32 (input_bfd, pinsn2,
+                                       contents + off2 + 4);
                        }
                    }
                }
@@ -15428,7 +16233,6 @@ ppc64_elf_relocate_section (bfd *output_bfd,
          break;
        }
 
-      /* Set `addend'.  */
       tls_type = 0;
       save_unresolved_reloc = unresolved_reloc;
       switch (r_type)
@@ -15439,7 +16243,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                              input_bfd, ppc64_elf_howto_table[r_type]->name);
 
          bfd_set_error (bfd_error_bad_value);
-         ret = FALSE;
+         ret = false;
          goto copy_reloc;
 
        case R_PPC64_NONE:
@@ -15461,7 +16265,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        case R_PPC64_GOT_TLSGD16_LO:
        case R_PPC64_GOT_TLSGD16_HI:
        case R_PPC64_GOT_TLSGD16_HA:
-       case R_PPC64_GOT_TLSGD34:
+       case R_PPC64_GOT_TLSGD_PCREL34:
          tls_type = TLS_TLS | TLS_GD;
          goto dogot;
 
@@ -15469,7 +16273,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        case R_PPC64_GOT_TLSLD16_LO:
        case R_PPC64_GOT_TLSLD16_HI:
        case R_PPC64_GOT_TLSLD16_HA:
-       case R_PPC64_GOT_TLSLD34:
+       case R_PPC64_GOT_TLSLD_PCREL34:
          tls_type = TLS_TLS | TLS_LD;
          goto dogot;
 
@@ -15477,7 +16281,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        case R_PPC64_GOT_TPREL16_LO_DS:
        case R_PPC64_GOT_TPREL16_HI:
        case R_PPC64_GOT_TPREL16_HA:
-       case R_PPC64_GOT_TPREL34:
+       case R_PPC64_GOT_TPREL_PCREL34:
          tls_type = TLS_TLS | TLS_TPREL;
          goto dogot;
 
@@ -15485,7 +16289,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        case R_PPC64_GOT_DTPREL16_LO_DS:
        case R_PPC64_GOT_DTPREL16_HI:
        case R_PPC64_GOT_DTPREL16_HA:
-       case R_PPC64_GOT_DTPREL34:
+       case R_PPC64_GOT_DTPREL_PCREL34:
          tls_type = TLS_TLS | TLS_DTPREL;
          goto dogot;
 
@@ -15505,18 +16309,9 @@ ppc64_elf_relocate_section (bfd *output_bfd,
            bfd_vma off;
            unsigned long indx = 0;
            struct got_entry *ent;
-           bfd_vma sym_addend = orig_rel.r_addend;
-
-           if (r_type == R_PPC64_GOT_PCREL34
-               || r_type == R_PPC64_GOT_TLSGD34
-               || r_type == R_PPC64_GOT_TLSLD34
-               || r_type == R_PPC64_GOT_TPREL34
-               || r_type == R_PPC64_GOT_DTPREL34)
-             sym_addend = 0;
 
            if (tls_type == (TLS_TLS | TLS_LD)
-               && (h == NULL
-                   || !h->elf.def_dynamic))
+               && (h == NULL || SYMBOL_REFERENCES_LOCAL (info, &h->elf)))
              ent = ppc64_tlsld_got (input_bfd);
            else
              {
@@ -15534,7 +16329,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                    else
                      {
                        indx = h->elf.dynindx;
-                       unresolved_reloc = FALSE;
+                       unresolved_reloc = false;
                      }
                    ent = h->elf.got.glist;
                  }
@@ -15546,7 +16341,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                  }
 
                for (; ent != NULL; ent = ent->next)
-                 if (ent->addend == sym_addend
+                 if (ent->addend == orig_rel.r_addend
                      && ent->owner == input_bfd
                      && ent->tls_type == tls_type)
                    break;
@@ -15573,7 +16368,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                   the case of TLSLD where we'll use one entry per
                   module.  */
                asection *relgot;
-               bfd_boolean ifunc;
+               bool ifunc;
 
                *offp = off | 1;
                relgot = NULL;
@@ -15583,27 +16378,25 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                if (ifunc)
                  {
                    relgot = htab->elf.irelplt;
-                   if (indx == 0)
-                     htab->local_ifunc_resolver = 1;
-                   else if (is_static_defined (&h->elf))
-                     htab->maybe_local_ifunc_resolver = 1;
+                   if (indx == 0 || is_static_defined (&h->elf))
+                     htab->elf.ifunc_resolvers = true;
                  }
                else if (indx != 0
                         || (bfd_link_pic (info)
                             && (h == NULL
-                                || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, &h->elf)
-                                || (tls_type == (TLS_TLS | TLS_LD)
-                                    && !h->elf.def_dynamic))
-                            && !(tls_type == (TLS_TLS | TLS_TPREL)
+                                || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, &h->elf))
+                            && !(tls_type != 0
                                  && bfd_link_executable (info)
-                                 && SYMBOL_REFERENCES_LOCAL (info, &h->elf))))
+                                 && (h == NULL
+                                     || SYMBOL_REFERENCES_LOCAL (info,
+                                                                 &h->elf)))))
                  relgot = ppc64_elf_tdata (ent->owner)->relgot;
                if (relgot != NULL)
                  {
                    outrel.r_offset = (got->output_section->vma
                                       + got->output_offset
                                       + off);
-                   outrel.r_addend = sym_addend;
+                   outrel.r_addend = orig_rel.r_addend;
                    if (tls_type & (TLS_LD | TLS_GD))
                      {
                        outrel.r_addend = 0;
@@ -15616,7 +16409,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                            bfd_elf64_swap_reloca_out (output_bfd,
                                                       &outrel, loc);
                            outrel.r_offset += 8;
-                           outrel.r_addend = sym_addend;
+                           outrel.r_addend = orig_rel.r_addend;
                            outrel.r_info
                              = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
                          }
@@ -15662,7 +16455,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                   emitting a reloc.  */
                else
                  {
-                   relocation += sym_addend;
+                   relocation += orig_rel.r_addend;
                    if (tls_type != 0)
                      {
                        if (htab->elf.tls_sec == NULL)
@@ -15693,11 +16486,12 @@ ppc64_elf_relocate_section (bfd *output_bfd,
              abort ();
 
            relocation = got->output_section->vma + got->output_offset + off;
+           addend = 0;
            if (!(r_type == R_PPC64_GOT_PCREL34
-                 || r_type == R_PPC64_GOT_TLSGD34
-                 || r_type == R_PPC64_GOT_TLSLD34
-                 || r_type == R_PPC64_GOT_TPREL34
-                 || r_type == R_PPC64_GOT_DTPREL34))
+                 || r_type == R_PPC64_GOT_TLSGD_PCREL34
+                 || r_type == R_PPC64_GOT_TLSLD_PCREL34
+                 || r_type == R_PPC64_GOT_TPREL_PCREL34
+                 || r_type == R_PPC64_GOT_DTPREL_PCREL34))
              addend = -(TOCstart + htab->sec_info[input_section->id].toc_off);
          }
          break;
@@ -15716,7 +16510,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        case R_PPC64_PLTCALL_NOTOC:
          /* Relocation is to the entry for this symbol in the
             procedure linkage table.  */
-         unresolved_reloc = TRUE;
+         unresolved_reloc = true;
          {
            struct plt_entry **plt_list = NULL;
            if (h != NULL)
@@ -15730,23 +16524,16 @@ ppc64_elf_relocate_section (bfd *output_bfd,
            if (plt_list)
              {
                struct plt_entry *ent;
-               bfd_vma sym_addend = orig_rel.r_addend;
-
-               if (r_type == R_PPC64_PLT_PCREL34
-                   || r_type == R_PPC64_PLT_PCREL34_NOTOC)
-                 sym_addend = 0;
 
                for (ent = *plt_list; ent != NULL; ent = ent->next)
                  if (ent->plt.offset != (bfd_vma) -1
-                     && ent->addend == sym_addend)
+                     && ent->addend == orig_rel.r_addend)
                    {
                      asection *plt;
                      bfd_vma got;
 
                      plt = htab->elf.splt;
-                     if (!htab->elf.dynamic_sections_created
-                         || h == NULL
-                         || h->elf.dynindx == -1)
+                     if (use_local_plt (info, elf_hash_entry (h)))
                        {
                          if (h != NULL
                              ? h->elf.type == STT_GNU_IFUNC
@@ -15767,10 +16554,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                                 + htab->sec_info[input_section->id].toc_off);
                          relocation -= got;
                        }
-                     if (r_type != R_PPC64_PLT_PCREL34
-                         && r_type != R_PPC64_PLT_PCREL34_NOTOC)
-                       addend = 0;
-                     unresolved_reloc = FALSE;
+                     addend = 0;
+                     unresolved_reloc = false;
                      break;
                    }
              }
@@ -15787,7 +16572,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
          else if (sec != NULL && sec->id < htab->sec_info_arr_size)
            relocation += htab->sec_info[sec->id].toc_off;
          else
-           unresolved_reloc = TRUE;
+           unresolved_reloc = true;
          goto dodyn;
 
          /* TOC16 relocs.  We want the offset relative to the TOC base,
@@ -15801,6 +16586,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        case R_PPC64_TOC16_LO_DS:
        case R_PPC64_TOC16_HA:
          addend -= TOCstart + htab->sec_info[input_section->id].toc_off;
+         if (h != NULL)
+           goto dodyn;
          break;
 
          /* Relocate against the beginning of the section.  */
@@ -15956,14 +16743,14 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 
          if (bfd_link_pic (info)
              ? ((h == NULL
-                 || h->dyn_relocs != NULL)
+                 || h->elf.dyn_relocs != NULL)
                 && ((h != NULL && pc_dynrelocs (h))
                     || must_be_dyn_reloc (info, r_type)))
              : (h != NULL
-                ? h->dyn_relocs != NULL
+                ? h->elf.dyn_relocs != NULL
                 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))
            {
-             bfd_boolean skip, relocate;
+             bool skip, relocate;
              asection *sreloc;
              bfd_vma out_off;
              long indx = 0;
@@ -15972,15 +16759,15 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                 are copied into the output file to be resolved at run
                 time.  */
 
-             skip = FALSE;
-             relocate = FALSE;
+             skip = false;
+             relocate = false;
 
              out_off = _bfd_elf_section_offset (output_bfd, info,
                                                 input_section, rel->r_offset);
              if (out_off == (bfd_vma) -1)
-               skip = TRUE;
+               skip = true;
              else if (out_off == (bfd_vma) -2)
-               skip = TRUE, relocate = TRUE;
+               skip = true, relocate = true;
              out_off += (input_section->output_section->vma
                          + input_section->output_offset);
              outrel.r_offset = out_off;
@@ -15999,7 +16786,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 
              if (skip)
                memset (&outrel, 0, sizeof outrel);
-             else if (!SYMBOL_REFERENCES_LOCAL (info, &h->elf)
+             else if (h != NULL
+                      && !SYMBOL_REFERENCES_LOCAL (info, &h->elf)
                       && !is_opd
                       && r_type != R_PPC64_TOC)
                {
@@ -16027,7 +16815,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                             bug in binutils handling of weak syms.)
                             In these cases we won't use the opd
                             entry in this lib.  */
-                         unresolved_reloc = FALSE;
+                         unresolved_reloc = false;
                        }
                      if (!is_opd
                          && r_type == R_PPC64_ADDR64
@@ -16043,7 +16831,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                             Prelink also wants simple and consistent rules
                             for relocs.  This make all RELATIVE relocs have
                             *r_offset equal to r_addend.  */
-                         relocate = TRUE;
+                         relocate = true;
                        }
                    }
                  else
@@ -16059,14 +16847,14 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                             input_bfd, input_section, rel->r_offset,
                             ppc64_elf_howto_table[r_type]->name,
                             sym_name);
-                         ret = FALSE;
+                         ret = false;
                        }
                      else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec))
                        ;
                      else if (sec == NULL || sec->owner == NULL)
                        {
                          bfd_set_error (bfd_error_bad_value);
-                         return FALSE;
+                         return false;
                        }
                      else
                        {
@@ -16121,10 +16909,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                  : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
                {
                  sreloc = htab->elf.irelplt;
-                 if (indx == 0)
-                   htab->local_ifunc_resolver = 1;
-                 else if (is_static_defined (&h->elf))
-                   htab->maybe_local_ifunc_resolver = 1;
+                 if (indx == 0 || is_static_defined (&h->elf))
+                   htab->elf.ifunc_resolvers = true;
                }
              if (sreloc == NULL)
                abort ();
@@ -16136,13 +16922,26 @@ ppc64_elf_relocate_section (bfd *output_bfd,
              loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
              bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
 
+             if (!warned_dynamic
+                 && !ppc64_glibc_dynamic_reloc (ELF64_R_TYPE (outrel.r_info)))
+               {
+                 info->callbacks->einfo
+                   /* xgettext:c-format */
+                   (_("%X%P: %pB: %s against %pT "
+                      "is not supported by glibc as a dynamic relocation\n"),
+                    input_bfd,
+                    ppc64_elf_howto_table[ELF64_R_TYPE (outrel.r_info)]->name,
+                    sym_name);
+                 warned_dynamic = true;
+               }
+
              /* If this reloc is against an external symbol, it will
                 be computed at runtime, so there's no need to do
                 anything now.  However, for the sake of prelink ensure
                 that the section contents are a known value.  */
              if (!relocate)
                {
-                 unresolved_reloc = FALSE;
+                 unresolved_reloc = false;
                  /* The value chosen here is quite arbitrary as ld.so
                     ignores section contents except for the special
                     case of .opd where the contents might be accessed
@@ -16188,7 +16987,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
             ppc64_elf_howto_table[r_type]->name, sym_name);
 
          bfd_set_error (bfd_error_invalid_operation);
-         ret = FALSE;
+         ret = false;
          goto copy_reloc;
        }
 
@@ -16238,7 +17037,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        case R_PPC64_PLTSEQ:
          if (unresolved_reloc)
            {
-             unresolved_reloc = FALSE;
+             unresolved_reloc = false;
              goto nop_it;
            }
          break;
@@ -16253,7 +17052,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
              bfd_byte *p = contents + rel->r_offset;
              bfd_put_32 (input_bfd, PNOP >> 32, p);
              bfd_put_32 (input_bfd, PNOP, p + 4);
-             unresolved_reloc = FALSE;
+             unresolved_reloc = false;
              goto copy_reloc;
            }
          break;
@@ -16261,7 +17060,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        case R_PPC64_PLT16_HA:
          if (unresolved_reloc)
            {
-             unresolved_reloc = FALSE;
+             unresolved_reloc = false;
              goto nop_it;
            }
          /* Fall through.  */
@@ -16286,7 +17085,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        case R_PPC64_PLT16_LO_DS:
          if (unresolved_reloc)
            {
-             unresolved_reloc = FALSE;
+             unresolved_reloc = false;
              goto nop_it;
            }
          /* Fall through.  */
@@ -16303,10 +17102,10 @@ ppc64_elf_relocate_section (bfd *output_bfd,
            {
              bfd_byte *p = contents + (rel->r_offset & ~3);
              insn = bfd_get_32 (input_bfd, p);
-             if ((insn & (0x3f << 26)) == 12u << 26 /* addic */)
+             if ((insn & (0x3fu << 26)) == 12u << 26 /* addic */)
                {
                  /* Transform addic to addi when we change reg.  */
-                 insn &= ~((0x3f << 26) | (0x1f << 16));
+                 insn &= ~((0x3fu << 26) | (0x1f << 16));
                  insn |= (14u << 26) | (2 << 16);
                }
              else
@@ -16322,19 +17121,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
          if (htab->do_tls_opt && relocation + addend + 0x8000 < 0x10000)
            {
              bfd_byte *p = contents + (rel->r_offset & ~3);
-             insn = bfd_get_32 (input_bfd, p);
-             if ((insn & ((0x3f << 26) | 0x1f << 16))
-                 != ((15u << 26) | (13 << 16)) /* addis rt,13,imm */)
-               /* xgettext:c-format */
-               info->callbacks->minfo
-                 (_("%H: warning: %s unexpected insn %#x.\n"),
-                  input_bfd, input_section, rel->r_offset,
-                  ppc64_elf_howto_table[r_type]->name, insn);
-             else
-               {
-                 bfd_put_32 (input_bfd, NOP, p);
-                 goto copy_reloc;
-               }
+             bfd_put_32 (input_bfd, NOP, p);
+             goto copy_reloc;
            }
          break;
 
@@ -16432,8 +17220,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
             forms of all the _DS relocs bloats all reloc switches in
             this file.  It doesn't make much sense to use these
             relocs in data, so testing the insn should be safe.  */
-         if ((insn & (0x3f << 26)) == (56u << 26)
-             || ((insn & (0x3f << 26)) == (61u << 26) && (insn & 3) == 1))
+         if ((insn & (0x3fu << 26)) == (56u << 26)
+             || ((insn & (0x3fu << 26)) == (61u << 26) && (insn & 3) == 1))
            mask = 15;
          relocation += addend;
          addend = insn & (mask ^ 3);
@@ -16447,7 +17235,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                 ppc64_elf_howto_table[r_type]->name,
                 mask + 1);
              bfd_set_error (bfd_error_bad_value);
-             ret = FALSE;
+             ret = false;
              goto copy_reloc;
            }
          break;
@@ -16469,7 +17257,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
             input_bfd, input_section, rel->r_offset,
             howto->name,
             h->elf.root.root.string);
-         ret = FALSE;
+         ret = false;
        }
 
       /* 16-bit fields in insns mostly have signed values, but a
@@ -16482,15 +17270,15 @@ ppc64_elf_relocate_section (bfd *output_bfd,
          enum complain_overflow complain = complain_overflow_signed;
 
          insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
-         if ((insn & (0x3f << 26)) == 10u << 26 /* cmpli */)
+         if ((insn & (0x3fu << 26)) == 10u << 26 /* cmpli */)
            complain = complain_overflow_bitfield;
          else if (howto->rightshift == 0
-                  ? ((insn & (0x3f << 26)) == 28u << 26 /* andi */
-                     || (insn & (0x3f << 26)) == 24u << 26 /* ori */
-                     || (insn & (0x3f << 26)) == 26u << 26 /* xori */)
-                  : ((insn & (0x3f << 26)) == 29u << 26 /* andis */
-                     || (insn & (0x3f << 26)) == 25u << 26 /* oris */
-                     || (insn & (0x3f << 26)) == 27u << 26 /* xoris */))
+                  ? ((insn & (0x3fu << 26)) == 28u << 26 /* andi */
+                     || (insn & (0x3fu << 26)) == 24u << 26 /* ori */
+                     || (insn & (0x3fu << 26)) == 26u << 26 /* xori */)
+                  : ((insn & (0x3fu << 26)) == 29u << 26 /* andis */
+                     || (insn & (0x3fu << 26)) == 25u << 26 /* oris */
+                     || (insn & (0x3fu << 26)) == 27u << 26 /* xoris */))
            complain = complain_overflow_unsigned;
          if (howto->complain_on_overflow != complain)
            {
@@ -16511,10 +17299,10 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        case R_PPC64_GOT_PCREL34:
        case R_PPC64_TPREL34:
        case R_PPC64_DTPREL34:
-       case R_PPC64_GOT_TLSGD34:
-       case R_PPC64_GOT_TLSLD34:
-       case R_PPC64_GOT_TPREL34:
-       case R_PPC64_GOT_DTPREL34:
+       case R_PPC64_GOT_TLSGD_PCREL34:
+       case R_PPC64_GOT_TLSLD_PCREL34:
+       case R_PPC64_GOT_TPREL_PCREL34:
+       case R_PPC64_GOT_DTPREL_PCREL34:
        case R_PPC64_PLT_PCREL34:
        case R_PPC64_PLT_PCREL34_NOTOC:
        case R_PPC64_D28:
@@ -16600,11 +17388,10 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                           && (h->elf.root.type == bfd_link_hash_undefweak
                               || h->elf.root.type == bfd_link_hash_undefined)
                           && is_branch_reloc (r_type))))
-               info->callbacks->reloc_overflow (info, &h->elf.root,
-                                                sym_name, reloc_name,
-                                                orig_rel.r_addend,
-                                                input_bfd, input_section,
-                                                rel->r_offset);
+               info->callbacks->reloc_overflow
+                 (info, (struct bfd_link_hash_entry *) h, sym_name,
+                  reloc_name, orig_rel.r_addend, input_bfd, input_section,
+                  rel->r_offset);
            }
          else
            {
@@ -16613,10 +17400,9 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                (_("%H: %s against `%pT': error %d\n"),
                 input_bfd, input_section, rel->r_offset,
                 reloc_name, sym_name, (int) r);
-             ret = FALSE;
+             ret = false;
            }
-         if (more_info != NULL)
-           free (more_info);
+         free (more_info);
        }
     copy_reloc:
       if (wrel != rel)
@@ -16656,7 +17442,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
       BFD_ASSERT (ppc64_elf_tdata (input_bfd)->opd.relocs == NULL);
       ppc64_elf_tdata (input_bfd)->opd.relocs = rel;
       if (rel == NULL)
-       return FALSE;
+       return false;
       memcpy (rel, relocs, amt);
     }
   return ret;
@@ -16697,7 +17483,7 @@ ppc64_elf_output_symbol_hook (struct bfd_link_info *info,
 /* Finish up dynamic symbol handling.  We set the contents of various
    dynamic sections here.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
                                 struct bfd_link_info *info,
                                 struct elf_link_hash_entry *h,
@@ -16708,7 +17494,7 @@ ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   if (!htab->opd_abi && !h->def_regular)
     for (ent = h->plt.plist; ent != NULL; ent = ent->next)
@@ -16734,23 +17520,21 @@ ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
          break;
        }
 
-  if (h->needs_copy)
+  if (h->needs_copy
+      && (h->root.type == bfd_link_hash_defined
+         || h->root.type == bfd_link_hash_defweak)
+      && (h->root.u.def.section == htab->elf.sdynbss
+         || h->root.u.def.section == htab->elf.sdynrelro))
     {
       /* This symbol needs a copy reloc.  Set it up.  */
       Elf_Internal_Rela rela;
       asection *srel;
       bfd_byte *loc;
 
-      if (h->dynindx == -1
-         || (h->root.type != bfd_link_hash_defined
-             && h->root.type != bfd_link_hash_defweak)
-         || htab->elf.srelbss == NULL
-         || htab->elf.sreldynrelro == NULL)
+      if (h->dynindx == -1)
        abort ();
 
-      rela.r_offset = (h->root.u.def.value
-                      + h->root.u.def.section->output_section->vma
-                      + h->root.u.def.section->output_offset);
+      rela.r_offset = defined_sym_val (h);
       rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
       rela.r_addend = 0;
       if (h->root.u.def.section == htab->elf.sdynrelro)
@@ -16762,7 +17546,7 @@ ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
       bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Used to decide how to sort relocs in an optimal manner for the
@@ -16795,7 +17579,7 @@ ppc64_elf_reloc_type_class (const struct bfd_link_info *info,
 
 /* Finish up the dynamic sections.  */
 
-static bfd_boolean
+static bool
 ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
                                   struct bfd_link_info *info)
 {
@@ -16805,7 +17589,7 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
 
   htab = ppc_hash_table (info);
   if (htab == NULL)
-    return FALSE;
+    return false;
 
   dynobj = htab->elf.dynobj;
   sdyn = bfd_get_linker_section (dynobj, ".dynamic");
@@ -16878,11 +17662,7 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
              break;
 
            case DT_TEXTREL:
-             if (htab->local_ifunc_resolver)
-               info->callbacks->einfo
-                 (_("%X%P: text relocations and GNU indirect "
-                    "functions will result in a segfault at runtime\n"));
-             else if (htab->maybe_local_ifunc_resolver)
+             if (htab->elf.ifunc_resolvers)
                info->callbacks->einfo
                  (_("%P: warning: text relocations and GNU indirect "
                     "functions may result in a segfault at runtime\n"));
@@ -16924,7 +17704,7 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
                                       elf_section_data (htab->brlt)->rela.hdr,
                                       elf_section_data (htab->brlt)->relocs,
                                       NULL))
-    return FALSE;
+    return false;
 
   if (htab->glink != NULL
       && htab->glink->reloc_count != 0
@@ -16933,7 +17713,7 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
                                       elf_section_data (htab->glink)->rela.hdr,
                                       elf_section_data (htab->glink)->relocs,
                                       NULL))
-    return FALSE;
+    return false;
 
 
   if (htab->glink_eh_frame != NULL
@@ -16942,7 +17722,7 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
       && !_bfd_elf_write_section_eh_frame (output_bfd, info,
                                           htab->glink_eh_frame,
                                           htab->glink_eh_frame->contents))
-    return FALSE;
+    return false;
 
   /* We need to handle writing out multiple GOT sections ourselves,
      since we didn't add them to DYNOBJ.  We know dynobj is the first
@@ -16961,7 +17741,7 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
          && !bfd_set_section_contents (output_bfd, s->output_section,
                                        s->contents, s->output_offset,
                                        s->size))
-       return FALSE;
+       return false;
       s = ppc64_elf_tdata (dynobj)->relgot;
       if (s != NULL
          && s->size != 0
@@ -16969,10 +17749,10 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
          && !bfd_set_section_contents (output_bfd, s->output_section,
                                        s->contents, s->output_offset,
                                        s->size))
-       return FALSE;
+       return false;
     }
 
-  return TRUE;
+  return true;
 }
 
 #include "elf64-target.h"
@@ -16980,7 +17760,9 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
 /* FreeBSD support */
 
 #undef  TARGET_LITTLE_SYM
+#define TARGET_LITTLE_SYM powerpc_elf64_fbsd_le_vec
 #undef  TARGET_LITTLE_NAME
+#define TARGET_LITTLE_NAME "elf64-powerpcle-freebsd"
 
 #undef  TARGET_BIG_SYM
 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
This page took 0.163084 seconds and 4 git commands to generate.