mirror of
https://github.com/bebbo/amigaos-binutils-2.14.git
synced 2025-12-08 22:38:24 +00:00
3270 lines
102 KiB
C
3270 lines
102 KiB
C
/* SPARC-specific support for 64-bit ELF
|
||
Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||
2003 Free Software Foundation, Inc.
|
||
|
||
This file is part of BFD, the Binary File Descriptor library.
|
||
|
||
This program is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation; either version 2 of the License, or
|
||
(at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with this program; if not, write to the Free Software
|
||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||
|
||
#include "bfd.h"
|
||
#include "sysdep.h"
|
||
#include "libbfd.h"
|
||
#include "elf-bfd.h"
|
||
#include "opcode/sparc.h"
|
||
|
||
/* This is defined if one wants to build upward compatible binaries
|
||
with the original sparc64-elf toolchain. The support is kept in for
|
||
now but is turned off by default. dje 970930 */
|
||
/*#define SPARC64_OLD_RELOCS*/
|
||
|
||
#include "elf/sparc.h"
|
||
|
||
/* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
|
||
#define MINUS_ONE (~ (bfd_vma) 0)
|
||
|
||
static struct bfd_link_hash_table * sparc64_elf_bfd_link_hash_table_create
|
||
PARAMS ((bfd *));
|
||
static bfd_reloc_status_type init_insn_reloc
|
||
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *,
|
||
bfd *, bfd_vma *, bfd_vma *));
|
||
static reloc_howto_type *sparc64_elf_reloc_type_lookup
|
||
PARAMS ((bfd *, bfd_reloc_code_real_type));
|
||
static void sparc64_elf_info_to_howto
|
||
PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
|
||
|
||
static void sparc64_elf_build_plt
|
||
PARAMS ((bfd *, unsigned char *, int));
|
||
static bfd_vma sparc64_elf_plt_entry_offset
|
||
PARAMS ((bfd_vma));
|
||
static bfd_vma sparc64_elf_plt_ptr_offset
|
||
PARAMS ((bfd_vma, bfd_vma));
|
||
|
||
static bfd_boolean sparc64_elf_check_relocs
|
||
PARAMS ((bfd *, struct bfd_link_info *, asection *sec,
|
||
const Elf_Internal_Rela *));
|
||
static bfd_boolean sparc64_elf_adjust_dynamic_symbol
|
||
PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
|
||
static bfd_boolean sparc64_elf_size_dynamic_sections
|
||
PARAMS ((bfd *, struct bfd_link_info *));
|
||
static int sparc64_elf_get_symbol_type
|
||
PARAMS (( Elf_Internal_Sym *, int));
|
||
static bfd_boolean sparc64_elf_add_symbol_hook
|
||
PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
|
||
const char **, flagword *, asection **, bfd_vma *));
|
||
static bfd_boolean sparc64_elf_output_arch_syms
|
||
PARAMS ((bfd *, struct bfd_link_info *, PTR,
|
||
bfd_boolean (*) (PTR, const char *, Elf_Internal_Sym *, asection *)));
|
||
static void sparc64_elf_symbol_processing
|
||
PARAMS ((bfd *, asymbol *));
|
||
|
||
static bfd_boolean sparc64_elf_merge_private_bfd_data
|
||
PARAMS ((bfd *, bfd *));
|
||
|
||
static bfd_boolean sparc64_elf_fake_sections
|
||
PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
|
||
|
||
static const char *sparc64_elf_print_symbol_all
|
||
PARAMS ((bfd *, PTR, asymbol *));
|
||
static bfd_boolean sparc64_elf_new_section_hook
|
||
PARAMS ((bfd *, asection *));
|
||
static bfd_boolean sparc64_elf_relax_section
|
||
PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
|
||
static bfd_boolean sparc64_elf_relocate_section
|
||
PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
|
||
Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
|
||
static bfd_boolean sparc64_elf_finish_dynamic_symbol
|
||
PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
|
||
Elf_Internal_Sym *));
|
||
static bfd_boolean sparc64_elf_finish_dynamic_sections
|
||
PARAMS ((bfd *, struct bfd_link_info *));
|
||
static bfd_boolean sparc64_elf_object_p PARAMS ((bfd *));
|
||
static long sparc64_elf_get_reloc_upper_bound PARAMS ((bfd *, asection *));
|
||
static long sparc64_elf_get_dynamic_reloc_upper_bound PARAMS ((bfd *));
|
||
static bfd_boolean sparc64_elf_slurp_one_reloc_table
|
||
PARAMS ((bfd *, asection *, Elf_Internal_Shdr *, asymbol **, bfd_boolean));
|
||
static bfd_boolean sparc64_elf_slurp_reloc_table
|
||
PARAMS ((bfd *, asection *, asymbol **, bfd_boolean));
|
||
static long sparc64_elf_canonicalize_reloc
|
||
PARAMS ((bfd *, asection *, arelent **, asymbol **));
|
||
static long sparc64_elf_canonicalize_dynamic_reloc
|
||
PARAMS ((bfd *, arelent **, asymbol **));
|
||
static void sparc64_elf_write_relocs PARAMS ((bfd *, asection *, PTR));
|
||
static enum elf_reloc_type_class sparc64_elf_reloc_type_class
|
||
PARAMS ((const Elf_Internal_Rela *));
|
||
|
||
/* The relocation "howto" table. */
|
||
|
||
static bfd_reloc_status_type sparc_elf_notsup_reloc
|
||
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
||
static bfd_reloc_status_type sparc_elf_wdisp16_reloc
|
||
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
||
static bfd_reloc_status_type sparc_elf_hix22_reloc
|
||
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
||
static bfd_reloc_status_type sparc_elf_lox10_reloc
|
||
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
||
|
||
static reloc_howto_type sparc64_elf_howto_table[] =
|
||
{
|
||
HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_8, 0,0, 8,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_8", FALSE,0,0x000000ff,TRUE),
|
||
HOWTO(R_SPARC_16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_16", FALSE,0,0x0000ffff,TRUE),
|
||
HOWTO(R_SPARC_32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_32", FALSE,0,0xffffffff,TRUE),
|
||
HOWTO(R_SPARC_DISP8, 0,0, 8,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP8", FALSE,0,0x000000ff,TRUE),
|
||
HOWTO(R_SPARC_DISP16, 0,1,16,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP16", FALSE,0,0x0000ffff,TRUE),
|
||
HOWTO(R_SPARC_DISP32, 0,2,32,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP32", FALSE,0,0xffffffff,TRUE),
|
||
HOWTO(R_SPARC_WDISP30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP30", FALSE,0,0x3fffffff,TRUE),
|
||
HOWTO(R_SPARC_WDISP22, 2,2,22,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP22", FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_HI22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HI22", FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_22, 0,2,22,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_22", FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_13, 0,2,13,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_13", FALSE,0,0x00001fff,TRUE),
|
||
HOWTO(R_SPARC_LO10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LO10", FALSE,0,0x000003ff,TRUE),
|
||
HOWTO(R_SPARC_GOT10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT10", FALSE,0,0x000003ff,TRUE),
|
||
HOWTO(R_SPARC_GOT13, 0,2,13,FALSE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_GOT13", FALSE,0,0x00001fff,TRUE),
|
||
HOWTO(R_SPARC_GOT22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT22", FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_PC10, 0,2,10,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC10", FALSE,0,0x000003ff,TRUE),
|
||
HOWTO(R_SPARC_PC22, 10,2,22,TRUE, 0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PC22", FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_WPLT30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WPLT30", FALSE,0,0x3fffffff,TRUE),
|
||
HOWTO(R_SPARC_COPY, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_COPY", FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_GLOB_DAT, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GLOB_DAT",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_JMP_SLOT, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_JMP_SLOT",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_RELATIVE, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_RELATIVE",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_UA32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA32", FALSE,0,0xffffffff,TRUE),
|
||
#ifndef SPARC64_OLD_RELOCS
|
||
HOWTO(R_SPARC_PLT32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PLT32", FALSE,0,0xffffffff,TRUE),
|
||
/* These aren't implemented yet. */
|
||
HOWTO(R_SPARC_HIPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_HIPLT22", FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_LOPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_LOPLT10", FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_PCPLT32, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT32", FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_PCPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT22", FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_PCPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT10", FALSE,0,0x00000000,TRUE),
|
||
#endif
|
||
HOWTO(R_SPARC_10, 0,2,10,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_10", FALSE,0,0x000003ff,TRUE),
|
||
HOWTO(R_SPARC_11, 0,2,11,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_11", FALSE,0,0x000007ff,TRUE),
|
||
HOWTO(R_SPARC_64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_64", FALSE,0,MINUS_ONE, TRUE),
|
||
HOWTO(R_SPARC_OLO10, 0,2,13,FALSE,0,complain_overflow_signed, sparc_elf_notsup_reloc, "R_SPARC_OLO10", FALSE,0,0x00001fff,TRUE),
|
||
HOWTO(R_SPARC_HH22, 42,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_HH22", FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_HM10, 32,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HM10", FALSE,0,0x000003ff,TRUE),
|
||
HOWTO(R_SPARC_LM22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LM22", FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_PC_HH22, 42,2,22,TRUE, 0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_PC_HH22", FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_PC_HM10, 32,2,10,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC_HM10", FALSE,0,0x000003ff,TRUE),
|
||
HOWTO(R_SPARC_PC_LM22, 10,2,22,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC_LM22", FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_WDISP16, 2,2,16,TRUE, 0,complain_overflow_signed, sparc_elf_wdisp16_reloc,"R_SPARC_WDISP16", FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_WDISP19, 2,2,19,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP19", FALSE,0,0x0007ffff,TRUE),
|
||
HOWTO(R_SPARC_UNUSED_42, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_UNUSED_42",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_7, 0,2, 7,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_7", FALSE,0,0x0000007f,TRUE),
|
||
HOWTO(R_SPARC_5, 0,2, 5,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_5", FALSE,0,0x0000001f,TRUE),
|
||
HOWTO(R_SPARC_6, 0,2, 6,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_6", FALSE,0,0x0000003f,TRUE),
|
||
HOWTO(R_SPARC_DISP64, 0,4,64,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP64", FALSE,0,MINUS_ONE, TRUE),
|
||
HOWTO(R_SPARC_PLT64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PLT64", FALSE,0,MINUS_ONE, TRUE),
|
||
HOWTO(R_SPARC_HIX22, 0,4, 0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc, "R_SPARC_HIX22", FALSE,0,MINUS_ONE, FALSE),
|
||
HOWTO(R_SPARC_LOX10, 0,4, 0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_LOX10", FALSE,0,MINUS_ONE, FALSE),
|
||
HOWTO(R_SPARC_H44, 22,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_H44", FALSE,0,0x003fffff,FALSE),
|
||
HOWTO(R_SPARC_M44, 12,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_M44", FALSE,0,0x000003ff,FALSE),
|
||
HOWTO(R_SPARC_L44, 0,2,13,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_L44", FALSE,0,0x00000fff,FALSE),
|
||
HOWTO(R_SPARC_REGISTER, 0,4, 0,FALSE,0,complain_overflow_bitfield,sparc_elf_notsup_reloc, "R_SPARC_REGISTER",FALSE,0,MINUS_ONE, FALSE),
|
||
HOWTO(R_SPARC_UA64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA64", FALSE,0,MINUS_ONE, TRUE),
|
||
HOWTO(R_SPARC_UA16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA16", FALSE,0,0x0000ffff,TRUE),
|
||
HOWTO(R_SPARC_TLS_GD_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_HI22",FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_TLS_GD_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_LO10",FALSE,0,0x000003ff,TRUE),
|
||
HOWTO(R_SPARC_TLS_GD_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_ADD",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_TLS_GD_CALL,2,2,30,TRUE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_CALL",FALSE,0,0x3fffffff,TRUE),
|
||
HOWTO(R_SPARC_TLS_LDM_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_HI22",FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_TLS_LDM_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_LO10",FALSE,0,0x000003ff,TRUE),
|
||
HOWTO(R_SPARC_TLS_LDM_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_ADD",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_TLS_LDM_CALL,2,2,30,TRUE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_CALL",FALSE,0,0x3fffffff,TRUE),
|
||
HOWTO(R_SPARC_TLS_LDO_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc,"R_SPARC_TLS_LDO_HIX22",FALSE,0,0x003fffff, FALSE),
|
||
HOWTO(R_SPARC_TLS_LDO_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_TLS_LDO_LOX10",FALSE,0,0x000003ff, FALSE),
|
||
HOWTO(R_SPARC_TLS_LDO_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDO_ADD",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_TLS_IE_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_HI22",FALSE,0,0x003fffff,TRUE),
|
||
HOWTO(R_SPARC_TLS_IE_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LO10",FALSE,0,0x000003ff,TRUE),
|
||
HOWTO(R_SPARC_TLS_IE_LD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LD",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_TLS_IE_LDX,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LDX",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_TLS_IE_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_ADD",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_TLS_LE_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc, "R_SPARC_TLS_LE_HIX22",FALSE,0,0x003fffff, FALSE),
|
||
HOWTO(R_SPARC_TLS_LE_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_TLS_LE_LOX10",FALSE,0,0x000003ff, FALSE),
|
||
HOWTO(R_SPARC_TLS_DTPMOD32,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_DTPMOD32",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_TLS_DTPMOD64,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_DTPMOD64",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_TLS_DTPOFF32,0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_TLS_DTPOFF32",FALSE,0,0xffffffff,TRUE),
|
||
HOWTO(R_SPARC_TLS_DTPOFF64,0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_TLS_DTPOFF64",FALSE,0,MINUS_ONE,TRUE),
|
||
HOWTO(R_SPARC_TLS_TPOFF32,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_TPOFF32",FALSE,0,0x00000000,TRUE),
|
||
HOWTO(R_SPARC_TLS_TPOFF64,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_TPOFF64",FALSE,0,0x00000000,TRUE)
|
||
};
|
||
|
||
struct elf_reloc_map {
|
||
bfd_reloc_code_real_type bfd_reloc_val;
|
||
unsigned char elf_reloc_val;
|
||
};
|
||
|
||
static const struct elf_reloc_map sparc_reloc_map[] =
|
||
{
|
||
{ BFD_RELOC_NONE, R_SPARC_NONE, },
|
||
{ BFD_RELOC_16, R_SPARC_16, },
|
||
{ BFD_RELOC_16_PCREL, R_SPARC_DISP16 },
|
||
{ BFD_RELOC_8, R_SPARC_8 },
|
||
{ BFD_RELOC_8_PCREL, R_SPARC_DISP8 },
|
||
{ BFD_RELOC_CTOR, R_SPARC_64 },
|
||
{ BFD_RELOC_32, R_SPARC_32 },
|
||
{ BFD_RELOC_32_PCREL, R_SPARC_DISP32 },
|
||
{ BFD_RELOC_HI22, R_SPARC_HI22 },
|
||
{ BFD_RELOC_LO10, R_SPARC_LO10, },
|
||
{ BFD_RELOC_32_PCREL_S2, R_SPARC_WDISP30 },
|
||
{ BFD_RELOC_64_PCREL, R_SPARC_DISP64 },
|
||
{ BFD_RELOC_SPARC22, R_SPARC_22 },
|
||
{ BFD_RELOC_SPARC13, R_SPARC_13 },
|
||
{ BFD_RELOC_SPARC_GOT10, R_SPARC_GOT10 },
|
||
{ BFD_RELOC_SPARC_GOT13, R_SPARC_GOT13 },
|
||
{ BFD_RELOC_SPARC_GOT22, R_SPARC_GOT22 },
|
||
{ BFD_RELOC_SPARC_PC10, R_SPARC_PC10 },
|
||
{ BFD_RELOC_SPARC_PC22, R_SPARC_PC22 },
|
||
{ BFD_RELOC_SPARC_WPLT30, R_SPARC_WPLT30 },
|
||
{ BFD_RELOC_SPARC_COPY, R_SPARC_COPY },
|
||
{ BFD_RELOC_SPARC_GLOB_DAT, R_SPARC_GLOB_DAT },
|
||
{ BFD_RELOC_SPARC_JMP_SLOT, R_SPARC_JMP_SLOT },
|
||
{ BFD_RELOC_SPARC_RELATIVE, R_SPARC_RELATIVE },
|
||
{ BFD_RELOC_SPARC_WDISP22, R_SPARC_WDISP22 },
|
||
{ BFD_RELOC_SPARC_UA16, R_SPARC_UA16 },
|
||
{ BFD_RELOC_SPARC_UA32, R_SPARC_UA32 },
|
||
{ BFD_RELOC_SPARC_UA64, R_SPARC_UA64 },
|
||
{ BFD_RELOC_SPARC_10, R_SPARC_10 },
|
||
{ BFD_RELOC_SPARC_11, R_SPARC_11 },
|
||
{ BFD_RELOC_SPARC_64, R_SPARC_64 },
|
||
{ BFD_RELOC_SPARC_OLO10, R_SPARC_OLO10 },
|
||
{ BFD_RELOC_SPARC_HH22, R_SPARC_HH22 },
|
||
{ BFD_RELOC_SPARC_HM10, R_SPARC_HM10 },
|
||
{ BFD_RELOC_SPARC_LM22, R_SPARC_LM22 },
|
||
{ BFD_RELOC_SPARC_PC_HH22, R_SPARC_PC_HH22 },
|
||
{ BFD_RELOC_SPARC_PC_HM10, R_SPARC_PC_HM10 },
|
||
{ BFD_RELOC_SPARC_PC_LM22, R_SPARC_PC_LM22 },
|
||
{ BFD_RELOC_SPARC_WDISP16, R_SPARC_WDISP16 },
|
||
{ BFD_RELOC_SPARC_WDISP19, R_SPARC_WDISP19 },
|
||
{ BFD_RELOC_SPARC_7, R_SPARC_7 },
|
||
{ BFD_RELOC_SPARC_5, R_SPARC_5 },
|
||
{ BFD_RELOC_SPARC_6, R_SPARC_6 },
|
||
{ BFD_RELOC_SPARC_DISP64, R_SPARC_DISP64 },
|
||
{ BFD_RELOC_SPARC_TLS_GD_HI22, R_SPARC_TLS_GD_HI22 },
|
||
{ BFD_RELOC_SPARC_TLS_GD_LO10, R_SPARC_TLS_GD_LO10 },
|
||
{ BFD_RELOC_SPARC_TLS_GD_ADD, R_SPARC_TLS_GD_ADD },
|
||
{ BFD_RELOC_SPARC_TLS_GD_CALL, R_SPARC_TLS_GD_CALL },
|
||
{ BFD_RELOC_SPARC_TLS_LDM_HI22, R_SPARC_TLS_LDM_HI22 },
|
||
{ BFD_RELOC_SPARC_TLS_LDM_LO10, R_SPARC_TLS_LDM_LO10 },
|
||
{ BFD_RELOC_SPARC_TLS_LDM_ADD, R_SPARC_TLS_LDM_ADD },
|
||
{ BFD_RELOC_SPARC_TLS_LDM_CALL, R_SPARC_TLS_LDM_CALL },
|
||
{ BFD_RELOC_SPARC_TLS_LDO_HIX22, R_SPARC_TLS_LDO_HIX22 },
|
||
{ BFD_RELOC_SPARC_TLS_LDO_LOX10, R_SPARC_TLS_LDO_LOX10 },
|
||
{ BFD_RELOC_SPARC_TLS_LDO_ADD, R_SPARC_TLS_LDO_ADD },
|
||
{ BFD_RELOC_SPARC_TLS_IE_HI22, R_SPARC_TLS_IE_HI22 },
|
||
{ BFD_RELOC_SPARC_TLS_IE_LO10, R_SPARC_TLS_IE_LO10 },
|
||
{ BFD_RELOC_SPARC_TLS_IE_LD, R_SPARC_TLS_IE_LD },
|
||
{ BFD_RELOC_SPARC_TLS_IE_LDX, R_SPARC_TLS_IE_LDX },
|
||
{ BFD_RELOC_SPARC_TLS_IE_ADD, R_SPARC_TLS_IE_ADD },
|
||
{ BFD_RELOC_SPARC_TLS_LE_HIX22, R_SPARC_TLS_LE_HIX22 },
|
||
{ BFD_RELOC_SPARC_TLS_LE_LOX10, R_SPARC_TLS_LE_LOX10 },
|
||
{ BFD_RELOC_SPARC_TLS_DTPMOD32, R_SPARC_TLS_DTPMOD32 },
|
||
{ BFD_RELOC_SPARC_TLS_DTPMOD64, R_SPARC_TLS_DTPMOD64 },
|
||
{ BFD_RELOC_SPARC_TLS_DTPOFF32, R_SPARC_TLS_DTPOFF32 },
|
||
{ BFD_RELOC_SPARC_TLS_DTPOFF64, R_SPARC_TLS_DTPOFF64 },
|
||
{ BFD_RELOC_SPARC_TLS_TPOFF32, R_SPARC_TLS_TPOFF32 },
|
||
{ BFD_RELOC_SPARC_TLS_TPOFF64, R_SPARC_TLS_TPOFF64 },
|
||
#ifndef SPARC64_OLD_RELOCS
|
||
{ BFD_RELOC_SPARC_PLT32, R_SPARC_PLT32 },
|
||
#endif
|
||
{ BFD_RELOC_SPARC_PLT64, R_SPARC_PLT64 },
|
||
{ BFD_RELOC_SPARC_HIX22, R_SPARC_HIX22 },
|
||
{ BFD_RELOC_SPARC_LOX10, R_SPARC_LOX10 },
|
||
{ BFD_RELOC_SPARC_H44, R_SPARC_H44 },
|
||
{ BFD_RELOC_SPARC_M44, R_SPARC_M44 },
|
||
{ BFD_RELOC_SPARC_L44, R_SPARC_L44 },
|
||
{ BFD_RELOC_SPARC_REGISTER, R_SPARC_REGISTER }
|
||
};
|
||
|
||
static reloc_howto_type *
|
||
sparc64_elf_reloc_type_lookup (abfd, code)
|
||
bfd *abfd ATTRIBUTE_UNUSED;
|
||
bfd_reloc_code_real_type code;
|
||
{
|
||
unsigned int i;
|
||
for (i = 0; i < sizeof (sparc_reloc_map) / sizeof (struct elf_reloc_map); i++)
|
||
{
|
||
if (sparc_reloc_map[i].bfd_reloc_val == code)
|
||
return &sparc64_elf_howto_table[(int) sparc_reloc_map[i].elf_reloc_val];
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
static void
|
||
sparc64_elf_info_to_howto (abfd, cache_ptr, dst)
|
||
bfd *abfd ATTRIBUTE_UNUSED;
|
||
arelent *cache_ptr;
|
||
Elf_Internal_Rela *dst;
|
||
{
|
||
BFD_ASSERT (ELF64_R_TYPE_ID (dst->r_info) < (unsigned int) R_SPARC_max_std);
|
||
cache_ptr->howto = &sparc64_elf_howto_table[ELF64_R_TYPE_ID (dst->r_info)];
|
||
}
|
||
|
||
struct sparc64_elf_section_data
|
||
{
|
||
struct bfd_elf_section_data elf;
|
||
unsigned int do_relax, reloc_count;
|
||
};
|
||
|
||
#define sec_do_relax(sec) \
|
||
((struct sparc64_elf_section_data *) elf_section_data (sec))->do_relax
|
||
#define canon_reloc_count(sec) \
|
||
((struct sparc64_elf_section_data *) elf_section_data (sec))->reloc_count
|
||
|
||
/* Due to the way how we handle R_SPARC_OLO10, each entry in a SHT_RELA
|
||
section can represent up to two relocs, we must tell the user to allocate
|
||
more space. */
|
||
|
||
static long
|
||
sparc64_elf_get_reloc_upper_bound (abfd, sec)
|
||
bfd *abfd ATTRIBUTE_UNUSED;
|
||
asection *sec;
|
||
{
|
||
return (sec->reloc_count * 2 + 1) * sizeof (arelent *);
|
||
}
|
||
|
||
static long
|
||
sparc64_elf_get_dynamic_reloc_upper_bound (abfd)
|
||
bfd *abfd;
|
||
{
|
||
return _bfd_elf_get_dynamic_reloc_upper_bound (abfd) * 2;
|
||
}
|
||
|
||
/* Read relocations for ASECT from REL_HDR. There are RELOC_COUNT of
|
||
them. We cannot use generic elf routines for this, because R_SPARC_OLO10
|
||
has secondary addend in ELF64_R_TYPE_DATA. We handle it as two relocations
|
||
for the same location, R_SPARC_LO10 and R_SPARC_13. */
|
||
|
||
static bfd_boolean
|
||
sparc64_elf_slurp_one_reloc_table (abfd, asect, rel_hdr, symbols, dynamic)
|
||
bfd *abfd;
|
||
asection *asect;
|
||
Elf_Internal_Shdr *rel_hdr;
|
||
asymbol **symbols;
|
||
bfd_boolean dynamic;
|
||
{
|
||
PTR allocated = NULL;
|
||
bfd_byte *native_relocs;
|
||
arelent *relent;
|
||
unsigned int i;
|
||
int entsize;
|
||
bfd_size_type count;
|
||
arelent *relents;
|
||
|
||
allocated = (PTR) bfd_malloc (rel_hdr->sh_size);
|
||
if (allocated == NULL)
|
||
goto error_return;
|
||
|
||
if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0
|
||
|| bfd_bread (allocated, rel_hdr->sh_size, abfd) != rel_hdr->sh_size)
|
||
goto error_return;
|
||
|
||
native_relocs = (bfd_byte *) allocated;
|
||
|
||
relents = asect->relocation + canon_reloc_count (asect);
|
||
|
||
entsize = rel_hdr->sh_entsize;
|
||
BFD_ASSERT (entsize == sizeof (Elf64_External_Rela));
|
||
|
||
count = rel_hdr->sh_size / entsize;
|
||
|
||
for (i = 0, relent = relents; i < count;
|
||
i++, relent++, native_relocs += entsize)
|
||
{
|
||
Elf_Internal_Rela rela;
|
||
|
||
bfd_elf64_swap_reloca_in (abfd, native_relocs, &rela);
|
||
|
||
/* The address of an ELF reloc is section relative for an object
|
||
file, and absolute for an executable file or shared library.
|
||
The address of a normal BFD reloc is always section relative,
|
||
and the address of a dynamic reloc is absolute.. */
|
||
if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 || dynamic)
|
||
relent->address = rela.r_offset;
|
||
else
|
||
relent->address = rela.r_offset - asect->vma;
|
||
|
||
if (ELF64_R_SYM (rela.r_info) == 0)
|
||
relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
|
||
else
|
||
{
|
||
asymbol **ps, *s;
|
||
|
||
ps = symbols + ELF64_R_SYM (rela.r_info) - 1;
|
||
s = *ps;
|
||
|
||
/* Canonicalize ELF section symbols. FIXME: Why? */
|
||
if ((s->flags & BSF_SECTION_SYM) == 0)
|
||
relent->sym_ptr_ptr = ps;
|
||
else
|
||
relent->sym_ptr_ptr = s->section->symbol_ptr_ptr;
|
||
}
|
||
|
||
relent->addend = rela.r_addend;
|
||
|
||
BFD_ASSERT (ELF64_R_TYPE_ID (rela.r_info) < (unsigned int) R_SPARC_max_std);
|
||
if (ELF64_R_TYPE_ID (rela.r_info) == R_SPARC_OLO10)
|
||
{
|
||
relent->howto = &sparc64_elf_howto_table[R_SPARC_LO10];
|
||
relent[1].address = relent->address;
|
||
relent++;
|
||
relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
|
||
relent->addend = ELF64_R_TYPE_DATA (rela.r_info);
|
||
relent->howto = &sparc64_elf_howto_table[R_SPARC_13];
|
||
}
|
||
else
|
||
relent->howto = &sparc64_elf_howto_table[ELF64_R_TYPE_ID (rela.r_info)];
|
||
}
|
||
|
||
canon_reloc_count (asect) += relent - relents;
|
||
|
||
if (allocated != NULL)
|
||
free (allocated);
|
||
|
||
return TRUE;
|
||
|
||
error_return:
|
||
if (allocated != NULL)
|
||
free (allocated);
|
||
return FALSE;
|
||
}
|
||
|
||
/* Read in and swap the external relocs. */
|
||
|
||
static bfd_boolean
|
||
sparc64_elf_slurp_reloc_table (abfd, asect, symbols, dynamic)
|
||
bfd *abfd;
|
||
asection *asect;
|
||
asymbol **symbols;
|
||
bfd_boolean dynamic;
|
||
{
|
||
struct bfd_elf_section_data * const d = elf_section_data (asect);
|
||
Elf_Internal_Shdr *rel_hdr;
|
||
Elf_Internal_Shdr *rel_hdr2;
|
||
bfd_size_type amt;
|
||
|
||
if (asect->relocation != NULL)
|
||
return TRUE;
|
||
|
||
if (! dynamic)
|
||
{
|
||
if ((asect->flags & SEC_RELOC) == 0
|
||
|| asect->reloc_count == 0)
|
||
return TRUE;
|
||
|
||
rel_hdr = &d->rel_hdr;
|
||
rel_hdr2 = d->rel_hdr2;
|
||
|
||
BFD_ASSERT (asect->rel_filepos == rel_hdr->sh_offset
|
||
|| (rel_hdr2 && asect->rel_filepos == rel_hdr2->sh_offset));
|
||
}
|
||
else
|
||
{
|
||
/* Note that ASECT->RELOC_COUNT tends not to be accurate in this
|
||
case because relocations against this section may use the
|
||
dynamic symbol table, and in that case bfd_section_from_shdr
|
||
in elf.c does not update the RELOC_COUNT. */
|
||
if (asect->_raw_size == 0)
|
||
return TRUE;
|
||
|
||
rel_hdr = &d->this_hdr;
|
||
asect->reloc_count = NUM_SHDR_ENTRIES (rel_hdr);
|
||
rel_hdr2 = NULL;
|
||
}
|
||
|
||
amt = asect->reloc_count;
|
||
amt *= 2 * sizeof (arelent);
|
||
asect->relocation = (arelent *) bfd_alloc (abfd, amt);
|
||
if (asect->relocation == NULL)
|
||
return FALSE;
|
||
|
||
/* The sparc64_elf_slurp_one_reloc_table routine increments
|
||
canon_reloc_count. */
|
||
canon_reloc_count (asect) = 0;
|
||
|
||
if (!sparc64_elf_slurp_one_reloc_table (abfd, asect, rel_hdr, symbols,
|
||
dynamic))
|
||
return FALSE;
|
||
|
||
if (rel_hdr2
|
||
&& !sparc64_elf_slurp_one_reloc_table (abfd, asect, rel_hdr2, symbols,
|
||
dynamic))
|
||
return FALSE;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/* Canonicalize the relocs. */
|
||
|
||
static long
|
||
sparc64_elf_canonicalize_reloc (abfd, section, relptr, symbols)
|
||
bfd *abfd;
|
||
sec_ptr section;
|
||
arelent **relptr;
|
||
asymbol **symbols;
|
||
{
|
||
arelent *tblptr;
|
||
unsigned int i;
|
||
struct elf_backend_data *bed = get_elf_backend_data (abfd);
|
||
|
||
if (! bed->s->slurp_reloc_table (abfd, section, symbols, FALSE))
|
||
return -1;
|
||
|
||
tblptr = section->relocation;
|
||
for (i = 0; i < canon_reloc_count (section); i++)
|
||
*relptr++ = tblptr++;
|
||
|
||
*relptr = NULL;
|
||
|
||
return canon_reloc_count (section);
|
||
}
|
||
|
||
|
||
/* Canonicalize the dynamic relocation entries. Note that we return
|
||
the dynamic relocations as a single block, although they are
|
||
actually associated with particular sections; the interface, which
|
||
was designed for SunOS style shared libraries, expects that there
|
||
is only one set of dynamic relocs. Any section that was actually
|
||
installed in the BFD, and has type SHT_REL or SHT_RELA, and uses
|
||
the dynamic symbol table, is considered to be a dynamic reloc
|
||
section. */
|
||
|
||
static long
|
||
sparc64_elf_canonicalize_dynamic_reloc (abfd, storage, syms)
|
||
bfd *abfd;
|
||
arelent **storage;
|
||
asymbol **syms;
|
||
{
|
||
asection *s;
|
||
long ret;
|
||
|
||
if (elf_dynsymtab (abfd) == 0)
|
||
{
|
||
bfd_set_error (bfd_error_invalid_operation);
|
||
return -1;
|
||
}
|
||
|
||
ret = 0;
|
||
for (s = abfd->sections; s != NULL; s = s->next)
|
||
{
|
||
if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
|
||
&& (elf_section_data (s)->this_hdr.sh_type == SHT_RELA))
|
||
{
|
||
arelent *p;
|
||
long count, i;
|
||
|
||
if (! sparc64_elf_slurp_reloc_table (abfd, s, syms, TRUE))
|
||
return -1;
|
||
count = canon_reloc_count (s);
|
||
p = s->relocation;
|
||
for (i = 0; i < count; i++)
|
||
*storage++ = p++;
|
||
ret += count;
|
||
}
|
||
}
|
||
|
||
*storage = NULL;
|
||
|
||
return ret;
|
||
}
|
||
|
||
/* Write out the relocs. */
|
||
|
||
static void
|
||
sparc64_elf_write_relocs (abfd, sec, data)
|
||
bfd *abfd;
|
||
asection *sec;
|
||
PTR data;
|
||
{
|
||
bfd_boolean *failedp = (bfd_boolean *) data;
|
||
Elf_Internal_Shdr *rela_hdr;
|
||
Elf64_External_Rela *outbound_relocas, *src_rela;
|
||
unsigned int idx, count;
|
||
asymbol *last_sym = 0;
|
||
int last_sym_idx = 0;
|
||
|
||
/* If we have already failed, don't do anything. */
|
||
if (*failedp)
|
||
return;
|
||
|
||
if ((sec->flags & SEC_RELOC) == 0)
|
||
return;
|
||
|
||
/* The linker backend writes the relocs out itself, and sets the
|
||
reloc_count field to zero to inhibit writing them here. Also,
|
||
sometimes the SEC_RELOC flag gets set even when there aren't any
|
||
relocs. */
|
||
if (sec->reloc_count == 0)
|
||
return;
|
||
|
||
/* We can combine two relocs that refer to the same address
|
||
into R_SPARC_OLO10 if first one is R_SPARC_LO10 and the
|
||
latter is R_SPARC_13 with no associated symbol. */
|
||
count = 0;
|
||
for (idx = 0; idx < sec->reloc_count; idx++)
|
||
{
|
||
bfd_vma addr;
|
||
|
||
++count;
|
||
|
||
addr = sec->orelocation[idx]->address;
|
||
if (sec->orelocation[idx]->howto->type == R_SPARC_LO10
|
||
&& idx < sec->reloc_count - 1)
|
||
{
|
||
arelent *r = sec->orelocation[idx + 1];
|
||
|
||
if (r->howto->type == R_SPARC_13
|
||
&& r->address == addr
|
||
&& bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
|
||
&& (*r->sym_ptr_ptr)->value == 0)
|
||
++idx;
|
||
}
|
||
}
|
||
|
||
rela_hdr = &elf_section_data (sec)->rel_hdr;
|
||
|
||
rela_hdr->sh_size = rela_hdr->sh_entsize * count;
|
||
rela_hdr->contents = (PTR) bfd_alloc (abfd, rela_hdr->sh_size);
|
||
if (rela_hdr->contents == NULL)
|
||
{
|
||
*failedp = TRUE;
|
||
return;
|
||
}
|
||
|
||
/* Figure out whether the relocations are RELA or REL relocations. */
|
||
if (rela_hdr->sh_type != SHT_RELA)
|
||
abort ();
|
||
|
||
/* orelocation has the data, reloc_count has the count... */
|
||
outbound_relocas = (Elf64_External_Rela *) rela_hdr->contents;
|
||
src_rela = outbound_relocas;
|
||
|
||
for (idx = 0; idx < sec->reloc_count; idx++)
|
||
{
|
||
Elf_Internal_Rela dst_rela;
|
||
arelent *ptr;
|
||
asymbol *sym;
|
||
int n;
|
||
|
||
ptr = sec->orelocation[idx];
|
||
|
||
/* The address of an ELF reloc is section relative for an object
|
||
file, and absolute for an executable file or shared library.
|
||
The address of a BFD reloc is always section relative. */
|
||
if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
|
||
dst_rela.r_offset = ptr->address;
|
||
else
|
||
dst_rela.r_offset = ptr->address + sec->vma;
|
||
|
||
sym = *ptr->sym_ptr_ptr;
|
||
if (sym == last_sym)
|
||
n = last_sym_idx;
|
||
else if (bfd_is_abs_section (sym->section) && sym->value == 0)
|
||
n = STN_UNDEF;
|
||
else
|
||
{
|
||
last_sym = sym;
|
||
n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
|
||
if (n < 0)
|
||
{
|
||
*failedp = TRUE;
|
||
return;
|
||
}
|
||
last_sym_idx = n;
|
||
}
|
||
|
||
if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
|
||
&& (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
|
||
&& ! _bfd_elf_validate_reloc (abfd, ptr))
|
||
{
|
||
*failedp = TRUE;
|
||
return;
|
||
}
|
||
|
||
if (ptr->howto->type == R_SPARC_LO10
|
||
&& idx < sec->reloc_count - 1)
|
||
{
|
||
arelent *r = sec->orelocation[idx + 1];
|
||
|
||
if (r->howto->type == R_SPARC_13
|
||
&& r->address == ptr->address
|
||
&& bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
|
||
&& (*r->sym_ptr_ptr)->value == 0)
|
||
{
|
||
idx++;
|
||
dst_rela.r_info
|
||
= ELF64_R_INFO (n, ELF64_R_TYPE_INFO (r->addend,
|
||
R_SPARC_OLO10));
|
||
}
|
||
else
|
||
dst_rela.r_info = ELF64_R_INFO (n, R_SPARC_LO10);
|
||
}
|
||
else
|
||
dst_rela.r_info = ELF64_R_INFO (n, ptr->howto->type);
|
||
|
||
dst_rela.r_addend = ptr->addend;
|
||
bfd_elf64_swap_reloca_out (abfd, &dst_rela, (bfd_byte *) src_rela);
|
||
++src_rela;
|
||
}
|
||
}
|
||
|
||
/* Sparc64 ELF linker hash table. */
|
||
|
||
struct sparc64_elf_app_reg
|
||
{
|
||
unsigned char bind;
|
||
unsigned short shndx;
|
||
bfd *abfd;
|
||
char *name;
|
||
};
|
||
|
||
struct sparc64_elf_link_hash_table
|
||
{
|
||
struct elf_link_hash_table root;
|
||
|
||
struct sparc64_elf_app_reg app_regs [4];
|
||
};
|
||
|
||
/* Get the Sparc64 ELF linker hash table from a link_info structure. */
|
||
|
||
#define sparc64_elf_hash_table(p) \
|
||
((struct sparc64_elf_link_hash_table *) ((p)->hash))
|
||
|
||
/* Create a Sparc64 ELF linker hash table. */
|
||
|
||
static struct bfd_link_hash_table *
|
||
sparc64_elf_bfd_link_hash_table_create (abfd)
|
||
bfd *abfd;
|
||
{
|
||
struct sparc64_elf_link_hash_table *ret;
|
||
bfd_size_type amt = sizeof (struct sparc64_elf_link_hash_table);
|
||
|
||
ret = (struct sparc64_elf_link_hash_table *) bfd_zmalloc (amt);
|
||
if (ret == (struct sparc64_elf_link_hash_table *) NULL)
|
||
return NULL;
|
||
|
||
if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
|
||
_bfd_elf_link_hash_newfunc))
|
||
{
|
||
free (ret);
|
||
return NULL;
|
||
}
|
||
|
||
return &ret->root.root;
|
||
}
|
||
|
||
/* Utility for performing the standard initial work of an instruction
|
||
relocation.
|
||
*PRELOCATION will contain the relocated item.
|
||
*PINSN will contain the instruction from the input stream.
|
||
If the result is `bfd_reloc_other' the caller can continue with
|
||
performing the relocation. Otherwise it must stop and return the
|
||
value to its caller. */
|
||
|
||
static bfd_reloc_status_type
|
||
init_insn_reloc (abfd,
|
||
reloc_entry,
|
||
symbol,
|
||
data,
|
||
input_section,
|
||
output_bfd,
|
||
prelocation,
|
||
pinsn)
|
||
bfd *abfd;
|
||
arelent *reloc_entry;
|
||
asymbol *symbol;
|
||
PTR data;
|
||
asection *input_section;
|
||
bfd *output_bfd;
|
||
bfd_vma *prelocation;
|
||
bfd_vma *pinsn;
|
||
{
|
||
bfd_vma relocation;
|
||
reloc_howto_type *howto = reloc_entry->howto;
|
||
|
||
if (output_bfd != (bfd *) NULL
|
||
&& (symbol->flags & BSF_SECTION_SYM) == 0
|
||
&& (! howto->partial_inplace
|
||
|| reloc_entry->addend == 0))
|
||
{
|
||
reloc_entry->address += input_section->output_offset;
|
||
return bfd_reloc_ok;
|
||
}
|
||
|
||
/* This works because partial_inplace is FALSE. */
|
||
if (output_bfd != NULL)
|
||
return bfd_reloc_continue;
|
||
|
||
if (reloc_entry->address > input_section->_cooked_size)
|
||
return bfd_reloc_outofrange;
|
||
|
||
relocation = (symbol->value
|
||
+ symbol->section->output_section->vma
|
||
+ symbol->section->output_offset);
|
||
relocation += reloc_entry->addend;
|
||
if (howto->pc_relative)
|
||
{
|
||
relocation -= (input_section->output_section->vma
|
||
+ input_section->output_offset);
|
||
relocation -= reloc_entry->address;
|
||
}
|
||
|
||
*prelocation = relocation;
|
||
*pinsn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
|
||
return bfd_reloc_other;
|
||
}
|
||
|
||
/* For unsupported relocs. */
|
||
|
||
static bfd_reloc_status_type
|
||
sparc_elf_notsup_reloc (abfd,
|
||
reloc_entry,
|
||
symbol,
|
||
data,
|
||
input_section,
|
||
output_bfd,
|
||
error_message)
|
||
bfd *abfd ATTRIBUTE_UNUSED;
|
||
arelent *reloc_entry ATTRIBUTE_UNUSED;
|
||
asymbol *symbol ATTRIBUTE_UNUSED;
|
||
PTR data ATTRIBUTE_UNUSED;
|
||
asection *input_section ATTRIBUTE_UNUSED;
|
||
bfd *output_bfd ATTRIBUTE_UNUSED;
|
||
char **error_message ATTRIBUTE_UNUSED;
|
||
{
|
||
return bfd_reloc_notsupported;
|
||
}
|
||
|
||
/* Handle the WDISP16 reloc. */
|
||
|
||
static bfd_reloc_status_type
|
||
sparc_elf_wdisp16_reloc (abfd, reloc_entry, symbol, data, input_section,
|
||
output_bfd, error_message)
|
||
bfd *abfd;
|
||
arelent *reloc_entry;
|
||
asymbol *symbol;
|
||
PTR data;
|
||
asection *input_section;
|
||
bfd *output_bfd;
|
||
char **error_message ATTRIBUTE_UNUSED;
|
||
{
|
||
bfd_vma relocation;
|
||
bfd_vma insn;
|
||
bfd_reloc_status_type status;
|
||
|
||
status = init_insn_reloc (abfd, reloc_entry, symbol, data,
|
||
input_section, output_bfd, &relocation, &insn);
|
||
if (status != bfd_reloc_other)
|
||
return status;
|
||
|
||
insn &= ~ (bfd_vma) 0x303fff;
|
||
insn |= (((relocation >> 2) & 0xc000) << 6) | ((relocation >> 2) & 0x3fff);
|
||
bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
|
||
|
||
if ((bfd_signed_vma) relocation < - 0x40000
|
||
|| (bfd_signed_vma) relocation > 0x3ffff)
|
||
return bfd_reloc_overflow;
|
||
else
|
||
return bfd_reloc_ok;
|
||
}
|
||
|
||
/* Handle the HIX22 reloc. */
|
||
|
||
static bfd_reloc_status_type
|
||
sparc_elf_hix22_reloc (abfd,
|
||
reloc_entry,
|
||
symbol,
|
||
data,
|
||
input_section,
|
||
output_bfd,
|
||
error_message)
|
||
bfd *abfd;
|
||
arelent *reloc_entry;
|
||
asymbol *symbol;
|
||
PTR data;
|
||
asection *input_section;
|
||
bfd *output_bfd;
|
||
char **error_message ATTRIBUTE_UNUSED;
|
||
{
|
||
bfd_vma relocation;
|
||
bfd_vma insn;
|
||
bfd_reloc_status_type status;
|
||
|
||
status = init_insn_reloc (abfd, reloc_entry, symbol, data,
|
||
input_section, output_bfd, &relocation, &insn);
|
||
if (status != bfd_reloc_other)
|
||
return status;
|
||
|
||
relocation ^= MINUS_ONE;
|
||
insn = (insn &~ (bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
|
||
bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
|
||
|
||
if ((relocation & ~ (bfd_vma) 0xffffffff) != 0)
|
||
return bfd_reloc_overflow;
|
||
else
|
||
return bfd_reloc_ok;
|
||
}
|
||
|
||
/* Handle the LOX10 reloc. */
|
||
|
||
static bfd_reloc_status_type
|
||
sparc_elf_lox10_reloc (abfd,
|
||
reloc_entry,
|
||
symbol,
|
||
data,
|
||
input_section,
|
||
output_bfd,
|
||
error_message)
|
||
bfd *abfd;
|
||
arelent *reloc_entry;
|
||
asymbol *symbol;
|
||
PTR data;
|
||
asection *input_section;
|
||
bfd *output_bfd;
|
||
char **error_message ATTRIBUTE_UNUSED;
|
||
{
|
||
bfd_vma relocation;
|
||
bfd_vma insn;
|
||
bfd_reloc_status_type status;
|
||
|
||
status = init_insn_reloc (abfd, reloc_entry, symbol, data,
|
||
input_section, output_bfd, &relocation, &insn);
|
||
if (status != bfd_reloc_other)
|
||
return status;
|
||
|
||
insn = (insn &~ (bfd_vma) 0x1fff) | 0x1c00 | (relocation & 0x3ff);
|
||
bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
|
||
|
||
return bfd_reloc_ok;
|
||
}
|
||
|
||
/* PLT/GOT stuff */
|
||
|
||
/* Both the headers and the entries are icache aligned. */
|
||
#define PLT_ENTRY_SIZE 32
|
||
#define PLT_HEADER_SIZE (4 * PLT_ENTRY_SIZE)
|
||
#define LARGE_PLT_THRESHOLD 32768
|
||
#define GOT_RESERVED_ENTRIES 1
|
||
|
||
#define ELF_DYNAMIC_INTERPRETER "/usr/lib/sparcv9/ld.so.1"
|
||
|
||
/* Fill in the .plt section. */
|
||
|
||
static void
|
||
sparc64_elf_build_plt (output_bfd, contents, nentries)
|
||
bfd *output_bfd;
|
||
unsigned char *contents;
|
||
int nentries;
|
||
{
|
||
const unsigned int nop = 0x01000000;
|
||
int i, j;
|
||
|
||
/* The first four entries are reserved, and are initially undefined.
|
||
We fill them with `illtrap 0' to force ld.so to do something. */
|
||
|
||
for (i = 0; i < PLT_HEADER_SIZE/4; ++i)
|
||
bfd_put_32 (output_bfd, (bfd_vma) 0, contents+i*4);
|
||
|
||
/* The first 32768 entries are close enough to plt1 to get there via
|
||
a straight branch. */
|
||
|
||
for (i = 4; i < LARGE_PLT_THRESHOLD && i < nentries; ++i)
|
||
{
|
||
unsigned char *entry = contents + i * PLT_ENTRY_SIZE;
|
||
unsigned int sethi, ba;
|
||
|
||
/* sethi (. - plt0), %g1 */
|
||
sethi = 0x03000000 | (i * PLT_ENTRY_SIZE);
|
||
|
||
/* ba,a,pt %xcc, plt1 */
|
||
ba = 0x30680000 | (((contents+PLT_ENTRY_SIZE) - (entry+4)) / 4 & 0x7ffff);
|
||
|
||
bfd_put_32 (output_bfd, (bfd_vma) sethi, entry);
|
||
bfd_put_32 (output_bfd, (bfd_vma) ba, entry + 4);
|
||
bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 8);
|
||
bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 12);
|
||
bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 16);
|
||
bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 20);
|
||
bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 24);
|
||
bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 28);
|
||
}
|
||
|
||
/* Now the tricky bit. Entries 32768 and higher are grouped in blocks of
|
||
160: 160 entries and 160 pointers. This is to separate code from data,
|
||
which is much friendlier on the cache. */
|
||
|
||
for (; i < nentries; i += 160)
|
||
{
|
||
int block = (i + 160 <= nentries ? 160 : nentries - i);
|
||
for (j = 0; j < block; ++j)
|
||
{
|
||
unsigned char *entry, *ptr;
|
||
unsigned int ldx;
|
||
|
||
entry = contents + i*PLT_ENTRY_SIZE + j*4*6;
|
||
ptr = contents + i*PLT_ENTRY_SIZE + block*4*6 + j*8;
|
||
|
||
/* ldx [%o7 + ptr - (entry+4)], %g1 */
|
||
ldx = 0xc25be000 | ((ptr - (entry+4)) & 0x1fff);
|
||
|
||
/* mov %o7,%g5
|
||
call .+8
|
||
nop
|
||
ldx [%o7+P],%g1
|
||
jmpl %o7+%g1,%g1
|
||
mov %g5,%o7 */
|
||
bfd_put_32 (output_bfd, (bfd_vma) 0x8a10000f, entry);
|
||
bfd_put_32 (output_bfd, (bfd_vma) 0x40000002, entry + 4);
|
||
bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 8);
|
||
bfd_put_32 (output_bfd, (bfd_vma) ldx, entry + 12);
|
||
bfd_put_32 (output_bfd, (bfd_vma) 0x83c3c001, entry + 16);
|
||
bfd_put_32 (output_bfd, (bfd_vma) 0x9e100005, entry + 20);
|
||
|
||
bfd_put_64 (output_bfd, (bfd_vma) (contents - (entry + 4)), ptr);
|
||
}
|
||
}
|
||
}
|
||
|
||
/* Return the offset of a particular plt entry within the .plt section. */
|
||
|
||
static bfd_vma
|
||
sparc64_elf_plt_entry_offset (index)
|
||
bfd_vma index;
|
||
{
|
||
bfd_vma block, ofs;
|
||
|
||
if (index < LARGE_PLT_THRESHOLD)
|
||
return index * PLT_ENTRY_SIZE;
|
||
|
||
/* See above for details. */
|
||
|
||
block = (index - LARGE_PLT_THRESHOLD) / 160;
|
||
ofs = (index - LARGE_PLT_THRESHOLD) % 160;
|
||
|
||
return (LARGE_PLT_THRESHOLD + block * 160) * PLT_ENTRY_SIZE + ofs * 6 * 4;
|
||
}
|
||
|
||
static bfd_vma
|
||
sparc64_elf_plt_ptr_offset (index, max)
|
||
bfd_vma index;
|
||
bfd_vma max;
|
||
{
|
||
bfd_vma block, ofs, last;
|
||
|
||
BFD_ASSERT(index >= LARGE_PLT_THRESHOLD);
|
||
|
||
/* See above for details. */
|
||
|
||
block = (((index - LARGE_PLT_THRESHOLD) / 160) * 160) + LARGE_PLT_THRESHOLD;
|
||
ofs = index - block;
|
||
if (block + 160 > max)
|
||
last = (max - LARGE_PLT_THRESHOLD) % 160;
|
||
else
|
||
last = 160;
|
||
|
||
return (block * PLT_ENTRY_SIZE
|
||
+ last * 6*4
|
||
+ ofs * 8);
|
||
}
|
||
|
||
/* Look through the relocs for a section during the first phase, and
|
||
allocate space in the global offset table or procedure linkage
|
||
table. */
|
||
|
||
static bfd_boolean
|
||
sparc64_elf_check_relocs (abfd, info, sec, relocs)
|
||
bfd *abfd;
|
||
struct bfd_link_info *info;
|
||
asection *sec;
|
||
const Elf_Internal_Rela *relocs;
|
||
{
|
||
bfd *dynobj;
|
||
Elf_Internal_Shdr *symtab_hdr;
|
||
struct elf_link_hash_entry **sym_hashes;
|
||
bfd_vma *local_got_offsets;
|
||
const Elf_Internal_Rela *rel;
|
||
const Elf_Internal_Rela *rel_end;
|
||
asection *sgot;
|
||
asection *srelgot;
|
||
asection *sreloc;
|
||
|
||
if (info->relocateable || !(sec->flags & SEC_ALLOC))
|
||
return TRUE;
|
||
|
||
dynobj = elf_hash_table (info)->dynobj;
|
||
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
||
sym_hashes = elf_sym_hashes (abfd);
|
||
local_got_offsets = elf_local_got_offsets (abfd);
|
||
|
||
sgot = NULL;
|
||
srelgot = NULL;
|
||
sreloc = NULL;
|
||
|
||
rel_end = relocs + NUM_SHDR_ENTRIES (& elf_section_data (sec)->rel_hdr);
|
||
for (rel = relocs; rel < rel_end; rel++)
|
||
{
|
||
unsigned long r_symndx;
|
||
struct elf_link_hash_entry *h;
|
||
|
||
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];
|
||
|
||
switch (ELF64_R_TYPE_ID (rel->r_info))
|
||
{
|
||
case R_SPARC_GOT10:
|
||
case R_SPARC_GOT13:
|
||
case R_SPARC_GOT22:
|
||
/* This symbol requires a global offset table entry. */
|
||
|
||
if (dynobj == NULL)
|
||
{
|
||
/* Create the .got section. */
|
||
elf_hash_table (info)->dynobj = dynobj = abfd;
|
||
if (! _bfd_elf_create_got_section (dynobj, info))
|
||
return FALSE;
|
||
}
|
||
|
||
if (sgot == NULL)
|
||
{
|
||
sgot = bfd_get_section_by_name (dynobj, ".got");
|
||
BFD_ASSERT (sgot != NULL);
|
||
}
|
||
|
||
if (srelgot == NULL && (h != NULL || info->shared))
|
||
{
|
||
srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
|
||
if (srelgot == NULL)
|
||
{
|
||
srelgot = bfd_make_section (dynobj, ".rela.got");
|
||
if (srelgot == NULL
|
||
|| ! bfd_set_section_flags (dynobj, srelgot,
|
||
(SEC_ALLOC
|
||
| SEC_LOAD
|
||
| SEC_HAS_CONTENTS
|
||
| SEC_IN_MEMORY
|
||
| SEC_LINKER_CREATED
|
||
| SEC_READONLY))
|
||
|| ! bfd_set_section_alignment (dynobj, srelgot, 3))
|
||
return FALSE;
|
||
}
|
||
}
|
||
|
||
if (h != NULL)
|
||
{
|
||
if (h->got.offset != (bfd_vma) -1)
|
||
{
|
||
/* We have already allocated space in the .got. */
|
||
break;
|
||
}
|
||
h->got.offset = sgot->_raw_size;
|
||
|
||
/* Make sure this symbol is output as a dynamic symbol. */
|
||
if (h->dynindx == -1)
|
||
{
|
||
if (! bfd_elf64_link_record_dynamic_symbol (info, h))
|
||
return FALSE;
|
||
}
|
||
|
||
srelgot->_raw_size += sizeof (Elf64_External_Rela);
|
||
}
|
||
else
|
||
{
|
||
/* This is a global offset table entry for a local
|
||
symbol. */
|
||
if (local_got_offsets == NULL)
|
||
{
|
||
bfd_size_type size;
|
||
register unsigned int i;
|
||
|
||
size = symtab_hdr->sh_info;
|
||
size *= sizeof (bfd_vma);
|
||
local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
|
||
if (local_got_offsets == NULL)
|
||
return FALSE;
|
||
elf_local_got_offsets (abfd) = local_got_offsets;
|
||
for (i = 0; i < symtab_hdr->sh_info; i++)
|
||
local_got_offsets[i] = (bfd_vma) -1;
|
||
}
|
||
if (local_got_offsets[r_symndx] != (bfd_vma) -1)
|
||
{
|
||
/* We have already allocated space in the .got. */
|
||
break;
|
||
}
|
||
local_got_offsets[r_symndx] = sgot->_raw_size;
|
||
|
||
if (info->shared)
|
||
{
|
||
/* If we are generating a shared object, we need to
|
||
output a R_SPARC_RELATIVE reloc so that the
|
||
dynamic linker can adjust this GOT entry. */
|
||
srelgot->_raw_size += sizeof (Elf64_External_Rela);
|
||
}
|
||
}
|
||
|
||
sgot->_raw_size += 8;
|
||
|
||
#if 0
|
||
/* Doesn't work for 64-bit -fPIC, since sethi/or builds
|
||
unsigned numbers. If we permit ourselves to modify
|
||
code so we get sethi/xor, this could work.
|
||
Question: do we consider conditionally re-enabling
|
||
this for -fpic, once we know about object code models? */
|
||
/* If the .got section is more than 0x1000 bytes, we add
|
||
0x1000 to the value of _GLOBAL_OFFSET_TABLE_, so that 13
|
||
bit relocations have a greater chance of working. */
|
||
if (sgot->_raw_size >= 0x1000
|
||
&& elf_hash_table (info)->hgot->root.u.def.value == 0)
|
||
elf_hash_table (info)->hgot->root.u.def.value = 0x1000;
|
||
#endif
|
||
|
||
break;
|
||
|
||
case R_SPARC_WPLT30:
|
||
case R_SPARC_PLT32:
|
||
case R_SPARC_HIPLT22:
|
||
case R_SPARC_LOPLT10:
|
||
case R_SPARC_PCPLT32:
|
||
case R_SPARC_PCPLT22:
|
||
case R_SPARC_PCPLT10:
|
||
case R_SPARC_PLT64:
|
||
/* This symbol requires a procedure linkage table entry. We
|
||
actually build the entry in adjust_dynamic_symbol,
|
||
because this might be a case of linking PIC code without
|
||
linking in any dynamic objects, in which case we don't
|
||
need to generate a procedure linkage table after all. */
|
||
|
||
if (h == NULL)
|
||
{
|
||
/* It does not make sense to have a procedure linkage
|
||
table entry for a local symbol. */
|
||
bfd_set_error (bfd_error_bad_value);
|
||
return FALSE;
|
||
}
|
||
|
||
/* Make sure this symbol is output as a dynamic symbol. */
|
||
if (h->dynindx == -1)
|
||
{
|
||
if (! bfd_elf64_link_record_dynamic_symbol (info, h))
|
||
return FALSE;
|
||
}
|
||
|
||
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
|
||
if (ELF64_R_TYPE_ID (rel->r_info) != R_SPARC_PLT32
|
||
&& ELF64_R_TYPE_ID (rel->r_info) != R_SPARC_PLT64)
|
||
break;
|
||
/* Fall through. */
|
||
case R_SPARC_PC10:
|
||
case R_SPARC_PC22:
|
||
case R_SPARC_PC_HH22:
|
||
case R_SPARC_PC_HM10:
|
||
case R_SPARC_PC_LM22:
|
||
if (h != NULL
|
||
&& strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
|
||
break;
|
||
/* Fall through. */
|
||
case R_SPARC_DISP8:
|
||
case R_SPARC_DISP16:
|
||
case R_SPARC_DISP32:
|
||
case R_SPARC_DISP64:
|
||
case R_SPARC_WDISP30:
|
||
case R_SPARC_WDISP22:
|
||
case R_SPARC_WDISP19:
|
||
case R_SPARC_WDISP16:
|
||
if (h == NULL)
|
||
break;
|
||
/* Fall through. */
|
||
case R_SPARC_8:
|
||
case R_SPARC_16:
|
||
case R_SPARC_32:
|
||
case R_SPARC_HI22:
|
||
case R_SPARC_22:
|
||
case R_SPARC_13:
|
||
case R_SPARC_LO10:
|
||
case R_SPARC_UA32:
|
||
case R_SPARC_10:
|
||
case R_SPARC_11:
|
||
case R_SPARC_64:
|
||
case R_SPARC_OLO10:
|
||
case R_SPARC_HH22:
|
||
case R_SPARC_HM10:
|
||
case R_SPARC_LM22:
|
||
case R_SPARC_7:
|
||
case R_SPARC_5:
|
||
case R_SPARC_6:
|
||
case R_SPARC_HIX22:
|
||
case R_SPARC_LOX10:
|
||
case R_SPARC_H44:
|
||
case R_SPARC_M44:
|
||
case R_SPARC_L44:
|
||
case R_SPARC_UA64:
|
||
case R_SPARC_UA16:
|
||
/* When creating a shared object, we must copy these relocs
|
||
into the output file. We create a reloc section in
|
||
dynobj and make room for the reloc.
|
||
|
||
But don't do this for debugging sections -- this shows up
|
||
with DWARF2 -- first because they are not loaded, and
|
||
second because DWARF sez the debug info is not to be
|
||
biased by the load address. */
|
||
if (info->shared && (sec->flags & SEC_ALLOC))
|
||
{
|
||
if (sreloc == NULL)
|
||
{
|
||
const char *name;
|
||
|
||
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;
|
||
|
||
BFD_ASSERT (strncmp (name, ".rela", 5) == 0
|
||
&& strcmp (bfd_get_section_name (abfd, sec),
|
||
name + 5) == 0);
|
||
|
||
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;
|
||
}
|
||
if (sec->flags & SEC_READONLY)
|
||
info->flags |= DF_TEXTREL;
|
||
}
|
||
|
||
sreloc->_raw_size += sizeof (Elf64_External_Rela);
|
||
}
|
||
break;
|
||
|
||
case R_SPARC_REGISTER:
|
||
/* Nothing to do. */
|
||
break;
|
||
|
||
default:
|
||
(*_bfd_error_handler) (_("%s: check_relocs: unhandled reloc type %d"),
|
||
bfd_archive_filename (abfd),
|
||
ELF64_R_TYPE_ID (rel->r_info));
|
||
return FALSE;
|
||
}
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/* Hook called by the linker routine which adds symbols from an object
|
||
file. We use it for STT_REGISTER symbols. */
|
||
|
||
static bfd_boolean
|
||
sparc64_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
|
||
bfd *abfd;
|
||
struct bfd_link_info *info;
|
||
const Elf_Internal_Sym *sym;
|
||
const char **namep;
|
||
flagword *flagsp ATTRIBUTE_UNUSED;
|
||
asection **secp ATTRIBUTE_UNUSED;
|
||
bfd_vma *valp ATTRIBUTE_UNUSED;
|
||
{
|
||
static const char *const< |