Home | History | Annotate | Line # | Download | only in bfd
elf32-frv.c revision 1.1.1.2
      1      1.1     skrll /* FRV-specific support for 32-bit ELF.
      2  1.1.1.2  christos    Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
      3      1.1     skrll    Free Software Foundation, Inc.
      4      1.1     skrll 
      5      1.1     skrll    This file is part of BFD, the Binary File Descriptor library.
      6      1.1     skrll 
      7      1.1     skrll    This program is free software; you can redistribute it and/or modify
      8      1.1     skrll    it under the terms of the GNU General Public License as published by
      9      1.1     skrll    the Free Software Foundation; either version 3 of the License, or
     10      1.1     skrll    (at your option) any later version.
     11      1.1     skrll 
     12      1.1     skrll    This program is distributed in the hope that it will be useful,
     13      1.1     skrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14      1.1     skrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15      1.1     skrll    GNU General Public License for more details.
     16      1.1     skrll 
     17      1.1     skrll    You should have received a copy of the GNU General Public License
     18      1.1     skrll    along with this program; if not, write to the Free Software
     19      1.1     skrll    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     20      1.1     skrll    MA 02110-1301, USA.  */
     21      1.1     skrll 
     22      1.1     skrll #include "sysdep.h"
     23      1.1     skrll #include "bfd.h"
     24      1.1     skrll #include "libbfd.h"
     25      1.1     skrll #include "elf-bfd.h"
     26      1.1     skrll #include "elf/frv.h"
     27  1.1.1.2  christos #include "dwarf2.h"
     28      1.1     skrll #include "hashtab.h"
     29      1.1     skrll 
     30      1.1     skrll /* Forward declarations.  */
     31      1.1     skrll static bfd_reloc_status_type elf32_frv_relocate_lo16
     32      1.1     skrll   PARAMS ((bfd *,  Elf_Internal_Rela *, bfd_byte *, bfd_vma));
     33      1.1     skrll static bfd_reloc_status_type elf32_frv_relocate_hi16
     34      1.1     skrll   PARAMS ((bfd *,  Elf_Internal_Rela *, bfd_byte *, bfd_vma));
     35      1.1     skrll static bfd_reloc_status_type elf32_frv_relocate_label24
     36      1.1     skrll   PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_vma));
     37      1.1     skrll static bfd_reloc_status_type elf32_frv_relocate_gprel12
     38      1.1     skrll   PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
     39      1.1     skrll 	   bfd_byte *, bfd_vma));
     40      1.1     skrll static bfd_reloc_status_type elf32_frv_relocate_gprelu12
     41      1.1     skrll   PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
     42      1.1     skrll 	   bfd_byte *, bfd_vma));
     43      1.1     skrll static bfd_reloc_status_type elf32_frv_relocate_gprello
     44      1.1     skrll   PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
     45      1.1     skrll 	   bfd_byte *, bfd_vma));
     46      1.1     skrll static bfd_reloc_status_type elf32_frv_relocate_gprelhi
     47      1.1     skrll   PARAMS ((struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *,
     48      1.1     skrll 	   bfd_byte *, bfd_vma));
     49      1.1     skrll static reloc_howto_type *frv_reloc_type_lookup
     50      1.1     skrll   PARAMS ((bfd *, bfd_reloc_code_real_type));
     51      1.1     skrll static void frv_info_to_howto_rela
     52      1.1     skrll   PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
     53      1.1     skrll static bfd_boolean elf32_frv_relocate_section
     54      1.1     skrll   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
     55      1.1     skrll 	   Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
     56      1.1     skrll static bfd_boolean elf32_frv_add_symbol_hook
     57      1.1     skrll   PARAMS (( bfd *, struct bfd_link_info *, Elf_Internal_Sym *,
     58      1.1     skrll 	    const char **, flagword *, asection **, bfd_vma *));
     59      1.1     skrll static bfd_reloc_status_type frv_final_link_relocate
     60      1.1     skrll   PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
     61      1.1     skrll 	   Elf_Internal_Rela *, bfd_vma));
     62      1.1     skrll static bfd_boolean elf32_frv_check_relocs
     63      1.1     skrll   PARAMS ((bfd *, struct bfd_link_info *, asection *,
     64      1.1     skrll 	   const Elf_Internal_Rela *));
     65      1.1     skrll static int elf32_frv_machine
     66      1.1     skrll   PARAMS ((bfd *));
     67      1.1     skrll static bfd_boolean elf32_frv_object_p
     68      1.1     skrll   PARAMS ((bfd *));
     69      1.1     skrll static bfd_boolean frv_elf_set_private_flags
     70      1.1     skrll   PARAMS ((bfd *, flagword));
     71      1.1     skrll static bfd_boolean frv_elf_copy_private_bfd_data
     72      1.1     skrll   PARAMS ((bfd *, bfd *));
     73      1.1     skrll static bfd_boolean frv_elf_merge_private_bfd_data
     74      1.1     skrll   PARAMS ((bfd *, bfd *));
     75      1.1     skrll static bfd_boolean frv_elf_print_private_bfd_data
     76      1.1     skrll   PARAMS ((bfd *, PTR));
     77      1.1     skrll static bfd_boolean elf32_frv_grok_prstatus (bfd * abfd,
     78      1.1     skrll 					    Elf_Internal_Note * note);
     79      1.1     skrll static bfd_boolean elf32_frv_grok_psinfo (bfd * abfd,
     80      1.1     skrll 					  Elf_Internal_Note * note);
     81      1.1     skrll 
     82      1.1     skrll static reloc_howto_type elf32_frv_howto_table [] =
     83      1.1     skrll {
     84      1.1     skrll   /* This reloc does nothing.  */
     85      1.1     skrll   HOWTO (R_FRV_NONE,		/* type */
     86      1.1     skrll 	 0,			/* rightshift */
     87      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
     88      1.1     skrll 	 32,			/* bitsize */
     89      1.1     skrll 	 FALSE,			/* pc_relative */
     90      1.1     skrll 	 0,			/* bitpos */
     91      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
     92      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
     93      1.1     skrll 	 "R_FRV_NONE",		/* name */
     94      1.1     skrll 	 FALSE,			/* partial_inplace */
     95      1.1     skrll 	 0,			/* src_mask */
     96      1.1     skrll 	 0,			/* dst_mask */
     97      1.1     skrll 	 FALSE),		/* pcrel_offset */
     98      1.1     skrll 
     99      1.1     skrll   /* A 32 bit absolute relocation.  */
    100      1.1     skrll   HOWTO (R_FRV_32,		/* type */
    101      1.1     skrll 	 0,			/* rightshift */
    102      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    103      1.1     skrll 	 32,			/* bitsize */
    104      1.1     skrll 	 FALSE,			/* pc_relative */
    105      1.1     skrll 	 0,			/* bitpos */
    106      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    107      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    108      1.1     skrll 	 "R_FRV_32",		/* name */
    109      1.1     skrll 	 FALSE,			/* partial_inplace */
    110      1.1     skrll 	 0xffffffff,		/* src_mask */
    111      1.1     skrll 	 0xffffffff,		/* dst_mask */
    112      1.1     skrll 	 FALSE),		/* pcrel_offset */
    113      1.1     skrll 
    114      1.1     skrll   /* A 16 bit pc-relative relocation.  */
    115      1.1     skrll   HOWTO (R_FRV_LABEL16,		/* type */
    116      1.1     skrll 	 2,			/* rightshift */
    117      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    118      1.1     skrll 	 16,			/* bitsize */
    119      1.1     skrll 	 TRUE,			/* pc_relative */
    120      1.1     skrll 	 0,			/* bitpos */
    121      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    122      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    123      1.1     skrll 	 "R_FRV_LABEL16",	/* name */
    124      1.1     skrll 	 FALSE,			/* partial_inplace */
    125      1.1     skrll 	 0xffff,		/* src_mask */
    126      1.1     skrll 	 0xffff,		/* dst_mask */
    127      1.1     skrll 	 TRUE),			/* pcrel_offset */
    128      1.1     skrll 
    129      1.1     skrll   /* A 24-bit pc-relative relocation.  */
    130      1.1     skrll   HOWTO (R_FRV_LABEL24,		/* type */
    131      1.1     skrll 	 2,			/* rightshift */
    132      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    133      1.1     skrll 	 26,			/* bitsize */
    134      1.1     skrll 	 TRUE,			/* pc_relative */
    135      1.1     skrll 	 0,			/* bitpos */
    136      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    137      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    138      1.1     skrll 	 "R_FRV_LABEL24",	/* name */
    139      1.1     skrll 	 FALSE,			/* partial_inplace */
    140      1.1     skrll 	 0x7e03ffff,		/* src_mask */
    141      1.1     skrll 	 0x7e03ffff,		/* dst_mask */
    142      1.1     skrll 	 TRUE),			/* pcrel_offset */
    143      1.1     skrll 
    144      1.1     skrll   HOWTO (R_FRV_LO16,		/* type */
    145      1.1     skrll 	 0,			/* rightshift */
    146      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    147      1.1     skrll 	 16,			/* bitsize */
    148      1.1     skrll 	 FALSE,			/* pc_relative */
    149      1.1     skrll 	 0,			/* bitpos */
    150      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    151      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    152      1.1     skrll 	 "R_FRV_LO16",		/* name */
    153      1.1     skrll 	 FALSE,			/* partial_inplace */
    154      1.1     skrll 	 0xffff,		/* src_mask */
    155      1.1     skrll 	 0xffff,		/* dst_mask */
    156      1.1     skrll 	 FALSE),		/* pcrel_offset */
    157      1.1     skrll 
    158      1.1     skrll   HOWTO (R_FRV_HI16,		/* type */
    159      1.1     skrll 	 0,			/* rightshift */
    160      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    161      1.1     skrll 	 16,			/* bitsize */
    162      1.1     skrll 	 FALSE,			/* pc_relative */
    163      1.1     skrll 	 0,			/* bitpos */
    164      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    165      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    166      1.1     skrll 	 "R_FRV_HI16",		/* name */
    167      1.1     skrll 	 FALSE,			/* partial_inplace */
    168      1.1     skrll 	 0xffff,		/* src_mask */
    169      1.1     skrll 	 0xffff,		/* dst_mask */
    170      1.1     skrll 	 FALSE),		/* pcrel_offset */
    171      1.1     skrll 
    172      1.1     skrll   HOWTO (R_FRV_GPREL12,		/* type */
    173      1.1     skrll 	 0,			/* rightshift */
    174      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    175      1.1     skrll 	 12,			/* bitsize */
    176      1.1     skrll 	 FALSE,			/* pc_relative */
    177      1.1     skrll 	 0,			/* bitpos */
    178      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    179      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    180      1.1     skrll 	 "R_FRV_GPREL12",	/* name */
    181      1.1     skrll 	 FALSE,			/* partial_inplace */
    182      1.1     skrll 	 0xfff,			/* src_mask */
    183      1.1     skrll 	 0xfff,			/* dst_mask */
    184      1.1     skrll 	 FALSE),		/* pcrel_offset */
    185      1.1     skrll 
    186      1.1     skrll   HOWTO (R_FRV_GPRELU12,	/* type */
    187      1.1     skrll 	 0,			/* rightshift */
    188      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    189      1.1     skrll 	 12,			/* bitsize */
    190      1.1     skrll 	 FALSE,			/* pc_relative */
    191      1.1     skrll 	 0,			/* bitpos */
    192      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    193      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    194      1.1     skrll 	 "R_FRV_GPRELU12",	/* name */
    195      1.1     skrll 	 FALSE,			/* partial_inplace */
    196      1.1     skrll 	 0xfff,			/* src_mask */
    197      1.1     skrll 	 0x3f03f,		/* dst_mask */
    198      1.1     skrll 	 FALSE),		/* pcrel_offset */
    199      1.1     skrll 
    200      1.1     skrll   HOWTO (R_FRV_GPREL32,		/* type */
    201      1.1     skrll 	 0,			/* rightshift */
    202      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    203      1.1     skrll 	 32,			/* bitsize */
    204      1.1     skrll 	 FALSE,			/* pc_relative */
    205      1.1     skrll 	 0,			/* bitpos */
    206      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    207      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    208      1.1     skrll 	 "R_FRV_GPREL32",	/* name */
    209      1.1     skrll 	 FALSE,			/* partial_inplace */
    210      1.1     skrll 	 0xffffffff,		/* src_mask */
    211      1.1     skrll 	 0xffffffff,		/* dst_mask */
    212      1.1     skrll 	 FALSE),		/* pcrel_offset */
    213      1.1     skrll 
    214      1.1     skrll   HOWTO (R_FRV_GPRELHI,		/* type */
    215      1.1     skrll 	 0,			/* rightshift */
    216      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    217      1.1     skrll 	 16,			/* bitsize */
    218      1.1     skrll 	 FALSE,			/* pc_relative */
    219      1.1     skrll 	 0,			/* bitpos */
    220      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    221      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    222      1.1     skrll 	 "R_FRV_GPRELHI",	/* name */
    223      1.1     skrll 	 FALSE,			/* partial_inplace */
    224      1.1     skrll 	 0xffff,		/* src_mask */
    225      1.1     skrll 	 0xffff,		/* dst_mask */
    226      1.1     skrll 	 FALSE),		/* pcrel_offset */
    227      1.1     skrll 
    228      1.1     skrll   HOWTO (R_FRV_GPRELLO,		/* type */
    229      1.1     skrll 	 0,			/* rightshift */
    230      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    231      1.1     skrll 	 16,			/* bitsize */
    232      1.1     skrll 	 FALSE,			/* pc_relative */
    233      1.1     skrll 	 0,			/* bitpos */
    234      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    235      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    236      1.1     skrll 	 "R_FRV_GPRELLO",	/* name */
    237      1.1     skrll 	 FALSE,			/* partial_inplace */
    238      1.1     skrll 	 0xffff,		/* src_mask */
    239      1.1     skrll 	 0xffff,		/* dst_mask */
    240      1.1     skrll 	 FALSE),		/* pcrel_offset */
    241      1.1     skrll 
    242      1.1     skrll   /* A 12-bit signed operand with the GOT offset for the address of
    243      1.1     skrll      the symbol.  */
    244      1.1     skrll   HOWTO (R_FRV_GOT12,		/* type */
    245      1.1     skrll 	 0,			/* rightshift */
    246      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    247      1.1     skrll 	 12,			/* bitsize */
    248      1.1     skrll 	 FALSE,			/* pc_relative */
    249      1.1     skrll 	 0,			/* bitpos */
    250      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    251      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    252      1.1     skrll 	 "R_FRV_GOT12",		/* name */
    253      1.1     skrll 	 FALSE,			/* partial_inplace */
    254      1.1     skrll 	 0xfff,			/* src_mask */
    255      1.1     skrll 	 0xfff,			/* dst_mask */
    256      1.1     skrll 	 FALSE),		/* pcrel_offset */
    257      1.1     skrll 
    258      1.1     skrll   /* The upper 16 bits of the GOT offset for the address of the
    259      1.1     skrll      symbol.  */
    260      1.1     skrll   HOWTO (R_FRV_GOTHI,		/* type */
    261      1.1     skrll 	 0,			/* rightshift */
    262      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    263      1.1     skrll 	 16,			/* bitsize */
    264      1.1     skrll 	 FALSE,			/* pc_relative */
    265      1.1     skrll 	 0,			/* bitpos */
    266      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    267      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    268      1.1     skrll 	 "R_FRV_GOTHI",		/* name */
    269      1.1     skrll 	 FALSE,			/* partial_inplace */
    270      1.1     skrll 	 0xffff,		/* src_mask */
    271      1.1     skrll 	 0xffff,		/* dst_mask */
    272      1.1     skrll 	 FALSE),		/* pcrel_offset */
    273      1.1     skrll 
    274      1.1     skrll   /* The lower 16 bits of the GOT offset for the address of the
    275      1.1     skrll      symbol.  */
    276      1.1     skrll   HOWTO (R_FRV_GOTLO,		/* type */
    277      1.1     skrll 	 0,			/* rightshift */
    278      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    279      1.1     skrll 	 16,			/* bitsize */
    280      1.1     skrll 	 FALSE,			/* pc_relative */
    281      1.1     skrll 	 0,			/* bitpos */
    282      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    283      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    284      1.1     skrll 	 "R_FRV_GOTLO",		/* name */
    285      1.1     skrll 	 FALSE,			/* partial_inplace */
    286      1.1     skrll 	 0xffff,		/* src_mask */
    287      1.1     skrll 	 0xffff,		/* dst_mask */
    288      1.1     skrll 	 FALSE),		/* pcrel_offset */
    289      1.1     skrll 
    290      1.1     skrll   /* The 32-bit address of the canonical descriptor of a function.  */
    291      1.1     skrll   HOWTO (R_FRV_FUNCDESC,	/* type */
    292      1.1     skrll 	 0,			/* rightshift */
    293      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    294      1.1     skrll 	 32,			/* bitsize */
    295      1.1     skrll 	 FALSE,			/* pc_relative */
    296      1.1     skrll 	 0,			/* bitpos */
    297      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    298      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    299      1.1     skrll 	 "R_FRV_FUNCDESC",	/* name */
    300      1.1     skrll 	 FALSE,			/* partial_inplace */
    301      1.1     skrll 	 0xffffffff,		/* src_mask */
    302      1.1     skrll 	 0xffffffff,		/* dst_mask */
    303      1.1     skrll 	 FALSE),		/* pcrel_offset */
    304      1.1     skrll 
    305      1.1     skrll   /* A 12-bit signed operand with the GOT offset for the address of
    306      1.1     skrll      canonical descriptor of a function.  */
    307      1.1     skrll   HOWTO (R_FRV_FUNCDESC_GOT12,	/* type */
    308      1.1     skrll 	 0,			/* rightshift */
    309      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    310      1.1     skrll 	 12,			/* bitsize */
    311      1.1     skrll 	 FALSE,			/* pc_relative */
    312      1.1     skrll 	 0,			/* bitpos */
    313      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    314      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    315      1.1     skrll 	 "R_FRV_FUNCDESC_GOT12", /* name */
    316      1.1     skrll 	 FALSE,			/* partial_inplace */
    317      1.1     skrll 	 0xfff,			/* src_mask */
    318      1.1     skrll 	 0xfff,			/* dst_mask */
    319      1.1     skrll 	 FALSE),		/* pcrel_offset */
    320      1.1     skrll 
    321      1.1     skrll   /* The upper 16 bits of the GOT offset for the address of the
    322      1.1     skrll      canonical descriptor of a function.  */
    323      1.1     skrll   HOWTO (R_FRV_FUNCDESC_GOTHI,	/* type */
    324      1.1     skrll 	 0,			/* rightshift */
    325      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    326      1.1     skrll 	 16,			/* bitsize */
    327      1.1     skrll 	 FALSE,			/* pc_relative */
    328      1.1     skrll 	 0,			/* bitpos */
    329      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    330      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    331      1.1     skrll 	 "R_FRV_FUNCDESC_GOTHI", /* name */
    332      1.1     skrll 	 FALSE,			/* partial_inplace */
    333      1.1     skrll 	 0xffff,		/* src_mask */
    334      1.1     skrll 	 0xffff,		/* dst_mask */
    335      1.1     skrll 	 FALSE),		/* pcrel_offset */
    336      1.1     skrll 
    337      1.1     skrll   /* The lower 16 bits of the GOT offset for the address of the
    338      1.1     skrll      canonical descriptor of a function.  */
    339      1.1     skrll   HOWTO (R_FRV_FUNCDESC_GOTLO,	/* type */
    340      1.1     skrll 	 0,			/* rightshift */
    341      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    342      1.1     skrll 	 16,			/* bitsize */
    343      1.1     skrll 	 FALSE,			/* pc_relative */
    344      1.1     skrll 	 0,			/* bitpos */
    345      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    346      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    347      1.1     skrll 	 "R_FRV_FUNCDESC_GOTLO", /* name */
    348      1.1     skrll 	 FALSE,			/* partial_inplace */
    349      1.1     skrll 	 0xffff,		/* src_mask */
    350      1.1     skrll 	 0xffff,		/* dst_mask */
    351      1.1     skrll 	 FALSE),		/* pcrel_offset */
    352      1.1     skrll 
    353      1.1     skrll   /* The 64-bit descriptor of a function.  */
    354      1.1     skrll   HOWTO (R_FRV_FUNCDESC_VALUE,	/* type */
    355      1.1     skrll 	 0,			/* rightshift */
    356      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    357      1.1     skrll 	 64,			/* bitsize */
    358      1.1     skrll 	 FALSE,			/* pc_relative */
    359      1.1     skrll 	 0,			/* bitpos */
    360      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    361      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    362      1.1     skrll 	 "R_FRV_FUNCDESC_VALUE", /* name */
    363      1.1     skrll 	 FALSE,			/* partial_inplace */
    364      1.1     skrll 	 0xffffffff,		/* src_mask */
    365      1.1     skrll 	 0xffffffff,		/* dst_mask */
    366      1.1     skrll 	 FALSE),		/* pcrel_offset */
    367      1.1     skrll 
    368      1.1     skrll   /* A 12-bit signed operand with the GOT offset for the address of
    369      1.1     skrll      canonical descriptor of a function.  */
    370      1.1     skrll   HOWTO (R_FRV_FUNCDESC_GOTOFF12, /* type */
    371      1.1     skrll 	 0,			/* rightshift */
    372      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    373      1.1     skrll 	 12,			/* bitsize */
    374      1.1     skrll 	 FALSE,			/* pc_relative */
    375      1.1     skrll 	 0,			/* bitpos */
    376      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    377      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    378      1.1     skrll 	 "R_FRV_FUNCDESC_GOTOFF12", /* name */
    379      1.1     skrll 	 FALSE,			/* partial_inplace */
    380      1.1     skrll 	 0xfff,			/* src_mask */
    381      1.1     skrll 	 0xfff,			/* dst_mask */
    382      1.1     skrll 	 FALSE),		/* pcrel_offset */
    383      1.1     skrll 
    384      1.1     skrll   /* The upper 16 bits of the GOT offset for the address of the
    385      1.1     skrll      canonical descriptor of a function.  */
    386      1.1     skrll   HOWTO (R_FRV_FUNCDESC_GOTOFFHI, /* type */
    387      1.1     skrll 	 0,			/* rightshift */
    388      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    389      1.1     skrll 	 16,			/* bitsize */
    390      1.1     skrll 	 FALSE,			/* pc_relative */
    391      1.1     skrll 	 0,			/* bitpos */
    392      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    393      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    394      1.1     skrll 	 "R_FRV_FUNCDESC_GOTOFFHI", /* name */
    395      1.1     skrll 	 FALSE,			/* partial_inplace */
    396      1.1     skrll 	 0xffff,		/* src_mask */
    397      1.1     skrll 	 0xffff,		/* dst_mask */
    398      1.1     skrll 	 FALSE),		/* pcrel_offset */
    399      1.1     skrll 
    400      1.1     skrll   /* The lower 16 bits of the GOT offset for the address of the
    401      1.1     skrll      canonical descriptor of a function.  */
    402      1.1     skrll   HOWTO (R_FRV_FUNCDESC_GOTOFFLO, /* type */
    403      1.1     skrll 	 0,			/* rightshift */
    404      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    405      1.1     skrll 	 16,			/* bitsize */
    406      1.1     skrll 	 FALSE,			/* pc_relative */
    407      1.1     skrll 	 0,			/* bitpos */
    408      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    409      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    410      1.1     skrll 	 "R_FRV_FUNCDESC_GOTOFFLO", /* name */
    411      1.1     skrll 	 FALSE,			/* partial_inplace */
    412      1.1     skrll 	 0xffff,		/* src_mask */
    413      1.1     skrll 	 0xffff,		/* dst_mask */
    414      1.1     skrll 	 FALSE),		/* pcrel_offset */
    415      1.1     skrll 
    416      1.1     skrll   /* A 12-bit signed operand with the GOT offset for the address of
    417      1.1     skrll      the symbol.  */
    418      1.1     skrll   HOWTO (R_FRV_GOTOFF12,	/* type */
    419      1.1     skrll 	 0,			/* rightshift */
    420      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    421      1.1     skrll 	 12,			/* bitsize */
    422      1.1     skrll 	 FALSE,			/* pc_relative */
    423      1.1     skrll 	 0,			/* bitpos */
    424      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    425      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    426      1.1     skrll 	 "R_FRV_GOTOFF12",	/* name */
    427      1.1     skrll 	 FALSE,			/* partial_inplace */
    428      1.1     skrll 	 0xfff,			/* src_mask */
    429      1.1     skrll 	 0xfff,			/* dst_mask */
    430      1.1     skrll 	 FALSE),		/* pcrel_offset */
    431      1.1     skrll 
    432      1.1     skrll   /* The upper 16 bits of the GOT offset for the address of the
    433      1.1     skrll      symbol.  */
    434      1.1     skrll   HOWTO (R_FRV_GOTOFFHI,	/* type */
    435      1.1     skrll 	 0,			/* rightshift */
    436      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    437      1.1     skrll 	 16,			/* bitsize */
    438      1.1     skrll 	 FALSE,			/* pc_relative */
    439      1.1     skrll 	 0,			/* bitpos */
    440      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    441      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    442      1.1     skrll 	 "R_FRV_GOTOFFHI",	/* name */
    443      1.1     skrll 	 FALSE,			/* partial_inplace */
    444      1.1     skrll 	 0xffff,		/* src_mask */
    445      1.1     skrll 	 0xffff,		/* dst_mask */
    446      1.1     skrll 	 FALSE),		/* pcrel_offset */
    447      1.1     skrll 
    448      1.1     skrll   /* The lower 16 bits of the GOT offset for the address of the
    449      1.1     skrll      symbol.  */
    450      1.1     skrll   HOWTO (R_FRV_GOTOFFLO,	/* type */
    451      1.1     skrll 	 0,			/* rightshift */
    452      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    453      1.1     skrll 	 16,			/* bitsize */
    454      1.1     skrll 	 FALSE,			/* pc_relative */
    455      1.1     skrll 	 0,			/* bitpos */
    456      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    457      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    458      1.1     skrll 	 "R_FRV_GOTOFFLO",	/* name */
    459      1.1     skrll 	 FALSE,			/* partial_inplace */
    460      1.1     skrll 	 0xffff,		/* src_mask */
    461      1.1     skrll 	 0xffff,		/* dst_mask */
    462      1.1     skrll 	 FALSE),		/* pcrel_offset */
    463      1.1     skrll 
    464      1.1     skrll   /* A 24-bit pc-relative relocation referencing the TLS PLT entry for
    465      1.1     skrll      a thread-local symbol.  If the symbol number is 0, it refers to
    466      1.1     skrll      the module.  */
    467      1.1     skrll   HOWTO (R_FRV_GETTLSOFF,	/* type */
    468      1.1     skrll 	 2,			/* rightshift */
    469      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    470      1.1     skrll 	 26,			/* bitsize */
    471      1.1     skrll 	 TRUE,			/* pc_relative */
    472      1.1     skrll 	 0,			/* bitpos */
    473      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    474      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    475      1.1     skrll 	 "R_FRV_GETTLSOFF",	/* name */
    476      1.1     skrll 	 FALSE,			/* partial_inplace */
    477      1.1     skrll 	 0x7e03ffff,		/* src_mask */
    478      1.1     skrll 	 0x7e03ffff,		/* dst_mask */
    479      1.1     skrll 	 TRUE),			/* pcrel_offset */
    480      1.1     skrll 
    481      1.1     skrll   /* A 64-bit TLS descriptor for a symbol.  This relocation is only
    482      1.1     skrll      valid as a REL, dynamic relocation.  */
    483      1.1     skrll   HOWTO (R_FRV_TLSDESC_VALUE,	/* type */
    484      1.1     skrll 	 0,			/* rightshift */
    485      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    486      1.1     skrll 	 64,			/* bitsize */
    487      1.1     skrll 	 FALSE,			/* pc_relative */
    488      1.1     skrll 	 0,			/* bitpos */
    489      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    490      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    491      1.1     skrll 	 "R_FRV_TLSDESC_VALUE", /* name */
    492      1.1     skrll 	 FALSE,			/* partial_inplace */
    493      1.1     skrll 	 0xffffffff,		/* src_mask */
    494      1.1     skrll 	 0xffffffff,		/* dst_mask */
    495      1.1     skrll 	 FALSE),		/* pcrel_offset */
    496      1.1     skrll 
    497      1.1     skrll   /* A 12-bit signed operand with the GOT offset for the TLS
    498      1.1     skrll      descriptor of the symbol.  */
    499      1.1     skrll   HOWTO (R_FRV_GOTTLSDESC12,	/* type */
    500      1.1     skrll 	 0,			/* rightshift */
    501      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    502      1.1     skrll 	 12,			/* bitsize */
    503      1.1     skrll 	 FALSE,			/* pc_relative */
    504      1.1     skrll 	 0,			/* bitpos */
    505      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    506      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    507      1.1     skrll 	 "R_FRV_GOTTLSDESC12",	/* name */
    508      1.1     skrll 	 FALSE,			/* partial_inplace */
    509      1.1     skrll 	 0xfff,			/* src_mask */
    510      1.1     skrll 	 0xfff,			/* dst_mask */
    511      1.1     skrll 	 FALSE),		/* pcrel_offset */
    512      1.1     skrll 
    513      1.1     skrll   /* The upper 16 bits of the GOT offset for the TLS descriptor of the
    514      1.1     skrll      symbol.  */
    515      1.1     skrll   HOWTO (R_FRV_GOTTLSDESCHI,	/* type */
    516      1.1     skrll 	 0,			/* rightshift */
    517      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    518      1.1     skrll 	 16,			/* bitsize */
    519      1.1     skrll 	 FALSE,			/* pc_relative */
    520      1.1     skrll 	 0,			/* bitpos */
    521      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    522      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    523      1.1     skrll 	 "R_FRV_GOTTLSDESCHI",	/* name */
    524      1.1     skrll 	 FALSE,			/* partial_inplace */
    525      1.1     skrll 	 0xffff,		/* src_mask */
    526      1.1     skrll 	 0xffff,		/* dst_mask */
    527      1.1     skrll 	 FALSE),		/* pcrel_offset */
    528      1.1     skrll 
    529      1.1     skrll   /* The lower 16 bits of the GOT offset for the TLS descriptor of the
    530      1.1     skrll      symbol.  */
    531      1.1     skrll   HOWTO (R_FRV_GOTTLSDESCLO,	/* type */
    532      1.1     skrll 	 0,			/* rightshift */
    533      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    534      1.1     skrll 	 16,			/* bitsize */
    535      1.1     skrll 	 FALSE,			/* pc_relative */
    536      1.1     skrll 	 0,			/* bitpos */
    537      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    538      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    539      1.1     skrll 	 "R_FRV_GOTTLSDESCLO",	/* name */
    540      1.1     skrll 	 FALSE,			/* partial_inplace */
    541      1.1     skrll 	 0xffff,		/* src_mask */
    542      1.1     skrll 	 0xffff,		/* dst_mask */
    543      1.1     skrll 	 FALSE),		/* pcrel_offset */
    544      1.1     skrll 
    545      1.1     skrll   /* A 12-bit signed operand with the offset from the module base
    546      1.1     skrll      address to the thread-local symbol address.  */
    547      1.1     skrll   HOWTO (R_FRV_TLSMOFF12,	 /* type */
    548      1.1     skrll 	 0,			/* rightshift */
    549      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    550      1.1     skrll 	 12,			/* bitsize */
    551      1.1     skrll 	 FALSE,			/* pc_relative */
    552      1.1     skrll 	 0,			/* bitpos */
    553      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    554      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    555      1.1     skrll 	 "R_FRV_TLSMOFF12",	/* name */
    556      1.1     skrll 	 FALSE,			/* partial_inplace */
    557      1.1     skrll 	 0xfff,			/* src_mask */
    558      1.1     skrll 	 0xfff,			/* dst_mask */
    559      1.1     skrll 	 FALSE),		/* pcrel_offset */
    560      1.1     skrll 
    561      1.1     skrll   /* The upper 16 bits of the offset from the module base address to
    562      1.1     skrll      the thread-local symbol address.  */
    563      1.1     skrll   HOWTO (R_FRV_TLSMOFFHI,	/* type */
    564      1.1     skrll 	 0,			/* rightshift */
    565      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    566      1.1     skrll 	 16,			/* bitsize */
    567      1.1     skrll 	 FALSE,			/* pc_relative */
    568      1.1     skrll 	 0,			/* bitpos */
    569      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    570      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    571      1.1     skrll 	 "R_FRV_TLSMOFFHI",	/* name */
    572      1.1     skrll 	 FALSE,			/* partial_inplace */
    573      1.1     skrll 	 0xffff,		/* src_mask */
    574      1.1     skrll 	 0xffff,		/* dst_mask */
    575      1.1     skrll 	 FALSE),		/* pcrel_offset */
    576      1.1     skrll 
    577      1.1     skrll   /* The lower 16 bits of the offset from the module base address to
    578      1.1     skrll      the thread-local symbol address.  */
    579      1.1     skrll   HOWTO (R_FRV_TLSMOFFLO,	/* type */
    580      1.1     skrll 	 0,			/* rightshift */
    581      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    582      1.1     skrll 	 16,			/* bitsize */
    583      1.1     skrll 	 FALSE,			/* pc_relative */
    584      1.1     skrll 	 0,			/* bitpos */
    585      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    586      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    587      1.1     skrll 	 "R_FRV_TLSMOFFLO",	/* name */
    588      1.1     skrll 	 FALSE,			/* partial_inplace */
    589      1.1     skrll 	 0xffff,		/* src_mask */
    590      1.1     skrll 	 0xffff,		/* dst_mask */
    591      1.1     skrll 	 FALSE),		/* pcrel_offset */
    592      1.1     skrll 
    593      1.1     skrll   /* A 12-bit signed operand with the GOT offset for the TLSOFF entry
    594      1.1     skrll      for a symbol.  */
    595      1.1     skrll   HOWTO (R_FRV_GOTTLSOFF12,	/* type */
    596      1.1     skrll 	 0,			/* rightshift */
    597      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    598      1.1     skrll 	 12,			/* bitsize */
    599      1.1     skrll 	 FALSE,			/* pc_relative */
    600      1.1     skrll 	 0,			/* bitpos */
    601      1.1     skrll 	 complain_overflow_signed, /* complain_on_overflow */
    602      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    603      1.1     skrll 	 "R_FRV_GOTTLSOFF12",	/* name */
    604      1.1     skrll 	 FALSE,			/* partial_inplace */
    605      1.1     skrll 	 0xfff,			/* src_mask */
    606      1.1     skrll 	 0xfff,			/* dst_mask */
    607      1.1     skrll 	 FALSE),		/* pcrel_offset */
    608      1.1     skrll 
    609      1.1     skrll   /* The upper 16 bits of the GOT offset for the TLSOFF entry for a
    610      1.1     skrll      symbol.  */
    611      1.1     skrll   HOWTO (R_FRV_GOTTLSOFFHI,	/* type */
    612      1.1     skrll 	 0,			/* rightshift */
    613      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    614      1.1     skrll 	 16,			/* bitsize */
    615      1.1     skrll 	 FALSE,			/* pc_relative */
    616      1.1     skrll 	 0,			/* bitpos */
    617      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    618      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    619      1.1     skrll 	 "R_FRV_GOTTLSOFFHI",	/* name */
    620      1.1     skrll 	 FALSE,			/* partial_inplace */
    621      1.1     skrll 	 0xffff,		/* src_mask */
    622      1.1     skrll 	 0xffff,		/* dst_mask */
    623      1.1     skrll 	 FALSE),		/* pcrel_offset */
    624      1.1     skrll 
    625      1.1     skrll   /* The lower 16 bits of the GOT offset for the TLSOFF entry for a
    626      1.1     skrll      symbol.  */
    627      1.1     skrll   HOWTO (R_FRV_GOTTLSOFFLO,	/* type */
    628      1.1     skrll 	 0,			/* rightshift */
    629      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    630      1.1     skrll 	 16,			/* bitsize */
    631      1.1     skrll 	 FALSE,			/* pc_relative */
    632      1.1     skrll 	 0,			/* bitpos */
    633      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    634      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    635      1.1     skrll 	 "R_FRV_GOTTLSOFFLO",	/* name */
    636      1.1     skrll 	 FALSE,			/* partial_inplace */
    637      1.1     skrll 	 0xffff,		/* src_mask */
    638      1.1     skrll 	 0xffff,		/* dst_mask */
    639      1.1     skrll 	 FALSE),		/* pcrel_offset */
    640      1.1     skrll 
    641      1.1     skrll   /* The 32-bit offset from the thread pointer (not the module base
    642      1.1     skrll      address) to a thread-local symbol.  */
    643      1.1     skrll   HOWTO (R_FRV_TLSOFF,		/* type */
    644      1.1     skrll 	 0,			/* rightshift */
    645      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    646      1.1     skrll 	 32,			/* bitsize */
    647      1.1     skrll 	 FALSE,			/* pc_relative */
    648      1.1     skrll 	 0,			/* bitpos */
    649      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    650      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    651      1.1     skrll 	 "R_FRV_TLSOFF",	/* name */
    652      1.1     skrll 	 FALSE,			/* partial_inplace */
    653      1.1     skrll 	 0xffffffff,		/* src_mask */
    654      1.1     skrll 	 0xffffffff,		/* dst_mask */
    655      1.1     skrll 	 FALSE),		/* pcrel_offset */
    656      1.1     skrll 
    657      1.1     skrll   /* An annotation for linker relaxation, that denotes the
    658      1.1     skrll      symbol+addend whose TLS descriptor is referenced by the sum of
    659      1.1     skrll      the two input registers of an ldd instruction.  */
    660      1.1     skrll   HOWTO (R_FRV_TLSDESC_RELAX,	/* type */
    661      1.1     skrll 	 0,			/* rightshift */
    662      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    663      1.1     skrll 	 0,			/* bitsize */
    664      1.1     skrll 	 FALSE,			/* pc_relative */
    665      1.1     skrll 	 0,			/* bitpos */
    666      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    667      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    668      1.1     skrll 	 "R_FRV_TLSDESC_RELAX",	/* name */
    669      1.1     skrll 	 FALSE,			/* partial_inplace */
    670      1.1     skrll 	 0,			/* src_mask */
    671      1.1     skrll 	 0,			/* dst_mask */
    672      1.1     skrll 	 FALSE),		/* pcrel_offset */
    673      1.1     skrll 
    674      1.1     skrll   /* An annotation for linker relaxation, that denotes the
    675      1.1     skrll      symbol+addend whose TLS resolver entry point is given by the sum
    676      1.1     skrll      of the two register operands of an calll instruction.  */
    677      1.1     skrll   HOWTO (R_FRV_GETTLSOFF_RELAX,	/* type */
    678      1.1     skrll 	 0,			/* rightshift */
    679      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    680      1.1     skrll 	 0,			/* bitsize */
    681      1.1     skrll 	 FALSE,			/* pc_relative */
    682      1.1     skrll 	 0,			/* bitpos */
    683      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    684      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    685      1.1     skrll 	 "R_FRV_GETTLSOFF_RELAX", /* name */
    686      1.1     skrll 	 FALSE,			/* partial_inplace */
    687      1.1     skrll 	 0,			/* src_mask */
    688      1.1     skrll 	 0,			/* dst_mask */
    689      1.1     skrll 	 FALSE),		/* pcrel_offset */
    690      1.1     skrll 
    691      1.1     skrll   /* An annotation for linker relaxation, that denotes the
    692      1.1     skrll      symbol+addend whose TLS offset GOT entry is given by the sum of
    693      1.1     skrll      the two input registers of an ld instruction.  */
    694      1.1     skrll   HOWTO (R_FRV_TLSOFF_RELAX,	/* type */
    695      1.1     skrll 	 0,			/* rightshift */
    696      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    697      1.1     skrll 	 0,			/* bitsize */
    698      1.1     skrll 	 FALSE,			/* pc_relative */
    699      1.1     skrll 	 0,			/* bitpos */
    700      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    701      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    702      1.1     skrll 	 "R_FRV_TLSOFF_RELAX",	/* name */
    703      1.1     skrll 	 FALSE,			/* partial_inplace */
    704      1.1     skrll 	 0,			/* src_mask */
    705      1.1     skrll 	 0,			/* dst_mask */
    706      1.1     skrll 	 FALSE),		/* pcrel_offset */
    707      1.1     skrll 
    708      1.1     skrll   /* A 32-bit offset from the module base address to
    709      1.1     skrll      the thread-local symbol address.  */
    710      1.1     skrll   HOWTO (R_FRV_TLSMOFF,		/* type */
    711      1.1     skrll 	 0,			/* rightshift */
    712      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    713      1.1     skrll 	 32,			/* bitsize */
    714      1.1     skrll 	 FALSE,			/* pc_relative */
    715      1.1     skrll 	 0,			/* bitpos */
    716      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    717      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    718      1.1     skrll 	 "R_FRV_TLSMOFF",	/* name */
    719      1.1     skrll 	 FALSE,			/* partial_inplace */
    720      1.1     skrll 	 0xffffffff,		/* src_mask */
    721      1.1     skrll 	 0xffffffff,		/* dst_mask */
    722      1.1     skrll 	 FALSE),		/* pcrel_offset */
    723      1.1     skrll };
    724      1.1     skrll 
    725      1.1     skrll /* GNU extension to record C++ vtable hierarchy.  */
    726      1.1     skrll static reloc_howto_type elf32_frv_vtinherit_howto =
    727      1.1     skrll   HOWTO (R_FRV_GNU_VTINHERIT,	/* type */
    728      1.1     skrll 	 0,			/* rightshift */
    729      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    730      1.1     skrll 	 0,			/* bitsize */
    731      1.1     skrll 	 FALSE,			/* pc_relative */
    732      1.1     skrll 	 0,			/* bitpos */
    733      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    734      1.1     skrll 	 NULL,			/* special_function */
    735      1.1     skrll 	 "R_FRV_GNU_VTINHERIT", /* name */
    736      1.1     skrll 	 FALSE,			/* partial_inplace */
    737      1.1     skrll 	 0,			/* src_mask */
    738      1.1     skrll 	 0,			/* dst_mask */
    739      1.1     skrll 	 FALSE);		/* pcrel_offset */
    740      1.1     skrll 
    741      1.1     skrll   /* GNU extension to record C++ vtable member usage.  */
    742      1.1     skrll static reloc_howto_type elf32_frv_vtentry_howto =
    743      1.1     skrll   HOWTO (R_FRV_GNU_VTENTRY,	/* type */
    744      1.1     skrll 	 0,			/* rightshift */
    745      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    746      1.1     skrll 	 0,			/* bitsize */
    747      1.1     skrll 	 FALSE,			/* pc_relative */
    748      1.1     skrll 	 0,			/* bitpos */
    749      1.1     skrll 	 complain_overflow_dont, /* complain_on_overflow */
    750      1.1     skrll 	 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
    751      1.1     skrll 	 "R_FRV_GNU_VTENTRY",	/* name */
    752      1.1     skrll 	 FALSE,			/* partial_inplace */
    753      1.1     skrll 	 0,			/* src_mask */
    754      1.1     skrll 	 0,			/* dst_mask */
    755      1.1     skrll 	 FALSE);		/* pcrel_offset */
    756      1.1     skrll 
    757      1.1     skrll /* The following 3 relocations are REL.  The only difference to the
    758      1.1     skrll    entries in the table above are that partial_inplace is TRUE.  */
    759      1.1     skrll static reloc_howto_type elf32_frv_rel_32_howto =
    760      1.1     skrll   HOWTO (R_FRV_32,		/* type */
    761      1.1     skrll 	 0,			/* rightshift */
    762      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    763      1.1     skrll 	 32,			/* bitsize */
    764      1.1     skrll 	 FALSE,			/* pc_relative */
    765      1.1     skrll 	 0,			/* bitpos */
    766      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    767      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    768      1.1     skrll 	 "R_FRV_32",		/* name */
    769      1.1     skrll 	 TRUE,			/* partial_inplace */
    770      1.1     skrll 	 0xffffffff,		/* src_mask */
    771      1.1     skrll 	 0xffffffff,		/* dst_mask */
    772      1.1     skrll 	 FALSE);		/* pcrel_offset */
    773      1.1     skrll 
    774      1.1     skrll static reloc_howto_type elf32_frv_rel_funcdesc_howto =
    775      1.1     skrll   HOWTO (R_FRV_FUNCDESC,	/* type */
    776      1.1     skrll 	 0,			/* rightshift */
    777      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    778      1.1     skrll 	 32,			/* bitsize */
    779      1.1     skrll 	 FALSE,			/* pc_relative */
    780      1.1     skrll 	 0,			/* bitpos */
    781      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    782      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    783      1.1     skrll 	 "R_FRV_FUNCDESC",	/* name */
    784      1.1     skrll 	 TRUE,			/* partial_inplace */
    785      1.1     skrll 	 0xffffffff,		/* src_mask */
    786      1.1     skrll 	 0xffffffff,		/* dst_mask */
    787      1.1     skrll 	 FALSE);		/* pcrel_offset */
    788      1.1     skrll 
    789      1.1     skrll static reloc_howto_type elf32_frv_rel_funcdesc_value_howto =
    790      1.1     skrll   HOWTO (R_FRV_FUNCDESC_VALUE,	/* type */
    791      1.1     skrll 	 0,			/* rightshift */
    792      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    793      1.1     skrll 	 64,			/* bitsize */
    794      1.1     skrll 	 FALSE,			/* pc_relative */
    795      1.1     skrll 	 0,			/* bitpos */
    796      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    797      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    798      1.1     skrll 	 "R_FRV_FUNCDESC_VALUE", /* name */
    799      1.1     skrll 	 TRUE,			/* partial_inplace */
    800      1.1     skrll 	 0xffffffff,		/* src_mask */
    801      1.1     skrll 	 0xffffffff,		/* dst_mask */
    802      1.1     skrll 	 FALSE);		/* pcrel_offset */
    803      1.1     skrll 
    804      1.1     skrll static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto =
    805      1.1     skrll   /* A 64-bit TLS descriptor for a symbol.  The first word resolves to
    806      1.1     skrll      an entry point, and the second resolves to a special argument.
    807      1.1     skrll      If the symbol turns out to be in static TLS, the entry point is a
    808      1.1     skrll      return instruction, and the special argument is the TLS offset
    809      1.1     skrll      for the symbol.  If it's in dynamic TLS, the entry point is a TLS
    810      1.1     skrll      offset resolver, and the special argument is a pointer to a data
    811      1.1     skrll      structure allocated by the dynamic loader, containing the GOT
    812      1.1     skrll      address for the offset resolver, the module id, the offset within
    813      1.1     skrll      the module, and anything else the TLS offset resolver might need
    814      1.1     skrll      to determine the TLS offset for the symbol in the running
    815      1.1     skrll      thread.  */
    816      1.1     skrll   HOWTO (R_FRV_TLSDESC_VALUE,	/* type */
    817      1.1     skrll 	 0,			/* rightshift */
    818      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    819      1.1     skrll 	 64,			/* bitsize */
    820      1.1     skrll 	 FALSE,			/* pc_relative */
    821      1.1     skrll 	 0,			/* bitpos */
    822      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    823      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    824      1.1     skrll 	 "R_FRV_TLSDESC_VALUE", /* name */
    825      1.1     skrll 	 TRUE,			/* partial_inplace */
    826      1.1     skrll 	 0xffffffff,		/* src_mask */
    827      1.1     skrll 	 0xffffffff,		/* dst_mask */
    828      1.1     skrll 	 FALSE);		/* pcrel_offset */
    829      1.1     skrll 
    830      1.1     skrll static reloc_howto_type elf32_frv_rel_tlsoff_howto =
    831      1.1     skrll   /* The 32-bit offset from the thread pointer (not the module base
    832      1.1     skrll      address) to a thread-local symbol.  */
    833      1.1     skrll   HOWTO (R_FRV_TLSOFF,		/* type */
    834      1.1     skrll 	 0,			/* rightshift */
    835      1.1     skrll 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    836      1.1     skrll 	 32,			/* bitsize */
    837      1.1     skrll 	 FALSE,			/* pc_relative */
    838      1.1     skrll 	 0,			/* bitpos */
    839      1.1     skrll 	 complain_overflow_bitfield, /* complain_on_overflow */
    840      1.1     skrll 	 bfd_elf_generic_reloc,	/* special_function */
    841      1.1     skrll 	 "R_FRV_TLSOFF",	/* name */
    842      1.1     skrll 	 TRUE,			/* partial_inplace */
    843      1.1     skrll 	 0xffffffff,		/* src_mask */
    844      1.1     skrll 	 0xffffffff,		/* dst_mask */
    845      1.1     skrll 	 FALSE);		/* pcrel_offset */
    846      1.1     skrll 
    847      1.1     skrll 
    848      1.1     skrll 
    849      1.1     skrll extern const bfd_target bfd_elf32_frvfdpic_vec;
    851      1.1     skrll #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_frvfdpic_vec)
    852      1.1     skrll 
    853      1.1     skrll /* An extension of the elf hash table data structure, containing some
    854      1.1     skrll    additional FRV-specific data.  */
    855      1.1     skrll struct frvfdpic_elf_link_hash_table
    856      1.1     skrll {
    857      1.1     skrll   struct elf_link_hash_table elf;
    858      1.1     skrll 
    859      1.1     skrll   /* A pointer to the .got section.  */
    860      1.1     skrll   asection *sgot;
    861      1.1     skrll   /* A pointer to the .rel.got section.  */
    862      1.1     skrll   asection *sgotrel;
    863      1.1     skrll   /* A pointer to the .rofixup section.  */
    864      1.1     skrll   asection *sgotfixup;
    865      1.1     skrll   /* A pointer to the .plt section.  */
    866      1.1     skrll   asection *splt;
    867      1.1     skrll   /* A pointer to the .rel.plt section.  */
    868      1.1     skrll   asection *spltrel;
    869      1.1     skrll   /* GOT base offset.  */
    870      1.1     skrll   bfd_vma got0;
    871      1.1     skrll   /* Location of the first non-lazy PLT entry, i.e., the number of
    872      1.1     skrll      bytes taken by lazy PLT entries.  If locally-bound TLS
    873      1.1     skrll      descriptors require a ret instruction, it will be placed at this
    874      1.1     skrll      offset.  */
    875      1.1     skrll   bfd_vma plt0;
    876      1.1     skrll   /* A hash table holding information about which symbols were
    877      1.1     skrll      referenced with which PIC-related relocations.  */
    878      1.1     skrll   struct htab *relocs_info;
    879      1.1     skrll   /* Summary reloc information collected by
    880      1.1     skrll      _frvfdpic_count_got_plt_entries.  */
    881      1.1     skrll   struct _frvfdpic_dynamic_got_info *g;
    882      1.1     skrll };
    883      1.1     skrll 
    884      1.1     skrll /* Get the FRV ELF linker hash table from a link_info structure.  */
    885  1.1.1.2  christos 
    886  1.1.1.2  christos #define frvfdpic_hash_table(p) \
    887  1.1.1.2  christos   (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
    888      1.1     skrll   == FRV_ELF_DATA ? ((struct frvfdpic_elf_link_hash_table *) ((p)->hash)) : NULL)
    889      1.1     skrll 
    890      1.1     skrll #define frvfdpic_got_section(info) \
    891      1.1     skrll   (frvfdpic_hash_table (info)->sgot)
    892      1.1     skrll #define frvfdpic_gotrel_section(info) \
    893      1.1     skrll   (frvfdpic_hash_table (info)->sgotrel)
    894      1.1     skrll #define frvfdpic_gotfixup_section(info) \
    895      1.1     skrll   (frvfdpic_hash_table (info)->sgotfixup)
    896      1.1     skrll #define frvfdpic_plt_section(info) \
    897      1.1     skrll   (frvfdpic_hash_table (info)->splt)
    898      1.1     skrll #define frvfdpic_pltrel_section(info) \
    899      1.1     skrll   (frvfdpic_hash_table (info)->spltrel)
    900      1.1     skrll #define frvfdpic_relocs_info(info) \
    901      1.1     skrll   (frvfdpic_hash_table (info)->relocs_info)
    902      1.1     skrll #define frvfdpic_got_initial_offset(info) \
    903      1.1     skrll   (frvfdpic_hash_table (info)->got0)
    904      1.1     skrll #define frvfdpic_plt_initial_offset(info) \
    905      1.1     skrll   (frvfdpic_hash_table (info)->plt0)
    906      1.1     skrll #define frvfdpic_dynamic_got_plt_info(info) \
    907      1.1     skrll   (frvfdpic_hash_table (info)->g)
    908      1.1     skrll 
    909      1.1     skrll /* Currently it's the same, but if some day we have a reason to change
    910      1.1     skrll    it, we'd better be using a different macro.
    911      1.1     skrll 
    912      1.1     skrll    FIXME: if there's any TLS PLT entry that uses local-exec or
    913      1.1     skrll    initial-exec models, we could use the ret at the end of any of them
    914      1.1     skrll    instead of adding one more.  */
    915      1.1     skrll #define frvfdpic_plt_tls_ret_offset(info) \
    916      1.1     skrll   (frvfdpic_plt_initial_offset (info))
    917      1.1     skrll 
    918      1.1     skrll /* The name of the dynamic interpreter.  This is put in the .interp
    919      1.1     skrll    section.  */
    920      1.1     skrll 
    921      1.1     skrll #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
    922      1.1     skrll 
    923      1.1     skrll #define DEFAULT_STACK_SIZE 0x20000
    924      1.1     skrll 
    925      1.1     skrll /* This structure is used to collect the number of entries present in
    926      1.1     skrll    each addressable range of the got.  */
    927      1.1     skrll struct _frvfdpic_dynamic_got_info
    928      1.1     skrll {
    929      1.1     skrll   /* Several bits of information about the current link.  */
    930      1.1     skrll   struct bfd_link_info *info;
    931      1.1     skrll   /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
    932      1.1     skrll      ranges.  */
    933      1.1     skrll   bfd_vma got12, gotlos, gothilo;
    934      1.1     skrll   /* Total GOT size needed for function descriptor entries within the 12-,
    935      1.1     skrll      16- or 32-bit ranges.  */
    936      1.1     skrll   bfd_vma fd12, fdlos, fdhilo;
    937      1.1     skrll   /* Total GOT size needed by function descriptor entries referenced
    938      1.1     skrll      in PLT entries, that would be profitable to place in offsets
    939      1.1     skrll      close to the PIC register.  */
    940      1.1     skrll   bfd_vma fdplt;
    941      1.1     skrll   /* Total PLT size needed by lazy PLT entries.  */
    942      1.1     skrll   bfd_vma lzplt;
    943      1.1     skrll   /* Total GOT size needed for TLS descriptor entries within the 12-,
    944      1.1     skrll      16- or 32-bit ranges.  */
    945      1.1     skrll   bfd_vma tlsd12, tlsdlos, tlsdhilo;
    946      1.1     skrll   /* Total GOT size needed by TLS descriptors referenced in PLT
    947      1.1     skrll      entries, that would be profitable to place in offers close to the
    948      1.1     skrll      PIC register.  */
    949      1.1     skrll   bfd_vma tlsdplt;
    950      1.1     skrll   /* Total PLT size needed by TLS lazy PLT entries.  */
    951      1.1     skrll   bfd_vma tlslzplt;
    952      1.1     skrll   /* Number of relocations carried over from input object files.  */
    953      1.1     skrll   unsigned long relocs;
    954      1.1     skrll   /* Number of fixups introduced by relocations in input object files.  */
    955      1.1     skrll   unsigned long fixups;
    956      1.1     skrll   /* The number of fixups that reference the ret instruction added to
    957      1.1     skrll      the PLT for locally-resolved TLS descriptors.  */
    958      1.1     skrll   unsigned long tls_ret_refs;
    959      1.1     skrll };
    960      1.1     skrll 
    961      1.1     skrll /* This structure is used to assign offsets to got entries, function
    962      1.1     skrll    descriptors, plt entries and lazy plt entries.  */
    963      1.1     skrll 
    964      1.1     skrll struct _frvfdpic_dynamic_got_plt_info
    965      1.1     skrll {
    966      1.1     skrll   /* Summary information collected with _frvfdpic_count_got_plt_entries.  */
    967      1.1     skrll   struct _frvfdpic_dynamic_got_info g;
    968      1.1     skrll 
    969      1.1     skrll   /* For each addressable range, we record a MAX (positive) and MIN
    970      1.1     skrll      (negative) value.  CUR is used to assign got entries, and it's
    971      1.1     skrll      incremented from an initial positive value to MAX, then from MIN
    972      1.1     skrll      to FDCUR (unless FDCUR wraps around first).  FDCUR is used to
    973      1.1     skrll      assign function descriptors, and it's decreased from an initial
    974      1.1     skrll      non-positive value to MIN, then from MAX down to CUR (unless CUR
    975      1.1     skrll      wraps around first).  All of MIN, MAX, CUR and FDCUR always point
    976      1.1     skrll      to even words.  ODD, if non-zero, indicates an odd word to be
    977      1.1     skrll      used for the next got entry, otherwise CUR is used and
    978      1.1     skrll      incremented by a pair of words, wrapping around when it reaches
    979      1.1     skrll      MAX.  FDCUR is decremented (and wrapped) before the next function
    980      1.1     skrll      descriptor is chosen.  FDPLT indicates the number of remaining
    981      1.1     skrll      slots that can be used for function descriptors used only by PLT
    982      1.1     skrll      entries.
    983      1.1     skrll 
    984      1.1     skrll      TMAX, TMIN and TCUR are used to assign TLS descriptors.  TCUR
    985      1.1     skrll      starts as MAX, and grows up to TMAX, then wraps around to TMIN
    986      1.1     skrll      and grows up to MIN.  TLSDPLT indicates the number of remaining
    987      1.1     skrll      slots that can be used for TLS descriptors used only by TLS PLT
    988      1.1     skrll      entries.  */
    989      1.1     skrll   struct _frvfdpic_dynamic_got_alloc_data
    990      1.1     skrll   {
    991      1.1     skrll     bfd_signed_vma max, cur, odd, fdcur, min;
    992      1.1     skrll     bfd_signed_vma tmax, tcur, tmin;
    993      1.1     skrll     bfd_vma fdplt, tlsdplt;
    994      1.1     skrll   } got12, gotlos, gothilo;
    995      1.1     skrll };
    996      1.1     skrll 
    997      1.1     skrll /* Create an FRV ELF linker hash table.  */
    998      1.1     skrll 
    999      1.1     skrll static struct bfd_link_hash_table *
   1000      1.1     skrll frvfdpic_elf_link_hash_table_create (bfd *abfd)
   1001      1.1     skrll {
   1002      1.1     skrll   struct frvfdpic_elf_link_hash_table *ret;
   1003      1.1     skrll   bfd_size_type amt = sizeof (struct frvfdpic_elf_link_hash_table);
   1004      1.1     skrll 
   1005      1.1     skrll   ret = bfd_zalloc (abfd, amt);
   1006      1.1     skrll   if (ret == NULL)
   1007      1.1     skrll     return NULL;
   1008      1.1     skrll 
   1009      1.1     skrll   if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
   1010  1.1.1.2  christos 				      _bfd_elf_link_hash_newfunc,
   1011  1.1.1.2  christos 				      sizeof (struct elf_link_hash_entry),
   1012      1.1     skrll 				      FRV_ELF_DATA))
   1013      1.1     skrll     {
   1014      1.1     skrll       free (ret);
   1015      1.1     skrll       return NULL;
   1016      1.1     skrll     }
   1017      1.1     skrll 
   1018      1.1     skrll   return &ret->elf.root;
   1019      1.1     skrll }
   1020      1.1     skrll 
   1021      1.1     skrll /* Decide whether a reference to a symbol can be resolved locally or
   1022      1.1     skrll    not.  If the symbol is protected, we want the local address, but
   1023      1.1     skrll    its function descriptor must be assigned by the dynamic linker.  */
   1024      1.1     skrll #define FRVFDPIC_SYM_LOCAL(INFO, H) \
   1025      1.1     skrll   (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
   1026      1.1     skrll    || ! elf_hash_table (INFO)->dynamic_sections_created)
   1027      1.1     skrll #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
   1028      1.1     skrll   ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
   1029      1.1     skrll 
   1030      1.1     skrll /* This structure collects information on what kind of GOT, PLT or
   1031      1.1     skrll    function descriptors are required by relocations that reference a
   1032      1.1     skrll    certain symbol.  */
   1033      1.1     skrll struct frvfdpic_relocs_info
   1034      1.1     skrll {
   1035      1.1     skrll   /* The index of the symbol, as stored in the relocation r_info, if
   1036      1.1     skrll      we have a local symbol; -1 otherwise.  */
   1037      1.1     skrll   long symndx;
   1038      1.1     skrll   union
   1039      1.1     skrll   {
   1040      1.1     skrll     /* The input bfd in which the symbol is defined, if it's a local
   1041      1.1     skrll        symbol.  */
   1042      1.1     skrll     bfd *abfd;
   1043      1.1     skrll     /* If symndx == -1, the hash table entry corresponding to a global
   1044      1.1     skrll        symbol (even if it turns out to bind locally, in which case it
   1045      1.1     skrll        should ideally be replaced with section's symndx + addend).  */
   1046      1.1     skrll     struct elf_link_hash_entry *h;
   1047      1.1     skrll   } d;
   1048      1.1     skrll   /* The addend of the relocation that references the symbol.  */
   1049      1.1     skrll   bfd_vma addend;
   1050      1.1     skrll 
   1051      1.1     skrll   /* The fields above are used to identify an entry.  The fields below
   1052      1.1     skrll      contain information on how an entry is used and, later on, which
   1053      1.1     skrll      locations it was assigned.  */
   1054      1.1     skrll   /* The following 3 fields record whether the symbol+addend above was
   1055      1.1     skrll      ever referenced with a GOT relocation.  The 12 suffix indicates a
   1056      1.1     skrll      GOT12 relocation; los is used for GOTLO relocations that are not
   1057      1.1     skrll      matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
   1058      1.1     skrll      pairs.  */
   1059      1.1     skrll   unsigned got12:1;
   1060      1.1     skrll   unsigned gotlos:1;
   1061      1.1     skrll   unsigned gothilo:1;
   1062      1.1     skrll   /* Whether a FUNCDESC relocation references symbol+addend.  */
   1063      1.1     skrll   unsigned fd:1;
   1064      1.1     skrll   /* Whether a FUNCDESC_GOT relocation references symbol+addend.  */
   1065      1.1     skrll   unsigned fdgot12:1;
   1066      1.1     skrll   unsigned fdgotlos:1;
   1067      1.1     skrll   unsigned fdgothilo:1;
   1068      1.1     skrll   /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend.  */
   1069      1.1     skrll   unsigned fdgoff12:1;
   1070      1.1     skrll   unsigned fdgofflos:1;
   1071      1.1     skrll   unsigned fdgoffhilo:1;
   1072      1.1     skrll   /* Whether a GETTLSOFF relocation references symbol+addend.  */
   1073      1.1     skrll   unsigned tlsplt:1;
   1074      1.1     skrll   /* FIXME: we should probably add tlspltdesc, tlspltoff and
   1075      1.1     skrll      tlspltimm, to tell what kind of TLS PLT entry we're generating.
   1076      1.1     skrll      We might instead just pre-compute flags telling whether the
   1077      1.1     skrll      object is suitable for local exec, initial exec or general
   1078      1.1     skrll      dynamic addressing, and use that all over the place.  We could
   1079      1.1     skrll      also try to do a better job of merging TLSOFF and TLSDESC entries
   1080      1.1     skrll      in main executables, but perhaps we can get rid of TLSDESC
   1081      1.1     skrll      entirely in them instead.  */
   1082      1.1     skrll   /* Whether a GOTTLSDESC relocation references symbol+addend.  */
   1083      1.1     skrll   unsigned tlsdesc12:1;
   1084      1.1     skrll   unsigned tlsdesclos:1;
   1085      1.1     skrll   unsigned tlsdeschilo:1;
   1086      1.1     skrll   /* Whether a GOTTLSOFF relocation references symbol+addend.  */
   1087      1.1     skrll   unsigned tlsoff12:1;
   1088      1.1     skrll   unsigned tlsofflos:1;
   1089      1.1     skrll   unsigned tlsoffhilo:1;
   1090      1.1     skrll   /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
   1091      1.1     skrll      GOTOFFHI relocations.  The addend doesn't really matter, since we
   1092      1.1     skrll      envision that this will only be used to check whether the symbol
   1093      1.1     skrll      is mapped to the same segment as the got.  */
   1094      1.1     skrll   unsigned gotoff:1;
   1095      1.1     skrll   /* Whether symbol+addend is referenced by a LABEL24 relocation.  */
   1096      1.1     skrll   unsigned call:1;
   1097      1.1     skrll   /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
   1098      1.1     skrll      relocation.  */
   1099      1.1     skrll   unsigned sym:1;
   1100      1.1     skrll   /* Whether we need a PLT entry for a symbol.  Should be implied by
   1101      1.1     skrll      something like:
   1102      1.1     skrll      (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h))  */
   1103      1.1     skrll   unsigned plt:1;
   1104      1.1     skrll   /* Whether a function descriptor should be created in this link unit
   1105      1.1     skrll      for symbol+addend.  Should be implied by something like:
   1106      1.1     skrll      (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
   1107      1.1     skrll       || ((fd || fdgot12 || fdgotlos || fdgothilo)
   1108      1.1     skrll           && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h))))  */
   1109      1.1     skrll   unsigned privfd:1;
   1110      1.1     skrll   /* Whether a lazy PLT entry is needed for this symbol+addend.
   1111      1.1     skrll      Should be implied by something like:
   1112      1.1     skrll      (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
   1113      1.1     skrll       && ! (info->flags & DF_BIND_NOW))  */
   1114      1.1     skrll   unsigned lazyplt:1;
   1115      1.1     skrll   /* Whether we've already emitted GOT relocations and PLT entries as
   1116      1.1     skrll      needed for this symbol.  */
   1117      1.1     skrll   unsigned done:1;
   1118      1.1     skrll 
   1119      1.1     skrll   /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
   1120      1.1     skrll      R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
   1121      1.1     skrll      symbol+addend.  */
   1122      1.1     skrll   unsigned relocs32, relocsfd, relocsfdv, relocstlsd, relocstlsoff;
   1123      1.1     skrll 
   1124      1.1     skrll   /* The number of .rofixups entries and dynamic relocations allocated
   1125      1.1     skrll      for this symbol, minus any that might have already been used.  */
   1126      1.1     skrll   unsigned fixups, dynrelocs;
   1127      1.1     skrll 
   1128      1.1     skrll   /* The offsets of the GOT entries assigned to symbol+addend, to the
   1129      1.1     skrll      function descriptor's address, and to a function descriptor,
   1130      1.1     skrll      respectively.  Should be zero if unassigned.  The offsets are
   1131      1.1     skrll      counted from the value that will be assigned to the PIC register,
   1132      1.1     skrll      not from the beginning of the .got section.  */
   1133      1.1     skrll   bfd_signed_vma got_entry, fdgot_entry, fd_entry;
   1134      1.1     skrll   /* The offsets of the PLT entries assigned to symbol+addend,
   1135      1.1     skrll      non-lazy and lazy, respectively.  If unassigned, should be
   1136      1.1     skrll      (bfd_vma)-1.  */
   1137      1.1     skrll   bfd_vma plt_entry, lzplt_entry;
   1138      1.1     skrll   /* The offsets of the GOT entries for TLS offset and TLS descriptor.  */
   1139      1.1     skrll   bfd_signed_vma tlsoff_entry, tlsdesc_entry;
   1140      1.1     skrll   /* The offset of the TLS offset PLT entry.  */
   1141      1.1     skrll   bfd_vma tlsplt_entry;
   1142      1.1     skrll };
   1143      1.1     skrll 
   1144      1.1     skrll /* Compute a hash with the key fields of an frvfdpic_relocs_info entry.  */
   1145      1.1     skrll static hashval_t
   1146      1.1     skrll frvfdpic_relocs_info_hash (const void *entry_)
   1147      1.1     skrll {
   1148      1.1     skrll   const struct frvfdpic_relocs_info *entry = entry_;
   1149      1.1     skrll 
   1150      1.1     skrll   return (entry->symndx == -1
   1151      1.1     skrll 	  ? (long) entry->d.h->root.root.hash
   1152      1.1     skrll 	  : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend;
   1153      1.1     skrll }
   1154      1.1     skrll 
   1155      1.1     skrll /* Test whether the key fields of two frvfdpic_relocs_info entries are
   1156      1.1     skrll    identical.  */
   1157      1.1     skrll static int
   1158      1.1     skrll frvfdpic_relocs_info_eq (const void *entry1, const void *entry2)
   1159      1.1     skrll {
   1160      1.1     skrll   const struct frvfdpic_relocs_info *e1 = entry1;
   1161      1.1     skrll   const struct frvfdpic_relocs_info *e2 = entry2;
   1162      1.1     skrll 
   1163      1.1     skrll   return e1->symndx == e2->symndx && e1->addend == e2->addend
   1164      1.1     skrll     && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd);
   1165      1.1     skrll }
   1166      1.1     skrll 
   1167      1.1     skrll /* Find or create an entry in a hash table HT that matches the key
   1168      1.1     skrll    fields of the given ENTRY.  If it's not found, memory for a new
   1169      1.1     skrll    entry is allocated in ABFD's obstack.  */
   1170      1.1     skrll static struct frvfdpic_relocs_info *
   1171      1.1     skrll frvfdpic_relocs_info_find (struct htab *ht,
   1172      1.1     skrll 			   bfd *abfd,
   1173      1.1     skrll 			   const struct frvfdpic_relocs_info *entry,
   1174      1.1     skrll 			   enum insert_option insert)
   1175      1.1     skrll {
   1176      1.1     skrll   struct frvfdpic_relocs_info **loc =
   1177      1.1     skrll     (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert);
   1178      1.1     skrll 
   1179      1.1     skrll   if (! loc)
   1180      1.1     skrll     return NULL;
   1181      1.1     skrll 
   1182      1.1     skrll   if (*loc)
   1183      1.1     skrll     return *loc;
   1184      1.1     skrll 
   1185      1.1     skrll   *loc = bfd_zalloc (abfd, sizeof (**loc));
   1186      1.1     skrll 
   1187      1.1     skrll   if (! *loc)
   1188      1.1     skrll     return *loc;
   1189      1.1     skrll 
   1190      1.1     skrll   (*loc)->symndx = entry->symndx;
   1191      1.1     skrll   (*loc)->d = entry->d;
   1192      1.1     skrll   (*loc)->addend = entry->addend;
   1193      1.1     skrll   (*loc)->plt_entry = (bfd_vma)-1;
   1194      1.1     skrll   (*loc)->lzplt_entry = (bfd_vma)-1;
   1195      1.1     skrll   (*loc)->tlsplt_entry = (bfd_vma)-1;
   1196      1.1     skrll 
   1197      1.1     skrll   return *loc;
   1198      1.1     skrll }
   1199      1.1     skrll 
   1200      1.1     skrll /* Obtain the address of the entry in HT associated with H's symbol +
   1201      1.1     skrll    addend, creating a new entry if none existed.  ABFD is only used
   1202      1.1     skrll    for memory allocation purposes.  */
   1203      1.1     skrll inline static struct frvfdpic_relocs_info *
   1204      1.1     skrll frvfdpic_relocs_info_for_global (struct htab *ht,
   1205      1.1     skrll 				 bfd *abfd,
   1206      1.1     skrll 				 struct elf_link_hash_entry *h,
   1207      1.1     skrll 				 bfd_vma addend,
   1208      1.1     skrll 				 enum insert_option insert)
   1209      1.1     skrll {
   1210      1.1     skrll   struct frvfdpic_relocs_info entry;
   1211      1.1     skrll 
   1212      1.1     skrll   entry.symndx = -1;
   1213      1.1     skrll   entry.d.h = h;
   1214      1.1     skrll   entry.addend = addend;
   1215      1.1     skrll 
   1216      1.1     skrll   return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
   1217      1.1     skrll }
   1218      1.1     skrll 
   1219      1.1     skrll /* Obtain the address of the entry in HT associated with the SYMNDXth
   1220      1.1     skrll    local symbol of the input bfd ABFD, plus the addend, creating a new
   1221      1.1     skrll    entry if none existed.  */
   1222      1.1     skrll inline static struct frvfdpic_relocs_info *
   1223      1.1     skrll frvfdpic_relocs_info_for_local (struct htab *ht,
   1224      1.1     skrll 				bfd *abfd,
   1225      1.1     skrll 				long symndx,
   1226      1.1     skrll 				bfd_vma addend,
   1227      1.1     skrll 				enum insert_option insert)
   1228      1.1     skrll {
   1229      1.1     skrll   struct frvfdpic_relocs_info entry;
   1230      1.1     skrll 
   1231      1.1     skrll   entry.symndx = symndx;
   1232      1.1     skrll   entry.d.abfd = abfd;
   1233      1.1     skrll   entry.addend = addend;
   1234      1.1     skrll 
   1235      1.1     skrll   return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
   1236      1.1     skrll }
   1237      1.1     skrll 
   1238      1.1     skrll /* Merge fields set by check_relocs() of two entries that end up being
   1239      1.1     skrll    mapped to the same (presumably global) symbol.  */
   1240      1.1     skrll 
   1241      1.1     skrll inline static void
   1242      1.1     skrll frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2,
   1243      1.1     skrll 				      struct frvfdpic_relocs_info const *e1)
   1244      1.1     skrll {
   1245      1.1     skrll   e2->got12 |= e1->got12;
   1246      1.1     skrll   e2->gotlos |= e1->gotlos;
   1247      1.1     skrll   e2->gothilo |= e1->gothilo;
   1248      1.1     skrll   e2->fd |= e1->fd;
   1249      1.1     skrll   e2->fdgot12 |= e1->fdgot12;
   1250      1.1     skrll   e2->fdgotlos |= e1->fdgotlos;
   1251      1.1     skrll   e2->fdgothilo |= e1->fdgothilo;
   1252      1.1     skrll   e2->fdgoff12 |= e1->fdgoff12;
   1253      1.1     skrll   e2->fdgofflos |= e1->fdgofflos;
   1254      1.1     skrll   e2->fdgoffhilo |= e1->fdgoffhilo;
   1255      1.1     skrll   e2->tlsplt |= e1->tlsplt;
   1256      1.1     skrll   e2->tlsdesc12 |= e1->tlsdesc12;
   1257      1.1     skrll   e2->tlsdesclos |= e1->tlsdesclos;
   1258      1.1     skrll   e2->tlsdeschilo |= e1->tlsdeschilo;
   1259      1.1     skrll   e2->tlsoff12 |= e1->tlsoff12;
   1260      1.1     skrll   e2->tlsofflos |= e1->tlsofflos;
   1261      1.1     skrll   e2->tlsoffhilo |= e1->tlsoffhilo;
   1262      1.1     skrll   e2->gotoff |= e1->gotoff;
   1263      1.1     skrll   e2->call |= e1->call;
   1264      1.1     skrll   e2->sym |= e1->sym;
   1265      1.1     skrll }
   1266      1.1     skrll 
   1267      1.1     skrll /* Every block of 65535 lazy PLT entries shares a single call to the
   1268      1.1     skrll    resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
   1269      1.1     skrll    32767, counting from 0).  All other lazy PLT entries branch to it
   1270      1.1     skrll    in a single instruction.  */
   1271      1.1     skrll 
   1272      1.1     skrll #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
   1273      1.1     skrll #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
   1274      1.1     skrll 
   1275      1.1     skrll /* Add a dynamic relocation to the SRELOC section.  */
   1276      1.1     skrll 
   1277      1.1     skrll inline static bfd_vma
   1278      1.1     skrll _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
   1279      1.1     skrll 			 int reloc_type, long dynindx, bfd_vma addend,
   1280      1.1     skrll 			 struct frvfdpic_relocs_info *entry)
   1281      1.1     skrll {
   1282      1.1     skrll   Elf_Internal_Rela outrel;
   1283      1.1     skrll   bfd_vma reloc_offset;
   1284      1.1     skrll 
   1285      1.1     skrll   outrel.r_offset = offset;
   1286      1.1     skrll   outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
   1287      1.1     skrll   outrel.r_addend = addend;
   1288      1.1     skrll 
   1289      1.1     skrll   reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel);
   1290      1.1     skrll   BFD_ASSERT (reloc_offset < sreloc->size);
   1291      1.1     skrll   bfd_elf32_swap_reloc_out (output_bfd, &outrel,
   1292      1.1     skrll 			    sreloc->contents + reloc_offset);
   1293      1.1     skrll   sreloc->reloc_count++;
   1294      1.1     skrll 
   1295      1.1     skrll   /* If the entry's index is zero, this relocation was probably to a
   1296      1.1     skrll      linkonce section that got discarded.  We reserved a dynamic
   1297      1.1     skrll      relocation, but it was for another entry than the one we got at
   1298      1.1     skrll      the time of emitting the relocation.  Unfortunately there's no
   1299      1.1     skrll      simple way for us to catch this situation, since the relocation
   1300      1.1     skrll      is cleared right before calling relocate_section, at which point
   1301      1.1     skrll      we no longer know what the relocation used to point to.  */
   1302      1.1     skrll   if (entry->symndx)
   1303      1.1     skrll     {
   1304      1.1     skrll       BFD_ASSERT (entry->dynrelocs > 0);
   1305      1.1     skrll       entry->dynrelocs--;
   1306      1.1     skrll     }
   1307      1.1     skrll 
   1308      1.1     skrll   return reloc_offset;
   1309      1.1     skrll }
   1310      1.1     skrll 
   1311      1.1     skrll /* Add a fixup to the ROFIXUP section.  */
   1312      1.1     skrll 
   1313      1.1     skrll static bfd_vma
   1314      1.1     skrll _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
   1315      1.1     skrll 		       struct frvfdpic_relocs_info *entry)
   1316      1.1     skrll {
   1317      1.1     skrll   bfd_vma fixup_offset;
   1318      1.1     skrll 
   1319      1.1     skrll   if (rofixup->flags & SEC_EXCLUDE)
   1320      1.1     skrll     return -1;
   1321      1.1     skrll 
   1322      1.1     skrll   fixup_offset = rofixup->reloc_count * 4;
   1323      1.1     skrll   if (rofixup->contents)
   1324      1.1     skrll     {
   1325      1.1     skrll       BFD_ASSERT (fixup_offset < rofixup->size);
   1326      1.1     skrll       bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
   1327      1.1     skrll     }
   1328      1.1     skrll   rofixup->reloc_count++;
   1329      1.1     skrll 
   1330      1.1     skrll   if (entry && entry->symndx)
   1331      1.1     skrll     {
   1332      1.1     skrll       /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
   1333      1.1     skrll 	 above.  */
   1334      1.1     skrll       BFD_ASSERT (entry->fixups > 0);
   1335      1.1     skrll       entry->fixups--;
   1336      1.1     skrll     }
   1337      1.1     skrll 
   1338      1.1     skrll   return fixup_offset;
   1339      1.1     skrll }
   1340      1.1     skrll 
   1341      1.1     skrll /* Find the segment number in which OSEC, and output section, is
   1342      1.1     skrll    located.  */
   1343      1.1     skrll 
   1344      1.1     skrll static unsigned
   1345      1.1     skrll _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
   1346      1.1     skrll {
   1347      1.1     skrll   Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
   1348      1.1     skrll 
   1349      1.1     skrll   return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
   1350      1.1     skrll }
   1351      1.1     skrll 
   1352      1.1     skrll inline static bfd_boolean
   1353      1.1     skrll _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec)
   1354      1.1     skrll {
   1355      1.1     skrll   unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec);
   1356      1.1     skrll 
   1357      1.1     skrll   return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
   1358      1.1     skrll }
   1359      1.1     skrll 
   1360      1.1     skrll #define FRVFDPIC_TLS_BIAS (2048 - 16)
   1361      1.1     skrll 
   1362      1.1     skrll /* Return the base VMA address which should be subtracted from real addresses
   1363      1.1     skrll    when resolving TLSMOFF relocation.
   1364      1.1     skrll    This is PT_TLS segment p_vaddr, plus the 2048-16 bias.  */
   1365      1.1     skrll 
   1366      1.1     skrll static bfd_vma
   1367      1.1     skrll tls_biased_base (struct bfd_link_info *info)
   1368      1.1     skrll {
   1369      1.1     skrll   /* If tls_sec is NULL, we should have signalled an error already.  */
   1370      1.1     skrll   if (elf_hash_table (info)->tls_sec == NULL)
   1371      1.1     skrll     return FRVFDPIC_TLS_BIAS;
   1372      1.1     skrll   return elf_hash_table (info)->tls_sec->vma + FRVFDPIC_TLS_BIAS;
   1373      1.1     skrll }
   1374      1.1     skrll 
   1375      1.1     skrll /* Generate relocations for GOT entries, function descriptors, and
   1376      1.1     skrll    code for PLT and lazy PLT entries.  */
   1377      1.1     skrll 
   1378      1.1     skrll inline static bfd_boolean
   1379      1.1     skrll _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry,
   1380      1.1     skrll 				       bfd *output_bfd,
   1381      1.1     skrll 				       struct bfd_link_info *info,
   1382      1.1     skrll 				       asection *sec,
   1383      1.1     skrll 				       Elf_Internal_Sym *sym,
   1384      1.1     skrll 				       bfd_vma addend)
   1385      1.1     skrll 
   1386      1.1     skrll {
   1387      1.1     skrll   bfd_vma fd_lazy_rel_offset = (bfd_vma)-1;
   1388      1.1     skrll   int dynindx = -1;
   1389      1.1     skrll 
   1390      1.1     skrll   if (entry->done)
   1391      1.1     skrll     return TRUE;
   1392      1.1     skrll   entry->done = 1;
   1393      1.1     skrll 
   1394      1.1     skrll   if (entry->got_entry || entry->fdgot_entry || entry->fd_entry
   1395      1.1     skrll       || entry->tlsoff_entry || entry->tlsdesc_entry)
   1396      1.1     skrll     {
   1397      1.1     skrll       /* If the symbol is dynamic, consider it for dynamic
   1398      1.1     skrll 	 relocations, otherwise decay to section + offset.  */
   1399      1.1     skrll       if (entry->symndx == -1 && entry->d.h->dynindx != -1)
   1400      1.1     skrll 	dynindx = entry->d.h->dynindx;
   1401      1.1     skrll       else
   1402      1.1     skrll 	{
   1403      1.1     skrll 	  if (sec
   1404      1.1     skrll 	      && sec->output_section
   1405      1.1     skrll 	      && ! bfd_is_abs_section (sec->output_section)
   1406      1.1     skrll 	      && ! bfd_is_und_section (sec->output_section))
   1407      1.1     skrll 	    dynindx = elf_section_data (sec->output_section)->dynindx;
   1408      1.1     skrll 	  else
   1409      1.1     skrll 	    dynindx = 0;
   1410      1.1     skrll 	}
   1411      1.1     skrll     }
   1412      1.1     skrll 
   1413      1.1     skrll   /* Generate relocation for GOT entry pointing to the symbol.  */
   1414      1.1     skrll   if (entry->got_entry)
   1415      1.1     skrll     {
   1416      1.1     skrll       int idx = dynindx;
   1417      1.1     skrll       bfd_vma ad = addend;
   1418      1.1     skrll 
   1419      1.1     skrll       /* If the symbol is dynamic but binds locally, use
   1420      1.1     skrll 	 section+offset.  */
   1421      1.1     skrll       if (sec && (entry->symndx != -1
   1422      1.1     skrll 		  || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
   1423      1.1     skrll 	{
   1424      1.1     skrll 	  if (entry->symndx == -1)
   1425      1.1     skrll 	    ad += entry->d.h->root.u.def.value;
   1426      1.1     skrll 	  else
   1427      1.1     skrll 	    ad += sym->st_value;
   1428      1.1     skrll 	  ad += sec->output_offset;
   1429      1.1     skrll 	  if (sec->output_section && elf_section_data (sec->output_section))
   1430      1.1     skrll 	    idx = elf_section_data (sec->output_section)->dynindx;
   1431      1.1     skrll 	  else
   1432      1.1     skrll 	    idx = 0;
   1433      1.1     skrll 	}
   1434      1.1     skrll 
   1435      1.1     skrll       /* If we're linking an executable at a fixed address, we can
   1436      1.1     skrll 	 omit the dynamic relocation as long as the symbol is local to
   1437      1.1     skrll 	 this module.  */
   1438      1.1     skrll       if (info->executable && !info->pie
   1439      1.1     skrll 	  && (entry->symndx != -1
   1440      1.1     skrll 	      || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
   1441      1.1     skrll 	{
   1442      1.1     skrll 	  if (sec)
   1443      1.1     skrll 	    ad += sec->output_section->vma;
   1444      1.1     skrll 	  if (entry->symndx != -1
   1445      1.1     skrll 	      || entry->d.h->root.type != bfd_link_hash_undefweak)
   1446      1.1     skrll 	    _frvfdpic_add_rofixup (output_bfd,
   1447      1.1     skrll 				   frvfdpic_gotfixup_section (info),
   1448      1.1     skrll 				   frvfdpic_got_section (info)->output_section
   1449      1.1     skrll 				   ->vma
   1450      1.1     skrll 				   + frvfdpic_got_section (info)->output_offset
   1451      1.1     skrll 				   + frvfdpic_got_initial_offset (info)
   1452      1.1     skrll 				   + entry->got_entry, entry);
   1453      1.1     skrll 	}
   1454      1.1     skrll       else
   1455      1.1     skrll 	_frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
   1456      1.1     skrll 				 _bfd_elf_section_offset
   1457      1.1     skrll 				 (output_bfd, info,
   1458      1.1     skrll 				  frvfdpic_got_section (info),
   1459      1.1     skrll 				  frvfdpic_got_initial_offset (info)
   1460      1.1     skrll 				  + entry->got_entry)
   1461      1.1     skrll 				 + frvfdpic_got_section (info)
   1462      1.1     skrll 				 ->output_section->vma
   1463      1.1     skrll 				 + frvfdpic_got_section (info)->output_offset,
   1464      1.1     skrll 				 R_FRV_32, idx, ad, entry);
   1465      1.1     skrll 
   1466      1.1     skrll       bfd_put_32 (output_bfd, ad,
   1467      1.1     skrll 		  frvfdpic_got_section (info)->contents
   1468      1.1     skrll 		  + frvfdpic_got_initial_offset (info)
   1469      1.1     skrll 		  + entry->got_entry);
   1470      1.1     skrll     }
   1471      1.1     skrll 
   1472      1.1     skrll   /* Generate relocation for GOT entry pointing to a canonical
   1473      1.1     skrll      function descriptor.  */
   1474      1.1     skrll   if (entry->fdgot_entry)
   1475      1.1     skrll     {
   1476      1.1     skrll       int reloc, idx;
   1477      1.1     skrll       bfd_vma ad = 0;
   1478      1.1     skrll 
   1479      1.1     skrll       if (! (entry->symndx == -1
   1480      1.1     skrll 	     && entry->d.h->root.type == bfd_link_hash_undefweak
   1481      1.1     skrll 	     && FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
   1482      1.1     skrll 	{
   1483      1.1     skrll 	  /* If the symbol is dynamic and there may be dynamic symbol
   1484      1.1     skrll 	     resolution because we are, or are linked with, a shared
   1485      1.1     skrll 	     library, emit a FUNCDESC relocation such that the dynamic
   1486      1.1     skrll 	     linker will allocate the function descriptor.  If the
   1487      1.1     skrll 	     symbol needs a non-local function descriptor but binds
   1488      1.1     skrll 	     locally (e.g., its visibility is protected, emit a
   1489      1.1     skrll 	     dynamic relocation decayed to section+offset.  */
   1490      1.1     skrll 	  if (entry->symndx == -1
   1491      1.1     skrll 	      && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)
   1492      1.1     skrll 	      && FRVFDPIC_SYM_LOCAL (info, entry->d.h)
   1493      1.1     skrll 	      && !(info->executable && !info->pie))
   1494      1.1     skrll 	    {
   1495      1.1     skrll 	      reloc = R_FRV_FUNCDESC;
   1496      1.1     skrll 	      idx = elf_section_data (entry->d.h->root.u.def.section
   1497      1.1     skrll 				      ->output_section)->dynindx;
   1498      1.1     skrll 	      ad = entry->d.h->root.u.def.section->output_offset
   1499      1.1     skrll 		+ entry->d.h->root.u.def.value;
   1500      1.1     skrll 	    }
   1501      1.1     skrll 	  else if (entry->symndx == -1
   1502      1.1     skrll 		   && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))
   1503      1.1     skrll 	    {
   1504      1.1     skrll 	      reloc = R_FRV_FUNCDESC;
   1505      1.1     skrll 	      idx = dynindx;
   1506      1.1     skrll 	      ad = addend;
   1507      1.1     skrll 	      if (ad)
   1508      1.1     skrll 		{
   1509      1.1     skrll 		  (*info->callbacks->reloc_dangerous)
   1510      1.1     skrll 		    (info, _("relocation requires zero addend"),
   1511      1.1     skrll 		     elf_hash_table (info)->dynobj,
   1512      1.1     skrll 		     frvfdpic_got_section (info),
   1513      1.1     skrll 		     entry->fdgot_entry);
   1514      1.1     skrll 		  return FALSE;
   1515      1.1     skrll 		}
   1516      1.1     skrll 	    }
   1517      1.1     skrll 	  else
   1518      1.1     skrll 	    {
   1519      1.1     skrll 	      /* Otherwise, we know we have a private function descriptor,
   1520      1.1     skrll 		 so reference it directly.  */
   1521      1.1     skrll 	      if (elf_hash_table (info)->dynamic_sections_created)
   1522      1.1     skrll 		BFD_ASSERT (entry->privfd);
   1523      1.1     skrll 	      reloc = R_FRV_32;
   1524      1.1     skrll 	      idx = elf_section_data (frvfdpic_got_section (info)
   1525      1.1     skrll 				      ->output_section)->dynindx;
   1526      1.1     skrll 	      ad = frvfdpic_got_section (info)->output_offset
   1527      1.1     skrll 		+ frvfdpic_got_initial_offset (info) + entry->fd_entry;
   1528      1.1     skrll 	    }
   1529      1.1     skrll 
   1530      1.1     skrll 	  /* If there is room for dynamic symbol resolution, emit the
   1531      1.1     skrll 	     dynamic relocation.  However, if we're linking an
   1532      1.1     skrll 	     executable at a fixed location, we won't have emitted a
   1533      1.1     skrll 	     dynamic symbol entry for the got section, so idx will be
   1534      1.1     skrll 	     zero, which means we can and should compute the address
   1535      1.1     skrll 	     of the private descriptor ourselves.  */
   1536      1.1     skrll 	  if (info->executable && !info->pie
   1537      1.1     skrll 	      && (entry->symndx != -1
   1538      1.1     skrll 		  || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)))
   1539      1.1     skrll 	    {
   1540      1.1     skrll 	      ad += frvfdpic_got_section (info)->output_section->vma;
   1541      1.1     skrll 	      _frvfdpic_add_rofixup (output_bfd,
   1542      1.1     skrll 				     frvfdpic_gotfixup_section (info),
   1543      1.1     skrll 				     frvfdpic_got_section (info)
   1544      1.1     skrll 				     ->output_section->vma
   1545      1.1     skrll 				     + frvfdpic_got_section (info)
   1546      1.1     skrll 				     ->output_offset
   1547      1.1     skrll 				     + frvfdpic_got_initial_offset (info)
   1548      1.1     skrll 				     + entry->fdgot_entry, entry);
   1549      1.1     skrll 	    }
   1550      1.1     skrll 	  else
   1551      1.1     skrll 	    _frvfdpic_add_dyn_reloc (output_bfd,
   1552      1.1     skrll 				     frvfdpic_gotrel_section (info),
   1553      1.1     skrll 				     _bfd_elf_section_offset
   1554      1.1     skrll 				     (output_bfd, info,
   1555      1.1     skrll 				      frvfdpic_got_section (info),
   1556      1.1     skrll 				      frvfdpic_got_initial_offset (info)
   1557      1.1     skrll 				      + entry->fdgot_entry)
   1558      1.1     skrll 				     + frvfdpic_got_section (info)
   1559      1.1     skrll 				     ->output_section->vma
   1560      1.1     skrll 				     + frvfdpic_got_section (info)
   1561      1.1     skrll 				     ->output_offset,
   1562      1.1     skrll 				     reloc, idx, ad, entry);
   1563      1.1     skrll 	}
   1564      1.1     skrll 
   1565      1.1     skrll       bfd_put_32 (output_bfd, ad,
   1566      1.1     skrll 		  frvfdpic_got_section (info)->contents
   1567      1.1     skrll 		  + frvfdpic_got_initial_offset (info)
   1568      1.1     skrll 		  + entry->fdgot_entry);
   1569      1.1     skrll     }
   1570      1.1     skrll 
   1571      1.1     skrll   /* Generate relocation to fill in a private function descriptor in
   1572      1.1     skrll      the GOT.  */
   1573      1.1     skrll   if (entry->fd_entry)
   1574      1.1     skrll     {
   1575      1.1     skrll       int idx = dynindx;
   1576      1.1     skrll       bfd_vma ad = addend;
   1577      1.1     skrll       bfd_vma ofst;
   1578      1.1     skrll       long lowword, highword;
   1579      1.1     skrll 
   1580      1.1     skrll       /* If the symbol is dynamic but binds locally, use
   1581      1.1     skrll 	 section+offset.  */
   1582      1.1     skrll       if (sec && (entry->symndx != -1
   1583      1.1     skrll 		  || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
   1584      1.1     skrll 	{
   1585      1.1     skrll 	  if (entry->symndx == -1)
   1586      1.1     skrll 	    ad += entry->d.h->root.u.def.value;
   1587      1.1     skrll 	  else
   1588      1.1     skrll 	    ad += sym->st_value;
   1589      1.1     skrll 	  ad += sec->output_offset;
   1590      1.1     skrll 	  if (sec->output_section && elf_section_data (sec->output_section))
   1591      1.1     skrll 	    idx = elf_section_data (sec->output_section)->dynindx;
   1592      1.1     skrll 	  else
   1593      1.1     skrll 	    idx = 0;
   1594      1.1     skrll 	}
   1595      1.1     skrll 
   1596      1.1     skrll       /* If we're linking an executable at a fixed address, we can
   1597      1.1     skrll 	 omit the dynamic relocation as long as the symbol is local to
   1598      1.1     skrll 	 this module.  */
   1599      1.1     skrll       if (info->executable && !info->pie
   1600      1.1     skrll 	  && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
   1601      1.1     skrll 	{
   1602      1.1     skrll 	  if (sec)
   1603      1.1     skrll 	    ad += sec->output_section->vma;
   1604      1.1     skrll 	  ofst = 0;
   1605      1.1     skrll 	  if (entry->symndx != -1
   1606      1.1     skrll 	      || entry->d.h->root.type != bfd_link_hash_undefweak)
   1607      1.1     skrll 	    {
   1608      1.1     skrll 	      _frvfdpic_add_rofixup (output_bfd,
   1609      1.1     skrll 				     frvfdpic_gotfixup_section (info),
   1610      1.1     skrll 				     frvfdpic_got_section (info)
   1611      1.1     skrll 				     ->output_section->vma
   1612      1.1     skrll 				     + frvfdpic_got_section (info)
   1613      1.1     skrll 				     ->output_offset
   1614      1.1     skrll 				     + frvfdpic_got_initial_offset (info)
   1615      1.1     skrll 				     + entry->fd_entry, entry);
   1616      1.1     skrll 	      _frvfdpic_add_rofixup (output_bfd,
   1617      1.1     skrll 				     frvfdpic_gotfixup_section (info),
   1618      1.1     skrll 				     frvfdpic_got_section (info)
   1619      1.1     skrll 				     ->output_section->vma
   1620      1.1     skrll 				     + frvfdpic_got_section (info)
   1621      1.1     skrll 				     ->output_offset
   1622      1.1     skrll 				     + frvfdpic_got_initial_offset (info)
   1623      1.1     skrll 				     + entry->fd_entry + 4, entry);
   1624      1.1     skrll 	    }
   1625      1.1     skrll 	}
   1626      1.1     skrll       else
   1627      1.1     skrll 	{
   1628      1.1     skrll 	  ofst =
   1629      1.1     skrll 	    _frvfdpic_add_dyn_reloc (output_bfd,
   1630      1.1     skrll 				     entry->lazyplt
   1631      1.1     skrll 				     ? frvfdpic_pltrel_section (info)
   1632      1.1     skrll 				     : frvfdpic_gotrel_section (info),
   1633      1.1     skrll 				     _bfd_elf_section_offset
   1634      1.1     skrll 				     (output_bfd, info,
   1635      1.1     skrll 				      frvfdpic_got_section (info),
   1636      1.1     skrll 				      frvfdpic_got_initial_offset (info)
   1637      1.1     skrll 				      + entry->fd_entry)
   1638      1.1     skrll 				     + frvfdpic_got_section (info)
   1639      1.1     skrll 				     ->output_section->vma
   1640      1.1     skrll 				     + frvfdpic_got_section (info)
   1641      1.1     skrll 				     ->output_offset,
   1642      1.1     skrll 				     R_FRV_FUNCDESC_VALUE, idx, ad, entry);
   1643      1.1     skrll 	}
   1644      1.1     skrll 
   1645      1.1     skrll       /* If we've omitted the dynamic relocation, just emit the fixed
   1646      1.1     skrll 	 addresses of the symbol and of the local GOT base offset.  */
   1647      1.1     skrll       if (info->executable && !info->pie && sec && sec->output_section)
   1648      1.1     skrll 	{
   1649      1.1     skrll 	  lowword = ad;
   1650      1.1     skrll 	  highword = frvfdpic_got_section (info)->output_section->vma
   1651      1.1     skrll 	    + frvfdpic_got_section (info)->output_offset
   1652      1.1     skrll 	    + frvfdpic_got_initial_offset (info);
   1653      1.1     skrll 	}
   1654      1.1     skrll       else if (entry->lazyplt)
   1655      1.1     skrll 	{
   1656      1.1     skrll 	  if (ad)
   1657      1.1     skrll 	    {
   1658      1.1     skrll 	      (*info->callbacks->reloc_dangerous)
   1659      1.1     skrll 		(info, _("relocation requires zero addend"),
   1660      1.1     skrll 		 elf_hash_table (info)->dynobj,
   1661      1.1     skrll 		 frvfdpic_got_section (info),
   1662      1.1     skrll 		 entry->fd_entry);
   1663      1.1     skrll 	      return FALSE;
   1664      1.1     skrll 	    }
   1665      1.1     skrll 
   1666      1.1     skrll 	  fd_lazy_rel_offset = ofst;
   1667      1.1     skrll 
   1668      1.1     skrll 	  /* A function descriptor used for lazy or local resolving is
   1669      1.1     skrll 	     initialized such that its high word contains the output
   1670      1.1     skrll 	     section index in which the PLT entries are located, and
   1671      1.1     skrll 	     the low word contains the address of the lazy PLT entry
   1672      1.1     skrll 	     entry point, that must be within the memory region
   1673      1.1     skrll 	     assigned to that section.  */
   1674      1.1     skrll 	  lowword = entry->lzplt_entry + 4
   1675      1.1     skrll 	    + frvfdpic_plt_section (info)->output_offset
   1676      1.1     skrll 	    + frvfdpic_plt_section (info)->output_section->vma;
   1677      1.1     skrll 	  highword = _frvfdpic_osec_to_segment
   1678      1.1     skrll 	    (output_bfd, frvfdpic_plt_section (info)->output_section);
   1679      1.1     skrll 	}
   1680      1.1     skrll       else
   1681      1.1     skrll 	{
   1682      1.1     skrll 	  /* A function descriptor for a local function gets the index
   1683      1.1     skrll 	     of the section.  For a non-local function, it's
   1684      1.1     skrll 	     disregarded.  */
   1685      1.1     skrll 	  lowword = ad;
   1686      1.1     skrll 	  if (sec == NULL
   1687      1.1     skrll 	      || (entry->symndx == -1 && entry->d.h->dynindx != -1
   1688      1.1     skrll 		  && entry->d.h->dynindx == idx))
   1689      1.1     skrll 	    highword = 0;
   1690      1.1     skrll 	  else
   1691      1.1     skrll 	    highword = _frvfdpic_osec_to_segment
   1692      1.1     skrll 	      (output_bfd, sec->output_section);
   1693      1.1     skrll 	}
   1694      1.1     skrll 
   1695      1.1     skrll       bfd_put_32 (output_bfd, lowword,
   1696      1.1     skrll 		  frvfdpic_got_section (info)->contents
   1697      1.1     skrll 		  + frvfdpic_got_initial_offset (info)
   1698      1.1     skrll 		  + entry->fd_entry);
   1699      1.1     skrll       bfd_put_32 (output_bfd, highword,
   1700      1.1     skrll 		  frvfdpic_got_section (info)->contents
   1701      1.1     skrll 		  + frvfdpic_got_initial_offset (info)
   1702      1.1     skrll 		  + entry->fd_entry + 4);
   1703      1.1     skrll     }
   1704      1.1     skrll 
   1705      1.1     skrll   /* Generate code for the PLT entry.  */
   1706      1.1     skrll   if (entry->plt_entry != (bfd_vma) -1)
   1707      1.1     skrll     {
   1708      1.1     skrll       bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
   1709      1.1     skrll 	+ entry->plt_entry;
   1710      1.1     skrll 
   1711      1.1     skrll       BFD_ASSERT (entry->fd_entry);
   1712      1.1     skrll 
   1713      1.1     skrll       /* Figure out what kind of PLT entry we need, depending on the
   1714      1.1     skrll 	 location of the function descriptor within the GOT.  */
   1715      1.1     skrll       if (entry->fd_entry >= -(1 << (12 - 1))
   1716      1.1     skrll 	  && entry->fd_entry < (1 << (12 - 1)))
   1717      1.1     skrll 	{
   1718      1.1     skrll 	  /* lddi @(gr15, fd_entry), gr14 */
   1719      1.1     skrll 	  bfd_put_32 (output_bfd,
   1720      1.1     skrll 		      0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)),
   1721      1.1     skrll 		      plt_code);
   1722      1.1     skrll 	  plt_code += 4;
   1723      1.1     skrll 	}
   1724      1.1     skrll       else
   1725      1.1     skrll 	{
   1726      1.1     skrll 	  if (entry->fd_entry >= -(1 << (16 - 1))
   1727      1.1     skrll 	      && entry->fd_entry < (1 << (16 - 1)))
   1728      1.1     skrll 	    {
   1729      1.1     skrll 	      /* setlos lo(fd_entry), gr14 */
   1730      1.1     skrll 	      bfd_put_32 (output_bfd,
   1731      1.1     skrll 			  0x9cfc0000
   1732      1.1     skrll 			  | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
   1733      1.1     skrll 			  plt_code);
   1734      1.1     skrll 	      plt_code += 4;
   1735      1.1     skrll 	    }
   1736      1.1     skrll 	  else
   1737      1.1     skrll 	    {
   1738      1.1     skrll 	      /* sethi.p hi(fd_entry), gr14
   1739      1.1     skrll 		 setlo lo(fd_entry), gr14 */
   1740      1.1     skrll 	      bfd_put_32 (output_bfd,
   1741      1.1     skrll 			  0x1cf80000
   1742      1.1     skrll 			  | ((entry->fd_entry >> 16)
   1743      1.1     skrll 			     & (((bfd_vma)1 << 16) - 1)),
   1744      1.1     skrll 			  plt_code);
   1745      1.1     skrll 	      plt_code += 4;
   1746      1.1     skrll 	      bfd_put_32 (output_bfd,
   1747      1.1     skrll 			  0x9cf40000
   1748      1.1     skrll 			  | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
   1749      1.1     skrll 			  plt_code);
   1750      1.1     skrll 	      plt_code += 4;
   1751      1.1     skrll 	    }
   1752      1.1     skrll 	  /* ldd @(gr14,gr15),gr14 */
   1753      1.1     skrll 	  bfd_put_32 (output_bfd, 0x9c08e14f, plt_code);
   1754      1.1     skrll 	  plt_code += 4;
   1755      1.1     skrll 	}
   1756      1.1     skrll       /* jmpl @(gr14,gr0) */
   1757      1.1     skrll       bfd_put_32 (output_bfd, 0x8030e000, plt_code);
   1758      1.1     skrll     }
   1759      1.1     skrll 
   1760      1.1     skrll   /* Generate code for the lazy PLT entry.  */
   1761      1.1     skrll   if (entry->lzplt_entry != (bfd_vma) -1)
   1762      1.1     skrll     {
   1763      1.1     skrll       bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents
   1764      1.1     skrll 	+ entry->lzplt_entry;
   1765      1.1     skrll       bfd_vma resolverStub_addr;
   1766      1.1     skrll 
   1767      1.1     skrll       bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
   1768      1.1     skrll       lzplt_code += 4;
   1769      1.1     skrll 
   1770      1.1     skrll       resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE
   1771      1.1     skrll 	* FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC;
   1772      1.1     skrll       if (resolverStub_addr >= frvfdpic_plt_initial_offset (info))
   1773      1.1     skrll 	resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12;
   1774      1.1     skrll 
   1775      1.1     skrll       if (entry->lzplt_entry == resolverStub_addr)
   1776      1.1     skrll 	{
   1777      1.1     skrll 	  /* This is a lazy PLT entry that includes a resolver call.  */
   1778      1.1     skrll 	  /* ldd @(gr15,gr0), gr4
   1779      1.1     skrll 	     jmpl @(gr4,gr0)  */
   1780      1.1     skrll 	  bfd_put_32 (output_bfd, 0x8808f140, lzplt_code);
   1781      1.1     skrll 	  bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4);
   1782      1.1     skrll 	}
   1783      1.1     skrll       else
   1784      1.1     skrll 	{
   1785      1.1     skrll 	  /* bra  resolverStub */
   1786      1.1     skrll 	  bfd_put_32 (output_bfd,
   1787      1.1     skrll 		      0xc01a0000
   1788      1.1     skrll 		      | (((resolverStub_addr - entry->lzplt_entry)
   1789      1.1     skrll 			  / 4) & (((bfd_vma)1 << 16) - 1)),
   1790      1.1     skrll 		      lzplt_code);
   1791      1.1     skrll 	}
   1792      1.1     skrll     }
   1793      1.1     skrll 
   1794      1.1     skrll   /* Generate relocation for GOT entry holding the TLS offset.  */
   1795      1.1     skrll   if (entry->tlsoff_entry)
   1796      1.1     skrll     {
   1797      1.1     skrll       int idx = dynindx;
   1798      1.1     skrll       bfd_vma ad = addend;
   1799      1.1     skrll 
   1800      1.1     skrll       if (entry->symndx != -1
   1801      1.1     skrll 	  || FRVFDPIC_SYM_LOCAL (info, entry->d.h))
   1802      1.1     skrll 	{
   1803      1.1     skrll 	  /* If the symbol is dynamic but binds locally, use
   1804      1.1     skrll 	     section+offset.  */
   1805      1.1     skrll 	  if (sec)
   1806      1.1     skrll 	    {
   1807      1.1     skrll 	      if (entry->symndx == -1)
   1808      1.1     skrll 		ad += entry->d.h->root.u.def.value;
   1809      1.1     skrll 	      else
   1810      1.1     skrll 		ad += sym->st_value;
   1811      1.1     skrll 	      ad += sec->output_offset;
   1812      1.1     skrll 	      if (sec->output_section
   1813      1.1     skrll 		  && elf_section_data (sec->output_section))
   1814      1.1     skrll 		idx = elf_section_data (sec->output_section)->dynindx;
   1815      1.1     skrll 	      else
   1816      1.1     skrll 		idx = 0;
   1817      1.1     skrll 	    }
   1818      1.1     skrll 	}
   1819      1.1     skrll 
   1820      1.1     skrll       /* *ABS*+addend is special for TLS relocations, use only the
   1821      1.1     skrll 	 addend.  */
   1822      1.1     skrll       if (info->executable
   1823      1.1     skrll 	  && idx == 0
   1824      1.1     skrll 	  && (bfd_is_abs_section (sec)
   1825      1.1     skrll 	      || bfd_is_und_section (sec)))
   1826      1.1     skrll 	;
   1827      1.1     skrll       /* If we're linking an executable, we can entirely omit the
   1828      1.1     skrll 	 dynamic relocation if the symbol is local to this module.  */
   1829      1.1     skrll       else if (info->executable
   1830      1.1     skrll 	       && (entry->symndx != -1
   1831      1.1     skrll 		   || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
   1832      1.1     skrll 	{
   1833      1.1     skrll 	  if (sec)
   1834      1.1     skrll 	    ad += sec->output_section->vma - tls_biased_base (info);
   1835      1.1     skrll 	}
   1836      1.1     skrll       else
   1837      1.1     skrll 	{
   1838      1.1     skrll 	  if (idx == 0
   1839      1.1     skrll 	      && (bfd_is_abs_section (sec)
   1840      1.1     skrll 		  || bfd_is_und_section (sec)))
   1841      1.1     skrll 	    {
   1842      1.1     skrll 	      if (! elf_hash_table (info)->tls_sec)
   1843      1.1     skrll 		{
   1844      1.1     skrll 		  (*info->callbacks->undefined_symbol)
   1845      1.1     skrll 		    (info, "TLS section", elf_hash_table (info)->dynobj,
   1846      1.1     skrll 		     frvfdpic_got_section (info), entry->tlsoff_entry, TRUE);
   1847      1.1     skrll 		  return FALSE;
   1848      1.1     skrll 		}
   1849      1.1     skrll 	      idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
   1850      1.1     skrll 	      ad += FRVFDPIC_TLS_BIAS;
   1851      1.1     skrll 	    }
   1852      1.1     skrll 	  _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
   1853      1.1     skrll 				   _bfd_elf_section_offset
   1854      1.1     skrll 				   (output_bfd, info,
   1855      1.1     skrll 				    frvfdpic_got_section (info),
   1856      1.1     skrll 				    frvfdpic_got_initial_offset (info)
   1857      1.1     skrll 				    + entry->tlsoff_entry)
   1858      1.1     skrll 				   + frvfdpic_got_section (info)
   1859      1.1     skrll 				   ->output_section->vma
   1860      1.1     skrll 				   + frvfdpic_got_section (info)
   1861      1.1     skrll 				   ->output_offset,
   1862      1.1     skrll 				   R_FRV_TLSOFF, idx, ad, entry);
   1863      1.1     skrll 	}
   1864      1.1     skrll 
   1865      1.1     skrll       bfd_put_32 (output_bfd, ad,
   1866      1.1     skrll 		  frvfdpic_got_section (info)->contents
   1867      1.1     skrll 		  + frvfdpic_got_initial_offset (info)
   1868      1.1     skrll 		  + entry->tlsoff_entry);
   1869      1.1     skrll     }
   1870      1.1     skrll 
   1871      1.1     skrll   if (entry->tlsdesc_entry)
   1872      1.1     skrll     {
   1873      1.1     skrll       int idx = dynindx;
   1874      1.1     skrll       bfd_vma ad = addend;
   1875      1.1     skrll 
   1876      1.1     skrll       /* If the symbol is dynamic but binds locally, use
   1877      1.1     skrll 	 section+offset.  */
   1878      1.1     skrll       if (sec && (entry->symndx != -1
   1879      1.1     skrll 		  || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
   1880      1.1     skrll 	{
   1881      1.1     skrll 	  if (entry->symndx == -1)
   1882      1.1     skrll 	    ad += entry->d.h->root.u.def.value;
   1883      1.1     skrll 	  else
   1884      1.1     skrll 	    ad += sym->st_value;
   1885      1.1     skrll 	  ad += sec->output_offset;
   1886      1.1     skrll 	  if (sec->output_section && elf_section_data (sec->output_section))
   1887      1.1     skrll 	    idx = elf_section_data (sec->output_section)->dynindx;
   1888      1.1     skrll 	  else
   1889      1.1     skrll 	    idx = 0;
   1890      1.1     skrll 	}
   1891      1.1     skrll 
   1892      1.1     skrll       /* If we didn't set up a TLS offset entry, but we're linking an
   1893      1.1     skrll 	 executable and the symbol binds locally, we can use the
   1894      1.1     skrll 	 module offset in the TLS descriptor in relaxations.  */
   1895      1.1     skrll       if (info->executable && ! entry->tlsoff_entry)
   1896      1.1     skrll 	entry->tlsoff_entry = entry->tlsdesc_entry + 4;
   1897      1.1     skrll 
   1898      1.1     skrll       if (info->executable && !info->pie
   1899      1.1     skrll 	  && ((idx == 0
   1900      1.1     skrll 	       && (bfd_is_abs_section (sec)
   1901      1.1     skrll 		   || bfd_is_und_section (sec)))
   1902      1.1     skrll 	      || entry->symndx != -1
   1903      1.1     skrll 	      || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
   1904      1.1     skrll 	{
   1905      1.1     skrll 	  /* *ABS*+addend is special for TLS relocations, use only the
   1906      1.1     skrll 	     addend for the TLS offset, and take the module id as
   1907      1.1     skrll 	     0.  */
   1908      1.1     skrll 	  if (idx == 0
   1909      1.1     skrll 	      && (bfd_is_abs_section (sec)
   1910      1.1     skrll 		  || bfd_is_und_section (sec)))
   1911      1.1     skrll 	    ;
   1912      1.1     skrll 	  /* For other TLS symbols that bind locally, add the section
   1913      1.1     skrll 	     TLS offset to the addend.  */
   1914      1.1     skrll 	  else if (sec)
   1915      1.1     skrll 	    ad += sec->output_section->vma - tls_biased_base (info);
   1916      1.1     skrll 
   1917      1.1     skrll 	  bfd_put_32 (output_bfd,
   1918      1.1     skrll 		      frvfdpic_plt_section (info)->output_section->vma
   1919      1.1     skrll 		      + frvfdpic_plt_section (info)->output_offset
   1920      1.1     skrll 		      + frvfdpic_plt_tls_ret_offset (info),
   1921      1.1     skrll 		      frvfdpic_got_section (info)->contents
   1922      1.1     skrll 		      + frvfdpic_got_initial_offset (info)
   1923      1.1     skrll 		      + entry->tlsdesc_entry);
   1924      1.1     skrll 
   1925      1.1     skrll 	  _frvfdpic_add_rofixup (output_bfd,
   1926      1.1     skrll 				 frvfdpic_gotfixup_section (info),
   1927      1.1     skrll 				 frvfdpic_got_section (info)
   1928      1.1     skrll 				 ->output_section->vma
   1929      1.1     skrll 				 + frvfdpic_got_section (info)
   1930      1.1     skrll 				 ->output_offset
   1931      1.1     skrll 				 + frvfdpic_got_initial_offset (info)
   1932      1.1     skrll 				 + entry->tlsdesc_entry, entry);
   1933      1.1     skrll 
   1934      1.1     skrll 	  BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs);
   1935      1.1     skrll 
   1936      1.1     skrll 	  /* We've used one of the reserved fixups, so discount it so
   1937      1.1     skrll 	     that we can check at the end that we've used them
   1938      1.1     skrll 	     all.  */
   1939      1.1     skrll 	  frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs--;
   1940      1.1     skrll 
   1941      1.1     skrll 	  /* While at that, make sure the ret instruction makes to the
   1942      1.1     skrll 	     right location in the PLT.  We could do it only when we
   1943      1.1     skrll 	     got to 0, but since the check at the end will only print
   1944      1.1     skrll 	     a warning, make sure we have the ret in place in case the
   1945      1.1     skrll 	     warning is missed.  */
   1946      1.1     skrll 	  bfd_put_32 (output_bfd, 0xc03a4000,
   1947      1.1     skrll 		      frvfdpic_plt_section (info)->contents
   1948      1.1     skrll 		      + frvfdpic_plt_tls_ret_offset (info));
   1949      1.1     skrll 	}
   1950      1.1     skrll       else
   1951      1.1     skrll 	{
   1952      1.1     skrll 	  if (idx == 0
   1953      1.1     skrll 	      && (bfd_is_abs_section (sec)
   1954      1.1     skrll 		  || bfd_is_und_section (sec)))
   1955      1.1     skrll 	    {
   1956      1.1     skrll 	      if (! elf_hash_table (info)->tls_sec)
   1957      1.1     skrll 		{
   1958      1.1     skrll 		  (*info->callbacks->undefined_symbol)
   1959      1.1     skrll 		    (info, "TLS section", elf_hash_table (info)->dynobj,
   1960      1.1     skrll 		     frvfdpic_got_section (info), entry->tlsdesc_entry, TRUE);
   1961      1.1     skrll 		  return FALSE;
   1962      1.1     skrll 		}
   1963      1.1     skrll 	      idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
   1964      1.1     skrll 	      ad += FRVFDPIC_TLS_BIAS;
   1965      1.1     skrll 	    }
   1966      1.1     skrll 
   1967      1.1     skrll 	  _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
   1968      1.1     skrll 				   _bfd_elf_section_offset
   1969      1.1     skrll 				   (output_bfd, info,
   1970      1.1     skrll 				    frvfdpic_got_section (info),
   1971      1.1     skrll 				    frvfdpic_got_initial_offset (info)
   1972      1.1     skrll 				    + entry->tlsdesc_entry)
   1973      1.1     skrll 				   + frvfdpic_got_section (info)
   1974      1.1     skrll 				   ->output_section->vma
   1975      1.1     skrll 				   + frvfdpic_got_section (info)
   1976      1.1     skrll 				   ->output_offset,
   1977      1.1     skrll 				   R_FRV_TLSDESC_VALUE, idx, ad, entry);
   1978      1.1     skrll 
   1979      1.1     skrll 	  bfd_put_32 (output_bfd, 0,
   1980      1.1     skrll 		      frvfdpic_got_section (info)->contents
   1981      1.1     skrll 		      + frvfdpic_got_initial_offset (info)
   1982      1.1     skrll 		      + entry->tlsdesc_entry);
   1983      1.1     skrll 	}
   1984      1.1     skrll 
   1985      1.1     skrll       bfd_put_32 (output_bfd, ad,
   1986      1.1     skrll 		  frvfdpic_got_section (info)->contents
   1987      1.1     skrll 		  + frvfdpic_got_initial_offset (info)
   1988      1.1     skrll 		  + entry->tlsdesc_entry + 4);
   1989      1.1     skrll     }
   1990      1.1     skrll 
   1991      1.1     skrll   /* Generate code for the get-TLS-offset PLT entry.  */
   1992      1.1     skrll   if (entry->tlsplt_entry != (bfd_vma) -1)
   1993      1.1     skrll     {
   1994      1.1     skrll       bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
   1995      1.1     skrll 	+ entry->tlsplt_entry;
   1996      1.1     skrll 
   1997      1.1     skrll       if (info->executable
   1998      1.1     skrll 	  && (entry->symndx != -1
   1999      1.1     skrll 	      || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
   2000      1.1     skrll 	{
   2001      1.1     skrll 	  int idx = dynindx;
   2002      1.1     skrll 	  bfd_vma ad = addend;
   2003      1.1     skrll 
   2004      1.1     skrll 	  /* sec may be NULL when referencing an undefweak symbol
   2005      1.1     skrll 	     while linking a static executable.  */
   2006      1.1     skrll 	  if (!sec)
   2007      1.1     skrll 	    {
   2008      1.1     skrll 	      BFD_ASSERT (entry->symndx == -1
   2009      1.1     skrll 			  && entry->d.h->root.type == bfd_link_hash_undefweak);
   2010      1.1     skrll 	    }
   2011      1.1     skrll 	  else
   2012      1.1     skrll 	    {
   2013      1.1     skrll 	      if (entry->symndx == -1)
   2014      1.1     skrll 		ad += entry->d.h->root.u.def.value;
   2015      1.1     skrll 	      else
   2016      1.1     skrll 		ad += sym->st_value;
   2017      1.1     skrll 	      ad += sec->output_offset;
   2018      1.1     skrll 	      if (sec->output_section
   2019      1.1     skrll 		  && elf_section_data (sec->output_section))
   2020      1.1     skrll 		idx = elf_section_data (sec->output_section)->dynindx;
   2021      1.1     skrll 	      else
   2022      1.1     skrll 		idx = 0;
   2023      1.1     skrll 	    }
   2024      1.1     skrll 
   2025      1.1     skrll 	  /* *ABS*+addend is special for TLS relocations, use only the
   2026      1.1     skrll 	     addend for the TLS offset, and take the module id as
   2027      1.1     skrll 	     0.  */
   2028      1.1     skrll 	  if (idx == 0
   2029      1.1     skrll 	      && (bfd_is_abs_section (sec)
   2030      1.1     skrll 		  || bfd_is_und_section (sec)))
   2031      1.1     skrll 	    ;
   2032      1.1     skrll 	  /* For other TLS symbols that bind locally, add the section
   2033      1.1     skrll 	     TLS offset to the addend.  */
   2034      1.1     skrll 	  else if (sec)
   2035      1.1     skrll 	    ad += sec->output_section->vma - tls_biased_base (info);
   2036      1.1     skrll 
   2037      1.1     skrll 	  if ((bfd_signed_vma)ad >= -(1 << (16 - 1))
   2038      1.1     skrll 	      && (bfd_signed_vma)ad < (1 << (16 - 1)))
   2039      1.1     skrll 	    {
   2040      1.1     skrll 	      /* setlos lo(ad), gr9 */
   2041      1.1     skrll 	      bfd_put_32 (output_bfd,
   2042      1.1     skrll 			  0x92fc0000
   2043      1.1     skrll 			  | (ad
   2044      1.1     skrll 			     & (((bfd_vma)1 << 16) - 1)),
   2045      1.1     skrll 			  plt_code);
   2046      1.1     skrll 	      plt_code += 4;
   2047      1.1     skrll 	    }
   2048      1.1     skrll 	  else
   2049      1.1     skrll 	    {
   2050      1.1     skrll 	      /* sethi.p hi(ad), gr9
   2051      1.1     skrll 		 setlo lo(ad), gr9 */
   2052      1.1     skrll 	      bfd_put_32 (output_bfd,
   2053      1.1     skrll 			  0x12f80000
   2054      1.1     skrll 			  | ((ad >> 16)
   2055      1.1     skrll 			     & (((bfd_vma)1 << 16) - 1)),
   2056      1.1     skrll 			  plt_code);
   2057      1.1     skrll 	      plt_code += 4;
   2058      1.1     skrll 	      bfd_put_32 (output_bfd,
   2059      1.1     skrll 			  0x92f40000
   2060      1.1     skrll 			  | (ad
   2061      1.1     skrll 			     & (((bfd_vma)1 << 16) - 1)),
   2062      1.1     skrll 			  plt_code);
   2063      1.1     skrll 	      plt_code += 4;
   2064      1.1     skrll 	    }
   2065      1.1     skrll 	  /* ret */
   2066      1.1     skrll 	  bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
   2067      1.1     skrll 	}
   2068      1.1     skrll       else if (entry->tlsoff_entry)
   2069      1.1     skrll 	{
   2070      1.1     skrll 	  /* Figure out what kind of PLT entry we need, depending on the
   2071      1.1     skrll 	     location of the TLS descriptor within the GOT.  */
   2072      1.1     skrll 	  if (entry->tlsoff_entry >= -(1 << (12 - 1))
   2073      1.1     skrll 	      && entry->tlsoff_entry < (1 << (12 - 1)))
   2074      1.1     skrll 	    {
   2075      1.1     skrll 	      /* ldi @(gr15, tlsoff_entry), gr9 */
   2076      1.1     skrll 	      bfd_put_32 (output_bfd,
   2077      1.1     skrll 			  0x92c8f000 | (entry->tlsoff_entry
   2078      1.1     skrll 					& ((1 << 12) - 1)),
   2079      1.1     skrll 			  plt_code);
   2080      1.1     skrll 	      plt_code += 4;
   2081      1.1     skrll 	    }
   2082      1.1     skrll 	  else
   2083      1.1     skrll 	    {
   2084      1.1     skrll 	      if (entry->tlsoff_entry >= -(1 << (16 - 1))
   2085      1.1     skrll 		  && entry->tlsoff_entry < (1 << (16 - 1)))
   2086      1.1     skrll 		{
   2087      1.1     skrll 		  /* setlos lo(tlsoff_entry), gr8 */
   2088      1.1     skrll 		  bfd_put_32 (output_bfd,
   2089      1.1     skrll 			      0x90fc0000
   2090      1.1     skrll 			      | (entry->tlsoff_entry
   2091      1.1     skrll 				 & (((bfd_vma)1 << 16) - 1)),
   2092      1.1     skrll 			      plt_code);
   2093      1.1     skrll 		  plt_code += 4;
   2094      1.1     skrll 		}
   2095      1.1     skrll 	      else
   2096      1.1     skrll 		{
   2097      1.1     skrll 		  /* sethi.p hi(tlsoff_entry), gr8
   2098      1.1     skrll 		     setlo lo(tlsoff_entry), gr8 */
   2099      1.1     skrll 		  bfd_put_32 (output_bfd,
   2100      1.1     skrll 			      0x10f80000
   2101      1.1     skrll 			      | ((entry->tlsoff_entry >> 16)
   2102      1.1     skrll 				 & (((bfd_vma)1 << 16) - 1)),
   2103      1.1     skrll 			      plt_code);
   2104      1.1     skrll 		  plt_code += 4;
   2105      1.1     skrll 		  bfd_put_32 (output_bfd,
   2106      1.1     skrll 			      0x90f40000
   2107      1.1     skrll 			      | (entry->tlsoff_entry
   2108      1.1     skrll 				 & (((bfd_vma)1 << 16) - 1)),
   2109      1.1     skrll 			      plt_code);
   2110      1.1     skrll 		  plt_code += 4;
   2111      1.1     skrll 		}
   2112      1.1     skrll 	      /* ld @(gr15,gr8),gr9 */
   2113      1.1     skrll 	      bfd_put_32 (output_bfd, 0x9008f108, plt_code);
   2114      1.1     skrll 	      plt_code += 4;
   2115      1.1     skrll 	    }
   2116      1.1     skrll 	  /* ret */
   2117      1.1     skrll 	  bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
   2118      1.1     skrll 	}
   2119      1.1     skrll       else
   2120      1.1     skrll 	{
   2121      1.1     skrll 	  BFD_ASSERT (entry->tlsdesc_entry);
   2122      1.1     skrll 
   2123      1.1     skrll 	  /* Figure out what kind of PLT entry we need, depending on the
   2124      1.1     skrll 	     location of the TLS descriptor within the GOT.  */
   2125      1.1     skrll 	  if (entry->tlsdesc_entry >= -(1 << (12 - 1))
   2126      1.1     skrll 	      && entry->tlsdesc_entry < (1 << (12 - 1)))
   2127      1.1     skrll 	    {
   2128      1.1     skrll 	      /* lddi @(gr15, tlsdesc_entry), gr8 */
   2129      1.1     skrll 	      bfd_put_32 (output_bfd,
   2130      1.1     skrll 			  0x90ccf000 | (entry->tlsdesc_entry
   2131      1.1     skrll 					& ((1 << 12) - 1)),
   2132      1.1     skrll 			  plt_code);
   2133      1.1     skrll 	      plt_code += 4;
   2134      1.1     skrll 	    }
   2135      1.1     skrll 	  else
   2136      1.1     skrll 	    {
   2137      1.1     skrll 	      if (entry->tlsdesc_entry >= -(1 << (16 - 1))
   2138      1.1     skrll 		  && entry->tlsdesc_entry < (1 << (16 - 1)))
   2139      1.1     skrll 		{
   2140      1.1     skrll 		  /* setlos lo(tlsdesc_entry), gr8 */
   2141      1.1     skrll 		  bfd_put_32 (output_bfd,
   2142      1.1     skrll 			      0x90fc0000
   2143      1.1     skrll 			      | (entry->tlsdesc_entry
   2144      1.1     skrll 				 & (((bfd_vma)1 << 16) - 1)),
   2145      1.1     skrll 			      plt_code);
   2146      1.1     skrll 		  plt_code += 4;
   2147      1.1     skrll 		}
   2148      1.1     skrll 	      else
   2149      1.1     skrll 		{
   2150      1.1     skrll 		  /* sethi.p hi(tlsdesc_entry), gr8
   2151      1.1     skrll 		     setlo lo(tlsdesc_entry), gr8 */
   2152      1.1     skrll 		  bfd_put_32 (output_bfd,
   2153      1.1     skrll 			      0x10f80000
   2154      1.1     skrll 			      | ((entry->tlsdesc_entry >> 16)
   2155      1.1     skrll 				 & (((bfd_vma)1 << 16) - 1)),
   2156      1.1     skrll 			      plt_code);
   2157      1.1     skrll 		  plt_code += 4;
   2158      1.1     skrll 		  bfd_put_32 (output_bfd,
   2159      1.1     skrll 			      0x90f40000
   2160      1.1     skrll 			      | (entry->tlsdesc_entry
   2161      1.1     skrll 				 & (((bfd_vma)1 << 16) - 1)),
   2162      1.1     skrll 			      plt_code);
   2163      1.1     skrll 		  plt_code += 4;
   2164      1.1     skrll 		}
   2165      1.1     skrll 	      /* ldd @(gr15,gr8),gr8 */
   2166      1.1     skrll 	      bfd_put_32 (output_bfd, 0x9008f148, plt_code);
   2167      1.1     skrll 	      plt_code += 4;
   2168      1.1     skrll 	    }
   2169      1.1     skrll 	  /* jmpl @(gr8,gr0) */
   2170      1.1     skrll 	  bfd_put_32 (output_bfd, 0x80308000, plt_code);
   2171      1.1     skrll 	}
   2172      1.1     skrll     }
   2173      1.1     skrll 
   2174      1.1     skrll   return TRUE;
   2175      1.1     skrll }
   2176      1.1     skrll 
   2177      1.1     skrll /* Handle an FRV small data reloc.  */
   2178      1.1     skrll 
   2179      1.1     skrll static bfd_reloc_status_type
   2180      1.1     skrll elf32_frv_relocate_gprel12 (info, input_bfd, input_section, relocation,
   2181      1.1     skrll 			    contents, value)
   2182      1.1     skrll      struct bfd_link_info *info;
   2183      1.1     skrll      bfd *input_bfd;
   2184      1.1     skrll      asection *input_section;
   2185      1.1     skrll      Elf_Internal_Rela *relocation;
   2186      1.1     skrll      bfd_byte *contents;
   2187      1.1     skrll      bfd_vma value;
   2188      1.1     skrll {
   2189      1.1     skrll   bfd_vma insn;
   2190      1.1     skrll   bfd_vma gp;
   2191      1.1     skrll   struct bfd_link_hash_entry *h;
   2192      1.1     skrll 
   2193      1.1     skrll   h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
   2194      1.1     skrll 
   2195      1.1     skrll   gp = (h->u.def.value
   2196      1.1     skrll 	+ h->u.def.section->output_section->vma
   2197      1.1     skrll 	+ h->u.def.section->output_offset);
   2198      1.1     skrll 
   2199      1.1     skrll   value -= input_section->output_section->vma;
   2200      1.1     skrll   value -= (gp - input_section->output_section->vma);
   2201      1.1     skrll 
   2202      1.1     skrll   insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
   2203      1.1     skrll 
   2204      1.1     skrll   value += relocation->r_addend;
   2205      1.1     skrll 
   2206      1.1     skrll   if ((long) value > 0x7ff || (long) value < -0x800)
   2207      1.1     skrll     return bfd_reloc_overflow;
   2208      1.1     skrll 
   2209      1.1     skrll   bfd_put_32 (input_bfd,
   2210      1.1     skrll 	      (insn & 0xfffff000) | (value & 0xfff),
   2211      1.1     skrll 	      contents + relocation->r_offset);
   2212      1.1     skrll 
   2213      1.1     skrll   return bfd_reloc_ok;
   2214      1.1     skrll }
   2215      1.1     skrll 
   2216      1.1     skrll /* Handle an FRV small data reloc. for the u12 field.  */
   2217      1.1     skrll 
   2218      1.1     skrll static bfd_reloc_status_type
   2219      1.1     skrll elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, relocation,
   2220      1.1     skrll 			     contents, value)
   2221      1.1     skrll      struct bfd_link_info *info;
   2222      1.1     skrll      bfd *input_bfd;
   2223      1.1     skrll      asection *input_section;
   2224      1.1     skrll      Elf_Internal_Rela *relocation;
   2225      1.1     skrll      bfd_byte *contents;
   2226      1.1     skrll      bfd_vma value;
   2227      1.1     skrll {
   2228      1.1     skrll   bfd_vma insn;
   2229      1.1     skrll   bfd_vma gp;
   2230      1.1     skrll   struct bfd_link_hash_entry *h;
   2231      1.1     skrll   bfd_vma mask;
   2232      1.1     skrll 
   2233      1.1     skrll   h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
   2234      1.1     skrll 
   2235      1.1     skrll   gp = (h->u.def.value
   2236      1.1     skrll 	+ h->u.def.section->output_section->vma
   2237      1.1     skrll 	+ h->u.def.section->output_offset);
   2238      1.1     skrll 
   2239      1.1     skrll   value -= input_section->output_section->vma;
   2240      1.1     skrll   value -= (gp - input_section->output_section->vma);
   2241      1.1     skrll 
   2242      1.1     skrll   insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
   2243      1.1     skrll 
   2244      1.1     skrll   value += relocation->r_addend;
   2245      1.1     skrll 
   2246      1.1     skrll   if ((long) value > 0x7ff || (long) value < -0x800)
   2247      1.1     skrll     return bfd_reloc_overflow;
   2248      1.1     skrll 
   2249      1.1     skrll   /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0.  */
   2250      1.1     skrll   mask = 0x3f03f;
   2251      1.1     skrll   insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f);
   2252      1.1     skrll 
   2253      1.1     skrll   bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
   2254      1.1     skrll 
   2255      1.1     skrll   return bfd_reloc_ok;
   2256      1.1     skrll }
   2257      1.1     skrll 
   2258      1.1     skrll /* Handle an FRV ELF HI16 reloc.  */
   2259      1.1     skrll 
   2260      1.1     skrll static bfd_reloc_status_type
   2261      1.1     skrll elf32_frv_relocate_hi16 (input_bfd, relhi, contents, value)
   2262      1.1     skrll      bfd *input_bfd;
   2263      1.1     skrll      Elf_Internal_Rela *relhi;
   2264      1.1     skrll      bfd_byte *contents;
   2265      1.1     skrll      bfd_vma value;
   2266      1.1     skrll {
   2267      1.1     skrll   bfd_vma insn;
   2268      1.1     skrll 
   2269      1.1     skrll   insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
   2270      1.1     skrll 
   2271      1.1     skrll   value += relhi->r_addend;
   2272      1.1     skrll   value = ((value >> 16) & 0xffff);
   2273      1.1     skrll 
   2274      1.1     skrll   insn = (insn & 0xffff0000) | value;
   2275      1.1     skrll 
   2276      1.1     skrll   if ((long) value > 0xffff || (long) value < -0x10000)
   2277      1.1     skrll     return bfd_reloc_overflow;
   2278      1.1     skrll 
   2279      1.1     skrll   bfd_put_32 (input_bfd, insn, contents + relhi->r_offset);
   2280      1.1     skrll   return bfd_reloc_ok;
   2281      1.1     skrll 
   2282      1.1     skrll }
   2283      1.1     skrll static bfd_reloc_status_type
   2284      1.1     skrll elf32_frv_relocate_lo16 (input_bfd, rello, contents, value)
   2285      1.1     skrll      bfd *input_bfd;
   2286      1.1     skrll      Elf_Internal_Rela *rello;
   2287      1.1     skrll      bfd_byte *contents;
   2288      1.1     skrll      bfd_vma value;
   2289      1.1     skrll {
   2290      1.1     skrll   bfd_vma insn;
   2291      1.1     skrll 
   2292      1.1     skrll   insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
   2293      1.1     skrll 
   2294      1.1     skrll   value += rello->r_addend;
   2295      1.1     skrll   value = value & 0xffff;
   2296      1.1     skrll 
   2297      1.1     skrll   insn = (insn & 0xffff0000) | value;
   2298      1.1     skrll 
   2299      1.1     skrll   if ((long) value > 0xffff || (long) value < -0x10000)
   2300      1.1     skrll     return bfd_reloc_overflow;
   2301      1.1     skrll 
   2302      1.1     skrll   bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
   2303      1.1     skrll   return bfd_reloc_ok;
   2304      1.1     skrll }
   2305      1.1     skrll 
   2306      1.1     skrll /* Perform the relocation for the CALL label24 instruction.  */
   2307      1.1     skrll 
   2308      1.1     skrll static bfd_reloc_status_type
   2309      1.1     skrll elf32_frv_relocate_label24 (input_bfd, input_section, rello, contents, value)
   2310      1.1     skrll      bfd *input_bfd;
   2311      1.1     skrll      asection *input_section;
   2312      1.1     skrll      Elf_Internal_Rela *rello;
   2313      1.1     skrll      bfd_byte *contents;
   2314      1.1     skrll      bfd_vma value;
   2315      1.1     skrll {
   2316      1.1     skrll   bfd_vma insn;
   2317      1.1     skrll   bfd_vma label6;
   2318      1.1     skrll   bfd_vma label18;
   2319      1.1     skrll 
   2320      1.1     skrll   /* The format for the call instruction is:
   2321      1.1     skrll 
   2322      1.1     skrll     0 000000 0001111 000000000000000000
   2323      1.1     skrll       label6 opcode  label18
   2324      1.1     skrll 
   2325      1.1     skrll     The branch calculation is: pc + (4*label24)
   2326      1.1     skrll     where label24 is the concatenation of label6 and label18.  */
   2327      1.1     skrll 
   2328      1.1     skrll   /* Grab the instruction.  */
   2329      1.1     skrll   insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
   2330      1.1     skrll 
   2331      1.1     skrll   value -= input_section->output_section->vma + input_section->output_offset;
   2332      1.1     skrll   value -= rello->r_offset;
   2333      1.1     skrll   value += rello->r_addend;
   2334      1.1     skrll 
   2335      1.1     skrll   value = value >> 2;
   2336      1.1     skrll 
   2337      1.1     skrll   label6  = value & 0xfc0000;
   2338      1.1     skrll   label6  = label6 << 7;
   2339      1.1     skrll 
   2340      1.1     skrll   label18 = value & 0x3ffff;
   2341      1.1     skrll 
   2342      1.1     skrll   insn = insn & 0x803c0000;
   2343      1.1     skrll   insn = insn | label6;
   2344      1.1     skrll   insn = insn | label18;
   2345      1.1     skrll 
   2346      1.1     skrll   bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
   2347      1.1     skrll 
   2348      1.1     skrll   return bfd_reloc_ok;
   2349      1.1     skrll }
   2350      1.1     skrll 
   2351      1.1     skrll static bfd_reloc_status_type
   2352      1.1     skrll elf32_frv_relocate_gprelhi (info, input_bfd, input_section, relocation,
   2353      1.1     skrll 			    contents, value)
   2354      1.1     skrll      struct bfd_link_info *info;
   2355      1.1     skrll      bfd *input_bfd;
   2356      1.1     skrll      asection *input_section;
   2357      1.1     skrll      Elf_Internal_Rela *relocation;
   2358      1.1     skrll      bfd_byte *contents;
   2359      1.1     skrll      bfd_vma value;
   2360      1.1     skrll {
   2361      1.1     skrll   bfd_vma insn;
   2362      1.1     skrll   bfd_vma gp;
   2363      1.1     skrll   struct bfd_link_hash_entry *h;
   2364      1.1     skrll 
   2365      1.1     skrll   h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
   2366      1.1     skrll 
   2367      1.1     skrll   gp = (h->u.def.value
   2368      1.1     skrll         + h->u.def.section->output_section->vma
   2369      1.1     skrll         + h->u.def.section->output_offset);
   2370      1.1     skrll 
   2371      1.1     skrll   value -= input_section->output_section->vma;
   2372      1.1     skrll   value -= (gp - input_section->output_section->vma);
   2373      1.1     skrll   value += relocation->r_addend;
   2374      1.1     skrll   value = ((value >> 16) & 0xffff);
   2375      1.1     skrll 
   2376      1.1     skrll   if ((long) value > 0xffff || (long) value < -0x10000)
   2377      1.1     skrll     return bfd_reloc_overflow;
   2378      1.1     skrll 
   2379      1.1     skrll   insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
   2380      1.1     skrll   insn = (insn & 0xffff0000) | value;
   2381      1.1     skrll 
   2382      1.1     skrll   bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
   2383      1.1     skrll   return bfd_reloc_ok;
   2384      1.1     skrll }
   2385      1.1     skrll 
   2386      1.1     skrll static bfd_reloc_status_type
   2387      1.1     skrll elf32_frv_relocate_gprello (info, input_bfd, input_section, relocation,
   2388      1.1     skrll 			    contents, value)
   2389      1.1     skrll      struct bfd_link_info *info;
   2390      1.1     skrll      bfd *input_bfd;
   2391      1.1     skrll      asection *input_section;
   2392      1.1     skrll      Elf_Internal_Rela *relocation;
   2393      1.1     skrll      bfd_byte *contents;
   2394      1.1     skrll      bfd_vma value;
   2395      1.1     skrll {
   2396      1.1     skrll   bfd_vma insn;
   2397      1.1     skrll   bfd_vma gp;
   2398      1.1     skrll   struct bfd_link_hash_entry *h;
   2399      1.1     skrll 
   2400      1.1     skrll   h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE);
   2401      1.1     skrll 
   2402      1.1     skrll   gp = (h->u.def.value
   2403      1.1     skrll         + h->u.def.section->output_section->vma
   2404      1.1     skrll         + h->u.def.section->output_offset);
   2405      1.1     skrll 
   2406      1.1     skrll   value -= input_section->output_section->vma;
   2407      1.1     skrll   value -= (gp - input_section->output_section->vma);
   2408      1.1     skrll   value += relocation->r_addend;
   2409      1.1     skrll   value = value & 0xffff;
   2410      1.1     skrll 
   2411      1.1     skrll   if ((long) value > 0xffff || (long) value < -0x10000)
   2412      1.1     skrll     return bfd_reloc_overflow;
   2413      1.1     skrll 
   2414      1.1     skrll   insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
   2415      1.1     skrll   insn = (insn & 0xffff0000) | value;
   2416      1.1     skrll 
   2417      1.1     skrll   bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
   2418      1.1     skrll 
   2419      1.1     skrll  return bfd_reloc_ok;
   2420      1.1     skrll }
   2421      1.1     skrll 
   2422      1.1     skrll static reloc_howto_type *
   2423      1.1     skrll frv_reloc_type_lookup (abfd, code)
   2424      1.1     skrll      bfd *abfd ATTRIBUTE_UNUSED;
   2425      1.1     skrll      bfd_reloc_code_real_type code;
   2426      1.1     skrll {
   2427      1.1     skrll   switch (code)
   2428      1.1     skrll     {
   2429      1.1     skrll     default:
   2430      1.1     skrll       break;
   2431      1.1     skrll 
   2432      1.1     skrll     case BFD_RELOC_NONE:
   2433      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_NONE];
   2434      1.1     skrll 
   2435      1.1     skrll     case BFD_RELOC_32:
   2436      1.1     skrll       if (elf_elfheader (abfd)->e_type == ET_EXEC
   2437      1.1     skrll 	  || elf_elfheader (abfd)->e_type == ET_DYN)
   2438      1.1     skrll 	return &elf32_frv_rel_32_howto;
   2439      1.1     skrll       /* Fall through.  */
   2440      1.1     skrll     case BFD_RELOC_CTOR:
   2441      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_32];
   2442      1.1     skrll 
   2443      1.1     skrll     case BFD_RELOC_FRV_LABEL16:
   2444      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_LABEL16];
   2445      1.1     skrll 
   2446      1.1     skrll     case BFD_RELOC_FRV_LABEL24:
   2447      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_LABEL24];
   2448      1.1     skrll 
   2449      1.1     skrll     case BFD_RELOC_FRV_LO16:
   2450      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_LO16];
   2451      1.1     skrll 
   2452      1.1     skrll     case BFD_RELOC_FRV_HI16:
   2453      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_HI16];
   2454      1.1     skrll 
   2455      1.1     skrll     case BFD_RELOC_FRV_GPREL12:
   2456      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GPREL12];
   2457      1.1     skrll 
   2458      1.1     skrll     case BFD_RELOC_FRV_GPRELU12:
   2459      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12];
   2460      1.1     skrll 
   2461      1.1     skrll     case BFD_RELOC_FRV_GPREL32:
   2462      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GPREL32];
   2463      1.1     skrll 
   2464      1.1     skrll     case BFD_RELOC_FRV_GPRELHI:
   2465      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI];
   2466      1.1     skrll 
   2467      1.1     skrll     case BFD_RELOC_FRV_GPRELLO:
   2468      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO];
   2469      1.1     skrll 
   2470      1.1     skrll     case BFD_RELOC_FRV_GOT12:
   2471      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOT12];
   2472      1.1     skrll 
   2473      1.1     skrll     case BFD_RELOC_FRV_GOTHI:
   2474      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOTHI];
   2475      1.1     skrll 
   2476      1.1     skrll     case BFD_RELOC_FRV_GOTLO:
   2477      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOTLO];
   2478      1.1     skrll 
   2479      1.1     skrll     case BFD_RELOC_FRV_FUNCDESC:
   2480      1.1     skrll       if (elf_elfheader (abfd)->e_type == ET_EXEC
   2481      1.1     skrll 	  || elf_elfheader (abfd)->e_type == ET_DYN)
   2482      1.1     skrll 	return &elf32_frv_rel_funcdesc_howto;
   2483      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC];
   2484      1.1     skrll 
   2485      1.1     skrll     case BFD_RELOC_FRV_FUNCDESC_GOT12:
   2486      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12];
   2487      1.1     skrll 
   2488      1.1     skrll     case BFD_RELOC_FRV_FUNCDESC_GOTHI:
   2489      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI];
   2490      1.1     skrll 
   2491      1.1     skrll     case BFD_RELOC_FRV_FUNCDESC_GOTLO:
   2492      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO];
   2493      1.1     skrll 
   2494      1.1     skrll     case BFD_RELOC_FRV_FUNCDESC_VALUE:
   2495      1.1     skrll       if (elf_elfheader (abfd)->e_type == ET_EXEC
   2496      1.1     skrll 	  || elf_elfheader (abfd)->e_type == ET_DYN)
   2497      1.1     skrll 	return &elf32_frv_rel_funcdesc_value_howto;
   2498      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE];
   2499      1.1     skrll 
   2500      1.1     skrll     case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
   2501      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12];
   2502      1.1     skrll 
   2503      1.1     skrll     case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
   2504      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI];
   2505      1.1     skrll 
   2506      1.1     skrll     case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
   2507      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO];
   2508      1.1     skrll 
   2509      1.1     skrll     case BFD_RELOC_FRV_GOTOFF12:
   2510      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12];
   2511      1.1     skrll 
   2512      1.1     skrll     case BFD_RELOC_FRV_GOTOFFHI:
   2513      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI];
   2514      1.1     skrll 
   2515      1.1     skrll     case BFD_RELOC_FRV_GOTOFFLO:
   2516      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO];
   2517      1.1     skrll 
   2518      1.1     skrll     case BFD_RELOC_FRV_GETTLSOFF:
   2519      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF];
   2520      1.1     skrll 
   2521      1.1     skrll     case BFD_RELOC_FRV_TLSDESC_VALUE:
   2522      1.1     skrll       if (elf_elfheader (abfd)->e_type == ET_EXEC
   2523      1.1     skrll 	  || elf_elfheader (abfd)->e_type == ET_DYN)
   2524      1.1     skrll 	return &elf32_frv_rel_tlsdesc_value_howto;
   2525      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_VALUE];
   2526      1.1     skrll 
   2527      1.1     skrll     case BFD_RELOC_FRV_GOTTLSDESC12:
   2528      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESC12];
   2529      1.1     skrll 
   2530      1.1     skrll     case BFD_RELOC_FRV_GOTTLSDESCHI:
   2531      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCHI];
   2532      1.1     skrll 
   2533      1.1     skrll     case BFD_RELOC_FRV_GOTTLSDESCLO:
   2534      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCLO];
   2535      1.1     skrll 
   2536      1.1     skrll     case BFD_RELOC_FRV_TLSMOFF12:
   2537      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF12];
   2538      1.1     skrll 
   2539      1.1     skrll     case BFD_RELOC_FRV_TLSMOFFHI:
   2540      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFHI];
   2541      1.1     skrll 
   2542      1.1     skrll     case BFD_RELOC_FRV_TLSMOFFLO:
   2543      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFLO];
   2544      1.1     skrll 
   2545      1.1     skrll     case BFD_RELOC_FRV_GOTTLSOFF12:
   2546      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFF12];
   2547      1.1     skrll 
   2548      1.1     skrll     case BFD_RELOC_FRV_GOTTLSOFFHI:
   2549      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFHI];
   2550      1.1     skrll 
   2551      1.1     skrll     case BFD_RELOC_FRV_GOTTLSOFFLO:
   2552      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFLO];
   2553      1.1     skrll 
   2554      1.1     skrll     case BFD_RELOC_FRV_TLSOFF:
   2555      1.1     skrll       if (elf_elfheader (abfd)->e_type == ET_EXEC
   2556      1.1     skrll 	  || elf_elfheader (abfd)->e_type == ET_DYN)
   2557      1.1     skrll 	return &elf32_frv_rel_tlsoff_howto;
   2558      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF];
   2559      1.1     skrll 
   2560      1.1     skrll     case BFD_RELOC_FRV_TLSDESC_RELAX:
   2561      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_RELAX];
   2562      1.1     skrll 
   2563      1.1     skrll     case BFD_RELOC_FRV_GETTLSOFF_RELAX:
   2564      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF_RELAX];
   2565      1.1     skrll 
   2566      1.1     skrll     case BFD_RELOC_FRV_TLSOFF_RELAX:
   2567      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF_RELAX];
   2568      1.1     skrll 
   2569      1.1     skrll     case BFD_RELOC_FRV_TLSMOFF:
   2570      1.1     skrll       return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF];
   2571      1.1     skrll 
   2572      1.1     skrll     case BFD_RELOC_VTABLE_INHERIT:
   2573      1.1     skrll       return &elf32_frv_vtinherit_howto;
   2574      1.1     skrll 
   2575      1.1     skrll     case BFD_RELOC_VTABLE_ENTRY:
   2576      1.1     skrll       return &elf32_frv_vtentry_howto;
   2577      1.1     skrll     }
   2578      1.1     skrll 
   2579      1.1     skrll   return NULL;
   2580      1.1     skrll }
   2581      1.1     skrll 
   2582      1.1     skrll static reloc_howto_type *
   2583      1.1     skrll frv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
   2584      1.1     skrll {
   2585      1.1     skrll   unsigned int i;
   2586      1.1     skrll 
   2587      1.1     skrll   for (i = 0;
   2588      1.1     skrll        i < sizeof (elf32_frv_howto_table) / sizeof (elf32_frv_howto_table[0]);
   2589      1.1     skrll        i++)
   2590      1.1     skrll     if (elf32_frv_howto_table[i].name != NULL
   2591      1.1     skrll 	&& strcasecmp (elf32_frv_howto_table[i].name, r_name) == 0)
   2592      1.1     skrll       return &elf32_frv_howto_table[i];
   2593      1.1     skrll 
   2594      1.1     skrll   if (strcasecmp (elf32_frv_vtinherit_howto.name, r_name) == 0)
   2595      1.1     skrll     return &elf32_frv_vtinherit_howto;
   2596      1.1     skrll   if (strcasecmp (elf32_frv_vtentry_howto.name, r_name) == 0)
   2597      1.1     skrll     return &elf32_frv_vtentry_howto;
   2598      1.1     skrll 
   2599      1.1     skrll   return NULL;
   2600      1.1     skrll }
   2601      1.1     skrll 
   2602      1.1     skrll /* Set the howto pointer for an FRV ELF reloc.  */
   2603      1.1     skrll 
   2604      1.1     skrll static void
   2605      1.1     skrll frv_info_to_howto_rela (abfd, cache_ptr, dst)
   2606      1.1     skrll      bfd *abfd ATTRIBUTE_UNUSED;
   2607      1.1     skrll      arelent *cache_ptr;
   2608      1.1     skrll      Elf_Internal_Rela *dst;
   2609      1.1     skrll {
   2610      1.1     skrll   unsigned int r_type;
   2611      1.1     skrll 
   2612      1.1     skrll   r_type = ELF32_R_TYPE (dst->r_info);
   2613      1.1     skrll   switch (r_type)
   2614      1.1     skrll     {
   2615      1.1     skrll     case R_FRV_GNU_VTINHERIT:
   2616      1.1     skrll       cache_ptr->howto = &elf32_frv_vtinherit_howto;
   2617      1.1     skrll       break;
   2618      1.1     skrll 
   2619      1.1     skrll     case R_FRV_GNU_VTENTRY:
   2620      1.1     skrll       cache_ptr->howto = &elf32_frv_vtentry_howto;
   2621      1.1     skrll       break;
   2622      1.1     skrll 
   2623      1.1     skrll     default:
   2624      1.1     skrll       cache_ptr->howto = & elf32_frv_howto_table [r_type];
   2625      1.1     skrll       break;
   2626      1.1     skrll     }
   2627      1.1     skrll }
   2628      1.1     skrll 
   2629      1.1     skrll /* Set the howto pointer for an FRV ELF REL reloc.  */
   2630      1.1     skrll static void
   2631      1.1     skrll frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   2632      1.1     skrll 			    arelent *cache_ptr, Elf_Internal_Rela *dst)
   2633      1.1     skrll {
   2634      1.1     skrll   unsigned int r_type;
   2635      1.1     skrll 
   2636      1.1     skrll   r_type = ELF32_R_TYPE (dst->r_info);
   2637      1.1     skrll   switch (r_type)
   2638      1.1     skrll     {
   2639      1.1     skrll     case R_FRV_32:
   2640      1.1     skrll       cache_ptr->howto = &elf32_frv_rel_32_howto;
   2641      1.1     skrll       break;
   2642      1.1     skrll 
   2643      1.1     skrll     case R_FRV_FUNCDESC:
   2644      1.1     skrll       cache_ptr->howto = &elf32_frv_rel_funcdesc_howto;
   2645      1.1     skrll       break;
   2646      1.1     skrll 
   2647      1.1     skrll     case R_FRV_FUNCDESC_VALUE:
   2648      1.1     skrll       cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto;
   2649      1.1     skrll       break;
   2650      1.1     skrll 
   2651      1.1     skrll     case R_FRV_TLSDESC_VALUE:
   2652      1.1     skrll       cache_ptr->howto = &elf32_frv_rel_tlsdesc_value_howto;
   2653      1.1     skrll       break;
   2654      1.1     skrll 
   2655      1.1     skrll     case R_FRV_TLSOFF:
   2656      1.1     skrll       cache_ptr->howto = &elf32_frv_rel_tlsoff_howto;
   2657      1.1     skrll       break;
   2658      1.1     skrll 
   2659      1.1     skrll     default:
   2660      1.1     skrll       cache_ptr->howto = NULL;
   2661      1.1     skrll       break;
   2662      1.1     skrll     }
   2663      1.1     skrll }
   2664      1.1     skrll 
   2665      1.1     skrll /* Perform a single relocation.  By default we use the standard BFD
   2667      1.1     skrll    routines, but a few relocs, we have to do them ourselves.  */
   2668      1.1     skrll 
   2669      1.1     skrll static bfd_reloc_status_type
   2670      1.1     skrll frv_final_link_relocate (howto, input_bfd, input_section, contents, rel,
   2671      1.1     skrll 			 relocation)
   2672      1.1     skrll      reloc_howto_type *howto;
   2673      1.1     skrll      bfd *input_bfd;
   2674      1.1     skrll      asection *input_section;
   2675      1.1     skrll      bfd_byte *contents;
   2676      1.1     skrll      Elf_Internal_Rela *rel;
   2677      1.1     skrll      bfd_vma relocation;
   2678      1.1     skrll {
   2679      1.1     skrll   return _bfd_final_link_relocate (howto, input_bfd, input_section,
   2680      1.1     skrll 				   contents, rel->r_offset, relocation,
   2681      1.1     skrll 				   rel->r_addend);
   2682      1.1     skrll }
   2683      1.1     skrll 
   2684      1.1     skrll 
   2685      1.1     skrll /* Relocate an FRV ELF section.
   2687      1.1     skrll 
   2688      1.1     skrll    The RELOCATE_SECTION function is called by the new ELF backend linker
   2689      1.1     skrll    to handle the relocations for a section.
   2690      1.1     skrll 
   2691      1.1     skrll    The relocs are always passed as Rela structures; if the section
   2692      1.1     skrll    actually uses Rel structures, the r_addend field will always be
   2693      1.1     skrll    zero.
   2694      1.1     skrll 
   2695      1.1     skrll    This function is responsible for adjusting the section contents as
   2696      1.1     skrll    necessary, and (if using Rela relocs and generating a relocatable
   2697      1.1     skrll    output file) adjusting the reloc addend as necessary.
   2698      1.1     skrll 
   2699      1.1     skrll    This function does not have to worry about setting the reloc
   2700      1.1     skrll    address or the reloc symbol index.
   2701      1.1     skrll 
   2702      1.1     skrll    LOCAL_SYMS is a pointer to the swapped in local symbols.
   2703      1.1     skrll 
   2704      1.1     skrll    LOCAL_SECTIONS is an array giving the section in the input file
   2705      1.1     skrll    corresponding to the st_shndx field of each local symbol.
   2706      1.1     skrll 
   2707      1.1     skrll    The global hash table entry for the global symbols can be found
   2708      1.1     skrll    via elf_sym_hashes (input_bfd).
   2709      1.1     skrll 
   2710      1.1     skrll    When generating relocatable output, this function must handle
   2711      1.1     skrll    STB_LOCAL/STT_SECTION symbols specially.  The output symbol is
   2712      1.1     skrll    going to be the section symbol corresponding to the output
   2713      1.1     skrll    section, which means that the addend must be adjusted
   2714      1.1     skrll    accordingly.  */
   2715      1.1     skrll 
   2716      1.1     skrll static bfd_boolean
   2717      1.1     skrll elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
   2718      1.1     skrll 			    contents, relocs, local_syms, local_sections)
   2719      1.1     skrll      bfd *output_bfd ATTRIBUTE_UNUSED;
   2720      1.1     skrll      struct bfd_link_info *info;
   2721      1.1     skrll      bfd *input_bfd;
   2722      1.1     skrll      asection *input_section;
   2723      1.1     skrll      bfd_byte *contents;
   2724      1.1     skrll      Elf_Internal_Rela *relocs;
   2725      1.1     skrll      Elf_Internal_Sym *local_syms;
   2726      1.1     skrll      asection **local_sections;
   2727      1.1     skrll {
   2728      1.1     skrll   Elf_Internal_Shdr *symtab_hdr;
   2729      1.1     skrll   struct elf_link_hash_entry **sym_hashes;
   2730      1.1     skrll   Elf_Internal_Rela *rel;
   2731      1.1     skrll   Elf_Internal_Rela *relend;
   2732      1.1     skrll   unsigned isec_segment, got_segment, plt_segment, gprel_segment, tls_segment,
   2733      1.1     skrll     check_segment[2];
   2734      1.1     skrll   int silence_segment_error = !(info->shared || info->pie);
   2735      1.1     skrll   unsigned long insn;
   2736      1.1     skrll 
   2737      1.1     skrll   symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
   2738      1.1     skrll   sym_hashes = elf_sym_hashes (input_bfd);
   2739      1.1     skrll   relend     = relocs + input_section->reloc_count;
   2740      1.1     skrll 
   2741      1.1     skrll   isec_segment = _frvfdpic_osec_to_segment (output_bfd,
   2742      1.1     skrll 					    input_section->output_section);
   2743      1.1     skrll   if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info))
   2744      1.1     skrll     got_segment = _frvfdpic_osec_to_segment (output_bfd,
   2745      1.1     skrll 					     frvfdpic_got_section (info)
   2746      1.1     skrll 					     ->output_section);
   2747      1.1     skrll   else
   2748      1.1     skrll     got_segment = -1;
   2749      1.1     skrll   if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info))
   2750      1.1     skrll     gprel_segment = _frvfdpic_osec_to_segment (output_bfd,
   2751      1.1     skrll 					       frvfdpic_gotfixup_section (info)
   2752      1.1     skrll 					       ->output_section);
   2753      1.1     skrll   else
   2754      1.1     skrll     gprel_segment = -1;
   2755      1.1     skrll   if (IS_FDPIC (output_bfd) && frvfdpic_plt_section (info))
   2756      1.1     skrll     plt_segment = _frvfdpic_osec_to_segment (output_bfd,
   2757      1.1     skrll 					     frvfdpic_plt_section (info)
   2758      1.1     skrll 					     ->output_section);
   2759      1.1     skrll   else
   2760      1.1     skrll     plt_segment = -1;
   2761      1.1     skrll   if (elf_hash_table (info)->tls_sec)
   2762      1.1     skrll     tls_segment = _frvfdpic_osec_to_segment (output_bfd,
   2763      1.1     skrll 					     elf_hash_table (info)->tls_sec);
   2764      1.1     skrll   else
   2765      1.1     skrll     tls_segment = -1;
   2766      1.1     skrll 
   2767      1.1     skrll   for (rel = relocs; rel < relend; rel ++)
   2768      1.1     skrll     {
   2769      1.1     skrll       reloc_howto_type *howto;
   2770      1.1     skrll       unsigned long r_symndx;
   2771      1.1     skrll       Elf_Internal_Sym *sym;
   2772      1.1     skrll       asection *sec;
   2773  1.1.1.2  christos       struct elf_link_hash_entry *h;
   2774      1.1     skrll       bfd_vma relocation;
   2775      1.1     skrll       bfd_reloc_status_type r;
   2776      1.1     skrll       const char *name;
   2777      1.1     skrll       int r_type;
   2778      1.1     skrll       asection *osec;
   2779      1.1     skrll       struct frvfdpic_relocs_info *picrel;
   2780      1.1     skrll       bfd_vma orig_addend = rel->r_addend;
   2781      1.1     skrll 
   2782      1.1     skrll       r_type = ELF32_R_TYPE (rel->r_info);
   2783      1.1     skrll 
   2784      1.1     skrll       if (   r_type == R_FRV_GNU_VTINHERIT
   2785      1.1     skrll 	  || r_type == R_FRV_GNU_VTENTRY)
   2786      1.1     skrll 	continue;
   2787      1.1     skrll 
   2788      1.1     skrll       r_symndx = ELF32_R_SYM (rel->r_info);
   2789      1.1     skrll       howto  = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info);
   2790      1.1     skrll       h      = NULL;
   2791      1.1     skrll       sym    = NULL;
   2792      1.1     skrll       sec    = NULL;
   2793      1.1     skrll 
   2794      1.1     skrll       if (r_symndx < symtab_hdr->sh_info)
   2795      1.1     skrll 	{
   2796      1.1     skrll 	  sym = local_syms + r_symndx;
   2797      1.1     skrll 	  osec = sec = local_sections [r_symndx];
   2798      1.1     skrll 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
   2799  1.1.1.2  christos 
   2800  1.1.1.2  christos 	  name = bfd_elf_string_from_elf_section
   2801      1.1     skrll 	    (input_bfd, symtab_hdr->sh_link, sym->st_name);
   2802      1.1     skrll 	  if (name == NULL || name[0] == 0)
   2803      1.1     skrll 	    name = bfd_section_name (input_bfd, sec);
   2804      1.1     skrll 	}
   2805      1.1     skrll       else
   2806      1.1     skrll 	{
   2807      1.1     skrll 	  bfd_boolean warned;
   2808      1.1     skrll 	  bfd_boolean unresolved_reloc;
   2809      1.1     skrll 
   2810      1.1     skrll 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
   2811      1.1     skrll 				   r_symndx, symtab_hdr, sym_hashes,
   2812  1.1.1.2  christos 				   h, sec, relocation,
   2813      1.1     skrll 				   unresolved_reloc, warned);
   2814      1.1     skrll 	  osec = sec;
   2815      1.1     skrll 	  name = h->root.root.string;
   2816  1.1.1.2  christos 	}
   2817  1.1.1.2  christos 
   2818      1.1     skrll       if (sec != NULL && elf_discarded_section (sec))
   2819      1.1     skrll 	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   2820      1.1     skrll 					 rel, relend, howto, contents);
   2821      1.1     skrll 
   2822      1.1     skrll       if (info->relocatable)
   2823      1.1     skrll 	continue;
   2824      1.1     skrll 
   2825      1.1     skrll       if (r_type != R_FRV_TLSMOFF
   2826      1.1     skrll 	  && h != NULL
   2827      1.1     skrll 	  && (h->root.type == bfd_link_hash_defined
   2828      1.1     skrll 	      || h->root.type == bfd_link_hash_defweak)
   2829      1.1     skrll 	  && !FRVFDPIC_SYM_LOCAL (info, h))
   2830      1.1     skrll 	{
   2831      1.1     skrll 	  osec = sec = NULL;
   2832      1.1     skrll 	  relocation = 0;
   2833      1.1     skrll 	}
   2834      1.1     skrll 
   2835      1.1     skrll       switch (r_type)
   2836      1.1     skrll 	{
   2837      1.1     skrll 	case R_FRV_LABEL24:
   2838      1.1     skrll 	case R_FRV_32:
   2839      1.1     skrll 	  if (! IS_FDPIC (output_bfd))
   2840      1.1     skrll 	    goto non_fdpic;
   2841      1.1     skrll 
   2842      1.1     skrll 	case R_FRV_GOT12:
   2843      1.1     skrll 	case R_FRV_GOTHI:
   2844      1.1     skrll 	case R_FRV_GOTLO:
   2845      1.1     skrll 	case R_FRV_FUNCDESC_GOT12:
   2846      1.1     skrll 	case R_FRV_FUNCDESC_GOTHI:
   2847      1.1     skrll 	case R_FRV_FUNCDESC_GOTLO:
   2848      1.1     skrll 	case R_FRV_GOTOFF12:
   2849      1.1     skrll 	case R_FRV_GOTOFFHI:
   2850      1.1     skrll 	case R_FRV_GOTOFFLO:
   2851      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFF12:
   2852      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFHI:
   2853      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFLO:
   2854      1.1     skrll 	case R_FRV_FUNCDESC:
   2855      1.1     skrll 	case R_FRV_FUNCDESC_VALUE:
   2856      1.1     skrll 	case R_FRV_GETTLSOFF:
   2857      1.1     skrll 	case R_FRV_TLSDESC_VALUE:
   2858      1.1     skrll 	case R_FRV_GOTTLSDESC12:
   2859      1.1     skrll 	case R_FRV_GOTTLSDESCHI:
   2860      1.1     skrll 	case R_FRV_GOTTLSDESCLO:
   2861      1.1     skrll 	case R_FRV_TLSMOFF12:
   2862      1.1     skrll 	case R_FRV_TLSMOFFHI:
   2863      1.1     skrll 	case R_FRV_TLSMOFFLO:
   2864      1.1     skrll 	case R_FRV_GOTTLSOFF12:
   2865      1.1     skrll 	case R_FRV_GOTTLSOFFHI:
   2866      1.1     skrll 	case R_FRV_GOTTLSOFFLO:
   2867      1.1     skrll 	case R_FRV_TLSOFF:
   2868      1.1     skrll 	case R_FRV_TLSDESC_RELAX:
   2869      1.1     skrll 	case R_FRV_GETTLSOFF_RELAX:
   2870      1.1     skrll 	case R_FRV_TLSOFF_RELAX:
   2871      1.1     skrll 	case R_FRV_TLSMOFF:
   2872      1.1     skrll 	  if (h != NULL)
   2873      1.1     skrll 	    picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
   2874      1.1     skrll 						      (info), input_bfd, h,
   2875      1.1     skrll 						      orig_addend, INSERT);
   2876      1.1     skrll 	  else
   2877      1.1     skrll 	    /* In order to find the entry we created before, we must
   2878      1.1     skrll 	       use the original addend, not the one that may have been
   2879      1.1     skrll 	       modified by _bfd_elf_rela_local_sym().  */
   2880      1.1     skrll 	    picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
   2881      1.1     skrll 						     (info), input_bfd, r_symndx,
   2882      1.1     skrll 						     orig_addend, INSERT);
   2883      1.1     skrll 	  if (! picrel)
   2884      1.1     skrll 	    return FALSE;
   2885      1.1     skrll 
   2886      1.1     skrll 	  if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info,
   2887      1.1     skrll 						      osec, sym,
   2888      1.1     skrll 						      rel->r_addend))
   2889      1.1     skrll 	    {
   2890      1.1     skrll 	      (*_bfd_error_handler)
   2891      1.1     skrll 		(_("%B(%A+0x%x): relocation to `%s+%x' may have caused the error above"),
   2892      1.1     skrll 		 input_bfd, input_section, rel->r_offset, name, rel->r_addend);
   2893      1.1     skrll 	      return FALSE;
   2894      1.1     skrll 	    }
   2895      1.1     skrll 
   2896      1.1     skrll 	  break;
   2897      1.1     skrll 
   2898      1.1     skrll 	default:
   2899      1.1     skrll 	non_fdpic:
   2900      1.1     skrll 	  picrel = NULL;
   2901      1.1     skrll 	  if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
   2902      1.1     skrll 	    {
   2903      1.1     skrll 	      info->callbacks->warning
   2904      1.1     skrll 		(info, _("relocation references symbol not defined in the module"),
   2905      1.1     skrll 		 name, input_bfd, input_section, rel->r_offset);
   2906      1.1     skrll 	      return FALSE;
   2907      1.1     skrll 	    }
   2908      1.1     skrll 	  break;
   2909      1.1     skrll 	}
   2910      1.1     skrll 
   2911      1.1     skrll       switch (r_type)
   2912      1.1     skrll 	{
   2913      1.1     skrll 	case R_FRV_GETTLSOFF:
   2914      1.1     skrll 	case R_FRV_TLSDESC_VALUE:
   2915      1.1     skrll 	case R_FRV_GOTTLSDESC12:
   2916      1.1     skrll 	case R_FRV_GOTTLSDESCHI:
   2917      1.1     skrll 	case R_FRV_GOTTLSDESCLO:
   2918      1.1     skrll 	case R_FRV_TLSMOFF12:
   2919      1.1     skrll 	case R_FRV_TLSMOFFHI:
   2920      1.1     skrll 	case R_FRV_TLSMOFFLO:
   2921      1.1     skrll 	case R_FRV_GOTTLSOFF12:
   2922      1.1     skrll 	case R_FRV_GOTTLSOFFHI:
   2923      1.1     skrll 	case R_FRV_GOTTLSOFFLO:
   2924      1.1     skrll 	case R_FRV_TLSOFF:
   2925      1.1     skrll 	case R_FRV_TLSDESC_RELAX:
   2926      1.1     skrll 	case R_FRV_GETTLSOFF_RELAX:
   2927      1.1     skrll 	case R_FRV_TLSOFF_RELAX:
   2928      1.1     skrll 	case R_FRV_TLSMOFF:
   2929      1.1     skrll 	  if (sec && (bfd_is_abs_section (sec) || bfd_is_und_section (sec)))
   2930      1.1     skrll 	    relocation += tls_biased_base (info);
   2931      1.1     skrll 	  break;
   2932      1.1     skrll 
   2933      1.1     skrll 	default:
   2934      1.1     skrll 	  break;
   2935      1.1     skrll 	}
   2936      1.1     skrll 
   2937      1.1     skrll       /* Try to apply TLS relaxations.  */
   2938      1.1     skrll       if (1)
   2939      1.1     skrll 	switch (r_type)
   2940      1.1     skrll 	  {
   2941      1.1     skrll 
   2942      1.1     skrll #define LOCAL_EXEC_P(info, picrel) \
   2943      1.1     skrll   ((info)->executable \
   2944      1.1     skrll    && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
   2945      1.1     skrll #define INITIAL_EXEC_P(info, picrel) \
   2946      1.1     skrll   (((info)->executable || (info)->flags & DF_STATIC_TLS) \
   2947      1.1     skrll    && (picrel)->tlsoff_entry)
   2948      1.1     skrll 
   2949      1.1     skrll #define IN_RANGE_FOR_OFST12_P(value) \
   2950      1.1     skrll   ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
   2951      1.1     skrll #define IN_RANGE_FOR_SETLOS_P(value) \
   2952      1.1     skrll   ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
   2953      1.1     skrll #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
   2954      1.1     skrll   (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
   2955      1.1     skrll 
   2956      1.1     skrll #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
   2957      1.1     skrll   (LOCAL_EXEC_P ((info), (picrel)) \
   2958      1.1     skrll    && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
   2959      1.1     skrll #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
   2960      1.1     skrll   (INITIAL_EXEC_P ((info), (picrel)) \
   2961      1.1     skrll    && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
   2962      1.1     skrll 
   2963      1.1     skrll #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
   2964      1.1     skrll   (LOCAL_EXEC_P ((info), (picrel)))
   2965      1.1     skrll #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
   2966      1.1     skrll   (INITIAL_EXEC_P ((info), (picrel)))
   2967      1.1     skrll 
   2968      1.1     skrll #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
   2969      1.1     skrll   (LOCAL_EXEC_P ((info), (picrel)) \
   2970      1.1     skrll    && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
   2971      1.1     skrll 
   2972      1.1     skrll 	  case R_FRV_GETTLSOFF:
   2973      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   2974      1.1     skrll 
   2975      1.1     skrll 	    /* Is this a call instruction?  */
   2976      1.1     skrll 	    if ((insn & (unsigned long)0x01fc0000) != 0x003c0000)
   2977      1.1     skrll 	      {
   2978      1.1     skrll 		r = info->callbacks->warning
   2979      1.1     skrll 		  (info,
   2980      1.1     skrll 		   _("R_FRV_GETTLSOFF not applied to a call instruction"),
   2981      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   2982      1.1     skrll 		return FALSE;
   2983      1.1     skrll 	      }
   2984      1.1     skrll 
   2985      1.1     skrll 	    if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info, picrel,
   2986      1.1     skrll 					      relocation + rel->r_addend))
   2987      1.1     skrll 	      {
   2988      1.1     skrll 		/* Replace the call instruction (except the packing bit)
   2989      1.1     skrll 		   with setlos #tlsmofflo(symbol+offset), gr9.  */
   2990      1.1     skrll 		insn &= (unsigned long)0x80000000;
   2991      1.1     skrll 		insn |= (unsigned long)0x12fc0000;
   2992      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   2993      1.1     skrll 
   2994      1.1     skrll 		r_type = R_FRV_TLSMOFFLO;
   2995      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   2996      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   2997      1.1     skrll 	      }
   2998      1.1     skrll 
   2999      1.1     skrll 	    else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info, picrel))
   3000      1.1     skrll 	      {
   3001      1.1     skrll 		/* Replace the call instruction (except the packing bit)
   3002      1.1     skrll 		   with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9.  */
   3003      1.1     skrll 		insn &= (unsigned long)0x80000000;
   3004      1.1     skrll 		insn |= (unsigned long)0x12c8f000;
   3005      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3006      1.1     skrll 
   3007      1.1     skrll 		r_type = R_FRV_GOTTLSOFF12;
   3008      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3009      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3010      1.1     skrll 	      }
   3011      1.1     skrll 
   3012      1.1     skrll 	    break;
   3013      1.1     skrll 
   3014      1.1     skrll 	  case R_FRV_GOTTLSDESC12:
   3015      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   3016      1.1     skrll 
   3017      1.1     skrll 	    /* Is this an lddi instruction?  */
   3018      1.1     skrll 	    if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000)
   3019      1.1     skrll 	      {
   3020      1.1     skrll 		r = info->callbacks->warning
   3021      1.1     skrll 		  (info,
   3022      1.1     skrll 		   _("R_FRV_GOTTLSDESC12 not applied to an lddi instruction"),
   3023      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3024      1.1     skrll 		return FALSE;
   3025      1.1     skrll 	      }
   3026      1.1     skrll 
   3027      1.1     skrll 	    if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
   3028      1.1     skrll 					    relocation + rel->r_addend)
   3029      1.1     skrll 		&& TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
   3030      1.1     skrll 						  info))
   3031      1.1     skrll 	      {
   3032      1.1     skrll 		/* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
   3033      1.1     skrll 		   with setlos #tlsmofflo(symbol+offset), gr<C+1>.
   3034      1.1     skrll 		   Preserve the packing bit.  */
   3035      1.1     skrll 		insn = (insn & (unsigned long)0x80000000)
   3036      1.1     skrll 		  | ((insn + (unsigned long)0x02000000)
   3037      1.1     skrll 		     & (unsigned long)0x7e000000);
   3038      1.1     skrll 		insn |= (unsigned long)0x00fc0000;
   3039      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3040      1.1     skrll 
   3041      1.1     skrll 		r_type = R_FRV_TLSMOFFLO;
   3042      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3043      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3044      1.1     skrll 	      }
   3045      1.1     skrll 
   3046      1.1     skrll 	    else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
   3047      1.1     skrll 						 relocation + rel->r_addend))
   3048      1.1     skrll 	      {
   3049      1.1     skrll 		/* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
   3050      1.1     skrll 		   with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
   3051      1.1     skrll 		   Preserve the packing bit.  */
   3052      1.1     skrll 		insn = (insn & (unsigned long)0x80000000)
   3053      1.1     skrll 		  | ((insn + (unsigned long)0x02000000)
   3054      1.1     skrll 		     & (unsigned long)0x7e000000);
   3055      1.1     skrll 		insn |= (unsigned long)0x00f80000;
   3056      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3057      1.1     skrll 
   3058      1.1     skrll 		r_type = R_FRV_TLSMOFFHI;
   3059      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3060      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3061      1.1     skrll 	      }
   3062      1.1     skrll 
   3063      1.1     skrll 	    else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
   3064      1.1     skrll 	      {
   3065      1.1     skrll 		/* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
   3066      1.1     skrll 		   with ldi @(grB, #gottlsoff12(symbol+offset),
   3067      1.1     skrll 		   gr<C+1>.  Preserve the packing bit.  If gottlsoff12
   3068      1.1     skrll 		   overflows, we'll error out, but that's sort-of ok,
   3069      1.1     skrll 		   since we'd started with gottlsdesc12, that's actually
   3070      1.1     skrll 		   more demanding.  Compiling with -fPIE instead of
   3071      1.1     skrll 		   -fpie would fix it; linking with --relax should fix
   3072      1.1     skrll 		   it as well.  */
   3073      1.1     skrll 		insn = (insn & (unsigned long)0x80cbf000)
   3074      1.1     skrll 		  | ((insn + (unsigned long)0x02000000)
   3075      1.1     skrll 		     & (unsigned long)0x7e000000);
   3076      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3077      1.1     skrll 
   3078      1.1     skrll 		r_type = R_FRV_GOTTLSOFF12;
   3079      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3080      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3081      1.1     skrll 	      }
   3082      1.1     skrll 
   3083      1.1     skrll 	    break;
   3084      1.1     skrll 
   3085      1.1     skrll 	  case R_FRV_GOTTLSDESCHI:
   3086      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   3087      1.1     skrll 
   3088      1.1     skrll 	    /* Is this a sethi instruction?  */
   3089      1.1     skrll 	    if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
   3090      1.1     skrll 	      {
   3091      1.1     skrll 		r = info->callbacks->warning
   3092      1.1     skrll 		  (info,
   3093      1.1     skrll 		   _("R_FRV_GOTTLSDESCHI not applied to a sethi instruction"),
   3094      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3095      1.1     skrll 		return FALSE;
   3096      1.1     skrll 	      }
   3097      1.1     skrll 
   3098      1.1     skrll 	    if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
   3099      1.1     skrll 					    relocation + rel->r_addend)
   3100      1.1     skrll 		|| (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
   3101      1.1     skrll 		    && IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry)))
   3102      1.1     skrll 	      {
   3103      1.1     skrll 		/* Replace sethi with a nop.  Preserve the packing bit.  */
   3104      1.1     skrll 		insn &= (unsigned long)0x80000000;
   3105      1.1     skrll 		insn |= (unsigned long)0x00880000;
   3106      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3107      1.1     skrll 
   3108      1.1     skrll 		/* Nothing to relocate.  */
   3109      1.1     skrll 		continue;
   3110      1.1     skrll 	      }
   3111      1.1     skrll 
   3112      1.1     skrll 	    else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
   3113      1.1     skrll 	      {
   3114      1.1     skrll 		/* Simply decay GOTTLSDESC to GOTTLSOFF.  */
   3115      1.1     skrll 		r_type = R_FRV_GOTTLSOFFHI;
   3116      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3117      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3118      1.1     skrll 	      }
   3119      1.1     skrll 
   3120      1.1     skrll 	    break;
   3121      1.1     skrll 
   3122      1.1     skrll 	  case R_FRV_GOTTLSDESCLO:
   3123      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   3124      1.1     skrll 
   3125      1.1     skrll 	    /* Is this a setlo or setlos instruction?  */
   3126      1.1     skrll 	    if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
   3127      1.1     skrll 	      {
   3128      1.1     skrll 		r = info->callbacks->warning
   3129      1.1     skrll 		  (info,
   3130      1.1     skrll 		   _("R_FRV_GOTTLSDESCLO"
   3131      1.1     skrll 		     " not applied to a setlo or setlos instruction"),
   3132      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3133      1.1     skrll 		return FALSE;
   3134      1.1     skrll 	      }
   3135      1.1     skrll 
   3136      1.1     skrll 	    if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
   3137      1.1     skrll 					    relocation + rel->r_addend)
   3138      1.1     skrll 		|| (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
   3139      1.1     skrll 		    && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
   3140      1.1     skrll 	      {
   3141      1.1     skrll 		/* Replace setlo/setlos with a nop.  Preserve the
   3142      1.1     skrll 		   packing bit.  */
   3143      1.1     skrll 		insn &= (unsigned long)0x80000000;
   3144      1.1     skrll 		insn |= (unsigned long)0x00880000;
   3145      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3146      1.1     skrll 
   3147      1.1     skrll 		/* Nothing to relocate.  */
   3148      1.1     skrll 		continue;
   3149      1.1     skrll 	      }
   3150      1.1     skrll 
   3151      1.1     skrll 	    else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
   3152      1.1     skrll 	      {
   3153      1.1     skrll 		/* If the corresponding sethi (if it exists) decayed
   3154      1.1     skrll 		   to a nop, make sure this becomes (or already is) a
   3155      1.1     skrll 		   setlos, not setlo.  */
   3156      1.1     skrll 		if (IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry))
   3157      1.1     skrll 		  {
   3158      1.1     skrll 		    insn |= (unsigned long)0x00080000;
   3159      1.1     skrll 		    bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3160      1.1     skrll 		  }
   3161      1.1     skrll 
   3162      1.1     skrll 		/* Simply decay GOTTLSDESC to GOTTLSOFF.  */
   3163      1.1     skrll 		r_type = R_FRV_GOTTLSOFFLO;
   3164      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3165      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3166      1.1     skrll 	      }
   3167      1.1     skrll 
   3168      1.1     skrll 	    break;
   3169      1.1     skrll 
   3170      1.1     skrll 	  case R_FRV_TLSDESC_RELAX:
   3171      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   3172      1.1     skrll 
   3173      1.1     skrll 	    /* Is this an ldd instruction?  */
   3174      1.1     skrll 	    if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140)
   3175      1.1     skrll 	      {
   3176      1.1     skrll 		r = info->callbacks->warning
   3177      1.1     skrll 		  (info,
   3178      1.1     skrll 		   _("R_FRV_TLSDESC_RELAX not applied to an ldd instruction"),
   3179      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3180      1.1     skrll 		return FALSE;
   3181      1.1     skrll 	      }
   3182      1.1     skrll 
   3183      1.1     skrll 	    if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
   3184      1.1     skrll 					    relocation + rel->r_addend)
   3185      1.1     skrll 		&& TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
   3186      1.1     skrll 						  info))
   3187      1.1     skrll 	      {
   3188      1.1     skrll 		/* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
   3189      1.1     skrll 		   with setlos #tlsmofflo(symbol+offset), gr<C+1>.
   3190      1.1     skrll 		   Preserve the packing bit.  */
   3191      1.1     skrll 		insn = (insn & (unsigned long)0x80000000)
   3192      1.1     skrll 		  | ((insn + (unsigned long)0x02000000)
   3193      1.1     skrll 		     & (unsigned long)0x7e000000);
   3194      1.1     skrll 		insn |= (unsigned long)0x00fc0000;
   3195      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3196      1.1     skrll 
   3197      1.1     skrll 		r_type = R_FRV_TLSMOFFLO;
   3198      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3199      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3200      1.1     skrll 	      }
   3201      1.1     skrll 
   3202      1.1     skrll 	    else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
   3203      1.1     skrll 						 relocation + rel->r_addend))
   3204      1.1     skrll 	      {
   3205      1.1     skrll 		/* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
   3206      1.1     skrll 		   with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
   3207      1.1     skrll 		   Preserve the packing bit.  */
   3208      1.1     skrll 		insn = (insn & (unsigned long)0x80000000)
   3209      1.1     skrll 		  | ((insn + (unsigned long)0x02000000)
   3210      1.1     skrll 		     & (unsigned long)0x7e000000);
   3211      1.1     skrll 		insn |= (unsigned long)0x00f80000;
   3212      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3213      1.1     skrll 
   3214      1.1     skrll 		r_type = R_FRV_TLSMOFFHI;
   3215      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3216      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3217      1.1     skrll 	      }
   3218      1.1     skrll 
   3219      1.1     skrll 	    else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
   3220      1.1     skrll 		     && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
   3221      1.1     skrll 	      {
   3222      1.1     skrll 		/* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
   3223      1.1     skrll 		   with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
   3224      1.1     skrll 		   Preserve the packing bit.  */
   3225      1.1     skrll 		insn = (insn & (unsigned long)0x8003f000)
   3226      1.1     skrll 		  | (unsigned long)0x00c80000
   3227      1.1     skrll 		  | ((insn + (unsigned long)0x02000000)
   3228      1.1     skrll 		     & (unsigned long)0x7e000000);
   3229      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3230      1.1     skrll 
   3231      1.1     skrll 		r_type = R_FRV_GOTTLSOFF12;
   3232      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3233      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3234      1.1     skrll 	      }
   3235      1.1     skrll 
   3236      1.1     skrll 	    else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
   3237      1.1     skrll 	      {
   3238      1.1     skrll 		/* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
   3239      1.1     skrll 		   with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
   3240      1.1     skrll 		   Preserve the packing bit.  */
   3241      1.1     skrll 		insn = (insn & (unsigned long)0x81ffffbf)
   3242      1.1     skrll 		  | ((insn + (unsigned long)0x02000000)
   3243      1.1     skrll 		     & (unsigned long)0x7e000000);
   3244      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3245      1.1     skrll 
   3246      1.1     skrll 		/* #tlsoff(symbol+offset) is just a relaxation
   3247      1.1     skrll                     annotation, so there's nothing left to
   3248      1.1     skrll                     relocate.  */
   3249      1.1     skrll 		continue;
   3250      1.1     skrll 	      }
   3251      1.1     skrll 
   3252      1.1     skrll 	    break;
   3253      1.1     skrll 
   3254      1.1     skrll 	  case R_FRV_GETTLSOFF_RELAX:
   3255      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   3256      1.1     skrll 
   3257      1.1     skrll 	    /* Is this a calll or callil instruction?  */
   3258      1.1     skrll 	    if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000)
   3259      1.1     skrll 	      {
   3260      1.1     skrll 		r = info->callbacks->warning
   3261      1.1     skrll 		  (info,
   3262      1.1     skrll 		   _("R_FRV_GETTLSOFF_RELAX"
   3263      1.1     skrll 		     " not applied to a calll instruction"),
   3264      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3265      1.1     skrll 		return FALSE;
   3266      1.1     skrll 	      }
   3267      1.1     skrll 
   3268      1.1     skrll 	    if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
   3269      1.1     skrll 					    relocation + rel->r_addend)
   3270      1.1     skrll 		&& TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
   3271      1.1     skrll 						  info))
   3272      1.1     skrll 	      {
   3273      1.1     skrll 		/* Replace calll with a nop.  Preserve the packing bit.  */
   3274      1.1     skrll 		insn &= (unsigned long)0x80000000;
   3275      1.1     skrll 		insn |= (unsigned long)0x00880000;
   3276      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3277      1.1     skrll 
   3278      1.1     skrll 		/* Nothing to relocate.  */
   3279      1.1     skrll 		continue;
   3280      1.1     skrll 	      }
   3281      1.1     skrll 
   3282      1.1     skrll 	    else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
   3283      1.1     skrll 						 relocation + rel->r_addend))
   3284      1.1     skrll 	      {
   3285      1.1     skrll 		/* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
   3286      1.1     skrll 		   Preserve the packing bit.  */
   3287      1.1     skrll 		insn &= (unsigned long)0x80000000;
   3288      1.1     skrll 		insn |= (unsigned long)0x12f40000;
   3289      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3290      1.1     skrll 
   3291      1.1     skrll 		r_type = R_FRV_TLSMOFFLO;
   3292      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3293      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3294      1.1     skrll 	      }
   3295      1.1     skrll 
   3296      1.1     skrll 	    else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
   3297      1.1     skrll 	      {
   3298      1.1     skrll 		/* Replace calll with a nop.  Preserve the packing bit.  */
   3299      1.1     skrll 		insn &= (unsigned long)0x80000000;
   3300      1.1     skrll 		insn |= (unsigned long)0x00880000;
   3301      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3302      1.1     skrll 
   3303      1.1     skrll 		/* Nothing to relocate.  */
   3304      1.1     skrll 		continue;
   3305      1.1     skrll 	      }
   3306      1.1     skrll 
   3307      1.1     skrll 	    break;
   3308      1.1     skrll 
   3309      1.1     skrll 	  case R_FRV_GOTTLSOFF12:
   3310      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   3311      1.1     skrll 
   3312      1.1     skrll 	    /* Is this an ldi instruction?  */
   3313      1.1     skrll 	    if ((insn & (unsigned long)0x01fc0000) != 0x00c80000)
   3314      1.1     skrll 	      {
   3315      1.1     skrll 		r = info->callbacks->warning
   3316      1.1     skrll 		  (info,
   3317      1.1     skrll 		   _("R_FRV_GOTTLSOFF12 not applied to an ldi instruction"),
   3318      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3319      1.1     skrll 		return FALSE;
   3320      1.1     skrll 	      }
   3321      1.1     skrll 
   3322      1.1     skrll 	    if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
   3323      1.1     skrll 					      relocation + rel->r_addend))
   3324      1.1     skrll 	      {
   3325      1.1     skrll 		/* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
   3326      1.1     skrll 		   with setlos #tlsmofflo(symbol+offset), grC.
   3327      1.1     skrll 		   Preserve the packing bit.  */
   3328      1.1     skrll 		insn &= (unsigned long)0xfe000000;
   3329      1.1     skrll 		insn |= (unsigned long)0x00fc0000;
   3330      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3331      1.1     skrll 
   3332      1.1     skrll 		r_type = R_FRV_TLSMOFFLO;
   3333      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3334      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3335      1.1     skrll 	      }
   3336      1.1     skrll 
   3337      1.1     skrll 	    break;
   3338      1.1     skrll 
   3339      1.1     skrll 	  case R_FRV_GOTTLSOFFHI:
   3340      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   3341      1.1     skrll 
   3342      1.1     skrll 	    /* Is this a sethi instruction?  */
   3343      1.1     skrll 	    if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
   3344      1.1     skrll 	      {
   3345      1.1     skrll 		r = info->callbacks->warning
   3346      1.1     skrll 		  (info,
   3347      1.1     skrll 		   _("R_FRV_GOTTLSOFFHI not applied to a sethi instruction"),
   3348      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3349      1.1     skrll 		return FALSE;
   3350      1.1     skrll 	      }
   3351      1.1     skrll 
   3352      1.1     skrll 	    if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
   3353      1.1     skrll 					      relocation + rel->r_addend)
   3354      1.1     skrll 		|| (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
   3355      1.1     skrll 		    && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
   3356      1.1     skrll 	      {
   3357      1.1     skrll 		/* Replace sethi with a nop.  Preserve the packing bit.  */
   3358      1.1     skrll 		insn &= (unsigned long)0x80000000;
   3359      1.1     skrll 		insn |= (unsigned long)0x00880000;
   3360      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3361      1.1     skrll 
   3362      1.1     skrll 		/* Nothing to relocate.  */
   3363      1.1     skrll 		continue;
   3364      1.1     skrll 	      }
   3365      1.1     skrll 
   3366      1.1     skrll 	    break;
   3367      1.1     skrll 
   3368      1.1     skrll 	  case R_FRV_GOTTLSOFFLO:
   3369      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   3370      1.1     skrll 
   3371      1.1     skrll 	    /* Is this a setlo or setlos instruction?  */
   3372      1.1     skrll 	    if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
   3373      1.1     skrll 	      {
   3374      1.1     skrll 		r = info->callbacks->warning
   3375      1.1     skrll 		  (info,
   3376      1.1     skrll 		   _("R_FRV_GOTTLSOFFLO"
   3377      1.1     skrll 		     " not applied to a setlo or setlos instruction"),
   3378      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3379      1.1     skrll 		return FALSE;
   3380      1.1     skrll 	      }
   3381      1.1     skrll 
   3382      1.1     skrll 	    if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
   3383      1.1     skrll 					      relocation + rel->r_addend)
   3384      1.1     skrll 		|| (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
   3385      1.1     skrll 		    && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
   3386      1.1     skrll 	      {
   3387      1.1     skrll 		/* Replace setlo/setlos with a nop.  Preserve the
   3388      1.1     skrll 		   packing bit.  */
   3389      1.1     skrll 		insn &= (unsigned long)0x80000000;
   3390      1.1     skrll 		insn |= (unsigned long)0x00880000;
   3391      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3392      1.1     skrll 
   3393      1.1     skrll 		/* Nothing to relocate.  */
   3394      1.1     skrll 		continue;
   3395      1.1     skrll 	      }
   3396      1.1     skrll 
   3397      1.1     skrll 	    break;
   3398      1.1     skrll 
   3399      1.1     skrll 	  case R_FRV_TLSOFF_RELAX:
   3400      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   3401      1.1     skrll 
   3402      1.1     skrll 	    /* Is this an ld instruction?  */
   3403      1.1     skrll 	    if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100)
   3404      1.1     skrll 	      {
   3405      1.1     skrll 		r = info->callbacks->warning
   3406      1.1     skrll 		  (info,
   3407      1.1     skrll 		   _("R_FRV_TLSOFF_RELAX not applied to an ld instruction"),
   3408      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3409      1.1     skrll 		return FALSE;
   3410      1.1     skrll 	      }
   3411      1.1     skrll 
   3412      1.1     skrll 	    if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
   3413      1.1     skrll 					      relocation + rel->r_addend))
   3414      1.1     skrll 	      {
   3415      1.1     skrll 		/* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
   3416      1.1     skrll 		   with setlos #tlsmofflo(symbol+offset), grC.
   3417      1.1     skrll 		   Preserve the packing bit.  */
   3418      1.1     skrll 		insn &= (unsigned long)0xfe000000;
   3419      1.1     skrll 		insn |= (unsigned long)0x00fc0000;
   3420      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3421      1.1     skrll 
   3422      1.1     skrll 		r_type = R_FRV_TLSMOFFLO;
   3423      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3424      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3425      1.1     skrll 	      }
   3426      1.1     skrll 
   3427      1.1     skrll 	    else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
   3428      1.1     skrll 		     && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
   3429      1.1     skrll 	      {
   3430      1.1     skrll 		/* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
   3431      1.1     skrll 		   with ldi @(grB, #gottlsoff12(symbol+offset), grC.
   3432      1.1     skrll 		   Preserve the packing bit.  */
   3433      1.1     skrll 		insn = (insn & (unsigned long)0xfe03f000)
   3434      1.1     skrll 		  | (unsigned long)0x00c80000;;
   3435      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3436      1.1     skrll 
   3437      1.1     skrll 		r_type = R_FRV_GOTTLSOFF12;
   3438      1.1     skrll 		howto  = elf32_frv_howto_table + r_type;
   3439      1.1     skrll 		rel->r_info = ELF32_R_INFO (r_symndx, r_type);
   3440      1.1     skrll 	      }
   3441      1.1     skrll 
   3442      1.1     skrll 	    break;
   3443      1.1     skrll 
   3444      1.1     skrll 	  case R_FRV_TLSMOFFHI:
   3445      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   3446      1.1     skrll 
   3447      1.1     skrll 	    /* Is this a sethi instruction?  */
   3448      1.1     skrll 	    if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
   3449      1.1     skrll 	      {
   3450      1.1     skrll 		r = info->callbacks->warning
   3451      1.1     skrll 		  (info,
   3452      1.1     skrll 		   _("R_FRV_TLSMOFFHI not applied to a sethi instruction"),
   3453      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3454      1.1     skrll 		return FALSE;
   3455      1.1     skrll 	      }
   3456      1.1     skrll 
   3457      1.1     skrll 	    if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
   3458      1.1     skrll 					       info))
   3459      1.1     skrll 	      {
   3460      1.1     skrll 		/* Replace sethi with a nop.  Preserve the packing bit.  */
   3461      1.1     skrll 		insn &= (unsigned long)0x80000000;
   3462      1.1     skrll 		insn |= (unsigned long)0x00880000;
   3463      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3464      1.1     skrll 
   3465      1.1     skrll 		/* Nothing to relocate.  */
   3466      1.1     skrll 		continue;
   3467      1.1     skrll 	      }
   3468      1.1     skrll 
   3469      1.1     skrll 	    break;
   3470      1.1     skrll 
   3471      1.1     skrll 	  case R_FRV_TLSMOFFLO:
   3472      1.1     skrll 	    insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
   3473      1.1     skrll 
   3474      1.1     skrll 	    /* Is this a setlo or setlos instruction?  */
   3475      1.1     skrll 	    if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
   3476      1.1     skrll 	      {
   3477      1.1     skrll 		r = info->callbacks->warning
   3478      1.1     skrll 		  (info,
   3479      1.1     skrll 		   _("R_FRV_TLSMOFFLO"
   3480      1.1     skrll 		     " not applied to a setlo or setlos instruction"),
   3481      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3482      1.1     skrll 		return FALSE;
   3483      1.1     skrll 	      }
   3484      1.1     skrll 
   3485      1.1     skrll 	    if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
   3486      1.1     skrll 					       info))
   3487      1.1     skrll 	      /* If the corresponding sethi (if it exists) decayed
   3488      1.1     skrll 		 to a nop, make sure this becomes (or already is) a
   3489      1.1     skrll 		 setlos, not setlo.  */
   3490      1.1     skrll 	      {
   3491      1.1     skrll 		insn |= (unsigned long)0x00080000;
   3492      1.1     skrll 		bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
   3493      1.1     skrll 	      }
   3494      1.1     skrll 
   3495      1.1     skrll 	    break;
   3496      1.1     skrll 
   3497      1.1     skrll 	    /*
   3498      1.1     skrll 	      There's nothing to relax in these:
   3499      1.1     skrll 		R_FRV_TLSDESC_VALUE
   3500      1.1     skrll 		R_FRV_TLSOFF
   3501      1.1     skrll 		R_FRV_TLSMOFF12
   3502      1.1     skrll 		R_FRV_TLSMOFFHI
   3503      1.1     skrll 		R_FRV_TLSMOFFLO
   3504      1.1     skrll 		R_FRV_TLSMOFF
   3505      1.1     skrll 	    */
   3506      1.1     skrll 
   3507      1.1     skrll 	  default:
   3508      1.1     skrll 	    break;
   3509      1.1     skrll 	  }
   3510      1.1     skrll 
   3511      1.1     skrll       switch (r_type)
   3512      1.1     skrll 	{
   3513      1.1     skrll 	case R_FRV_LABEL24:
   3514      1.1     skrll 	  check_segment[0] = isec_segment;
   3515      1.1     skrll 	  if (! IS_FDPIC (output_bfd))
   3516      1.1     skrll 	    check_segment[1] = isec_segment;
   3517      1.1     skrll 	  else if (picrel->plt)
   3518      1.1     skrll 	    {
   3519      1.1     skrll 	      relocation = frvfdpic_plt_section (info)->output_section->vma
   3520      1.1     skrll 		+ frvfdpic_plt_section (info)->output_offset
   3521      1.1     skrll 		+ picrel->plt_entry;
   3522      1.1     skrll 	      check_segment[1] = plt_segment;
   3523      1.1     skrll 	    }
   3524      1.1     skrll 	  /* We don't want to warn on calls to undefined weak symbols,
   3525      1.1     skrll 	     as calls to them must be protected by non-NULL tests
   3526      1.1     skrll 	     anyway, and unprotected calls would invoke undefined
   3527      1.1     skrll 	     behavior.  */
   3528      1.1     skrll 	  else if (picrel->symndx == -1
   3529      1.1     skrll 		   && picrel->d.h->root.type == bfd_link_hash_undefweak)
   3530      1.1     skrll 	    check_segment[1] = check_segment[0];
   3531      1.1     skrll 	  else
   3532      1.1     skrll 	    check_segment[1] = sec
   3533      1.1     skrll 	      ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
   3534      1.1     skrll 	      : (unsigned)-1;
   3535      1.1     skrll 	  break;
   3536      1.1     skrll 
   3537      1.1     skrll 	case R_FRV_GOT12:
   3538      1.1     skrll 	case R_FRV_GOTHI:
   3539      1.1     skrll 	case R_FRV_GOTLO:
   3540      1.1     skrll 	  relocation = picrel->got_entry;
   3541      1.1     skrll 	  check_segment[0] = check_segment[1] = got_segment;
   3542      1.1     skrll 	  break;
   3543      1.1     skrll 
   3544      1.1     skrll 	case R_FRV_FUNCDESC_GOT12:
   3545      1.1     skrll 	case R_FRV_FUNCDESC_GOTHI:
   3546      1.1     skrll 	case R_FRV_FUNCDESC_GOTLO:
   3547      1.1     skrll 	  relocation = picrel->fdgot_entry;
   3548      1.1     skrll 	  check_segment[0] = check_segment[1] = got_segment;
   3549      1.1     skrll 	  break;
   3550      1.1     skrll 
   3551      1.1     skrll 	case R_FRV_GOTOFFHI:
   3552      1.1     skrll 	case R_FRV_GOTOFF12:
   3553      1.1     skrll 	case R_FRV_GOTOFFLO:
   3554      1.1     skrll 	  relocation -= frvfdpic_got_section (info)->output_section->vma
   3555      1.1     skrll 	    + frvfdpic_got_section (info)->output_offset
   3556      1.1     skrll 	    + frvfdpic_got_initial_offset (info);
   3557      1.1     skrll 	  check_segment[0] = got_segment;
   3558      1.1     skrll 	  check_segment[1] = sec
   3559      1.1     skrll 	    ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
   3560      1.1     skrll 	    : (unsigned)-1;
   3561      1.1     skrll 	  break;
   3562      1.1     skrll 
   3563      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFF12:
   3564      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFHI:
   3565      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFLO:
   3566      1.1     skrll 	  relocation = picrel->fd_entry;
   3567      1.1     skrll 	  check_segment[0] = check_segment[1] = got_segment;
   3568      1.1     skrll 	  break;
   3569      1.1     skrll 
   3570      1.1     skrll 	case R_FRV_FUNCDESC:
   3571      1.1     skrll 	  {
   3572      1.1     skrll 	    int dynindx;
   3573      1.1     skrll 	    bfd_vma addend = rel->r_addend;
   3574      1.1     skrll 
   3575      1.1     skrll 	    if (! (h && h->root.type == bfd_link_hash_undefweak
   3576      1.1     skrll 		   && FRVFDPIC_SYM_LOCAL (info, h)))
   3577      1.1     skrll 	      {
   3578      1.1     skrll 		/* If the symbol is dynamic and there may be dynamic
   3579      1.1     skrll 		   symbol resolution because we are or are linked with a
   3580      1.1     skrll 		   shared library, emit a FUNCDESC relocation such that
   3581      1.1     skrll 		   the dynamic linker will allocate the function
   3582      1.1     skrll 		   descriptor.  If the symbol needs a non-local function
   3583      1.1     skrll 		   descriptor but binds locally (e.g., its visibility is
   3584      1.1     skrll 		   protected, emit a dynamic relocation decayed to
   3585      1.1     skrll 		   section+offset.  */
   3586      1.1     skrll 		if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)
   3587      1.1     skrll 		    && FRVFDPIC_SYM_LOCAL (info, h)
   3588      1.1     skrll 		    && !(info->executable && !info->pie))
   3589      1.1     skrll 		  {
   3590      1.1     skrll 		    dynindx = elf_section_data (h->root.u.def.section
   3591      1.1     skrll 						->output_section)->dynindx;
   3592      1.1     skrll 		    addend += h->root.u.def.section->output_offset
   3593      1.1     skrll 		      + h->root.u.def.value;
   3594      1.1     skrll 		  }
   3595      1.1     skrll 		else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h))
   3596      1.1     skrll 		  {
   3597      1.1     skrll 		    if (addend)
   3598      1.1     skrll 		      {
   3599      1.1     skrll 			info->callbacks->warning
   3600      1.1     skrll 			  (info, _("R_FRV_FUNCDESC references dynamic symbol with nonzero addend"),
   3601      1.1     skrll 			   name, input_bfd, input_section, rel->r_offset);
   3602      1.1     skrll 			return FALSE;
   3603      1.1     skrll 		      }
   3604      1.1     skrll 		    dynindx = h->dynindx;
   3605      1.1     skrll 		  }
   3606      1.1     skrll 		else
   3607      1.1     skrll 		  {
   3608      1.1     skrll 		    /* Otherwise, we know we have a private function
   3609      1.1     skrll 		       descriptor, so reference it directly.  */
   3610      1.1     skrll 		    BFD_ASSERT (picrel->privfd);
   3611      1.1     skrll 		    r_type = R_FRV_32;
   3612      1.1     skrll 		    dynindx = elf_section_data (frvfdpic_got_section (info)
   3613      1.1     skrll 						->output_section)->dynindx;
   3614      1.1     skrll 		    addend = frvfdpic_got_section (info)->output_offset
   3615      1.1     skrll 		      + frvfdpic_got_initial_offset (info)
   3616      1.1     skrll 		      + picrel->fd_entry;
   3617      1.1     skrll 		  }
   3618      1.1     skrll 
   3619      1.1     skrll 		/* If there is room for dynamic symbol resolution, emit
   3620      1.1     skrll 		   the dynamic relocation.  However, if we're linking an
   3621      1.1     skrll 		   executable at a fixed location, we won't have emitted a
   3622      1.1     skrll 		   dynamic symbol entry for the got section, so idx will
   3623      1.1     skrll 		   be zero, which means we can and should compute the
   3624      1.1     skrll 		   address of the private descriptor ourselves.  */
   3625      1.1     skrll 		if (info->executable && !info->pie
   3626      1.1     skrll 		    && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h)))
   3627      1.1     skrll 		  {
   3628      1.1     skrll 		    addend += frvfdpic_got_section (info)->output_section->vma;
   3629      1.1     skrll 		    if ((bfd_get_section_flags (output_bfd,
   3630      1.1     skrll 						input_section->output_section)
   3631      1.1     skrll 			 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
   3632      1.1     skrll 		      {
   3633      1.1     skrll 			bfd_vma offset;
   3634      1.1     skrll 
   3635      1.1     skrll 			if (_frvfdpic_osec_readonly_p (output_bfd,
   3636      1.1     skrll 						       input_section
   3637      1.1     skrll 						       ->output_section))
   3638      1.1     skrll 			  {
   3639      1.1     skrll 			    info->callbacks->warning
   3640      1.1     skrll 			      (info,
   3641      1.1     skrll 			       _("cannot emit fixups in read-only section"),
   3642      1.1     skrll 			       name, input_bfd, input_section, rel->r_offset);
   3643      1.1     skrll 			    return FALSE;
   3644      1.1     skrll 			  }
   3645      1.1     skrll 
   3646      1.1     skrll 			offset = _bfd_elf_section_offset
   3647      1.1     skrll 			  (output_bfd, info,
   3648      1.1     skrll 			   input_section, rel->r_offset);
   3649      1.1     skrll 
   3650      1.1     skrll 			if (offset != (bfd_vma)-1)
   3651      1.1     skrll 			  _frvfdpic_add_rofixup (output_bfd,
   3652      1.1     skrll 						 frvfdpic_gotfixup_section
   3653      1.1     skrll 						 (info),
   3654      1.1     skrll 						 offset + input_section
   3655      1.1     skrll 						 ->output_section->vma
   3656      1.1     skrll 						 + input_section->output_offset,
   3657      1.1     skrll 						 picrel);
   3658      1.1     skrll 		      }
   3659      1.1     skrll 		  }
   3660      1.1     skrll 		else if ((bfd_get_section_flags (output_bfd,
   3661      1.1     skrll 						 input_section->output_section)
   3662      1.1     skrll 			  & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
   3663      1.1     skrll 		  {
   3664      1.1     skrll 		    bfd_vma offset;
   3665      1.1     skrll 
   3666      1.1     skrll 		    if (_frvfdpic_osec_readonly_p (output_bfd,
   3667      1.1     skrll 						   input_section
   3668      1.1     skrll 						   ->output_section))
   3669      1.1     skrll 		      {
   3670      1.1     skrll 			info->callbacks->warning
   3671      1.1     skrll 			  (info,
   3672      1.1     skrll 			   _("cannot emit dynamic relocations in read-only section"),
   3673      1.1     skrll 			   name, input_bfd, input_section, rel->r_offset);
   3674      1.1     skrll 			return FALSE;
   3675      1.1     skrll 		      }
   3676      1.1     skrll 
   3677      1.1     skrll 		    offset = _bfd_elf_section_offset
   3678      1.1     skrll 		      (output_bfd, info,
   3679      1.1     skrll 		       input_section, rel->r_offset);
   3680      1.1     skrll 
   3681      1.1     skrll 		    if (offset != (bfd_vma)-1)
   3682      1.1     skrll 		      _frvfdpic_add_dyn_reloc (output_bfd,
   3683      1.1     skrll 					       frvfdpic_gotrel_section (info),
   3684      1.1     skrll 					       offset + input_section
   3685      1.1     skrll 					       ->output_section->vma
   3686      1.1     skrll 					       + input_section->output_offset,
   3687      1.1     skrll 					       r_type, dynindx, addend, picrel);
   3688      1.1     skrll 		  }
   3689      1.1     skrll 		else
   3690      1.1     skrll 		  addend += frvfdpic_got_section (info)->output_section->vma;
   3691      1.1     skrll 	      }
   3692      1.1     skrll 
   3693      1.1     skrll 	    /* We want the addend in-place because dynamic
   3694      1.1     skrll 	       relocations are REL.  Setting relocation to it should
   3695      1.1     skrll 	       arrange for it to be installed.  */
   3696      1.1     skrll 	    relocation = addend - rel->r_addend;
   3697      1.1     skrll 	  }
   3698      1.1     skrll 	  check_segment[0] = check_segment[1] = got_segment;
   3699      1.1     skrll 	  break;
   3700      1.1     skrll 
   3701      1.1     skrll 	case R_FRV_32:
   3702      1.1     skrll 	  if (! IS_FDPIC (output_bfd))
   3703      1.1     skrll 	    {
   3704      1.1     skrll 	      check_segment[0] = check_segment[1] = -1;
   3705      1.1     skrll 	      break;
   3706      1.1     skrll 	    }
   3707      1.1     skrll 	  /* Fall through.  */
   3708      1.1     skrll 	case R_FRV_FUNCDESC_VALUE:
   3709      1.1     skrll 	  {
   3710      1.1     skrll 	    int dynindx;
   3711      1.1     skrll 	    bfd_vma addend = rel->r_addend;
   3712      1.1     skrll 
   3713      1.1     skrll 	    /* If the symbol is dynamic but binds locally, use
   3714      1.1     skrll 	       section+offset.  */
   3715      1.1     skrll 	    if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
   3716      1.1     skrll 	      {
   3717      1.1     skrll 		if (addend && r_type == R_FRV_FUNCDESC_VALUE)
   3718      1.1     skrll 		  {
   3719      1.1     skrll 		    info->callbacks->warning
   3720      1.1     skrll 		      (info, _("R_FRV_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
   3721      1.1     skrll 		       name, input_bfd, input_section, rel->r_offset);
   3722      1.1     skrll 		    return FALSE;
   3723      1.1     skrll 		  }
   3724      1.1     skrll 		dynindx = h->dynindx;
   3725      1.1     skrll 	      }
   3726      1.1     skrll 	    else
   3727      1.1     skrll 	      {
   3728      1.1     skrll 		if (h)
   3729      1.1     skrll 		  addend += h->root.u.def.value;
   3730      1.1     skrll 		else
   3731      1.1     skrll 		  addend += sym->st_value;
   3732      1.1     skrll 		if (osec)
   3733      1.1     skrll 		  addend += osec->output_offset;
   3734      1.1     skrll 		if (osec && osec->output_section
   3735      1.1     skrll 		    && ! bfd_is_abs_section (osec->output_section)
   3736      1.1     skrll 		    && ! bfd_is_und_section (osec->output_section))
   3737      1.1     skrll 		  dynindx = elf_section_data (osec->output_section)->dynindx;
   3738      1.1     skrll 		else
   3739      1.1     skrll 		  dynindx = 0;
   3740      1.1     skrll 	      }
   3741      1.1     skrll 
   3742      1.1     skrll 	    /* If we're linking an executable at a fixed address, we
   3743      1.1     skrll 	       can omit the dynamic relocation as long as the symbol
   3744      1.1     skrll 	       is defined in the current link unit (which is implied
   3745      1.1     skrll 	       by its output section not being NULL).  */
   3746      1.1     skrll 	    if (info->executable && !info->pie
   3747      1.1     skrll 		&& (!h || FRVFDPIC_SYM_LOCAL (info, h)))
   3748      1.1     skrll 	      {
   3749      1.1     skrll 		if (osec)
   3750      1.1     skrll 		  addend += osec->output_section->vma;
   3751      1.1     skrll 		if (IS_FDPIC (input_bfd)
   3752      1.1     skrll 		    && (bfd_get_section_flags (output_bfd,
   3753      1.1     skrll 					       input_section->output_section)
   3754      1.1     skrll 			& (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
   3755      1.1     skrll 		  {
   3756      1.1     skrll 		    if (_frvfdpic_osec_readonly_p (output_bfd,
   3757      1.1     skrll 						   input_section
   3758      1.1     skrll 						   ->output_section))
   3759      1.1     skrll 		      {
   3760      1.1     skrll 			info->callbacks->warning
   3761      1.1     skrll 			  (info,
   3762      1.1     skrll 			   _("cannot emit fixups in read-only section"),
   3763      1.1     skrll 			   name, input_bfd, input_section, rel->r_offset);
   3764      1.1     skrll 			return FALSE;
   3765      1.1     skrll 		      }
   3766      1.1     skrll 		    if (!h || h->root.type != bfd_link_hash_undefweak)
   3767      1.1     skrll 		      {
   3768      1.1     skrll 			bfd_vma offset = _bfd_elf_section_offset
   3769      1.1     skrll 			  (output_bfd, info,
   3770      1.1     skrll 			   input_section, rel->r_offset);
   3771      1.1     skrll 
   3772      1.1     skrll 			if (offset != (bfd_vma)-1)
   3773      1.1     skrll 			  {
   3774      1.1     skrll 			    _frvfdpic_add_rofixup (output_bfd,
   3775      1.1     skrll 						   frvfdpic_gotfixup_section
   3776      1.1     skrll 						   (info),
   3777      1.1     skrll 						   offset + input_section
   3778      1.1     skrll 						   ->output_section->vma
   3779      1.1     skrll 						   + input_section->output_offset,
   3780      1.1     skrll 						   picrel);
   3781      1.1     skrll 			    if (r_type == R_FRV_FUNCDESC_VALUE)
   3782      1.1     skrll 			      _frvfdpic_add_rofixup
   3783      1.1     skrll 				(output_bfd,
   3784      1.1     skrll 				 frvfdpic_gotfixup_section (info),
   3785      1.1     skrll 				 offset
   3786      1.1     skrll 				 + input_section->output_section->vma
   3787      1.1     skrll 				 + input_section->output_offset + 4, picrel);
   3788      1.1     skrll 			  }
   3789      1.1     skrll 		      }
   3790      1.1     skrll 		  }
   3791      1.1     skrll 	      }
   3792      1.1     skrll 	    else
   3793      1.1     skrll 	      {
   3794      1.1     skrll 		if ((bfd_get_section_flags (output_bfd,
   3795      1.1     skrll 					    input_section->output_section)
   3796      1.1     skrll 		     & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
   3797      1.1     skrll 		  {
   3798      1.1     skrll 		    bfd_vma offset;
   3799      1.1     skrll 
   3800      1.1     skrll 		    if (_frvfdpic_osec_readonly_p (output_bfd,
   3801      1.1     skrll 						   input_section
   3802      1.1     skrll 						   ->output_section))
   3803      1.1     skrll 		      {
   3804      1.1     skrll 			info->callbacks->warning
   3805      1.1     skrll 			  (info,
   3806      1.1     skrll 			   _("cannot emit dynamic relocations in read-only section"),
   3807      1.1     skrll 			   name, input_bfd, input_section, rel->r_offset);
   3808      1.1     skrll 			return FALSE;
   3809      1.1     skrll 		      }
   3810      1.1     skrll 
   3811      1.1     skrll 		    offset = _bfd_elf_section_offset
   3812      1.1     skrll 		      (output_bfd, info,
   3813      1.1     skrll 		       input_section, rel->r_offset);
   3814      1.1     skrll 
   3815      1.1     skrll 		    if (offset != (bfd_vma)-1)
   3816      1.1     skrll 		      _frvfdpic_add_dyn_reloc (output_bfd,
   3817      1.1     skrll 					       frvfdpic_gotrel_section (info),
   3818      1.1     skrll 					       offset + input_section
   3819      1.1     skrll 					       ->output_section->vma
   3820      1.1     skrll 					       + input_section->output_offset,
   3821      1.1     skrll 					       r_type, dynindx, addend, picrel);
   3822      1.1     skrll 		  }
   3823      1.1     skrll 		else if (osec)
   3824      1.1     skrll 		  addend += osec->output_section->vma;
   3825      1.1     skrll 		/* We want the addend in-place because dynamic
   3826      1.1     skrll 		   relocations are REL.  Setting relocation to it
   3827      1.1     skrll 		   should arrange for it to be installed.  */
   3828      1.1     skrll 		relocation = addend - rel->r_addend;
   3829      1.1     skrll 	      }
   3830      1.1     skrll 
   3831      1.1     skrll 	    if (r_type == R_FRV_FUNCDESC_VALUE)
   3832      1.1     skrll 	      {
   3833      1.1     skrll 		/* If we've omitted the dynamic relocation, just emit
   3834      1.1     skrll 		   the fixed addresses of the symbol and of the local
   3835      1.1     skrll 		   GOT base offset.  */
   3836      1.1     skrll 		if (info->executable && !info->pie
   3837      1.1     skrll 		    && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
   3838      1.1     skrll 		  bfd_put_32 (output_bfd,
   3839      1.1     skrll 			      frvfdpic_got_section (info)->output_section->vma
   3840      1.1     skrll 			      + frvfdpic_got_section (info)->output_offset
   3841      1.1     skrll 			      + frvfdpic_got_initial_offset (info),
   3842      1.1     skrll 			      contents + rel->r_offset + 4);
   3843      1.1     skrll 		else
   3844      1.1     skrll 		  /* A function descriptor used for lazy or local
   3845      1.1     skrll 		     resolving is initialized such that its high word
   3846      1.1     skrll 		     contains the output section index in which the
   3847      1.1     skrll 		     PLT entries are located, and the low word
   3848      1.1     skrll 		     contains the offset of the lazy PLT entry entry
   3849      1.1     skrll 		     point into that section.  */
   3850      1.1     skrll 		  bfd_put_32 (output_bfd,
   3851      1.1     skrll 			      h && ! FRVFDPIC_SYM_LOCAL (info, h)
   3852      1.1     skrll 			      ? 0
   3853      1.1     skrll 			      : _frvfdpic_osec_to_segment (output_bfd,
   3854      1.1     skrll 							   sec
   3855      1.1     skrll 							   ->output_section),
   3856      1.1     skrll 			      contents + rel->r_offset + 4);
   3857      1.1     skrll 	      }
   3858      1.1     skrll 	  }
   3859      1.1     skrll 	  check_segment[0] = check_segment[1] = got_segment;
   3860      1.1     skrll 	  break;
   3861      1.1     skrll 
   3862      1.1     skrll 	case R_FRV_GPREL12:
   3863      1.1     skrll 	case R_FRV_GPRELU12:
   3864      1.1     skrll 	case R_FRV_GPREL32:
   3865      1.1     skrll 	case R_FRV_GPRELHI:
   3866      1.1     skrll 	case R_FRV_GPRELLO:
   3867      1.1     skrll 	  check_segment[0] = gprel_segment;
   3868      1.1     skrll 	  check_segment[1] = sec
   3869      1.1     skrll 	    ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
   3870      1.1     skrll 	    : (unsigned)-1;
   3871      1.1     skrll 	  break;
   3872      1.1     skrll 
   3873      1.1     skrll 	case R_FRV_GETTLSOFF:
   3874      1.1     skrll 	  relocation = frvfdpic_plt_section (info)->output_section->vma
   3875      1.1     skrll 	    + frvfdpic_plt_section (info)->output_offset
   3876      1.1     skrll 	    + picrel->tlsplt_entry;
   3877      1.1     skrll 	  BFD_ASSERT (picrel->tlsplt_entry != (bfd_vma)-1
   3878      1.1     skrll 		      && picrel->tlsdesc_entry);
   3879      1.1     skrll 	  check_segment[0] = isec_segment;
   3880      1.1     skrll 	  check_segment[1] = plt_segment;
   3881      1.1     skrll 	  break;
   3882      1.1     skrll 
   3883      1.1     skrll 	case R_FRV_GOTTLSDESC12:
   3884      1.1     skrll 	case R_FRV_GOTTLSDESCHI:
   3885      1.1     skrll 	case R_FRV_GOTTLSDESCLO:
   3886      1.1     skrll 	  BFD_ASSERT (picrel->tlsdesc_entry);
   3887      1.1     skrll 	  relocation = picrel->tlsdesc_entry;
   3888      1.1     skrll 	  check_segment[0] = tls_segment;
   3889      1.1     skrll 	  check_segment[1] = sec
   3890      1.1     skrll 	    && ! bfd_is_abs_section (sec)
   3891      1.1     skrll 	    && ! bfd_is_und_section (sec)
   3892      1.1     skrll 	    ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
   3893      1.1     skrll 	    : tls_segment;
   3894      1.1     skrll 	  break;
   3895      1.1     skrll 
   3896      1.1     skrll 	case R_FRV_TLSMOFF12:
   3897      1.1     skrll 	case R_FRV_TLSMOFFHI:
   3898      1.1     skrll 	case R_FRV_TLSMOFFLO:
   3899      1.1     skrll 	case R_FRV_TLSMOFF:
   3900      1.1     skrll 	  check_segment[0] = tls_segment;
   3901      1.1     skrll 	  if (! sec)
   3902      1.1     skrll 	    check_segment[1] = -1;
   3903      1.1     skrll 	  else if (bfd_is_abs_section (sec)
   3904      1.1     skrll 		   || bfd_is_und_section (sec))
   3905      1.1     skrll 	    {
   3906      1.1     skrll 	      relocation = 0;
   3907      1.1     skrll 	      check_segment[1] = tls_segment;
   3908      1.1     skrll 	    }
   3909      1.1     skrll 	  else if (sec->output_section)
   3910      1.1     skrll 	    {
   3911      1.1     skrll 	      relocation -= tls_biased_base (info);
   3912      1.1     skrll 	      check_segment[1] =
   3913      1.1     skrll 		_frvfdpic_osec_to_segment (output_bfd, sec->output_section);
   3914      1.1     skrll 	    }
   3915      1.1     skrll 	  else
   3916      1.1     skrll 	    check_segment[1] = -1;
   3917      1.1     skrll 	  break;
   3918      1.1     skrll 
   3919      1.1     skrll 	case R_FRV_GOTTLSOFF12:
   3920      1.1     skrll 	case R_FRV_GOTTLSOFFHI:
   3921      1.1     skrll 	case R_FRV_GOTTLSOFFLO:
   3922      1.1     skrll 	  BFD_ASSERT (picrel->tlsoff_entry);
   3923      1.1     skrll 	  relocation = picrel->tlsoff_entry;
   3924      1.1     skrll 	  check_segment[0] = tls_segment;
   3925      1.1     skrll 	  check_segment[1] = sec
   3926      1.1     skrll 	    && ! bfd_is_abs_section (sec)
   3927      1.1     skrll 	    && ! bfd_is_und_section (sec)
   3928      1.1     skrll 	    ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
   3929      1.1     skrll 	    : tls_segment;
   3930      1.1     skrll 	  break;
   3931      1.1     skrll 
   3932      1.1     skrll 	case R_FRV_TLSDESC_VALUE:
   3933      1.1     skrll 	case R_FRV_TLSOFF:
   3934      1.1     skrll 	  /* These shouldn't be present in input object files.  */
   3935      1.1     skrll 	  check_segment[0] = check_segment[1] = isec_segment;
   3936      1.1     skrll 	  break;
   3937      1.1     skrll 
   3938      1.1     skrll 	case R_FRV_TLSDESC_RELAX:
   3939      1.1     skrll 	case R_FRV_GETTLSOFF_RELAX:
   3940      1.1     skrll 	case R_FRV_TLSOFF_RELAX:
   3941      1.1     skrll 	  /* These are just annotations for relaxation, nothing to do
   3942      1.1     skrll 	     here.  */
   3943      1.1     skrll 	  continue;
   3944      1.1     skrll 
   3945      1.1     skrll 	default:
   3946      1.1     skrll 	  check_segment[0] = isec_segment;
   3947      1.1     skrll 	  check_segment[1] = sec
   3948      1.1     skrll 	    ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
   3949      1.1     skrll 	    : (unsigned)-1;
   3950      1.1     skrll 	  break;
   3951      1.1     skrll 	}
   3952      1.1     skrll 
   3953      1.1     skrll       if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd))
   3954      1.1     skrll 	{
   3955      1.1     skrll 	  /* If you take this out, remove the #error from fdpic-static-6.d
   3956      1.1     skrll 	     in the ld testsuite.  */
   3957      1.1     skrll 	  /* This helps catch problems in GCC while we can't do more
   3958      1.1     skrll 	     than static linking.  The idea is to test whether the
   3959      1.1     skrll 	     input file basename is crt0.o only once.  */
   3960      1.1     skrll 	  if (silence_segment_error == 1)
   3961      1.1     skrll 	    silence_segment_error =
   3962      1.1     skrll 	      (strlen (input_bfd->filename) == 6
   3963      1.1     skrll 	       && strcmp (input_bfd->filename, "crt0.o") == 0)
   3964      1.1     skrll 	      || (strlen (input_bfd->filename) > 6
   3965      1.1     skrll 		  && strcmp (input_bfd->filename
   3966      1.1     skrll 			     + strlen (input_bfd->filename) - 7,
   3967      1.1     skrll 			     "/crt0.o") == 0)
   3968      1.1     skrll 	      ? -1 : 0;
   3969      1.1     skrll 	  if (!silence_segment_error
   3970      1.1     skrll 	      /* We don't want duplicate errors for undefined
   3971      1.1     skrll 		 symbols.  */
   3972      1.1     skrll 	      && !(picrel && picrel->symndx == -1
   3973      1.1     skrll 		   && picrel->d.h->root.type == bfd_link_hash_undefined))
   3974      1.1     skrll 	    {
   3975      1.1     skrll 	      if (info->shared || info->pie)
   3976      1.1     skrll 		(*_bfd_error_handler)
   3977      1.1     skrll 		  (_("%B(%A+0x%lx): reloc against `%s': %s"),
   3978      1.1     skrll 		   input_bfd, input_section, (long)rel->r_offset, name,
   3979      1.1     skrll 		   _("relocation references a different segment"));
   3980      1.1     skrll 	      else
   3981      1.1     skrll 		info->callbacks->warning
   3982      1.1     skrll 		  (info,
   3983      1.1     skrll 		   _("relocation references a different segment"),
   3984      1.1     skrll 		   name, input_bfd, input_section, rel->r_offset);
   3985      1.1     skrll 	    }
   3986      1.1     skrll 	  if (!silence_segment_error && (info->shared || info->pie))
   3987      1.1     skrll 	    return FALSE;
   3988      1.1     skrll 	  elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC;
   3989      1.1     skrll 	}
   3990      1.1     skrll 
   3991      1.1     skrll       switch (r_type)
   3992      1.1     skrll 	{
   3993      1.1     skrll 	case R_FRV_GOTOFFHI:
   3994      1.1     skrll 	case R_FRV_TLSMOFFHI:
   3995      1.1     skrll 	  /* We need the addend to be applied before we shift the
   3996      1.1     skrll 	     value right.  */
   3997      1.1     skrll 	  relocation += rel->r_addend;
   3998      1.1     skrll 	  /* Fall through.  */
   3999      1.1     skrll 	case R_FRV_GOTHI:
   4000      1.1     skrll 	case R_FRV_FUNCDESC_GOTHI:
   4001      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFHI:
   4002      1.1     skrll 	case R_FRV_GOTTLSOFFHI:
   4003      1.1     skrll 	case R_FRV_GOTTLSDESCHI:
   4004      1.1     skrll 	  relocation >>= 16;
   4005      1.1     skrll 	  /* Fall through.  */
   4006      1.1     skrll 
   4007      1.1     skrll 	case R_FRV_GOTLO:
   4008      1.1     skrll 	case R_FRV_FUNCDESC_GOTLO:
   4009      1.1     skrll 	case R_FRV_GOTOFFLO:
   4010      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFLO:
   4011      1.1     skrll 	case R_FRV_GOTTLSOFFLO:
   4012      1.1     skrll 	case R_FRV_GOTTLSDESCLO:
   4013      1.1     skrll 	case R_FRV_TLSMOFFLO:
   4014      1.1     skrll 	  relocation &= 0xffff;
   4015      1.1     skrll 	  break;
   4016      1.1     skrll 
   4017      1.1     skrll 	default:
   4018      1.1     skrll 	  break;
   4019      1.1     skrll 	}
   4020      1.1     skrll 
   4021      1.1     skrll       switch (r_type)
   4022      1.1     skrll 	{
   4023      1.1     skrll 	case R_FRV_LABEL24:
   4024      1.1     skrll 	  if (! IS_FDPIC (output_bfd) || ! picrel->plt)
   4025      1.1     skrll 	    break;
   4026      1.1     skrll 	  /* Fall through.  */
   4027      1.1     skrll 
   4028      1.1     skrll 	  /* When referencing a GOT entry, a function descriptor or a
   4029      1.1     skrll 	     PLT, we don't want the addend to apply to the reference,
   4030      1.1     skrll 	     but rather to the referenced symbol.  The actual entry
   4031      1.1     skrll 	     will have already been created taking the addend into
   4032      1.1     skrll 	     account, so cancel it out here.  */
   4033      1.1     skrll 	case R_FRV_GOT12:
   4034      1.1     skrll 	case R_FRV_GOTHI:
   4035      1.1     skrll 	case R_FRV_GOTLO:
   4036      1.1     skrll 	case R_FRV_FUNCDESC_GOT12:
   4037      1.1     skrll 	case R_FRV_FUNCDESC_GOTHI:
   4038      1.1     skrll 	case R_FRV_FUNCDESC_GOTLO:
   4039      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFF12:
   4040      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFHI:
   4041      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFLO:
   4042      1.1     skrll 	case R_FRV_GETTLSOFF:
   4043      1.1     skrll 	case R_FRV_GOTTLSDESC12:
   4044      1.1     skrll 	case R_FRV_GOTTLSDESCHI:
   4045      1.1     skrll 	case R_FRV_GOTTLSDESCLO:
   4046      1.1     skrll 	case R_FRV_GOTTLSOFF12:
   4047      1.1     skrll 	case R_FRV_GOTTLSOFFHI:
   4048      1.1     skrll 	case R_FRV_GOTTLSOFFLO:
   4049      1.1     skrll 	  /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
   4050      1.1     skrll 	     here, since we do want to apply the addend to the others.
   4051      1.1     skrll 	     Note that we've applied the addend to GOTOFFHI before we
   4052      1.1     skrll 	     shifted it right.  */
   4053      1.1     skrll 	case R_FRV_GOTOFFHI:
   4054      1.1     skrll 	case R_FRV_TLSMOFFHI:
   4055      1.1     skrll 	  relocation -= rel->r_addend;
   4056      1.1     skrll 	  break;
   4057      1.1     skrll 
   4058      1.1     skrll 	default:
   4059      1.1     skrll 	  break;
   4060      1.1     skrll 	}
   4061      1.1     skrll 
   4062      1.1     skrll      if (r_type == R_FRV_HI16)
   4063      1.1     skrll        r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation);
   4064      1.1     skrll 
   4065      1.1     skrll      else if (r_type == R_FRV_LO16)
   4066      1.1     skrll        r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation);
   4067      1.1     skrll 
   4068      1.1     skrll      else if (r_type == R_FRV_LABEL24 || r_type == R_FRV_GETTLSOFF)
   4069      1.1     skrll        r = elf32_frv_relocate_label24 (input_bfd, input_section, rel,
   4070      1.1     skrll 				       contents, relocation);
   4071      1.1     skrll 
   4072      1.1     skrll      else if (r_type == R_FRV_GPREL12)
   4073      1.1     skrll        r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel,
   4074      1.1     skrll 				       contents, relocation);
   4075      1.1     skrll 
   4076      1.1     skrll      else if (r_type == R_FRV_GPRELU12)
   4077      1.1     skrll        r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel,
   4078      1.1     skrll 					contents, relocation);
   4079      1.1     skrll 
   4080      1.1     skrll      else if (r_type == R_FRV_GPRELLO)
   4081      1.1     skrll        r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel,
   4082      1.1     skrll 				       contents, relocation);
   4083      1.1     skrll 
   4084      1.1     skrll      else if (r_type == R_FRV_GPRELHI)
   4085      1.1     skrll        r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel,
   4086      1.1     skrll 				       contents, relocation);
   4087      1.1     skrll 
   4088      1.1     skrll      else if (r_type == R_FRV_TLSOFF
   4089      1.1     skrll 	      || r_type == R_FRV_TLSDESC_VALUE)
   4090      1.1     skrll        r = bfd_reloc_notsupported;
   4091      1.1     skrll 
   4092      1.1     skrll      else
   4093      1.1     skrll        r = frv_final_link_relocate (howto, input_bfd, input_section, contents,
   4094      1.1     skrll 				    rel, relocation);
   4095      1.1     skrll 
   4096      1.1     skrll       if (r != bfd_reloc_ok)
   4097      1.1     skrll 	{
   4098      1.1     skrll 	  const char * msg = (const char *) NULL;
   4099      1.1     skrll 
   4100      1.1     skrll 	  switch (r)
   4101      1.1     skrll 	    {
   4102      1.1     skrll 	    case bfd_reloc_overflow:
   4103      1.1     skrll 	      r = info->callbacks->reloc_overflow
   4104      1.1     skrll 		(info, (h ? &h->root : NULL), name, howto->name,
   4105      1.1     skrll 		 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
   4106      1.1     skrll 	      break;
   4107      1.1     skrll 
   4108      1.1     skrll 	    case bfd_reloc_undefined:
   4109      1.1     skrll 	      r = info->callbacks->undefined_symbol
   4110      1.1     skrll 		(info, name, input_bfd, input_section, rel->r_offset, TRUE);
   4111      1.1     skrll 	      break;
   4112      1.1     skrll 
   4113      1.1     skrll 	    case bfd_reloc_outofrange:
   4114      1.1     skrll 	      msg = _("internal error: out of range error");
   4115      1.1     skrll 	      break;
   4116      1.1     skrll 
   4117      1.1     skrll 	    case bfd_reloc_notsupported:
   4118      1.1     skrll 	      msg = _("internal error: unsupported relocation error");
   4119      1.1     skrll 	      break;
   4120      1.1     skrll 
   4121      1.1     skrll 	    case bfd_reloc_dangerous:
   4122      1.1     skrll 	      msg = _("internal error: dangerous relocation");
   4123      1.1     skrll 	      break;
   4124      1.1     skrll 
   4125      1.1     skrll 	    default:
   4126      1.1     skrll 	      msg = _("internal error: unknown error");
   4127      1.1     skrll 	      break;
   4128      1.1     skrll 	    }
   4129      1.1     skrll 
   4130      1.1     skrll 	  if (msg)
   4131      1.1     skrll 	    {
   4132      1.1     skrll 	      (*_bfd_error_handler)
   4133      1.1     skrll 		(_("%B(%A+0x%lx): reloc against `%s': %s"),
   4134      1.1     skrll 		 input_bfd, input_section, (long)rel->r_offset, name, msg);
   4135      1.1     skrll 	      return FALSE;
   4136      1.1     skrll 	    }
   4137      1.1     skrll 
   4138      1.1     skrll 	  if (! r)
   4139      1.1     skrll 	    return FALSE;
   4140      1.1     skrll 	}
   4141      1.1     skrll     }
   4142      1.1     skrll 
   4143      1.1     skrll   return TRUE;
   4144      1.1     skrll }
   4145      1.1     skrll 
   4146      1.1     skrll /* Return the section that should be marked against GC for a given
   4148      1.1     skrll    relocation.  */
   4149      1.1     skrll 
   4150      1.1     skrll static asection *
   4151      1.1     skrll elf32_frv_gc_mark_hook (asection *sec,
   4152      1.1     skrll 			struct bfd_link_info *info,
   4153      1.1     skrll 			Elf_Internal_Rela *rel,
   4154      1.1     skrll 			struct elf_link_hash_entry *h,
   4155      1.1     skrll 			Elf_Internal_Sym *sym)
   4156      1.1     skrll {
   4157      1.1     skrll   if (h != NULL)
   4158      1.1     skrll     switch (ELF32_R_TYPE (rel->r_info))
   4159      1.1     skrll       {
   4160      1.1     skrll       case R_FRV_GNU_VTINHERIT:
   4161      1.1     skrll       case R_FRV_GNU_VTENTRY:
   4162      1.1     skrll 	return NULL;
   4163      1.1     skrll       }
   4164      1.1     skrll 
   4165      1.1     skrll   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
   4166      1.1     skrll }
   4167      1.1     skrll 
   4168      1.1     skrll /* Hook called by the linker routine which adds symbols from an object
   4170      1.1     skrll    file.  We use it to put .comm items in .scomm, and not .comm.  */
   4171      1.1     skrll 
   4172      1.1     skrll static bfd_boolean
   4173      1.1     skrll elf32_frv_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
   4174      1.1     skrll      bfd *abfd;
   4175      1.1     skrll      struct bfd_link_info *info;
   4176      1.1     skrll      Elf_Internal_Sym *sym;
   4177      1.1     skrll      const char **namep ATTRIBUTE_UNUSED;
   4178      1.1     skrll      flagword *flagsp ATTRIBUTE_UNUSED;
   4179      1.1     skrll      asection **secp;
   4180      1.1     skrll      bfd_vma *valp;
   4181      1.1     skrll {
   4182      1.1     skrll   if (sym->st_shndx == SHN_COMMON
   4183      1.1     skrll       && !info->relocatable
   4184      1.1     skrll       && (int)sym->st_size <= (int)bfd_get_gp_size (abfd))
   4185      1.1     skrll     {
   4186      1.1     skrll       /* Common symbols less than or equal to -G nn bytes are
   4187      1.1     skrll 	 automatically put into .sbss.  */
   4188      1.1     skrll 
   4189      1.1     skrll       asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
   4190      1.1     skrll 
   4191      1.1     skrll       if (scomm == NULL)
   4192      1.1     skrll 	{
   4193      1.1     skrll 	  scomm = bfd_make_section_with_flags (abfd, ".scommon",
   4194      1.1     skrll 					       (SEC_ALLOC
   4195      1.1     skrll 						| SEC_IS_COMMON
   4196      1.1     skrll 						| SEC_LINKER_CREATED));
   4197      1.1     skrll 	  if (scomm == NULL)
   4198      1.1     skrll 	    return FALSE;
   4199      1.1     skrll 	}
   4200      1.1     skrll 
   4201      1.1     skrll       *secp = scomm;
   4202      1.1     skrll       *valp = sym->st_size;
   4203      1.1     skrll     }
   4204      1.1     skrll 
   4205      1.1     skrll   return TRUE;
   4206      1.1     skrll }
   4207      1.1     skrll 
   4208      1.1     skrll /* We need dynamic symbols for every section, since segments can
   4209      1.1     skrll    relocate independently.  */
   4210      1.1     skrll static bfd_boolean
   4211      1.1     skrll _frvfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
   4212      1.1     skrll 				    struct bfd_link_info *info
   4213      1.1     skrll 				    ATTRIBUTE_UNUSED,
   4214      1.1     skrll 				    asection *p ATTRIBUTE_UNUSED)
   4215      1.1     skrll {
   4216      1.1     skrll   switch (elf_section_data (p)->this_hdr.sh_type)
   4217      1.1     skrll     {
   4218      1.1     skrll     case SHT_PROGBITS:
   4219      1.1     skrll     case SHT_NOBITS:
   4220      1.1     skrll       /* If sh_type is yet undecided, assume it could be
   4221      1.1     skrll 	 SHT_PROGBITS/SHT_NOBITS.  */
   4222      1.1     skrll     case SHT_NULL:
   4223      1.1     skrll       return FALSE;
   4224      1.1     skrll 
   4225      1.1     skrll       /* There shouldn't be section relative relocations
   4226      1.1     skrll 	 against any other section.  */
   4227      1.1     skrll     default:
   4228      1.1     skrll       return TRUE;
   4229      1.1     skrll     }
   4230      1.1     skrll }
   4231      1.1     skrll 
   4232      1.1     skrll /* Create  a .got section, as well as its additional info field.  This
   4233      1.1     skrll    is almost entirely copied from
   4234      1.1     skrll    elflink.c:_bfd_elf_create_got_section().  */
   4235      1.1     skrll 
   4236      1.1     skrll static bfd_boolean
   4237      1.1     skrll _frv_create_got_section (bfd *abfd, struct bfd_link_info *info)
   4238      1.1     skrll {
   4239      1.1     skrll   flagword flags, pltflags;
   4240      1.1     skrll   asection *s;
   4241      1.1     skrll   struct elf_link_hash_entry *h;
   4242      1.1     skrll   struct bfd_link_hash_entry *bh;
   4243      1.1     skrll   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   4244      1.1     skrll   int ptralign;
   4245      1.1     skrll   int offset;
   4246      1.1     skrll 
   4247      1.1     skrll   /* This function may be called more than once.  */
   4248      1.1     skrll   s = bfd_get_section_by_name (abfd, ".got");
   4249      1.1     skrll   if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0)
   4250      1.1     skrll     return TRUE;
   4251      1.1     skrll 
   4252      1.1     skrll   /* Machine specific: although pointers are 32-bits wide, we want the
   4253      1.1     skrll      GOT to be aligned to a 64-bit boundary, such that function
   4254      1.1     skrll      descriptors in it can be accessed with 64-bit loads and
   4255      1.1     skrll      stores.  */
   4256      1.1     skrll   ptralign = 3;
   4257      1.1     skrll 
   4258      1.1     skrll   flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
   4259      1.1     skrll 	   | SEC_LINKER_CREATED);
   4260      1.1     skrll   pltflags = flags;
   4261      1.1     skrll 
   4262      1.1     skrll   s = bfd_make_section_with_flags (abfd, ".got", flags);
   4263      1.1     skrll   if (s == NULL
   4264      1.1     skrll       || !bfd_set_section_alignment (abfd, s, ptralign))
   4265      1.1     skrll     return FALSE;
   4266      1.1     skrll 
   4267      1.1     skrll   if (bed->want_got_plt)
   4268      1.1     skrll     {
   4269      1.1     skrll       s = bfd_make_section_with_flags (abfd, ".got.plt", flags);
   4270      1.1     skrll       if (s == NULL
   4271      1.1     skrll 	  || !bfd_set_section_alignment (abfd, s, ptralign))
   4272      1.1     skrll 	return FALSE;
   4273      1.1     skrll     }
   4274      1.1     skrll 
   4275      1.1     skrll   if (bed->want_got_sym)
   4276      1.1     skrll     {
   4277      1.1     skrll       /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
   4278      1.1     skrll 	 (or .got.plt) section.  We don't do this in the linker script
   4279      1.1     skrll 	 because we don't want to define the symbol if we are not creating
   4280      1.1     skrll 	 a global offset table.  */
   4281      1.1     skrll       h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
   4282      1.1     skrll       elf_hash_table (info)->hgot = h;
   4283      1.1     skrll       if (h == NULL)
   4284      1.1     skrll 	return FALSE;
   4285      1.1     skrll 
   4286      1.1     skrll       /* Machine-specific: we want the symbol for executables as
   4287      1.1     skrll 	 well.  */
   4288      1.1     skrll       if (! bfd_elf_link_record_dynamic_symbol (info, h))
   4289      1.1     skrll 	return FALSE;
   4290      1.1     skrll     }
   4291      1.1     skrll 
   4292      1.1     skrll   /* The first bit of the global offset table is the header.  */
   4293      1.1     skrll   s->size += bed->got_header_size;
   4294      1.1     skrll 
   4295      1.1     skrll   /* This is the machine-specific part.  Create and initialize section
   4296      1.1     skrll      data for the got.  */
   4297      1.1     skrll   if (IS_FDPIC (abfd))
   4298      1.1     skrll     {
   4299      1.1     skrll       frvfdpic_got_section (info) = s;
   4300      1.1     skrll       frvfdpic_relocs_info (info) = htab_try_create (1,
   4301      1.1     skrll 						     frvfdpic_relocs_info_hash,
   4302      1.1     skrll 						     frvfdpic_relocs_info_eq,
   4303      1.1     skrll 						     (htab_del) NULL);
   4304      1.1     skrll       if (! frvfdpic_relocs_info (info))
   4305      1.1     skrll 	return FALSE;
   4306      1.1     skrll 
   4307      1.1     skrll       s = bfd_make_section_with_flags (abfd, ".rel.got",
   4308      1.1     skrll 				       (flags | SEC_READONLY));
   4309      1.1     skrll       if (s == NULL
   4310      1.1     skrll 	  || ! bfd_set_section_alignment (abfd, s, 2))
   4311      1.1     skrll 	return FALSE;
   4312      1.1     skrll 
   4313      1.1     skrll       frvfdpic_gotrel_section (info) = s;
   4314      1.1     skrll 
   4315      1.1     skrll       /* Machine-specific.  */
   4316      1.1     skrll       s = bfd_make_section_with_flags (abfd, ".rofixup",
   4317      1.1     skrll 				       (flags | SEC_READONLY));
   4318      1.1     skrll       if (s == NULL
   4319      1.1     skrll 	  || ! bfd_set_section_alignment (abfd, s, 2))
   4320      1.1     skrll 	return FALSE;
   4321      1.1     skrll 
   4322      1.1     skrll       frvfdpic_gotfixup_section (info) = s;
   4323      1.1     skrll       offset = -2048;
   4324      1.1     skrll       flags = BSF_GLOBAL;
   4325      1.1     skrll     }
   4326      1.1     skrll   else
   4327      1.1     skrll     {
   4328      1.1     skrll       offset = 2048;
   4329      1.1     skrll       flags = BSF_GLOBAL | BSF_WEAK;
   4330      1.1     skrll     }
   4331      1.1     skrll 
   4332      1.1     skrll   /* Define _gp in .rofixup, for FDPIC, or .got otherwise.  If it
   4333      1.1     skrll      turns out that we're linking with a different linker script, the
   4334      1.1     skrll      linker script will override it.  */
   4335      1.1     skrll   bh = NULL;
   4336      1.1     skrll   if (!(_bfd_generic_link_add_one_symbol
   4337      1.1     skrll 	(info, abfd, "_gp", flags, s, offset, (const char *) NULL, FALSE,
   4338      1.1     skrll 	 bed->collect, &bh)))
   4339      1.1     skrll     return FALSE;
   4340      1.1     skrll   h = (struct elf_link_hash_entry *) bh;
   4341      1.1     skrll   h->def_regular = 1;
   4342      1.1     skrll   h->type = STT_OBJECT;
   4343      1.1     skrll   /* h->other = STV_HIDDEN; */ /* Should we?  */
   4344      1.1     skrll 
   4345      1.1     skrll   /* Machine-specific: we want the symbol for executables as well.  */
   4346      1.1     skrll   if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h))
   4347      1.1     skrll     return FALSE;
   4348      1.1     skrll 
   4349      1.1     skrll   if (!IS_FDPIC (abfd))
   4350      1.1     skrll     return TRUE;
   4351      1.1     skrll 
   4352      1.1     skrll   /* FDPIC supports Thread Local Storage, and this may require a
   4353      1.1     skrll      procedure linkage table for TLS PLT entries.  */
   4354      1.1     skrll 
   4355      1.1     skrll   /* This is mostly copied from
   4356      1.1     skrll      elflink.c:_bfd_elf_create_dynamic_sections().  */
   4357      1.1     skrll 
   4358      1.1     skrll   flags = pltflags;
   4359      1.1     skrll   pltflags |= SEC_CODE;
   4360      1.1     skrll   if (bed->plt_not_loaded)
   4361      1.1     skrll     pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
   4362      1.1     skrll   if (bed->plt_readonly)
   4363      1.1     skrll     pltflags |= SEC_READONLY;
   4364      1.1     skrll 
   4365      1.1     skrll   s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
   4366      1.1     skrll   if (s == NULL
   4367      1.1     skrll       || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
   4368      1.1     skrll     return FALSE;
   4369      1.1     skrll   /* FRV-specific: remember it.  */
   4370      1.1     skrll   frvfdpic_plt_section (info) = s;
   4371      1.1     skrll 
   4372      1.1     skrll   /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
   4373      1.1     skrll      .plt section.  */
   4374      1.1     skrll   if (bed->want_plt_sym)
   4375      1.1     skrll     {
   4376      1.1     skrll       h = _bfd_elf_define_linkage_sym (abfd, info, s,
   4377      1.1     skrll 				       "_PROCEDURE_LINKAGE_TABLE_");
   4378      1.1     skrll       elf_hash_table (info)->hplt = h;
   4379      1.1     skrll       if (h == NULL)
   4380      1.1     skrll 	return FALSE;
   4381      1.1     skrll     }
   4382      1.1     skrll 
   4383      1.1     skrll   /* FRV-specific: we want rel relocations for the plt.  */
   4384      1.1     skrll   s = bfd_make_section_with_flags (abfd, ".rel.plt",
   4385      1.1     skrll 				   flags | SEC_READONLY);
   4386      1.1     skrll   if (s == NULL
   4387      1.1     skrll       || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
   4388      1.1     skrll     return FALSE;
   4389      1.1     skrll   /* FRV-specific: remember it.  */
   4390      1.1     skrll   frvfdpic_pltrel_section (info) = s;
   4391      1.1     skrll 
   4392      1.1     skrll   return TRUE;
   4393      1.1     skrll }
   4394      1.1     skrll 
   4395      1.1     skrll /* Make sure the got and plt sections exist, and that our pointers in
   4396      1.1     skrll    the link hash table point to them.  */
   4397      1.1     skrll 
   4398      1.1     skrll static bfd_boolean
   4399      1.1     skrll elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   4400      1.1     skrll {
   4401      1.1     skrll   /* This is mostly copied from
   4402      1.1     skrll      elflink.c:_bfd_elf_create_dynamic_sections().  */
   4403      1.1     skrll   flagword flags;
   4404      1.1     skrll   asection *s;
   4405      1.1     skrll   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   4406      1.1     skrll 
   4407      1.1     skrll   flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
   4408      1.1     skrll 	   | SEC_LINKER_CREATED);
   4409      1.1     skrll 
   4410      1.1     skrll   /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
   4411      1.1     skrll      .rel[a].bss sections.  */
   4412      1.1     skrll 
   4413      1.1     skrll   /* FRV-specific: we want to create the GOT and the PLT in the FRV
   4414      1.1     skrll      way.  */
   4415      1.1     skrll   if (! _frv_create_got_section (abfd, info))
   4416      1.1     skrll     return FALSE;
   4417      1.1     skrll 
   4418      1.1     skrll   /* FRV-specific: make sure we created everything we wanted.  */
   4419      1.1     skrll   BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info)
   4420      1.1     skrll 	      && frvfdpic_gotfixup_section (info)
   4421      1.1     skrll 	      && frvfdpic_plt_section (info)
   4422      1.1     skrll 	      && frvfdpic_pltrel_section (info));
   4423      1.1     skrll 
   4424      1.1     skrll   if (bed->want_dynbss)
   4425      1.1     skrll     {
   4426      1.1     skrll       /* The .dynbss section is a place to put symbols which are defined
   4427      1.1     skrll 	 by dynamic objects, are referenced by regular objects, and are
   4428      1.1     skrll 	 not functions.  We must allocate space for them in the process
   4429      1.1     skrll 	 image and use a R_*_COPY reloc to tell the dynamic linker to
   4430      1.1     skrll 	 initialize them at run time.  The linker script puts the .dynbss
   4431      1.1     skrll 	 section into the .bss section of the final image.  */
   4432      1.1     skrll       s = bfd_make_section_with_flags (abfd, ".dynbss",
   4433      1.1     skrll 				       SEC_ALLOC | SEC_LINKER_CREATED);
   4434      1.1     skrll       if (s == NULL)
   4435      1.1     skrll 	return FALSE;
   4436      1.1     skrll 
   4437      1.1     skrll       /* The .rel[a].bss section holds copy relocs.  This section is not
   4438      1.1     skrll      normally needed.  We need to create it here, though, so that the
   4439      1.1     skrll      linker will map it to an output section.  We can't just create it
   4440      1.1     skrll      only if we need it, because we will not know whether we need it
   4441      1.1     skrll      until we have seen all the input files, and the first time the
   4442      1.1     skrll      main linker code calls BFD after examining all the input files
   4443      1.1     skrll      (size_dynamic_sections) the input sections have already been
   4444      1.1     skrll      mapped to the output sections.  If the section turns out not to
   4445      1.1     skrll      be needed, we can discard it later.  We will never need this
   4446      1.1     skrll      section when generating a shared object, since they do not use
   4447      1.1     skrll      copy relocs.  */
   4448      1.1     skrll       if (! info->shared)
   4449      1.1     skrll 	{
   4450      1.1     skrll 	  s = bfd_make_section_with_flags (abfd,
   4451      1.1     skrll 					   (bed->default_use_rela_p
   4452      1.1     skrll 					    ? ".rela.bss" : ".rel.bss"),
   4453      1.1     skrll 					   flags | SEC_READONLY);
   4454      1.1     skrll 	  if (s == NULL
   4455      1.1     skrll 	      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
   4456      1.1     skrll 	    return FALSE;
   4457      1.1     skrll 	}
   4458      1.1     skrll     }
   4459      1.1     skrll 
   4460      1.1     skrll   return TRUE;
   4461      1.1     skrll }
   4462      1.1     skrll 
   4463      1.1     skrll /* Compute the total GOT and PLT size required by each symbol in each
   4464      1.1     skrll    range.  Symbols may require up to 4 words in the GOT: an entry
   4465      1.1     skrll    pointing to the symbol, an entry pointing to its function
   4466      1.1     skrll    descriptor, and a private function descriptors taking two
   4467      1.1     skrll    words.  */
   4468      1.1     skrll 
   4469      1.1     skrll static void
   4470      1.1     skrll _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info *entry,
   4471      1.1     skrll 				struct _frvfdpic_dynamic_got_info *dinfo)
   4472      1.1     skrll {
   4473      1.1     skrll   /* Allocate space for a GOT entry pointing to the symbol.  */
   4474      1.1     skrll   if (entry->got12)
   4475      1.1     skrll     dinfo->got12 += 4;
   4476      1.1     skrll   else if (entry->gotlos)
   4477      1.1     skrll     dinfo->gotlos += 4;
   4478      1.1     skrll   else if (entry->gothilo)
   4479      1.1     skrll     dinfo->gothilo += 4;
   4480      1.1     skrll   else
   4481      1.1     skrll     entry->relocs32--;
   4482      1.1     skrll   entry->relocs32++;
   4483      1.1     skrll 
   4484      1.1     skrll   /* Allocate space for a GOT entry pointing to the function
   4485      1.1     skrll      descriptor.  */
   4486      1.1     skrll   if (entry->fdgot12)
   4487      1.1     skrll     dinfo->got12 += 4;
   4488      1.1     skrll   else if (entry->fdgotlos)
   4489      1.1     skrll     dinfo->gotlos += 4;
   4490      1.1     skrll   else if (entry->fdgothilo)
   4491      1.1     skrll     dinfo->gothilo += 4;
   4492      1.1     skrll   else
   4493      1.1     skrll     entry->relocsfd--;
   4494      1.1     skrll   entry->relocsfd++;
   4495      1.1     skrll 
   4496      1.1     skrll   /* Decide whether we need a PLT entry, a function descriptor in the
   4497      1.1     skrll      GOT, and a lazy PLT entry for this symbol.  */
   4498      1.1     skrll   entry->plt = entry->call
   4499      1.1     skrll     && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
   4500      1.1     skrll     && elf_hash_table (dinfo->info)->dynamic_sections_created;
   4501      1.1     skrll   entry->privfd = entry->plt
   4502      1.1     skrll     || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo
   4503      1.1     skrll     || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo)
   4504      1.1     skrll 	&& (entry->symndx != -1
   4505      1.1     skrll 	    || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)));
   4506      1.1     skrll   entry->lazyplt = entry->privfd
   4507      1.1     skrll     && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
   4508      1.1     skrll     && ! (dinfo->info->flags & DF_BIND_NOW)
   4509      1.1     skrll     && elf_hash_table (dinfo->info)->dynamic_sections_created;
   4510      1.1     skrll 
   4511      1.1     skrll   /* Allocate space for a function descriptor.  */
   4512      1.1     skrll   if (entry->fdgoff12)
   4513      1.1     skrll     dinfo->fd12 += 8;
   4514      1.1     skrll   else if (entry->fdgofflos)
   4515      1.1     skrll     dinfo->fdlos += 8;
   4516      1.1     skrll   else if (entry->privfd && entry->plt)
   4517      1.1     skrll     dinfo->fdplt += 8;
   4518      1.1     skrll   else if (entry->privfd)
   4519      1.1     skrll     dinfo->fdhilo += 8;
   4520      1.1     skrll   else
   4521      1.1     skrll     entry->relocsfdv--;
   4522      1.1     skrll   entry->relocsfdv++;
   4523      1.1     skrll 
   4524      1.1     skrll   if (entry->lazyplt)
   4525      1.1     skrll     dinfo->lzplt += 8;
   4526      1.1     skrll }
   4527      1.1     skrll 
   4528      1.1     skrll /* Compute the total GOT size required by each TLS symbol in each
   4529      1.1     skrll    range.  Symbols may require up to 5 words in the GOT: an entry
   4530      1.1     skrll    holding the TLS offset for the symbol, and an entry with a full TLS
   4531      1.1     skrll    descriptor taking 4 words.  */
   4532      1.1     skrll 
   4533      1.1     skrll static void
   4534      1.1     skrll _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info *entry,
   4535      1.1     skrll 			     struct _frvfdpic_dynamic_got_info *dinfo,
   4536      1.1     skrll 			     bfd_boolean subtract)
   4537      1.1     skrll {
   4538      1.1     skrll   const int l = subtract ? -1 : 1;
   4539      1.1     skrll 
   4540      1.1     skrll   /* Allocate space for a GOT entry with the TLS offset of the
   4541      1.1     skrll      symbol.  */
   4542      1.1     skrll   if (entry->tlsoff12)
   4543      1.1     skrll     dinfo->got12 += 4 * l;
   4544      1.1     skrll   else if (entry->tlsofflos)
   4545      1.1     skrll     dinfo->gotlos += 4 * l;
   4546      1.1     skrll   else if (entry->tlsoffhilo)
   4547      1.1     skrll     dinfo->gothilo += 4 * l;
   4548      1.1     skrll   else
   4549      1.1     skrll     entry->relocstlsoff -= l;
   4550      1.1     skrll   entry->relocstlsoff += l;
   4551      1.1     skrll 
   4552      1.1     skrll   /* If there's any TLSOFF relocation, mark the output file as not
   4553      1.1     skrll      suitable for dlopening.  This mark will remain even if we relax
   4554      1.1     skrll      all such relocations, but this is not a problem, since we'll only
   4555      1.1     skrll      do so for executables, and we definitely don't want anyone
   4556      1.1     skrll      dlopening executables.  */
   4557      1.1     skrll   if (entry->relocstlsoff)
   4558      1.1     skrll     dinfo->info->flags |= DF_STATIC_TLS;
   4559      1.1     skrll 
   4560      1.1     skrll   /* Allocate space for a TLS descriptor.  */
   4561      1.1     skrll   if (entry->tlsdesc12)
   4562      1.1     skrll     dinfo->tlsd12 += 8 * l;
   4563      1.1     skrll   else if (entry->tlsdesclos)
   4564      1.1     skrll     dinfo->tlsdlos += 8 * l;
   4565      1.1     skrll   else if (entry->tlsplt)
   4566      1.1     skrll     dinfo->tlsdplt += 8 * l;
   4567      1.1     skrll   else if (entry->tlsdeschilo)
   4568      1.1     skrll     dinfo->tlsdhilo += 8 * l;
   4569      1.1     skrll   else
   4570      1.1     skrll     entry->relocstlsd -= l;
   4571      1.1     skrll   entry->relocstlsd += l;
   4572      1.1     skrll }
   4573      1.1     skrll 
   4574      1.1     skrll /* Compute the number of dynamic relocations and fixups that a symbol
   4575      1.1     skrll    requires, and add (or subtract) from the grand and per-symbol
   4576      1.1     skrll    totals.  */
   4577      1.1     skrll 
   4578      1.1     skrll static void
   4579      1.1     skrll _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info *entry,
   4580      1.1     skrll 			       struct _frvfdpic_dynamic_got_info *dinfo,
   4581      1.1     skrll 			       bfd_boolean subtract)
   4582      1.1     skrll {
   4583      1.1     skrll   bfd_vma relocs = 0, fixups = 0, tlsrets = 0;
   4584      1.1     skrll 
   4585      1.1     skrll   if (!dinfo->info->executable || dinfo->info->pie)
   4586      1.1     skrll     {
   4587      1.1     skrll       relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv
   4588      1.1     skrll 	+ entry->relocstlsd;
   4589      1.1     skrll 
   4590      1.1     skrll       /* In the executable, TLS relocations to symbols that bind
   4591      1.1     skrll 	 locally (including those that resolve to global TLS offsets)
   4592      1.1     skrll 	 are resolved immediately, without any need for fixups or
   4593      1.1     skrll 	 dynamic relocations.  In shared libraries, however, we must
   4594      1.1     skrll 	 emit dynamic relocations even for local symbols, because we
   4595      1.1     skrll 	 don't know the module id the library is going to get at
   4596      1.1     skrll 	 run-time, nor its TLS base offset.  */
   4597      1.1     skrll       if (!dinfo->info->executable
   4598      1.1     skrll 	  || (entry->symndx == -1
   4599      1.1     skrll 	      && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
   4600      1.1     skrll 	relocs += entry->relocstlsoff;
   4601      1.1     skrll     }
   4602      1.1     skrll   else
   4603      1.1     skrll     {
   4604      1.1     skrll       if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))
   4605      1.1     skrll 	{
   4606      1.1     skrll 	  if (entry->symndx != -1
   4607      1.1     skrll 	      || entry->d.h->root.type != bfd_link_hash_undefweak)
   4608      1.1     skrll 	    fixups += entry->relocs32 + 2 * entry->relocsfdv;
   4609      1.1     skrll 	  fixups += entry->relocstlsd;
   4610      1.1     skrll 	  tlsrets += entry->relocstlsd;
   4611      1.1     skrll 	}
   4612      1.1     skrll       else
   4613      1.1     skrll 	{
   4614      1.1     skrll 	  relocs += entry->relocs32 + entry->relocsfdv
   4615      1.1     skrll 	    + entry->relocstlsoff + entry->relocstlsd;
   4616      1.1     skrll 	}
   4617      1.1     skrll 
   4618      1.1     skrll       if (entry->symndx != -1
   4619      1.1     skrll 	  || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))
   4620      1.1     skrll 	{
   4621      1.1     skrll 	  if (entry->symndx != -1
   4622      1.1     skrll 	      || entry->d.h->root.type != bfd_link_hash_undefweak)
   4623      1.1     skrll 	    fixups += entry->relocsfd;
   4624      1.1     skrll 	}
   4625      1.1     skrll       else
   4626      1.1     skrll 	relocs += entry->relocsfd;
   4627      1.1     skrll     }
   4628      1.1     skrll 
   4629      1.1     skrll   if (subtract)
   4630      1.1     skrll     {
   4631      1.1     skrll       relocs = - relocs;
   4632      1.1     skrll       fixups = - fixups;
   4633      1.1     skrll       tlsrets = - tlsrets;
   4634      1.1     skrll     }
   4635      1.1     skrll 
   4636      1.1     skrll   entry->dynrelocs += relocs;
   4637      1.1     skrll   entry->fixups += fixups;
   4638      1.1     skrll   dinfo->relocs += relocs;
   4639      1.1     skrll   dinfo->fixups += fixups;
   4640      1.1     skrll   dinfo->tls_ret_refs += tlsrets;
   4641      1.1     skrll }
   4642      1.1     skrll 
   4643      1.1     skrll /* Look for opportunities to relax TLS relocations.  We can assume
   4644      1.1     skrll    we're linking the main executable or a static-tls library, since
   4645      1.1     skrll    otherwise we wouldn't have got here.  When relaxing, we have to
   4646      1.1     skrll    first undo any previous accounting of TLS uses of fixups, dynamic
   4647      1.1     skrll    relocations, GOT and PLT entries.  */
   4648      1.1     skrll 
   4649      1.1     skrll static void
   4650      1.1     skrll _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info *entry,
   4651      1.1     skrll 			     struct _frvfdpic_dynamic_got_info *dinfo,
   4652      1.1     skrll 			     bfd_boolean relaxing)
   4653      1.1     skrll {
   4654      1.1     skrll   bfd_boolean changed = ! relaxing;
   4655      1.1     skrll 
   4656      1.1     skrll   BFD_ASSERT (dinfo->info->executable
   4657      1.1     skrll 	      || (dinfo->info->flags & DF_STATIC_TLS));
   4658      1.1     skrll 
   4659      1.1     skrll   if (entry->tlsdesc12 || entry->tlsdesclos || entry->tlsdeschilo)
   4660      1.1     skrll     {
   4661      1.1     skrll       if (! changed)
   4662      1.1     skrll 	{
   4663      1.1     skrll 	  _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
   4664      1.1     skrll 	  _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
   4665      1.1     skrll 	  changed = TRUE;
   4666      1.1     skrll 	}
   4667      1.1     skrll 
   4668      1.1     skrll       /* When linking an executable, we can always decay GOTTLSDESC to
   4669      1.1     skrll 	 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
   4670      1.1     skrll 	 When linking a static-tls shared library, using TLSMOFF is
   4671      1.1     skrll 	 not an option, but we can still use GOTTLSOFF.  When decaying
   4672      1.1     skrll 	 to GOTTLSOFF, we must keep the GOT entry in range.  We know
   4673      1.1     skrll 	 it has to fit because we'll be trading the 4 words of hte TLS
   4674      1.1     skrll 	 descriptor for a single word in the same range.  */
   4675      1.1     skrll       if (! dinfo->info->executable
   4676      1.1     skrll 	  || (entry->symndx == -1
   4677      1.1     skrll 	      && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
   4678      1.1     skrll 	{
   4679      1.1     skrll 	  entry->tlsoff12 |= entry->tlsdesc12;
   4680      1.1     skrll 	  entry->tlsofflos |= entry->tlsdesclos;
   4681      1.1     skrll 	  entry->tlsoffhilo |= entry->tlsdeschilo;
   4682      1.1     skrll 	}
   4683      1.1     skrll 
   4684      1.1     skrll       entry->tlsdesc12 = entry->tlsdesclos = entry->tlsdeschilo = 0;
   4685      1.1     skrll     }
   4686      1.1     skrll 
   4687      1.1     skrll   /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
   4688      1.1     skrll      main executable.  We have to check whether the symbol's TLSOFF is
   4689      1.1     skrll      in range for a setlos.  For symbols with a hash entry, we can
   4690      1.1     skrll      determine exactly what to do; for others locals, we don't have
   4691      1.1     skrll      addresses handy, so we use the size of the TLS section as an
   4692      1.1     skrll      approximation.  If we get it wrong, we'll retain a GOT entry
   4693      1.1     skrll      holding the TLS offset (without dynamic relocations or fixups),
   4694      1.1     skrll      but we'll still optimize away the loads from it.  Since TLS sizes
   4695      1.1     skrll      are generally very small, it's probably not worth attempting to
   4696      1.1     skrll      do better than this.  */
   4697      1.1     skrll   if ((entry->tlsplt
   4698      1.1     skrll        || entry->tlsoff12 || entry->tlsofflos || entry->tlsoffhilo)
   4699      1.1     skrll       && dinfo->info->executable && relaxing
   4700      1.1     skrll       && ((entry->symndx == -1
   4701      1.1     skrll 	   && FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
   4702      1.1     skrll 	   /* The above may hold for an undefweak TLS symbol, so make
   4703      1.1     skrll 	      sure we don't have this case before accessing def.value
   4704      1.1     skrll 	      and def.section.  */
   4705      1.1     skrll 	   && (entry->d.h->root.type == bfd_link_hash_undefweak
   4706      1.1     skrll 	       || (bfd_vma)(entry->d.h->root.u.def.value
   4707      1.1     skrll 			    + (entry->d.h->root.u.def.section
   4708      1.1     skrll 			       ->output_section->vma)
   4709      1.1     skrll 			    + entry->d.h->root.u.def.section->output_offset
   4710      1.1     skrll 			    + entry->addend
   4711      1.1     skrll 			    - tls_biased_base (dinfo->info)
   4712      1.1     skrll 			    + 32768) < (bfd_vma)65536))
   4713      1.1     skrll 	  || (entry->symndx != -1
   4714      1.1     skrll 	      && (elf_hash_table (dinfo->info)->tls_sec->size
   4715      1.1     skrll 		  + abs (entry->addend) < 32768 + FRVFDPIC_TLS_BIAS))))
   4716      1.1     skrll     {
   4717      1.1     skrll       if (! changed)
   4718      1.1     skrll 	{
   4719      1.1     skrll 	  _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
   4720      1.1     skrll 	  _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
   4721      1.1     skrll 	  changed = TRUE;
   4722      1.1     skrll 	}
   4723      1.1     skrll 
   4724      1.1     skrll       entry->tlsplt =
   4725      1.1     skrll 	entry->tlsoff12 = entry->tlsofflos = entry->tlsoffhilo = 0;
   4726      1.1     skrll     }
   4727      1.1     skrll 
   4728      1.1     skrll   /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
   4729      1.1     skrll      have a #gottlsoff12 relocation for this entry, or if we can fit
   4730      1.1     skrll      one more in the 12-bit (and 16-bit) ranges.  */
   4731      1.1     skrll   if (entry->tlsplt
   4732      1.1     skrll       && (entry->tlsoff12
   4733      1.1     skrll 	  || (relaxing
   4734      1.1     skrll 	      && dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 <= 4096 - 12 - 4
   4735      1.1     skrll 	      && (dinfo->got12 + dinfo->fd12 + dinfo->tlsd12
   4736      1.1     skrll 		  + dinfo->gotlos + dinfo->fdlos + dinfo->tlsdlos
   4737      1.1     skrll 		  <= 65536 - 12 - 4))))
   4738      1.1     skrll     {
   4739      1.1     skrll       if (! changed)
   4740      1.1     skrll 	{
   4741      1.1     skrll 	  _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE);
   4742      1.1     skrll 	  _frvfdpic_count_tls_entries (entry, dinfo, TRUE);
   4743      1.1     skrll 	  changed = TRUE;
   4744      1.1     skrll 	}
   4745      1.1     skrll 
   4746      1.1     skrll       entry->tlsoff12 = 1;
   4747      1.1     skrll       entry->tlsplt = 0;
   4748      1.1     skrll     }
   4749      1.1     skrll 
   4750      1.1     skrll   if (changed)
   4751      1.1     skrll     {
   4752      1.1     skrll       _frvfdpic_count_tls_entries (entry, dinfo, FALSE);
   4753      1.1     skrll       _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE);
   4754      1.1     skrll     }
   4755      1.1     skrll 
   4756      1.1     skrll   return;
   4757      1.1     skrll }
   4758      1.1     skrll 
   4759      1.1     skrll /* Compute the total GOT and PLT size required by each symbol in each range. *
   4760      1.1     skrll    Symbols may require up to 4 words in the GOT: an entry pointing to
   4761      1.1     skrll    the symbol, an entry pointing to its function descriptor, and a
   4762      1.1     skrll    private function descriptors taking two words.  */
   4763      1.1     skrll 
   4764      1.1     skrll static int
   4765      1.1     skrll _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_)
   4766      1.1     skrll {
   4767      1.1     skrll   struct frvfdpic_relocs_info *entry = *entryp;
   4768      1.1     skrll   struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
   4769      1.1     skrll 
   4770      1.1     skrll   _frvfdpic_count_nontls_entries (entry, dinfo);
   4771      1.1     skrll 
   4772      1.1     skrll   if (dinfo->info->executable || (dinfo->info->flags & DF_STATIC_TLS))
   4773      1.1     skrll     _frvfdpic_relax_tls_entries (entry, dinfo, FALSE);
   4774      1.1     skrll   else
   4775      1.1     skrll     {
   4776      1.1     skrll       _frvfdpic_count_tls_entries (entry, dinfo, FALSE);
   4777      1.1     skrll       _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE);
   4778      1.1     skrll     }
   4779      1.1     skrll 
   4780      1.1     skrll   return 1;
   4781      1.1     skrll }
   4782      1.1     skrll 
   4783      1.1     skrll /* Determine the positive and negative ranges to be used by each
   4784      1.1     skrll    offset range in the GOT.  FDCUR and CUR, that must be aligned to a
   4785      1.1     skrll    double-word boundary, are the minimum (negative) and maximum
   4786      1.1     skrll    (positive) GOT offsets already used by previous ranges, except for
   4787      1.1     skrll    an ODD entry that may have been left behind.  GOT and FD indicate
   4788      1.1     skrll    the size of GOT entries and function descriptors that must be
   4789      1.1     skrll    placed within the range from -WRAP to WRAP.  If there's room left,
   4790      1.1     skrll    up to FDPLT bytes should be reserved for additional function
   4791      1.1     skrll    descriptors.  */
   4792      1.1     skrll 
   4793      1.1     skrll inline static bfd_signed_vma
   4794      1.1     skrll _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad,
   4795      1.1     skrll 				  bfd_signed_vma fdcur,
   4796      1.1     skrll 				  bfd_signed_vma odd,
   4797      1.1     skrll 				  bfd_signed_vma cur,
   4798      1.1     skrll 				  bfd_vma got,
   4799      1.1     skrll 				  bfd_vma fd,
   4800      1.1     skrll 				  bfd_vma fdplt,
   4801      1.1     skrll 				  bfd_vma tlsd,
   4802      1.1     skrll 				  bfd_vma tlsdplt,
   4803      1.1     skrll 				  bfd_vma wrap)
   4804      1.1     skrll {
   4805      1.1     skrll   bfd_signed_vma wrapmin = -wrap;
   4806      1.1     skrll   const bfd_vma tdescsz = 8;
   4807      1.1     skrll 
   4808      1.1     skrll   /* Start at the given initial points.  */
   4809      1.1     skrll   gad->fdcur = fdcur;
   4810      1.1     skrll   gad->cur = cur;
   4811      1.1     skrll 
   4812      1.1     skrll   /* If we had an incoming odd word and we have any got entries that
   4813      1.1     skrll      are going to use it, consume it, otherwise leave gad->odd at
   4814      1.1     skrll      zero.  We might force gad->odd to zero and return the incoming
   4815      1.1     skrll      odd such that it is used by the next range, but then GOT entries
   4816      1.1     skrll      might appear to be out of order and we wouldn't be able to
   4817      1.1     skrll      shorten the GOT by one word if it turns out to end with an
   4818      1.1     skrll      unpaired GOT entry.  */
   4819      1.1     skrll   if (odd && got)
   4820      1.1     skrll     {
   4821      1.1     skrll       gad->odd = odd;
   4822      1.1     skrll       got -= 4;
   4823      1.1     skrll       odd = 0;
   4824      1.1     skrll     }
   4825      1.1     skrll   else
   4826      1.1     skrll     gad->odd = 0;
   4827      1.1     skrll 
   4828      1.1     skrll   /* If we're left with an unpaired GOT entry, compute its location
   4829      1.1     skrll      such that we can return it.  Otherwise, if got doesn't require an
   4830      1.1     skrll      odd number of words here, either odd was already zero in the
   4831      1.1     skrll      block above, or it was set to zero because got was non-zero, or
   4832      1.1     skrll      got was already zero.  In the latter case, we want the value of
   4833      1.1     skrll      odd to carry over to the return statement, so we don't want to
   4834      1.1     skrll      reset odd unless the condition below is true.  */
   4835      1.1     skrll   if (got & 4)
   4836      1.1     skrll     {
   4837      1.1     skrll       odd = cur + got;
   4838      1.1     skrll       got += 4;
   4839      1.1     skrll     }
   4840      1.1     skrll 
   4841      1.1     skrll   /* Compute the tentative boundaries of this range.  */
   4842      1.1     skrll   gad->max = cur + got;
   4843      1.1     skrll   gad->min = fdcur - fd;
   4844      1.1     skrll   gad->fdplt = 0;
   4845      1.1     skrll 
   4846      1.1     skrll   /* If function descriptors took too much space, wrap some of them
   4847      1.1     skrll      around.  */
   4848      1.1     skrll   if (gad->min < wrapmin)
   4849      1.1     skrll     {
   4850      1.1     skrll       gad->max += wrapmin - gad->min;
   4851      1.1     skrll       gad->tmin = gad->min = wrapmin;
   4852      1.1     skrll     }
   4853      1.1     skrll 
   4854      1.1     skrll   /* If GOT entries took too much space, wrap some of them around.
   4855      1.1     skrll      This may well cause gad->min to become lower than wrapmin.  This
   4856      1.1     skrll      will cause a relocation overflow later on, so we don't have to
   4857      1.1     skrll      report it here . */
   4858      1.1     skrll   if ((bfd_vma) gad->max > wrap)
   4859      1.1     skrll     {
   4860      1.1     skrll       gad->min -= gad->max - wrap;
   4861      1.1     skrll       gad->max = wrap;
   4862      1.1     skrll     }
   4863      1.1     skrll 
   4864      1.1     skrll   /* Add TLS descriptors.  */
   4865      1.1     skrll   gad->tmax = gad->max + tlsd;
   4866      1.1     skrll   gad->tmin = gad->min;
   4867      1.1     skrll   gad->tlsdplt = 0;
   4868      1.1     skrll 
   4869      1.1     skrll   /* If TLS descriptors took too much space, wrap an integral number
   4870      1.1     skrll      of them around.  */
   4871      1.1     skrll   if ((bfd_vma) gad->tmax > wrap)
   4872      1.1     skrll     {
   4873      1.1     skrll       bfd_vma wrapsize = gad->tmax - wrap;
   4874      1.1     skrll 
   4875      1.1     skrll       wrapsize += tdescsz / 2;
   4876      1.1     skrll       wrapsize &= ~ tdescsz / 2;
   4877      1.1     skrll 
   4878      1.1     skrll       gad->tmin -= wrapsize;
   4879      1.1     skrll       gad->tmax -= wrapsize;
   4880      1.1     skrll     }
   4881      1.1     skrll 
   4882      1.1     skrll   /* If there is space left and we have function descriptors
   4883      1.1     skrll      referenced in PLT entries that could take advantage of shorter
   4884      1.1     skrll      offsets, place them now.  */
   4885      1.1     skrll   if (fdplt && gad->tmin > wrapmin)
   4886      1.1     skrll     {
   4887      1.1     skrll       bfd_vma fds;
   4888      1.1     skrll 
   4889      1.1     skrll       if ((bfd_vma) (gad->tmin - wrapmin) < fdplt)
   4890      1.1     skrll 	fds = gad->tmin - wrapmin;
   4891      1.1     skrll       else
   4892      1.1     skrll 	fds = fdplt;
   4893      1.1     skrll 
   4894      1.1     skrll       fdplt -= fds;
   4895      1.1     skrll       gad->min -= fds;
   4896      1.1     skrll       gad->tmin -= fds;
   4897      1.1     skrll       gad->fdplt += fds;
   4898      1.1     skrll     }
   4899      1.1     skrll 
   4900      1.1     skrll   /* If there is more space left, try to place some more function
   4901      1.1     skrll      descriptors for PLT entries.  */
   4902      1.1     skrll   if (fdplt && (bfd_vma) gad->tmax < wrap)
   4903      1.1     skrll     {
   4904      1.1     skrll       bfd_vma fds;
   4905      1.1     skrll 
   4906      1.1     skrll       if ((bfd_vma) (wrap - gad->tmax) < fdplt)
   4907      1.1     skrll 	fds = wrap - gad->tmax;
   4908      1.1     skrll       else
   4909      1.1     skrll 	fds = fdplt;
   4910      1.1     skrll 
   4911      1.1     skrll       fdplt -= fds;
   4912      1.1     skrll       gad->max += fds;
   4913      1.1     skrll       gad->tmax += fds;
   4914      1.1     skrll       gad->fdplt += fds;
   4915      1.1     skrll     }
   4916      1.1     skrll 
   4917      1.1     skrll   /* If there is space left and we have TLS descriptors referenced in
   4918      1.1     skrll      PLT entries that could take advantage of shorter offsets, place
   4919      1.1     skrll      them now.  */
   4920      1.1     skrll   if (tlsdplt && gad->tmin > wrapmin)
   4921      1.1     skrll     {
   4922      1.1     skrll       bfd_vma tlsds;
   4923      1.1     skrll 
   4924      1.1     skrll       if ((bfd_vma) (gad->tmin - wrapmin) < tlsdplt)
   4925      1.1     skrll 	tlsds = (gad->tmin - wrapmin) & ~ (tdescsz / 2);
   4926      1.1     skrll       else
   4927      1.1     skrll 	tlsds = tlsdplt;
   4928      1.1     skrll 
   4929      1.1     skrll       tlsdplt -= tlsds;
   4930      1.1     skrll       gad->tmin -= tlsds;
   4931      1.1     skrll       gad->tlsdplt += tlsds;
   4932      1.1     skrll     }
   4933      1.1     skrll 
   4934      1.1     skrll   /* If there is more space left, try to place some more TLS
   4935      1.1     skrll      descriptors for PLT entries.  Although we could try to fit an
   4936      1.1     skrll      additional TLS descriptor with half of it just before before the
   4937      1.1     skrll      wrap point and another right past the wrap point, this might
   4938      1.1     skrll      cause us to run out of space for the next region, so don't do
   4939      1.1     skrll      it.  */
   4940      1.1     skrll   if (tlsdplt && (bfd_vma) gad->tmax < wrap - tdescsz / 2)
   4941      1.1     skrll     {
   4942      1.1     skrll       bfd_vma tlsds;
   4943      1.1     skrll 
   4944      1.1     skrll       if ((bfd_vma) (wrap - gad->tmax) < tlsdplt)
   4945      1.1     skrll 	tlsds = (wrap - gad->tmax) & ~ (tdescsz / 2);
   4946      1.1     skrll       else
   4947      1.1     skrll 	tlsds = tlsdplt;
   4948      1.1     skrll 
   4949      1.1     skrll       tlsdplt -= tlsds;
   4950      1.1     skrll       gad->tmax += tlsds;
   4951      1.1     skrll       gad->tlsdplt += tlsds;
   4952      1.1     skrll     }
   4953      1.1     skrll 
   4954      1.1     skrll   /* If odd was initially computed as an offset past the wrap point,
   4955      1.1     skrll      wrap it around.  */
   4956      1.1     skrll   if (odd > gad->max)
   4957      1.1     skrll     odd = gad->min + odd - gad->max;
   4958      1.1     skrll 
   4959      1.1     skrll   /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
   4960      1.1     skrll      before returning, so do it here too.  This guarantees that,
   4961      1.1     skrll      should cur and fdcur meet at the wrap point, they'll both be
   4962      1.1     skrll      equal to min.  */
   4963      1.1     skrll   if (gad->cur == gad->max)
   4964      1.1     skrll     gad->cur = gad->min;
   4965      1.1     skrll 
   4966      1.1     skrll   /* Ditto for _frvfdpic_get_tlsdesc_entry().  */
   4967      1.1     skrll   gad->tcur = gad->max;
   4968      1.1     skrll   if (gad->tcur == gad->tmax)
   4969      1.1     skrll     gad->tcur = gad->tmin;
   4970      1.1     skrll 
   4971      1.1     skrll   return odd;
   4972      1.1     skrll }
   4973      1.1     skrll 
   4974      1.1     skrll /* Compute the location of the next GOT entry, given the allocation
   4975      1.1     skrll    data for a range.  */
   4976      1.1     skrll 
   4977      1.1     skrll inline static bfd_signed_vma
   4978      1.1     skrll _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
   4979      1.1     skrll {
   4980      1.1     skrll   bfd_signed_vma ret;
   4981      1.1     skrll 
   4982      1.1     skrll   if (gad->odd)
   4983      1.1     skrll     {
   4984      1.1     skrll       /* If there was an odd word left behind, use it.  */
   4985      1.1     skrll       ret = gad->odd;
   4986      1.1     skrll       gad->odd = 0;
   4987      1.1     skrll     }
   4988      1.1     skrll   else
   4989      1.1     skrll     {
   4990      1.1     skrll       /* Otherwise, use the word pointed to by cur, reserve the next
   4991      1.1     skrll 	 as an odd word, and skip to the next pair of words, possibly
   4992      1.1     skrll 	 wrapping around.  */
   4993      1.1     skrll       ret = gad->cur;
   4994      1.1     skrll       gad->odd = gad->cur + 4;
   4995      1.1     skrll       gad->cur += 8;
   4996      1.1     skrll       if (gad->cur == gad->max)
   4997      1.1     skrll 	gad->cur = gad->min;
   4998      1.1     skrll     }
   4999      1.1     skrll 
   5000      1.1     skrll   return ret;
   5001      1.1     skrll }
   5002      1.1     skrll 
   5003      1.1     skrll /* Compute the location of the next function descriptor entry in the
   5004      1.1     skrll    GOT, given the allocation data for a range.  */
   5005      1.1     skrll 
   5006      1.1     skrll inline static bfd_signed_vma
   5007      1.1     skrll _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
   5008      1.1     skrll {
   5009      1.1     skrll   /* If we're at the bottom, wrap around, and only then allocate the
   5010      1.1     skrll      next pair of words.  */
   5011      1.1     skrll   if (gad->fdcur == gad->min)
   5012      1.1     skrll     gad->fdcur = gad->max;
   5013      1.1     skrll   return gad->fdcur -= 8;
   5014      1.1     skrll }
   5015      1.1     skrll 
   5016      1.1     skrll /* Compute the location of the next TLS descriptor entry in the GOT,
   5017      1.1     skrll    given the allocation data for a range.  */
   5018      1.1     skrll inline static bfd_signed_vma
   5019      1.1     skrll _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
   5020      1.1     skrll {
   5021      1.1     skrll   bfd_signed_vma ret;
   5022      1.1     skrll 
   5023      1.1     skrll   ret = gad->tcur;
   5024      1.1     skrll 
   5025      1.1     skrll   gad->tcur += 8;
   5026      1.1     skrll 
   5027      1.1     skrll   /* If we're at the top of the region, wrap around to the bottom.  */
   5028      1.1     skrll   if (gad->tcur == gad->tmax)
   5029      1.1     skrll     gad->tcur = gad->tmin;
   5030      1.1     skrll 
   5031      1.1     skrll   return ret;
   5032      1.1     skrll }
   5033      1.1     skrll 
   5034      1.1     skrll /* Assign GOT offsets for every GOT entry and function descriptor.
   5035      1.1     skrll    Doing everything in a single pass is tricky.  */
   5036      1.1     skrll 
   5037      1.1     skrll static int
   5038      1.1     skrll _frvfdpic_assign_got_entries (void **entryp, void *info_)
   5039      1.1     skrll {
   5040      1.1     skrll   struct frvfdpic_relocs_info *entry = *entryp;
   5041      1.1     skrll   struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
   5042      1.1     skrll 
   5043      1.1     skrll   if (entry->got12)
   5044      1.1     skrll     entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12);
   5045      1.1     skrll   else if (entry->gotlos)
   5046      1.1     skrll     entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
   5047      1.1     skrll   else if (entry->gothilo)
   5048      1.1     skrll     entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
   5049      1.1     skrll 
   5050      1.1     skrll   if (entry->fdgot12)
   5051      1.1     skrll     entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12);
   5052      1.1     skrll   else if (entry->fdgotlos)
   5053      1.1     skrll     entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
   5054      1.1     skrll   else if (entry->fdgothilo)
   5055      1.1     skrll     entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
   5056      1.1     skrll 
   5057      1.1     skrll   if (entry->fdgoff12)
   5058      1.1     skrll     entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
   5059      1.1     skrll   else if (entry->plt && dinfo->got12.fdplt)
   5060      1.1     skrll     {
   5061      1.1     skrll       dinfo->got12.fdplt -= 8;
   5062      1.1     skrll       entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
   5063      1.1     skrll     }
   5064      1.1     skrll   else if (entry->fdgofflos)
   5065      1.1     skrll     entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
   5066      1.1     skrll   else if (entry->plt && dinfo->gotlos.fdplt)
   5067      1.1     skrll     {
   5068      1.1     skrll       dinfo->gotlos.fdplt -= 8;
   5069      1.1     skrll       entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
   5070      1.1     skrll     }
   5071      1.1     skrll   else if (entry->plt)
   5072      1.1     skrll     {
   5073      1.1     skrll       dinfo->gothilo.fdplt -= 8;
   5074      1.1     skrll       entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
   5075      1.1     skrll     }
   5076      1.1     skrll   else if (entry->privfd)
   5077      1.1     skrll     entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
   5078      1.1     skrll 
   5079      1.1     skrll   if (entry->tlsoff12)
   5080      1.1     skrll     entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->got12);
   5081      1.1     skrll   else if (entry->tlsofflos)
   5082      1.1     skrll     entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
   5083      1.1     skrll   else if (entry->tlsoffhilo)
   5084      1.1     skrll     entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
   5085      1.1     skrll 
   5086      1.1     skrll   if (entry->tlsdesc12)
   5087      1.1     skrll     entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
   5088      1.1     skrll   else if (entry->tlsplt && dinfo->got12.tlsdplt)
   5089      1.1     skrll     {
   5090      1.1     skrll       dinfo->got12.tlsdplt -= 8;
   5091      1.1     skrll       entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
   5092      1.1     skrll     }
   5093      1.1     skrll   else if (entry->tlsdesclos)
   5094      1.1     skrll     entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
   5095      1.1     skrll   else if (entry->tlsplt && dinfo->gotlos.tlsdplt)
   5096      1.1     skrll     {
   5097      1.1     skrll       dinfo->gotlos.tlsdplt -= 8;
   5098      1.1     skrll       entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
   5099      1.1     skrll     }
   5100      1.1     skrll   else if (entry->tlsplt)
   5101      1.1     skrll     {
   5102      1.1     skrll       dinfo->gothilo.tlsdplt -= 8;
   5103      1.1     skrll       entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
   5104      1.1     skrll     }
   5105      1.1     skrll   else if (entry->tlsdeschilo)
   5106      1.1     skrll     entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
   5107      1.1     skrll 
   5108      1.1     skrll   return 1;
   5109      1.1     skrll }
   5110      1.1     skrll 
   5111      1.1     skrll /* Assign GOT offsets to private function descriptors used by PLT
   5112      1.1     skrll    entries (or referenced by 32-bit offsets), as well as PLT entries
   5113      1.1     skrll    and lazy PLT entries.  */
   5114      1.1     skrll 
   5115      1.1     skrll static int
   5116      1.1     skrll _frvfdpic_assign_plt_entries (void **entryp, void *info_)
   5117      1.1     skrll {
   5118      1.1     skrll   struct frvfdpic_relocs_info *entry = *entryp;
   5119      1.1     skrll   struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
   5120      1.1     skrll 
   5121      1.1     skrll   if (entry->privfd)
   5122      1.1     skrll     BFD_ASSERT (entry->fd_entry);
   5123      1.1     skrll 
   5124      1.1     skrll   if (entry->plt)
   5125      1.1     skrll     {
   5126      1.1     skrll       int size;
   5127      1.1     skrll 
   5128      1.1     skrll       /* We use the section's raw size to mark the location of the
   5129      1.1     skrll 	 next PLT entry.  */
   5130      1.1     skrll       entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->size;
   5131      1.1     skrll 
   5132      1.1     skrll       /* Figure out the length of this PLT entry based on the
   5133      1.1     skrll 	 addressing mode we need to reach the function descriptor.  */
   5134      1.1     skrll       BFD_ASSERT (entry->fd_entry);
   5135      1.1     skrll       if (entry->fd_entry >= -(1 << (12 - 1))
   5136      1.1     skrll 	  && entry->fd_entry < (1 << (12 - 1)))
   5137      1.1     skrll 	size = 8;
   5138      1.1     skrll       else if (entry->fd_entry >= -(1 << (16 - 1))
   5139      1.1     skrll 	       && entry->fd_entry < (1 << (16 - 1)))
   5140      1.1     skrll 	size = 12;
   5141      1.1     skrll       else
   5142      1.1     skrll 	size = 16;
   5143      1.1     skrll 
   5144      1.1     skrll       frvfdpic_plt_section (dinfo->g.info)->size += size;
   5145      1.1     skrll     }
   5146      1.1     skrll 
   5147      1.1     skrll   if (entry->lazyplt)
   5148      1.1     skrll     {
   5149      1.1     skrll       entry->lzplt_entry = dinfo->g.lzplt;
   5150      1.1     skrll       dinfo->g.lzplt += 8;
   5151      1.1     skrll       /* If this entry is the one that gets the resolver stub, account
   5152      1.1     skrll 	 for the additional instruction.  */
   5153      1.1     skrll       if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE
   5154      1.1     skrll 	  == FRVFDPIC_LZPLT_RESOLV_LOC)
   5155      1.1     skrll 	dinfo->g.lzplt += 4;
   5156      1.1     skrll     }
   5157      1.1     skrll 
   5158      1.1     skrll   if (entry->tlsplt)
   5159      1.1     skrll     {
   5160      1.1     skrll       int size;
   5161      1.1     skrll 
   5162      1.1     skrll       entry->tlsplt_entry
   5163      1.1     skrll 	= frvfdpic_plt_section (dinfo->g.info)->size;
   5164      1.1     skrll 
   5165      1.1     skrll       if (dinfo->g.info->executable
   5166      1.1     skrll 	  && (entry->symndx != -1
   5167      1.1     skrll 	      || FRVFDPIC_SYM_LOCAL (dinfo->g.info, entry->d.h)))
   5168      1.1     skrll 	{
   5169      1.1     skrll 	  if ((bfd_signed_vma)entry->addend >= -(1 << (16 - 1))
   5170      1.1     skrll 	      /* FIXME: here we use the size of the TLS section
   5171      1.1     skrll 		 as an upper bound for the value of the TLS
   5172      1.1     skrll 		 symbol, because we may not know the exact value
   5173      1.1     skrll 		 yet.  If we get it wrong, we'll just waste a
   5174      1.1     skrll 		 word in the PLT, and we should never get even
   5175      1.1     skrll 		 close to 32 KiB of TLS anyway.  */
   5176      1.1     skrll 	      && elf_hash_table (dinfo->g.info)->tls_sec
   5177      1.1     skrll 	      && (elf_hash_table (dinfo->g.info)->tls_sec->size
   5178      1.1     skrll 		  + (bfd_signed_vma)(entry->addend) <= (1 << (16 - 1))))
   5179      1.1     skrll 	    size = 8;
   5180      1.1     skrll 	  else
   5181      1.1     skrll 	    size = 12;
   5182      1.1     skrll 	}
   5183      1.1     skrll       else if (entry->tlsoff_entry)
   5184      1.1     skrll 	{
   5185      1.1     skrll 	  if (entry->tlsoff_entry >= -(1 << (12 - 1))
   5186      1.1     skrll 	      && entry->tlsoff_entry < (1 << (12 - 1)))
   5187      1.1     skrll 	    size = 8;
   5188      1.1     skrll 	  else if (entry->tlsoff_entry >= -(1 << (16 - 1))
   5189      1.1     skrll 		   && entry->tlsoff_entry < (1 << (16 - 1)))
   5190      1.1     skrll 	    size = 12;
   5191      1.1     skrll 	  else
   5192      1.1     skrll 	    size = 16;
   5193      1.1     skrll 	}
   5194      1.1     skrll       else
   5195      1.1     skrll 	{
   5196      1.1     skrll 	  BFD_ASSERT (entry->tlsdesc_entry);
   5197      1.1     skrll 
   5198      1.1     skrll 	  if (entry->tlsdesc_entry >= -(1 << (12 - 1))
   5199      1.1     skrll 	      && entry->tlsdesc_entry < (1 << (12 - 1)))
   5200      1.1     skrll 	    size = 8;
   5201      1.1     skrll 	  else if (entry->tlsdesc_entry >= -(1 << (16 - 1))
   5202      1.1     skrll 		   && entry->tlsdesc_entry < (1 << (16 - 1)))
   5203      1.1     skrll 	    size = 12;
   5204      1.1     skrll 	  else
   5205      1.1     skrll 	    size = 16;
   5206      1.1     skrll 	}
   5207      1.1     skrll 
   5208      1.1     skrll       frvfdpic_plt_section (dinfo->g.info)->size += size;
   5209      1.1     skrll     }
   5210      1.1     skrll 
   5211      1.1     skrll   return 1;
   5212      1.1     skrll }
   5213      1.1     skrll 
   5214      1.1     skrll /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
   5215      1.1     skrll    _frvfdpic_assign_plt_entries.  */
   5216      1.1     skrll 
   5217      1.1     skrll static int
   5218      1.1     skrll _frvfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED)
   5219      1.1     skrll {
   5220      1.1     skrll   struct frvfdpic_relocs_info *entry = *entryp;
   5221      1.1     skrll 
   5222      1.1     skrll   entry->got_entry = 0;
   5223      1.1     skrll   entry->fdgot_entry = 0;
   5224      1.1     skrll   entry->fd_entry = 0;
   5225      1.1     skrll   entry->plt_entry = (bfd_vma)-1;
   5226      1.1     skrll   entry->lzplt_entry = (bfd_vma)-1;
   5227      1.1     skrll   entry->tlsoff_entry = 0;
   5228      1.1     skrll   entry->tlsdesc_entry = 0;
   5229      1.1     skrll   entry->tlsplt_entry = (bfd_vma)-1;
   5230      1.1     skrll 
   5231      1.1     skrll   return 1;
   5232      1.1     skrll }
   5233      1.1     skrll 
   5234      1.1     skrll /* Follow indirect and warning hash entries so that each got entry
   5235      1.1     skrll    points to the final symbol definition.  P must point to a pointer
   5236      1.1     skrll    to the hash table we're traversing.  Since this traversal may
   5237      1.1     skrll    modify the hash table, we set this pointer to NULL to indicate
   5238      1.1     skrll    we've made a potentially-destructive change to the hash table, so
   5239      1.1     skrll    the traversal must be restarted.  */
   5240      1.1     skrll static int
   5241      1.1     skrll _frvfdpic_resolve_final_relocs_info (void **entryp, void *p)
   5242      1.1     skrll {
   5243      1.1     skrll   struct frvfdpic_relocs_info *entry = *entryp;
   5244      1.1     skrll   htab_t *htab = p;
   5245      1.1     skrll 
   5246      1.1     skrll   if (entry->symndx == -1)
   5247      1.1     skrll     {
   5248      1.1     skrll       struct elf_link_hash_entry *h = entry->d.h;
   5249      1.1     skrll       struct frvfdpic_relocs_info *oentry;
   5250      1.1     skrll 
   5251      1.1     skrll       while (h->root.type == bfd_link_hash_indirect
   5252      1.1     skrll 	     || h->root.type == bfd_link_hash_warning)
   5253      1.1     skrll 	h = (struct elf_link_hash_entry *)h->root.u.i.link;
   5254      1.1     skrll 
   5255      1.1     skrll       if (entry->d.h == h)
   5256      1.1     skrll 	return 1;
   5257      1.1     skrll 
   5258      1.1     skrll       oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend,
   5259      1.1     skrll 						NO_INSERT);
   5260      1.1     skrll 
   5261      1.1     skrll       if (oentry)
   5262      1.1     skrll 	{
   5263      1.1     skrll 	  /* Merge the two entries.  */
   5264      1.1     skrll 	  frvfdpic_pic_merge_early_relocs_info (oentry, entry);
   5265      1.1     skrll 	  htab_clear_slot (*htab, entryp);
   5266      1.1     skrll 	  return 1;
   5267      1.1     skrll 	}
   5268      1.1     skrll 
   5269      1.1     skrll       entry->d.h = h;
   5270      1.1     skrll 
   5271      1.1     skrll       /* If we can't find this entry with the new bfd hash, re-insert
   5272      1.1     skrll 	 it, and get the traversal restarted.  */
   5273      1.1     skrll       if (! htab_find (*htab, entry))
   5274      1.1     skrll 	{
   5275      1.1     skrll 	  htab_clear_slot (*htab, entryp);
   5276      1.1     skrll 	  entryp = htab_find_slot (*htab, entry, INSERT);
   5277      1.1     skrll 	  if (! *entryp)
   5278      1.1     skrll 	    *entryp = entry;
   5279      1.1     skrll 	  /* Abort the traversal, since the whole table may have
   5280      1.1     skrll 	     moved, and leave it up to the parent to restart the
   5281      1.1     skrll 	     process.  */
   5282      1.1     skrll 	  *(htab_t *)p = NULL;
   5283      1.1     skrll 	  return 0;
   5284      1.1     skrll 	}
   5285      1.1     skrll     }
   5286      1.1     skrll 
   5287      1.1     skrll   return 1;
   5288      1.1     skrll }
   5289      1.1     skrll 
   5290      1.1     skrll /* Compute the total size of the GOT, the PLT, the dynamic relocations
   5291      1.1     skrll    section and the rofixup section.  Assign locations for GOT and PLT
   5292      1.1     skrll    entries.  */
   5293      1.1     skrll 
   5294      1.1     skrll static bfd_boolean
   5295      1.1     skrll _frvfdpic_size_got_plt (bfd *output_bfd,
   5296      1.1     skrll 			struct _frvfdpic_dynamic_got_plt_info *gpinfop)
   5297      1.1     skrll {
   5298      1.1     skrll   bfd_signed_vma odd;
   5299      1.1     skrll   bfd_vma limit, tlslimit;
   5300      1.1     skrll   struct bfd_link_info *info = gpinfop->g.info;
   5301      1.1     skrll   bfd *dynobj = elf_hash_table (info)->dynobj;
   5302      1.1     skrll 
   5303      1.1     skrll   memcpy (frvfdpic_dynamic_got_plt_info (info), &gpinfop->g,
   5304      1.1     skrll 	  sizeof (gpinfop->g));
   5305      1.1     skrll 
   5306      1.1     skrll   odd = 12;
   5307      1.1     skrll   /* Compute the total size taken by entries in the 12-bit and 16-bit
   5308      1.1     skrll      ranges, to tell how many PLT function descriptors we can bring
   5309      1.1     skrll      into the 12-bit range without causing the 16-bit range to
   5310      1.1     skrll      overflow.  */
   5311      1.1     skrll   limit = odd + gpinfop->g.got12 + gpinfop->g.gotlos
   5312      1.1     skrll     + gpinfop->g.fd12 + gpinfop->g.fdlos
   5313      1.1     skrll     + gpinfop->g.tlsd12 + gpinfop->g.tlsdlos;
   5314      1.1     skrll   if (limit < (bfd_vma)1 << 16)
   5315      1.1     skrll     limit = ((bfd_vma)1 << 16) - limit;
   5316      1.1     skrll   else
   5317      1.1     skrll     limit = 0;
   5318      1.1     skrll   if (gpinfop->g.fdplt < limit)
   5319      1.1     skrll     {
   5320      1.1     skrll       tlslimit = (limit - gpinfop->g.fdplt) & ~ (bfd_vma) 8;
   5321      1.1     skrll       limit = gpinfop->g.fdplt;
   5322      1.1     skrll     }
   5323      1.1     skrll   else
   5324      1.1     skrll     tlslimit = 0;
   5325      1.1     skrll   if (gpinfop->g.tlsdplt < tlslimit)
   5326      1.1     skrll     tlslimit = gpinfop->g.tlsdplt;
   5327      1.1     skrll 
   5328      1.1     skrll   /* Determine the ranges of GOT offsets that we can use for each
   5329      1.1     skrll      range of addressing modes.  */
   5330      1.1     skrll   odd = _frvfdpic_compute_got_alloc_data (&gpinfop->got12,
   5331      1.1     skrll 					  0,
   5332      1.1     skrll 					  odd,
   5333      1.1     skrll 					  16,
   5334      1.1     skrll 					  gpinfop->g.got12,
   5335      1.1     skrll 					  gpinfop->g.fd12,
   5336      1.1     skrll 					  limit,
   5337      1.1     skrll 					  gpinfop->g.tlsd12,
   5338      1.1     skrll 					  tlslimit,
   5339      1.1     skrll 					  (bfd_vma)1 << (12-1));
   5340      1.1     skrll   odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gotlos,
   5341      1.1     skrll 					  gpinfop->got12.tmin,
   5342      1.1     skrll 					  odd,
   5343      1.1     skrll 					  gpinfop->got12.tmax,
   5344      1.1     skrll 					  gpinfop->g.gotlos,
   5345      1.1     skrll 					  gpinfop->g.fdlos,
   5346      1.1     skrll 					  gpinfop->g.fdplt
   5347      1.1     skrll 					  - gpinfop->got12.fdplt,
   5348      1.1     skrll 					  gpinfop->g.tlsdlos,
   5349      1.1     skrll 					  gpinfop->g.tlsdplt
   5350      1.1     skrll 					  - gpinfop->got12.tlsdplt,
   5351      1.1     skrll 					  (bfd_vma)1 << (16-1));
   5352      1.1     skrll   odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gothilo,
   5353      1.1     skrll 					  gpinfop->gotlos.tmin,
   5354      1.1     skrll 					  odd,
   5355      1.1     skrll 					  gpinfop->gotlos.tmax,
   5356      1.1     skrll 					  gpinfop->g.gothilo,
   5357      1.1     skrll 					  gpinfop->g.fdhilo,
   5358      1.1     skrll 					  gpinfop->g.fdplt
   5359      1.1     skrll 					  - gpinfop->got12.fdplt
   5360      1.1     skrll 					  - gpinfop->gotlos.fdplt,
   5361      1.1     skrll 					  gpinfop->g.tlsdhilo,
   5362      1.1     skrll 					  gpinfop->g.tlsdplt
   5363      1.1     skrll 					  - gpinfop->got12.tlsdplt
   5364      1.1     skrll 					  - gpinfop->gotlos.tlsdplt,
   5365      1.1     skrll 					  (bfd_vma)1 << (32-1));
   5366      1.1     skrll 
   5367      1.1     skrll   /* Now assign (most) GOT offsets.  */
   5368      1.1     skrll   htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries,
   5369      1.1     skrll 		 gpinfop);
   5370      1.1     skrll 
   5371      1.1     skrll   frvfdpic_got_section (info)->size = gpinfop->gothilo.tmax
   5372      1.1     skrll     - gpinfop->gothilo.tmin
   5373      1.1     skrll     /* If an odd word is the last word of the GOT, we don't need this
   5374      1.1     skrll        word to be part of the GOT.  */
   5375      1.1     skrll     - (odd + 4 == gpinfop->gothilo.tmax ? 4 : 0);
   5376      1.1     skrll   if (frvfdpic_got_section (info)->size == 0)
   5377      1.1     skrll     frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
   5378      1.1     skrll   else if (frvfdpic_got_section (info)->size == 12
   5379      1.1     skrll 	   && ! elf_hash_table (info)->dynamic_sections_created)
   5380      1.1     skrll     {
   5381      1.1     skrll       frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
   5382      1.1     skrll       frvfdpic_got_section (info)->size = 0;
   5383      1.1     skrll     }
   5384      1.1     skrll   /* This will be non-NULL during relaxation.  The assumption is that
   5385      1.1     skrll      the size of one of these sections will never grow, only shrink,
   5386      1.1     skrll      so we can use the larger buffer we allocated before.  */
   5387      1.1     skrll   else if (frvfdpic_got_section (info)->contents == NULL)
   5388      1.1     skrll     {
   5389      1.1     skrll       frvfdpic_got_section (info)->contents =
   5390      1.1     skrll 	(bfd_byte *) bfd_zalloc (dynobj,
   5391      1.1     skrll 				 frvfdpic_got_section (info)->size);
   5392      1.1     skrll       if (frvfdpic_got_section (info)->contents == NULL)
   5393      1.1     skrll 	return FALSE;
   5394      1.1     skrll     }
   5395      1.1     skrll 
   5396      1.1     skrll   if (frvfdpic_gotrel_section (info))
   5397      1.1     skrll     /* Subtract the number of lzplt entries, since those will generate
   5398      1.1     skrll        relocations in the pltrel section.  */
   5399      1.1     skrll     frvfdpic_gotrel_section (info)->size =
   5400      1.1     skrll       (gpinfop->g.relocs - gpinfop->g.lzplt / 8)
   5401      1.1     skrll       * get_elf_backend_data (output_bfd)->s->sizeof_rel;
   5402      1.1     skrll   else
   5403      1.1     skrll     BFD_ASSERT (gpinfop->g.relocs == 0);
   5404      1.1     skrll   if (frvfdpic_gotrel_section (info)->size == 0)
   5405      1.1     skrll     frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE;
   5406      1.1     skrll   else if (frvfdpic_gotrel_section (info)->contents == NULL)
   5407      1.1     skrll     {
   5408      1.1     skrll       frvfdpic_gotrel_section (info)->contents =
   5409      1.1     skrll 	(bfd_byte *) bfd_zalloc (dynobj,
   5410      1.1     skrll 				 frvfdpic_gotrel_section (info)->size);
   5411      1.1     skrll       if (frvfdpic_gotrel_section (info)->contents == NULL)
   5412      1.1     skrll 	return FALSE;
   5413      1.1     skrll     }
   5414      1.1     skrll 
   5415      1.1     skrll   frvfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4;
   5416      1.1     skrll   if (frvfdpic_gotfixup_section (info)->size == 0)
   5417      1.1     skrll     frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE;
   5418      1.1     skrll   else if (frvfdpic_gotfixup_section (info)->contents == NULL)
   5419      1.1     skrll     {
   5420      1.1     skrll       frvfdpic_gotfixup_section (info)->contents =
   5421      1.1     skrll 	(bfd_byte *) bfd_zalloc (dynobj,
   5422      1.1     skrll 				 frvfdpic_gotfixup_section (info)->size);
   5423      1.1     skrll       if (frvfdpic_gotfixup_section (info)->contents == NULL)
   5424      1.1     skrll 	return FALSE;
   5425      1.1     skrll     }
   5426      1.1     skrll 
   5427      1.1     skrll   if (frvfdpic_pltrel_section (info))
   5428      1.1     skrll     {
   5429      1.1     skrll       frvfdpic_pltrel_section (info)->size =
   5430      1.1     skrll 	gpinfop->g.lzplt / 8
   5431      1.1     skrll 	* get_elf_backend_data (output_bfd)->s->sizeof_rel;
   5432      1.1     skrll       if (frvfdpic_pltrel_section (info)->size == 0)
   5433      1.1     skrll 	frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE;
   5434      1.1     skrll       else if (frvfdpic_pltrel_section (info)->contents == NULL)
   5435      1.1     skrll 	{
   5436      1.1     skrll 	  frvfdpic_pltrel_section (info)->contents =
   5437      1.1     skrll 	    (bfd_byte *) bfd_zalloc (dynobj,
   5438      1.1     skrll 				     frvfdpic_pltrel_section (info)->size);
   5439      1.1     skrll 	  if (frvfdpic_pltrel_section (info)->contents == NULL)
   5440      1.1     skrll 	    return FALSE;
   5441      1.1     skrll 	}
   5442      1.1     skrll     }
   5443      1.1     skrll 
   5444      1.1     skrll   /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
   5445      1.1     skrll      such that there's room for the additional instruction needed to
   5446      1.1     skrll      call the resolver.  Since _frvfdpic_assign_got_entries didn't
   5447      1.1     skrll      account for them, our block size is 4 bytes smaller than the real
   5448      1.1     skrll      block size.  */
   5449      1.1     skrll   if (frvfdpic_plt_section (info))
   5450      1.1     skrll     {
   5451      1.1     skrll       frvfdpic_plt_section (info)->size = gpinfop->g.lzplt
   5452      1.1     skrll 	+ ((gpinfop->g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8)
   5453      1.1     skrll 	   / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4);
   5454      1.1     skrll     }
   5455      1.1     skrll 
   5456      1.1     skrll   /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
   5457      1.1     skrll      actually assign lazy PLT entries addresses.  */
   5458      1.1     skrll   gpinfop->g.lzplt = 0;
   5459      1.1     skrll 
   5460      1.1     skrll   /* Save information that we're going to need to generate GOT and PLT
   5461      1.1     skrll      entries.  */
   5462      1.1     skrll   frvfdpic_got_initial_offset (info) = -gpinfop->gothilo.tmin;
   5463      1.1     skrll 
   5464      1.1     skrll   if (get_elf_backend_data (output_bfd)->want_got_sym)
   5465      1.1     skrll     elf_hash_table (info)->hgot->root.u.def.value
   5466      1.1     skrll       = frvfdpic_got_initial_offset (info);
   5467      1.1     skrll 
   5468      1.1     skrll   if (frvfdpic_plt_section (info))
   5469      1.1     skrll     frvfdpic_plt_initial_offset (info) =
   5470      1.1     skrll       frvfdpic_plt_section (info)->size;
   5471      1.1     skrll 
   5472      1.1     skrll   /* Allocate a ret statement at plt_initial_offset, to be used by
   5473      1.1     skrll      locally-resolved TLS descriptors.  */
   5474      1.1     skrll   if (gpinfop->g.tls_ret_refs)
   5475      1.1     skrll     frvfdpic_plt_section (info)->size += 4;
   5476      1.1     skrll 
   5477      1.1     skrll   htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries,
   5478      1.1     skrll 		 gpinfop);
   5479      1.1     skrll 
   5480      1.1     skrll   /* Allocate the PLT section contents only after
   5481      1.1     skrll      _frvfdpic_assign_plt_entries has a chance to add the size of the
   5482      1.1     skrll      non-lazy PLT entries.  */
   5483      1.1     skrll   if (frvfdpic_plt_section (info))
   5484      1.1     skrll     {
   5485      1.1     skrll       if (frvfdpic_plt_section (info)->size == 0)
   5486      1.1     skrll 	frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE;
   5487      1.1     skrll       else if (frvfdpic_plt_section (info)->contents == NULL)
   5488      1.1     skrll 	{
   5489      1.1     skrll 	  frvfdpic_plt_section (info)->contents =
   5490      1.1     skrll 	    (bfd_byte *) bfd_zalloc (dynobj,
   5491      1.1     skrll 				     frvfdpic_plt_section (info)->size);
   5492      1.1     skrll 	  if (frvfdpic_plt_section (info)->contents == NULL)
   5493      1.1     skrll 	    return FALSE;
   5494      1.1     skrll 	}
   5495      1.1     skrll     }
   5496      1.1     skrll 
   5497      1.1     skrll   return TRUE;
   5498      1.1     skrll }
   5499      1.1     skrll 
   5500      1.1     skrll /* Set the sizes of the dynamic sections.  */
   5501      1.1     skrll 
   5502      1.1     skrll static bfd_boolean
   5503      1.1     skrll elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd,
   5504      1.1     skrll 				      struct bfd_link_info *info)
   5505      1.1     skrll {
   5506      1.1     skrll   bfd *dynobj;
   5507      1.1     skrll   asection *s;
   5508      1.1     skrll   struct _frvfdpic_dynamic_got_plt_info gpinfo;
   5509      1.1     skrll 
   5510      1.1     skrll   dynobj = elf_hash_table (info)->dynobj;
   5511      1.1     skrll   BFD_ASSERT (dynobj != NULL);
   5512      1.1     skrll 
   5513      1.1     skrll   if (elf_hash_table (info)->dynamic_sections_created)
   5514      1.1     skrll     {
   5515      1.1     skrll       /* Set the contents of the .interp section to the interpreter.  */
   5516      1.1     skrll       if (info->executable)
   5517      1.1     skrll 	{
   5518      1.1     skrll 	  s = bfd_get_section_by_name (dynobj, ".interp");
   5519      1.1     skrll 	  BFD_ASSERT (s != NULL);
   5520      1.1     skrll 	  s->size = sizeof ELF_DYNAMIC_INTERPRETER;
   5521      1.1     skrll 	  s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
   5522      1.1     skrll 	}
   5523      1.1     skrll     }
   5524      1.1     skrll 
   5525      1.1     skrll   memset (&gpinfo, 0, sizeof (gpinfo));
   5526      1.1     skrll   gpinfo.g.info = info;
   5527      1.1     skrll 
   5528      1.1     skrll   for (;;)
   5529      1.1     skrll     {
   5530      1.1     skrll       htab_t relocs = frvfdpic_relocs_info (info);
   5531      1.1     skrll 
   5532      1.1     skrll       htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs);
   5533      1.1     skrll 
   5534      1.1     skrll       if (relocs == frvfdpic_relocs_info (info))
   5535      1.1     skrll 	break;
   5536      1.1     skrll     }
   5537      1.1     skrll 
   5538      1.1     skrll   htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries,
   5539      1.1     skrll 		 &gpinfo.g);
   5540      1.1     skrll 
   5541      1.1     skrll   /* Allocate space to save the summary information, we're going to
   5542      1.1     skrll      use it if we're doing relaxations.  */
   5543      1.1     skrll   frvfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g));
   5544      1.1     skrll 
   5545      1.1     skrll   if (!_frvfdpic_size_got_plt (output_bfd, &gpinfo))
   5546      1.1     skrll     return FALSE;
   5547      1.1     skrll 
   5548      1.1     skrll   if (elf_hash_table (info)->dynamic_sections_created)
   5549      1.1     skrll     {
   5550      1.1     skrll       if (frvfdpic_got_section (info)->size)
   5551      1.1     skrll 	if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0))
   5552      1.1     skrll 	  return FALSE;
   5553      1.1     skrll 
   5554      1.1     skrll       if (frvfdpic_pltrel_section (info)->size)
   5555      1.1     skrll 	if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
   5556      1.1     skrll 	    || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL)
   5557      1.1     skrll 	    || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
   5558      1.1     skrll 	  return FALSE;
   5559      1.1     skrll 
   5560      1.1     skrll       if (frvfdpic_gotrel_section (info)->size)
   5561      1.1     skrll 	if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0)
   5562      1.1     skrll 	    || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0)
   5563      1.1     skrll 	    || !_bfd_elf_add_dynamic_entry (info, DT_RELENT,
   5564      1.1     skrll 					    sizeof (Elf32_External_Rel)))
   5565      1.1     skrll 	  return FALSE;
   5566      1.1     skrll     }
   5567      1.1     skrll 
   5568      1.1     skrll   return TRUE;
   5569      1.1     skrll }
   5570      1.1     skrll 
   5571      1.1     skrll static bfd_boolean
   5572      1.1     skrll elf32_frvfdpic_always_size_sections (bfd *output_bfd,
   5573      1.1     skrll 				     struct bfd_link_info *info)
   5574      1.1     skrll {
   5575      1.1     skrll   if (!info->relocatable)
   5576      1.1     skrll     {
   5577      1.1     skrll       struct elf_link_hash_entry *h;
   5578      1.1     skrll 
   5579      1.1     skrll       /* Force a PT_GNU_STACK segment to be created.  */
   5580      1.1     skrll       if (! elf_tdata (output_bfd)->stack_flags)
   5581      1.1     skrll 	elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
   5582      1.1     skrll 
   5583      1.1     skrll       /* Define __stacksize if it's not defined yet.  */
   5584      1.1     skrll       h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
   5585      1.1     skrll 				FALSE, FALSE, FALSE);
   5586      1.1     skrll       if (! h || h->root.type != bfd_link_hash_defined
   5587      1.1     skrll 	  || h->type != STT_OBJECT
   5588      1.1     skrll 	  || !h->def_regular)
   5589      1.1     skrll 	{
   5590      1.1     skrll 	  struct bfd_link_hash_entry *bh = NULL;
   5591      1.1     skrll 
   5592      1.1     skrll 	  if (!(_bfd_generic_link_add_one_symbol
   5593      1.1     skrll 		(info, output_bfd, "__stacksize",
   5594      1.1     skrll 		 BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE,
   5595      1.1     skrll 		 (const char *) NULL, FALSE,
   5596      1.1     skrll 		 get_elf_backend_data (output_bfd)->collect, &bh)))
   5597      1.1     skrll 	    return FALSE;
   5598      1.1     skrll 
   5599      1.1     skrll 	  h = (struct elf_link_hash_entry *) bh;
   5600      1.1     skrll 	  h->def_regular = 1;
   5601      1.1     skrll 	  h->type = STT_OBJECT;
   5602      1.1     skrll 	  /* This one must NOT be hidden.  */
   5603      1.1     skrll 	}
   5604      1.1     skrll     }
   5605      1.1     skrll 
   5606      1.1     skrll   return TRUE;
   5607      1.1     skrll }
   5608      1.1     skrll 
   5609      1.1     skrll /* Check whether any of the relocations was optimized away, and
   5610      1.1     skrll    subtract it from the relocation or fixup count.  */
   5611      1.1     skrll static bfd_boolean
   5612      1.1     skrll _frvfdpic_check_discarded_relocs (bfd *abfd, asection *sec,
   5613      1.1     skrll 				  struct bfd_link_info *info,
   5614      1.1     skrll 
   5615      1.1     skrll 				  bfd_boolean *changed)
   5616      1.1     skrll {
   5617      1.1     skrll   Elf_Internal_Shdr *symtab_hdr;
   5618      1.1     skrll   struct elf_link_hash_entry **sym_hashes;
   5619      1.1     skrll   Elf_Internal_Rela *rel, *erel;
   5620      1.1     skrll 
   5621      1.1     skrll   if ((sec->flags & SEC_RELOC) == 0
   5622      1.1     skrll       || sec->reloc_count == 0)
   5623      1.1     skrll     return TRUE;
   5624      1.1     skrll 
   5625      1.1     skrll   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   5626      1.1     skrll   sym_hashes = elf_sym_hashes (abfd);
   5627      1.1     skrll 
   5628      1.1     skrll   rel = elf_section_data (sec)->relocs;
   5629      1.1     skrll 
   5630      1.1     skrll   /* Now examine each relocation.  */
   5631      1.1     skrll   for (erel = rel + sec->reloc_count; rel < erel; rel++)
   5632      1.1     skrll     {
   5633      1.1     skrll       struct elf_link_hash_entry *h;
   5634      1.1     skrll       unsigned long r_symndx;
   5635      1.1     skrll       struct frvfdpic_relocs_info *picrel;
   5636      1.1     skrll       struct _frvfdpic_dynamic_got_info *dinfo;
   5637      1.1     skrll 
   5638      1.1     skrll       if (ELF32_R_TYPE (rel->r_info) != R_FRV_32
   5639      1.1     skrll 	  && ELF32_R_TYPE (rel->r_info) != R_FRV_FUNCDESC)
   5640      1.1     skrll 	continue;
   5641      1.1     skrll 
   5642      1.1     skrll       if (_bfd_elf_section_offset (sec->output_section->owner,
   5643      1.1     skrll 				   info, sec, rel->r_offset)
   5644      1.1     skrll 	  != (bfd_vma)-1)
   5645      1.1     skrll 	continue;
   5646      1.1     skrll 
   5647      1.1     skrll       r_symndx = ELF32_R_SYM (rel->r_info);
   5648      1.1     skrll       if (r_symndx < symtab_hdr->sh_info)
   5649      1.1     skrll 	h = NULL;
   5650      1.1     skrll       else
   5651      1.1     skrll 	{
   5652      1.1     skrll 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   5653      1.1     skrll 	  while (h->root.type == bfd_link_hash_indirect
   5654      1.1     skrll 		 || h->root.type == bfd_link_hash_warning)
   5655      1.1     skrll 	    h = (struct elf_link_hash_entry *)h->root.u.i.link;
   5656      1.1     skrll 	}
   5657      1.1     skrll 
   5658      1.1     skrll       if (h != NULL)
   5659      1.1     skrll 	picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info),
   5660      1.1     skrll 						  abfd, h,
   5661      1.1     skrll 						  rel->r_addend, NO_INSERT);
   5662      1.1     skrll       else
   5663      1.1     skrll 	picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info),
   5664      1.1     skrll 						 abfd, r_symndx,
   5665      1.1     skrll 						 rel->r_addend, NO_INSERT);
   5666      1.1     skrll 
   5667      1.1     skrll       if (! picrel)
   5668      1.1     skrll 	return FALSE;
   5669      1.1     skrll 
   5670      1.1     skrll       *changed = TRUE;
   5671      1.1     skrll       dinfo = frvfdpic_dynamic_got_plt_info (info);
   5672      1.1     skrll 
   5673      1.1     skrll       _frvfdpic_count_relocs_fixups (picrel, dinfo, TRUE);
   5674      1.1     skrll       if (ELF32_R_TYPE (rel->r_info) == R_FRV_32)
   5675      1.1     skrll 	picrel->relocs32--;
   5676      1.1     skrll       else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */
   5677      1.1     skrll 	picrel->relocsfd--;
   5678      1.1     skrll       _frvfdpic_count_relocs_fixups (picrel, dinfo, FALSE);
   5679      1.1     skrll     }
   5680      1.1     skrll 
   5681      1.1     skrll   return TRUE;
   5682      1.1     skrll }
   5683      1.1     skrll 
   5684      1.1     skrll static bfd_boolean
   5685      1.1     skrll frvfdpic_elf_discard_info (bfd *ibfd,
   5686      1.1     skrll 			   struct elf_reloc_cookie *cookie ATTRIBUTE_UNUSED,
   5687      1.1     skrll 			   struct bfd_link_info *info)
   5688      1.1     skrll {
   5689      1.1     skrll   bfd_boolean changed = FALSE;
   5690      1.1     skrll   asection *s;
   5691      1.1     skrll   bfd *obfd = NULL;
   5692      1.1     skrll 
   5693      1.1     skrll   /* Account for relaxation of .eh_frame section.  */
   5694      1.1     skrll   for (s = ibfd->sections; s; s = s->next)
   5695      1.1     skrll     if (s->sec_info_type == ELF_INFO_TYPE_EH_FRAME)
   5696      1.1     skrll       {
   5697      1.1     skrll 	if (!_frvfdpic_check_discarded_relocs (ibfd, s, info, &changed))
   5698      1.1     skrll 	  return FALSE;
   5699      1.1     skrll 	obfd = s->output_section->owner;
   5700      1.1     skrll       }
   5701      1.1     skrll 
   5702      1.1     skrll   if (changed)
   5703      1.1     skrll     {
   5704      1.1     skrll       struct _frvfdpic_dynamic_got_plt_info gpinfo;
   5705      1.1     skrll 
   5706      1.1     skrll       memset (&gpinfo, 0, sizeof (gpinfo));
   5707      1.1     skrll       memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info),
   5708      1.1     skrll 	      sizeof (gpinfo.g));
   5709      1.1     skrll 
   5710      1.1     skrll       /* Clear GOT and PLT assignments.  */
   5711      1.1     skrll       htab_traverse (frvfdpic_relocs_info (info),
   5712      1.1     skrll 		     _frvfdpic_reset_got_plt_entries,
   5713      1.1     skrll 		     NULL);
   5714      1.1     skrll 
   5715      1.1     skrll       if (!_frvfdpic_size_got_plt (obfd, &gpinfo))
   5716      1.1     skrll 	return FALSE;
   5717      1.1     skrll     }
   5718      1.1     skrll 
   5719      1.1     skrll   return TRUE;
   5720      1.1     skrll }
   5721      1.1     skrll 
   5722      1.1     skrll /* Look for opportunities to relax TLS relocations.  We can assume
   5723      1.1     skrll    we're linking the main executable or a static-tls library, since
   5724      1.1     skrll    otherwise we wouldn't have got here.  */
   5725      1.1     skrll 
   5726      1.1     skrll static int
   5727      1.1     skrll _frvfdpic_relax_got_plt_entries (void **entryp, void *dinfo_)
   5728      1.1     skrll {
   5729      1.1     skrll   struct frvfdpic_relocs_info *entry = *entryp;
   5730      1.1     skrll   struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
   5731      1.1     skrll 
   5732      1.1     skrll   _frvfdpic_relax_tls_entries (entry, dinfo, TRUE);
   5733      1.1     skrll 
   5734      1.1     skrll   return 1;
   5735      1.1     skrll }
   5736      1.1     skrll 
   5737      1.1     skrll static bfd_boolean
   5738  1.1.1.2  christos elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
   5739  1.1.1.2  christos 			      struct bfd_link_info *info, bfd_boolean *again)
   5740  1.1.1.2  christos {
   5741  1.1.1.2  christos   struct _frvfdpic_dynamic_got_plt_info gpinfo;
   5742      1.1     skrll 
   5743      1.1     skrll   if (info->relocatable)
   5744      1.1     skrll     (*info->callbacks->einfo)
   5745      1.1     skrll       (_("%P%F: --relax and -r may not be used together\n"));
   5746      1.1     skrll 
   5747      1.1     skrll   /* If we return early, we didn't change anything.  */
   5748      1.1     skrll   *again = FALSE;
   5749      1.1     skrll 
   5750      1.1     skrll   /* We'll do our thing when requested to relax the GOT section.  */
   5751      1.1     skrll   if (sec != frvfdpic_got_section (info))
   5752      1.1     skrll     return TRUE;
   5753      1.1     skrll 
   5754      1.1     skrll   /* We can only relax when linking the main executable or a library
   5755      1.1     skrll      that can't be dlopened.  */
   5756      1.1     skrll   if (! info->executable && ! (info->flags & DF_STATIC_TLS))
   5757      1.1     skrll     return TRUE;
   5758      1.1     skrll 
   5759      1.1     skrll   /* If there isn't a TLS section for this binary, we can't do
   5760      1.1     skrll      anything about its TLS relocations (it probably doesn't have
   5761      1.1     skrll      any.  */
   5762      1.1     skrll   if (elf_hash_table (info)->tls_sec == NULL)
   5763      1.1     skrll     return TRUE;
   5764      1.1     skrll 
   5765      1.1     skrll   memset (&gpinfo, 0, sizeof (gpinfo));
   5766      1.1     skrll   memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), sizeof (gpinfo.g));
   5767      1.1     skrll 
   5768      1.1     skrll   /* Now look for opportunities to relax, adjusting the GOT usage
   5769      1.1     skrll      as needed.  */
   5770      1.1     skrll   htab_traverse (frvfdpic_relocs_info (info),
   5771      1.1     skrll 		 _frvfdpic_relax_got_plt_entries,
   5772      1.1     skrll 		 &gpinfo.g);
   5773      1.1     skrll 
   5774      1.1     skrll   /* If we changed anything, reset and re-assign GOT and PLT entries.  */
   5775      1.1     skrll   if (memcmp (frvfdpic_dynamic_got_plt_info (info),
   5776      1.1     skrll 	      &gpinfo.g, sizeof (gpinfo.g)) != 0)
   5777      1.1     skrll     {
   5778      1.1     skrll       /* Clear GOT and PLT assignments.  */
   5779      1.1     skrll       htab_traverse (frvfdpic_relocs_info (info),
   5780      1.1     skrll 		     _frvfdpic_reset_got_plt_entries,
   5781      1.1     skrll 		     NULL);
   5782      1.1     skrll 
   5783      1.1     skrll       /* The owner of the TLS section is the output bfd.  There should
   5784      1.1     skrll 	 be a better way to get to it.  */
   5785      1.1     skrll       if (!_frvfdpic_size_got_plt (elf_hash_table (info)->tls_sec->owner,
   5786      1.1     skrll 				   &gpinfo))
   5787      1.1     skrll 	return FALSE;
   5788      1.1     skrll 
   5789      1.1     skrll       /* Repeat until we don't make any further changes.  We could fail to
   5790      1.1     skrll 	 introduce changes in a round if, for example, the 12-bit range is
   5791      1.1     skrll 	 full, but we later release some space by getting rid of TLS
   5792      1.1     skrll 	 descriptors in it.  We have to repeat the whole process because
   5793      1.1     skrll 	 we might have changed the size of a section processed before this
   5794      1.1     skrll 	 one.  */
   5795      1.1     skrll       *again = TRUE;
   5796      1.1     skrll     }
   5797      1.1     skrll 
   5798      1.1     skrll   return TRUE;
   5799      1.1     skrll }
   5800      1.1     skrll 
   5801      1.1     skrll static bfd_boolean
   5802      1.1     skrll elf32_frvfdpic_modify_program_headers (bfd *output_bfd,
   5803      1.1     skrll 				       struct bfd_link_info *info)
   5804      1.1     skrll {
   5805      1.1     skrll   struct elf_obj_tdata *tdata = elf_tdata (output_bfd);
   5806      1.1     skrll   struct elf_segment_map *m;
   5807      1.1     skrll   Elf_Internal_Phdr *p;
   5808      1.1     skrll 
   5809      1.1     skrll   /* objcopy and strip preserve what's already there using
   5810      1.1     skrll      elf32_frvfdpic_copy_private_bfd_data ().  */
   5811      1.1     skrll   if (! info)
   5812      1.1     skrll     return TRUE;
   5813      1.1     skrll 
   5814      1.1     skrll   for (p = tdata->phdr, m = tdata->segment_map; m != NULL; m = m->next, p++)
   5815      1.1     skrll     if (m->p_type == PT_GNU_STACK)
   5816      1.1     skrll       break;
   5817      1.1     skrll 
   5818      1.1     skrll   if (m)
   5819      1.1     skrll     {
   5820      1.1     skrll       struct elf_link_hash_entry *h;
   5821      1.1     skrll 
   5822      1.1     skrll       /* Obtain the pointer to the __stacksize symbol.  */
   5823      1.1     skrll       h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
   5824      1.1     skrll 				FALSE, FALSE, FALSE);
   5825      1.1     skrll       if (h)
   5826      1.1     skrll 	{
   5827      1.1     skrll 	  while (h->root.type == bfd_link_hash_indirect
   5828      1.1     skrll 		 || h->root.type == bfd_link_hash_warning)
   5829      1.1     skrll 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   5830      1.1     skrll 	  BFD_ASSERT (h->root.type == bfd_link_hash_defined);
   5831      1.1     skrll 	}
   5832      1.1     skrll 
   5833      1.1     skrll       /* Set the header p_memsz from the symbol value.  We
   5834      1.1     skrll 	 intentionally ignore the symbol section.  */
   5835      1.1     skrll       if (h && h->root.type == bfd_link_hash_defined)
   5836      1.1     skrll 	p->p_memsz = h->root.u.def.value;
   5837      1.1     skrll       else
   5838      1.1     skrll 	p->p_memsz = DEFAULT_STACK_SIZE;
   5839      1.1     skrll 
   5840      1.1     skrll       p->p_align = 8;
   5841      1.1     skrll     }
   5842      1.1     skrll 
   5843      1.1     skrll   return TRUE;
   5844      1.1     skrll }
   5845      1.1     skrll 
   5846      1.1     skrll /* Fill in code and data in dynamic sections.  */
   5847      1.1     skrll 
   5848      1.1     skrll static bfd_boolean
   5849      1.1     skrll elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   5850      1.1     skrll 				   struct bfd_link_info *info ATTRIBUTE_UNUSED)
   5851      1.1     skrll {
   5852      1.1     skrll   /* Nothing to be done for non-FDPIC.  */
   5853      1.1     skrll   return TRUE;
   5854      1.1     skrll }
   5855      1.1     skrll 
   5856      1.1     skrll static bfd_boolean
   5857      1.1     skrll elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd,
   5858      1.1     skrll 					struct bfd_link_info *info)
   5859      1.1     skrll {
   5860      1.1     skrll   bfd *dynobj;
   5861      1.1     skrll   asection *sdyn;
   5862      1.1     skrll 
   5863      1.1     skrll   dynobj = elf_hash_table (info)->dynobj;
   5864      1.1     skrll 
   5865      1.1     skrll   if (frvfdpic_dynamic_got_plt_info (info))
   5866      1.1     skrll     {
   5867      1.1     skrll       BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs == 0);
   5868      1.1     skrll     }
   5869      1.1     skrll   if (frvfdpic_got_section (info))
   5870      1.1     skrll     {
   5871      1.1     skrll       BFD_ASSERT (frvfdpic_gotrel_section (info)->size
   5872      1.1     skrll 		  == (frvfdpic_gotrel_section (info)->reloc_count
   5873      1.1     skrll 		      * sizeof (Elf32_External_Rel)));
   5874      1.1     skrll 
   5875      1.1     skrll       if (frvfdpic_gotfixup_section (info))
   5876      1.1     skrll 	{
   5877      1.1     skrll 	  struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot;
   5878      1.1     skrll 	  bfd_vma got_value = hgot->root.u.def.value
   5879      1.1     skrll 	    + hgot->root.u.def.section->output_section->vma
   5880      1.1     skrll 	    + hgot->root.u.def.section->output_offset;
   5881      1.1     skrll 	  struct bfd_link_hash_entry *hend;
   5882      1.1     skrll 
   5883      1.1     skrll 	  _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info),
   5884      1.1     skrll 				 got_value, 0);
   5885      1.1     skrll 
   5886      1.1     skrll 	  if (frvfdpic_gotfixup_section (info)->size
   5887      1.1     skrll 	      != (frvfdpic_gotfixup_section (info)->reloc_count * 4))
   5888      1.1     skrll 	    {
   5889      1.1     skrll 	    error:
   5890      1.1     skrll 	      (*_bfd_error_handler)
   5891      1.1     skrll 		("LINKER BUG: .rofixup section size mismatch");
   5892      1.1     skrll 	      return FALSE;
   5893      1.1     skrll 	    }
   5894  1.1.1.2  christos 
   5895  1.1.1.2  christos 	  hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__",
   5896      1.1     skrll 				       FALSE, FALSE, TRUE);
   5897      1.1     skrll 	  if (hend
   5898      1.1     skrll 	      && (hend->type == bfd_link_hash_defined
   5899      1.1     skrll 		  || hend->type == bfd_link_hash_defweak)
   5900      1.1     skrll 	      && hend->u.def.section->output_section != NULL)
   5901      1.1     skrll 	    {
   5902      1.1     skrll 	      bfd_vma value =
   5903      1.1     skrll 		frvfdpic_gotfixup_section (info)->output_section->vma
   5904      1.1     skrll 		+ frvfdpic_gotfixup_section (info)->output_offset
   5905      1.1     skrll 		+ frvfdpic_gotfixup_section (info)->size
   5906      1.1     skrll 		- hend->u.def.section->output_section->vma
   5907      1.1     skrll 		- hend->u.def.section->output_offset;
   5908      1.1     skrll 	      BFD_ASSERT (hend->u.def.value == value);
   5909      1.1     skrll 	      if (hend->u.def.value != value)
   5910      1.1     skrll 		goto error;
   5911      1.1     skrll 	    }
   5912      1.1     skrll 	}
   5913      1.1     skrll     }
   5914      1.1     skrll   if (frvfdpic_pltrel_section (info))
   5915      1.1     skrll     {
   5916      1.1     skrll       BFD_ASSERT (frvfdpic_pltrel_section (info)->size
   5917      1.1     skrll 		  == (frvfdpic_pltrel_section (info)->reloc_count
   5918      1.1     skrll 		      * sizeof (Elf32_External_Rel)));
   5919      1.1     skrll     }
   5920      1.1     skrll 
   5921      1.1     skrll 
   5922      1.1     skrll   if (elf_hash_table (info)->dynamic_sections_created)
   5923      1.1     skrll     {
   5924      1.1     skrll       Elf32_External_Dyn * dyncon;
   5925      1.1     skrll       Elf32_External_Dyn * dynconend;
   5926      1.1     skrll 
   5927      1.1     skrll       sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
   5928      1.1     skrll 
   5929      1.1     skrll       BFD_ASSERT (sdyn != NULL);
   5930      1.1     skrll 
   5931      1.1     skrll       dyncon = (Elf32_External_Dyn *) sdyn->contents;
   5932      1.1     skrll       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
   5933      1.1     skrll 
   5934      1.1     skrll       for (; dyncon < dynconend; dyncon++)
   5935      1.1     skrll 	{
   5936      1.1     skrll 	  Elf_Internal_Dyn dyn;
   5937      1.1     skrll 
   5938      1.1     skrll 	  bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
   5939      1.1     skrll 
   5940      1.1     skrll 	  switch (dyn.d_tag)
   5941      1.1     skrll 	    {
   5942      1.1     skrll 	    default:
   5943      1.1     skrll 	      break;
   5944      1.1     skrll 
   5945      1.1     skrll 	    case DT_PLTGOT:
   5946      1.1     skrll 	      dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma
   5947      1.1     skrll 		+ frvfdpic_got_section (info)->output_offset
   5948      1.1     skrll 		+ frvfdpic_got_initial_offset (info);
   5949      1.1     skrll 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   5950      1.1     skrll 	      break;
   5951      1.1     skrll 
   5952      1.1     skrll 	    case DT_JMPREL:
   5953      1.1     skrll 	      dyn.d_un.d_ptr = frvfdpic_pltrel_section (info)
   5954      1.1     skrll 		->output_section->vma
   5955      1.1     skrll 		+ frvfdpic_pltrel_section (info)->output_offset;
   5956      1.1     skrll 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   5957      1.1     skrll 	      break;
   5958      1.1     skrll 
   5959      1.1     skrll 	    case DT_PLTRELSZ:
   5960      1.1     skrll 	      dyn.d_un.d_val = frvfdpic_pltrel_section (info)->size;
   5961      1.1     skrll 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   5962      1.1     skrll 	      break;
   5963      1.1     skrll 	    }
   5964      1.1     skrll 	}
   5965      1.1     skrll     }
   5966      1.1     skrll 
   5967      1.1     skrll   return TRUE;
   5968      1.1     skrll }
   5969      1.1     skrll 
   5970      1.1     skrll /* Adjust a symbol defined by a dynamic object and referenced by a
   5971      1.1     skrll    regular object.  */
   5972      1.1     skrll 
   5973      1.1     skrll static bfd_boolean
   5974      1.1     skrll elf32_frvfdpic_adjust_dynamic_symbol
   5975      1.1     skrll (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   5976      1.1     skrll  struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
   5977      1.1     skrll {
   5978      1.1     skrll   bfd * dynobj;
   5979      1.1     skrll 
   5980      1.1     skrll   dynobj = elf_hash_table (info)->dynobj;
   5981      1.1     skrll 
   5982      1.1     skrll   /* Make sure we know what is going on here.  */
   5983      1.1     skrll   BFD_ASSERT (dynobj != NULL
   5984      1.1     skrll 	      && (h->u.weakdef != NULL
   5985      1.1     skrll 		  || (h->def_dynamic
   5986      1.1     skrll 		      && h->ref_regular
   5987      1.1     skrll 		      && !h->def_regular)));
   5988      1.1     skrll 
   5989      1.1     skrll   /* If this is a weak symbol, and there is a real definition, the
   5990      1.1     skrll      processor independent code will have arranged for us to see the
   5991      1.1     skrll      real definition first, and we can just use the same value.  */
   5992      1.1     skrll   if (h->u.weakdef != NULL)
   5993      1.1     skrll     {
   5994      1.1     skrll       BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
   5995      1.1     skrll 		  || h->u.weakdef->root.type == bfd_link_hash_defweak);
   5996      1.1     skrll       h->root.u.def.section = h->u.weakdef->root.u.def.section;
   5997      1.1     skrll       h->root.u.def.value = h->u.weakdef->root.u.def.value;
   5998      1.1     skrll     }
   5999      1.1     skrll 
   6000      1.1     skrll   return TRUE;
   6001      1.1     skrll }
   6002      1.1     skrll 
   6003      1.1     skrll /* Perform any actions needed for dynamic symbols.  */
   6004      1.1     skrll 
   6005      1.1     skrll static bfd_boolean
   6006      1.1     skrll elf32_frvfdpic_finish_dynamic_symbol
   6007      1.1     skrll (bfd *output_bfd ATTRIBUTE_UNUSED,
   6008      1.1     skrll  struct bfd_link_info *info ATTRIBUTE_UNUSED,
   6009      1.1     skrll  struct elf_link_hash_entry *h ATTRIBUTE_UNUSED,
   6010      1.1     skrll  Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
   6011      1.1     skrll {
   6012      1.1     skrll   return TRUE;
   6013      1.1     skrll }
   6014      1.1     skrll 
   6015      1.1     skrll /* Decide whether to attempt to turn absptr or lsda encodings in
   6016      1.1     skrll    shared libraries into pcrel within the given input section.  */
   6017      1.1     skrll 
   6018      1.1     skrll static bfd_boolean
   6019      1.1     skrll frvfdpic_elf_use_relative_eh_frame
   6020      1.1     skrll (bfd *input_bfd ATTRIBUTE_UNUSED,
   6021      1.1     skrll  struct bfd_link_info *info ATTRIBUTE_UNUSED,
   6022      1.1     skrll  asection *eh_frame_section ATTRIBUTE_UNUSED)
   6023      1.1     skrll {
   6024      1.1     skrll   /* We can't use PC-relative encodings in FDPIC binaries, in general.  */
   6025      1.1     skrll   return FALSE;
   6026      1.1     skrll }
   6027      1.1     skrll 
   6028      1.1     skrll /* Adjust the contents of an eh_frame_hdr section before they're output.  */
   6029      1.1     skrll 
   6030      1.1     skrll static bfd_byte
   6031      1.1     skrll frvfdpic_elf_encode_eh_address (bfd *abfd,
   6032      1.1     skrll 				struct bfd_link_info *info,
   6033      1.1     skrll 				asection *osec, bfd_vma offset,
   6034      1.1     skrll 				asection *loc_sec, bfd_vma loc_offset,
   6035      1.1     skrll 				bfd_vma *encoded)
   6036      1.1     skrll {
   6037      1.1     skrll   struct elf_link_hash_entry *h;
   6038      1.1     skrll 
   6039      1.1     skrll   h = elf_hash_table (info)->hgot;
   6040      1.1     skrll   BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
   6041      1.1     skrll 
   6042      1.1     skrll   if (! h || (_frvfdpic_osec_to_segment (abfd, osec)
   6043      1.1     skrll 	      == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section)))
   6044      1.1     skrll     return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
   6045      1.1     skrll 				       loc_sec, loc_offset, encoded);
   6046      1.1     skrll 
   6047      1.1     skrll   BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec)
   6048      1.1     skrll 	      == (_frvfdpic_osec_to_segment
   6049      1.1     skrll 		  (abfd, h->root.u.def.section->output_section)));
   6050      1.1     skrll 
   6051      1.1     skrll   *encoded = osec->vma + offset
   6052      1.1     skrll     - (h->root.u.def.value
   6053      1.1     skrll        + h->root.u.def.section->output_section->vma
   6054      1.1     skrll        + h->root.u.def.section->output_offset);
   6055      1.1     skrll 
   6056      1.1     skrll   return DW_EH_PE_datarel | DW_EH_PE_sdata4;
   6057      1.1     skrll }
   6058      1.1     skrll 
   6059      1.1     skrll /* Look through the relocs for a section during the first phase.
   6060      1.1     skrll 
   6061      1.1     skrll    Besides handling virtual table relocs for gc, we have to deal with
   6062      1.1     skrll    all sorts of PIC-related relocations.  We describe below the
   6063      1.1     skrll    general plan on how to handle such relocations, even though we only
   6064      1.1     skrll    collect information at this point, storing them in hash tables for
   6065      1.1     skrll    perusal of later passes.
   6066      1.1     skrll 
   6067      1.1     skrll    32 relocations are propagated to the linker output when creating
   6068      1.1     skrll    position-independent output.  LO16 and HI16 relocations are not
   6069      1.1     skrll    supposed to be encountered in this case.
   6070      1.1     skrll 
   6071      1.1     skrll    LABEL16 should always be resolvable by the linker, since it's only
   6072      1.1     skrll    used by branches.
   6073      1.1     skrll 
   6074      1.1     skrll    LABEL24, on the other hand, is used by calls.  If it turns out that
   6075      1.1     skrll    the target of a call is a dynamic symbol, a PLT entry must be
   6076      1.1     skrll    created for it, which triggers the creation of a private function
   6077      1.1     skrll    descriptor and, unless lazy binding is disabled, a lazy PLT entry.
   6078      1.1     skrll 
   6079      1.1     skrll    GPREL relocations require the referenced symbol to be in the same
   6080      1.1     skrll    segment as _gp, but this can only be checked later.
   6081      1.1     skrll 
   6082      1.1     skrll    All GOT, GOTOFF and FUNCDESC relocations require a .got section to
   6083      1.1     skrll    exist.  LABEL24 might as well, since it may require a PLT entry,
   6084      1.1     skrll    that will require a got.
   6085      1.1     skrll 
   6086      1.1     skrll    Non-FUNCDESC GOT relocations require a GOT entry to be created
   6087      1.1     skrll    regardless of whether the symbol is dynamic.  However, since a
   6088      1.1     skrll    global symbol that turns out to not be exported may have the same
   6089      1.1     skrll    address of a non-dynamic symbol, we don't assign GOT entries at
   6090      1.1     skrll    this point, such that we can share them in this case.  A relocation
   6091      1.1     skrll    for the GOT entry always has to be created, be it to offset a
   6092      1.1     skrll    private symbol by the section load address, be it to get the symbol
   6093      1.1     skrll    resolved dynamically.
   6094      1.1     skrll 
   6095      1.1     skrll    FUNCDESC GOT relocations require a GOT entry to be created, and
   6096      1.1     skrll    handled as if a FUNCDESC relocation was applied to the GOT entry in
   6097      1.1     skrll    an object file.
   6098      1.1     skrll 
   6099      1.1     skrll    FUNCDESC relocations referencing a symbol that turns out to NOT be
   6100      1.1     skrll    dynamic cause a private function descriptor to be created.  The
   6101      1.1     skrll    FUNCDESC relocation then decays to a 32 relocation that points at
   6102      1.1     skrll    the private descriptor.  If the symbol is dynamic, the FUNCDESC
   6103      1.1     skrll    relocation is propagated to the linker output, such that the
   6104      1.1     skrll    dynamic linker creates the canonical descriptor, pointing to the
   6105      1.1     skrll    dynamically-resolved definition of the function.
   6106      1.1     skrll 
   6107      1.1     skrll    Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
   6108      1.1     skrll    symbols that are assigned to the same segment as the GOT, but we
   6109      1.1     skrll    can only check this later, after we know the complete set of
   6110      1.1     skrll    symbols defined and/or exported.
   6111      1.1     skrll 
   6112      1.1     skrll    FUNCDESC GOTOFF relocations require a function descriptor to be
   6113      1.1     skrll    created and, unless lazy binding is disabled or the symbol is not
   6114      1.1     skrll    dynamic, a lazy PLT entry.  Since we can't tell at this point
   6115      1.1     skrll    whether a symbol is going to be dynamic, we have to decide later
   6116      1.1     skrll    whether to create a lazy PLT entry or bind the descriptor directly
   6117      1.1     skrll    to the private function.
   6118      1.1     skrll 
   6119      1.1     skrll    FUNCDESC_VALUE relocations are not supposed to be present in object
   6120      1.1     skrll    files, but they may very well be simply propagated to the linker
   6121      1.1     skrll    output, since they have no side effect.
   6122      1.1     skrll 
   6123      1.1     skrll 
   6124      1.1     skrll    A function descriptor always requires a FUNCDESC_VALUE relocation.
   6125      1.1     skrll    Whether it's in .plt.rel or not depends on whether lazy binding is
   6126      1.1     skrll    enabled and on whether the referenced symbol is dynamic.
   6127      1.1     skrll 
   6128      1.1     skrll    The existence of a lazy PLT requires the resolverStub lazy PLT
   6129      1.1     skrll    entry to be present.
   6130      1.1     skrll 
   6131      1.1     skrll 
   6132      1.1     skrll    As for assignment of GOT, PLT and lazy PLT entries, and private
   6133      1.1     skrll    descriptors, we might do them all sequentially, but we can do
   6134      1.1     skrll    better than that.  For example, we can place GOT entries and
   6135      1.1     skrll    private function descriptors referenced using 12-bit operands
   6136      1.1     skrll    closer to the PIC register value, such that these relocations don't
   6137      1.1     skrll    overflow.  Those that are only referenced with LO16 relocations
   6138      1.1     skrll    could come next, but we may as well place PLT-required function
   6139      1.1     skrll    descriptors in the 12-bit range to make them shorter.  Symbols
   6140      1.1     skrll    referenced with LO16/HI16 may come next, but we may place
   6141      1.1     skrll    additional function descriptors in the 16-bit range if we can
   6142      1.1     skrll    reliably tell that we've already placed entries that are ever
   6143      1.1     skrll    referenced with only LO16.  PLT entries are therefore generated as
   6144      1.1     skrll    small as possible, while not introducing relocation overflows in
   6145      1.1     skrll    GOT or FUNCDESC_GOTOFF relocations.  Lazy PLT entries could be
   6146      1.1     skrll    generated before or after PLT entries, but not intermingled with
   6147      1.1     skrll    them, such that we can have more lazy PLT entries in range for a
   6148      1.1     skrll    branch to the resolverStub.  The resolverStub should be emitted at
   6149      1.1     skrll    the most distant location from the first lazy PLT entry such that
   6150      1.1     skrll    it's still in range for a branch, or closer, if there isn't a need
   6151      1.1     skrll    for so many lazy PLT entries.  Additional lazy PLT entries may be
   6152      1.1     skrll    emitted after the resolverStub, as long as branches are still in
   6153      1.1     skrll    range.  If the branch goes out of range, longer lazy PLT entries
   6154      1.1     skrll    are emitted.
   6155      1.1     skrll 
   6156      1.1     skrll    We could further optimize PLT and lazy PLT entries by giving them
   6157      1.1     skrll    priority in assignment to closer-to-gr17 locations depending on the
   6158      1.1     skrll    number of occurrences of references to them (assuming a function
   6159      1.1     skrll    that's called more often is more important for performance, so its
   6160      1.1     skrll    PLT entry should be faster), or taking hints from the compiler.
   6161      1.1     skrll    Given infinite time and money... :-)  */
   6162      1.1     skrll 
   6163      1.1     skrll static bfd_boolean
   6164      1.1     skrll elf32_frv_check_relocs (abfd, info, sec, relocs)
   6165      1.1     skrll      bfd *abfd;
   6166      1.1     skrll      struct bfd_link_info *info;
   6167      1.1     skrll      asection *sec;
   6168      1.1     skrll      const Elf_Internal_Rela *relocs;
   6169      1.1     skrll {
   6170      1.1     skrll   Elf_Internal_Shdr *symtab_hdr;
   6171      1.1     skrll   struct elf_link_hash_entry **sym_hashes;
   6172      1.1     skrll   const Elf_Internal_Rela *rel;
   6173      1.1     skrll   const Elf_Internal_Rela *rel_end;
   6174      1.1     skrll   bfd *dynobj;
   6175      1.1     skrll   struct frvfdpic_relocs_info *picrel;
   6176      1.1     skrll 
   6177      1.1     skrll   if (info->relocatable)
   6178      1.1     skrll     return TRUE;
   6179      1.1     skrll 
   6180      1.1     skrll   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   6181      1.1     skrll   sym_hashes = elf_sym_hashes (abfd);
   6182      1.1     skrll 
   6183      1.1     skrll   dynobj = elf_hash_table (info)->dynobj;
   6184      1.1     skrll   rel_end = relocs + sec->reloc_count;
   6185      1.1     skrll   for (rel = relocs; rel < rel_end; rel++)
   6186      1.1     skrll     {
   6187      1.1     skrll       struct elf_link_hash_entry *h;
   6188      1.1     skrll       unsigned long r_symndx;
   6189      1.1     skrll 
   6190      1.1     skrll       r_symndx = ELF32_R_SYM (rel->r_info);
   6191      1.1     skrll       if (r_symndx < symtab_hdr->sh_info)
   6192      1.1     skrll         h = NULL;
   6193      1.1     skrll       else
   6194      1.1     skrll 	{
   6195      1.1     skrll 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   6196      1.1     skrll 	  while (h->root.type == bfd_link_hash_indirect
   6197      1.1     skrll 		 || h->root.type == bfd_link_hash_warning)
   6198      1.1     skrll 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   6199      1.1     skrll 	}
   6200      1.1     skrll 
   6201      1.1     skrll       switch (ELF32_R_TYPE (rel->r_info))
   6202      1.1     skrll 	{
   6203      1.1     skrll 	case R_FRV_GETTLSOFF:
   6204      1.1     skrll 	case R_FRV_TLSDESC_VALUE:
   6205      1.1     skrll 	case R_FRV_GOTTLSDESC12:
   6206      1.1     skrll 	case R_FRV_GOTTLSDESCHI:
   6207      1.1     skrll 	case R_FRV_GOTTLSDESCLO:
   6208      1.1     skrll 	case R_FRV_GOTTLSOFF12:
   6209      1.1     skrll 	case R_FRV_GOTTLSOFFHI:
   6210      1.1     skrll 	case R_FRV_GOTTLSOFFLO:
   6211      1.1     skrll 	case R_FRV_TLSOFF:
   6212      1.1     skrll 	case R_FRV_GOT12:
   6213      1.1     skrll 	case R_FRV_GOTHI:
   6214      1.1     skrll 	case R_FRV_GOTLO:
   6215      1.1     skrll 	case R_FRV_FUNCDESC_GOT12:
   6216      1.1     skrll 	case R_FRV_FUNCDESC_GOTHI:
   6217      1.1     skrll 	case R_FRV_FUNCDESC_GOTLO:
   6218      1.1     skrll 	case R_FRV_GOTOFF12:
   6219      1.1     skrll 	case R_FRV_GOTOFFHI:
   6220      1.1     skrll 	case R_FRV_GOTOFFLO:
   6221      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFF12:
   6222      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFHI:
   6223      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFLO:
   6224      1.1     skrll 	case R_FRV_FUNCDESC:
   6225      1.1     skrll 	case R_FRV_FUNCDESC_VALUE:
   6226      1.1     skrll 	case R_FRV_TLSMOFF12:
   6227      1.1     skrll 	case R_FRV_TLSMOFFHI:
   6228      1.1     skrll 	case R_FRV_TLSMOFFLO:
   6229      1.1     skrll 	case R_FRV_TLSMOFF:
   6230      1.1     skrll 	  if (! IS_FDPIC (abfd))
   6231      1.1     skrll 	    goto bad_reloc;
   6232      1.1     skrll 	  /* Fall through.  */
   6233      1.1     skrll 	case R_FRV_GPREL12:
   6234      1.1     skrll 	case R_FRV_GPRELU12:
   6235      1.1     skrll 	case R_FRV_GPRELHI:
   6236      1.1     skrll 	case R_FRV_GPRELLO:
   6237      1.1     skrll 	case R_FRV_LABEL24:
   6238      1.1     skrll 	case R_FRV_32:
   6239      1.1     skrll 	  if (! dynobj)
   6240      1.1     skrll 	    {
   6241      1.1     skrll 	      elf_hash_table (info)->dynobj = dynobj = abfd;
   6242      1.1     skrll 	      if (! _frv_create_got_section (abfd, info))
   6243      1.1     skrll 		return FALSE;
   6244      1.1     skrll 	    }
   6245      1.1     skrll 	  if (! IS_FDPIC (abfd))
   6246      1.1     skrll 	    {
   6247      1.1     skrll 	      picrel = NULL;
   6248      1.1     skrll 	      break;
   6249      1.1     skrll 	    }
   6250      1.1     skrll 	  if (h != NULL)
   6251      1.1     skrll 	    {
   6252      1.1     skrll 	      if (h->dynindx == -1)
   6253      1.1     skrll 		switch (ELF_ST_VISIBILITY (h->other))
   6254      1.1     skrll 		  {
   6255      1.1     skrll 		  case STV_INTERNAL:
   6256      1.1     skrll 		  case STV_HIDDEN:
   6257      1.1     skrll 		    break;
   6258      1.1     skrll 		  default:
   6259      1.1     skrll 		    bfd_elf_link_record_dynamic_symbol (info, h);
   6260      1.1     skrll 		    break;
   6261      1.1     skrll 		  }
   6262      1.1     skrll 	      picrel
   6263      1.1     skrll 		= frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info),
   6264      1.1     skrll 						   abfd, h,
   6265      1.1     skrll 						   rel->r_addend, INSERT);
   6266      1.1     skrll 	    }
   6267      1.1     skrll 	  else
   6268      1.1     skrll 	    picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
   6269      1.1     skrll 						     (info), abfd, r_symndx,
   6270      1.1     skrll 						     rel->r_addend, INSERT);
   6271      1.1     skrll 	  if (! picrel)
   6272      1.1     skrll 	    return FALSE;
   6273      1.1     skrll 	  break;
   6274      1.1     skrll 
   6275      1.1     skrll 	default:
   6276      1.1     skrll 	  picrel = NULL;
   6277      1.1     skrll 	  break;
   6278      1.1     skrll 	}
   6279      1.1     skrll 
   6280      1.1     skrll       switch (ELF32_R_TYPE (rel->r_info))
   6281      1.1     skrll         {
   6282      1.1     skrll 	case R_FRV_LABEL24:
   6283      1.1     skrll 	  if (IS_FDPIC (abfd))
   6284      1.1     skrll 	    picrel->call = 1;
   6285      1.1     skrll 	  break;
   6286      1.1     skrll 
   6287      1.1     skrll 	case R_FRV_FUNCDESC_VALUE:
   6288      1.1     skrll 	  picrel->relocsfdv++;
   6289      1.1     skrll 	  if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
   6290      1.1     skrll 	    picrel->relocs32--;
   6291      1.1     skrll 	  /* Fall through.  */
   6292      1.1     skrll 
   6293      1.1     skrll 	case R_FRV_32:
   6294      1.1     skrll 	  if (! IS_FDPIC (abfd))
   6295      1.1     skrll 	    break;
   6296      1.1     skrll 
   6297      1.1     skrll 	  picrel->sym = 1;
   6298      1.1     skrll 	  if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
   6299      1.1     skrll 	    picrel->relocs32++;
   6300      1.1     skrll 	  break;
   6301      1.1     skrll 
   6302      1.1     skrll 	case R_FRV_GOT12:
   6303      1.1     skrll 	  picrel->got12 = 1;
   6304      1.1     skrll 	  break;
   6305      1.1     skrll 
   6306      1.1     skrll 	case R_FRV_GOTHI:
   6307      1.1     skrll 	case R_FRV_GOTLO:
   6308      1.1     skrll 	  picrel->gothilo = 1;
   6309      1.1     skrll 	  break;
   6310      1.1     skrll 
   6311      1.1     skrll 	case R_FRV_FUNCDESC_GOT12:
   6312      1.1     skrll 	  picrel->fdgot12 = 1;
   6313      1.1     skrll 	  break;
   6314      1.1     skrll 
   6315      1.1     skrll 	case R_FRV_FUNCDESC_GOTHI:
   6316      1.1     skrll 	case R_FRV_FUNCDESC_GOTLO:
   6317      1.1     skrll 	  picrel->fdgothilo = 1;
   6318      1.1     skrll 	  break;
   6319      1.1     skrll 
   6320      1.1     skrll 	case R_FRV_GOTOFF12:
   6321      1.1     skrll 	case R_FRV_GOTOFFHI:
   6322      1.1     skrll 	case R_FRV_GOTOFFLO:
   6323      1.1     skrll 	  picrel->gotoff = 1;
   6324      1.1     skrll 	  break;
   6325      1.1     skrll 
   6326      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFF12:
   6327      1.1     skrll 	  picrel->fdgoff12 = 1;
   6328      1.1     skrll 	  break;
   6329      1.1     skrll 
   6330      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFHI:
   6331      1.1     skrll 	case R_FRV_FUNCDESC_GOTOFFLO:
   6332      1.1     skrll 	  picrel->fdgoffhilo = 1;
   6333      1.1     skrll 	  break;
   6334      1.1     skrll 
   6335      1.1     skrll 	case R_FRV_FUNCDESC:
   6336      1.1     skrll 	  picrel->fd = 1;
   6337      1.1     skrll 	  picrel->relocsfd++;
   6338      1.1     skrll 	  break;
   6339      1.1     skrll 
   6340      1.1     skrll 	case R_FRV_GETTLSOFF:
   6341      1.1     skrll 	  picrel->tlsplt = 1;
   6342      1.1     skrll 	  break;
   6343      1.1     skrll 
   6344      1.1     skrll 	case R_FRV_TLSDESC_VALUE:
   6345      1.1     skrll 	  picrel->relocstlsd++;
   6346      1.1     skrll 	  goto bad_reloc;
   6347      1.1     skrll 
   6348      1.1     skrll 	case R_FRV_GOTTLSDESC12:
   6349      1.1     skrll 	  picrel->tlsdesc12 = 1;
   6350      1.1     skrll 	  break;
   6351      1.1     skrll 
   6352      1.1     skrll 	case R_FRV_GOTTLSDESCHI:
   6353      1.1     skrll 	case R_FRV_GOTTLSDESCLO:
   6354      1.1     skrll 	  picrel->tlsdeschilo = 1;
   6355      1.1     skrll 	  break;
   6356      1.1     skrll 
   6357      1.1     skrll 	case R_FRV_TLSMOFF12:
   6358      1.1     skrll 	case R_FRV_TLSMOFFHI:
   6359      1.1     skrll 	case R_FRV_TLSMOFFLO:
   6360      1.1     skrll 	case R_FRV_TLSMOFF:
   6361      1.1     skrll 	  break;
   6362      1.1     skrll 
   6363      1.1     skrll 	case R_FRV_GOTTLSOFF12:
   6364      1.1     skrll 	  picrel->tlsoff12 = 1;
   6365      1.1     skrll 	  info->flags |= DF_STATIC_TLS;
   6366      1.1     skrll 	  break;
   6367      1.1     skrll 
   6368      1.1     skrll 	case R_FRV_GOTTLSOFFHI:
   6369      1.1     skrll 	case R_FRV_GOTTLSOFFLO:
   6370      1.1     skrll 	  picrel->tlsoffhilo = 1;
   6371      1.1     skrll 	  info->flags |= DF_STATIC_TLS;
   6372      1.1     skrll 	  break;
   6373      1.1     skrll 
   6374      1.1     skrll 	case R_FRV_TLSOFF:
   6375      1.1     skrll 	  picrel->relocstlsoff++;
   6376      1.1     skrll 	  info->flags |= DF_STATIC_TLS;
   6377      1.1     skrll 	  goto bad_reloc;
   6378      1.1     skrll 
   6379      1.1     skrll         /* This relocation describes the C++ object vtable hierarchy.
   6380      1.1     skrll            Reconstruct it for later use during GC.  */
   6381      1.1     skrll         case R_FRV_GNU_VTINHERIT:
   6382      1.1     skrll           if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
   6383      1.1     skrll             return FALSE;
   6384      1.1     skrll           break;
   6385      1.1     skrll 
   6386      1.1     skrll         /* This relocation describes which C++ vtable entries are actually
   6387      1.1     skrll            used.  Record for later use during GC.  */
   6388      1.1     skrll         case R_FRV_GNU_VTENTRY:
   6389      1.1     skrll           BFD_ASSERT (h != NULL);
   6390      1.1     skrll           if (h != NULL
   6391      1.1     skrll               && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
   6392      1.1     skrll             return FALSE;
   6393      1.1     skrll           break;
   6394      1.1     skrll 
   6395      1.1     skrll 	case R_FRV_LABEL16:
   6396      1.1     skrll 	case R_FRV_LO16:
   6397      1.1     skrll 	case R_FRV_HI16:
   6398      1.1     skrll 	case R_FRV_GPREL12:
   6399      1.1     skrll 	case R_FRV_GPRELU12:
   6400      1.1     skrll 	case R_FRV_GPREL32:
   6401      1.1     skrll 	case R_FRV_GPRELHI:
   6402      1.1     skrll 	case R_FRV_GPRELLO:
   6403      1.1     skrll 	case R_FRV_TLSDESC_RELAX:
   6404      1.1     skrll 	case R_FRV_GETTLSOFF_RELAX:
   6405      1.1     skrll 	case R_FRV_TLSOFF_RELAX:
   6406      1.1     skrll 	  break;
   6407      1.1     skrll 
   6408      1.1     skrll 	default:
   6409      1.1     skrll 	bad_reloc:
   6410      1.1     skrll 	  (*_bfd_error_handler)
   6411      1.1     skrll 	    (_("%B: unsupported relocation type %i"),
   6412      1.1     skrll 	     abfd, ELF32_R_TYPE (rel->r_info));
   6413      1.1     skrll 	  return FALSE;
   6414      1.1     skrll         }
   6415      1.1     skrll     }
   6416      1.1     skrll 
   6417      1.1     skrll   return TRUE;
   6418      1.1     skrll }
   6419      1.1     skrll 
   6420      1.1     skrll 
   6421      1.1     skrll /* Return the machine subcode from the ELF e_flags header.  */
   6423      1.1     skrll 
   6424      1.1     skrll static int
   6425      1.1     skrll elf32_frv_machine (abfd)
   6426      1.1     skrll      bfd *abfd;
   6427      1.1     skrll {
   6428      1.1     skrll   switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK)
   6429      1.1     skrll     {
   6430      1.1     skrll     default:		    break;
   6431      1.1     skrll     case EF_FRV_CPU_FR550:  return bfd_mach_fr550;
   6432      1.1     skrll     case EF_FRV_CPU_FR500:  return bfd_mach_fr500;
   6433      1.1     skrll     case EF_FRV_CPU_FR450:  return bfd_mach_fr450;
   6434      1.1     skrll     case EF_FRV_CPU_FR405:  return bfd_mach_fr400;
   6435      1.1     skrll     case EF_FRV_CPU_FR400:  return bfd_mach_fr400;
   6436      1.1     skrll     case EF_FRV_CPU_FR300:  return bfd_mach_fr300;
   6437      1.1     skrll     case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple;
   6438      1.1     skrll     case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat;
   6439      1.1     skrll     }
   6440      1.1     skrll 
   6441      1.1     skrll   return bfd_mach_frv;
   6442      1.1     skrll }
   6443      1.1     skrll 
   6444      1.1     skrll /* Set the right machine number for a FRV ELF file.  */
   6445      1.1     skrll 
   6446      1.1     skrll static bfd_boolean
   6447      1.1     skrll elf32_frv_object_p (abfd)
   6448      1.1     skrll      bfd *abfd;
   6449      1.1     skrll {
   6450      1.1     skrll   bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd));
   6451      1.1     skrll   return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0)
   6452      1.1     skrll 	  == (IS_FDPIC (abfd)));
   6453      1.1     skrll }
   6454      1.1     skrll 
   6455      1.1     skrll /* Function to set the ELF flag bits.  */
   6457      1.1     skrll 
   6458      1.1     skrll static bfd_boolean
   6459      1.1     skrll frv_elf_set_private_flags (abfd, flags)
   6460      1.1     skrll      bfd *abfd;
   6461      1.1     skrll      flagword flags;
   6462      1.1     skrll {
   6463      1.1     skrll   elf_elfheader (abfd)->e_flags = flags;
   6464      1.1     skrll   elf_flags_init (abfd) = TRUE;
   6465      1.1     skrll   return TRUE;
   6466      1.1     skrll }
   6467      1.1     skrll 
   6468      1.1     skrll /* Copy backend specific data from one object module to another.  */
   6469      1.1     skrll 
   6470      1.1     skrll static bfd_boolean
   6471      1.1     skrll frv_elf_copy_private_bfd_data (ibfd, obfd)
   6472      1.1     skrll      bfd *ibfd;
   6473      1.1     skrll      bfd *obfd;
   6474      1.1     skrll {
   6475      1.1     skrll   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
   6476      1.1     skrll       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
   6477      1.1     skrll     return TRUE;
   6478      1.1     skrll 
   6479      1.1     skrll   BFD_ASSERT (!elf_flags_init (obfd)
   6480      1.1     skrll 	      || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
   6481      1.1     skrll 
   6482      1.1     skrll   elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
   6483      1.1     skrll   elf_flags_init (obfd) = TRUE;
   6484      1.1     skrll 
   6485      1.1     skrll   /* Copy object attributes.  */
   6486      1.1     skrll   _bfd_elf_copy_obj_attributes (ibfd, obfd);
   6487      1.1     skrll 
   6488      1.1     skrll   return TRUE;
   6489      1.1     skrll }
   6490      1.1     skrll 
   6491      1.1     skrll /* Return true if the architecture described by elf header flag
   6492      1.1     skrll    EXTENSION is an extension of the architecture described by BASE.  */
   6493      1.1     skrll 
   6494      1.1     skrll static bfd_boolean
   6495      1.1     skrll frv_elf_arch_extension_p (flagword base, flagword extension)
   6496      1.1     skrll {
   6497      1.1     skrll   if (base == extension)
   6498      1.1     skrll     return TRUE;
   6499      1.1     skrll 
   6500      1.1     skrll   /* CPU_GENERIC code can be merged with code for a specific
   6501      1.1     skrll      architecture, in which case the result is marked as being
   6502      1.1     skrll      for the specific architecture.  Everything is therefore
   6503      1.1     skrll      an extension of CPU_GENERIC.  */
   6504      1.1     skrll   if (base == EF_FRV_CPU_GENERIC)
   6505      1.1     skrll     return TRUE;
   6506      1.1     skrll 
   6507      1.1     skrll   if (extension == EF_FRV_CPU_FR450)
   6508      1.1     skrll     if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405)
   6509      1.1     skrll       return TRUE;
   6510      1.1     skrll 
   6511      1.1     skrll   if (extension == EF_FRV_CPU_FR405)
   6512      1.1     skrll     if (base == EF_FRV_CPU_FR400)
   6513      1.1     skrll       return TRUE;
   6514      1.1     skrll 
   6515      1.1     skrll   return FALSE;
   6516      1.1     skrll }
   6517      1.1     skrll 
   6518      1.1     skrll static bfd_boolean
   6519      1.1     skrll elf32_frvfdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
   6520      1.1     skrll {
   6521      1.1     skrll   unsigned i;
   6522      1.1     skrll 
   6523      1.1     skrll   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
   6524      1.1     skrll       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
   6525      1.1     skrll     return TRUE;
   6526      1.1     skrll 
   6527      1.1     skrll   if (! frv_elf_copy_private_bfd_data (ibfd, obfd))
   6528      1.1     skrll     return FALSE;
   6529      1.1     skrll 
   6530      1.1     skrll   if (! elf_tdata (ibfd) || ! elf_tdata (ibfd)->phdr
   6531      1.1     skrll       || ! elf_tdata (obfd) || ! elf_tdata (obfd)->phdr)
   6532      1.1     skrll     return TRUE;
   6533      1.1     skrll 
   6534      1.1     skrll   /* Copy the stack size.  */
   6535      1.1     skrll   for (i = 0; i < elf_elfheader (ibfd)->e_phnum; i++)
   6536      1.1     skrll     if (elf_tdata (ibfd)->phdr[i].p_type == PT_GNU_STACK)
   6537      1.1     skrll       {
   6538      1.1     skrll 	Elf_Internal_Phdr *iphdr = &elf_tdata (ibfd)->phdr[i];
   6539      1.1     skrll 
   6540      1.1     skrll 	for (i = 0; i < elf_elfheader (obfd)->e_phnum; i++)
   6541      1.1     skrll 	  if (elf_tdata (obfd)->phdr[i].p_type == PT_GNU_STACK)
   6542      1.1     skrll 	    {
   6543      1.1     skrll 	      memcpy (&elf_tdata (obfd)->phdr[i], iphdr, sizeof (*iphdr));
   6544      1.1     skrll 
   6545      1.1     skrll 	      /* Rewrite the phdrs, since we're only called after they
   6546      1.1     skrll 		 were first written.  */
   6547      1.1     skrll 	      if (bfd_seek (obfd, (bfd_signed_vma) get_elf_backend_data (obfd)
   6548      1.1     skrll 			    ->s->sizeof_ehdr, SEEK_SET) != 0
   6549      1.1     skrll 		  || get_elf_backend_data (obfd)->s
   6550      1.1     skrll 		  ->write_out_phdrs (obfd, elf_tdata (obfd)->phdr,
   6551      1.1     skrll 				     elf_elfheader (obfd)->e_phnum) != 0)
   6552      1.1     skrll 		return FALSE;
   6553      1.1     skrll 	      break;
   6554      1.1     skrll 	    }
   6555      1.1     skrll 
   6556      1.1     skrll 	break;
   6557      1.1     skrll       }
   6558      1.1     skrll 
   6559      1.1     skrll   return TRUE;
   6560      1.1     skrll }
   6561      1.1     skrll 
   6562      1.1     skrll /* Merge backend specific data from an object file to the output
   6563      1.1     skrll    object file when linking.  */
   6564      1.1     skrll 
   6565      1.1     skrll static bfd_boolean
   6566      1.1     skrll frv_elf_merge_private_bfd_data (ibfd, obfd)
   6567      1.1     skrll      bfd *ibfd;
   6568      1.1     skrll      bfd *obfd;
   6569      1.1     skrll {
   6570      1.1     skrll   flagword old_flags, old_partial;
   6571      1.1     skrll   flagword new_flags, new_partial;
   6572      1.1     skrll   bfd_boolean error = FALSE;
   6573      1.1     skrll   char new_opt[80];
   6574      1.1     skrll   char old_opt[80];
   6575      1.1     skrll 
   6576      1.1     skrll   new_opt[0] = old_opt[0] = '\0';
   6577      1.1     skrll   new_flags = elf_elfheader (ibfd)->e_flags;
   6578      1.1     skrll   old_flags = elf_elfheader (obfd)->e_flags;
   6579      1.1     skrll 
   6580      1.1     skrll   if (new_flags & EF_FRV_FDPIC)
   6581      1.1     skrll     new_flags &= ~EF_FRV_PIC;
   6582      1.1     skrll 
   6583      1.1     skrll #ifdef DEBUG
   6584      1.1     skrll   (*_bfd_error_handler) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s",
   6585      1.1     skrll 			 old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no",
   6586      1.1     skrll 			 bfd_get_filename (ibfd));
   6587      1.1     skrll #endif
   6588      1.1     skrll 
   6589      1.1     skrll   if (!elf_flags_init (obfd))			/* First call, no flags set.  */
   6590      1.1     skrll     {
   6591      1.1     skrll       elf_flags_init (obfd) = TRUE;
   6592      1.1     skrll       old_flags = new_flags;
   6593      1.1     skrll     }
   6594      1.1     skrll 
   6595      1.1     skrll   else if (new_flags == old_flags)		/* Compatible flags are ok.  */
   6596      1.1     skrll     ;
   6597      1.1     skrll 
   6598      1.1     skrll   else						/* Possibly incompatible flags.  */
   6599      1.1     skrll     {
   6600      1.1     skrll       /* Warn if different # of gprs are used.  Note, 0 means nothing is
   6601      1.1     skrll          said about the size of gprs.  */
   6602      1.1     skrll       new_partial = (new_flags & EF_FRV_GPR_MASK);
   6603      1.1     skrll       old_partial = (old_flags & EF_FRV_GPR_MASK);
   6604      1.1     skrll       if (new_partial == old_partial)
   6605      1.1     skrll 	;
   6606      1.1     skrll 
   6607      1.1     skrll       else if (new_partial == 0)
   6608      1.1     skrll 	;
   6609      1.1     skrll 
   6610      1.1     skrll       else if (old_partial == 0)
   6611      1.1     skrll 	old_flags |= new_partial;
   6612      1.1     skrll 
   6613      1.1     skrll       else
   6614      1.1     skrll 	{
   6615      1.1     skrll 	  switch (new_partial)
   6616      1.1     skrll 	    {
   6617      1.1     skrll 	    default:		strcat (new_opt, " -mgpr-??"); break;
   6618      1.1     skrll 	    case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break;
   6619      1.1     skrll 	    case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break;
   6620      1.1     skrll 	    }
   6621      1.1     skrll 
   6622      1.1     skrll 	  switch (old_partial)
   6623      1.1     skrll 	    {
   6624      1.1     skrll 	    default:		strcat (old_opt, " -mgpr-??"); break;
   6625      1.1     skrll 	    case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break;
   6626      1.1     skrll 	    case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break;
   6627      1.1     skrll 	    }
   6628      1.1     skrll 	}
   6629      1.1     skrll 
   6630      1.1     skrll       /* Warn if different # of fprs are used.  Note, 0 means nothing is
   6631      1.1     skrll          said about the size of fprs.  */
   6632      1.1     skrll       new_partial = (new_flags & EF_FRV_FPR_MASK);
   6633      1.1     skrll       old_partial = (old_flags & EF_FRV_FPR_MASK);
   6634      1.1     skrll       if (new_partial == old_partial)
   6635      1.1     skrll 	;
   6636      1.1     skrll 
   6637      1.1     skrll       else if (new_partial == 0)
   6638      1.1     skrll 	;
   6639      1.1     skrll 
   6640      1.1     skrll       else if (old_partial == 0)
   6641      1.1     skrll 	old_flags |= new_partial;
   6642      1.1     skrll 
   6643      1.1     skrll       else
   6644      1.1     skrll 	{
   6645      1.1     skrll 	  switch (new_partial)
   6646      1.1     skrll 	    {
   6647      1.1     skrll 	    default:		  strcat (new_opt, " -mfpr-?");      break;
   6648      1.1     skrll 	    case EF_FRV_FPR_32:   strcat (new_opt, " -mfpr-32");     break;
   6649      1.1     skrll 	    case EF_FRV_FPR_64:   strcat (new_opt, " -mfpr-64");     break;
   6650      1.1     skrll 	    case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break;
   6651      1.1     skrll 	    }
   6652      1.1     skrll 
   6653      1.1     skrll 	  switch (old_partial)
   6654      1.1     skrll 	    {
   6655      1.1     skrll 	    default:		  strcat (old_opt, " -mfpr-?");      break;
   6656      1.1     skrll 	    case EF_FRV_FPR_32:   strcat (old_opt, " -mfpr-32");     break;
   6657      1.1     skrll 	    case EF_FRV_FPR_64:   strcat (old_opt, " -mfpr-64");     break;
   6658      1.1     skrll 	    case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break;
   6659      1.1     skrll 	    }
   6660      1.1     skrll 	}
   6661      1.1     skrll 
   6662      1.1     skrll       /* Warn if different dword support was used.  Note, 0 means nothing is
   6663      1.1     skrll          said about the dword support.  */
   6664      1.1     skrll       new_partial = (new_flags & EF_FRV_DWORD_MASK);
   6665      1.1     skrll       old_partial = (old_flags & EF_FRV_DWORD_MASK);
   6666      1.1     skrll       if (new_partial == old_partial)
   6667      1.1     skrll 	;
   6668      1.1     skrll 
   6669      1.1     skrll       else if (new_partial == 0)
   6670      1.1     skrll 	;
   6671      1.1     skrll 
   6672      1.1     skrll       else if (old_partial == 0)
   6673      1.1     skrll 	old_flags |= new_partial;
   6674      1.1     skrll 
   6675      1.1     skrll       else
   6676      1.1     skrll 	{
   6677      1.1     skrll 	  switch (new_partial)
   6678      1.1     skrll 	    {
   6679      1.1     skrll 	    default:		   strcat (new_opt, " -mdword-?");  break;
   6680      1.1     skrll 	    case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword");    break;
   6681      1.1     skrll 	    case EF_FRV_DWORD_NO:  strcat (new_opt, " -mno-dword"); break;
   6682      1.1     skrll 	    }
   6683      1.1     skrll 
   6684      1.1     skrll 	  switch (old_partial)
   6685      1.1     skrll 	    {
   6686      1.1     skrll 	    default:		   strcat (old_opt, " -mdword-?");  break;
   6687      1.1     skrll 	    case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword");    break;
   6688      1.1     skrll 	    case EF_FRV_DWORD_NO:  strcat (old_opt, " -mno-dword"); break;
   6689      1.1     skrll 	    }
   6690      1.1     skrll 	}
   6691      1.1     skrll 
   6692      1.1     skrll       /* Or in flags that accumulate (ie, if one module uses it, mark that the
   6693      1.1     skrll 	 feature is used.  */
   6694      1.1     skrll       old_flags |= new_flags & (EF_FRV_DOUBLE
   6695      1.1     skrll 				| EF_FRV_MEDIA
   6696      1.1     skrll 				| EF_FRV_MULADD
   6697      1.1     skrll 				| EF_FRV_NON_PIC_RELOCS);
   6698      1.1     skrll 
   6699      1.1     skrll       /* If any module was compiled without -G0, clear the G0 bit.  */
   6700      1.1     skrll       old_flags = ((old_flags & ~ EF_FRV_G0)
   6701      1.1     skrll 		   | (old_flags & new_flags & EF_FRV_G0));
   6702      1.1     skrll 
   6703      1.1     skrll       /* If any module was compiled without -mnopack, clear the mnopack bit.  */
   6704      1.1     skrll       old_flags = ((old_flags & ~ EF_FRV_NOPACK)
   6705      1.1     skrll 		   | (old_flags & new_flags & EF_FRV_NOPACK));
   6706      1.1     skrll 
   6707      1.1     skrll       /* We don't have to do anything if the pic flags are the same, or the new
   6708      1.1     skrll          module(s) were compiled with -mlibrary-pic.  */
   6709      1.1     skrll       new_partial = (new_flags & EF_FRV_PIC_FLAGS);
   6710      1.1     skrll       old_partial = (old_flags & EF_FRV_PIC_FLAGS);
   6711      1.1     skrll       if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0))
   6712      1.1     skrll 	;
   6713      1.1     skrll 
   6714      1.1     skrll       /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
   6715      1.1     skrll          flags if any from the new module.  */
   6716      1.1     skrll       else if ((old_partial & EF_FRV_LIBPIC) != 0)
   6717      1.1     skrll 	old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial;
   6718      1.1     skrll 
   6719      1.1     skrll       /* If we have mixtures of -fpic and -fPIC, or in both bits.  */
   6720      1.1     skrll       else if (new_partial != 0 && old_partial != 0)
   6721      1.1     skrll 	old_flags |= new_partial;
   6722      1.1     skrll 
   6723      1.1     skrll       /* One module was compiled for pic and the other was not, see if we have
   6724      1.1     skrll          had any relocations that are not pic-safe.  */
   6725      1.1     skrll       else
   6726      1.1     skrll 	{
   6727      1.1     skrll 	  if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0)
   6728      1.1     skrll 	    old_flags |= new_partial;
   6729      1.1     skrll 	  else
   6730      1.1     skrll 	    {
   6731      1.1     skrll 	      old_flags &= ~ EF_FRV_PIC_FLAGS;
   6732      1.1     skrll #ifndef FRV_NO_PIC_ERROR
   6733      1.1     skrll 	      error = TRUE;
   6734      1.1     skrll 	      (*_bfd_error_handler)
   6735      1.1     skrll 		(_("%s: compiled with %s and linked with modules that use non-pic relocations"),
   6736      1.1     skrll 		 bfd_get_filename (ibfd),
   6737      1.1     skrll 		 (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic");
   6738      1.1     skrll #endif
   6739      1.1     skrll 	    }
   6740      1.1     skrll 	}
   6741      1.1     skrll 
   6742      1.1     skrll       /* Warn if different cpu is used (allow a specific cpu to override
   6743      1.1     skrll 	 the generic cpu).  */
   6744      1.1     skrll       new_partial = (new_flags & EF_FRV_CPU_MASK);
   6745      1.1     skrll       old_partial = (old_flags & EF_FRV_CPU_MASK);
   6746      1.1     skrll       if (frv_elf_arch_extension_p (new_partial, old_partial))
   6747      1.1     skrll 	;
   6748      1.1     skrll 
   6749      1.1     skrll       else if (frv_elf_arch_extension_p (old_partial, new_partial))
   6750      1.1     skrll 	old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial;
   6751      1.1     skrll 
   6752      1.1     skrll       else
   6753      1.1     skrll 	{
   6754      1.1     skrll 	  switch (new_partial)
   6755      1.1     skrll 	    {
   6756      1.1     skrll 	    default:		     strcat (new_opt, " -mcpu=?");      break;
   6757      1.1     skrll 	    case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv");    break;
   6758      1.1     skrll 	    case EF_FRV_CPU_SIMPLE:  strcat (new_opt, " -mcpu=simple"); break;
   6759      1.1     skrll 	    case EF_FRV_CPU_FR550:   strcat (new_opt, " -mcpu=fr550");  break;
   6760      1.1     skrll 	    case EF_FRV_CPU_FR500:   strcat (new_opt, " -mcpu=fr500");  break;
   6761      1.1     skrll 	    case EF_FRV_CPU_FR450:   strcat (new_opt, " -mcpu=fr450");  break;
   6762      1.1     skrll 	    case EF_FRV_CPU_FR405:   strcat (new_opt, " -mcpu=fr405");  break;
   6763      1.1     skrll 	    case EF_FRV_CPU_FR400:   strcat (new_opt, " -mcpu=fr400");  break;
   6764      1.1     skrll 	    case EF_FRV_CPU_FR300:   strcat (new_opt, " -mcpu=fr300");  break;
   6765      1.1     skrll 	    case EF_FRV_CPU_TOMCAT:  strcat (new_opt, " -mcpu=tomcat"); break;
   6766      1.1     skrll 	    }
   6767      1.1     skrll 
   6768      1.1     skrll 	  switch (old_partial)
   6769      1.1     skrll 	    {
   6770      1.1     skrll 	    default:		     strcat (old_opt, " -mcpu=?");      break;
   6771      1.1     skrll 	    case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv");    break;
   6772      1.1     skrll 	    case EF_FRV_CPU_SIMPLE:  strcat (old_opt, " -mcpu=simple"); break;
   6773      1.1     skrll 	    case EF_FRV_CPU_FR550:   strcat (old_opt, " -mcpu=fr550");  break;
   6774      1.1     skrll 	    case EF_FRV_CPU_FR500:   strcat (old_opt, " -mcpu=fr500");  break;
   6775      1.1     skrll 	    case EF_FRV_CPU_FR450:   strcat (old_opt, " -mcpu=fr450");  break;
   6776      1.1     skrll 	    case EF_FRV_CPU_FR405:   strcat (old_opt, " -mcpu=fr405");  break;
   6777      1.1     skrll 	    case EF_FRV_CPU_FR400:   strcat (old_opt, " -mcpu=fr400");  break;
   6778      1.1     skrll 	    case EF_FRV_CPU_FR300:   strcat (old_opt, " -mcpu=fr300");  break;
   6779      1.1     skrll 	    case EF_FRV_CPU_TOMCAT:  strcat (old_opt, " -mcpu=tomcat"); break;
   6780      1.1     skrll 	    }
   6781      1.1     skrll 	}
   6782      1.1     skrll 
   6783      1.1     skrll       /* Print out any mismatches from above.  */
   6784      1.1     skrll       if (new_opt[0])
   6785      1.1     skrll 	{
   6786      1.1     skrll 	  error = TRUE;
   6787      1.1     skrll 	  (*_bfd_error_handler)
   6788      1.1     skrll 	    (_("%s: compiled with %s and linked with modules compiled with %s"),
   6789      1.1     skrll 	     bfd_get_filename (ibfd), new_opt, old_opt);
   6790      1.1     skrll 	}
   6791      1.1     skrll 
   6792      1.1     skrll       /* Warn about any other mismatches */
   6793      1.1     skrll       new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS);
   6794      1.1     skrll       old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS);
   6795      1.1     skrll       if (new_partial != old_partial)
   6796      1.1     skrll 	{
   6797      1.1     skrll 	  old_flags |= new_partial;
   6798      1.1     skrll 	  error = TRUE;
   6799      1.1     skrll 	  (*_bfd_error_handler)
   6800      1.1     skrll 	    (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"),
   6801      1.1     skrll 	     bfd_get_filename (ibfd), (long)new_partial, (long)old_partial);
   6802      1.1     skrll 	}
   6803      1.1     skrll     }
   6804      1.1     skrll 
   6805      1.1     skrll   /* If the cpu is -mcpu=simple, then set the -mnopack bit.  */
   6806      1.1     skrll   if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE)
   6807      1.1     skrll     old_flags |= EF_FRV_NOPACK;
   6808      1.1     skrll 
   6809      1.1     skrll   /* Update the old flags now with changes made above.  */
   6810      1.1     skrll   old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK;
   6811      1.1     skrll   elf_elfheader (obfd)->e_flags = old_flags;
   6812      1.1     skrll   if (old_partial != (old_flags & EF_FRV_CPU_MASK))
   6813      1.1     skrll     bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd));
   6814      1.1     skrll 
   6815      1.1     skrll   if (((new_flags & EF_FRV_FDPIC) == 0)
   6816      1.1     skrll       != (! IS_FDPIC (ibfd)))
   6817      1.1     skrll     {
   6818      1.1     skrll       error = TRUE;
   6819      1.1     skrll       if (IS_FDPIC (obfd))
   6820      1.1     skrll 	(*_bfd_error_handler)
   6821      1.1     skrll 	  (_("%s: cannot link non-fdpic object file into fdpic executable"),
   6822      1.1     skrll 	   bfd_get_filename (ibfd));
   6823      1.1     skrll       else
   6824      1.1     skrll 	(*_bfd_error_handler)
   6825      1.1     skrll 	  (_("%s: cannot link fdpic object file into non-fdpic executable"),
   6826      1.1     skrll 	   bfd_get_filename (ibfd));
   6827      1.1     skrll     }
   6828      1.1     skrll 
   6829      1.1     skrll   if (error)
   6830      1.1     skrll     bfd_set_error (bfd_error_bad_value);
   6831      1.1     skrll 
   6832      1.1     skrll   return !error;
   6833      1.1     skrll }
   6834      1.1     skrll 
   6835      1.1     skrll 
   6836      1.1     skrll bfd_boolean
   6838      1.1     skrll frv_elf_print_private_bfd_data (abfd, ptr)
   6839      1.1     skrll      bfd *abfd;
   6840      1.1     skrll      PTR ptr;
   6841      1.1     skrll {
   6842      1.1     skrll   FILE *file = (FILE *) ptr;
   6843      1.1     skrll   flagword flags;
   6844      1.1     skrll 
   6845      1.1     skrll   BFD_ASSERT (abfd != NULL && ptr != NULL);
   6846      1.1     skrll 
   6847      1.1     skrll   /* Print normal ELF private data.  */
   6848      1.1     skrll   _bfd_elf_print_private_bfd_data (abfd, ptr);
   6849      1.1     skrll 
   6850      1.1     skrll   flags = elf_elfheader (abfd)->e_flags;
   6851      1.1     skrll   fprintf (file, _("private flags = 0x%lx:"), (unsigned long) flags);
   6852      1.1     skrll 
   6853      1.1     skrll   switch (flags & EF_FRV_CPU_MASK)
   6854      1.1     skrll     {
   6855      1.1     skrll     default:							break;
   6856      1.1     skrll     case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple");	break;
   6857      1.1     skrll     case EF_FRV_CPU_FR550:  fprintf (file, " -mcpu=fr550");	break;
   6858      1.1     skrll     case EF_FRV_CPU_FR500:  fprintf (file, " -mcpu=fr500");	break;
   6859      1.1     skrll     case EF_FRV_CPU_FR450:  fprintf (file, " -mcpu=fr450");	break;
   6860      1.1     skrll     case EF_FRV_CPU_FR405:  fprintf (file, " -mcpu=fr405");	break;
   6861      1.1     skrll     case EF_FRV_CPU_FR400:  fprintf (file, " -mcpu=fr400");	break;
   6862      1.1     skrll     case EF_FRV_CPU_FR300:  fprintf (file, " -mcpu=fr300");	break;
   6863      1.1     skrll     case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat");	break;
   6864      1.1     skrll     }
   6865      1.1     skrll 
   6866      1.1     skrll   switch (flags & EF_FRV_GPR_MASK)
   6867      1.1     skrll     {
   6868      1.1     skrll     default:							break;
   6869      1.1     skrll     case EF_FRV_GPR_32: fprintf (file, " -mgpr-32");		break;
   6870      1.1     skrll     case EF_FRV_GPR_64: fprintf (file, " -mgpr-64");		break;
   6871      1.1     skrll     }
   6872      1.1     skrll 
   6873      1.1     skrll   switch (flags & EF_FRV_FPR_MASK)
   6874      1.1     skrll     {
   6875      1.1     skrll     default:							break;
   6876      1.1     skrll     case EF_FRV_FPR_32:   fprintf (file, " -mfpr-32");		break;
   6877      1.1     skrll     case EF_FRV_FPR_64:   fprintf (file, " -mfpr-64");		break;
   6878      1.1     skrll     case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float");	break;
   6879      1.1     skrll     }
   6880      1.1     skrll 
   6881      1.1     skrll   switch (flags & EF_FRV_DWORD_MASK)
   6882      1.1     skrll     {
   6883      1.1     skrll     default:							break;
   6884      1.1     skrll     case EF_FRV_DWORD_YES: fprintf (file, " -mdword");		break;
   6885      1.1     skrll     case EF_FRV_DWORD_NO:  fprintf (file, " -mno-dword");	break;
   6886      1.1     skrll     }
   6887      1.1     skrll 
   6888      1.1     skrll   if (flags & EF_FRV_DOUBLE)
   6889      1.1     skrll     fprintf (file, " -mdouble");
   6890      1.1     skrll 
   6891      1.1     skrll   if (flags & EF_FRV_MEDIA)
   6892      1.1     skrll     fprintf (file, " -mmedia");
   6893      1.1     skrll 
   6894      1.1     skrll   if (flags & EF_FRV_MULADD)
   6895      1.1     skrll     fprintf (file, " -mmuladd");
   6896      1.1     skrll 
   6897      1.1     skrll   if (flags & EF_FRV_PIC)
   6898      1.1     skrll     fprintf (file, " -fpic");
   6899      1.1     skrll 
   6900      1.1     skrll   if (flags & EF_FRV_BIGPIC)
   6901      1.1     skrll     fprintf (file, " -fPIC");
   6902      1.1     skrll 
   6903      1.1     skrll   if (flags & EF_FRV_LIBPIC)
   6904      1.1     skrll     fprintf (file, " -mlibrary-pic");
   6905      1.1     skrll 
   6906      1.1     skrll   if (flags & EF_FRV_FDPIC)
   6907      1.1     skrll     fprintf (file, " -mfdpic");
   6908      1.1     skrll 
   6909      1.1     skrll   if (flags & EF_FRV_NON_PIC_RELOCS)
   6910      1.1     skrll     fprintf (file, " non-pic relocations");
   6911      1.1     skrll 
   6912      1.1     skrll   if (flags & EF_FRV_G0)
   6913      1.1     skrll     fprintf (file, " -G0");
   6914      1.1     skrll 
   6915      1.1     skrll   fputc ('\n', file);
   6916      1.1     skrll   return TRUE;
   6917      1.1     skrll }
   6918      1.1     skrll 
   6919      1.1     skrll 
   6920      1.1     skrll /* Support for core dump NOTE sections.  */
   6922      1.1     skrll 
   6923      1.1     skrll static bfd_boolean
   6924      1.1     skrll elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
   6925      1.1     skrll {
   6926      1.1     skrll   int offset;
   6927      1.1     skrll   unsigned int raw_size;
   6928      1.1     skrll 
   6929      1.1     skrll   switch (note->descsz)
   6930      1.1     skrll     {
   6931      1.1     skrll       default:
   6932      1.1     skrll 	return FALSE;
   6933      1.1     skrll 
   6934  1.1.1.2  christos       /* The Linux/FRV elf_prstatus struct is 268 bytes long.  The other
   6935      1.1     skrll          hardcoded offsets and sizes listed below (and contained within
   6936      1.1     skrll 	 this lexical block) refer to fields in the target's elf_prstatus
   6937      1.1     skrll 	 struct.  */
   6938      1.1     skrll       case 268:
   6939      1.1     skrll 	/* `pr_cursig' is at offset 12.  */
   6940      1.1     skrll 	elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
   6941      1.1     skrll 
   6942      1.1     skrll 	/* `pr_pid' is at offset 24.  */
   6943      1.1     skrll 	elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24);
   6944      1.1     skrll 
   6945      1.1     skrll 	/* `pr_reg' is at offset 72.  */
   6946      1.1     skrll 	offset = 72;
   6947      1.1     skrll 
   6948      1.1     skrll 	/* Most grok_prstatus implementations set `raw_size' to the size
   6949      1.1     skrll 	   of the pr_reg field.  For Linux/FRV, we set `raw_size' to be
   6950      1.1     skrll 	   the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
   6951      1.1     skrll 	   and `pr_interp_fdpic_loadmap', both of which (by design)
   6952      1.1     skrll 	   immediately follow `pr_reg'.  This will allow these fields to
   6953      1.1     skrll 	   be viewed by GDB as registers.
   6954      1.1     skrll 
   6955      1.1     skrll 	   `pr_reg' is 184 bytes long.  `pr_exec_fdpic_loadmap' and
   6956      1.1     skrll 	   `pr_interp_fdpic_loadmap' are 4 bytes each.  */
   6957      1.1     skrll 	raw_size = 184 + 4 + 4;
   6958      1.1     skrll 
   6959      1.1     skrll 	break;
   6960      1.1     skrll     }
   6961      1.1     skrll 
   6962      1.1     skrll   /* Make a ".reg/999" section.  */
   6963      1.1     skrll   return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size,
   6964      1.1     skrll 					  note->descpos + offset);
   6965      1.1     skrll }
   6966      1.1     skrll 
   6967      1.1     skrll static bfd_boolean
   6968      1.1     skrll elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
   6969      1.1     skrll {
   6970      1.1     skrll   switch (note->descsz)
   6971      1.1     skrll     {
   6972      1.1     skrll       default:
   6973      1.1     skrll 	return FALSE;
   6974      1.1     skrll 
   6975      1.1     skrll       /* The Linux/FRV elf_prpsinfo struct is 124 bytes long.  */
   6976      1.1     skrll       case 124:
   6977      1.1     skrll 
   6978      1.1     skrll 	/* `pr_fname' is found at offset 28 and is 16 bytes long.  */
   6979      1.1     skrll 	elf_tdata (abfd)->core_program
   6980      1.1     skrll 	  = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
   6981      1.1     skrll 
   6982      1.1     skrll 	/* `pr_psargs' is found at offset 44 and is 80 bytes long.  */
   6983      1.1     skrll 	elf_tdata (abfd)->core_command
   6984      1.1     skrll 	  = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
   6985      1.1     skrll     }
   6986      1.1     skrll 
   6987      1.1     skrll   /* Note that for some reason, a spurious space is tacked
   6988      1.1     skrll      onto the end of the args in some (at least one anyway)
   6989      1.1     skrll      implementations, so strip it off if it exists.  */
   6990      1.1     skrll 
   6991      1.1     skrll   {
   6992      1.1     skrll     char *command = elf_tdata (abfd)->core_command;
   6993  1.1.1.2  christos     int n = strlen (command);
   6994      1.1     skrll 
   6995      1.1     skrll     if (0 < n && command[n - 1] == ' ')
   6996      1.1     skrll       command[n - 1] = '\0';
   6997      1.1     skrll   }
   6998      1.1     skrll 
   6999      1.1     skrll   return TRUE;
   7000      1.1     skrll }
   7001      1.1     skrll #define ELF_ARCH		bfd_arch_frv
   7002      1.1     skrll #define ELF_TARGET_ID		FRV_ELF_DATA
   7003      1.1     skrll #define ELF_MACHINE_CODE	EM_CYGNUS_FRV
   7004      1.1     skrll #define ELF_MAXPAGESIZE		0x1000
   7005      1.1     skrll 
   7006      1.1     skrll #define TARGET_BIG_SYM          bfd_elf32_frv_vec
   7007      1.1     skrll #define TARGET_BIG_NAME		"elf32-frv"
   7008      1.1     skrll 
   7009      1.1     skrll #define elf_info_to_howto			frv_info_to_howto_rela
   7010      1.1     skrll #define elf_backend_relocate_section		elf32_frv_relocate_section
   7011      1.1     skrll #define elf_backend_gc_mark_hook		elf32_frv_gc_mark_hook
   7012      1.1     skrll #define elf_backend_check_relocs                elf32_frv_check_relocs
   7013      1.1     skrll #define elf_backend_object_p			elf32_frv_object_p
   7014      1.1     skrll #define elf_backend_add_symbol_hook             elf32_frv_add_symbol_hook
   7015      1.1     skrll 
   7016      1.1     skrll #define elf_backend_can_gc_sections		1
   7017      1.1     skrll #define elf_backend_rela_normal			1
   7018      1.1     skrll 
   7019      1.1     skrll #define bfd_elf32_bfd_reloc_type_lookup		frv_reloc_type_lookup
   7020      1.1     skrll #define bfd_elf32_bfd_reloc_name_lookup	frv_reloc_name_lookup
   7021      1.1     skrll #define bfd_elf32_bfd_set_private_flags		frv_elf_set_private_flags
   7022      1.1     skrll #define bfd_elf32_bfd_copy_private_bfd_data	frv_elf_copy_private_bfd_data
   7023      1.1     skrll #define bfd_elf32_bfd_merge_private_bfd_data	frv_elf_merge_private_bfd_data
   7024      1.1     skrll #define bfd_elf32_bfd_print_private_bfd_data	frv_elf_print_private_bfd_data
   7025      1.1     skrll 
   7026      1.1     skrll #define elf_backend_want_got_sym	1
   7027      1.1     skrll #define elf_backend_got_header_size	0
   7028      1.1     skrll #define elf_backend_want_got_plt	0
   7029      1.1     skrll #define elf_backend_plt_readonly	1
   7030      1.1     skrll #define elf_backend_want_plt_sym	0
   7031      1.1     skrll #define elf_backend_plt_header_size	0
   7032      1.1     skrll 
   7033      1.1     skrll #define elf_backend_finish_dynamic_sections \
   7034      1.1     skrll 		elf32_frv_finish_dynamic_sections
   7035      1.1     skrll 
   7036      1.1     skrll #define elf_backend_grok_prstatus	elf32_frv_grok_prstatus
   7037      1.1     skrll #define elf_backend_grok_psinfo		elf32_frv_grok_psinfo
   7038      1.1     skrll 
   7039      1.1     skrll #include "elf32-target.h"
   7040      1.1     skrll 
   7041      1.1     skrll #undef ELF_MAXPAGESIZE
   7042      1.1     skrll #define ELF_MAXPAGESIZE		0x4000
   7043      1.1     skrll 
   7044      1.1     skrll #undef TARGET_BIG_SYM
   7045      1.1     skrll #define TARGET_BIG_SYM          bfd_elf32_frvfdpic_vec
   7046      1.1     skrll #undef TARGET_BIG_NAME
   7047      1.1     skrll #define TARGET_BIG_NAME		"elf32-frvfdpic"
   7048      1.1     skrll #undef	elf32_bed
   7049      1.1     skrll #define	elf32_bed		elf32_frvfdpic_bed
   7050      1.1     skrll 
   7051      1.1     skrll #undef elf_info_to_howto_rel
   7052      1.1     skrll #define elf_info_to_howto_rel	frvfdpic_info_to_howto_rel
   7053      1.1     skrll 
   7054      1.1     skrll #undef bfd_elf32_bfd_link_hash_table_create
   7055      1.1     skrll #define bfd_elf32_bfd_link_hash_table_create \
   7056      1.1     skrll 		frvfdpic_elf_link_hash_table_create
   7057      1.1     skrll #undef elf_backend_always_size_sections
   7058      1.1     skrll #define elf_backend_always_size_sections \
   7059      1.1     skrll 		elf32_frvfdpic_always_size_sections
   7060      1.1     skrll #undef elf_backend_modify_program_headers
   7061      1.1     skrll #define elf_backend_modify_program_headers \
   7062      1.1     skrll 		elf32_frvfdpic_modify_program_headers
   7063      1.1     skrll #undef bfd_elf32_bfd_copy_private_bfd_data
   7064      1.1     skrll #define bfd_elf32_bfd_copy_private_bfd_data \
   7065      1.1     skrll 		elf32_frvfdpic_copy_private_bfd_data
   7066      1.1     skrll 
   7067      1.1     skrll #undef elf_backend_create_dynamic_sections
   7068      1.1     skrll #define elf_backend_create_dynamic_sections \
   7069      1.1     skrll 		elf32_frvfdpic_create_dynamic_sections
   7070      1.1     skrll #undef elf_backend_adjust_dynamic_symbol
   7071      1.1     skrll #define elf_backend_adjust_dynamic_symbol \
   7072      1.1     skrll 		elf32_frvfdpic_adjust_dynamic_symbol
   7073      1.1     skrll #undef elf_backend_size_dynamic_sections
   7074      1.1     skrll #define elf_backend_size_dynamic_sections \
   7075      1.1     skrll 		elf32_frvfdpic_size_dynamic_sections
   7076      1.1     skrll #undef bfd_elf32_bfd_relax_section
   7077      1.1     skrll #define bfd_elf32_bfd_relax_section \
   7078      1.1     skrll   elf32_frvfdpic_relax_section
   7079      1.1     skrll #undef elf_backend_finish_dynamic_symbol
   7080      1.1     skrll #define elf_backend_finish_dynamic_symbol \
   7081      1.1     skrll 		elf32_frvfdpic_finish_dynamic_symbol
   7082      1.1     skrll #undef elf_backend_finish_dynamic_sections
   7083      1.1     skrll #define elf_backend_finish_dynamic_sections \
   7084      1.1     skrll 		elf32_frvfdpic_finish_dynamic_sections
   7085      1.1     skrll 
   7086      1.1     skrll #undef elf_backend_discard_info
   7087      1.1     skrll #define elf_backend_discard_info \
   7088      1.1     skrll 		frvfdpic_elf_discard_info
   7089      1.1     skrll #undef elf_backend_can_make_relative_eh_frame
   7090      1.1     skrll #define elf_backend_can_make_relative_eh_frame \
   7091      1.1     skrll 		frvfdpic_elf_use_relative_eh_frame
   7092      1.1     skrll #undef elf_backend_can_make_lsda_relative_eh_frame
   7093      1.1     skrll #define elf_backend_can_make_lsda_relative_eh_frame \
   7094      1.1     skrll 		frvfdpic_elf_use_relative_eh_frame
   7095      1.1     skrll #undef elf_backend_encode_eh_address
   7096      1.1     skrll #define elf_backend_encode_eh_address \
   7097      1.1     skrll 		frvfdpic_elf_encode_eh_address
   7098      1.1     skrll 
   7099      1.1     skrll #undef elf_backend_may_use_rel_p
   7100      1.1     skrll #define elf_backend_may_use_rel_p       1
   7101      1.1     skrll #undef elf_backend_may_use_rela_p
   7102                    #define elf_backend_may_use_rela_p      1
   7103                    /* We use REL for dynamic relocations only.  */
   7104                    #undef elf_backend_default_use_rela_p
   7105                    #define elf_backend_default_use_rela_p  1
   7106                    
   7107                    #undef elf_backend_omit_section_dynsym
   7108                    #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
   7109                    
   7110                    #include "elf32-target.h"
   7111