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