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