Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/elf32-ppc.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* PowerPC-specific support for 32-bit ELF
    2    Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
     2   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    33   Free Software Foundation, Inc.
    44   Written by Ian Lance Taylor, Cygnus Support.
    55
    6 This file is part of BFD, the Binary File Descriptor library.
    7 
    8 This program is free software; you can redistribute it and/or modify
    9 it under the terms of the GNU General Public License as published by
    10 the Free Software Foundation; either version 2 of the License, or
    11 (at your option) any later version.
    12 
    13 This program is distributed in the hope that it will be useful,
    14 but WITHOUT ANY WARRANTY; without even the implied warranty of
    15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16 GNU General Public License for more details.
    17 
    18 You should have received a copy of the GNU General Public License
    19 along with this program; if not, write to the Free Software
    20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
     6   This file is part of BFD, the Binary File Descriptor library.
     7
     8   This program is free software; you can redistribute it and/or modify
     9   it under the terms of the GNU General Public License as published by
     10   the Free Software Foundation; either version 2 of the License, or
     11   (at your option) any later version.
     12
     13   This program is distributed in the hope that it will be useful,
     14   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16   GNU General Public License for more details.
     17
     18   You should have received a copy of the GNU General Public License
     19   along with this program; if not, write to the
     20   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     21   Boston, MA 02111-1307, USA.  */
    2122
    2223/* This file is based on a preliminary PowerPC ELF ABI.  The
     
    3132#include "elf-bfd.h"
    3233#include "elf/ppc.h"
    33 
    34 #define USE_RELA                /* we want RELA relocations, not REL */
    35 
     34#include "elf32-ppc.h"
     35
     36/* RELA relocations are used here.  */
     37
     38static struct bfd_hash_entry *ppc_elf_link_hash_newfunc
     39  PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
     40           const char *string));
     41static struct bfd_link_hash_table *ppc_elf_link_hash_table_create
     42  PARAMS ((bfd *abfd));
     43static void ppc_elf_copy_indirect_symbol
     44  PARAMS ((struct elf_backend_data *bed, struct elf_link_hash_entry *dir,
     45           struct elf_link_hash_entry *ind));
    3646static reloc_howto_type *ppc_elf_reloc_type_lookup
    3747  PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
    3848static void ppc_elf_info_to_howto
    39   PARAMS ((bfd *abfd, arelent *cache_ptr, Elf32_Internal_Rela *dst));
    40 static void ppc_elf_howto_init PARAMS ((void));
     49  PARAMS ((bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst));
     50static void ppc_elf_howto_init
     51  PARAMS ((void));
     52static int ppc_elf_sort_rela
     53  PARAMS ((const PTR, const PTR));
     54static bfd_boolean ppc_elf_relax_section
     55  PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
    4156static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
    4257  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
    43 static boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword));
    44 static boolean ppc_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
    45 static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
    46 
    47 static int ppc_elf_additional_program_headers PARAMS ((bfd *));
    48 static boolean ppc_elf_modify_segment_map PARAMS ((bfd *));
    49 
    50 static boolean ppc_elf_create_dynamic_sections
     58static bfd_reloc_status_type ppc_elf_unhandled_reloc
     59  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
     60static bfd_boolean ppc_elf_object_p
     61  PARAMS ((bfd *));
     62static bfd_boolean ppc_elf_set_private_flags
     63  PARAMS ((bfd *, flagword));
     64static bfd_boolean ppc_elf_merge_private_bfd_data
     65  PARAMS ((bfd *, bfd *));
     66static int ppc_elf_additional_program_headers
     67  PARAMS ((bfd *));
     68static bfd_boolean ppc_elf_modify_segment_map
     69  PARAMS ((bfd *));
     70static bfd_boolean ppc_elf_create_got
    5171  PARAMS ((bfd *, struct bfd_link_info *));
    52 
    53 static boolean ppc_elf_section_from_shdr PARAMS ((bfd *,
    54                                                   Elf32_Internal_Shdr *,
    55                                                   char *));
    56 static boolean ppc_elf_fake_sections
    57   PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *));
    58 
     72static bfd_boolean ppc_elf_create_dynamic_sections
     73  PARAMS ((bfd *, struct bfd_link_info *));
     74static bfd_boolean ppc_elf_section_from_shdr
     75  PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
     76static bfd_boolean ppc_elf_fake_sections
     77  PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
    5978static elf_linker_section_t *ppc_elf_create_linker_section
    60   PARAMS ((bfd *abfd,
    61            struct bfd_link_info *info,
     79  PARAMS ((bfd *abfd, struct bfd_link_info *info,
    6280           enum elf_linker_section_enum));
    63 
    64 static boolean ppc_elf_check_relocs PARAMS ((bfd *,
    65                                              struct bfd_link_info *,
    66                                              asection *,
    67                                              const Elf_Internal_Rela *));
    68 
    69 static asection * ppc_elf_gc_mark_hook PARAMS ((bfd *abfd,
    70                                                 struct bfd_link_info *info,
    71                                                 Elf_Internal_Rela *rel,
    72                                                 struct elf_link_hash_entry *h,
    73                                                 Elf_Internal_Sym *sym));
    74 
    75 static boolean ppc_elf_gc_sweep_hook PARAMS ((bfd *abfd,
    76                                               struct bfd_link_info *info,
    77                                               asection *sec,
    78                                               const Elf_Internal_Rela *relocs));
    79 
    80 static boolean ppc_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *,
    81                                                       struct elf_link_hash_entry *));
    82 
    83 static boolean ppc_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
    84 
    85 static boolean ppc_elf_relocate_section PARAMS ((bfd *,
    86                                                  struct bfd_link_info *info,
    87                                                  bfd *,
    88                                                  asection *,
    89                                                  bfd_byte *,
    90                                                  Elf_Internal_Rela *relocs,
    91                                                  Elf_Internal_Sym *local_syms,
    92                                                  asection **));
    93 
    94 static boolean ppc_elf_add_symbol_hook  PARAMS ((bfd *,
    95                                                  struct bfd_link_info *,
    96                                                  const Elf_Internal_Sym *,
    97                                                  const char **,
    98                                                  flagword *,
    99                                                  asection **,
    100                                                  bfd_vma *));
    101 
    102 static boolean ppc_elf_finish_dynamic_symbol PARAMS ((bfd *,
    103                                                       struct bfd_link_info *,
    104                                                       struct elf_link_hash_entry *,
    105                                                       Elf_Internal_Sym *));
    106 
    107 static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
    108 
    109 #define BRANCH_PREDICT_BIT 0x200000             /* branch prediction bit for branch taken relocs */
    110 #define RA_REGISTER_MASK 0x001f0000             /* mask to set RA in memory instructions */
    111 #define RA_REGISTER_SHIFT 16                    /* value to shift register by to insert RA */
     81static bfd_boolean update_local_sym_info
     82  PARAMS ((bfd *, Elf_Internal_Shdr *, unsigned long, int));
     83static void bad_shared_reloc
     84  PARAMS ((bfd *, enum elf_ppc_reloc_type));
     85static bfd_boolean ppc_elf_check_relocs
     86  PARAMS ((bfd *, struct bfd_link_info *, asection *,
     87           const Elf_Internal_Rela *));
     88static asection *ppc_elf_gc_mark_hook
     89  PARAMS ((asection *sec, struct bfd_link_info *info, Elf_Internal_Rela *rel,
     90           struct elf_link_hash_entry *h, Elf_Internal_Sym *sym));
     91static bfd_boolean ppc_elf_gc_sweep_hook
     92  PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
     93           const Elf_Internal_Rela *relocs));
     94static bfd_boolean ppc_elf_adjust_dynamic_symbol
     95  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
     96static bfd_boolean allocate_dynrelocs
     97  PARAMS ((struct elf_link_hash_entry *, PTR));
     98static bfd_boolean readonly_dynrelocs
     99  PARAMS ((struct elf_link_hash_entry *, PTR));
     100static bfd_boolean ppc_elf_size_dynamic_sections
     101  PARAMS ((bfd *, struct bfd_link_info *));
     102static bfd_boolean ppc_elf_relocate_section
     103  PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *,
     104           Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
     105           asection **));
     106static bfd_boolean ppc_elf_add_symbol_hook
     107  PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
     108           const char **, flagword *, asection **, bfd_vma *));
     109static bfd_boolean ppc_elf_finish_dynamic_symbol
     110  PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
     111           Elf_Internal_Sym *));
     112static bfd_boolean ppc_elf_finish_dynamic_sections
     113  PARAMS ((bfd *, struct bfd_link_info *));
     114static enum elf_reloc_type_class ppc_elf_reloc_type_class
     115  PARAMS ((const Elf_Internal_Rela *));
     116static bfd_boolean ppc_elf_grok_prstatus
     117  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
     118static bfd_boolean ppc_elf_grok_psinfo
     119  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
     120
     121/* Branch prediction bit for branch taken relocs.  */
     122#define BRANCH_PREDICT_BIT 0x200000
     123/* Mask to set RA in memory instructions.  */
     124#define RA_REGISTER_MASK 0x001f0000
     125/* Value to shift register by to insert RA.  */
     126#define RA_REGISTER_SHIFT 16
    112127
    113128/* The name of the dynamic interpreter.  This is put in the .interp
    114129   section.  */
    115 
    116130#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
    117131
     
    125139#define PLT_NUM_SINGLE_ENTRIES 8192
    126140
     141/* Some nop instructions.  */
     142#define NOP             0x60000000
     143#define CROR_151515     0x4def7b82
     144#define CROR_313131     0x4ffffb82
     145
     146/* Offset of tp and dtp pointers from start of TLS block.  */
     147#define TP_OFFSET       0x7000
     148#define DTP_OFFSET      0x8000
     149
    127150/* Will references to this symbol always reference the symbol
    128    in this object?  */
     151   in this object?  STV_PROTECTED is excluded from the visibility test
     152   here so that function pointer comparisons work properly.  Since
     153   function symbols not defined in an app are set to their .plt entry,
     154   it's necessary for shared libs to also reference the .plt even
     155   though the symbol is really local to the shared lib.  */
    129156#define SYMBOL_REFERENCES_LOCAL(INFO, H)                                \
    130157  ((! INFO->shared                                                      \
     
    136163
    137164/* Will _calls_ to this symbol always call the version in this object?  */
    138 #define SYMBOL_CALLS_LOCAL(INFO, H)                             \
     165#define SYMBOL_CALLS_LOCAL(INFO, H)                                     \
    139166  ((! INFO->shared                                                      \
    140167    || INFO->symbolic                                                   \
     
    142169    || ELF_ST_VISIBILITY (H->other) != STV_DEFAULT)                     \
    143170   && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
     171
     172
     173/* The PPC linker needs to keep track of the number of relocs that it
     174   decides to copy as dynamic relocs in check_relocs for each symbol.
     175   This is so that it can later discard them if they are found to be
     176   unnecessary.  We store the information in a field extending the
     177   regular ELF linker hash table.  */
     178
     179struct ppc_elf_dyn_relocs
     180{
     181  struct ppc_elf_dyn_relocs *next;
     182
     183  /* The input section of the reloc.  */
     184  asection *sec;
     185
     186  /* Total number of relocs copied for the input section.  */
     187  bfd_size_type count;
     188
     189  /* Number of pc-relative relocs copied for the input section.  */
     190  bfd_size_type pc_count;
     191};
     192
     193/* PPC ELF linker hash entry.  */
     194
     195struct ppc_elf_link_hash_entry
     196{
     197  struct elf_link_hash_entry elf;
     198
     199  /* Track dynamic relocs copied for this symbol.  */
     200  struct ppc_elf_dyn_relocs *dyn_relocs;
     201
     202  /* Contexts in which symbol is used in the GOT (or TOC).
     203     TLS_GD .. TLS_TLS bits are or'd into the mask as the
     204     corresponding relocs are encountered during check_relocs.
     205     tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
     206     indicate the corresponding GOT entry type is not needed.  */
     207#define TLS_GD           1      /* GD reloc. */
     208#define TLS_LD           2      /* LD reloc. */
     209#define TLS_TPREL        4      /* TPREL reloc, => IE. */
     210#define TLS_DTPREL       8      /* DTPREL reloc, => LD. */
     211#define TLS_TLS         16      /* Any TLS reloc.  */
     212#define TLS_TPRELGD     32      /* TPREL reloc resulting from GD->IE. */
     213  char tls_mask;
     214};
     215
     216#define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
     217
     218/* PPC ELF linker hash table.  */
     219
     220struct ppc_elf_link_hash_table
     221{
     222  struct elf_link_hash_table elf;
     223
     224  /* Short-cuts to get to dynamic linker sections.  */
     225  asection *got;
     226  asection *relgot;
     227  asection *plt;
     228  asection *relplt;
     229  asection *dynbss;
     230  asection *relbss;
     231  asection *dynsbss;
     232  asection *relsbss;
     233  elf_linker_section_t *sdata;
     234  elf_linker_section_t *sdata2;
     235
     236  /* Short-cut to first output tls section.  */
     237  asection *tls_sec;
     238
     239  /* Shortcut to .__tls_get_addr.  */
     240  struct elf_link_hash_entry *tls_get_addr;
     241
     242  /* TLS local dynamic got entry handling.  */
     243  union {
     244    bfd_signed_vma refcount;
     245    bfd_vma offset;
     246  } tlsld_got;
     247
     248  /* Small local sym to section mapping cache.  */
     249  struct sym_sec_cache sym_sec;
     250};
     251
     252/* Get the PPC ELF linker hash table from a link_info structure.  */
     253
     254#define ppc_elf_hash_table(p) \
     255  ((struct ppc_elf_link_hash_table *) (p)->hash)
     256
     257/* Create an entry in a PPC ELF linker hash table.  */
     258
     259static struct bfd_hash_entry *
     260ppc_elf_link_hash_newfunc (entry, table, string)
     261     struct bfd_hash_entry *entry;
     262     struct bfd_hash_table *table;
     263     const char *string;
     264{
     265  /* Allocate the structure if it has not already been allocated by a
     266     subclass.  */
     267  if (entry == NULL)
     268    {
     269      entry = bfd_hash_allocate (table,
     270                                 sizeof (struct ppc_elf_link_hash_entry));
     271      if (entry == NULL)
     272        return entry;
     273    }
     274
     275  /* Call the allocation method of the superclass.  */
     276  entry = _bfd_elf_link_hash_newfunc (entry, table, string);
     277  if (entry != NULL)
     278    {
     279      ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
     280      ppc_elf_hash_entry (entry)->tls_mask = 0;
     281    }
     282
     283  return entry;
     284}
     285
     286/* Create a PPC ELF linker hash table.  */
     287
     288static struct bfd_link_hash_table *
     289ppc_elf_link_hash_table_create (abfd)
     290     bfd *abfd;
     291{
     292  struct ppc_elf_link_hash_table *ret;
     293
     294  ret = ((struct ppc_elf_link_hash_table *)
     295         bfd_malloc (sizeof (struct ppc_elf_link_hash_table)));
     296  if (ret == NULL)
     297    return NULL;
     298
     299  if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
     300                                       ppc_elf_link_hash_newfunc))
     301    {
     302      free (ret);
     303      return NULL;
     304    }
     305
     306  ret->got = NULL;
     307  ret->relgot = NULL;
     308  ret->plt = NULL;
     309  ret->relplt = NULL;
     310  ret->dynbss = NULL;
     311  ret->relbss = NULL;
     312  ret->dynsbss = NULL;
     313  ret->relsbss = NULL;
     314  ret->sdata = NULL;
     315  ret->sdata2 = NULL;
     316  ret->tls_sec = NULL;
     317  ret->tls_get_addr = NULL;
     318  ret->tlsld_got.refcount = 0;
     319  ret->sym_sec.abfd = NULL;
     320
     321  return &ret->elf.root;
     322}
     323
     324/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
     325   copying dynamic variables from a shared lib into an app's dynbss
     326   section, and instead use a dynamic relocation to point into the
     327   shared lib.  */
     328#define ELIMINATE_COPY_RELOCS 1
     329
     330/* Copy the extra info we tack onto an elf_link_hash_entry.  */
     331
     332static void
     333ppc_elf_copy_indirect_symbol (bed, dir, ind)
     334     struct elf_backend_data *bed;
     335     struct elf_link_hash_entry *dir, *ind;
     336{
     337  struct ppc_elf_link_hash_entry *edir, *eind;
     338
     339  edir = (struct ppc_elf_link_hash_entry *) dir;
     340  eind = (struct ppc_elf_link_hash_entry *) ind;
     341
     342  if (eind->dyn_relocs != NULL)
     343    {
     344      if (edir->dyn_relocs != NULL)
     345        {
     346          struct ppc_elf_dyn_relocs **pp;
     347          struct ppc_elf_dyn_relocs *p;
     348
     349          if (ind->root.type == bfd_link_hash_indirect)
     350            abort ();
     351
     352          /* Add reloc counts against the weak sym to the strong sym
     353             list.  Merge any entries against the same section.  */
     354          for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
     355            {
     356              struct ppc_elf_dyn_relocs *q;
     357
     358              for (q = edir->dyn_relocs; q != NULL; q = q->next)
     359                if (q->sec == p->sec)
     360                  {
     361                    q->pc_count += p->pc_count;
     362                    q->count += p->count;
     363                    *pp = p->next;
     364                    break;
     365                  }
     366              if (q == NULL)
     367                pp = &p->next;
     368            }
     369          *pp = edir->dyn_relocs;
     370        }
     371
     372      edir->dyn_relocs = eind->dyn_relocs;
     373      eind->dyn_relocs = NULL;
     374    }
     375
     376  edir->tls_mask |= eind->tls_mask;
     377
     378  if (ELIMINATE_COPY_RELOCS
     379      && ind->root.type != bfd_link_hash_indirect
     380      && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
     381    /* If called to transfer flags for a weakdef during processing
     382       of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
     383       We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
     384    dir->elf_link_hash_flags |=
     385      (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
     386                                   | ELF_LINK_HASH_REF_REGULAR
     387                                   | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
     388  else
     389    _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
     390}
    144391
    145392
     
    152399         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    153400         32,                    /* bitsize */
    154          false,                 /* pc_relative */
     401         FALSE,                 /* pc_relative */
    155402         0,                     /* bitpos */
    156403         complain_overflow_bitfield, /* complain_on_overflow */
    157404         bfd_elf_generic_reloc, /* special_function */
    158405         "R_PPC_NONE",          /* name */
    159          false,                 /* partial_inplace */
     406         FALSE,                 /* partial_inplace */
    160407         0,                     /* src_mask */
    161408         0,                     /* dst_mask */
    162          false),                /* pcrel_offset */
     409         FALSE),                /* pcrel_offset */
    163410
    164411  /* A standard 32 bit relocation.  */
     
    167414         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    168415         32,                    /* bitsize */
    169          false,                 /* pc_relative */
     416         FALSE,                 /* pc_relative */
    170417         0,                     /* bitpos */
    171418         complain_overflow_bitfield, /* complain_on_overflow */
    172419         bfd_elf_generic_reloc, /* special_function */
    173420         "R_PPC_ADDR32",        /* name */
    174          false,                 /* partial_inplace */
     421         FALSE,                 /* partial_inplace */
    175422         0,                     /* src_mask */
    176423         0xffffffff,            /* dst_mask */
    177          false),                /* pcrel_offset */
     424         FALSE),                /* pcrel_offset */
    178425
    179426  /* An absolute 26 bit branch; the lower two bits must be zero.
     
    183430         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    184431         26,                    /* bitsize */
    185          false,                 /* pc_relative */
     432         FALSE,                 /* pc_relative */
    186433         0,                     /* bitpos */
    187434         complain_overflow_bitfield, /* complain_on_overflow */
    188435         bfd_elf_generic_reloc, /* special_function */
    189436         "R_PPC_ADDR24",        /* name */
    190          false,                 /* partial_inplace */
     437         FALSE,                 /* partial_inplace */
    191438         0,                     /* src_mask */
    192439         0x3fffffc,             /* dst_mask */
    193          false),                /* pcrel_offset */
     440         FALSE),                /* pcrel_offset */
    194441
    195442  /* A standard 16 bit relocation.  */
     
    198445         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    199446         16,                    /* bitsize */
    200          false,                 /* pc_relative */
     447         FALSE,                 /* pc_relative */
    201448         0,                     /* bitpos */
    202449         complain_overflow_bitfield, /* complain_on_overflow */
    203450         bfd_elf_generic_reloc, /* special_function */
    204451         "R_PPC_ADDR16",        /* name */
    205          false,                 /* partial_inplace */
     452         FALSE,                 /* partial_inplace */
    206453         0,                     /* src_mask */
    207454         0xffff,                /* dst_mask */
    208          false),                /* pcrel_offset */
     455         FALSE),                /* pcrel_offset */
    209456
    210457  /* A 16 bit relocation without overflow.  */
     
    213460         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    214461         16,                    /* bitsize */
    215          false,                 /* pc_relative */
     462         FALSE,                 /* pc_relative */
    216463         0,                     /* bitpos */
    217464         complain_overflow_dont,/* complain_on_overflow */
    218465         bfd_elf_generic_reloc, /* special_function */
    219466         "R_PPC_ADDR16_LO",     /* name */
    220          false,                 /* partial_inplace */
     467         FALSE,                 /* partial_inplace */
    221468         0,                     /* src_mask */
    222469         0xffff,                /* dst_mask */
    223          false),                /* pcrel_offset */
     470         FALSE),                /* pcrel_offset */
    224471
    225472  /* The high order 16 bits of an address.  */
     
    228475         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    229476         16,                    /* bitsize */
    230          false,                 /* pc_relative */
     477         FALSE,                 /* pc_relative */
    231478         0,                     /* bitpos */
    232479         complain_overflow_dont, /* complain_on_overflow */
    233480         bfd_elf_generic_reloc, /* special_function */
    234481         "R_PPC_ADDR16_HI",     /* name */
    235          false,                 /* partial_inplace */
     482         FALSE,                 /* partial_inplace */
    236483         0,                     /* src_mask */
    237484         0xffff,                /* dst_mask */
    238          false),                /* pcrel_offset */
     485         FALSE),                /* pcrel_offset */
    239486
    240487  /* The high order 16 bits of an address, plus 1 if the contents of
     
    244491         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    245492         16,                    /* bitsize */
    246          false,                 /* pc_relative */
     493         FALSE,                 /* pc_relative */
    247494         0,                     /* bitpos */
    248495         complain_overflow_dont, /* complain_on_overflow */
    249496         ppc_elf_addr16_ha_reloc, /* special_function */
    250497         "R_PPC_ADDR16_HA",     /* name */
    251          false,                 /* partial_inplace */
     498         FALSE,                 /* partial_inplace */
    252499         0,                     /* src_mask */
    253500         0xffff,                /* dst_mask */
    254          false),                /* pcrel_offset */
     501         FALSE),                /* pcrel_offset */
    255502
    256503  /* An absolute 16 bit branch; the lower two bits must be zero.
     
    260507         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    261508         16,                    /* bitsize */
    262          false,                 /* pc_relative */
     509         FALSE,                 /* pc_relative */
    263510         0,                     /* bitpos */
    264511         complain_overflow_bitfield, /* complain_on_overflow */
    265512         bfd_elf_generic_reloc, /* special_function */
    266513         "R_PPC_ADDR14",        /* name */
    267          false,                 /* partial_inplace */
     514         FALSE,                 /* partial_inplace */
    268515         0,                     /* src_mask */
    269516         0xfffc,                /* dst_mask */
    270          false),                /* pcrel_offset */
     517         FALSE),                /* pcrel_offset */
    271518
    272519  /* An absolute 16 bit branch, for which bit 10 should be set to
     
    277524         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    278525         16,                    /* bitsize */
    279          false,                 /* pc_relative */
     526         FALSE,                 /* pc_relative */
    280527         0,                     /* bitpos */
    281528         complain_overflow_bitfield, /* complain_on_overflow */
    282529         bfd_elf_generic_reloc, /* special_function */
    283530         "R_PPC_ADDR14_BRTAKEN",/* name */
    284          false,                 /* partial_inplace */
     531         FALSE,                 /* partial_inplace */
    285532         0,                     /* src_mask */
    286533         0xfffc,                /* dst_mask */
    287          false),                /* pcrel_offset */
     534         FALSE),                /* pcrel_offset */
    288535
    289536  /* An absolute 16 bit branch, for which bit 10 should be set to
     
    294541         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    295542         16,                    /* bitsize */
    296          false,                 /* pc_relative */
     543         FALSE,                 /* pc_relative */
    297544         0,                     /* bitpos */
    298545         complain_overflow_bitfield, /* complain_on_overflow */
    299546         bfd_elf_generic_reloc, /* special_function */
    300547         "R_PPC_ADDR14_BRNTAKEN",/* name */
    301          false,                 /* partial_inplace */
     548         FALSE,                 /* partial_inplace */
    302549         0,                     /* src_mask */
    303550         0xfffc,                /* dst_mask */
    304          false),                /* pcrel_offset */
     551         FALSE),                /* pcrel_offset */
    305552
    306553  /* A relative 26 bit branch; the lower two bits must be zero.  */
     
    309556         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    310557         26,                    /* bitsize */
    311          true,                  /* pc_relative */
     558         TRUE,                  /* pc_relative */
    312559         0,                     /* bitpos */
    313560         complain_overflow_signed, /* complain_on_overflow */
    314561         bfd_elf_generic_reloc, /* special_function */
    315562         "R_PPC_REL24",         /* name */
    316          false,                 /* partial_inplace */
     563         FALSE,                 /* partial_inplace */
    317564         0,                     /* src_mask */
    318565         0x3fffffc,             /* dst_mask */
    319          true),                 /* pcrel_offset */
     566         TRUE),                 /* pcrel_offset */
    320567
    321568  /* A relative 16 bit branch; the lower two bits must be zero.  */
     
    324571         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    325572         16,                    /* bitsize */
    326          true,                  /* pc_relative */
     573         TRUE,                  /* pc_relative */
    327574         0,                     /* bitpos */
    328575         complain_overflow_signed, /* complain_on_overflow */
    329576         bfd_elf_generic_reloc, /* special_function */
    330577         "R_PPC_REL14",         /* name */
    331          false,                 /* partial_inplace */
     578         FALSE,                 /* partial_inplace */
    332579         0,                     /* src_mask */
    333580         0xfffc,                /* dst_mask */
    334          true),                 /* pcrel_offset */
     581         TRUE),                 /* pcrel_offset */
    335582
    336583  /* A relative 16 bit branch.  Bit 10 should be set to indicate that
     
    341588         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    342589         16,                    /* bitsize */
    343          true,                  /* pc_relative */
     590         TRUE,                  /* pc_relative */
    344591         0,                     /* bitpos */
    345592         complain_overflow_signed, /* complain_on_overflow */
    346593         bfd_elf_generic_reloc, /* special_function */
    347594         "R_PPC_REL14_BRTAKEN", /* name */
    348          false,                 /* partial_inplace */
     595         FALSE,                 /* partial_inplace */
    349596         0,                     /* src_mask */
    350597         0xfffc,                /* dst_mask */
    351          true),                 /* pcrel_offset */
     598         TRUE),                 /* pcrel_offset */
    352599
    353600  /* A relative 16 bit branch.  Bit 10 should be set to indicate that
     
    358605         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    359606         16,                    /* bitsize */
    360          true,                  /* pc_relative */
     607         TRUE,                  /* pc_relative */
    361608         0,                     /* bitpos */
    362609         complain_overflow_signed, /* complain_on_overflow */
    363610         bfd_elf_generic_reloc, /* special_function */
    364611         "R_PPC_REL14_BRNTAKEN",/* name */
    365          false,                 /* partial_inplace */
     612         FALSE,                 /* partial_inplace */
    366613         0,                     /* src_mask */
    367614         0xfffc,                /* dst_mask */
    368          true),                 /* pcrel_offset */
     615         TRUE),                 /* pcrel_offset */
    369616
    370617  /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
     
    374621         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    375622         16,                    /* bitsize */
    376          false,                 /* pc_relative */
     623         FALSE,                 /* pc_relative */
    377624         0,                     /* bitpos */
    378625         complain_overflow_signed, /* complain_on_overflow */
    379626         bfd_elf_generic_reloc, /* special_function */
    380627         "R_PPC_GOT16",         /* name */
    381          false,                 /* partial_inplace */
     628         FALSE,                 /* partial_inplace */
    382629         0,                     /* src_mask */
    383630         0xffff,                /* dst_mask */
    384          false),                /* pcrel_offset */
     631         FALSE),                /* pcrel_offset */
    385632
    386633  /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
     
    390637         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    391638         16,                    /* bitsize */
    392          false,                 /* pc_relative */
     639         FALSE,                 /* pc_relative */
    393640         0,                     /* bitpos */
    394641         complain_overflow_dont, /* complain_on_overflow */
    395642         bfd_elf_generic_reloc, /* special_function */
    396643         "R_PPC_GOT16_LO",      /* name */
    397          false,                 /* partial_inplace */
     644         FALSE,                 /* partial_inplace */
    398645         0,                     /* src_mask */
    399646         0xffff,                /* dst_mask */
    400          false),                /* pcrel_offset */
     647         FALSE),                /* pcrel_offset */
    401648
    402649  /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
     
    406653         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    407654         16,                    /* bitsize */
    408          false,                 /* pc_relative */
     655         FALSE,                 /* pc_relative */
    409656         0,                     /* bitpos */
    410657         complain_overflow_bitfield, /* complain_on_overflow */
    411658         bfd_elf_generic_reloc, /* special_function */
    412659         "R_PPC_GOT16_HI",      /* name */
    413          false,                 /* partial_inplace */
     660         FALSE,                 /* partial_inplace */
    414661         0,                     /* src_mask */
    415662         0xffff,                /* dst_mask */
    416          false),                 /* pcrel_offset */
     663         FALSE),                 /* pcrel_offset */
    417664
    418665  /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
     
    422669         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    423670         16,                    /* bitsize */
    424          false,                 /* pc_relative */
     671         FALSE,                 /* pc_relative */
    425672         0,                     /* bitpos */
    426673         complain_overflow_bitfield, /* complain_on_overflow */
    427674         ppc_elf_addr16_ha_reloc, /* special_function */
    428675         "R_PPC_GOT16_HA",      /* name */
    429          false,                 /* partial_inplace */
     676         FALSE,                 /* partial_inplace */
    430677         0,                     /* src_mask */
    431678         0xffff,                /* dst_mask */
    432          false),                /* pcrel_offset */
     679         FALSE),                /* pcrel_offset */
    433680
    434681  /* Like R_PPC_REL24, but referring to the procedure linkage table
     
    438685         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    439686         26,                    /* bitsize */
    440          true,                  /* pc_relative */
     687         TRUE,                  /* pc_relative */
    441688         0,                     /* bitpos */
    442689         complain_overflow_signed,  /* complain_on_overflow */
    443690         bfd_elf_generic_reloc, /* special_function */
    444691         "R_PPC_PLTREL24",      /* name */
    445          false,                 /* partial_inplace */
     692         FALSE,                 /* partial_inplace */
    446693         0,                     /* src_mask */
    447694         0x3fffffc,             /* dst_mask */
    448          true),                 /* pcrel_offset */
     695         TRUE),                 /* pcrel_offset */
    449696
    450697  /* This is used only by the dynamic linker.  The symbol should exist
     
    457704         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    458705         32,                    /* bitsize */
    459          false,                 /* pc_relative */
     706         FALSE,                 /* pc_relative */
    460707         0,                     /* bitpos */
    461708         complain_overflow_bitfield, /* complain_on_overflow */
    462709         bfd_elf_generic_reloc,  /* special_function */
    463710         "R_PPC_COPY",          /* name */
    464          false,                 /* partial_inplace */
     711         FALSE,                 /* partial_inplace */
    465712         0,                     /* src_mask */
    466713         0,                     /* dst_mask */
    467          false),                /* pcrel_offset */
     714         FALSE),                /* pcrel_offset */
    468715
    469716  /* Like R_PPC_ADDR32, but used when setting global offset table
     
    473720         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    474721         32,                    /* bitsize */
    475          false,                 /* pc_relative */
     722         FALSE,                 /* pc_relative */
    476723         0,                     /* bitpos */
    477724         complain_overflow_bitfield, /* complain_on_overflow */
    478725         bfd_elf_generic_reloc,  /* special_function */
    479726         "R_PPC_GLOB_DAT",      /* name */
    480          false,                 /* partial_inplace */
     727         FALSE,                 /* partial_inplace */
    481728         0,                     /* src_mask */
    482729         0xffffffff,            /* dst_mask */
    483          false),                /* pcrel_offset */
     730         FALSE),                /* pcrel_offset */
    484731
    485732  /* Marks a procedure linkage table entry for a symbol.  */
     
    488735         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    489736         32,                    /* bitsize */
    490          false,                 /* pc_relative */
     737         FALSE,                 /* pc_relative */
    491738         0,                     /* bitpos */
    492739         complain_overflow_bitfield, /* complain_on_overflow */
    493740         bfd_elf_generic_reloc,  /* special_function */
    494741         "R_PPC_JMP_SLOT",      /* name */
    495          false,                 /* partial_inplace */
     742         FALSE,                 /* partial_inplace */
    496743         0,                     /* src_mask */
    497744         0,                     /* dst_mask */
    498          false),                /* pcrel_offset */
     745         FALSE),                /* pcrel_offset */
    499746
    500747  /* Used only by the dynamic linker.  When the object is run, this
     
    505752         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    506753         32,                    /* bitsize */
    507          false,                 /* pc_relative */
     754         FALSE,                 /* pc_relative */
    508755         0,                     /* bitpos */
    509756         complain_overflow_bitfield, /* complain_on_overflow */
    510757         bfd_elf_generic_reloc,  /* special_function */
    511758         "R_PPC_RELATIVE",      /* name */
    512          false,                 /* partial_inplace */
     759         FALSE,                 /* partial_inplace */
    513760         0,                     /* src_mask */
    514761         0xffffffff,            /* dst_mask */
    515          false),                /* pcrel_offset */
     762         FALSE),                /* pcrel_offset */
    516763
    517764  /* Like R_PPC_REL24, but uses the value of the symbol within the
     
    522769         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    523770         26,                    /* bitsize */
    524          true,                  /* pc_relative */
     771         TRUE,                  /* pc_relative */
    525772         0,                     /* bitpos */
    526773         complain_overflow_signed, /* complain_on_overflow */
    527774         bfd_elf_generic_reloc, /* special_function */
    528775         "R_PPC_LOCAL24PC",     /* name */
    529          false,                 /* partial_inplace */
     776         FALSE,                 /* partial_inplace */
    530777         0,                     /* src_mask */
    531778         0x3fffffc,             /* dst_mask */
    532          true),                 /* pcrel_offset */
     779         TRUE),                 /* pcrel_offset */
    533780
    534781  /* Like R_PPC_ADDR32, but may be unaligned.  */
     
    537784         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    538785         32,                    /* bitsize */
    539          false,                 /* pc_relative */
     786         FALSE,                 /* pc_relative */
    540787         0,                     /* bitpos */
    541788         complain_overflow_bitfield, /* complain_on_overflow */
    542789         bfd_elf_generic_reloc, /* special_function */
    543790         "R_PPC_UADDR32",       /* name */
    544          false,                 /* partial_inplace */
     791         FALSE,                 /* partial_inplace */
    545792         0,                     /* src_mask */
    546793         0xffffffff,            /* dst_mask */
    547          false),                /* pcrel_offset */
     794         FALSE),                /* pcrel_offset */
    548795
    549796  /* Like R_PPC_ADDR16, but may be unaligned.  */
     
    552799         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    553800         16,                    /* bitsize */
    554          false,                 /* pc_relative */
     801         FALSE,                 /* pc_relative */
    555802         0,                     /* bitpos */
    556803         complain_overflow_bitfield, /* complain_on_overflow */
    557804         bfd_elf_generic_reloc, /* special_function */
    558805         "R_PPC_UADDR16",       /* name */
    559          false,                 /* partial_inplace */
     806         FALSE,                 /* partial_inplace */
    560807         0,                     /* src_mask */
    561808         0xffff,                /* dst_mask */
    562          false),                /* pcrel_offset */
     809         FALSE),                /* pcrel_offset */
    563810
    564811  /* 32-bit PC relative */
     
    567814         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    568815         32,                    /* bitsize */
    569          true,                  /* pc_relative */
     816         TRUE,                  /* pc_relative */
    570817         0,                     /* bitpos */
    571818         complain_overflow_bitfield, /* complain_on_overflow */
    572819         bfd_elf_generic_reloc, /* special_function */
    573820         "R_PPC_REL32",         /* name */
    574          false,                 /* partial_inplace */
     821         FALSE,                 /* partial_inplace */
    575822         0,                     /* src_mask */
    576823         0xffffffff,            /* dst_mask */
    577          true),                 /* pcrel_offset */
     824         TRUE),                 /* pcrel_offset */
    578825
    579826  /* 32-bit relocation to the symbol's procedure linkage table.
     
    583830         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    584831         32,                    /* bitsize */
    585          false,                 /* pc_relative */
     832         FALSE,                 /* pc_relative */
    586833         0,                     /* bitpos */
    587834         complain_overflow_bitfield, /* complain_on_overflow */
    588835         bfd_elf_generic_reloc, /* special_function */
    589836         "R_PPC_PLT32",         /* name */
    590          false,                 /* partial_inplace */
     837         FALSE,                 /* partial_inplace */
    591838         0,                     /* src_mask */
    592839         0,                     /* dst_mask */
    593          false),                /* pcrel_offset */
     840         FALSE),                /* pcrel_offset */
    594841
    595842  /* 32-bit PC relative relocation to the symbol's procedure linkage table.
     
    599846         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    600847         32,                    /* bitsize */
    601          true,                  /* pc_relative */
     848         TRUE,                  /* pc_relative */
    602849         0,                     /* bitpos */
    603850         complain_overflow_bitfield, /* complain_on_overflow */
    604851         bfd_elf_generic_reloc, /* special_function */
    605852         "R_PPC_PLTREL32",      /* name */
    606          false,                 /* partial_inplace */
     853         FALSE,                 /* partial_inplace */
    607854         0,                     /* src_mask */
    608855         0,                     /* dst_mask */
    609          true),                 /* pcrel_offset */
     856         TRUE),                 /* pcrel_offset */
    610857
    611858  /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
     
    615862         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    616863         16,                    /* bitsize */
    617          false,                 /* pc_relative */
     864         FALSE,                 /* pc_relative */
    618865         0,                     /* bitpos */
    619866         complain_overflow_dont, /* complain_on_overflow */
    620867         bfd_elf_generic_reloc, /* special_function */
    621868         "R_PPC_PLT16_LO",      /* name */
    622          false,                 /* partial_inplace */
     869         FALSE,                 /* partial_inplace */
    623870         0,                     /* src_mask */
    624871         0xffff,                /* dst_mask */
    625          false),                /* pcrel_offset */
     872         FALSE),                /* pcrel_offset */
    626873
    627874  /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
     
    631878         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    632879         16,                    /* bitsize */
    633          false,                 /* pc_relative */
     880         FALSE,                 /* pc_relative */
    634881         0,                     /* bitpos */
    635882         complain_overflow_bitfield, /* complain_on_overflow */
    636883         bfd_elf_generic_reloc, /* special_function */
    637884         "R_PPC_PLT16_HI",      /* name */
    638          false,                 /* partial_inplace */
     885         FALSE,                 /* partial_inplace */
    639886         0,                     /* src_mask */
    640887         0xffff,                /* dst_mask */
    641          false),                 /* pcrel_offset */
     888         FALSE),                 /* pcrel_offset */
    642889
    643890  /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
     
    647894         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    648895         16,                    /* bitsize */
    649          false,                 /* pc_relative */
     896         FALSE,                 /* pc_relative */
    650897         0,                     /* bitpos */
    651898         complain_overflow_bitfield, /* complain_on_overflow */
    652899         ppc_elf_addr16_ha_reloc, /* special_function */
    653900         "R_PPC_PLT16_HA",      /* name */
    654          false,                 /* partial_inplace */
     901         FALSE,                 /* partial_inplace */
    655902         0,                     /* src_mask */
    656903         0xffff,                /* dst_mask */
    657          false),                /* pcrel_offset */
     904         FALSE),                /* pcrel_offset */
    658905
    659906  /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
     
    663910         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    664911         16,                    /* bitsize */
    665          false,                 /* pc_relative */
     912         FALSE,                 /* pc_relative */
    666913         0,                     /* bitpos */
    667914         complain_overflow_signed, /* complain_on_overflow */
    668915         bfd_elf_generic_reloc, /* special_function */
    669916         "R_PPC_SDAREL16",      /* name */
    670          false,                 /* partial_inplace */
     917         FALSE,                 /* partial_inplace */
    671918         0,                     /* src_mask */
    672919         0xffff,                /* dst_mask */
    673          false),                /* pcrel_offset */
    674 
    675   /* 32-bit section relative relocation.  */
     920         FALSE),                /* pcrel_offset */
     921
     922  /* 16-bit section relative relocation.  */
    676923  HOWTO (R_PPC_SECTOFF,         /* type */
    677924         0,                     /* rightshift */
    678          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    679          32,                    /* bitsize */
    680          true,                  /* pc_relative */
     925         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     926         16,                    /* bitsize */
     927         FALSE,                 /* pc_relative */
    681928         0,                     /* bitpos */
    682929         complain_overflow_bitfield, /* complain_on_overflow */
    683930         bfd_elf_generic_reloc, /* special_function */
    684931         "R_PPC_SECTOFF",       /* name */
    685          false,                 /* partial_inplace */
    686          0,                     /* src_mask */
    687          0,                     /* dst_mask */
    688          true),                 /* pcrel_offset */
     932         FALSE,                 /* partial_inplace */
     933         0,                     /* src_mask */
     934         0xffff,                /* dst_mask */
     935         FALSE),                /* pcrel_offset */
    689936
    690937  /* 16-bit lower half section relative relocation.  */
     
    693940         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    694941         16,                    /* bitsize */
    695          false,                 /* pc_relative */
     942         FALSE,                 /* pc_relative */
    696943         0,                     /* bitpos */
    697944         complain_overflow_dont, /* complain_on_overflow */
    698945         bfd_elf_generic_reloc, /* special_function */
    699946         "R_PPC_SECTOFF_LO",    /* name */
    700          false,                 /* partial_inplace */
     947         FALSE,                 /* partial_inplace */
    701948         0,                     /* src_mask */
    702949         0xffff,                /* dst_mask */
    703          false),                /* pcrel_offset */
     950         FALSE),                /* pcrel_offset */
    704951
    705952  /* 16-bit upper half section relative relocation.  */
     
    708955         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    709956         16,                    /* bitsize */
    710          false,                 /* pc_relative */
     957         FALSE,                 /* pc_relative */
    711958         0,                     /* bitpos */
    712959         complain_overflow_bitfield, /* complain_on_overflow */
    713960         bfd_elf_generic_reloc, /* special_function */
    714961         "R_PPC_SECTOFF_HI",    /* name */
    715          false,                 /* partial_inplace */
     962         FALSE,                 /* partial_inplace */
    716963         0,                     /* src_mask */
    717964         0xffff,                /* dst_mask */
    718          false),                 /* pcrel_offset */
     965         FALSE),                 /* pcrel_offset */
    719966
    720967  /* 16-bit upper half adjusted section relative relocation.  */
     
    723970         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    724971         16,                    /* bitsize */
    725          false,                 /* pc_relative */
     972         FALSE,                 /* pc_relative */
    726973         0,                     /* bitpos */
    727974         complain_overflow_bitfield, /* complain_on_overflow */
    728975         ppc_elf_addr16_ha_reloc, /* special_function */
    729976         "R_PPC_SECTOFF_HA",    /* name */
    730          false,                 /* partial_inplace */
     977         FALSE,                 /* partial_inplace */
    731978         0,                     /* src_mask */
    732979         0xffff,                /* dst_mask */
    733          false),                /* pcrel_offset */
     980         FALSE),                /* pcrel_offset */
     981
     982  /* Marker reloc for TLS.  */
     983  HOWTO (R_PPC_TLS,
     984         0,                     /* rightshift */
     985         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     986         32,                    /* bitsize */
     987         FALSE,                 /* pc_relative */
     988         0,                     /* bitpos */
     989         complain_overflow_dont, /* complain_on_overflow */
     990         bfd_elf_generic_reloc, /* special_function */
     991         "R_PPC_TLS",           /* name */
     992         FALSE,                 /* partial_inplace */
     993         0,                     /* src_mask */
     994         0,                     /* dst_mask */
     995         FALSE),                /* pcrel_offset */
     996
     997  /* Computes the load module index of the load module that contains the
     998     definition of its TLS sym.  */
     999  HOWTO (R_PPC_DTPMOD32,
     1000         0,                     /* rightshift */
     1001         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1002         32,                    /* bitsize */
     1003         FALSE,                 /* pc_relative */
     1004         0,                     /* bitpos */
     1005         complain_overflow_dont, /* complain_on_overflow */
     1006         ppc_elf_unhandled_reloc, /* special_function */
     1007         "R_PPC_DTPMOD32",      /* name */
     1008         FALSE,                 /* partial_inplace */
     1009         0,                     /* src_mask */
     1010         0xffffffff,            /* dst_mask */
     1011         FALSE),                /* pcrel_offset */
     1012
     1013  /* Computes a dtv-relative displacement, the difference between the value
     1014     of sym+add and the base address of the thread-local storage block that
     1015     contains the definition of sym, minus 0x8000.  */
     1016  HOWTO (R_PPC_DTPREL32,
     1017         0,                     /* rightshift */
     1018         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1019         32,                    /* bitsize */
     1020         FALSE,                 /* pc_relative */
     1021         0,                     /* bitpos */
     1022         complain_overflow_dont, /* complain_on_overflow */
     1023         ppc_elf_unhandled_reloc, /* special_function */
     1024         "R_PPC_DTPREL32",      /* name */
     1025         FALSE,                 /* partial_inplace */
     1026         0,                     /* src_mask */
     1027         0xffffffff,            /* dst_mask */
     1028         FALSE),                /* pcrel_offset */
     1029
     1030  /* A 16 bit dtprel reloc.  */
     1031  HOWTO (R_PPC_DTPREL16,
     1032         0,                     /* rightshift */
     1033         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1034         16,                    /* bitsize */
     1035         FALSE,                 /* pc_relative */
     1036         0,                     /* bitpos */
     1037         complain_overflow_signed, /* complain_on_overflow */
     1038         ppc_elf_unhandled_reloc, /* special_function */
     1039         "R_PPC_DTPREL16",      /* name */
     1040         FALSE,                 /* partial_inplace */
     1041         0,                     /* src_mask */
     1042         0xffff,                /* dst_mask */
     1043         FALSE),                /* pcrel_offset */
     1044
     1045  /* Like DTPREL16, but no overflow.  */
     1046  HOWTO (R_PPC_DTPREL16_LO,
     1047         0,                     /* rightshift */
     1048         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1049         16,                    /* bitsize */
     1050         FALSE,                 /* pc_relative */
     1051         0,                     /* bitpos */
     1052         complain_overflow_dont, /* complain_on_overflow */
     1053         ppc_elf_unhandled_reloc, /* special_function */
     1054         "R_PPC_DTPREL16_LO",   /* name */
     1055         FALSE,                 /* partial_inplace */
     1056         0,                     /* src_mask */
     1057         0xffff,                /* dst_mask */
     1058         FALSE),                /* pcrel_offset */
     1059
     1060  /* Like DTPREL16_LO, but next higher group of 16 bits.  */
     1061  HOWTO (R_PPC_DTPREL16_HI,
     1062         16,                    /* rightshift */
     1063         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1064         16,                    /* bitsize */
     1065         FALSE,                 /* pc_relative */
     1066         0,                     /* bitpos */
     1067         complain_overflow_dont, /* complain_on_overflow */
     1068         ppc_elf_unhandled_reloc, /* special_function */
     1069         "R_PPC_DTPREL16_HI",   /* name */
     1070         FALSE,                 /* partial_inplace */
     1071         0,                     /* src_mask */
     1072         0xffff,                /* dst_mask */
     1073         FALSE),                /* pcrel_offset */
     1074
     1075  /* Like DTPREL16_HI, but adjust for low 16 bits.  */
     1076  HOWTO (R_PPC_DTPREL16_HA,
     1077         16,                    /* rightshift */
     1078         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1079         16,                    /* bitsize */
     1080         FALSE,                 /* pc_relative */
     1081         0,                     /* bitpos */
     1082         complain_overflow_dont, /* complain_on_overflow */
     1083         ppc_elf_unhandled_reloc, /* special_function */
     1084         "R_PPC_DTPREL16_HA",   /* name */
     1085         FALSE,                 /* partial_inplace */
     1086         0,                     /* src_mask */
     1087         0xffff,                /* dst_mask */
     1088         FALSE),                /* pcrel_offset */
     1089
     1090  /* Computes a tp-relative displacement, the difference between the value of
     1091     sym+add and the value of the thread pointer (r13).  */
     1092  HOWTO (R_PPC_TPREL32,
     1093         0,                     /* rightshift */
     1094         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1095         32,                    /* bitsize */
     1096         FALSE,                 /* pc_relative */
     1097         0,                     /* bitpos */
     1098         complain_overflow_dont, /* complain_on_overflow */
     1099         ppc_elf_unhandled_reloc, /* special_function */
     1100         "R_PPC_TPREL32",       /* name */
     1101         FALSE,                 /* partial_inplace */
     1102         0,                     /* src_mask */
     1103         0xffffffff,            /* dst_mask */
     1104         FALSE),                /* pcrel_offset */
     1105
     1106  /* A 16 bit tprel reloc.  */
     1107  HOWTO (R_PPC_TPREL16,
     1108         0,                     /* rightshift */
     1109         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1110         16,                    /* bitsize */
     1111         FALSE,                 /* pc_relative */
     1112         0,                     /* bitpos */
     1113         complain_overflow_signed, /* complain_on_overflow */
     1114         ppc_elf_unhandled_reloc, /* special_function */
     1115         "R_PPC_TPREL16",       /* name */
     1116         FALSE,                 /* partial_inplace */
     1117         0,                     /* src_mask */
     1118         0xffff,                /* dst_mask */
     1119         FALSE),                /* pcrel_offset */
     1120
     1121  /* Like TPREL16, but no overflow.  */
     1122  HOWTO (R_PPC_TPREL16_LO,
     1123         0,                     /* rightshift */
     1124         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1125         16,                    /* bitsize */
     1126         FALSE,                 /* pc_relative */
     1127         0,                     /* bitpos */
     1128         complain_overflow_dont, /* complain_on_overflow */
     1129         ppc_elf_unhandled_reloc, /* special_function */
     1130         "R_PPC_TPREL16_LO",    /* name */
     1131         FALSE,                 /* partial_inplace */
     1132         0,                     /* src_mask */
     1133         0xffff,                /* dst_mask */
     1134         FALSE),                /* pcrel_offset */
     1135
     1136  /* Like TPREL16_LO, but next higher group of 16 bits.  */
     1137  HOWTO (R_PPC_TPREL16_HI,
     1138         16,                    /* rightshift */
     1139         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1140         16,                    /* bitsize */
     1141         FALSE,                 /* pc_relative */
     1142         0,                     /* bitpos */
     1143         complain_overflow_dont, /* complain_on_overflow */
     1144         ppc_elf_unhandled_reloc, /* special_function */
     1145         "R_PPC_TPREL16_HI",    /* name */
     1146         FALSE,                 /* partial_inplace */
     1147         0,                     /* src_mask */
     1148         0xffff,                /* dst_mask */
     1149         FALSE),                /* pcrel_offset */
     1150
     1151  /* Like TPREL16_HI, but adjust for low 16 bits.  */
     1152  HOWTO (R_PPC_TPREL16_HA,
     1153         16,                    /* rightshift */
     1154         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1155         16,                    /* bitsize */
     1156         FALSE,                 /* pc_relative */
     1157         0,                     /* bitpos */
     1158         complain_overflow_dont, /* complain_on_overflow */
     1159         ppc_elf_unhandled_reloc, /* special_function */
     1160         "R_PPC_TPREL16_HA",    /* name */
     1161         FALSE,                 /* partial_inplace */
     1162         0,                     /* src_mask */
     1163         0xffff,                /* dst_mask */
     1164         FALSE),                /* pcrel_offset */
     1165
     1166  /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
     1167     with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
     1168     to the first entry.  */
     1169  HOWTO (R_PPC_GOT_TLSGD16,
     1170         0,                     /* rightshift */
     1171         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1172         16,                    /* bitsize */
     1173         FALSE,                 /* pc_relative */
     1174         0,                     /* bitpos */
     1175         complain_overflow_signed, /* complain_on_overflow */
     1176         ppc_elf_unhandled_reloc, /* special_function */
     1177         "R_PPC_GOT_TLSGD16",   /* name */
     1178         FALSE,                 /* partial_inplace */
     1179         0,                     /* src_mask */
     1180         0xffff,                /* dst_mask */
     1181         FALSE),                /* pcrel_offset */
     1182
     1183  /* Like GOT_TLSGD16, but no overflow.  */
     1184  HOWTO (R_PPC_GOT_TLSGD16_LO,
     1185         0,                     /* rightshift */
     1186         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1187         16,                    /* bitsize */
     1188         FALSE,                 /* pc_relative */
     1189         0,                     /* bitpos */
     1190         complain_overflow_dont, /* complain_on_overflow */
     1191         ppc_elf_unhandled_reloc, /* special_function */
     1192         "R_PPC_GOT_TLSGD16_LO", /* name */
     1193         FALSE,                 /* partial_inplace */
     1194         0,                     /* src_mask */
     1195         0xffff,                /* dst_mask */
     1196         FALSE),                /* pcrel_offset */
     1197
     1198  /* Like GOT_TLSGD16_LO, but next higher group of 16 bits.  */
     1199  HOWTO (R_PPC_GOT_TLSGD16_HI,
     1200         16,                    /* rightshift */
     1201         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1202         16,                    /* bitsize */
     1203         FALSE,                 /* pc_relative */
     1204         0,                     /* bitpos */
     1205         complain_overflow_dont, /* complain_on_overflow */
     1206         ppc_elf_unhandled_reloc, /* special_function */
     1207         "R_PPC_GOT_TLSGD16_HI", /* name */
     1208         FALSE,                 /* partial_inplace */
     1209         0,                     /* src_mask */
     1210         0xffff,                /* dst_mask */
     1211         FALSE),                /* pcrel_offset */
     1212
     1213  /* Like GOT_TLSGD16_HI, but adjust for low 16 bits.  */
     1214  HOWTO (R_PPC_GOT_TLSGD16_HA,
     1215         16,                    /* rightshift */
     1216         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1217         16,                    /* bitsize */
     1218         FALSE,                 /* pc_relative */
     1219         0,                     /* bitpos */
     1220         complain_overflow_dont, /* complain_on_overflow */
     1221         ppc_elf_unhandled_reloc, /* special_function */
     1222         "R_PPC_GOT_TLSGD16_HA", /* name */
     1223         FALSE,                 /* partial_inplace */
     1224         0,                     /* src_mask */
     1225         0xffff,                /* dst_mask */
     1226         FALSE),                /* pcrel_offset */
     1227
     1228  /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
     1229     with values (sym+add)@dtpmod and zero, and computes the offset to the
     1230     first entry.  */
     1231  HOWTO (R_PPC_GOT_TLSLD16,
     1232         0,                     /* rightshift */
     1233         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1234         16,                    /* bitsize */
     1235         FALSE,                 /* pc_relative */
     1236         0,                     /* bitpos */
     1237         complain_overflow_signed, /* complain_on_overflow */
     1238         ppc_elf_unhandled_reloc, /* special_function */
     1239         "R_PPC_GOT_TLSLD16",   /* name */
     1240         FALSE,                 /* partial_inplace */
     1241         0,                     /* src_mask */
     1242         0xffff,                /* dst_mask */
     1243         FALSE),                /* pcrel_offset */
     1244
     1245  /* Like GOT_TLSLD16, but no overflow.  */
     1246  HOWTO (R_PPC_GOT_TLSLD16_LO,
     1247         0,                     /* rightshift */
     1248         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1249         16,                    /* bitsize */
     1250         FALSE,                 /* pc_relative */
     1251         0,                     /* bitpos */
     1252         complain_overflow_dont, /* complain_on_overflow */
     1253         ppc_elf_unhandled_reloc, /* special_function */
     1254         "R_PPC_GOT_TLSLD16_LO", /* name */
     1255         FALSE,                 /* partial_inplace */
     1256         0,                     /* src_mask */
     1257         0xffff,                /* dst_mask */
     1258         FALSE),                /* pcrel_offset */
     1259
     1260  /* Like GOT_TLSLD16_LO, but next higher group of 16 bits.  */
     1261  HOWTO (R_PPC_GOT_TLSLD16_HI,
     1262         16,                    /* rightshift */
     1263         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1264         16,                    /* bitsize */
     1265         FALSE,                 /* pc_relative */
     1266         0,                     /* bitpos */
     1267         complain_overflow_dont, /* complain_on_overflow */
     1268         ppc_elf_unhandled_reloc, /* special_function */
     1269         "R_PPC_GOT_TLSLD16_HI", /* name */
     1270         FALSE,                 /* partial_inplace */
     1271         0,                     /* src_mask */
     1272         0xffff,                /* dst_mask */
     1273         FALSE),                /* pcrel_offset */
     1274
     1275  /* Like GOT_TLSLD16_HI, but adjust for low 16 bits.  */
     1276  HOWTO (R_PPC_GOT_TLSLD16_HA,
     1277         16,                    /* rightshift */
     1278         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1279         16,                    /* bitsize */
     1280         FALSE,                 /* pc_relative */
     1281         0,                     /* bitpos */
     1282         complain_overflow_dont, /* complain_on_overflow */
     1283         ppc_elf_unhandled_reloc, /* special_function */
     1284         "R_PPC_GOT_TLSLD16_HA", /* name */
     1285         FALSE,                 /* partial_inplace */
     1286         0,                     /* src_mask */
     1287         0xffff,                /* dst_mask */
     1288         FALSE),                /* pcrel_offset */
     1289
     1290  /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
     1291     the offset to the entry.  */
     1292  HOWTO (R_PPC_GOT_DTPREL16,
     1293         0,                     /* rightshift */
     1294         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1295         16,                    /* bitsize */
     1296         FALSE,                 /* pc_relative */
     1297         0,                     /* bitpos */
     1298         complain_overflow_signed, /* complain_on_overflow */
     1299         ppc_elf_unhandled_reloc, /* special_function */
     1300         "R_PPC_GOT_DTPREL16",  /* name */
     1301         FALSE,                 /* partial_inplace */
     1302         0,                     /* src_mask */
     1303         0xffff,                /* dst_mask */
     1304         FALSE),                /* pcrel_offset */
     1305
     1306  /* Like GOT_DTPREL16, but no overflow.  */
     1307  HOWTO (R_PPC_GOT_DTPREL16_LO,
     1308         0,                     /* rightshift */
     1309         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1310         16,                    /* bitsize */
     1311         FALSE,                 /* pc_relative */
     1312         0,                     /* bitpos */
     1313         complain_overflow_dont, /* complain_on_overflow */
     1314         ppc_elf_unhandled_reloc, /* special_function */
     1315         "R_PPC_GOT_DTPREL16_LO", /* name */
     1316         FALSE,                 /* partial_inplace */
     1317         0,                     /* src_mask */
     1318         0xffff,                /* dst_mask */
     1319         FALSE),                /* pcrel_offset */
     1320
     1321  /* Like GOT_DTPREL16_LO, but next higher group of 16 bits.  */
     1322  HOWTO (R_PPC_GOT_DTPREL16_HI,
     1323         16,                    /* rightshift */
     1324         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1325         16,                    /* bitsize */
     1326         FALSE,                 /* pc_relative */
     1327         0,                     /* bitpos */
     1328         complain_overflow_dont, /* complain_on_overflow */
     1329         ppc_elf_unhandled_reloc, /* special_function */
     1330         "R_PPC_GOT_DTPREL16_HI", /* name */
     1331         FALSE,                 /* partial_inplace */
     1332         0,                     /* src_mask */
     1333         0xffff,                /* dst_mask */
     1334         FALSE),                /* pcrel_offset */
     1335
     1336  /* Like GOT_DTPREL16_HI, but adjust for low 16 bits.  */
     1337  HOWTO (R_PPC_GOT_DTPREL16_HA,
     1338         16,                    /* rightshift */
     1339         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1340         16,                    /* bitsize */
     1341         FALSE,                 /* pc_relative */
     1342         0,                     /* bitpos */
     1343         complain_overflow_dont, /* complain_on_overflow */
     1344         ppc_elf_unhandled_reloc, /* special_function */
     1345         "R_PPC_GOT_DTPREL16_HA", /* name */
     1346         FALSE,                 /* partial_inplace */
     1347         0,                     /* src_mask */
     1348         0xffff,                /* dst_mask */
     1349         FALSE),                /* pcrel_offset */
     1350
     1351  /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
     1352     offset to the entry.  */
     1353  HOWTO (R_PPC_GOT_TPREL16,
     1354         0,                     /* rightshift */
     1355         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1356         16,                    /* bitsize */
     1357         FALSE,                 /* pc_relative */
     1358         0,                     /* bitpos */
     1359         complain_overflow_signed, /* complain_on_overflow */
     1360         ppc_elf_unhandled_reloc, /* special_function */
     1361         "R_PPC_GOT_TPREL16",   /* name */
     1362         FALSE,                 /* partial_inplace */
     1363         0,                     /* src_mask */
     1364         0xffff,                /* dst_mask */
     1365         FALSE),                /* pcrel_offset */
     1366
     1367  /* Like GOT_TPREL16, but no overflow.  */
     1368  HOWTO (R_PPC_GOT_TPREL16_LO,
     1369         0,                     /* rightshift */
     1370         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1371         16,                    /* bitsize */
     1372         FALSE,                 /* pc_relative */
     1373         0,                     /* bitpos */
     1374         complain_overflow_dont, /* complain_on_overflow */
     1375         ppc_elf_unhandled_reloc, /* special_function */
     1376         "R_PPC_GOT_TPREL16_LO", /* name */
     1377         FALSE,                 /* partial_inplace */
     1378         0,                     /* src_mask */
     1379         0xffff,                /* dst_mask */
     1380         FALSE),                /* pcrel_offset */
     1381
     1382  /* Like GOT_TPREL16_LO, but next higher group of 16 bits.  */
     1383  HOWTO (R_PPC_GOT_TPREL16_HI,
     1384         16,                    /* rightshift */
     1385         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1386         16,                    /* bitsize */
     1387         FALSE,                 /* pc_relative */
     1388         0,                     /* bitpos */
     1389         complain_overflow_dont, /* complain_on_overflow */
     1390         ppc_elf_unhandled_reloc, /* special_function */
     1391         "R_PPC_GOT_TPREL16_HI", /* name */
     1392         FALSE,                 /* partial_inplace */
     1393         0,                     /* src_mask */
     1394         0xffff,                /* dst_mask */
     1395         FALSE),                /* pcrel_offset */
     1396
     1397  /* Like GOT_TPREL16_HI, but adjust for low 16 bits.  */
     1398  HOWTO (R_PPC_GOT_TPREL16_HA,
     1399         16,                    /* rightshift */
     1400         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1401         16,                    /* bitsize */
     1402         FALSE,                 /* pc_relative */
     1403         0,                     /* bitpos */
     1404         complain_overflow_dont, /* complain_on_overflow */
     1405         ppc_elf_unhandled_reloc, /* special_function */
     1406         "R_PPC_GOT_TPREL16_HA", /* name */
     1407         FALSE,                 /* partial_inplace */
     1408         0,                     /* src_mask */
     1409         0xffff,                /* dst_mask */
     1410         FALSE),                /* pcrel_offset */
    7341411
    7351412  /* The remaining relocs are from the Embedded ELF ABI, and are not
    7361413     in the SVR4 ELF ABI.  */
    7371414
    738   /* 32 bit value resulting from the addend minus the symbol */
     1415  /* 32 bit value resulting from the addend minus the symbol. */
    7391416  HOWTO (R_PPC_EMB_NADDR32,     /* type */
    7401417         0,                     /* rightshift */
    7411418         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    7421419         32,                    /* bitsize */
    743          false,                 /* pc_relative */
     1420         FALSE,                 /* pc_relative */
    7441421         0,                     /* bitpos */
    7451422         complain_overflow_bitfield, /* complain_on_overflow */
    7461423         bfd_elf_generic_reloc, /* special_function */
    7471424         "R_PPC_EMB_NADDR32",   /* name */
    748          false,                 /* partial_inplace */
     1425         FALSE,                 /* partial_inplace */
    7491426         0,                     /* src_mask */
    7501427         0xffffffff,            /* dst_mask */
    751          false),                /* pcrel_offset */
    752 
    753   /* 16 bit value resulting from the addend minus the symbol */
     1428         FALSE),                /* pcrel_offset */
     1429
     1430  /* 16 bit value resulting from the addend minus the symbol. */
    7541431  HOWTO (R_PPC_EMB_NADDR16,     /* type */
    7551432         0,                     /* rightshift */
    7561433         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    7571434         16,                    /* bitsize */
    758          false,                 /* pc_relative */
     1435         FALSE,                 /* pc_relative */
    7591436         0,                     /* bitpos */
    7601437         complain_overflow_bitfield, /* complain_on_overflow */
    7611438         bfd_elf_generic_reloc, /* special_function */
    7621439         "R_PPC_EMB_NADDR16",   /* name */
    763          false,                 /* partial_inplace */
     1440         FALSE,                 /* partial_inplace */
    7641441         0,                     /* src_mask */
    7651442         0xffff,                /* dst_mask */
    766          false),                /* pcrel_offset */
    767 
    768   /* 16 bit value resulting from the addend minus the symbol */
     1443         FALSE),                /* pcrel_offset */
     1444
     1445  /* 16 bit value resulting from the addend minus the symbol. */
    7691446  HOWTO (R_PPC_EMB_NADDR16_LO,  /* type */
    7701447         0,                     /* rightshift */
    7711448         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    7721449         16,                    /* bitsize */
    773          false,                 /* pc_relative */
     1450         FALSE,                 /* pc_relative */
    7741451         0,                     /* bitpos */
    7751452         complain_overflow_dont,/* complain_on_overflow */
    7761453         bfd_elf_generic_reloc, /* special_function */
    7771454         "R_PPC_EMB_ADDR16_LO", /* name */
    778          false,                 /* partial_inplace */
     1455         FALSE,                 /* partial_inplace */
    7791456         0,                     /* src_mask */
    7801457         0xffff,                /* dst_mask */
    781          false),                /* pcrel_offset */
    782 
    783   /* The high order 16 bits of the addend minus the symbol */
     1458         FALSE),                /* pcrel_offset */
     1459
     1460  /* The high order 16 bits of the addend minus the symbol. */
    7841461  HOWTO (R_PPC_EMB_NADDR16_HI,  /* type */
    7851462         16,                    /* rightshift */
    7861463         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    7871464         16,                    /* bitsize */
    788          false,                 /* pc_relative */
     1465         FALSE,                 /* pc_relative */
    7891466         0,                     /* bitpos */
    7901467         complain_overflow_dont, /* complain_on_overflow */
    7911468         bfd_elf_generic_reloc, /* special_function */
    7921469         "R_PPC_EMB_NADDR16_HI", /* name */
    793          false,                 /* partial_inplace */
     1470         FALSE,                 /* partial_inplace */
    7941471         0,                     /* src_mask */
    7951472         0xffff,                /* dst_mask */
    796          false),                /* pcrel_offset */
     1473         FALSE),                /* pcrel_offset */
    7971474
    7981475  /* The high order 16 bits of the result of the addend minus the address,
     
    8031480         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    8041481         16,                    /* bitsize */
    805          false,                 /* pc_relative */
     1482         FALSE,                 /* pc_relative */
    8061483         0,                     /* bitpos */
    8071484         complain_overflow_dont, /* complain_on_overflow */
    8081485         ppc_elf_addr16_ha_reloc, /* special_function */
    8091486         "R_PPC_EMB_NADDR16_HA", /* name */
    810          false,                 /* partial_inplace */
     1487         FALSE,                 /* partial_inplace */
    8111488         0,                     /* src_mask */
    8121489         0xffff,                /* dst_mask */
    813          false),                /* pcrel_offset */
     1490         FALSE),                /* pcrel_offset */
    8141491
    8151492  /* 16 bit value resulting from allocating a 4 byte word to hold an
    8161493     address in the .sdata section, and returning the offset from
    817      _SDA_BASE_ for that relocation */
     1494     _SDA_BASE_ for that relocation. */
    8181495  HOWTO (R_PPC_EMB_SDAI16,      /* type */
    8191496         0,                     /* rightshift */
    8201497         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    8211498         16,                    /* bitsize */
    822          false,                 /* pc_relative */
     1499         FALSE,                 /* pc_relative */
    8231500         0,                     /* bitpos */
    8241501         complain_overflow_bitfield, /* complain_on_overflow */
    8251502         bfd_elf_generic_reloc, /* special_function */
    8261503         "R_PPC_EMB_SDAI16",    /* name */
    827          false,                 /* partial_inplace */
     1504         FALSE,                 /* partial_inplace */
    8281505         0,                     /* src_mask */
    8291506         0xffff,                /* dst_mask */
    830          false),                /* pcrel_offset */
     1507         FALSE),                /* pcrel_offset */
    8311508
    8321509  /* 16 bit value resulting from allocating a 4 byte word to hold an
    8331510     address in the .sdata2 section, and returning the offset from
    834      _SDA2_BASE_ for that relocation */
     1511     _SDA2_BASE_ for that relocation. */
    8351512  HOWTO (R_PPC_EMB_SDA2I16,     /* type */
    8361513         0,                     /* rightshift */
    8371514         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    8381515         16,                    /* bitsize */
    839          false,                 /* pc_relative */
     1516         FALSE,                 /* pc_relative */
    8401517         0,                     /* bitpos */
    8411518         complain_overflow_bitfield, /* complain_on_overflow */
    8421519         bfd_elf_generic_reloc, /* special_function */
    8431520         "R_PPC_EMB_SDA2I16",   /* name */
    844          false,                 /* partial_inplace */
     1521         FALSE,                 /* partial_inplace */
    8451522         0,                     /* src_mask */
    8461523         0xffff,                /* dst_mask */
    847          false),                /* pcrel_offset */
     1524         FALSE),                /* pcrel_offset */
    8481525
    8491526  /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
     
    8531530         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    8541531         16,                    /* bitsize */
    855          false,                 /* pc_relative */
     1532         FALSE,                 /* pc_relative */
    8561533         0,                     /* bitpos */
    8571534         complain_overflow_signed, /* complain_on_overflow */
    8581535         bfd_elf_generic_reloc, /* special_function */
    8591536         "R_PPC_EMB_SDA2REL",   /* name */
    860          false,                 /* partial_inplace */
     1537         FALSE,                 /* partial_inplace */
    8611538         0,                     /* src_mask */
    8621539         0xffff,                /* dst_mask */
    863          false),                /* pcrel_offset */
     1540         FALSE),                /* pcrel_offset */
    8641541
    8651542  /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
     
    8701547         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    8711548         16,                    /* bitsize */
    872          false,                 /* pc_relative */
     1549         FALSE,                 /* pc_relative */
    8731550         0,                     /* bitpos */
    8741551         complain_overflow_signed, /* complain_on_overflow */
    8751552         bfd_elf_generic_reloc, /* special_function */
    8761553         "R_PPC_EMB_SDA21",     /* name */
    877          false,                 /* partial_inplace */
     1554         FALSE,                 /* partial_inplace */
    8781555         0,                     /* src_mask */
    8791556         0xffff,                /* dst_mask */
    880          false),                /* pcrel_offset */
     1557         FALSE),                /* pcrel_offset */
    8811558
    8821559  /* Relocation not handled: R_PPC_EMB_MRKREF */
     
    8941571         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    8951572         16,                    /* bitsize */
    896          true,                  /* pc_relative */
     1573         TRUE,                  /* pc_relative */
    8971574         0,                     /* bitpos */
    8981575         complain_overflow_signed, /* complain_on_overflow */
    8991576         bfd_elf_generic_reloc, /* special_function */
    9001577         "R_PPC_EMB_RELSDA",    /* name */
    901          false,                 /* partial_inplace */
     1578         FALSE,                 /* partial_inplace */
    9021579         0,                     /* src_mask */
    9031580         0xffff,                /* dst_mask */
    904          false),                /* pcrel_offset */
    905 
    906   /* GNU extension to record C++ vtable hierarchy */
     1581         FALSE),                /* pcrel_offset */
     1582
     1583  /* GNU extension to record C++ vtable hierarchy. */
    9071584  HOWTO (R_PPC_GNU_VTINHERIT,   /* type */
    9081585         0,                     /* rightshift */
    9091586         0,                     /* size (0 = byte, 1 = short, 2 = long) */
    9101587         0,                     /* bitsize */
    911          false,                 /* pc_relative */
     1588         FALSE,                 /* pc_relative */
    9121589         0,                     /* bitpos */
    9131590         complain_overflow_dont, /* complain_on_overflow */
    9141591         NULL,                  /* special_function */
    9151592         "R_PPC_GNU_VTINHERIT", /* name */
    916          false,                 /* partial_inplace */
     1593         FALSE,                 /* partial_inplace */
    9171594         0,                     /* src_mask */
    9181595         0,                     /* dst_mask */
    919          false),                /* pcrel_offset */
    920 
    921   /* GNU extension to record C++ vtable member usage */
     1596         FALSE),                /* pcrel_offset */
     1597
     1598  /* GNU extension to record C++ vtable member usage. */
    9221599  HOWTO (R_PPC_GNU_VTENTRY,     /* type */
    9231600         0,                     /* rightshift */
    9241601         0,                     /* size (0 = byte, 1 = short, 2 = long) */
    9251602         0,                     /* bitsize */
    926          false,                 /* pc_relative */
     1603         FALSE,                 /* pc_relative */
    9271604         0,                     /* bitpos */
    9281605         complain_overflow_dont, /* complain_on_overflow */
    9291606         NULL,                  /* special_function */
    9301607         "R_PPC_GNU_VTENTRY",   /* name */
    931          false,                 /* partial_inplace */
     1608         FALSE,                 /* partial_inplace */
    9321609         0,                     /* src_mask */
    9331610         0,                     /* dst_mask */
    934          false),                /* pcrel_offset */
    935 
    936   /* Phony reloc to handle AIX style TOC entries */
     1611         FALSE),                /* pcrel_offset */
     1612
     1613  /* Phony reloc to handle AIX style TOC entries. */
    9371614  HOWTO (R_PPC_TOC16,           /* type */
    9381615         0,                     /* rightshift */
    9391616         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    9401617         16,                    /* bitsize */
    941          false,                 /* pc_relative */
     1618         FALSE,                 /* pc_relative */
    9421619         0,                     /* bitpos */
    9431620         complain_overflow_signed, /* complain_on_overflow */
    9441621         bfd_elf_generic_reloc, /* special_function */
    9451622         "R_PPC_TOC16",         /* name */
    946          false,                 /* partial_inplace */
     1623         FALSE,                 /* partial_inplace */
    9471624         0,                     /* src_mask */
    9481625         0xffff,                /* dst_mask */
    949          false),                /* pcrel_offset */
     1626         FALSE),                /* pcrel_offset */
    9501627};
    9511628
     
    9581635  unsigned int i, type;
    9591636
    960   for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
     1637  for (i = 0;
     1638       i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
     1639       i++)
    9611640    {
    9621641      type = ppc_elf_howto_raw[i].type;
    963       BFD_ASSERT (type < sizeof (ppc_elf_howto_table) / sizeof (ppc_elf_howto_table[0]));
     1642      if (type >= (sizeof (ppc_elf_howto_table)
     1643                   / sizeof (ppc_elf_howto_table[0])))
     1644        abort ();
    9641645      ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
    9651646    }
     
    9761657   3/ The branch is taken.
    9771658   4/ The branch is located in the last 5 words of a page.
    978       (The EOP limit is 5 by default but may be specified as any value from 1-10.)
     1659      (The EOP limit is 5 by default but may be specified as any value
     1660      from 1-10.)
    9791661
    9801662   Our software solution is to detect these problematic branches in a
     
    9861668      bit" is set (ensure it is predicted taken).
    9871669   4/ Conditional register branches - Ensure that the "y bit" is set
    988       (ensure it is predicted taken).
    989 */
     1670      (ensure it is predicted taken).  */
    9901671
    9911672/* Sort sections by address.  */
     
    9931674static int
    9941675ppc_elf_sort_rela (arg1, arg2)
    995      const void *arg1;
    996      const void *arg2;
     1676     const PTR arg1;
     1677     const PTR arg2;
    9971678{
    9981679  const Elf_Internal_Rela **rela1 = (const Elf_Internal_Rela**) arg1;
     
    10031684}
    10041685
    1005 static boolean
     1686static bfd_boolean
    10061687ppc_elf_relax_section (abfd, isec, link_info, again)
    10071688     bfd *abfd;
    10081689     asection *isec;
    10091690     struct bfd_link_info *link_info;
    1010      boolean *again;
     1691     bfd_boolean *again;
    10111692{
    10121693#define PAGESIZE 0x1000
     
    10201701
    10211702  /* We never have to do this more than once per input section.  */
    1022   *again = false;
     1703  *again = FALSE;
    10231704
    10241705  /* If needed, initialize this section's cooked size.  */
    10251706  if (isec->_cooked_size == 0)
    1026       isec->_cooked_size = isec->_raw_size;
     1707    isec->_cooked_size = isec->_raw_size;
    10271708
    10281709  /* We're only interested in text sections which overlap the
     
    10311712    {
    10321713      bfd_vma dot, end_page, end_section;
    1033       boolean section_modified;
     1714      bfd_boolean section_modified;
    10341715
    10351716      /* Get the section contents.  */
    10361717      /* Get cached copy if it exists.  */
    10371718      if (elf_section_data (isec)->this_hdr.contents != NULL)
    1038           contents = elf_section_data (isec)->this_hdr.contents;
     1719        contents = elf_section_data (isec)->this_hdr.contents;
    10391720      else
    10401721        {
     
    10541735      if (isec->reloc_count)
    10551736        {
    1056           unsigned n;
    1057 
    1058           /* Get a copy of the native relocations.  */
    1059           internal_relocs = _bfd_elf32_link_read_relocs (
    1060             abfd, isec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
    1061             link_info->keep_memory);
    1062           if (internal_relocs == NULL)
    1063               goto error_return;
    1064           if (! link_info->keep_memory)
    1065               free_relocs = internal_relocs;
    1066 
    1067           /* Setup a faster access method for the reloc info we need.  */
    1068           rela_comb = (Elf_Internal_Rela**)
    1069             bfd_malloc (isec->reloc_count*sizeof (Elf_Internal_Rela*));
    1070           if (rela_comb == NULL)
    1071               goto error_return;
    1072           for (n = 0; n < isec->reloc_count; ++n)
    1073             {
    1074               long r_type;
    1075 
    1076               r_type = ELF32_R_TYPE (internal_relocs[n].r_info);
    1077               if (r_type < 0 || r_type >= (int) R_PPC_max)
    1078                   goto error_return;
    1079 
    1080               /* Prologue constants are sometimes present in the ".text"
    1081               sections and they can be identified by their associated relocation.
    1082               We don't want to process those words and some others which
    1083               can also be identified by their relocations.  However, not all
    1084               conditional branches will have a relocation so we will
    1085               only ignore words that 1) have a reloc, and 2) the reloc
    1086               is not applicable to a conditional branch.
    1087               The array rela_comb is built here for use in the EOP scan loop.  */
    1088               switch (r_type)
    1089                 {
    1090                 case R_PPC_ADDR14_BRNTAKEN:     /* absolute, predicted not taken */
    1091                 case R_PPC_REL14:               /* relative cond. br.  */
    1092                 case R_PPC_REL14_BRNTAKEN:      /* rel. cond. br., predicted not taken */
    1093                   /* We should check the instruction.  */
    1094                   break;
    1095                 default:
    1096                   /* The word is not a conditional branch - ignore it.  */
    1097                   rela_comb[comb_count++] = &internal_relocs[n];
    1098                   break;
    1099                 }
    1100             }
    1101           if (comb_count > 1)
    1102             qsort (rela_comb, (size_t) comb_count, sizeof (int), ppc_elf_sort_rela);
     1737          unsigned n;
     1738          bfd_size_type amt;
     1739
     1740          /* Get a copy of the native relocations.  */
     1741          internal_relocs
     1742            = _bfd_elf32_link_read_relocs (abfd, isec, (PTR) NULL,
     1743                                           (Elf_Internal_Rela *) NULL,
     1744                                           link_info->keep_memory);
     1745          if (internal_relocs == NULL)
     1746            goto error_return;
     1747          if (! link_info->keep_memory)
     1748            free_relocs = internal_relocs;
     1749
     1750          /* Setup a faster access method for the reloc info we need.  */
     1751          amt = isec->reloc_count;
     1752          amt *= sizeof (Elf_Internal_Rela*);
     1753          rela_comb = (Elf_Internal_Rela**) bfd_malloc (amt);
     1754          if (rela_comb == NULL)
     1755            goto error_return;
     1756          for (n = 0; n < isec->reloc_count; ++n)
     1757            {
     1758              long r_type;
     1759
     1760              r_type = ELF32_R_TYPE (internal_relocs[n].r_info);
     1761              if (r_type < 0 || r_type >= (int) R_PPC_max)
     1762                goto error_return;
     1763
     1764              /* Prologue constants are sometimes present in the ".text"
     1765                 sections and they can be identified by their associated
     1766                 relocation.  We don't want to process those words and
     1767                 some others which can also be identified by their
     1768                 relocations.  However, not all conditional branches will
     1769                 have a relocation so we will only ignore words that
     1770                 1) have a reloc, and 2) the reloc is not applicable to a
     1771                 conditional branch.  The array rela_comb is built here
     1772                 for use in the EOP scan loop.  */
     1773              switch (r_type)
     1774                {
     1775                case R_PPC_ADDR14_BRNTAKEN:
     1776                case R_PPC_REL14:
     1777                case R_PPC_REL14_BRNTAKEN:
     1778                  /* We should check the instruction.  */
     1779                  break;
     1780                default:
     1781                  /* The word is not a conditional branch - ignore it.  */
     1782                  rela_comb[comb_count++] = &internal_relocs[n];
     1783                  break;
     1784                }
     1785            }
     1786          if (comb_count > 1)
     1787            qsort (rela_comb, (size_t) comb_count, sizeof (int),
     1788                   ppc_elf_sort_rela);
    11031789        }
    11041790
     
    11071793      dot = end_page = (isec->vma | (PAGESIZE - 1)) + 1;
    11081794      dot -= link_info->mpc860c0;
    1109       section_modified = false;
    1110       if (dot < isec->vma)      /* Increment the start position if this section */
    1111           dot = isec->vma;      /* begins in the middle of its first EOP region.  */
     1795      section_modified = FALSE;
     1796      /* Increment the start position if this section begins in the
     1797         middle of its first EOP region.  */
     1798      if (dot < isec->vma)
     1799        dot = isec->vma;
    11121800      for (;
    1113            dot < end_section;
    1114            dot += PAGESIZE, end_page += PAGESIZE)
    1115         {
    1116 
    1117           /* Check each word in this EOP region.  */
    1118           for (; dot < end_page; dot += 4)
    1119             {
    1120               bfd_vma isec_offset;
    1121               unsigned long insn;
    1122               boolean skip, modified;
    1123 
    1124               /* Don't process this word if there is a relocation for it and
    1125               the relocation indicates the word is not a conditional branch.  */
    1126               skip = false;
    1127               isec_offset = dot - isec->vma;
    1128               for (; comb_curr<comb_count; ++comb_curr)
    1129                 {
    1130                   bfd_vma r_offset;
    1131 
    1132                   r_offset = rela_comb[comb_curr]->r_offset;
    1133                   if (r_offset >= isec_offset)
    1134                     {
    1135                       if (r_offset == isec_offset) skip = true;
    1136                       break;
    1137                     }
    1138                 }
    1139               if (skip) continue;
    1140 
    1141               /* Check the current word for a problematic conditional branch.  */
     1801           dot < end_section;
     1802           dot += PAGESIZE, end_page += PAGESIZE)
     1803        {
     1804          /* Check each word in this EOP region.  */
     1805          for (; dot < end_page; dot += 4)
     1806            {
     1807              bfd_vma isec_offset;
     1808              unsigned long insn;
     1809              bfd_boolean skip, modified;
     1810
     1811              /* Don't process this word if there is a relocation for it
     1812                 and the relocation indicates the word is not a
     1813                 conditional branch.  */
     1814              skip = FALSE;
     1815              isec_offset = dot - isec->vma;
     1816              for (; comb_curr<comb_count; ++comb_curr)
     1817                {
     1818                  bfd_vma r_offset;
     1819
     1820                  r_offset = rela_comb[comb_curr]->r_offset;
     1821                  if (r_offset >= isec_offset)
     1822                    {
     1823                      if (r_offset == isec_offset) skip = TRUE;
     1824                      break;
     1825                    }
     1826                }
     1827              if (skip) continue;
     1828
     1829              /* Check the current word for a problematic conditional
     1830                 branch.  */
    11421831#define BO0(insn) ((insn) & 0x02000000)
    11431832#define BO2(insn) ((insn) & 0x00800000)
    11441833#define BO4(insn) ((insn) & 0x00200000)
    1145               insn = (unsigned long) bfd_get_32 (abfd, contents + isec_offset);
    1146               modified = false;
    1147               if ((insn & 0xFc000000) == 0x40000000)
    1148                 {
    1149                   /* Instruction is BCx */
    1150                   if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
    1151                     {
    1152                       bfd_vma target;
    1153                       /* This branch is predicted as "normal".
    1154                       If this is a forward branch, it is problematic.  */
    1155 
    1156                       target = insn & 0x0000Fffc;               /*extract*/
    1157                       target = (target ^ 0x8000) - 0x8000;      /*sign extend*/
    1158                       if ((insn & 0x00000002) == 0)
    1159                           target += dot;                        /*convert to abs*/
    1160                       if (target > dot)
    1161                         {
    1162                           insn |= 0x00200000;   /* set the prediction bit */
    1163                           modified = true;
    1164                         }
    1165                     }
    1166                 }
    1167               else if ((insn & 0xFc00Fffe) == 0x4c000420)
    1168                 {
    1169                   /* Instruction is BCCTRx */
    1170                   if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
     1834              insn = (unsigned long) bfd_get_32 (abfd, contents + isec_offset);
     1835              modified = FALSE;
     1836              if ((insn & 0xFc000000) == 0x40000000)
     1837                {
     1838                  /* Instruction is BCx */
     1839                  if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
     1840                    {
     1841                      bfd_vma target;
     1842
     1843                      /* This branch is predicted as "normal".
     1844                         If this is a forward branch, it is problematic.  */
     1845                      target = insn & 0x0000Fffc;
     1846                      target = (target ^ 0x8000) - 0x8000;
     1847                      if ((insn & 0x00000002) == 0)
     1848                        /* Convert to abs.  */
     1849                        target += dot;
     1850                      if (target > dot)
     1851                        {
     1852                          /* Set the prediction bit.  */
     1853                          insn |= 0x00200000;
     1854                          modified = TRUE;
     1855                        }
     1856                    }
     1857                }
     1858              else if ((insn & 0xFc00Fffe) == 0x4c000420)
     1859                {
     1860                  /* Instruction is BCCTRx.  */
     1861                  if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
    11711862                    {
    11721863                      /* This branch is predicted as not-taken.
    1173                       If this is a forward branch, it is problematic.
    1174                       Since we can't tell statically if it will branch forward,
    1175                       always set the prediction bit.  */
    1176                       insn |= 0x00200000;   /* set the prediction bit */
    1177                       modified = true;
     1864                        If this is a forward branch, it is problematic.
     1865                         Since we can't tell statically if it will branch
     1866                         forward, always set the prediction bit.  */
     1867                      insn |= 0x00200000;
     1868                      modified = TRUE;
    11781869                    }
    1179                 }
    1180               else if ((insn & 0xFc00Fffe) == 0x4c000020)
    1181                 {
    1182                   /* Instruction is BCLRx */
    1183                   if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
     1870                }
     1871              else if ((insn & 0xFc00Fffe) == 0x4c000020)
     1872                {
     1873                  /* Instruction is BCLRx */
     1874                  if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
    11841875                    {
    11851876                      /* This branch is predicted as not-taken.
    1186                       If this is a forward branch, it is problematic.
    1187                       Since we can't tell statically if it will branch forward,
    1188                       always set the prediction bit.  */
    1189                       insn |= 0x00200000;   /* set the prediction bit */
    1190                       modified = true;
     1877                        If this is a forward branch, it is problematic.
     1878                         Since we can't tell statically if it will branch
     1879                         forward, always set the prediction bit.  */
     1880                      insn |= 0x00200000;
     1881                      modified = TRUE;
    11911882                    }
    1192                 }
     1883                }
    11931884#undef BO0
    11941885#undef BO2
    11951886#undef BO4
    1196               if (modified)
    1197                 {
    1198                   bfd_put_32 (abfd, insn, contents + isec_offset);
    1199                   section_modified = true;
    1200                 }
    1201             }
    1202         }
     1887              if (modified)
     1888                {
     1889                  bfd_put_32 (abfd, (bfd_vma) insn, contents + isec_offset);
     1890                  section_modified = TRUE;
     1891                }
     1892            }
     1893        }
    12031894      if (section_modified)
    12041895        {
     
    12321923    }
    12331924
    1234   return true;
    1235 
    1236 error_return:
     1925  return TRUE;
     1926
     1927 error_return:
    12371928  if (rela_comb != NULL)
    12381929    free (rela_comb);
     
    12411932  if (free_contents != NULL)
    12421933    free (free_contents);
    1243   return false;
     1934  return FALSE;
    12441935}
    12451936
     
    12501941     bfd_reloc_code_real_type code;
    12511942{
    1252   enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
     1943  enum elf_ppc_reloc_type r;
    12531944
    12541945  if (!ppc_elf_howto_table[R_PPC_ADDR32])
     
    12611952      return (reloc_howto_type *) NULL;
    12621953
    1263     case BFD_RELOC_NONE:                ppc_reloc = R_PPC_NONE;                 break;
    1264     case BFD_RELOC_32:                  ppc_reloc = R_PPC_ADDR32;               break;
    1265     case BFD_RELOC_PPC_BA26:            ppc_reloc = R_PPC_ADDR24;               break;
    1266     case BFD_RELOC_16:                  ppc_reloc = R_PPC_ADDR16;               break;
    1267     case BFD_RELOC_LO16:                ppc_reloc = R_PPC_ADDR16_LO;            break;
    1268     case BFD_RELOC_HI16:                ppc_reloc = R_PPC_ADDR16_HI;            break;
    1269     case BFD_RELOC_HI16_S:              ppc_reloc = R_PPC_ADDR16_HA;            break;
    1270     case BFD_RELOC_PPC_BA16:            ppc_reloc = R_PPC_ADDR14;               break;
    1271     case BFD_RELOC_PPC_BA16_BRTAKEN:    ppc_reloc = R_PPC_ADDR14_BRTAKEN;       break;
    1272     case BFD_RELOC_PPC_BA16_BRNTAKEN:   ppc_reloc = R_PPC_ADDR14_BRNTAKEN;      break;
    1273     case BFD_RELOC_PPC_B26:             ppc_reloc = R_PPC_REL24;                break;
    1274     case BFD_RELOC_PPC_B16:             ppc_reloc = R_PPC_REL14;                break;
    1275     case BFD_RELOC_PPC_B16_BRTAKEN:     ppc_reloc = R_PPC_REL14_BRTAKEN;        break;
    1276     case BFD_RELOC_PPC_B16_BRNTAKEN:    ppc_reloc = R_PPC_REL14_BRNTAKEN;       break;
    1277     case BFD_RELOC_16_GOTOFF:           ppc_reloc = R_PPC_GOT16;                break;
    1278     case BFD_RELOC_LO16_GOTOFF:         ppc_reloc = R_PPC_GOT16_LO;             break;
    1279     case BFD_RELOC_HI16_GOTOFF:         ppc_reloc = R_PPC_GOT16_HI;             break;
    1280     case BFD_RELOC_HI16_S_GOTOFF:       ppc_reloc = R_PPC_GOT16_HA;             break;
    1281     case BFD_RELOC_24_PLT_PCREL:        ppc_reloc = R_PPC_PLTREL24;             break;
    1282     case BFD_RELOC_PPC_COPY:            ppc_reloc = R_PPC_COPY;                 break;
    1283     case BFD_RELOC_PPC_GLOB_DAT:        ppc_reloc = R_PPC_GLOB_DAT;             break;
    1284     case BFD_RELOC_PPC_LOCAL24PC:       ppc_reloc = R_PPC_LOCAL24PC;            break;
    1285     case BFD_RELOC_32_PCREL:            ppc_reloc = R_PPC_REL32;                break;
    1286     case BFD_RELOC_32_PLTOFF:           ppc_reloc = R_PPC_PLT32;                break;
    1287     case BFD_RELOC_32_PLT_PCREL:        ppc_reloc = R_PPC_PLTREL32;             break;
    1288     case BFD_RELOC_LO16_PLTOFF:         ppc_reloc = R_PPC_PLT16_LO;             break;
    1289     case BFD_RELOC_HI16_PLTOFF:         ppc_reloc = R_PPC_PLT16_HI;             break;
    1290     case BFD_RELOC_HI16_S_PLTOFF:       ppc_reloc = R_PPC_PLT16_HA;             break;
    1291     case BFD_RELOC_GPREL16:             ppc_reloc = R_PPC_SDAREL16;             break;
    1292     case BFD_RELOC_32_BASEREL:          ppc_reloc = R_PPC_SECTOFF;              break;
    1293     case BFD_RELOC_LO16_BASEREL:        ppc_reloc = R_PPC_SECTOFF_LO;           break;
    1294     case BFD_RELOC_HI16_BASEREL:        ppc_reloc = R_PPC_SECTOFF_HI;           break;
    1295     case BFD_RELOC_HI16_S_BASEREL:      ppc_reloc = R_PPC_SECTOFF_HA;           break;
    1296     case BFD_RELOC_CTOR:                ppc_reloc = R_PPC_ADDR32;               break;
    1297     case BFD_RELOC_PPC_TOC16:           ppc_reloc = R_PPC_TOC16;                break;
    1298     case BFD_RELOC_PPC_EMB_NADDR32:     ppc_reloc = R_PPC_EMB_NADDR32;          break;
    1299     case BFD_RELOC_PPC_EMB_NADDR16:     ppc_reloc = R_PPC_EMB_NADDR16;          break;
    1300     case BFD_RELOC_PPC_EMB_NADDR16_LO:  ppc_reloc = R_PPC_EMB_NADDR16_LO;       break;
    1301     case BFD_RELOC_PPC_EMB_NADDR16_HI:  ppc_reloc = R_PPC_EMB_NADDR16_HI;       break;
    1302     case BFD_RELOC_PPC_EMB_NADDR16_HA:  ppc_reloc = R_PPC_EMB_NADDR16_HA;       break;
    1303     case BFD_RELOC_PPC_EMB_SDAI16:      ppc_reloc = R_PPC_EMB_SDAI16;           break;
    1304     case BFD_RELOC_PPC_EMB_SDA2I16:     ppc_reloc = R_PPC_EMB_SDA2I16;          break;
    1305     case BFD_RELOC_PPC_EMB_SDA2REL:     ppc_reloc = R_PPC_EMB_SDA2REL;          break;
    1306     case BFD_RELOC_PPC_EMB_SDA21:       ppc_reloc = R_PPC_EMB_SDA21;            break;
    1307     case BFD_RELOC_PPC_EMB_MRKREF:      ppc_reloc = R_PPC_EMB_MRKREF;           break;
    1308     case BFD_RELOC_PPC_EMB_RELSEC16:    ppc_reloc = R_PPC_EMB_RELSEC16;         break;
    1309     case BFD_RELOC_PPC_EMB_RELST_LO:    ppc_reloc = R_PPC_EMB_RELST_LO;         break;
    1310     case BFD_RELOC_PPC_EMB_RELST_HI:    ppc_reloc = R_PPC_EMB_RELST_HI;         break;
    1311     case BFD_RELOC_PPC_EMB_RELST_HA:    ppc_reloc = R_PPC_EMB_RELST_HA;         break;
    1312     case BFD_RELOC_PPC_EMB_BIT_FLD:     ppc_reloc = R_PPC_EMB_BIT_FLD;          break;
    1313     case BFD_RELOC_PPC_EMB_RELSDA:      ppc_reloc = R_PPC_EMB_RELSDA;           break;
    1314     case BFD_RELOC_VTABLE_INHERIT:      ppc_reloc = R_PPC_GNU_VTINHERIT;        break;
    1315     case BFD_RELOC_VTABLE_ENTRY:        ppc_reloc = R_PPC_GNU_VTENTRY;          break;
     1954    case BFD_RELOC_NONE:                r = R_PPC_NONE;                 break;
     1955    case BFD_RELOC_32:                  r = R_PPC_ADDR32;               break;
     1956    case BFD_RELOC_PPC_BA26:            r = R_PPC_ADDR24;               break;
     1957    case BFD_RELOC_16:                  r = R_PPC_ADDR16;               break;
     1958    case BFD_RELOC_LO16:                r = R_PPC_ADDR16_LO;            break;
     1959    case BFD_RELOC_HI16:                r = R_PPC_ADDR16_HI;            break;
     1960    case BFD_RELOC_HI16_S:              r = R_PPC_ADDR16_HA;            break;
     1961    case BFD_RELOC_PPC_BA16:            r = R_PPC_ADDR14;               break;
     1962    case BFD_RELOC_PPC_BA16_BRTAKEN:    r = R_PPC_ADDR14_BRTAKEN;       break;
     1963    case BFD_RELOC_PPC_BA16_BRNTAKEN:   r = R_PPC_ADDR14_BRNTAKEN;      break;
     1964    case BFD_RELOC_PPC_B26:             r = R_PPC_REL24;                break;
     1965    case BFD_RELOC_PPC_B16:             r = R_PPC_REL14;                break;
     1966    case BFD_RELOC_PPC_B16_BRTAKEN:     r = R_PPC_REL14_BRTAKEN;        break;
     1967    case BFD_RELOC_PPC_B16_BRNTAKEN:    r = R_PPC_REL14_BRNTAKEN;       break;
     1968    case BFD_RELOC_16_GOTOFF:           r = R_PPC_GOT16;                break;
     1969    case BFD_RELOC_LO16_GOTOFF:         r = R_PPC_GOT16_LO;             break;
     1970    case BFD_RELOC_HI16_GOTOFF:         r = R_PPC_GOT16_HI;             break;
     1971    case BFD_RELOC_HI16_S_GOTOFF:       r = R_PPC_GOT16_HA;             break;
     1972    case BFD_RELOC_24_PLT_PCREL:        r = R_PPC_PLTREL24;             break;
     1973    case BFD_RELOC_PPC_COPY:            r = R_PPC_COPY;                 break;
     1974    case BFD_RELOC_PPC_GLOB_DAT:        r = R_PPC_GLOB_DAT;             break;
     1975    case BFD_RELOC_PPC_LOCAL24PC:       r = R_PPC_LOCAL24PC;            break;
     1976    case BFD_RELOC_32_PCREL:            r = R_PPC_REL32;                break;
     1977    case BFD_RELOC_32_PLTOFF:           r = R_PPC_PLT32;                break;
     1978    case BFD_RELOC_32_PLT_PCREL:        r = R_PPC_PLTREL32;             break;
     1979    case BFD_RELOC_LO16_PLTOFF:         r = R_PPC_PLT16_LO;             break;
     1980    case BFD_RELOC_HI16_PLTOFF:         r = R_PPC_PLT16_HI;             break;
     1981    case BFD_RELOC_HI16_S_PLTOFF:       r = R_PPC_PLT16_HA;             break;
     1982    case BFD_RELOC_GPREL16:             r = R_PPC_SDAREL16;             break;
     1983    case BFD_RELOC_16_BASEREL:          r = R_PPC_SECTOFF;              break;
     1984    case BFD_RELOC_LO16_BASEREL:        r = R_PPC_SECTOFF_LO;           break;
     1985    case BFD_RELOC_HI16_BASEREL:        r = R_PPC_SECTOFF_HI;           break;
     1986    case BFD_RELOC_HI16_S_BASEREL:      r = R_PPC_SECTOFF_HA;           break;
     1987    case BFD_RELOC_CTOR:                r = R_PPC_ADDR32;               break;
     1988    case BFD_RELOC_PPC_TOC16:           r = R_PPC_TOC16;                break;
     1989    case BFD_RELOC_PPC_TLS:             r = R_PPC_TLS;                  break;
     1990    case BFD_RELOC_PPC_DTPMOD:          r = R_PPC_DTPMOD32;             break;
     1991    case BFD_RELOC_PPC_TPREL16:         r = R_PPC_TPREL16;              break;
     1992    case BFD_RELOC_PPC_TPREL16_LO:      r = R_PPC_TPREL16_LO;           break;
     1993    case BFD_RELOC_PPC_TPREL16_HI:      r = R_PPC_TPREL16_HI;           break;
     1994    case BFD_RELOC_PPC_TPREL16_HA:      r = R_PPC_TPREL16_HA;           break;
     1995    case BFD_RELOC_PPC_TPREL:           r = R_PPC_TPREL32;              break;
     1996    case BFD_RELOC_PPC_DTPREL16:        r = R_PPC_DTPREL16;             break;
     1997    case BFD_RELOC_PPC_DTPREL16_LO:     r = R_PPC_DTPREL16_LO;          break;
     1998    case BFD_RELOC_PPC_DTPREL16_HI:     r = R_PPC_DTPREL16_HI;          break;
     1999    case BFD_RELOC_PPC_DTPREL16_HA:     r = R_PPC_DTPREL16_HA;          break;
     2000    case BFD_RELOC_PPC_DTPREL:          r = R_PPC_DTPREL32;             break;
     2001    case BFD_RELOC_PPC_GOT_TLSGD16:     r = R_PPC_GOT_TLSGD16;          break;
     2002    case BFD_RELOC_PPC_GOT_TLSGD16_LO:  r = R_PPC_GOT_TLSGD16_LO;       break;
     2003    case BFD_RELOC_PPC_GOT_TLSGD16_HI:  r = R_PPC_GOT_TLSGD16_HI;       break;
     2004    case BFD_RELOC_PPC_GOT_TLSGD16_HA:  r = R_PPC_GOT_TLSGD16_HA;       break;
     2005    case BFD_RELOC_PPC_GOT_TLSLD16:     r = R_PPC_GOT_TLSLD16;          break;
     2006    case BFD_RELOC_PPC_GOT_TLSLD16_LO:  r = R_PPC_GOT_TLSLD16_LO;       break;
     2007    case BFD_RELOC_PPC_GOT_TLSLD16_HI:  r = R_PPC_GOT_TLSLD16_HI;       break;
     2008    case BFD_RELOC_PPC_GOT_TLSLD16_HA:  r = R_PPC_GOT_TLSLD16_HA;       break;
     2009    case BFD_RELOC_PPC_GOT_TPREL16:     r = R_PPC_GOT_TPREL16;          break;
     2010    case BFD_RELOC_PPC_GOT_TPREL16_LO:  r = R_PPC_GOT_TPREL16_LO;       break;
     2011    case BFD_RELOC_PPC_GOT_TPREL16_HI:  r = R_PPC_GOT_TPREL16_HI;       break;
     2012    case BFD_RELOC_PPC_GOT_TPREL16_HA:  r = R_PPC_GOT_TPREL16_HA;       break;
     2013    case BFD_RELOC_PPC_GOT_DTPREL16:    r = R_PPC_GOT_DTPREL16;         break;
     2014    case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO;      break;
     2015    case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI;      break;
     2016    case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA;      break;
     2017    case BFD_RELOC_PPC_EMB_NADDR32:     r = R_PPC_EMB_NADDR32;          break;
     2018    case BFD_RELOC_PPC_EMB_NADDR16:     r = R_PPC_EMB_NADDR16;          break;
     2019    case BFD_RELOC_PPC_EMB_NADDR16_LO:  r = R_PPC_EMB_NADDR16_LO;       break;
     2020    case BFD_RELOC_PPC_EMB_NADDR16_HI:  r = R_PPC_EMB_NADDR16_HI;       break;
     2021    case BFD_RELOC_PPC_EMB_NADDR16_HA:  r = R_PPC_EMB_NADDR16_HA;       break;
     2022    case BFD_RELOC_PPC_EMB_SDAI16:      r = R_PPC_EMB_SDAI16;           break;
     2023    case BFD_RELOC_PPC_EMB_SDA2I16:     r = R_PPC_EMB_SDA2I16;          break;
     2024    case BFD_RELOC_PPC_EMB_SDA2REL:     r = R_PPC_EMB_SDA2REL;          break;
     2025    case BFD_RELOC_PPC_EMB_SDA21:       r = R_PPC_EMB_SDA21;            break;
     2026    case BFD_RELOC_PPC_EMB_MRKREF:      r = R_PPC_EMB_MRKREF;           break;
     2027    case BFD_RELOC_PPC_EMB_RELSEC16:    r = R_PPC_EMB_RELSEC16;         break;
     2028    case BFD_RELOC_PPC_EMB_RELST_LO:    r = R_PPC_EMB_RELST_LO;         break;
     2029    case BFD_RELOC_PPC_EMB_RELST_HI:    r = R_PPC_EMB_RELST_HI;         break;
     2030    case BFD_RELOC_PPC_EMB_RELST_HA:    r = R_PPC_EMB_RELST_HA;         break;
     2031    case BFD_RELOC_PPC_EMB_BIT_FLD:     r = R_PPC_EMB_BIT_FLD;          break;
     2032    case BFD_RELOC_PPC_EMB_RELSDA:      r = R_PPC_EMB_RELSDA;           break;
     2033    case BFD_RELOC_VTABLE_INHERIT:      r = R_PPC_GNU_VTINHERIT;        break;
     2034    case BFD_RELOC_VTABLE_ENTRY:        r = R_PPC_GNU_VTENTRY;          break;
    13162035    }
    13172036
    1318   return ppc_elf_howto_table[(int) ppc_reloc];
     2037  return ppc_elf_howto_table[(int) r];
    13192038};
    13202039
     
    13252044     bfd *abfd ATTRIBUTE_UNUSED;
    13262045     arelent *cache_ptr;
    1327      Elf32_Internal_Rela *dst;
     2046     Elf_Internal_Rela *dst;
    13282047{
    13292048  if (!ppc_elf_howto_table[R_PPC_ADDR32])
     
    13732092}
    13742093
     2094static bfd_reloc_status_type
     2095ppc_elf_unhandled_reloc (abfd, reloc_entry, symbol, data,
     2096                         input_section, output_bfd, error_message)
     2097     bfd *abfd;
     2098     arelent *reloc_entry;
     2099     asymbol *symbol;
     2100     PTR data;
     2101     asection *input_section;
     2102     bfd *output_bfd;
     2103     char **error_message;
     2104{
     2105  /* If this is a relocatable link (output_bfd test tells us), just
     2106     call the generic function.  Any adjustment will be done at final
     2107     link time.  */
     2108  if (output_bfd != NULL)
     2109    return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
     2110                                  input_section, output_bfd, error_message);
     2111
     2112  if (error_message != NULL)
     2113    {
     2114      static char buf[60];
     2115      sprintf (buf, "generic linker can't handle %s",
     2116               reloc_entry->howto->name);
     2117      *error_message = buf;
     2118    }
     2119  return bfd_reloc_dangerous;
     2120}
     2121
     2122/* Fix bad default arch selected for a 32 bit input bfd when the
     2123   default is 64 bit.  */
     2124
     2125static bfd_boolean
     2126ppc_elf_object_p (abfd)
     2127     bfd *abfd;
     2128{
     2129  if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
     2130    {
     2131      Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
     2132
     2133      if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
     2134        {
     2135          /* Relies on arch after 64 bit default being 32 bit default.  */
     2136          abfd->arch_info = abfd->arch_info->next;
     2137          BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
     2138        }
     2139    }
     2140  return TRUE;
     2141}
     2142
    13752143/* Function to set whether a module needs the -mrelocatable bit set.  */
    13762144
    1377 static boolean
     2145static bfd_boolean
    13782146ppc_elf_set_private_flags (abfd, flags)
    13792147     bfd *abfd;
     
    13842152
    13852153  elf_elfheader (abfd)->e_flags = flags;
    1386   elf_flags_init (abfd) = true;
    1387   return true;
     2154  elf_flags_init (abfd) = TRUE;
     2155  return TRUE;
    13882156}
    13892157
    1390 /* Copy backend specific data from one object module to another */
    1391 static boolean
    1392 ppc_elf_copy_private_bfd_data (ibfd, obfd)
    1393      bfd *ibfd;
    1394      bfd *obfd;
    1395 {
    1396   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    1397       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    1398     return true;
    1399 
    1400   BFD_ASSERT (!elf_flags_init (obfd)
    1401               || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
    1402 
    1403   elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
    1404   elf_flags_init (obfd) = true;
    1405   return true;
    1406 }
    1407 
    14082158/* Merge backend specific data from an object file to the output
    1409    object file when linking */
    1410 static boolean
     2159   object file when linking.  */
     2160
     2161static bfd_boolean
    14112162ppc_elf_merge_private_bfd_data (ibfd, obfd)
    14122163     bfd *ibfd;
     
    14152166  flagword old_flags;
    14162167  flagword new_flags;
    1417   boolean error;
    1418 
    1419   /* Check if we have the same endianess */
    1420   if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
    1421     return false;
     2168  bfd_boolean error;
     2169
     2170  /* Check if we have the same endianess. */
     2171  if (! _bfd_generic_verify_endian_match (ibfd, obfd))
     2172    return FALSE;
    14222173
    14232174  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    14242175      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    1425     return true;
     2176    return TRUE;
    14262177
    14272178  new_flags = elf_elfheader (ibfd)->e_flags;
    14282179  old_flags = elf_elfheader (obfd)->e_flags;
    1429   if (!elf_flags_init (obfd))   /* First call, no flags set */
     2180  if (!elf_flags_init (obfd))
    14302181    {
    1431       elf_flags_init (obfd) = true;
     2182      /* First call, no flags set.  */
     2183      elf_flags_init (obfd) = TRUE;
    14322184      elf_elfheader (obfd)->e_flags = new_flags;
    14332185    }
    14342186
    1435   else if (new_flags == old_flags)      /* Compatible flags are ok */
     2187  /* Compatible flags are ok.  */
     2188  else if (new_flags == old_flags)
    14362189    ;
    14372190
    1438   else                                  /* Incompatible flags */
     2191  /* Incompatible flags.  */
     2192  else
    14392193    {
    1440       /* Warn about -mrelocatable mismatch.  Allow -mrelocatable-lib to be linked
    1441         with either.  */
    1442       error = false;
     2194      /* Warn about -mrelocatable mismatch.  Allow -mrelocatable-lib
     2195         to be linked with either.  */
     2196      error = FALSE;
    14432197      if ((new_flags & EF_PPC_RELOCATABLE) != 0
    14442198          && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
    14452199        {
    1446           error = true;
     2200          error = TRUE;
    14472201          (*_bfd_error_handler)
    14482202            (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
    1449              bfd_get_filename (ibfd));
     2203             bfd_archive_filename (ibfd));
    14502204        }
    14512205      else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
    14522206               && (old_flags & EF_PPC_RELOCATABLE) != 0)
    14532207        {
    1454           error = true;
     2208          error = TRUE;
    14552209          (*_bfd_error_handler)
    14562210            (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
    1457              bfd_get_filename (ibfd));
     2211             bfd_archive_filename (ibfd));
    14582212        }
    14592213
     
    14632217
    14642218      /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
    1465         but each input file is either -mrelocatable or -mrelocatable-lib.  */
     2219        but each input file is either -mrelocatable or -mrelocatable-lib.  */
    14662220      if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
    14672221          && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
     
    14692223        elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
    14702224
    1471       /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
     2225      /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
     2226         any module uses it.  */
    14722227      elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
    14732228
    1474       new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
    1475       old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
    1476 
    1477       /* Warn about any other mismatches */
     2229      new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
     2230      old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
     2231
     2232      /* Warn about any other mismatches. */
    14782233      if (new_flags != old_flags)
    14792234        {
    1480           error = true;
     2235          error = TRUE;
    14812236          (*_bfd_error_handler)
    14822237            (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
    1483              bfd_get_filename (ibfd), (long) new_flags, (long) old_flags);
     2238             bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
    14842239        }
    14852240
     
    14872242        {
    14882243          bfd_set_error (bfd_error_bad_value);
    1489           return false;
     2244          return FALSE;
    14902245        }
    14912246    }
    14922247
    1493   return true;
     2248  return TRUE;
    14942249}
    14952250
     
    14982253   is called when elfcode.h finds a section with an unknown type.  */
    14992254
    1500 static boolean
     2255static bfd_boolean
    15012256ppc_elf_section_from_shdr (abfd, hdr, name)
    15022257     bfd *abfd;
    1503      Elf32_Internal_Shdr *hdr;
    1504      char *name;
     2258     Elf_Internal_Shdr *hdr;
     2259     const char *name;
    15052260{
    15062261  asection *newsect;
     
    15082263
    15092264  if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
    1510     return false;
     2265    return FALSE;
    15112266
    15122267  newsect = hdr->bfd_section;
     
    15192274
    15202275  bfd_set_section_flags (abfd, newsect, flags);
    1521   return true;
     2276  return TRUE;
    15222277}
    15232278
     
    15252280/* Set up any other section flags and such that may be necessary.  */
    15262281
    1527 static boolean
     2282static bfd_boolean
    15282283ppc_elf_fake_sections (abfd, shdr, asect)
    15292284     bfd *abfd ATTRIBUTE_UNUSED;
    1530      Elf32_Internal_Shdr *shdr;
     2285     Elf_Internal_Shdr *shdr;
    15312286     asection *asect;
    15322287{
     
    15372292    shdr->sh_type = SHT_ORDERED;
    15382293
    1539   return true;
     2294  return TRUE;
    15402295}
    15412296
     
    15512306  elf_linker_section_t *lsect;
    15522307
    1553   /* Record the first bfd section that needs the special section */
     2308  /* Record the first bfd section that needs the special section. */
    15542309  if (!dynobj)
    15552310    dynobj = elf_hash_table (info)->dynobj = abfd;
    15562311
    1557   /* If this is the first time, create the section */
     2312  /* If this is the first time, create the section. */
    15582313  lsect = elf_linker_section (dynobj, which);
    15592314  if (!lsect)
     
    15642319      defaults = zero_section;
    15652320      defaults.which = which;
    1566       defaults.hole_written_p = false;
     2321      defaults.hole_written_p = FALSE;
    15672322      defaults.alignment = 2;
    15682323
     
    15812336        {
    15822337        default:
    1583           (*_bfd_error_handler) (_("%s: Unknown special linker type %d"),
     2338          (*_bfd_error_handler) (_("%s: unknown special linker type %d"),
    15842339                                 bfd_get_filename (abfd),
    15852340                                 (int) which);
     
    16422397/* Modify the segment map if needed.  */
    16432398
    1644 static boolean
     2399static bfd_boolean
    16452400ppc_elf_modify_segment_map (abfd)
    16462401     bfd *abfd ATTRIBUTE_UNUSED;
    16472402{
    1648   return true;
     2403  return TRUE;
    16492404}
    16502405
     2406
     2407/* The powerpc .got has a blrl instruction in it.  Mark it executable.  */
     2408
     2409static bfd_boolean
     2410ppc_elf_create_got (abfd, info)
     2411     bfd *abfd;
     2412     struct bfd_link_info *info;
     2413{
     2414  struct ppc_elf_link_hash_table *htab;
     2415  asection *s;
     2416  flagword flags;
     2417
     2418  if (!_bfd_elf_create_got_section (abfd, info))
     2419    return FALSE;
     2420
     2421  htab = ppc_elf_hash_table (info);
     2422  htab->got = s = bfd_get_section_by_name (abfd, ".got");
     2423  if (s == NULL)
     2424    abort ();
     2425
     2426  flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY
     2427           | SEC_LINKER_CREATED);
     2428  if (!bfd_set_section_flags (abfd, s, flags))
     2429    return FALSE;
     2430
     2431  htab->relgot = bfd_make_section (abfd, ".rela.got");
     2432  if (!htab->relgot
     2433      || ! bfd_set_section_flags (abfd, htab->relgot,
     2434                                  (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
     2435                                   | SEC_IN_MEMORY | SEC_LINKER_CREATED
     2436                                   | SEC_READONLY))
     2437      || ! bfd_set_section_alignment (abfd, htab->relgot, 2))
     2438    return FALSE;
     2439
     2440  return TRUE;
     2441}
    16512442
    16522443/* We have to create .dynsbss and .rela.sbss here so that they get mapped
     
    16542445   to create .dynbss and .rela.bss).  */
    16552446
    1656 static boolean
     2447static bfd_boolean
    16572448ppc_elf_create_dynamic_sections (abfd, info)
    16582449     bfd *abfd;
    16592450     struct bfd_link_info *info;
    16602451{
    1661   register asection *s;
     2452  struct ppc_elf_link_hash_table *htab;
     2453  asection *s;
    16622454  flagword flags;
    16632455
     2456  if (!ppc_elf_create_got (abfd, info))
     2457    return FALSE;
     2458
    16642459  if (!_bfd_elf_create_dynamic_sections (abfd, info))
    1665     return false;
     2460    return FALSE;
    16662461
    16672462  flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
    16682463           | SEC_LINKER_CREATED);
    16692464
    1670   s = bfd_make_section (abfd, ".dynsbss");
     2465  htab = ppc_elf_hash_table (info);
     2466  htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
     2467  htab->dynsbss = s = bfd_make_section (abfd, ".dynsbss");
    16712468  if (s == NULL
    16722469      || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
    1673     return false;
     2470    return FALSE;
    16742471
    16752472  if (! info->shared)
    16762473    {
    1677       s = bfd_make_section (abfd, ".rela.sbss");
     2474      htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
     2475      htab->relsbss = s = bfd_make_section (abfd, ".rela.sbss");
    16782476      if (s == NULL
    16792477          || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
    16802478          || ! bfd_set_section_alignment (abfd, s, 2))
    1681         return false;
     2479        return FALSE;
    16822480    }
    1683   return true;
     2481
     2482  htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
     2483  htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
     2484  if (s == NULL)
     2485    abort ();
     2486
     2487  flags = SEC_ALLOC | SEC_CODE | SEC_IN_MEMORY | SEC_LINKER_CREATED;
     2488  return bfd_set_section_flags (abfd, s, flags);
    16842489}
    16852490
     
    16902495   understand.  */
    16912496
    1692 static boolean
     2497static bfd_boolean
    16932498ppc_elf_adjust_dynamic_symbol (info, h)
    16942499     struct bfd_link_info *info;
    16952500     struct elf_link_hash_entry *h;
    16962501{
    1697   bfd *dynobj = elf_hash_table (info)->dynobj;
     2502  struct ppc_elf_link_hash_table *htab;
    16982503  asection *s;
    16992504  unsigned int power_of_two;
    1700   bfd_vma plt_offset;
    17012505
    17022506#ifdef DEBUG
    1703   fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", h->root.root.string);
     2507  fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
     2508           h->root.root.string);
    17042509#endif
    17052510
    17062511  /* Make sure we know what is going on here.  */
    1707   BFD_ASSERT (dynobj != NULL
     2512  htab = ppc_elf_hash_table (info);
     2513  BFD_ASSERT (htab->elf.dynobj != NULL
    17082514              && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
    17092515                  || h->weakdef != NULL
     
    17152521                          & ELF_LINK_HASH_DEF_REGULAR) == 0)));
    17162522
    1717   /* If this is a function, put it in the procedure linkage table.  We
    1718      will fill in the contents of the procedure linkage table later,
    1719      when we know the address of the .got section.  */
     2523  /* Deal with function syms.  */
    17202524  if (h->type == STT_FUNC
    17212525      || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
    17222526    {
    1723       if (! elf_hash_table (info)->dynamic_sections_created
    1724           || SYMBOL_CALLS_LOCAL (info, h)
    1725           || (info->shared && h->plt.refcount <= 0))
     2527      /* Clear procedure linkage table information for any symbol that
     2528         won't need a .plt entry.  */
     2529      if (! htab->elf.dynamic_sections_created
     2530          || SYMBOL_CALLS_LOCAL (info, h)
     2531          || h->plt.refcount <= 0)
    17262532        {
    17272533          /* A PLT entry is not required/allowed when:
    17282534
    1729              1. We are not using ld.so; because then the PLT entry
    1730              can't be set up, so we can't use one.
    1731 
    1732              2. We know for certain that a call to this symbol
    1733              will go to this object.
    1734 
    1735              3. GC has rendered the entry unused.
    1736              Note, however, that in an executable all references to the
    1737              symbol go to the PLT, so we can't turn it off in that case.
    1738              ??? The correct thing to do here is to reference count
    1739              all uses of the symbol, not just those to the GOT or PLT.  */
     2535          1. We are not using ld.so; because then the PLT entry
     2536          can't be set up, so we can't use one.
     2537
     2538          2. We know for certain that a call to this symbol
     2539          will go to this object.
     2540
     2541          3. GC has rendered the entry unused.  */
    17402542          h->plt.offset = (bfd_vma) -1;
    17412543          h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
    1742           return true;
    17432544        }
    1744 
    1745       /* Make sure this symbol is output as a dynamic symbol.  */
    1746       if (h->dynindx == -1)
    1747         {
    1748           if (! bfd_elf32_link_record_dynamic_symbol (info, h))
    1749             return false;
    1750         }
    1751       BFD_ASSERT (h->dynindx != -1);
    1752 
    1753       s = bfd_get_section_by_name (dynobj, ".plt");
    1754       BFD_ASSERT (s != NULL);
    1755 
    1756       /* If this is the first .plt entry, make room for the special
    1757          first entry.  */
    1758       if (s->_raw_size == 0)
    1759         s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
    1760 
    1761       /* The PowerPC PLT is actually composed of two parts, the first part
    1762          is 2 words (for a load and a jump), and then there is a remaining
    1763          word available at the end.  */
    1764       plt_offset = (PLT_INITIAL_ENTRY_SIZE
    1765                     + (PLT_SLOT_SIZE
    1766                        * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE)
    1767                           / PLT_ENTRY_SIZE)));
    1768 
    1769       /* If this symbol is not defined in a regular file, and we are
    1770          not generating a shared library, then set the symbol to this
    1771          location in the .plt.  This is required to make function
    1772          pointers compare as equal between the normal executable and
    1773          the shared library.  */
    1774       if (! info->shared
    1775           && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
    1776         {
    1777           h->root.u.def.section = s;
    1778           h->root.u.def.value = plt_offset;
    1779         }
    1780 
    1781       h->plt.offset = plt_offset;
    1782 
    1783       /* Make room for this entry.  After the 8192nd entry, room
    1784          for two entries is allocated.  */
    1785       if ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
    1786           >= PLT_NUM_SINGLE_ENTRIES)
    1787         s->_raw_size += 2 * PLT_ENTRY_SIZE;
    1788       else
    1789         s->_raw_size += PLT_ENTRY_SIZE;
    1790 
    1791       /* We also need to make an entry in the .rela.plt section.  */
    1792       s = bfd_get_section_by_name (dynobj, ".rela.plt");
    1793       BFD_ASSERT (s != NULL);
    1794       s->_raw_size += sizeof (Elf32_External_Rela);
    1795 
    1796       return true;
     2545      return TRUE;
    17972546    }
     2547  else
     2548    h->plt.offset = (bfd_vma) -1;
    17982549
    17992550  /* If this is a weak symbol, and there is a real definition, the
     
    18062557      h->root.u.def.section = h->weakdef->root.u.def.section;
    18072558      h->root.u.def.value = h->weakdef->root.u.def.value;
    1808       return true;
     2559      if (ELIMINATE_COPY_RELOCS)
     2560        h->elf_link_hash_flags
     2561          = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
     2562             | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
     2563      return TRUE;
    18092564    }
    18102565
     
    18172572     be handled correctly by relocate_section.  */
    18182573  if (info->shared)
    1819     return true;
     2574    return TRUE;
     2575
     2576  /* If there are no references to this symbol that do not use the
     2577     GOT, we don't need to generate a copy reloc.  */
     2578  if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
     2579    return TRUE;
     2580
     2581  if (ELIMINATE_COPY_RELOCS)
     2582    {
     2583      struct ppc_elf_dyn_relocs *p;
     2584      for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
     2585        {
     2586          s = p->sec->output_section;
     2587          if (s != NULL && (s->flags & SEC_READONLY) != 0)
     2588            break;
     2589        }
     2590
     2591      /* If we didn't find any dynamic relocs in read-only sections, then
     2592         we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
     2593      if (p == NULL)
     2594        {
     2595          h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
     2596          return TRUE;
     2597        }
     2598    }
    18202599
    18212600  /* We must allocate the symbol in our .dynbss section, which will
     
    18332612     only if there were actually SDAREL relocs for that symbol.  */
    18342613
    1835   if (h->size <= elf_gp_size (dynobj))
    1836     s = bfd_get_section_by_name (dynobj, ".dynsbss");
     2614  if (h->size <= elf_gp_size (htab->elf.dynobj))
     2615    s = htab->dynsbss;
    18372616  else
    1838     s = bfd_get_section_by_name (dynobj, ".dynbss");
     2617    s = htab->dynbss;
    18392618  BFD_ASSERT (s != NULL);
    18402619
     
    18472626      asection *srel;
    18482627
    1849       if (h->size <= elf_gp_size (dynobj))
    1850         srel = bfd_get_section_by_name (dynobj, ".rela.sbss");
     2628      if (h->size <= elf_gp_size (htab->elf.dynobj))
     2629        srel = htab->relsbss;
    18512630      else
    1852         srel = bfd_get_section_by_name (dynobj, ".rela.bss");
     2631        srel = htab->relbss;
    18532632      BFD_ASSERT (srel != NULL);
    18542633      srel->_raw_size += sizeof (Elf32_External_Rela);
     
    18652644  s->_raw_size = BFD_ALIGN (s->_raw_size,
    18662645                            (bfd_size_type) (1 << power_of_two));
    1867   if (power_of_two > bfd_get_section_alignment (dynobj, s))
     2646  if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
    18682647    {
    1869       if (! bfd_set_section_alignment (dynobj, s, power_of_two))
    1870         return false;
     2648      if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
     2649        return FALSE;
    18712650    }
    18722651
     
    18782657  s->_raw_size += h->size;
    18792658
    1880   return true;
     2659  return TRUE;
    18812660}
    18822661
    18832662
     2663/* This is the condition under which finish_dynamic_symbol will be
     2664   called from elflink.h.  If elflink.h doesn't call our
     2665   finish_dynamic_symbol routine, we'll need to do something about
     2666   initializing any .plt and .got entries in relocate_section.  */
     2667#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
     2668  ((DYN)                                                                \
     2669   && ((SHARED)                                                         \
     2670       || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)      \
     2671   && ((H)->dynindx != -1                                               \
     2672       || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
     2673
     2674/* Of those relocs that might be copied as dynamic relocs, this macro
     2675   selects those that must be copied when linking a shared library,
     2676   even when the symbol is local.  */
     2677
     2678#define MUST_BE_DYN_RELOC(RTYPE)                \
     2679  ((RTYPE) != R_PPC_REL24                       \
     2680   && (RTYPE) != R_PPC_REL14                    \
     2681   && (RTYPE) != R_PPC_REL14_BRTAKEN            \
     2682   && (RTYPE) != R_PPC_REL14_BRNTAKEN           \
     2683   && (RTYPE) != R_PPC_REL32)
     2684
     2685/* Allocate space in associated reloc sections for dynamic relocs.  */
     2686
     2687static bfd_boolean
     2688allocate_dynrelocs (h, inf)
     2689     struct elf_link_hash_entry *h;
     2690     PTR inf;
     2691{
     2692  struct bfd_link_info *info = (struct bfd_link_info *) inf;
     2693  struct ppc_elf_link_hash_entry *eh;
     2694  struct ppc_elf_link_hash_table *htab;
     2695  struct ppc_elf_dyn_relocs *p;
     2696
     2697  if (h->root.type == bfd_link_hash_indirect)
     2698    return TRUE;
     2699
     2700  if (h->root.type == bfd_link_hash_warning)
     2701    /* When warning symbols are created, they **replace** the "real"
     2702       entry in the hash table, thus we never get to see the real
     2703       symbol in a hash traversal.  So look at it now.  */
     2704    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     2705
     2706  htab = ppc_elf_hash_table (info);
     2707  if (htab->elf.dynamic_sections_created
     2708      && h->plt.refcount > 0)
     2709    {
     2710      /* Make sure this symbol is output as a dynamic symbol.  */
     2711      if (h->dynindx == -1
     2712          && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
     2713        {
     2714          if (! bfd_elf32_link_record_dynamic_symbol (info, h))
     2715            return FALSE;
     2716        }
     2717
     2718      if (info->shared
     2719          || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
     2720        {
     2721          asection *s = htab->plt;
     2722
     2723          /* If this is the first .plt entry, make room for the special
     2724             first entry.  */
     2725          if (s->_raw_size == 0)
     2726            s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
     2727
     2728          /* The PowerPC PLT is actually composed of two parts, the
     2729             first part is 2 words (for a load and a jump), and then
     2730             there is a remaining word available at the end.  */
     2731          h->plt.offset = (PLT_INITIAL_ENTRY_SIZE
     2732                           + (PLT_SLOT_SIZE
     2733                              * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE)
     2734                                 / PLT_ENTRY_SIZE)));
     2735
     2736          /* If this symbol is not defined in a regular file, and we
     2737             are not generating a shared library, then set the symbol
     2738             to this location in the .plt.  This is required to make
     2739             function pointers compare as equal between the normal
     2740             executable and the shared library.  */
     2741          if (! info->shared
     2742              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
     2743            {
     2744              h->root.u.def.section = s;
     2745              h->root.u.def.value = h->plt.offset;
     2746            }
     2747
     2748          /* Make room for this entry.  After the 8192nd entry, room
     2749             for two entries is allocated.  */
     2750          s->_raw_size += PLT_ENTRY_SIZE;
     2751          if ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
     2752              > PLT_NUM_SINGLE_ENTRIES)
     2753            s->_raw_size += PLT_ENTRY_SIZE;
     2754
     2755          /* We also need to make an entry in the .rela.plt section.  */
     2756          htab->relplt->_raw_size += sizeof (Elf32_External_Rela);
     2757        }
     2758      else
     2759        {
     2760          h->plt.offset = (bfd_vma) -1;
     2761          h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
     2762        }
     2763    }
     2764  else
     2765    {
     2766      h->plt.offset = (bfd_vma) -1;
     2767      h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
     2768    }
     2769
     2770  eh = (struct ppc_elf_link_hash_entry *) h;
     2771  if (eh->elf.got.refcount > 0)
     2772    {
     2773      /* Make sure this symbol is output as a dynamic symbol.  */
     2774      if (eh->elf.dynindx == -1
     2775          && (eh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
     2776        {
     2777          if (!bfd_elf32_link_record_dynamic_symbol (info, &eh->elf))
     2778            return FALSE;
     2779        }
     2780
     2781      if (eh->tls_mask == (TLS_TLS | TLS_LD)
     2782          && !(eh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))
     2783        /* If just an LD reloc, we'll just use htab->tlsld_got.offset.  */
     2784        eh->elf.got.offset = (bfd_vma) -1;
     2785      else
     2786        {
     2787          bfd_boolean dyn;
     2788          eh->elf.got.offset = htab->got->_raw_size;
     2789          if ((eh->tls_mask & TLS_TLS) != 0)
     2790            {
     2791              if ((eh->tls_mask & TLS_LD) != 0)
     2792                htab->got->_raw_size += 8;
     2793              if ((eh->tls_mask & TLS_GD) != 0)
     2794                htab->got->_raw_size += 8;
     2795              if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
     2796                htab->got->_raw_size += 4;
     2797              if ((eh->tls_mask & TLS_DTPREL) != 0)
     2798                htab->got->_raw_size += 4;
     2799            }
     2800          else
     2801            htab->got->_raw_size += 4;
     2802          dyn = htab->elf.dynamic_sections_created;
     2803          if (info->shared
     2804              || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
     2805            {
     2806              /* All the entries we allocated need relocs.  */
     2807              htab->relgot->_raw_size
     2808                += ((htab->got->_raw_size - eh->elf.got.offset) / 4
     2809                    * sizeof (Elf32_External_Rela));
     2810              /* Except LD only needs one.  */
     2811              if ((eh->tls_mask & TLS_LD) != 0)
     2812                htab->relgot->_raw_size -= sizeof (Elf32_External_Rela);
     2813            }
     2814        }
     2815    }
     2816  else
     2817    eh->elf.got.offset = (bfd_vma) -1;
     2818
     2819  if (eh->dyn_relocs == NULL)
     2820    return TRUE;
     2821
     2822  /* In the shared -Bsymbolic case, discard space allocated for
     2823     dynamic pc-relative relocs against symbols which turn out to be
     2824     defined in regular objects.  For the normal shared case, discard
     2825     space for relocs that have become local due to symbol visibility
     2826     changes.  */
     2827  if (info->shared)
     2828    {
     2829      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
     2830          && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
     2831              || info->symbolic))
     2832        {
     2833          struct ppc_elf_dyn_relocs **pp;
     2834
     2835          for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
     2836            {
     2837              p->count -= p->pc_count;
     2838              p->pc_count = 0;
     2839              if (p->count == 0)
     2840                *pp = p->next;
     2841              else
     2842                pp = &p->next;
     2843            }
     2844        }
     2845    }
     2846  else if (ELIMINATE_COPY_RELOCS)
     2847    {
     2848      /* For the non-shared case, discard space for relocs against
     2849         symbols which turn out to need copy relocs or are not
     2850         dynamic.  */
     2851
     2852      if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
     2853          && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
     2854          && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
     2855        {
     2856          /* Make sure this symbol is output as a dynamic symbol.
     2857             Undefined weak syms won't yet be marked as dynamic.  */
     2858          if (h->dynindx == -1
     2859              && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
     2860            {
     2861              if (! bfd_elf64_link_record_dynamic_symbol (info, h))
     2862                return FALSE;
     2863            }
     2864
     2865          /* If that succeeded, we know we'll be keeping all the
     2866             relocs.  */
     2867          if (h->dynindx != -1)
     2868            goto keep;
     2869        }
     2870
     2871      eh->dyn_relocs = NULL;
     2872
     2873    keep: ;
     2874    }
     2875
     2876  /* Finally, allocate space.  */
     2877  for (p = eh->dyn_relocs; p != NULL; p = p->next)
     2878    {
     2879      asection *sreloc = elf_section_data (p->sec)->sreloc;
     2880      sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
     2881    }
     2882
     2883  return TRUE;
     2884}
     2885
     2886/* Find any dynamic relocs that apply to read-only sections.  */
     2887
     2888static bfd_boolean
     2889readonly_dynrelocs (h, info)
     2890     struct elf_link_hash_entry *h;
     2891     PTR info;
     2892{
     2893  struct ppc_elf_dyn_relocs *p;
     2894
     2895  if (h->root.type == bfd_link_hash_indirect)
     2896    return TRUE;
     2897
     2898  if (h->root.type == bfd_link_hash_warning)
     2899    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     2900
     2901  for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
     2902    {
     2903      asection *s = p->sec->output_section;
     2904
     2905      if (s != NULL
     2906          && ((s->flags & (SEC_READONLY | SEC_ALLOC))
     2907              == (SEC_READONLY | SEC_ALLOC)))
     2908        {
     2909          ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
     2910
     2911          /* Not an error, just cut short the traversal.  */
     2912          return FALSE;
     2913        }
     2914    }
     2915  return TRUE;
     2916}
     2917
    18842918/* Set the sizes of the dynamic sections.  */
    18852919
    1886 static boolean
     2920static bfd_boolean
    18872921ppc_elf_size_dynamic_sections (output_bfd, info)
    1888      bfd *output_bfd;
     2922     bfd *output_bfd ATTRIBUTE_UNUSED;
    18892923     struct bfd_link_info *info;
    18902924{
    1891   bfd *dynobj;
     2925  struct ppc_elf_link_hash_table *htab;
    18922926  asection *s;
    1893   boolean plt;
    1894   boolean relocs;
    1895   boolean reltext;
     2927  bfd_boolean relocs;
     2928  bfd *ibfd;
    18962929
    18972930#ifdef DEBUG
     
    18992932#endif
    19002933
    1901   dynobj = elf_hash_table (info)->dynobj;
    1902   BFD_ASSERT (dynobj != NULL);
     2934  htab = ppc_elf_hash_table (info);
     2935  BFD_ASSERT (htab->elf.dynobj != NULL);
    19032936
    19042937  if (elf_hash_table (info)->dynamic_sections_created)
     
    19072940      if (! info->shared)
    19082941        {
    1909           s = bfd_get_section_by_name (dynobj, ".interp");
     2942          s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
    19102943          BFD_ASSERT (s != NULL);
    19112944          s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
     
    19132946        }
    19142947    }
     2948
     2949  if (htab->tlsld_got.refcount > 0)
     2950    {
     2951      htab->tlsld_got.offset = htab->got->_raw_size;
     2952      htab->got->_raw_size += 8;
     2953      if (info->shared)
     2954        htab->relgot->_raw_size += sizeof (Elf32_External_Rela);
     2955    }
    19152956  else
     2957    htab->tlsld_got.offset = (bfd_vma) -1;
     2958
     2959  /* Set up .got offsets for local syms, and space for local dynamic
     2960     relocs.  */
     2961  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
    19162962    {
    1917       /* We may have created entries in the .rela.got, .rela.sdata, and
    1918          .rela.sdata2 sections.  However, if we are not creating the
    1919          dynamic sections, we will not actually use these entries.  Reset
    1920          the size of .rela.got, et al, which will cause it to get
    1921          stripped from the output file below.  */
    1922       static char *rela_sections[] = { ".rela.got", ".rela.sdata",
    1923                                        ".rela.sdata2", ".rela.sbss",
    1924                                        (char *) 0 };
    1925       char **p;
    1926 
    1927       for (p = rela_sections; *p != (char *) 0; p++)
     2963      bfd_signed_vma *local_got;
     2964      bfd_signed_vma *end_local_got;
     2965      char *lgot_masks;
     2966      bfd_size_type locsymcount;
     2967      Elf_Internal_Shdr *symtab_hdr;
     2968      asection *srel;
     2969
     2970      if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
     2971        continue;
     2972
     2973      for (s = ibfd->sections; s != NULL; s = s->next)
    19282974        {
    1929           s = bfd_get_section_by_name (dynobj, *p);
    1930           if (s != NULL)
    1931             s->_raw_size = 0;
     2975          struct ppc_elf_dyn_relocs *p;
     2976
     2977          for (p = ((struct ppc_elf_dyn_relocs *)
     2978                    elf_section_data (s)->local_dynrel);
     2979               p != NULL;
     2980               p = p->next)
     2981            {
     2982              if (!bfd_is_abs_section (p->sec)
     2983                  && bfd_is_abs_section (p->sec->output_section))
     2984                {
     2985                  /* Input section has been discarded, either because
     2986                     it is a copy of a linkonce section or due to
     2987                     linker script /DISCARD/, so we'll be discarding
     2988                     the relocs too.  */
     2989                }
     2990              else if (p->count != 0)
     2991                {
     2992                  elf_section_data (p->sec)->sreloc->_raw_size
     2993                    += p->count * sizeof (Elf32_External_Rela);
     2994                  if ((p->sec->output_section->flags
     2995                       & (SEC_READONLY | SEC_ALLOC))
     2996                      == (SEC_READONLY | SEC_ALLOC))
     2997                    info->flags |= DF_TEXTREL;
     2998                }
     2999            }
    19323000        }
     3001
     3002      local_got = elf_local_got_refcounts (ibfd);
     3003      if (!local_got)
     3004        continue;
     3005
     3006      symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
     3007      locsymcount = symtab_hdr->sh_info;
     3008      end_local_got = local_got + locsymcount;
     3009      lgot_masks = (char *) end_local_got;
     3010      s = htab->got;
     3011      srel = htab->relgot;
     3012      for (; local_got < end_local_got; ++local_got, ++lgot_masks)
     3013        if (*local_got > 0)
     3014          {
     3015            if (*lgot_masks == (TLS_TLS | TLS_LD))
     3016              {
     3017                /* If just an LD reloc, we'll just use
     3018                   htab->tlsld_got.offset.  */
     3019                if (htab->tlsld_got.offset == (bfd_vma) -1)
     3020                  {
     3021                    htab->tlsld_got.offset = s->_raw_size;
     3022                    s->_raw_size += 8;
     3023                    if (info->shared)
     3024                      srel->_raw_size += sizeof (Elf32_External_Rela);
     3025                  }
     3026                *local_got = (bfd_vma) -1;
     3027              }
     3028            else
     3029              {
     3030                *local_got = s->_raw_size;
     3031                if ((*lgot_masks & TLS_TLS) != 0)
     3032                  {
     3033                    if ((*lgot_masks & TLS_GD) != 0)
     3034                      s->_raw_size += 8;
     3035                    if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
     3036                      s->_raw_size += 4;
     3037                    if ((*lgot_masks & TLS_DTPREL) != 0)
     3038                      s->_raw_size += 4;
     3039                  }
     3040                else
     3041                  s->_raw_size += 4;
     3042                if (info->shared)
     3043                  srel->_raw_size += ((s->_raw_size - *local_got) / 4
     3044                                      * sizeof (Elf32_External_Rela));
     3045              }
     3046          }
     3047        else
     3048          *local_got = (bfd_vma) -1;
    19333049    }
    19343050
    1935   /* The check_relocs and adjust_dynamic_symbol entry points have
    1936      determined the sizes of the various dynamic sections.  Allocate
    1937      memory for them.  */
    1938   plt = false;
    1939   relocs = false;
    1940   reltext = false;
    1941   for (s = dynobj->sections; s != NULL; s = s->next)
     3051  /* Allocate space for global sym dynamic relocs.  */
     3052  elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
     3053
     3054  /* We've now determined the sizes of the various dynamic sections.
     3055     Allocate memory for them.  */
     3056  relocs = FALSE;
     3057  for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
    19423058    {
    1943       const char *name;
    1944       boolean strip;
    1945 
    19463059      if ((s->flags & SEC_LINKER_CREATED) == 0)
    19473060        continue;
    19483061
    1949       /* It's OK to base decisions on the section name, because none
    1950          of the dynobj section names depend upon the input files.  */
    1951       name = bfd_get_section_name (dynobj, s);
    1952 
    1953       strip = false;
    1954 
    1955       if (strcmp (name, ".plt") == 0)
     3062      if (s == htab->plt
     3063          || s == htab->got
     3064          || (htab->sdata != NULL && s == htab->sdata->section)
     3065          || (htab->sdata2 != NULL && s == htab->sdata2->section))
    19563066        {
    1957           if (s->_raw_size == 0)
    1958             {
    1959               /* Strip this section if we don't need it; see the
    1960                  comment below.  */
    1961               strip = true;
    1962             }
    1963           else
    1964             {
    1965               /* Remember whether there is a PLT.  */
    1966               plt = true;
    1967             }
     3067          /* Strip this section if we don't need it; see the
     3068             comment below.  */
    19683069        }
    1969       else if (strncmp (name, ".rela", 5) == 0)
     3070      else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
    19703071        {
    19713072          if (s->_raw_size == 0)
     
    19803081                 function which decides whether anything needs to go
    19813082                 into these sections.  */
    1982               strip = true;
    19833083            }
    19843084          else
    19853085            {
    1986               asection *target;
    1987               const char *outname;
    1988 
    19893086              /* Remember whether there are any relocation sections.  */
    1990               relocs = true;
    1991 
    1992               /* If this relocation section applies to a read only
    1993                  section, then we probably need a DT_TEXTREL entry.  */
    1994               outname = bfd_get_section_name (output_bfd,
    1995                                               s->output_section);
    1996               target = bfd_get_section_by_name (output_bfd, outname + 5);
    1997               if (target != NULL
    1998                   && (target->flags & SEC_READONLY) != 0
    1999                   && (target->flags & SEC_ALLOC) != 0)
    2000                 reltext = true;
     3087              relocs = TRUE;
    20013088
    20023089              /* We use the reloc_count field as a counter if we need
     
    20053092            }
    20063093        }
    2007       else if (strcmp (name, ".got") != 0
    2008                && strcmp (name, ".sdata") != 0
    2009                && strcmp (name, ".sdata2") != 0)
     3094      else
    20103095        {
    20113096          /* It's not one of our sections, so don't allocate space.  */
     
    20133098        }
    20143099
    2015       if (strip)
     3100      if (s->_raw_size == 0)
    20163101        {
    20173102          _bfd_strip_section_from_output (info, s);
     
    20203105
    20213106      /* Allocate memory for the section contents.  */
    2022       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
    2023       if (s->contents == NULL && s->_raw_size != 0)
    2024         return false;
     3107      s->contents = (bfd_byte *) bfd_zalloc (htab->elf.dynobj, s->_raw_size);
     3108      if (s->contents == NULL)
     3109        return FALSE;
    20253110    }
    20263111
    2027   if (elf_hash_table (info)->dynamic_sections_created)
     3112  if (htab->elf.dynamic_sections_created)
    20283113    {
    20293114      /* Add some entries to the .dynamic section.  We fill in the
     
    20323117         the .dynamic section.  The DT_DEBUG entry is filled in by the
    20333118         dynamic linker and used by the debugger.  */
    2034       if (! info->shared)
     3119#define add_dynamic_entry(TAG, VAL) \
     3120  bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
     3121
     3122      if (!info->shared)
    20353123        {
    2036           if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
    2037             return false;
     3124          if (!add_dynamic_entry (DT_DEBUG, 0))
     3125            return FALSE;
    20383126        }
    20393127
    2040       if (plt)
     3128      if (htab->plt != NULL && htab->plt->_raw_size != 0)
    20413129        {
    2042           if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)
    2043               || ! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
    2044               || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
    2045               || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
    2046             return false;
     3130          if (!add_dynamic_entry (DT_PLTGOT, 0)
     3131              || !add_dynamic_entry (DT_PLTRELSZ, 0)
     3132              || !add_dynamic_entry (DT_PLTREL, DT_RELA)
     3133              || !add_dynamic_entry (DT_JMPREL, 0))
     3134            return FALSE;
    20473135        }
    20483136
    20493137      if (relocs)
    20503138        {
    2051           if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
    2052               || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
    2053               || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
    2054                                                 sizeof (Elf32_External_Rela)))
    2055             return false;
     3139          if (!add_dynamic_entry (DT_RELA, 0)
     3140              || !add_dynamic_entry (DT_RELASZ, 0)
     3141              || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
     3142            return FALSE;
    20563143        }
    20573144
    2058       if (reltext)
     3145      /* If any dynamic relocs apply to a read-only section, then we
     3146         need a DT_TEXTREL entry.  */
     3147      if ((info->flags & DF_TEXTREL) == 0)
     3148        elf_link_hash_traverse (elf_hash_table (info), readonly_dynrelocs,
     3149                                (PTR) info);
     3150
     3151      if ((info->flags & DF_TEXTREL) != 0)
    20593152        {
    2060           if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
    2061             return false;
    2062           info->flags |= DF_TEXTREL;
     3153          if (!add_dynamic_entry (DT_TEXTREL, 0))
     3154            return FALSE;
    20633155        }
    20643156    }
    2065 
    2066   return true;
     3157#undef add_dynamic_entry
     3158
     3159  return TRUE;
    20673160}
    20683161
     3162
     3163static bfd_boolean
     3164update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type)
     3165     bfd *abfd;
     3166     Elf_Internal_Shdr *symtab_hdr;
     3167     unsigned long r_symndx;
     3168     int tls_type;
     3169{
     3170  bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
     3171  char *local_got_tls_masks;
     3172
     3173  if (local_got_refcounts == NULL)
     3174    {
     3175      bfd_size_type size = symtab_hdr->sh_info;
     3176
     3177      size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks);
     3178      local_got_refcounts = (bfd_signed_vma *) bfd_zalloc (abfd, size);
     3179      if (local_got_refcounts == NULL)
     3180        return FALSE;
     3181      elf_local_got_refcounts (abfd) = local_got_refcounts;
     3182    }
     3183
     3184  local_got_refcounts[r_symndx] += 1;
     3185  local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info);
     3186  local_got_tls_masks[r_symndx] |= tls_type;
     3187  return TRUE;
     3188}
     3189
     3190static void
     3191bad_shared_reloc (abfd, r_type)
     3192     bfd *abfd;
     3193     enum elf_ppc_reloc_type r_type;
     3194{
     3195  (*_bfd_error_handler)
     3196    (_("%s: relocation %s cannot be used when making a shared object"),
     3197     bfd_archive_filename (abfd),
     3198     ppc_elf_howto_table[(int) r_type]->name);
     3199  bfd_set_error (bfd_error_bad_value);
     3200}
    20693201
    20703202/* Look through the relocs for a section during the first phase, and
     
    20723204   table.  */
    20733205
    2074 static boolean
     3206static bfd_boolean
    20753207ppc_elf_check_relocs (abfd, info, sec, relocs)
    20763208     bfd *abfd;
     
    20793211     const Elf_Internal_Rela *relocs;
    20803212{
    2081   bfd *dynobj;
     3213  struct ppc_elf_link_hash_table *htab;
    20823214  Elf_Internal_Shdr *symtab_hdr;
    2083   struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
     3215  struct elf_link_hash_entry **sym_hashes;
    20843216  const Elf_Internal_Rela *rel;
    20853217  const Elf_Internal_Rela *rel_end;
    2086   bfd_signed_vma *local_got_refcounts;
    2087   elf_linker_section_t *sdata;
    2088   elf_linker_section_t *sdata2;
    20893218  asection *sreloc;
    2090   asection *sgot = NULL;
    2091   asection *srelgot = NULL;
    20923219
    20933220  if (info->relocateable)
    2094     return true;
     3221    return TRUE;
    20953222
    20963223#ifdef DEBUG
    20973224  fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n",
    20983225           bfd_get_section_name (abfd, sec),
    2099            bfd_get_filename (abfd));
     3226           bfd_archive_filename (abfd));
    21003227#endif
    21013228
     
    21033230     special symbols are created.  */
    21043231
    2105   if ((sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA)) == NULL)
     3232  htab = ppc_elf_hash_table (info);
     3233  if (htab->sdata == NULL)
    21063234    {
    2107       sdata = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
    2108       if (!sdata)
    2109         return false;
     3235      htab->sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA);
     3236      if (htab->sdata == NULL)
     3237        htab->sdata = ppc_elf_create_linker_section (abfd, info,
     3238                                                     LINKER_SECTION_SDATA);
     3239      if (htab->sdata == NULL)
     3240        return FALSE;
    21103241    }
    21113242
    2112   if ((sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2)) == NULL)
     3243  if (htab->sdata2 == NULL)
    21133244    {
    2114       sdata2 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA2);
    2115       if (!sdata2)
    2116         return false;
     3245      htab->sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2);
     3246      if (htab->sdata2 == NULL)
     3247        htab->sdata2 = ppc_elf_create_linker_section (abfd, info,
     3248                                                      LINKER_SECTION_SDATA2);
     3249      if (htab->sdata2 == NULL)
     3250        return FALSE;
    21173251    }
    21183252
    2119   dynobj = elf_hash_table (info)->dynobj;
    21203253  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
    2121   local_got_refcounts = elf_local_got_refcounts (abfd);
    2122 
    21233254  sym_hashes = elf_sym_hashes (abfd);
    2124   sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
    2125   if (!elf_bad_symtab (abfd))
    2126     sym_hashes_end -= symtab_hdr->sh_info;
    2127 
    21283255  sreloc = NULL;
    21293256
     
    21323259    {
    21333260      unsigned long r_symndx;
     3261      enum elf_ppc_reloc_type r_type;
    21343262      struct elf_link_hash_entry *h;
     3263      int tls_type = 0;
    21353264
    21363265      r_symndx = ELF32_R_SYM (rel->r_info);
     
    21453274      if (h && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
    21463275        {
    2147           if (sgot == NULL)
     3276          if (htab->got == NULL)
    21483277            {
    2149               if (dynobj == NULL)
    2150                 elf_hash_table (info)->dynobj = dynobj = abfd;
    2151               if (! _bfd_elf_create_got_section (dynobj, info))
    2152                 return false;
    2153               sgot = bfd_get_section_by_name (dynobj, ".got");
    2154               BFD_ASSERT (sgot != NULL);
     3278              if (htab->elf.dynobj == NULL)
     3279                htab->elf.dynobj = abfd;
     3280              if (!ppc_elf_create_got (htab->elf.dynobj, info))
     3281                return FALSE;
    21553282            }
    21563283        }
    21573284
    2158       switch (ELF32_R_TYPE (rel->r_info))
     3285      r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info);
     3286      switch (r_type)
    21593287        {
    2160         /* GOT16 relocations */
     3288        case R_PPC_GOT_TLSLD16:
     3289        case R_PPC_GOT_TLSLD16_LO:
     3290        case R_PPC_GOT_TLSLD16_HI:
     3291        case R_PPC_GOT_TLSLD16_HA:
     3292          htab->tlsld_got.refcount += 1;
     3293          tls_type = TLS_TLS | TLS_LD;
     3294          goto dogottls;
     3295
     3296        case R_PPC_GOT_TLSGD16:
     3297        case R_PPC_GOT_TLSGD16_LO:
     3298        case R_PPC_GOT_TLSGD16_HI:
     3299        case R_PPC_GOT_TLSGD16_HA:
     3300          tls_type = TLS_TLS | TLS_GD;
     3301          goto dogottls;
     3302
     3303        case R_PPC_GOT_TPREL16:
     3304        case R_PPC_GOT_TPREL16_LO:
     3305        case R_PPC_GOT_TPREL16_HI:
     3306        case R_PPC_GOT_TPREL16_HA:
     3307          if (info->shared)
     3308            info->flags |= DF_STATIC_TLS;
     3309          tls_type = TLS_TLS | TLS_TPREL;
     3310          goto dogottls;
     3311
     3312        case R_PPC_GOT_DTPREL16:
     3313        case R_PPC_GOT_DTPREL16_LO:
     3314        case R_PPC_GOT_DTPREL16_HI:
     3315        case R_PPC_GOT_DTPREL16_HA:
     3316          tls_type = TLS_TLS | TLS_DTPREL;
     3317        dogottls:
     3318          sec->has_tls_reloc = 1;
     3319          /* Fall thru */
     3320
     3321          /* GOT16 relocations */
    21613322        case R_PPC_GOT16:
    21623323        case R_PPC_GOT16_LO:
     
    21643325        case R_PPC_GOT16_HA:
    21653326          /* This symbol requires a global offset table entry.  */
    2166 
    2167           if (sgot == NULL)
     3327          if (htab->got == NULL)
    21683328            {
    2169               if (dynobj == NULL)
    2170                 elf_hash_table (info)->dynobj = dynobj = abfd;
    2171               if (! _bfd_elf_create_got_section (dynobj, info))
    2172                 return false;
    2173               sgot = bfd_get_section_by_name (dynobj, ".got");
    2174               BFD_ASSERT (sgot != NULL);
     3329              if (htab->elf.dynobj == NULL)
     3330                htab->elf.dynobj = abfd;
     3331              if (!ppc_elf_create_got (htab->elf.dynobj, info))
     3332                return FALSE;
    21753333            }
    2176 
    2177           if (srelgot == NULL
    2178               && (h != NULL || info->shared))
    2179             {
    2180               srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
    2181               if (srelgot == NULL)
    2182                 {
    2183                   srelgot = bfd_make_section (dynobj, ".rela.got");
    2184                   if (srelgot == NULL
    2185                       || ! bfd_set_section_flags (dynobj, srelgot,
    2186                                                   (SEC_ALLOC
    2187                                                    | SEC_LOAD
    2188                                                    | SEC_HAS_CONTENTS
    2189                                                    | SEC_IN_MEMORY
    2190                                                    | SEC_LINKER_CREATED
    2191                                                    | SEC_READONLY))
    2192                       || ! bfd_set_section_alignment (dynobj, srelgot, 2))
    2193                     return false;
    2194                 }
    2195             }
    2196 
    21973334          if (h != NULL)
    21983335            {
    2199               if (h->got.refcount == -1)
    2200                 {
    2201                   /* Make sure this symbol is output as a dynamic symbol.  */
    2202                   if (h->dynindx == -1)
    2203                     if (!bfd_elf32_link_record_dynamic_symbol (info, h))
    2204                       return false;
    2205 
    2206                   /* Allocate space in the .got.  */
    2207                   sgot->_raw_size += 4;
    2208                   /* Allocate relocation space.  */
    2209                   srelgot->_raw_size += sizeof (Elf32_External_Rela);
    2210 
    2211                   h->got.refcount = 1;
    2212                 }
    2213               else
    2214                 h->got.refcount++;
     3336              h->got.refcount += 1;
     3337              ppc_elf_hash_entry (h)->tls_mask |= tls_type;
    22153338            }
    22163339          else
    2217             {
    2218               /* This is a global offset table entry for a local symbol.  */
    2219               if (local_got_refcounts == NULL)
    2220                 {
    2221                   size_t size;
    2222 
    2223                   size = symtab_hdr->sh_info * sizeof (bfd_signed_vma);
    2224                   local_got_refcounts = (bfd_signed_vma *)
    2225                     bfd_alloc (abfd, size);
    2226                   if (local_got_refcounts == NULL)
    2227                     return false;
    2228                   elf_local_got_refcounts (abfd) = local_got_refcounts;
    2229                   memset (local_got_refcounts, -1, size);
    2230                 }
    2231               if (local_got_refcounts[r_symndx] == -1)
    2232                 {
    2233                   sgot->_raw_size += 4;
    2234 
    2235                   /* If we are generating a shared object, we need to
    2236                      output a R_PPC_RELATIVE reloc so that the
    2237                      dynamic linker can adjust this GOT entry.  */
    2238                   if (info->shared)
    2239                     srelgot->_raw_size += sizeof (Elf32_External_Rela);
    2240 
    2241                   local_got_refcounts[r_symndx] = 1;
    2242                 }
    2243               else
    2244                 local_got_refcounts[r_symndx]++;
    2245             }
     3340            /* This is a global offset table entry for a local symbol.  */
     3341            if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
     3342              return FALSE;
    22463343          break;
    22473344
    2248         /* Indirect .sdata relocation */
     3345          /* Indirect .sdata relocation. */
    22493346        case R_PPC_EMB_SDAI16:
    22503347          if (info->shared)
    22513348            {
    2252               ((*_bfd_error_handler)
    2253                (_("%s: relocation %s cannot be used when making a shared object"),
    2254                 bfd_get_filename (abfd), "R_PPC_EMB_SDAI16"));
    2255               return false;
     3349              bad_shared_reloc (abfd, r_type);
     3350              return FALSE;
    22563351            }
    2257 
    2258           if (srelgot == NULL && (h != NULL || info->shared))
    2259             {
    2260               srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
    2261               if (srelgot == NULL)
    2262                 {
    2263                   srelgot = bfd_make_section (dynobj, ".rela.got");
    2264                   if (srelgot == NULL
    2265                       || ! bfd_set_section_flags (dynobj, srelgot,
    2266                                                   (SEC_ALLOC
    2267                                                    | SEC_LOAD
    2268                                                    | SEC_HAS_CONTENTS
    2269                                                    | SEC_IN_MEMORY
    2270                                                    | SEC_LINKER_CREATED
    2271                                                    | SEC_READONLY))
    2272                       || ! bfd_set_section_alignment (dynobj, srelgot, 2))
    2273                     return false;
    2274                 }
    2275             }
    2276 
    2277           if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata, h, rel))
    2278             return false;
    2279 
     3352          if (!bfd_elf32_create_pointer_linker_section (abfd, info,
     3353                                                        htab->sdata, h, rel))
     3354            return FALSE;
    22803355          break;
    22813356
    2282         /* Indirect .sdata2 relocation */
     3357          /* Indirect .sdata2 relocation. */
    22833358        case R_PPC_EMB_SDA2I16:
    22843359          if (info->shared)
    22853360            {
    2286               ((*_bfd_error_handler)
    2287                (_("%s: relocation %s cannot be used when making a shared object"),
    2288                 bfd_get_filename (abfd), "R_PPC_EMB_SDA2I16"));
    2289               return false;
     3361              bad_shared_reloc (abfd, r_type);
     3362              return FALSE;
    22903363            }
    2291 
    2292           if (srelgot == NULL && (h != NULL || info->shared))
    2293             {
    2294               srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
    2295               if (srelgot == NULL)
    2296                 {
    2297                   srelgot = bfd_make_section (dynobj, ".rela.got");
    2298                   if (srelgot == NULL
    2299                       || ! bfd_set_section_flags (dynobj, srelgot,
    2300                                                   (SEC_ALLOC
    2301                                                    | SEC_LOAD
    2302                                                    | SEC_HAS_CONTENTS
    2303                                                    | SEC_IN_MEMORY
    2304                                                    | SEC_LINKER_CREATED
    2305                                                    | SEC_READONLY))
    2306                       || ! bfd_set_section_alignment (dynobj, srelgot, 2))
    2307                     return false;
    2308                 }
    2309             }
    2310 
    2311           if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata2, h, rel))
    2312             return false;
    2313 
     3364          if (!bfd_elf32_create_pointer_linker_section (abfd, info,
     3365                                                        htab->sdata2, h, rel))
     3366            return FALSE;
    23143367          break;
    23153368
     
    23173370        case R_PPC_EMB_SDA2REL:
    23183371        case R_PPC_EMB_SDA21:
     3372        case R_PPC_EMB_RELSDA:
     3373        case R_PPC_EMB_NADDR32:
     3374        case R_PPC_EMB_NADDR16:
     3375        case R_PPC_EMB_NADDR16_LO:
     3376        case R_PPC_EMB_NADDR16_HI:
     3377        case R_PPC_EMB_NADDR16_HA:
    23193378          if (info->shared)
    23203379            {
    2321               ((*_bfd_error_handler)
    2322                (_("%s: relocation %s cannot be used when making a shared object"),
    2323                 bfd_get_filename (abfd),
    2324                 ppc_elf_howto_table[(int) ELF32_R_TYPE (rel->r_info)]->name));
    2325               return false;
     3380              bad_shared_reloc (abfd, r_type);
     3381              return FALSE;
    23263382            }
    23273383          break;
     
    23293385        case R_PPC_PLT32:
    23303386        case R_PPC_PLTREL24:
     3387        case R_PPC_PLTREL32:
    23313388        case R_PPC_PLT16_LO:
    23323389        case R_PPC_PLT16_HI:
     
    23363393#endif
    23373394          /* This symbol requires a procedure linkage table entry.  We
    2338              actually build the entry in adjust_dynamic_symbol,
    2339              because this might be a case of linking PIC code without
    2340              linking in any dynamic objects, in which case we don't
    2341              need to generate a procedure linkage table after all.  */
     3395             actually build the entry in finish_dynamic_symbol,
     3396             because this might be a case of linking PIC code without
     3397             linking in any dynamic objects, in which case we don't
     3398             need to generate a procedure linkage table after all.  */
    23423399
    23433400          if (h == NULL)
    23443401            {
    23453402              /* It does not make sense to have a procedure linkage
    2346                 table entry for a local symbol.  */
     3403                table entry for a local symbol.  */
    23473404              bfd_set_error (bfd_error_bad_value);
    2348               return false;
     3405              return FALSE;
    23493406            }
    23503407
    2351           /* Make sure this symbol is output as a dynamic symbol.  */
    2352           if (h->dynindx == -1)
    2353             {
    2354               if (! bfd_elf32_link_record_dynamic_symbol (info, h))
    2355                 return false;
    2356             }
    2357           if (h->plt.refcount == -1)
    2358             {
    2359               h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
    2360               h->plt.refcount = 1;
    2361             }
    2362           else
    2363             h->plt.refcount++;
     3408          h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
     3409          h->plt.refcount++;
    23643410          break;
    23653411
     
    23713417        case R_PPC_SECTOFF_HI:
    23723418        case R_PPC_SECTOFF_HA:
     3419        case R_PPC_DTPREL16:
     3420        case R_PPC_DTPREL16_LO:
     3421        case R_PPC_DTPREL16_HI:
     3422        case R_PPC_DTPREL16_HA:
     3423        case R_PPC_TOC16:
    23733424          break;
    23743425
    2375           /* This refers only to functions defined in the shared library */
     3426          /* This are just markers.  */
     3427        case R_PPC_TLS:
     3428        case R_PPC_EMB_MRKREF:
     3429        case R_PPC_NONE:
     3430        case R_PPC_max:
     3431          break;
     3432
     3433          /* These should only appear in dynamic objects.  */
     3434        case R_PPC_COPY:
     3435        case R_PPC_GLOB_DAT:
     3436        case R_PPC_JMP_SLOT:
     3437        case R_PPC_RELATIVE:
     3438          break;
     3439
     3440          /* These aren't handled yet.  We'll report an error later.  */
     3441        case R_PPC_ADDR30:
     3442        case R_PPC_EMB_RELSEC16:
     3443        case R_PPC_EMB_RELST_LO:
     3444        case R_PPC_EMB_RELST_HI:
     3445        case R_PPC_EMB_RELST_HA:
     3446        case R_PPC_EMB_BIT_FLD:
     3447          break;
     3448
     3449          /* This refers only to functions defined in the shared library.  */
    23763450        case R_PPC_LOCAL24PC:
    23773451          break;
     
    23813455        case R_PPC_GNU_VTINHERIT:
    23823456          if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
    2383             return false;
     3457            return FALSE;
    23843458          break;
    23853459
     
    23883462        case R_PPC_GNU_VTENTRY:
    23893463          if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
    2390             return false;
     3464            return FALSE;
    23913465          break;
     3466
     3467          /* We shouldn't really be seeing these.  */
     3468        case R_PPC_TPREL32:
     3469          if (info->shared)
     3470            info->flags |= DF_STATIC_TLS;
     3471          goto dodyn;
     3472
     3473          /* Nor these.  */
     3474        case R_PPC_DTPMOD32:
     3475        case R_PPC_DTPREL32:
     3476          goto dodyn;
     3477
     3478        case R_PPC_TPREL16:
     3479        case R_PPC_TPREL16_LO:
     3480        case R_PPC_TPREL16_HI:
     3481        case R_PPC_TPREL16_HA:
     3482          if (info->shared)
     3483            info->flags |= DF_STATIC_TLS;
     3484          goto dodyn;
    23923485
    23933486          /* When creating a shared object, we must copy these
     
    24003493        case R_PPC_REL32:
    24013494          if (h == NULL
    2402               || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
    2403               || SYMBOL_REFERENCES_LOCAL (info, h))
     3495              || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
    24043496            break;
    24053497          /* fall through */
    24063498
    2407         default:
    2408           if (info->shared)
     3499        case R_PPC_ADDR32:
     3500        case R_PPC_ADDR24:
     3501        case R_PPC_ADDR16:
     3502        case R_PPC_ADDR16_LO:
     3503        case R_PPC_ADDR16_HI:
     3504        case R_PPC_ADDR16_HA:
     3505        case R_PPC_ADDR14:
     3506        case R_PPC_ADDR14_BRTAKEN:
     3507        case R_PPC_ADDR14_BRNTAKEN:
     3508        case R_PPC_UADDR32:
     3509        case R_PPC_UADDR16:
     3510          if (h != NULL && !info->shared)
    24093511            {
     3512              /* We may need a plt entry if the symbol turns out to be
     3513                 a function defined in a dynamic object.  */
     3514              h->plt.refcount++;
     3515
     3516              /* We may need a copy reloc too.  */
     3517              h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
     3518            }
     3519
     3520        dodyn:
     3521          /* If we are creating a shared library, and this is a reloc
     3522             against a global symbol, or a non PC relative reloc
     3523             against a local symbol, then we need to copy the reloc
     3524             into the shared library.  However, if we are linking with
     3525             -Bsymbolic, we do not need to copy a reloc against a
     3526             global symbol which is defined in an object we are
     3527             including in the link (i.e., DEF_REGULAR is set).  At
     3528             this point we have not seen all the input files, so it is
     3529             possible that DEF_REGULAR is not set now but will be set
     3530             later (it is never cleared).  In case of a weak definition,
     3531             DEF_REGULAR may be cleared later by a strong definition in
     3532             a shared library.  We account for that possibility below by
     3533             storing information in the dyn_relocs field of the hash
     3534             table entry.  A similar situation occurs when creating
     3535             shared libraries and symbol visibility changes render the
     3536             symbol local.
     3537
     3538             If on the other hand, we are creating an executable, we
     3539             may need to keep relocations for symbols satisfied by a
     3540             dynamic library if we manage to avoid copy relocs for the
     3541             symbol.  */
     3542          if ((info->shared
     3543               && (MUST_BE_DYN_RELOC (r_type)
     3544                   || (h != NULL
     3545                       && (! info->symbolic
     3546                           || h->root.type == bfd_link_hash_defweak
     3547                           || (h->elf_link_hash_flags
     3548                               & ELF_LINK_HASH_DEF_REGULAR) == 0))))
     3549              || (ELIMINATE_COPY_RELOCS
     3550                  && !info->shared
     3551                  && (sec->flags & SEC_ALLOC) != 0
     3552                  && h != NULL
     3553                  && (h->root.type == bfd_link_hash_defweak
     3554                      || (h->elf_link_hash_flags
     3555                          & ELF_LINK_HASH_DEF_REGULAR) == 0)))
     3556            {
     3557              struct ppc_elf_dyn_relocs *p;
     3558              struct ppc_elf_dyn_relocs **head;
     3559
    24103560#ifdef DEBUG
    24113561              fprintf (stderr, "ppc_elf_check_relocs need to create relocation for %s\n",
    2412                        (h && h->root.root.string) ? h->root.root.string : "<unknown>");
     3562                       (h && h->root.root.string
     3563                        ? h->root.root.string : "<unknown>"));
    24133564#endif
    24143565              if (sreloc == NULL)
     
    24213572                           elf_section_data (sec)->rel_hdr.sh_name));
    24223573                  if (name == NULL)
    2423                     return false;
     3574                    return FALSE;
    24243575
    24253576                  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
     
    24273578                                         name + 5) == 0);
    24283579
    2429                   sreloc = bfd_get_section_by_name (dynobj, name);
     3580                  sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
    24303581                  if (sreloc == NULL)
    24313582                    {
    24323583                      flagword flags;
    24333584
    2434                       sreloc = bfd_make_section (dynobj, name);
     3585                      sreloc = bfd_make_section (htab->elf.dynobj, name);
    24353586                      flags = (SEC_HAS_CONTENTS | SEC_READONLY
    24363587                               | SEC_IN_MEMORY | SEC_LINKER_CREATED);
     
    24383589                        flags |= SEC_ALLOC | SEC_LOAD;
    24393590                      if (sreloc == NULL
    2440                           || ! bfd_set_section_flags (dynobj, sreloc, flags)
    2441                           || ! bfd_set_section_alignment (dynobj, sreloc, 2))
    2442                         return false;
     3591                          || ! bfd_set_section_flags (htab->elf.dynobj,
     3592                                                      sreloc, flags)
     3593                          || ! bfd_set_section_alignment (htab->elf.dynobj,
     3594                                                          sreloc, 2))
     3595                        return FALSE;
    24433596                    }
     3597                  elf_section_data (sec)->sreloc = sreloc;
    24443598                }
    24453599
    2446               sreloc->_raw_size += sizeof (Elf32_External_Rela);
    2447 
    2448               /* FIXME: We should here do what the m68k and i386
    2449                  backends do: if the reloc is pc-relative, record it
    2450                  in case it turns out that the reloc is unnecessary
    2451                  because the symbol is forced local by versioning or
    2452                  we are linking with -Bdynamic.  Fortunately this
    2453                  case is not frequent.  */
     3600              /* If this is a global symbol, we count the number of
     3601                 relocations we need for this symbol.  */
     3602              if (h != NULL)
     3603                {
     3604                  head = &ppc_elf_hash_entry (h)->dyn_relocs;
     3605                }
     3606              else
     3607                {
     3608                  /* Track dynamic relocs needed for local syms too.
     3609                     We really need local syms available to do this
     3610                     easily.  Oh well.  */
     3611
     3612                  asection *s;
     3613                  s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
     3614                                                 sec, r_symndx);
     3615                  if (s == NULL)
     3616                    return FALSE;
     3617
     3618                  head = ((struct ppc_elf_dyn_relocs **)
     3619                          &elf_section_data (s)->local_dynrel);
     3620                }
     3621
     3622              p = *head;
     3623              if (p == NULL || p->sec != sec)
     3624                {
     3625                  p = ((struct ppc_elf_dyn_relocs *)
     3626                       bfd_alloc (htab->elf.dynobj, sizeof *p));
     3627                  if (p == NULL)
     3628                    return FALSE;
     3629                  p->next = *head;
     3630                  *head = p;
     3631                  p->sec = sec;
     3632                  p->count = 0;
     3633                  p->pc_count = 0;
     3634                }
     3635
     3636              p->count += 1;
     3637              if (!MUST_BE_DYN_RELOC (r_type))
     3638                p->pc_count += 1;
    24543639            }
    24553640
     
    24583643    }
    24593644
    2460   return true;
     3645  return TRUE;
    24613646}
    24623647
     
    24653650
    24663651static asection *
    2467 ppc_elf_gc_mark_hook (abfd, info, rel, h, sym)
    2468      bfd *abfd;
     3652ppc_elf_gc_mark_hook (sec, info, rel, h, sym)
     3653     asection *sec;
    24693654     struct bfd_link_info *info ATTRIBUTE_UNUSED;
    24703655     Elf_Internal_Rela *rel;
     
    24963681    }
    24973682  else
    2498     {
    2499       if (!(elf_bad_symtab (abfd)
    2500             && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
    2501           && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
    2502                 && sym->st_shndx != SHN_COMMON))
    2503         {
    2504           return bfd_section_from_elf_index (abfd, sym->st_shndx);
    2505         }
    2506     }
     3683    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
    25073684
    25083685  return NULL;
    25093686}
    25103687
    2511 /* Update the got entry reference counts for the section being removed.  */
    2512 
    2513 static boolean
     3688/* Update the got, plt and dynamic reloc reference counts for the
     3689   section being removed.  */
     3690
     3691static bfd_boolean
    25143692ppc_elf_gc_sweep_hook (abfd, info, sec, relocs)
    25153693     bfd *abfd;
    2516      struct bfd_link_info *info ATTRIBUTE_UNUSED;
     3694     struct bfd_link_info *info;
    25173695     asection *sec;
    25183696     const Elf_Internal_Rela *relocs;
    25193697{
     3698  struct ppc_elf_link_hash_table *htab;
    25203699  Elf_Internal_Shdr *symtab_hdr;
    25213700  struct elf_link_hash_entry **sym_hashes;
    25223701  bfd_signed_vma *local_got_refcounts;
    25233702  const Elf_Internal_Rela *rel, *relend;
    2524   unsigned long r_symndx;
    2525   struct elf_link_hash_entry *h;
    2526 
     3703
     3704  elf_section_data (sec)->local_dynrel = NULL;
     3705
     3706  htab = ppc_elf_hash_table (info);
    25273707  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
    25283708  sym_hashes = elf_sym_hashes (abfd);
     
    25313711  relend = relocs + sec->reloc_count;
    25323712  for (rel = relocs; rel < relend; rel++)
    2533     switch (ELF32_R_TYPE (rel->r_info))
    2534       {
    2535       case R_PPC_GOT16:
    2536       case R_PPC_GOT16_LO:
    2537       case R_PPC_GOT16_HI:
    2538       case R_PPC_GOT16_HA:
    2539         r_symndx = ELF32_R_SYM (rel->r_info);
    2540         if (r_symndx >= symtab_hdr->sh_info)
     3713    {
     3714      unsigned long r_symndx;
     3715      enum elf_ppc_reloc_type r_type;
     3716      struct elf_link_hash_entry *h = NULL;
     3717
     3718      r_symndx = ELF32_R_SYM (rel->r_info);
     3719      if (r_symndx >= symtab_hdr->sh_info)
     3720        {
     3721          struct ppc_elf_dyn_relocs **pp, *p;
     3722          struct ppc_elf_link_hash_entry *eh;
     3723
     3724          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
     3725          eh = (struct ppc_elf_link_hash_entry *) h;
     3726
     3727          for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
     3728            if (p->sec == sec)
     3729              {
     3730                /* Everything must go for SEC.  */
     3731                *pp = p->next;
     3732                break;
     3733              }
     3734        }
     3735
     3736      r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info);
     3737      switch (r_type)
     3738        {
     3739        case R_PPC_GOT_TLSLD16:
     3740        case R_PPC_GOT_TLSLD16_LO:
     3741        case R_PPC_GOT_TLSLD16_HI:
     3742        case R_PPC_GOT_TLSLD16_HA:
     3743          htab->tlsld_got.refcount -= 1;
     3744          /* Fall thru */
     3745
     3746        case R_PPC_GOT_TLSGD16:
     3747        case R_PPC_GOT_TLSGD16_LO:
     3748        case R_PPC_GOT_TLSGD16_HI:
     3749        case R_PPC_GOT_TLSGD16_HA:
     3750        case R_PPC_GOT_TPREL16:
     3751        case R_PPC_GOT_TPREL16_LO:
     3752        case R_PPC_GOT_TPREL16_HI:
     3753        case R_PPC_GOT_TPREL16_HA:
     3754        case R_PPC_GOT_DTPREL16:
     3755        case R_PPC_GOT_DTPREL16_LO:
     3756        case R_PPC_GOT_DTPREL16_HI:
     3757        case R_PPC_GOT_DTPREL16_HA:
     3758        case R_PPC_GOT16:
     3759        case R_PPC_GOT16_LO:
     3760        case R_PPC_GOT16_HI:
     3761        case R_PPC_GOT16_HA:
     3762          if (h != NULL)
     3763            {
     3764              if (h->got.refcount > 0)
     3765                h->got.refcount--;
     3766            }
     3767          else if (local_got_refcounts != NULL)
     3768            {
     3769              if (local_got_refcounts[r_symndx] > 0)
     3770                local_got_refcounts[r_symndx]--;
     3771            }
     3772          break;
     3773
     3774        case R_PPC_REL24:
     3775        case R_PPC_REL14:
     3776        case R_PPC_REL14_BRTAKEN:
     3777        case R_PPC_REL14_BRNTAKEN:
     3778        case R_PPC_REL32:
     3779          if (h == NULL
     3780              || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
     3781            break;
     3782          /* Fall thru */
     3783
     3784        case R_PPC_ADDR32:
     3785        case R_PPC_ADDR24:
     3786        case R_PPC_ADDR16:
     3787        case R_PPC_ADDR16_LO:
     3788        case R_PPC_ADDR16_HI:
     3789        case R_PPC_ADDR16_HA:
     3790        case R_PPC_ADDR14:
     3791        case R_PPC_ADDR14_BRTAKEN:
     3792        case R_PPC_ADDR14_BRNTAKEN:
     3793        case R_PPC_UADDR32:
     3794        case R_PPC_UADDR16:
     3795        case R_PPC_PLT32:
     3796        case R_PPC_PLTREL24:
     3797        case R_PPC_PLT16_LO:
     3798        case R_PPC_PLT16_HI:
     3799        case R_PPC_PLT16_HA:
     3800          if (h != NULL)
     3801            {
     3802              if (h->plt.refcount > 0)
     3803                h->plt.refcount--;
     3804            }
     3805          break;
     3806
     3807        default:
     3808          break;
     3809        }
     3810    }
     3811  return TRUE;
     3812}
     3813
     3814/* Set htab->tls_sec and htab->tls_get_addr.  */
     3815
     3816bfd_boolean
     3817ppc_elf_tls_setup (obfd, info)
     3818     bfd *obfd;
     3819     struct bfd_link_info *info;
     3820{
     3821  asection *tls;
     3822  struct ppc_elf_link_hash_table *htab;
     3823
     3824  htab = ppc_elf_hash_table (info);
     3825  htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
     3826                                             FALSE, FALSE, TRUE);
     3827
     3828  for (tls = obfd->sections; tls != NULL; tls = tls->next)
     3829    if ((tls->flags & (SEC_THREAD_LOCAL | SEC_LOAD))
     3830        == (SEC_THREAD_LOCAL | SEC_LOAD))
     3831      break;
     3832  htab->tls_sec = tls;
     3833
     3834  return tls != NULL;
     3835}
     3836
     3837/* Run through all the TLS relocs looking for optimization
     3838   opportunities.  */
     3839
     3840bfd_boolean
     3841ppc_elf_tls_optimize (obfd, info)
     3842     bfd *obfd ATTRIBUTE_UNUSED;
     3843     struct bfd_link_info *info;
     3844{
     3845  bfd *ibfd;
     3846  asection *sec;
     3847  struct ppc_elf_link_hash_table *htab;
     3848
     3849  if (info->relocateable || info->shared)
     3850    return TRUE;
     3851
     3852  htab = ppc_elf_hash_table (info);
     3853  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
     3854    {
     3855      Elf_Internal_Sym *locsyms = NULL;
     3856      Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
     3857
     3858      for (sec = ibfd->sections; sec != NULL; sec = sec->next)
     3859        if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
    25413860          {
    2542             h = sym_hashes[r_symndx - symtab_hdr->sh_info];
    2543             if (h->got.refcount > 0)
    2544               h->got.refcount--;
     3861            Elf_Internal_Rela *relstart, *rel, *relend;
     3862            int expecting_tls_get_addr;
     3863
     3864            /* Read the relocations.  */
     3865            relstart = _bfd_elf32_link_read_relocs (ibfd, sec, (PTR) NULL,
     3866                                                    (Elf_Internal_Rela *) NULL,
     3867                                                    info->keep_memory);
     3868            if (relstart == NULL)
     3869              return FALSE;
     3870
     3871            expecting_tls_get_addr = 0;
     3872            relend = relstart + sec->reloc_count;
     3873            for (rel = relstart; rel < relend; rel++)
     3874              {
     3875                enum elf_ppc_reloc_type r_type;
     3876                unsigned long r_symndx;
     3877                struct elf_link_hash_entry *h = NULL;
     3878                char *tls_mask;
     3879                char tls_set, tls_clear;
     3880                bfd_boolean is_local;
     3881
     3882                r_symndx = ELF32_R_SYM (rel->r_info);
     3883                if (r_symndx >= symtab_hdr->sh_info)
     3884                  {
     3885                    struct elf_link_hash_entry **sym_hashes;
     3886
     3887                    sym_hashes = elf_sym_hashes (ibfd);
     3888                    h = sym_hashes[r_symndx - symtab_hdr->sh_info];
     3889                    while (h->root.type == bfd_link_hash_indirect
     3890                           || h->root.type == bfd_link_hash_warning)
     3891                      h = (struct elf_link_hash_entry *) h->root.u.i.link;
     3892                  }
     3893
     3894                is_local = FALSE;
     3895                if (h == NULL
     3896                    || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))
     3897                  is_local = TRUE;
     3898
     3899                r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info);
     3900                switch (r_type)
     3901                  {
     3902                  case R_PPC_GOT_TLSLD16:
     3903                  case R_PPC_GOT_TLSLD16_LO:
     3904                  case R_PPC_GOT_TLSLD16_HI:
     3905                  case R_PPC_GOT_TLSLD16_HA:
     3906                    /* These relocs should never be against a symbol
     3907                       defined in a shared lib.  Leave them alone if
     3908                       that turns out to be the case.  */
     3909                    expecting_tls_get_addr = 0;
     3910                    htab->tlsld_got.refcount -= 1;
     3911                    if (!is_local)
     3912                      continue;
     3913
     3914                    /* LD -> LE */
     3915                    tls_set = 0;
     3916                    tls_clear = TLS_LD;
     3917                    expecting_tls_get_addr = 1;
     3918                    break;
     3919
     3920                  case R_PPC_GOT_TLSGD16:
     3921                  case R_PPC_GOT_TLSGD16_LO:
     3922                  case R_PPC_GOT_TLSGD16_HI:
     3923                  case R_PPC_GOT_TLSGD16_HA:
     3924                    if (is_local)
     3925                      /* GD -> LE */
     3926                      tls_set = 0;
     3927                    else
     3928                      /* GD -> IE */
     3929                      tls_set = TLS_TLS | TLS_TPRELGD;
     3930                    tls_clear = TLS_GD;
     3931                    expecting_tls_get_addr = 1;
     3932                    break;
     3933
     3934                  case R_PPC_GOT_TPREL16:
     3935                  case R_PPC_GOT_TPREL16_LO:
     3936                  case R_PPC_GOT_TPREL16_HI:
     3937                  case R_PPC_GOT_TPREL16_HA:
     3938                    expecting_tls_get_addr = 0;
     3939                    if (is_local)
     3940                      {
     3941                        /* IE -> LE */
     3942                        tls_set = 0;
     3943                        tls_clear = TLS_TPREL;
     3944                        break;
     3945                      }
     3946                    else
     3947                      continue;
     3948
     3949                  case R_PPC_REL14:
     3950                  case R_PPC_REL14_BRTAKEN:
     3951                  case R_PPC_REL14_BRNTAKEN:
     3952                  case R_PPC_REL24:
     3953                    if (expecting_tls_get_addr
     3954                        && h != NULL
     3955                        && h == htab->tls_get_addr)
     3956                      {
     3957                        if (h->plt.refcount > 0)
     3958                          h->plt.refcount -= 1;
     3959                      }
     3960                    expecting_tls_get_addr = 0;
     3961                    continue;
     3962
     3963                  default:
     3964                    expecting_tls_get_addr = 0;
     3965                    continue;
     3966                  }
     3967
     3968                if (h != NULL)
     3969                  {
     3970                    if (tls_set == 0)
     3971                      {
     3972                        /* We managed to get rid of a got entry.  */
     3973                        if (h->got.refcount > 0)
     3974                          h->got.refcount -= 1;
     3975                      }
     3976                    tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
     3977                  }
     3978                else
     3979                  {
     3980                    Elf_Internal_Sym *sym;
     3981                    bfd_signed_vma *lgot_refs;
     3982                    char *lgot_masks;
     3983
     3984                    if (locsyms == NULL)
     3985                      {
     3986                        locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
     3987                        if (locsyms == NULL)
     3988                          locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
     3989                                                          symtab_hdr->sh_info,
     3990                                                          0, NULL, NULL, NULL);
     3991                        if (locsyms == NULL)
     3992                          {
     3993                            if (elf_section_data (sec)->relocs != relstart)
     3994                              free (relstart);
     3995                            return FALSE;
     3996                          }
     3997                      }
     3998                    sym = locsyms + r_symndx;
     3999                    lgot_refs = elf_local_got_refcounts (ibfd);
     4000                    if (lgot_refs == NULL)
     4001                      abort ();
     4002                    if (tls_set == 0)
     4003                      {
     4004                        /* We managed to get rid of a got entry.  */
     4005                        if (lgot_refs[r_symndx] > 0)
     4006                          lgot_refs[r_symndx] -= 1;
     4007                      }
     4008                    lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info);
     4009                    tls_mask = &lgot_masks[r_symndx];
     4010                  }
     4011
     4012                *tls_mask |= tls_set;
     4013                *tls_mask &= ~tls_clear;
     4014              }
     4015
     4016            if (elf_section_data (sec)->relocs != relstart)
     4017              free (relstart);
    25454018          }
    2546         else if (local_got_refcounts != NULL)
    2547           {
    2548             if (local_got_refcounts[r_symndx] > 0)
    2549               local_got_refcounts[r_symndx]--;
    2550           }
    2551         break;
    2552 
    2553       case R_PPC_PLT32:
    2554       case R_PPC_PLTREL24:
    2555       case R_PPC_PLT16_LO:
    2556       case R_PPC_PLT16_HI:
    2557       case R_PPC_PLT16_HA:
    2558         r_symndx = ELF32_R_SYM (rel->r_info);
    2559         if (r_symndx >= symtab_hdr->sh_info)
    2560           {
    2561             h = sym_hashes[r_symndx - symtab_hdr->sh_info];
    2562             if (h->plt.refcount > 0)
    2563               h->plt.refcount--;
    2564           }
    2565         break;
    2566 
    2567       default:
    2568         break;
    2569       }
    2570 
    2571   return true;
     4019
     4020      if (locsyms != NULL
     4021          && (symtab_hdr->contents != (unsigned char *) locsyms))
     4022        {
     4023          if (!info->keep_memory)
     4024            free (locsyms);
     4025          else
     4026            symtab_hdr->contents = (unsigned char *) locsyms;
     4027        }
     4028    }
     4029  return TRUE;
    25724030}
    25734031
     
    25764034   file.  We use it to put .comm items in .sbss, and not .bss.  */
    25774035
    2578 static boolean
     4036static bfd_boolean
    25794037ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
    25804038     bfd *abfd;
     
    25884046  if (sym->st_shndx == SHN_COMMON
    25894047      && !info->relocateable
    2590       && sym->st_size <= (bfd_vma) bfd_get_gp_size (abfd))
     4048      && sym->st_size <= elf_gp_size (abfd)
     4049      && info->hash->creator->flavour == bfd_target_elf_flavour)
    25914050    {
    25924051      /* Common symbols less than or equal to -G nn bytes are automatically
     
    25974056      if (!sdata->bss_section)
    25984057        {
     4058          bfd_size_type amt;
     4059
    25994060          /* We don't go through bfd_make_section, because we don't
    2600              want to attach this common section to DYNOBJ.  The linker
    2601              will move the symbols to the appropriate output section
    2602              when it defines common symbols.  */
    2603           sdata->bss_section = ((asection *)
    2604                                 bfd_zalloc (abfd, sizeof (asection)));
     4061             want to attach this common section to DYNOBJ.  The linker
     4062             will move the symbols to the appropriate output section
     4063             when it defines common symbols.  */
     4064          amt = sizeof (asection);
     4065          sdata->bss_section = (asection *) bfd_zalloc (abfd, amt);
    26054066          if (sdata->bss_section == NULL)
    2606             return false;
     4067            return FALSE;
    26074068          sdata->bss_section->name = sdata->bss_name;
    26084069          sdata->bss_section->flags = SEC_IS_COMMON;
    26094070          sdata->bss_section->output_section = sdata->bss_section;
    2610           sdata->bss_section->symbol =
    2611             (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
     4071          amt = sizeof (asymbol);
     4072          sdata->bss_section->symbol = (asymbol *) bfd_zalloc (abfd, amt);
     4073          amt = sizeof (asymbol *);
    26124074          sdata->bss_section->symbol_ptr_ptr =
    2613             (asymbol **) bfd_zalloc (abfd, sizeof (asymbol *));
     4075            (asymbol **) bfd_zalloc (abfd, amt);
    26144076          if (sdata->bss_section->symbol == NULL
    26154077              || sdata->bss_section->symbol_ptr_ptr == NULL)
    2616             return false;
     4078            return FALSE;
    26174079          sdata->bss_section->symbol->name = sdata->bss_name;
    26184080          sdata->bss_section->symbol->flags = BSF_SECTION_SYM;
     
    26254087    }
    26264088
    2627   return true;
     4089  return TRUE;
    26284090}
    26294091
     
    26324094   dynamic sections here.  */
    26334095
    2634 static boolean
     4096static bfd_boolean
    26354097ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
    26364098     bfd *output_bfd;
     
    26394101     Elf_Internal_Sym *sym;
    26404102{
    2641   bfd *dynobj;
     4103  struct ppc_elf_link_hash_table *htab;
    26424104
    26434105#ifdef DEBUG
     
    26464108#endif
    26474109
    2648   dynobj = elf_hash_table (info)->dynobj;
    2649   BFD_ASSERT (dynobj != NULL);
     4110  htab = ppc_elf_hash_table (info);
     4111  BFD_ASSERT (htab->elf.dynobj != NULL);
    26504112
    26514113  if (h->plt.offset != (bfd_vma) -1)
    26524114    {
    2653       asection *splt;
    2654       asection *srela;
    26554115      Elf_Internal_Rela rela;
     4116      bfd_byte *loc;
    26564117      bfd_vma reloc_index;
    26574118
     
    26614122
    26624123      /* This symbol has an entry in the procedure linkage table.  Set
    2663         it up.  */
     4124        it up.  */
    26644125
    26654126      BFD_ASSERT (h->dynindx != -1);
    2666 
    2667       splt = bfd_get_section_by_name (dynobj, ".plt");
    2668       srela = bfd_get_section_by_name (dynobj, ".rela.plt");
    2669       BFD_ASSERT (splt != NULL && srela != NULL);
     4127      BFD_ASSERT (htab->plt != NULL && htab->relplt != NULL);
    26704128
    26714129      /* We don't need to fill in the .plt.  The ppc dynamic linker
     
    26734131
    26744132      /* Fill in the entry in the .rela.plt section.  */
    2675       rela.r_offset = (splt->output_section->vma
    2676                        + splt->output_offset
     4133      rela.r_offset = (htab->plt->output_section->vma
     4134                       + htab->plt->output_offset
    26774135                       + h->plt.offset);
    26784136      rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
     
    26824140      if (reloc_index > PLT_NUM_SINGLE_ENTRIES)
    26834141        reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
    2684       bfd_elf32_swap_reloca_out (output_bfd, &rela,
    2685                                  ((Elf32_External_Rela *) srela->contents
    2686                                   + reloc_index));
     4142      loc = (htab->relplt->contents
     4143             + reloc_index * sizeof (Elf32_External_Rela));
     4144      bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
    26874145
    26884146      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
     
    27014159    }
    27024160
    2703   if (h->got.offset != (bfd_vma) -1)
    2704     {
    2705       asection *sgot;
    2706       asection *srela;
    2707       Elf_Internal_Rela rela;
    2708 
    2709       /* This symbol has an entry in the global offset table.  Set it
    2710          up.  */
    2711 
    2712       sgot = bfd_get_section_by_name (dynobj, ".got");
    2713       srela = bfd_get_section_by_name (dynobj, ".rela.got");
    2714       BFD_ASSERT (sgot != NULL && srela != NULL);
    2715 
    2716       rela.r_offset = (sgot->output_section->vma
    2717                        + sgot->output_offset
    2718                        + (h->got.offset &~ 1));
    2719 
    2720       /* If this is a -Bsymbolic link, and the symbol is defined
    2721          locally, we just want to emit a RELATIVE reloc.  The entry in
    2722          the global offset table will already have been initialized in
    2723          the relocate_section function.  */
    2724       if (info->shared
    2725           && SYMBOL_REFERENCES_LOCAL (info, h))
    2726         {
    2727           rela.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
    2728           rela.r_addend = (h->root.u.def.value
    2729                            + h->root.u.def.section->output_section->vma
    2730                            + h->root.u.def.section->output_offset);
    2731         }
    2732       else
    2733         {
    2734           BFD_ASSERT ((h->got.offset & 1) == 0);
    2735           bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
    2736           rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_GLOB_DAT);
    2737           rela.r_addend = 0;
    2738         }
    2739 
    2740       bfd_elf32_swap_reloca_out (output_bfd, &rela,
    2741                                  ((Elf32_External_Rela *) srela->contents
    2742                                   + srela->reloc_count));
    2743       ++srela->reloc_count;
    2744     }
    2745 
    27464161  if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
    27474162    {
    27484163      asection *s;
    27494164      Elf_Internal_Rela rela;
     4165      bfd_byte *loc;
    27504166
    27514167      /* This symbols needs a copy reloc.  Set it up.  */
     
    27574173      BFD_ASSERT (h->dynindx != -1);
    27584174
    2759       if (h->size <= elf_gp_size (dynobj))
    2760         s = bfd_get_section_by_name (h->root.u.def.section->owner,
    2761                                      ".rela.sbss");
     4175      if (h->size <= elf_gp_size (htab->elf.dynobj))
     4176        s = htab->relsbss;
    27624177      else
    2763         s = bfd_get_section_by_name (h->root.u.def.section->owner,
    2764                                      ".rela.bss");
     4178        s = htab->relbss;
    27654179      BFD_ASSERT (s != NULL);
    27664180
     
    27704184      rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
    27714185      rela.r_addend = 0;
    2772       bfd_elf32_swap_reloca_out (output_bfd, &rela,
    2773                                  ((Elf32_External_Rela *) s->contents
    2774                                   + s->reloc_count));
    2775       ++s->reloc_count;
     4186      loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
     4187      bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
    27764188    }
    27774189
     
    27864198    sym->st_shndx = SHN_ABS;
    27874199
    2788   return true;
     4200  return TRUE;
    27894201}
    27904202
     
    27924204/* Finish up the dynamic sections.  */
    27934205
    2794 static boolean
     4206static bfd_boolean
    27954207ppc_elf_finish_dynamic_sections (output_bfd, info)
    27964208     bfd *output_bfd;
     
    27984210{
    27994211  asection *sdyn;
    2800   bfd *dynobj = elf_hash_table (info)->dynobj;
    2801   asection *sgot = bfd_get_section_by_name (dynobj, ".got");
     4212  struct ppc_elf_link_hash_table *htab;
    28024213
    28034214#ifdef DEBUG
     
    28054216#endif
    28064217
    2807   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
    2808 
    2809   if (elf_hash_table (info)->dynamic_sections_created)
     4218  htab = ppc_elf_hash_table (info);
     4219  sdyn = bfd_get_section_by_name (htab->elf.dynobj, ".dynamic");
     4220
     4221  if (htab->elf.dynamic_sections_created)
    28104222    {
    2811       asection *splt;
    28124223      Elf32_External_Dyn *dyncon, *dynconend;
    28134224
    2814       splt = bfd_get_section_by_name (dynobj, ".plt");
    2815       BFD_ASSERT (splt != NULL && sdyn != NULL);
     4225      BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
    28164226
    28174227      dyncon = (Elf32_External_Dyn *) sdyn->contents;
     
    28204230        {
    28214231          Elf_Internal_Dyn dyn;
    2822           const char *name;
    2823           boolean size;
    2824 
    2825           bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
     4232          asection *s;
     4233
     4234          bfd_elf32_swap_dyn_in (htab->elf.dynobj, dyncon, &dyn);
    28264235
    28274236          switch (dyn.d_tag)
    28284237            {
    2829             case DT_PLTGOT:   name = ".plt";      size = false; break;
    2830             case DT_PLTRELSZ: name = ".rela.plt"; size = true;  break;
    2831             case DT_JMPREL:   name = ".rela.plt"; size = false; break;
    2832             default:          name = NULL;        size = false; break;
     4238            case DT_PLTGOT:
     4239              s = htab->plt;
     4240              dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
     4241              break;
     4242
     4243            case DT_PLTRELSZ:
     4244              dyn.d_un.d_val = htab->relplt->_raw_size;
     4245              break;
     4246
     4247            case DT_JMPREL:
     4248              s = htab->relplt;
     4249              dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
     4250              break;
     4251
     4252            default:
     4253              continue;
    28334254            }
    28344255
    2835           if (name != NULL)
    2836             {
    2837               asection *s;
    2838 
    2839               s = bfd_get_section_by_name (output_bfd, name);
    2840               if (s == NULL)
    2841                 dyn.d_un.d_val = 0;
    2842               else
    2843                 {
    2844                   if (! size)
    2845                     dyn.d_un.d_ptr = s->vma;
    2846                   else
    2847                     {
    2848                       if (s->_cooked_size != 0)
    2849                         dyn.d_un.d_val = s->_cooked_size;
    2850                       else
    2851                         dyn.d_un.d_val = s->_raw_size;
    2852                     }
    2853                 }
    2854               bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
    2855             }
     4256          bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
    28564257        }
    28574258    }
     
    28594260  /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
    28604261     easily find the address of the _GLOBAL_OFFSET_TABLE_.  */
    2861   if (sgot)
     4262  if (htab->got)
    28624263    {
    2863       unsigned char *contents = sgot->contents;
    2864       bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents);
     4264      unsigned char *contents = htab->got->contents;
     4265      bfd_put_32 (output_bfd, (bfd_vma) 0x4e800021 /* blrl */, contents);
    28654266
    28664267      if (sdyn == NULL)
    2867         bfd_put_32 (output_bfd, (bfd_vma) 0, contents+4);
     4268        bfd_put_32 (output_bfd, (bfd_vma) 0, contents + 4);
    28684269      else
    28694270        bfd_put_32 (output_bfd,
    28704271                    sdyn->output_section->vma + sdyn->output_offset,
    2871                     contents+4);
    2872 
    2873       elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
     4272                    contents + 4);
     4273
     4274      elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
    28744275    }
    28754276
    2876   return true;
     4277  return TRUE;
    28774278}
    28784279
     
    29074308   accordingly.  */
    29084309
    2909 static boolean
     4310static bfd_boolean
    29104311ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
    29114312                          contents, relocs, local_syms, local_sections)
     
    29194320     asection **local_sections;
    29204321{
    2921   Elf_Internal_Shdr *symtab_hdr           = &elf_tdata (input_bfd)->symtab_hdr;
    2922   struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
    2923   bfd *dynobj                             = elf_hash_table (info)->dynobj;
    2924   elf_linker_section_t *sdata             = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA)  : NULL;
    2925   elf_linker_section_t *sdata2            = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA2) : NULL;
    2926   Elf_Internal_Rela *rel                  = relocs;
    2927   Elf_Internal_Rela *relend               = relocs + input_section->reloc_count;
    2928   asection *sreloc                        = NULL;
    2929   asection *splt;
    2930   asection *sgot;
     4322  Elf_Internal_Shdr *symtab_hdr;
     4323  struct elf_link_hash_entry **sym_hashes;
     4324  struct ppc_elf_link_hash_table *htab;
     4325  Elf_Internal_Rela *rel;
     4326  Elf_Internal_Rela *relend;
     4327  Elf_Internal_Rela outrel;
     4328  bfd_byte *loc;
     4329  asection *sreloc = NULL;
    29314330  bfd_vma *local_got_offsets;
    2932   boolean ret                             = true;
    2933   long insn;
     4331  bfd_boolean ret = TRUE;
    29344332
    29354333#ifdef DEBUG
    29364334  fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
    2937            bfd_get_filename (input_bfd),
     4335           bfd_archive_filename (input_bfd),
    29384336           bfd_section_name(input_bfd, input_section),
    29394337           (long) input_section->reloc_count,
     
    29414339#endif
    29424340
     4341  if (info->relocateable)
     4342    return TRUE;
     4343
    29434344  if (!ppc_elf_howto_table[R_PPC_ADDR32])
    29444345    /* Initialize howto table if needed.  */
    29454346    ppc_elf_howto_init ();
    29464347
     4348  htab = ppc_elf_hash_table (info);
    29474349  local_got_offsets = elf_local_got_offsets (input_bfd);
    2948 
    2949   splt = sgot = NULL;
    2950   if (dynobj != NULL)
    2951     {
    2952       splt = bfd_get_section_by_name (dynobj, ".plt");
    2953       sgot = bfd_get_section_by_name (dynobj, ".got");
    2954     }
    2955 
     4350  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
     4351  sym_hashes = elf_sym_hashes (input_bfd);
     4352  rel = relocs;
     4353  relend = relocs + input_section->reloc_count;
    29564354  for (; rel < relend; rel++)
    29574355    {
    2958       enum elf_ppc_reloc_type r_type    = (enum elf_ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
    2959       bfd_vma offset                    = rel->r_offset;
    2960       bfd_vma addend                    = rel->r_addend;
    2961       bfd_reloc_status_type r           = bfd_reloc_other;
    2962       Elf_Internal_Sym *sym             = (Elf_Internal_Sym *) 0;
    2963       asection *sec                     = (asection *) 0;
    2964       struct elf_link_hash_entry *h     = (struct elf_link_hash_entry *) 0;
    2965       const char *sym_name              = (const char *) 0;
     4356      enum elf_ppc_reloc_type r_type;
     4357      bfd_vma addend;
     4358      bfd_reloc_status_type r;
     4359      Elf_Internal_Sym *sym;
     4360      asection *sec;
     4361      struct elf_link_hash_entry *h;
     4362      const char *sym_name;
    29664363      reloc_howto_type *howto;
    29674364      unsigned long r_symndx;
    29684365      bfd_vma relocation;
    2969       int will_become_local;
    2970 
    2971       /* Unknown relocation handling */
    2972       if ((unsigned) r_type >= (unsigned) R_PPC_max
    2973           || !ppc_elf_howto_table[(int) r_type])
    2974         {
    2975           (*_bfd_error_handler) (_("%s: unknown relocation type %d"),
    2976                                  bfd_get_filename (input_bfd),
    2977                                  (int) r_type);
    2978 
    2979           bfd_set_error (bfd_error_bad_value);
    2980           ret = false;
    2981           continue;
    2982         }
    2983 
    2984       howto = ppc_elf_howto_table[(int) r_type];
     4366      bfd_vma branch_bit, insn, from;
     4367      bfd_boolean unresolved_reloc;
     4368      bfd_boolean warned;
     4369      unsigned int tls_type, tls_mask, tls_gd;
     4370
     4371      r_type = (enum elf_ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
     4372      sym = (Elf_Internal_Sym *) 0;
     4373      sec = (asection *) 0;
     4374      h = (struct elf_link_hash_entry *) 0;
     4375      unresolved_reloc = FALSE;
     4376      warned = FALSE;
    29854377      r_symndx = ELF32_R_SYM (rel->r_info);
    2986 
    2987       if (info->relocateable)
    2988         {
    2989           /* This is a relocateable link.  We don't have to change
    2990              anything, unless the reloc is against a section symbol,
    2991              in which case we have to adjust according to where the
    2992              section symbol winds up in the output section.  */
    2993           if (r_symndx < symtab_hdr->sh_info)
    2994             {
    2995               sym = local_syms + r_symndx;
    2996               if ((unsigned) ELF_ST_TYPE (sym->st_info) == STT_SECTION)
    2997                 {
    2998                   sec = local_sections[r_symndx];
    2999                   addend = rel->r_addend += sec->output_offset + sym->st_value;
    3000                 }
    3001             }
    3002 
    3003 #ifdef DEBUG
    3004           fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
    3005                    howto->name,
    3006                    (int) r_type,
    3007                    r_symndx,
    3008                    (long) offset,
    3009                    (long) addend);
    3010 #endif
    3011           continue;
    3012         }
    3013 
    3014       /* This is a final link.  */
    30154378      if (r_symndx < symtab_hdr->sh_info)
    30164379        {
    30174380          sym = local_syms + r_symndx;
    30184381          sec = local_sections[r_symndx];
    3019           sym_name = "<local symbol>";
    3020 
    3021           relocation = (sec->output_section->vma
    3022                         + sec->output_offset
    3023                         + sym->st_value);
    3024           /* Relocs to local symbols are always resolved.  */
    3025           will_become_local = 1;
     4382          sym_name = bfd_elf_local_sym_name (input_bfd, sym);
     4383
     4384          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
    30264385        }
    30274386      else
     
    30334392          sym_name = h->root.root.string;
    30344393
    3035           /* Can this relocation be resolved immediately?  */
    3036           will_become_local = SYMBOL_REFERENCES_LOCAL (info, h);
    3037 
     4394          relocation = 0;
    30384395          if (h->root.type == bfd_link_hash_defined
    30394396              || h->root.type == bfd_link_hash_defweak)
    30404397            {
    30414398              sec = h->root.u.def.section;
    3042               if (((r_type == R_PPC_PLT32
    3043                     || r_type == R_PPC_PLTREL24)
    3044                    && splt != NULL
    3045                    && h->plt.offset != (bfd_vma) -1)
    3046                   || (r_type == R_PPC_LOCAL24PC
    3047                       && sec->output_section == NULL)
    3048                   || ((r_type == R_PPC_GOT16
    3049                        || r_type == R_PPC_GOT16_LO
    3050                        || r_type == R_PPC_GOT16_HI
    3051                        || r_type == R_PPC_GOT16_HA)
    3052                       && elf_hash_table (info)->dynamic_sections_created
    3053                       && (! info->shared || ! will_become_local))
    3054                   || (info->shared
    3055                       && ! will_become_local
    3056                       && ((input_section->flags & SEC_ALLOC) != 0
    3057                           /* Testing SEC_DEBUGGING here may be wrong.
    3058                              It's here to avoid a crash when
    3059                              generating a shared library with DWARF
    3060                              debugging information.  */
    3061                           || ((input_section->flags & SEC_DEBUGGING) != 0
    3062                               && (h->elf_link_hash_flags
    3063                                   & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
    3064                       && (r_type == R_PPC_ADDR32
    3065                           || r_type == R_PPC_ADDR24
    3066                           || r_type == R_PPC_ADDR16
    3067                           || r_type == R_PPC_ADDR16_LO
    3068                           || r_type == R_PPC_ADDR16_HI
    3069                           || r_type == R_PPC_ADDR16_HA
    3070                           || r_type == R_PPC_ADDR14
    3071                           || r_type == R_PPC_ADDR14_BRTAKEN
    3072                           || r_type == R_PPC_ADDR14_BRNTAKEN
    3073                           || r_type == R_PPC_COPY
    3074                           || r_type == R_PPC_GLOB_DAT
    3075                           || r_type == R_PPC_JMP_SLOT
    3076                           || r_type == R_PPC_UADDR32
    3077                           || r_type == R_PPC_UADDR16
    3078                           || r_type == R_PPC_SDAREL16
    3079                           || r_type == R_PPC_EMB_NADDR32
    3080                           || r_type == R_PPC_EMB_NADDR16
    3081                           || r_type == R_PPC_EMB_NADDR16_LO
    3082                           || r_type == R_PPC_EMB_NADDR16_HI
    3083                           || r_type == R_PPC_EMB_NADDR16_HA
    3084                           || r_type == R_PPC_EMB_SDAI16
    3085                           || r_type == R_PPC_EMB_SDA2I16
    3086                           || r_type == R_PPC_EMB_SDA2REL
    3087                           || r_type == R_PPC_EMB_SDA21
    3088                           || r_type == R_PPC_EMB_MRKREF
    3089                           || r_type == R_PPC_EMB_BIT_FLD
    3090                           || r_type == R_PPC_EMB_RELSDA
    3091                           || ((r_type == R_PPC_REL24
    3092                                || r_type == R_PPC_REL32
    3093                                || r_type == R_PPC_REL14
    3094                                || r_type == R_PPC_REL14_BRTAKEN
    3095                                || r_type == R_PPC_REL14_BRNTAKEN
    3096                                || r_type == R_PPC_RELATIVE)
    3097                               && strcmp (h->root.root.string,
    3098                                          "_GLOBAL_OFFSET_TABLE_") != 0))))
    3099                 {
    3100                   /* In these cases, we don't need the relocation
    3101                      value.  We check specially because in some
    3102                      obscure cases sec->output_section will be NULL.  */
    3103                   relocation = 0;
    3104                 }
    3105               else if (sec->output_section == NULL)
    3106                 {
    3107                   (*_bfd_error_handler)
    3108                     (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
    3109                      bfd_get_filename (input_bfd), h->root.root.string,
    3110                      bfd_get_section_name (input_bfd, input_section));
    3111                   relocation = 0;
    3112                 }
     4399              /* Set a flag that will be cleared later if we find a
     4400                 relocation value for this symbol.  output_section
     4401                 is typically NULL for symbols satisfied by a shared
     4402                 library.  */
     4403              if (sec->output_section == NULL)
     4404                unresolved_reloc = TRUE;
    31134405              else
    31144406                relocation = (h->root.u.def.value
     
    31174409            }
    31184410          else if (h->root.type == bfd_link_hash_undefweak)
    3119             relocation = 0;
    3120           else if (info->shared && !info->symbolic && !info->no_undefined
     4411            ;
     4412          else if (info->shared
     4413                   && !info->no_undefined
    31214414                   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
    3122             relocation = 0;
     4415            ;
    31234416          else
    31244417            {
    3125               if (! (*info->callbacks->undefined_symbol) (info,
    3126                                                          h->root.root.string,
    3127                                                          input_bfd,
    3128                                                          input_section,
    3129                                                          rel->r_offset,
    3130                                                          (!info->shared
    3131                                                           || info->no_undefined
    3132                                                           || ELF_ST_VISIBILITY (h->other))))
    3133                 return false;
    3134               relocation = 0;
     4418              if (! ((*info->callbacks->undefined_symbol)
     4419                     (info, h->root.root.string, input_bfd, input_section,
     4420                      rel->r_offset, (!info->shared
     4421                                      || info->no_undefined
     4422                                      || ELF_ST_VISIBILITY (h->other)))))
     4423                return FALSE;
     4424              warned = TRUE;
    31354425            }
    31364426        }
    31374427
    3138       switch ((int) r_type)
     4428      /* TLS optimizations.  Replace instruction sequences and relocs
     4429         based on information we collected in tls_optimize.  We edit
     4430         RELOCS so that --emit-relocs will output something sensible
     4431         for the final instruction stream.  */
     4432      tls_mask = 0;
     4433      tls_gd = 0;
     4434      if (IS_PPC_TLS_RELOC (r_type))
     4435        {
     4436          if (h != NULL)
     4437            tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
     4438          else if (local_got_offsets != NULL)
     4439            {
     4440              char *lgot_masks;
     4441              lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
     4442              tls_mask = lgot_masks[r_symndx];
     4443            }
     4444        }
     4445
     4446      /* Ensure reloc mapping code below stays sane.  */
     4447      if ((R_PPC_GOT_TLSLD16 & 3)    != (R_PPC_GOT_TLSGD16 & 3)
     4448          || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
     4449          || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
     4450          || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
     4451          || (R_PPC_GOT_TLSLD16 & 3)    != (R_PPC_GOT_TPREL16 & 3)
     4452          || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
     4453          || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
     4454          || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
     4455        abort ();
     4456      switch (r_type)
    31394457        {
    31404458        default:
    3141           (*_bfd_error_handler) (_("%s: unknown relocation type %d for symbol %s"),
    3142                                  bfd_get_filename (input_bfd),
    3143                                  (int) r_type, sym_name);
     4459          break;
     4460
     4461        case R_PPC_GOT_TPREL16:
     4462        case R_PPC_GOT_TPREL16_LO:
     4463          if (tls_mask != 0
     4464              && (tls_mask & TLS_TPREL) == 0)
     4465            {
     4466              bfd_vma insn;
     4467              insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2);
     4468              insn &= 31 << 21;
     4469              insn |= 0x3c020000;       /* addis 0,2,0 */
     4470              bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2);
     4471              r_type = R_PPC_TPREL16_HA;
     4472              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
     4473            }
     4474          break;
     4475
     4476        case R_PPC_TLS:
     4477          if (tls_mask != 0
     4478              && (tls_mask & TLS_TPREL) == 0)
     4479            {
     4480              bfd_vma insn, rtra;
     4481              insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
     4482              if ((insn & ((31 << 26) | (31 << 11)))
     4483                  == ((31 << 26) | (2 << 11)))
     4484                rtra = insn & ((1 << 26) - (1 << 16));
     4485              else if ((insn & ((31 << 26) | (31 << 16)))
     4486                       == ((31 << 26) | (2 << 16)))
     4487                rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
     4488              else
     4489                abort ();
     4490              if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
     4491                /* add -> addi.  */
     4492                insn = 14 << 26;
     4493              else if ((insn & (31 << 1)) == 23 << 1
     4494                       && ((insn & (31 << 6)) < 14 << 6
     4495                           || ((insn & (31 << 6)) >= 16 << 6
     4496                               && (insn & (31 << 6)) < 24 << 6)))
     4497                /* load and store indexed -> dform.  */
     4498                insn = (32 | ((insn >> 6) & 31)) << 26;
     4499              else if ((insn & (31 << 1)) == 21 << 1
     4500                       && (insn & (0x1a << 6)) == 0)
     4501                /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu.  */
     4502                insn = (((58 | ((insn >> 6) & 4)) << 26)
     4503                        | ((insn >> 6) & 1));
     4504              else if ((insn & (31 << 1)) == 21 << 1
     4505                       && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
     4506                /* lwax -> lwa.  */
     4507                insn = (58 << 26) | 2;
     4508              else
     4509                abort ();
     4510              insn |= rtra;
     4511              bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
     4512              r_type = R_PPC_TPREL16_LO;
     4513              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
     4514              /* Was PPC_TLS which sits on insn boundary, now
     4515                 PPC_TPREL16_LO which is at insn+2.  */
     4516              rel->r_offset += 2;
     4517            }
     4518          break;
     4519
     4520        case R_PPC_GOT_TLSGD16_HI:
     4521        case R_PPC_GOT_TLSGD16_HA:
     4522          tls_gd = TLS_TPRELGD;
     4523          if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
     4524            goto tls_gdld_hi;
     4525          break;
     4526
     4527        case R_PPC_GOT_TLSLD16_HI:
     4528        case R_PPC_GOT_TLSLD16_HA:
     4529          if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
     4530            {
     4531            tls_gdld_hi:
     4532              if ((tls_mask & tls_gd) != 0)
     4533                r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
     4534                          + R_PPC_GOT_TPREL16);
     4535              else
     4536                {
     4537                  bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
     4538                  rel->r_offset -= 2;
     4539                  r_type = R_PPC_NONE;
     4540                }
     4541              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
     4542            }
     4543          break;
     4544
     4545        case R_PPC_GOT_TLSGD16:
     4546        case R_PPC_GOT_TLSGD16_LO:
     4547          tls_gd = TLS_TPRELGD;
     4548          if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
     4549            goto tls_get_addr_check;
     4550          break;
     4551
     4552        case R_PPC_GOT_TLSLD16:
     4553        case R_PPC_GOT_TLSLD16_LO:
     4554          if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
     4555            {
     4556            tls_get_addr_check:
     4557              if (rel + 1 < relend)
     4558                {
     4559                  enum elf_ppc_reloc_type r_type2;
     4560                  unsigned long r_symndx2;
     4561                  struct elf_link_hash_entry *h2;
     4562                  bfd_vma insn1, insn2;
     4563                  bfd_vma offset;
     4564
     4565                  /* The next instruction should be a call to
     4566                     __tls_get_addr.  Peek at the reloc to be sure.  */
     4567                  r_type2
     4568                    = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel[1].r_info);
     4569                  r_symndx2 = ELF32_R_SYM (rel[1].r_info);
     4570                  if (r_symndx2 < symtab_hdr->sh_info
     4571                      || (r_type2 != R_PPC_REL14
     4572                          && r_type2 != R_PPC_REL14_BRTAKEN
     4573                          && r_type2 != R_PPC_REL14_BRNTAKEN
     4574                          && r_type2 != R_PPC_REL24
     4575                          && r_type2 != R_PPC_PLTREL24))
     4576                    break;
     4577
     4578                  h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
     4579                  while (h2->root.type == bfd_link_hash_indirect
     4580                         || h2->root.type == bfd_link_hash_warning)
     4581                    h2 = (struct elf_link_hash_entry *) h2->root.u.i.link;
     4582                  if (h2 == NULL || h2 != htab->tls_get_addr)
     4583                    break;
     4584
     4585                  /* OK, it checks out.  Replace the call.  */
     4586                  offset = rel[1].r_offset;
     4587                  insn1 = bfd_get_32 (output_bfd,
     4588                                      contents + rel->r_offset - 2);
     4589                  if ((tls_mask & tls_gd) != 0)
     4590                    {
     4591                      /* IE */
     4592                      insn1 &= (1 << 26) - 1;
     4593                      insn1 |= 32 << 26;        /* lwz */
     4594                      insn2 = 0x7c631214;       /* add 3,3,2 */
     4595                      rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE);
     4596                      r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
     4597                                + R_PPC_GOT_TPREL16);
     4598                      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
     4599                    }
     4600                  else
     4601                    {
     4602                      /* LE */
     4603                      insn1 = 0x3c620000;       /* addis 3,2,0 */
     4604                      insn2 = 0x38630000;       /* addi 3,3,0 */
     4605                      if (tls_gd == 0)
     4606                        {
     4607                          /* Was an LD reloc.  */
     4608                          r_symndx = 0;
     4609                          rel->r_addend = htab->tls_sec->vma + DTP_OFFSET;
     4610                          rel[1].r_addend = htab->tls_sec->vma + DTP_OFFSET;
     4611                        }
     4612                      r_type = R_PPC_TPREL16_HA;
     4613                      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
     4614                      rel[1].r_info = ELF32_R_INFO (r_symndx,
     4615                                                    R_PPC_TPREL16_LO);
     4616                      rel[1].r_offset += 2;
     4617                    }
     4618                  bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
     4619                  bfd_put_32 (output_bfd, insn2, contents + offset);
     4620                  if (tls_gd == 0)
     4621                    {
     4622                      /* We changed the symbol on an LD reloc.  Start over
     4623                         in order to get h, sym, sec etc. right.  */
     4624                      rel--;
     4625                      continue;
     4626                    }
     4627                }
     4628            }
     4629          break;
     4630        }
     4631
     4632      /* Handle other relocations that tweak non-addend part of insn.  */
     4633      branch_bit = 0;
     4634      switch (r_type)
     4635        {
     4636        default:
     4637          break;
     4638
     4639          /* Branch taken prediction relocations.  */
     4640        case R_PPC_ADDR14_BRTAKEN:
     4641        case R_PPC_REL14_BRTAKEN:
     4642          branch_bit = BRANCH_PREDICT_BIT;
     4643          /* Fall thru */
     4644
     4645          /* Branch not taken predicition relocations.  */
     4646        case R_PPC_ADDR14_BRNTAKEN:
     4647        case R_PPC_REL14_BRNTAKEN:
     4648          insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
     4649          insn &= ~BRANCH_PREDICT_BIT;
     4650          insn |= branch_bit;
     4651
     4652          from = (rel->r_offset
     4653                  + input_section->output_offset
     4654                  + input_section->output_section->vma);
     4655
     4656          /* Invert 'y' bit if not the default.  */
     4657          if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
     4658            insn ^= BRANCH_PREDICT_BIT;
     4659
     4660          bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
     4661          break;
     4662        }
     4663
     4664      addend = rel->r_addend;
     4665      tls_type = 0;
     4666      howto = NULL;
     4667      if ((unsigned) r_type < (unsigned) R_PPC_max)
     4668        howto = ppc_elf_howto_table[(int) r_type];
     4669      switch (r_type)
     4670        {
     4671        default:
     4672          (*_bfd_error_handler)
     4673            (_("%s: unknown relocation type %d for symbol %s"),
     4674             bfd_archive_filename (input_bfd), (int) r_type, sym_name);
    31444675
    31454676          bfd_set_error (bfd_error_bad_value);
    3146           ret = false;
     4677          ret = FALSE;
    31474678          continue;
    31484679
     4680        case R_PPC_NONE:
     4681        case R_PPC_TLS:
     4682        case R_PPC_EMB_MRKREF:
     4683        case R_PPC_GNU_VTINHERIT:
     4684        case R_PPC_GNU_VTENTRY:
     4685          continue;
     4686
     4687          /* GOT16 relocations.  Like an ADDR16 using the symbol's
     4688             address in the GOT as relocation value instead of the
     4689             symbol's value itself.  Also, create a GOT entry for the
     4690             symbol and put the symbol value there.  */
     4691        case R_PPC_GOT_TLSGD16:
     4692        case R_PPC_GOT_TLSGD16_LO:
     4693        case R_PPC_GOT_TLSGD16_HI:
     4694        case R_PPC_GOT_TLSGD16_HA:
     4695          tls_type = TLS_TLS | TLS_GD;
     4696          goto dogot;
     4697
     4698        case R_PPC_GOT_TLSLD16:
     4699        case R_PPC_GOT_TLSLD16_LO:
     4700        case R_PPC_GOT_TLSLD16_HI:
     4701        case R_PPC_GOT_TLSLD16_HA:
     4702          tls_type = TLS_TLS | TLS_LD;
     4703          goto dogot;
     4704
     4705        case R_PPC_GOT_TPREL16:
     4706        case R_PPC_GOT_TPREL16_LO:
     4707        case R_PPC_GOT_TPREL16_HI:
     4708        case R_PPC_GOT_TPREL16_HA:
     4709          tls_type = TLS_TLS | TLS_TPREL;
     4710          goto dogot;
     4711
     4712        case R_PPC_GOT_DTPREL16:
     4713        case R_PPC_GOT_DTPREL16_LO:
     4714        case R_PPC_GOT_DTPREL16_HI:
     4715        case R_PPC_GOT_DTPREL16_HA:
     4716          tls_type = TLS_TLS | TLS_DTPREL;
     4717          goto dogot;
     4718
     4719        case R_PPC_GOT16:
     4720        case R_PPC_GOT16_LO:
     4721        case R_PPC_GOT16_HI:
     4722        case R_PPC_GOT16_HA:
     4723        dogot:
     4724          {
     4725            /* Relocation is to the entry for this symbol in the global
     4726               offset table.  */
     4727            bfd_vma off;
     4728            bfd_vma *offp;
     4729            unsigned long indx;
     4730
     4731            if (htab->got == NULL)
     4732              abort ();
     4733
     4734            indx = 0;
     4735            if (tls_type == (TLS_TLS | TLS_LD)
     4736                && (h == NULL
     4737                    || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)))
     4738              offp = &htab->tlsld_got.offset;
     4739            else if (h != NULL)
     4740              {
     4741                bfd_boolean dyn;
     4742                dyn = htab->elf.dynamic_sections_created;
     4743                if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
     4744                    || (info->shared
     4745                        && SYMBOL_REFERENCES_LOCAL (info, h)))
     4746                  /* This is actually a static link, or it is a
     4747                     -Bsymbolic link and the symbol is defined
     4748                     locally, or the symbol was forced to be local
     4749                     because of a version file.  */
     4750                  ;
     4751                else
     4752                  {
     4753                    indx = h->dynindx;
     4754                    unresolved_reloc = FALSE;
     4755                  }
     4756                offp = &h->got.offset;
     4757              }
     4758            else
     4759              {
     4760                if (local_got_offsets == NULL)
     4761                  abort ();
     4762                offp = &local_got_offsets[r_symndx];
     4763              }
     4764
     4765            /* The offset must always be a multiple of 4.  We use the
     4766               least significant bit to record whether we have already
     4767               processed this entry.  */
     4768            off = *offp;
     4769            if ((off & 1) != 0)
     4770              off &= ~1;
     4771            else
     4772              {
     4773                unsigned int tls_m = (tls_mask
     4774                                      & (TLS_LD | TLS_GD | TLS_DTPREL
     4775                                         | TLS_TPREL | TLS_TPRELGD));
     4776
     4777                if (offp == &htab->tlsld_got.offset)
     4778                  tls_m = TLS_LD;
     4779                else if (h == NULL
     4780                         || !(h->elf_link_hash_flags
     4781                              & ELF_LINK_HASH_DEF_DYNAMIC))
     4782                  tls_m &= ~TLS_LD;
     4783
     4784                /* We might have multiple got entries for this sym.
     4785                   Initialize them all.  */
     4786                do
     4787                  {
     4788                    int tls_ty = 0;
     4789
     4790                    if ((tls_m & TLS_LD) != 0)
     4791                      {
     4792                        tls_ty = TLS_TLS | TLS_LD;
     4793                        tls_m &= ~TLS_LD;
     4794                      }
     4795                    else if ((tls_m & TLS_GD) != 0)
     4796                      {
     4797                        tls_ty = TLS_TLS | TLS_GD;
     4798                        tls_m &= ~TLS_GD;
     4799                      }
     4800                    else if ((tls_m & TLS_DTPREL) != 0)
     4801                      {
     4802                        tls_ty = TLS_TLS | TLS_DTPREL;
     4803                        tls_m &= ~TLS_DTPREL;
     4804                      }
     4805                    else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
     4806                      {
     4807                        tls_ty = TLS_TLS | TLS_TPREL;
     4808                        tls_m = 0;
     4809                      }
     4810
     4811                    /* Generate relocs for the dynamic linker.  */
     4812                    if (info->shared || indx != 0)
     4813                      {
     4814                        outrel.r_offset = (htab->got->output_section->vma
     4815                                           + htab->got->output_offset
     4816                                           + off);
     4817                        outrel.r_addend = 0;
     4818                        if (tls_ty & (TLS_LD | TLS_GD))
     4819                          {
     4820                            outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
     4821                            if (tls_ty == (TLS_TLS | TLS_GD))
     4822                              {
     4823                                loc = htab->relgot->contents;
     4824                                loc += (htab->relgot->reloc_count++
     4825                                        * sizeof (Elf32_External_Rela));
     4826                                bfd_elf32_swap_reloca_out (output_bfd,
     4827                                                           &outrel, loc);
     4828                                outrel.r_offset += 4;
     4829                                outrel.r_info
     4830                                  = ELF32_R_INFO (indx, R_PPC_DTPREL32);
     4831                              }
     4832                          }
     4833                        else if (tls_ty == (TLS_TLS | TLS_DTPREL))
     4834                          outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
     4835                        else if (tls_ty == (TLS_TLS | TLS_TPREL))
     4836                          outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
     4837                        else if (indx == 0)
     4838                          outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE);
     4839                        else
     4840                          outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
     4841                        if (indx == 0)
     4842                          {
     4843                            outrel.r_addend += relocation;
     4844                            if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
     4845                              outrel.r_addend -= htab->tls_sec->vma;
     4846                          }
     4847                        loc = htab->relgot->contents;
     4848                        loc += (htab->relgot->reloc_count++
     4849                                * sizeof (Elf32_External_Rela));
     4850                        bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
     4851                      }
     4852
     4853                    /* Init the .got section contents if we're not
     4854                       emitting a reloc.  */
     4855                    else
     4856                      {
     4857                        bfd_vma value = relocation;
     4858
     4859                        if (tls_ty == (TLS_TLS | TLS_LD))
     4860                          value = 1;
     4861                        else if (tls_ty != 0)
     4862                          {
     4863                            value -= htab->tls_sec->vma + DTP_OFFSET;
     4864                            if (tls_ty == (TLS_TLS | TLS_TPREL))
     4865                              value += DTP_OFFSET - TP_OFFSET;
     4866
     4867                            if (tls_ty == (TLS_TLS | TLS_GD))
     4868                              {
     4869                                bfd_put_32 (output_bfd, value,
     4870                                            htab->got->contents + off + 4);
     4871                                value = 1;
     4872                              }
     4873                          }
     4874                        bfd_put_32 (output_bfd, value,
     4875                                    htab->got->contents + off);
     4876                      }
     4877
     4878                    off += 4;
     4879                    if (tls_ty & (TLS_LD | TLS_GD))
     4880                      off += 4;
     4881                  }
     4882                while (tls_m != 0);
     4883
     4884                off = *offp;
     4885                *offp = off | 1;
     4886              }
     4887
     4888            if (off >= (bfd_vma) -2)
     4889              abort ();
     4890
     4891            if ((tls_type & TLS_TLS) != 0)
     4892              {
     4893                if (tls_type != (TLS_TLS | TLS_LD))
     4894                  {
     4895                    if ((tls_mask & TLS_LD) != 0
     4896                        && !(h == NULL
     4897                             || !(h->elf_link_hash_flags
     4898                                  & ELF_LINK_HASH_DEF_DYNAMIC)))
     4899                      off += 8;
     4900                    if (tls_type != (TLS_TLS | TLS_GD))
     4901                      {
     4902                        if ((tls_mask & TLS_GD) != 0)
     4903                          off += 8;
     4904                        if (tls_type != (TLS_TLS | TLS_DTPREL))
     4905                          {
     4906                            if ((tls_mask & TLS_DTPREL) != 0)
     4907                              off += 4;
     4908                          }
     4909                      }
     4910                  }
     4911              }
     4912
     4913            relocation = htab->got->output_offset + off - 4;
     4914
     4915            /* Addends on got relocations don't make much sense.
     4916               x+off@got is actually x@got+off, and since the got is
     4917               generated by a hash table traversal, the value in the
     4918               got at entry m+n bears little relation to the entry m.  */
     4919            if (addend != 0)
     4920              (*_bfd_error_handler)
     4921                (_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"),
     4922                 bfd_archive_filename (input_bfd),
     4923                 bfd_get_section_name (input_bfd, input_section),
     4924                 (long) rel->r_offset,
     4925                 howto->name,
     4926                 sym_name);
     4927          }
     4928        break;
     4929
    31494930        /* Relocations that need no special processing.  */
    3150         case (int) R_PPC_LOCAL24PC:
     4931        case R_PPC_LOCAL24PC:
    31514932          /* It makes no sense to point a local relocation
    31524933             at a symbol not in this object.  */
    3153           if (h != NULL
    3154               && (h->root.type == bfd_link_hash_defined
    3155                   || h->root.type == bfd_link_hash_defweak)
    3156               && sec->output_section == NULL)
     4934          if (unresolved_reloc)
    31574935            {
    31584936              if (! (*info->callbacks->undefined_symbol) (info,
     
    31614939                                                          input_section,
    31624940                                                          rel->r_offset,
    3163                                                           true))
    3164                 return false;
     4941                                                          TRUE))
     4942                return FALSE;
    31654943              continue;
    31664944            }
    31674945          break;
    31684946
    3169         /* Relocations that may need to be propagated if this is a shared
    3170            object.  */
    3171         case (int) R_PPC_REL24:
    3172         case (int) R_PPC_REL32:
    3173         case (int) R_PPC_REL14:
     4947        case R_PPC_DTPREL16:
     4948        case R_PPC_DTPREL16_LO:
     4949        case R_PPC_DTPREL16_HI:
     4950        case R_PPC_DTPREL16_HA:
     4951          addend -= htab->tls_sec->vma + DTP_OFFSET;
     4952          break;
     4953
     4954          /* Relocations that may need to be propagated if this is a shared
     4955             object.  */
     4956        case R_PPC_TPREL16:
     4957        case R_PPC_TPREL16_LO:
     4958        case R_PPC_TPREL16_HI:
     4959        case R_PPC_TPREL16_HA:
     4960          addend -= htab->tls_sec->vma + TP_OFFSET;
     4961          /* The TPREL16 relocs shouldn't really be used in shared
     4962             libs as they will result in DT_TEXTREL being set, but
     4963             support them anyway.  */
     4964          goto dodyn;
     4965
     4966        case R_PPC_TPREL32:
     4967          addend -= htab->tls_sec->vma + TP_OFFSET;
     4968          goto dodyn;
     4969
     4970        case R_PPC_DTPREL32:
     4971          addend -= htab->tls_sec->vma + DTP_OFFSET;
     4972          goto dodyn;
     4973
     4974        case R_PPC_DTPMOD32:
     4975          relocation = 1;
     4976          addend = 0;
     4977          goto dodyn;
     4978
     4979        case R_PPC_REL24:
     4980        case R_PPC_REL32:
     4981        case R_PPC_REL14:
     4982        case R_PPC_REL14_BRTAKEN:
     4983        case R_PPC_REL14_BRNTAKEN:
    31744984          /* If these relocations are not to a named symbol, they can be
    31754985             handled right here, no need to bother the dynamic linker.  */
     
    31784988              || SYMBOL_REFERENCES_LOCAL (info, h))
    31794989            break;
    3180         /* fall through */
    3181 
    3182         /* Relocations that always need to be propagated if this is a shared
    3183            object.  */
    3184         case (int) R_PPC_NONE:
    3185         case (int) R_PPC_ADDR32:
    3186         case (int) R_PPC_ADDR24:
    3187         case (int) R_PPC_ADDR16:
    3188         case (int) R_PPC_ADDR16_LO:
    3189         case (int) R_PPC_ADDR16_HI:
    3190         case (int) R_PPC_ADDR16_HA:
    3191         case (int) R_PPC_ADDR14:
    3192         case (int) R_PPC_UADDR32:
    3193         case (int) R_PPC_UADDR16:
    3194           if (info->shared)
     4990          /* fall through */
     4991
     4992          /* Relocations that always need to be propagated if this is a shared
     4993             object.  */
     4994        case R_PPC_ADDR32:
     4995        case R_PPC_ADDR24:
     4996        case R_PPC_ADDR16:
     4997        case R_PPC_ADDR16_LO:
     4998        case R_PPC_ADDR16_HI:
     4999        case R_PPC_ADDR16_HA:
     5000        case R_PPC_ADDR14:
     5001        case R_PPC_ADDR14_BRTAKEN:
     5002        case R_PPC_ADDR14_BRNTAKEN:
     5003        case R_PPC_UADDR32:
     5004        case R_PPC_UADDR16:
     5005          /* r_symndx will be zero only for relocs against symbols
     5006             from removed linkonce sections, or sections discarded by
     5007             a linker script.  */
     5008        dodyn:
     5009          if (r_symndx == 0)
     5010            break;
     5011          /* Fall thru.  */
     5012
     5013          if ((info->shared
     5014               && (MUST_BE_DYN_RELOC (r_type)
     5015                   || (h != NULL
     5016                       && h->dynindx != -1
     5017                       && (!info->symbolic
     5018                           || (h->elf_link_hash_flags
     5019                               & ELF_LINK_HASH_DEF_REGULAR) == 0))))
     5020              || (ELIMINATE_COPY_RELOCS
     5021                  && !info->shared
     5022                  && (input_section->flags & SEC_ALLOC) != 0
     5023                  && h != NULL
     5024                  && h->dynindx != -1
     5025                  && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
     5026                  && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
     5027                  && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0))
    31955028            {
    3196               Elf_Internal_Rela outrel;
    3197               boolean skip;
     5029              int skip;
    31985030
    31995031#ifdef DEBUG
    32005032              fprintf (stderr, "ppc_elf_relocate_section need to create relocation for %s\n",
    3201                        (h && h->root.root.string) ? h->root.root.string : "<unknown>");
     5033                       (h && h->root.root.string
     5034                        ? h->root.root.string : "<unknown>"));
    32025035#endif
    32035036
    32045037              /* When generating a shared object, these relocations
    3205                  are copied into the output file to be resolved at run
    3206                  time.  */
    3207 
     5038                 are copied into the output file to be resolved at run
     5039                 time.  */
    32085040              if (sreloc == NULL)
    32095041                {
     
    32155047                           elf_section_data (input_section)->rel_hdr.sh_name));
    32165048                  if (name == NULL)
    3217                     return false;
     5049                    return FALSE;
    32185050
    32195051                  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
     
    32225054                                         name + 5) == 0);
    32235055
    3224                   sreloc = bfd_get_section_by_name (dynobj, name);
     5056                  sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
    32255057                  BFD_ASSERT (sreloc != NULL);
    32265058                }
    32275059
    3228               skip = false;
    3229 
    3230               if (elf_section_data (input_section)->stab_info == NULL)
    3231                 outrel.r_offset = rel->r_offset;
    3232               else
    3233                 {
    3234                   bfd_vma off;
    3235 
    3236                   off = (_bfd_stab_section_offset
    3237                          (output_bfd, &elf_hash_table (info)->stab_info,
    3238                           input_section,
    3239                           &elf_section_data (input_section)->stab_info,
    3240                           rel->r_offset));
    3241                   if (off == (bfd_vma) -1)
    3242                     skip = true;
    3243                   outrel.r_offset = off;
    3244                 }
    3245 
     5060              skip = 0;
     5061
     5062              outrel.r_offset =
     5063                _bfd_elf_section_offset (output_bfd, info, input_section,
     5064                                         rel->r_offset);
     5065              if (outrel.r_offset == (bfd_vma) -1
     5066                  || outrel.r_offset == (bfd_vma) -2)
     5067                skip = (int) outrel.r_offset;
    32465068              outrel.r_offset += (input_section->output_section->vma
    32475069                                  + input_section->output_offset);
     
    32495071              if (skip)
    32505072                memset (&outrel, 0, sizeof outrel);
    3251               /* h->dynindx may be -1 if this symbol was marked to
    3252                  become local.  */
    3253               else if (! will_become_local)
     5073              else if (h != NULL
     5074                       && !SYMBOL_REFERENCES_LOCAL (info, h))
    32545075                {
     5076                  unresolved_reloc = FALSE;
    32555077                  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
    32565078                  outrel.r_addend = rel->r_addend;
     
    32585080              else
    32595081                {
     5082                  outrel.r_addend = relocation + rel->r_addend;
     5083
    32605084                  if (r_type == R_PPC_ADDR32)
    3261                     {
    3262                       outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
    3263                       outrel.r_addend = relocation + rel->r_addend;
    3264                     }
     5085                    outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
    32655086                  else
    32665087                    {
    32675088                      long indx;
    32685089
    3269                       if (h == NULL)
    3270                         sec = local_sections[r_symndx];
    3271                       else
    3272                         {
    3273                           BFD_ASSERT (h->root.type == bfd_link_hash_defined
    3274                                       || (h->root.type
    3275                                           == bfd_link_hash_defweak));
    3276                           sec = h->root.u.def.section;
    3277                         }
    3278                       if (sec != NULL && bfd_is_abs_section (sec))
     5090                      if (bfd_is_abs_section (sec))
    32795091                        indx = 0;
    32805092                      else if (sec == NULL || sec->owner == NULL)
    32815093                        {
    32825094                          bfd_set_error (bfd_error_bad_value);
    3283                           return false;
     5095                          return FALSE;
    32845096                        }
    32855097                      else
     
    32875099                          asection *osec;
    32885100
     5101                          /* We are turning this relocation into one
     5102                             against a section symbol.  It would be
     5103                             proper to subtract the symbol's value,
     5104                             osec->vma, from the emitted reloc addend,
     5105                             but ld.so expects buggy relocs.  */
    32895106                          osec = sec->output_section;
    32905107                          indx = elf_section_data (osec)->dynindx;
     
    32945111                            {
    32955112                              printf ("indx=%d section=%s flags=%08x name=%s\n",
    3296                                      indx, osec->name, osec->flags,
    3297                                      h->root.root.string);
     5113                                      indx, osec->name, osec->flags,
     5114                                      h->root.root.string);
    32985115                            }
    32995116#endif
     
    33015118
    33025119                      outrel.r_info = ELF32_R_INFO (indx, r_type);
    3303                       outrel.r_addend = relocation + rel->r_addend;
    33045120                    }
    33055121                }
    33065122
    3307               bfd_elf32_swap_reloca_out (output_bfd, &outrel,
    3308                                          (((Elf32_External_Rela *)
    3309                                            sreloc->contents)
    3310                                           + sreloc->reloc_count));
    3311               ++sreloc->reloc_count;
    3312 
    3313               /* This reloc will be computed at runtime, so there's no
    3314                  need to do anything now, unless this is a RELATIVE
    3315                  reloc in an unallocated section.  */
    3316               if (skip
    3317                   || (input_section->flags & SEC_ALLOC) != 0
    3318                   || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE)
     5123              loc = sreloc->contents;
     5124              loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
     5125              bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
     5126
     5127              if (skip == -1)
    33195128                continue;
    3320             }
    3321 
    3322           /* Arithmetic adjust relocations that aren't going into a
    3323              shared object.  */
    3324           if (r_type == R_PPC_ADDR16_HA
    3325               /* It's just possible that this symbol is a weak symbol
    3326                  that's not actually defined anywhere. In that case,
    3327                  'sec' would be NULL, and we should leave the symbol
    3328                  alone (it will be set to zero elsewhere in the link).  */
    3329               && sec != NULL)
    3330             {
    3331               addend += ((relocation + addend) & 0x8000) << 1;
     5129
     5130              /* This reloc will be computed at runtime.  We clear the memory
     5131                 so that it contains predictable value.  */
     5132              if (! skip
     5133                  && ((input_section->flags & SEC_ALLOC) != 0
     5134                      || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
     5135                {
     5136                  relocation = howto->pc_relative ? outrel.r_offset : 0;
     5137                  addend = 0;
     5138                  break;
     5139                }
    33325140            }
    33335141          break;
    33345142
    3335         /* branch taken prediction relocations */
    3336         case (int) R_PPC_ADDR14_BRTAKEN:
    3337         case (int) R_PPC_REL14_BRTAKEN:
    3338           insn = bfd_get_32 (output_bfd, contents + offset);
    3339           if ((relocation - offset) & 0x8000)
    3340             insn &= ~BRANCH_PREDICT_BIT;
    3341           else
    3342             insn |= BRANCH_PREDICT_BIT;
    3343           bfd_put_32 (output_bfd, insn, contents + offset);
     5143          /* Indirect .sdata relocation.  */
     5144        case R_PPC_EMB_SDAI16:
     5145          BFD_ASSERT (htab->sdata != NULL);
     5146          relocation
     5147            = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd,
     5148                                                       info, htab->sdata, h,
     5149                                                       relocation, rel,
     5150                                                       R_PPC_RELATIVE);
    33445151          break;
    33455152
    3346         /* branch not taken predicition relocations */
    3347         case (int) R_PPC_ADDR14_BRNTAKEN:
    3348         case (int) R_PPC_REL14_BRNTAKEN:
    3349           insn = bfd_get_32 (output_bfd, contents + offset);
    3350           if ((relocation - offset) & 0x8000)
    3351             insn |= BRANCH_PREDICT_BIT;
    3352           else
    3353             insn &= ~BRANCH_PREDICT_BIT;
    3354           bfd_put_32 (output_bfd, insn, contents + offset);
     5153          /* Indirect .sdata2 relocation.  */
     5154        case R_PPC_EMB_SDA2I16:
     5155          BFD_ASSERT (htab->sdata2 != NULL);
     5156          relocation
     5157            = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd,
     5158                                                       info, htab->sdata2, h,
     5159                                                       relocation, rel,
     5160                                                       R_PPC_RELATIVE);
    33555161          break;
    33565162
    3357         /* GOT16 relocations */
    3358         case (int) R_PPC_GOT16:
    3359         case (int) R_PPC_GOT16_LO:
    3360         case (int) R_PPC_GOT16_HI:
    3361         case (int) R_PPC_GOT16_HA:
    3362           /* Relocation is to the entry for this symbol in the global
    3363              offset table.  */
    3364           BFD_ASSERT (sgot != NULL);
    3365 
    3366           if (h != NULL)
    3367             {
    3368               bfd_vma off;
    3369 
    3370               off = h->got.offset;
    3371               BFD_ASSERT (off != (bfd_vma) -1);
    3372 
    3373               if (! elf_hash_table (info)->dynamic_sections_created
    3374                   || (info->shared
    3375                       && SYMBOL_REFERENCES_LOCAL (info, h)))
    3376                 {
    3377                   /* This is actually a static link, or it is a
    3378                      -Bsymbolic link and the symbol is defined
    3379                      locally.  We must initialize this entry in the
    3380                      global offset table.  Since the offset must
    3381                      always be a multiple of 4, we use the least
    3382                      significant bit to record whether we have
    3383                      initialized it already.
    3384 
    3385                      When doing a dynamic link, we create a .rela.got
    3386                      relocation entry to initialize the value.  This
    3387                      is done in the finish_dynamic_symbol routine.  */
    3388                   if ((off & 1) != 0)
    3389                     off &= ~1;
    3390                   else
    3391                     {
    3392                       bfd_put_32 (output_bfd, relocation,
    3393                                   sgot->contents + off);
    3394                       h->got.offset |= 1;
    3395                     }
    3396                 }
    3397 
    3398               relocation = sgot->output_offset + off - 4;
    3399             }
    3400           else
    3401             {
    3402               bfd_vma off;
    3403 
    3404               BFD_ASSERT (local_got_offsets != NULL
    3405                           && local_got_offsets[r_symndx] != (bfd_vma) -1);
    3406 
    3407               off = local_got_offsets[r_symndx];
    3408 
    3409               /* The offset must always be a multiple of 4.  We use
    3410                  the least significant bit to record whether we have
    3411                  already processed this entry.  */
    3412               if ((off & 1) != 0)
    3413                 off &= ~1;
    3414               else
    3415                 {
    3416                   bfd_put_32 (output_bfd, relocation, sgot->contents + off);
    3417 
    3418                   if (info->shared)
    3419                     {
    3420                       asection *srelgot;
    3421                       Elf_Internal_Rela outrel;
    3422 
    3423                       /* We need to generate a R_PPC_RELATIVE reloc
    3424                          for the dynamic linker.  */
    3425                       srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
    3426                       BFD_ASSERT (srelgot != NULL);
    3427 
    3428                       outrel.r_offset = (sgot->output_section->vma
    3429                                          + sgot->output_offset
    3430                                          + off);
    3431                       outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
    3432                       outrel.r_addend = relocation;
    3433                       bfd_elf32_swap_reloca_out (output_bfd, &outrel,
    3434                                                  (((Elf32_External_Rela *)
    3435                                                    srelgot->contents)
    3436                                                   + srelgot->reloc_count));
    3437                       ++srelgot->reloc_count;
    3438                     }
    3439 
    3440                   local_got_offsets[r_symndx] |= 1;
    3441                 }
    3442 
    3443               relocation = sgot->output_offset + off - 4;
    3444             }
    3445           break;
    3446 
    3447         /* Indirect .sdata relocation */
    3448         case (int) R_PPC_EMB_SDAI16:
    3449           BFD_ASSERT (sdata != NULL);
    3450           relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
    3451                                                                 sdata, h, relocation, rel,
    3452                                                                 R_PPC_RELATIVE);
    3453           break;
    3454 
    3455         /* Indirect .sdata2 relocation */
    3456         case (int) R_PPC_EMB_SDA2I16:
    3457           BFD_ASSERT (sdata2 != NULL);
    3458           relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
    3459                                                                 sdata2, h, relocation, rel,
    3460                                                                 R_PPC_RELATIVE);
    3461           break;
    3462 
    3463         /* Handle the TOC16 reloc.  We want to use the offset within the .got
    3464            section, not the actual VMA.  This is appropriate when generating
    3465            an embedded ELF object, for which the .got section acts like the
    3466            AIX .toc section.  */
    3467         case (int) R_PPC_TOC16:                 /* phony GOT16 relocations */
     5163          /* Handle the TOC16 reloc.  We want to use the offset within the .got
     5164             section, not the actual VMA.  This is appropriate when generating
     5165             an embedded ELF object, for which the .got section acts like the
     5166             AIX .toc section.  */
     5167        case R_PPC_TOC16:                       /* phony GOT16 relocations */
    34685168          BFD_ASSERT (sec != (asection *) 0);
    34695169          BFD_ASSERT (bfd_is_und_section (sec)
     
    34715171                      || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0)
    34725172
    3473           addend -= sec->output_section->vma + sec->output_offset + 0x8000;
     5173            addend -= sec->output_section->vma + sec->output_offset + 0x8000;
    34745174          break;
    34755175
    3476         case (int) R_PPC_PLTREL24:
     5176        case R_PPC_PLTREL24:
    34775177          /* Relocation is to the entry for this symbol in the
    3478              procedure linkage table.  */
     5178             procedure linkage table.  */
    34795179          BFD_ASSERT (h != NULL);
    34805180
    34815181          if (h->plt.offset == (bfd_vma) -1
    3482               || splt == NULL)
     5182              || htab->plt == NULL)
    34835183            {
    34845184              /* We didn't make a PLT entry for this symbol.  This
    3485                 happens when statically linking PIC code, or when
    3486                 using -Bsymbolic.  */
     5185                happens when statically linking PIC code, or when
     5186                using -Bsymbolic.  */
    34875187              break;
    34885188            }
    34895189
    3490           relocation = (splt->output_section->vma
    3491                         + splt->output_offset
     5190          unresolved_reloc = FALSE;
     5191          relocation = (htab->plt->output_section->vma
     5192                        + htab->plt->output_offset
    34925193                        + h->plt.offset);
    34935194          break;
    34945195
    3495         /* relocate against _SDA_BASE_ */
    3496         case (int) R_PPC_SDAREL16:
     5196          /* Relocate against _SDA_BASE_. */
     5197        case R_PPC_SDAREL16:
    34975198          {
    34985199            const char *name;
     5200            const struct elf_link_hash_entry *sh;
    34995201
    35005202            BFD_ASSERT (sec != (asection *) 0);
    35015203            name = bfd_get_section_name (abfd, sec->output_section);
    3502             if (strcmp (name, ".sdata") != 0
    3503                 && strcmp (name, ".sbss") != 0)
     5204            if (! ((strncmp (name, ".sdata", 6) == 0
     5205                    && (name[6] == 0 || name[6] == '.'))
     5206                   || (strncmp (name, ".sbss", 5) == 0
     5207                       && (name[5] == 0 || name[5] == '.'))))
    35045208              {
    3505                 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
    3506                                        bfd_get_filename (input_bfd),
     5209                (*_bfd_error_handler) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
     5210                                       bfd_archive_filename (input_bfd),
    35075211                                       sym_name,
    3508                                        ppc_elf_howto_table[(int) r_type]->name,
     5212                                       howto->name,
    35095213                                       name);
    35105214              }
    3511             addend -= (sdata->sym_hash->root.u.def.value
    3512                        + sdata->sym_hash->root.u.def.section->output_section->vma
    3513                        + sdata->sym_hash->root.u.def.section->output_offset);
     5215            sh = htab->sdata->sym_hash;
     5216            addend -= (sh->root.u.def.value
     5217                       + sh->root.u.def.section->output_section->vma
     5218                       + sh->root.u.def.section->output_offset);
    35145219          }
    35155220          break;
    35165221
    3517         /* relocate against _SDA2_BASE_ */
    3518         case (int) R_PPC_EMB_SDA2REL:
     5222          /* Relocate against _SDA2_BASE_. */
     5223        case R_PPC_EMB_SDA2REL:
    35195224          {
    35205225            const char *name;
     5226            const struct elf_link_hash_entry *sh;
    35215227
    35225228            BFD_ASSERT (sec != (asection *) 0);
    35235229            name = bfd_get_section_name (abfd, sec->output_section);
    3524             if (strcmp (name, ".sdata2") != 0 && strcmp (name, ".sbss2") != 0)
     5230            if (! (strncmp (name, ".sdata2", 7) == 0
     5231                   || strncmp (name, ".sbss2", 6) == 0))
    35255232              {
    3526                 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
    3527                                        bfd_get_filename (input_bfd),
     5233                (*_bfd_error_handler) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
     5234                                       bfd_archive_filename (input_bfd),
    35285235                                       sym_name,
    3529                                        ppc_elf_howto_table[(int) r_type]->name,
     5236                                       howto->name,
    35305237                                       name);
    35315238
    35325239                bfd_set_error (bfd_error_bad_value);
    3533                 ret = false;
     5240                ret = FALSE;
    35345241                continue;
    35355242              }
    3536             addend -= (sdata2->sym_hash->root.u.def.value
    3537                        + sdata2->sym_hash->root.u.def.section->output_section->vma
    3538                        + sdata2->sym_hash->root.u.def.section->output_offset);
     5243            sh = htab->sdata2->sym_hash;
     5244            addend -= (sh->root.u.def.value
     5245                       + sh->root.u.def.section->output_section->vma
     5246                       + sh->root.u.def.section->output_offset);
    35395247          }
    35405248          break;
    35415249
    3542         /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
    3543         case (int) R_PPC_EMB_SDA21:
    3544         case (int) R_PPC_EMB_RELSDA:
     5250          /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
     5251        case R_PPC_EMB_SDA21:
     5252        case R_PPC_EMB_RELSDA:
    35455253          {
    35465254            const char *name;
     5255            const struct elf_link_hash_entry *sh;
    35475256            int reg;
    35485257
    35495258            BFD_ASSERT (sec != (asection *) 0);
    35505259            name = bfd_get_section_name (abfd, sec->output_section);
    3551             if (strcmp (name, ".sdata") == 0 || strcmp (name, ".sbss") == 0)
     5260            if (((strncmp (name, ".sdata", 6) == 0
     5261                  && (name[6] == 0 || name[6] == '.'))
     5262                 || (strncmp (name, ".sbss", 5) == 0
     5263                     && (name[5] == 0 || name[5] == '.'))))
    35525264              {
    35535265                reg = 13;
    3554                 addend -= (sdata->sym_hash->root.u.def.value
    3555                            + sdata->sym_hash->root.u.def.section->output_section->vma
    3556                            + sdata->sym_hash->root.u.def.section->output_offset);
     5266                sh = htab->sdata->sym_hash;
     5267                addend -= (sh->root.u.def.value
     5268                           + sh->root.u.def.section->output_section->vma
     5269                           + sh->root.u.def.section->output_offset);
    35575270              }
    35585271
    3559             else if (strcmp (name, ".sdata2") == 0
    3560                      || strcmp (name, ".sbss2") == 0)
     5272            else if (strncmp (name, ".sdata2", 7) == 0
     5273                     || strncmp (name, ".sbss2", 6) == 0)
    35615274              {
    35625275                reg = 2;
    3563                 addend -= (sdata2->sym_hash->root.u.def.value
    3564                            + sdata2->sym_hash->root.u.def.section->output_section->vma
    3565                            + sdata2->sym_hash->root.u.def.section->output_offset);
     5276                sh = htab->sdata2->sym_hash;
     5277                addend -= (sh->root.u.def.value
     5278                           + sh->root.u.def.section->output_section->vma
     5279                           + sh->root.u.def.section->output_offset);
    35665280              }
    35675281
     
    35745288            else
    35755289              {
    3576                 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
    3577                                        bfd_get_filename (input_bfd),
     5290                (*_bfd_error_handler) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
     5291                                       bfd_archive_filename (input_bfd),
    35785292                                       sym_name,
    3579                                        ppc_elf_howto_table[(int) r_type]->name,
     5293                                       howto->name,
    35805294                                       name);
    35815295
    35825296                bfd_set_error (bfd_error_bad_value);
    3583                 ret = false;
     5297                ret = FALSE;
    35845298                continue;
    35855299              }
     
    35875301            if (r_type == R_PPC_EMB_SDA21)
    35885302              {                 /* fill in register field */
    3589                 insn = bfd_get_32 (output_bfd, contents + offset);
     5303                insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
    35905304                insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
    3591                 bfd_put_32 (output_bfd, insn, contents + offset);
     5305                bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
    35925306              }
    35935307          }
    35945308          break;
    35955309
    3596         /* Relocate against the beginning of the section */
    3597         case (int) R_PPC_SECTOFF:
    3598         case (int) R_PPC_SECTOFF_LO:
    3599         case (int) R_PPC_SECTOFF_HI:
     5310          /* Relocate against the beginning of the section.  */
     5311        case R_PPC_SECTOFF:
     5312        case R_PPC_SECTOFF_LO:
     5313        case R_PPC_SECTOFF_HI:
     5314        case R_PPC_SECTOFF_HA:
    36005315          BFD_ASSERT (sec != (asection *) 0);
    36015316          addend -= sec->output_section->vma;
    36025317          break;
    36035318
    3604         case (int) R_PPC_SECTOFF_HA:
    3605           BFD_ASSERT (sec != (asection *) 0);
    3606           addend -= sec->output_section->vma;
    3607           addend += ((relocation + addend) & 0x8000) << 1;
    3608           break;
    3609 
    3610         /* Negative relocations */
    3611         case (int) R_PPC_EMB_NADDR32:
    3612         case (int) R_PPC_EMB_NADDR16:
    3613         case (int) R_PPC_EMB_NADDR16_LO:
    3614         case (int) R_PPC_EMB_NADDR16_HI:
     5319          /* Negative relocations.  */
     5320        case R_PPC_EMB_NADDR32:
     5321        case R_PPC_EMB_NADDR16:
     5322        case R_PPC_EMB_NADDR16_LO:
     5323        case R_PPC_EMB_NADDR16_HI:
     5324        case R_PPC_EMB_NADDR16_HA:
    36155325          addend -= 2 * relocation;
    36165326          break;
    36175327
    3618         case (int) R_PPC_EMB_NADDR16_HA:
    3619           addend -= 2 * relocation;
    3620           addend += ((relocation + addend) & 0x8000) << 1;
     5328        case R_PPC_COPY:
     5329        case R_PPC_GLOB_DAT:
     5330        case R_PPC_JMP_SLOT:
     5331        case R_PPC_RELATIVE:
     5332        case R_PPC_PLT32:
     5333        case R_PPC_PLTREL32:
     5334        case R_PPC_PLT16_LO:
     5335        case R_PPC_PLT16_HI:
     5336        case R_PPC_PLT16_HA:
     5337        case R_PPC_ADDR30:
     5338        case R_PPC_EMB_RELSEC16:
     5339        case R_PPC_EMB_RELST_LO:
     5340        case R_PPC_EMB_RELST_HI:
     5341        case R_PPC_EMB_RELST_HA:
     5342        case R_PPC_EMB_BIT_FLD:
     5343          (*_bfd_error_handler)
     5344            (_("%s: relocation %s is not yet supported for symbol %s."),
     5345             bfd_archive_filename (input_bfd),
     5346             howto->name,
     5347             sym_name);
     5348
     5349          bfd_set_error (bfd_error_invalid_operation);
     5350          ret = FALSE;
     5351          continue;
     5352        }
     5353
     5354      /* Do any further special processing.  */
     5355      switch (r_type)
     5356        {
     5357        default:
    36215358          break;
    36225359
    3623         /* NOP relocation that prevents garbage collecting linkers from omitting a
    3624            reference.  */
    3625         case (int) R_PPC_EMB_MRKREF:
    3626           continue;
    3627 
    3628         case (int) R_PPC_COPY:
    3629         case (int) R_PPC_GLOB_DAT:
    3630         case (int) R_PPC_JMP_SLOT:
    3631         case (int) R_PPC_RELATIVE:
    3632         case (int) R_PPC_PLT32:
    3633         case (int) R_PPC_PLTREL32:
    3634         case (int) R_PPC_PLT16_LO:
    3635         case (int) R_PPC_PLT16_HI:
    3636         case (int) R_PPC_PLT16_HA:
    3637         case (int) R_PPC_EMB_RELSEC16:
    3638         case (int) R_PPC_EMB_RELST_LO:
    3639         case (int) R_PPC_EMB_RELST_HI:
    3640         case (int) R_PPC_EMB_RELST_HA:
    3641         case (int) R_PPC_EMB_BIT_FLD:
    3642           (*_bfd_error_handler) (_("%s: Relocation %s is not yet supported for symbol %s."),
    3643                                  bfd_get_filename (input_bfd),
    3644                                  ppc_elf_howto_table[(int) r_type]->name,
    3645                                  sym_name);
    3646 
    3647           bfd_set_error (bfd_error_invalid_operation);
    3648           ret = false;
    3649           continue;
    3650 
    3651         case (int) R_PPC_GNU_VTINHERIT:
    3652         case (int) R_PPC_GNU_VTENTRY:
    3653           /* These are no-ops in the end.  */
    3654           continue;
     5360        case R_PPC_ADDR16_HA:
     5361        case R_PPC_GOT16_HA:
     5362        case R_PPC_PLT16_HA:
     5363        case R_PPC_SECTOFF_HA:
     5364        case R_PPC_TPREL16_HA:
     5365        case R_PPC_DTPREL16_HA:
     5366        case R_PPC_GOT_TLSGD16_HA:
     5367        case R_PPC_GOT_TLSLD16_HA:
     5368        case R_PPC_GOT_TPREL16_HA:
     5369        case R_PPC_GOT_DTPREL16_HA:
     5370        case R_PPC_EMB_NADDR16_HA:
     5371        case R_PPC_EMB_RELST_HA:
     5372          /* It's just possible that this symbol is a weak symbol
     5373             that's not actually defined anywhere.  In that case,
     5374             'sec' would be NULL, and we should leave the symbol
     5375             alone (it will be set to zero elsewhere in the link).  */
     5376          if (sec != NULL)
     5377            /* Add 0x10000 if sign bit in 0:15 is set.
     5378               Bits 0:15 are not used.  */
     5379            addend += 0x8000;
     5380          break;
    36555381        }
    36565382
     
    36615387               sym_name,
    36625388               r_symndx,
    3663                (long) offset,
     5389               (long) rel->r_offset,
    36645390               (long) addend);
    36655391#endif
     5392
     5393      if (unresolved_reloc
     5394          && !((input_section->flags & SEC_DEBUGGING) != 0
     5395               && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
     5396        {
     5397          (*_bfd_error_handler)
     5398            (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
     5399             bfd_archive_filename (input_bfd),
     5400             bfd_get_section_name (input_bfd, input_section),
     5401             (long) rel->r_offset,
     5402             howto->name,
     5403             sym_name);
     5404          ret = FALSE;
     5405        }
    36665406
    36675407      r = _bfd_final_link_relocate (howto,
     
    36695409                                    input_section,
    36705410                                    contents,
    3671                                     offset,
     5411                                    rel->r_offset,
    36725412                                    relocation,
    36735413                                    addend);
    36745414
    3675       if (r == bfd_reloc_ok)
    3676         ;
    3677       else if (r == bfd_reloc_overflow)
     5415      if (r != bfd_reloc_ok)
    36785416        {
    3679           const char *name;
    3680 
    3681           if (h != NULL)
     5417          if (sym_name == NULL)
     5418            sym_name = "(null)";
     5419          if (r == bfd_reloc_overflow)
    36825420            {
    3683               if (h->root.type == bfd_link_hash_undefweak
     5421              if (warned)
     5422                continue;
     5423              if (h != NULL
     5424                  && h->root.type == bfd_link_hash_undefweak
    36845425                  && howto->pc_relative)
    36855426                {
     
    36935434                }
    36945435
    3695               name = h->root.root.string;
     5436              if (! (*info->callbacks->reloc_overflow) (info,
     5437                                                        sym_name,
     5438                                                        howto->name,
     5439                                                        rel->r_addend,
     5440                                                        input_bfd,
     5441                                                        input_section,
     5442                                                        rel->r_offset))
     5443                return FALSE;
    36965444            }
    36975445          else
    36985446            {
    3699               name = bfd_elf_string_from_elf_section (input_bfd,
    3700                                                       symtab_hdr->sh_link,
    3701                                                       sym->st_name);
    3702               if (name == NULL)
    3703                 continue;
    3704               if (*name == '\0')
    3705                 name = bfd_section_name (input_bfd, sec);
     5447              (*_bfd_error_handler)
     5448                (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
     5449                 bfd_archive_filename (input_bfd),
     5450                 bfd_get_section_name (input_bfd, input_section),
     5451                 (long) rel->r_offset, howto->name, sym_name, (int) r);
     5452              ret = FALSE;
    37065453            }
    3707 
    3708           if (! (*info->callbacks->reloc_overflow) (info,
    3709                                                    name,
    3710                                                    howto->name,
    3711                                                    (bfd_vma) 0,
    3712                                                    input_bfd,
    3713                                                    input_section,
    3714                                                    offset))
    3715             return false;
    37165454        }
    3717       else
    3718         ret = false;
    37195455    }
    37205456
     
    37245460
    37255461  return ret;
     5462}
     5463
     5464static enum elf_reloc_type_class
     5465ppc_elf_reloc_type_class (rela)
     5466     const Elf_Internal_Rela *rela;
     5467{
     5468  switch ((int) ELF32_R_TYPE (rela->r_info))
     5469    {
     5470    case R_PPC_RELATIVE:
     5471      return reloc_class_relative;
     5472    case R_PPC_REL24:
     5473    case R_PPC_ADDR24:
     5474    case R_PPC_JMP_SLOT:
     5475      return reloc_class_plt;
     5476    case R_PPC_COPY:
     5477      return reloc_class_copy;
     5478    default:
     5479      return reloc_class_normal;
     5480    }
     5481}
     5482
     5483
     5484/* Support for core dump NOTE sections.  */
     5485
     5486static bfd_boolean
     5487ppc_elf_grok_prstatus (abfd, note)
     5488     bfd *abfd;
     5489     Elf_Internal_Note *note;
     5490{
     5491  int offset;
     5492  unsigned int raw_size;
     5493
     5494  switch (note->descsz)
     5495    {
     5496    default:
     5497      return FALSE;
     5498
     5499    case 268:           /* Linux/PPC.  */
     5500      /* pr_cursig */
     5501      elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
     5502
     5503      /* pr_pid */
     5504      elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
     5505
     5506      /* pr_reg */
     5507      offset = 72;
     5508      raw_size = 192;
     5509
     5510      break;
     5511    }
     5512
     5513  /* Make a ".reg/999" section.  */
     5514  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
     5515                                          raw_size, note->descpos + offset);
     5516}
     5517
     5518static bfd_boolean
     5519ppc_elf_grok_psinfo (abfd, note)
     5520     bfd *abfd;
     5521     Elf_Internal_Note *note;
     5522{
     5523  switch (note->descsz)
     5524    {
     5525    default:
     5526      return FALSE;
     5527
     5528    case 128:           /* Linux/PPC elf_prpsinfo.  */
     5529      elf_tdata (abfd)->core_program
     5530        = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
     5531      elf_tdata (abfd)->core_command
     5532        = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
     5533    }
     5534
     5535  /* Note that for some reason, a spurious space is tacked
     5536     onto the end of the args in some (at least one anyway)
     5537     implementations, so strip it off if it exists.  */
     5538
     5539  {
     5540    char *command = elf_tdata (abfd)->core_command;
     5541    int n = strlen (command);
     5542
     5543    if (0 < n && command[n - 1] == ' ')
     5544      command[n - 1] = '\0';
     5545  }
     5546
     5547  return TRUE;
     5548}
     5549
     5550
     5551/* Very simple linked list structure for recording apuinfo values.  */
     5552typedef struct apuinfo_list
     5553{
     5554  struct apuinfo_list *next;
     5555  unsigned long value;
     5556}
     5557apuinfo_list;
     5558
     5559static apuinfo_list * head;
     5560
     5561static void apuinfo_list_init PARAMS ((void));
     5562static void apuinfo_list_add PARAMS ((unsigned long));
     5563static unsigned apuinfo_list_length PARAMS ((void));
     5564static unsigned long apuinfo_list_element PARAMS ((unsigned long));
     5565static void apuinfo_list_finish PARAMS ((void));
     5566
     5567extern void ppc_elf_begin_write_processing
     5568  PARAMS ((bfd *, struct bfd_link_info *));
     5569extern void ppc_elf_final_write_processing
     5570  PARAMS ((bfd *, bfd_boolean));
     5571extern bfd_boolean ppc_elf_write_section
     5572  PARAMS ((bfd *, asection *, bfd_byte *));
     5573
     5574
     5575static void
     5576apuinfo_list_init PARAMS ((void))
     5577{
     5578  head = NULL;
     5579}
     5580
     5581static void
     5582apuinfo_list_add (value)
     5583     unsigned long value;
     5584{
     5585  apuinfo_list *entry = head;
     5586
     5587  while (entry != NULL)
     5588    {
     5589      if (entry->value == value)
     5590        return;
     5591      entry = entry->next;
     5592    }
     5593
     5594  entry = bfd_malloc (sizeof (* entry));
     5595  if (entry == NULL)
     5596    return;
     5597
     5598  entry->value = value;
     5599  entry->next  = head;
     5600  head = entry;
     5601}
     5602
     5603static unsigned
     5604apuinfo_list_length PARAMS ((void))
     5605{
     5606  apuinfo_list *entry;
     5607  unsigned long count;
     5608
     5609  for (entry = head, count = 0;
     5610       entry;
     5611       entry = entry->next)
     5612    ++ count;
     5613
     5614  return count;
     5615}
     5616
     5617static inline unsigned long
     5618apuinfo_list_element (number)
     5619     unsigned long number;
     5620{
     5621  apuinfo_list * entry;
     5622
     5623  for (entry = head;
     5624       entry && number --;
     5625       entry = entry->next)
     5626    ;
     5627
     5628  return entry ? entry->value : 0;
     5629}
     5630
     5631static void
     5632apuinfo_list_finish PARAMS ((void))
     5633{
     5634  apuinfo_list *entry;
     5635
     5636  for (entry = head; entry;)
     5637    {
     5638      apuinfo_list *next = entry->next;
     5639      free (entry);
     5640      entry = next;
     5641    }
     5642
     5643  head = NULL;
     5644}
     5645
     5646#define APUINFO_SECTION_NAME    ".PPC.EMB.apuinfo"
     5647#define APUINFO_LABEL           "APUinfo"
     5648
     5649/* Scan the input BFDs and create a linked list of
     5650   the APUinfo values that will need to be emitted.  */
     5651
     5652void
     5653ppc_elf_begin_write_processing (abfd, link_info)
     5654     bfd *abfd;
     5655     struct bfd_link_info *link_info;
     5656{
     5657  bfd *ibfd;
     5658  asection *asec;
     5659  char *buffer;
     5660  unsigned num_input_sections;
     5661  bfd_size_type output_section_size;
     5662  unsigned i;
     5663  unsigned num_entries;
     5664  unsigned long offset;
     5665  unsigned long length;
     5666  const char *error_message = NULL;
     5667
     5668  if (link_info == NULL)
     5669    return;
     5670
     5671  /* Scan the input bfds, looking for apuinfo sections.  */
     5672  num_input_sections = 0;
     5673  output_section_size = 0;
     5674
     5675  for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
     5676    {
     5677      asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
     5678      if (asec)
     5679        {
     5680          ++ num_input_sections;
     5681          output_section_size += asec->_raw_size;
     5682        }
     5683    }
     5684
     5685  /* We need at least one input sections
     5686     in order to make merging worthwhile.  */
     5687  if (num_input_sections < 1)
     5688    return;
     5689
     5690  /* Just make sure that the output section exists as well.  */
     5691  asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
     5692  if (asec == NULL)
     5693    return;
     5694
     5695  /* Allocate a buffer for the contents of the input sections.  */
     5696  buffer = bfd_malloc (output_section_size);
     5697  if (buffer == NULL)
     5698    return;
     5699
     5700  offset = 0;
     5701  apuinfo_list_init ();
     5702
     5703  /* Read in the input sections contents.  */
     5704  for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
     5705    {
     5706      unsigned long datum;
     5707      char *ptr;
     5708
     5709      asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
     5710      if (asec == NULL)
     5711        continue;
     5712
     5713      length = asec->_raw_size;
     5714      if (length < 24)
     5715        {
     5716          error_message = _("corrupt or empty %s section in %s");
     5717          goto fail;
     5718        }
     5719
     5720      if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
     5721          || (bfd_bread (buffer + offset, length, ibfd) != length))
     5722        {
     5723          error_message = _("unable to read in %s section from %s");
     5724          goto fail;
     5725        }
     5726
     5727      /* Process the contents of the section.  */
     5728      ptr = buffer + offset;
     5729      error_message = _("corrupt %s section in %s");
     5730
     5731      /* Verify the contents of the header.  Note - we have to
     5732         extract the values this way in order to allow for a
     5733         host whose endian-ness is different from the target.  */
     5734      datum = bfd_get_32 (ibfd, ptr);
     5735      if (datum != sizeof APUINFO_LABEL)
     5736        goto fail;
     5737
     5738      datum = bfd_get_32 (ibfd, ptr + 8);
     5739      if (datum != 0x2)
     5740        goto fail;
     5741
     5742      if (strcmp (ptr + 12, APUINFO_LABEL) != 0)
     5743        goto fail;
     5744
     5745      /* Get the number of apuinfo entries.  */
     5746      datum = bfd_get_32 (ibfd, ptr + 4);
     5747      if ((datum * 4 + 20) != length)
     5748        goto fail;
     5749
     5750      /* Make sure that we do not run off the end of the section.  */
     5751      if (offset + length > output_section_size)
     5752        goto fail;
     5753
     5754      /* Scan the apuinfo section, building a list of apuinfo numbers.  */
     5755      for (i = 0; i < datum; i++)
     5756        apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + (i * 4)));
     5757
     5758      /* Update the offset.  */
     5759      offset += length;
     5760    }
     5761
     5762  error_message = NULL;
     5763
     5764  /* Compute the size of the output section.  */
     5765  num_entries = apuinfo_list_length ();
     5766  output_section_size = 20 + num_entries * 4;
     5767
     5768  asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
     5769
     5770  if (! bfd_set_section_size (abfd, asec, output_section_size))
     5771    ibfd = abfd,
     5772      error_message = _("warning: unable to set size of %s section in %s");
     5773
     5774 fail:
     5775  free (buffer);
     5776
     5777  if (error_message)
     5778    (*_bfd_error_handler) (error_message, APUINFO_SECTION_NAME,
     5779                           bfd_archive_filename (ibfd));
     5780}
     5781
     5782
     5783/* Prevent the output section from accumulating the input sections'
     5784   contents.  We have already stored this in our linked list structure.  */
     5785
     5786bfd_boolean
     5787ppc_elf_write_section (abfd, asec, contents)
     5788     bfd *abfd ATTRIBUTE_UNUSED;
     5789     asection *asec;
     5790     bfd_byte *contents ATTRIBUTE_UNUSED;
     5791{
     5792  return (apuinfo_list_length ()
     5793          && strcmp (asec->name, APUINFO_SECTION_NAME) == 0);
     5794}
     5795
     5796
     5797/* Finally we can generate the output section.  */
     5798
     5799void
     5800ppc_elf_final_write_processing (abfd, linker)
     5801     bfd *abfd;
     5802     bfd_boolean linker ATTRIBUTE_UNUSED;
     5803{
     5804  bfd_byte *buffer;
     5805  asection *asec;
     5806  unsigned i;
     5807  unsigned num_entries;
     5808  bfd_size_type length;
     5809
     5810  asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
     5811  if (asec == NULL)
     5812    return;
     5813
     5814  if (apuinfo_list_length () == 0)
     5815    return;
     5816
     5817  length = asec->_raw_size;
     5818  if (length < 20)
     5819    return;
     5820
     5821  buffer = bfd_malloc (length);
     5822  if (buffer == NULL)
     5823    {
     5824      (*_bfd_error_handler)
     5825        (_("failed to allocate space for new APUinfo section."));
     5826      return;
     5827    }
     5828
     5829  /* Create the apuinfo header.  */
     5830  num_entries = apuinfo_list_length ();
     5831  bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
     5832  bfd_put_32 (abfd, num_entries, buffer + 4);
     5833  bfd_put_32 (abfd, 0x2, buffer + 8);
     5834  strcpy (buffer + 12, APUINFO_LABEL);
     5835
     5836  length = 20;
     5837  for (i = 0; i < num_entries; i++)
     5838    {
     5839      bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
     5840      length += 4;
     5841    }
     5842
     5843  if (length != asec->_raw_size)
     5844    (*_bfd_error_handler) (_("failed to compute new APUinfo section."));
     5845
     5846  if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
     5847    (*_bfd_error_handler) (_("failed to install new APUinfo section."));
     5848
     5849  free (buffer);
     5850
     5851  apuinfo_list_finish ();
    37265852}
    37275853
     
    37475873#define elf_backend_got_symbol_offset   4
    37485874#define elf_backend_can_gc_sections     1
     5875#define elf_backend_can_refcount        1
    37495876#define elf_backend_got_header_size     12
    37505877#define elf_backend_plt_header_size     PLT_INITIAL_ENTRY_SIZE
    3751 
    3752 #define bfd_elf32_bfd_copy_private_bfd_data     ppc_elf_copy_private_bfd_data
     5878#define elf_backend_rela_normal         1
     5879
    37535880#define bfd_elf32_bfd_merge_private_bfd_data    ppc_elf_merge_private_bfd_data
    3754 #define bfd_elf32_bfd_relax_section             ppc_elf_relax_section
     5881#define bfd_elf32_bfd_relax_section             ppc_elf_relax_section
    37555882#define bfd_elf32_bfd_reloc_type_lookup         ppc_elf_reloc_type_lookup
    37565883#define bfd_elf32_bfd_set_private_flags         ppc_elf_set_private_flags
    3757 #define bfd_elf32_bfd_final_link                _bfd_elf32_gc_common_final_link
    3758 
     5884#define bfd_elf32_bfd_link_hash_table_create    ppc_elf_link_hash_table_create
     5885
     5886#define elf_backend_object_p                    ppc_elf_object_p
    37595887#define elf_backend_gc_mark_hook                ppc_elf_gc_mark_hook
    37605888#define elf_backend_gc_sweep_hook               ppc_elf_gc_sweep_hook
     
    37635891#define elf_backend_create_dynamic_sections     ppc_elf_create_dynamic_sections
    37645892#define elf_backend_check_relocs                ppc_elf_check_relocs
     5893#define elf_backend_copy_indirect_symbol        ppc_elf_copy_indirect_symbol
    37655894#define elf_backend_adjust_dynamic_symbol       ppc_elf_adjust_dynamic_symbol
    37665895#define elf_backend_add_symbol_hook             ppc_elf_add_symbol_hook
     
    37715900#define elf_backend_additional_program_headers  ppc_elf_additional_program_headers
    37725901#define elf_backend_modify_segment_map          ppc_elf_modify_segment_map
     5902#define elf_backend_grok_prstatus               ppc_elf_grok_prstatus
     5903#define elf_backend_grok_psinfo                 ppc_elf_grok_psinfo
     5904#define elf_backend_reloc_type_class            ppc_elf_reloc_type_class
     5905#define elf_backend_begin_write_processing      ppc_elf_begin_write_processing
     5906#define elf_backend_final_write_processing      ppc_elf_final_write_processing
     5907#define elf_backend_write_section               ppc_elf_write_section
    37735908
    37745909#include "elf32-target.h"
Note: See TracChangeset for help on using the changeset viewer.