elf32-ppc.c revision 130562
113044Sasami/* PowerPC-specific support for 32-bit ELF
213044Sasami   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
313044Sasami   2004 Free Software Foundation, Inc.
413044Sasami   Written by Ian Lance Taylor, Cygnus Support.
513044Sasami
613044Sasami   This file is part of BFD, the Binary File Descriptor library.
713044Sasami
813044Sasami   This program is free software; you can redistribute it and/or modify
913044Sasami   it under the terms of the GNU General Public License as published by
1013044Sasami   the Free Software Foundation; either version 2 of the License, or
1113044Sasami   (at your option) any later version.
1213044Sasami
1313044Sasami   This program is distributed in the hope that it will be useful,
1413044Sasami   but WITHOUT ANY WARRANTY; without even the implied warranty of
1513044Sasami   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1613044Sasami   GNU General Public License for more details.
1713044Sasami
1813044Sasami   You should have received a copy of the GNU General Public License
1913044Sasami   along with this program; if not, write to the
2013044Sasami   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
2113044Sasami   Boston, MA 02111-1307, USA.  */
2213044Sasami
2313044Sasami/* This file is based on a preliminary PowerPC ELF ABI.  The
2413044Sasami   information may not match the final PowerPC ELF ABI.  It includes
2513044Sasami   suggestions from the in-progress Embedded PowerPC ABI, and that
2613044Sasami   information may also not match.  */
2713044Sasami
2813044Sasami#include "bfd.h"
2913044Sasami#include "sysdep.h"
3013044Sasami#include "bfdlink.h"
3113044Sasami#include "libbfd.h"
3213044Sasami#include "elf-bfd.h"
3313044Sasami#include "elf/ppc.h"
3413044Sasami#include "elf32-ppc.h"
3536628Scharnier
3636628Scharnier/* RELA relocations are used here.  */
3750476Speter
3836628Scharnierstatic bfd_reloc_status_type ppc_elf_addr16_ha_reloc
3936628Scharnier  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
4013044Sasamistatic bfd_reloc_status_type ppc_elf_unhandled_reloc
4148568Sbillf  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
4213044Sasami
4313044Sasami/* Branch prediction bit for branch taken relocs.  */
4445329Speter#define BRANCH_PREDICT_BIT 0x200000
4513044Sasami/* Mask to set RA in memory instructions.  */
4613044Sasami#define RA_REGISTER_MASK 0x001f0000
4713044Sasami/* Value to shift register by to insert RA.  */
4813044Sasami#define RA_REGISTER_SHIFT 16
4913044Sasami
5013044Sasami/* The name of the dynamic interpreter.  This is put in the .interp
5169793Sobrien   section.  */
5213044Sasami#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
5313044Sasami
5413044Sasami/* The size in bytes of an entry in the procedure linkage table.  */
5513044Sasami#define PLT_ENTRY_SIZE 12
5613044Sasami/* The initial size of the plt reserved for the dynamic linker.  */
5739228Sgibbs#define PLT_INITIAL_ENTRY_SIZE 72
5813052Sasami/* The size of the gap between entries in the PLT.  */
5913044Sasami#define PLT_SLOT_SIZE 8
6013044Sasami/* The number of single-slot PLT entries (the rest use two slots).  */
6113044Sasami#define PLT_NUM_SINGLE_ENTRIES 8192
6213044Sasami
6313044Sasami/* Some nop instructions.  */
6413044Sasami#define NOP		0x60000000
6513044Sasami#define CROR_151515	0x4def7b82
6613044Sasami#define CROR_313131	0x4ffffb82
6713044Sasami
6813044Sasami/* Offset of tp and dtp pointers from start of TLS block.  */
6913044Sasami#define TP_OFFSET	0x7000
7013044Sasami#define DTP_OFFSET	0x8000
7113044Sasami
7213044Sasami
7313044Sasami/* Enumeration to specify the special section.  */
7413044Sasamienum elf_linker_section_enum
7513762Sasami{
7613762Sasami  LINKER_SECTION_SDATA,
7713044Sasami  LINKER_SECTION_SDATA2
7813044Sasami};
7913044Sasami
8013044Sasami/* Sections created by the linker.  */
8113044Sasami
8213044Sasamitypedef struct elf_linker_section
8313044Sasami{
8413044Sasami  /* pointer to the section */
8513044Sasami  asection *section;
8613044Sasami  /* pointer to the relocations needed for this section */
8713044Sasami  asection *rel_section;
8813044Sasami  /* pointer to the created symbol hash value */
8913044Sasami  struct elf_link_hash_entry *sym_hash;
9013044Sasami  /* offset of symbol from beginning of section */
9113044Sasami  bfd_vma sym_offset;
9213044Sasami} elf_linker_section_t;
9313044Sasami
9413044Sasami/* Linked list of allocated pointer entries.  This hangs off of the
9513044Sasami   symbol lists, and provides allows us to return different pointers,
9613044Sasami   based on different addend's.  */
9713044Sasami
9813044Sasamitypedef struct elf_linker_section_pointers
9913044Sasami{
10013044Sasami  /* next allocated pointer for this symbol */
10113044Sasami  struct elf_linker_section_pointers *next;
10213044Sasami  /* offset of pointer from beginning of section */
10313044Sasami  bfd_vma offset;
10413044Sasami  /* addend used */
10513044Sasami  bfd_vma addend;
10613044Sasami  /* which linker section this is */
10713044Sasami  elf_linker_section_t *lsect;
10813044Sasami  /* whether address was written yet */
10913044Sasami  bfd_boolean written_address_p;
11013044Sasami} elf_linker_section_pointers_t;
11113044Sasami
11213044Sasamistruct ppc_elf_obj_tdata
11313044Sasami{
11413044Sasami  struct elf_obj_tdata elf;
11513044Sasami
11613044Sasami  /* A mapping from local symbols to offsets into the various linker
11713044Sasami     sections added.  This is index by the symbol index.  */
11813044Sasami  elf_linker_section_pointers_t **linker_section_pointers;
11913044Sasami};
12013044Sasami
12113044Sasami#define ppc_elf_tdata(bfd) \
12213044Sasami  ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
12313044Sasami
12413044Sasami#define elf_local_ptr_offsets(bfd) \
12513044Sasami  (ppc_elf_tdata (bfd)->linker_section_pointers)
12613044Sasami
12713044Sasami/* Override the generic function because we store some extras.  */
12813044Sasami
12913044Sasamistatic bfd_boolean
13013044Sasamippc_elf_mkobject (bfd *abfd)
13113044Sasami{
13213044Sasami  bfd_size_type amt = sizeof (struct ppc_elf_obj_tdata);
13313044Sasami  abfd->tdata.any = bfd_zalloc (abfd, amt);
13413044Sasami  if (abfd->tdata.any == NULL)
13513044Sasami    return FALSE;
13613044Sasami  return TRUE;
13713044Sasami}
13813044Sasami
13913044Sasami/* The PPC linker needs to keep track of the number of relocs that it
14013044Sasami   decides to copy as dynamic relocs in check_relocs for each symbol.
14113044Sasami   This is so that it can later discard them if they are found to be
14213044Sasami   unnecessary.  We store the information in a field extending the
14313044Sasami   regular ELF linker hash table.  */
14413044Sasami
14513044Sasamistruct ppc_elf_dyn_relocs
14613044Sasami{
14713044Sasami  struct ppc_elf_dyn_relocs *next;
14813044Sasami
14913044Sasami  /* The input section of the reloc.  */
15013044Sasami  asection *sec;
15113044Sasami
15213044Sasami  /* Total number of relocs copied for the input section.  */
15313044Sasami  bfd_size_type count;
15413044Sasami
15513044Sasami  /* Number of pc-relative relocs copied for the input section.  */
15613044Sasami  bfd_size_type pc_count;
15713044Sasami};
15813044Sasami
15913044Sasami/* PPC ELF linker hash entry.  */
16013044Sasami
16113044Sasamistruct ppc_elf_link_hash_entry
16213044Sasami{
16313044Sasami  struct elf_link_hash_entry elf;
16413044Sasami
16532116Simp  /* If this symbol is used in the linker created sections, the processor
16632116Simp     specific backend uses this field to map the field into the offset
16732116Simp     from the beginning of the section.  */
16832116Simp  elf_linker_section_pointers_t *linker_section_pointer;
16932116Simp
17032116Simp  /* Track dynamic relocs copied for this symbol.  */
17132116Simp  struct ppc_elf_dyn_relocs *dyn_relocs;
17232116Simp
17332116Simp  /* Contexts in which symbol is used in the GOT (or TOC).
17445329Speter     TLS_GD .. TLS_TLS bits are or'd into the mask as the
17545329Speter     corresponding relocs are encountered during check_relocs.
17645329Speter     tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
17745329Speter     indicate the corresponding GOT entry type is not needed.  */
17845329Speter#define TLS_GD		 1	/* GD reloc. */
17945329Speter#define TLS_LD		 2	/* LD reloc. */
18013044Sasami#define TLS_TPREL	 4	/* TPREL reloc, => IE. */
18113044Sasami#define TLS_DTPREL	 8	/* DTPREL reloc, => LD. */
18213044Sasami#define TLS_TLS		16	/* Any TLS reloc.  */
18313044Sasami#define TLS_TPRELGD	32	/* TPREL reloc resulting from GD->IE. */
18413044Sasami  char tls_mask;
18513044Sasami};
18613044Sasami
18713044Sasami#define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
18813044Sasami
18913044Sasami/* PPC ELF linker hash table.  */
19013044Sasami
19113044Sasamistruct ppc_elf_link_hash_table
19213044Sasami{
19313044Sasami  struct elf_link_hash_table elf;
19413044Sasami
19513044Sasami  /* Short-cuts to get to dynamic linker sections.  */
19636628Scharnier  asection *got;
19713044Sasami  asection *relgot;
19813044Sasami  asection *plt;
19913044Sasami  asection *relplt;
20013044Sasami  asection *dynbss;
20113044Sasami  asection *relbss;
20213044Sasami  asection *dynsbss;
20313044Sasami  asection *relsbss;
20413044Sasami  elf_linker_section_t *sdata;
20513044Sasami  elf_linker_section_t *sdata2;
20613044Sasami  asection *sbss;
20751690Sbillf
20813044Sasami  /* Shortcut to .__tls_get_addr.  */
20913044Sasami  struct elf_link_hash_entry *tls_get_addr;
21013044Sasami
21113044Sasami  /* TLS local dynamic got entry handling.  */
21213044Sasami  union {
21313044Sasami    bfd_signed_vma refcount;
21413044Sasami    bfd_vma offset;
21513044Sasami  } tlsld_got;
21613044Sasami
21713044Sasami  /* Small local sym to section mapping cache.  */
21813044Sasami  struct sym_sec_cache sym_sec;
21913044Sasami};
22013044Sasami
22113044Sasami/* Get the PPC ELF linker hash table from a link_info structure.  */
22213044Sasami
22313044Sasami#define ppc_elf_hash_table(p) \
22413044Sasami  ((struct ppc_elf_link_hash_table *) (p)->hash)
22513044Sasami
22613044Sasami/* Create an entry in a PPC ELF linker hash table.  */
22713044Sasami
22813044Sasamistatic struct bfd_hash_entry *
22913044Sasamippc_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
23013044Sasami			   struct bfd_hash_table *table,
23113044Sasami			   const char *string)
23248568Sbillf{
23313044Sasami  /* Allocate the structure if it has not already been allocated by a
23413044Sasami     subclass.  */
23513044Sasami  if (entry == NULL)
23613044Sasami    {
23713044Sasami      entry = bfd_hash_allocate (table,
23813044Sasami				 sizeof (struct ppc_elf_link_hash_entry));
23913044Sasami      if (entry == NULL)
24013044Sasami	return entry;
24113044Sasami    }
24213044Sasami
24348568Sbillf  /* Call the allocation method of the superclass.  */
24413044Sasami  entry = _bfd_elf_link_hash_newfunc (entry, table, string);
24513044Sasami  if (entry != NULL)
24613044Sasami    {
24713044Sasami      ppc_elf_hash_entry (entry)->linker_section_pointer = NULL;
24813044Sasami      ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
24913044Sasami      ppc_elf_hash_entry (entry)->tls_mask = 0;
25013044Sasami    }
25113044Sasami
25213044Sasami  return entry;
25313044Sasami}
25413044Sasami
25513044Sasami/* Create a PPC ELF linker hash table.  */
25613044Sasami
25713044Sasamistatic struct bfd_link_hash_table *
25813044Sasamippc_elf_link_hash_table_create (bfd *abfd)
25913044Sasami{
26013044Sasami  struct ppc_elf_link_hash_table *ret;
26113044Sasami
26213044Sasami  ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
26313044Sasami  if (ret == NULL)
26413044Sasami    return NULL;
26513044Sasami
26613044Sasami  if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
26713044Sasami				       ppc_elf_link_hash_newfunc))
26813044Sasami    {
26913044Sasami      free (ret);
27013044Sasami      return NULL;
27113044Sasami    }
27213044Sasami
27313044Sasami  return &ret->elf.root;
27413044Sasami}
27513044Sasami
27613044Sasami/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
27713044Sasami   copying dynamic variables from a shared lib into an app's dynbss
27813044Sasami   section, and instead use a dynamic relocation to point into the
27913044Sasami   shared lib.  */
28013044Sasami#define ELIMINATE_COPY_RELOCS 1
28113044Sasami
28213044Sasami/* Copy the extra info we tack onto an elf_link_hash_entry.  */
28313044Sasami
28413044Sasamistatic void
28513044Sasamippc_elf_copy_indirect_symbol (const struct elf_backend_data *bed,
28613044Sasami			      struct elf_link_hash_entry *dir,
28713044Sasami			      struct elf_link_hash_entry *ind)
28813044Sasami{
28913044Sasami  struct ppc_elf_link_hash_entry *edir, *eind;
29013044Sasami
29113044Sasami  edir = (struct ppc_elf_link_hash_entry *) dir;
29213044Sasami  eind = (struct ppc_elf_link_hash_entry *) ind;
29313044Sasami
29413044Sasami  if (eind->dyn_relocs != NULL)
29513044Sasami    {
29613044Sasami      if (edir->dyn_relocs != NULL)
29713044Sasami	{
29813044Sasami	  struct ppc_elf_dyn_relocs **pp;
29913044Sasami	  struct ppc_elf_dyn_relocs *p;
30013044Sasami
30113044Sasami	  if (ind->root.type == bfd_link_hash_indirect)
30213044Sasami	    abort ();
30313044Sasami
30413044Sasami	  /* Add reloc counts against the weak sym to the strong sym
30513044Sasami	     list.  Merge any entries against the same section.  */
30613044Sasami	  for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
30713044Sasami	    {
30813044Sasami	      struct ppc_elf_dyn_relocs *q;
30948568Sbillf
31013044Sasami	      for (q = edir->dyn_relocs; q != NULL; q = q->next)
31113044Sasami		if (q->sec == p->sec)
31213044Sasami		  {
31313044Sasami		    q->pc_count += p->pc_count;
31413044Sasami		    q->count += p->count;
31513044Sasami		    *pp = p->next;
31613044Sasami		    break;
31713044Sasami		  }
31813044Sasami	      if (q == NULL)
31913044Sasami		pp = &p->next;
32013044Sasami	    }
32113044Sasami	  *pp = edir->dyn_relocs;
32213044Sasami	}
32313044Sasami
32413044Sasami      edir->dyn_relocs = eind->dyn_relocs;
32513044Sasami      eind->dyn_relocs = NULL;
32613044Sasami    }
32713044Sasami
32832116Simp  edir->tls_mask |= eind->tls_mask;
32913044Sasami
33051690Sbillf  if (ELIMINATE_COPY_RELOCS
33132116Simp      && ind->root.type != bfd_link_hash_indirect
33232116Simp      && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
33313044Sasami    /* If called to transfer flags for a weakdef during processing
33432116Simp       of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
33513044Sasami       We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
33613044Sasami    dir->elf_link_hash_flags |=
33713044Sasami      (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
33832116Simp				   | ELF_LINK_HASH_REF_REGULAR
33913044Sasami				   | ELF_LINK_HASH_REF_REGULAR_NONWEAK
34013044Sasami				   | ELF_LINK_HASH_NEEDS_PLT));
34113044Sasami  else
34213044Sasami    _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
34313044Sasami}
34413044Sasami
34513044Sasamistatic reloc_howto_type *ppc_elf_howto_table[R_PPC_max];
34613044Sasami
34713044Sasamistatic reloc_howto_type ppc_elf_howto_raw[] = {
34813044Sasami  /* This reloc does nothing.  */
34913044Sasami  HOWTO (R_PPC_NONE,		/* type */
35013044Sasami	 0,			/* rightshift */
35113044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
35213044Sasami	 32,			/* bitsize */
35313044Sasami	 FALSE,			/* pc_relative */
35413044Sasami	 0,			/* bitpos */
35513044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
35613044Sasami	 bfd_elf_generic_reloc,	/* special_function */
35713044Sasami	 "R_PPC_NONE",		/* name */
35813044Sasami	 FALSE,			/* partial_inplace */
35913044Sasami	 0,			/* src_mask */
36013044Sasami	 0,			/* dst_mask */
36113044Sasami	 FALSE),		/* pcrel_offset */
36213044Sasami
36313044Sasami  /* A standard 32 bit relocation.  */
36413044Sasami  HOWTO (R_PPC_ADDR32,		/* type */
36513044Sasami	 0,			/* rightshift */
36613044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
36713044Sasami	 32,			/* bitsize */
36813044Sasami	 FALSE,			/* pc_relative */
36913044Sasami	 0,			/* bitpos */
37013044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
37113044Sasami	 bfd_elf_generic_reloc,	/* special_function */
37213044Sasami	 "R_PPC_ADDR32",	/* name */
37313044Sasami	 FALSE,			/* partial_inplace */
37413044Sasami	 0,			/* src_mask */
37513044Sasami	 0xffffffff,		/* dst_mask */
37613044Sasami	 FALSE),		/* pcrel_offset */
37713044Sasami
37813044Sasami  /* An absolute 26 bit branch; the lower two bits must be zero.
37913044Sasami     FIXME: we don't check that, we just clear them.  */
38013044Sasami  HOWTO (R_PPC_ADDR24,		/* type */
38113044Sasami	 0,			/* rightshift */
38213044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
38313044Sasami	 26,			/* bitsize */
38413044Sasami	 FALSE,			/* pc_relative */
38513044Sasami	 0,			/* bitpos */
38613044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
38713044Sasami	 bfd_elf_generic_reloc,	/* special_function */
38813044Sasami	 "R_PPC_ADDR24",	/* name */
38913044Sasami	 FALSE,			/* partial_inplace */
39013044Sasami	 0,			/* src_mask */
39113044Sasami	 0x3fffffc,		/* dst_mask */
39213044Sasami	 FALSE),		/* pcrel_offset */
39313044Sasami
39413044Sasami  /* A standard 16 bit relocation.  */
39513044Sasami  HOWTO (R_PPC_ADDR16,		/* type */
39613044Sasami	 0,			/* rightshift */
39713044Sasami	 1,			/* size (0 = byte, 1 = short, 2 = long) */
39813044Sasami	 16,			/* bitsize */
39913044Sasami	 FALSE,			/* pc_relative */
40013044Sasami	 0,			/* bitpos */
40113044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
40213044Sasami	 bfd_elf_generic_reloc,	/* special_function */
40313044Sasami	 "R_PPC_ADDR16",	/* name */
40413044Sasami	 FALSE,			/* partial_inplace */
40513044Sasami	 0,			/* src_mask */
40613044Sasami	 0xffff,		/* dst_mask */
40713044Sasami	 FALSE),		/* pcrel_offset */
40813044Sasami
40913044Sasami  /* A 16 bit relocation without overflow.  */
41013044Sasami  HOWTO (R_PPC_ADDR16_LO,	/* type */
41113044Sasami	 0,			/* rightshift */
41213044Sasami	 1,			/* size (0 = byte, 1 = short, 2 = long) */
41313044Sasami	 16,			/* bitsize */
41413044Sasami	 FALSE,			/* pc_relative */
41513044Sasami	 0,			/* bitpos */
41613044Sasami	 complain_overflow_dont,/* complain_on_overflow */
41713044Sasami	 bfd_elf_generic_reloc,	/* special_function */
41813044Sasami	 "R_PPC_ADDR16_LO",	/* name */
41913044Sasami	 FALSE,			/* partial_inplace */
42013044Sasami	 0,			/* src_mask */
42113044Sasami	 0xffff,		/* dst_mask */
42213044Sasami	 FALSE),		/* pcrel_offset */
42313044Sasami
42413044Sasami  /* The high order 16 bits of an address.  */
42513044Sasami  HOWTO (R_PPC_ADDR16_HI,	/* type */
42636628Scharnier	 16,			/* rightshift */
42713044Sasami	 1,			/* size (0 = byte, 1 = short, 2 = long) */
42813044Sasami	 16,			/* bitsize */
42913044Sasami	 FALSE,			/* pc_relative */
43013044Sasami	 0,			/* bitpos */
43113044Sasami	 complain_overflow_dont, /* complain_on_overflow */
43213044Sasami	 bfd_elf_generic_reloc,	/* special_function */
43313044Sasami	 "R_PPC_ADDR16_HI",	/* name */
43413044Sasami	 FALSE,			/* partial_inplace */
43513044Sasami	 0,			/* src_mask */
43613044Sasami	 0xffff,		/* dst_mask */
43713044Sasami	 FALSE),		/* pcrel_offset */
43813044Sasami
43913044Sasami  /* The high order 16 bits of an address, plus 1 if the contents of
44013044Sasami     the low 16 bits, treated as a signed number, is negative.  */
44113044Sasami  HOWTO (R_PPC_ADDR16_HA,	/* type */
44213044Sasami	 16,			/* rightshift */
44313044Sasami	 1,			/* size (0 = byte, 1 = short, 2 = long) */
44413044Sasami	 16,			/* bitsize */
44513044Sasami	 FALSE,			/* pc_relative */
44613044Sasami	 0,			/* bitpos */
44713044Sasami	 complain_overflow_dont, /* complain_on_overflow */
44869793Sobrien	 ppc_elf_addr16_ha_reloc, /* special_function */
44913044Sasami	 "R_PPC_ADDR16_HA",	/* name */
45069793Sobrien	 FALSE,			/* partial_inplace */
45113044Sasami	 0,			/* src_mask */
45213044Sasami	 0xffff,		/* dst_mask */
45313044Sasami	 FALSE),		/* pcrel_offset */
45413044Sasami
45513044Sasami  /* An absolute 16 bit branch; the lower two bits must be zero.
45613044Sasami     FIXME: we don't check that, we just clear them.  */
45713044Sasami  HOWTO (R_PPC_ADDR14,		/* type */
45813044Sasami	 0,			/* rightshift */
45913044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
46013044Sasami	 16,			/* bitsize */
46113044Sasami	 FALSE,			/* pc_relative */
46213044Sasami	 0,			/* bitpos */
46313044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
46413044Sasami	 bfd_elf_generic_reloc,	/* special_function */
46513044Sasami	 "R_PPC_ADDR14",	/* name */
46613044Sasami	 FALSE,			/* partial_inplace */
46713044Sasami	 0,			/* src_mask */
46813044Sasami	 0xfffc,		/* dst_mask */
46913044Sasami	 FALSE),		/* pcrel_offset */
47013044Sasami
47113044Sasami  /* An absolute 16 bit branch, for which bit 10 should be set to
47213044Sasami     indicate that the branch is expected to be taken.	The lower two
47313044Sasami     bits must be zero.  */
47413044Sasami  HOWTO (R_PPC_ADDR14_BRTAKEN,	/* type */
47513044Sasami	 0,			/* rightshift */
47613044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
47713044Sasami	 16,			/* bitsize */
47813044Sasami	 FALSE,			/* pc_relative */
47913044Sasami	 0,			/* bitpos */
48013044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
48113044Sasami	 bfd_elf_generic_reloc,	/* special_function */
48213044Sasami	 "R_PPC_ADDR14_BRTAKEN",/* name */
48313044Sasami	 FALSE,			/* partial_inplace */
48413044Sasami	 0,			/* src_mask */
48513044Sasami	 0xfffc,		/* dst_mask */
48613044Sasami	 FALSE),		/* pcrel_offset */
48713044Sasami
48813044Sasami  /* An absolute 16 bit branch, for which bit 10 should be set to
48913044Sasami     indicate that the branch is not expected to be taken.  The lower
49013044Sasami     two bits must be zero.  */
49164275Skris  HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
49264275Skris	 0,			/* rightshift */
49313044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
49413044Sasami	 16,			/* bitsize */
49513044Sasami	 FALSE,			/* pc_relative */
49613044Sasami	 0,			/* bitpos */
49713044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
49813044Sasami	 bfd_elf_generic_reloc,	/* special_function */
49913044Sasami	 "R_PPC_ADDR14_BRNTAKEN",/* name */
50013044Sasami	 FALSE,			/* partial_inplace */
50113044Sasami	 0,			/* src_mask */
50213044Sasami	 0xfffc,		/* dst_mask */
50313044Sasami	 FALSE),		/* pcrel_offset */
50413044Sasami
50513044Sasami  /* A relative 26 bit branch; the lower two bits must be zero.  */
50613044Sasami  HOWTO (R_PPC_REL24,		/* type */
50713044Sasami	 0,			/* rightshift */
50813044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
50913044Sasami	 26,			/* bitsize */
51013044Sasami	 TRUE,			/* pc_relative */
51113044Sasami	 0,			/* bitpos */
51213044Sasami	 complain_overflow_signed, /* complain_on_overflow */
51313044Sasami	 bfd_elf_generic_reloc,	/* special_function */
51413044Sasami	 "R_PPC_REL24",		/* name */
51513044Sasami	 FALSE,			/* partial_inplace */
51613044Sasami	 0,			/* src_mask */
51713044Sasami	 0x3fffffc,		/* dst_mask */
51813044Sasami	 TRUE),			/* pcrel_offset */
51913044Sasami
52013044Sasami  /* A relative 16 bit branch; the lower two bits must be zero.  */
52113044Sasami  HOWTO (R_PPC_REL14,		/* type */
52213044Sasami	 0,			/* rightshift */
52313044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
52413044Sasami	 16,			/* bitsize */
52513044Sasami	 TRUE,			/* pc_relative */
52613044Sasami	 0,			/* bitpos */
52713044Sasami	 complain_overflow_signed, /* complain_on_overflow */
52813044Sasami	 bfd_elf_generic_reloc,	/* special_function */
52913044Sasami	 "R_PPC_REL14",		/* name */
53013044Sasami	 FALSE,			/* partial_inplace */
53113044Sasami	 0,			/* src_mask */
53213044Sasami	 0xfffc,		/* dst_mask */
53313044Sasami	 TRUE),			/* pcrel_offset */
53413044Sasami
53513044Sasami  /* A relative 16 bit branch.  Bit 10 should be set to indicate that
53613044Sasami     the branch is expected to be taken.  The lower two bits must be
53713044Sasami     zero.  */
53813044Sasami  HOWTO (R_PPC_REL14_BRTAKEN,	/* type */
53913044Sasami	 0,			/* rightshift */
54013044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
54113044Sasami	 16,			/* bitsize */
54213044Sasami	 TRUE,			/* pc_relative */
54313044Sasami	 0,			/* bitpos */
54413044Sasami	 complain_overflow_signed, /* complain_on_overflow */
54513044Sasami	 bfd_elf_generic_reloc,	/* special_function */
54613044Sasami	 "R_PPC_REL14_BRTAKEN",	/* name */
54713044Sasami	 FALSE,			/* partial_inplace */
54813044Sasami	 0,			/* src_mask */
54913044Sasami	 0xfffc,		/* dst_mask */
55013044Sasami	 TRUE),			/* pcrel_offset */
55113044Sasami
55213044Sasami  /* A relative 16 bit branch.  Bit 10 should be set to indicate that
55313044Sasami     the branch is not expected to be taken.  The lower two bits must
55413044Sasami     be zero.  */
55513044Sasami  HOWTO (R_PPC_REL14_BRNTAKEN,	/* type */
55613044Sasami	 0,			/* rightshift */
55713044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
55813044Sasami	 16,			/* bitsize */
55913044Sasami	 TRUE,			/* pc_relative */
56013044Sasami	 0,			/* bitpos */
56113044Sasami	 complain_overflow_signed, /* complain_on_overflow */
56213044Sasami	 bfd_elf_generic_reloc,	/* special_function */
56313044Sasami	 "R_PPC_REL14_BRNTAKEN",/* name */
56413044Sasami	 FALSE,			/* partial_inplace */
56513044Sasami	 0,			/* src_mask */
56613044Sasami	 0xfffc,		/* dst_mask */
56713044Sasami	 TRUE),			/* pcrel_offset */
56813044Sasami
56913044Sasami  /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
57013044Sasami     symbol.  */
57113044Sasami  HOWTO (R_PPC_GOT16,		/* type */
57213044Sasami	 0,			/* rightshift */
57313044Sasami	 1,			/* size (0 = byte, 1 = short, 2 = long) */
57413044Sasami	 16,			/* bitsize */
57513044Sasami	 FALSE,			/* pc_relative */
57613044Sasami	 0,			/* bitpos */
57713044Sasami	 complain_overflow_signed, /* complain_on_overflow */
57813044Sasami	 bfd_elf_generic_reloc,	/* special_function */
57913044Sasami	 "R_PPC_GOT16",		/* name */
58013044Sasami	 FALSE,			/* partial_inplace */
58113044Sasami	 0,			/* src_mask */
58213044Sasami	 0xffff,		/* dst_mask */
58313044Sasami	 FALSE),		/* pcrel_offset */
58413044Sasami
58513044Sasami  /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
58613044Sasami     the symbol.  */
58713044Sasami  HOWTO (R_PPC_GOT16_LO,	/* type */
58813044Sasami	 0,			/* rightshift */
58913044Sasami	 1,			/* size (0 = byte, 1 = short, 2 = long) */
59013044Sasami	 16,			/* bitsize */
59113044Sasami	 FALSE,			/* pc_relative */
59213044Sasami	 0,			/* bitpos */
59313044Sasami	 complain_overflow_dont, /* complain_on_overflow */
59413044Sasami	 bfd_elf_generic_reloc,	/* special_function */
59513044Sasami	 "R_PPC_GOT16_LO",	/* name */
59613044Sasami	 FALSE,			/* partial_inplace */
59713044Sasami	 0,			/* src_mask */
59813044Sasami	 0xffff,		/* dst_mask */
59913044Sasami	 FALSE),		/* pcrel_offset */
60013044Sasami
60113044Sasami  /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
60213044Sasami     the symbol.  */
60313044Sasami  HOWTO (R_PPC_GOT16_HI,	/* type */
60413044Sasami	 16,			/* rightshift */
60513044Sasami	 1,			/* size (0 = byte, 1 = short, 2 = long) */
60613044Sasami	 16,			/* bitsize */
60713044Sasami	 FALSE,			/* pc_relative */
60813044Sasami	 0,			/* bitpos */
60913044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
61013044Sasami	 bfd_elf_generic_reloc,	/* special_function */
61113044Sasami	 "R_PPC_GOT16_HI",	/* name */
61213044Sasami	 FALSE,			/* partial_inplace */
61313044Sasami	 0,			/* src_mask */
61413044Sasami	 0xffff,		/* dst_mask */
61513044Sasami	 FALSE),		 /* pcrel_offset */
61613044Sasami
61713044Sasami  /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
61813044Sasami     the symbol.  */
61913044Sasami  HOWTO (R_PPC_GOT16_HA,	/* type */
62013044Sasami	 16,			/* rightshift */
62113044Sasami	 1,			/* size (0 = byte, 1 = short, 2 = long) */
62213044Sasami	 16,			/* bitsize */
62313044Sasami	 FALSE,			/* pc_relative */
62413044Sasami	 0,			/* bitpos */
62513044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
62664275Skris	 ppc_elf_addr16_ha_reloc, /* special_function */
62713044Sasami	 "R_PPC_GOT16_HA",	/* name */
62813044Sasami	 FALSE,			/* partial_inplace */
62913044Sasami	 0,			/* src_mask */
63013044Sasami	 0xffff,		/* dst_mask */
63113044Sasami	 FALSE),		/* pcrel_offset */
63213044Sasami
63313044Sasami  /* Like R_PPC_REL24, but referring to the procedure linkage table
63413044Sasami     entry for the symbol.  */
63513044Sasami  HOWTO (R_PPC_PLTREL24,	/* type */
63664282Salex	 0,			/* rightshift */
63713044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
63813044Sasami	 26,			/* bitsize */
63913044Sasami	 TRUE,			/* pc_relative */
64013044Sasami	 0,			/* bitpos */
64113044Sasami	 complain_overflow_signed,  /* complain_on_overflow */
64213044Sasami	 bfd_elf_generic_reloc,	/* special_function */
64313044Sasami	 "R_PPC_PLTREL24",	/* name */
64413044Sasami	 FALSE,			/* partial_inplace */
64513044Sasami	 0,			/* src_mask */
64613044Sasami	 0x3fffffc,		/* dst_mask */
64713044Sasami	 TRUE),			/* pcrel_offset */
64813044Sasami
64913044Sasami  /* This is used only by the dynamic linker.  The symbol should exist
65013052Sasami     both in the object being run and in some shared library.  The
65113044Sasami     dynamic linker copies the data addressed by the symbol from the
65213044Sasami     shared library into the object, because the object being
65313044Sasami     run has to have the data at some particular address.  */
65413044Sasami  HOWTO (R_PPC_COPY,		/* type */
65513044Sasami	 0,			/* rightshift */
65613052Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
65713044Sasami	 32,			/* bitsize */
65813044Sasami	 FALSE,			/* pc_relative */
65913044Sasami	 0,			/* bitpos */
66013044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
66113044Sasami	 bfd_elf_generic_reloc,	 /* special_function */
66213044Sasami	 "R_PPC_COPY",		/* name */
66313044Sasami	 FALSE,			/* partial_inplace */
66413044Sasami	 0,			/* src_mask */
66513044Sasami	 0,			/* dst_mask */
66613044Sasami	 FALSE),		/* pcrel_offset */
66713044Sasami
66813044Sasami  /* Like R_PPC_ADDR32, but used when setting global offset table
66913044Sasami     entries.  */
67013044Sasami  HOWTO (R_PPC_GLOB_DAT,	/* type */
67113044Sasami	 0,			/* rightshift */
67213044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
67313044Sasami	 32,			/* bitsize */
67413044Sasami	 FALSE,			/* pc_relative */
67513044Sasami	 0,			/* bitpos */
67613044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
67713044Sasami	 bfd_elf_generic_reloc,	 /* special_function */
67813044Sasami	 "R_PPC_GLOB_DAT",	/* name */
67913044Sasami	 FALSE,			/* partial_inplace */
68013044Sasami	 0,			/* src_mask */
68113044Sasami	 0xffffffff,		/* dst_mask */
68213044Sasami	 FALSE),		/* pcrel_offset */
68313044Sasami
68413044Sasami  /* Marks a procedure linkage table entry for a symbol.  */
68513044Sasami  HOWTO (R_PPC_JMP_SLOT,	/* type */
68613044Sasami	 0,			/* rightshift */
68713044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
68813044Sasami	 32,			/* bitsize */
68913044Sasami	 FALSE,			/* pc_relative */
69013044Sasami	 0,			/* bitpos */
69113044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
69213044Sasami	 bfd_elf_generic_reloc,	 /* special_function */
69313044Sasami	 "R_PPC_JMP_SLOT",	/* name */
69413044Sasami	 FALSE,			/* partial_inplace */
69513044Sasami	 0,			/* src_mask */
69613044Sasami	 0,			/* dst_mask */
69713044Sasami	 FALSE),		/* pcrel_offset */
69813044Sasami
69913044Sasami  /* Used only by the dynamic linker.  When the object is run, this
70013044Sasami     longword is set to the load address of the object, plus the
70113044Sasami     addend.  */
70213044Sasami  HOWTO (R_PPC_RELATIVE,	/* type */
70313044Sasami	 0,			/* rightshift */
70413044Sasami	 2,			/* size (0 = byte, 1 = short, 2 = long) */
70513044Sasami	 32,			/* bitsize */
70613044Sasami	 FALSE,			/* pc_relative */
70713044Sasami	 0,			/* bitpos */
70813044Sasami	 complain_overflow_bitfield, /* complain_on_overflow */
70913044Sasami	 bfd_elf_generic_reloc,	 /* special_function */
71013044Sasami	 "R_PPC_RELATIVE",	/* name */
71113044Sasami	 FALSE,			/* partial_inplace */
71213044Sasami	 0,			/* src_mask */
71313044Sasami	 0xffffffff,		/* dst_mask */
71413044Sasami	 FALSE),		/* pcrel_offset */
71513044Sasami
71613044Sasami  /* Like R_PPC_REL24, but uses the value of the symbol within the
71713044Sasami     object rather than the final value.  Normally used for
71813044Sasami     _GLOBAL_OFFSET_TABLE_.  */
71913044Sasami  HOWTO (R_PPC_LOCAL24PC,	/* type */
72013044Sasami	 0,			/* rightshift */
72126541Scharnier	 2,			/* size (0 = byte, 1 = short, 2 = long) */
72226541Scharnier	 26,			/* bitsize */
72326541Scharnier	 TRUE,			/* pc_relative */
72426541Scharnier	 0,			/* bitpos */
72526541Scharnier	 complain_overflow_signed, /* complain_on_overflow */
72626541Scharnier	 bfd_elf_generic_reloc,	/* special_function */
72713044Sasami	 "R_PPC_LOCAL24PC",	/* name */
72813044Sasami	 FALSE,			/* partial_inplace */
72926541Scharnier	 0,			/* src_mask */
73013052Sasami	 0x3fffffc,		/* dst_mask */
73113052Sasami	 TRUE),			/* pcrel_offset */
73213052Sasami
73313052Sasami  /* Like R_PPC_ADDR32, but may be unaligned.  */
734  HOWTO (R_PPC_UADDR32,		/* type */
735	 0,			/* rightshift */
736	 2,			/* size (0 = byte, 1 = short, 2 = long) */
737	 32,			/* bitsize */
738	 FALSE,			/* pc_relative */
739	 0,			/* bitpos */
740	 complain_overflow_bitfield, /* complain_on_overflow */
741	 bfd_elf_generic_reloc,	/* special_function */
742	 "R_PPC_UADDR32",	/* name */
743	 FALSE,			/* partial_inplace */
744	 0,			/* src_mask */
745	 0xffffffff,		/* dst_mask */
746	 FALSE),		/* pcrel_offset */
747
748  /* Like R_PPC_ADDR16, but may be unaligned.  */
749  HOWTO (R_PPC_UADDR16,		/* type */
750	 0,			/* rightshift */
751	 1,			/* size (0 = byte, 1 = short, 2 = long) */
752	 16,			/* bitsize */
753	 FALSE,			/* pc_relative */
754	 0,			/* bitpos */
755	 complain_overflow_bitfield, /* complain_on_overflow */
756	 bfd_elf_generic_reloc,	/* special_function */
757	 "R_PPC_UADDR16",	/* name */
758	 FALSE,			/* partial_inplace */
759	 0,			/* src_mask */
760	 0xffff,		/* dst_mask */
761	 FALSE),		/* pcrel_offset */
762
763  /* 32-bit PC relative */
764  HOWTO (R_PPC_REL32,		/* type */
765	 0,			/* rightshift */
766	 2,			/* size (0 = byte, 1 = short, 2 = long) */
767	 32,			/* bitsize */
768	 TRUE,			/* pc_relative */
769	 0,			/* bitpos */
770	 complain_overflow_bitfield, /* complain_on_overflow */
771	 bfd_elf_generic_reloc,	/* special_function */
772	 "R_PPC_REL32",		/* name */
773	 FALSE,			/* partial_inplace */
774	 0,			/* src_mask */
775	 0xffffffff,		/* dst_mask */
776	 TRUE),			/* pcrel_offset */
777
778  /* 32-bit relocation to the symbol's procedure linkage table.
779     FIXME: not supported.  */
780  HOWTO (R_PPC_PLT32,		/* type */
781	 0,			/* rightshift */
782	 2,			/* size (0 = byte, 1 = short, 2 = long) */
783	 32,			/* bitsize */
784	 FALSE,			/* pc_relative */
785	 0,			/* bitpos */
786	 complain_overflow_bitfield, /* complain_on_overflow */
787	 bfd_elf_generic_reloc,	/* special_function */
788	 "R_PPC_PLT32",		/* name */
789	 FALSE,			/* partial_inplace */
790	 0,			/* src_mask */
791	 0,			/* dst_mask */
792	 FALSE),		/* pcrel_offset */
793
794  /* 32-bit PC relative relocation to the symbol's procedure linkage table.
795     FIXME: not supported.  */
796  HOWTO (R_PPC_PLTREL32,	/* type */
797	 0,			/* rightshift */
798	 2,			/* size (0 = byte, 1 = short, 2 = long) */
799	 32,			/* bitsize */
800	 TRUE,			/* pc_relative */
801	 0,			/* bitpos */
802	 complain_overflow_bitfield, /* complain_on_overflow */
803	 bfd_elf_generic_reloc,	/* special_function */
804	 "R_PPC_PLTREL32",	/* name */
805	 FALSE,			/* partial_inplace */
806	 0,			/* src_mask */
807	 0,			/* dst_mask */
808	 TRUE),			/* pcrel_offset */
809
810  /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
811     the symbol.  */
812  HOWTO (R_PPC_PLT16_LO,	/* type */
813	 0,			/* rightshift */
814	 1,			/* size (0 = byte, 1 = short, 2 = long) */
815	 16,			/* bitsize */
816	 FALSE,			/* pc_relative */
817	 0,			/* bitpos */
818	 complain_overflow_dont, /* complain_on_overflow */
819	 bfd_elf_generic_reloc,	/* special_function */
820	 "R_PPC_PLT16_LO",	/* name */
821	 FALSE,			/* partial_inplace */
822	 0,			/* src_mask */
823	 0xffff,		/* dst_mask */
824	 FALSE),		/* pcrel_offset */
825
826  /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
827     the symbol.  */
828  HOWTO (R_PPC_PLT16_HI,	/* type */
829	 16,			/* rightshift */
830	 1,			/* size (0 = byte, 1 = short, 2 = long) */
831	 16,			/* bitsize */
832	 FALSE,			/* pc_relative */
833	 0,			/* bitpos */
834	 complain_overflow_bitfield, /* complain_on_overflow */
835	 bfd_elf_generic_reloc,	/* special_function */
836	 "R_PPC_PLT16_HI",	/* name */
837	 FALSE,			/* partial_inplace */
838	 0,			/* src_mask */
839	 0xffff,		/* dst_mask */
840	 FALSE),		 /* pcrel_offset */
841
842  /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
843     the symbol.  */
844  HOWTO (R_PPC_PLT16_HA,	/* type */
845	 16,			/* rightshift */
846	 1,			/* size (0 = byte, 1 = short, 2 = long) */
847	 16,			/* bitsize */
848	 FALSE,			/* pc_relative */
849	 0,			/* bitpos */
850	 complain_overflow_bitfield, /* complain_on_overflow */
851	 ppc_elf_addr16_ha_reloc, /* special_function */
852	 "R_PPC_PLT16_HA",	/* name */
853	 FALSE,			/* partial_inplace */
854	 0,			/* src_mask */
855	 0xffff,		/* dst_mask */
856	 FALSE),		/* pcrel_offset */
857
858  /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
859     small data items.  */
860  HOWTO (R_PPC_SDAREL16,	/* type */
861	 0,			/* rightshift */
862	 1,			/* size (0 = byte, 1 = short, 2 = long) */
863	 16,			/* bitsize */
864	 FALSE,			/* pc_relative */
865	 0,			/* bitpos */
866	 complain_overflow_signed, /* complain_on_overflow */
867	 bfd_elf_generic_reloc,	/* special_function */
868	 "R_PPC_SDAREL16",	/* name */
869	 FALSE,			/* partial_inplace */
870	 0,			/* src_mask */
871	 0xffff,		/* dst_mask */
872	 FALSE),		/* pcrel_offset */
873
874  /* 16-bit section relative relocation.  */
875  HOWTO (R_PPC_SECTOFF,		/* type */
876	 0,			/* rightshift */
877	 1,			/* size (0 = byte, 1 = short, 2 = long) */
878	 16,			/* bitsize */
879	 FALSE,			/* pc_relative */
880	 0,			/* bitpos */
881	 complain_overflow_bitfield, /* complain_on_overflow */
882	 bfd_elf_generic_reloc,	/* special_function */
883	 "R_PPC_SECTOFF",	/* name */
884	 FALSE,			/* partial_inplace */
885	 0,			/* src_mask */
886	 0xffff,		/* dst_mask */
887	 FALSE),		/* pcrel_offset */
888
889  /* 16-bit lower half section relative relocation.  */
890  HOWTO (R_PPC_SECTOFF_LO,	  /* type */
891	 0,			/* rightshift */
892	 1,			/* size (0 = byte, 1 = short, 2 = long) */
893	 16,			/* bitsize */
894	 FALSE,			/* pc_relative */
895	 0,			/* bitpos */
896	 complain_overflow_dont, /* complain_on_overflow */
897	 bfd_elf_generic_reloc,	/* special_function */
898	 "R_PPC_SECTOFF_LO",	/* name */
899	 FALSE,			/* partial_inplace */
900	 0,			/* src_mask */
901	 0xffff,		/* dst_mask */
902	 FALSE),		/* pcrel_offset */
903
904  /* 16-bit upper half section relative relocation.  */
905  HOWTO (R_PPC_SECTOFF_HI,	/* type */
906	 16,			/* rightshift */
907	 1,			/* size (0 = byte, 1 = short, 2 = long) */
908	 16,			/* bitsize */
909	 FALSE,			/* pc_relative */
910	 0,			/* bitpos */
911	 complain_overflow_bitfield, /* complain_on_overflow */
912	 bfd_elf_generic_reloc,	/* special_function */
913	 "R_PPC_SECTOFF_HI",	/* name */
914	 FALSE,			/* partial_inplace */
915	 0,			/* src_mask */
916	 0xffff,		/* dst_mask */
917	 FALSE),		 /* pcrel_offset */
918
919  /* 16-bit upper half adjusted section relative relocation.  */
920  HOWTO (R_PPC_SECTOFF_HA,	/* type */
921	 16,			/* rightshift */
922	 1,			/* size (0 = byte, 1 = short, 2 = long) */
923	 16,			/* bitsize */
924	 FALSE,			/* pc_relative */
925	 0,			/* bitpos */
926	 complain_overflow_bitfield, /* complain_on_overflow */
927	 ppc_elf_addr16_ha_reloc, /* special_function */
928	 "R_PPC_SECTOFF_HA",	/* name */
929	 FALSE,			/* partial_inplace */
930	 0,			/* src_mask */
931	 0xffff,		/* dst_mask */
932	 FALSE),		/* pcrel_offset */
933
934  /* Marker reloc for TLS.  */
935  HOWTO (R_PPC_TLS,
936	 0,			/* rightshift */
937	 2,			/* size (0 = byte, 1 = short, 2 = long) */
938	 32,			/* bitsize */
939	 FALSE,			/* pc_relative */
940	 0,			/* bitpos */
941	 complain_overflow_dont, /* complain_on_overflow */
942	 bfd_elf_generic_reloc,	/* special_function */
943	 "R_PPC_TLS",		/* name */
944	 FALSE,			/* partial_inplace */
945	 0,			/* src_mask */
946	 0,			/* dst_mask */
947	 FALSE),		/* pcrel_offset */
948
949  /* Computes the load module index of the load module that contains the
950     definition of its TLS sym.  */
951  HOWTO (R_PPC_DTPMOD32,
952	 0,			/* rightshift */
953	 2,			/* size (0 = byte, 1 = short, 2 = long) */
954	 32,			/* bitsize */
955	 FALSE,			/* pc_relative */
956	 0,			/* bitpos */
957	 complain_overflow_dont, /* complain_on_overflow */
958	 ppc_elf_unhandled_reloc, /* special_function */
959	 "R_PPC_DTPMOD32",	/* name */
960	 FALSE,			/* partial_inplace */
961	 0,			/* src_mask */
962	 0xffffffff,		/* dst_mask */
963	 FALSE),		/* pcrel_offset */
964
965  /* Computes a dtv-relative displacement, the difference between the value
966     of sym+add and the base address of the thread-local storage block that
967     contains the definition of sym, minus 0x8000.  */
968  HOWTO (R_PPC_DTPREL32,
969	 0,			/* rightshift */
970	 2,			/* size (0 = byte, 1 = short, 2 = long) */
971	 32,			/* bitsize */
972	 FALSE,			/* pc_relative */
973	 0,			/* bitpos */
974	 complain_overflow_dont, /* complain_on_overflow */
975	 ppc_elf_unhandled_reloc, /* special_function */
976	 "R_PPC_DTPREL32",	/* name */
977	 FALSE,			/* partial_inplace */
978	 0,			/* src_mask */
979	 0xffffffff,		/* dst_mask */
980	 FALSE),		/* pcrel_offset */
981
982  /* A 16 bit dtprel reloc.  */
983  HOWTO (R_PPC_DTPREL16,
984	 0,			/* rightshift */
985	 1,			/* size (0 = byte, 1 = short, 2 = long) */
986	 16,			/* bitsize */
987	 FALSE,			/* pc_relative */
988	 0,			/* bitpos */
989	 complain_overflow_signed, /* complain_on_overflow */
990	 ppc_elf_unhandled_reloc, /* special_function */
991	 "R_PPC_DTPREL16",	/* name */
992	 FALSE,			/* partial_inplace */
993	 0,			/* src_mask */
994	 0xffff,		/* dst_mask */
995	 FALSE),		/* pcrel_offset */
996
997  /* Like DTPREL16, but no overflow.  */
998  HOWTO (R_PPC_DTPREL16_LO,
999	 0,			/* rightshift */
1000	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1001	 16,			/* bitsize */
1002	 FALSE,			/* pc_relative */
1003	 0,			/* bitpos */
1004	 complain_overflow_dont, /* complain_on_overflow */
1005	 ppc_elf_unhandled_reloc, /* special_function */
1006	 "R_PPC_DTPREL16_LO",	/* name */
1007	 FALSE,			/* partial_inplace */
1008	 0,			/* src_mask */
1009	 0xffff,		/* dst_mask */
1010	 FALSE),		/* pcrel_offset */
1011
1012  /* Like DTPREL16_LO, but next higher group of 16 bits.  */
1013  HOWTO (R_PPC_DTPREL16_HI,
1014	 16,			/* rightshift */
1015	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1016	 16,			/* bitsize */
1017	 FALSE,			/* pc_relative */
1018	 0,			/* bitpos */
1019	 complain_overflow_dont, /* complain_on_overflow */
1020	 ppc_elf_unhandled_reloc, /* special_function */
1021	 "R_PPC_DTPREL16_HI",	/* name */
1022	 FALSE,			/* partial_inplace */
1023	 0,			/* src_mask */
1024	 0xffff,		/* dst_mask */
1025	 FALSE),		/* pcrel_offset */
1026
1027  /* Like DTPREL16_HI, but adjust for low 16 bits.  */
1028  HOWTO (R_PPC_DTPREL16_HA,
1029	 16,			/* rightshift */
1030	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1031	 16,			/* bitsize */
1032	 FALSE,			/* pc_relative */
1033	 0,			/* bitpos */
1034	 complain_overflow_dont, /* complain_on_overflow */
1035	 ppc_elf_unhandled_reloc, /* special_function */
1036	 "R_PPC_DTPREL16_HA",	/* name */
1037	 FALSE,			/* partial_inplace */
1038	 0,			/* src_mask */
1039	 0xffff,		/* dst_mask */
1040	 FALSE),		/* pcrel_offset */
1041
1042  /* Computes a tp-relative displacement, the difference between the value of
1043     sym+add and the value of the thread pointer (r13).  */
1044  HOWTO (R_PPC_TPREL32,
1045	 0,			/* rightshift */
1046	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1047	 32,			/* bitsize */
1048	 FALSE,			/* pc_relative */
1049	 0,			/* bitpos */
1050	 complain_overflow_dont, /* complain_on_overflow */
1051	 ppc_elf_unhandled_reloc, /* special_function */
1052	 "R_PPC_TPREL32",	/* name */
1053	 FALSE,			/* partial_inplace */
1054	 0,			/* src_mask */
1055	 0xffffffff,		/* dst_mask */
1056	 FALSE),		/* pcrel_offset */
1057
1058  /* A 16 bit tprel reloc.  */
1059  HOWTO (R_PPC_TPREL16,
1060	 0,			/* rightshift */
1061	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1062	 16,			/* bitsize */
1063	 FALSE,			/* pc_relative */
1064	 0,			/* bitpos */
1065	 complain_overflow_signed, /* complain_on_overflow */
1066	 ppc_elf_unhandled_reloc, /* special_function */
1067	 "R_PPC_TPREL16",	/* name */
1068	 FALSE,			/* partial_inplace */
1069	 0,			/* src_mask */
1070	 0xffff,		/* dst_mask */
1071	 FALSE),		/* pcrel_offset */
1072
1073  /* Like TPREL16, but no overflow.  */
1074  HOWTO (R_PPC_TPREL16_LO,
1075	 0,			/* rightshift */
1076	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1077	 16,			/* bitsize */
1078	 FALSE,			/* pc_relative */
1079	 0,			/* bitpos */
1080	 complain_overflow_dont, /* complain_on_overflow */
1081	 ppc_elf_unhandled_reloc, /* special_function */
1082	 "R_PPC_TPREL16_LO",	/* name */
1083	 FALSE,			/* partial_inplace */
1084	 0,			/* src_mask */
1085	 0xffff,		/* dst_mask */
1086	 FALSE),		/* pcrel_offset */
1087
1088  /* Like TPREL16_LO, but next higher group of 16 bits.  */
1089  HOWTO (R_PPC_TPREL16_HI,
1090	 16,			/* rightshift */
1091	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1092	 16,			/* bitsize */
1093	 FALSE,			/* pc_relative */
1094	 0,			/* bitpos */
1095	 complain_overflow_dont, /* complain_on_overflow */
1096	 ppc_elf_unhandled_reloc, /* special_function */
1097	 "R_PPC_TPREL16_HI",	/* name */
1098	 FALSE,			/* partial_inplace */
1099	 0,			/* src_mask */
1100	 0xffff,		/* dst_mask */
1101	 FALSE),		/* pcrel_offset */
1102
1103  /* Like TPREL16_HI, but adjust for low 16 bits.  */
1104  HOWTO (R_PPC_TPREL16_HA,
1105	 16,			/* rightshift */
1106	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1107	 16,			/* bitsize */
1108	 FALSE,			/* pc_relative */
1109	 0,			/* bitpos */
1110	 complain_overflow_dont, /* complain_on_overflow */
1111	 ppc_elf_unhandled_reloc, /* special_function */
1112	 "R_PPC_TPREL16_HA",	/* name */
1113	 FALSE,			/* partial_inplace */
1114	 0,			/* src_mask */
1115	 0xffff,		/* dst_mask */
1116	 FALSE),		/* pcrel_offset */
1117
1118  /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1119     with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1120     to the first entry.  */
1121  HOWTO (R_PPC_GOT_TLSGD16,
1122	 0,			/* rightshift */
1123	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1124	 16,			/* bitsize */
1125	 FALSE,			/* pc_relative */
1126	 0,			/* bitpos */
1127	 complain_overflow_signed, /* complain_on_overflow */
1128	 ppc_elf_unhandled_reloc, /* special_function */
1129	 "R_PPC_GOT_TLSGD16",	/* name */
1130	 FALSE,			/* partial_inplace */
1131	 0,			/* src_mask */
1132	 0xffff,		/* dst_mask */
1133	 FALSE),		/* pcrel_offset */
1134
1135  /* Like GOT_TLSGD16, but no overflow.  */
1136  HOWTO (R_PPC_GOT_TLSGD16_LO,
1137	 0,			/* rightshift */
1138	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1139	 16,			/* bitsize */
1140	 FALSE,			/* pc_relative */
1141	 0,			/* bitpos */
1142	 complain_overflow_dont, /* complain_on_overflow */
1143	 ppc_elf_unhandled_reloc, /* special_function */
1144	 "R_PPC_GOT_TLSGD16_LO", /* name */
1145	 FALSE,			/* partial_inplace */
1146	 0,			/* src_mask */
1147	 0xffff,		/* dst_mask */
1148	 FALSE),		/* pcrel_offset */
1149
1150  /* Like GOT_TLSGD16_LO, but next higher group of 16 bits.  */
1151  HOWTO (R_PPC_GOT_TLSGD16_HI,
1152	 16,			/* rightshift */
1153	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1154	 16,			/* bitsize */
1155	 FALSE,			/* pc_relative */
1156	 0,			/* bitpos */
1157	 complain_overflow_dont, /* complain_on_overflow */
1158	 ppc_elf_unhandled_reloc, /* special_function */
1159	 "R_PPC_GOT_TLSGD16_HI", /* name */
1160	 FALSE,			/* partial_inplace */
1161	 0,			/* src_mask */
1162	 0xffff,		/* dst_mask */
1163	 FALSE),		/* pcrel_offset */
1164
1165  /* Like GOT_TLSGD16_HI, but adjust for low 16 bits.  */
1166  HOWTO (R_PPC_GOT_TLSGD16_HA,
1167	 16,			/* rightshift */
1168	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1169	 16,			/* bitsize */
1170	 FALSE,			/* pc_relative */
1171	 0,			/* bitpos */
1172	 complain_overflow_dont, /* complain_on_overflow */
1173	 ppc_elf_unhandled_reloc, /* special_function */
1174	 "R_PPC_GOT_TLSGD16_HA", /* name */
1175	 FALSE,			/* partial_inplace */
1176	 0,			/* src_mask */
1177	 0xffff,		/* dst_mask */
1178	 FALSE),		/* pcrel_offset */
1179
1180  /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1181     with values (sym+add)@dtpmod and zero, and computes the offset to the
1182     first entry.  */
1183  HOWTO (R_PPC_GOT_TLSLD16,
1184	 0,			/* rightshift */
1185	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1186	 16,			/* bitsize */
1187	 FALSE,			/* pc_relative */
1188	 0,			/* bitpos */
1189	 complain_overflow_signed, /* complain_on_overflow */
1190	 ppc_elf_unhandled_reloc, /* special_function */
1191	 "R_PPC_GOT_TLSLD16",	/* name */
1192	 FALSE,			/* partial_inplace */
1193	 0,			/* src_mask */
1194	 0xffff,		/* dst_mask */
1195	 FALSE),		/* pcrel_offset */
1196
1197  /* Like GOT_TLSLD16, but no overflow.  */
1198  HOWTO (R_PPC_GOT_TLSLD16_LO,
1199	 0,			/* rightshift */
1200	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1201	 16,			/* bitsize */
1202	 FALSE,			/* pc_relative */
1203	 0,			/* bitpos */
1204	 complain_overflow_dont, /* complain_on_overflow */
1205	 ppc_elf_unhandled_reloc, /* special_function */
1206	 "R_PPC_GOT_TLSLD16_LO", /* name */
1207	 FALSE,			/* partial_inplace */
1208	 0,			/* src_mask */
1209	 0xffff,		/* dst_mask */
1210	 FALSE),		/* pcrel_offset */
1211
1212  /* Like GOT_TLSLD16_LO, but next higher group of 16 bits.  */
1213  HOWTO (R_PPC_GOT_TLSLD16_HI,
1214	 16,			/* rightshift */
1215	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1216	 16,			/* bitsize */
1217	 FALSE,			/* pc_relative */
1218	 0,			/* bitpos */
1219	 complain_overflow_dont, /* complain_on_overflow */
1220	 ppc_elf_unhandled_reloc, /* special_function */
1221	 "R_PPC_GOT_TLSLD16_HI", /* name */
1222	 FALSE,			/* partial_inplace */
1223	 0,			/* src_mask */
1224	 0xffff,		/* dst_mask */
1225	 FALSE),		/* pcrel_offset */
1226
1227  /* Like GOT_TLSLD16_HI, but adjust for low 16 bits.  */
1228  HOWTO (R_PPC_GOT_TLSLD16_HA,
1229	 16,			/* rightshift */
1230	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1231	 16,			/* bitsize */
1232	 FALSE,			/* pc_relative */
1233	 0,			/* bitpos */
1234	 complain_overflow_dont, /* complain_on_overflow */
1235	 ppc_elf_unhandled_reloc, /* special_function */
1236	 "R_PPC_GOT_TLSLD16_HA", /* name */
1237	 FALSE,			/* partial_inplace */
1238	 0,			/* src_mask */
1239	 0xffff,		/* dst_mask */
1240	 FALSE),		/* pcrel_offset */
1241
1242  /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1243     the offset to the entry.  */
1244  HOWTO (R_PPC_GOT_DTPREL16,
1245	 0,			/* rightshift */
1246	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1247	 16,			/* bitsize */
1248	 FALSE,			/* pc_relative */
1249	 0,			/* bitpos */
1250	 complain_overflow_signed, /* complain_on_overflow */
1251	 ppc_elf_unhandled_reloc, /* special_function */
1252	 "R_PPC_GOT_DTPREL16",	/* name */
1253	 FALSE,			/* partial_inplace */
1254	 0,			/* src_mask */
1255	 0xffff,		/* dst_mask */
1256	 FALSE),		/* pcrel_offset */
1257
1258  /* Like GOT_DTPREL16, but no overflow.  */
1259  HOWTO (R_PPC_GOT_DTPREL16_LO,
1260	 0,			/* rightshift */
1261	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1262	 16,			/* bitsize */
1263	 FALSE,			/* pc_relative */
1264	 0,			/* bitpos */
1265	 complain_overflow_dont, /* complain_on_overflow */
1266	 ppc_elf_unhandled_reloc, /* special_function */
1267	 "R_PPC_GOT_DTPREL16_LO", /* name */
1268	 FALSE,			/* partial_inplace */
1269	 0,			/* src_mask */
1270	 0xffff,		/* dst_mask */
1271	 FALSE),		/* pcrel_offset */
1272
1273  /* Like GOT_DTPREL16_LO, but next higher group of 16 bits.  */
1274  HOWTO (R_PPC_GOT_DTPREL16_HI,
1275	 16,			/* rightshift */
1276	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1277	 16,			/* bitsize */
1278	 FALSE,			/* pc_relative */
1279	 0,			/* bitpos */
1280	 complain_overflow_dont, /* complain_on_overflow */
1281	 ppc_elf_unhandled_reloc, /* special_function */
1282	 "R_PPC_GOT_DTPREL16_HI", /* name */
1283	 FALSE,			/* partial_inplace */
1284	 0,			/* src_mask */
1285	 0xffff,		/* dst_mask */
1286	 FALSE),		/* pcrel_offset */
1287
1288  /* Like GOT_DTPREL16_HI, but adjust for low 16 bits.  */
1289  HOWTO (R_PPC_GOT_DTPREL16_HA,
1290	 16,			/* rightshift */
1291	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1292	 16,			/* bitsize */
1293	 FALSE,			/* pc_relative */
1294	 0,			/* bitpos */
1295	 complain_overflow_dont, /* complain_on_overflow */
1296	 ppc_elf_unhandled_reloc, /* special_function */
1297	 "R_PPC_GOT_DTPREL16_HA", /* name */
1298	 FALSE,			/* partial_inplace */
1299	 0,			/* src_mask */
1300	 0xffff,		/* dst_mask */
1301	 FALSE),		/* pcrel_offset */
1302
1303  /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1304     offset to the entry.  */
1305  HOWTO (R_PPC_GOT_TPREL16,
1306	 0,			/* rightshift */
1307	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1308	 16,			/* bitsize */
1309	 FALSE,			/* pc_relative */
1310	 0,			/* bitpos */
1311	 complain_overflow_signed, /* complain_on_overflow */
1312	 ppc_elf_unhandled_reloc, /* special_function */
1313	 "R_PPC_GOT_TPREL16",	/* name */
1314	 FALSE,			/* partial_inplace */
1315	 0,			/* src_mask */
1316	 0xffff,		/* dst_mask */
1317	 FALSE),		/* pcrel_offset */
1318
1319  /* Like GOT_TPREL16, but no overflow.  */
1320  HOWTO (R_PPC_GOT_TPREL16_LO,
1321	 0,			/* rightshift */
1322	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1323	 16,			/* bitsize */
1324	 FALSE,			/* pc_relative */
1325	 0,			/* bitpos */
1326	 complain_overflow_dont, /* complain_on_overflow */
1327	 ppc_elf_unhandled_reloc, /* special_function */
1328	 "R_PPC_GOT_TPREL16_LO", /* name */
1329	 FALSE,			/* partial_inplace */
1330	 0,			/* src_mask */
1331	 0xffff,		/* dst_mask */
1332	 FALSE),		/* pcrel_offset */
1333
1334  /* Like GOT_TPREL16_LO, but next higher group of 16 bits.  */
1335  HOWTO (R_PPC_GOT_TPREL16_HI,
1336	 16,			/* rightshift */
1337	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1338	 16,			/* bitsize */
1339	 FALSE,			/* pc_relative */
1340	 0,			/* bitpos */
1341	 complain_overflow_dont, /* complain_on_overflow */
1342	 ppc_elf_unhandled_reloc, /* special_function */
1343	 "R_PPC_GOT_TPREL16_HI", /* name */
1344	 FALSE,			/* partial_inplace */
1345	 0,			/* src_mask */
1346	 0xffff,		/* dst_mask */
1347	 FALSE),		/* pcrel_offset */
1348
1349  /* Like GOT_TPREL16_HI, but adjust for low 16 bits.  */
1350  HOWTO (R_PPC_GOT_TPREL16_HA,
1351	 16,			/* rightshift */
1352	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1353	 16,			/* bitsize */
1354	 FALSE,			/* pc_relative */
1355	 0,			/* bitpos */
1356	 complain_overflow_dont, /* complain_on_overflow */
1357	 ppc_elf_unhandled_reloc, /* special_function */
1358	 "R_PPC_GOT_TPREL16_HA", /* name */
1359	 FALSE,			/* partial_inplace */
1360	 0,			/* src_mask */
1361	 0xffff,		/* dst_mask */
1362	 FALSE),		/* pcrel_offset */
1363
1364  /* The remaining relocs are from the Embedded ELF ABI, and are not
1365     in the SVR4 ELF ABI.  */
1366
1367  /* 32 bit value resulting from the addend minus the symbol.  */
1368  HOWTO (R_PPC_EMB_NADDR32,	/* type */
1369	 0,			/* rightshift */
1370	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1371	 32,			/* bitsize */
1372	 FALSE,			/* pc_relative */
1373	 0,			/* bitpos */
1374	 complain_overflow_bitfield, /* complain_on_overflow */
1375	 bfd_elf_generic_reloc,	/* special_function */
1376	 "R_PPC_EMB_NADDR32",	/* name */
1377	 FALSE,			/* partial_inplace */
1378	 0,			/* src_mask */
1379	 0xffffffff,		/* dst_mask */
1380	 FALSE),		/* pcrel_offset */
1381
1382  /* 16 bit value resulting from the addend minus the symbol.  */
1383  HOWTO (R_PPC_EMB_NADDR16,	/* type */
1384	 0,			/* rightshift */
1385	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1386	 16,			/* bitsize */
1387	 FALSE,			/* pc_relative */
1388	 0,			/* bitpos */
1389	 complain_overflow_bitfield, /* complain_on_overflow */
1390	 bfd_elf_generic_reloc,	/* special_function */
1391	 "R_PPC_EMB_NADDR16",	/* name */
1392	 FALSE,			/* partial_inplace */
1393	 0,			/* src_mask */
1394	 0xffff,		/* dst_mask */
1395	 FALSE),		/* pcrel_offset */
1396
1397  /* 16 bit value resulting from the addend minus the symbol.  */
1398  HOWTO (R_PPC_EMB_NADDR16_LO,	/* type */
1399	 0,			/* 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	 bfd_elf_generic_reloc,	/* special_function */
1406	 "R_PPC_EMB_ADDR16_LO",	/* name */
1407	 FALSE,			/* partial_inplace */
1408	 0,			/* src_mask */
1409	 0xffff,		/* dst_mask */
1410	 FALSE),		/* pcrel_offset */
1411
1412  /* The high order 16 bits of the addend minus the symbol.  */
1413  HOWTO (R_PPC_EMB_NADDR16_HI,	/* type */
1414	 16,			/* rightshift */
1415	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1416	 16,			/* bitsize */
1417	 FALSE,			/* pc_relative */
1418	 0,			/* bitpos */
1419	 complain_overflow_dont, /* complain_on_overflow */
1420	 bfd_elf_generic_reloc,	/* special_function */
1421	 "R_PPC_EMB_NADDR16_HI", /* name */
1422	 FALSE,			/* partial_inplace */
1423	 0,			/* src_mask */
1424	 0xffff,		/* dst_mask */
1425	 FALSE),		/* pcrel_offset */
1426
1427  /* The high order 16 bits of the result of the addend minus the address,
1428     plus 1 if the contents of the low 16 bits, treated as a signed number,
1429     is negative.  */
1430  HOWTO (R_PPC_EMB_NADDR16_HA,	/* type */
1431	 16,			/* rightshift */
1432	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1433	 16,			/* bitsize */
1434	 FALSE,			/* pc_relative */
1435	 0,			/* bitpos */
1436	 complain_overflow_dont, /* complain_on_overflow */
1437	 ppc_elf_addr16_ha_reloc, /* special_function */
1438	 "R_PPC_EMB_NADDR16_HA", /* name */
1439	 FALSE,			/* partial_inplace */
1440	 0,			/* src_mask */
1441	 0xffff,		/* dst_mask */
1442	 FALSE),		/* pcrel_offset */
1443
1444  /* 16 bit value resulting from allocating a 4 byte word to hold an
1445     address in the .sdata section, and returning the offset from
1446     _SDA_BASE_ for that relocation.  */
1447  HOWTO (R_PPC_EMB_SDAI16,	/* type */
1448	 0,			/* rightshift */
1449	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1450	 16,			/* bitsize */
1451	 FALSE,			/* pc_relative */
1452	 0,			/* bitpos */
1453	 complain_overflow_bitfield, /* complain_on_overflow */
1454	 bfd_elf_generic_reloc,	/* special_function */
1455	 "R_PPC_EMB_SDAI16",	/* name */
1456	 FALSE,			/* partial_inplace */
1457	 0,			/* src_mask */
1458	 0xffff,		/* dst_mask */
1459	 FALSE),		/* pcrel_offset */
1460
1461  /* 16 bit value resulting from allocating a 4 byte word to hold an
1462     address in the .sdata2 section, and returning the offset from
1463     _SDA2_BASE_ for that relocation.  */
1464  HOWTO (R_PPC_EMB_SDA2I16,	/* type */
1465	 0,			/* rightshift */
1466	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1467	 16,			/* bitsize */
1468	 FALSE,			/* pc_relative */
1469	 0,			/* bitpos */
1470	 complain_overflow_bitfield, /* complain_on_overflow */
1471	 bfd_elf_generic_reloc,	/* special_function */
1472	 "R_PPC_EMB_SDA2I16",	/* name */
1473	 FALSE,			/* partial_inplace */
1474	 0,			/* src_mask */
1475	 0xffff,		/* dst_mask */
1476	 FALSE),		/* pcrel_offset */
1477
1478  /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1479     small data items.	 */
1480  HOWTO (R_PPC_EMB_SDA2REL,	/* type */
1481	 0,			/* rightshift */
1482	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1483	 16,			/* bitsize */
1484	 FALSE,			/* pc_relative */
1485	 0,			/* bitpos */
1486	 complain_overflow_signed, /* complain_on_overflow */
1487	 bfd_elf_generic_reloc,	/* special_function */
1488	 "R_PPC_EMB_SDA2REL",	/* name */
1489	 FALSE,			/* partial_inplace */
1490	 0,			/* src_mask */
1491	 0xffff,		/* dst_mask */
1492	 FALSE),		/* pcrel_offset */
1493
1494  /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1495     signed offset from the appropriate base, and filling in the register
1496     field with the appropriate register (0, 2, or 13).  */
1497  HOWTO (R_PPC_EMB_SDA21,	/* type */
1498	 0,			/* rightshift */
1499	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1500	 16,			/* bitsize */
1501	 FALSE,			/* pc_relative */
1502	 0,			/* bitpos */
1503	 complain_overflow_signed, /* complain_on_overflow */
1504	 bfd_elf_generic_reloc,	/* special_function */
1505	 "R_PPC_EMB_SDA21",	/* name */
1506	 FALSE,			/* partial_inplace */
1507	 0,			/* src_mask */
1508	 0xffff,		/* dst_mask */
1509	 FALSE),		/* pcrel_offset */
1510
1511  /* Relocation not handled: R_PPC_EMB_MRKREF */
1512  /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1513  /* Relocation not handled: R_PPC_EMB_RELST_LO */
1514  /* Relocation not handled: R_PPC_EMB_RELST_HI */
1515  /* Relocation not handled: R_PPC_EMB_RELST_HA */
1516  /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1517
1518  /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1519     in the 16 bit signed offset from the appropriate base, and filling in the
1520     register field with the appropriate register (0, 2, or 13).  */
1521  HOWTO (R_PPC_EMB_RELSDA,	/* type */
1522	 0,			/* rightshift */
1523	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1524	 16,			/* bitsize */
1525	 TRUE,			/* pc_relative */
1526	 0,			/* bitpos */
1527	 complain_overflow_signed, /* complain_on_overflow */
1528	 bfd_elf_generic_reloc,	/* special_function */
1529	 "R_PPC_EMB_RELSDA",	/* name */
1530	 FALSE,			/* partial_inplace */
1531	 0,			/* src_mask */
1532	 0xffff,		/* dst_mask */
1533	 FALSE),		/* pcrel_offset */
1534
1535  /* Phony relocs to handle branch stubs.  */
1536  HOWTO (R_PPC_RELAX32,		/* type */
1537	 0,			/* rightshift */
1538	 0,			/* size */
1539	 0,			/* bitsize */
1540	 FALSE,			/* pc_relative */
1541	 0,			/* bitpos */
1542	 complain_overflow_dont, /* complain_on_overflow */
1543	 bfd_elf_generic_reloc,	/* special_function */
1544	 "R_PPC_RELAX32",	/* name */
1545	 FALSE,			/* partial_inplace */
1546	 0,			/* src_mask */
1547	 0,			/* dst_mask */
1548	 FALSE),		/* pcrel_offset */
1549
1550  HOWTO (R_PPC_RELAX32PC,	/* type */
1551	 0,			/* rightshift */
1552	 0,			/* size */
1553	 0,			/* bitsize */
1554	 FALSE,			/* pc_relative */
1555	 0,			/* bitpos */
1556	 complain_overflow_dont, /* complain_on_overflow */
1557	 bfd_elf_generic_reloc,	/* special_function */
1558	 "R_PPC_RELAX32PC",	/* name */
1559	 FALSE,			/* partial_inplace */
1560	 0,			/* src_mask */
1561	 0,			/* dst_mask */
1562	 FALSE),		/* pcrel_offset */
1563
1564  /* GNU extension to record C++ vtable hierarchy.  */
1565  HOWTO (R_PPC_GNU_VTINHERIT,	/* type */
1566	 0,			/* rightshift */
1567	 0,			/* size (0 = byte, 1 = short, 2 = long) */
1568	 0,			/* bitsize */
1569	 FALSE,			/* pc_relative */
1570	 0,			/* bitpos */
1571	 complain_overflow_dont, /* complain_on_overflow */
1572	 NULL,			/* special_function */
1573	 "R_PPC_GNU_VTINHERIT",	/* name */
1574	 FALSE,			/* partial_inplace */
1575	 0,			/* src_mask */
1576	 0,			/* dst_mask */
1577	 FALSE),		/* pcrel_offset */
1578
1579  /* GNU extension to record C++ vtable member usage.  */
1580  HOWTO (R_PPC_GNU_VTENTRY,	/* type */
1581	 0,			/* rightshift */
1582	 0,			/* size (0 = byte, 1 = short, 2 = long) */
1583	 0,			/* bitsize */
1584	 FALSE,			/* pc_relative */
1585	 0,			/* bitpos */
1586	 complain_overflow_dont, /* complain_on_overflow */
1587	 NULL,			/* special_function */
1588	 "R_PPC_GNU_VTENTRY",	/* name */
1589	 FALSE,			/* partial_inplace */
1590	 0,			/* src_mask */
1591	 0,			/* dst_mask */
1592	 FALSE),		/* pcrel_offset */
1593
1594  /* Phony reloc to handle AIX style TOC entries.  */
1595  HOWTO (R_PPC_TOC16,		/* type */
1596	 0,			/* rightshift */
1597	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1598	 16,			/* bitsize */
1599	 FALSE,			/* pc_relative */
1600	 0,			/* bitpos */
1601	 complain_overflow_signed, /* complain_on_overflow */
1602	 bfd_elf_generic_reloc,	/* special_function */
1603	 "R_PPC_TOC16",		/* name */
1604	 FALSE,			/* partial_inplace */
1605	 0,			/* src_mask */
1606	 0xffff,		/* dst_mask */
1607	 FALSE),		/* pcrel_offset */
1608};
1609
1610/* Initialize the ppc_elf_howto_table, so that linear accesses can be done.  */
1611
1612static void
1613ppc_elf_howto_init (void)
1614{
1615  unsigned int i, type;
1616
1617  for (i = 0;
1618       i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
1619       i++)
1620    {
1621      type = ppc_elf_howto_raw[i].type;
1622      if (type >= (sizeof (ppc_elf_howto_table)
1623		   / sizeof (ppc_elf_howto_table[0])))
1624	abort ();
1625      ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
1626    }
1627}
1628
1629#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
1630
1631static const int shared_stub_entry[] =
1632  {
1633    0x7c0802a6, /* mflr 0 */
1634    0x429f0005, /* bcl 20, 31, .Lxxx */
1635    0x7d6802a6, /* mflr 11 */
1636    0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
1637    0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
1638    0x7c0803a6, /* mtlr 0 */
1639    0x7d6903a6, /* mtctr 11 */
1640    0x4e800420, /* bctr */
1641  };
1642
1643static const int stub_entry[] =
1644  {
1645    0x3d600000, /* lis 11,xxx@ha */
1646    0x396b0000, /* addi 11,11,xxx@l */
1647    0x7d6903a6, /* mtctr 11 */
1648    0x4e800420, /* bctr */
1649  };
1650
1651
1652static bfd_boolean
1653ppc_elf_relax_section (bfd *abfd,
1654		       asection *isec,
1655		       struct bfd_link_info *link_info,
1656		       bfd_boolean *again)
1657{
1658  struct one_fixup
1659  {
1660    struct one_fixup *next;
1661    asection *tsec;
1662    bfd_vma toff;
1663    bfd_vma trampoff;
1664  };
1665
1666  Elf_Internal_Shdr *symtab_hdr;
1667  bfd_byte *contents = NULL;
1668  Elf_Internal_Sym *isymbuf = NULL;
1669  Elf_Internal_Rela *internal_relocs = NULL;
1670  Elf_Internal_Rela *irel, *irelend;
1671  struct one_fixup *fixups = NULL;
1672  bfd_boolean changed;
1673  struct ppc_elf_link_hash_table *ppc_info;
1674  bfd_size_type trampoff;
1675
1676  *again = FALSE;
1677
1678  /* Nothing to do if there are no relocations.  */
1679  if ((isec->flags & SEC_RELOC) == 0 || isec->reloc_count == 0)
1680    return TRUE;
1681
1682  /* If needed, initialize this section's cooked size.  */
1683  if (isec->_cooked_size == 0)
1684    isec->_cooked_size = isec->_raw_size;
1685
1686  trampoff = (isec->_cooked_size + 3) & (bfd_vma) -4;
1687  /* Space for a branch around any trampolines.  */
1688  trampoff += 4;
1689
1690  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1691
1692  /* Get a copy of the native relocations.  */
1693  internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL,
1694					       link_info->keep_memory);
1695  if (internal_relocs == NULL)
1696    goto error_return;
1697
1698  ppc_info = ppc_elf_hash_table (link_info);
1699  irelend = internal_relocs + isec->reloc_count;
1700
1701  /* Get the section contents.  */
1702  /* Get cached copy if it exists.  */
1703  if (elf_section_data (isec)->this_hdr.contents != NULL)
1704    contents = elf_section_data (isec)->this_hdr.contents;
1705  else
1706    {
1707      /* Go get them off disk.  */
1708      contents = bfd_malloc (isec->_raw_size);
1709      if (contents == NULL)
1710	goto error_return;
1711
1712      if (!bfd_get_section_contents (abfd, isec, contents, 0, isec->_raw_size))
1713	goto error_return;
1714    }
1715
1716  for (irel = internal_relocs; irel < irelend; irel++)
1717    {
1718      unsigned long r_type = ELF32_R_TYPE (irel->r_info);
1719      bfd_vma symaddr, reladdr, toff, roff;
1720      asection *tsec;
1721      struct one_fixup *f;
1722      size_t insn_offset = 0;
1723      bfd_vma max_branch_offset, val;
1724      bfd_byte *hit_addr;
1725      unsigned long t0;
1726
1727      switch (r_type)
1728	{
1729	case R_PPC_REL24:
1730	case R_PPC_LOCAL24PC:
1731	case R_PPC_PLTREL24:
1732	  max_branch_offset = 1 << 25;
1733	  break;
1734
1735	case R_PPC_REL14:
1736	case R_PPC_REL14_BRTAKEN:
1737	case R_PPC_REL14_BRNTAKEN:
1738	  max_branch_offset = 1 << 15;
1739	  break;
1740
1741	default:
1742	  continue;
1743	}
1744
1745      /* Get the value of the symbol referred to by the reloc.  */
1746      if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
1747	{
1748	  /* A local symbol.  */
1749	  Elf_Internal_Sym *isym;
1750
1751	  /* Read this BFD's local symbols.  */
1752	  if (isymbuf == NULL)
1753	    {
1754	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1755	      if (isymbuf == NULL)
1756		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
1757						symtab_hdr->sh_info, 0,
1758						NULL, NULL, NULL);
1759	      if (isymbuf == 0)
1760		goto error_return;
1761	    }
1762	  isym = isymbuf + ELF32_R_SYM (irel->r_info);
1763	  if (isym->st_shndx == SHN_UNDEF)
1764	    continue;	/* We can't do anything with undefined symbols.  */
1765	  else if (isym->st_shndx == SHN_ABS)
1766	    tsec = bfd_abs_section_ptr;
1767	  else if (isym->st_shndx == SHN_COMMON)
1768	    tsec = bfd_com_section_ptr;
1769	  else
1770	    tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
1771
1772	  toff = isym->st_value;
1773	}
1774      else
1775	{
1776	  /* Global symbol handling.  */
1777	  unsigned long indx;
1778	  struct elf_link_hash_entry *h;
1779
1780	  indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
1781	  h = elf_sym_hashes (abfd)[indx];
1782
1783	  while (h->root.type == bfd_link_hash_indirect
1784		 || h->root.type == bfd_link_hash_warning)
1785	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
1786
1787	  if (r_type == R_PPC_PLTREL24
1788	      && ppc_info->plt != NULL
1789	      && h->plt.offset != (bfd_vma) -1)
1790	    {
1791	      tsec = ppc_info->plt;
1792	      toff = h->plt.offset;
1793	    }
1794	  else if (h->root.type == bfd_link_hash_defined
1795		   || h->root.type == bfd_link_hash_defweak)
1796	    {
1797	      tsec = h->root.u.def.section;
1798	      toff = h->root.u.def.value;
1799	    }
1800	  else
1801	    continue;
1802	}
1803
1804      /* If the branch and target are in the same section, you have
1805	 no hope of adding stubs.  We'll error out later should the
1806	 branch overflow.  */
1807      if (tsec == isec)
1808	continue;
1809
1810      toff += irel->r_addend;
1811      if (tsec->sec_info_type == ELF_INFO_TYPE_MERGE)
1812	toff = _bfd_merged_section_offset (abfd, &tsec,
1813					   elf_section_data (tsec)->sec_info,
1814					   toff, 0);
1815
1816      symaddr = tsec->output_section->vma + tsec->output_offset + toff;
1817
1818      roff = irel->r_offset;
1819      reladdr = isec->output_section->vma + isec->output_offset + roff;
1820
1821      /* If the branch is in range, no need to do anything.  */
1822      if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset)
1823	continue;
1824
1825      /* Look for an existing fixup to this address.  */
1826      for (f = fixups; f ; f = f->next)
1827	if (f->tsec == tsec && f->toff == toff)
1828	  break;
1829
1830      if (f == NULL)
1831	{
1832	  size_t size;
1833	  unsigned long stub_rtype;
1834
1835	  val = trampoff - roff;
1836	  if (val >= max_branch_offset)
1837	    /* Oh dear, we can't reach a trampoline.  Don't try to add
1838	       one.  We'll report an error later.  */
1839	    continue;
1840
1841	  if (link_info->shared)
1842	    {
1843	      size = 4 * ARRAY_SIZE (shared_stub_entry);
1844	      insn_offset = 12;
1845	      stub_rtype = R_PPC_RELAX32PC;
1846	    }
1847	  else
1848	    {
1849	      size = 4 * ARRAY_SIZE (stub_entry);
1850	      insn_offset = 0;
1851	      stub_rtype = R_PPC_RELAX32;
1852	    }
1853
1854	  /* Hijack the old relocation.  Since we need two
1855	     relocations for this use a "composite" reloc.  */
1856	  irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
1857				       stub_rtype);
1858	  irel->r_offset = trampoff + insn_offset;
1859
1860	  /* Record the fixup so we don't do it again this section.  */
1861	  f = bfd_malloc (sizeof (*f));
1862	  f->next = fixups;
1863	  f->tsec = tsec;
1864	  f->toff = toff;
1865	  f->trampoff = trampoff;
1866	  fixups = f;
1867
1868	  trampoff += size;
1869	}
1870      else
1871	{
1872	  val = f->trampoff - roff;
1873	  if (val >= max_branch_offset)
1874	    continue;
1875
1876	  /* Nop out the reloc, since we're finalizing things here.  */
1877	  irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
1878	}
1879
1880      /* Fix up the existing branch to hit the trampoline.  */
1881      hit_addr = contents + roff;
1882      switch (r_type)
1883	{
1884	case R_PPC_REL24:
1885	case R_PPC_LOCAL24PC:
1886	case R_PPC_PLTREL24:
1887	  t0 = bfd_get_32 (abfd, hit_addr);
1888	  t0 &= ~0x3fffffc;
1889	  t0 |= val & 0x3fffffc;
1890	  bfd_put_32 (abfd, t0, hit_addr);
1891	  break;
1892
1893	case R_PPC_REL14:
1894	case R_PPC_REL14_BRTAKEN:
1895	case R_PPC_REL14_BRNTAKEN:
1896	  t0 = bfd_get_32 (abfd, hit_addr);
1897	  t0 &= ~0xfffc;
1898	  t0 |= val & 0xfffc;
1899	  bfd_put_32 (abfd, t0, hit_addr);
1900	  break;
1901	}
1902    }
1903
1904  /* Write out the trampolines.  */
1905  changed = fixups != NULL;
1906  if (fixups != NULL)
1907    {
1908      const int *stub;
1909      bfd_byte *dest;
1910      bfd_vma val;
1911      int i, size;
1912
1913      do
1914	{
1915	  struct one_fixup *f = fixups;
1916	  fixups = fixups->next;
1917	  free (f);
1918	}
1919      while (fixups);
1920
1921      contents = bfd_realloc (contents, trampoff);
1922      if (contents == NULL)
1923	goto error_return;
1924
1925      isec->_cooked_size = (isec->_cooked_size + 3) & (bfd_vma) -4;
1926      /* Branch around the trampolines.  */
1927      val = trampoff - isec->_cooked_size + 0x48000000;
1928      dest = contents + isec->_cooked_size;
1929      isec->_cooked_size = trampoff;
1930      bfd_put_32 (abfd, val, dest);
1931      dest += 4;
1932
1933      if (link_info->shared)
1934	{
1935	  stub = shared_stub_entry;
1936	  size = ARRAY_SIZE (shared_stub_entry);
1937	}
1938      else
1939	{
1940	  stub = stub_entry;
1941	  size = ARRAY_SIZE (stub_entry);
1942	}
1943
1944      i = 0;
1945      while (dest < contents + trampoff)
1946	{
1947	  bfd_put_32 (abfd, stub[i], dest);
1948	  i++;
1949	  if (i == size)
1950	    i = 0;
1951	  dest += 4;
1952	}
1953      BFD_ASSERT (i == 0);
1954    }
1955
1956  if (isymbuf != NULL
1957      && symtab_hdr->contents != (unsigned char *) isymbuf)
1958    {
1959      if (! link_info->keep_memory)
1960	free (isymbuf);
1961      else
1962	{
1963	  /* Cache the symbols for elf_link_input_bfd.  */
1964	  symtab_hdr->contents = (unsigned char *) isymbuf;
1965	}
1966    }
1967
1968  if (contents != NULL
1969      && elf_section_data (isec)->this_hdr.contents != contents)
1970    {
1971      if (!changed && !link_info->keep_memory)
1972	free (contents);
1973      else
1974	{
1975	  /* Cache the section contents for elf_link_input_bfd.  */
1976	  elf_section_data (isec)->this_hdr.contents = contents;
1977	}
1978    }
1979
1980  if (elf_section_data (isec)->relocs != internal_relocs)
1981    {
1982      if (!changed)
1983	free (internal_relocs);
1984      else
1985	elf_section_data (isec)->relocs = internal_relocs;
1986    }
1987
1988  *again = changed;
1989  return TRUE;
1990
1991 error_return:
1992  if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
1993    free (isymbuf);
1994  if (contents != NULL
1995      && elf_section_data (isec)->this_hdr.contents != contents)
1996    free (contents);
1997  if (internal_relocs != NULL
1998      && elf_section_data (isec)->relocs != internal_relocs)
1999    free (internal_relocs);
2000  return FALSE;
2001}
2002
2003static reloc_howto_type *
2004ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2005			   bfd_reloc_code_real_type code)
2006{
2007  enum elf_ppc_reloc_type r;
2008
2009  /* Initialize howto table if not already done.  */
2010  if (!ppc_elf_howto_table[R_PPC_ADDR32])
2011    ppc_elf_howto_init ();
2012
2013  switch (code)
2014    {
2015    default:
2016      return NULL;
2017
2018    case BFD_RELOC_NONE:		r = R_PPC_NONE;			break;
2019    case BFD_RELOC_32:			r = R_PPC_ADDR32;		break;
2020    case BFD_RELOC_PPC_BA26:		r = R_PPC_ADDR24;		break;
2021    case BFD_RELOC_16:			r = R_PPC_ADDR16;		break;
2022    case BFD_RELOC_LO16:		r = R_PPC_ADDR16_LO;		break;
2023    case BFD_RELOC_HI16:		r = R_PPC_ADDR16_HI;		break;
2024    case BFD_RELOC_HI16_S:		r = R_PPC_ADDR16_HA;		break;
2025    case BFD_RELOC_PPC_BA16:		r = R_PPC_ADDR14;		break;
2026    case BFD_RELOC_PPC_BA16_BRTAKEN:	r = R_PPC_ADDR14_BRTAKEN;	break;
2027    case BFD_RELOC_PPC_BA16_BRNTAKEN:	r = R_PPC_ADDR14_BRNTAKEN;	break;
2028    case BFD_RELOC_PPC_B26:		r = R_PPC_REL24;		break;
2029    case BFD_RELOC_PPC_B16:		r = R_PPC_REL14;		break;
2030    case BFD_RELOC_PPC_B16_BRTAKEN:	r = R_PPC_REL14_BRTAKEN;	break;
2031    case BFD_RELOC_PPC_B16_BRNTAKEN:	r = R_PPC_REL14_BRNTAKEN;	break;
2032    case BFD_RELOC_16_GOTOFF:		r = R_PPC_GOT16;		break;
2033    case BFD_RELOC_LO16_GOTOFF:		r = R_PPC_GOT16_LO;		break;
2034    case BFD_RELOC_HI16_GOTOFF:		r = R_PPC_GOT16_HI;		break;
2035    case BFD_RELOC_HI16_S_GOTOFF:	r = R_PPC_GOT16_HA;		break;
2036    case BFD_RELOC_24_PLT_PCREL:	r = R_PPC_PLTREL24;		break;
2037    case BFD_RELOC_PPC_COPY:		r = R_PPC_COPY;			break;
2038    case BFD_RELOC_PPC_GLOB_DAT:	r = R_PPC_GLOB_DAT;		break;
2039    case BFD_RELOC_PPC_LOCAL24PC:	r = R_PPC_LOCAL24PC;		break;
2040    case BFD_RELOC_32_PCREL:		r = R_PPC_REL32;		break;
2041    case BFD_RELOC_32_PLTOFF:		r = R_PPC_PLT32;		break;
2042    case BFD_RELOC_32_PLT_PCREL:	r = R_PPC_PLTREL32;		break;
2043    case BFD_RELOC_LO16_PLTOFF:		r = R_PPC_PLT16_LO;		break;
2044    case BFD_RELOC_HI16_PLTOFF:		r = R_PPC_PLT16_HI;		break;
2045    case BFD_RELOC_HI16_S_PLTOFF:	r = R_PPC_PLT16_HA;		break;
2046    case BFD_RELOC_GPREL16:		r = R_PPC_SDAREL16;		break;
2047    case BFD_RELOC_16_BASEREL:		r = R_PPC_SECTOFF;		break;
2048    case BFD_RELOC_LO16_BASEREL:	r = R_PPC_SECTOFF_LO;		break;
2049    case BFD_RELOC_HI16_BASEREL:	r = R_PPC_SECTOFF_HI;		break;
2050    case BFD_RELOC_HI16_S_BASEREL:	r = R_PPC_SECTOFF_HA;		break;
2051    case BFD_RELOC_CTOR:		r = R_PPC_ADDR32;		break;
2052    case BFD_RELOC_PPC_TOC16:		r = R_PPC_TOC16;		break;
2053    case BFD_RELOC_PPC_TLS:		r = R_PPC_TLS;			break;
2054    case BFD_RELOC_PPC_DTPMOD:		r = R_PPC_DTPMOD32;		break;
2055    case BFD_RELOC_PPC_TPREL16:		r = R_PPC_TPREL16;		break;
2056    case BFD_RELOC_PPC_TPREL16_LO:	r = R_PPC_TPREL16_LO;		break;
2057    case BFD_RELOC_PPC_TPREL16_HI:	r = R_PPC_TPREL16_HI;		break;
2058    case BFD_RELOC_PPC_TPREL16_HA:	r = R_PPC_TPREL16_HA;		break;
2059    case BFD_RELOC_PPC_TPREL:		r = R_PPC_TPREL32;		break;
2060    case BFD_RELOC_PPC_DTPREL16:	r = R_PPC_DTPREL16;		break;
2061    case BFD_RELOC_PPC_DTPREL16_LO:	r = R_PPC_DTPREL16_LO;		break;
2062    case BFD_RELOC_PPC_DTPREL16_HI:	r = R_PPC_DTPREL16_HI;		break;
2063    case BFD_RELOC_PPC_DTPREL16_HA:	r = R_PPC_DTPREL16_HA;		break;
2064    case BFD_RELOC_PPC_DTPREL:		r = R_PPC_DTPREL32;		break;
2065    case BFD_RELOC_PPC_GOT_TLSGD16:	r = R_PPC_GOT_TLSGD16;		break;
2066    case BFD_RELOC_PPC_GOT_TLSGD16_LO:	r = R_PPC_GOT_TLSGD16_LO;	break;
2067    case BFD_RELOC_PPC_GOT_TLSGD16_HI:	r = R_PPC_GOT_TLSGD16_HI;	break;
2068    case BFD_RELOC_PPC_GOT_TLSGD16_HA:	r = R_PPC_GOT_TLSGD16_HA;	break;
2069    case BFD_RELOC_PPC_GOT_TLSLD16:	r = R_PPC_GOT_TLSLD16;		break;
2070    case BFD_RELOC_PPC_GOT_TLSLD16_LO:	r = R_PPC_GOT_TLSLD16_LO;	break;
2071    case BFD_RELOC_PPC_GOT_TLSLD16_HI:	r = R_PPC_GOT_TLSLD16_HI;	break;
2072    case BFD_RELOC_PPC_GOT_TLSLD16_HA:	r = R_PPC_GOT_TLSLD16_HA;	break;
2073    case BFD_RELOC_PPC_GOT_TPREL16:	r = R_PPC_GOT_TPREL16;		break;
2074    case BFD_RELOC_PPC_GOT_TPREL16_LO:	r = R_PPC_GOT_TPREL16_LO;	break;
2075    case BFD_RELOC_PPC_GOT_TPREL16_HI:	r = R_PPC_GOT_TPREL16_HI;	break;
2076    case BFD_RELOC_PPC_GOT_TPREL16_HA:	r = R_PPC_GOT_TPREL16_HA;	break;
2077    case BFD_RELOC_PPC_GOT_DTPREL16:	r = R_PPC_GOT_DTPREL16;		break;
2078    case BFD_RELOC_PPC_GOT_DTPREL16_LO:	r = R_PPC_GOT_DTPREL16_LO;	break;
2079    case BFD_RELOC_PPC_GOT_DTPREL16_HI:	r = R_PPC_GOT_DTPREL16_HI;	break;
2080    case BFD_RELOC_PPC_GOT_DTPREL16_HA:	r = R_PPC_GOT_DTPREL16_HA;	break;
2081    case BFD_RELOC_PPC_EMB_NADDR32:	r = R_PPC_EMB_NADDR32;		break;
2082    case BFD_RELOC_PPC_EMB_NADDR16:	r = R_PPC_EMB_NADDR16;		break;
2083    case BFD_RELOC_PPC_EMB_NADDR16_LO:	r = R_PPC_EMB_NADDR16_LO;	break;
2084    case BFD_RELOC_PPC_EMB_NADDR16_HI:	r = R_PPC_EMB_NADDR16_HI;	break;
2085    case BFD_RELOC_PPC_EMB_NADDR16_HA:	r = R_PPC_EMB_NADDR16_HA;	break;
2086    case BFD_RELOC_PPC_EMB_SDAI16:	r = R_PPC_EMB_SDAI16;		break;
2087    case BFD_RELOC_PPC_EMB_SDA2I16:	r = R_PPC_EMB_SDA2I16;		break;
2088    case BFD_RELOC_PPC_EMB_SDA2REL:	r = R_PPC_EMB_SDA2REL;		break;
2089    case BFD_RELOC_PPC_EMB_SDA21:	r = R_PPC_EMB_SDA21;		break;
2090    case BFD_RELOC_PPC_EMB_MRKREF:	r = R_PPC_EMB_MRKREF;		break;
2091    case BFD_RELOC_PPC_EMB_RELSEC16:	r = R_PPC_EMB_RELSEC16;		break;
2092    case BFD_RELOC_PPC_EMB_RELST_LO:	r = R_PPC_EMB_RELST_LO;		break;
2093    case BFD_RELOC_PPC_EMB_RELST_HI:	r = R_PPC_EMB_RELST_HI;		break;
2094    case BFD_RELOC_PPC_EMB_RELST_HA:	r = R_PPC_EMB_RELST_HA;		break;
2095    case BFD_RELOC_PPC_EMB_BIT_FLD:	r = R_PPC_EMB_BIT_FLD;		break;
2096    case BFD_RELOC_PPC_EMB_RELSDA:	r = R_PPC_EMB_RELSDA;		break;
2097    case BFD_RELOC_VTABLE_INHERIT:	r = R_PPC_GNU_VTINHERIT;	break;
2098    case BFD_RELOC_VTABLE_ENTRY:	r = R_PPC_GNU_VTENTRY;		break;
2099    }
2100
2101  return ppc_elf_howto_table[r];
2102};
2103
2104/* Set the howto pointer for a PowerPC ELF reloc.  */
2105
2106static void
2107ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
2108		       arelent *cache_ptr,
2109		       Elf_Internal_Rela *dst)
2110{
2111  /* Initialize howto table if not already done.  */
2112  if (!ppc_elf_howto_table[R_PPC_ADDR32])
2113    ppc_elf_howto_init ();
2114
2115  BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
2116  cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
2117}
2118
2119/* Handle the R_PPC_ADDR16_HA reloc.  */
2120
2121static bfd_reloc_status_type
2122ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED,
2123			 arelent *reloc_entry,
2124			 asymbol *symbol,
2125			 void *data ATTRIBUTE_UNUSED,
2126			 asection *input_section,
2127			 bfd *output_bfd,
2128			 char **error_message ATTRIBUTE_UNUSED)
2129{
2130  bfd_vma relocation;
2131
2132  if (output_bfd != NULL)
2133    {
2134      reloc_entry->address += input_section->output_offset;
2135      return bfd_reloc_ok;
2136    }
2137
2138  if (reloc_entry->address > input_section->_cooked_size)
2139    return bfd_reloc_outofrange;
2140
2141  if (bfd_is_com_section (symbol->section))
2142    relocation = 0;
2143  else
2144    relocation = symbol->value;
2145
2146  relocation += symbol->section->output_section->vma;
2147  relocation += symbol->section->output_offset;
2148  relocation += reloc_entry->addend;
2149
2150  reloc_entry->addend += (relocation & 0x8000) << 1;
2151
2152  return bfd_reloc_continue;
2153}
2154
2155static bfd_reloc_status_type
2156ppc_elf_unhandled_reloc (bfd *abfd,
2157			 arelent *reloc_entry,
2158			 asymbol *symbol,
2159			 void *data,
2160			 asection *input_section,
2161			 bfd *output_bfd,
2162			 char **error_message)
2163{
2164  /* If this is a relocatable link (output_bfd test tells us), just
2165     call the generic function.  Any adjustment will be done at final
2166     link time.  */
2167  if (output_bfd != NULL)
2168    return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2169				  input_section, output_bfd, error_message);
2170
2171  if (error_message != NULL)
2172    {
2173      static char buf[60];
2174      sprintf (buf, _("generic linker can't handle %s"),
2175	       reloc_entry->howto->name);
2176      *error_message = buf;
2177    }
2178  return bfd_reloc_dangerous;
2179}
2180
2181/* Fix bad default arch selected for a 32 bit input bfd when the
2182   default is 64 bit.  */
2183
2184static bfd_boolean
2185ppc_elf_object_p (bfd *abfd)
2186{
2187  if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
2188    {
2189      Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
2190
2191      if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
2192	{
2193	  /* Relies on arch after 64 bit default being 32 bit default.  */
2194	  abfd->arch_info = abfd->arch_info->next;
2195	  BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
2196	}
2197    }
2198  return TRUE;
2199}
2200
2201/* Function to set whether a module needs the -mrelocatable bit set.  */
2202
2203static bfd_boolean
2204ppc_elf_set_private_flags (bfd *abfd, flagword flags)
2205{
2206  BFD_ASSERT (!elf_flags_init (abfd)
2207	      || elf_elfheader (abfd)->e_flags == flags);
2208
2209  elf_elfheader (abfd)->e_flags = flags;
2210  elf_flags_init (abfd) = TRUE;
2211  return TRUE;
2212}
2213
2214/* Merge backend specific data from an object file to the output
2215   object file when linking.  */
2216
2217static bfd_boolean
2218ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
2219{
2220  flagword old_flags;
2221  flagword new_flags;
2222  bfd_boolean error;
2223
2224  /* Check if we have the same endianess.  */
2225  if (! _bfd_generic_verify_endian_match (ibfd, obfd))
2226    return FALSE;
2227
2228  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2229      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2230    return TRUE;
2231
2232  new_flags = elf_elfheader (ibfd)->e_flags;
2233  old_flags = elf_elfheader (obfd)->e_flags;
2234  if (!elf_flags_init (obfd))
2235    {
2236      /* First call, no flags set.  */
2237      elf_flags_init (obfd) = TRUE;
2238      elf_elfheader (obfd)->e_flags = new_flags;
2239    }
2240
2241  /* Compatible flags are ok.  */
2242  else if (new_flags == old_flags)
2243    ;
2244
2245  /* Incompatible flags.  */
2246  else
2247    {
2248      /* Warn about -mrelocatable mismatch.  Allow -mrelocatable-lib
2249	 to be linked with either.  */
2250      error = FALSE;
2251      if ((new_flags & EF_PPC_RELOCATABLE) != 0
2252	  && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
2253	{
2254	  error = TRUE;
2255	  (*_bfd_error_handler)
2256	    (_("%s: compiled with -mrelocatable and linked with "
2257	       "modules compiled normally"),
2258	     bfd_archive_filename (ibfd));
2259	}
2260      else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
2261	       && (old_flags & EF_PPC_RELOCATABLE) != 0)
2262	{
2263	  error = TRUE;
2264	  (*_bfd_error_handler)
2265	    (_("%s: compiled normally and linked with "
2266	       "modules compiled with -mrelocatable"),
2267	     bfd_archive_filename (ibfd));
2268	}
2269
2270      /* The output is -mrelocatable-lib iff both the input files are.  */
2271      if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
2272	elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
2273
2274      /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2275	 but each input file is either -mrelocatable or -mrelocatable-lib.  */
2276      if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
2277	  && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
2278	  && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
2279	elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
2280
2281      /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
2282	 any module uses it.  */
2283      elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
2284
2285      new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
2286      old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
2287
2288      /* Warn about any other mismatches.  */
2289      if (new_flags != old_flags)
2290	{
2291	  error = TRUE;
2292	  (*_bfd_error_handler)
2293	    (_("%s: uses different e_flags (0x%lx) fields "
2294	       "than previous modules (0x%lx)"),
2295	     bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
2296	}
2297
2298      if (error)
2299	{
2300	  bfd_set_error (bfd_error_bad_value);
2301	  return FALSE;
2302	}
2303    }
2304
2305  return TRUE;
2306}
2307
2308/* Handle a PowerPC specific section when reading an object file.  This
2309   is called when elfcode.h finds a section with an unknown type.  */
2310
2311static bfd_boolean
2312ppc_elf_section_from_shdr (bfd *abfd, Elf_Internal_Shdr *hdr, const char *name)
2313{
2314  asection *newsect;
2315  flagword flags;
2316
2317  if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
2318    return FALSE;
2319
2320  newsect = hdr->bfd_section;
2321  flags = bfd_get_section_flags (abfd, newsect);
2322  if (hdr->sh_flags & SHF_EXCLUDE)
2323    flags |= SEC_EXCLUDE;
2324
2325  if (hdr->sh_type == SHT_ORDERED)
2326    flags |= SEC_SORT_ENTRIES;
2327
2328  bfd_set_section_flags (abfd, newsect, flags);
2329  return TRUE;
2330}
2331
2332/* Set up any other section flags and such that may be necessary.  */
2333
2334static bfd_boolean
2335ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
2336		       Elf_Internal_Shdr *shdr,
2337		       asection *asect)
2338{
2339  if ((asect->flags & SEC_EXCLUDE) != 0)
2340    shdr->sh_flags |= SHF_EXCLUDE;
2341
2342  if ((asect->flags & SEC_SORT_ENTRIES) != 0)
2343    shdr->sh_type = SHT_ORDERED;
2344
2345  return TRUE;
2346}
2347
2348/* Find a linker generated pointer with a given addend and type.  */
2349
2350static elf_linker_section_pointers_t *
2351elf_find_pointer_linker_section
2352  (elf_linker_section_pointers_t *linker_pointers,
2353   bfd_vma addend,
2354   elf_linker_section_t *lsect)
2355{
2356  for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next)
2357    if (lsect == linker_pointers->lsect && addend == linker_pointers->addend)
2358      return linker_pointers;
2359
2360  return NULL;
2361}
2362
2363/* Allocate a pointer to live in a linker created section.  */
2364
2365static bfd_boolean
2366elf_create_pointer_linker_section (bfd *abfd,
2367				   struct bfd_link_info *info,
2368				   elf_linker_section_t *lsect,
2369				   struct elf_link_hash_entry *h,
2370				   const Elf_Internal_Rela *rel)
2371{
2372  elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL;
2373  elf_linker_section_pointers_t *linker_section_ptr;
2374  unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
2375  bfd_size_type amt;
2376
2377  BFD_ASSERT (lsect != NULL);
2378
2379  /* Is this a global symbol?  */
2380  if (h != NULL)
2381    {
2382      struct ppc_elf_link_hash_entry *eh;
2383
2384      /* Has this symbol already been allocated?  If so, our work is done.  */
2385      eh = (struct ppc_elf_link_hash_entry *) h;
2386      if (elf_find_pointer_linker_section (eh->linker_section_pointer,
2387					   rel->r_addend,
2388					   lsect))
2389	return TRUE;
2390
2391      ptr_linker_section_ptr = &eh->linker_section_pointer;
2392      /* Make sure this symbol is output as a dynamic symbol.  */
2393      if (h->dynindx == -1)
2394	{
2395	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
2396	    return FALSE;
2397	}
2398
2399      if (lsect->rel_section)
2400	lsect->rel_section->_raw_size += sizeof (Elf32_External_Rela);
2401    }
2402  else
2403    {
2404      /* Allocation of a pointer to a local symbol.  */
2405      elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
2406
2407      /* Allocate a table to hold the local symbols if first time.  */
2408      if (!ptr)
2409	{
2410	  unsigned int num_symbols = elf_tdata (abfd)->symtab_hdr.sh_info;
2411
2412	  amt = num_symbols;
2413	  amt *= sizeof (elf_linker_section_pointers_t *);
2414	  ptr = bfd_zalloc (abfd, amt);
2415
2416	  if (!ptr)
2417	    return FALSE;
2418
2419	  elf_local_ptr_offsets (abfd) = ptr;
2420	}
2421
2422      /* Has this symbol already been allocated?  If so, our work is done.  */
2423      if (elf_find_pointer_linker_section (ptr[r_symndx],
2424					   rel->r_addend,
2425					   lsect))
2426	return TRUE;
2427
2428      ptr_linker_section_ptr = &ptr[r_symndx];
2429
2430      if (info->shared)
2431	{
2432	  /* If we are generating a shared object, we need to
2433	     output a R_<xxx>_RELATIVE reloc so that the
2434	     dynamic linker can adjust this GOT entry.  */
2435	  BFD_ASSERT (lsect->rel_section != NULL);
2436	  lsect->rel_section->_raw_size += sizeof (Elf32_External_Rela);
2437	}
2438    }
2439
2440  /* Allocate space for a pointer in the linker section, and allocate
2441     a new pointer record from internal memory.  */
2442  BFD_ASSERT (ptr_linker_section_ptr != NULL);
2443  amt = sizeof (elf_linker_section_pointers_t);
2444  linker_section_ptr = bfd_alloc (abfd, amt);
2445
2446  if (!linker_section_ptr)
2447    return FALSE;
2448
2449  linker_section_ptr->next = *ptr_linker_section_ptr;
2450  linker_section_ptr->addend = rel->r_addend;
2451  linker_section_ptr->lsect = lsect;
2452  linker_section_ptr->written_address_p = FALSE;
2453  *ptr_linker_section_ptr = linker_section_ptr;
2454
2455  linker_section_ptr->offset = lsect->section->_raw_size;
2456  lsect->section->_raw_size += 4;
2457
2458#ifdef DEBUG
2459  fprintf (stderr,
2460	   "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2461	   lsect->name, (long) linker_section_ptr->offset,
2462	   (long) lsect->section->_raw_size);
2463#endif
2464
2465  return TRUE;
2466}
2467
2468#define bfd_put_ptr(BFD, VAL, ADDR) bfd_put_32 (BFD, VAL, ADDR)
2469
2470/* Fill in the address for a pointer generated in a linker section.  */
2471
2472static bfd_vma
2473elf_finish_pointer_linker_section (bfd *output_bfd,
2474				   bfd *input_bfd,
2475				   struct bfd_link_info *info,
2476				   elf_linker_section_t *lsect,
2477				   struct elf_link_hash_entry *h,
2478				   bfd_vma relocation,
2479				   const Elf_Internal_Rela *rel,
2480				   int relative_reloc)
2481{
2482  elf_linker_section_pointers_t *linker_section_ptr;
2483
2484  BFD_ASSERT (lsect != NULL);
2485
2486  if (h != NULL)
2487    {
2488      /* Handle global symbol.  */
2489      struct ppc_elf_link_hash_entry *eh;
2490
2491      eh = (struct ppc_elf_link_hash_entry *) h;
2492      linker_section_ptr
2493	= elf_find_pointer_linker_section (eh->linker_section_pointer,
2494					   rel->r_addend,
2495					   lsect);
2496
2497      BFD_ASSERT (linker_section_ptr != NULL);
2498
2499      if (! elf_hash_table (info)->dynamic_sections_created
2500	  || (info->shared
2501	      && info->symbolic
2502	      && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
2503	{
2504	  /* This is actually a static link, or it is a
2505	     -Bsymbolic link and the symbol is defined
2506	     locally.  We must initialize this entry in the
2507	     global section.
2508
2509	     When doing a dynamic link, we create a .rela.<xxx>
2510	     relocation entry to initialize the value.  This
2511	     is done in the finish_dynamic_symbol routine.  */
2512	  if (!linker_section_ptr->written_address_p)
2513	    {
2514	      linker_section_ptr->written_address_p = TRUE;
2515	      bfd_put_ptr (output_bfd,
2516			   relocation + linker_section_ptr->addend,
2517			   (lsect->section->contents
2518			    + linker_section_ptr->offset));
2519	    }
2520	}
2521    }
2522  else
2523    {
2524      /* Handle local symbol.  */
2525      unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
2526      BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
2527      BFD_ASSERT (elf_local_ptr_offsets (input_bfd)[r_symndx] != NULL);
2528      linker_section_ptr = (elf_find_pointer_linker_section
2529			    (elf_local_ptr_offsets (input_bfd)[r_symndx],
2530			     rel->r_addend,
2531			     lsect));
2532
2533      BFD_ASSERT (linker_section_ptr != NULL);
2534
2535      /* Write out pointer if it hasn't been rewritten out before.  */
2536      if (!linker_section_ptr->written_address_p)
2537	{
2538	  linker_section_ptr->written_address_p = TRUE;
2539	  bfd_put_ptr (output_bfd, relocation + linker_section_ptr->addend,
2540		       lsect->section->contents + linker_section_ptr->offset);
2541
2542	  if (info->shared)
2543	    {
2544	      /* We need to generate a relative reloc for the dynamic
2545		 linker.  */
2546
2547	      asection *srel = lsect->rel_section;
2548	      Elf_Internal_Rela outrel[MAX_INT_RELS_PER_EXT_REL];
2549	      bfd_byte *erel;
2550	      const struct elf_backend_data *bed;
2551	      unsigned int i;
2552
2553	      BFD_ASSERT (srel != NULL);
2554
2555	      bed = get_elf_backend_data (output_bfd);
2556	      for (i = 0; i < bed->s->int_rels_per_ext_rel; i++)
2557		{
2558		  outrel[i].r_offset = (lsect->section->output_section->vma
2559					+ lsect->section->output_offset
2560					+ linker_section_ptr->offset);
2561		  outrel[i].r_info = 0;
2562		  outrel[i].r_addend = 0;
2563		}
2564	      outrel[0].r_info = ELF32_R_INFO (0, relative_reloc);
2565	      erel = lsect->section->contents;
2566	      erel += (elf_section_data (lsect->section)->rel_count++
2567		       * sizeof (Elf32_External_Rela));
2568	      bfd_elf32_swap_reloca_out (output_bfd, outrel, erel);
2569	    }
2570	}
2571    }
2572
2573  relocation = (lsect->section->output_offset
2574		+ linker_section_ptr->offset
2575		- lsect->sym_offset);
2576
2577#ifdef DEBUG
2578  fprintf (stderr,
2579	   "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
2580	   lsect->name, (long) relocation, (long) relocation);
2581#endif
2582
2583  /* Subtract out the addend, because it will get added back in by the normal
2584     processing.  */
2585  return relocation - linker_section_ptr->addend;
2586}
2587
2588/* Create a special linker section */
2589static elf_linker_section_t *
2590ppc_elf_create_linker_section (bfd *abfd,
2591			       struct bfd_link_info *info,
2592			       enum elf_linker_section_enum which)
2593{
2594  elf_linker_section_t *lsect;
2595  struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
2596  asection *s;
2597  bfd_size_type amt;
2598  flagword flags;
2599  const char *name;
2600  const char *rel_name;
2601  const char *sym_name;
2602  bfd_vma sym_offset;
2603
2604  /* Both of these sections are (technically) created by the user
2605     putting data in them, so they shouldn't be marked
2606     SEC_LINKER_CREATED.
2607
2608     The linker creates them so it has somewhere to attach their
2609     respective symbols. In fact, if they were empty it would
2610     be OK to leave the symbol set to 0 (or any random number), because
2611     the appropriate register should never be used.  */
2612  flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
2613  sym_offset = 32768;
2614
2615  switch (which)
2616    {
2617    default:
2618      abort ();
2619      return NULL;
2620
2621    case LINKER_SECTION_SDATA:	/* .sdata/.sbss section */
2622      name	= ".sdata";
2623      rel_name	= ".rela.sdata";
2624      sym_name	= "_SDA_BASE_";
2625      break;
2626
2627    case LINKER_SECTION_SDATA2:	/* .sdata2/.sbss2 section */
2628      name	= ".sdata2";
2629      rel_name	= ".rela.sdata2";
2630      sym_name	= "_SDA2_BASE_";
2631      flags    |= SEC_READONLY;
2632      break;
2633    }
2634
2635  /* Record the first bfd that needs the special sections.  */
2636  if (!htab->elf.dynobj)
2637    htab->elf.dynobj = abfd;
2638
2639  amt = sizeof (elf_linker_section_t);
2640  lsect = bfd_zalloc (htab->elf.dynobj, amt);
2641
2642  lsect->sym_offset = sym_offset;
2643
2644  /* See if the sections already exist.  */
2645  s = bfd_get_section_by_name (htab->elf.dynobj, name);
2646  if (s == NULL || (s->flags & flags) != flags)
2647    {
2648      s = bfd_make_section_anyway (htab->elf.dynobj, name);
2649      if (s == NULL
2650	  || !bfd_set_section_flags (htab->elf.dynobj, s, flags))
2651	return NULL;
2652    }
2653  lsect->section = s;
2654
2655  if (bfd_get_section_alignment (htab->elf.dynobj, s) < 2
2656      && !bfd_set_section_alignment (htab->elf.dynobj, s, 2))
2657    return NULL;
2658
2659  s->_raw_size = align_power (s->_raw_size, 2);
2660
2661#ifdef DEBUG
2662  fprintf (stderr, "Creating section %s, current size = %ld\n",
2663	   name, (long) s->_raw_size);
2664#endif
2665
2666  if (sym_name)
2667    {
2668      struct elf_link_hash_entry *h;
2669      struct bfd_link_hash_entry *bh;
2670
2671#ifdef DEBUG
2672      fprintf (stderr, "Adding %s to section %s\n", sym_name, name);
2673#endif
2674      bh = bfd_link_hash_lookup (info->hash, sym_name,
2675				 FALSE, FALSE, FALSE);
2676
2677      if ((bh == NULL || bh->type == bfd_link_hash_undefined)
2678	  && !(_bfd_generic_link_add_one_symbol
2679	       (info, abfd, sym_name, BSF_GLOBAL, s, sym_offset, NULL,
2680		FALSE, get_elf_backend_data (abfd)->collect, &bh)))
2681	return NULL;
2682      h = (struct elf_link_hash_entry *) bh;
2683
2684      h->type = STT_OBJECT;
2685      lsect->sym_hash = h;
2686
2687      if (info->shared
2688	  && ! bfd_elf_link_record_dynamic_symbol (info, h))
2689	return NULL;
2690    }
2691
2692  if (info->shared)
2693    {
2694      s = bfd_make_section_anyway (htab->elf.dynobj, rel_name);
2695      lsect->rel_section = s;
2696      flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2697	       | SEC_LINKER_CREATED | SEC_READONLY);
2698      if (s == NULL
2699	  || ! bfd_set_section_flags (htab->elf.dynobj, s, flags)
2700	  || ! bfd_set_section_alignment (htab->elf.dynobj, s, 2))
2701	return NULL;
2702    }
2703
2704  return lsect;
2705}
2706
2707/* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2708   need to bump up the number of section headers.  */
2709
2710static int
2711ppc_elf_additional_program_headers (bfd *abfd)
2712{
2713  asection *s;
2714  int ret;
2715
2716  ret = 0;
2717
2718  s = bfd_get_section_by_name (abfd, ".interp");
2719  if (s != NULL)
2720    ++ret;
2721
2722  s = bfd_get_section_by_name (abfd, ".sbss2");
2723  if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
2724    ++ret;
2725
2726  s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
2727  if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
2728    ++ret;
2729
2730  return ret;
2731}
2732
2733/* Modify the segment map if needed.  */
2734
2735static bfd_boolean
2736ppc_elf_modify_segment_map (bfd *abfd ATTRIBUTE_UNUSED,
2737			    struct bfd_link_info *info ATTRIBUTE_UNUSED)
2738{
2739  return TRUE;
2740}
2741
2742/* The powerpc .got has a blrl instruction in it.  Mark it executable.  */
2743
2744static bfd_boolean
2745ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info)
2746{
2747  struct ppc_elf_link_hash_table *htab;
2748  asection *s;
2749  flagword flags;
2750
2751  if (!_bfd_elf_create_got_section (abfd, info))
2752    return FALSE;
2753
2754  htab = ppc_elf_hash_table (info);
2755  htab->got = s = bfd_get_section_by_name (abfd, ".got");
2756  if (s == NULL)
2757    abort ();
2758
2759  flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2760	   | SEC_LINKER_CREATED);
2761  if (!bfd_set_section_flags (abfd, s, flags))
2762    return FALSE;
2763
2764  htab->relgot = bfd_make_section (abfd, ".rela.got");
2765  if (!htab->relgot
2766      || ! bfd_set_section_flags (abfd, htab->relgot,
2767				  (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2768				   | SEC_IN_MEMORY | SEC_LINKER_CREATED
2769				   | SEC_READONLY))
2770      || ! bfd_set_section_alignment (abfd, htab->relgot, 2))
2771    return FALSE;
2772
2773  return TRUE;
2774}
2775
2776/* We have to create .dynsbss and .rela.sbss here so that they get mapped
2777   to output sections (just like _bfd_elf_create_dynamic_sections has
2778   to create .dynbss and .rela.bss).  */
2779
2780static bfd_boolean
2781ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2782{
2783  struct ppc_elf_link_hash_table *htab;
2784  asection *s;
2785  flagword flags;
2786
2787  htab = ppc_elf_hash_table (info);
2788
2789  if (htab->got == NULL
2790      && !ppc_elf_create_got (abfd, info))
2791    return FALSE;
2792
2793  if (!_bfd_elf_create_dynamic_sections (abfd, info))
2794    return FALSE;
2795
2796  flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2797	   | SEC_LINKER_CREATED);
2798
2799  htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
2800  htab->dynsbss = s = bfd_make_section (abfd, ".dynsbss");
2801  if (s == NULL
2802      || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
2803    return FALSE;
2804
2805  if (! info->shared)
2806    {
2807      htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
2808      htab->relsbss = s = bfd_make_section (abfd, ".rela.sbss");
2809      if (s == NULL
2810	  || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2811	  || ! bfd_set_section_alignment (abfd, s, 2))
2812	return FALSE;
2813    }
2814
2815  htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
2816  htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
2817  if (s == NULL)
2818    abort ();
2819
2820  flags = SEC_ALLOC | SEC_CODE | SEC_IN_MEMORY | SEC_LINKER_CREATED;
2821  return bfd_set_section_flags (abfd, s, flags);
2822}
2823
2824/* Adjust a symbol defined by a dynamic object and referenced by a
2825   regular object.  The current definition is in some section of the
2826   dynamic object, but we're not including those sections.  We have to
2827   change the definition to something the rest of the link can
2828   understand.  */
2829
2830static bfd_boolean
2831ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
2832			       struct elf_link_hash_entry *h)
2833{
2834  struct ppc_elf_link_hash_table *htab;
2835  asection *s;
2836  unsigned int power_of_two;
2837
2838#ifdef DEBUG
2839  fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
2840	   h->root.root.string);
2841#endif
2842
2843  /* Make sure we know what is going on here.  */
2844  htab = ppc_elf_hash_table (info);
2845  BFD_ASSERT (htab->elf.dynobj != NULL
2846	      && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
2847		  || h->weakdef != NULL
2848		  || ((h->elf_link_hash_flags
2849		       & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2850		      && (h->elf_link_hash_flags
2851			  & ELF_LINK_HASH_REF_REGULAR) != 0
2852		      && (h->elf_link_hash_flags
2853			  & ELF_LINK_HASH_DEF_REGULAR) == 0)));
2854
2855  /* Deal with function syms.  */
2856  if (h->type == STT_FUNC
2857      || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2858    {
2859      /* Clear procedure linkage table information for any symbol that
2860	 won't need a .plt entry.  */
2861      if (h->plt.refcount <= 0
2862	  || SYMBOL_CALLS_LOCAL (info, h)
2863	  || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2864	      && h->root.type == bfd_link_hash_undefweak))
2865	{
2866	  /* A PLT entry is not required/allowed when:
2867
2868	     1. We are not using ld.so; because then the PLT entry
2869	     can't be set up, so we can't use one.  In this case,
2870	     ppc_elf_adjust_dynamic_symbol won't even be called.
2871
2872	     2. GC has rendered the entry unused.
2873
2874	     3. We know for certain that a call to this symbol
2875	     will go to this object, or will remain undefined.  */
2876	  h->plt.offset = (bfd_vma) -1;
2877	  h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2878	}
2879      return TRUE;
2880    }
2881  else
2882    h->plt.offset = (bfd_vma) -1;
2883
2884  /* If this is a weak symbol, and there is a real definition, the
2885     processor independent code will have arranged for us to see the
2886     real definition first, and we can just use the same value.  */
2887  if (h->weakdef != NULL)
2888    {
2889      BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
2890		  || h->weakdef->root.type == bfd_link_hash_defweak);
2891      h->root.u.def.section = h->weakdef->root.u.def.section;
2892      h->root.u.def.value = h->weakdef->root.u.def.value;
2893      if (ELIMINATE_COPY_RELOCS)
2894	h->elf_link_hash_flags
2895	  = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
2896	     | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
2897      return TRUE;
2898    }
2899
2900  /* This is a reference to a symbol defined by a dynamic object which
2901     is not a function.  */
2902
2903  /* If we are creating a shared library, we must presume that the
2904     only references to the symbol are via the global offset table.
2905     For such cases we need not do anything here; the relocations will
2906     be handled correctly by relocate_section.  */
2907  if (info->shared)
2908    return TRUE;
2909
2910  /* If there are no references to this symbol that do not use the
2911     GOT, we don't need to generate a copy reloc.  */
2912  if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
2913    return TRUE;
2914
2915  if (ELIMINATE_COPY_RELOCS)
2916    {
2917      struct ppc_elf_dyn_relocs *p;
2918      for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
2919	{
2920	  s = p->sec->output_section;
2921	  if (s != NULL && (s->flags & SEC_READONLY) != 0)
2922	    break;
2923	}
2924
2925      /* If we didn't find any dynamic relocs in read-only sections, then
2926	 we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
2927      if (p == NULL)
2928	{
2929	  h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
2930	  return TRUE;
2931	}
2932    }
2933
2934  /* We must allocate the symbol in our .dynbss section, which will
2935     become part of the .bss section of the executable.  There will be
2936     an entry for this symbol in the .dynsym section.  The dynamic
2937     object will contain position independent code, so all references
2938     from the dynamic object to this symbol will go through the global
2939     offset table.  The dynamic linker will use the .dynsym entry to
2940     determine the address it must put in the global offset table, so
2941     both the dynamic object and the regular object will refer to the
2942     same memory location for the variable.
2943
2944     Of course, if the symbol is sufficiently small, we must instead
2945     allocate it in .sbss.  FIXME: It would be better to do this if and
2946     only if there were actually SDAREL relocs for that symbol.  */
2947
2948  if (h->size <= elf_gp_size (htab->elf.dynobj))
2949    s = htab->dynsbss;
2950  else
2951    s = htab->dynbss;
2952  BFD_ASSERT (s != NULL);
2953
2954  /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2955     copy the initial value out of the dynamic object and into the
2956     runtime process image.  We need to remember the offset into the
2957     .rela.bss section we are going to use.  */
2958  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2959    {
2960      asection *srel;
2961
2962      if (h->size <= elf_gp_size (htab->elf.dynobj))
2963	srel = htab->relsbss;
2964      else
2965	srel = htab->relbss;
2966      BFD_ASSERT (srel != NULL);
2967      srel->_raw_size += sizeof (Elf32_External_Rela);
2968      h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
2969    }
2970
2971  /* We need to figure out the alignment required for this symbol.  I
2972     have no idea how ELF linkers handle this.  */
2973  power_of_two = bfd_log2 (h->size);
2974  if (power_of_two > 4)
2975    power_of_two = 4;
2976
2977  /* Apply the required alignment.  */
2978  s->_raw_size = BFD_ALIGN (s->_raw_size,
2979			    (bfd_size_type) (1 << power_of_two));
2980  if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
2981    {
2982      if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
2983	return FALSE;
2984    }
2985
2986  /* Define the symbol as being at this point in the section.  */
2987  h->root.u.def.section = s;
2988  h->root.u.def.value = s->_raw_size;
2989
2990  /* Increment the section size to make room for the symbol.  */
2991  s->_raw_size += h->size;
2992
2993  return TRUE;
2994}
2995
2996/* Of those relocs that might be copied as dynamic relocs, this macro
2997   selects those that must be copied when linking a shared library,
2998   even when the symbol is local.  */
2999
3000#define MUST_BE_DYN_RELOC(RTYPE)		\
3001  ((RTYPE) != R_PPC_REL24			\
3002   && (RTYPE) != R_PPC_REL14			\
3003   && (RTYPE) != R_PPC_REL14_BRTAKEN		\
3004   && (RTYPE) != R_PPC_REL14_BRNTAKEN		\
3005   && (RTYPE) != R_PPC_REL32)
3006
3007/* Allocate space in associated reloc sections for dynamic relocs.  */
3008
3009static bfd_boolean
3010allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
3011{
3012  struct bfd_link_info *info = inf;
3013  struct ppc_elf_link_hash_entry *eh;
3014  struct ppc_elf_link_hash_table *htab;
3015  struct ppc_elf_dyn_relocs *p;
3016
3017  if (h->root.type == bfd_link_hash_indirect)
3018    return TRUE;
3019
3020  if (h->root.type == bfd_link_hash_warning)
3021    /* When warning symbols are created, they **replace** the "real"
3022       entry in the hash table, thus we never get to see the real
3023       symbol in a hash traversal.  So look at it now.  */
3024    h = (struct elf_link_hash_entry *) h->root.u.i.link;
3025
3026  htab = ppc_elf_hash_table (info);
3027  if (htab->elf.dynamic_sections_created
3028      && h->plt.refcount > 0)
3029    {
3030      /* Make sure this symbol is output as a dynamic symbol.  */
3031      if (h->dynindx == -1
3032	  && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3033	{
3034	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
3035	    return FALSE;
3036	}
3037
3038      if (info->shared
3039	  || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
3040	{
3041	  asection *s = htab->plt;
3042
3043	  /* If this is the first .plt entry, make room for the special
3044	     first entry.  */
3045	  if (s->_raw_size == 0)
3046	    s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
3047
3048	  /* The PowerPC PLT is actually composed of two parts, the
3049	     first part is 2 words (for a load and a jump), and then
3050	     there is a remaining word available at the end.  */
3051	  h->plt.offset = (PLT_INITIAL_ENTRY_SIZE
3052			   + (PLT_SLOT_SIZE
3053			      * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE)
3054				 / PLT_ENTRY_SIZE)));
3055
3056	  /* If this symbol is not defined in a regular file, and we
3057	     are not generating a shared library, then set the symbol
3058	     to this location in the .plt.  This is required to make
3059	     function pointers compare as equal between the normal
3060	     executable and the shared library.  */
3061	  if (! info->shared
3062	      && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3063	    {
3064	      h->root.u.def.section = s;
3065	      h->root.u.def.value = h->plt.offset;
3066	    }
3067
3068	  /* Make room for this entry.  After the 8192nd entry, room
3069	     for two entries is allocated.  */
3070	  s->_raw_size += PLT_ENTRY_SIZE;
3071	  if ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
3072	      > PLT_NUM_SINGLE_ENTRIES)
3073	    s->_raw_size += PLT_ENTRY_SIZE;
3074
3075	  /* We also need to make an entry in the .rela.plt section.  */
3076	  htab->relplt->_raw_size += sizeof (Elf32_External_Rela);
3077	}
3078      else
3079	{
3080	  h->plt.offset = (bfd_vma) -1;
3081	  h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3082	}
3083    }
3084  else
3085    {
3086      h->plt.offset = (bfd_vma) -1;
3087      h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3088    }
3089
3090  eh = (struct ppc_elf_link_hash_entry *) h;
3091  if (eh->elf.got.refcount > 0)
3092    {
3093      /* Make sure this symbol is output as a dynamic symbol.  */
3094      if (eh->elf.dynindx == -1
3095	  && (eh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3096	{
3097	  if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
3098	    return FALSE;
3099	}
3100
3101      if (eh->tls_mask == (TLS_TLS | TLS_LD)
3102	  && !(eh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))
3103	/* If just an LD reloc, we'll just use htab->tlsld_got.offset.  */
3104	eh->elf.got.offset = (bfd_vma) -1;
3105      else
3106	{
3107	  bfd_boolean dyn;
3108	  eh->elf.got.offset = htab->got->_raw_size;
3109	  if ((eh->tls_mask & TLS_TLS) != 0)
3110	    {
3111	      if ((eh->tls_mask & TLS_LD) != 0)
3112		htab->got->_raw_size += 8;
3113	      if ((eh->tls_mask & TLS_GD) != 0)
3114		htab->got->_raw_size += 8;
3115	      if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
3116		htab->got->_raw_size += 4;
3117	      if ((eh->tls_mask & TLS_DTPREL) != 0)
3118		htab->got->_raw_size += 4;
3119	    }
3120	  else
3121	    htab->got->_raw_size += 4;
3122	  dyn = htab->elf.dynamic_sections_created;
3123	  if ((info->shared
3124	       || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
3125	      && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
3126		  || eh->elf.root.type != bfd_link_hash_undefweak))
3127	    {
3128	      /* All the entries we allocated need relocs.  */
3129	      htab->relgot->_raw_size
3130		+= ((htab->got->_raw_size - eh->elf.got.offset) / 4
3131		    * sizeof (Elf32_External_Rela));
3132	      /* Except LD only needs one.  */
3133	      if ((eh->tls_mask & TLS_LD) != 0)
3134		htab->relgot->_raw_size -= sizeof (Elf32_External_Rela);
3135	    }
3136	}
3137    }
3138  else
3139    eh->elf.got.offset = (bfd_vma) -1;
3140
3141  if (eh->dyn_relocs == NULL)
3142    return TRUE;
3143
3144  /* In the shared -Bsymbolic case, discard space allocated for
3145     dynamic pc-relative relocs against symbols which turn out to be
3146     defined in regular objects.  For the normal shared case, discard
3147     space for relocs that have become local due to symbol visibility
3148     changes.  */
3149
3150  if (info->shared)
3151    {
3152      /* Relocs that use pc_count are those that appear on a call insn,
3153	 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
3154	 generated via assembly.  We want calls to protected symbols to
3155	 resolve directly to the function rather than going via the plt.
3156	 If people want function pointer comparisons to work as expected
3157	 then they should avoid writing weird assembly.  */
3158      if (SYMBOL_CALLS_LOCAL (info, h))
3159	{
3160	  struct ppc_elf_dyn_relocs **pp;
3161
3162	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3163	    {
3164	      p->count -= p->pc_count;
3165	      p->pc_count = 0;
3166	      if (p->count == 0)
3167		*pp = p->next;
3168	      else
3169		pp = &p->next;
3170	    }
3171	}
3172
3173      /* Also discard relocs on undefined weak syms with non-default
3174	 visibility.  */
3175      if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3176	  && h->root.type == bfd_link_hash_undefweak)
3177	eh->dyn_relocs = NULL;
3178
3179      /* Make sure undefined weak symbols are output as a dynamic symbol
3180	 in PIEs.  */
3181      if (info->pie
3182	  && eh->dyn_relocs != NULL
3183	  && h->dynindx == -1
3184	  && h->root.type == bfd_link_hash_undefweak
3185	  && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3186	{
3187	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
3188	    return FALSE;
3189	}
3190    }
3191  else if (ELIMINATE_COPY_RELOCS)
3192    {
3193      /* For the non-shared case, discard space for relocs against
3194	 symbols which turn out to need copy relocs or are not
3195	 dynamic.  */
3196
3197      if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
3198	  && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3199	  && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3200	{
3201	  /* Make sure this symbol is output as a dynamic symbol.
3202	     Undefined weak syms won't yet be marked as dynamic.  */
3203	  if (h->dynindx == -1
3204	      && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3205	    {
3206	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
3207		return FALSE;
3208	    }
3209
3210	  /* If that succeeded, we know we'll be keeping all the
3211	     relocs.  */
3212	  if (h->dynindx != -1)
3213	    goto keep;
3214	}
3215
3216      eh->dyn_relocs = NULL;
3217
3218    keep: ;
3219    }
3220
3221  /* Finally, allocate space.  */
3222  for (p = eh->dyn_relocs; p != NULL; p = p->next)
3223    {
3224      asection *sreloc = elf_section_data (p->sec)->sreloc;
3225      sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
3226    }
3227
3228  return TRUE;
3229}
3230
3231/* Find any dynamic relocs that apply to read-only sections.  */
3232
3233static bfd_boolean
3234readonly_dynrelocs (struct elf_link_hash_entry *h, void *info)
3235{
3236  struct ppc_elf_dyn_relocs *p;
3237
3238  if (h->root.type == bfd_link_hash_indirect)
3239    return TRUE;
3240
3241  if (h->root.type == bfd_link_hash_warning)
3242    h = (struct elf_link_hash_entry *) h->root.u.i.link;
3243
3244  for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
3245    {
3246      asection *s = p->sec->output_section;
3247
3248      if (s != NULL
3249	  && ((s->flags & (SEC_READONLY | SEC_ALLOC))
3250	      == (SEC_READONLY | SEC_ALLOC)))
3251	{
3252	  ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
3253
3254	  /* Not an error, just cut short the traversal.  */
3255	  return FALSE;
3256	}
3257    }
3258  return TRUE;
3259}
3260
3261/* Set the sizes of the dynamic sections.  */
3262
3263static bfd_boolean
3264ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3265			       struct bfd_link_info *info)
3266{
3267  struct ppc_elf_link_hash_table *htab;
3268  asection *s;
3269  bfd_boolean relocs;
3270  bfd *ibfd;
3271
3272#ifdef DEBUG
3273  fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
3274#endif
3275
3276  htab = ppc_elf_hash_table (info);
3277  BFD_ASSERT (htab->elf.dynobj != NULL);
3278
3279  if (elf_hash_table (info)->dynamic_sections_created)
3280    {
3281      /* Set the contents of the .interp section to the interpreter.  */
3282      if (info->executable)
3283	{
3284	  s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
3285	  BFD_ASSERT (s != NULL);
3286	  s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
3287	  s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3288	}
3289    }
3290
3291  if (htab->tlsld_got.refcount > 0)
3292    {
3293      htab->tlsld_got.offset = htab->got->_raw_size;
3294      htab->got->_raw_size += 8;
3295      if (info->shared)
3296	htab->relgot->_raw_size += sizeof (Elf32_External_Rela);
3297    }
3298  else
3299    htab->tlsld_got.offset = (bfd_vma) -1;
3300
3301  /* Set up .got offsets for local syms, and space for local dynamic
3302     relocs.  */
3303  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
3304    {
3305      bfd_signed_vma *local_got;
3306      bfd_signed_vma *end_local_got;
3307      char *lgot_masks;
3308      bfd_size_type locsymcount;
3309      Elf_Internal_Shdr *symtab_hdr;
3310      asection *srel;
3311
3312      if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
3313	continue;
3314
3315      for (s = ibfd->sections; s != NULL; s = s->next)
3316	{
3317	  struct ppc_elf_dyn_relocs *p;
3318
3319	  for (p = ((struct ppc_elf_dyn_relocs *)
3320		    elf_section_data (s)->local_dynrel);
3321	       p != NULL;
3322	       p = p->next)
3323	    {
3324	      if (!bfd_is_abs_section (p->sec)
3325		  && bfd_is_abs_section (p->sec->output_section))
3326		{
3327		  /* Input section has been discarded, either because
3328		     it is a copy of a linkonce section or due to
3329		     linker script /DISCARD/, so we'll be discarding
3330		     the relocs too.  */
3331		}
3332	      else if (p->count != 0)
3333		{
3334		  elf_section_data (p->sec)->sreloc->_raw_size
3335		    += p->count * sizeof (Elf32_External_Rela);
3336		  if ((p->sec->output_section->flags
3337		       & (SEC_READONLY | SEC_ALLOC))
3338		      == (SEC_READONLY | SEC_ALLOC))
3339		    info->flags |= DF_TEXTREL;
3340		}
3341	    }
3342	}
3343
3344      local_got = elf_local_got_refcounts (ibfd);
3345      if (!local_got)
3346	continue;
3347
3348      symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3349      locsymcount = symtab_hdr->sh_info;
3350      end_local_got = local_got + locsymcount;
3351      lgot_masks = (char *) end_local_got;
3352      s = htab->got;
3353      srel = htab->relgot;
3354      for (; local_got < end_local_got; ++local_got, ++lgot_masks)
3355	if (*local_got > 0)
3356	  {
3357	    if (*lgot_masks == (TLS_TLS | TLS_LD))
3358	      {
3359		/* If just an LD reloc, we'll just use
3360		   htab->tlsld_got.offset.  */
3361		if (htab->tlsld_got.offset == (bfd_vma) -1)
3362		  {
3363		    htab->tlsld_got.offset = s->_raw_size;
3364		    s->_raw_size += 8;
3365		    if (info->shared)
3366		      srel->_raw_size += sizeof (Elf32_External_Rela);
3367		  }
3368		*local_got = (bfd_vma) -1;
3369	      }
3370	    else
3371	      {
3372		*local_got = s->_raw_size;
3373		if ((*lgot_masks & TLS_TLS) != 0)
3374		  {
3375		    if ((*lgot_masks & TLS_GD) != 0)
3376		      s->_raw_size += 8;
3377		    if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
3378		      s->_raw_size += 4;
3379		    if ((*lgot_masks & TLS_DTPREL) != 0)
3380		      s->_raw_size += 4;
3381		  }
3382		else
3383		  s->_raw_size += 4;
3384		if (info->shared)
3385		  srel->_raw_size += ((s->_raw_size - *local_got) / 4
3386				      * sizeof (Elf32_External_Rela));
3387	      }
3388	  }
3389	else
3390	  *local_got = (bfd_vma) -1;
3391    }
3392
3393  /* Allocate space for global sym dynamic relocs.  */
3394  elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
3395
3396  /* We've now determined the sizes of the various dynamic sections.
3397     Allocate memory for them.  */
3398  relocs = FALSE;
3399  for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
3400    {
3401      if ((s->flags & SEC_LINKER_CREATED) == 0)
3402	continue;
3403
3404      if (s == htab->plt
3405	  || s == htab->got
3406	  || (htab->sdata != NULL && s == htab->sdata->section)
3407	  || (htab->sdata2 != NULL && s == htab->sdata2->section))
3408	{
3409	  /* Strip this section if we don't need it; see the
3410	     comment below.  */
3411	}
3412      else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
3413	{
3414	  if (s->_raw_size == 0)
3415	    {
3416	      /* If we don't need this section, strip it from the
3417		 output file.  This is mostly to handle .rela.bss and
3418		 .rela.plt.  We must create both sections in
3419		 create_dynamic_sections, because they must be created
3420		 before the linker maps input sections to output
3421		 sections.  The linker does that before
3422		 adjust_dynamic_symbol is called, and it is that
3423		 function which decides whether anything needs to go
3424		 into these sections.  */
3425	    }
3426	  else
3427	    {
3428	      /* Remember whether there are any relocation sections.  */
3429	      relocs = TRUE;
3430
3431	      /* We use the reloc_count field as a counter if we need
3432		 to copy relocs into the output file.  */
3433	      s->reloc_count = 0;
3434	    }
3435	}
3436      else
3437	{
3438	  /* It's not one of our sections, so don't allocate space.  */
3439	  continue;
3440	}
3441
3442      if (s->_raw_size == 0)
3443	{
3444	  _bfd_strip_section_from_output (info, s);
3445	  continue;
3446	}
3447
3448      /* Allocate memory for the section contents.  */
3449      s->contents = bfd_zalloc (htab->elf.dynobj, s->_raw_size);
3450      if (s->contents == NULL)
3451	return FALSE;
3452    }
3453
3454  if (htab->elf.dynamic_sections_created)
3455    {
3456      /* Add some entries to the .dynamic section.  We fill in the
3457	 values later, in ppc_elf_finish_dynamic_sections, but we
3458	 must add the entries now so that we get the correct size for
3459	 the .dynamic section.  The DT_DEBUG entry is filled in by the
3460	 dynamic linker and used by the debugger.  */
3461#define add_dynamic_entry(TAG, VAL) \
3462  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3463
3464      if (info->executable)
3465	{
3466	  if (!add_dynamic_entry (DT_DEBUG, 0))
3467	    return FALSE;
3468	}
3469
3470      if (htab->plt != NULL && htab->plt->_raw_size != 0)
3471	{
3472	  if (!add_dynamic_entry (DT_PLTGOT, 0)
3473	      || !add_dynamic_entry (DT_PLTRELSZ, 0)
3474	      || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3475	      || !add_dynamic_entry (DT_JMPREL, 0))
3476	    return FALSE;
3477	}
3478
3479      if (relocs)
3480	{
3481	  if (!add_dynamic_entry (DT_RELA, 0)
3482	      || !add_dynamic_entry (DT_RELASZ, 0)
3483	      || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
3484	    return FALSE;
3485	}
3486
3487      /* If any dynamic relocs apply to a read-only section, then we
3488	 need a DT_TEXTREL entry.  */
3489      if ((info->flags & DF_TEXTREL) == 0)
3490	elf_link_hash_traverse (elf_hash_table (info), readonly_dynrelocs,
3491				info);
3492
3493      if ((info->flags & DF_TEXTREL) != 0)
3494	{
3495	  if (!add_dynamic_entry (DT_TEXTREL, 0))
3496	    return FALSE;
3497	}
3498    }
3499#undef add_dynamic_entry
3500
3501  return TRUE;
3502}
3503
3504static bfd_boolean
3505update_local_sym_info (bfd *abfd,
3506		       Elf_Internal_Shdr *symtab_hdr,
3507		       unsigned long r_symndx,
3508		       int tls_type)
3509{
3510  bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
3511  char *local_got_tls_masks;
3512
3513  if (local_got_refcounts == NULL)
3514    {
3515      bfd_size_type size = symtab_hdr->sh_info;
3516
3517      size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks);
3518      local_got_refcounts = bfd_zalloc (abfd, size);
3519      if (local_got_refcounts == NULL)
3520	return FALSE;
3521      elf_local_got_refcounts (abfd) = local_got_refcounts;
3522    }
3523
3524  local_got_refcounts[r_symndx] += 1;
3525  local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info);
3526  local_got_tls_masks[r_symndx] |= tls_type;
3527  return TRUE;
3528}
3529
3530static void
3531bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type)
3532{
3533  (*_bfd_error_handler)
3534    (_("%s: relocation %s cannot be used when making a shared object"),
3535     bfd_archive_filename (abfd),
3536     ppc_elf_howto_table[r_type]->name);
3537  bfd_set_error (bfd_error_bad_value);
3538}
3539
3540/* Look through the relocs for a section during the first phase, and
3541   allocate space in the global offset table or procedure linkage
3542   table.  */
3543
3544static bfd_boolean
3545ppc_elf_check_relocs (bfd *abfd,
3546		      struct bfd_link_info *info,
3547		      asection *sec,
3548		      const Elf_Internal_Rela *relocs)
3549{
3550  struct ppc_elf_link_hash_table *htab;
3551  Elf_Internal_Shdr *symtab_hdr;
3552  struct elf_link_hash_entry **sym_hashes;
3553  const Elf_Internal_Rela *rel;
3554  const Elf_Internal_Rela *rel_end;
3555  asection *sreloc;
3556
3557  if (info->relocatable)
3558    return TRUE;
3559
3560#ifdef DEBUG
3561  fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n",
3562	   bfd_get_section_name (abfd, sec),
3563	   bfd_archive_filename (abfd));
3564#endif
3565
3566  /* Initialize howto table if not already done.  */
3567  if (!ppc_elf_howto_table[R_PPC_ADDR32])
3568    ppc_elf_howto_init ();
3569
3570  /* Create the linker generated sections all the time so that the
3571     special symbols are created.  */
3572  htab = ppc_elf_hash_table (info);
3573  if (htab->sdata == NULL)
3574    {
3575      htab->sdata = ppc_elf_create_linker_section (abfd, info,
3576						   LINKER_SECTION_SDATA);
3577      if (htab->sdata == NULL)
3578	return FALSE;
3579    }
3580
3581  if (htab->sdata2 == NULL)
3582    {
3583      htab->sdata2 = ppc_elf_create_linker_section (abfd, info,
3584						    LINKER_SECTION_SDATA2);
3585      if (htab->sdata2 == NULL)
3586	return FALSE;
3587    }
3588
3589  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3590  sym_hashes = elf_sym_hashes (abfd);
3591  sreloc = NULL;
3592
3593  rel_end = relocs + sec->reloc_count;
3594  for (rel = relocs; rel < rel_end; rel++)
3595    {
3596      unsigned long r_symndx;
3597      enum elf_ppc_reloc_type r_type;
3598      struct elf_link_hash_entry *h;
3599      int tls_type = 0;
3600
3601      r_symndx = ELF32_R_SYM (rel->r_info);
3602      if (r_symndx < symtab_hdr->sh_info)
3603	h = NULL;
3604      else
3605	h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3606
3607      /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3608	 This shows up in particular in an R_PPC_ADDR32 in the eabi
3609	 startup code.  */
3610      if (h && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3611	{
3612	  if (htab->got == NULL)
3613	    {
3614	      if (htab->elf.dynobj == NULL)
3615		htab->elf.dynobj = abfd;
3616	      if (!ppc_elf_create_got (htab->elf.dynobj, info))
3617		return FALSE;
3618	    }
3619	}
3620
3621      r_type = ELF32_R_TYPE (rel->r_info);
3622      switch (r_type)
3623	{
3624	case R_PPC_GOT_TLSLD16:
3625	case R_PPC_GOT_TLSLD16_LO:
3626	case R_PPC_GOT_TLSLD16_HI:
3627	case R_PPC_GOT_TLSLD16_HA:
3628	  htab->tlsld_got.refcount += 1;
3629	  tls_type = TLS_TLS | TLS_LD;
3630	  goto dogottls;
3631
3632	case R_PPC_GOT_TLSGD16:
3633	case R_PPC_GOT_TLSGD16_LO:
3634	case R_PPC_GOT_TLSGD16_HI:
3635	case R_PPC_GOT_TLSGD16_HA:
3636	  tls_type = TLS_TLS | TLS_GD;
3637	  goto dogottls;
3638
3639	case R_PPC_GOT_TPREL16:
3640	case R_PPC_GOT_TPREL16_LO:
3641	case R_PPC_GOT_TPREL16_HI:
3642	case R_PPC_GOT_TPREL16_HA:
3643	  if (info->shared)
3644	    info->flags |= DF_STATIC_TLS;
3645	  tls_type = TLS_TLS | TLS_TPREL;
3646	  goto dogottls;
3647
3648	case R_PPC_GOT_DTPREL16:
3649	case R_PPC_GOT_DTPREL16_LO:
3650	case R_PPC_GOT_DTPREL16_HI:
3651	case R_PPC_GOT_DTPREL16_HA:
3652	  tls_type = TLS_TLS | TLS_DTPREL;
3653	dogottls:
3654	  sec->has_tls_reloc = 1;
3655	  /* Fall thru */
3656
3657	  /* GOT16 relocations */
3658	case R_PPC_GOT16:
3659	case R_PPC_GOT16_LO:
3660	case R_PPC_GOT16_HI:
3661	case R_PPC_GOT16_HA:
3662	  /* This symbol requires a global offset table entry.  */
3663	  if (htab->got == NULL)
3664	    {
3665	      if (htab->elf.dynobj == NULL)
3666		htab->elf.dynobj = abfd;
3667	      if (!ppc_elf_create_got (htab->elf.dynobj, info))
3668		return FALSE;
3669	    }
3670	  if (h != NULL)
3671	    {
3672	      h->got.refcount += 1;
3673	      ppc_elf_hash_entry (h)->tls_mask |= tls_type;
3674	    }
3675	  else
3676	    /* This is a global offset table entry for a local symbol.  */
3677	    if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
3678	      return FALSE;
3679	  break;
3680
3681	  /* Indirect .sdata relocation.  */
3682	case R_PPC_EMB_SDAI16:
3683	  if (info->shared)
3684	    {
3685	      bad_shared_reloc (abfd, r_type);
3686	      return FALSE;
3687	    }
3688	  if (!elf_create_pointer_linker_section (abfd, info,
3689						  htab->sdata, h, rel))
3690	    return FALSE;
3691	  break;
3692
3693	  /* Indirect .sdata2 relocation.  */
3694	case R_PPC_EMB_SDA2I16:
3695	  if (info->shared)
3696	    {
3697	      bad_shared_reloc (abfd, r_type);
3698	      return FALSE;
3699	    }
3700	  if (!elf_create_pointer_linker_section (abfd, info,
3701						  htab->sdata2, h, rel))
3702	    return FALSE;
3703	  break;
3704
3705	case R_PPC_SDAREL16:
3706	case R_PPC_EMB_SDA2REL:
3707	case R_PPC_EMB_SDA21:
3708	case R_PPC_EMB_RELSDA:
3709	case R_PPC_EMB_NADDR32:
3710	case R_PPC_EMB_NADDR16:
3711	case R_PPC_EMB_NADDR16_LO:
3712	case R_PPC_EMB_NADDR16_HI:
3713	case R_PPC_EMB_NADDR16_HA:
3714	  if (info->shared)
3715	    {
3716	      bad_shared_reloc (abfd, r_type);
3717	      return FALSE;
3718	    }
3719	  break;
3720
3721	case R_PPC_PLT32:
3722	case R_PPC_PLTREL24:
3723	case R_PPC_PLTREL32:
3724	case R_PPC_PLT16_LO:
3725	case R_PPC_PLT16_HI:
3726	case R_PPC_PLT16_HA:
3727#ifdef DEBUG
3728	  fprintf (stderr, "Reloc requires a PLT entry\n");
3729#endif
3730	  /* This symbol requires a procedure linkage table entry.  We
3731	     actually build the entry in finish_dynamic_symbol,
3732	     because this might be a case of linking PIC code without
3733	     linking in any dynamic objects, in which case we don't
3734	     need to generate a procedure linkage table after all.  */
3735
3736	  if (h == NULL)
3737	    {
3738	      /* It does not make sense to have a procedure linkage
3739		 table entry for a local symbol.  */
3740	      (*_bfd_error_handler) (_("%s(%s+0x%lx): %s reloc against "
3741				       "local symbol"),
3742				     bfd_archive_filename (abfd),
3743				     sec->name,
3744				     (long) rel->r_offset,
3745				     ppc_elf_howto_table[r_type]->name);
3746	      bfd_set_error (bfd_error_bad_value);
3747	      return FALSE;
3748	    }
3749
3750	  h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3751	  h->plt.refcount++;
3752	  break;
3753
3754	  /* The following relocations don't need to propagate the
3755	     relocation if linking a shared object since they are
3756	     section relative.  */
3757	case R_PPC_SECTOFF:
3758	case R_PPC_SECTOFF_LO:
3759	case R_PPC_SECTOFF_HI:
3760	case R_PPC_SECTOFF_HA:
3761	case R_PPC_DTPREL16:
3762	case R_PPC_DTPREL16_LO:
3763	case R_PPC_DTPREL16_HI:
3764	case R_PPC_DTPREL16_HA:
3765	case R_PPC_TOC16:
3766	  break;
3767
3768	  /* This are just markers.  */
3769	case R_PPC_TLS:
3770	case R_PPC_EMB_MRKREF:
3771	case R_PPC_NONE:
3772	case R_PPC_max:
3773	  break;
3774
3775	  /* These should only appear in dynamic objects.  */
3776	case R_PPC_COPY:
3777	case R_PPC_GLOB_DAT:
3778	case R_PPC_JMP_SLOT:
3779	case R_PPC_RELATIVE:
3780	  break;
3781
3782	  /* These aren't handled yet.  We'll report an error later.  */
3783	case R_PPC_ADDR30:
3784	case R_PPC_EMB_RELSEC16:
3785	case R_PPC_EMB_RELST_LO:
3786	case R_PPC_EMB_RELST_HI:
3787	case R_PPC_EMB_RELST_HA:
3788	case R_PPC_EMB_BIT_FLD:
3789	  break;
3790
3791	  /* This refers only to functions defined in the shared library.  */
3792	case R_PPC_LOCAL24PC:
3793	  break;
3794
3795	  /* This relocation describes the C++ object vtable hierarchy.
3796	     Reconstruct it for later use during GC.  */
3797	case R_PPC_GNU_VTINHERIT:
3798	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3799	    return FALSE;
3800	  break;
3801
3802	  /* This relocation describes which C++ vtable entries are actually
3803	     used.  Record for later use during GC.  */
3804	case R_PPC_GNU_VTENTRY:
3805	  if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3806	    return FALSE;
3807	  break;
3808
3809	  /* We shouldn't really be seeing these.  */
3810	case R_PPC_TPREL32:
3811	  if (info->shared)
3812	    info->flags |= DF_STATIC_TLS;
3813	  goto dodyn;
3814
3815	  /* Nor these.  */
3816	case R_PPC_DTPMOD32:
3817	case R_PPC_DTPREL32:
3818	  goto dodyn;
3819
3820	case R_PPC_TPREL16:
3821	case R_PPC_TPREL16_LO:
3822	case R_PPC_TPREL16_HI:
3823	case R_PPC_TPREL16_HA:
3824	  if (info->shared)
3825	    info->flags |= DF_STATIC_TLS;
3826	  goto dodyn;
3827
3828	  /* When creating a shared object, we must copy these
3829	     relocs into the output file.  We create a reloc
3830	     section in dynobj and make room for the reloc.  */
3831	case R_PPC_REL24:
3832	case R_PPC_REL14:
3833	case R_PPC_REL14_BRTAKEN:
3834	case R_PPC_REL14_BRNTAKEN:
3835	case R_PPC_REL32:
3836	  if (h == NULL
3837	      || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3838	    break;
3839	  /* fall through */
3840
3841	case R_PPC_ADDR32:
3842	case R_PPC_ADDR24:
3843	case R_PPC_ADDR16:
3844	case R_PPC_ADDR16_LO:
3845	case R_PPC_ADDR16_HI:
3846	case R_PPC_ADDR16_HA:
3847	case R_PPC_ADDR14:
3848	case R_PPC_ADDR14_BRTAKEN:
3849	case R_PPC_ADDR14_BRNTAKEN:
3850	case R_PPC_UADDR32:
3851	case R_PPC_UADDR16:
3852	  if (h != NULL && !info->shared)
3853	    {
3854	      /* We may need a plt entry if the symbol turns out to be
3855		 a function defined in a dynamic object.  */
3856	      h->plt.refcount++;
3857
3858	      /* We may need a copy reloc too.  */
3859	      h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
3860	    }
3861
3862	dodyn:
3863	  /* If we are creating a shared library, and this is a reloc
3864	     against a global symbol, or a non PC relative reloc
3865	     against a local symbol, then we need to copy the reloc
3866	     into the shared library.  However, if we are linking with
3867	     -Bsymbolic, we do not need to copy a reloc against a
3868	     global symbol which is defined in an object we are
3869	     including in the link (i.e., DEF_REGULAR is set).  At
3870	     this point we have not seen all the input files, so it is
3871	     possible that DEF_REGULAR is not set now but will be set
3872	     later (it is never cleared).  In case of a weak definition,
3873	     DEF_REGULAR may be cleared later by a strong definition in
3874	     a shared library.  We account for that possibility below by
3875	     storing information in the dyn_relocs field of the hash
3876	     table entry.  A similar situation occurs when creating
3877	     shared libraries and symbol visibility changes render the
3878	     symbol local.
3879
3880	     If on the other hand, we are creating an executable, we
3881	     may need to keep relocations for symbols satisfied by a
3882	     dynamic library if we manage to avoid copy relocs for the
3883	     symbol.  */
3884	  if ((info->shared
3885	       && (MUST_BE_DYN_RELOC (r_type)
3886		   || (h != NULL
3887		       && (! info->symbolic
3888			   || h->root.type == bfd_link_hash_defweak
3889			   || (h->elf_link_hash_flags
3890			       & ELF_LINK_HASH_DEF_REGULAR) == 0))))
3891	      || (ELIMINATE_COPY_RELOCS
3892		  && !info->shared
3893		  && (sec->flags & SEC_ALLOC) != 0
3894		  && h != NULL
3895		  && (h->root.type == bfd_link_hash_defweak
3896		      || (h->elf_link_hash_flags
3897			  & ELF_LINK_HASH_DEF_REGULAR) == 0)))
3898	    {
3899	      struct ppc_elf_dyn_relocs *p;
3900	      struct ppc_elf_dyn_relocs **head;
3901
3902#ifdef DEBUG
3903	      fprintf (stderr,
3904		       "ppc_elf_check_relocs needs to "
3905		       "create relocation for %s\n",
3906		       (h && h->root.root.string
3907			? h->root.root.string : "<unknown>"));
3908#endif
3909	      if (sreloc == NULL)
3910		{
3911		  const char *name;
3912
3913		  name = (bfd_elf_string_from_elf_section
3914			  (abfd,
3915			   elf_elfheader (abfd)->e_shstrndx,
3916			   elf_section_data (sec)->rel_hdr.sh_name));
3917		  if (name == NULL)
3918		    return FALSE;
3919
3920		  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
3921			      && strcmp (bfd_get_section_name (abfd, sec),
3922					 name + 5) == 0);
3923
3924		  sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
3925		  if (sreloc == NULL)
3926		    {
3927		      flagword flags;
3928
3929		      sreloc = bfd_make_section (htab->elf.dynobj, name);
3930		      flags = (SEC_HAS_CONTENTS | SEC_READONLY
3931			       | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3932		      if ((sec->flags & SEC_ALLOC) != 0)
3933			flags |= SEC_ALLOC | SEC_LOAD;
3934		      if (sreloc == NULL
3935			  || ! bfd_set_section_flags (htab->elf.dynobj,
3936						      sreloc, flags)
3937			  || ! bfd_set_section_alignment (htab->elf.dynobj,
3938							  sreloc, 2))
3939			return FALSE;
3940		    }
3941		  elf_section_data (sec)->sreloc = sreloc;
3942		}
3943
3944	      /* If this is a global symbol, we count the number of
3945		 relocations we need for this symbol.  */
3946	      if (h != NULL)
3947		{
3948		  head = &ppc_elf_hash_entry (h)->dyn_relocs;
3949		}
3950	      else
3951		{
3952		  /* Track dynamic relocs needed for local syms too.
3953		     We really need local syms available to do this
3954		     easily.  Oh well.  */
3955
3956		  asection *s;
3957		  s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
3958						 sec, r_symndx);
3959		  if (s == NULL)
3960		    return FALSE;
3961
3962		  head = ((struct ppc_elf_dyn_relocs **)
3963			  &elf_section_data (s)->local_dynrel);
3964		}
3965
3966	      p = *head;
3967	      if (p == NULL || p->sec != sec)
3968		{
3969		  p = bfd_alloc (htab->elf.dynobj, sizeof *p);
3970		  if (p == NULL)
3971		    return FALSE;
3972		  p->next = *head;
3973		  *head = p;
3974		  p->sec = sec;
3975		  p->count = 0;
3976		  p->pc_count = 0;
3977		}
3978
3979	      p->count += 1;
3980	      if (!MUST_BE_DYN_RELOC (r_type))
3981		p->pc_count += 1;
3982	    }
3983
3984	  break;
3985	}
3986    }
3987
3988  return TRUE;
3989}
3990
3991/* Return the section that should be marked against GC for a given
3992   relocation.  */
3993
3994static asection *
3995ppc_elf_gc_mark_hook (asection *sec,
3996		      struct bfd_link_info *info ATTRIBUTE_UNUSED,
3997		      Elf_Internal_Rela *rel,
3998		      struct elf_link_hash_entry *h,
3999		      Elf_Internal_Sym *sym)
4000{
4001  if (h != NULL)
4002    {
4003      switch (ELF32_R_TYPE (rel->r_info))
4004	{
4005	case R_PPC_GNU_VTINHERIT:
4006	case R_PPC_GNU_VTENTRY:
4007	  break;
4008
4009	default:
4010	  switch (h->root.type)
4011	    {
4012	    case bfd_link_hash_defined:
4013	    case bfd_link_hash_defweak:
4014	      return h->root.u.def.section;
4015
4016	    case bfd_link_hash_common:
4017	      return h->root.u.c.p->section;
4018
4019	    default:
4020	      break;
4021	    }
4022	}
4023    }
4024  else
4025    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
4026
4027  return NULL;
4028}
4029
4030/* Update the got, plt and dynamic reloc reference counts for the
4031   section being removed.  */
4032
4033static bfd_boolean
4034ppc_elf_gc_sweep_hook (bfd *abfd,
4035		       struct bfd_link_info *info,
4036		       asection *sec,
4037		       const Elf_Internal_Rela *relocs)
4038{
4039  struct ppc_elf_link_hash_table *htab;
4040  Elf_Internal_Shdr *symtab_hdr;
4041  struct elf_link_hash_entry **sym_hashes;
4042  bfd_signed_vma *local_got_refcounts;
4043  const Elf_Internal_Rela *rel, *relend;
4044
4045  elf_section_data (sec)->local_dynrel = NULL;
4046
4047  htab = ppc_elf_hash_table (info);
4048  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4049  sym_hashes = elf_sym_hashes (abfd);
4050  local_got_refcounts = elf_local_got_refcounts (abfd);
4051
4052  relend = relocs + sec->reloc_count;
4053  for (rel = relocs; rel < relend; rel++)
4054    {
4055      unsigned long r_symndx;
4056      enum elf_ppc_reloc_type r_type;
4057      struct elf_link_hash_entry *h = NULL;
4058
4059      r_symndx = ELF32_R_SYM (rel->r_info);
4060      if (r_symndx >= symtab_hdr->sh_info)
4061	{
4062	  struct ppc_elf_dyn_relocs **pp, *p;
4063	  struct ppc_elf_link_hash_entry *eh;
4064
4065	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4066	  eh = (struct ppc_elf_link_hash_entry *) h;
4067
4068	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
4069	    if (p->sec == sec)
4070	      {
4071		/* Everything must go for SEC.  */
4072		*pp = p->next;
4073		break;
4074	      }
4075	}
4076
4077      r_type = ELF32_R_TYPE (rel->r_info);
4078      switch (r_type)
4079	{
4080	case R_PPC_GOT_TLSLD16:
4081	case R_PPC_GOT_TLSLD16_LO:
4082	case R_PPC_GOT_TLSLD16_HI:
4083	case R_PPC_GOT_TLSLD16_HA:
4084	  htab->tlsld_got.refcount -= 1;
4085	  /* Fall thru */
4086
4087	case R_PPC_GOT_TLSGD16:
4088	case R_PPC_GOT_TLSGD16_LO:
4089	case R_PPC_GOT_TLSGD16_HI:
4090	case R_PPC_GOT_TLSGD16_HA:
4091	case R_PPC_GOT_TPREL16:
4092	case R_PPC_GOT_TPREL16_LO:
4093	case R_PPC_GOT_TPREL16_HI:
4094	case R_PPC_GOT_TPREL16_HA:
4095	case R_PPC_GOT_DTPREL16:
4096	case R_PPC_GOT_DTPREL16_LO:
4097	case R_PPC_GOT_DTPREL16_HI:
4098	case R_PPC_GOT_DTPREL16_HA:
4099	case R_PPC_GOT16:
4100	case R_PPC_GOT16_LO:
4101	case R_PPC_GOT16_HI:
4102	case R_PPC_GOT16_HA:
4103	  if (h != NULL)
4104	    {
4105	      if (h->got.refcount > 0)
4106		h->got.refcount--;
4107	    }
4108	  else if (local_got_refcounts != NULL)
4109	    {
4110	      if (local_got_refcounts[r_symndx] > 0)
4111		local_got_refcounts[r_symndx]--;
4112	    }
4113	  break;
4114
4115	case R_PPC_REL24:
4116	case R_PPC_REL14:
4117	case R_PPC_REL14_BRTAKEN:
4118	case R_PPC_REL14_BRNTAKEN:
4119	case R_PPC_REL32:
4120	  if (h == NULL
4121	      || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
4122	    break;
4123	  /* Fall thru */
4124
4125	case R_PPC_ADDR32:
4126	case R_PPC_ADDR24:
4127	case R_PPC_ADDR16:
4128	case R_PPC_ADDR16_LO:
4129	case R_PPC_ADDR16_HI:
4130	case R_PPC_ADDR16_HA:
4131	case R_PPC_ADDR14:
4132	case R_PPC_ADDR14_BRTAKEN:
4133	case R_PPC_ADDR14_BRNTAKEN:
4134	case R_PPC_UADDR32:
4135	case R_PPC_UADDR16:
4136	case R_PPC_PLT32:
4137	case R_PPC_PLTREL24:
4138	case R_PPC_PLT16_LO:
4139	case R_PPC_PLT16_HI:
4140	case R_PPC_PLT16_HA:
4141	  if (h != NULL)
4142	    {
4143	      if (h->plt.refcount > 0)
4144		h->plt.refcount--;
4145	    }
4146	  break;
4147
4148	default:
4149	  break;
4150	}
4151    }
4152  return TRUE;
4153}
4154
4155/* Set htab->tls_get_addr and call the generic ELF tls_setup function.  */
4156
4157asection *
4158ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
4159{
4160  struct ppc_elf_link_hash_table *htab;
4161
4162  htab = ppc_elf_hash_table (info);
4163  htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
4164					     FALSE, FALSE, TRUE);
4165
4166  return _bfd_elf_tls_setup (obfd, info);
4167}
4168
4169/* Run through all the TLS relocs looking for optimization
4170   opportunities.  */
4171
4172bfd_boolean
4173ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
4174		      struct bfd_link_info *info)
4175{
4176  bfd *ibfd;
4177  asection *sec;
4178  struct ppc_elf_link_hash_table *htab;
4179
4180  if (info->relocatable || info->shared)
4181    return TRUE;
4182
4183  htab = ppc_elf_hash_table (info);
4184  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4185    {
4186      Elf_Internal_Sym *locsyms = NULL;
4187      Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4188
4189      for (sec = ibfd->sections; sec != NULL; sec = sec->next)
4190	if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
4191	  {
4192	    Elf_Internal_Rela *relstart, *rel, *relend;
4193	    int expecting_tls_get_addr;
4194
4195	    /* Read the relocations.  */
4196	    relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
4197						  info->keep_memory);
4198	    if (relstart == NULL)
4199	      return FALSE;
4200
4201	    expecting_tls_get_addr = 0;
4202	    relend = relstart + sec->reloc_count;
4203	    for (rel = relstart; rel < relend; rel++)
4204	      {
4205		enum elf_ppc_reloc_type r_type;
4206		unsigned long r_symndx;
4207		struct elf_link_hash_entry *h = NULL;
4208		char *tls_mask;
4209		char tls_set, tls_clear;
4210		bfd_boolean is_local;
4211
4212		r_symndx = ELF32_R_SYM (rel->r_info);
4213		if (r_symndx >= symtab_hdr->sh_info)
4214		  {
4215		    struct elf_link_hash_entry **sym_hashes;
4216
4217		    sym_hashes = elf_sym_hashes (ibfd);
4218		    h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4219		    while (h->root.type == bfd_link_hash_indirect
4220			   || h->root.type == bfd_link_hash_warning)
4221		      h = (struct elf_link_hash_entry *) h->root.u.i.link;
4222		  }
4223
4224		is_local = FALSE;
4225		if (h == NULL
4226		    || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))
4227		  is_local = TRUE;
4228
4229		r_type = ELF32_R_TYPE (rel->r_info);
4230		switch (r_type)
4231		  {
4232		  case R_PPC_GOT_TLSLD16:
4233		  case R_PPC_GOT_TLSLD16_LO:
4234		  case R_PPC_GOT_TLSLD16_HI:
4235		  case R_PPC_GOT_TLSLD16_HA:
4236		    /* These relocs should never be against a symbol
4237		       defined in a shared lib.  Leave them alone if
4238		       that turns out to be the case.  */
4239		    expecting_tls_get_addr = 0;
4240		    htab->tlsld_got.refcount -= 1;
4241		    if (!is_local)
4242		      continue;
4243
4244		    /* LD -> LE */
4245		    tls_set = 0;
4246		    tls_clear = TLS_LD;
4247		    expecting_tls_get_addr = 1;
4248		    break;
4249
4250		  case R_PPC_GOT_TLSGD16:
4251		  case R_PPC_GOT_TLSGD16_LO:
4252		  case R_PPC_GOT_TLSGD16_HI:
4253		  case R_PPC_GOT_TLSGD16_HA:
4254		    if (is_local)
4255		      /* GD -> LE */
4256		      tls_set = 0;
4257		    else
4258		      /* GD -> IE */
4259		      tls_set = TLS_TLS | TLS_TPRELGD;
4260		    tls_clear = TLS_GD;
4261		    expecting_tls_get_addr = 1;
4262		    break;
4263
4264		  case R_PPC_GOT_TPREL16:
4265		  case R_PPC_GOT_TPREL16_LO:
4266		  case R_PPC_GOT_TPREL16_HI:
4267		  case R_PPC_GOT_TPREL16_HA:
4268		    expecting_tls_get_addr = 0;
4269		    if (is_local)
4270		      {
4271			/* IE -> LE */
4272			tls_set = 0;
4273			tls_clear = TLS_TPREL;
4274			break;
4275		      }
4276		    else
4277		      continue;
4278
4279		  case R_PPC_REL14:
4280		  case R_PPC_REL14_BRTAKEN:
4281		  case R_PPC_REL14_BRNTAKEN:
4282		  case R_PPC_REL24:
4283		    if (expecting_tls_get_addr
4284			&& h != NULL
4285			&& h == htab->tls_get_addr)
4286		      {
4287			if (h->plt.refcount > 0)
4288			  h->plt.refcount -= 1;
4289		      }
4290		    expecting_tls_get_addr = 0;
4291		    continue;
4292
4293		  default:
4294		    expecting_tls_get_addr = 0;
4295		    continue;
4296		  }
4297
4298		if (h != NULL)
4299		  {
4300		    if (tls_set == 0)
4301		      {
4302			/* We managed to get rid of a got entry.  */
4303			if (h->got.refcount > 0)
4304			  h->got.refcount -= 1;
4305		      }
4306		    tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
4307		  }
4308		else
4309		  {
4310		    Elf_Internal_Sym *sym;
4311		    bfd_signed_vma *lgot_refs;
4312		    char *lgot_masks;
4313
4314		    if (locsyms == NULL)
4315		      {
4316			locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
4317			if (locsyms == NULL)
4318			  locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
4319							  symtab_hdr->sh_info,
4320							  0, NULL, NULL, NULL);
4321			if (locsyms == NULL)
4322			  {
4323			    if (elf_section_data (sec)->relocs != relstart)
4324			      free (relstart);
4325			    return FALSE;
4326			  }
4327		      }
4328		    sym = locsyms + r_symndx;
4329		    lgot_refs = elf_local_got_refcounts (ibfd);
4330		    if (lgot_refs == NULL)
4331		      abort ();
4332		    if (tls_set == 0)
4333		      {
4334			/* We managed to get rid of a got entry.  */
4335			if (lgot_refs[r_symndx] > 0)
4336			  lgot_refs[r_symndx] -= 1;
4337		      }
4338		    lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info);
4339		    tls_mask = &lgot_masks[r_symndx];
4340		  }
4341
4342		*tls_mask |= tls_set;
4343		*tls_mask &= ~tls_clear;
4344	      }
4345
4346	    if (elf_section_data (sec)->relocs != relstart)
4347	      free (relstart);
4348	  }
4349
4350      if (locsyms != NULL
4351	  && (symtab_hdr->contents != (unsigned char *) locsyms))
4352	{
4353	  if (!info->keep_memory)
4354	    free (locsyms);
4355	  else
4356	    symtab_hdr->contents = (unsigned char *) locsyms;
4357	}
4358    }
4359  return TRUE;
4360}
4361
4362/* Hook called by the linker routine which adds symbols from an object
4363   file.  We use it to put .comm items in .sbss, and not .bss.  */
4364
4365static bfd_boolean
4366ppc_elf_add_symbol_hook (bfd *abfd,
4367			 struct bfd_link_info *info,
4368			 Elf_Internal_Sym *sym,
4369			 const char **namep ATTRIBUTE_UNUSED,
4370			 flagword *flagsp ATTRIBUTE_UNUSED,
4371			 asection **secp,
4372			 bfd_vma *valp)
4373{
4374  if (sym->st_shndx == SHN_COMMON
4375      && !info->relocatable
4376      && sym->st_size <= elf_gp_size (abfd)
4377      && (info->hash->creator == abfd->xvec
4378	  || info->hash->creator == abfd->xvec->alternative_target))
4379    {
4380      /* Common symbols less than or equal to -G nn bytes are automatically
4381	 put into .sbss.  */
4382      struct ppc_elf_link_hash_table *htab;
4383
4384      htab = ppc_elf_hash_table (info);
4385      if (htab->sbss == NULL)
4386	{
4387	  flagword flags = SEC_IS_COMMON;
4388
4389	  htab->sbss = bfd_make_section_anyway (abfd, ".sbss");
4390	  if (htab->sbss == NULL
4391	      || ! bfd_set_section_flags (abfd, htab->sbss, flags))
4392	    return FALSE;
4393	}
4394
4395      *secp = htab->sbss;
4396      *valp = sym->st_size;
4397    }
4398
4399  return TRUE;
4400}
4401
4402/* Finish up dynamic symbol handling.  We set the contents of various
4403   dynamic sections here.  */
4404
4405static bfd_boolean
4406ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
4407			       struct bfd_link_info *info,
4408			       struct elf_link_hash_entry *h,
4409			       Elf_Internal_Sym *sym)
4410{
4411  struct ppc_elf_link_hash_table *htab;
4412
4413#ifdef DEBUG
4414  fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
4415	   h->root.root.string);
4416#endif
4417
4418  htab = ppc_elf_hash_table (info);
4419  BFD_ASSERT (htab->elf.dynobj != NULL);
4420
4421  if (h->plt.offset != (bfd_vma) -1)
4422    {
4423      Elf_Internal_Rela rela;
4424      bfd_byte *loc;
4425      bfd_vma reloc_index;
4426
4427#ifdef DEBUG
4428      fprintf (stderr, ", plt_offset = %d", h->plt.offset);
4429#endif
4430
4431      /* This symbol has an entry in the procedure linkage table.  Set
4432	 it up.  */
4433
4434      BFD_ASSERT (h->dynindx != -1);
4435      BFD_ASSERT (htab->plt != NULL && htab->relplt != NULL);
4436
4437      /* We don't need to fill in the .plt.  The ppc dynamic linker
4438	 will fill it in.  */
4439
4440      /* Fill in the entry in the .rela.plt section.  */
4441      rela.r_offset = (htab->plt->output_section->vma
4442		       + htab->plt->output_offset
4443		       + h->plt.offset);
4444      rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
4445      rela.r_addend = 0;
4446
4447      reloc_index = (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_SLOT_SIZE;
4448      if (reloc_index > PLT_NUM_SINGLE_ENTRIES)
4449	reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
4450      loc = (htab->relplt->contents
4451	     + reloc_index * sizeof (Elf32_External_Rela));
4452      bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4453
4454      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4455	{
4456	  /* Mark the symbol as undefined, rather than as defined in
4457	     the .plt section.  Leave the value alone.  */
4458	  sym->st_shndx = SHN_UNDEF;
4459	  /* If the symbol is weak, we do need to clear the value.
4460	     Otherwise, the PLT entry would provide a definition for
4461	     the symbol even if the symbol wasn't defined anywhere,
4462	     and so the symbol would never be NULL.  */
4463	  if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
4464	      == 0)
4465	    sym->st_value = 0;
4466	}
4467    }
4468
4469  if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
4470    {
4471      asection *s;
4472      Elf_Internal_Rela rela;
4473      bfd_byte *loc;
4474
4475      /* This symbols needs a copy reloc.  Set it up.  */
4476
4477#ifdef DEBUG
4478      fprintf (stderr, ", copy");
4479#endif
4480
4481      BFD_ASSERT (h->dynindx != -1);
4482
4483      if (h->size <= elf_gp_size (htab->elf.dynobj))
4484	s = htab->relsbss;
4485      else
4486	s = htab->relbss;
4487      BFD_ASSERT (s != NULL);
4488
4489      rela.r_offset = (h->root.u.def.value
4490		       + h->root.u.def.section->output_section->vma
4491		       + h->root.u.def.section->output_offset);
4492      rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
4493      rela.r_addend = 0;
4494      loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
4495      bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4496    }
4497
4498#ifdef DEBUG
4499  fprintf (stderr, "\n");
4500#endif
4501
4502  /* Mark some specially defined symbols as absolute.  */
4503  if (strcmp (h->root.root.string, "_DYNAMIC") == 0
4504      || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
4505      || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4506    sym->st_shndx = SHN_ABS;
4507
4508  return TRUE;
4509}
4510
4511/* Finish up the dynamic sections.  */
4512
4513static bfd_boolean
4514ppc_elf_finish_dynamic_sections (bfd *output_bfd,
4515				 struct bfd_link_info *info)
4516{
4517  asection *sdyn;
4518  struct ppc_elf_link_hash_table *htab;
4519
4520#ifdef DEBUG
4521  fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
4522#endif
4523
4524  htab = ppc_elf_hash_table (info);
4525  sdyn = bfd_get_section_by_name (htab->elf.dynobj, ".dynamic");
4526
4527  if (htab->elf.dynamic_sections_created)
4528    {
4529      Elf32_External_Dyn *dyncon, *dynconend;
4530
4531      BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
4532
4533      dyncon = (Elf32_External_Dyn *) sdyn->contents;
4534      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
4535      for (; dyncon < dynconend; dyncon++)
4536	{
4537	  Elf_Internal_Dyn dyn;
4538	  asection *s;
4539
4540	  bfd_elf32_swap_dyn_in (htab->elf.dynobj, dyncon, &dyn);
4541
4542	  switch (dyn.d_tag)
4543	    {
4544	    case DT_PLTGOT:
4545	      s = htab->plt;
4546	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4547	      break;
4548
4549	    case DT_PLTRELSZ:
4550	      dyn.d_un.d_val = htab->relplt->_raw_size;
4551	      break;
4552
4553	    case DT_JMPREL:
4554	      s = htab->relplt;
4555	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4556	      break;
4557
4558	    default:
4559	      continue;
4560	    }
4561
4562	  bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4563	}
4564    }
4565
4566  /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4567     easily find the address of the _GLOBAL_OFFSET_TABLE_.  */
4568  if (htab->got)
4569    {
4570      unsigned char *contents = htab->got->contents;
4571      bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents);
4572
4573      if (sdyn == NULL)
4574	bfd_put_32 (output_bfd, 0, contents + 4);
4575      else
4576	bfd_put_32 (output_bfd,
4577		    sdyn->output_section->vma + sdyn->output_offset,
4578		    contents + 4);
4579
4580      elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
4581    }
4582
4583  return TRUE;
4584}
4585
4586/* The RELOCATE_SECTION function is called by the ELF backend linker
4587   to handle the relocations for a section.
4588
4589   The relocs are always passed as Rela structures; if the section
4590   actually uses Rel structures, the r_addend field will always be
4591   zero.
4592
4593   This function is responsible for adjust the section contents as
4594   necessary, and (if using Rela relocs and generating a
4595   relocatable output file) adjusting the reloc addend as
4596   necessary.
4597
4598   This function does not have to worry about setting the reloc
4599   address or the reloc symbol index.
4600
4601   LOCAL_SYMS is a pointer to the swapped in local symbols.
4602
4603   LOCAL_SECTIONS is an array giving the section in the input file
4604   corresponding to the st_shndx field of each local symbol.
4605
4606   The global hash table entry for the global symbols can be found
4607   via elf_sym_hashes (input_bfd).
4608
4609   When generating relocatable output, this function must handle
4610   STB_LOCAL/STT_SECTION symbols specially.  The output symbol is
4611   going to be the section symbol corresponding to the output
4612   section, which means that the addend must be adjusted
4613   accordingly.  */
4614
4615static bfd_boolean
4616ppc_elf_relocate_section (bfd *output_bfd,
4617			  struct bfd_link_info *info,
4618			  bfd *input_bfd,
4619			  asection *input_section,
4620			  bfd_byte *contents,
4621			  Elf_Internal_Rela *relocs,
4622			  Elf_Internal_Sym *local_syms,
4623			  asection **local_sections)
4624{
4625  Elf_Internal_Shdr *symtab_hdr;
4626  struct elf_link_hash_entry **sym_hashes;
4627  struct ppc_elf_link_hash_table *htab;
4628  Elf_Internal_Rela *rel;
4629  Elf_Internal_Rela *relend;
4630  Elf_Internal_Rela outrel;
4631  bfd_byte *loc;
4632  asection *sreloc = NULL;
4633  bfd_vma *local_got_offsets;
4634  bfd_boolean ret = TRUE;
4635
4636#ifdef DEBUG
4637  fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, "
4638	   "%ld relocations%s\n",
4639	   bfd_archive_filename (input_bfd),
4640	   bfd_section_name(input_bfd, input_section),
4641	   (long) input_section->reloc_count,
4642	   (info->relocatable) ? " (relocatable)" : "");
4643#endif
4644
4645  if (info->relocatable)
4646    return TRUE;
4647
4648  /* Initialize howto table if not already done.  */
4649  if (!ppc_elf_howto_table[R_PPC_ADDR32])
4650    ppc_elf_howto_init ();
4651
4652  htab = ppc_elf_hash_table (info);
4653  local_got_offsets = elf_local_got_offsets (input_bfd);
4654  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4655  sym_hashes = elf_sym_hashes (input_bfd);
4656  rel = relocs;
4657  relend = relocs + input_section->reloc_count;
4658  for (; rel < relend; rel++)
4659    {
4660      enum elf_ppc_reloc_type r_type;
4661      bfd_vma addend;
4662      bfd_reloc_status_type r;
4663      Elf_Internal_Sym *sym;
4664      asection *sec;
4665      struct elf_link_hash_entry *h;
4666      const char *sym_name;
4667      reloc_howto_type *howto;
4668      unsigned long r_symndx;
4669      bfd_vma relocation;
4670      bfd_vma branch_bit, insn, from;
4671      bfd_boolean unresolved_reloc;
4672      bfd_boolean warned;
4673      unsigned int tls_type, tls_mask, tls_gd;
4674
4675      r_type = ELF32_R_TYPE (rel->r_info);
4676      sym = NULL;
4677      sec = NULL;
4678      h = NULL;
4679      unresolved_reloc = FALSE;
4680      warned = FALSE;
4681      r_symndx = ELF32_R_SYM (rel->r_info);
4682
4683      if (r_symndx < symtab_hdr->sh_info)
4684	{
4685	  sym = local_syms + r_symndx;
4686	  sec = local_sections[r_symndx];
4687	  sym_name = bfd_elf_local_sym_name (input_bfd, sym);
4688
4689	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
4690	}
4691      else
4692	{
4693	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
4694				   r_symndx, symtab_hdr, sym_hashes,
4695				   h, sec, relocation,
4696				   unresolved_reloc, warned);
4697
4698	  sym_name = h->root.root.string;
4699	}
4700
4701      /* TLS optimizations.  Replace instruction sequences and relocs
4702	 based on information we collected in tls_optimize.  We edit
4703	 RELOCS so that --emit-relocs will output something sensible
4704	 for the final instruction stream.  */
4705      tls_mask = 0;
4706      tls_gd = 0;
4707      if (IS_PPC_TLS_RELOC (r_type))
4708	{
4709	  if (h != NULL)
4710	    tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
4711	  else if (local_got_offsets != NULL)
4712	    {
4713	      char *lgot_masks;
4714	      lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
4715	      tls_mask = lgot_masks[r_symndx];
4716	    }
4717	}
4718
4719      /* Ensure reloc mapping code below stays sane.  */
4720      if ((R_PPC_GOT_TLSLD16 & 3)    != (R_PPC_GOT_TLSGD16 & 3)
4721	  || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
4722	  || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
4723	  || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
4724	  || (R_PPC_GOT_TLSLD16 & 3)    != (R_PPC_GOT_TPREL16 & 3)
4725	  || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
4726	  || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
4727	  || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
4728	abort ();
4729      switch (r_type)
4730	{
4731	default:
4732	  break;
4733
4734	case R_PPC_GOT_TPREL16:
4735	case R_PPC_GOT_TPREL16_LO:
4736	  if (tls_mask != 0
4737	      && (tls_mask & TLS_TPREL) == 0)
4738	    {
4739	      bfd_vma insn;
4740	      insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2);
4741	      insn &= 31 << 21;
4742	      insn |= 0x3c020000;	/* addis 0,2,0 */
4743	      bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2);
4744	      r_type = R_PPC_TPREL16_HA;
4745	      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4746	    }
4747	  break;
4748
4749	case R_PPC_TLS:
4750	  if (tls_mask != 0
4751	      && (tls_mask & TLS_TPREL) == 0)
4752	    {
4753	      bfd_vma insn, rtra;
4754	      insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
4755	      if ((insn & ((31 << 26) | (31 << 11)))
4756		  == ((31 << 26) | (2 << 11)))
4757		rtra = insn & ((1 << 26) - (1 << 16));
4758	      else if ((insn & ((31 << 26) | (31 << 16)))
4759		       == ((31 << 26) | (2 << 16)))
4760		rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
4761	      else
4762		abort ();
4763	      if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
4764		/* add -> addi.  */
4765		insn = 14 << 26;
4766	      else if ((insn & (31 << 1)) == 23 << 1
4767		       && ((insn & (31 << 6)) < 14 << 6
4768			   || ((insn & (31 << 6)) >= 16 << 6
4769			       && (insn & (31 << 6)) < 24 << 6)))
4770		/* load and store indexed -> dform.  */
4771		insn = (32 | ((insn >> 6) & 31)) << 26;
4772	      else if ((insn & (31 << 1)) == 21 << 1
4773		       && (insn & (0x1a << 6)) == 0)
4774		/* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu.  */
4775		insn = (((58 | ((insn >> 6) & 4)) << 26)
4776			| ((insn >> 6) & 1));
4777	      else if ((insn & (31 << 1)) == 21 << 1
4778		       && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
4779		/* lwax -> lwa.  */
4780		insn = (58 << 26) | 2;
4781	      else
4782		abort ();
4783	      insn |= rtra;
4784	      bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
4785	      r_type = R_PPC_TPREL16_LO;
4786	      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4787	      /* Was PPC_TLS which sits on insn boundary, now
4788		 PPC_TPREL16_LO which is at insn+2.  */
4789	      rel->r_offset += 2;
4790	    }
4791	  break;
4792
4793	case R_PPC_GOT_TLSGD16_HI:
4794	case R_PPC_GOT_TLSGD16_HA:
4795	  tls_gd = TLS_TPRELGD;
4796	  if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
4797	    goto tls_gdld_hi;
4798	  break;
4799
4800	case R_PPC_GOT_TLSLD16_HI:
4801	case R_PPC_GOT_TLSLD16_HA:
4802	  if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
4803	    {
4804	    tls_gdld_hi:
4805	      if ((tls_mask & tls_gd) != 0)
4806		r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
4807			  + R_PPC_GOT_TPREL16);
4808	      else
4809		{
4810		  bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
4811		  rel->r_offset -= 2;
4812		  r_type = R_PPC_NONE;
4813		}
4814	      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4815	    }
4816	  break;
4817
4818	case R_PPC_GOT_TLSGD16:
4819	case R_PPC_GOT_TLSGD16_LO:
4820	  tls_gd = TLS_TPRELGD;
4821	  if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
4822	    goto tls_get_addr_check;
4823	  break;
4824
4825	case R_PPC_GOT_TLSLD16:
4826	case R_PPC_GOT_TLSLD16_LO:
4827	  if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
4828	    {
4829	    tls_get_addr_check:
4830	      if (rel + 1 < relend)
4831		{
4832		  enum elf_ppc_reloc_type r_type2;
4833		  unsigned long r_symndx2;
4834		  struct elf_link_hash_entry *h2;
4835		  bfd_vma insn1, insn2;
4836		  bfd_vma offset;
4837
4838		  /* The next instruction should be a call to
4839		     __tls_get_addr.  Peek at the reloc to be sure.  */
4840		  r_type2 = ELF32_R_TYPE (rel[1].r_info);
4841		  r_symndx2 = ELF32_R_SYM (rel[1].r_info);
4842		  if (r_symndx2 < symtab_hdr->sh_info
4843		      || (r_type2 != R_PPC_REL14
4844			  && r_type2 != R_PPC_REL14_BRTAKEN
4845			  && r_type2 != R_PPC_REL14_BRNTAKEN
4846			  && r_type2 != R_PPC_REL24
4847			  && r_type2 != R_PPC_PLTREL24))
4848		    break;
4849
4850		  h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
4851		  while (h2->root.type == bfd_link_hash_indirect
4852			 || h2->root.type == bfd_link_hash_warning)
4853		    h2 = (struct elf_link_hash_entry *) h2->root.u.i.link;
4854		  if (h2 == NULL || h2 != htab->tls_get_addr)
4855		    break;
4856
4857		  /* OK, it checks out.  Replace the call.  */
4858		  offset = rel[1].r_offset;
4859		  insn1 = bfd_get_32 (output_bfd,
4860				      contents + rel->r_offset - 2);
4861		  if ((tls_mask & tls_gd) != 0)
4862		    {
4863		      /* IE */
4864		      insn1 &= (1 << 26) - 1;
4865		      insn1 |= 32 << 26;	/* lwz */
4866		      insn2 = 0x7c631214;	/* add 3,3,2 */
4867		      rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE);
4868		      r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
4869				+ R_PPC_GOT_TPREL16);
4870		      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4871		    }
4872		  else
4873		    {
4874		      /* LE */
4875		      insn1 = 0x3c620000;	/* addis 3,2,0 */
4876		      insn2 = 0x38630000;	/* addi 3,3,0 */
4877		      if (tls_gd == 0)
4878			{
4879			  /* Was an LD reloc.  */
4880			  r_symndx = 0;
4881			  rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
4882			  rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
4883			}
4884		      r_type = R_PPC_TPREL16_HA;
4885		      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4886		      rel[1].r_info = ELF32_R_INFO (r_symndx,
4887						    R_PPC_TPREL16_LO);
4888		      rel[1].r_offset += 2;
4889		    }
4890		  bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
4891		  bfd_put_32 (output_bfd, insn2, contents + offset);
4892		  if (tls_gd == 0)
4893		    {
4894		      /* We changed the symbol on an LD reloc.  Start over
4895			 in order to get h, sym, sec etc. right.  */
4896		      rel--;
4897		      continue;
4898		    }
4899		}
4900	    }
4901	  break;
4902	}
4903
4904      /* Handle other relocations that tweak non-addend part of insn.  */
4905      branch_bit = 0;
4906      switch (r_type)
4907	{
4908	default:
4909	  break;
4910
4911	  /* Branch taken prediction relocations.  */
4912	case R_PPC_ADDR14_BRTAKEN:
4913	case R_PPC_REL14_BRTAKEN:
4914	  branch_bit = BRANCH_PREDICT_BIT;
4915	  /* Fall thru */
4916
4917	  /* Branch not taken prediction relocations.  */
4918	case R_PPC_ADDR14_BRNTAKEN:
4919	case R_PPC_REL14_BRNTAKEN:
4920	  insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
4921	  insn &= ~BRANCH_PREDICT_BIT;
4922	  insn |= branch_bit;
4923
4924	  from = (rel->r_offset
4925		  + input_section->output_offset
4926		  + input_section->output_section->vma);
4927
4928	  /* Invert 'y' bit if not the default.  */
4929	  if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
4930	    insn ^= BRANCH_PREDICT_BIT;
4931
4932	  bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
4933	  break;
4934	}
4935
4936      addend = rel->r_addend;
4937      tls_type = 0;
4938      howto = NULL;
4939      if (r_type < R_PPC_max)
4940	howto = ppc_elf_howto_table[r_type];
4941      switch (r_type)
4942	{
4943	default:
4944	  (*_bfd_error_handler)
4945	    (_("%s: unknown relocation type %d for symbol %s"),
4946	     bfd_archive_filename (input_bfd), (int) r_type, sym_name);
4947
4948	  bfd_set_error (bfd_error_bad_value);
4949	  ret = FALSE;
4950	  continue;
4951
4952	case R_PPC_NONE:
4953	case R_PPC_TLS:
4954	case R_PPC_EMB_MRKREF:
4955	case R_PPC_GNU_VTINHERIT:
4956	case R_PPC_GNU_VTENTRY:
4957	  continue;
4958
4959	  /* GOT16 relocations.  Like an ADDR16 using the symbol's
4960	     address in the GOT as relocation value instead of the
4961	     symbol's value itself.  Also, create a GOT entry for the
4962	     symbol and put the symbol value there.  */
4963	case R_PPC_GOT_TLSGD16:
4964	case R_PPC_GOT_TLSGD16_LO:
4965	case R_PPC_GOT_TLSGD16_HI:
4966	case R_PPC_GOT_TLSGD16_HA:
4967	  tls_type = TLS_TLS | TLS_GD;
4968	  goto dogot;
4969
4970	case R_PPC_GOT_TLSLD16:
4971	case R_PPC_GOT_TLSLD16_LO:
4972	case R_PPC_GOT_TLSLD16_HI:
4973	case R_PPC_GOT_TLSLD16_HA:
4974	  tls_type = TLS_TLS | TLS_LD;
4975	  goto dogot;
4976
4977	case R_PPC_GOT_TPREL16:
4978	case R_PPC_GOT_TPREL16_LO:
4979	case R_PPC_GOT_TPREL16_HI:
4980	case R_PPC_GOT_TPREL16_HA:
4981	  tls_type = TLS_TLS | TLS_TPREL;
4982	  goto dogot;
4983
4984	case R_PPC_GOT_DTPREL16:
4985	case R_PPC_GOT_DTPREL16_LO:
4986	case R_PPC_GOT_DTPREL16_HI:
4987	case R_PPC_GOT_DTPREL16_HA:
4988	  tls_type = TLS_TLS | TLS_DTPREL;
4989	  goto dogot;
4990
4991	case R_PPC_GOT16:
4992	case R_PPC_GOT16_LO:
4993	case R_PPC_GOT16_HI:
4994	case R_PPC_GOT16_HA:
4995	dogot:
4996	  {
4997	    /* Relocation is to the entry for this symbol in the global
4998	       offset table.  */
4999	    bfd_vma off;
5000	    bfd_vma *offp;
5001	    unsigned long indx;
5002
5003	    if (htab->got == NULL)
5004	      abort ();
5005
5006	    indx = 0;
5007	    if (tls_type == (TLS_TLS | TLS_LD)
5008		&& (h == NULL
5009		    || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)))
5010	      offp = &htab->tlsld_got.offset;
5011	    else if (h != NULL)
5012	      {
5013		bfd_boolean dyn;
5014		dyn = htab->elf.dynamic_sections_created;
5015		if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5016		    || (info->shared
5017			&& SYMBOL_REFERENCES_LOCAL (info, h)))
5018		  /* This is actually a static link, or it is a
5019		     -Bsymbolic link and the symbol is defined
5020		     locally, or the symbol was forced to be local
5021		     because of a version file.  */
5022		  ;
5023		else
5024		  {
5025		    indx = h->dynindx;
5026		    unresolved_reloc = FALSE;
5027		  }
5028		offp = &h->got.offset;
5029	      }
5030	    else
5031	      {
5032		if (local_got_offsets == NULL)
5033		  abort ();
5034		offp = &local_got_offsets[r_symndx];
5035	      }
5036
5037	    /* The offset must always be a multiple of 4.  We use the
5038	       least significant bit to record whether we have already
5039	       processed this entry.  */
5040	    off = *offp;
5041	    if ((off & 1) != 0)
5042	      off &= ~1;
5043	    else
5044	      {
5045		unsigned int tls_m = (tls_mask
5046				      & (TLS_LD | TLS_GD | TLS_DTPREL
5047					 | TLS_TPREL | TLS_TPRELGD));
5048
5049		if (offp == &htab->tlsld_got.offset)
5050		  tls_m = TLS_LD;
5051		else if (h == NULL
5052			 || !(h->elf_link_hash_flags
5053			      & ELF_LINK_HASH_DEF_DYNAMIC))
5054		  tls_m &= ~TLS_LD;
5055
5056		/* We might have multiple got entries for this sym.
5057		   Initialize them all.  */
5058		do
5059		  {
5060		    int tls_ty = 0;
5061
5062		    if ((tls_m & TLS_LD) != 0)
5063		      {
5064			tls_ty = TLS_TLS | TLS_LD;
5065			tls_m &= ~TLS_LD;
5066		      }
5067		    else if ((tls_m & TLS_GD) != 0)
5068		      {
5069			tls_ty = TLS_TLS | TLS_GD;
5070			tls_m &= ~TLS_GD;
5071		      }
5072		    else if ((tls_m & TLS_DTPREL) != 0)
5073		      {
5074			tls_ty = TLS_TLS | TLS_DTPREL;
5075			tls_m &= ~TLS_DTPREL;
5076		      }
5077		    else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
5078		      {
5079			tls_ty = TLS_TLS | TLS_TPREL;
5080			tls_m = 0;
5081		      }
5082
5083		    /* Generate relocs for the dynamic linker.  */
5084		    if ((info->shared || indx != 0)
5085			&& (h == NULL
5086			    || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5087			    || h->root.type != bfd_link_hash_undefweak))
5088		      {
5089			outrel.r_offset = (htab->got->output_section->vma
5090					   + htab->got->output_offset
5091					   + off);
5092			outrel.r_addend = 0;
5093			if (tls_ty & (TLS_LD | TLS_GD))
5094			  {
5095			    outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
5096			    if (tls_ty == (TLS_TLS | TLS_GD))
5097			      {
5098				loc = htab->relgot->contents;
5099				loc += (htab->relgot->reloc_count++
5100					* sizeof (Elf32_External_Rela));
5101				bfd_elf32_swap_reloca_out (output_bfd,
5102							   &outrel, loc);
5103				outrel.r_offset += 4;
5104				outrel.r_info
5105				  = ELF32_R_INFO (indx, R_PPC_DTPREL32);
5106			      }
5107			  }
5108			else if (tls_ty == (TLS_TLS | TLS_DTPREL))
5109			  outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
5110			else if (tls_ty == (TLS_TLS | TLS_TPREL))
5111			  outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
5112			else if (indx == 0)
5113			  outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE);
5114			else
5115			  outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
5116			if (indx == 0)
5117			  {
5118			    outrel.r_addend += relocation;
5119			    if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
5120			      outrel.r_addend -= htab->elf.tls_sec->vma;
5121			  }
5122			loc = htab->relgot->contents;
5123			loc += (htab->relgot->reloc_count++
5124				* sizeof (Elf32_External_Rela));
5125			bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5126		      }
5127
5128		    /* Init the .got section contents if we're not
5129		       emitting a reloc.  */
5130		    else
5131		      {
5132			bfd_vma value = relocation;
5133
5134			if (tls_ty == (TLS_TLS | TLS_LD))
5135			  value = 1;
5136			else if (tls_ty != 0)
5137			  {
5138			    value -= htab->elf.tls_sec->vma + DTP_OFFSET;
5139			    if (tls_ty == (TLS_TLS | TLS_TPREL))
5140			      value += DTP_OFFSET - TP_OFFSET;
5141
5142			    if (tls_ty == (TLS_TLS | TLS_GD))
5143			      {
5144				bfd_put_32 (output_bfd, value,
5145					    htab->got->contents + off + 4);
5146				value = 1;
5147			      }
5148			  }
5149			bfd_put_32 (output_bfd, value,
5150				    htab->got->contents + off);
5151		      }
5152
5153		    off += 4;
5154		    if (tls_ty & (TLS_LD | TLS_GD))
5155		      off += 4;
5156		  }
5157		while (tls_m != 0);
5158
5159		off = *offp;
5160		*offp = off | 1;
5161	      }
5162
5163	    if (off >= (bfd_vma) -2)
5164	      abort ();
5165
5166	    if ((tls_type & TLS_TLS) != 0)
5167	      {
5168		if (tls_type != (TLS_TLS | TLS_LD))
5169		  {
5170		    if ((tls_mask & TLS_LD) != 0
5171			&& !(h == NULL
5172			     || !(h->elf_link_hash_flags
5173				  & ELF_LINK_HASH_DEF_DYNAMIC)))
5174		      off += 8;
5175		    if (tls_type != (TLS_TLS | TLS_GD))
5176		      {
5177			if ((tls_mask & TLS_GD) != 0)
5178			  off += 8;
5179			if (tls_type != (TLS_TLS | TLS_DTPREL))
5180			  {
5181			    if ((tls_mask & TLS_DTPREL) != 0)
5182			      off += 4;
5183			  }
5184		      }
5185		  }
5186	      }
5187
5188	    relocation = htab->got->output_offset + off - 4;
5189
5190	    /* Addends on got relocations don't make much sense.
5191	       x+off@got is actually x@got+off, and since the got is
5192	       generated by a hash table traversal, the value in the
5193	       got at entry m+n bears little relation to the entry m.  */
5194	    if (addend != 0)
5195	      (*_bfd_error_handler)
5196		(_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"),
5197		 bfd_archive_filename (input_bfd),
5198		 bfd_get_section_name (input_bfd, input_section),
5199		 (long) rel->r_offset,
5200		 howto->name,
5201		 sym_name);
5202	  }
5203	break;
5204
5205	/* Relocations that need no special processing.  */
5206	case R_PPC_LOCAL24PC:
5207	  /* It makes no sense to point a local relocation
5208	     at a symbol not in this object.  */
5209	  if (unresolved_reloc)
5210	    {
5211	      if (! (*info->callbacks->undefined_symbol) (info,
5212							  h->root.root.string,
5213							  input_bfd,
5214							  input_section,
5215							  rel->r_offset,
5216							  TRUE))
5217		return FALSE;
5218	      continue;
5219	    }
5220	  break;
5221
5222	case R_PPC_DTPREL16:
5223	case R_PPC_DTPREL16_LO:
5224	case R_PPC_DTPREL16_HI:
5225	case R_PPC_DTPREL16_HA:
5226	  addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
5227	  break;
5228
5229	  /* Relocations that may need to be propagated if this is a shared
5230	     object.  */
5231	case R_PPC_TPREL16:
5232	case R_PPC_TPREL16_LO:
5233	case R_PPC_TPREL16_HI:
5234	case R_PPC_TPREL16_HA:
5235	  addend -= htab->elf.tls_sec->vma + TP_OFFSET;
5236	  /* The TPREL16 relocs shouldn't really be used in shared
5237	     libs as they will result in DT_TEXTREL being set, but
5238	     support them anyway.  */
5239	  goto dodyn;
5240
5241	case R_PPC_TPREL32:
5242	  addend -= htab->elf.tls_sec->vma + TP_OFFSET;
5243	  goto dodyn;
5244
5245	case R_PPC_DTPREL32:
5246	  addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
5247	  goto dodyn;
5248
5249	case R_PPC_DTPMOD32:
5250	  relocation = 1;
5251	  addend = 0;
5252	  goto dodyn;
5253
5254	case R_PPC_REL24:
5255	case R_PPC_REL32:
5256	case R_PPC_REL14:
5257	case R_PPC_REL14_BRTAKEN:
5258	case R_PPC_REL14_BRNTAKEN:
5259	  /* If these relocations are not to a named symbol, they can be
5260	     handled right here, no need to bother the dynamic linker.  */
5261	  if (SYMBOL_REFERENCES_LOCAL (info, h)
5262	      || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
5263	    break;
5264	  /* fall through */
5265
5266	  /* Relocations that always need to be propagated if this is a shared
5267	     object.  */
5268	case R_PPC_ADDR32:
5269	case R_PPC_ADDR24:
5270	case R_PPC_ADDR16:
5271	case R_PPC_ADDR16_LO:
5272	case R_PPC_ADDR16_HI:
5273	case R_PPC_ADDR16_HA:
5274	case R_PPC_ADDR14:
5275	case R_PPC_ADDR14_BRTAKEN:
5276	case R_PPC_ADDR14_BRNTAKEN:
5277	case R_PPC_UADDR32:
5278	case R_PPC_UADDR16:
5279	  /* r_symndx will be zero only for relocs against symbols
5280	     from removed linkonce sections, or sections discarded by
5281	     a linker script.  */
5282	dodyn:
5283	  if (r_symndx == 0)
5284	    break;
5285	  /* Fall thru.  */
5286
5287	  if ((info->shared
5288	       && (h == NULL
5289		   || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5290		   || h->root.type != bfd_link_hash_undefweak)
5291	       && (MUST_BE_DYN_RELOC (r_type)
5292		   || !SYMBOL_CALLS_LOCAL (info, h)))
5293	      || (ELIMINATE_COPY_RELOCS
5294		  && !info->shared
5295		  && (input_section->flags & SEC_ALLOC) != 0
5296		  && h != NULL
5297		  && h->dynindx != -1
5298		  && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
5299		  && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
5300		  && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0))
5301	    {
5302	      int skip;
5303
5304#ifdef DEBUG
5305	      fprintf (stderr, "ppc_elf_relocate_section needs to "
5306		       "create relocation for %s\n",
5307		       (h && h->root.root.string
5308			? h->root.root.string : "<unknown>"));
5309#endif
5310
5311	      /* When generating a shared object, these relocations
5312		 are copied into the output file to be resolved at run
5313		 time.  */
5314	      if (sreloc == NULL)
5315		{
5316		  const char *name;
5317
5318		  name = (bfd_elf_string_from_elf_section
5319			  (input_bfd,
5320			   elf_elfheader (input_bfd)->e_shstrndx,
5321			   elf_section_data (input_section)->rel_hdr.sh_name));
5322		  if (name == NULL)
5323		    return FALSE;
5324
5325		  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5326			      && strcmp (bfd_get_section_name (input_bfd,
5327							       input_section),
5328					 name + 5) == 0);
5329
5330		  sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
5331		  BFD_ASSERT (sreloc != NULL);
5332		}
5333
5334	      skip = 0;
5335
5336	      outrel.r_offset =
5337		_bfd_elf_section_offset (output_bfd, info, input_section,
5338					 rel->r_offset);
5339	      if (outrel.r_offset == (bfd_vma) -1
5340		  || outrel.r_offset == (bfd_vma) -2)
5341		skip = (int) outrel.r_offset;
5342	      outrel.r_offset += (input_section->output_section->vma
5343				  + input_section->output_offset);
5344
5345	      if (skip)
5346		memset (&outrel, 0, sizeof outrel);
5347	      else if (!SYMBOL_REFERENCES_LOCAL (info, h))
5348		{
5349		  unresolved_reloc = FALSE;
5350		  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
5351		  outrel.r_addend = rel->r_addend;
5352		}
5353	      else
5354		{
5355		  outrel.r_addend = relocation + rel->r_addend;
5356
5357		  if (r_type == R_PPC_ADDR32)
5358		    outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
5359		  else
5360		    {
5361		      long indx;
5362
5363		      if (bfd_is_abs_section (sec))
5364			indx = 0;
5365		      else if (sec == NULL || sec->owner == NULL)
5366			{
5367			  bfd_set_error (bfd_error_bad_value);
5368			  return FALSE;
5369			}
5370		      else
5371			{
5372			  asection *osec;
5373
5374			  /* We are turning this relocation into one
5375			     against a section symbol.  It would be
5376			     proper to subtract the symbol's value,
5377			     osec->vma, from the emitted reloc addend,
5378			     but ld.so expects buggy relocs.  */
5379			  osec = sec->output_section;
5380			  indx = elf_section_data (osec)->dynindx;
5381			  BFD_ASSERT (indx > 0);
5382#ifdef DEBUG
5383			  if (indx <= 0)
5384			    printf ("indx=%d section=%s flags=%08x name=%s\n",
5385				    indx, osec->name, osec->flags,
5386				    h->root.root.string);
5387#endif
5388			}
5389
5390		      outrel.r_info = ELF32_R_INFO (indx, r_type);
5391		    }
5392		}
5393
5394	      loc = sreloc->contents;
5395	      loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5396	      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5397
5398	      if (skip == -1)
5399		continue;
5400
5401	      /* This reloc will be computed at runtime.  We clear the memory
5402		 so that it contains predictable value.  */
5403	      if (! skip
5404		  && ((input_section->flags & SEC_ALLOC) != 0
5405		      || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
5406		{
5407		  relocation = howto->pc_relative ? outrel.r_offset : 0;
5408		  addend = 0;
5409		  break;
5410		}
5411	    }
5412	  break;
5413
5414	case R_PPC_RELAX32PC:
5415	  relocation -= (input_section->output_section->vma
5416			 + input_section->output_offset
5417			 + rel->r_offset - 4);
5418	  /* Fall thru */
5419	case R_PPC_RELAX32:
5420	  {
5421	    unsigned long t0;
5422	    unsigned long t1;
5423
5424	    t0 = bfd_get_32 (output_bfd, contents + rel->r_offset);
5425	    t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4);
5426
5427	    /* We're clearing the bits for R_PPC_ADDR16_HA
5428	       and R_PPC_ADDR16_LO here.  */
5429	    t0 &= ~0xffff;
5430	    t1 &= ~0xffff;
5431
5432	    /* t0 is HA, t1 is LO */
5433	    relocation += addend;
5434	    t0 |= ((relocation + 0x8000) >> 16) & 0xffff;
5435	    t1 |= relocation & 0xffff;
5436
5437	    bfd_put_32 (output_bfd, t0, contents + rel->r_offset);
5438	    bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4);
5439	  }
5440	  continue;
5441
5442	  /* Indirect .sdata relocation.  */
5443	case R_PPC_EMB_SDAI16:
5444	  BFD_ASSERT (htab->sdata != NULL);
5445	  relocation
5446	    = elf_finish_pointer_linker_section (output_bfd, input_bfd, info,
5447						 htab->sdata, h, relocation,
5448						 rel, R_PPC_RELATIVE);
5449	  break;
5450
5451	  /* Indirect .sdata2 relocation.  */
5452	case R_PPC_EMB_SDA2I16:
5453	  BFD_ASSERT (htab->sdata2 != NULL);
5454	  relocation
5455	    = elf_finish_pointer_linker_section (output_bfd, input_bfd, info,
5456						 htab->sdata2, h, relocation,
5457						 rel, R_PPC_RELATIVE);
5458	  break;
5459
5460	  /* Handle the TOC16 reloc.  We want to use the offset within the .got
5461	     section, not the actual VMA.  This is appropriate when generating
5462	     an embedded ELF object, for which the .got section acts like the
5463	     AIX .toc section.  */
5464	case R_PPC_TOC16:			/* phony GOT16 relocations */
5465	  BFD_ASSERT (sec != NULL);
5466	  BFD_ASSERT (bfd_is_und_section (sec)
5467		      || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
5468		      || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0)
5469
5470	    addend -= sec->output_section->vma + sec->output_offset + 0x8000;
5471	  break;
5472
5473	case R_PPC_PLTREL24:
5474	  /* Relocation is to the entry for this symbol in the
5475	     procedure linkage table.  */
5476	  BFD_ASSERT (h != NULL);
5477
5478	  if (h->plt.offset == (bfd_vma) -1
5479	      || htab->plt == NULL)
5480	    {
5481	      /* We didn't make a PLT entry for this symbol.  This
5482		 happens when statically linking PIC code, or when
5483		 using -Bsymbolic.  */
5484	      break;
5485	    }
5486
5487	  unresolved_reloc = FALSE;
5488	  relocation = (htab->plt->output_section->vma
5489			+ htab->plt->output_offset
5490			+ h->plt.offset);
5491	  break;
5492
5493	  /* Relocate against _SDA_BASE_.  */
5494	case R_PPC_SDAREL16:
5495	  {
5496	    const char *name;
5497	    const struct elf_link_hash_entry *sh;
5498
5499	    BFD_ASSERT (sec != NULL);
5500	    name = bfd_get_section_name (abfd, sec->output_section);
5501	    if (! ((strncmp (name, ".sdata", 6) == 0
5502		    && (name[6] == 0 || name[6] == '.'))
5503		   || (strncmp (name, ".sbss", 5) == 0
5504		       && (name[5] == 0 || name[5] == '.'))))
5505	      {
5506		(*_bfd_error_handler)
5507		  (_("%s: the target (%s) of a %s relocation is "
5508		     "in the wrong output section (%s)"),
5509		   bfd_archive_filename (input_bfd),
5510		   sym_name,
5511		   howto->name,
5512		   name);
5513	      }
5514	    sh = htab->sdata->sym_hash;
5515	    addend -= (sh->root.u.def.value
5516		       + sh->root.u.def.section->output_section->vma
5517		       + sh->root.u.def.section->output_offset);
5518	  }
5519	  break;
5520
5521	  /* Relocate against _SDA2_BASE_.  */
5522	case R_PPC_EMB_SDA2REL:
5523	  {
5524	    const char *name;
5525	    const struct elf_link_hash_entry *sh;
5526
5527	    BFD_ASSERT (sec != NULL);
5528	    name = bfd_get_section_name (abfd, sec->output_section);
5529	    if (! (strncmp (name, ".sdata2", 7) == 0
5530		   || strncmp (name, ".sbss2", 6) == 0))
5531	      {
5532		(*_bfd_error_handler)
5533		  (_("%s: the target (%s) of a %s relocation is "
5534		     "in the wrong output section (%s)"),
5535		   bfd_archive_filename (input_bfd),
5536		   sym_name,
5537		   howto->name,
5538		   name);
5539
5540		bfd_set_error (bfd_error_bad_value);
5541		ret = FALSE;
5542		continue;
5543	      }
5544	    sh = htab->sdata2->sym_hash;
5545	    addend -= (sh->root.u.def.value
5546		       + sh->root.u.def.section->output_section->vma
5547		       + sh->root.u.def.section->output_offset);
5548	  }
5549	  break;
5550
5551	  /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0.  */
5552	case R_PPC_EMB_SDA21:
5553	case R_PPC_EMB_RELSDA:
5554	  {
5555	    const char *name;
5556	    const struct elf_link_hash_entry *sh;
5557	    int reg;
5558
5559	    BFD_ASSERT (sec != NULL);
5560	    name = bfd_get_section_name (abfd, sec->output_section);
5561	    if (((strncmp (name, ".sdata", 6) == 0
5562		  && (name[6] == 0 || name[6] == '.'))
5563		 || (strncmp (name, ".sbss", 5) == 0
5564		     && (name[5] == 0 || name[5] == '.'))))
5565	      {
5566		reg = 13;
5567		sh = htab->sdata->sym_hash;
5568		addend -= (sh->root.u.def.value
5569			   + sh->root.u.def.section->output_section->vma
5570			   + sh->root.u.def.section->output_offset);
5571	      }
5572
5573	    else if (strncmp (name, ".sdata2", 7) == 0
5574		     || strncmp (name, ".sbss2", 6) == 0)
5575	      {
5576		reg = 2;
5577		sh = htab->sdata2->sym_hash;
5578		addend -= (sh->root.u.def.value
5579			   + sh->root.u.def.section->output_section->vma
5580			   + sh->root.u.def.section->output_offset);
5581	      }
5582
5583	    else if (strcmp (name, ".PPC.EMB.sdata0") == 0
5584		     || strcmp (name, ".PPC.EMB.sbss0") == 0)
5585	      {
5586		reg = 0;
5587	      }
5588
5589	    else
5590	      {
5591		(*_bfd_error_handler)
5592		  (_("%s: the target (%s) of a %s relocation is "
5593		     "in the wrong output section (%s)"),
5594		   bfd_archive_filename (input_bfd),
5595		   sym_name,
5596		   howto->name,
5597		   name);
5598
5599		bfd_set_error (bfd_error_bad_value);
5600		ret = FALSE;
5601		continue;
5602	      }
5603
5604	    if (r_type == R_PPC_EMB_SDA21)
5605	      {			/* fill in register field */
5606		insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
5607		insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
5608		bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
5609	      }
5610	  }
5611	  break;
5612
5613	  /* Relocate against the beginning of the section.  */
5614	case R_PPC_SECTOFF:
5615	case R_PPC_SECTOFF_LO:
5616	case R_PPC_SECTOFF_HI:
5617	case R_PPC_SECTOFF_HA:
5618	  BFD_ASSERT (sec != NULL);
5619	  addend -= sec->output_section->vma;
5620	  break;
5621
5622	  /* Negative relocations.  */
5623	case R_PPC_EMB_NADDR32:
5624	case R_PPC_EMB_NADDR16:
5625	case R_PPC_EMB_NADDR16_LO:
5626	case R_PPC_EMB_NADDR16_HI:
5627	case R_PPC_EMB_NADDR16_HA:
5628	  addend -= 2 * relocation;
5629	  break;
5630
5631	case R_PPC_COPY:
5632	case R_PPC_GLOB_DAT:
5633	case R_PPC_JMP_SLOT:
5634	case R_PPC_RELATIVE:
5635	case R_PPC_PLT32:
5636	case R_PPC_PLTREL32:
5637	case R_PPC_PLT16_LO:
5638	case R_PPC_PLT16_HI:
5639	case R_PPC_PLT16_HA:
5640	case R_PPC_ADDR30:
5641	case R_PPC_EMB_RELSEC16:
5642	case R_PPC_EMB_RELST_LO:
5643	case R_PPC_EMB_RELST_HI:
5644	case R_PPC_EMB_RELST_HA:
5645	case R_PPC_EMB_BIT_FLD:
5646	  (*_bfd_error_handler)
5647	    (_("%s: relocation %s is not yet supported for symbol %s."),
5648	     bfd_archive_filename (input_bfd),
5649	     howto->name,
5650	     sym_name);
5651
5652	  bfd_set_error (bfd_error_invalid_operation);
5653	  ret = FALSE;
5654	  continue;
5655	}
5656
5657      /* Do any further special processing.  */
5658      switch (r_type)
5659	{
5660	default:
5661	  break;
5662
5663	case R_PPC_ADDR16_HA:
5664	case R_PPC_GOT16_HA:
5665	case R_PPC_PLT16_HA:
5666	case R_PPC_SECTOFF_HA:
5667	case R_PPC_TPREL16_HA:
5668	case R_PPC_DTPREL16_HA:
5669	case R_PPC_GOT_TLSGD16_HA:
5670	case R_PPC_GOT_TLSLD16_HA:
5671	case R_PPC_GOT_TPREL16_HA:
5672	case R_PPC_GOT_DTPREL16_HA:
5673	case R_PPC_EMB_NADDR16_HA:
5674	case R_PPC_EMB_RELST_HA:
5675	  /* It's just possible that this symbol is a weak symbol
5676	     that's not actually defined anywhere.  In that case,
5677	     'sec' would be NULL, and we should leave the symbol
5678	     alone (it will be set to zero elsewhere in the link).  */
5679	  if (sec != NULL)
5680	    /* Add 0x10000 if sign bit in 0:15 is set.
5681	       Bits 0:15 are not used.  */
5682	    addend += 0x8000;
5683	  break;
5684	}
5685
5686#ifdef DEBUG
5687      fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, "
5688	       "offset = %ld, addend = %ld\n",
5689	       howto->name,
5690	       (int) r_type,
5691	       sym_name,
5692	       r_symndx,
5693	       (long) rel->r_offset,
5694	       (long) addend);
5695#endif
5696
5697      if (unresolved_reloc
5698	  && !((input_section->flags & SEC_DEBUGGING) != 0
5699	       && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
5700	{
5701	  (*_bfd_error_handler)
5702	    (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
5703	     bfd_archive_filename (input_bfd),
5704	     bfd_get_section_name (input_bfd, input_section),
5705	     (long) rel->r_offset,
5706	     howto->name,
5707	     sym_name);
5708	  ret = FALSE;
5709	}
5710
5711      r = _bfd_final_link_relocate (howto,
5712				    input_bfd,
5713				    input_section,
5714				    contents,
5715				    rel->r_offset,
5716				    relocation,
5717				    addend);
5718
5719      if (r != bfd_reloc_ok)
5720	{
5721	  if (sym_name == NULL)
5722	    sym_name = "(null)";
5723	  if (r == bfd_reloc_overflow)
5724	    {
5725	      if (warned)
5726		continue;
5727	      if (h != NULL
5728		  && h->root.type == bfd_link_hash_undefweak
5729		  && howto->pc_relative)
5730		{
5731		  /* Assume this is a call protected by other code that
5732		     detect the symbol is undefined.  If this is the case,
5733		     we can safely ignore the overflow.  If not, the
5734		     program is hosed anyway, and a little warning isn't
5735		     going to help.  */
5736
5737		  continue;
5738		}
5739
5740	      if (! (*info->callbacks->reloc_overflow) (info,
5741							sym_name,
5742							howto->name,
5743							rel->r_addend,
5744							input_bfd,
5745							input_section,
5746							rel->r_offset))
5747		return FALSE;
5748	    }
5749	  else
5750	    {
5751	      (*_bfd_error_handler)
5752		(_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
5753		 bfd_archive_filename (input_bfd),
5754		 bfd_get_section_name (input_bfd, input_section),
5755		 (long) rel->r_offset, howto->name, sym_name, (int) r);
5756	      ret = FALSE;
5757	    }
5758	}
5759    }
5760
5761#ifdef DEBUG
5762  fprintf (stderr, "\n");
5763#endif
5764
5765  return ret;
5766}
5767
5768static enum elf_reloc_type_class
5769ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela)
5770{
5771  switch (ELF32_R_TYPE (rela->r_info))
5772    {
5773    case R_PPC_RELATIVE:
5774      return reloc_class_relative;
5775    case R_PPC_REL24:
5776    case R_PPC_ADDR24:
5777    case R_PPC_JMP_SLOT:
5778      return reloc_class_plt;
5779    case R_PPC_COPY:
5780      return reloc_class_copy;
5781    default:
5782      return reloc_class_normal;
5783    }
5784}
5785
5786/* Support for core dump NOTE sections.  */
5787
5788static bfd_boolean
5789ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
5790{
5791  int offset;
5792  unsigned int raw_size;
5793
5794  switch (note->descsz)
5795    {
5796    default:
5797      return FALSE;
5798
5799    case 268:		/* Linux/PPC.  */
5800      /* pr_cursig */
5801      elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
5802
5803      /* pr_pid */
5804      elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
5805
5806      /* pr_reg */
5807      offset = 72;
5808      raw_size = 192;
5809
5810      break;
5811    }
5812
5813  /* Make a ".reg/999" section.  */
5814  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
5815					  raw_size, note->descpos + offset);
5816}
5817
5818static bfd_boolean
5819ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
5820{
5821  switch (note->descsz)
5822    {
5823    default:
5824      return FALSE;
5825
5826    case 128:		/* Linux/PPC elf_prpsinfo.  */
5827      elf_tdata (abfd)->core_program
5828	= _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
5829      elf_tdata (abfd)->core_command
5830	= _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
5831    }
5832
5833  /* Note that for some reason, a spurious space is tacked
5834     onto the end of the args in some (at least one anyway)
5835     implementations, so strip it off if it exists.  */
5836
5837  {
5838    char *command = elf_tdata (abfd)->core_command;
5839    int n = strlen (command);
5840
5841    if (0 < n && command[n - 1] == ' ')
5842      command[n - 1] = '\0';
5843  }
5844
5845  return TRUE;
5846}
5847
5848/* Very simple linked list structure for recording apuinfo values.  */
5849typedef struct apuinfo_list
5850{
5851  struct apuinfo_list *next;
5852  unsigned long value;
5853}
5854apuinfo_list;
5855
5856static apuinfo_list *head;
5857
5858
5859static void
5860apuinfo_list_init (void)
5861{
5862  head = NULL;
5863}
5864
5865static void
5866apuinfo_list_add (unsigned long value)
5867{
5868  apuinfo_list *entry = head;
5869
5870  while (entry != NULL)
5871    {
5872      if (entry->value == value)
5873	return;
5874      entry = entry->next;
5875    }
5876
5877  entry = bfd_malloc (sizeof (* entry));
5878  if (entry == NULL)
5879    return;
5880
5881  entry->value = value;
5882  entry->next  = head;
5883  head = entry;
5884}
5885
5886static unsigned
5887apuinfo_list_length (void)
5888{
5889  apuinfo_list *entry;
5890  unsigned long count;
5891
5892  for (entry = head, count = 0;
5893       entry;
5894       entry = entry->next)
5895    ++ count;
5896
5897  return count;
5898}
5899
5900static inline unsigned long
5901apuinfo_list_element (unsigned long number)
5902{
5903  apuinfo_list * entry;
5904
5905  for (entry = head;
5906       entry && number --;
5907       entry = entry->next)
5908    ;
5909
5910  return entry ? entry->value : 0;
5911}
5912
5913static void
5914apuinfo_list_finish (void)
5915{
5916  apuinfo_list *entry;
5917
5918  for (entry = head; entry;)
5919    {
5920      apuinfo_list *next = entry->next;
5921      free (entry);
5922      entry = next;
5923    }
5924
5925  head = NULL;
5926}
5927
5928#define APUINFO_SECTION_NAME	".PPC.EMB.apuinfo"
5929#define APUINFO_LABEL		"APUinfo"
5930
5931/* Scan the input BFDs and create a linked list of
5932   the APUinfo values that will need to be emitted.  */
5933
5934static void
5935ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
5936{
5937  bfd *ibfd;
5938  asection *asec;
5939  char *buffer;
5940  unsigned num_input_sections;
5941  bfd_size_type	output_section_size;
5942  unsigned i;
5943  unsigned num_entries;
5944  unsigned long	offset;
5945  unsigned long length;
5946  const char *error_message = NULL;
5947
5948  if (link_info == NULL)
5949    return;
5950
5951  /* Scan the input bfds, looking for apuinfo sections.  */
5952  num_input_sections = 0;
5953  output_section_size = 0;
5954
5955  for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
5956    {
5957      asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
5958      if (asec)
5959	{
5960	  ++ num_input_sections;
5961	  output_section_size += asec->_raw_size;
5962	}
5963    }
5964
5965  /* We need at least one input sections
5966     in order to make merging worthwhile.  */
5967  if (num_input_sections < 1)
5968    return;
5969
5970  /* Just make sure that the output section exists as well.  */
5971  asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
5972  if (asec == NULL)
5973    return;
5974
5975  /* Allocate a buffer for the contents of the input sections.  */
5976  buffer = bfd_malloc (output_section_size);
5977  if (buffer == NULL)
5978    return;
5979
5980  offset = 0;
5981  apuinfo_list_init ();
5982
5983  /* Read in the input sections contents.  */
5984  for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
5985    {
5986      unsigned long datum;
5987      char *ptr;
5988
5989      asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
5990      if (asec == NULL)
5991	continue;
5992
5993      length = asec->_raw_size;
5994      if (length < 24)
5995	{
5996	  error_message = _("corrupt or empty %s section in %s");
5997	  goto fail;
5998	}
5999
6000      if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
6001	  || (bfd_bread (buffer + offset, length, ibfd) != length))
6002	{
6003	  error_message = _("unable to read in %s section from %s");
6004	  goto fail;
6005	}
6006
6007      /* Process the contents of the section.  */
6008      ptr = buffer + offset;
6009      error_message = _("corrupt %s section in %s");
6010
6011      /* Verify the contents of the header.  Note - we have to
6012	 extract the values this way in order to allow for a
6013	 host whose endian-ness is different from the target.  */
6014      datum = bfd_get_32 (ibfd, ptr);
6015      if (datum != sizeof APUINFO_LABEL)
6016	goto fail;
6017
6018      datum = bfd_get_32 (ibfd, ptr + 8);
6019      if (datum != 0x2)
6020	goto fail;
6021
6022      if (strcmp (ptr + 12, APUINFO_LABEL) != 0)
6023	goto fail;
6024
6025      /* Get the number of bytes used for apuinfo entries.  */
6026      datum = bfd_get_32 (ibfd, ptr + 4);
6027      if (datum + 20 != length)
6028	goto fail;
6029
6030      /* Make sure that we do not run off the end of the section.  */
6031      if (offset + length > output_section_size)
6032	goto fail;
6033
6034      /* Scan the apuinfo section, building a list of apuinfo numbers.  */
6035      for (i = 0; i < datum; i += 4)
6036	apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + i));
6037
6038      /* Update the offset.  */
6039      offset += length;
6040    }
6041
6042  error_message = NULL;
6043
6044  /* Compute the size of the output section.  */
6045  num_entries = apuinfo_list_length ();
6046  output_section_size = 20 + num_entries * 4;
6047
6048  asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
6049
6050  if (! bfd_set_section_size (abfd, asec, output_section_size))
6051    ibfd = abfd,
6052      error_message = _("warning: unable to set size of %s section in %s");
6053
6054 fail:
6055  free (buffer);
6056
6057  if (error_message)
6058    (*_bfd_error_handler) (error_message, APUINFO_SECTION_NAME,
6059			   bfd_archive_filename (ibfd));
6060}
6061
6062
6063/* Prevent the output section from accumulating the input sections'
6064   contents.  We have already stored this in our linked list structure.  */
6065
6066static bfd_boolean
6067ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
6068		       asection *asec,
6069		       bfd_byte *contents ATTRIBUTE_UNUSED)
6070{
6071  return (apuinfo_list_length ()
6072	  && strcmp (asec->name, APUINFO_SECTION_NAME) == 0);
6073}
6074
6075
6076/* Finally we can generate the output section.  */
6077
6078static void
6079ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
6080{
6081  bfd_byte *buffer;
6082  asection *asec;
6083  unsigned i;
6084  unsigned num_entries;
6085  bfd_size_type length;
6086
6087  asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
6088  if (asec == NULL)
6089    return;
6090
6091  if (apuinfo_list_length () == 0)
6092    return;
6093
6094  length = asec->_raw_size;
6095  if (length < 20)
6096    return;
6097
6098  buffer = bfd_malloc (length);
6099  if (buffer == NULL)
6100    {
6101      (*_bfd_error_handler)
6102	(_("failed to allocate space for new APUinfo section."));
6103      return;
6104    }
6105
6106  /* Create the apuinfo header.  */
6107  num_entries = apuinfo_list_length ();
6108  bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
6109  bfd_put_32 (abfd, num_entries * 4, buffer + 4);
6110  bfd_put_32 (abfd, 0x2, buffer + 8);
6111  strcpy (buffer + 12, APUINFO_LABEL);
6112
6113  length = 20;
6114  for (i = 0; i < num_entries; i++)
6115    {
6116      bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
6117      length += 4;
6118    }
6119
6120  if (length != asec->_raw_size)
6121    (*_bfd_error_handler) (_("failed to compute new APUinfo section."));
6122
6123  if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
6124    (*_bfd_error_handler) (_("failed to install new APUinfo section."));
6125
6126  free (buffer);
6127
6128  apuinfo_list_finish ();
6129}
6130
6131/* Add extra PPC sections -- Note, for now, make .sbss2 and
6132   .PPC.EMB.sbss0 a normal section, and not a bss section so
6133   that the linker doesn't crater when trying to make more than
6134   2 sections.  */
6135
6136static struct bfd_elf_special_section const ppc_elf_special_sections[]=
6137{
6138  { ".tags",             5,  0, SHT_ORDERED,  SHF_ALLOC },
6139  { ".sdata",            6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
6140  { ".sbss",             5, -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE },
6141  { ".sdata2",           7, -2, SHT_PROGBITS, SHF_ALLOC },
6142  { ".sbss2",            6, -2, SHT_PROGBITS, SHF_ALLOC },
6143  { ".PPC.EMB.apuinfo", 16,  0, SHT_NOTE,     0 },
6144  { ".PPC.EMB.sdata0",  15,  0, SHT_PROGBITS, SHF_ALLOC },
6145  { ".PPC.EMB.sbss0",   14,  0, SHT_PROGBITS, SHF_ALLOC },
6146  { ".plt",              4,  0, SHT_NOBITS,   SHF_ALLOC + SHF_EXECINSTR },
6147  { NULL,                0,  0, 0,            0 }
6148};
6149
6150#define TARGET_LITTLE_SYM	bfd_elf32_powerpcle_vec
6151#define TARGET_LITTLE_NAME	"elf32-powerpcle"
6152#define TARGET_BIG_SYM		bfd_elf32_powerpc_vec
6153#define TARGET_BIG_NAME		"elf32-powerpc"
6154#define ELF_ARCH		bfd_arch_powerpc
6155#define ELF_MACHINE_CODE	EM_PPC
6156#ifdef __QNXTARGET__
6157#define ELF_MAXPAGESIZE		0x1000
6158#else
6159#define ELF_MAXPAGESIZE		0x10000
6160#endif
6161#define elf_info_to_howto	ppc_elf_info_to_howto
6162
6163#ifdef  EM_CYGNUS_POWERPC
6164#define ELF_MACHINE_ALT1	EM_CYGNUS_POWERPC
6165#endif
6166
6167#ifdef EM_PPC_OLD
6168#define ELF_MACHINE_ALT2	EM_PPC_OLD
6169#endif
6170
6171#define elf_backend_plt_not_loaded	1
6172#define elf_backend_got_symbol_offset	4
6173#define elf_backend_can_gc_sections	1
6174#define elf_backend_can_refcount	1
6175#define elf_backend_got_header_size	12
6176#define elf_backend_rela_normal		1
6177
6178#define bfd_elf32_mkobject			ppc_elf_mkobject
6179#define bfd_elf32_bfd_merge_private_bfd_data	ppc_elf_merge_private_bfd_data
6180#define bfd_elf32_bfd_relax_section		ppc_elf_relax_section
6181#define bfd_elf32_bfd_reloc_type_lookup		ppc_elf_reloc_type_lookup
6182#define bfd_elf32_bfd_set_private_flags		ppc_elf_set_private_flags
6183#define bfd_elf32_bfd_link_hash_table_create	ppc_elf_link_hash_table_create
6184
6185#define elf_backend_object_p			ppc_elf_object_p
6186#define elf_backend_gc_mark_hook		ppc_elf_gc_mark_hook
6187#define elf_backend_gc_sweep_hook		ppc_elf_gc_sweep_hook
6188#define elf_backend_section_from_shdr		ppc_elf_section_from_shdr
6189#define elf_backend_relocate_section		ppc_elf_relocate_section
6190#define elf_backend_create_dynamic_sections	ppc_elf_create_dynamic_sections
6191#define elf_backend_check_relocs		ppc_elf_check_relocs
6192#define elf_backend_copy_indirect_symbol	ppc_elf_copy_indirect_symbol
6193#define elf_backend_adjust_dynamic_symbol	ppc_elf_adjust_dynamic_symbol
6194#define elf_backend_add_symbol_hook		ppc_elf_add_symbol_hook
6195#define elf_backend_size_dynamic_sections	ppc_elf_size_dynamic_sections
6196#define elf_backend_finish_dynamic_symbol	ppc_elf_finish_dynamic_symbol
6197#define elf_backend_finish_dynamic_sections	ppc_elf_finish_dynamic_sections
6198#define elf_backend_fake_sections		ppc_elf_fake_sections
6199#define elf_backend_additional_program_headers	ppc_elf_additional_program_headers
6200#define elf_backend_modify_segment_map		ppc_elf_modify_segment_map
6201#define elf_backend_grok_prstatus		ppc_elf_grok_prstatus
6202#define elf_backend_grok_psinfo			ppc_elf_grok_psinfo
6203#define elf_backend_reloc_type_class		ppc_elf_reloc_type_class
6204#define elf_backend_begin_write_processing	ppc_elf_begin_write_processing
6205#define elf_backend_final_write_processing	ppc_elf_final_write_processing
6206#define elf_backend_write_section		ppc_elf_write_section
6207#define elf_backend_special_sections		ppc_elf_special_sections
6208
6209#include "elf32-target.h"
6210