Home | History | Annotate | Line # | Download | only in bfd
elf32-or1k.c revision 1.1.1.7
      1      1.1  christos /* Or1k-specific support for 32-bit ELF.
      2  1.1.1.7  christos    Copyright (C) 2001-2022 Free Software Foundation, Inc.
      3      1.1  christos    Contributed for OR32 by Johan Rydberg, jrydberg (at) opencores.org
      4      1.1  christos 
      5      1.1  christos    PIC parts added by Stefan Kristiansson, stefan.kristiansson (at) saunalahti.fi,
      6      1.1  christos    largely based on elf32-m32r.c and elf32-microblaze.c.
      7      1.1  christos 
      8      1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      9      1.1  christos 
     10      1.1  christos    This program is free software; you can redistribute it and/or modify
     11      1.1  christos    it under the terms of the GNU General Public License as published by
     12      1.1  christos    the Free Software Foundation; either version 3 of the License, or
     13      1.1  christos    (at your option) any later version.
     14      1.1  christos 
     15      1.1  christos    This program is distributed in the hope that it will be useful,
     16      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     17      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18      1.1  christos    GNU General Public License for more details.
     19      1.1  christos 
     20      1.1  christos    You should have received a copy of the GNU General Public License
     21      1.1  christos    along with this program; if not, see <http://www.gnu.org/licenses/>.  */
     22      1.1  christos 
     23      1.1  christos #include "sysdep.h"
     24      1.1  christos #include "bfd.h"
     25      1.1  christos #include "libbfd.h"
     26      1.1  christos #include "elf-bfd.h"
     27      1.1  christos #include "elf/or1k.h"
     28      1.1  christos #include "libiberty.h"
     29      1.1  christos 
     30  1.1.1.5  christos #define N_ONES(X)	(((bfd_vma)2 << (X)) - 1)
     31      1.1  christos 
     32  1.1.1.5  christos #define PLT_ENTRY_SIZE 16
     33  1.1.1.7  christos #define PLT_ENTRY_SIZE_LARGE (6*4)
     34  1.1.1.7  christos #define PLT_MAX_INSN_COUNT 6
     35  1.1.1.5  christos 
     36  1.1.1.5  christos #define OR1K_MOVHI(D)		(0x18000000 | (D << 21))
     37  1.1.1.5  christos #define OR1K_ADRP(D)		(0x08000000 | (D << 21))
     38  1.1.1.5  christos #define OR1K_LWZ(D,A)		(0x84000000 | (D << 21) | (A << 16))
     39  1.1.1.7  christos #define OR1K_ADD(D,A,B)		(0xE0000000 | (D << 21) | (A << 16) | (B << 11))
     40  1.1.1.7  christos #define OR1K_ORI(D,A)		(0xA8000000 | (D << 21) | (A << 16))
     41  1.1.1.5  christos #define OR1K_ORI0(D)		(0xA8000000 | (D << 21))
     42  1.1.1.5  christos #define OR1K_JR(B)		(0x44000000 | (B << 11))
     43  1.1.1.5  christos #define OR1K_NOP		0x15000000
     44      1.1  christos 
     45      1.1  christos #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
     46      1.1  christos 
     47      1.1  christos static reloc_howto_type or1k_elf_howto_table[] =
     48      1.1  christos {
     49      1.1  christos   /* This reloc does nothing.  */
     50  1.1.1.5  christos   HOWTO (R_OR1K_NONE,		/* type */
     51  1.1.1.5  christos 	 0,			/* rightshift */
     52  1.1.1.7  christos 	 0,			/* size */
     53  1.1.1.5  christos 	 0,			/* bitsize */
     54  1.1.1.7  christos 	 false,			/* pc_relative */
     55  1.1.1.5  christos 	 0,			/* bitpos */
     56  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
     57  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
     58  1.1.1.5  christos 	 "R_OR1K_NONE",		/* name */
     59  1.1.1.7  christos 	 false,			/* partial_inplace */
     60  1.1.1.5  christos 	 0,			/* src_mask */
     61  1.1.1.5  christos 	 0,			/* dst_mask */
     62  1.1.1.7  christos 	 false),		/* pcrel_offset */
     63      1.1  christos 
     64      1.1  christos   HOWTO (R_OR1K_32,
     65  1.1.1.5  christos 	 0,			/* rightshift */
     66  1.1.1.7  christos 	 4,			/* size */
     67  1.1.1.5  christos 	 32,			/* bitsize */
     68  1.1.1.7  christos 	 false,			/* pc_relative */
     69  1.1.1.5  christos 	 0,			/* bitpos */
     70  1.1.1.5  christos 	 complain_overflow_unsigned, /* complain_on_overflow */
     71  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
     72  1.1.1.5  christos 	 "R_OR1K_32",		/* name */
     73  1.1.1.7  christos 	 false,			/* partial_inplace */
     74  1.1.1.5  christos 	 0,			/* src_mask */
     75  1.1.1.5  christos 	 0xffffffff,		/* dst_mask */
     76  1.1.1.7  christos 	 false),		/* pcrel_offset */
     77      1.1  christos 
     78      1.1  christos   HOWTO (R_OR1K_16,
     79  1.1.1.5  christos 	 0,			/* rightshift */
     80  1.1.1.7  christos 	 2,			/* size */
     81  1.1.1.5  christos 	 16,			/* bitsize */
     82  1.1.1.7  christos 	 false,			/* pc_relative */
     83  1.1.1.5  christos 	 0,			/* bitpos */
     84  1.1.1.5  christos 	 complain_overflow_unsigned, /* complain_on_overflow */
     85  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
     86  1.1.1.5  christos 	 "R_OR1K_16",		/* name */
     87  1.1.1.7  christos 	 false,			/* partial_inplace */
     88  1.1.1.5  christos 	 0,			/* src_mask */
     89  1.1.1.5  christos 	 0xffff,		/* dst_mask */
     90  1.1.1.7  christos 	 false),		/* pcrel_offset */
     91      1.1  christos 
     92      1.1  christos   HOWTO (R_OR1K_8,
     93  1.1.1.5  christos 	 0,			/* rightshift */
     94  1.1.1.7  christos 	 1,			/* size */
     95  1.1.1.5  christos 	 8,			/* bitsize */
     96  1.1.1.7  christos 	 false,			/* pc_relative */
     97  1.1.1.5  christos 	 0,			/* bitpos */
     98  1.1.1.5  christos 	 complain_overflow_unsigned, /* complain_on_overflow */
     99  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    100  1.1.1.5  christos 	 "R_OR1K_8",		/* name */
    101  1.1.1.7  christos 	 false,			/* partial_inplace */
    102  1.1.1.5  christos 	 0,			/* src_mask */
    103  1.1.1.5  christos 	 0xff,			/* dst_mask */
    104  1.1.1.7  christos 	 false),		/* pcrel_offset */
    105      1.1  christos 
    106      1.1  christos   HOWTO (R_OR1K_LO_16_IN_INSN, /* type */
    107  1.1.1.5  christos 	 0,			/* rightshift */
    108  1.1.1.7  christos 	 4,			/* size */
    109  1.1.1.5  christos 	 16,			/* bitsize */
    110  1.1.1.7  christos 	 false,			/* pc_relative */
    111  1.1.1.5  christos 	 0,			/* bitpos */
    112  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    113  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    114  1.1.1.5  christos 	 "R_OR1K_LO_16_IN_INSN", /* name */
    115  1.1.1.7  christos 	 false,			/* partial_inplace */
    116  1.1.1.5  christos 	 0,			/* src_mask */
    117  1.1.1.5  christos 	 0x0000ffff,		/* dst_mask */
    118  1.1.1.7  christos 	 false),		/* pcrel_offset */
    119      1.1  christos 
    120      1.1  christos   HOWTO (R_OR1K_HI_16_IN_INSN, /* type */
    121  1.1.1.5  christos 	 16,			/* rightshift */
    122  1.1.1.7  christos 	 4,			/* size */
    123  1.1.1.5  christos 	 16,			/* bitsize */
    124  1.1.1.7  christos 	 false,			/* pc_relative */
    125  1.1.1.5  christos 	 0,			/* bitpos */
    126  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    127  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    128  1.1.1.5  christos 	 "R_OR1K_HI_16_IN_INSN", /* name */
    129  1.1.1.7  christos 	 false,			/* partial_inplace */
    130  1.1.1.5  christos 	 0,			/* src_mask */
    131  1.1.1.5  christos 	 0x0000ffff,		/* dst_mask */
    132  1.1.1.7  christos 	 false),		/* pcrel_offset */
    133      1.1  christos 
    134      1.1  christos   /* A PC relative 26 bit relocation, right shifted by 2.  */
    135      1.1  christos   HOWTO (R_OR1K_INSN_REL_26, /* type */
    136  1.1.1.5  christos 	 2,			/* rightshift */
    137  1.1.1.7  christos 	 4,			/* size */
    138  1.1.1.5  christos 	 26,			/* bitsize */
    139  1.1.1.7  christos 	 true,			/* pc_relative */
    140  1.1.1.5  christos 	 0,			/* bitpos */
    141  1.1.1.5  christos 	 complain_overflow_signed, /* complain_on_overflow */
    142  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    143  1.1.1.5  christos 	 "R_OR1K_INSN_REL_26", /* name */
    144  1.1.1.7  christos 	 false,			/* partial_inplace */
    145  1.1.1.5  christos 	 0,			/* src_mask */
    146  1.1.1.5  christos 	 0x03ffffff,		/* dst_mask */
    147  1.1.1.7  christos 	 true),			/* pcrel_offset */
    148      1.1  christos 
    149      1.1  christos   /* GNU extension to record C++ vtable hierarchy.  */
    150      1.1  christos   HOWTO (R_OR1K_GNU_VTINHERIT, /* type */
    151  1.1.1.5  christos 	 0,			/* rightshift */
    152  1.1.1.7  christos 	 4,			/* size */
    153  1.1.1.5  christos 	 0,			/* bitsize */
    154  1.1.1.7  christos 	 false,			/* pc_relative */
    155  1.1.1.5  christos 	 0,			/* bitpos */
    156  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    157  1.1.1.5  christos 	 NULL,			/* special_function */
    158  1.1.1.5  christos 	 "R_OR1K_GNU_VTINHERIT", /* name */
    159  1.1.1.7  christos 	 false,			/* partial_inplace */
    160  1.1.1.5  christos 	 0,			/* src_mask */
    161  1.1.1.5  christos 	 0,			/* dst_mask */
    162  1.1.1.7  christos 	 false),		/* pcrel_offset */
    163      1.1  christos 
    164      1.1  christos   /* GNU extension to record C++ vtable member usage.  */
    165      1.1  christos   HOWTO (R_OR1K_GNU_VTENTRY, /* type */
    166  1.1.1.5  christos 	 0,			/* rightshift */
    167  1.1.1.7  christos 	 4,			/* size */
    168  1.1.1.5  christos 	 0,			/* bitsize */
    169  1.1.1.7  christos 	 false,			/* pc_relative */
    170  1.1.1.5  christos 	 0,			/* bitpos */
    171  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    172  1.1.1.5  christos 	 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
    173  1.1.1.5  christos 	 "R_OR1K_GNU_VTENTRY", /* name */
    174  1.1.1.7  christos 	 false,			/* partial_inplace */
    175  1.1.1.5  christos 	 0,			/* src_mask */
    176  1.1.1.5  christos 	 0,			/* dst_mask */
    177  1.1.1.7  christos 	 false),		/* pcrel_offset */
    178      1.1  christos 
    179      1.1  christos   HOWTO (R_OR1K_32_PCREL,
    180  1.1.1.5  christos 	 0,			/* rightshift */
    181  1.1.1.7  christos 	 4,			/* size */
    182  1.1.1.5  christos 	 32,			/* bitsize */
    183  1.1.1.7  christos 	 true,			/* pc_relative */
    184  1.1.1.5  christos 	 0,			/* bitpos */
    185  1.1.1.5  christos 	 complain_overflow_signed, /* complain_on_overflow */
    186  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    187  1.1.1.5  christos 	 "R_OR1K_32_PCREL",	/* name */
    188  1.1.1.7  christos 	 false,			/* partial_inplace */
    189  1.1.1.5  christos 	 0,			/* src_mask */
    190  1.1.1.5  christos 	 0xffffffff,		/* dst_mask */
    191  1.1.1.7  christos 	 true),			/* pcrel_offset */
    192      1.1  christos 
    193      1.1  christos   HOWTO (R_OR1K_16_PCREL,
    194  1.1.1.5  christos 	 0,			/* rightshift */
    195  1.1.1.7  christos 	 2,			/* size */
    196  1.1.1.5  christos 	 16,			/* bitsize */
    197  1.1.1.7  christos 	 true,			/* pc_relative */
    198  1.1.1.5  christos 	 0,			/* bitpos */
    199  1.1.1.5  christos 	 complain_overflow_signed, /* complain_on_overflow */
    200  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    201  1.1.1.5  christos 	 "R_OR1K_16_PCREL",	/* name */
    202  1.1.1.7  christos 	 false,			/* partial_inplace */
    203  1.1.1.5  christos 	 0,			/* src_mask */
    204  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    205  1.1.1.7  christos 	 true),			/* pcrel_offset */
    206      1.1  christos 
    207      1.1  christos   HOWTO (R_OR1K_8_PCREL,
    208  1.1.1.5  christos 	 0,			/* rightshift */
    209  1.1.1.7  christos 	 1,			/* size */
    210  1.1.1.5  christos 	 8,			/* bitsize */
    211  1.1.1.7  christos 	 true,			/* pc_relative */
    212  1.1.1.5  christos 	 0,			/* bitpos */
    213  1.1.1.5  christos 	 complain_overflow_signed, /* complain_on_overflow */
    214  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    215  1.1.1.5  christos 	 "R_OR1K_8_PCREL",	/* name */
    216  1.1.1.7  christos 	 false,			/* partial_inplace */
    217  1.1.1.5  christos 	 0,			/* src_mask */
    218  1.1.1.5  christos 	 0xff,			/* dst_mask */
    219  1.1.1.7  christos 	 true),			/* pcrel_offset */
    220  1.1.1.5  christos 
    221  1.1.1.5  christos    HOWTO (R_OR1K_GOTPC_HI16,	/* Type.  */
    222  1.1.1.5  christos 	 16,			/* Rightshift.  */
    223  1.1.1.7  christos 	 4,			/* Size.  */
    224  1.1.1.5  christos 	 16,			/* Bitsize.  */
    225  1.1.1.7  christos 	 true,			/* PC_relative.  */
    226  1.1.1.5  christos 	 0,			/* Bitpos.  */
    227  1.1.1.5  christos 	 complain_overflow_dont, /* Complain on overflow.  */
    228  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* Special Function.  */
    229  1.1.1.5  christos 	 "R_OR1K_GOTPC_HI16",	/* Name.  */
    230  1.1.1.7  christos 	 false,		/* Partial Inplace.  */
    231  1.1.1.5  christos 	 0,			/* Source Mask.  */
    232  1.1.1.5  christos 	 0xffff,		/* Dest Mask.  */
    233  1.1.1.7  christos 	 true),			/* PC relative offset?  */
    234  1.1.1.5  christos 
    235  1.1.1.5  christos    HOWTO (R_OR1K_GOTPC_LO16,	/* Type.  */
    236  1.1.1.5  christos 	 0,			/* Rightshift.  */
    237  1.1.1.7  christos 	 4,			/* Size.  */
    238  1.1.1.5  christos 	 16,			/* Bitsize.  */
    239  1.1.1.7  christos 	 true,			/* PC_relative.  */
    240  1.1.1.5  christos 	 0,			/* Bitpos.  */
    241  1.1.1.5  christos 	 complain_overflow_dont, /* Complain on overflow.  */
    242  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* Special Function.  */
    243  1.1.1.5  christos 	 "R_OR1K_GOTPC_LO16",	/* Name.  */
    244  1.1.1.7  christos 	 false,		/* Partial Inplace.  */
    245  1.1.1.5  christos 	 0,			/* Source Mask.  */
    246  1.1.1.5  christos 	 0xffff,		/* Dest Mask.  */
    247  1.1.1.7  christos 	 true),			/* PC relative offset?  */
    248  1.1.1.5  christos 
    249  1.1.1.5  christos   HOWTO (R_OR1K_GOT16,		/* type */
    250  1.1.1.5  christos 	 0,			/* rightshift */
    251  1.1.1.7  christos 	 4,			/* size */
    252  1.1.1.5  christos 	 16,			/* bitsize */
    253  1.1.1.7  christos 	 false,			/* pc_relative */
    254  1.1.1.5  christos 	 0,			/* bitpos */
    255  1.1.1.5  christos 	 complain_overflow_signed, /* complain_on_overflow */
    256  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    257  1.1.1.5  christos 	 "R_OR1K_GOT16",	/* name */
    258  1.1.1.7  christos 	 false,			/* partial_inplace */
    259  1.1.1.5  christos 	 0,			/* src_mask */
    260  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    261  1.1.1.7  christos 	 false),		/* pcrel_offset */
    262      1.1  christos 
    263      1.1  christos   /* A 26 bit PLT relocation.  Shifted by 2.  */
    264  1.1.1.5  christos   HOWTO (R_OR1K_PLT26,		/* Type.  */
    265  1.1.1.5  christos 	 2,			/* Rightshift.  */
    266  1.1.1.7  christos 	 4,			/* Size.  */
    267  1.1.1.5  christos 	 26,			/* Bitsize.  */
    268  1.1.1.7  christos 	 true,			/* pc_relative.  */
    269  1.1.1.5  christos 	 0,			/* Bitpos.  */
    270  1.1.1.5  christos 	 complain_overflow_signed, /* Complain on overflow.  */
    271  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* Special Function.  */
    272  1.1.1.5  christos 	 "R_OR1K_PLT26",	/* Name.  */
    273  1.1.1.7  christos 	 false,			/* Partial Inplace.  */
    274  1.1.1.5  christos 	 0,			/* Source Mask.  */
    275  1.1.1.5  christos 	 0x03ffffff,		/* Dest Mask.  */
    276  1.1.1.7  christos 	 true),			/* PC relative offset?  */
    277  1.1.1.5  christos 
    278  1.1.1.5  christos   HOWTO (R_OR1K_GOTOFF_HI16,	/* type */
    279  1.1.1.5  christos 	 16,			/* rightshift */
    280  1.1.1.7  christos 	 4,			/* size */
    281  1.1.1.5  christos 	 16,			/* bitsize */
    282  1.1.1.7  christos 	 false,			/* pc_relative */
    283  1.1.1.5  christos 	 0,			/* bitpos */
    284  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    285  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    286  1.1.1.5  christos 	 "R_OR1K_GOTOFF_HI16",	/* name */
    287  1.1.1.7  christos 	 false,			/* partial_inplace */
    288  1.1.1.5  christos 	 0x0,			/* src_mask */
    289  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    290  1.1.1.7  christos 	 false),		/* pcrel_offset */
    291  1.1.1.5  christos 
    292  1.1.1.5  christos   HOWTO (R_OR1K_GOTOFF_LO16,	/* type */
    293  1.1.1.5  christos 	 0,			/* rightshift */
    294  1.1.1.7  christos 	 4,			/* size */
    295  1.1.1.5  christos 	 16,			/* bitsize */
    296  1.1.1.7  christos 	 false,			/* pc_relative */
    297  1.1.1.5  christos 	 0,			/* bitpos */
    298  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    299  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    300  1.1.1.5  christos 	 "R_OR1K_GOTOFF_LO16",	/* name */
    301  1.1.1.7  christos 	 false,			/* partial_inplace */
    302  1.1.1.5  christos 	 0x0,			/* src_mask */
    303  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    304  1.1.1.7  christos 	 false),		/* pcrel_offset */
    305  1.1.1.5  christos 
    306  1.1.1.5  christos   HOWTO (R_OR1K_COPY,		/* type */
    307  1.1.1.5  christos 	 0,			/* rightshift */
    308  1.1.1.7  christos 	 4,			/* size */
    309  1.1.1.5  christos 	 32,			/* bitsize */
    310  1.1.1.7  christos 	 false,			/* pc_relative */
    311  1.1.1.5  christos 	 0,			/* bitpos */
    312  1.1.1.5  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    313  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    314  1.1.1.5  christos 	 "R_OR1K_COPY",		/* name */
    315  1.1.1.7  christos 	 false,			/* partial_inplace */
    316  1.1.1.5  christos 	 0xffffffff,		/* src_mask */
    317  1.1.1.5  christos 	 0xffffffff,		/* dst_mask */
    318  1.1.1.7  christos 	 false),		/* pcrel_offset */
    319  1.1.1.5  christos 
    320  1.1.1.5  christos   HOWTO (R_OR1K_GLOB_DAT,	/* type */
    321  1.1.1.5  christos 	 0,			/* rightshift */
    322  1.1.1.7  christos 	 4,			/* size */
    323  1.1.1.5  christos 	 32,			/* bitsize */
    324  1.1.1.7  christos 	 false,			/* pc_relative */
    325  1.1.1.5  christos 	 0,			/* bitpos */
    326  1.1.1.5  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    327  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    328  1.1.1.5  christos 	 "R_OR1K_GLOB_DAT",	/* name */
    329  1.1.1.7  christos 	 false,			/* partial_inplace */
    330  1.1.1.5  christos 	 0xffffffff,		/* src_mask */
    331  1.1.1.5  christos 	 0xffffffff,		/* dst_mask */
    332  1.1.1.7  christos 	 false),		/* pcrel_offset */
    333  1.1.1.5  christos 
    334  1.1.1.5  christos   HOWTO (R_OR1K_JMP_SLOT,	/* type */
    335  1.1.1.5  christos 	 0,			/* rightshift */
    336  1.1.1.7  christos 	 4,			/* size */
    337  1.1.1.5  christos 	 32,			/* bitsize */
    338  1.1.1.7  christos 	 false,			/* pc_relative */
    339  1.1.1.5  christos 	 0,			/* bitpos */
    340  1.1.1.5  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    341  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    342  1.1.1.5  christos 	 "R_OR1K_JMP_SLOT",	/* name */
    343  1.1.1.7  christos 	 false,			/* partial_inplace */
    344  1.1.1.5  christos 	 0xffffffff,		/* src_mask */
    345  1.1.1.5  christos 	 0xffffffff,		/* dst_mask */
    346  1.1.1.7  christos 	 false),		/* pcrel_offset */
    347  1.1.1.5  christos 
    348  1.1.1.5  christos   HOWTO (R_OR1K_RELATIVE,	/* type */
    349  1.1.1.5  christos 	 0,			/* rightshift */
    350  1.1.1.7  christos 	 4,			/* size */
    351  1.1.1.5  christos 	 32,			/* bitsize */
    352  1.1.1.7  christos 	 false,			/* pc_relative */
    353  1.1.1.5  christos 	 0,			/* bitpos */
    354  1.1.1.5  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    355  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    356  1.1.1.5  christos 	 "R_OR1K_RELATIVE",	/* name */
    357  1.1.1.7  christos 	 false,			/* partial_inplace */
    358  1.1.1.5  christos 	 0xffffffff,		/* src_mask */
    359  1.1.1.5  christos 	 0xffffffff,		/* dst_mask */
    360  1.1.1.7  christos 	 false),		/* pcrel_offset */
    361  1.1.1.5  christos 
    362  1.1.1.5  christos   HOWTO (R_OR1K_TLS_GD_HI16,	/* type */
    363  1.1.1.5  christos 	 16,			/* rightshift */
    364  1.1.1.7  christos 	 4,			/* size */
    365  1.1.1.5  christos 	 16,			/* bitsize */
    366  1.1.1.7  christos 	 false,			/* pc_relative */
    367  1.1.1.5  christos 	 0,			/* bitpos */
    368  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    369  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    370  1.1.1.5  christos 	 "R_OR1K_TLS_GD_HI16",	/* name */
    371  1.1.1.7  christos 	 false,			/* partial_inplace */
    372  1.1.1.5  christos 	 0x0,			/* src_mask */
    373  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    374  1.1.1.7  christos 	 false),		/* pcrel_offset */
    375  1.1.1.5  christos 
    376  1.1.1.5  christos   HOWTO (R_OR1K_TLS_GD_LO16,	/* type */
    377  1.1.1.5  christos 	 0,			/* rightshift */
    378  1.1.1.7  christos 	 4,			/* size */
    379  1.1.1.5  christos 	 16,			/* bitsize */
    380  1.1.1.7  christos 	 false,			/* pc_relative */
    381  1.1.1.5  christos 	 0,			/* bitpos */
    382  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    383  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    384  1.1.1.5  christos 	 "R_OR1K_TLS_GD_LO16",	/* name */
    385  1.1.1.7  christos 	 false,			/* partial_inplace */
    386  1.1.1.5  christos 	 0x0,			/* src_mask */
    387  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    388  1.1.1.7  christos 	 false),		/* pcrel_offset */
    389  1.1.1.5  christos 
    390  1.1.1.5  christos   HOWTO (R_OR1K_TLS_LDM_HI16,	/* type */
    391  1.1.1.5  christos 	 16,			/* rightshift */
    392  1.1.1.7  christos 	 4,			/* size */
    393  1.1.1.5  christos 	 16,			/* bitsize */
    394  1.1.1.7  christos 	 false,			/* pc_relative */
    395  1.1.1.5  christos 	 0,			/* bitpos */
    396  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    397  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    398  1.1.1.5  christos 	 "R_OR1K_TLS_LDM_HI16", /* name */
    399  1.1.1.7  christos 	 false,			/* partial_inplace */
    400  1.1.1.5  christos 	 0x0,			/* src_mask */
    401  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    402  1.1.1.7  christos 	 false),		/* pcrel_offset */
    403  1.1.1.5  christos 
    404  1.1.1.5  christos   HOWTO (R_OR1K_TLS_LDM_LO16,	/* type */
    405  1.1.1.5  christos 	 0,			/* rightshift */
    406  1.1.1.7  christos 	 4,			/* size */
    407  1.1.1.5  christos 	 16,			/* bitsize */
    408  1.1.1.7  christos 	 false,			/* pc_relative */
    409  1.1.1.5  christos 	 0,			/* bitpos */
    410  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    411  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    412  1.1.1.5  christos 	 "R_OR1K_TLS_LDM_LO16", /* name */
    413  1.1.1.7  christos 	 false,			/* partial_inplace */
    414  1.1.1.5  christos 	 0x0,			/* src_mask */
    415  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    416  1.1.1.7  christos 	 false),		/* pcrel_offset */
    417  1.1.1.5  christos 
    418  1.1.1.5  christos   HOWTO (R_OR1K_TLS_LDO_HI16,	/* type */
    419  1.1.1.5  christos 	 16,			/* rightshift */
    420  1.1.1.7  christos 	 4,			/* size */
    421  1.1.1.5  christos 	 16,			/* bitsize */
    422  1.1.1.7  christos 	 false,			/* pc_relative */
    423  1.1.1.5  christos 	 0,			/* bitpos */
    424  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    425  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    426  1.1.1.5  christos 	 "R_OR1K_TLS_LDO_HI16", /* name */
    427  1.1.1.7  christos 	 false,			/* partial_inplace */
    428  1.1.1.5  christos 	 0x0,			/* src_mask */
    429  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    430  1.1.1.7  christos 	 false),		/* pcrel_offset */
    431  1.1.1.5  christos 
    432  1.1.1.5  christos   HOWTO (R_OR1K_TLS_LDO_LO16,	/* type */
    433  1.1.1.5  christos 	 0,			/* rightshift */
    434  1.1.1.7  christos 	 4,			/* size */
    435  1.1.1.5  christos 	 16,			/* bitsize */
    436  1.1.1.7  christos 	 false,			/* pc_relative */
    437  1.1.1.5  christos 	 0,			/* bitpos */
    438  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    439  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    440  1.1.1.5  christos 	 "R_OR1K_TLS_LDO_LO16", /* name */
    441  1.1.1.7  christos 	 false,			/* partial_inplace */
    442  1.1.1.5  christos 	 0x0,			/* src_mask */
    443  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    444  1.1.1.7  christos 	 false),		/* pcrel_offset */
    445  1.1.1.5  christos 
    446  1.1.1.5  christos   HOWTO (R_OR1K_TLS_IE_HI16,	/* type */
    447  1.1.1.5  christos 	 16,			/* rightshift */
    448  1.1.1.7  christos 	 4,			/* size */
    449  1.1.1.5  christos 	 16,			/* bitsize */
    450  1.1.1.7  christos 	 false,			/* pc_relative */
    451  1.1.1.5  christos 	 0,			/* bitpos */
    452  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    453  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    454  1.1.1.5  christos 	 "R_OR1K_TLS_IE_HI16",	/* name */
    455  1.1.1.7  christos 	 false,			/* partial_inplace */
    456  1.1.1.5  christos 	 0x0,			/* src_mask */
    457  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    458  1.1.1.7  christos 	 false),		/* pcrel_offset */
    459  1.1.1.5  christos 
    460  1.1.1.5  christos   HOWTO (R_OR1K_TLS_IE_LO16,	/* type */
    461  1.1.1.5  christos 	 0,			/* rightshift */
    462  1.1.1.7  christos 	 4,			/* size */
    463  1.1.1.5  christos 	 16,			/* bitsize */
    464  1.1.1.7  christos 	 false,			/* pc_relative */
    465  1.1.1.5  christos 	 0,			/* bitpos */
    466  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    467  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    468  1.1.1.5  christos 	 "R_OR1K_TLS_IE_LO16",	/* name */
    469  1.1.1.7  christos 	 false,			/* partial_inplace */
    470  1.1.1.5  christos 	 0x0,			/* src_mask */
    471  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    472  1.1.1.7  christos 	 false),		/* pcrel_offset */
    473  1.1.1.5  christos 
    474  1.1.1.5  christos   HOWTO (R_OR1K_TLS_LE_HI16,	/* type */
    475  1.1.1.5  christos 	 16,			/* rightshift */
    476  1.1.1.7  christos 	 4,			/* size */
    477  1.1.1.5  christos 	 16,			/* bitsize */
    478  1.1.1.7  christos 	 false,			/* pc_relative */
    479  1.1.1.5  christos 	 0,			/* bitpos */
    480  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    481  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    482  1.1.1.5  christos 	 "R_OR1K_TLS_LE_HI16",	/* name */
    483  1.1.1.7  christos 	 false,			/* partial_inplace */
    484  1.1.1.5  christos 	 0x0,			/* src_mask */
    485  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    486  1.1.1.7  christos 	 false),		/* pcrel_offset */
    487  1.1.1.5  christos 
    488  1.1.1.5  christos   HOWTO (R_OR1K_TLS_LE_LO16,	/* type */
    489  1.1.1.5  christos 	 0,			/* rightshift */
    490  1.1.1.7  christos 	 4,			/* size */
    491  1.1.1.5  christos 	 16,			/* bitsize */
    492  1.1.1.7  christos 	 false,			/* pc_relative */
    493  1.1.1.5  christos 	 0,			/* bitpos */
    494  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    495  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    496  1.1.1.5  christos 	 "R_OR1K_TLS_LE_LO16",	/* name */
    497  1.1.1.7  christos 	 false,			/* partial_inplace */
    498  1.1.1.5  christos 	 0x0,			/* src_mask */
    499  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    500  1.1.1.7  christos 	 false),		/* pcrel_offset */
    501  1.1.1.5  christos 
    502  1.1.1.5  christos   HOWTO (R_OR1K_TLS_TPOFF,	/* type */
    503  1.1.1.5  christos 	 0,			/* rightshift */
    504  1.1.1.7  christos 	 4,			/* size */
    505  1.1.1.5  christos 	 32,			/* bitsize */
    506  1.1.1.7  christos 	 false,			/* pc_relative */
    507  1.1.1.5  christos 	 0,			/* bitpos */
    508  1.1.1.5  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    509  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    510  1.1.1.5  christos 	 "R_OR1K_TLS_TPOFF",    /* name */
    511  1.1.1.7  christos 	 false,			/* partial_inplace */
    512  1.1.1.5  christos 	 0xffffffff,		/* src_mask */
    513  1.1.1.5  christos 	 0xffffffff,		/* dst_mask */
    514  1.1.1.7  christos 	 false),		/* pcrel_offset */
    515  1.1.1.5  christos 
    516  1.1.1.5  christos   HOWTO (R_OR1K_TLS_DTPOFF,	/* type */
    517  1.1.1.5  christos 	 0,			/* rightshift */
    518  1.1.1.7  christos 	 4,			/* size */
    519  1.1.1.5  christos 	 32,			/* bitsize */
    520  1.1.1.7  christos 	 false,			/* pc_relative */
    521  1.1.1.5  christos 	 0,			/* bitpos */
    522  1.1.1.5  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    523  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    524  1.1.1.5  christos 	 "R_OR1K_TLS_DTPOFF",   /* name */
    525  1.1.1.7  christos 	 false,			/* partial_inplace */
    526  1.1.1.5  christos 	 0xffffffff,		/* src_mask */
    527  1.1.1.5  christos 	 0xffffffff,		/* dst_mask */
    528  1.1.1.7  christos 	 false),		/* pcrel_offset */
    529  1.1.1.5  christos 
    530  1.1.1.5  christos   HOWTO (R_OR1K_TLS_DTPMOD,	/* type */
    531  1.1.1.5  christos 	 0,			/* rightshift */
    532  1.1.1.7  christos 	 4,			/* size */
    533  1.1.1.5  christos 	 32,			/* bitsize */
    534  1.1.1.7  christos 	 false,			/* pc_relative */
    535  1.1.1.5  christos 	 0,			/* bitpos */
    536  1.1.1.5  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    537  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    538  1.1.1.5  christos 	 "R_OR1K_TLS_DTPMOD",   /* name */
    539  1.1.1.7  christos 	 false,			/* partial_inplace */
    540  1.1.1.5  christos 	 0xffffffff,		/* src_mask */
    541  1.1.1.5  christos 	 0xffffffff,		/* dst_mask */
    542  1.1.1.7  christos 	 false),		/* pcrel_offset */
    543  1.1.1.5  christos 
    544  1.1.1.5  christos   HOWTO (R_OR1K_AHI16,		/* type */
    545  1.1.1.5  christos 	 16,			/* rightshift */
    546  1.1.1.7  christos 	 4,			/* size */
    547  1.1.1.5  christos 	 16,			/* bitsize */
    548  1.1.1.7  christos 	 false,			/* pc_relative */
    549  1.1.1.5  christos 	 0,			/* bitpos */
    550  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    551  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    552  1.1.1.5  christos 	 "R_OR1K_AHI16",	/* name */
    553  1.1.1.7  christos 	 false,			/* partial_inplace */
    554  1.1.1.5  christos 	 0x0,			/* src_mask */
    555  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    556  1.1.1.7  christos 	 false),		/* pcrel_offset */
    557  1.1.1.5  christos 
    558  1.1.1.5  christos   HOWTO (R_OR1K_GOTOFF_AHI16,	/* type */
    559  1.1.1.5  christos 	 16,			/* rightshift */
    560  1.1.1.7  christos 	 4,			/* size */
    561  1.1.1.5  christos 	 16,			/* bitsize */
    562  1.1.1.7  christos 	 false,			/* pc_relative */
    563  1.1.1.5  christos 	 0,			/* bitpos */
    564  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    565  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    566  1.1.1.5  christos 	 "R_OR1K_GOTOFF_AHI16", /* name */
    567  1.1.1.7  christos 	 false,			/* partial_inplace */
    568  1.1.1.5  christos 	 0x0,			/* src_mask */
    569  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    570  1.1.1.7  christos 	 false),		/* pcrel_offset */
    571  1.1.1.5  christos 
    572  1.1.1.5  christos   HOWTO (R_OR1K_TLS_IE_AHI16,   /* type */
    573  1.1.1.5  christos 	 16,			/* rightshift */
    574  1.1.1.7  christos 	 4,			/* size */
    575  1.1.1.5  christos 	 16,			/* bitsize */
    576  1.1.1.7  christos 	 false,			/* pc_relative */
    577  1.1.1.5  christos 	 0,			/* bitpos */
    578  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    579  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    580  1.1.1.5  christos 	 "R_OR1K_TLS_IE_AHI16", /* name */
    581  1.1.1.7  christos 	 false,			/* partial_inplace */
    582  1.1.1.5  christos 	 0x0,			/* src_mask */
    583  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    584  1.1.1.7  christos 	 false),		/* pcrel_offset */
    585  1.1.1.5  christos 
    586  1.1.1.5  christos   HOWTO (R_OR1K_TLS_LE_AHI16,	/* type */
    587  1.1.1.5  christos 	 16,			/* rightshift */
    588  1.1.1.7  christos 	 4,			/* size */
    589  1.1.1.5  christos 	 16,			/* bitsize */
    590  1.1.1.7  christos 	 false,			/* pc_relative */
    591  1.1.1.5  christos 	 0,			/* bitpos */
    592  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    593  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    594  1.1.1.5  christos 	 "R_OR1K_TLS_LE_AHI16", /* name */
    595  1.1.1.7  christos 	 false,			/* partial_inplace */
    596  1.1.1.5  christos 	 0x0,			/* src_mask */
    597  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    598  1.1.1.7  christos 	 false),		/* pcrel_offset */
    599  1.1.1.5  christos 
    600  1.1.1.5  christos   HOWTO (R_OR1K_SLO16,		/* type */
    601  1.1.1.5  christos 	 0,			/* rightshift */
    602  1.1.1.7  christos 	 4,			/* size */
    603  1.1.1.5  christos 	 16,			/* bitsize */
    604  1.1.1.7  christos 	 false,			/* pc_relative */
    605  1.1.1.5  christos 	 0,			/* bitpos */
    606  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    607  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    608  1.1.1.5  christos 	 "R_OR1K_SLO16",	/* name */
    609  1.1.1.7  christos 	 false,			/* partial_inplace */
    610  1.1.1.5  christos 	 0x0,			/* src_mask */
    611  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    612  1.1.1.7  christos 	 false),		/* pcrel_offset */
    613  1.1.1.5  christos 
    614  1.1.1.5  christos   HOWTO (R_OR1K_GOTOFF_SLO16,	/* type */
    615  1.1.1.5  christos 	 0,			/* rightshift */
    616  1.1.1.7  christos 	 4,			/* size */
    617  1.1.1.5  christos 	 16,			/* bitsize */
    618  1.1.1.7  christos 	 false,			/* pc_relative */
    619  1.1.1.5  christos 	 0,			/* bitpos */
    620  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    621  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    622  1.1.1.5  christos 	 "R_OR1K_GOTOFF_SLO16", /* name */
    623  1.1.1.7  christos 	 false,			/* partial_inplace */
    624  1.1.1.5  christos 	 0x0,			/* src_mask */
    625  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    626  1.1.1.7  christos 	 false),		/* pcrel_offset */
    627  1.1.1.5  christos 
    628  1.1.1.5  christos   HOWTO (R_OR1K_TLS_LE_SLO16,   /* type */
    629  1.1.1.5  christos 	 0,			/* rightshift */
    630  1.1.1.7  christos 	 4,			/* size */
    631  1.1.1.5  christos 	 16,			/* bitsize */
    632  1.1.1.7  christos 	 false,			/* pc_relative */
    633  1.1.1.5  christos 	 0,			/* bitpos */
    634  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    635  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    636  1.1.1.5  christos 	 "R_OR1K_TLS_LE_SLO16", /* name */
    637  1.1.1.7  christos 	 false,			/* partial_inplace */
    638  1.1.1.5  christos 	 0x0,			/* src_mask */
    639  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    640  1.1.1.7  christos 	 false),		/* pcrel_offset */
    641  1.1.1.5  christos 
    642  1.1.1.5  christos   /* A page relative 21 bit relocation, right shifted by 13, aligned.
    643  1.1.1.5  christos      Note that this is *page* relative, not pc relative.  The idea is
    644  1.1.1.5  christos      similar, but normally the section alignment is not such that the
    645  1.1.1.5  christos      assembler can infer a final value, which it attempts to do with
    646  1.1.1.5  christos      pc-relative relocations to local symbols.  */
    647  1.1.1.5  christos   HOWTO (R_OR1K_PCREL_PG21,    /* type */
    648  1.1.1.5  christos 	 13,			/* rightshift */
    649  1.1.1.7  christos 	 4,			/* size */
    650  1.1.1.5  christos 	 21,			/* bitsize */
    651  1.1.1.7  christos 	 false,			/* pc_relative */
    652  1.1.1.5  christos 	 0,			/* bitpos */
    653  1.1.1.5  christos 	 complain_overflow_signed, /* complain_on_overflow */
    654  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    655  1.1.1.5  christos 	 "R_OR1K_PCREL_PG21",   /* name */
    656  1.1.1.7  christos 	 false,			/* partial_inplace */
    657  1.1.1.5  christos 	 0,			/* src_mask */
    658  1.1.1.5  christos 	 0x001fffff,		/* dst_mask */
    659  1.1.1.7  christos 	 true),			/* pcrel_offset */
    660  1.1.1.5  christos 
    661  1.1.1.5  christos   HOWTO (R_OR1K_GOT_PG21,       /* type */
    662  1.1.1.5  christos 	 13,			/* rightshift */
    663  1.1.1.7  christos 	 4,			/* size */
    664  1.1.1.5  christos 	 21,			/* bitsize */
    665  1.1.1.7  christos 	 false,			/* pc_relative */
    666  1.1.1.5  christos 	 0,			/* bitpos */
    667  1.1.1.5  christos 	 complain_overflow_signed, /* complain_on_overflow */
    668  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    669  1.1.1.5  christos 	 "R_OR1K_GOT_PG21",     /* name */
    670  1.1.1.7  christos 	 false,			/* partial_inplace */
    671  1.1.1.5  christos 	 0,			/* src_mask */
    672  1.1.1.5  christos 	 0x001fffff,		/* dst_mask */
    673  1.1.1.7  christos 	 true),			/* pcrel_offset */
    674  1.1.1.5  christos 
    675  1.1.1.5  christos   HOWTO (R_OR1K_TLS_GD_PG21,    /* type */
    676  1.1.1.5  christos 	 13,			/* rightshift */
    677  1.1.1.7  christos 	 4,			/* size */
    678  1.1.1.5  christos 	 21,			/* bitsize */
    679  1.1.1.7  christos 	 false,			/* pc_relative */
    680  1.1.1.5  christos 	 0,			/* bitpos */
    681  1.1.1.5  christos 	 complain_overflow_signed, /* complain_on_overflow */
    682  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    683  1.1.1.5  christos 	 "R_OR1K_TLS_GD_PG21",  /* name */
    684  1.1.1.7  christos 	 false,			/* partial_inplace */
    685  1.1.1.5  christos 	 0,			/* src_mask */
    686  1.1.1.5  christos 	 0x001fffff,		/* dst_mask */
    687  1.1.1.7  christos 	 true),			/* pcrel_offset */
    688  1.1.1.5  christos 
    689  1.1.1.5  christos   HOWTO (R_OR1K_TLS_LDM_PG21,   /* type */
    690  1.1.1.5  christos 	 13,			/* rightshift */
    691  1.1.1.7  christos 	 4,			/* size */
    692  1.1.1.5  christos 	 21,			/* bitsize */
    693  1.1.1.7  christos 	 false,			/* pc_relative */
    694  1.1.1.5  christos 	 0,			/* bitpos */
    695  1.1.1.5  christos 	 complain_overflow_signed, /* complain_on_overflow */
    696  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    697  1.1.1.5  christos 	 "R_OR1K_TLS_LDM_PG21", /* name */
    698  1.1.1.7  christos 	 false,			/* partial_inplace */
    699  1.1.1.5  christos 	 0,			/* src_mask */
    700  1.1.1.5  christos 	 0x001fffff,		/* dst_mask */
    701  1.1.1.7  christos 	 true),			/* pcrel_offset */
    702  1.1.1.5  christos 
    703  1.1.1.5  christos   HOWTO (R_OR1K_TLS_IE_PG21,    /* type */
    704  1.1.1.5  christos 	 13,			/* rightshift */
    705  1.1.1.7  christos 	 4,			/* size */
    706  1.1.1.5  christos 	 21,			/* bitsize */
    707  1.1.1.7  christos 	 false,			/* pc_relative */
    708  1.1.1.5  christos 	 0,			/* bitpos */
    709  1.1.1.5  christos 	 complain_overflow_signed, /* complain_on_overflow */
    710  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    711  1.1.1.5  christos 	 "R_OR1K_TLS_IE_PG21",  /* name */
    712  1.1.1.7  christos 	 false,			/* partial_inplace */
    713  1.1.1.5  christos 	 0,			/* src_mask */
    714  1.1.1.5  christos 	 0x001fffff,		/* dst_mask */
    715  1.1.1.7  christos 	 true),			/* pcrel_offset */
    716  1.1.1.5  christos 
    717  1.1.1.5  christos   HOWTO (R_OR1K_LO13,		/* type */
    718  1.1.1.5  christos 	 0,			/* rightshift */
    719  1.1.1.7  christos 	 4,			/* size */
    720  1.1.1.5  christos 	 16,			/* bitsize */
    721  1.1.1.7  christos 	 false,			/* pc_relative */
    722  1.1.1.5  christos 	 0,			/* bitpos */
    723  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    724  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    725  1.1.1.5  christos 	 "R_OR1K_LO13",		/* name */
    726  1.1.1.7  christos 	 false,			/* partial_inplace */
    727  1.1.1.5  christos 	 0x0,			/* src_mask */
    728  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    729  1.1.1.7  christos 	 false),		/* pcrel_offset */
    730  1.1.1.5  christos 
    731  1.1.1.5  christos   HOWTO (R_OR1K_GOT_LO13,       /* type */
    732  1.1.1.5  christos 	 0,			/* rightshift */
    733  1.1.1.7  christos 	 4,			/* size */
    734  1.1.1.5  christos 	 16,			/* bitsize */
    735  1.1.1.7  christos 	 false,			/* pc_relative */
    736  1.1.1.5  christos 	 0,			/* bitpos */
    737  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    738  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    739  1.1.1.5  christos 	 "R_OR1K_GOT_LO13",     /* name */
    740  1.1.1.7  christos 	 false,			/* partial_inplace */
    741  1.1.1.5  christos 	 0x0,			/* src_mask */
    742  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    743  1.1.1.7  christos 	 false),		/* pcrel_offset */
    744  1.1.1.5  christos 
    745  1.1.1.5  christos   HOWTO (R_OR1K_TLS_GD_LO13,    /* type */
    746  1.1.1.5  christos 	 0,			/* rightshift */
    747  1.1.1.7  christos 	 4,			/* size */
    748  1.1.1.5  christos 	 16,			/* bitsize */
    749  1.1.1.7  christos 	 false,			/* pc_relative */
    750  1.1.1.5  christos 	 0,			/* bitpos */
    751  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    752  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    753  1.1.1.5  christos 	 "R_OR1K_TLS_GD_LO13",  /* name */
    754  1.1.1.7  christos 	 false,			/* partial_inplace */
    755  1.1.1.5  christos 	 0x0,			/* src_mask */
    756  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    757  1.1.1.7  christos 	 false),		/* pcrel_offset */
    758  1.1.1.5  christos 
    759  1.1.1.5  christos   HOWTO (R_OR1K_TLS_LDM_LO13,   /* type */
    760  1.1.1.5  christos 	 0,			/* rightshift */
    761  1.1.1.7  christos 	 4,			/* size */
    762  1.1.1.5  christos 	 16,			/* bitsize */
    763  1.1.1.7  christos 	 false,			/* pc_relative */
    764  1.1.1.5  christos 	 0,			/* bitpos */
    765  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    766  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    767  1.1.1.5  christos 	 "R_OR1K_TLD_LDM_LO13", /* name */
    768  1.1.1.7  christos 	 false,			/* partial_inplace */
    769  1.1.1.5  christos 	 0x0,			/* src_mask */
    770  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    771  1.1.1.7  christos 	 false),		/* pcrel_offset */
    772  1.1.1.5  christos 
    773  1.1.1.5  christos   HOWTO (R_OR1K_TLS_IE_LO13,    /* type */
    774  1.1.1.5  christos 	 0,			/* rightshift */
    775  1.1.1.7  christos 	 4,			/* size */
    776  1.1.1.5  christos 	 16,			/* bitsize */
    777  1.1.1.7  christos 	 false,			/* pc_relative */
    778  1.1.1.5  christos 	 0,			/* bitpos */
    779  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    780  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    781  1.1.1.5  christos 	 "R_OR1K_TLS_IE_LO13",  /* name */
    782  1.1.1.7  christos 	 false,			/* partial_inplace */
    783  1.1.1.5  christos 	 0x0,			/* src_mask */
    784  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    785  1.1.1.7  christos 	 false),		/* pcrel_offset */
    786  1.1.1.5  christos 
    787  1.1.1.5  christos   HOWTO (R_OR1K_SLO13,		/* type */
    788  1.1.1.5  christos 	 0,			/* rightshift */
    789  1.1.1.7  christos 	 4,			/* size */
    790  1.1.1.5  christos 	 16,			/* bitsize */
    791  1.1.1.7  christos 	 false,			/* pc_relative */
    792  1.1.1.5  christos 	 0,			/* bitpos */
    793  1.1.1.5  christos 	 complain_overflow_dont, /* complain_on_overflow */
    794  1.1.1.5  christos 	 bfd_elf_generic_reloc, /* special_function */
    795  1.1.1.5  christos 	 "R_OR1K_SLO13",	/* name */
    796  1.1.1.7  christos 	 false,			/* partial_inplace */
    797  1.1.1.5  christos 	 0x0,			/* src_mask */
    798  1.1.1.5  christos 	 0xffff,		/* dst_mask */
    799  1.1.1.7  christos 	 false),		/* pcrel_offset */
    800  1.1.1.5  christos 
    801  1.1.1.5  christos   /* A 26 bit PLT relocation, using ADRP.  Shifted by 2.  */
    802  1.1.1.5  christos   HOWTO (R_OR1K_PLTA26,		/* Type.  */
    803  1.1.1.5  christos 	 2,			/* Rightshift.  */
    804  1.1.1.7  christos 	 4,			/* Size.  */
    805  1.1.1.5  christos 	 26,			/* Bitsize.  */
    806  1.1.1.7  christos 	 true,			/* pc_relative.  */
    807  1.1.1.5  christos 	 0,			/* Bitpos.  */
    808  1.1.1.5  christos 	 complain_overflow_signed, /* Complain on overflow.  */
    809  1.1.1.5  christos 	 bfd_elf_generic_reloc,	/* Special Function.  */
    810  1.1.1.5  christos 	 "R_OR1K_PLTA26",	/* Name.  */
    811  1.1.1.7  christos 	 false,			/* Partial Inplace.  */
    812  1.1.1.5  christos 	 0,			/* Source Mask.  */
    813  1.1.1.5  christos 	 0x03ffffff,		/* Dest Mask.  */
    814  1.1.1.7  christos 	 true),			/* PC relative offset?  */
    815  1.1.1.7  christos 
    816  1.1.1.7  christos   HOWTO (R_OR1K_GOT_AHI16,	/* type */
    817  1.1.1.7  christos 	 16,			/* rightshift */
    818  1.1.1.7  christos 	 4,			/* size */
    819  1.1.1.7  christos 	 16,			/* bitsize */
    820  1.1.1.7  christos 	 false,			/* pc_relative */
    821  1.1.1.7  christos 	 0,			/* bitpos */
    822  1.1.1.7  christos 	 complain_overflow_signed, /* complain_on_overflow */
    823  1.1.1.7  christos 	 bfd_elf_generic_reloc, /* special_function */
    824  1.1.1.7  christos 	 "R_OR1K_GOT_AHI16",	/* name */
    825  1.1.1.7  christos 	 false,			/* partial_inplace */
    826  1.1.1.7  christos 	 0,			/* src_mask */
    827  1.1.1.7  christos 	 0xffff,		/* dst_mask */
    828  1.1.1.7  christos 	 false),		/* pcrel_offset */
    829      1.1  christos };
    830      1.1  christos 
    831  1.1.1.7  christos /* A copy of the R_OR1K_GOT16 used in the presense of R_OR1K_GOT_AHI16
    832  1.1.1.7  christos    relocations when we know we can ignore overflows.  */
    833  1.1.1.7  christos static reloc_howto_type or1k_elf_got16_no_overflow_howto =
    834  1.1.1.7  christos   HOWTO (R_OR1K_GOT16,		/* type */
    835  1.1.1.7  christos 	 0,			/* rightshift */
    836  1.1.1.7  christos 	 4,			/* size */
    837  1.1.1.7  christos 	 16,			/* bitsize */
    838  1.1.1.7  christos 	 false,			/* pc_relative */
    839  1.1.1.7  christos 	 0,			/* bitpos */
    840  1.1.1.7  christos 	 complain_overflow_dont, /* complain_on_overflow */
    841  1.1.1.7  christos 	 bfd_elf_generic_reloc, /* special_function */
    842  1.1.1.7  christos 	 "R_OR1K_GOT16",	/* name */
    843  1.1.1.7  christos 	 false,			/* partial_inplace */
    844  1.1.1.7  christos 	 0,			/* src_mask */
    845  1.1.1.7  christos 	 0xffff,		/* dst_mask */
    846  1.1.1.7  christos 	 false);		/* pcrel_offset */
    847  1.1.1.7  christos 
    848      1.1  christos /* Map BFD reloc types to Or1k ELF reloc types.  */
    849      1.1  christos 
    850      1.1  christos struct or1k_reloc_map
    851      1.1  christos {
    852      1.1  christos   bfd_reloc_code_real_type bfd_reloc_val;
    853      1.1  christos   unsigned int or1k_reloc_val;
    854      1.1  christos };
    855      1.1  christos 
    856      1.1  christos static const struct or1k_reloc_map or1k_reloc_map[] =
    857      1.1  christos {
    858  1.1.1.5  christos   { BFD_RELOC_NONE,		R_OR1K_NONE },
    859  1.1.1.5  christos   { BFD_RELOC_32,		R_OR1K_32 },
    860  1.1.1.5  christos   { BFD_RELOC_16,		R_OR1K_16 },
    861  1.1.1.5  christos   { BFD_RELOC_8,		R_OR1K_8 },
    862  1.1.1.5  christos   { BFD_RELOC_LO16,		R_OR1K_LO_16_IN_INSN },
    863  1.1.1.5  christos   { BFD_RELOC_HI16,		R_OR1K_HI_16_IN_INSN },
    864  1.1.1.5  christos   { BFD_RELOC_HI16_S,		R_OR1K_AHI16 },
    865  1.1.1.5  christos   { BFD_RELOC_OR1K_REL_26,	R_OR1K_INSN_REL_26 },
    866  1.1.1.5  christos   { BFD_RELOC_VTABLE_ENTRY,	R_OR1K_GNU_VTENTRY },
    867  1.1.1.5  christos   { BFD_RELOC_VTABLE_INHERIT,	R_OR1K_GNU_VTINHERIT },
    868  1.1.1.5  christos   { BFD_RELOC_32_PCREL,		R_OR1K_32_PCREL },
    869  1.1.1.5  christos   { BFD_RELOC_16_PCREL,		R_OR1K_16_PCREL },
    870  1.1.1.5  christos   { BFD_RELOC_8_PCREL,		R_OR1K_8_PCREL },
    871  1.1.1.5  christos   { BFD_RELOC_LO16_GOTOFF,	R_OR1K_GOTOFF_LO16 },
    872  1.1.1.5  christos   { BFD_RELOC_HI16_GOTOFF,	R_OR1K_GOTOFF_HI16 },
    873  1.1.1.5  christos   { BFD_RELOC_HI16_S_GOTOFF,	R_OR1K_GOTOFF_AHI16 },
    874  1.1.1.5  christos   { BFD_RELOC_OR1K_GOTPC_HI16,	R_OR1K_GOTPC_HI16 },
    875  1.1.1.5  christos   { BFD_RELOC_OR1K_GOTPC_LO16,	R_OR1K_GOTPC_LO16 },
    876  1.1.1.5  christos   { BFD_RELOC_OR1K_GOT16,	R_OR1K_GOT16 },
    877  1.1.1.5  christos   { BFD_RELOC_OR1K_PLT26,	R_OR1K_PLT26 },
    878  1.1.1.5  christos   { BFD_RELOC_OR1K_GLOB_DAT,	R_OR1K_GLOB_DAT },
    879  1.1.1.5  christos   { BFD_RELOC_OR1K_COPY,	R_OR1K_COPY },
    880  1.1.1.5  christos   { BFD_RELOC_OR1K_JMP_SLOT,	R_OR1K_JMP_SLOT },
    881  1.1.1.5  christos   { BFD_RELOC_OR1K_RELATIVE,	R_OR1K_RELATIVE },
    882      1.1  christos   { BFD_RELOC_OR1K_TLS_GD_HI16, R_OR1K_TLS_GD_HI16 },
    883      1.1  christos   { BFD_RELOC_OR1K_TLS_GD_LO16, R_OR1K_TLS_GD_LO16 },
    884  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_LDM_HI16,	R_OR1K_TLS_LDM_HI16 },
    885  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_LDM_LO16,	R_OR1K_TLS_LDM_LO16 },
    886  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_LDO_HI16,	R_OR1K_TLS_LDO_HI16 },
    887  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_LDO_LO16,	R_OR1K_TLS_LDO_LO16 },
    888      1.1  christos   { BFD_RELOC_OR1K_TLS_IE_HI16, R_OR1K_TLS_IE_HI16 },
    889      1.1  christos   { BFD_RELOC_OR1K_TLS_IE_LO16, R_OR1K_TLS_IE_LO16 },
    890  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_IE_AHI16, R_OR1K_TLS_IE_AHI16 },
    891      1.1  christos   { BFD_RELOC_OR1K_TLS_LE_HI16, R_OR1K_TLS_LE_HI16 },
    892      1.1  christos   { BFD_RELOC_OR1K_TLS_LE_LO16, R_OR1K_TLS_LE_LO16 },
    893  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_LE_AHI16, R_OR1K_TLS_LE_AHI16 },
    894  1.1.1.5  christos   { BFD_RELOC_OR1K_SLO16,	R_OR1K_SLO16 },
    895  1.1.1.5  christos   { BFD_RELOC_OR1K_GOTOFF_SLO16, R_OR1K_GOTOFF_SLO16 },
    896  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_LE_SLO16, R_OR1K_TLS_LE_SLO16 },
    897  1.1.1.5  christos   { BFD_RELOC_OR1K_PCREL_PG21,	R_OR1K_PCREL_PG21 },
    898  1.1.1.5  christos   { BFD_RELOC_OR1K_GOT_PG21,	R_OR1K_GOT_PG21 },
    899  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_GD_PG21,	R_OR1K_TLS_GD_PG21 },
    900  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_LDM_PG21, R_OR1K_TLS_LDM_PG21 },
    901  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_IE_PG21,	R_OR1K_TLS_IE_PG21 },
    902  1.1.1.5  christos   { BFD_RELOC_OR1K_LO13,	R_OR1K_LO13 },
    903  1.1.1.5  christos   { BFD_RELOC_OR1K_GOT_LO13,	R_OR1K_GOT_LO13 },
    904  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_GD_LO13,	R_OR1K_TLS_GD_LO13 },
    905  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_LDM_LO13, R_OR1K_TLS_LDM_LO13 },
    906  1.1.1.5  christos   { BFD_RELOC_OR1K_TLS_IE_LO13,	R_OR1K_TLS_IE_LO13 },
    907  1.1.1.5  christos   { BFD_RELOC_OR1K_SLO13,	R_OR1K_SLO13 },
    908  1.1.1.5  christos   { BFD_RELOC_OR1K_PLTA26,	R_OR1K_PLTA26 },
    909  1.1.1.7  christos   { BFD_RELOC_OR1K_GOT_AHI16,	R_OR1K_GOT_AHI16 },
    910      1.1  christos };
    911      1.1  christos 
    912  1.1.1.6  christos /* tls_type is a mask used to track how each symbol is accessed,
    913  1.1.1.6  christos    it may be accessed via multiple types of TLS access methods.
    914  1.1.1.6  christos    We track this for sizing (allocating got + relocation section space) and
    915  1.1.1.6  christos    for how to process relocations.  */
    916      1.1  christos #define TLS_UNKNOWN    0
    917      1.1  christos #define TLS_NONE       1
    918  1.1.1.5  christos #define TLS_GD	       2
    919  1.1.1.6  christos #define TLS_LD	       4
    920  1.1.1.6  christos #define TLS_IE	       8
    921  1.1.1.6  christos #define TLS_LE	      16
    922  1.1.1.6  christos 
    923  1.1.1.6  christos /* The size of the TLS thread control block, used to offset LE access.  */
    924  1.1.1.6  christos #define TCB_SIZE      16
    925      1.1  christos 
    926      1.1  christos /* ELF linker hash entry.  */
    927      1.1  christos struct elf_or1k_link_hash_entry
    928      1.1  christos {
    929      1.1  christos   struct elf_link_hash_entry root;
    930      1.1  christos 
    931  1.1.1.7  christos   /* For calculating PLT size.  */
    932  1.1.1.7  christos   bfd_vma plt_index;
    933      1.1  christos   /* Track type of TLS access.  */
    934      1.1  christos   unsigned char tls_type;
    935      1.1  christos };
    936      1.1  christos 
    937      1.1  christos /* ELF object data.  */
    938      1.1  christos struct elf_or1k_obj_tdata
    939      1.1  christos {
    940      1.1  christos   struct elf_obj_tdata root;
    941      1.1  christos 
    942      1.1  christos   /* tls_type for each local got entry.  */
    943      1.1  christos   unsigned char *local_tls_type;
    944      1.1  christos };
    945      1.1  christos 
    946      1.1  christos #define elf_or1k_tdata(abfd) \
    947      1.1  christos   ((struct elf_or1k_obj_tdata *) (abfd)->tdata.any)
    948      1.1  christos 
    949      1.1  christos #define elf_or1k_local_tls_type(abfd) \
    950      1.1  christos   (elf_or1k_tdata (abfd)->local_tls_type)
    951      1.1  christos 
    952      1.1  christos /* ELF linker hash table.  */
    953      1.1  christos struct elf_or1k_link_hash_table
    954      1.1  christos {
    955      1.1  christos   struct elf_link_hash_table root;
    956      1.1  christos 
    957  1.1.1.7  christos   bfd_vma plt_count;
    958  1.1.1.7  christos   bool saw_plta;
    959      1.1  christos };
    960      1.1  christos 
    961  1.1.1.7  christos static size_t
    962  1.1.1.7  christos elf_or1k_plt_entry_size (bfd_vma plt_index)
    963  1.1.1.7  christos {
    964  1.1.1.7  christos   bfd_vma plt_reloc;
    965  1.1.1.7  christos 
    966  1.1.1.7  christos   plt_reloc = plt_index * sizeof (Elf32_External_Rela);
    967  1.1.1.7  christos 
    968  1.1.1.7  christos   return (plt_reloc > 0xffff) ? PLT_ENTRY_SIZE_LARGE : PLT_ENTRY_SIZE;
    969  1.1.1.7  christos }
    970  1.1.1.7  christos 
    971      1.1  christos /* Get the ELF linker hash table from a link_info structure.  */
    972      1.1  christos #define or1k_elf_hash_table(p) \
    973  1.1.1.6  christos   ((is_elf_hash_table ((p)->hash)					\
    974  1.1.1.6  christos     && elf_hash_table_id (elf_hash_table (p)) == OR1K_ELF_DATA)		\
    975  1.1.1.6  christos    ? (struct elf_or1k_link_hash_table *) (p)->hash : NULL)
    976      1.1  christos 
    977  1.1.1.7  christos static bool
    978      1.1  christos elf_or1k_mkobject (bfd *abfd)
    979      1.1  christos {
    980      1.1  christos   return bfd_elf_allocate_object (abfd, sizeof (struct elf_or1k_obj_tdata),
    981  1.1.1.5  christos 				  OR1K_ELF_DATA);
    982      1.1  christos }
    983      1.1  christos 
    984      1.1  christos /* Create an entry in an or1k ELF linker hash table.  */
    985      1.1  christos 
    986      1.1  christos static struct bfd_hash_entry *
    987      1.1  christos or1k_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
    988  1.1.1.5  christos 			    struct bfd_hash_table *table,
    989  1.1.1.5  christos 			    const char *string)
    990      1.1  christos {
    991      1.1  christos   struct elf_or1k_link_hash_entry *ret =
    992      1.1  christos     (struct elf_or1k_link_hash_entry *) entry;
    993      1.1  christos 
    994      1.1  christos   /* Allocate the structure if it has not already been allocated by a
    995      1.1  christos      subclass.  */
    996      1.1  christos   if (ret == NULL)
    997      1.1  christos     ret = bfd_hash_allocate (table,
    998  1.1.1.5  christos 			     sizeof (struct elf_or1k_link_hash_entry));
    999      1.1  christos   if (ret == NULL)
   1000      1.1  christos     return NULL;
   1001      1.1  christos 
   1002      1.1  christos   /* Call the allocation method of the superclass.  */
   1003      1.1  christos   ret = ((struct elf_or1k_link_hash_entry *)
   1004  1.1.1.5  christos 	 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
   1005  1.1.1.5  christos 				     table, string));
   1006      1.1  christos   if (ret != NULL)
   1007      1.1  christos     {
   1008      1.1  christos       struct elf_or1k_link_hash_entry *eh;
   1009      1.1  christos 
   1010      1.1  christos       eh = (struct elf_or1k_link_hash_entry *) ret;
   1011      1.1  christos       eh->tls_type = TLS_UNKNOWN;
   1012      1.1  christos     }
   1013      1.1  christos 
   1014      1.1  christos   return (struct bfd_hash_entry *) ret;
   1015      1.1  christos }
   1016      1.1  christos 
   1017      1.1  christos /* Create an or1k ELF linker hash table.  */
   1018      1.1  christos 
   1019      1.1  christos static struct bfd_link_hash_table *
   1020      1.1  christos or1k_elf_link_hash_table_create (bfd *abfd)
   1021      1.1  christos {
   1022      1.1  christos   struct elf_or1k_link_hash_table *ret;
   1023  1.1.1.6  christos   size_t amt = sizeof (struct elf_or1k_link_hash_table);
   1024      1.1  christos 
   1025      1.1  christos   ret = bfd_zmalloc (amt);
   1026      1.1  christos   if (ret == NULL)
   1027      1.1  christos     return NULL;
   1028      1.1  christos 
   1029      1.1  christos   if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
   1030  1.1.1.5  christos 				      or1k_elf_link_hash_newfunc,
   1031  1.1.1.5  christos 				      sizeof (struct elf_or1k_link_hash_entry),
   1032  1.1.1.5  christos 				      OR1K_ELF_DATA))
   1033      1.1  christos     {
   1034      1.1  christos       free (ret);
   1035      1.1  christos       return NULL;
   1036      1.1  christos     }
   1037      1.1  christos 
   1038      1.1  christos   return &ret->root.root;
   1039      1.1  christos }
   1040      1.1  christos 
   1041      1.1  christos static reloc_howto_type *
   1042      1.1  christos or1k_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
   1043  1.1.1.5  christos 			bfd_reloc_code_real_type bcode)
   1044      1.1  christos {
   1045      1.1  christos   unsigned int i;
   1046      1.1  christos 
   1047  1.1.1.5  christos   for (i = 0; i < ARRAY_SIZE (or1k_reloc_map); i++)
   1048  1.1.1.5  christos     if (or1k_reloc_map[i].bfd_reloc_val == bcode)
   1049  1.1.1.5  christos       {
   1050  1.1.1.5  christos 	unsigned int ocode = or1k_reloc_map[i].or1k_reloc_val;
   1051  1.1.1.5  christos 	if (ocode < (unsigned int) R_OR1K_max)
   1052  1.1.1.5  christos 	  return &or1k_elf_howto_table[ocode];
   1053  1.1.1.5  christos 	else
   1054  1.1.1.5  christos 	  break;
   1055  1.1.1.5  christos       }
   1056      1.1  christos 
   1057      1.1  christos   return NULL;
   1058      1.1  christos }
   1059      1.1  christos 
   1060      1.1  christos static reloc_howto_type *
   1061      1.1  christos or1k_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   1062      1.1  christos 			const char *r_name)
   1063      1.1  christos {
   1064      1.1  christos   unsigned int i;
   1065      1.1  christos 
   1066  1.1.1.5  christos   for (i = 0; i < R_OR1K_max; i++)
   1067      1.1  christos     if (or1k_elf_howto_table[i].name != NULL
   1068  1.1.1.5  christos 	&& strcasecmp (or1k_elf_howto_table[i].name, r_name) == 0)
   1069      1.1  christos       return &or1k_elf_howto_table[i];
   1070      1.1  christos 
   1071      1.1  christos   return NULL;
   1072      1.1  christos }
   1073      1.1  christos 
   1074      1.1  christos /* Set the howto pointer for an Or1k ELF reloc.  */
   1075      1.1  christos 
   1076  1.1.1.7  christos static bool
   1077  1.1.1.5  christos or1k_info_to_howto_rela (bfd * abfd,
   1078      1.1  christos 			 arelent * cache_ptr,
   1079      1.1  christos 			 Elf_Internal_Rela * dst)
   1080      1.1  christos {
   1081      1.1  christos   unsigned int r_type;
   1082      1.1  christos 
   1083      1.1  christos   r_type = ELF32_R_TYPE (dst->r_info);
   1084      1.1  christos   if (r_type >= (unsigned int) R_OR1K_max)
   1085      1.1  christos     {
   1086  1.1.1.4  christos       /* xgettext:c-format */
   1087  1.1.1.5  christos       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
   1088  1.1.1.5  christos 			  abfd, r_type);
   1089  1.1.1.5  christos       bfd_set_error (bfd_error_bad_value);
   1090  1.1.1.7  christos       return false;
   1091      1.1  christos     }
   1092      1.1  christos   cache_ptr->howto = & or1k_elf_howto_table[r_type];
   1093  1.1.1.7  christos   return true;
   1094      1.1  christos }
   1095      1.1  christos 
   1096      1.1  christos /* Return the relocation value for @tpoff relocations..  */
   1097      1.1  christos static bfd_vma
   1098  1.1.1.7  christos tpoff (struct bfd_link_info *info, bfd_vma address, bool dynamic)
   1099      1.1  christos {
   1100  1.1.1.6  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
   1101  1.1.1.6  christos   bfd_vma base;
   1102  1.1.1.6  christos 
   1103      1.1  christos   /* If tls_sec is NULL, we should have signalled an error already.  */
   1104  1.1.1.6  christos   if (htab->tls_sec == NULL)
   1105      1.1  christos     return 0;
   1106      1.1  christos 
   1107  1.1.1.6  christos   if (dynamic)
   1108  1.1.1.6  christos     return address - htab->tls_sec->vma;
   1109  1.1.1.6  christos   else
   1110  1.1.1.6  christos     {
   1111  1.1.1.6  christos       /* On or1k, the tp points to just after the tcb, if we have an alignment
   1112  1.1.1.6  christos 	 greater than the tcb size we need to offset by the alignment difference.  */
   1113  1.1.1.6  christos       base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power)
   1114  1.1.1.6  christos 	     - TCB_SIZE;
   1115  1.1.1.6  christos 
   1116  1.1.1.6  christos       /* The thread pointer on or1k stores the address after the TCB where
   1117  1.1.1.6  christos 	 the data is, just compute the difference. No need to compensate
   1118  1.1.1.6  christos 	 for the size of TCB.  */
   1119  1.1.1.6  christos       return address - htab->tls_sec->vma + base;
   1120  1.1.1.6  christos     }
   1121  1.1.1.6  christos }
   1122  1.1.1.6  christos 
   1123  1.1.1.6  christos /* If we have both IE and GD accesses to a symbol the IE relocations should be
   1124  1.1.1.6  christos    offset by 8 bytes because the got contains both GD and IE entries.  */
   1125  1.1.1.6  christos static bfd_vma
   1126  1.1.1.6  christos or1k_initial_exec_offset (reloc_howto_type *howto, unsigned char tls_type_mask)
   1127  1.1.1.6  christos {
   1128  1.1.1.6  christos    switch (howto->type)
   1129  1.1.1.6  christos      {
   1130  1.1.1.6  christos      case R_OR1K_TLS_IE_HI16:
   1131  1.1.1.6  christos      case R_OR1K_TLS_IE_LO16:
   1132  1.1.1.6  christos      case R_OR1K_TLS_IE_PG21:
   1133  1.1.1.6  christos      case R_OR1K_TLS_IE_LO13:
   1134  1.1.1.6  christos      case R_OR1K_TLS_IE_AHI16:
   1135  1.1.1.6  christos        return (tls_type_mask & TLS_GD) != 0 ? 8 : 0;
   1136  1.1.1.6  christos      default:
   1137  1.1.1.6  christos        return 0;
   1138  1.1.1.6  christos      }
   1139      1.1  christos }
   1140      1.1  christos 
   1141  1.1.1.5  christos /* Like _bfd_final_link_relocate, but handles non-contiguous fields.  */
   1142  1.1.1.5  christos 
   1143  1.1.1.5  christos static bfd_reloc_status_type
   1144  1.1.1.5  christos or1k_final_link_relocate (reloc_howto_type *howto, bfd *input_bfd,
   1145  1.1.1.5  christos 			  asection *input_section, bfd_byte *contents,
   1146  1.1.1.5  christos 			  bfd_vma offset, bfd_vma value)
   1147  1.1.1.5  christos {
   1148  1.1.1.5  christos   bfd_reloc_status_type status = bfd_reloc_ok;
   1149  1.1.1.5  christos   int size = bfd_get_reloc_size (howto);
   1150  1.1.1.5  christos   bfd_vma x, place;
   1151  1.1.1.5  christos 
   1152  1.1.1.5  christos   /* Sanity check the address.  */
   1153  1.1.1.5  christos   if (offset + size > bfd_get_section_limit_octets (input_bfd, input_section))
   1154  1.1.1.5  christos     return bfd_reloc_outofrange;
   1155  1.1.1.5  christos 
   1156  1.1.1.5  christos   place = (input_section->output_section->vma
   1157  1.1.1.5  christos 	   + input_section->output_offset
   1158  1.1.1.5  christos 	   + (howto->pcrel_offset ? offset : 0));
   1159  1.1.1.5  christos 
   1160  1.1.1.5  christos   switch (howto->type)
   1161  1.1.1.5  christos     {
   1162  1.1.1.5  christos     case R_OR1K_AHI16:
   1163  1.1.1.7  christos     case R_OR1K_GOT_AHI16:
   1164  1.1.1.5  christos     case R_OR1K_GOTOFF_AHI16:
   1165  1.1.1.5  christos     case R_OR1K_TLS_IE_AHI16:
   1166  1.1.1.5  christos     case R_OR1K_TLS_LE_AHI16:
   1167  1.1.1.5  christos       /* Adjust the operand to match with a signed LO16.  */
   1168  1.1.1.5  christos       value += 0x8000;
   1169  1.1.1.5  christos       break;
   1170  1.1.1.5  christos 
   1171  1.1.1.5  christos     case R_OR1K_INSN_REL_26:
   1172  1.1.1.5  christos       value -= place;
   1173  1.1.1.5  christos       /* Diagnose mis-aligned branch targets.  */
   1174  1.1.1.5  christos       if (value & 3)
   1175  1.1.1.5  christos 	status = bfd_reloc_dangerous;
   1176  1.1.1.5  christos       break;
   1177  1.1.1.5  christos 
   1178  1.1.1.5  christos     case R_OR1K_PCREL_PG21:
   1179  1.1.1.5  christos     case R_OR1K_GOT_PG21:
   1180  1.1.1.5  christos     case R_OR1K_TLS_GD_PG21:
   1181  1.1.1.5  christos     case R_OR1K_TLS_LDM_PG21:
   1182  1.1.1.5  christos     case R_OR1K_TLS_IE_PG21:
   1183  1.1.1.5  christos       value = (value & -8192) - (place & -8192);
   1184  1.1.1.5  christos       break;
   1185  1.1.1.5  christos 
   1186  1.1.1.5  christos     case R_OR1K_LO13:
   1187  1.1.1.5  christos     case R_OR1K_GOT_LO13:
   1188  1.1.1.5  christos     case R_OR1K_TLS_GD_LO13:
   1189  1.1.1.5  christos     case R_OR1K_TLS_LDM_LO13:
   1190  1.1.1.5  christos     case R_OR1K_TLS_IE_LO13:
   1191  1.1.1.5  christos     case R_OR1K_SLO13:
   1192  1.1.1.5  christos       value &= 8191;
   1193  1.1.1.5  christos       break;
   1194  1.1.1.5  christos 
   1195  1.1.1.5  christos     default:
   1196  1.1.1.5  christos       if (howto->pc_relative)
   1197  1.1.1.5  christos 	value -= place;
   1198  1.1.1.5  christos       break;
   1199  1.1.1.5  christos     }
   1200  1.1.1.5  christos 
   1201  1.1.1.5  christos   status = bfd_check_overflow (howto->complain_on_overflow,
   1202  1.1.1.5  christos 			       howto->bitsize,
   1203  1.1.1.5  christos 			       howto->rightshift,
   1204  1.1.1.5  christos 			       bfd_arch_bits_per_address (input_bfd),
   1205  1.1.1.5  christos 			       value);
   1206  1.1.1.5  christos   value >>= howto->rightshift;
   1207  1.1.1.5  christos 
   1208  1.1.1.5  christos   /* If we're overwriting the entire destination,
   1209  1.1.1.5  christos      then no need to read the current contents.  */
   1210  1.1.1.5  christos   if (size == 0 || howto->dst_mask == N_ONES (size))
   1211  1.1.1.5  christos     x = 0;
   1212  1.1.1.5  christos   else
   1213  1.1.1.5  christos     {
   1214  1.1.1.5  christos       BFD_ASSERT (size == 4);
   1215  1.1.1.5  christos       x = bfd_get_32 (input_bfd, contents + offset);
   1216  1.1.1.5  christos     }
   1217  1.1.1.5  christos 
   1218  1.1.1.5  christos   switch (howto->type)
   1219  1.1.1.5  christos     {
   1220  1.1.1.5  christos     case R_OR1K_SLO16:
   1221  1.1.1.5  christos     case R_OR1K_GOTOFF_SLO16:
   1222  1.1.1.5  christos     case R_OR1K_TLS_LE_SLO16:
   1223  1.1.1.5  christos     case R_OR1K_SLO13:
   1224  1.1.1.5  christos       /* The split imm16 field used for stores.  */
   1225  1.1.1.5  christos       x = (x & ~0x3e007ff) | ((value & 0xf800) << 10) | (value & 0x7ff);
   1226  1.1.1.5  christos       break;
   1227  1.1.1.5  christos 
   1228  1.1.1.5  christos     default:
   1229  1.1.1.5  christos       {
   1230  1.1.1.5  christos 	bfd_vma fieldmask = howto->dst_mask;
   1231  1.1.1.5  christos 	value <<= howto->bitpos;
   1232  1.1.1.5  christos 	x = (x & ~fieldmask) | (value & fieldmask);
   1233  1.1.1.5  christos       }
   1234  1.1.1.5  christos       break;
   1235  1.1.1.5  christos     }
   1236  1.1.1.5  christos 
   1237  1.1.1.5  christos   /* Put the relocated value back in the object file.  */
   1238  1.1.1.5  christos   switch (size)
   1239  1.1.1.5  christos     {
   1240  1.1.1.5  christos     case 0:
   1241  1.1.1.5  christos       break;
   1242  1.1.1.5  christos     case 1:
   1243  1.1.1.5  christos       bfd_put_8 (input_bfd, x, contents + offset);
   1244  1.1.1.5  christos       break;
   1245  1.1.1.5  christos     case 2:
   1246  1.1.1.5  christos       bfd_put_16 (input_bfd, x, contents + offset);
   1247  1.1.1.5  christos       break;
   1248  1.1.1.5  christos     case 4:
   1249  1.1.1.5  christos       bfd_put_32 (input_bfd, x, contents + offset);
   1250  1.1.1.5  christos       break;
   1251  1.1.1.5  christos #ifdef BFD64
   1252  1.1.1.5  christos     case 8:
   1253  1.1.1.5  christos       bfd_put_64 (input_bfd, x, contents + offset);
   1254  1.1.1.5  christos       break;
   1255  1.1.1.5  christos #endif
   1256  1.1.1.5  christos     default:
   1257  1.1.1.5  christos       _bfd_error_handler
   1258  1.1.1.5  christos 	(_("%pB: Cannot handle relocation value size of %d"),
   1259  1.1.1.5  christos 	 input_bfd, size);
   1260  1.1.1.5  christos       abort ();
   1261  1.1.1.5  christos     }
   1262  1.1.1.5  christos   return status;
   1263  1.1.1.5  christos }
   1264  1.1.1.5  christos 
   1265      1.1  christos /* Relocate an Or1k ELF section.
   1266      1.1  christos 
   1267      1.1  christos    The RELOCATE_SECTION function is called by the new ELF backend linker
   1268      1.1  christos    to handle the relocations for a section.
   1269      1.1  christos 
   1270      1.1  christos    The relocs are always passed as Rela structures; if the section
   1271      1.1  christos    actually uses Rel structures, the r_addend field will always be
   1272      1.1  christos    zero.
   1273      1.1  christos 
   1274      1.1  christos    This function is responsible for adjusting the section contents as
   1275      1.1  christos    necessary, and (if using Rela relocs and generating a relocatable
   1276      1.1  christos    output file) adjusting the reloc addend as necessary.
   1277      1.1  christos 
   1278      1.1  christos    This function does not have to worry about setting the reloc
   1279      1.1  christos    address or the reloc symbol index.
   1280      1.1  christos 
   1281      1.1  christos    LOCAL_SYMS is a pointer to the swapped in local symbols.
   1282      1.1  christos 
   1283      1.1  christos    LOCAL_SECTIONS is an array giving the section in the input file
   1284      1.1  christos    corresponding to the st_shndx field of each local symbol.
   1285      1.1  christos 
   1286      1.1  christos    The global hash table entry for the global symbols can be found
   1287      1.1  christos    via elf_sym_hashes (input_bfd).
   1288      1.1  christos 
   1289      1.1  christos    When generating relocatable output, this function must handle
   1290      1.1  christos    STB_LOCAL/STT_SECTION symbols specially.  The output symbol is
   1291      1.1  christos    going to be the section symbol corresponding to the output
   1292      1.1  christos    section, which means that the addend must be adjusted
   1293      1.1  christos    accordingly.  */
   1294      1.1  christos 
   1295  1.1.1.7  christos static int
   1296      1.1  christos or1k_elf_relocate_section (bfd *output_bfd,
   1297      1.1  christos 			   struct bfd_link_info *info,
   1298      1.1  christos 			   bfd *input_bfd,
   1299      1.1  christos 			   asection *input_section,
   1300      1.1  christos 			   bfd_byte *contents,
   1301      1.1  christos 			   Elf_Internal_Rela *relocs,
   1302      1.1  christos 			   Elf_Internal_Sym *local_syms,
   1303      1.1  christos 			   asection **local_sections)
   1304      1.1  christos {
   1305      1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   1306      1.1  christos   struct elf_link_hash_entry **sym_hashes;
   1307      1.1  christos   Elf_Internal_Rela *rel;
   1308      1.1  christos   Elf_Internal_Rela *relend;
   1309      1.1  christos   struct elf_or1k_link_hash_table *htab = or1k_elf_hash_table (info);
   1310      1.1  christos   asection *sreloc;
   1311      1.1  christos   bfd_vma *local_got_offsets;
   1312  1.1.1.5  christos   asection *sgot, *splt;
   1313  1.1.1.5  christos   bfd_vma plt_base, got_base, got_sym_value;
   1314  1.1.1.7  christos   bool ret_val = true;
   1315  1.1.1.7  christos   bool saw_gotha = false;
   1316      1.1  christos 
   1317      1.1  christos   if (htab == NULL)
   1318  1.1.1.7  christos     return false;
   1319      1.1  christos 
   1320      1.1  christos   local_got_offsets = elf_local_got_offsets (input_bfd);
   1321      1.1  christos 
   1322      1.1  christos   sreloc = elf_section_data (input_section)->sreloc;
   1323      1.1  christos 
   1324  1.1.1.5  christos   splt = htab->root.splt;
   1325  1.1.1.5  christos   plt_base = 0;
   1326  1.1.1.5  christos   if (splt != NULL)
   1327  1.1.1.5  christos     plt_base = splt->output_section->vma + splt->output_offset;
   1328  1.1.1.5  christos 
   1329  1.1.1.4  christos   sgot = htab->root.sgot;
   1330  1.1.1.5  christos   got_sym_value = got_base = 0;
   1331  1.1.1.5  christos   if (sgot != NULL)
   1332  1.1.1.5  christos     {
   1333  1.1.1.5  christos       struct elf_link_hash_entry *hgot = htab->root.hgot;
   1334  1.1.1.5  christos       got_sym_value = (hgot->root.u.def.value
   1335  1.1.1.5  christos 		       + hgot->root.u.def.section->output_section->vma
   1336  1.1.1.5  christos 		       + hgot->root.u.def.section->output_offset);
   1337  1.1.1.6  christos       got_base = sgot->output_section->vma + sgot->output_offset;
   1338  1.1.1.5  christos     }
   1339      1.1  christos 
   1340      1.1  christos   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   1341      1.1  christos   sym_hashes = elf_sym_hashes (input_bfd);
   1342      1.1  christos   relend = relocs + input_section->reloc_count;
   1343      1.1  christos 
   1344      1.1  christos   for (rel = relocs; rel < relend; rel++)
   1345      1.1  christos     {
   1346      1.1  christos       reloc_howto_type *howto;
   1347      1.1  christos       unsigned long r_symndx;
   1348      1.1  christos       Elf_Internal_Sym *sym;
   1349      1.1  christos       asection *sec;
   1350      1.1  christos       struct elf_link_hash_entry *h;
   1351      1.1  christos       bfd_vma relocation;
   1352      1.1  christos       bfd_reloc_status_type r;
   1353      1.1  christos       const char *name = NULL;
   1354      1.1  christos       int r_type;
   1355      1.1  christos 
   1356      1.1  christos       r_type = ELF32_R_TYPE (rel->r_info);
   1357      1.1  christos       r_symndx = ELF32_R_SYM (rel->r_info);
   1358      1.1  christos 
   1359      1.1  christos       if (r_type == R_OR1K_GNU_VTINHERIT
   1360  1.1.1.5  christos 	  || r_type == R_OR1K_GNU_VTENTRY)
   1361  1.1.1.5  christos 	continue;
   1362      1.1  christos 
   1363      1.1  christos       if (r_type < 0 || r_type >= (int) R_OR1K_max)
   1364  1.1.1.5  christos 	{
   1365  1.1.1.5  christos 	  _bfd_error_handler
   1366  1.1.1.5  christos 	    (_("%pB: unknown relocation type %d"),
   1367  1.1.1.5  christos 	     input_bfd, (int) r_type);
   1368  1.1.1.5  christos 	  bfd_set_error (bfd_error_bad_value);
   1369  1.1.1.7  christos 	  ret_val = false;
   1370  1.1.1.5  christos 	  continue;
   1371  1.1.1.5  christos 	}
   1372      1.1  christos 
   1373      1.1  christos       howto = or1k_elf_howto_table + ELF32_R_TYPE (rel->r_info);
   1374      1.1  christos       h = NULL;
   1375      1.1  christos       sym = NULL;
   1376      1.1  christos       sec = NULL;
   1377      1.1  christos 
   1378      1.1  christos       if (r_symndx < symtab_hdr->sh_info)
   1379  1.1.1.5  christos 	{
   1380  1.1.1.5  christos 	  sym = local_syms + r_symndx;
   1381  1.1.1.5  christos 	  sec = local_sections[r_symndx];
   1382  1.1.1.5  christos 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
   1383  1.1.1.5  christos 
   1384  1.1.1.5  christos 	  name = bfd_elf_string_from_elf_section
   1385  1.1.1.5  christos 	    (input_bfd, symtab_hdr->sh_link, sym->st_name);
   1386  1.1.1.6  christos 	  name = name == NULL ? bfd_section_name (sec) : name;
   1387  1.1.1.5  christos 	}
   1388      1.1  christos       else
   1389  1.1.1.5  christos 	{
   1390  1.1.1.7  christos 	  bool unresolved_reloc, warned, ignored;
   1391      1.1  christos 
   1392  1.1.1.5  christos 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
   1393  1.1.1.5  christos 				   r_symndx, symtab_hdr, sym_hashes,
   1394  1.1.1.5  christos 				   h, sec, relocation,
   1395  1.1.1.5  christos 				   unresolved_reloc, warned, ignored);
   1396  1.1.1.5  christos 	  name = h->root.root.string;
   1397  1.1.1.5  christos 	}
   1398      1.1  christos 
   1399      1.1  christos       if (sec != NULL && discarded_section (sec))
   1400  1.1.1.5  christos 	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   1401  1.1.1.5  christos 					 rel, 1, relend, howto, 0, contents);
   1402      1.1  christos 
   1403  1.1.1.3  christos       if (bfd_link_relocatable (info))
   1404  1.1.1.5  christos 	continue;
   1405      1.1  christos 
   1406      1.1  christos       switch (howto->type)
   1407  1.1.1.5  christos 	{
   1408  1.1.1.5  christos 	case R_OR1K_PLT26:
   1409  1.1.1.5  christos 	case R_OR1K_PLTA26:
   1410  1.1.1.5  christos 	  /* If the call is not local, redirect the branch to the PLT.
   1411  1.1.1.5  christos 	     Otherwise do nothing to send the branch to the symbol direct.  */
   1412  1.1.1.5  christos 	  if (!SYMBOL_CALLS_LOCAL (info, h)
   1413  1.1.1.5  christos 	      && h->plt.offset != (bfd_vma) -1)
   1414  1.1.1.5  christos 	    relocation = plt_base + h->plt.offset;
   1415  1.1.1.5  christos 
   1416  1.1.1.5  christos 	  /* Addend should be zero.  */
   1417  1.1.1.5  christos 	  if (rel->r_addend != 0)
   1418  1.1.1.5  christos 	    {
   1419  1.1.1.5  christos 	      _bfd_error_handler
   1420  1.1.1.5  christos 		(_("%pB: addend should be zero for plt relocations"),
   1421  1.1.1.5  christos 		 input_bfd);
   1422  1.1.1.5  christos 	      bfd_set_error (bfd_error_bad_value);
   1423  1.1.1.7  christos 	      ret_val = false;
   1424  1.1.1.5  christos 	    }
   1425  1.1.1.5  christos 	  break;
   1426  1.1.1.5  christos 
   1427  1.1.1.7  christos 	case R_OR1K_GOT_AHI16:
   1428  1.1.1.5  christos 	case R_OR1K_GOT16:
   1429  1.1.1.5  christos 	case R_OR1K_GOT_PG21:
   1430  1.1.1.5  christos 	case R_OR1K_GOT_LO13:
   1431  1.1.1.5  christos 	  {
   1432  1.1.1.5  christos 	    bfd_vma off;
   1433  1.1.1.5  christos 
   1434  1.1.1.5  christos 	    /* Relocation is to the entry for this symbol
   1435  1.1.1.5  christos 	       in the global offset table.  */
   1436  1.1.1.5  christos 	  BFD_ASSERT (sgot != NULL);
   1437  1.1.1.5  christos 	  if (h != NULL)
   1438  1.1.1.5  christos 	    {
   1439  1.1.1.7  christos 	      bool dyn;
   1440      1.1  christos 
   1441  1.1.1.5  christos 	      off = h->got.offset;
   1442  1.1.1.5  christos 	      BFD_ASSERT (off != (bfd_vma) -1);
   1443      1.1  christos 
   1444  1.1.1.5  christos 	      dyn = htab->root.dynamic_sections_created;
   1445  1.1.1.5  christos 	      if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
   1446  1.1.1.3  christos 						     bfd_link_pic (info),
   1447  1.1.1.3  christos 						     h)
   1448  1.1.1.5  christos 		  || (bfd_link_pic (info)
   1449  1.1.1.5  christos 		      && SYMBOL_REFERENCES_LOCAL (info, h)))
   1450  1.1.1.5  christos 		{
   1451  1.1.1.5  christos 		    /* This is actually a static link, or it is a -Bsymbolic
   1452  1.1.1.5  christos 		       link and the symbol is defined locally, or the symbol
   1453  1.1.1.5  christos 		       was forced to be local because of a version file.
   1454  1.1.1.5  christos 		       We must initialize this entry in the GOT.  Since the
   1455  1.1.1.5  christos 		       offset must always be a multiple of 4, we use the least
   1456  1.1.1.5  christos 		       significant bit to record whether we have initialized
   1457  1.1.1.5  christos 		       it already.
   1458  1.1.1.5  christos 
   1459  1.1.1.5  christos 		     When doing a dynamic link, we create a .rela.got
   1460  1.1.1.5  christos 		     relocation entry to initialize the value.  This
   1461  1.1.1.5  christos 		     is done in the finish_dynamic_symbol routine.  */
   1462  1.1.1.5  christos 		  if ((off & 1) != 0)
   1463  1.1.1.5  christos 		    off &= ~1;
   1464  1.1.1.5  christos 		  else
   1465  1.1.1.5  christos 		    {
   1466  1.1.1.5  christos 		      /* Write entry in GOT.  */
   1467  1.1.1.5  christos 		      bfd_put_32 (output_bfd, relocation,
   1468  1.1.1.5  christos 				  sgot->contents + off);
   1469  1.1.1.5  christos 		      /* Mark GOT entry as having been written.  */
   1470  1.1.1.5  christos 		      h->got.offset |= 1;
   1471  1.1.1.5  christos 		    }
   1472  1.1.1.5  christos 		}
   1473  1.1.1.5  christos 	    }
   1474  1.1.1.5  christos 	  else
   1475  1.1.1.5  christos 	    {
   1476  1.1.1.5  christos 	      bfd_byte *loc;
   1477  1.1.1.5  christos 
   1478  1.1.1.5  christos 	      BFD_ASSERT (local_got_offsets != NULL
   1479  1.1.1.5  christos 			  && local_got_offsets[r_symndx] != (bfd_vma) -1);
   1480  1.1.1.5  christos 
   1481  1.1.1.5  christos 	      /* Get offset into GOT table.  */
   1482  1.1.1.5  christos 	      off = local_got_offsets[r_symndx];
   1483  1.1.1.5  christos 
   1484  1.1.1.5  christos 	      /* The offset must always be a multiple of 4.  We use
   1485  1.1.1.5  christos 		 the least significant bit to record whether we have
   1486  1.1.1.5  christos 		 already processed this entry.  */
   1487  1.1.1.5  christos 	      if ((off & 1) != 0)
   1488  1.1.1.5  christos 		off &= ~1;
   1489  1.1.1.5  christos 	      else
   1490  1.1.1.5  christos 		{
   1491  1.1.1.5  christos 		  /* Write entry in GOT.  */
   1492  1.1.1.5  christos 		  bfd_put_32 (output_bfd, relocation, sgot->contents + off);
   1493  1.1.1.5  christos 		  if (bfd_link_pic (info))
   1494  1.1.1.5  christos 		    {
   1495  1.1.1.5  christos 		      asection *srelgot;
   1496  1.1.1.5  christos 		      Elf_Internal_Rela outrel;
   1497  1.1.1.5  christos 
   1498  1.1.1.5  christos 		      /* We need to generate a R_OR1K_RELATIVE reloc
   1499  1.1.1.5  christos 			 for the dynamic linker.  */
   1500  1.1.1.6  christos 		      srelgot = htab->root.srelgot;
   1501  1.1.1.5  christos 		      BFD_ASSERT (srelgot != NULL);
   1502  1.1.1.5  christos 
   1503  1.1.1.5  christos 		      outrel.r_offset = got_base + off;
   1504  1.1.1.5  christos 		      outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
   1505  1.1.1.5  christos 		      outrel.r_addend = relocation;
   1506  1.1.1.5  christos 		      loc = srelgot->contents;
   1507  1.1.1.6  christos 		      loc += (srelgot->reloc_count
   1508  1.1.1.6  christos 			      * sizeof (Elf32_External_Rela));
   1509  1.1.1.6  christos 		      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   1510  1.1.1.5  christos 		      ++srelgot->reloc_count;
   1511  1.1.1.5  christos 		    }
   1512  1.1.1.5  christos 		  local_got_offsets[r_symndx] |= 1;
   1513  1.1.1.5  christos 		}
   1514  1.1.1.5  christos 	    }
   1515  1.1.1.5  christos 
   1516  1.1.1.5  christos 	    /* The GOT_PG21 and GOT_LO13 relocs are pc-relative,
   1517  1.1.1.5  christos 	       while the GOT16 reloc is GOT relative.  */
   1518  1.1.1.5  christos 	    relocation = got_base + off;
   1519  1.1.1.7  christos 	    if (r_type == R_OR1K_GOT16
   1520  1.1.1.7  christos 		|| r_type == R_OR1K_GOT_AHI16)
   1521  1.1.1.5  christos 	      relocation -= got_sym_value;
   1522  1.1.1.5  christos 
   1523  1.1.1.7  christos 	    if (r_type == R_OR1K_GOT_AHI16)
   1524  1.1.1.7  christos 	      saw_gotha = true;
   1525  1.1.1.7  christos 
   1526  1.1.1.7  christos 	    /* If we have a R_OR1K_GOT16 following a R_OR1K_GOT_AHI16
   1527  1.1.1.7  christos 	       relocation we assume the code is doing the right thing to avoid
   1528  1.1.1.7  christos 	       overflows.  */
   1529  1.1.1.7  christos 	    if (r_type == R_OR1K_GOT16 && saw_gotha)
   1530  1.1.1.7  christos 	      howto = &or1k_elf_got16_no_overflow_howto;
   1531  1.1.1.7  christos 
   1532  1.1.1.5  christos 	  /* Addend should be zero.  */
   1533  1.1.1.5  christos 	  if (rel->r_addend != 0)
   1534  1.1.1.5  christos 	    {
   1535  1.1.1.5  christos 	      _bfd_error_handler
   1536  1.1.1.5  christos 		(_("%pB: addend should be zero for got relocations"),
   1537  1.1.1.5  christos 		 input_bfd);
   1538  1.1.1.5  christos 	      bfd_set_error (bfd_error_bad_value);
   1539  1.1.1.7  christos 	      ret_val = false;
   1540  1.1.1.5  christos 	    }
   1541  1.1.1.5  christos 	  }
   1542  1.1.1.5  christos 	  break;
   1543  1.1.1.5  christos 
   1544  1.1.1.5  christos 	case R_OR1K_GOTOFF_LO16:
   1545  1.1.1.5  christos 	case R_OR1K_GOTOFF_HI16:
   1546  1.1.1.5  christos 	case R_OR1K_GOTOFF_AHI16:
   1547  1.1.1.5  christos 	case R_OR1K_GOTOFF_SLO16:
   1548  1.1.1.5  christos 	  /* Relocation is offset from GOT.  */
   1549  1.1.1.5  christos 	  BFD_ASSERT (sgot != NULL);
   1550  1.1.1.5  christos 	  if (!SYMBOL_REFERENCES_LOCAL (info, h))
   1551  1.1.1.5  christos 	    {
   1552  1.1.1.5  christos 	      _bfd_error_handler
   1553  1.1.1.5  christos 		(_("%pB: gotoff relocation against dynamic symbol %s"),
   1554  1.1.1.5  christos 		 input_bfd, h->root.root.string);
   1555  1.1.1.7  christos 	      ret_val = false;
   1556  1.1.1.5  christos 	      bfd_set_error (bfd_error_bad_value);
   1557  1.1.1.5  christos 	    }
   1558  1.1.1.5  christos 	  relocation -= got_sym_value;
   1559  1.1.1.5  christos 	  break;
   1560  1.1.1.5  christos 
   1561  1.1.1.5  christos 	case R_OR1K_INSN_REL_26:
   1562  1.1.1.7  christos 	  /* For a non-shared link, these will reference plt or call the
   1563  1.1.1.7  christos 	     version of actual object.  */
   1564  1.1.1.7  christos 	  if (bfd_link_pic (info) && !SYMBOL_CALLS_LOCAL (info, h))
   1565  1.1.1.7  christos 	    {
   1566  1.1.1.7  christos 	      _bfd_error_handler
   1567  1.1.1.7  christos 		(_("%pB: pc-relative relocation against dynamic symbol %s"),
   1568  1.1.1.7  christos 		 input_bfd, name);
   1569  1.1.1.7  christos 	      ret_val = false;
   1570  1.1.1.7  christos 	      bfd_set_error (bfd_error_bad_value);
   1571  1.1.1.7  christos 	    }
   1572  1.1.1.7  christos 	  break;
   1573  1.1.1.7  christos 
   1574  1.1.1.5  christos 	case R_OR1K_PCREL_PG21:
   1575  1.1.1.5  christos 	case R_OR1K_LO13:
   1576  1.1.1.5  christos 	case R_OR1K_SLO13:
   1577  1.1.1.5  christos 	  /* For a non-shared link, these will reference either the plt
   1578  1.1.1.5  christos 	     or a .dynbss copy of the symbol.  */
   1579  1.1.1.5  christos 	  if (bfd_link_pic (info) && !SYMBOL_REFERENCES_LOCAL (info, h))
   1580  1.1.1.5  christos 	    {
   1581  1.1.1.5  christos 	      _bfd_error_handler
   1582  1.1.1.5  christos 		(_("%pB: pc-relative relocation against dynamic symbol %s"),
   1583  1.1.1.5  christos 		 input_bfd, name);
   1584  1.1.1.7  christos 	      ret_val = false;
   1585  1.1.1.5  christos 	      bfd_set_error (bfd_error_bad_value);
   1586  1.1.1.5  christos 	    }
   1587  1.1.1.5  christos 	  break;
   1588  1.1.1.5  christos 
   1589  1.1.1.5  christos 	case R_OR1K_HI_16_IN_INSN:
   1590  1.1.1.5  christos 	case R_OR1K_LO_16_IN_INSN:
   1591  1.1.1.5  christos 	case R_OR1K_AHI16:
   1592  1.1.1.5  christos 	case R_OR1K_SLO16:
   1593  1.1.1.5  christos 	  if (bfd_link_pic (info))
   1594  1.1.1.5  christos 	    {
   1595  1.1.1.5  christos 	      _bfd_error_handler
   1596  1.1.1.5  christos 		(_("%pB: non-pic relocation against symbol %s"),
   1597  1.1.1.5  christos 		 input_bfd, name);
   1598  1.1.1.7  christos 	      ret_val = false;
   1599  1.1.1.5  christos 	      bfd_set_error (bfd_error_bad_value);
   1600  1.1.1.5  christos 	    }
   1601  1.1.1.5  christos 	  break;
   1602  1.1.1.5  christos 
   1603  1.1.1.5  christos 	case R_OR1K_32:
   1604  1.1.1.5  christos 	  /* R_OR1K_16? */
   1605  1.1.1.5  christos 	  {
   1606  1.1.1.5  christos 	    /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
   1607  1.1.1.5  christos 	       from removed linkonce sections, or sections discarded by
   1608  1.1.1.5  christos 	       a linker script.  */
   1609  1.1.1.5  christos 	    if (r_symndx == STN_UNDEF
   1610  1.1.1.5  christos 		|| (input_section->flags & SEC_ALLOC) == 0)
   1611  1.1.1.5  christos 	      break;
   1612  1.1.1.5  christos 
   1613  1.1.1.5  christos 	    /* Emit a direct relocation if the symbol is dynamic,
   1614  1.1.1.5  christos 	       or a RELATIVE reloc for shared objects.  We can omit
   1615  1.1.1.5  christos 	       RELATIVE relocs to local undefweak symbols.  */
   1616  1.1.1.5  christos 	    if (bfd_link_pic (info)
   1617  1.1.1.5  christos 		? (h == NULL
   1618  1.1.1.5  christos 		     || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
   1619  1.1.1.5  christos 		     || h->root.type != bfd_link_hash_undefweak)
   1620  1.1.1.5  christos 		: (h != NULL
   1621  1.1.1.5  christos 		    && h->dynindx != -1
   1622  1.1.1.5  christos 		    && !h->non_got_ref
   1623  1.1.1.5  christos 		   && ((h->def_dynamic && !h->def_regular)
   1624  1.1.1.5  christos 			|| h->root.type == bfd_link_hash_undefweak
   1625  1.1.1.5  christos 			|| h->root.type == bfd_link_hash_undefined)))
   1626  1.1.1.5  christos 	      {
   1627  1.1.1.5  christos 		Elf_Internal_Rela outrel;
   1628  1.1.1.5  christos 		bfd_byte *loc;
   1629  1.1.1.7  christos 		bool skip;
   1630  1.1.1.5  christos 
   1631  1.1.1.5  christos 		/* When generating a shared object, these relocations
   1632  1.1.1.5  christos 		   are copied into the output file to be resolved at run
   1633  1.1.1.5  christos 		   time.  */
   1634  1.1.1.5  christos 
   1635  1.1.1.5  christos 		BFD_ASSERT (sreloc != NULL);
   1636  1.1.1.5  christos 
   1637  1.1.1.7  christos 		skip = false;
   1638  1.1.1.5  christos 
   1639  1.1.1.5  christos 		outrel.r_offset =
   1640  1.1.1.5  christos 		  _bfd_elf_section_offset (output_bfd, info, input_section,
   1641  1.1.1.5  christos 					   rel->r_offset);
   1642  1.1.1.5  christos 		if (outrel.r_offset == (bfd_vma) -1)
   1643  1.1.1.7  christos 		  skip = true;
   1644  1.1.1.5  christos 		else if (outrel.r_offset == (bfd_vma) -2)
   1645  1.1.1.7  christos 		  skip = true;
   1646  1.1.1.5  christos 		outrel.r_offset += (input_section->output_section->vma
   1647  1.1.1.5  christos 				    + input_section->output_offset);
   1648  1.1.1.5  christos 
   1649  1.1.1.5  christos 		if (skip)
   1650  1.1.1.5  christos 		  memset (&outrel, 0, sizeof outrel);
   1651  1.1.1.5  christos 		else if (SYMBOL_REFERENCES_LOCAL (info, h))
   1652  1.1.1.5  christos 		  {
   1653  1.1.1.5  christos 		    outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
   1654  1.1.1.5  christos 		    outrel.r_addend = relocation + rel->r_addend;
   1655  1.1.1.5  christos 		  }
   1656  1.1.1.5  christos 		else
   1657  1.1.1.5  christos 		  {
   1658  1.1.1.5  christos 		    BFD_ASSERT (h->dynindx != -1);
   1659  1.1.1.5  christos 		    outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
   1660  1.1.1.5  christos 		    outrel.r_addend = rel->r_addend;
   1661  1.1.1.5  christos 		  }
   1662  1.1.1.5  christos 
   1663  1.1.1.5  christos 		loc = sreloc->contents;
   1664  1.1.1.5  christos 		loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
   1665  1.1.1.5  christos 		bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   1666  1.1.1.5  christos 		break;
   1667  1.1.1.5  christos 	      }
   1668  1.1.1.5  christos 	    break;
   1669  1.1.1.5  christos 	  }
   1670  1.1.1.5  christos 
   1671  1.1.1.5  christos 	case R_OR1K_TLS_LDM_HI16:
   1672  1.1.1.5  christos 	case R_OR1K_TLS_LDM_LO16:
   1673  1.1.1.5  christos 	case R_OR1K_TLS_LDM_PG21:
   1674  1.1.1.5  christos 	case R_OR1K_TLS_LDM_LO13:
   1675  1.1.1.5  christos 	case R_OR1K_TLS_LDO_HI16:
   1676  1.1.1.5  christos 	case R_OR1K_TLS_LDO_LO16:
   1677  1.1.1.5  christos 	  /* TODO: implement support for local dynamic.  */
   1678  1.1.1.5  christos 	  BFD_FAIL ();
   1679  1.1.1.4  christos 	  _bfd_error_handler
   1680  1.1.1.5  christos 	    (_("%pB: support for local dynamic not implemented"),
   1681  1.1.1.5  christos 	     input_bfd);
   1682  1.1.1.5  christos 	  bfd_set_error (bfd_error_bad_value);
   1683  1.1.1.7  christos 	  return false;
   1684  1.1.1.5  christos 
   1685  1.1.1.5  christos 	case R_OR1K_TLS_GD_HI16:
   1686  1.1.1.5  christos 	case R_OR1K_TLS_GD_LO16:
   1687  1.1.1.5  christos 	case R_OR1K_TLS_GD_PG21:
   1688  1.1.1.5  christos 	case R_OR1K_TLS_GD_LO13:
   1689  1.1.1.5  christos 	case R_OR1K_TLS_IE_HI16:
   1690  1.1.1.5  christos 	case R_OR1K_TLS_IE_LO16:
   1691  1.1.1.5  christos 	case R_OR1K_TLS_IE_PG21:
   1692  1.1.1.5  christos 	case R_OR1K_TLS_IE_LO13:
   1693  1.1.1.5  christos 	case R_OR1K_TLS_IE_AHI16:
   1694  1.1.1.5  christos 	  {
   1695  1.1.1.5  christos 	    bfd_vma gotoff;
   1696  1.1.1.5  christos 	    Elf_Internal_Rela rela;
   1697  1.1.1.6  christos 	    asection *srelgot;
   1698  1.1.1.5  christos 	    bfd_byte *loc;
   1699  1.1.1.7  christos 	    bool dynamic;
   1700  1.1.1.6  christos 	    int indx = 0;
   1701  1.1.1.6  christos 	    unsigned char tls_type;
   1702  1.1.1.5  christos 
   1703  1.1.1.6  christos 	    srelgot = htab->root.srelgot;
   1704  1.1.1.5  christos 
   1705  1.1.1.5  christos 	    /* Mark as TLS related GOT entry by setting
   1706  1.1.1.6  christos 	       bit 2 to indcate TLS and bit 1 to indicate GOT.  */
   1707  1.1.1.5  christos 	    if (h != NULL)
   1708  1.1.1.5  christos 	      {
   1709  1.1.1.5  christos 		gotoff = h->got.offset;
   1710  1.1.1.6  christos 		tls_type = ((struct elf_or1k_link_hash_entry *) h)->tls_type;
   1711  1.1.1.5  christos 		h->got.offset |= 3;
   1712  1.1.1.5  christos 	      }
   1713  1.1.1.5  christos 	    else
   1714  1.1.1.5  christos 	      {
   1715  1.1.1.6  christos 		unsigned char *local_tls_type;
   1716  1.1.1.6  christos 
   1717  1.1.1.5  christos 		gotoff = local_got_offsets[r_symndx];
   1718  1.1.1.6  christos 		local_tls_type = (unsigned char *) elf_or1k_local_tls_type (input_bfd);
   1719  1.1.1.6  christos 		tls_type = local_tls_type == NULL ? TLS_NONE
   1720  1.1.1.6  christos 						  : local_tls_type[r_symndx];
   1721  1.1.1.5  christos 		local_got_offsets[r_symndx] |= 3;
   1722  1.1.1.5  christos 	      }
   1723  1.1.1.5  christos 
   1724  1.1.1.5  christos 	    /* Only process the relocation once.  */
   1725  1.1.1.6  christos 	    if ((gotoff & 1) != 0)
   1726  1.1.1.5  christos 	      {
   1727  1.1.1.6  christos 		gotoff += or1k_initial_exec_offset (howto, tls_type);
   1728  1.1.1.6  christos 
   1729  1.1.1.6  christos 		/* The PG21 and LO13 relocs are pc-relative, while the
   1730  1.1.1.6  christos 		   rest are GOT relative.  */
   1731  1.1.1.6  christos 		relocation = got_base + (gotoff & ~3);
   1732  1.1.1.6  christos 		if (!(r_type == R_OR1K_TLS_GD_PG21
   1733  1.1.1.6  christos 		    || r_type == R_OR1K_TLS_GD_LO13
   1734  1.1.1.6  christos 		    || r_type == R_OR1K_TLS_IE_PG21
   1735  1.1.1.6  christos 		    || r_type == R_OR1K_TLS_IE_LO13))
   1736  1.1.1.6  christos 		  relocation -= got_sym_value;
   1737  1.1.1.5  christos 		break;
   1738  1.1.1.5  christos 	      }
   1739      1.1  christos 
   1740  1.1.1.5  christos 	    BFD_ASSERT (elf_hash_table (info)->hgot == NULL
   1741      1.1  christos 			|| elf_hash_table (info)->hgot->root.u.def.value == 0);
   1742      1.1  christos 
   1743  1.1.1.6  christos 	    if (h != NULL)
   1744  1.1.1.6  christos 	      {
   1745  1.1.1.7  christos 		bool dyn = htab->root.dynamic_sections_created;
   1746  1.1.1.7  christos 		bool pic = bfd_link_pic (info);
   1747  1.1.1.6  christos 
   1748  1.1.1.6  christos 		if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, pic, h)
   1749  1.1.1.6  christos 		    && (!pic || !SYMBOL_REFERENCES_LOCAL (info, h)))
   1750  1.1.1.6  christos 		  indx = h->dynindx;
   1751  1.1.1.6  christos 	      }
   1752  1.1.1.6  christos 
   1753  1.1.1.6  christos 	    /* Dynamic entries will require relocations.  If we do not need
   1754  1.1.1.5  christos 	       them we will just use the default R_OR1K_NONE and
   1755  1.1.1.5  christos 	       not set anything.  */
   1756  1.1.1.6  christos 	    dynamic = (bfd_link_pic (info) || indx != 0)
   1757  1.1.1.6  christos 		       && (h == NULL
   1758  1.1.1.6  christos 			   || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
   1759  1.1.1.6  christos 			   || h->root.type != bfd_link_hash_undefweak);
   1760      1.1  christos 
   1761  1.1.1.5  christos 	    /* Shared GD.  */
   1762  1.1.1.6  christos 	    if (dynamic && ((tls_type & TLS_GD) != 0))
   1763  1.1.1.5  christos 	      {
   1764  1.1.1.5  christos 		int i;
   1765  1.1.1.5  christos 
   1766  1.1.1.5  christos 		/* Add DTPMOD and DTPOFF GOT and rela entries.  */
   1767  1.1.1.5  christos 		for (i = 0; i < 2; ++i)
   1768  1.1.1.5  christos 		  {
   1769  1.1.1.6  christos 		    BFD_ASSERT (srelgot->contents != NULL);
   1770  1.1.1.6  christos 
   1771  1.1.1.5  christos 		    rela.r_offset = got_base + gotoff + i*4;
   1772  1.1.1.5  christos 		    if (h != NULL && h->dynindx != -1)
   1773  1.1.1.5  christos 		      {
   1774  1.1.1.5  christos 			rela.r_info = ELF32_R_INFO (h->dynindx,
   1775  1.1.1.5  christos 			    (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
   1776  1.1.1.5  christos 			rela.r_addend = 0;
   1777  1.1.1.5  christos 		      }
   1778  1.1.1.5  christos 		    else
   1779  1.1.1.5  christos 		      {
   1780  1.1.1.5  christos 			rela.r_info = ELF32_R_INFO (0,
   1781  1.1.1.5  christos 			    (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
   1782  1.1.1.6  christos 			rela.r_addend =
   1783  1.1.1.6  christos 			    (i == 0 ? 0 : tpoff (info, relocation, dynamic));
   1784  1.1.1.5  christos 		      }
   1785  1.1.1.5  christos 
   1786  1.1.1.6  christos 		    loc = srelgot->contents;
   1787  1.1.1.6  christos 		    loc += (srelgot->reloc_count++
   1788  1.1.1.6  christos 			    * sizeof (Elf32_External_Rela));
   1789  1.1.1.5  christos 
   1790  1.1.1.5  christos 		    bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   1791  1.1.1.5  christos 		    bfd_put_32 (output_bfd, 0, sgot->contents + gotoff + i*4);
   1792  1.1.1.5  christos 		  }
   1793  1.1.1.5  christos 	      }
   1794  1.1.1.5  christos 	    /* Static GD.  */
   1795  1.1.1.6  christos 	    else if ((tls_type & TLS_GD) != 0)
   1796  1.1.1.5  christos 	      {
   1797  1.1.1.5  christos 		bfd_put_32 (output_bfd, 1, sgot->contents + gotoff);
   1798  1.1.1.6  christos 		bfd_put_32 (output_bfd, tpoff (info, relocation, dynamic),
   1799  1.1.1.5  christos 		    sgot->contents + gotoff + 4);
   1800  1.1.1.5  christos 	      }
   1801  1.1.1.6  christos 
   1802  1.1.1.6  christos 	    gotoff += or1k_initial_exec_offset (howto, tls_type);
   1803  1.1.1.6  christos 
   1804  1.1.1.5  christos 	    /* Shared IE.  */
   1805  1.1.1.6  christos 	    if (dynamic && ((tls_type & TLS_IE) != 0))
   1806  1.1.1.5  christos 	      {
   1807  1.1.1.6  christos 		BFD_ASSERT (srelgot->contents != NULL);
   1808  1.1.1.6  christos 
   1809  1.1.1.5  christos 		/* Add TPOFF GOT and rela entries.  */
   1810  1.1.1.5  christos 		rela.r_offset = got_base + gotoff;
   1811  1.1.1.5  christos 		if (h != NULL && h->dynindx != -1)
   1812  1.1.1.5  christos 		  {
   1813  1.1.1.5  christos 		    rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_TLS_TPOFF);
   1814  1.1.1.5  christos 		    rela.r_addend = 0;
   1815  1.1.1.5  christos 		  }
   1816  1.1.1.5  christos 		else
   1817  1.1.1.5  christos 		  {
   1818  1.1.1.5  christos 		    rela.r_info = ELF32_R_INFO (0, R_OR1K_TLS_TPOFF);
   1819  1.1.1.6  christos 		    rela.r_addend = tpoff (info, relocation, dynamic);
   1820  1.1.1.5  christos 		  }
   1821  1.1.1.5  christos 
   1822  1.1.1.6  christos 		loc = srelgot->contents;
   1823  1.1.1.6  christos 		loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
   1824  1.1.1.5  christos 
   1825  1.1.1.5  christos 		bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   1826  1.1.1.5  christos 		bfd_put_32 (output_bfd, 0, sgot->contents + gotoff);
   1827  1.1.1.5  christos 	      }
   1828  1.1.1.5  christos 	    /* Static IE.  */
   1829  1.1.1.6  christos 	    else if ((tls_type & TLS_IE) != 0)
   1830  1.1.1.6  christos 	      bfd_put_32 (output_bfd, tpoff (info, relocation, dynamic),
   1831  1.1.1.6  christos 			  sgot->contents + gotoff);
   1832  1.1.1.5  christos 
   1833  1.1.1.5  christos 	    /* The PG21 and LO13 relocs are pc-relative, while the
   1834  1.1.1.5  christos 	       rest are GOT relative.  */
   1835  1.1.1.5  christos 	    relocation = got_base + gotoff;
   1836  1.1.1.5  christos 	    if (!(r_type == R_OR1K_TLS_GD_PG21
   1837  1.1.1.5  christos 		  || r_type == R_OR1K_TLS_GD_LO13
   1838  1.1.1.5  christos 		  || r_type == R_OR1K_TLS_IE_PG21
   1839  1.1.1.5  christos 		  || r_type == R_OR1K_TLS_IE_LO13))
   1840  1.1.1.5  christos 	      relocation -= got_sym_value;
   1841  1.1.1.5  christos 	  }
   1842  1.1.1.5  christos 	  break;
   1843  1.1.1.5  christos 
   1844  1.1.1.5  christos 	case R_OR1K_TLS_LE_HI16:
   1845  1.1.1.5  christos 	case R_OR1K_TLS_LE_LO16:
   1846  1.1.1.5  christos 	case R_OR1K_TLS_LE_AHI16:
   1847  1.1.1.5  christos 	case R_OR1K_TLS_LE_SLO16:
   1848  1.1.1.5  christos 	  /* Relocation is offset from TP.  */
   1849  1.1.1.6  christos 	  relocation = tpoff (info, relocation, 0);
   1850  1.1.1.5  christos 	  break;
   1851  1.1.1.5  christos 
   1852  1.1.1.5  christos 	case R_OR1K_TLS_DTPMOD:
   1853  1.1.1.5  christos 	case R_OR1K_TLS_DTPOFF:
   1854  1.1.1.5  christos 	case R_OR1K_TLS_TPOFF:
   1855  1.1.1.5  christos 	  /* These are resolved dynamically on load and shouldn't
   1856  1.1.1.5  christos 	     be used as linker input.  */
   1857  1.1.1.5  christos 	  BFD_FAIL ();
   1858  1.1.1.4  christos 	  _bfd_error_handler
   1859  1.1.1.5  christos 	    (_("%pB: will not resolve runtime TLS relocation"),
   1860  1.1.1.5  christos 	     input_bfd);
   1861  1.1.1.5  christos 	  bfd_set_error (bfd_error_bad_value);
   1862  1.1.1.7  christos 	  return false;
   1863  1.1.1.5  christos 
   1864  1.1.1.5  christos 	default:
   1865  1.1.1.5  christos 	  break;
   1866  1.1.1.5  christos 	}
   1867  1.1.1.5  christos 
   1868  1.1.1.5  christos       r = or1k_final_link_relocate (howto, input_bfd, input_section, contents,
   1869  1.1.1.5  christos 				    rel->r_offset, relocation + rel->r_addend);
   1870      1.1  christos 
   1871      1.1  christos       if (r != bfd_reloc_ok)
   1872  1.1.1.5  christos 	{
   1873  1.1.1.5  christos 	  const char *msg = NULL;
   1874      1.1  christos 
   1875  1.1.1.5  christos 	  switch (r)
   1876  1.1.1.5  christos 	    {
   1877  1.1.1.5  christos 	    case bfd_reloc_overflow:
   1878  1.1.1.3  christos 	      (*info->callbacks->reloc_overflow)
   1879  1.1.1.5  christos 		(info, (h ? &h->root : NULL), name, howto->name,
   1880  1.1.1.5  christos 		 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
   1881  1.1.1.5  christos 	      break;
   1882      1.1  christos 
   1883  1.1.1.5  christos 	    case bfd_reloc_undefined:
   1884  1.1.1.3  christos 	      (*info->callbacks->undefined_symbol)
   1885  1.1.1.7  christos 		(info, name, input_bfd, input_section, rel->r_offset, true);
   1886  1.1.1.5  christos 	      break;
   1887      1.1  christos 
   1888  1.1.1.5  christos 	    case bfd_reloc_outofrange:
   1889  1.1.1.5  christos 	      msg = _("internal error: out of range error");
   1890  1.1.1.5  christos 	      break;
   1891  1.1.1.5  christos 
   1892  1.1.1.5  christos 	    case bfd_reloc_notsupported:
   1893  1.1.1.5  christos 	      msg = _("internal error: unsupported relocation error");
   1894  1.1.1.5  christos 	      break;
   1895  1.1.1.5  christos 
   1896  1.1.1.5  christos 	    case bfd_reloc_dangerous:
   1897  1.1.1.5  christos 	      msg = _("internal error: dangerous relocation");
   1898  1.1.1.5  christos 	      break;
   1899  1.1.1.5  christos 
   1900  1.1.1.5  christos 	    default:
   1901  1.1.1.5  christos 	      msg = _("internal error: unknown error");
   1902  1.1.1.5  christos 	      break;
   1903  1.1.1.5  christos 	    }
   1904      1.1  christos 
   1905  1.1.1.5  christos 	  if (msg)
   1906  1.1.1.3  christos 	    (*info->callbacks->warning) (info, msg, name, input_bfd,
   1907  1.1.1.3  christos 					 input_section, rel->r_offset);
   1908  1.1.1.5  christos 	}
   1909      1.1  christos     }
   1910      1.1  christos 
   1911  1.1.1.5  christos   return ret_val;
   1912      1.1  christos }
   1913      1.1  christos 
   1914      1.1  christos /* Return the section that should be marked against GC for a given
   1915      1.1  christos    relocation.  */
   1916      1.1  christos 
   1917      1.1  christos static asection *
   1918      1.1  christos or1k_elf_gc_mark_hook (asection *sec,
   1919      1.1  christos 		       struct bfd_link_info *info,
   1920      1.1  christos 		       Elf_Internal_Rela *rel,
   1921      1.1  christos 		       struct elf_link_hash_entry *h,
   1922      1.1  christos 		       Elf_Internal_Sym *sym)
   1923      1.1  christos {
   1924      1.1  christos   if (h != NULL)
   1925      1.1  christos     switch (ELF32_R_TYPE (rel->r_info))
   1926      1.1  christos       {
   1927      1.1  christos       case R_OR1K_GNU_VTINHERIT:
   1928      1.1  christos       case R_OR1K_GNU_VTENTRY:
   1929  1.1.1.5  christos 	return NULL;
   1930      1.1  christos       }
   1931      1.1  christos 
   1932      1.1  christos   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
   1933      1.1  christos }
   1934      1.1  christos 
   1935      1.1  christos /* Look through the relocs for a section during the first phase.  */
   1936      1.1  christos 
   1937  1.1.1.7  christos static bool
   1938      1.1  christos or1k_elf_check_relocs (bfd *abfd,
   1939      1.1  christos 		       struct bfd_link_info *info,
   1940      1.1  christos 		       asection *sec,
   1941      1.1  christos 		       const Elf_Internal_Rela *relocs)
   1942      1.1  christos {
   1943      1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   1944      1.1  christos   struct elf_link_hash_entry **sym_hashes;
   1945      1.1  christos   const Elf_Internal_Rela *rel;
   1946      1.1  christos 
   1947      1.1  christos   const Elf_Internal_Rela *rel_end;
   1948      1.1  christos   struct elf_or1k_link_hash_table *htab;
   1949      1.1  christos   bfd *dynobj;
   1950      1.1  christos   asection *sreloc = NULL;
   1951      1.1  christos 
   1952  1.1.1.3  christos   if (bfd_link_relocatable (info))
   1953  1.1.1.7  christos     return true;
   1954      1.1  christos 
   1955      1.1  christos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   1956      1.1  christos   sym_hashes = elf_sym_hashes (abfd);
   1957      1.1  christos 
   1958      1.1  christos   htab = or1k_elf_hash_table (info);
   1959      1.1  christos   if (htab == NULL)
   1960  1.1.1.7  christos     return false;
   1961      1.1  christos 
   1962      1.1  christos   dynobj = htab->root.dynobj;
   1963      1.1  christos 
   1964      1.1  christos   rel_end = relocs + sec->reloc_count;
   1965      1.1  christos   for (rel = relocs; rel < rel_end; rel++)
   1966      1.1  christos     {
   1967      1.1  christos       struct elf_link_hash_entry *h;
   1968      1.1  christos       unsigned long r_symndx;
   1969      1.1  christos       unsigned char tls_type;
   1970  1.1.1.5  christos       int r_type;
   1971      1.1  christos 
   1972      1.1  christos       r_symndx = ELF32_R_SYM (rel->r_info);
   1973      1.1  christos       if (r_symndx < symtab_hdr->sh_info)
   1974  1.1.1.5  christos 	h = NULL;
   1975      1.1  christos       else
   1976  1.1.1.5  christos 	{
   1977  1.1.1.5  christos 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   1978  1.1.1.5  christos 	  while (h->root.type == bfd_link_hash_indirect
   1979  1.1.1.5  christos 		 || h->root.type == bfd_link_hash_warning)
   1980  1.1.1.5  christos 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   1981  1.1.1.5  christos 	}
   1982  1.1.1.5  christos 
   1983  1.1.1.5  christos       r_type = ELF32_R_TYPE (rel->r_info);
   1984  1.1.1.5  christos       switch (r_type)
   1985  1.1.1.5  christos 	{
   1986  1.1.1.5  christos 	case R_OR1K_TLS_GD_HI16:
   1987  1.1.1.5  christos 	case R_OR1K_TLS_GD_LO16:
   1988  1.1.1.5  christos 	case R_OR1K_TLS_GD_PG21:
   1989  1.1.1.5  christos 	case R_OR1K_TLS_GD_LO13:
   1990  1.1.1.5  christos 	  tls_type = TLS_GD;
   1991  1.1.1.5  christos 	  break;
   1992  1.1.1.5  christos 	case R_OR1K_TLS_LDM_HI16:
   1993  1.1.1.5  christos 	case R_OR1K_TLS_LDM_LO16:
   1994  1.1.1.5  christos 	case R_OR1K_TLS_LDM_PG21:
   1995  1.1.1.5  christos 	case R_OR1K_TLS_LDM_LO13:
   1996  1.1.1.5  christos 	case R_OR1K_TLS_LDO_HI16:
   1997  1.1.1.5  christos 	case R_OR1K_TLS_LDO_LO16:
   1998  1.1.1.5  christos 	  tls_type = TLS_LD;
   1999  1.1.1.5  christos 	  break;
   2000  1.1.1.5  christos 	case R_OR1K_TLS_IE_HI16:
   2001  1.1.1.5  christos 	case R_OR1K_TLS_IE_LO16:
   2002  1.1.1.5  christos 	case R_OR1K_TLS_IE_PG21:
   2003  1.1.1.5  christos 	case R_OR1K_TLS_IE_LO13:
   2004  1.1.1.5  christos 	case R_OR1K_TLS_IE_AHI16:
   2005  1.1.1.5  christos 	  tls_type = TLS_IE;
   2006  1.1.1.5  christos 	  break;
   2007  1.1.1.5  christos 	case R_OR1K_TLS_LE_HI16:
   2008  1.1.1.5  christos 	case R_OR1K_TLS_LE_LO16:
   2009  1.1.1.5  christos 	case R_OR1K_TLS_LE_AHI16:
   2010  1.1.1.5  christos 	case R_OR1K_TLS_LE_SLO16:
   2011  1.1.1.5  christos 	  tls_type = TLS_LE;
   2012  1.1.1.5  christos 	  break;
   2013  1.1.1.5  christos 	default:
   2014  1.1.1.5  christos 	  tls_type = TLS_NONE;
   2015  1.1.1.5  christos 	}
   2016      1.1  christos 
   2017      1.1  christos       /* Record TLS type.  */
   2018      1.1  christos       if (h != NULL)
   2019  1.1.1.6  christos 	  ((struct elf_or1k_link_hash_entry *) h)->tls_type |= tls_type;
   2020      1.1  christos       else
   2021  1.1.1.5  christos 	{
   2022  1.1.1.5  christos 	  unsigned char *local_tls_type;
   2023      1.1  christos 
   2024  1.1.1.5  christos 	  /* This is a TLS type record for a local symbol.  */
   2025  1.1.1.5  christos 	  local_tls_type = (unsigned char *) elf_or1k_local_tls_type (abfd);
   2026  1.1.1.5  christos 	  if (local_tls_type == NULL)
   2027  1.1.1.5  christos 	    {
   2028  1.1.1.5  christos 	      bfd_size_type size;
   2029  1.1.1.5  christos 
   2030  1.1.1.5  christos 	      size = symtab_hdr->sh_info;
   2031  1.1.1.5  christos 	      local_tls_type = bfd_zalloc (abfd, size);
   2032  1.1.1.5  christos 	      if (local_tls_type == NULL)
   2033  1.1.1.7  christos 		return false;
   2034  1.1.1.5  christos 	      elf_or1k_local_tls_type (abfd) = local_tls_type;
   2035  1.1.1.5  christos 	    }
   2036  1.1.1.6  christos 	  local_tls_type[r_symndx] |= tls_type;
   2037  1.1.1.5  christos 	}
   2038  1.1.1.5  christos 
   2039  1.1.1.5  christos       switch (r_type)
   2040  1.1.1.5  christos 	{
   2041  1.1.1.5  christos 	  /* This relocation describes the C++ object vtable hierarchy.
   2042  1.1.1.5  christos 	     Reconstruct it for later use during GC.  */
   2043  1.1.1.5  christos 	case R_OR1K_GNU_VTINHERIT:
   2044  1.1.1.5  christos 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
   2045  1.1.1.7  christos 	    return false;
   2046  1.1.1.5  christos 	  break;
   2047  1.1.1.5  christos 
   2048  1.1.1.5  christos 	  /* This relocation describes which C++ vtable entries are actually
   2049  1.1.1.5  christos 	     used.  Record for later use during GC.  */
   2050  1.1.1.5  christos 	case R_OR1K_GNU_VTENTRY:
   2051  1.1.1.6  christos 	  if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
   2052  1.1.1.7  christos 	    return false;
   2053  1.1.1.5  christos 	  break;
   2054  1.1.1.5  christos 
   2055  1.1.1.5  christos 	  /* This relocation requires .plt entry.  */
   2056  1.1.1.5  christos 	case R_OR1K_PLTA26:
   2057  1.1.1.7  christos 	  htab->saw_plta = true;
   2058  1.1.1.5  christos 	  /* FALLTHRU */
   2059  1.1.1.5  christos 	case R_OR1K_PLT26:
   2060  1.1.1.5  christos 	  if (h != NULL)
   2061  1.1.1.5  christos 	    {
   2062  1.1.1.5  christos 	      h->needs_plt = 1;
   2063  1.1.1.5  christos 	      h->plt.refcount += 1;
   2064  1.1.1.5  christos 	    }
   2065  1.1.1.5  christos 	  break;
   2066  1.1.1.5  christos 
   2067  1.1.1.7  christos 	case R_OR1K_GOT_AHI16:
   2068  1.1.1.5  christos 	case R_OR1K_GOT16:
   2069  1.1.1.5  christos 	case R_OR1K_GOT_PG21:
   2070  1.1.1.5  christos 	case R_OR1K_GOT_LO13:
   2071  1.1.1.5  christos 	case R_OR1K_TLS_GD_HI16:
   2072  1.1.1.5  christos 	case R_OR1K_TLS_GD_LO16:
   2073  1.1.1.5  christos 	case R_OR1K_TLS_GD_PG21:
   2074  1.1.1.5  christos 	case R_OR1K_TLS_GD_LO13:
   2075  1.1.1.5  christos 	case R_OR1K_TLS_IE_HI16:
   2076  1.1.1.5  christos 	case R_OR1K_TLS_IE_LO16:
   2077  1.1.1.5  christos 	case R_OR1K_TLS_IE_PG21:
   2078  1.1.1.5  christos 	case R_OR1K_TLS_IE_LO13:
   2079  1.1.1.5  christos 	case R_OR1K_TLS_IE_AHI16:
   2080  1.1.1.5  christos 	      if (h != NULL)
   2081  1.1.1.5  christos 		h->got.refcount += 1;
   2082  1.1.1.5  christos 	      else
   2083  1.1.1.5  christos 		{
   2084  1.1.1.5  christos 		  bfd_signed_vma *local_got_refcounts;
   2085  1.1.1.5  christos 
   2086  1.1.1.5  christos 		  /* This is a global offset table entry for a local symbol.  */
   2087  1.1.1.5  christos 		  local_got_refcounts = elf_local_got_refcounts (abfd);
   2088  1.1.1.5  christos 		  if (local_got_refcounts == NULL)
   2089  1.1.1.5  christos 		    {
   2090  1.1.1.5  christos 		      bfd_size_type size;
   2091  1.1.1.5  christos 
   2092  1.1.1.5  christos 		      size = symtab_hdr->sh_info;
   2093  1.1.1.5  christos 		      size *= sizeof (bfd_signed_vma);
   2094  1.1.1.5  christos 		      local_got_refcounts = bfd_zalloc (abfd, size);
   2095  1.1.1.5  christos 		      if (local_got_refcounts == NULL)
   2096  1.1.1.7  christos 			return false;
   2097  1.1.1.5  christos 		      elf_local_got_refcounts (abfd) = local_got_refcounts;
   2098  1.1.1.5  christos 		    }
   2099  1.1.1.5  christos 		  local_got_refcounts[r_symndx] += 1;
   2100  1.1.1.5  christos 		}
   2101  1.1.1.5  christos 	  /* FALLTHRU */
   2102  1.1.1.5  christos 
   2103  1.1.1.5  christos 	case R_OR1K_GOTOFF_HI16:
   2104  1.1.1.5  christos 	case R_OR1K_GOTOFF_LO16:
   2105  1.1.1.5  christos 	case R_OR1K_GOTOFF_AHI16:
   2106  1.1.1.5  christos 	case R_OR1K_GOTOFF_SLO16:
   2107  1.1.1.5  christos 	  if (htab->root.sgot == NULL)
   2108  1.1.1.5  christos 	    {
   2109  1.1.1.5  christos 	      if (dynobj == NULL)
   2110  1.1.1.5  christos 		htab->root.dynobj = dynobj = abfd;
   2111  1.1.1.5  christos 	      if (!_bfd_elf_create_got_section (dynobj, info))
   2112  1.1.1.7  christos 		return false;
   2113  1.1.1.5  christos 	    }
   2114  1.1.1.5  christos 	  break;
   2115  1.1.1.5  christos 
   2116  1.1.1.5  christos 	case R_OR1K_INSN_REL_26:
   2117  1.1.1.5  christos 	case R_OR1K_HI_16_IN_INSN:
   2118  1.1.1.5  christos 	case R_OR1K_LO_16_IN_INSN:
   2119  1.1.1.5  christos 	case R_OR1K_AHI16:
   2120  1.1.1.5  christos 	case R_OR1K_SLO16:
   2121  1.1.1.5  christos 	case R_OR1K_32:
   2122  1.1.1.5  christos 	case R_OR1K_PCREL_PG21:
   2123  1.1.1.5  christos 	case R_OR1K_LO13:
   2124  1.1.1.5  christos 	case R_OR1K_SLO13:
   2125  1.1.1.5  christos 	  {
   2126  1.1.1.5  christos 	    if (h != NULL && !bfd_link_pic (info))
   2127  1.1.1.5  christos 	      {
   2128  1.1.1.5  christos 		/* We may need a copy reloc.  */
   2129  1.1.1.5  christos 		h->non_got_ref = 1;
   2130  1.1.1.5  christos 
   2131  1.1.1.5  christos 		/* We may also need a .plt entry.  */
   2132  1.1.1.5  christos 		h->plt.refcount += 1;
   2133  1.1.1.5  christos 		if (r_type != R_OR1K_INSN_REL_26)
   2134  1.1.1.5  christos 		  h->pointer_equality_needed = 1;
   2135  1.1.1.5  christos 	      }
   2136  1.1.1.5  christos 
   2137  1.1.1.5  christos 	    /* If we are creating a shared library, and this is a reloc
   2138  1.1.1.5  christos 	       against a global symbol, or a non PC relative reloc
   2139  1.1.1.5  christos 	       against a local symbol, then we need to copy the reloc
   2140  1.1.1.5  christos 	       into the shared library.  However, if we are linking with
   2141  1.1.1.5  christos 	       -Bsymbolic, we do not need to copy a reloc against a
   2142  1.1.1.5  christos 	       global symbol which is defined in an object we are
   2143  1.1.1.5  christos 	       including in the link (i.e., DEF_REGULAR is set).  At
   2144  1.1.1.5  christos 	       this point we have not seen all the input files, so it is
   2145  1.1.1.5  christos 	       possible that DEF_REGULAR is not set now but will be set
   2146  1.1.1.5  christos 	       later (it is never cleared).  In case of a weak definition,
   2147  1.1.1.5  christos 	       DEF_REGULAR may be cleared later by a strong definition in
   2148  1.1.1.5  christos 	       a shared library.  We account for that possibility below by
   2149  1.1.1.5  christos 	       storing information in the relocs_copied field of the hash
   2150  1.1.1.5  christos 	       table entry.  A similar situation occurs when creating
   2151  1.1.1.5  christos 	       shared libraries and symbol visibility changes render the
   2152  1.1.1.5  christos 	       symbol local.
   2153  1.1.1.5  christos 
   2154  1.1.1.5  christos 	       If on the other hand, we are creating an executable, we
   2155  1.1.1.5  christos 	       may need to keep relocations for symbols satisfied by a
   2156  1.1.1.5  christos 	       dynamic library if we manage to avoid copy relocs for the
   2157  1.1.1.5  christos 	       symbol.  */
   2158  1.1.1.5  christos 
   2159  1.1.1.5  christos 	    if ((bfd_link_pic (info)
   2160  1.1.1.5  christos 		 && (sec->flags & SEC_ALLOC) != 0
   2161  1.1.1.5  christos 		 && (r_type != R_OR1K_INSN_REL_26
   2162  1.1.1.5  christos 		     || (h != NULL
   2163  1.1.1.5  christos 			 && (!SYMBOLIC_BIND (info, h)
   2164  1.1.1.5  christos 			     || h->root.type == bfd_link_hash_defweak
   2165  1.1.1.5  christos 			     || !h->def_regular))))
   2166  1.1.1.5  christos 		|| (!bfd_link_pic (info)
   2167  1.1.1.5  christos 		    && (sec->flags & SEC_ALLOC) != 0
   2168  1.1.1.5  christos 		    && h != NULL
   2169  1.1.1.5  christos 		    && (h->root.type == bfd_link_hash_defweak
   2170  1.1.1.5  christos 			|| !h->def_regular)))
   2171  1.1.1.5  christos 	      {
   2172  1.1.1.6  christos 		struct elf_dyn_relocs *sec_relocs;
   2173  1.1.1.5  christos 		struct elf_dyn_relocs **head;
   2174  1.1.1.5  christos 
   2175  1.1.1.5  christos 		/* When creating a shared object, we must copy these
   2176  1.1.1.5  christos 		   relocs into the output file.  We create a reloc
   2177  1.1.1.5  christos 		   section in dynobj and make room for the reloc.  */
   2178  1.1.1.5  christos 		if (sreloc == NULL)
   2179  1.1.1.5  christos 		  {
   2180  1.1.1.5  christos 		    const char *name;
   2181  1.1.1.5  christos 		    unsigned int strndx = elf_elfheader (abfd)->e_shstrndx;
   2182  1.1.1.5  christos 		    unsigned int shnam = _bfd_elf_single_rel_hdr (sec)->sh_name;
   2183  1.1.1.5  christos 
   2184  1.1.1.5  christos 		    name = bfd_elf_string_from_elf_section (abfd, strndx, shnam);
   2185  1.1.1.5  christos 		    if (name == NULL)
   2186  1.1.1.7  christos 		      return false;
   2187  1.1.1.5  christos 
   2188  1.1.1.7  christos 		    if (!startswith (name, ".rela")
   2189  1.1.1.6  christos 			|| strcmp (bfd_section_name (sec), name + 5) != 0)
   2190  1.1.1.5  christos 		      {
   2191  1.1.1.4  christos 			_bfd_error_handler
   2192  1.1.1.4  christos 			  /* xgettext:c-format */
   2193  1.1.1.5  christos 			  (_("%pB: bad relocation section name `%s\'"),
   2194  1.1.1.5  christos 			   abfd, name);
   2195  1.1.1.5  christos 		      }
   2196  1.1.1.5  christos 
   2197  1.1.1.5  christos 		    if (htab->root.dynobj == NULL)
   2198  1.1.1.5  christos 		      htab->root.dynobj = abfd;
   2199  1.1.1.5  christos 		    dynobj = htab->root.dynobj;
   2200  1.1.1.5  christos 
   2201  1.1.1.5  christos 		    sreloc = bfd_get_section_by_name (dynobj, name);
   2202  1.1.1.5  christos 		    if (sreloc == NULL)
   2203  1.1.1.5  christos 		      {
   2204  1.1.1.5  christos 			sreloc = _bfd_elf_make_dynamic_reloc_section
   2205  1.1.1.7  christos 			  (sec, dynobj, 2, abfd, /*rela?*/ true);
   2206  1.1.1.5  christos 
   2207  1.1.1.5  christos 			if (sreloc == NULL)
   2208  1.1.1.7  christos 			  return false;
   2209  1.1.1.5  christos 		      }
   2210  1.1.1.5  christos 		    elf_section_data (sec)->sreloc = sreloc;
   2211  1.1.1.5  christos 		  }
   2212  1.1.1.5  christos 
   2213  1.1.1.5  christos 		/* If this is a global symbol, we count the number of
   2214  1.1.1.5  christos 		   relocations we need for this symbol.  */
   2215  1.1.1.5  christos 		if (h != NULL)
   2216  1.1.1.6  christos 		  head = &h->dyn_relocs;
   2217  1.1.1.5  christos 		else
   2218  1.1.1.5  christos 		  {
   2219  1.1.1.5  christos 		    /* Track dynamic relocs needed for local syms too.
   2220  1.1.1.5  christos 		       We really need local syms available to do this
   2221  1.1.1.5  christos 		       easily.  Oh well.  */
   2222  1.1.1.5  christos 
   2223  1.1.1.5  christos 		    asection *s;
   2224  1.1.1.5  christos 		    Elf_Internal_Sym *isym;
   2225  1.1.1.5  christos 		    void *vpp;
   2226  1.1.1.5  christos 
   2227  1.1.1.6  christos 		    isym = bfd_sym_from_r_symndx (&htab->root.sym_cache,
   2228  1.1.1.5  christos 						  abfd, r_symndx);
   2229  1.1.1.5  christos 		    if (isym == NULL)
   2230  1.1.1.7  christos 		      return false;
   2231  1.1.1.5  christos 
   2232  1.1.1.5  christos 		    s = bfd_section_from_elf_index (abfd, isym->st_shndx);
   2233  1.1.1.5  christos 		    if (s == NULL)
   2234  1.1.1.7  christos 		      return false;
   2235  1.1.1.5  christos 
   2236  1.1.1.5  christos 		    vpp = &elf_section_data (s)->local_dynrel;
   2237  1.1.1.5  christos 		    head = (struct elf_dyn_relocs **) vpp;
   2238  1.1.1.5  christos 		  }
   2239  1.1.1.5  christos 
   2240  1.1.1.6  christos 		sec_relocs = *head;
   2241  1.1.1.6  christos 		/* Allocate this sections dynamic reolcations structure if this
   2242  1.1.1.6  christos 		   is a new section.  */
   2243  1.1.1.6  christos 		if (sec_relocs == NULL || sec_relocs->sec != sec)
   2244  1.1.1.5  christos 		  {
   2245  1.1.1.6  christos 		    size_t amt = sizeof *sec_relocs;
   2246  1.1.1.6  christos 		    sec_relocs = ((struct elf_dyn_relocs *)
   2247  1.1.1.6  christos 				  bfd_alloc (htab->root.dynobj, amt));
   2248  1.1.1.6  christos 		    if (sec_relocs == NULL)
   2249  1.1.1.7  christos 		      return false;
   2250  1.1.1.6  christos 		    sec_relocs->next = *head;
   2251  1.1.1.6  christos 		    *head = sec_relocs;
   2252  1.1.1.6  christos 		    sec_relocs->sec = sec;
   2253  1.1.1.6  christos 		    sec_relocs->count = 0;
   2254  1.1.1.6  christos 		    sec_relocs->pc_count = 0;
   2255  1.1.1.5  christos 		  }
   2256  1.1.1.5  christos 
   2257  1.1.1.6  christos 		sec_relocs->count += 1;
   2258  1.1.1.5  christos 		if (r_type == R_OR1K_INSN_REL_26)
   2259  1.1.1.6  christos 		  sec_relocs->pc_count += 1;
   2260  1.1.1.5  christos 	      }
   2261  1.1.1.5  christos 	  }
   2262  1.1.1.5  christos 	  break;
   2263  1.1.1.5  christos 	}
   2264      1.1  christos     }
   2265      1.1  christos 
   2266  1.1.1.7  christos   return true;
   2267      1.1  christos }
   2268      1.1  christos 
   2269  1.1.1.5  christos static void
   2270  1.1.1.7  christos or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj,
   2271  1.1.1.7  christos 		      unsigned insns[], size_t insn_count)
   2272  1.1.1.5  christos {
   2273  1.1.1.5  christos   unsigned nodelay = elf_elfheader (output_bfd)->e_flags & EF_OR1K_NODELAY;
   2274  1.1.1.7  christos   unsigned output_insns[PLT_MAX_INSN_COUNT];
   2275  1.1.1.7  christos 
   2276  1.1.1.7  christos   /* Copy instructions into the output buffer.  */
   2277  1.1.1.7  christos   for (size_t i = 0; i < insn_count; i++)
   2278  1.1.1.7  christos     output_insns[i] = insns[i];
   2279  1.1.1.5  christos 
   2280  1.1.1.5  christos   /* Honor the no-delay-slot setting.  */
   2281  1.1.1.7  christos   if (insns[insn_count-1] == OR1K_NOP)
   2282  1.1.1.5  christos     {
   2283  1.1.1.7  christos       unsigned slot1, slot2;
   2284  1.1.1.7  christos 
   2285  1.1.1.5  christos       if (nodelay)
   2286  1.1.1.7  christos 	slot1 = insns[insn_count-2], slot2 = insnj;
   2287  1.1.1.5  christos       else
   2288  1.1.1.7  christos 	slot1 = insnj, slot2 = insns[insn_count-2];
   2289  1.1.1.7  christos 
   2290  1.1.1.7  christos       output_insns[insn_count-2] = slot1;
   2291  1.1.1.7  christos       output_insns[insn_count-1] = slot2;
   2292  1.1.1.7  christos       output_insns[insn_count]   = OR1K_NOP;
   2293  1.1.1.5  christos     }
   2294  1.1.1.5  christos   else
   2295  1.1.1.5  christos     {
   2296  1.1.1.7  christos       unsigned slot1, slot2;
   2297  1.1.1.7  christos 
   2298  1.1.1.5  christos       if (nodelay)
   2299  1.1.1.7  christos 	slot1 = insns[insn_count-1], slot2 = insnj;
   2300  1.1.1.5  christos       else
   2301  1.1.1.7  christos 	slot1 = insnj, slot2 = insns[insn_count-1];
   2302  1.1.1.7  christos 
   2303  1.1.1.7  christos       output_insns[insn_count-1] = slot1;
   2304  1.1.1.7  christos       output_insns[insn_count]   = slot2;
   2305  1.1.1.5  christos     }
   2306  1.1.1.5  christos 
   2307  1.1.1.7  christos   /* Write out the output buffer.  */
   2308  1.1.1.7  christos   for (size_t i = 0; i < (insn_count+1); i++)
   2309  1.1.1.7  christos     bfd_put_32 (output_bfd, output_insns[i], contents + (i*4));
   2310  1.1.1.5  christos }
   2311  1.1.1.5  christos 
   2312      1.1  christos /* Finish up the dynamic sections.  */
   2313      1.1  christos 
   2314  1.1.1.7  christos static bool
   2315      1.1  christos or1k_elf_finish_dynamic_sections (bfd *output_bfd,
   2316  1.1.1.5  christos 				  struct bfd_link_info *info)
   2317      1.1  christos {
   2318      1.1  christos   bfd *dynobj;
   2319      1.1  christos   asection *sdyn, *sgot;
   2320      1.1  christos   struct elf_or1k_link_hash_table *htab;
   2321      1.1  christos 
   2322      1.1  christos   htab = or1k_elf_hash_table (info);
   2323      1.1  christos   if (htab == NULL)
   2324  1.1.1.7  christos     return false;
   2325      1.1  christos 
   2326      1.1  christos   dynobj = htab->root.dynobj;
   2327      1.1  christos 
   2328  1.1.1.4  christos   sgot = htab->root.sgotplt;
   2329      1.1  christos   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
   2330      1.1  christos 
   2331      1.1  christos   if (htab->root.dynamic_sections_created)
   2332      1.1  christos     {
   2333      1.1  christos       asection *splt;
   2334      1.1  christos       Elf32_External_Dyn *dyncon, *dynconend;
   2335      1.1  christos 
   2336      1.1  christos       BFD_ASSERT (sgot != NULL && sdyn != NULL);
   2337      1.1  christos 
   2338      1.1  christos       dyncon = (Elf32_External_Dyn *) sdyn->contents;
   2339      1.1  christos       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
   2340      1.1  christos 
   2341      1.1  christos       for (; dyncon < dynconend; dyncon++)
   2342  1.1.1.5  christos 	{
   2343  1.1.1.5  christos 	  Elf_Internal_Dyn dyn;
   2344  1.1.1.5  christos 	  asection *s;
   2345  1.1.1.5  christos 
   2346  1.1.1.5  christos 	  bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
   2347  1.1.1.5  christos 
   2348  1.1.1.5  christos 	  switch (dyn.d_tag)
   2349  1.1.1.5  christos 	    {
   2350  1.1.1.5  christos 	    default:
   2351  1.1.1.5  christos 	      continue;
   2352  1.1.1.5  christos 
   2353  1.1.1.5  christos 	    case DT_PLTGOT:
   2354  1.1.1.5  christos 	      s = htab->root.sgotplt;
   2355  1.1.1.5  christos 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   2356  1.1.1.5  christos 	      break;
   2357  1.1.1.5  christos 
   2358  1.1.1.5  christos 	    case DT_JMPREL:
   2359  1.1.1.5  christos 	      s = htab->root.srelplt;
   2360  1.1.1.5  christos 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   2361  1.1.1.5  christos 	      break;
   2362  1.1.1.5  christos 
   2363  1.1.1.5  christos 	    case DT_PLTRELSZ:
   2364  1.1.1.5  christos 	      s = htab->root.srelplt;
   2365  1.1.1.5  christos 	      dyn.d_un.d_val = s->size;
   2366  1.1.1.5  christos 	      break;
   2367  1.1.1.5  christos 	    }
   2368  1.1.1.5  christos 	  bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   2369  1.1.1.5  christos 	}
   2370      1.1  christos 
   2371      1.1  christos 
   2372      1.1  christos       /* Fill in the first entry in the procedure linkage table.  */
   2373  1.1.1.4  christos       splt = htab->root.splt;
   2374      1.1  christos       if (splt && splt->size > 0)
   2375  1.1.1.5  christos 	{
   2376  1.1.1.7  christos 	  unsigned plt[PLT_MAX_INSN_COUNT];
   2377  1.1.1.7  christos 	  size_t plt_insn_count = 3;
   2378  1.1.1.5  christos 	  bfd_vma got_addr = sgot->output_section->vma + sgot->output_offset;
   2379  1.1.1.5  christos 
   2380  1.1.1.5  christos 	  /* Note we force 16 byte alignment on the .got, so that
   2381  1.1.1.5  christos 	     the movhi/adrp can be shared between the two loads.  */
   2382  1.1.1.5  christos 
   2383  1.1.1.5  christos 	  if (htab->saw_plta)
   2384  1.1.1.5  christos 	    {
   2385  1.1.1.5  christos 	      bfd_vma pc = splt->output_section->vma + splt->output_offset;
   2386  1.1.1.5  christos 	      unsigned pa = ((got_addr >> 13) - (pc >> 13)) & 0x1fffff;
   2387  1.1.1.5  christos 	      unsigned po = got_addr & 0x1fff;
   2388  1.1.1.7  christos 	      plt[0] = OR1K_ADRP(12) | pa;
   2389  1.1.1.7  christos 	      plt[1] = OR1K_LWZ(15,12) | (po + 8);
   2390  1.1.1.7  christos 	      plt[2] = OR1K_LWZ(12,12) | (po + 4);
   2391  1.1.1.5  christos 	    }
   2392  1.1.1.5  christos 	  else if (bfd_link_pic (info))
   2393  1.1.1.5  christos 	    {
   2394  1.1.1.7  christos 	      plt[0] = OR1K_LWZ(15, 16) | 8;	/* .got+8 */
   2395  1.1.1.7  christos 	      plt[1] = OR1K_LWZ(12, 16) | 4;	/* .got+4 */
   2396  1.1.1.7  christos 	      plt[2] = OR1K_NOP;
   2397  1.1.1.5  christos 	    }
   2398  1.1.1.5  christos 	  else
   2399  1.1.1.5  christos 	    {
   2400  1.1.1.5  christos 	      unsigned ha = ((got_addr + 0x8000) >> 16) & 0xffff;
   2401  1.1.1.5  christos 	      unsigned lo = got_addr & 0xffff;
   2402  1.1.1.7  christos 	      plt[0] = OR1K_MOVHI(12) | ha;
   2403  1.1.1.7  christos 	      plt[1] = OR1K_LWZ(15,12) | (lo + 8);
   2404  1.1.1.7  christos 	      plt[2] = OR1K_LWZ(12,12) | (lo + 4);
   2405  1.1.1.5  christos 	    }
   2406      1.1  christos 
   2407  1.1.1.7  christos 	  or1k_write_plt_entry (output_bfd, splt->contents, OR1K_JR(15),
   2408  1.1.1.7  christos 				plt, plt_insn_count);
   2409  1.1.1.5  christos 
   2410  1.1.1.5  christos 	  elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
   2411  1.1.1.5  christos 	}
   2412      1.1  christos     }
   2413      1.1  christos 
   2414      1.1  christos   /* Set the first entry in the global offset table to the address of
   2415      1.1  christos      the dynamic section.  */
   2416      1.1  christos   if (sgot && sgot->size > 0)
   2417      1.1  christos     {
   2418      1.1  christos       if (sdyn == NULL)
   2419  1.1.1.5  christos 	bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
   2420      1.1  christos       else
   2421  1.1.1.5  christos 	bfd_put_32 (output_bfd,
   2422  1.1.1.5  christos 		    sdyn->output_section->vma + sdyn->output_offset,
   2423  1.1.1.5  christos 		    sgot->contents);
   2424      1.1  christos       elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
   2425      1.1  christos     }
   2426      1.1  christos 
   2427  1.1.1.4  christos   if (htab->root.sgot && htab->root.sgot->size > 0)
   2428  1.1.1.4  christos     elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize = 4;
   2429      1.1  christos 
   2430  1.1.1.7  christos   return true;
   2431      1.1  christos }
   2432      1.1  christos 
   2433      1.1  christos /* Finish up dynamic symbol handling.  We set the contents of various
   2434      1.1  christos    dynamic sections here.  */
   2435      1.1  christos 
   2436  1.1.1.7  christos static bool
   2437      1.1  christos or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
   2438  1.1.1.5  christos 				struct bfd_link_info *info,
   2439  1.1.1.5  christos 				struct elf_link_hash_entry *h,
   2440  1.1.1.5  christos 				Elf_Internal_Sym *sym)
   2441      1.1  christos {
   2442      1.1  christos   struct elf_or1k_link_hash_table *htab;
   2443      1.1  christos   bfd_byte *loc;
   2444      1.1  christos 
   2445      1.1  christos   htab = or1k_elf_hash_table (info);
   2446      1.1  christos   if (htab == NULL)
   2447  1.1.1.7  christos     return false;
   2448      1.1  christos 
   2449      1.1  christos   if (h->plt.offset != (bfd_vma) -1)
   2450      1.1  christos     {
   2451  1.1.1.7  christos       unsigned int plt[PLT_MAX_INSN_COUNT];
   2452  1.1.1.7  christos       size_t plt_insn_count = 3;
   2453      1.1  christos       asection *splt;
   2454      1.1  christos       asection *sgot;
   2455      1.1  christos       asection *srela;
   2456  1.1.1.5  christos       bfd_vma plt_base_addr;
   2457  1.1.1.5  christos       bfd_vma plt_addr;
   2458      1.1  christos       bfd_vma plt_index;
   2459  1.1.1.5  christos       bfd_vma plt_reloc;
   2460  1.1.1.5  christos       bfd_vma got_base_addr;
   2461      1.1  christos       bfd_vma got_offset;
   2462      1.1  christos       bfd_vma got_addr;
   2463      1.1  christos       Elf_Internal_Rela rela;
   2464  1.1.1.7  christos       bool large_plt_entry;
   2465      1.1  christos 
   2466      1.1  christos       /* This symbol has an entry in the procedure linkage table.  Set
   2467  1.1.1.5  christos 	 it up.  */
   2468      1.1  christos       BFD_ASSERT (h->dynindx != -1);
   2469      1.1  christos 
   2470  1.1.1.4  christos       splt = htab->root.splt;
   2471  1.1.1.4  christos       sgot = htab->root.sgotplt;
   2472  1.1.1.4  christos       srela = htab->root.srelplt;
   2473      1.1  christos       BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
   2474      1.1  christos 
   2475  1.1.1.5  christos       plt_base_addr = splt->output_section->vma + splt->output_offset;
   2476  1.1.1.5  christos       got_base_addr = sgot->output_section->vma + sgot->output_offset;
   2477  1.1.1.5  christos 
   2478      1.1  christos       /* Get the index in the procedure linkage table which
   2479  1.1.1.5  christos 	 corresponds to this symbol.  This is the index of this symbol
   2480  1.1.1.5  christos 	 in all the symbols for which we are making plt entries.  The
   2481  1.1.1.5  christos 	 first entry in the procedure linkage table is reserved.  */
   2482  1.1.1.7  christos       plt_index = ((struct elf_or1k_link_hash_entry *) h)->plt_index;
   2483  1.1.1.5  christos       plt_addr = plt_base_addr + h->plt.offset;
   2484  1.1.1.5  christos       plt_reloc = plt_index * sizeof (Elf32_External_Rela);
   2485      1.1  christos 
   2486  1.1.1.7  christos       large_plt_entry = (elf_or1k_plt_entry_size (plt_index)
   2487  1.1.1.7  christos 			 == PLT_ENTRY_SIZE_LARGE);
   2488  1.1.1.7  christos 
   2489      1.1  christos       /* Get the offset into the .got table of the entry that
   2490  1.1.1.5  christos 	corresponds to this function.  Each .got entry is 4 bytes.
   2491  1.1.1.5  christos 	The first three are reserved.  */
   2492      1.1  christos       got_offset = (plt_index + 3) * 4;
   2493  1.1.1.5  christos       got_addr = got_base_addr + got_offset;
   2494      1.1  christos 
   2495      1.1  christos       /* Fill in the entry in the procedure linkage table.  */
   2496  1.1.1.5  christos       if (htab->saw_plta)
   2497  1.1.1.5  christos 	{
   2498  1.1.1.5  christos 	  unsigned pa = ((got_addr >> 13) - (plt_addr >> 13)) & 0x1fffff;
   2499  1.1.1.5  christos 	  unsigned po = (got_addr & 0x1fff);
   2500  1.1.1.7  christos 	  plt[0] = OR1K_ADRP(12) | pa;
   2501  1.1.1.7  christos 	  plt[1] = OR1K_LWZ(12,12) | po;
   2502  1.1.1.7  christos 	  plt[2] = OR1K_ORI0(11) | plt_reloc;
   2503  1.1.1.5  christos 	}
   2504  1.1.1.5  christos       else if (bfd_link_pic (info))
   2505  1.1.1.5  christos 	{
   2506  1.1.1.7  christos 	  if (large_plt_entry)
   2507  1.1.1.7  christos 	    {
   2508  1.1.1.7  christos 	      unsigned gotha = ((got_offset + 0x8000) >> 16) & 0xffff;
   2509  1.1.1.7  christos 	      unsigned got = got_offset & 0xffff;
   2510  1.1.1.7  christos 	      unsigned pltrelhi = (plt_reloc >> 16) & 0xffff;
   2511  1.1.1.7  christos 	      unsigned pltrello = plt_reloc & 0xffff;
   2512  1.1.1.7  christos 
   2513  1.1.1.7  christos 	      plt[0] = OR1K_MOVHI(12) | gotha;
   2514  1.1.1.7  christos 	      plt[1] = OR1K_ADD(12,12,16);
   2515  1.1.1.7  christos 	      plt[2] = OR1K_LWZ(12,12) | got;
   2516  1.1.1.7  christos 	      plt[3] = OR1K_MOVHI(11) | pltrelhi;
   2517  1.1.1.7  christos 	      plt[4] = OR1K_ORI(11,11) | pltrello;
   2518  1.1.1.7  christos 	      plt_insn_count = 5;
   2519  1.1.1.7  christos 	    }
   2520  1.1.1.7  christos 	  else
   2521  1.1.1.7  christos 	    {
   2522  1.1.1.7  christos 	      plt[0] = OR1K_LWZ(12,16) | got_offset;
   2523  1.1.1.7  christos 	      plt[1] = OR1K_ORI0(11) | plt_reloc;
   2524  1.1.1.7  christos 	      plt[2] = OR1K_NOP;
   2525  1.1.1.7  christos 	    }
   2526  1.1.1.5  christos 	}
   2527      1.1  christos       else
   2528  1.1.1.5  christos 	{
   2529  1.1.1.5  christos 	  unsigned ha = ((got_addr + 0x8000) >> 16) & 0xffff;
   2530  1.1.1.5  christos 	  unsigned lo = got_addr & 0xffff;
   2531  1.1.1.7  christos 	  plt[0] = OR1K_MOVHI(12) | ha;
   2532  1.1.1.7  christos 	  plt[1] = OR1K_LWZ(12,12) | lo;
   2533  1.1.1.7  christos 	  plt[2] = OR1K_ORI0(11) | plt_reloc;
   2534  1.1.1.7  christos 	}
   2535  1.1.1.7  christos 
   2536  1.1.1.7  christos       /* For large code model we fixup the non-PIC PLT relocation instructions
   2537  1.1.1.7  christos 	 here.  */
   2538  1.1.1.7  christos       if (large_plt_entry && !bfd_link_pic (info))
   2539  1.1.1.7  christos 	{
   2540  1.1.1.7  christos 	  unsigned pltrelhi = (plt_reloc >> 16) & 0xffff;
   2541  1.1.1.7  christos 	  unsigned pltrello = plt_reloc & 0xffff;
   2542  1.1.1.7  christos 
   2543  1.1.1.7  christos 	  plt[2] = OR1K_MOVHI(11) | pltrelhi;
   2544  1.1.1.7  christos 	  plt[3] = OR1K_ORI(11,11) | pltrello;
   2545  1.1.1.7  christos 	  plt[4] = OR1K_NOP;
   2546  1.1.1.7  christos 	  plt_insn_count = 5;
   2547  1.1.1.5  christos 	}
   2548  1.1.1.5  christos 
   2549  1.1.1.5  christos       or1k_write_plt_entry (output_bfd, splt->contents + h->plt.offset,
   2550  1.1.1.7  christos 			    OR1K_JR(12), plt, plt_insn_count);
   2551      1.1  christos 
   2552  1.1.1.6  christos       /* Fill in the entry in the global offset table.  We initialize it to
   2553  1.1.1.6  christos 	 point to the top of the plt.  This is done to lazy lookup the actual
   2554  1.1.1.6  christos 	 symbol as the first plt entry will be setup by libc to call the
   2555  1.1.1.6  christos 	 runtime dynamic linker.  */
   2556  1.1.1.6  christos       bfd_put_32 (output_bfd, plt_base_addr, sgot->contents + got_offset);
   2557      1.1  christos 
   2558      1.1  christos       /* Fill in the entry in the .rela.plt section.  */
   2559  1.1.1.5  christos       rela.r_offset = got_addr;
   2560      1.1  christos       rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_JMP_SLOT);
   2561      1.1  christos       rela.r_addend = 0;
   2562      1.1  christos       loc = srela->contents;
   2563      1.1  christos       loc += plt_index * sizeof (Elf32_External_Rela);
   2564      1.1  christos       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   2565      1.1  christos 
   2566      1.1  christos       if (!h->def_regular)
   2567  1.1.1.5  christos 	{
   2568  1.1.1.5  christos 	  /* Mark the symbol as undefined, rather than as defined in
   2569  1.1.1.5  christos 	     the .plt section.  Leave the value alone.  */
   2570  1.1.1.5  christos 	  sym->st_shndx = SHN_UNDEF;
   2571  1.1.1.5  christos 	}
   2572      1.1  christos     }
   2573      1.1  christos 
   2574      1.1  christos   if (h->got.offset != (bfd_vma) -1
   2575      1.1  christos       && (h->got.offset & 2) == 0) /* Homemade TLS check.  */
   2576      1.1  christos     {
   2577      1.1  christos       asection *sgot;
   2578  1.1.1.6  christos       asection *srelgot;
   2579      1.1  christos       Elf_Internal_Rela rela;
   2580      1.1  christos 
   2581      1.1  christos       /* This symbol has an entry in the global offset table.  Set it
   2582  1.1.1.5  christos 	 up.  */
   2583  1.1.1.4  christos       sgot = htab->root.sgot;
   2584  1.1.1.6  christos       srelgot = htab->root.srelgot;
   2585  1.1.1.6  christos       BFD_ASSERT (sgot != NULL && srelgot != NULL);
   2586      1.1  christos 
   2587      1.1  christos       rela.r_offset = (sgot->output_section->vma
   2588  1.1.1.5  christos 		       + sgot->output_offset
   2589  1.1.1.5  christos 		       + (h->got.offset &~ 1));
   2590      1.1  christos 
   2591      1.1  christos       /* If this is a -Bsymbolic link, and the symbol is defined
   2592  1.1.1.5  christos 	 locally, we just want to emit a RELATIVE reloc.  Likewise if
   2593  1.1.1.5  christos 	 the symbol was forced to be local because of a version file.
   2594  1.1.1.5  christos 	 The entry in the global offset table will already have been
   2595  1.1.1.5  christos 	 initialized in the relocate_section function.  */
   2596  1.1.1.3  christos       if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
   2597  1.1.1.5  christos 	{
   2598  1.1.1.5  christos 	  rela.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
   2599  1.1.1.5  christos 	  rela.r_addend = (h->root.u.def.value
   2600  1.1.1.5  christos 			   + h->root.u.def.section->output_section->vma
   2601  1.1.1.5  christos 			   + h->root.u.def.section->output_offset);
   2602  1.1.1.5  christos 	}
   2603      1.1  christos       else
   2604  1.1.1.5  christos 	{
   2605  1.1.1.5  christos 	  BFD_ASSERT ((h->got.offset & 1) == 0);
   2606  1.1.1.5  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
   2607  1.1.1.5  christos 	  rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_GLOB_DAT);
   2608  1.1.1.5  christos 	  rela.r_addend = 0;
   2609  1.1.1.5  christos 	}
   2610      1.1  christos 
   2611  1.1.1.6  christos       loc = srelgot->contents;
   2612  1.1.1.6  christos       loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
   2613      1.1  christos       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   2614  1.1.1.6  christos       ++srelgot->reloc_count;
   2615      1.1  christos     }
   2616      1.1  christos 
   2617      1.1  christos   if (h->needs_copy)
   2618      1.1  christos     {
   2619      1.1  christos       asection *s;
   2620      1.1  christos       Elf_Internal_Rela rela;
   2621      1.1  christos 
   2622      1.1  christos       /* This symbols needs a copy reloc.  Set it up.  */
   2623      1.1  christos       BFD_ASSERT (h->dynindx != -1
   2624  1.1.1.5  christos 		  && (h->root.type == bfd_link_hash_defined
   2625  1.1.1.5  christos 		      || h->root.type == bfd_link_hash_defweak));
   2626      1.1  christos 
   2627      1.1  christos       rela.r_offset = (h->root.u.def.value
   2628  1.1.1.5  christos 		       + h->root.u.def.section->output_section->vma
   2629  1.1.1.5  christos 		       + h->root.u.def.section->output_offset);
   2630      1.1  christos       rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_COPY);
   2631      1.1  christos       rela.r_addend = 0;
   2632  1.1.1.4  christos       if (h->root.u.def.section == htab->root.sdynrelro)
   2633  1.1.1.4  christos 	s = htab->root.sreldynrelro;
   2634  1.1.1.4  christos       else
   2635  1.1.1.4  christos 	s = htab->root.srelbss;
   2636  1.1.1.4  christos       loc = s->contents + s->reloc_count * sizeof (Elf32_External_Rela);
   2637      1.1  christos       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   2638      1.1  christos       ++s->reloc_count;
   2639      1.1  christos     }
   2640      1.1  christos 
   2641      1.1  christos   /* Mark some specially defined symbols as absolute.  */
   2642      1.1  christos   if (strcmp (h->root.root.string, "_DYNAMIC") == 0
   2643      1.1  christos       || h == htab->root.hgot)
   2644      1.1  christos     sym->st_shndx = SHN_ABS;
   2645      1.1  christos 
   2646  1.1.1.7  christos   return true;
   2647      1.1  christos }
   2648      1.1  christos 
   2649      1.1  christos static enum elf_reloc_type_class
   2650      1.1  christos or1k_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
   2651  1.1.1.5  christos 			   const asection *rel_sec ATTRIBUTE_UNUSED,
   2652  1.1.1.5  christos 			   const Elf_Internal_Rela *rela)
   2653      1.1  christos {
   2654      1.1  christos   switch ((int) ELF32_R_TYPE (rela->r_info))
   2655      1.1  christos     {
   2656      1.1  christos     case R_OR1K_RELATIVE:  return reloc_class_relative;
   2657      1.1  christos     case R_OR1K_JMP_SLOT:  return reloc_class_plt;
   2658  1.1.1.5  christos     case R_OR1K_COPY:	   return reloc_class_copy;
   2659  1.1.1.5  christos     default:		   return reloc_class_normal;
   2660  1.1.1.5  christos     }
   2661  1.1.1.5  christos }
   2662  1.1.1.5  christos 
   2663      1.1  christos /* Adjust a symbol defined by a dynamic object and referenced by a
   2664      1.1  christos    regular object.  The current definition is in some section of the
   2665      1.1  christos    dynamic object, but we're not including those sections.  We have to
   2666      1.1  christos    change the definition to something the rest of the link can
   2667      1.1  christos    understand.  */
   2668      1.1  christos 
   2669  1.1.1.7  christos static bool
   2670      1.1  christos or1k_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   2671  1.1.1.5  christos 				struct elf_link_hash_entry *h)
   2672      1.1  christos {
   2673      1.1  christos   struct elf_or1k_link_hash_table *htab;
   2674      1.1  christos   bfd *dynobj;
   2675  1.1.1.4  christos   asection *s, *srel;
   2676      1.1  christos 
   2677      1.1  christos   dynobj = elf_hash_table (info)->dynobj;
   2678      1.1  christos 
   2679      1.1  christos   /* Make sure we know what is going on here.  */
   2680      1.1  christos   BFD_ASSERT (dynobj != NULL
   2681  1.1.1.5  christos 	      && (h->needs_plt
   2682  1.1.1.5  christos 		  || h->is_weakalias
   2683  1.1.1.5  christos 		  || (h->def_dynamic
   2684  1.1.1.5  christos 		      && h->ref_regular
   2685  1.1.1.5  christos 		      && !h->def_regular)));
   2686      1.1  christos 
   2687      1.1  christos   /* If this is a function, put it in the procedure linkage table.  We
   2688      1.1  christos      will fill in the contents of the procedure linkage table later,
   2689      1.1  christos      when we know the address of the .got section.  */
   2690      1.1  christos   if (h->type == STT_FUNC
   2691      1.1  christos       || h->needs_plt)
   2692      1.1  christos     {
   2693  1.1.1.7  christos       if (h->plt.refcount <= 0
   2694  1.1.1.7  christos 	  || (SYMBOL_CALLS_LOCAL (info, h)
   2695  1.1.1.7  christos 	  || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
   2696  1.1.1.7  christos 	      && h->root.type == bfd_link_hash_undefweak)))
   2697  1.1.1.5  christos 	{
   2698  1.1.1.5  christos 	  /* This case can occur if we saw a PLT reloc in an input
   2699  1.1.1.5  christos 	     file, but the symbol was never referred to by a dynamic
   2700  1.1.1.5  christos 	     object.  In such a case, we don't actually need to build
   2701  1.1.1.5  christos 	     a procedure linkage table, and we can just do a PCREL
   2702  1.1.1.5  christos 	     reloc instead.  */
   2703  1.1.1.5  christos 	  h->plt.offset = (bfd_vma) -1;
   2704  1.1.1.5  christos 	  h->needs_plt = 0;
   2705  1.1.1.5  christos 	}
   2706      1.1  christos 
   2707  1.1.1.7  christos       return true;
   2708      1.1  christos     }
   2709      1.1  christos   else
   2710      1.1  christos     h->plt.offset = (bfd_vma) -1;
   2711      1.1  christos 
   2712      1.1  christos   /* If this is a weak symbol, and there is a real definition, the
   2713      1.1  christos      processor independent code will have arranged for us to see the
   2714      1.1  christos      real definition first, and we can just use the same value.  */
   2715  1.1.1.5  christos   if (h->is_weakalias)
   2716      1.1  christos     {
   2717  1.1.1.5  christos       struct elf_link_hash_entry *def = weakdef (h);
   2718  1.1.1.5  christos       BFD_ASSERT (def->root.type == bfd_link_hash_defined);
   2719  1.1.1.5  christos       h->root.u.def.section = def->root.u.def.section;
   2720  1.1.1.5  christos       h->root.u.def.value = def->root.u.def.value;
   2721  1.1.1.7  christos       return true;
   2722      1.1  christos     }
   2723      1.1  christos 
   2724      1.1  christos   /* This is a reference to a symbol defined by a dynamic object which
   2725      1.1  christos      is not a function.  */
   2726      1.1  christos 
   2727      1.1  christos   /* If we are creating a shared library, we must presume that the
   2728      1.1  christos      only references to the symbol are via the global offset table.
   2729      1.1  christos      For such cases we need not do anything here; the relocations will
   2730      1.1  christos      be handled correctly by relocate_section.  */
   2731  1.1.1.3  christos   if (bfd_link_pic (info))
   2732  1.1.1.7  christos     return true;
   2733      1.1  christos 
   2734      1.1  christos   /* If there are no references to this symbol that do not use the
   2735      1.1  christos      GOT, we don't need to generate a copy reloc.  */
   2736      1.1  christos   if (!h->non_got_ref)
   2737  1.1.1.7  christos     return true;
   2738      1.1  christos 
   2739      1.1  christos   /* If -z nocopyreloc was given, we won't generate them either.  */
   2740      1.1  christos   if (info->nocopyreloc)
   2741      1.1  christos     {
   2742      1.1  christos       h->non_got_ref = 0;
   2743  1.1.1.7  christos       return true;
   2744      1.1  christos     }
   2745      1.1  christos 
   2746  1.1.1.5  christos   /* If we don't find any dynamic relocs in read-only sections, then
   2747  1.1.1.5  christos      we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
   2748  1.1.1.6  christos   if (!_bfd_elf_readonly_dynrelocs (h))
   2749      1.1  christos     {
   2750      1.1  christos       h->non_got_ref = 0;
   2751  1.1.1.7  christos       return true;
   2752      1.1  christos     }
   2753      1.1  christos 
   2754      1.1  christos   /* We must allocate the symbol in our .dynbss section, which will
   2755      1.1  christos      become part of the .bss section of the executable.  There will be
   2756      1.1  christos      an entry for this symbol in the .dynsym section.  The dynamic
   2757      1.1  christos      object will contain position independent code, so all references
   2758      1.1  christos      from the dynamic object to this symbol will go through the global
   2759      1.1  christos      offset table.  The dynamic linker will use the .dynsym entry to
   2760      1.1  christos      determine the address it must put in the global offset table, so
   2761      1.1  christos      both the dynamic object and the regular object will refer to the
   2762      1.1  christos      same memory location for the variable.  */
   2763      1.1  christos 
   2764      1.1  christos   htab = or1k_elf_hash_table (info);
   2765      1.1  christos   if (htab == NULL)
   2766  1.1.1.7  christos     return false;
   2767      1.1  christos 
   2768      1.1  christos   /* We must generate a R_OR1K_COPY reloc to tell the dynamic linker
   2769      1.1  christos      to copy the initial value out of the dynamic object and into the
   2770      1.1  christos      runtime process image.  We need to remember the offset into the
   2771      1.1  christos      .rela.bss section we are going to use.  */
   2772  1.1.1.4  christos   if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
   2773  1.1.1.4  christos     {
   2774  1.1.1.4  christos       s = htab->root.sdynrelro;
   2775  1.1.1.4  christos       srel = htab->root.sreldynrelro;
   2776  1.1.1.4  christos     }
   2777  1.1.1.4  christos   else
   2778  1.1.1.4  christos     {
   2779  1.1.1.4  christos       s = htab->root.sdynbss;
   2780  1.1.1.4  christos       srel = htab->root.srelbss;
   2781  1.1.1.4  christos     }
   2782      1.1  christos   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
   2783      1.1  christos     {
   2784      1.1  christos       srel->size += sizeof (Elf32_External_Rela);
   2785      1.1  christos       h->needs_copy = 1;
   2786      1.1  christos     }
   2787      1.1  christos 
   2788      1.1  christos   return _bfd_elf_adjust_dynamic_copy (info, h, s);
   2789      1.1  christos }
   2790      1.1  christos 
   2791  1.1.1.6  christos /* Caclulate an update the sizes required for a symbol in the GOT and
   2792  1.1.1.6  christos    RELA relocation section based on the TLS_TYPE and whether or not the symbol
   2793  1.1.1.6  christos    is DYNAMIC.
   2794  1.1.1.6  christos 
   2795  1.1.1.6  christos    Symbols with TLS_GD access require 8 bytes in the GOT and, if dynamic,
   2796  1.1.1.6  christos    require two relocation entries.  Symbols with TLS_IE access require 4 bytes
   2797  1.1.1.6  christos    in the GOT and, if dynamic, require one relocation entry.  Symbols may have
   2798  1.1.1.6  christos    both TLS_GD and TLS_IE access to be accounted for.
   2799  1.1.1.6  christos 
   2800  1.1.1.6  christos    Other symbols require 4 bytes in the GOT table and, if dynamic, require one
   2801  1.1.1.6  christos    relocation entry.  */
   2802  1.1.1.6  christos 
   2803  1.1.1.6  christos static void
   2804  1.1.1.6  christos or1k_set_got_and_rela_sizes (const unsigned char tls_type,
   2805  1.1.1.7  christos 			     const bool dynamic,
   2806  1.1.1.6  christos 			     bfd_vma *got_size,
   2807  1.1.1.6  christos 			     bfd_vma *rela_size)
   2808  1.1.1.6  christos {
   2809  1.1.1.7  christos   bool is_tls_entry = false;
   2810  1.1.1.6  christos 
   2811  1.1.1.6  christos   /* TLS GD requires two GOT entries and two relocs.  */
   2812  1.1.1.6  christos   if ((tls_type & TLS_GD) != 0)
   2813  1.1.1.6  christos     {
   2814  1.1.1.6  christos       *got_size += 8;
   2815  1.1.1.7  christos       is_tls_entry = true;
   2816  1.1.1.6  christos     }
   2817  1.1.1.6  christos 
   2818  1.1.1.6  christos   if ((tls_type & TLS_IE) != 0)
   2819  1.1.1.6  christos     {
   2820  1.1.1.6  christos       *got_size += 4;
   2821  1.1.1.7  christos       is_tls_entry = true;
   2822  1.1.1.6  christos     }
   2823  1.1.1.6  christos 
   2824  1.1.1.7  christos   if (!is_tls_entry)
   2825  1.1.1.6  christos     *got_size += 4;
   2826  1.1.1.6  christos 
   2827  1.1.1.6  christos   if (dynamic)
   2828  1.1.1.6  christos     {
   2829  1.1.1.6  christos       if ((tls_type & TLS_GD) != 0)
   2830  1.1.1.6  christos 	*rela_size += 2 * sizeof (Elf32_External_Rela);
   2831  1.1.1.6  christos 
   2832  1.1.1.6  christos       if ((tls_type & TLS_IE) != 0)
   2833  1.1.1.6  christos 	*rela_size += sizeof (Elf32_External_Rela);
   2834  1.1.1.6  christos 
   2835  1.1.1.7  christos       if (!is_tls_entry)
   2836  1.1.1.6  christos 	*rela_size += sizeof (Elf32_External_Rela);
   2837  1.1.1.6  christos     }
   2838  1.1.1.6  christos }
   2839  1.1.1.6  christos 
   2840  1.1.1.6  christos 
   2841      1.1  christos /* Allocate space in .plt, .got and associated reloc sections for
   2842      1.1  christos    dynamic relocs.  */
   2843      1.1  christos 
   2844  1.1.1.7  christos static bool
   2845      1.1  christos allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
   2846      1.1  christos {
   2847      1.1  christos   struct bfd_link_info *info;
   2848      1.1  christos   struct elf_or1k_link_hash_table *htab;
   2849  1.1.1.6  christos   struct elf_dyn_relocs *sec_relocs;
   2850      1.1  christos 
   2851      1.1  christos   if (h->root.type == bfd_link_hash_indirect)
   2852  1.1.1.7  christos     return true;
   2853      1.1  christos 
   2854      1.1  christos   info = (struct bfd_link_info *) inf;
   2855      1.1  christos   htab = or1k_elf_hash_table (info);
   2856      1.1  christos   if (htab == NULL)
   2857  1.1.1.7  christos     return false;
   2858      1.1  christos 
   2859      1.1  christos   if (htab->root.dynamic_sections_created
   2860      1.1  christos       && h->plt.refcount > 0)
   2861      1.1  christos     {
   2862      1.1  christos       /* Make sure this symbol is output as a dynamic symbol.
   2863  1.1.1.5  christos 	 Undefined weak syms won't yet be marked as dynamic.  */
   2864      1.1  christos       if (h->dynindx == -1
   2865  1.1.1.5  christos 	  && !h->forced_local)
   2866  1.1.1.5  christos 	{
   2867  1.1.1.5  christos 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   2868  1.1.1.7  christos 	    return false;
   2869  1.1.1.5  christos 	}
   2870      1.1  christos 
   2871  1.1.1.3  christos       if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
   2872  1.1.1.5  christos 	{
   2873  1.1.1.6  christos 	  asection *splt = htab->root.splt;
   2874  1.1.1.7  christos 	  bfd_vma plt_index;
   2875  1.1.1.7  christos 
   2876  1.1.1.7  christos 	  /* Track the index of our plt entry for use in calculating size.  */
   2877  1.1.1.7  christos 	  plt_index = htab->plt_count++;
   2878  1.1.1.7  christos 	  ((struct elf_or1k_link_hash_entry *) h)->plt_index = plt_index;
   2879      1.1  christos 
   2880  1.1.1.5  christos 	  /* If this is the first .plt entry, make room for the special
   2881  1.1.1.5  christos 	     first entry.  */
   2882  1.1.1.6  christos 	  if (splt->size == 0)
   2883  1.1.1.7  christos 	    splt->size = elf_or1k_plt_entry_size (plt_index);
   2884  1.1.1.5  christos 
   2885  1.1.1.6  christos 	  h->plt.offset = splt->size;
   2886  1.1.1.5  christos 
   2887  1.1.1.5  christos 	  /* If this symbol is not defined in a regular file, and we are
   2888  1.1.1.5  christos 	     not generating a shared library, then set the symbol to this
   2889  1.1.1.5  christos 	     location in the .plt.  This is required to make function
   2890  1.1.1.5  christos 	     pointers compare as equal between the normal executable and
   2891  1.1.1.5  christos 	     the shared library.  */
   2892  1.1.1.5  christos 	  if (! bfd_link_pic (info)
   2893  1.1.1.5  christos 	      && !h->def_regular)
   2894  1.1.1.5  christos 	    {
   2895  1.1.1.6  christos 	      h->root.u.def.section = splt;
   2896  1.1.1.5  christos 	      h->root.u.def.value = h->plt.offset;
   2897  1.1.1.5  christos 	    }
   2898  1.1.1.5  christos 
   2899  1.1.1.5  christos 	  /* Make room for this entry.  */
   2900  1.1.1.7  christos 	  splt->size += elf_or1k_plt_entry_size (plt_index);
   2901  1.1.1.5  christos 
   2902  1.1.1.5  christos 	  /* We also need to make an entry in the .got.plt section, which
   2903  1.1.1.5  christos 	     will be placed in the .got section by the linker script.  */
   2904  1.1.1.5  christos 	  htab->root.sgotplt->size += 4;
   2905  1.1.1.5  christos 
   2906  1.1.1.5  christos 	  /* We also need to make an entry in the .rel.plt section.  */
   2907  1.1.1.5  christos 	  htab->root.srelplt->size += sizeof (Elf32_External_Rela);
   2908  1.1.1.5  christos 	}
   2909      1.1  christos       else
   2910  1.1.1.5  christos 	{
   2911  1.1.1.5  christos 	  h->plt.offset = (bfd_vma) -1;
   2912  1.1.1.5  christos 	  h->needs_plt = 0;
   2913  1.1.1.5  christos 	}
   2914      1.1  christos     }
   2915      1.1  christos   else
   2916      1.1  christos     {
   2917      1.1  christos       h->plt.offset = (bfd_vma) -1;
   2918      1.1  christos       h->needs_plt = 0;
   2919      1.1  christos     }
   2920      1.1  christos 
   2921      1.1  christos   if (h->got.refcount > 0)
   2922      1.1  christos     {
   2923  1.1.1.6  christos       asection *sgot;
   2924  1.1.1.7  christos       bool dyn;
   2925      1.1  christos       unsigned char tls_type;
   2926      1.1  christos 
   2927      1.1  christos       /* Make sure this symbol is output as a dynamic symbol.
   2928  1.1.1.5  christos 	 Undefined weak syms won't yet be marked as dynamic.  */
   2929      1.1  christos       if (h->dynindx == -1
   2930  1.1.1.5  christos 	  && !h->forced_local)
   2931  1.1.1.5  christos 	{
   2932  1.1.1.5  christos 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   2933  1.1.1.7  christos 	    return false;
   2934  1.1.1.5  christos 	}
   2935      1.1  christos 
   2936  1.1.1.6  christos       sgot = htab->root.sgot;
   2937      1.1  christos 
   2938  1.1.1.6  christos       h->got.offset = sgot->size;
   2939      1.1  christos 
   2940      1.1  christos       tls_type = ((struct elf_or1k_link_hash_entry *) h)->tls_type;
   2941      1.1  christos 
   2942      1.1  christos       dyn = htab->root.dynamic_sections_created;
   2943  1.1.1.6  christos       dyn = WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h);
   2944  1.1.1.6  christos       or1k_set_got_and_rela_sizes (tls_type, dyn,
   2945  1.1.1.6  christos 				   &sgot->size, &htab->root.srelgot->size);
   2946      1.1  christos     }
   2947      1.1  christos   else
   2948      1.1  christos     h->got.offset = (bfd_vma) -1;
   2949      1.1  christos 
   2950  1.1.1.6  christos   if (h->dyn_relocs == NULL)
   2951  1.1.1.7  christos     return true;
   2952      1.1  christos 
   2953      1.1  christos   /* In the shared -Bsymbolic case, discard space allocated for
   2954      1.1  christos      dynamic pc-relative relocs against symbols which turn out to be
   2955      1.1  christos      defined in regular objects.  For the normal shared case, discard
   2956      1.1  christos      space for pc-relative relocs that have become local due to symbol
   2957      1.1  christos      visibility changes.  */
   2958      1.1  christos 
   2959  1.1.1.3  christos   if (bfd_link_pic (info))
   2960      1.1  christos     {
   2961      1.1  christos       if (SYMBOL_CALLS_LOCAL (info, h))
   2962  1.1.1.5  christos 	{
   2963  1.1.1.5  christos 	  struct elf_dyn_relocs **pp;
   2964      1.1  christos 
   2965  1.1.1.6  christos 	  for (pp = &h->dyn_relocs; (sec_relocs = *pp) != NULL;)
   2966  1.1.1.5  christos 	    {
   2967  1.1.1.6  christos 	      sec_relocs->count -= sec_relocs->pc_count;
   2968  1.1.1.6  christos 	      sec_relocs->pc_count = 0;
   2969  1.1.1.6  christos 	      if (sec_relocs->count == 0)
   2970  1.1.1.6  christos 		*pp = sec_relocs->next;
   2971  1.1.1.5  christos 	      else
   2972  1.1.1.6  christos 		pp = &sec_relocs->next;
   2973  1.1.1.5  christos 	    }
   2974  1.1.1.5  christos 	}
   2975      1.1  christos 
   2976      1.1  christos       /* Also discard relocs on undefined weak syms with non-default
   2977  1.1.1.5  christos 	 visibility.  */
   2978  1.1.1.6  christos       if (h->dyn_relocs != NULL
   2979  1.1.1.5  christos 	  && h->root.type == bfd_link_hash_undefweak)
   2980  1.1.1.5  christos 	{
   2981  1.1.1.5  christos 	  if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
   2982  1.1.1.6  christos 	    h->dyn_relocs = NULL;
   2983  1.1.1.5  christos 
   2984  1.1.1.5  christos 	  /* Make sure undefined weak symbols are output as a dynamic
   2985  1.1.1.5  christos 	     symbol in PIEs.  */
   2986  1.1.1.5  christos 	  else if (h->dynindx == -1
   2987  1.1.1.5  christos 		   && !h->forced_local)
   2988  1.1.1.5  christos 	    {
   2989  1.1.1.5  christos 	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
   2990  1.1.1.7  christos 		return false;
   2991  1.1.1.5  christos 	    }
   2992  1.1.1.5  christos 	}
   2993      1.1  christos     }
   2994      1.1  christos   else
   2995      1.1  christos     {
   2996      1.1  christos       /* For the non-shared case, discard space for relocs against
   2997  1.1.1.5  christos 	 symbols which turn out to need copy relocs or are not
   2998  1.1.1.5  christos 	 dynamic.  */
   2999      1.1  christos 
   3000      1.1  christos       if (!h->non_got_ref
   3001  1.1.1.5  christos 	  && ((h->def_dynamic
   3002  1.1.1.5  christos 	       && !h->def_regular)
   3003  1.1.1.5  christos 	      || (htab->root.dynamic_sections_created
   3004  1.1.1.5  christos 		  && (h->root.type == bfd_link_hash_undefweak
   3005  1.1.1.5  christos 		      || h->root.type == bfd_link_hash_undefined))))
   3006  1.1.1.5  christos 	{
   3007  1.1.1.5  christos 	  /* Make sure this symbol is output as a dynamic symbol.
   3008  1.1.1.5  christos 	     Undefined weak syms won't yet be marked as dynamic.  */
   3009  1.1.1.5  christos 	  if (h->dynindx == -1
   3010  1.1.1.5  christos 	      && !h->forced_local)
   3011  1.1.1.5  christos 	    {
   3012  1.1.1.5  christos 	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
   3013  1.1.1.7  christos 		return false;
   3014  1.1.1.5  christos 	    }
   3015  1.1.1.5  christos 
   3016  1.1.1.5  christos 	  /* If that succeeded, we know we'll be keeping all the
   3017  1.1.1.5  christos 	     relocs.  */
   3018  1.1.1.5  christos 	  if (h->dynindx != -1)
   3019  1.1.1.5  christos 	    goto keep;
   3020  1.1.1.5  christos 	}
   3021      1.1  christos 
   3022  1.1.1.6  christos       h->dyn_relocs = NULL;
   3023      1.1  christos 
   3024      1.1  christos     keep: ;
   3025      1.1  christos     }
   3026      1.1  christos 
   3027      1.1  christos   /* Finally, allocate space.  */
   3028  1.1.1.6  christos   for (sec_relocs = h->dyn_relocs;
   3029  1.1.1.6  christos        sec_relocs != NULL;
   3030  1.1.1.6  christos        sec_relocs = sec_relocs->next)
   3031      1.1  christos     {
   3032  1.1.1.6  christos       asection *sreloc = elf_section_data (sec_relocs->sec)->sreloc;
   3033  1.1.1.6  christos       sreloc->size += sec_relocs->count * sizeof (Elf32_External_Rela);
   3034      1.1  christos     }
   3035      1.1  christos 
   3036  1.1.1.7  christos   return true;
   3037      1.1  christos }
   3038      1.1  christos 
   3039      1.1  christos /* Set the sizes of the dynamic sections.  */
   3040      1.1  christos 
   3041  1.1.1.7  christos static bool
   3042      1.1  christos or1k_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   3043  1.1.1.5  christos 				struct bfd_link_info *info)
   3044      1.1  christos {
   3045      1.1  christos   struct elf_or1k_link_hash_table *htab;
   3046      1.1  christos   bfd *dynobj;
   3047      1.1  christos   asection *s;
   3048  1.1.1.7  christos   bool relocs;
   3049      1.1  christos   bfd *ibfd;
   3050      1.1  christos 
   3051      1.1  christos   htab = or1k_elf_hash_table (info);
   3052      1.1  christos   if (htab == NULL)
   3053  1.1.1.7  christos     return false;
   3054      1.1  christos 
   3055      1.1  christos   dynobj = htab->root.dynobj;
   3056      1.1  christos   BFD_ASSERT (dynobj != NULL);
   3057      1.1  christos 
   3058      1.1  christos   if (htab->root.dynamic_sections_created)
   3059      1.1  christos     {
   3060      1.1  christos       /* Set the contents of the .interp section to the interpreter.  */
   3061  1.1.1.3  christos       if (bfd_link_executable (info) && !info->nointerp)
   3062  1.1.1.5  christos 	{
   3063  1.1.1.5  christos 	  s = bfd_get_section_by_name (dynobj, ".interp");
   3064  1.1.1.5  christos 	  BFD_ASSERT (s != NULL);
   3065  1.1.1.5  christos 	  s->size = sizeof ELF_DYNAMIC_INTERPRETER;
   3066  1.1.1.5  christos 	  s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
   3067  1.1.1.5  christos 	}
   3068      1.1  christos     }
   3069      1.1  christos 
   3070      1.1  christos   /* Set up .got offsets for local syms, and space for local dynamic
   3071      1.1  christos      relocs.  */
   3072      1.1  christos   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
   3073      1.1  christos     {
   3074      1.1  christos       bfd_signed_vma *local_got;
   3075      1.1  christos       bfd_signed_vma *end_local_got;
   3076      1.1  christos       bfd_size_type locsymcount;
   3077      1.1  christos       Elf_Internal_Shdr *symtab_hdr;
   3078      1.1  christos       unsigned char *local_tls_type;
   3079      1.1  christos       asection *srel;
   3080      1.1  christos 
   3081      1.1  christos       if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
   3082  1.1.1.5  christos 	continue;
   3083      1.1  christos 
   3084      1.1  christos       for (s = ibfd->sections; s != NULL; s = s->next)
   3085  1.1.1.5  christos 	{
   3086  1.1.1.6  christos 	  struct elf_dyn_relocs *sec_relocs;
   3087      1.1  christos 
   3088  1.1.1.6  christos 	  for (sec_relocs = ((struct elf_dyn_relocs *)
   3089  1.1.1.6  christos 			     elf_section_data (s)->local_dynrel);
   3090  1.1.1.6  christos 	       sec_relocs != NULL;
   3091  1.1.1.6  christos 	       sec_relocs = sec_relocs->next)
   3092  1.1.1.5  christos 	    {
   3093  1.1.1.6  christos 	      if (! bfd_is_abs_section (sec_relocs->sec)
   3094  1.1.1.6  christos 		  && bfd_is_abs_section (sec_relocs->sec->output_section))
   3095  1.1.1.5  christos 		{
   3096  1.1.1.5  christos 		  /* Input section has been discarded, either because
   3097  1.1.1.5  christos 		     it is a copy of a linkonce section or due to
   3098  1.1.1.5  christos 		     linker script /DISCARD/, so we'll be discarding
   3099  1.1.1.5  christos 		     the relocs too.  */
   3100  1.1.1.5  christos 		}
   3101  1.1.1.6  christos 	      else if (sec_relocs->count != 0)
   3102  1.1.1.5  christos 		{
   3103  1.1.1.6  christos 		  srel = elf_section_data (sec_relocs->sec)->sreloc;
   3104  1.1.1.6  christos 		  srel->size += sec_relocs->count
   3105  1.1.1.6  christos 				* sizeof (Elf32_External_Rela);
   3106  1.1.1.6  christos 		  if ((sec_relocs->sec->output_section->flags & SEC_READONLY)
   3107  1.1.1.6  christos 		      != 0)
   3108  1.1.1.5  christos 		    info->flags |= DF_TEXTREL;
   3109  1.1.1.5  christos 		}
   3110  1.1.1.5  christos 	    }
   3111  1.1.1.5  christos 	}
   3112      1.1  christos 
   3113      1.1  christos       local_got = elf_local_got_refcounts (ibfd);
   3114      1.1  christos       if (!local_got)
   3115  1.1.1.5  christos 	continue;
   3116      1.1  christos 
   3117      1.1  christos       symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
   3118      1.1  christos       locsymcount = symtab_hdr->sh_info;
   3119      1.1  christos       end_local_got = local_got + locsymcount;
   3120  1.1.1.4  christos       s = htab->root.sgot;
   3121  1.1.1.4  christos       srel = htab->root.srelgot;
   3122      1.1  christos       local_tls_type = (unsigned char *) elf_or1k_local_tls_type (ibfd);
   3123      1.1  christos       for (; local_got < end_local_got; ++local_got)
   3124  1.1.1.5  christos 	{
   3125  1.1.1.5  christos 	  if (*local_got > 0)
   3126  1.1.1.5  christos 	    {
   3127  1.1.1.6  christos 	      unsigned char tls_type = (local_tls_type == NULL)
   3128  1.1.1.6  christos 					? TLS_UNKNOWN
   3129  1.1.1.6  christos 					: *local_tls_type;
   3130  1.1.1.5  christos 
   3131  1.1.1.6  christos 	      *local_got = s->size;
   3132  1.1.1.6  christos 	      or1k_set_got_and_rela_sizes (tls_type, bfd_link_pic (info),
   3133  1.1.1.6  christos 					   &s->size, &srel->size);
   3134  1.1.1.5  christos 	    }
   3135  1.1.1.5  christos 	  else
   3136  1.1.1.5  christos 
   3137  1.1.1.5  christos 	    *local_got = (bfd_vma) -1;
   3138  1.1.1.5  christos 
   3139  1.1.1.5  christos 	  if (local_tls_type)
   3140  1.1.1.5  christos 	    ++local_tls_type;
   3141  1.1.1.5  christos 	}
   3142      1.1  christos     }
   3143      1.1  christos 
   3144      1.1  christos   /* Allocate global sym .plt and .got entries, and space for global
   3145      1.1  christos      sym dynamic relocs.  */
   3146      1.1  christos   elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
   3147      1.1  christos 
   3148      1.1  christos   /* We now have determined the sizes of the various dynamic sections.
   3149      1.1  christos      Allocate memory for them.  */
   3150  1.1.1.7  christos   relocs = false;
   3151      1.1  christos   for (s = dynobj->sections; s != NULL; s = s->next)
   3152      1.1  christos     {
   3153      1.1  christos       if ((s->flags & SEC_LINKER_CREATED) == 0)
   3154  1.1.1.5  christos 	continue;
   3155      1.1  christos 
   3156  1.1.1.4  christos       if (s == htab->root.splt
   3157  1.1.1.5  christos 	  || s == htab->root.sgot
   3158  1.1.1.5  christos 	  || s == htab->root.sgotplt
   3159  1.1.1.4  christos 	  || s == htab->root.sdynbss
   3160  1.1.1.4  christos 	  || s == htab->root.sdynrelro)
   3161  1.1.1.5  christos 	{
   3162  1.1.1.5  christos 	  /* Strip this section if we don't need it; see the
   3163  1.1.1.5  christos 	     comment below.  */
   3164  1.1.1.5  christos 	}
   3165  1.1.1.7  christos       else if (startswith (bfd_section_name (s), ".rela"))
   3166  1.1.1.5  christos 	{
   3167  1.1.1.5  christos 	  if (s->size != 0 && s != htab->root.srelplt)
   3168  1.1.1.7  christos 	    relocs = true;
   3169  1.1.1.5  christos 
   3170  1.1.1.5  christos 	  /* We use the reloc_count field as a counter if we need
   3171  1.1.1.5  christos 	     to copy relocs into the output file.  */
   3172  1.1.1.5  christos 	  s->reloc_count = 0;
   3173  1.1.1.5  christos 	}
   3174      1.1  christos       else
   3175  1.1.1.5  christos 	/* It's not one of our sections, so don't allocate space.  */
   3176  1.1.1.5  christos 	continue;
   3177      1.1  christos 
   3178      1.1  christos       if (s->size == 0)
   3179  1.1.1.5  christos 	{
   3180  1.1.1.5  christos 	  /* If we don't need this section, strip it from the
   3181  1.1.1.5  christos 	     output file.  This is mostly to handle .rela.bss and
   3182  1.1.1.5  christos 	     .rela.plt.  We must create both sections in
   3183  1.1.1.5  christos 	     create_dynamic_sections, because they must be created
   3184  1.1.1.5  christos 	     before the linker maps input sections to output
   3185  1.1.1.5  christos 	     sections.  The linker does that before
   3186  1.1.1.5  christos 	     adjust_dynamic_symbol is called, and it is that
   3187  1.1.1.5  christos 	     function which decides whether anything needs to go
   3188  1.1.1.5  christos 	     into these sections.  */
   3189  1.1.1.5  christos 	  s->flags |= SEC_EXCLUDE;
   3190  1.1.1.5  christos 	  continue;
   3191  1.1.1.5  christos 	}
   3192      1.1  christos 
   3193      1.1  christos       if ((s->flags & SEC_HAS_CONTENTS) == 0)
   3194  1.1.1.5  christos 	continue;
   3195      1.1  christos 
   3196      1.1  christos       /* Allocate memory for the section contents.  We use bfd_zalloc
   3197  1.1.1.5  christos 	 here in case unused entries are not reclaimed before the
   3198  1.1.1.5  christos 	 section's contents are written out.  This should not happen,
   3199  1.1.1.5  christos 	 but this way if it does, we get a R_OR1K_NONE reloc instead
   3200  1.1.1.5  christos 	 of garbage.  */
   3201      1.1  christos       s->contents = bfd_zalloc (dynobj, s->size);
   3202      1.1  christos 
   3203      1.1  christos       if (s->contents == NULL)
   3204  1.1.1.7  christos 	return false;
   3205      1.1  christos     }
   3206      1.1  christos 
   3207  1.1.1.6  christos   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
   3208      1.1  christos }
   3209      1.1  christos 
   3210      1.1  christos /* Copy the extra info we tack onto an elf_link_hash_entry.  */
   3211      1.1  christos 
   3212      1.1  christos static void
   3213      1.1  christos or1k_elf_copy_indirect_symbol (struct bfd_link_info *info,
   3214  1.1.1.5  christos 			       struct elf_link_hash_entry *dir,
   3215  1.1.1.5  christos 			       struct elf_link_hash_entry *ind)
   3216      1.1  christos {
   3217      1.1  christos   struct elf_or1k_link_hash_entry * edir;
   3218      1.1  christos   struct elf_or1k_link_hash_entry * eind;
   3219      1.1  christos 
   3220      1.1  christos   edir = (struct elf_or1k_link_hash_entry *) dir;
   3221      1.1  christos   eind = (struct elf_or1k_link_hash_entry *) ind;
   3222      1.1  christos 
   3223      1.1  christos   if (ind->root.type == bfd_link_hash_indirect)
   3224      1.1  christos     {
   3225      1.1  christos       if (dir->got.refcount <= 0)
   3226  1.1.1.5  christos 	{
   3227  1.1.1.5  christos 	  edir->tls_type = eind->tls_type;
   3228  1.1.1.5  christos 	  eind->tls_type = TLS_UNKNOWN;
   3229  1.1.1.5  christos 	}
   3230      1.1  christos     }
   3231      1.1  christos 
   3232      1.1  christos   _bfd_elf_link_hash_copy_indirect (info, dir, ind);
   3233      1.1  christos }
   3234      1.1  christos 
   3235      1.1  christos /* Set the right machine number.  */
   3236      1.1  christos 
   3237  1.1.1.7  christos static bool
   3238      1.1  christos or1k_elf_object_p (bfd *abfd)
   3239      1.1  christos {
   3240      1.1  christos   unsigned long mach = bfd_mach_or1k;
   3241      1.1  christos 
   3242      1.1  christos   if (elf_elfheader (abfd)->e_flags & EF_OR1K_NODELAY)
   3243      1.1  christos     mach = bfd_mach_or1knd;
   3244      1.1  christos 
   3245      1.1  christos   return bfd_default_set_arch_mach (abfd, bfd_arch_or1k, mach);
   3246      1.1  christos }
   3247      1.1  christos 
   3248      1.1  christos /* Store the machine number in the flags field.  */
   3249      1.1  christos 
   3250  1.1.1.7  christos static bool
   3251  1.1.1.6  christos or1k_elf_final_write_processing (bfd *abfd)
   3252      1.1  christos {
   3253      1.1  christos   switch (bfd_get_mach (abfd))
   3254      1.1  christos     {
   3255      1.1  christos     default:
   3256      1.1  christos     case bfd_mach_or1k:
   3257      1.1  christos       break;
   3258      1.1  christos     case bfd_mach_or1knd:
   3259      1.1  christos       elf_elfheader (abfd)->e_flags |= EF_OR1K_NODELAY;
   3260      1.1  christos       break;
   3261      1.1  christos     }
   3262  1.1.1.6  christos   return _bfd_elf_final_write_processing (abfd);
   3263      1.1  christos }
   3264      1.1  christos 
   3265  1.1.1.7  christos static bool
   3266      1.1  christos or1k_elf_set_private_flags (bfd *abfd, flagword flags)
   3267      1.1  christos {
   3268      1.1  christos   BFD_ASSERT (!elf_flags_init (abfd)
   3269  1.1.1.5  christos 	      || elf_elfheader (abfd)->e_flags == flags);
   3270      1.1  christos 
   3271      1.1  christos   elf_elfheader (abfd)->e_flags = flags;
   3272  1.1.1.7  christos   elf_flags_init (abfd) = true;
   3273  1.1.1.7  christos   return true;
   3274      1.1  christos }
   3275      1.1  christos 
   3276      1.1  christos /* Make sure all input files are consistent with respect to
   3277      1.1  christos    EF_OR1K_NODELAY flag setting.  */
   3278      1.1  christos 
   3279  1.1.1.7  christos static bool
   3280  1.1.1.4  christos elf32_or1k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   3281      1.1  christos {
   3282  1.1.1.4  christos   bfd *obfd = info->output_bfd;
   3283      1.1  christos   flagword out_flags;
   3284      1.1  christos   flagword in_flags;
   3285      1.1  christos 
   3286      1.1  christos   in_flags  = elf_elfheader (ibfd)->e_flags;
   3287      1.1  christos   out_flags = elf_elfheader (obfd)->e_flags;
   3288      1.1  christos 
   3289      1.1  christos   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
   3290      1.1  christos       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
   3291  1.1.1.7  christos     return true;
   3292      1.1  christos 
   3293      1.1  christos   if (!elf_flags_init (obfd))
   3294      1.1  christos     {
   3295  1.1.1.7  christos       elf_flags_init (obfd) = true;
   3296      1.1  christos       elf_elfheader (obfd)->e_flags = in_flags;
   3297      1.1  christos 
   3298  1.1.1.7  christos       return true;
   3299      1.1  christos     }
   3300      1.1  christos 
   3301      1.1  christos   if (in_flags == out_flags)
   3302  1.1.1.7  christos     return true;
   3303      1.1  christos 
   3304      1.1  christos   if ((in_flags & EF_OR1K_NODELAY) != (out_flags & EF_OR1K_NODELAY))
   3305      1.1  christos     {
   3306  1.1.1.4  christos       _bfd_error_handler
   3307  1.1.1.5  christos 	(_("%pB: %s flag mismatch with previous modules"),
   3308  1.1.1.5  christos 	 ibfd, "EF_OR1K_NODELAY");
   3309      1.1  christos 
   3310      1.1  christos       bfd_set_error (bfd_error_bad_value);
   3311  1.1.1.7  christos       return false;
   3312      1.1  christos     }
   3313      1.1  christos 
   3314  1.1.1.7  christos   return true;
   3315      1.1  christos 
   3316      1.1  christos }
   3317      1.1  christos 
   3318  1.1.1.5  christos /* Implement elf_backend_grok_prstatus:
   3319  1.1.1.5  christos    Support for core dump NOTE sections.  */
   3320  1.1.1.7  christos static bool
   3321  1.1.1.5  christos or1k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
   3322  1.1.1.5  christos {
   3323  1.1.1.5  christos   int offset;
   3324  1.1.1.5  christos   size_t size;
   3325  1.1.1.5  christos 
   3326  1.1.1.5  christos   switch (note->descsz)
   3327  1.1.1.5  christos     {
   3328  1.1.1.5  christos     default:
   3329  1.1.1.7  christos       return false;
   3330  1.1.1.5  christos 
   3331  1.1.1.5  christos     case 212:	      /* Linux/OpenRISC */
   3332  1.1.1.5  christos       /* pr_cursig */
   3333  1.1.1.5  christos       elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
   3334  1.1.1.5  christos 
   3335  1.1.1.5  christos       /* pr_pid */
   3336  1.1.1.5  christos       elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
   3337  1.1.1.5  christos 
   3338  1.1.1.5  christos       /* pr_reg */
   3339  1.1.1.5  christos       offset = 72;
   3340  1.1.1.5  christos       size = 132;
   3341  1.1.1.5  christos 
   3342  1.1.1.5  christos       break;
   3343  1.1.1.5  christos     }
   3344  1.1.1.5  christos 
   3345  1.1.1.5  christos   /* Make a ".reg/999" section.  */
   3346  1.1.1.5  christos   return _bfd_elfcore_make_pseudosection (abfd, ".reg",
   3347  1.1.1.5  christos 					  size, note->descpos + offset);
   3348  1.1.1.5  christos }
   3349  1.1.1.5  christos 
   3350  1.1.1.5  christos /* Implement elf_backend_grok_psinfo.  */
   3351  1.1.1.7  christos static bool
   3352  1.1.1.5  christos or1k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
   3353  1.1.1.5  christos {
   3354  1.1.1.5  christos   switch (note->descsz)
   3355  1.1.1.5  christos     {
   3356  1.1.1.5  christos     default:
   3357  1.1.1.7  christos       return false;
   3358  1.1.1.5  christos 
   3359  1.1.1.5  christos     case 128:	      /* Linux/OpenRISC elf_prpsinfo */
   3360  1.1.1.5  christos       elf_tdata (abfd)->core->program
   3361  1.1.1.5  christos 	= _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
   3362  1.1.1.5  christos       elf_tdata (abfd)->core->command
   3363  1.1.1.5  christos 	= _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
   3364  1.1.1.5  christos     }
   3365  1.1.1.5  christos 
   3366  1.1.1.7  christos   return true;
   3367  1.1.1.5  christos }
   3368  1.1.1.5  christos 
   3369      1.1  christos 
   3370  1.1.1.5  christos #define ELF_ARCH			bfd_arch_or1k
   3371  1.1.1.5  christos #define ELF_MACHINE_CODE		EM_OR1K
   3372  1.1.1.5  christos #define ELF_TARGET_ID			OR1K_ELF_DATA
   3373  1.1.1.5  christos #define ELF_MAXPAGESIZE			0x2000
   3374  1.1.1.5  christos 
   3375  1.1.1.5  christos #define TARGET_BIG_SYM			or1k_elf32_vec
   3376  1.1.1.5  christos #define TARGET_BIG_NAME			"elf32-or1k"
   3377  1.1.1.5  christos 
   3378  1.1.1.5  christos #define elf_info_to_howto_rel		NULL
   3379  1.1.1.5  christos #define elf_info_to_howto		or1k_info_to_howto_rela
   3380  1.1.1.5  christos #define elf_backend_relocate_section	or1k_elf_relocate_section
   3381  1.1.1.5  christos #define elf_backend_gc_mark_hook	or1k_elf_gc_mark_hook
   3382  1.1.1.5  christos #define elf_backend_check_relocs	or1k_elf_check_relocs
   3383  1.1.1.5  christos #define elf_backend_reloc_type_class	or1k_elf_reloc_type_class
   3384  1.1.1.5  christos #define elf_backend_can_gc_sections	1
   3385  1.1.1.5  christos #define elf_backend_rela_normal		1
   3386  1.1.1.5  christos 
   3387  1.1.1.5  christos #define bfd_elf32_mkobject		     elf_or1k_mkobject
   3388      1.1  christos 
   3389      1.1  christos #define bfd_elf32_bfd_merge_private_bfd_data elf32_or1k_merge_private_bfd_data
   3390      1.1  christos #define bfd_elf32_bfd_set_private_flags or1k_elf_set_private_flags
   3391      1.1  christos #define bfd_elf32_bfd_reloc_type_lookup or1k_reloc_type_lookup
   3392      1.1  christos #define bfd_elf32_bfd_reloc_name_lookup or1k_reloc_name_lookup
   3393      1.1  christos 
   3394  1.1.1.5  christos #define elf_backend_object_p		    or1k_elf_object_p
   3395      1.1  christos #define elf_backend_final_write_processing  or1k_elf_final_write_processing
   3396  1.1.1.5  christos #define elf_backend_can_refcount		1
   3397      1.1  christos 
   3398  1.1.1.5  christos #define elf_backend_plt_readonly		1
   3399  1.1.1.5  christos #define elf_backend_want_got_plt		1
   3400  1.1.1.5  christos #define elf_backend_want_plt_sym		0
   3401  1.1.1.5  christos #define elf_backend_got_header_size		12
   3402  1.1.1.4  christos #define elf_backend_dtrel_excludes_plt		1
   3403  1.1.1.4  christos #define elf_backend_want_dynrelro		1
   3404  1.1.1.4  christos 
   3405  1.1.1.5  christos #define bfd_elf32_bfd_link_hash_table_create	or1k_elf_link_hash_table_create
   3406  1.1.1.5  christos #define elf_backend_copy_indirect_symbol	or1k_elf_copy_indirect_symbol
   3407  1.1.1.5  christos #define elf_backend_create_dynamic_sections	_bfd_elf_create_dynamic_sections
   3408  1.1.1.5  christos #define elf_backend_finish_dynamic_sections	or1k_elf_finish_dynamic_sections
   3409  1.1.1.5  christos #define elf_backend_size_dynamic_sections	or1k_elf_size_dynamic_sections
   3410  1.1.1.5  christos #define elf_backend_adjust_dynamic_symbol	or1k_elf_adjust_dynamic_symbol
   3411  1.1.1.5  christos #define elf_backend_finish_dynamic_symbol	or1k_elf_finish_dynamic_symbol
   3412  1.1.1.5  christos 
   3413  1.1.1.5  christos #define elf_backend_grok_prstatus	  or1k_grok_prstatus
   3414  1.1.1.5  christos #define elf_backend_grok_psinfo		  or1k_grok_psinfo
   3415      1.1  christos 
   3416      1.1  christos #include "elf32-target.h"
   3417