Home | History | Annotate | Line # | Download | only in bfd
elf64-x86-64.c revision 1.1
      1  1.1  christos /* X86-64 specific support for ELF
      2  1.1  christos    Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
      3  1.1  christos    2010  Free Software Foundation, Inc.
      4  1.1  christos    Contributed by Jan Hubicka <jh (at) suse.cz>.
      5  1.1  christos 
      6  1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      7  1.1  christos 
      8  1.1  christos    This program is free software; you can redistribute it and/or modify
      9  1.1  christos    it under the terms of the GNU General Public License as published by
     10  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     11  1.1  christos    (at your option) any later version.
     12  1.1  christos 
     13  1.1  christos    This program is distributed in the hope that it will be useful,
     14  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  1.1  christos    GNU General Public License for more details.
     17  1.1  christos 
     18  1.1  christos    You should have received a copy of the GNU General Public License
     19  1.1  christos    along with this program; if not, write to the Free Software
     20  1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     21  1.1  christos    MA 02110-1301, USA.  */
     22  1.1  christos 
     23  1.1  christos #include "sysdep.h"
     24  1.1  christos #include "bfd.h"
     25  1.1  christos #include "bfdlink.h"
     26  1.1  christos #include "libbfd.h"
     27  1.1  christos #include "elf-bfd.h"
     28  1.1  christos #include "bfd_stdint.h"
     29  1.1  christos #include "objalloc.h"
     30  1.1  christos #include "hashtab.h"
     31  1.1  christos 
     32  1.1  christos #include "elf/x86-64.h"
     33  1.1  christos 
     34  1.1  christos /* In case we're on a 32-bit machine, construct a 64-bit "-1" value.  */
     35  1.1  christos #define MINUS_ONE (~ (bfd_vma) 0)
     36  1.1  christos 
     37  1.1  christos /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
     38  1.1  christos    identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
     39  1.1  christos    relocation type.  We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
     40  1.1  christos    since they are the same.  */
     41  1.1  christos 
     42  1.1  christos #define ABI_64_P(abfd) \
     43  1.1  christos   (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
     44  1.1  christos 
     45  1.1  christos /* The relocation "howto" table.  Order of fields:
     46  1.1  christos    type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
     47  1.1  christos    special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset.  */
     48  1.1  christos static reloc_howto_type x86_64_elf_howto_table[] =
     49  1.1  christos {
     50  1.1  christos   HOWTO(R_X86_64_NONE, 0, 0, 0, FALSE, 0, complain_overflow_dont,
     51  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_NONE",	FALSE, 0x00000000, 0x00000000,
     52  1.1  christos 	FALSE),
     53  1.1  christos   HOWTO(R_X86_64_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
     54  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_64", FALSE, MINUS_ONE, MINUS_ONE,
     55  1.1  christos 	FALSE),
     56  1.1  christos   HOWTO(R_X86_64_PC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
     57  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_PC32", FALSE, 0xffffffff, 0xffffffff,
     58  1.1  christos 	TRUE),
     59  1.1  christos   HOWTO(R_X86_64_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
     60  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_GOT32", FALSE, 0xffffffff, 0xffffffff,
     61  1.1  christos 	FALSE),
     62  1.1  christos   HOWTO(R_X86_64_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
     63  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_PLT32", FALSE, 0xffffffff, 0xffffffff,
     64  1.1  christos 	TRUE),
     65  1.1  christos   HOWTO(R_X86_64_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
     66  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_COPY", FALSE, 0xffffffff, 0xffffffff,
     67  1.1  christos 	FALSE),
     68  1.1  christos   HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
     69  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", FALSE, MINUS_ONE,
     70  1.1  christos 	MINUS_ONE, FALSE),
     71  1.1  christos   HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
     72  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", FALSE, MINUS_ONE,
     73  1.1  christos 	MINUS_ONE, FALSE),
     74  1.1  christos   HOWTO(R_X86_64_RELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
     75  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_RELATIVE", FALSE, MINUS_ONE,
     76  1.1  christos 	MINUS_ONE, FALSE),
     77  1.1  christos   HOWTO(R_X86_64_GOTPCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed,
     78  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", FALSE, 0xffffffff,
     79  1.1  christos 	0xffffffff, TRUE),
     80  1.1  christos   HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,
     81  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,
     82  1.1  christos 	FALSE),
     83  1.1  christos   HOWTO(R_X86_64_32S, 0, 2, 32, FALSE, 0, complain_overflow_signed,
     84  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_32S", FALSE, 0xffffffff, 0xffffffff,
     85  1.1  christos 	FALSE),
     86  1.1  christos   HOWTO(R_X86_64_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
     87  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_16", FALSE, 0xffff, 0xffff, FALSE),
     88  1.1  christos   HOWTO(R_X86_64_PC16,0, 1, 16, TRUE, 0, complain_overflow_bitfield,
     89  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_PC16", FALSE, 0xffff, 0xffff, TRUE),
     90  1.1  christos   HOWTO(R_X86_64_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
     91  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_8", FALSE, 0xff, 0xff, FALSE),
     92  1.1  christos   HOWTO(R_X86_64_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,
     93  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_PC8", FALSE, 0xff, 0xff, TRUE),
     94  1.1  christos   HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
     95  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", FALSE, MINUS_ONE,
     96  1.1  christos 	MINUS_ONE, FALSE),
     97  1.1  christos   HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
     98  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", FALSE, MINUS_ONE,
     99  1.1  christos 	MINUS_ONE, FALSE),
    100  1.1  christos   HOWTO(R_X86_64_TPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
    101  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_TPOFF64", FALSE, MINUS_ONE,
    102  1.1  christos 	MINUS_ONE, FALSE),
    103  1.1  christos   HOWTO(R_X86_64_TLSGD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
    104  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_TLSGD", FALSE, 0xffffffff,
    105  1.1  christos 	0xffffffff, TRUE),
    106  1.1  christos   HOWTO(R_X86_64_TLSLD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
    107  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_TLSLD", FALSE, 0xffffffff,
    108  1.1  christos 	0xffffffff, TRUE),
    109  1.1  christos   HOWTO(R_X86_64_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
    110  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", FALSE, 0xffffffff,
    111  1.1  christos 	0xffffffff, FALSE),
    112  1.1  christos   HOWTO(R_X86_64_GOTTPOFF, 0, 2, 32, TRUE, 0, complain_overflow_signed,
    113  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", FALSE, 0xffffffff,
    114  1.1  christos 	0xffffffff, TRUE),
    115  1.1  christos   HOWTO(R_X86_64_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
    116  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_TPOFF32", FALSE, 0xffffffff,
    117  1.1  christos 	0xffffffff, FALSE),
    118  1.1  christos   HOWTO(R_X86_64_PC64, 0, 4, 64, TRUE, 0, complain_overflow_bitfield,
    119  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_PC64", FALSE, MINUS_ONE, MINUS_ONE,
    120  1.1  christos 	TRUE),
    121  1.1  christos   HOWTO(R_X86_64_GOTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
    122  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_GOTOFF64",
    123  1.1  christos 	FALSE, MINUS_ONE, MINUS_ONE, FALSE),
    124  1.1  christos   HOWTO(R_X86_64_GOTPC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
    125  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_GOTPC32",
    126  1.1  christos 	FALSE, 0xffffffff, 0xffffffff, TRUE),
    127  1.1  christos   HOWTO(R_X86_64_GOT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
    128  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_GOT64", FALSE, MINUS_ONE, MINUS_ONE,
    129  1.1  christos 	FALSE),
    130  1.1  christos   HOWTO(R_X86_64_GOTPCREL64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
    131  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", FALSE, MINUS_ONE,
    132  1.1  christos 	MINUS_ONE, TRUE),
    133  1.1  christos   HOWTO(R_X86_64_GOTPC64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
    134  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_GOTPC64",
    135  1.1  christos 	FALSE, MINUS_ONE, MINUS_ONE, TRUE),
    136  1.1  christos   HOWTO(R_X86_64_GOTPLT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
    137  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", FALSE, MINUS_ONE,
    138  1.1  christos 	MINUS_ONE, FALSE),
    139  1.1  christos   HOWTO(R_X86_64_PLTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
    140  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", FALSE, MINUS_ONE,
    141  1.1  christos 	MINUS_ONE, FALSE),
    142  1.1  christos   EMPTY_HOWTO (32),
    143  1.1  christos   EMPTY_HOWTO (33),
    144  1.1  christos   HOWTO(R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, TRUE, 0,
    145  1.1  christos 	complain_overflow_bitfield, bfd_elf_generic_reloc,
    146  1.1  christos 	"R_X86_64_GOTPC32_TLSDESC",
    147  1.1  christos 	FALSE, 0xffffffff, 0xffffffff, TRUE),
    148  1.1  christos   HOWTO(R_X86_64_TLSDESC_CALL, 0, 0, 0, FALSE, 0,
    149  1.1  christos 	complain_overflow_dont, bfd_elf_generic_reloc,
    150  1.1  christos 	"R_X86_64_TLSDESC_CALL",
    151  1.1  christos 	FALSE, 0, 0, FALSE),
    152  1.1  christos   HOWTO(R_X86_64_TLSDESC, 0, 4, 64, FALSE, 0,
    153  1.1  christos 	complain_overflow_bitfield, bfd_elf_generic_reloc,
    154  1.1  christos 	"R_X86_64_TLSDESC",
    155  1.1  christos 	FALSE, MINUS_ONE, MINUS_ONE, FALSE),
    156  1.1  christos   HOWTO(R_X86_64_IRELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
    157  1.1  christos 	bfd_elf_generic_reloc, "R_X86_64_IRELATIVE", FALSE, MINUS_ONE,
    158  1.1  christos 	MINUS_ONE, FALSE),
    159  1.1  christos 
    160  1.1  christos   /* We have a gap in the reloc numbers here.
    161  1.1  christos      R_X86_64_standard counts the number up to this point, and
    162  1.1  christos      R_X86_64_vt_offset is the value to subtract from a reloc type of
    163  1.1  christos      R_X86_64_GNU_VT* to form an index into this table.  */
    164  1.1  christos #define R_X86_64_standard (R_X86_64_IRELATIVE + 1)
    165  1.1  christos #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
    166  1.1  christos 
    167  1.1  christos /* GNU extension to record C++ vtable hierarchy.  */
    168  1.1  christos   HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, FALSE, 0, complain_overflow_dont,
    169  1.1  christos 	 NULL, "R_X86_64_GNU_VTINHERIT", FALSE, 0, 0, FALSE),
    170  1.1  christos 
    171  1.1  christos /* GNU extension to record C++ vtable member usage.  */
    172  1.1  christos   HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont,
    173  1.1  christos 	 _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0,
    174  1.1  christos 	 FALSE)
    175  1.1  christos };
    176  1.1  christos 
    177  1.1  christos #define IS_X86_64_PCREL_TYPE(TYPE)	\
    178  1.1  christos   (   ((TYPE) == R_X86_64_PC8)		\
    179  1.1  christos    || ((TYPE) == R_X86_64_PC16)		\
    180  1.1  christos    || ((TYPE) == R_X86_64_PC32)		\
    181  1.1  christos    || ((TYPE) == R_X86_64_PC64))
    182  1.1  christos 
    183  1.1  christos /* Map BFD relocs to the x86_64 elf relocs.  */
    184  1.1  christos struct elf_reloc_map
    185  1.1  christos {
    186  1.1  christos   bfd_reloc_code_real_type bfd_reloc_val;
    187  1.1  christos   unsigned char elf_reloc_val;
    188  1.1  christos };
    189  1.1  christos 
    190  1.1  christos static const struct elf_reloc_map x86_64_reloc_map[] =
    191  1.1  christos {
    192  1.1  christos   { BFD_RELOC_NONE,		R_X86_64_NONE, },
    193  1.1  christos   { BFD_RELOC_64,		R_X86_64_64,   },
    194  1.1  christos   { BFD_RELOC_32_PCREL,		R_X86_64_PC32, },
    195  1.1  christos   { BFD_RELOC_X86_64_GOT32,	R_X86_64_GOT32,},
    196  1.1  christos   { BFD_RELOC_X86_64_PLT32,	R_X86_64_PLT32,},
    197  1.1  christos   { BFD_RELOC_X86_64_COPY,	R_X86_64_COPY, },
    198  1.1  christos   { BFD_RELOC_X86_64_GLOB_DAT,	R_X86_64_GLOB_DAT, },
    199  1.1  christos   { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
    200  1.1  christos   { BFD_RELOC_X86_64_RELATIVE,	R_X86_64_RELATIVE, },
    201  1.1  christos   { BFD_RELOC_X86_64_GOTPCREL,	R_X86_64_GOTPCREL, },
    202  1.1  christos   { BFD_RELOC_32,		R_X86_64_32, },
    203  1.1  christos   { BFD_RELOC_X86_64_32S,	R_X86_64_32S, },
    204  1.1  christos   { BFD_RELOC_16,		R_X86_64_16, },
    205  1.1  christos   { BFD_RELOC_16_PCREL,		R_X86_64_PC16, },
    206  1.1  christos   { BFD_RELOC_8,		R_X86_64_8, },
    207  1.1  christos   { BFD_RELOC_8_PCREL,		R_X86_64_PC8, },
    208  1.1  christos   { BFD_RELOC_X86_64_DTPMOD64,	R_X86_64_DTPMOD64, },
    209  1.1  christos   { BFD_RELOC_X86_64_DTPOFF64,	R_X86_64_DTPOFF64, },
    210  1.1  christos   { BFD_RELOC_X86_64_TPOFF64,	R_X86_64_TPOFF64, },
    211  1.1  christos   { BFD_RELOC_X86_64_TLSGD,	R_X86_64_TLSGD, },
    212  1.1  christos   { BFD_RELOC_X86_64_TLSLD,	R_X86_64_TLSLD, },
    213  1.1  christos   { BFD_RELOC_X86_64_DTPOFF32,	R_X86_64_DTPOFF32, },
    214  1.1  christos   { BFD_RELOC_X86_64_GOTTPOFF,	R_X86_64_GOTTPOFF, },
    215  1.1  christos   { BFD_RELOC_X86_64_TPOFF32,	R_X86_64_TPOFF32, },
    216  1.1  christos   { BFD_RELOC_64_PCREL,		R_X86_64_PC64, },
    217  1.1  christos   { BFD_RELOC_X86_64_GOTOFF64,	R_X86_64_GOTOFF64, },
    218  1.1  christos   { BFD_RELOC_X86_64_GOTPC32,	R_X86_64_GOTPC32, },
    219  1.1  christos   { BFD_RELOC_X86_64_GOT64,	R_X86_64_GOT64, },
    220  1.1  christos   { BFD_RELOC_X86_64_GOTPCREL64,R_X86_64_GOTPCREL64, },
    221  1.1  christos   { BFD_RELOC_X86_64_GOTPC64,	R_X86_64_GOTPC64, },
    222  1.1  christos   { BFD_RELOC_X86_64_GOTPLT64,	R_X86_64_GOTPLT64, },
    223  1.1  christos   { BFD_RELOC_X86_64_PLTOFF64,	R_X86_64_PLTOFF64, },
    224  1.1  christos   { BFD_RELOC_X86_64_GOTPC32_TLSDESC, R_X86_64_GOTPC32_TLSDESC, },
    225  1.1  christos   { BFD_RELOC_X86_64_TLSDESC_CALL, R_X86_64_TLSDESC_CALL, },
    226  1.1  christos   { BFD_RELOC_X86_64_TLSDESC,	R_X86_64_TLSDESC, },
    227  1.1  christos   { BFD_RELOC_X86_64_IRELATIVE,	R_X86_64_IRELATIVE, },
    228  1.1  christos   { BFD_RELOC_VTABLE_INHERIT,	R_X86_64_GNU_VTINHERIT, },
    229  1.1  christos   { BFD_RELOC_VTABLE_ENTRY,	R_X86_64_GNU_VTENTRY, },
    230  1.1  christos };
    231  1.1  christos 
    232  1.1  christos static reloc_howto_type *
    233  1.1  christos elf_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type)
    234  1.1  christos {
    235  1.1  christos   unsigned i;
    236  1.1  christos 
    237  1.1  christos   if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
    238  1.1  christos       || r_type >= (unsigned int) R_X86_64_max)
    239  1.1  christos     {
    240  1.1  christos       if (r_type >= (unsigned int) R_X86_64_standard)
    241  1.1  christos 	{
    242  1.1  christos 	  (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
    243  1.1  christos 				 abfd, (int) r_type);
    244  1.1  christos 	  r_type = R_X86_64_NONE;
    245  1.1  christos 	}
    246  1.1  christos       i = r_type;
    247  1.1  christos     }
    248  1.1  christos   else
    249  1.1  christos     i = r_type - (unsigned int) R_X86_64_vt_offset;
    250  1.1  christos   BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type);
    251  1.1  christos   return &x86_64_elf_howto_table[i];
    252  1.1  christos }
    253  1.1  christos 
    254  1.1  christos /* Given a BFD reloc type, return a HOWTO structure.  */
    255  1.1  christos static reloc_howto_type *
    256  1.1  christos elf_x86_64_reloc_type_lookup (bfd *abfd,
    257  1.1  christos 			      bfd_reloc_code_real_type code)
    258  1.1  christos {
    259  1.1  christos   unsigned int i;
    260  1.1  christos 
    261  1.1  christos   for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
    262  1.1  christos        i++)
    263  1.1  christos     {
    264  1.1  christos       if (x86_64_reloc_map[i].bfd_reloc_val == code)
    265  1.1  christos 	return elf_x86_64_rtype_to_howto (abfd,
    266  1.1  christos 					  x86_64_reloc_map[i].elf_reloc_val);
    267  1.1  christos     }
    268  1.1  christos   return 0;
    269  1.1  christos }
    270  1.1  christos 
    271  1.1  christos static reloc_howto_type *
    272  1.1  christos elf_x86_64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    273  1.1  christos 			      const char *r_name)
    274  1.1  christos {
    275  1.1  christos   unsigned int i;
    276  1.1  christos 
    277  1.1  christos   for (i = 0;
    278  1.1  christos        i < (sizeof (x86_64_elf_howto_table)
    279  1.1  christos 	    / sizeof (x86_64_elf_howto_table[0]));
    280  1.1  christos        i++)
    281  1.1  christos     if (x86_64_elf_howto_table[i].name != NULL
    282  1.1  christos 	&& strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0)
    283  1.1  christos       return &x86_64_elf_howto_table[i];
    284  1.1  christos 
    285  1.1  christos   return NULL;
    286  1.1  christos }
    287  1.1  christos 
    288  1.1  christos /* Given an x86_64 ELF reloc type, fill in an arelent structure.  */
    289  1.1  christos 
    290  1.1  christos static void
    291  1.1  christos elf_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
    292  1.1  christos 			  Elf_Internal_Rela *dst)
    293  1.1  christos {
    294  1.1  christos   unsigned r_type;
    295  1.1  christos 
    296  1.1  christos   r_type = ELF32_R_TYPE (dst->r_info);
    297  1.1  christos   cache_ptr->howto = elf_x86_64_rtype_to_howto (abfd, r_type);
    298  1.1  christos   BFD_ASSERT (r_type == cache_ptr->howto->type);
    299  1.1  christos }
    300  1.1  christos 
    301  1.1  christos /* Support for core dump NOTE sections.  */
    303  1.1  christos static bfd_boolean
    304  1.1  christos elf_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
    305  1.1  christos {
    306  1.1  christos   int offset;
    307  1.1  christos   size_t size;
    308  1.1  christos 
    309  1.1  christos   switch (note->descsz)
    310  1.1  christos     {
    311  1.1  christos       default:
    312  1.1  christos 	return FALSE;
    313  1.1  christos 
    314  1.1  christos       case 336:		/* sizeof(istruct elf_prstatus) on Linux/x86_64 */
    315  1.1  christos 	/* pr_cursig */
    316  1.1  christos 	elf_tdata (abfd)->core_signal
    317  1.1  christos 	  = bfd_get_16 (abfd, note->descdata + 12);
    318  1.1  christos 
    319  1.1  christos 	/* pr_pid */
    320  1.1  christos 	elf_tdata (abfd)->core_lwpid
    321  1.1  christos 	  = bfd_get_32 (abfd, note->descdata + 32);
    322  1.1  christos 
    323  1.1  christos 	/* pr_reg */
    324  1.1  christos 	offset = 112;
    325  1.1  christos 	size = 216;
    326  1.1  christos 
    327  1.1  christos 	break;
    328  1.1  christos     }
    329  1.1  christos 
    330  1.1  christos   /* Make a ".reg/999" section.  */
    331  1.1  christos   return _bfd_elfcore_make_pseudosection (abfd, ".reg",
    332  1.1  christos 					  size, note->descpos + offset);
    333  1.1  christos }
    334  1.1  christos 
    335  1.1  christos static bfd_boolean
    336  1.1  christos elf_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
    337  1.1  christos {
    338  1.1  christos   switch (note->descsz)
    339  1.1  christos     {
    340  1.1  christos       default:
    341  1.1  christos 	return FALSE;
    342  1.1  christos 
    343  1.1  christos       case 136:		/* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
    344  1.1  christos 	elf_tdata (abfd)->core_pid
    345  1.1  christos 	  = bfd_get_32 (abfd, note->descdata + 24);
    346  1.1  christos 	elf_tdata (abfd)->core_program
    347  1.1  christos 	 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
    348  1.1  christos 	elf_tdata (abfd)->core_command
    349  1.1  christos 	 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
    350  1.1  christos     }
    351  1.1  christos 
    352  1.1  christos   /* Note that for some reason, a spurious space is tacked
    353  1.1  christos      onto the end of the args in some (at least one anyway)
    354  1.1  christos      implementations, so strip it off if it exists.  */
    355  1.1  christos 
    356  1.1  christos   {
    357  1.1  christos     char *command = elf_tdata (abfd)->core_command;
    358  1.1  christos     int n = strlen (command);
    359  1.1  christos 
    360  1.1  christos     if (0 < n && command[n - 1] == ' ')
    361  1.1  christos       command[n - 1] = '\0';
    362  1.1  christos   }
    363  1.1  christos 
    364  1.1  christos   return TRUE;
    365  1.1  christos }
    366  1.1  christos 
    367  1.1  christos /* Functions for the x86-64 ELF linker.	 */
    369  1.1  christos 
    370  1.1  christos /* The name of the dynamic interpreter.	 This is put in the .interp
    371  1.1  christos    section.  */
    372  1.1  christos 
    373  1.1  christos #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
    374  1.1  christos #define ELF32_DYNAMIC_INTERPRETER "/lib/ld32.so.1"
    375  1.1  christos 
    376  1.1  christos /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
    377  1.1  christos    copying dynamic variables from a shared lib into an app's dynbss
    378  1.1  christos    section, and instead use a dynamic relocation to point into the
    379  1.1  christos    shared lib.  */
    380  1.1  christos #define ELIMINATE_COPY_RELOCS 1
    381  1.1  christos 
    382  1.1  christos /* The size in bytes of an entry in the global offset table.  */
    383  1.1  christos 
    384  1.1  christos #define GOT_ENTRY_SIZE 8
    385  1.1  christos 
    386  1.1  christos /* The size in bytes of an entry in the procedure linkage table.  */
    387  1.1  christos 
    388  1.1  christos #define PLT_ENTRY_SIZE 16
    389  1.1  christos 
    390  1.1  christos /* The first entry in a procedure linkage table looks like this.  See the
    391  1.1  christos    SVR4 ABI i386 supplement and the x86-64 ABI to see how this works.  */
    392  1.1  christos 
    393  1.1  christos static const bfd_byte elf_x86_64_plt0_entry[PLT_ENTRY_SIZE] =
    394  1.1  christos {
    395  1.1  christos   0xff, 0x35, 8, 0, 0, 0,	/* pushq GOT+8(%rip)  */
    396  1.1  christos   0xff, 0x25, 16, 0, 0, 0,	/* jmpq *GOT+16(%rip) */
    397  1.1  christos   0x0f, 0x1f, 0x40, 0x00	/* nopl 0(%rax)       */
    398  1.1  christos };
    399  1.1  christos 
    400  1.1  christos /* Subsequent entries in a procedure linkage table look like this.  */
    401  1.1  christos 
    402  1.1  christos static const bfd_byte elf_x86_64_plt_entry[PLT_ENTRY_SIZE] =
    403  1.1  christos {
    404  1.1  christos   0xff, 0x25,	/* jmpq *name@GOTPC(%rip) */
    405  1.1  christos   0, 0, 0, 0,	/* replaced with offset to this symbol in .got.	 */
    406  1.1  christos   0x68,		/* pushq immediate */
    407  1.1  christos   0, 0, 0, 0,	/* replaced with index into relocation table.  */
    408  1.1  christos   0xe9,		/* jmp relative */
    409  1.1  christos   0, 0, 0, 0	/* replaced with offset to start of .plt0.  */
    410  1.1  christos };
    411  1.1  christos 
    412  1.1  christos /* x86-64 ELF linker hash entry.  */
    413  1.1  christos 
    414  1.1  christos struct elf_x86_64_link_hash_entry
    415  1.1  christos {
    416  1.1  christos   struct elf_link_hash_entry elf;
    417  1.1  christos 
    418  1.1  christos   /* Track dynamic relocs copied for this symbol.  */
    419  1.1  christos   struct elf_dyn_relocs *dyn_relocs;
    420  1.1  christos 
    421  1.1  christos #define GOT_UNKNOWN	0
    422  1.1  christos #define GOT_NORMAL	1
    423  1.1  christos #define GOT_TLS_GD	2
    424  1.1  christos #define GOT_TLS_IE	3
    425  1.1  christos #define GOT_TLS_GDESC	4
    426  1.1  christos #define GOT_TLS_GD_BOTH_P(type) \
    427  1.1  christos   ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
    428  1.1  christos #define GOT_TLS_GD_P(type) \
    429  1.1  christos   ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
    430  1.1  christos #define GOT_TLS_GDESC_P(type) \
    431  1.1  christos   ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
    432  1.1  christos #define GOT_TLS_GD_ANY_P(type) \
    433  1.1  christos   (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
    434  1.1  christos   unsigned char tls_type;
    435  1.1  christos 
    436  1.1  christos   /* Offset of the GOTPLT entry reserved for the TLS descriptor,
    437  1.1  christos      starting at the end of the jump table.  */
    438  1.1  christos   bfd_vma tlsdesc_got;
    439  1.1  christos };
    440  1.1  christos 
    441  1.1  christos #define elf_x86_64_hash_entry(ent) \
    442  1.1  christos   ((struct elf_x86_64_link_hash_entry *)(ent))
    443  1.1  christos 
    444  1.1  christos struct elf_x86_64_obj_tdata
    445  1.1  christos {
    446  1.1  christos   struct elf_obj_tdata root;
    447  1.1  christos 
    448  1.1  christos   /* tls_type for each local got entry.  */
    449  1.1  christos   char *local_got_tls_type;
    450  1.1  christos 
    451  1.1  christos   /* GOTPLT entries for TLS descriptors.  */
    452  1.1  christos   bfd_vma *local_tlsdesc_gotent;
    453  1.1  christos };
    454  1.1  christos 
    455  1.1  christos #define elf_x86_64_tdata(abfd) \
    456  1.1  christos   ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
    457  1.1  christos 
    458  1.1  christos #define elf_x86_64_local_got_tls_type(abfd) \
    459  1.1  christos   (elf_x86_64_tdata (abfd)->local_got_tls_type)
    460  1.1  christos 
    461  1.1  christos #define elf_x86_64_local_tlsdesc_gotent(abfd) \
    462  1.1  christos   (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
    463  1.1  christos 
    464  1.1  christos #define is_x86_64_elf(bfd)				\
    465  1.1  christos   (bfd_get_flavour (bfd) == bfd_target_elf_flavour	\
    466  1.1  christos    && elf_tdata (bfd) != NULL				\
    467  1.1  christos    && elf_object_id (bfd) == X86_64_ELF_DATA)
    468  1.1  christos 
    469  1.1  christos static bfd_boolean
    470  1.1  christos elf_x86_64_mkobject (bfd *abfd)
    471  1.1  christos {
    472  1.1  christos   return bfd_elf_allocate_object (abfd, sizeof (struct elf_x86_64_obj_tdata),
    473  1.1  christos 				  X86_64_ELF_DATA);
    474  1.1  christos }
    475  1.1  christos 
    476  1.1  christos /* x86-64 ELF linker hash table.  */
    477  1.1  christos 
    478  1.1  christos struct elf_x86_64_link_hash_table
    479  1.1  christos {
    480  1.1  christos   struct elf_link_hash_table elf;
    481  1.1  christos 
    482  1.1  christos   /* Short-cuts to get to dynamic linker sections.  */
    483  1.1  christos   asection *sdynbss;
    484  1.1  christos   asection *srelbss;
    485  1.1  christos 
    486  1.1  christos   union
    487  1.1  christos   {
    488  1.1  christos     bfd_signed_vma refcount;
    489  1.1  christos     bfd_vma offset;
    490  1.1  christos   } tls_ld_got;
    491  1.1  christos 
    492  1.1  christos   /* The amount of space used by the jump slots in the GOT.  */
    493  1.1  christos   bfd_vma sgotplt_jump_table_size;
    494  1.1  christos 
    495  1.1  christos   /* Small local sym cache.  */
    496  1.1  christos   struct sym_cache sym_cache;
    497  1.1  christos 
    498  1.1  christos   bfd_vma (*r_info) (bfd_vma, bfd_vma);
    499  1.1  christos   bfd_vma (*r_sym) (bfd_vma);
    500  1.1  christos   unsigned int pointer_r_type;
    501  1.1  christos   const char *dynamic_interpreter;
    502  1.1  christos   int dynamic_interpreter_size;
    503  1.1  christos 
    504  1.1  christos   /* _TLS_MODULE_BASE_ symbol.  */
    505  1.1  christos   struct bfd_link_hash_entry *tls_module_base;
    506  1.1  christos 
    507  1.1  christos   /* Used by local STT_GNU_IFUNC symbols.  */
    508  1.1  christos   htab_t loc_hash_table;
    509  1.1  christos   void * loc_hash_memory;
    510  1.1  christos 
    511  1.1  christos   /* The offset into splt of the PLT entry for the TLS descriptor
    512  1.1  christos      resolver.  Special values are 0, if not necessary (or not found
    513  1.1  christos      to be necessary yet), and -1 if needed but not determined
    514  1.1  christos      yet.  */
    515  1.1  christos   bfd_vma tlsdesc_plt;
    516  1.1  christos   /* The offset into sgot of the GOT entry used by the PLT entry
    517  1.1  christos      above.  */
    518  1.1  christos   bfd_vma tlsdesc_got;
    519  1.1  christos };
    520  1.1  christos 
    521  1.1  christos /* Get the x86-64 ELF linker hash table from a link_info structure.  */
    522  1.1  christos 
    523  1.1  christos #define elf_x86_64_hash_table(p) \
    524  1.1  christos   (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
    525  1.1  christos   == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
    526  1.1  christos 
    527  1.1  christos #define elf_x86_64_compute_jump_table_size(htab) \
    528  1.1  christos   ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
    529  1.1  christos 
    530  1.1  christos /* Create an entry in an x86-64 ELF linker hash table.	*/
    531  1.1  christos 
    532  1.1  christos static struct bfd_hash_entry *
    533  1.1  christos elf_x86_64_link_hash_newfunc (struct bfd_hash_entry *entry,
    534  1.1  christos 			      struct bfd_hash_table *table,
    535  1.1  christos 			      const char *string)
    536  1.1  christos {
    537  1.1  christos   /* Allocate the structure if it has not already been allocated by a
    538  1.1  christos      subclass.  */
    539  1.1  christos   if (entry == NULL)
    540  1.1  christos     {
    541  1.1  christos       entry = (struct bfd_hash_entry *)
    542  1.1  christos           bfd_hash_allocate (table,
    543  1.1  christos                              sizeof (struct elf_x86_64_link_hash_entry));
    544  1.1  christos       if (entry == NULL)
    545  1.1  christos 	return entry;
    546  1.1  christos     }
    547  1.1  christos 
    548  1.1  christos   /* Call the allocation method of the superclass.  */
    549  1.1  christos   entry = _bfd_elf_link_hash_newfunc (entry, table, string);
    550  1.1  christos   if (entry != NULL)
    551  1.1  christos     {
    552  1.1  christos       struct elf_x86_64_link_hash_entry *eh;
    553  1.1  christos 
    554  1.1  christos       eh = (struct elf_x86_64_link_hash_entry *) entry;
    555  1.1  christos       eh->dyn_relocs = NULL;
    556  1.1  christos       eh->tls_type = GOT_UNKNOWN;
    557  1.1  christos       eh->tlsdesc_got = (bfd_vma) -1;
    558  1.1  christos     }
    559  1.1  christos 
    560  1.1  christos   return entry;
    561  1.1  christos }
    562  1.1  christos 
    563  1.1  christos /* Compute a hash of a local hash entry.  We use elf_link_hash_entry
    564  1.1  christos   for local symbol so that we can handle local STT_GNU_IFUNC symbols
    565  1.1  christos   as global symbol.  We reuse indx and dynstr_index for local symbol
    566  1.1  christos   hash since they aren't used by global symbols in this backend.  */
    567  1.1  christos 
    568  1.1  christos static hashval_t
    569  1.1  christos elf_x86_64_local_htab_hash (const void *ptr)
    570  1.1  christos {
    571  1.1  christos   struct elf_link_hash_entry *h
    572  1.1  christos     = (struct elf_link_hash_entry *) ptr;
    573  1.1  christos   return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
    574  1.1  christos }
    575  1.1  christos 
    576  1.1  christos /* Compare local hash entries.  */
    577  1.1  christos 
    578  1.1  christos static int
    579  1.1  christos elf_x86_64_local_htab_eq (const void *ptr1, const void *ptr2)
    580  1.1  christos {
    581  1.1  christos   struct elf_link_hash_entry *h1
    582  1.1  christos      = (struct elf_link_hash_entry *) ptr1;
    583  1.1  christos   struct elf_link_hash_entry *h2
    584  1.1  christos     = (struct elf_link_hash_entry *) ptr2;
    585  1.1  christos 
    586  1.1  christos   return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
    587  1.1  christos }
    588  1.1  christos 
    589  1.1  christos /* Find and/or create a hash entry for local symbol.  */
    590  1.1  christos 
    591  1.1  christos static struct elf_link_hash_entry *
    592  1.1  christos elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table *htab,
    593  1.1  christos 			       bfd *abfd, const Elf_Internal_Rela *rel,
    594  1.1  christos 			       bfd_boolean create)
    595  1.1  christos {
    596  1.1  christos   struct elf_x86_64_link_hash_entry e, *ret;
    597  1.1  christos   asection *sec = abfd->sections;
    598  1.1  christos   hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
    599  1.1  christos 				       htab->r_sym (rel->r_info));
    600  1.1  christos   void **slot;
    601  1.1  christos 
    602  1.1  christos   e.elf.indx = sec->id;
    603  1.1  christos   e.elf.dynstr_index = htab->r_sym (rel->r_info);
    604  1.1  christos   slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
    605  1.1  christos 				   create ? INSERT : NO_INSERT);
    606  1.1  christos 
    607  1.1  christos   if (!slot)
    608  1.1  christos     return NULL;
    609  1.1  christos 
    610  1.1  christos   if (*slot)
    611  1.1  christos     {
    612  1.1  christos       ret = (struct elf_x86_64_link_hash_entry *) *slot;
    613  1.1  christos       return &ret->elf;
    614  1.1  christos     }
    615  1.1  christos 
    616  1.1  christos   ret = (struct elf_x86_64_link_hash_entry *)
    617  1.1  christos 	objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
    618  1.1  christos 			sizeof (struct elf_x86_64_link_hash_entry));
    619  1.1  christos   if (ret)
    620  1.1  christos     {
    621  1.1  christos       memset (ret, 0, sizeof (*ret));
    622  1.1  christos       ret->elf.indx = sec->id;
    623  1.1  christos       ret->elf.dynstr_index = htab->r_sym (rel->r_info);
    624  1.1  christos       ret->elf.dynindx = -1;
    625  1.1  christos       *slot = ret;
    626  1.1  christos     }
    627  1.1  christos   return &ret->elf;
    628  1.1  christos }
    629  1.1  christos 
    630  1.1  christos /* Create an X86-64 ELF linker hash table.  */
    631  1.1  christos 
    632  1.1  christos static struct bfd_link_hash_table *
    633  1.1  christos elf_x86_64_link_hash_table_create (bfd *abfd)
    634  1.1  christos {
    635  1.1  christos   struct elf_x86_64_link_hash_table *ret;
    636  1.1  christos   bfd_size_type amt = sizeof (struct elf_x86_64_link_hash_table);
    637  1.1  christos 
    638  1.1  christos   ret = (struct elf_x86_64_link_hash_table *) bfd_malloc (amt);
    639  1.1  christos   if (ret == NULL)
    640  1.1  christos     return NULL;
    641  1.1  christos 
    642  1.1  christos   if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
    643  1.1  christos 				      elf_x86_64_link_hash_newfunc,
    644  1.1  christos 				      sizeof (struct elf_x86_64_link_hash_entry),
    645  1.1  christos 				      X86_64_ELF_DATA))
    646  1.1  christos     {
    647  1.1  christos       free (ret);
    648  1.1  christos       return NULL;
    649  1.1  christos     }
    650  1.1  christos 
    651  1.1  christos   ret->sdynbss = NULL;
    652  1.1  christos   ret->srelbss = NULL;
    653  1.1  christos   ret->sym_cache.abfd = NULL;
    654  1.1  christos   ret->tlsdesc_plt = 0;
    655  1.1  christos   ret->tlsdesc_got = 0;
    656  1.1  christos   ret->tls_ld_got.refcount = 0;
    657  1.1  christos   ret->sgotplt_jump_table_size = 0;
    658  1.1  christos   ret->tls_module_base = NULL;
    659  1.1  christos 
    660  1.1  christos   if (ABI_64_P (abfd))
    661  1.1  christos     {
    662  1.1  christos       ret->r_info = elf64_r_info;
    663  1.1  christos       ret->r_sym = elf64_r_sym;
    664  1.1  christos       ret->pointer_r_type = R_X86_64_64;
    665  1.1  christos       ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
    666  1.1  christos       ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
    667  1.1  christos     }
    668  1.1  christos   else
    669  1.1  christos     {
    670  1.1  christos       ret->r_info = elf32_r_info;
    671  1.1  christos       ret->r_sym = elf32_r_sym;
    672  1.1  christos       ret->pointer_r_type = R_X86_64_32;
    673  1.1  christos       ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER;
    674  1.1  christos       ret->dynamic_interpreter_size = sizeof ELF32_DYNAMIC_INTERPRETER;
    675  1.1  christos     }
    676  1.1  christos 
    677  1.1  christos   ret->loc_hash_table = htab_try_create (1024,
    678  1.1  christos 					 elf_x86_64_local_htab_hash,
    679  1.1  christos 					 elf_x86_64_local_htab_eq,
    680  1.1  christos 					 NULL);
    681  1.1  christos   ret->loc_hash_memory = objalloc_create ();
    682  1.1  christos   if (!ret->loc_hash_table || !ret->loc_hash_memory)
    683  1.1  christos     {
    684  1.1  christos       free (ret);
    685  1.1  christos       return NULL;
    686  1.1  christos     }
    687  1.1  christos 
    688  1.1  christos   return &ret->elf.root;
    689  1.1  christos }
    690  1.1  christos 
    691  1.1  christos /* Destroy an X86-64 ELF linker hash table.  */
    692  1.1  christos 
    693  1.1  christos static void
    694  1.1  christos elf_x86_64_link_hash_table_free (struct bfd_link_hash_table *hash)
    695  1.1  christos {
    696  1.1  christos   struct elf_x86_64_link_hash_table *htab
    697  1.1  christos     = (struct elf_x86_64_link_hash_table *) hash;
    698  1.1  christos 
    699  1.1  christos   if (htab->loc_hash_table)
    700  1.1  christos     htab_delete (htab->loc_hash_table);
    701  1.1  christos   if (htab->loc_hash_memory)
    702  1.1  christos     objalloc_free ((struct objalloc *) htab->loc_hash_memory);
    703  1.1  christos   _bfd_generic_link_hash_table_free (hash);
    704  1.1  christos }
    705  1.1  christos 
    706  1.1  christos /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
    707  1.1  christos    .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
    708  1.1  christos    hash table.  */
    709  1.1  christos 
    710  1.1  christos static bfd_boolean
    711  1.1  christos elf_x86_64_create_dynamic_sections (bfd *dynobj,
    712  1.1  christos 				    struct bfd_link_info *info)
    713  1.1  christos {
    714  1.1  christos   struct elf_x86_64_link_hash_table *htab;
    715  1.1  christos 
    716  1.1  christos   if (!_bfd_elf_create_dynamic_sections (dynobj, info))
    717  1.1  christos     return FALSE;
    718  1.1  christos 
    719  1.1  christos   htab = elf_x86_64_hash_table (info);
    720  1.1  christos   if (htab == NULL)
    721  1.1  christos     return FALSE;
    722  1.1  christos 
    723  1.1  christos   htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
    724  1.1  christos   if (!info->shared)
    725  1.1  christos     htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
    726  1.1  christos 
    727  1.1  christos   if (!htab->sdynbss
    728  1.1  christos       || (!info->shared && !htab->srelbss))
    729  1.1  christos     abort ();
    730  1.1  christos 
    731  1.1  christos   return TRUE;
    732  1.1  christos }
    733  1.1  christos 
    734  1.1  christos /* Copy the extra info we tack onto an elf_link_hash_entry.  */
    735  1.1  christos 
    736  1.1  christos static void
    737  1.1  christos elf_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
    738  1.1  christos 				 struct elf_link_hash_entry *dir,
    739  1.1  christos 				 struct elf_link_hash_entry *ind)
    740  1.1  christos {
    741  1.1  christos   struct elf_x86_64_link_hash_entry *edir, *eind;
    742  1.1  christos 
    743  1.1  christos   edir = (struct elf_x86_64_link_hash_entry *) dir;
    744  1.1  christos   eind = (struct elf_x86_64_link_hash_entry *) ind;
    745  1.1  christos 
    746  1.1  christos   if (eind->dyn_relocs != NULL)
    747  1.1  christos     {
    748  1.1  christos       if (edir->dyn_relocs != NULL)
    749  1.1  christos 	{
    750  1.1  christos 	  struct elf_dyn_relocs **pp;
    751  1.1  christos 	  struct elf_dyn_relocs *p;
    752  1.1  christos 
    753  1.1  christos 	  /* Add reloc counts against the indirect sym to the direct sym
    754  1.1  christos 	     list.  Merge any entries against the same section.  */
    755  1.1  christos 	  for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
    756  1.1  christos 	    {
    757  1.1  christos 	      struct elf_dyn_relocs *q;
    758  1.1  christos 
    759  1.1  christos 	      for (q = edir->dyn_relocs; q != NULL; q = q->next)
    760  1.1  christos 		if (q->sec == p->sec)
    761  1.1  christos 		  {
    762  1.1  christos 		    q->pc_count += p->pc_count;
    763  1.1  christos 		    q->count += p->count;
    764  1.1  christos 		    *pp = p->next;
    765  1.1  christos 		    break;
    766  1.1  christos 		  }
    767  1.1  christos 	      if (q == NULL)
    768  1.1  christos 		pp = &p->next;
    769  1.1  christos 	    }
    770  1.1  christos 	  *pp = edir->dyn_relocs;
    771  1.1  christos 	}
    772  1.1  christos 
    773  1.1  christos       edir->dyn_relocs = eind->dyn_relocs;
    774  1.1  christos       eind->dyn_relocs = NULL;
    775  1.1  christos     }
    776  1.1  christos 
    777  1.1  christos   if (ind->root.type == bfd_link_hash_indirect
    778  1.1  christos       && dir->got.refcount <= 0)
    779  1.1  christos     {
    780  1.1  christos       edir->tls_type = eind->tls_type;
    781  1.1  christos       eind->tls_type = GOT_UNKNOWN;
    782  1.1  christos     }
    783  1.1  christos 
    784  1.1  christos   if (ELIMINATE_COPY_RELOCS
    785  1.1  christos       && ind->root.type != bfd_link_hash_indirect
    786  1.1  christos       && dir->dynamic_adjusted)
    787  1.1  christos     {
    788  1.1  christos       /* If called to transfer flags for a weakdef during processing
    789  1.1  christos 	 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
    790  1.1  christos 	 We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
    791  1.1  christos       dir->ref_dynamic |= ind->ref_dynamic;
    792  1.1  christos       dir->ref_regular |= ind->ref_regular;
    793  1.1  christos       dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
    794  1.1  christos       dir->needs_plt |= ind->needs_plt;
    795  1.1  christos       dir->pointer_equality_needed |= ind->pointer_equality_needed;
    796  1.1  christos     }
    797  1.1  christos   else
    798  1.1  christos     _bfd_elf_link_hash_copy_indirect (info, dir, ind);
    799  1.1  christos }
    800  1.1  christos 
    801  1.1  christos static bfd_boolean
    802  1.1  christos elf64_x86_64_elf_object_p (bfd *abfd)
    803  1.1  christos {
    804  1.1  christos   /* Set the right machine number for an x86-64 elf64 file.  */
    805  1.1  christos   bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
    806  1.1  christos   return TRUE;
    807  1.1  christos }
    808  1.1  christos 
    809  1.1  christos typedef union
    810  1.1  christos   {
    811  1.1  christos     unsigned char c[2];
    812  1.1  christos     uint16_t i;
    813  1.1  christos   }
    814  1.1  christos x86_64_opcode16;
    815  1.1  christos 
    816  1.1  christos typedef union
    817  1.1  christos   {
    818  1.1  christos     unsigned char c[4];
    819  1.1  christos     uint32_t i;
    820  1.1  christos   }
    821  1.1  christos x86_64_opcode32;
    822  1.1  christos 
    823  1.1  christos /* Return TRUE if the TLS access code sequence support transition
    824  1.1  christos    from R_TYPE.  */
    825  1.1  christos 
    826  1.1  christos static bfd_boolean
    827  1.1  christos elf_x86_64_check_tls_transition (bfd *abfd,
    828  1.1  christos 				 struct bfd_link_info *info,
    829  1.1  christos 				 asection *sec,
    830  1.1  christos 				 bfd_byte *contents,
    831  1.1  christos 				 Elf_Internal_Shdr *symtab_hdr,
    832  1.1  christos 				 struct elf_link_hash_entry **sym_hashes,
    833  1.1  christos 				 unsigned int r_type,
    834  1.1  christos 				 const Elf_Internal_Rela *rel,
    835  1.1  christos 				 const Elf_Internal_Rela *relend)
    836  1.1  christos {
    837  1.1  christos   unsigned int val;
    838  1.1  christos   unsigned long r_symndx;
    839  1.1  christos   struct elf_link_hash_entry *h;
    840  1.1  christos   bfd_vma offset;
    841  1.1  christos   struct elf_x86_64_link_hash_table *htab;
    842  1.1  christos 
    843  1.1  christos   /* Get the section contents.  */
    844  1.1  christos   if (contents == NULL)
    845  1.1  christos     {
    846  1.1  christos       if (elf_section_data (sec)->this_hdr.contents != NULL)
    847  1.1  christos 	contents = elf_section_data (sec)->this_hdr.contents;
    848  1.1  christos       else
    849  1.1  christos 	{
    850  1.1  christos 	  /* FIXME: How to better handle error condition?  */
    851  1.1  christos 	  if (!bfd_malloc_and_get_section (abfd, sec, &contents))
    852  1.1  christos 	    return FALSE;
    853  1.1  christos 
    854  1.1  christos 	  /* Cache the section contents for elf_link_input_bfd.  */
    855  1.1  christos 	  elf_section_data (sec)->this_hdr.contents = contents;
    856  1.1  christos 	}
    857  1.1  christos     }
    858  1.1  christos 
    859  1.1  christos   htab = elf_x86_64_hash_table (info);
    860  1.1  christos   offset = rel->r_offset;
    861  1.1  christos   switch (r_type)
    862  1.1  christos     {
    863  1.1  christos     case R_X86_64_TLSGD:
    864  1.1  christos     case R_X86_64_TLSLD:
    865  1.1  christos       if ((rel + 1) >= relend)
    866  1.1  christos 	return FALSE;
    867  1.1  christos 
    868  1.1  christos       if (r_type == R_X86_64_TLSGD)
    869  1.1  christos 	{
    870  1.1  christos 	  /* Check transition from GD access model.  For 64bit, only
    871  1.1  christos 		.byte 0x66; leaq foo@tlsgd(%rip), %rdi
    872  1.1  christos 		.word 0x6666; rex64; call __tls_get_addr
    873  1.1  christos 	     can transit to different access model.  For 32bit, only
    874  1.1  christos 		leaq foo@tlsgd(%rip), %rdi
    875  1.1  christos 		.word 0x6666; rex64; call __tls_get_addr
    876  1.1  christos 	     can transit to different access model.  */
    877  1.1  christos 
    878  1.1  christos 	  static x86_64_opcode32 call = { { 0x66, 0x66, 0x48, 0xe8 } };
    879  1.1  christos 	  if ((offset + 12) > sec->size
    880  1.1  christos 	      || bfd_get_32 (abfd, contents + offset + 4) != call.i)
    881  1.1  christos 	    return FALSE;
    882  1.1  christos 
    883  1.1  christos 	  if (ABI_64_P (abfd))
    884  1.1  christos 	    {
    885  1.1  christos 	      static x86_64_opcode32 leaq = { { 0x66, 0x48, 0x8d, 0x3d } };
    886  1.1  christos 	      if (offset < 4
    887  1.1  christos 		  || bfd_get_32 (abfd, contents + offset - 4) != leaq.i)
    888  1.1  christos 		return FALSE;
    889  1.1  christos 	    }
    890  1.1  christos 	  else
    891  1.1  christos 	    {
    892  1.1  christos 	      static x86_64_opcode16 lea = { { 0x8d, 0x3d } };
    893  1.1  christos 	      if (offset < 3
    894  1.1  christos 		  || bfd_get_8 (abfd, contents + offset - 3) != 0x48
    895  1.1  christos 		  || bfd_get_16 (abfd, contents + offset - 2) != lea.i)
    896  1.1  christos 		return FALSE;
    897  1.1  christos 	    }
    898  1.1  christos 	}
    899  1.1  christos       else
    900  1.1  christos 	{
    901  1.1  christos 	  /* Check transition from LD access model.  Only
    902  1.1  christos 		leaq foo@tlsld(%rip), %rdi;
    903  1.1  christos 		call __tls_get_addr
    904  1.1  christos 	     can transit to different access model.  */
    905  1.1  christos 
    906  1.1  christos 	  static x86_64_opcode32 ld = { { 0x48, 0x8d, 0x3d, 0xe8 } };
    907  1.1  christos 	  x86_64_opcode32 op;
    908  1.1  christos 
    909  1.1  christos 	  if (offset < 3 || (offset + 9) > sec->size)
    910  1.1  christos 	    return FALSE;
    911  1.1  christos 
    912  1.1  christos 	  op.i = bfd_get_32 (abfd, contents + offset - 3);
    913  1.1  christos 	  op.c[3] = bfd_get_8 (abfd, contents + offset + 4);
    914  1.1  christos 	  if (op.i != ld.i)
    915  1.1  christos 	    return FALSE;
    916  1.1  christos 	}
    917  1.1  christos 
    918  1.1  christos       r_symndx = htab->r_sym (rel[1].r_info);
    919  1.1  christos       if (r_symndx < symtab_hdr->sh_info)
    920  1.1  christos 	return FALSE;
    921  1.1  christos 
    922  1.1  christos       h = sym_hashes[r_symndx - symtab_hdr->sh_info];
    923  1.1  christos       /* Use strncmp to check __tls_get_addr since __tls_get_addr
    924  1.1  christos 	 may be versioned.  */
    925  1.1  christos       return (h != NULL
    926  1.1  christos 	      && h->root.root.string != NULL
    927  1.1  christos 	      && (ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PC32
    928  1.1  christos 		  || ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)
    929  1.1  christos 	      && (strncmp (h->root.root.string,
    930  1.1  christos 			   "__tls_get_addr", 14) == 0));
    931  1.1  christos 
    932  1.1  christos     case R_X86_64_GOTTPOFF:
    933  1.1  christos       /* Check transition from IE access model:
    934  1.1  christos 		mov foo@gottpoff(%rip), %reg
    935  1.1  christos 		add foo@gottpoff(%rip), %reg
    936  1.1  christos        */
    937  1.1  christos 
    938  1.1  christos       /* Check REX prefix first.  */
    939  1.1  christos       if (offset >= 3 && (offset + 4) <= sec->size)
    940  1.1  christos 	{
    941  1.1  christos 	  val = bfd_get_8 (abfd, contents + offset - 3);
    942  1.1  christos 	  if (val != 0x48 && val != 0x4c)
    943  1.1  christos 	    {
    944  1.1  christos 	      /* X32 may have 0x44 REX prefix or no REX prefix.  */
    945  1.1  christos 	      if (ABI_64_P (abfd))
    946  1.1  christos 		return FALSE;
    947  1.1  christos 	    }
    948  1.1  christos 	}
    949  1.1  christos       else
    950  1.1  christos 	{
    951  1.1  christos 	  /* X32 may not have any REX prefix.  */
    952  1.1  christos 	  if (ABI_64_P (abfd))
    953  1.1  christos 	    return FALSE;
    954  1.1  christos 	  if (offset < 2 || (offset + 3) > sec->size)
    955  1.1  christos 	    return FALSE;
    956  1.1  christos 	}
    957  1.1  christos 
    958  1.1  christos       val = bfd_get_8 (abfd, contents + offset - 2);
    959  1.1  christos       if (val != 0x8b && val != 0x03)
    960  1.1  christos 	return FALSE;
    961  1.1  christos 
    962  1.1  christos       val = bfd_get_8 (abfd, contents + offset - 1);
    963  1.1  christos       return (val & 0xc7) == 5;
    964  1.1  christos 
    965  1.1  christos     case R_X86_64_GOTPC32_TLSDESC:
    966  1.1  christos       /* Check transition from GDesc access model:
    967  1.1  christos 		leaq x@tlsdesc(%rip), %rax
    968  1.1  christos 
    969  1.1  christos 	 Make sure it's a leaq adding rip to a 32-bit offset
    970  1.1  christos 	 into any register, although it's probably almost always
    971  1.1  christos 	 going to be rax.  */
    972  1.1  christos 
    973  1.1  christos       if (offset < 3 || (offset + 4) > sec->size)
    974  1.1  christos 	return FALSE;
    975  1.1  christos 
    976  1.1  christos       val = bfd_get_8 (abfd, contents + offset - 3);
    977  1.1  christos       if ((val & 0xfb) != 0x48)
    978  1.1  christos 	return FALSE;
    979  1.1  christos 
    980  1.1  christos       if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
    981  1.1  christos 	return FALSE;
    982  1.1  christos 
    983  1.1  christos       val = bfd_get_8 (abfd, contents + offset - 1);
    984  1.1  christos       return (val & 0xc7) == 0x05;
    985  1.1  christos 
    986  1.1  christos     case R_X86_64_TLSDESC_CALL:
    987  1.1  christos       /* Check transition from GDesc access model:
    988  1.1  christos 		call *x@tlsdesc(%rax)
    989  1.1  christos        */
    990  1.1  christos       if (offset + 2 <= sec->size)
    991  1.1  christos 	{
    992  1.1  christos 	  /* Make sure that it's a call *x@tlsdesc(%rax).  */
    993  1.1  christos 	  static x86_64_opcode16 call = { { 0xff, 0x10 } };
    994  1.1  christos 	  return bfd_get_16 (abfd, contents + offset) == call.i;
    995  1.1  christos 	}
    996  1.1  christos 
    997  1.1  christos       return FALSE;
    998  1.1  christos 
    999  1.1  christos     default:
   1000  1.1  christos       abort ();
   1001  1.1  christos     }
   1002  1.1  christos }
   1003  1.1  christos 
   1004  1.1  christos /* Return TRUE if the TLS access transition is OK or no transition
   1005  1.1  christos    will be performed.  Update R_TYPE if there is a transition.  */
   1006  1.1  christos 
   1007  1.1  christos static bfd_boolean
   1008  1.1  christos elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
   1009  1.1  christos 			   asection *sec, bfd_byte *contents,
   1010  1.1  christos 			   Elf_Internal_Shdr *symtab_hdr,
   1011  1.1  christos 			   struct elf_link_hash_entry **sym_hashes,
   1012  1.1  christos 			   unsigned int *r_type, int tls_type,
   1013  1.1  christos 			   const Elf_Internal_Rela *rel,
   1014  1.1  christos 			   const Elf_Internal_Rela *relend,
   1015  1.1  christos 			   struct elf_link_hash_entry *h,
   1016  1.1  christos 			   unsigned long r_symndx)
   1017  1.1  christos {
   1018  1.1  christos   unsigned int from_type = *r_type;
   1019  1.1  christos   unsigned int to_type = from_type;
   1020  1.1  christos   bfd_boolean check = TRUE;
   1021  1.1  christos 
   1022  1.1  christos   /* Skip TLS transition for functions.  */
   1023  1.1  christos   if (h != NULL
   1024  1.1  christos       && (h->type == STT_FUNC
   1025  1.1  christos 	  || h->type == STT_GNU_IFUNC))
   1026  1.1  christos     return TRUE;
   1027  1.1  christos 
   1028  1.1  christos   switch (from_type)
   1029  1.1  christos     {
   1030  1.1  christos     case R_X86_64_TLSGD:
   1031  1.1  christos     case R_X86_64_GOTPC32_TLSDESC:
   1032  1.1  christos     case R_X86_64_TLSDESC_CALL:
   1033  1.1  christos     case R_X86_64_GOTTPOFF:
   1034  1.1  christos       if (info->executable)
   1035  1.1  christos 	{
   1036  1.1  christos 	  if (h == NULL)
   1037  1.1  christos 	    to_type = R_X86_64_TPOFF32;
   1038  1.1  christos 	  else
   1039  1.1  christos 	    to_type = R_X86_64_GOTTPOFF;
   1040  1.1  christos 	}
   1041  1.1  christos 
   1042  1.1  christos       /* When we are called from elf_x86_64_relocate_section,
   1043  1.1  christos 	 CONTENTS isn't NULL and there may be additional transitions
   1044  1.1  christos 	 based on TLS_TYPE.  */
   1045  1.1  christos       if (contents != NULL)
   1046  1.1  christos 	{
   1047  1.1  christos 	  unsigned int new_to_type = to_type;
   1048  1.1  christos 
   1049  1.1  christos 	  if (info->executable
   1050  1.1  christos 	      && h != NULL
   1051  1.1  christos 	      && h->dynindx == -1
   1052  1.1  christos 	      && tls_type == GOT_TLS_IE)
   1053  1.1  christos 	    new_to_type = R_X86_64_TPOFF32;
   1054  1.1  christos 
   1055  1.1  christos 	  if (to_type == R_X86_64_TLSGD
   1056  1.1  christos 	      || to_type == R_X86_64_GOTPC32_TLSDESC
   1057  1.1  christos 	      || to_type == R_X86_64_TLSDESC_CALL)
   1058  1.1  christos 	    {
   1059  1.1  christos 	      if (tls_type == GOT_TLS_IE)
   1060  1.1  christos 		new_to_type = R_X86_64_GOTTPOFF;
   1061  1.1  christos 	    }
   1062  1.1  christos 
   1063  1.1  christos 	  /* We checked the transition before when we were called from
   1064  1.1  christos 	     elf_x86_64_check_relocs.  We only want to check the new
   1065  1.1  christos 	     transition which hasn't been checked before.  */
   1066  1.1  christos 	  check = new_to_type != to_type && from_type == to_type;
   1067  1.1  christos 	  to_type = new_to_type;
   1068  1.1  christos 	}
   1069  1.1  christos 
   1070  1.1  christos       break;
   1071  1.1  christos 
   1072  1.1  christos     case R_X86_64_TLSLD:
   1073  1.1  christos       if (info->executable)
   1074  1.1  christos 	to_type = R_X86_64_TPOFF32;
   1075  1.1  christos       break;
   1076  1.1  christos 
   1077  1.1  christos     default:
   1078  1.1  christos       return TRUE;
   1079  1.1  christos     }
   1080  1.1  christos 
   1081  1.1  christos   /* Return TRUE if there is no transition.  */
   1082  1.1  christos   if (from_type == to_type)
   1083  1.1  christos     return TRUE;
   1084  1.1  christos 
   1085  1.1  christos   /* Check if the transition can be performed.  */
   1086  1.1  christos   if (check
   1087  1.1  christos       && ! elf_x86_64_check_tls_transition (abfd, info, sec, contents,
   1088  1.1  christos 					    symtab_hdr, sym_hashes,
   1089  1.1  christos 					    from_type, rel, relend))
   1090  1.1  christos     {
   1091  1.1  christos       reloc_howto_type *from, *to;
   1092  1.1  christos       const char *name;
   1093  1.1  christos 
   1094  1.1  christos       from = elf_x86_64_rtype_to_howto (abfd, from_type);
   1095  1.1  christos       to = elf_x86_64_rtype_to_howto (abfd, to_type);
   1096  1.1  christos 
   1097  1.1  christos       if (h)
   1098  1.1  christos 	name = h->root.root.string;
   1099  1.1  christos       else
   1100  1.1  christos 	{
   1101  1.1  christos 	  struct elf_x86_64_link_hash_table *htab;
   1102  1.1  christos 
   1103  1.1  christos 	  htab = elf_x86_64_hash_table (info);
   1104  1.1  christos 	  if (htab == NULL)
   1105  1.1  christos 	    name = "*unknown*";
   1106  1.1  christos 	  else
   1107  1.1  christos 	    {
   1108  1.1  christos 	      Elf_Internal_Sym *isym;
   1109  1.1  christos 
   1110  1.1  christos 	      isym = bfd_sym_from_r_symndx (&htab->sym_cache,
   1111  1.1  christos 					    abfd, r_symndx);
   1112  1.1  christos 	      name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
   1113  1.1  christos 	    }
   1114  1.1  christos 	}
   1115  1.1  christos 
   1116  1.1  christos       (*_bfd_error_handler)
   1117  1.1  christos 	(_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
   1118  1.1  christos 	   "in section `%A' failed"),
   1119  1.1  christos 	 abfd, sec, from->name, to->name, name,
   1120  1.1  christos 	 (unsigned long) rel->r_offset);
   1121  1.1  christos       bfd_set_error (bfd_error_bad_value);
   1122  1.1  christos       return FALSE;
   1123  1.1  christos     }
   1124  1.1  christos 
   1125  1.1  christos   *r_type = to_type;
   1126  1.1  christos   return TRUE;
   1127  1.1  christos }
   1128  1.1  christos 
   1129  1.1  christos /* Look through the relocs for a section during the first phase, and
   1130  1.1  christos    calculate needed space in the global offset table, procedure
   1131  1.1  christos    linkage table, and dynamic reloc sections.  */
   1132  1.1  christos 
   1133  1.1  christos static bfd_boolean
   1134  1.1  christos elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
   1135  1.1  christos 			 asection *sec,
   1136  1.1  christos 			 const Elf_Internal_Rela *relocs)
   1137  1.1  christos {
   1138  1.1  christos   struct elf_x86_64_link_hash_table *htab;
   1139  1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   1140  1.1  christos   struct elf_link_hash_entry **sym_hashes;
   1141  1.1  christos   const Elf_Internal_Rela *rel;
   1142  1.1  christos   const Elf_Internal_Rela *rel_end;
   1143  1.1  christos   asection *sreloc;
   1144  1.1  christos 
   1145  1.1  christos   if (info->relocatable)
   1146  1.1  christos     return TRUE;
   1147  1.1  christos 
   1148  1.1  christos   BFD_ASSERT (is_x86_64_elf (abfd));
   1149  1.1  christos 
   1150  1.1  christos   htab = elf_x86_64_hash_table (info);
   1151  1.1  christos   if (htab == NULL)
   1152  1.1  christos     return FALSE;
   1153  1.1  christos 
   1154  1.1  christos   symtab_hdr = &elf_symtab_hdr (abfd);
   1155  1.1  christos   sym_hashes = elf_sym_hashes (abfd);
   1156  1.1  christos 
   1157  1.1  christos   sreloc = NULL;
   1158  1.1  christos 
   1159  1.1  christos   rel_end = relocs + sec->reloc_count;
   1160  1.1  christos   for (rel = relocs; rel < rel_end; rel++)
   1161  1.1  christos     {
   1162  1.1  christos       unsigned int r_type;
   1163  1.1  christos       unsigned long r_symndx;
   1164  1.1  christos       struct elf_link_hash_entry *h;
   1165  1.1  christos       Elf_Internal_Sym *isym;
   1166  1.1  christos       const char *name;
   1167  1.1  christos 
   1168  1.1  christos       r_symndx = htab->r_sym (rel->r_info);
   1169  1.1  christos       r_type = ELF32_R_TYPE (rel->r_info);
   1170  1.1  christos 
   1171  1.1  christos       if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
   1172  1.1  christos 	{
   1173  1.1  christos 	  (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
   1174  1.1  christos 				 abfd, r_symndx);
   1175  1.1  christos 	  return FALSE;
   1176  1.1  christos 	}
   1177  1.1  christos 
   1178  1.1  christos       if (r_symndx < symtab_hdr->sh_info)
   1179  1.1  christos 	{
   1180  1.1  christos 	  /* A local symbol.  */
   1181  1.1  christos 	  isym = bfd_sym_from_r_symndx (&htab->sym_cache,
   1182  1.1  christos 					abfd, r_symndx);
   1183  1.1  christos 	  if (isym == NULL)
   1184  1.1  christos 	    return FALSE;
   1185  1.1  christos 
   1186  1.1  christos 	  /* Check relocation against local STT_GNU_IFUNC symbol.  */
   1187  1.1  christos 	  if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
   1188  1.1  christos 	    {
   1189  1.1  christos 	      h = elf_x86_64_get_local_sym_hash (htab, abfd, rel,
   1190  1.1  christos 						 TRUE);
   1191  1.1  christos 	      if (h == NULL)
   1192  1.1  christos 		return FALSE;
   1193  1.1  christos 
   1194  1.1  christos 	      /* Fake a STT_GNU_IFUNC symbol.  */
   1195  1.1  christos 	      h->type = STT_GNU_IFUNC;
   1196  1.1  christos 	      h->def_regular = 1;
   1197  1.1  christos 	      h->ref_regular = 1;
   1198  1.1  christos 	      h->forced_local = 1;
   1199  1.1  christos 	      h->root.type = bfd_link_hash_defined;
   1200  1.1  christos 	    }
   1201  1.1  christos 	  else
   1202  1.1  christos 	    h = NULL;
   1203  1.1  christos 	}
   1204  1.1  christos       else
   1205  1.1  christos 	{
   1206  1.1  christos 	  isym = NULL;
   1207  1.1  christos 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   1208  1.1  christos 	  while (h->root.type == bfd_link_hash_indirect
   1209  1.1  christos 		 || h->root.type == bfd_link_hash_warning)
   1210  1.1  christos 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   1211  1.1  christos 	}
   1212  1.1  christos 
   1213  1.1  christos       /* Check invalid x32 relocations.  */
   1214  1.1  christos       if (!ABI_64_P (abfd))
   1215  1.1  christos 	switch (r_type)
   1216  1.1  christos 	  {
   1217  1.1  christos 	  default:
   1218  1.1  christos 	    break;
   1219  1.1  christos 
   1220  1.1  christos 	  case R_X86_64_64:
   1221  1.1  christos 	  case R_X86_64_DTPOFF64:
   1222  1.1  christos 	  case R_X86_64_TPOFF64:
   1223  1.1  christos 	  case R_X86_64_PC64:
   1224  1.1  christos 	  case R_X86_64_GOTOFF64:
   1225  1.1  christos 	  case R_X86_64_GOT64:
   1226  1.1  christos 	  case R_X86_64_GOTPCREL64:
   1227  1.1  christos 	  case R_X86_64_GOTPC64:
   1228  1.1  christos 	  case R_X86_64_GOTPLT64:
   1229  1.1  christos 	  case R_X86_64_PLTOFF64:
   1230  1.1  christos 	      {
   1231  1.1  christos 		if (h)
   1232  1.1  christos 		  name = h->root.root.string;
   1233  1.1  christos 		else
   1234  1.1  christos 		  name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
   1235  1.1  christos 					   NULL);
   1236  1.1  christos 		(*_bfd_error_handler)
   1237  1.1  christos 		  (_("%B: relocation %s against symbol `%s' isn't "
   1238  1.1  christos 		     "supported in x32 mode"), abfd,
   1239  1.1  christos 		   x86_64_elf_howto_table[r_type].name, name);
   1240  1.1  christos 		bfd_set_error (bfd_error_bad_value);
   1241  1.1  christos 		return FALSE;
   1242  1.1  christos 	      }
   1243  1.1  christos 	    break;
   1244  1.1  christos 	  }
   1245  1.1  christos 
   1246  1.1  christos       if (h != NULL)
   1247  1.1  christos 	{
   1248  1.1  christos 	  /* Create the ifunc sections for static executables.  If we
   1249  1.1  christos 	     never see an indirect function symbol nor we are building
   1250  1.1  christos 	     a static executable, those sections will be empty and
   1251  1.1  christos 	     won't appear in output.  */
   1252  1.1  christos 	  switch (r_type)
   1253  1.1  christos 	    {
   1254  1.1  christos 	    default:
   1255  1.1  christos 	      break;
   1256  1.1  christos 
   1257  1.1  christos 	    case R_X86_64_32S:
   1258  1.1  christos 	    case R_X86_64_32:
   1259  1.1  christos 	    case R_X86_64_64:
   1260  1.1  christos 	    case R_X86_64_PC32:
   1261  1.1  christos 	    case R_X86_64_PC64:
   1262  1.1  christos 	    case R_X86_64_PLT32:
   1263  1.1  christos 	    case R_X86_64_GOTPCREL:
   1264  1.1  christos 	    case R_X86_64_GOTPCREL64:
   1265  1.1  christos 	      if (!_bfd_elf_create_ifunc_sections (abfd, info))
   1266  1.1  christos 		return FALSE;
   1267  1.1  christos 	      break;
   1268  1.1  christos 	    }
   1269  1.1  christos 
   1270  1.1  christos 	  /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
   1271  1.1  christos 	     it here if it is defined in a non-shared object.  */
   1272  1.1  christos 	  if (h->type == STT_GNU_IFUNC
   1273  1.1  christos 	      && h->def_regular)
   1274  1.1  christos 	    {
   1275  1.1  christos 	      /* It is referenced by a non-shared object. */
   1276  1.1  christos 	      h->ref_regular = 1;
   1277  1.1  christos 	      h->needs_plt = 1;
   1278  1.1  christos 
   1279  1.1  christos 	      /* STT_GNU_IFUNC symbol must go through PLT.  */
   1280  1.1  christos 	      h->plt.refcount += 1;
   1281  1.1  christos 
   1282  1.1  christos 	      /* STT_GNU_IFUNC needs dynamic sections.  */
   1283  1.1  christos 	      if (htab->elf.dynobj == NULL)
   1284  1.1  christos 		htab->elf.dynobj = abfd;
   1285  1.1  christos 
   1286  1.1  christos 	      switch (r_type)
   1287  1.1  christos 		{
   1288  1.1  christos 		default:
   1289  1.1  christos 		  if (h->root.root.string)
   1290  1.1  christos 		    name = h->root.root.string;
   1291  1.1  christos 		  else
   1292  1.1  christos 		    name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
   1293  1.1  christos 					     NULL);
   1294  1.1  christos 		  (*_bfd_error_handler)
   1295  1.1  christos 		    (_("%B: relocation %s against STT_GNU_IFUNC "
   1296  1.1  christos 		       "symbol `%s' isn't handled by %s"), abfd,
   1297  1.1  christos 		     x86_64_elf_howto_table[r_type].name,
   1298  1.1  christos 		     name, __FUNCTION__);
   1299  1.1  christos 		  bfd_set_error (bfd_error_bad_value);
   1300  1.1  christos 		  return FALSE;
   1301  1.1  christos 
   1302  1.1  christos 		case R_X86_64_32:
   1303  1.1  christos 		  if (ABI_64_P (abfd))
   1304  1.1  christos 		    goto not_pointer;
   1305  1.1  christos 		case R_X86_64_64:
   1306  1.1  christos 		  h->non_got_ref = 1;
   1307  1.1  christos 		  h->pointer_equality_needed = 1;
   1308  1.1  christos 		  if (info->shared)
   1309  1.1  christos 		    {
   1310  1.1  christos 		      /* We must copy these reloc types into the output
   1311  1.1  christos 			 file.  Create a reloc section in dynobj and
   1312  1.1  christos 			 make room for this reloc.  */
   1313  1.1  christos 		      sreloc = _bfd_elf_create_ifunc_dyn_reloc
   1314  1.1  christos 			(abfd, info, sec, sreloc,
   1315  1.1  christos 			 &((struct elf_x86_64_link_hash_entry *) h)->dyn_relocs);
   1316  1.1  christos 		      if (sreloc == NULL)
   1317  1.1  christos 			return FALSE;
   1318  1.1  christos 		    }
   1319  1.1  christos 		  break;
   1320  1.1  christos 
   1321  1.1  christos 		case R_X86_64_32S:
   1322  1.1  christos 		case R_X86_64_PC32:
   1323  1.1  christos 		case R_X86_64_PC64:
   1324  1.1  christos not_pointer:
   1325  1.1  christos 		  h->non_got_ref = 1;
   1326  1.1  christos 		  if (r_type != R_X86_64_PC32
   1327  1.1  christos 		      && r_type != R_X86_64_PC64)
   1328  1.1  christos 		    h->pointer_equality_needed = 1;
   1329  1.1  christos 		  break;
   1330  1.1  christos 
   1331  1.1  christos 		case R_X86_64_PLT32:
   1332  1.1  christos 		  break;
   1333  1.1  christos 
   1334  1.1  christos 		case R_X86_64_GOTPCREL:
   1335  1.1  christos 		case R_X86_64_GOTPCREL64:
   1336  1.1  christos 		  h->got.refcount += 1;
   1337  1.1  christos 		  if (htab->elf.sgot == NULL
   1338  1.1  christos 		      && !_bfd_elf_create_got_section (htab->elf.dynobj,
   1339  1.1  christos 						       info))
   1340  1.1  christos 		    return FALSE;
   1341  1.1  christos 		  break;
   1342  1.1  christos 		}
   1343  1.1  christos 
   1344  1.1  christos 	      continue;
   1345  1.1  christos 	    }
   1346  1.1  christos 	}
   1347  1.1  christos 
   1348  1.1  christos       if (! elf_x86_64_tls_transition (info, abfd, sec, NULL,
   1349  1.1  christos 				       symtab_hdr, sym_hashes,
   1350  1.1  christos 				       &r_type, GOT_UNKNOWN,
   1351  1.1  christos 				       rel, rel_end, h, r_symndx))
   1352  1.1  christos 	return FALSE;
   1353  1.1  christos 
   1354  1.1  christos       switch (r_type)
   1355  1.1  christos 	{
   1356  1.1  christos 	case R_X86_64_TLSLD:
   1357  1.1  christos 	  htab->tls_ld_got.refcount += 1;
   1358  1.1  christos 	  goto create_got;
   1359  1.1  christos 
   1360  1.1  christos 	case R_X86_64_TPOFF32:
   1361  1.1  christos 	  if (!info->executable && ABI_64_P (abfd))
   1362  1.1  christos 	    {
   1363  1.1  christos 	      if (h)
   1364  1.1  christos 		name = h->root.root.string;
   1365  1.1  christos 	      else
   1366  1.1  christos 		name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
   1367  1.1  christos 					 NULL);
   1368  1.1  christos 	      (*_bfd_error_handler)
   1369  1.1  christos 		(_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
   1370  1.1  christos 		 abfd,
   1371  1.1  christos 		 x86_64_elf_howto_table[r_type].name, name);
   1372  1.1  christos 	      bfd_set_error (bfd_error_bad_value);
   1373  1.1  christos 	      return FALSE;
   1374  1.1  christos 	    }
   1375  1.1  christos 	  break;
   1376  1.1  christos 
   1377  1.1  christos 	case R_X86_64_GOTTPOFF:
   1378  1.1  christos 	  if (!info->executable)
   1379  1.1  christos 	    info->flags |= DF_STATIC_TLS;
   1380  1.1  christos 	  /* Fall through */
   1381  1.1  christos 
   1382  1.1  christos 	case R_X86_64_GOT32:
   1383  1.1  christos 	case R_X86_64_GOTPCREL:
   1384  1.1  christos 	case R_X86_64_TLSGD:
   1385  1.1  christos 	case R_X86_64_GOT64:
   1386  1.1  christos 	case R_X86_64_GOTPCREL64:
   1387  1.1  christos 	case R_X86_64_GOTPLT64:
   1388  1.1  christos 	case R_X86_64_GOTPC32_TLSDESC:
   1389  1.1  christos 	case R_X86_64_TLSDESC_CALL:
   1390  1.1  christos 	  /* This symbol requires a global offset table entry.	*/
   1391  1.1  christos 	  {
   1392  1.1  christos 	    int tls_type, old_tls_type;
   1393  1.1  christos 
   1394  1.1  christos 	    switch (r_type)
   1395  1.1  christos 	      {
   1396  1.1  christos 	      default: tls_type = GOT_NORMAL; break;
   1397  1.1  christos 	      case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
   1398  1.1  christos 	      case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
   1399  1.1  christos 	      case R_X86_64_GOTPC32_TLSDESC:
   1400  1.1  christos 	      case R_X86_64_TLSDESC_CALL:
   1401  1.1  christos 		tls_type = GOT_TLS_GDESC; break;
   1402  1.1  christos 	      }
   1403  1.1  christos 
   1404  1.1  christos 	    if (h != NULL)
   1405  1.1  christos 	      {
   1406  1.1  christos 		if (r_type == R_X86_64_GOTPLT64)
   1407  1.1  christos 		  {
   1408  1.1  christos 		    /* This relocation indicates that we also need
   1409  1.1  christos 		       a PLT entry, as this is a function.  We don't need
   1410  1.1  christos 		       a PLT entry for local symbols.  */
   1411  1.1  christos 		    h->needs_plt = 1;
   1412  1.1  christos 		    h->plt.refcount += 1;
   1413  1.1  christos 		  }
   1414  1.1  christos 		h->got.refcount += 1;
   1415  1.1  christos 		old_tls_type = elf_x86_64_hash_entry (h)->tls_type;
   1416  1.1  christos 	      }
   1417  1.1  christos 	    else
   1418  1.1  christos 	      {
   1419  1.1  christos 		bfd_signed_vma *local_got_refcounts;
   1420  1.1  christos 
   1421  1.1  christos 		/* This is a global offset table entry for a local symbol.  */
   1422  1.1  christos 		local_got_refcounts = elf_local_got_refcounts (abfd);
   1423  1.1  christos 		if (local_got_refcounts == NULL)
   1424  1.1  christos 		  {
   1425  1.1  christos 		    bfd_size_type size;
   1426  1.1  christos 
   1427  1.1  christos 		    size = symtab_hdr->sh_info;
   1428  1.1  christos 		    size *= sizeof (bfd_signed_vma)
   1429  1.1  christos 		      + sizeof (bfd_vma) + sizeof (char);
   1430  1.1  christos 		    local_got_refcounts = ((bfd_signed_vma *)
   1431  1.1  christos 					   bfd_zalloc (abfd, size));
   1432  1.1  christos 		    if (local_got_refcounts == NULL)
   1433  1.1  christos 		      return FALSE;
   1434  1.1  christos 		    elf_local_got_refcounts (abfd) = local_got_refcounts;
   1435  1.1  christos 		    elf_x86_64_local_tlsdesc_gotent (abfd)
   1436  1.1  christos 		      = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
   1437  1.1  christos 		    elf_x86_64_local_got_tls_type (abfd)
   1438  1.1  christos 		      = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
   1439  1.1  christos 		  }
   1440  1.1  christos 		local_got_refcounts[r_symndx] += 1;
   1441  1.1  christos 		old_tls_type
   1442  1.1  christos 		  = elf_x86_64_local_got_tls_type (abfd) [r_symndx];
   1443  1.1  christos 	      }
   1444  1.1  christos 
   1445  1.1  christos 	    /* If a TLS symbol is accessed using IE at least once,
   1446  1.1  christos 	       there is no point to use dynamic model for it.  */
   1447  1.1  christos 	    if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
   1448  1.1  christos 		&& (! GOT_TLS_GD_ANY_P (old_tls_type)
   1449  1.1  christos 		    || tls_type != GOT_TLS_IE))
   1450  1.1  christos 	      {
   1451  1.1  christos 		if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type))
   1452  1.1  christos 		  tls_type = old_tls_type;
   1453  1.1  christos 		else if (GOT_TLS_GD_ANY_P (old_tls_type)
   1454  1.1  christos 			 && GOT_TLS_GD_ANY_P (tls_type))
   1455  1.1  christos 		  tls_type |= old_tls_type;
   1456  1.1  christos 		else
   1457  1.1  christos 		  {
   1458  1.1  christos 		    if (h)
   1459  1.1  christos 		      name = h->root.root.string;
   1460  1.1  christos 		    else
   1461  1.1  christos 		      name = bfd_elf_sym_name (abfd, symtab_hdr,
   1462  1.1  christos 					       isym, NULL);
   1463  1.1  christos 		    (*_bfd_error_handler)
   1464  1.1  christos 		      (_("%B: '%s' accessed both as normal and thread local symbol"),
   1465  1.1  christos 		       abfd, name);
   1466  1.1  christos 		    return FALSE;
   1467  1.1  christos 		  }
   1468  1.1  christos 	      }
   1469  1.1  christos 
   1470  1.1  christos 	    if (old_tls_type != tls_type)
   1471  1.1  christos 	      {
   1472  1.1  christos 		if (h != NULL)
   1473  1.1  christos 		  elf_x86_64_hash_entry (h)->tls_type = tls_type;
   1474  1.1  christos 		else
   1475  1.1  christos 		  elf_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type;
   1476  1.1  christos 	      }
   1477  1.1  christos 	  }
   1478  1.1  christos 	  /* Fall through */
   1479  1.1  christos 
   1480  1.1  christos 	case R_X86_64_GOTOFF64:
   1481  1.1  christos 	case R_X86_64_GOTPC32:
   1482  1.1  christos 	case R_X86_64_GOTPC64:
   1483  1.1  christos 	create_got:
   1484  1.1  christos 	  if (htab->elf.sgot == NULL)
   1485  1.1  christos 	    {
   1486  1.1  christos 	      if (htab->elf.dynobj == NULL)
   1487  1.1  christos 		htab->elf.dynobj = abfd;
   1488  1.1  christos 	      if (!_bfd_elf_create_got_section (htab->elf.dynobj,
   1489  1.1  christos 						info))
   1490  1.1  christos 		return FALSE;
   1491  1.1  christos 	    }
   1492  1.1  christos 	  break;
   1493  1.1  christos 
   1494  1.1  christos 	case R_X86_64_PLT32:
   1495  1.1  christos 	  /* This symbol requires a procedure linkage table entry.  We
   1496  1.1  christos 	     actually build the entry in adjust_dynamic_symbol,
   1497  1.1  christos 	     because this might be a case of linking PIC code which is
   1498  1.1  christos 	     never referenced by a dynamic object, in which case we
   1499  1.1  christos 	     don't need to generate a procedure linkage table entry
   1500  1.1  christos 	     after all.	 */
   1501  1.1  christos 
   1502  1.1  christos 	  /* If this is a local symbol, we resolve it directly without
   1503  1.1  christos 	     creating a procedure linkage table entry.	*/
   1504  1.1  christos 	  if (h == NULL)
   1505  1.1  christos 	    continue;
   1506  1.1  christos 
   1507  1.1  christos 	  h->needs_plt = 1;
   1508  1.1  christos 	  h->plt.refcount += 1;
   1509  1.1  christos 	  break;
   1510  1.1  christos 
   1511  1.1  christos 	case R_X86_64_PLTOFF64:
   1512  1.1  christos 	  /* This tries to form the 'address' of a function relative
   1513  1.1  christos 	     to GOT.  For global symbols we need a PLT entry.  */
   1514  1.1  christos 	  if (h != NULL)
   1515  1.1  christos 	    {
   1516  1.1  christos 	      h->needs_plt = 1;
   1517  1.1  christos 	      h->plt.refcount += 1;
   1518  1.1  christos 	    }
   1519  1.1  christos 	  goto create_got;
   1520  1.1  christos 
   1521  1.1  christos 	case R_X86_64_32:
   1522  1.1  christos 	  if (!ABI_64_P (abfd))
   1523  1.1  christos 	    goto pointer;
   1524  1.1  christos 	case R_X86_64_8:
   1525  1.1  christos 	case R_X86_64_16:
   1526  1.1  christos 	case R_X86_64_32S:
   1527  1.1  christos 	  /* Let's help debug shared library creation.  These relocs
   1528  1.1  christos 	     cannot be used in shared libs.  Don't error out for
   1529  1.1  christos 	     sections we don't care about, such as debug sections or
   1530  1.1  christos 	     non-constant sections.  */
   1531  1.1  christos 	  if (info->shared
   1532  1.1  christos 	      && (sec->flags & SEC_ALLOC) != 0
   1533  1.1  christos 	      && (sec->flags & SEC_READONLY) != 0)
   1534  1.1  christos 	    {
   1535  1.1  christos 	      if (h)
   1536  1.1  christos 		name = h->root.root.string;
   1537  1.1  christos 	      else
   1538  1.1  christos 		name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
   1539  1.1  christos 	      (*_bfd_error_handler)
   1540  1.1  christos 		(_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
   1541  1.1  christos 		 abfd, x86_64_elf_howto_table[r_type].name, name);
   1542  1.1  christos 	      bfd_set_error (bfd_error_bad_value);
   1543  1.1  christos 	      return FALSE;
   1544  1.1  christos 	    }
   1545  1.1  christos 	  /* Fall through.  */
   1546  1.1  christos 
   1547  1.1  christos 	case R_X86_64_PC8:
   1548  1.1  christos 	case R_X86_64_PC16:
   1549  1.1  christos 	case R_X86_64_PC32:
   1550  1.1  christos 	case R_X86_64_PC64:
   1551  1.1  christos 	case R_X86_64_64:
   1552  1.1  christos pointer:
   1553  1.1  christos 	  if (h != NULL && info->executable)
   1554  1.1  christos 	    {
   1555  1.1  christos 	      /* If this reloc is in a read-only section, we might
   1556  1.1  christos 		 need a copy reloc.  We can't check reliably at this
   1557  1.1  christos 		 stage whether the section is read-only, as input
   1558  1.1  christos 		 sections have not yet been mapped to output sections.
   1559  1.1  christos 		 Tentatively set the flag for now, and correct in
   1560  1.1  christos 		 adjust_dynamic_symbol.  */
   1561  1.1  christos 	      h->non_got_ref = 1;
   1562  1.1  christos 
   1563  1.1  christos 	      /* We may need a .plt entry if the function this reloc
   1564  1.1  christos 		 refers to is in a shared lib.  */
   1565  1.1  christos 	      h->plt.refcount += 1;
   1566  1.1  christos 	      if (r_type != R_X86_64_PC32 && r_type != R_X86_64_PC64)
   1567  1.1  christos 		h->pointer_equality_needed = 1;
   1568  1.1  christos 	    }
   1569  1.1  christos 
   1570  1.1  christos 	  /* If we are creating a shared library, and this is a reloc
   1571  1.1  christos 	     against a global symbol, or a non PC relative reloc
   1572  1.1  christos 	     against a local symbol, then we need to copy the reloc
   1573  1.1  christos 	     into the shared library.  However, if we are linking with
   1574  1.1  christos 	     -Bsymbolic, we do not need to copy a reloc against a
   1575  1.1  christos 	     global symbol which is defined in an object we are
   1576  1.1  christos 	     including in the link (i.e., DEF_REGULAR is set).	At
   1577  1.1  christos 	     this point we have not seen all the input files, so it is
   1578  1.1  christos 	     possible that DEF_REGULAR is not set now but will be set
   1579  1.1  christos 	     later (it is never cleared).  In case of a weak definition,
   1580  1.1  christos 	     DEF_REGULAR may be cleared later by a strong definition in
   1581  1.1  christos 	     a shared library.  We account for that possibility below by
   1582  1.1  christos 	     storing information in the relocs_copied field of the hash
   1583  1.1  christos 	     table entry.  A similar situation occurs when creating
   1584  1.1  christos 	     shared libraries and symbol visibility changes render the
   1585  1.1  christos 	     symbol local.
   1586  1.1  christos 
   1587  1.1  christos 	     If on the other hand, we are creating an executable, we
   1588  1.1  christos 	     may need to keep relocations for symbols satisfied by a
   1589  1.1  christos 	     dynamic library if we manage to avoid copy relocs for the
   1590  1.1  christos 	     symbol.  */
   1591  1.1  christos 	  if ((info->shared
   1592  1.1  christos 	       && (sec->flags & SEC_ALLOC) != 0
   1593  1.1  christos 	       && (! IS_X86_64_PCREL_TYPE (r_type)
   1594  1.1  christos 		   || (h != NULL
   1595  1.1  christos 		       && (! SYMBOLIC_BIND (info, h)
   1596  1.1  christos 			   || h->root.type == bfd_link_hash_defweak
   1597  1.1  christos 			   || !h->def_regular))))
   1598  1.1  christos 	      || (ELIMINATE_COPY_RELOCS
   1599  1.1  christos 		  && !info->shared
   1600  1.1  christos 		  && (sec->flags & SEC_ALLOC) != 0
   1601  1.1  christos 		  && h != NULL
   1602  1.1  christos 		  && (h->root.type == bfd_link_hash_defweak
   1603  1.1  christos 		      || !h->def_regular)))
   1604  1.1  christos 	    {
   1605  1.1  christos 	      struct elf_dyn_relocs *p;
   1606  1.1  christos 	      struct elf_dyn_relocs **head;
   1607  1.1  christos 
   1608  1.1  christos 	      /* We must copy these reloc types into the output file.
   1609  1.1  christos 		 Create a reloc section in dynobj and make room for
   1610  1.1  christos 		 this reloc.  */
   1611  1.1  christos 	      if (sreloc == NULL)
   1612  1.1  christos 		{
   1613  1.1  christos 		  if (htab->elf.dynobj == NULL)
   1614  1.1  christos 		    htab->elf.dynobj = abfd;
   1615  1.1  christos 
   1616  1.1  christos 		  sreloc = _bfd_elf_make_dynamic_reloc_section
   1617  1.1  christos 		    (sec, htab->elf.dynobj, ABI_64_P (abfd) ? 3 : 2,
   1618  1.1  christos 		     abfd, /*rela?*/ TRUE);
   1619  1.1  christos 
   1620  1.1  christos 		  if (sreloc == NULL)
   1621  1.1  christos 		    return FALSE;
   1622  1.1  christos 		}
   1623  1.1  christos 
   1624  1.1  christos 	      /* If this is a global symbol, we count the number of
   1625  1.1  christos 		 relocations we need for this symbol.  */
   1626  1.1  christos 	      if (h != NULL)
   1627  1.1  christos 		{
   1628  1.1  christos 		  head = &((struct elf_x86_64_link_hash_entry *) h)->dyn_relocs;
   1629  1.1  christos 		}
   1630  1.1  christos 	      else
   1631  1.1  christos 		{
   1632  1.1  christos 		  /* Track dynamic relocs needed for local syms too.
   1633  1.1  christos 		     We really need local syms available to do this
   1634  1.1  christos 		     easily.  Oh well.  */
   1635  1.1  christos 		  asection *s;
   1636  1.1  christos 		  void **vpp;
   1637  1.1  christos 
   1638  1.1  christos 		  isym = bfd_sym_from_r_symndx (&htab->sym_cache,
   1639  1.1  christos 						abfd, r_symndx);
   1640  1.1  christos 		  if (isym == NULL)
   1641  1.1  christos 		    return FALSE;
   1642  1.1  christos 
   1643  1.1  christos 		  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
   1644  1.1  christos 		  if (s == NULL)
   1645  1.1  christos 		    s = sec;
   1646  1.1  christos 
   1647  1.1  christos 		  /* Beware of type punned pointers vs strict aliasing
   1648  1.1  christos 		     rules.  */
   1649  1.1  christos 		  vpp = &(elf_section_data (s)->local_dynrel);
   1650  1.1  christos 		  head = (struct elf_dyn_relocs **)vpp;
   1651  1.1  christos 		}
   1652  1.1  christos 
   1653  1.1  christos 	      p = *head;
   1654  1.1  christos 	      if (p == NULL || p->sec != sec)
   1655  1.1  christos 		{
   1656  1.1  christos 		  bfd_size_type amt = sizeof *p;
   1657  1.1  christos 
   1658  1.1  christos 		  p = ((struct elf_dyn_relocs *)
   1659  1.1  christos 		       bfd_alloc (htab->elf.dynobj, amt));
   1660  1.1  christos 		  if (p == NULL)
   1661  1.1  christos 		    return FALSE;
   1662  1.1  christos 		  p->next = *head;
   1663  1.1  christos 		  *head = p;
   1664  1.1  christos 		  p->sec = sec;
   1665  1.1  christos 		  p->count = 0;
   1666  1.1  christos 		  p->pc_count = 0;
   1667  1.1  christos 		}
   1668  1.1  christos 
   1669  1.1  christos 	      p->count += 1;
   1670  1.1  christos 	      if (IS_X86_64_PCREL_TYPE (r_type))
   1671  1.1  christos 		p->pc_count += 1;
   1672  1.1  christos 	    }
   1673  1.1  christos 	  break;
   1674  1.1  christos 
   1675  1.1  christos 	  /* This relocation describes the C++ object vtable hierarchy.
   1676  1.1  christos 	     Reconstruct it for later use during GC.  */
   1677  1.1  christos 	case R_X86_64_GNU_VTINHERIT:
   1678  1.1  christos 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
   1679  1.1  christos 	    return FALSE;
   1680  1.1  christos 	  break;
   1681  1.1  christos 
   1682  1.1  christos 	  /* This relocation describes which C++ vtable entries are actually
   1683  1.1  christos 	     used.  Record for later use during GC.  */
   1684  1.1  christos 	case R_X86_64_GNU_VTENTRY:
   1685  1.1  christos 	  BFD_ASSERT (h != NULL);
   1686  1.1  christos 	  if (h != NULL
   1687  1.1  christos 	      && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
   1688  1.1  christos 	    return FALSE;
   1689  1.1  christos 	  break;
   1690  1.1  christos 
   1691  1.1  christos 	default:
   1692  1.1  christos 	  break;
   1693  1.1  christos 	}
   1694  1.1  christos     }
   1695  1.1  christos 
   1696  1.1  christos   return TRUE;
   1697  1.1  christos }
   1698  1.1  christos 
   1699  1.1  christos /* Return the section that should be marked against GC for a given
   1700  1.1  christos    relocation.	*/
   1701  1.1  christos 
   1702  1.1  christos static asection *
   1703  1.1  christos elf_x86_64_gc_mark_hook (asection *sec,
   1704  1.1  christos 			 struct bfd_link_info *info,
   1705  1.1  christos 			 Elf_Internal_Rela *rel,
   1706  1.1  christos 			 struct elf_link_hash_entry *h,
   1707  1.1  christos 			 Elf_Internal_Sym *sym)
   1708  1.1  christos {
   1709  1.1  christos   if (h != NULL)
   1710  1.1  christos     switch (ELF32_R_TYPE (rel->r_info))
   1711  1.1  christos       {
   1712  1.1  christos       case R_X86_64_GNU_VTINHERIT:
   1713  1.1  christos       case R_X86_64_GNU_VTENTRY:
   1714  1.1  christos 	return NULL;
   1715  1.1  christos       }
   1716  1.1  christos 
   1717  1.1  christos   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
   1718  1.1  christos }
   1719  1.1  christos 
   1720  1.1  christos /* Update the got entry reference counts for the section being removed.	 */
   1721  1.1  christos 
   1722  1.1  christos static bfd_boolean
   1723  1.1  christos elf_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
   1724  1.1  christos 			  asection *sec,
   1725  1.1  christos 			  const Elf_Internal_Rela *relocs)
   1726  1.1  christos {
   1727  1.1  christos   struct elf_x86_64_link_hash_table *htab;
   1728  1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   1729  1.1  christos   struct elf_link_hash_entry **sym_hashes;
   1730  1.1  christos   bfd_signed_vma *local_got_refcounts;
   1731  1.1  christos   const Elf_Internal_Rela *rel, *relend;
   1732  1.1  christos 
   1733  1.1  christos   if (info->relocatable)
   1734  1.1  christos     return TRUE;
   1735  1.1  christos 
   1736  1.1  christos   htab = elf_x86_64_hash_table (info);
   1737  1.1  christos   if (htab == NULL)
   1738  1.1  christos     return FALSE;
   1739  1.1  christos 
   1740  1.1  christos   elf_section_data (sec)->local_dynrel = NULL;
   1741  1.1  christos 
   1742  1.1  christos   symtab_hdr = &elf_symtab_hdr (abfd);
   1743  1.1  christos   sym_hashes = elf_sym_hashes (abfd);
   1744  1.1  christos   local_got_refcounts = elf_local_got_refcounts (abfd);
   1745  1.1  christos 
   1746  1.1  christos   htab = elf_x86_64_hash_table (info);
   1747  1.1  christos   relend = relocs + sec->reloc_count;
   1748  1.1  christos   for (rel = relocs; rel < relend; rel++)
   1749  1.1  christos     {
   1750  1.1  christos       unsigned long r_symndx;
   1751  1.1  christos       unsigned int r_type;
   1752  1.1  christos       struct elf_link_hash_entry *h = NULL;
   1753  1.1  christos 
   1754  1.1  christos       r_symndx = htab->r_sym (rel->r_info);
   1755  1.1  christos       if (r_symndx >= symtab_hdr->sh_info)
   1756  1.1  christos 	{
   1757  1.1  christos 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   1758  1.1  christos 	  while (h->root.type == bfd_link_hash_indirect
   1759  1.1  christos 		 || h->root.type == bfd_link_hash_warning)
   1760  1.1  christos 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   1761  1.1  christos 	}
   1762  1.1  christos       else
   1763  1.1  christos 	{
   1764  1.1  christos 	  /* A local symbol.  */
   1765  1.1  christos 	  Elf_Internal_Sym *isym;
   1766  1.1  christos 
   1767  1.1  christos 	  isym = bfd_sym_from_r_symndx (&htab->sym_cache,
   1768  1.1  christos 					abfd, r_symndx);
   1769  1.1  christos 
   1770  1.1  christos 	  /* Check relocation against local STT_GNU_IFUNC symbol.  */
   1771  1.1  christos 	  if (isym != NULL
   1772  1.1  christos 	      && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
   1773  1.1  christos 	    {
   1774  1.1  christos 	      h = elf_x86_64_get_local_sym_hash (htab, abfd, rel, FALSE);
   1775  1.1  christos 	      if (h == NULL)
   1776  1.1  christos 		abort ();
   1777  1.1  christos 	    }
   1778  1.1  christos 	}
   1779  1.1  christos 
   1780  1.1  christos       if (h)
   1781  1.1  christos 	{
   1782  1.1  christos 	  struct elf_x86_64_link_hash_entry *eh;
   1783  1.1  christos 	  struct elf_dyn_relocs **pp;
   1784  1.1  christos 	  struct elf_dyn_relocs *p;
   1785  1.1  christos 
   1786  1.1  christos 	  eh = (struct elf_x86_64_link_hash_entry *) h;
   1787  1.1  christos 
   1788  1.1  christos 	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
   1789  1.1  christos 	    if (p->sec == sec)
   1790  1.1  christos 	      {
   1791  1.1  christos 		/* Everything must go for SEC.  */
   1792  1.1  christos 		*pp = p->next;
   1793  1.1  christos 		break;
   1794  1.1  christos 	      }
   1795  1.1  christos 	}
   1796  1.1  christos 
   1797  1.1  christos       r_type = ELF32_R_TYPE (rel->r_info);
   1798  1.1  christos       if (! elf_x86_64_tls_transition (info, abfd, sec, NULL,
   1799  1.1  christos 				       symtab_hdr, sym_hashes,
   1800  1.1  christos 				       &r_type, GOT_UNKNOWN,
   1801  1.1  christos 				       rel, relend, h, r_symndx))
   1802  1.1  christos 	return FALSE;
   1803  1.1  christos 
   1804  1.1  christos       switch (r_type)
   1805  1.1  christos 	{
   1806  1.1  christos 	case R_X86_64_TLSLD:
   1807  1.1  christos 	  if (htab->tls_ld_got.refcount > 0)
   1808  1.1  christos 	    htab->tls_ld_got.refcount -= 1;
   1809  1.1  christos 	  break;
   1810  1.1  christos 
   1811  1.1  christos 	case R_X86_64_TLSGD:
   1812  1.1  christos 	case R_X86_64_GOTPC32_TLSDESC:
   1813  1.1  christos 	case R_X86_64_TLSDESC_CALL:
   1814  1.1  christos 	case R_X86_64_GOTTPOFF:
   1815  1.1  christos 	case R_X86_64_GOT32:
   1816  1.1  christos 	case R_X86_64_GOTPCREL:
   1817  1.1  christos 	case R_X86_64_GOT64:
   1818  1.1  christos 	case R_X86_64_GOTPCREL64:
   1819  1.1  christos 	case R_X86_64_GOTPLT64:
   1820  1.1  christos 	  if (h != NULL)
   1821  1.1  christos 	    {
   1822  1.1  christos 	      if (r_type == R_X86_64_GOTPLT64 && h->plt.refcount > 0)
   1823  1.1  christos 	        h->plt.refcount -= 1;
   1824  1.1  christos 	      if (h->got.refcount > 0)
   1825  1.1  christos 		h->got.refcount -= 1;
   1826  1.1  christos 	      if (h->type == STT_GNU_IFUNC)
   1827  1.1  christos 		{
   1828  1.1  christos 		  if (h->plt.refcount > 0)
   1829  1.1  christos 		    h->plt.refcount -= 1;
   1830  1.1  christos 		}
   1831  1.1  christos 	    }
   1832  1.1  christos 	  else if (local_got_refcounts != NULL)
   1833  1.1  christos 	    {
   1834  1.1  christos 	      if (local_got_refcounts[r_symndx] > 0)
   1835  1.1  christos 		local_got_refcounts[r_symndx] -= 1;
   1836  1.1  christos 	    }
   1837  1.1  christos 	  break;
   1838  1.1  christos 
   1839  1.1  christos 	case R_X86_64_8:
   1840  1.1  christos 	case R_X86_64_16:
   1841  1.1  christos 	case R_X86_64_32:
   1842  1.1  christos 	case R_X86_64_64:
   1843  1.1  christos 	case R_X86_64_32S:
   1844  1.1  christos 	case R_X86_64_PC8:
   1845  1.1  christos 	case R_X86_64_PC16:
   1846  1.1  christos 	case R_X86_64_PC32:
   1847  1.1  christos 	case R_X86_64_PC64:
   1848  1.1  christos 	  if (info->shared
   1849  1.1  christos 	      && (h == NULL || h->type != STT_GNU_IFUNC))
   1850  1.1  christos 	    break;
   1851  1.1  christos 	  /* Fall thru */
   1852  1.1  christos 
   1853  1.1  christos 	case R_X86_64_PLT32:
   1854  1.1  christos 	case R_X86_64_PLTOFF64:
   1855  1.1  christos 	  if (h != NULL)
   1856  1.1  christos 	    {
   1857  1.1  christos 	      if (h->plt.refcount > 0)
   1858  1.1  christos 		h->plt.refcount -= 1;
   1859  1.1  christos 	    }
   1860  1.1  christos 	  break;
   1861  1.1  christos 
   1862  1.1  christos 	default:
   1863  1.1  christos 	  break;
   1864  1.1  christos 	}
   1865  1.1  christos     }
   1866  1.1  christos 
   1867  1.1  christos   return TRUE;
   1868  1.1  christos }
   1869  1.1  christos 
   1870  1.1  christos /* Adjust a symbol defined by a dynamic object and referenced by a
   1871  1.1  christos    regular object.  The current definition is in some section of the
   1872  1.1  christos    dynamic object, but we're not including those sections.  We have to
   1873  1.1  christos    change the definition to something the rest of the link can
   1874  1.1  christos    understand.	*/
   1875  1.1  christos 
   1876  1.1  christos static bfd_boolean
   1877  1.1  christos elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
   1878  1.1  christos 				  struct elf_link_hash_entry *h)
   1879  1.1  christos {
   1880  1.1  christos   struct elf_x86_64_link_hash_table *htab;
   1881  1.1  christos   asection *s;
   1882  1.1  christos 
   1883  1.1  christos   /* STT_GNU_IFUNC symbol must go through PLT. */
   1884  1.1  christos   if (h->type == STT_GNU_IFUNC)
   1885  1.1  christos     {
   1886  1.1  christos       if (h->plt.refcount <= 0)
   1887  1.1  christos 	{
   1888  1.1  christos 	  h->plt.offset = (bfd_vma) -1;
   1889  1.1  christos 	  h->needs_plt = 0;
   1890  1.1  christos 	}
   1891  1.1  christos       return TRUE;
   1892  1.1  christos     }
   1893  1.1  christos 
   1894  1.1  christos   /* If this is a function, put it in the procedure linkage table.  We
   1895  1.1  christos      will fill in the contents of the procedure linkage table later,
   1896  1.1  christos      when we know the address of the .got section.  */
   1897  1.1  christos   if (h->type == STT_FUNC
   1898  1.1  christos       || h->needs_plt)
   1899  1.1  christos     {
   1900  1.1  christos       if (h->plt.refcount <= 0
   1901  1.1  christos 	  || SYMBOL_CALLS_LOCAL (info, h)
   1902  1.1  christos 	  || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
   1903  1.1  christos 	      && h->root.type == bfd_link_hash_undefweak))
   1904  1.1  christos 	{
   1905  1.1  christos 	  /* This case can occur if we saw a PLT32 reloc in an input
   1906  1.1  christos 	     file, but the symbol was never referred to by a dynamic
   1907  1.1  christos 	     object, or if all references were garbage collected.  In
   1908  1.1  christos 	     such a case, we don't actually need to build a procedure
   1909  1.1  christos 	     linkage table, and we can just do a PC32 reloc instead.  */
   1910  1.1  christos 	  h->plt.offset = (bfd_vma) -1;
   1911  1.1  christos 	  h->needs_plt = 0;
   1912  1.1  christos 	}
   1913  1.1  christos 
   1914  1.1  christos       return TRUE;
   1915  1.1  christos     }
   1916  1.1  christos   else
   1917  1.1  christos     /* It's possible that we incorrectly decided a .plt reloc was
   1918  1.1  christos        needed for an R_X86_64_PC32 reloc to a non-function sym in
   1919  1.1  christos        check_relocs.  We can't decide accurately between function and
   1920  1.1  christos        non-function syms in check-relocs;  Objects loaded later in
   1921  1.1  christos        the link may change h->type.  So fix it now.  */
   1922  1.1  christos     h->plt.offset = (bfd_vma) -1;
   1923  1.1  christos 
   1924  1.1  christos   /* If this is a weak symbol, and there is a real definition, the
   1925  1.1  christos      processor independent code will have arranged for us to see the
   1926  1.1  christos      real definition first, and we can just use the same value.	 */
   1927  1.1  christos   if (h->u.weakdef != NULL)
   1928  1.1  christos     {
   1929  1.1  christos       BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
   1930  1.1  christos 		  || h->u.weakdef->root.type == bfd_link_hash_defweak);
   1931  1.1  christos       h->root.u.def.section = h->u.weakdef->root.u.def.section;
   1932  1.1  christos       h->root.u.def.value = h->u.weakdef->root.u.def.value;
   1933  1.1  christos       if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
   1934  1.1  christos 	h->non_got_ref = h->u.weakdef->non_got_ref;
   1935  1.1  christos       return TRUE;
   1936  1.1  christos     }
   1937  1.1  christos 
   1938  1.1  christos   /* This is a reference to a symbol defined by a dynamic object which
   1939  1.1  christos      is not a function.	 */
   1940  1.1  christos 
   1941  1.1  christos   /* If we are creating a shared library, we must presume that the
   1942  1.1  christos      only references to the symbol are via the global offset table.
   1943  1.1  christos      For such cases we need not do anything here; the relocations will
   1944  1.1  christos      be handled correctly by relocate_section.	*/
   1945  1.1  christos   if (info->shared)
   1946  1.1  christos     return TRUE;
   1947  1.1  christos 
   1948  1.1  christos   /* If there are no references to this symbol that do not use the
   1949  1.1  christos      GOT, we don't need to generate a copy reloc.  */
   1950  1.1  christos   if (!h->non_got_ref)
   1951  1.1  christos     return TRUE;
   1952  1.1  christos 
   1953  1.1  christos   /* If -z nocopyreloc was given, we won't generate them either.  */
   1954  1.1  christos   if (info->nocopyreloc)
   1955  1.1  christos     {
   1956  1.1  christos       h->non_got_ref = 0;
   1957  1.1  christos       return TRUE;
   1958  1.1  christos     }
   1959  1.1  christos 
   1960  1.1  christos   if (ELIMINATE_COPY_RELOCS)
   1961  1.1  christos     {
   1962  1.1  christos       struct elf_x86_64_link_hash_entry * eh;
   1963  1.1  christos       struct elf_dyn_relocs *p;
   1964  1.1  christos 
   1965  1.1  christos       eh = (struct elf_x86_64_link_hash_entry *) h;
   1966  1.1  christos       for (p = eh->dyn_relocs; p != NULL; p = p->next)
   1967  1.1  christos 	{
   1968  1.1  christos 	  s = p->sec->output_section;
   1969  1.1  christos 	  if (s != NULL && (s->flags & SEC_READONLY) != 0)
   1970  1.1  christos 	    break;
   1971  1.1  christos 	}
   1972  1.1  christos 
   1973  1.1  christos       /* If we didn't find any dynamic relocs in read-only sections, then
   1974  1.1  christos 	 we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
   1975  1.1  christos       if (p == NULL)
   1976  1.1  christos 	{
   1977  1.1  christos 	  h->non_got_ref = 0;
   1978  1.1  christos 	  return TRUE;
   1979  1.1  christos 	}
   1980  1.1  christos     }
   1981  1.1  christos 
   1982  1.1  christos   if (h->size == 0)
   1983  1.1  christos     {
   1984  1.1  christos       (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
   1985  1.1  christos 			     h->root.root.string);
   1986  1.1  christos       return TRUE;
   1987  1.1  christos     }
   1988  1.1  christos 
   1989  1.1  christos   /* We must allocate the symbol in our .dynbss section, which will
   1990  1.1  christos      become part of the .bss section of the executable.	 There will be
   1991  1.1  christos      an entry for this symbol in the .dynsym section.  The dynamic
   1992  1.1  christos      object will contain position independent code, so all references
   1993  1.1  christos      from the dynamic object to this symbol will go through the global
   1994  1.1  christos      offset table.  The dynamic linker will use the .dynsym entry to
   1995  1.1  christos      determine the address it must put in the global offset table, so
   1996  1.1  christos      both the dynamic object and the regular object will refer to the
   1997  1.1  christos      same memory location for the variable.  */
   1998  1.1  christos 
   1999  1.1  christos   htab = elf_x86_64_hash_table (info);
   2000  1.1  christos   if (htab == NULL)
   2001  1.1  christos     return FALSE;
   2002  1.1  christos 
   2003  1.1  christos   /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
   2004  1.1  christos      to copy the initial value out of the dynamic object and into the
   2005  1.1  christos      runtime process image.  */
   2006  1.1  christos   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
   2007  1.1  christos     {
   2008  1.1  christos       const struct elf_backend_data *bed;
   2009  1.1  christos       bed = get_elf_backend_data (info->output_bfd);
   2010  1.1  christos       htab->srelbss->size += bed->s->sizeof_rela;
   2011  1.1  christos       h->needs_copy = 1;
   2012  1.1  christos     }
   2013  1.1  christos 
   2014  1.1  christos   s = htab->sdynbss;
   2015  1.1  christos 
   2016  1.1  christos   return _bfd_elf_adjust_dynamic_copy (h, s);
   2017  1.1  christos }
   2018  1.1  christos 
   2019  1.1  christos /* Allocate space in .plt, .got and associated reloc sections for
   2020  1.1  christos    dynamic relocs.  */
   2021  1.1  christos 
   2022  1.1  christos static bfd_boolean
   2023  1.1  christos elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
   2024  1.1  christos {
   2025  1.1  christos   struct bfd_link_info *info;
   2026  1.1  christos   struct elf_x86_64_link_hash_table *htab;
   2027  1.1  christos   struct elf_x86_64_link_hash_entry *eh;
   2028  1.1  christos   struct elf_dyn_relocs *p;
   2029  1.1  christos   const struct elf_backend_data *bed;
   2030  1.1  christos 
   2031  1.1  christos   if (h->root.type == bfd_link_hash_indirect)
   2032  1.1  christos     return TRUE;
   2033  1.1  christos 
   2034  1.1  christos   if (h->root.type == bfd_link_hash_warning)
   2035  1.1  christos     h = (struct elf_link_hash_entry *) h->root.u.i.link;
   2036  1.1  christos   eh = (struct elf_x86_64_link_hash_entry *) h;
   2037  1.1  christos 
   2038  1.1  christos   info = (struct bfd_link_info *) inf;
   2039  1.1  christos   htab = elf_x86_64_hash_table (info);
   2040  1.1  christos   if (htab == NULL)
   2041  1.1  christos     return FALSE;
   2042  1.1  christos   bed = get_elf_backend_data (info->output_bfd);
   2043  1.1  christos 
   2044  1.1  christos   /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
   2045  1.1  christos      here if it is defined and referenced in a non-shared object.  */
   2046  1.1  christos   if (h->type == STT_GNU_IFUNC
   2047  1.1  christos       && h->def_regular)
   2048  1.1  christos     return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
   2049  1.1  christos 					       &eh->dyn_relocs,
   2050  1.1  christos 					       PLT_ENTRY_SIZE,
   2051  1.1  christos 					       GOT_ENTRY_SIZE);
   2052  1.1  christos   else if (htab->elf.dynamic_sections_created
   2053  1.1  christos 	   && h->plt.refcount > 0)
   2054  1.1  christos     {
   2055  1.1  christos       /* Make sure this symbol is output as a dynamic symbol.
   2056  1.1  christos 	 Undefined weak syms won't yet be marked as dynamic.  */
   2057  1.1  christos       if (h->dynindx == -1
   2058  1.1  christos 	  && !h->forced_local)
   2059  1.1  christos 	{
   2060  1.1  christos 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   2061  1.1  christos 	    return FALSE;
   2062  1.1  christos 	}
   2063  1.1  christos 
   2064  1.1  christos       if (info->shared
   2065  1.1  christos 	  || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
   2066  1.1  christos 	{
   2067  1.1  christos 	  asection *s = htab->elf.splt;
   2068  1.1  christos 
   2069  1.1  christos 	  /* If this is the first .plt entry, make room for the special
   2070  1.1  christos 	     first entry.  */
   2071  1.1  christos 	  if (s->size == 0)
   2072  1.1  christos 	    s->size += PLT_ENTRY_SIZE;
   2073  1.1  christos 
   2074  1.1  christos 	  h->plt.offset = s->size;
   2075  1.1  christos 
   2076  1.1  christos 	  /* If this symbol is not defined in a regular file, and we are
   2077  1.1  christos 	     not generating a shared library, then set the symbol to this
   2078  1.1  christos 	     location in the .plt.  This is required to make function
   2079  1.1  christos 	     pointers compare as equal between the normal executable and
   2080  1.1  christos 	     the shared library.  */
   2081  1.1  christos 	  if (! info->shared
   2082  1.1  christos 	      && !h->def_regular)
   2083  1.1  christos 	    {
   2084  1.1  christos 	      h->root.u.def.section = s;
   2085  1.1  christos 	      h->root.u.def.value = h->plt.offset;
   2086  1.1  christos 	    }
   2087  1.1  christos 
   2088  1.1  christos 	  /* Make room for this entry.  */
   2089  1.1  christos 	  s->size += PLT_ENTRY_SIZE;
   2090  1.1  christos 
   2091  1.1  christos 	  /* We also need to make an entry in the .got.plt section, which
   2092  1.1  christos 	     will be placed in the .got section by the linker script.  */
   2093  1.1  christos 	  htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
   2094  1.1  christos 
   2095  1.1  christos 	  /* We also need to make an entry in the .rela.plt section.  */
   2096  1.1  christos 	  htab->elf.srelplt->size += bed->s->sizeof_rela;
   2097  1.1  christos 	  htab->elf.srelplt->reloc_count++;
   2098  1.1  christos 	}
   2099  1.1  christos       else
   2100  1.1  christos 	{
   2101  1.1  christos 	  h->plt.offset = (bfd_vma) -1;
   2102  1.1  christos 	  h->needs_plt = 0;
   2103  1.1  christos 	}
   2104  1.1  christos     }
   2105  1.1  christos   else
   2106  1.1  christos     {
   2107  1.1  christos       h->plt.offset = (bfd_vma) -1;
   2108  1.1  christos       h->needs_plt = 0;
   2109  1.1  christos     }
   2110  1.1  christos 
   2111  1.1  christos   eh->tlsdesc_got = (bfd_vma) -1;
   2112  1.1  christos 
   2113  1.1  christos   /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
   2114  1.1  christos      make it a R_X86_64_TPOFF32 requiring no GOT entry.  */
   2115  1.1  christos   if (h->got.refcount > 0
   2116  1.1  christos       && info->executable
   2117  1.1  christos       && h->dynindx == -1
   2118  1.1  christos       && elf_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
   2119  1.1  christos     {
   2120  1.1  christos       h->got.offset = (bfd_vma) -1;
   2121  1.1  christos     }
   2122  1.1  christos   else if (h->got.refcount > 0)
   2123  1.1  christos     {
   2124  1.1  christos       asection *s;
   2125  1.1  christos       bfd_boolean dyn;
   2126  1.1  christos       int tls_type = elf_x86_64_hash_entry (h)->tls_type;
   2127  1.1  christos 
   2128  1.1  christos       /* Make sure this symbol is output as a dynamic symbol.
   2129  1.1  christos 	 Undefined weak syms won't yet be marked as dynamic.  */
   2130  1.1  christos       if (h->dynindx == -1
   2131  1.1  christos 	  && !h->forced_local)
   2132  1.1  christos 	{
   2133  1.1  christos 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   2134  1.1  christos 	    return FALSE;
   2135  1.1  christos 	}
   2136  1.1  christos 
   2137  1.1  christos       if (GOT_TLS_GDESC_P (tls_type))
   2138  1.1  christos 	{
   2139  1.1  christos 	  eh->tlsdesc_got = htab->elf.sgotplt->size
   2140  1.1  christos 	    - elf_x86_64_compute_jump_table_size (htab);
   2141  1.1  christos 	  htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
   2142  1.1  christos 	  h->got.offset = (bfd_vma) -2;
   2143  1.1  christos 	}
   2144  1.1  christos       if (! GOT_TLS_GDESC_P (tls_type)
   2145  1.1  christos 	  || GOT_TLS_GD_P (tls_type))
   2146  1.1  christos 	{
   2147  1.1  christos 	  s = htab->elf.sgot;
   2148  1.1  christos 	  h->got.offset = s->size;
   2149  1.1  christos 	  s->size += GOT_ENTRY_SIZE;
   2150  1.1  christos 	  if (GOT_TLS_GD_P (tls_type))
   2151  1.1  christos 	    s->size += GOT_ENTRY_SIZE;
   2152  1.1  christos 	}
   2153  1.1  christos       dyn = htab->elf.dynamic_sections_created;
   2154  1.1  christos       /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
   2155  1.1  christos 	 and two if global.
   2156  1.1  christos 	 R_X86_64_GOTTPOFF needs one dynamic relocation.  */
   2157  1.1  christos       if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
   2158  1.1  christos 	  || tls_type == GOT_TLS_IE)
   2159  1.1  christos 	htab->elf.srelgot->size += bed->s->sizeof_rela;
   2160  1.1  christos       else if (GOT_TLS_GD_P (tls_type))
   2161  1.1  christos 	htab->elf.srelgot->size += 2 * bed->s->sizeof_rela;
   2162  1.1  christos       else if (! GOT_TLS_GDESC_P (tls_type)
   2163  1.1  christos 	       && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
   2164  1.1  christos 		   || h->root.type != bfd_link_hash_undefweak)
   2165  1.1  christos 	       && (info->shared
   2166  1.1  christos 		   || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
   2167  1.1  christos 	htab->elf.srelgot->size += bed->s->sizeof_rela;
   2168  1.1  christos       if (GOT_TLS_GDESC_P (tls_type))
   2169  1.1  christos 	{
   2170  1.1  christos 	  htab->elf.srelplt->size += bed->s->sizeof_rela;
   2171  1.1  christos 	  htab->tlsdesc_plt = (bfd_vma) -1;
   2172  1.1  christos 	}
   2173  1.1  christos     }
   2174  1.1  christos   else
   2175  1.1  christos     h->got.offset = (bfd_vma) -1;
   2176  1.1  christos 
   2177  1.1  christos   if (eh->dyn_relocs == NULL)
   2178  1.1  christos     return TRUE;
   2179  1.1  christos 
   2180  1.1  christos   /* In the shared -Bsymbolic case, discard space allocated for
   2181  1.1  christos      dynamic pc-relative relocs against symbols which turn out to be
   2182  1.1  christos      defined in regular objects.  For the normal shared case, discard
   2183  1.1  christos      space for pc-relative relocs that have become local due to symbol
   2184  1.1  christos      visibility changes.  */
   2185  1.1  christos 
   2186  1.1  christos   if (info->shared)
   2187  1.1  christos     {
   2188  1.1  christos       /* Relocs that use pc_count are those that appear on a call
   2189  1.1  christos 	 insn, or certain REL relocs that can generated via assembly.
   2190  1.1  christos 	 We want calls to protected symbols to resolve directly to the
   2191  1.1  christos 	 function rather than going via the plt.  If people want
   2192  1.1  christos 	 function pointer comparisons to work as expected then they
   2193  1.1  christos 	 should avoid writing weird assembly.  */
   2194  1.1  christos       if (SYMBOL_CALLS_LOCAL (info, h))
   2195  1.1  christos 	{
   2196  1.1  christos 	  struct elf_dyn_relocs **pp;
   2197  1.1  christos 
   2198  1.1  christos 	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
   2199  1.1  christos 	    {
   2200  1.1  christos 	      p->count -= p->pc_count;
   2201  1.1  christos 	      p->pc_count = 0;
   2202  1.1  christos 	      if (p->count == 0)
   2203  1.1  christos 		*pp = p->next;
   2204  1.1  christos 	      else
   2205  1.1  christos 		pp = &p->next;
   2206  1.1  christos 	    }
   2207  1.1  christos 	}
   2208  1.1  christos 
   2209  1.1  christos       /* Also discard relocs on undefined weak syms with non-default
   2210  1.1  christos 	 visibility.  */
   2211  1.1  christos       if (eh->dyn_relocs != NULL
   2212  1.1  christos 	  && h->root.type == bfd_link_hash_undefweak)
   2213  1.1  christos 	{
   2214  1.1  christos 	  if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
   2215  1.1  christos 	    eh->dyn_relocs = NULL;
   2216  1.1  christos 
   2217  1.1  christos 	  /* Make sure undefined weak symbols are output as a dynamic
   2218  1.1  christos 	     symbol in PIEs.  */
   2219  1.1  christos 	  else if (h->dynindx == -1
   2220  1.1  christos 		   && ! h->forced_local
   2221  1.1  christos 		   && ! bfd_elf_link_record_dynamic_symbol (info, h))
   2222  1.1  christos 	    return FALSE;
   2223  1.1  christos 	}
   2224  1.1  christos 
   2225  1.1  christos     }
   2226  1.1  christos   else if (ELIMINATE_COPY_RELOCS)
   2227  1.1  christos     {
   2228  1.1  christos       /* For the non-shared case, discard space for relocs against
   2229  1.1  christos 	 symbols which turn out to need copy relocs or are not
   2230  1.1  christos 	 dynamic.  */
   2231  1.1  christos 
   2232  1.1  christos       if (!h->non_got_ref
   2233  1.1  christos 	  && ((h->def_dynamic
   2234  1.1  christos 	       && !h->def_regular)
   2235  1.1  christos 	      || (htab->elf.dynamic_sections_created
   2236  1.1  christos 		  && (h->root.type == bfd_link_hash_undefweak
   2237  1.1  christos 		      || h->root.type == bfd_link_hash_undefined))))
   2238  1.1  christos 	{
   2239  1.1  christos 	  /* Make sure this symbol is output as a dynamic symbol.
   2240  1.1  christos 	     Undefined weak syms won't yet be marked as dynamic.  */
   2241  1.1  christos 	  if (h->dynindx == -1
   2242  1.1  christos 	      && ! h->forced_local
   2243  1.1  christos 	      && ! bfd_elf_link_record_dynamic_symbol (info, h))
   2244  1.1  christos 	    return FALSE;
   2245  1.1  christos 
   2246  1.1  christos 	  /* If that succeeded, we know we'll be keeping all the
   2247  1.1  christos 	     relocs.  */
   2248  1.1  christos 	  if (h->dynindx != -1)
   2249  1.1  christos 	    goto keep;
   2250  1.1  christos 	}
   2251  1.1  christos 
   2252  1.1  christos       eh->dyn_relocs = NULL;
   2253  1.1  christos 
   2254  1.1  christos     keep: ;
   2255  1.1  christos     }
   2256  1.1  christos 
   2257  1.1  christos   /* Finally, allocate space.  */
   2258  1.1  christos   for (p = eh->dyn_relocs; p != NULL; p = p->next)
   2259  1.1  christos     {
   2260  1.1  christos       asection * sreloc;
   2261  1.1  christos 
   2262  1.1  christos       sreloc = elf_section_data (p->sec)->sreloc;
   2263  1.1  christos 
   2264  1.1  christos       BFD_ASSERT (sreloc != NULL);
   2265  1.1  christos 
   2266  1.1  christos       sreloc->size += p->count * bed->s->sizeof_rela;
   2267  1.1  christos     }
   2268  1.1  christos 
   2269  1.1  christos   return TRUE;
   2270  1.1  christos }
   2271  1.1  christos 
   2272  1.1  christos /* Allocate space in .plt, .got and associated reloc sections for
   2273  1.1  christos    local dynamic relocs.  */
   2274  1.1  christos 
   2275  1.1  christos static bfd_boolean
   2276  1.1  christos elf_x86_64_allocate_local_dynrelocs (void **slot, void *inf)
   2277  1.1  christos {
   2278  1.1  christos   struct elf_link_hash_entry *h
   2279  1.1  christos     = (struct elf_link_hash_entry *) *slot;
   2280  1.1  christos 
   2281  1.1  christos   if (h->type != STT_GNU_IFUNC
   2282  1.1  christos       || !h->def_regular
   2283  1.1  christos       || !h->ref_regular
   2284  1.1  christos       || !h->forced_local
   2285  1.1  christos       || h->root.type != bfd_link_hash_defined)
   2286  1.1  christos     abort ();
   2287  1.1  christos 
   2288  1.1  christos   return elf_x86_64_allocate_dynrelocs (h, inf);
   2289  1.1  christos }
   2290  1.1  christos 
   2291  1.1  christos /* Find any dynamic relocs that apply to read-only sections.  */
   2292  1.1  christos 
   2293  1.1  christos static bfd_boolean
   2294  1.1  christos elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry *h,
   2295  1.1  christos 			       void * inf)
   2296  1.1  christos {
   2297  1.1  christos   struct elf_x86_64_link_hash_entry *eh;
   2298  1.1  christos   struct elf_dyn_relocs *p;
   2299  1.1  christos 
   2300  1.1  christos   if (h->root.type == bfd_link_hash_warning)
   2301  1.1  christos     h = (struct elf_link_hash_entry *) h->root.u.i.link;
   2302  1.1  christos 
   2303  1.1  christos   eh = (struct elf_x86_64_link_hash_entry *) h;
   2304  1.1  christos   for (p = eh->dyn_relocs; p != NULL; p = p->next)
   2305  1.1  christos     {
   2306  1.1  christos       asection *s = p->sec->output_section;
   2307  1.1  christos 
   2308  1.1  christos       if (s != NULL && (s->flags & SEC_READONLY) != 0)
   2309  1.1  christos 	{
   2310  1.1  christos 	  struct bfd_link_info *info = (struct bfd_link_info *) inf;
   2311  1.1  christos 
   2312  1.1  christos 	  info->flags |= DF_TEXTREL;
   2313  1.1  christos 
   2314  1.1  christos 	  /* Not an error, just cut short the traversal.  */
   2315  1.1  christos 	  return FALSE;
   2316  1.1  christos 	}
   2317  1.1  christos     }
   2318  1.1  christos   return TRUE;
   2319  1.1  christos }
   2320  1.1  christos 
   2321  1.1  christos /* Set the sizes of the dynamic sections.  */
   2322  1.1  christos 
   2323  1.1  christos static bfd_boolean
   2324  1.1  christos elf_x86_64_size_dynamic_sections (bfd *output_bfd,
   2325  1.1  christos 				  struct bfd_link_info *info)
   2326  1.1  christos {
   2327  1.1  christos   struct elf_x86_64_link_hash_table *htab;
   2328  1.1  christos   bfd *dynobj;
   2329  1.1  christos   asection *s;
   2330  1.1  christos   bfd_boolean relocs;
   2331  1.1  christos   bfd *ibfd;
   2332  1.1  christos   const struct elf_backend_data *bed;
   2333  1.1  christos 
   2334  1.1  christos   htab = elf_x86_64_hash_table (info);
   2335  1.1  christos   if (htab == NULL)
   2336  1.1  christos     return FALSE;
   2337  1.1  christos   bed = get_elf_backend_data (output_bfd);
   2338  1.1  christos 
   2339  1.1  christos   dynobj = htab->elf.dynobj;
   2340  1.1  christos   if (dynobj == NULL)
   2341  1.1  christos     abort ();
   2342  1.1  christos 
   2343  1.1  christos   if (htab->elf.dynamic_sections_created)
   2344  1.1  christos     {
   2345  1.1  christos       /* Set the contents of the .interp section to the interpreter.  */
   2346  1.1  christos       if (info->executable)
   2347  1.1  christos 	{
   2348  1.1  christos 	  s = bfd_get_section_by_name (dynobj, ".interp");
   2349  1.1  christos 	  if (s == NULL)
   2350  1.1  christos 	    abort ();
   2351  1.1  christos 	  s->size = htab->dynamic_interpreter_size;
   2352  1.1  christos 	  s->contents = (unsigned char *) htab->dynamic_interpreter;
   2353  1.1  christos 	}
   2354  1.1  christos     }
   2355  1.1  christos 
   2356  1.1  christos   /* Set up .got offsets for local syms, and space for local dynamic
   2357  1.1  christos      relocs.  */
   2358  1.1  christos   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
   2359  1.1  christos     {
   2360  1.1  christos       bfd_signed_vma *local_got;
   2361  1.1  christos       bfd_signed_vma *end_local_got;
   2362  1.1  christos       char *local_tls_type;
   2363  1.1  christos       bfd_vma *local_tlsdesc_gotent;
   2364  1.1  christos       bfd_size_type locsymcount;
   2365  1.1  christos       Elf_Internal_Shdr *symtab_hdr;
   2366  1.1  christos       asection *srel;
   2367  1.1  christos 
   2368  1.1  christos       if (! is_x86_64_elf (ibfd))
   2369  1.1  christos 	continue;
   2370  1.1  christos 
   2371  1.1  christos       for (s = ibfd->sections; s != NULL; s = s->next)
   2372  1.1  christos 	{
   2373  1.1  christos 	  struct elf_dyn_relocs *p;
   2374  1.1  christos 
   2375  1.1  christos 	  for (p = (struct elf_dyn_relocs *)
   2376  1.1  christos 		    (elf_section_data (s)->local_dynrel);
   2377  1.1  christos 	       p != NULL;
   2378  1.1  christos 	       p = p->next)
   2379  1.1  christos 	    {
   2380  1.1  christos 	      if (!bfd_is_abs_section (p->sec)
   2381  1.1  christos 		  && bfd_is_abs_section (p->sec->output_section))
   2382  1.1  christos 		{
   2383  1.1  christos 		  /* Input section has been discarded, either because
   2384  1.1  christos 		     it is a copy of a linkonce section or due to
   2385  1.1  christos 		     linker script /DISCARD/, so we'll be discarding
   2386  1.1  christos 		     the relocs too.  */
   2387  1.1  christos 		}
   2388  1.1  christos 	      else if (p->count != 0)
   2389  1.1  christos 		{
   2390  1.1  christos 		  srel = elf_section_data (p->sec)->sreloc;
   2391  1.1  christos 		  srel->size += p->count * bed->s->sizeof_rela;
   2392  1.1  christos 		  if ((p->sec->output_section->flags & SEC_READONLY) != 0)
   2393  1.1  christos 		    info->flags |= DF_TEXTREL;
   2394  1.1  christos 		}
   2395  1.1  christos 	    }
   2396  1.1  christos 	}
   2397  1.1  christos 
   2398  1.1  christos       local_got = elf_local_got_refcounts (ibfd);
   2399  1.1  christos       if (!local_got)
   2400  1.1  christos 	continue;
   2401  1.1  christos 
   2402  1.1  christos       symtab_hdr = &elf_symtab_hdr (ibfd);
   2403  1.1  christos       locsymcount = symtab_hdr->sh_info;
   2404  1.1  christos       end_local_got = local_got + locsymcount;
   2405  1.1  christos       local_tls_type = elf_x86_64_local_got_tls_type (ibfd);
   2406  1.1  christos       local_tlsdesc_gotent = elf_x86_64_local_tlsdesc_gotent (ibfd);
   2407  1.1  christos       s = htab->elf.sgot;
   2408  1.1  christos       srel = htab->elf.srelgot;
   2409  1.1  christos       for (; local_got < end_local_got;
   2410  1.1  christos 	   ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
   2411  1.1  christos 	{
   2412  1.1  christos 	  *local_tlsdesc_gotent = (bfd_vma) -1;
   2413  1.1  christos 	  if (*local_got > 0)
   2414  1.1  christos 	    {
   2415  1.1  christos 	      if (GOT_TLS_GDESC_P (*local_tls_type))
   2416  1.1  christos 		{
   2417  1.1  christos 		  *local_tlsdesc_gotent = htab->elf.sgotplt->size
   2418  1.1  christos 		    - elf_x86_64_compute_jump_table_size (htab);
   2419  1.1  christos 		  htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
   2420  1.1  christos 		  *local_got = (bfd_vma) -2;
   2421  1.1  christos 		}
   2422  1.1  christos 	      if (! GOT_TLS_GDESC_P (*local_tls_type)
   2423  1.1  christos 		  || GOT_TLS_GD_P (*local_tls_type))
   2424  1.1  christos 		{
   2425  1.1  christos 		  *local_got = s->size;
   2426  1.1  christos 		  s->size += GOT_ENTRY_SIZE;
   2427  1.1  christos 		  if (GOT_TLS_GD_P (*local_tls_type))
   2428  1.1  christos 		    s->size += GOT_ENTRY_SIZE;
   2429  1.1  christos 		}
   2430  1.1  christos 	      if (info->shared
   2431  1.1  christos 		  || GOT_TLS_GD_ANY_P (*local_tls_type)
   2432  1.1  christos 		  || *local_tls_type == GOT_TLS_IE)
   2433  1.1  christos 		{
   2434  1.1  christos 		  if (GOT_TLS_GDESC_P (*local_tls_type))
   2435  1.1  christos 		    {
   2436  1.1  christos 		      htab->elf.srelplt->size
   2437  1.1  christos 			+= bed->s->sizeof_rela;
   2438  1.1  christos 		      htab->tlsdesc_plt = (bfd_vma) -1;
   2439  1.1  christos 		    }
   2440  1.1  christos 		  if (! GOT_TLS_GDESC_P (*local_tls_type)
   2441  1.1  christos 		      || GOT_TLS_GD_P (*local_tls_type))
   2442  1.1  christos 		    srel->size += bed->s->sizeof_rela;
   2443  1.1  christos 		}
   2444  1.1  christos 	    }
   2445  1.1  christos 	  else
   2446  1.1  christos 	    *local_got = (bfd_vma) -1;
   2447  1.1  christos 	}
   2448  1.1  christos     }
   2449  1.1  christos 
   2450  1.1  christos   if (htab->tls_ld_got.refcount > 0)
   2451  1.1  christos     {
   2452  1.1  christos       /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
   2453  1.1  christos 	 relocs.  */
   2454  1.1  christos       htab->tls_ld_got.offset = htab->elf.sgot->size;
   2455  1.1  christos       htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE;
   2456  1.1  christos       htab->elf.srelgot->size += bed->s->sizeof_rela;
   2457  1.1  christos     }
   2458  1.1  christos   else
   2459  1.1  christos     htab->tls_ld_got.offset = -1;
   2460  1.1  christos 
   2461  1.1  christos   /* Allocate global sym .plt and .got entries, and space for global
   2462  1.1  christos      sym dynamic relocs.  */
   2463  1.1  christos   elf_link_hash_traverse (&htab->elf, elf_x86_64_allocate_dynrelocs,
   2464  1.1  christos 			  info);
   2465  1.1  christos 
   2466  1.1  christos   /* Allocate .plt and .got entries, and space for local symbols.  */
   2467  1.1  christos   htab_traverse (htab->loc_hash_table,
   2468  1.1  christos 		 elf_x86_64_allocate_local_dynrelocs,
   2469  1.1  christos 		 info);
   2470  1.1  christos 
   2471  1.1  christos   /* For every jump slot reserved in the sgotplt, reloc_count is
   2472  1.1  christos      incremented.  However, when we reserve space for TLS descriptors,
   2473  1.1  christos      it's not incremented, so in order to compute the space reserved
   2474  1.1  christos      for them, it suffices to multiply the reloc count by the jump
   2475  1.1  christos      slot size.  */
   2476  1.1  christos   if (htab->elf.srelplt)
   2477  1.1  christos     htab->sgotplt_jump_table_size
   2478  1.1  christos       = elf_x86_64_compute_jump_table_size (htab);
   2479  1.1  christos 
   2480  1.1  christos   if (htab->tlsdesc_plt)
   2481  1.1  christos     {
   2482  1.1  christos       /* If we're not using lazy TLS relocations, don't generate the
   2483  1.1  christos 	 PLT and GOT entries they require.  */
   2484  1.1  christos       if ((info->flags & DF_BIND_NOW))
   2485  1.1  christos 	htab->tlsdesc_plt = 0;
   2486  1.1  christos       else
   2487  1.1  christos 	{
   2488  1.1  christos 	  htab->tlsdesc_got = htab->elf.sgot->size;
   2489  1.1  christos 	  htab->elf.sgot->size += GOT_ENTRY_SIZE;
   2490  1.1  christos 	  /* Reserve room for the initial entry.
   2491  1.1  christos 	     FIXME: we could probably do away with it in this case.  */
   2492  1.1  christos 	  if (htab->elf.splt->size == 0)
   2493  1.1  christos 	    htab->elf.splt->size += PLT_ENTRY_SIZE;
   2494  1.1  christos 	  htab->tlsdesc_plt = htab->elf.splt->size;
   2495  1.1  christos 	  htab->elf.splt->size += PLT_ENTRY_SIZE;
   2496  1.1  christos 	}
   2497  1.1  christos     }
   2498  1.1  christos 
   2499  1.1  christos   if (htab->elf.sgotplt)
   2500  1.1  christos     {
   2501  1.1  christos       struct elf_link_hash_entry *got;
   2502  1.1  christos       got = elf_link_hash_lookup (elf_hash_table (info),
   2503  1.1  christos 				  "_GLOBAL_OFFSET_TABLE_",
   2504  1.1  christos 				  FALSE, FALSE, FALSE);
   2505  1.1  christos 
   2506  1.1  christos       /* Don't allocate .got.plt section if there are no GOT nor PLT
   2507  1.1  christos          entries and there is no refeence to _GLOBAL_OFFSET_TABLE_.  */
   2508  1.1  christos       if ((got == NULL
   2509  1.1  christos 	   || !got->ref_regular_nonweak)
   2510  1.1  christos 	  && (htab->elf.sgotplt->size
   2511  1.1  christos 	      == get_elf_backend_data (output_bfd)->got_header_size)
   2512  1.1  christos 	  && (htab->elf.splt == NULL
   2513  1.1  christos 	      || htab->elf.splt->size == 0)
   2514  1.1  christos 	  && (htab->elf.sgot == NULL
   2515  1.1  christos 	      || htab->elf.sgot->size == 0)
   2516  1.1  christos 	  && (htab->elf.iplt == NULL
   2517  1.1  christos 	      || htab->elf.iplt->size == 0)
   2518  1.1  christos 	  && (htab->elf.igotplt == NULL
   2519  1.1  christos 	      || htab->elf.igotplt->size == 0))
   2520  1.1  christos 	htab->elf.sgotplt->size = 0;
   2521  1.1  christos     }
   2522  1.1  christos 
   2523  1.1  christos   /* We now have determined the sizes of the various dynamic sections.
   2524  1.1  christos      Allocate memory for them.  */
   2525  1.1  christos   relocs = FALSE;
   2526  1.1  christos   for (s = dynobj->sections; s != NULL; s = s->next)
   2527  1.1  christos     {
   2528  1.1  christos       if ((s->flags & SEC_LINKER_CREATED) == 0)
   2529  1.1  christos 	continue;
   2530  1.1  christos 
   2531  1.1  christos       if (s == htab->elf.splt
   2532  1.1  christos 	  || s == htab->elf.sgot
   2533  1.1  christos 	  || s == htab->elf.sgotplt
   2534  1.1  christos 	  || s == htab->elf.iplt
   2535  1.1  christos 	  || s == htab->elf.igotplt
   2536  1.1  christos 	  || s == htab->sdynbss)
   2537  1.1  christos 	{
   2538  1.1  christos 	  /* Strip this section if we don't need it; see the
   2539  1.1  christos 	     comment below.  */
   2540  1.1  christos 	}
   2541  1.1  christos       else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
   2542  1.1  christos 	{
   2543  1.1  christos 	  if (s->size != 0 && s != htab->elf.srelplt)
   2544  1.1  christos 	    relocs = TRUE;
   2545  1.1  christos 
   2546  1.1  christos 	  /* We use the reloc_count field as a counter if we need
   2547  1.1  christos 	     to copy relocs into the output file.  */
   2548  1.1  christos 	  if (s != htab->elf.srelplt)
   2549  1.1  christos 	    s->reloc_count = 0;
   2550  1.1  christos 	}
   2551  1.1  christos       else
   2552  1.1  christos 	{
   2553  1.1  christos 	  /* It's not one of our sections, so don't allocate space.  */
   2554  1.1  christos 	  continue;
   2555  1.1  christos 	}
   2556  1.1  christos 
   2557  1.1  christos       if (s->size == 0)
   2558  1.1  christos 	{
   2559  1.1  christos 	  /* If we don't need this section, strip it from the
   2560  1.1  christos 	     output file.  This is mostly to handle .rela.bss and
   2561  1.1  christos 	     .rela.plt.  We must create both sections in
   2562  1.1  christos 	     create_dynamic_sections, because they must be created
   2563  1.1  christos 	     before the linker maps input sections to output
   2564  1.1  christos 	     sections.  The linker does that before
   2565  1.1  christos 	     adjust_dynamic_symbol is called, and it is that
   2566  1.1  christos 	     function which decides whether anything needs to go
   2567  1.1  christos 	     into these sections.  */
   2568  1.1  christos 
   2569  1.1  christos 	  s->flags |= SEC_EXCLUDE;
   2570  1.1  christos 	  continue;
   2571  1.1  christos 	}
   2572  1.1  christos 
   2573  1.1  christos       if ((s->flags & SEC_HAS_CONTENTS) == 0)
   2574  1.1  christos 	continue;
   2575  1.1  christos 
   2576  1.1  christos       /* Allocate memory for the section contents.  We use bfd_zalloc
   2577  1.1  christos 	 here in case unused entries are not reclaimed before the
   2578  1.1  christos 	 section's contents are written out.  This should not happen,
   2579  1.1  christos 	 but this way if it does, we get a R_X86_64_NONE reloc instead
   2580  1.1  christos 	 of garbage.  */
   2581  1.1  christos       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
   2582  1.1  christos       if (s->contents == NULL)
   2583  1.1  christos 	return FALSE;
   2584  1.1  christos     }
   2585  1.1  christos 
   2586  1.1  christos   if (htab->elf.dynamic_sections_created)
   2587  1.1  christos     {
   2588  1.1  christos       /* Add some entries to the .dynamic section.  We fill in the
   2589  1.1  christos 	 values later, in elf_x86_64_finish_dynamic_sections, but we
   2590  1.1  christos 	 must add the entries now so that we get the correct size for
   2591  1.1  christos 	 the .dynamic section.	The DT_DEBUG entry is filled in by the
   2592  1.1  christos 	 dynamic linker and used by the debugger.  */
   2593  1.1  christos #define add_dynamic_entry(TAG, VAL) \
   2594  1.1  christos   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
   2595  1.1  christos 
   2596  1.1  christos       if (info->executable)
   2597  1.1  christos 	{
   2598  1.1  christos 	  if (!add_dynamic_entry (DT_DEBUG, 0))
   2599  1.1  christos 	    return FALSE;
   2600  1.1  christos 	}
   2601  1.1  christos 
   2602  1.1  christos       if (htab->elf.splt->size != 0)
   2603  1.1  christos 	{
   2604  1.1  christos 	  if (!add_dynamic_entry (DT_PLTGOT, 0)
   2605  1.1  christos 	      || !add_dynamic_entry (DT_PLTRELSZ, 0)
   2606  1.1  christos 	      || !add_dynamic_entry (DT_PLTREL, DT_RELA)
   2607  1.1  christos 	      || !add_dynamic_entry (DT_JMPREL, 0))
   2608  1.1  christos 	    return FALSE;
   2609  1.1  christos 
   2610  1.1  christos 	  if (htab->tlsdesc_plt
   2611  1.1  christos 	      && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
   2612  1.1  christos 		  || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
   2613  1.1  christos 	    return FALSE;
   2614  1.1  christos 	}
   2615  1.1  christos 
   2616  1.1  christos       if (relocs)
   2617  1.1  christos 	{
   2618  1.1  christos 	  if (!add_dynamic_entry (DT_RELA, 0)
   2619  1.1  christos 	      || !add_dynamic_entry (DT_RELASZ, 0)
   2620  1.1  christos 	      || !add_dynamic_entry (DT_RELAENT, bed->s->sizeof_rela))
   2621  1.1  christos 	    return FALSE;
   2622  1.1  christos 
   2623  1.1  christos 	  /* If any dynamic relocs apply to a read-only section,
   2624  1.1  christos 	     then we need a DT_TEXTREL entry.  */
   2625  1.1  christos 	  if ((info->flags & DF_TEXTREL) == 0)
   2626  1.1  christos 	    elf_link_hash_traverse (&htab->elf,
   2627  1.1  christos 				    elf_x86_64_readonly_dynrelocs,
   2628  1.1  christos 				    info);
   2629  1.1  christos 
   2630  1.1  christos 	  if ((info->flags & DF_TEXTREL) != 0)
   2631  1.1  christos 	    {
   2632  1.1  christos 	      if (!add_dynamic_entry (DT_TEXTREL, 0))
   2633  1.1  christos 		return FALSE;
   2634  1.1  christos 	    }
   2635  1.1  christos 	}
   2636  1.1  christos     }
   2637  1.1  christos #undef add_dynamic_entry
   2638  1.1  christos 
   2639  1.1  christos   return TRUE;
   2640  1.1  christos }
   2641  1.1  christos 
   2642  1.1  christos static bfd_boolean
   2643  1.1  christos elf_x86_64_always_size_sections (bfd *output_bfd,
   2644  1.1  christos 				 struct bfd_link_info *info)
   2645  1.1  christos {
   2646  1.1  christos   asection *tls_sec = elf_hash_table (info)->tls_sec;
   2647  1.1  christos 
   2648  1.1  christos   if (tls_sec)
   2649  1.1  christos     {
   2650  1.1  christos       struct elf_link_hash_entry *tlsbase;
   2651  1.1  christos 
   2652  1.1  christos       tlsbase = elf_link_hash_lookup (elf_hash_table (info),
   2653  1.1  christos 				      "_TLS_MODULE_BASE_",
   2654  1.1  christos 				      FALSE, FALSE, FALSE);
   2655  1.1  christos 
   2656  1.1  christos       if (tlsbase && tlsbase->type == STT_TLS)
   2657  1.1  christos 	{
   2658  1.1  christos 	  struct elf_x86_64_link_hash_table *htab;
   2659  1.1  christos 	  struct bfd_link_hash_entry *bh = NULL;
   2660  1.1  christos 	  const struct elf_backend_data *bed
   2661  1.1  christos 	    = get_elf_backend_data (output_bfd);
   2662  1.1  christos 
   2663  1.1  christos 	  htab = elf_x86_64_hash_table (info);
   2664  1.1  christos 	  if (htab == NULL)
   2665  1.1  christos 	    return FALSE;
   2666  1.1  christos 
   2667  1.1  christos 	  if (!(_bfd_generic_link_add_one_symbol
   2668  1.1  christos 		(info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
   2669  1.1  christos 		 tls_sec, 0, NULL, FALSE,
   2670  1.1  christos 		 bed->collect, &bh)))
   2671  1.1  christos 	    return FALSE;
   2672  1.1  christos 
   2673  1.1  christos 	  htab->tls_module_base = bh;
   2674  1.1  christos 
   2675  1.1  christos 	  tlsbase = (struct elf_link_hash_entry *)bh;
   2676  1.1  christos 	  tlsbase->def_regular = 1;
   2677  1.1  christos 	  tlsbase->other = STV_HIDDEN;
   2678  1.1  christos 	  (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
   2679  1.1  christos 	}
   2680  1.1  christos     }
   2681  1.1  christos 
   2682  1.1  christos   return TRUE;
   2683  1.1  christos }
   2684  1.1  christos 
   2685  1.1  christos /* _TLS_MODULE_BASE_ needs to be treated especially when linking
   2686  1.1  christos    executables.  Rather than setting it to the beginning of the TLS
   2687  1.1  christos    section, we have to set it to the end.  This function may be called
   2688  1.1  christos    multiple times, it is idempotent.  */
   2689  1.1  christos 
   2690  1.1  christos static void
   2691  1.1  christos elf_x86_64_set_tls_module_base (struct bfd_link_info *info)
   2692  1.1  christos {
   2693  1.1  christos   struct elf_x86_64_link_hash_table *htab;
   2694  1.1  christos   struct bfd_link_hash_entry *base;
   2695  1.1  christos 
   2696  1.1  christos   if (!info->executable)
   2697  1.1  christos     return;
   2698  1.1  christos 
   2699  1.1  christos   htab = elf_x86_64_hash_table (info);
   2700  1.1  christos   if (htab == NULL)
   2701  1.1  christos     return;
   2702  1.1  christos 
   2703  1.1  christos   base = htab->tls_module_base;
   2704  1.1  christos   if (base == NULL)
   2705  1.1  christos     return;
   2706  1.1  christos 
   2707  1.1  christos   base->u.def.value = htab->elf.tls_size;
   2708  1.1  christos }
   2709  1.1  christos 
   2710  1.1  christos /* Return the base VMA address which should be subtracted from real addresses
   2711  1.1  christos    when resolving @dtpoff relocation.
   2712  1.1  christos    This is PT_TLS segment p_vaddr.  */
   2713  1.1  christos 
   2714  1.1  christos static bfd_vma
   2715  1.1  christos elf_x86_64_dtpoff_base (struct bfd_link_info *info)
   2716  1.1  christos {
   2717  1.1  christos   /* If tls_sec is NULL, we should have signalled an error already.  */
   2718  1.1  christos   if (elf_hash_table (info)->tls_sec == NULL)
   2719  1.1  christos     return 0;
   2720  1.1  christos   return elf_hash_table (info)->tls_sec->vma;
   2721  1.1  christos }
   2722  1.1  christos 
   2723  1.1  christos /* Return the relocation value for @tpoff relocation
   2724  1.1  christos    if STT_TLS virtual address is ADDRESS.  */
   2725  1.1  christos 
   2726  1.1  christos static bfd_vma
   2727  1.1  christos elf_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address)
   2728  1.1  christos {
   2729  1.1  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
   2730  1.1  christos   const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
   2731  1.1  christos   bfd_vma static_tls_size;
   2732  1.1  christos 
   2733  1.1  christos   /* If tls_segment is NULL, we should have signalled an error already.  */
   2734  1.1  christos   if (htab->tls_sec == NULL)
   2735  1.1  christos     return 0;
   2736  1.1  christos 
   2737  1.1  christos   /* Consider special static TLS alignment requirements.  */
   2738  1.1  christos   static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
   2739  1.1  christos   return address - static_tls_size - htab->tls_sec->vma;
   2740  1.1  christos }
   2741  1.1  christos 
   2742  1.1  christos /* Is the instruction before OFFSET in CONTENTS a 32bit relative
   2743  1.1  christos    branch?  */
   2744  1.1  christos 
   2745  1.1  christos static bfd_boolean
   2746  1.1  christos is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
   2747  1.1  christos {
   2748  1.1  christos   /* Opcode		Instruction
   2749  1.1  christos      0xe8		call
   2750  1.1  christos      0xe9		jump
   2751  1.1  christos      0x0f 0x8x		conditional jump */
   2752  1.1  christos   return ((offset > 0
   2753  1.1  christos 	   && (contents [offset - 1] == 0xe8
   2754  1.1  christos 	       || contents [offset - 1] == 0xe9))
   2755  1.1  christos 	  || (offset > 1
   2756  1.1  christos 	      && contents [offset - 2] == 0x0f
   2757  1.1  christos 	      && (contents [offset - 1] & 0xf0) == 0x80));
   2758  1.1  christos }
   2759  1.1  christos 
   2760  1.1  christos /* Relocate an x86_64 ELF section.  */
   2761  1.1  christos 
   2762  1.1  christos static bfd_boolean
   2763  1.1  christos elf_x86_64_relocate_section (bfd *output_bfd,
   2764  1.1  christos 			     struct bfd_link_info *info,
   2765  1.1  christos 			     bfd *input_bfd,
   2766  1.1  christos 			     asection *input_section,
   2767  1.1  christos 			     bfd_byte *contents,
   2768  1.1  christos 			     Elf_Internal_Rela *relocs,
   2769  1.1  christos 			     Elf_Internal_Sym *local_syms,
   2770  1.1  christos 			     asection **local_sections)
   2771  1.1  christos {
   2772  1.1  christos   struct elf_x86_64_link_hash_table *htab;
   2773  1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   2774  1.1  christos   struct elf_link_hash_entry **sym_hashes;
   2775  1.1  christos   bfd_vma *local_got_offsets;
   2776  1.1  christos   bfd_vma *local_tlsdesc_gotents;
   2777  1.1  christos   Elf_Internal_Rela *rel;
   2778  1.1  christos   Elf_Internal_Rela *relend;
   2779  1.1  christos 
   2780  1.1  christos   BFD_ASSERT (is_x86_64_elf (input_bfd));
   2781  1.1  christos 
   2782  1.1  christos   htab = elf_x86_64_hash_table (info);
   2783  1.1  christos   if (htab == NULL)
   2784  1.1  christos     return FALSE;
   2785  1.1  christos   symtab_hdr = &elf_symtab_hdr (input_bfd);
   2786  1.1  christos   sym_hashes = elf_sym_hashes (input_bfd);
   2787  1.1  christos   local_got_offsets = elf_local_got_offsets (input_bfd);
   2788  1.1  christos   local_tlsdesc_gotents = elf_x86_64_local_tlsdesc_gotent (input_bfd);
   2789  1.1  christos 
   2790  1.1  christos   elf_x86_64_set_tls_module_base (info);
   2791  1.1  christos 
   2792  1.1  christos   rel = relocs;
   2793  1.1  christos   relend = relocs + input_section->reloc_count;
   2794  1.1  christos   for (; rel < relend; rel++)
   2795  1.1  christos     {
   2796  1.1  christos       unsigned int r_type;
   2797  1.1  christos       reloc_howto_type *howto;
   2798  1.1  christos       unsigned long r_symndx;
   2799  1.1  christos       struct elf_link_hash_entry *h;
   2800  1.1  christos       Elf_Internal_Sym *sym;
   2801  1.1  christos       asection *sec;
   2802  1.1  christos       bfd_vma off, offplt;
   2803  1.1  christos       bfd_vma relocation;
   2804  1.1  christos       bfd_boolean unresolved_reloc;
   2805  1.1  christos       bfd_reloc_status_type r;
   2806  1.1  christos       int tls_type;
   2807  1.1  christos       asection *base_got;
   2808  1.1  christos 
   2809  1.1  christos       r_type = ELF32_R_TYPE (rel->r_info);
   2810  1.1  christos       if (r_type == (int) R_X86_64_GNU_VTINHERIT
   2811  1.1  christos 	  || r_type == (int) R_X86_64_GNU_VTENTRY)
   2812  1.1  christos 	continue;
   2813  1.1  christos 
   2814  1.1  christos       if (r_type >= R_X86_64_max)
   2815  1.1  christos 	{
   2816  1.1  christos 	  bfd_set_error (bfd_error_bad_value);
   2817  1.1  christos 	  return FALSE;
   2818  1.1  christos 	}
   2819  1.1  christos 
   2820  1.1  christos       howto = x86_64_elf_howto_table + r_type;
   2821  1.1  christos       r_symndx = htab->r_sym (rel->r_info);
   2822  1.1  christos       h = NULL;
   2823  1.1  christos       sym = NULL;
   2824  1.1  christos       sec = NULL;
   2825  1.1  christos       unresolved_reloc = FALSE;
   2826  1.1  christos       if (r_symndx < symtab_hdr->sh_info)
   2827  1.1  christos 	{
   2828  1.1  christos 	  sym = local_syms + r_symndx;
   2829  1.1  christos 	  sec = local_sections[r_symndx];
   2830  1.1  christos 
   2831  1.1  christos 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym,
   2832  1.1  christos 						&sec, rel);
   2833  1.1  christos 
   2834  1.1  christos 	  /* Relocate against local STT_GNU_IFUNC symbol.  */
   2835  1.1  christos 	  if (!info->relocatable
   2836  1.1  christos 	      && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
   2837  1.1  christos 	    {
   2838  1.1  christos 	      h = elf_x86_64_get_local_sym_hash (htab, input_bfd,
   2839  1.1  christos 						 rel, FALSE);
   2840  1.1  christos 	      if (h == NULL)
   2841  1.1  christos 		abort ();
   2842  1.1  christos 
   2843  1.1  christos 	      /* Set STT_GNU_IFUNC symbol value.  */
   2844  1.1  christos 	      h->root.u.def.value = sym->st_value;
   2845  1.1  christos 	      h->root.u.def.section = sec;
   2846  1.1  christos 	    }
   2847  1.1  christos 	}
   2848  1.1  christos       else
   2849  1.1  christos 	{
   2850  1.1  christos 	  bfd_boolean warned ATTRIBUTE_UNUSED;
   2851  1.1  christos 
   2852  1.1  christos 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
   2853  1.1  christos 				   r_symndx, symtab_hdr, sym_hashes,
   2854  1.1  christos 				   h, sec, relocation,
   2855  1.1  christos 				   unresolved_reloc, warned);
   2856  1.1  christos 	}
   2857  1.1  christos 
   2858  1.1  christos       if (sec != NULL && elf_discarded_section (sec))
   2859  1.1  christos 	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   2860  1.1  christos 					 rel, relend, howto, contents);
   2861  1.1  christos 
   2862  1.1  christos       if (info->relocatable)
   2863  1.1  christos 	continue;
   2864  1.1  christos 
   2865  1.1  christos       /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
   2866  1.1  christos 	 it here if it is defined in a non-shared object.  */
   2867  1.1  christos       if (h != NULL
   2868  1.1  christos 	  && h->type == STT_GNU_IFUNC
   2869  1.1  christos 	  && h->def_regular)
   2870  1.1  christos 	{
   2871  1.1  christos 	  asection *plt;
   2872  1.1  christos 	  bfd_vma plt_index;
   2873  1.1  christos 	  const char *name;
   2874  1.1  christos 
   2875  1.1  christos 	  if ((input_section->flags & SEC_ALLOC) == 0
   2876  1.1  christos 	      || h->plt.offset == (bfd_vma) -1)
   2877  1.1  christos 	    abort ();
   2878  1.1  christos 
   2879  1.1  christos 	  /* STT_GNU_IFUNC symbol must go through PLT.  */
   2880  1.1  christos 	  plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
   2881  1.1  christos 	  relocation = (plt->output_section->vma
   2882  1.1  christos 			+ plt->output_offset + h->plt.offset);
   2883  1.1  christos 
   2884  1.1  christos 	  switch (r_type)
   2885  1.1  christos 	    {
   2886  1.1  christos 	    default:
   2887  1.1  christos 	      if (h->root.root.string)
   2888  1.1  christos 		name = h->root.root.string;
   2889  1.1  christos 	      else
   2890  1.1  christos 		name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
   2891  1.1  christos 					 NULL);
   2892  1.1  christos 	      (*_bfd_error_handler)
   2893  1.1  christos 		(_("%B: relocation %s against STT_GNU_IFUNC "
   2894  1.1  christos 		   "symbol `%s' isn't handled by %s"), input_bfd,
   2895  1.1  christos 		 x86_64_elf_howto_table[r_type].name,
   2896  1.1  christos 		 name, __FUNCTION__);
   2897  1.1  christos 	      bfd_set_error (bfd_error_bad_value);
   2898  1.1  christos 	      return FALSE;
   2899  1.1  christos 
   2900  1.1  christos 	    case R_X86_64_32S:
   2901  1.1  christos 	      if (info->shared)
   2902  1.1  christos 		abort ();
   2903  1.1  christos 	      goto do_relocation;
   2904  1.1  christos 
   2905  1.1  christos 	    case R_X86_64_32:
   2906  1.1  christos 	      if (ABI_64_P (output_bfd))
   2907  1.1  christos 		goto do_relocation;
   2908  1.1  christos 	      /* FALLTHROUGH */
   2909  1.1  christos 	    case R_X86_64_64:
   2910  1.1  christos 	      if (rel->r_addend != 0)
   2911  1.1  christos 		{
   2912  1.1  christos 		  if (h->root.root.string)
   2913  1.1  christos 		    name = h->root.root.string;
   2914  1.1  christos 		  else
   2915  1.1  christos 		    name = bfd_elf_sym_name (input_bfd, symtab_hdr,
   2916  1.1  christos 					     sym, NULL);
   2917  1.1  christos 		  (*_bfd_error_handler)
   2918  1.1  christos 		    (_("%B: relocation %s against STT_GNU_IFUNC "
   2919  1.1  christos 		       "symbol `%s' has non-zero addend: %d"),
   2920  1.1  christos 		     input_bfd, x86_64_elf_howto_table[r_type].name,
   2921  1.1  christos 		     name, rel->r_addend);
   2922  1.1  christos 		  bfd_set_error (bfd_error_bad_value);
   2923  1.1  christos 		  return FALSE;
   2924  1.1  christos 		}
   2925  1.1  christos 
   2926  1.1  christos 	      /* Generate dynamic relcoation only when there is a
   2927  1.1  christos 		 non-GOF reference in a shared object.  */
   2928  1.1  christos 	      if (info->shared && h->non_got_ref)
   2929  1.1  christos 		{
   2930  1.1  christos 		  Elf_Internal_Rela outrel;
   2931  1.1  christos 		  asection *sreloc;
   2932  1.1  christos 
   2933  1.1  christos 		  /* Need a dynamic relocation to get the real function
   2934  1.1  christos 		     address.  */
   2935  1.1  christos 		  outrel.r_offset = _bfd_elf_section_offset (output_bfd,
   2936  1.1  christos 							     info,
   2937  1.1  christos 							     input_section,
   2938  1.1  christos 							     rel->r_offset);
   2939  1.1  christos 		  if (outrel.r_offset == (bfd_vma) -1
   2940  1.1  christos 		      || outrel.r_offset == (bfd_vma) -2)
   2941  1.1  christos 		    abort ();
   2942  1.1  christos 
   2943  1.1  christos 		  outrel.r_offset += (input_section->output_section->vma
   2944  1.1  christos 				      + input_section->output_offset);
   2945  1.1  christos 
   2946  1.1  christos 		  if (h->dynindx == -1
   2947  1.1  christos 		      || h->forced_local
   2948  1.1  christos 		      || info->executable)
   2949  1.1  christos 		    {
   2950  1.1  christos 		      /* This symbol is resolved locally.  */
   2951  1.1  christos 		      outrel.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
   2952  1.1  christos 		      outrel.r_addend = (h->root.u.def.value
   2953  1.1  christos 					 + h->root.u.def.section->output_section->vma
   2954  1.1  christos 					 + h->root.u.def.section->output_offset);
   2955  1.1  christos 		    }
   2956  1.1  christos 		  else
   2957  1.1  christos 		    {
   2958  1.1  christos 		      outrel.r_info = htab->r_info (h->dynindx, r_type);
   2959  1.1  christos 		      outrel.r_addend = 0;
   2960  1.1  christos 		    }
   2961  1.1  christos 
   2962  1.1  christos 		  sreloc = htab->elf.irelifunc;
   2963  1.1  christos 		  elf_append_rela (output_bfd, sreloc, &outrel);
   2964  1.1  christos 
   2965  1.1  christos 		  /* If this reloc is against an external symbol, we
   2966  1.1  christos 		     do not want to fiddle with the addend.  Otherwise,
   2967  1.1  christos 		     we need to include the symbol value so that it
   2968  1.1  christos 		     becomes an addend for the dynamic reloc.  For an
   2969  1.1  christos 		     internal symbol, we have updated addend.  */
   2970  1.1  christos 		  continue;
   2971  1.1  christos 		}
   2972  1.1  christos 	      /* FALLTHROUGH */
   2973  1.1  christos 	    case R_X86_64_PC32:
   2974  1.1  christos 	    case R_X86_64_PC64:
   2975  1.1  christos 	    case R_X86_64_PLT32:
   2976  1.1  christos 	      goto do_relocation;
   2977  1.1  christos 
   2978  1.1  christos 	    case R_X86_64_GOTPCREL:
   2979  1.1  christos 	    case R_X86_64_GOTPCREL64:
   2980  1.1  christos 	      base_got = htab->elf.sgot;
   2981  1.1  christos 	      off = h->got.offset;
   2982  1.1  christos 
   2983  1.1  christos 	      if (base_got == NULL)
   2984  1.1  christos 		abort ();
   2985  1.1  christos 
   2986  1.1  christos 	      if (off == (bfd_vma) -1)
   2987  1.1  christos 		{
   2988  1.1  christos 		  /* We can't use h->got.offset here to save state, or
   2989  1.1  christos 		     even just remember the offset, as finish_dynamic_symbol
   2990  1.1  christos 		     would use that as offset into .got.  */
   2991  1.1  christos 
   2992  1.1  christos 		  if (htab->elf.splt != NULL)
   2993  1.1  christos 		    {
   2994  1.1  christos 		      plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
   2995  1.1  christos 		      off = (plt_index + 3) * GOT_ENTRY_SIZE;
   2996  1.1  christos 		      base_got = htab->elf.sgotplt;
   2997  1.1  christos 		    }
   2998  1.1  christos 		  else
   2999  1.1  christos 		    {
   3000  1.1  christos 		      plt_index = h->plt.offset / PLT_ENTRY_SIZE;
   3001  1.1  christos 		      off = plt_index * GOT_ENTRY_SIZE;
   3002  1.1  christos 		      base_got = htab->elf.igotplt;
   3003  1.1  christos 		    }
   3004  1.1  christos 
   3005  1.1  christos 		  if (h->dynindx == -1
   3006  1.1  christos 		      || h->forced_local
   3007  1.1  christos 		      || info->symbolic)
   3008  1.1  christos 		    {
   3009  1.1  christos 		      /* This references the local defitionion.  We must
   3010  1.1  christos 			 initialize this entry in the global offset table.
   3011  1.1  christos 			 Since the offset must always be a multiple of 8,
   3012  1.1  christos 			 we use the least significant bit to record
   3013  1.1  christos 			 whether we have initialized it already.
   3014  1.1  christos 
   3015  1.1  christos 			 When doing a dynamic link, we create a .rela.got
   3016  1.1  christos 			 relocation entry to initialize the value.  This
   3017  1.1  christos 			 is done in the finish_dynamic_symbol routine.	 */
   3018  1.1  christos 		      if ((off & 1) != 0)
   3019  1.1  christos 			off &= ~1;
   3020  1.1  christos 		      else
   3021  1.1  christos 			{
   3022  1.1  christos 			  bfd_put_64 (output_bfd, relocation,
   3023  1.1  christos 				      base_got->contents + off);
   3024  1.1  christos 			  /* Note that this is harmless for the GOTPLT64
   3025  1.1  christos 			     case, as -1 | 1 still is -1.  */
   3026  1.1  christos 			  h->got.offset |= 1;
   3027  1.1  christos 			}
   3028  1.1  christos 		    }
   3029  1.1  christos 		}
   3030  1.1  christos 
   3031  1.1  christos 	      relocation = (base_got->output_section->vma
   3032  1.1  christos 			    + base_got->output_offset + off);
   3033  1.1  christos 
   3034  1.1  christos 	      goto do_relocation;
   3035  1.1  christos 	    }
   3036  1.1  christos 	}
   3037  1.1  christos 
   3038  1.1  christos       /* When generating a shared object, the relocations handled here are
   3039  1.1  christos 	 copied into the output file to be resolved at run time.  */
   3040  1.1  christos       switch (r_type)
   3041  1.1  christos 	{
   3042  1.1  christos 	case R_X86_64_GOT32:
   3043  1.1  christos 	case R_X86_64_GOT64:
   3044  1.1  christos 	  /* Relocation is to the entry for this symbol in the global
   3045  1.1  christos 	     offset table.  */
   3046  1.1  christos 	case R_X86_64_GOTPCREL:
   3047  1.1  christos 	case R_X86_64_GOTPCREL64:
   3048  1.1  christos 	  /* Use global offset table entry as symbol value.  */
   3049  1.1  christos 	case R_X86_64_GOTPLT64:
   3050  1.1  christos 	  /* This is the same as GOT64 for relocation purposes, but
   3051  1.1  christos 	     indicates the existence of a PLT entry.  The difficulty is,
   3052  1.1  christos 	     that we must calculate the GOT slot offset from the PLT
   3053  1.1  christos 	     offset, if this symbol got a PLT entry (it was global).
   3054  1.1  christos 	     Additionally if it's computed from the PLT entry, then that
   3055  1.1  christos 	     GOT offset is relative to .got.plt, not to .got.  */
   3056  1.1  christos 	  base_got = htab->elf.sgot;
   3057  1.1  christos 
   3058  1.1  christos 	  if (htab->elf.sgot == NULL)
   3059  1.1  christos 	    abort ();
   3060  1.1  christos 
   3061  1.1  christos 	  if (h != NULL)
   3062  1.1  christos 	    {
   3063  1.1  christos 	      bfd_boolean dyn;
   3064  1.1  christos 
   3065  1.1  christos 	      off = h->got.offset;
   3066  1.1  christos 	      if (h->needs_plt
   3067  1.1  christos 	          && h->plt.offset != (bfd_vma)-1
   3068  1.1  christos 		  && off == (bfd_vma)-1)
   3069  1.1  christos 		{
   3070  1.1  christos 		  /* We can't use h->got.offset here to save
   3071  1.1  christos 		     state, or even just remember the offset, as
   3072  1.1  christos 		     finish_dynamic_symbol would use that as offset into
   3073  1.1  christos 		     .got.  */
   3074  1.1  christos 		  bfd_vma plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
   3075  1.1  christos 		  off = (plt_index + 3) * GOT_ENTRY_SIZE;
   3076  1.1  christos 		  base_got = htab->elf.sgotplt;
   3077  1.1  christos 		}
   3078  1.1  christos 
   3079  1.1  christos 	      dyn = htab->elf.dynamic_sections_created;
   3080  1.1  christos 
   3081  1.1  christos 	      if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
   3082  1.1  christos 		  || (info->shared
   3083  1.1  christos 		      && SYMBOL_REFERENCES_LOCAL (info, h))
   3084  1.1  christos 		  || (ELF_ST_VISIBILITY (h->other)
   3085  1.1  christos 		      && h->root.type == bfd_link_hash_undefweak))
   3086  1.1  christos 		{
   3087  1.1  christos 		  /* This is actually a static link, or it is a -Bsymbolic
   3088  1.1  christos 		     link and the symbol is defined locally, or the symbol
   3089  1.1  christos 		     was forced to be local because of a version file.	We
   3090  1.1  christos 		     must initialize this entry in the global offset table.
   3091  1.1  christos 		     Since the offset must always be a multiple of 8, we
   3092  1.1  christos 		     use the least significant bit to record whether we
   3093  1.1  christos 		     have initialized it already.
   3094  1.1  christos 
   3095  1.1  christos 		     When doing a dynamic link, we create a .rela.got
   3096  1.1  christos 		     relocation entry to initialize the value.	This is
   3097  1.1  christos 		     done in the finish_dynamic_symbol routine.	 */
   3098  1.1  christos 		  if ((off & 1) != 0)
   3099  1.1  christos 		    off &= ~1;
   3100  1.1  christos 		  else
   3101  1.1  christos 		    {
   3102  1.1  christos 		      bfd_put_64 (output_bfd, relocation,
   3103  1.1  christos 				  base_got->contents + off);
   3104  1.1  christos 		      /* Note that this is harmless for the GOTPLT64 case,
   3105  1.1  christos 		         as -1 | 1 still is -1.  */
   3106  1.1  christos 		      h->got.offset |= 1;
   3107  1.1  christos 		    }
   3108  1.1  christos 		}
   3109  1.1  christos 	      else
   3110  1.1  christos 		unresolved_reloc = FALSE;
   3111  1.1  christos 	    }
   3112  1.1  christos 	  else
   3113  1.1  christos 	    {
   3114  1.1  christos 	      if (local_got_offsets == NULL)
   3115  1.1  christos 		abort ();
   3116  1.1  christos 
   3117  1.1  christos 	      off = local_got_offsets[r_symndx];
   3118  1.1  christos 
   3119  1.1  christos 	      /* The offset must always be a multiple of 8.  We use
   3120  1.1  christos 		 the least significant bit to record whether we have
   3121  1.1  christos 		 already generated the necessary reloc.	 */
   3122  1.1  christos 	      if ((off & 1) != 0)
   3123  1.1  christos 		off &= ~1;
   3124  1.1  christos 	      else
   3125  1.1  christos 		{
   3126  1.1  christos 		  bfd_put_64 (output_bfd, relocation,
   3127  1.1  christos 			      base_got->contents + off);
   3128  1.1  christos 
   3129  1.1  christos 		  if (info->shared)
   3130  1.1  christos 		    {
   3131  1.1  christos 		      asection *s;
   3132  1.1  christos 		      Elf_Internal_Rela outrel;
   3133  1.1  christos 
   3134  1.1  christos 		      /* We need to generate a R_X86_64_RELATIVE reloc
   3135  1.1  christos 			 for the dynamic linker.  */
   3136  1.1  christos 		      s = htab->elf.srelgot;
   3137  1.1  christos 		      if (s == NULL)
   3138  1.1  christos 			abort ();
   3139  1.1  christos 
   3140  1.1  christos 		      outrel.r_offset = (base_got->output_section->vma
   3141  1.1  christos 					 + base_got->output_offset
   3142  1.1  christos 					 + off);
   3143  1.1  christos 		      outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
   3144  1.1  christos 		      outrel.r_addend = relocation;
   3145  1.1  christos 		      elf_append_rela (output_bfd, s, &outrel);
   3146  1.1  christos 		    }
   3147  1.1  christos 
   3148  1.1  christos 		  local_got_offsets[r_symndx] |= 1;
   3149  1.1  christos 		}
   3150  1.1  christos 	    }
   3151  1.1  christos 
   3152  1.1  christos 	  if (off >= (bfd_vma) -2)
   3153  1.1  christos 	    abort ();
   3154  1.1  christos 
   3155  1.1  christos 	  relocation = base_got->output_section->vma
   3156  1.1  christos 		       + base_got->output_offset + off;
   3157  1.1  christos 	  if (r_type != R_X86_64_GOTPCREL && r_type != R_X86_64_GOTPCREL64)
   3158  1.1  christos 	    relocation -= htab->elf.sgotplt->output_section->vma
   3159  1.1  christos 			  - htab->elf.sgotplt->output_offset;
   3160  1.1  christos 
   3161  1.1  christos 	  break;
   3162  1.1  christos 
   3163  1.1  christos 	case R_X86_64_GOTOFF64:
   3164  1.1  christos 	  /* Relocation is relative to the start of the global offset
   3165  1.1  christos 	     table.  */
   3166  1.1  christos 
   3167  1.1  christos 	  /* Check to make sure it isn't a protected function symbol
   3168  1.1  christos 	     for shared library since it may not be local when used
   3169  1.1  christos 	     as function address.  */
   3170  1.1  christos 	  if (info->shared
   3171  1.1  christos 	      && h
   3172  1.1  christos 	      && h->def_regular
   3173  1.1  christos 	      && h->type == STT_FUNC
   3174  1.1  christos 	      && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
   3175  1.1  christos 	    {
   3176  1.1  christos 	      (*_bfd_error_handler)
   3177  1.1  christos 		(_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
   3178  1.1  christos 		 input_bfd, h->root.root.string);
   3179  1.1  christos 	      bfd_set_error (bfd_error_bad_value);
   3180  1.1  christos 	      return FALSE;
   3181  1.1  christos 	    }
   3182  1.1  christos 
   3183  1.1  christos 	  /* Note that sgot is not involved in this
   3184  1.1  christos 	     calculation.  We always want the start of .got.plt.  If we
   3185  1.1  christos 	     defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
   3186  1.1  christos 	     permitted by the ABI, we might have to change this
   3187  1.1  christos 	     calculation.  */
   3188  1.1  christos 	  relocation -= htab->elf.sgotplt->output_section->vma
   3189  1.1  christos 			+ htab->elf.sgotplt->output_offset;
   3190  1.1  christos 	  break;
   3191  1.1  christos 
   3192  1.1  christos 	case R_X86_64_GOTPC32:
   3193  1.1  christos 	case R_X86_64_GOTPC64:
   3194  1.1  christos 	  /* Use global offset table as symbol value.  */
   3195  1.1  christos 	  relocation = htab->elf.sgotplt->output_section->vma
   3196  1.1  christos 		       + htab->elf.sgotplt->output_offset;
   3197  1.1  christos 	  unresolved_reloc = FALSE;
   3198  1.1  christos 	  break;
   3199  1.1  christos 
   3200  1.1  christos 	case R_X86_64_PLTOFF64:
   3201  1.1  christos 	  /* Relocation is PLT entry relative to GOT.  For local
   3202  1.1  christos 	     symbols it's the symbol itself relative to GOT.  */
   3203  1.1  christos           if (h != NULL
   3204  1.1  christos 	      /* See PLT32 handling.  */
   3205  1.1  christos 	      && h->plt.offset != (bfd_vma) -1
   3206  1.1  christos 	      && htab->elf.splt != NULL)
   3207  1.1  christos 	    {
   3208  1.1  christos 	      relocation = (htab->elf.splt->output_section->vma
   3209  1.1  christos 			    + htab->elf.splt->output_offset
   3210  1.1  christos 			    + h->plt.offset);
   3211  1.1  christos 	      unresolved_reloc = FALSE;
   3212  1.1  christos 	    }
   3213  1.1  christos 
   3214  1.1  christos 	  relocation -= htab->elf.sgotplt->output_section->vma
   3215  1.1  christos 			+ htab->elf.sgotplt->output_offset;
   3216  1.1  christos 	  break;
   3217  1.1  christos 
   3218  1.1  christos 	case R_X86_64_PLT32:
   3219  1.1  christos 	  /* Relocation is to the entry for this symbol in the
   3220  1.1  christos 	     procedure linkage table.  */
   3221  1.1  christos 
   3222  1.1  christos 	  /* Resolve a PLT32 reloc against a local symbol directly,
   3223  1.1  christos 	     without using the procedure linkage table.	 */
   3224  1.1  christos 	  if (h == NULL)
   3225  1.1  christos 	    break;
   3226  1.1  christos 
   3227  1.1  christos 	  if (h->plt.offset == (bfd_vma) -1
   3228  1.1  christos 	      || htab->elf.splt == NULL)
   3229  1.1  christos 	    {
   3230  1.1  christos 	      /* We didn't make a PLT entry for this symbol.  This
   3231  1.1  christos 		 happens when statically linking PIC code, or when
   3232  1.1  christos 		 using -Bsymbolic.  */
   3233  1.1  christos 	      break;
   3234  1.1  christos 	    }
   3235  1.1  christos 
   3236  1.1  christos 	  relocation = (htab->elf.splt->output_section->vma
   3237  1.1  christos 			+ htab->elf.splt->output_offset
   3238  1.1  christos 			+ h->plt.offset);
   3239  1.1  christos 	  unresolved_reloc = FALSE;
   3240  1.1  christos 	  break;
   3241  1.1  christos 
   3242  1.1  christos 	case R_X86_64_PC8:
   3243  1.1  christos 	case R_X86_64_PC16:
   3244  1.1  christos 	case R_X86_64_PC32:
   3245  1.1  christos 	  if (info->shared
   3246  1.1  christos 	      && ABI_64_P (output_bfd)
   3247  1.1  christos 	      && (input_section->flags & SEC_ALLOC) != 0
   3248  1.1  christos 	      && (input_section->flags & SEC_READONLY) != 0
   3249  1.1  christos 	      && h != NULL)
   3250  1.1  christos 	    {
   3251  1.1  christos 	      bfd_boolean fail = FALSE;
   3252  1.1  christos 	      bfd_boolean branch
   3253  1.1  christos 		= (r_type == R_X86_64_PC32
   3254  1.1  christos 		   && is_32bit_relative_branch (contents, rel->r_offset));
   3255  1.1  christos 
   3256  1.1  christos 	      if (SYMBOL_REFERENCES_LOCAL (info, h))
   3257  1.1  christos 		{
   3258  1.1  christos 		  /* Symbol is referenced locally.  Make sure it is
   3259  1.1  christos 		     defined locally or for a branch.  */
   3260  1.1  christos 		  fail = !h->def_regular && !branch;
   3261  1.1  christos 		}
   3262  1.1  christos 	      else
   3263  1.1  christos 		{
   3264  1.1  christos 		  /* Symbol isn't referenced locally.  We only allow
   3265  1.1  christos 		     branch to symbol with non-default visibility. */
   3266  1.1  christos 		  fail = (!branch
   3267  1.1  christos 			  || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
   3268  1.1  christos 		}
   3269  1.1  christos 
   3270  1.1  christos 	      if (fail)
   3271  1.1  christos 		{
   3272  1.1  christos 		  const char *fmt;
   3273  1.1  christos 		  const char *v;
   3274  1.1  christos 		  const char *pic = "";
   3275  1.1  christos 
   3276  1.1  christos 		  switch (ELF_ST_VISIBILITY (h->other))
   3277  1.1  christos 		    {
   3278  1.1  christos 		    case STV_HIDDEN:
   3279  1.1  christos 		      v = _("hidden symbol");
   3280  1.1  christos 		      break;
   3281  1.1  christos 		    case STV_INTERNAL:
   3282  1.1  christos 		      v = _("internal symbol");
   3283  1.1  christos 		      break;
   3284  1.1  christos 		    case STV_PROTECTED:
   3285  1.1  christos 		      v = _("protected symbol");
   3286  1.1  christos 		      break;
   3287  1.1  christos 		    default:
   3288  1.1  christos 		      v = _("symbol");
   3289  1.1  christos 		      pic = _("; recompile with -fPIC");
   3290  1.1  christos 		      break;
   3291  1.1  christos 		    }
   3292  1.1  christos 
   3293  1.1  christos 		  if (h->def_regular)
   3294  1.1  christos 		    fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
   3295  1.1  christos 		  else
   3296  1.1  christos 		    fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
   3297  1.1  christos 
   3298  1.1  christos 		  (*_bfd_error_handler) (fmt, input_bfd,
   3299  1.1  christos 					 x86_64_elf_howto_table[r_type].name,
   3300  1.1  christos 					 v,  h->root.root.string, pic);
   3301  1.1  christos 		  bfd_set_error (bfd_error_bad_value);
   3302  1.1  christos 		  return FALSE;
   3303  1.1  christos 		}
   3304  1.1  christos 	    }
   3305  1.1  christos 	  /* Fall through.  */
   3306  1.1  christos 
   3307  1.1  christos 	case R_X86_64_8:
   3308  1.1  christos 	case R_X86_64_16:
   3309  1.1  christos 	case R_X86_64_32:
   3310  1.1  christos 	case R_X86_64_PC64:
   3311  1.1  christos 	case R_X86_64_64:
   3312  1.1  christos 	  /* FIXME: The ABI says the linker should make sure the value is
   3313  1.1  christos 	     the same when it's zeroextended to 64 bit.	 */
   3314  1.1  christos 
   3315  1.1  christos 	  if ((input_section->flags & SEC_ALLOC) == 0)
   3316  1.1  christos 	    break;
   3317  1.1  christos 
   3318  1.1  christos 	  if ((info->shared
   3319  1.1  christos 	       && (h == NULL
   3320  1.1  christos 		   || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
   3321  1.1  christos 		   || h->root.type != bfd_link_hash_undefweak)
   3322  1.1  christos 	       && (! IS_X86_64_PCREL_TYPE (r_type)
   3323  1.1  christos 		   || ! SYMBOL_CALLS_LOCAL (info, h)))
   3324  1.1  christos 	      || (ELIMINATE_COPY_RELOCS
   3325  1.1  christos 		  && !info->shared
   3326  1.1  christos 		  && h != NULL
   3327  1.1  christos 		  && h->dynindx != -1
   3328  1.1  christos 		  && !h->non_got_ref
   3329  1.1  christos 		  && ((h->def_dynamic
   3330  1.1  christos 		       && !h->def_regular)
   3331  1.1  christos 		      || h->root.type == bfd_link_hash_undefweak
   3332  1.1  christos 		      || h->root.type == bfd_link_hash_undefined)))
   3333  1.1  christos 	    {
   3334  1.1  christos 	      Elf_Internal_Rela outrel;
   3335  1.1  christos 	      bfd_boolean skip, relocate;
   3336  1.1  christos 	      asection *sreloc;
   3337  1.1  christos 
   3338  1.1  christos 	      /* When generating a shared object, these relocations
   3339  1.1  christos 		 are copied into the output file to be resolved at run
   3340  1.1  christos 		 time.	*/
   3341  1.1  christos 	      skip = FALSE;
   3342  1.1  christos 	      relocate = FALSE;
   3343  1.1  christos 
   3344  1.1  christos 	      outrel.r_offset =
   3345  1.1  christos 		_bfd_elf_section_offset (output_bfd, info, input_section,
   3346  1.1  christos 					 rel->r_offset);
   3347  1.1  christos 	      if (outrel.r_offset == (bfd_vma) -1)
   3348  1.1  christos 		skip = TRUE;
   3349  1.1  christos 	      else if (outrel.r_offset == (bfd_vma) -2)
   3350  1.1  christos 		skip = TRUE, relocate = TRUE;
   3351  1.1  christos 
   3352  1.1  christos 	      outrel.r_offset += (input_section->output_section->vma
   3353  1.1  christos 				  + input_section->output_offset);
   3354  1.1  christos 
   3355  1.1  christos 	      if (skip)
   3356  1.1  christos 		memset (&outrel, 0, sizeof outrel);
   3357  1.1  christos 
   3358  1.1  christos 	      /* h->dynindx may be -1 if this symbol was marked to
   3359  1.1  christos 		 become local.  */
   3360  1.1  christos 	      else if (h != NULL
   3361  1.1  christos 		       && h->dynindx != -1
   3362  1.1  christos 		       && (IS_X86_64_PCREL_TYPE (r_type)
   3363  1.1  christos 			   || ! info->shared
   3364  1.1  christos 			   || ! SYMBOLIC_BIND (info, h)
   3365  1.1  christos 			   || ! h->def_regular))
   3366  1.1  christos 		{
   3367  1.1  christos 		  outrel.r_info = htab->r_info (h->dynindx, r_type);
   3368  1.1  christos 		  outrel.r_addend = rel->r_addend;
   3369  1.1  christos 		}
   3370  1.1  christos 	      else
   3371  1.1  christos 		{
   3372  1.1  christos 		  /* This symbol is local, or marked to become local.  */
   3373  1.1  christos 		  if (r_type == htab->pointer_r_type)
   3374  1.1  christos 		    {
   3375  1.1  christos 		      relocate = TRUE;
   3376  1.1  christos 		      outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
   3377  1.1  christos 		      outrel.r_addend = relocation + rel->r_addend;
   3378  1.1  christos 		    }
   3379  1.1  christos 		  else
   3380  1.1  christos 		    {
   3381  1.1  christos 		      long sindx;
   3382  1.1  christos 
   3383  1.1  christos 		      if (bfd_is_abs_section (sec))
   3384  1.1  christos 			sindx = 0;
   3385  1.1  christos 		      else if (sec == NULL || sec->owner == NULL)
   3386  1.1  christos 			{
   3387  1.1  christos 			  bfd_set_error (bfd_error_bad_value);
   3388  1.1  christos 			  return FALSE;
   3389  1.1  christos 			}
   3390  1.1  christos 		      else
   3391  1.1  christos 			{
   3392  1.1  christos 			  asection *osec;
   3393  1.1  christos 
   3394  1.1  christos 			  /* We are turning this relocation into one
   3395  1.1  christos 			     against a section symbol.  It would be
   3396  1.1  christos 			     proper to subtract the symbol's value,
   3397  1.1  christos 			     osec->vma, from the emitted reloc addend,
   3398  1.1  christos 			     but ld.so expects buggy relocs.  */
   3399  1.1  christos 			  osec = sec->output_section;
   3400  1.1  christos 			  sindx = elf_section_data (osec)->dynindx;
   3401  1.1  christos 			  if (sindx == 0)
   3402  1.1  christos 			    {
   3403  1.1  christos 			      asection *oi = htab->elf.text_index_section;
   3404  1.1  christos 			      sindx = elf_section_data (oi)->dynindx;
   3405  1.1  christos 			    }
   3406  1.1  christos 			  BFD_ASSERT (sindx != 0);
   3407  1.1  christos 			}
   3408  1.1  christos 
   3409  1.1  christos 		      outrel.r_info = htab->r_info (sindx, r_type);
   3410  1.1  christos 		      outrel.r_addend = relocation + rel->r_addend;
   3411  1.1  christos 		    }
   3412  1.1  christos 		}
   3413  1.1  christos 
   3414  1.1  christos 	      sreloc = elf_section_data (input_section)->sreloc;
   3415  1.1  christos 
   3416  1.1  christos 	      BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL);
   3417  1.1  christos 
   3418  1.1  christos 	      elf_append_rela (output_bfd, sreloc, &outrel);
   3419  1.1  christos 
   3420  1.1  christos 	      /* If this reloc is against an external symbol, we do
   3421  1.1  christos 		 not want to fiddle with the addend.  Otherwise, we
   3422  1.1  christos 		 need to include the symbol value so that it becomes
   3423  1.1  christos 		 an addend for the dynamic reloc.  */
   3424  1.1  christos 	      if (! relocate)
   3425  1.1  christos 		continue;
   3426  1.1  christos 	    }
   3427  1.1  christos 
   3428  1.1  christos 	  break;
   3429  1.1  christos 
   3430  1.1  christos 	case R_X86_64_TLSGD:
   3431  1.1  christos 	case R_X86_64_GOTPC32_TLSDESC:
   3432  1.1  christos 	case R_X86_64_TLSDESC_CALL:
   3433  1.1  christos 	case R_X86_64_GOTTPOFF:
   3434  1.1  christos 	  tls_type = GOT_UNKNOWN;
   3435  1.1  christos 	  if (h == NULL && local_got_offsets)
   3436  1.1  christos 	    tls_type = elf_x86_64_local_got_tls_type (input_bfd) [r_symndx];
   3437  1.1  christos 	  else if (h != NULL)
   3438  1.1  christos 	    tls_type = elf_x86_64_hash_entry (h)->tls_type;
   3439  1.1  christos 
   3440  1.1  christos 	  if (! elf_x86_64_tls_transition (info, input_bfd,
   3441  1.1  christos 					   input_section, contents,
   3442  1.1  christos 					   symtab_hdr, sym_hashes,
   3443  1.1  christos 					   &r_type, tls_type, rel,
   3444  1.1  christos 					   relend, h, r_symndx))
   3445  1.1  christos 	    return FALSE;
   3446  1.1  christos 
   3447  1.1  christos 	  if (r_type == R_X86_64_TPOFF32)
   3448  1.1  christos 	    {
   3449  1.1  christos 	      bfd_vma roff = rel->r_offset;
   3450  1.1  christos 
   3451  1.1  christos 	      BFD_ASSERT (! unresolved_reloc);
   3452  1.1  christos 
   3453  1.1  christos 	      if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
   3454  1.1  christos 		{
   3455  1.1  christos 		  /* GD->LE transition.  For 64bit, change
   3456  1.1  christos 		     .byte 0x66; leaq foo@tlsgd(%rip), %rdi
   3457  1.1  christos 		     .word 0x6666; rex64; call __tls_get_addr
   3458  1.1  christos 		     into:
   3459  1.1  christos 		     movq %fs:0, %rax
   3460  1.1  christos 		     leaq foo@tpoff(%rax), %rax
   3461  1.1  christos 		     For 32bit, change
   3462  1.1  christos 		     leaq foo@tlsgd(%rip), %rdi
   3463  1.1  christos 		     .word 0x6666; rex64; call __tls_get_addr
   3464  1.1  christos 		     into:
   3465  1.1  christos 		     movl %fs:0, %eax
   3466  1.1  christos 		     leaq foo@tpoff(%rax), %rax */
   3467  1.1  christos 		  if (ABI_64_P (output_bfd))
   3468  1.1  christos 		    memcpy (contents + roff - 4,
   3469  1.1  christos 			    "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
   3470  1.1  christos 			    16);
   3471  1.1  christos 		  else
   3472  1.1  christos 		    memcpy (contents + roff - 3,
   3473  1.1  christos 			    "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
   3474  1.1  christos 			    15);
   3475  1.1  christos 		  bfd_put_32 (output_bfd,
   3476  1.1  christos 			      elf_x86_64_tpoff (info, relocation),
   3477  1.1  christos 			      contents + roff + 8);
   3478  1.1  christos 		  /* Skip R_X86_64_PC32/R_X86_64_PLT32.  */
   3479  1.1  christos 		  rel++;
   3480  1.1  christos 		  continue;
   3481  1.1  christos 		}
   3482  1.1  christos 	      else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
   3483  1.1  christos 		{
   3484  1.1  christos 		  /* GDesc -> LE transition.
   3485  1.1  christos 		     It's originally something like:
   3486  1.1  christos 		     leaq x@tlsdesc(%rip), %rax
   3487  1.1  christos 
   3488  1.1  christos 		     Change it to:
   3489  1.1  christos 		     movl $x@tpoff, %rax.  */
   3490  1.1  christos 
   3491  1.1  christos 		  unsigned int val, type;
   3492  1.1  christos 
   3493  1.1  christos 		  type = bfd_get_8 (input_bfd, contents + roff - 3);
   3494  1.1  christos 		  val = bfd_get_8 (input_bfd, contents + roff - 1);
   3495  1.1  christos 		  bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),
   3496  1.1  christos 			     contents + roff - 3);
   3497  1.1  christos 		  bfd_put_8 (output_bfd, 0xc7, contents + roff - 2);
   3498  1.1  christos 		  bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
   3499  1.1  christos 			     contents + roff - 1);
   3500  1.1  christos 		  bfd_put_32 (output_bfd,
   3501  1.1  christos 			      elf_x86_64_tpoff (info, relocation),
   3502  1.1  christos 			      contents + roff);
   3503  1.1  christos 		  continue;
   3504  1.1  christos 		}
   3505  1.1  christos 	      else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
   3506  1.1  christos 		{
   3507  1.1  christos 		  /* GDesc -> LE transition.
   3508  1.1  christos 		     It's originally:
   3509  1.1  christos 		     call *(%rax)
   3510  1.1  christos 		     Turn it into:
   3511  1.1  christos 		     xchg %ax,%ax.  */
   3512  1.1  christos 		  bfd_put_8 (output_bfd, 0x66, contents + roff);
   3513  1.1  christos 		  bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
   3514  1.1  christos 		  continue;
   3515  1.1  christos 		}
   3516  1.1  christos 	      else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTTPOFF)
   3517  1.1  christos 		{
   3518  1.1  christos 		  /* IE->LE transition:
   3519  1.1  christos 		     Originally it can be one of:
   3520  1.1  christos 		     movq foo@gottpoff(%rip), %reg
   3521  1.1  christos 		     addq foo@gottpoff(%rip), %reg
   3522  1.1  christos 		     We change it into:
   3523  1.1  christos 		     movq $foo, %reg
   3524  1.1  christos 		     leaq foo(%reg), %reg
   3525  1.1  christos 		     addq $foo, %reg.  */
   3526  1.1  christos 
   3527  1.1  christos 		  unsigned int val, type, reg;
   3528  1.1  christos 
   3529  1.1  christos 		  val = bfd_get_8 (input_bfd, contents + roff - 3);
   3530  1.1  christos 		  type = bfd_get_8 (input_bfd, contents + roff - 2);
   3531  1.1  christos 		  reg = bfd_get_8 (input_bfd, contents + roff - 1);
   3532  1.1  christos 		  reg >>= 3;
   3533  1.1  christos 		  if (type == 0x8b)
   3534  1.1  christos 		    {
   3535  1.1  christos 		      /* movq */
   3536  1.1  christos 		      if (val == 0x4c)
   3537  1.1  christos 			bfd_put_8 (output_bfd, 0x49,
   3538  1.1  christos 				   contents + roff - 3);
   3539  1.1  christos 		      else if (!ABI_64_P (output_bfd) && val == 0x44)
   3540  1.1  christos 			bfd_put_8 (output_bfd, 0x41,
   3541  1.1  christos 				   contents + roff - 3);
   3542  1.1  christos 		      bfd_put_8 (output_bfd, 0xc7,
   3543  1.1  christos 				 contents + roff - 2);
   3544  1.1  christos 		      bfd_put_8 (output_bfd, 0xc0 | reg,
   3545  1.1  christos 				 contents + roff - 1);
   3546  1.1  christos 		    }
   3547  1.1  christos 		  else if (reg == 4)
   3548  1.1  christos 		    {
   3549  1.1  christos 		      /* addq -> addq - addressing with %rsp/%r12 is
   3550  1.1  christos 			 special  */
   3551  1.1  christos 		      if (val == 0x4c)
   3552  1.1  christos 			bfd_put_8 (output_bfd, 0x49,
   3553  1.1  christos 				   contents + roff - 3);
   3554  1.1  christos 		      else if (!ABI_64_P (output_bfd) && val == 0x44)
   3555  1.1  christos 			bfd_put_8 (output_bfd, 0x41,
   3556  1.1  christos 				   contents + roff - 3);
   3557  1.1  christos 		      bfd_put_8 (output_bfd, 0x81,
   3558  1.1  christos 				 contents + roff - 2);
   3559  1.1  christos 		      bfd_put_8 (output_bfd, 0xc0 | reg,
   3560  1.1  christos 				 contents + roff - 1);
   3561  1.1  christos 		    }
   3562  1.1  christos 		  else
   3563  1.1  christos 		    {
   3564  1.1  christos 		      /* addq -> leaq */
   3565  1.1  christos 		      if (val == 0x4c)
   3566  1.1  christos 			bfd_put_8 (output_bfd, 0x4d,
   3567  1.1  christos 				   contents + roff - 3);
   3568  1.1  christos 		      else if (!ABI_64_P (output_bfd) && val == 0x44)
   3569  1.1  christos 			bfd_put_8 (output_bfd, 0x45,
   3570  1.1  christos 				   contents + roff - 3);
   3571  1.1  christos 		      bfd_put_8 (output_bfd, 0x8d,
   3572  1.1  christos 				 contents + roff - 2);
   3573  1.1  christos 		      bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
   3574  1.1  christos 				 contents + roff - 1);
   3575  1.1  christos 		    }
   3576  1.1  christos 		  bfd_put_32 (output_bfd,
   3577  1.1  christos 			      elf_x86_64_tpoff (info, relocation),
   3578  1.1  christos 			      contents + roff);
   3579  1.1  christos 		  continue;
   3580  1.1  christos 		}
   3581  1.1  christos 	      else
   3582  1.1  christos 		BFD_ASSERT (FALSE);
   3583  1.1  christos 	    }
   3584  1.1  christos 
   3585  1.1  christos 	  if (htab->elf.sgot == NULL)
   3586  1.1  christos 	    abort ();
   3587  1.1  christos 
   3588  1.1  christos 	  if (h != NULL)
   3589  1.1  christos 	    {
   3590  1.1  christos 	      off = h->got.offset;
   3591  1.1  christos 	      offplt = elf_x86_64_hash_entry (h)->tlsdesc_got;
   3592  1.1  christos 	    }
   3593  1.1  christos 	  else
   3594  1.1  christos 	    {
   3595  1.1  christos 	      if (local_got_offsets == NULL)
   3596  1.1  christos 		abort ();
   3597  1.1  christos 
   3598  1.1  christos 	      off = local_got_offsets[r_symndx];
   3599  1.1  christos 	      offplt = local_tlsdesc_gotents[r_symndx];
   3600  1.1  christos 	    }
   3601  1.1  christos 
   3602  1.1  christos 	  if ((off & 1) != 0)
   3603  1.1  christos 	    off &= ~1;
   3604  1.1  christos 	  else
   3605  1.1  christos 	    {
   3606  1.1  christos 	      Elf_Internal_Rela outrel;
   3607  1.1  christos 	      int dr_type, indx;
   3608  1.1  christos 	      asection *sreloc;
   3609  1.1  christos 
   3610  1.1  christos 	      if (htab->elf.srelgot == NULL)
   3611  1.1  christos 		abort ();
   3612  1.1  christos 
   3613  1.1  christos 	      indx = h && h->dynindx != -1 ? h->dynindx : 0;
   3614  1.1  christos 
   3615  1.1  christos 	      if (GOT_TLS_GDESC_P (tls_type))
   3616  1.1  christos 		{
   3617  1.1  christos 		  outrel.r_info = htab->r_info (indx, R_X86_64_TLSDESC);
   3618  1.1  christos 		  BFD_ASSERT (htab->sgotplt_jump_table_size + offplt
   3619  1.1  christos 			      + 2 * GOT_ENTRY_SIZE <= htab->elf.sgotplt->size);
   3620  1.1  christos 		  outrel.r_offset = (htab->elf.sgotplt->output_section->vma
   3621  1.1  christos 				     + htab->elf.sgotplt->output_offset
   3622  1.1  christos 				     + offplt
   3623  1.1  christos 				     + htab->sgotplt_jump_table_size);
   3624  1.1  christos 		  sreloc = htab->elf.srelplt;
   3625  1.1  christos 		  if (indx == 0)
   3626  1.1  christos 		    outrel.r_addend = relocation - elf_x86_64_dtpoff_base (info);
   3627  1.1  christos 		  else
   3628  1.1  christos 		    outrel.r_addend = 0;
   3629  1.1  christos 		  elf_append_rela (output_bfd, sreloc, &outrel);
   3630  1.1  christos 		}
   3631  1.1  christos 
   3632  1.1  christos 	      sreloc = htab->elf.srelgot;
   3633  1.1  christos 
   3634  1.1  christos 	      outrel.r_offset = (htab->elf.sgot->output_section->vma
   3635  1.1  christos 				 + htab->elf.sgot->output_offset + off);
   3636  1.1  christos 
   3637  1.1  christos 	      if (GOT_TLS_GD_P (tls_type))
   3638  1.1  christos 		dr_type = R_X86_64_DTPMOD64;
   3639  1.1  christos 	      else if (GOT_TLS_GDESC_P (tls_type))
   3640  1.1  christos 		goto dr_done;
   3641  1.1  christos 	      else
   3642  1.1  christos 		dr_type = R_X86_64_TPOFF64;
   3643  1.1  christos 
   3644  1.1  christos 	      bfd_put_64 (output_bfd, 0, htab->elf.sgot->contents + off);
   3645  1.1  christos 	      outrel.r_addend = 0;
   3646  1.1  christos 	      if ((dr_type == R_X86_64_TPOFF64
   3647  1.1  christos 		   || dr_type == R_X86_64_TLSDESC) && indx == 0)
   3648  1.1  christos 		outrel.r_addend = relocation - elf_x86_64_dtpoff_base (info);
   3649  1.1  christos 	      outrel.r_info = htab->r_info (indx, dr_type);
   3650  1.1  christos 
   3651  1.1  christos 	      elf_append_rela (output_bfd, sreloc, &outrel);
   3652  1.1  christos 
   3653  1.1  christos 	      if (GOT_TLS_GD_P (tls_type))
   3654  1.1  christos 		{
   3655  1.1  christos 		  if (indx == 0)
   3656  1.1  christos 		    {
   3657  1.1  christos 		      BFD_ASSERT (! unresolved_reloc);
   3658  1.1  christos 		      bfd_put_64 (output_bfd,
   3659  1.1  christos 				  relocation - elf_x86_64_dtpoff_base (info),
   3660  1.1  christos 				  htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
   3661  1.1  christos 		    }
   3662  1.1  christos 		  else
   3663  1.1  christos 		    {
   3664  1.1  christos 		      bfd_put_64 (output_bfd, 0,
   3665  1.1  christos 				  htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
   3666  1.1  christos 		      outrel.r_info = htab->r_info (indx,
   3667  1.1  christos 						    R_X86_64_DTPOFF64);
   3668  1.1  christos 		      outrel.r_offset += GOT_ENTRY_SIZE;
   3669  1.1  christos 		      elf_append_rela (output_bfd, sreloc,
   3670  1.1  christos 						&outrel);
   3671  1.1  christos 		    }
   3672  1.1  christos 		}
   3673  1.1  christos 
   3674  1.1  christos 	    dr_done:
   3675  1.1  christos 	      if (h != NULL)
   3676  1.1  christos 		h->got.offset |= 1;
   3677  1.1  christos 	      else
   3678  1.1  christos 		local_got_offsets[r_symndx] |= 1;
   3679  1.1  christos 	    }
   3680  1.1  christos 
   3681  1.1  christos 	  if (off >= (bfd_vma) -2
   3682  1.1  christos 	      && ! GOT_TLS_GDESC_P (tls_type))
   3683  1.1  christos 	    abort ();
   3684  1.1  christos 	  if (r_type == ELF32_R_TYPE (rel->r_info))
   3685  1.1  christos 	    {
   3686  1.1  christos 	      if (r_type == R_X86_64_GOTPC32_TLSDESC
   3687  1.1  christos 		  || r_type == R_X86_64_TLSDESC_CALL)
   3688  1.1  christos 		relocation = htab->elf.sgotplt->output_section->vma
   3689  1.1  christos 		  + htab->elf.sgotplt->output_offset
   3690  1.1  christos 		  + offplt + htab->sgotplt_jump_table_size;
   3691  1.1  christos 	      else
   3692  1.1  christos 		relocation = htab->elf.sgot->output_section->vma
   3693  1.1  christos 		  + htab->elf.sgot->output_offset + off;
   3694  1.1  christos 	      unresolved_reloc = FALSE;
   3695  1.1  christos 	    }
   3696  1.1  christos 	  else
   3697  1.1  christos 	    {
   3698  1.1  christos 	      bfd_vma roff = rel->r_offset;
   3699  1.1  christos 
   3700  1.1  christos 	      if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
   3701  1.1  christos 		{
   3702  1.1  christos 		  /* GD->IE transition.  For 64bit, change
   3703  1.1  christos 		     .byte 0x66; leaq foo@tlsgd(%rip), %rdi
   3704  1.1  christos 		     .word 0x6666; rex64; call __tls_get_addr@plt
   3705  1.1  christos 		     into:
   3706  1.1  christos 		     movq %fs:0, %rax
   3707  1.1  christos 		     addq foo@gottpoff(%rip), %rax
   3708  1.1  christos 		     For 32bit, change
   3709  1.1  christos 		     leaq foo@tlsgd(%rip), %rdi
   3710  1.1  christos 		     .word 0x6666; rex64; call __tls_get_addr@plt
   3711  1.1  christos 		     into:
   3712  1.1  christos 		     movl %fs:0, %eax
   3713  1.1  christos 		     addq foo@gottpoff(%rip), %rax */
   3714  1.1  christos 		  if (ABI_64_P (output_bfd))
   3715  1.1  christos 		    memcpy (contents + roff - 4,
   3716  1.1  christos 			    "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
   3717  1.1  christos 			    16);
   3718  1.1  christos 		  else
   3719  1.1  christos 		    memcpy (contents + roff - 3,
   3720  1.1  christos 			    "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
   3721  1.1  christos 			    15);
   3722  1.1  christos 
   3723  1.1  christos 		  relocation = (htab->elf.sgot->output_section->vma
   3724  1.1  christos 				+ htab->elf.sgot->output_offset + off
   3725  1.1  christos 				- roff
   3726  1.1  christos 				- input_section->output_section->vma
   3727  1.1  christos 				- input_section->output_offset
   3728  1.1  christos 				- 12);
   3729  1.1  christos 		  bfd_put_32 (output_bfd, relocation,
   3730  1.1  christos 			      contents + roff + 8);
   3731  1.1  christos 		  /* Skip R_X86_64_PLT32.  */
   3732  1.1  christos 		  rel++;
   3733  1.1  christos 		  continue;
   3734  1.1  christos 		}
   3735  1.1  christos 	      else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
   3736  1.1  christos 		{
   3737  1.1  christos 		  /* GDesc -> IE transition.
   3738  1.1  christos 		     It's originally something like:
   3739  1.1  christos 		     leaq x@tlsdesc(%rip), %rax
   3740  1.1  christos 
   3741  1.1  christos 		     Change it to:
   3742  1.1  christos 		     movq x@gottpoff(%rip), %rax # before xchg %ax,%ax.  */
   3743  1.1  christos 
   3744  1.1  christos 		  /* Now modify the instruction as appropriate. To
   3745  1.1  christos 		     turn a leaq into a movq in the form we use it, it
   3746  1.1  christos 		     suffices to change the second byte from 0x8d to
   3747  1.1  christos 		     0x8b.  */
   3748  1.1  christos 		  bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
   3749  1.1  christos 
   3750  1.1  christos 		  bfd_put_32 (output_bfd,
   3751  1.1  christos 			      htab->elf.sgot->output_section->vma
   3752  1.1  christos 			      + htab->elf.sgot->output_offset + off
   3753  1.1  christos 			      - rel->r_offset
   3754  1.1  christos 			      - input_section->output_section->vma
   3755  1.1  christos 			      - input_section->output_offset
   3756  1.1  christos 			      - 4,
   3757  1.1  christos 			      contents + roff);
   3758  1.1  christos 		  continue;
   3759  1.1  christos 		}
   3760  1.1  christos 	      else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
   3761  1.1  christos 		{
   3762  1.1  christos 		  /* GDesc -> IE transition.
   3763  1.1  christos 		     It's originally:
   3764  1.1  christos 		     call *(%rax)
   3765  1.1  christos 
   3766  1.1  christos 		     Change it to:
   3767  1.1  christos 		     xchg %ax, %ax.  */
   3768  1.1  christos 
   3769  1.1  christos 		  bfd_put_8 (output_bfd, 0x66, contents + roff);
   3770  1.1  christos 		  bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
   3771  1.1  christos 		  continue;
   3772  1.1  christos 		}
   3773  1.1  christos 	      else
   3774  1.1  christos 		BFD_ASSERT (FALSE);
   3775  1.1  christos 	    }
   3776  1.1  christos 	  break;
   3777  1.1  christos 
   3778  1.1  christos 	case R_X86_64_TLSLD:
   3779  1.1  christos 	  if (! elf_x86_64_tls_transition (info, input_bfd,
   3780  1.1  christos 					   input_section, contents,
   3781  1.1  christos 					   symtab_hdr, sym_hashes,
   3782  1.1  christos 					   &r_type, GOT_UNKNOWN,
   3783  1.1  christos 					   rel, relend, h, r_symndx))
   3784  1.1  christos 	    return FALSE;
   3785  1.1  christos 
   3786  1.1  christos 	  if (r_type != R_X86_64_TLSLD)
   3787  1.1  christos 	    {
   3788  1.1  christos 	      /* LD->LE transition:
   3789  1.1  christos 		 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
   3790  1.1  christos 		 For 64bit, we change it into:
   3791  1.1  christos 		 .word 0x6666; .byte 0x66; movq %fs:0, %rax.
   3792  1.1  christos 		 For 32bit, we change it into:
   3793  1.1  christos 		 nopl 0x0(%rax); movl %fs:0, %eax.  */
   3794  1.1  christos 
   3795  1.1  christos 	      BFD_ASSERT (r_type == R_X86_64_TPOFF32);
   3796  1.1  christos 	      if (ABI_64_P (output_bfd))
   3797  1.1  christos 		memcpy (contents + rel->r_offset - 3,
   3798  1.1  christos 			"\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
   3799  1.1  christos 	      else
   3800  1.1  christos 		memcpy (contents + rel->r_offset - 3,
   3801  1.1  christos 			"\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
   3802  1.1  christos 	      /* Skip R_X86_64_PC32/R_X86_64_PLT32.  */
   3803  1.1  christos 	      rel++;
   3804  1.1  christos 	      continue;
   3805  1.1  christos 	    }
   3806  1.1  christos 
   3807  1.1  christos 	  if (htab->elf.sgot == NULL)
   3808  1.1  christos 	    abort ();
   3809  1.1  christos 
   3810  1.1  christos 	  off = htab->tls_ld_got.offset;
   3811  1.1  christos 	  if (off & 1)
   3812  1.1  christos 	    off &= ~1;
   3813  1.1  christos 	  else
   3814  1.1  christos 	    {
   3815  1.1  christos 	      Elf_Internal_Rela outrel;
   3816  1.1  christos 
   3817  1.1  christos 	      if (htab->elf.srelgot == NULL)
   3818  1.1  christos 		abort ();
   3819  1.1  christos 
   3820  1.1  christos 	      outrel.r_offset = (htab->elf.sgot->output_section->vma
   3821  1.1  christos 				 + htab->elf.sgot->output_offset + off);
   3822  1.1  christos 
   3823  1.1  christos 	      bfd_put_64 (output_bfd, 0,
   3824  1.1  christos 			  htab->elf.sgot->contents + off);
   3825  1.1  christos 	      bfd_put_64 (output_bfd, 0,
   3826  1.1  christos 			  htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
   3827  1.1  christos 	      outrel.r_info = htab->r_info (0, R_X86_64_DTPMOD64);
   3828  1.1  christos 	      outrel.r_addend = 0;
   3829  1.1  christos 	      elf_append_rela (output_bfd, htab->elf.srelgot,
   3830  1.1  christos 					&outrel);
   3831  1.1  christos 	      htab->tls_ld_got.offset |= 1;
   3832  1.1  christos 	    }
   3833  1.1  christos 	  relocation = htab->elf.sgot->output_section->vma
   3834  1.1  christos 		       + htab->elf.sgot->output_offset + off;
   3835  1.1  christos 	  unresolved_reloc = FALSE;
   3836  1.1  christos 	  break;
   3837  1.1  christos 
   3838  1.1  christos 	case R_X86_64_DTPOFF32:
   3839  1.1  christos 	  if (!info->executable|| (input_section->flags & SEC_CODE) == 0)
   3840  1.1  christos 	    relocation -= elf_x86_64_dtpoff_base (info);
   3841  1.1  christos 	  else
   3842  1.1  christos 	    relocation = elf_x86_64_tpoff (info, relocation);
   3843  1.1  christos 	  break;
   3844  1.1  christos 
   3845  1.1  christos 	case R_X86_64_TPOFF32:
   3846  1.1  christos 	  BFD_ASSERT (info->executable);
   3847  1.1  christos 	  relocation = elf_x86_64_tpoff (info, relocation);
   3848  1.1  christos 	  break;
   3849  1.1  christos 
   3850  1.1  christos 	default:
   3851  1.1  christos 	  break;
   3852  1.1  christos 	}
   3853  1.1  christos 
   3854  1.1  christos       /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
   3855  1.1  christos 	 because such sections are not SEC_ALLOC and thus ld.so will
   3856  1.1  christos 	 not process them.  */
   3857  1.1  christos       if (unresolved_reloc
   3858  1.1  christos 	  && !((input_section->flags & SEC_DEBUGGING) != 0
   3859  1.1  christos 	       && h->def_dynamic))
   3860  1.1  christos 	(*_bfd_error_handler)
   3861  1.1  christos 	  (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
   3862  1.1  christos 	   input_bfd,
   3863  1.1  christos 	   input_section,
   3864  1.1  christos 	   (long) rel->r_offset,
   3865  1.1  christos 	   howto->name,
   3866  1.1  christos 	   h->root.root.string);
   3867  1.1  christos 
   3868  1.1  christos do_relocation:
   3869  1.1  christos       r = _bfd_final_link_relocate (howto, input_bfd, input_section,
   3870  1.1  christos 				    contents, rel->r_offset,
   3871  1.1  christos 				    relocation, rel->r_addend);
   3872  1.1  christos 
   3873  1.1  christos       if (r != bfd_reloc_ok)
   3874  1.1  christos 	{
   3875  1.1  christos 	  const char *name;
   3876  1.1  christos 
   3877  1.1  christos 	  if (h != NULL)
   3878  1.1  christos 	    name = h->root.root.string;
   3879  1.1  christos 	  else
   3880  1.1  christos 	    {
   3881  1.1  christos 	      name = bfd_elf_string_from_elf_section (input_bfd,
   3882  1.1  christos 						      symtab_hdr->sh_link,
   3883  1.1  christos 						      sym->st_name);
   3884  1.1  christos 	      if (name == NULL)
   3885  1.1  christos 		return FALSE;
   3886  1.1  christos 	      if (*name == '\0')
   3887  1.1  christos 		name = bfd_section_name (input_bfd, sec);
   3888  1.1  christos 	    }
   3889  1.1  christos 
   3890  1.1  christos 	  if (r == bfd_reloc_overflow)
   3891  1.1  christos 	    {
   3892  1.1  christos 	      if (! ((*info->callbacks->reloc_overflow)
   3893  1.1  christos 		     (info, (h ? &h->root : NULL), name, howto->name,
   3894  1.1  christos 		      (bfd_vma) 0, input_bfd, input_section,
   3895  1.1  christos 		      rel->r_offset)))
   3896  1.1  christos 		return FALSE;
   3897  1.1  christos 	    }
   3898  1.1  christos 	  else
   3899  1.1  christos 	    {
   3900  1.1  christos 	      (*_bfd_error_handler)
   3901  1.1  christos 		(_("%B(%A+0x%lx): reloc against `%s': error %d"),
   3902  1.1  christos 		 input_bfd, input_section,
   3903  1.1  christos 		 (long) rel->r_offset, name, (int) r);
   3904  1.1  christos 	      return FALSE;
   3905  1.1  christos 	    }
   3906  1.1  christos 	}
   3907  1.1  christos     }
   3908  1.1  christos 
   3909  1.1  christos   return TRUE;
   3910  1.1  christos }
   3911  1.1  christos 
   3912  1.1  christos /* Finish up dynamic symbol handling.  We set the contents of various
   3913  1.1  christos    dynamic sections here.  */
   3914  1.1  christos 
   3915  1.1  christos static bfd_boolean
   3916  1.1  christos elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
   3917  1.1  christos 				  struct bfd_link_info *info,
   3918  1.1  christos 				  struct elf_link_hash_entry *h,
   3919  1.1  christos 				  Elf_Internal_Sym *sym)
   3920  1.1  christos {
   3921  1.1  christos   struct elf_x86_64_link_hash_table *htab;
   3922  1.1  christos 
   3923  1.1  christos   htab = elf_x86_64_hash_table (info);
   3924  1.1  christos   if (htab == NULL)
   3925  1.1  christos     return FALSE;
   3926  1.1  christos 
   3927  1.1  christos   if (h->plt.offset != (bfd_vma) -1)
   3928  1.1  christos     {
   3929  1.1  christos       bfd_vma plt_index;
   3930  1.1  christos       bfd_vma got_offset;
   3931  1.1  christos       Elf_Internal_Rela rela;
   3932  1.1  christos       bfd_byte *loc;
   3933  1.1  christos       asection *plt, *gotplt, *relplt;
   3934  1.1  christos       const struct elf_backend_data *bed;
   3935  1.1  christos 
   3936  1.1  christos       /* When building a static executable, use .iplt, .igot.plt and
   3937  1.1  christos 	 .rela.iplt sections for STT_GNU_IFUNC symbols.  */
   3938  1.1  christos       if (htab->elf.splt != NULL)
   3939  1.1  christos 	{
   3940  1.1  christos 	  plt = htab->elf.splt;
   3941  1.1  christos 	  gotplt = htab->elf.sgotplt;
   3942  1.1  christos 	  relplt = htab->elf.srelplt;
   3943  1.1  christos 	}
   3944  1.1  christos       else
   3945  1.1  christos 	{
   3946  1.1  christos 	  plt = htab->elf.iplt;
   3947  1.1  christos 	  gotplt = htab->elf.igotplt;
   3948  1.1  christos 	  relplt = htab->elf.irelplt;
   3949  1.1  christos 	}
   3950  1.1  christos 
   3951  1.1  christos       /* This symbol has an entry in the procedure linkage table.  Set
   3952  1.1  christos 	 it up.	 */
   3953  1.1  christos       if ((h->dynindx == -1
   3954  1.1  christos 	   && !((h->forced_local || info->executable)
   3955  1.1  christos 		&& h->def_regular
   3956  1.1  christos 		&& h->type == STT_GNU_IFUNC))
   3957  1.1  christos 	  || plt == NULL
   3958  1.1  christos 	  || gotplt == NULL
   3959  1.1  christos 	  || relplt == NULL)
   3960  1.1  christos 	abort ();
   3961  1.1  christos 
   3962  1.1  christos       /* Get the index in the procedure linkage table which
   3963  1.1  christos 	 corresponds to this symbol.  This is the index of this symbol
   3964  1.1  christos 	 in all the symbols for which we are making plt entries.  The
   3965  1.1  christos 	 first entry in the procedure linkage table is reserved.
   3966  1.1  christos 
   3967  1.1  christos 	 Get the offset into the .got table of the entry that
   3968  1.1  christos 	 corresponds to this function.	Each .got entry is GOT_ENTRY_SIZE
   3969  1.1  christos 	 bytes. The first three are reserved for the dynamic linker.
   3970  1.1  christos 
   3971  1.1  christos 	 For static executables, we don't reserve anything.  */
   3972  1.1  christos 
   3973  1.1  christos       if (plt == htab->elf.splt)
   3974  1.1  christos 	{
   3975  1.1  christos 	  plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
   3976  1.1  christos 	  got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
   3977  1.1  christos 	}
   3978  1.1  christos       else
   3979  1.1  christos 	{
   3980  1.1  christos 	  plt_index = h->plt.offset / PLT_ENTRY_SIZE;
   3981  1.1  christos 	  got_offset = plt_index * GOT_ENTRY_SIZE;
   3982  1.1  christos 	}
   3983  1.1  christos 
   3984  1.1  christos       /* Fill in the entry in the procedure linkage table.  */
   3985  1.1  christos       memcpy (plt->contents + h->plt.offset, elf_x86_64_plt_entry,
   3986  1.1  christos 	      PLT_ENTRY_SIZE);
   3987  1.1  christos 
   3988  1.1  christos       /* Insert the relocation positions of the plt section.  The magic
   3989  1.1  christos 	 numbers at the end of the statements are the positions of the
   3990  1.1  christos 	 relocations in the plt section.  */
   3991  1.1  christos       /* Put offset for jmp *name@GOTPCREL(%rip), since the
   3992  1.1  christos 	 instruction uses 6 bytes, subtract this value.  */
   3993  1.1  christos       bfd_put_32 (output_bfd,
   3994  1.1  christos 		      (gotplt->output_section->vma
   3995  1.1  christos 		       + gotplt->output_offset
   3996  1.1  christos 		       + got_offset
   3997  1.1  christos 		       - plt->output_section->vma
   3998  1.1  christos 		       - plt->output_offset
   3999  1.1  christos 		       - h->plt.offset
   4000  1.1  christos 		       - 6),
   4001  1.1  christos 		  plt->contents + h->plt.offset + 2);
   4002  1.1  christos 
   4003  1.1  christos       /* Don't fill PLT entry for static executables.  */
   4004  1.1  christos       if (plt == htab->elf.splt)
   4005  1.1  christos 	{
   4006  1.1  christos 	  /* Put relocation index.  */
   4007  1.1  christos 	  bfd_put_32 (output_bfd, plt_index,
   4008  1.1  christos 		      plt->contents + h->plt.offset + 7);
   4009  1.1  christos 	  /* Put offset for jmp .PLT0.  */
   4010  1.1  christos 	  bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),
   4011  1.1  christos 		      plt->contents + h->plt.offset + 12);
   4012  1.1  christos 	}
   4013  1.1  christos 
   4014  1.1  christos       /* Fill in the entry in the global offset table, initially this
   4015  1.1  christos 	 points to the pushq instruction in the PLT which is at offset 6.  */
   4016  1.1  christos       bfd_put_64 (output_bfd, (plt->output_section->vma
   4017  1.1  christos 			       + plt->output_offset
   4018  1.1  christos 			       + h->plt.offset + 6),
   4019  1.1  christos 		  gotplt->contents + got_offset);
   4020  1.1  christos 
   4021  1.1  christos       /* Fill in the entry in the .rela.plt section.  */
   4022  1.1  christos       rela.r_offset = (gotplt->output_section->vma
   4023  1.1  christos 		       + gotplt->output_offset
   4024  1.1  christos 		       + got_offset);
   4025  1.1  christos       if (h->dynindx == -1
   4026  1.1  christos 	  || ((info->executable
   4027  1.1  christos 	       || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
   4028  1.1  christos 	      && h->def_regular
   4029  1.1  christos 	      && h->type == STT_GNU_IFUNC))
   4030  1.1  christos 	{
   4031  1.1  christos 	  /* If an STT_GNU_IFUNC symbol is locally defined, generate
   4032  1.1  christos 	     R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT.  */
   4033  1.1  christos 	  rela.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
   4034  1.1  christos 	  rela.r_addend = (h->root.u.def.value
   4035  1.1  christos 			   + h->root.u.def.section->output_section->vma
   4036  1.1  christos 			   + h->root.u.def.section->output_offset);
   4037  1.1  christos 	}
   4038  1.1  christos       else
   4039  1.1  christos 	{
   4040  1.1  christos 	  rela.r_info = htab->r_info (h->dynindx, R_X86_64_JUMP_SLOT);
   4041  1.1  christos 	  rela.r_addend = 0;
   4042  1.1  christos 	}
   4043  1.1  christos 
   4044  1.1  christos       bed = get_elf_backend_data (output_bfd);
   4045  1.1  christos       loc = relplt->contents + plt_index * bed->s->sizeof_rela;
   4046  1.1  christos       bed->s->swap_reloca_out (output_bfd, &rela, loc);
   4047  1.1  christos 
   4048  1.1  christos       if (!h->def_regular)
   4049  1.1  christos 	{
   4050  1.1  christos 	  /* Mark the symbol as undefined, rather than as defined in
   4051  1.1  christos 	     the .plt section.  Leave the value if there were any
   4052  1.1  christos 	     relocations where pointer equality matters (this is a clue
   4053  1.1  christos 	     for the dynamic linker, to make function pointer
   4054  1.1  christos 	     comparisons work between an application and shared
   4055  1.1  christos 	     library), otherwise set it to zero.  If a function is only
   4056  1.1  christos 	     called from a binary, there is no need to slow down
   4057  1.1  christos 	     shared libraries because of that.  */
   4058  1.1  christos 	  sym->st_shndx = SHN_UNDEF;
   4059  1.1  christos 	  if (!h->pointer_equality_needed)
   4060  1.1  christos 	    sym->st_value = 0;
   4061  1.1  christos 	}
   4062  1.1  christos     }
   4063  1.1  christos 
   4064  1.1  christos   if (h->got.offset != (bfd_vma) -1
   4065  1.1  christos       && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h)->tls_type)
   4066  1.1  christos       && elf_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE)
   4067  1.1  christos     {
   4068  1.1  christos       Elf_Internal_Rela rela;
   4069  1.1  christos 
   4070  1.1  christos       /* This symbol has an entry in the global offset table.  Set it
   4071  1.1  christos 	 up.  */
   4072  1.1  christos       if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
   4073  1.1  christos 	abort ();
   4074  1.1  christos 
   4075  1.1  christos       rela.r_offset = (htab->elf.sgot->output_section->vma
   4076  1.1  christos 		       + htab->elf.sgot->output_offset
   4077  1.1  christos 		       + (h->got.offset &~ (bfd_vma) 1));
   4078  1.1  christos 
   4079  1.1  christos       /* If this is a static link, or it is a -Bsymbolic link and the
   4080  1.1  christos 	 symbol is defined locally or was forced to be local because
   4081  1.1  christos 	 of a version file, we just want to emit a RELATIVE reloc.
   4082  1.1  christos 	 The entry in the global offset table will already have been
   4083  1.1  christos 	 initialized in the relocate_section function.  */
   4084  1.1  christos       if (h->def_regular
   4085  1.1  christos 	  && h->type == STT_GNU_IFUNC)
   4086  1.1  christos 	{
   4087  1.1  christos 	  if (info->shared)
   4088  1.1  christos 	    {
   4089  1.1  christos 	      /* Generate R_X86_64_GLOB_DAT.  */
   4090  1.1  christos 	      goto do_glob_dat;
   4091  1.1  christos 	    }
   4092  1.1  christos 	  else
   4093  1.1  christos 	    {
   4094  1.1  christos 	      asection *plt;
   4095  1.1  christos 
   4096  1.1  christos 	      if (!h->pointer_equality_needed)
   4097  1.1  christos 		abort ();
   4098  1.1  christos 
   4099  1.1  christos 	      /* For non-shared object, we can't use .got.plt, which
   4100  1.1  christos 		 contains the real function addres if we need pointer
   4101  1.1  christos 		 equality.  We load the GOT entry with the PLT entry.  */
   4102  1.1  christos 	      plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
   4103  1.1  christos 	      bfd_put_64 (output_bfd, (plt->output_section->vma
   4104  1.1  christos 				       + plt->output_offset
   4105  1.1  christos 				       + h->plt.offset),
   4106  1.1  christos 			  htab->elf.sgot->contents + h->got.offset);
   4107  1.1  christos 	      return TRUE;
   4108  1.1  christos 	    }
   4109  1.1  christos 	}
   4110  1.1  christos       else if (info->shared
   4111  1.1  christos 	       && SYMBOL_REFERENCES_LOCAL (info, h))
   4112  1.1  christos 	{
   4113  1.1  christos 	  if (!h->def_regular)
   4114  1.1  christos 	    return FALSE;
   4115  1.1  christos 	  BFD_ASSERT((h->got.offset & 1) != 0);
   4116  1.1  christos 	  rela.r_info = htab->r_info (0, R_X86_64_RELATIVE);
   4117  1.1  christos 	  rela.r_addend = (h->root.u.def.value
   4118  1.1  christos 			   + h->root.u.def.section->output_section->vma
   4119  1.1  christos 			   + h->root.u.def.section->output_offset);
   4120  1.1  christos 	}
   4121  1.1  christos       else
   4122  1.1  christos 	{
   4123  1.1  christos 	  BFD_ASSERT((h->got.offset & 1) == 0);
   4124  1.1  christos do_glob_dat:
   4125  1.1  christos 	  bfd_put_64 (output_bfd, (bfd_vma) 0,
   4126  1.1  christos 		      htab->elf.sgot->contents + h->got.offset);
   4127  1.1  christos 	  rela.r_info = htab->r_info (h->dynindx, R_X86_64_GLOB_DAT);
   4128  1.1  christos 	  rela.r_addend = 0;
   4129  1.1  christos 	}
   4130  1.1  christos 
   4131  1.1  christos       elf_append_rela (output_bfd, htab->elf.srelgot, &rela);
   4132  1.1  christos     }
   4133  1.1  christos 
   4134  1.1  christos   if (h->needs_copy)
   4135  1.1  christos     {
   4136  1.1  christos       Elf_Internal_Rela rela;
   4137  1.1  christos 
   4138  1.1  christos       /* This symbol needs a copy reloc.  Set it up.  */
   4139  1.1  christos 
   4140  1.1  christos       if (h->dynindx == -1
   4141  1.1  christos 	  || (h->root.type != bfd_link_hash_defined
   4142  1.1  christos 	      && h->root.type != bfd_link_hash_defweak)
   4143  1.1  christos 	  || htab->srelbss == NULL)
   4144  1.1  christos 	abort ();
   4145  1.1  christos 
   4146  1.1  christos       rela.r_offset = (h->root.u.def.value
   4147  1.1  christos 		       + h->root.u.def.section->output_section->vma
   4148  1.1  christos 		       + h->root.u.def.section->output_offset);
   4149  1.1  christos       rela.r_info = htab->r_info (h->dynindx, R_X86_64_COPY);
   4150  1.1  christos       rela.r_addend = 0;
   4151  1.1  christos       elf_append_rela (output_bfd, htab->srelbss, &rela);
   4152  1.1  christos     }
   4153  1.1  christos 
   4154  1.1  christos   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  SYM may
   4155  1.1  christos      be NULL for local symbols.  */
   4156  1.1  christos   if (sym != NULL
   4157  1.1  christos       && (strcmp (h->root.root.string, "_DYNAMIC") == 0
   4158  1.1  christos 	  || h == htab->elf.hgot))
   4159  1.1  christos     sym->st_shndx = SHN_ABS;
   4160  1.1  christos 
   4161  1.1  christos   return TRUE;
   4162  1.1  christos }
   4163  1.1  christos 
   4164  1.1  christos /* Finish up local dynamic symbol handling.  We set the contents of
   4165  1.1  christos    various dynamic sections here.  */
   4166  1.1  christos 
   4167  1.1  christos static bfd_boolean
   4168  1.1  christos elf_x86_64_finish_local_dynamic_symbol (void **slot, void *inf)
   4169  1.1  christos {
   4170  1.1  christos   struct elf_link_hash_entry *h
   4171  1.1  christos     = (struct elf_link_hash_entry *) *slot;
   4172  1.1  christos   struct bfd_link_info *info
   4173  1.1  christos     = (struct bfd_link_info *) inf;
   4174  1.1  christos 
   4175  1.1  christos   return elf_x86_64_finish_dynamic_symbol (info->output_bfd,
   4176  1.1  christos 					     info, h, NULL);
   4177  1.1  christos }
   4178  1.1  christos 
   4179  1.1  christos /* Used to decide how to sort relocs in an optimal manner for the
   4180  1.1  christos    dynamic linker, before writing them out.  */
   4181  1.1  christos 
   4182  1.1  christos static enum elf_reloc_type_class
   4183  1.1  christos elf_x86_64_reloc_type_class (const Elf_Internal_Rela *rela)
   4184  1.1  christos {
   4185  1.1  christos   switch ((int) ELF32_R_TYPE (rela->r_info))
   4186  1.1  christos     {
   4187  1.1  christos     case R_X86_64_RELATIVE:
   4188  1.1  christos       return reloc_class_relative;
   4189  1.1  christos     case R_X86_64_JUMP_SLOT:
   4190  1.1  christos       return reloc_class_plt;
   4191  1.1  christos     case R_X86_64_COPY:
   4192  1.1  christos       return reloc_class_copy;
   4193  1.1  christos     default:
   4194  1.1  christos       return reloc_class_normal;
   4195  1.1  christos     }
   4196  1.1  christos }
   4197  1.1  christos 
   4198  1.1  christos /* Finish up the dynamic sections.  */
   4199  1.1  christos 
   4200  1.1  christos static bfd_boolean
   4201  1.1  christos elf_x86_64_finish_dynamic_sections (bfd *output_bfd,
   4202  1.1  christos 				    struct bfd_link_info *info)
   4203  1.1  christos {
   4204  1.1  christos   struct elf_x86_64_link_hash_table *htab;
   4205  1.1  christos   bfd *dynobj;
   4206  1.1  christos   asection *sdyn;
   4207  1.1  christos 
   4208  1.1  christos   htab = elf_x86_64_hash_table (info);
   4209  1.1  christos   if (htab == NULL)
   4210  1.1  christos     return FALSE;
   4211  1.1  christos 
   4212  1.1  christos   dynobj = htab->elf.dynobj;
   4213  1.1  christos   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
   4214  1.1  christos 
   4215  1.1  christos   if (htab->elf.dynamic_sections_created)
   4216  1.1  christos     {
   4217  1.1  christos       bfd_byte *dyncon, *dynconend;
   4218  1.1  christos       const struct elf_backend_data *bed;
   4219  1.1  christos       bfd_size_type sizeof_dyn;
   4220  1.1  christos 
   4221  1.1  christos       if (sdyn == NULL || htab->elf.sgot == NULL)
   4222  1.1  christos 	abort ();
   4223  1.1  christos 
   4224  1.1  christos       bed = get_elf_backend_data (dynobj);
   4225  1.1  christos       sizeof_dyn = bed->s->sizeof_dyn;
   4226  1.1  christos       dyncon = sdyn->contents;
   4227  1.1  christos       dynconend = sdyn->contents + sdyn->size;
   4228  1.1  christos       for (; dyncon < dynconend; dyncon += sizeof_dyn)
   4229  1.1  christos 	{
   4230  1.1  christos 	  Elf_Internal_Dyn dyn;
   4231  1.1  christos 	  asection *s;
   4232  1.1  christos 
   4233  1.1  christos 	  (*bed->s->swap_dyn_in) (dynobj, dyncon, &dyn);
   4234  1.1  christos 
   4235  1.1  christos 	  switch (dyn.d_tag)
   4236  1.1  christos 	    {
   4237  1.1  christos 	    default:
   4238  1.1  christos 	      continue;
   4239  1.1  christos 
   4240  1.1  christos 	    case DT_PLTGOT:
   4241  1.1  christos 	      s = htab->elf.sgotplt;
   4242  1.1  christos 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   4243  1.1  christos 	      break;
   4244  1.1  christos 
   4245  1.1  christos 	    case DT_JMPREL:
   4246  1.1  christos 	      dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma;
   4247  1.1  christos 	      break;
   4248  1.1  christos 
   4249  1.1  christos 	    case DT_PLTRELSZ:
   4250  1.1  christos 	      s = htab->elf.srelplt->output_section;
   4251  1.1  christos 	      dyn.d_un.d_val = s->size;
   4252  1.1  christos 	      break;
   4253  1.1  christos 
   4254  1.1  christos 	    case DT_RELASZ:
   4255  1.1  christos 	      /* The procedure linkage table relocs (DT_JMPREL) should
   4256  1.1  christos 		 not be included in the overall relocs (DT_RELA).
   4257  1.1  christos 		 Therefore, we override the DT_RELASZ entry here to
   4258  1.1  christos 		 make it not include the JMPREL relocs.  Since the
   4259  1.1  christos 		 linker script arranges for .rela.plt to follow all
   4260  1.1  christos 		 other relocation sections, we don't have to worry
   4261  1.1  christos 		 about changing the DT_RELA entry.  */
   4262  1.1  christos 	      if (htab->elf.srelplt != NULL)
   4263  1.1  christos 		{
   4264  1.1  christos 		  s = htab->elf.srelplt->output_section;
   4265  1.1  christos 		  dyn.d_un.d_val -= s->size;
   4266  1.1  christos 		}
   4267  1.1  christos 	      break;
   4268  1.1  christos 
   4269  1.1  christos 	    case DT_TLSDESC_PLT:
   4270  1.1  christos 	      s = htab->elf.splt;
   4271  1.1  christos 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
   4272  1.1  christos 		+ htab->tlsdesc_plt;
   4273  1.1  christos 	      break;
   4274  1.1  christos 
   4275  1.1  christos 	    case DT_TLSDESC_GOT:
   4276  1.1  christos 	      s = htab->elf.sgot;
   4277  1.1  christos 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
   4278  1.1  christos 		+ htab->tlsdesc_got;
   4279  1.1  christos 	      break;
   4280  1.1  christos 	    }
   4281  1.1  christos 
   4282  1.1  christos 	  (*bed->s->swap_dyn_out) (output_bfd, &dyn, dyncon);
   4283  1.1  christos 	}
   4284  1.1  christos 
   4285  1.1  christos       /* Fill in the special first entry in the procedure linkage table.  */
   4286  1.1  christos       if (htab->elf.splt && htab->elf.splt->size > 0)
   4287  1.1  christos 	{
   4288  1.1  christos 	  /* Fill in the first entry in the procedure linkage table.  */
   4289  1.1  christos 	  memcpy (htab->elf.splt->contents, elf_x86_64_plt0_entry,
   4290  1.1  christos 		  PLT_ENTRY_SIZE);
   4291  1.1  christos 	  /* Add offset for pushq GOT+8(%rip), since the instruction
   4292  1.1  christos 	     uses 6 bytes subtract this value.  */
   4293  1.1  christos 	  bfd_put_32 (output_bfd,
   4294  1.1  christos 		      (htab->elf.sgotplt->output_section->vma
   4295  1.1  christos 		       + htab->elf.sgotplt->output_offset
   4296  1.1  christos 		       + 8
   4297  1.1  christos 		       - htab->elf.splt->output_section->vma
   4298  1.1  christos 		       - htab->elf.splt->output_offset
   4299  1.1  christos 		       - 6),
   4300  1.1  christos 		      htab->elf.splt->contents + 2);
   4301  1.1  christos 	  /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
   4302  1.1  christos 	     the end of the instruction.  */
   4303  1.1  christos 	  bfd_put_32 (output_bfd,
   4304  1.1  christos 		      (htab->elf.sgotplt->output_section->vma
   4305  1.1  christos 		       + htab->elf.sgotplt->output_offset
   4306  1.1  christos 		       + 16
   4307  1.1  christos 		       - htab->elf.splt->output_section->vma
   4308  1.1  christos 		       - htab->elf.splt->output_offset
   4309  1.1  christos 		       - 12),
   4310  1.1  christos 		      htab->elf.splt->contents + 8);
   4311  1.1  christos 
   4312  1.1  christos 	  elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize =
   4313  1.1  christos 	    PLT_ENTRY_SIZE;
   4314  1.1  christos 
   4315  1.1  christos 	  if (htab->tlsdesc_plt)
   4316  1.1  christos 	    {
   4317  1.1  christos 	      bfd_put_64 (output_bfd, (bfd_vma) 0,
   4318  1.1  christos 			  htab->elf.sgot->contents + htab->tlsdesc_got);
   4319  1.1  christos 
   4320  1.1  christos 	      memcpy (htab->elf.splt->contents + htab->tlsdesc_plt,
   4321  1.1  christos 		      elf_x86_64_plt0_entry,
   4322  1.1  christos 		      PLT_ENTRY_SIZE);
   4323  1.1  christos 
   4324  1.1  christos 	      /* Add offset for pushq GOT+8(%rip), since the
   4325  1.1  christos 		 instruction uses 6 bytes subtract this value.  */
   4326  1.1  christos 	      bfd_put_32 (output_bfd,
   4327  1.1  christos 			  (htab->elf.sgotplt->output_section->vma
   4328  1.1  christos 			   + htab->elf.sgotplt->output_offset
   4329  1.1  christos 			   + 8
   4330  1.1  christos 			   - htab->elf.splt->output_section->vma
   4331  1.1  christos 			   - htab->elf.splt->output_offset
   4332  1.1  christos 			   - htab->tlsdesc_plt
   4333  1.1  christos 			   - 6),
   4334  1.1  christos 			  htab->elf.splt->contents + htab->tlsdesc_plt + 2);
   4335  1.1  christos 	      /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
   4336  1.1  christos 		 htab->tlsdesc_got. The 12 is the offset to the end of
   4337  1.1  christos 		 the instruction.  */
   4338  1.1  christos 	      bfd_put_32 (output_bfd,
   4339  1.1  christos 			  (htab->elf.sgot->output_section->vma
   4340  1.1  christos 			   + htab->elf.sgot->output_offset
   4341  1.1  christos 			   + htab->tlsdesc_got
   4342  1.1  christos 			   - htab->elf.splt->output_section->vma
   4343  1.1  christos 			   - htab->elf.splt->output_offset
   4344  1.1  christos 			   - htab->tlsdesc_plt
   4345  1.1  christos 			   - 12),
   4346  1.1  christos 			  htab->elf.splt->contents + htab->tlsdesc_plt + 8);
   4347  1.1  christos 	    }
   4348  1.1  christos 	}
   4349  1.1  christos     }
   4350  1.1  christos 
   4351  1.1  christos   if (htab->elf.sgotplt)
   4352  1.1  christos     {
   4353  1.1  christos       if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
   4354  1.1  christos 	{
   4355  1.1  christos 	  (*_bfd_error_handler)
   4356  1.1  christos 	    (_("discarded output section: `%A'"), htab->elf.sgotplt);
   4357  1.1  christos 	  return FALSE;
   4358  1.1  christos 	}
   4359  1.1  christos 
   4360  1.1  christos       /* Fill in the first three entries in the global offset table.  */
   4361  1.1  christos       if (htab->elf.sgotplt->size > 0)
   4362  1.1  christos 	{
   4363  1.1  christos 	  /* Set the first entry in the global offset table to the address of
   4364  1.1  christos 	     the dynamic section.  */
   4365  1.1  christos 	  if (sdyn == NULL)
   4366  1.1  christos 	    bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents);
   4367  1.1  christos 	  else
   4368  1.1  christos 	    bfd_put_64 (output_bfd,
   4369  1.1  christos 			sdyn->output_section->vma + sdyn->output_offset,
   4370  1.1  christos 			htab->elf.sgotplt->contents);
   4371  1.1  christos 	  /* Write GOT[1] and GOT[2], needed for the dynamic linker.  */
   4372  1.1  christos 	  bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE);
   4373  1.1  christos 	  bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE*2);
   4374  1.1  christos 	}
   4375  1.1  christos 
   4376  1.1  christos       elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize =
   4377  1.1  christos 	GOT_ENTRY_SIZE;
   4378  1.1  christos     }
   4379  1.1  christos 
   4380  1.1  christos   if (htab->elf.sgot && htab->elf.sgot->size > 0)
   4381  1.1  christos     elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
   4382  1.1  christos       = GOT_ENTRY_SIZE;
   4383  1.1  christos 
   4384  1.1  christos   /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols.  */
   4385  1.1  christos   htab_traverse (htab->loc_hash_table,
   4386  1.1  christos 		 elf_x86_64_finish_local_dynamic_symbol,
   4387  1.1  christos 		 info);
   4388  1.1  christos 
   4389  1.1  christos   return TRUE;
   4390  1.1  christos }
   4391  1.1  christos 
   4392  1.1  christos /* Return address for Ith PLT stub in section PLT, for relocation REL
   4393  1.1  christos    or (bfd_vma) -1 if it should not be included.  */
   4394  1.1  christos 
   4395  1.1  christos static bfd_vma
   4396  1.1  christos elf_x86_64_plt_sym_val (bfd_vma i, const asection *plt,
   4397  1.1  christos 			const arelent *rel ATTRIBUTE_UNUSED)
   4398  1.1  christos {
   4399  1.1  christos   return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
   4400  1.1  christos }
   4401  1.1  christos 
   4402  1.1  christos /* Handle an x86-64 specific section when reading an object file.  This
   4403  1.1  christos    is called when elfcode.h finds a section with an unknown type.  */
   4404  1.1  christos 
   4405  1.1  christos static bfd_boolean
   4406  1.1  christos elf_x86_64_section_from_shdr (bfd *abfd,
   4407  1.1  christos 				Elf_Internal_Shdr *hdr,
   4408  1.1  christos 				const char *name,
   4409  1.1  christos 				int shindex)
   4410  1.1  christos {
   4411  1.1  christos   if (hdr->sh_type != SHT_X86_64_UNWIND)
   4412  1.1  christos     return FALSE;
   4413  1.1  christos 
   4414  1.1  christos   if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
   4415  1.1  christos     return FALSE;
   4416  1.1  christos 
   4417  1.1  christos   return TRUE;
   4418  1.1  christos }
   4419  1.1  christos 
   4420  1.1  christos /* Hook called by the linker routine which adds symbols from an object
   4421  1.1  christos    file.  We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
   4422  1.1  christos    of .bss.  */
   4423  1.1  christos 
   4424  1.1  christos static bfd_boolean
   4425  1.1  christos elf_x86_64_add_symbol_hook (bfd *abfd,
   4426  1.1  christos 			    struct bfd_link_info *info,
   4427  1.1  christos 			    Elf_Internal_Sym *sym,
   4428  1.1  christos 			    const char **namep ATTRIBUTE_UNUSED,
   4429  1.1  christos 			    flagword *flagsp ATTRIBUTE_UNUSED,
   4430  1.1  christos 			    asection **secp,
   4431  1.1  christos 			    bfd_vma *valp)
   4432  1.1  christos {
   4433  1.1  christos   asection *lcomm;
   4434  1.1  christos 
   4435  1.1  christos   switch (sym->st_shndx)
   4436  1.1  christos     {
   4437  1.1  christos     case SHN_X86_64_LCOMMON:
   4438  1.1  christos       lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON");
   4439  1.1  christos       if (lcomm == NULL)
   4440  1.1  christos 	{
   4441  1.1  christos 	  lcomm = bfd_make_section_with_flags (abfd,
   4442  1.1  christos 					       "LARGE_COMMON",
   4443  1.1  christos 					       (SEC_ALLOC
   4444  1.1  christos 						| SEC_IS_COMMON
   4445  1.1  christos 						| SEC_LINKER_CREATED));
   4446  1.1  christos 	  if (lcomm == NULL)
   4447  1.1  christos 	    return FALSE;
   4448  1.1  christos 	  elf_section_flags (lcomm) |= SHF_X86_64_LARGE;
   4449  1.1  christos 	}
   4450  1.1  christos       *secp = lcomm;
   4451  1.1  christos       *valp = sym->st_size;
   4452  1.1  christos       return TRUE;
   4453  1.1  christos     }
   4454  1.1  christos 
   4455  1.1  christos   if ((abfd->flags & DYNAMIC) == 0
   4456  1.1  christos       && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
   4457  1.1  christos     elf_tdata (info->output_bfd)->has_ifunc_symbols = TRUE;
   4458  1.1  christos 
   4459  1.1  christos   return TRUE;
   4460  1.1  christos }
   4461  1.1  christos 
   4462  1.1  christos 
   4463  1.1  christos /* Given a BFD section, try to locate the corresponding ELF section
   4464  1.1  christos    index.  */
   4465  1.1  christos 
   4466  1.1  christos static bfd_boolean
   4467  1.1  christos elf_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
   4468  1.1  christos 					 asection *sec, int *index_return)
   4469  1.1  christos {
   4470  1.1  christos   if (sec == &_bfd_elf_large_com_section)
   4471  1.1  christos     {
   4472  1.1  christos       *index_return = SHN_X86_64_LCOMMON;
   4473  1.1  christos       return TRUE;
   4474  1.1  christos     }
   4475  1.1  christos   return FALSE;
   4476  1.1  christos }
   4477  1.1  christos 
   4478  1.1  christos /* Process a symbol.  */
   4479  1.1  christos 
   4480  1.1  christos static void
   4481  1.1  christos elf_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
   4482  1.1  christos 			      asymbol *asym)
   4483  1.1  christos {
   4484  1.1  christos   elf_symbol_type *elfsym = (elf_symbol_type *) asym;
   4485  1.1  christos 
   4486  1.1  christos   switch (elfsym->internal_elf_sym.st_shndx)
   4487  1.1  christos     {
   4488  1.1  christos     case SHN_X86_64_LCOMMON:
   4489  1.1  christos       asym->section = &_bfd_elf_large_com_section;
   4490  1.1  christos       asym->value = elfsym->internal_elf_sym.st_size;
   4491  1.1  christos       /* Common symbol doesn't set BSF_GLOBAL.  */
   4492  1.1  christos       asym->flags &= ~BSF_GLOBAL;
   4493  1.1  christos       break;
   4494  1.1  christos     }
   4495  1.1  christos }
   4496  1.1  christos 
   4497  1.1  christos static bfd_boolean
   4498  1.1  christos elf_x86_64_common_definition (Elf_Internal_Sym *sym)
   4499  1.1  christos {
   4500  1.1  christos   return (sym->st_shndx == SHN_COMMON
   4501  1.1  christos 	  || sym->st_shndx == SHN_X86_64_LCOMMON);
   4502  1.1  christos }
   4503  1.1  christos 
   4504  1.1  christos static unsigned int
   4505  1.1  christos elf_x86_64_common_section_index (asection *sec)
   4506  1.1  christos {
   4507  1.1  christos   if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
   4508  1.1  christos     return SHN_COMMON;
   4509  1.1  christos   else
   4510  1.1  christos     return SHN_X86_64_LCOMMON;
   4511  1.1  christos }
   4512  1.1  christos 
   4513  1.1  christos static asection *
   4514  1.1  christos elf_x86_64_common_section (asection *sec)
   4515  1.1  christos {
   4516  1.1  christos   if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
   4517  1.1  christos     return bfd_com_section_ptr;
   4518  1.1  christos   else
   4519  1.1  christos     return &_bfd_elf_large_com_section;
   4520  1.1  christos }
   4521  1.1  christos 
   4522  1.1  christos static bfd_boolean
   4523  1.1  christos elf_x86_64_merge_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   4524  1.1  christos 			 struct elf_link_hash_entry **sym_hash ATTRIBUTE_UNUSED,
   4525  1.1  christos 			 struct elf_link_hash_entry *h,
   4526  1.1  christos 			 Elf_Internal_Sym *sym,
   4527  1.1  christos 			 asection **psec,
   4528  1.1  christos 			 bfd_vma *pvalue ATTRIBUTE_UNUSED,
   4529  1.1  christos 			 unsigned int *pold_alignment ATTRIBUTE_UNUSED,
   4530  1.1  christos 			 bfd_boolean *skip ATTRIBUTE_UNUSED,
   4531  1.1  christos 			 bfd_boolean *override ATTRIBUTE_UNUSED,
   4532  1.1  christos 			 bfd_boolean *type_change_ok ATTRIBUTE_UNUSED,
   4533  1.1  christos 			 bfd_boolean *size_change_ok ATTRIBUTE_UNUSED,
   4534  1.1  christos 			 bfd_boolean *newdef ATTRIBUTE_UNUSED,
   4535  1.1  christos 			 bfd_boolean *newdyn,
   4536  1.1  christos 			 bfd_boolean *newdyncommon ATTRIBUTE_UNUSED,
   4537  1.1  christos 			 bfd_boolean *newweak ATTRIBUTE_UNUSED,
   4538  1.1  christos 			 bfd *abfd ATTRIBUTE_UNUSED,
   4539  1.1  christos 			 asection **sec,
   4540  1.1  christos 			 bfd_boolean *olddef ATTRIBUTE_UNUSED,
   4541  1.1  christos 			 bfd_boolean *olddyn,
   4542  1.1  christos 			 bfd_boolean *olddyncommon ATTRIBUTE_UNUSED,
   4543  1.1  christos 			 bfd_boolean *oldweak ATTRIBUTE_UNUSED,
   4544  1.1  christos 			 bfd *oldbfd,
   4545  1.1  christos 			 asection **oldsec)
   4546  1.1  christos {
   4547  1.1  christos   /* A normal common symbol and a large common symbol result in a
   4548  1.1  christos      normal common symbol.  We turn the large common symbol into a
   4549  1.1  christos      normal one.  */
   4550  1.1  christos   if (!*olddyn
   4551  1.1  christos       && h->root.type == bfd_link_hash_common
   4552  1.1  christos       && !*newdyn
   4553  1.1  christos       && bfd_is_com_section (*sec)
   4554  1.1  christos       && *oldsec != *sec)
   4555  1.1  christos     {
   4556  1.1  christos       if (sym->st_shndx == SHN_COMMON
   4557  1.1  christos 	  && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) != 0)
   4558  1.1  christos 	{
   4559  1.1  christos 	  h->root.u.c.p->section
   4560  1.1  christos 	    = bfd_make_section_old_way (oldbfd, "COMMON");
   4561  1.1  christos 	  h->root.u.c.p->section->flags = SEC_ALLOC;
   4562  1.1  christos 	}
   4563  1.1  christos       else if (sym->st_shndx == SHN_X86_64_LCOMMON
   4564  1.1  christos 	       && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) == 0)
   4565  1.1  christos 	*psec = *sec = bfd_com_section_ptr;
   4566  1.1  christos     }
   4567  1.1  christos 
   4568  1.1  christos   return TRUE;
   4569  1.1  christos }
   4570  1.1  christos 
   4571  1.1  christos static int
   4572  1.1  christos elf_x86_64_additional_program_headers (bfd *abfd,
   4573  1.1  christos 				       struct bfd_link_info *info ATTRIBUTE_UNUSED)
   4574  1.1  christos {
   4575  1.1  christos   asection *s;
   4576  1.1  christos   int count = 0;
   4577  1.1  christos 
   4578  1.1  christos   /* Check to see if we need a large readonly segment.  */
   4579  1.1  christos   s = bfd_get_section_by_name (abfd, ".lrodata");
   4580  1.1  christos   if (s && (s->flags & SEC_LOAD))
   4581  1.1  christos     count++;
   4582  1.1  christos 
   4583  1.1  christos   /* Check to see if we need a large data segment.  Since .lbss sections
   4584  1.1  christos      is placed right after the .bss section, there should be no need for
   4585  1.1  christos      a large data segment just because of .lbss.  */
   4586  1.1  christos   s = bfd_get_section_by_name (abfd, ".ldata");
   4587  1.1  christos   if (s && (s->flags & SEC_LOAD))
   4588  1.1  christos     count++;
   4589  1.1  christos 
   4590  1.1  christos   return count;
   4591  1.1  christos }
   4592  1.1  christos 
   4593  1.1  christos /* Return TRUE if symbol should be hashed in the `.gnu.hash' section.  */
   4594  1.1  christos 
   4595  1.1  christos static bfd_boolean
   4596  1.1  christos elf_x86_64_hash_symbol (struct elf_link_hash_entry *h)
   4597  1.1  christos {
   4598  1.1  christos   if (h->plt.offset != (bfd_vma) -1
   4599  1.1  christos       && !h->def_regular
   4600  1.1  christos       && !h->pointer_equality_needed)
   4601  1.1  christos     return FALSE;
   4602  1.1  christos 
   4603  1.1  christos   return _bfd_elf_hash_symbol (h);
   4604  1.1  christos }
   4605  1.1  christos 
   4606  1.1  christos /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
   4607  1.1  christos 
   4608  1.1  christos static bfd_boolean
   4609  1.1  christos elf_x86_64_relocs_compatible (const bfd_target *input,
   4610  1.1  christos 			      const bfd_target *output)
   4611  1.1  christos {
   4612  1.1  christos   return ((xvec_get_elf_backend_data (input)->s->elfclass
   4613  1.1  christos 	   == xvec_get_elf_backend_data (output)->s->elfclass)
   4614  1.1  christos 	  && _bfd_elf_relocs_compatible (input, output));
   4615  1.1  christos }
   4616  1.1  christos 
   4617  1.1  christos static const struct bfd_elf_special_section
   4618  1.1  christos   elf_x86_64_special_sections[]=
   4619  1.1  christos {
   4620  1.1  christos   { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
   4621  1.1  christos   { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
   4622  1.1  christos   { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE},
   4623  1.1  christos   { STRING_COMMA_LEN (".lbss"),	           -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
   4624  1.1  christos   { STRING_COMMA_LEN (".ldata"),	   -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
   4625  1.1  christos   { STRING_COMMA_LEN (".lrodata"),	   -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
   4626  1.1  christos   { NULL,	                0,          0, 0,            0 }
   4627  1.1  christos };
   4628  1.1  christos 
   4629  1.1  christos #define TARGET_LITTLE_SYM		    bfd_elf64_x86_64_vec
   4630  1.1  christos #define TARGET_LITTLE_NAME		    "elf64-x86-64"
   4631  1.1  christos #define ELF_ARCH			    bfd_arch_i386
   4632  1.1  christos #define ELF_TARGET_ID			    X86_64_ELF_DATA
   4633  1.1  christos #define ELF_MACHINE_CODE		    EM_X86_64
   4634  1.1  christos #define ELF_MAXPAGESIZE			    0x200000
   4635  1.1  christos #define ELF_MINPAGESIZE			    0x1000
   4636  1.1  christos #define ELF_COMMONPAGESIZE		    0x1000
   4637  1.1  christos 
   4638  1.1  christos #define elf_backend_can_gc_sections	    1
   4639  1.1  christos #define elf_backend_can_refcount	    1
   4640  1.1  christos #define elf_backend_want_got_plt	    1
   4641  1.1  christos #define elf_backend_plt_readonly	    1
   4642  1.1  christos #define elf_backend_want_plt_sym	    0
   4643  1.1  christos #define elf_backend_got_header_size	    (GOT_ENTRY_SIZE*3)
   4644  1.1  christos #define elf_backend_rela_normal		    1
   4645  1.1  christos 
   4646  1.1  christos #define elf_info_to_howto		    elf_x86_64_info_to_howto
   4647  1.1  christos 
   4648  1.1  christos #define bfd_elf64_bfd_link_hash_table_create \
   4649  1.1  christos   elf_x86_64_link_hash_table_create
   4650  1.1  christos #define bfd_elf64_bfd_link_hash_table_free \
   4651  1.1  christos   elf_x86_64_link_hash_table_free
   4652  1.1  christos #define bfd_elf64_bfd_reloc_type_lookup	    elf_x86_64_reloc_type_lookup
   4653  1.1  christos #define bfd_elf64_bfd_reloc_name_lookup \
   4654  1.1  christos   elf_x86_64_reloc_name_lookup
   4655  1.1  christos 
   4656  1.1  christos #define elf_backend_adjust_dynamic_symbol   elf_x86_64_adjust_dynamic_symbol
   4657  1.1  christos #define elf_backend_relocs_compatible	    elf_x86_64_relocs_compatible
   4658  1.1  christos #define elf_backend_check_relocs	    elf_x86_64_check_relocs
   4659  1.1  christos #define elf_backend_copy_indirect_symbol    elf_x86_64_copy_indirect_symbol
   4660  1.1  christos #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
   4661  1.1  christos #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
   4662  1.1  christos #define elf_backend_finish_dynamic_symbol   elf_x86_64_finish_dynamic_symbol
   4663  1.1  christos #define elf_backend_gc_mark_hook	    elf_x86_64_gc_mark_hook
   4664  1.1  christos #define elf_backend_gc_sweep_hook	    elf_x86_64_gc_sweep_hook
   4665  1.1  christos #define elf_backend_grok_prstatus	    elf_x86_64_grok_prstatus
   4666  1.1  christos #define elf_backend_grok_psinfo		    elf_x86_64_grok_psinfo
   4667  1.1  christos #define elf_backend_reloc_type_class	    elf_x86_64_reloc_type_class
   4668  1.1  christos #define elf_backend_relocate_section	    elf_x86_64_relocate_section
   4669  1.1  christos #define elf_backend_size_dynamic_sections   elf_x86_64_size_dynamic_sections
   4670  1.1  christos #define elf_backend_always_size_sections    elf_x86_64_always_size_sections
   4671  1.1  christos #define elf_backend_init_index_section	    _bfd_elf_init_1_index_section
   4672  1.1  christos #define elf_backend_plt_sym_val		    elf_x86_64_plt_sym_val
   4673  1.1  christos #define elf_backend_object_p		    elf64_x86_64_elf_object_p
   4674  1.1  christos #define bfd_elf64_mkobject		    elf_x86_64_mkobject
   4675  1.1  christos 
   4676  1.1  christos #define elf_backend_section_from_shdr \
   4677  1.1  christos 	elf_x86_64_section_from_shdr
   4678  1.1  christos 
   4679  1.1  christos #define elf_backend_section_from_bfd_section \
   4680  1.1  christos   elf_x86_64_elf_section_from_bfd_section
   4681  1.1  christos #define elf_backend_add_symbol_hook \
   4682  1.1  christos   elf_x86_64_add_symbol_hook
   4683  1.1  christos #define elf_backend_symbol_processing \
   4684  1.1  christos   elf_x86_64_symbol_processing
   4685  1.1  christos #define elf_backend_common_section_index \
   4686  1.1  christos   elf_x86_64_common_section_index
   4687  1.1  christos #define elf_backend_common_section \
   4688  1.1  christos   elf_x86_64_common_section
   4689  1.1  christos #define elf_backend_common_definition \
   4690  1.1  christos   elf_x86_64_common_definition
   4691  1.1  christos #define elf_backend_merge_symbol \
   4692  1.1  christos   elf_x86_64_merge_symbol
   4693  1.1  christos #define elf_backend_special_sections \
   4694  1.1  christos   elf_x86_64_special_sections
   4695  1.1  christos #define elf_backend_additional_program_headers \
   4696  1.1  christos   elf_x86_64_additional_program_headers
   4697  1.1  christos #define elf_backend_hash_symbol \
   4698  1.1  christos   elf_x86_64_hash_symbol
   4699  1.1  christos 
   4700  1.1  christos #undef  elf_backend_post_process_headers
   4701  1.1  christos #define elf_backend_post_process_headers  _bfd_elf_set_osabi
   4702  1.1  christos 
   4703  1.1  christos #include "elf64-target.h"
   4704  1.1  christos 
   4705  1.1  christos /* FreeBSD support.  */
   4706  1.1  christos 
   4707  1.1  christos #undef  TARGET_LITTLE_SYM
   4708  1.1  christos #define TARGET_LITTLE_SYM		    bfd_elf64_x86_64_freebsd_vec
   4709  1.1  christos #undef  TARGET_LITTLE_NAME
   4710  1.1  christos #define TARGET_LITTLE_NAME		    "elf64-x86-64-freebsd"
   4711  1.1  christos 
   4712  1.1  christos #undef	ELF_OSABI
   4713  1.1  christos #define	ELF_OSABI			    ELFOSABI_FREEBSD
   4714  1.1  christos 
   4715  1.1  christos #undef  elf64_bed
   4716  1.1  christos #define elf64_bed elf64_x86_64_fbsd_bed
   4717  1.1  christos 
   4718  1.1  christos #include "elf64-target.h"
   4719  1.1  christos 
   4720  1.1  christos /* Solaris 2 support.  */
   4721  1.1  christos 
   4722  1.1  christos #undef  TARGET_LITTLE_SYM
   4723  1.1  christos #define TARGET_LITTLE_SYM		    bfd_elf64_x86_64_sol2_vec
   4724  1.1  christos #undef  TARGET_LITTLE_NAME
   4725  1.1  christos #define TARGET_LITTLE_NAME		    "elf64-x86-64-sol2"
   4726  1.1  christos 
   4727  1.1  christos /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
   4728  1.1  christos    objects won't be recognized.  */
   4729  1.1  christos #undef ELF_OSABI
   4730  1.1  christos 
   4731  1.1  christos #undef  elf64_bed
   4732  1.1  christos #define elf64_bed			    elf64_x86_64_sol2_bed
   4733  1.1  christos 
   4734  1.1  christos /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
   4735  1.1  christos    boundary.  */
   4736  1.1  christos #undef elf_backend_static_tls_alignment
   4737  1.1  christos #define elf_backend_static_tls_alignment    16
   4738  1.1  christos 
   4739  1.1  christos /* The Solaris 2 ABI requires a plt symbol on all platforms.
   4740  1.1  christos 
   4741  1.1  christos    Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
   4742  1.1  christos    File, p.63.  */
   4743  1.1  christos #undef elf_backend_want_plt_sym
   4744  1.1  christos #define elf_backend_want_plt_sym	    1
   4745  1.1  christos 
   4746  1.1  christos #include "elf64-target.h"
   4747  1.1  christos 
   4748  1.1  christos /* Intel L1OM support.  */
   4749  1.1  christos 
   4750  1.1  christos static bfd_boolean
   4751  1.1  christos elf64_l1om_elf_object_p (bfd *abfd)
   4752  1.1  christos {
   4753  1.1  christos   /* Set the right machine number for an L1OM elf64 file.  */
   4754  1.1  christos   bfd_default_set_arch_mach (abfd, bfd_arch_l1om, bfd_mach_l1om);
   4755  1.1  christos   return TRUE;
   4756  1.1  christos }
   4757  1.1  christos 
   4758  1.1  christos #undef  TARGET_LITTLE_SYM
   4759  1.1  christos #define TARGET_LITTLE_SYM		    bfd_elf64_l1om_vec
   4760  1.1  christos #undef  TARGET_LITTLE_NAME
   4761  1.1  christos #define TARGET_LITTLE_NAME		    "elf64-l1om"
   4762  1.1  christos #undef ELF_ARCH
   4763  1.1  christos #define ELF_ARCH			    bfd_arch_l1om
   4764  1.1  christos 
   4765  1.1  christos #undef	ELF_MACHINE_CODE
   4766  1.1  christos #define ELF_MACHINE_CODE		    EM_L1OM
   4767  1.1  christos 
   4768  1.1  christos #undef	ELF_OSABI
   4769  1.1  christos 
   4770  1.1  christos #undef  elf64_bed
   4771  1.1  christos #define elf64_bed elf64_l1om_bed
   4772  1.1  christos 
   4773  1.1  christos #undef elf_backend_object_p
   4774  1.1  christos #define elf_backend_object_p		    elf64_l1om_elf_object_p
   4775  1.1  christos 
   4776  1.1  christos #undef  elf_backend_post_process_headers
   4777  1.1  christos #undef  elf_backend_static_tls_alignment
   4778  1.1  christos 
   4779  1.1  christos #undef elf_backend_want_plt_sym
   4780  1.1  christos #define elf_backend_want_plt_sym	    0
   4781  1.1  christos 
   4782  1.1  christos #include "elf64-target.h"
   4783  1.1  christos 
   4784  1.1  christos /* FreeBSD L1OM support.  */
   4785  1.1  christos 
   4786  1.1  christos #undef  TARGET_LITTLE_SYM
   4787  1.1  christos #define TARGET_LITTLE_SYM		    bfd_elf64_l1om_freebsd_vec
   4788  1.1  christos #undef  TARGET_LITTLE_NAME
   4789  1.1  christos #define TARGET_LITTLE_NAME		    "elf64-l1om-freebsd"
   4790  1.1  christos 
   4791  1.1  christos #undef	ELF_OSABI
   4792  1.1  christos #define	ELF_OSABI			    ELFOSABI_FREEBSD
   4793  1.1  christos 
   4794  1.1  christos #undef  elf64_bed
   4795  1.1  christos #define elf64_bed elf64_l1om_fbsd_bed
   4796  1.1  christos 
   4797  1.1  christos #undef  elf_backend_post_process_headers
   4798  1.1  christos #define elf_backend_post_process_headers  _bfd_elf_set_osabi
   4799  1.1  christos 
   4800  1.1  christos #include "elf64-target.h"
   4801  1.1  christos 
   4802  1.1  christos /* 32bit x86-64 support.  */
   4803  1.1  christos 
   4804  1.1  christos static bfd_boolean
   4805  1.1  christos elf32_x86_64_elf_object_p (bfd *abfd)
   4806  1.1  christos {
   4807  1.1  christos   /* Set the right machine number for an x86-64 elf32 file.  */
   4808  1.1  christos   bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32);
   4809  1.1  christos   return TRUE;
   4810  1.1  christos }
   4811  1.1  christos 
   4812  1.1  christos #undef  TARGET_LITTLE_SYM
   4813  1.1  christos #define TARGET_LITTLE_SYM		    bfd_elf32_x86_64_vec
   4814  1.1  christos #undef  TARGET_LITTLE_NAME
   4815  1.1  christos #define TARGET_LITTLE_NAME		    "elf32-x86-64"
   4816  1.1  christos 
   4817  1.1  christos #undef ELF_ARCH
   4818  1.1  christos #define ELF_ARCH			    bfd_arch_i386
   4819  1.1  christos 
   4820  1.1  christos #undef	ELF_MACHINE_CODE
   4821  1.1  christos #define ELF_MACHINE_CODE		    EM_X86_64
   4822  1.1  christos 
   4823  1.1  christos #define bfd_elf32_bfd_link_hash_table_create \
   4824  1.1  christos   elf_x86_64_link_hash_table_create
   4825  1.1  christos #define bfd_elf32_bfd_link_hash_table_free \
   4826  1.1  christos   elf_x86_64_link_hash_table_free
   4827  1.1  christos #define bfd_elf32_bfd_reloc_type_lookup	\
   4828  1.1  christos   elf_x86_64_reloc_type_lookup
   4829  1.1  christos #define bfd_elf32_bfd_reloc_name_lookup \
   4830  1.1  christos   elf_x86_64_reloc_name_lookup
   4831  1.1  christos #define bfd_elf32_mkobject \
   4832  1.1  christos   elf_x86_64_mkobject
   4833  1.1  christos 
   4834  1.1  christos #undef	ELF_OSABI
   4835  1.1  christos 
   4836  1.1  christos #undef elf_backend_post_process_headers
   4837  1.1  christos 
   4838  1.1  christos #undef elf_backend_object_p
   4839  1.1  christos #define elf_backend_object_p \
   4840  1.1  christos   elf32_x86_64_elf_object_p
   4841  1.1  christos 
   4842  1.1  christos #undef elf_backend_bfd_from_remote_memory
   4843  1.1  christos #define elf_backend_bfd_from_remote_memory \
   4844  1.1  christos   _bfd_elf32_bfd_from_remote_memory
   4845  1.1  christos 
   4846  1.1  christos #undef elf_backend_size_info
   4847  1.1  christos #define elf_backend_size_info \
   4848  1.1  christos   _bfd_elf32_size_info
   4849                
   4850                #include "elf32-target.h"
   4851