#include "bfd.h"
#include "sysdep.h"
#include "bfdlink.h"
#include "libbfd.h"
#include "elf-bfd.h"
#include "elf/ppc.h"
#include "elf64-ppc.h"
#define USE_RELA
static void ppc_howto_init
PARAMS ((void));
static reloc_howto_type *ppc64_elf_reloc_type_lookup
PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
static void ppc64_elf_info_to_howto
PARAMS ((bfd *abfd, arelent *cache_ptr, Elf64_Internal_Rela *dst));
static bfd_reloc_status_type ppc64_elf_addr16_ha_reloc
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
static boolean ppc64_elf_set_private_flags
PARAMS ((bfd *, flagword));
static boolean ppc64_elf_merge_private_bfd_data
PARAMS ((bfd *, bfd *));
static boolean ppc64_elf_section_from_shdr
PARAMS ((bfd *, Elf64_Internal_Shdr *, char *));
static struct bfd_hash_entry *link_hash_newfunc
PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
static struct bfd_link_hash_table *ppc64_elf_link_hash_table_create
PARAMS ((bfd *));
static boolean create_linkage_sections
PARAMS ((bfd *, struct bfd_link_info *));
static boolean create_got_section
PARAMS ((bfd *, struct bfd_link_info *));
static boolean ppc64_elf_create_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
static void ppc64_elf_copy_indirect_symbol
PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
static boolean ppc64_elf_check_relocs
PARAMS ((bfd *, struct bfd_link_info *, asection *,
const Elf_Internal_Rela *));
static asection * ppc64_elf_gc_mark_hook
PARAMS ((bfd *abfd, struct bfd_link_info *info, Elf_Internal_Rela *rel,
struct elf_link_hash_entry *h, Elf_Internal_Sym *sym));
static boolean ppc64_elf_gc_sweep_hook
PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
const Elf_Internal_Rela *relocs));
static boolean func_desc_adjust
PARAMS ((struct elf_link_hash_entry *, PTR));
static boolean ppc64_elf_func_desc_adjust
PARAMS ((bfd *, struct bfd_link_info *));
static boolean ppc64_elf_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
static void ppc64_elf_hide_symbol
PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean));
static boolean allocate_dynrelocs
PARAMS ((struct elf_link_hash_entry *, PTR));
static boolean readonly_dynrelocs
PARAMS ((struct elf_link_hash_entry *, PTR));
static enum elf_reloc_type_class ppc64_elf_reloc_type_class
PARAMS ((const Elf_Internal_Rela *));
static boolean ppc64_elf_size_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
static bfd_byte *build_plt_stub
PARAMS ((bfd *, bfd_byte *, int, int));
static boolean build_one_stub
PARAMS ((struct elf_link_hash_entry *, PTR));
static boolean ppc64_elf_fake_sections
PARAMS ((bfd *, Elf64_Internal_Shdr *, asection *));
static boolean ppc64_elf_relocate_section
PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *,
Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
asection **));
static boolean ppc64_elf_finish_dynamic_symbol
PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
Elf_Internal_Sym *));
static boolean ppc64_elf_finish_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
#define RA_REGISTER_MASK 0x001f0000
#define RA_REGISTER_SHIFT 16
#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
#define PLT_ENTRY_SIZE 24
#define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
#define TOC_BASE_OFF (0x8000)
#define ADDIS_R12_R2 0x3d820000
#define STD_R2_40R1 0xf8410028
#define LD_R11_0R12 0xe96c0000
#define LD_R2_0R12 0xe84c0000
#define MTCTR_R11 0x7d6903a6
#define BCTR 0x4e800420
#define PLT_CALL_STUB_SIZE (7*4)
#define ADDIS_R12_R12_1 0x3d8c0001
#define LD_R2_40R1 0xe8410028
#define GLINK_CALL_STUB_SIZE (8*4)
#define NOP 0x60000000
#define LI_R0_0 0x38000000
#define B_DOT 0x48000000
#define LIS_R0_0 0x3c000000
#define ORI_R0_R0_0 0x60000000
#define STFD_FR0_0R1 0xd8010000
#define LFD_FR0_0R1 0xc8010000
#define BLR 0x4e800020
#ifndef NO_OPD_RELOCS
#define NO_OPD_RELOCS 0
#endif
static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC_max];
static reloc_howto_type ppc64_elf_howto_raw[] = {
HOWTO (R_PPC64_NONE,
0,
2,
32,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_NONE",
false,
0,
0,
false),
HOWTO (R_PPC64_ADDR32,
0,
2,
32,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_ADDR32",
false,
0,
0xffffffff,
false),
HOWTO (R_PPC64_ADDR24,
0,
2,
26,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_ADDR24",
false,
0,
0x3fffffc,
false),
HOWTO (R_PPC64_ADDR16,
0,
1,
16,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_ADDR16",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_ADDR16_LO,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_ADDR16_LO",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_ADDR16_HI,
16,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_ADDR16_HI",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_ADDR16_HA,
16,
1,
16,
false,
0,
complain_overflow_dont,
ppc64_elf_addr16_ha_reloc,
"R_PPC64_ADDR16_HA",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_ADDR14,
0,
2,
16,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_ADDR14",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_ADDR14_BRTAKEN,
0,
2,
16,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_ADDR14_BRTAKEN",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_ADDR14_BRNTAKEN,
0,
2,
16,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_ADDR14_BRNTAKEN",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_REL24,
0,
2,
26,
true,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_REL24",
false,
0,
0x3fffffc,
true),
HOWTO (R_PPC64_REL14,
0,
2,
16,
true,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_REL14",
false,
0,
0xfffc,
true),
HOWTO (R_PPC64_REL14_BRTAKEN,
0,
2,
16,
true,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_REL14_BRTAKEN",
false,
0,
0xfffc,
true),
HOWTO (R_PPC64_REL14_BRNTAKEN,
0,
2,
16,
true,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_REL14_BRNTAKEN",
false,
0,
0xfffc,
true),
HOWTO (R_PPC64_GOT16,
0,
1,
16,
false,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_GOT16",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_GOT16_LO,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_GOT16_LO",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_GOT16_HI,
16,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_GOT16_HI",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_GOT16_HA,
16,
1,
16,
false,
0,
complain_overflow_dont,
ppc64_elf_addr16_ha_reloc,
"R_PPC64_GOT16_HA",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_COPY,
0,
2,
32,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_COPY",
false,
0,
0,
false),
HOWTO (R_PPC64_GLOB_DAT,
0,
4,
64,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_GLOB_DAT",
false,
0,
0xffffffffffffffff,
false),
HOWTO (R_PPC64_JMP_SLOT,
0,
0,
0,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_JMP_SLOT",
false,
0,
0,
false),
HOWTO (R_PPC64_RELATIVE,
0,
4,
64,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_RELATIVE",
false,
0,
0xffffffffffffffff,
false),
HOWTO (R_PPC64_UADDR32,
0,
2,
32,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_UADDR32",
false,
0,
0xffffffff,
false),
HOWTO (R_PPC64_UADDR16,
0,
1,
16,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_UADDR16",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_REL32,
0,
2,
32,
true,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_REL32",
false,
0,
0xffffffff,
true),
HOWTO (R_PPC64_PLT32,
0,
2,
32,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_PLT32",
false,
0,
0,
false),
HOWTO (R_PPC64_PLTREL32,
0,
2,
32,
true,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_PLTREL32",
false,
0,
0,
true),
HOWTO (R_PPC64_PLT16_LO,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_PLT16_LO",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_PLT16_HI,
16,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_PLT16_HI",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_PLT16_HA,
16,
1,
16,
false,
0,
complain_overflow_dont,
ppc64_elf_addr16_ha_reloc,
"R_PPC64_PLT16_HA",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_SECTOFF,
0,
2,
32,
true,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_SECTOFF",
false,
0,
0,
true),
HOWTO (R_PPC64_SECTOFF_LO,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_SECTOFF_LO",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_SECTOFF_HI,
16,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_SECTOFF_HI",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_SECTOFF_HA,
16,
1,
16,
false,
0,
complain_overflow_dont,
ppc64_elf_addr16_ha_reloc,
"R_PPC64_SECTOFF_HA",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_ADDR30,
2,
2,
30,
true,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_ADDR30",
false,
0,
0xfffffffc,
true),
HOWTO (R_PPC64_ADDR64,
0,
4,
64,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_ADDR64",
false,
0,
0xffffffffffffffff,
false),
HOWTO (R_PPC64_ADDR16_HIGHER,
32,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_ADDR16_HIGHER",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_ADDR16_HIGHERA,
32,
1,
16,
false,
0,
complain_overflow_dont,
ppc64_elf_addr16_ha_reloc,
"R_PPC64_ADDR16_HIGHERA",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_ADDR16_HIGHEST,
48,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_ADDR16_HIGHEST",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_ADDR16_HIGHESTA,
48,
1,
16,
false,
0,
complain_overflow_dont,
ppc64_elf_addr16_ha_reloc,
"R_PPC64_ADDR16_HIGHESTA",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_UADDR64,
0,
4,
64,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_UADDR64",
false,
0,
0xffffffffffffffff,
false),
HOWTO (R_PPC64_REL64,
0,
4,
64,
true,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_REL64",
false,
0,
0xffffffffffffffff,
true),
HOWTO (R_PPC64_PLT64,
0,
4,
64,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_PLT64",
false,
0,
0,
false),
HOWTO (R_PPC64_PLTREL64,
0,
4,
64,
true,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_PLTREL64",
false,
0,
0,
true),
HOWTO (R_PPC64_TOC16,
0,
1,
16,
false,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_TOC16",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_TOC16_LO,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_TOC16_LO",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_TOC16_HI,
16,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_TOC16_HI",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_TOC16_HA,
16,
1,
16,
false,
0,
complain_overflow_dont,
ppc64_elf_addr16_ha_reloc,
"R_PPC64_TOC16_HA",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_TOC,
0,
4,
64,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_TOC",
false,
0,
0xffffffffffffffff,
false),
HOWTO (R_PPC64_PLTGOT16,
0,
1,
16,
false,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_PLTGOT16",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_PLTGOT16_LO,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_PLTGOT16_LO",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_PLTGOT16_HI,
16,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_PLTGOT16_HI",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_PLTGOT16_HA,
16,
1,
16,
false,
0,
complain_overflow_dont,
ppc64_elf_addr16_ha_reloc,
"R_PPC64_PLTGOT16_HA",
false,
0,
0xffff,
false),
HOWTO (R_PPC64_ADDR16_DS,
0,
1,
16,
false,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_ADDR16_DS",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_ADDR16_LO_DS,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_ADDR16_LO_DS",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_GOT16_DS,
0,
1,
16,
false,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_GOT16_DS",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_GOT16_LO_DS,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_GOT16_LO_DS",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_PLT16_LO_DS,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_PLT16_LO_DS",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_SECTOFF_DS,
0,
2,
32,
true,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_PPC64_SECTOFF_DS",
false,
0,
0,
true),
HOWTO (R_PPC64_SECTOFF_LO_DS,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_SECTOFF_LO_DS",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_TOC16_DS,
0,
1,
16,
false,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_TOC16_DS",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_TOC16_LO_DS,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_TOC16_LO_DS",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_PLTGOT16_DS,
0,
1,
16,
false,
0,
complain_overflow_signed,
bfd_elf_generic_reloc,
"R_PPC64_PLTGOT16_DS",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_PLTGOT16_LO_DS,
0,
1,
16,
false,
0,
complain_overflow_dont,
bfd_elf_generic_reloc,
"R_PPC64_PLTGOT16_LO_DS",
false,
0,
0xfffc,
false),
HOWTO (R_PPC64_GNU_VTINHERIT,
0,
0,
0,
false,
0,
complain_overflow_dont,
NULL,
"R_PPC64_GNU_VTINHERIT",
false,
0,
0,
false),
HOWTO (R_PPC64_GNU_VTENTRY,
0,
0,
0,
false,
0,
complain_overflow_dont,
NULL,
"R_PPC64_GNU_VTENTRY",
false,
0,
0,
false),
};
static void
ppc_howto_init ()
{
unsigned int i, type;
for (i = 0;
i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
i++)
{
type = ppc64_elf_howto_raw[i].type;
BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
/ sizeof (ppc64_elf_howto_table[0])));
ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
}
}
static reloc_howto_type *
ppc64_elf_reloc_type_lookup (abfd, code)
bfd *abfd ATTRIBUTE_UNUSED;
bfd_reloc_code_real_type code;
{
enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
ppc_howto_init ();
switch ((int) code)
{
default:
return (reloc_howto_type *) NULL;
case BFD_RELOC_NONE: ppc_reloc = R_PPC64_NONE;
break;
case BFD_RELOC_32: ppc_reloc = R_PPC64_ADDR32;
break;
case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC64_ADDR24;
break;
case BFD_RELOC_16: ppc_reloc = R_PPC64_ADDR16;
break;
case BFD_RELOC_LO16: ppc_reloc = R_PPC64_ADDR16_LO;
break;
case BFD_RELOC_HI16: ppc_reloc = R_PPC64_ADDR16_HI;
break;
case BFD_RELOC_HI16_S: ppc_reloc = R_PPC64_ADDR16_HA;
break;
case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC64_ADDR14;
break;
case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC64_ADDR14_BRTAKEN;
break;
case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC64_ADDR14_BRNTAKEN;
break;
case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC64_REL24;
break;
case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC64_REL14;
break;
case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC64_REL14_BRTAKEN;
break;
case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC64_REL14_BRNTAKEN;
break;
case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC64_GOT16;
break;
case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC64_GOT16_LO;
break;
case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC64_GOT16_HI;
break;
case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC64_GOT16_HA;
break;
case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC64_COPY;
break;
case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC64_GLOB_DAT;
break;
case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC64_REL32;
break;
case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC64_PLT32;
break;
case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL32;
break;
case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC64_PLT16_LO;
break;
case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC64_PLT16_HI;
break;
case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC64_PLT16_HA;
break;
case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC64_SECTOFF;
break;
case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_LO;
break;
case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HI;
break;
case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HA;
break;
case BFD_RELOC_CTOR: ppc_reloc = R_PPC64_ADDR64;
break;
case BFD_RELOC_64: ppc_reloc = R_PPC64_ADDR64;
break;
case BFD_RELOC_PPC64_HIGHER: ppc_reloc = R_PPC64_ADDR16_HIGHER;
break;
case BFD_RELOC_PPC64_HIGHER_S: ppc_reloc = R_PPC64_ADDR16_HIGHERA;
break;
case BFD_RELOC_PPC64_HIGHEST: ppc_reloc = R_PPC64_ADDR16_HIGHEST;
break;
case BFD_RELOC_PPC64_HIGHEST_S: ppc_reloc = R_PPC64_ADDR16_HIGHESTA;
break;
case BFD_RELOC_64_PCREL: ppc_reloc = R_PPC64_REL64;
break;
case BFD_RELOC_64_PLTOFF: ppc_reloc = R_PPC64_PLT64;
break;
case BFD_RELOC_64_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL64;
break;
case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC64_TOC16;
break;
case BFD_RELOC_PPC64_TOC16_LO: ppc_reloc = R_PPC64_TOC16_LO;
break;
case BFD_RELOC_PPC64_TOC16_HI: ppc_reloc = R_PPC64_TOC16_HI;
break;
case BFD_RELOC_PPC64_TOC16_HA: ppc_reloc = R_PPC64_TOC16_HA;
break;
case BFD_RELOC_PPC64_TOC: ppc_reloc = R_PPC64_TOC;
break;
case BFD_RELOC_PPC64_PLTGOT16: ppc_reloc = R_PPC64_PLTGOT16;
break;
case BFD_RELOC_PPC64_PLTGOT16_LO: ppc_reloc = R_PPC64_PLTGOT16_LO;
break;
case BFD_RELOC_PPC64_PLTGOT16_HI: ppc_reloc = R_PPC64_PLTGOT16_HI;
break;
case BFD_RELOC_PPC64_PLTGOT16_HA: ppc_reloc = R_PPC64_PLTGOT16_HA;
break;
case BFD_RELOC_PPC64_ADDR16_DS: ppc_reloc = R_PPC64_ADDR16_DS;
break;
case BFD_RELOC_PPC64_ADDR16_LO_DS: ppc_reloc = R_PPC64_ADDR16_LO_DS;
break;
case BFD_RELOC_PPC64_GOT16_DS: ppc_reloc = R_PPC64_GOT16_DS;
break;
case BFD_RELOC_PPC64_GOT16_LO_DS: ppc_reloc = R_PPC64_GOT16_LO_DS;
break;
case BFD_RELOC_PPC64_PLT16_LO_DS: ppc_reloc = R_PPC64_PLT16_LO_DS;
break;
case BFD_RELOC_PPC64_SECTOFF_DS: ppc_reloc = R_PPC64_SECTOFF_DS;
break;
case BFD_RELOC_PPC64_SECTOFF_LO_DS: ppc_reloc = R_PPC64_SECTOFF_LO_DS;
break;
case BFD_RELOC_PPC64_TOC16_DS: ppc_reloc = R_PPC64_TOC16_DS;
break;
case BFD_RELOC_PPC64_TOC16_LO_DS: ppc_reloc = R_PPC64_TOC16_LO_DS;
break;
case BFD_RELOC_PPC64_PLTGOT16_DS: ppc_reloc = R_PPC64_PLTGOT16_DS;
break;
case BFD_RELOC_PPC64_PLTGOT16_LO_DS: ppc_reloc = R_PPC64_PLTGOT16_LO_DS;
break;
case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC64_GNU_VTINHERIT;
break;
case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC64_GNU_VTENTRY;
break;
}
return ppc64_elf_howto_table[(int) ppc_reloc];
};
static void
ppc64_elf_info_to_howto (abfd, cache_ptr, dst)
bfd *abfd ATTRIBUTE_UNUSED;
arelent *cache_ptr;
Elf64_Internal_Rela *dst;
{
unsigned int type;
if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
ppc_howto_init ();
type = ELF64_R_TYPE (dst->r_info);
BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
/ sizeof (ppc64_elf_howto_table[0])));
cache_ptr->howto = ppc64_elf_howto_table[type];
}
static bfd_reloc_status_type
ppc64_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
output_bfd, error_message)
bfd *abfd ATTRIBUTE_UNUSED;
arelent *reloc_entry;
asymbol *symbol;
PTR data ATTRIBUTE_UNUSED;
asection *input_section;
bfd *output_bfd;
char **error_message ATTRIBUTE_UNUSED;
{
bfd_vma relocation;
if (output_bfd != NULL)
{
reloc_entry->address += input_section->output_offset;
return bfd_reloc_ok;
}
if (reloc_entry->address > input_section->_cooked_size)
return bfd_reloc_outofrange;
if (bfd_is_com_section (symbol->section))
relocation = 0;
else
relocation = symbol->value;
relocation += symbol->section->output_section->vma;
relocation += symbol->section->output_offset;
relocation += reloc_entry->addend;
reloc_entry->addend += (relocation & 0x8000) << 1;
return bfd_reloc_continue;
}
static boolean
ppc64_elf_set_private_flags (abfd, flags)
bfd *abfd;
flagword flags;
{
BFD_ASSERT (!elf_flags_init (abfd)
|| elf_elfheader (abfd)->e_flags == flags);
elf_elfheader (abfd)->e_flags = flags;
elf_flags_init (abfd) = true;
return true;
}
static boolean
ppc64_elf_merge_private_bfd_data (ibfd, obfd)
bfd *ibfd;
bfd *obfd;
{
flagword old_flags;
flagword new_flags;
boolean error;
if (ibfd->xvec->byteorder != obfd->xvec->byteorder
&& obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
{
const char *msg;
if (bfd_big_endian (ibfd))
msg = _("%s: compiled for a big endian system and target is little endian");
else
msg = _("%s: compiled for a little endian system and target is big endian");
(*_bfd_error_handler) (msg, bfd_archive_filename (ibfd));
bfd_set_error (bfd_error_wrong_format);
return false;
}
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour)
return true;
new_flags = elf_elfheader (ibfd)->e_flags;
old_flags = elf_elfheader (obfd)->e_flags;
if (!elf_flags_init (obfd))
{
elf_flags_init (obfd) = true;
elf_elfheader (obfd)->e_flags = new_flags;
}
else if (new_flags == old_flags)
;
else
{
error = false;
if ((new_flags & EF_PPC_RELOCATABLE) != 0
&& (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
{
error = true;
(*_bfd_error_handler)
(_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
bfd_archive_filename (ibfd));
}
else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
&& (old_flags & EF_PPC_RELOCATABLE) != 0)
{
error = true;
(*_bfd_error_handler)
(_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
bfd_archive_filename (ibfd));
}
if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
&& (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
&& (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
if (new_flags != old_flags)
{
error = true;
(*_bfd_error_handler)
(_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
}
if (error)
{
bfd_set_error (bfd_error_bad_value);
return false;
}
}
return true;
}
static boolean
ppc64_elf_section_from_shdr (abfd, hdr, name)
bfd *abfd;
Elf64_Internal_Shdr *hdr;
char *name;
{
asection *newsect;
flagword flags;
if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
return false;
newsect = hdr->bfd_section;
flags = bfd_get_section_flags (abfd, newsect);
if (hdr->sh_flags & SHF_EXCLUDE)
flags |= SEC_EXCLUDE;
if (hdr->sh_type == SHT_ORDERED)
flags |= SEC_SORT_ENTRIES;
bfd_set_section_flags (abfd, newsect, flags);
return true;
}
struct ppc_dyn_relocs
{
struct ppc_dyn_relocs *next;
asection *sec;
bfd_size_type count;
bfd_size_type pc_count;
};
#define IS_ABSOLUTE_RELOC(RTYPE) \
((RTYPE) != R_PPC64_REL14 \
&& (RTYPE) != R_PPC64_REL14_BRNTAKEN \
&& (RTYPE) != R_PPC64_REL14_BRTAKEN \
&& (RTYPE) != R_PPC64_REL24 \
&& (RTYPE) != R_PPC64_REL32 \
&& (RTYPE) != R_PPC64_REL64)
struct ppc_link_hash_entry
{
struct elf_link_hash_entry elf;
struct ppc_dyn_relocs *dyn_relocs;
unsigned int is_func:1;
unsigned int is_func_descriptor:1;
};
struct ppc_link_hash_table
{
struct elf_link_hash_table elf;
asection *sgot;
asection *srelgot;
asection *splt;
asection *srelplt;
asection *sdynbss;
asection *srelbss;
asection *sstub;
asection *sglink;
asection *sfpr;
int plt_overflow;
struct sym_sec_cache sym_sec;
};
#define ppc_hash_table(p) \
((struct ppc_link_hash_table *) ((p)->hash))
static struct bfd_hash_entry *
link_hash_newfunc (entry, table, string)
struct bfd_hash_entry *entry;
struct bfd_hash_table *table;
const char *string;
{
if (entry == NULL)
{
entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
if (entry == NULL)
return entry;
}
entry = _bfd_elf_link_hash_newfunc (entry, table, string);
if (entry != NULL)
{
struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
eh->dyn_relocs = NULL;
eh->is_func = 0;
eh->is_func_descriptor = 0;
}
return entry;
}
static struct bfd_link_hash_table *
ppc64_elf_link_hash_table_create (abfd)
bfd *abfd;
{
struct ppc_link_hash_table *htab;
bfd_size_type amt = sizeof (struct ppc_link_hash_table);
htab = (struct ppc_link_hash_table *) bfd_malloc (amt);
if (htab == NULL)
return NULL;
if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc))
{
free (htab);
return NULL;
}
htab->sgot = NULL;
htab->srelgot = NULL;
htab->splt = NULL;
htab->srelplt = NULL;
htab->sdynbss = NULL;
htab->srelbss = NULL;
htab->sstub = NULL;
htab->sglink = NULL;
htab->sfpr = NULL;
htab->plt_overflow = 0;
htab->sym_sec.abfd = NULL;
return &htab->elf.root;
}
static boolean
create_linkage_sections (dynobj, info)
bfd *dynobj;
struct bfd_link_info *info;
{
struct ppc_link_hash_table *htab;
flagword flags;
htab = ppc_hash_table (info);
flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
| SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
htab->sfpr = bfd_make_section (dynobj, ".sfpr");
if (htab->sfpr == NULL
|| ! bfd_set_section_flags (dynobj, htab->sfpr, flags)
|| ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
return false;
htab->sstub = bfd_make_section (dynobj, ".stub");
if (htab->sstub == NULL
|| ! bfd_set_section_flags (dynobj, htab->sstub, flags)
|| ! bfd_set_section_alignment (dynobj, htab->sstub, 2))
return false;
htab->sglink = bfd_make_section (dynobj, ".glink");
if (htab->sglink == NULL
|| ! bfd_set_section_flags (dynobj, htab->sglink, flags)
|| ! bfd_set_section_alignment (dynobj, htab->sglink, 2))
return false;
return true;
}
static boolean
create_got_section (dynobj, info)
bfd *dynobj;
struct bfd_link_info *info;
{
struct ppc_link_hash_table *htab;
if (! _bfd_elf_create_got_section (dynobj, info))
return false;
htab = ppc_hash_table (info);
htab->sgot = bfd_get_section_by_name (dynobj, ".got");
if (!htab->sgot)
abort ();
htab->srelgot = bfd_make_section (dynobj, ".rela.got");
if (!htab->srelgot
|| ! bfd_set_section_flags (dynobj, htab->srelgot,
(SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
| SEC_IN_MEMORY | SEC_LINKER_CREATED
| SEC_READONLY))
|| ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
return false;
return true;
}
static boolean
ppc64_elf_create_dynamic_sections (dynobj, info)
bfd *dynobj;
struct bfd_link_info *info;
{
struct ppc_link_hash_table *htab;
htab = ppc_hash_table (info);
if (!htab->sgot && !create_got_section (dynobj, info))
return false;
if (!_bfd_elf_create_dynamic_sections (dynobj, info))
return false;
htab->splt = bfd_get_section_by_name (dynobj, ".plt");
htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
if (!info->shared)
htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
if (!htab->splt || !htab->srelplt || !htab->sdynbss
|| (!info->shared && !htab->srelbss))
abort ();
return true;
}
static void
ppc64_elf_copy_indirect_symbol (dir, ind)
struct elf_link_hash_entry *dir, *ind;
{
struct ppc_link_hash_entry *edir, *eind;
edir = (struct ppc_link_hash_entry *) dir;
eind = (struct ppc_link_hash_entry *) ind;
if (eind->dyn_relocs != NULL)
{
if (edir->dyn_relocs != NULL)
{
struct ppc_dyn_relocs **pp;
struct ppc_dyn_relocs *p;
if (ind->root.type == bfd_link_hash_indirect)
abort ();
for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
{
struct ppc_dyn_relocs *q;
for (q = edir->dyn_relocs; q != NULL; q = q->next)
if (q->sec == p->sec)
{
q->pc_count += p->pc_count;
q->count += p->count;
*pp = p->next;
break;
}
if (q == NULL)
pp = &p->next;
}
*pp = edir->dyn_relocs;
}
edir->dyn_relocs = eind->dyn_relocs;
eind->dyn_relocs = NULL;
}
edir->is_func |= eind->is_func;
edir->is_func_descriptor |= eind->is_func_descriptor;
_bfd_elf_link_hash_copy_indirect (dir, ind);
}
static boolean
ppc64_elf_check_relocs (abfd, info, sec, relocs)
bfd *abfd;
struct bfd_link_info *info;
asection *sec;
const Elf_Internal_Rela *relocs;
{
struct ppc_link_hash_table *htab;
Elf_Internal_Shdr *symtab_hdr;
struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
const Elf_Internal_Rela *rel;
const Elf_Internal_Rela *rel_end;
asection *sreloc;
boolean is_opd;
if (info->relocateable)
return true;
htab = ppc_hash_table (info);
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
sym_hashes = elf_sym_hashes (abfd);
sym_hashes_end = (sym_hashes
+ symtab_hdr->sh_size / sizeof (Elf64_External_Sym));
if (!elf_bad_symtab (abfd))
sym_hashes_end -= symtab_hdr->sh_info;
sreloc = NULL;
is_opd = strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0;
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
if (htab->sfpr == NULL
&& !create_linkage_sections (htab->elf.dynobj, info))
return false;
rel_end = relocs + sec->reloc_count;
for (rel = relocs; rel < rel_end; rel++)
{
unsigned long r_symndx;
struct elf_link_hash_entry *h;
enum elf_ppc_reloc_type r_type;
r_symndx = ELF64_R_SYM (rel->r_info);
if (r_symndx < symtab_hdr->sh_info)
h = NULL;
else
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
switch (r_type)
{
case R_PPC64_GOT16:
case R_PPC64_GOT16_DS:
case R_PPC64_GOT16_HA:
case R_PPC64_GOT16_HI:
case R_PPC64_GOT16_LO:
case R_PPC64_GOT16_LO_DS:
if (htab->sgot == NULL
&& !create_got_section (htab->elf.dynobj, info))
return false;
if (h != NULL)
{
h->got.refcount += 1;
}
else
{
bfd_signed_vma *local_got_refcounts;
local_got_refcounts = elf_local_got_refcounts (abfd);
if (local_got_refcounts == NULL)
{
bfd_size_type size;
size = symtab_hdr->sh_info;
size *= sizeof (bfd_signed_vma);
local_got_refcounts = ((bfd_signed_vma *)
bfd_zalloc (abfd, size));
if (local_got_refcounts == NULL)
return false;
elf_local_got_refcounts (abfd) = local_got_refcounts;
}
local_got_refcounts[r_symndx] += 1;
}
break;
case R_PPC64_PLT16_HA:
case R_PPC64_PLT16_HI:
case R_PPC64_PLT16_LO:
case R_PPC64_PLT32:
case R_PPC64_PLT64:
if (h == NULL)
{
bfd_set_error (bfd_error_bad_value);
return false;
}
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
h->plt.refcount += 1;
((struct ppc_link_hash_entry *) h)->is_func = 1;
break;
case R_PPC64_SECTOFF:
case R_PPC64_SECTOFF_LO:
case R_PPC64_SECTOFF_HI:
case R_PPC64_SECTOFF_HA:
case R_PPC64_SECTOFF_DS:
case R_PPC64_SECTOFF_LO_DS:
case R_PPC64_TOC16:
case R_PPC64_TOC16_LO:
case R_PPC64_TOC16_HI:
case R_PPC64_TOC16_HA:
case R_PPC64_TOC16_DS:
case R_PPC64_TOC16_LO_DS:
break;
case R_PPC64_GNU_VTINHERIT:
if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
return false;
break;
case R_PPC64_GNU_VTENTRY:
if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
return false;
break;
case R_PPC64_REL24:
if (h != NULL
&& h->root.root.string[0] == '.'
&& h->root.root.string[1] != 0)
{
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
h->plt.refcount += 1;
((struct ppc_link_hash_entry *) h)->is_func = 1;
}
break;
case R_PPC64_ADDR64:
if (is_opd
&& h != NULL
&& h->root.root.string[0] == '.'
&& h->root.root.string[1] != 0)
{
struct elf_link_hash_entry *fdh;
fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
false, false, false);
if (fdh != NULL)
{
fdh->root.root.string = h->root.root.string + 1;
((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
((struct ppc_link_hash_entry *) h)->is_func = 1;
}
}
case R_PPC64_REL64:
case R_PPC64_REL32:
case R_PPC64_REL14:
case R_PPC64_REL14_BRTAKEN:
case R_PPC64_REL14_BRNTAKEN:
case R_PPC64_ADDR14:
case R_PPC64_ADDR14_BRNTAKEN:
case R_PPC64_ADDR14_BRTAKEN:
case R_PPC64_ADDR16:
case R_PPC64_ADDR16_DS:
case R_PPC64_ADDR16_HA:
case R_PPC64_ADDR16_HI:
case R_PPC64_ADDR16_HIGHER:
case R_PPC64_ADDR16_HIGHERA:
case R_PPC64_ADDR16_HIGHEST:
case R_PPC64_ADDR16_HIGHESTA:
case R_PPC64_ADDR16_LO:
case R_PPC64_ADDR16_LO_DS:
case R_PPC64_ADDR24:
case R_PPC64_ADDR30:
case R_PPC64_ADDR32:
case R_PPC64_UADDR16:
case R_PPC64_UADDR32:
case R_PPC64_UADDR64:
case R_PPC64_TOC:
if (NO_OPD_RELOCS && is_opd)
break;
if ((info->shared
&& (sec->flags & SEC_ALLOC) != 0
&& (IS_ABSOLUTE_RELOC (r_type)
|| (h != NULL
&& (! info->symbolic
|| h->root.type == bfd_link_hash_defweak
|| (h->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR) == 0))))
|| (!info->shared
&& (sec->flags & SEC_ALLOC) != 0
&& h != NULL
&& (h->root.type == bfd_link_hash_defweak
|| (h->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR) == 0)))
{
struct ppc_dyn_relocs *p;
struct ppc_dyn_relocs **head;
if (sreloc == NULL)
{
const char *name;
bfd *dynobj;
name = (bfd_elf_string_from_elf_section
(abfd,
elf_elfheader (abfd)->e_shstrndx,
elf_section_data (sec)->rel_hdr.sh_name));
if (name == NULL)
return false;
if (strncmp (name, ".rela", 5) != 0
|| strcmp (bfd_get_section_name (abfd, sec),
name + 5) != 0)
{
(*_bfd_error_handler)
(_("%s: bad relocation section name `%s\'"),
bfd_archive_filename (abfd), name);
bfd_set_error (bfd_error_bad_value);
}
dynobj = htab->elf.dynobj;
sreloc = bfd_get_section_by_name (dynobj, name);
if (sreloc == NULL)
{
flagword flags;
sreloc = bfd_make_section (dynobj, name);
flags = (SEC_HAS_CONTENTS | SEC_READONLY
| SEC_IN_MEMORY | SEC_LINKER_CREATED);
if ((sec->flags & SEC_ALLOC) != 0)
flags |= SEC_ALLOC | SEC_LOAD;
if (sreloc == NULL
|| ! bfd_set_section_flags (dynobj, sreloc, flags)
|| ! bfd_set_section_alignment (dynobj, sreloc, 3))
return false;
}
elf_section_data (sec)->sreloc = sreloc;
}
if (h != NULL)
{
head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
}
else
{
asection *s;
s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
sec, r_symndx);
if (s == NULL)
return false;
head = ((struct ppc_dyn_relocs **)
&elf_section_data (s)->local_dynrel);
}
p = *head;
if (p == NULL || p->sec != sec)
{
p = ((struct ppc_dyn_relocs *)
bfd_alloc (htab->elf.dynobj,
(bfd_size_type) sizeof *p));
if (p == NULL)
return false;
p->next = *head;
*head = p;
p->sec = sec;
p->count = 0;
p->pc_count = 0;
}
p->count += 1;
if (!IS_ABSOLUTE_RELOC (r_type))
p->pc_count += 1;
}
break;
default:
break;
}
}
return true;
}
static asection *
ppc64_elf_gc_mark_hook (abfd, info, rel, h, sym)
bfd *abfd;
struct bfd_link_info *info ATTRIBUTE_UNUSED;
Elf_Internal_Rela *rel;
struct elf_link_hash_entry *h;
Elf_Internal_Sym *sym;
{
if (h != NULL)
{
enum elf_ppc_reloc_type r_type;
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
switch (r_type)
{
case R_PPC64_GNU_VTINHERIT:
case R_PPC64_GNU_VTENTRY:
break;
default:
switch (h->root.type)
{
case bfd_link_hash_defined:
case bfd_link_hash_defweak:
return h->root.u.def.section;
case bfd_link_hash_common:
return h->root.u.c.p->section;
default:
break;
}
}
}
else
{
return bfd_section_from_elf_index (abfd, sym->st_shndx);
}
return NULL;
}
static boolean
ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs)
bfd *abfd;
struct bfd_link_info *info ATTRIBUTE_UNUSED;
asection *sec;
const Elf_Internal_Rela *relocs;
{
Elf_Internal_Shdr *symtab_hdr;
struct elf_link_hash_entry **sym_hashes;
bfd_signed_vma *local_got_refcounts;
const Elf_Internal_Rela *rel, *relend;
elf_section_data (sec)->local_dynrel = NULL;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
sym_hashes = elf_sym_hashes (abfd);
local_got_refcounts = elf_local_got_refcounts (abfd);
relend = relocs + sec->reloc_count;
for (rel = relocs; rel < relend; rel++)
{
unsigned long r_symndx;
enum elf_ppc_reloc_type r_type;
struct elf_link_hash_entry *h;
r_symndx = ELF64_R_SYM (rel->r_info);
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
switch (r_type)
{
case R_PPC64_GOT16:
case R_PPC64_GOT16_DS:
case R_PPC64_GOT16_HA:
case R_PPC64_GOT16_HI:
case R_PPC64_GOT16_LO:
case R_PPC64_GOT16_LO_DS:
if (r_symndx >= symtab_hdr->sh_info)
{
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
if (h->got.refcount > 0)
h->got.refcount--;
}
else
{
if (local_got_refcounts[r_symndx] > 0)
local_got_refcounts[r_symndx]--;
}
break;
case R_PPC64_PLT16_HA:
case R_PPC64_PLT16_HI:
case R_PPC64_PLT16_LO:
case R_PPC64_PLT32:
case R_PPC64_PLT64:
if (r_symndx >= symtab_hdr->sh_info)
{
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
if (h->plt.refcount > 0)
h->plt.refcount--;
}
break;
case R_PPC64_REL24:
if (r_symndx >= symtab_hdr->sh_info)
{
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
if (h->plt.refcount > 0)
h->plt.refcount--;
}
break;
case R_PPC64_REL14:
case R_PPC64_REL14_BRNTAKEN:
case R_PPC64_REL14_BRTAKEN:
case R_PPC64_REL32:
case R_PPC64_REL64:
if (r_symndx >= symtab_hdr->sh_info)
{
struct ppc_link_hash_entry *eh;
struct ppc_dyn_relocs **pp;
struct ppc_dyn_relocs *p;
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
eh = (struct ppc_link_hash_entry *) h;
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
if (p->sec == sec)
{
p->pc_count -= 1;
p->count -= 1;
if (p->count == 0)
*pp = p->next;
break;
}
}
break;
case R_PPC64_ADDR14:
case R_PPC64_ADDR14_BRNTAKEN:
case R_PPC64_ADDR14_BRTAKEN:
case R_PPC64_ADDR16:
case R_PPC64_ADDR16_DS:
case R_PPC64_ADDR16_HA:
case R_PPC64_ADDR16_HI:
case R_PPC64_ADDR16_HIGHER:
case R_PPC64_ADDR16_HIGHERA:
case R_PPC64_ADDR16_HIGHEST:
case R_PPC64_ADDR16_HIGHESTA:
case R_PPC64_ADDR16_LO:
case R_PPC64_ADDR16_LO_DS:
case R_PPC64_ADDR24:
case R_PPC64_ADDR30:
case R_PPC64_ADDR32:
case R_PPC64_ADDR64:
case R_PPC64_UADDR16:
case R_PPC64_UADDR32:
case R_PPC64_UADDR64:
case R_PPC64_TOC:
if (r_symndx >= symtab_hdr->sh_info)
{
struct ppc_link_hash_entry *eh;
struct ppc_dyn_relocs **pp;
struct ppc_dyn_relocs *p;
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
eh = (struct ppc_link_hash_entry *) h;
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
if (p->sec == sec)
{
p->count -= 1;
if (p->count == 0)
*pp = p->next;
break;
}
}
break;
default:
break;
}
}
return true;
}
static boolean
func_desc_adjust (h, inf)
struct elf_link_hash_entry *h;
PTR inf;
{
struct bfd_link_info *info;
struct ppc_link_hash_table *htab;
if (h->root.type == bfd_link_hash_indirect)
return true;
if (h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
info = (struct bfd_link_info *) inf;
htab = ppc_hash_table (info);
if (!((struct ppc_link_hash_entry *) h)->is_func)
return true;
if (h->plt.refcount > 0
&& h->root.root.string[0] == '.'
&& h->root.root.string[1] != '\0')
{
struct elf_link_hash_entry *fdh;
boolean force_local;
fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
false, false, true);
if (fdh == NULL
&& info->shared
&& (h->root.type == bfd_link_hash_undefined
|| h->root.type == bfd_link_hash_undefweak))
{
bfd *abfd;
asymbol *newsym;
abfd = h->root.u.undef.abfd;
newsym = bfd_make_empty_symbol (abfd);
newsym->name = h->root.root.string + 1;
newsym->section = bfd_und_section_ptr;
newsym->value = 0;
newsym->flags = BSF_OBJECT;
if (h->root.type == bfd_link_hash_undefweak)
newsym->flags |= BSF_WEAK;
if ( !(_bfd_generic_link_add_one_symbol
(info, abfd, newsym->name, newsym->flags,
newsym->section, newsym->value, NULL, false, false,
(struct bfd_link_hash_entry **) &fdh)))
{
return false;
}
fdh->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
}
if (fdh != NULL
&& (fdh->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
&& (info->shared
|| (fdh->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
|| (fdh->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0))
{
if (fdh->dynindx == -1)
if (! bfd_elf64_link_record_dynamic_symbol (info, fdh))
return false;
fdh->elf_link_hash_flags |= (h->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
| ELF_LINK_HASH_REF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR_NONWEAK
| ELF_LINK_NON_GOT_REF));
if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
{
fdh->plt.refcount = h->plt.refcount;
fdh->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
}
((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
fdh->root.root.string = h->root.root.string + 1;
}
force_local = ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
&& info->shared);
_bfd_elf_link_hash_hide_symbol (info, h, force_local);
}
return true;
}
#define MIN_SAVE_FPR 14
#define MAX_SAVE_FPR 31
static boolean
ppc64_elf_func_desc_adjust (obfd, info)
bfd *obfd ATTRIBUTE_UNUSED;
struct bfd_link_info *info;
{
struct ppc_link_hash_table *htab;
unsigned int lowest_savef = MAX_SAVE_FPR + 2;
unsigned int lowest_restf = MAX_SAVE_FPR + 2;
unsigned int i;
struct elf_link_hash_entry *h;
char sym[10];
htab = ppc_hash_table (info);
if (htab->sfpr == NULL)
return true;
memcpy (sym, "._savef14", 10);
for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
{
sym[7] = i / 10 + '0';
sym[8] = i % 10 + '0';
h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
if (h != NULL
&& h->root.type == bfd_link_hash_undefined)
{
if (lowest_savef > i)
lowest_savef = i;
h->root.type = bfd_link_hash_defined;
h->root.u.def.section = htab->sfpr;
h->root.u.def.value = (i - lowest_savef) * 4;
h->type = STT_FUNC;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
_bfd_elf_link_hash_hide_symbol (info, h, info->shared);
}
}
memcpy (sym, "._restf14", 10);
for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
{
sym[7] = i / 10 + '0';
sym[8] = i % 10 + '0';
h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
if (h != NULL
&& h->root.type == bfd_link_hash_undefined)
{
if (lowest_restf > i)
lowest_restf = i;
h->root.type = bfd_link_hash_defined;
h->root.u.def.section = htab->sfpr;
h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
+ (i - lowest_restf) * 4);
h->type = STT_FUNC;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
_bfd_elf_link_hash_hide_symbol (info, h, info->shared);
}
}
htab->sfpr->_raw_size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
+ (MAX_SAVE_FPR + 2 - lowest_restf) * 4);
if (htab->sfpr->_raw_size == 0)
{
_bfd_strip_section_from_output (info, htab->sfpr);
}
else
{
bfd_byte *p = (bfd_byte *) bfd_alloc (htab->elf.dynobj,
htab->sfpr->_raw_size);
if (p == NULL)
return false;
htab->sfpr->contents = p;
for (i = lowest_savef; i <= MAX_SAVE_FPR; i++)
{
unsigned int fpr = i << 21;
unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p);
p += 4;
}
bfd_put_32 (htab->elf.dynobj, BLR, p);
p += 4;
for (i = lowest_restf; i <= MAX_SAVE_FPR; i++)
{
unsigned int fpr = i << 21;
unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p);
p += 4;
}
bfd_put_32 (htab->elf.dynobj, BLR, p);
p += 4;
}
elf_link_hash_traverse (&htab->elf, func_desc_adjust, (PTR) info);
return true;
}
static boolean
ppc64_elf_adjust_dynamic_symbol (info, h)
struct bfd_link_info *info;
struct elf_link_hash_entry *h;
{
struct ppc_link_hash_table *htab;
struct ppc_link_hash_entry * eh;
struct ppc_dyn_relocs *p;
asection *s;
unsigned int power_of_two;
htab = ppc_hash_table (info);
if (h->type == STT_FUNC
|| (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
{
if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor
|| h->plt.refcount <= 0
|| (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
|| (! info->shared
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
&& (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0))
{
h->plt.offset = (bfd_vma) -1;
h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
}
return true;
}
else
h->plt.offset = (bfd_vma) -1;
if (h->weakdef != NULL)
{
BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
|| h->weakdef->root.type == bfd_link_hash_defweak);
h->root.u.def.section = h->weakdef->root.u.def.section;
h->root.u.def.value = h->weakdef->root.u.def.value;
return true;
}
if (info->shared)
return true;
if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
return true;
eh = (struct ppc_link_hash_entry *) h;
for (p = eh->dyn_relocs; p != NULL; p = p->next)
{
s = p->sec->output_section;
if (s != NULL && (s->flags & SEC_READONLY) != 0)
break;
}
if (p == NULL)
{
h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
return true;
}
if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
{
htab->srelbss->_raw_size += sizeof (Elf64_External_Rela);
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
}
power_of_two = bfd_log2 (h->size);
if (power_of_two > 4)
power_of_two = 4;
s = htab->sdynbss;
s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
{
if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
return false;
}
h->root.u.def.section = s;
h->root.u.def.value = s->_raw_size;
s->_raw_size += h->size;
return true;
}
static void
ppc64_elf_hide_symbol (info, h, force_local)
struct bfd_link_info *info;
struct elf_link_hash_entry *h;
boolean force_local;
{
_bfd_elf_link_hash_hide_symbol (info, h, force_local);
if (((struct ppc_link_hash_entry *) h)->is_func_descriptor)
{
const char *name;
struct elf_link_hash_entry *fh;
struct ppc_link_hash_table *htab;
name = h->root.root.string - 1;
htab = ppc_hash_table (info);
fh = elf_link_hash_lookup (&htab->elf, name, false, false, false);
if (fh != NULL)
_bfd_elf_link_hash_hide_symbol (info, fh, force_local);
}
}
#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
((DYN) \
&& ((INFO)->shared \
|| ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
&& ((H)->dynindx != -1 \
|| ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
static boolean
allocate_dynrelocs (h, inf)
struct elf_link_hash_entry *h;
PTR inf;
{
struct bfd_link_info *info;
struct ppc_link_hash_table *htab;
asection *s;
struct ppc_link_hash_entry *eh;
struct ppc_dyn_relocs *p;
if (h->root.type == bfd_link_hash_indirect)
return true;
if (h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
info = (struct bfd_link_info *) inf;
htab = ppc_hash_table (info);
if (htab->elf.dynamic_sections_created
&& h->plt.refcount > 0
&& h->dynindx != -1)
{
BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor);
if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
{
s = htab->splt;
if (s->_raw_size == 0)
s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
h->plt.offset = s->_raw_size;
s->_raw_size += PLT_ENTRY_SIZE;
s = htab->sstub;
s->_raw_size += PLT_CALL_STUB_SIZE;
s = htab->sglink;
if (s->_raw_size == 0)
s->_raw_size += GLINK_CALL_STUB_SIZE;
if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
s->_raw_size += 4;
s->_raw_size += 2*4;
s = htab->srelplt;
s->_raw_size += sizeof (Elf64_External_Rela);
}
else
{
h->plt.offset = (bfd_vma) -1;
h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
}
}
else
{
h->plt.offset = (bfd_vma) -1;
h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
}
if (h->got.refcount > 0)
{
boolean dyn;
if (h->dynindx == -1
&& (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
{
if (! bfd_elf64_link_record_dynamic_symbol (info, h))
return false;
}
s = htab->sgot;
h->got.offset = s->_raw_size;
s->_raw_size += 8;
dyn = htab->elf.dynamic_sections_created;
if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
}
else
h->got.offset = (bfd_vma) -1;
eh = (struct ppc_link_hash_entry *) h;
if (eh->dyn_relocs == NULL)
return true;
if (info->shared)
{
if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
&& ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
|| info->symbolic))
{
struct ppc_dyn_relocs **pp;
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
{
p->count -= p->pc_count;
p->pc_count = 0;
if (p->count == 0)
*pp = p->next;
else
pp = &p->next;
}
}
}
else
{
if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
&& (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
|| (htab->elf.dynamic_sections_created
&& (h->root.type == bfd_link_hash_undefweak
|| h->root.type == bfd_link_hash_undefined))))
{
if (h->dynindx == -1
&& (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
{
if (! bfd_elf64_link_record_dynamic_symbol (info, h))
return false;
}
if (h->dynindx != -1)
goto keep;
}
eh->dyn_relocs = NULL;
keep: ;
}
for (p = eh->dyn_relocs; p != NULL; p = p->next)
{
asection *sreloc = elf_section_data (p->sec)->sreloc;
sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela);
}
return true;
}
static boolean
readonly_dynrelocs (h, inf)
struct elf_link_hash_entry *h;
PTR inf;
{
struct ppc_link_hash_entry *eh;
struct ppc_dyn_relocs *p;
if (h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
eh = (struct ppc_link_hash_entry *) h;
for (p = eh->dyn_relocs; p != NULL; p = p->next)
{
asection *s = p->sec->output_section;
if (s != NULL && (s->flags & SEC_READONLY) != 0)
{
struct bfd_link_info *info = (struct bfd_link_info *) inf;
info->flags |= DF_TEXTREL;
return false;
}
}
return true;
}
static boolean
ppc64_elf_size_dynamic_sections (output_bfd, info)
bfd *output_bfd ATTRIBUTE_UNUSED;
struct bfd_link_info *info;
{
struct ppc_link_hash_table *htab;
bfd *dynobj;
asection *s;
boolean relocs;
bfd *ibfd;
htab = ppc_hash_table (info);
dynobj = htab->elf.dynobj;
if (dynobj == NULL)
abort ();
if (htab->elf.dynamic_sections_created)
{
if (! info->shared)
{
s = bfd_get_section_by_name (dynobj, ".interp");
if (s == NULL)
abort ();
s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
}
}
for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
{
bfd_signed_vma *local_got;
bfd_signed_vma *end_local_got;
bfd_size_type locsymcount;
Elf_Internal_Shdr *symtab_hdr;
asection *srel;
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
continue;
for (s = ibfd->sections; s != NULL; s = s->next)
{
struct ppc_dyn_relocs *p;
for (p = *((struct ppc_dyn_relocs **)
&elf_section_data (s)->local_dynrel);
p != NULL;
p = p->next)
{
if (!bfd_is_abs_section (p->sec)
&& bfd_is_abs_section (p->sec->output_section))
{
}
else if (p->count != 0)
{
srel = elf_section_data (p->sec)->sreloc;
srel->_raw_size += p->count * sizeof (Elf64_External_Rela);
if ((p->sec->output_section->flags & SEC_READONLY) != 0)
info->flags |= DF_TEXTREL;
}
}
}
local_got = elf_local_got_refcounts (ibfd);
if (!local_got)
continue;
symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
locsymcount = symtab_hdr->sh_info;
end_local_got = local_got + locsymcount;
s = htab->sgot;
srel = htab->srelgot;
for (; local_got < end_local_got; ++local_got)
{
if (*local_got > 0)
{
*local_got = s->_raw_size;
s->_raw_size += 8;
if (info->shared)
srel->_raw_size += sizeof (Elf64_External_Rela);
}
else
*local_got = (bfd_vma) -1;
}
}
elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
relocs = false;
for (s = dynobj->sections; s != NULL; s = s->next)
{
bfd_vma size;
if ((s->flags & SEC_LINKER_CREATED) == 0)
continue;
if (s == htab->splt
|| s == htab->sgot
|| s == htab->sstub
|| s == htab->sglink)
{
}
else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
{
if (s->_raw_size == 0)
{
}
else
{
if (s != htab->srelplt)
relocs = true;
s->reloc_count = 0;
}
}
else
{
continue;
}
if (s->_raw_size == 0)
{
_bfd_strip_section_from_output (info, s);
continue;
}
size = s->_raw_size;
if (s == htab->sstub)
{
size += (size + 65536 + 65535) / 65536 * 4;
}
s->contents = (bfd_byte *) bfd_zalloc (dynobj, size);
if (s->contents == NULL)
return false;
}
if (htab->elf.dynamic_sections_created)
{
#define add_dynamic_entry(TAG, VAL) \
bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
if (!info->shared)
{
if (!add_dynamic_entry (DT_DEBUG, 0))
return false;
}
if (htab->splt->_raw_size != 0)
{
if (!add_dynamic_entry (DT_PLTGOT, 0)
|| !add_dynamic_entry (DT_PLTRELSZ, 0)
|| !add_dynamic_entry (DT_PLTREL, DT_RELA)
|| !add_dynamic_entry (DT_JMPREL, 0)
|| !add_dynamic_entry (DT_PPC64_GLINK, 0))
return false;
}
if (NO_OPD_RELOCS)
{
if (!add_dynamic_entry (DT_PPC64_OPD, 0)
|| !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
return false;
}
if (relocs)
{
if (!add_dynamic_entry (DT_RELA, 0)
|| !add_dynamic_entry (DT_RELASZ, 0)
|| !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
return false;
if ((info->flags & DF_TEXTREL) == 0)
elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
(PTR) info);
if ((info->flags & DF_TEXTREL) != 0)
{
if (!add_dynamic_entry (DT_TEXTREL, 0))
return false;
}
}
}
#undef add_dynamic_entry
return true;
}
boolean
ppc64_elf_set_toc (obfd, info)
bfd *obfd;
struct bfd_link_info *info;
{
if (!info->relocateable)
{
asection *s;
bfd_vma TOCstart;
s = bfd_get_section_by_name (obfd, ".got");
if (s == NULL)
s = bfd_get_section_by_name (obfd, ".toc");
if (s == NULL)
s = bfd_get_section_by_name (obfd, ".tocbss");
if (s == NULL)
s = bfd_get_section_by_name (obfd, ".plt");
if (s == NULL)
{
for (s = obfd->sections; s != NULL; s = s->next)
if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
== (SEC_ALLOC | SEC_SMALL_DATA))
break;
if (s == NULL)
for (s = obfd->sections; s != NULL; s = s->next)
if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
== (SEC_ALLOC | SEC_SMALL_DATA))
break;
if (s == NULL)
for (s = obfd->sections; s != NULL; s = s->next)
if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
break;
if (s == NULL)
for (s = obfd->sections; s != NULL; s = s->next)
if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
break;
}
TOCstart = 0;
if (s != NULL)
TOCstart = s->output_section->vma + s->output_offset;
elf_gp (obfd) = TOCstart;
}
return true;
}
boolean
ppc64_elf_size_stubs (obfd, info, changed)
bfd *obfd;
struct bfd_link_info *info;
int *changed;
{
struct ppc_link_hash_table *htab = ppc_hash_table (info);
bfd_vma plt_offset, next_64k;
long base, num, extra;
if ((htab->splt == NULL || htab->splt->_raw_size == 0)
!= (htab->sstub == NULL || htab->sstub->_raw_size == 0))
abort ();
if (htab->splt == NULL || htab->splt->_raw_size == 0)
return true;
plt_offset = (htab->splt->output_section->vma
+ htab->splt->output_offset
- elf_gp (obfd));
next_64k = (plt_offset + 65535) & -65536;
if (plt_offset + htab->splt->_raw_size <= next_64k)
return true;
base = next_64k / 65536;
num = (plt_offset + htab->splt->_raw_size - next_64k) / 65536;
extra = (base % 3 + num + 1) * 2 / 3;
if (htab->sstub->_cooked_size < htab->sstub->_raw_size + extra * 4)
{
htab->sstub->_cooked_size = htab->sstub->_raw_size + extra * 4;
*changed = true;
}
return true;
}
static bfd_byte *
build_plt_stub (obfd, p, offset, glink)
bfd *obfd;
bfd_byte *p;
int offset;
int glink;
{
#define PPC_LO(v) ((v) & 0xffff)
#define PPC_HI(v) (((v) >> 16) & 0xffff)
#define PPC_HA(v) PPC_HI ((v) + 0x8000)
if (glink)
bfd_put_32 (obfd, LD_R2_40R1, p), p += 4;
bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
if (!glink)
bfd_put_32 (obfd, STD_R2_40R1, p), p += 4;
bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
if (PPC_HA (offset + 8) != PPC_HA (offset))
bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
offset += 8;
bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4;
if (PPC_HA (offset + 8) != PPC_HA (offset))
bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
offset += 8;
bfd_put_32 (obfd, MTCTR_R11, p), p += 4;
bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
bfd_put_32 (obfd, BCTR, p), p += 4;
return p;
}
static boolean
build_one_stub (h, inf)
struct elf_link_hash_entry *h;
PTR inf;
{
struct bfd_link_info *info;
struct ppc_link_hash_table *htab;
if (h->root.type == bfd_link_hash_indirect
|| h->root.type == bfd_link_hash_warning)
return true;
info = (struct bfd_link_info *) inf;
htab = ppc_hash_table (info);
if (htab->elf.dynamic_sections_created
&& h->plt.offset != (bfd_vma) -1
&& ((struct ppc_link_hash_entry *) h)->is_func_descriptor)
{
struct elf_link_hash_entry *fh;
asection *s;
bfd_vma plt_r2;
bfd_byte *p;
unsigned int indx;
fh = elf_link_hash_lookup (&htab->elf, h->root.root.string - 1,
false, false, true);
if (fh == NULL)
abort ();
BFD_ASSERT (((struct ppc_link_hash_entry *) fh)->is_func);
plt_r2 = (htab->splt->output_section->vma
+ htab->splt->output_offset
+ h->plt.offset
- elf_gp (htab->splt->output_section->owner)
- TOC_BASE_OFF);
if (plt_r2 + 0x80000000 > 0xffffffff
|| (plt_r2 & 3) != 0)
{
(*_bfd_error_handler)
(_("linkage table error against `%s'"),
h->root.root.string);
bfd_set_error (bfd_error_bad_value);
htab->plt_overflow = true;
return false;
}
s = htab->sstub;
fh->plt.offset = s->_cooked_size;
p = s->contents + s->_cooked_size;
p = build_plt_stub (s->owner, p, (int) plt_r2, 0);
s->_cooked_size = p - s->contents;
s = htab->sglink;
p = s->contents + s->_cooked_size;
indx = s->reloc_count;
if (indx < 0x8000)
{
bfd_put_32 (s->owner, LI_R0_0 | indx, p);
p += 4;
}
else
{
bfd_put_32 (s->owner, LIS_R0_0 | PPC_HI (indx), p);
p += 4;
bfd_put_32 (s->owner, ORI_R0_R0_0 | PPC_LO (indx), p);
p += 4;
}
bfd_put_32 (s->owner, B_DOT | ((s->contents - p) & 0x3fffffc), p);
p += 4;
s->_cooked_size = p - s->contents;
s->reloc_count += 1;
}
return true;
}
boolean
ppc64_elf_build_stubs (obfd, info)
bfd *obfd;
struct bfd_link_info *info;
{
struct ppc_link_hash_table *htab = ppc_hash_table (info);
bfd_vma old_stub_size;
bfd_vma plt_r2;
bfd_byte *p;
if (htab->sstub == NULL || htab->sstub->_raw_size == 0)
return true;
old_stub_size = htab->sstub->_cooked_size;
htab->sstub->_cooked_size = 0;
plt_r2 = (htab->splt->output_section->vma
+ htab->splt->output_offset
- elf_gp (obfd)
- TOC_BASE_OFF);
p = htab->sglink->contents;
p = build_plt_stub (htab->sglink->owner, p, (int) plt_r2, 1);
while (p - htab->sglink->contents < GLINK_CALL_STUB_SIZE)
{
bfd_put_32 (htab->sglink->owner, NOP, p);
p += 4;
}
htab->sglink->_cooked_size = p - htab->sglink->contents;
htab->sglink->reloc_count = 0;
elf_link_hash_traverse (&htab->elf, build_one_stub, (PTR) info);
htab->sglink->reloc_count = 0;
if (htab->plt_overflow)
return false;
if (old_stub_size != htab->sstub->_cooked_size
|| htab->sglink->_raw_size != htab->sglink->_cooked_size)
{
(*_bfd_error_handler)
(_("stub section size doesn't match calculated size"));
bfd_set_error (bfd_error_bad_value);
return false;
}
return true;
}
static boolean
ppc64_elf_fake_sections (abfd, shdr, asect)
bfd *abfd ATTRIBUTE_UNUSED;
Elf64_Internal_Shdr *shdr;
asection *asect;
{
if ((asect->flags & SEC_EXCLUDE) != 0)
shdr->sh_flags |= SHF_EXCLUDE;
if ((asect->flags & SEC_SORT_ENTRIES) != 0)
shdr->sh_type = SHT_ORDERED;
return true;
}
static boolean
ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
contents, relocs, local_syms, local_sections)
bfd *output_bfd;
struct bfd_link_info *info;
bfd *input_bfd;
asection *input_section;
bfd_byte *contents;
Elf_Internal_Rela *relocs;
Elf_Internal_Sym *local_syms;
asection **local_sections;
{
struct ppc_link_hash_table *htab;
Elf_Internal_Shdr *symtab_hdr;
struct elf_link_hash_entry **sym_hashes;
Elf_Internal_Rela *rel;
Elf_Internal_Rela *relend;
bfd_vma *local_got_offsets;
bfd_vma TOCstart;
boolean ret = true;
boolean is_opd;
boolean is_power4 = false;
if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
ppc_howto_init ();
htab = ppc_hash_table (info);
local_got_offsets = elf_local_got_offsets (input_bfd);
TOCstart = elf_gp (output_bfd);
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
sym_hashes = elf_sym_hashes (input_bfd);
is_opd = strcmp (bfd_get_section_name (abfd, input_section), ".opd") == 0;
rel = relocs;
relend = relocs + input_section->reloc_count;
for (; rel < relend; rel++)
{
enum elf_ppc_reloc_type r_type;
bfd_vma offset;
bfd_vma addend;
bfd_reloc_status_type r;
Elf_Internal_Sym *sym;
asection *sec;
struct elf_link_hash_entry *h;
const char *sym_name;
unsigned long r_symndx;
bfd_vma relocation;
boolean unresolved_reloc;
boolean has_nop;
long insn;
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
r_symndx = ELF64_R_SYM (rel->r_info);
if (info->relocateable)
{
if (r_symndx < symtab_hdr->sh_info)
{
sym = local_syms + r_symndx;
if ((unsigned) ELF_ST_TYPE (sym->st_info) == STT_SECTION)
{
sec = local_sections[r_symndx];
rel->r_addend += sec->output_offset + sym->st_value;
}
}
continue;
}
offset = rel->r_offset;
addend = rel->r_addend;
r = bfd_reloc_other;
sym = (Elf_Internal_Sym *) 0;
sec = (asection *) 0;
h = (struct elf_link_hash_entry *) 0;
sym_name = (const char *) 0;
unresolved_reloc = false;
if (r_type == R_PPC64_TOC)
{
relocation = TOCstart + TOC_BASE_OFF;
}
else if (r_symndx < symtab_hdr->sh_info)
{
sym = local_syms + r_symndx;
sec = local_sections[r_symndx];
sym_name = "<local symbol>";
relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
addend = rel->r_addend;
}
else
{
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
while (h->root.type == bfd_link_hash_indirect
|| h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
sym_name = h->root.root.string;
relocation = 0;
if (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak)
{
sec = h->root.u.def.section;
if (sec->output_section == NULL)
unresolved_reloc = true;
else
relocation = (h->root.u.def.value
+ sec->output_section->vma
+ sec->output_offset);
}
else if (h->root.type == bfd_link_hash_undefweak)
;
else if (info->shared
&& (!info->symbolic || info->allow_shlib_undefined)
&& !info->no_undefined
&& ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
;
else
{
if (! ((*info->callbacks->undefined_symbol)
(info, h->root.root.string, input_bfd, input_section,
offset, (!info->shared
|| info->no_undefined
|| ELF_ST_VISIBILITY (h->other)))))
return false;
}
}
insn = 0;
switch (r_type)
{
default:
break;
case R_PPC64_ADDR14_BRTAKEN:
case R_PPC64_REL14_BRTAKEN:
insn = 0x01 << 21;
case R_PPC64_ADDR14_BRNTAKEN:
case R_PPC64_REL14_BRNTAKEN:
insn |= bfd_get_32 (output_bfd, contents + offset) & ~(0x01 << 21);
if (is_power4)
{
if ((insn & (0x14 << 21)) == (0x04 << 21))
insn |= 0x02 << 21;
else if ((insn & (0x14 << 21)) == (0x10 << 21))
insn |= 0x08 << 21;
else
break;
}
else
{
if ((bfd_signed_vma) (relocation - offset) < 0)
insn ^= 0x01 << 21;
}
bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset);
break;
case R_PPC64_REL24:
case R_PPC64_ADDR24:
has_nop = 0;
if (h != NULL
&& h->plt.offset != (bfd_vma) -1
&& htab->sstub != NULL)
{
relocation = (htab->sstub->output_section->vma
+ htab->sstub->output_offset
+ h->plt.offset);
unresolved_reloc = false;
if (offset + 8 <= input_section->_cooked_size)
{
bfd_byte *pnext;
pnext = contents + offset + 4;
insn = bfd_get_32 (input_bfd, pnext);
if (insn == 0x60000000
|| insn == 0x4def7b82
|| insn == 0x4ffffb82)
{
bfd_put_32 (input_bfd,
(bfd_vma) 0xe8410028,
pnext);
has_nop = 1;
}
}
}
if (h != NULL
&& h->root.type == bfd_link_hash_undefweak
&& r_type == R_PPC64_REL24
&& addend == 0
&& relocation == 0)
{
relocation = 4;
if (has_nop)
relocation = 8;
}
break;
}
switch (r_type)
{
default:
(*_bfd_error_handler)
(_("%s: unknown relocation type %d for symbol %s"),
bfd_archive_filename (input_bfd), (int) r_type, sym_name);
bfd_set_error (bfd_error_bad_value);
ret = false;
continue;
case R_PPC64_NONE:
case R_PPC_GNU_VTINHERIT:
case R_PPC_GNU_VTENTRY:
continue;
case R_PPC64_GOT16:
case R_PPC64_GOT16_LO:
case R_PPC64_GOT16_HI:
case R_PPC64_GOT16_HA:
case R_PPC64_GOT16_DS:
case R_PPC64_GOT16_LO_DS:
{
bfd_vma off;
if (htab->sgot == NULL)
abort ();
if (h != NULL)
{
boolean dyn;
off = h->got.offset;
dyn = htab->elf.dynamic_sections_created;
if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
|| (info->shared
&& (info->symbolic
|| h->dynindx == -1
|| (h->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL))
&& (h->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR)))
{
if ((off & 1) != 0)
off &= ~1;
else
{
bfd_put_64 (output_bfd, relocation,
htab->sgot->contents + off);
h->got.offset |= 1;
}
}
else
unresolved_reloc = false;
}
else
{
if (local_got_offsets == NULL)
abort ();
off = local_got_offsets[r_symndx];
if ((off & 1) != 0)
off &= ~1;
else
{
bfd_put_64 (output_bfd, relocation,
htab->sgot->contents + off);
if (info->shared)
{
Elf_Internal_Rela outrel;
Elf64_External_Rela *loc;
outrel.r_offset = (htab->sgot->output_section->vma
+ htab->sgot->output_offset
+ off);
outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
outrel.r_addend = relocation;
loc = (Elf64_External_Rela *) htab->srelgot->contents;
loc += htab->srelgot->reloc_count++;
bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
}
local_got_offsets[r_symndx] |= 1;
}
}
if (off >= (bfd_vma) -2)
abort ();
relocation = htab->sgot->output_offset + off;
addend -= TOC_BASE_OFF;
}
break;
case R_PPC64_PLT16_HA:
case R_PPC64_PLT16_HI:
case R_PPC64_PLT16_LO:
case R_PPC64_PLT32:
case R_PPC64_PLT64:
if (h == NULL)
break;
if (h->plt.offset == (bfd_vma) -1
|| htab->splt == NULL)
{
break;
}
relocation = (htab->splt->output_section->vma
+ htab->splt->output_offset
+ h->plt.offset);
unresolved_reloc = false;
break;
case R_PPC64_TOC16:
case R_PPC64_TOC16_LO:
case R_PPC64_TOC16_HI:
case R_PPC64_TOC16_DS:
case R_PPC64_TOC16_LO_DS:
case R_PPC64_TOC16_HA:
addend -= TOCstart + TOC_BASE_OFF;
break;
case R_PPC64_SECTOFF:
case R_PPC64_SECTOFF_LO:
case R_PPC64_SECTOFF_HI:
case R_PPC64_SECTOFF_DS:
case R_PPC64_SECTOFF_LO_DS:
case R_PPC64_SECTOFF_HA:
if (sec != (asection *) 0)
addend -= sec->output_section->vma;
break;
case R_PPC64_REL24:
break;
case R_PPC64_REL14:
case R_PPC64_REL14_BRNTAKEN:
case R_PPC64_REL14_BRTAKEN:
case R_PPC64_REL32:
case R_PPC64_REL64:
case R_PPC64_ADDR14:
case R_PPC64_ADDR14_BRNTAKEN:
case R_PPC64_ADDR14_BRTAKEN:
case R_PPC64_ADDR16:
case R_PPC64_ADDR16_DS:
case R_PPC64_ADDR16_HA:
case R_PPC64_ADDR16_HI:
case R_PPC64_ADDR16_HIGHER:
case R_PPC64_ADDR16_HIGHERA:
case R_PPC64_ADDR16_HIGHEST:
case R_PPC64_ADDR16_HIGHESTA:
case R_PPC64_ADDR16_LO:
case R_PPC64_ADDR16_LO_DS:
case R_PPC64_ADDR24:
case R_PPC64_ADDR30:
case R_PPC64_ADDR32:
case R_PPC64_ADDR64:
case R_PPC64_UADDR16:
case R_PPC64_UADDR32:
case R_PPC64_UADDR64:
if (r_symndx == 0)
break;
case R_PPC64_TOC:
if ((input_section->flags & SEC_ALLOC) == 0)
break;
if (NO_OPD_RELOCS && is_opd)
break;
if ((info->shared
&& (IS_ABSOLUTE_RELOC (r_type)
|| (h != NULL
&& h->dynindx != -1
&& (! info->symbolic
|| (h->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR) == 0))))
|| (!info->shared
&& h != NULL
&& h->dynindx != -1
&& (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
&& (((h->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC) != 0
&& (h->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR) == 0)
|| h->root.type == bfd_link_hash_undefweak
|| h->root.type == bfd_link_hash_undefined)))
{
Elf_Internal_Rela outrel;
boolean skip, relocate;
asection *sreloc;
Elf64_External_Rela *loc;
skip = false;
relocate = false;
outrel.r_offset =
_bfd_elf_section_offset (output_bfd, info, input_section,
rel->r_offset);
if (outrel.r_offset == (bfd_vma) -1)
skip = true;
else if (outrel.r_offset == (bfd_vma) -2)
skip = true, relocate = true;
outrel.r_offset += (input_section->output_section->vma
+ input_section->output_offset);
outrel.r_addend = addend;
if (skip)
memset (&outrel, 0, sizeof outrel);
else if (h != NULL
&& h->dynindx != -1
&& !is_opd
&& (!IS_ABSOLUTE_RELOC (r_type)
|| !info->shared
|| !info->symbolic
|| (h->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR) == 0))
outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
else
{
outrel.r_addend += relocation;
relocate = true;
if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
{
outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
}
else
{
long indx = 0;
if (bfd_is_abs_section (sec))
;
else if (sec == NULL || sec->owner == NULL)
{
bfd_set_error (bfd_error_bad_value);
return false;
}
else
{
asection *osec;
osec = sec->output_section;
indx = elf_section_data (osec)->dynindx;
outrel.r_addend -= osec->vma;
}
outrel.r_info = ELF64_R_INFO (indx, r_type);
}
}
sreloc = elf_section_data (input_section)->sreloc;
if (sreloc == NULL)
abort ();
loc = (Elf64_External_Rela *) sreloc->contents;
loc += sreloc->reloc_count++;
bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
if (! relocate)
continue;
}
break;
case R_PPC64_COPY:
case R_PPC64_GLOB_DAT:
case R_PPC64_JMP_SLOT:
case R_PPC64_RELATIVE:
case R_PPC64_PLTGOT16:
case R_PPC64_PLTGOT16_DS:
case R_PPC64_PLTGOT16_HA:
case R_PPC64_PLTGOT16_HI:
case R_PPC64_PLTGOT16_LO:
case R_PPC64_PLTGOT16_LO_DS:
case R_PPC64_PLTREL32:
case R_PPC64_PLTREL64:
(*_bfd_error_handler)
(_("%s: Relocation %s is not supported for symbol %s."),
bfd_archive_filename (input_bfd),
ppc64_elf_howto_table[(int) r_type]->name, sym_name);
bfd_set_error (bfd_error_invalid_operation);
ret = false;
continue;
}
switch (r_type)
{
default:
break;
case R_PPC64_ADDR16_HA:
case R_PPC64_ADDR16_HIGHERA:
case R_PPC64_ADDR16_HIGHESTA:
case R_PPC64_PLT16_HA:
case R_PPC64_TOC16_HA:
case R_PPC64_SECTOFF_HA:
if (sec != NULL)
addend += ((relocation + addend) & 0x8000) << 1;
break;
case R_PPC64_ADDR16_DS:
case R_PPC64_ADDR16_LO_DS:
case R_PPC64_GOT16_DS:
case R_PPC64_GOT16_LO_DS:
case R_PPC64_PLT16_LO_DS:
case R_PPC64_SECTOFF_DS:
case R_PPC64_SECTOFF_LO_DS:
case R_PPC64_TOC16_DS:
case R_PPC64_TOC16_LO_DS:
case R_PPC64_PLTGOT16_DS:
case R_PPC64_PLTGOT16_LO_DS:
if (((relocation + addend) & 3) != 0)
{
(*_bfd_error_handler)
(_("%s: error: relocation %s not a multiple of 4"),
bfd_archive_filename (input_bfd),
ppc64_elf_howto_table[(int) r_type]->name);
bfd_set_error (bfd_error_bad_value);
ret = false;
continue;
}
break;
}
if (unresolved_reloc
&& !(info->shared
&& (input_section->flags & SEC_DEBUGGING) != 0
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
(*_bfd_error_handler)
(_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
bfd_archive_filename (input_bfd),
bfd_get_section_name (input_bfd, input_section),
(long) rel->r_offset,
h->root.root.string);
r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
input_bfd,
input_section,
contents,
offset,
relocation,
addend);
if (r == bfd_reloc_ok)
;
else if (r == bfd_reloc_overflow)
{
const char *name;
if (h != NULL)
{
if (h->root.type == bfd_link_hash_undefweak
&& ppc64_elf_howto_table[(int) r_type]->pc_relative)
{
continue;
}
name = h->root.root.string;
}
else
{
name = bfd_elf_string_from_elf_section (input_bfd,
symtab_hdr->sh_link,
sym->st_name);
if (name == NULL)
continue;
if (*name == '\0')
name = bfd_section_name (input_bfd, sec);
}
if (! ((*info->callbacks->reloc_overflow)
(info, name, ppc64_elf_howto_table[(int) r_type]->name,
(bfd_vma) 0, input_bfd, input_section, offset)))
return false;
}
else
ret = false;
}
return ret;
}
static boolean
ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
bfd *output_bfd;
struct bfd_link_info *info;
struct elf_link_hash_entry *h;
Elf_Internal_Sym *sym;
{
struct ppc_link_hash_table *htab;
bfd *dynobj;
htab = ppc_hash_table (info);
dynobj = htab->elf.dynobj;
if (h->plt.offset != (bfd_vma) -1
&& ((struct ppc_link_hash_entry *) h)->is_func_descriptor)
{
Elf_Internal_Rela rela;
Elf64_External_Rela *loc;
if (htab->splt == NULL
|| htab->srelplt == NULL
|| htab->sglink == NULL)
abort ();
rela.r_offset = (htab->splt->output_section->vma
+ htab->splt->output_offset
+ h->plt.offset);
rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
rela.r_addend = 0;
loc = (Elf64_External_Rela *) htab->srelplt->contents;
loc += (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE;
bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
}
if (h->got.offset != (bfd_vma) -1)
{
Elf_Internal_Rela rela;
Elf64_External_Rela *loc;
if (htab->sgot == NULL || htab->srelgot == NULL)
abort ();
rela.r_offset = (htab->sgot->output_section->vma
+ htab->sgot->output_offset
+ (h->got.offset &~ (bfd_vma) 1));
if (info->shared
&& (info->symbolic
|| h->dynindx == -1
|| (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
{
BFD_ASSERT((h->got.offset & 1) != 0);
rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
rela.r_addend = (h->root.u.def.value
+ h->root.u.def.section->output_section->vma
+ h->root.u.def.section->output_offset);
}
else
{
BFD_ASSERT ((h->got.offset & 1) == 0);
bfd_put_64 (output_bfd, (bfd_vma) 0,
htab->sgot->contents + h->got.offset);
rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_GLOB_DAT);
rela.r_addend = 0;
}
loc = (Elf64_External_Rela *) htab->srelgot->contents;
loc += htab->srelgot->reloc_count++;
bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
}
if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
{
Elf_Internal_Rela rela;
Elf64_External_Rela *loc;
if (h->dynindx == -1
|| (h->root.type != bfd_link_hash_defined
&& h->root.type != bfd_link_hash_defweak)
|| htab->srelbss == NULL)
abort ();
rela.r_offset = (h->root.u.def.value
+ h->root.u.def.section->output_section->vma
+ h->root.u.def.section->output_offset);
rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
rela.r_addend = 0;
loc = (Elf64_External_Rela *) htab->srelbss->contents;
loc += htab->srelbss->reloc_count++;
bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
}
if (strcmp (h->root.root.string, "_DYNAMIC") == 0)
sym->st_shndx = SHN_ABS;
return true;
}
static enum elf_reloc_type_class
ppc64_elf_reloc_type_class (rela)
const Elf_Internal_Rela *rela;
{
enum elf_ppc_reloc_type r_type;
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rela->r_info);
switch (r_type)
{
case R_PPC64_RELATIVE:
return reloc_class_relative;
case R_PPC64_JMP_SLOT:
return reloc_class_plt;
case R_PPC64_COPY:
return reloc_class_copy;
default:
return reloc_class_normal;
}
}
static boolean
ppc64_elf_finish_dynamic_sections (output_bfd, info)
bfd *output_bfd;
struct bfd_link_info *info;
{
struct ppc_link_hash_table *htab;
bfd *dynobj;
asection *sdyn;
htab = ppc_hash_table (info);
dynobj = htab->elf.dynobj;
sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
if (htab->elf.dynamic_sections_created)
{
Elf64_External_Dyn *dyncon, *dynconend;
if (sdyn == NULL || htab->sgot == NULL)
abort ();
dyncon = (Elf64_External_Dyn *) sdyn->contents;
dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
for (; dyncon < dynconend; dyncon++)
{
Elf_Internal_Dyn dyn;
asection *s;
bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
switch (dyn.d_tag)
{
default:
continue;
case DT_PPC64_GLINK:
dyn.d_un.d_ptr = (htab->sglink->output_section->vma
+ htab->sglink->output_offset);
break;
case DT_PPC64_OPD:
s = bfd_get_section_by_name (output_bfd, ".opd");
if (s != NULL)
dyn.d_un.d_ptr = s->vma;
break;
case DT_PPC64_OPDSZ:
s = bfd_get_section_by_name (output_bfd, ".opd");
if (s != NULL)
dyn.d_un.d_val = s->_raw_size;
break;
case DT_PLTGOT:
dyn.d_un.d_ptr = (htab->splt->output_section->vma
+ htab->splt->output_offset);
break;
case DT_JMPREL:
dyn.d_un.d_ptr = (htab->srelplt->output_section->vma
+ htab->srelplt->output_offset);
break;
case DT_PLTRELSZ:
dyn.d_un.d_val = htab->srelplt->_raw_size;
break;
case DT_RELASZ:
if (htab->srelplt != NULL)
dyn.d_un.d_val -= htab->srelplt->_raw_size;
break;
}
bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
}
}
if (htab->sgot != NULL && htab->sgot->_raw_size != 0)
{
bfd_put_64 (output_bfd,
elf_gp (output_bfd) + TOC_BASE_OFF,
htab->sgot->contents);
elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 8;
}
if (htab->splt != NULL && htab->splt->_raw_size != 0)
{
elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize
= PLT_ENTRY_SIZE;
}
return true;
}
#define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
#define TARGET_LITTLE_NAME "elf64-powerpcle"
#define TARGET_BIG_SYM bfd_elf64_powerpc_vec
#define TARGET_BIG_NAME "elf64-powerpc"
#define ELF_ARCH bfd_arch_powerpc
#define ELF_MACHINE_CODE EM_PPC64
#define ELF_MAXPAGESIZE 0x10000
#define elf_info_to_howto ppc64_elf_info_to_howto
#ifdef EM_CYGNUS_POWERPC
#define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
#endif
#ifdef EM_PPC_OLD
#define ELF_MACHINE_ALT2 EM_PPC_OLD
#endif
#define elf_backend_want_got_sym 0
#define elf_backend_want_plt_sym 0
#define elf_backend_plt_alignment 3
#define elf_backend_plt_not_loaded 1
#define elf_backend_got_symbol_offset 0
#define elf_backend_got_header_size 8
#define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
#define elf_backend_can_gc_sections 1
#define elf_backend_can_refcount 1
#define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
#define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
#define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
#define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
#define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
#define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
#define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
#define elf_backend_check_relocs ppc64_elf_check_relocs
#define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
#define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
#define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
#define elf_backend_hide_symbol ppc64_elf_hide_symbol
#define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
#define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
#define elf_backend_fake_sections ppc64_elf_fake_sections
#define elf_backend_relocate_section ppc64_elf_relocate_section
#define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
#define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
#define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
#include "elf64-target.h"