Home | History | Annotate | Download | only in bfd
      1 /* PowerPC-specific support for 32-bit ELF
      2    Copyright (C) 1994-2014 Free Software Foundation, Inc.
      3    Written by Ian Lance Taylor, Cygnus Support.
      4 
      5    This file is part of BFD, the Binary File Descriptor library.
      6 
      7    This program is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program; if not, write to the
     19    Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
     20    Boston, MA 02110-1301, USA.  */
     21 
     22 
     23 /* This file is based on a preliminary PowerPC ELF ABI.  The
     24    information may not match the final PowerPC ELF ABI.  It includes
     25    suggestions from the in-progress Embedded PowerPC ABI, and that
     26    information may also not match.  */
     27 
     28 #include "sysdep.h"
     29 #include <stdarg.h>
     30 #include "bfd.h"
     31 #include "bfdlink.h"
     32 #include "libbfd.h"
     33 #include "elf-bfd.h"
     34 #include "elf/ppc.h"
     35 #include "elf32-ppc.h"
     36 #include "elf-vxworks.h"
     37 #include "dwarf2.h"
     38 #include "elf-linux-psinfo.h"
     39 
     40 typedef enum split16_format_type
     41 {
     42   split16a_type = 0,
     43   split16d_type
     44 }
     45 split16_format_type;
     46 
     47 /* RELA relocations are used here.  */
     48 
     49 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
     50   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
     51 static bfd_reloc_status_type ppc_elf_unhandled_reloc
     52   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
     53 
     54 /* Branch prediction bit for branch taken relocs.  */
     55 #define BRANCH_PREDICT_BIT 0x200000
     56 /* Mask to set RA in memory instructions.  */
     57 #define RA_REGISTER_MASK 0x001f0000
     58 /* Value to shift register by to insert RA.  */
     59 #define RA_REGISTER_SHIFT 16
     60 
     61 /* The name of the dynamic interpreter.  This is put in the .interp
     62    section.  */
     63 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
     64 
     65 /* For old-style PLT.  */
     66 /* The number of single-slot PLT entries (the rest use two slots).  */
     67 #define PLT_NUM_SINGLE_ENTRIES 8192
     68 
     69 /* For new-style .glink and .plt.  */
     70 #define GLINK_PLTRESOLVE 16*4
     71 #define GLINK_ENTRY_SIZE 4*4
     72 #define TLS_GET_ADDR_GLINK_SIZE 12*4
     73 
     74 /* VxWorks uses its own plt layout, filled in by the static linker.  */
     75 
     76 /* The standard VxWorks PLT entry.  */
     77 #define VXWORKS_PLT_ENTRY_SIZE 32
     78 static const bfd_vma ppc_elf_vxworks_plt_entry
     79     [VXWORKS_PLT_ENTRY_SIZE / 4] =
     80   {
     81     0x3d800000, /* lis     r12,0                 */
     82     0x818c0000, /* lwz     r12,0(r12)            */
     83     0x7d8903a6, /* mtctr   r12                   */
     84     0x4e800420, /* bctr                          */
     85     0x39600000, /* li      r11,0                 */
     86     0x48000000, /* b       14 <.PLT0resolve+0x4> */
     87     0x60000000, /* nop                           */
     88     0x60000000, /* nop                           */
     89   };
     90 static const bfd_vma ppc_elf_vxworks_pic_plt_entry
     91     [VXWORKS_PLT_ENTRY_SIZE / 4] =
     92   {
     93     0x3d9e0000, /* addis r12,r30,0 */
     94     0x818c0000, /* lwz	 r12,0(r12) */
     95     0x7d8903a6, /* mtctr r12 */
     96     0x4e800420, /* bctr */
     97     0x39600000, /* li	 r11,0 */
     98     0x48000000, /* b	 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */
     99     0x60000000, /* nop */
    100     0x60000000, /* nop */
    101   };
    102 
    103 /* The initial VxWorks PLT entry.  */
    104 #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32
    105 static const bfd_vma ppc_elf_vxworks_plt0_entry
    106     [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
    107   {
    108     0x3d800000, /* lis     r12,0        */
    109     0x398c0000, /* addi    r12,r12,0    */
    110     0x800c0008, /* lwz     r0,8(r12)    */
    111     0x7c0903a6, /* mtctr   r0           */
    112     0x818c0004, /* lwz     r12,4(r12)   */
    113     0x4e800420, /* bctr                 */
    114     0x60000000, /* nop                  */
    115     0x60000000, /* nop                  */
    116   };
    117 static const bfd_vma ppc_elf_vxworks_pic_plt0_entry
    118     [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
    119   {
    120     0x819e0008, /* lwz	 r12,8(r30) */
    121     0x7d8903a6, /* mtctr r12        */
    122     0x819e0004, /* lwz	 r12,4(r30) */
    123     0x4e800420, /* bctr             */
    124     0x60000000, /* nop              */
    125     0x60000000, /* nop              */
    126     0x60000000, /* nop              */
    127     0x60000000, /* nop              */
    128   };
    129 
    130 /* For executables, we have some additional relocations in
    131    .rela.plt.unloaded, for the kernel loader.  */
    132 
    133 /* The number of non-JMP_SLOT relocations per PLT0 slot. */
    134 #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3
    135 /* The number of relocations in the PLTResolve slot. */
    136 #define VXWORKS_PLTRESOLVE_RELOCS 2
    137 /* The number of relocations in the PLTResolve slot when when creating
    138    a shared library. */
    139 #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0
    140 
    141 /* Some instructions.  */
    142 #define ADDIS_11_11	0x3d6b0000
    143 #define ADDIS_11_30	0x3d7e0000
    144 #define ADDIS_12_12	0x3d8c0000
    145 #define ADDI_11_11	0x396b0000
    146 #define ADD_0_11_11	0x7c0b5a14
    147 #define ADD_3_12_2	0x7c6c1214
    148 #define ADD_11_0_11	0x7d605a14
    149 #define B		0x48000000
    150 #define BA		0x48000002
    151 #define BCL_20_31	0x429f0005
    152 #define BCTR		0x4e800420
    153 #define BEQLR		0x4d820020
    154 #define CMPWI_11_0	0x2c0b0000
    155 #define LIS_11		0x3d600000
    156 #define LIS_12		0x3d800000
    157 #define LWZU_0_12	0x840c0000
    158 #define LWZ_0_12	0x800c0000
    159 #define LWZ_11_3	0x81630000
    160 #define LWZ_11_11	0x816b0000
    161 #define LWZ_11_30	0x817e0000
    162 #define LWZ_12_3	0x81830000
    163 #define LWZ_12_12	0x818c0000
    164 #define MR_0_3		0x7c601b78
    165 #define MR_3_0		0x7c030378
    166 #define MFLR_0		0x7c0802a6
    167 #define MFLR_12		0x7d8802a6
    168 #define MTCTR_0		0x7c0903a6
    169 #define MTCTR_11	0x7d6903a6
    170 #define MTLR_0		0x7c0803a6
    171 #define NOP		0x60000000
    172 #define SUB_11_11_12	0x7d6c5850
    173 
    174 /* Offset of tp and dtp pointers from start of TLS block.  */
    175 #define TP_OFFSET	0x7000
    176 #define DTP_OFFSET	0x8000
    177 
    178 /* The value of a defined global symbol.  */
    179 #define SYM_VAL(SYM) \
    180   ((SYM)->root.u.def.section->output_section->vma	\
    181    + (SYM)->root.u.def.section->output_offset		\
    182    + (SYM)->root.u.def.value)
    183 
    184 static reloc_howto_type *ppc_elf_howto_table[R_PPC_max];
    186 
    187 static reloc_howto_type ppc_elf_howto_raw[] = {
    188   /* This reloc does nothing.  */
    189   HOWTO (R_PPC_NONE,		/* type */
    190 	 0,			/* rightshift */
    191 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    192 	 32,			/* bitsize */
    193 	 FALSE,			/* pc_relative */
    194 	 0,			/* bitpos */
    195 	 complain_overflow_dont, /* complain_on_overflow */
    196 	 bfd_elf_generic_reloc,	/* special_function */
    197 	 "R_PPC_NONE",		/* name */
    198 	 FALSE,			/* partial_inplace */
    199 	 0,			/* src_mask */
    200 	 0,			/* dst_mask */
    201 	 FALSE),		/* pcrel_offset */
    202 
    203   /* A standard 32 bit relocation.  */
    204   HOWTO (R_PPC_ADDR32,		/* type */
    205 	 0,			/* rightshift */
    206 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    207 	 32,			/* bitsize */
    208 	 FALSE,			/* pc_relative */
    209 	 0,			/* bitpos */
    210 	 complain_overflow_dont, /* complain_on_overflow */
    211 	 bfd_elf_generic_reloc,	/* special_function */
    212 	 "R_PPC_ADDR32",	/* name */
    213 	 FALSE,			/* partial_inplace */
    214 	 0,			/* src_mask */
    215 	 0xffffffff,		/* dst_mask */
    216 	 FALSE),		/* pcrel_offset */
    217 
    218   /* An absolute 26 bit branch; the lower two bits must be zero.
    219      FIXME: we don't check that, we just clear them.  */
    220   HOWTO (R_PPC_ADDR24,		/* type */
    221 	 0,			/* rightshift */
    222 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    223 	 26,			/* bitsize */
    224 	 FALSE,			/* pc_relative */
    225 	 0,			/* bitpos */
    226 	 complain_overflow_signed, /* complain_on_overflow */
    227 	 bfd_elf_generic_reloc,	/* special_function */
    228 	 "R_PPC_ADDR24",	/* name */
    229 	 FALSE,			/* partial_inplace */
    230 	 0,			/* src_mask */
    231 	 0x3fffffc,		/* dst_mask */
    232 	 FALSE),		/* pcrel_offset */
    233 
    234   /* A standard 16 bit relocation.  */
    235   HOWTO (R_PPC_ADDR16,		/* type */
    236 	 0,			/* rightshift */
    237 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    238 	 16,			/* bitsize */
    239 	 FALSE,			/* pc_relative */
    240 	 0,			/* bitpos */
    241 	 complain_overflow_bitfield, /* complain_on_overflow */
    242 	 bfd_elf_generic_reloc,	/* special_function */
    243 	 "R_PPC_ADDR16",	/* name */
    244 	 FALSE,			/* partial_inplace */
    245 	 0,			/* src_mask */
    246 	 0xffff,		/* dst_mask */
    247 	 FALSE),		/* pcrel_offset */
    248 
    249   /* A 16 bit relocation without overflow.  */
    250   HOWTO (R_PPC_ADDR16_LO,	/* type */
    251 	 0,			/* rightshift */
    252 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    253 	 16,			/* bitsize */
    254 	 FALSE,			/* pc_relative */
    255 	 0,			/* bitpos */
    256 	 complain_overflow_dont,/* complain_on_overflow */
    257 	 bfd_elf_generic_reloc,	/* special_function */
    258 	 "R_PPC_ADDR16_LO",	/* name */
    259 	 FALSE,			/* partial_inplace */
    260 	 0,			/* src_mask */
    261 	 0xffff,		/* dst_mask */
    262 	 FALSE),		/* pcrel_offset */
    263 
    264   /* The high order 16 bits of an address.  */
    265   HOWTO (R_PPC_ADDR16_HI,	/* type */
    266 	 16,			/* rightshift */
    267 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    268 	 16,			/* bitsize */
    269 	 FALSE,			/* pc_relative */
    270 	 0,			/* bitpos */
    271 	 complain_overflow_dont, /* complain_on_overflow */
    272 	 bfd_elf_generic_reloc,	/* special_function */
    273 	 "R_PPC_ADDR16_HI",	/* name */
    274 	 FALSE,			/* partial_inplace */
    275 	 0,			/* src_mask */
    276 	 0xffff,		/* dst_mask */
    277 	 FALSE),		/* pcrel_offset */
    278 
    279   /* The high order 16 bits of an address, plus 1 if the contents of
    280      the low 16 bits, treated as a signed number, is negative.  */
    281   HOWTO (R_PPC_ADDR16_HA,	/* type */
    282 	 16,			/* rightshift */
    283 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    284 	 16,			/* bitsize */
    285 	 FALSE,			/* pc_relative */
    286 	 0,			/* bitpos */
    287 	 complain_overflow_dont, /* complain_on_overflow */
    288 	 ppc_elf_addr16_ha_reloc, /* special_function */
    289 	 "R_PPC_ADDR16_HA",	/* name */
    290 	 FALSE,			/* partial_inplace */
    291 	 0,			/* src_mask */
    292 	 0xffff,		/* dst_mask */
    293 	 FALSE),		/* pcrel_offset */
    294 
    295   /* An absolute 16 bit branch; the lower two bits must be zero.
    296      FIXME: we don't check that, we just clear them.  */
    297   HOWTO (R_PPC_ADDR14,		/* type */
    298 	 0,			/* rightshift */
    299 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    300 	 16,			/* bitsize */
    301 	 FALSE,			/* pc_relative */
    302 	 0,			/* bitpos */
    303 	 complain_overflow_signed, /* complain_on_overflow */
    304 	 bfd_elf_generic_reloc,	/* special_function */
    305 	 "R_PPC_ADDR14",	/* name */
    306 	 FALSE,			/* partial_inplace */
    307 	 0,			/* src_mask */
    308 	 0xfffc,		/* dst_mask */
    309 	 FALSE),		/* pcrel_offset */
    310 
    311   /* An absolute 16 bit branch, for which bit 10 should be set to
    312      indicate that the branch is expected to be taken.	The lower two
    313      bits must be zero.  */
    314   HOWTO (R_PPC_ADDR14_BRTAKEN,	/* type */
    315 	 0,			/* rightshift */
    316 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    317 	 16,			/* bitsize */
    318 	 FALSE,			/* pc_relative */
    319 	 0,			/* bitpos */
    320 	 complain_overflow_signed, /* complain_on_overflow */
    321 	 bfd_elf_generic_reloc,	/* special_function */
    322 	 "R_PPC_ADDR14_BRTAKEN",/* name */
    323 	 FALSE,			/* partial_inplace */
    324 	 0,			/* src_mask */
    325 	 0xfffc,		/* dst_mask */
    326 	 FALSE),		/* pcrel_offset */
    327 
    328   /* An absolute 16 bit branch, for which bit 10 should be set to
    329      indicate that the branch is not expected to be taken.  The lower
    330      two bits must be zero.  */
    331   HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
    332 	 0,			/* rightshift */
    333 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    334 	 16,			/* bitsize */
    335 	 FALSE,			/* pc_relative */
    336 	 0,			/* bitpos */
    337 	 complain_overflow_signed, /* complain_on_overflow */
    338 	 bfd_elf_generic_reloc,	/* special_function */
    339 	 "R_PPC_ADDR14_BRNTAKEN",/* name */
    340 	 FALSE,			/* partial_inplace */
    341 	 0,			/* src_mask */
    342 	 0xfffc,		/* dst_mask */
    343 	 FALSE),		/* pcrel_offset */
    344 
    345   /* A relative 26 bit branch; the lower two bits must be zero.  */
    346   HOWTO (R_PPC_REL24,		/* type */
    347 	 0,			/* rightshift */
    348 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    349 	 26,			/* bitsize */
    350 	 TRUE,			/* pc_relative */
    351 	 0,			/* bitpos */
    352 	 complain_overflow_signed, /* complain_on_overflow */
    353 	 bfd_elf_generic_reloc,	/* special_function */
    354 	 "R_PPC_REL24",		/* name */
    355 	 FALSE,			/* partial_inplace */
    356 	 0,			/* src_mask */
    357 	 0x3fffffc,		/* dst_mask */
    358 	 TRUE),			/* pcrel_offset */
    359 
    360   /* A relative 16 bit branch; the lower two bits must be zero.  */
    361   HOWTO (R_PPC_REL14,		/* type */
    362 	 0,			/* rightshift */
    363 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    364 	 16,			/* bitsize */
    365 	 TRUE,			/* pc_relative */
    366 	 0,			/* bitpos */
    367 	 complain_overflow_signed, /* complain_on_overflow */
    368 	 bfd_elf_generic_reloc,	/* special_function */
    369 	 "R_PPC_REL14",		/* name */
    370 	 FALSE,			/* partial_inplace */
    371 	 0,			/* src_mask */
    372 	 0xfffc,		/* dst_mask */
    373 	 TRUE),			/* pcrel_offset */
    374 
    375   /* A relative 16 bit branch.  Bit 10 should be set to indicate that
    376      the branch is expected to be taken.  The lower two bits must be
    377      zero.  */
    378   HOWTO (R_PPC_REL14_BRTAKEN,	/* type */
    379 	 0,			/* rightshift */
    380 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    381 	 16,			/* bitsize */
    382 	 TRUE,			/* pc_relative */
    383 	 0,			/* bitpos */
    384 	 complain_overflow_signed, /* complain_on_overflow */
    385 	 bfd_elf_generic_reloc,	/* special_function */
    386 	 "R_PPC_REL14_BRTAKEN",	/* name */
    387 	 FALSE,			/* partial_inplace */
    388 	 0,			/* src_mask */
    389 	 0xfffc,		/* dst_mask */
    390 	 TRUE),			/* pcrel_offset */
    391 
    392   /* A relative 16 bit branch.  Bit 10 should be set to indicate that
    393      the branch is not expected to be taken.  The lower two bits must
    394      be zero.  */
    395   HOWTO (R_PPC_REL14_BRNTAKEN,	/* type */
    396 	 0,			/* rightshift */
    397 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    398 	 16,			/* bitsize */
    399 	 TRUE,			/* pc_relative */
    400 	 0,			/* bitpos */
    401 	 complain_overflow_signed, /* complain_on_overflow */
    402 	 bfd_elf_generic_reloc,	/* special_function */
    403 	 "R_PPC_REL14_BRNTAKEN",/* name */
    404 	 FALSE,			/* partial_inplace */
    405 	 0,			/* src_mask */
    406 	 0xfffc,		/* dst_mask */
    407 	 TRUE),			/* pcrel_offset */
    408 
    409   /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
    410      symbol.  */
    411   HOWTO (R_PPC_GOT16,		/* type */
    412 	 0,			/* rightshift */
    413 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    414 	 16,			/* bitsize */
    415 	 FALSE,			/* pc_relative */
    416 	 0,			/* bitpos */
    417 	 complain_overflow_signed, /* complain_on_overflow */
    418 	 bfd_elf_generic_reloc,	/* special_function */
    419 	 "R_PPC_GOT16",		/* name */
    420 	 FALSE,			/* partial_inplace */
    421 	 0,			/* src_mask */
    422 	 0xffff,		/* dst_mask */
    423 	 FALSE),		/* pcrel_offset */
    424 
    425   /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
    426      the symbol.  */
    427   HOWTO (R_PPC_GOT16_LO,	/* type */
    428 	 0,			/* rightshift */
    429 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    430 	 16,			/* bitsize */
    431 	 FALSE,			/* pc_relative */
    432 	 0,			/* bitpos */
    433 	 complain_overflow_dont, /* complain_on_overflow */
    434 	 bfd_elf_generic_reloc,	/* special_function */
    435 	 "R_PPC_GOT16_LO",	/* name */
    436 	 FALSE,			/* partial_inplace */
    437 	 0,			/* src_mask */
    438 	 0xffff,		/* dst_mask */
    439 	 FALSE),		/* pcrel_offset */
    440 
    441   /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
    442      the symbol.  */
    443   HOWTO (R_PPC_GOT16_HI,	/* type */
    444 	 16,			/* rightshift */
    445 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    446 	 16,			/* bitsize */
    447 	 FALSE,			/* pc_relative */
    448 	 0,			/* bitpos */
    449 	 complain_overflow_dont, /* complain_on_overflow */
    450 	 bfd_elf_generic_reloc,	/* special_function */
    451 	 "R_PPC_GOT16_HI",	/* name */
    452 	 FALSE,			/* partial_inplace */
    453 	 0,			/* src_mask */
    454 	 0xffff,		/* dst_mask */
    455 	 FALSE),		 /* pcrel_offset */
    456 
    457   /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
    458      the symbol.  */
    459   HOWTO (R_PPC_GOT16_HA,	/* type */
    460 	 16,			/* rightshift */
    461 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    462 	 16,			/* bitsize */
    463 	 FALSE,			/* pc_relative */
    464 	 0,			/* bitpos */
    465 	 complain_overflow_dont, /* complain_on_overflow */
    466 	 ppc_elf_addr16_ha_reloc, /* special_function */
    467 	 "R_PPC_GOT16_HA",	/* name */
    468 	 FALSE,			/* partial_inplace */
    469 	 0,			/* src_mask */
    470 	 0xffff,		/* dst_mask */
    471 	 FALSE),		/* pcrel_offset */
    472 
    473   /* Like R_PPC_REL24, but referring to the procedure linkage table
    474      entry for the symbol.  */
    475   HOWTO (R_PPC_PLTREL24,	/* type */
    476 	 0,			/* rightshift */
    477 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    478 	 26,			/* bitsize */
    479 	 TRUE,			/* pc_relative */
    480 	 0,			/* bitpos */
    481 	 complain_overflow_signed,  /* complain_on_overflow */
    482 	 bfd_elf_generic_reloc,	/* special_function */
    483 	 "R_PPC_PLTREL24",	/* name */
    484 	 FALSE,			/* partial_inplace */
    485 	 0,			/* src_mask */
    486 	 0x3fffffc,		/* dst_mask */
    487 	 TRUE),			/* pcrel_offset */
    488 
    489   /* This is used only by the dynamic linker.  The symbol should exist
    490      both in the object being run and in some shared library.  The
    491      dynamic linker copies the data addressed by the symbol from the
    492      shared library into the object, because the object being
    493      run has to have the data at some particular address.  */
    494   HOWTO (R_PPC_COPY,		/* type */
    495 	 0,			/* rightshift */
    496 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    497 	 32,			/* bitsize */
    498 	 FALSE,			/* pc_relative */
    499 	 0,			/* bitpos */
    500 	 complain_overflow_dont, /* complain_on_overflow */
    501 	 bfd_elf_generic_reloc,	 /* special_function */
    502 	 "R_PPC_COPY",		/* name */
    503 	 FALSE,			/* partial_inplace */
    504 	 0,			/* src_mask */
    505 	 0,			/* dst_mask */
    506 	 FALSE),		/* pcrel_offset */
    507 
    508   /* Like R_PPC_ADDR32, but used when setting global offset table
    509      entries.  */
    510   HOWTO (R_PPC_GLOB_DAT,	/* type */
    511 	 0,			/* rightshift */
    512 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    513 	 32,			/* bitsize */
    514 	 FALSE,			/* pc_relative */
    515 	 0,			/* bitpos */
    516 	 complain_overflow_dont, /* complain_on_overflow */
    517 	 bfd_elf_generic_reloc,	 /* special_function */
    518 	 "R_PPC_GLOB_DAT",	/* name */
    519 	 FALSE,			/* partial_inplace */
    520 	 0,			/* src_mask */
    521 	 0xffffffff,		/* dst_mask */
    522 	 FALSE),		/* pcrel_offset */
    523 
    524   /* Marks a procedure linkage table entry for a symbol.  */
    525   HOWTO (R_PPC_JMP_SLOT,	/* type */
    526 	 0,			/* rightshift */
    527 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    528 	 32,			/* bitsize */
    529 	 FALSE,			/* pc_relative */
    530 	 0,			/* bitpos */
    531 	 complain_overflow_dont, /* complain_on_overflow */
    532 	 bfd_elf_generic_reloc,	 /* special_function */
    533 	 "R_PPC_JMP_SLOT",	/* name */
    534 	 FALSE,			/* partial_inplace */
    535 	 0,			/* src_mask */
    536 	 0,			/* dst_mask */
    537 	 FALSE),		/* pcrel_offset */
    538 
    539   /* Used only by the dynamic linker.  When the object is run, this
    540      longword is set to the load address of the object, plus the
    541      addend.  */
    542   HOWTO (R_PPC_RELATIVE,	/* type */
    543 	 0,			/* rightshift */
    544 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    545 	 32,			/* bitsize */
    546 	 FALSE,			/* pc_relative */
    547 	 0,			/* bitpos */
    548 	 complain_overflow_dont, /* complain_on_overflow */
    549 	 bfd_elf_generic_reloc,	 /* special_function */
    550 	 "R_PPC_RELATIVE",	/* name */
    551 	 FALSE,			/* partial_inplace */
    552 	 0,			/* src_mask */
    553 	 0xffffffff,		/* dst_mask */
    554 	 FALSE),		/* pcrel_offset */
    555 
    556   /* Like R_PPC_REL24, but uses the value of the symbol within the
    557      object rather than the final value.  Normally used for
    558      _GLOBAL_OFFSET_TABLE_.  */
    559   HOWTO (R_PPC_LOCAL24PC,	/* type */
    560 	 0,			/* rightshift */
    561 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    562 	 26,			/* bitsize */
    563 	 TRUE,			/* pc_relative */
    564 	 0,			/* bitpos */
    565 	 complain_overflow_signed, /* complain_on_overflow */
    566 	 bfd_elf_generic_reloc,	/* special_function */
    567 	 "R_PPC_LOCAL24PC",	/* name */
    568 	 FALSE,			/* partial_inplace */
    569 	 0,			/* src_mask */
    570 	 0x3fffffc,		/* dst_mask */
    571 	 TRUE),			/* pcrel_offset */
    572 
    573   /* Like R_PPC_ADDR32, but may be unaligned.  */
    574   HOWTO (R_PPC_UADDR32,		/* type */
    575 	 0,			/* rightshift */
    576 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    577 	 32,			/* bitsize */
    578 	 FALSE,			/* pc_relative */
    579 	 0,			/* bitpos */
    580 	 complain_overflow_dont, /* complain_on_overflow */
    581 	 bfd_elf_generic_reloc,	/* special_function */
    582 	 "R_PPC_UADDR32",	/* name */
    583 	 FALSE,			/* partial_inplace */
    584 	 0,			/* src_mask */
    585 	 0xffffffff,		/* dst_mask */
    586 	 FALSE),		/* pcrel_offset */
    587 
    588   /* Like R_PPC_ADDR16, but may be unaligned.  */
    589   HOWTO (R_PPC_UADDR16,		/* type */
    590 	 0,			/* rightshift */
    591 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    592 	 16,			/* bitsize */
    593 	 FALSE,			/* pc_relative */
    594 	 0,			/* bitpos */
    595 	 complain_overflow_bitfield, /* complain_on_overflow */
    596 	 bfd_elf_generic_reloc,	/* special_function */
    597 	 "R_PPC_UADDR16",	/* name */
    598 	 FALSE,			/* partial_inplace */
    599 	 0,			/* src_mask */
    600 	 0xffff,		/* dst_mask */
    601 	 FALSE),		/* pcrel_offset */
    602 
    603   /* 32-bit PC relative */
    604   HOWTO (R_PPC_REL32,		/* type */
    605 	 0,			/* rightshift */
    606 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    607 	 32,			/* bitsize */
    608 	 TRUE,			/* pc_relative */
    609 	 0,			/* bitpos */
    610 	 complain_overflow_dont, /* complain_on_overflow */
    611 	 bfd_elf_generic_reloc,	/* special_function */
    612 	 "R_PPC_REL32",		/* name */
    613 	 FALSE,			/* partial_inplace */
    614 	 0,			/* src_mask */
    615 	 0xffffffff,		/* dst_mask */
    616 	 TRUE),			/* pcrel_offset */
    617 
    618   /* 32-bit relocation to the symbol's procedure linkage table.
    619      FIXME: not supported.  */
    620   HOWTO (R_PPC_PLT32,		/* type */
    621 	 0,			/* rightshift */
    622 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    623 	 32,			/* bitsize */
    624 	 FALSE,			/* pc_relative */
    625 	 0,			/* bitpos */
    626 	 complain_overflow_dont, /* complain_on_overflow */
    627 	 bfd_elf_generic_reloc,	/* special_function */
    628 	 "R_PPC_PLT32",		/* name */
    629 	 FALSE,			/* partial_inplace */
    630 	 0,			/* src_mask */
    631 	 0,			/* dst_mask */
    632 	 FALSE),		/* pcrel_offset */
    633 
    634   /* 32-bit PC relative relocation to the symbol's procedure linkage table.
    635      FIXME: not supported.  */
    636   HOWTO (R_PPC_PLTREL32,	/* type */
    637 	 0,			/* rightshift */
    638 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    639 	 32,			/* bitsize */
    640 	 TRUE,			/* pc_relative */
    641 	 0,			/* bitpos */
    642 	 complain_overflow_dont, /* complain_on_overflow */
    643 	 bfd_elf_generic_reloc,	/* special_function */
    644 	 "R_PPC_PLTREL32",	/* name */
    645 	 FALSE,			/* partial_inplace */
    646 	 0,			/* src_mask */
    647 	 0,			/* dst_mask */
    648 	 TRUE),			/* pcrel_offset */
    649 
    650   /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
    651      the symbol.  */
    652   HOWTO (R_PPC_PLT16_LO,	/* type */
    653 	 0,			/* rightshift */
    654 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    655 	 16,			/* bitsize */
    656 	 FALSE,			/* pc_relative */
    657 	 0,			/* bitpos */
    658 	 complain_overflow_dont, /* complain_on_overflow */
    659 	 bfd_elf_generic_reloc,	/* special_function */
    660 	 "R_PPC_PLT16_LO",	/* name */
    661 	 FALSE,			/* partial_inplace */
    662 	 0,			/* src_mask */
    663 	 0xffff,		/* dst_mask */
    664 	 FALSE),		/* pcrel_offset */
    665 
    666   /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
    667      the symbol.  */
    668   HOWTO (R_PPC_PLT16_HI,	/* type */
    669 	 16,			/* rightshift */
    670 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    671 	 16,			/* bitsize */
    672 	 FALSE,			/* pc_relative */
    673 	 0,			/* bitpos */
    674 	 complain_overflow_dont, /* complain_on_overflow */
    675 	 bfd_elf_generic_reloc,	/* special_function */
    676 	 "R_PPC_PLT16_HI",	/* name */
    677 	 FALSE,			/* partial_inplace */
    678 	 0,			/* src_mask */
    679 	 0xffff,		/* dst_mask */
    680 	 FALSE),		 /* pcrel_offset */
    681 
    682   /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
    683      the symbol.  */
    684   HOWTO (R_PPC_PLT16_HA,	/* type */
    685 	 16,			/* rightshift */
    686 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    687 	 16,			/* bitsize */
    688 	 FALSE,			/* pc_relative */
    689 	 0,			/* bitpos */
    690 	 complain_overflow_dont, /* complain_on_overflow */
    691 	 ppc_elf_addr16_ha_reloc, /* special_function */
    692 	 "R_PPC_PLT16_HA",	/* name */
    693 	 FALSE,			/* partial_inplace */
    694 	 0,			/* src_mask */
    695 	 0xffff,		/* dst_mask */
    696 	 FALSE),		/* pcrel_offset */
    697 
    698   /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
    699      small data items.  */
    700   HOWTO (R_PPC_SDAREL16,	/* type */
    701 	 0,			/* rightshift */
    702 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    703 	 16,			/* bitsize */
    704 	 FALSE,			/* pc_relative */
    705 	 0,			/* bitpos */
    706 	 complain_overflow_signed, /* complain_on_overflow */
    707 	 bfd_elf_generic_reloc,	/* special_function */
    708 	 "R_PPC_SDAREL16",	/* name */
    709 	 FALSE,			/* partial_inplace */
    710 	 0,			/* src_mask */
    711 	 0xffff,		/* dst_mask */
    712 	 FALSE),		/* pcrel_offset */
    713 
    714   /* 16-bit section relative relocation.  */
    715   HOWTO (R_PPC_SECTOFF,		/* type */
    716 	 0,			/* rightshift */
    717 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    718 	 16,			/* bitsize */
    719 	 FALSE,			/* pc_relative */
    720 	 0,			/* bitpos */
    721 	 complain_overflow_signed, /* complain_on_overflow */
    722 	 bfd_elf_generic_reloc,	/* special_function */
    723 	 "R_PPC_SECTOFF",	/* name */
    724 	 FALSE,			/* partial_inplace */
    725 	 0,			/* src_mask */
    726 	 0xffff,		/* dst_mask */
    727 	 FALSE),		/* pcrel_offset */
    728 
    729   /* 16-bit lower half section relative relocation.  */
    730   HOWTO (R_PPC_SECTOFF_LO,	  /* type */
    731 	 0,			/* rightshift */
    732 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    733 	 16,			/* bitsize */
    734 	 FALSE,			/* pc_relative */
    735 	 0,			/* bitpos */
    736 	 complain_overflow_dont, /* complain_on_overflow */
    737 	 bfd_elf_generic_reloc,	/* special_function */
    738 	 "R_PPC_SECTOFF_LO",	/* name */
    739 	 FALSE,			/* partial_inplace */
    740 	 0,			/* src_mask */
    741 	 0xffff,		/* dst_mask */
    742 	 FALSE),		/* pcrel_offset */
    743 
    744   /* 16-bit upper half section relative relocation.  */
    745   HOWTO (R_PPC_SECTOFF_HI,	/* type */
    746 	 16,			/* rightshift */
    747 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    748 	 16,			/* bitsize */
    749 	 FALSE,			/* pc_relative */
    750 	 0,			/* bitpos */
    751 	 complain_overflow_dont, /* complain_on_overflow */
    752 	 bfd_elf_generic_reloc,	/* special_function */
    753 	 "R_PPC_SECTOFF_HI",	/* name */
    754 	 FALSE,			/* partial_inplace */
    755 	 0,			/* src_mask */
    756 	 0xffff,		/* dst_mask */
    757 	 FALSE),		 /* pcrel_offset */
    758 
    759   /* 16-bit upper half adjusted section relative relocation.  */
    760   HOWTO (R_PPC_SECTOFF_HA,	/* type */
    761 	 16,			/* rightshift */
    762 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    763 	 16,			/* bitsize */
    764 	 FALSE,			/* pc_relative */
    765 	 0,			/* bitpos */
    766 	 complain_overflow_dont, /* complain_on_overflow */
    767 	 ppc_elf_addr16_ha_reloc, /* special_function */
    768 	 "R_PPC_SECTOFF_HA",	/* name */
    769 	 FALSE,			/* partial_inplace */
    770 	 0,			/* src_mask */
    771 	 0xffff,		/* dst_mask */
    772 	 FALSE),		/* pcrel_offset */
    773 
    774   /* Marker relocs for TLS.  */
    775   HOWTO (R_PPC_TLS,
    776 	 0,			/* rightshift */
    777 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    778 	 32,			/* bitsize */
    779 	 FALSE,			/* pc_relative */
    780 	 0,			/* bitpos */
    781 	 complain_overflow_dont, /* complain_on_overflow */
    782 	 bfd_elf_generic_reloc,	/* special_function */
    783 	 "R_PPC_TLS",		/* name */
    784 	 FALSE,			/* partial_inplace */
    785 	 0,			/* src_mask */
    786 	 0,			/* dst_mask */
    787 	 FALSE),		/* pcrel_offset */
    788 
    789   HOWTO (R_PPC_TLSGD,
    790 	 0,			/* rightshift */
    791 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    792 	 32,			/* bitsize */
    793 	 FALSE,			/* pc_relative */
    794 	 0,			/* bitpos */
    795 	 complain_overflow_dont, /* complain_on_overflow */
    796 	 bfd_elf_generic_reloc, /* special_function */
    797 	 "R_PPC_TLSGD",		/* name */
    798 	 FALSE,			/* partial_inplace */
    799 	 0,			/* src_mask */
    800 	 0,			/* dst_mask */
    801 	 FALSE),		/* pcrel_offset */
    802 
    803   HOWTO (R_PPC_TLSLD,
    804 	 0,			/* rightshift */
    805 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    806 	 32,			/* bitsize */
    807 	 FALSE,			/* pc_relative */
    808 	 0,			/* bitpos */
    809 	 complain_overflow_dont, /* complain_on_overflow */
    810 	 bfd_elf_generic_reloc, /* special_function */
    811 	 "R_PPC_TLSLD",		/* name */
    812 	 FALSE,			/* partial_inplace */
    813 	 0,			/* src_mask */
    814 	 0,			/* dst_mask */
    815 	 FALSE),		/* pcrel_offset */
    816 
    817   /* Computes the load module index of the load module that contains the
    818      definition of its TLS sym.  */
    819   HOWTO (R_PPC_DTPMOD32,
    820 	 0,			/* rightshift */
    821 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    822 	 32,			/* bitsize */
    823 	 FALSE,			/* pc_relative */
    824 	 0,			/* bitpos */
    825 	 complain_overflow_dont, /* complain_on_overflow */
    826 	 ppc_elf_unhandled_reloc, /* special_function */
    827 	 "R_PPC_DTPMOD32",	/* name */
    828 	 FALSE,			/* partial_inplace */
    829 	 0,			/* src_mask */
    830 	 0xffffffff,		/* dst_mask */
    831 	 FALSE),		/* pcrel_offset */
    832 
    833   /* Computes a dtv-relative displacement, the difference between the value
    834      of sym+add and the base address of the thread-local storage block that
    835      contains the definition of sym, minus 0x8000.  */
    836   HOWTO (R_PPC_DTPREL32,
    837 	 0,			/* rightshift */
    838 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    839 	 32,			/* bitsize */
    840 	 FALSE,			/* pc_relative */
    841 	 0,			/* bitpos */
    842 	 complain_overflow_dont, /* complain_on_overflow */
    843 	 ppc_elf_unhandled_reloc, /* special_function */
    844 	 "R_PPC_DTPREL32",	/* name */
    845 	 FALSE,			/* partial_inplace */
    846 	 0,			/* src_mask */
    847 	 0xffffffff,		/* dst_mask */
    848 	 FALSE),		/* pcrel_offset */
    849 
    850   /* A 16 bit dtprel reloc.  */
    851   HOWTO (R_PPC_DTPREL16,
    852 	 0,			/* rightshift */
    853 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    854 	 16,			/* bitsize */
    855 	 FALSE,			/* pc_relative */
    856 	 0,			/* bitpos */
    857 	 complain_overflow_signed, /* complain_on_overflow */
    858 	 ppc_elf_unhandled_reloc, /* special_function */
    859 	 "R_PPC_DTPREL16",	/* name */
    860 	 FALSE,			/* partial_inplace */
    861 	 0,			/* src_mask */
    862 	 0xffff,		/* dst_mask */
    863 	 FALSE),		/* pcrel_offset */
    864 
    865   /* Like DTPREL16, but no overflow.  */
    866   HOWTO (R_PPC_DTPREL16_LO,
    867 	 0,			/* rightshift */
    868 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    869 	 16,			/* bitsize */
    870 	 FALSE,			/* pc_relative */
    871 	 0,			/* bitpos */
    872 	 complain_overflow_dont, /* complain_on_overflow */
    873 	 ppc_elf_unhandled_reloc, /* special_function */
    874 	 "R_PPC_DTPREL16_LO",	/* name */
    875 	 FALSE,			/* partial_inplace */
    876 	 0,			/* src_mask */
    877 	 0xffff,		/* dst_mask */
    878 	 FALSE),		/* pcrel_offset */
    879 
    880   /* Like DTPREL16_LO, but next higher group of 16 bits.  */
    881   HOWTO (R_PPC_DTPREL16_HI,
    882 	 16,			/* rightshift */
    883 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    884 	 16,			/* bitsize */
    885 	 FALSE,			/* pc_relative */
    886 	 0,			/* bitpos */
    887 	 complain_overflow_dont, /* complain_on_overflow */
    888 	 ppc_elf_unhandled_reloc, /* special_function */
    889 	 "R_PPC_DTPREL16_HI",	/* name */
    890 	 FALSE,			/* partial_inplace */
    891 	 0,			/* src_mask */
    892 	 0xffff,		/* dst_mask */
    893 	 FALSE),		/* pcrel_offset */
    894 
    895   /* Like DTPREL16_HI, but adjust for low 16 bits.  */
    896   HOWTO (R_PPC_DTPREL16_HA,
    897 	 16,			/* rightshift */
    898 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    899 	 16,			/* bitsize */
    900 	 FALSE,			/* pc_relative */
    901 	 0,			/* bitpos */
    902 	 complain_overflow_dont, /* complain_on_overflow */
    903 	 ppc_elf_unhandled_reloc, /* special_function */
    904 	 "R_PPC_DTPREL16_HA",	/* name */
    905 	 FALSE,			/* partial_inplace */
    906 	 0,			/* src_mask */
    907 	 0xffff,		/* dst_mask */
    908 	 FALSE),		/* pcrel_offset */
    909 
    910   /* Computes a tp-relative displacement, the difference between the value of
    911      sym+add and the value of the thread pointer (r13).  */
    912   HOWTO (R_PPC_TPREL32,
    913 	 0,			/* rightshift */
    914 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    915 	 32,			/* bitsize */
    916 	 FALSE,			/* pc_relative */
    917 	 0,			/* bitpos */
    918 	 complain_overflow_dont, /* complain_on_overflow */
    919 	 ppc_elf_unhandled_reloc, /* special_function */
    920 	 "R_PPC_TPREL32",	/* name */
    921 	 FALSE,			/* partial_inplace */
    922 	 0,			/* src_mask */
    923 	 0xffffffff,		/* dst_mask */
    924 	 FALSE),		/* pcrel_offset */
    925 
    926   /* A 16 bit tprel reloc.  */
    927   HOWTO (R_PPC_TPREL16,
    928 	 0,			/* rightshift */
    929 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    930 	 16,			/* bitsize */
    931 	 FALSE,			/* pc_relative */
    932 	 0,			/* bitpos */
    933 	 complain_overflow_signed, /* complain_on_overflow */
    934 	 ppc_elf_unhandled_reloc, /* special_function */
    935 	 "R_PPC_TPREL16",	/* name */
    936 	 FALSE,			/* partial_inplace */
    937 	 0,			/* src_mask */
    938 	 0xffff,		/* dst_mask */
    939 	 FALSE),		/* pcrel_offset */
    940 
    941   /* Like TPREL16, but no overflow.  */
    942   HOWTO (R_PPC_TPREL16_LO,
    943 	 0,			/* rightshift */
    944 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    945 	 16,			/* bitsize */
    946 	 FALSE,			/* pc_relative */
    947 	 0,			/* bitpos */
    948 	 complain_overflow_dont, /* complain_on_overflow */
    949 	 ppc_elf_unhandled_reloc, /* special_function */
    950 	 "R_PPC_TPREL16_LO",	/* name */
    951 	 FALSE,			/* partial_inplace */
    952 	 0,			/* src_mask */
    953 	 0xffff,		/* dst_mask */
    954 	 FALSE),		/* pcrel_offset */
    955 
    956   /* Like TPREL16_LO, but next higher group of 16 bits.  */
    957   HOWTO (R_PPC_TPREL16_HI,
    958 	 16,			/* rightshift */
    959 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    960 	 16,			/* bitsize */
    961 	 FALSE,			/* pc_relative */
    962 	 0,			/* bitpos */
    963 	 complain_overflow_dont, /* complain_on_overflow */
    964 	 ppc_elf_unhandled_reloc, /* special_function */
    965 	 "R_PPC_TPREL16_HI",	/* name */
    966 	 FALSE,			/* partial_inplace */
    967 	 0,			/* src_mask */
    968 	 0xffff,		/* dst_mask */
    969 	 FALSE),		/* pcrel_offset */
    970 
    971   /* Like TPREL16_HI, but adjust for low 16 bits.  */
    972   HOWTO (R_PPC_TPREL16_HA,
    973 	 16,			/* rightshift */
    974 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    975 	 16,			/* bitsize */
    976 	 FALSE,			/* pc_relative */
    977 	 0,			/* bitpos */
    978 	 complain_overflow_dont, /* complain_on_overflow */
    979 	 ppc_elf_unhandled_reloc, /* special_function */
    980 	 "R_PPC_TPREL16_HA",	/* name */
    981 	 FALSE,			/* partial_inplace */
    982 	 0,			/* src_mask */
    983 	 0xffff,		/* dst_mask */
    984 	 FALSE),		/* pcrel_offset */
    985 
    986   /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
    987      with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
    988      to the first entry.  */
    989   HOWTO (R_PPC_GOT_TLSGD16,
    990 	 0,			/* rightshift */
    991 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    992 	 16,			/* bitsize */
    993 	 FALSE,			/* pc_relative */
    994 	 0,			/* bitpos */
    995 	 complain_overflow_signed, /* complain_on_overflow */
    996 	 ppc_elf_unhandled_reloc, /* special_function */
    997 	 "R_PPC_GOT_TLSGD16",	/* name */
    998 	 FALSE,			/* partial_inplace */
    999 	 0,			/* src_mask */
   1000 	 0xffff,		/* dst_mask */
   1001 	 FALSE),		/* pcrel_offset */
   1002 
   1003   /* Like GOT_TLSGD16, but no overflow.  */
   1004   HOWTO (R_PPC_GOT_TLSGD16_LO,
   1005 	 0,			/* rightshift */
   1006 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1007 	 16,			/* bitsize */
   1008 	 FALSE,			/* pc_relative */
   1009 	 0,			/* bitpos */
   1010 	 complain_overflow_dont, /* complain_on_overflow */
   1011 	 ppc_elf_unhandled_reloc, /* special_function */
   1012 	 "R_PPC_GOT_TLSGD16_LO", /* name */
   1013 	 FALSE,			/* partial_inplace */
   1014 	 0,			/* src_mask */
   1015 	 0xffff,		/* dst_mask */
   1016 	 FALSE),		/* pcrel_offset */
   1017 
   1018   /* Like GOT_TLSGD16_LO, but next higher group of 16 bits.  */
   1019   HOWTO (R_PPC_GOT_TLSGD16_HI,
   1020 	 16,			/* rightshift */
   1021 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1022 	 16,			/* bitsize */
   1023 	 FALSE,			/* pc_relative */
   1024 	 0,			/* bitpos */
   1025 	 complain_overflow_dont, /* complain_on_overflow */
   1026 	 ppc_elf_unhandled_reloc, /* special_function */
   1027 	 "R_PPC_GOT_TLSGD16_HI", /* name */
   1028 	 FALSE,			/* partial_inplace */
   1029 	 0,			/* src_mask */
   1030 	 0xffff,		/* dst_mask */
   1031 	 FALSE),		/* pcrel_offset */
   1032 
   1033   /* Like GOT_TLSGD16_HI, but adjust for low 16 bits.  */
   1034   HOWTO (R_PPC_GOT_TLSGD16_HA,
   1035 	 16,			/* rightshift */
   1036 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1037 	 16,			/* bitsize */
   1038 	 FALSE,			/* pc_relative */
   1039 	 0,			/* bitpos */
   1040 	 complain_overflow_dont, /* complain_on_overflow */
   1041 	 ppc_elf_unhandled_reloc, /* special_function */
   1042 	 "R_PPC_GOT_TLSGD16_HA", /* name */
   1043 	 FALSE,			/* partial_inplace */
   1044 	 0,			/* src_mask */
   1045 	 0xffff,		/* dst_mask */
   1046 	 FALSE),		/* pcrel_offset */
   1047 
   1048   /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
   1049      with values (sym+add)@dtpmod and zero, and computes the offset to the
   1050      first entry.  */
   1051   HOWTO (R_PPC_GOT_TLSLD16,
   1052 	 0,			/* rightshift */
   1053 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1054 	 16,			/* bitsize */
   1055 	 FALSE,			/* pc_relative */
   1056 	 0,			/* bitpos */
   1057 	 complain_overflow_signed, /* complain_on_overflow */
   1058 	 ppc_elf_unhandled_reloc, /* special_function */
   1059 	 "R_PPC_GOT_TLSLD16",	/* name */
   1060 	 FALSE,			/* partial_inplace */
   1061 	 0,			/* src_mask */
   1062 	 0xffff,		/* dst_mask */
   1063 	 FALSE),		/* pcrel_offset */
   1064 
   1065   /* Like GOT_TLSLD16, but no overflow.  */
   1066   HOWTO (R_PPC_GOT_TLSLD16_LO,
   1067 	 0,			/* rightshift */
   1068 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1069 	 16,			/* bitsize */
   1070 	 FALSE,			/* pc_relative */
   1071 	 0,			/* bitpos */
   1072 	 complain_overflow_dont, /* complain_on_overflow */
   1073 	 ppc_elf_unhandled_reloc, /* special_function */
   1074 	 "R_PPC_GOT_TLSLD16_LO", /* name */
   1075 	 FALSE,			/* partial_inplace */
   1076 	 0,			/* src_mask */
   1077 	 0xffff,		/* dst_mask */
   1078 	 FALSE),		/* pcrel_offset */
   1079 
   1080   /* Like GOT_TLSLD16_LO, but next higher group of 16 bits.  */
   1081   HOWTO (R_PPC_GOT_TLSLD16_HI,
   1082 	 16,			/* rightshift */
   1083 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1084 	 16,			/* bitsize */
   1085 	 FALSE,			/* pc_relative */
   1086 	 0,			/* bitpos */
   1087 	 complain_overflow_dont, /* complain_on_overflow */
   1088 	 ppc_elf_unhandled_reloc, /* special_function */
   1089 	 "R_PPC_GOT_TLSLD16_HI", /* name */
   1090 	 FALSE,			/* partial_inplace */
   1091 	 0,			/* src_mask */
   1092 	 0xffff,		/* dst_mask */
   1093 	 FALSE),		/* pcrel_offset */
   1094 
   1095   /* Like GOT_TLSLD16_HI, but adjust for low 16 bits.  */
   1096   HOWTO (R_PPC_GOT_TLSLD16_HA,
   1097 	 16,			/* rightshift */
   1098 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1099 	 16,			/* bitsize */
   1100 	 FALSE,			/* pc_relative */
   1101 	 0,			/* bitpos */
   1102 	 complain_overflow_dont, /* complain_on_overflow */
   1103 	 ppc_elf_unhandled_reloc, /* special_function */
   1104 	 "R_PPC_GOT_TLSLD16_HA", /* name */
   1105 	 FALSE,			/* partial_inplace */
   1106 	 0,			/* src_mask */
   1107 	 0xffff,		/* dst_mask */
   1108 	 FALSE),		/* pcrel_offset */
   1109 
   1110   /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
   1111      the offset to the entry.  */
   1112   HOWTO (R_PPC_GOT_DTPREL16,
   1113 	 0,			/* rightshift */
   1114 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1115 	 16,			/* bitsize */
   1116 	 FALSE,			/* pc_relative */
   1117 	 0,			/* bitpos */
   1118 	 complain_overflow_signed, /* complain_on_overflow */
   1119 	 ppc_elf_unhandled_reloc, /* special_function */
   1120 	 "R_PPC_GOT_DTPREL16",	/* name */
   1121 	 FALSE,			/* partial_inplace */
   1122 	 0,			/* src_mask */
   1123 	 0xffff,		/* dst_mask */
   1124 	 FALSE),		/* pcrel_offset */
   1125 
   1126   /* Like GOT_DTPREL16, but no overflow.  */
   1127   HOWTO (R_PPC_GOT_DTPREL16_LO,
   1128 	 0,			/* rightshift */
   1129 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1130 	 16,			/* bitsize */
   1131 	 FALSE,			/* pc_relative */
   1132 	 0,			/* bitpos */
   1133 	 complain_overflow_dont, /* complain_on_overflow */
   1134 	 ppc_elf_unhandled_reloc, /* special_function */
   1135 	 "R_PPC_GOT_DTPREL16_LO", /* name */
   1136 	 FALSE,			/* partial_inplace */
   1137 	 0,			/* src_mask */
   1138 	 0xffff,		/* dst_mask */
   1139 	 FALSE),		/* pcrel_offset */
   1140 
   1141   /* Like GOT_DTPREL16_LO, but next higher group of 16 bits.  */
   1142   HOWTO (R_PPC_GOT_DTPREL16_HI,
   1143 	 16,			/* rightshift */
   1144 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1145 	 16,			/* bitsize */
   1146 	 FALSE,			/* pc_relative */
   1147 	 0,			/* bitpos */
   1148 	 complain_overflow_dont, /* complain_on_overflow */
   1149 	 ppc_elf_unhandled_reloc, /* special_function */
   1150 	 "R_PPC_GOT_DTPREL16_HI", /* name */
   1151 	 FALSE,			/* partial_inplace */
   1152 	 0,			/* src_mask */
   1153 	 0xffff,		/* dst_mask */
   1154 	 FALSE),		/* pcrel_offset */
   1155 
   1156   /* Like GOT_DTPREL16_HI, but adjust for low 16 bits.  */
   1157   HOWTO (R_PPC_GOT_DTPREL16_HA,
   1158 	 16,			/* rightshift */
   1159 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1160 	 16,			/* bitsize */
   1161 	 FALSE,			/* pc_relative */
   1162 	 0,			/* bitpos */
   1163 	 complain_overflow_dont, /* complain_on_overflow */
   1164 	 ppc_elf_unhandled_reloc, /* special_function */
   1165 	 "R_PPC_GOT_DTPREL16_HA", /* name */
   1166 	 FALSE,			/* partial_inplace */
   1167 	 0,			/* src_mask */
   1168 	 0xffff,		/* dst_mask */
   1169 	 FALSE),		/* pcrel_offset */
   1170 
   1171   /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
   1172      offset to the entry.  */
   1173   HOWTO (R_PPC_GOT_TPREL16,
   1174 	 0,			/* rightshift */
   1175 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1176 	 16,			/* bitsize */
   1177 	 FALSE,			/* pc_relative */
   1178 	 0,			/* bitpos */
   1179 	 complain_overflow_signed, /* complain_on_overflow */
   1180 	 ppc_elf_unhandled_reloc, /* special_function */
   1181 	 "R_PPC_GOT_TPREL16",	/* name */
   1182 	 FALSE,			/* partial_inplace */
   1183 	 0,			/* src_mask */
   1184 	 0xffff,		/* dst_mask */
   1185 	 FALSE),		/* pcrel_offset */
   1186 
   1187   /* Like GOT_TPREL16, but no overflow.  */
   1188   HOWTO (R_PPC_GOT_TPREL16_LO,
   1189 	 0,			/* rightshift */
   1190 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1191 	 16,			/* bitsize */
   1192 	 FALSE,			/* pc_relative */
   1193 	 0,			/* bitpos */
   1194 	 complain_overflow_dont, /* complain_on_overflow */
   1195 	 ppc_elf_unhandled_reloc, /* special_function */
   1196 	 "R_PPC_GOT_TPREL16_LO", /* name */
   1197 	 FALSE,			/* partial_inplace */
   1198 	 0,			/* src_mask */
   1199 	 0xffff,		/* dst_mask */
   1200 	 FALSE),		/* pcrel_offset */
   1201 
   1202   /* Like GOT_TPREL16_LO, but next higher group of 16 bits.  */
   1203   HOWTO (R_PPC_GOT_TPREL16_HI,
   1204 	 16,			/* rightshift */
   1205 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1206 	 16,			/* bitsize */
   1207 	 FALSE,			/* pc_relative */
   1208 	 0,			/* bitpos */
   1209 	 complain_overflow_dont, /* complain_on_overflow */
   1210 	 ppc_elf_unhandled_reloc, /* special_function */
   1211 	 "R_PPC_GOT_TPREL16_HI", /* name */
   1212 	 FALSE,			/* partial_inplace */
   1213 	 0,			/* src_mask */
   1214 	 0xffff,		/* dst_mask */
   1215 	 FALSE),		/* pcrel_offset */
   1216 
   1217   /* Like GOT_TPREL16_HI, but adjust for low 16 bits.  */
   1218   HOWTO (R_PPC_GOT_TPREL16_HA,
   1219 	 16,			/* rightshift */
   1220 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1221 	 16,			/* bitsize */
   1222 	 FALSE,			/* pc_relative */
   1223 	 0,			/* bitpos */
   1224 	 complain_overflow_dont, /* complain_on_overflow */
   1225 	 ppc_elf_unhandled_reloc, /* special_function */
   1226 	 "R_PPC_GOT_TPREL16_HA", /* name */
   1227 	 FALSE,			/* partial_inplace */
   1228 	 0,			/* src_mask */
   1229 	 0xffff,		/* dst_mask */
   1230 	 FALSE),		/* pcrel_offset */
   1231 
   1232   /* The remaining relocs are from the Embedded ELF ABI, and are not
   1233      in the SVR4 ELF ABI.  */
   1234 
   1235   /* 32 bit value resulting from the addend minus the symbol.  */
   1236   HOWTO (R_PPC_EMB_NADDR32,	/* type */
   1237 	 0,			/* rightshift */
   1238 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1239 	 32,			/* bitsize */
   1240 	 FALSE,			/* pc_relative */
   1241 	 0,			/* bitpos */
   1242 	 complain_overflow_dont, /* complain_on_overflow */
   1243 	 bfd_elf_generic_reloc,	/* special_function */
   1244 	 "R_PPC_EMB_NADDR32",	/* name */
   1245 	 FALSE,			/* partial_inplace */
   1246 	 0,			/* src_mask */
   1247 	 0xffffffff,		/* dst_mask */
   1248 	 FALSE),		/* pcrel_offset */
   1249 
   1250   /* 16 bit value resulting from the addend minus the symbol.  */
   1251   HOWTO (R_PPC_EMB_NADDR16,	/* type */
   1252 	 0,			/* rightshift */
   1253 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1254 	 16,			/* bitsize */
   1255 	 FALSE,			/* pc_relative */
   1256 	 0,			/* bitpos */
   1257 	 complain_overflow_signed, /* complain_on_overflow */
   1258 	 bfd_elf_generic_reloc,	/* special_function */
   1259 	 "R_PPC_EMB_NADDR16",	/* name */
   1260 	 FALSE,			/* partial_inplace */
   1261 	 0,			/* src_mask */
   1262 	 0xffff,		/* dst_mask */
   1263 	 FALSE),		/* pcrel_offset */
   1264 
   1265   /* 16 bit value resulting from the addend minus the symbol.  */
   1266   HOWTO (R_PPC_EMB_NADDR16_LO,	/* type */
   1267 	 0,			/* rightshift */
   1268 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1269 	 16,			/* bitsize */
   1270 	 FALSE,			/* pc_relative */
   1271 	 0,			/* bitpos */
   1272 	 complain_overflow_dont,/* complain_on_overflow */
   1273 	 bfd_elf_generic_reloc,	/* special_function */
   1274 	 "R_PPC_EMB_ADDR16_LO",	/* name */
   1275 	 FALSE,			/* partial_inplace */
   1276 	 0,			/* src_mask */
   1277 	 0xffff,		/* dst_mask */
   1278 	 FALSE),		/* pcrel_offset */
   1279 
   1280   /* The high order 16 bits of the addend minus the symbol.  */
   1281   HOWTO (R_PPC_EMB_NADDR16_HI,	/* type */
   1282 	 16,			/* rightshift */
   1283 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1284 	 16,			/* bitsize */
   1285 	 FALSE,			/* pc_relative */
   1286 	 0,			/* bitpos */
   1287 	 complain_overflow_dont, /* complain_on_overflow */
   1288 	 bfd_elf_generic_reloc,	/* special_function */
   1289 	 "R_PPC_EMB_NADDR16_HI", /* name */
   1290 	 FALSE,			/* partial_inplace */
   1291 	 0,			/* src_mask */
   1292 	 0xffff,		/* dst_mask */
   1293 	 FALSE),		/* pcrel_offset */
   1294 
   1295   /* The high order 16 bits of the result of the addend minus the address,
   1296      plus 1 if the contents of the low 16 bits, treated as a signed number,
   1297      is negative.  */
   1298   HOWTO (R_PPC_EMB_NADDR16_HA,	/* type */
   1299 	 16,			/* rightshift */
   1300 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1301 	 16,			/* bitsize */
   1302 	 FALSE,			/* pc_relative */
   1303 	 0,			/* bitpos */
   1304 	 complain_overflow_dont, /* complain_on_overflow */
   1305 	 ppc_elf_addr16_ha_reloc, /* special_function */
   1306 	 "R_PPC_EMB_NADDR16_HA", /* name */
   1307 	 FALSE,			/* partial_inplace */
   1308 	 0,			/* src_mask */
   1309 	 0xffff,		/* dst_mask */
   1310 	 FALSE),		/* pcrel_offset */
   1311 
   1312   /* 16 bit value resulting from allocating a 4 byte word to hold an
   1313      address in the .sdata section, and returning the offset from
   1314      _SDA_BASE_ for that relocation.  */
   1315   HOWTO (R_PPC_EMB_SDAI16,	/* type */
   1316 	 0,			/* rightshift */
   1317 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1318 	 16,			/* bitsize */
   1319 	 FALSE,			/* pc_relative */
   1320 	 0,			/* bitpos */
   1321 	 complain_overflow_signed, /* complain_on_overflow */
   1322 	 bfd_elf_generic_reloc,	/* special_function */
   1323 	 "R_PPC_EMB_SDAI16",	/* name */
   1324 	 FALSE,			/* partial_inplace */
   1325 	 0,			/* src_mask */
   1326 	 0xffff,		/* dst_mask */
   1327 	 FALSE),		/* pcrel_offset */
   1328 
   1329   /* 16 bit value resulting from allocating a 4 byte word to hold an
   1330      address in the .sdata2 section, and returning the offset from
   1331      _SDA2_BASE_ for that relocation.  */
   1332   HOWTO (R_PPC_EMB_SDA2I16,	/* type */
   1333 	 0,			/* rightshift */
   1334 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1335 	 16,			/* bitsize */
   1336 	 FALSE,			/* pc_relative */
   1337 	 0,			/* bitpos */
   1338 	 complain_overflow_signed, /* complain_on_overflow */
   1339 	 bfd_elf_generic_reloc,	/* special_function */
   1340 	 "R_PPC_EMB_SDA2I16",	/* name */
   1341 	 FALSE,			/* partial_inplace */
   1342 	 0,			/* src_mask */
   1343 	 0xffff,		/* dst_mask */
   1344 	 FALSE),		/* pcrel_offset */
   1345 
   1346   /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
   1347      small data items.	 */
   1348   HOWTO (R_PPC_EMB_SDA2REL,	/* type */
   1349 	 0,			/* rightshift */
   1350 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1351 	 16,			/* bitsize */
   1352 	 FALSE,			/* pc_relative */
   1353 	 0,			/* bitpos */
   1354 	 complain_overflow_signed, /* complain_on_overflow */
   1355 	 bfd_elf_generic_reloc,	/* special_function */
   1356 	 "R_PPC_EMB_SDA2REL",	/* name */
   1357 	 FALSE,			/* partial_inplace */
   1358 	 0,			/* src_mask */
   1359 	 0xffff,		/* dst_mask */
   1360 	 FALSE),		/* pcrel_offset */
   1361 
   1362   /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
   1363      signed offset from the appropriate base, and filling in the register
   1364      field with the appropriate register (0, 2, or 13).  */
   1365   HOWTO (R_PPC_EMB_SDA21,	/* type */
   1366 	 0,			/* rightshift */
   1367 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1368 	 16,			/* bitsize */
   1369 	 FALSE,			/* pc_relative */
   1370 	 0,			/* bitpos */
   1371 	 complain_overflow_signed, /* complain_on_overflow */
   1372 	 bfd_elf_generic_reloc,	/* special_function */
   1373 	 "R_PPC_EMB_SDA21",	/* name */
   1374 	 FALSE,			/* partial_inplace */
   1375 	 0,			/* src_mask */
   1376 	 0xffff,		/* dst_mask */
   1377 	 FALSE),		/* pcrel_offset */
   1378 
   1379   /* Relocation not handled: R_PPC_EMB_MRKREF */
   1380   /* Relocation not handled: R_PPC_EMB_RELSEC16 */
   1381   /* Relocation not handled: R_PPC_EMB_RELST_LO */
   1382   /* Relocation not handled: R_PPC_EMB_RELST_HI */
   1383   /* Relocation not handled: R_PPC_EMB_RELST_HA */
   1384   /* Relocation not handled: R_PPC_EMB_BIT_FLD */
   1385 
   1386   /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
   1387      in the 16 bit signed offset from the appropriate base, and filling in the
   1388      register field with the appropriate register (0, 2, or 13).  */
   1389   HOWTO (R_PPC_EMB_RELSDA,	/* type */
   1390 	 0,			/* rightshift */
   1391 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1392 	 16,			/* bitsize */
   1393 	 FALSE,			/* pc_relative */
   1394 	 0,			/* bitpos */
   1395 	 complain_overflow_signed, /* complain_on_overflow */
   1396 	 bfd_elf_generic_reloc,	/* special_function */
   1397 	 "R_PPC_EMB_RELSDA",	/* name */
   1398 	 FALSE,			/* partial_inplace */
   1399 	 0,			/* src_mask */
   1400 	 0xffff,		/* dst_mask */
   1401 	 FALSE),		/* pcrel_offset */
   1402 
   1403   /* A relative 8 bit branch.  */
   1404   HOWTO (R_PPC_VLE_REL8,	/* type */
   1405 	 1,			/* rightshift */
   1406 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1407 	 8,			/* bitsize */
   1408 	 TRUE,			/* pc_relative */
   1409 	 0,			/* bitpos */
   1410 	 complain_overflow_signed, /* complain_on_overflow */
   1411 	 bfd_elf_generic_reloc,	/* special_function */
   1412 	 "R_PPC_VLE_REL8",	/* name */
   1413 	 FALSE,			/* partial_inplace */
   1414 	 0,			/* src_mask */
   1415 	 0xff,			/* dst_mask */
   1416 	 TRUE),			/* pcrel_offset */
   1417 
   1418   /* A relative 15 bit branch.  */
   1419   HOWTO (R_PPC_VLE_REL15,	/* type */
   1420 	 1,			/* rightshift */
   1421 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1422 	 15,			/* bitsize */
   1423 	 TRUE,			/* pc_relative */
   1424 	 1,			/* bitpos */
   1425 	 complain_overflow_signed, /* complain_on_overflow */
   1426 	 bfd_elf_generic_reloc,	/* special_function */
   1427 	 "R_PPC_VLE_REL15",	/* name */
   1428 	 FALSE,			/* partial_inplace */
   1429 	 0,			/* src_mask */
   1430 	 0xfe,			/* dst_mask */
   1431 	 TRUE),			/* pcrel_offset */
   1432 
   1433   /* A relative 24 bit branch.  */
   1434   HOWTO (R_PPC_VLE_REL24,	/* type */
   1435 	 1,			/* rightshift */
   1436 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1437 	 24,			/* bitsize */
   1438 	 TRUE,			/* pc_relative */
   1439 	 1,			/* bitpos */
   1440 	 complain_overflow_signed, /* complain_on_overflow */
   1441 	 bfd_elf_generic_reloc,	/* special_function */
   1442 	 "R_PPC_VLE_REL24",	/* name */
   1443 	 FALSE,			/* partial_inplace */
   1444 	 0,			/* src_mask */
   1445 	 0x1fffffe,		/* dst_mask */
   1446 	 TRUE),			/* pcrel_offset */
   1447 
   1448   /* The 16 LSBS in split16a format.  */
   1449   HOWTO (R_PPC_VLE_LO16A,	/* type */
   1450 	 0,			/* rightshift */
   1451 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1452 	 16,			/* bitsize */
   1453 	 FALSE,			/* pc_relative */
   1454 	 0,			/* bitpos */
   1455 	 complain_overflow_dont, /* complain_on_overflow */
   1456 	 bfd_elf_generic_reloc,	 /* special_function */
   1457 	 "R_PPC_VLE_LO16A",	/* name */
   1458 	 FALSE,			/* partial_inplace */
   1459 	 0,			/* src_mask */
   1460 	 0x1f007ff,		/* dst_mask */
   1461 	 FALSE),		/* pcrel_offset */
   1462 
   1463   /* The 16 LSBS in split16d format.  */
   1464   HOWTO (R_PPC_VLE_LO16D,	/* type */
   1465 	 0,			/* rightshift */
   1466 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1467 	 16,			/* bitsize */
   1468 	 FALSE,			/* pc_relative */
   1469 	 0,			/* bitpos */
   1470 	 complain_overflow_dont, /* complain_on_overflow */
   1471 	 bfd_elf_generic_reloc,	 /* special_function */
   1472 	 "R_PPC_VLE_LO16D",		/* name */
   1473 	 FALSE,			/* partial_inplace */
   1474 	 0,			/* src_mask */
   1475 	 0x1f07ff,		/* dst_mask */
   1476 	 FALSE),		/* pcrel_offset */
   1477 
   1478   /* Bits 16-31 split16a format.  */
   1479   HOWTO (R_PPC_VLE_HI16A,	/* type */
   1480 	 16,			/* rightshift */
   1481 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1482 	 16,			/* bitsize */
   1483 	 FALSE,			/* pc_relative */
   1484 	 0,			/* bitpos */
   1485 	 complain_overflow_dont, /* complain_on_overflow */
   1486 	 bfd_elf_generic_reloc,	 /* special_function */
   1487 	 "R_PPC_VLE_HI16A",		/* name */
   1488 	 FALSE,			/* partial_inplace */
   1489 	 0,			/* src_mask */
   1490 	 0x1f007ff,		/* dst_mask */
   1491 	 FALSE),		/* pcrel_offset */
   1492 
   1493   /* Bits 16-31 split16d format.  */
   1494   HOWTO (R_PPC_VLE_HI16D,	/* type */
   1495 	 16,			/* rightshift */
   1496 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1497 	 16,			/* bitsize */
   1498 	 FALSE,			/* pc_relative */
   1499 	 0,			/* bitpos */
   1500 	 complain_overflow_dont, /* complain_on_overflow */
   1501 	 bfd_elf_generic_reloc,	 /* special_function */
   1502 	 "R_PPC_VLE_HI16D",		/* name */
   1503 	 FALSE,			/* partial_inplace */
   1504 	 0,			/* src_mask */
   1505 	 0x1f07ff,		/* dst_mask */
   1506 	 FALSE),		/* pcrel_offset */
   1507 
   1508   /* Bits 16-31 (High Adjusted) in split16a format.  */
   1509   HOWTO (R_PPC_VLE_HA16A,	/* type */
   1510 	 16,			/* rightshift */
   1511 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1512 	 16,			/* bitsize */
   1513 	 FALSE,			/* pc_relative */
   1514 	 0,			/* bitpos */
   1515 	 complain_overflow_dont, /* complain_on_overflow */
   1516 	 bfd_elf_generic_reloc,	 /* special_function */
   1517 	 "R_PPC_VLE_HA16A",		/* name */
   1518 	 FALSE,			/* partial_inplace */
   1519 	 0,			/* src_mask */
   1520 	 0x1f007ff,		/* dst_mask */
   1521 	 FALSE),		/* pcrel_offset */
   1522 
   1523   /* Bits 16-31 (High Adjusted) in split16d format.  */
   1524   HOWTO (R_PPC_VLE_HA16D,	/* type */
   1525 	 16,			/* rightshift */
   1526 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1527 	 16,			/* bitsize */
   1528 	 FALSE,			/* pc_relative */
   1529 	 0,			/* bitpos */
   1530 	 complain_overflow_dont, /* complain_on_overflow */
   1531 	 bfd_elf_generic_reloc,	 /* special_function */
   1532 	 "R_PPC_VLE_HA16D",		/* name */
   1533 	 FALSE,			/* partial_inplace */
   1534 	 0,			/* src_mask */
   1535 	 0x1f07ff,		/* dst_mask */
   1536 	 FALSE),		/* pcrel_offset */
   1537 
   1538   /* This reloc is like R_PPC_EMB_SDA21 but only applies to e_add16i
   1539      instructions.  If the register base is 0 then the linker changes
   1540      the e_add16i to an e_li instruction.  */
   1541   HOWTO (R_PPC_VLE_SDA21,	/* type */
   1542 	 0,			/* rightshift */
   1543 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1544 	 16,			/* bitsize */
   1545 	 FALSE,			/* pc_relative */
   1546 	 0,			/* bitpos */
   1547 	 complain_overflow_signed, /* complain_on_overflow */
   1548 	 bfd_elf_generic_reloc,	/* special_function */
   1549 	 "R_PPC_VLE_SDA21",		/* name */
   1550 	 FALSE,			/* partial_inplace */
   1551 	 0,			/* src_mask */
   1552 	 0xffff,		/* dst_mask */
   1553 	 FALSE),		/* pcrel_offset */
   1554 
   1555   /* Like R_PPC_VLE_SDA21 but ignore overflow.  */
   1556   HOWTO (R_PPC_VLE_SDA21_LO,	/* type */
   1557 	 0,			/* rightshift */
   1558 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1559 	 16,			/* bitsize */
   1560 	 FALSE,			/* pc_relative */
   1561 	 0,			/* bitpos */
   1562 	 complain_overflow_dont, /* complain_on_overflow */
   1563 	 bfd_elf_generic_reloc,	/* special_function */
   1564 	 "R_PPC_VLE_SDA21_LO",	/* name */
   1565 	 FALSE,			/* partial_inplace */
   1566 	 0,			/* src_mask */
   1567 	 0xffff,		/* dst_mask */
   1568 	 FALSE),		/* pcrel_offset */
   1569 
   1570   /* The 16 LSBS relative to _SDA_BASE_ in split16a format.  */
   1571   HOWTO (R_PPC_VLE_SDAREL_LO16A,/* type */
   1572 	 0,			/* rightshift */
   1573 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1574 	 16,			/* bitsize */
   1575 	 FALSE,			/* pc_relative */
   1576 	 0,			/* bitpos */
   1577 	 complain_overflow_dont,	/* complain_on_overflow */
   1578 	 bfd_elf_generic_reloc,	 /* special_function */
   1579 	 "R_PPC_VLE_SDAREL_LO16A",	/* name */
   1580 	 FALSE,			/* partial_inplace */
   1581 	 0,			/* src_mask */
   1582 	 0x1f007ff,		/* dst_mask */
   1583 	 FALSE),		/* pcrel_offset */
   1584 
   1585   /* The 16 LSBS relative to _SDA_BASE_ in split16d format.  */
   1586   HOWTO (R_PPC_VLE_SDAREL_LO16D, /* type */
   1587 	 0,			/* rightshift */
   1588 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1589 	 16,			/* bitsize */
   1590 	 FALSE,			/* pc_relative */
   1591 	 0,			/* bitpos */
   1592 	 complain_overflow_dont,	/* complain_on_overflow */
   1593 	 bfd_elf_generic_reloc,	 /* special_function */
   1594 	 "R_PPC_VLE_SDAREL_LO16D",		/* name */
   1595 	 FALSE,			/* partial_inplace */
   1596 	 0,			/* src_mask */
   1597 	 0x1f07ff,		/* dst_mask */
   1598 	 FALSE),		/* pcrel_offset */
   1599 
   1600   /* Bits 16-31 relative to _SDA_BASE_ in split16a format.  */
   1601   HOWTO (R_PPC_VLE_SDAREL_HI16A,	/* type */
   1602 	 16,			/* rightshift */
   1603 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1604 	 16,			/* bitsize */
   1605 	 FALSE,			/* pc_relative */
   1606 	 0,			/* bitpos */
   1607 	 complain_overflow_dont,	/* complain_on_overflow */
   1608 	 bfd_elf_generic_reloc,	 /* special_function */
   1609 	 "R_PPC_VLE_SDAREL_HI16A",	/* name */
   1610 	 FALSE,			/* partial_inplace */
   1611 	 0,			/* src_mask */
   1612 	 0x1f007ff,		/* dst_mask */
   1613 	 FALSE),		/* pcrel_offset */
   1614 
   1615   /* Bits 16-31 relative to _SDA_BASE_ in split16d format.  */
   1616   HOWTO (R_PPC_VLE_SDAREL_HI16D,	/* type */
   1617 	 16,			/* rightshift */
   1618 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1619 	 16,			/* bitsize */
   1620 	 FALSE,			/* pc_relative */
   1621 	 0,			/* bitpos */
   1622 	 complain_overflow_dont,	/* complain_on_overflow */
   1623 	 bfd_elf_generic_reloc,	 /* special_function */
   1624 	 "R_PPC_VLE_SDAREL_HI16D",	/* name */
   1625 	 FALSE,			/* partial_inplace */
   1626 	 0,			/* src_mask */
   1627 	 0x1f07ff,		/* dst_mask */
   1628 	 FALSE),		/* pcrel_offset */
   1629 
   1630   /* Bits 16-31 (HA) relative to _SDA_BASE split16a format.  */
   1631   HOWTO (R_PPC_VLE_SDAREL_HA16A,	/* type */
   1632 	 16,			/* rightshift */
   1633 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1634 	 16,			/* bitsize */
   1635 	 FALSE,			/* pc_relative */
   1636 	 0,			/* bitpos */
   1637 	 complain_overflow_dont,	/* complain_on_overflow */
   1638 	 bfd_elf_generic_reloc,	 /* special_function */
   1639 	 "R_PPC_VLE_SDAREL_HA16A",	/* name */
   1640 	 FALSE,			/* partial_inplace */
   1641 	 0,			/* src_mask */
   1642 	 0x1f007ff,		/* dst_mask */
   1643 	 FALSE),		/* pcrel_offset */
   1644 
   1645   /* Bits 16-31 (HA) relative to _SDA_BASE split16d format.  */
   1646   HOWTO (R_PPC_VLE_SDAREL_HA16D,	/* type */
   1647 	 16,			/* rightshift */
   1648 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1649 	 16,			/* bitsize */
   1650 	 FALSE,			/* pc_relative */
   1651 	 0,			/* bitpos */
   1652 	 complain_overflow_dont,	/* complain_on_overflow */
   1653 	 bfd_elf_generic_reloc,	 /* special_function */
   1654 	 "R_PPC_VLE_SDAREL_HA16D",	/* name */
   1655 	 FALSE,			/* partial_inplace */
   1656 	 0,			/* src_mask */
   1657 	 0x1f07ff,		/* dst_mask */
   1658 	 FALSE),		/* pcrel_offset */
   1659 
   1660   HOWTO (R_PPC_IRELATIVE,	/* type */
   1661 	 0,			/* rightshift */
   1662 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1663 	 32,			/* bitsize */
   1664 	 FALSE,			/* pc_relative */
   1665 	 0,			/* bitpos */
   1666 	 complain_overflow_dont, /* complain_on_overflow */
   1667 	 bfd_elf_generic_reloc,	 /* special_function */
   1668 	 "R_PPC_IRELATIVE",	/* name */
   1669 	 FALSE,			/* partial_inplace */
   1670 	 0,			/* src_mask */
   1671 	 0xffffffff,		/* dst_mask */
   1672 	 FALSE),		/* pcrel_offset */
   1673 
   1674   /* A 16 bit relative relocation.  */
   1675   HOWTO (R_PPC_REL16,		/* type */
   1676 	 0,			/* rightshift */
   1677 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1678 	 16,			/* bitsize */
   1679 	 TRUE,			/* pc_relative */
   1680 	 0,			/* bitpos */
   1681 	 complain_overflow_signed, /* complain_on_overflow */
   1682 	 bfd_elf_generic_reloc,	/* special_function */
   1683 	 "R_PPC_REL16",		/* name */
   1684 	 FALSE,			/* partial_inplace */
   1685 	 0,			/* src_mask */
   1686 	 0xffff,		/* dst_mask */
   1687 	 TRUE),			/* pcrel_offset */
   1688 
   1689   /* A 16 bit relative relocation without overflow.  */
   1690   HOWTO (R_PPC_REL16_LO,	/* type */
   1691 	 0,			/* rightshift */
   1692 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1693 	 16,			/* bitsize */
   1694 	 TRUE,			/* pc_relative */
   1695 	 0,			/* bitpos */
   1696 	 complain_overflow_dont,/* complain_on_overflow */
   1697 	 bfd_elf_generic_reloc,	/* special_function */
   1698 	 "R_PPC_REL16_LO",	/* name */
   1699 	 FALSE,			/* partial_inplace */
   1700 	 0,			/* src_mask */
   1701 	 0xffff,		/* dst_mask */
   1702 	 TRUE),			/* pcrel_offset */
   1703 
   1704   /* The high order 16 bits of a relative address.  */
   1705   HOWTO (R_PPC_REL16_HI,	/* type */
   1706 	 16,			/* rightshift */
   1707 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1708 	 16,			/* bitsize */
   1709 	 TRUE,			/* pc_relative */
   1710 	 0,			/* bitpos */
   1711 	 complain_overflow_dont, /* complain_on_overflow */
   1712 	 bfd_elf_generic_reloc,	/* special_function */
   1713 	 "R_PPC_REL16_HI",	/* name */
   1714 	 FALSE,			/* partial_inplace */
   1715 	 0,			/* src_mask */
   1716 	 0xffff,		/* dst_mask */
   1717 	 TRUE),			/* pcrel_offset */
   1718 
   1719   /* The high order 16 bits of a relative address, plus 1 if the contents of
   1720      the low 16 bits, treated as a signed number, is negative.  */
   1721   HOWTO (R_PPC_REL16_HA,	/* type */
   1722 	 16,			/* rightshift */
   1723 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1724 	 16,			/* bitsize */
   1725 	 TRUE,			/* pc_relative */
   1726 	 0,			/* bitpos */
   1727 	 complain_overflow_dont, /* complain_on_overflow */
   1728 	 ppc_elf_addr16_ha_reloc, /* special_function */
   1729 	 "R_PPC_REL16_HA",	/* name */
   1730 	 FALSE,			/* partial_inplace */
   1731 	 0,			/* src_mask */
   1732 	 0xffff,		/* dst_mask */
   1733 	 TRUE),			/* pcrel_offset */
   1734 
   1735   /* GNU extension to record C++ vtable hierarchy.  */
   1736   HOWTO (R_PPC_GNU_VTINHERIT,	/* type */
   1737 	 0,			/* rightshift */
   1738 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
   1739 	 0,			/* bitsize */
   1740 	 FALSE,			/* pc_relative */
   1741 	 0,			/* bitpos */
   1742 	 complain_overflow_dont, /* complain_on_overflow */
   1743 	 NULL,			/* special_function */
   1744 	 "R_PPC_GNU_VTINHERIT",	/* name */
   1745 	 FALSE,			/* partial_inplace */
   1746 	 0,			/* src_mask */
   1747 	 0,			/* dst_mask */
   1748 	 FALSE),		/* pcrel_offset */
   1749 
   1750   /* GNU extension to record C++ vtable member usage.  */
   1751   HOWTO (R_PPC_GNU_VTENTRY,	/* type */
   1752 	 0,			/* rightshift */
   1753 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
   1754 	 0,			/* bitsize */
   1755 	 FALSE,			/* pc_relative */
   1756 	 0,			/* bitpos */
   1757 	 complain_overflow_dont, /* complain_on_overflow */
   1758 	 NULL,			/* special_function */
   1759 	 "R_PPC_GNU_VTENTRY",	/* name */
   1760 	 FALSE,			/* partial_inplace */
   1761 	 0,			/* src_mask */
   1762 	 0,			/* dst_mask */
   1763 	 FALSE),		/* pcrel_offset */
   1764 
   1765   /* Phony reloc to handle AIX style TOC entries.  */
   1766   HOWTO (R_PPC_TOC16,		/* type */
   1767 	 0,			/* rightshift */
   1768 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1769 	 16,			/* bitsize */
   1770 	 FALSE,			/* pc_relative */
   1771 	 0,			/* bitpos */
   1772 	 complain_overflow_signed, /* complain_on_overflow */
   1773 	 bfd_elf_generic_reloc,	/* special_function */
   1774 	 "R_PPC_TOC16",		/* name */
   1775 	 FALSE,			/* partial_inplace */
   1776 	 0,			/* src_mask */
   1777 	 0xffff,		/* dst_mask */
   1778 	 FALSE),		/* pcrel_offset */
   1779 };
   1780 
   1781 /* External 32-bit PPC structure for PRPSINFO.  This structure is
   1782    ABI-defined, thus we choose to use char arrays here in order to
   1783    avoid dealing with different types in different architectures.
   1784 
   1785    The PPC 32-bit structure uses int for `pr_uid' and `pr_gid' while
   1786    most non-PPC architectures use `short int'.
   1787 
   1788    This structure will ultimately be written in the corefile's note
   1789    section, as the PRPSINFO.  */
   1790 
   1791 struct elf_external_ppc_linux_prpsinfo32
   1792   {
   1793     char pr_state;			/* Numeric process state.  */
   1794     char pr_sname;			/* Char for pr_state.  */
   1795     char pr_zomb;			/* Zombie.  */
   1796     char pr_nice;			/* Nice val.  */
   1797     char pr_flag[4];			/* Flags.  */
   1798     char pr_uid[4];
   1799     char pr_gid[4];
   1800     char pr_pid[4];
   1801     char pr_ppid[4];
   1802     char pr_pgrp[4];
   1803     char pr_sid[4];
   1804     char pr_fname[16];			/* Filename of executable.  */
   1805     char pr_psargs[80];			/* Initial part of arg list.  */
   1806   };
   1807 
   1808 /* Helper macro to swap (properly handling endianess) things from the
   1809    `elf_internal_prpsinfo' structure to the `elf_external_ppc_prpsinfo32'
   1810    structure.
   1811 
   1812    Note that FROM should be a pointer, and TO should be the explicit type.  */
   1813 
   1814 #define PPC_LINUX_PRPSINFO32_SWAP_FIELDS(abfd, from, to)	      \
   1815   do								      \
   1816     {								      \
   1817       H_PUT_8 (abfd, from->pr_state, &to.pr_state);		      \
   1818       H_PUT_8 (abfd, from->pr_sname, &to.pr_sname);		      \
   1819       H_PUT_8 (abfd, from->pr_zomb, &to.pr_zomb);		      \
   1820       H_PUT_8 (abfd, from->pr_nice, &to.pr_nice);		      \
   1821       H_PUT_32 (abfd, from->pr_flag, to.pr_flag);		      \
   1822       H_PUT_32 (abfd, from->pr_uid, to.pr_uid);			      \
   1823       H_PUT_32 (abfd, from->pr_gid, to.pr_gid);			      \
   1824       H_PUT_32 (abfd, from->pr_pid, to.pr_pid);			      \
   1825       H_PUT_32 (abfd, from->pr_ppid, to.pr_ppid);		      \
   1826       H_PUT_32 (abfd, from->pr_pgrp, to.pr_pgrp);		      \
   1827       H_PUT_32 (abfd, from->pr_sid, to.pr_sid);			      \
   1828       strncpy (to.pr_fname, from->pr_fname, sizeof (to.pr_fname));    \
   1829       strncpy (to.pr_psargs, from->pr_psargs, sizeof (to.pr_psargs)); \
   1830     } while (0)
   1831 
   1832 
   1833 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done.  */
   1835 
   1836 static void
   1837 ppc_elf_howto_init (void)
   1838 {
   1839   unsigned int i, type;
   1840 
   1841   for (i = 0;
   1842        i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
   1843        i++)
   1844     {
   1845       type = ppc_elf_howto_raw[i].type;
   1846       if (type >= (sizeof (ppc_elf_howto_table)
   1847 		   / sizeof (ppc_elf_howto_table[0])))
   1848 	abort ();
   1849       ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
   1850     }
   1851 }
   1852 
   1853 static reloc_howto_type *
   1854 ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   1855 			   bfd_reloc_code_real_type code)
   1856 {
   1857   enum elf_ppc_reloc_type r;
   1858 
   1859   /* Initialize howto table if not already done.  */
   1860   if (!ppc_elf_howto_table[R_PPC_ADDR32])
   1861     ppc_elf_howto_init ();
   1862 
   1863   switch (code)
   1864     {
   1865     default:
   1866       return NULL;
   1867 
   1868     case BFD_RELOC_NONE:		r = R_PPC_NONE;			break;
   1869     case BFD_RELOC_32:			r = R_PPC_ADDR32;		break;
   1870     case BFD_RELOC_PPC_BA26:		r = R_PPC_ADDR24;		break;
   1871     case BFD_RELOC_PPC64_ADDR16_DS:
   1872     case BFD_RELOC_16:			r = R_PPC_ADDR16;		break;
   1873     case BFD_RELOC_PPC64_ADDR16_LO_DS:
   1874     case BFD_RELOC_LO16:		r = R_PPC_ADDR16_LO;		break;
   1875     case BFD_RELOC_HI16:		r = R_PPC_ADDR16_HI;		break;
   1876     case BFD_RELOC_HI16_S:		r = R_PPC_ADDR16_HA;		break;
   1877     case BFD_RELOC_PPC_BA16:		r = R_PPC_ADDR14;		break;
   1878     case BFD_RELOC_PPC_BA16_BRTAKEN:	r = R_PPC_ADDR14_BRTAKEN;	break;
   1879     case BFD_RELOC_PPC_BA16_BRNTAKEN:	r = R_PPC_ADDR14_BRNTAKEN;	break;
   1880     case BFD_RELOC_PPC_B26:		r = R_PPC_REL24;		break;
   1881     case BFD_RELOC_PPC_B16:		r = R_PPC_REL14;		break;
   1882     case BFD_RELOC_PPC_B16_BRTAKEN:	r = R_PPC_REL14_BRTAKEN;	break;
   1883     case BFD_RELOC_PPC_B16_BRNTAKEN:	r = R_PPC_REL14_BRNTAKEN;	break;
   1884     case BFD_RELOC_PPC64_GOT16_DS:
   1885     case BFD_RELOC_16_GOTOFF:		r = R_PPC_GOT16;		break;
   1886     case BFD_RELOC_PPC64_GOT16_LO_DS:
   1887     case BFD_RELOC_LO16_GOTOFF:		r = R_PPC_GOT16_LO;		break;
   1888     case BFD_RELOC_HI16_GOTOFF:		r = R_PPC_GOT16_HI;		break;
   1889     case BFD_RELOC_HI16_S_GOTOFF:	r = R_PPC_GOT16_HA;		break;
   1890     case BFD_RELOC_24_PLT_PCREL:	r = R_PPC_PLTREL24;		break;
   1891     case BFD_RELOC_PPC_COPY:		r = R_PPC_COPY;			break;
   1892     case BFD_RELOC_PPC_GLOB_DAT:	r = R_PPC_GLOB_DAT;		break;
   1893     case BFD_RELOC_PPC_LOCAL24PC:	r = R_PPC_LOCAL24PC;		break;
   1894     case BFD_RELOC_32_PCREL:		r = R_PPC_REL32;		break;
   1895     case BFD_RELOC_32_PLTOFF:		r = R_PPC_PLT32;		break;
   1896     case BFD_RELOC_32_PLT_PCREL:	r = R_PPC_PLTREL32;		break;
   1897     case BFD_RELOC_PPC64_PLT16_LO_DS:
   1898     case BFD_RELOC_LO16_PLTOFF:		r = R_PPC_PLT16_LO;		break;
   1899     case BFD_RELOC_HI16_PLTOFF:		r = R_PPC_PLT16_HI;		break;
   1900     case BFD_RELOC_HI16_S_PLTOFF:	r = R_PPC_PLT16_HA;		break;
   1901     case BFD_RELOC_GPREL16:		r = R_PPC_SDAREL16;		break;
   1902     case BFD_RELOC_PPC64_SECTOFF_DS:
   1903     case BFD_RELOC_16_BASEREL:		r = R_PPC_SECTOFF;		break;
   1904     case BFD_RELOC_PPC64_SECTOFF_LO_DS:
   1905     case BFD_RELOC_LO16_BASEREL:	r = R_PPC_SECTOFF_LO;		break;
   1906     case BFD_RELOC_HI16_BASEREL:	r = R_PPC_SECTOFF_HI;		break;
   1907     case BFD_RELOC_HI16_S_BASEREL:	r = R_PPC_SECTOFF_HA;		break;
   1908     case BFD_RELOC_CTOR:		r = R_PPC_ADDR32;		break;
   1909     case BFD_RELOC_PPC64_TOC16_DS:
   1910     case BFD_RELOC_PPC_TOC16:		r = R_PPC_TOC16;		break;
   1911     case BFD_RELOC_PPC_TLS:		r = R_PPC_TLS;			break;
   1912     case BFD_RELOC_PPC_TLSGD:		r = R_PPC_TLSGD;		break;
   1913     case BFD_RELOC_PPC_TLSLD:		r = R_PPC_TLSLD;		break;
   1914     case BFD_RELOC_PPC_DTPMOD:		r = R_PPC_DTPMOD32;		break;
   1915     case BFD_RELOC_PPC64_TPREL16_DS:
   1916     case BFD_RELOC_PPC_TPREL16:		r = R_PPC_TPREL16;		break;
   1917     case BFD_RELOC_PPC64_TPREL16_LO_DS:
   1918     case BFD_RELOC_PPC_TPREL16_LO:	r = R_PPC_TPREL16_LO;		break;
   1919     case BFD_RELOC_PPC_TPREL16_HI:	r = R_PPC_TPREL16_HI;		break;
   1920     case BFD_RELOC_PPC_TPREL16_HA:	r = R_PPC_TPREL16_HA;		break;
   1921     case BFD_RELOC_PPC_TPREL:		r = R_PPC_TPREL32;		break;
   1922     case BFD_RELOC_PPC64_DTPREL16_DS:
   1923     case BFD_RELOC_PPC_DTPREL16:	r = R_PPC_DTPREL16;		break;
   1924     case BFD_RELOC_PPC64_DTPREL16_LO_DS:
   1925     case BFD_RELOC_PPC_DTPREL16_LO:	r = R_PPC_DTPREL16_LO;		break;
   1926     case BFD_RELOC_PPC_DTPREL16_HI:	r = R_PPC_DTPREL16_HI;		break;
   1927     case BFD_RELOC_PPC_DTPREL16_HA:	r = R_PPC_DTPREL16_HA;		break;
   1928     case BFD_RELOC_PPC_DTPREL:		r = R_PPC_DTPREL32;		break;
   1929     case BFD_RELOC_PPC_GOT_TLSGD16:	r = R_PPC_GOT_TLSGD16;		break;
   1930     case BFD_RELOC_PPC_GOT_TLSGD16_LO:	r = R_PPC_GOT_TLSGD16_LO;	break;
   1931     case BFD_RELOC_PPC_GOT_TLSGD16_HI:	r = R_PPC_GOT_TLSGD16_HI;	break;
   1932     case BFD_RELOC_PPC_GOT_TLSGD16_HA:	r = R_PPC_GOT_TLSGD16_HA;	break;
   1933     case BFD_RELOC_PPC_GOT_TLSLD16:	r = R_PPC_GOT_TLSLD16;		break;
   1934     case BFD_RELOC_PPC_GOT_TLSLD16_LO:	r = R_PPC_GOT_TLSLD16_LO;	break;
   1935     case BFD_RELOC_PPC_GOT_TLSLD16_HI:	r = R_PPC_GOT_TLSLD16_HI;	break;
   1936     case BFD_RELOC_PPC_GOT_TLSLD16_HA:	r = R_PPC_GOT_TLSLD16_HA;	break;
   1937     case BFD_RELOC_PPC_GOT_TPREL16:	r = R_PPC_GOT_TPREL16;		break;
   1938     case BFD_RELOC_PPC_GOT_TPREL16_LO:	r = R_PPC_GOT_TPREL16_LO;	break;
   1939     case BFD_RELOC_PPC_GOT_TPREL16_HI:	r = R_PPC_GOT_TPREL16_HI;	break;
   1940     case BFD_RELOC_PPC_GOT_TPREL16_HA:	r = R_PPC_GOT_TPREL16_HA;	break;
   1941     case BFD_RELOC_PPC_GOT_DTPREL16:	r = R_PPC_GOT_DTPREL16;		break;
   1942     case BFD_RELOC_PPC_GOT_DTPREL16_LO:	r = R_PPC_GOT_DTPREL16_LO;	break;
   1943     case BFD_RELOC_PPC_GOT_DTPREL16_HI:	r = R_PPC_GOT_DTPREL16_HI;	break;
   1944     case BFD_RELOC_PPC_GOT_DTPREL16_HA:	r = R_PPC_GOT_DTPREL16_HA;	break;
   1945     case BFD_RELOC_PPC_EMB_NADDR32:	r = R_PPC_EMB_NADDR32;		break;
   1946     case BFD_RELOC_PPC_EMB_NADDR16:	r = R_PPC_EMB_NADDR16;		break;
   1947     case BFD_RELOC_PPC_EMB_NADDR16_LO:	r = R_PPC_EMB_NADDR16_LO;	break;
   1948     case BFD_RELOC_PPC_EMB_NADDR16_HI:	r = R_PPC_EMB_NADDR16_HI;	break;
   1949     case BFD_RELOC_PPC_EMB_NADDR16_HA:	r = R_PPC_EMB_NADDR16_HA;	break;
   1950     case BFD_RELOC_PPC_EMB_SDAI16:	r = R_PPC_EMB_SDAI16;		break;
   1951     case BFD_RELOC_PPC_EMB_SDA2I16:	r = R_PPC_EMB_SDA2I16;		break;
   1952     case BFD_RELOC_PPC_EMB_SDA2REL:	r = R_PPC_EMB_SDA2REL;		break;
   1953     case BFD_RELOC_PPC_EMB_SDA21:	r = R_PPC_EMB_SDA21;		break;
   1954     case BFD_RELOC_PPC_EMB_MRKREF:	r = R_PPC_EMB_MRKREF;		break;
   1955     case BFD_RELOC_PPC_EMB_RELSEC16:	r = R_PPC_EMB_RELSEC16;		break;
   1956     case BFD_RELOC_PPC_EMB_RELST_LO:	r = R_PPC_EMB_RELST_LO;		break;
   1957     case BFD_RELOC_PPC_EMB_RELST_HI:	r = R_PPC_EMB_RELST_HI;		break;
   1958     case BFD_RELOC_PPC_EMB_RELST_HA:	r = R_PPC_EMB_RELST_HA;		break;
   1959     case BFD_RELOC_PPC_EMB_BIT_FLD:	r = R_PPC_EMB_BIT_FLD;		break;
   1960     case BFD_RELOC_PPC_EMB_RELSDA:	r = R_PPC_EMB_RELSDA;		break;
   1961     case BFD_RELOC_PPC_VLE_REL8:	r = R_PPC_VLE_REL8;		break;
   1962     case BFD_RELOC_PPC_VLE_REL15:	r = R_PPC_VLE_REL15;		break;
   1963     case BFD_RELOC_PPC_VLE_REL24:	r = R_PPC_VLE_REL24;		break;
   1964     case BFD_RELOC_PPC_VLE_LO16A:	r = R_PPC_VLE_LO16A;		break;
   1965     case BFD_RELOC_PPC_VLE_LO16D:	r = R_PPC_VLE_LO16D;		break;
   1966     case BFD_RELOC_PPC_VLE_HI16A:	r = R_PPC_VLE_HI16A;		break;
   1967     case BFD_RELOC_PPC_VLE_HI16D:	r = R_PPC_VLE_HI16D;		break;
   1968     case BFD_RELOC_PPC_VLE_HA16A:	r = R_PPC_VLE_HA16A;		break;
   1969     case BFD_RELOC_PPC_VLE_HA16D:	r = R_PPC_VLE_HA16D;		break;
   1970     case BFD_RELOC_PPC_VLE_SDA21:	r = R_PPC_VLE_SDA21;		break;
   1971     case BFD_RELOC_PPC_VLE_SDA21_LO:	r = R_PPC_VLE_SDA21_LO;		break;
   1972     case BFD_RELOC_PPC_VLE_SDAREL_LO16A:
   1973       r = R_PPC_VLE_SDAREL_LO16A;
   1974       break;
   1975     case BFD_RELOC_PPC_VLE_SDAREL_LO16D:
   1976       r = R_PPC_VLE_SDAREL_LO16D;
   1977       break;
   1978     case BFD_RELOC_PPC_VLE_SDAREL_HI16A:
   1979       r = R_PPC_VLE_SDAREL_HI16A;
   1980       break;
   1981     case BFD_RELOC_PPC_VLE_SDAREL_HI16D:
   1982       r = R_PPC_VLE_SDAREL_HI16D;
   1983       break;
   1984     case BFD_RELOC_PPC_VLE_SDAREL_HA16A:
   1985       r = R_PPC_VLE_SDAREL_HA16A;
   1986       break;
   1987     case BFD_RELOC_PPC_VLE_SDAREL_HA16D:
   1988       r = R_PPC_VLE_SDAREL_HA16D;
   1989       break;
   1990     case BFD_RELOC_16_PCREL:		r = R_PPC_REL16;		break;
   1991     case BFD_RELOC_LO16_PCREL:		r = R_PPC_REL16_LO;		break;
   1992     case BFD_RELOC_HI16_PCREL:		r = R_PPC_REL16_HI;		break;
   1993     case BFD_RELOC_HI16_S_PCREL:	r = R_PPC_REL16_HA;		break;
   1994     case BFD_RELOC_VTABLE_INHERIT:	r = R_PPC_GNU_VTINHERIT;	break;
   1995     case BFD_RELOC_VTABLE_ENTRY:	r = R_PPC_GNU_VTENTRY;		break;
   1996     }
   1997 
   1998   return ppc_elf_howto_table[r];
   1999 };
   2000 
   2001 static reloc_howto_type *
   2002 ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   2003 			   const char *r_name)
   2004 {
   2005   unsigned int i;
   2006 
   2007   for (i = 0;
   2008        i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
   2009        i++)
   2010     if (ppc_elf_howto_raw[i].name != NULL
   2011 	&& strcasecmp (ppc_elf_howto_raw[i].name, r_name) == 0)
   2012       return &ppc_elf_howto_raw[i];
   2013 
   2014   return NULL;
   2015 }
   2016 
   2017 /* Set the howto pointer for a PowerPC ELF reloc.  */
   2018 
   2019 static void
   2020 ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
   2021 		       arelent *cache_ptr,
   2022 		       Elf_Internal_Rela *dst)
   2023 {
   2024   /* Initialize howto table if not already done.  */
   2025   if (!ppc_elf_howto_table[R_PPC_ADDR32])
   2026     ppc_elf_howto_init ();
   2027 
   2028   BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
   2029   cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
   2030 
   2031   /* Just because the above assert didn't trigger doesn't mean that
   2032      ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation.  */
   2033   if (!cache_ptr->howto)
   2034     {
   2035       (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
   2036                              abfd, ELF32_R_TYPE (dst->r_info));
   2037       bfd_set_error (bfd_error_bad_value);
   2038 
   2039       cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE];
   2040     }
   2041 }
   2042 
   2043 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs.  */
   2044 
   2045 static bfd_reloc_status_type
   2046 ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED,
   2047 			 arelent *reloc_entry,
   2048 			 asymbol *symbol,
   2049 			 void *data ATTRIBUTE_UNUSED,
   2050 			 asection *input_section,
   2051 			 bfd *output_bfd,
   2052 			 char **error_message ATTRIBUTE_UNUSED)
   2053 {
   2054   bfd_vma relocation;
   2055 
   2056   if (output_bfd != NULL)
   2057     {
   2058       reloc_entry->address += input_section->output_offset;
   2059       return bfd_reloc_ok;
   2060     }
   2061 
   2062   if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
   2063     return bfd_reloc_outofrange;
   2064 
   2065   if (bfd_is_com_section (symbol->section))
   2066     relocation = 0;
   2067   else
   2068     relocation = symbol->value;
   2069 
   2070   relocation += symbol->section->output_section->vma;
   2071   relocation += symbol->section->output_offset;
   2072   relocation += reloc_entry->addend;
   2073   if (reloc_entry->howto->pc_relative)
   2074     relocation -= reloc_entry->address;
   2075 
   2076   reloc_entry->addend += (relocation & 0x8000) << 1;
   2077 
   2078   return bfd_reloc_continue;
   2079 }
   2080 
   2081 static bfd_reloc_status_type
   2082 ppc_elf_unhandled_reloc (bfd *abfd,
   2083 			 arelent *reloc_entry,
   2084 			 asymbol *symbol,
   2085 			 void *data,
   2086 			 asection *input_section,
   2087 			 bfd *output_bfd,
   2088 			 char **error_message)
   2089 {
   2090   /* If this is a relocatable link (output_bfd test tells us), just
   2091      call the generic function.  Any adjustment will be done at final
   2092      link time.  */
   2093   if (output_bfd != NULL)
   2094     return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
   2095 				  input_section, output_bfd, error_message);
   2096 
   2097   if (error_message != NULL)
   2098     {
   2099       static char buf[60];
   2100       sprintf (buf, _("generic linker can't handle %s"),
   2101 	       reloc_entry->howto->name);
   2102       *error_message = buf;
   2103     }
   2104   return bfd_reloc_dangerous;
   2105 }
   2106 
   2107 /* Sections created by the linker.  */
   2109 
   2110 typedef struct elf_linker_section
   2111 {
   2112   /* Pointer to the bfd section.  */
   2113   asection *section;
   2114   /* Section name.  */
   2115   const char *name;
   2116   /* Associated bss section name.  */
   2117   const char *bss_name;
   2118   /* Associated symbol name.  */
   2119   const char *sym_name;
   2120   /* Associated symbol.  */
   2121   struct elf_link_hash_entry *sym;
   2122 } elf_linker_section_t;
   2123 
   2124 /* Linked list of allocated pointer entries.  This hangs off of the
   2125    symbol lists, and provides allows us to return different pointers,
   2126    based on different addend's.  */
   2127 
   2128 typedef struct elf_linker_section_pointers
   2129 {
   2130   /* next allocated pointer for this symbol */
   2131   struct elf_linker_section_pointers *next;
   2132   /* offset of pointer from beginning of section */
   2133   bfd_vma offset;
   2134   /* addend used */
   2135   bfd_vma addend;
   2136   /* which linker section this is */
   2137   elf_linker_section_t *lsect;
   2138 } elf_linker_section_pointers_t;
   2139 
   2140 struct ppc_elf_obj_tdata
   2141 {
   2142   struct elf_obj_tdata elf;
   2143 
   2144   /* A mapping from local symbols to offsets into the various linker
   2145      sections added.  This is index by the symbol index.  */
   2146   elf_linker_section_pointers_t **linker_section_pointers;
   2147 
   2148   /* Flags used to auto-detect plt type.  */
   2149   unsigned int makes_plt_call : 1;
   2150   unsigned int has_rel16 : 1;
   2151 };
   2152 
   2153 #define ppc_elf_tdata(bfd) \
   2154   ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
   2155 
   2156 #define elf_local_ptr_offsets(bfd) \
   2157   (ppc_elf_tdata (bfd)->linker_section_pointers)
   2158 
   2159 #define is_ppc_elf(bfd) \
   2160   (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
   2161    && elf_object_id (bfd) == PPC32_ELF_DATA)
   2162 
   2163 /* Override the generic function because we store some extras.  */
   2164 
   2165 static bfd_boolean
   2166 ppc_elf_mkobject (bfd *abfd)
   2167 {
   2168   return bfd_elf_allocate_object (abfd, sizeof (struct ppc_elf_obj_tdata),
   2169 				  PPC32_ELF_DATA);
   2170 }
   2171 
   2172 /* Fix bad default arch selected for a 32 bit input bfd when the
   2173    default is 64 bit.  */
   2174 
   2175 static bfd_boolean
   2176 ppc_elf_object_p (bfd *abfd)
   2177 {
   2178   if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
   2179     {
   2180       Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
   2181 
   2182       if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
   2183 	{
   2184 	  /* Relies on arch after 64 bit default being 32 bit default.  */
   2185 	  abfd->arch_info = abfd->arch_info->next;
   2186 	  BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
   2187 	}
   2188     }
   2189   return TRUE;
   2190 }
   2191 
   2192 /* Function to set whether a module needs the -mrelocatable bit set.  */
   2193 
   2194 static bfd_boolean
   2195 ppc_elf_set_private_flags (bfd *abfd, flagword flags)
   2196 {
   2197   BFD_ASSERT (!elf_flags_init (abfd)
   2198 	      || elf_elfheader (abfd)->e_flags == flags);
   2199 
   2200   elf_elfheader (abfd)->e_flags = flags;
   2201   elf_flags_init (abfd) = TRUE;
   2202   return TRUE;
   2203 }
   2204 
   2205 /* Support for core dump NOTE sections.  */
   2206 
   2207 static bfd_boolean
   2208 ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
   2209 {
   2210   int offset;
   2211   unsigned int size;
   2212 
   2213   switch (note->descsz)
   2214     {
   2215     default:
   2216       return FALSE;
   2217 
   2218     case 268:		/* Linux/PPC.  */
   2219       /* pr_cursig */
   2220       elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
   2221 
   2222       /* pr_pid */
   2223       elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
   2224 
   2225       /* pr_reg */
   2226       offset = 72;
   2227       size = 192;
   2228 
   2229       break;
   2230     }
   2231 
   2232   /* Make a ".reg/999" section.  */
   2233   return _bfd_elfcore_make_pseudosection (abfd, ".reg",
   2234 					  size, note->descpos + offset);
   2235 }
   2236 
   2237 static bfd_boolean
   2238 ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
   2239 {
   2240   switch (note->descsz)
   2241     {
   2242     default:
   2243       return FALSE;
   2244 
   2245     case 128:		/* Linux/PPC elf_prpsinfo.  */
   2246       elf_tdata (abfd)->core->pid
   2247 	= bfd_get_32 (abfd, note->descdata + 16);
   2248       elf_tdata (abfd)->core->program
   2249 	= _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
   2250       elf_tdata (abfd)->core->command
   2251 	= _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
   2252     }
   2253 
   2254   /* Note that for some reason, a spurious space is tacked
   2255      onto the end of the args in some (at least one anyway)
   2256      implementations, so strip it off if it exists.  */
   2257 
   2258   {
   2259     char *command = elf_tdata (abfd)->core->command;
   2260     int n = strlen (command);
   2261 
   2262     if (0 < n && command[n - 1] == ' ')
   2263       command[n - 1] = '\0';
   2264   }
   2265 
   2266   return TRUE;
   2267 }
   2268 
   2269 char *
   2270 elfcore_write_ppc_linux_prpsinfo32 (bfd *abfd, char *buf, int *bufsiz,
   2271 				      const struct elf_internal_linux_prpsinfo *prpsinfo)
   2272 {
   2273   struct elf_external_ppc_linux_prpsinfo32 data;
   2274 
   2275   memset (&data, 0, sizeof (data));
   2276   PPC_LINUX_PRPSINFO32_SWAP_FIELDS (abfd, prpsinfo, data);
   2277 
   2278   return elfcore_write_note (abfd, buf, bufsiz,
   2279 			     "CORE", NT_PRPSINFO, &data, sizeof (data));
   2280 }
   2281 
   2282 static char *
   2283 ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...)
   2284 {
   2285   switch (note_type)
   2286     {
   2287     default:
   2288       return NULL;
   2289 
   2290     case NT_PRPSINFO:
   2291       {
   2292 	char data[128];
   2293 	va_list ap;
   2294 
   2295 	va_start (ap, note_type);
   2296 	memset (data, 0, sizeof (data));
   2297 	strncpy (data + 32, va_arg (ap, const char *), 16);
   2298 	strncpy (data + 48, va_arg (ap, const char *), 80);
   2299 	va_end (ap);
   2300 	return elfcore_write_note (abfd, buf, bufsiz,
   2301 				   "CORE", note_type, data, sizeof (data));
   2302       }
   2303 
   2304     case NT_PRSTATUS:
   2305       {
   2306 	char data[268];
   2307 	va_list ap;
   2308 	long pid;
   2309 	int cursig;
   2310 	const void *greg;
   2311 
   2312 	va_start (ap, note_type);
   2313 	memset (data, 0, 72);
   2314 	pid = va_arg (ap, long);
   2315 	bfd_put_32 (abfd, pid, data + 24);
   2316 	cursig = va_arg (ap, int);
   2317 	bfd_put_16 (abfd, cursig, data + 12);
   2318 	greg = va_arg (ap, const void *);
   2319 	memcpy (data + 72, greg, 192);
   2320 	memset (data + 264, 0, 4);
   2321 	va_end (ap);
   2322 	return elfcore_write_note (abfd, buf, bufsiz,
   2323 				   "CORE", note_type, data, sizeof (data));
   2324       }
   2325     }
   2326 }
   2327 
   2328 static flagword
   2329 ppc_elf_lookup_section_flags (char *flag_name)
   2330 {
   2331 
   2332   if (!strcmp (flag_name, "SHF_PPC_VLE"))
   2333     return SHF_PPC_VLE;
   2334 
   2335   return 0;
   2336 }
   2337 
   2338 /* Add the VLE flag if required.  */
   2339 
   2340 bfd_boolean
   2341 ppc_elf_section_processing (bfd *abfd, Elf_Internal_Shdr *shdr)
   2342 {
   2343   if (bfd_get_mach (abfd) == bfd_mach_ppc_vle
   2344       && (shdr->sh_flags & SHF_EXECINSTR) != 0)
   2345     shdr->sh_flags |= SHF_PPC_VLE;
   2346 
   2347   return TRUE;
   2348 }
   2349 
   2350 /* Return address for Ith PLT stub in section PLT, for relocation REL
   2351    or (bfd_vma) -1 if it should not be included.  */
   2352 
   2353 static bfd_vma
   2354 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED,
   2355 		     const asection *plt ATTRIBUTE_UNUSED,
   2356 		     const arelent *rel)
   2357 {
   2358   return rel->address;
   2359 }
   2360 
   2361 /* Handle a PowerPC specific section when reading an object file.  This
   2362    is called when bfd_section_from_shdr finds a section with an unknown
   2363    type.  */
   2364 
   2365 static bfd_boolean
   2366 ppc_elf_section_from_shdr (bfd *abfd,
   2367 			   Elf_Internal_Shdr *hdr,
   2368 			   const char *name,
   2369 			   int shindex)
   2370 {
   2371   asection *newsect;
   2372   flagword flags;
   2373 
   2374   if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
   2375     return FALSE;
   2376 
   2377   newsect = hdr->bfd_section;
   2378   flags = bfd_get_section_flags (abfd, newsect);
   2379   if (hdr->sh_flags & SHF_EXCLUDE)
   2380     flags |= SEC_EXCLUDE;
   2381 
   2382   if (hdr->sh_type == SHT_ORDERED)
   2383     flags |= SEC_SORT_ENTRIES;
   2384 
   2385   bfd_set_section_flags (abfd, newsect, flags);
   2386   return TRUE;
   2387 }
   2388 
   2389 /* Set up any other section flags and such that may be necessary.  */
   2390 
   2391 static bfd_boolean
   2392 ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
   2393 		       Elf_Internal_Shdr *shdr,
   2394 		       asection *asect)
   2395 {
   2396   if ((asect->flags & SEC_SORT_ENTRIES) != 0)
   2397     shdr->sh_type = SHT_ORDERED;
   2398 
   2399   return TRUE;
   2400 }
   2401 
   2402 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
   2403    need to bump up the number of section headers.  */
   2404 
   2405 static int
   2406 ppc_elf_additional_program_headers (bfd *abfd,
   2407 				    struct bfd_link_info *info ATTRIBUTE_UNUSED)
   2408 {
   2409   asection *s;
   2410   int ret = 0;
   2411 
   2412   s = bfd_get_section_by_name (abfd, ".sbss2");
   2413   if (s != NULL && (s->flags & SEC_ALLOC) != 0)
   2414     ++ret;
   2415 
   2416   s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
   2417   if (s != NULL && (s->flags & SEC_ALLOC) != 0)
   2418     ++ret;
   2419 
   2420   return ret;
   2421 }
   2422 
   2423 /* Modify the segment map for VLE executables.  */
   2424 
   2425 bfd_boolean
   2426 ppc_elf_modify_segment_map (bfd *abfd,
   2427 			    struct bfd_link_info *info ATTRIBUTE_UNUSED)
   2428 {
   2429   struct elf_segment_map *m, *n;
   2430   bfd_size_type amt;
   2431   unsigned int j, k;
   2432   bfd_boolean sect0_vle, sectj_vle;
   2433 
   2434   /* At this point in the link, output sections have already been sorted by
   2435      LMA and assigned to segments.  All that is left to do is to ensure
   2436      there is no mixing of VLE & non-VLE sections in a text segment.
   2437      If we find that case, we split the segment.
   2438      We maintain the original output section order.  */
   2439 
   2440   for (m = elf_seg_map (abfd); m != NULL; m = m->next)
   2441     {
   2442       if (m->count == 0)
   2443 	continue;
   2444 
   2445       sect0_vle = (elf_section_flags (m->sections[0]) & SHF_PPC_VLE) != 0;
   2446       for (j = 1; j < m->count; ++j)
   2447 	{
   2448 	  sectj_vle = (elf_section_flags (m->sections[j]) & SHF_PPC_VLE) != 0;
   2449 
   2450 	  if (sectj_vle != sect0_vle)
   2451 	    break;
   2452         }
   2453       if (j >= m->count)
   2454 	continue;
   2455 
   2456       /* sections 0..j-1 stay in this (current) segment,
   2457 	 the remainder are put in a new segment.
   2458 	 The scan resumes with the new segment.  */
   2459 
   2460       /* Fix the new segment.  */
   2461       amt = sizeof (struct elf_segment_map);
   2462       amt += (m->count - j - 1) * sizeof (asection *);
   2463       n = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
   2464       if (n == NULL)
   2465         return FALSE;
   2466 
   2467       n->p_type = PT_LOAD;
   2468       n->p_flags = PF_X | PF_R;
   2469       if (sectj_vle)
   2470         n->p_flags |= PF_PPC_VLE;
   2471       n->count = m->count - j;
   2472       for (k = 0; k < n->count; ++k)
   2473         {
   2474           n->sections[k] = m->sections[j+k];
   2475           m->sections[j+k] = NULL;
   2476 	}
   2477       n->next = m->next;
   2478       m->next = n;
   2479 
   2480       /* Fix the current segment  */
   2481       m->count = j;
   2482     }
   2483 
   2484   return TRUE;
   2485 }
   2486 
   2487 /* Add extra PPC sections -- Note, for now, make .sbss2 and
   2488    .PPC.EMB.sbss0 a normal section, and not a bss section so
   2489    that the linker doesn't crater when trying to make more than
   2490    2 sections.  */
   2491 
   2492 static const struct bfd_elf_special_section ppc_elf_special_sections[] =
   2493 {
   2494   { STRING_COMMA_LEN (".plt"),             0, SHT_NOBITS,   SHF_ALLOC + SHF_EXECINSTR },
   2495   { STRING_COMMA_LEN (".sbss"),           -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE },
   2496   { STRING_COMMA_LEN (".sbss2"),          -2, SHT_PROGBITS, SHF_ALLOC },
   2497   { STRING_COMMA_LEN (".sdata"),          -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
   2498   { STRING_COMMA_LEN (".sdata2"),         -2, SHT_PROGBITS, SHF_ALLOC },
   2499   { STRING_COMMA_LEN (".tags"),            0, SHT_ORDERED,  SHF_ALLOC },
   2500   { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE,     0 },
   2501   { STRING_COMMA_LEN (".PPC.EMB.sbss0"),   0, SHT_PROGBITS, SHF_ALLOC },
   2502   { STRING_COMMA_LEN (".PPC.EMB.sdata0"),  0, SHT_PROGBITS, SHF_ALLOC },
   2503   { NULL,                              0,  0, 0,            0 }
   2504 };
   2505 
   2506 /* This is what we want for new plt/got.  */
   2507 static struct bfd_elf_special_section ppc_alt_plt =
   2508   { STRING_COMMA_LEN (".plt"),             0, SHT_PROGBITS, SHF_ALLOC };
   2509 
   2510 static const struct bfd_elf_special_section *
   2511 ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
   2512 {
   2513   const struct bfd_elf_special_section *ssect;
   2514 
   2515   /* See if this is one of the special sections.  */
   2516   if (sec->name == NULL)
   2517     return NULL;
   2518 
   2519   ssect = _bfd_elf_get_special_section (sec->name, ppc_elf_special_sections,
   2520 					sec->use_rela_p);
   2521   if (ssect != NULL)
   2522     {
   2523       if (ssect == ppc_elf_special_sections && (sec->flags & SEC_LOAD) != 0)
   2524 	ssect = &ppc_alt_plt;
   2525       return ssect;
   2526     }
   2527 
   2528   return _bfd_elf_get_sec_type_attr (abfd, sec);
   2529 }
   2530 
   2531 /* Very simple linked list structure for recording apuinfo values.  */
   2533 typedef struct apuinfo_list
   2534 {
   2535   struct apuinfo_list *next;
   2536   unsigned long value;
   2537 }
   2538 apuinfo_list;
   2539 
   2540 static apuinfo_list *head;
   2541 static bfd_boolean apuinfo_set;
   2542 
   2543 static void
   2544 apuinfo_list_init (void)
   2545 {
   2546   head = NULL;
   2547   apuinfo_set = FALSE;
   2548 }
   2549 
   2550 static void
   2551 apuinfo_list_add (unsigned long value)
   2552 {
   2553   apuinfo_list *entry = head;
   2554 
   2555   while (entry != NULL)
   2556     {
   2557       if (entry->value == value)
   2558 	return;
   2559       entry = entry->next;
   2560     }
   2561 
   2562   entry = bfd_malloc (sizeof (* entry));
   2563   if (entry == NULL)
   2564     return;
   2565 
   2566   entry->value = value;
   2567   entry->next  = head;
   2568   head = entry;
   2569 }
   2570 
   2571 static unsigned
   2572 apuinfo_list_length (void)
   2573 {
   2574   apuinfo_list *entry;
   2575   unsigned long count;
   2576 
   2577   for (entry = head, count = 0;
   2578        entry;
   2579        entry = entry->next)
   2580     ++ count;
   2581 
   2582   return count;
   2583 }
   2584 
   2585 static inline unsigned long
   2586 apuinfo_list_element (unsigned long number)
   2587 {
   2588   apuinfo_list * entry;
   2589 
   2590   for (entry = head;
   2591        entry && number --;
   2592        entry = entry->next)
   2593     ;
   2594 
   2595   return entry ? entry->value : 0;
   2596 }
   2597 
   2598 static void
   2599 apuinfo_list_finish (void)
   2600 {
   2601   apuinfo_list *entry;
   2602 
   2603   for (entry = head; entry;)
   2604     {
   2605       apuinfo_list *next = entry->next;
   2606       free (entry);
   2607       entry = next;
   2608     }
   2609 
   2610   head = NULL;
   2611 }
   2612 
   2613 #define APUINFO_SECTION_NAME	".PPC.EMB.apuinfo"
   2614 #define APUINFO_LABEL		"APUinfo"
   2615 
   2616 /* Scan the input BFDs and create a linked list of
   2617    the APUinfo values that will need to be emitted.  */
   2618 
   2619 static void
   2620 ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
   2621 {
   2622   bfd *ibfd;
   2623   asection *asec;
   2624   char *buffer = NULL;
   2625   bfd_size_type largest_input_size = 0;
   2626   unsigned i;
   2627   unsigned long length;
   2628   const char *error_message = NULL;
   2629 
   2630   if (link_info == NULL)
   2631     return;
   2632 
   2633   apuinfo_list_init ();
   2634 
   2635   /* Read in the input sections contents.  */
   2636   for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link.next)
   2637     {
   2638       unsigned long datum;
   2639 
   2640       asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
   2641       if (asec == NULL)
   2642 	continue;
   2643 
   2644       error_message = _("corrupt %s section in %B");
   2645       length = asec->size;
   2646       if (length < 20)
   2647 	goto fail;
   2648 
   2649       apuinfo_set = TRUE;
   2650       if (largest_input_size < asec->size)
   2651 	{
   2652 	  if (buffer)
   2653 	    free (buffer);
   2654 	  largest_input_size = asec->size;
   2655 	  buffer = bfd_malloc (largest_input_size);
   2656 	  if (!buffer)
   2657 	    return;
   2658 	}
   2659 
   2660       if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
   2661 	  || (bfd_bread (buffer, length, ibfd) != length))
   2662 	{
   2663 	  error_message = _("unable to read in %s section from %B");
   2664 	  goto fail;
   2665 	}
   2666 
   2667       /* Verify the contents of the header.  Note - we have to
   2668 	 extract the values this way in order to allow for a
   2669 	 host whose endian-ness is different from the target.  */
   2670       datum = bfd_get_32 (ibfd, buffer);
   2671       if (datum != sizeof APUINFO_LABEL)
   2672 	goto fail;
   2673 
   2674       datum = bfd_get_32 (ibfd, buffer + 8);
   2675       if (datum != 0x2)
   2676 	goto fail;
   2677 
   2678       if (strcmp (buffer + 12, APUINFO_LABEL) != 0)
   2679 	goto fail;
   2680 
   2681       /* Get the number of bytes used for apuinfo entries.  */
   2682       datum = bfd_get_32 (ibfd, buffer + 4);
   2683       if (datum + 20 != length)
   2684 	goto fail;
   2685 
   2686       /* Scan the apuinfo section, building a list of apuinfo numbers.  */
   2687       for (i = 0; i < datum; i += 4)
   2688 	apuinfo_list_add (bfd_get_32 (ibfd, buffer + 20 + i));
   2689     }
   2690 
   2691   error_message = NULL;
   2692 
   2693   if (apuinfo_set)
   2694     {
   2695       /* Compute the size of the output section.  */
   2696       unsigned num_entries = apuinfo_list_length ();
   2697 
   2698       /* Set the output section size, if it exists.  */
   2699       asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
   2700 
   2701       if (asec && ! bfd_set_section_size (abfd, asec, 20 + num_entries * 4))
   2702 	{
   2703 	  ibfd = abfd;
   2704 	  error_message = _("warning: unable to set size of %s section in %B");
   2705 	}
   2706     }
   2707 
   2708  fail:
   2709   if (buffer)
   2710     free (buffer);
   2711 
   2712   if (error_message)
   2713     (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME);
   2714 }
   2715 
   2716 /* Prevent the output section from accumulating the input sections'
   2717    contents.  We have already stored this in our linked list structure.  */
   2718 
   2719 static bfd_boolean
   2720 ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
   2721 		       struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
   2722 		       asection *asec,
   2723 		       bfd_byte *contents ATTRIBUTE_UNUSED)
   2724 {
   2725   return apuinfo_set && strcmp (asec->name, APUINFO_SECTION_NAME) == 0;
   2726 }
   2727 
   2728 /* Finally we can generate the output section.  */
   2729 
   2730 static void
   2731 ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
   2732 {
   2733   bfd_byte *buffer;
   2734   asection *asec;
   2735   unsigned i;
   2736   unsigned num_entries;
   2737   bfd_size_type length;
   2738 
   2739   asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
   2740   if (asec == NULL)
   2741     return;
   2742 
   2743   if (!apuinfo_set)
   2744     return;
   2745 
   2746   length = asec->size;
   2747   if (length < 20)
   2748     return;
   2749 
   2750   buffer = bfd_malloc (length);
   2751   if (buffer == NULL)
   2752     {
   2753       (*_bfd_error_handler)
   2754 	(_("failed to allocate space for new APUinfo section."));
   2755       return;
   2756     }
   2757 
   2758   /* Create the apuinfo header.  */
   2759   num_entries = apuinfo_list_length ();
   2760   bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
   2761   bfd_put_32 (abfd, num_entries * 4, buffer + 4);
   2762   bfd_put_32 (abfd, 0x2, buffer + 8);
   2763   strcpy ((char *) buffer + 12, APUINFO_LABEL);
   2764 
   2765   length = 20;
   2766   for (i = 0; i < num_entries; i++)
   2767     {
   2768       bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
   2769       length += 4;
   2770     }
   2771 
   2772   if (length != asec->size)
   2773     (*_bfd_error_handler) (_("failed to compute new APUinfo section."));
   2774 
   2775   if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
   2776     (*_bfd_error_handler) (_("failed to install new APUinfo section."));
   2777 
   2778   free (buffer);
   2779 
   2780   apuinfo_list_finish ();
   2781 }
   2782 
   2783 static bfd_boolean
   2785 is_nonpic_glink_stub (bfd *abfd, asection *glink, bfd_vma off)
   2786 {
   2787   bfd_byte buf[GLINK_ENTRY_SIZE];
   2788 
   2789   if (!bfd_get_section_contents (abfd, glink, buf, off, GLINK_ENTRY_SIZE))
   2790     return FALSE;
   2791 
   2792   return ((bfd_get_32 (abfd, buf + 0) & 0xffff0000) == LIS_11
   2793 	  && (bfd_get_32 (abfd, buf + 4) & 0xffff0000) == LWZ_11_11
   2794 	  && bfd_get_32 (abfd, buf + 8) == MTCTR_11
   2795 	  && bfd_get_32 (abfd, buf + 12) == BCTR);
   2796 }
   2797 
   2798 static bfd_boolean
   2799 section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr)
   2800 {
   2801   bfd_vma vma = *(bfd_vma *) ptr;
   2802   return ((section->flags & SEC_ALLOC) != 0
   2803 	  && section->vma <= vma
   2804 	  && vma < section->vma + section->size);
   2805 }
   2806 
   2807 static long
   2808 ppc_elf_get_synthetic_symtab (bfd *abfd, long symcount, asymbol **syms,
   2809 			      long dynsymcount, asymbol **dynsyms,
   2810 			      asymbol **ret)
   2811 {
   2812   bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
   2813   asection *plt, *relplt, *dynamic, *glink;
   2814   bfd_vma glink_vma = 0;
   2815   bfd_vma resolv_vma = 0;
   2816   bfd_vma stub_vma;
   2817   asymbol *s;
   2818   arelent *p;
   2819   long count, i;
   2820   size_t size;
   2821   char *names;
   2822   bfd_byte buf[4];
   2823 
   2824   *ret = NULL;
   2825 
   2826   if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
   2827     return 0;
   2828 
   2829   if (dynsymcount <= 0)
   2830     return 0;
   2831 
   2832   relplt = bfd_get_section_by_name (abfd, ".rela.plt");
   2833   if (relplt == NULL)
   2834     return 0;
   2835 
   2836   plt = bfd_get_section_by_name (abfd, ".plt");
   2837   if (plt == NULL)
   2838     return 0;
   2839 
   2840   /* Call common code to handle old-style executable PLTs.  */
   2841   if (elf_section_flags (plt) & SHF_EXECINSTR)
   2842     return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms,
   2843 					  dynsymcount, dynsyms, ret);
   2844 
   2845   /* If this object was prelinked, the prelinker stored the address
   2846      of .glink at got[1].  If it wasn't prelinked, got[1] will be zero.  */
   2847   dynamic = bfd_get_section_by_name (abfd, ".dynamic");
   2848   if (dynamic != NULL)
   2849     {
   2850       bfd_byte *dynbuf, *extdyn, *extdynend;
   2851       size_t extdynsize;
   2852       void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *);
   2853 
   2854       if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf))
   2855 	return -1;
   2856 
   2857       extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
   2858       swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
   2859 
   2860       extdyn = dynbuf;
   2861       extdynend = extdyn + dynamic->size;
   2862       for (; extdyn < extdynend; extdyn += extdynsize)
   2863 	{
   2864 	  Elf_Internal_Dyn dyn;
   2865 	  (*swap_dyn_in) (abfd, extdyn, &dyn);
   2866 
   2867 	  if (dyn.d_tag == DT_NULL)
   2868 	    break;
   2869 
   2870 	  if (dyn.d_tag == DT_PPC_GOT)
   2871 	    {
   2872 	      unsigned int g_o_t = dyn.d_un.d_val;
   2873 	      asection *got = bfd_get_section_by_name (abfd, ".got");
   2874 	      if (got != NULL
   2875 		  && bfd_get_section_contents (abfd, got, buf,
   2876 					       g_o_t - got->vma + 4, 4))
   2877 		glink_vma = bfd_get_32 (abfd, buf);
   2878 	      break;
   2879 	    }
   2880 	}
   2881       free (dynbuf);
   2882     }
   2883 
   2884   /* Otherwise we read the first plt entry.  */
   2885   if (glink_vma == 0)
   2886     {
   2887       if (bfd_get_section_contents (abfd, plt, buf, 0, 4))
   2888 	glink_vma = bfd_get_32 (abfd, buf);
   2889     }
   2890 
   2891   if (glink_vma == 0)
   2892     return 0;
   2893 
   2894   /* The .glink section usually does not survive the final
   2895      link; search for the section (usually .text) where the
   2896      glink stubs now reside.  */
   2897   glink = bfd_sections_find_if (abfd, section_covers_vma, &glink_vma);
   2898   if (glink == NULL)
   2899     return 0;
   2900 
   2901   /* Determine glink PLT resolver by reading the relative branch
   2902      from the first glink stub.  */
   2903   if (bfd_get_section_contents (abfd, glink, buf,
   2904 				glink_vma - glink->vma, 4))
   2905     {
   2906       unsigned int insn = bfd_get_32 (abfd, buf);
   2907 
   2908       /* The first glink stub may either branch to the resolver ...  */
   2909       insn ^= B;
   2910       if ((insn & ~0x3fffffc) == 0)
   2911 	resolv_vma = glink_vma + (insn ^ 0x2000000) - 0x2000000;
   2912 
   2913       /* ... or fall through a bunch of NOPs.  */
   2914       else if ((insn ^ B ^ NOP) == 0)
   2915 	for (i = 4;
   2916 	     bfd_get_section_contents (abfd, glink, buf,
   2917 				       glink_vma - glink->vma + i, 4);
   2918 	     i += 4)
   2919 	  if (bfd_get_32 (abfd, buf) != NOP)
   2920 	    {
   2921 	      resolv_vma = glink_vma + i;
   2922 	      break;
   2923 	    }
   2924     }
   2925 
   2926   count = relplt->size / sizeof (Elf32_External_Rela);
   2927   stub_vma = glink_vma - (bfd_vma) count * 16;
   2928   /* If the stubs are those for -shared/-pie then we might have
   2929      multiple stubs for each plt entry.  If that is the case then
   2930      there is no way to associate stubs with their plt entries short
   2931      of figuring out the GOT pointer value used in the stub.  */
   2932   if (!is_nonpic_glink_stub (abfd, glink,
   2933 			     glink_vma - GLINK_ENTRY_SIZE - glink->vma))
   2934     return 0;
   2935 
   2936   slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
   2937   if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE))
   2938     return -1;
   2939 
   2940   size = count * sizeof (asymbol);
   2941   p = relplt->relocation;
   2942   for (i = 0; i < count; i++, p++)
   2943     {
   2944       size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
   2945       if (p->addend != 0)
   2946 	size += sizeof ("+0x") - 1 + 8;
   2947     }
   2948 
   2949   size += sizeof (asymbol) + sizeof ("__glink");
   2950 
   2951   if (resolv_vma)
   2952     size += sizeof (asymbol) + sizeof ("__glink_PLTresolve");
   2953 
   2954   s = *ret = bfd_malloc (size);
   2955   if (s == NULL)
   2956     return -1;
   2957 
   2958   names = (char *) (s + count + 1 + (resolv_vma != 0));
   2959   p = relplt->relocation;
   2960   for (i = 0; i < count; i++, p++)
   2961     {
   2962       size_t len;
   2963 
   2964       *s = **p->sym_ptr_ptr;
   2965       /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set.  Since
   2966 	 we are defining a symbol, ensure one of them is set.  */
   2967       if ((s->flags & BSF_LOCAL) == 0)
   2968 	s->flags |= BSF_GLOBAL;
   2969       s->flags |= BSF_SYNTHETIC;
   2970       s->section = glink;
   2971       s->value = stub_vma - glink->vma;
   2972       s->name = names;
   2973       s->udata.p = NULL;
   2974       len = strlen ((*p->sym_ptr_ptr)->name);
   2975       memcpy (names, (*p->sym_ptr_ptr)->name, len);
   2976       names += len;
   2977       if (p->addend != 0)
   2978 	{
   2979 	  memcpy (names, "+0x", sizeof ("+0x") - 1);
   2980 	  names += sizeof ("+0x") - 1;
   2981 	  bfd_sprintf_vma (abfd, names, p->addend);
   2982 	  names += strlen (names);
   2983 	}
   2984       memcpy (names, "@plt", sizeof ("@plt"));
   2985       names += sizeof ("@plt");
   2986       ++s;
   2987       stub_vma += 16;
   2988     }
   2989 
   2990   /* Add a symbol at the start of the glink branch table.  */
   2991   memset (s, 0, sizeof *s);
   2992   s->the_bfd = abfd;
   2993   s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
   2994   s->section = glink;
   2995   s->value = glink_vma - glink->vma;
   2996   s->name = names;
   2997   memcpy (names, "__glink", sizeof ("__glink"));
   2998   names += sizeof ("__glink");
   2999   s++;
   3000   count++;
   3001 
   3002   if (resolv_vma)
   3003     {
   3004       /* Add a symbol for the glink PLT resolver.  */
   3005       memset (s, 0, sizeof *s);
   3006       s->the_bfd = abfd;
   3007       s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
   3008       s->section = glink;
   3009       s->value = resolv_vma - glink->vma;
   3010       s->name = names;
   3011       memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
   3012       names += sizeof ("__glink_PLTresolve");
   3013       s++;
   3014       count++;
   3015     }
   3016 
   3017   return count;
   3018 }
   3019 
   3020 /* The following functions are specific to the ELF linker, while
   3022    functions above are used generally.  They appear in this file more
   3023    or less in the order in which they are called.  eg.
   3024    ppc_elf_check_relocs is called early in the link process,
   3025    ppc_elf_finish_dynamic_sections is one of the last functions
   3026    called.  */
   3027 
   3028 /* Track PLT entries needed for a given symbol.  We might need more
   3029    than one glink entry per symbol when generating a pic binary.  */
   3030 struct plt_entry
   3031 {
   3032   struct plt_entry *next;
   3033 
   3034   /* -fPIC uses multiple GOT sections, one per file, called ".got2".
   3035      This field stores the offset into .got2 used to initialise the
   3036      GOT pointer reg.  It will always be at least 32768.  (Current
   3037      gcc always uses an offset of 32768, but ld -r will pack .got2
   3038      sections together resulting in larger offsets).  */
   3039   bfd_vma addend;
   3040 
   3041   /* The .got2 section.  */
   3042   asection *sec;
   3043 
   3044   /* PLT refcount or offset.  */
   3045   union
   3046     {
   3047       bfd_signed_vma refcount;
   3048       bfd_vma offset;
   3049     } plt;
   3050 
   3051   /* .glink stub offset.  */
   3052   bfd_vma glink_offset;
   3053 };
   3054 
   3055 /* Of those relocs that might be copied as dynamic relocs, this function
   3056    selects those that must be copied when linking a shared library,
   3057    even when the symbol is local.  */
   3058 
   3059 static int
   3060 must_be_dyn_reloc (struct bfd_link_info *info,
   3061 		   enum elf_ppc_reloc_type r_type)
   3062 {
   3063   switch (r_type)
   3064     {
   3065     default:
   3066       return 1;
   3067 
   3068     case R_PPC_REL24:
   3069     case R_PPC_REL14:
   3070     case R_PPC_REL14_BRTAKEN:
   3071     case R_PPC_REL14_BRNTAKEN:
   3072     case R_PPC_REL32:
   3073       return 0;
   3074 
   3075     case R_PPC_TPREL32:
   3076     case R_PPC_TPREL16:
   3077     case R_PPC_TPREL16_LO:
   3078     case R_PPC_TPREL16_HI:
   3079     case R_PPC_TPREL16_HA:
   3080       return !info->executable;
   3081     }
   3082 }
   3083 
   3084 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
   3085    copying dynamic variables from a shared lib into an app's dynbss
   3086    section, and instead use a dynamic relocation to point into the
   3087    shared lib.  */
   3088 #define ELIMINATE_COPY_RELOCS 1
   3089 
   3090 /* Used to track dynamic relocations for local symbols.  */
   3091 struct ppc_dyn_relocs
   3092 {
   3093   struct ppc_dyn_relocs *next;
   3094 
   3095   /* The input section of the reloc.  */
   3096   asection *sec;
   3097 
   3098   /* Total number of relocs copied for the input section.  */
   3099   unsigned int count : 31;
   3100 
   3101   /* Whether this entry is for STT_GNU_IFUNC symbols.  */
   3102   unsigned int ifunc : 1;
   3103 };
   3104 
   3105 /* PPC ELF linker hash entry.  */
   3106 
   3107 struct ppc_elf_link_hash_entry
   3108 {
   3109   struct elf_link_hash_entry elf;
   3110 
   3111   /* If this symbol is used in the linker created sections, the processor
   3112      specific backend uses this field to map the field into the offset
   3113      from the beginning of the section.  */
   3114   elf_linker_section_pointers_t *linker_section_pointer;
   3115 
   3116   /* Track dynamic relocs copied for this symbol.  */
   3117   struct elf_dyn_relocs *dyn_relocs;
   3118 
   3119   /* Contexts in which symbol is used in the GOT (or TOC).
   3120      TLS_GD .. TLS_TLS bits are or'd into the mask as the
   3121      corresponding relocs are encountered during check_relocs.
   3122      tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
   3123      indicate the corresponding GOT entry type is not needed.  */
   3124 #define TLS_GD		 1	/* GD reloc. */
   3125 #define TLS_LD		 2	/* LD reloc. */
   3126 #define TLS_TPREL	 4	/* TPREL reloc, => IE. */
   3127 #define TLS_DTPREL	 8	/* DTPREL reloc, => LD. */
   3128 #define TLS_TLS		16	/* Any TLS reloc.  */
   3129 #define TLS_TPRELGD	32	/* TPREL reloc resulting from GD->IE. */
   3130 #define PLT_IFUNC	64	/* STT_GNU_IFUNC.  */
   3131   char tls_mask;
   3132 
   3133   /* Nonzero if we have seen a small data relocation referring to this
   3134      symbol.  */
   3135   unsigned char has_sda_refs;
   3136 };
   3137 
   3138 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
   3139 
   3140 /* PPC ELF linker hash table.  */
   3141 
   3142 struct ppc_elf_link_hash_table
   3143 {
   3144   struct elf_link_hash_table elf;
   3145 
   3146   /* Various options passed from the linker.  */
   3147   struct ppc_elf_params *params;
   3148 
   3149   /* Short-cuts to get to dynamic linker sections.  */
   3150   asection *got;
   3151   asection *relgot;
   3152   asection *glink;
   3153   asection *plt;
   3154   asection *relplt;
   3155   asection *iplt;
   3156   asection *reliplt;
   3157   asection *dynbss;
   3158   asection *relbss;
   3159   asection *dynsbss;
   3160   asection *relsbss;
   3161   elf_linker_section_t sdata[2];
   3162   asection *sbss;
   3163   asection *glink_eh_frame;
   3164 
   3165   /* The (unloaded but important) .rela.plt.unloaded on VxWorks.  */
   3166   asection *srelplt2;
   3167 
   3168   /* The .got.plt section (VxWorks only)*/
   3169   asection *sgotplt;
   3170 
   3171   /* Shortcut to __tls_get_addr.  */
   3172   struct elf_link_hash_entry *tls_get_addr;
   3173 
   3174   /* The bfd that forced an old-style PLT.  */
   3175   bfd *old_bfd;
   3176 
   3177   /* TLS local dynamic got entry handling.  */
   3178   union {
   3179     bfd_signed_vma refcount;
   3180     bfd_vma offset;
   3181   } tlsld_got;
   3182 
   3183   /* Offset of branch table to PltResolve function in glink.  */
   3184   bfd_vma glink_pltresolve;
   3185 
   3186   /* Size of reserved GOT entries.  */
   3187   unsigned int got_header_size;
   3188   /* Non-zero if allocating the header left a gap.  */
   3189   unsigned int got_gap;
   3190 
   3191   /* The type of PLT we have chosen to use.  */
   3192   enum ppc_elf_plt_type plt_type;
   3193 
   3194   /* True if the target system is VxWorks.  */
   3195   unsigned int is_vxworks:1;
   3196 
   3197   /* The size of PLT entries.  */
   3198   int plt_entry_size;
   3199   /* The distance between adjacent PLT slots.  */
   3200   int plt_slot_size;
   3201   /* The size of the first PLT entry.  */
   3202   int plt_initial_entry_size;
   3203 
   3204   /* Small local sym cache.  */
   3205   struct sym_cache sym_cache;
   3206 };
   3207 
   3208 /* Rename some of the generic section flags to better document how they
   3209    are used for ppc32.  The flags are only valid for ppc32 elf objects.  */
   3210 
   3211 /* Nonzero if this section has TLS related relocations.  */
   3212 #define has_tls_reloc sec_flg0
   3213 
   3214 /* Nonzero if this section has a call to __tls_get_addr.  */
   3215 #define has_tls_get_addr_call sec_flg1
   3216 
   3217 /* Get the PPC ELF linker hash table from a link_info structure.  */
   3218 
   3219 #define ppc_elf_hash_table(p) \
   3220   (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
   3221   == PPC32_ELF_DATA ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL)
   3222 
   3223 /* Create an entry in a PPC ELF linker hash table.  */
   3224 
   3225 static struct bfd_hash_entry *
   3226 ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
   3227 			   struct bfd_hash_table *table,
   3228 			   const char *string)
   3229 {
   3230   /* Allocate the structure if it has not already been allocated by a
   3231      subclass.  */
   3232   if (entry == NULL)
   3233     {
   3234       entry = bfd_hash_allocate (table,
   3235 				 sizeof (struct ppc_elf_link_hash_entry));
   3236       if (entry == NULL)
   3237 	return entry;
   3238     }
   3239 
   3240   /* Call the allocation method of the superclass.  */
   3241   entry = _bfd_elf_link_hash_newfunc (entry, table, string);
   3242   if (entry != NULL)
   3243     {
   3244       ppc_elf_hash_entry (entry)->linker_section_pointer = NULL;
   3245       ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
   3246       ppc_elf_hash_entry (entry)->tls_mask = 0;
   3247       ppc_elf_hash_entry (entry)->has_sda_refs = 0;
   3248     }
   3249 
   3250   return entry;
   3251 }
   3252 
   3253 /* Create a PPC ELF linker hash table.  */
   3254 
   3255 static struct bfd_link_hash_table *
   3256 ppc_elf_link_hash_table_create (bfd *abfd)
   3257 {
   3258   struct ppc_elf_link_hash_table *ret;
   3259   static struct ppc_elf_params default_params = { PLT_OLD, 0, 1, 0, 0, 12 };
   3260 
   3261   ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
   3262   if (ret == NULL)
   3263     return NULL;
   3264 
   3265   if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
   3266 				      ppc_elf_link_hash_newfunc,
   3267 				      sizeof (struct ppc_elf_link_hash_entry),
   3268 				      PPC32_ELF_DATA))
   3269     {
   3270       free (ret);
   3271       return NULL;
   3272     }
   3273 
   3274   ret->elf.init_plt_refcount.refcount = 0;
   3275   ret->elf.init_plt_refcount.glist = NULL;
   3276   ret->elf.init_plt_offset.offset = 0;
   3277   ret->elf.init_plt_offset.glist = NULL;
   3278 
   3279   ret->params = &default_params;
   3280 
   3281   ret->sdata[0].name = ".sdata";
   3282   ret->sdata[0].sym_name = "_SDA_BASE_";
   3283   ret->sdata[0].bss_name = ".sbss";
   3284 
   3285   ret->sdata[1].name = ".sdata2";
   3286   ret->sdata[1].sym_name = "_SDA2_BASE_";
   3287   ret->sdata[1].bss_name = ".sbss2";
   3288 
   3289   ret->plt_entry_size = 12;
   3290   ret->plt_slot_size = 8;
   3291   ret->plt_initial_entry_size = 72;
   3292 
   3293   return &ret->elf.root;
   3294 }
   3295 
   3296 /* Hook linker params into hash table.  */
   3297 
   3298 void
   3299 ppc_elf_link_params (struct bfd_link_info *info, struct ppc_elf_params *params)
   3300 {
   3301   struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
   3302 
   3303   if (htab)
   3304     htab->params = params;
   3305 }
   3306 
   3307 /* Create .got and the related sections.  */
   3308 
   3309 static bfd_boolean
   3310 ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info)
   3311 {
   3312   struct ppc_elf_link_hash_table *htab;
   3313   asection *s;
   3314   flagword flags;
   3315 
   3316   if (!_bfd_elf_create_got_section (abfd, info))
   3317     return FALSE;
   3318 
   3319   htab = ppc_elf_hash_table (info);
   3320   htab->got = s = bfd_get_linker_section (abfd, ".got");
   3321   if (s == NULL)
   3322     abort ();
   3323 
   3324   if (htab->is_vxworks)
   3325     {
   3326       htab->sgotplt = bfd_get_linker_section (abfd, ".got.plt");
   3327       if (!htab->sgotplt)
   3328 	abort ();
   3329     }
   3330   else
   3331     {
   3332       /* The powerpc .got has a blrl instruction in it.  Mark it
   3333 	 executable.  */
   3334       flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS
   3335 	       | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   3336       if (!bfd_set_section_flags (abfd, s, flags))
   3337 	return FALSE;
   3338     }
   3339 
   3340   htab->relgot = bfd_get_linker_section (abfd, ".rela.got");
   3341   if (!htab->relgot)
   3342     abort ();
   3343 
   3344   return TRUE;
   3345 }
   3346 
   3347 /* Create a special linker section, used for R_PPC_EMB_SDAI16 and
   3348    R_PPC_EMB_SDA2I16 pointers.  These sections become part of .sdata
   3349    and .sdata2.  Create _SDA_BASE_ and _SDA2_BASE too.  */
   3350 
   3351 static bfd_boolean
   3352 ppc_elf_create_linker_section (bfd *abfd,
   3353 			       struct bfd_link_info *info,
   3354 			       flagword flags,
   3355 			       elf_linker_section_t *lsect)
   3356 {
   3357   asection *s;
   3358 
   3359   flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
   3360 	    | SEC_LINKER_CREATED);
   3361 
   3362   s = bfd_make_section_anyway_with_flags (abfd, lsect->name, flags);
   3363   if (s == NULL)
   3364     return FALSE;
   3365   lsect->section = s;
   3366 
   3367   /* Define the sym on the first section of this name.  */
   3368   s = bfd_get_section_by_name (abfd, lsect->name);
   3369 
   3370   lsect->sym = _bfd_elf_define_linkage_sym (abfd, info, s, lsect->sym_name);
   3371   if (lsect->sym == NULL)
   3372     return FALSE;
   3373   lsect->sym->root.u.def.value = 0x8000;
   3374   return TRUE;
   3375 }
   3376 
   3377 static bfd_boolean
   3378 ppc_elf_create_glink (bfd *abfd, struct bfd_link_info *info)
   3379 {
   3380   struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
   3381   asection *s;
   3382   flagword flags;
   3383 
   3384   flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS
   3385 	   | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   3386   s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags);
   3387   htab->glink = s;
   3388   if (s == NULL
   3389       || !bfd_set_section_alignment (abfd, s,
   3390 				     htab->params->ppc476_workaround ? 6 : 4))
   3391     return FALSE;
   3392 
   3393   if (!info->no_ld_generated_unwind_info)
   3394     {
   3395       flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
   3396 	       | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   3397       s = bfd_make_section_anyway_with_flags (abfd, ".eh_frame", flags);
   3398       htab->glink_eh_frame = s;
   3399       if (s == NULL
   3400 	  || !bfd_set_section_alignment (abfd, s, 2))
   3401 	return FALSE;
   3402     }
   3403 
   3404   flags = SEC_ALLOC | SEC_LINKER_CREATED;
   3405   s = bfd_make_section_anyway_with_flags (abfd, ".iplt", flags);
   3406   htab->iplt = s;
   3407   if (s == NULL
   3408       || !bfd_set_section_alignment (abfd, s, 4))
   3409     return FALSE;
   3410 
   3411   flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
   3412 	   | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   3413   s = bfd_make_section_anyway_with_flags (abfd, ".rela.iplt", flags);
   3414   htab->reliplt = s;
   3415   if (s == NULL
   3416       || ! bfd_set_section_alignment (abfd, s, 2))
   3417     return FALSE;
   3418 
   3419   if (!ppc_elf_create_linker_section (abfd, info, 0,
   3420 				      &htab->sdata[0]))
   3421     return FALSE;
   3422 
   3423   if (!ppc_elf_create_linker_section (abfd, info, SEC_READONLY,
   3424 				      &htab->sdata[1]))
   3425     return FALSE;
   3426 
   3427   return TRUE;
   3428 }
   3429 
   3430 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
   3431    to output sections (just like _bfd_elf_create_dynamic_sections has
   3432    to create .dynbss and .rela.bss).  */
   3433 
   3434 static bfd_boolean
   3435 ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   3436 {
   3437   struct ppc_elf_link_hash_table *htab;
   3438   asection *s;
   3439   flagword flags;
   3440 
   3441   htab = ppc_elf_hash_table (info);
   3442 
   3443   if (htab->got == NULL
   3444       && !ppc_elf_create_got (abfd, info))
   3445     return FALSE;
   3446 
   3447   if (!_bfd_elf_create_dynamic_sections (abfd, info))
   3448     return FALSE;
   3449 
   3450   if (htab->glink == NULL
   3451       && !ppc_elf_create_glink (abfd, info))
   3452     return FALSE;
   3453 
   3454   htab->dynbss = bfd_get_linker_section (abfd, ".dynbss");
   3455   s = bfd_make_section_anyway_with_flags (abfd, ".dynsbss",
   3456 					  SEC_ALLOC | SEC_LINKER_CREATED);
   3457   htab->dynsbss = s;
   3458   if (s == NULL)
   3459     return FALSE;
   3460 
   3461   if (! info->shared)
   3462     {
   3463       htab->relbss = bfd_get_linker_section (abfd, ".rela.bss");
   3464       flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
   3465 	       | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   3466       s = bfd_make_section_anyway_with_flags (abfd, ".rela.sbss", flags);
   3467       htab->relsbss = s;
   3468       if (s == NULL
   3469 	  || ! bfd_set_section_alignment (abfd, s, 2))
   3470 	return FALSE;
   3471     }
   3472 
   3473   if (htab->is_vxworks
   3474       && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
   3475     return FALSE;
   3476 
   3477   htab->relplt = bfd_get_linker_section (abfd, ".rela.plt");
   3478   htab->plt = s = bfd_get_linker_section (abfd, ".plt");
   3479   if (s == NULL)
   3480     abort ();
   3481 
   3482   flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED;
   3483   if (htab->plt_type == PLT_VXWORKS)
   3484     /* The VxWorks PLT is a loaded section with contents.  */
   3485     flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY;
   3486   return bfd_set_section_flags (abfd, s, flags);
   3487 }
   3488 
   3489 /* Copy the extra info we tack onto an elf_link_hash_entry.  */
   3490 
   3491 static void
   3492 ppc_elf_copy_indirect_symbol (struct bfd_link_info *info,
   3493 			      struct elf_link_hash_entry *dir,
   3494 			      struct elf_link_hash_entry *ind)
   3495 {
   3496   struct ppc_elf_link_hash_entry *edir, *eind;
   3497 
   3498   edir = (struct ppc_elf_link_hash_entry *) dir;
   3499   eind = (struct ppc_elf_link_hash_entry *) ind;
   3500 
   3501   edir->tls_mask |= eind->tls_mask;
   3502   edir->has_sda_refs |= eind->has_sda_refs;
   3503 
   3504   /* If called to transfer flags for a weakdef during processing
   3505      of elf_adjust_dynamic_symbol, don't copy non_got_ref.
   3506      We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
   3507   if (!(ELIMINATE_COPY_RELOCS
   3508 	&& eind->elf.root.type != bfd_link_hash_indirect
   3509 	&& edir->elf.dynamic_adjusted))
   3510     edir->elf.non_got_ref |= eind->elf.non_got_ref;
   3511 
   3512   edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
   3513   edir->elf.ref_regular |= eind->elf.ref_regular;
   3514   edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
   3515   edir->elf.needs_plt |= eind->elf.needs_plt;
   3516   edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed;
   3517 
   3518   if (eind->dyn_relocs != NULL)
   3519     {
   3520       if (edir->dyn_relocs != NULL)
   3521 	{
   3522 	  struct elf_dyn_relocs **pp;
   3523 	  struct elf_dyn_relocs *p;
   3524 
   3525 	  /* Add reloc counts against the indirect sym to the direct sym
   3526 	     list.  Merge any entries against the same section.  */
   3527 	  for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
   3528 	    {
   3529 	      struct elf_dyn_relocs *q;
   3530 
   3531 	      for (q = edir->dyn_relocs; q != NULL; q = q->next)
   3532 		if (q->sec == p->sec)
   3533 		  {
   3534 		    q->pc_count += p->pc_count;
   3535 		    q->count += p->count;
   3536 		    *pp = p->next;
   3537 		    break;
   3538 		  }
   3539 	      if (q == NULL)
   3540 		pp = &p->next;
   3541 	    }
   3542 	  *pp = edir->dyn_relocs;
   3543 	}
   3544 
   3545       edir->dyn_relocs = eind->dyn_relocs;
   3546       eind->dyn_relocs = NULL;
   3547     }
   3548 
   3549   /* If we were called to copy over info for a weak sym, that's all.
   3550      You might think dyn_relocs need not be copied over;  After all,
   3551      both syms will be dynamic or both non-dynamic so we're just
   3552      moving reloc accounting around.  However, ELIMINATE_COPY_RELOCS
   3553      code in ppc_elf_adjust_dynamic_symbol needs to check for
   3554      dyn_relocs in read-only sections, and it does so on what is the
   3555      DIR sym here.  */
   3556   if (eind->elf.root.type != bfd_link_hash_indirect)
   3557     return;
   3558 
   3559   /* Copy over the GOT refcount entries that we may have already seen to
   3560      the symbol which just became indirect.  */
   3561   edir->elf.got.refcount += eind->elf.got.refcount;
   3562   eind->elf.got.refcount = 0;
   3563 
   3564   /* And plt entries.  */
   3565   if (eind->elf.plt.plist != NULL)
   3566     {
   3567       if (edir->elf.plt.plist != NULL)
   3568 	{
   3569 	  struct plt_entry **entp;
   3570 	  struct plt_entry *ent;
   3571 
   3572 	  for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; )
   3573 	    {
   3574 	      struct plt_entry *dent;
   3575 
   3576 	      for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next)
   3577 		if (dent->sec == ent->sec && dent->addend == ent->addend)
   3578 		  {
   3579 		    dent->plt.refcount += ent->plt.refcount;
   3580 		    *entp = ent->next;
   3581 		    break;
   3582 		  }
   3583 	      if (dent == NULL)
   3584 		entp = &ent->next;
   3585 	    }
   3586 	  *entp = edir->elf.plt.plist;
   3587 	}
   3588 
   3589       edir->elf.plt.plist = eind->elf.plt.plist;
   3590       eind->elf.plt.plist = NULL;
   3591     }
   3592 
   3593   if (eind->elf.dynindx != -1)
   3594     {
   3595       if (edir->elf.dynindx != -1)
   3596 	_bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
   3597 				edir->elf.dynstr_index);
   3598       edir->elf.dynindx = eind->elf.dynindx;
   3599       edir->elf.dynstr_index = eind->elf.dynstr_index;
   3600       eind->elf.dynindx = -1;
   3601       eind->elf.dynstr_index = 0;
   3602     }
   3603 }
   3604 
   3605 /* Hook called by the linker routine which adds symbols from an object
   3606    file.  We use it to put .comm items in .sbss, and not .bss.  */
   3607 
   3608 static bfd_boolean
   3609 ppc_elf_add_symbol_hook (bfd *abfd,
   3610 			 struct bfd_link_info *info,
   3611 			 Elf_Internal_Sym *sym,
   3612 			 const char **namep ATTRIBUTE_UNUSED,
   3613 			 flagword *flagsp ATTRIBUTE_UNUSED,
   3614 			 asection **secp,
   3615 			 bfd_vma *valp)
   3616 {
   3617   if (sym->st_shndx == SHN_COMMON
   3618       && !info->relocatable
   3619       && is_ppc_elf (info->output_bfd)
   3620       && sym->st_size <= elf_gp_size (abfd))
   3621     {
   3622       /* Common symbols less than or equal to -G nn bytes are automatically
   3623 	 put into .sbss.  */
   3624       struct ppc_elf_link_hash_table *htab;
   3625 
   3626       htab = ppc_elf_hash_table (info);
   3627       if (htab->sbss == NULL)
   3628 	{
   3629 	  flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED;
   3630 
   3631 	  if (!htab->elf.dynobj)
   3632 	    htab->elf.dynobj = abfd;
   3633 
   3634 	  htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
   3635 							   ".sbss",
   3636 							   flags);
   3637 	  if (htab->sbss == NULL)
   3638 	    return FALSE;
   3639 	}
   3640 
   3641       *secp = htab->sbss;
   3642       *valp = sym->st_size;
   3643     }
   3644 
   3645   if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
   3646        || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
   3647       && (abfd->flags & DYNAMIC) == 0
   3648       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
   3649     elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
   3650 
   3651   return TRUE;
   3652 }
   3653 
   3654 /* Find a linker generated pointer with a given addend and type.  */
   3656 
   3657 static elf_linker_section_pointers_t *
   3658 elf_find_pointer_linker_section
   3659   (elf_linker_section_pointers_t *linker_pointers,
   3660    bfd_vma addend,
   3661    elf_linker_section_t *lsect)
   3662 {
   3663   for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next)
   3664     if (lsect == linker_pointers->lsect && addend == linker_pointers->addend)
   3665       return linker_pointers;
   3666 
   3667   return NULL;
   3668 }
   3669 
   3670 /* Allocate a pointer to live in a linker created section.  */
   3671 
   3672 static bfd_boolean
   3673 elf_allocate_pointer_linker_section (bfd *abfd,
   3674 				     elf_linker_section_t *lsect,
   3675 				     struct elf_link_hash_entry *h,
   3676 				     const Elf_Internal_Rela *rel)
   3677 {
   3678   elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL;
   3679   elf_linker_section_pointers_t *linker_section_ptr;
   3680   unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
   3681   bfd_size_type amt;
   3682 
   3683   BFD_ASSERT (lsect != NULL);
   3684 
   3685   /* Is this a global symbol?  */
   3686   if (h != NULL)
   3687     {
   3688       struct ppc_elf_link_hash_entry *eh;
   3689 
   3690       /* Has this symbol already been allocated?  If so, our work is done.  */
   3691       eh = (struct ppc_elf_link_hash_entry *) h;
   3692       if (elf_find_pointer_linker_section (eh->linker_section_pointer,
   3693 					   rel->r_addend,
   3694 					   lsect))
   3695 	return TRUE;
   3696 
   3697       ptr_linker_section_ptr = &eh->linker_section_pointer;
   3698     }
   3699   else
   3700     {
   3701       BFD_ASSERT (is_ppc_elf (abfd));
   3702 
   3703       /* Allocation of a pointer to a local symbol.  */
   3704       elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
   3705 
   3706       /* Allocate a table to hold the local symbols if first time.  */
   3707       if (!ptr)
   3708 	{
   3709 	  unsigned int num_symbols = elf_symtab_hdr (abfd).sh_info;
   3710 
   3711 	  amt = num_symbols;
   3712 	  amt *= sizeof (elf_linker_section_pointers_t *);
   3713 	  ptr = bfd_zalloc (abfd, amt);
   3714 
   3715 	  if (!ptr)
   3716 	    return FALSE;
   3717 
   3718 	  elf_local_ptr_offsets (abfd) = ptr;
   3719 	}
   3720 
   3721       /* Has this symbol already been allocated?  If so, our work is done.  */
   3722       if (elf_find_pointer_linker_section (ptr[r_symndx],
   3723 					   rel->r_addend,
   3724 					   lsect))
   3725 	return TRUE;
   3726 
   3727       ptr_linker_section_ptr = &ptr[r_symndx];
   3728     }
   3729 
   3730   /* Allocate space for a pointer in the linker section, and allocate
   3731      a new pointer record from internal memory.  */
   3732   BFD_ASSERT (ptr_linker_section_ptr != NULL);
   3733   amt = sizeof (elf_linker_section_pointers_t);
   3734   linker_section_ptr = bfd_alloc (abfd, amt);
   3735 
   3736   if (!linker_section_ptr)
   3737     return FALSE;
   3738 
   3739   linker_section_ptr->next = *ptr_linker_section_ptr;
   3740   linker_section_ptr->addend = rel->r_addend;
   3741   linker_section_ptr->lsect = lsect;
   3742   *ptr_linker_section_ptr = linker_section_ptr;
   3743 
   3744   if (!bfd_set_section_alignment (lsect->section->owner, lsect->section, 2))
   3745     return FALSE;
   3746   linker_section_ptr->offset = lsect->section->size;
   3747   lsect->section->size += 4;
   3748 
   3749 #ifdef DEBUG
   3750   fprintf (stderr,
   3751 	   "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
   3752 	   lsect->name, (long) linker_section_ptr->offset,
   3753 	   (long) lsect->section->size);
   3754 #endif
   3755 
   3756   return TRUE;
   3757 }
   3758 
   3759 static struct plt_entry **
   3760 update_local_sym_info (bfd *abfd,
   3761 		       Elf_Internal_Shdr *symtab_hdr,
   3762 		       unsigned long r_symndx,
   3763 		       int tls_type)
   3764 {
   3765   bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
   3766   struct plt_entry **local_plt;
   3767   char *local_got_tls_masks;
   3768 
   3769   if (local_got_refcounts == NULL)
   3770     {
   3771       bfd_size_type size = symtab_hdr->sh_info;
   3772 
   3773       size *= (sizeof (*local_got_refcounts)
   3774 	       + sizeof (*local_plt)
   3775 	       + sizeof (*local_got_tls_masks));
   3776       local_got_refcounts = bfd_zalloc (abfd, size);
   3777       if (local_got_refcounts == NULL)
   3778 	return NULL;
   3779       elf_local_got_refcounts (abfd) = local_got_refcounts;
   3780     }
   3781 
   3782   local_plt = (struct plt_entry **) (local_got_refcounts + symtab_hdr->sh_info);
   3783   local_got_tls_masks = (char *) (local_plt + symtab_hdr->sh_info);
   3784   local_got_tls_masks[r_symndx] |= tls_type;
   3785   if (tls_type != PLT_IFUNC)
   3786     local_got_refcounts[r_symndx] += 1;
   3787   return local_plt + r_symndx;
   3788 }
   3789 
   3790 static bfd_boolean
   3791 update_plt_info (bfd *abfd, struct plt_entry **plist,
   3792 		 asection *sec, bfd_vma addend)
   3793 {
   3794   struct plt_entry *ent;
   3795 
   3796   if (addend < 32768)
   3797     sec = NULL;
   3798   for (ent = *plist; ent != NULL; ent = ent->next)
   3799     if (ent->sec == sec && ent->addend == addend)
   3800       break;
   3801   if (ent == NULL)
   3802     {
   3803       bfd_size_type amt = sizeof (*ent);
   3804       ent = bfd_alloc (abfd, amt);
   3805       if (ent == NULL)
   3806 	return FALSE;
   3807       ent->next = *plist;
   3808       ent->sec = sec;
   3809       ent->addend = addend;
   3810       ent->plt.refcount = 0;
   3811       *plist = ent;
   3812     }
   3813   ent->plt.refcount += 1;
   3814   return TRUE;
   3815 }
   3816 
   3817 static struct plt_entry *
   3818 find_plt_ent (struct plt_entry **plist, asection *sec, bfd_vma addend)
   3819 {
   3820   struct plt_entry *ent;
   3821 
   3822   if (addend < 32768)
   3823     sec = NULL;
   3824   for (ent = *plist; ent != NULL; ent = ent->next)
   3825     if (ent->sec == sec && ent->addend == addend)
   3826       break;
   3827   return ent;
   3828 }
   3829 
   3830 static bfd_boolean
   3831 is_branch_reloc (enum elf_ppc_reloc_type r_type)
   3832 {
   3833   return (r_type == R_PPC_PLTREL24
   3834 	  || r_type == R_PPC_LOCAL24PC
   3835 	  || r_type == R_PPC_REL24
   3836 	  || r_type == R_PPC_REL14
   3837 	  || r_type == R_PPC_REL14_BRTAKEN
   3838 	  || r_type == R_PPC_REL14_BRNTAKEN
   3839 	  || r_type == R_PPC_ADDR24
   3840 	  || r_type == R_PPC_ADDR14
   3841 	  || r_type == R_PPC_ADDR14_BRTAKEN
   3842 	  || r_type == R_PPC_ADDR14_BRNTAKEN);
   3843 }
   3844 
   3845 static void
   3846 bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type)
   3847 {
   3848   (*_bfd_error_handler)
   3849     (_("%B: relocation %s cannot be used when making a shared object"),
   3850      abfd,
   3851      ppc_elf_howto_table[r_type]->name);
   3852   bfd_set_error (bfd_error_bad_value);
   3853 }
   3854 
   3855 /* Look through the relocs for a section during the first phase, and
   3856    allocate space in the global offset table or procedure linkage
   3857    table.  */
   3858 
   3859 static bfd_boolean
   3860 ppc_elf_check_relocs (bfd *abfd,
   3861 		      struct bfd_link_info *info,
   3862 		      asection *sec,
   3863 		      const Elf_Internal_Rela *relocs)
   3864 {
   3865   struct ppc_elf_link_hash_table *htab;
   3866   Elf_Internal_Shdr *symtab_hdr;
   3867   struct elf_link_hash_entry **sym_hashes;
   3868   const Elf_Internal_Rela *rel;
   3869   const Elf_Internal_Rela *rel_end;
   3870   asection *got2, *sreloc;
   3871   struct elf_link_hash_entry *tga;
   3872 
   3873   if (info->relocatable)
   3874     return TRUE;
   3875 
   3876   /* Don't do anything special with non-loaded, non-alloced sections.
   3877      In particular, any relocs in such sections should not affect GOT
   3878      and PLT reference counting (ie. we don't allow them to create GOT
   3879      or PLT entries), there's no possibility or desire to optimize TLS
   3880      relocs, and there's not much point in propagating relocs to shared
   3881      libs that the dynamic linker won't relocate.  */
   3882   if ((sec->flags & SEC_ALLOC) == 0)
   3883     return TRUE;
   3884 
   3885 #ifdef DEBUG
   3886   _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
   3887 		      sec, abfd);
   3888 #endif
   3889 
   3890   BFD_ASSERT (is_ppc_elf (abfd));
   3891 
   3892   /* Initialize howto table if not already done.  */
   3893   if (!ppc_elf_howto_table[R_PPC_ADDR32])
   3894     ppc_elf_howto_init ();
   3895 
   3896   htab = ppc_elf_hash_table (info);
   3897   if (htab->glink == NULL)
   3898     {
   3899       if (htab->elf.dynobj == NULL)
   3900 	htab->elf.dynobj = abfd;
   3901       if (!ppc_elf_create_glink (htab->elf.dynobj, info))
   3902 	return FALSE;
   3903     }
   3904   tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
   3905 			      FALSE, FALSE, TRUE);
   3906   symtab_hdr = &elf_symtab_hdr (abfd);
   3907   sym_hashes = elf_sym_hashes (abfd);
   3908   got2 = bfd_get_section_by_name (abfd, ".got2");
   3909   sreloc = NULL;
   3910 
   3911   rel_end = relocs + sec->reloc_count;
   3912   for (rel = relocs; rel < rel_end; rel++)
   3913     {
   3914       unsigned long r_symndx;
   3915       enum elf_ppc_reloc_type r_type;
   3916       struct elf_link_hash_entry *h;
   3917       int tls_type;
   3918 
   3919       r_symndx = ELF32_R_SYM (rel->r_info);
   3920       if (r_symndx < symtab_hdr->sh_info)
   3921 	h = NULL;
   3922       else
   3923 	{
   3924 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   3925 	  while (h->root.type == bfd_link_hash_indirect
   3926 		 || h->root.type == bfd_link_hash_warning)
   3927 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   3928 
   3929 	  /* PR15323, ref flags aren't set for references in the same
   3930 	     object.  */
   3931 	  h->root.non_ir_ref = 1;
   3932 	}
   3933 
   3934       /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
   3935 	 This shows up in particular in an R_PPC_ADDR32 in the eabi
   3936 	 startup code.  */
   3937       if (h != NULL
   3938 	  && htab->got == NULL
   3939 	  && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
   3940 	{
   3941 	  if (htab->elf.dynobj == NULL)
   3942 	    htab->elf.dynobj = abfd;
   3943 	  if (!ppc_elf_create_got (htab->elf.dynobj, info))
   3944 	    return FALSE;
   3945 	  BFD_ASSERT (h == htab->elf.hgot);
   3946 	}
   3947 
   3948       tls_type = 0;
   3949       r_type = ELF32_R_TYPE (rel->r_info);
   3950       if (h == NULL && !htab->is_vxworks)
   3951 	{
   3952 	  Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
   3953 							  abfd, r_symndx);
   3954 	  if (isym == NULL)
   3955 	    return FALSE;
   3956 
   3957 	  if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
   3958 	    {
   3959 	      struct plt_entry **ifunc;
   3960 
   3961 	      /* Set PLT_IFUNC flag for this sym, no GOT entry yet.  */
   3962 	      ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
   3963 					     PLT_IFUNC);
   3964 	      if (ifunc == NULL)
   3965 		return FALSE;
   3966 
   3967 	      /* STT_GNU_IFUNC symbols must have a PLT entry;
   3968 		 In a non-pie executable even when there are
   3969 		 no plt calls.  */
   3970 	      if (!info->shared
   3971 		  || is_branch_reloc (r_type))
   3972 		{
   3973 		  bfd_vma addend = 0;
   3974 		  if (r_type == R_PPC_PLTREL24)
   3975 		    {
   3976 		      ppc_elf_tdata (abfd)->makes_plt_call = 1;
   3977 		      if (info->shared)
   3978 			addend = rel->r_addend;
   3979 		    }
   3980 		  if (!update_plt_info (abfd, ifunc, got2, addend))
   3981 		    return FALSE;
   3982 		}
   3983 	    }
   3984 	}
   3985 
   3986       if (!htab->is_vxworks
   3987 	  && is_branch_reloc (r_type)
   3988 	  && h != NULL
   3989 	  && h == tga)
   3990 	{
   3991 	  if (rel != relocs
   3992 	      && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD
   3993 		  || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD))
   3994 	    /* We have a new-style __tls_get_addr call with a marker
   3995 	       reloc.  */
   3996 	    ;
   3997 	  else
   3998 	    /* Mark this section as having an old-style call.  */
   3999 	    sec->has_tls_get_addr_call = 1;
   4000 	}
   4001 
   4002       switch (r_type)
   4003 	{
   4004 	case R_PPC_TLSGD:
   4005 	case R_PPC_TLSLD:
   4006 	  /* These special tls relocs tie a call to __tls_get_addr with
   4007 	     its parameter symbol.  */
   4008 	  break;
   4009 
   4010 	case R_PPC_GOT_TLSLD16:
   4011 	case R_PPC_GOT_TLSLD16_LO:
   4012 	case R_PPC_GOT_TLSLD16_HI:
   4013 	case R_PPC_GOT_TLSLD16_HA:
   4014 	  tls_type = TLS_TLS | TLS_LD;
   4015 	  goto dogottls;
   4016 
   4017 	case R_PPC_GOT_TLSGD16:
   4018 	case R_PPC_GOT_TLSGD16_LO:
   4019 	case R_PPC_GOT_TLSGD16_HI:
   4020 	case R_PPC_GOT_TLSGD16_HA:
   4021 	  tls_type = TLS_TLS | TLS_GD;
   4022 	  goto dogottls;
   4023 
   4024 	case R_PPC_GOT_TPREL16:
   4025 	case R_PPC_GOT_TPREL16_LO:
   4026 	case R_PPC_GOT_TPREL16_HI:
   4027 	case R_PPC_GOT_TPREL16_HA:
   4028 	  if (info->shared)
   4029 	    info->flags |= DF_STATIC_TLS;
   4030 	  tls_type = TLS_TLS | TLS_TPREL;
   4031 	  goto dogottls;
   4032 
   4033 	case R_PPC_GOT_DTPREL16:
   4034 	case R_PPC_GOT_DTPREL16_LO:
   4035 	case R_PPC_GOT_DTPREL16_HI:
   4036 	case R_PPC_GOT_DTPREL16_HA:
   4037 	  tls_type = TLS_TLS | TLS_DTPREL;
   4038 	dogottls:
   4039 	  sec->has_tls_reloc = 1;
   4040 	  /* Fall thru */
   4041 
   4042 	  /* GOT16 relocations */
   4043 	case R_PPC_GOT16:
   4044 	case R_PPC_GOT16_LO:
   4045 	case R_PPC_GOT16_HI:
   4046 	case R_PPC_GOT16_HA:
   4047 	  /* This symbol requires a global offset table entry.  */
   4048 	  if (htab->got == NULL)
   4049 	    {
   4050 	      if (htab->elf.dynobj == NULL)
   4051 		htab->elf.dynobj = abfd;
   4052 	      if (!ppc_elf_create_got (htab->elf.dynobj, info))
   4053 		return FALSE;
   4054 	    }
   4055 	  if (h != NULL)
   4056 	    {
   4057 	      h->got.refcount += 1;
   4058 	      ppc_elf_hash_entry (h)->tls_mask |= tls_type;
   4059 	    }
   4060 	  else
   4061 	    /* This is a global offset table entry for a local symbol.  */
   4062 	    if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
   4063 	      return FALSE;
   4064 
   4065 	  /* We may also need a plt entry if the symbol turns out to be
   4066 	     an ifunc.  */
   4067 	  if (h != NULL && !info->shared)
   4068 	    {
   4069 	      if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
   4070 		return FALSE;
   4071 	    }
   4072 	  break;
   4073 
   4074 	  /* Indirect .sdata relocation.  */
   4075 	case R_PPC_EMB_SDAI16:
   4076 	  if (info->shared)
   4077 	    {
   4078 	      bad_shared_reloc (abfd, r_type);
   4079 	      return FALSE;
   4080 	    }
   4081 	  htab->sdata[0].sym->ref_regular = 1;
   4082 	  if (!elf_allocate_pointer_linker_section (abfd, &htab->sdata[0],
   4083 						    h, rel))
   4084 	    return FALSE;
   4085 	  if (h != NULL)
   4086 	    {
   4087 	      ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
   4088 	      h->non_got_ref = TRUE;
   4089 	    }
   4090 	  break;
   4091 
   4092 	  /* Indirect .sdata2 relocation.  */
   4093 	case R_PPC_EMB_SDA2I16:
   4094 	  if (info->shared)
   4095 	    {
   4096 	      bad_shared_reloc (abfd, r_type);
   4097 	      return FALSE;
   4098 	    }
   4099 	  htab->sdata[1].sym->ref_regular = 1;
   4100 	  if (!elf_allocate_pointer_linker_section (abfd, &htab->sdata[1],
   4101 						    h, rel))
   4102 	    return FALSE;
   4103 	  if (h != NULL)
   4104 	    {
   4105 	      ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
   4106 	      h->non_got_ref = TRUE;
   4107 	    }
   4108 	  break;
   4109 
   4110 	case R_PPC_SDAREL16:
   4111 	  htab->sdata[0].sym->ref_regular = 1;
   4112 	  /* Fall thru */
   4113 
   4114 	case R_PPC_VLE_SDAREL_LO16A:
   4115 	case R_PPC_VLE_SDAREL_LO16D:
   4116 	case R_PPC_VLE_SDAREL_HI16A:
   4117 	case R_PPC_VLE_SDAREL_HI16D:
   4118 	case R_PPC_VLE_SDAREL_HA16A:
   4119 	case R_PPC_VLE_SDAREL_HA16D:
   4120 	  if (h != NULL)
   4121 	    {
   4122 	      ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
   4123 	      h->non_got_ref = TRUE;
   4124 	    }
   4125 	  break;
   4126 
   4127 	case R_PPC_VLE_REL8:
   4128 	case R_PPC_VLE_REL15:
   4129 	case R_PPC_VLE_REL24:
   4130 	case R_PPC_VLE_LO16A:
   4131 	case R_PPC_VLE_LO16D:
   4132 	case R_PPC_VLE_HI16A:
   4133 	case R_PPC_VLE_HI16D:
   4134 	case R_PPC_VLE_HA16A:
   4135 	case R_PPC_VLE_HA16D:
   4136 	  break;
   4137 
   4138 	case R_PPC_EMB_SDA2REL:
   4139 	  if (info->shared)
   4140 	    {
   4141 	      bad_shared_reloc (abfd, r_type);
   4142 	      return FALSE;
   4143 	    }
   4144 	  htab->sdata[1].sym->ref_regular = 1;
   4145 	  if (h != NULL)
   4146 	    {
   4147 	      ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
   4148 	      h->non_got_ref = TRUE;
   4149 	    }
   4150 	  break;
   4151 
   4152 	case R_PPC_VLE_SDA21_LO:
   4153 	case R_PPC_VLE_SDA21:
   4154 	case R_PPC_EMB_SDA21:
   4155 	case R_PPC_EMB_RELSDA:
   4156 	  if (info->shared)
   4157 	    {
   4158 	      bad_shared_reloc (abfd, r_type);
   4159 	      return FALSE;
   4160 	    }
   4161 	  if (h != NULL)
   4162 	    {
   4163 	      ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
   4164 	      h->non_got_ref = TRUE;
   4165 	    }
   4166 	  break;
   4167 
   4168 	case R_PPC_EMB_NADDR32:
   4169 	case R_PPC_EMB_NADDR16:
   4170 	case R_PPC_EMB_NADDR16_LO:
   4171 	case R_PPC_EMB_NADDR16_HI:
   4172 	case R_PPC_EMB_NADDR16_HA:
   4173 	  if (info->shared)
   4174 	    {
   4175 	      bad_shared_reloc (abfd, r_type);
   4176 	      return FALSE;
   4177 	    }
   4178 	  if (h != NULL)
   4179 	    h->non_got_ref = TRUE;
   4180 	  break;
   4181 
   4182 	case R_PPC_PLTREL24:
   4183 	  if (h == NULL)
   4184 	    break;
   4185 	  /* Fall through */
   4186 	case R_PPC_PLT32:
   4187 	case R_PPC_PLTREL32:
   4188 	case R_PPC_PLT16_LO:
   4189 	case R_PPC_PLT16_HI:
   4190 	case R_PPC_PLT16_HA:
   4191 #ifdef DEBUG
   4192 	  fprintf (stderr, "Reloc requires a PLT entry\n");
   4193 #endif
   4194 	  /* This symbol requires a procedure linkage table entry.  We
   4195 	     actually build the entry in finish_dynamic_symbol,
   4196 	     because this might be a case of linking PIC code without
   4197 	     linking in any dynamic objects, in which case we don't
   4198 	     need to generate a procedure linkage table after all.  */
   4199 
   4200 	  if (h == NULL)
   4201 	    {
   4202 	      /* It does not make sense to have a procedure linkage
   4203 		 table entry for a local symbol.  */
   4204 	      info->callbacks->einfo (_("%P: %H: %s reloc against local symbol\n"),
   4205 				      abfd, sec, rel->r_offset,
   4206 				      ppc_elf_howto_table[r_type]->name);
   4207 	      bfd_set_error (bfd_error_bad_value);
   4208 	      return FALSE;
   4209 	    }
   4210 	  else
   4211 	    {
   4212 	      bfd_vma addend = 0;
   4213 
   4214 	      if (r_type == R_PPC_PLTREL24)
   4215 		{
   4216 		  ppc_elf_tdata (abfd)->makes_plt_call = 1;
   4217 		  if (info->shared)
   4218 		    addend = rel->r_addend;
   4219 		}
   4220 	      h->needs_plt = 1;
   4221 	      if (!update_plt_info (abfd, &h->plt.plist, got2, addend))
   4222 		return FALSE;
   4223 	    }
   4224 	  break;
   4225 
   4226 	  /* The following relocations don't need to propagate the
   4227 	     relocation if linking a shared object since they are
   4228 	     section relative.  */
   4229 	case R_PPC_SECTOFF:
   4230 	case R_PPC_SECTOFF_LO:
   4231 	case R_PPC_SECTOFF_HI:
   4232 	case R_PPC_SECTOFF_HA:
   4233 	case R_PPC_DTPREL16:
   4234 	case R_PPC_DTPREL16_LO:
   4235 	case R_PPC_DTPREL16_HI:
   4236 	case R_PPC_DTPREL16_HA:
   4237 	case R_PPC_TOC16:
   4238 	  break;
   4239 
   4240 	case R_PPC_REL16:
   4241 	case R_PPC_REL16_LO:
   4242 	case R_PPC_REL16_HI:
   4243 	case R_PPC_REL16_HA:
   4244 	  ppc_elf_tdata (abfd)->has_rel16 = 1;
   4245 	  break;
   4246 
   4247 	  /* These are just markers.  */
   4248 	case R_PPC_TLS:
   4249 	case R_PPC_EMB_MRKREF:
   4250 	case R_PPC_NONE:
   4251 	case R_PPC_max:
   4252 	case R_PPC_RELAX:
   4253 	case R_PPC_RELAX_PLT:
   4254 	case R_PPC_RELAX_PLTREL24:
   4255 	  break;
   4256 
   4257 	  /* These should only appear in dynamic objects.  */
   4258 	case R_PPC_COPY:
   4259 	case R_PPC_GLOB_DAT:
   4260 	case R_PPC_JMP_SLOT:
   4261 	case R_PPC_RELATIVE:
   4262 	case R_PPC_IRELATIVE:
   4263 	  break;
   4264 
   4265 	  /* These aren't handled yet.  We'll report an error later.  */
   4266 	case R_PPC_ADDR30:
   4267 	case R_PPC_EMB_RELSEC16:
   4268 	case R_PPC_EMB_RELST_LO:
   4269 	case R_PPC_EMB_RELST_HI:
   4270 	case R_PPC_EMB_RELST_HA:
   4271 	case R_PPC_EMB_BIT_FLD:
   4272 	  break;
   4273 
   4274 	  /* This refers only to functions defined in the shared library.  */
   4275 	case R_PPC_LOCAL24PC:
   4276 	  if (h != NULL && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
   4277 	    {
   4278 	      htab->plt_type = PLT_OLD;
   4279 	      htab->old_bfd = abfd;
   4280 	    }
   4281 	  if (h != NULL && h->type == STT_GNU_IFUNC)
   4282 	    {
   4283 	      if (info->shared)
   4284 		{
   4285 		  info->callbacks->einfo (_("%P: %H: @local call to ifunc %s\n"),
   4286 					  abfd, sec, rel->r_offset,
   4287 					  h->root.root.string);
   4288 		  bfd_set_error (bfd_error_bad_value);
   4289 		  return FALSE;
   4290 		}
   4291 	      h->needs_plt = 1;
   4292 	      if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
   4293 		return FALSE;
   4294 	    }
   4295 	  break;
   4296 
   4297 	  /* This relocation describes the C++ object vtable hierarchy.
   4298 	     Reconstruct it for later use during GC.  */
   4299 	case R_PPC_GNU_VTINHERIT:
   4300 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
   4301 	    return FALSE;
   4302 	  break;
   4303 
   4304 	  /* This relocation describes which C++ vtable entries are actually
   4305 	     used.  Record for later use during GC.  */
   4306 	case R_PPC_GNU_VTENTRY:
   4307 	  BFD_ASSERT (h != NULL);
   4308 	  if (h != NULL
   4309 	      && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
   4310 	    return FALSE;
   4311 	  break;
   4312 
   4313 	  /* We shouldn't really be seeing these.  */
   4314 	case R_PPC_TPREL32:
   4315 	case R_PPC_TPREL16:
   4316 	case R_PPC_TPREL16_LO:
   4317 	case R_PPC_TPREL16_HI:
   4318 	case R_PPC_TPREL16_HA:
   4319 	  if (info->shared)
   4320 	    info->flags |= DF_STATIC_TLS;
   4321 	  goto dodyn;
   4322 
   4323 	  /* Nor these.  */
   4324 	case R_PPC_DTPMOD32:
   4325 	case R_PPC_DTPREL32:
   4326 	  goto dodyn;
   4327 
   4328 	case R_PPC_REL32:
   4329 	  if (h == NULL
   4330 	      && got2 != NULL
   4331 	      && (sec->flags & SEC_CODE) != 0
   4332 	      && info->shared
   4333 	      && htab->plt_type == PLT_UNSET)
   4334 	    {
   4335 	      /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
   4336 		 the start of a function, which assembles to a REL32
   4337 		 reference to .got2.  If we detect one of these, then
   4338 		 force the old PLT layout because the linker cannot
   4339 		 reliably deduce the GOT pointer value needed for
   4340 		 PLT call stubs.  */
   4341 	      asection *s;
   4342 	      Elf_Internal_Sym *isym;
   4343 
   4344 	      isym = bfd_sym_from_r_symndx (&htab->sym_cache,
   4345 					    abfd, r_symndx);
   4346 	      if (isym == NULL)
   4347 		return FALSE;
   4348 
   4349 	      s = bfd_section_from_elf_index (abfd, isym->st_shndx);
   4350 	      if (s == got2)
   4351 		{
   4352 		  htab->plt_type = PLT_OLD;
   4353 		  htab->old_bfd = abfd;
   4354 		}
   4355 	    }
   4356 	  if (h == NULL || h == htab->elf.hgot)
   4357 	    break;
   4358 	  /* fall through */
   4359 
   4360 	case R_PPC_ADDR32:
   4361 	case R_PPC_ADDR16:
   4362 	case R_PPC_ADDR16_LO:
   4363 	case R_PPC_ADDR16_HI:
   4364 	case R_PPC_ADDR16_HA:
   4365 	case R_PPC_UADDR32:
   4366 	case R_PPC_UADDR16:
   4367 	  if (h != NULL && !info->shared)
   4368 	    {
   4369 	      /* We may need a plt entry if the symbol turns out to be
   4370 		 a function defined in a dynamic object.  */
   4371 	      if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
   4372 		return FALSE;
   4373 
   4374 	      /* We may need a copy reloc too.  */
   4375 	      h->non_got_ref = 1;
   4376 	      h->pointer_equality_needed = 1;
   4377 	    }
   4378 	  goto dodyn;
   4379 
   4380 	case R_PPC_REL24:
   4381 	case R_PPC_REL14:
   4382 	case R_PPC_REL14_BRTAKEN:
   4383 	case R_PPC_REL14_BRNTAKEN:
   4384 	  if (h == NULL)
   4385 	    break;
   4386 	  if (h == htab->elf.hgot)
   4387 	    {
   4388 	      if (htab->plt_type == PLT_UNSET)
   4389 		{
   4390 		  htab->plt_type = PLT_OLD;
   4391 		  htab->old_bfd = abfd;
   4392 		}
   4393 	      break;
   4394 	    }
   4395 	  /* fall through */
   4396 
   4397 	case R_PPC_ADDR24:
   4398 	case R_PPC_ADDR14:
   4399 	case R_PPC_ADDR14_BRTAKEN:
   4400 	case R_PPC_ADDR14_BRNTAKEN:
   4401 	  if (h != NULL && !info->shared)
   4402 	    {
   4403 	      /* We may need a plt entry if the symbol turns out to be
   4404 		 a function defined in a dynamic object.  */
   4405 	      h->needs_plt = 1;
   4406 	      if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
   4407 		return FALSE;
   4408 	      break;
   4409 	    }
   4410 
   4411 	dodyn:
   4412 	  /* If we are creating a shared library, and this is a reloc
   4413 	     against a global symbol, or a non PC relative reloc
   4414 	     against a local symbol, then we need to copy the reloc
   4415 	     into the shared library.  However, if we are linking with
   4416 	     -Bsymbolic, we do not need to copy a reloc against a
   4417 	     global symbol which is defined in an object we are
   4418 	     including in the link (i.e., DEF_REGULAR is set).  At
   4419 	     this point we have not seen all the input files, so it is
   4420 	     possible that DEF_REGULAR is not set now but will be set
   4421 	     later (it is never cleared).  In case of a weak definition,
   4422 	     DEF_REGULAR may be cleared later by a strong definition in
   4423 	     a shared library.  We account for that possibility below by
   4424 	     storing information in the dyn_relocs field of the hash
   4425 	     table entry.  A similar situation occurs when creating
   4426 	     shared libraries and symbol visibility changes render the
   4427 	     symbol local.
   4428 
   4429 	     If on the other hand, we are creating an executable, we
   4430 	     may need to keep relocations for symbols satisfied by a
   4431 	     dynamic library if we manage to avoid copy relocs for the
   4432 	     symbol.  */
   4433 	  if ((info->shared
   4434 	       && (must_be_dyn_reloc (info, r_type)
   4435 		   || (h != NULL
   4436 		       && (!SYMBOLIC_BIND (info, h)
   4437 			   || h->root.type == bfd_link_hash_defweak
   4438 			   || !h->def_regular))))
   4439 	      || (ELIMINATE_COPY_RELOCS
   4440 		  && !info->shared
   4441 		  && h != NULL
   4442 		  && (h->root.type == bfd_link_hash_defweak
   4443 		      || !h->def_regular)))
   4444 	    {
   4445 #ifdef DEBUG
   4446 	      fprintf (stderr,
   4447 		       "ppc_elf_check_relocs needs to "
   4448 		       "create relocation for %s\n",
   4449 		       (h && h->root.root.string
   4450 			? h->root.root.string : "<unknown>"));
   4451 #endif
   4452 	      if (sreloc == NULL)
   4453 		{
   4454 		  if (htab->elf.dynobj == NULL)
   4455 		    htab->elf.dynobj = abfd;
   4456 
   4457 		  sreloc = _bfd_elf_make_dynamic_reloc_section
   4458 		    (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE);
   4459 
   4460 		  if (sreloc == NULL)
   4461 		    return FALSE;
   4462 		}
   4463 
   4464 	      /* If this is a global symbol, we count the number of
   4465 		 relocations we need for this symbol.  */
   4466 	      if (h != NULL)
   4467 		{
   4468 		  struct elf_dyn_relocs *p;
   4469 		  struct elf_dyn_relocs **rel_head;
   4470 
   4471 		  rel_head = &ppc_elf_hash_entry (h)->dyn_relocs;
   4472 		  p = *rel_head;
   4473 		  if (p == NULL || p->sec != sec)
   4474 		    {
   4475 		      p = bfd_alloc (htab->elf.dynobj, sizeof *p);
   4476 		      if (p == NULL)
   4477 			return FALSE;
   4478 		      p->next = *rel_head;
   4479 		      *rel_head = p;
   4480 		      p->sec = sec;
   4481 		      p->count = 0;
   4482 		      p->pc_count = 0;
   4483 		    }
   4484 		  p->count += 1;
   4485 		  if (!must_be_dyn_reloc (info, r_type))
   4486 		    p->pc_count += 1;
   4487 		}
   4488 	      else
   4489 		{
   4490 		  /* Track dynamic relocs needed for local syms too.
   4491 		     We really need local syms available to do this
   4492 		     easily.  Oh well.  */
   4493 		  struct ppc_dyn_relocs *p;
   4494 		  struct ppc_dyn_relocs **rel_head;
   4495 		  bfd_boolean is_ifunc;
   4496 		  asection *s;
   4497 		  void *vpp;
   4498 		  Elf_Internal_Sym *isym;
   4499 
   4500 		  isym = bfd_sym_from_r_symndx (&htab->sym_cache,
   4501 						abfd, r_symndx);
   4502 		  if (isym == NULL)
   4503 		    return FALSE;
   4504 
   4505 		  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
   4506 		  if (s == NULL)
   4507 		    s = sec;
   4508 
   4509 		  vpp = &elf_section_data (s)->local_dynrel;
   4510 		  rel_head = (struct ppc_dyn_relocs **) vpp;
   4511 		  is_ifunc = ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC;
   4512 		  p = *rel_head;
   4513 		  if (p != NULL && p->sec == sec && p->ifunc != is_ifunc)
   4514 		    p = p->next;
   4515 		  if (p == NULL || p->sec != sec || p->ifunc != is_ifunc)
   4516 		    {
   4517 		      p = bfd_alloc (htab->elf.dynobj, sizeof *p);
   4518 		      if (p == NULL)
   4519 			return FALSE;
   4520 		      p->next = *rel_head;
   4521 		      *rel_head = p;
   4522 		      p->sec = sec;
   4523 		      p->ifunc = is_ifunc;
   4524 		      p->count = 0;
   4525 		    }
   4526 		  p->count += 1;
   4527 		}
   4528 	    }
   4529 
   4530 	  break;
   4531 	}
   4532     }
   4533 
   4534   return TRUE;
   4535 }
   4536 
   4537 
   4539 /* Merge object attributes from IBFD into OBFD.  Raise an error if
   4540    there are conflicting attributes.  */
   4541 static bfd_boolean
   4542 ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
   4543 {
   4544   obj_attribute *in_attr, *in_attrs;
   4545   obj_attribute *out_attr, *out_attrs;
   4546 
   4547   if (!elf_known_obj_attributes_proc (obfd)[0].i)
   4548     {
   4549       /* This is the first object.  Copy the attributes.  */
   4550       _bfd_elf_copy_obj_attributes (ibfd, obfd);
   4551 
   4552       /* Use the Tag_null value to indicate the attributes have been
   4553 	 initialized.  */
   4554       elf_known_obj_attributes_proc (obfd)[0].i = 1;
   4555 
   4556       return TRUE;
   4557     }
   4558 
   4559   in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
   4560   out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
   4561 
   4562   /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge
   4563      non-conflicting ones.  */
   4564   in_attr = &in_attrs[Tag_GNU_Power_ABI_FP];
   4565   out_attr = &out_attrs[Tag_GNU_Power_ABI_FP];
   4566   if (in_attr->i != out_attr->i)
   4567     {
   4568       out_attr->type = 1;
   4569       if (out_attr->i == 0)
   4570 	out_attr->i = in_attr->i;
   4571       else if (in_attr->i == 0)
   4572 	;
   4573       else if (out_attr->i == 1 && in_attr->i == 2)
   4574 	_bfd_error_handler
   4575 	  (_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd);
   4576       else if (out_attr->i == 1 && in_attr->i == 3)
   4577 	_bfd_error_handler
   4578 	  (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
   4579 	  obfd, ibfd);
   4580       else if (out_attr->i == 3 && in_attr->i == 1)
   4581 	_bfd_error_handler
   4582 	  (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
   4583 	  ibfd, obfd);
   4584       else if (out_attr->i == 3 && in_attr->i == 2)
   4585 	_bfd_error_handler
   4586 	  (_("Warning: %B uses soft float, %B uses single-precision hard float"),
   4587 	  ibfd, obfd);
   4588       else if (out_attr->i == 2 && (in_attr->i == 1 || in_attr->i == 3))
   4589 	_bfd_error_handler
   4590 	  (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd);
   4591       else if (in_attr->i > 3)
   4592 	_bfd_error_handler
   4593 	  (_("Warning: %B uses unknown floating point ABI %d"), ibfd,
   4594 	   in_attr->i);
   4595       else
   4596 	_bfd_error_handler
   4597 	  (_("Warning: %B uses unknown floating point ABI %d"), obfd,
   4598 	   out_attr->i);
   4599     }
   4600 
   4601   /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and
   4602      merge non-conflicting ones.  */
   4603   in_attr = &in_attrs[Tag_GNU_Power_ABI_Vector];
   4604   out_attr = &out_attrs[Tag_GNU_Power_ABI_Vector];
   4605   if (in_attr->i != out_attr->i)
   4606     {
   4607       const char *in_abi = NULL, *out_abi = NULL;
   4608 
   4609       switch (in_attr->i)
   4610 	{
   4611 	case 1: in_abi = "generic"; break;
   4612 	case 2: in_abi = "AltiVec"; break;
   4613 	case 3: in_abi = "SPE"; break;
   4614 	}
   4615 
   4616       switch (out_attr->i)
   4617 	{
   4618 	case 1: out_abi = "generic"; break;
   4619 	case 2: out_abi = "AltiVec"; break;
   4620 	case 3: out_abi = "SPE"; break;
   4621 	}
   4622 
   4623       out_attr->type = 1;
   4624       if (out_attr->i == 0)
   4625 	out_attr->i = in_attr->i;
   4626       else if (in_attr->i == 0)
   4627 	;
   4628       /* For now, allow generic to transition to AltiVec or SPE
   4629 	 without a warning.  If GCC marked files with their stack
   4630 	 alignment and used don't-care markings for files which are
   4631 	 not affected by the vector ABI, we could warn about this
   4632 	 case too.  */
   4633       else if (out_attr->i == 1)
   4634 	out_attr->i = in_attr->i;
   4635       else if (in_attr->i == 1)
   4636 	;
   4637       else if (in_abi == NULL)
   4638 	_bfd_error_handler
   4639 	  (_("Warning: %B uses unknown vector ABI %d"), ibfd,
   4640 	   in_attr->i);
   4641       else if (out_abi == NULL)
   4642 	_bfd_error_handler
   4643 	  (_("Warning: %B uses unknown vector ABI %d"), obfd,
   4644 	   in_attr->i);
   4645       else
   4646 	_bfd_error_handler
   4647 	  (_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""),
   4648 	   ibfd, obfd, in_abi, out_abi);
   4649     }
   4650 
   4651   /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes
   4652      and merge non-conflicting ones.  */
   4653   in_attr = &in_attrs[Tag_GNU_Power_ABI_Struct_Return];
   4654   out_attr = &out_attrs[Tag_GNU_Power_ABI_Struct_Return];
   4655   if (in_attr->i != out_attr->i)
   4656     {
   4657       out_attr->type = 1;
   4658       if (out_attr->i == 0)
   4659        out_attr->i = in_attr->i;
   4660       else if (in_attr->i == 0)
   4661        ;
   4662       else if (out_attr->i == 1 && in_attr->i == 2)
   4663        _bfd_error_handler
   4664          (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd, ibfd);
   4665       else if (out_attr->i == 2 && in_attr->i == 1)
   4666        _bfd_error_handler
   4667          (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd, obfd);
   4668       else if (in_attr->i > 2)
   4669        _bfd_error_handler
   4670          (_("Warning: %B uses unknown small structure return convention %d"), ibfd,
   4671           in_attr->i);
   4672       else
   4673        _bfd_error_handler
   4674          (_("Warning: %B uses unknown small structure return convention %d"), obfd,
   4675           out_attr->i);
   4676     }
   4677 
   4678   /* Merge Tag_compatibility attributes and any common GNU ones.  */
   4679   _bfd_elf_merge_object_attributes (ibfd, obfd);
   4680 
   4681   return TRUE;
   4682 }
   4683 
   4684 /* Merge backend specific data from an object file to the output
   4685    object file when linking.  */
   4686 
   4687 static bfd_boolean
   4688 ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
   4689 {
   4690   flagword old_flags;
   4691   flagword new_flags;
   4692   bfd_boolean error;
   4693 
   4694   if (!is_ppc_elf (ibfd) || !is_ppc_elf (obfd))
   4695     return TRUE;
   4696 
   4697   /* Check if we have the same endianness.  */
   4698   if (! _bfd_generic_verify_endian_match (ibfd, obfd))
   4699     return FALSE;
   4700 
   4701   if (!ppc_elf_merge_obj_attributes (ibfd, obfd))
   4702     return FALSE;
   4703 
   4704   new_flags = elf_elfheader (ibfd)->e_flags;
   4705   old_flags = elf_elfheader (obfd)->e_flags;
   4706   if (!elf_flags_init (obfd))
   4707     {
   4708       /* First call, no flags set.  */
   4709       elf_flags_init (obfd) = TRUE;
   4710       elf_elfheader (obfd)->e_flags = new_flags;
   4711     }
   4712 
   4713   /* Compatible flags are ok.  */
   4714   else if (new_flags == old_flags)
   4715     ;
   4716 
   4717   /* Incompatible flags.  */
   4718   else
   4719     {
   4720       /* Warn about -mrelocatable mismatch.  Allow -mrelocatable-lib
   4721 	 to be linked with either.  */
   4722       error = FALSE;
   4723       if ((new_flags & EF_PPC_RELOCATABLE) != 0
   4724 	  && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
   4725 	{
   4726 	  error = TRUE;
   4727 	  (*_bfd_error_handler)
   4728 	    (_("%B: compiled with -mrelocatable and linked with "
   4729 	       "modules compiled normally"), ibfd);
   4730 	}
   4731       else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
   4732 	       && (old_flags & EF_PPC_RELOCATABLE) != 0)
   4733 	{
   4734 	  error = TRUE;
   4735 	  (*_bfd_error_handler)
   4736 	    (_("%B: compiled normally and linked with "
   4737 	       "modules compiled with -mrelocatable"), ibfd);
   4738 	}
   4739 
   4740       /* The output is -mrelocatable-lib iff both the input files are.  */
   4741       if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
   4742 	elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
   4743 
   4744       /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
   4745 	 but each input file is either -mrelocatable or -mrelocatable-lib.  */
   4746       if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
   4747 	  && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
   4748 	  && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
   4749 	elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
   4750 
   4751       /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
   4752 	 any module uses it.  */
   4753       elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
   4754 
   4755       new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
   4756       old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
   4757 
   4758       /* Warn about any other mismatches.  */
   4759       if (new_flags != old_flags)
   4760 	{
   4761 	  error = TRUE;
   4762 	  (*_bfd_error_handler)
   4763 	    (_("%B: uses different e_flags (0x%lx) fields "
   4764 	       "than previous modules (0x%lx)"),
   4765 	     ibfd, (long) new_flags, (long) old_flags);
   4766 	}
   4767 
   4768       if (error)
   4769 	{
   4770 	  bfd_set_error (bfd_error_bad_value);
   4771 	  return FALSE;
   4772 	}
   4773     }
   4774 
   4775   return TRUE;
   4776 }
   4777 
   4778 static void
   4779 ppc_elf_vle_split16 (bfd *output_bfd, bfd_byte *loc,
   4780 		     bfd_vma value,
   4781 		     split16_format_type split16_format)
   4782 
   4783 {
   4784   unsigned int insn, top5;
   4785 
   4786   insn = bfd_get_32 (output_bfd, loc);
   4787   top5 = value & 0xf800;
   4788   top5 = top5 << (split16_format == split16a_type ? 9 : 5);
   4789   insn |= top5;
   4790   insn |= value & 0x7ff;
   4791   bfd_put_32 (output_bfd, insn, loc);
   4792 }
   4793 
   4794 
   4795 /* Choose which PLT scheme to use, and set .plt flags appropriately.
   4797    Returns -1 on error, 0 for old PLT, 1 for new PLT.  */
   4798 int
   4799 ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
   4800 			   struct bfd_link_info *info)
   4801 {
   4802   struct ppc_elf_link_hash_table *htab;
   4803   flagword flags;
   4804 
   4805   htab = ppc_elf_hash_table (info);
   4806 
   4807   if (htab->plt_type == PLT_UNSET)
   4808     {
   4809       struct elf_link_hash_entry *h;
   4810 
   4811       if (htab->params->plt_style == PLT_OLD)
   4812 	htab->plt_type = PLT_OLD;
   4813       else if (info->shared
   4814 	       && htab->elf.dynamic_sections_created
   4815 	       && (h = elf_link_hash_lookup (&htab->elf, "_mcount",
   4816 					     FALSE, FALSE, TRUE)) != NULL
   4817 	       && (h->type == STT_FUNC
   4818 		   || h->needs_plt)
   4819 	       && h->ref_regular
   4820 	       && !(SYMBOL_CALLS_LOCAL (info, h)
   4821 		    || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
   4822 			&& h->root.type == bfd_link_hash_undefweak)))
   4823 	{
   4824 	  /* Profiling of shared libs (and pies) is not supported with
   4825 	     secure plt, because ppc32 does profiling before a
   4826 	     function prologue and a secure plt pic call stubs needs
   4827 	     r30 to be set up.  */
   4828 	  htab->plt_type = PLT_OLD;
   4829 	}
   4830       else
   4831 	{
   4832 	  bfd *ibfd;
   4833 	  enum ppc_elf_plt_type plt_type = htab->params->plt_style;
   4834 
   4835 	  /* Look through the reloc flags left by ppc_elf_check_relocs.
   4836 	     Use the old style bss plt if a file makes plt calls
   4837 	     without using the new relocs, and if ld isn't given
   4838 	     --secure-plt and we never see REL16 relocs.  */
   4839 	  if (plt_type == PLT_UNSET)
   4840 	    plt_type = PLT_OLD;
   4841 	  for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link.next)
   4842 	    if (is_ppc_elf (ibfd))
   4843 	      {
   4844 		if (ppc_elf_tdata (ibfd)->has_rel16)
   4845 		  plt_type = PLT_NEW;
   4846 		else if (ppc_elf_tdata (ibfd)->makes_plt_call)
   4847 		  {
   4848 		    plt_type = PLT_OLD;
   4849 		    htab->old_bfd = ibfd;
   4850 		    break;
   4851 		  }
   4852 	      }
   4853 	  htab->plt_type = plt_type;
   4854 	}
   4855     }
   4856   if (htab->plt_type == PLT_OLD && htab->params->plt_style == PLT_NEW)
   4857     {
   4858       if (htab->old_bfd != NULL)
   4859 	info->callbacks->einfo (_("%P: bss-plt forced due to %B\n"),
   4860 				htab->old_bfd);
   4861       else
   4862 	info->callbacks->einfo (_("%P: bss-plt forced by profiling\n"));
   4863     }
   4864 
   4865   BFD_ASSERT (htab->plt_type != PLT_VXWORKS);
   4866 
   4867   if (htab->plt_type == PLT_NEW)
   4868     {
   4869       flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
   4870 	       | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   4871 
   4872       /* The new PLT is a loaded section.  */
   4873       if (htab->plt != NULL
   4874 	  && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags))
   4875 	return -1;
   4876 
   4877       /* The new GOT is not executable.  */
   4878       if (htab->got != NULL
   4879 	  && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags))
   4880 	return -1;
   4881     }
   4882   else
   4883     {
   4884       /* Stop an unused .glink section from affecting .text alignment.  */
   4885       if (htab->glink != NULL
   4886 	  && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0))
   4887 	return -1;
   4888     }
   4889   return htab->plt_type == PLT_NEW;
   4890 }
   4891 
   4892 /* Return the section that should be marked against GC for a given
   4894    relocation.  */
   4895 
   4896 static asection *
   4897 ppc_elf_gc_mark_hook (asection *sec,
   4898 		      struct bfd_link_info *info,
   4899 		      Elf_Internal_Rela *rel,
   4900 		      struct elf_link_hash_entry *h,
   4901 		      Elf_Internal_Sym *sym)
   4902 {
   4903   if (h != NULL)
   4904     switch (ELF32_R_TYPE (rel->r_info))
   4905       {
   4906       case R_PPC_GNU_VTINHERIT:
   4907       case R_PPC_GNU_VTENTRY:
   4908 	return NULL;
   4909       }
   4910 
   4911   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
   4912 }
   4913 
   4914 /* Update the got, plt and dynamic reloc reference counts for the
   4915    section being removed.  */
   4916 
   4917 static bfd_boolean
   4918 ppc_elf_gc_sweep_hook (bfd *abfd,
   4919 		       struct bfd_link_info *info,
   4920 		       asection *sec,
   4921 		       const Elf_Internal_Rela *relocs)
   4922 {
   4923   struct ppc_elf_link_hash_table *htab;
   4924   Elf_Internal_Shdr *symtab_hdr;
   4925   struct elf_link_hash_entry **sym_hashes;
   4926   bfd_signed_vma *local_got_refcounts;
   4927   const Elf_Internal_Rela *rel, *relend;
   4928   asection *got2;
   4929 
   4930   if (info->relocatable)
   4931     return TRUE;
   4932 
   4933   if ((sec->flags & SEC_ALLOC) == 0)
   4934     return TRUE;
   4935 
   4936   elf_section_data (sec)->local_dynrel = NULL;
   4937 
   4938   htab = ppc_elf_hash_table (info);
   4939   symtab_hdr = &elf_symtab_hdr (abfd);
   4940   sym_hashes = elf_sym_hashes (abfd);
   4941   local_got_refcounts = elf_local_got_refcounts (abfd);
   4942   got2 = bfd_get_section_by_name (abfd, ".got2");
   4943 
   4944   relend = relocs + sec->reloc_count;
   4945   for (rel = relocs; rel < relend; rel++)
   4946     {
   4947       unsigned long r_symndx;
   4948       enum elf_ppc_reloc_type r_type;
   4949       struct elf_link_hash_entry *h = NULL;
   4950 
   4951       r_symndx = ELF32_R_SYM (rel->r_info);
   4952       if (r_symndx >= symtab_hdr->sh_info)
   4953 	{
   4954 	  struct elf_dyn_relocs **pp, *p;
   4955 	  struct ppc_elf_link_hash_entry *eh;
   4956 
   4957 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   4958 	  while (h->root.type == bfd_link_hash_indirect
   4959 		 || h->root.type == bfd_link_hash_warning)
   4960 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   4961 	  eh = (struct ppc_elf_link_hash_entry *) h;
   4962 
   4963 	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
   4964 	    if (p->sec == sec)
   4965 	      {
   4966 		/* Everything must go for SEC.  */
   4967 		*pp = p->next;
   4968 		break;
   4969 	      }
   4970 	}
   4971 
   4972       r_type = ELF32_R_TYPE (rel->r_info);
   4973       if (!htab->is_vxworks
   4974 	  && h == NULL
   4975 	  && local_got_refcounts != NULL
   4976 	  && (!info->shared
   4977 	      || is_branch_reloc (r_type)))
   4978 	{
   4979 	  struct plt_entry **local_plt = (struct plt_entry **)
   4980 	    (local_got_refcounts + symtab_hdr->sh_info);
   4981 	  char *local_got_tls_masks = (char *)
   4982 	    (local_plt + symtab_hdr->sh_info);
   4983 	  if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
   4984 	    {
   4985 	      struct plt_entry **ifunc = local_plt + r_symndx;
   4986 	      bfd_vma addend = 0;
   4987 	      struct plt_entry *ent;
   4988 
   4989 	      if (r_type == R_PPC_PLTREL24 && info->shared)
   4990 		addend = rel->r_addend;
   4991 	      ent = find_plt_ent (ifunc, got2, addend);
   4992 	      if (ent->plt.refcount > 0)
   4993 		ent->plt.refcount -= 1;
   4994 	      continue;
   4995 	    }
   4996 	}
   4997 
   4998       switch (r_type)
   4999 	{
   5000 	case R_PPC_GOT_TLSLD16:
   5001 	case R_PPC_GOT_TLSLD16_LO:
   5002 	case R_PPC_GOT_TLSLD16_HI:
   5003 	case R_PPC_GOT_TLSLD16_HA:
   5004 	case R_PPC_GOT_TLSGD16:
   5005 	case R_PPC_GOT_TLSGD16_LO:
   5006 	case R_PPC_GOT_TLSGD16_HI:
   5007 	case R_PPC_GOT_TLSGD16_HA:
   5008 	case R_PPC_GOT_TPREL16:
   5009 	case R_PPC_GOT_TPREL16_LO:
   5010 	case R_PPC_GOT_TPREL16_HI:
   5011 	case R_PPC_GOT_TPREL16_HA:
   5012 	case R_PPC_GOT_DTPREL16:
   5013 	case R_PPC_GOT_DTPREL16_LO:
   5014 	case R_PPC_GOT_DTPREL16_HI:
   5015 	case R_PPC_GOT_DTPREL16_HA:
   5016 	case R_PPC_GOT16:
   5017 	case R_PPC_GOT16_LO:
   5018 	case R_PPC_GOT16_HI:
   5019 	case R_PPC_GOT16_HA:
   5020 	  if (h != NULL)
   5021 	    {
   5022 	      if (h->got.refcount > 0)
   5023 		h->got.refcount--;
   5024 	      if (!info->shared)
   5025 		{
   5026 		  struct plt_entry *ent;
   5027 
   5028 		  ent = find_plt_ent (&h->plt.plist, NULL, 0);
   5029 		  if (ent != NULL && ent->plt.refcount > 0)
   5030 		    ent->plt.refcount -= 1;
   5031 		}
   5032 	    }
   5033 	  else if (local_got_refcounts != NULL)
   5034 	    {
   5035 	      if (local_got_refcounts[r_symndx] > 0)
   5036 		local_got_refcounts[r_symndx]--;
   5037 	    }
   5038 	  break;
   5039 
   5040 	case R_PPC_REL24:
   5041 	case R_PPC_REL14:
   5042 	case R_PPC_REL14_BRTAKEN:
   5043 	case R_PPC_REL14_BRNTAKEN:
   5044 	case R_PPC_REL32:
   5045 	  if (h == NULL || h == htab->elf.hgot)
   5046 	    break;
   5047 	  /* Fall thru */
   5048 
   5049 	case R_PPC_ADDR32:
   5050 	case R_PPC_ADDR24:
   5051 	case R_PPC_ADDR16:
   5052 	case R_PPC_ADDR16_LO:
   5053 	case R_PPC_ADDR16_HI:
   5054 	case R_PPC_ADDR16_HA:
   5055 	case R_PPC_ADDR14:
   5056 	case R_PPC_ADDR14_BRTAKEN:
   5057 	case R_PPC_ADDR14_BRNTAKEN:
   5058 	case R_PPC_UADDR32:
   5059 	case R_PPC_UADDR16:
   5060 	  if (info->shared)
   5061 	    break;
   5062 
   5063 	case R_PPC_PLT32:
   5064 	case R_PPC_PLTREL24:
   5065 	case R_PPC_PLTREL32:
   5066 	case R_PPC_PLT16_LO:
   5067 	case R_PPC_PLT16_HI:
   5068 	case R_PPC_PLT16_HA:
   5069 	  if (h != NULL)
   5070 	    {
   5071 	      bfd_vma addend = 0;
   5072 	      struct plt_entry *ent;
   5073 
   5074 	      if (r_type == R_PPC_PLTREL24 && info->shared)
   5075 		addend = rel->r_addend;
   5076 	      ent = find_plt_ent (&h->plt.plist, got2, addend);
   5077 	      if (ent != NULL && ent->plt.refcount > 0)
   5078 		ent->plt.refcount -= 1;
   5079 	    }
   5080 	  break;
   5081 
   5082 	default:
   5083 	  break;
   5084 	}
   5085     }
   5086   return TRUE;
   5087 }
   5088 
   5089 /* Set plt output section type, htab->tls_get_addr, and call the
   5091    generic ELF tls_setup function.  */
   5092 
   5093 asection *
   5094 ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
   5095 {
   5096   struct ppc_elf_link_hash_table *htab;
   5097 
   5098   htab = ppc_elf_hash_table (info);
   5099   htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
   5100 					     FALSE, FALSE, TRUE);
   5101   if (!htab->params->no_tls_get_addr_opt)
   5102     {
   5103       struct elf_link_hash_entry *opt, *tga;
   5104       opt = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt",
   5105 				  FALSE, FALSE, TRUE);
   5106       if (opt != NULL
   5107 	  && (opt->root.type == bfd_link_hash_defined
   5108 	      || opt->root.type == bfd_link_hash_defweak))
   5109 	{
   5110 	  /* If glibc supports an optimized __tls_get_addr call stub,
   5111 	     signalled by the presence of __tls_get_addr_opt, and we'll
   5112 	     be calling __tls_get_addr via a plt call stub, then
   5113 	     make __tls_get_addr point to __tls_get_addr_opt.  */
   5114 	  tga = htab->tls_get_addr;
   5115 	  if (htab->elf.dynamic_sections_created
   5116 	      && tga != NULL
   5117 	      && (tga->type == STT_FUNC
   5118 		  || tga->needs_plt)
   5119 	      && !(SYMBOL_CALLS_LOCAL (info, tga)
   5120 		   || (ELF_ST_VISIBILITY (tga->other) != STV_DEFAULT
   5121 		       && tga->root.type == bfd_link_hash_undefweak)))
   5122 	    {
   5123 	      struct plt_entry *ent;
   5124 	      for (ent = tga->plt.plist; ent != NULL; ent = ent->next)
   5125 		if (ent->plt.refcount > 0)
   5126 		  break;
   5127 	      if (ent != NULL)
   5128 		{
   5129 		  tga->root.type = bfd_link_hash_indirect;
   5130 		  tga->root.u.i.link = &opt->root;
   5131 		  ppc_elf_copy_indirect_symbol (info, opt, tga);
   5132 		  if (opt->dynindx != -1)
   5133 		    {
   5134 		      /* Use __tls_get_addr_opt in dynamic relocations.  */
   5135 		      opt->dynindx = -1;
   5136 		      _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
   5137 					      opt->dynstr_index);
   5138 		      if (!bfd_elf_link_record_dynamic_symbol (info, opt))
   5139 			return FALSE;
   5140 		    }
   5141 		  htab->tls_get_addr = opt;
   5142 		}
   5143 	    }
   5144 	}
   5145       else
   5146 	htab->params->no_tls_get_addr_opt = TRUE;
   5147     }
   5148   if (htab->plt_type == PLT_NEW
   5149       && htab->plt != NULL
   5150       && htab->plt->output_section != NULL)
   5151     {
   5152       elf_section_type (htab->plt->output_section) = SHT_PROGBITS;
   5153       elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE;
   5154     }
   5155 
   5156   return _bfd_elf_tls_setup (obfd, info);
   5157 }
   5158 
   5159 /* Return TRUE iff REL is a branch reloc with a global symbol matching
   5160    HASH.  */
   5161 
   5162 static bfd_boolean
   5163 branch_reloc_hash_match (const bfd *ibfd,
   5164 			 const Elf_Internal_Rela *rel,
   5165 			 const struct elf_link_hash_entry *hash)
   5166 {
   5167   Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
   5168   enum elf_ppc_reloc_type r_type = ELF32_R_TYPE (rel->r_info);
   5169   unsigned int r_symndx = ELF32_R_SYM (rel->r_info);
   5170 
   5171   if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type))
   5172     {
   5173       struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
   5174       struct elf_link_hash_entry *h;
   5175 
   5176       h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   5177       while (h->root.type == bfd_link_hash_indirect
   5178 	     || h->root.type == bfd_link_hash_warning)
   5179 	h = (struct elf_link_hash_entry *) h->root.u.i.link;
   5180       if (h == hash)
   5181 	return TRUE;
   5182     }
   5183   return FALSE;
   5184 }
   5185 
   5186 /* Run through all the TLS relocs looking for optimization
   5187    opportunities.  */
   5188 
   5189 bfd_boolean
   5190 ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
   5191 		      struct bfd_link_info *info)
   5192 {
   5193   bfd *ibfd;
   5194   asection *sec;
   5195   struct ppc_elf_link_hash_table *htab;
   5196   int pass;
   5197 
   5198   if (info->relocatable || !info->executable)
   5199     return TRUE;
   5200 
   5201   htab = ppc_elf_hash_table (info);
   5202   if (htab == NULL)
   5203     return FALSE;
   5204 
   5205   /* Make two passes through the relocs.  First time check that tls
   5206      relocs involved in setting up a tls_get_addr call are indeed
   5207      followed by such a call.  If they are not, don't do any tls
   5208      optimization.  On the second pass twiddle tls_mask flags to
   5209      notify relocate_section that optimization can be done, and
   5210      adjust got and plt refcounts.  */
   5211   for (pass = 0; pass < 2; ++pass)
   5212     for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
   5213       {
   5214 	Elf_Internal_Sym *locsyms = NULL;
   5215 	Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
   5216 	asection *got2 = bfd_get_section_by_name (ibfd, ".got2");
   5217 
   5218 	for (sec = ibfd->sections; sec != NULL; sec = sec->next)
   5219 	  if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
   5220 	    {
   5221 	      Elf_Internal_Rela *relstart, *rel, *relend;
   5222 	      int expecting_tls_get_addr = 0;
   5223 
   5224 	      /* Read the relocations.  */
   5225 	      relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
   5226 						    info->keep_memory);
   5227 	      if (relstart == NULL)
   5228 		return FALSE;
   5229 
   5230 	      relend = relstart + sec->reloc_count;
   5231 	      for (rel = relstart; rel < relend; rel++)
   5232 		{
   5233 		  enum elf_ppc_reloc_type r_type;
   5234 		  unsigned long r_symndx;
   5235 		  struct elf_link_hash_entry *h = NULL;
   5236 		  char *tls_mask;
   5237 		  char tls_set, tls_clear;
   5238 		  bfd_boolean is_local;
   5239 		  bfd_signed_vma *got_count;
   5240 
   5241 		  r_symndx = ELF32_R_SYM (rel->r_info);
   5242 		  if (r_symndx >= symtab_hdr->sh_info)
   5243 		    {
   5244 		      struct elf_link_hash_entry **sym_hashes;
   5245 
   5246 		      sym_hashes = elf_sym_hashes (ibfd);
   5247 		      h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   5248 		      while (h->root.type == bfd_link_hash_indirect
   5249 			     || h->root.type == bfd_link_hash_warning)
   5250 			h = (struct elf_link_hash_entry *) h->root.u.i.link;
   5251 		    }
   5252 
   5253 		  is_local = FALSE;
   5254 		  if (h == NULL
   5255 		      || !h->def_dynamic)
   5256 		    is_local = TRUE;
   5257 
   5258 		  r_type = ELF32_R_TYPE (rel->r_info);
   5259 		  /* If this section has old-style __tls_get_addr calls
   5260 		     without marker relocs, then check that each
   5261 		     __tls_get_addr call reloc is preceded by a reloc
   5262 		     that conceivably belongs to the __tls_get_addr arg
   5263 		     setup insn.  If we don't find matching arg setup
   5264 		     relocs, don't do any tls optimization.  */
   5265 		  if (pass == 0
   5266 		      && sec->has_tls_get_addr_call
   5267 		      && h != NULL
   5268 		      && h == htab->tls_get_addr
   5269 		      && !expecting_tls_get_addr
   5270 		      && is_branch_reloc (r_type))
   5271 		    {
   5272 		      info->callbacks->minfo ("%H __tls_get_addr lost arg, "
   5273 					      "TLS optimization disabled\n",
   5274 					      ibfd, sec, rel->r_offset);
   5275 		      if (elf_section_data (sec)->relocs != relstart)
   5276 			free (relstart);
   5277 		      return TRUE;
   5278 		    }
   5279 
   5280 		  expecting_tls_get_addr = 0;
   5281 		  switch (r_type)
   5282 		    {
   5283 		    case R_PPC_GOT_TLSLD16:
   5284 		    case R_PPC_GOT_TLSLD16_LO:
   5285 		      expecting_tls_get_addr = 1;
   5286 		      /* Fall thru */
   5287 
   5288 		    case R_PPC_GOT_TLSLD16_HI:
   5289 		    case R_PPC_GOT_TLSLD16_HA:
   5290 		      /* These relocs should never be against a symbol
   5291 			 defined in a shared lib.  Leave them alone if
   5292 			 that turns out to be the case.  */
   5293 		      if (!is_local)
   5294 			continue;
   5295 
   5296 		      /* LD -> LE */
   5297 		      tls_set = 0;
   5298 		      tls_clear = TLS_LD;
   5299 		      break;
   5300 
   5301 		    case R_PPC_GOT_TLSGD16:
   5302 		    case R_PPC_GOT_TLSGD16_LO:
   5303 		      expecting_tls_get_addr = 1;
   5304 		      /* Fall thru */
   5305 
   5306 		    case R_PPC_GOT_TLSGD16_HI:
   5307 		    case R_PPC_GOT_TLSGD16_HA:
   5308 		      if (is_local)
   5309 			/* GD -> LE */
   5310 			tls_set = 0;
   5311 		      else
   5312 			/* GD -> IE */
   5313 			tls_set = TLS_TLS | TLS_TPRELGD;
   5314 		      tls_clear = TLS_GD;
   5315 		      break;
   5316 
   5317 		    case R_PPC_GOT_TPREL16:
   5318 		    case R_PPC_GOT_TPREL16_LO:
   5319 		    case R_PPC_GOT_TPREL16_HI:
   5320 		    case R_PPC_GOT_TPREL16_HA:
   5321 		      if (is_local)
   5322 			{
   5323 			  /* IE -> LE */
   5324 			  tls_set = 0;
   5325 			  tls_clear = TLS_TPREL;
   5326 			  break;
   5327 			}
   5328 		      else
   5329 			continue;
   5330 
   5331 		    case R_PPC_TLSGD:
   5332 		    case R_PPC_TLSLD:
   5333 		      expecting_tls_get_addr = 2;
   5334 		      tls_set = 0;
   5335 		      tls_clear = 0;
   5336 		      break;
   5337 
   5338 		    default:
   5339 		      continue;
   5340 		    }
   5341 
   5342 		  if (pass == 0)
   5343 		    {
   5344 		      if (!expecting_tls_get_addr
   5345 			  || (expecting_tls_get_addr == 1
   5346 			      && !sec->has_tls_get_addr_call))
   5347 			continue;
   5348 
   5349 		      if (rel + 1 < relend
   5350 			  && branch_reloc_hash_match (ibfd, rel + 1,
   5351 						      htab->tls_get_addr))
   5352 			continue;
   5353 
   5354 		      /* Uh oh, we didn't find the expected call.  We
   5355 			 could just mark this symbol to exclude it
   5356 			 from tls optimization but it's safer to skip
   5357 			 the entire optimization.  */
   5358 		      info->callbacks->minfo (_("%H arg lost __tls_get_addr, "
   5359 						"TLS optimization disabled\n"),
   5360 					      ibfd, sec, rel->r_offset);
   5361 		      if (elf_section_data (sec)->relocs != relstart)
   5362 			free (relstart);
   5363 		      return TRUE;
   5364 		    }
   5365 
   5366 		  if (expecting_tls_get_addr)
   5367 		    {
   5368 		      struct plt_entry *ent;
   5369 		      bfd_vma addend = 0;
   5370 
   5371 		      if (info->shared
   5372 			  && ELF32_R_TYPE (rel[1].r_info) == R_PPC_PLTREL24)
   5373 			addend = rel[1].r_addend;
   5374 		      ent = find_plt_ent (&htab->tls_get_addr->plt.plist,
   5375 					  got2, addend);
   5376 		      if (ent != NULL && ent->plt.refcount > 0)
   5377 			ent->plt.refcount -= 1;
   5378 
   5379 		      if (expecting_tls_get_addr == 2)
   5380 			continue;
   5381 		    }
   5382 
   5383 		  if (h != NULL)
   5384 		    {
   5385 		      tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
   5386 		      got_count = &h->got.refcount;
   5387 		    }
   5388 		  else
   5389 		    {
   5390 		      bfd_signed_vma *lgot_refs;
   5391 		      struct plt_entry **local_plt;
   5392 		      char *lgot_masks;
   5393 
   5394 		      if (locsyms == NULL)
   5395 			{
   5396 			  locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
   5397 			  if (locsyms == NULL)
   5398 			    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
   5399 							    symtab_hdr->sh_info,
   5400 							    0, NULL, NULL, NULL);
   5401 			  if (locsyms == NULL)
   5402 			    {
   5403 			      if (elf_section_data (sec)->relocs != relstart)
   5404 				free (relstart);
   5405 			      return FALSE;
   5406 			    }
   5407 			}
   5408 		      lgot_refs = elf_local_got_refcounts (ibfd);
   5409 		      if (lgot_refs == NULL)
   5410 			abort ();
   5411 		      local_plt = (struct plt_entry **)
   5412 			(lgot_refs + symtab_hdr->sh_info);
   5413 		      lgot_masks = (char *) (local_plt + symtab_hdr->sh_info);
   5414 		      tls_mask = &lgot_masks[r_symndx];
   5415 		      got_count = &lgot_refs[r_symndx];
   5416 		    }
   5417 
   5418 		  if (tls_set == 0)
   5419 		    {
   5420 		      /* We managed to get rid of a got entry.  */
   5421 		      if (*got_count > 0)
   5422 			*got_count -= 1;
   5423 		    }
   5424 
   5425 		  *tls_mask |= tls_set;
   5426 		  *tls_mask &= ~tls_clear;
   5427 		}
   5428 
   5429 	      if (elf_section_data (sec)->relocs != relstart)
   5430 		free (relstart);
   5431 	    }
   5432 
   5433 	if (locsyms != NULL
   5434 	    && (symtab_hdr->contents != (unsigned char *) locsyms))
   5435 	  {
   5436 	    if (!info->keep_memory)
   5437 	      free (locsyms);
   5438 	    else
   5439 	      symtab_hdr->contents = (unsigned char *) locsyms;
   5440 	  }
   5441       }
   5442   return TRUE;
   5443 }
   5444 
   5445 /* Return true if we have dynamic relocs that apply to read-only sections.  */
   5447 
   5448 static bfd_boolean
   5449 readonly_dynrelocs (struct elf_link_hash_entry *h)
   5450 {
   5451   struct elf_dyn_relocs *p;
   5452 
   5453   for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
   5454     {
   5455       asection *s = p->sec->output_section;
   5456 
   5457       if (s != NULL
   5458 	  && ((s->flags & (SEC_READONLY | SEC_ALLOC))
   5459 	      == (SEC_READONLY | SEC_ALLOC)))
   5460 	return TRUE;
   5461     }
   5462   return FALSE;
   5463 }
   5464 
   5465 /* Adjust a symbol defined by a dynamic object and referenced by a
   5466    regular object.  The current definition is in some section of the
   5467    dynamic object, but we're not including those sections.  We have to
   5468    change the definition to something the rest of the link can
   5469    understand.  */
   5470 
   5471 static bfd_boolean
   5472 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   5473 			       struct elf_link_hash_entry *h)
   5474 {
   5475   struct ppc_elf_link_hash_table *htab;
   5476   asection *s;
   5477 
   5478 #ifdef DEBUG
   5479   fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
   5480 	   h->root.root.string);
   5481 #endif
   5482 
   5483   /* Make sure we know what is going on here.  */
   5484   htab = ppc_elf_hash_table (info);
   5485   BFD_ASSERT (htab->elf.dynobj != NULL
   5486 	      && (h->needs_plt
   5487 		  || h->type == STT_GNU_IFUNC
   5488 		  || h->u.weakdef != NULL
   5489 		  || (h->def_dynamic
   5490 		      && h->ref_regular
   5491 		      && !h->def_regular)));
   5492 
   5493   /* Deal with function syms.  */
   5494   if (h->type == STT_FUNC
   5495       || h->type == STT_GNU_IFUNC
   5496       || h->needs_plt)
   5497     {
   5498       /* Clear procedure linkage table information for any symbol that
   5499 	 won't need a .plt entry.  */
   5500       struct plt_entry *ent;
   5501       for (ent = h->plt.plist; ent != NULL; ent = ent->next)
   5502 	if (ent->plt.refcount > 0)
   5503 	  break;
   5504       if (ent == NULL
   5505 	  || (h->type != STT_GNU_IFUNC
   5506 	      && (SYMBOL_CALLS_LOCAL (info, h)
   5507 		  || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
   5508 		      && h->root.type == bfd_link_hash_undefweak))))
   5509 	{
   5510 	  /* A PLT entry is not required/allowed when:
   5511 
   5512 	     1. We are not using ld.so; because then the PLT entry
   5513 	     can't be set up, so we can't use one.  In this case,
   5514 	     ppc_elf_adjust_dynamic_symbol won't even be called.
   5515 
   5516 	     2. GC has rendered the entry unused.
   5517 
   5518 	     3. We know for certain that a call to this symbol
   5519 	     will go to this object, or will remain undefined.  */
   5520 	  h->plt.plist = NULL;
   5521 	  h->needs_plt = 0;
   5522 	  h->pointer_equality_needed = 0;
   5523 	}
   5524       else
   5525 	{
   5526 	  /* Taking a function's address in a read/write section
   5527 	     doesn't require us to define the function symbol in the
   5528 	     executable on a plt call stub.  A dynamic reloc can
   5529 	     be used instead.  */
   5530 	  if (h->pointer_equality_needed
   5531 	      && h->type != STT_GNU_IFUNC
   5532 	      && !htab->is_vxworks
   5533 	      && !ppc_elf_hash_entry (h)->has_sda_refs
   5534 	      && !readonly_dynrelocs (h))
   5535 	    {
   5536 	      h->pointer_equality_needed = 0;
   5537 	      h->non_got_ref = 0;
   5538 	    }
   5539 
   5540 	  /* After adjust_dynamic_symbol, non_got_ref set in the
   5541 	     non-shared case means that we have allocated space in
   5542 	     .dynbss for the symbol and thus dyn_relocs for this
   5543 	     symbol should be discarded.
   5544 	     If we get here we know we are making a PLT entry for this
   5545 	     symbol, and in an executable we'd normally resolve
   5546 	     relocations against this symbol to the PLT entry.  Allow
   5547 	     dynamic relocs if the reference is weak, and the dynamic
   5548 	     relocs will not cause text relocation.  */
   5549 	  else if (!h->ref_regular_nonweak
   5550 		   && h->non_got_ref
   5551 		   && h->type != STT_GNU_IFUNC
   5552 		   && !htab->is_vxworks
   5553 		   && !ppc_elf_hash_entry (h)->has_sda_refs
   5554 		   && !readonly_dynrelocs (h))
   5555 	    h->non_got_ref = 0;
   5556 	}
   5557       return TRUE;
   5558     }
   5559   else
   5560     h->plt.plist = NULL;
   5561 
   5562   /* If this is a weak symbol, and there is a real definition, the
   5563      processor independent code will have arranged for us to see the
   5564      real definition first, and we can just use the same value.  */
   5565   if (h->u.weakdef != NULL)
   5566     {
   5567       BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
   5568 		  || h->u.weakdef->root.type == bfd_link_hash_defweak);
   5569       h->root.u.def.section = h->u.weakdef->root.u.def.section;
   5570       h->root.u.def.value = h->u.weakdef->root.u.def.value;
   5571       if (ELIMINATE_COPY_RELOCS)
   5572 	h->non_got_ref = h->u.weakdef->non_got_ref;
   5573       return TRUE;
   5574     }
   5575 
   5576   /* This is a reference to a symbol defined by a dynamic object which
   5577      is not a function.  */
   5578 
   5579   /* If we are creating a shared library, we must presume that the
   5580      only references to the symbol are via the global offset table.
   5581      For such cases we need not do anything here; the relocations will
   5582      be handled correctly by relocate_section.  */
   5583   if (info->shared)
   5584     return TRUE;
   5585 
   5586   /* If there are no references to this symbol that do not use the
   5587      GOT, we don't need to generate a copy reloc.  */
   5588   if (!h->non_got_ref)
   5589     return TRUE;
   5590 
   5591    /* If we didn't find any dynamic relocs in read-only sections, then
   5592       we'll be keeping the dynamic relocs and avoiding the copy reloc.
   5593       We can't do this if there are any small data relocations.  This
   5594       doesn't work on VxWorks, where we can not have dynamic
   5595       relocations (other than copy and jump slot relocations) in an
   5596       executable.  */
   5597   if (ELIMINATE_COPY_RELOCS
   5598       && !ppc_elf_hash_entry (h)->has_sda_refs
   5599       && !htab->is_vxworks
   5600       && !h->def_regular
   5601       && !readonly_dynrelocs (h))
   5602     {
   5603       h->non_got_ref = 0;
   5604       return TRUE;
   5605     }
   5606 
   5607   /* We must allocate the symbol in our .dynbss section, which will
   5608      become part of the .bss section of the executable.  There will be
   5609      an entry for this symbol in the .dynsym section.  The dynamic
   5610      object will contain position independent code, so all references
   5611      from the dynamic object to this symbol will go through the global
   5612      offset table.  The dynamic linker will use the .dynsym entry to
   5613      determine the address it must put in the global offset table, so
   5614      both the dynamic object and the regular object will refer to the
   5615      same memory location for the variable.
   5616 
   5617      Of course, if the symbol is referenced using SDAREL relocs, we
   5618      must instead allocate it in .sbss.  */
   5619 
   5620   if (ppc_elf_hash_entry (h)->has_sda_refs)
   5621     s = htab->dynsbss;
   5622   else
   5623     s = htab->dynbss;
   5624   BFD_ASSERT (s != NULL);
   5625 
   5626   /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
   5627      copy the initial value out of the dynamic object and into the
   5628      runtime process image.  We need to remember the offset into the
   5629      .rela.bss section we are going to use.  */
   5630   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
   5631     {
   5632       asection *srel;
   5633 
   5634       if (ppc_elf_hash_entry (h)->has_sda_refs)
   5635 	srel = htab->relsbss;
   5636       else
   5637 	srel = htab->relbss;
   5638       BFD_ASSERT (srel != NULL);
   5639       srel->size += sizeof (Elf32_External_Rela);
   5640       h->needs_copy = 1;
   5641     }
   5642 
   5643   return _bfd_elf_adjust_dynamic_copy (h, s);
   5644 }
   5645 
   5646 /* Generate a symbol to mark plt call stubs.  For non-PIC code the sym is
   5648    xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0,
   5649    specifying the addend on the plt relocation.  For -fpic code, the sym
   5650    is xxxxxxxx.plt_pic32.<callee>, and for -fPIC
   5651    xxxxxxxx.got2.plt_pic32.<callee>.  */
   5652 
   5653 static bfd_boolean
   5654 add_stub_sym (struct plt_entry *ent,
   5655 	      struct elf_link_hash_entry *h,
   5656 	      struct bfd_link_info *info)
   5657 {
   5658   struct elf_link_hash_entry *sh;
   5659   size_t len1, len2, len3;
   5660   char *name;
   5661   const char *stub;
   5662   struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
   5663 
   5664   if (info->shared)
   5665     stub = ".plt_pic32.";
   5666   else
   5667     stub = ".plt_call32.";
   5668 
   5669   len1 = strlen (h->root.root.string);
   5670   len2 = strlen (stub);
   5671   len3 = 0;
   5672   if (ent->sec)
   5673     len3 = strlen (ent->sec->name);
   5674   name = bfd_malloc (len1 + len2 + len3 + 9);
   5675   if (name == NULL)
   5676     return FALSE;
   5677   sprintf (name, "%08x", (unsigned) ent->addend & 0xffffffff);
   5678   if (ent->sec)
   5679     memcpy (name + 8, ent->sec->name, len3);
   5680   memcpy (name + 8 + len3, stub, len2);
   5681   memcpy (name + 8 + len3 + len2, h->root.root.string, len1 + 1);
   5682   sh = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
   5683   if (sh == NULL)
   5684     return FALSE;
   5685   if (sh->root.type == bfd_link_hash_new)
   5686     {
   5687       sh->root.type = bfd_link_hash_defined;
   5688       sh->root.u.def.section = htab->glink;
   5689       sh->root.u.def.value = ent->glink_offset;
   5690       sh->ref_regular = 1;
   5691       sh->def_regular = 1;
   5692       sh->ref_regular_nonweak = 1;
   5693       sh->forced_local = 1;
   5694       sh->non_elf = 0;
   5695     }
   5696   return TRUE;
   5697 }
   5698 
   5699 /* Allocate NEED contiguous space in .got, and return the offset.
   5700    Handles allocation of the got header when crossing 32k.  */
   5701 
   5702 static bfd_vma
   5703 allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
   5704 {
   5705   bfd_vma where;
   5706   unsigned int max_before_header;
   5707 
   5708   if (htab->plt_type == PLT_VXWORKS)
   5709     {
   5710       where = htab->got->size;
   5711       htab->got->size += need;
   5712     }
   5713   else
   5714     {
   5715       max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764;
   5716       if (need <= htab->got_gap)
   5717 	{
   5718 	  where = max_before_header - htab->got_gap;
   5719 	  htab->got_gap -= need;
   5720 	}
   5721       else
   5722 	{
   5723 	  if (htab->got->size + need > max_before_header
   5724 	      && htab->got->size <= max_before_header)
   5725 	    {
   5726 	      htab->got_gap = max_before_header - htab->got->size;
   5727 	      htab->got->size = max_before_header + htab->got_header_size;
   5728 	    }
   5729 	  where = htab->got->size;
   5730 	  htab->got->size += need;
   5731 	}
   5732     }
   5733   return where;
   5734 }
   5735 
   5736 /* Allocate space in associated reloc sections for dynamic relocs.  */
   5737 
   5738 static bfd_boolean
   5739 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   5740 {
   5741   struct bfd_link_info *info = inf;
   5742   struct ppc_elf_link_hash_entry *eh;
   5743   struct ppc_elf_link_hash_table *htab;
   5744   struct elf_dyn_relocs *p;
   5745 
   5746   if (h->root.type == bfd_link_hash_indirect)
   5747     return TRUE;
   5748 
   5749   htab = ppc_elf_hash_table (info);
   5750   if (htab->elf.dynamic_sections_created
   5751       || h->type == STT_GNU_IFUNC)
   5752     {
   5753       struct plt_entry *ent;
   5754       bfd_boolean doneone = FALSE;
   5755       bfd_vma plt_offset = 0, glink_offset = 0;
   5756       bfd_boolean dyn;
   5757 
   5758       for (ent = h->plt.plist; ent != NULL; ent = ent->next)
   5759 	if (ent->plt.refcount > 0)
   5760 	  {
   5761 	    /* Make sure this symbol is output as a dynamic symbol.  */
   5762 	    if (h->dynindx == -1
   5763 		&& !h->forced_local
   5764 		&& !h->def_regular
   5765 		&& htab->elf.dynamic_sections_created)
   5766 	      {
   5767 		if (! bfd_elf_link_record_dynamic_symbol (info, h))
   5768 		  return FALSE;
   5769 	      }
   5770 
   5771 	    dyn = htab->elf.dynamic_sections_created;
   5772 	    if (info->shared
   5773 		|| h->type == STT_GNU_IFUNC
   5774 		|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
   5775 	      {
   5776 		asection *s = htab->plt;
   5777 		if (!dyn || h->dynindx == -1)
   5778 		  s = htab->iplt;
   5779 
   5780 		if (htab->plt_type == PLT_NEW || !dyn || h->dynindx == -1)
   5781 		  {
   5782 		    if (!doneone)
   5783 		      {
   5784 			plt_offset = s->size;
   5785 			s->size += 4;
   5786 		      }
   5787 		    ent->plt.offset = plt_offset;
   5788 
   5789 		    s = htab->glink;
   5790 		    if (!doneone || info->shared)
   5791 		      {
   5792 			glink_offset = s->size;
   5793 			s->size += GLINK_ENTRY_SIZE;
   5794 			if (h == htab->tls_get_addr
   5795 			    && !htab->params->no_tls_get_addr_opt)
   5796 			  s->size += TLS_GET_ADDR_GLINK_SIZE - GLINK_ENTRY_SIZE;
   5797 		      }
   5798 		    if (!doneone
   5799 			&& !info->shared
   5800 			&& h->def_dynamic
   5801 			&& !h->def_regular)
   5802 		      {
   5803 			h->root.u.def.section = s;
   5804 			h->root.u.def.value = glink_offset;
   5805 		      }
   5806 		    ent->glink_offset = glink_offset;
   5807 
   5808 		    if (htab->params->emit_stub_syms
   5809 			&& !add_stub_sym (ent, h, info))
   5810 		      return FALSE;
   5811 		  }
   5812 		else
   5813 		  {
   5814 		    if (!doneone)
   5815 		      {
   5816 			/* If this is the first .plt entry, make room
   5817 			   for the special first entry.  */
   5818 			if (s->size == 0)
   5819 			  s->size += htab->plt_initial_entry_size;
   5820 
   5821 			/* The PowerPC PLT is actually composed of two
   5822 			   parts, the first part is 2 words (for a load
   5823 			   and a jump), and then there is a remaining
   5824 			   word available at the end.  */
   5825 			plt_offset = (htab->plt_initial_entry_size
   5826 				      + (htab->plt_slot_size
   5827 					 * ((s->size
   5828 					     - htab->plt_initial_entry_size)
   5829 					    / htab->plt_entry_size)));
   5830 
   5831 			/* If this symbol is not defined in a regular
   5832 			   file, and we are not generating a shared
   5833 			   library, then set the symbol to this location
   5834 			   in the .plt.  This is to avoid text
   5835 			   relocations, and is required to make
   5836 			   function pointers compare as equal between
   5837 			   the normal executable and the shared library.  */
   5838 			if (! info->shared
   5839 			    && h->def_dynamic
   5840 			    && !h->def_regular)
   5841 			  {
   5842 			    h->root.u.def.section = s;
   5843 			    h->root.u.def.value = plt_offset;
   5844 			  }
   5845 
   5846 			/* Make room for this entry.  */
   5847 			s->size += htab->plt_entry_size;
   5848 			/* After the 8192nd entry, room for two entries
   5849 			   is allocated.  */
   5850 			if (htab->plt_type == PLT_OLD
   5851 			    && (s->size - htab->plt_initial_entry_size)
   5852 				/ htab->plt_entry_size
   5853 			       > PLT_NUM_SINGLE_ENTRIES)
   5854 			  s->size += htab->plt_entry_size;
   5855 		      }
   5856 		    ent->plt.offset = plt_offset;
   5857 		  }
   5858 
   5859 		/* We also need to make an entry in the .rela.plt section.  */
   5860 		if (!doneone)
   5861 		  {
   5862 		    if (!htab->elf.dynamic_sections_created
   5863 			|| h->dynindx == -1)
   5864 		      htab->reliplt->size += sizeof (Elf32_External_Rela);
   5865 		    else
   5866 		      {
   5867 			htab->relplt->size += sizeof (Elf32_External_Rela);
   5868 
   5869 			if (htab->plt_type == PLT_VXWORKS)
   5870 			  {
   5871 			    /* Allocate space for the unloaded relocations.  */
   5872 			    if (!info->shared
   5873 				&& htab->elf.dynamic_sections_created)
   5874 			      {
   5875 				if (ent->plt.offset
   5876 				    == (bfd_vma) htab->plt_initial_entry_size)
   5877 				  {
   5878 				    htab->srelplt2->size
   5879 				      += (sizeof (Elf32_External_Rela)
   5880 					  * VXWORKS_PLTRESOLVE_RELOCS);
   5881 				  }
   5882 
   5883 				htab->srelplt2->size
   5884 				  += (sizeof (Elf32_External_Rela)
   5885 				      * VXWORKS_PLT_NON_JMP_SLOT_RELOCS);
   5886 			      }
   5887 
   5888 			    /* Every PLT entry has an associated GOT entry in
   5889 			       .got.plt.  */
   5890 			    htab->sgotplt->size += 4;
   5891 			  }
   5892 		      }
   5893 		    doneone = TRUE;
   5894 		  }
   5895 	      }
   5896 	    else
   5897 	      ent->plt.offset = (bfd_vma) -1;
   5898 	  }
   5899 	else
   5900 	  ent->plt.offset = (bfd_vma) -1;
   5901 
   5902       if (!doneone)
   5903 	{
   5904 	  h->plt.plist = NULL;
   5905 	  h->needs_plt = 0;
   5906 	}
   5907     }
   5908   else
   5909     {
   5910       h->plt.plist = NULL;
   5911       h->needs_plt = 0;
   5912     }
   5913 
   5914   eh = (struct ppc_elf_link_hash_entry *) h;
   5915   if (eh->elf.got.refcount > 0)
   5916     {
   5917       bfd_boolean dyn;
   5918       unsigned int need;
   5919 
   5920       /* Make sure this symbol is output as a dynamic symbol.  */
   5921       if (eh->elf.dynindx == -1
   5922 	  && !eh->elf.forced_local
   5923 	  && eh->elf.type != STT_GNU_IFUNC
   5924 	  && htab->elf.dynamic_sections_created)
   5925 	{
   5926 	  if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
   5927 	    return FALSE;
   5928 	}
   5929 
   5930       need = 0;
   5931       if ((eh->tls_mask & TLS_TLS) != 0)
   5932 	{
   5933 	  if ((eh->tls_mask & TLS_LD) != 0)
   5934 	    {
   5935 	      if (!eh->elf.def_dynamic)
   5936 		/* We'll just use htab->tlsld_got.offset.  This should
   5937 		   always be the case.  It's a little odd if we have
   5938 		   a local dynamic reloc against a non-local symbol.  */
   5939 		htab->tlsld_got.refcount += 1;
   5940 	      else
   5941 		need += 8;
   5942 	    }
   5943 	  if ((eh->tls_mask & TLS_GD) != 0)
   5944 	    need += 8;
   5945 	  if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
   5946 	    need += 4;
   5947 	  if ((eh->tls_mask & TLS_DTPREL) != 0)
   5948 	    need += 4;
   5949 	}
   5950       else
   5951 	need += 4;
   5952       if (need == 0)
   5953 	eh->elf.got.offset = (bfd_vma) -1;
   5954       else
   5955 	{
   5956 	  eh->elf.got.offset = allocate_got (htab, need);
   5957 	  dyn = htab->elf.dynamic_sections_created;
   5958 	  if ((info->shared
   5959 	       || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
   5960 	      && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
   5961 		  || eh->elf.root.type != bfd_link_hash_undefweak))
   5962 	    {
   5963 	      asection *rsec = htab->relgot;
   5964 
   5965 	      if (eh->elf.type == STT_GNU_IFUNC)
   5966 		rsec = htab->reliplt;
   5967 	      /* All the entries we allocated need relocs.
   5968 		 Except LD only needs one.  */
   5969 	      if ((eh->tls_mask & TLS_LD) != 0
   5970 		  && eh->elf.def_dynamic)
   5971 		need -= 4;
   5972 	      rsec->size += need * (sizeof (Elf32_External_Rela) / 4);
   5973 	    }
   5974 	}
   5975     }
   5976   else
   5977     eh->elf.got.offset = (bfd_vma) -1;
   5978 
   5979   if (eh->dyn_relocs == NULL
   5980       || !htab->elf.dynamic_sections_created)
   5981     return TRUE;
   5982 
   5983   /* In the shared -Bsymbolic case, discard space allocated for
   5984      dynamic pc-relative relocs against symbols which turn out to be
   5985      defined in regular objects.  For the normal shared case, discard
   5986      space for relocs that have become local due to symbol visibility
   5987      changes.  */
   5988 
   5989   if (info->shared)
   5990     {
   5991       /* Relocs that use pc_count are those that appear on a call insn,
   5992 	 or certain REL relocs (see must_be_dyn_reloc) that can be
   5993 	 generated via assembly.  We want calls to protected symbols to
   5994 	 resolve directly to the function rather than going via the plt.
   5995 	 If people want function pointer comparisons to work as expected
   5996 	 then they should avoid writing weird assembly.  */
   5997       if (SYMBOL_CALLS_LOCAL (info, h))
   5998 	{
   5999 	  struct elf_dyn_relocs **pp;
   6000 
   6001 	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
   6002 	    {
   6003 	      p->count -= p->pc_count;
   6004 	      p->pc_count = 0;
   6005 	      if (p->count == 0)
   6006 		*pp = p->next;
   6007 	      else
   6008 		pp = &p->next;
   6009 	    }
   6010 	}
   6011 
   6012       if (htab->is_vxworks)
   6013 	{
   6014 	  struct elf_dyn_relocs **pp;
   6015 
   6016 	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
   6017 	    {
   6018 	      if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
   6019 		*pp = p->next;
   6020 	      else
   6021 		pp = &p->next;
   6022 	    }
   6023 	}
   6024 
   6025       /* Discard relocs on undefined symbols that must be local.  */
   6026       if (eh->dyn_relocs != NULL
   6027 	  && h->root.type == bfd_link_hash_undefined
   6028 	  && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
   6029 	      || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
   6030 	eh->dyn_relocs = NULL;
   6031 
   6032       /* Also discard relocs on undefined weak syms with non-default
   6033 	 visibility.  */
   6034       if (eh->dyn_relocs != NULL
   6035 	  && h->root.type == bfd_link_hash_undefweak)
   6036 	{
   6037 	  if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
   6038 	    eh->dyn_relocs = NULL;
   6039 
   6040 	  /* Make sure undefined weak symbols are output as a dynamic
   6041 	     symbol in PIEs.  */
   6042 	  else if (h->dynindx == -1
   6043 		   && !h->forced_local
   6044 		   && !h->def_regular)
   6045 	    {
   6046 	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
   6047 		return FALSE;
   6048 	    }
   6049 	}
   6050     }
   6051   else if (ELIMINATE_COPY_RELOCS)
   6052     {
   6053       /* For the non-shared case, discard space for relocs against
   6054 	 symbols which turn out to need copy relocs or are not
   6055 	 dynamic.  */
   6056 
   6057       if (!h->non_got_ref
   6058 	  && !h->def_regular)
   6059 	{
   6060 	  /* Make sure this symbol is output as a dynamic symbol.
   6061 	     Undefined weak syms won't yet be marked as dynamic.  */
   6062 	  if (h->dynindx == -1
   6063 	      && !h->forced_local)
   6064 	    {
   6065 	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
   6066 		return FALSE;
   6067 	    }
   6068 
   6069 	  /* If that succeeded, we know we'll be keeping all the
   6070 	     relocs.  */
   6071 	  if (h->dynindx != -1)
   6072 	    goto keep;
   6073 	}
   6074 
   6075       eh->dyn_relocs = NULL;
   6076 
   6077     keep: ;
   6078     }
   6079 
   6080   /* Finally, allocate space.  */
   6081   for (p = eh->dyn_relocs; p != NULL; p = p->next)
   6082     {
   6083       asection *sreloc = elf_section_data (p->sec)->sreloc;
   6084       if (eh->elf.type == STT_GNU_IFUNC)
   6085 	sreloc = htab->reliplt;
   6086       sreloc->size += p->count * sizeof (Elf32_External_Rela);
   6087     }
   6088 
   6089   return TRUE;
   6090 }
   6091 
   6092 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
   6093    read-only sections.  */
   6094 
   6095 static bfd_boolean
   6096 maybe_set_textrel (struct elf_link_hash_entry *h, void *info)
   6097 {
   6098   if (h->root.type == bfd_link_hash_indirect)
   6099     return TRUE;
   6100 
   6101   if (readonly_dynrelocs (h))
   6102     {
   6103       ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
   6104 
   6105       /* Not an error, just cut short the traversal.  */
   6106       return FALSE;
   6107     }
   6108   return TRUE;
   6109 }
   6110 
   6111 static const unsigned char glink_eh_frame_cie[] =
   6112 {
   6113   0, 0, 0, 16,				/* length.  */
   6114   0, 0, 0, 0,				/* id.  */
   6115   1,					/* CIE version.  */
   6116   'z', 'R', 0,				/* Augmentation string.  */
   6117   4,					/* Code alignment.  */
   6118   0x7c,					/* Data alignment.  */
   6119   65,					/* RA reg.  */
   6120   1,					/* Augmentation size.  */
   6121   DW_EH_PE_pcrel | DW_EH_PE_sdata4,	/* FDE encoding.  */
   6122   DW_CFA_def_cfa, 1, 0			/* def_cfa: r1 offset 0.  */
   6123 };
   6124 
   6125 /* Set the sizes of the dynamic sections.  */
   6126 
   6127 static bfd_boolean
   6128 ppc_elf_size_dynamic_sections (bfd *output_bfd,
   6129 			       struct bfd_link_info *info)
   6130 {
   6131   struct ppc_elf_link_hash_table *htab;
   6132   asection *s;
   6133   bfd_boolean relocs;
   6134   bfd *ibfd;
   6135 
   6136 #ifdef DEBUG
   6137   fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
   6138 #endif
   6139 
   6140   htab = ppc_elf_hash_table (info);
   6141   BFD_ASSERT (htab->elf.dynobj != NULL);
   6142 
   6143   if (elf_hash_table (info)->dynamic_sections_created)
   6144     {
   6145       /* Set the contents of the .interp section to the interpreter.  */
   6146       if (info->executable)
   6147 	{
   6148 	  s = bfd_get_linker_section (htab->elf.dynobj, ".interp");
   6149 	  BFD_ASSERT (s != NULL);
   6150 	  s->size = sizeof ELF_DYNAMIC_INTERPRETER;
   6151 	  s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
   6152 	}
   6153     }
   6154 
   6155   if (htab->plt_type == PLT_OLD)
   6156     htab->got_header_size = 16;
   6157   else if (htab->plt_type == PLT_NEW)
   6158     htab->got_header_size = 12;
   6159 
   6160   /* Set up .got offsets for local syms, and space for local dynamic
   6161      relocs.  */
   6162   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
   6163     {
   6164       bfd_signed_vma *local_got;
   6165       bfd_signed_vma *end_local_got;
   6166       struct plt_entry **local_plt;
   6167       struct plt_entry **end_local_plt;
   6168       char *lgot_masks;
   6169       bfd_size_type locsymcount;
   6170       Elf_Internal_Shdr *symtab_hdr;
   6171 
   6172       if (!is_ppc_elf (ibfd))
   6173 	continue;
   6174 
   6175       for (s = ibfd->sections; s != NULL; s = s->next)
   6176 	{
   6177 	  struct ppc_dyn_relocs *p;
   6178 
   6179 	  for (p = ((struct ppc_dyn_relocs *)
   6180 		    elf_section_data (s)->local_dynrel);
   6181 	       p != NULL;
   6182 	       p = p->next)
   6183 	    {
   6184 	      if (!bfd_is_abs_section (p->sec)
   6185 		  && bfd_is_abs_section (p->sec->output_section))
   6186 		{
   6187 		  /* Input section has been discarded, either because
   6188 		     it is a copy of a linkonce section or due to
   6189 		     linker script /DISCARD/, so we'll be discarding
   6190 		     the relocs too.  */
   6191 		}
   6192 	      else if (htab->is_vxworks
   6193 		       && strcmp (p->sec->output_section->name,
   6194 				  ".tls_vars") == 0)
   6195 		{
   6196 		  /* Relocations in vxworks .tls_vars sections are
   6197 		     handled specially by the loader.  */
   6198 		}
   6199 	      else if (p->count != 0)
   6200 		{
   6201 		  asection *sreloc = elf_section_data (p->sec)->sreloc;
   6202 		  if (p->ifunc)
   6203 		    sreloc = htab->reliplt;
   6204 		  sreloc->size += p->count * sizeof (Elf32_External_Rela);
   6205 		  if ((p->sec->output_section->flags
   6206 		       & (SEC_READONLY | SEC_ALLOC))
   6207 		      == (SEC_READONLY | SEC_ALLOC))
   6208 		    info->flags |= DF_TEXTREL;
   6209 		}
   6210 	    }
   6211 	}
   6212 
   6213       local_got = elf_local_got_refcounts (ibfd);
   6214       if (!local_got)
   6215 	continue;
   6216 
   6217       symtab_hdr = &elf_symtab_hdr (ibfd);
   6218       locsymcount = symtab_hdr->sh_info;
   6219       end_local_got = local_got + locsymcount;
   6220       local_plt = (struct plt_entry **) end_local_got;
   6221       end_local_plt = local_plt + locsymcount;
   6222       lgot_masks = (char *) end_local_plt;
   6223 
   6224       for (; local_got < end_local_got; ++local_got, ++lgot_masks)
   6225 	if (*local_got > 0)
   6226 	  {
   6227 	    unsigned int need = 0;
   6228 	    if ((*lgot_masks & TLS_TLS) != 0)
   6229 	      {
   6230 		if ((*lgot_masks & TLS_GD) != 0)
   6231 		  need += 8;
   6232 		if ((*lgot_masks & TLS_LD) != 0)
   6233 		  htab->tlsld_got.refcount += 1;
   6234 		if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
   6235 		  need += 4;
   6236 		if ((*lgot_masks & TLS_DTPREL) != 0)
   6237 		  need += 4;
   6238 	      }
   6239 	    else
   6240 	      need += 4;
   6241 	    if (need == 0)
   6242 	      *local_got = (bfd_vma) -1;
   6243 	    else
   6244 	      {
   6245 		*local_got = allocate_got (htab, need);
   6246 		if (info->shared)
   6247 		  {
   6248 		    asection *srel = htab->relgot;
   6249 		    if ((*lgot_masks & PLT_IFUNC) != 0)
   6250 		      srel = htab->reliplt;
   6251 		    srel->size += need * (sizeof (Elf32_External_Rela) / 4);
   6252 		  }
   6253 	      }
   6254 	  }
   6255 	else
   6256 	  *local_got = (bfd_vma) -1;
   6257 
   6258       if (htab->is_vxworks)
   6259 	continue;
   6260 
   6261       /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt.  */
   6262       for (; local_plt < end_local_plt; ++local_plt)
   6263 	{
   6264 	  struct plt_entry *ent;
   6265 	  bfd_boolean doneone = FALSE;
   6266 	  bfd_vma plt_offset = 0, glink_offset = 0;
   6267 
   6268 	  for (ent = *local_plt; ent != NULL; ent = ent->next)
   6269 	    if (ent->plt.refcount > 0)
   6270 	      {
   6271 		s = htab->iplt;
   6272 
   6273 		if (!doneone)
   6274 		  {
   6275 		    plt_offset = s->size;
   6276 		    s->size += 4;
   6277 		  }
   6278 		ent->plt.offset = plt_offset;
   6279 
   6280 		s = htab->glink;
   6281 		if (!doneone || info->shared)
   6282 		  {
   6283 		    glink_offset = s->size;
   6284 		    s->size += GLINK_ENTRY_SIZE;
   6285 		  }
   6286 		ent->glink_offset = glink_offset;
   6287 
   6288 		if (!doneone)
   6289 		  {
   6290 		    htab->reliplt->size += sizeof (Elf32_External_Rela);
   6291 		    doneone = TRUE;
   6292 		  }
   6293 	      }
   6294 	    else
   6295 	      ent->plt.offset = (bfd_vma) -1;
   6296 	}
   6297     }
   6298 
   6299   /* Allocate space for global sym dynamic relocs.  */
   6300   elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
   6301 
   6302   if (htab->tlsld_got.refcount > 0)
   6303     {
   6304       htab->tlsld_got.offset = allocate_got (htab, 8);
   6305       if (info->shared)
   6306 	htab->relgot->size += sizeof (Elf32_External_Rela);
   6307     }
   6308   else
   6309     htab->tlsld_got.offset = (bfd_vma) -1;
   6310 
   6311   if (htab->got != NULL && htab->plt_type != PLT_VXWORKS)
   6312     {
   6313       unsigned int g_o_t = 32768;
   6314 
   6315       /* If we haven't allocated the header, do so now.  When we get here,
   6316 	 for old plt/got the got size will be 0 to 32764 (not allocated),
   6317 	 or 32780 to 65536 (header allocated).  For new plt/got, the
   6318 	 corresponding ranges are 0 to 32768 and 32780 to 65536.  */
   6319       if (htab->got->size <= 32768)
   6320 	{
   6321 	  g_o_t = htab->got->size;
   6322 	  if (htab->plt_type == PLT_OLD)
   6323 	    g_o_t += 4;
   6324 	  htab->got->size += htab->got_header_size;
   6325 	}
   6326 
   6327       htab->elf.hgot->root.u.def.value = g_o_t;
   6328     }
   6329   if (info->shared)
   6330     {
   6331       struct elf_link_hash_entry *sda = htab->sdata[0].sym;
   6332 
   6333       sda->root.u.def.section = htab->elf.hgot->root.u.def.section;
   6334       sda->root.u.def.value = htab->elf.hgot->root.u.def.value;
   6335     }
   6336   if (info->emitrelocations)
   6337     {
   6338       struct elf_link_hash_entry *sda = htab->sdata[0].sym;
   6339 
   6340       if (sda != NULL && sda->ref_regular)
   6341 	sda->root.u.def.section->flags |= SEC_KEEP;
   6342       sda = htab->sdata[1].sym;
   6343       if (sda != NULL && sda->ref_regular)
   6344 	sda->root.u.def.section->flags |= SEC_KEEP;
   6345     }
   6346 
   6347   if (htab->glink != NULL
   6348       && htab->glink->size != 0
   6349       && htab->elf.dynamic_sections_created)
   6350     {
   6351       htab->glink_pltresolve = htab->glink->size;
   6352       /* Space for the branch table.  */
   6353       htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4;
   6354       /* Pad out to align the start of PLTresolve.  */
   6355       htab->glink->size += -htab->glink->size & (htab->params->ppc476_workaround
   6356 						 ? 63 : 15);
   6357       htab->glink->size += GLINK_PLTRESOLVE;
   6358 
   6359       if (htab->params->emit_stub_syms)
   6360 	{
   6361 	  struct elf_link_hash_entry *sh;
   6362 	  sh = elf_link_hash_lookup (&htab->elf, "__glink",
   6363 				     TRUE, FALSE, FALSE);
   6364 	  if (sh == NULL)
   6365 	    return FALSE;
   6366 	  if (sh->root.type == bfd_link_hash_new)
   6367 	    {
   6368 	      sh->root.type = bfd_link_hash_defined;
   6369 	      sh->root.u.def.section = htab->glink;
   6370 	      sh->root.u.def.value = htab->glink_pltresolve;
   6371 	      sh->ref_regular = 1;
   6372 	      sh->def_regular = 1;
   6373 	      sh->ref_regular_nonweak = 1;
   6374 	      sh->forced_local = 1;
   6375 	      sh->non_elf = 0;
   6376 	    }
   6377 	  sh = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
   6378 				     TRUE, FALSE, FALSE);
   6379 	  if (sh == NULL)
   6380 	    return FALSE;
   6381 	  if (sh->root.type == bfd_link_hash_new)
   6382 	    {
   6383 	      sh->root.type = bfd_link_hash_defined;
   6384 	      sh->root.u.def.section = htab->glink;
   6385 	      sh->root.u.def.value = htab->glink->size - GLINK_PLTRESOLVE;
   6386 	      sh->ref_regular = 1;
   6387 	      sh->def_regular = 1;
   6388 	      sh->ref_regular_nonweak = 1;
   6389 	      sh->forced_local = 1;
   6390 	      sh->non_elf = 0;
   6391 	    }
   6392 	}
   6393     }
   6394 
   6395   if (htab->glink != NULL
   6396       && htab->glink->size != 0
   6397       && htab->glink_eh_frame != NULL
   6398       && !bfd_is_abs_section (htab->glink_eh_frame->output_section)
   6399       && _bfd_elf_eh_frame_present (info))
   6400     {
   6401       s = htab->glink_eh_frame;
   6402       s->size = sizeof (glink_eh_frame_cie) + 20;
   6403       if (info->shared)
   6404 	{
   6405 	  s->size += 4;
   6406 	  if (htab->glink->size - GLINK_PLTRESOLVE + 8 >= 256)
   6407 	    s->size += 4;
   6408 	}
   6409     }
   6410 
   6411   /* We've now determined the sizes of the various dynamic sections.
   6412      Allocate memory for them.  */
   6413   relocs = FALSE;
   6414   for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
   6415     {
   6416       bfd_boolean strip_section = TRUE;
   6417 
   6418       if ((s->flags & SEC_LINKER_CREATED) == 0)
   6419 	continue;
   6420 
   6421       if (s == htab->plt
   6422 	  || s == htab->got)
   6423 	{
   6424 	  /* We'd like to strip these sections if they aren't needed, but if
   6425 	     we've exported dynamic symbols from them we must leave them.
   6426 	     It's too late to tell BFD to get rid of the symbols.  */
   6427 	  if (htab->elf.hplt != NULL)
   6428 	    strip_section = FALSE;
   6429 	  /* Strip this section if we don't need it; see the
   6430 	     comment below.  */
   6431 	}
   6432       else if (s == htab->iplt
   6433 	       || s == htab->glink
   6434 	       || s == htab->glink_eh_frame
   6435 	       || s == htab->sgotplt
   6436 	       || s == htab->sbss
   6437 	       || s == htab->dynbss
   6438 	       || s == htab->dynsbss)
   6439 	{
   6440 	  /* Strip these too.  */
   6441 	}
   6442       else if (s == htab->sdata[0].section
   6443 	       || s == htab->sdata[1].section)
   6444 	{
   6445 	  strip_section = (s->flags & SEC_KEEP) == 0;
   6446 	}
   6447       else if (CONST_STRNEQ (bfd_get_section_name (htab->elf.dynobj, s),
   6448 			     ".rela"))
   6449 	{
   6450 	  if (s->size != 0)
   6451 	    {
   6452 	      /* Remember whether there are any relocation sections.  */
   6453 	      relocs = TRUE;
   6454 
   6455 	      /* We use the reloc_count field as a counter if we need
   6456 		 to copy relocs into the output file.  */
   6457 	      s->reloc_count = 0;
   6458 	    }
   6459 	}
   6460       else
   6461 	{
   6462 	  /* It's not one of our sections, so don't allocate space.  */
   6463 	  continue;
   6464 	}
   6465 
   6466       if (s->size == 0 && strip_section)
   6467 	{
   6468 	  /* If we don't need this section, strip it from the
   6469 	     output file.  This is mostly to handle .rela.bss and
   6470 	     .rela.plt.  We must create both sections in
   6471 	     create_dynamic_sections, because they must be created
   6472 	     before the linker maps input sections to output
   6473 	     sections.  The linker does that before
   6474 	     adjust_dynamic_symbol is called, and it is that
   6475 	     function which decides whether anything needs to go
   6476 	     into these sections.  */
   6477 	  s->flags |= SEC_EXCLUDE;
   6478 	  continue;
   6479 	}
   6480 
   6481       if ((s->flags & SEC_HAS_CONTENTS) == 0)
   6482 	continue;
   6483 
   6484       /* Allocate memory for the section contents.  */
   6485       s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
   6486       if (s->contents == NULL)
   6487 	return FALSE;
   6488     }
   6489 
   6490   if (htab->elf.dynamic_sections_created)
   6491     {
   6492       /* Add some entries to the .dynamic section.  We fill in the
   6493 	 values later, in ppc_elf_finish_dynamic_sections, but we
   6494 	 must add the entries now so that we get the correct size for
   6495 	 the .dynamic section.  The DT_DEBUG entry is filled in by the
   6496 	 dynamic linker and used by the debugger.  */
   6497 #define add_dynamic_entry(TAG, VAL) \
   6498   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
   6499 
   6500       if (info->executable)
   6501 	{
   6502 	  if (!add_dynamic_entry (DT_DEBUG, 0))
   6503 	    return FALSE;
   6504 	}
   6505 
   6506       if (htab->plt != NULL && htab->plt->size != 0)
   6507 	{
   6508 	  if (!add_dynamic_entry (DT_PLTGOT, 0)
   6509 	      || !add_dynamic_entry (DT_PLTRELSZ, 0)
   6510 	      || !add_dynamic_entry (DT_PLTREL, DT_RELA)
   6511 	      || !add_dynamic_entry (DT_JMPREL, 0))
   6512 	    return FALSE;
   6513 	}
   6514 
   6515       if (htab->plt_type == PLT_NEW
   6516 	  && htab->glink != NULL
   6517 	  && htab->glink->size != 0)
   6518 	{
   6519 	  if (!add_dynamic_entry (DT_PPC_GOT, 0))
   6520 	    return FALSE;
   6521 	  if (!htab->params->no_tls_get_addr_opt
   6522 	      && htab->tls_get_addr != NULL
   6523 	      && htab->tls_get_addr->plt.plist != NULL
   6524 	      && !add_dynamic_entry (DT_PPC_OPT, PPC_OPT_TLS))
   6525 	    return FALSE;
   6526 	}
   6527 
   6528       if (relocs)
   6529 	{
   6530 	  if (!add_dynamic_entry (DT_RELA, 0)
   6531 	      || !add_dynamic_entry (DT_RELASZ, 0)
   6532 	      || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
   6533 	    return FALSE;
   6534 	}
   6535 
   6536       /* If any dynamic relocs apply to a read-only section, then we
   6537 	 need a DT_TEXTREL entry.  */
   6538       if ((info->flags & DF_TEXTREL) == 0)
   6539 	elf_link_hash_traverse (elf_hash_table (info), maybe_set_textrel,
   6540 				info);
   6541 
   6542       if ((info->flags & DF_TEXTREL) != 0)
   6543 	{
   6544 	  if (!add_dynamic_entry (DT_TEXTREL, 0))
   6545 	    return FALSE;
   6546 	}
   6547       if (htab->is_vxworks
   6548 	  && !elf_vxworks_add_dynamic_entries (output_bfd, info))
   6549 	return FALSE;
   6550    }
   6551 #undef add_dynamic_entry
   6552 
   6553   if (htab->glink_eh_frame != NULL
   6554       && htab->glink_eh_frame->contents != NULL)
   6555     {
   6556       unsigned char *p = htab->glink_eh_frame->contents;
   6557       bfd_vma val;
   6558 
   6559       memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
   6560       /* CIE length (rewrite in case little-endian).  */
   6561       bfd_put_32 (htab->elf.dynobj, sizeof (glink_eh_frame_cie) - 4, p);
   6562       p += sizeof (glink_eh_frame_cie);
   6563       /* FDE length.  */
   6564       val = htab->glink_eh_frame->size - 4 - sizeof (glink_eh_frame_cie);
   6565       bfd_put_32 (htab->elf.dynobj, val, p);
   6566       p += 4;
   6567       /* CIE pointer.  */
   6568       val = p - htab->glink_eh_frame->contents;
   6569       bfd_put_32 (htab->elf.dynobj, val, p);
   6570       p += 4;
   6571       /* Offset to .glink.  Set later.  */
   6572       p += 4;
   6573       /* .glink size.  */
   6574       bfd_put_32 (htab->elf.dynobj, htab->glink->size, p);
   6575       p += 4;
   6576       /* Augmentation.  */
   6577       p += 1;
   6578 
   6579       if (info->shared
   6580 	  && htab->elf.dynamic_sections_created)
   6581 	{
   6582 	  bfd_vma adv = (htab->glink->size - GLINK_PLTRESOLVE + 8) >> 2;
   6583 	  if (adv < 64)
   6584 	    *p++ = DW_CFA_advance_loc + adv;
   6585 	  else if (adv < 256)
   6586 	    {
   6587 	      *p++ = DW_CFA_advance_loc1;
   6588 	      *p++ = adv;
   6589 	    }
   6590 	  else if (adv < 65536)
   6591 	    {
   6592 	      *p++ = DW_CFA_advance_loc2;
   6593 	      bfd_put_16 (htab->elf.dynobj, adv, p);
   6594 	      p += 2;
   6595 	    }
   6596 	  else
   6597 	    {
   6598 	      *p++ = DW_CFA_advance_loc4;
   6599 	      bfd_put_32 (htab->elf.dynobj, adv, p);
   6600 	      p += 4;
   6601 	    }
   6602 	  *p++ = DW_CFA_register;
   6603 	  *p++ = 65;
   6604 	  p++;
   6605 	  *p++ = DW_CFA_advance_loc + 4;
   6606 	  *p++ = DW_CFA_restore_extended;
   6607 	  *p++ = 65;
   6608 	}
   6609       BFD_ASSERT ((bfd_vma) ((p + 3 - htab->glink_eh_frame->contents) & -4)
   6610 		  == htab->glink_eh_frame->size);
   6611     }
   6612 
   6613   return TRUE;
   6614 }
   6615 
   6616 /* Arrange to have _SDA_BASE_ or _SDA2_BASE_ stripped from the output
   6617    if it looks like nothing is using them.  */
   6618 
   6619 static void
   6620 maybe_strip_sdasym (bfd *output_bfd, elf_linker_section_t *lsect)
   6621 {
   6622   struct elf_link_hash_entry *sda = lsect->sym;
   6623 
   6624   if (sda != NULL && !sda->ref_regular && sda->dynindx == -1)
   6625     {
   6626       asection *s;
   6627 
   6628       s = bfd_get_section_by_name (output_bfd, lsect->name);
   6629       if (s == NULL || bfd_section_removed_from_list (output_bfd, s))
   6630 	{
   6631 	  s = bfd_get_section_by_name (output_bfd, lsect->bss_name);
   6632 	  if (s == NULL || bfd_section_removed_from_list (output_bfd, s))
   6633 	    {
   6634 	      sda->def_regular = 0;
   6635 	      /* This is somewhat magic.  See elf_link_output_extsym.  */
   6636 	      sda->ref_dynamic = 1;
   6637 	      sda->forced_local = 0;
   6638 	    }
   6639 	}
   6640     }
   6641 }
   6642 
   6643 void
   6644 ppc_elf_maybe_strip_sdata_syms (struct bfd_link_info *info)
   6645 {
   6646   struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
   6647 
   6648   if (htab != NULL)
   6649     {
   6650       maybe_strip_sdasym (info->output_bfd, &htab->sdata[0]);
   6651       maybe_strip_sdasym (info->output_bfd, &htab->sdata[1]);
   6652     }
   6653 }
   6654 
   6655 
   6656 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section.  */
   6657 
   6658 static bfd_boolean
   6659 ppc_elf_hash_symbol (struct elf_link_hash_entry *h)
   6660 {
   6661   if (h->plt.plist != NULL
   6662       && !h->def_regular
   6663       && (!h->pointer_equality_needed
   6664 	  || !h->ref_regular_nonweak))
   6665     return FALSE;
   6666 
   6667   return _bfd_elf_hash_symbol (h);
   6668 }
   6669 
   6670 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
   6672 
   6673 /* Relaxation trampolines.  r12 is available for clobbering (r11, is
   6674    used for some functions that are allowed to break the ABI).  */
   6675 static const int shared_stub_entry[] =
   6676   {
   6677     0x7c0802a6, /* mflr 0 */
   6678     0x429f0005, /* bcl 20, 31, .Lxxx */
   6679     0x7d8802a6, /* mflr 12 */
   6680     0x3d8c0000, /* addis 12, 12, (xxx-.Lxxx)@ha */
   6681     0x398c0000, /* addi 12, 12, (xxx-.Lxxx)@l */
   6682     0x7c0803a6, /* mtlr 0 */
   6683     0x7d8903a6, /* mtctr 12 */
   6684     0x4e800420, /* bctr */
   6685   };
   6686 
   6687 static const int stub_entry[] =
   6688   {
   6689     0x3d800000, /* lis 12,xxx@ha */
   6690     0x398c0000, /* addi 12,12,xxx@l */
   6691     0x7d8903a6, /* mtctr 12 */
   6692     0x4e800420, /* bctr */
   6693   };
   6694 
   6695 struct ppc_elf_relax_info
   6696 {
   6697   unsigned int workaround_size;
   6698 };
   6699 
   6700 /* This function implements long branch trampolines, and the ppc476
   6701    icache bug workaround.  Any section needing trampolines or patch
   6702    space for the workaround has its size extended so that we can
   6703    add trampolines at the end of the section.  */
   6704 
   6705 static bfd_boolean
   6706 ppc_elf_relax_section (bfd *abfd,
   6707 		       asection *isec,
   6708 		       struct bfd_link_info *link_info,
   6709 		       bfd_boolean *again)
   6710 {
   6711   struct one_fixup
   6712   {
   6713     struct one_fixup *next;
   6714     asection *tsec;
   6715     /* Final link, can use the symbol offset.  For a
   6716        relocatable link we use the symbol's index.  */
   6717     bfd_vma toff;
   6718     bfd_vma trampoff;
   6719   };
   6720 
   6721   Elf_Internal_Shdr *symtab_hdr;
   6722   bfd_byte *contents = NULL;
   6723   Elf_Internal_Sym *isymbuf = NULL;
   6724   Elf_Internal_Rela *internal_relocs = NULL;
   6725   Elf_Internal_Rela *irel, *irelend = NULL;
   6726   struct one_fixup *fixups = NULL;
   6727   struct ppc_elf_relax_info *relax_info = NULL;
   6728   unsigned changes = 0;
   6729   bfd_boolean workaround_change;
   6730   struct ppc_elf_link_hash_table *htab;
   6731   bfd_size_type trampbase, trampoff, newsize;
   6732   asection *got2;
   6733   bfd_boolean maybe_pasted;
   6734 
   6735   *again = FALSE;
   6736 
   6737   /* No need to do anything with non-alloc or non-code sections.  */
   6738   if ((isec->flags & SEC_ALLOC) == 0
   6739       || (isec->flags & SEC_CODE) == 0
   6740       || (isec->flags & SEC_LINKER_CREATED) != 0
   6741       || isec->size < 4)
   6742     return TRUE;
   6743 
   6744   /* We cannot represent the required PIC relocs in the output, so don't
   6745      do anything.  The linker doesn't support mixing -shared and -r
   6746      anyway.  */
   6747   if (link_info->relocatable && link_info->shared)
   6748     return TRUE;
   6749 
   6750   htab = ppc_elf_hash_table (link_info);
   6751   if (htab == NULL)
   6752     return TRUE;
   6753 
   6754   isec->size = (isec->size + 3) & -4;
   6755   if (isec->rawsize == 0)
   6756     isec->rawsize = isec->size;
   6757   trampbase = isec->size;
   6758 
   6759   BFD_ASSERT (isec->sec_info_type == SEC_INFO_TYPE_NONE
   6760 	      || isec->sec_info_type == SEC_INFO_TYPE_TARGET);
   6761   isec->sec_info_type = SEC_INFO_TYPE_TARGET;
   6762 
   6763   if (htab->params->ppc476_workaround)
   6764     {
   6765       if (elf_section_data (isec)->sec_info == NULL)
   6766 	{
   6767 	  elf_section_data (isec)->sec_info
   6768 	    = bfd_zalloc (abfd, sizeof (struct ppc_elf_relax_info));
   6769 	  if (elf_section_data (isec)->sec_info == NULL)
   6770 	    return FALSE;
   6771 	}
   6772       relax_info = elf_section_data (isec)->sec_info;
   6773       trampbase -= relax_info->workaround_size;
   6774     }
   6775 
   6776   maybe_pasted = (strcmp (isec->output_section->name, ".init") == 0
   6777 		  || strcmp (isec->output_section->name, ".fini") == 0);
   6778   /* Space for a branch around any trampolines.  */
   6779   trampoff = trampbase;
   6780   if (maybe_pasted && trampbase == isec->rawsize)
   6781     trampoff += 4;
   6782 
   6783   symtab_hdr = &elf_symtab_hdr (abfd);
   6784 
   6785   if (htab->params->branch_trampolines)
   6786     {
   6787       /* Get a copy of the native relocations.  */
   6788       if (isec->reloc_count != 0)
   6789 	{
   6790 	  internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL,
   6791 						       link_info->keep_memory);
   6792 	  if (internal_relocs == NULL)
   6793 	    goto error_return;
   6794 	}
   6795 
   6796       got2 = bfd_get_section_by_name (abfd, ".got2");
   6797 
   6798       irelend = internal_relocs + isec->reloc_count;
   6799       for (irel = internal_relocs; irel < irelend; irel++)
   6800 	{
   6801 	  unsigned long r_type = ELF32_R_TYPE (irel->r_info);
   6802 	  bfd_vma toff, roff;
   6803 	  asection *tsec;
   6804 	  struct one_fixup *f;
   6805 	  size_t insn_offset = 0;
   6806 	  bfd_vma max_branch_offset, val;
   6807 	  bfd_byte *hit_addr;
   6808 	  unsigned long t0;
   6809 	  struct elf_link_hash_entry *h;
   6810 	  struct plt_entry **plist;
   6811 	  unsigned char sym_type;
   6812 
   6813 	  switch (r_type)
   6814 	    {
   6815 	    case R_PPC_REL24:
   6816 	    case R_PPC_LOCAL24PC:
   6817 	    case R_PPC_PLTREL24:
   6818 	      max_branch_offset = 1 << 25;
   6819 	      break;
   6820 
   6821 	    case R_PPC_REL14:
   6822 	    case R_PPC_REL14_BRTAKEN:
   6823 	    case R_PPC_REL14_BRNTAKEN:
   6824 	      max_branch_offset = 1 << 15;
   6825 	      break;
   6826 
   6827 	    default:
   6828 	      continue;
   6829 	    }
   6830 
   6831 	  /* Get the value of the symbol referred to by the reloc.  */
   6832 	  h = NULL;
   6833 	  if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
   6834 	    {
   6835 	      /* A local symbol.  */
   6836 	      Elf_Internal_Sym *isym;
   6837 
   6838 	      /* Read this BFD's local symbols.  */
   6839 	      if (isymbuf == NULL)
   6840 		{
   6841 		  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   6842 		  if (isymbuf == NULL)
   6843 		    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
   6844 						    symtab_hdr->sh_info, 0,
   6845 						    NULL, NULL, NULL);
   6846 		  if (isymbuf == 0)
   6847 		    goto error_return;
   6848 		}
   6849 	      isym = isymbuf + ELF32_R_SYM (irel->r_info);
   6850 	      if (isym->st_shndx == SHN_UNDEF)
   6851 		tsec = bfd_und_section_ptr;
   6852 	      else if (isym->st_shndx == SHN_ABS)
   6853 		tsec = bfd_abs_section_ptr;
   6854 	      else if (isym->st_shndx == SHN_COMMON)
   6855 		tsec = bfd_com_section_ptr;
   6856 	      else
   6857 		tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
   6858 
   6859 	      toff = isym->st_value;
   6860 	      sym_type = ELF_ST_TYPE (isym->st_info);
   6861 	    }
   6862 	  else
   6863 	    {
   6864 	      /* Global symbol handling.  */
   6865 	      unsigned long indx;
   6866 
   6867 	      indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
   6868 	      h = elf_sym_hashes (abfd)[indx];
   6869 
   6870 	      while (h->root.type == bfd_link_hash_indirect
   6871 		     || h->root.type == bfd_link_hash_warning)
   6872 		h = (struct elf_link_hash_entry *) h->root.u.i.link;
   6873 
   6874 	      if (h->root.type == bfd_link_hash_defined
   6875 		  || h->root.type == bfd_link_hash_defweak)
   6876 		{
   6877 		  tsec = h->root.u.def.section;
   6878 		  toff = h->root.u.def.value;
   6879 		}
   6880 	      else if (h->root.type == bfd_link_hash_undefined
   6881 		       || h->root.type == bfd_link_hash_undefweak)
   6882 		{
   6883 		  tsec = bfd_und_section_ptr;
   6884 		  toff = link_info->relocatable ? indx : 0;
   6885 		}
   6886 	      else
   6887 		continue;
   6888 
   6889 	      /* If this branch is to __tls_get_addr then we may later
   6890 		 optimise away the call.  We won't be needing a long-
   6891 		 branch stub in that case.  */
   6892 	      if (link_info->executable
   6893 		  && !link_info->relocatable
   6894 		  && h == htab->tls_get_addr
   6895 		  && irel != internal_relocs)
   6896 		{
   6897 		  unsigned long t_symndx = ELF32_R_SYM (irel[-1].r_info);
   6898 		  unsigned long t_rtype = ELF32_R_TYPE (irel[-1].r_info);
   6899 		  unsigned int tls_mask = 0;
   6900 
   6901 		  /* The previous reloc should be one of R_PPC_TLSGD or
   6902 		     R_PPC_TLSLD, or for older object files, a reloc
   6903 		     on the __tls_get_addr arg setup insn.  Get tls
   6904 		     mask bits from the symbol on that reloc.  */
   6905 		  if (t_symndx < symtab_hdr->sh_info)
   6906 		    {
   6907 		      bfd_vma *local_got_offsets = elf_local_got_offsets (abfd);
   6908 
   6909 		      if (local_got_offsets != NULL)
   6910 			{
   6911 			  struct plt_entry **local_plt = (struct plt_entry **)
   6912 			    (local_got_offsets + symtab_hdr->sh_info);
   6913 			  char *lgot_masks = (char *)
   6914 			    (local_plt + symtab_hdr->sh_info);
   6915 			  tls_mask = lgot_masks[t_symndx];
   6916 			}
   6917 		    }
   6918 		  else
   6919 		    {
   6920 		      struct elf_link_hash_entry *th
   6921 			= elf_sym_hashes (abfd)[t_symndx - symtab_hdr->sh_info];
   6922 
   6923 		      while (th->root.type == bfd_link_hash_indirect
   6924 			     || th->root.type == bfd_link_hash_warning)
   6925 			th = (struct elf_link_hash_entry *) th->root.u.i.link;
   6926 
   6927 		      tls_mask
   6928 			= ((struct ppc_elf_link_hash_entry *) th)->tls_mask;
   6929 		    }
   6930 
   6931 		  /* The mask bits tell us if the call will be
   6932 		     optimised away.  */
   6933 		  if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0
   6934 		      && (t_rtype == R_PPC_TLSGD
   6935 			  || t_rtype == R_PPC_GOT_TLSGD16
   6936 			  || t_rtype == R_PPC_GOT_TLSGD16_LO))
   6937 		    continue;
   6938 		  if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0
   6939 		      && (t_rtype == R_PPC_TLSLD
   6940 			  || t_rtype == R_PPC_GOT_TLSLD16
   6941 			  || t_rtype == R_PPC_GOT_TLSLD16_LO))
   6942 		    continue;
   6943 		}
   6944 
   6945 	      sym_type = h->type;
   6946 	    }
   6947 
   6948 	  /* The condition here under which we call find_plt_ent must
   6949 	     match that in relocate_section.  If we call find_plt_ent here
   6950 	     but not in relocate_section, or vice versa, then the branch
   6951 	     destination used here may be incorrect.  */
   6952 	  plist = NULL;
   6953 	  if (h != NULL)
   6954 	    {
   6955 	      /* We know is_branch_reloc (r_type) is true.  */
   6956 	      if (h->type == STT_GNU_IFUNC
   6957 		  || r_type == R_PPC_PLTREL24)
   6958 		plist = &h->plt.plist;
   6959 	    }
   6960 	  else if (sym_type == STT_GNU_IFUNC
   6961 		   && elf_local_got_offsets (abfd) != NULL)
   6962 	    {
   6963 	      bfd_vma *local_got_offsets = elf_local_got_offsets (abfd);
   6964 	      struct plt_entry **local_plt = (struct plt_entry **)
   6965 		(local_got_offsets + symtab_hdr->sh_info);
   6966 	      plist = local_plt + ELF32_R_SYM (irel->r_info);
   6967 	    }
   6968 	  if (plist != NULL)
   6969 	    {
   6970 	      bfd_vma addend = 0;
   6971 	      struct plt_entry *ent;
   6972 
   6973 	      if (r_type == R_PPC_PLTREL24 && link_info->shared)
   6974 		addend = irel->r_addend;
   6975 	      ent = find_plt_ent (plist, got2, addend);
   6976 	      if (ent != NULL)
   6977 		{
   6978 		  if (htab->plt_type == PLT_NEW
   6979 		      || h == NULL
   6980 		      || !htab->elf.dynamic_sections_created
   6981 		      || h->dynindx == -1)
   6982 		    {
   6983 		      tsec = htab->glink;
   6984 		      toff = ent->glink_offset;
   6985 		    }
   6986 		  else
   6987 		    {
   6988 		      tsec = htab->plt;
   6989 		      toff = ent->plt.offset;
   6990 		    }
   6991 		}
   6992 	    }
   6993 
   6994 	  /* If the branch and target are in the same section, you have
   6995 	     no hope of adding stubs.  We'll error out later should the
   6996 	     branch overflow.  */
   6997 	  if (tsec == isec)
   6998 	    continue;
   6999 
   7000 	  /* There probably isn't any reason to handle symbols in
   7001 	     SEC_MERGE sections;  SEC_MERGE doesn't seem a likely
   7002 	     attribute for a code section, and we are only looking at
   7003 	     branches.  However, implement it correctly here as a
   7004 	     reference for other target relax_section functions.  */
   7005 	  if (0 && tsec->sec_info_type == SEC_INFO_TYPE_MERGE)
   7006 	    {
   7007 	      /* At this stage in linking, no SEC_MERGE symbol has been
   7008 		 adjusted, so all references to such symbols need to be
   7009 		 passed through _bfd_merged_section_offset.  (Later, in
   7010 		 relocate_section, all SEC_MERGE symbols *except* for
   7011 		 section symbols have been adjusted.)
   7012 
   7013 		 gas may reduce relocations against symbols in SEC_MERGE
   7014 		 sections to a relocation against the section symbol when
   7015 		 the original addend was zero.  When the reloc is against
   7016 		 a section symbol we should include the addend in the
   7017 		 offset passed to _bfd_merged_section_offset, since the
   7018 		 location of interest is the original symbol.  On the
   7019 		 other hand, an access to "sym+addend" where "sym" is not
   7020 		 a section symbol should not include the addend;  Such an
   7021 		 access is presumed to be an offset from "sym";  The
   7022 		 location of interest is just "sym".  */
   7023 	      if (sym_type == STT_SECTION)
   7024 		toff += irel->r_addend;
   7025 
   7026 	      toff
   7027 		= _bfd_merged_section_offset (abfd, &tsec,
   7028 					      elf_section_data (tsec)->sec_info,
   7029 					      toff);
   7030 
   7031 	      if (sym_type != STT_SECTION)
   7032 		toff += irel->r_addend;
   7033 	    }
   7034 	  /* PLTREL24 addends are special.  */
   7035 	  else if (r_type != R_PPC_PLTREL24)
   7036 	    toff += irel->r_addend;
   7037 
   7038 	  /* Attempted -shared link of non-pic code loses.  */
   7039 	  if ((!link_info->relocatable
   7040 	       && tsec == bfd_und_section_ptr)
   7041 	      || tsec->output_section == NULL
   7042 	      || (tsec->owner != NULL
   7043 		  && (tsec->owner->flags & BFD_PLUGIN) != 0))
   7044 	    continue;
   7045 
   7046 	  roff = irel->r_offset;
   7047 
   7048 	  /* If the branch is in range, no need to do anything.  */
   7049 	  if (tsec != bfd_und_section_ptr
   7050 	      && (!link_info->relocatable
   7051 		  /* A relocatable link may have sections moved during
   7052 		     final link, so do not presume they remain in range.  */
   7053 		  || tsec->output_section == isec->output_section))
   7054 	    {
   7055 	      bfd_vma symaddr, reladdr;
   7056 
   7057 	      symaddr = tsec->output_section->vma + tsec->output_offset + toff;
   7058 	      reladdr = isec->output_section->vma + isec->output_offset + roff;
   7059 	      if (symaddr - reladdr + max_branch_offset
   7060 		  < 2 * max_branch_offset)
   7061 		continue;
   7062 	    }
   7063 
   7064 	  /* Look for an existing fixup to this address.  */
   7065 	  for (f = fixups; f ; f = f->next)
   7066 	    if (f->tsec == tsec && f->toff == toff)
   7067 	      break;
   7068 
   7069 	  if (f == NULL)
   7070 	    {
   7071 	      size_t size;
   7072 	      unsigned long stub_rtype;
   7073 
   7074 	      val = trampoff - roff;
   7075 	      if (val >= max_branch_offset)
   7076 		/* Oh dear, we can't reach a trampoline.  Don't try to add
   7077 		   one.  We'll report an error later.  */
   7078 		continue;
   7079 
   7080 	      if (link_info->shared)
   7081 		{
   7082 		  size = 4 * ARRAY_SIZE (shared_stub_entry);
   7083 		  insn_offset = 12;
   7084 		}
   7085 	      else
   7086 		{
   7087 		  size = 4 * ARRAY_SIZE (stub_entry);
   7088 		  insn_offset = 0;
   7089 		}
   7090 	      stub_rtype = R_PPC_RELAX;
   7091 	      if (tsec == htab->plt
   7092 		  || tsec == htab->glink)
   7093 		{
   7094 		  stub_rtype = R_PPC_RELAX_PLT;
   7095 		  if (r_type == R_PPC_PLTREL24)
   7096 		    stub_rtype = R_PPC_RELAX_PLTREL24;
   7097 		}
   7098 
   7099 	      /* Hijack the old relocation.  Since we need two
   7100 		 relocations for this use a "composite" reloc.  */
   7101 	      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   7102 					   stub_rtype);
   7103 	      irel->r_offset = trampoff + insn_offset;
   7104 	      if (r_type == R_PPC_PLTREL24
   7105 		  && stub_rtype != R_PPC_RELAX_PLTREL24)
   7106 		irel->r_addend = 0;
   7107 
   7108 	      /* Record the fixup so we don't do it again this section.  */
   7109 	      f = bfd_malloc (sizeof (*f));
   7110 	      f->next = fixups;
   7111 	      f->tsec = tsec;
   7112 	      f->toff = toff;
   7113 	      f->trampoff = trampoff;
   7114 	      fixups = f;
   7115 
   7116 	      trampoff += size;
   7117 	      changes++;
   7118 	    }
   7119 	  else
   7120 	    {
   7121 	      val = f->trampoff - roff;
   7122 	      if (val >= max_branch_offset)
   7123 		continue;
   7124 
   7125 	      /* Nop out the reloc, since we're finalizing things here.  */
   7126 	      irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
   7127 	    }
   7128 
   7129 	  /* Get the section contents.  */
   7130 	  if (contents == NULL)
   7131 	    {
   7132 	      /* Get cached copy if it exists.  */
   7133 	      if (elf_section_data (isec)->this_hdr.contents != NULL)
   7134 		contents = elf_section_data (isec)->this_hdr.contents;
   7135 	      /* Go get them off disk.  */
   7136 	      else if (!bfd_malloc_and_get_section (abfd, isec, &contents))
   7137 		goto error_return;
   7138 	    }
   7139 
   7140 	  /* Fix up the existing branch to hit the trampoline.  */
   7141 	  hit_addr = contents + roff;
   7142 	  switch (r_type)
   7143 	    {
   7144 	    case R_PPC_REL24:
   7145 	    case R_PPC_LOCAL24PC:
   7146 	    case R_PPC_PLTREL24:
   7147 	      t0 = bfd_get_32 (abfd, hit_addr);
   7148 	      t0 &= ~0x3fffffc;
   7149 	      t0 |= val & 0x3fffffc;
   7150 	      bfd_put_32 (abfd, t0, hit_addr);
   7151 	      break;
   7152 
   7153 	    case R_PPC_REL14:
   7154 	    case R_PPC_REL14_BRTAKEN:
   7155 	    case R_PPC_REL14_BRNTAKEN:
   7156 	      t0 = bfd_get_32 (abfd, hit_addr);
   7157 	      t0 &= ~0xfffc;
   7158 	      t0 |= val & 0xfffc;
   7159 	      bfd_put_32 (abfd, t0, hit_addr);
   7160 	      break;
   7161 	    }
   7162 	}
   7163 
   7164       while (fixups != NULL)
   7165 	{
   7166 	  struct one_fixup *f = fixups;
   7167 	  fixups = fixups->next;
   7168 	  free (f);
   7169 	}
   7170     }
   7171 
   7172   workaround_change = FALSE;
   7173   newsize = trampoff;
   7174   if (htab->params->ppc476_workaround
   7175       && (!link_info->relocatable
   7176 	  || isec->output_section->alignment_power >= htab->params->pagesize_p2))
   7177     {
   7178       bfd_vma addr, end_addr;
   7179       unsigned int crossings;
   7180       bfd_vma pagesize = (bfd_vma) 1 << htab->params->pagesize_p2;
   7181 
   7182       addr = isec->output_section->vma + isec->output_offset;
   7183       end_addr = addr + trampoff;
   7184       addr &= -pagesize;
   7185       crossings = ((end_addr & -pagesize) - addr) >> htab->params->pagesize_p2;
   7186       if (crossings != 0)
   7187 	{
   7188 	  /* Keep space aligned, to ensure the patch code itself does
   7189 	     not cross a page.  Don't decrease size calculated on a
   7190 	     previous pass as otherwise we might never settle on a layout.  */
   7191 	  newsize = 15 - (end_addr & 15);
   7192 	  newsize += crossings * 16;
   7193 	  if (relax_info->workaround_size < newsize)
   7194 	    {
   7195 	      relax_info->workaround_size = newsize;
   7196 	      workaround_change = TRUE;
   7197 	    }
   7198 	  /* Ensure relocate_section is called.  */
   7199 	  isec->flags |= SEC_RELOC;
   7200 	}
   7201       newsize = trampoff + relax_info->workaround_size;
   7202     }
   7203 
   7204   if (changes || workaround_change)
   7205     isec->size = newsize;
   7206 
   7207   if (isymbuf != NULL
   7208       && symtab_hdr->contents != (unsigned char *) isymbuf)
   7209     {
   7210       if (! link_info->keep_memory)
   7211 	free (isymbuf);
   7212       else
   7213 	{
   7214 	  /* Cache the symbols for elf_link_input_bfd.  */
   7215 	  symtab_hdr->contents = (unsigned char *) isymbuf;
   7216 	}
   7217     }
   7218 
   7219   if (contents != NULL
   7220       && elf_section_data (isec)->this_hdr.contents != contents)
   7221     {
   7222       if (!changes && !link_info->keep_memory)
   7223 	free (contents);
   7224       else
   7225 	{
   7226 	  /* Cache the section contents for elf_link_input_bfd.  */
   7227 	  elf_section_data (isec)->this_hdr.contents = contents;
   7228 	}
   7229     }
   7230 
   7231   if (changes != 0)
   7232     {
   7233       /* Append sufficient NOP relocs so we can write out relocation
   7234 	 information for the trampolines.  */
   7235       Elf_Internal_Shdr *rel_hdr;
   7236       Elf_Internal_Rela *new_relocs = bfd_malloc ((changes + isec->reloc_count)
   7237 						  * sizeof (*new_relocs));
   7238       unsigned ix;
   7239 
   7240       if (!new_relocs)
   7241 	goto error_return;
   7242       memcpy (new_relocs, internal_relocs,
   7243 	      isec->reloc_count * sizeof (*new_relocs));
   7244       for (ix = changes; ix--;)
   7245 	{
   7246 	  irel = new_relocs + ix + isec->reloc_count;
   7247 
   7248 	  irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
   7249 	}
   7250       if (internal_relocs != elf_section_data (isec)->relocs)
   7251 	free (internal_relocs);
   7252       elf_section_data (isec)->relocs = new_relocs;
   7253       isec->reloc_count += changes;
   7254       rel_hdr = _bfd_elf_single_rel_hdr (isec);
   7255       rel_hdr->sh_size += changes * rel_hdr->sh_entsize;
   7256     }
   7257   else if (internal_relocs != NULL
   7258 	   && elf_section_data (isec)->relocs != internal_relocs)
   7259     free (internal_relocs);
   7260 
   7261   *again = changes != 0 || workaround_change;
   7262   return TRUE;
   7263 
   7264  error_return:
   7265   while (fixups != NULL)
   7266     {
   7267       struct one_fixup *f = fixups;
   7268       fixups = fixups->next;
   7269       free (f);
   7270     }
   7271   if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
   7272     free (isymbuf);
   7273   if (contents != NULL
   7274       && elf_section_data (isec)->this_hdr.contents != contents)
   7275     free (contents);
   7276   if (internal_relocs != NULL
   7277       && elf_section_data (isec)->relocs != internal_relocs)
   7278     free (internal_relocs);
   7279   return FALSE;
   7280 }
   7281 
   7282 /* What to do when ld finds relocations against symbols defined in
   7284    discarded sections.  */
   7285 
   7286 static unsigned int
   7287 ppc_elf_action_discarded (asection *sec)
   7288 {
   7289   if (strcmp (".fixup", sec->name) == 0)
   7290     return 0;
   7291 
   7292   if (strcmp (".got2", sec->name) == 0)
   7293     return 0;
   7294 
   7295   return _bfd_elf_default_action_discarded (sec);
   7296 }
   7297 
   7298 /* Fill in the address for a pointer generated in a linker section.  */
   7300 
   7301 static bfd_vma
   7302 elf_finish_pointer_linker_section (bfd *input_bfd,
   7303 				   elf_linker_section_t *lsect,
   7304 				   struct elf_link_hash_entry *h,
   7305 				   bfd_vma relocation,
   7306 				   const Elf_Internal_Rela *rel)
   7307 {
   7308   elf_linker_section_pointers_t *linker_section_ptr;
   7309 
   7310   BFD_ASSERT (lsect != NULL);
   7311 
   7312   if (h != NULL)
   7313     {
   7314       /* Handle global symbol.  */
   7315       struct ppc_elf_link_hash_entry *eh;
   7316 
   7317       eh = (struct ppc_elf_link_hash_entry *) h;
   7318       BFD_ASSERT (eh->elf.def_regular);
   7319       linker_section_ptr = eh->linker_section_pointer;
   7320     }
   7321   else
   7322     {
   7323       /* Handle local symbol.  */
   7324       unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
   7325 
   7326       BFD_ASSERT (is_ppc_elf (input_bfd));
   7327       BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
   7328       linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx];
   7329     }
   7330 
   7331   linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr,
   7332 							rel->r_addend,
   7333 							lsect);
   7334   BFD_ASSERT (linker_section_ptr != NULL);
   7335 
   7336   /* Offset will always be a multiple of four, so use the bottom bit
   7337      as a "written" flag.  */
   7338   if ((linker_section_ptr->offset & 1) == 0)
   7339     {
   7340       bfd_put_32 (lsect->section->owner,
   7341 		  relocation + linker_section_ptr->addend,
   7342 		  lsect->section->contents + linker_section_ptr->offset);
   7343       linker_section_ptr->offset += 1;
   7344     }
   7345 
   7346   relocation = (lsect->section->output_section->vma
   7347 		+ lsect->section->output_offset
   7348 		+ linker_section_ptr->offset - 1
   7349 		- SYM_VAL (lsect->sym));
   7350 
   7351 #ifdef DEBUG
   7352   fprintf (stderr,
   7353 	   "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
   7354 	   lsect->name, (long) relocation, (long) relocation);
   7355 #endif
   7356 
   7357   return relocation;
   7358 }
   7359 
   7360 #define PPC_LO(v) ((v) & 0xffff)
   7361 #define PPC_HI(v) (((v) >> 16) & 0xffff)
   7362 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
   7363 
   7364 static void
   7365 write_glink_stub (struct plt_entry *ent, asection *plt_sec, unsigned char *p,
   7366 		  struct bfd_link_info *info)
   7367 {
   7368   struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
   7369   bfd *output_bfd = info->output_bfd;
   7370   bfd_vma plt;
   7371 
   7372   plt = ((ent->plt.offset & ~1)
   7373 	 + plt_sec->output_section->vma
   7374 	 + plt_sec->output_offset);
   7375 
   7376   if (info->shared)
   7377     {
   7378       bfd_vma got = 0;
   7379 
   7380       if (ent->addend >= 32768)
   7381 	got = (ent->addend
   7382 	       + ent->sec->output_section->vma
   7383 	       + ent->sec->output_offset);
   7384       else if (htab->elf.hgot != NULL)
   7385 	got = SYM_VAL (htab->elf.hgot);
   7386 
   7387       plt -= got;
   7388 
   7389       if (plt + 0x8000 < 0x10000)
   7390 	{
   7391 	  bfd_put_32 (output_bfd, LWZ_11_30 + PPC_LO (plt), p);
   7392 	  p += 4;
   7393 	  bfd_put_32 (output_bfd, MTCTR_11, p);
   7394 	  p += 4;
   7395 	  bfd_put_32 (output_bfd, BCTR, p);
   7396 	  p += 4;
   7397 	  bfd_put_32 (output_bfd, htab->params->ppc476_workaround ? BA : NOP, p);
   7398 	  p += 4;
   7399 	}
   7400       else
   7401 	{
   7402 	  bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (plt), p);
   7403 	  p += 4;
   7404 	  bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
   7405 	  p += 4;
   7406 	  bfd_put_32 (output_bfd, MTCTR_11, p);
   7407 	  p += 4;
   7408 	  bfd_put_32 (output_bfd, BCTR, p);
   7409 	  p += 4;
   7410 	}
   7411     }
   7412   else
   7413     {
   7414       bfd_put_32 (output_bfd, LIS_11 + PPC_HA (plt), p);
   7415       p += 4;
   7416       bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
   7417       p += 4;
   7418       bfd_put_32 (output_bfd, MTCTR_11, p);
   7419       p += 4;
   7420       bfd_put_32 (output_bfd, BCTR, p);
   7421       p += 4;
   7422     }
   7423 }
   7424 
   7425 /* Return true if symbol is defined statically.  */
   7426 
   7427 static bfd_boolean
   7428 is_static_defined (struct elf_link_hash_entry *h)
   7429 {
   7430   return ((h->root.type == bfd_link_hash_defined
   7431 	   || h->root.type == bfd_link_hash_defweak)
   7432 	  && h->root.u.def.section != NULL
   7433 	  && h->root.u.def.section->output_section != NULL);
   7434 }
   7435 
   7436 /* If INSN is an opcode that may be used with an @tls operand, return
   7437    the transformed insn for TLS optimisation, otherwise return 0.  If
   7438    REG is non-zero only match an insn with RB or RA equal to REG.  */
   7439 
   7440 unsigned int
   7441 _bfd_elf_ppc_at_tls_transform (unsigned int insn, unsigned int reg)
   7442 {
   7443   unsigned int rtra;
   7444 
   7445   if ((insn & (0x3f << 26)) != 31 << 26)
   7446     return 0;
   7447 
   7448   if (reg == 0 || ((insn >> 11) & 0x1f) == reg)
   7449     rtra = insn & ((1 << 26) - (1 << 16));
   7450   else if (((insn >> 16) & 0x1f) == reg)
   7451     rtra = (insn & (0x1f << 21)) | ((insn & (0x1f << 11)) << 5);
   7452   else
   7453     return 0;
   7454 
   7455   if ((insn & (0x3ff << 1)) == 266 << 1)
   7456     /* add -> addi.  */
   7457     insn = 14 << 26;
   7458   else if ((insn & (0x1f << 1)) == 23 << 1
   7459 	   && ((insn & (0x1f << 6)) < 14 << 6
   7460 	       || ((insn & (0x1f << 6)) >= 16 << 6
   7461 		   && (insn & (0x1f << 6)) < 24 << 6)))
   7462     /* load and store indexed -> dform.  */
   7463     insn = (32 | ((insn >> 6) & 0x1f)) << 26;
   7464   else if ((insn & (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
   7465     /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu.  */
   7466     insn = ((58 | ((insn >> 6) & 4)) << 26) | ((insn >> 6) & 1);
   7467   else if ((insn & (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
   7468     /* lwax -> lwa.  */
   7469     insn = (58 << 26) | 2;
   7470   else
   7471     return 0;
   7472   insn |= rtra;
   7473   return insn;
   7474 }
   7475 
   7476 /* If INSN is an opcode that may be used with an @tprel operand, return
   7477    the transformed insn for an undefined weak symbol, ie. with the
   7478    thread pointer REG operand removed.  Otherwise return 0.  */
   7479 
   7480 unsigned int
   7481 _bfd_elf_ppc_at_tprel_transform (unsigned int insn, unsigned int reg)
   7482 {
   7483   if ((insn & (0x1f << 16)) == reg << 16
   7484       && ((insn & (0x3f << 26)) == 14u << 26 /* addi */
   7485 	  || (insn & (0x3f << 26)) == 15u << 26 /* addis */
   7486 	  || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
   7487 	  || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
   7488 	  || (insn & (0x3f << 26)) == 36u << 26 /* stw */
   7489 	  || (insn & (0x3f << 26)) == 38u << 26 /* stb */
   7490 	  || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
   7491 	  || (insn & (0x3f << 26)) == 42u << 26 /* lha */
   7492 	  || (insn & (0x3f << 26)) == 44u << 26 /* sth */
   7493 	  || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
   7494 	  || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
   7495 	  || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
   7496 	  || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
   7497 	  || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
   7498 	  || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
   7499 	  || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
   7500 	      && (insn & 3) != 1)
   7501 	  || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */
   7502 	      && ((insn & 3) == 0 || (insn & 3) == 3))))
   7503     {
   7504       insn &= ~(0x1f << 16);
   7505     }
   7506   else if ((insn & (0x1f << 21)) == reg << 21
   7507 	   && ((insn & (0x3e << 26)) == 24u << 26 /* ori, oris */
   7508 	       || (insn & (0x3e << 26)) == 26u << 26 /* xori,xoris */
   7509 	       || (insn & (0x3e << 26)) == 28u << 26 /* andi,andis */))
   7510     {
   7511       insn &= ~(0x1f << 21);
   7512       insn |= (insn & (0x1f << 16)) << 5;
   7513       if ((insn & (0x3e << 26)) == 26 << 26 /* xori,xoris */)
   7514 	insn -= 2 >> 26;  /* convert to ori,oris */
   7515     }
   7516   else
   7517     insn = 0;
   7518   return insn;
   7519 }
   7520 
   7521 static bfd_boolean
   7522 is_insn_ds_form (unsigned int insn)
   7523 {
   7524   return ((insn & (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
   7525 	  || (insn & (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
   7526 	  || (insn & (0x3f << 26)) == 57u << 26 /* lfdp */
   7527 	  || (insn & (0x3f << 26)) == 61u << 26 /* stfdp */);
   7528 }
   7529 
   7530 static bfd_boolean
   7531 is_insn_dq_form (unsigned int insn)
   7532 {
   7533   return (insn & (0x3f << 26)) == 56u << 26; /* lq */
   7534 }
   7535 
   7536 /* The RELOCATE_SECTION function is called by the ELF backend linker
   7537    to handle the relocations for a section.
   7538 
   7539    The relocs are always passed as Rela structures; if the section
   7540    actually uses Rel structures, the r_addend field will always be
   7541    zero.
   7542 
   7543    This function is responsible for adjust the section contents as
   7544    necessary, and (if using Rela relocs and generating a
   7545    relocatable output file) adjusting the reloc addend as
   7546    necessary.
   7547 
   7548    This function does not have to worry about setting the reloc
   7549    address or the reloc symbol index.
   7550 
   7551    LOCAL_SYMS is a pointer to the swapped in local symbols.
   7552 
   7553    LOCAL_SECTIONS is an array giving the section in the input file
   7554    corresponding to the st_shndx field of each local symbol.
   7555 
   7556    The global hash table entry for the global symbols can be found
   7557    via elf_sym_hashes (input_bfd).
   7558 
   7559    When generating relocatable output, this function must handle
   7560    STB_LOCAL/STT_SECTION symbols specially.  The output symbol is
   7561    going to be the section symbol corresponding to the output
   7562    section, which means that the addend must be adjusted
   7563    accordingly.  */
   7564 
   7565 static bfd_boolean
   7566 ppc_elf_relocate_section (bfd *output_bfd,
   7567 			  struct bfd_link_info *info,
   7568 			  bfd *input_bfd,
   7569 			  asection *input_section,
   7570 			  bfd_byte *contents,
   7571 			  Elf_Internal_Rela *relocs,
   7572 			  Elf_Internal_Sym *local_syms,
   7573 			  asection **local_sections)
   7574 {
   7575   Elf_Internal_Shdr *symtab_hdr;
   7576   struct elf_link_hash_entry **sym_hashes;
   7577   struct ppc_elf_link_hash_table *htab;
   7578   Elf_Internal_Rela *rel;
   7579   Elf_Internal_Rela *relend;
   7580   Elf_Internal_Rela outrel;
   7581   asection *got2;
   7582   bfd_vma *local_got_offsets;
   7583   bfd_boolean ret = TRUE;
   7584   bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
   7585   bfd_boolean is_vxworks_tls;
   7586 
   7587 #ifdef DEBUG
   7588   _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
   7589 		      "%ld relocations%s",
   7590 		      input_bfd, input_section,
   7591 		      (long) input_section->reloc_count,
   7592 		      (info->relocatable) ? " (relocatable)" : "");
   7593 #endif
   7594 
   7595   got2 = bfd_get_section_by_name (input_bfd, ".got2");
   7596 
   7597   /* Initialize howto table if not already done.  */
   7598   if (!ppc_elf_howto_table[R_PPC_ADDR32])
   7599     ppc_elf_howto_init ();
   7600 
   7601   htab = ppc_elf_hash_table (info);
   7602   local_got_offsets = elf_local_got_offsets (input_bfd);
   7603   symtab_hdr = &elf_symtab_hdr (input_bfd);
   7604   sym_hashes = elf_sym_hashes (input_bfd);
   7605   /* We have to handle relocations in vxworks .tls_vars sections
   7606      specially, because the dynamic loader is 'weird'.  */
   7607   is_vxworks_tls = (htab->is_vxworks && info->shared
   7608 		    && !strcmp (input_section->output_section->name,
   7609 				".tls_vars"));
   7610   rel = relocs;
   7611   relend = relocs + input_section->reloc_count;
   7612   for (; rel < relend; rel++)
   7613     {
   7614       enum elf_ppc_reloc_type r_type;
   7615       bfd_vma addend;
   7616       bfd_reloc_status_type r;
   7617       Elf_Internal_Sym *sym;
   7618       asection *sec;
   7619       struct elf_link_hash_entry *h;
   7620       const char *sym_name;
   7621       reloc_howto_type *howto;
   7622       unsigned long r_symndx;
   7623       bfd_vma relocation;
   7624       bfd_vma branch_bit, from;
   7625       bfd_boolean unresolved_reloc;
   7626       bfd_boolean warned;
   7627       unsigned int tls_type, tls_mask, tls_gd;
   7628       struct plt_entry **ifunc;
   7629       struct reloc_howto_struct alt_howto;
   7630 
   7631       r_type = ELF32_R_TYPE (rel->r_info);
   7632       sym = NULL;
   7633       sec = NULL;
   7634       h = NULL;
   7635       unresolved_reloc = FALSE;
   7636       warned = FALSE;
   7637       r_symndx = ELF32_R_SYM (rel->r_info);
   7638 
   7639       if (r_symndx < symtab_hdr->sh_info)
   7640 	{
   7641 	  sym = local_syms + r_symndx;
   7642 	  sec = local_sections[r_symndx];
   7643 	  sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
   7644 
   7645 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
   7646 	}
   7647       else
   7648 	{
   7649 	  bfd_boolean ignored;
   7650 
   7651 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
   7652 				   r_symndx, symtab_hdr, sym_hashes,
   7653 				   h, sec, relocation,
   7654 				   unresolved_reloc, warned, ignored);
   7655 
   7656 	  sym_name = h->root.root.string;
   7657 	}
   7658 
   7659       if (sec != NULL && discarded_section (sec))
   7660 	{
   7661 	  /* For relocs against symbols from removed linkonce sections,
   7662 	     or sections discarded by a linker script, we just want the
   7663 	     section contents zeroed.  Avoid any special processing.  */
   7664 	  howto = NULL;
   7665 	  if (r_type < R_PPC_max)
   7666 	    howto = ppc_elf_howto_table[r_type];
   7667 	  RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   7668 					   rel, 1, relend, howto, 0, contents);
   7669 	}
   7670 
   7671       if (info->relocatable)
   7672 	{
   7673 	  if (got2 != NULL
   7674 	      && r_type == R_PPC_PLTREL24
   7675 	      && rel->r_addend != 0)
   7676 	    {
   7677 	      /* R_PPC_PLTREL24 is rather special.  If non-zero, the
   7678 		 addend specifies the GOT pointer offset within .got2.  */
   7679 	      rel->r_addend += got2->output_offset;
   7680 	    }
   7681 	  if (r_type != R_PPC_RELAX_PLT
   7682 	      && r_type != R_PPC_RELAX_PLTREL24
   7683 	      && r_type != R_PPC_RELAX)
   7684 	    continue;
   7685 	}
   7686 
   7687       /* TLS optimizations.  Replace instruction sequences and relocs
   7688 	 based on information we collected in tls_optimize.  We edit
   7689 	 RELOCS so that --emit-relocs will output something sensible
   7690 	 for the final instruction stream.  */
   7691       tls_mask = 0;
   7692       tls_gd = 0;
   7693       if (h != NULL)
   7694 	tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
   7695       else if (local_got_offsets != NULL)
   7696 	{
   7697 	  struct plt_entry **local_plt;
   7698 	  char *lgot_masks;
   7699 	  local_plt
   7700 	    = (struct plt_entry **) (local_got_offsets + symtab_hdr->sh_info);
   7701 	  lgot_masks = (char *) (local_plt + symtab_hdr->sh_info);
   7702 	  tls_mask = lgot_masks[r_symndx];
   7703 	}
   7704 
   7705       /* Ensure reloc mapping code below stays sane.  */
   7706       if ((R_PPC_GOT_TLSLD16 & 3)    != (R_PPC_GOT_TLSGD16 & 3)
   7707 	  || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
   7708 	  || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
   7709 	  || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
   7710 	  || (R_PPC_GOT_TLSLD16 & 3)    != (R_PPC_GOT_TPREL16 & 3)
   7711 	  || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
   7712 	  || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
   7713 	  || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
   7714 	abort ();
   7715       switch (r_type)
   7716 	{
   7717 	default:
   7718 	  break;
   7719 
   7720 	case R_PPC_GOT_TPREL16:
   7721 	case R_PPC_GOT_TPREL16_LO:
   7722 	  if ((tls_mask & TLS_TLS) != 0
   7723 	      && (tls_mask & TLS_TPREL) == 0)
   7724 	    {
   7725 	      bfd_vma insn;
   7726 
   7727 	      insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
   7728 	      insn &= 31 << 21;
   7729 	      insn |= 0x3c020000;	/* addis 0,2,0 */
   7730 	      bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
   7731 	      r_type = R_PPC_TPREL16_HA;
   7732 	      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   7733 	    }
   7734 	  break;
   7735 
   7736 	case R_PPC_TLS:
   7737 	  if ((tls_mask & TLS_TLS) != 0
   7738 	      && (tls_mask & TLS_TPREL) == 0)
   7739 	    {
   7740 	      bfd_vma insn;
   7741 
   7742 	      insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
   7743 	      insn = _bfd_elf_ppc_at_tls_transform (insn, 2);
   7744 	      if (insn == 0)
   7745 		abort ();
   7746 	      bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
   7747 	      r_type = R_PPC_TPREL16_LO;
   7748 	      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   7749 
   7750 	      /* Was PPC_TLS which sits on insn boundary, now
   7751 		 PPC_TPREL16_LO which is at low-order half-word.  */
   7752 	      rel->r_offset += d_offset;
   7753 	    }
   7754 	  break;
   7755 
   7756 	case R_PPC_GOT_TLSGD16_HI:
   7757 	case R_PPC_GOT_TLSGD16_HA:
   7758 	  tls_gd = TLS_TPRELGD;
   7759 	  if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
   7760 	    goto tls_gdld_hi;
   7761 	  break;
   7762 
   7763 	case R_PPC_GOT_TLSLD16_HI:
   7764 	case R_PPC_GOT_TLSLD16_HA:
   7765 	  if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
   7766 	    {
   7767 	    tls_gdld_hi:
   7768 	      if ((tls_mask & tls_gd) != 0)
   7769 		r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
   7770 			  + R_PPC_GOT_TPREL16);
   7771 	      else
   7772 		{
   7773 		  bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
   7774 		  rel->r_offset -= d_offset;
   7775 		  r_type = R_PPC_NONE;
   7776 		}
   7777 	      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   7778 	    }
   7779 	  break;
   7780 
   7781 	case R_PPC_GOT_TLSGD16:
   7782 	case R_PPC_GOT_TLSGD16_LO:
   7783 	  tls_gd = TLS_TPRELGD;
   7784 	  if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
   7785 	    goto tls_ldgd_opt;
   7786 	  break;
   7787 
   7788 	case R_PPC_GOT_TLSLD16:
   7789 	case R_PPC_GOT_TLSLD16_LO:
   7790 	  if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
   7791 	    {
   7792 	      unsigned int insn1, insn2;
   7793 	      bfd_vma offset;
   7794 
   7795 	    tls_ldgd_opt:
   7796 	      offset = (bfd_vma) -1;
   7797 	      /* If not using the newer R_PPC_TLSGD/LD to mark
   7798 		 __tls_get_addr calls, we must trust that the call
   7799 		 stays with its arg setup insns, ie. that the next
   7800 		 reloc is the __tls_get_addr call associated with
   7801 		 the current reloc.  Edit both insns.  */
   7802 	      if (input_section->has_tls_get_addr_call
   7803 		  && rel + 1 < relend
   7804 		  && branch_reloc_hash_match (input_bfd, rel + 1,
   7805 					      htab->tls_get_addr))
   7806 		offset = rel[1].r_offset;
   7807 	      if ((tls_mask & tls_gd) != 0)
   7808 		{
   7809 		  /* IE */
   7810 		  insn1 = bfd_get_32 (output_bfd,
   7811 				      contents + rel->r_offset - d_offset);
   7812 		  insn1 &= (1 << 26) - 1;
   7813 		  insn1 |= 32 << 26;	/* lwz */
   7814 		  if (offset != (bfd_vma) -1)
   7815 		    {
   7816 		      rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
   7817 		      insn2 = 0x7c631214;	/* add 3,3,2 */
   7818 		      bfd_put_32 (output_bfd, insn2, contents + offset);
   7819 		    }
   7820 		  r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
   7821 			    + R_PPC_GOT_TPREL16);
   7822 		  rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   7823 		}
   7824 	      else
   7825 		{
   7826 		  /* LE */
   7827 		  insn1 = 0x3c620000;	/* addis 3,2,0 */
   7828 		  if (tls_gd == 0)
   7829 		    {
   7830 		      /* Was an LD reloc.  */
   7831 		      for (r_symndx = 0;
   7832 			   r_symndx < symtab_hdr->sh_info;
   7833 			   r_symndx++)
   7834 			if (local_sections[r_symndx] == sec)
   7835 			  break;
   7836 		      if (r_symndx >= symtab_hdr->sh_info)
   7837 			r_symndx = STN_UNDEF;
   7838 		      rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
   7839 		      if (r_symndx != STN_UNDEF)
   7840 			rel->r_addend -= (local_syms[r_symndx].st_value
   7841 					  + sec->output_offset
   7842 					  + sec->output_section->vma);
   7843 		    }
   7844 		  r_type = R_PPC_TPREL16_HA;
   7845 		  rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   7846 		  if (offset != (bfd_vma) -1)
   7847 		    {
   7848 		      rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
   7849 		      rel[1].r_offset = offset + d_offset;
   7850 		      rel[1].r_addend = rel->r_addend;
   7851 		      insn2 = 0x38630000;	/* addi 3,3,0 */
   7852 		      bfd_put_32 (output_bfd, insn2, contents + offset);
   7853 		    }
   7854 		}
   7855 	      bfd_put_32 (output_bfd, insn1,
   7856 			  contents + rel->r_offset - d_offset);
   7857 	      if (tls_gd == 0)
   7858 		{
   7859 		  /* We changed the symbol on an LD reloc.  Start over
   7860 		     in order to get h, sym, sec etc. right.  */
   7861 		  rel--;
   7862 		  continue;
   7863 		}
   7864 	    }
   7865 	  break;
   7866 
   7867 	case R_PPC_TLSGD:
   7868 	  if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
   7869 	    {
   7870 	      unsigned int insn2;
   7871 	      bfd_vma offset = rel->r_offset;
   7872 
   7873 	      if ((tls_mask & TLS_TPRELGD) != 0)
   7874 		{
   7875 		  /* IE */
   7876 		  r_type = R_PPC_NONE;
   7877 		  insn2 = 0x7c631214;	/* add 3,3,2 */
   7878 		}
   7879 	      else
   7880 		{
   7881 		  /* LE */
   7882 		  r_type = R_PPC_TPREL16_LO;
   7883 		  rel->r_offset += d_offset;
   7884 		  insn2 = 0x38630000;	/* addi 3,3,0 */
   7885 		}
   7886 	      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   7887 	      bfd_put_32 (output_bfd, insn2, contents + offset);
   7888 	      /* Zap the reloc on the _tls_get_addr call too.  */
   7889 	      BFD_ASSERT (offset == rel[1].r_offset);
   7890 	      rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
   7891 	    }
   7892 	  break;
   7893 
   7894 	case R_PPC_TLSLD:
   7895 	  if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
   7896 	    {
   7897 	      unsigned int insn2;
   7898 
   7899 	      for (r_symndx = 0;
   7900 		   r_symndx < symtab_hdr->sh_info;
   7901 		   r_symndx++)
   7902 		if (local_sections[r_symndx] == sec)
   7903 		  break;
   7904 	      if (r_symndx >= symtab_hdr->sh_info)
   7905 		r_symndx = STN_UNDEF;
   7906 	      rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
   7907 	      if (r_symndx != STN_UNDEF)
   7908 		rel->r_addend -= (local_syms[r_symndx].st_value
   7909 				  + sec->output_offset
   7910 				  + sec->output_section->vma);
   7911 
   7912 	      rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
   7913 	      rel->r_offset += d_offset;
   7914 	      insn2 = 0x38630000;	/* addi 3,3,0 */
   7915 	      bfd_put_32 (output_bfd, insn2,
   7916 			  contents + rel->r_offset - d_offset);
   7917 	      /* Zap the reloc on the _tls_get_addr call too.  */
   7918 	      BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset);
   7919 	      rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
   7920 	      rel--;
   7921 	      continue;
   7922 	    }
   7923 	  break;
   7924 	}
   7925 
   7926       /* Handle other relocations that tweak non-addend part of insn.  */
   7927       branch_bit = 0;
   7928       switch (r_type)
   7929 	{
   7930 	default:
   7931 	  break;
   7932 
   7933 	  /* Branch taken prediction relocations.  */
   7934 	case R_PPC_ADDR14_BRTAKEN:
   7935 	case R_PPC_REL14_BRTAKEN:
   7936 	  branch_bit = BRANCH_PREDICT_BIT;
   7937 	  /* Fall thru */
   7938 
   7939 	  /* Branch not taken prediction relocations.  */
   7940 	case R_PPC_ADDR14_BRNTAKEN:
   7941 	case R_PPC_REL14_BRNTAKEN:
   7942 	  {
   7943 	    bfd_vma insn;
   7944 
   7945 	    insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
   7946 	    insn &= ~BRANCH_PREDICT_BIT;
   7947 	    insn |= branch_bit;
   7948 
   7949 	    from = (rel->r_offset
   7950 		    + input_section->output_offset
   7951 		    + input_section->output_section->vma);
   7952 
   7953 	    /* Invert 'y' bit if not the default.  */
   7954 	    if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
   7955 	      insn ^= BRANCH_PREDICT_BIT;
   7956 
   7957 	    bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
   7958 	    break;
   7959 	  }
   7960 	}
   7961 
   7962       ifunc = NULL;
   7963       if (!htab->is_vxworks)
   7964 	{
   7965 	  struct plt_entry *ent;
   7966 
   7967 	  if (h != NULL)
   7968 	    {
   7969 	      if (h->type == STT_GNU_IFUNC)
   7970 		ifunc = &h->plt.plist;
   7971 	    }
   7972 	  else if (local_got_offsets != NULL
   7973 		   && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
   7974 	    {
   7975 	      struct plt_entry **local_plt;
   7976 
   7977 	      local_plt = (struct plt_entry **) (local_got_offsets
   7978 						 + symtab_hdr->sh_info);
   7979 	      ifunc = local_plt + r_symndx;
   7980 	    }
   7981 
   7982 	  ent = NULL;
   7983 	  if (ifunc != NULL
   7984 	      && (!info->shared
   7985 		  || is_branch_reloc (r_type)))
   7986 	    {
   7987 	      addend = 0;
   7988 	      if (r_type == R_PPC_PLTREL24 && info->shared)
   7989 		addend = rel->r_addend;
   7990 	      ent = find_plt_ent (ifunc, got2, addend);
   7991 	    }
   7992 	  if (ent != NULL)
   7993 	    {
   7994 	      if (h == NULL && (ent->plt.offset & 1) == 0)
   7995 		{
   7996 		  Elf_Internal_Rela rela;
   7997 		  bfd_byte *loc;
   7998 
   7999 		  rela.r_offset = (htab->iplt->output_section->vma
   8000 				   + htab->iplt->output_offset
   8001 				   + ent->plt.offset);
   8002 		  rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
   8003 		  rela.r_addend = relocation;
   8004 		  loc = htab->reliplt->contents;
   8005 		  loc += (htab->reliplt->reloc_count++
   8006 			  * sizeof (Elf32_External_Rela));
   8007 		  bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   8008 
   8009 		  ent->plt.offset |= 1;
   8010 		}
   8011 	      if (h == NULL && (ent->glink_offset & 1) == 0)
   8012 		{
   8013 		  unsigned char *p = ((unsigned char *) htab->glink->contents
   8014 				      + ent->glink_offset);
   8015 		  write_glink_stub (ent, htab->iplt, p, info);
   8016 		  ent->glink_offset |= 1;
   8017 		}
   8018 
   8019 	      unresolved_reloc = FALSE;
   8020 	      if (htab->plt_type == PLT_NEW
   8021 		  || !htab->elf.dynamic_sections_created
   8022 		  || h == NULL
   8023 		  || h->dynindx == -1)
   8024 		relocation = (htab->glink->output_section->vma
   8025 			      + htab->glink->output_offset
   8026 			      + (ent->glink_offset & ~1));
   8027 	      else
   8028 		relocation = (htab->plt->output_section->vma
   8029 			      + htab->plt->output_offset
   8030 			      + ent->plt.offset);
   8031 	    }
   8032 	}
   8033 
   8034       addend = rel->r_addend;
   8035       tls_type = 0;
   8036       howto = NULL;
   8037       if (r_type < R_PPC_max)
   8038 	howto = ppc_elf_howto_table[r_type];
   8039       switch (r_type)
   8040 	{
   8041 	default:
   8042 	  info->callbacks->einfo
   8043 	    (_("%P: %B: unknown relocation type %d for symbol %s\n"),
   8044 	     input_bfd, (int) r_type, sym_name);
   8045 
   8046 	  bfd_set_error (bfd_error_bad_value);
   8047 	  ret = FALSE;
   8048 	  continue;
   8049 
   8050 	case R_PPC_NONE:
   8051 	case R_PPC_TLS:
   8052 	case R_PPC_TLSGD:
   8053 	case R_PPC_TLSLD:
   8054 	case R_PPC_EMB_MRKREF:
   8055 	case R_PPC_GNU_VTINHERIT:
   8056 	case R_PPC_GNU_VTENTRY:
   8057 	  continue;
   8058 
   8059 	  /* GOT16 relocations.  Like an ADDR16 using the symbol's
   8060 	     address in the GOT as relocation value instead of the
   8061 	     symbol's value itself.  Also, create a GOT entry for the
   8062 	     symbol and put the symbol value there.  */
   8063 	case R_PPC_GOT_TLSGD16:
   8064 	case R_PPC_GOT_TLSGD16_LO:
   8065 	case R_PPC_GOT_TLSGD16_HI:
   8066 	case R_PPC_GOT_TLSGD16_HA:
   8067 	  tls_type = TLS_TLS | TLS_GD;
   8068 	  goto dogot;
   8069 
   8070 	case R_PPC_GOT_TLSLD16:
   8071 	case R_PPC_GOT_TLSLD16_LO:
   8072 	case R_PPC_GOT_TLSLD16_HI:
   8073 	case R_PPC_GOT_TLSLD16_HA:
   8074 	  tls_type = TLS_TLS | TLS_LD;
   8075 	  goto dogot;
   8076 
   8077 	case R_PPC_GOT_TPREL16:
   8078 	case R_PPC_GOT_TPREL16_LO:
   8079 	case R_PPC_GOT_TPREL16_HI:
   8080 	case R_PPC_GOT_TPREL16_HA:
   8081 	  tls_type = TLS_TLS | TLS_TPREL;
   8082 	  goto dogot;
   8083 
   8084 	case R_PPC_GOT_DTPREL16:
   8085 	case R_PPC_GOT_DTPREL16_LO:
   8086 	case R_PPC_GOT_DTPREL16_HI:
   8087 	case R_PPC_GOT_DTPREL16_HA:
   8088 	  tls_type = TLS_TLS | TLS_DTPREL;
   8089 	  goto dogot;
   8090 
   8091 	case R_PPC_GOT16:
   8092 	case R_PPC_GOT16_LO:
   8093 	case R_PPC_GOT16_HI:
   8094 	case R_PPC_GOT16_HA:
   8095 	  tls_mask = 0;
   8096 	dogot:
   8097 	  {
   8098 	    /* Relocation is to the entry for this symbol in the global
   8099 	       offset table.  */
   8100 	    bfd_vma off;
   8101 	    bfd_vma *offp;
   8102 	    unsigned long indx;
   8103 
   8104 	    if (htab->got == NULL)
   8105 	      abort ();
   8106 
   8107 	    indx = 0;
   8108 	    if (tls_type == (TLS_TLS | TLS_LD)
   8109 		&& (h == NULL
   8110 		    || !h->def_dynamic))
   8111 	      offp = &htab->tlsld_got.offset;
   8112 	    else if (h != NULL)
   8113 	      {
   8114 		bfd_boolean dyn;
   8115 		dyn = htab->elf.dynamic_sections_created;
   8116 		if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
   8117 		    || (info->shared
   8118 			&& SYMBOL_REFERENCES_LOCAL (info, h)))
   8119 		  /* This is actually a static link, or it is a
   8120 		     -Bsymbolic link and the symbol is defined
   8121 		     locally, or the symbol was forced to be local
   8122 		     because of a version file.  */
   8123 		  ;
   8124 		else
   8125 		  {
   8126 		    BFD_ASSERT (h->dynindx != -1);
   8127 		    indx = h->dynindx;
   8128 		    unresolved_reloc = FALSE;
   8129 		  }
   8130 		offp = &h->got.offset;
   8131 	      }
   8132 	    else
   8133 	      {
   8134 		if (local_got_offsets == NULL)
   8135 		  abort ();
   8136 		offp = &local_got_offsets[r_symndx];
   8137 	      }
   8138 
   8139 	    /* The offset must always be a multiple of 4.  We use the
   8140 	       least significant bit to record whether we have already
   8141 	       processed this entry.  */
   8142 	    off = *offp;
   8143 	    if ((off & 1) != 0)
   8144 	      off &= ~1;
   8145 	    else
   8146 	      {
   8147 		unsigned int tls_m = (tls_mask
   8148 				      & (TLS_LD | TLS_GD | TLS_DTPREL
   8149 					 | TLS_TPREL | TLS_TPRELGD));
   8150 
   8151 		if (offp == &htab->tlsld_got.offset)
   8152 		  tls_m = TLS_LD;
   8153 		else if (h == NULL
   8154 			 || !h->def_dynamic)
   8155 		  tls_m &= ~TLS_LD;
   8156 
   8157 		/* We might have multiple got entries for this sym.
   8158 		   Initialize them all.  */
   8159 		do
   8160 		  {
   8161 		    int tls_ty = 0;
   8162 
   8163 		    if ((tls_m & TLS_LD) != 0)
   8164 		      {
   8165 			tls_ty = TLS_TLS | TLS_LD;
   8166 			tls_m &= ~TLS_LD;
   8167 		      }
   8168 		    else if ((tls_m & TLS_GD) != 0)
   8169 		      {
   8170 			tls_ty = TLS_TLS | TLS_GD;
   8171 			tls_m &= ~TLS_GD;
   8172 		      }
   8173 		    else if ((tls_m & TLS_DTPREL) != 0)
   8174 		      {
   8175 			tls_ty = TLS_TLS | TLS_DTPREL;
   8176 			tls_m &= ~TLS_DTPREL;
   8177 		      }
   8178 		    else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
   8179 		      {
   8180 			tls_ty = TLS_TLS | TLS_TPREL;
   8181 			tls_m = 0;
   8182 		      }
   8183 
   8184 		    /* Generate relocs for the dynamic linker.  */
   8185 		    if ((info->shared || indx != 0)
   8186 			&& (offp == &htab->tlsld_got.offset
   8187 			    || h == NULL
   8188 			    || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
   8189 			    || h->root.type != bfd_link_hash_undefweak))
   8190 		      {
   8191 			asection *rsec = htab->relgot;
   8192 			bfd_byte * loc;
   8193 
   8194 			if (ifunc != NULL)
   8195 			  rsec = htab->reliplt;
   8196 			outrel.r_offset = (htab->got->output_section->vma
   8197 					   + htab->got->output_offset
   8198 					   + off);
   8199 			outrel.r_addend = 0;
   8200 			if (tls_ty & (TLS_LD | TLS_GD))
   8201 			  {
   8202 			    outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
   8203 			    if (tls_ty == (TLS_TLS | TLS_GD))
   8204 			      {
   8205 				loc = rsec->contents;
   8206 				loc += (rsec->reloc_count++
   8207 					* sizeof (Elf32_External_Rela));
   8208 				bfd_elf32_swap_reloca_out (output_bfd,
   8209 							   &outrel, loc);
   8210 				outrel.r_offset += 4;
   8211 				outrel.r_info
   8212 				  = ELF32_R_INFO (indx, R_PPC_DTPREL32);
   8213 			      }
   8214 			  }
   8215 			else if (tls_ty == (TLS_TLS | TLS_DTPREL))
   8216 			  outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
   8217 			else if (tls_ty == (TLS_TLS | TLS_TPREL))
   8218 			  outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
   8219 			else if (indx != 0)
   8220 			  outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
   8221 			else if (ifunc != NULL)
   8222 			  outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
   8223 			else
   8224 			  outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
   8225 			if (indx == 0 && tls_ty != (TLS_TLS | TLS_LD))
   8226 			  {
   8227 			    outrel.r_addend += relocation;
   8228 			    if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
   8229 			      outrel.r_addend -= htab->elf.tls_sec->vma;
   8230 			  }
   8231 			loc = rsec->contents;
   8232 			loc += (rsec->reloc_count++
   8233 				* sizeof (Elf32_External_Rela));
   8234 			bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   8235 		      }
   8236 
   8237 		    /* Init the .got section contents if we're not
   8238 		       emitting a reloc.  */
   8239 		    else
   8240 		      {
   8241 			bfd_vma value = relocation;
   8242 
   8243 			if (tls_ty == (TLS_TLS | TLS_LD))
   8244 			  value = 1;
   8245 			else if (tls_ty != 0)
   8246 			  {
   8247 			    value -= htab->elf.tls_sec->vma + DTP_OFFSET;
   8248 			    if (tls_ty == (TLS_TLS | TLS_TPREL))
   8249 			      value += DTP_OFFSET - TP_OFFSET;
   8250 
   8251 			    if (tls_ty == (TLS_TLS | TLS_GD))
   8252 			      {
   8253 				bfd_put_32 (output_bfd, value,
   8254 					    htab->got->contents + off + 4);
   8255 				value = 1;
   8256 			      }
   8257 			  }
   8258 			bfd_put_32 (output_bfd, value,
   8259 				    htab->got->contents + off);
   8260 		      }
   8261 
   8262 		    off += 4;
   8263 		    if (tls_ty & (TLS_LD | TLS_GD))
   8264 		      off += 4;
   8265 		  }
   8266 		while (tls_m != 0);
   8267 
   8268 		off = *offp;
   8269 		*offp = off | 1;
   8270 	      }
   8271 
   8272 	    if (off >= (bfd_vma) -2)
   8273 	      abort ();
   8274 
   8275 	    if ((tls_type & TLS_TLS) != 0)
   8276 	      {
   8277 		if (tls_type != (TLS_TLS | TLS_LD))
   8278 		  {
   8279 		    if ((tls_mask & TLS_LD) != 0
   8280 			&& !(h == NULL
   8281 			     || !h->def_dynamic))
   8282 		      off += 8;
   8283 		    if (tls_type != (TLS_TLS | TLS_GD))
   8284 		      {
   8285 			if ((tls_mask & TLS_GD) != 0)
   8286 			  off += 8;
   8287 			if (tls_type != (TLS_TLS | TLS_DTPREL))
   8288 			  {
   8289 			    if ((tls_mask & TLS_DTPREL) != 0)
   8290 			      off += 4;
   8291 			  }
   8292 		      }
   8293 		  }
   8294 	      }
   8295 
   8296 	    relocation = (htab->got->output_section->vma
   8297 			  + htab->got->output_offset
   8298 			  + off
   8299 			  - SYM_VAL (htab->elf.hgot));
   8300 
   8301 	    /* Addends on got relocations don't make much sense.
   8302 	       x+off@got is actually x@got+off, and since the got is
   8303 	       generated by a hash table traversal, the value in the
   8304 	       got at entry m+n bears little relation to the entry m.  */
   8305 	    if (addend != 0)
   8306 	      info->callbacks->einfo
   8307 		(_("%P: %H: non-zero addend on %s reloc against `%s'\n"),
   8308 		 input_bfd, input_section, rel->r_offset,
   8309 		 howto->name,
   8310 		 sym_name);
   8311 	  }
   8312 	  break;
   8313 
   8314 	  /* Relocations that need no special processing.  */
   8315 	case R_PPC_LOCAL24PC:
   8316 	  /* It makes no sense to point a local relocation
   8317 	     at a symbol not in this object.  */
   8318 	  if (unresolved_reloc)
   8319 	    {
   8320 	      if (! (*info->callbacks->undefined_symbol) (info,
   8321 							  h->root.root.string,
   8322 							  input_bfd,
   8323 							  input_section,
   8324 							  rel->r_offset,
   8325 							  TRUE))
   8326 		return FALSE;
   8327 	      continue;
   8328 	    }
   8329 	  break;
   8330 
   8331 	case R_PPC_DTPREL16:
   8332 	case R_PPC_DTPREL16_LO:
   8333 	case R_PPC_DTPREL16_HI:
   8334 	case R_PPC_DTPREL16_HA:
   8335 	  addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
   8336 	  break;
   8337 
   8338 	  /* Relocations that may need to be propagated if this is a shared
   8339 	     object.  */
   8340 	case R_PPC_TPREL16:
   8341 	case R_PPC_TPREL16_LO:
   8342 	case R_PPC_TPREL16_HI:
   8343 	case R_PPC_TPREL16_HA:
   8344 	  if (h != NULL
   8345 	      && h->root.type == bfd_link_hash_undefweak
   8346 	      && h->dynindx == -1)
   8347 	    {
   8348 	      /* Make this relocation against an undefined weak symbol
   8349 		 resolve to zero.  This is really just a tweak, since
   8350 		 code using weak externs ought to check that they are
   8351 		 defined before using them.  */
   8352 	      bfd_byte *p = contents + rel->r_offset - d_offset;
   8353 	      unsigned int insn = bfd_get_32 (output_bfd, p);
   8354 	      insn = _bfd_elf_ppc_at_tprel_transform (insn, 2);
   8355 	      if (insn != 0)
   8356 		bfd_put_32 (output_bfd, insn, p);
   8357 	      break;
   8358 	    }
   8359 	  addend -= htab->elf.tls_sec->vma + TP_OFFSET;
   8360 	  /* The TPREL16 relocs shouldn't really be used in shared
   8361 	     libs as they will result in DT_TEXTREL being set, but
   8362 	     support them anyway.  */
   8363 	  goto dodyn;
   8364 
   8365 	case R_PPC_TPREL32:
   8366 	  addend -= htab->elf.tls_sec->vma + TP_OFFSET;
   8367 	  goto dodyn;
   8368 
   8369 	case R_PPC_DTPREL32:
   8370 	  addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
   8371 	  goto dodyn;
   8372 
   8373 	case R_PPC_DTPMOD32:
   8374 	  relocation = 1;
   8375 	  addend = 0;
   8376 	  goto dodyn;
   8377 
   8378 	case R_PPC_REL16:
   8379 	case R_PPC_REL16_LO:
   8380 	case R_PPC_REL16_HI:
   8381 	case R_PPC_REL16_HA:
   8382 	  break;
   8383 
   8384 	case R_PPC_REL32:
   8385 	  if (h == NULL || h == htab->elf.hgot)
   8386 	    break;
   8387 	  /* fall through */
   8388 
   8389 	case R_PPC_ADDR32:
   8390 	case R_PPC_ADDR16:
   8391 	case R_PPC_ADDR16_LO:
   8392 	case R_PPC_ADDR16_HI:
   8393 	case R_PPC_ADDR16_HA:
   8394 	case R_PPC_UADDR32:
   8395 	case R_PPC_UADDR16:
   8396 	  goto dodyn;
   8397 
   8398 	case R_PPC_VLE_REL8:
   8399 	case R_PPC_VLE_REL15:
   8400 	case R_PPC_VLE_REL24:
   8401 	case R_PPC_REL24:
   8402 	case R_PPC_REL14:
   8403 	case R_PPC_REL14_BRTAKEN:
   8404 	case R_PPC_REL14_BRNTAKEN:
   8405 	  /* If these relocations are not to a named symbol, they can be
   8406 	     handled right here, no need to bother the dynamic linker.  */
   8407 	  if (SYMBOL_CALLS_LOCAL (info, h)
   8408 	      || h == htab->elf.hgot)
   8409 	    break;
   8410 	  /* fall through */
   8411 
   8412 	case R_PPC_ADDR24:
   8413 	case R_PPC_ADDR14:
   8414 	case R_PPC_ADDR14_BRTAKEN:
   8415 	case R_PPC_ADDR14_BRNTAKEN:
   8416 	  if (h != NULL && !info->shared)
   8417 	    break;
   8418 	  /* fall through */
   8419 
   8420 	dodyn:
   8421 	  if ((input_section->flags & SEC_ALLOC) == 0
   8422 	      || is_vxworks_tls)
   8423 	    break;
   8424 
   8425 	  if ((info->shared
   8426 	       && !(h != NULL
   8427 		    && ((h->root.type == bfd_link_hash_undefined
   8428 			 && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
   8429 			     || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
   8430 			|| (h->root.type == bfd_link_hash_undefweak
   8431 			    && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)))
   8432 	       && (must_be_dyn_reloc (info, r_type)
   8433 		   || !SYMBOL_CALLS_LOCAL (info, h)))
   8434 	      || (ELIMINATE_COPY_RELOCS
   8435 		  && !info->shared
   8436 		  && h != NULL
   8437 		  && h->dynindx != -1
   8438 		  && !h->non_got_ref
   8439 		  && !h->def_regular))
   8440 	    {
   8441 	      int skip;
   8442 	      bfd_byte *loc;
   8443 	      asection *sreloc;
   8444 #ifdef DEBUG
   8445 	      fprintf (stderr, "ppc_elf_relocate_section needs to "
   8446 		       "create relocation for %s\n",
   8447 		       (h && h->root.root.string
   8448 			? h->root.root.string : "<unknown>"));
   8449 #endif
   8450 
   8451 	      /* When generating a shared object, these relocations
   8452 		 are copied into the output file to be resolved at run
   8453 		 time.  */
   8454 	      sreloc = elf_section_data (input_section)->sreloc;
   8455 	      if (ifunc)
   8456 		sreloc = htab->reliplt;
   8457 	      if (sreloc == NULL)
   8458 		return FALSE;
   8459 
   8460 	      skip = 0;
   8461 	      outrel.r_offset = _bfd_elf_section_offset (output_bfd, info,
   8462 							 input_section,
   8463 							 rel->r_offset);
   8464 	      if (outrel.r_offset == (bfd_vma) -1
   8465 		  || outrel.r_offset == (bfd_vma) -2)
   8466 		skip = (int) outrel.r_offset;
   8467 	      outrel.r_offset += (input_section->output_section->vma
   8468 				  + input_section->output_offset);
   8469 
   8470 	      if (skip)
   8471 		memset (&outrel, 0, sizeof outrel);
   8472 	      else if ((h != NULL
   8473 			&& (h->root.type == bfd_link_hash_undefined
   8474 			    || h->root.type == bfd_link_hash_undefweak))
   8475 		       || !SYMBOL_REFERENCES_LOCAL (info, h))
   8476 		{
   8477 		  BFD_ASSERT (h->dynindx != -1);
   8478 		  unresolved_reloc = FALSE;
   8479 		  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
   8480 		  outrel.r_addend = rel->r_addend;
   8481 		}
   8482 	      else
   8483 		{
   8484 		  outrel.r_addend = relocation + rel->r_addend;
   8485 
   8486 		  if (r_type != R_PPC_ADDR32)
   8487 		    {
   8488 		      long indx = 0;
   8489 
   8490 		      if (ifunc != NULL)
   8491 			{
   8492 			  /* If we get here when building a static
   8493 			     executable, then the libc startup function
   8494 			     responsible for applying indirect function
   8495 			     relocations is going to complain about
   8496 			     the reloc type.
   8497 			     If we get here when building a dynamic
   8498 			     executable, it will be because we have
   8499 			     a text relocation.  The dynamic loader
   8500 			     will set the text segment writable and
   8501 			     non-executable to apply text relocations.
   8502 			     So we'll segfault when trying to run the
   8503 			     indirection function to resolve the reloc.  */
   8504 			  info->callbacks->einfo
   8505 			    (_("%P: %H: relocation %s for indirect "
   8506 			       "function %s unsupported\n"),
   8507 			     input_bfd, input_section, rel->r_offset,
   8508 			     howto->name,
   8509 			     sym_name);
   8510 			  ret = FALSE;
   8511 			}
   8512 		      else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec))
   8513 			;
   8514 		      else if (sec == NULL || sec->owner == NULL)
   8515 			{
   8516 			  bfd_set_error (bfd_error_bad_value);
   8517 			  ret = FALSE;
   8518 			}
   8519 		      else
   8520 			{
   8521 			  asection *osec;
   8522 
   8523 			  /* We are turning this relocation into one
   8524 			     against a section symbol.  It would be
   8525 			     proper to subtract the symbol's value,
   8526 			     osec->vma, from the emitted reloc addend,
   8527 			     but ld.so expects buggy relocs.
   8528 			     FIXME: Why not always use a zero index?  */
   8529 			  osec = sec->output_section;
   8530 			  indx = elf_section_data (osec)->dynindx;
   8531 			  if (indx == 0)
   8532 			    {
   8533 			      osec = htab->elf.text_index_section;
   8534 			      indx = elf_section_data (osec)->dynindx;
   8535 			    }
   8536 			  BFD_ASSERT (indx != 0);
   8537 #ifdef DEBUG
   8538 			  if (indx == 0)
   8539 			    printf ("indx=%ld section=%s flags=%08x name=%s\n",
   8540 				    indx, osec->name, osec->flags,
   8541 				    h->root.root.string);
   8542 #endif
   8543 			}
   8544 
   8545 		      outrel.r_info = ELF32_R_INFO (indx, r_type);
   8546 		    }
   8547 		  else if (ifunc != NULL)
   8548 		    outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
   8549 		  else
   8550 		    outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
   8551 		}
   8552 
   8553 	      loc = sreloc->contents;
   8554 	      loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
   8555 	      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   8556 
   8557 	      if (skip == -1)
   8558 		continue;
   8559 
   8560 	      /* This reloc will be computed at runtime.  We clear the memory
   8561 		 so that it contains predictable value.  */
   8562 	      if (! skip
   8563 		  && ((input_section->flags & SEC_ALLOC) != 0
   8564 		      || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
   8565 		{
   8566 		  relocation = howto->pc_relative ? outrel.r_offset : 0;
   8567 		  addend = 0;
   8568 		  break;
   8569 		}
   8570 	    }
   8571 	  break;
   8572 
   8573 	case R_PPC_RELAX_PLT:
   8574 	case R_PPC_RELAX_PLTREL24:
   8575 	  if (h != NULL)
   8576 	    {
   8577 	      struct plt_entry *ent;
   8578 	      bfd_vma got2_addend = 0;
   8579 
   8580 	      if (r_type == R_PPC_RELAX_PLTREL24)
   8581 		{
   8582 		  if (info->shared)
   8583 		    got2_addend = addend;
   8584 		  addend = 0;
   8585 		}
   8586 	      ent = find_plt_ent (&h->plt.plist, got2, got2_addend);
   8587 	      if (htab->plt_type == PLT_NEW)
   8588 		relocation = (htab->glink->output_section->vma
   8589 			      + htab->glink->output_offset
   8590 			      + ent->glink_offset);
   8591 	      else
   8592 		relocation = (htab->plt->output_section->vma
   8593 			      + htab->plt->output_offset
   8594 			      + ent->plt.offset);
   8595 	    }
   8596 	  /* Fall thru */
   8597 
   8598 	case R_PPC_RELAX:
   8599 	  {
   8600 	    const int *stub;
   8601 	    size_t size;
   8602 	    size_t insn_offset = rel->r_offset;
   8603 	    unsigned int insn;
   8604 
   8605 	    if (info->shared)
   8606 	      {
   8607 		relocation -= (input_section->output_section->vma
   8608 			       + input_section->output_offset
   8609 			       + rel->r_offset - 4);
   8610 		stub = shared_stub_entry;
   8611 		bfd_put_32 (output_bfd, stub[0], contents + insn_offset - 12);
   8612 		bfd_put_32 (output_bfd, stub[1], contents + insn_offset - 8);
   8613 		bfd_put_32 (output_bfd, stub[2], contents + insn_offset - 4);
   8614 		stub += 3;
   8615 		size = ARRAY_SIZE (shared_stub_entry) - 3;
   8616 	      }
   8617 	    else
   8618 	      {
   8619 		stub = stub_entry;
   8620 		size = ARRAY_SIZE (stub_entry);
   8621 	      }
   8622 
   8623 	    relocation += addend;
   8624 	    if (info->relocatable)
   8625 	      relocation = 0;
   8626 
   8627 	    /* First insn is HA, second is LO.  */
   8628 	    insn = *stub++;
   8629 	    insn |= ((relocation + 0x8000) >> 16) & 0xffff;
   8630 	    bfd_put_32 (output_bfd, insn, contents + insn_offset);
   8631 	    insn_offset += 4;
   8632 
   8633 	    insn = *stub++;
   8634 	    insn |= relocation & 0xffff;
   8635 	    bfd_put_32 (output_bfd, insn, contents + insn_offset);
   8636 	    insn_offset += 4;
   8637 	    size -= 2;
   8638 
   8639 	    while (size != 0)
   8640 	      {
   8641 		insn = *stub++;
   8642 		--size;
   8643 		bfd_put_32 (output_bfd, insn, contents + insn_offset);
   8644 		insn_offset += 4;
   8645 	      }
   8646 
   8647 	    /* Rewrite the reloc and convert one of the trailing nop
   8648 	       relocs to describe this relocation.  */
   8649 	    BFD_ASSERT (ELF32_R_TYPE (relend[-1].r_info) == R_PPC_NONE);
   8650 	    /* The relocs are at the bottom 2 bytes */
   8651 	    rel[0].r_offset += d_offset;
   8652 	    memmove (rel + 1, rel, (relend - rel - 1) * sizeof (*rel));
   8653 	    rel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA);
   8654 	    rel[1].r_offset += 4;
   8655 	    rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO);
   8656 	    rel++;
   8657 	  }
   8658 	  continue;
   8659 
   8660 	  /* Indirect .sdata relocation.  */
   8661 	case R_PPC_EMB_SDAI16:
   8662 	  BFD_ASSERT (htab->sdata[0].section != NULL);
   8663 	  if (!is_static_defined (htab->sdata[0].sym))
   8664 	    {
   8665 	      unresolved_reloc = TRUE;
   8666 	      break;
   8667 	    }
   8668 	  relocation
   8669 	    = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0],
   8670 						 h, relocation, rel);
   8671 	  addend = 0;
   8672 	  break;
   8673 
   8674 	  /* Indirect .sdata2 relocation.  */
   8675 	case R_PPC_EMB_SDA2I16:
   8676 	  BFD_ASSERT (htab->sdata[1].section != NULL);
   8677 	  if (!is_static_defined (htab->sdata[1].sym))
   8678 	    {
   8679 	      unresolved_reloc = TRUE;
   8680 	      break;
   8681 	    }
   8682 	  relocation
   8683 	    = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1],
   8684 						 h, relocation, rel);
   8685 	  addend = 0;
   8686 	  break;
   8687 
   8688 	  /* Handle the TOC16 reloc.  We want to use the offset within the .got
   8689 	     section, not the actual VMA.  This is appropriate when generating
   8690 	     an embedded ELF object, for which the .got section acts like the
   8691 	     AIX .toc section.  */
   8692 	case R_PPC_TOC16:			/* phony GOT16 relocations */
   8693 	  if (sec == NULL || sec->output_section == NULL)
   8694 	    {
   8695 	      unresolved_reloc = TRUE;
   8696 	      break;
   8697 	    }
   8698 	  BFD_ASSERT (strcmp (bfd_get_section_name (sec->owner, sec),
   8699 			      ".got") == 0
   8700 		      || strcmp (bfd_get_section_name (sec->owner, sec),
   8701 				 ".cgot") == 0);
   8702 
   8703 	  addend -= sec->output_section->vma + sec->output_offset + 0x8000;
   8704 	  break;
   8705 
   8706 	case R_PPC_PLTREL24:
   8707 	  if (h != NULL && ifunc == NULL)
   8708 	    {
   8709 	      struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2,
   8710 						    info->shared ? addend : 0);
   8711 	      if (ent == NULL
   8712 		  || htab->plt == NULL)
   8713 		{
   8714 		  /* We didn't make a PLT entry for this symbol.  This
   8715 		     happens when statically linking PIC code, or when
   8716 		     using -Bsymbolic.  */
   8717 		}
   8718 	      else
   8719 		{
   8720 		  /* Relocation is to the entry for this symbol in the
   8721 		     procedure linkage table.  */
   8722 		  unresolved_reloc = FALSE;
   8723 		  if (htab->plt_type == PLT_NEW)
   8724 		    relocation = (htab->glink->output_section->vma
   8725 				  + htab->glink->output_offset
   8726 				  + ent->glink_offset);
   8727 		  else
   8728 		    relocation = (htab->plt->output_section->vma
   8729 				  + htab->plt->output_offset
   8730 				  + ent->plt.offset);
   8731 		}
   8732 	    }
   8733 
   8734 	  /* R_PPC_PLTREL24 is rather special.  If non-zero, the
   8735 	     addend specifies the GOT pointer offset within .got2.
   8736 	     Don't apply it to the relocation field.  */
   8737 	  addend = 0;
   8738 	  break;
   8739 
   8740 	  /* Relocate against _SDA_BASE_.  */
   8741 	case R_PPC_SDAREL16:
   8742 	  {
   8743 	    const char *name;
   8744 	    struct elf_link_hash_entry *sda = htab->sdata[0].sym;
   8745 
   8746 	    if (sec == NULL
   8747 		|| sec->output_section == NULL
   8748 		|| !is_static_defined (sda))
   8749 	      {
   8750 		unresolved_reloc = TRUE;
   8751 		break;
   8752 	      }
   8753 	    addend -= SYM_VAL (sda);
   8754 
   8755 	    name = bfd_get_section_name (output_bfd, sec->output_section);
   8756 	    if (!(strcmp (name, ".sdata") == 0
   8757 		  || strcmp (name, ".sbss") == 0))
   8758 	      {
   8759 		info->callbacks->einfo
   8760 		  (_("%P: %B: the target (%s) of a %s relocation is "
   8761 		     "in the wrong output section (%s)\n"),
   8762 		   input_bfd,
   8763 		   sym_name,
   8764 		   howto->name,
   8765 		   name);
   8766 	      }
   8767 	  }
   8768 	  break;
   8769 
   8770 	  /* Relocate against _SDA2_BASE_.  */
   8771 	case R_PPC_EMB_SDA2REL:
   8772 	  {
   8773 	    const char *name;
   8774 	    struct elf_link_hash_entry *sda = htab->sdata[1].sym;
   8775 
   8776 	    if (sec == NULL
   8777 		|| sec->output_section == NULL
   8778 		|| !is_static_defined (sda))
   8779 	      {
   8780 		unresolved_reloc = TRUE;
   8781 		break;
   8782 	      }
   8783 	    addend -= SYM_VAL (sda);
   8784 
   8785 	    name = bfd_get_section_name (output_bfd, sec->output_section);
   8786 	    if (!(strcmp (name, ".sdata2") == 0
   8787 		  || strcmp (name, ".sbss2") == 0))
   8788 	      {
   8789 		info->callbacks->einfo
   8790 		  (_("%P: %B: the target (%s) of a %s relocation is "
   8791 		     "in the wrong output section (%s)\n"),
   8792 		   input_bfd,
   8793 		   sym_name,
   8794 		   howto->name,
   8795 		   name);
   8796 	      }
   8797 	  }
   8798 	  break;
   8799 
   8800 	case R_PPC_VLE_LO16A:
   8801 	  relocation = relocation + addend;
   8802 	  ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   8803 			       relocation, split16a_type);
   8804 	  continue;
   8805 
   8806 	case R_PPC_VLE_LO16D:
   8807 	  relocation = relocation + addend;
   8808 	  ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   8809 			       relocation, split16d_type);
   8810 	  continue;
   8811 
   8812 	case R_PPC_VLE_HI16A:
   8813 	  relocation = (relocation + addend) >> 16;
   8814 	  ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   8815 			       relocation, split16a_type);
   8816 	  continue;
   8817 
   8818 	case R_PPC_VLE_HI16D:
   8819 	  relocation = (relocation + addend) >> 16;
   8820 	  ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   8821 			       relocation, split16d_type);
   8822 	  continue;
   8823 
   8824 	case R_PPC_VLE_HA16A:
   8825 	  relocation = (relocation + addend + 0x8000) >> 16;
   8826 	  ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   8827 			       relocation, split16a_type);
   8828 	  continue;
   8829 
   8830 	case R_PPC_VLE_HA16D:
   8831 	  relocation = (relocation + addend + 0x8000) >> 16;
   8832 	  ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   8833 			       relocation, split16d_type);
   8834 	  continue;
   8835 
   8836 	  /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0.  */
   8837 	case R_PPC_EMB_SDA21:
   8838 	case R_PPC_VLE_SDA21:
   8839 	case R_PPC_EMB_RELSDA:
   8840 	case R_PPC_VLE_SDA21_LO:
   8841 	  {
   8842 	    const char *name;
   8843 	    int reg;
   8844 	    unsigned int insn;
   8845 	    struct elf_link_hash_entry *sda = NULL;
   8846 
   8847 	    if (sec == NULL || sec->output_section == NULL)
   8848 	      {
   8849 		unresolved_reloc = TRUE;
   8850 		break;
   8851 	      }
   8852 
   8853 	    name = bfd_get_section_name (output_bfd, sec->output_section);
   8854 	    if (strcmp (name, ".sdata") == 0
   8855 		|| strcmp (name, ".sbss") == 0)
   8856 	      {
   8857 		reg = 13;
   8858 		sda = htab->sdata[0].sym;
   8859 	      }
   8860 	    else if (strcmp (name, ".sdata2") == 0
   8861 		     || strcmp (name, ".sbss2") == 0)
   8862 	      {
   8863 		reg = 2;
   8864 		sda = htab->sdata[1].sym;
   8865 	      }
   8866 	    else if (strcmp (name, ".PPC.EMB.sdata0") == 0
   8867 		     || strcmp (name, ".PPC.EMB.sbss0") == 0)
   8868 	      {
   8869 		reg = 0;
   8870 	      }
   8871 	    else
   8872 	      {
   8873 		info->callbacks->einfo
   8874 		  (_("%P: %B: the target (%s) of a %s relocation is "
   8875 		     "in the wrong output section (%s)\n"),
   8876 		   input_bfd,
   8877 		   sym_name,
   8878 		   howto->name,
   8879 		   name);
   8880 
   8881 		bfd_set_error (bfd_error_bad_value);
   8882 		ret = FALSE;
   8883 		continue;
   8884 	      }
   8885 
   8886 	    if (sda != NULL)
   8887 	      {
   8888 		if (!is_static_defined (sda))
   8889 		  {
   8890 		    unresolved_reloc = TRUE;
   8891 		    break;
   8892 		  }
   8893 		addend -= SYM_VAL (sda);
   8894 	      }
   8895 
   8896 	    insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
   8897 	    if (reg == 0
   8898 		&& (r_type == R_PPC_VLE_SDA21
   8899 		    || r_type == R_PPC_VLE_SDA21_LO))
   8900 	      {
   8901 		relocation = relocation + addend;
   8902 		addend = 0;
   8903 
   8904 		/* Force e_li insn, keeping RT from original insn.  */
   8905 		insn &= 0x1f << 21;
   8906 		insn |= 28u << 26;
   8907 
   8908 		/* We have an li20 field, bits 17..20, 11..15, 21..31.  */
   8909 		/* Top 4 bits of value to 17..20.  */
   8910 		insn |= (relocation & 0xf0000) >> 5;
   8911 		/* Next 5 bits of the value to 11..15.  */
   8912 		insn |= (relocation & 0xf800) << 5;
   8913 		/* And the final 11 bits of the value to bits 21 to 31.  */
   8914 		insn |= relocation & 0x7ff;
   8915 
   8916 		bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
   8917 
   8918 		if (r_type == R_PPC_VLE_SDA21
   8919 		    && ((relocation + 0x80000) & 0xffffffff) > 0x100000)
   8920 		  goto overflow;
   8921 		continue;
   8922 	      }
   8923 	    else if (r_type == R_PPC_EMB_SDA21
   8924 		     || r_type == R_PPC_VLE_SDA21
   8925 		     || r_type == R_PPC_VLE_SDA21_LO)
   8926 	      {
   8927 		/* Fill in register field.  */
   8928 		insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
   8929 	      }
   8930 	    bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
   8931 	  }
   8932 	  break;
   8933 
   8934 	case R_PPC_VLE_SDAREL_LO16A:
   8935 	case R_PPC_VLE_SDAREL_LO16D:
   8936 	case R_PPC_VLE_SDAREL_HI16A:
   8937 	case R_PPC_VLE_SDAREL_HI16D:
   8938 	case R_PPC_VLE_SDAREL_HA16A:
   8939 	case R_PPC_VLE_SDAREL_HA16D:
   8940 	  {
   8941 	    bfd_vma value;
   8942 	    const char *name;
   8943 	    //int reg;
   8944 	    struct elf_link_hash_entry *sda = NULL;
   8945 
   8946 	    if (sec == NULL || sec->output_section == NULL)
   8947 	      {
   8948 		unresolved_reloc = TRUE;
   8949 		break;
   8950 	      }
   8951 
   8952 	    name = bfd_get_section_name (output_bfd, sec->output_section);
   8953 	    if (strcmp (name, ".sdata") == 0
   8954 		|| strcmp (name, ".sbss") == 0)
   8955 	      {
   8956 		//reg = 13;
   8957 		sda = htab->sdata[0].sym;
   8958 	      }
   8959 	    else if (strcmp (name, ".sdata2") == 0
   8960 		     || strcmp (name, ".sbss2") == 0)
   8961 	      {
   8962 		//reg = 2;
   8963 		sda = htab->sdata[1].sym;
   8964 	      }
   8965 	    else
   8966 	      {
   8967 		(*_bfd_error_handler)
   8968 		  (_("%B: the target (%s) of a %s relocation is "
   8969 		     "in the wrong output section (%s)"),
   8970 		   input_bfd,
   8971 		   sym_name,
   8972 		   howto->name,
   8973 		   name);
   8974 
   8975 		bfd_set_error (bfd_error_bad_value);
   8976 		ret = FALSE;
   8977 		continue;
   8978 	      }
   8979 
   8980 	    if (sda != NULL)
   8981 	      {
   8982 		if (!is_static_defined (sda))
   8983 		  {
   8984 		    unresolved_reloc = TRUE;
   8985 		    break;
   8986 		  }
   8987 	      }
   8988 
   8989 	    value = (sda->root.u.def.section->output_section->vma
   8990 		     + sda->root.u.def.section->output_offset
   8991 		     + addend);
   8992 
   8993 	    if (r_type == R_PPC_VLE_SDAREL_LO16A)
   8994 	      ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   8995 				   value, split16a_type);
   8996 	    else if (r_type == R_PPC_VLE_SDAREL_LO16D)
   8997 	      ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   8998 				   value, split16d_type);
   8999 	    else if (r_type == R_PPC_VLE_SDAREL_HI16A)
   9000 	      {
   9001 		value = value >> 16;
   9002 		ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   9003 				     value, split16a_type);
   9004 	      }
   9005 	    else if (r_type == R_PPC_VLE_SDAREL_HI16D)
   9006 	      {
   9007 		value = value >> 16;
   9008 		ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   9009 				     value, split16d_type);
   9010 	      }
   9011 	    else if (r_type == R_PPC_VLE_SDAREL_HA16A)
   9012 	      {
   9013 		value = (value + 0x8000) >> 16;
   9014 		ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   9015 				     value, split16a_type);
   9016 	      }
   9017 	    else if (r_type == R_PPC_VLE_SDAREL_HA16D)
   9018 	      {
   9019 		value = (value + 0x8000) >> 16;
   9020 		ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
   9021 				     value, split16d_type);
   9022 	      }
   9023 	  }
   9024 	  continue;
   9025 
   9026 	  /* Relocate against the beginning of the section.  */
   9027 	case R_PPC_SECTOFF:
   9028 	case R_PPC_SECTOFF_LO:
   9029 	case R_PPC_SECTOFF_HI:
   9030 	case R_PPC_SECTOFF_HA:
   9031 	  if (sec == NULL || sec->output_section == NULL)
   9032 	    {
   9033 	      unresolved_reloc = TRUE;
   9034 	      break;
   9035 	    }
   9036 	  addend -= sec->output_section->vma;
   9037 	  break;
   9038 
   9039 	  /* Negative relocations.  */
   9040 	case R_PPC_EMB_NADDR32:
   9041 	case R_PPC_EMB_NADDR16:
   9042 	case R_PPC_EMB_NADDR16_LO:
   9043 	case R_PPC_EMB_NADDR16_HI:
   9044 	case R_PPC_EMB_NADDR16_HA:
   9045 	  addend -= 2 * relocation;
   9046 	  break;
   9047 
   9048 	case R_PPC_COPY:
   9049 	case R_PPC_GLOB_DAT:
   9050 	case R_PPC_JMP_SLOT:
   9051 	case R_PPC_RELATIVE:
   9052 	case R_PPC_IRELATIVE:
   9053 	case R_PPC_PLT32:
   9054 	case R_PPC_PLTREL32:
   9055 	case R_PPC_PLT16_LO:
   9056 	case R_PPC_PLT16_HI:
   9057 	case R_PPC_PLT16_HA:
   9058 	case R_PPC_ADDR30:
   9059 	case R_PPC_EMB_RELSEC16:
   9060 	case R_PPC_EMB_RELST_LO:
   9061 	case R_PPC_EMB_RELST_HI:
   9062 	case R_PPC_EMB_RELST_HA:
   9063 	case R_PPC_EMB_BIT_FLD:
   9064 	  info->callbacks->einfo
   9065 	    (_("%P: %B: relocation %s is not yet supported for symbol %s\n"),
   9066 	     input_bfd,
   9067 	     howto->name,
   9068 	     sym_name);
   9069 
   9070 	  bfd_set_error (bfd_error_invalid_operation);
   9071 	  ret = FALSE;
   9072 	  continue;
   9073 	}
   9074 
   9075       /* Do any further special processing.  */
   9076       switch (r_type)
   9077 	{
   9078 	default:
   9079 	  break;
   9080 
   9081 	case R_PPC_ADDR16_HA:
   9082 	case R_PPC_REL16_HA:
   9083 	case R_PPC_SECTOFF_HA:
   9084 	case R_PPC_TPREL16_HA:
   9085 	case R_PPC_DTPREL16_HA:
   9086 	case R_PPC_EMB_NADDR16_HA:
   9087 	case R_PPC_EMB_RELST_HA:
   9088 	  /* It's just possible that this symbol is a weak symbol
   9089 	     that's not actually defined anywhere.  In that case,
   9090 	     'sec' would be NULL, and we should leave the symbol
   9091 	     alone (it will be set to zero elsewhere in the link).  */
   9092 	  if (sec == NULL)
   9093 	    break;
   9094 	  /* Fall thru */
   9095 
   9096 	case R_PPC_PLT16_HA:
   9097 	case R_PPC_GOT16_HA:
   9098 	case R_PPC_GOT_TLSGD16_HA:
   9099 	case R_PPC_GOT_TLSLD16_HA:
   9100 	case R_PPC_GOT_TPREL16_HA:
   9101 	case R_PPC_GOT_DTPREL16_HA:
   9102 	  /* Add 0x10000 if sign bit in 0:15 is set.
   9103 	     Bits 0:15 are not used.  */
   9104 	  addend += 0x8000;
   9105 	  break;
   9106 
   9107 	case R_PPC_ADDR16:
   9108 	case R_PPC_ADDR16_LO:
   9109 	case R_PPC_GOT16:
   9110 	case R_PPC_GOT16_LO:
   9111 	case R_PPC_SDAREL16:
   9112 	case R_PPC_SECTOFF:
   9113 	case R_PPC_SECTOFF_LO:
   9114 	case R_PPC_DTPREL16:
   9115 	case R_PPC_DTPREL16_LO:
   9116 	case R_PPC_TPREL16:
   9117 	case R_PPC_TPREL16_LO:
   9118 	case R_PPC_GOT_TLSGD16:
   9119 	case R_PPC_GOT_TLSGD16_LO:
   9120 	case R_PPC_GOT_TLSLD16:
   9121 	case R_PPC_GOT_TLSLD16_LO:
   9122 	case R_PPC_GOT_DTPREL16:
   9123 	case R_PPC_GOT_DTPREL16_LO:
   9124 	case R_PPC_GOT_TPREL16:
   9125 	case R_PPC_GOT_TPREL16_LO:
   9126 	  {
   9127 	    /* The 32-bit ABI lacks proper relocations to deal with
   9128 	       certain 64-bit instructions.  Prevent damage to bits
   9129 	       that make up part of the insn opcode.  */
   9130 	    unsigned int insn, mask, lobit;
   9131 
   9132 	    insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
   9133 	    mask = 0;
   9134 	    if (is_insn_ds_form (insn))
   9135 	      mask = 3;
   9136 	    else if (is_insn_dq_form (insn))
   9137 	      mask = 15;
   9138 	    else
   9139 	      break;
   9140 	    lobit = mask & (relocation + addend);
   9141 	    if (lobit != 0)
   9142 	      {
   9143 		addend -= lobit;
   9144 		info->callbacks->einfo
   9145 		  (_("%P: %H: error: %s against `%s' not a multiple of %u\n"),
   9146 		   input_bfd, input_section, rel->r_offset,
   9147 		   howto->name, sym_name, mask + 1);
   9148 		bfd_set_error (bfd_error_bad_value);
   9149 		ret = FALSE;
   9150 	      }
   9151 	    addend += insn & mask;
   9152 	  }
   9153 	  break;
   9154 	}
   9155 
   9156 #ifdef DEBUG
   9157       fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, "
   9158 	       "offset = %ld, addend = %ld\n",
   9159 	       howto->name,
   9160 	       (int) r_type,
   9161 	       sym_name,
   9162 	       r_symndx,
   9163 	       (long) rel->r_offset,
   9164 	       (long) addend);
   9165 #endif
   9166 
   9167       if (unresolved_reloc
   9168 	  && !((input_section->flags & SEC_DEBUGGING) != 0
   9169 	       && h->def_dynamic)
   9170 	  && _bfd_elf_section_offset (output_bfd, info, input_section,
   9171 				      rel->r_offset) != (bfd_vma) -1)
   9172 	{
   9173 	  info->callbacks->einfo
   9174 	    (_("%P: %H: unresolvable %s relocation against symbol `%s'\n"),
   9175 	     input_bfd, input_section, rel->r_offset,
   9176 	     howto->name,
   9177 	     sym_name);
   9178 	  ret = FALSE;
   9179 	}
   9180 
   9181       /* 16-bit fields in insns mostly have signed values, but a
   9182 	 few insns have 16-bit unsigned values.  Really, we should
   9183 	 have different reloc types.  */
   9184       if (howto->complain_on_overflow != complain_overflow_dont
   9185 	  && howto->dst_mask == 0xffff
   9186 	  && (input_section->flags & SEC_CODE) != 0)
   9187 	{
   9188 	  enum complain_overflow complain = complain_overflow_signed;
   9189 
   9190 	  if ((elf_section_flags (input_section) & SHF_PPC_VLE) == 0)
   9191 	    {
   9192 	      unsigned int insn;
   9193 
   9194 	      insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
   9195 	      if ((insn & (0x3f << 26)) == 10u << 26 /* cmpli */)
   9196 		complain = complain_overflow_bitfield;
   9197 	      else if ((insn & (0x3f << 26)) == 28u << 26 /* andi */
   9198 		       || (insn & (0x3f << 26)) == 24u << 26 /* ori */
   9199 		       || (insn & (0x3f << 26)) == 26u << 26 /* xori */)
   9200 		complain = complain_overflow_unsigned;
   9201 	    }
   9202 	  if (howto->complain_on_overflow != complain)
   9203 	    {
   9204 	      alt_howto = *howto;
   9205 	      alt_howto.complain_on_overflow = complain;
   9206 	      howto = &alt_howto;
   9207 	    }
   9208 	}
   9209 
   9210       r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
   9211 				    rel->r_offset, relocation, addend);
   9212 
   9213       if (r != bfd_reloc_ok)
   9214 	{
   9215 	  if (r == bfd_reloc_overflow)
   9216 	    {
   9217 	    overflow:
   9218 	      if (warned)
   9219 		continue;
   9220 	      if (h != NULL
   9221 		  && h->root.type == bfd_link_hash_undefweak
   9222 		  && howto->pc_relative)
   9223 		{
   9224 		  /* Assume this is a call protected by other code that
   9225 		     detect the symbol is undefined.  If this is the case,
   9226 		     we can safely ignore the overflow.  If not, the
   9227 		     program is hosed anyway, and a little warning isn't
   9228 		     going to help.  */
   9229 
   9230 		  continue;
   9231 		}
   9232 
   9233 	      if (! (*info->callbacks->reloc_overflow) (info,
   9234 							(h ? &h->root : NULL),
   9235 							sym_name,
   9236 							howto->name,
   9237 							rel->r_addend,
   9238 							input_bfd,
   9239 							input_section,
   9240 							rel->r_offset))
   9241 		return FALSE;
   9242 	    }
   9243 	  else
   9244 	    {
   9245 	      info->callbacks->einfo
   9246 		(_("%P: %H: %s reloc against `%s': error %d\n"),
   9247 		 input_bfd, input_section, rel->r_offset,
   9248 		 howto->name, sym_name, (int) r);
   9249 	      ret = FALSE;
   9250 	    }
   9251 	}
   9252     }
   9253 
   9254 #ifdef DEBUG
   9255   fprintf (stderr, "\n");
   9256 #endif
   9257 
   9258   if (input_section->sec_info_type == SEC_INFO_TYPE_TARGET
   9259       && input_section->size != input_section->rawsize
   9260       && (strcmp (input_section->output_section->name, ".init") == 0
   9261 	  || strcmp (input_section->output_section->name, ".fini") == 0))
   9262     {
   9263       /* Branch around the trampolines.  */
   9264       unsigned int insn = B + input_section->size - input_section->rawsize;
   9265       bfd_put_32 (input_bfd, insn, contents + input_section->rawsize);
   9266     }
   9267 
   9268   if (htab->params->ppc476_workaround
   9269       && input_section->sec_info_type == SEC_INFO_TYPE_TARGET
   9270       && (!info->relocatable
   9271 	  || (input_section->output_section->alignment_power
   9272 	      >= htab->params->pagesize_p2)))
   9273     {
   9274       struct ppc_elf_relax_info *relax_info;
   9275       bfd_vma start_addr, end_addr, addr;
   9276       bfd_vma pagesize = (bfd_vma) 1 << htab->params->pagesize_p2;
   9277 
   9278       relax_info = elf_section_data (input_section)->sec_info;
   9279       if (relax_info->workaround_size != 0)
   9280 	{
   9281 	  bfd_byte *p;
   9282 	  unsigned int n;
   9283 	  bfd_byte fill[4];
   9284 
   9285 	  bfd_put_32 (input_bfd, BA, fill);
   9286 	  p = contents + input_section->size - relax_info->workaround_size;
   9287 	  n = relax_info->workaround_size >> 2;
   9288 	  while (n--)
   9289 	    {
   9290 	      memcpy (p, fill, 4);
   9291 	      p += 4;
   9292 	    }
   9293 	}
   9294 
   9295       /* The idea is: Replace the last instruction on a page with a
   9296 	 branch to a patch area.  Put the insn there followed by a
   9297 	 branch back to the next page.  Complicated a little by
   9298 	 needing to handle moved conditional branches, and by not
   9299 	 wanting to touch data-in-text.  */
   9300 
   9301       start_addr = (input_section->output_section->vma
   9302 		    + input_section->output_offset);
   9303       end_addr = (start_addr + input_section->size
   9304 		  - relax_info->workaround_size);
   9305       for (addr = ((start_addr & -pagesize) + pagesize - 4);
   9306 	   addr < end_addr;
   9307 	   addr += pagesize)
   9308 	{
   9309 	  bfd_vma offset = addr - start_addr;
   9310 	  Elf_Internal_Rela *lo, *hi;
   9311 	  bfd_boolean is_data;
   9312 	  bfd_vma patch_off, patch_addr;
   9313 	  unsigned int insn;
   9314 
   9315 	  /* Do we have a data reloc at this offset?  If so, leave
   9316 	     the word alone.  */
   9317 	  is_data = FALSE;
   9318 	  lo = relocs;
   9319 	  hi = relend;
   9320 	  rel = NULL;
   9321 	  while (lo < hi)
   9322 	    {
   9323 	      rel = lo + (hi - lo) / 2;
   9324 	      if (rel->r_offset < offset)
   9325 		lo = rel + 1;
   9326 	      else if (rel->r_offset > offset + 3)
   9327 		hi = rel;
   9328 	      else
   9329 		{
   9330 		  switch (ELF32_R_TYPE (rel->r_info))
   9331 		    {
   9332 		    case R_PPC_ADDR32:
   9333 		    case R_PPC_UADDR32:
   9334 		    case R_PPC_REL32:
   9335 		    case R_PPC_ADDR30:
   9336 		      is_data = TRUE;
   9337 		      break;
   9338 		    default:
   9339 		      break;
   9340 		    }
   9341 		  break;
   9342 		}
   9343 	    }
   9344 	  if (is_data)
   9345 	    continue;
   9346 
   9347 	  /* Some instructions can be left alone too.  Unconditional
   9348 	     branches, except for bcctr with BO=0x14 (bctr, bctrl),
   9349 	     avoid the icache failure.
   9350 
   9351 	     The problem occurs due to prefetch across a page boundary
   9352 	     where stale instructions can be fetched from the next
   9353 	     page, and the mechanism for flushing these bad
   9354 	     instructions fails under certain circumstances.  The
   9355 	     unconditional branches:
   9356 	     1) Branch: b, bl, ba, bla,
   9357 	     2) Branch Conditional: bc, bca, bcl, bcla,
   9358 	     3) Branch Conditional to Link Register: bclr, bclrl,
   9359 	     where (2) and (3) have BO=0x14 making them unconditional,
   9360 	     prevent the bad prefetch because the prefetch itself is
   9361 	     affected by these instructions.  This happens even if the
   9362 	     instruction is not executed.
   9363 
   9364 	     A bctr example:
   9365 	     .
   9366 	     .	lis 9,new_page@ha
   9367 	     .	addi 9,9,new_page@l
   9368 	     .	mtctr 9
   9369 	     .	bctr
   9370 	     .	nop
   9371 	     .	nop
   9372 	     . new_page:
   9373 	     .
   9374 	     The bctr is not predicted taken due to ctr not being
   9375 	     ready, so prefetch continues on past the bctr into the
   9376 	     new page which might have stale instructions.  If they
   9377 	     fail to be flushed, then they will be executed after the
   9378 	     bctr executes.  Either of the following modifications
   9379 	     prevent the bad prefetch from happening in the first
   9380 	     place:
   9381 	     .
   9382 	     .	lis 9,new_page@ha	 lis 9,new_page@ha
   9383 	     .	addi 9,9,new_page@l	 addi 9,9,new_page@l
   9384 	     .	mtctr 9			 mtctr 9
   9385 	     .	bctr			 bctr
   9386 	     .	nop			 b somewhere_else
   9387 	     .	b somewhere_else	 nop
   9388 	     . new_page:		new_page:
   9389 	     .  */
   9390 	  insn = bfd_get_32 (input_bfd, contents + offset);
   9391 	  if ((insn & (0x3f << 26)) == (18u << 26)          /* b,bl,ba,bla */
   9392 	      || ((insn & (0x3f << 26)) == (16u << 26)      /* bc,bcl,bca,bcla*/
   9393 		  && (insn & (0x14 << 21)) == (0x14 << 21)) /*   with BO=0x14 */
   9394 	      || ((insn & (0x3f << 26)) == (19u << 26)
   9395 		  && (insn & (0x3ff << 1)) == (16u << 1)    /* bclr,bclrl */
   9396 		  && (insn & (0x14 << 21)) == (0x14 << 21)))/*   with BO=0x14 */
   9397 	    continue;
   9398 
   9399 	  patch_addr = (start_addr + input_section->size
   9400 			- relax_info->workaround_size);
   9401 	  patch_addr = (patch_addr + 15) & -16;
   9402 	  patch_off = patch_addr - start_addr;
   9403 	  bfd_put_32 (input_bfd, B + patch_off - offset, contents + offset);
   9404 
   9405 	  if (rel != NULL
   9406 	      && rel->r_offset >= offset
   9407 	      && rel->r_offset < offset + 4)
   9408 	    {
   9409 	      /* If the insn we are patching had a reloc, adjust the
   9410 		 reloc r_offset so that the reloc applies to the moved
   9411 		 location.  This matters for -r and --emit-relocs.  */
   9412 	      if (rel + 1 != relend)
   9413 		{
   9414 		  Elf_Internal_Rela tmp = *rel;
   9415 
   9416 		  /* Keep the relocs sorted by r_offset.  */
   9417 		  memmove (rel, rel + 1, (relend - (rel + 1)) * sizeof (*rel));
   9418 		  relend[-1] = tmp;
   9419 		}
   9420 	      relend[-1].r_offset += patch_off - offset;
   9421 	    }
   9422 	  else
   9423 	    rel = NULL;
   9424 
   9425 	  if ((insn & (0x3f << 26)) == (16u << 26) /* bc */
   9426 	      && (insn & 2) == 0 /* relative */)
   9427 	    {
   9428 	      bfd_vma delta = ((insn & 0xfffc) ^ 0x8000) - 0x8000;
   9429 
   9430 	      delta += offset - patch_off;
   9431 	      if (info->relocatable && rel != NULL)
   9432 		delta = 0;
   9433 	      if (!info->relocatable && rel != NULL)
   9434 		{
   9435 		  enum elf_ppc_reloc_type r_type;
   9436 
   9437 		  r_type = ELF32_R_TYPE (relend[-1].r_info);
   9438 		  if (r_type == R_PPC_REL14_BRTAKEN)
   9439 		    insn |= BRANCH_PREDICT_BIT;
   9440 		  else if (r_type == R_PPC_REL14_BRNTAKEN)
   9441 		    insn &= ~BRANCH_PREDICT_BIT;
   9442 		  else
   9443 		    BFD_ASSERT (r_type == R_PPC_REL14);
   9444 
   9445 		  if ((r_type == R_PPC_REL14_BRTAKEN
   9446 		       || r_type == R_PPC_REL14_BRNTAKEN)
   9447 		      && delta + 0x8000 < 0x10000
   9448 		      && (bfd_signed_vma) delta < 0)
   9449 		    insn ^= BRANCH_PREDICT_BIT;
   9450 		}
   9451 	      if (delta + 0x8000 < 0x10000)
   9452 		{
   9453 		  bfd_put_32 (input_bfd,
   9454 			      (insn & ~0xfffc) | (delta & 0xfffc),
   9455 			      contents + patch_off);
   9456 		  patch_off += 4;
   9457 		  bfd_put_32 (input_bfd,
   9458 			      B | ((offset + 4 - patch_off) & 0x3fffffc),
   9459 			      contents + patch_off);
   9460 		  patch_off += 4;
   9461 		}
   9462 	      else
   9463 		{
   9464 		  if (rel != NULL)
   9465 		    {
   9466 		      unsigned int r_sym = ELF32_R_SYM (relend[-1].r_info);
   9467 
   9468 		      relend[-1].r_offset += 8;
   9469 		      relend[-1].r_info = ELF32_R_INFO (r_sym, R_PPC_REL24);
   9470 		    }
   9471 		  bfd_put_32 (input_bfd,
   9472 			      (insn & ~0xfffc) | 8,
   9473 			      contents + patch_off);
   9474 		  patch_off += 4;
   9475 		  bfd_put_32 (input_bfd,
   9476 			      B | ((offset + 4 - patch_off) & 0x3fffffc),
   9477 			      contents + patch_off);
   9478 		  patch_off += 4;
   9479 		  bfd_put_32 (input_bfd,
   9480 			      B | ((delta - 8) & 0x3fffffc),
   9481 			      contents + patch_off);
   9482 		  patch_off += 4;
   9483 		}
   9484 	    }
   9485 	  else
   9486 	    {
   9487 	      bfd_put_32 (input_bfd, insn, contents + patch_off);
   9488 	      patch_off += 4;
   9489 	      bfd_put_32 (input_bfd,
   9490 			  B | ((offset + 4 - patch_off) & 0x3fffffc),
   9491 			  contents + patch_off);
   9492 	      patch_off += 4;
   9493 	    }
   9494 	  BFD_ASSERT (patch_off <= input_section->size);
   9495 	  relax_info->workaround_size = input_section->size - patch_off;
   9496 	}
   9497     }
   9498 
   9499   return ret;
   9500 }
   9501 
   9502 /* Finish up dynamic symbol handling.  We set the contents of various
   9504    dynamic sections here.  */
   9505 
   9506 static bfd_boolean
   9507 ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
   9508 			       struct bfd_link_info *info,
   9509 			       struct elf_link_hash_entry *h,
   9510 			       Elf_Internal_Sym *sym)
   9511 {
   9512   struct ppc_elf_link_hash_table *htab;
   9513   struct plt_entry *ent;
   9514   bfd_boolean doneone;
   9515 
   9516 #ifdef DEBUG
   9517   fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
   9518 	   h->root.root.string);
   9519 #endif
   9520 
   9521   htab = ppc_elf_hash_table (info);
   9522   BFD_ASSERT (htab->elf.dynobj != NULL);
   9523 
   9524   doneone = FALSE;
   9525   for (ent = h->plt.plist; ent != NULL; ent = ent->next)
   9526     if (ent->plt.offset != (bfd_vma) -1)
   9527       {
   9528 	if (!doneone)
   9529 	  {
   9530 	    Elf_Internal_Rela rela;
   9531 	    bfd_byte *loc;
   9532 	    bfd_vma reloc_index;
   9533 
   9534 	    if (htab->plt_type == PLT_NEW
   9535 		|| !htab->elf.dynamic_sections_created
   9536 		|| h->dynindx == -1)
   9537 	      reloc_index = ent->plt.offset / 4;
   9538 	    else
   9539 	      {
   9540 		reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size)
   9541 			       / htab->plt_slot_size);
   9542 		if (reloc_index > PLT_NUM_SINGLE_ENTRIES
   9543 		    && htab->plt_type == PLT_OLD)
   9544 		  reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
   9545 	      }
   9546 
   9547 	    /* This symbol has an entry in the procedure linkage table.
   9548 	       Set it up.  */
   9549 	    if (htab->plt_type == PLT_VXWORKS
   9550 		&& htab->elf.dynamic_sections_created
   9551 		&& h->dynindx != -1)
   9552 	      {
   9553 		bfd_vma got_offset;
   9554 		const bfd_vma *plt_entry;
   9555 
   9556 		/* The first three entries in .got.plt are reserved.  */
   9557 		got_offset = (reloc_index + 3) * 4;
   9558 
   9559 		/* Use the right PLT. */
   9560 		plt_entry = info->shared ? ppc_elf_vxworks_pic_plt_entry
   9561 			    : ppc_elf_vxworks_plt_entry;
   9562 
   9563 		/* Fill in the .plt on VxWorks.  */
   9564 		if (info->shared)
   9565 		  {
   9566 		    bfd_put_32 (output_bfd,
   9567 				plt_entry[0] | PPC_HA (got_offset),
   9568 				htab->plt->contents + ent->plt.offset + 0);
   9569 		    bfd_put_32 (output_bfd,
   9570 				plt_entry[1] | PPC_LO (got_offset),
   9571 				htab->plt->contents + ent->plt.offset + 4);
   9572 		  }
   9573 		else
   9574 		  {
   9575 		    bfd_vma got_loc = got_offset + SYM_VAL (htab->elf.hgot);
   9576 
   9577 		    bfd_put_32 (output_bfd,
   9578 				plt_entry[0] | PPC_HA (got_loc),
   9579 				htab->plt->contents + ent->plt.offset + 0);
   9580 		    bfd_put_32 (output_bfd,
   9581 				plt_entry[1] | PPC_LO (got_loc),
   9582 				htab->plt->contents + ent->plt.offset + 4);
   9583 		  }
   9584 
   9585 		bfd_put_32 (output_bfd, plt_entry[2],
   9586 			    htab->plt->contents + ent->plt.offset + 8);
   9587 		bfd_put_32 (output_bfd, plt_entry[3],
   9588 			    htab->plt->contents + ent->plt.offset + 12);
   9589 
   9590 		/* This instruction is an immediate load.  The value loaded is
   9591 		   the byte offset of the R_PPC_JMP_SLOT relocation from the
   9592 		   start of the .rela.plt section.  The value is stored in the
   9593 		   low-order 16 bits of the load instruction.  */
   9594 		/* NOTE: It appears that this is now an index rather than a
   9595 		   prescaled offset.  */
   9596 		bfd_put_32 (output_bfd,
   9597 			    plt_entry[4] | reloc_index,
   9598 			    htab->plt->contents + ent->plt.offset + 16);
   9599 		/* This instruction is a PC-relative branch whose target is
   9600 		   the start of the PLT section.  The address of this branch
   9601 		   instruction is 20 bytes beyond the start of this PLT entry.
   9602 		   The address is encoded in bits 6-29, inclusive.  The value
   9603 		   stored is right-shifted by two bits, permitting a 26-bit
   9604 		   offset.  */
   9605 		bfd_put_32 (output_bfd,
   9606 			    (plt_entry[5]
   9607 			     | (-(ent->plt.offset + 20) & 0x03fffffc)),
   9608 			    htab->plt->contents + ent->plt.offset + 20);
   9609 		bfd_put_32 (output_bfd, plt_entry[6],
   9610 			    htab->plt->contents + ent->plt.offset + 24);
   9611 		bfd_put_32 (output_bfd, plt_entry[7],
   9612 			    htab->plt->contents + ent->plt.offset + 28);
   9613 
   9614 		/* Fill in the GOT entry corresponding to this PLT slot with
   9615 		   the address immediately after the "bctr" instruction
   9616 		   in this PLT entry.  */
   9617 		bfd_put_32 (output_bfd, (htab->plt->output_section->vma
   9618 					 + htab->plt->output_offset
   9619 					 + ent->plt.offset + 16),
   9620 			    htab->sgotplt->contents + got_offset);
   9621 
   9622 		if (!info->shared)
   9623 		  {
   9624 		    /* Fill in a couple of entries in .rela.plt.unloaded.  */
   9625 		    loc = htab->srelplt2->contents
   9626 		      + ((VXWORKS_PLTRESOLVE_RELOCS + reloc_index
   9627 			  * VXWORKS_PLT_NON_JMP_SLOT_RELOCS)
   9628 			 * sizeof (Elf32_External_Rela));
   9629 
   9630 		    /* Provide the @ha relocation for the first instruction.  */
   9631 		    rela.r_offset = (htab->plt->output_section->vma
   9632 				     + htab->plt->output_offset
   9633 				     + ent->plt.offset + 2);
   9634 		    rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
   9635 						R_PPC_ADDR16_HA);
   9636 		    rela.r_addend = got_offset;
   9637 		    bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   9638 		    loc += sizeof (Elf32_External_Rela);
   9639 
   9640 		    /* Provide the @l relocation for the second instruction.  */
   9641 		    rela.r_offset = (htab->plt->output_section->vma
   9642 				     + htab->plt->output_offset
   9643 				     + ent->plt.offset + 6);
   9644 		    rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
   9645 						R_PPC_ADDR16_LO);
   9646 		    rela.r_addend = got_offset;
   9647 		    bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   9648 		    loc += sizeof (Elf32_External_Rela);
   9649 
   9650 		    /* Provide a relocation for the GOT entry corresponding to this
   9651 		       PLT slot.  Point it at the middle of the .plt entry.  */
   9652 		    rela.r_offset = (htab->sgotplt->output_section->vma
   9653 				     + htab->sgotplt->output_offset
   9654 				     + got_offset);
   9655 		    rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
   9656 						R_PPC_ADDR32);
   9657 		    rela.r_addend = ent->plt.offset + 16;
   9658 		    bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   9659 		  }
   9660 
   9661 		/* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT.
   9662 		   In particular, the offset for the relocation is not the
   9663 		   address of the PLT entry for this function, as specified
   9664 		   by the ABI.  Instead, the offset is set to the address of
   9665 		   the GOT slot for this function.  See EABI 4.4.4.1.  */
   9666 		rela.r_offset = (htab->sgotplt->output_section->vma
   9667 				 + htab->sgotplt->output_offset
   9668 				 + got_offset);
   9669 
   9670 	      }
   9671 	    else
   9672 	      {
   9673 		asection *splt = htab->plt;
   9674 		if (!htab->elf.dynamic_sections_created
   9675 		    || h->dynindx == -1)
   9676 		  splt = htab->iplt;
   9677 
   9678 		rela.r_offset = (splt->output_section->vma
   9679 				 + splt->output_offset
   9680 				 + ent->plt.offset);
   9681 		if (htab->plt_type == PLT_OLD
   9682 		    || !htab->elf.dynamic_sections_created
   9683 		    || h->dynindx == -1)
   9684 		  {
   9685 		    /* We don't need to fill in the .plt.  The ppc dynamic
   9686 		       linker will fill it in.  */
   9687 		  }
   9688 		else
   9689 		  {
   9690 		    bfd_vma val = (htab->glink_pltresolve + ent->plt.offset
   9691 				   + htab->glink->output_section->vma
   9692 				   + htab->glink->output_offset);
   9693 		    bfd_put_32 (output_bfd, val,
   9694 				splt->contents + ent->plt.offset);
   9695 		  }
   9696 	      }
   9697 
   9698 	    /* Fill in the entry in the .rela.plt section.  */
   9699 	    rela.r_addend = 0;
   9700 	    if (!htab->elf.dynamic_sections_created
   9701 		|| h->dynindx == -1)
   9702 	      {
   9703 		BFD_ASSERT (h->type == STT_GNU_IFUNC
   9704 			    && h->def_regular
   9705 			    && (h->root.type == bfd_link_hash_defined
   9706 				|| h->root.type == bfd_link_hash_defweak));
   9707 		rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
   9708 		rela.r_addend = SYM_VAL (h);
   9709 	      }
   9710 	    else
   9711 	      rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
   9712 
   9713 	    if (!htab->elf.dynamic_sections_created
   9714 		|| h->dynindx == -1)
   9715 	      loc = (htab->reliplt->contents
   9716 		     + (htab->reliplt->reloc_count++
   9717 			* sizeof (Elf32_External_Rela)));
   9718 	    else
   9719 	      loc = (htab->relplt->contents
   9720 		     + reloc_index * sizeof (Elf32_External_Rela));
   9721 	    bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   9722 
   9723 	    if (!h->def_regular)
   9724 	      {
   9725 		/* Mark the symbol as undefined, rather than as
   9726 		   defined in the .plt section.  Leave the value if
   9727 		   there were any relocations where pointer equality
   9728 		   matters (this is a clue for the dynamic linker, to
   9729 		   make function pointer comparisons work between an
   9730 		   application and shared library), otherwise set it
   9731 		   to zero.  */
   9732 		sym->st_shndx = SHN_UNDEF;
   9733 		if (!h->pointer_equality_needed)
   9734 		  sym->st_value = 0;
   9735 		else if (!h->ref_regular_nonweak)
   9736 		  {
   9737 		    /* This breaks function pointer comparisons, but
   9738 		       that is better than breaking tests for a NULL
   9739 		       function pointer.  */
   9740 		    sym->st_value = 0;
   9741 		  }
   9742 	      }
   9743 	    else if (h->type == STT_GNU_IFUNC
   9744 		     && !info->shared)
   9745 	      {
   9746 		/* Set the value of ifunc symbols in a non-pie
   9747 		   executable to the glink entry.  This is to avoid
   9748 		   text relocations.  We can't do this for ifunc in
   9749 		   allocate_dynrelocs, as we do for normal dynamic
   9750 		   function symbols with plt entries, because we need
   9751 		   to keep the original value around for the ifunc
   9752 		   relocation.  */
   9753 		sym->st_shndx = (_bfd_elf_section_from_bfd_section
   9754 				 (output_bfd, htab->glink->output_section));
   9755 		sym->st_value = (ent->glink_offset
   9756 				 + htab->glink->output_offset
   9757 				 + htab->glink->output_section->vma);
   9758 	      }
   9759 	    doneone = TRUE;
   9760 	  }
   9761 
   9762 	if (htab->plt_type == PLT_NEW
   9763 	    || !htab->elf.dynamic_sections_created
   9764 	    || h->dynindx == -1)
   9765 	  {
   9766 	    unsigned char *p;
   9767 	    asection *splt = htab->plt;
   9768 	    if (!htab->elf.dynamic_sections_created
   9769 		|| h->dynindx == -1)
   9770 	      splt = htab->iplt;
   9771 
   9772 	    p = (unsigned char *) htab->glink->contents + ent->glink_offset;
   9773 
   9774 	    if (h == htab->tls_get_addr && !htab->params->no_tls_get_addr_opt)
   9775 	      {
   9776 		bfd_put_32 (output_bfd, LWZ_11_3, p);
   9777 		p += 4;
   9778 		bfd_put_32 (output_bfd, LWZ_12_3 + 4, p);
   9779 		p += 4;
   9780 		bfd_put_32 (output_bfd, MR_0_3, p);
   9781 		p += 4;
   9782 		bfd_put_32 (output_bfd, CMPWI_11_0, p);
   9783 		p += 4;
   9784 		bfd_put_32 (output_bfd, ADD_3_12_2, p);
   9785 		p += 4;
   9786 		bfd_put_32 (output_bfd, BEQLR, p);
   9787 		p += 4;
   9788 		bfd_put_32 (output_bfd, MR_3_0, p);
   9789 		p += 4;
   9790 		bfd_put_32 (output_bfd, NOP, p);
   9791 		p += 4;
   9792 	      }
   9793 
   9794 	    write_glink_stub (ent, splt, p, info);
   9795 
   9796 	    if (!info->shared)
   9797 	      /* We only need one non-PIC glink stub.  */
   9798 	      break;
   9799 	  }
   9800 	else
   9801 	  break;
   9802       }
   9803 
   9804   if (h->needs_copy)
   9805     {
   9806       asection *s;
   9807       Elf_Internal_Rela rela;
   9808       bfd_byte *loc;
   9809 
   9810       /* This symbols needs a copy reloc.  Set it up.  */
   9811 
   9812 #ifdef DEBUG
   9813       fprintf (stderr, ", copy");
   9814 #endif
   9815 
   9816       BFD_ASSERT (h->dynindx != -1);
   9817 
   9818       if (ppc_elf_hash_entry (h)->has_sda_refs)
   9819 	s = htab->relsbss;
   9820       else
   9821 	s = htab->relbss;
   9822       BFD_ASSERT (s != NULL);
   9823 
   9824       rela.r_offset = SYM_VAL (h);
   9825       rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
   9826       rela.r_addend = 0;
   9827       loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
   9828       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   9829     }
   9830 
   9831 #ifdef DEBUG
   9832   fprintf (stderr, "\n");
   9833 #endif
   9834 
   9835   return TRUE;
   9836 }
   9837 
   9838 static enum elf_reloc_type_class
   9840 ppc_elf_reloc_type_class (const struct bfd_link_info *info,
   9841 			  const asection *rel_sec,
   9842 			  const Elf_Internal_Rela *rela)
   9843 {
   9844   struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
   9845 
   9846   if (rel_sec == htab->reliplt)
   9847     return reloc_class_ifunc;
   9848 
   9849   switch (ELF32_R_TYPE (rela->r_info))
   9850     {
   9851     case R_PPC_RELATIVE:
   9852       return reloc_class_relative;
   9853     case R_PPC_JMP_SLOT:
   9854       return reloc_class_plt;
   9855     case R_PPC_COPY:
   9856       return reloc_class_copy;
   9857     default:
   9858       return reloc_class_normal;
   9859     }
   9860 }
   9861 
   9862 /* Finish up the dynamic sections.  */
   9864 
   9865 static bfd_boolean
   9866 ppc_elf_finish_dynamic_sections (bfd *output_bfd,
   9867 				 struct bfd_link_info *info)
   9868 {
   9869   asection *sdyn;
   9870   asection *splt;
   9871   struct ppc_elf_link_hash_table *htab;
   9872   bfd_vma got;
   9873   bfd *dynobj;
   9874   bfd_boolean ret = TRUE;
   9875 
   9876 #ifdef DEBUG
   9877   fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
   9878 #endif
   9879 
   9880   htab = ppc_elf_hash_table (info);
   9881   dynobj = elf_hash_table (info)->dynobj;
   9882   sdyn = bfd_get_linker_section (dynobj, ".dynamic");
   9883   if (htab->is_vxworks)
   9884     splt = bfd_get_linker_section (dynobj, ".plt");
   9885   else
   9886     splt = NULL;
   9887 
   9888   got = 0;
   9889   if (htab->elf.hgot != NULL)
   9890     got = SYM_VAL (htab->elf.hgot);
   9891 
   9892   if (htab->elf.dynamic_sections_created)
   9893     {
   9894       Elf32_External_Dyn *dyncon, *dynconend;
   9895 
   9896       BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
   9897 
   9898       dyncon = (Elf32_External_Dyn *) sdyn->contents;
   9899       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
   9900       for (; dyncon < dynconend; dyncon++)
   9901 	{
   9902 	  Elf_Internal_Dyn dyn;
   9903 	  asection *s;
   9904 
   9905 	  bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
   9906 
   9907 	  switch (dyn.d_tag)
   9908 	    {
   9909 	    case DT_PLTGOT:
   9910 	      if (htab->is_vxworks)
   9911 		s = htab->sgotplt;
   9912 	      else
   9913 		s = htab->plt;
   9914 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   9915 	      break;
   9916 
   9917 	    case DT_PLTRELSZ:
   9918 	      dyn.d_un.d_val = htab->relplt->size;
   9919 	      break;
   9920 
   9921 	    case DT_JMPREL:
   9922 	      s = htab->relplt;
   9923 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   9924 	      break;
   9925 
   9926 	    case DT_PPC_GOT:
   9927 	      dyn.d_un.d_ptr = got;
   9928 	      break;
   9929 
   9930 	    case DT_RELASZ:
   9931 	      if (htab->is_vxworks)
   9932 		{
   9933 		  if (htab->relplt)
   9934 		    dyn.d_un.d_ptr -= htab->relplt->size;
   9935 		  break;
   9936 		}
   9937 	      continue;
   9938 
   9939 	    default:
   9940 	      if (htab->is_vxworks
   9941 		  && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
   9942 		break;
   9943 	      continue;
   9944 	    }
   9945 
   9946 	  bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   9947 	}
   9948     }
   9949 
   9950   if (htab->got != NULL)
   9951     {
   9952       if (htab->elf.hgot->root.u.def.section == htab->got
   9953 	  || htab->elf.hgot->root.u.def.section == htab->sgotplt)
   9954 	{
   9955 	  unsigned char *p = htab->elf.hgot->root.u.def.section->contents;
   9956 
   9957 	  p += htab->elf.hgot->root.u.def.value;
   9958 	  if (htab->plt_type == PLT_OLD)
   9959 	    {
   9960 	      /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4
   9961 		 so that a function can easily find the address of
   9962 		 _GLOBAL_OFFSET_TABLE_.  */
   9963 	      BFD_ASSERT (htab->elf.hgot->root.u.def.value - 4
   9964 			  < htab->elf.hgot->root.u.def.section->size);
   9965 	      bfd_put_32 (output_bfd, 0x4e800021, p - 4);
   9966 	    }
   9967 
   9968 	  if (sdyn != NULL)
   9969 	    {
   9970 	      bfd_vma val = sdyn->output_section->vma + sdyn->output_offset;
   9971 	      BFD_ASSERT (htab->elf.hgot->root.u.def.value
   9972 			  < htab->elf.hgot->root.u.def.section->size);
   9973 	      bfd_put_32 (output_bfd, val, p);
   9974 	    }
   9975 	}
   9976       else
   9977 	{
   9978 	  info->callbacks->einfo (_("%P: %s not defined in linker created %s\n"),
   9979 				  htab->elf.hgot->root.root.string,
   9980 				  (htab->sgotplt != NULL
   9981 				   ? htab->sgotplt->name : htab->got->name));
   9982 	  bfd_set_error (bfd_error_bad_value);
   9983 	  ret = FALSE;
   9984 	}
   9985 
   9986       elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
   9987     }
   9988 
   9989   /* Fill in the first entry in the VxWorks procedure linkage table.  */
   9990   if (splt && splt->size > 0)
   9991     {
   9992       /* Use the right PLT. */
   9993       const bfd_vma *plt_entry = (info->shared
   9994 				  ? ppc_elf_vxworks_pic_plt0_entry
   9995 				  : ppc_elf_vxworks_plt0_entry);
   9996 
   9997       if (!info->shared)
   9998 	{
   9999 	  bfd_vma got_value = SYM_VAL (htab->elf.hgot);
   10000 
   10001 	  bfd_put_32 (output_bfd, plt_entry[0] | PPC_HA (got_value),
   10002 		      splt->contents +  0);
   10003 	  bfd_put_32 (output_bfd, plt_entry[1] | PPC_LO (got_value),
   10004 		      splt->contents +  4);
   10005 	}
   10006       else
   10007 	{
   10008 	  bfd_put_32 (output_bfd, plt_entry[0], splt->contents +  0);
   10009 	  bfd_put_32 (output_bfd, plt_entry[1], splt->contents +  4);
   10010 	}
   10011       bfd_put_32 (output_bfd, plt_entry[2], splt->contents +  8);
   10012       bfd_put_32 (output_bfd, plt_entry[3], splt->contents + 12);
   10013       bfd_put_32 (output_bfd, plt_entry[4], splt->contents + 16);
   10014       bfd_put_32 (output_bfd, plt_entry[5], splt->contents + 20);
   10015       bfd_put_32 (output_bfd, plt_entry[6], splt->contents + 24);
   10016       bfd_put_32 (output_bfd, plt_entry[7], splt->contents + 28);
   10017 
   10018       if (! info->shared)
   10019 	{
   10020 	  Elf_Internal_Rela rela;
   10021 	  bfd_byte *loc;
   10022 
   10023 	  loc = htab->srelplt2->contents;
   10024 
   10025 	  /* Output the @ha relocation for the first instruction.  */
   10026 	  rela.r_offset = (htab->plt->output_section->vma
   10027 			   + htab->plt->output_offset
   10028 			   + 2);
   10029 	  rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
   10030 	  rela.r_addend = 0;
   10031 	  bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   10032 	  loc += sizeof (Elf32_External_Rela);
   10033 
   10034 	  /* Output the @l relocation for the second instruction.  */
   10035 	  rela.r_offset = (htab->plt->output_section->vma
   10036 			   + htab->plt->output_offset
   10037 			   + 6);
   10038 	  rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
   10039 	  rela.r_addend = 0;
   10040 	  bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   10041 	  loc += sizeof (Elf32_External_Rela);
   10042 
   10043 	  /* Fix up the remaining relocations.  They may have the wrong
   10044 	     symbol index for _G_O_T_ or _P_L_T_ depending on the order
   10045 	     in which symbols were output.  */
   10046 	  while (loc < htab->srelplt2->contents + htab->srelplt2->size)
   10047 	    {
   10048 	      Elf_Internal_Rela rel;
   10049 
   10050 	      bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
   10051 	      rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
   10052 	      bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
   10053 	      loc += sizeof (Elf32_External_Rela);
   10054 
   10055 	      bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
   10056 	      rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
   10057 	      bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
   10058 	      loc += sizeof (Elf32_External_Rela);
   10059 
   10060 	      bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
   10061 	      rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32);
   10062 	      bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
   10063 	      loc += sizeof (Elf32_External_Rela);
   10064 	    }
   10065 	}
   10066     }
   10067 
   10068   if (htab->glink != NULL
   10069       && htab->glink->contents != NULL
   10070       && htab->elf.dynamic_sections_created)
   10071     {
   10072       unsigned char *p;
   10073       unsigned char *endp;
   10074       bfd_vma res0;
   10075       unsigned int i;
   10076 
   10077       /*
   10078        * PIC glink code is the following:
   10079        *
   10080        * # ith PLT code stub.
   10081        *   addis 11,30,(plt+(i-1)*4-got)@ha
   10082        *   lwz 11,(plt+(i-1)*4-got)@l(11)
   10083        *   mtctr 11
   10084        *   bctr
   10085        *
   10086        * # A table of branches, one for each plt entry.
   10087        * # The idea is that the plt call stub loads ctr and r11 with these
   10088        * # addresses, so (r11 - res_0) gives the plt index * 4.
   10089        * res_0:	b PLTresolve
   10090        * res_1:	b PLTresolve
   10091        * .
   10092        * # Some number of entries towards the end can be nops
   10093        * res_n_m3: nop
   10094        * res_n_m2: nop
   10095        * res_n_m1:
   10096        *
   10097        * PLTresolve:
   10098        *    addis 11,11,(1f-res_0)@ha
   10099        *    mflr 0
   10100        *    bcl 20,31,1f
   10101        * 1: addi 11,11,(1b-res_0)@l
   10102        *    mflr 12
   10103        *    mtlr 0
   10104        *    sub 11,11,12                # r11 = index * 4
   10105        *    addis 12,12,(got+4-1b)@ha
   10106        *    lwz 0,(got+4-1b)@l(12)      # got[1] address of dl_runtime_resolve
   10107        *    lwz 12,(got+8-1b)@l(12)     # got[2] contains the map address
   10108        *    mtctr 0
   10109        *    add 0,11,11
   10110        *    add 11,0,11                 # r11 = index * 12 = reloc offset.
   10111        *    bctr
   10112        */
   10113       static const unsigned int pic_plt_resolve[] =
   10114 	{
   10115 	  ADDIS_11_11,
   10116 	  MFLR_0,
   10117 	  BCL_20_31,
   10118 	  ADDI_11_11,
   10119 	  MFLR_12,
   10120 	  MTLR_0,
   10121 	  SUB_11_11_12,
   10122 	  ADDIS_12_12,
   10123 	  LWZ_0_12,
   10124 	  LWZ_12_12,
   10125 	  MTCTR_0,
   10126 	  ADD_0_11_11,
   10127 	  ADD_11_0_11,
   10128 	  BCTR,
   10129 	  NOP,
   10130 	  NOP
   10131 	};
   10132 
   10133       /*
   10134        * Non-PIC glink code is a little simpler.
   10135        *
   10136        * # ith PLT code stub.
   10137        *   lis 11,(plt+(i-1)*4)@ha
   10138        *   lwz 11,(plt+(i-1)*4)@l(11)
   10139        *   mtctr 11
   10140        *   bctr
   10141        *
   10142        * The branch table is the same, then comes
   10143        *
   10144        * PLTresolve:
   10145        *    lis 12,(got+4)@ha
   10146        *    addis 11,11,(-res_0)@ha
   10147        *    lwz 0,(got+4)@l(12)         # got[1] address of dl_runtime_resolve
   10148        *    addi 11,11,(-res_0)@l       # r11 = index * 4
   10149        *    mtctr 0
   10150        *    add 0,11,11
   10151        *    lwz 12,(got+8)@l(12)        # got[2] contains the map address
   10152        *    add 11,0,11                 # r11 = index * 12 = reloc offset.
   10153        *    bctr
   10154        */
   10155       static const unsigned int plt_resolve[] =
   10156 	{
   10157 	  LIS_12,
   10158 	  ADDIS_11_11,
   10159 	  LWZ_0_12,
   10160 	  ADDI_11_11,
   10161 	  MTCTR_0,
   10162 	  ADD_0_11_11,
   10163 	  LWZ_12_12,
   10164 	  ADD_11_0_11,
   10165 	  BCTR,
   10166 	  NOP,
   10167 	  NOP,
   10168 	  NOP,
   10169 	  NOP,
   10170 	  NOP,
   10171 	  NOP,
   10172 	  NOP
   10173 	};
   10174 
   10175       if (ARRAY_SIZE (pic_plt_resolve) != GLINK_PLTRESOLVE / 4)
   10176 	abort ();
   10177       if (ARRAY_SIZE (plt_resolve) != GLINK_PLTRESOLVE / 4)
   10178 	abort ();
   10179 
   10180       /* Build the branch table, one for each plt entry (less one),
   10181 	 and perhaps some padding.  */
   10182       p = htab->glink->contents;
   10183       p += htab->glink_pltresolve;
   10184       endp = htab->glink->contents;
   10185       endp += htab->glink->size - GLINK_PLTRESOLVE;
   10186       while (p < endp - (htab->params->ppc476_workaround ? 0 : 8 * 4))
   10187 	{
   10188 	  bfd_put_32 (output_bfd, B + endp - p, p);
   10189 	  p += 4;
   10190 	}
   10191       while (p < endp)
   10192 	{
   10193 	  bfd_put_32 (output_bfd, NOP, p);
   10194 	  p += 4;
   10195 	}
   10196 
   10197       res0 = (htab->glink_pltresolve
   10198 	      + htab->glink->output_section->vma
   10199 	      + htab->glink->output_offset);
   10200 
   10201       if (htab->params->ppc476_workaround)
   10202 	{
   10203 	  /* Ensure that a call stub at the end of a page doesn't
   10204 	     result in prefetch over the end of the page into the
   10205 	     glink branch table.  */
   10206 	  bfd_vma pagesize = (bfd_vma) 1 << htab->params->pagesize_p2;
   10207 	  bfd_vma page_addr;
   10208 	  bfd_vma glink_start = (htab->glink->output_section->vma
   10209 				 + htab->glink->output_offset);
   10210 
   10211 	  for (page_addr = res0 & -pagesize;
   10212 	       page_addr > glink_start;
   10213 	       page_addr -= pagesize)
   10214 	    {
   10215 	      /* We have a plt call stub that may need fixing.  */
   10216 	      bfd_byte *loc;
   10217 	      unsigned int insn;
   10218 
   10219 	      loc = htab->glink->contents + page_addr - 4 - glink_start;
   10220 	      insn = bfd_get_32 (output_bfd, loc);
   10221 	      if (insn == BCTR)
   10222 		{
   10223 		  /* By alignment, we know that there must be at least
   10224 		     one other call stub before this one.  */
   10225 		  insn = bfd_get_32 (output_bfd, loc - 16);
   10226 		  if (insn == BCTR)
   10227 		    bfd_put_32 (output_bfd, B | (-16 & 0x3fffffc), loc);
   10228 		  else
   10229 		    bfd_put_32 (output_bfd, B | (-20 & 0x3fffffc), loc);
   10230 		}
   10231 	    }
   10232 	}
   10233 
   10234       /* Last comes the PLTresolve stub.  */
   10235       if (info->shared)
   10236 	{
   10237 	  bfd_vma bcl;
   10238 
   10239 	  for (i = 0; i < ARRAY_SIZE (pic_plt_resolve); i++)
   10240 	    {
   10241 	      unsigned int insn = pic_plt_resolve[i];
   10242 
   10243 	      if (htab->params->ppc476_workaround && insn == NOP)
   10244 		insn = BA + 0;
   10245 	      bfd_put_32 (output_bfd, insn, p);
   10246 	      p += 4;
   10247 	    }
   10248 	  p -= 4 * ARRAY_SIZE (pic_plt_resolve);
   10249 
   10250 	  bcl = (htab->glink->size - GLINK_PLTRESOLVE + 3*4
   10251 		 + htab->glink->output_section->vma
   10252 		 + htab->glink->output_offset);
   10253 
   10254 	  bfd_put_32 (output_bfd,
   10255 		      ADDIS_11_11 + PPC_HA (bcl - res0), p + 0*4);
   10256 	  bfd_put_32 (output_bfd,
   10257 		      ADDI_11_11 + PPC_LO (bcl - res0), p + 3*4);
   10258 	  bfd_put_32 (output_bfd,
   10259 		      ADDIS_12_12 + PPC_HA (got + 4 - bcl), p + 7*4);
   10260 	  if (PPC_HA (got + 4 - bcl) == PPC_HA (got + 8 - bcl))
   10261 	    {
   10262 	      bfd_put_32 (output_bfd,
   10263 			  LWZ_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
   10264 	      bfd_put_32 (output_bfd,
   10265 			  LWZ_12_12 + PPC_LO (got + 8 - bcl), p + 9*4);
   10266 	    }
   10267 	  else
   10268 	    {
   10269 	      bfd_put_32 (output_bfd,
   10270 			  LWZU_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
   10271 	      bfd_put_32 (output_bfd,
   10272 			  LWZ_12_12 + 4, p + 9*4);
   10273 	    }
   10274 	}
   10275       else
   10276 	{
   10277 	  for (i = 0; i < ARRAY_SIZE (plt_resolve); i++)
   10278 	    {
   10279 	      unsigned int insn = plt_resolve[i];
   10280 
   10281 	      if (htab->params->ppc476_workaround && insn == NOP)
   10282 		insn = BA + 0;
   10283 	      bfd_put_32 (output_bfd, insn, p);
   10284 	      p += 4;
   10285 	    }
   10286 	  p -= 4 * ARRAY_SIZE (plt_resolve);
   10287 
   10288 	  bfd_put_32 (output_bfd,
   10289 		      LIS_12 + PPC_HA (got + 4), p + 0*4);
   10290 	  bfd_put_32 (output_bfd,
   10291 		      ADDIS_11_11 + PPC_HA (-res0), p + 1*4);
   10292 	  bfd_put_32 (output_bfd,
   10293 		      ADDI_11_11 + PPC_LO (-res0), p + 3*4);
   10294 	  if (PPC_HA (got + 4) == PPC_HA (got + 8))
   10295 	    {
   10296 	      bfd_put_32 (output_bfd,
   10297 			  LWZ_0_12 + PPC_LO (got + 4), p + 2*4);
   10298 	      bfd_put_32 (output_bfd,
   10299 			  LWZ_12_12 + PPC_LO (got + 8), p + 6*4);
   10300 	    }
   10301 	  else
   10302 	    {
   10303 	      bfd_put_32 (output_bfd,
   10304 			  LWZU_0_12 + PPC_LO (got + 4), p + 2*4);
   10305 	      bfd_put_32 (output_bfd,
   10306 			  LWZ_12_12 + 4, p + 6*4);
   10307 	    }
   10308 	}
   10309     }
   10310 
   10311   if (htab->glink_eh_frame != NULL
   10312       && htab->glink_eh_frame->contents != NULL)
   10313     {
   10314       unsigned char *p = htab->glink_eh_frame->contents;
   10315       bfd_vma val;
   10316 
   10317       p += sizeof (glink_eh_frame_cie);
   10318       /* FDE length.  */
   10319       p += 4;
   10320       /* CIE pointer.  */
   10321       p += 4;
   10322       /* Offset to .glink.  */
   10323       val = (htab->glink->output_section->vma
   10324 	     + htab->glink->output_offset);
   10325       val -= (htab->glink_eh_frame->output_section->vma
   10326 	      + htab->glink_eh_frame->output_offset);
   10327       val -= p - htab->glink_eh_frame->contents;
   10328       bfd_put_32 (htab->elf.dynobj, val, p);
   10329 
   10330       if (htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME
   10331 	  && !_bfd_elf_write_section_eh_frame (output_bfd, info,
   10332 					       htab->glink_eh_frame,
   10333 					       htab->glink_eh_frame->contents))
   10334 	return FALSE;
   10335     }
   10336 
   10337   return ret;
   10338 }
   10339 
   10340 #define TARGET_LITTLE_SYM	powerpc_elf32_le_vec
   10342 #define TARGET_LITTLE_NAME	"elf32-powerpcle"
   10343 #define TARGET_BIG_SYM		powerpc_elf32_vec
   10344 #define TARGET_BIG_NAME		"elf32-powerpc"
   10345 #define ELF_ARCH		bfd_arch_powerpc
   10346 #define ELF_TARGET_ID		PPC32_ELF_DATA
   10347 #define ELF_MACHINE_CODE	EM_PPC
   10348 #ifdef __QNXTARGET__
   10349 #define ELF_MAXPAGESIZE		0x1000
   10350 #else
   10351 #define ELF_MAXPAGESIZE		0x10000
   10352 #endif
   10353 #define ELF_MINPAGESIZE		0x1000
   10354 #define ELF_COMMONPAGESIZE	0x1000
   10355 #define elf_info_to_howto	ppc_elf_info_to_howto
   10356 
   10357 #ifdef  EM_CYGNUS_POWERPC
   10358 #define ELF_MACHINE_ALT1	EM_CYGNUS_POWERPC
   10359 #endif
   10360 
   10361 #ifdef EM_PPC_OLD
   10362 #define ELF_MACHINE_ALT2	EM_PPC_OLD
   10363 #endif
   10364 
   10365 #define elf_backend_plt_not_loaded	1
   10366 #define elf_backend_can_gc_sections	1
   10367 #define elf_backend_can_refcount	1
   10368 #define elf_backend_rela_normal		1
   10369 #define elf_backend_caches_rawsize	1
   10370 
   10371 #define bfd_elf32_mkobject			ppc_elf_mkobject
   10372 #define bfd_elf32_bfd_merge_private_bfd_data	ppc_elf_merge_private_bfd_data
   10373 #define bfd_elf32_bfd_relax_section		ppc_elf_relax_section
   10374 #define bfd_elf32_bfd_reloc_type_lookup		ppc_elf_reloc_type_lookup
   10375 #define bfd_elf32_bfd_reloc_name_lookup		ppc_elf_reloc_name_lookup
   10376 #define bfd_elf32_bfd_set_private_flags		ppc_elf_set_private_flags
   10377 #define bfd_elf32_bfd_link_hash_table_create	ppc_elf_link_hash_table_create
   10378 #define bfd_elf32_get_synthetic_symtab		ppc_elf_get_synthetic_symtab
   10379 
   10380 #define elf_backend_object_p			ppc_elf_object_p
   10381 #define elf_backend_gc_mark_hook		ppc_elf_gc_mark_hook
   10382 #define elf_backend_gc_sweep_hook		ppc_elf_gc_sweep_hook
   10383 #define elf_backend_section_from_shdr		ppc_elf_section_from_shdr
   10384 #define elf_backend_relocate_section		ppc_elf_relocate_section
   10385 #define elf_backend_create_dynamic_sections	ppc_elf_create_dynamic_sections
   10386 #define elf_backend_check_relocs		ppc_elf_check_relocs
   10387 #define elf_backend_copy_indirect_symbol	ppc_elf_copy_indirect_symbol
   10388 #define elf_backend_adjust_dynamic_symbol	ppc_elf_adjust_dynamic_symbol
   10389 #define elf_backend_add_symbol_hook		ppc_elf_add_symbol_hook
   10390 #define elf_backend_size_dynamic_sections	ppc_elf_size_dynamic_sections
   10391 #define elf_backend_hash_symbol			ppc_elf_hash_symbol
   10392 #define elf_backend_finish_dynamic_symbol	ppc_elf_finish_dynamic_symbol
   10393 #define elf_backend_finish_dynamic_sections	ppc_elf_finish_dynamic_sections
   10394 #define elf_backend_fake_sections		ppc_elf_fake_sections
   10395 #define elf_backend_additional_program_headers	ppc_elf_additional_program_headers
   10396 #define elf_backend_modify_segment_map     	ppc_elf_modify_segment_map
   10397 #define elf_backend_grok_prstatus		ppc_elf_grok_prstatus
   10398 #define elf_backend_grok_psinfo			ppc_elf_grok_psinfo
   10399 #define elf_backend_write_core_note		ppc_elf_write_core_note
   10400 #define elf_backend_reloc_type_class		ppc_elf_reloc_type_class
   10401 #define elf_backend_begin_write_processing	ppc_elf_begin_write_processing
   10402 #define elf_backend_final_write_processing	ppc_elf_final_write_processing
   10403 #define elf_backend_write_section		ppc_elf_write_section
   10404 #define elf_backend_get_sec_type_attr		ppc_elf_get_sec_type_attr
   10405 #define elf_backend_plt_sym_val			ppc_elf_plt_sym_val
   10406 #define elf_backend_action_discarded		ppc_elf_action_discarded
   10407 #define elf_backend_init_index_section		_bfd_elf_init_1_index_section
   10408 #define elf_backend_lookup_section_flags_hook	ppc_elf_lookup_section_flags
   10409 #define elf_backend_section_processing		ppc_elf_section_processing
   10410 
   10411 #include "elf32-target.h"
   10412 
   10413 /* FreeBSD Target */
   10414 
   10415 #undef  TARGET_LITTLE_SYM
   10416 #undef  TARGET_LITTLE_NAME
   10417 
   10418 #undef  TARGET_BIG_SYM
   10419 #define TARGET_BIG_SYM  powerpc_elf32_fbsd_vec
   10420 #undef  TARGET_BIG_NAME
   10421 #define TARGET_BIG_NAME "elf32-powerpc-freebsd"
   10422 
   10423 #undef  ELF_OSABI
   10424 #define ELF_OSABI	ELFOSABI_FREEBSD
   10425 
   10426 #undef  elf32_bed
   10427 #define elf32_bed	elf32_powerpc_fbsd_bed
   10428 
   10429 #include "elf32-target.h"
   10430 
   10431 /* VxWorks Target */
   10432 
   10433 #undef TARGET_LITTLE_SYM
   10434 #undef TARGET_LITTLE_NAME
   10435 
   10436 #undef TARGET_BIG_SYM
   10437 #define TARGET_BIG_SYM		powerpc_elf32_vxworks_vec
   10438 #undef TARGET_BIG_NAME
   10439 #define TARGET_BIG_NAME		"elf32-powerpc-vxworks"
   10440 
   10441 #undef  ELF_OSABI
   10442 
   10443 /* VxWorks uses the elf default section flags for .plt.  */
   10444 static const struct bfd_elf_special_section *
   10445 ppc_elf_vxworks_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
   10446 {
   10447   if (sec->name == NULL)
   10448     return NULL;
   10449 
   10450   if (strcmp (sec->name, ".plt") == 0)
   10451     return _bfd_elf_get_sec_type_attr (abfd, sec);
   10452 
   10453   return ppc_elf_get_sec_type_attr (abfd, sec);
   10454 }
   10455 
   10456 /* Like ppc_elf_link_hash_table_create, but overrides
   10457    appropriately for VxWorks.  */
   10458 static struct bfd_link_hash_table *
   10459 ppc_elf_vxworks_link_hash_table_create (bfd *abfd)
   10460 {
   10461   struct bfd_link_hash_table *ret;
   10462 
   10463   ret = ppc_elf_link_hash_table_create (abfd);
   10464   if (ret)
   10465     {
   10466       struct ppc_elf_link_hash_table *htab
   10467         = (struct ppc_elf_link_hash_table *)ret;
   10468       htab->is_vxworks = 1;
   10469       htab->plt_type = PLT_VXWORKS;
   10470       htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE;
   10471       htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE;
   10472       htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE;
   10473     }
   10474   return ret;
   10475 }
   10476 
   10477 /* Tweak magic VxWorks symbols as they are loaded.  */
   10478 static bfd_boolean
   10479 ppc_elf_vxworks_add_symbol_hook (bfd *abfd,
   10480 				 struct bfd_link_info *info,
   10481 				 Elf_Internal_Sym *sym,
   10482 				 const char **namep ATTRIBUTE_UNUSED,
   10483 				 flagword *flagsp ATTRIBUTE_UNUSED,
   10484 				 asection **secp,
   10485 				 bfd_vma *valp)
   10486 {
   10487   if (!elf_vxworks_add_symbol_hook(abfd, info, sym,namep, flagsp, secp,
   10488 				   valp))
   10489     return FALSE;
   10490 
   10491   return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp);
   10492 }
   10493 
   10494 static void
   10495 ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
   10496 {
   10497   ppc_elf_final_write_processing(abfd, linker);
   10498   elf_vxworks_final_write_processing(abfd, linker);
   10499 }
   10500 
   10501 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
   10502    define it.  */
   10503 #undef elf_backend_want_plt_sym
   10504 #define elf_backend_want_plt_sym		1
   10505 #undef elf_backend_want_got_plt
   10506 #define elf_backend_want_got_plt		1
   10507 #undef elf_backend_got_symbol_offset
   10508 #define elf_backend_got_symbol_offset		0
   10509 #undef elf_backend_plt_not_loaded
   10510 #define elf_backend_plt_not_loaded		0
   10511 #undef elf_backend_plt_readonly
   10512 #define elf_backend_plt_readonly		1
   10513 #undef elf_backend_got_header_size
   10514 #define elf_backend_got_header_size		12
   10515 
   10516 #undef bfd_elf32_get_synthetic_symtab
   10517 
   10518 #undef bfd_elf32_bfd_link_hash_table_create
   10519 #define bfd_elf32_bfd_link_hash_table_create \
   10520   ppc_elf_vxworks_link_hash_table_create
   10521 #undef elf_backend_add_symbol_hook
   10522 #define elf_backend_add_symbol_hook \
   10523   ppc_elf_vxworks_add_symbol_hook
   10524 #undef elf_backend_link_output_symbol_hook
   10525 #define elf_backend_link_output_symbol_hook \
   10526   elf_vxworks_link_output_symbol_hook
   10527 #undef elf_backend_final_write_processing
   10528 #define elf_backend_final_write_processing \
   10529   ppc_elf_vxworks_final_write_processing
   10530 #undef elf_backend_get_sec_type_attr
   10531 #define elf_backend_get_sec_type_attr \
   10532   ppc_elf_vxworks_get_sec_type_attr
   10533 #undef elf_backend_emit_relocs
   10534 #define elf_backend_emit_relocs \
   10535   elf_vxworks_emit_relocs
   10536 
   10537 #undef elf32_bed
   10538 #define elf32_bed				ppc_elf_vxworks_bed
   10539 #undef elf_backend_post_process_headers
   10540 
   10541 #include "elf32-target.h"
   10542