Enable support for the AArch64 dot-prod instruction in the Cortex A55 and A75 cpus.
[deliverable/binutils-gdb.git] / bfd / elf32-ppc.c
index 91942ec297fb20488698ae78f6aae79af2022123..2bdba9ff5aed404d2c028a95e400b7210ddf5a3e 100644 (file)
@@ -1,5 +1,5 @@
 /* PowerPC-specific support for 32-bit ELF
-   Copyright (C) 1994-2015 Free Software Foundation, Inc.
+   Copyright (C) 1994-2017 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -35,7 +35,7 @@
 #include "elf32-ppc.h"
 #include "elf-vxworks.h"
 #include "dwarf2.h"
-#include "elf-linux-psinfo.h"
+#include "opcode/ppc.h"
 
 typedef enum split16_format_type
 {
@@ -134,7 +134,7 @@ static const bfd_vma ppc_elf_vxworks_pic_plt0_entry
 #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3
 /* The number of relocations in the PLTResolve slot. */
 #define VXWORKS_PLTRESOLVE_RELOCS 2
-/* The number of relocations in the PLTResolve slot when when creating
+/* The number of relocations in the PLTResolve slot when creating
    a shared library. */
 #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0
 
@@ -414,7 +414,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_GOT16",         /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -430,7 +430,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_GOT16_LO",      /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -446,7 +446,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_GOT16_HI",      /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -462,7 +462,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        ppc_elf_addr16_ha_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_GOT16_HA",      /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -477,8 +477,8 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         26,                    /* bitsize */
         TRUE,                  /* pc_relative */
         0,                     /* bitpos */
-        complain_overflow_signed,  /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        complain_overflow_signed, /* complain_on_overflow */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_PLTREL24",      /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -497,7 +497,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_COPY",          /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -513,7 +513,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_GLOB_DAT",      /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -528,7 +528,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_JMP_SLOT",      /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -623,7 +623,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_PLT32",         /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -639,7 +639,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         TRUE,                  /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_PLTREL32",      /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -655,7 +655,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_PLT16_LO",      /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -671,7 +671,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_PLT16_HI",      /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -687,7 +687,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        ppc_elf_addr16_ha_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_PLT16_HA",      /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -703,7 +703,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_SDAREL16",      /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -718,7 +718,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_SECTOFF",       /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -733,7 +733,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_SECTOFF_LO",    /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -748,7 +748,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_SECTOFF_HI",    /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -763,7 +763,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        ppc_elf_addr16_ha_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_SECTOFF_HA",    /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1239,7 +1239,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_EMB_NADDR32",   /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1254,7 +1254,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_EMB_NADDR16",   /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1269,7 +1269,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont,/* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_EMB_ADDR16_LO", /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1284,7 +1284,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_EMB_NADDR16_HI", /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1301,7 +1301,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        ppc_elf_addr16_ha_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_EMB_NADDR16_HA", /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1318,7 +1318,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_EMB_SDAI16",    /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1335,7 +1335,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_EMB_SDA2I16",   /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1351,7 +1351,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_EMB_SDA2REL",   /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1368,7 +1368,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_EMB_SDA21",     /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1392,7 +1392,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_EMB_RELSDA",    /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1426,7 +1426,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         "R_PPC_VLE_REL15",     /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0xfe,                  /* dst_mask */
+        0xfffe,                /* dst_mask */
         TRUE),                 /* pcrel_offset */
 
   /* A relative 24 bit branch.  */
@@ -1452,11 +1452,11 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_VLE_LO16A",     /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f007ff,             /* dst_mask */
+        0x1f07ff,              /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   /* The 16 LSBS in split16d format.  */
@@ -1467,11 +1467,11 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
-        "R_PPC_VLE_LO16D",             /* name */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_LO16D",     /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f07ff,              /* dst_mask */
+        0x3e007ff,             /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   /* Bits 16-31 split16a format.  */
@@ -1482,11 +1482,11 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
-        "R_PPC_VLE_HI16A",             /* name */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_HI16A",     /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f007ff,             /* dst_mask */
+        0x1f07ff,              /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   /* Bits 16-31 split16d format.  */
@@ -1497,11 +1497,11 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
-        "R_PPC_VLE_HI16D",             /* name */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_HI16D",     /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f07ff,              /* dst_mask */
+        0x3e007ff,             /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   /* Bits 16-31 (High Adjusted) in split16a format.  */
@@ -1512,11 +1512,11 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
-        "R_PPC_VLE_HA16A",             /* name */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_HA16A",     /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f007ff,             /* dst_mask */
+        0x1f07ff,              /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   /* Bits 16-31 (High Adjusted) in split16d format.  */
@@ -1527,11 +1527,11 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
-        "R_PPC_VLE_HA16D",             /* name */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_HA16D",     /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f07ff,              /* dst_mask */
+        0x3e007ff,             /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   /* This reloc is like R_PPC_EMB_SDA21 but only applies to e_add16i
@@ -1544,8 +1544,8 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
-        "R_PPC_VLE_SDA21",             /* name */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_SDA21",     /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0xffff,                /* dst_mask */
@@ -1559,7 +1559,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_VLE_SDA21_LO",  /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1573,12 +1573,12 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         16,                    /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
-        complain_overflow_dont,        /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
-        "R_PPC_VLE_SDAREL_LO16A",      /* name */
+        complain_overflow_dont, /* complain_on_overflow */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_SDAREL_LO16A", /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f007ff,             /* dst_mask */
+        0x1f07ff,              /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   /* The 16 LSBS relative to _SDA_BASE_ in split16d format.  */
@@ -1588,72 +1588,72 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         16,                    /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
-        complain_overflow_dont,        /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
-        "R_PPC_VLE_SDAREL_LO16D",              /* name */
+        complain_overflow_dont, /* complain_on_overflow */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_SDAREL_LO16D", /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f07ff,              /* dst_mask */
+        0x3e007ff,             /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   /* Bits 16-31 relative to _SDA_BASE_ in split16a format.  */
-  HOWTO (R_PPC_VLE_SDAREL_HI16A,       /* type */
+  HOWTO (R_PPC_VLE_SDAREL_HI16A, /* type */
         16,                    /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         16,                    /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
-        complain_overflow_dont,        /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
-        "R_PPC_VLE_SDAREL_HI16A",      /* name */
+        complain_overflow_dont, /* complain_on_overflow */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_SDAREL_HI16A", /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f007ff,             /* dst_mask */
+        0x1f07ff,              /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   /* Bits 16-31 relative to _SDA_BASE_ in split16d format.  */
-  HOWTO (R_PPC_VLE_SDAREL_HI16D,       /* type */
+  HOWTO (R_PPC_VLE_SDAREL_HI16D, /* type */
         16,                    /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         16,                    /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
-        complain_overflow_dont,        /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
-        "R_PPC_VLE_SDAREL_HI16D",      /* name */
+        complain_overflow_dont, /* complain_on_overflow */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_SDAREL_HI16D", /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f07ff,              /* dst_mask */
+        0x3e007ff,             /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   /* Bits 16-31 (HA) relative to _SDA_BASE split16a format.  */
-  HOWTO (R_PPC_VLE_SDAREL_HA16A,       /* type */
+  HOWTO (R_PPC_VLE_SDAREL_HA16A, /* type */
         16,                    /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         16,                    /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
-        complain_overflow_dont,        /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
-        "R_PPC_VLE_SDAREL_HA16A",      /* name */
+        complain_overflow_dont, /* complain_on_overflow */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_SDAREL_HA16A", /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f007ff,             /* dst_mask */
+        0x1f07ff,              /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   /* Bits 16-31 (HA) relative to _SDA_BASE split16d format.  */
-  HOWTO (R_PPC_VLE_SDAREL_HA16D,       /* type */
+  HOWTO (R_PPC_VLE_SDAREL_HA16D, /* type */
         16,                    /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         16,                    /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
-        complain_overflow_dont,        /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
-        "R_PPC_VLE_SDAREL_HA16D",      /* name */
+        complain_overflow_dont, /* complain_on_overflow */
+        ppc_elf_unhandled_reloc, /* special_function */
+        "R_PPC_VLE_SDAREL_HA16D", /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0x1f07ff,              /* dst_mask */
+        0x3e007ff,             /* dst_mask */
         FALSE),                /* pcrel_offset */
 
   HOWTO (R_PPC_IRELATIVE,      /* type */
@@ -1663,7 +1663,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
-        bfd_elf_generic_reloc,  /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_IRELATIVE",     /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1731,6 +1731,36 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         0xffff,                /* dst_mask */
         TRUE),                 /* pcrel_offset */
 
+  /* Like R_PPC_REL16_HA but for split field in addpcis.  */
+  HOWTO (R_PPC_REL16DX_HA,     /* type */
+        16,                    /* rightshift */
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
+        16,                    /* bitsize */
+        TRUE,                  /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_signed, /* complain_on_overflow */
+        ppc_elf_addr16_ha_reloc, /* special_function */
+        "R_PPC_REL16DX_HA",    /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0x1fffc1,              /* dst_mask */
+        TRUE),                 /* pcrel_offset */
+
+  /* A split-field reloc for addpcis, non-relative (gas internal use only).  */
+  HOWTO (R_PPC_16DX_HA,                /* type */
+        16,                    /* rightshift */
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
+        16,                    /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_signed, /* complain_on_overflow */
+        ppc_elf_addr16_ha_reloc, /* special_function */
+        "R_PPC_16DX_HA",       /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0x1fffc1,              /* dst_mask */
+        FALSE),                /* pcrel_offset */
+
   /* GNU extension to record C++ vtable hierarchy.  */
   HOWTO (R_PPC_GNU_VTINHERIT,  /* type */
         0,                     /* rightshift */
@@ -1769,7 +1799,7 @@ static reloc_howto_type ppc_elf_howto_raw[] = {
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        ppc_elf_unhandled_reloc, /* special_function */
         "R_PPC_TOC16",         /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -1804,30 +1834,28 @@ struct elf_external_ppc_linux_prpsinfo32
     char pr_psargs[80];                        /* Initial part of arg list.  */
   };
 
-/* Helper macro to swap (properly handling endianess) things from the
-   `elf_internal_prpsinfo' structure to the `elf_external_ppc_prpsinfo32'
-   structure.
-
-   Note that FROM should be a pointer, and TO should be the explicit type.  */
-
-#define PPC_LINUX_PRPSINFO32_SWAP_FIELDS(abfd, from, to)             \
-  do                                                                 \
-    {                                                                \
-      H_PUT_8 (abfd, from->pr_state, &to.pr_state);                  \
-      H_PUT_8 (abfd, from->pr_sname, &to.pr_sname);                  \
-      H_PUT_8 (abfd, from->pr_zomb, &to.pr_zomb);                    \
-      H_PUT_8 (abfd, from->pr_nice, &to.pr_nice);                    \
-      H_PUT_32 (abfd, from->pr_flag, to.pr_flag);                    \
-      H_PUT_32 (abfd, from->pr_uid, to.pr_uid);                              \
-      H_PUT_32 (abfd, from->pr_gid, to.pr_gid);                              \
-      H_PUT_32 (abfd, from->pr_pid, to.pr_pid);                              \
-      H_PUT_32 (abfd, from->pr_ppid, to.pr_ppid);                    \
-      H_PUT_32 (abfd, from->pr_pgrp, to.pr_pgrp);                    \
-      H_PUT_32 (abfd, from->pr_sid, to.pr_sid);                              \
-      strncpy (to.pr_fname, from->pr_fname, sizeof (to.pr_fname));    \
-      strncpy (to.pr_psargs, from->pr_psargs, sizeof (to.pr_psargs)); \
-    } while (0)
+/* Helper function to copy an elf_internal_linux_prpsinfo in host
+   endian to an elf_external_ppc_linux_prpsinfo32 in target endian.  */
 
+static inline void
+swap_ppc_linux_prpsinfo32_out (bfd *obfd,
+                              const struct elf_internal_linux_prpsinfo *from,
+                              struct elf_external_ppc_linux_prpsinfo32 *to)
+{
+  bfd_put_8 (obfd, from->pr_state, &to->pr_state);
+  bfd_put_8 (obfd, from->pr_sname, &to->pr_sname);
+  bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb);
+  bfd_put_8 (obfd, from->pr_nice, &to->pr_nice);
+  bfd_put_32 (obfd, from->pr_flag, to->pr_flag);
+  bfd_put_32 (obfd, from->pr_uid, to->pr_uid);
+  bfd_put_32 (obfd, from->pr_gid, to->pr_gid);
+  bfd_put_32 (obfd, from->pr_pid, to->pr_pid);
+  bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
+  bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
+  bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
+  strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
+  strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
+}
 \f
 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done.  */
 
@@ -1989,6 +2017,8 @@ ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
     case BFD_RELOC_LO16_PCREL:         r = R_PPC_REL16_LO;             break;
     case BFD_RELOC_HI16_PCREL:         r = R_PPC_REL16_HI;             break;
     case BFD_RELOC_HI16_S_PCREL:       r = R_PPC_REL16_HA;             break;
+    case BFD_RELOC_PPC_16DX_HA:                r = R_PPC_16DX_HA;              break;
+    case BFD_RELOC_PPC_REL16DX_HA:     r = R_PPC_REL16DX_HA;           break;
     case BFD_RELOC_VTABLE_INHERIT:     r = R_PPC_GNU_VTINHERIT;        break;
     case BFD_RELOC_VTABLE_ENTRY:       r = R_PPC_GNU_VTENTRY;          break;
     }
@@ -2015,7 +2045,7 @@ ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
 /* Set the howto pointer for a PowerPC ELF reloc.  */
 
 static void
-ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
+ppc_elf_info_to_howto (bfd *abfd,
                       arelent *cache_ptr,
                       Elf_Internal_Rela *dst)
 {
@@ -2028,8 +2058,9 @@ ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= R_PPC_max)
     {
-      (*_bfd_error_handler) (_("%B: unrecognised PPC reloc number: %d"),
-                            abfd, r_type);
+      /* xgettext:c-format */
+      _bfd_error_handler (_("%B: unrecognised PPC reloc number: %d"),
+                         abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
       r_type = R_PPC_NONE;
     }
@@ -2039,8 +2070,9 @@ ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
      ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation.  */
   if (!cache_ptr->howto)
     {
-      (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
-                             abfd, r_type);
+      /* xgettext:c-format */
+      _bfd_error_handler (_("%B: invalid relocation type %d"),
+                         abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
 
       cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE];
@@ -2050,15 +2082,18 @@ ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs.  */
 
 static bfd_reloc_status_type
-ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED,
+ppc_elf_addr16_ha_reloc (bfd *abfd,
                         arelent *reloc_entry,
                         asymbol *symbol,
-                        void *data ATTRIBUTE_UNUSED,
+                        void *data,
                         asection *input_section,
                         bfd *output_bfd,
                         char **error_message ATTRIBUTE_UNUSED)
 {
-  bfd_vma relocation;
+  enum elf_ppc_reloc_type r_type;
+  long insn;
+  bfd_size_type octets;
+  bfd_vma value;
 
   if (output_bfd != NULL)
     {
@@ -2066,20 +2101,28 @@ ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED,
       return bfd_reloc_ok;
     }
 
-  if (bfd_is_com_section (symbol->section))
-    relocation = 0;
-  else
-    relocation = symbol->value;
-
-  relocation += symbol->section->output_section->vma;
-  relocation += symbol->section->output_offset;
-  relocation += reloc_entry->addend;
-  if (reloc_entry->howto->pc_relative)
-    relocation -= reloc_entry->address;
-
-  reloc_entry->addend += (relocation & 0x8000) << 1;
-
-  return bfd_reloc_continue;
+  reloc_entry->addend += 0x8000;
+  r_type = reloc_entry->howto->type;
+  if (r_type != R_PPC_REL16DX_HA)
+    return bfd_reloc_continue;
+
+  value = 0;
+  if (!bfd_is_com_section (symbol->section))
+    value = symbol->value;
+  value += (reloc_entry->addend
+           + symbol->section->output_offset
+           + symbol->section->output_section->vma);
+  value -= (reloc_entry->address
+           + input_section->output_offset
+           + input_section->output_section->vma);
+  value >>= 16;
+
+  octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
+  insn &= ~0x1fffc1;
+  insn |= (value & 0xffc1) | ((value & 0x3e) << 15);
+  bfd_put_32 (abfd, insn, (bfd_byte *) data + octets);
+  return bfd_reloc_ok;
 }
 
 static bfd_reloc_status_type
@@ -2172,13 +2215,94 @@ ppc_elf_mkobject (bfd *abfd)
                                  PPC32_ELF_DATA);
 }
 
+/* When defaulting arch/mach, decode apuinfo to find a better match.  */
+
+bfd_boolean
+_bfd_elf_ppc_set_arch (bfd *abfd)
+{
+  unsigned long mach = 0;
+  asection *s;
+  unsigned char *contents;
+
+  if (abfd->arch_info->bits_per_word == 32
+      && bfd_big_endian (abfd))
+    {
+
+      for (s = abfd->sections; s != NULL; s = s->next)
+       if ((elf_section_data (s)->this_hdr.sh_flags & SHF_PPC_VLE) != 0)
+         break;
+      if (s != NULL)
+       mach = bfd_mach_ppc_vle;
+    }
+
+  if (mach == 0)
+    {
+      s = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
+      if (s != NULL && bfd_malloc_and_get_section (abfd, s, &contents))
+       {
+         unsigned int apuinfo_size = bfd_get_32 (abfd, contents + 4);
+         unsigned int i;
+
+         for (i = 20; i < apuinfo_size + 20 && i + 4 <= s->size; i += 4)
+           {
+             unsigned int val = bfd_get_32 (abfd, contents + i);
+             switch (val >> 16)
+               {
+               case PPC_APUINFO_PMR:
+               case PPC_APUINFO_RFMCI:
+                 if (mach == 0)
+                   mach = bfd_mach_ppc_titan;
+                 break;
+
+               case PPC_APUINFO_ISEL:
+               case PPC_APUINFO_CACHELCK:
+                 if (mach == bfd_mach_ppc_titan)
+                   mach = bfd_mach_ppc_e500mc;
+                 break;
+
+               case PPC_APUINFO_SPE:
+               case PPC_APUINFO_EFS:
+               case PPC_APUINFO_BRLOCK:
+                 if (mach != bfd_mach_ppc_vle)
+                   mach = bfd_mach_ppc_e500;
+                 break;
+
+               case PPC_APUINFO_VLE:
+                 mach = bfd_mach_ppc_vle;
+                 break;
+
+               default:
+                 mach = -1ul;
+               }
+           }
+         free (contents);
+       }
+    }
+
+  if (mach != 0 && mach != -1ul)
+    {
+      const bfd_arch_info_type *arch;
+
+      for (arch = abfd->arch_info->next; arch; arch = arch->next)
+       if (arch->mach == mach)
+         {
+           abfd->arch_info = arch;
+           break;
+         }
+    }
+  return TRUE;
+}
+
 /* Fix bad default arch selected for a 32 bit input bfd when the
-   default is 64 bit.  */
+   default is 64 bit.  Also select arch based on apuinfo.  */
 
 static bfd_boolean
 ppc_elf_object_p (bfd *abfd)
 {
-  if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
+  if (!abfd->arch_info->the_default)
+    return TRUE;
+
+  if (abfd->arch_info->bits_per_word == 64)
     {
       Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
 
@@ -2189,7 +2313,7 @@ ppc_elf_object_p (bfd *abfd)
          BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
        }
     }
-  return TRUE;
+  return _bfd_elf_ppc_set_arch (abfd);
 }
 
 /* Function to set whether a module needs the -mrelocatable bit set.  */
@@ -2270,14 +2394,15 @@ ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
 }
 
 char *
-elfcore_write_ppc_linux_prpsinfo32 (bfd *abfd, char *buf, int *bufsiz,
-                                     const struct elf_internal_linux_prpsinfo *prpsinfo)
+elfcore_write_ppc_linux_prpsinfo32
+  (bfd *abfd,
+   char *buf,
+   int *bufsiz,
+   const struct elf_internal_linux_prpsinfo *prpsinfo)
 {
   struct elf_external_ppc_linux_prpsinfo32 data;
 
-  memset (&data, 0, sizeof (data));
-  PPC_LINUX_PRPSINFO32_SWAP_FIELDS (abfd, prpsinfo, data);
-
+  swap_ppc_linux_prpsinfo32_out (abfd, prpsinfo, &data);
   return elfcore_write_note (abfd, buf, bufsiz,
                             "CORE", NT_PRPSINFO, &data, sizeof (data));
 }
@@ -2338,18 +2463,6 @@ ppc_elf_lookup_section_flags (char *flag_name)
   return 0;
 }
 
-/* Add the VLE flag if required.  */
-
-bfd_boolean
-ppc_elf_section_processing (bfd *abfd, Elf_Internal_Shdr *shdr)
-{
-  if (bfd_get_mach (abfd) == bfd_mach_ppc_vle
-      && (shdr->sh_flags & SHF_EXECINSTR) != 0)
-    shdr->sh_flags |= SHF_PPC_VLE;
-
-  return TRUE;
-}
-
 /* Return address for Ith PLT stub in section PLT, for relocation REL
    or (bfd_vma) -1 if it should not be included.  */
 
@@ -2429,10 +2542,7 @@ bfd_boolean
 ppc_elf_modify_segment_map (bfd *abfd,
                            struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
-  struct elf_segment_map *m, *n;
-  bfd_size_type amt;
-  unsigned int j, k;
-  bfd_boolean sect0_vle, sectj_vle;
+  struct elf_segment_map *m;
 
   /* At this point in the link, output sections have already been sorted by
      LMA and assigned to segments.  All that is left to do is to ensure
@@ -2442,46 +2552,73 @@ ppc_elf_modify_segment_map (bfd *abfd,
 
   for (m = elf_seg_map (abfd); m != NULL; m = m->next)
     {
-      if (m->count == 0)
+      struct elf_segment_map *n;
+      bfd_size_type amt;
+      unsigned int j, k;
+      unsigned int p_flags;
+
+      if (m->p_type != PT_LOAD || m->count == 0)
        continue;
 
-      sect0_vle = (elf_section_flags (m->sections[0]) & SHF_PPC_VLE) != 0;
-      for (j = 1; j < m->count; ++j)
+      for (p_flags = PF_R, j = 0; j != m->count; ++j)
        {
-         sectj_vle = (elf_section_flags (m->sections[j]) & SHF_PPC_VLE) != 0;
+         if ((m->sections[j]->flags & SEC_READONLY) == 0)
+           p_flags |= PF_W;
+         if ((m->sections[j]->flags & SEC_CODE) != 0)
+           {
+             p_flags |= PF_X;
+             if ((elf_section_flags (m->sections[j]) & SHF_PPC_VLE) != 0)
+               p_flags |= PF_PPC_VLE;
+             break;
+           }
+       }
+      if (j != m->count)
+       while (++j != m->count)
+         {
+           unsigned int p_flags1 = PF_R;
 
-         if (sectj_vle != sect0_vle)
-           break;
-        }
-      if (j >= m->count)
+           if ((m->sections[j]->flags & SEC_READONLY) == 0)
+             p_flags1 |= PF_W;
+           if ((m->sections[j]->flags & SEC_CODE) != 0)
+             {
+               p_flags1 |= PF_X;
+               if ((elf_section_flags (m->sections[j]) & SHF_PPC_VLE) != 0)
+                 p_flags1 |= PF_PPC_VLE;
+               if (((p_flags1 ^ p_flags) & PF_PPC_VLE) != 0)
+                 break;
+             }
+           p_flags |= p_flags1;
+         }
+      /* If we're splitting a segment which originally contained rw
+        sections then those sections might now only be in one of the
+        two parts.  So always set p_flags if splitting, even if we
+        are being called for objcopy with p_flags_valid set.  */
+      if (j != m->count || !m->p_flags_valid)
+       {
+         m->p_flags_valid = 1;
+         m->p_flags = p_flags;
+       }
+      if (j == m->count)
        continue;
 
-      /* sections 0..j-1 stay in this (current) segment,
+      /* Sections 0..j-1 stay in this (current) segment,
         the remainder are put in a new segment.
         The scan resumes with the new segment.  */
 
-      /* Fix the new segment.  */
       amt = sizeof (struct elf_segment_map);
       amt += (m->count - j - 1) * sizeof (asection *);
       n = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
       if (n == NULL)
-        return FALSE;
+       return FALSE;
 
       n->p_type = PT_LOAD;
-      n->p_flags = PF_X | PF_R;
-      if (sectj_vle)
-        n->p_flags |= PF_PPC_VLE;
       n->count = m->count - j;
       for (k = 0; k < n->count; ++k)
-        {
-          n->sections[k] = m->sections[j+k];
-          m->sections[j+k] = NULL;
-       }
+       n->sections[k] = m->sections[j + k];
+      m->count = j;
+      m->p_size_valid = 0;
       n->next = m->next;
       m->next = n;
-
-      /* Fix the current segment  */
-      m->count = j;
     }
 
   return TRUE;
@@ -2494,16 +2631,16 @@ ppc_elf_modify_segment_map (bfd *abfd,
 
 static const struct bfd_elf_special_section ppc_elf_special_sections[] =
 {
-  { STRING_COMMA_LEN (".plt"),             0, SHT_NOBITS,   SHF_ALLOC + SHF_EXECINSTR },
-  { STRING_COMMA_LEN (".sbss"),           -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE },
-  { STRING_COMMA_LEN (".sbss2"),          -2, SHT_PROGBITS, SHF_ALLOC },
-  { STRING_COMMA_LEN (".sdata"),          -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
-  { STRING_COMMA_LEN (".sdata2"),         -2, SHT_PROGBITS, SHF_ALLOC },
-  { STRING_COMMA_LEN (".tags"),            0, SHT_ORDERED,  SHF_ALLOC },
-  { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE,     0 },
-  { STRING_COMMA_LEN (".PPC.EMB.sbss0"),   0, SHT_PROGBITS, SHF_ALLOC },
-  { STRING_COMMA_LEN (".PPC.EMB.sdata0"),  0, SHT_PROGBITS, SHF_ALLOC },
-  { NULL,                              0,  0, 0,            0 }
+  { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR },
+  { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
+  { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS, SHF_ALLOC },
+  { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
+  { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS, SHF_ALLOC },
+  { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED, SHF_ALLOC },
+  { STRING_COMMA_LEN (APUINFO_SECTION_NAME), 0, SHT_NOTE, 0 },
+  { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS, SHF_ALLOC },
+  { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS, SHF_ALLOC },
+  { NULL, 0, 0, 0, 0 }
 };
 
 /* This is what we want for new plt/got.  */
@@ -2511,7 +2648,7 @@ static struct bfd_elf_special_section ppc_alt_plt =
   { STRING_COMMA_LEN (".plt"),             0, SHT_PROGBITS, SHF_ALLOC };
 
 static const struct bfd_elf_special_section *
-ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
+ppc_elf_get_sec_type_attr (bfd *abfd, asection *sec)
 {
   const struct bfd_elf_special_section *ssect;
 
@@ -2612,9 +2749,6 @@ apuinfo_list_finish (void)
   head = NULL;
 }
 
-#define APUINFO_SECTION_NAME   ".PPC.EMB.apuinfo"
-#define APUINFO_LABEL          "APUinfo"
-
 /* Scan the input BFDs and create a linked list of
    the APUinfo values that will need to be emitted.  */
 
@@ -2643,6 +2777,7 @@ ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
       if (asec == NULL)
        continue;
 
+      /* xgettext:c-format */
       error_message = _("corrupt %s section in %B");
       length = asec->size;
       if (length < 20)
@@ -2662,6 +2797,7 @@ ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
       if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
          || (bfd_bread (buffer, length, ibfd) != length))
        {
+         /* xgettext:c-format */
          error_message = _("unable to read in %s section from %B");
          goto fail;
        }
@@ -2703,6 +2839,7 @@ ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
       if (asec && ! bfd_set_section_size (abfd, asec, 20 + num_entries * 4))
        {
          ibfd = abfd;
+         /* xgettext:c-format */
          error_message = _("warning: unable to set size of %s section in %B");
        }
     }
@@ -2712,7 +2849,7 @@ ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
     free (buffer);
 
   if (error_message)
-    (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME);
+    _bfd_error_handler (error_message, APUINFO_SECTION_NAME, ibfd);
 }
 
 /* Prevent the output section from accumulating the input sections'
@@ -2752,7 +2889,7 @@ ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
   buffer = bfd_malloc (length);
   if (buffer == NULL)
     {
-      (*_bfd_error_handler)
+      _bfd_error_handler
        (_("failed to allocate space for new APUinfo section."));
       return;
     }
@@ -2772,10 +2909,10 @@ ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
     }
 
   if (length != asec->size)
-    (*_bfd_error_handler) (_("failed to compute new APUinfo section."));
+    _bfd_error_handler (_("failed to compute new APUinfo section."));
 
   if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
-    (*_bfd_error_handler) (_("failed to install new APUinfo section."));
+    _bfd_error_handler (_("failed to install new APUinfo section."));
 
   free (buffer);
 
@@ -3055,9 +3192,9 @@ struct plt_entry
   bfd_vma glink_offset;
 };
 
-/* Of those relocs that might be copied as dynamic relocs, this function
-   selects those that must be copied when linking a shared library,
-   even when the symbol is local.  */
+/* Of those relocs that might be copied as dynamic relocs, this
+   function selects those that must be copied when linking a shared
+   library or PIE, even when the symbol is local.  */
 
 static int
 must_be_dyn_reloc (struct bfd_link_info *info,
@@ -3066,6 +3203,10 @@ must_be_dyn_reloc (struct bfd_link_info *info,
   switch (r_type)
     {
     default:
+      /* Only relative relocs can be resolved when the object load
+        address isn't fixed.  DTPREL32 is excluded because the
+        dynamic linker needs to differentiate global dynamic from
+        local dynamic __tls_index pairs when PPC_OPT_TLS is set.  */
       return 1;
 
     case R_PPC_REL24:
@@ -3080,10 +3221,19 @@ must_be_dyn_reloc (struct bfd_link_info *info,
     case R_PPC_TPREL16_LO:
     case R_PPC_TPREL16_HI:
     case R_PPC_TPREL16_HA:
-      return !info->executable;
+      /* These relocations are relative but in a shared library the
+        linker doesn't know the thread pointer base.  */
+      return bfd_link_dll (info);
     }
 }
 
+/* Whether an undefined weak symbol should resolve to its link-time
+   value, even in PIC or PIE objects.  */
+#define UNDEFWEAK_NO_DYNAMIC_RELOC(INFO, H)            \
+  ((H)->root.type == bfd_link_hash_undefweak           \
+   && (ELF_ST_VISIBILITY ((H)->other) != STV_DEFAULT   \
+       || (INFO)->dynamic_undefined_weak == 0))
+
 /* 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
    section, and instead use a dynamic relocation to point into the
@@ -3154,15 +3304,7 @@ struct ppc_elf_link_hash_table
   struct ppc_elf_params *params;
 
   /* Short-cuts to get to dynamic linker sections.  */
-  asection *got;
-  asection *relgot;
   asection *glink;
-  asection *plt;
-  asection *relplt;
-  asection *iplt;
-  asection *reliplt;
-  asection *dynbss;
-  asection *relbss;
   asection *dynsbss;
   asection *relsbss;
   elf_linker_section_t sdata[2];
@@ -3172,9 +3314,6 @@ struct ppc_elf_link_hash_table
   /* The (unloaded but important) .rela.plt.unloaded on VxWorks.  */
   asection *srelplt2;
 
-  /* The .got.plt section (VxWorks only)*/
-  asection *sgotplt;
-
   /* Shortcut to __tls_get_addr.  */
   struct elf_link_hash_entry *tls_get_addr;
 
@@ -3201,6 +3340,14 @@ struct ppc_elf_link_hash_table
   /* True if the target system is VxWorks.  */
   unsigned int is_vxworks: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;
+
+  /* Set if tls optimization is enabled.  */
+  unsigned int do_tls_opt:1;
+
   /* The size of PLT entries.  */
   int plt_entry_size;
   /* The distance between adjacent PLT slots.  */
@@ -3263,7 +3410,8 @@ static struct bfd_link_hash_table *
 ppc_elf_link_hash_table_create (bfd *abfd)
 {
   struct ppc_elf_link_hash_table *ret;
-  static struct ppc_elf_params default_params = { PLT_OLD, 0, 1, 0, 0, 12, 0 };
+  static struct ppc_elf_params default_params
+    = { PLT_OLD, 0, 1, 0, 0, 12, 0, 0, 0 };
 
   ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
   if (ret == NULL)
@@ -3309,6 +3457,7 @@ ppc_elf_link_params (struct bfd_link_info *info, struct ppc_elf_params *params)
 
   if (htab)
     htab->params = params;
+  params->pagesize_p2 = bfd_log2 (params->pagesize);
 }
 
 /* Create .got and the related sections.  */
@@ -3317,37 +3466,21 @@ static bfd_boolean
 ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info)
 {
   struct ppc_elf_link_hash_table *htab;
-  asection *s;
-  flagword flags;
 
   if (!_bfd_elf_create_got_section (abfd, info))
     return FALSE;
 
   htab = ppc_elf_hash_table (info);
-  htab->got = s = bfd_get_linker_section (abfd, ".got");
-  if (s == NULL)
-    abort ();
-
-  if (htab->is_vxworks)
-    {
-      htab->sgotplt = bfd_get_linker_section (abfd, ".got.plt");
-      if (!htab->sgotplt)
-       abort ();
-    }
-  else
+  if (!htab->is_vxworks)
     {
       /* The powerpc .got has a blrl instruction in it.  Mark it
         executable.  */
-      flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS
-              | SEC_IN_MEMORY | SEC_LINKER_CREATED);
-      if (!bfd_set_section_flags (abfd, s, flags))
+      flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS
+                       | SEC_IN_MEMORY | SEC_LINKER_CREATED);
+      if (!bfd_set_section_flags (abfd, htab->elf.sgot, flags))
        return FALSE;
     }
 
-  htab->relgot = bfd_get_linker_section (abfd, ".rela.got");
-  if (!htab->relgot)
-    abort ();
-
   return TRUE;
 }
 
@@ -3410,7 +3543,7 @@ ppc_elf_create_glink (bfd *abfd, struct bfd_link_info *info)
 
   flags = SEC_ALLOC | SEC_LINKER_CREATED;
   s = bfd_make_section_anyway_with_flags (abfd, ".iplt", flags);
-  htab->iplt = s;
+  htab->elf.iplt = s;
   if (s == NULL
       || !bfd_set_section_alignment (abfd, s, 4))
     return FALSE;
@@ -3418,7 +3551,7 @@ ppc_elf_create_glink (bfd *abfd, struct bfd_link_info *info)
   flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
           | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   s = bfd_make_section_anyway_with_flags (abfd, ".rela.iplt", flags);
-  htab->reliplt = s;
+  htab->elf.irelplt = s;
   if (s == NULL
       || ! bfd_set_section_alignment (abfd, s, 2))
     return FALSE;
@@ -3447,7 +3580,7 @@ ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
 
   htab = ppc_elf_hash_table (info);
 
-  if (htab->got == NULL
+  if (htab->elf.sgot == NULL
       && !ppc_elf_create_got (abfd, info))
     return FALSE;
 
@@ -3458,16 +3591,14 @@ ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
       && !ppc_elf_create_glink (abfd, info))
     return FALSE;
 
-  htab->dynbss = bfd_get_linker_section (abfd, ".dynbss");
   s = bfd_make_section_anyway_with_flags (abfd, ".dynsbss",
                                          SEC_ALLOC | SEC_LINKER_CREATED);
   htab->dynsbss = s;
   if (s == NULL)
     return FALSE;
 
-  if (! info->shared)
+  if (! bfd_link_pic (info))
     {
-      htab->relbss = bfd_get_linker_section (abfd, ".rela.bss");
       flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
               | SEC_IN_MEMORY | SEC_LINKER_CREATED);
       s = bfd_make_section_anyway_with_flags (abfd, ".rela.sbss", flags);
@@ -3481,11 +3612,7 @@ ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
       && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
     return FALSE;
 
-  htab->relplt = bfd_get_linker_section (abfd, ".rela.plt");
-  htab->plt = s = bfd_get_linker_section (abfd, ".plt");
-  if (s == NULL)
-    abort ();
-
+  s = htab->elf.splt;
   flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED;
   if (htab->plt_type == PLT_VXWORKS)
     /* The VxWorks PLT is a loaded section with contents.  */
@@ -3516,7 +3643,8 @@ ppc_elf_copy_indirect_symbol (struct bfd_link_info *info,
        && edir->elf.dynamic_adjusted))
     edir->elf.non_got_ref |= eind->elf.non_got_ref;
 
-  edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
+  if (edir->elf.versioned != versioned_hidden)
+    edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
   edir->elf.ref_regular |= eind->elf.ref_regular;
   edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
   edir->elf.needs_plt |= eind->elf.needs_plt;
@@ -3622,7 +3750,7 @@ ppc_elf_add_symbol_hook (bfd *abfd,
                         bfd_vma *valp)
 {
   if (sym->st_shndx == SHN_COMMON
-      && !info->relocatable
+      && !bfd_link_relocatable (info)
       && is_ppc_elf (info->output_bfd)
       && sym->st_size <= elf_gp_size (abfd))
     {
@@ -3649,11 +3777,10 @@ ppc_elf_add_symbol_hook (bfd *abfd,
       *valp = sym->st_size;
     }
 
-  if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
-       || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
+  if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
       && (abfd->flags & DYNAMIC) == 0
       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
+    elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
 
   return TRUE;
 }
@@ -3845,13 +3972,15 @@ is_branch_reloc (enum elf_ppc_reloc_type r_type)
          || r_type == R_PPC_ADDR24
          || r_type == R_PPC_ADDR14
          || r_type == R_PPC_ADDR14_BRTAKEN
-         || r_type == R_PPC_ADDR14_BRNTAKEN);
+         || r_type == R_PPC_ADDR14_BRNTAKEN
+         || r_type == R_PPC_VLE_REL24);
 }
 
 static void
 bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type)
 {
-  (*_bfd_error_handler)
+  _bfd_error_handler
+    /* xgettext:c-format */
     (_("%B: relocation %s cannot be used when making a shared object"),
      abfd,
      ppc_elf_howto_table[r_type]->name);
@@ -3876,7 +4005,7 @@ ppc_elf_check_relocs (bfd *abfd,
   asection *got2, *sreloc;
   struct elf_link_hash_entry *tga;
 
-  if (info->relocatable)
+  if (bfd_link_relocatable (info))
     return TRUE;
 
   /* Don't do anything special with non-loaded, non-alloced sections.
@@ -3921,6 +4050,7 @@ ppc_elf_check_relocs (bfd *abfd,
       enum elf_ppc_reloc_type r_type;
       struct elf_link_hash_entry *h;
       int tls_type;
+      struct plt_entry **ifunc;
 
       r_symndx = ELF32_R_SYM (rel->r_info);
       if (r_symndx < symtab_hdr->sh_info)
@@ -3934,14 +4064,14 @@ ppc_elf_check_relocs (bfd *abfd,
 
          /* PR15323, ref flags aren't set for references in the same
             object.  */
-         h->root.non_ir_ref = 1;
+         h->root.non_ir_ref_regular = 1;
        }
 
       /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
         This shows up in particular in an R_PPC_ADDR32 in the eabi
         startup code.  */
       if (h != NULL
-         && htab->got == NULL
+         && htab->elf.sgot == NULL
          && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
        {
          if (htab->elf.dynobj == NULL)
@@ -3953,6 +4083,7 @@ ppc_elf_check_relocs (bfd *abfd,
 
       tls_type = 0;
       r_type = ELF32_R_TYPE (rel->r_info);
+      ifunc = NULL;
       if (h == NULL && !htab->is_vxworks)
        {
          Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
@@ -3962,8 +4093,6 @@ ppc_elf_check_relocs (bfd *abfd,
 
          if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
            {
-             struct plt_entry **ifunc;
-
              /* Set PLT_IFUNC flag for this sym, no GOT entry yet.  */
              ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
                                             PLT_IFUNC);
@@ -3973,14 +4102,14 @@ ppc_elf_check_relocs (bfd *abfd,
              /* STT_GNU_IFUNC symbols must have a PLT entry;
                 In a non-pie executable even when there are
                 no plt calls.  */
-             if (!info->shared
+             if (!bfd_link_pic (info)
                  || is_branch_reloc (r_type))
                {
                  bfd_vma addend = 0;
                  if (r_type == R_PPC_PLTREL24)
                    {
                      ppc_elf_tdata (abfd)->makes_plt_call = 1;
-                     if (info->shared)
+                     if (bfd_link_pic (info))
                        addend = rel->r_addend;
                    }
                  if (!update_plt_info (abfd, ifunc, got2, addend))
@@ -4031,7 +4160,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_GOT_TPREL16_LO:
        case R_PPC_GOT_TPREL16_HI:
        case R_PPC_GOT_TPREL16_HA:
-         if (info->shared)
+         if (bfd_link_dll (info))
            info->flags |= DF_STATIC_TLS;
          tls_type = TLS_TLS | TLS_TPREL;
          goto dogottls;
@@ -4043,7 +4172,7 @@ ppc_elf_check_relocs (bfd *abfd,
          tls_type = TLS_TLS | TLS_DTPREL;
        dogottls:
          sec->has_tls_reloc = 1;
-         /* Fall thru */
+         /* Fall through.  */
 
          /* GOT16 relocations */
        case R_PPC_GOT16:
@@ -4051,7 +4180,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_GOT16_HI:
        case R_PPC_GOT16_HA:
          /* This symbol requires a global offset table entry.  */
-         if (htab->got == NULL)
+         if (htab->elf.sgot == NULL)
            {
              if (htab->elf.dynobj == NULL)
                htab->elf.dynobj = abfd;
@@ -4070,7 +4199,7 @@ ppc_elf_check_relocs (bfd *abfd,
 
          /* We may also need a plt entry if the symbol turns out to be
             an ifunc.  */
-         if (h != NULL && !info->shared)
+         if (h != NULL && !bfd_link_pic (info))
            {
              if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
                return FALSE;
@@ -4079,7 +4208,7 @@ ppc_elf_check_relocs (bfd *abfd,
 
          /* Indirect .sdata relocation.  */
        case R_PPC_EMB_SDAI16:
-         if (info->shared)
+         if (bfd_link_pic (info))
            {
              bad_shared_reloc (abfd, r_type);
              return FALSE;
@@ -4097,7 +4226,7 @@ ppc_elf_check_relocs (bfd *abfd,
 
          /* Indirect .sdata2 relocation.  */
        case R_PPC_EMB_SDA2I16:
-         if (info->shared)
+         if (bfd_link_pic (info))
            {
              bad_shared_reloc (abfd, r_type);
              return FALSE;
@@ -4115,7 +4244,7 @@ ppc_elf_check_relocs (bfd *abfd,
 
        case R_PPC_SDAREL16:
          htab->sdata[0].sym->ref_regular = 1;
-         /* Fall thru */
+         /* Fall through.  */
 
        case R_PPC_VLE_SDAREL_LO16A:
        case R_PPC_VLE_SDAREL_LO16D:
@@ -4142,7 +4271,7 @@ ppc_elf_check_relocs (bfd *abfd,
          break;
 
        case R_PPC_EMB_SDA2REL:
-         if (info->shared)
+         if (bfd_link_pic (info))
            {
              bad_shared_reloc (abfd, r_type);
              return FALSE;
@@ -4159,7 +4288,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_VLE_SDA21:
        case R_PPC_EMB_SDA21:
        case R_PPC_EMB_RELSDA:
-         if (info->shared)
+         if (bfd_link_pic (info))
            {
              bad_shared_reloc (abfd, r_type);
              return FALSE;
@@ -4176,7 +4305,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_EMB_NADDR16_LO:
        case R_PPC_EMB_NADDR16_HI:
        case R_PPC_EMB_NADDR16_HA:
-         if (info->shared)
+         if (bfd_link_pic (info))
            {
              bad_shared_reloc (abfd, r_type);
              return FALSE;
@@ -4197,21 +4326,21 @@ ppc_elf_check_relocs (bfd *abfd,
 #ifdef DEBUG
          fprintf (stderr, "Reloc requires a PLT entry\n");
 #endif
-         /* This symbol requires a procedure linkage table entry.  We
-            actually build the entry in finish_dynamic_symbol,
-            because this might be a case of linking PIC code without
-            linking in any dynamic objects, in which case we don't
-            need to generate a procedure linkage table after all.  */
-
+         /* This symbol requires a procedure linkage table entry.  */
          if (h == NULL)
            {
-             /* It does not make sense to have a procedure linkage
-                table entry for a local symbol.  */
-             info->callbacks->einfo (_("%P: %H: %s reloc against local symbol\n"),
-                                     abfd, sec, rel->r_offset,
-                                     ppc_elf_howto_table[r_type]->name);
-             bfd_set_error (bfd_error_bad_value);
-             return FALSE;
+             if (ifunc == NULL)
+               {
+                 /* It does not make sense to have a procedure linkage
+                    table entry for a non-ifunc local symbol.  */
+                 info->callbacks->einfo
+                   /* xgettext:c-format */
+                   (_("%H: %s reloc against local symbol\n"),
+                    abfd, sec, rel->r_offset,
+                    ppc_elf_howto_table[r_type]->name);
+                 bfd_set_error (bfd_error_bad_value);
+                 return FALSE;
+               }
            }
          else
            {
@@ -4220,7 +4349,7 @@ ppc_elf_check_relocs (bfd *abfd,
              if (r_type == R_PPC_PLTREL24)
                {
                  ppc_elf_tdata (abfd)->makes_plt_call = 1;
-                 if (info->shared)
+                 if (bfd_link_pic (info))
                    addend = rel->r_addend;
                }
              h->needs_plt = 1;
@@ -4247,6 +4376,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_REL16_LO:
        case R_PPC_REL16_HI:
        case R_PPC_REL16_HA:
+       case R_PPC_REL16DX_HA:
          ppc_elf_tdata (abfd)->has_rel16 = 1;
          break;
 
@@ -4258,6 +4388,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_RELAX:
        case R_PPC_RELAX_PLT:
        case R_PPC_RELAX_PLTREL24:
+       case R_PPC_16DX_HA:
          break;
 
          /* These should only appear in dynamic objects.  */
@@ -4286,14 +4417,6 @@ ppc_elf_check_relocs (bfd *abfd,
            }
          if (h != NULL && h->type == STT_GNU_IFUNC)
            {
-             if (info->shared)
-               {
-                 info->callbacks->einfo (_("%P: %H: @local call to ifunc %s\n"),
-                                         abfd, sec, rel->r_offset,
-                                         h->root.root.string);
-                 bfd_set_error (bfd_error_bad_value);
-                 return FALSE;
-               }
              h->needs_plt = 1;
              if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
                return FALSE;
@@ -4316,13 +4439,13 @@ ppc_elf_check_relocs (bfd *abfd,
            return FALSE;
          break;
 
-         /* We shouldn't really be seeing these.  */
+         /* We shouldn't really be seeing TPREL32.  */
        case R_PPC_TPREL32:
        case R_PPC_TPREL16:
        case R_PPC_TPREL16_LO:
        case R_PPC_TPREL16_HI:
        case R_PPC_TPREL16_HA:
-         if (info->shared)
+         if (bfd_link_dll (info))
            info->flags |= DF_STATIC_TLS;
          goto dodyn;
 
@@ -4335,7 +4458,7 @@ ppc_elf_check_relocs (bfd *abfd,
          if (h == NULL
              && got2 != NULL
              && (sec->flags & SEC_CODE) != 0
-             && info->shared
+             && bfd_link_pic (info)
              && htab->plt_type == PLT_UNSET)
            {
              /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
@@ -4370,7 +4493,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_ADDR16_HA:
        case R_PPC_UADDR32:
        case R_PPC_UADDR16:
-         if (h != NULL && !info->shared)
+         if (h != NULL && !bfd_link_pic (info))
            {
              /* We may need a plt entry if the symbol turns out to be
                 a function defined in a dynamic object.  */
@@ -4408,7 +4531,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_ADDR14:
        case R_PPC_ADDR14_BRTAKEN:
        case R_PPC_ADDR14_BRNTAKEN:
-         if (h != NULL && !info->shared)
+         if (h != NULL && !bfd_link_pic (info))
            {
              /* We may need a plt entry if the symbol turns out to be
                 a function defined in a dynamic object.  */
@@ -4440,14 +4563,14 @@ ppc_elf_check_relocs (bfd *abfd,
             may need to keep relocations for symbols satisfied by a
             dynamic library if we manage to avoid copy relocs for the
             symbol.  */
-         if ((info->shared
+         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
-                 && !info->shared
+                 && !bfd_link_pic (info)
                  && h != NULL
                  && (h->root.type == bfd_link_hash_defweak
                      || !h->def_regular)))
@@ -4544,68 +4667,98 @@ ppc_elf_check_relocs (bfd *abfd,
   return TRUE;
 }
 \f
-
-/* Merge object attributes from IBFD into OBFD.  Raise an error if
-   there are conflicting attributes.  */
-static bfd_boolean
-ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
+/* Warn for conflicting Tag_GNU_Power_ABI_FP attributes between IBFD
+   and OBFD, and merge non-conflicting ones.  */
+void
+_bfd_elf_ppc_merge_fp_attributes (bfd *ibfd, struct bfd_link_info *info)
 {
+  bfd *obfd = info->output_bfd;
   obj_attribute *in_attr, *in_attrs;
   obj_attribute *out_attr, *out_attrs;
 
-  if (!elf_known_obj_attributes_proc (obfd)[0].i)
-    {
-      /* This is the first object.  Copy the attributes.  */
-      _bfd_elf_copy_obj_attributes (ibfd, obfd);
-
-      /* Use the Tag_null value to indicate the attributes have been
-        initialized.  */
-      elf_known_obj_attributes_proc (obfd)[0].i = 1;
-
-      return TRUE;
-    }
-
   in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
   out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
 
-  /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge
-     non-conflicting ones.  */
   in_attr = &in_attrs[Tag_GNU_Power_ABI_FP];
   out_attr = &out_attrs[Tag_GNU_Power_ABI_FP];
+
   if (in_attr->i != out_attr->i)
     {
-      out_attr->type = 1;
-      if (out_attr->i == 0)
-       out_attr->i = in_attr->i;
-      else if (in_attr->i == 0)
+      int in_fp = in_attr->i & 3;
+      int out_fp = out_attr->i & 3;
+
+      if (in_fp == 0)
        ;
-      else if (out_attr->i == 1 && in_attr->i == 2)
+      else if (out_fp == 0)
+       {
+         out_attr->type = 1;
+         out_attr->i ^= in_fp;
+       }
+      else if (out_fp != 2 && in_fp == 2)
        _bfd_error_handler
+         /* xgettext:c-format */
          (_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd);
-      else if (out_attr->i == 1 && in_attr->i == 3)
+      else if (out_fp == 2 && in_fp != 2)
        _bfd_error_handler
-         (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
-         obfd, ibfd);
-      else if (out_attr->i == 3 && in_attr->i == 1)
+         /* xgettext:c-format */
+         (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd);
+      else if (out_fp == 1 && in_fp == 3)
        _bfd_error_handler
-         (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
-         ibfd, obfd);
-      else if (out_attr->i == 3 && in_attr->i == 2)
+         /* xgettext:c-format */
+         (_("Warning: %B uses double-precision hard float, "
+            "%B uses single-precision hard float"), obfd, ibfd);
+      else if (out_fp == 3 && in_fp == 1)
        _bfd_error_handler
-         (_("Warning: %B uses soft float, %B uses single-precision hard float"),
-         ibfd, obfd);
-      else if (out_attr->i == 2 && (in_attr->i == 1 || in_attr->i == 3))
+         /* xgettext:c-format */
+         (_("Warning: %B uses double-precision hard float, "
+            "%B uses single-precision hard float"), ibfd, obfd);
+
+      in_fp = in_attr->i & 0xc;
+      out_fp = out_attr->i & 0xc;
+      if (in_fp == 0)
+       ;
+      else if (out_fp == 0)
+       {
+         out_attr->type = 1;
+         out_attr->i ^= in_fp;
+       }
+      else if (out_fp != 2 * 4 && in_fp == 2 * 4)
        _bfd_error_handler
-         (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd);
-      else if (in_attr->i > 3)
+         /* xgettext:c-format */
+         (_("Warning: %B uses 64-bit long double, "
+            "%B uses 128-bit long double"), ibfd, obfd);
+      else if (in_fp != 2 * 4 && out_fp == 2 * 4)
        _bfd_error_handler
-         (_("Warning: %B uses unknown floating point ABI %d"), ibfd,
-          in_attr->i);
-      else
+         /* xgettext:c-format */
+         (_("Warning: %B uses 64-bit long double, "
+            "%B uses 128-bit long double"), obfd, ibfd);
+      else if (out_fp == 1 * 4 && in_fp == 3 * 4)
        _bfd_error_handler
-         (_("Warning: %B uses unknown floating point ABI %d"), obfd,
-          out_attr->i);
+         /* xgettext:c-format */
+         (_("Warning: %B uses IBM long double, "
+            "%B uses IEEE long double"), ibfd, obfd);
+      else if (out_fp == 3 * 4 && in_fp == 1 * 4)
+       _bfd_error_handler
+         /* xgettext:c-format */
+         (_("Warning: %B uses IBM long double, "
+            "%B uses IEEE long double"), obfd, ibfd);
     }
+}
+
+/* Merge object attributes from IBFD into OBFD.  Warn if
+   there are conflicting attributes.  */
+static bfd_boolean
+ppc_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info)
+{
+  bfd *obfd;
+  obj_attribute *in_attr, *in_attrs;
+  obj_attribute *out_attr, *out_attrs;
+
+  _bfd_elf_ppc_merge_fp_attributes (ibfd, info);
+
+  obfd = info->output_bfd;
+  in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
+  out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
 
   /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and
      merge non-conflicting ones.  */
@@ -4613,48 +4766,38 @@ ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
   out_attr = &out_attrs[Tag_GNU_Power_ABI_Vector];
   if (in_attr->i != out_attr->i)
     {
-      const char *in_abi = NULL, *out_abi = NULL;
+      int in_vec = in_attr->i & 3;
+      int out_vec = out_attr->i & 3;
 
-      switch (in_attr->i)
-       {
-       case 1: in_abi = "generic"; break;
-       case 2: in_abi = "AltiVec"; break;
-       case 3: in_abi = "SPE"; break;
-       }
-
-      switch (out_attr->i)
+      if (in_vec == 0)
+       ;
+      else if (out_vec == 0)
        {
-       case 1: out_abi = "generic"; break;
-       case 2: out_abi = "AltiVec"; break;
-       case 3: out_abi = "SPE"; break;
+         out_attr->type = 1;
+         out_attr->i = in_vec;
        }
-
-      out_attr->type = 1;
-      if (out_attr->i == 0)
-       out_attr->i = in_attr->i;
-      else if (in_attr->i == 0)
-       ;
       /* For now, allow generic to transition to AltiVec or SPE
         without a warning.  If GCC marked files with their stack
         alignment and used don't-care markings for files which are
         not affected by the vector ABI, we could warn about this
         case too.  */
-      else if (out_attr->i == 1)
-       out_attr->i = in_attr->i;
-      else if (in_attr->i == 1)
+      else if (in_vec == 1)
        ;
-      else if (in_abi == NULL)
-       _bfd_error_handler
-         (_("Warning: %B uses unknown vector ABI %d"), ibfd,
-          in_attr->i);
-      else if (out_abi == NULL)
+      else if (out_vec == 1)
+       {
+         out_attr->type = 1;
+         out_attr->i = in_vec;
+       }
+      else if (out_vec < in_vec)
        _bfd_error_handler
-         (_("Warning: %B uses unknown vector ABI %d"), obfd,
-          in_attr->i);
-      else
+         /* xgettext:c-format */
+         (_("Warning: %B uses AltiVec vector ABI, %B uses SPE vector ABI"),
+          obfd, ibfd);
+      else if (out_vec > in_vec)
        _bfd_error_handler
-         (_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""),
-          ibfd, obfd, in_abi, out_abi);
+         /* xgettext:c-format */
+         (_("Warning: %B uses AltiVec vector ABI, %B uses SPE vector ABI"),
+          ibfd, obfd);
     }
 
   /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes
@@ -4663,29 +4806,30 @@ ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
   out_attr = &out_attrs[Tag_GNU_Power_ABI_Struct_Return];
   if (in_attr->i != out_attr->i)
     {
-      out_attr->type = 1;
-      if (out_attr->i == 0)
-       out_attr->i = in_attr->i;
-      else if (in_attr->i == 0)
+      int in_struct = in_attr->i & 3;
+      int out_struct = out_attr->i & 3;
+
+      if (in_struct == 0 || in_struct == 3)
        ;
-      else if (out_attr->i == 1 && in_attr->i == 2)
-       _bfd_error_handler
-         (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd, ibfd);
-      else if (out_attr->i == 2 && in_attr->i == 1)
-       _bfd_error_handler
-         (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd, obfd);
-      else if (in_attr->i > 2)
-       _bfd_error_handler
-         (_("Warning: %B uses unknown small structure return convention %d"), ibfd,
-          in_attr->i);
-      else
-       _bfd_error_handler
-         (_("Warning: %B uses unknown small structure return convention %d"), obfd,
-          out_attr->i);
+      else if (out_struct == 0)
+       {
+         out_attr->type = 1;
+         out_attr->i = in_struct;
+       }
+      else if (out_struct < in_struct)
+       _bfd_error_handler
+         /* xgettext:c-format */
+         (_("Warning: %B uses r3/r4 for small structure returns, "
+            "%B uses memory"), obfd, ibfd);
+      else if (out_struct > in_struct)
+       _bfd_error_handler
+         /* xgettext:c-format */
+         (_("Warning: %B uses r3/r4 for small structure returns, "
+            "%B uses memory"), ibfd, obfd);
     }
 
   /* Merge Tag_compatibility attributes and any common GNU ones.  */
-  _bfd_elf_merge_object_attributes (ibfd, obfd);
+  _bfd_elf_merge_object_attributes (ibfd, info);
 
   return TRUE;
 }
@@ -4694,8 +4838,9 @@ ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
    object file when linking.  */
 
 static bfd_boolean
-ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
+ppc_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 {
+  bfd *obfd = info->output_bfd;
   flagword old_flags;
   flagword new_flags;
   bfd_boolean error;
@@ -4704,10 +4849,10 @@ ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
     return TRUE;
 
   /* Check if we have the same endianness.  */
-  if (! _bfd_generic_verify_endian_match (ibfd, obfd))
+  if (! _bfd_generic_verify_endian_match (ibfd, info))
     return FALSE;
 
-  if (!ppc_elf_merge_obj_attributes (ibfd, obfd))
+  if (!ppc_elf_merge_obj_attributes (ibfd, info))
     return FALSE;
 
   new_flags = elf_elfheader (ibfd)->e_flags;
@@ -4733,7 +4878,7 @@ ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
          && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
        {
          error = TRUE;
-         (*_bfd_error_handler)
+         _bfd_error_handler
            (_("%B: compiled with -mrelocatable and linked with "
               "modules compiled normally"), ibfd);
        }
@@ -4741,7 +4886,7 @@ ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
               && (old_flags & EF_PPC_RELOCATABLE) != 0)
        {
          error = TRUE;
-         (*_bfd_error_handler)
+         _bfd_error_handler
            (_("%B: compiled normally and linked with "
               "modules compiled with -mrelocatable"), ibfd);
        }
@@ -4768,10 +4913,11 @@ ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
       if (new_flags != old_flags)
        {
          error = TRUE;
-         (*_bfd_error_handler)
-           (_("%B: uses different e_flags (0x%lx) fields "
-              "than previous modules (0x%lx)"),
-            ibfd, (long) new_flags, (long) old_flags);
+         _bfd_error_handler
+           /* xgettext:c-format */
+           (_("%B: uses different e_flags (%#x) fields "
+              "than previous modules (%#x)"),
+            ibfd, new_flags, old_flags);
        }
 
       if (error)
@@ -4785,21 +4931,61 @@ ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
 }
 
 static void
-ppc_elf_vle_split16 (bfd *output_bfd, bfd_byte *loc,
+ppc_elf_vle_split16 (bfd *input_bfd,
+                    asection *input_section,
+                    unsigned long offset,
+                    bfd_byte *loc,
                     bfd_vma value,
-                    split16_format_type split16_format)
-
+                    split16_format_type split16_format,
+                    bfd_boolean fixup)
 {
-  unsigned int insn, top5;
-
-  insn = bfd_get_32 (output_bfd, loc);
+  unsigned int insn, opcode, top5;
+
+  insn = bfd_get_32 (input_bfd, loc);
+  opcode = insn & 0xfc00f800;
+  if (opcode == E_OR2I_INSN
+      || opcode == E_AND2I_DOT_INSN
+      || opcode == E_OR2IS_INSN
+      || opcode == E_LIS_INSN
+      || opcode == E_AND2IS_DOT_INSN)
+    {
+      if (split16_format != split16a_type)
+       {
+         if (fixup)
+           split16_format = split16a_type;
+         else
+           _bfd_error_handler
+             /* xgettext:c-format */
+             (_("%B(%A+0x%lx): expected 16A style relocation on 0x%08x insn"),
+              input_bfd, input_section, offset, opcode);
+       }
+    }
+  else if (opcode == E_ADD2I_DOT_INSN
+          || opcode == E_ADD2IS_INSN
+          || opcode == E_CMP16I_INSN
+          || opcode == E_MULL2I_INSN
+          || opcode == E_CMPL16I_INSN
+          || opcode == E_CMPH16I_INSN
+          || opcode == E_CMPHL16I_INSN)
+    {
+      if (split16_format != split16d_type)
+       {
+         if (fixup)
+           split16_format = split16d_type;
+         else
+           _bfd_error_handler
+             /* xgettext:c-format */
+             (_("%B(%A+0x%lx): expected 16D style relocation on 0x%08x insn"),
+              input_bfd, input_section, offset, opcode);
+       }
+    }
   top5 = value & 0xf800;
-  top5 = top5 << (split16_format == split16a_type ? 9 : 5);
+  top5 = top5 << (split16_format == split16a_type ? 5 : 10);
+  insn &= (split16_format == split16a_type ? ~0x1f07ff : ~0x3e007ff);
   insn |= top5;
   insn |= value & 0x7ff;
-  bfd_put_32 (output_bfd, insn, loc);
+  bfd_put_32 (input_bfd, insn, loc);
 }
-
 \f
 /* Choose which PLT scheme to use, and set .plt flags appropriately.
    Returns -1 on error, 0 for old PLT, 1 for new PLT.  */
@@ -4818,7 +5004,7 @@ ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
 
       if (htab->params->plt_style == PLT_OLD)
        htab->plt_type = PLT_OLD;
-      else if (info->shared
+      else if (bfd_link_pic (info)
               && htab->elf.dynamic_sections_created
               && (h = elf_link_hash_lookup (&htab->elf, "_mcount",
                                             FALSE, FALSE, TRUE)) != NULL
@@ -4826,8 +5012,7 @@ ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
                   || h->needs_plt)
               && h->ref_regular
               && !(SYMBOL_CALLS_LOCAL (info, h)
-                   || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
-                       && h->root.type == bfd_link_hash_undefweak)))
+                   || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)))
        {
          /* Profiling of shared libs (and pies) is not supported with
             secure plt, because ppc32 does profiling before a
@@ -4878,13 +5063,13 @@ ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
               | SEC_IN_MEMORY | SEC_LINKER_CREATED);
 
       /* The new PLT is a loaded section.  */
-      if (htab->plt != NULL
-         && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags))
+      if (htab->elf.splt != NULL
+         && !bfd_set_section_flags (htab->elf.dynobj, htab->elf.splt, flags))
        return -1;
 
       /* The new GOT is not executable.  */
-      if (htab->got != NULL
-         && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags))
+      if (htab->elf.sgot != NULL
+         && !bfd_set_section_flags (htab->elf.dynobj, htab->elf.sgot, flags))
        return -1;
     }
   else
@@ -4934,7 +5119,7 @@ ppc_elf_gc_sweep_hook (bfd *abfd,
   const Elf_Internal_Rela *rel, *relend;
   asection *got2;
 
-  if (info->relocatable)
+  if (bfd_link_relocatable (info))
     return TRUE;
 
   if ((sec->flags & SEC_ALLOC) == 0)
@@ -4980,7 +5165,7 @@ ppc_elf_gc_sweep_hook (bfd *abfd,
       if (!htab->is_vxworks
          && h == NULL
          && local_got_refcounts != NULL
-         && (!info->shared
+         && (!bfd_link_pic (info)
              || is_branch_reloc (r_type)))
        {
          struct plt_entry **local_plt = (struct plt_entry **)
@@ -4993,7 +5178,7 @@ ppc_elf_gc_sweep_hook (bfd *abfd,
              bfd_vma addend = 0;
              struct plt_entry *ent;
 
-             if (r_type == R_PPC_PLTREL24 && info->shared)
+             if (r_type == R_PPC_PLTREL24 && bfd_link_pic (info))
                addend = rel->r_addend;
              ent = find_plt_ent (ifunc, got2, addend);
              if (ent->plt.refcount > 0)
@@ -5028,7 +5213,7 @@ ppc_elf_gc_sweep_hook (bfd *abfd,
            {
              if (h->got.refcount > 0)
                h->got.refcount--;
-             if (!info->shared)
+             if (!bfd_link_pic (info))
                {
                  struct plt_entry *ent;
 
@@ -5051,7 +5236,7 @@ ppc_elf_gc_sweep_hook (bfd *abfd,
        case R_PPC_REL32:
          if (h == NULL || h == htab->elf.hgot)
            break;
-         /* Fall thru */
+         /* Fall through.  */
 
        case R_PPC_ADDR32:
        case R_PPC_ADDR24:
@@ -5064,8 +5249,9 @@ ppc_elf_gc_sweep_hook (bfd *abfd,
        case R_PPC_ADDR14_BRNTAKEN:
        case R_PPC_UADDR32:
        case R_PPC_UADDR16:
-         if (info->shared)
+         if (bfd_link_pic (info))
            break;
+         /* Fall through.  */
 
        case R_PPC_PLT32:
        case R_PPC_PLTREL24:
@@ -5078,7 +5264,7 @@ ppc_elf_gc_sweep_hook (bfd *abfd,
              bfd_vma addend = 0;
              struct plt_entry *ent;
 
-             if (r_type == R_PPC_PLTREL24 && info->shared)
+             if (r_type == R_PPC_PLTREL24 && bfd_link_pic (info))
                addend = rel->r_addend;
              ent = find_plt_ent (&h->plt.plist, got2, addend);
              if (ent != NULL && ent->plt.refcount > 0)
@@ -5126,8 +5312,7 @@ ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
              && (tga->type == STT_FUNC
                  || tga->needs_plt)
              && !(SYMBOL_CALLS_LOCAL (info, tga)
-                  || (ELF_ST_VISIBILITY (tga->other) != STV_DEFAULT
-                      && tga->root.type == bfd_link_hash_undefweak)))
+                  || UNDEFWEAK_NO_DYNAMIC_RELOC (info, tga)))
            {
              struct plt_entry *ent;
              for (ent = tga->plt.plist; ent != NULL; ent = ent->next)
@@ -5138,6 +5323,7 @@ ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
                  tga->root.type = bfd_link_hash_indirect;
                  tga->root.u.i.link = &opt->root;
                  ppc_elf_copy_indirect_symbol (info, opt, tga);
+                 opt->mark = 1;
                  if (opt->dynindx != -1)
                    {
                      /* Use __tls_get_addr_opt in dynamic relocations.  */
@@ -5155,11 +5341,11 @@ ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
        htab->params->no_tls_get_addr_opt = TRUE;
     }
   if (htab->plt_type == PLT_NEW
-      && htab->plt != NULL
-      && htab->plt->output_section != NULL)
+      && htab->elf.splt != NULL
+      && htab->elf.splt->output_section != NULL)
     {
-      elf_section_type (htab->plt->output_section) = SHT_PROGBITS;
-      elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE;
+      elf_section_type (htab->elf.splt->output_section) = SHT_PROGBITS;
+      elf_section_flags (htab->elf.splt->output_section) = SHF_ALLOC + SHF_WRITE;
     }
 
   return _bfd_elf_tls_setup (obfd, info);
@@ -5204,7 +5390,7 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
   struct ppc_elf_link_hash_table *htab;
   int pass;
 
-  if (info->relocatable || !info->executable)
+  if (!bfd_link_executable (info))
     return TRUE;
 
   htab = ppc_elf_hash_table (info);
@@ -5292,7 +5478,7 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
                    case R_PPC_GOT_TLSLD16:
                    case R_PPC_GOT_TLSLD16_LO:
                      expecting_tls_get_addr = 1;
-                     /* Fall thru */
+                     /* Fall through.  */
 
                    case R_PPC_GOT_TLSLD16_HI:
                    case R_PPC_GOT_TLSLD16_HA:
@@ -5310,7 +5496,7 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
                    case R_PPC_GOT_TLSGD16:
                    case R_PPC_GOT_TLSGD16_LO:
                      expecting_tls_get_addr = 1;
-                     /* Fall thru */
+                     /* Fall through.  */
 
                    case R_PPC_GOT_TLSGD16_HI:
                    case R_PPC_GOT_TLSGD16_HA:
@@ -5377,7 +5563,7 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
                      struct plt_entry *ent;
                      bfd_vma addend = 0;
 
-                     if (info->shared
+                     if (bfd_link_pic (info)
                          && ELF32_R_TYPE (rel[1].r_info) == R_PPC_PLTREL24)
                        addend = rel[1].r_addend;
                      ent = find_plt_ent (&htab->tls_get_addr->plt.plist,
@@ -5448,6 +5634,7 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
              symtab_hdr->contents = (unsigned char *) locsyms;
          }
       }
+  htab->do_tls_opt = 1;
   return TRUE;
 }
 \f
@@ -5512,8 +5699,7 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
       if (ent == NULL
          || (h->type != STT_GNU_IFUNC
              && (SYMBOL_CALLS_LOCAL (info, h)
-                 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
-                     && h->root.type == bfd_link_hash_undefweak))))
+                 || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))))
        {
          /* A PLT entry is not required/allowed when:
 
@@ -5534,33 +5720,24 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
          /* Taking a function's address in a read/write section
             doesn't require us to define the function symbol in the
             executable on a plt call stub.  A dynamic reloc can
-            be used instead.  */
-         if (h->pointer_equality_needed
-             && h->type != STT_GNU_IFUNC
+            be used instead, giving better runtime performance.
+            (Calls via that function pointer don't need to bounce
+            through the plt call stub.)  Similarly, use a dynamic
+            reloc for a weak reference when possible, allowing the
+            resolution of the symbol to be set at load time rather
+            than link time.  */
+         if ((h->pointer_equality_needed
+              || (!h->ref_regular_nonweak && h->non_got_ref))
              && !htab->is_vxworks
              && !ppc_elf_hash_entry (h)->has_sda_refs
              && !readonly_dynrelocs (h))
            {
              h->pointer_equality_needed = 0;
+             /* After adjust_dynamic_symbol, non_got_ref set in the
+                non-pic case means that dyn_relocs for this symbol
+                should be discarded.  */
              h->non_got_ref = 0;
            }
-
-         /* After adjust_dynamic_symbol, non_got_ref set in the
-            non-shared case means that we have allocated space in
-            .dynbss for the symbol and thus dyn_relocs for this
-            symbol should be discarded.
-            If we get here we know we are making a PLT entry for this
-            symbol, and in an executable we'd normally resolve
-            relocations against this symbol to the PLT entry.  Allow
-            dynamic relocs if the reference is weak, and the dynamic
-            relocs will not cause text relocation.  */
-         else if (!h->ref_regular_nonweak
-                  && h->non_got_ref
-                  && h->type != STT_GNU_IFUNC
-                  && !htab->is_vxworks
-                  && !ppc_elf_hash_entry (h)->has_sda_refs
-                  && !readonly_dynrelocs (h))
-           h->non_got_ref = 0;
        }
       h->protected_def = 0;
       return TRUE;
@@ -5589,7 +5766,7 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
      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 (info->shared)
+  if (bfd_link_pic (info))
     {
       h->protected_def = 0;
       return TRUE;
@@ -5657,8 +5834,10 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 
   if (ppc_elf_hash_entry (h)->has_sda_refs)
     s = htab->dynsbss;
+  else if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+    s = htab->elf.sdynrelro;
   else
-    s = htab->dynbss;
+    s = htab->elf.sdynbss;
   BFD_ASSERT (s != NULL);
 
   /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
@@ -5671,8 +5850,10 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 
       if (ppc_elf_hash_entry (h)->has_sda_refs)
        srel = htab->relsbss;
+      else if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+       srel = htab->elf.sreldynrelro;
       else
-       srel = htab->relbss;
+       srel = htab->elf.srelbss;
       BFD_ASSERT (srel != NULL);
       srel->size += sizeof (Elf32_External_Rela);
       h->needs_copy = 1;
@@ -5698,7 +5879,7 @@ add_stub_sym (struct plt_entry *ent,
   const char *stub;
   struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
 
-  if (info->shared)
+  if (bfd_link_pic (info))
     stub = ".plt_pic32.";
   else
     stub = ".plt_call32.";
@@ -5745,8 +5926,8 @@ allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
 
   if (htab->plt_type == PLT_VXWORKS)
     {
-      where = htab->got->size;
-      htab->got->size += need;
+      where = htab->elf.sgot->size;
+      htab->elf.sgot->size += need;
     }
   else
     {
@@ -5757,198 +5938,54 @@ allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
          htab->got_gap -= need;
        }
       else
-       {
-         if (htab->got->size + need > max_before_header
-             && htab->got->size <= max_before_header)
-           {
-             htab->got_gap = max_before_header - htab->got->size;
-             htab->got->size = max_before_header + htab->got_header_size;
-           }
-         where = htab->got->size;
-         htab->got->size += need;
-       }
-    }
-  return where;
-}
-
-/* Allocate space in associated reloc sections for dynamic relocs.  */
-
-static bfd_boolean
-allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
-{
-  struct bfd_link_info *info = inf;
-  struct ppc_elf_link_hash_entry *eh;
-  struct ppc_elf_link_hash_table *htab;
-  struct elf_dyn_relocs *p;
-
-  if (h->root.type == bfd_link_hash_indirect)
-    return TRUE;
-
-  htab = ppc_elf_hash_table (info);
-  if (htab->elf.dynamic_sections_created
-      || h->type == STT_GNU_IFUNC)
-    {
-      struct plt_entry *ent;
-      bfd_boolean doneone = FALSE;
-      bfd_vma plt_offset = 0, glink_offset = 0;
-      bfd_boolean dyn;
-
-      for (ent = h->plt.plist; ent != NULL; ent = ent->next)
-       if (ent->plt.refcount > 0)
-         {
-           /* Make sure this symbol is output as a dynamic symbol.  */
-           if (h->dynindx == -1
-               && !h->forced_local
-               && !h->def_regular
-               && htab->elf.dynamic_sections_created)
-             {
-               if (! bfd_elf_link_record_dynamic_symbol (info, h))
-                 return FALSE;
-             }
-
-           dyn = htab->elf.dynamic_sections_created;
-           if (info->shared
-               || h->type == STT_GNU_IFUNC
-               || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
-             {
-               asection *s = htab->plt;
-               if (!dyn || h->dynindx == -1)
-                 s = htab->iplt;
-
-               if (htab->plt_type == PLT_NEW || !dyn || h->dynindx == -1)
-                 {
-                   if (!doneone)
-                     {
-                       plt_offset = s->size;
-                       s->size += 4;
-                     }
-                   ent->plt.offset = plt_offset;
-
-                   s = htab->glink;
-                   if (!doneone || info->shared)
-                     {
-                       glink_offset = s->size;
-                       s->size += GLINK_ENTRY_SIZE;
-                       if (h == htab->tls_get_addr
-                           && !htab->params->no_tls_get_addr_opt)
-                         s->size += TLS_GET_ADDR_GLINK_SIZE - GLINK_ENTRY_SIZE;
-                     }
-                   if (!doneone
-                       && !info->shared
-                       && h->def_dynamic
-                       && !h->def_regular)
-                     {
-                       h->root.u.def.section = s;
-                       h->root.u.def.value = glink_offset;
-                     }
-                   ent->glink_offset = glink_offset;
-
-                   if (htab->params->emit_stub_syms
-                       && !add_stub_sym (ent, h, info))
-                     return FALSE;
-                 }
-               else
-                 {
-                   if (!doneone)
-                     {
-                       /* If this is the first .plt entry, make room
-                          for the special first entry.  */
-                       if (s->size == 0)
-                         s->size += htab->plt_initial_entry_size;
-
-                       /* The PowerPC PLT is actually composed of two
-                          parts, the first part is 2 words (for a load
-                          and a jump), and then there is a remaining
-                          word available at the end.  */
-                       plt_offset = (htab->plt_initial_entry_size
-                                     + (htab->plt_slot_size
-                                        * ((s->size
-                                            - htab->plt_initial_entry_size)
-                                           / htab->plt_entry_size)));
-
-                       /* If this symbol is not defined in a regular
-                          file, and we are not generating a shared
-                          library, then set the symbol to this location
-                          in the .plt.  This is to avoid text
-                          relocations, and is required to make
-                          function pointers compare as equal between
-                          the normal executable and the shared library.  */
-                       if (! info->shared
-                           && h->def_dynamic
-                           && !h->def_regular)
-                         {
-                           h->root.u.def.section = s;
-                           h->root.u.def.value = plt_offset;
-                         }
-
-                       /* Make room for this entry.  */
-                       s->size += htab->plt_entry_size;
-                       /* After the 8192nd entry, room for two entries
-                          is allocated.  */
-                       if (htab->plt_type == PLT_OLD
-                           && (s->size - htab->plt_initial_entry_size)
-                               / htab->plt_entry_size
-                              > PLT_NUM_SINGLE_ENTRIES)
-                         s->size += htab->plt_entry_size;
-                     }
-                   ent->plt.offset = plt_offset;
-                 }
-
-               /* We also need to make an entry in the .rela.plt section.  */
-               if (!doneone)
-                 {
-                   if (!htab->elf.dynamic_sections_created
-                       || h->dynindx == -1)
-                     htab->reliplt->size += sizeof (Elf32_External_Rela);
-                   else
-                     {
-                       htab->relplt->size += sizeof (Elf32_External_Rela);
-
-                       if (htab->plt_type == PLT_VXWORKS)
-                         {
-                           /* Allocate space for the unloaded relocations.  */
-                           if (!info->shared
-                               && htab->elf.dynamic_sections_created)
-                             {
-                               if (ent->plt.offset
-                                   == (bfd_vma) htab->plt_initial_entry_size)
-                                 {
-                                   htab->srelplt2->size
-                                     += (sizeof (Elf32_External_Rela)
-                                         * VXWORKS_PLTRESOLVE_RELOCS);
-                                 }
-
-                               htab->srelplt2->size
-                                 += (sizeof (Elf32_External_Rela)
-                                     * VXWORKS_PLT_NON_JMP_SLOT_RELOCS);
-                             }
-
-                           /* Every PLT entry has an associated GOT entry in
-                              .got.plt.  */
-                           htab->sgotplt->size += 4;
-                         }
-                     }
-                   doneone = TRUE;
-                 }
-             }
-           else
-             ent->plt.offset = (bfd_vma) -1;
-         }
-       else
-         ent->plt.offset = (bfd_vma) -1;
-
-      if (!doneone)
-       {
-         h->plt.plist = NULL;
-         h->needs_plt = 0;
-       }
-    }
-  else
-    {
-      h->plt.plist = NULL;
-      h->needs_plt = 0;
+       {
+         if (htab->elf.sgot->size + need > max_before_header
+             && htab->elf.sgot->size <= max_before_header)
+           {
+             htab->got_gap = max_before_header - htab->elf.sgot->size;
+             htab->elf.sgot->size = max_before_header + htab->got_header_size;
+           }
+         where = htab->elf.sgot->size;
+         htab->elf.sgot->size += need;
+       }
     }
+  return where;
+}
+
+/* If H is undefined, make it dynamic if that makes sense.  */
+
+static bfd_boolean
+ensure_undef_dynamic (struct bfd_link_info *info,
+                     struct elf_link_hash_entry *h)
+{
+  struct elf_link_hash_table *htab = elf_hash_table (info);
+
+  if (htab->dynamic_sections_created
+      && ((info->dynamic_undefined_weak != 0
+          && h->root.type == bfd_link_hash_undefweak)
+         || h->root.type == bfd_link_hash_undefined)
+      && h->dynindx == -1
+      && !h->forced_local
+      && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
+    return bfd_elf_link_record_dynamic_symbol (info, h);
+  return TRUE;
+}
+
+/* Allocate space in associated reloc sections for dynamic relocs.  */
+
+static bfd_boolean
+allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
+{
+  struct bfd_link_info *info = inf;
+  struct ppc_elf_link_hash_entry *eh;
+  struct ppc_elf_link_hash_table *htab;
+  struct elf_dyn_relocs *p;
+  bfd_boolean dyn;
+
+  if (h->root.type == bfd_link_hash_indirect)
+    return TRUE;
 
+  htab = ppc_elf_hash_table (info);
   eh = (struct ppc_elf_link_hash_entry *) h;
   if (eh->elf.got.refcount > 0
       || (ELIMINATE_COPY_RELOCS
@@ -5958,18 +5995,11 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
          && eh->has_addr16_lo
          && htab->params->pic_fixup > 0))
     {
-      bfd_boolean dyn;
       unsigned int need;
 
       /* Make sure this symbol is output as a dynamic symbol.  */
-      if (eh->elf.dynindx == -1
-         && !eh->elf.forced_local
-         && eh->elf.type != STT_GNU_IFUNC
-         && htab->elf.dynamic_sections_created)
-       {
-         if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
-           return FALSE;
-       }
+      if (!ensure_undef_dynamic (info, &eh->elf))
+       return FALSE;
 
       need = 0;
       if ((eh->tls_mask & TLS_TLS) != 0)
@@ -5998,16 +6028,16 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
       else
        {
          eh->elf.got.offset = allocate_got (htab, need);
-         dyn = htab->elf.dynamic_sections_created;
-         if ((info->shared
-              || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
-             && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
-                 || eh->elf.root.type != bfd_link_hash_undefweak))
+         if ((bfd_link_pic (info)
+              || (htab->elf.dynamic_sections_created
+                  && eh->elf.dynindx != -1
+                  && !SYMBOL_REFERENCES_LOCAL (info, &eh->elf)))
+             && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, &eh->elf))
            {
-             asection *rsec = htab->relgot;
+             asection *rsec = htab->elf.srelgot;
 
              if (eh->elf.type == STT_GNU_IFUNC)
-               rsec = htab->reliplt;
+               rsec = htab->elf.irelplt;
              /* All the entries we allocated need relocs.
                 Except LD only needs one.  */
              if ((eh->tls_mask & TLS_LD) != 0
@@ -6020,25 +6050,39 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   else
     eh->elf.got.offset = (bfd_vma) -1;
 
-  if (eh->dyn_relocs == NULL
-      || !htab->elf.dynamic_sections_created)
-    return TRUE;
+  /* If no dynamic sections we can't have dynamic relocs, except for
+     IFUNCs which are handled even in static executables.  */
+  if (!htab->elf.dynamic_sections_created
+      && h->type != STT_GNU_IFUNC)
+    eh->dyn_relocs = NULL;
+
+  if (eh->dyn_relocs == NULL)
+    ;
 
   /* In the shared -Bsymbolic case, discard space allocated for
      dynamic pc-relative relocs against symbols which turn out to be
      defined in regular objects.  For the normal shared case, discard
      space for relocs that have become local due to symbol visibility
      changes.  */
-
-  if (info->shared)
+  else if (bfd_link_pic (info))
     {
+      /* Discard relocs on undefined symbols that must be local.  */
+      if (h->root.type == bfd_link_hash_undefined
+         && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
+       eh->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;
+
       /* Relocs that use pc_count are those that appear on a call insn,
         or certain REL relocs (see must_be_dyn_reloc) that can be
         generated via assembly.  We want calls to protected symbols to
         resolve directly to the function rather than going via the plt.
         If people want function pointer comparisons to work as expected
         then they should avoid writing weird assembly.  */
-      if (SYMBOL_CALLS_LOCAL (info, h))
+      else if (SYMBOL_CALLS_LOCAL (info, h))
        {
          struct elf_dyn_relocs **pp;
 
@@ -6066,38 +6110,18 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
            }
        }
 
-      /* Discard relocs on undefined symbols that must be local.  */
-      if (eh->dyn_relocs != NULL
-         && h->root.type == bfd_link_hash_undefined
-         && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
-             || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
-       eh->dyn_relocs = NULL;
-
-      /* Also discard relocs on undefined weak syms with non-default
-        visibility.  */
-      if (eh->dyn_relocs != NULL
-         && h->root.type == bfd_link_hash_undefweak)
+      if (eh->dyn_relocs != NULL)
        {
-         if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
-           eh->dyn_relocs = NULL;
-
-         /* Make sure undefined weak symbols are output as a dynamic
-            symbol in PIEs.  */
-         else if (h->dynindx == -1
-                  && !h->forced_local
-                  && !h->def_regular)
-           {
-             if (! bfd_elf_link_record_dynamic_symbol (info, h))
-               return FALSE;
-           }
+         /* Make sure this symbol is output as a dynamic symbol.  */
+         if (!ensure_undef_dynamic (info, h))
+           return FALSE;
        }
     }
   else if (ELIMINATE_COPY_RELOCS)
     {
-      /* For the non-shared case, discard space for relocs against
+      /* For the non-pic case, discard space for relocs against
         symbols which turn out to need copy relocs or are not
         dynamic.  */
-
       if (!h->non_got_ref
          && !h->def_regular
          && !(h->protected_def
@@ -6105,35 +6129,172 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
               && eh->has_addr16_lo
               && htab->params->pic_fixup > 0))
        {
-         /* Make sure this symbol is output as a dynamic symbol.
-            Undefined weak syms won't yet be marked as dynamic.  */
-         if (h->dynindx == -1
-             && !h->forced_local)
-           {
-             if (! bfd_elf_link_record_dynamic_symbol (info, h))
-               return FALSE;
-           }
+         /* Make sure this symbol is output as a dynamic symbol.  */
+         if (!ensure_undef_dynamic (info, h))
+           return FALSE;
 
-         /* If that succeeded, we know we'll be keeping all the
-            relocs.  */
-         if (h->dynindx != -1)
-           goto keep;
+         if (h->dynindx == -1)
+           eh->dyn_relocs = NULL;
        }
-
-      eh->dyn_relocs = NULL;
-
-    keep: ;
+      else
+       eh->dyn_relocs = NULL;
     }
 
-  /* Finally, allocate space.  */
+  /* Allocate space.  */
   for (p = eh->dyn_relocs; p != NULL; p = p->next)
     {
       asection *sreloc = elf_section_data (p->sec)->sreloc;
       if (eh->elf.type == STT_GNU_IFUNC)
-       sreloc = htab->reliplt;
+       sreloc = htab->elf.irelplt;
       sreloc->size += p->count * sizeof (Elf32_External_Rela);
     }
 
+  /* Handle PLT relocs.  Done last, after dynindx has settled.  */
+  dyn = htab->elf.dynamic_sections_created && h->dynindx != -1;
+  if (dyn || h->type == STT_GNU_IFUNC)
+    {
+      struct plt_entry *ent;
+      bfd_boolean doneone = FALSE;
+      bfd_vma plt_offset = 0, glink_offset = 0;
+
+      for (ent = h->plt.plist; ent != NULL; ent = ent->next)
+       if (ent->plt.refcount > 0)
+         {
+           asection *s = htab->elf.splt;
+
+           if (!dyn)
+             s = htab->elf.iplt;
+
+           if (htab->plt_type == PLT_NEW || !dyn)
+             {
+               if (!doneone)
+                 {
+                   plt_offset = s->size;
+                   s->size += 4;
+                 }
+               ent->plt.offset = plt_offset;
+
+               s = htab->glink;
+               if (!doneone || bfd_link_pic (info))
+                 {
+                   glink_offset = s->size;
+                   s->size += GLINK_ENTRY_SIZE;
+                   if (h == htab->tls_get_addr
+                       && !htab->params->no_tls_get_addr_opt)
+                     s->size += TLS_GET_ADDR_GLINK_SIZE - GLINK_ENTRY_SIZE;
+                 }
+               if (!doneone
+                   && !bfd_link_pic (info)
+                   && h->def_dynamic
+                   && !h->def_regular)
+                 {
+                   h->root.u.def.section = s;
+                   h->root.u.def.value = glink_offset;
+                 }
+               ent->glink_offset = glink_offset;
+
+               if (htab->params->emit_stub_syms
+                   && !add_stub_sym (ent, h, info))
+                 return FALSE;
+             }
+           else
+             {
+               if (!doneone)
+                 {
+                   /* If this is the first .plt entry, make room
+                      for the special first entry.  */
+                   if (s->size == 0)
+                     s->size += htab->plt_initial_entry_size;
+
+                   /* The PowerPC PLT is actually composed of two
+                      parts, the first part is 2 words (for a load
+                      and a jump), and then there is a remaining
+                      word available at the end.  */
+                   plt_offset = (htab->plt_initial_entry_size
+                                 + (htab->plt_slot_size
+                                    * ((s->size
+                                        - htab->plt_initial_entry_size)
+                                       / htab->plt_entry_size)));
+
+                   /* If this symbol is not defined in a regular
+                      file, and we are not generating a shared
+                      library, then set the symbol to this location
+                      in the .plt.  This is to avoid text
+                      relocations, and is required to make
+                      function pointers compare as equal between
+                      the normal executable and the shared library.  */
+                   if (! bfd_link_pic (info)
+                       && h->def_dynamic
+                       && !h->def_regular)
+                     {
+                       h->root.u.def.section = s;
+                       h->root.u.def.value = plt_offset;
+                     }
+
+                   /* Make room for this entry.  */
+                   s->size += htab->plt_entry_size;
+                   /* After the 8192nd entry, room for two entries
+                      is allocated.  */
+                   if (htab->plt_type == PLT_OLD
+                       && (s->size - htab->plt_initial_entry_size)
+                       / htab->plt_entry_size
+                       > PLT_NUM_SINGLE_ENTRIES)
+                     s->size += htab->plt_entry_size;
+                 }
+               ent->plt.offset = plt_offset;
+             }
+
+           /* We also need to make an entry in the .rela.plt section.  */
+           if (!doneone)
+             {
+               if (!dyn)
+                 htab->elf.irelplt->size += sizeof (Elf32_External_Rela);
+               else
+                 {
+                   htab->elf.srelplt->size += sizeof (Elf32_External_Rela);
+
+                   if (htab->plt_type == PLT_VXWORKS)
+                     {
+                       /* Allocate space for the unloaded relocations.  */
+                       if (!bfd_link_pic (info)
+                           && htab->elf.dynamic_sections_created)
+                         {
+                           if (ent->plt.offset
+                               == (bfd_vma) htab->plt_initial_entry_size)
+                             {
+                               htab->srelplt2->size
+                                 += (sizeof (Elf32_External_Rela)
+                                     * VXWORKS_PLTRESOLVE_RELOCS);
+                             }
+
+                           htab->srelplt2->size
+                             += (sizeof (Elf32_External_Rela)
+                                 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS);
+                         }
+
+                       /* Every PLT entry has an associated GOT entry in
+                          .got.plt.  */
+                       htab->elf.sgotplt->size += 4;
+                     }
+                 }
+               doneone = TRUE;
+             }
+         }
+       else
+         ent->plt.offset = (bfd_vma) -1;
+
+      if (!doneone)
+       {
+         h->plt.plist = NULL;
+         h->needs_plt = 0;
+       }
+    }
+  else
+    {
+      h->plt.plist = NULL;
+      h->needs_plt = 0;
+    }
+
   return TRUE;
 }
 
@@ -6191,7 +6352,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (info->executable)
+      if (bfd_link_executable (info) && !info->nointerp)
        {
          s = bfd_get_linker_section (htab->elf.dynobj, ".interp");
          BFD_ASSERT (s != NULL);
@@ -6248,7 +6409,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
                {
                  asection *sreloc = elf_section_data (p->sec)->sreloc;
                  if (p->ifunc)
-                   sreloc = htab->reliplt;
+                   sreloc = htab->elf.irelplt;
                  sreloc->size += p->count * sizeof (Elf32_External_Rela);
                  if ((p->sec->output_section->flags
                       & (SEC_READONLY | SEC_ALLOC))
@@ -6291,11 +6452,11 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
            else
              {
                *local_got = allocate_got (htab, need);
-               if (info->shared)
+               if (bfd_link_pic (info))
                  {
-                   asection *srel = htab->relgot;
+                   asection *srel = htab->elf.srelgot;
                    if ((*lgot_masks & PLT_IFUNC) != 0)
-                     srel = htab->reliplt;
+                     srel = htab->elf.irelplt;
                    srel->size += need * (sizeof (Elf32_External_Rela) / 4);
                  }
              }
@@ -6316,7 +6477,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
          for (ent = *local_plt; ent != NULL; ent = ent->next)
            if (ent->plt.refcount > 0)
              {
-               s = htab->iplt;
+               s = htab->elf.iplt;
 
                if (!doneone)
                  {
@@ -6326,7 +6487,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
                ent->plt.offset = plt_offset;
 
                s = htab->glink;
-               if (!doneone || info->shared)
+               if (!doneone || bfd_link_pic (info))
                  {
                    glink_offset = s->size;
                    s->size += GLINK_ENTRY_SIZE;
@@ -6335,7 +6496,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
 
                if (!doneone)
                  {
-                   htab->reliplt->size += sizeof (Elf32_External_Rela);
+                   htab->elf.irelplt->size += sizeof (Elf32_External_Rela);
                    doneone = TRUE;
                  }
              }
@@ -6350,13 +6511,13 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
   if (htab->tlsld_got.refcount > 0)
     {
       htab->tlsld_got.offset = allocate_got (htab, 8);
-      if (info->shared)
-       htab->relgot->size += sizeof (Elf32_External_Rela);
+      if (bfd_link_pic (info))
+       htab->elf.srelgot->size += sizeof (Elf32_External_Rela);
     }
   else
     htab->tlsld_got.offset = (bfd_vma) -1;
 
-  if (htab->got != NULL && htab->plt_type != PLT_VXWORKS)
+  if (htab->elf.sgot != NULL && htab->plt_type != PLT_VXWORKS)
     {
       unsigned int g_o_t = 32768;
 
@@ -6364,17 +6525,17 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
         for old plt/got the got size will be 0 to 32764 (not allocated),
         or 32780 to 65536 (header allocated).  For new plt/got, the
         corresponding ranges are 0 to 32768 and 32780 to 65536.  */
-      if (htab->got->size <= 32768)
+      if (htab->elf.sgot->size <= 32768)
        {
-         g_o_t = htab->got->size;
+         g_o_t = htab->elf.sgot->size;
          if (htab->plt_type == PLT_OLD)
            g_o_t += 4;
-         htab->got->size += htab->got_header_size;
+         htab->elf.sgot->size += htab->got_header_size;
        }
 
       htab->elf.hgot->root.u.def.value = g_o_t;
     }
-  if (info->shared)
+  if (bfd_link_pic (info))
     {
       struct elf_link_hash_entry *sda = htab->sdata[0].sym;
 
@@ -6397,7 +6558,9 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
       && htab->elf.dynamic_sections_created)
     {
       htab->glink_pltresolve = htab->glink->size;
-      /* Space for the branch table.  */
+      /* Space for the branch table.  ??? We don't need entries for
+        non-dynamic symbols in this table.  This case can arise with
+        static ifuncs or forced local ifuncs.  */
       htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4;
       /* Pad out to align the start of PLTresolve.  */
       htab->glink->size += -htab->glink->size & (htab->params->ppc476_workaround
@@ -6450,7 +6613,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
     {
       s = htab->glink_eh_frame;
       s->size = sizeof (glink_eh_frame_cie) + 20;
-      if (info->shared)
+      if (bfd_link_pic (info))
        {
          s->size += 4;
          if (htab->glink->size - GLINK_PLTRESOLVE + 8 >= 256)
@@ -6468,8 +6631,8 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
       if ((s->flags & SEC_LINKER_CREATED) == 0)
        continue;
 
-      if (s == htab->plt
-         || s == htab->got)
+      if (s == htab->elf.splt
+         || s == htab->elf.sgot)
        {
          /* We'd like to strip these sections if they aren't needed, but if
             we've exported dynamic symbols from them we must leave them.
@@ -6479,12 +6642,13 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
          /* Strip this section if we don't need it; see the
             comment below.  */
        }
-      else if (s == htab->iplt
+      else if (s == htab->elf.iplt
               || s == htab->glink
               || s == htab->glink_eh_frame
-              || s == htab->sgotplt
+              || s == htab->elf.sgotplt
               || s == htab->sbss
-              || s == htab->dynbss
+              || s == htab->elf.sdynbss
+              || s == htab->elf.sdynrelro
               || s == htab->dynsbss)
        {
          /* Strip these too.  */
@@ -6547,13 +6711,13 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
 #define add_dynamic_entry(TAG, VAL) \
   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
-      if (info->executable)
+      if (bfd_link_executable (info))
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
        }
 
-      if (htab->plt != NULL && htab->plt->size != 0)
+      if (htab->elf.splt != NULL && htab->elf.splt->size != 0)
        {
          if (!add_dynamic_entry (DT_PLTGOT, 0)
              || !add_dynamic_entry (DT_PLTRELSZ, 0)
@@ -6626,7 +6790,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
       /* Augmentation.  */
       p += 1;
 
-      if (info->shared
+      if (bfd_link_pic (info)
          && htab->elf.dynamic_sections_created)
        {
          bfd_vma adv = (htab->glink->size - GLINK_PLTRESOLVE + 8) >> 2;
@@ -6794,7 +6958,7 @@ ppc_elf_relax_section (bfd *abfd,
   /* We cannot represent the required PIC relocs in the output, so don't
      do anything.  The linker doesn't support mixing -shared and -r
      anyway.  */
-  if (link_info->relocatable && link_info->shared)
+  if (bfd_link_relocatable (link_info) && bfd_link_pic (link_info))
     return TRUE;
 
   htab = ppc_elf_hash_table (link_info);
@@ -6938,7 +7102,7 @@ ppc_elf_relax_section (bfd *abfd,
                       || h->root.type == bfd_link_hash_undefweak)
                {
                  tsec = bfd_und_section_ptr;
-                 toff = link_info->relocatable ? indx : 0;
+                 toff = bfd_link_relocatable (link_info) ? indx : 0;
                }
              else
                continue;
@@ -6946,8 +7110,7 @@ ppc_elf_relax_section (bfd *abfd,
              /* If this branch is to __tls_get_addr then we may later
                 optimise away the call.  We won't be needing a long-
                 branch stub in that case.  */
-             if (link_info->executable
-                 && !link_info->relocatable
+             if (bfd_link_executable (link_info)
                  && h == htab->tls_get_addr
                  && irel != internal_relocs)
                {
@@ -7038,7 +7201,7 @@ ppc_elf_relax_section (bfd *abfd,
              bfd_vma addend = 0;
              struct plt_entry *ent;
 
-             if (r_type == R_PPC_PLTREL24 && link_info->shared)
+             if (r_type == R_PPC_PLTREL24 && bfd_link_pic (link_info))
                addend = irel->r_addend;
              ent = find_plt_ent (plist, got2, addend);
              if (ent != NULL)
@@ -7053,7 +7216,7 @@ ppc_elf_relax_section (bfd *abfd,
                    }
                  else
                    {
-                     tsec = htab->plt;
+                     tsec = htab->elf.splt;
                      toff = ent->plt.offset;
                    }
                }
@@ -7104,7 +7267,7 @@ ppc_elf_relax_section (bfd *abfd,
            toff += irel->r_addend;
 
          /* Attempted -shared link of non-pic code loses.  */
-         if ((!link_info->relocatable
+         if ((!bfd_link_relocatable (link_info)
               && tsec == bfd_und_section_ptr)
              || tsec->output_section == NULL
              || (tsec->owner != NULL
@@ -7115,7 +7278,7 @@ ppc_elf_relax_section (bfd *abfd,
 
          /* If the branch is in range, no need to do anything.  */
          if (tsec != bfd_und_section_ptr
-             && (!link_info->relocatable
+             && (!bfd_link_relocatable (link_info)
                  /* A relocatable link may have sections moved during
                     final link, so do not presume they remain in range.  */
                  || tsec->output_section == isec->output_section))
@@ -7145,7 +7308,7 @@ ppc_elf_relax_section (bfd *abfd,
                   one.  We'll report an error later.  */
                continue;
 
-             if (link_info->shared)
+             if (bfd_link_pic (link_info))
                {
                  size = 4 * ARRAY_SIZE (shared_stub_entry);
                  insn_offset = 12;
@@ -7156,7 +7319,7 @@ ppc_elf_relax_section (bfd *abfd,
                  insn_offset = 0;
                }
              stub_rtype = R_PPC_RELAX;
-             if (tsec == htab->plt
+             if (tsec == htab->elf.splt
                  || tsec == htab->glink)
                {
                  stub_rtype = R_PPC_RELAX_PLT;
@@ -7240,7 +7403,7 @@ ppc_elf_relax_section (bfd *abfd,
   workaround_change = FALSE;
   newsize = trampoff;
   if (htab->params->ppc476_workaround
-      && (!link_info->relocatable
+      && (!bfd_link_relocatable (link_info)
          || isec->output_section->alignment_power >= htab->params->pagesize_p2))
     {
       bfd_vma addr, end_addr;
@@ -7448,7 +7611,7 @@ write_glink_stub (struct plt_entry *ent, asection *plt_sec, unsigned char *p,
         + plt_sec->output_section->vma
         + plt_sec->output_offset);
 
-  if (info->shared)
+  if (bfd_link_pic (info))
     {
       bfd_vma got = 0;
 
@@ -7605,7 +7768,9 @@ is_insn_ds_form (unsigned int insn)
 static bfd_boolean
 is_insn_dq_form (unsigned int insn)
 {
-  return (insn & (0x3f << 26)) == 56u << 26; /* lq */
+  return ((insn & (0x3f << 26)) == 56u << 26 /* lq */
+         || ((insn & (0x3f << 26)) == (61u << 26) /* lxv, stxv */
+             && (insn & 3) == 1));
 }
 
 /* The RELOCATE_SECTION function is called by the ELF backend linker
@@ -7651,12 +7816,13 @@ ppc_elf_relocate_section (bfd *output_bfd,
   struct elf_link_hash_entry **sym_hashes;
   struct ppc_elf_link_hash_table *htab;
   Elf_Internal_Rela *rel;
+  Elf_Internal_Rela *wrel;
   Elf_Internal_Rela *relend;
   Elf_Internal_Rela outrel;
   asection *got2;
   bfd_vma *local_got_offsets;
   bfd_boolean ret = TRUE;
-  bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
+  bfd_vma d_offset = (bfd_big_endian (input_bfd) ? 2 : 0);
   bfd_boolean is_vxworks_tls;
   unsigned int picfixup_size = 0;
   struct ppc_elf_relax_info *relax_info = NULL;
@@ -7666,7 +7832,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                      "%ld relocations%s",
                      input_bfd, input_section,
                      (long) input_section->reloc_count,
-                     (info->relocatable) ? " (relocatable)" : "");
+                     (bfd_link_relocatable (info)) ? " (relocatable)" : "");
 #endif
 
   got2 = bfd_get_section_by_name (input_bfd, ".got2");
@@ -7681,14 +7847,14 @@ ppc_elf_relocate_section (bfd *output_bfd,
   sym_hashes = elf_sym_hashes (input_bfd);
   /* We have to handle relocations in vxworks .tls_vars sections
      specially, because the dynamic loader is 'weird'.  */
-  is_vxworks_tls = (htab->is_vxworks && info->shared
+  is_vxworks_tls = (htab->is_vxworks && bfd_link_pic (info)
                    && !strcmp (input_section->output_section->name,
                                ".tls_vars"));
   if (input_section->sec_info_type == SEC_INFO_TYPE_TARGET)
     relax_info = elf_section_data (input_section)->sec_info;
-  rel = relocs;
+  rel = wrel = relocs;
   relend = relocs + input_section->reloc_count;
-  for (; rel < relend; rel++)
+  for (; rel < relend; wrel++, rel++)
     {
       enum elf_ppc_reloc_type r_type;
       bfd_vma addend;
@@ -7707,6 +7873,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
       struct plt_entry **ifunc;
       struct reloc_howto_struct alt_howto;
 
+    again:
       r_type = ELF32_R_TYPE (rel->r_info);
       sym = NULL;
       sec = NULL;
@@ -7743,11 +7910,25 @@ ppc_elf_relocate_section (bfd *output_bfd,
          howto = NULL;
          if (r_type < R_PPC_max)
            howto = ppc_elf_howto_table[r_type];
-         RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
-                                          rel, 1, relend, howto, 0, contents);
+
+         _bfd_clear_contents (howto, input_bfd, input_section,
+                              contents + rel->r_offset);
+         wrel->r_offset = rel->r_offset;
+         wrel->r_info = 0;
+         wrel->r_addend = 0;
+
+         /* For ld -r, remove relocations in debug sections against
+            sections defined in discarded sections.  Not done for
+            non-debug to preserve relocs in .eh_frame which the
+            eh_frame editing code expects to be present.  */
+         if (bfd_link_relocatable (info)
+             && (input_section->flags & SEC_DEBUGGING))
+           wrel--;
+
+         continue;
        }
 
-      if (info->relocatable)
+      if (bfd_link_relocatable (info))
        {
          if (got2 != NULL
              && r_type == R_PPC_PLTREL24
@@ -7760,7 +7941,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
          if (r_type != R_PPC_RELAX_PLT
              && r_type != R_PPC_RELAX_PLTREL24
              && r_type != R_PPC_RELAX)
-           continue;
+           goto copy_reloc;
        }
 
       /* TLS optimizations.  Replace instruction sequences and relocs
@@ -7803,10 +7984,12 @@ ppc_elf_relocate_section (bfd *output_bfd,
            {
              bfd_vma insn;
 
-             insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
+             insn = bfd_get_32 (input_bfd,
+                                contents + rel->r_offset - d_offset);
              insn &= 31 << 21;
              insn |= 0x3c020000;       /* addis 0,2,0 */
-             bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
+             bfd_put_32 (input_bfd, insn,
+                         contents + rel->r_offset - d_offset);
              r_type = R_PPC_TPREL16_HA;
              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
            }
@@ -7818,11 +8001,11 @@ ppc_elf_relocate_section (bfd *output_bfd,
            {
              bfd_vma insn;
 
-             insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
+             insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
              insn = _bfd_elf_ppc_at_tls_transform (insn, 2);
              if (insn == 0)
                abort ();
-             bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
+             bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
              r_type = R_PPC_TPREL16_LO;
              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
 
@@ -7850,7 +8033,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
              else
                {
                  rel->r_offset -= d_offset;
-                 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
+                 bfd_put_32 (input_bfd, NOP, contents + rel->r_offset);
                  r_type = R_PPC_NONE;
                }
              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
@@ -7887,7 +8070,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                 the destination reg.  It may be something other than
                 the usual r3, and moved to r3 before the call by
                 intervening code.  */
-             insn1 = bfd_get_32 (output_bfd,
+             insn1 = bfd_get_32 (input_bfd,
                                  contents + rel->r_offset - d_offset);
              if ((tls_mask & tls_gd) != 0)
                {
@@ -7898,7 +8081,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                    {
                      rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
                      insn2 = 0x7c631214;       /* add 3,3,2 */
-                     bfd_put_32 (output_bfd, insn2, contents + offset);
+                     bfd_put_32 (input_bfd, insn2, contents + offset);
                    }
                  r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
                            + R_PPC_GOT_TPREL16);
@@ -7933,17 +8116,16 @@ ppc_elf_relocate_section (bfd *output_bfd,
                      rel[1].r_offset = offset + d_offset;
                      rel[1].r_addend = rel->r_addend;
                      insn2 = 0x38630000;       /* addi 3,3,0 */
-                     bfd_put_32 (output_bfd, insn2, contents + offset);
+                     bfd_put_32 (input_bfd, insn2, contents + offset);
                    }
                }
-             bfd_put_32 (output_bfd, insn1,
+             bfd_put_32 (input_bfd, insn1,
                          contents + rel->r_offset - d_offset);
              if (tls_gd == 0)
                {
                  /* We changed the symbol on an LD reloc.  Start over
                     in order to get h, sym, sec etc. right.  */
-                 rel--;
-                 continue;
+                 goto again;
                }
            }
          break;
@@ -7968,7 +8150,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                  insn2 = 0x38630000;   /* addi 3,3,0 */
                }
              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
-             bfd_put_32 (output_bfd, insn2, contents + offset);
+             bfd_put_32 (input_bfd, insn2, contents + offset);
              /* Zap the reloc on the _tls_get_addr call too.  */
              BFD_ASSERT (offset == rel[1].r_offset);
              rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
@@ -7996,13 +8178,12 @@ ppc_elf_relocate_section (bfd *output_bfd,
              rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
              rel->r_offset += d_offset;
              insn2 = 0x38630000;       /* addi 3,3,0 */
-             bfd_put_32 (output_bfd, insn2,
+             bfd_put_32 (input_bfd, insn2,
                          contents + rel->r_offset - d_offset);
              /* Zap the reloc on the _tls_get_addr call too.  */
              BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset);
              rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
-             rel--;
-             continue;
+             goto again;
            }
          break;
        }
@@ -8018,7 +8199,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_ADDR14_BRTAKEN:
        case R_PPC_REL14_BRTAKEN:
          branch_bit = BRANCH_PREDICT_BIT;
-         /* Fall thru */
+         /* Fall through.  */
 
          /* Branch not taken prediction relocations.  */
        case R_PPC_ADDR14_BRNTAKEN:
@@ -8026,7 +8207,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
          {
            bfd_vma insn;
 
-           insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
+           insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
            insn &= ~BRANCH_PREDICT_BIT;
            insn |= branch_bit;
 
@@ -8038,7 +8219,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
            if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
              insn ^= BRANCH_PREDICT_BIT;
 
-           bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
+           bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
            break;
          }
        }
@@ -8057,7 +8238,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
          if (r_type == R_PPC_ADDR16_HA)
            {
-             insn = bfd_get_32 (output_bfd,
+             insn = bfd_get_32 (input_bfd,
                                 contents + rel->r_offset - d_offset);
              if ((insn & (0x3f << 26)) == (15u << 26)
                  && (insn & (0x1f << 16)) == 0 /* lis */)
@@ -8073,51 +8254,53 @@ ppc_elf_relocate_section (bfd *output_bfd,
                  off = (p - contents) - (rel->r_offset - d_offset);
                  if (off > 0x1fffffc || (off & 3) != 0)
                    info->callbacks->einfo
-                     (_("%P: %H: fixup branch overflow\n"),
+                     (_("%H: fixup branch overflow\n"),
                       input_bfd, input_section, rel->r_offset);
 
-                 bfd_put_32 (output_bfd, B | off,
+                 bfd_put_32 (input_bfd, B | off,
                              contents + rel->r_offset - d_offset);
-                 got_addr = (htab->got->output_section->vma
-                             + htab->got->output_offset
+                 got_addr = (htab->elf.sgot->output_section->vma
+                             + htab->elf.sgot->output_offset
                              + (h->got.offset & ~1));
-                 rel->r_info = ELF32_R_INFO (0, R_PPC_ADDR16_HA);
-                 rel->r_addend = got_addr;
-                 rel->r_offset = (p - contents) + d_offset;
+                 wrel->r_offset = (p - contents) + d_offset;
+                 wrel->r_info = ELF32_R_INFO (0, R_PPC_ADDR16_HA);
+                 wrel->r_addend = got_addr;
                  insn &= ~0xffff;
-                 insn |= ((unsigned int )(got_addr + 0x8000) >> 16) & 0xffff;
-                 bfd_put_32 (output_bfd, insn, p);
+                 insn |= ((unsigned int(got_addr + 0x8000) >> 16) & 0xffff;
+                 bfd_put_32 (input_bfd, insn, p);
 
                  /* Convert lis to lwz, loading address from GOT.  */
                  insn &= ~0xffff;
                  insn ^= (32u ^ 15u) << 26;
                  insn |= (insn & (0x1f << 21)) >> 5;
                  insn |= got_addr & 0xffff;
-                 bfd_put_32 (output_bfd, insn, p + 4);
+                 bfd_put_32 (input_bfd, insn, p + 4);
 
-                 bfd_put_32 (output_bfd, B | ((-4 - off) & 0x3ffffff), p + 8);
+                 bfd_put_32 (input_bfd, B | ((-4 - off) & 0x3ffffff), p + 8);
                  picfixup_size += 12;
 
                  /* Use one of the spare relocs, so --emit-relocs
                     output is reasonable.  */
                  memmove (rel + 1, rel, (relend - rel - 1) * sizeof (*rel));
-                 rel++;
+                 wrel++, rel++;
+                 rel->r_offset = wrel[-1].r_offset + 4;
                  rel->r_info = ELF32_R_INFO (0, R_PPC_ADDR16_LO);
-                 rel->r_offset += 4;
+                 rel->r_addend = wrel[-1].r_addend;
 
                  /* Continue on as if we had a got reloc, to output
                     dynamic reloc.  */
                  r_type = R_PPC_GOT16_LO;
                }
              else
-               info->callbacks->einfo
-                 (_("%P: %H: error: %s with unexpected instruction %x\n"),
+               _bfd_error_handler
+                 /* xgettext:c-format */
+                 (_("%B(%A+%#Lx): error: %s with unexpected instruction %#x"),
                   input_bfd, input_section, rel->r_offset,
                   "R_PPC_ADDR16_HA", insn);
            }
          else if (r_type == R_PPC_ADDR16_LO)
            {
-             insn = bfd_get_32 (output_bfd,
+             insn = bfd_get_32 (input_bfd,
                                 contents + rel->r_offset - d_offset);
              if ((insn & (0x3f << 26)) == 14u << 26    /* addi */
                  || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
@@ -8144,8 +8327,9 @@ ppc_elf_relocate_section (bfd *output_bfd,
                  rel->r_info = ELF32_R_INFO (0, r_type);
                }
              else
-               info->callbacks->einfo
-                 (_("%P: %H: error: %s with unexpected instruction %x\n"),
+               _bfd_error_handler
+                 /* xgettext:c-format */
+                 (_("%B(%A+%#Lx): error: %s with unexpected instruction %#x"),
                   input_bfd, input_section, rel->r_offset,
                   "R_PPC_ADDR16_LO", insn);
            }
@@ -8173,30 +8357,52 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
          ent = NULL;
          if (ifunc != NULL
-             && (!info->shared
+             && (!bfd_link_pic (info)
                  || is_branch_reloc (r_type)))
            {
              addend = 0;
-             if (r_type == R_PPC_PLTREL24 && info->shared)
+             if (r_type == R_PPC_PLTREL24 && bfd_link_pic (info))
                addend = rel->r_addend;
              ent = find_plt_ent (ifunc, got2, addend);
            }
          if (ent != NULL)
            {
+             if (bfd_link_pic (info)
+                 && ent->sec != got2
+                 && htab->plt_type != PLT_NEW
+                 && (!htab->elf.dynamic_sections_created
+                     || h == NULL
+                     || h->dynindx == -1))
+               {
+                 /* Uh oh, we are going to create a pic glink stub
+                    for an ifunc (here for h == NULL and later in
+                    finish_dynamic_symbol for h != NULL), and
+                    apparently are using code compiled with
+                    -mbss-plt.  The difficulty is that -mbss-plt code
+                    gives no indication via a magic PLTREL24 addend
+                    whether r30 is equal to _GLOBAL_OFFSET_TABLE_ or
+                    is pointing into a .got2 section (and how far
+                    into .got2).  */
+                   info->callbacks->einfo
+                     /* xgettext:c-format */
+                     (_("%X%H: unsupported bss-plt -fPIC ifunc %s\n"),
+                      input_bfd, input_section, rel->r_offset, sym_name);
+               }
              if (h == NULL && (ent->plt.offset & 1) == 0)
                {
                  Elf_Internal_Rela rela;
                  bfd_byte *loc;
 
-                 rela.r_offset = (htab->iplt->output_section->vma
-                                  + htab->iplt->output_offset
+                 rela.r_offset = (htab->elf.iplt->output_section->vma
+                                  + htab->elf.iplt->output_offset
                                   + ent->plt.offset);
                  rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
                  rela.r_addend = relocation;
-                 loc = htab->reliplt->contents;
-                 loc += (htab->reliplt->reloc_count++
+                 loc = htab->elf.irelplt->contents;
+                 loc += (htab->elf.irelplt->reloc_count++
                          * sizeof (Elf32_External_Rela));
                  bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
+                 htab->local_ifunc_resolver = 1;
 
                  ent->plt.offset |= 1;
                }
@@ -8204,7 +8410,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                {
                  unsigned char *p = ((unsigned char *) htab->glink->contents
                                      + ent->glink_offset);
-                 write_glink_stub (ent, htab->iplt, p, info);
+                 write_glink_stub (ent, htab->elf.iplt, p, info);
                  ent->glink_offset |= 1;
                }
 
@@ -8217,27 +8423,62 @@ ppc_elf_relocate_section (bfd *output_bfd,
                              + htab->glink->output_offset
                              + (ent->glink_offset & ~1));
              else
-               relocation = (htab->plt->output_section->vma
-                             + htab->plt->output_offset
+               relocation = (htab->elf.splt->output_section->vma
+                             + htab->elf.splt->output_offset
                              + ent->plt.offset);
            }
        }
 
       addend = rel->r_addend;
-      tls_type = 0;
       howto = NULL;
       if (r_type < R_PPC_max)
        howto = ppc_elf_howto_table[r_type];
+
+      switch (r_type)
+       {
+       default:
+         break;
+
+       case R_PPC_TPREL16_HA:
+         if (htab->do_tls_opt && relocation + addend + 0x8000 < 0x10000)
+           {
+             bfd_byte *p = contents + (rel->r_offset & ~3);
+             unsigned int insn = bfd_get_32 (input_bfd, p);
+             if ((insn & ((0x3f << 26) | 0x1f << 16))
+                 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
+               /* xgettext:c-format */
+               info->callbacks->minfo
+                 (_("%H: warning: %s unexpected insn %#x.\n"),
+                  input_bfd, input_section, rel->r_offset, howto->name, insn);
+             else
+               bfd_put_32 (input_bfd, NOP, p);
+           }
+         break;
+
+       case R_PPC_TPREL16_LO:
+         if (htab->do_tls_opt && relocation + addend + 0x8000 < 0x10000)
+           {
+             bfd_byte *p = contents + (rel->r_offset & ~3);
+             unsigned int insn = bfd_get_32 (input_bfd, p);
+             insn &= ~(0x1f << 16);
+             insn |= 2 << 16;
+             bfd_put_32 (input_bfd, insn, p);
+           }
+         break;
+       }
+
+      tls_type = 0;
       switch (r_type)
        {
        default:
          info->callbacks->einfo
+           /* xgettext:c-format */
            (_("%P: %B: unknown relocation type %d for symbol %s\n"),
             input_bfd, (int) r_type, sym_name);
 
          bfd_set_error (bfd_error_bad_value);
          ret = FALSE;
-         continue;
+         goto copy_reloc;
 
        case R_PPC_NONE:
        case R_PPC_TLS:
@@ -8246,7 +8487,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_EMB_MRKREF:
        case R_PPC_GNU_VTINHERIT:
        case R_PPC_GNU_VTENTRY:
-         continue;
+         goto copy_reloc;
 
          /* GOT16 relocations.  Like an ADDR16 using the symbol's
             address in the GOT as relocation value instead of the
@@ -8293,7 +8534,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
            bfd_vma *offp;
            unsigned long indx;
 
-           if (htab->got == NULL)
+           if (htab->elf.sgot == NULL)
              abort ();
 
            indx = 0;
@@ -8303,11 +8544,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
              offp = &htab->tlsld_got.offset;
            else if (h != NULL)
              {
-               bfd_boolean dyn;
-               dyn = htab->elf.dynamic_sections_created;
-               if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
-                   || (info->shared
-                       && SYMBOL_REFERENCES_LOCAL (info, h)))
+               if (!htab->elf.dynamic_sections_created
+                   || h->dynindx == -1
+                   || SYMBOL_REFERENCES_LOCAL (info, h)
+                   || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
                  /* This is actually a static link, or it is a
                     -Bsymbolic link and the symbol is defined
                     locally, or the symbol was forced to be local
@@ -8315,7 +8555,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
                  ;
                else
                  {
-                   BFD_ASSERT (h->dynindx != -1);
                    indx = h->dynindx;
                    unresolved_reloc = FALSE;
                  }
@@ -8374,19 +8613,25 @@ ppc_elf_relocate_section (bfd *output_bfd,
                      }
 
                    /* Generate relocs for the dynamic linker.  */
-                   if ((info->shared || indx != 0)
-                       && (offp == &htab->tlsld_got.offset
-                           || h == NULL
-                           || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
-                           || h->root.type != bfd_link_hash_undefweak))
+                   if (indx != 0
+                       || (bfd_link_pic (info)
+                           && (h == NULL
+                               || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)
+                               || offp == &htab->tlsld_got.offset)))
                      {
-                       asection *rsec = htab->relgot;
+                       asection *rsec = htab->elf.srelgot;
                        bfd_byte * loc;
 
                        if (ifunc != NULL)
-                         rsec = htab->reliplt;
-                       outrel.r_offset = (htab->got->output_section->vma
-                                          + htab->got->output_offset
+                         {
+                           rsec = htab->elf.irelplt;
+                           if (indx == 0)
+                             htab->local_ifunc_resolver = 1;
+                           else if (is_static_defined (h))
+                             htab->maybe_local_ifunc_resolver = 1;
+                         }
+                       outrel.r_offset = (htab->elf.sgot->output_section->vma
+                                          + htab->elf.sgot->output_offset
                                           + off);
                        outrel.r_addend = 0;
                        if (tls_ty & (TLS_LD | TLS_GD))
@@ -8437,28 +8682,29 @@ ppc_elf_relocate_section (bfd *output_bfd,
                      {
                        bfd_vma value = relocation;
 
-                       if (tls_ty == (TLS_TLS | TLS_LD))
-                         value = 1;
-                       else if (tls_ty != 0)
+                       if (tls_ty != 0)
                          {
                            if (htab->elf.tls_sec == NULL)
                              value = 0;
                            else
                              {
-                               value -= htab->elf.tls_sec->vma + DTP_OFFSET;
-                               if (tls_ty == (TLS_TLS | TLS_TPREL))
+                               if (tls_ty & TLS_LD)
+                                 value = 0;
+                               else
+                                 value -= htab->elf.tls_sec->vma + DTP_OFFSET;
+                               if (tls_ty & TLS_TPREL)
                                  value += DTP_OFFSET - TP_OFFSET;
                              }
 
-                           if (tls_ty == (TLS_TLS | TLS_GD))
+                           if (tls_ty & (TLS_LD | TLS_GD))
                              {
-                               bfd_put_32 (output_bfd, value,
-                                           htab->got->contents + off + 4);
+                               bfd_put_32 (input_bfd, value,
+                                           htab->elf.sgot->contents + off + 4);
                                value = 1;
                              }
                          }
-                       bfd_put_32 (output_bfd, value,
-                                   htab->got->contents + off);
+                       bfd_put_32 (input_bfd, value,
+                                   htab->elf.sgot->contents + off);
                      }
 
                    off += 4;
@@ -8497,10 +8743,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
            /* If here for a picfixup, we're done.  */
            if (r_type != ELF32_R_TYPE (rel->r_info))
-             continue;
+             goto copy_reloc;
 
-           relocation = (htab->got->output_section->vma
-                         + htab->got->output_offset
+           relocation = (htab->elf.sgot->output_section->vma
+                         + htab->elf.sgot->output_offset
                          + off
                          - SYM_VAL (htab->elf.hgot));
 
@@ -8510,7 +8756,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
               got at entry m+n bears little relation to the entry m.  */
            if (addend != 0)
              info->callbacks->einfo
-               (_("%P: %H: non-zero addend on %s reloc against `%s'\n"),
+               /* xgettext:c-format */
+               (_("%H: non-zero addend on %s reloc against `%s'\n"),
                 input_bfd, input_section, rel->r_offset,
                 howto->name,
                 sym_name);
@@ -8523,14 +8770,28 @@ ppc_elf_relocate_section (bfd *output_bfd,
             at a symbol not in this object.  */
          if (unresolved_reloc)
            {
-             if (! (*info->callbacks->undefined_symbol) (info,
-                                                         h->root.root.string,
-                                                         input_bfd,
-                                                         input_section,
-                                                         rel->r_offset,
-                                                         TRUE))
-               return FALSE;
-             continue;
+             (*info->callbacks->undefined_symbol) (info,
+                                                   h->root.root.string,
+                                                   input_bfd,
+                                                   input_section,
+                                                   rel->r_offset,
+                                                   TRUE);
+             goto copy_reloc;
+           }
+         if (h != NULL && h->type == STT_GNU_IFUNC && bfd_link_pic (info))
+           {
+             /* @local on an ifunc does not really make sense since
+                the ifunc resolver can take you anywhere.  More
+                seriously, calls to ifuncs must go through a plt call
+                stub, and for pic the plt call stubs uses r30 to
+                access the PLT.  The problem is that a call that is
+                local won't have the +32k reloc addend trick marking
+                -fPIC code, so the linker won't know whether r30 is
+                _GLOBAL_OFFSET_TABLE_ or pointing into a .got2 section.  */
+             /* xgettext:c-format */
+             info->callbacks->einfo (_("%X%H: @local call to ifunc %s\n"),
+                                     input_bfd, input_section, rel->r_offset,
+                                     h->root.root.string);
            }
          break;
 
@@ -8557,17 +8818,17 @@ ppc_elf_relocate_section (bfd *output_bfd,
                 code using weak externs ought to check that they are
                 defined before using them.  */
              bfd_byte *p = contents + rel->r_offset - d_offset;
-             unsigned int insn = bfd_get_32 (output_bfd, p);
+             unsigned int insn = bfd_get_32 (input_bfd, p);
              insn = _bfd_elf_ppc_at_tprel_transform (insn, 2);
              if (insn != 0)
-               bfd_put_32 (output_bfd, insn, p);
+               bfd_put_32 (input_bfd, insn, p);
              break;
            }
          if (htab->elf.tls_sec != NULL)
            addend -= htab->elf.tls_sec->vma + TP_OFFSET;
          /* The TPREL16 relocs shouldn't really be used in shared
-            libs as they will result in DT_TEXTREL being set, but
-            support them anyway.  */
+            libs or with non-local symbols as that will result in
+            DT_TEXTREL being set, but support them anyway.  */
          goto dodyn;
 
        case R_PPC_TPREL32:
@@ -8589,6 +8850,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_REL16_LO:
        case R_PPC_REL16_HI:
        case R_PPC_REL16_HA:
+       case R_PPC_REL16DX_HA:
          break;
 
        case R_PPC_REL32:
@@ -8623,7 +8885,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_ADDR14:
        case R_PPC_ADDR14_BRTAKEN:
        case R_PPC_ADDR14_BRNTAKEN:
-         if (h != NULL && !info->shared)
+         if (h != NULL && !bfd_link_pic (info))
            break;
          /* fall through */
 
@@ -8632,17 +8894,15 @@ ppc_elf_relocate_section (bfd *output_bfd,
              || is_vxworks_tls)
            break;
 
-         if ((info->shared
+         if ((bfd_link_pic (info)
               && !(h != NULL
                    && ((h->root.type == bfd_link_hash_undefined
-                        && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
-                            || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
-                       || (h->root.type == bfd_link_hash_undefweak
-                           && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)))
+                        && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
+                       || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)))
               && (must_be_dyn_reloc (info, r_type)
                   || !SYMBOL_CALLS_LOCAL (info, h)))
              || (ELIMINATE_COPY_RELOCS
-                 && !info->shared
+                 && !bfd_link_pic (info)
                  && h != NULL
                  && h->dynindx != -1
                  && !h->non_got_ref
@@ -8655,6 +8915,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
              int skip;
              bfd_byte *loc;
              asection *sreloc;
+             long indx = 0;
+
 #ifdef DEBUG
              fprintf (stderr, "ppc_elf_relocate_section needs to "
                       "create relocation for %s\n",
@@ -8665,12 +8927,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
              /* When generating a shared object, these relocations
                 are copied into the output file to be resolved at run
                 time.  */
-             sreloc = elf_section_data (input_section)->sreloc;
-             if (ifunc)
-               sreloc = htab->reliplt;
-             if (sreloc == NULL)
-               return FALSE;
-
              skip = 0;
              outrel.r_offset = _bfd_elf_section_offset (output_bfd, info,
                                                         input_section,
@@ -8683,14 +8939,12 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
              if (skip)
                memset (&outrel, 0, sizeof outrel);
-             else if ((h != NULL
-                       && (h->root.type == bfd_link_hash_undefined
-                           || h->root.type == bfd_link_hash_undefweak))
-                      || !SYMBOL_REFERENCES_LOCAL (info, h))
+             else if (!SYMBOL_REFERENCES_LOCAL (info, h))
                {
-                 BFD_ASSERT (h->dynindx != -1);
+                 indx = h->dynindx;
+                 BFD_ASSERT (indx != -1);
                  unresolved_reloc = FALSE;
-                 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
+                 outrel.r_info = ELF32_R_INFO (indx, r_type);
                  outrel.r_addend = rel->r_addend;
                }
              else
@@ -8699,8 +8953,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
                  if (r_type != R_PPC_ADDR32)
                    {
-                     long indx = 0;
-
                      if (ifunc != NULL)
                        {
                          /* If we get here when building a static
@@ -8716,7 +8968,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
                             So we'll segfault when trying to run the
                             indirection function to resolve the reloc.  */
                          info->callbacks->einfo
-                           (_("%P: %H: relocation %s for indirect "
+                           /* xgettext:c-format */
+                           (_("%H: relocation %s for indirect "
                               "function %s unsupported\n"),
                             input_bfd, input_section, rel->r_offset,
                             howto->name,
@@ -8764,18 +9017,28 @@ ppc_elf_relocate_section (bfd *output_bfd,
                    outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
                }
 
+             sreloc = elf_section_data (input_section)->sreloc;
+             if (ifunc)
+               {
+                 sreloc = htab->elf.irelplt;
+                 if (indx == 0)
+                   htab->local_ifunc_resolver = 1;
+                 else if (is_static_defined (h))
+                   htab->maybe_local_ifunc_resolver = 1;
+               }
+             if (sreloc == NULL)
+               return FALSE;
+
              loc = sreloc->contents;
              loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
              bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
 
              if (skip == -1)
-               continue;
+               goto copy_reloc;
 
-             /* This reloc will be computed at runtime.  We clear the memory
-                so that it contains predictable value.  */
-             if (! skip
-                 && ((input_section->flags & SEC_ALLOC) != 0
-                     || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
+             /* This reloc will be computed at runtime.  Clear the memory
+                so that it contains a predictable value for prelink.  */
+             if (!skip)
                {
                  relocation = howto->pc_relative ? outrel.r_offset : 0;
                  addend = 0;
@@ -8793,7 +9056,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
              if (r_type == R_PPC_RELAX_PLTREL24)
                {
-                 if (info->shared)
+                 if (bfd_link_pic (info))
                    got2_addend = addend;
                  addend = 0;
                }
@@ -8803,11 +9066,11 @@ ppc_elf_relocate_section (bfd *output_bfd,
                              + htab->glink->output_offset
                              + ent->glink_offset);
              else
-               relocation = (htab->plt->output_section->vma
-                             + htab->plt->output_offset
+               relocation = (htab->elf.splt->output_section->vma
+                             + htab->elf.splt->output_offset
                              + ent->plt.offset);
            }
-         /* Fall thru */
+         /* Fall through.  */
 
        case R_PPC_RELAX:
          {
@@ -8816,15 +9079,15 @@ ppc_elf_relocate_section (bfd *output_bfd,
            size_t insn_offset = rel->r_offset;
            unsigned int insn;
 
-           if (info->shared)
+           if (bfd_link_pic (info))
              {
                relocation -= (input_section->output_section->vma
                               + input_section->output_offset
                               + rel->r_offset - 4);
                stub = shared_stub_entry;
-               bfd_put_32 (output_bfd, stub[0], contents + insn_offset - 12);
-               bfd_put_32 (output_bfd, stub[1], contents + insn_offset - 8);
-               bfd_put_32 (output_bfd, stub[2], contents + insn_offset - 4);
+               bfd_put_32 (input_bfd, stub[0], contents + insn_offset - 12);
+               bfd_put_32 (input_bfd, stub[1], contents + insn_offset - 8);
+               bfd_put_32 (input_bfd, stub[2], contents + insn_offset - 4);
                stub += 3;
                size = ARRAY_SIZE (shared_stub_entry) - 3;
              }
@@ -8835,18 +9098,18 @@ ppc_elf_relocate_section (bfd *output_bfd,
              }
 
            relocation += addend;
-           if (info->relocatable)
+           if (bfd_link_relocatable (info))
              relocation = 0;
 
            /* First insn is HA, second is LO.  */
            insn = *stub++;
            insn |= ((relocation + 0x8000) >> 16) & 0xffff;
-           bfd_put_32 (output_bfd, insn, contents + insn_offset);
+           bfd_put_32 (input_bfd, insn, contents + insn_offset);
            insn_offset += 4;
 
            insn = *stub++;
            insn |= relocation & 0xffff;
-           bfd_put_32 (output_bfd, insn, contents + insn_offset);
+           bfd_put_32 (input_bfd, insn, contents + insn_offset);
            insn_offset += 4;
            size -= 2;
 
@@ -8854,7 +9117,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
              {
                insn = *stub++;
                --size;
-               bfd_put_32 (output_bfd, insn, contents + insn_offset);
+               bfd_put_32 (input_bfd, insn, contents + insn_offset);
                insn_offset += 4;
              }
 
@@ -8862,12 +9125,13 @@ ppc_elf_relocate_section (bfd *output_bfd,
               relocs to describe this relocation.  */
            BFD_ASSERT (ELF32_R_TYPE (relend[-1].r_info) == R_PPC_NONE);
            /* The relocs are at the bottom 2 bytes */
-           rel[0].r_offset += d_offset;
-           memmove (rel + 1, rel, (relend - rel - 1) * sizeof (*rel));
-           rel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA);
-           rel[1].r_offset += 4;
-           rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO);
-           rel++;
+           wrel->r_offset = rel->r_offset + d_offset;
+           wrel->r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA);
+           wrel->r_addend = rel->r_addend;
+           memmove (wrel + 1, wrel, (relend - wrel - 1) * sizeof (*wrel));
+           wrel++, rel++;
+           wrel->r_offset += 4;
+           wrel->r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO);
          }
          continue;
 
@@ -8920,10 +9184,12 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_PLTREL24:
          if (h != NULL && ifunc == NULL)
            {
-             struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2,
-                                                   info->shared ? addend : 0);
+             struct plt_entry *ent;
+
+             ent = find_plt_ent (&h->plt.plist, got2,
+                                 bfd_link_pic (info) ? addend : 0);
              if (ent == NULL
-                 || htab->plt == NULL)
+                 || htab->elf.splt == NULL)
                {
                  /* We didn't make a PLT entry for this symbol.  This
                     happens when statically linking PIC code, or when
@@ -8939,8 +9205,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
                                  + htab->glink->output_offset
                                  + ent->glink_offset);
                  else
-                   relocation = (htab->plt->output_section->vma
-                                 + htab->plt->output_offset
+                   relocation = (htab->elf.splt->output_section->vma
+                                 + htab->elf.splt->output_offset
                                  + ent->plt.offset);
                }
            }
@@ -8971,6 +9237,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                  || strcmp (name, ".sbss") == 0))
              {
                info->callbacks->einfo
+                 /* xgettext:c-format */
                  (_("%P: %B: the target (%s) of a %s relocation is "
                     "in the wrong output section (%s)\n"),
                   input_bfd,
@@ -9001,6 +9268,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                  || strcmp (name, ".sbss2") == 0))
              {
                info->callbacks->einfo
+                 /* xgettext:c-format */
                  (_("%P: %B: the target (%s) of a %s relocation is "
                     "in the wrong output section (%s)\n"),
                   input_bfd,
@@ -9013,39 +9281,45 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
        case R_PPC_VLE_LO16A:
          relocation = relocation + addend;
-         ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                              relocation, split16a_type);
-         continue;
+         ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                              contents + rel->r_offset, relocation,
+                              split16a_type, htab->params->vle_reloc_fixup);
+         goto copy_reloc;
 
        case R_PPC_VLE_LO16D:
          relocation = relocation + addend;
-         ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                              relocation, split16d_type);
-         continue;
+         ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                              contents + rel->r_offset, relocation,
+                              split16d_type, htab->params->vle_reloc_fixup);
+         goto copy_reloc;
 
        case R_PPC_VLE_HI16A:
          relocation = (relocation + addend) >> 16;
-         ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                              relocation, split16a_type);
-         continue;
+         ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                              contents + rel->r_offset, relocation,
+                              split16a_type, htab->params->vle_reloc_fixup);
+         goto copy_reloc;
 
        case R_PPC_VLE_HI16D:
          relocation = (relocation + addend) >> 16;
-         ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                              relocation, split16d_type);
-         continue;
+         ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                              contents + rel->r_offset, relocation,
+                              split16d_type, htab->params->vle_reloc_fixup);
+         goto copy_reloc;
 
        case R_PPC_VLE_HA16A:
          relocation = (relocation + addend + 0x8000) >> 16;
-         ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                              relocation, split16a_type);
-         continue;
+         ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                              contents + rel->r_offset, relocation,
+                              split16a_type, htab->params->vle_reloc_fixup);
+         goto copy_reloc;
 
        case R_PPC_VLE_HA16D:
          relocation = (relocation + addend + 0x8000) >> 16;
-         ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                              relocation, split16d_type);
-         continue;
+         ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                              contents + rel->r_offset, relocation,
+                              split16d_type, htab->params->vle_reloc_fixup);
+         goto copy_reloc;
 
          /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0.  */
        case R_PPC_EMB_SDA21:
@@ -9085,6 +9359,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
            else
              {
                info->callbacks->einfo
+                 /* xgettext:c-format */
                  (_("%P: %B: the target (%s) of a %s relocation is "
                     "in the wrong output section (%s)\n"),
                   input_bfd,
@@ -9094,7 +9369,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
                bfd_set_error (bfd_error_bad_value);
                ret = FALSE;
-               continue;
+               goto copy_reloc;
              }
 
            if (sda != NULL)
@@ -9107,7 +9382,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                addend -= SYM_VAL (sda);
              }
 
-           insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
+           insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
            if (reg == 0
                && (r_type == R_PPC_VLE_SDA21
                    || r_type == R_PPC_VLE_SDA21_LO))
@@ -9127,12 +9402,12 @@ ppc_elf_relocate_section (bfd *output_bfd,
                /* And the final 11 bits of the value to bits 21 to 31.  */
                insn |= relocation & 0x7ff;
 
-               bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
+               bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
 
                if (r_type == R_PPC_VLE_SDA21
                    && ((relocation + 0x80000) & 0xffffffff) > 0x100000)
                  goto overflow;
-               continue;
+               goto copy_reloc;
              }
            else if (r_type == R_PPC_EMB_SDA21
                     || r_type == R_PPC_VLE_SDA21
@@ -9141,7 +9416,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                /* Fill in register field.  */
                insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
              }
-           bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
+           bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
          }
          break;
 
@@ -9154,7 +9429,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
          {
            bfd_vma value;
            const char *name;
-           //int reg;
            struct elf_link_hash_entry *sda = NULL;
 
            if (sec == NULL || sec->output_section == NULL)
@@ -9166,19 +9440,14 @@ ppc_elf_relocate_section (bfd *output_bfd,
            name = bfd_get_section_name (output_bfd, sec->output_section);
            if (strcmp (name, ".sdata") == 0
                || strcmp (name, ".sbss") == 0)
-             {
-               //reg = 13;
-               sda = htab->sdata[0].sym;
-             }
+             sda = htab->sdata[0].sym;
            else if (strcmp (name, ".sdata2") == 0
                     || strcmp (name, ".sbss2") == 0)
-             {
-               //reg = 2;
-               sda = htab->sdata[1].sym;
-             }
+             sda = htab->sdata[1].sym;
            else
              {
-               (*_bfd_error_handler)
+               _bfd_error_handler
+                 /* xgettext:c-format */
                  (_("%B: the target (%s) of a %s relocation is "
                     "in the wrong output section (%s)"),
                   input_bfd,
@@ -9188,54 +9457,60 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
                bfd_set_error (bfd_error_bad_value);
                ret = FALSE;
-               continue;
+               goto copy_reloc;
              }
 
-           if (sda != NULL)
+           if (sda == NULL || !is_static_defined (sda))
              {
-               if (!is_static_defined (sda))
-                 {
-                   unresolved_reloc = TRUE;
-                   break;
-                 }
+               unresolved_reloc = TRUE;
+               break;
              }
-
-           value = (sda->root.u.def.section->output_section->vma
-                    + sda->root.u.def.section->output_offset
-                    + addend);
+           value = relocation + addend - SYM_VAL (sda);
 
            if (r_type == R_PPC_VLE_SDAREL_LO16A)
-             ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                                  value, split16a_type);
+             ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                                  contents + rel->r_offset, value,
+                                  split16a_type,
+                                  htab->params->vle_reloc_fixup);
            else if (r_type == R_PPC_VLE_SDAREL_LO16D)
-             ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                                  value, split16d_type);
+             ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                                  contents + rel->r_offset, value,
+                                  split16d_type,
+                                  htab->params->vle_reloc_fixup);
            else if (r_type == R_PPC_VLE_SDAREL_HI16A)
              {
                value = value >> 16;
-               ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                                    value, split16a_type);
+               ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                                    contents + rel->r_offset, value,
+                                    split16a_type,
+                                    htab->params->vle_reloc_fixup);
              }
            else if (r_type == R_PPC_VLE_SDAREL_HI16D)
              {
                value = value >> 16;
-               ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                                    value, split16d_type);
+               ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                                    contents + rel->r_offset, value,
+                                    split16d_type,
+                                    htab->params->vle_reloc_fixup);
              }
            else if (r_type == R_PPC_VLE_SDAREL_HA16A)
              {
                value = (value + 0x8000) >> 16;
-               ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                                    value, split16a_type);
+               ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                                    contents + rel->r_offset, value,
+                                    split16a_type,
+                                    htab->params->vle_reloc_fixup);
              }
            else if (r_type == R_PPC_VLE_SDAREL_HA16D)
              {
                value = (value + 0x8000) >> 16;
-               ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
-                                    value, split16d_type);
+               ppc_elf_vle_split16 (input_bfd, input_section, rel->r_offset,
+                                    contents + rel->r_offset, value,
+                                    split16d_type,
+                                    htab->params->vle_reloc_fixup);
              }
          }
-         continue;
+         goto copy_reloc;
 
          /* Relocate against the beginning of the section.  */
        case R_PPC_SECTOFF:
@@ -9276,6 +9551,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_EMB_RELST_HA:
        case R_PPC_EMB_BIT_FLD:
          info->callbacks->einfo
+           /* xgettext:c-format */
            (_("%P: %B: relocation %s is not yet supported for symbol %s\n"),
             input_bfd,
             howto->name,
@@ -9283,7 +9559,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
          bfd_set_error (bfd_error_invalid_operation);
          ret = FALSE;
-         continue;
+         goto copy_reloc;
        }
 
       /* Do any further special processing.  */
@@ -9294,6 +9570,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
        case R_PPC_ADDR16_HA:
        case R_PPC_REL16_HA:
+       case R_PPC_REL16DX_HA:
        case R_PPC_SECTOFF_HA:
        case R_PPC_TPREL16_HA:
        case R_PPC_DTPREL16_HA:
@@ -9305,7 +9582,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
             alone (it will be set to zero elsewhere in the link).  */
          if (sec == NULL)
            break;
-         /* Fall thru */
+         /* Fall through.  */
 
        case R_PPC_PLT16_HA:
        case R_PPC_GOT16_HA:
@@ -9343,7 +9620,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
               that make up part of the insn opcode.  */
            unsigned int insn, mask, lobit;
 
-           insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
+           insn = bfd_get_32 (input_bfd,
+                              contents + rel->r_offset - d_offset);
            mask = 0;
            if (is_insn_ds_form (insn))
              mask = 3;
@@ -9351,18 +9629,20 @@ ppc_elf_relocate_section (bfd *output_bfd,
              mask = 15;
            else
              break;
-           lobit = mask & (relocation + addend);
+           relocation += addend;
+           addend = insn & mask;
+           lobit = mask & relocation;
            if (lobit != 0)
              {
-               addend -= lobit;
+               relocation ^= lobit;
                info->callbacks->einfo
-                 (_("%P: %H: error: %s against `%s' not a multiple of %u\n"),
+                 /* xgettext:c-format */
+                 (_("%H: error: %s against `%s' not a multiple of %u\n"),
                   input_bfd, input_section, rel->r_offset,
                   howto->name, sym_name, mask + 1);
                bfd_set_error (bfd_error_bad_value);
                ret = FALSE;
              }
-           addend += insn & mask;
          }
          break;
        }
@@ -9385,7 +9665,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
                                      rel->r_offset) != (bfd_vma) -1)
        {
          info->callbacks->einfo
-           (_("%P: %H: unresolvable %s relocation against symbol `%s'\n"),
+           /* xgettext:c-format */
+           (_("%H: unresolvable %s relocation against symbol `%s'\n"),
             input_bfd, input_section, rel->r_offset,
             howto->name,
             sym_name);
@@ -9421,8 +9702,30 @@ ppc_elf_relocate_section (bfd *output_bfd,
            }
        }
 
-      r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
-                                   rel->r_offset, relocation, addend);
+      if (r_type == R_PPC_REL16DX_HA)
+       {
+         /* Split field reloc isn't handled by _bfd_final_link_relocate.  */
+         if (rel->r_offset + 4 > input_section->size)
+           r = bfd_reloc_outofrange;
+         else
+           {
+             unsigned int insn;
+
+             relocation += addend;
+             relocation -= (rel->r_offset
+                            + input_section->output_offset
+                            + input_section->output_section->vma);
+             relocation >>= 16;
+             insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
+             insn &= ~0x1fffc1;
+             insn |= (relocation & 0xffc1) | ((relocation & 0x3e) << 15);
+             bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
+             r = bfd_reloc_ok;
+           }
+       }
+      else
+       r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
+                                     rel->r_offset, relocation, addend);
 
       if (r != bfd_reloc_ok)
        {
@@ -9436,23 +9739,45 @@ ppc_elf_relocate_section (bfd *output_bfd,
                       && (h->root.type == bfd_link_hash_undefweak
                           || h->root.type == bfd_link_hash_undefined)
                       && is_branch_reloc (r_type)))
-               {
-                 if (!((*info->callbacks->reloc_overflow)
-                       (info, (h ? &h->root : NULL), sym_name,
-                        howto->name, rel->r_addend,
-                        input_bfd, input_section, rel->r_offset)))
-                   return FALSE;
-               }
+               info->callbacks->reloc_overflow
+                 (info, (h ? &h->root : NULL), sym_name, howto->name,
+                  rel->r_addend, input_bfd, input_section, rel->r_offset);
            }
          else
            {
              info->callbacks->einfo
-               (_("%P: %H: %s reloc against `%s': error %d\n"),
+               /* xgettext:c-format */
+               (_("%H: %s reloc against `%s': error %d\n"),
                 input_bfd, input_section, rel->r_offset,
                 howto->name, sym_name, (int) r);
              ret = FALSE;
            }
        }
+    copy_reloc:
+      if (wrel != rel)
+       *wrel = *rel;
+    }
+
+  if (wrel != rel)
+    {
+      Elf_Internal_Shdr *rel_hdr;
+      size_t deleted = rel - wrel;
+
+      rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section);
+      rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
+      if (rel_hdr->sh_size == 0)
+       {
+         /* It is too late to remove an empty reloc section.  Leave
+            one NONE reloc.
+            ??? What is wrong with an empty section???  */
+         rel_hdr->sh_size = rel_hdr->sh_entsize;
+         deleted -= 1;
+         wrel++;
+       }
+      relend = wrel;
+      rel_hdr = _bfd_elf_single_rel_hdr (input_section);
+      rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
+      input_section->reloc_count -= deleted;
     }
 
 #ifdef DEBUG
@@ -9471,7 +9796,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
   if (htab->params->ppc476_workaround
       && input_section->sec_info_type == SEC_INFO_TYPE_TARGET
-      && (!info->relocatable
+      && (!bfd_link_relocatable (info)
          || (input_section->output_section->alignment_power
              >= htab->params->pagesize_p2)))
     {
@@ -9683,9 +10008,9 @@ ppc_elf_relocate_section (bfd *output_bfd,
              bfd_vma delta = ((insn & 0xfffc) ^ 0x8000) - 0x8000;
 
              delta += offset - patch_off;
-             if (info->relocatable && rel != NULL)
+             if (bfd_link_relocatable (info) && rel != NULL)
                delta = 0;
-             if (!info->relocatable && rel != NULL)
+             if (!bfd_link_relocatable (info) && rel != NULL)
                {
                  enum elf_ppc_reloc_type r_type;
 
@@ -9811,18 +10136,18 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                got_offset = (reloc_index + 3) * 4;
 
                /* Use the right PLT. */
-               plt_entry = info->shared ? ppc_elf_vxworks_pic_plt_entry
+               plt_entry = bfd_link_pic (info) ? ppc_elf_vxworks_pic_plt_entry
                            : ppc_elf_vxworks_plt_entry;
 
                /* Fill in the .plt on VxWorks.  */
-               if (info->shared)
+               if (bfd_link_pic (info))
                  {
                    bfd_put_32 (output_bfd,
                                plt_entry[0] | PPC_HA (got_offset),
-                               htab->plt->contents + ent->plt.offset + 0);
+                               htab->elf.splt->contents + ent->plt.offset + 0);
                    bfd_put_32 (output_bfd,
                                plt_entry[1] | PPC_LO (got_offset),
-                               htab->plt->contents + ent->plt.offset + 4);
+                               htab->elf.splt->contents + ent->plt.offset + 4);
                  }
                else
                  {
@@ -9830,16 +10155,16 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
 
                    bfd_put_32 (output_bfd,
                                plt_entry[0] | PPC_HA (got_loc),
-                               htab->plt->contents + ent->plt.offset + 0);
+                               htab->elf.splt->contents + ent->plt.offset + 0);
                    bfd_put_32 (output_bfd,
                                plt_entry[1] | PPC_LO (got_loc),
-                               htab->plt->contents + ent->plt.offset + 4);
+                               htab->elf.splt->contents + ent->plt.offset + 4);
                  }
 
                bfd_put_32 (output_bfd, plt_entry[2],
-                           htab->plt->contents + ent->plt.offset + 8);
+                           htab->elf.splt->contents + ent->plt.offset + 8);
                bfd_put_32 (output_bfd, plt_entry[3],
-                           htab->plt->contents + ent->plt.offset + 12);
+                           htab->elf.splt->contents + ent->plt.offset + 12);
 
                /* This instruction is an immediate load.  The value loaded is
                   the byte offset of the R_PPC_JMP_SLOT relocation from the
@@ -9849,7 +10174,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                   prescaled offset.  */
                bfd_put_32 (output_bfd,
                            plt_entry[4] | reloc_index,
-                           htab->plt->contents + ent->plt.offset + 16);
+                           htab->elf.splt->contents + ent->plt.offset + 16);
                /* This instruction is a PC-relative branch whose target is
                   the start of the PLT section.  The address of this branch
                   instruction is 20 bytes beyond the start of this PLT entry.
@@ -9859,21 +10184,21 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                bfd_put_32 (output_bfd,
                            (plt_entry[5]
                             | (-(ent->plt.offset + 20) & 0x03fffffc)),
-                           htab->plt->contents + ent->plt.offset + 20);
+                           htab->elf.splt->contents + ent->plt.offset + 20);
                bfd_put_32 (output_bfd, plt_entry[6],
-                           htab->plt->contents + ent->plt.offset + 24);
+                           htab->elf.splt->contents + ent->plt.offset + 24);
                bfd_put_32 (output_bfd, plt_entry[7],
-                           htab->plt->contents + ent->plt.offset + 28);
+                           htab->elf.splt->contents + ent->plt.offset + 28);
 
                /* Fill in the GOT entry corresponding to this PLT slot with
                   the address immediately after the "bctr" instruction
                   in this PLT entry.  */
-               bfd_put_32 (output_bfd, (htab->plt->output_section->vma
-                                        + htab->plt->output_offset
+               bfd_put_32 (output_bfd, (htab->elf.splt->output_section->vma
+                                        + htab->elf.splt->output_offset
                                         + ent->plt.offset + 16),
-                           htab->sgotplt->contents + got_offset);
+                           htab->elf.sgotplt->contents + got_offset);
 
-               if (!info->shared)
+               if (!bfd_link_pic (info))
                  {
                    /* Fill in a couple of entries in .rela.plt.unloaded.  */
                    loc = htab->srelplt2->contents
@@ -9882,8 +10207,8 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                         * sizeof (Elf32_External_Rela));
 
                    /* Provide the @ha relocation for the first instruction.  */
-                   rela.r_offset = (htab->plt->output_section->vma
-                                    + htab->plt->output_offset
+                   rela.r_offset = (htab->elf.splt->output_section->vma
+                                    + htab->elf.splt->output_offset
                                     + ent->plt.offset + 2);
                    rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
                                                R_PPC_ADDR16_HA);
@@ -9892,8 +10217,8 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                    loc += sizeof (Elf32_External_Rela);
 
                    /* Provide the @l relocation for the second instruction.  */
-                   rela.r_offset = (htab->plt->output_section->vma
-                                    + htab->plt->output_offset
+                   rela.r_offset = (htab->elf.splt->output_section->vma
+                                    + htab->elf.splt->output_offset
                                     + ent->plt.offset + 6);
                    rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
                                                R_PPC_ADDR16_LO);
@@ -9903,8 +10228,8 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
 
                    /* Provide a relocation for the GOT entry corresponding to this
                       PLT slot.  Point it at the middle of the .plt entry.  */
-                   rela.r_offset = (htab->sgotplt->output_section->vma
-                                    + htab->sgotplt->output_offset
+                   rela.r_offset = (htab->elf.sgotplt->output_section->vma
+                                    + htab->elf.sgotplt->output_offset
                                     + got_offset);
                    rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
                                                R_PPC_ADDR32);
@@ -9917,17 +10242,17 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                   address of the PLT entry for this function, as specified
                   by the ABI.  Instead, the offset is set to the address of
                   the GOT slot for this function.  See EABI 4.4.4.1.  */
-               rela.r_offset = (htab->sgotplt->output_section->vma
-                                + htab->sgotplt->output_offset
+               rela.r_offset = (htab->elf.sgotplt->output_section->vma
+                                + htab->elf.sgotplt->output_offset
                                 + got_offset);
 
              }
            else
              {
-               asection *splt = htab->plt;
+               asection *splt = htab->elf.splt;
                if (!htab->elf.dynamic_sections_created
                    || h->dynindx == -1)
-                 splt = htab->iplt;
+                 splt = htab->elf.iplt;
 
                rela.r_offset = (splt->output_section->vma
                                 + splt->output_offset
@@ -9966,12 +10291,19 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
 
            if (!htab->elf.dynamic_sections_created
                || h->dynindx == -1)
-             loc = (htab->reliplt->contents
-                    + (htab->reliplt->reloc_count++
-                       * sizeof (Elf32_External_Rela)));
+             {
+               loc = (htab->elf.irelplt->contents
+                      + (htab->elf.irelplt->reloc_count++
+                         * sizeof (Elf32_External_Rela)));
+               htab->local_ifunc_resolver = 1;
+             }
            else
-             loc = (htab->relplt->contents
-                    + reloc_index * sizeof (Elf32_External_Rela));
+             {
+               loc = (htab->elf.srelplt->contents
+                      + reloc_index * sizeof (Elf32_External_Rela));
+               if (h->type == STT_GNU_IFUNC && is_static_defined (h))
+                 htab->maybe_local_ifunc_resolver = 1;
+             }
            bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
 
            if (!h->def_regular)
@@ -9995,7 +10327,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                  }
              }
            else if (h->type == STT_GNU_IFUNC
-                    && !info->shared)
+                    && !bfd_link_pic (info))
              {
                /* Set the value of ifunc symbols in a non-pie
                   executable to the glink entry.  This is to avoid
@@ -10018,10 +10350,10 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
            || h->dynindx == -1)
          {
            unsigned char *p;
-           asection *splt = htab->plt;
+           asection *splt = htab->elf.splt;
            if (!htab->elf.dynamic_sections_created
                || h->dynindx == -1)
-             splt = htab->iplt;
+             splt = htab->elf.iplt;
 
            p = (unsigned char *) htab->glink->contents + ent->glink_offset;
 
@@ -10047,7 +10379,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
 
            write_glink_stub (ent, splt, p, info);
 
-           if (!info->shared)
+           if (!bfd_link_pic (info))
              /* We only need one non-PIC glink stub.  */
              break;
          }
@@ -10071,8 +10403,10 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
 
       if (ppc_elf_hash_entry (h)->has_sda_refs)
        s = htab->relsbss;
+      else if (h->root.u.def.section == htab->elf.sdynrelro)
+       s = htab->elf.sreldynrelro;
       else
-       s = htab->relbss;
+       s = htab->elf.srelbss;
       BFD_ASSERT (s != NULL);
 
       rela.r_offset = SYM_VAL (h);
@@ -10096,7 +10430,7 @@ ppc_elf_reloc_type_class (const struct bfd_link_info *info,
 {
   struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
 
-  if (rel_sec == htab->reliplt)
+  if (rel_sec == htab->elf.irelplt)
     return reloc_class_ifunc;
 
   switch (ELF32_R_TYPE (rela->r_info))
@@ -10119,7 +10453,6 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
                                 struct bfd_link_info *info)
 {
   asection *sdyn;
-  asection *splt;
   struct ppc_elf_link_hash_table *htab;
   bfd_vma got;
   bfd *dynobj;
@@ -10130,12 +10463,8 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 #endif
 
   htab = ppc_elf_hash_table (info);
-  dynobj = elf_hash_table (info)->dynobj;
+  dynobj = htab->elf.dynobj;
   sdyn = bfd_get_linker_section (dynobj, ".dynamic");
-  if (htab->is_vxworks)
-    splt = bfd_get_linker_section (dynobj, ".plt");
-  else
-    splt = NULL;
 
   got = 0;
   if (htab->elf.hgot != NULL)
@@ -10145,7 +10474,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
     {
       Elf32_External_Dyn *dyncon, *dynconend;
 
-      BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
+      BFD_ASSERT (htab->elf.splt != NULL && sdyn != NULL);
 
       dyncon = (Elf32_External_Dyn *) sdyn->contents;
       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
@@ -10160,18 +10489,18 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
            {
            case DT_PLTGOT:
              if (htab->is_vxworks)
-               s = htab->sgotplt;
+               s = htab->elf.sgotplt;
              else
-               s = htab->plt;
+               s = htab->elf.splt;
              dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
              break;
 
            case DT_PLTRELSZ:
-             dyn.d_un.d_val = htab->relplt->size;
+             dyn.d_un.d_val = htab->elf.srelplt->size;
              break;
 
            case DT_JMPREL:
-             s = htab->relplt;
+             s = htab->elf.srelplt;
              dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
              break;
 
@@ -10179,13 +10508,15 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
              dyn.d_un.d_ptr = got;
              break;
 
-           case DT_RELASZ:
-             if (htab->is_vxworks)
-               {
-                 if (htab->relplt)
-                   dyn.d_un.d_ptr -= htab->relplt->size;
-                 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)
+               info->callbacks->einfo
+                 (_("%P: warning: text relocations and GNU indirect "
+                    "functions may result in a segfault at runtime\n"));
              continue;
 
            default:
@@ -10199,10 +10530,11 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
        }
     }
 
-  if (htab->got != NULL)
+  if (htab->elf.sgot != NULL
+      && htab->elf.sgot->output_section != bfd_abs_section_ptr)
     {
-      if (htab->elf.hgot->root.u.def.section == htab->got
-         || htab->elf.hgot->root.u.def.section == htab->sgotplt)
+      if (htab->elf.hgot->root.u.def.section == htab->elf.sgot
+         || htab->elf.hgot->root.u.def.section == htab->elf.sgotplt)
        {
          unsigned char *p = htab->elf.hgot->root.u.def.section->contents;
 
@@ -10227,26 +10559,32 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
        }
       else
        {
+         /* xgettext:c-format */
          info->callbacks->einfo (_("%P: %s not defined in linker created %s\n"),
                                  htab->elf.hgot->root.root.string,
-                                 (htab->sgotplt != NULL
-                                  ? htab->sgotplt->name : htab->got->name));
+                                 (htab->elf.sgotplt != NULL
+                                  ? htab->elf.sgotplt->name
+                                  : htab->elf.sgot->name));
          bfd_set_error (bfd_error_bad_value);
          ret = FALSE;
        }
 
-      elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
+      elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 4;
     }
 
   /* Fill in the first entry in the VxWorks procedure linkage table.  */
-  if (splt && splt->size > 0)
+  if (htab->is_vxworks
+      && htab->elf.splt != NULL
+      && htab->elf.splt->size != 0
+      && htab->elf.splt->output_section != bfd_abs_section_ptr)
     {
+      asection *splt = htab->elf.splt;
       /* Use the right PLT. */
-      const bfd_vma *plt_entry = (info->shared
+      const bfd_vma *plt_entry = (bfd_link_pic (info)
                                  ? ppc_elf_vxworks_pic_plt0_entry
                                  : ppc_elf_vxworks_plt0_entry);
 
-      if (!info->shared)
+      if (!bfd_link_pic (info))
        {
          bfd_vma got_value = SYM_VAL (htab->elf.hgot);
 
@@ -10267,7 +10605,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
       bfd_put_32 (output_bfd, plt_entry[6], splt->contents + 24);
       bfd_put_32 (output_bfd, plt_entry[7], splt->contents + 28);
 
-      if (! info->shared)
+      if (! bfd_link_pic (info))
        {
          Elf_Internal_Rela rela;
          bfd_byte *loc;
@@ -10275,8 +10613,8 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
          loc = htab->srelplt2->contents;
 
          /* Output the @ha relocation for the first instruction.  */
-         rela.r_offset = (htab->plt->output_section->vma
-                          + htab->plt->output_offset
+         rela.r_offset = (htab->elf.splt->output_section->vma
+                          + htab->elf.splt->output_offset
                           + 2);
          rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
          rela.r_addend = 0;
@@ -10284,8 +10622,8 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
          loc += sizeof (Elf32_External_Rela);
 
          /* Output the @l relocation for the second instruction.  */
-         rela.r_offset = (htab->plt->output_section->vma
-                          + htab->plt->output_offset
+         rela.r_offset = (htab->elf.splt->output_section->vma
+                          + htab->elf.splt->output_offset
                           + 6);
          rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
          rela.r_addend = 0;
@@ -10484,7 +10822,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
        }
 
       /* Last comes the PLTresolve stub.  */
-      if (info->shared)
+      if (bfd_link_pic (info))
        {
          bfd_vma bcl;
 
@@ -10615,6 +10953,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 #endif
 
 #define elf_backend_plt_not_loaded     1
+#define elf_backend_want_dynrelro      1
 #define elf_backend_can_gc_sections    1
 #define elf_backend_can_refcount       1
 #define elf_backend_rela_normal                1
@@ -10645,7 +10984,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 #define elf_backend_finish_dynamic_sections    ppc_elf_finish_dynamic_sections
 #define elf_backend_fake_sections              ppc_elf_fake_sections
 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
-#define elf_backend_modify_segment_map         ppc_elf_modify_segment_map
+#define elf_backend_modify_segment_map         ppc_elf_modify_segment_map
 #define elf_backend_grok_prstatus              ppc_elf_grok_prstatus
 #define elf_backend_grok_psinfo                        ppc_elf_grok_psinfo
 #define elf_backend_write_core_note            ppc_elf_write_core_note
@@ -10658,7 +10997,6 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 #define elf_backend_action_discarded           ppc_elf_action_discarded
 #define elf_backend_init_index_section         _bfd_elf_init_1_index_section
 #define elf_backend_lookup_section_flags_hook  ppc_elf_lookup_section_flags
-#define elf_backend_section_processing         ppc_elf_section_processing
 
 #include "elf32-target.h"
 
@@ -10694,7 +11032,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 
 /* VxWorks uses the elf default section flags for .plt.  */
 static const struct bfd_elf_special_section *
-ppc_elf_vxworks_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
+ppc_elf_vxworks_get_sec_type_attr (bfd *abfd, asection *sec)
 {
   if (sec->name == NULL)
     return NULL;
@@ -10716,7 +11054,7 @@ ppc_elf_vxworks_link_hash_table_create (bfd *abfd)
   if (ret)
     {
       struct ppc_elf_link_hash_table *htab
-        = (struct ppc_elf_link_hash_table *)ret;
+       = (struct ppc_elf_link_hash_table *)ret;
       htab->is_vxworks = 1;
       htab->plt_type = PLT_VXWORKS;
       htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE;
@@ -10731,23 +11069,23 @@ static bfd_boolean
 ppc_elf_vxworks_add_symbol_hook (bfd *abfd,
                                 struct bfd_link_info *info,
                                 Elf_Internal_Sym *sym,
-                                const char **namep ATTRIBUTE_UNUSED,
-                                flagword *flagsp ATTRIBUTE_UNUSED,
+                                const char **namep,
+                                flagword *flagsp,
                                 asection **secp,
                                 bfd_vma *valp)
 {
-  if (!elf_vxworks_add_symbol_hook(abfd, info, sym,namep, flagsp, secp,
-                                  valp))
+  if (!elf_vxworks_add_symbol_hook (abfd, info, sym, namep, flagsp, secp,
+                                   valp))
     return FALSE;
 
-  return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp);
+  return ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp);
 }
 
 static void
 ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
 {
-  ppc_elf_final_write_processing(abfd, linker);
-  elf_vxworks_final_write_processing(abfd, linker);
+  ppc_elf_final_write_processing (abfd, linker);
+  elf_vxworks_final_write_processing (abfd, linker);
 }
 
 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
@@ -10764,6 +11102,8 @@ ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
 #define elf_backend_plt_readonly               1
 #undef elf_backend_got_header_size
 #define elf_backend_got_header_size            12
+#undef elf_backend_dtrel_excludes_plt
+#define elf_backend_dtrel_excludes_plt         1
 
 #undef bfd_elf32_get_synthetic_symtab
 
This page took 0.099073 seconds and 4 git commands to generate.