Home | History | Annotate | Line # | Download | only in bfd
      1       1.1  christos /* TILE-Gx-specific support for ELF.
      2  1.1.1.10  christos    Copyright (C) 2011-2026 Free Software Foundation, Inc.
      3       1.1  christos 
      4       1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      5       1.1  christos 
      6       1.1  christos    This program is free software; you can redistribute it and/or modify
      7       1.1  christos    it under the terms of the GNU General Public License as published by
      8       1.1  christos    the Free Software Foundation; either version 3 of the License, or
      9       1.1  christos    (at your option) any later version.
     10       1.1  christos 
     11       1.1  christos    This program is distributed in the hope that it will be useful,
     12       1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13       1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14       1.1  christos    GNU General Public License for more details.
     15       1.1  christos 
     16       1.1  christos    You should have received a copy of the GNU General Public License
     17       1.1  christos    along with this program; if not, write to the Free Software
     18       1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     19       1.1  christos    MA 02110-1301, USA.  */
     20       1.1  christos 
     21       1.1  christos #include "sysdep.h"
     22       1.1  christos #include "bfd.h"
     23       1.1  christos #include "libbfd.h"
     24       1.1  christos #include "elf-bfd.h"
     25       1.1  christos #include "elf/tilegx.h"
     26       1.1  christos #include "opcode/tilegx.h"
     27       1.1  christos #include "libiberty.h"
     28       1.1  christos #include "elfxx-tilegx.h"
     29       1.1  christos 
     30       1.1  christos #define TILEGX_ELF_WORD_BYTES(htab) \
     31       1.1  christos   ((htab)->bytes_per_word)
     32       1.1  christos 
     33       1.1  christos /* The size of an external RELA relocation.  */
     34       1.1  christos #define TILEGX_ELF_RELA_BYTES(htab) \
     35       1.1  christos   ((htab)->bytes_per_rela)
     36       1.1  christos 
     37       1.1  christos /* Both 32-bit and 64-bit tilegx encode this in an identical manner,
     38       1.1  christos    so just take advantage of that.  */
     39       1.1  christos #define TILEGX_ELF_R_TYPE(r_info) \
     40       1.1  christos   ((r_info) & 0xFF)
     41       1.1  christos 
     42       1.1  christos #define TILEGX_ELF_R_INFO(htab, in_rel, index, type)	\
     43       1.1  christos   ((htab)->r_info (in_rel, index, type))
     44       1.1  christos 
     45       1.1  christos #define TILEGX_ELF_R_SYMNDX(htab, r_info) \
     46       1.1  christos   ((htab)->r_symndx(r_info))
     47       1.1  christos 
     48       1.1  christos #define TILEGX_ELF_DTPOFF_RELOC(htab) \
     49       1.1  christos   ((htab)->dtpoff_reloc)
     50       1.1  christos 
     51       1.1  christos #define TILEGX_ELF_DTPMOD_RELOC(htab) \
     52       1.1  christos   ((htab)->dtpmod_reloc)
     53       1.1  christos 
     54       1.1  christos #define TILEGX_ELF_TPOFF_RELOC(htab) \
     55       1.1  christos   ((htab)->tpoff_reloc)
     56       1.1  christos 
     57       1.1  christos #define TILEGX_ELF_PUT_WORD(htab, bfd, val, ptr) \
     58       1.1  christos   ((htab)->put_word (bfd, val, ptr))
     59       1.1  christos 
     60       1.1  christos /* The name of the dynamic interpreter.  This is put in the .interp
     61       1.1  christos    section.  */
     62       1.1  christos 
     63       1.1  christos #define ELF64_DYNAMIC_INTERPRETER "/lib/ld.so.1"
     64       1.1  christos #define ELF32_DYNAMIC_INTERPRETER "/lib32/ld.so.1"
     65       1.1  christos 
     66       1.1  christos 
     67       1.1  christos static reloc_howto_type tilegx_elf_howto_table [] =
     68       1.1  christos {
     69       1.1  christos   /* This reloc does nothing.  */
     70       1.1  christos   HOWTO (R_TILEGX_NONE,	/* type */
     71       1.1  christos 	 0,			/* rightshift */
     72   1.1.1.7  christos 	 0,			/* size */
     73   1.1.1.2  christos 	 0,			/* bitsize */
     74   1.1.1.7  christos 	 false,			/* pc_relative */
     75       1.1  christos 	 0,			/* bitpos */
     76   1.1.1.2  christos 	 complain_overflow_dont, /* complain_on_overflow */
     77       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
     78       1.1  christos 	 "R_TILEGX_NONE",	/* name */
     79   1.1.1.7  christos 	 false,			/* partial_inplace */
     80       1.1  christos 	 0,			/* src_mask */
     81       1.1  christos 	 0,			/* dst_mask */
     82   1.1.1.7  christos 	 false),		/* pcrel_offset */
     83       1.1  christos #ifdef BFD64
     84       1.1  christos   /* A 64 bit absolute relocation.  */
     85       1.1  christos   HOWTO (R_TILEGX_64,	/* type */
     86       1.1  christos 	 0,			/* rightshift */
     87   1.1.1.7  christos 	 8,			/* size */
     88       1.1  christos 	 64,			/* bitsize */
     89   1.1.1.7  christos 	 false,			/* pc_relative */
     90       1.1  christos 	 0,			/* bitpos */
     91       1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
     92       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
     93       1.1  christos 	 "R_TILEGX_64",	/* name */
     94   1.1.1.7  christos 	 false,			/* partial_inplace */
     95       1.1  christos 	 0,			/* src_mask */
     96       1.1  christos 	 0xffffffffffffffffULL,	/* dst_mask */
     97   1.1.1.7  christos 	 false),		/* pcrel_offset */
     98       1.1  christos #endif
     99       1.1  christos   /* A 32 bit absolute relocation.  */
    100       1.1  christos   HOWTO (R_TILEGX_32,	/* type */
    101       1.1  christos 	 0,			/* rightshift */
    102   1.1.1.7  christos 	 4,			/* size */
    103       1.1  christos 	 32,			/* bitsize */
    104   1.1.1.7  christos 	 false,			/* pc_relative */
    105       1.1  christos 	 0,			/* bitpos */
    106       1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    107       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    108       1.1  christos 	 "R_TILEGX_32",	/* name */
    109   1.1.1.7  christos 	 false,			/* partial_inplace */
    110       1.1  christos 	 0,			/* src_mask */
    111       1.1  christos 	 0xffffffff,		/* dst_mask */
    112   1.1.1.7  christos 	 false),		/* pcrel_offset */
    113       1.1  christos 
    114       1.1  christos   /* A 16 bit absolute relocation.  */
    115       1.1  christos   HOWTO (R_TILEGX_16,	/* type */
    116       1.1  christos 	 0,			/* rightshift */
    117   1.1.1.7  christos 	 2,			/* size */
    118       1.1  christos 	 16,			/* bitsize */
    119   1.1.1.7  christos 	 false,			/* pc_relative */
    120       1.1  christos 	 0,			/* bitpos */
    121       1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    122       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    123       1.1  christos 	 "R_TILEGX_16",	/* name */
    124   1.1.1.7  christos 	 false,			/* partial_inplace */
    125       1.1  christos 	 0,			/* src_mask */
    126       1.1  christos 	 0xffff,		/* dst_mask */
    127   1.1.1.7  christos 	 false),		/* pcrel_offset */
    128       1.1  christos 
    129       1.1  christos   /* An 8 bit absolute relocation.  */
    130       1.1  christos   HOWTO (R_TILEGX_8,	/* type */
    131       1.1  christos 	 0,			/* rightshift */
    132   1.1.1.7  christos 	 1,			/* size */
    133       1.1  christos 	 8,			/* bitsize */
    134   1.1.1.7  christos 	 false,			/* pc_relative */
    135       1.1  christos 	 0,			/* bitpos */
    136       1.1  christos 	 complain_overflow_unsigned, /* complain_on_overflow */
    137       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    138       1.1  christos 	 "R_TILEGX_8",	/* name */
    139   1.1.1.7  christos 	 false,			/* partial_inplace */
    140       1.1  christos 	 0,			/* src_mask */
    141       1.1  christos 	 0xff,			/* dst_mask */
    142   1.1.1.7  christos 	 false),		/* pcrel_offset */
    143       1.1  christos #ifdef BFD64
    144       1.1  christos   /* A 64 bit pc-relative relocation.  */
    145       1.1  christos   HOWTO (R_TILEGX_64_PCREL,/* type */
    146       1.1  christos 	 0,			/* rightshift */
    147   1.1.1.7  christos 	 8,			/* size */
    148       1.1  christos 	 64,			/* bitsize */
    149   1.1.1.7  christos 	 true,			/* pc_relative */
    150       1.1  christos 	 0,			/* bitpos */
    151       1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    152       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    153       1.1  christos 	 "R_TILEGX_32_PCREL", /* name */
    154   1.1.1.7  christos 	 false,			/* partial_inplace */
    155       1.1  christos 	 0,			/* src_mask */
    156       1.1  christos 	 0xffffffffffffffffULL,	/* dst_mask */
    157   1.1.1.7  christos 	 true),			/* pcrel_offset */
    158       1.1  christos #endif
    159       1.1  christos   /* A 32 bit pc-relative relocation.  */
    160       1.1  christos   HOWTO (R_TILEGX_32_PCREL,/* type */
    161       1.1  christos 	 0,			/* rightshift */
    162   1.1.1.7  christos 	 4,			/* size */
    163       1.1  christos 	 32,			/* bitsize */
    164   1.1.1.7  christos 	 true,			/* pc_relative */
    165       1.1  christos 	 0,			/* bitpos */
    166       1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    167       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    168       1.1  christos 	 "R_TILEGX_32_PCREL", /* name */
    169   1.1.1.7  christos 	 false,			/* partial_inplace */
    170       1.1  christos 	 0,			/* src_mask */
    171       1.1  christos 	 0xffffffff,		/* dst_mask */
    172   1.1.1.7  christos 	 true),			/* pcrel_offset */
    173       1.1  christos 
    174       1.1  christos   /* A 16 bit pc-relative relocation.  */
    175       1.1  christos   HOWTO (R_TILEGX_16_PCREL,/* type */
    176       1.1  christos 	 0,			/* rightshift */
    177   1.1.1.7  christos 	 2,			/* size */
    178       1.1  christos 	 16,			/* bitsize */
    179   1.1.1.7  christos 	 true,			/* pc_relative */
    180       1.1  christos 	 0,			/* bitpos */
    181       1.1  christos 	 complain_overflow_signed, /* complain_on_overflow */
    182       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    183       1.1  christos 	 "R_TILEGX_16_PCREL",	/* name */
    184   1.1.1.7  christos 	 false,			/* partial_inplace */
    185       1.1  christos 	 0,			/* src_mask */
    186       1.1  christos 	 0xffff,		/* dst_mask */
    187   1.1.1.7  christos 	 true),			/* pcrel_offset */
    188       1.1  christos 
    189       1.1  christos   /* An 8 bit pc-relative relocation.  */
    190       1.1  christos   HOWTO (R_TILEGX_8_PCREL,	/* type */
    191       1.1  christos 	 0,			/* rightshift */
    192   1.1.1.7  christos 	 1,			/* size */
    193       1.1  christos 	 8,			/* bitsize */
    194   1.1.1.7  christos 	 true,			/* pc_relative */
    195       1.1  christos 	 0,			/* bitpos */
    196       1.1  christos 	 complain_overflow_signed, /* complain_on_overflow */
    197       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    198       1.1  christos 	 "R_TILEGX_8_PCREL",/* name */
    199   1.1.1.7  christos 	 false,			/* partial_inplace */
    200       1.1  christos 	 0,			/* src_mask */
    201       1.1  christos 	 0xff,			/* dst_mask */
    202   1.1.1.7  christos 	 true),			/* pcrel_offset */
    203       1.1  christos 
    204       1.1  christos   /* A 16 bit relocation without overflow.  */
    205       1.1  christos   HOWTO (R_TILEGX_HW0,	/* type */
    206       1.1  christos 	 0,			/* rightshift */
    207   1.1.1.7  christos 	 2,			/* size */
    208       1.1  christos 	 16,			/* bitsize */
    209   1.1.1.7  christos 	 false,			/* pc_relative */
    210       1.1  christos 	 0,			/* bitpos */
    211       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    212       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    213       1.1  christos 	 "R_TILEGX_HW0",	/* name */
    214   1.1.1.7  christos 	 false,			/* partial_inplace */
    215       1.1  christos 	 0,			/* src_mask */
    216       1.1  christos 	 0xffff,		/* dst_mask */
    217   1.1.1.7  christos 	 false),		/* pcrel_offset */
    218       1.1  christos 
    219       1.1  christos   /* A 16 bit relocation without overflow.  */
    220       1.1  christos   HOWTO (R_TILEGX_HW1,	/* type */
    221       1.1  christos 	 16,			/* rightshift */
    222   1.1.1.7  christos 	 2,			/* size */
    223       1.1  christos 	 16,			/* bitsize */
    224   1.1.1.7  christos 	 false,			/* pc_relative */
    225       1.1  christos 	 0,			/* bitpos */
    226       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    227       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    228       1.1  christos 	 "R_TILEGX_HW1",	/* name */
    229   1.1.1.7  christos 	 false,			/* partial_inplace */
    230       1.1  christos 	 0,			/* src_mask */
    231       1.1  christos 	 0xffff,		/* dst_mask */
    232   1.1.1.7  christos 	 false),		/* pcrel_offset */
    233       1.1  christos 
    234       1.1  christos   /* A 16 bit relocation without overflow.  */
    235       1.1  christos   HOWTO (R_TILEGX_HW2,	/* type */
    236       1.1  christos 	 32,			/* rightshift */
    237   1.1.1.7  christos 	 2,			/* size */
    238       1.1  christos 	 16,			/* bitsize */
    239   1.1.1.7  christos 	 false,			/* pc_relative */
    240       1.1  christos 	 0,			/* bitpos */
    241       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    242       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    243       1.1  christos 	 "R_TILEGX_HW2",	/* name */
    244   1.1.1.7  christos 	 false,			/* partial_inplace */
    245       1.1  christos 	 0,			/* src_mask */
    246       1.1  christos 	 0xffff,		/* dst_mask */
    247   1.1.1.7  christos 	 false),		/* pcrel_offset */
    248       1.1  christos 
    249       1.1  christos   /* A 16 bit relocation without overflow.  */
    250       1.1  christos   HOWTO (R_TILEGX_HW3,	/* type */
    251       1.1  christos 	 48,			/* rightshift */
    252   1.1.1.7  christos 	 2,			/* size */
    253       1.1  christos 	 16,			/* bitsize */
    254   1.1.1.7  christos 	 false,			/* pc_relative */
    255       1.1  christos 	 0,			/* bitpos */
    256       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    257       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    258       1.1  christos 	 "R_TILEGX_HW3",	/* name */
    259   1.1.1.7  christos 	 false,			/* partial_inplace */
    260       1.1  christos 	 0,			/* src_mask */
    261       1.1  christos 	 0xffff,		/* dst_mask */
    262   1.1.1.7  christos 	 false),		/* pcrel_offset */
    263       1.1  christos 
    264       1.1  christos   /* A 16 bit relocation with overflow.  */
    265       1.1  christos   HOWTO (R_TILEGX_HW0_LAST,	/* type */
    266       1.1  christos 	 0,			/* rightshift */
    267   1.1.1.7  christos 	 2,			/* size */
    268       1.1  christos 	 16,			/* bitsize */
    269   1.1.1.7  christos 	 false,			/* pc_relative */
    270       1.1  christos 	 0,			/* bitpos */
    271       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    272       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    273       1.1  christos 	 "R_TILEGX_HW0_LAST",	/* name */
    274   1.1.1.7  christos 	 false,			/* partial_inplace */
    275       1.1  christos 	 0,			/* src_mask */
    276       1.1  christos 	 0xffff,		/* dst_mask */
    277   1.1.1.7  christos 	 false),		/* pcrel_offset */
    278       1.1  christos 
    279       1.1  christos   /* A 16 bit relocation with overflow.  */
    280       1.1  christos   HOWTO (R_TILEGX_HW1_LAST,	/* type */
    281       1.1  christos 	 16,			/* rightshift */
    282   1.1.1.7  christos 	 2,			/* size */
    283       1.1  christos 	 16,			/* bitsize */
    284   1.1.1.7  christos 	 false,			/* pc_relative */
    285       1.1  christos 	 0,			/* bitpos */
    286       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    287       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    288       1.1  christos 	 "R_TILEGX_HW1_LAST",	/* name */
    289   1.1.1.7  christos 	 false,			/* partial_inplace */
    290       1.1  christos 	 0,			/* src_mask */
    291       1.1  christos 	 0xffff,		/* dst_mask */
    292   1.1.1.7  christos 	 false),		/* pcrel_offset */
    293       1.1  christos 
    294       1.1  christos   /* A 16 bit relocation with overflow.  */
    295       1.1  christos   HOWTO (R_TILEGX_HW2_LAST,	/* type */
    296       1.1  christos 	 32,			/* rightshift */
    297   1.1.1.7  christos 	 2,			/* size */
    298       1.1  christos 	 16,			/* bitsize */
    299   1.1.1.7  christos 	 false,			/* pc_relative */
    300       1.1  christos 	 0,			/* bitpos */
    301       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    302       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    303       1.1  christos 	 "R_TILEGX_HW2_LAST",	/* name */
    304   1.1.1.7  christos 	 false,			/* partial_inplace */
    305       1.1  christos 	 0,			/* src_mask */
    306       1.1  christos 	 0xffff,		/* dst_mask */
    307   1.1.1.7  christos 	 false),		/* pcrel_offset */
    308       1.1  christos 
    309       1.1  christos   HOWTO (R_TILEGX_COPY,		/* type */
    310       1.1  christos 	 0,			/* rightshift */
    311   1.1.1.7  christos 	 0,			/* size */
    312       1.1  christos 	 0,			/* bitsize */
    313   1.1.1.7  christos 	 false,			/* pc_relative */
    314       1.1  christos 	 0,			/* bitpos */
    315       1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    316       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    317       1.1  christos 	 "R_TILEGX_COPY",		/* name */
    318   1.1.1.7  christos 	 false,			/* partial_inplace */
    319       1.1  christos 	 0,			/* src_mask */
    320       1.1  christos 	 0,			/* dst_mask */
    321   1.1.1.7  christos 	 true),			/* pcrel_offset */
    322       1.1  christos 
    323       1.1  christos   HOWTO (R_TILEGX_GLOB_DAT,	/* type */
    324       1.1  christos 	 0,			/* rightshift */
    325   1.1.1.7  christos 	 0,			/* size */
    326       1.1  christos 	 0,			/* bitsize */
    327   1.1.1.7  christos 	 false,			/* pc_relative */
    328       1.1  christos 	 0,			/* bitpos */
    329       1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    330       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    331       1.1  christos 	 "R_TILEGX_GLOB_DAT",	/* name */
    332   1.1.1.7  christos 	 false,			/* partial_inplace */
    333       1.1  christos 	 0,			/* src_mask */
    334       1.1  christos 	 0,			/* dst_mask */
    335   1.1.1.7  christos 	 true),			/* pcrel_offset */
    336       1.1  christos 
    337       1.1  christos   HOWTO (R_TILEGX_JMP_SLOT,	/* type */
    338       1.1  christos 	 0,			/* rightshift */
    339   1.1.1.7  christos 	 0,			/* size */
    340       1.1  christos 	 0,			/* bitsize */
    341   1.1.1.7  christos 	 false,			/* pc_relative */
    342       1.1  christos 	 0,			/* bitpos */
    343       1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    344       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    345       1.1  christos 	 "R_TILEGX_JMP_SLOT",	/* name */
    346   1.1.1.7  christos 	 false,			/* partial_inplace */
    347       1.1  christos 	 0,			/* src_mask */
    348       1.1  christos 	 0,			/* dst_mask */
    349   1.1.1.7  christos 	 true),			/* pcrel_offset */
    350       1.1  christos 
    351       1.1  christos   HOWTO (R_TILEGX_RELATIVE,	/* type */
    352       1.1  christos 	 0,			/* rightshift */
    353   1.1.1.7  christos 	 0,			/* size */
    354       1.1  christos 	 0,			/* bitsize */
    355   1.1.1.7  christos 	 false,			/* pc_relative */
    356       1.1  christos 	 0,			/* bitpos */
    357       1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    358       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    359       1.1  christos 	 "R_TILEGX_RELATIVE",	/* name */
    360   1.1.1.7  christos 	 false,			/* partial_inplace */
    361       1.1  christos 	 0,			/* src_mask */
    362       1.1  christos 	 0,			/* dst_mask */
    363   1.1.1.7  christos 	 true),			/* pcrel_offset */
    364       1.1  christos 
    365       1.1  christos   HOWTO (R_TILEGX_BROFF_X1, /* type */
    366       1.1  christos 	 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
    367   1.1.1.7  christos 	 4,			/* size */
    368       1.1  christos 	 17,			/* bitsize */
    369   1.1.1.7  christos 	 true,			/* pc_relative */
    370       1.1  christos 	 0,			/* bitpos */
    371       1.1  christos 	 complain_overflow_signed, /* complain_on_overflow */
    372       1.1  christos 	 bfd_elf_generic_reloc, /* special_function */
    373       1.1  christos 	 "R_TILEGX_BROFF_X1", /* name */
    374   1.1.1.7  christos 	 false,			/* partial_inplace */
    375       1.1  christos 	 0,			/* src_mask */
    376       1.1  christos 	 -1,			/* dst_mask */
    377   1.1.1.7  christos 	 true),			/* pcrel_offset */
    378       1.1  christos 
    379       1.1  christos   HOWTO (R_TILEGX_JUMPOFF_X1, /* type */
    380       1.1  christos 	 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
    381   1.1.1.7  christos 	 4,			/* size */
    382       1.1  christos 	 27,			/* bitsize */
    383   1.1.1.7  christos 	 true,			/* pc_relative */
    384       1.1  christos 	 0,			/* bitpos */
    385       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    386       1.1  christos 	 bfd_elf_generic_reloc, /* special_function */
    387       1.1  christos 	 "R_TILEGX_JUMPOFF_X1", /* name */
    388   1.1.1.7  christos 	 false,			/* partial_inplace */
    389       1.1  christos 	 0,			/* src_mask */
    390       1.1  christos 	 -1,			/* dst_mask */
    391   1.1.1.7  christos 	 true),			/* pcrel_offset */
    392       1.1  christos 
    393       1.1  christos   HOWTO (R_TILEGX_JUMPOFF_X1_PLT, /* type */
    394       1.1  christos 	 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
    395   1.1.1.7  christos 	 4,			/* size */
    396       1.1  christos 	 27,			/* bitsize */
    397   1.1.1.7  christos 	 true,			/* pc_relative */
    398       1.1  christos 	 0,			/* bitpos */
    399       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    400       1.1  christos 	 bfd_elf_generic_reloc, /* special_function */
    401       1.1  christos 	 "R_TILEGX_JUMPOFF_X1_PLT", /* name */
    402   1.1.1.7  christos 	 false,			/* partial_inplace */
    403       1.1  christos 	 0,			/* src_mask */
    404       1.1  christos 	 -1,			/* dst_mask */
    405   1.1.1.7  christos 	 true),			/* pcrel_offset */
    406       1.1  christos 
    407       1.1  christos #define TILEGX_IMM_HOWTO(name, size, bitsize) \
    408   1.1.1.7  christos   HOWTO (name, 0, size, bitsize, false, 0, \
    409   1.1.1.4  christos 	 complain_overflow_signed, bfd_elf_generic_reloc, \
    410   1.1.1.7  christos 	 #name, false, 0, -1, false)
    411       1.1  christos 
    412       1.1  christos #define TILEGX_UIMM_HOWTO(name, size, bitsize) \
    413   1.1.1.7  christos   HOWTO (name, 0, size, bitsize, false, 0, \
    414   1.1.1.4  christos 	 complain_overflow_unsigned, bfd_elf_generic_reloc, \
    415   1.1.1.7  christos 	 #name, false, 0, -1, false)
    416       1.1  christos 
    417   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X0, 1, 8),
    418   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y0, 1, 8),
    419   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X1, 1, 8),
    420   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y1, 1, 8),
    421   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_DEST_IMM8_X1, 1, 8),
    422   1.1.1.7  christos 
    423   1.1.1.7  christos   TILEGX_UIMM_HOWTO(R_TILEGX_MT_IMM14_X1, 2, 14),
    424   1.1.1.7  christos   TILEGX_UIMM_HOWTO(R_TILEGX_MF_IMM14_X1, 2, 14),
    425   1.1.1.7  christos 
    426   1.1.1.7  christos   TILEGX_UIMM_HOWTO(R_TILEGX_MMSTART_X0, 1, 6),
    427   1.1.1.7  christos   TILEGX_UIMM_HOWTO(R_TILEGX_MMEND_X0,   1, 6),
    428   1.1.1.7  christos 
    429   1.1.1.7  christos   TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_X0, 1, 6),
    430   1.1.1.7  christos   TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_X1, 1, 6),
    431   1.1.1.7  christos   TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_Y0, 1, 6),
    432   1.1.1.7  christos   TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_Y1, 1, 6),
    433       1.1  christos 
    434       1.1  christos #define TILEGX_IMM16_HOWTO(name, rshift) \
    435   1.1.1.7  christos   HOWTO (name, rshift, 2, 16, false, 0, \
    436   1.1.1.4  christos 	 complain_overflow_dont, bfd_elf_generic_reloc, \
    437   1.1.1.7  christos 	 #name, false, 0, 0xffff, false)
    438       1.1  christos 
    439       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW0, 0),
    440       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW0, 0),
    441       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW1, 16),
    442       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW1, 16),
    443       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW2, 32),
    444       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW2, 32),
    445       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW3, 48),
    446       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW3, 48),
    447       1.1  christos 
    448       1.1  christos #define TILEGX_IMM16_HOWTO_LAST(name, rshift) \
    449   1.1.1.7  christos   HOWTO (name, rshift, 2, 16, false, 0, \
    450   1.1.1.4  christos 	 complain_overflow_signed, bfd_elf_generic_reloc, \
    451   1.1.1.7  christos 	 #name, false, 0, 0xffff, false)
    452       1.1  christos 
    453       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW0_LAST, 0),
    454       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW0_LAST, 0),
    455       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW1_LAST, 16),
    456       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW1_LAST, 16),
    457       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW2_LAST, 32),
    458       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW2_LAST, 32),
    459       1.1  christos 
    460       1.1  christos   /* PC-relative offsets. */
    461       1.1  christos 
    462       1.1  christos #define TILEGX_IMM16_HOWTO_PCREL(name, rshift) \
    463   1.1.1.7  christos   HOWTO (name, rshift, 2, 16, true, 0, \
    464   1.1.1.4  christos 	 complain_overflow_dont, bfd_elf_generic_reloc, \
    465   1.1.1.7  christos 	 #name, false, 0, 0xffff, true)
    466       1.1  christos 
    467       1.1  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW0_PCREL, 0),
    468       1.1  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW0_PCREL, 0),
    469       1.1  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW1_PCREL, 16),
    470       1.1  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW1_PCREL, 16),
    471       1.1  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW2_PCREL, 32),
    472       1.1  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW2_PCREL, 32),
    473       1.1  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW3_PCREL, 48),
    474       1.1  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW3_PCREL, 48),
    475       1.1  christos 
    476       1.1  christos #define TILEGX_IMM16_HOWTO_LAST_PCREL(name, rshift) \
    477   1.1.1.7  christos   HOWTO (name, rshift, 2, 16, true, 0, \
    478   1.1.1.4  christos 	 complain_overflow_signed, bfd_elf_generic_reloc, \
    479   1.1.1.7  christos 	 #name, false, 0, 0xffff, true)
    480       1.1  christos 
    481       1.1  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW0_LAST_PCREL,  0),
    482       1.1  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW0_LAST_PCREL,  0),
    483       1.1  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW1_LAST_PCREL, 16),
    484       1.1  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW1_LAST_PCREL, 16),
    485       1.1  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW2_LAST_PCREL, 32),
    486       1.1  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW2_LAST_PCREL, 32),
    487       1.1  christos 
    488       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW0_GOT, 0),
    489       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW0_GOT, 0),
    490   1.1.1.2  christos 
    491   1.1.1.2  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW0_PLT_PCREL, 0),
    492   1.1.1.2  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW0_PLT_PCREL, 0),
    493   1.1.1.2  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW1_PLT_PCREL, 16),
    494   1.1.1.2  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW1_PLT_PCREL, 16),
    495   1.1.1.2  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW2_PLT_PCREL, 32),
    496   1.1.1.2  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW2_PLT_PCREL, 32),
    497       1.1  christos 
    498       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW0_LAST_GOT, 0),
    499       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW0_LAST_GOT, 0),
    500       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW1_LAST_GOT, 16),
    501       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW1_LAST_GOT, 16),
    502   1.1.1.2  christos 
    503   1.1.1.2  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW3_PLT_PCREL, 48),
    504   1.1.1.2  christos   TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW3_PLT_PCREL, 48),
    505       1.1  christos 
    506       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW0_TLS_GD, 0),
    507       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW0_TLS_GD, 0),
    508       1.1  christos 
    509       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW0_TLS_LE, 0),
    510       1.1  christos   TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW0_TLS_LE, 0),
    511       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE, 0),
    512       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE, 0),
    513       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE, 16),
    514       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE, 16),
    515       1.1  christos 
    516       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD, 0),
    517       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD, 0),
    518       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD, 16),
    519       1.1  christos   TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD, 16),
    520       1.1  christos   EMPTY_HOWTO (90),
    521       1.1  christos   EMPTY_HOWTO (91),
    522       1.1  christos 
    523       1.1  christos #define TILEGX_IMM16_HOWTO_TLS_IE(name, rshift) \
    524   1.1.1.7  christos   HOWTO (name, rshift, 2, 16, false, 0, \
    525   1.1.1.4  christos 	 complain_overflow_dont, bfd_elf_generic_reloc, \
    526   1.1.1.7  christos 	 #name, false, 0, 0xffff, true)
    527       1.1  christos 
    528       1.1  christos   TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X0_HW0_TLS_IE, 0),
    529       1.1  christos   TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X1_HW0_TLS_IE, 0),
    530   1.1.1.2  christos 
    531   1.1.1.2  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL,  0),
    532   1.1.1.2  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL,  0),
    533   1.1.1.2  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL, 16),
    534   1.1.1.2  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL, 16),
    535   1.1.1.2  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL, 32),
    536   1.1.1.2  christos   TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL, 32),
    537       1.1  christos 
    538       1.1  christos #define TILEGX_IMM16_HOWTO_LAST_TLS_IE(name, rshift) \
    539   1.1.1.7  christos   HOWTO (name, rshift, 2, 16, false, 0, \
    540   1.1.1.4  christos 	 complain_overflow_signed, bfd_elf_generic_reloc, \
    541   1.1.1.7  christos 	 #name, false, 0, 0xffff, true)
    542       1.1  christos 
    543       1.1  christos   TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE, 0),
    544       1.1  christos   TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE, 0),
    545       1.1  christos   TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE, 16),
    546       1.1  christos   TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE, 16),
    547       1.1  christos   EMPTY_HOWTO (104),
    548       1.1  christos   EMPTY_HOWTO (105),
    549       1.1  christos 
    550   1.1.1.7  christos   HOWTO(R_TILEGX_TLS_DTPMOD64, 0, 0, 0, false, 0, complain_overflow_dont,
    551   1.1.1.4  christos 	bfd_elf_generic_reloc, "R_TILEGX_TLS_DTPMOD64",
    552   1.1.1.7  christos 	false, 0, 0, true),
    553   1.1.1.7  christos   HOWTO(R_TILEGX_TLS_DTPOFF64, 0, 8, 64, false, 0, complain_overflow_bitfield,
    554   1.1.1.4  christos 	bfd_elf_generic_reloc, "R_TILEGX_TLS_DTPOFF64",
    555   1.1.1.7  christos 	false, 0, -1, true),
    556   1.1.1.7  christos   HOWTO(R_TILEGX_TLS_TPOFF64, 0, 0, 0, false, 0, complain_overflow_dont,
    557   1.1.1.4  christos 	bfd_elf_generic_reloc, "R_TILEGX_TLS_TPOFF64",
    558   1.1.1.7  christos 	false, 0, 0, true),
    559       1.1  christos 
    560   1.1.1.7  christos   HOWTO(R_TILEGX_TLS_DTPMOD32, 0, 0, 0, false, 0, complain_overflow_dont,
    561   1.1.1.4  christos 	bfd_elf_generic_reloc, "R_TILEGX_TLS_DTPMOD32",
    562   1.1.1.7  christos 	false, 0, 0, true),
    563   1.1.1.7  christos   HOWTO(R_TILEGX_TLS_DTPOFF32, 0, 8, 32, false, 0, complain_overflow_bitfield,
    564   1.1.1.4  christos 	bfd_elf_generic_reloc, "R_TILEGX_TLS_DTPOFF32",
    565   1.1.1.7  christos 	false, 0, -1, true),
    566   1.1.1.7  christos   HOWTO(R_TILEGX_TLS_TPOFF32, 0, 0, 0, false, 0, complain_overflow_dont,
    567   1.1.1.4  christos 	bfd_elf_generic_reloc, "R_TILEGX_TLS_TPOFF32",
    568   1.1.1.7  christos 	false, 0, 0, true),
    569       1.1  christos 
    570       1.1  christos   HOWTO (R_TILEGX_TLS_GD_CALL, /* type */
    571       1.1  christos 	 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
    572   1.1.1.7  christos 	 4,			/* size */
    573       1.1  christos 	 27,			/* bitsize */
    574   1.1.1.7  christos 	 true,			/* pc_relative */
    575       1.1  christos 	 0,			/* bitpos */
    576       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    577       1.1  christos 	 bfd_elf_generic_reloc, /* special_function */
    578       1.1  christos 	 "R_TILEGX_TLS_GD_CALL", /* name */
    579   1.1.1.7  christos 	 false,			/* partial_inplace */
    580       1.1  christos 	 0,			/* src_mask */
    581       1.1  christos 	 -1,			/* dst_mask */
    582   1.1.1.7  christos 	 true),			/* pcrel_offset */
    583       1.1  christos 
    584   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X0_TLS_GD_ADD,  1,  8),
    585   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X1_TLS_GD_ADD,  1,  8),
    586   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y0_TLS_GD_ADD,  1,  8),
    587   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y1_TLS_GD_ADD,  1,  8),
    588   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_TLS_IE_LOAD, 1,  8),
    589   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X0_TLS_ADD,  1,  8),
    590   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X1_TLS_ADD,  1,  8),
    591   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y0_TLS_ADD,  1,  8),
    592   1.1.1.7  christos   TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y1_TLS_ADD,  1,  8),
    593       1.1  christos };
    594       1.1  christos 
    595       1.1  christos static reloc_howto_type tilegx_elf_howto_table2 [] =
    596       1.1  christos {
    597       1.1  christos   /* GNU extension to record C++ vtable hierarchy */
    598       1.1  christos   HOWTO (R_TILEGX_GNU_VTINHERIT, /* type */
    599   1.1.1.4  christos 	 0,			/* rightshift */
    600   1.1.1.7  christos 	 8,			/* size */
    601   1.1.1.4  christos 	 0,			/* bitsize */
    602   1.1.1.7  christos 	 false,			/* pc_relative */
    603   1.1.1.4  christos 	 0,			/* bitpos */
    604   1.1.1.4  christos 	 complain_overflow_dont, /* complain_on_overflow */
    605   1.1.1.4  christos 	 NULL,			/* special_function */
    606   1.1.1.4  christos 	 "R_TILEGX_GNU_VTINHERIT", /* name */
    607   1.1.1.7  christos 	 false,			/* partial_inplace */
    608   1.1.1.4  christos 	 0,			/* src_mask */
    609   1.1.1.4  christos 	 0,			/* dst_mask */
    610   1.1.1.7  christos 	 false),		/* pcrel_offset */
    611       1.1  christos 
    612       1.1  christos   /* GNU extension to record C++ vtable member usage */
    613   1.1.1.4  christos   HOWTO (R_TILEGX_GNU_VTENTRY,	   /* type */
    614   1.1.1.4  christos 	 0,			/* rightshift */
    615   1.1.1.7  christos 	 8,			/* size */
    616   1.1.1.4  christos 	 0,			/* bitsize */
    617   1.1.1.7  christos 	 false,			/* pc_relative */
    618   1.1.1.4  christos 	 0,			/* bitpos */
    619   1.1.1.4  christos 	 complain_overflow_dont, /* complain_on_overflow */
    620   1.1.1.4  christos 	 _bfd_elf_rel_vtable_reloc_fn,	/* special_function */
    621   1.1.1.4  christos 	 "R_TILEGX_GNU_VTENTRY",   /* name */
    622   1.1.1.7  christos 	 false,			/* partial_inplace */
    623   1.1.1.4  christos 	 0,			/* src_mask */
    624   1.1.1.4  christos 	 0,			/* dst_mask */
    625   1.1.1.7  christos 	 false),		/* pcrel_offset */
    626       1.1  christos 
    627       1.1  christos };
    628       1.1  christos 
    629       1.1  christos /* Map BFD reloc types to TILEGX ELF reloc types.  */
    631       1.1  christos 
    632       1.1  christos typedef struct tilegx_reloc_map
    633       1.1  christos {
    634   1.1.1.4  christos   bfd_reloc_code_real_type  bfd_reloc_val;
    635   1.1.1.4  christos   unsigned int		    tilegx_reloc_val;
    636       1.1  christos   reloc_howto_type *	    table;
    637       1.1  christos } reloc_map;
    638       1.1  christos 
    639       1.1  christos static const reloc_map tilegx_reloc_map [] =
    640       1.1  christos {
    641       1.1  christos #define TH_REMAP(bfd, tilegx) \
    642       1.1  christos   { bfd, tilegx, tilegx_elf_howto_table },
    643       1.1  christos 
    644   1.1.1.4  christos   /* Standard relocations. */
    645   1.1.1.4  christos   TH_REMAP (BFD_RELOC_NONE,		       R_TILEGX_NONE)
    646   1.1.1.4  christos   TH_REMAP (BFD_RELOC_64,		       R_TILEGX_64)
    647   1.1.1.4  christos   TH_REMAP (BFD_RELOC_32,		       R_TILEGX_32)
    648   1.1.1.4  christos   TH_REMAP (BFD_RELOC_16,		       R_TILEGX_16)
    649   1.1.1.4  christos   TH_REMAP (BFD_RELOC_8,		       R_TILEGX_8)
    650   1.1.1.4  christos   TH_REMAP (BFD_RELOC_64_PCREL,		       R_TILEGX_64_PCREL)
    651   1.1.1.4  christos   TH_REMAP (BFD_RELOC_32_PCREL,		       R_TILEGX_32_PCREL)
    652   1.1.1.4  christos   TH_REMAP (BFD_RELOC_16_PCREL,		       R_TILEGX_16_PCREL)
    653  1.1.1.10  christos   TH_REMAP (BFD_RELOC_8_PCREL,		       R_TILEGX_8_PCREL)
    654  1.1.1.10  christos   TH_REMAP (BFD_RELOC_COPY,		       R_TILEGX_COPY)
    655  1.1.1.10  christos   TH_REMAP (BFD_RELOC_GLOB_DAT,		       R_TILEGX_GLOB_DAT)
    656  1.1.1.10  christos   TH_REMAP (BFD_RELOC_JMP_SLOT,		       R_TILEGX_JMP_SLOT)
    657       1.1  christos   TH_REMAP (BFD_RELOC_RELATIVE,		       R_TILEGX_RELATIVE)
    658       1.1  christos 
    659       1.1  christos #define SIMPLE_REMAP(t) TH_REMAP (BFD_RELOC_##t, R_##t)
    660       1.1  christos 
    661       1.1  christos   /* Custom relocations. */
    662       1.1  christos   SIMPLE_REMAP (TILEGX_HW0)
    663       1.1  christos   SIMPLE_REMAP (TILEGX_HW1)
    664       1.1  christos   SIMPLE_REMAP (TILEGX_HW2)
    665       1.1  christos   SIMPLE_REMAP (TILEGX_HW3)
    666       1.1  christos   SIMPLE_REMAP (TILEGX_HW0_LAST)
    667       1.1  christos   SIMPLE_REMAP (TILEGX_HW1_LAST)
    668       1.1  christos   SIMPLE_REMAP (TILEGX_HW2_LAST)
    669       1.1  christos   SIMPLE_REMAP (TILEGX_BROFF_X1)
    670       1.1  christos   SIMPLE_REMAP (TILEGX_JUMPOFF_X1)
    671       1.1  christos   SIMPLE_REMAP (TILEGX_JUMPOFF_X1_PLT)
    672       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_X0)
    673       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_Y0)
    674       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_X1)
    675       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_Y1)
    676       1.1  christos   SIMPLE_REMAP (TILEGX_DEST_IMM8_X1)
    677       1.1  christos   SIMPLE_REMAP (TILEGX_MT_IMM14_X1)
    678       1.1  christos   SIMPLE_REMAP (TILEGX_MF_IMM14_X1)
    679       1.1  christos   SIMPLE_REMAP (TILEGX_MMSTART_X0)
    680       1.1  christos   SIMPLE_REMAP (TILEGX_MMEND_X0)
    681       1.1  christos   SIMPLE_REMAP (TILEGX_SHAMT_X0)
    682       1.1  christos   SIMPLE_REMAP (TILEGX_SHAMT_X1)
    683       1.1  christos   SIMPLE_REMAP (TILEGX_SHAMT_Y0)
    684       1.1  christos   SIMPLE_REMAP (TILEGX_SHAMT_Y1)
    685       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0)
    686       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0)
    687       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW1)
    688       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW1)
    689       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW2)
    690       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW2)
    691       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW3)
    692       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW3)
    693       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST)
    694       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST)
    695       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST)
    696       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST)
    697       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_LAST)
    698       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_LAST)
    699       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_PCREL)
    700       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_PCREL)
    701       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_PCREL)
    702       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_PCREL)
    703       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_PCREL)
    704       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_PCREL)
    705       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW3_PCREL)
    706       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW3_PCREL)
    707       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_PCREL)
    708       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_PCREL)
    709       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_PCREL)
    710       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_PCREL)
    711       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_LAST_PCREL)
    712       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_LAST_PCREL)
    713       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_GOT)
    714   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_GOT)
    715   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_PLT_PCREL)
    716   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_PLT_PCREL)
    717   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_PLT_PCREL)
    718   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_PLT_PCREL)
    719   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_PLT_PCREL)
    720       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_PLT_PCREL)
    721       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_GOT)
    722       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_GOT)
    723       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_GOT)
    724   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_GOT)
    725   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW3_PLT_PCREL)
    726       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW3_PLT_PCREL)
    727       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_TLS_GD)
    728       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_TLS_GD)
    729       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_TLS_LE)
    730       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_TLS_LE)
    731       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_TLS_LE)
    732       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_TLS_LE)
    733       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_TLS_LE)
    734       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_TLS_LE)
    735       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_TLS_GD)
    736       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_TLS_GD)
    737       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_TLS_GD)
    738       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_TLS_GD)
    739       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_TLS_IE)
    740   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_TLS_IE)
    741   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL)
    742   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL)
    743   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL)
    744   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL)
    745   1.1.1.2  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL)
    746       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL)
    747       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_TLS_IE)
    748       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_TLS_IE)
    749       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_TLS_IE)
    750       1.1  christos   SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_TLS_IE)
    751       1.1  christos 
    752       1.1  christos   SIMPLE_REMAP (TILEGX_TLS_DTPMOD64)
    753       1.1  christos   SIMPLE_REMAP (TILEGX_TLS_DTPOFF64)
    754       1.1  christos   SIMPLE_REMAP (TILEGX_TLS_TPOFF64)
    755       1.1  christos 
    756       1.1  christos   SIMPLE_REMAP (TILEGX_TLS_DTPMOD32)
    757       1.1  christos   SIMPLE_REMAP (TILEGX_TLS_DTPOFF32)
    758       1.1  christos   SIMPLE_REMAP (TILEGX_TLS_TPOFF32)
    759       1.1  christos 
    760       1.1  christos   SIMPLE_REMAP (TILEGX_TLS_GD_CALL)
    761       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_X0_TLS_GD_ADD)
    762       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_X1_TLS_GD_ADD)
    763       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_Y0_TLS_GD_ADD)
    764       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_Y1_TLS_GD_ADD)
    765       1.1  christos   SIMPLE_REMAP (TILEGX_TLS_IE_LOAD)
    766       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_X0_TLS_ADD)
    767       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_X1_TLS_ADD)
    768       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_Y0_TLS_ADD)
    769       1.1  christos   SIMPLE_REMAP (TILEGX_IMM8_Y1_TLS_ADD)
    770       1.1  christos 
    771       1.1  christos #undef SIMPLE_REMAP
    772       1.1  christos #undef TH_REMAP
    773   1.1.1.4  christos 
    774   1.1.1.4  christos   { BFD_RELOC_VTABLE_INHERIT,	    R_TILEGX_GNU_VTINHERIT, tilegx_elf_howto_table2 },
    775       1.1  christos   { BFD_RELOC_VTABLE_ENTRY,	    R_TILEGX_GNU_VTENTRY,   tilegx_elf_howto_table2 },
    776       1.1  christos };
    777       1.1  christos 
    778       1.1  christos 
    779       1.1  christos 
    780       1.1  christos /* TILEGX ELF linker hash entry.  */
    781       1.1  christos 
    782       1.1  christos struct tilegx_elf_link_hash_entry
    783       1.1  christos {
    784       1.1  christos   struct elf_link_hash_entry elf;
    785       1.1  christos 
    786       1.1  christos #define GOT_UNKNOWN     0
    787       1.1  christos #define GOT_NORMAL      1
    788       1.1  christos #define GOT_TLS_GD      2
    789       1.1  christos #define GOT_TLS_IE      4
    790       1.1  christos   unsigned char tls_type;
    791       1.1  christos };
    792       1.1  christos 
    793       1.1  christos #define tilegx_elf_hash_entry(ent) \
    794       1.1  christos   ((struct tilegx_elf_link_hash_entry *)(ent))
    795       1.1  christos 
    796       1.1  christos struct _bfd_tilegx_elf_obj_tdata
    797       1.1  christos {
    798       1.1  christos   struct elf_obj_tdata root;
    799       1.1  christos 
    800       1.1  christos   /* tls_type for each local got entry.  */
    801       1.1  christos   char *local_got_tls_type;
    802       1.1  christos };
    803       1.1  christos 
    804       1.1  christos #define _bfd_tilegx_elf_tdata(abfd) \
    805       1.1  christos   ((struct _bfd_tilegx_elf_obj_tdata *) (abfd)->tdata.any)
    806       1.1  christos 
    807       1.1  christos #define _bfd_tilegx_elf_local_got_tls_type(abfd) \
    808       1.1  christos   (_bfd_tilegx_elf_tdata (abfd)->local_got_tls_type)
    809       1.1  christos 
    810       1.1  christos #define is_tilegx_elf(bfd)				\
    811       1.1  christos   (bfd_get_flavour (bfd) == bfd_target_elf_flavour	\
    812       1.1  christos    && elf_tdata (bfd) != NULL				\
    813       1.1  christos    && elf_object_id (bfd) == TILEGX_ELF_DATA)
    814       1.1  christos 
    815       1.1  christos #include "elf/common.h"
    816       1.1  christos #include "elf/internal.h"
    817       1.1  christos 
    818       1.1  christos struct tilegx_elf_link_hash_table
    819       1.1  christos {
    820       1.1  christos   struct elf_link_hash_table elf;
    821       1.1  christos 
    822       1.1  christos   int bytes_per_word;
    823       1.1  christos   int word_align_power;
    824       1.1  christos   int bytes_per_rela;
    825       1.1  christos   int dtpmod_reloc;
    826       1.1  christos   int dtpoff_reloc;
    827       1.1  christos   int tpoff_reloc;
    828       1.1  christos   bfd_vma (*r_info) (Elf_Internal_Rela *, bfd_vma, bfd_vma);
    829       1.1  christos   bfd_vma (*r_symndx) (bfd_vma);
    830       1.1  christos   void (*put_word) (bfd *, bfd_vma, void *);
    831       1.1  christos   const char *dynamic_interpreter;
    832       1.1  christos 
    833       1.1  christos   /* Whether LE transition has been disabled for some of the
    834   1.1.1.7  christos      sections.  */
    835       1.1  christos   bool disable_le_transition;
    836       1.1  christos };
    837       1.1  christos 
    838       1.1  christos 
    839       1.1  christos /* Get the Tile ELF linker hash table from a link_info structure.  */
    840   1.1.1.7  christos #define tilegx_elf_hash_table(p) \
    841   1.1.1.7  christos   ((is_elf_hash_table ((p)->hash)					\
    842   1.1.1.7  christos     && elf_hash_table_id (elf_hash_table (p)) == TILEGX_ELF_DATA)	\
    843       1.1  christos    ? (struct tilegx_elf_link_hash_table *) (p)->hash : NULL)
    844       1.1  christos 
    845       1.1  christos #ifdef BFD64
    846       1.1  christos static bfd_vma
    847       1.1  christos tilegx_elf_r_info_64 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
    848       1.1  christos 		      bfd_vma rel_index,
    849       1.1  christos 		      bfd_vma type)
    850       1.1  christos {
    851       1.1  christos   return ELF64_R_INFO (rel_index, type);
    852       1.1  christos }
    853       1.1  christos 
    854       1.1  christos static bfd_vma
    855       1.1  christos tilegx_elf_r_symndx_64 (bfd_vma r_info)
    856       1.1  christos {
    857       1.1  christos   return ELF64_R_SYM (r_info);
    858       1.1  christos }
    859       1.1  christos 
    860       1.1  christos static void
    861       1.1  christos tilegx_put_word_64 (bfd *abfd, bfd_vma val, void *ptr)
    862       1.1  christos {
    863       1.1  christos   bfd_put_64 (abfd, val, ptr);
    864       1.1  christos }
    865       1.1  christos #endif /* BFD64 */
    866       1.1  christos 
    867       1.1  christos static bfd_vma
    868       1.1  christos tilegx_elf_r_info_32 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
    869       1.1  christos 		      bfd_vma rel_index,
    870       1.1  christos 		      bfd_vma type)
    871       1.1  christos {
    872       1.1  christos   return ELF32_R_INFO (rel_index, type);
    873       1.1  christos }
    874       1.1  christos 
    875       1.1  christos static bfd_vma
    876       1.1  christos tilegx_elf_r_symndx_32 (bfd_vma r_info)
    877       1.1  christos {
    878       1.1  christos   return ELF32_R_SYM (r_info);
    879       1.1  christos }
    880       1.1  christos 
    881       1.1  christos static void
    882       1.1  christos tilegx_put_word_32 (bfd *abfd, bfd_vma val, void *ptr)
    883       1.1  christos {
    884       1.1  christos   bfd_put_32 (abfd, val, ptr);
    885       1.1  christos }
    886       1.1  christos 
    887   1.1.1.5  christos reloc_howto_type *
    888       1.1  christos tilegx_reloc_type_lookup (bfd * abfd,
    889       1.1  christos 			  bfd_reloc_code_real_type code)
    890       1.1  christos {
    891       1.1  christos   unsigned int i;
    892   1.1.1.2  christos 
    893       1.1  christos   for (i = ARRAY_SIZE (tilegx_reloc_map); i--;)
    894       1.1  christos     {
    895       1.1  christos       const reloc_map * entry;
    896       1.1  christos 
    897       1.1  christos       entry = tilegx_reloc_map + i;
    898       1.1  christos 
    899       1.1  christos       if (entry->bfd_reloc_val == code)
    900       1.1  christos 	return entry->table + (entry->tilegx_reloc_val
    901       1.1  christos 			       - entry->table[0].type);
    902       1.1  christos     }
    903   1.1.1.5  christos 
    904   1.1.1.5  christos   /* xgettext:c-format */
    905   1.1.1.5  christos   _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
    906   1.1.1.5  christos 		      abfd, (int) code);
    907       1.1  christos   bfd_set_error (bfd_error_bad_value);
    908       1.1  christos   return NULL;
    909       1.1  christos }
    910       1.1  christos 
    911       1.1  christos reloc_howto_type *
    912       1.1  christos tilegx_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    913       1.1  christos 			  const char *r_name)
    914       1.1  christos {
    915       1.1  christos   unsigned int i;
    916       1.1  christos 
    917       1.1  christos   for (i = 0;
    918   1.1.1.4  christos        i < (sizeof (tilegx_elf_howto_table)
    919       1.1  christos 	    / sizeof (tilegx_elf_howto_table[0]));
    920       1.1  christos        i++)
    921   1.1.1.4  christos     if (tilegx_elf_howto_table[i].name != NULL
    922       1.1  christos 	&& strcasecmp (tilegx_elf_howto_table[i].name, r_name) == 0)
    923       1.1  christos       return &tilegx_elf_howto_table[i];
    924       1.1  christos 
    925       1.1  christos   return NULL;
    926       1.1  christos }
    927   1.1.1.7  christos 
    928       1.1  christos bool
    929       1.1  christos tilegx_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
    930       1.1  christos 			   arelent *cache_ptr,
    931       1.1  christos 			   Elf_Internal_Rela *dst)
    932       1.1  christos {
    933       1.1  christos   unsigned int r_type = TILEGX_ELF_R_TYPE (dst->r_info);
    934       1.1  christos 
    935       1.1  christos   if (r_type <= (unsigned int) R_TILEGX_IMM8_Y1_TLS_ADD)
    936       1.1  christos     cache_ptr->howto = &tilegx_elf_howto_table [r_type];
    937   1.1.1.5  christos   else if (r_type - R_TILEGX_GNU_VTINHERIT
    938   1.1.1.5  christos 	   <= ((unsigned int) R_TILEGX_GNU_VTENTRY
    939       1.1  christos 	       - (unsigned int) R_TILEGX_GNU_VTINHERIT))
    940       1.1  christos     cache_ptr->howto
    941       1.1  christos       = &tilegx_elf_howto_table2 [r_type - R_TILEGX_GNU_VTINHERIT];
    942   1.1.1.5  christos   else
    943   1.1.1.5  christos     {
    944   1.1.1.5  christos       /* xgettext:c-format */
    945   1.1.1.5  christos       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
    946   1.1.1.5  christos 			  abfd, r_type);
    947   1.1.1.7  christos       bfd_set_error (bfd_error_bad_value);
    948   1.1.1.5  christos       return false;
    949   1.1.1.7  christos     }
    950       1.1  christos   return true;
    951       1.1  christos }
    952       1.1  christos 
    953       1.1  christos typedef tilegx_bundle_bits (*tilegx_create_func)(int);
    954       1.1  christos 
    955       1.1  christos static const tilegx_create_func reloc_to_create_func[] =
    956       1.1  christos {
    957       1.1  christos   /* The first twenty relocation types don't correspond to operands */
    958       1.1  christos   NULL,
    959       1.1  christos   NULL,
    960       1.1  christos   NULL,
    961       1.1  christos   NULL,
    962       1.1  christos   NULL,
    963       1.1  christos   NULL,
    964       1.1  christos   NULL,
    965       1.1  christos   NULL,
    966       1.1  christos   NULL,
    967       1.1  christos   NULL,
    968       1.1  christos   NULL,
    969       1.1  christos   NULL,
    970       1.1  christos   NULL,
    971       1.1  christos   NULL,
    972       1.1  christos   NULL,
    973       1.1  christos   NULL,
    974       1.1  christos   NULL,
    975       1.1  christos   NULL,
    976       1.1  christos   NULL,
    977       1.1  christos   NULL,
    978       1.1  christos 
    979       1.1  christos   /* The remaining relocations are used for immediate operands */
    980       1.1  christos   create_BrOff_X1,
    981       1.1  christos   create_JumpOff_X1,
    982       1.1  christos   create_JumpOff_X1,
    983       1.1  christos   create_Imm8_X0,
    984       1.1  christos   create_Imm8_Y0,
    985       1.1  christos   create_Imm8_X1,
    986       1.1  christos   create_Imm8_Y1,
    987       1.1  christos   create_Dest_Imm8_X1,
    988       1.1  christos   create_MT_Imm14_X1,
    989       1.1  christos   create_MF_Imm14_X1,
    990       1.1  christos   create_BFStart_X0,
    991       1.1  christos   create_BFEnd_X0,
    992       1.1  christos   create_ShAmt_X0,
    993       1.1  christos   create_ShAmt_X1,
    994       1.1  christos   create_ShAmt_Y0,
    995       1.1  christos   create_ShAmt_Y1,
    996       1.1  christos   create_Imm16_X0,
    997       1.1  christos   create_Imm16_X1,
    998       1.1  christos   create_Imm16_X0,
    999       1.1  christos   create_Imm16_X1,
   1000       1.1  christos   create_Imm16_X0,
   1001       1.1  christos   create_Imm16_X1,
   1002       1.1  christos   create_Imm16_X0,
   1003       1.1  christos   create_Imm16_X1,
   1004       1.1  christos   create_Imm16_X0,
   1005       1.1  christos   create_Imm16_X1,
   1006       1.1  christos   create_Imm16_X0,
   1007       1.1  christos   create_Imm16_X1,
   1008       1.1  christos   create_Imm16_X0,
   1009       1.1  christos   create_Imm16_X1,
   1010       1.1  christos   create_Imm16_X0,
   1011       1.1  christos   create_Imm16_X1,
   1012       1.1  christos   create_Imm16_X0,
   1013       1.1  christos   create_Imm16_X1,
   1014       1.1  christos   create_Imm16_X0,
   1015       1.1  christos   create_Imm16_X1,
   1016       1.1  christos   create_Imm16_X0,
   1017       1.1  christos   create_Imm16_X1,
   1018       1.1  christos   create_Imm16_X0,
   1019       1.1  christos   create_Imm16_X1,
   1020       1.1  christos   create_Imm16_X0,
   1021       1.1  christos   create_Imm16_X1,
   1022       1.1  christos   create_Imm16_X0,
   1023       1.1  christos   create_Imm16_X1,
   1024       1.1  christos   create_Imm16_X0,
   1025       1.1  christos   create_Imm16_X1,
   1026       1.1  christos   create_Imm16_X0,
   1027       1.1  christos   create_Imm16_X1,
   1028       1.1  christos   create_Imm16_X0,
   1029       1.1  christos   create_Imm16_X1,
   1030       1.1  christos   create_Imm16_X0,
   1031       1.1  christos   create_Imm16_X1,
   1032       1.1  christos   create_Imm16_X0,
   1033       1.1  christos   create_Imm16_X1,
   1034       1.1  christos   create_Imm16_X0,
   1035       1.1  christos   create_Imm16_X1,
   1036       1.1  christos   create_Imm16_X0,
   1037       1.1  christos   create_Imm16_X1,
   1038       1.1  christos   create_Imm16_X0,
   1039       1.1  christos   create_Imm16_X1,
   1040       1.1  christos   create_Imm16_X0,
   1041       1.1  christos   create_Imm16_X1,
   1042       1.1  christos   create_Imm16_X0,
   1043   1.1.1.2  christos   create_Imm16_X1,
   1044   1.1.1.2  christos   create_Imm16_X0,
   1045   1.1.1.2  christos   create_Imm16_X1,
   1046   1.1.1.2  christos   create_Imm16_X0,
   1047   1.1.1.2  christos   create_Imm16_X1,
   1048   1.1.1.2  christos   create_Imm16_X0,
   1049       1.1  christos   create_Imm16_X1,
   1050       1.1  christos   NULL,
   1051       1.1  christos   NULL,
   1052       1.1  christos   create_Imm16_X0,
   1053       1.1  christos   create_Imm16_X1,
   1054       1.1  christos   create_Imm16_X0,
   1055   1.1.1.2  christos   create_Imm16_X1,
   1056   1.1.1.2  christos   create_Imm16_X0,
   1057   1.1.1.2  christos   create_Imm16_X1,
   1058   1.1.1.2  christos   create_Imm16_X0,
   1059   1.1.1.2  christos   create_Imm16_X1,
   1060   1.1.1.2  christos   create_Imm16_X0,
   1061   1.1.1.2  christos   create_Imm16_X1,
   1062   1.1.1.2  christos   create_Imm16_X0,
   1063       1.1  christos   create_Imm16_X1,
   1064       1.1  christos };
   1065       1.1  christos 
   1066       1.1  christos static void
   1067       1.1  christos tilegx_elf_append_rela (bfd *abfd, asection *s, Elf_Internal_Rela *rel)
   1068  1.1.1.10  christos {
   1069       1.1  christos   elf_backend_data *bed;
   1070       1.1  christos   bfd_byte *loc;
   1071       1.1  christos 
   1072       1.1  christos   bed = get_elf_backend_data (abfd);
   1073       1.1  christos   loc = s->contents + (s->reloc_count++ * bed->s->sizeof_rela);
   1074       1.1  christos   bed->s->swap_reloca_out (abfd, rel, loc);
   1075       1.1  christos }
   1076       1.1  christos 
   1077       1.1  christos /* PLT/GOT stuff */
   1078       1.1  christos 
   1079       1.1  christos /* The procedure linkage table starts with the following header:
   1080   1.1.1.4  christos 
   1081   1.1.1.4  christos      ld_add	  r28, r27, 8
   1082       1.1  christos      ld		  r27, r27
   1083   1.1.1.4  christos    {
   1084   1.1.1.4  christos      jr		  r27
   1085       1.1  christos      info	  10		## SP not offset, return PC in LR
   1086       1.1  christos    }
   1087       1.1  christos 
   1088       1.1  christos    Subsequent entries are the following, jumping to the header at the end:
   1089       1.1  christos 
   1090   1.1.1.4  christos    {
   1091   1.1.1.4  christos      moveli	  r28, <_GLOBAL_OFFSET_TABLE_ - 1f + MY_GOT_OFFSET>
   1092       1.1  christos      lnk	  r26
   1093       1.1  christos    }
   1094       1.1  christos 1:
   1095   1.1.1.4  christos    {
   1096   1.1.1.4  christos      moveli	  r27, <_GLOBAL_OFFSET_TABLE_ - 1b>
   1097       1.1  christos      shl16insli	  r28, r28, <_GLOBAL_OFFSET_TABLE_ - 1b + MY_GOT_OFFSET>
   1098       1.1  christos    }
   1099   1.1.1.4  christos    {
   1100   1.1.1.4  christos      add	  r28, r26, r28
   1101       1.1  christos      shl16insli	  r27, r27, <_GLOBAL_OFFSET_TABLE_ - 1b>
   1102       1.1  christos    }
   1103   1.1.1.4  christos    {
   1104   1.1.1.4  christos      add	  r27, r26, r27
   1105   1.1.1.4  christos      ld		  r28, r28
   1106       1.1  christos      info	  10	   ## SP not offset, return PC in LR
   1107       1.1  christos    }
   1108   1.1.1.4  christos    {
   1109   1.1.1.4  christos      shl16insli	  r29, zero, MY_PLT_INDEX
   1110       1.1  christos      jr		  r28
   1111       1.1  christos    }
   1112       1.1  christos 
   1113       1.1  christos    This code sequence lets the code at at the start of the PLT determine
   1114       1.1  christos    which PLT entry was executed by examining 'r29'.
   1115       1.1  christos 
   1116       1.1  christos    Note that MY_PLT_INDEX skips over the header entries, so the first
   1117       1.1  christos    actual jump table entry has index zero.
   1118       1.1  christos 
   1119       1.1  christos    If the offset fits in 16 bits,
   1120   1.1.1.4  christos 
   1121       1.1  christos      lnk	  r26
   1122       1.1  christos 1:
   1123   1.1.1.4  christos    {
   1124   1.1.1.4  christos      addli	  r28, r26, <_GLOBAL_OFFSET_TABLE_ - 1b + MY_GOT_OFFSET>
   1125       1.1  christos      moveli	  r27, <_GLOBAL_OFFSET_TABLE_ - 1b>
   1126       1.1  christos    }
   1127   1.1.1.4  christos    {
   1128   1.1.1.4  christos      shl16insli	  r29, zero, MY_PLT_INDEX
   1129       1.1  christos      ld		  r28, r28
   1130       1.1  christos    }
   1131   1.1.1.4  christos    {
   1132   1.1.1.4  christos      add	  r27, r26, r27
   1133       1.1  christos      jr		  r28
   1134   1.1.1.4  christos    }
   1135       1.1  christos      info	  10	   ## SP not offset, return PC in LR
   1136       1.1  christos 
   1137       1.1  christos    For the purpose of backtracing, the procedure linkage table ends with the
   1138       1.1  christos    following tail entry:
   1139   1.1.1.4  christos 
   1140       1.1  christos      info	  10	   ## SP not offset, return PC in LR
   1141       1.1  christos 
   1142       1.1  christos    The 32-bit versions are similar, with ld4s replacing ld, and offsets into
   1143       1.1  christos    the GOT being multiples of 4 instead of 8.
   1144       1.1  christos 
   1145       1.1  christos */
   1146       1.1  christos 
   1147       1.1  christos #define PLT_HEADER_SIZE_IN_BUNDLES 3
   1148       1.1  christos #define PLT_ENTRY_SIZE_IN_BUNDLES 5
   1149       1.1  christos #define PLT_TAIL_SIZE_IN_BUNDLES 1
   1150       1.1  christos 
   1151       1.1  christos #define PLT_HEADER_SIZE \
   1152       1.1  christos   (PLT_HEADER_SIZE_IN_BUNDLES * TILEGX_BUNDLE_SIZE_IN_BYTES)
   1153       1.1  christos #define PLT_ENTRY_SIZE \
   1154       1.1  christos   (PLT_ENTRY_SIZE_IN_BUNDLES * TILEGX_BUNDLE_SIZE_IN_BYTES)
   1155       1.1  christos #define PLT_TAIL_SIZE \
   1156       1.1  christos   (PLT_TAIL_SIZE_IN_BUNDLES * TILEGX_BUNDLE_SIZE_IN_BYTES)
   1157       1.1  christos 
   1158       1.1  christos #define GOT_ENTRY_SIZE(htab) TILEGX_ELF_WORD_BYTES (htab)
   1159       1.1  christos 
   1160       1.1  christos #define GOTPLT_HEADER_SIZE(htab) (2 * GOT_ENTRY_SIZE (htab))
   1161       1.1  christos 
   1162       1.1  christos static const bfd_byte
   1163       1.1  christos tilegx64_plt0_entry[PLT_HEADER_SIZE] =
   1164       1.1  christos {
   1165       1.1  christos   0x00, 0x30, 0x48, 0x51,
   1166       1.1  christos   0x6e, 0x43, 0xa0, 0x18, /* { ld_add r28, r27, 8 } */
   1167       1.1  christos   0x00, 0x30, 0xbc, 0x35,
   1168       1.1  christos   0x00, 0x40, 0xde, 0x9e, /* { ld r27, r27 } */
   1169       1.1  christos   0xff, 0xaf, 0x30, 0x40,
   1170       1.1  christos   0x60, 0x73, 0x6a, 0x28, /* { info 10 ; jr r27 } */
   1171       1.1  christos };
   1172       1.1  christos 
   1173       1.1  christos static const bfd_byte
   1174       1.1  christos tilegx64_long_plt_entry[PLT_ENTRY_SIZE] =
   1175       1.1  christos {
   1176       1.1  christos   0xdc, 0x0f, 0x00, 0x10,
   1177       1.1  christos   0x0d, 0xf0, 0x6a, 0x28, /* { moveli r28, 0 ; lnk r26 } */
   1178       1.1  christos   0xdb, 0x0f, 0x00, 0x10,
   1179       1.1  christos   0x8e, 0x03, 0x00, 0x38, /* { moveli r27, 0 ; shl16insli r28, r28, 0 } */
   1180       1.1  christos   0x9c, 0xc6, 0x0d, 0xd0,
   1181       1.1  christos   0x6d, 0x03, 0x00, 0x38, /* { add r28, r26, r28 ; shl16insli r27, r27, 0 } */
   1182       1.1  christos   0x9b, 0xb6, 0xc5, 0xad,
   1183       1.1  christos   0xff, 0x57, 0xe0, 0x8e, /* { add r27, r26, r27 ; info 10 ; ld r28, r28 } */
   1184       1.1  christos   0xdd, 0x0f, 0x00, 0x70,
   1185       1.1  christos   0x80, 0x73, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; jr r28 } */
   1186       1.1  christos };
   1187       1.1  christos 
   1188       1.1  christos static const bfd_byte
   1189       1.1  christos tilegx64_short_plt_entry[PLT_ENTRY_SIZE] =
   1190       1.1  christos {
   1191       1.1  christos   0x00, 0x30, 0x48, 0x51,
   1192       1.1  christos   0x0d, 0xf0, 0x6a, 0x28, /* { lnk r26 } */
   1193       1.1  christos   0x9c, 0x06, 0x00, 0x90,
   1194       1.1  christos   0xed, 0x07, 0x00, 0x00, /* { addli r28, r26, 0 ; moveli r27, 0 } */
   1195       1.1  christos   0xdd, 0x0f, 0x00, 0x70,
   1196       1.1  christos   0x8e, 0xeb, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; ld r28, r28 } */
   1197       1.1  christos   0x9b, 0xb6, 0x0d, 0x50,
   1198       1.1  christos   0x80, 0x73, 0x6a, 0x28, /* { add r27, r26, r27 ; jr r28 } */
   1199       1.1  christos   0x00, 0x30, 0x48, 0xd1,
   1200       1.1  christos   0xff, 0x57, 0x18, 0x18, /* { info 10 } */
   1201       1.1  christos };
   1202       1.1  christos 
   1203   1.1.1.2  christos /* Reuse an existing info 10 bundle.  */
   1204       1.1  christos static const bfd_byte *const tilegx64_plt_tail_entry =
   1205       1.1  christos   &tilegx64_short_plt_entry[4 * TILEGX_BUNDLE_SIZE_IN_BYTES];
   1206       1.1  christos 
   1207       1.1  christos static const bfd_byte
   1208       1.1  christos tilegx32_plt0_entry[PLT_HEADER_SIZE] =
   1209       1.1  christos {
   1210       1.1  christos   0x00, 0x30, 0x48, 0x51,
   1211       1.1  christos   0x6e, 0x23, 0x58, 0x18, /* { ld4s_add r28, r27, 4 } */
   1212       1.1  christos   0x00, 0x30, 0xbc, 0x35,
   1213       1.1  christos   0x00, 0x40, 0xde, 0x9c, /* { ld4s r27, r27 } */
   1214       1.1  christos   0xff, 0xaf, 0x30, 0x40,
   1215       1.1  christos   0x60, 0x73, 0x6a, 0x28, /* { info 10 ; jr r27 } */
   1216       1.1  christos };
   1217       1.1  christos 
   1218       1.1  christos static const bfd_byte
   1219       1.1  christos tilegx32_long_plt_entry[PLT_ENTRY_SIZE] =
   1220       1.1  christos {
   1221       1.1  christos   0xdc, 0x0f, 0x00, 0x10,
   1222       1.1  christos   0x0d, 0xf0, 0x6a, 0x28, /* { moveli r28, 0 ; lnk r26 } */
   1223       1.1  christos   0xdb, 0x0f, 0x00, 0x10,
   1224       1.1  christos   0x8e, 0x03, 0x00, 0x38, /* { moveli r27, 0 ; shl16insli r28, r28, 0 } */
   1225       1.1  christos   0x9c, 0xc6, 0x0d, 0xd0,
   1226       1.1  christos   0x6d, 0x03, 0x00, 0x38, /* { add r28, r26, r28 ; shl16insli r27, r27, 0 } */
   1227       1.1  christos   0x9b, 0xb6, 0xc5, 0xad,
   1228       1.1  christos   0xff, 0x57, 0xe0, 0x8c, /* { add r27, r26, r27 ; info 10 ; ld4s r28, r28 } */
   1229       1.1  christos   0xdd, 0x0f, 0x00, 0x70,
   1230       1.1  christos   0x80, 0x73, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; jr r28 } */
   1231       1.1  christos };
   1232       1.1  christos 
   1233       1.1  christos static const bfd_byte
   1234       1.1  christos tilegx32_short_plt_entry[PLT_ENTRY_SIZE] =
   1235       1.1  christos {
   1236       1.1  christos   0x00, 0x30, 0x48, 0x51,
   1237       1.1  christos   0x0d, 0xf0, 0x6a, 0x28, /* { lnk r26 } */
   1238       1.1  christos   0x9c, 0x06, 0x00, 0x90,
   1239       1.1  christos   0xed, 0x07, 0x00, 0x00, /* { addli r28, r26, 0 ; moveli r27, 0 } */
   1240       1.1  christos   0xdd, 0x0f, 0x00, 0x70,
   1241       1.1  christos   0x8e, 0x9b, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; ld4s r28, r28 } */
   1242       1.1  christos   0x9b, 0xb6, 0x0d, 0x50,
   1243       1.1  christos   0x80, 0x73, 0x6a, 0x28, /* { add r27, r26, r27 ; jr r28 } */
   1244       1.1  christos   0x00, 0x30, 0x48, 0xd1,
   1245       1.1  christos   0xff, 0x57, 0x18, 0x18, /* { info 10 } */
   1246       1.1  christos };
   1247       1.1  christos 
   1248   1.1.1.2  christos /* Reuse an existing info 10 bundle.  */
   1249       1.1  christos static const bfd_byte *const tilegx32_plt_tail_entry =
   1250       1.1  christos   &tilegx64_short_plt_entry[4 * TILEGX_BUNDLE_SIZE_IN_BYTES];
   1251       1.1  christos 
   1252       1.1  christos static int
   1253       1.1  christos tilegx_plt_entry_build (bfd *output_bfd,
   1254       1.1  christos 			struct tilegx_elf_link_hash_table *htab,
   1255       1.1  christos 			asection *splt, asection *sgotplt,
   1256       1.1  christos 			bfd_vma offset, bfd_vma *r_offset)
   1257       1.1  christos {
   1258       1.1  christos   int plt_index = (offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
   1259       1.1  christos   int got_offset = (plt_index * GOT_ENTRY_SIZE (htab)
   1260       1.1  christos 		    + GOTPLT_HEADER_SIZE (htab));
   1261       1.1  christos   tilegx_bundle_bits *pc;
   1262       1.1  christos 
   1263       1.1  christos   /* Compute the distance from the got entry to the lnk.  */
   1264       1.1  christos   bfd_signed_vma dist_got_entry = sgotplt->output_section->vma
   1265       1.1  christos     + sgotplt->output_offset
   1266       1.1  christos     + got_offset
   1267       1.1  christos     - splt->output_section->vma
   1268       1.1  christos     - splt->output_offset
   1269       1.1  christos     - offset
   1270       1.1  christos     - TILEGX_BUNDLE_SIZE_IN_BYTES;
   1271       1.1  christos 
   1272       1.1  christos   /* Compute the distance to GOTPLT[0].  */
   1273       1.1  christos   bfd_signed_vma dist_got0 = dist_got_entry - got_offset;
   1274       1.1  christos 
   1275   1.1.1.7  christos   /* Check whether we can use the short plt entry with 16-bit offset.  */
   1276       1.1  christos   bool short_plt_entry =
   1277       1.1  christos     (dist_got_entry <= 0x7fff && dist_got0 >= -0x8000);
   1278       1.1  christos 
   1279       1.1  christos   const tilegx_bundle_bits *plt_entry = (tilegx_bundle_bits *)
   1280       1.1  christos     (ABI_64_P (output_bfd) ?
   1281       1.1  christos      (short_plt_entry ? tilegx64_short_plt_entry : tilegx64_long_plt_entry) :
   1282       1.1  christos      (short_plt_entry ? tilegx32_short_plt_entry : tilegx32_long_plt_entry));
   1283       1.1  christos 
   1284       1.1  christos   /* Copy the plt entry template.  */
   1285       1.1  christos   memcpy (splt->contents + offset, plt_entry, PLT_ENTRY_SIZE);
   1286       1.1  christos 
   1287       1.1  christos   /* Write the immediate offsets.  */
   1288       1.1  christos   pc = (tilegx_bundle_bits *)(splt->contents + offset);
   1289       1.1  christos 
   1290       1.1  christos   if (short_plt_entry)
   1291       1.1  christos     {
   1292       1.1  christos       /* { lnk r28 }  */
   1293       1.1  christos       pc++;
   1294       1.1  christos 
   1295       1.1  christos       /* { addli r28, r28, &GOTPLT[MY_GOT_INDEX] ; moveli r27, &GOTPLT[0] }  */
   1296       1.1  christos       *pc++ |= create_Imm16_X0 (dist_got_entry)
   1297       1.1  christos 	| create_Imm16_X1 (dist_got0);
   1298       1.1  christos 
   1299       1.1  christos       /* { shl16insli r29, zero, MY_PLT_INDEX ; ld r28, r28 }  */
   1300       1.1  christos       *pc++ |= create_Imm16_X0 (plt_index);
   1301       1.1  christos     }
   1302       1.1  christos   else
   1303       1.1  christos     {
   1304       1.1  christos       /* { moveli r28, &GOTPLT[MY_GOT_INDEX] ; lnk r26 }  */
   1305       1.1  christos       *pc++ |= create_Imm16_X0 (dist_got_entry >> 16);
   1306       1.1  christos 
   1307       1.1  christos       /* { moveli r27, &GOTPLT[0] ;
   1308       1.1  christos 	   shl16insli r28, r28, &GOTPLT[MY_GOT_INDEX] }  */
   1309       1.1  christos       *pc++ |= create_Imm16_X0 (dist_got0 >> 16)
   1310       1.1  christos 	| create_Imm16_X1 (dist_got_entry);
   1311       1.1  christos 
   1312       1.1  christos       /* { add r28, r26, r28 ; shl16insli r27, r27, &GOTPLT[0] }  */
   1313       1.1  christos       *pc++ |= create_Imm16_X1 (dist_got0);
   1314       1.1  christos 
   1315       1.1  christos       /* { add r27, r26, r27 ; info 10 ; ld r28, r28 } */
   1316       1.1  christos       pc++;
   1317       1.1  christos 
   1318       1.1  christos       /* { shl16insli r29, zero, MY_GOT_INDEX ; jr r28 } */
   1319       1.1  christos       *pc++ |= create_Imm16_X0 (plt_index);
   1320       1.1  christos    }
   1321       1.1  christos 
   1322       1.1  christos   /* Set the relocation offset.  */
   1323       1.1  christos   *r_offset = got_offset;
   1324       1.1  christos 
   1325       1.1  christos   return plt_index;
   1326       1.1  christos }
   1327       1.1  christos 
   1328       1.1  christos /* Create an entry in an TILEGX ELF linker hash table.  */
   1329       1.1  christos 
   1330       1.1  christos static struct bfd_hash_entry *
   1331       1.1  christos link_hash_newfunc (struct bfd_hash_entry *entry,
   1332       1.1  christos 		   struct bfd_hash_table *table, const char *string)
   1333       1.1  christos {
   1334       1.1  christos   /* Allocate the structure if it has not already been allocated by a
   1335       1.1  christos      subclass.  */
   1336       1.1  christos   if (entry == NULL)
   1337       1.1  christos     {
   1338   1.1.1.4  christos       entry =
   1339   1.1.1.4  christos 	bfd_hash_allocate (table,
   1340       1.1  christos 			   sizeof (struct tilegx_elf_link_hash_entry));
   1341       1.1  christos       if (entry == NULL)
   1342       1.1  christos 	return entry;
   1343       1.1  christos     }
   1344       1.1  christos 
   1345       1.1  christos   /* Call the allocation method of the superclass.  */
   1346       1.1  christos   entry = _bfd_elf_link_hash_newfunc (entry, table, string);
   1347       1.1  christos   if (entry != NULL)
   1348       1.1  christos     {
   1349       1.1  christos       struct tilegx_elf_link_hash_entry *eh;
   1350       1.1  christos 
   1351       1.1  christos       eh = (struct tilegx_elf_link_hash_entry *) entry;
   1352       1.1  christos       eh->tls_type = GOT_UNKNOWN;
   1353       1.1  christos     }
   1354       1.1  christos 
   1355       1.1  christos   return entry;
   1356       1.1  christos }
   1357       1.1  christos 
   1358       1.1  christos /* Create a TILEGX ELF linker hash table.  */
   1359       1.1  christos 
   1360       1.1  christos struct bfd_link_hash_table *
   1361       1.1  christos tilegx_elf_link_hash_table_create (bfd *abfd)
   1362       1.1  christos {
   1363   1.1.1.7  christos   struct tilegx_elf_link_hash_table *ret;
   1364       1.1  christos   size_t amt = sizeof (struct tilegx_elf_link_hash_table);
   1365       1.1  christos 
   1366       1.1  christos   ret = (struct tilegx_elf_link_hash_table *) bfd_zmalloc (amt);
   1367       1.1  christos   if (ret == NULL)
   1368       1.1  christos     return NULL;
   1369       1.1  christos 
   1370       1.1  christos #ifdef BFD64
   1371       1.1  christos   if (ABI_64_P (abfd))
   1372       1.1  christos     {
   1373       1.1  christos       ret->bytes_per_word = 8;
   1374       1.1  christos       ret->word_align_power = 3;
   1375       1.1  christos       ret->bytes_per_rela = sizeof (Elf64_External_Rela);
   1376       1.1  christos       ret->dtpoff_reloc = R_TILEGX_TLS_DTPOFF64;
   1377       1.1  christos       ret->dtpmod_reloc = R_TILEGX_TLS_DTPMOD64;
   1378       1.1  christos       ret->tpoff_reloc = R_TILEGX_TLS_TPOFF64;
   1379       1.1  christos       ret->r_info = tilegx_elf_r_info_64;
   1380       1.1  christos       ret->r_symndx = tilegx_elf_r_symndx_64;
   1381       1.1  christos       ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
   1382       1.1  christos       ret->put_word = tilegx_put_word_64;
   1383       1.1  christos     }
   1384       1.1  christos   else
   1385       1.1  christos #endif
   1386       1.1  christos     {
   1387       1.1  christos       ret->bytes_per_word = 4;
   1388       1.1  christos       ret->word_align_power = 2;
   1389       1.1  christos       ret->bytes_per_rela = sizeof (Elf32_External_Rela);
   1390       1.1  christos       ret->dtpoff_reloc = R_TILEGX_TLS_DTPOFF32;
   1391       1.1  christos       ret->dtpmod_reloc = R_TILEGX_TLS_DTPMOD32;
   1392       1.1  christos       ret->tpoff_reloc = R_TILEGX_TLS_TPOFF32;
   1393       1.1  christos       ret->r_info = tilegx_elf_r_info_32;
   1394       1.1  christos       ret->r_symndx = tilegx_elf_r_symndx_32;
   1395       1.1  christos       ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER;
   1396       1.1  christos       ret->put_word = tilegx_put_word_32;
   1397       1.1  christos     }
   1398       1.1  christos 
   1399   1.1.1.9  christos   if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
   1400       1.1  christos 				      sizeof (struct tilegx_elf_link_hash_entry)))
   1401       1.1  christos     {
   1402       1.1  christos       free (ret);
   1403       1.1  christos       return NULL;
   1404       1.1  christos     }
   1405       1.1  christos 
   1406       1.1  christos   return &ret->elf.root;
   1407       1.1  christos }
   1408       1.1  christos 
   1409       1.1  christos /* Create the .got section.  */
   1410   1.1.1.7  christos 
   1411       1.1  christos static bool
   1412       1.1  christos tilegx_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
   1413       1.1  christos {
   1414       1.1  christos   flagword flags;
   1415       1.1  christos   asection *s, *s_got;
   1416  1.1.1.10  christos   struct elf_link_hash_entry *h;
   1417       1.1  christos   elf_backend_data *bed = get_elf_backend_data (abfd);
   1418       1.1  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
   1419       1.1  christos 
   1420   1.1.1.4  christos   /* This function may be called more than once.  */
   1421   1.1.1.7  christos   if (htab->sgot != NULL)
   1422       1.1  christos     return true;
   1423       1.1  christos 
   1424       1.1  christos   flags = bed->dynamic_sec_flags;
   1425       1.1  christos 
   1426       1.1  christos   s = bfd_make_section_anyway_with_flags (abfd,
   1427       1.1  christos 					  (bed->rela_plts_and_copies_p
   1428       1.1  christos 					   ? ".rela.got" : ".rel.got"),
   1429       1.1  christos 					  (bed->dynamic_sec_flags
   1430       1.1  christos 					   | SEC_READONLY));
   1431   1.1.1.6  christos   if (s == NULL
   1432   1.1.1.7  christos       || !bfd_set_section_alignment (s, bed->s->log_file_align))
   1433       1.1  christos     return false;
   1434       1.1  christos   htab->srelgot = s;
   1435       1.1  christos 
   1436       1.1  christos   s = s_got = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
   1437   1.1.1.6  christos   if (s == NULL
   1438   1.1.1.7  christos       || !bfd_set_section_alignment (s, bed->s->log_file_align))
   1439       1.1  christos     return false;
   1440       1.1  christos   htab->sgot = s;
   1441       1.1  christos 
   1442       1.1  christos   /* The first bit of the global offset table is the header.  */
   1443       1.1  christos   s->size += bed->got_header_size;
   1444       1.1  christos 
   1445       1.1  christos   if (bed->want_got_plt)
   1446       1.1  christos     {
   1447       1.1  christos       s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
   1448   1.1.1.6  christos       if (s == NULL
   1449   1.1.1.7  christos 	  || !bfd_set_section_alignment (s, bed->s->log_file_align))
   1450       1.1  christos 	return false;
   1451       1.1  christos       htab->sgotplt = s;
   1452       1.1  christos 
   1453       1.1  christos       /* Reserve room for the header.  */
   1454       1.1  christos       s->size += GOTPLT_HEADER_SIZE (tilegx_elf_hash_table (info));
   1455       1.1  christos     }
   1456       1.1  christos 
   1457       1.1  christos   if (bed->want_got_sym)
   1458       1.1  christos     {
   1459       1.1  christos       /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
   1460       1.1  christos 	 section.  We don't do this in the linker script because we don't want
   1461       1.1  christos 	 to define the symbol if we are not creating a global offset
   1462       1.1  christos 	 table.  */
   1463       1.1  christos       h = _bfd_elf_define_linkage_sym (abfd, info, s_got,
   1464       1.1  christos 				       "_GLOBAL_OFFSET_TABLE_");
   1465       1.1  christos       elf_hash_table (info)->hgot = h;
   1466   1.1.1.7  christos       if (h == NULL)
   1467       1.1  christos 	return false;
   1468       1.1  christos     }
   1469   1.1.1.7  christos 
   1470       1.1  christos   return true;
   1471       1.1  christos }
   1472       1.1  christos 
   1473       1.1  christos /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
   1474       1.1  christos    .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
   1475       1.1  christos    hash table.  */
   1476   1.1.1.7  christos 
   1477       1.1  christos bool
   1478       1.1  christos tilegx_elf_create_dynamic_sections (bfd *dynobj,
   1479       1.1  christos 				    struct bfd_link_info *info)
   1480       1.1  christos {
   1481   1.1.1.7  christos   if (!tilegx_elf_create_got_section (dynobj, info))
   1482       1.1  christos     return false;
   1483   1.1.1.4  christos 
   1484       1.1  christos   return _bfd_elf_create_dynamic_sections (dynobj, info);
   1485       1.1  christos }
   1486       1.1  christos 
   1487       1.1  christos /* Copy the extra info we tack onto an elf_link_hash_entry.  */
   1488       1.1  christos 
   1489       1.1  christos void
   1490       1.1  christos tilegx_elf_copy_indirect_symbol (struct bfd_link_info *info,
   1491       1.1  christos 				 struct elf_link_hash_entry *dir,
   1492       1.1  christos 				 struct elf_link_hash_entry *ind)
   1493       1.1  christos {
   1494       1.1  christos   struct tilegx_elf_link_hash_entry *edir, *eind;
   1495       1.1  christos 
   1496       1.1  christos   edir = (struct tilegx_elf_link_hash_entry *) dir;
   1497       1.1  christos   eind = (struct tilegx_elf_link_hash_entry *) ind;
   1498       1.1  christos 
   1499       1.1  christos   if (ind->root.type == bfd_link_hash_indirect
   1500       1.1  christos       && dir->got.refcount <= 0)
   1501       1.1  christos     {
   1502       1.1  christos       edir->tls_type = eind->tls_type;
   1503       1.1  christos       eind->tls_type = GOT_UNKNOWN;
   1504       1.1  christos     }
   1505       1.1  christos   _bfd_elf_link_hash_copy_indirect (info, dir, ind);
   1506       1.1  christos }
   1507       1.1  christos 
   1508       1.1  christos static int
   1509       1.1  christos tilegx_tls_translate_to_le (int r_type)
   1510       1.1  christos {
   1511       1.1  christos   switch (r_type)
   1512       1.1  christos     {
   1513       1.1  christos     case R_TILEGX_IMM16_X0_HW0_TLS_GD:
   1514       1.1  christos     case R_TILEGX_IMM16_X0_HW0_TLS_IE:
   1515       1.1  christos       return R_TILEGX_IMM16_X0_HW0_TLS_LE;
   1516       1.1  christos 
   1517       1.1  christos     case R_TILEGX_IMM16_X1_HW0_TLS_GD:
   1518       1.1  christos     case R_TILEGX_IMM16_X1_HW0_TLS_IE:
   1519       1.1  christos       return R_TILEGX_IMM16_X1_HW0_TLS_LE;
   1520       1.1  christos 
   1521       1.1  christos     case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
   1522       1.1  christos     case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
   1523       1.1  christos       return R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE;
   1524       1.1  christos 
   1525       1.1  christos     case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
   1526       1.1  christos     case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
   1527       1.1  christos       return R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE;
   1528       1.1  christos 
   1529       1.1  christos     case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
   1530       1.1  christos     case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
   1531       1.1  christos       return R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE;
   1532       1.1  christos 
   1533       1.1  christos     case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
   1534       1.1  christos     case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
   1535       1.1  christos       return R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE;
   1536       1.1  christos     }
   1537       1.1  christos   return r_type;
   1538       1.1  christos }
   1539       1.1  christos 
   1540       1.1  christos static int
   1541       1.1  christos tilegx_tls_translate_to_ie (int r_type)
   1542       1.1  christos {
   1543       1.1  christos   switch (r_type)
   1544       1.1  christos     {
   1545       1.1  christos     case R_TILEGX_IMM16_X0_HW0_TLS_GD:
   1546       1.1  christos     case R_TILEGX_IMM16_X0_HW0_TLS_IE:
   1547       1.1  christos       return R_TILEGX_IMM16_X0_HW0_TLS_IE;
   1548       1.1  christos 
   1549       1.1  christos     case R_TILEGX_IMM16_X1_HW0_TLS_GD:
   1550       1.1  christos     case R_TILEGX_IMM16_X1_HW0_TLS_IE:
   1551       1.1  christos       return R_TILEGX_IMM16_X1_HW0_TLS_IE;
   1552       1.1  christos 
   1553       1.1  christos     case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
   1554       1.1  christos     case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
   1555       1.1  christos       return R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE;
   1556       1.1  christos 
   1557       1.1  christos     case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
   1558       1.1  christos     case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
   1559       1.1  christos       return R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE;
   1560       1.1  christos 
   1561       1.1  christos     case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
   1562       1.1  christos     case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
   1563       1.1  christos       return R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE;
   1564       1.1  christos 
   1565       1.1  christos     case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
   1566       1.1  christos     case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
   1567       1.1  christos       return R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE;
   1568       1.1  christos     }
   1569       1.1  christos   return r_type;
   1570       1.1  christos }
   1571       1.1  christos 
   1572       1.1  christos static int
   1573   1.1.1.7  christos tilegx_elf_tls_transition (struct bfd_link_info *info, int r_type,
   1574       1.1  christos 			   int is_local, bool disable_le_transition)
   1575   1.1.1.4  christos {
   1576       1.1  christos   if (!bfd_link_executable (info))
   1577       1.1  christos     return r_type;
   1578       1.1  christos 
   1579       1.1  christos   if (is_local && !disable_le_transition)
   1580       1.1  christos     return tilegx_tls_translate_to_le (r_type);
   1581       1.1  christos   else
   1582       1.1  christos     return tilegx_tls_translate_to_ie (r_type);
   1583       1.1  christos }
   1584       1.1  christos 
   1585       1.1  christos /* Look through the relocs for a section during the first phase, and
   1586       1.1  christos    allocate space in the global offset table or procedure linkage
   1587       1.1  christos    table.  */
   1588   1.1.1.7  christos 
   1589       1.1  christos bool
   1590       1.1  christos tilegx_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
   1591       1.1  christos 			 asection *sec, const Elf_Internal_Rela *relocs)
   1592       1.1  christos {
   1593       1.1  christos   struct tilegx_elf_link_hash_table *htab;
   1594       1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   1595       1.1  christos   struct elf_link_hash_entry **sym_hashes;
   1596       1.1  christos   const Elf_Internal_Rela *rel;
   1597       1.1  christos   const Elf_Internal_Rela *rel_end;
   1598       1.1  christos   asection *sreloc;
   1599   1.1.1.7  christos   int num_relocs;
   1600       1.1  christos   bool has_tls_gd_or_ie = false, has_tls_add = false;
   1601   1.1.1.2  christos 
   1602   1.1.1.7  christos   if (bfd_link_relocatable (info))
   1603       1.1  christos     return true;
   1604       1.1  christos 
   1605       1.1  christos   htab = tilegx_elf_hash_table (info);
   1606       1.1  christos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   1607       1.1  christos   sym_hashes = elf_sym_hashes (abfd);
   1608       1.1  christos 
   1609       1.1  christos   sreloc = NULL;
   1610       1.1  christos 
   1611       1.1  christos   num_relocs = sec->reloc_count;
   1612       1.1  christos 
   1613       1.1  christos   BFD_ASSERT (is_tilegx_elf (abfd) || num_relocs == 0);
   1614       1.1  christos 
   1615       1.1  christos   if (htab->elf.dynobj == NULL)
   1616       1.1  christos     htab->elf.dynobj = abfd;
   1617       1.1  christos 
   1618       1.1  christos   rel_end = relocs + num_relocs;
   1619       1.1  christos 
   1620       1.1  christos   /* Check whether to do optimization to transform TLS GD/IE
   1621       1.1  christos      referehces to TLS LE.  We disable it if we're linking with old
   1622       1.1  christos      TLS code sequences that do not support such optimization.  Old
   1623       1.1  christos      TLS code sequences have tls_gd_call/tls_ie_load relocations but
   1624       1.1  christos      no tls_add relocations.  */
   1625       1.1  christos   for (rel = relocs; rel < rel_end && !has_tls_add; rel++)
   1626       1.1  christos     {
   1627       1.1  christos       int r_type = TILEGX_ELF_R_TYPE (rel->r_info);
   1628       1.1  christos       switch (r_type)
   1629       1.1  christos 	{
   1630       1.1  christos 	case R_TILEGX_TLS_GD_CALL:
   1631   1.1.1.7  christos 	case R_TILEGX_TLS_IE_LOAD:
   1632       1.1  christos 	  has_tls_gd_or_ie = true;
   1633       1.1  christos 	  break;
   1634       1.1  christos 	case R_TILEGX_IMM8_X0_TLS_ADD:
   1635       1.1  christos 	case R_TILEGX_IMM8_Y0_TLS_ADD:
   1636       1.1  christos 	case R_TILEGX_IMM8_X1_TLS_ADD:
   1637   1.1.1.7  christos 	case R_TILEGX_IMM8_Y1_TLS_ADD:
   1638       1.1  christos 	  has_tls_add = true;
   1639       1.1  christos 	  break;
   1640       1.1  christos 	}
   1641       1.1  christos     }
   1642       1.1  christos 
   1643       1.1  christos   sec->sec_flg0 = (has_tls_gd_or_ie && !has_tls_add);
   1644       1.1  christos   htab->disable_le_transition |= sec->sec_flg0;
   1645       1.1  christos 
   1646       1.1  christos   for (rel = relocs; rel < rel_end; rel++)
   1647       1.1  christos     {
   1648   1.1.1.4  christos       unsigned int r_type;
   1649       1.1  christos       unsigned int r_symndx;
   1650       1.1  christos       struct elf_link_hash_entry *h;
   1651       1.1  christos       int tls_type;
   1652       1.1  christos 
   1653       1.1  christos       r_symndx = TILEGX_ELF_R_SYMNDX (htab, rel->r_info);
   1654       1.1  christos       r_type = TILEGX_ELF_R_TYPE (rel->r_info);
   1655       1.1  christos 
   1656       1.1  christos       if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
   1657   1.1.1.4  christos 	{
   1658   1.1.1.5  christos 	  /* xgettext:c-format */
   1659   1.1.1.4  christos 	  _bfd_error_handler (_("%pB: bad symbol index: %d"),
   1660   1.1.1.7  christos 			      abfd, r_symndx);
   1661       1.1  christos 	  return false;
   1662       1.1  christos 	}
   1663       1.1  christos 
   1664       1.1  christos       if (r_symndx < symtab_hdr->sh_info)
   1665       1.1  christos 	h = NULL;
   1666       1.1  christos       else
   1667       1.1  christos 	{
   1668       1.1  christos 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   1669       1.1  christos 	  while (h->root.type == bfd_link_hash_indirect
   1670       1.1  christos 		 || h->root.type == bfd_link_hash_warning)
   1671       1.1  christos 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   1672       1.1  christos 	}
   1673       1.1  christos 
   1674       1.1  christos       r_type = tilegx_elf_tls_transition (info, r_type, h == NULL,
   1675       1.1  christos 					  sec->sec_flg0);
   1676       1.1  christos       switch (r_type)
   1677       1.1  christos 	{
   1678       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_TLS_LE:
   1679       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_TLS_LE:
   1680       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
   1681       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
   1682       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
   1683   1.1.1.4  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
   1684       1.1  christos 	  if (!bfd_link_executable (info))
   1685       1.1  christos 	    goto r_tilegx_plt32;
   1686       1.1  christos 	  break;
   1687       1.1  christos 
   1688       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_TLS_GD:
   1689       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_TLS_GD:
   1690       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
   1691       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
   1692       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
   1693   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
   1694       1.1  christos 	  BFD_ASSERT (bfd_link_pic (info));
   1695   1.1.1.4  christos 	  tls_type = GOT_TLS_GD;
   1696       1.1  christos 	  goto have_got_reference;
   1697       1.1  christos 
   1698       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_TLS_IE:
   1699       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_TLS_IE:
   1700       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
   1701       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
   1702       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
   1703   1.1.1.4  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
   1704   1.1.1.4  christos 	  tls_type = GOT_TLS_IE;
   1705   1.1.1.4  christos 	  if (!bfd_link_executable (info))
   1706   1.1.1.4  christos 	    info->flags |= DF_STATIC_TLS;
   1707       1.1  christos 	  goto have_got_reference;
   1708       1.1  christos 
   1709       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_GOT:
   1710       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_GOT:
   1711       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_GOT:
   1712       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_GOT:
   1713       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_GOT:
   1714   1.1.1.4  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_GOT:
   1715   1.1.1.4  christos 	  tls_type = GOT_NORMAL;
   1716       1.1  christos 	  /* Fall Through */
   1717   1.1.1.4  christos 
   1718       1.1  christos 	have_got_reference:
   1719       1.1  christos 	  /* This symbol requires a global offset table entry.  */
   1720   1.1.1.4  christos 	  {
   1721       1.1  christos 	    int old_tls_type;
   1722       1.1  christos 
   1723       1.1  christos 	    if (h != NULL)
   1724       1.1  christos 	      {
   1725       1.1  christos 		h->got.refcount += 1;
   1726       1.1  christos 		old_tls_type = tilegx_elf_hash_entry(h)->tls_type;
   1727       1.1  christos 	      }
   1728       1.1  christos 	    else
   1729       1.1  christos 	      {
   1730       1.1  christos 		bfd_signed_vma *local_got_refcounts;
   1731       1.1  christos 
   1732       1.1  christos 		/* This is a global offset table entry for a local symbol.  */
   1733       1.1  christos 		local_got_refcounts = elf_local_got_refcounts (abfd);
   1734       1.1  christos 		if (local_got_refcounts == NULL)
   1735       1.1  christos 		  {
   1736       1.1  christos 		    bfd_size_type size;
   1737       1.1  christos 
   1738       1.1  christos 		    size = symtab_hdr->sh_info;
   1739       1.1  christos 		    size *= (sizeof (bfd_signed_vma) + sizeof(char));
   1740       1.1  christos 		    local_got_refcounts = ((bfd_signed_vma *)
   1741       1.1  christos 					   bfd_zalloc (abfd, size));
   1742   1.1.1.7  christos 		    if (local_got_refcounts == NULL)
   1743       1.1  christos 		      return false;
   1744   1.1.1.4  christos 		    elf_local_got_refcounts (abfd) = local_got_refcounts;
   1745   1.1.1.4  christos 		    _bfd_tilegx_elf_local_got_tls_type (abfd)
   1746       1.1  christos 		      = (char *) (local_got_refcounts + symtab_hdr->sh_info);
   1747       1.1  christos 		  }
   1748   1.1.1.4  christos 		local_got_refcounts[r_symndx] += 1;
   1749   1.1.1.4  christos 		old_tls_type = _bfd_tilegx_elf_local_got_tls_type (abfd) [r_symndx];
   1750       1.1  christos 	      }
   1751   1.1.1.4  christos 
   1752   1.1.1.4  christos 	    /* If a TLS symbol is accessed using IE at least once,
   1753   1.1.1.4  christos 	       there is no point to use dynamic model for it.  */
   1754   1.1.1.4  christos 	    if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
   1755   1.1.1.4  christos 		&& (old_tls_type != GOT_TLS_GD
   1756   1.1.1.4  christos 		    || tls_type != GOT_TLS_IE))
   1757   1.1.1.4  christos 	      {
   1758   1.1.1.4  christos 		if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
   1759   1.1.1.4  christos 		  tls_type = old_tls_type;
   1760   1.1.1.4  christos 		else
   1761   1.1.1.4  christos 		  {
   1762   1.1.1.4  christos 		    _bfd_error_handler
   1763   1.1.1.5  christos 		      /* xgettext:c-format */
   1764   1.1.1.4  christos 		      (_("%pB: `%s' accessed both as normal and thread local symbol"),
   1765   1.1.1.7  christos 		       abfd, h ? h->root.root.string : "<local>");
   1766   1.1.1.4  christos 		    return false;
   1767   1.1.1.4  christos 		  }
   1768   1.1.1.4  christos 	      }
   1769   1.1.1.4  christos 
   1770   1.1.1.4  christos 	    if (old_tls_type != tls_type)
   1771   1.1.1.4  christos 	      {
   1772   1.1.1.4  christos 		if (h != NULL)
   1773   1.1.1.4  christos 		  tilegx_elf_hash_entry (h)->tls_type = tls_type;
   1774   1.1.1.4  christos 		else
   1775       1.1  christos 		  _bfd_tilegx_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
   1776       1.1  christos 	      }
   1777       1.1  christos 	  }
   1778       1.1  christos 
   1779       1.1  christos 	  if (htab->elf.sgot == NULL)
   1780       1.1  christos 	    {
   1781   1.1.1.7  christos 	      if (!tilegx_elf_create_got_section (htab->elf.dynobj, info))
   1782       1.1  christos 		return false;
   1783       1.1  christos 	    }
   1784       1.1  christos 	  break;
   1785       1.1  christos 
   1786   1.1.1.4  christos 	case R_TILEGX_TLS_GD_CALL:
   1787       1.1  christos 	  if (!bfd_link_executable (info))
   1788       1.1  christos 	    {
   1789       1.1  christos 	      /* These are basically R_TILEGX_JUMPOFF_X1_PLT relocs
   1790       1.1  christos 		 against __tls_get_addr.  */
   1791       1.1  christos 	      struct bfd_link_hash_entry *bh = NULL;
   1792       1.1  christos 	      if (! _bfd_generic_link_add_one_symbol (info, abfd,
   1793       1.1  christos 						      "__tls_get_addr", 0,
   1794   1.1.1.7  christos 						      bfd_und_section_ptr, 0,
   1795       1.1  christos 						      NULL, false, false,
   1796   1.1.1.7  christos 						      &bh))
   1797       1.1  christos 		return false;
   1798       1.1  christos 	      h = (struct elf_link_hash_entry *) bh;
   1799       1.1  christos 	    }
   1800       1.1  christos 	  else
   1801       1.1  christos 	    break;
   1802       1.1  christos 	  /* Fall through */
   1803   1.1.1.4  christos 
   1804   1.1.1.2  christos 	case R_TILEGX_JUMPOFF_X1_PLT:
   1805   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
   1806   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
   1807   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
   1808   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
   1809   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
   1810   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
   1811   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW3_PLT_PCREL:
   1812   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW3_PLT_PCREL:
   1813   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
   1814   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
   1815   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
   1816   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
   1817   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
   1818       1.1  christos 	case R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
   1819       1.1  christos 	  /* This symbol requires a procedure linkage table entry.  We
   1820       1.1  christos 	     actually build the entry in adjust_dynamic_symbol,
   1821       1.1  christos 	     because this might be a case of linking PIC code without
   1822       1.1  christos 	     linking in any dynamic objects, in which case we don't
   1823       1.1  christos 	     need to generate a procedure linkage table after all.  */
   1824       1.1  christos 
   1825   1.1.1.4  christos 	  if (h != NULL)
   1826   1.1.1.4  christos 	    {
   1827   1.1.1.4  christos 	      h->needs_plt = 1;
   1828   1.1.1.4  christos 	      h->plt.refcount += 1;
   1829       1.1  christos 	    }
   1830       1.1  christos 	  break;
   1831   1.1.1.4  christos 
   1832   1.1.1.4  christos 	case R_TILEGX_64_PCREL:
   1833   1.1.1.4  christos 	case R_TILEGX_32_PCREL:
   1834   1.1.1.4  christos 	case R_TILEGX_16_PCREL:
   1835       1.1  christos 	case R_TILEGX_8_PCREL:
   1836       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_PCREL:
   1837       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_PCREL:
   1838       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_PCREL:
   1839       1.1  christos 	case R_TILEGX_IMM16_X1_HW1_PCREL:
   1840       1.1  christos 	case R_TILEGX_IMM16_X0_HW2_PCREL:
   1841       1.1  christos 	case R_TILEGX_IMM16_X1_HW2_PCREL:
   1842       1.1  christos 	case R_TILEGX_IMM16_X0_HW3_PCREL:
   1843       1.1  christos 	case R_TILEGX_IMM16_X1_HW3_PCREL:
   1844       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
   1845       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
   1846       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
   1847       1.1  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
   1848       1.1  christos 	case R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
   1849       1.1  christos 	case R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
   1850       1.1  christos 	  if (h != NULL)
   1851       1.1  christos 	    h->non_got_ref = 1;
   1852       1.1  christos 
   1853       1.1  christos 	  if (h != NULL
   1854       1.1  christos 	      && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
   1855       1.1  christos 	    break;
   1856       1.1  christos 	  /* Fall through.  */
   1857   1.1.1.4  christos 
   1858   1.1.1.4  christos 	case R_TILEGX_64:
   1859   1.1.1.4  christos 	case R_TILEGX_32:
   1860   1.1.1.4  christos 	case R_TILEGX_16:
   1861       1.1  christos 	case R_TILEGX_8:
   1862       1.1  christos 	case R_TILEGX_HW0:
   1863       1.1  christos 	case R_TILEGX_HW1:
   1864       1.1  christos 	case R_TILEGX_HW2:
   1865       1.1  christos 	case R_TILEGX_HW3:
   1866       1.1  christos 	case R_TILEGX_HW0_LAST:
   1867       1.1  christos 	case R_TILEGX_HW1_LAST:
   1868   1.1.1.4  christos 	case R_TILEGX_HW2_LAST:
   1869   1.1.1.4  christos 	case R_TILEGX_COPY:
   1870   1.1.1.4  christos 	case R_TILEGX_GLOB_DAT:
   1871   1.1.1.4  christos 	case R_TILEGX_JMP_SLOT:
   1872   1.1.1.4  christos 	case R_TILEGX_RELATIVE:
   1873   1.1.1.4  christos 	case R_TILEGX_BROFF_X1:
   1874   1.1.1.4  christos 	case R_TILEGX_JUMPOFF_X1:
   1875   1.1.1.4  christos 	case R_TILEGX_IMM8_X0:
   1876   1.1.1.4  christos 	case R_TILEGX_IMM8_Y0:
   1877   1.1.1.4  christos 	case R_TILEGX_IMM8_X1:
   1878   1.1.1.4  christos 	case R_TILEGX_IMM8_Y1:
   1879   1.1.1.4  christos 	case R_TILEGX_DEST_IMM8_X1:
   1880   1.1.1.4  christos 	case R_TILEGX_MT_IMM14_X1:
   1881   1.1.1.4  christos 	case R_TILEGX_MF_IMM14_X1:
   1882   1.1.1.4  christos 	case R_TILEGX_MMSTART_X0:
   1883   1.1.1.4  christos 	case R_TILEGX_MMEND_X0:
   1884   1.1.1.4  christos 	case R_TILEGX_SHAMT_X0:
   1885   1.1.1.4  christos 	case R_TILEGX_SHAMT_X1:
   1886   1.1.1.4  christos 	case R_TILEGX_SHAMT_Y0:
   1887       1.1  christos 	case R_TILEGX_SHAMT_Y1:
   1888       1.1  christos 	case R_TILEGX_IMM16_X0_HW0:
   1889       1.1  christos 	case R_TILEGX_IMM16_X1_HW0:
   1890       1.1  christos 	case R_TILEGX_IMM16_X0_HW1:
   1891       1.1  christos 	case R_TILEGX_IMM16_X1_HW1:
   1892       1.1  christos 	case R_TILEGX_IMM16_X0_HW2:
   1893       1.1  christos 	case R_TILEGX_IMM16_X1_HW2:
   1894       1.1  christos 	case R_TILEGX_IMM16_X0_HW3:
   1895       1.1  christos 	case R_TILEGX_IMM16_X1_HW3:
   1896       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_LAST:
   1897       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_LAST:
   1898       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_LAST:
   1899       1.1  christos 	case R_TILEGX_IMM16_X1_HW1_LAST:
   1900       1.1  christos 	case R_TILEGX_IMM16_X0_HW2_LAST:
   1901       1.1  christos 	case R_TILEGX_IMM16_X1_HW2_LAST:
   1902       1.1  christos 	  if (h != NULL)
   1903       1.1  christos 	    h->non_got_ref = 1;
   1904       1.1  christos 
   1905   1.1.1.2  christos 	r_tilegx_plt32:
   1906       1.1  christos 	  if (h != NULL && !bfd_link_pic (info))
   1907       1.1  christos 	    {
   1908       1.1  christos 	      /* We may need a .plt entry if the function this reloc
   1909       1.1  christos 		 refers to is in a shared lib.  */
   1910       1.1  christos 	      h->plt.refcount += 1;
   1911       1.1  christos 	    }
   1912       1.1  christos 
   1913       1.1  christos 	  /* If we are creating a shared library, and this is a reloc
   1914       1.1  christos 	     against a global symbol, or a non PC relative reloc
   1915       1.1  christos 	     against a local symbol, then we need to copy the reloc
   1916       1.1  christos 	     into the shared library.  However, if we are linking with
   1917       1.1  christos 	     -Bsymbolic, we do not need to copy a reloc against a
   1918       1.1  christos 	     global symbol which is defined in an object we are
   1919       1.1  christos 	     including in the link (i.e., DEF_REGULAR is set).  At
   1920       1.1  christos 	     this point we have not seen all the input files, so it is
   1921       1.1  christos 	     possible that DEF_REGULAR is not set now but will be set
   1922       1.1  christos 	     later (it is never cleared).  In case of a weak definition,
   1923       1.1  christos 	     DEF_REGULAR may be cleared later by a strong definition in
   1924       1.1  christos 	     a shared library.  We account for that possibility below by
   1925       1.1  christos 	     storing information in the relocs_copied field of the hash
   1926       1.1  christos 	     table entry.  A similar situation occurs when creating
   1927       1.1  christos 	     shared libraries and symbol visibility changes render the
   1928       1.1  christos 	     symbol local.
   1929       1.1  christos 
   1930       1.1  christos 	     If on the other hand, we are creating an executable, we
   1931       1.1  christos 	     may need to keep relocations for symbols satisfied by a
   1932       1.1  christos 	     dynamic library if we manage to avoid copy relocs for the
   1933   1.1.1.2  christos 	     symbol.  */
   1934       1.1  christos 	  if ((bfd_link_pic (info)
   1935       1.1  christos 	       && (sec->flags & SEC_ALLOC) != 0
   1936       1.1  christos 	       && (! tilegx_elf_howto_table[r_type].pc_relative
   1937       1.1  christos 		   || (h != NULL
   1938       1.1  christos 		       && (! info->symbolic
   1939       1.1  christos 			   || h->root.type == bfd_link_hash_defweak
   1940   1.1.1.2  christos 			   || !h->def_regular))))
   1941       1.1  christos 	      || (!bfd_link_pic (info)
   1942       1.1  christos 		  && (sec->flags & SEC_ALLOC) != 0
   1943       1.1  christos 		  && h != NULL
   1944       1.1  christos 		  && (h->root.type == bfd_link_hash_defweak
   1945       1.1  christos 		      || !h->def_regular)))
   1946   1.1.1.4  christos 	    {
   1947   1.1.1.4  christos 	      struct elf_dyn_relocs *p;
   1948       1.1  christos 	      struct elf_dyn_relocs **head;
   1949       1.1  christos 
   1950       1.1  christos 	      /* When creating a shared object, we must copy these
   1951       1.1  christos 		 relocs into the output file.  We create a reloc
   1952       1.1  christos 		 section in dynobj and make room for the reloc.  */
   1953       1.1  christos 	      if (sreloc == NULL)
   1954       1.1  christos 		{
   1955       1.1  christos 		  sreloc = _bfd_elf_make_dynamic_reloc_section
   1956   1.1.1.7  christos 		    (sec, htab->elf.dynobj, htab->word_align_power, abfd,
   1957       1.1  christos 		     /*rela?*/ true);
   1958       1.1  christos 
   1959   1.1.1.7  christos 		  if (sreloc == NULL)
   1960       1.1  christos 		    return false;
   1961       1.1  christos 		}
   1962       1.1  christos 
   1963       1.1  christos 	      /* If this is a global symbol, we count the number of
   1964       1.1  christos 		 relocations we need for this symbol.  */
   1965   1.1.1.7  christos 	      if (h != NULL)
   1966       1.1  christos 		head = &h->dyn_relocs;
   1967       1.1  christos 	      else
   1968       1.1  christos 		{
   1969       1.1  christos 		  /* Track dynamic relocs needed for local syms too.
   1970       1.1  christos 		     We really need local syms available to do this
   1971       1.1  christos 		     easily.  Oh well.  */
   1972       1.1  christos 
   1973       1.1  christos 		  asection *s;
   1974       1.1  christos 		  void *vpp;
   1975       1.1  christos 		  Elf_Internal_Sym *isym;
   1976   1.1.1.7  christos 
   1977       1.1  christos 		  isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
   1978       1.1  christos 						abfd, r_symndx);
   1979   1.1.1.7  christos 		  if (isym == NULL)
   1980       1.1  christos 		    return false;
   1981       1.1  christos 
   1982       1.1  christos 		  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
   1983       1.1  christos 		  if (s == NULL)
   1984       1.1  christos 		    s = sec;
   1985       1.1  christos 
   1986   1.1.1.4  christos 		  vpp = &elf_section_data (s)->local_dynrel;
   1987       1.1  christos 		  head = (struct elf_dyn_relocs **) vpp;
   1988       1.1  christos 		}
   1989       1.1  christos 
   1990       1.1  christos 	      p = *head;
   1991       1.1  christos 	      if (p == NULL || p->sec != sec)
   1992   1.1.1.7  christos 		{
   1993   1.1.1.4  christos 		  size_t amt = sizeof *p;
   1994       1.1  christos 		  p = ((struct elf_dyn_relocs *)
   1995       1.1  christos 		       bfd_alloc (htab->elf.dynobj, amt));
   1996   1.1.1.7  christos 		  if (p == NULL)
   1997       1.1  christos 		    return false;
   1998       1.1  christos 		  p->next = *head;
   1999       1.1  christos 		  *head = p;
   2000       1.1  christos 		  p->sec = sec;
   2001       1.1  christos 		  p->count = 0;
   2002       1.1  christos 		  p->pc_count = 0;
   2003       1.1  christos 		}
   2004       1.1  christos 
   2005       1.1  christos 	      p->count += 1;
   2006       1.1  christos 	      if (tilegx_elf_howto_table[r_type].pc_relative)
   2007       1.1  christos 		p->pc_count += 1;
   2008       1.1  christos 	    }
   2009       1.1  christos 
   2010       1.1  christos 	  break;
   2011       1.1  christos 
   2012       1.1  christos 	case R_TILEGX_GNU_VTINHERIT:
   2013   1.1.1.7  christos 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
   2014       1.1  christos 	    return false;
   2015       1.1  christos 	  break;
   2016       1.1  christos 
   2017       1.1  christos 	case R_TILEGX_GNU_VTENTRY:
   2018   1.1.1.7  christos 	  if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
   2019       1.1  christos 	    return false;
   2020       1.1  christos 	  break;
   2021       1.1  christos 
   2022       1.1  christos 	default:
   2023       1.1  christos 	  break;
   2024       1.1  christos 	}
   2025       1.1  christos     }
   2026   1.1.1.7  christos 
   2027       1.1  christos   return true;
   2028       1.1  christos }
   2029       1.1  christos 
   2030       1.1  christos 
   2031       1.1  christos asection *
   2033  1.1.1.10  christos tilegx_elf_gc_mark_hook (asection *sec,
   2034       1.1  christos 			 struct bfd_link_info *info,
   2035  1.1.1.10  christos 			 struct elf_reloc_cookie *cookie,
   2036       1.1  christos 			 struct elf_link_hash_entry *h,
   2037       1.1  christos 			 unsigned int symndx)
   2038       1.1  christos {
   2039  1.1.1.10  christos   if (h != NULL)
   2040       1.1  christos     {
   2041       1.1  christos       switch (TILEGX_ELF_R_TYPE (cookie->rel->r_info))
   2042       1.1  christos 	{
   2043       1.1  christos 	case R_TILEGX_GNU_VTINHERIT:
   2044       1.1  christos 	case R_TILEGX_GNU_VTENTRY:
   2045       1.1  christos 	  return NULL;
   2046       1.1  christos 	}
   2047       1.1  christos     }
   2048   1.1.1.2  christos 
   2049   1.1.1.2  christos   /* FIXME: The test here, in check_relocs and in relocate_section
   2050       1.1  christos      dealing with TLS optimization, ought to be !bfd_link_executable (info).  */
   2051   1.1.1.4  christos   if (bfd_link_pic (info))
   2052   1.1.1.4  christos     {
   2053  1.1.1.10  christos       struct bfd_link_hash_entry *bh;
   2054       1.1  christos 
   2055       1.1  christos       switch (TILEGX_ELF_R_TYPE (cookie->rel->r_info))
   2056       1.1  christos 	{
   2057       1.1  christos 	case R_TILEGX_TLS_GD_CALL:
   2058       1.1  christos 	  /* This reloc implicitly references __tls_get_addr.  We know
   2059       1.1  christos 	     another reloc will reference the same symbol as the one
   2060       1.1  christos 	     on this reloc, so the real symbol and section will be
   2061   1.1.1.4  christos 	     gc marked when processing the other reloc.  That lets
   2062   1.1.1.4  christos 	     us handle __tls_get_addr here.  */
   2063   1.1.1.4  christos 	  bh = NULL;
   2064   1.1.1.4  christos 	  if (! _bfd_generic_link_add_one_symbol (info, sec->owner,
   2065   1.1.1.7  christos 						  "__tls_get_addr", 0,
   2066   1.1.1.7  christos 						  bfd_und_section_ptr,
   2067   1.1.1.4  christos 						  0, NULL, false,
   2068   1.1.1.4  christos 						  false, &bh))
   2069       1.1  christos 	    return NULL;
   2070       1.1  christos 	  h = (struct elf_link_hash_entry *) bh;
   2071   1.1.1.4  christos 	  BFD_ASSERT (h != NULL);
   2072   1.1.1.4  christos 	  h->mark = 1;
   2073  1.1.1.10  christos 	  if (h->is_weakalias)
   2074       1.1  christos 	    weakdef (h)->mark = 1;
   2075       1.1  christos 	  symndx = 0;
   2076       1.1  christos 	}
   2077  1.1.1.10  christos     }
   2078       1.1  christos 
   2079       1.1  christos   return _bfd_elf_gc_mark_hook (sec, info, cookie, h, symndx);
   2080       1.1  christos }
   2081       1.1  christos 
   2082       1.1  christos /* Adjust a symbol defined by a dynamic object and referenced by a
   2083       1.1  christos    regular object.  The current definition is in some section of the
   2084       1.1  christos    dynamic object, but we're not including those sections.  We have to
   2085       1.1  christos    change the definition to something the rest of the link can
   2086   1.1.1.7  christos    understand.  */
   2087       1.1  christos 
   2088       1.1  christos bool
   2089       1.1  christos tilegx_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   2090       1.1  christos 				  struct elf_link_hash_entry *h)
   2091       1.1  christos {
   2092   1.1.1.4  christos   struct tilegx_elf_link_hash_table *htab;
   2093       1.1  christos   bfd *dynobj;
   2094       1.1  christos   asection *s, *srel;
   2095       1.1  christos 
   2096       1.1  christos   htab = tilegx_elf_hash_table (info);
   2097       1.1  christos   BFD_ASSERT (htab != NULL);
   2098       1.1  christos 
   2099       1.1  christos   dynobj = htab->elf.dynobj;
   2100       1.1  christos 
   2101       1.1  christos   /* Make sure we know what is going on here.  */
   2102   1.1.1.4  christos   BFD_ASSERT (dynobj != NULL
   2103       1.1  christos 	      && (h->needs_plt
   2104       1.1  christos 		  || h->is_weakalias
   2105       1.1  christos 		  || (h->def_dynamic
   2106       1.1  christos 		      && h->ref_regular
   2107       1.1  christos 		      && !h->def_regular)));
   2108       1.1  christos 
   2109       1.1  christos   /* If this is a function, put it in the procedure linkage table.  We
   2110       1.1  christos      will fill in the contents of the procedure linkage table later
   2111       1.1  christos      (although we could actually do it here). */
   2112       1.1  christos   if (h->type == STT_FUNC || h->needs_plt)
   2113       1.1  christos     {
   2114       1.1  christos       if (h->plt.refcount <= 0
   2115       1.1  christos 	  || SYMBOL_CALLS_LOCAL (info, h)
   2116       1.1  christos 	  || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
   2117       1.1  christos 	      && h->root.type == bfd_link_hash_undefweak))
   2118   1.1.1.4  christos 	{
   2119   1.1.1.4  christos 	  /* This case can occur if we saw a R_TILEGX_JUMPOFF_X1_PLT
   2120   1.1.1.4  christos 	     reloc in an input file, but the symbol was never referred
   2121   1.1.1.4  christos 	     to by a dynamic object, or if all references were garbage
   2122   1.1.1.4  christos 	     collected.  In such a case, we don't actually need to build
   2123       1.1  christos 	     a procedure linkage table, and we can just do a
   2124       1.1  christos 	     R_TILEGX_JUMPOFF_X1 relocation instead. */
   2125       1.1  christos 	  h->plt.offset = (bfd_vma) -1;
   2126       1.1  christos 	  h->needs_plt = 0;
   2127   1.1.1.7  christos 	}
   2128       1.1  christos 
   2129       1.1  christos       return true;
   2130       1.1  christos     }
   2131       1.1  christos   else
   2132       1.1  christos     h->plt.offset = (bfd_vma) -1;
   2133       1.1  christos 
   2134       1.1  christos   /* If this is a weak symbol, and there is a real definition, the
   2135   1.1.1.4  christos      processor independent code will have arranged for us to see the
   2136       1.1  christos      real definition first, and we can just use the same value.  */
   2137   1.1.1.4  christos   if (h->is_weakalias)
   2138   1.1.1.4  christos     {
   2139   1.1.1.4  christos       struct elf_link_hash_entry *def = weakdef (h);
   2140   1.1.1.4  christos       BFD_ASSERT (def->root.type == bfd_link_hash_defined);
   2141   1.1.1.7  christos       h->root.u.def.section = def->root.u.def.section;
   2142       1.1  christos       h->root.u.def.value = def->root.u.def.value;
   2143       1.1  christos       return true;
   2144       1.1  christos     }
   2145       1.1  christos 
   2146       1.1  christos   /* This is a reference to a symbol defined by a dynamic object which
   2147       1.1  christos      is not a function.  */
   2148       1.1  christos 
   2149       1.1  christos   /* If we are creating a shared library, we must presume that the
   2150       1.1  christos      only references to the symbol are via the global offset table.
   2151   1.1.1.2  christos      For such cases we need not do anything here; the relocations will
   2152   1.1.1.7  christos      be handled correctly by relocate_section.  */
   2153       1.1  christos   if (bfd_link_pic (info))
   2154       1.1  christos     return true;
   2155       1.1  christos 
   2156       1.1  christos   /* If there are no references to this symbol that do not use the
   2157   1.1.1.7  christos      GOT, we don't need to generate a copy reloc.  */
   2158       1.1  christos   if (!h->non_got_ref)
   2159       1.1  christos     return true;
   2160       1.1  christos 
   2161       1.1  christos   /* If -z nocopyreloc was given, we won't generate them either.  */
   2162       1.1  christos   if (info->nocopyreloc)
   2163   1.1.1.7  christos     {
   2164       1.1  christos       h->non_got_ref = 0;
   2165       1.1  christos       return true;
   2166   1.1.1.4  christos     }
   2167       1.1  christos 
   2168   1.1.1.7  christos   /* If we don't find any dynamic relocs in read-only sections, then
   2169       1.1  christos      we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
   2170       1.1  christos   if (!_bfd_elf_readonly_dynrelocs (h))
   2171   1.1.1.7  christos     {
   2172       1.1  christos       h->non_got_ref = 0;
   2173       1.1  christos       return true;
   2174       1.1  christos     }
   2175       1.1  christos 
   2176       1.1  christos   /* We must allocate the symbol in our .dynbss section, which will
   2177       1.1  christos      become part of the .bss section of the executable.  There will be
   2178       1.1  christos      an entry for this symbol in the .dynsym section.  The dynamic
   2179       1.1  christos      object will contain position independent code, so all references
   2180       1.1  christos      from the dynamic object to this symbol will go through the global
   2181       1.1  christos      offset table.  The dynamic linker will use the .dynsym entry to
   2182       1.1  christos      determine the address it must put in the global offset table, so
   2183       1.1  christos      both the dynamic object and the regular object will refer to the
   2184       1.1  christos      same memory location for the variable.  */
   2185       1.1  christos 
   2186       1.1  christos   /* We must generate a R_TILEGX_COPY reloc to tell the dynamic linker
   2187       1.1  christos      to copy the initial value out of the dynamic object and into the
   2188   1.1.1.4  christos      runtime process image.  We need to remember the offset into the
   2189   1.1.1.4  christos      .rel.bss section we are going to use.  */
   2190   1.1.1.4  christos   if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
   2191   1.1.1.4  christos     {
   2192   1.1.1.4  christos       s = htab->elf.sdynrelro;
   2193   1.1.1.4  christos       srel = htab->elf.sreldynrelro;
   2194   1.1.1.4  christos     }
   2195   1.1.1.4  christos   else
   2196   1.1.1.4  christos     {
   2197   1.1.1.4  christos       s = htab->elf.sdynbss;
   2198       1.1  christos       srel = htab->elf.srelbss;
   2199       1.1  christos     }
   2200   1.1.1.4  christos   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
   2201       1.1  christos     {
   2202       1.1  christos       srel->size += TILEGX_ELF_RELA_BYTES (htab);
   2203       1.1  christos       h->needs_copy = 1;
   2204   1.1.1.4  christos     }
   2205       1.1  christos 
   2206       1.1  christos   return _bfd_elf_adjust_dynamic_copy (info, h, s);
   2207       1.1  christos }
   2208       1.1  christos 
   2209       1.1  christos /* Allocate space in .plt, .got and associated reloc sections for
   2210   1.1.1.7  christos    dynamic relocs.  */
   2211       1.1  christos 
   2212       1.1  christos static bool
   2213       1.1  christos allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   2214       1.1  christos {
   2215   1.1.1.4  christos   struct bfd_link_info *info;
   2216       1.1  christos   struct tilegx_elf_link_hash_table *htab;
   2217       1.1  christos   struct elf_dyn_relocs *p;
   2218   1.1.1.7  christos 
   2219       1.1  christos   if (h->root.type == bfd_link_hash_indirect)
   2220       1.1  christos     return true;
   2221       1.1  christos 
   2222       1.1  christos   info = (struct bfd_link_info *) inf;
   2223       1.1  christos   htab = tilegx_elf_hash_table (info);
   2224       1.1  christos   BFD_ASSERT (htab != NULL);
   2225       1.1  christos 
   2226       1.1  christos   if (htab->elf.dynamic_sections_created
   2227       1.1  christos       && h->plt.refcount > 0)
   2228       1.1  christos     {
   2229       1.1  christos       /* Make sure this symbol is output as a dynamic symbol.
   2230       1.1  christos 	 Undefined weak syms won't yet be marked as dynamic.  */
   2231       1.1  christos       if (h->dynindx == -1
   2232       1.1  christos 	  && !h->forced_local)
   2233   1.1.1.7  christos 	{
   2234       1.1  christos 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   2235       1.1  christos 	    return false;
   2236   1.1.1.2  christos 	}
   2237       1.1  christos 
   2238       1.1  christos       if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
   2239       1.1  christos 	{
   2240       1.1  christos 	  asection *s = htab->elf.splt;
   2241       1.1  christos 
   2242       1.1  christos 	  /* Allocate room for the header and tail.  */
   2243   1.1.1.2  christos 	  if (s->size == 0)
   2244       1.1  christos 	    {
   2245       1.1  christos 	      s->size = PLT_ENTRY_SIZE;
   2246   1.1.1.4  christos 	    }
   2247       1.1  christos 
   2248       1.1  christos 	  h->plt.offset = s->size - PLT_ENTRY_SIZE + PLT_HEADER_SIZE;
   2249       1.1  christos 
   2250       1.1  christos 	  /* If this symbol is not defined in a regular file, and we are
   2251       1.1  christos 	     not generating a shared library, then set the symbol to this
   2252       1.1  christos 	     location in the .plt.  This is required to make function
   2253   1.1.1.2  christos 	     pointers compare as equal between the normal executable and
   2254       1.1  christos 	     the shared library.  */
   2255       1.1  christos 	  if (! bfd_link_pic (info)
   2256       1.1  christos 	      && !h->def_regular)
   2257       1.1  christos 	    {
   2258       1.1  christos 	      h->root.u.def.section = s;
   2259       1.1  christos 	      h->root.u.def.value = h->plt.offset;
   2260       1.1  christos 	    }
   2261       1.1  christos 
   2262       1.1  christos 	  /* Make room for this entry.  */
   2263       1.1  christos 	  s->size += PLT_ENTRY_SIZE;
   2264       1.1  christos 
   2265       1.1  christos 	  /* We also need to make an entry in the .got.plt section.  */
   2266       1.1  christos 	  htab->elf.sgotplt->size += GOT_ENTRY_SIZE (htab);
   2267       1.1  christos 
   2268       1.1  christos 	  /* We also need to make an entry in the .rela.plt section.  */
   2269       1.1  christos 	  htab->elf.srelplt->size += TILEGX_ELF_RELA_BYTES (htab);
   2270       1.1  christos 	}
   2271       1.1  christos       else
   2272       1.1  christos 	{
   2273       1.1  christos 	  h->plt.offset = (bfd_vma) -1;
   2274       1.1  christos 	  h->needs_plt = 0;
   2275       1.1  christos 	}
   2276       1.1  christos     }
   2277       1.1  christos   else
   2278       1.1  christos     {
   2279       1.1  christos       h->plt.offset = (bfd_vma) -1;
   2280       1.1  christos       h->needs_plt = 0;
   2281       1.1  christos     }
   2282       1.1  christos 
   2283       1.1  christos   /* If a TLS_IE symbol is now local to the binary, make it a TLS_LE
   2284       1.1  christos      requiring no TLS entry.  */
   2285   1.1.1.4  christos   if (h->got.refcount > 0
   2286       1.1  christos       && !htab->disable_le_transition
   2287       1.1  christos       && bfd_link_executable (info)
   2288       1.1  christos       && h->dynindx == -1
   2289       1.1  christos       && tilegx_elf_hash_entry(h)->tls_type == GOT_TLS_IE)
   2290       1.1  christos     h->got.offset = (bfd_vma) -1;
   2291       1.1  christos   else if (h->got.refcount > 0)
   2292   1.1.1.7  christos     {
   2293       1.1  christos       asection *s;
   2294       1.1  christos       bool dyn;
   2295       1.1  christos       int tls_type = tilegx_elf_hash_entry(h)->tls_type;
   2296       1.1  christos 
   2297       1.1  christos       /* Make sure this symbol is output as a dynamic symbol.
   2298       1.1  christos 	 Undefined weak syms won't yet be marked as dynamic.  */
   2299       1.1  christos       if (h->dynindx == -1
   2300       1.1  christos 	  && !h->forced_local)
   2301   1.1.1.7  christos 	{
   2302       1.1  christos 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   2303       1.1  christos 	    return false;
   2304       1.1  christos 	}
   2305       1.1  christos 
   2306       1.1  christos       s = htab->elf.sgot;
   2307       1.1  christos       h->got.offset = s->size;
   2308       1.1  christos       s->size += TILEGX_ELF_WORD_BYTES (htab);
   2309   1.1.1.4  christos       /* TLS_GD entries need 2 consecutive GOT slots. */
   2310       1.1  christos       if (tls_type == GOT_TLS_GD)
   2311       1.1  christos 	s->size += TILEGX_ELF_WORD_BYTES (htab);
   2312   1.1.1.4  christos       dyn = htab->elf.dynamic_sections_created;
   2313       1.1  christos       /* TLS_IE needs one dynamic relocation,
   2314       1.1  christos 	 TLS_GD needs two if local symbol and two if global.  */
   2315   1.1.1.2  christos       if (tls_type == GOT_TLS_GD || tls_type == GOT_TLS_IE)
   2316   1.1.1.2  christos 	htab->elf.srelgot->size += 2 * TILEGX_ELF_RELA_BYTES (htab);
   2317   1.1.1.2  christos       else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
   2318       1.1  christos 						bfd_link_pic (info),
   2319       1.1  christos 						h))
   2320       1.1  christos 	htab->elf.srelgot->size += TILEGX_ELF_RELA_BYTES (htab);
   2321       1.1  christos     }
   2322       1.1  christos   else
   2323   1.1.1.7  christos     h->got.offset = (bfd_vma) -1;
   2324   1.1.1.7  christos 
   2325       1.1  christos   if (h->dyn_relocs == NULL)
   2326       1.1  christos     return true;
   2327       1.1  christos 
   2328       1.1  christos   /* In the shared -Bsymbolic case, discard space allocated for
   2329       1.1  christos      dynamic pc-relative relocs against symbols which turn out to be
   2330       1.1  christos      defined in regular objects.  For the normal shared case, discard
   2331       1.1  christos      space for pc-relative relocs that have become local due to symbol
   2332   1.1.1.2  christos      visibility changes.  */
   2333       1.1  christos 
   2334       1.1  christos   if (bfd_link_pic (info))
   2335       1.1  christos     {
   2336   1.1.1.4  christos       if (SYMBOL_CALLS_LOCAL (info, h))
   2337       1.1  christos 	{
   2338   1.1.1.7  christos 	  struct elf_dyn_relocs **pp;
   2339       1.1  christos 
   2340       1.1  christos 	  for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
   2341       1.1  christos 	    {
   2342       1.1  christos 	      p->count -= p->pc_count;
   2343       1.1  christos 	      p->pc_count = 0;
   2344       1.1  christos 	      if (p->count == 0)
   2345       1.1  christos 		*pp = p->next;
   2346       1.1  christos 	      else
   2347       1.1  christos 		pp = &p->next;
   2348       1.1  christos 	    }
   2349       1.1  christos 	}
   2350       1.1  christos 
   2351   1.1.1.7  christos       /* Also discard relocs on undefined weak syms with non-default
   2352       1.1  christos 	 visibility.  */
   2353       1.1  christos       if (h->dyn_relocs != NULL
   2354   1.1.1.4  christos 	  && h->root.type == bfd_link_hash_undefweak)
   2355   1.1.1.4  christos 	{
   2356   1.1.1.7  christos 	  if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
   2357       1.1  christos 	      || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
   2358       1.1  christos 	    h->dyn_relocs = NULL;
   2359       1.1  christos 
   2360       1.1  christos 	  /* Make sure undefined weak symbols are output as a dynamic
   2361       1.1  christos 	     symbol in PIEs.  */
   2362       1.1  christos 	  else if (h->dynindx == -1
   2363       1.1  christos 		   && !h->forced_local)
   2364   1.1.1.7  christos 	    {
   2365       1.1  christos 	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
   2366       1.1  christos 		return false;
   2367       1.1  christos 	    }
   2368       1.1  christos 	}
   2369       1.1  christos     }
   2370       1.1  christos   else
   2371       1.1  christos     {
   2372       1.1  christos       /* For the non-shared case, discard space for relocs against
   2373       1.1  christos 	 symbols which turn out to need copy relocs or are not
   2374       1.1  christos 	 dynamic.  */
   2375       1.1  christos 
   2376       1.1  christos       if (!h->non_got_ref
   2377       1.1  christos 	  && ((h->def_dynamic
   2378       1.1  christos 	       && !h->def_regular)
   2379       1.1  christos 	      || (htab->elf.dynamic_sections_created
   2380       1.1  christos 		  && (h->root.type == bfd_link_hash_undefweak
   2381       1.1  christos 		      || h->root.type == bfd_link_hash_undefined))))
   2382       1.1  christos 	{
   2383       1.1  christos 	  /* Make sure this symbol is output as a dynamic symbol.
   2384       1.1  christos 	     Undefined weak syms won't yet be marked as dynamic.  */
   2385       1.1  christos 	  if (h->dynindx == -1
   2386       1.1  christos 	      && !h->forced_local)
   2387   1.1.1.7  christos 	    {
   2388       1.1  christos 	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
   2389       1.1  christos 		return false;
   2390       1.1  christos 	    }
   2391       1.1  christos 
   2392       1.1  christos 	  /* If that succeeded, we know we'll be keeping all the
   2393       1.1  christos 	     relocs.  */
   2394       1.1  christos 	  if (h->dynindx != -1)
   2395       1.1  christos 	    goto keep;
   2396   1.1.1.7  christos 	}
   2397       1.1  christos 
   2398       1.1  christos       h->dyn_relocs = NULL;
   2399       1.1  christos 
   2400       1.1  christos     keep: ;
   2401       1.1  christos     }
   2402   1.1.1.7  christos 
   2403       1.1  christos   /* Finally, allocate space.  */
   2404       1.1  christos   for (p = h->dyn_relocs; p != NULL; p = p->next)
   2405       1.1  christos     {
   2406       1.1  christos       asection *sreloc = elf_section_data (p->sec)->sreloc;
   2407       1.1  christos       sreloc->size += p->count * TILEGX_ELF_RELA_BYTES (htab);
   2408   1.1.1.7  christos     }
   2409       1.1  christos 
   2410       1.1  christos   return true;
   2411       1.1  christos }
   2412       1.1  christos 
   2413       1.1  christos /* Return true if the dynamic symbol for a given section should be
   2414   1.1.1.7  christos    omitted when creating a shared library.  */
   2415       1.1  christos 
   2416       1.1  christos bool
   2417       1.1  christos tilegx_elf_omit_section_dynsym (bfd *output_bfd,
   2418       1.1  christos 				struct bfd_link_info *info,
   2419       1.1  christos 				asection *p)
   2420       1.1  christos {
   2421       1.1  christos   /* We keep the .got section symbol so that explicit relocations
   2422       1.1  christos      against the _GLOBAL_OFFSET_TABLE_ symbol emitted in PIC mode
   2423   1.1.1.7  christos      can be turned into relocations against the .got symbol.  */
   2424       1.1  christos   if (strcmp (p->name, ".got") == 0)
   2425   1.1.1.5  christos     return false;
   2426       1.1  christos 
   2427       1.1  christos   return _bfd_elf_omit_section_dynsym_default (output_bfd, info, p);
   2428   1.1.1.7  christos }
   2429   1.1.1.9  christos 
   2430   1.1.1.9  christos bool
   2431       1.1  christos tilegx_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   2432       1.1  christos 			       struct bfd_link_info *info)
   2433       1.1  christos {
   2434       1.1  christos   struct tilegx_elf_link_hash_table *htab;
   2435       1.1  christos   bfd *dynobj;
   2436       1.1  christos   asection *s;
   2437       1.1  christos   bfd *ibfd;
   2438       1.1  christos 
   2439       1.1  christos   htab = tilegx_elf_hash_table (info);
   2440   1.1.1.9  christos   BFD_ASSERT (htab != NULL);
   2441   1.1.1.9  christos   dynobj = htab->elf.dynobj;
   2442       1.1  christos   if (dynobj == NULL)
   2443       1.1  christos     return true;
   2444       1.1  christos 
   2445       1.1  christos   if (elf_hash_table (info)->dynamic_sections_created)
   2446   1.1.1.2  christos     {
   2447       1.1  christos       /* Set the contents of the .interp section to the interpreter.  */
   2448  1.1.1.10  christos       if (bfd_link_executable (info) && !info->nointerp)
   2449       1.1  christos 	{
   2450       1.1  christos 	  s = htab->elf.interp;
   2451       1.1  christos 	  BFD_ASSERT (s != NULL);
   2452   1.1.1.9  christos 	  s->size = strlen (htab->dynamic_interpreter) + 1;
   2453       1.1  christos 	  s->contents = (unsigned char *) htab->dynamic_interpreter;
   2454       1.1  christos 	  s->alloced = 1;
   2455       1.1  christos 	}
   2456       1.1  christos     }
   2457       1.1  christos 
   2458   1.1.1.2  christos   /* Set up .got offsets for local syms, and space for local dynamic
   2459       1.1  christos      relocs.  */
   2460       1.1  christos   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
   2461       1.1  christos     {
   2462       1.1  christos       bfd_signed_vma *local_got;
   2463       1.1  christos       bfd_signed_vma *end_local_got;
   2464       1.1  christos       char *local_tls_type;
   2465       1.1  christos       bfd_size_type locsymcount;
   2466       1.1  christos       Elf_Internal_Shdr *symtab_hdr;
   2467       1.1  christos       asection *srel;
   2468       1.1  christos 
   2469       1.1  christos       if (! is_tilegx_elf (ibfd))
   2470       1.1  christos 	continue;
   2471       1.1  christos 
   2472   1.1.1.4  christos       for (s = ibfd->sections; s != NULL; s = s->next)
   2473       1.1  christos 	{
   2474       1.1  christos 	  struct elf_dyn_relocs *p;
   2475       1.1  christos 
   2476       1.1  christos 	  for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
   2477       1.1  christos 	    {
   2478       1.1  christos 	      if (!bfd_is_abs_section (p->sec)
   2479       1.1  christos 		  && bfd_is_abs_section (p->sec->output_section))
   2480       1.1  christos 		{
   2481       1.1  christos 		  /* Input section has been discarded, either because
   2482       1.1  christos 		     it is a copy of a linkonce section or due to
   2483       1.1  christos 		     linker script /DISCARD/, so we'll be discarding
   2484       1.1  christos 		     the relocs too.  */
   2485       1.1  christos 		}
   2486       1.1  christos 	      else if (p->count != 0)
   2487       1.1  christos 		{
   2488       1.1  christos 		  srel = elf_section_data (p->sec)->sreloc;
   2489   1.1.1.4  christos 		  srel->size += p->count * TILEGX_ELF_RELA_BYTES (htab);
   2490   1.1.1.4  christos 		  if ((p->sec->output_section->flags & SEC_READONLY) != 0)
   2491   1.1.1.4  christos 		    {
   2492   1.1.1.5  christos 		      info->flags |= DF_TEXTREL;
   2493   1.1.1.4  christos 
   2494   1.1.1.4  christos 		      info->callbacks->minfo (_("%pB: dynamic relocation in read-only section `%pA'\n"),
   2495       1.1  christos 					      p->sec->owner, p->sec);
   2496       1.1  christos 		    }
   2497       1.1  christos 		}
   2498       1.1  christos 	    }
   2499       1.1  christos 	}
   2500       1.1  christos 
   2501       1.1  christos       local_got = elf_local_got_refcounts (ibfd);
   2502       1.1  christos       if (!local_got)
   2503       1.1  christos 	continue;
   2504       1.1  christos 
   2505       1.1  christos       symtab_hdr = &elf_symtab_hdr (ibfd);
   2506       1.1  christos       locsymcount = symtab_hdr->sh_info;
   2507       1.1  christos       end_local_got = local_got + locsymcount;
   2508       1.1  christos       local_tls_type = _bfd_tilegx_elf_local_got_tls_type (ibfd);
   2509       1.1  christos       s = htab->elf.sgot;
   2510       1.1  christos       srel = htab->elf.srelgot;
   2511       1.1  christos       for (; local_got < end_local_got; ++local_got, ++local_tls_type)
   2512       1.1  christos 	{
   2513       1.1  christos 	  if (*local_got > 0)
   2514       1.1  christos 	    {
   2515   1.1.1.4  christos 	      *local_got = s->size;
   2516   1.1.1.4  christos 	      s->size += TILEGX_ELF_WORD_BYTES (htab);
   2517   1.1.1.4  christos 	      if (*local_tls_type == GOT_TLS_GD)
   2518   1.1.1.4  christos 		s->size += TILEGX_ELF_WORD_BYTES (htab);
   2519   1.1.1.4  christos 	      if (bfd_link_pic (info)
   2520       1.1  christos 		  || *local_tls_type == GOT_TLS_GD
   2521       1.1  christos 		  || *local_tls_type == GOT_TLS_IE)
   2522       1.1  christos 		srel->size += TILEGX_ELF_RELA_BYTES (htab);
   2523       1.1  christos 	    }
   2524       1.1  christos 	  else
   2525       1.1  christos 	    *local_got = (bfd_vma) -1;
   2526       1.1  christos 	}
   2527       1.1  christos     }
   2528       1.1  christos 
   2529       1.1  christos   /* Allocate global sym .plt and .got entries, and space for global
   2530       1.1  christos      sym dynamic relocs.  */
   2531       1.1  christos   elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
   2532       1.1  christos 
   2533       1.1  christos   if (elf_hash_table (info)->dynamic_sections_created)
   2534       1.1  christos     {
   2535       1.1  christos       /* If the .got section is more than 0x8000 bytes, we add
   2536       1.1  christos 	 0x8000 to the value of _GLOBAL_OFFSET_TABLE_, so that 16
   2537       1.1  christos 	 bit relocations have a greater chance of working. */
   2538       1.1  christos       if (htab->elf.sgot->size >= 0x8000
   2539       1.1  christos 	  && elf_hash_table (info)->hgot->root.u.def.value == 0)
   2540       1.1  christos 	elf_hash_table (info)->hgot->root.u.def.value = 0x8000;
   2541       1.1  christos     }
   2542       1.1  christos 
   2543       1.1  christos   if (htab->elf.sgotplt)
   2544       1.1  christos     {
   2545       1.1  christos       struct elf_link_hash_entry *got;
   2546   1.1.1.7  christos       got = elf_link_hash_lookup (elf_hash_table (info),
   2547       1.1  christos 				  "_GLOBAL_OFFSET_TABLE_",
   2548       1.1  christos 				  false, false, false);
   2549   1.1.1.4  christos 
   2550       1.1  christos       /* Don't allocate .got.plt section if there are no GOT nor PLT
   2551       1.1  christos 	 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_.  */
   2552       1.1  christos       if ((got == NULL
   2553       1.1  christos 	   || !got->ref_regular_nonweak)
   2554       1.1  christos 	  && (htab->elf.sgotplt->size
   2555       1.1  christos 	      == (unsigned)GOTPLT_HEADER_SIZE (htab))
   2556       1.1  christos 	  && (htab->elf.splt == NULL
   2557       1.1  christos 	      || htab->elf.splt->size == 0)
   2558       1.1  christos 	  && (htab->elf.sgot == NULL
   2559       1.1  christos 	      || (htab->elf.sgot->size
   2560       1.1  christos 		  == get_elf_backend_data (output_bfd)->got_header_size)))
   2561       1.1  christos 	htab->elf.sgotplt->size = 0;
   2562       1.1  christos     }
   2563       1.1  christos 
   2564       1.1  christos   /* The check_relocs and adjust_dynamic_symbol entry points have
   2565       1.1  christos      determined the sizes of the various dynamic sections.  Allocate
   2566       1.1  christos      memory for them.  */
   2567       1.1  christos   for (s = dynobj->sections; s != NULL; s = s->next)
   2568       1.1  christos     {
   2569       1.1  christos       if ((s->flags & SEC_LINKER_CREATED) == 0)
   2570       1.1  christos 	continue;
   2571       1.1  christos 
   2572       1.1  christos       if (s == htab->elf.splt
   2573   1.1.1.4  christos 	  || s == htab->elf.sgot
   2574   1.1.1.4  christos 	  || s == htab->elf.sgotplt
   2575       1.1  christos 	  || s == htab->elf.sdynbss
   2576       1.1  christos 	  || s == htab->elf.sdynrelro)
   2577       1.1  christos 	{
   2578       1.1  christos 	  /* Strip this section if we don't need it; see the
   2579   1.1.1.7  christos 	     comment below.  */
   2580       1.1  christos 	}
   2581       1.1  christos       else if (startswith (s->name, ".rela"))
   2582       1.1  christos 	{
   2583       1.1  christos 	  if (s->size != 0)
   2584       1.1  christos 	    {
   2585       1.1  christos 	      /* We use the reloc_count field as a counter if we need
   2586       1.1  christos 		 to copy relocs into the output file.  */
   2587       1.1  christos 	      s->reloc_count = 0;
   2588       1.1  christos 	    }
   2589       1.1  christos 	}
   2590       1.1  christos       else
   2591       1.1  christos 	{
   2592       1.1  christos 	  /* It's not one of our sections.  */
   2593       1.1  christos 	  continue;
   2594       1.1  christos 	}
   2595       1.1  christos 
   2596       1.1  christos       if (s->size == 0)
   2597       1.1  christos 	{
   2598       1.1  christos 	  /* If we don't need this section, strip it from the
   2599       1.1  christos 	     output file.  This is mostly to handle .rela.bss and
   2600       1.1  christos 	     .rela.plt.  We must create both sections in
   2601       1.1  christos 	     create_dynamic_sections, because they must be created
   2602       1.1  christos 	     before the linker maps input sections to output
   2603       1.1  christos 	     sections.  The linker does that before
   2604       1.1  christos 	     adjust_dynamic_symbol is called, and it is that
   2605       1.1  christos 	     function which decides whether anything needs to go
   2606       1.1  christos 	     into these sections.  */
   2607       1.1  christos 	  s->flags |= SEC_EXCLUDE;
   2608       1.1  christos 	  continue;
   2609       1.1  christos 	}
   2610       1.1  christos 
   2611       1.1  christos       if ((s->flags & SEC_HAS_CONTENTS) == 0)
   2612       1.1  christos 	continue;
   2613       1.1  christos 
   2614       1.1  christos       /* Allocate memory for the section contents.  Zero the memory
   2615       1.1  christos 	 for the benefit of .rela.plt, which has 4 unused entries
   2616       1.1  christos 	 at the beginning, and we don't want garbage.  */
   2617   1.1.1.7  christos       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
   2618   1.1.1.9  christos       if (s->contents == NULL)
   2619       1.1  christos 	return false;
   2620       1.1  christos       s->alloced = 1;
   2621   1.1.1.7  christos     }
   2622       1.1  christos 
   2623       1.1  christos   return _bfd_elf_add_dynamic_tags (output_bfd, info, true);
   2624       1.1  christos }
   2625       1.1  christos 
   2626       1.1  christos /* Return the base VMA address which should be subtracted from real addresses
   2628       1.1  christos    when resolving @dtpoff relocation.
   2629       1.1  christos    This is PT_TLS segment p_vaddr.  */
   2630       1.1  christos 
   2631       1.1  christos static bfd_vma
   2632       1.1  christos dtpoff_base (struct bfd_link_info *info)
   2633       1.1  christos {
   2634       1.1  christos   /* If tls_sec is NULL, we should have signalled an error already.  */
   2635       1.1  christos   if (elf_hash_table (info)->tls_sec == NULL)
   2636       1.1  christos     return 0;
   2637       1.1  christos   return elf_hash_table (info)->tls_sec->vma;
   2638       1.1  christos }
   2639       1.1  christos 
   2640       1.1  christos /* Return the relocation value for @tpoff relocation. */
   2641       1.1  christos 
   2642       1.1  christos static bfd_vma
   2643       1.1  christos tpoff (struct bfd_link_info *info, bfd_vma address)
   2644       1.1  christos {
   2645       1.1  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
   2646       1.1  christos 
   2647       1.1  christos   /* If tls_sec is NULL, we should have signalled an error already.  */
   2648       1.1  christos   if (htab->tls_sec == NULL)
   2649       1.1  christos     return 0;
   2650       1.1  christos 
   2651       1.1  christos   return (address - htab->tls_sec->vma);
   2652       1.1  christos }
   2653       1.1  christos 
   2654       1.1  christos /* Copy SIZE bits from FROM to TO at address ADDR.  */
   2655       1.1  christos 
   2656       1.1  christos static void
   2657       1.1  christos tilegx_copy_bits (bfd_byte *addr, int from, int to, int size)
   2658       1.1  christos {
   2659       1.1  christos   int i;
   2660       1.1  christos   for (i = 0; i < size; i++)
   2661       1.1  christos     {
   2662       1.1  christos       int from_byte = (from + i) / 8;
   2663       1.1  christos       int from_bit = (from + i) % 8;
   2664       1.1  christos       int to_byte = (to + i) / 8;
   2665       1.1  christos       int to_bit = (to + i) % 8;
   2666       1.1  christos       bfd_byte to_mask = 1 << to_bit;
   2667       1.1  christos       addr[to_byte] = (addr[to_byte] & ~to_mask)
   2668       1.1  christos 	| ((addr[from_byte] >> from_bit << to_bit) & to_mask);
   2669       1.1  christos     }
   2670       1.1  christos }
   2671       1.1  christos 
   2672       1.1  christos /* Replace the MASK bits in ADDR with those in INSN, for the next
   2673       1.1  christos    TILEGX_BUNDLE_SIZE_IN_BYTES bytes.  */
   2674       1.1  christos 
   2675       1.1  christos static void
   2676       1.1  christos tilegx_replace_insn (bfd_byte *addr, const bfd_byte *mask,
   2677       1.1  christos 		     const bfd_byte *insn)
   2678       1.1  christos {
   2679       1.1  christos   int i;
   2680       1.1  christos   for (i = 0; i < TILEGX_BUNDLE_SIZE_IN_BYTES; i++)
   2681       1.1  christos     {
   2682       1.1  christos       addr[i] = (addr[i] & ~mask[i]) | (insn[i] & mask[i]);
   2683       1.1  christos     }
   2684       1.1  christos }
   2685       1.1  christos 
   2686       1.1  christos /* Mask to extract the bits corresponding to an instruction in a
   2687       1.1  christos    specific pipe of a bundle.  */
   2688       1.1  christos static const bfd_byte insn_mask_X1[] = {
   2689       1.1  christos   0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x3f
   2690       1.1  christos };
   2691       1.1  christos 
   2692   1.1.1.2  christos /* Mask to extract the bits corresponding to an instruction in a
   2693       1.1  christos    specific pipe of a bundle, minus the destination operand and the
   2694       1.1  christos    first source operand.  */
   2695       1.1  christos static const bfd_byte insn_mask_X0_no_dest_no_srca[] = {
   2696       1.1  christos   0x00, 0xf0, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00
   2697       1.1  christos };
   2698       1.1  christos 
   2699       1.1  christos static const bfd_byte insn_mask_X1_no_dest_no_srca[] = {
   2700       1.1  christos   0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x3f
   2701       1.1  christos };
   2702       1.1  christos 
   2703       1.1  christos static const bfd_byte insn_mask_Y0_no_dest_no_srca[] = {
   2704       1.1  christos   0x00, 0xf0, 0x0f, 0x78, 0x00, 0x00, 0x00, 0x00
   2705       1.1  christos };
   2706       1.1  christos static const bfd_byte insn_mask_Y1_no_dest_no_srca[] = {
   2707       1.1  christos   0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x3c
   2708       1.1  christos };
   2709       1.1  christos 
   2710       1.1  christos /* Mask to extract the bits corresponding to an instruction in a
   2711       1.1  christos    specific pipe of a bundle, minus the register operands.  */
   2712       1.1  christos static const bfd_byte insn_mask_X0_no_operand[] = {
   2713       1.1  christos   0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00
   2714       1.1  christos };
   2715       1.1  christos 
   2716       1.1  christos static const bfd_byte insn_mask_X1_no_operand[] = {
   2717       1.1  christos   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x3f
   2718       1.1  christos };
   2719       1.1  christos 
   2720       1.1  christos static const bfd_byte insn_mask_Y0_no_operand[] = {
   2721       1.1  christos   0x00, 0x00, 0x0c, 0x78, 0x00, 0x00, 0x00, 0x00
   2722       1.1  christos };
   2723       1.1  christos 
   2724       1.1  christos static const bfd_byte insn_mask_Y1_no_operand[] = {
   2725       1.1  christos   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x3c
   2726       1.1  christos };
   2727       1.1  christos 
   2728       1.1  christos /* Various instructions synthesized to support tls references.  */
   2729       1.1  christos 
   2730       1.1  christos /* ld r0, r0 in the X1 pipe, used for tls ie.  */
   2731       1.1  christos static const bfd_byte insn_tls_ie_ld_X1[] = {
   2732       1.1  christos   0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0x6a, 0x28
   2733       1.1  christos };
   2734       1.1  christos 
   2735       1.1  christos /* ld4s r0, r0 in the X1 pipe, used for tls ie.  */
   2736       1.1  christos static const bfd_byte insn_tls_ie_ld4s_X1[] = {
   2737       1.1  christos   0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x6a, 0x28
   2738       1.1  christos };
   2739       1.1  christos 
   2740       1.1  christos /* add r0, r0, tp in various pipes, used for tls ie.  */
   2741       1.1  christos static const bfd_byte insn_tls_ie_add_X0X1[] = {
   2742       1.1  christos   0x00, 0x50, 0x0f, 0x50, 0x00, 0xa8, 0x07, 0x28
   2743       1.1  christos };
   2744       1.1  christos static const bfd_byte insn_tls_ie_add_Y0Y1[] = {
   2745       1.1  christos   0x00, 0x50, 0x27, 0x2c, 0x00, 0xa8, 0x13, 0x9a
   2746       1.1  christos };
   2747       1.1  christos 
   2748       1.1  christos /* addx r0, r0, tp in various pipes, used for tls ie.  */
   2749       1.1  christos static const bfd_byte insn_tls_ie_addx_X0X1[] = {
   2750       1.1  christos   0x00, 0x50, 0x0b, 0x50, 0x00, 0xa8, 0x05, 0x28
   2751       1.1  christos };
   2752       1.1  christos static const bfd_byte insn_tls_ie_addx_Y0Y1[] = {
   2753       1.1  christos   0x00, 0x50, 0x03, 0x2c, 0x00, 0xa8, 0x01, 0x9a
   2754       1.1  christos };
   2755       1.1  christos 
   2756       1.1  christos /* move r0, r0 in various pipes, used for tls gd.  */
   2757       1.1  christos static const bfd_byte insn_tls_gd_add_X0X1[] = {
   2758       1.1  christos   0x00, 0xf0, 0x07, 0x51, 0x00, 0xf8, 0x3b, 0x28
   2759       1.1  christos };
   2760       1.1  christos static const bfd_byte insn_tls_gd_add_Y0Y1[] = {
   2761       1.1  christos   0x00, 0xf0, 0x0b, 0x54, 0x00, 0xf8, 0x05, 0xae
   2762       1.1  christos };
   2763       1.1  christos 
   2764       1.1  christos static const bfd_byte *insn_move_X0X1 = insn_tls_gd_add_X0X1;
   2765       1.1  christos static const bfd_byte *insn_move_Y0Y1 = insn_tls_gd_add_Y0Y1;
   2766       1.1  christos 
   2767       1.1  christos static const bfd_byte *insn_add_X0X1 = insn_tls_ie_add_X0X1;
   2768       1.1  christos static const bfd_byte *insn_add_Y0Y1 = insn_tls_ie_add_Y0Y1;
   2769       1.1  christos 
   2770       1.1  christos static const bfd_byte *insn_addx_X0X1 = insn_tls_ie_addx_X0X1;
   2771       1.1  christos static const bfd_byte *insn_addx_Y0Y1 = insn_tls_ie_addx_Y0Y1;
   2772       1.1  christos 
   2773       1.1  christos /* Relocate an TILEGX ELF section.
   2774       1.1  christos 
   2775       1.1  christos    The RELOCATE_SECTION function is called by the new ELF backend linker
   2776       1.1  christos    to handle the relocations for a section.
   2777       1.1  christos 
   2778       1.1  christos    The relocs are always passed as Rela structures.
   2779       1.1  christos 
   2780       1.1  christos    This function is responsible for adjusting the section contents as
   2781       1.1  christos    necessary, and (if generating a relocatable output file) adjusting
   2782       1.1  christos    the reloc addend as necessary.
   2783       1.1  christos 
   2784       1.1  christos    This function does not have to worry about setting the reloc
   2785       1.1  christos    address or the reloc symbol index.
   2786       1.1  christos 
   2787       1.1  christos    LOCAL_SYMS is a pointer to the swapped in local symbols.
   2788       1.1  christos 
   2789       1.1  christos    LOCAL_SECTIONS is an array giving the section in the input file
   2790       1.1  christos    corresponding to the st_shndx field of each local symbol.
   2791       1.1  christos 
   2792       1.1  christos    The global hash table entry for the global symbols can be found
   2793       1.1  christos    via elf_sym_hashes (input_bfd).
   2794       1.1  christos 
   2795       1.1  christos    When generating relocatable output, this function must handle
   2796       1.1  christos    STB_LOCAL/STT_SECTION symbols specially.  The output symbol is
   2797       1.1  christos    going to be the section symbol corresponding to the output
   2798   1.1.1.7  christos    section, which means that the addend must be adjusted
   2799       1.1  christos    accordingly.  */
   2800       1.1  christos 
   2801       1.1  christos int
   2802       1.1  christos tilegx_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
   2803       1.1  christos 			     bfd *input_bfd, asection *input_section,
   2804       1.1  christos 			     bfd_byte *contents, Elf_Internal_Rela *relocs,
   2805       1.1  christos 			     Elf_Internal_Sym *local_syms,
   2806       1.1  christos 			     asection **local_sections)
   2807       1.1  christos {
   2808       1.1  christos   struct tilegx_elf_link_hash_table *htab;
   2809       1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   2810       1.1  christos   struct elf_link_hash_entry **sym_hashes;
   2811       1.1  christos   bfd_vma *local_got_offsets;
   2812       1.1  christos   bfd_vma got_base;
   2813       1.1  christos   asection *sreloc;
   2814       1.1  christos   Elf_Internal_Rela *rel;
   2815       1.1  christos   Elf_Internal_Rela *relend;
   2816       1.1  christos   int num_relocs;
   2817       1.1  christos 
   2818       1.1  christos   htab = tilegx_elf_hash_table (info);
   2819       1.1  christos   BFD_ASSERT (htab != NULL);
   2820       1.1  christos   symtab_hdr = &elf_symtab_hdr (input_bfd);
   2821       1.1  christos   sym_hashes = elf_sym_hashes (input_bfd);
   2822       1.1  christos   local_got_offsets = elf_local_got_offsets (input_bfd);
   2823       1.1  christos 
   2824       1.1  christos   if (elf_hash_table (info)->hgot == NULL)
   2825       1.1  christos     got_base = 0;
   2826       1.1  christos   else
   2827       1.1  christos     got_base = elf_hash_table (info)->hgot->root.u.def.value;
   2828       1.1  christos 
   2829       1.1  christos   sreloc = elf_section_data (input_section)->sreloc;
   2830       1.1  christos 
   2831       1.1  christos   rel = relocs;
   2832       1.1  christos   num_relocs = input_section->reloc_count;
   2833       1.1  christos   relend = relocs + num_relocs;
   2834   1.1.1.7  christos   for (; rel < relend; rel++)
   2835       1.1  christos     {
   2836       1.1  christos       int r_type, tls_type;
   2837       1.1  christos       bool is_tls_iele, is_tls_le;
   2838       1.1  christos       reloc_howto_type *howto;
   2839       1.1  christos       unsigned long r_symndx;
   2840       1.1  christos       struct elf_link_hash_entry *h;
   2841       1.1  christos       Elf_Internal_Sym *sym;
   2842       1.1  christos       tilegx_create_func create_func;
   2843       1.1  christos       asection *sec;
   2844       1.1  christos       bfd_vma relocation;
   2845   1.1.1.7  christos       bfd_reloc_status_type r;
   2846   1.1.1.7  christos       const char *name;
   2847   1.1.1.7  christos       bfd_vma off;
   2848       1.1  christos       bool is_plt = false;
   2849       1.1  christos       bool resolved_to_zero;
   2850       1.1  christos       bool unresolved_reloc;
   2851       1.1  christos 
   2852       1.1  christos       r_type = TILEGX_ELF_R_TYPE (rel->r_info);
   2853       1.1  christos       if (r_type == R_TILEGX_GNU_VTINHERIT
   2854       1.1  christos 	  || r_type == R_TILEGX_GNU_VTENTRY)
   2855   1.1.1.4  christos 	continue;
   2856       1.1  christos 
   2857       1.1  christos       if ((unsigned int)r_type >= ARRAY_SIZE (tilegx_elf_howto_table))
   2858       1.1  christos 	return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
   2859       1.1  christos 
   2860       1.1  christos       howto = tilegx_elf_howto_table + r_type;
   2861       1.1  christos 
   2862       1.1  christos       /* This is a final link.  */
   2863       1.1  christos       r_symndx = TILEGX_ELF_R_SYMNDX (htab, rel->r_info);
   2864   1.1.1.7  christos       h = NULL;
   2865       1.1  christos       sym = NULL;
   2866       1.1  christos       sec = NULL;
   2867       1.1  christos       unresolved_reloc = false;
   2868       1.1  christos       if (r_symndx < symtab_hdr->sh_info)
   2869       1.1  christos 	{
   2870       1.1  christos 	  sym = local_syms + r_symndx;
   2871       1.1  christos 	  sec = local_sections[r_symndx];
   2872       1.1  christos 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
   2873   1.1.1.7  christos 	}
   2874   1.1.1.7  christos       else
   2875       1.1  christos 	{
   2876       1.1  christos 	  bool warned ATTRIBUTE_UNUSED;
   2877       1.1  christos 	  bool ignored ATTRIBUTE_UNUSED;
   2878       1.1  christos 
   2879   1.1.1.2  christos 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
   2880       1.1  christos 				   r_symndx, symtab_hdr, sym_hashes,
   2881       1.1  christos 				   h, sec, relocation,
   2882       1.1  christos 				   unresolved_reloc, warned, ignored);
   2883       1.1  christos 	  if (warned)
   2884       1.1  christos 	    {
   2885       1.1  christos 	      /* To avoid generating warning messages about truncated
   2886       1.1  christos 		 relocations, set the relocation's address to be the same as
   2887       1.1  christos 		 the start of this section.  */
   2888       1.1  christos 	      if (input_section->output_section != NULL)
   2889       1.1  christos 		relocation = input_section->output_section->vma;
   2890       1.1  christos 	      else
   2891       1.1  christos 		relocation = 0;
   2892       1.1  christos 	    }
   2893       1.1  christos 	}
   2894  1.1.1.10  christos 
   2895  1.1.1.10  christos       if (sec != NULL && discarded_section (sec))
   2896       1.1  christos 	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   2897   1.1.1.2  christos 					 rel, 1, relend, R_TILEGX_NONE,
   2898       1.1  christos 					 howto, 0, contents);
   2899       1.1  christos 
   2900       1.1  christos       if (bfd_link_relocatable (info))
   2901       1.1  christos 	continue;
   2902       1.1  christos 
   2903       1.1  christos       if (h != NULL)
   2904       1.1  christos 	name = h->root.root.string;
   2905       1.1  christos       else
   2906       1.1  christos 	{
   2907   1.1.1.6  christos 	  name = (bfd_elf_string_from_elf_section
   2908       1.1  christos 		  (input_bfd, symtab_hdr->sh_link, sym->st_name));
   2909       1.1  christos 	  if (name == NULL || *name == '\0')
   2910       1.1  christos 	    name = bfd_section_name (sec);
   2911       1.1  christos 	}
   2912       1.1  christos 
   2913       1.1  christos       switch (r_type)
   2914       1.1  christos 	{
   2915       1.1  christos 	case R_TILEGX_TLS_GD_CALL:
   2916       1.1  christos 	case R_TILEGX_IMM8_X0_TLS_GD_ADD:
   2917       1.1  christos 	case R_TILEGX_IMM8_Y0_TLS_GD_ADD:
   2918       1.1  christos 	case R_TILEGX_IMM8_X1_TLS_GD_ADD:
   2919       1.1  christos 	case R_TILEGX_IMM8_Y1_TLS_GD_ADD:
   2920       1.1  christos 	case R_TILEGX_IMM8_X0_TLS_ADD:
   2921       1.1  christos 	case R_TILEGX_IMM8_Y0_TLS_ADD:
   2922       1.1  christos 	case R_TILEGX_IMM8_X1_TLS_ADD:
   2923       1.1  christos 	case R_TILEGX_IMM8_Y1_TLS_ADD:
   2924       1.1  christos 	  tls_type = GOT_UNKNOWN;
   2925       1.1  christos 	  if (h == NULL && local_got_offsets)
   2926       1.1  christos 	    tls_type =
   2927       1.1  christos 	      _bfd_tilegx_elf_local_got_tls_type (input_bfd) [r_symndx];
   2928   1.1.1.4  christos 	  else if (h != NULL)
   2929       1.1  christos 	    tls_type = tilegx_elf_hash_entry(h)->tls_type;
   2930   1.1.1.4  christos 
   2931       1.1  christos 	  is_tls_iele = (bfd_link_executable (info) || tls_type == GOT_TLS_IE);
   2932       1.1  christos 	  is_tls_le = is_tls_iele && (!input_section->sec_flg0
   2933       1.1  christos 				      && bfd_link_executable (info)
   2934       1.1  christos 				      && (h == NULL || h->dynindx == -1));
   2935       1.1  christos 
   2936       1.1  christos 	  if (r_type == R_TILEGX_TLS_GD_CALL)
   2937       1.1  christos 	    {
   2938       1.1  christos 	      if (is_tls_le)
   2939       1.1  christos 		{
   2940       1.1  christos 		  /* GD -> LE */
   2941       1.1  christos 		  tilegx_replace_insn (contents + rel->r_offset,
   2942       1.1  christos 				       insn_mask_X1, insn_move_X0X1);
   2943       1.1  christos 		  continue;
   2944       1.1  christos 		}
   2945       1.1  christos 	      else if (is_tls_iele)
   2946       1.1  christos 		{
   2947       1.1  christos 		  /* GD -> IE */
   2948       1.1  christos 		  if (ABI_64_P (output_bfd))
   2949       1.1  christos 		    tilegx_replace_insn (contents + rel->r_offset,
   2950       1.1  christos 					 insn_mask_X1, insn_tls_ie_ld_X1);
   2951       1.1  christos 		  else
   2952       1.1  christos 		    tilegx_replace_insn (contents + rel->r_offset,
   2953       1.1  christos 					 insn_mask_X1, insn_tls_ie_ld4s_X1);
   2954       1.1  christos 		  continue;
   2955       1.1  christos 		}
   2956   1.1.1.7  christos 
   2957   1.1.1.7  christos 	      /* GD -> GD */
   2958       1.1  christos 	      h = (struct elf_link_hash_entry *)
   2959       1.1  christos 		bfd_link_hash_lookup (info->hash, "__tls_get_addr", false,
   2960       1.1  christos 				      false, true);
   2961       1.1  christos 	      BFD_ASSERT (h != NULL);
   2962       1.1  christos 	      r_type = R_TILEGX_JUMPOFF_X1_PLT;
   2963       1.1  christos 	      howto = tilegx_elf_howto_table + r_type;
   2964       1.1  christos 	    }
   2965       1.1  christos 	  else if (r_type == R_TILEGX_IMM8_X0_TLS_ADD
   2966       1.1  christos 		   || r_type ==  R_TILEGX_IMM8_X1_TLS_ADD
   2967   1.1.1.7  christos 		   || r_type ==  R_TILEGX_IMM8_Y0_TLS_ADD
   2968       1.1  christos 		   || r_type ==  R_TILEGX_IMM8_Y1_TLS_ADD)
   2969       1.1  christos 	    {
   2970   1.1.1.7  christos 	      bool is_pipe0 =
   2971       1.1  christos 		(r_type == R_TILEGX_IMM8_X0_TLS_ADD
   2972       1.1  christos 		 || r_type ==  R_TILEGX_IMM8_Y0_TLS_ADD);
   2973       1.1  christos 	      bool is_X0X1 =
   2974       1.1  christos 		(r_type == R_TILEGX_IMM8_X0_TLS_ADD
   2975       1.1  christos 		 || r_type ==  R_TILEGX_IMM8_X1_TLS_ADD);
   2976       1.1  christos 	      int dest_begin = is_pipe0 ? 0 : 31;
   2977       1.1  christos 	      int src_begin;
   2978       1.1  christos 	      const bfd_byte *insn;
   2979       1.1  christos 	      const bfd_byte *mask = NULL;
   2980       1.1  christos 
   2981       1.1  christos 	      if (is_tls_le)
   2982       1.1  christos 		{
   2983       1.1  christos 		  /* 1. copy dest operand into the first source operand.
   2984       1.1  christos 		     2. change the opcode to "move".  */
   2985       1.1  christos 		  src_begin = is_pipe0 ? 6 : 37;
   2986       1.1  christos 		  insn = is_X0X1 ? insn_move_X0X1 : insn_move_Y0Y1;
   2987       1.1  christos 
   2988       1.1  christos 		  switch (r_type)
   2989       1.1  christos 		    {
   2990       1.1  christos 		    case R_TILEGX_IMM8_X0_TLS_ADD:
   2991       1.1  christos 		      mask = insn_mask_X0_no_dest_no_srca;
   2992       1.1  christos 		      break;
   2993       1.1  christos 		    case R_TILEGX_IMM8_X1_TLS_ADD:
   2994       1.1  christos 		      mask = insn_mask_X1_no_dest_no_srca;
   2995       1.1  christos 		      break;
   2996       1.1  christos 		    case R_TILEGX_IMM8_Y0_TLS_ADD:
   2997       1.1  christos 		      mask = insn_mask_Y0_no_dest_no_srca;
   2998       1.1  christos 		      break;
   2999       1.1  christos 		    case R_TILEGX_IMM8_Y1_TLS_ADD:
   3000       1.1  christos 		      mask = insn_mask_Y1_no_dest_no_srca;
   3001       1.1  christos 		      break;
   3002       1.1  christos 		    }
   3003       1.1  christos 		}
   3004       1.1  christos 	      else
   3005       1.1  christos 		{
   3006       1.1  christos 		  /* 1. copy dest operand into the second source operand.
   3007       1.1  christos 		     2. change the opcode to "add".  */
   3008       1.1  christos 		  src_begin = is_pipe0 ? 12 : 43;
   3009       1.1  christos 		  if (ABI_64_P (output_bfd))
   3010       1.1  christos 		    insn = is_X0X1 ? insn_add_X0X1 : insn_add_Y0Y1;
   3011       1.1  christos 		  else
   3012       1.1  christos 		    insn = is_X0X1 ? insn_addx_X0X1 : insn_addx_Y0Y1;
   3013       1.1  christos 
   3014       1.1  christos 		  switch (r_type)
   3015       1.1  christos 		    {
   3016       1.1  christos 		    case R_TILEGX_IMM8_X0_TLS_ADD:
   3017       1.1  christos 		      mask = insn_mask_X0_no_operand;
   3018       1.1  christos 		      break;
   3019       1.1  christos 		    case R_TILEGX_IMM8_X1_TLS_ADD:
   3020       1.1  christos 		      mask = insn_mask_X1_no_operand;
   3021       1.1  christos 		      break;
   3022       1.1  christos 		    case R_TILEGX_IMM8_Y0_TLS_ADD:
   3023       1.1  christos 		      mask = insn_mask_Y0_no_operand;
   3024       1.1  christos 		      break;
   3025       1.1  christos 		    case R_TILEGX_IMM8_Y1_TLS_ADD:
   3026       1.1  christos 		      mask = insn_mask_Y1_no_operand;
   3027       1.1  christos 		      break;
   3028       1.1  christos 		    }
   3029       1.1  christos 		}
   3030       1.1  christos 
   3031       1.1  christos 	      tilegx_copy_bits (contents + rel->r_offset, dest_begin,
   3032       1.1  christos 				src_begin, 6);
   3033       1.1  christos 	      tilegx_replace_insn (contents  + rel->r_offset, mask, insn);
   3034       1.1  christos 
   3035       1.1  christos 	      continue;
   3036       1.1  christos 	    }
   3037       1.1  christos 	  else
   3038   1.1.1.7  christos 	    {
   3039       1.1  christos 	      const bfd_byte *mask = NULL;
   3040       1.1  christos 	      const bfd_byte *add_insn = NULL;
   3041       1.1  christos 	      bool is_64bit = ABI_64_P (output_bfd);
   3042       1.1  christos 
   3043       1.1  christos 	      switch (r_type)
   3044       1.1  christos 		{
   3045       1.1  christos 		case R_TILEGX_IMM8_X0_TLS_GD_ADD:
   3046       1.1  christos 		  add_insn = is_tls_iele
   3047       1.1  christos 		    ? (is_64bit ? insn_tls_ie_add_X0X1 : insn_tls_ie_addx_X0X1)
   3048       1.1  christos 		    : insn_tls_gd_add_X0X1;
   3049       1.1  christos 		  mask = insn_mask_X0_no_dest_no_srca;
   3050       1.1  christos 		  break;
   3051       1.1  christos 		case R_TILEGX_IMM8_X1_TLS_GD_ADD:
   3052       1.1  christos 		  add_insn = is_tls_iele
   3053       1.1  christos 		    ? (is_64bit ? insn_tls_ie_add_X0X1 : insn_tls_ie_addx_X0X1)
   3054       1.1  christos 		    : insn_tls_gd_add_X0X1;
   3055       1.1  christos 		  mask = insn_mask_X1_no_dest_no_srca;
   3056       1.1  christos 		  break;
   3057       1.1  christos 		case R_TILEGX_IMM8_Y0_TLS_GD_ADD:
   3058       1.1  christos 		  add_insn = is_tls_iele
   3059       1.1  christos 		    ? (is_64bit ? insn_tls_ie_add_Y0Y1 : insn_tls_ie_addx_Y0Y1)
   3060       1.1  christos 		    : insn_tls_gd_add_Y0Y1;
   3061       1.1  christos 		  mask = insn_mask_Y0_no_dest_no_srca;
   3062       1.1  christos 		  break;
   3063       1.1  christos 		case R_TILEGX_IMM8_Y1_TLS_GD_ADD:
   3064       1.1  christos 		  add_insn = is_tls_iele
   3065       1.1  christos 		    ? (is_64bit ? insn_tls_ie_add_Y0Y1 : insn_tls_ie_addx_Y0Y1)
   3066       1.1  christos 		    : insn_tls_gd_add_Y0Y1;
   3067       1.1  christos 		  mask = insn_mask_Y1_no_dest_no_srca;
   3068       1.1  christos 		  break;
   3069       1.1  christos 		}
   3070       1.1  christos 
   3071       1.1  christos 	      tilegx_replace_insn (contents + rel->r_offset, mask, add_insn);
   3072       1.1  christos 
   3073       1.1  christos 	      continue;
   3074       1.1  christos 	    }
   3075   1.1.1.4  christos 	  break;
   3076       1.1  christos 	case R_TILEGX_TLS_IE_LOAD:
   3077       1.1  christos 	  if (!input_section->sec_flg0
   3078       1.1  christos 	      && bfd_link_executable (info)
   3079       1.1  christos 	      && (h == NULL || h->dynindx == -1))
   3080       1.1  christos 	    {
   3081       1.1  christos 	      /* IE -> LE */
   3082       1.1  christos 	      tilegx_replace_insn (contents + rel->r_offset,
   3083       1.1  christos 				   insn_mask_X1_no_dest_no_srca,
   3084       1.1  christos 				   insn_move_X0X1);
   3085       1.1  christos 	    }
   3086       1.1  christos 	  else
   3087       1.1  christos 	    {
   3088       1.1  christos 	      /* IE -> IE */
   3089       1.1  christos 	      if (ABI_64_P (output_bfd))
   3090       1.1  christos 		tilegx_replace_insn (contents + rel->r_offset,
   3091       1.1  christos 				     insn_mask_X1_no_dest_no_srca,
   3092       1.1  christos 				     insn_tls_ie_ld_X1);
   3093       1.1  christos 	      else
   3094       1.1  christos 		tilegx_replace_insn (contents + rel->r_offset,
   3095       1.1  christos 				     insn_mask_X1_no_dest_no_srca,
   3096       1.1  christos 				     insn_tls_ie_ld4s_X1);
   3097       1.1  christos 	    }
   3098       1.1  christos 	  continue;
   3099       1.1  christos 	  break;
   3100       1.1  christos 	default:
   3101   1.1.1.4  christos 	  break;
   3102   1.1.1.4  christos 	}
   3103   1.1.1.4  christos 
   3104       1.1  christos       resolved_to_zero = (h != NULL
   3105       1.1  christos 			  && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
   3106       1.1  christos 
   3107       1.1  christos       switch (r_type)
   3108       1.1  christos 	{
   3109       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_GOT:
   3110       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_GOT:
   3111       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_GOT:
   3112       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_GOT:
   3113       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_GOT:
   3114       1.1  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_GOT:
   3115       1.1  christos 	  /* Relocation is to the entry for this symbol in the global
   3116       1.1  christos 	     offset table.  */
   3117       1.1  christos 	  if (htab->elf.sgot == NULL)
   3118       1.1  christos 	    abort ();
   3119   1.1.1.7  christos 
   3120       1.1  christos 	  if (h != NULL)
   3121       1.1  christos 	    {
   3122       1.1  christos 	      bool dyn;
   3123       1.1  christos 
   3124       1.1  christos 	      off = h->got.offset;
   3125   1.1.1.2  christos 	      BFD_ASSERT (off != (bfd_vma) -1);
   3126   1.1.1.2  christos 	      dyn = elf_hash_table (info)->dynamic_sections_created;
   3127   1.1.1.2  christos 
   3128   1.1.1.2  christos 	      if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
   3129       1.1  christos 						     bfd_link_pic (info),
   3130       1.1  christos 						     h)
   3131       1.1  christos 		  || (bfd_link_pic (info)
   3132       1.1  christos 		      && SYMBOL_REFERENCES_LOCAL (info, h)))
   3133       1.1  christos 		{
   3134       1.1  christos 		  /* This is actually a static link, or it is a
   3135       1.1  christos 		     -Bsymbolic link and the symbol is defined
   3136       1.1  christos 		     locally, or the symbol was forced to be local
   3137       1.1  christos 		     because of a version file.  We must initialize
   3138       1.1  christos 		     this entry in the global offset table.  Since the
   3139       1.1  christos 		     offset must always be a multiple
   3140       1.1  christos 		     of 8 for 64-bit, we use the least significant bit
   3141       1.1  christos 		     to record whether we have initialized it already.
   3142       1.1  christos 
   3143       1.1  christos 		     When doing a dynamic link, we create a .rela.got
   3144       1.1  christos 		     relocation entry to initialize the value.  This
   3145       1.1  christos 		     is done in the finish_dynamic_symbol routine.  */
   3146       1.1  christos 		  if ((off & 1) != 0)
   3147       1.1  christos 		    off &= ~1;
   3148       1.1  christos 		  else
   3149       1.1  christos 		    {
   3150       1.1  christos 		      TILEGX_ELF_PUT_WORD (htab, output_bfd, relocation,
   3151       1.1  christos 					   htab->elf.sgot->contents + off);
   3152       1.1  christos 		      h->got.offset |= 1;
   3153   1.1.1.7  christos 		    }
   3154       1.1  christos 		}
   3155       1.1  christos 	      else
   3156       1.1  christos 		unresolved_reloc = false;
   3157       1.1  christos 	    }
   3158       1.1  christos 	  else
   3159       1.1  christos 	    {
   3160       1.1  christos 	      BFD_ASSERT (local_got_offsets != NULL
   3161       1.1  christos 			  && local_got_offsets[r_symndx] != (bfd_vma) -1);
   3162       1.1  christos 
   3163   1.1.1.4  christos 	      off = local_got_offsets[r_symndx];
   3164       1.1  christos 
   3165       1.1  christos 	      /* The offset must always be a multiple of 8 on 64-bit.
   3166       1.1  christos 		 We use the least significant bit to record
   3167       1.1  christos 		 whether we have already processed this entry.  */
   3168       1.1  christos 	      if ((off & 1) != 0)
   3169   1.1.1.2  christos 		off &= ~1;
   3170       1.1  christos 	      else
   3171       1.1  christos 		{
   3172       1.1  christos 		  if (bfd_link_pic (info))
   3173       1.1  christos 		    {
   3174       1.1  christos 		      asection *s;
   3175       1.1  christos 		      Elf_Internal_Rela outrel;
   3176       1.1  christos 
   3177       1.1  christos 		      /* We need to generate a R_TILEGX_RELATIVE reloc
   3178       1.1  christos 			 for the dynamic linker.  */
   3179       1.1  christos 		      s = htab->elf.srelgot;
   3180       1.1  christos 		      BFD_ASSERT (s != NULL);
   3181       1.1  christos 
   3182       1.1  christos 		      outrel.r_offset = (htab->elf.sgot->output_section->vma
   3183       1.1  christos 					 + htab->elf.sgot->output_offset
   3184       1.1  christos 					 + off);
   3185       1.1  christos 		      outrel.r_info =
   3186       1.1  christos 			TILEGX_ELF_R_INFO (htab, NULL, 0, R_TILEGX_RELATIVE);
   3187       1.1  christos 		      outrel.r_addend = relocation;
   3188       1.1  christos 		      relocation = 0;
   3189       1.1  christos 		      tilegx_elf_append_rela (output_bfd, s, &outrel);
   3190       1.1  christos 		    }
   3191       1.1  christos 
   3192       1.1  christos 		  TILEGX_ELF_PUT_WORD (htab, output_bfd, relocation,
   3193       1.1  christos 				       htab->elf.sgot->contents + off);
   3194       1.1  christos 		  local_got_offsets[r_symndx] |= 1;
   3195       1.1  christos 		}
   3196       1.1  christos 	    }
   3197   1.1.1.4  christos 	  relocation = off - got_base;
   3198   1.1.1.2  christos 	  break;
   3199   1.1.1.2  christos 
   3200   1.1.1.2  christos 	case R_TILEGX_JUMPOFF_X1_PLT:
   3201   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
   3202   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
   3203   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
   3204   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
   3205   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
   3206   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
   3207   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW3_PLT_PCREL:
   3208   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW3_PLT_PCREL:
   3209   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
   3210   1.1.1.2  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
   3211   1.1.1.2  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
   3212       1.1  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
   3213       1.1  christos 	case R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
   3214   1.1.1.4  christos 	case R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
   3215       1.1  christos 	  /* Relocation is to the entry for this symbol in the
   3216       1.1  christos 	     procedure linkage table.  */
   3217       1.1  christos 	  BFD_ASSERT (h != NULL);
   3218       1.1  christos 
   3219       1.1  christos 	  if (h->plt.offset == (bfd_vma) -1 || htab->elf.splt == NULL)
   3220       1.1  christos 	    {
   3221       1.1  christos 	      /* We didn't make a PLT entry for this symbol.  This
   3222       1.1  christos 		 happens when statically linking PIC code, or when
   3223       1.1  christos 		 using -Bsymbolic.  */
   3224       1.1  christos 	      break;
   3225       1.1  christos 	    }
   3226       1.1  christos 
   3227   1.1.1.7  christos 	  relocation = (htab->elf.splt->output_section->vma
   3228       1.1  christos 			+ htab->elf.splt->output_offset
   3229       1.1  christos 			+ h->plt.offset);
   3230   1.1.1.4  christos 	  unresolved_reloc = false;
   3231   1.1.1.4  christos 	  break;
   3232   1.1.1.4  christos 
   3233   1.1.1.4  christos 	case R_TILEGX_64_PCREL:
   3234       1.1  christos 	case R_TILEGX_32_PCREL:
   3235       1.1  christos 	case R_TILEGX_16_PCREL:
   3236       1.1  christos 	case R_TILEGX_8_PCREL:
   3237       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_PCREL:
   3238       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_PCREL:
   3239       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_PCREL:
   3240       1.1  christos 	case R_TILEGX_IMM16_X1_HW1_PCREL:
   3241       1.1  christos 	case R_TILEGX_IMM16_X0_HW2_PCREL:
   3242       1.1  christos 	case R_TILEGX_IMM16_X1_HW2_PCREL:
   3243       1.1  christos 	case R_TILEGX_IMM16_X0_HW3_PCREL:
   3244       1.1  christos 	case R_TILEGX_IMM16_X1_HW3_PCREL:
   3245       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
   3246       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
   3247       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
   3248       1.1  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
   3249       1.1  christos 	case R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
   3250       1.1  christos 	case R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
   3251       1.1  christos 	  if (h != NULL
   3252   1.1.1.4  christos 	      && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
   3253   1.1.1.4  christos 	    break;
   3254   1.1.1.4  christos 	  /* Fall through.  */
   3255   1.1.1.4  christos 	case R_TILEGX_64:
   3256       1.1  christos 	case R_TILEGX_32:
   3257       1.1  christos 	case R_TILEGX_16:
   3258       1.1  christos 	case R_TILEGX_8:
   3259       1.1  christos 	case R_TILEGX_HW0:
   3260       1.1  christos 	case R_TILEGX_HW1:
   3261       1.1  christos 	case R_TILEGX_HW2:
   3262       1.1  christos 	case R_TILEGX_HW3:
   3263   1.1.1.4  christos 	case R_TILEGX_HW0_LAST:
   3264   1.1.1.4  christos 	case R_TILEGX_HW1_LAST:
   3265   1.1.1.4  christos 	case R_TILEGX_HW2_LAST:
   3266   1.1.1.4  christos 	case R_TILEGX_COPY:
   3267   1.1.1.4  christos 	case R_TILEGX_GLOB_DAT:
   3268   1.1.1.4  christos 	case R_TILEGX_JMP_SLOT:
   3269   1.1.1.4  christos 	case R_TILEGX_RELATIVE:
   3270   1.1.1.4  christos 	case R_TILEGX_BROFF_X1:
   3271   1.1.1.4  christos 	case R_TILEGX_JUMPOFF_X1:
   3272   1.1.1.4  christos 	case R_TILEGX_IMM8_X0:
   3273   1.1.1.4  christos 	case R_TILEGX_IMM8_Y0:
   3274   1.1.1.4  christos 	case R_TILEGX_IMM8_X1:
   3275   1.1.1.4  christos 	case R_TILEGX_IMM8_Y1:
   3276   1.1.1.4  christos 	case R_TILEGX_DEST_IMM8_X1:
   3277   1.1.1.4  christos 	case R_TILEGX_MT_IMM14_X1:
   3278   1.1.1.4  christos 	case R_TILEGX_MF_IMM14_X1:
   3279   1.1.1.4  christos 	case R_TILEGX_MMSTART_X0:
   3280   1.1.1.4  christos 	case R_TILEGX_MMEND_X0:
   3281   1.1.1.4  christos 	case R_TILEGX_SHAMT_X0:
   3282       1.1  christos 	case R_TILEGX_SHAMT_X1:
   3283       1.1  christos 	case R_TILEGX_SHAMT_Y0:
   3284       1.1  christos 	case R_TILEGX_SHAMT_Y1:
   3285       1.1  christos 	case R_TILEGX_IMM16_X0_HW0:
   3286       1.1  christos 	case R_TILEGX_IMM16_X1_HW0:
   3287       1.1  christos 	case R_TILEGX_IMM16_X0_HW1:
   3288       1.1  christos 	case R_TILEGX_IMM16_X1_HW1:
   3289       1.1  christos 	case R_TILEGX_IMM16_X0_HW2:
   3290       1.1  christos 	case R_TILEGX_IMM16_X1_HW2:
   3291       1.1  christos 	case R_TILEGX_IMM16_X0_HW3:
   3292       1.1  christos 	case R_TILEGX_IMM16_X1_HW3:
   3293       1.1  christos 	case R_TILEGX_IMM16_X0_HW0_LAST:
   3294       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_LAST:
   3295       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_LAST:
   3296       1.1  christos 	case R_TILEGX_IMM16_X1_HW1_LAST:
   3297       1.1  christos 	case R_TILEGX_IMM16_X0_HW2_LAST:
   3298       1.1  christos 	case R_TILEGX_IMM16_X1_HW2_LAST:
   3299   1.1.1.2  christos 	  if ((input_section->flags & SEC_ALLOC) == 0)
   3300       1.1  christos 	    break;
   3301   1.1.1.4  christos 
   3302   1.1.1.4  christos 	  if ((bfd_link_pic (info)
   3303       1.1  christos 	       && (h == NULL
   3304       1.1  christos 		   || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
   3305       1.1  christos 		       && !resolved_to_zero)
   3306   1.1.1.2  christos 		   || h->root.type != bfd_link_hash_undefweak)
   3307       1.1  christos 	       && (! howto->pc_relative
   3308       1.1  christos 		   || !SYMBOL_CALLS_LOCAL (info, h)))
   3309       1.1  christos 	      || (!bfd_link_pic (info)
   3310       1.1  christos 		  && h != NULL
   3311       1.1  christos 		  && h->dynindx != -1
   3312       1.1  christos 		  && !h->non_got_ref
   3313       1.1  christos 		  && ((h->def_dynamic
   3314       1.1  christos 		       && !h->def_regular)
   3315       1.1  christos 		      || h->root.type == bfd_link_hash_undefweak
   3316   1.1.1.7  christos 		      || h->root.type == bfd_link_hash_undefined)))
   3317       1.1  christos 	    {
   3318       1.1  christos 	      Elf_Internal_Rela outrel;
   3319       1.1  christos 	      bool skip, relocate = false;
   3320       1.1  christos 
   3321       1.1  christos 	      /* When generating a shared object, these relocations
   3322       1.1  christos 		 are copied into the output file to be resolved at run
   3323       1.1  christos 		 time.  */
   3324   1.1.1.7  christos 
   3325       1.1  christos 	      BFD_ASSERT (sreloc != NULL);
   3326       1.1  christos 
   3327       1.1  christos 	      skip = false;
   3328       1.1  christos 
   3329       1.1  christos 	      outrel.r_offset =
   3330   1.1.1.7  christos 		_bfd_elf_section_offset (output_bfd, info, input_section,
   3331       1.1  christos 					 rel->r_offset);
   3332   1.1.1.7  christos 	      if (outrel.r_offset == (bfd_vma) -1)
   3333       1.1  christos 		skip = true;
   3334       1.1  christos 	      else if (outrel.r_offset == (bfd_vma) -2)
   3335       1.1  christos 		skip = true, relocate = true;
   3336       1.1  christos 	      outrel.r_offset += (input_section->output_section->vma
   3337       1.1  christos 				  + input_section->output_offset);
   3338   1.1.1.4  christos 
   3339   1.1.1.4  christos 	      switch (r_type)
   3340   1.1.1.4  christos 		{
   3341   1.1.1.4  christos 		case R_TILEGX_64_PCREL:
   3342       1.1  christos 		case R_TILEGX_32_PCREL:
   3343       1.1  christos 		case R_TILEGX_16_PCREL:
   3344       1.1  christos 		case R_TILEGX_8_PCREL:
   3345       1.1  christos 		  /* If the symbol is not dynamic, we should not keep
   3346       1.1  christos 		     a dynamic relocation.  But an .rela.* slot has been
   3347       1.1  christos 		     allocated for it, output R_TILEGX_NONE.
   3348   1.1.1.7  christos 		     FIXME: Add code tracking needed dynamic relocs as
   3349       1.1  christos 		     e.g. i386 has.  */
   3350       1.1  christos 		  if (h->dynindx == -1)
   3351       1.1  christos 		    skip = true, relocate = true;
   3352       1.1  christos 		  break;
   3353       1.1  christos 		}
   3354       1.1  christos 
   3355       1.1  christos 	      if (skip)
   3356       1.1  christos 		memset (&outrel, 0, sizeof outrel);
   3357       1.1  christos 	      /* h->dynindx may be -1 if the symbol was marked to
   3358       1.1  christos 		 become local.  */
   3359   1.1.1.2  christos 	      else if (h != NULL &&
   3360       1.1  christos 		       h->dynindx != -1
   3361       1.1  christos 		       && (! is_plt
   3362       1.1  christos 			   || !bfd_link_pic (info)
   3363       1.1  christos 			   || !SYMBOLIC_BIND (info, h)
   3364       1.1  christos 			   || !h->def_regular))
   3365       1.1  christos 		{
   3366       1.1  christos 		  BFD_ASSERT (h->dynindx != -1);
   3367       1.1  christos 		  outrel.r_info = TILEGX_ELF_R_INFO (htab, rel, 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 		  if (r_type == R_TILEGX_32 || r_type == R_TILEGX_64)
   3373       1.1  christos 		    {
   3374       1.1  christos 		      outrel.r_info = TILEGX_ELF_R_INFO (htab, NULL, 0,
   3375       1.1  christos 							 R_TILEGX_RELATIVE);
   3376       1.1  christos 		      outrel.r_addend = relocation + rel->r_addend;
   3377       1.1  christos 		    }
   3378       1.1  christos 		  else
   3379       1.1  christos 		    {
   3380       1.1  christos 		      long indx;
   3381       1.1  christos 
   3382       1.1  christos 		      outrel.r_addend = relocation + rel->r_addend;
   3383       1.1  christos 
   3384       1.1  christos 		      if (is_plt)
   3385       1.1  christos 			sec = htab->elf.splt;
   3386       1.1  christos 
   3387       1.1  christos 		      if (bfd_is_abs_section (sec))
   3388       1.1  christos 			indx = 0;
   3389   1.1.1.7  christos 		      else if (sec == NULL || sec->owner == NULL)
   3390       1.1  christos 			{
   3391       1.1  christos 			  bfd_set_error (bfd_error_bad_value);
   3392       1.1  christos 			  return false;
   3393       1.1  christos 			}
   3394       1.1  christos 		      else
   3395       1.1  christos 			{
   3396       1.1  christos 			  asection *osec;
   3397       1.1  christos 
   3398       1.1  christos 			  /* We are turning this relocation into one
   3399       1.1  christos 			     against a section symbol.  It would be
   3400       1.1  christos 			     proper to subtract the symbol's value,
   3401       1.1  christos 			     osec->vma, from the emitted reloc addend,
   3402       1.1  christos 			     but ld.so expects buggy relocs.  */
   3403       1.1  christos 			  osec = sec->output_section;
   3404       1.1  christos 			  indx = elf_section_data (osec)->dynindx;
   3405       1.1  christos 
   3406       1.1  christos 			  if (indx == 0)
   3407       1.1  christos 			    {
   3408       1.1  christos 			      osec = htab->elf.text_index_section;
   3409       1.1  christos 			      indx = elf_section_data (osec)->dynindx;
   3410       1.1  christos 			    }
   3411       1.1  christos 
   3412       1.1  christos 			  /* FIXME: we really should be able to link non-pic
   3413       1.1  christos 			     shared libraries.  */
   3414   1.1.1.4  christos 			  if (indx == 0)
   3415   1.1.1.5  christos 			    {
   3416       1.1  christos 			      BFD_FAIL ();
   3417       1.1  christos 			      _bfd_error_handler
   3418   1.1.1.7  christos 				(_("%pB: probably compiled without -fPIC?"),
   3419       1.1  christos 				 input_bfd);
   3420       1.1  christos 			      bfd_set_error (bfd_error_bad_value);
   3421       1.1  christos 			      return false;
   3422       1.1  christos 			    }
   3423       1.1  christos 			}
   3424       1.1  christos 
   3425       1.1  christos 		      outrel.r_info = TILEGX_ELF_R_INFO (htab, rel, indx,
   3426       1.1  christos 							 r_type);
   3427       1.1  christos 		    }
   3428       1.1  christos 		}
   3429       1.1  christos 
   3430       1.1  christos 	      tilegx_elf_append_rela (output_bfd, sreloc, &outrel);
   3431       1.1  christos 
   3432       1.1  christos 	      /* This reloc will be computed at runtime, so there's no
   3433       1.1  christos 		 need to do anything now.  */
   3434       1.1  christos 	      if (! relocate)
   3435       1.1  christos 		continue;
   3436   1.1.1.4  christos 	    }
   3437   1.1.1.4  christos 	  break;
   3438   1.1.1.4  christos 
   3439   1.1.1.4  christos 	case R_TILEGX_IMM16_X0_HW0_TLS_LE:
   3440   1.1.1.4  christos 	case R_TILEGX_IMM16_X1_HW0_TLS_LE:
   3441   1.1.1.4  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
   3442   1.1.1.4  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
   3443       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
   3444       1.1  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
   3445   1.1.1.7  christos 	  if (!bfd_link_executable (info))
   3446       1.1  christos 	    {
   3447       1.1  christos 	      Elf_Internal_Rela outrel;
   3448   1.1.1.7  christos 	      bool skip;
   3449       1.1  christos 
   3450       1.1  christos 	      BFD_ASSERT (sreloc != NULL);
   3451       1.1  christos 	      skip = false;
   3452       1.1  christos 	      outrel.r_offset =
   3453   1.1.1.7  christos 		_bfd_elf_section_offset (output_bfd, info, input_section,
   3454       1.1  christos 					 rel->r_offset);
   3455   1.1.1.7  christos 	      if (outrel.r_offset == (bfd_vma) -1)
   3456       1.1  christos 		skip = true;
   3457       1.1  christos 	      else if (outrel.r_offset == (bfd_vma) -2)
   3458       1.1  christos 		skip = true;
   3459       1.1  christos 	      outrel.r_offset += (input_section->output_section->vma
   3460       1.1  christos 				  + input_section->output_offset);
   3461       1.1  christos 	      if (skip)
   3462       1.1  christos 		memset (&outrel, 0, sizeof outrel);
   3463       1.1  christos 	      else
   3464       1.1  christos 		{
   3465       1.1  christos 		  outrel.r_info = TILEGX_ELF_R_INFO (htab, NULL, 0, r_type);
   3466       1.1  christos 		  outrel.r_addend = relocation - dtpoff_base (info)
   3467       1.1  christos 				    + rel->r_addend;
   3468       1.1  christos 		}
   3469       1.1  christos 
   3470       1.1  christos 	      tilegx_elf_append_rela (output_bfd, sreloc, &outrel);
   3471       1.1  christos 	      continue;
   3472       1.1  christos 	    }
   3473   1.1.1.4  christos 	  relocation = tpoff (info, relocation);
   3474   1.1.1.4  christos 	  break;
   3475   1.1.1.4  christos 
   3476   1.1.1.4  christos 	case R_TILEGX_IMM16_X0_HW0_TLS_GD:
   3477   1.1.1.4  christos 	case R_TILEGX_IMM16_X1_HW0_TLS_GD:
   3478   1.1.1.4  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
   3479   1.1.1.4  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
   3480   1.1.1.4  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
   3481   1.1.1.4  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
   3482   1.1.1.4  christos 	case R_TILEGX_IMM16_X0_HW0_TLS_IE:
   3483   1.1.1.4  christos 	case R_TILEGX_IMM16_X1_HW0_TLS_IE:
   3484   1.1.1.4  christos 	case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
   3485       1.1  christos 	case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
   3486       1.1  christos 	case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
   3487   1.1.1.4  christos 	case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
   3488       1.1  christos 	  r_type = tilegx_elf_tls_transition (info, r_type, h == NULL,
   3489       1.1  christos 					      input_section->sec_flg0);
   3490       1.1  christos 	  tls_type = GOT_UNKNOWN;
   3491       1.1  christos 	  if (h == NULL && local_got_offsets)
   3492       1.1  christos 	    tls_type =
   3493       1.1  christos 	      _bfd_tilegx_elf_local_got_tls_type (input_bfd) [r_symndx];
   3494   1.1.1.4  christos 	  else if (h != NULL)
   3495   1.1.1.2  christos 	    {
   3496   1.1.1.2  christos 	      tls_type = tilegx_elf_hash_entry(h)->tls_type;
   3497       1.1  christos 	      if (bfd_link_executable (info)
   3498       1.1  christos 		  && h->dynindx == -1
   3499       1.1  christos 		  && tls_type == GOT_TLS_IE)
   3500       1.1  christos 		r_type = (!input_section->sec_flg0
   3501       1.1  christos 			  ? tilegx_tls_translate_to_le (r_type)
   3502       1.1  christos 			  : tilegx_tls_translate_to_ie (r_type));
   3503       1.1  christos 	    }
   3504       1.1  christos 
   3505       1.1  christos 	  if (tls_type == GOT_TLS_IE)
   3506       1.1  christos 	    r_type = tilegx_tls_translate_to_ie (r_type);
   3507       1.1  christos 
   3508       1.1  christos 	  if (r_type == R_TILEGX_IMM16_X0_HW0_TLS_LE
   3509       1.1  christos 	      || r_type == R_TILEGX_IMM16_X1_HW0_TLS_LE
   3510       1.1  christos 	      || r_type == R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE
   3511       1.1  christos 	      || r_type == R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE
   3512       1.1  christos 	      || r_type == R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE
   3513       1.1  christos 	      || r_type == R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE)
   3514       1.1  christos 	    {
   3515       1.1  christos 	      relocation = tpoff (info, relocation);
   3516       1.1  christos 	      break;
   3517       1.1  christos 	    }
   3518       1.1  christos 
   3519       1.1  christos 	  if (h != NULL)
   3520       1.1  christos 	    {
   3521       1.1  christos 	      off = h->got.offset;
   3522       1.1  christos 	      h->got.offset |= 1;
   3523       1.1  christos 	    }
   3524       1.1  christos 	  else
   3525       1.1  christos 	    {
   3526       1.1  christos 	      BFD_ASSERT (local_got_offsets != NULL);
   3527       1.1  christos 	      off = local_got_offsets[r_symndx];
   3528       1.1  christos 	      local_got_offsets[r_symndx] |= 1;
   3529       1.1  christos 	    }
   3530       1.1  christos 
   3531       1.1  christos 	  if (htab->elf.sgot == NULL)
   3532       1.1  christos 	    abort ();
   3533       1.1  christos 
   3534       1.1  christos 	  if ((off & 1) != 0)
   3535       1.1  christos 	    off &= ~1;
   3536       1.1  christos 	  else
   3537   1.1.1.7  christos 	    {
   3538       1.1  christos 	      Elf_Internal_Rela outrel;
   3539       1.1  christos 	      int indx = 0;
   3540       1.1  christos 	      bool need_relocs = false;
   3541       1.1  christos 
   3542       1.1  christos 	      if (htab->elf.srelgot == NULL)
   3543       1.1  christos 		abort ();
   3544   1.1.1.7  christos 
   3545   1.1.1.4  christos 	      if (h != NULL)
   3546       1.1  christos 	      {
   3547   1.1.1.2  christos 		bool dyn;
   3548   1.1.1.2  christos 		dyn = htab->elf.dynamic_sections_created;
   3549   1.1.1.2  christos 
   3550   1.1.1.2  christos 		if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
   3551       1.1  christos 						     bfd_link_pic (info),
   3552       1.1  christos 						     h)
   3553       1.1  christos 		    && (!bfd_link_pic (info)
   3554       1.1  christos 			|| !SYMBOL_REFERENCES_LOCAL (info, h)))
   3555       1.1  christos 		  {
   3556       1.1  christos 		    indx = h->dynindx;
   3557       1.1  christos 		  }
   3558   1.1.1.4  christos 	      }
   3559   1.1.1.2  christos 
   3560       1.1  christos 	      /* The GOT entries have not been initialized yet.  Do it
   3561       1.1  christos 		 now, and emit any relocations. */
   3562       1.1  christos 	      if ((bfd_link_pic (info) || indx != 0)
   3563   1.1.1.7  christos 		  && (h == NULL
   3564       1.1  christos 		      || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
   3565   1.1.1.4  christos 		      || h->root.type != bfd_link_hash_undefweak))
   3566   1.1.1.4  christos 		    need_relocs = true;
   3567       1.1  christos 
   3568       1.1  christos 	      switch (r_type)
   3569       1.1  christos 		{
   3570       1.1  christos 		  case R_TILEGX_IMM16_X0_HW0_TLS_IE:
   3571       1.1  christos 		  case R_TILEGX_IMM16_X1_HW0_TLS_IE:
   3572       1.1  christos 		  case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
   3573       1.1  christos 		  case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
   3574       1.1  christos 		  case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
   3575       1.1  christos 		  case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
   3576   1.1.1.4  christos 		    if (need_relocs) {
   3577       1.1  christos 		      TILEGX_ELF_PUT_WORD (htab, output_bfd, 0,
   3578   1.1.1.4  christos 					   htab->elf.sgot->contents + off);
   3579       1.1  christos 		      outrel.r_offset = (htab->elf.sgot->output_section->vma
   3580   1.1.1.4  christos 				       + htab->elf.sgot->output_offset + off);
   3581       1.1  christos 		      outrel.r_addend = 0;
   3582       1.1  christos 		      if (indx == 0)
   3583       1.1  christos 			outrel.r_addend = relocation - dtpoff_base (info);
   3584   1.1.1.4  christos 		      outrel.r_info = TILEGX_ELF_R_INFO (htab, NULL, indx,
   3585       1.1  christos 							 TILEGX_ELF_TPOFF_RELOC (htab));
   3586       1.1  christos 		      tilegx_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
   3587       1.1  christos 		    } else {
   3588   1.1.1.4  christos 		      TILEGX_ELF_PUT_WORD (htab, output_bfd,
   3589   1.1.1.4  christos 					   tpoff (info, relocation),
   3590       1.1  christos 					   htab->elf.sgot->contents + off);
   3591       1.1  christos 		    }
   3592       1.1  christos 		    break;
   3593       1.1  christos 
   3594       1.1  christos 		  case R_TILEGX_IMM16_X0_HW0_TLS_GD:
   3595       1.1  christos 		  case R_TILEGX_IMM16_X1_HW0_TLS_GD:
   3596       1.1  christos 		  case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
   3597       1.1  christos 		  case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
   3598   1.1.1.4  christos 		  case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
   3599       1.1  christos 		  case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
   3600   1.1.1.4  christos 		    if (need_relocs) {
   3601   1.1.1.4  christos 		      outrel.r_offset = (htab->elf.sgot->output_section->vma
   3602       1.1  christos 				       + htab->elf.sgot->output_offset + off);
   3603       1.1  christos 		      outrel.r_addend = 0;
   3604       1.1  christos 		      outrel.r_info = TILEGX_ELF_R_INFO (htab, NULL, indx,
   3605   1.1.1.4  christos 							 TILEGX_ELF_DTPMOD_RELOC (htab));
   3606       1.1  christos 		      TILEGX_ELF_PUT_WORD (htab, output_bfd, 0,
   3607   1.1.1.4  christos 					   htab->elf.sgot->contents + off);
   3608   1.1.1.4  christos 		      tilegx_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
   3609       1.1  christos 		      if (indx == 0)
   3610       1.1  christos 			{
   3611       1.1  christos 			  BFD_ASSERT (! unresolved_reloc);
   3612       1.1  christos 			  TILEGX_ELF_PUT_WORD (htab, output_bfd,
   3613   1.1.1.4  christos 					       relocation - dtpoff_base (info),
   3614       1.1  christos 					       (htab->elf.sgot->contents + off +
   3615   1.1.1.4  christos 						TILEGX_ELF_WORD_BYTES (htab)));
   3616       1.1  christos 			}
   3617       1.1  christos 		      else
   3618       1.1  christos 			{
   3619   1.1.1.4  christos 			  TILEGX_ELF_PUT_WORD (htab, output_bfd, 0,
   3620       1.1  christos 					       (htab->elf.sgot->contents + off +
   3621   1.1.1.4  christos 						TILEGX_ELF_WORD_BYTES (htab)));
   3622   1.1.1.4  christos 			  outrel.r_info = TILEGX_ELF_R_INFO (htab, NULL, indx,
   3623   1.1.1.4  christos 							     TILEGX_ELF_DTPOFF_RELOC (htab));
   3624   1.1.1.4  christos 			  outrel.r_offset += TILEGX_ELF_WORD_BYTES (htab);
   3625       1.1  christos 			  tilegx_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
   3626       1.1  christos 			}
   3627       1.1  christos 		    }
   3628   1.1.1.4  christos 
   3629   1.1.1.4  christos 		    else {
   3630   1.1.1.4  christos 		      /* If we are not emitting relocations for a
   3631   1.1.1.4  christos 			 general dynamic reference, then we must be in a
   3632       1.1  christos 			 static link or an executable link with the
   3633       1.1  christos 			 symbol binding locally.  Mark it as belonging
   3634       1.1  christos 			 to module 1, the executable.  */
   3635       1.1  christos 		      TILEGX_ELF_PUT_WORD (htab, output_bfd, 1,
   3636       1.1  christos 					   htab->elf.sgot->contents + off );
   3637       1.1  christos 		      TILEGX_ELF_PUT_WORD (htab, output_bfd,
   3638       1.1  christos 					   relocation - dtpoff_base (info),
   3639   1.1.1.4  christos 					   htab->elf.sgot->contents + off +
   3640   1.1.1.4  christos 					   TILEGX_ELF_WORD_BYTES (htab));
   3641       1.1  christos 		   }
   3642       1.1  christos 		   break;
   3643       1.1  christos 		}
   3644       1.1  christos 	    }
   3645       1.1  christos 
   3646       1.1  christos 	  if (off >= (bfd_vma) -2)
   3647   1.1.1.7  christos 	    abort ();
   3648       1.1  christos 
   3649       1.1  christos 	  relocation = off - got_base;
   3650       1.1  christos 	  unresolved_reloc = false;
   3651       1.1  christos 	  howto = tilegx_elf_howto_table + r_type;
   3652       1.1  christos 	  break;
   3653       1.1  christos 
   3654       1.1  christos 	default:
   3655       1.1  christos 	  break;
   3656       1.1  christos 	}
   3657       1.1  christos 
   3658       1.1  christos       /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
   3659       1.1  christos 	 because such sections are not SEC_ALLOC and thus ld.so will
   3660       1.1  christos 	 not process them.  */
   3661       1.1  christos       if (unresolved_reloc
   3662       1.1  christos 	  && !((input_section->flags & SEC_DEBUGGING) != 0
   3663   1.1.1.4  christos 	       && h->def_dynamic)
   3664   1.1.1.4  christos 	  && _bfd_elf_section_offset (output_bfd, info, input_section,
   3665   1.1.1.5  christos 				      rel->r_offset) != (bfd_vma) -1)
   3666   1.1.1.5  christos 	_bfd_error_handler
   3667       1.1  christos 	  /* xgettext:c-format */
   3668       1.1  christos 	  (_("%pB(%pA+%#" PRIx64 "): "
   3669   1.1.1.5  christos 	     "unresolvable %s relocation against symbol `%s'"),
   3670       1.1  christos 	   input_bfd,
   3671       1.1  christos 	   input_section,
   3672       1.1  christos 	   (uint64_t) rel->r_offset,
   3673       1.1  christos 	   howto->name,
   3674       1.1  christos 	   h->root.root.string);
   3675       1.1  christos 
   3676       1.1  christos       r = bfd_reloc_continue;
   3677       1.1  christos 
   3678       1.1  christos       /* Get the operand creation function, if any. */
   3679   1.1.1.4  christos       create_func = reloc_to_create_func[r_type];
   3680   1.1.1.4  christos       if (create_func == NULL)
   3681   1.1.1.4  christos       {
   3682       1.1  christos 	r = _bfd_final_link_relocate (howto, input_bfd, input_section,
   3683       1.1  christos 				      contents, rel->r_offset,
   3684       1.1  christos 				      relocation, rel->r_addend);
   3685   1.1.1.4  christos       }
   3686   1.1.1.4  christos       else
   3687   1.1.1.4  christos       {
   3688   1.1.1.4  christos 	if (howto->pc_relative)
   3689   1.1.1.4  christos 	{
   3690   1.1.1.4  christos 	  relocation -=
   3691   1.1.1.4  christos 	    input_section->output_section->vma + input_section->output_offset;
   3692   1.1.1.4  christos 	  if (howto->pcrel_offset)
   3693   1.1.1.4  christos 	    relocation -= rel->r_offset;
   3694   1.1.1.4  christos 	}
   3695   1.1.1.4  christos 
   3696   1.1.1.4  christos 	bfd_byte *data;
   3697   1.1.1.4  christos 
   3698   1.1.1.4  christos 	/* Add the relocation addend if any to the final target value */
   3699   1.1.1.4  christos 	relocation += rel->r_addend;
   3700   1.1.1.4  christos 
   3701   1.1.1.4  christos 	/* Do basic range checking */
   3702   1.1.1.4  christos 	r = bfd_check_overflow (howto->complain_on_overflow,
   3703   1.1.1.4  christos 				howto->bitsize,
   3704   1.1.1.4  christos 				howto->rightshift,
   3705   1.1.1.4  christos 				TILEGX_ELF_WORD_BYTES (htab) * 8,
   3706   1.1.1.4  christos 				relocation);
   3707   1.1.1.4  christos 
   3708   1.1.1.4  christos 	/*
   3709   1.1.1.4  christos 	 * Write the relocated value out into the raw section data.
   3710   1.1.1.4  christos 	 * Don't put a relocation out in the .rela section.
   3711   1.1.1.4  christos 	 */
   3712   1.1.1.4  christos 	tilegx_bundle_bits mask = create_func(-1);
   3713   1.1.1.4  christos 	tilegx_bundle_bits value = create_func(relocation >> howto->rightshift);
   3714   1.1.1.4  christos 
   3715   1.1.1.4  christos 	/* Only touch bytes while the mask is not 0, so we
   3716   1.1.1.4  christos 	   don't write to out of bounds memory if this is actually
   3717   1.1.1.4  christos 	   a 16-bit switch instruction. */
   3718   1.1.1.4  christos 	for (data = contents + rel->r_offset; mask != 0; data++)
   3719   1.1.1.4  christos 	  {
   3720   1.1.1.4  christos 	    bfd_byte byte_mask = (bfd_byte)mask;
   3721   1.1.1.4  christos 	    *data = (*data & ~byte_mask) | ((bfd_byte)value & byte_mask);
   3722       1.1  christos 	    mask >>= 8;
   3723       1.1  christos 	    value >>= 8;
   3724       1.1  christos 	  }
   3725       1.1  christos       }
   3726       1.1  christos 
   3727       1.1  christos       if (r != bfd_reloc_ok)
   3728       1.1  christos 	{
   3729       1.1  christos 	  const char *msg = NULL;
   3730       1.1  christos 
   3731   1.1.1.3  christos 	  switch (r)
   3732       1.1  christos 	    {
   3733       1.1  christos 	    case bfd_reloc_overflow:
   3734       1.1  christos 	      (*info->callbacks->reloc_overflow)
   3735       1.1  christos 		(info, (h ? &h->root : NULL), name, howto->name,
   3736       1.1  christos 		 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
   3737   1.1.1.3  christos 	      break;
   3738   1.1.1.7  christos 
   3739       1.1  christos 	    case bfd_reloc_undefined:
   3740       1.1  christos 	      (*info->callbacks->undefined_symbol)
   3741       1.1  christos 		(info, name, input_bfd, input_section, rel->r_offset, true);
   3742       1.1  christos 	      break;
   3743       1.1  christos 
   3744       1.1  christos 	    case bfd_reloc_outofrange:
   3745       1.1  christos 	      msg = _("internal error: out of range error");
   3746       1.1  christos 	      break;
   3747       1.1  christos 
   3748       1.1  christos 	    case bfd_reloc_notsupported:
   3749       1.1  christos 	      msg = _("internal error: unsupported relocation error");
   3750       1.1  christos 	      break;
   3751       1.1  christos 
   3752       1.1  christos 	    case bfd_reloc_dangerous:
   3753       1.1  christos 	      msg = _("internal error: dangerous relocation");
   3754       1.1  christos 	      break;
   3755       1.1  christos 
   3756       1.1  christos 	    default:
   3757       1.1  christos 	      msg = _("internal error: unknown error");
   3758       1.1  christos 	      break;
   3759   1.1.1.3  christos 	    }
   3760   1.1.1.3  christos 
   3761       1.1  christos 	  if (msg)
   3762       1.1  christos 	    (*info->callbacks->warning) (info, msg, name, input_bfd,
   3763       1.1  christos 					 input_section, rel->r_offset);
   3764   1.1.1.7  christos 	}
   3765       1.1  christos     }
   3766       1.1  christos 
   3767       1.1  christos   return true;
   3768       1.1  christos }
   3769       1.1  christos 
   3770   1.1.1.7  christos /* Finish up dynamic symbol handling.  We set the contents of various
   3771       1.1  christos    dynamic sections here.  */
   3772       1.1  christos 
   3773       1.1  christos bool
   3774       1.1  christos tilegx_elf_finish_dynamic_symbol (bfd *output_bfd,
   3775       1.1  christos 				  struct bfd_link_info *info,
   3776       1.1  christos 				  struct elf_link_hash_entry *h,
   3777       1.1  christos 				  Elf_Internal_Sym *sym)
   3778       1.1  christos {
   3779       1.1  christos   struct tilegx_elf_link_hash_table *htab;
   3780       1.1  christos 
   3781       1.1  christos   htab = tilegx_elf_hash_table (info);
   3782       1.1  christos   BFD_ASSERT (htab != NULL);
   3783       1.1  christos 
   3784       1.1  christos   if (h->plt.offset != (bfd_vma) -1)
   3785       1.1  christos     {
   3786       1.1  christos       asection *splt;
   3787       1.1  christos       asection *srela;
   3788       1.1  christos       asection *sgotplt;
   3789  1.1.1.10  christos       Elf_Internal_Rela rela;
   3790       1.1  christos       bfd_byte *loc;
   3791       1.1  christos       bfd_vma r_offset;
   3792       1.1  christos       elf_backend_data *bed = get_elf_backend_data (output_bfd);
   3793       1.1  christos 
   3794       1.1  christos 
   3795       1.1  christos       int rela_index;
   3796       1.1  christos 
   3797       1.1  christos       /* This symbol has an entry in the PLT.  Set it up.  */
   3798       1.1  christos 
   3799       1.1  christos       BFD_ASSERT (h->dynindx != -1);
   3800       1.1  christos 
   3801       1.1  christos       splt = htab->elf.splt;
   3802       1.1  christos       srela = htab->elf.srelplt;
   3803       1.1  christos       sgotplt = htab->elf.sgotplt;
   3804       1.1  christos 
   3805       1.1  christos       if (splt == NULL || srela == NULL)
   3806       1.1  christos        abort ();
   3807       1.1  christos 
   3808       1.1  christos       /* Fill in the entry in the procedure linkage table.  */
   3809       1.1  christos       rela_index = tilegx_plt_entry_build (output_bfd, htab, splt, sgotplt,
   3810       1.1  christos 					   h->plt.offset, &r_offset);
   3811       1.1  christos 
   3812       1.1  christos       /* Fill in the entry in the global offset table, which initially points
   3813       1.1  christos 	 to the beginning of the plt.  */
   3814       1.1  christos       TILEGX_ELF_PUT_WORD (htab, output_bfd,
   3815       1.1  christos 			   splt->output_section->vma + splt->output_offset,
   3816       1.1  christos 			   sgotplt->contents + r_offset);
   3817       1.1  christos 
   3818       1.1  christos       /* Fill in the entry in the .rela.plt section.  */
   3819       1.1  christos       rela.r_offset = (sgotplt->output_section->vma
   3820       1.1  christos 		       + sgotplt->output_offset
   3821       1.1  christos 		       + r_offset);
   3822       1.1  christos       rela.r_addend = 0;
   3823       1.1  christos       rela.r_info = TILEGX_ELF_R_INFO (htab, NULL, h->dynindx, R_TILEGX_JMP_SLOT);
   3824       1.1  christos 
   3825       1.1  christos       loc = srela->contents + rela_index * TILEGX_ELF_RELA_BYTES (htab);
   3826       1.1  christos       bed->s->swap_reloca_out (output_bfd, &rela, loc);
   3827       1.1  christos 
   3828       1.1  christos       if (!h->def_regular)
   3829       1.1  christos 	{
   3830       1.1  christos 	  /* Mark the symbol as undefined, rather than as defined in
   3831       1.1  christos 	     the .plt section.  Leave the value alone.  */
   3832       1.1  christos 	  sym->st_shndx = SHN_UNDEF;
   3833       1.1  christos 	  /* If the symbol is weak, we do need to clear the value.
   3834       1.1  christos 	     Otherwise, the PLT entry would provide a definition for
   3835       1.1  christos 	     the symbol even if the symbol wasn't defined anywhere,
   3836       1.1  christos 	     and so the symbol would never be NULL.  */
   3837       1.1  christos 	  if (!h->ref_regular_nonweak)
   3838       1.1  christos 	    sym->st_value = 0;
   3839       1.1  christos 	}
   3840       1.1  christos     }
   3841       1.1  christos 
   3842       1.1  christos   if (h->got.offset != (bfd_vma) -1
   3843       1.1  christos       && tilegx_elf_hash_entry(h)->tls_type != GOT_TLS_GD
   3844       1.1  christos       && tilegx_elf_hash_entry(h)->tls_type != GOT_TLS_IE)
   3845       1.1  christos     {
   3846       1.1  christos       asection *sgot;
   3847       1.1  christos       asection *srela;
   3848       1.1  christos       Elf_Internal_Rela rela;
   3849       1.1  christos 
   3850       1.1  christos       /* This symbol has an entry in the GOT.  Set it up.  */
   3851       1.1  christos 
   3852       1.1  christos       sgot = htab->elf.sgot;
   3853       1.1  christos       srela = htab->elf.srelgot;
   3854       1.1  christos       BFD_ASSERT (sgot != NULL && srela != NULL);
   3855       1.1  christos 
   3856       1.1  christos       rela.r_offset = (sgot->output_section->vma
   3857       1.1  christos 		       + sgot->output_offset
   3858       1.1  christos 		       + (h->got.offset &~ (bfd_vma) 1));
   3859       1.1  christos 
   3860       1.1  christos       /* If this is a -Bsymbolic link, and the symbol is defined
   3861       1.1  christos 	 locally, we just want to emit a RELATIVE reloc.  Likewise if
   3862   1.1.1.2  christos 	 the symbol was forced to be local because of a version file.
   3863       1.1  christos 	 The entry in the global offset table will already have been
   3864       1.1  christos 	 initialized in the relocate_section function.  */
   3865       1.1  christos       if (bfd_link_pic (info)
   3866       1.1  christos 	  && (info->symbolic || h->dynindx == -1)
   3867       1.1  christos 	  && h->def_regular)
   3868       1.1  christos 	{
   3869       1.1  christos 	  asection *sec = h->root.u.def.section;
   3870       1.1  christos 	  rela.r_info = TILEGX_ELF_R_INFO (htab, NULL, 0, R_TILEGX_RELATIVE);
   3871       1.1  christos 	  rela.r_addend = (h->root.u.def.value
   3872       1.1  christos 			   + sec->output_section->vma
   3873       1.1  christos 			   + sec->output_offset);
   3874       1.1  christos 	}
   3875       1.1  christos       else
   3876       1.1  christos 	{
   3877       1.1  christos 	  rela.r_info = TILEGX_ELF_R_INFO (htab, NULL, h->dynindx, R_TILEGX_GLOB_DAT);
   3878       1.1  christos 	  rela.r_addend = 0;
   3879       1.1  christos 	}
   3880       1.1  christos 
   3881       1.1  christos       TILEGX_ELF_PUT_WORD (htab, output_bfd, 0,
   3882       1.1  christos 			   sgot->contents + (h->got.offset & ~(bfd_vma) 1));
   3883       1.1  christos       tilegx_elf_append_rela (output_bfd, srela, &rela);
   3884       1.1  christos     }
   3885       1.1  christos 
   3886       1.1  christos   if (h->needs_copy)
   3887       1.1  christos     {
   3888       1.1  christos       asection *s;
   3889       1.1  christos       Elf_Internal_Rela rela;
   3890       1.1  christos 
   3891   1.1.1.4  christos       /* This symbols needs a copy reloc.  Set it up.  */
   3892   1.1.1.4  christos       BFD_ASSERT (h->dynindx != -1);
   3893   1.1.1.4  christos 
   3894   1.1.1.4  christos       if (h->root.u.def.section == htab->elf.sdynrelro)
   3895       1.1  christos 	s = htab->elf.sreldynrelro;
   3896       1.1  christos       else
   3897       1.1  christos 	s = htab->elf.srelbss;
   3898       1.1  christos       BFD_ASSERT (s != NULL);
   3899       1.1  christos 
   3900       1.1  christos       rela.r_offset = (h->root.u.def.value
   3901       1.1  christos 		       + h->root.u.def.section->output_section->vma
   3902       1.1  christos 		       + h->root.u.def.section->output_offset);
   3903       1.1  christos       rela.r_info = TILEGX_ELF_R_INFO (htab, NULL, h->dynindx, R_TILEGX_COPY);
   3904       1.1  christos       rela.r_addend = 0;
   3905       1.1  christos       tilegx_elf_append_rela (output_bfd, s, &rela);
   3906   1.1.1.2  christos     }
   3907       1.1  christos 
   3908       1.1  christos   /* Mark some specially defined symbols as absolute. */
   3909       1.1  christos   if (h == htab->elf.hdynamic
   3910   1.1.1.7  christos       || (h == htab->elf.hgot || h == htab->elf.hplt))
   3911       1.1  christos     sym->st_shndx = SHN_ABS;
   3912       1.1  christos 
   3913       1.1  christos   return true;
   3914       1.1  christos }
   3915   1.1.1.7  christos 
   3916       1.1  christos /* Finish up the dynamic sections.  */
   3917       1.1  christos 
   3918       1.1  christos static bool
   3919       1.1  christos tilegx_finish_dyn (bfd *output_bfd, struct bfd_link_info *info,
   3920       1.1  christos 		   bfd *dynobj, asection *sdyn,
   3921  1.1.1.10  christos 		   asection *splt ATTRIBUTE_UNUSED)
   3922       1.1  christos {
   3923       1.1  christos   struct tilegx_elf_link_hash_table *htab;
   3924       1.1  christos   elf_backend_data *bed;
   3925       1.1  christos   bfd_byte *dyncon, *dynconend;
   3926       1.1  christos   size_t dynsize;
   3927       1.1  christos 
   3928       1.1  christos   htab = tilegx_elf_hash_table (info);
   3929       1.1  christos   BFD_ASSERT (htab != NULL);
   3930       1.1  christos   bed = get_elf_backend_data (output_bfd);
   3931       1.1  christos   dynsize = bed->s->sizeof_dyn;
   3932       1.1  christos   dynconend = sdyn->contents + sdyn->size;
   3933       1.1  christos 
   3934       1.1  christos   for (dyncon = sdyn->contents; dyncon < dynconend; dyncon += dynsize)
   3935       1.1  christos     {
   3936       1.1  christos       Elf_Internal_Dyn dyn;
   3937       1.1  christos       asection *s;
   3938       1.1  christos 
   3939       1.1  christos       bed->s->swap_dyn_in (dynobj, dyncon, &dyn);
   3940       1.1  christos 
   3941       1.1  christos       switch (dyn.d_tag)
   3942       1.1  christos 	{
   3943       1.1  christos 	case DT_PLTGOT:
   3944       1.1  christos 	  s = htab->elf.sgotplt;
   3945       1.1  christos 	  dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   3946       1.1  christos 	  break;
   3947       1.1  christos 	case DT_JMPREL:
   3948       1.1  christos 	  s = htab->elf.srelplt;
   3949       1.1  christos 	  dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   3950       1.1  christos 	  break;
   3951       1.1  christos 	case DT_PLTRELSZ:
   3952       1.1  christos 	  s = htab->elf.srelplt;
   3953       1.1  christos 	  dyn.d_un.d_val = s->size;
   3954       1.1  christos 	  break;
   3955       1.1  christos 	default:
   3956       1.1  christos 	  continue;
   3957       1.1  christos 	}
   3958   1.1.1.7  christos 
   3959       1.1  christos       bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
   3960       1.1  christos     }
   3961   1.1.1.7  christos   return true;
   3962       1.1  christos }
   3963  1.1.1.10  christos 
   3964  1.1.1.10  christos bool
   3965       1.1  christos tilegx_elf_finish_dynamic_sections (bfd *output_bfd,
   3966       1.1  christos 				    struct bfd_link_info *info,
   3967       1.1  christos 				    bfd_byte *buf ATTRIBUTE_UNUSED)
   3968       1.1  christos {
   3969   1.1.1.2  christos   bfd *dynobj;
   3970       1.1  christos   asection *sdyn;
   3971       1.1  christos   struct tilegx_elf_link_hash_table *htab;
   3972       1.1  christos   size_t pad_size;
   3973       1.1  christos 
   3974       1.1  christos   htab = tilegx_elf_hash_table (info);
   3975       1.1  christos   BFD_ASSERT (htab != NULL);
   3976       1.1  christos   dynobj = htab->elf.dynobj;
   3977       1.1  christos 
   3978       1.1  christos   sdyn = bfd_get_linker_section (dynobj, ".dynamic");
   3979       1.1  christos 
   3980   1.1.1.7  christos   if (elf_hash_table (info)->dynamic_sections_created)
   3981       1.1  christos     {
   3982       1.1  christos       asection *splt;
   3983       1.1  christos       bool ret;
   3984       1.1  christos 
   3985       1.1  christos       splt = htab->elf.splt;
   3986       1.1  christos       BFD_ASSERT (splt != NULL && sdyn != NULL);
   3987   1.1.1.4  christos 
   3988       1.1  christos       ret = tilegx_finish_dyn (output_bfd, info, dynobj, sdyn, splt);
   3989       1.1  christos 
   3990       1.1  christos       if (!ret)
   3991       1.1  christos 	return ret;
   3992       1.1  christos 
   3993       1.1  christos       /* Fill in the head and tail entries in the procedure linkage table.  */
   3994       1.1  christos       if (splt->size > 0)
   3995       1.1  christos 	{
   3996       1.1  christos 	  memcpy (splt->contents,
   3997       1.1  christos 		  ABI_64_P (output_bfd) ?
   3998   1.1.1.2  christos 		    tilegx64_plt0_entry : tilegx32_plt0_entry,
   3999   1.1.1.2  christos 		  PLT_HEADER_SIZE);
   4000       1.1  christos 
   4001       1.1  christos 	  memcpy (splt->contents + splt->size
   4002       1.1  christos 		  - PLT_ENTRY_SIZE + PLT_HEADER_SIZE,
   4003   1.1.1.2  christos 		  ABI_64_P (output_bfd) ?
   4004   1.1.1.2  christos 		    tilegx64_plt_tail_entry : tilegx32_plt_tail_entry,
   4005   1.1.1.2  christos 		  PLT_TAIL_SIZE);
   4006   1.1.1.2  christos 	  /* Add padding so that the plt section is a multiple of its
   4007       1.1  christos 	     entry size.  */
   4008   1.1.1.4  christos 	  pad_size = PLT_ENTRY_SIZE - PLT_HEADER_SIZE - PLT_TAIL_SIZE;
   4009   1.1.1.4  christos 	  memset (splt->contents + splt->size - pad_size, 0, pad_size);
   4010   1.1.1.4  christos 
   4011       1.1  christos 	  elf_section_data (splt->output_section)->this_hdr.sh_entsize
   4012       1.1  christos 	    = PLT_ENTRY_SIZE;
   4013       1.1  christos 	}
   4014       1.1  christos     }
   4015       1.1  christos 
   4016       1.1  christos   if (htab->elf.sgotplt)
   4017   1.1.1.4  christos     {
   4018   1.1.1.5  christos       if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
   4019   1.1.1.7  christos 	{
   4020       1.1  christos 	  _bfd_error_handler
   4021       1.1  christos 	    (_("discarded output section: `%pA'"), htab->elf.sgotplt);
   4022       1.1  christos 	  return false;
   4023       1.1  christos 	}
   4024       1.1  christos 
   4025       1.1  christos       if (htab->elf.sgotplt->size > 0)
   4026       1.1  christos 	{
   4027       1.1  christos 	  /* Write the first two entries in .got.plt, needed for the dynamic
   4028       1.1  christos 	     linker.  */
   4029       1.1  christos 	  TILEGX_ELF_PUT_WORD (htab, output_bfd, (bfd_vma) -1,
   4030       1.1  christos 			       htab->elf.sgotplt->contents);
   4031       1.1  christos 	  TILEGX_ELF_PUT_WORD (htab, output_bfd, (bfd_vma) 0,
   4032   1.1.1.4  christos 			       htab->elf.sgotplt->contents
   4033   1.1.1.4  christos 			       + GOT_ENTRY_SIZE (htab));
   4034   1.1.1.4  christos 
   4035       1.1  christos 	  elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize =
   4036       1.1  christos 	    GOT_ENTRY_SIZE (htab);
   4037       1.1  christos 	}
   4038       1.1  christos     }
   4039       1.1  christos 
   4040       1.1  christos   if (htab->elf.sgot)
   4041       1.1  christos     {
   4042       1.1  christos       if (htab->elf.sgot->size > 0)
   4043       1.1  christos 	{
   4044       1.1  christos 	  /* Set the first entry in the global offset table to the address of
   4045       1.1  christos 	     the dynamic section.  */
   4046       1.1  christos 	  bfd_vma val = (sdyn ?
   4047       1.1  christos 			 sdyn->output_section->vma + sdyn->output_offset :
   4048       1.1  christos 			 0);
   4049   1.1.1.4  christos 	  TILEGX_ELF_PUT_WORD (htab, output_bfd, val,
   4050   1.1.1.4  christos 			       htab->elf.sgot->contents);
   4051   1.1.1.4  christos 
   4052       1.1  christos 	  elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize =
   4053       1.1  christos 	    GOT_ENTRY_SIZE (htab);
   4054   1.1.1.7  christos 	}
   4055       1.1  christos     }
   4056       1.1  christos 
   4057       1.1  christos   return true;
   4058       1.1  christos }
   4059       1.1  christos 
   4060       1.1  christos 
   4061       1.1  christos 
   4063       1.1  christos /* Return address for Ith PLT stub in section PLT, for relocation REL
   4064       1.1  christos    or (bfd_vma) -1 if it should not be included.  */
   4065       1.1  christos 
   4066       1.1  christos bfd_vma
   4067       1.1  christos tilegx_elf_plt_sym_val (bfd_vma i, const asection *plt,
   4068       1.1  christos 			const arelent *rel ATTRIBUTE_UNUSED)
   4069       1.1  christos {
   4070   1.1.1.2  christos   return plt->vma + PLT_HEADER_SIZE + i * PLT_ENTRY_SIZE;
   4071   1.1.1.2  christos }
   4072   1.1.1.2  christos 
   4073       1.1  christos enum elf_reloc_type_class
   4074       1.1  christos tilegx_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
   4075       1.1  christos 			 const asection *rel_sec ATTRIBUTE_UNUSED,
   4076       1.1  christos 			 const Elf_Internal_Rela *rela)
   4077       1.1  christos {
   4078       1.1  christos   switch ((int) TILEGX_ELF_R_TYPE (rela->r_info))
   4079       1.1  christos     {
   4080       1.1  christos     case R_TILEGX_RELATIVE:
   4081       1.1  christos       return reloc_class_relative;
   4082       1.1  christos     case R_TILEGX_JMP_SLOT:
   4083       1.1  christos       return reloc_class_plt;
   4084       1.1  christos     case R_TILEGX_COPY:
   4085       1.1  christos       return reloc_class_copy;
   4086       1.1  christos     default:
   4087       1.1  christos       return reloc_class_normal;
   4088       1.1  christos     }
   4089       1.1  christos }
   4090       1.1  christos 
   4091       1.1  christos int
   4092       1.1  christos tilegx_additional_program_headers (bfd *abfd,
   4093       1.1  christos 				   struct bfd_link_info *info ATTRIBUTE_UNUSED)
   4094       1.1  christos {
   4095       1.1  christos   /* Each .intrpt section specified by the user adds another PT_LOAD
   4096       1.1  christos      header since the sections are discontiguous. */
   4097       1.1  christos   static const char intrpt_sections[4][9] =
   4098       1.1  christos     {
   4099       1.1  christos       ".intrpt0", ".intrpt1", ".intrpt2", ".intrpt3"
   4100       1.1  christos     };
   4101       1.1  christos   int count = 0;
   4102       1.1  christos   int i;
   4103       1.1  christos 
   4104       1.1  christos   for (i = 0; i < 4; i++)
   4105       1.1  christos     {
   4106       1.1  christos       asection *sec = bfd_get_section_by_name (abfd, intrpt_sections[i]);
   4107       1.1  christos       if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
   4108       1.1  christos 	++count;
   4109       1.1  christos     }
   4110       1.1  christos 
   4111       1.1  christos   /* Add four "padding" headers in to leave room in case a custom linker
   4112       1.1  christos      script does something fancy. Otherwise ld complains that it ran
   4113       1.1  christos      out of program headers and refuses to link. */
   4114       1.1  christos   count += 4;
   4115       1.1  christos 
   4116   1.1.1.7  christos   return count;
   4117   1.1.1.4  christos }
   4118       1.1  christos 
   4119   1.1.1.4  christos 
   4120       1.1  christos bool
   4121       1.1  christos _bfd_tilegx_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   4122       1.1  christos {
   4123       1.1  christos   bfd *obfd = info->output_bfd;
   4124       1.1  christos   const char *targ1 = bfd_get_target (ibfd);
   4125   1.1.1.4  christos   const char *targ2 = bfd_get_target (obfd);
   4126   1.1.1.4  christos 
   4127   1.1.1.5  christos   if (strcmp (targ1, targ2) != 0)
   4128       1.1  christos     {
   4129       1.1  christos       _bfd_error_handler
   4130   1.1.1.7  christos 	/* xgettext:c-format */
   4131       1.1  christos 	(_("%pB: cannot link together %s and %s objects"),
   4132       1.1  christos 	 ibfd, targ1, targ2);
   4133   1.1.1.7  christos       bfd_set_error (bfd_error_bad_value);
   4134       1.1  christos       return false;
   4135                         }
   4136                     
   4137                       return true;
   4138                     }
   4139