Home | History | Annotate | Line # | Download | only in bfd
      1       1.1  christos /* 32-bit ELF support for TI C6X
      2  1.1.1.11  christos    Copyright (C) 2010-2026 Free Software Foundation, Inc.
      3       1.1  christos    Contributed by Joseph Myers <joseph (at) codesourcery.com>
      4   1.1.1.5  christos 		  Bernd Schmidt  <bernds (at) codesourcery.com>
      5       1.1  christos 
      6       1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      7       1.1  christos 
      8       1.1  christos    This program is free software; you can redistribute it and/or modify
      9       1.1  christos    it under the terms of the GNU General Public License as published by
     10       1.1  christos    the Free Software Foundation; either version 3 of the License, or
     11       1.1  christos    (at your option) any later version.
     12       1.1  christos 
     13       1.1  christos    This program is distributed in the hope that it will be useful,
     14       1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15       1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16       1.1  christos    GNU General Public License for more details.
     17       1.1  christos 
     18       1.1  christos    You should have received a copy of the GNU General Public License
     19       1.1  christos    along with this program; if not, write to the Free Software
     20       1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     21       1.1  christos    MA 02110-1301, USA.  */
     22       1.1  christos 
     23       1.1  christos #include "sysdep.h"
     24   1.1.1.2  christos #include <limits.h>
     25       1.1  christos #include "bfd.h"
     26       1.1  christos #include "libbfd.h"
     27       1.1  christos #include "libiberty.h"
     28       1.1  christos #include "elf-bfd.h"
     29       1.1  christos #include "elf/tic6x.h"
     30       1.1  christos #include "elf32-tic6x.h"
     31       1.1  christos 
     32   1.1.1.2  christos #define ELF_DYNAMIC_INTERPRETER "/lib/ld-uClibc.so.0"
     33   1.1.1.2  christos 
     34   1.1.1.2  christos /* DSBT binaries have a default 128K stack.  */
     35   1.1.1.2  christos #define DEFAULT_STACK_SIZE 0x20000
     36   1.1.1.2  christos 
     37   1.1.1.2  christos /* The size in bytes of an entry in the procedure linkage table.  */
     38   1.1.1.2  christos #define PLT_ENTRY_SIZE 24
     39   1.1.1.2  christos 
     40   1.1.1.2  christos /* TI C6X ELF linker hash table.  */
     41   1.1.1.2  christos 
     42   1.1.1.2  christos struct elf32_tic6x_link_hash_table
     43   1.1.1.2  christos {
     44   1.1.1.2  christos   struct elf_link_hash_table elf;
     45   1.1.1.2  christos 
     46   1.1.1.2  christos   /* C6X specific command line arguments.  */
     47   1.1.1.2  christos   struct elf32_tic6x_params params;
     48   1.1.1.2  christos 
     49   1.1.1.2  christos   /* The output BFD, for convenience.  */
     50   1.1.1.2  christos   bfd *obfd;
     51   1.1.1.2  christos 
     52   1.1.1.2  christos   /* The .dsbt section.  */
     53   1.1.1.2  christos   asection *dsbt;
     54   1.1.1.2  christos };
     55   1.1.1.2  christos 
     56   1.1.1.2  christos /* Get the TI C6X ELF linker hash table from a link_info structure.  */
     57   1.1.1.2  christos 
     58   1.1.1.2  christos #define elf32_tic6x_hash_table(p) \
     59   1.1.1.2  christos   ((struct elf32_tic6x_link_hash_table *) ((p)->hash))
     60   1.1.1.2  christos 
     61   1.1.1.2  christos typedef enum
     62   1.1.1.2  christos {
     63   1.1.1.2  christos   DELETE_EXIDX_ENTRY,
     64   1.1.1.2  christos   INSERT_EXIDX_CANTUNWIND_AT_END
     65   1.1.1.2  christos }
     66   1.1.1.2  christos tic6x_unwind_edit_type;
     67   1.1.1.2  christos 
     68   1.1.1.2  christos /* A (sorted) list of edits to apply to an unwind table.  */
     69   1.1.1.2  christos typedef struct tic6x_unwind_table_edit
     70   1.1.1.2  christos {
     71   1.1.1.2  christos   tic6x_unwind_edit_type type;
     72   1.1.1.2  christos   /* Note: we sometimes want to insert an unwind entry corresponding to a
     73   1.1.1.2  christos      section different from the one we're currently writing out, so record the
     74   1.1.1.2  christos      (text) section this edit relates to here.  */
     75   1.1.1.2  christos   asection *linked_section;
     76   1.1.1.2  christos   unsigned int index;
     77   1.1.1.2  christos   struct tic6x_unwind_table_edit *next;
     78   1.1.1.2  christos }
     79   1.1.1.2  christos tic6x_unwind_table_edit;
     80   1.1.1.2  christos 
     81   1.1.1.2  christos typedef struct _tic6x_elf_section_data
     82   1.1.1.2  christos {
     83   1.1.1.2  christos   /* Information about mapping symbols.  */
     84   1.1.1.2  christos   struct bfd_elf_section_data elf;
     85   1.1.1.2  christos   /* Information about unwind tables.  */
     86   1.1.1.2  christos   union
     87   1.1.1.2  christos   {
     88   1.1.1.2  christos     /* Unwind info attached to a text section.  */
     89   1.1.1.2  christos     struct
     90   1.1.1.2  christos     {
     91   1.1.1.2  christos       asection *tic6x_exidx_sec;
     92   1.1.1.2  christos     } text;
     93   1.1.1.2  christos 
     94   1.1.1.2  christos     /* Unwind info attached to an .c6xabi.exidx section.  */
     95   1.1.1.2  christos     struct
     96   1.1.1.2  christos     {
     97   1.1.1.2  christos       tic6x_unwind_table_edit *unwind_edit_list;
     98   1.1.1.2  christos       tic6x_unwind_table_edit *unwind_edit_tail;
     99   1.1.1.2  christos     } exidx;
    100   1.1.1.2  christos   } u;
    101   1.1.1.2  christos }
    102   1.1.1.2  christos _tic6x_elf_section_data;
    103   1.1.1.2  christos 
    104   1.1.1.2  christos #define elf32_tic6x_section_data(sec) \
    105   1.1.1.2  christos   ((_tic6x_elf_section_data *) elf_section_data (sec))
    106   1.1.1.2  christos 
    107       1.1  christos struct elf32_tic6x_obj_tdata
    108       1.1  christos {
    109       1.1  christos   struct elf_obj_tdata root;
    110       1.1  christos 
    111       1.1  christos   /* Whether to use RELA relocations when generating relocations.
    112       1.1  christos      This is a per-object flag to allow the assembler to generate REL
    113       1.1  christos      relocations for use in linker testcases.  */
    114   1.1.1.8  christos   bool use_rela_p;
    115       1.1  christos };
    116       1.1  christos 
    117       1.1  christos #define elf32_tic6x_tdata(abfd) \
    118       1.1  christos   ((struct elf32_tic6x_obj_tdata *) (abfd)->tdata.any)
    119       1.1  christos 
    120   1.1.1.2  christos #define is_tic6x_elf(bfd) \
    121   1.1.1.2  christos   (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
    122   1.1.1.2  christos    && elf_tdata (bfd) != NULL \
    123   1.1.1.2  christos    && elf_object_id (bfd) == TIC6X_ELF_DATA)
    124   1.1.1.2  christos 
    125   1.1.1.2  christos /* C6X ELF uses two common sections.  One is the usual one, and the
    126   1.1.1.2  christos    other is for small objects.  All the small objects are kept
    127   1.1.1.2  christos    together, and then referenced via the gp pointer, which yields
    128   1.1.1.2  christos    faster assembler code.  This is what we use for the small common
    129   1.1.1.2  christos    section.  This approach is copied from ecoff.c.  */
    130   1.1.1.2  christos static asection tic6x_elf_scom_section;
    131   1.1.1.8  christos static const asymbol tic6x_elf_scom_symbol =
    132   1.1.1.8  christos   GLOBAL_SYM_INIT (".scommon", &tic6x_elf_scom_section);
    133   1.1.1.8  christos static asection tic6x_elf_scom_section =
    134   1.1.1.8  christos   BFD_FAKE_SECTION (tic6x_elf_scom_section, &tic6x_elf_scom_symbol,
    135   1.1.1.8  christos 		    ".scommon", 0, SEC_IS_COMMON | SEC_SMALL_DATA);
    136   1.1.1.2  christos 
    137       1.1  christos static reloc_howto_type elf32_tic6x_howto_table[] =
    138       1.1  christos {
    139       1.1  christos   HOWTO (R_C6000_NONE,		/* type */
    140       1.1  christos 	 0,			/* rightshift */
    141   1.1.1.8  christos 	 0,			/* size */
    142       1.1  christos 	 0,			/* bitsize */
    143   1.1.1.8  christos 	 false,			/* pc_relative */
    144       1.1  christos 	 0,			/* bitpos */
    145       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    146       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    147       1.1  christos 	 "R_C6000_NONE",	/* name */
    148   1.1.1.8  christos 	 false,			/* partial_inplace */
    149       1.1  christos 	 0,			/* src_mask */
    150       1.1  christos 	 0,			/* dst_mask */
    151   1.1.1.8  christos 	 false),		/* pcrel_offset */
    152       1.1  christos   HOWTO (R_C6000_ABS32,		/* type */
    153       1.1  christos 	 0,			/* rightshift */
    154   1.1.1.8  christos 	 4,			/* size */
    155       1.1  christos 	 32,			/* bitsize */
    156   1.1.1.8  christos 	 false,			/* pc_relative */
    157       1.1  christos 	 0,			/* bitpos */
    158       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    159       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    160       1.1  christos 	 "R_C6000_ABS32",	/* name */
    161   1.1.1.8  christos 	 false,			/* partial_inplace */
    162       1.1  christos 	 0,			/* src_mask */
    163       1.1  christos 	 0xffffffff,		/* dst_mask */
    164   1.1.1.8  christos 	 false),		/* pcrel_offset */
    165       1.1  christos   HOWTO (R_C6000_ABS16,		/* type */
    166       1.1  christos 	 0,			/* rightshift */
    167   1.1.1.8  christos 	 2,			/* size */
    168       1.1  christos 	 16,			/* bitsize */
    169   1.1.1.8  christos 	 false,			/* pc_relative */
    170       1.1  christos 	 0,			/* bitpos */
    171       1.1  christos 	 complain_overflow_bitfield,/* complain_on_overflow */
    172       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    173       1.1  christos 	 "R_C6000_ABS16",	/* name */
    174   1.1.1.8  christos 	 false,			/* partial_inplace */
    175       1.1  christos 	 0,			/* src_mask */
    176       1.1  christos 	 0x0000ffff,		/* dst_mask */
    177   1.1.1.8  christos 	 false),		/* pcrel_offset */
    178       1.1  christos   HOWTO (R_C6000_ABS8,		/* type */
    179       1.1  christos 	 0,			/* rightshift */
    180   1.1.1.8  christos 	 1,			/* size */
    181       1.1  christos 	 8,			/* bitsize */
    182   1.1.1.8  christos 	 false,			/* pc_relative */
    183       1.1  christos 	 0,			/* bitpos */
    184       1.1  christos 	 complain_overflow_bitfield,/* complain_on_overflow */
    185       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    186       1.1  christos 	 "R_C6000_ABS8",	/* name */
    187   1.1.1.8  christos 	 false,			/* partial_inplace */
    188       1.1  christos 	 0,			/* src_mask */
    189       1.1  christos 	 0x000000ff,		/* dst_mask */
    190   1.1.1.8  christos 	 false),		/* pcrel_offset */
    191       1.1  christos   HOWTO (R_C6000_PCR_S21,	/* type */
    192       1.1  christos 	 2,			/* rightshift */
    193   1.1.1.8  christos 	 4,			/* size */
    194       1.1  christos 	 21,			/* bitsize */
    195   1.1.1.8  christos 	 true,			/* pc_relative */
    196       1.1  christos 	 7,			/* bitpos */
    197       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    198       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    199       1.1  christos 	 "R_C6000_PCR_S21",	/* name */
    200   1.1.1.8  christos 	 false,			/* partial_inplace */
    201       1.1  christos 	 0,			/* src_mask */
    202       1.1  christos 	 0x0fffff80,		/* dst_mask */
    203   1.1.1.8  christos 	 true),			/* pcrel_offset */
    204       1.1  christos   HOWTO (R_C6000_PCR_S12,	/* type */
    205       1.1  christos 	 2,			/* rightshift */
    206   1.1.1.8  christos 	 4,			/* size */
    207       1.1  christos 	 12,			/* bitsize */
    208   1.1.1.8  christos 	 true,			/* pc_relative */
    209       1.1  christos 	 16,			/* bitpos */
    210       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    211       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    212       1.1  christos 	 "R_C6000_PCR_S12",	/* name */
    213   1.1.1.8  christos 	 false,			/* partial_inplace */
    214       1.1  christos 	 0,			/* src_mask */
    215       1.1  christos 	 0x0fff0000,		/* dst_mask */
    216   1.1.1.8  christos 	 true),			/* pcrel_offset */
    217       1.1  christos   HOWTO (R_C6000_PCR_S10,	/* type */
    218       1.1  christos 	 2,			/* rightshift */
    219   1.1.1.8  christos 	 4,			/* size */
    220       1.1  christos 	 10,			/* bitsize */
    221   1.1.1.8  christos 	 true,			/* pc_relative */
    222       1.1  christos 	 13,			/* bitpos */
    223       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    224       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    225       1.1  christos 	 "R_C6000_PCR_S10",	/* name */
    226   1.1.1.8  christos 	 false,			/* partial_inplace */
    227       1.1  christos 	 0,			/* src_mask */
    228       1.1  christos 	 0x007fe000,		/* dst_mask */
    229   1.1.1.8  christos 	 true),			/* pcrel_offset */
    230       1.1  christos   HOWTO (R_C6000_PCR_S7,	/* type */
    231       1.1  christos 	 2,			/* rightshift */
    232   1.1.1.8  christos 	 4,			/* size */
    233       1.1  christos 	 7,			/* bitsize */
    234   1.1.1.8  christos 	 true,			/* pc_relative */
    235       1.1  christos 	 16,			/* bitpos */
    236       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    237       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    238       1.1  christos 	 "R_C6000_PCR_S7",	/* name */
    239   1.1.1.8  christos 	 false,			/* partial_inplace */
    240       1.1  christos 	 0,			/* src_mask */
    241       1.1  christos 	 0x007f0000,		/* dst_mask */
    242   1.1.1.8  christos 	 true),			/* pcrel_offset */
    243       1.1  christos   HOWTO (R_C6000_ABS_S16,	/* type */
    244       1.1  christos 	 0,			/* rightshift */
    245   1.1.1.8  christos 	 4,			/* size */
    246       1.1  christos 	 16,			/* bitsize */
    247   1.1.1.8  christos 	 false,			/* pc_relative */
    248       1.1  christos 	 7,			/* bitpos */
    249       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    250       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    251       1.1  christos 	 "R_C6000_ABS_S16",	/* name */
    252   1.1.1.8  christos 	 false,			/* partial_inplace */
    253       1.1  christos 	 0,			/* src_mask */
    254       1.1  christos 	 0x007fff80,		/* dst_mask */
    255   1.1.1.8  christos 	 false),		/* pcrel_offset */
    256       1.1  christos   HOWTO (R_C6000_ABS_L16,	/* type */
    257       1.1  christos 	 0,			/* rightshift */
    258   1.1.1.8  christos 	 4,			/* size */
    259       1.1  christos 	 16,			/* bitsize */
    260   1.1.1.8  christos 	 false,			/* pc_relative */
    261       1.1  christos 	 7,			/* bitpos */
    262       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    263       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    264       1.1  christos 	 "R_C6000_ABS_L16",	/* name */
    265   1.1.1.8  christos 	 false,			/* partial_inplace */
    266       1.1  christos 	 0,			/* src_mask */
    267       1.1  christos 	 0x007fff80,		/* dst_mask */
    268   1.1.1.8  christos 	 false),		/* pcrel_offset */
    269       1.1  christos   HOWTO (R_C6000_ABS_H16,	/* type */
    270       1.1  christos 	 16,			/* rightshift */
    271   1.1.1.8  christos 	 4,			/* size */
    272       1.1  christos 	 16,			/* bitsize */
    273   1.1.1.8  christos 	 false,			/* pc_relative */
    274       1.1  christos 	 7,			/* bitpos */
    275       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    276       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    277       1.1  christos 	 "R_C6000_ABS_H16",	/* name */
    278   1.1.1.8  christos 	 false,			/* partial_inplace */
    279       1.1  christos 	 0,			/* src_mask */
    280       1.1  christos 	 0x007fff80,		/* dst_mask */
    281   1.1.1.8  christos 	 false),		/* pcrel_offset */
    282       1.1  christos   HOWTO (R_C6000_SBR_U15_B,	/* type */
    283       1.1  christos 	 0,			/* rightshift */
    284   1.1.1.8  christos 	 4,			/* size */
    285       1.1  christos 	 15,			/* bitsize */
    286   1.1.1.8  christos 	 false,			/* pc_relative */
    287       1.1  christos 	 8,			/* bitpos */
    288       1.1  christos 	 complain_overflow_unsigned,/* complain_on_overflow */
    289       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    290       1.1  christos 	 "R_C6000_SBR_U15_B",	/* name */
    291   1.1.1.8  christos 	 false,			/* partial_inplace */
    292       1.1  christos 	 0,			/* src_mask */
    293       1.1  christos 	 0x007fff00,		/* dst_mask */
    294   1.1.1.8  christos 	 false),		/* pcrel_offset */
    295       1.1  christos   HOWTO (R_C6000_SBR_U15_H,	/* type */
    296       1.1  christos 	 1,			/* rightshift */
    297   1.1.1.8  christos 	 4,			/* size */
    298       1.1  christos 	 15,			/* bitsize */
    299   1.1.1.8  christos 	 false,			/* pc_relative */
    300       1.1  christos 	 8,			/* bitpos */
    301       1.1  christos 	 complain_overflow_unsigned,/* complain_on_overflow */
    302       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    303       1.1  christos 	 "R_C6000_SBR_U15_H",	/* name */
    304   1.1.1.8  christos 	 false,			/* partial_inplace */
    305       1.1  christos 	 0,			/* src_mask */
    306       1.1  christos 	 0x007fff00,		/* dst_mask */
    307   1.1.1.8  christos 	 false),		/* pcrel_offset */
    308       1.1  christos   HOWTO (R_C6000_SBR_U15_W,	/* type */
    309       1.1  christos 	 2,			/* rightshift */
    310   1.1.1.8  christos 	 4,			/* size */
    311       1.1  christos 	 15,			/* bitsize */
    312   1.1.1.8  christos 	 false,			/* pc_relative */
    313       1.1  christos 	 8,			/* bitpos */
    314       1.1  christos 	 complain_overflow_unsigned,/* complain_on_overflow */
    315       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    316       1.1  christos 	 "R_C6000_SBR_U15_W",	/* name */
    317   1.1.1.8  christos 	 false,			/* partial_inplace */
    318       1.1  christos 	 0,			/* src_mask */
    319       1.1  christos 	 0x007fff00,		/* dst_mask */
    320   1.1.1.8  christos 	 false),		/* pcrel_offset */
    321       1.1  christos   HOWTO (R_C6000_SBR_S16,	/* type */
    322       1.1  christos 	 0,			/* rightshift */
    323   1.1.1.8  christos 	 4,			/* size */
    324       1.1  christos 	 16,			/* bitsize */
    325   1.1.1.8  christos 	 false,			/* pc_relative */
    326       1.1  christos 	 7,			/* bitpos */
    327       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    328       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    329       1.1  christos 	 "R_C6000_SBR_S16",	/* name */
    330   1.1.1.8  christos 	 false,			/* partial_inplace */
    331       1.1  christos 	 0,			/* src_mask */
    332       1.1  christos 	 0x007fff80,		/* dst_mask */
    333   1.1.1.8  christos 	 false),		/* pcrel_offset */
    334       1.1  christos   HOWTO (R_C6000_SBR_L16_B,	/* type */
    335       1.1  christos 	 0,			/* rightshift */
    336   1.1.1.8  christos 	 4,			/* size */
    337       1.1  christos 	 16,			/* bitsize */
    338   1.1.1.8  christos 	 false,			/* pc_relative */
    339       1.1  christos 	 7,			/* bitpos */
    340       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    341       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    342       1.1  christos 	 "R_C6000_SBR_L16_B",	/* name */
    343   1.1.1.8  christos 	 false,			/* partial_inplace */
    344       1.1  christos 	 0,			/* src_mask */
    345       1.1  christos 	 0x007fff80,		/* dst_mask */
    346   1.1.1.8  christos 	 false),		/* pcrel_offset */
    347       1.1  christos   HOWTO (R_C6000_SBR_L16_H,	/* type */
    348       1.1  christos 	 1,			/* rightshift */
    349   1.1.1.8  christos 	 4,			/* size */
    350       1.1  christos 	 16,			/* bitsize */
    351   1.1.1.8  christos 	 false,			/* pc_relative */
    352       1.1  christos 	 7,			/* bitpos */
    353       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    354       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    355       1.1  christos 	 "R_C6000_SBR_L16_H",	/* name */
    356   1.1.1.8  christos 	 false,			/* partial_inplace */
    357       1.1  christos 	 0,			/* src_mask */
    358       1.1  christos 	 0x007fff80,		/* dst_mask */
    359   1.1.1.8  christos 	 false),		/* pcrel_offset */
    360       1.1  christos   HOWTO (R_C6000_SBR_L16_W,	/* type */
    361       1.1  christos 	 2,			/* rightshift */
    362   1.1.1.8  christos 	 4,			/* size */
    363       1.1  christos 	 16,			/* bitsize */
    364   1.1.1.8  christos 	 false,			/* pc_relative */
    365       1.1  christos 	 7,			/* bitpos */
    366       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    367       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    368       1.1  christos 	 "R_C6000_SBR_L16_W",	/* name */
    369   1.1.1.8  christos 	 false,			/* partial_inplace */
    370       1.1  christos 	 0,			/* src_mask */
    371       1.1  christos 	 0x007fff80,		/* dst_mask */
    372   1.1.1.8  christos 	 false),		/* pcrel_offset */
    373       1.1  christos   HOWTO (R_C6000_SBR_H16_B,	/* type */
    374       1.1  christos 	 16,			/* rightshift */
    375   1.1.1.8  christos 	 4,			/* size */
    376       1.1  christos 	 16,			/* bitsize */
    377   1.1.1.8  christos 	 false,			/* pc_relative */
    378       1.1  christos 	 7,			/* bitpos */
    379       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    380       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    381       1.1  christos 	 "R_C6000_SBR_H16_B",	/* name */
    382   1.1.1.8  christos 	 false,			/* partial_inplace */
    383       1.1  christos 	 0,			/* src_mask */
    384       1.1  christos 	 0x007fff80,		/* dst_mask */
    385   1.1.1.8  christos 	 false),		/* pcrel_offset */
    386       1.1  christos   HOWTO (R_C6000_SBR_H16_H,	/* type */
    387       1.1  christos 	 17,			/* rightshift */
    388   1.1.1.8  christos 	 4,			/* size */
    389       1.1  christos 	 16,			/* bitsize */
    390   1.1.1.8  christos 	 false,			/* pc_relative */
    391       1.1  christos 	 7,			/* bitpos */
    392       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    393       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    394       1.1  christos 	 "R_C6000_SBR_H16_H",	/* name */
    395   1.1.1.8  christos 	 false,			/* partial_inplace */
    396       1.1  christos 	 0,			/* src_mask */
    397       1.1  christos 	 0x007fff80,		/* dst_mask */
    398   1.1.1.8  christos 	 false),		/* pcrel_offset */
    399       1.1  christos   HOWTO (R_C6000_SBR_H16_W,	/* type */
    400       1.1  christos 	 18,			/* rightshift */
    401   1.1.1.8  christos 	 4,			/* size */
    402       1.1  christos 	 16,			/* bitsize */
    403   1.1.1.8  christos 	 false,			/* pc_relative */
    404       1.1  christos 	 7,			/* bitpos */
    405       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    406       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    407       1.1  christos 	 "R_C6000_SBR_H16_W",	/* name */
    408   1.1.1.8  christos 	 false,			/* partial_inplace */
    409       1.1  christos 	 0,			/* src_mask */
    410       1.1  christos 	 0x007fff80,		/* dst_mask */
    411   1.1.1.8  christos 	 false),		/* pcrel_offset */
    412       1.1  christos   HOWTO (R_C6000_SBR_GOT_U15_W,	/* type */
    413       1.1  christos 	 2,			/* rightshift */
    414   1.1.1.8  christos 	 4,			/* size */
    415       1.1  christos 	 15,			/* bitsize */
    416   1.1.1.8  christos 	 false,			/* pc_relative */
    417       1.1  christos 	 8,			/* bitpos */
    418       1.1  christos 	 complain_overflow_unsigned,/* complain_on_overflow */
    419       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    420       1.1  christos 	 "R_C6000_SBR_GOT_U15_W",/* name */
    421   1.1.1.8  christos 	 false,			/* partial_inplace */
    422       1.1  christos 	 0,			/* src_mask */
    423       1.1  christos 	 0x007fff00,		/* dst_mask */
    424   1.1.1.8  christos 	 false),		/* pcrel_offset */
    425       1.1  christos   HOWTO (R_C6000_SBR_GOT_L16_W,	/* type */
    426       1.1  christos 	 2,			/* rightshift */
    427   1.1.1.8  christos 	 4,			/* size */
    428       1.1  christos 	 16,			/* bitsize */
    429   1.1.1.8  christos 	 false,			/* pc_relative */
    430       1.1  christos 	 7,			/* bitpos */
    431       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    432       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    433       1.1  christos 	 "R_C6000_SBR_GOT_L16_W",/* name */
    434   1.1.1.8  christos 	 false,			/* partial_inplace */
    435       1.1  christos 	 0,			/* src_mask */
    436       1.1  christos 	 0x007fff80,		/* dst_mask */
    437   1.1.1.8  christos 	 false),		/* pcrel_offset */
    438       1.1  christos   HOWTO (R_C6000_SBR_GOT_H16_W,	/* type */
    439       1.1  christos 	 18,			/* rightshift */
    440   1.1.1.8  christos 	 4,			/* size */
    441       1.1  christos 	 16,			/* bitsize */
    442   1.1.1.8  christos 	 false,			/* pc_relative */
    443       1.1  christos 	 7,			/* bitpos */
    444       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    445       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    446       1.1  christos 	 "R_C6000_SBR_GOT_H16_W",/* name */
    447   1.1.1.8  christos 	 false,			/* partial_inplace */
    448       1.1  christos 	 0,			/* src_mask */
    449       1.1  christos 	 0x007fff80,		/* dst_mask */
    450   1.1.1.8  christos 	 false),		/* pcrel_offset */
    451       1.1  christos   HOWTO (R_C6000_DSBT_INDEX,	/* type */
    452       1.1  christos 	 0,			/* rightshift */
    453   1.1.1.8  christos 	 4,			/* size */
    454       1.1  christos 	 15,			/* bitsize */
    455   1.1.1.8  christos 	 false,			/* pc_relative */
    456       1.1  christos 	 8,			/* bitpos */
    457       1.1  christos 	 complain_overflow_unsigned,/* complain_on_overflow */
    458       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    459       1.1  christos 	 "R_C6000_DSBT_INDEX",	/* name */
    460   1.1.1.8  christos 	 false,			/* partial_inplace */
    461       1.1  christos 	 0,			/* src_mask */
    462       1.1  christos 	 0x007fff00,		/* dst_mask */
    463   1.1.1.8  christos 	 false),		/* pcrel_offset */
    464       1.1  christos   HOWTO (R_C6000_PREL31,	/* type */
    465       1.1  christos 	 1,			/* rightshift */
    466   1.1.1.8  christos 	 4,			/* size */
    467       1.1  christos 	 31,			/* bitsize */
    468   1.1.1.8  christos 	 true,			/* pc_relative */
    469       1.1  christos 	 0,			/* bitpos */
    470       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    471       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    472       1.1  christos 	 "R_C6000_PREL31",	/* name */
    473   1.1.1.8  christos 	 false,			/* partial_inplace */
    474       1.1  christos 	 0,			/* src_mask */
    475       1.1  christos 	 0x7fffffff,		/* dst_mask */
    476   1.1.1.8  christos 	 true),			/* pcrel_offset */
    477       1.1  christos   HOWTO (R_C6000_COPY,		/* type */
    478       1.1  christos 	 0,			/* rightshift */
    479   1.1.1.8  christos 	 4,			/* size */
    480       1.1  christos 	 32,			/* bitsize */
    481   1.1.1.8  christos 	 false,			/* pc_relative */
    482       1.1  christos 	 0,			/* bitpos */
    483       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    484       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    485       1.1  christos 	 "R_C6000_COPY",	/* name */
    486   1.1.1.8  christos 	 false,			/* partial_inplace */
    487       1.1  christos 	 0,			/* src_mask */
    488       1.1  christos 	 0xffffffff,		/* dst_mask */
    489   1.1.1.8  christos 	 false),		/* pcrel_offset */
    490   1.1.1.2  christos   HOWTO (R_C6000_JUMP_SLOT,	/* type */
    491   1.1.1.2  christos 	 0,			/* rightshift */
    492   1.1.1.8  christos 	 4,			/* size */
    493   1.1.1.2  christos 	 32,			/* bitsize */
    494   1.1.1.8  christos 	 false,			/* pc_relative */
    495   1.1.1.2  christos 	 0,			/* bitpos */
    496   1.1.1.2  christos 	 complain_overflow_dont,/* complain_on_overflow */
    497   1.1.1.2  christos 	 bfd_elf_generic_reloc,	/* special_function */
    498   1.1.1.2  christos 	 "R_C6000_JUMP_SLOT",	/* name */
    499   1.1.1.8  christos 	 false,			/* partial_inplace */
    500   1.1.1.2  christos 	 0,			/* src_mask */
    501   1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
    502   1.1.1.8  christos 	 false),		/* pcrel_offset */
    503   1.1.1.2  christos   HOWTO (R_C6000_EHTYPE,	/* type */
    504   1.1.1.2  christos 	 0,			/* rightshift */
    505   1.1.1.8  christos 	 4,			/* size */
    506   1.1.1.2  christos 	 32,			/* bitsize */
    507   1.1.1.8  christos 	 false,			/* pc_relative */
    508   1.1.1.2  christos 	 0,			/* bitpos */
    509   1.1.1.2  christos 	 complain_overflow_dont,/* complain_on_overflow */
    510   1.1.1.2  christos 	 bfd_elf_generic_reloc,	/* special_function */
    511   1.1.1.2  christos 	 "R_C6000_EHTYPE",	/* name */
    512   1.1.1.8  christos 	 false,			/* partial_inplace */
    513   1.1.1.2  christos 	 0,			/* src_mask */
    514   1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
    515   1.1.1.8  christos 	 false),		/* pcrel_offset */
    516   1.1.1.2  christos   HOWTO (R_C6000_PCR_H16,	/* type */
    517   1.1.1.2  christos 	 16,			/* rightshift */
    518   1.1.1.8  christos 	 4,			/* size */
    519   1.1.1.2  christos 	 16,			/* bitsize */
    520   1.1.1.8  christos 	 true,			/* pc_relative */
    521   1.1.1.2  christos 	 7,			/* bitpos */
    522   1.1.1.2  christos 	 complain_overflow_dont,/* complain_on_overflow */
    523   1.1.1.2  christos 	 bfd_elf_generic_reloc,	/* special_function */
    524   1.1.1.2  christos 	 "R_C6000_PCR_H16",	/* name */
    525   1.1.1.8  christos 	 false,			/* partial_inplace */
    526   1.1.1.2  christos 	 0,			/* src_mask */
    527   1.1.1.2  christos 	 0x007fff80,		/* dst_mask */
    528   1.1.1.8  christos 	 true),			/* pcrel_offset */
    529   1.1.1.2  christos   HOWTO (R_C6000_PCR_L16,	/* type */
    530   1.1.1.2  christos 	 0,			/* rightshift */
    531   1.1.1.8  christos 	 4,			/* size */
    532   1.1.1.2  christos 	 16,			/* bitsize */
    533   1.1.1.8  christos 	 true,			/* pc_relative */
    534   1.1.1.2  christos 	 7,			/* bitpos */
    535   1.1.1.2  christos 	 complain_overflow_dont,/* complain_on_overflow */
    536   1.1.1.2  christos 	 bfd_elf_generic_reloc,	/* special_function */
    537   1.1.1.2  christos 	 "R_C6000_PCR_L16",	/* name */
    538   1.1.1.8  christos 	 false,			/* partial_inplace */
    539   1.1.1.2  christos 	 0,			/* src_mask */
    540   1.1.1.2  christos 	 0x007fff80,		/* dst_mask */
    541   1.1.1.8  christos 	 true),			/* pcrel_offset */
    542       1.1  christos   EMPTY_HOWTO (31),
    543       1.1  christos   EMPTY_HOWTO (32),
    544       1.1  christos   EMPTY_HOWTO (33),
    545       1.1  christos   EMPTY_HOWTO (34),
    546       1.1  christos   EMPTY_HOWTO (35),
    547       1.1  christos   EMPTY_HOWTO (36),
    548       1.1  christos   EMPTY_HOWTO (37),
    549       1.1  christos   EMPTY_HOWTO (38),
    550       1.1  christos   EMPTY_HOWTO (39),
    551       1.1  christos   EMPTY_HOWTO (40),
    552       1.1  christos   EMPTY_HOWTO (41),
    553       1.1  christos   EMPTY_HOWTO (42),
    554       1.1  christos   EMPTY_HOWTO (43),
    555       1.1  christos   EMPTY_HOWTO (44),
    556       1.1  christos   EMPTY_HOWTO (45),
    557       1.1  christos   EMPTY_HOWTO (46),
    558       1.1  christos   EMPTY_HOWTO (47),
    559       1.1  christos   EMPTY_HOWTO (48),
    560       1.1  christos   EMPTY_HOWTO (49),
    561       1.1  christos   EMPTY_HOWTO (50),
    562       1.1  christos   EMPTY_HOWTO (51),
    563       1.1  christos   EMPTY_HOWTO (52),
    564       1.1  christos   EMPTY_HOWTO (53),
    565       1.1  christos   EMPTY_HOWTO (54),
    566       1.1  christos   EMPTY_HOWTO (55),
    567       1.1  christos   EMPTY_HOWTO (56),
    568       1.1  christos   EMPTY_HOWTO (57),
    569       1.1  christos   EMPTY_HOWTO (58),
    570       1.1  christos   EMPTY_HOWTO (59),
    571       1.1  christos   EMPTY_HOWTO (60),
    572       1.1  christos   EMPTY_HOWTO (61),
    573       1.1  christos   EMPTY_HOWTO (62),
    574       1.1  christos   EMPTY_HOWTO (63),
    575       1.1  christos   EMPTY_HOWTO (64),
    576       1.1  christos   EMPTY_HOWTO (65),
    577       1.1  christos   EMPTY_HOWTO (66),
    578       1.1  christos   EMPTY_HOWTO (67),
    579       1.1  christos   EMPTY_HOWTO (68),
    580       1.1  christos   EMPTY_HOWTO (69),
    581       1.1  christos   EMPTY_HOWTO (70),
    582       1.1  christos   EMPTY_HOWTO (71),
    583       1.1  christos   EMPTY_HOWTO (72),
    584       1.1  christos   EMPTY_HOWTO (73),
    585       1.1  christos   EMPTY_HOWTO (74),
    586       1.1  christos   EMPTY_HOWTO (75),
    587       1.1  christos   EMPTY_HOWTO (76),
    588       1.1  christos   EMPTY_HOWTO (77),
    589       1.1  christos   EMPTY_HOWTO (78),
    590       1.1  christos   EMPTY_HOWTO (79),
    591       1.1  christos   EMPTY_HOWTO (80),
    592       1.1  christos   EMPTY_HOWTO (81),
    593       1.1  christos   EMPTY_HOWTO (82),
    594       1.1  christos   EMPTY_HOWTO (83),
    595       1.1  christos   EMPTY_HOWTO (84),
    596       1.1  christos   EMPTY_HOWTO (85),
    597       1.1  christos   EMPTY_HOWTO (86),
    598       1.1  christos   EMPTY_HOWTO (87),
    599       1.1  christos   EMPTY_HOWTO (88),
    600       1.1  christos   EMPTY_HOWTO (89),
    601       1.1  christos   EMPTY_HOWTO (90),
    602       1.1  christos   EMPTY_HOWTO (91),
    603       1.1  christos   EMPTY_HOWTO (92),
    604       1.1  christos   EMPTY_HOWTO (93),
    605       1.1  christos   EMPTY_HOWTO (94),
    606       1.1  christos   EMPTY_HOWTO (95),
    607       1.1  christos   EMPTY_HOWTO (96),
    608       1.1  christos   EMPTY_HOWTO (97),
    609       1.1  christos   EMPTY_HOWTO (98),
    610       1.1  christos   EMPTY_HOWTO (99),
    611       1.1  christos   EMPTY_HOWTO (100),
    612       1.1  christos   EMPTY_HOWTO (101),
    613       1.1  christos   EMPTY_HOWTO (102),
    614       1.1  christos   EMPTY_HOWTO (103),
    615       1.1  christos   EMPTY_HOWTO (104),
    616       1.1  christos   EMPTY_HOWTO (105),
    617       1.1  christos   EMPTY_HOWTO (106),
    618       1.1  christos   EMPTY_HOWTO (107),
    619       1.1  christos   EMPTY_HOWTO (108),
    620       1.1  christos   EMPTY_HOWTO (109),
    621       1.1  christos   EMPTY_HOWTO (110),
    622       1.1  christos   EMPTY_HOWTO (111),
    623       1.1  christos   EMPTY_HOWTO (112),
    624       1.1  christos   EMPTY_HOWTO (113),
    625       1.1  christos   EMPTY_HOWTO (114),
    626       1.1  christos   EMPTY_HOWTO (115),
    627       1.1  christos   EMPTY_HOWTO (116),
    628       1.1  christos   EMPTY_HOWTO (117),
    629       1.1  christos   EMPTY_HOWTO (118),
    630       1.1  christos   EMPTY_HOWTO (119),
    631       1.1  christos   EMPTY_HOWTO (120),
    632       1.1  christos   EMPTY_HOWTO (121),
    633       1.1  christos   EMPTY_HOWTO (122),
    634       1.1  christos   EMPTY_HOWTO (123),
    635       1.1  christos   EMPTY_HOWTO (124),
    636       1.1  christos   EMPTY_HOWTO (125),
    637       1.1  christos   EMPTY_HOWTO (126),
    638       1.1  christos   EMPTY_HOWTO (127),
    639       1.1  christos   EMPTY_HOWTO (128),
    640       1.1  christos   EMPTY_HOWTO (129),
    641       1.1  christos   EMPTY_HOWTO (130),
    642       1.1  christos   EMPTY_HOWTO (131),
    643       1.1  christos   EMPTY_HOWTO (132),
    644       1.1  christos   EMPTY_HOWTO (133),
    645       1.1  christos   EMPTY_HOWTO (134),
    646       1.1  christos   EMPTY_HOWTO (135),
    647       1.1  christos   EMPTY_HOWTO (136),
    648       1.1  christos   EMPTY_HOWTO (137),
    649       1.1  christos   EMPTY_HOWTO (138),
    650       1.1  christos   EMPTY_HOWTO (139),
    651       1.1  christos   EMPTY_HOWTO (140),
    652       1.1  christos   EMPTY_HOWTO (141),
    653       1.1  christos   EMPTY_HOWTO (142),
    654       1.1  christos   EMPTY_HOWTO (143),
    655       1.1  christos   EMPTY_HOWTO (144),
    656       1.1  christos   EMPTY_HOWTO (145),
    657       1.1  christos   EMPTY_HOWTO (146),
    658       1.1  christos   EMPTY_HOWTO (147),
    659       1.1  christos   EMPTY_HOWTO (148),
    660       1.1  christos   EMPTY_HOWTO (149),
    661       1.1  christos   EMPTY_HOWTO (150),
    662       1.1  christos   EMPTY_HOWTO (151),
    663       1.1  christos   EMPTY_HOWTO (152),
    664       1.1  christos   EMPTY_HOWTO (153),
    665       1.1  christos   EMPTY_HOWTO (154),
    666       1.1  christos   EMPTY_HOWTO (155),
    667       1.1  christos   EMPTY_HOWTO (156),
    668       1.1  christos   EMPTY_HOWTO (157),
    669       1.1  christos   EMPTY_HOWTO (158),
    670       1.1  christos   EMPTY_HOWTO (159),
    671       1.1  christos   EMPTY_HOWTO (160),
    672       1.1  christos   EMPTY_HOWTO (161),
    673       1.1  christos   EMPTY_HOWTO (162),
    674       1.1  christos   EMPTY_HOWTO (163),
    675       1.1  christos   EMPTY_HOWTO (164),
    676       1.1  christos   EMPTY_HOWTO (165),
    677       1.1  christos   EMPTY_HOWTO (166),
    678       1.1  christos   EMPTY_HOWTO (167),
    679       1.1  christos   EMPTY_HOWTO (168),
    680       1.1  christos   EMPTY_HOWTO (169),
    681       1.1  christos   EMPTY_HOWTO (170),
    682       1.1  christos   EMPTY_HOWTO (171),
    683       1.1  christos   EMPTY_HOWTO (172),
    684       1.1  christos   EMPTY_HOWTO (173),
    685       1.1  christos   EMPTY_HOWTO (174),
    686       1.1  christos   EMPTY_HOWTO (175),
    687       1.1  christos   EMPTY_HOWTO (176),
    688       1.1  christos   EMPTY_HOWTO (177),
    689       1.1  christos   EMPTY_HOWTO (178),
    690       1.1  christos   EMPTY_HOWTO (179),
    691       1.1  christos   EMPTY_HOWTO (180),
    692       1.1  christos   EMPTY_HOWTO (181),
    693       1.1  christos   EMPTY_HOWTO (182),
    694       1.1  christos   EMPTY_HOWTO (183),
    695       1.1  christos   EMPTY_HOWTO (184),
    696       1.1  christos   EMPTY_HOWTO (185),
    697       1.1  christos   EMPTY_HOWTO (186),
    698       1.1  christos   EMPTY_HOWTO (187),
    699       1.1  christos   EMPTY_HOWTO (188),
    700       1.1  christos   EMPTY_HOWTO (189),
    701       1.1  christos   EMPTY_HOWTO (190),
    702       1.1  christos   EMPTY_HOWTO (191),
    703       1.1  christos   EMPTY_HOWTO (192),
    704       1.1  christos   EMPTY_HOWTO (193),
    705       1.1  christos   EMPTY_HOWTO (194),
    706       1.1  christos   EMPTY_HOWTO (195),
    707       1.1  christos   EMPTY_HOWTO (196),
    708       1.1  christos   EMPTY_HOWTO (197),
    709       1.1  christos   EMPTY_HOWTO (198),
    710       1.1  christos   EMPTY_HOWTO (199),
    711       1.1  christos   EMPTY_HOWTO (200),
    712       1.1  christos   EMPTY_HOWTO (201),
    713       1.1  christos   EMPTY_HOWTO (202),
    714       1.1  christos   EMPTY_HOWTO (203),
    715       1.1  christos   EMPTY_HOWTO (204),
    716       1.1  christos   EMPTY_HOWTO (205),
    717       1.1  christos   EMPTY_HOWTO (206),
    718       1.1  christos   EMPTY_HOWTO (207),
    719       1.1  christos   EMPTY_HOWTO (208),
    720       1.1  christos   EMPTY_HOWTO (209),
    721       1.1  christos   EMPTY_HOWTO (210),
    722       1.1  christos   EMPTY_HOWTO (211),
    723       1.1  christos   EMPTY_HOWTO (212),
    724       1.1  christos   EMPTY_HOWTO (213),
    725       1.1  christos   EMPTY_HOWTO (214),
    726       1.1  christos   EMPTY_HOWTO (215),
    727       1.1  christos   EMPTY_HOWTO (216),
    728       1.1  christos   EMPTY_HOWTO (217),
    729       1.1  christos   EMPTY_HOWTO (218),
    730       1.1  christos   EMPTY_HOWTO (219),
    731       1.1  christos   EMPTY_HOWTO (220),
    732       1.1  christos   EMPTY_HOWTO (221),
    733       1.1  christos   EMPTY_HOWTO (222),
    734       1.1  christos   EMPTY_HOWTO (223),
    735       1.1  christos   EMPTY_HOWTO (224),
    736       1.1  christos   EMPTY_HOWTO (225),
    737       1.1  christos   EMPTY_HOWTO (226),
    738       1.1  christos   EMPTY_HOWTO (227),
    739       1.1  christos   EMPTY_HOWTO (228),
    740       1.1  christos   EMPTY_HOWTO (229),
    741       1.1  christos   EMPTY_HOWTO (230),
    742       1.1  christos   EMPTY_HOWTO (231),
    743       1.1  christos   EMPTY_HOWTO (232),
    744       1.1  christos   EMPTY_HOWTO (233),
    745       1.1  christos   EMPTY_HOWTO (234),
    746       1.1  christos   EMPTY_HOWTO (235),
    747       1.1  christos   EMPTY_HOWTO (236),
    748       1.1  christos   EMPTY_HOWTO (237),
    749       1.1  christos   EMPTY_HOWTO (238),
    750       1.1  christos   EMPTY_HOWTO (239),
    751       1.1  christos   EMPTY_HOWTO (240),
    752       1.1  christos   EMPTY_HOWTO (241),
    753       1.1  christos   EMPTY_HOWTO (242),
    754       1.1  christos   EMPTY_HOWTO (243),
    755       1.1  christos   EMPTY_HOWTO (244),
    756       1.1  christos   EMPTY_HOWTO (245),
    757       1.1  christos   EMPTY_HOWTO (246),
    758       1.1  christos   EMPTY_HOWTO (247),
    759       1.1  christos   EMPTY_HOWTO (248),
    760       1.1  christos   EMPTY_HOWTO (249),
    761       1.1  christos   EMPTY_HOWTO (250),
    762       1.1  christos   EMPTY_HOWTO (251),
    763       1.1  christos   EMPTY_HOWTO (252),
    764       1.1  christos   HOWTO (R_C6000_ALIGN,		/* type */
    765       1.1  christos 	 0,			/* rightshift */
    766   1.1.1.8  christos 	 0,			/* size */
    767       1.1  christos 	 0,			/* bitsize */
    768   1.1.1.8  christos 	 false,			/* pc_relative */
    769       1.1  christos 	 0,			/* bitpos */
    770       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    771       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    772       1.1  christos 	 "R_C6000_ALIGN",	/* name */
    773   1.1.1.8  christos 	 false,			/* partial_inplace */
    774       1.1  christos 	 0,			/* src_mask */
    775       1.1  christos 	 0,			/* dst_mask */
    776   1.1.1.8  christos 	 false),		/* pcrel_offset */
    777       1.1  christos   HOWTO (R_C6000_FPHEAD,	/* type */
    778       1.1  christos 	 0,			/* rightshift */
    779   1.1.1.8  christos 	 0,			/* size */
    780       1.1  christos 	 0,			/* bitsize */
    781   1.1.1.8  christos 	 false,			/* pc_relative */
    782       1.1  christos 	 0,			/* bitpos */
    783       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    784       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    785       1.1  christos 	 "R_C6000_FPHEAD",	/* name */
    786   1.1.1.8  christos 	 false,			/* partial_inplace */
    787       1.1  christos 	 0,			/* src_mask */
    788       1.1  christos 	 0,			/* dst_mask */
    789   1.1.1.8  christos 	 false),		/* pcrel_offset */
    790       1.1  christos   HOWTO (R_C6000_NOCMP,		/* type */
    791       1.1  christos 	 0,			/* rightshift */
    792   1.1.1.8  christos 	 0,			/* size */
    793       1.1  christos 	 0,			/* bitsize */
    794   1.1.1.8  christos 	 false,			/* pc_relative */
    795       1.1  christos 	 0,			/* bitpos */
    796       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    797       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    798       1.1  christos 	 "R_C6000_NOCMP",	/* name */
    799   1.1.1.8  christos 	 false,			/* partial_inplace */
    800       1.1  christos 	 0,			/* src_mask */
    801       1.1  christos 	 0,			/* dst_mask */
    802   1.1.1.8  christos 	 false)			/* pcrel_offset */
    803       1.1  christos };
    804       1.1  christos 
    805       1.1  christos static reloc_howto_type elf32_tic6x_howto_table_rel[] =
    806       1.1  christos {
    807       1.1  christos   HOWTO (R_C6000_NONE,		/* type */
    808       1.1  christos 	 0,			/* rightshift */
    809   1.1.1.8  christos 	 0,			/* size */
    810       1.1  christos 	 0,			/* bitsize */
    811   1.1.1.8  christos 	 false,			/* pc_relative */
    812       1.1  christos 	 0,			/* bitpos */
    813       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    814       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    815       1.1  christos 	 "R_C6000_NONE",	/* name */
    816   1.1.1.8  christos 	 true,			/* partial_inplace */
    817       1.1  christos 	 0,			/* src_mask */
    818       1.1  christos 	 0,			/* dst_mask */
    819   1.1.1.8  christos 	 false),		/* pcrel_offset */
    820       1.1  christos   HOWTO (R_C6000_ABS32,		/* type */
    821       1.1  christos 	 0,			/* rightshift */
    822   1.1.1.8  christos 	 4,			/* size */
    823       1.1  christos 	 32,			/* bitsize */
    824   1.1.1.8  christos 	 false,			/* pc_relative */
    825       1.1  christos 	 0,			/* bitpos */
    826       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    827       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    828       1.1  christos 	 "R_C6000_ABS32",	/* name */
    829   1.1.1.8  christos 	 true,			/* partial_inplace */
    830       1.1  christos 	 0xffffffff,		/* src_mask */
    831       1.1  christos 	 0xffffffff,		/* dst_mask */
    832   1.1.1.8  christos 	 false),		/* pcrel_offset */
    833       1.1  christos   HOWTO (R_C6000_ABS16,		/* type */
    834       1.1  christos 	 0,			/* rightshift */
    835   1.1.1.8  christos 	 2,			/* size */
    836       1.1  christos 	 16,			/* bitsize */
    837   1.1.1.8  christos 	 false,			/* pc_relative */
    838       1.1  christos 	 0,			/* bitpos */
    839       1.1  christos 	 complain_overflow_bitfield,/* complain_on_overflow */
    840       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    841       1.1  christos 	 "R_C6000_ABS16",	/* name */
    842   1.1.1.8  christos 	 true,			/* partial_inplace */
    843       1.1  christos 	 0x0000ffff,		/* src_mask */
    844       1.1  christos 	 0x0000ffff,		/* dst_mask */
    845   1.1.1.8  christos 	 false),		/* pcrel_offset */
    846       1.1  christos   HOWTO (R_C6000_ABS8,		/* type */
    847       1.1  christos 	 0,			/* rightshift */
    848   1.1.1.8  christos 	 1,			/* size */
    849       1.1  christos 	 8,			/* bitsize */
    850   1.1.1.8  christos 	 false,			/* pc_relative */
    851       1.1  christos 	 0,			/* bitpos */
    852       1.1  christos 	 complain_overflow_bitfield,/* complain_on_overflow */
    853       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    854       1.1  christos 	 "R_C6000_ABS8",	/* name */
    855   1.1.1.8  christos 	 true,			/* partial_inplace */
    856       1.1  christos 	 0x000000ff,		/* src_mask */
    857       1.1  christos 	 0x000000ff,		/* dst_mask */
    858   1.1.1.8  christos 	 false),		/* pcrel_offset */
    859       1.1  christos   HOWTO (R_C6000_PCR_S21,	/* type */
    860       1.1  christos 	 2,			/* rightshift */
    861   1.1.1.8  christos 	 4,			/* size */
    862       1.1  christos 	 21,			/* bitsize */
    863   1.1.1.8  christos 	 true,			/* pc_relative */
    864       1.1  christos 	 7,			/* bitpos */
    865       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    866       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    867       1.1  christos 	 "R_C6000_PCR_S21",	/* name */
    868   1.1.1.8  christos 	 true,			/* partial_inplace */
    869       1.1  christos 	 0x0fffff80,		/* src_mask */
    870       1.1  christos 	 0x0fffff80,		/* dst_mask */
    871   1.1.1.8  christos 	 true),			/* pcrel_offset */
    872       1.1  christos   HOWTO (R_C6000_PCR_S12,	/* type */
    873       1.1  christos 	 2,			/* rightshift */
    874   1.1.1.8  christos 	 4,			/* size */
    875       1.1  christos 	 12,			/* bitsize */
    876   1.1.1.8  christos 	 true,			/* pc_relative */
    877       1.1  christos 	 16,			/* bitpos */
    878       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    879       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    880       1.1  christos 	 "R_C6000_PCR_S12",	/* name */
    881   1.1.1.8  christos 	 true,			/* partial_inplace */
    882       1.1  christos 	 0x0fff0000,		/* src_mask */
    883       1.1  christos 	 0x0fff0000,		/* dst_mask */
    884   1.1.1.8  christos 	 true),			/* pcrel_offset */
    885       1.1  christos   HOWTO (R_C6000_PCR_S10,	/* type */
    886       1.1  christos 	 2,			/* rightshift */
    887   1.1.1.8  christos 	 4,			/* size */
    888       1.1  christos 	 10,			/* bitsize */
    889   1.1.1.8  christos 	 true,			/* pc_relative */
    890       1.1  christos 	 13,			/* bitpos */
    891       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    892       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    893       1.1  christos 	 "R_C6000_PCR_S10",	/* name */
    894   1.1.1.8  christos 	 true,			/* partial_inplace */
    895       1.1  christos 	 0x007fe000,		/* src_mask */
    896       1.1  christos 	 0x007fe000,		/* dst_mask */
    897   1.1.1.8  christos 	 true),			/* pcrel_offset */
    898       1.1  christos   HOWTO (R_C6000_PCR_S7,	/* type */
    899       1.1  christos 	 2,			/* rightshift */
    900   1.1.1.8  christos 	 4,			/* size */
    901       1.1  christos 	 7,			/* bitsize */
    902   1.1.1.8  christos 	 true,			/* pc_relative */
    903       1.1  christos 	 16,			/* bitpos */
    904       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    905       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    906       1.1  christos 	 "R_C6000_PCR_S7",	/* name */
    907   1.1.1.8  christos 	 true,			/* partial_inplace */
    908       1.1  christos 	 0x007f0000,		/* src_mask */
    909       1.1  christos 	 0x007f0000,		/* dst_mask */
    910   1.1.1.8  christos 	 true),			/* pcrel_offset */
    911       1.1  christos   HOWTO (R_C6000_ABS_S16,	/* type */
    912       1.1  christos 	 0,			/* rightshift */
    913   1.1.1.8  christos 	 4,			/* size */
    914       1.1  christos 	 16,			/* bitsize */
    915   1.1.1.8  christos 	 false,			/* pc_relative */
    916       1.1  christos 	 7,			/* bitpos */
    917       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    918       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    919       1.1  christos 	 "R_C6000_ABS_S16",	/* name */
    920   1.1.1.8  christos 	 true,			/* partial_inplace */
    921       1.1  christos 	 0x007fff80,		/* src_mask */
    922       1.1  christos 	 0x007fff80,		/* dst_mask */
    923   1.1.1.8  christos 	 false),		/* pcrel_offset */
    924       1.1  christos   HOWTO (R_C6000_ABS_L16,	/* type */
    925       1.1  christos 	 0,			/* rightshift */
    926   1.1.1.8  christos 	 4,			/* size */
    927       1.1  christos 	 16,			/* bitsize */
    928   1.1.1.8  christos 	 false,			/* pc_relative */
    929       1.1  christos 	 7,			/* bitpos */
    930       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    931       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    932       1.1  christos 	 "R_C6000_ABS_L16",	/* name */
    933   1.1.1.8  christos 	 true,			/* partial_inplace */
    934       1.1  christos 	 0x007fff80,		/* src_mask */
    935       1.1  christos 	 0x007fff80,		/* dst_mask */
    936   1.1.1.8  christos 	 false),		/* pcrel_offset */
    937       1.1  christos   EMPTY_HOWTO (R_C6000_ABS_H16),
    938       1.1  christos   HOWTO (R_C6000_SBR_U15_B,	/* type */
    939       1.1  christos 	 0,			/* rightshift */
    940   1.1.1.8  christos 	 4,			/* size */
    941       1.1  christos 	 15,			/* bitsize */
    942   1.1.1.8  christos 	 false,			/* pc_relative */
    943       1.1  christos 	 8,			/* bitpos */
    944       1.1  christos 	 complain_overflow_unsigned,/* complain_on_overflow */
    945       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    946       1.1  christos 	 "R_C6000_SBR_U15_B",	/* name */
    947   1.1.1.8  christos 	 true,			/* partial_inplace */
    948       1.1  christos 	 0x007fff00,		/* src_mask */
    949       1.1  christos 	 0x007fff00,		/* dst_mask */
    950   1.1.1.8  christos 	 false),		/* pcrel_offset */
    951       1.1  christos   HOWTO (R_C6000_SBR_U15_H,	/* type */
    952       1.1  christos 	 1,			/* rightshift */
    953   1.1.1.8  christos 	 4,			/* size */
    954       1.1  christos 	 15,			/* bitsize */
    955   1.1.1.8  christos 	 false,			/* pc_relative */
    956       1.1  christos 	 8,			/* bitpos */
    957       1.1  christos 	 complain_overflow_unsigned,/* complain_on_overflow */
    958       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    959       1.1  christos 	 "R_C6000_SBR_U15_H",	/* name */
    960   1.1.1.8  christos 	 true,			/* partial_inplace */
    961       1.1  christos 	 0x007fff00,		/* src_mask */
    962       1.1  christos 	 0x007fff00,		/* dst_mask */
    963   1.1.1.8  christos 	 false),		/* pcrel_offset */
    964       1.1  christos   HOWTO (R_C6000_SBR_U15_W,	/* type */
    965       1.1  christos 	 2,			/* rightshift */
    966   1.1.1.8  christos 	 4,			/* size */
    967       1.1  christos 	 15,			/* bitsize */
    968   1.1.1.8  christos 	 false,			/* pc_relative */
    969       1.1  christos 	 8,			/* bitpos */
    970       1.1  christos 	 complain_overflow_unsigned,/* complain_on_overflow */
    971       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    972       1.1  christos 	 "R_C6000_SBR_U15_W",	/* name */
    973   1.1.1.8  christos 	 true,			/* partial_inplace */
    974       1.1  christos 	 0x007fff00,		/* src_mask */
    975       1.1  christos 	 0x007fff00,		/* dst_mask */
    976   1.1.1.8  christos 	 false),		/* pcrel_offset */
    977       1.1  christos   HOWTO (R_C6000_SBR_S16,	/* type */
    978       1.1  christos 	 0,			/* rightshift */
    979   1.1.1.8  christos 	 4,			/* size */
    980       1.1  christos 	 16,			/* bitsize */
    981   1.1.1.8  christos 	 false,			/* pc_relative */
    982       1.1  christos 	 7,			/* bitpos */
    983       1.1  christos 	 complain_overflow_signed,/* complain_on_overflow */
    984       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    985       1.1  christos 	 "R_C6000_SBR_S16",	/* name */
    986   1.1.1.8  christos 	 true,			/* partial_inplace */
    987       1.1  christos 	 0x007fff80,		/* src_mask */
    988       1.1  christos 	 0x007fff80,		/* dst_mask */
    989   1.1.1.8  christos 	 false),		/* pcrel_offset */
    990       1.1  christos   HOWTO (R_C6000_SBR_L16_B,	/* type */
    991       1.1  christos 	 0,			/* rightshift */
    992   1.1.1.8  christos 	 4,			/* size */
    993       1.1  christos 	 16,			/* bitsize */
    994   1.1.1.8  christos 	 false,			/* pc_relative */
    995       1.1  christos 	 7,			/* bitpos */
    996       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    997       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    998       1.1  christos 	 "R_C6000_SBR_L16_B",	/* name */
    999   1.1.1.8  christos 	 true,			/* partial_inplace */
   1000       1.1  christos 	 0x007fff80,		/* src_mask */
   1001       1.1  christos 	 0x007fff80,		/* dst_mask */
   1002   1.1.1.8  christos 	 false),		/* pcrel_offset */
   1003       1.1  christos   HOWTO (R_C6000_SBR_L16_H,	/* type */
   1004       1.1  christos 	 1,			/* rightshift */
   1005   1.1.1.8  christos 	 4,			/* size */
   1006       1.1  christos 	 16,			/* bitsize */
   1007   1.1.1.8  christos 	 false,			/* pc_relative */
   1008       1.1  christos 	 7,			/* bitpos */
   1009       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
   1010       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1011       1.1  christos 	 "R_C6000_SBR_L16_H",	/* name */
   1012   1.1.1.8  christos 	 true,			/* partial_inplace */
   1013       1.1  christos 	 0x007fff80,		/* src_mask */
   1014       1.1  christos 	 0x007fff80,		/* dst_mask */
   1015   1.1.1.8  christos 	 false),		/* pcrel_offset */
   1016       1.1  christos   HOWTO (R_C6000_SBR_L16_W,	/* type */
   1017       1.1  christos 	 2,			/* rightshift */
   1018   1.1.1.8  christos 	 4,			/* size */
   1019       1.1  christos 	 16,			/* bitsize */
   1020   1.1.1.8  christos 	 false,			/* pc_relative */
   1021       1.1  christos 	 7,			/* bitpos */
   1022       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
   1023       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1024       1.1  christos 	 "R_C6000_SBR_L16_W",	/* name */
   1025   1.1.1.8  christos 	 true,			/* partial_inplace */
   1026       1.1  christos 	 0x007fff80,		/* src_mask */
   1027       1.1  christos 	 0x007fff80,		/* dst_mask */
   1028   1.1.1.8  christos 	 false),		/* pcrel_offset */
   1029       1.1  christos   EMPTY_HOWTO (R_C6000_SBR_H16_B),
   1030       1.1  christos   EMPTY_HOWTO (R_C6000_SBR_H16_H),
   1031       1.1  christos   EMPTY_HOWTO (R_C6000_SBR_H16_W),
   1032       1.1  christos   HOWTO (R_C6000_SBR_GOT_U15_W,	/* type */
   1033       1.1  christos 	 2,			/* rightshift */
   1034   1.1.1.8  christos 	 4,			/* size */
   1035       1.1  christos 	 15,			/* bitsize */
   1036   1.1.1.8  christos 	 false,			/* pc_relative */
   1037       1.1  christos 	 8,			/* bitpos */
   1038       1.1  christos 	 complain_overflow_unsigned,/* complain_on_overflow */
   1039       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1040       1.1  christos 	 "R_C6000_SBR_GOT_U15_W",/* name */
   1041   1.1.1.8  christos 	 true,			/* partial_inplace */
   1042       1.1  christos 	 0x007fff00,		/* src_mask */
   1043       1.1  christos 	 0x007fff00,		/* dst_mask */
   1044   1.1.1.8  christos 	 false),		/* pcrel_offset */
   1045       1.1  christos   HOWTO (R_C6000_SBR_GOT_L16_W,	/* type */
   1046       1.1  christos 	 2,			/* rightshift */
   1047   1.1.1.8  christos 	 4,			/* size */
   1048       1.1  christos 	 16,			/* bitsize */
   1049   1.1.1.8  christos 	 false,			/* pc_relative */
   1050       1.1  christos 	 7,			/* bitpos */
   1051       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
   1052       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1053       1.1  christos 	 "R_C6000_SBR_GOT_L16_W",/* name */
   1054   1.1.1.8  christos 	 true,			/* partial_inplace */
   1055       1.1  christos 	 0x007fff80,		/* src_mask */
   1056       1.1  christos 	 0x007fff80,		/* dst_mask */
   1057   1.1.1.8  christos 	 false),		/* pcrel_offset */
   1058       1.1  christos   EMPTY_HOWTO (R_C6000_SBR_GOT_H16_W),
   1059       1.1  christos   HOWTO (R_C6000_DSBT_INDEX,	/* type */
   1060       1.1  christos 	 0,			/* rightshift */
   1061   1.1.1.8  christos 	 4,			/* size */
   1062       1.1  christos 	 15,			/* bitsize */
   1063   1.1.1.8  christos 	 false,			/* pc_relative */
   1064       1.1  christos 	 8,			/* bitpos */
   1065       1.1  christos 	 complain_overflow_unsigned,/* complain_on_overflow */
   1066       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1067       1.1  christos 	 "R_C6000_DSBT_INDEX",	/* name */
   1068   1.1.1.8  christos 	 true,			/* partial_inplace */
   1069       1.1  christos 	 0,			/* src_mask */
   1070       1.1  christos 	 0x007fff00,		/* dst_mask */
   1071   1.1.1.8  christos 	 false),		/* pcrel_offset */
   1072       1.1  christos   HOWTO (R_C6000_PREL31,	/* type */
   1073       1.1  christos 	 1,			/* rightshift */
   1074   1.1.1.8  christos 	 4,			/* size */
   1075       1.1  christos 	 31,			/* bitsize */
   1076   1.1.1.8  christos 	 true,			/* pc_relative */
   1077       1.1  christos 	 0,			/* bitpos */
   1078       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
   1079       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1080       1.1  christos 	 "R_C6000_PREL31",	/* name */
   1081   1.1.1.8  christos 	 true,			/* partial_inplace */
   1082       1.1  christos 	 0,			/* src_mask */
   1083       1.1  christos 	 0x7fffffff,		/* dst_mask */
   1084   1.1.1.8  christos 	 true),			/* pcrel_offset */
   1085       1.1  christos   HOWTO (R_C6000_COPY,		/* type */
   1086       1.1  christos 	 0,			/* rightshift */
   1087   1.1.1.8  christos 	 4,			/* size */
   1088       1.1  christos 	 32,			/* bitsize */
   1089   1.1.1.8  christos 	 false,			/* pc_relative */
   1090       1.1  christos 	 0,			/* bitpos */
   1091       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
   1092       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1093       1.1  christos 	 "R_C6000_COPY",	/* name */
   1094   1.1.1.8  christos 	 true,			/* partial_inplace */
   1095       1.1  christos 	 0,			/* src_mask */
   1096       1.1  christos 	 0xffffffff,		/* dst_mask */
   1097   1.1.1.8  christos 	 false),		/* pcrel_offset */
   1098   1.1.1.2  christos   HOWTO (R_C6000_JUMP_SLOT,	/* type */
   1099   1.1.1.2  christos 	 0,			/* rightshift */
   1100   1.1.1.8  christos 	 4,			/* size */
   1101   1.1.1.2  christos 	 32,			/* bitsize */
   1102   1.1.1.8  christos 	 false,			/* pc_relative */
   1103   1.1.1.2  christos 	 0,			/* bitpos */
   1104   1.1.1.2  christos 	 complain_overflow_dont,/* complain_on_overflow */
   1105   1.1.1.2  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1106   1.1.1.2  christos 	 "R_C6000_JUMP_SLOT",	/* name */
   1107   1.1.1.8  christos 	 false,			/* partial_inplace */
   1108   1.1.1.2  christos 	 0,			/* src_mask */
   1109   1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
   1110   1.1.1.8  christos 	 false),		/* pcrel_offset */
   1111   1.1.1.2  christos   HOWTO (R_C6000_EHTYPE,	/* type */
   1112   1.1.1.2  christos 	 0,			/* rightshift */
   1113   1.1.1.8  christos 	 4,			/* size */
   1114   1.1.1.2  christos 	 32,			/* bitsize */
   1115   1.1.1.8  christos 	 false,			/* pc_relative */
   1116   1.1.1.2  christos 	 0,			/* bitpos */
   1117   1.1.1.2  christos 	 complain_overflow_dont,/* complain_on_overflow */
   1118   1.1.1.2  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1119   1.1.1.2  christos 	 "R_C6000_EHTYPE",	/* name */
   1120   1.1.1.8  christos 	 false,			/* partial_inplace */
   1121   1.1.1.2  christos 	 0,			/* src_mask */
   1122   1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
   1123   1.1.1.8  christos 	 false),		/* pcrel_offset */
   1124   1.1.1.2  christos   EMPTY_HOWTO (R_C6000_PCR_H16),
   1125   1.1.1.2  christos   EMPTY_HOWTO (R_C6000_PCR_L16),
   1126       1.1  christos   EMPTY_HOWTO (31),
   1127       1.1  christos   EMPTY_HOWTO (32),
   1128       1.1  christos   EMPTY_HOWTO (33),
   1129       1.1  christos   EMPTY_HOWTO (34),
   1130       1.1  christos   EMPTY_HOWTO (35),
   1131       1.1  christos   EMPTY_HOWTO (36),
   1132       1.1  christos   EMPTY_HOWTO (37),
   1133       1.1  christos   EMPTY_HOWTO (38),
   1134       1.1  christos   EMPTY_HOWTO (39),
   1135       1.1  christos   EMPTY_HOWTO (40),
   1136       1.1  christos   EMPTY_HOWTO (41),
   1137       1.1  christos   EMPTY_HOWTO (42),
   1138       1.1  christos   EMPTY_HOWTO (43),
   1139       1.1  christos   EMPTY_HOWTO (44),
   1140       1.1  christos   EMPTY_HOWTO (45),
   1141       1.1  christos   EMPTY_HOWTO (46),
   1142       1.1  christos   EMPTY_HOWTO (47),
   1143       1.1  christos   EMPTY_HOWTO (48),
   1144       1.1  christos   EMPTY_HOWTO (49),
   1145       1.1  christos   EMPTY_HOWTO (50),
   1146       1.1  christos   EMPTY_HOWTO (51),
   1147       1.1  christos   EMPTY_HOWTO (52),
   1148       1.1  christos   EMPTY_HOWTO (53),
   1149       1.1  christos   EMPTY_HOWTO (54),
   1150       1.1  christos   EMPTY_HOWTO (55),
   1151       1.1  christos   EMPTY_HOWTO (56),
   1152       1.1  christos   EMPTY_HOWTO (57),
   1153       1.1  christos   EMPTY_HOWTO (58),
   1154       1.1  christos   EMPTY_HOWTO (59),
   1155       1.1  christos   EMPTY_HOWTO (60),
   1156       1.1  christos   EMPTY_HOWTO (61),
   1157       1.1  christos   EMPTY_HOWTO (62),
   1158       1.1  christos   EMPTY_HOWTO (63),
   1159       1.1  christos   EMPTY_HOWTO (64),
   1160       1.1  christos   EMPTY_HOWTO (65),
   1161       1.1  christos   EMPTY_HOWTO (66),
   1162       1.1  christos   EMPTY_HOWTO (67),
   1163       1.1  christos   EMPTY_HOWTO (68),
   1164       1.1  christos   EMPTY_HOWTO (69),
   1165       1.1  christos   EMPTY_HOWTO (70),
   1166       1.1  christos   EMPTY_HOWTO (71),
   1167       1.1  christos   EMPTY_HOWTO (72),
   1168       1.1  christos   EMPTY_HOWTO (73),
   1169       1.1  christos   EMPTY_HOWTO (74),
   1170       1.1  christos   EMPTY_HOWTO (75),
   1171       1.1  christos   EMPTY_HOWTO (76),
   1172       1.1  christos   EMPTY_HOWTO (77),
   1173       1.1  christos   EMPTY_HOWTO (78),
   1174       1.1  christos   EMPTY_HOWTO (79),
   1175       1.1  christos   EMPTY_HOWTO (80),
   1176       1.1  christos   EMPTY_HOWTO (81),
   1177       1.1  christos   EMPTY_HOWTO (82),
   1178       1.1  christos   EMPTY_HOWTO (83),
   1179       1.1  christos   EMPTY_HOWTO (84),
   1180       1.1  christos   EMPTY_HOWTO (85),
   1181       1.1  christos   EMPTY_HOWTO (86),
   1182       1.1  christos   EMPTY_HOWTO (87),
   1183       1.1  christos   EMPTY_HOWTO (88),
   1184       1.1  christos   EMPTY_HOWTO (89),
   1185       1.1  christos   EMPTY_HOWTO (90),
   1186       1.1  christos   EMPTY_HOWTO (91),
   1187       1.1  christos   EMPTY_HOWTO (92),
   1188       1.1  christos   EMPTY_HOWTO (93),
   1189       1.1  christos   EMPTY_HOWTO (94),
   1190       1.1  christos   EMPTY_HOWTO (95),
   1191       1.1  christos   EMPTY_HOWTO (96),
   1192       1.1  christos   EMPTY_HOWTO (97),
   1193       1.1  christos   EMPTY_HOWTO (98),
   1194       1.1  christos   EMPTY_HOWTO (99),
   1195       1.1  christos   EMPTY_HOWTO (100),
   1196       1.1  christos   EMPTY_HOWTO (101),
   1197       1.1  christos   EMPTY_HOWTO (102),
   1198       1.1  christos   EMPTY_HOWTO (103),
   1199       1.1  christos   EMPTY_HOWTO (104),
   1200       1.1  christos   EMPTY_HOWTO (105),
   1201       1.1  christos   EMPTY_HOWTO (106),
   1202       1.1  christos   EMPTY_HOWTO (107),
   1203       1.1  christos   EMPTY_HOWTO (108),
   1204       1.1  christos   EMPTY_HOWTO (109),
   1205       1.1  christos   EMPTY_HOWTO (110),
   1206       1.1  christos   EMPTY_HOWTO (111),
   1207       1.1  christos   EMPTY_HOWTO (112),
   1208       1.1  christos   EMPTY_HOWTO (113),
   1209       1.1  christos   EMPTY_HOWTO (114),
   1210       1.1  christos   EMPTY_HOWTO (115),
   1211       1.1  christos   EMPTY_HOWTO (116),
   1212       1.1  christos   EMPTY_HOWTO (117),
   1213       1.1  christos   EMPTY_HOWTO (118),
   1214       1.1  christos   EMPTY_HOWTO (119),
   1215       1.1  christos   EMPTY_HOWTO (120),
   1216       1.1  christos   EMPTY_HOWTO (121),
   1217       1.1  christos   EMPTY_HOWTO (122),
   1218       1.1  christos   EMPTY_HOWTO (123),
   1219       1.1  christos   EMPTY_HOWTO (124),
   1220       1.1  christos   EMPTY_HOWTO (125),
   1221       1.1  christos   EMPTY_HOWTO (126),
   1222       1.1  christos   EMPTY_HOWTO (127),
   1223       1.1  christos   EMPTY_HOWTO (128),
   1224       1.1  christos   EMPTY_HOWTO (129),
   1225       1.1  christos   EMPTY_HOWTO (130),
   1226       1.1  christos   EMPTY_HOWTO (131),
   1227       1.1  christos   EMPTY_HOWTO (132),
   1228       1.1  christos   EMPTY_HOWTO (133),
   1229       1.1  christos   EMPTY_HOWTO (134),
   1230       1.1  christos   EMPTY_HOWTO (135),
   1231       1.1  christos   EMPTY_HOWTO (136),
   1232       1.1  christos   EMPTY_HOWTO (137),
   1233       1.1  christos   EMPTY_HOWTO (138),
   1234       1.1  christos   EMPTY_HOWTO (139),
   1235       1.1  christos   EMPTY_HOWTO (140),
   1236       1.1  christos   EMPTY_HOWTO (141),
   1237       1.1  christos   EMPTY_HOWTO (142),
   1238       1.1  christos   EMPTY_HOWTO (143),
   1239       1.1  christos   EMPTY_HOWTO (144),
   1240       1.1  christos   EMPTY_HOWTO (145),
   1241       1.1  christos   EMPTY_HOWTO (146),
   1242       1.1  christos   EMPTY_HOWTO (147),
   1243       1.1  christos   EMPTY_HOWTO (148),
   1244       1.1  christos   EMPTY_HOWTO (149),
   1245       1.1  christos   EMPTY_HOWTO (150),
   1246       1.1  christos   EMPTY_HOWTO (151),
   1247       1.1  christos   EMPTY_HOWTO (152),
   1248       1.1  christos   EMPTY_HOWTO (153),
   1249       1.1  christos   EMPTY_HOWTO (154),
   1250       1.1  christos   EMPTY_HOWTO (155),
   1251       1.1  christos   EMPTY_HOWTO (156),
   1252       1.1  christos   EMPTY_HOWTO (157),
   1253       1.1  christos   EMPTY_HOWTO (158),
   1254       1.1  christos   EMPTY_HOWTO (159),
   1255       1.1  christos   EMPTY_HOWTO (160),
   1256       1.1  christos   EMPTY_HOWTO (161),
   1257       1.1  christos   EMPTY_HOWTO (162),
   1258       1.1  christos   EMPTY_HOWTO (163),
   1259       1.1  christos   EMPTY_HOWTO (164),
   1260       1.1  christos   EMPTY_HOWTO (165),
   1261       1.1  christos   EMPTY_HOWTO (166),
   1262       1.1  christos   EMPTY_HOWTO (167),
   1263       1.1  christos   EMPTY_HOWTO (168),
   1264       1.1  christos   EMPTY_HOWTO (169),
   1265       1.1  christos   EMPTY_HOWTO (170),
   1266       1.1  christos   EMPTY_HOWTO (171),
   1267       1.1  christos   EMPTY_HOWTO (172),
   1268       1.1  christos   EMPTY_HOWTO (173),
   1269       1.1  christos   EMPTY_HOWTO (174),
   1270       1.1  christos   EMPTY_HOWTO (175),
   1271       1.1  christos   EMPTY_HOWTO (176),
   1272       1.1  christos   EMPTY_HOWTO (177),
   1273       1.1  christos   EMPTY_HOWTO (178),
   1274       1.1  christos   EMPTY_HOWTO (179),
   1275       1.1  christos   EMPTY_HOWTO (180),
   1276       1.1  christos   EMPTY_HOWTO (181),
   1277       1.1  christos   EMPTY_HOWTO (182),
   1278       1.1  christos   EMPTY_HOWTO (183),
   1279       1.1  christos   EMPTY_HOWTO (184),
   1280       1.1  christos   EMPTY_HOWTO (185),
   1281       1.1  christos   EMPTY_HOWTO (186),
   1282       1.1  christos   EMPTY_HOWTO (187),
   1283       1.1  christos   EMPTY_HOWTO (188),
   1284       1.1  christos   EMPTY_HOWTO (189),
   1285       1.1  christos   EMPTY_HOWTO (190),
   1286       1.1  christos   EMPTY_HOWTO (191),
   1287       1.1  christos   EMPTY_HOWTO (192),
   1288       1.1  christos   EMPTY_HOWTO (193),
   1289       1.1  christos   EMPTY_HOWTO (194),
   1290       1.1  christos   EMPTY_HOWTO (195),
   1291       1.1  christos   EMPTY_HOWTO (196),
   1292       1.1  christos   EMPTY_HOWTO (197),
   1293       1.1  christos   EMPTY_HOWTO (198),
   1294       1.1  christos   EMPTY_HOWTO (199),
   1295       1.1  christos   EMPTY_HOWTO (200),
   1296       1.1  christos   EMPTY_HOWTO (201),
   1297       1.1  christos   EMPTY_HOWTO (202),
   1298       1.1  christos   EMPTY_HOWTO (203),
   1299       1.1  christos   EMPTY_HOWTO (204),
   1300       1.1  christos   EMPTY_HOWTO (205),
   1301       1.1  christos   EMPTY_HOWTO (206),
   1302       1.1  christos   EMPTY_HOWTO (207),
   1303       1.1  christos   EMPTY_HOWTO (208),
   1304       1.1  christos   EMPTY_HOWTO (209),
   1305       1.1  christos   EMPTY_HOWTO (210),
   1306       1.1  christos   EMPTY_HOWTO (211),
   1307       1.1  christos   EMPTY_HOWTO (212),
   1308       1.1  christos   EMPTY_HOWTO (213),
   1309       1.1  christos   EMPTY_HOWTO (214),
   1310       1.1  christos   EMPTY_HOWTO (215),
   1311       1.1  christos   EMPTY_HOWTO (216),
   1312       1.1  christos   EMPTY_HOWTO (217),
   1313       1.1  christos   EMPTY_HOWTO (218),
   1314       1.1  christos   EMPTY_HOWTO (219),
   1315       1.1  christos   EMPTY_HOWTO (220),
   1316       1.1  christos   EMPTY_HOWTO (221),
   1317       1.1  christos   EMPTY_HOWTO (222),
   1318       1.1  christos   EMPTY_HOWTO (223),
   1319       1.1  christos   EMPTY_HOWTO (224),
   1320       1.1  christos   EMPTY_HOWTO (225),
   1321       1.1  christos   EMPTY_HOWTO (226),
   1322       1.1  christos   EMPTY_HOWTO (227),
   1323       1.1  christos   EMPTY_HOWTO (228),
   1324       1.1  christos   EMPTY_HOWTO (229),
   1325       1.1  christos   EMPTY_HOWTO (230),
   1326       1.1  christos   EMPTY_HOWTO (231),
   1327       1.1  christos   EMPTY_HOWTO (232),
   1328       1.1  christos   EMPTY_HOWTO (233),
   1329       1.1  christos   EMPTY_HOWTO (234),
   1330       1.1  christos   EMPTY_HOWTO (235),
   1331       1.1  christos   EMPTY_HOWTO (236),
   1332       1.1  christos   EMPTY_HOWTO (237),
   1333       1.1  christos   EMPTY_HOWTO (238),
   1334       1.1  christos   EMPTY_HOWTO (239),
   1335       1.1  christos   EMPTY_HOWTO (240),
   1336       1.1  christos   EMPTY_HOWTO (241),
   1337       1.1  christos   EMPTY_HOWTO (242),
   1338       1.1  christos   EMPTY_HOWTO (243),
   1339       1.1  christos   EMPTY_HOWTO (244),
   1340       1.1  christos   EMPTY_HOWTO (245),
   1341       1.1  christos   EMPTY_HOWTO (246),
   1342       1.1  christos   EMPTY_HOWTO (247),
   1343       1.1  christos   EMPTY_HOWTO (248),
   1344       1.1  christos   EMPTY_HOWTO (249),
   1345       1.1  christos   EMPTY_HOWTO (250),
   1346       1.1  christos   EMPTY_HOWTO (251),
   1347       1.1  christos   EMPTY_HOWTO (252),
   1348       1.1  christos   HOWTO (R_C6000_ALIGN,		/* type */
   1349       1.1  christos 	 0,			/* rightshift */
   1350   1.1.1.8  christos 	 0,			/* size */
   1351       1.1  christos 	 0,			/* bitsize */
   1352   1.1.1.8  christos 	 false,			/* pc_relative */
   1353       1.1  christos 	 0,			/* bitpos */
   1354       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
   1355       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1356       1.1  christos 	 "R_C6000_ALIGN",	/* name */
   1357   1.1.1.8  christos 	 true,			/* partial_inplace */
   1358       1.1  christos 	 0,			/* src_mask */
   1359       1.1  christos 	 0,			/* dst_mask */
   1360   1.1.1.8  christos 	 false),		/* pcrel_offset */
   1361       1.1  christos   HOWTO (R_C6000_FPHEAD,	/* type */
   1362       1.1  christos 	 0,			/* rightshift */
   1363   1.1.1.8  christos 	 0,			/* size */
   1364       1.1  christos 	 0,			/* bitsize */
   1365   1.1.1.8  christos 	 false,			/* pc_relative */
   1366       1.1  christos 	 0,			/* bitpos */
   1367       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
   1368       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1369       1.1  christos 	 "R_C6000_FPHEAD",	/* name */
   1370   1.1.1.8  christos 	 true,			/* partial_inplace */
   1371       1.1  christos 	 0,			/* src_mask */
   1372       1.1  christos 	 0,			/* dst_mask */
   1373   1.1.1.8  christos 	 false),		/* pcrel_offset */
   1374       1.1  christos   HOWTO (R_C6000_NOCMP,		/* type */
   1375       1.1  christos 	 0,			/* rightshift */
   1376   1.1.1.8  christos 	 0,			/* size */
   1377       1.1  christos 	 0,			/* bitsize */
   1378   1.1.1.8  christos 	 false,			/* pc_relative */
   1379       1.1  christos 	 0,			/* bitpos */
   1380       1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
   1381       1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
   1382       1.1  christos 	 "R_C6000_NOCMP",	/* name */
   1383   1.1.1.8  christos 	 true,			/* partial_inplace */
   1384       1.1  christos 	 0,			/* src_mask */
   1385       1.1  christos 	 0,			/* dst_mask */
   1386   1.1.1.8  christos 	 false)			/* pcrel_offset */
   1387       1.1  christos };
   1388       1.1  christos 
   1389       1.1  christos /* Map BFD relocations to ELF relocations.  */
   1390       1.1  christos 
   1391       1.1  christos typedef struct
   1392       1.1  christos {
   1393       1.1  christos   bfd_reloc_code_real_type bfd_reloc_val;
   1394       1.1  christos   enum elf_tic6x_reloc_type elf_reloc_val;
   1395       1.1  christos } tic6x_reloc_map;
   1396       1.1  christos 
   1397       1.1  christos static const tic6x_reloc_map elf32_tic6x_reloc_map[] =
   1398       1.1  christos   {
   1399       1.1  christos     { BFD_RELOC_NONE, R_C6000_NONE },
   1400       1.1  christos     { BFD_RELOC_32, R_C6000_ABS32 },
   1401       1.1  christos     { BFD_RELOC_16, R_C6000_ABS16 },
   1402       1.1  christos     { BFD_RELOC_8, R_C6000_ABS8 },
   1403       1.1  christos     { BFD_RELOC_C6000_PCR_S21, R_C6000_PCR_S21 },
   1404       1.1  christos     { BFD_RELOC_C6000_PCR_S12, R_C6000_PCR_S12 },
   1405       1.1  christos     { BFD_RELOC_C6000_PCR_S10, R_C6000_PCR_S10 },
   1406       1.1  christos     { BFD_RELOC_C6000_PCR_S7, R_C6000_PCR_S7 },
   1407       1.1  christos     { BFD_RELOC_C6000_ABS_S16, R_C6000_ABS_S16 },
   1408       1.1  christos     { BFD_RELOC_C6000_ABS_L16, R_C6000_ABS_L16 },
   1409       1.1  christos     { BFD_RELOC_C6000_ABS_H16, R_C6000_ABS_H16 },
   1410       1.1  christos     { BFD_RELOC_C6000_SBR_U15_B, R_C6000_SBR_U15_B },
   1411       1.1  christos     { BFD_RELOC_C6000_SBR_U15_H, R_C6000_SBR_U15_H },
   1412       1.1  christos     { BFD_RELOC_C6000_SBR_U15_W, R_C6000_SBR_U15_W },
   1413       1.1  christos     { BFD_RELOC_C6000_SBR_S16, R_C6000_SBR_S16 },
   1414       1.1  christos     { BFD_RELOC_C6000_SBR_L16_B, R_C6000_SBR_L16_B },
   1415       1.1  christos     { BFD_RELOC_C6000_SBR_L16_H, R_C6000_SBR_L16_H },
   1416       1.1  christos     { BFD_RELOC_C6000_SBR_L16_W, R_C6000_SBR_L16_W },
   1417       1.1  christos     { BFD_RELOC_C6000_SBR_H16_B, R_C6000_SBR_H16_B },
   1418       1.1  christos     { BFD_RELOC_C6000_SBR_H16_H, R_C6000_SBR_H16_H },
   1419       1.1  christos     { BFD_RELOC_C6000_SBR_H16_W, R_C6000_SBR_H16_W },
   1420       1.1  christos     { BFD_RELOC_C6000_SBR_GOT_U15_W, R_C6000_SBR_GOT_U15_W },
   1421       1.1  christos     { BFD_RELOC_C6000_SBR_GOT_L16_W, R_C6000_SBR_GOT_L16_W },
   1422       1.1  christos     { BFD_RELOC_C6000_SBR_GOT_H16_W, R_C6000_SBR_GOT_H16_W },
   1423       1.1  christos     { BFD_RELOC_C6000_DSBT_INDEX, R_C6000_DSBT_INDEX },
   1424       1.1  christos     { BFD_RELOC_C6000_PREL31, R_C6000_PREL31 },
   1425  1.1.1.11  christos     { BFD_RELOC_COPY, R_C6000_COPY },
   1426  1.1.1.11  christos     { BFD_RELOC_JMP_SLOT, R_C6000_JUMP_SLOT },
   1427   1.1.1.2  christos     { BFD_RELOC_C6000_EHTYPE, R_C6000_EHTYPE },
   1428   1.1.1.2  christos     { BFD_RELOC_C6000_PCR_H16, R_C6000_PCR_H16 },
   1429   1.1.1.2  christos     { BFD_RELOC_C6000_PCR_L16, R_C6000_PCR_L16 },
   1430       1.1  christos     { BFD_RELOC_C6000_ALIGN, R_C6000_ALIGN },
   1431       1.1  christos     { BFD_RELOC_C6000_FPHEAD, R_C6000_FPHEAD },
   1432       1.1  christos     { BFD_RELOC_C6000_NOCMP, R_C6000_NOCMP }
   1433       1.1  christos   };
   1434       1.1  christos 
   1435       1.1  christos static reloc_howto_type *
   1436       1.1  christos elf32_tic6x_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
   1437       1.1  christos {
   1438       1.1  christos   unsigned int i;
   1439       1.1  christos 
   1440       1.1  christos   for (i = 0; i < ARRAY_SIZE (elf32_tic6x_reloc_map); i++)
   1441       1.1  christos     if (elf32_tic6x_reloc_map[i].bfd_reloc_val == code)
   1442       1.1  christos       {
   1443       1.1  christos 	enum elf_tic6x_reloc_type elf_reloc_val;
   1444       1.1  christos 	reloc_howto_type *howto;
   1445       1.1  christos 
   1446       1.1  christos 	elf_reloc_val = elf32_tic6x_reloc_map[i].elf_reloc_val;
   1447       1.1  christos 	if (elf32_tic6x_tdata (abfd)->use_rela_p)
   1448       1.1  christos 	  howto = &elf32_tic6x_howto_table[elf_reloc_val];
   1449       1.1  christos 	else
   1450       1.1  christos 	  howto = &elf32_tic6x_howto_table_rel[elf_reloc_val];
   1451       1.1  christos 
   1452       1.1  christos 	/* Some relocations are RELA-only; do not return them for
   1453       1.1  christos 	   REL.  */
   1454       1.1  christos 	if (howto->name == NULL)
   1455       1.1  christos 	  howto = NULL;
   1456       1.1  christos 
   1457       1.1  christos 	return howto;
   1458       1.1  christos       }
   1459       1.1  christos 
   1460       1.1  christos   return NULL;
   1461       1.1  christos }
   1462       1.1  christos 
   1463       1.1  christos static reloc_howto_type *
   1464       1.1  christos elf32_tic6x_reloc_name_lookup (bfd *abfd, const char *r_name)
   1465       1.1  christos {
   1466       1.1  christos   if (elf32_tic6x_tdata (abfd)->use_rela_p)
   1467       1.1  christos     {
   1468       1.1  christos       unsigned int i;
   1469       1.1  christos 
   1470       1.1  christos       for (i = 0; i < ARRAY_SIZE (elf32_tic6x_howto_table); i++)
   1471       1.1  christos 	if (elf32_tic6x_howto_table[i].name != NULL
   1472       1.1  christos 	    && strcasecmp (elf32_tic6x_howto_table[i].name, r_name) == 0)
   1473       1.1  christos 	  return &elf32_tic6x_howto_table[i];
   1474       1.1  christos     }
   1475       1.1  christos   else
   1476       1.1  christos     {
   1477       1.1  christos       unsigned int i;
   1478       1.1  christos 
   1479       1.1  christos       for (i = 0; i < ARRAY_SIZE (elf32_tic6x_howto_table_rel); i++)
   1480       1.1  christos 	if (elf32_tic6x_howto_table_rel[i].name != NULL
   1481       1.1  christos 	    && strcasecmp (elf32_tic6x_howto_table_rel[i].name, r_name) == 0)
   1482       1.1  christos 	  return &elf32_tic6x_howto_table_rel[i];
   1483       1.1  christos     }
   1484       1.1  christos 
   1485       1.1  christos   return NULL;
   1486       1.1  christos }
   1487       1.1  christos 
   1488   1.1.1.8  christos static bool
   1489       1.1  christos elf32_tic6x_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
   1490       1.1  christos 			   Elf_Internal_Rela *elf_reloc)
   1491       1.1  christos {
   1492       1.1  christos   unsigned int r_type;
   1493       1.1  christos 
   1494       1.1  christos   r_type = ELF32_R_TYPE (elf_reloc->r_info);
   1495       1.1  christos   if (r_type >= ARRAY_SIZE (elf32_tic6x_howto_table))
   1496   1.1.1.6  christos     {
   1497   1.1.1.6  christos       /* xgettext:c-format */
   1498   1.1.1.6  christos       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
   1499   1.1.1.6  christos 			  abfd, r_type);
   1500   1.1.1.6  christos       bfd_set_error (bfd_error_bad_value);
   1501   1.1.1.8  christos       return false;
   1502   1.1.1.6  christos     }
   1503   1.1.1.6  christos 
   1504   1.1.1.6  christos   bfd_reloc->howto = &elf32_tic6x_howto_table[r_type];
   1505   1.1.1.6  christos   if (bfd_reloc->howto == NULL || bfd_reloc->howto->name == NULL)
   1506   1.1.1.6  christos     {
   1507   1.1.1.6  christos       /* xgettext:c-format */
   1508   1.1.1.6  christos       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
   1509   1.1.1.6  christos 			  abfd, r_type);
   1510   1.1.1.6  christos       bfd_set_error (bfd_error_bad_value);
   1511   1.1.1.8  christos       return false;
   1512   1.1.1.6  christos     }
   1513   1.1.1.6  christos 
   1514   1.1.1.8  christos   return true;
   1515       1.1  christos }
   1516       1.1  christos 
   1517   1.1.1.8  christos static bool
   1518       1.1  christos elf32_tic6x_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
   1519       1.1  christos 			       Elf_Internal_Rela *elf_reloc)
   1520       1.1  christos {
   1521       1.1  christos   unsigned int r_type;
   1522       1.1  christos 
   1523       1.1  christos   r_type = ELF32_R_TYPE (elf_reloc->r_info);
   1524       1.1  christos   if (r_type >= ARRAY_SIZE (elf32_tic6x_howto_table_rel))
   1525   1.1.1.6  christos     {
   1526   1.1.1.6  christos       /* xgettext:c-format */
   1527   1.1.1.6  christos       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
   1528   1.1.1.6  christos 			  abfd, r_type);
   1529   1.1.1.6  christos       bfd_set_error (bfd_error_bad_value);
   1530   1.1.1.8  christos       return false;
   1531   1.1.1.6  christos     }
   1532   1.1.1.6  christos 
   1533   1.1.1.6  christos   bfd_reloc->howto = &elf32_tic6x_howto_table_rel[r_type];
   1534   1.1.1.6  christos   if (bfd_reloc->howto == NULL || bfd_reloc->howto->name == NULL)
   1535   1.1.1.6  christos     {
   1536   1.1.1.6  christos       /* xgettext:c-format */
   1537   1.1.1.6  christos       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
   1538   1.1.1.6  christos 			  abfd, r_type);
   1539   1.1.1.6  christos       bfd_set_error (bfd_error_bad_value);
   1540   1.1.1.8  christos       return false;
   1541   1.1.1.6  christos     }
   1542   1.1.1.6  christos 
   1543   1.1.1.8  christos   return true;
   1544       1.1  christos }
   1545       1.1  christos 
   1546       1.1  christos void
   1547   1.1.1.8  christos elf32_tic6x_set_use_rela_p (bfd *abfd, bool use_rela_p)
   1548       1.1  christos {
   1549       1.1  christos   elf32_tic6x_tdata (abfd)->use_rela_p = use_rela_p;
   1550       1.1  christos }
   1551       1.1  christos 
   1552   1.1.1.2  christos /* Create a C6X ELF linker hash table.  */
   1553   1.1.1.2  christos 
   1554   1.1.1.2  christos static struct bfd_link_hash_table *
   1555   1.1.1.2  christos elf32_tic6x_link_hash_table_create (bfd *abfd)
   1556   1.1.1.2  christos {
   1557   1.1.1.2  christos   struct elf32_tic6x_link_hash_table *ret;
   1558   1.1.1.8  christos   size_t amt = sizeof (struct elf32_tic6x_link_hash_table);
   1559   1.1.1.2  christos 
   1560   1.1.1.3  christos   ret = bfd_zmalloc (amt);
   1561   1.1.1.2  christos   if (ret == NULL)
   1562   1.1.1.2  christos     return NULL;
   1563   1.1.1.2  christos 
   1564   1.1.1.2  christos   if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
   1565   1.1.1.8  christos 				      _bfd_elf_link_hash_newfunc,
   1566  1.1.1.10  christos 				      sizeof (struct elf_link_hash_entry)))
   1567   1.1.1.2  christos     {
   1568   1.1.1.2  christos       free (ret);
   1569   1.1.1.2  christos       return NULL;
   1570   1.1.1.2  christos     }
   1571   1.1.1.2  christos 
   1572   1.1.1.2  christos   ret->obfd = abfd;
   1573   1.1.1.2  christos   ret->elf.is_relocatable_executable = 1;
   1574   1.1.1.2  christos 
   1575   1.1.1.2  christos   return &ret->elf.root;
   1576       1.1  christos }
   1577       1.1  christos 
   1578   1.1.1.8  christos static bool
   1579   1.1.1.2  christos elf32_tic6x_final_link (bfd *abfd, struct bfd_link_info *info)
   1580       1.1  christos {
   1581   1.1.1.3  christos   if (bfd_link_pic (info))
   1582   1.1.1.2  christos     {
   1583   1.1.1.2  christos       obj_attribute *out_attr;
   1584   1.1.1.2  christos       out_attr = elf_known_obj_attributes_proc (abfd);
   1585   1.1.1.2  christos       if (out_attr[Tag_ABI_PIC].i == 0)
   1586   1.1.1.2  christos 	{
   1587   1.1.1.2  christos 	  _bfd_error_handler (_("warning: generating a shared library "
   1588   1.1.1.2  christos 				"containing non-PIC code"));
   1589   1.1.1.2  christos 	}
   1590   1.1.1.2  christos       if (out_attr[Tag_ABI_PID].i == 0)
   1591   1.1.1.2  christos 	{
   1592   1.1.1.2  christos 	  _bfd_error_handler (_("warning: generating a shared library "
   1593   1.1.1.2  christos 				"containing non-PID code"));
   1594   1.1.1.2  christos 	}
   1595   1.1.1.2  christos     }
   1596   1.1.1.2  christos   /* Invoke the regular ELF backend linker to do all the work.  */
   1597  1.1.1.11  christos   return _bfd_elf_final_link (abfd, info);
   1598   1.1.1.2  christos }
   1599       1.1  christos 
   1600   1.1.1.2  christos /* Called to pass PARAMS to the backend.  We store them in the hash table
   1601   1.1.1.2  christos    associated with INFO.  */
   1602   1.1.1.2  christos 
   1603   1.1.1.2  christos void
   1604   1.1.1.2  christos elf32_tic6x_setup (struct bfd_link_info *info,
   1605   1.1.1.2  christos 		   struct elf32_tic6x_params *params)
   1606   1.1.1.2  christos {
   1607   1.1.1.2  christos   struct elf32_tic6x_link_hash_table *htab = elf32_tic6x_hash_table (info);
   1608   1.1.1.2  christos   htab->params = *params;
   1609   1.1.1.2  christos }
   1610   1.1.1.2  christos 
   1611   1.1.1.2  christos /* Determine if we're dealing with a DSBT object.  */
   1612       1.1  christos 
   1613   1.1.1.8  christos static bool
   1614   1.1.1.2  christos elf32_tic6x_using_dsbt (bfd *abfd)
   1615       1.1  christos {
   1616   1.1.1.2  christos   return bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC,
   1617   1.1.1.2  christos 				   Tag_ABI_DSBT);
   1618   1.1.1.2  christos }
   1619       1.1  christos 
   1620   1.1.1.2  christos /* Create .plt, .rela.plt, .got, .got.plt, .rela.got and .dsbt
   1621   1.1.1.2  christos    sections in DYNOBJ, and set up shortcuts to them in our hash
   1622   1.1.1.2  christos    table.  */
   1623   1.1.1.2  christos 
   1624   1.1.1.8  christos static bool
   1625   1.1.1.2  christos elf32_tic6x_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
   1626   1.1.1.2  christos {
   1627   1.1.1.2  christos   struct elf32_tic6x_link_hash_table *htab;
   1628   1.1.1.2  christos   flagword flags;
   1629   1.1.1.2  christos 
   1630   1.1.1.2  christos   htab = elf32_tic6x_hash_table (info);
   1631   1.1.1.2  christos   if (htab == NULL)
   1632   1.1.1.8  christos     return false;
   1633   1.1.1.2  christos 
   1634   1.1.1.2  christos   if (!_bfd_elf_create_dynamic_sections (dynobj, info))
   1635   1.1.1.8  christos     return false;
   1636   1.1.1.2  christos 
   1637   1.1.1.2  christos   /* Create .dsbt  */
   1638   1.1.1.2  christos   flags = (SEC_ALLOC | SEC_LOAD
   1639   1.1.1.2  christos 	   | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   1640   1.1.1.2  christos   htab->dsbt = bfd_make_section_anyway_with_flags (dynobj, ".dsbt",
   1641   1.1.1.2  christos 						   flags);
   1642   1.1.1.2  christos   if (htab->dsbt == NULL
   1643   1.1.1.7  christos       || !bfd_set_section_alignment (htab->dsbt, 2)
   1644   1.1.1.7  christos       || !bfd_set_section_alignment (htab->elf.splt, 5))
   1645   1.1.1.8  christos     return false;
   1646   1.1.1.2  christos 
   1647   1.1.1.8  christos   return true;
   1648       1.1  christos }
   1649       1.1  christos 
   1650   1.1.1.8  christos static bool
   1651   1.1.1.2  christos elf32_tic6x_mkobject (bfd *abfd)
   1652       1.1  christos {
   1653   1.1.1.8  christos   bool ret;
   1654       1.1  christos 
   1655  1.1.1.10  christos   ret = bfd_elf_allocate_object (abfd, sizeof (struct elf32_tic6x_obj_tdata));
   1656   1.1.1.2  christos   if (ret)
   1657   1.1.1.8  christos     elf32_tic6x_set_use_rela_p (abfd, true);
   1658   1.1.1.2  christos   return ret;
   1659   1.1.1.2  christos }
   1660       1.1  christos 
   1661   1.1.1.2  christos /* Install relocation RELA into section SRELA, incrementing its
   1662   1.1.1.2  christos    reloc_count.  */
   1663       1.1  christos 
   1664   1.1.1.2  christos static void
   1665   1.1.1.2  christos elf32_tic6x_install_rela (bfd *output_bfd, asection *srela,
   1666   1.1.1.2  christos 			  Elf_Internal_Rela *rela)
   1667   1.1.1.2  christos {
   1668   1.1.1.2  christos   bfd_byte *loc;
   1669   1.1.1.2  christos   bfd_vma off = srela->reloc_count++ * sizeof (Elf32_External_Rela);
   1670   1.1.1.2  christos   loc = srela->contents + off;
   1671   1.1.1.2  christos   BFD_ASSERT (off < srela->size);
   1672   1.1.1.2  christos   bfd_elf32_swap_reloca_out (output_bfd, rela, loc);
   1673   1.1.1.2  christos }
   1674   1.1.1.2  christos 
   1675   1.1.1.2  christos /* Create a dynamic reloc against the GOT at offset OFFSET.  The contents
   1676   1.1.1.2  christos    of the GOT at this offset have been initialized with the relocation.  */
   1677   1.1.1.2  christos 
   1678   1.1.1.2  christos static void
   1679   1.1.1.2  christos elf32_tic6x_make_got_dynreloc (bfd *output_bfd,
   1680   1.1.1.2  christos 			       struct elf32_tic6x_link_hash_table *htab,
   1681   1.1.1.2  christos 			       asection *sym_sec, bfd_vma offset)
   1682   1.1.1.2  christos {
   1683   1.1.1.2  christos   asection *sgot = htab->elf.sgot;
   1684   1.1.1.2  christos   Elf_Internal_Rela outrel;
   1685   1.1.1.2  christos   int dynindx;
   1686   1.1.1.2  christos 
   1687   1.1.1.2  christos   outrel.r_offset = sgot->output_section->vma + sgot->output_offset + offset;
   1688   1.1.1.2  christos   outrel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
   1689   1.1.1.2  christos   if (sym_sec && sym_sec->output_section
   1690   1.1.1.2  christos       && ! bfd_is_abs_section (sym_sec->output_section)
   1691   1.1.1.2  christos       && ! bfd_is_und_section (sym_sec->output_section))
   1692       1.1  christos     {
   1693   1.1.1.2  christos       dynindx = elf_section_data (sym_sec->output_section)->dynindx;
   1694   1.1.1.2  christos       outrel.r_addend -= sym_sec->output_section->vma;
   1695   1.1.1.2  christos     }
   1696   1.1.1.2  christos   else
   1697   1.1.1.2  christos     {
   1698   1.1.1.2  christos       dynindx = 0;
   1699   1.1.1.2  christos     }
   1700   1.1.1.2  christos   outrel.r_info = ELF32_R_INFO (dynindx, R_C6000_ABS32);
   1701   1.1.1.2  christos   elf32_tic6x_install_rela (output_bfd, htab->elf.srelgot, &outrel);
   1702   1.1.1.2  christos }
   1703       1.1  christos 
   1704   1.1.1.2  christos /* Finish up dynamic symbol handling.  We set the contents of various
   1705   1.1.1.2  christos    dynamic sections here.  */
   1706       1.1  christos 
   1707   1.1.1.8  christos static bool
   1708   1.1.1.2  christos elf32_tic6x_finish_dynamic_symbol (bfd * output_bfd,
   1709   1.1.1.2  christos 				   struct bfd_link_info *info,
   1710   1.1.1.2  christos 				   struct elf_link_hash_entry *h,
   1711   1.1.1.2  christos 				   Elf_Internal_Sym * sym)
   1712   1.1.1.2  christos {
   1713   1.1.1.2  christos   struct elf32_tic6x_link_hash_table *htab;
   1714       1.1  christos 
   1715   1.1.1.2  christos   htab = elf32_tic6x_hash_table (info);
   1716   1.1.1.2  christos 
   1717   1.1.1.2  christos   if (h->plt.offset != (bfd_vma) -1)
   1718   1.1.1.2  christos     {
   1719   1.1.1.2  christos       bfd_vma plt_index;
   1720   1.1.1.2  christos       bfd_vma got_section_offset, got_dp_offset, rela_offset;
   1721   1.1.1.2  christos       Elf_Internal_Rela rela;
   1722   1.1.1.2  christos       bfd_byte *loc;
   1723   1.1.1.2  christos       asection *plt, *gotplt, *relplt;
   1724  1.1.1.11  christos       elf_backend_data *bed;
   1725   1.1.1.2  christos 
   1726   1.1.1.2  christos       bed = get_elf_backend_data (output_bfd);
   1727   1.1.1.2  christos 
   1728   1.1.1.2  christos       BFD_ASSERT (htab->elf.splt != NULL);
   1729   1.1.1.2  christos       plt = htab->elf.splt;
   1730   1.1.1.2  christos       gotplt = htab->elf.sgotplt;
   1731   1.1.1.2  christos       relplt = htab->elf.srelplt;
   1732   1.1.1.2  christos 
   1733   1.1.1.2  christos       /* This symbol has an entry in the procedure linkage table.  Set
   1734   1.1.1.2  christos 	 it up.  */
   1735   1.1.1.2  christos 
   1736   1.1.1.2  christos       if ((h->dynindx == -1
   1737   1.1.1.3  christos 	   && !((h->forced_local || bfd_link_executable (info))
   1738   1.1.1.2  christos 		&& h->def_regular
   1739   1.1.1.2  christos 		&& h->type == STT_GNU_IFUNC))
   1740   1.1.1.2  christos 	  || plt == NULL
   1741   1.1.1.2  christos 	  || gotplt == NULL
   1742   1.1.1.2  christos 	  || relplt == NULL)
   1743   1.1.1.2  christos 	abort ();
   1744   1.1.1.2  christos 
   1745   1.1.1.2  christos       /* Get the index in the procedure linkage table which
   1746   1.1.1.2  christos 	 corresponds to this symbol.  This is the index of this symbol
   1747   1.1.1.2  christos 	 in all the symbols for which we are making plt entries.  The
   1748   1.1.1.2  christos 	 first entry in the procedure linkage table is reserved.
   1749   1.1.1.2  christos 
   1750   1.1.1.2  christos 	 Get the offset into the .got table of the entry that
   1751   1.1.1.2  christos 	 corresponds to this function.  Each .got entry is 4 bytes.
   1752   1.1.1.2  christos 	 The first three are reserved.
   1753   1.1.1.3  christos 
   1754   1.1.1.2  christos 	 For static executables, we don't reserve anything.  */
   1755   1.1.1.2  christos 
   1756   1.1.1.2  christos       plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
   1757   1.1.1.2  christos       got_section_offset = plt_index + bed->got_header_size / 4;
   1758   1.1.1.2  christos       got_dp_offset = got_section_offset + htab->params.dsbt_size;
   1759   1.1.1.2  christos       rela_offset = plt_index * sizeof (Elf32_External_Rela);
   1760   1.1.1.2  christos 
   1761   1.1.1.2  christos       got_section_offset *= 4;
   1762   1.1.1.2  christos 
   1763   1.1.1.2  christos       /* Fill in the entry in the procedure linkage table.  */
   1764   1.1.1.2  christos 
   1765   1.1.1.2  christos       /* ldw .d2t2 *+B14($GOT(f)), b2 */
   1766   1.1.1.2  christos       bfd_put_32 (output_bfd, got_dp_offset << 8 | 0x0100006e,
   1767   1.1.1.2  christos 		  plt->contents + h->plt.offset);
   1768   1.1.1.2  christos       /* mvk .s2 low(rela_offset), b0 */
   1769   1.1.1.2  christos       bfd_put_32 (output_bfd, (rela_offset & 0xffff) << 7 | 0x0000002a,
   1770   1.1.1.2  christos 		  plt->contents + h->plt.offset + 4);
   1771   1.1.1.2  christos       /* mvkh .s2 high(rela_offset), b0 */
   1772   1.1.1.2  christos       bfd_put_32 (output_bfd, ((rela_offset >> 16) & 0xffff) << 7 | 0x0000006a,
   1773   1.1.1.2  christos 		  plt->contents + h->plt.offset + 8);
   1774   1.1.1.2  christos       /* nop 2 */
   1775   1.1.1.2  christos       bfd_put_32 (output_bfd, 0x00002000,
   1776   1.1.1.2  christos 		  plt->contents + h->plt.offset + 12);
   1777   1.1.1.2  christos       /* b .s2 b2 */
   1778   1.1.1.2  christos       bfd_put_32 (output_bfd, 0x00080362,
   1779   1.1.1.2  christos 		  plt->contents + h->plt.offset + 16);
   1780   1.1.1.2  christos       /* nop 5 */
   1781   1.1.1.2  christos       bfd_put_32 (output_bfd, 0x00008000,
   1782   1.1.1.2  christos 		  plt->contents + h->plt.offset + 20);
   1783   1.1.1.2  christos 
   1784   1.1.1.2  christos       /* Fill in the entry in the global offset table.  */
   1785   1.1.1.2  christos       bfd_put_32 (output_bfd,
   1786   1.1.1.2  christos 		  (plt->output_section->vma + plt->output_offset),
   1787   1.1.1.2  christos 		  gotplt->contents + got_section_offset);
   1788   1.1.1.2  christos 
   1789   1.1.1.2  christos       /* Fill in the entry in the .rel.plt section.  */
   1790   1.1.1.2  christos       rela.r_offset = (gotplt->output_section->vma
   1791   1.1.1.2  christos 		       + gotplt->output_offset
   1792   1.1.1.2  christos 		       + got_section_offset);
   1793   1.1.1.2  christos       rela.r_info = ELF32_R_INFO (h->dynindx, R_C6000_JUMP_SLOT);
   1794   1.1.1.2  christos       rela.r_addend = 0;
   1795   1.1.1.2  christos       loc = relplt->contents + rela_offset;
   1796   1.1.1.2  christos       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   1797   1.1.1.2  christos 
   1798   1.1.1.2  christos       if (!h->def_regular)
   1799       1.1  christos 	{
   1800   1.1.1.2  christos 	  /* Mark the symbol as undefined, rather than as defined in
   1801   1.1.1.2  christos 	     the .plt section.  */
   1802   1.1.1.2  christos 	  sym->st_shndx = SHN_UNDEF;
   1803   1.1.1.2  christos 	  sym->st_value = 0;
   1804       1.1  christos 	}
   1805   1.1.1.2  christos     }
   1806       1.1  christos 
   1807   1.1.1.2  christos   if (h->got.offset != (bfd_vma) -1)
   1808   1.1.1.2  christos     {
   1809   1.1.1.2  christos       asection *sgot;
   1810   1.1.1.2  christos       asection *srela;
   1811       1.1  christos 
   1812   1.1.1.2  christos       /* This symbol has an entry in the global offset table.
   1813   1.1.1.5  christos 	 Set it up.  */
   1814   1.1.1.2  christos 
   1815   1.1.1.5  christos       sgot = htab->elf.sgot;
   1816   1.1.1.5  christos       srela = htab->elf.srelgot;
   1817   1.1.1.2  christos       BFD_ASSERT (sgot != NULL && srela != NULL);
   1818   1.1.1.2  christos 
   1819   1.1.1.2  christos       /* If this is a -Bsymbolic link, and the symbol is defined
   1820   1.1.1.5  christos 	 locally, we just want to emit a RELATIVE reloc.  Likewise if
   1821   1.1.1.5  christos 	 the symbol was forced to be local because of a version file.
   1822   1.1.1.5  christos 	 The entry in the global offset table will already have been
   1823   1.1.1.5  christos 	 initialized in the relocate_section function.  */
   1824   1.1.1.3  christos       if (bfd_link_pic (info)
   1825   1.1.1.3  christos 	  && (SYMBOLIC_BIND (info, h)
   1826   1.1.1.2  christos 	      || h->dynindx == -1 || h->forced_local) && h->def_regular)
   1827       1.1  christos 	{
   1828   1.1.1.2  christos 	  asection *s = h->root.u.def.section;
   1829   1.1.1.2  christos 	  elf32_tic6x_make_got_dynreloc (output_bfd, htab, s,
   1830   1.1.1.2  christos 			     h->got.offset & ~(bfd_vma) 1);
   1831   1.1.1.2  christos 	}
   1832   1.1.1.2  christos       else
   1833   1.1.1.2  christos 	{
   1834   1.1.1.2  christos 	  Elf_Internal_Rela outrel;
   1835   1.1.1.2  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0,
   1836   1.1.1.2  christos 		      sgot->contents + (h->got.offset & ~(bfd_vma) 1));
   1837   1.1.1.2  christos 	  outrel.r_offset = (sgot->output_section->vma
   1838   1.1.1.2  christos 			   + sgot->output_offset
   1839   1.1.1.2  christos 			   + (h->got.offset & ~(bfd_vma) 1));
   1840   1.1.1.2  christos 	  outrel.r_info = ELF32_R_INFO (h->dynindx, R_C6000_ABS32);
   1841   1.1.1.2  christos 	  outrel.r_addend = 0;
   1842   1.1.1.2  christos 
   1843   1.1.1.2  christos 	  elf32_tic6x_install_rela (output_bfd, srela, &outrel);
   1844   1.1.1.2  christos 	}
   1845   1.1.1.2  christos     }
   1846   1.1.1.2  christos 
   1847   1.1.1.2  christos   if (h->needs_copy)
   1848   1.1.1.2  christos     {
   1849   1.1.1.2  christos       Elf_Internal_Rela rel;
   1850   1.1.1.5  christos       asection *s;
   1851   1.1.1.2  christos 
   1852   1.1.1.2  christos       /* This symbol needs a copy reloc.  Set it up.  */
   1853   1.1.1.2  christos 
   1854   1.1.1.2  christos       if (h->dynindx == -1
   1855   1.1.1.2  christos 	  || (h->root.type != bfd_link_hash_defined
   1856   1.1.1.2  christos 	      && h->root.type != bfd_link_hash_defweak)
   1857   1.1.1.5  christos 	  || htab->elf.srelbss == NULL
   1858   1.1.1.5  christos 	  || htab->elf.sreldynrelro == NULL)
   1859   1.1.1.2  christos 	abort ();
   1860   1.1.1.2  christos 
   1861   1.1.1.2  christos       rel.r_offset = (h->root.u.def.value
   1862   1.1.1.2  christos 		      + h->root.u.def.section->output_section->vma
   1863   1.1.1.2  christos 		      + h->root.u.def.section->output_offset);
   1864   1.1.1.2  christos       rel.r_info = ELF32_R_INFO (h->dynindx, R_C6000_COPY);
   1865   1.1.1.2  christos       rel.r_addend = 0;
   1866   1.1.1.5  christos       if (h->root.u.def.section == htab->elf.sdynrelro)
   1867   1.1.1.5  christos 	s = htab->elf.sreldynrelro;
   1868   1.1.1.5  christos       else
   1869   1.1.1.5  christos 	s = htab->elf.srelbss;
   1870   1.1.1.2  christos 
   1871   1.1.1.5  christos       elf32_tic6x_install_rela (output_bfd, s, &rel);
   1872   1.1.1.2  christos     }
   1873   1.1.1.2  christos 
   1874   1.1.1.2  christos   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
   1875   1.1.1.3  christos   if (h == elf_hash_table (info)->hdynamic
   1876   1.1.1.2  christos       || h == elf_hash_table (info)->hgot)
   1877   1.1.1.2  christos     sym->st_shndx = SHN_ABS;
   1878   1.1.1.2  christos 
   1879   1.1.1.8  christos   return true;
   1880   1.1.1.2  christos }
   1881   1.1.1.2  christos 
   1882   1.1.1.2  christos /* Unwinding tables are not referenced directly.  This pass marks them as
   1883   1.1.1.2  christos    required if the corresponding code section is marked.  */
   1884   1.1.1.2  christos 
   1885   1.1.1.8  christos static bool
   1886   1.1.1.2  christos elf32_tic6x_gc_mark_extra_sections (struct bfd_link_info *info,
   1887   1.1.1.2  christos 				    elf_gc_mark_hook_fn gc_mark_hook)
   1888   1.1.1.2  christos {
   1889   1.1.1.2  christos   bfd *sub;
   1890   1.1.1.2  christos   Elf_Internal_Shdr **elf_shdrp;
   1891   1.1.1.8  christos   bool again;
   1892   1.1.1.2  christos 
   1893   1.1.1.2  christos   _bfd_elf_gc_mark_extra_sections (info, gc_mark_hook);
   1894   1.1.1.2  christos 
   1895   1.1.1.2  christos   /* Marking EH data may cause additional code sections to be marked,
   1896   1.1.1.2  christos      requiring multiple passes.  */
   1897   1.1.1.8  christos   again = true;
   1898   1.1.1.2  christos   while (again)
   1899   1.1.1.2  christos     {
   1900   1.1.1.8  christos       again = false;
   1901   1.1.1.3  christos       for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
   1902   1.1.1.2  christos 	{
   1903   1.1.1.2  christos 	  asection *o;
   1904   1.1.1.2  christos 
   1905   1.1.1.2  christos 	  if (! is_tic6x_elf (sub))
   1906   1.1.1.2  christos 	    continue;
   1907   1.1.1.2  christos 
   1908   1.1.1.2  christos 	  elf_shdrp = elf_elfsections (sub);
   1909   1.1.1.2  christos 	  for (o = sub->sections; o != NULL; o = o->next)
   1910   1.1.1.2  christos 	    {
   1911   1.1.1.2  christos 	      Elf_Internal_Shdr *hdr;
   1912   1.1.1.2  christos 
   1913   1.1.1.2  christos 	      hdr = &elf_section_data (o)->this_hdr;
   1914   1.1.1.2  christos 	      if (hdr->sh_type == SHT_C6000_UNWIND
   1915   1.1.1.2  christos 		  && hdr->sh_link
   1916   1.1.1.2  christos 		  && hdr->sh_link < elf_numsections (sub)
   1917   1.1.1.2  christos 		  && !o->gc_mark
   1918   1.1.1.2  christos 		  && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
   1919   1.1.1.2  christos 		{
   1920   1.1.1.8  christos 		  again = true;
   1921   1.1.1.2  christos 		  if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
   1922   1.1.1.8  christos 		    return false;
   1923   1.1.1.2  christos 		}
   1924   1.1.1.2  christos 	    }
   1925   1.1.1.2  christos 	}
   1926   1.1.1.2  christos     }
   1927   1.1.1.2  christos 
   1928   1.1.1.8  christos   return true;
   1929   1.1.1.2  christos }
   1930   1.1.1.2  christos 
   1931   1.1.1.2  christos /* Return TRUE if this is an unwinding table index.  */
   1932   1.1.1.2  christos 
   1933   1.1.1.8  christos static bool
   1934   1.1.1.2  christos is_tic6x_elf_unwind_section_name (const char *name)
   1935   1.1.1.2  christos {
   1936   1.1.1.8  christos   return (startswith (name, ELF_STRING_C6000_unwind)
   1937   1.1.1.8  christos 	  || startswith (name, ELF_STRING_C6000_unwind_once));
   1938   1.1.1.2  christos }
   1939   1.1.1.2  christos 
   1940   1.1.1.2  christos 
   1941   1.1.1.2  christos /* Set the type and flags for an unwinding index table.  We do this by
   1942   1.1.1.2  christos    the section name, which is a hack, but ought to work.  */
   1943   1.1.1.2  christos 
   1944   1.1.1.8  christos static bool
   1945   1.1.1.2  christos elf32_tic6x_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
   1946   1.1.1.2  christos 			   Elf_Internal_Shdr *hdr, asection *sec)
   1947   1.1.1.2  christos {
   1948   1.1.1.2  christos   const char * name;
   1949   1.1.1.2  christos 
   1950   1.1.1.7  christos   name = bfd_section_name (sec);
   1951   1.1.1.2  christos 
   1952   1.1.1.2  christos   if (is_tic6x_elf_unwind_section_name (name))
   1953   1.1.1.2  christos     {
   1954   1.1.1.2  christos       hdr->sh_type = SHT_C6000_UNWIND;
   1955   1.1.1.2  christos       hdr->sh_flags |= SHF_LINK_ORDER;
   1956   1.1.1.2  christos     }
   1957   1.1.1.2  christos 
   1958   1.1.1.8  christos   return true;
   1959   1.1.1.2  christos }
   1960   1.1.1.2  christos 
   1961   1.1.1.2  christos /* Adjust a symbol defined by a dynamic object and referenced by a
   1962   1.1.1.2  christos    regular object.  The current definition is in some section of the
   1963   1.1.1.2  christos    dynamic object, but we're not including those sections.  We have to
   1964   1.1.1.2  christos    change the definition to something the rest of the link can
   1965   1.1.1.2  christos    understand.  */
   1966   1.1.1.2  christos 
   1967   1.1.1.8  christos static bool
   1968   1.1.1.2  christos elf32_tic6x_adjust_dynamic_symbol (struct bfd_link_info *info,
   1969   1.1.1.2  christos 				   struct elf_link_hash_entry *h)
   1970   1.1.1.2  christos {
   1971   1.1.1.2  christos   struct elf32_tic6x_link_hash_table *htab;
   1972   1.1.1.2  christos   bfd *dynobj;
   1973   1.1.1.5  christos   asection *s, *srel;
   1974   1.1.1.2  christos 
   1975   1.1.1.2  christos   dynobj = elf_hash_table (info)->dynobj;
   1976   1.1.1.2  christos 
   1977   1.1.1.2  christos   /* Make sure we know what is going on here.  */
   1978   1.1.1.2  christos   BFD_ASSERT (dynobj != NULL
   1979   1.1.1.2  christos 	      && (h->needs_plt
   1980   1.1.1.5  christos 		  || h->is_weakalias
   1981   1.1.1.2  christos 		  || (h->def_dynamic && h->ref_regular && !h->def_regular)));
   1982   1.1.1.2  christos 
   1983   1.1.1.2  christos   /* If this is a function, put it in the procedure linkage table.  We
   1984   1.1.1.2  christos      will fill in the contents of the procedure linkage table later,
   1985   1.1.1.2  christos      when we know the address of the .got section.  */
   1986   1.1.1.2  christos   if (h->type == STT_FUNC
   1987   1.1.1.2  christos       || h->needs_plt)
   1988   1.1.1.2  christos     {
   1989   1.1.1.2  christos       if (h->plt.refcount <= 0
   1990   1.1.1.2  christos 	  || SYMBOL_CALLS_LOCAL (info, h)
   1991   1.1.1.2  christos 	  || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
   1992   1.1.1.2  christos 	      && h->root.type == bfd_link_hash_undefweak))
   1993   1.1.1.2  christos 	{
   1994   1.1.1.2  christos 	  /* This case can occur if we saw a PLT32 reloc in an input
   1995   1.1.1.2  christos 	     file, but the symbol was never referred to by a dynamic
   1996   1.1.1.2  christos 	     object, or if all references were garbage collected.  In
   1997   1.1.1.2  christos 	     such a case, we don't actually need to build a procedure
   1998   1.1.1.2  christos 	     linkage table, and we can just do a PC32 reloc instead.  */
   1999   1.1.1.2  christos 	  h->plt.offset = (bfd_vma) -1;
   2000   1.1.1.2  christos 	  h->needs_plt = 0;
   2001   1.1.1.2  christos 	}
   2002   1.1.1.2  christos 
   2003   1.1.1.8  christos       return true;
   2004   1.1.1.2  christos     }
   2005   1.1.1.2  christos 
   2006   1.1.1.2  christos   /* If this is a weak symbol, and there is a real definition, the
   2007   1.1.1.2  christos      processor independent code will have arranged for us to see the
   2008   1.1.1.2  christos      real definition first, and we can just use the same value.  */
   2009   1.1.1.5  christos   if (h->is_weakalias)
   2010   1.1.1.2  christos     {
   2011   1.1.1.5  christos       struct elf_link_hash_entry *def = weakdef (h);
   2012   1.1.1.5  christos       BFD_ASSERT (def->root.type == bfd_link_hash_defined);
   2013   1.1.1.5  christos       h->root.u.def.section = def->root.u.def.section;
   2014   1.1.1.5  christos       h->root.u.def.value = def->root.u.def.value;
   2015   1.1.1.5  christos       h->non_got_ref = def->non_got_ref;
   2016   1.1.1.8  christos       return true;
   2017   1.1.1.2  christos     }
   2018   1.1.1.2  christos 
   2019   1.1.1.2  christos   /* This is a reference to a symbol defined by a dynamic object which
   2020   1.1.1.2  christos      is not a function.  */
   2021   1.1.1.2  christos 
   2022   1.1.1.2  christos   /* If we are creating a shared library, we must presume that the
   2023   1.1.1.2  christos      only references to the symbol are via the global offset table.
   2024   1.1.1.2  christos      For such cases we need not do anything here; the relocations will
   2025   1.1.1.2  christos      be handled correctly by relocate_section.  */
   2026   1.1.1.3  christos   if (bfd_link_pic (info))
   2027   1.1.1.8  christos     return true;
   2028   1.1.1.2  christos 
   2029   1.1.1.2  christos   /* If there are no references to this symbol that do not use the
   2030   1.1.1.2  christos      GOT, we don't need to generate a copy reloc.  */
   2031   1.1.1.2  christos   if (!h->non_got_ref)
   2032   1.1.1.8  christos     return true;
   2033   1.1.1.2  christos 
   2034   1.1.1.2  christos   /* If -z nocopyreloc was given, we won't generate them either.  */
   2035   1.1.1.2  christos   if (info->nocopyreloc)
   2036   1.1.1.2  christos     {
   2037   1.1.1.2  christos       h->non_got_ref = 0;
   2038   1.1.1.8  christos       return true;
   2039   1.1.1.2  christos     }
   2040   1.1.1.2  christos 
   2041   1.1.1.2  christos   htab = elf32_tic6x_hash_table (info);
   2042   1.1.1.2  christos   if (htab == NULL)
   2043   1.1.1.8  christos     return false;
   2044   1.1.1.2  christos 
   2045   1.1.1.2  christos   /* We must allocate the symbol in our .dynbss section, which will
   2046   1.1.1.2  christos      become part of the .bss section of the executable.  There will be
   2047   1.1.1.2  christos      an entry for this symbol in the .dynsym section.  The dynamic
   2048   1.1.1.2  christos      object will contain position independent code, so all references
   2049   1.1.1.2  christos      from the dynamic object to this symbol will go through the global
   2050   1.1.1.2  christos      offset table.  The dynamic linker will use the .dynsym entry to
   2051   1.1.1.2  christos      determine the address it must put in the global offset table, so
   2052   1.1.1.2  christos      both the dynamic object and the regular object will refer to the
   2053   1.1.1.2  christos      same memory location for the variable.  */
   2054   1.1.1.2  christos 
   2055   1.1.1.2  christos   /* We must generate a R_C6000_COPY reloc to tell the dynamic linker to
   2056   1.1.1.2  christos      copy the initial value out of the dynamic object and into the
   2057   1.1.1.2  christos      runtime process image.  */
   2058   1.1.1.5  christos   if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
   2059   1.1.1.5  christos     {
   2060   1.1.1.5  christos       s = htab->elf.sdynrelro;
   2061   1.1.1.5  christos       srel = htab->elf.sreldynrelro;
   2062   1.1.1.5  christos     }
   2063   1.1.1.5  christos   else
   2064   1.1.1.5  christos     {
   2065   1.1.1.5  christos       s = htab->elf.sdynbss;
   2066   1.1.1.5  christos       srel = htab->elf.srelbss;
   2067   1.1.1.5  christos     }
   2068   1.1.1.2  christos   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
   2069   1.1.1.2  christos     {
   2070   1.1.1.5  christos       srel->size += sizeof (Elf32_External_Rela);
   2071   1.1.1.2  christos       h->needs_copy = 1;
   2072   1.1.1.2  christos     }
   2073   1.1.1.2  christos 
   2074   1.1.1.3  christos   return _bfd_elf_adjust_dynamic_copy (info, h, s);
   2075   1.1.1.2  christos }
   2076   1.1.1.2  christos 
   2077   1.1.1.8  christos static bool
   2078   1.1.1.2  christos elf32_tic6x_new_section_hook (bfd *abfd, asection *sec)
   2079   1.1.1.2  christos {
   2080   1.1.1.8  christos   bool ret;
   2081  1.1.1.10  christos   _tic6x_elf_section_data *sdata;
   2082   1.1.1.2  christos 
   2083  1.1.1.10  christos   sdata = bfd_zalloc (abfd, sizeof (*sdata));
   2084  1.1.1.10  christos   if (sdata == NULL)
   2085  1.1.1.10  christos     return false;
   2086  1.1.1.10  christos   sec->used_by_bfd = sdata;
   2087   1.1.1.2  christos 
   2088   1.1.1.2  christos   ret = _bfd_elf_new_section_hook (abfd, sec);
   2089   1.1.1.2  christos   sec->use_rela_p = elf32_tic6x_tdata (abfd)->use_rela_p;
   2090   1.1.1.2  christos 
   2091   1.1.1.2  christos   return ret;
   2092   1.1.1.2  christos }
   2093   1.1.1.2  christos 
   2094   1.1.1.2  christos /* Return true if relocation REL against section SEC is a REL rather
   2095   1.1.1.2  christos    than RELA relocation.  RELOCS is the first relocation in the
   2096   1.1.1.2  christos    section and ABFD is the bfd that contains SEC.  */
   2097   1.1.1.2  christos 
   2098   1.1.1.8  christos static bool
   2099   1.1.1.2  christos elf32_tic6x_rel_relocation_p (bfd *abfd, asection *sec,
   2100   1.1.1.2  christos 			      const Elf_Internal_Rela *relocs,
   2101   1.1.1.2  christos 			      const Elf_Internal_Rela *rel)
   2102   1.1.1.2  christos {
   2103   1.1.1.2  christos   Elf_Internal_Shdr *rel_hdr;
   2104  1.1.1.11  christos   elf_backend_data *bed;
   2105   1.1.1.2  christos 
   2106   1.1.1.2  christos   /* To determine which flavor of relocation this is, we depend on the
   2107   1.1.1.2  christos      fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR.  */
   2108   1.1.1.2  christos   rel_hdr = elf_section_data (sec)->rel.hdr;
   2109   1.1.1.2  christos   if (rel_hdr == NULL)
   2110   1.1.1.8  christos     return false;
   2111   1.1.1.2  christos   bed = get_elf_backend_data (abfd);
   2112   1.1.1.2  christos   return ((size_t) (rel - relocs)
   2113   1.1.1.2  christos 	  < NUM_SHDR_ENTRIES (rel_hdr) * bed->s->int_rels_per_ext_rel);
   2114   1.1.1.2  christos }
   2115   1.1.1.2  christos 
   2116   1.1.1.2  christos /* We need dynamic symbols for every section, since segments can
   2117   1.1.1.2  christos    relocate independently.  */
   2118   1.1.1.8  christos static bool
   2119   1.1.1.2  christos elf32_tic6x_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
   2120   1.1.1.2  christos 				      struct bfd_link_info *info ATTRIBUTE_UNUSED,
   2121   1.1.1.2  christos 				      asection *p)
   2122   1.1.1.2  christos {
   2123   1.1.1.2  christos   switch (elf_section_data (p)->this_hdr.sh_type)
   2124   1.1.1.2  christos     {
   2125   1.1.1.2  christos     case SHT_PROGBITS:
   2126   1.1.1.2  christos     case SHT_NOBITS:
   2127   1.1.1.2  christos       /* If sh_type is yet undecided, assume it could be
   2128   1.1.1.2  christos 	 SHT_PROGBITS/SHT_NOBITS.  */
   2129   1.1.1.2  christos     case SHT_NULL:
   2130   1.1.1.8  christos       return false;
   2131   1.1.1.2  christos 
   2132   1.1.1.2  christos       /* There shouldn't be section relative relocations
   2133   1.1.1.2  christos 	 against any other section.  */
   2134   1.1.1.2  christos     default:
   2135   1.1.1.8  christos       return true;
   2136   1.1.1.2  christos     }
   2137   1.1.1.2  christos }
   2138   1.1.1.2  christos 
   2139   1.1.1.8  christos static int
   2140   1.1.1.2  christos elf32_tic6x_relocate_section (bfd *output_bfd,
   2141   1.1.1.2  christos 			      struct bfd_link_info *info,
   2142   1.1.1.2  christos 			      bfd *input_bfd,
   2143   1.1.1.2  christos 			      asection *input_section,
   2144   1.1.1.2  christos 			      bfd_byte *contents,
   2145   1.1.1.2  christos 			      Elf_Internal_Rela *relocs,
   2146   1.1.1.2  christos 			      Elf_Internal_Sym *local_syms,
   2147   1.1.1.2  christos 			      asection **local_sections)
   2148   1.1.1.2  christos {
   2149   1.1.1.2  christos   struct elf32_tic6x_link_hash_table *htab;
   2150   1.1.1.2  christos   Elf_Internal_Shdr *symtab_hdr;
   2151   1.1.1.2  christos   struct elf_link_hash_entry **sym_hashes;
   2152   1.1.1.2  christos   bfd_vma *local_got_offsets;
   2153   1.1.1.2  christos   Elf_Internal_Rela *rel;
   2154   1.1.1.2  christos   Elf_Internal_Rela *relend;
   2155   1.1.1.8  christos   bool ok = true;
   2156   1.1.1.2  christos 
   2157   1.1.1.2  christos   htab = elf32_tic6x_hash_table (info);
   2158   1.1.1.2  christos   symtab_hdr = & elf_symtab_hdr (input_bfd);
   2159   1.1.1.2  christos   sym_hashes = elf_sym_hashes (input_bfd);
   2160   1.1.1.2  christos   local_got_offsets = elf_local_got_offsets (input_bfd);
   2161   1.1.1.2  christos 
   2162   1.1.1.2  christos   relend = relocs + input_section->reloc_count;
   2163   1.1.1.2  christos 
   2164   1.1.1.2  christos   for (rel = relocs; rel < relend; rel ++)
   2165   1.1.1.2  christos     {
   2166   1.1.1.2  christos       int r_type;
   2167   1.1.1.2  christos       unsigned long r_symndx;
   2168   1.1.1.2  christos       arelent bfd_reloc;
   2169   1.1.1.2  christos       reloc_howto_type *howto;
   2170   1.1.1.2  christos       Elf_Internal_Sym *sym;
   2171   1.1.1.2  christos       asection *sec;
   2172   1.1.1.2  christos       struct elf_link_hash_entry *h;
   2173   1.1.1.2  christos       bfd_vma off, off2, relocation;
   2174   1.1.1.8  christos       bool unresolved_reloc;
   2175   1.1.1.2  christos       bfd_reloc_status_type r;
   2176   1.1.1.2  christos       struct bfd_link_hash_entry *sbh;
   2177   1.1.1.8  christos       bool is_rel;
   2178   1.1.1.8  christos       bool res;
   2179   1.1.1.2  christos 
   2180   1.1.1.2  christos       r_type = ELF32_R_TYPE (rel->r_info);
   2181   1.1.1.2  christos       r_symndx = ELF32_R_SYM (rel->r_info);
   2182   1.1.1.2  christos 
   2183   1.1.1.2  christos       is_rel = elf32_tic6x_rel_relocation_p (input_bfd, input_section,
   2184   1.1.1.2  christos 					     relocs, rel);
   2185   1.1.1.2  christos 
   2186   1.1.1.2  christos       if (is_rel)
   2187   1.1.1.6  christos 	res = elf32_tic6x_info_to_howto_rel (input_bfd, &bfd_reloc, rel);
   2188   1.1.1.2  christos       else
   2189   1.1.1.6  christos 	res = elf32_tic6x_info_to_howto (input_bfd, &bfd_reloc, rel);
   2190   1.1.1.6  christos 
   2191   1.1.1.6  christos       if (!res || (howto = bfd_reloc.howto) == NULL)
   2192   1.1.1.2  christos 	{
   2193   1.1.1.2  christos 	  bfd_set_error (bfd_error_bad_value);
   2194   1.1.1.8  christos 	  return false;
   2195   1.1.1.2  christos 	}
   2196   1.1.1.2  christos 
   2197   1.1.1.2  christos       h = NULL;
   2198   1.1.1.2  christos       sym = NULL;
   2199   1.1.1.2  christos       sec = NULL;
   2200   1.1.1.8  christos       unresolved_reloc = false;
   2201   1.1.1.2  christos 
   2202   1.1.1.2  christos       if (r_symndx < symtab_hdr->sh_info)
   2203   1.1.1.2  christos 	{
   2204   1.1.1.2  christos 	  sym = local_syms + r_symndx;
   2205   1.1.1.2  christos 	  sec = local_sections[r_symndx];
   2206       1.1  christos 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
   2207       1.1  christos 	}
   2208       1.1  christos       else
   2209       1.1  christos 	{
   2210   1.1.1.8  christos 	  bool warned, ignored;
   2211       1.1  christos 
   2212       1.1  christos 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
   2213       1.1  christos 				   r_symndx, symtab_hdr, sym_hashes,
   2214       1.1  christos 				   h, sec, relocation,
   2215   1.1.1.3  christos 				   unresolved_reloc, warned, ignored);
   2216       1.1  christos 	}
   2217       1.1  christos 
   2218   1.1.1.2  christos       if (sec != NULL && discarded_section (sec))
   2219       1.1  christos 	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   2220  1.1.1.11  christos 					 rel, 1, relend, R_C6000_NONE,
   2221  1.1.1.11  christos 					 howto, 0, contents);
   2222       1.1  christos 
   2223   1.1.1.3  christos       if (bfd_link_relocatable (info))
   2224       1.1  christos 	{
   2225       1.1  christos 	  if (is_rel
   2226       1.1  christos 	      && sym != NULL
   2227       1.1  christos 	      && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
   2228       1.1  christos 	    {
   2229       1.1  christos 	      rel->r_addend = 0;
   2230       1.1  christos 	      relocation = sec->output_offset + sym->st_value;
   2231       1.1  christos 	      r = _bfd_relocate_contents (howto, input_bfd, relocation,
   2232       1.1  christos 					  contents + rel->r_offset);
   2233       1.1  christos 	      goto done_reloc;
   2234       1.1  christos 	    }
   2235       1.1  christos 	  continue;
   2236       1.1  christos 	}
   2237       1.1  christos 
   2238       1.1  christos       switch (r_type)
   2239       1.1  christos 	{
   2240       1.1  christos 	case R_C6000_NONE:
   2241       1.1  christos 	case R_C6000_ALIGN:
   2242       1.1  christos 	case R_C6000_FPHEAD:
   2243       1.1  christos 	case R_C6000_NOCMP:
   2244       1.1  christos 	  /* No action needed.  */
   2245       1.1  christos 	  continue;
   2246       1.1  christos 
   2247       1.1  christos 	case R_C6000_PCR_S21:
   2248   1.1.1.2  christos 	  /* A branch to an undefined weak symbol is turned into a
   2249   1.1.1.2  christos 	     "b .s2 B3" instruction if the existing insn is of the
   2250   1.1.1.2  christos 	     form "b .s2 symbol".  */
   2251   1.1.1.2  christos 	  if (h ? h->root.type == bfd_link_hash_undefweak
   2252   1.1.1.2  christos 	      && (htab->elf.splt == NULL || h->plt.offset == (bfd_vma) -1)
   2253   1.1.1.2  christos 	      : r_symndx != STN_UNDEF && bfd_is_und_section (sec))
   2254   1.1.1.2  christos 	    {
   2255   1.1.1.2  christos 	      unsigned long oldval;
   2256   1.1.1.2  christos 	      oldval = bfd_get_32 (input_bfd, contents + rel->r_offset);
   2257   1.1.1.2  christos 
   2258   1.1.1.2  christos 	      if ((oldval & 0x7e) == 0x12)
   2259   1.1.1.2  christos 		{
   2260   1.1.1.2  christos 		  oldval &= 0xF0000001;
   2261   1.1.1.2  christos 		  bfd_put_32 (input_bfd, oldval | 0x000c0362,
   2262   1.1.1.2  christos 			      contents + rel->r_offset);
   2263   1.1.1.2  christos 		  r = bfd_reloc_ok;
   2264   1.1.1.2  christos 		  goto done_reloc;
   2265   1.1.1.2  christos 		}
   2266   1.1.1.2  christos 	    }
   2267   1.1.1.5  christos 	  /* Fall through.  */
   2268   1.1.1.2  christos 
   2269       1.1  christos 	case R_C6000_PCR_S12:
   2270       1.1  christos 	case R_C6000_PCR_S10:
   2271       1.1  christos 	case R_C6000_PCR_S7:
   2272   1.1.1.2  christos 	  if (h != NULL
   2273   1.1.1.2  christos 	      && h->plt.offset != (bfd_vma) -1
   2274   1.1.1.2  christos 	      && htab->elf.splt != NULL)
   2275   1.1.1.2  christos 	    {
   2276   1.1.1.2  christos 	      relocation = (htab->elf.splt->output_section->vma
   2277   1.1.1.2  christos 			    + htab->elf.splt->output_offset
   2278   1.1.1.2  christos 			    + h->plt.offset);
   2279   1.1.1.2  christos 	    }
   2280   1.1.1.2  christos 
   2281       1.1  christos 	  /* Generic PC-relative handling produces a value relative to
   2282       1.1  christos 	     the exact location of the relocation.  Adjust it to be
   2283       1.1  christos 	     relative to the start of the fetch packet instead.  */
   2284       1.1  christos 	  relocation += (input_section->output_section->vma
   2285       1.1  christos 			 + input_section->output_offset
   2286       1.1  christos 			 + rel->r_offset) & 0x1f;
   2287   1.1.1.8  christos 	  unresolved_reloc = false;
   2288   1.1.1.2  christos 	  break;
   2289   1.1.1.2  christos 
   2290   1.1.1.2  christos 	case R_C6000_PCR_H16:
   2291   1.1.1.2  christos 	case R_C6000_PCR_L16:
   2292   1.1.1.2  christos 	  off = (input_section->output_section->vma
   2293   1.1.1.2  christos 		 + input_section->output_offset
   2294   1.1.1.2  christos 		 + rel->r_offset);
   2295   1.1.1.2  christos 	  /* These must be calculated as R = S - FP(FP(PC) - A).
   2296   1.1.1.2  christos 	     PC, here, is the value we just computed in OFF.  RELOCATION
   2297   1.1.1.2  christos 	     has the address of S + A. */
   2298   1.1.1.2  christos 	  relocation -= rel->r_addend;
   2299   1.1.1.2  christos 	  off2 = ((off & ~(bfd_vma)0x1f) - rel->r_addend) & (bfd_vma)~0x1f;
   2300   1.1.1.2  christos 	  off2 = relocation - off2;
   2301   1.1.1.2  christos 	  relocation = off + off2;
   2302   1.1.1.2  christos 	  break;
   2303   1.1.1.2  christos 
   2304   1.1.1.2  christos 	case R_C6000_DSBT_INDEX:
   2305   1.1.1.2  christos 	  relocation = elf32_tic6x_hash_table (info)->params.dsbt_index;
   2306   1.1.1.3  christos 	  if (!bfd_link_pic (info) || relocation != 0)
   2307   1.1.1.2  christos 	    break;
   2308   1.1.1.2  christos 
   2309   1.1.1.2  christos 	  /* fall through */
   2310       1.1  christos 	case R_C6000_ABS32:
   2311       1.1  christos 	case R_C6000_ABS16:
   2312       1.1  christos 	case R_C6000_ABS8:
   2313       1.1  christos 	case R_C6000_ABS_S16:
   2314       1.1  christos 	case R_C6000_ABS_L16:
   2315       1.1  christos 	case R_C6000_ABS_H16:
   2316   1.1.1.2  christos 	  /* When generating a shared object or relocatable executable, these
   2317   1.1.1.2  christos 	     relocations are copied into the output file to be resolved at
   2318   1.1.1.2  christos 	     run time.  */
   2319   1.1.1.3  christos 	  if ((bfd_link_pic (info) || elf32_tic6x_using_dsbt (output_bfd))
   2320   1.1.1.2  christos 	      && (input_section->flags & SEC_ALLOC)
   2321   1.1.1.2  christos 	      && (h == NULL
   2322   1.1.1.2  christos 		  || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
   2323   1.1.1.2  christos 		  || h->root.type != bfd_link_hash_undefweak))
   2324   1.1.1.2  christos 	    {
   2325   1.1.1.2  christos 	      Elf_Internal_Rela outrel;
   2326   1.1.1.8  christos 	      bool skip, relocate;
   2327   1.1.1.2  christos 	      asection *sreloc;
   2328   1.1.1.2  christos 
   2329   1.1.1.8  christos 	      unresolved_reloc = false;
   2330   1.1.1.2  christos 
   2331   1.1.1.2  christos 	      sreloc = elf_section_data (input_section)->sreloc;
   2332   1.1.1.2  christos 	      BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL);
   2333   1.1.1.2  christos 
   2334   1.1.1.8  christos 	      skip = false;
   2335   1.1.1.8  christos 	      relocate = false;
   2336   1.1.1.2  christos 
   2337   1.1.1.2  christos 	      outrel.r_offset =
   2338   1.1.1.2  christos 		_bfd_elf_section_offset (output_bfd, info, input_section,
   2339   1.1.1.2  christos 					 rel->r_offset);
   2340   1.1.1.2  christos 	      if (outrel.r_offset == (bfd_vma) -1)
   2341   1.1.1.8  christos 		skip = true;
   2342   1.1.1.2  christos 	      else if (outrel.r_offset == (bfd_vma) -2)
   2343   1.1.1.8  christos 		skip = true, relocate = true;
   2344   1.1.1.2  christos 	      outrel.r_offset += (input_section->output_section->vma
   2345   1.1.1.2  christos 				  + input_section->output_offset);
   2346   1.1.1.2  christos 
   2347   1.1.1.2  christos 	      if (skip)
   2348   1.1.1.2  christos 		memset (&outrel, 0, sizeof outrel);
   2349   1.1.1.2  christos 	      else if (h != NULL
   2350   1.1.1.2  christos 		       && h->dynindx != -1
   2351   1.1.1.3  christos 		       && (!bfd_link_pic (info)
   2352   1.1.1.3  christos 			   || !SYMBOLIC_BIND (info, h)
   2353   1.1.1.2  christos 			   || !h->def_regular))
   2354   1.1.1.2  christos 		{
   2355   1.1.1.2  christos 		  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
   2356   1.1.1.2  christos 		  outrel.r_addend = rel->r_addend;
   2357   1.1.1.2  christos 		}
   2358   1.1.1.2  christos 	      else
   2359   1.1.1.2  christos 		{
   2360   1.1.1.2  christos 		  long indx;
   2361   1.1.1.2  christos 
   2362   1.1.1.2  christos 		  outrel.r_addend = relocation + rel->r_addend;
   2363   1.1.1.2  christos 
   2364   1.1.1.2  christos 		  if (bfd_is_abs_section (sec))
   2365   1.1.1.2  christos 		    indx = 0;
   2366   1.1.1.2  christos 		  else if (sec == NULL || sec->owner == NULL)
   2367   1.1.1.2  christos 		    {
   2368   1.1.1.2  christos 		      bfd_set_error (bfd_error_bad_value);
   2369   1.1.1.8  christos 		      return false;
   2370   1.1.1.2  christos 		    }
   2371   1.1.1.2  christos 		  else
   2372   1.1.1.2  christos 		    {
   2373   1.1.1.2  christos 		      asection *osec;
   2374   1.1.1.2  christos 
   2375   1.1.1.2  christos 		      osec = sec->output_section;
   2376   1.1.1.2  christos 		      indx = elf_section_data (osec)->dynindx;
   2377   1.1.1.2  christos 		      outrel.r_addend -= osec->vma;
   2378   1.1.1.2  christos 		      BFD_ASSERT (indx != 0);
   2379   1.1.1.2  christos 		    }
   2380   1.1.1.2  christos 
   2381   1.1.1.2  christos 		  outrel.r_info = ELF32_R_INFO (indx, r_type);
   2382   1.1.1.2  christos 		}
   2383   1.1.1.2  christos 
   2384   1.1.1.2  christos 	      elf32_tic6x_install_rela (output_bfd, sreloc, &outrel);
   2385   1.1.1.2  christos 
   2386   1.1.1.2  christos 	      /* If this reloc is against an external symbol, we do not want to
   2387   1.1.1.2  christos 		 fiddle with the addend.  Otherwise, we need to include the symbol
   2388   1.1.1.2  christos 		 value so that it becomes an addend for the dynamic reloc.  */
   2389   1.1.1.2  christos 	      if (! relocate)
   2390   1.1.1.2  christos 		continue;
   2391   1.1.1.2  christos 	    }
   2392   1.1.1.2  christos 
   2393       1.1  christos 	  /* Generic logic OK.  */
   2394       1.1  christos 	  break;
   2395       1.1  christos 
   2396       1.1  christos 	case R_C6000_SBR_U15_B:
   2397       1.1  christos 	case R_C6000_SBR_U15_H:
   2398       1.1  christos 	case R_C6000_SBR_U15_W:
   2399       1.1  christos 	case R_C6000_SBR_S16:
   2400       1.1  christos 	case R_C6000_SBR_L16_B:
   2401       1.1  christos 	case R_C6000_SBR_L16_H:
   2402       1.1  christos 	case R_C6000_SBR_L16_W:
   2403       1.1  christos 	case R_C6000_SBR_H16_B:
   2404       1.1  christos 	case R_C6000_SBR_H16_H:
   2405       1.1  christos 	case R_C6000_SBR_H16_W:
   2406       1.1  christos 	  sbh = bfd_link_hash_lookup (info->hash, "__c6xabi_DSBT_BASE",
   2407   1.1.1.8  christos 				      false, false, true);
   2408       1.1  christos 	  if (sbh != NULL
   2409       1.1  christos 	      && (sbh->type == bfd_link_hash_defined
   2410       1.1  christos 		  || sbh->type == bfd_link_hash_defweak))
   2411   1.1.1.2  christos 	    {
   2412   1.1.1.2  christos 	      if (h ? (h->root.type == bfd_link_hash_undefweak
   2413   1.1.1.2  christos 		       && (htab->elf.splt == NULL
   2414   1.1.1.2  christos 			   || h->plt.offset == (bfd_vma) -1))
   2415   1.1.1.2  christos 		  : r_symndx != STN_UNDEF && bfd_is_und_section (sec))
   2416   1.1.1.2  christos 		relocation = 0;
   2417   1.1.1.2  christos 	      else
   2418   1.1.1.2  christos 		relocation -= (sbh->u.def.value
   2419   1.1.1.2  christos 			       + sbh->u.def.section->output_section->vma
   2420   1.1.1.2  christos 			       + sbh->u.def.section->output_offset);
   2421   1.1.1.2  christos 	    }
   2422       1.1  christos 	  else
   2423       1.1  christos 	    {
   2424   1.1.1.6  christos 	      _bfd_error_handler (_("%pB: SB-relative relocation but "
   2425   1.1.1.5  christos 				    "__c6xabi_DSBT_BASE not defined"),
   2426   1.1.1.5  christos 				  input_bfd);
   2427   1.1.1.8  christos 	      ok = false;
   2428       1.1  christos 	      continue;
   2429       1.1  christos 	    }
   2430       1.1  christos 	  break;
   2431       1.1  christos 
   2432       1.1  christos 	case R_C6000_SBR_GOT_U15_W:
   2433       1.1  christos 	case R_C6000_SBR_GOT_L16_W:
   2434       1.1  christos 	case R_C6000_SBR_GOT_H16_W:
   2435   1.1.1.2  christos 	case R_C6000_EHTYPE:
   2436   1.1.1.2  christos 	  /* Relocation is to the entry for this symbol in the global
   2437   1.1.1.2  christos 	     offset table.  */
   2438   1.1.1.2  christos 	  if (htab->elf.sgot == NULL)
   2439   1.1.1.2  christos 	    abort ();
   2440       1.1  christos 
   2441   1.1.1.2  christos 	  if (h != NULL)
   2442   1.1.1.2  christos 	    {
   2443   1.1.1.8  christos 	      bool dyn;
   2444   1.1.1.2  christos 
   2445   1.1.1.2  christos 	      off = h->got.offset;
   2446   1.1.1.2  christos 	      dyn = htab->elf.dynamic_sections_created;
   2447   1.1.1.3  christos 	      if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
   2448   1.1.1.3  christos 						     bfd_link_pic (info),
   2449   1.1.1.3  christos 						     h)
   2450   1.1.1.3  christos 		  || (bfd_link_pic (info)
   2451   1.1.1.2  christos 		      && SYMBOL_REFERENCES_LOCAL (info, h))
   2452   1.1.1.2  christos 		  || (ELF_ST_VISIBILITY (h->other)
   2453   1.1.1.2  christos 		      && h->root.type == bfd_link_hash_undefweak))
   2454   1.1.1.2  christos 		{
   2455   1.1.1.2  christos 		  /* This is actually a static link, or it is a
   2456   1.1.1.2  christos 		     -Bsymbolic link and the symbol is defined
   2457   1.1.1.2  christos 		     locally, or the symbol was forced to be local
   2458   1.1.1.2  christos 		     because of a version file.  We must initialize
   2459   1.1.1.2  christos 		     this entry in the global offset table.  Since the
   2460   1.1.1.2  christos 		     offset must always be a multiple of 4, we use the
   2461   1.1.1.2  christos 		     least significant bit to record whether we have
   2462   1.1.1.2  christos 		     initialized it already.
   2463   1.1.1.2  christos 
   2464   1.1.1.2  christos 		     When doing a dynamic link, we create a .rel.got
   2465   1.1.1.2  christos 		     relocation entry to initialize the value.  This
   2466   1.1.1.2  christos 		     is done in the finish_dynamic_symbol routine.  */
   2467   1.1.1.2  christos 		  if ((off & 1) != 0)
   2468   1.1.1.2  christos 		    off &= ~1;
   2469   1.1.1.2  christos 		  else
   2470   1.1.1.2  christos 		    {
   2471   1.1.1.2  christos 		      bfd_put_32 (output_bfd, relocation,
   2472   1.1.1.2  christos 				  htab->elf.sgot->contents + off);
   2473   1.1.1.2  christos 		      h->got.offset |= 1;
   2474   1.1.1.2  christos 
   2475   1.1.1.3  christos 		      if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
   2476   1.1.1.3  christos 							    bfd_link_pic (info),
   2477   1.1.1.2  christos 							    h)
   2478   1.1.1.2  christos 			  && !(ELF_ST_VISIBILITY (h->other)
   2479   1.1.1.2  christos 			       && h->root.type == bfd_link_hash_undefweak))
   2480   1.1.1.2  christos 			elf32_tic6x_make_got_dynreloc (output_bfd, htab, sec,
   2481   1.1.1.2  christos 						       off);
   2482   1.1.1.2  christos 		    }
   2483   1.1.1.2  christos 		}
   2484   1.1.1.2  christos 	      else
   2485   1.1.1.8  christos 		unresolved_reloc = false;
   2486   1.1.1.2  christos 	    }
   2487   1.1.1.2  christos 	  else
   2488   1.1.1.2  christos 	    {
   2489   1.1.1.2  christos 	      if (local_got_offsets == NULL)
   2490   1.1.1.2  christos 		abort ();
   2491   1.1.1.2  christos 
   2492   1.1.1.2  christos 	      off = local_got_offsets[r_symndx];
   2493   1.1.1.2  christos 
   2494   1.1.1.2  christos 	      /* The offset must always be a multiple of 4.  We use
   2495   1.1.1.2  christos 		 the least significant bit to record whether we have
   2496   1.1.1.2  christos 		 already generated the necessary reloc.  */
   2497   1.1.1.2  christos 	      if ((off & 1) != 0)
   2498   1.1.1.2  christos 		off &= ~1;
   2499   1.1.1.2  christos 	      else
   2500   1.1.1.2  christos 		{
   2501   1.1.1.2  christos 		  bfd_put_32 (output_bfd, relocation,
   2502   1.1.1.2  christos 			      htab->elf.sgot->contents + off);
   2503   1.1.1.2  christos 
   2504   1.1.1.3  christos 		  if (bfd_link_pic (info) || elf32_tic6x_using_dsbt (output_bfd))
   2505   1.1.1.2  christos 		    elf32_tic6x_make_got_dynreloc (output_bfd, htab, sec, off);
   2506   1.1.1.2  christos 
   2507   1.1.1.2  christos 		  local_got_offsets[r_symndx] |= 1;
   2508   1.1.1.2  christos 		}
   2509   1.1.1.2  christos 	    }
   2510   1.1.1.2  christos 
   2511   1.1.1.2  christos 	  if (off >= (bfd_vma) -2)
   2512   1.1.1.2  christos 	    abort ();
   2513   1.1.1.2  christos 
   2514   1.1.1.2  christos 	  if (htab->dsbt)
   2515   1.1.1.2  christos 	    relocation = (htab->elf.sgot->output_section->vma
   2516   1.1.1.2  christos 			  + htab->elf.sgot->output_offset + off
   2517   1.1.1.2  christos 			  - htab->dsbt->output_section->vma
   2518   1.1.1.2  christos 			  - htab->dsbt->output_offset);
   2519   1.1.1.2  christos 	  else
   2520   1.1.1.2  christos 	    relocation = (htab->elf.sgot->output_section->vma
   2521   1.1.1.2  christos 			  + htab->elf.sgot->output_offset + off
   2522   1.1.1.2  christos 			  - htab->elf.sgotplt->output_section->vma
   2523   1.1.1.2  christos 			  - htab->elf.sgotplt->output_offset);
   2524   1.1.1.2  christos 
   2525   1.1.1.2  christos 	  if (rel->r_addend != 0)
   2526   1.1.1.2  christos 	    {
   2527   1.1.1.2  christos 	      /* We can't do anything for a relocation which is against
   2528   1.1.1.2  christos 		 a symbol *plus offset*.  GOT holds relocations for
   2529   1.1.1.2  christos 		 symbols.  Make this an error; the compiler isn't
   2530   1.1.1.2  christos 		 allowed to pass us these kinds of things.  */
   2531   1.1.1.2  christos 	      if (h == NULL)
   2532   1.1.1.5  christos 		_bfd_error_handler
   2533   1.1.1.5  christos 		  /* xgettext:c-format */
   2534   1.1.1.6  christos 		  (_("%pB, section %pA: relocation %s with non-zero addend %"
   2535   1.1.1.6  christos 		     PRId64 " against local symbol"),
   2536   1.1.1.2  christos 		   input_bfd,
   2537   1.1.1.2  christos 		   input_section,
   2538   1.1.1.2  christos 		   elf32_tic6x_howto_table[r_type].name,
   2539   1.1.1.6  christos 		   (int64_t) rel->r_addend);
   2540   1.1.1.2  christos 	      else
   2541   1.1.1.5  christos 		_bfd_error_handler
   2542   1.1.1.5  christos 		  /* xgettext:c-format */
   2543   1.1.1.6  christos 		  (_("%pB, section %pA: relocation %s with non-zero addend %"
   2544   1.1.1.6  christos 		     PRId64 " against symbol `%s'"),
   2545   1.1.1.2  christos 		   input_bfd,
   2546   1.1.1.2  christos 		   input_section,
   2547   1.1.1.2  christos 		   elf32_tic6x_howto_table[r_type].name,
   2548   1.1.1.6  christos 		   (int64_t) rel->r_addend,
   2549   1.1.1.2  christos 		   h->root.root.string[0] != '\0' ? h->root.root.string
   2550   1.1.1.2  christos 		   : _("[whose name is lost]"));
   2551   1.1.1.2  christos 
   2552   1.1.1.2  christos 	      bfd_set_error (bfd_error_bad_value);
   2553   1.1.1.8  christos 	      return false;
   2554   1.1.1.2  christos 	    }
   2555   1.1.1.2  christos 	  break;
   2556   1.1.1.2  christos 
   2557   1.1.1.2  christos 	case R_C6000_PREL31:
   2558   1.1.1.2  christos 	  if (h != NULL
   2559   1.1.1.2  christos 	      && h->plt.offset != (bfd_vma) -1
   2560   1.1.1.2  christos 	      && htab->elf.splt != NULL)
   2561   1.1.1.2  christos 	    {
   2562   1.1.1.2  christos 	      relocation = (htab->elf.splt->output_section->vma
   2563   1.1.1.2  christos 			    + htab->elf.splt->output_offset
   2564   1.1.1.2  christos 			    + h->plt.offset);
   2565   1.1.1.2  christos 	    }
   2566   1.1.1.2  christos 	  break;
   2567   1.1.1.2  christos 
   2568   1.1.1.2  christos 	case R_C6000_COPY:
   2569   1.1.1.2  christos 	  /* Invalid in relocatable object.  */
   2570   1.1.1.2  christos 	default:
   2571   1.1.1.2  christos 	  /* Unknown relocation.  */
   2572   1.1.1.5  christos 	  /* xgettext:c-format */
   2573   1.1.1.6  christos 	  _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
   2574   1.1.1.5  christos 			      input_bfd, r_type);
   2575   1.1.1.6  christos 	  bfd_set_error (bfd_error_bad_value);
   2576   1.1.1.8  christos 	  ok = false;
   2577   1.1.1.2  christos 	  continue;
   2578   1.1.1.2  christos 	}
   2579   1.1.1.2  christos 
   2580   1.1.1.2  christos       r = _bfd_final_link_relocate (howto, input_bfd, input_section,
   2581   1.1.1.2  christos 				    contents, rel->r_offset,
   2582   1.1.1.2  christos 				    relocation, rel->r_addend);
   2583   1.1.1.2  christos 
   2584   1.1.1.2  christos     done_reloc:
   2585   1.1.1.2  christos       if (r == bfd_reloc_ok
   2586   1.1.1.2  christos 	  && howto->complain_on_overflow == complain_overflow_bitfield)
   2587   1.1.1.2  christos 	{
   2588   1.1.1.2  christos 	  /* Generic overflow handling accepts cases the ABI says
   2589   1.1.1.2  christos 	     should be rejected for R_C6000_ABS16 and
   2590   1.1.1.2  christos 	     R_C6000_ABS8.  */
   2591   1.1.1.2  christos 	  bfd_vma value = (relocation + rel->r_addend) & 0xffffffff;
   2592   1.1.1.2  christos 	  bfd_vma sbit = 1 << (howto->bitsize - 1);
   2593   1.1.1.2  christos 	  bfd_vma sbits = (-(bfd_vma) sbit) & 0xffffffff;
   2594   1.1.1.2  christos 	  bfd_vma value_sbits = value & sbits;
   2595   1.1.1.2  christos 
   2596   1.1.1.2  christos 	  if (value_sbits != 0
   2597   1.1.1.2  christos 	      && value_sbits != sbit
   2598   1.1.1.2  christos 	      && value_sbits != sbits)
   2599   1.1.1.2  christos 	    r = bfd_reloc_overflow;
   2600   1.1.1.2  christos 	}
   2601   1.1.1.2  christos 
   2602   1.1.1.2  christos       if (r != bfd_reloc_ok)
   2603   1.1.1.2  christos 	{
   2604   1.1.1.2  christos 	  const char *name;
   2605   1.1.1.2  christos 	  const char *error_message;
   2606   1.1.1.2  christos 
   2607   1.1.1.2  christos 	  if (h != NULL)
   2608   1.1.1.2  christos 	    name = h->root.root.string;
   2609   1.1.1.2  christos 	  else
   2610   1.1.1.2  christos 	    {
   2611   1.1.1.2  christos 	      name = bfd_elf_string_from_elf_section (input_bfd,
   2612   1.1.1.2  christos 						      symtab_hdr->sh_link,
   2613   1.1.1.2  christos 						      sym->st_name);
   2614   1.1.1.2  christos 	      if (name == NULL)
   2615   1.1.1.8  christos 		return false;
   2616   1.1.1.2  christos 	      if (*name == '\0')
   2617   1.1.1.7  christos 		name = bfd_section_name (sec);
   2618   1.1.1.2  christos 	    }
   2619   1.1.1.2  christos 
   2620   1.1.1.2  christos 	  switch (r)
   2621   1.1.1.2  christos 	    {
   2622   1.1.1.2  christos 	    case bfd_reloc_overflow:
   2623   1.1.1.2  christos 	      /* If the overflowing reloc was to an undefined symbol,
   2624   1.1.1.2  christos 		 we have already printed one error message and there
   2625   1.1.1.2  christos 		 is no point complaining again.  */
   2626   1.1.1.4  christos 	      if (!h || h->root.type != bfd_link_hash_undefined)
   2627   1.1.1.4  christos 		(*info->callbacks->reloc_overflow)
   2628   1.1.1.4  christos 		  (info, (h ? &h->root : NULL), name, howto->name,
   2629   1.1.1.4  christos 		   (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
   2630   1.1.1.2  christos 	      break;
   2631   1.1.1.2  christos 
   2632   1.1.1.2  christos 	    case bfd_reloc_undefined:
   2633   1.1.1.4  christos 	      (*info->callbacks->undefined_symbol) (info, name, input_bfd,
   2634   1.1.1.4  christos 						    input_section,
   2635   1.1.1.8  christos 						    rel->r_offset, true);
   2636   1.1.1.2  christos 	      break;
   2637   1.1.1.2  christos 
   2638   1.1.1.2  christos 	    case bfd_reloc_outofrange:
   2639   1.1.1.2  christos 	      error_message = _("out of range");
   2640   1.1.1.2  christos 	      goto common_error;
   2641   1.1.1.2  christos 
   2642   1.1.1.2  christos 	    case bfd_reloc_notsupported:
   2643   1.1.1.2  christos 	      error_message = _("unsupported relocation");
   2644   1.1.1.2  christos 	      goto common_error;
   2645   1.1.1.2  christos 
   2646   1.1.1.2  christos 	    case bfd_reloc_dangerous:
   2647   1.1.1.2  christos 	      error_message = _("dangerous relocation");
   2648   1.1.1.2  christos 	      goto common_error;
   2649   1.1.1.2  christos 
   2650   1.1.1.2  christos 	    default:
   2651   1.1.1.2  christos 	      error_message = _("unknown error");
   2652   1.1.1.2  christos 	      /* Fall through.  */
   2653   1.1.1.2  christos 
   2654   1.1.1.2  christos 	    common_error:
   2655   1.1.1.2  christos 	      BFD_ASSERT (error_message != NULL);
   2656   1.1.1.4  christos 	      (*info->callbacks->reloc_dangerous)
   2657   1.1.1.4  christos 		(info, error_message, input_bfd, input_section, rel->r_offset);
   2658   1.1.1.2  christos 	      break;
   2659   1.1.1.2  christos 	    }
   2660   1.1.1.2  christos 	}
   2661   1.1.1.2  christos     }
   2662   1.1.1.2  christos 
   2663   1.1.1.2  christos   return ok;
   2664   1.1.1.2  christos }
   2665   1.1.1.2  christos 
   2666   1.1.1.2  christos 
   2667   1.1.1.2  christos /* Look through the relocs for a section during the first phase, and
   2669   1.1.1.2  christos    calculate needed space in the global offset table, procedure linkage
   2670   1.1.1.2  christos    table, and dynamic reloc sections.  */
   2671   1.1.1.8  christos 
   2672   1.1.1.2  christos static bool
   2673   1.1.1.2  christos elf32_tic6x_check_relocs (bfd *abfd, struct bfd_link_info *info,
   2674   1.1.1.2  christos 			  asection *sec, const Elf_Internal_Rela *relocs)
   2675   1.1.1.2  christos {
   2676   1.1.1.2  christos   struct elf32_tic6x_link_hash_table *htab;
   2677   1.1.1.2  christos   Elf_Internal_Shdr *symtab_hdr;
   2678   1.1.1.2  christos   struct elf_link_hash_entry **sym_hashes;
   2679   1.1.1.2  christos   const Elf_Internal_Rela *rel;
   2680   1.1.1.2  christos   const Elf_Internal_Rela *rel_end;
   2681   1.1.1.2  christos   asection *sreloc;
   2682   1.1.1.3  christos 
   2683   1.1.1.8  christos   if (bfd_link_relocatable (info))
   2684   1.1.1.2  christos     return true;
   2685   1.1.1.2  christos 
   2686   1.1.1.2  christos   htab = elf32_tic6x_hash_table (info);
   2687   1.1.1.2  christos   symtab_hdr = &elf_symtab_hdr (abfd);
   2688   1.1.1.2  christos   sym_hashes = elf_sym_hashes (abfd);
   2689   1.1.1.2  christos 
   2690   1.1.1.2  christos   /* Create dynamic sections for relocatable executables so that we can
   2691   1.1.1.3  christos      copy relocations.  */
   2692   1.1.1.2  christos   if ((bfd_link_pic (info) || elf32_tic6x_using_dsbt (abfd))
   2693   1.1.1.2  christos       && ! htab->elf.dynamic_sections_created)
   2694  1.1.1.11  christos     {
   2695   1.1.1.8  christos       if (! bfd_elf_link_create_dynamic_sections (abfd, info))
   2696   1.1.1.2  christos 	return false;
   2697   1.1.1.2  christos     }
   2698   1.1.1.2  christos 
   2699   1.1.1.2  christos   sreloc = NULL;
   2700   1.1.1.2  christos 
   2701   1.1.1.2  christos   rel_end = relocs + sec->reloc_count;
   2702   1.1.1.2  christos   for (rel = relocs; rel < rel_end; rel++)
   2703   1.1.1.2  christos     {
   2704   1.1.1.5  christos       unsigned int r_type;
   2705   1.1.1.2  christos       unsigned int r_symndx;
   2706   1.1.1.2  christos       struct elf_link_hash_entry *h;
   2707   1.1.1.2  christos       Elf_Internal_Sym *isym;
   2708   1.1.1.2  christos 
   2709   1.1.1.2  christos       r_symndx = ELF32_R_SYM (rel->r_info);
   2710   1.1.1.2  christos       r_type = ELF32_R_TYPE (rel->r_info);
   2711   1.1.1.2  christos 
   2712   1.1.1.2  christos       if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
   2713   1.1.1.5  christos 	{
   2714   1.1.1.6  christos 	  /* xgettext:c-format */
   2715   1.1.1.5  christos 	  _bfd_error_handler (_("%pB: bad symbol index: %d"),
   2716   1.1.1.8  christos 			      abfd, r_symndx);
   2717   1.1.1.2  christos 	  return false;
   2718   1.1.1.2  christos 	}
   2719   1.1.1.2  christos 
   2720   1.1.1.2  christos       if (r_symndx < symtab_hdr->sh_info)
   2721   1.1.1.2  christos 	{
   2722   1.1.1.8  christos 	  /* A local symbol.  */
   2723   1.1.1.2  christos 	  isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
   2724   1.1.1.2  christos 					abfd, r_symndx);
   2725   1.1.1.8  christos 	  if (isym == NULL)
   2726   1.1.1.2  christos 	    return false;
   2727   1.1.1.2  christos 	  h = NULL;
   2728   1.1.1.2  christos 	}
   2729   1.1.1.2  christos       else
   2730   1.1.1.2  christos 	{
   2731   1.1.1.2  christos 	  isym = NULL;
   2732   1.1.1.2  christos 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   2733   1.1.1.2  christos 	  while (h->root.type == bfd_link_hash_indirect
   2734   1.1.1.2  christos 		 || h->root.type == bfd_link_hash_warning)
   2735       1.1  christos 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   2736       1.1  christos 	}
   2737   1.1.1.2  christos 
   2738   1.1.1.2  christos       switch (r_type)
   2739   1.1.1.2  christos 	{
   2740   1.1.1.2  christos 	case R_C6000_PCR_S21:
   2741   1.1.1.2  christos 	case R_C6000_PREL31:
   2742   1.1.1.2  christos 	  /* This symbol requires a procedure linkage table entry.  We
   2743   1.1.1.2  christos 	     actually build the entry in adjust_dynamic_symbol,
   2744   1.1.1.2  christos 	     because this might be a case of linking PIC code which is
   2745   1.1.1.2  christos 	     never referenced by a dynamic object, in which case we
   2746   1.1.1.2  christos 	     don't need to generate a procedure linkage table entry
   2747   1.1.1.2  christos 	     after all.  */
   2748   1.1.1.2  christos 
   2749   1.1.1.2  christos 	  /* If this is a local symbol, we resolve it directly without
   2750   1.1.1.2  christos 	     creating a procedure linkage table entry.  */
   2751   1.1.1.2  christos 	  if (h == NULL)
   2752   1.1.1.2  christos 	    continue;
   2753   1.1.1.2  christos 
   2754   1.1.1.2  christos 	  h->needs_plt = 1;
   2755   1.1.1.2  christos 	  h->plt.refcount += 1;
   2756   1.1.1.2  christos 	  break;
   2757   1.1.1.2  christos 
   2758   1.1.1.2  christos 	case R_C6000_SBR_GOT_U15_W:
   2759   1.1.1.2  christos 	case R_C6000_SBR_GOT_L16_W:
   2760   1.1.1.2  christos 	case R_C6000_SBR_GOT_H16_W:
   2761   1.1.1.2  christos 	case R_C6000_EHTYPE:
   2762   1.1.1.2  christos 	  /* This symbol requires a global offset table entry.  */
   2763   1.1.1.2  christos 	  if (h != NULL)
   2764   1.1.1.2  christos 	    {
   2765   1.1.1.2  christos 	      h->got.refcount += 1;
   2766   1.1.1.2  christos 	    }
   2767   1.1.1.2  christos 	  else
   2768   1.1.1.2  christos 	    {
   2769   1.1.1.2  christos 	      bfd_signed_vma *local_got_refcounts;
   2770   1.1.1.2  christos 
   2771   1.1.1.2  christos 	      /* This is a global offset table entry for a local symbol.  */
   2772   1.1.1.2  christos 	      local_got_refcounts = elf_local_got_refcounts (abfd);
   2773   1.1.1.2  christos 	      if (local_got_refcounts == NULL)
   2774   1.1.1.2  christos 		{
   2775   1.1.1.2  christos 		  bfd_size_type size;
   2776   1.1.1.2  christos 
   2777   1.1.1.2  christos 		  size = symtab_hdr->sh_info;
   2778   1.1.1.2  christos 		  size *= (sizeof (bfd_signed_vma)
   2779   1.1.1.2  christos 			   + sizeof (bfd_vma) + sizeof(char));
   2780   1.1.1.2  christos 		  local_got_refcounts = bfd_zalloc (abfd, size);
   2781   1.1.1.8  christos 		  if (local_got_refcounts == NULL)
   2782   1.1.1.2  christos 		    return false;
   2783   1.1.1.2  christos 		  elf_local_got_refcounts (abfd) = local_got_refcounts;
   2784   1.1.1.2  christos 		}
   2785   1.1.1.2  christos 	      local_got_refcounts[r_symndx] += 1;
   2786   1.1.1.2  christos 	    }
   2787   1.1.1.2  christos 
   2788   1.1.1.2  christos 	  if (htab->elf.sgot == NULL)
   2789   1.1.1.2  christos 	    {
   2790   1.1.1.2  christos 	      if (htab->elf.dynobj == NULL)
   2791   1.1.1.2  christos 		htab->elf.dynobj = abfd;
   2792   1.1.1.8  christos 	      if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
   2793   1.1.1.2  christos 		return false;
   2794   1.1.1.2  christos 	    }
   2795   1.1.1.2  christos 	  break;
   2796   1.1.1.2  christos 
   2797   1.1.1.2  christos 	case R_C6000_DSBT_INDEX:
   2798   1.1.1.2  christos 	  /* We'd like to check for nonzero dsbt_index here, but it's
   2799   1.1.1.2  christos 	     set up only after check_relocs is called.  Instead, we
   2800   1.1.1.2  christos 	     store the number of R_C6000_DSBT_INDEX relocs in the
   2801   1.1.1.2  christos 	     pc_count field, and potentially discard the extra space
   2802   1.1.1.3  christos 	     in elf32_tic6x_allocate_dynrelocs.  */
   2803   1.1.1.2  christos 	  if (!bfd_link_pic (info))
   2804   1.1.1.2  christos 	    break;
   2805   1.1.1.2  christos 
   2806   1.1.1.2  christos 	  /* fall through */
   2807   1.1.1.2  christos 	case R_C6000_ABS32:
   2808   1.1.1.2  christos 	case R_C6000_ABS16:
   2809   1.1.1.2  christos 	case R_C6000_ABS8:
   2810   1.1.1.2  christos 	case R_C6000_ABS_S16:
   2811   1.1.1.2  christos 	case R_C6000_ABS_L16:
   2812   1.1.1.2  christos 	case R_C6000_ABS_H16:
   2813   1.1.1.2  christos 	  /* If we are creating a shared library, and this is a reloc
   2814   1.1.1.2  christos 	     against a global symbol, or a non PC relative reloc
   2815   1.1.1.2  christos 	     against a local symbol, then we need to copy the reloc
   2816   1.1.1.2  christos 	     into the shared library.  However, if we are linking with
   2817   1.1.1.2  christos 	     -Bsymbolic, we do not need to copy a reloc against a
   2818   1.1.1.2  christos 	     global symbol which is defined in an object we are
   2819   1.1.1.2  christos 	     including in the link (i.e., DEF_REGULAR is set).  At
   2820   1.1.1.2  christos 	     this point we have not seen all the input files, so it is
   2821   1.1.1.2  christos 	     possible that DEF_REGULAR is not set now but will be set
   2822   1.1.1.2  christos 	     later (it is never cleared).  In case of a weak definition,
   2823   1.1.1.2  christos 	     DEF_REGULAR may be cleared later by a strong definition in
   2824   1.1.1.2  christos 	     a shared library.  We account for that possibility below by
   2825   1.1.1.2  christos 	     storing information in the relocs_copied field of the hash
   2826   1.1.1.2  christos 	     table entry.  A similar situation occurs when creating
   2827   1.1.1.2  christos 	     shared libraries and symbol visibility changes render the
   2828   1.1.1.2  christos 	     symbol local.
   2829   1.1.1.2  christos 
   2830   1.1.1.2  christos 	     If on the other hand, we are creating an executable, we
   2831   1.1.1.2  christos 	     may need to keep relocations for symbols satisfied by a
   2832   1.1.1.2  christos 	     dynamic library if we manage to avoid copy relocs for the
   2833   1.1.1.3  christos 	     symbol.  */
   2834   1.1.1.2  christos 	  if ((bfd_link_pic (info) || elf32_tic6x_using_dsbt (abfd))
   2835   1.1.1.2  christos 	      && (sec->flags & SEC_ALLOC) != 0)
   2836   1.1.1.2  christos 	    {
   2837   1.1.1.2  christos 	      struct elf_dyn_relocs *p;
   2838   1.1.1.2  christos 	      struct elf_dyn_relocs **head;
   2839   1.1.1.2  christos 
   2840   1.1.1.2  christos 	      /* We must copy these reloc types into the output file.
   2841   1.1.1.2  christos 		 Create a reloc section in dynobj and make room for
   2842   1.1.1.2  christos 		 this reloc.  */
   2843   1.1.1.2  christos 	      if (sreloc == NULL)
   2844   1.1.1.2  christos 		{
   2845   1.1.1.2  christos 		  if (htab->elf.dynobj == NULL)
   2846   1.1.1.2  christos 		    htab->elf.dynobj = abfd;
   2847   1.1.1.2  christos 
   2848   1.1.1.8  christos 		  sreloc = _bfd_elf_make_dynamic_reloc_section
   2849   1.1.1.2  christos 		    (sec, htab->elf.dynobj, 2, abfd, /*rela? */ true);
   2850   1.1.1.2  christos 
   2851   1.1.1.8  christos 		  if (sreloc == NULL)
   2852   1.1.1.2  christos 		    return false;
   2853   1.1.1.2  christos 		}
   2854   1.1.1.2  christos 
   2855   1.1.1.2  christos 	      /* If this is a global symbol, we count the number of
   2856   1.1.1.2  christos 		 relocations we need for this symbol.  */
   2857   1.1.1.2  christos 	      if (h != NULL)
   2858   1.1.1.8  christos 		{
   2859   1.1.1.2  christos 		  head = &h->dyn_relocs;
   2860   1.1.1.2  christos 		}
   2861   1.1.1.2  christos 	      else
   2862   1.1.1.2  christos 		{
   2863   1.1.1.2  christos 		  /* Track dynamic relocs needed for local syms too.
   2864   1.1.1.2  christos 		     We really need local syms available to do this
   2865   1.1.1.2  christos 		     easily.  Oh well.  */
   2866   1.1.1.2  christos 		  void **vpp;
   2867   1.1.1.2  christos 		  asection *s;
   2868   1.1.1.2  christos 
   2869   1.1.1.2  christos 		  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
   2870   1.1.1.2  christos 		  if (s == NULL)
   2871   1.1.1.2  christos 		    s = sec;
   2872   1.1.1.2  christos 
   2873   1.1.1.2  christos 		  vpp = &elf_section_data (s)->local_dynrel;
   2874   1.1.1.2  christos 		  head = (struct elf_dyn_relocs **)vpp;
   2875   1.1.1.2  christos 		}
   2876   1.1.1.2  christos 
   2877   1.1.1.2  christos 	      p = *head;
   2878   1.1.1.2  christos 	      if (p == NULL || p->sec != sec)
   2879   1.1.1.8  christos 		{
   2880   1.1.1.2  christos 		  size_t amt = sizeof *p;
   2881   1.1.1.2  christos 		  p = bfd_alloc (htab->elf.dynobj, amt);
   2882   1.1.1.8  christos 		  if (p == NULL)
   2883   1.1.1.2  christos 		    return false;
   2884   1.1.1.2  christos 		  p->next = *head;
   2885   1.1.1.2  christos 		  *head = p;
   2886   1.1.1.2  christos 		  p->sec = sec;
   2887   1.1.1.2  christos 		  p->count = 0;
   2888   1.1.1.2  christos 		  p->pc_count = 0;
   2889   1.1.1.2  christos 		}
   2890   1.1.1.2  christos 
   2891   1.1.1.2  christos 	      p->count += 1;
   2892   1.1.1.2  christos 	      if (r_type == R_C6000_DSBT_INDEX)
   2893   1.1.1.2  christos 		p->pc_count += 1;
   2894   1.1.1.2  christos 	    }
   2895   1.1.1.2  christos 	  break;
   2896   1.1.1.2  christos 
   2897   1.1.1.2  christos 	case R_C6000_SBR_U15_B:
   2898   1.1.1.2  christos 	case R_C6000_SBR_U15_H:
   2899   1.1.1.2  christos 	case R_C6000_SBR_U15_W:
   2900   1.1.1.2  christos 	case R_C6000_SBR_S16:
   2901   1.1.1.2  christos 	case R_C6000_SBR_L16_B:
   2902   1.1.1.2  christos 	case R_C6000_SBR_L16_H:
   2903   1.1.1.2  christos 	case R_C6000_SBR_L16_W:
   2904   1.1.1.2  christos 	case R_C6000_SBR_H16_B:
   2905   1.1.1.2  christos 	case R_C6000_SBR_H16_H:
   2906   1.1.1.6  christos 	case R_C6000_SBR_H16_W:
   2907   1.1.1.6  christos 	  {
   2908   1.1.1.6  christos 	    /* These relocations implicitly reference __c6xabi_DSBT_BASE.
   2909   1.1.1.6  christos 	       Add an explicit reference so that the symbol will be
   2910   1.1.1.6  christos 	       provided by a linker script.  */
   2911   1.1.1.6  christos 	    struct bfd_link_hash_entry *bh = NULL;
   2912   1.1.1.6  christos 	    if (!_bfd_generic_link_add_one_symbol (info, abfd,
   2913   1.1.1.6  christos 						   "__c6xabi_DSBT_BASE",
   2914   1.1.1.6  christos 						   BSF_GLOBAL,
   2915   1.1.1.8  christos 						   bfd_und_section_ptr, 0,
   2916   1.1.1.8  christos 						   NULL, false, false, &bh))
   2917   1.1.1.6  christos 	      return false;
   2918   1.1.1.6  christos 	    ((struct elf_link_hash_entry *) bh)->non_elf = 0;
   2919   1.1.1.3  christos 	  }
   2920   1.1.1.2  christos 	  if (h != NULL && bfd_link_executable (info))
   2921   1.1.1.2  christos 	    {
   2922   1.1.1.2  christos 	      /* For B14-relative addresses, we might need a copy
   2923   1.1.1.2  christos 		 reloc.  */
   2924   1.1.1.2  christos 	      h->non_got_ref = 1;
   2925   1.1.1.2  christos 	    }
   2926   1.1.1.2  christos 	  break;
   2927   1.1.1.2  christos 
   2928   1.1.1.2  christos 	default:
   2929   1.1.1.2  christos 	  break;
   2930   1.1.1.2  christos 	}
   2931   1.1.1.2  christos     }
   2932   1.1.1.8  christos 
   2933   1.1.1.2  christos   return true;
   2934   1.1.1.2  christos }
   2935   1.1.1.8  christos 
   2936   1.1.1.2  christos static bool
   2937   1.1.1.2  christos elf32_tic6x_add_symbol_hook (bfd *abfd,
   2938   1.1.1.2  christos 			     struct bfd_link_info *info ATTRIBUTE_UNUSED,
   2939   1.1.1.2  christos 			     Elf_Internal_Sym *sym,
   2940   1.1.1.2  christos 			     const char **namep ATTRIBUTE_UNUSED,
   2941   1.1.1.2  christos 			     flagword *flagsp ATTRIBUTE_UNUSED,
   2942   1.1.1.2  christos 			     asection **secp,
   2943   1.1.1.2  christos 			     bfd_vma *valp)
   2944   1.1.1.2  christos {
   2945   1.1.1.2  christos   switch (sym->st_shndx)
   2946   1.1.1.2  christos     {
   2947   1.1.1.2  christos     case SHN_TIC6X_SCOMMON:
   2948   1.1.1.8  christos       *secp = bfd_make_section_old_way (abfd, ".scommon");
   2949   1.1.1.2  christos       (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
   2950   1.1.1.7  christos       *valp = sym->st_size;
   2951   1.1.1.2  christos       bfd_set_section_alignment (*secp, bfd_log2 (sym->st_value));
   2952   1.1.1.2  christos       break;
   2953   1.1.1.2  christos     }
   2954   1.1.1.8  christos 
   2955   1.1.1.2  christos   return true;
   2956   1.1.1.2  christos }
   2957   1.1.1.2  christos 
   2958   1.1.1.2  christos static void
   2959   1.1.1.2  christos elf32_tic6x_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
   2960   1.1.1.2  christos {
   2961   1.1.1.2  christos   elf_symbol_type *elfsym;
   2962   1.1.1.2  christos 
   2963   1.1.1.2  christos   elfsym = (elf_symbol_type *) asym;
   2964   1.1.1.2  christos   switch (elfsym->internal_elf_sym.st_shndx)
   2965   1.1.1.2  christos     {
   2966   1.1.1.2  christos     case SHN_TIC6X_SCOMMON:
   2967   1.1.1.2  christos       asym->section = &tic6x_elf_scom_section;
   2968   1.1.1.2  christos       asym->value = elfsym->internal_elf_sym.st_size;
   2969   1.1.1.2  christos       break;
   2970   1.1.1.2  christos     }
   2971   1.1.1.2  christos }
   2972   1.1.1.2  christos 
   2973   1.1.1.2  christos static int
   2974   1.1.1.2  christos elf32_tic6x_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   2975   1.1.1.2  christos 				     const char *name ATTRIBUTE_UNUSED,
   2976   1.1.1.2  christos 				     Elf_Internal_Sym *sym,
   2977   1.1.1.2  christos 				     asection *input_sec,
   2978   1.1.1.2  christos 				     struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
   2979   1.1.1.2  christos {
   2980   1.1.1.2  christos   /* If we see a common symbol, which implies a relocatable link, then
   2981   1.1.1.2  christos      if a symbol was small common in an input file, mark it as small
   2982   1.1.1.2  christos      common in the output file.  */
   2983   1.1.1.2  christos   if (sym->st_shndx == SHN_COMMON && strcmp (input_sec->name, ".scommon") == 0)
   2984   1.1.1.2  christos     sym->st_shndx = SHN_TIC6X_SCOMMON;
   2985   1.1.1.2  christos 
   2986   1.1.1.2  christos   return 1;
   2987   1.1.1.2  christos }
   2988   1.1.1.8  christos 
   2989   1.1.1.2  christos static bool
   2990   1.1.1.2  christos elf32_tic6x_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
   2991   1.1.1.2  christos 				      asection *sec,
   2992   1.1.1.2  christos 				      int *retval)
   2993   1.1.1.7  christos {
   2994   1.1.1.2  christos   if (strcmp (bfd_section_name (sec), ".scommon") == 0)
   2995   1.1.1.2  christos     {
   2996   1.1.1.8  christos       *retval = SHN_TIC6X_SCOMMON;
   2997   1.1.1.2  christos       return true;
   2998   1.1.1.2  christos     }
   2999   1.1.1.8  christos 
   3000   1.1.1.2  christos   return false;
   3001   1.1.1.2  christos }
   3002   1.1.1.2  christos 
   3003   1.1.1.2  christos /* Allocate space in .plt, .got and associated reloc sections for
   3004   1.1.1.2  christos    dynamic relocs.  */
   3005   1.1.1.8  christos 
   3006   1.1.1.2  christos static bool
   3007   1.1.1.2  christos elf32_tic6x_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   3008   1.1.1.2  christos {
   3009   1.1.1.2  christos   struct bfd_link_info *info;
   3010   1.1.1.2  christos   struct elf32_tic6x_link_hash_table *htab;
   3011   1.1.1.2  christos   struct elf_dyn_relocs *p;
   3012   1.1.1.2  christos 
   3013   1.1.1.8  christos   if (h->root.type == bfd_link_hash_indirect)
   3014   1.1.1.2  christos     return true;
   3015   1.1.1.2  christos 
   3016   1.1.1.2  christos   info = (struct bfd_link_info *) inf;
   3017   1.1.1.2  christos   htab = elf32_tic6x_hash_table (info);
   3018   1.1.1.2  christos 
   3019   1.1.1.2  christos   if (htab->elf.dynamic_sections_created && h->plt.refcount > 0)
   3020   1.1.1.2  christos     {
   3021   1.1.1.2  christos       /* Make sure this symbol is output as a dynamic symbol.
   3022   1.1.1.2  christos 	 Undefined weak syms won't yet be marked as dynamic.  */
   3023   1.1.1.2  christos       if (h->dynindx == -1 && !h->forced_local)
   3024   1.1.1.2  christos 	{
   3025   1.1.1.8  christos 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   3026   1.1.1.2  christos 	    return false;
   3027   1.1.1.2  christos 	}
   3028   1.1.1.3  christos 
   3029   1.1.1.2  christos       if (bfd_link_pic (info)
   3030   1.1.1.2  christos 	  || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
   3031   1.1.1.2  christos 	{
   3032   1.1.1.2  christos 	  asection *s = htab->elf.splt;
   3033   1.1.1.2  christos 
   3034   1.1.1.2  christos 	  /* If this is the first .plt entry, make room for the special
   3035   1.1.1.2  christos 	     first entry.  */
   3036   1.1.1.2  christos 	  if (s->size == 0)
   3037   1.1.1.2  christos 	    s->size += PLT_ENTRY_SIZE;
   3038   1.1.1.2  christos 
   3039   1.1.1.2  christos 	  h->plt.offset = s->size;
   3040   1.1.1.2  christos 
   3041   1.1.1.2  christos 	  /* If this symbol is not defined in a regular file, and we are
   3042   1.1.1.2  christos 	     not generating a shared library, then set the symbol to this
   3043   1.1.1.2  christos 	     location in the .plt.  This is required to make function
   3044   1.1.1.2  christos 	     pointers compare as equal between the normal executable and
   3045   1.1.1.3  christos 	     the shared library.  */
   3046   1.1.1.2  christos 	  if (! bfd_link_pic (info) && !h->def_regular)
   3047   1.1.1.2  christos 	    {
   3048   1.1.1.2  christos 	      h->root.u.def.section = s;
   3049   1.1.1.2  christos 	      h->root.u.def.value = h->plt.offset;
   3050   1.1.1.2  christos 	    }
   3051   1.1.1.2  christos 
   3052   1.1.1.2  christos 	  /* Make room for this entry.  */
   3053   1.1.1.2  christos 	  s->size += PLT_ENTRY_SIZE;
   3054   1.1.1.2  christos 	  /* We also need to make an entry in the .got.plt section, which
   3055   1.1.1.2  christos 	     will be placed in the .got section by the linker script.  */
   3056   1.1.1.2  christos 	  htab->elf.sgotplt->size += 4;
   3057   1.1.1.2  christos 	  /* We also need to make an entry in the .rel.plt section.  */
   3058   1.1.1.2  christos 	  htab->elf.srelplt->size += sizeof (Elf32_External_Rela);
   3059   1.1.1.2  christos 	}
   3060   1.1.1.2  christos       else
   3061   1.1.1.2  christos 	{
   3062   1.1.1.2  christos 	  h->plt.offset = (bfd_vma) -1;
   3063   1.1.1.2  christos 	  h->needs_plt = 0;
   3064   1.1.1.2  christos 	}
   3065   1.1.1.2  christos     }
   3066   1.1.1.2  christos   else
   3067   1.1.1.2  christos     {
   3068   1.1.1.2  christos       h->plt.offset = (bfd_vma) -1;
   3069   1.1.1.2  christos       h->needs_plt = 0;
   3070   1.1.1.2  christos     }
   3071   1.1.1.2  christos 
   3072   1.1.1.2  christos   if (h->got.refcount > 0)
   3073   1.1.1.2  christos     {
   3074   1.1.1.2  christos       asection *s;
   3075   1.1.1.2  christos 
   3076   1.1.1.2  christos       /* Make sure this symbol is output as a dynamic symbol.
   3077   1.1.1.2  christos 	 Undefined weak syms won't yet be marked as dynamic.  */
   3078   1.1.1.2  christos       if (h->dynindx == -1
   3079   1.1.1.2  christos 	  && !h->forced_local)
   3080   1.1.1.2  christos 	{
   3081   1.1.1.8  christos 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   3082   1.1.1.2  christos 	    return false;
   3083   1.1.1.2  christos 	}
   3084   1.1.1.2  christos 
   3085   1.1.1.2  christos       s = htab->elf.sgot;
   3086   1.1.1.2  christos       h->got.offset = s->size;
   3087   1.1.1.2  christos       s->size += 4;
   3088   1.1.1.2  christos 
   3089   1.1.1.2  christos       if (!(ELF_ST_VISIBILITY (h->other)
   3090   1.1.1.2  christos 	    && h->root.type == bfd_link_hash_undefweak))
   3091   1.1.1.2  christos 	htab->elf.srelgot->size += sizeof (Elf32_External_Rela);
   3092   1.1.1.2  christos     }
   3093   1.1.1.2  christos   else
   3094   1.1.1.2  christos     h->got.offset = (bfd_vma) -1;
   3095   1.1.1.8  christos 
   3096   1.1.1.8  christos   if (h->dyn_relocs == NULL)
   3097   1.1.1.2  christos     return true;
   3098   1.1.1.2  christos 
   3099   1.1.1.2  christos   /* Discard relocs on undefined weak syms with non-default
   3100   1.1.1.3  christos      visibility.  */
   3101   1.1.1.2  christos   if (bfd_link_pic (info) || elf32_tic6x_using_dsbt (htab->obfd))
   3102   1.1.1.2  christos     {
   3103   1.1.1.2  christos       /* We use the pc_count field to hold the number of
   3104   1.1.1.2  christos 	 R_C6000_DSBT_INDEX relocs.  */
   3105   1.1.1.2  christos       if (htab->params.dsbt_index != 0)
   3106   1.1.1.2  christos 	{
   3107   1.1.1.2  christos 	  struct elf_dyn_relocs **pp;
   3108   1.1.1.8  christos 
   3109   1.1.1.2  christos 	  for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
   3110   1.1.1.2  christos 	    {
   3111   1.1.1.2  christos 	      p->count -= p->pc_count;
   3112   1.1.1.2  christos 	      p->pc_count = 0;
   3113   1.1.1.2  christos 	      if (p->count == 0)
   3114   1.1.1.2  christos 		*pp = p->next;
   3115   1.1.1.2  christos 	      else
   3116   1.1.1.2  christos 		pp = &p->next;
   3117   1.1.1.2  christos 	    }
   3118   1.1.1.2  christos 	}
   3119   1.1.1.8  christos 
   3120   1.1.1.2  christos       if (h->dyn_relocs != NULL
   3121   1.1.1.2  christos 	  && h->root.type == bfd_link_hash_undefweak)
   3122   1.1.1.2  christos 	{
   3123   1.1.1.8  christos 	  if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
   3124   1.1.1.2  christos 	    h->dyn_relocs = NULL;
   3125   1.1.1.2  christos 
   3126   1.1.1.2  christos 	  /* Make sure undefined weak symbols are output as a dynamic
   3127   1.1.1.2  christos 	     symbol in PIEs.  */
   3128   1.1.1.2  christos 	  else if (h->dynindx == -1
   3129   1.1.1.2  christos 		   && !h->forced_local)
   3130   1.1.1.2  christos 	    {
   3131   1.1.1.8  christos 	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
   3132   1.1.1.2  christos 		return false;
   3133   1.1.1.2  christos 	    }
   3134   1.1.1.2  christos 	}
   3135   1.1.1.2  christos     }
   3136   1.1.1.2  christos 
   3137   1.1.1.8  christos   /* Finally, allocate space.  */
   3138   1.1.1.2  christos   for (p = h->dyn_relocs; p != NULL; p = p->next)
   3139   1.1.1.2  christos     {
   3140   1.1.1.2  christos       asection *sreloc;
   3141   1.1.1.2  christos 
   3142   1.1.1.2  christos       sreloc = elf_section_data (p->sec)->sreloc;
   3143   1.1.1.2  christos 
   3144   1.1.1.2  christos       BFD_ASSERT (sreloc != NULL);
   3145   1.1.1.2  christos       sreloc->size += p->count * sizeof (Elf32_External_Rela);
   3146   1.1.1.2  christos     }
   3147   1.1.1.8  christos 
   3148   1.1.1.2  christos   return true;
   3149   1.1.1.2  christos }
   3150   1.1.1.2  christos 
   3151   1.1.1.2  christos /* Set the sizes of the dynamic sections.  */
   3152   1.1.1.8  christos 
   3153  1.1.1.10  christos static bool
   3154   1.1.1.2  christos elf32_tic6x_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
   3155   1.1.1.2  christos {
   3156   1.1.1.2  christos   struct elf32_tic6x_link_hash_table *htab;
   3157   1.1.1.2  christos   bfd *dynobj;
   3158   1.1.1.8  christos   asection *s;
   3159   1.1.1.2  christos   bool relocs;
   3160   1.1.1.2  christos   bfd *ibfd;
   3161   1.1.1.2  christos 
   3162   1.1.1.2  christos   htab = elf32_tic6x_hash_table (info);
   3163   1.1.1.2  christos   dynobj = htab->elf.dynobj;
   3164  1.1.1.10  christos   if (dynobj == NULL)
   3165   1.1.1.2  christos     return true;
   3166   1.1.1.2  christos 
   3167   1.1.1.2  christos   if (htab->elf.dynamic_sections_created)
   3168   1.1.1.2  christos     {
   3169   1.1.1.3  christos       /* Set the contents of the .interp section to the interpreter.  */
   3170   1.1.1.2  christos       if (bfd_link_executable (info) && !info->nointerp)
   3171  1.1.1.11  christos 	{
   3172   1.1.1.2  christos 	  s = htab->elf.interp;
   3173   1.1.1.2  christos 	  if (s == NULL)
   3174   1.1.1.2  christos 	    abort ();
   3175   1.1.1.2  christos 	  s->size = sizeof ELF_DYNAMIC_INTERPRETER;
   3176  1.1.1.10  christos 	  s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
   3177   1.1.1.2  christos 	  s->alloced = 1;
   3178   1.1.1.2  christos 	}
   3179   1.1.1.2  christos     }
   3180   1.1.1.2  christos 
   3181   1.1.1.2  christos   /* Set up .got offsets for local syms, and space for local dynamic
   3182   1.1.1.3  christos      relocs.  */
   3183   1.1.1.2  christos   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
   3184   1.1.1.2  christos     {
   3185   1.1.1.2  christos       bfd_signed_vma *local_got;
   3186   1.1.1.2  christos       bfd_signed_vma *end_local_got;
   3187   1.1.1.2  christos       bfd_size_type locsymcount;
   3188   1.1.1.2  christos       Elf_Internal_Shdr *symtab_hdr;
   3189   1.1.1.2  christos       asection *srel;
   3190   1.1.1.2  christos 
   3191   1.1.1.2  christos       for (s = ibfd->sections; s != NULL; s = s->next)
   3192   1.1.1.2  christos 	{
   3193   1.1.1.2  christos 	  struct elf_dyn_relocs *p;
   3194   1.1.1.2  christos 
   3195   1.1.1.2  christos 	  for (p = ((struct elf_dyn_relocs *)
   3196   1.1.1.2  christos 		     elf_section_data (s)->local_dynrel);
   3197   1.1.1.2  christos 	       p != NULL;
   3198   1.1.1.2  christos 	       p = p->next)
   3199   1.1.1.2  christos 	    {
   3200   1.1.1.2  christos 	      if (!bfd_is_abs_section (p->sec)
   3201   1.1.1.2  christos 		  && bfd_is_abs_section (p->sec->output_section))
   3202   1.1.1.2  christos 		{
   3203   1.1.1.2  christos 		  /* Input section has been discarded, either because
   3204   1.1.1.2  christos 		     it is a copy of a linkonce section or due to
   3205   1.1.1.2  christos 		     linker script /DISCARD/, so we'll be discarding
   3206   1.1.1.2  christos 		     the relocs too.  */
   3207   1.1.1.2  christos 		}
   3208   1.1.1.2  christos 	      else if (p->count != 0)
   3209   1.1.1.2  christos 		{
   3210   1.1.1.2  christos 		  srel = elf_section_data (p->sec)->sreloc;
   3211   1.1.1.2  christos 		  srel->size += p->count * sizeof (Elf32_External_Rela);
   3212   1.1.1.2  christos 		  if ((p->sec->output_section->flags & SEC_READONLY) != 0)
   3213   1.1.1.2  christos 		    info->flags |= DF_TEXTREL;
   3214   1.1.1.2  christos 		}
   3215   1.1.1.2  christos 	    }
   3216   1.1.1.2  christos 	}
   3217   1.1.1.2  christos 
   3218   1.1.1.2  christos       local_got = elf_local_got_refcounts (ibfd);
   3219   1.1.1.2  christos       if (!local_got)
   3220   1.1.1.2  christos 	continue;
   3221   1.1.1.2  christos 
   3222   1.1.1.2  christos       symtab_hdr = &elf_symtab_hdr (ibfd);
   3223   1.1.1.2  christos       locsymcount = symtab_hdr->sh_info;
   3224   1.1.1.2  christos       end_local_got = local_got + locsymcount;
   3225   1.1.1.2  christos       s = htab->elf.sgot;
   3226   1.1.1.3  christos       srel = htab->elf.srelgot;
   3227   1.1.1.2  christos       for (; local_got < end_local_got; ++local_got)
   3228   1.1.1.2  christos 	{
   3229   1.1.1.2  christos 	  if (*local_got > 0)
   3230   1.1.1.2  christos 	    {
   3231   1.1.1.2  christos 	      *local_got = s->size;
   3232   1.1.1.2  christos 	      s->size += 4;
   3233   1.1.1.3  christos 
   3234   1.1.1.2  christos 	      if (bfd_link_pic (info) || elf32_tic6x_using_dsbt (output_bfd))
   3235   1.1.1.2  christos 		{
   3236   1.1.1.2  christos 		  srel->size += sizeof (Elf32_External_Rela);
   3237   1.1.1.2  christos 		}
   3238   1.1.1.2  christos 	    }
   3239   1.1.1.2  christos 	  else
   3240   1.1.1.2  christos 	    *local_got = (bfd_vma) -1;
   3241   1.1.1.2  christos 	}
   3242   1.1.1.2  christos     }
   3243   1.1.1.2  christos 
   3244   1.1.1.2  christos   /* Allocate global sym .plt and .got entries, and space for global
   3245   1.1.1.2  christos      sym dynamic relocs.  */
   3246   1.1.1.2  christos   elf_link_hash_traverse (&htab->elf, elf32_tic6x_allocate_dynrelocs, info);
   3247   1.1.1.2  christos 
   3248   1.1.1.2  christos   /* We now have determined the sizes of the various dynamic sections.
   3249   1.1.1.8  christos      Allocate memory for them.  */
   3250   1.1.1.2  christos   relocs = false;
   3251   1.1.1.2  christos   for (s = dynobj->sections; s != NULL; s = s->next)
   3252   1.1.1.8  christos     {
   3253   1.1.1.2  christos       bool strip_section = true;
   3254   1.1.1.2  christos 
   3255   1.1.1.2  christos       if ((s->flags & SEC_LINKER_CREATED) == 0)
   3256   1.1.1.2  christos 	continue;
   3257   1.1.1.2  christos 
   3258   1.1.1.2  christos       if (s == htab->dsbt)
   3259   1.1.1.2  christos 	s->size = 4 * htab->params.dsbt_size;
   3260   1.1.1.2  christos       else if (s == htab->elf.splt
   3261   1.1.1.2  christos 	       || s == htab->elf.sgot
   3262   1.1.1.5  christos 	       || s == htab->elf.sgotplt
   3263   1.1.1.5  christos 	       || s == htab->elf.sdynbss
   3264   1.1.1.2  christos 	       || s == htab->elf.sdynrelro)
   3265   1.1.1.2  christos 	{
   3266   1.1.1.2  christos 	  /* Strip this section if we don't need it; see the
   3267   1.1.1.2  christos 	     comment below.  */
   3268   1.1.1.2  christos 	  /* We'd like to strip these sections if they aren't needed, but if
   3269   1.1.1.2  christos 	     we've exported dynamic symbols from them we must leave them.
   3270   1.1.1.2  christos 	     It's too late to tell BFD to get rid of the symbols.  */
   3271   1.1.1.2  christos 
   3272   1.1.1.8  christos 	  if (htab->elf.hplt != NULL)
   3273   1.1.1.2  christos 	    strip_section = false;
   3274   1.1.1.2  christos 
   3275   1.1.1.2  christos 	  /* Round up the size of the PLT section to a multiple of 32.  */
   3276   1.1.1.2  christos 	  if (s == htab->elf.splt && s->size > 0)
   3277   1.1.1.2  christos 	    s->size = (s->size + 31) & ~(bfd_vma)31;
   3278   1.1.1.8  christos 	}
   3279   1.1.1.2  christos       else if (startswith (bfd_section_name (s), ".rela"))
   3280   1.1.1.2  christos 	{
   3281   1.1.1.2  christos 	  if (s->size != 0
   3282   1.1.1.8  christos 	      && s != htab->elf.srelplt)
   3283   1.1.1.2  christos 	    relocs = true;
   3284   1.1.1.2  christos 
   3285   1.1.1.2  christos 	  /* We use the reloc_count field as a counter if we need
   3286   1.1.1.2  christos 	     to copy relocs into the output file.  */
   3287   1.1.1.2  christos 	  s->reloc_count = 0;
   3288   1.1.1.2  christos 	}
   3289   1.1.1.2  christos       else
   3290   1.1.1.2  christos 	{
   3291   1.1.1.2  christos 	  /* It's not one of our sections, so don't allocate space.  */
   3292   1.1.1.2  christos 	  continue;
   3293   1.1.1.2  christos 	}
   3294   1.1.1.2  christos 
   3295   1.1.1.2  christos       if (s->size == 0)
   3296   1.1.1.2  christos 	{
   3297   1.1.1.2  christos 	  /* If we don't need this section, strip it from the
   3298   1.1.1.2  christos 	     output file.  This is mostly to handle .rel.bss and
   3299   1.1.1.2  christos 	     .rel.plt.  We must create both sections in
   3300   1.1.1.2  christos 	     create_dynamic_sections, because they must be created
   3301   1.1.1.2  christos 	     before the linker maps input sections to output
   3302   1.1.1.2  christos 	     sections.  The linker does that before
   3303   1.1.1.2  christos 	     adjust_dynamic_symbol is called, and it is that
   3304   1.1.1.2  christos 	     function which decides whether anything needs to go
   3305   1.1.1.2  christos 	     into these sections.  */
   3306   1.1.1.2  christos 	  if (strip_section)
   3307   1.1.1.2  christos 	    s->flags |= SEC_EXCLUDE;
   3308   1.1.1.2  christos 	  continue;
   3309   1.1.1.2  christos 	}
   3310   1.1.1.2  christos 
   3311   1.1.1.2  christos       if ((s->flags & SEC_HAS_CONTENTS) == 0)
   3312   1.1.1.2  christos 	continue;
   3313   1.1.1.2  christos 
   3314   1.1.1.2  christos       /* Allocate memory for the section contents.  We use bfd_zalloc
   3315   1.1.1.2  christos 	 here in case unused entries are not reclaimed before the
   3316   1.1.1.2  christos 	 section's contents are written out.  This should not happen,
   3317   1.1.1.2  christos 	 but this way if it does, we get a R_C6000_NONE reloc instead
   3318   1.1.1.2  christos 	 of garbage.  */
   3319   1.1.1.2  christos       s->contents = bfd_zalloc (dynobj, s->size);
   3320   1.1.1.8  christos       if (s->contents == NULL)
   3321  1.1.1.10  christos 	return false;
   3322   1.1.1.2  christos       s->alloced = 1;
   3323   1.1.1.2  christos     }
   3324   1.1.1.2  christos 
   3325   1.1.1.2  christos   if (htab->elf.dynamic_sections_created)
   3326   1.1.1.2  christos     {
   3327   1.1.1.2  christos       /* Add some entries to the .dynamic section.  We fill in the
   3328   1.1.1.2  christos 	 values later, in elf32_tic6x_finish_dynamic_sections, but we
   3329   1.1.1.2  christos 	 must add the entries now so that we get the correct size for
   3330   1.1.1.2  christos 	 the .dynamic section.  The DT_DEBUG entry is filled in by the
   3331   1.1.1.2  christos 	 dynamic linker and used by the debugger.  */
   3332   1.1.1.2  christos #define add_dynamic_entry(TAG, VAL) \
   3333   1.1.1.2  christos   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
   3334   1.1.1.8  christos 
   3335   1.1.1.8  christos       if (!_bfd_elf_add_dynamic_tags (output_bfd, info, relocs))
   3336   1.1.1.2  christos 	return false;
   3337   1.1.1.2  christos 
   3338   1.1.1.2  christos       if (!add_dynamic_entry (DT_C6000_DSBT_BASE, 0)
   3339   1.1.1.2  christos 	  || !add_dynamic_entry (DT_C6000_DSBT_SIZE, htab->params.dsbt_size)
   3340   1.1.1.2  christos 	  || !add_dynamic_entry (DT_C6000_DSBT_INDEX,
   3341   1.1.1.8  christos 				 htab->params.dsbt_index))
   3342   1.1.1.2  christos 	return false;
   3343   1.1.1.2  christos 
   3344   1.1.1.2  christos     }
   3345   1.1.1.2  christos #undef add_dynamic_entry
   3346   1.1.1.8  christos 
   3347   1.1.1.2  christos   return true;
   3348   1.1.1.2  christos }
   3349   1.1.1.2  christos 
   3350   1.1.1.2  christos /* This function is called after all the input files have been read,
   3351   1.1.1.2  christos    and the input sections have been assigned to output sections.  */
   3352   1.1.1.8  christos 
   3353  1.1.1.10  christos static bool
   3354   1.1.1.2  christos elf32_tic6x_early_size_sections (bfd *output_bfd, struct bfd_link_info *info)
   3355   1.1.1.3  christos {
   3356   1.1.1.3  christos   if (elf32_tic6x_using_dsbt (output_bfd) && !bfd_link_relocatable (info)
   3357   1.1.1.3  christos       && !bfd_elf_stack_segment_size (output_bfd, info,
   3358   1.1.1.8  christos 				      "__stacksize", DEFAULT_STACK_SIZE))
   3359   1.1.1.2  christos     return false;
   3360   1.1.1.8  christos 
   3361   1.1.1.2  christos   return true;
   3362   1.1.1.2  christos }
   3363   1.1.1.8  christos 
   3364   1.1.1.2  christos static bool
   3365  1.1.1.11  christos elf32_tic6x_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   3366  1.1.1.11  christos 				     struct bfd_link_info *info,
   3367   1.1.1.2  christos 				     bfd_byte *buf ATTRIBUTE_UNUSED)
   3368   1.1.1.2  christos {
   3369   1.1.1.2  christos   struct elf32_tic6x_link_hash_table *htab;
   3370   1.1.1.2  christos   bfd *dynobj;
   3371   1.1.1.2  christos   asection *sdyn;
   3372   1.1.1.2  christos 
   3373   1.1.1.2  christos   htab = elf32_tic6x_hash_table (info);
   3374   1.1.1.2  christos   dynobj = htab->elf.dynobj;
   3375       1.1  christos   sdyn = bfd_get_linker_section (dynobj, ".dynamic");
   3376   1.1.1.2  christos 
   3377   1.1.1.2  christos   if (elf_hash_table (info)->dynamic_sections_created)
   3378   1.1.1.2  christos     {
   3379   1.1.1.2  christos       Elf32_External_Dyn * dyncon;
   3380       1.1  christos       Elf32_External_Dyn * dynconend;
   3381   1.1.1.2  christos 
   3382       1.1  christos       BFD_ASSERT (sdyn != NULL);
   3383   1.1.1.2  christos 
   3384   1.1.1.2  christos       dyncon = (Elf32_External_Dyn *) sdyn->contents;
   3385   1.1.1.2  christos       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
   3386   1.1.1.2  christos 
   3387       1.1  christos       for (; dyncon < dynconend; dyncon++)
   3388   1.1.1.2  christos 	{
   3389   1.1.1.2  christos 	  Elf_Internal_Dyn dyn;
   3390       1.1  christos 	  asection *s;
   3391   1.1.1.2  christos 
   3392       1.1  christos 	  bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
   3393   1.1.1.2  christos 
   3394       1.1  christos 	  switch (dyn.d_tag)
   3395   1.1.1.2  christos 	    {
   3396       1.1  christos 	    default:
   3397       1.1  christos 	      break;
   3398   1.1.1.2  christos 
   3399   1.1.1.2  christos 	    case DT_C6000_DSBT_BASE:
   3400   1.1.1.2  christos 	      s = htab->dsbt;
   3401       1.1  christos 	      dyn.d_un.d_ptr = (s->output_section->vma + s->output_offset);
   3402       1.1  christos 	      break;
   3403   1.1.1.2  christos 
   3404   1.1.1.2  christos 	    case DT_PLTGOT:
   3405   1.1.1.2  christos 	      s = htab->elf.sgotplt;
   3406   1.1.1.2  christos 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   3407       1.1  christos 	      break;
   3408   1.1.1.2  christos 
   3409   1.1.1.2  christos 	    case DT_JMPREL:
   3410   1.1.1.2  christos 	      s = htab->elf.srelplt;
   3411   1.1.1.2  christos 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   3412       1.1  christos 	      break;
   3413   1.1.1.2  christos 
   3414   1.1.1.2  christos 	    case DT_PLTRELSZ:
   3415   1.1.1.2  christos 	      s = htab->elf.srelplt;
   3416       1.1  christos 	      dyn.d_un.d_val = s->size;
   3417       1.1  christos 	      break;
   3418   1.1.1.2  christos 	    }
   3419   1.1.1.2  christos 	  bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   3420   1.1.1.2  christos 	}
   3421   1.1.1.2  christos 
   3422   1.1.1.2  christos       /* Fill in the first entry in the procedure linkage table.  */
   3423   1.1.1.2  christos       if (htab->elf.splt && htab->elf.splt->size > 0)
   3424   1.1.1.2  christos 	{
   3425   1.1.1.2  christos 	  bfd_vma got_offs = (htab->elf.sgotplt->output_section->vma
   3426   1.1.1.2  christos 			      + htab->elf.sgotplt->output_offset
   3427   1.1.1.2  christos 			      - htab->dsbt->output_section->vma
   3428   1.1.1.2  christos 			      - htab->dsbt->output_offset) / 4;
   3429   1.1.1.2  christos 
   3430   1.1.1.2  christos 	  /* ldw .D2T2 *+b14[$GOT(0)],b2 */
   3431   1.1.1.2  christos 	  bfd_put_32 (output_bfd, got_offs << 8 | 0x0100006e,
   3432   1.1.1.2  christos 		      htab->elf.splt->contents);
   3433   1.1.1.2  christos 	  /* ldw .D2T2 *+b14[$GOT(4)],b1 */
   3434   1.1.1.2  christos 	  bfd_put_32 (output_bfd, (got_offs + 1) << 8 | 0x0080006e,
   3435   1.1.1.2  christos 		      htab->elf.splt->contents + 4);
   3436   1.1.1.2  christos 	  /* nop 3 */
   3437   1.1.1.2  christos 	  bfd_put_32 (output_bfd, 0x00004000,
   3438   1.1.1.2  christos 		      htab->elf.splt->contents + 8);
   3439   1.1.1.2  christos 	  /* b .s2 b2 */
   3440   1.1.1.2  christos 	  bfd_put_32 (output_bfd, 0x00080362,
   3441   1.1.1.2  christos 		      htab->elf.splt->contents + 12);
   3442   1.1.1.2  christos 	  /* nop 5 */
   3443   1.1.1.2  christos 	  bfd_put_32 (output_bfd, 0x00008000,
   3444   1.1.1.2  christos 		      htab->elf.splt->contents + 16);
   3445   1.1.1.2  christos 
   3446   1.1.1.2  christos 	  elf_section_data (htab->elf.splt->output_section)
   3447       1.1  christos 	    ->this_hdr.sh_entsize = PLT_ENTRY_SIZE;
   3448       1.1  christos 	}
   3449       1.1  christos     }
   3450   1.1.1.8  christos 
   3451   1.1.1.2  christos   return true;
   3452   1.1.1.2  christos }
   3453   1.1.1.2  christos 
   3454   1.1.1.2  christos /* Return address for Ith PLT stub in section PLT, for relocation REL
   3455   1.1.1.2  christos    or (bfd_vma) -1 if it should not be included.  */
   3456   1.1.1.2  christos 
   3457   1.1.1.2  christos static bfd_vma
   3458   1.1.1.2  christos elf32_tic6x_plt_sym_val (bfd_vma i, const asection *plt,
   3459   1.1.1.2  christos 			 const arelent *rel ATTRIBUTE_UNUSED)
   3460   1.1.1.2  christos {
   3461       1.1  christos   return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
   3462       1.1  christos }
   3463       1.1  christos 
   3464  1.1.1.11  christos static int
   3465       1.1  christos elf32_tic6x_obj_attrs_arg_type (obj_attr_tag_t tag)
   3466       1.1  christos {
   3467       1.1  christos   if (tag == Tag_ABI_compatibility)
   3468       1.1  christos     return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
   3469       1.1  christos   else if (tag & 1)
   3470       1.1  christos     return ATTR_TYPE_FLAG_STR_VAL;
   3471       1.1  christos   else
   3472       1.1  christos     return ATTR_TYPE_FLAG_INT_VAL;
   3473       1.1  christos }
   3474       1.1  christos 
   3475       1.1  christos static int
   3476       1.1  christos elf32_tic6x_obj_attrs_order (int num)
   3477       1.1  christos {
   3478       1.1  christos   if (num == LEAST_KNOWN_OBJ_ATTRIBUTE)
   3479       1.1  christos     return Tag_ABI_conformance;
   3480       1.1  christos   if ((num - 1) < Tag_ABI_conformance)
   3481       1.1  christos     return num - 1;
   3482       1.1  christos   return num;
   3483       1.1  christos }
   3484   1.1.1.8  christos 
   3485   1.1.1.2  christos static bool
   3486   1.1.1.2  christos elf32_tic6x_obj_attrs_handle_unknown (bfd *abfd, int tag)
   3487   1.1.1.2  christos {
   3488   1.1.1.2  christos   if ((tag & 127) < 64)
   3489   1.1.1.2  christos     {
   3490   1.1.1.5  christos       _bfd_error_handler
   3491   1.1.1.6  christos 	/* xgettext:c-format */
   3492   1.1.1.2  christos 	(_("%pB: error: unknown mandatory EABI object attribute %d"),
   3493   1.1.1.2  christos 	 abfd, tag);
   3494   1.1.1.8  christos       bfd_set_error (bfd_error_bad_value);
   3495   1.1.1.2  christos       return false;
   3496   1.1.1.2  christos     }
   3497   1.1.1.2  christos   else
   3498   1.1.1.2  christos     {
   3499   1.1.1.5  christos       _bfd_error_handler
   3500   1.1.1.6  christos 	/* xgettext:c-format */
   3501   1.1.1.2  christos 	(_("%pB: warning: unknown EABI object attribute %d"),
   3502   1.1.1.8  christos 	 abfd, tag);
   3503   1.1.1.2  christos       return true;
   3504   1.1.1.2  christos     }
   3505   1.1.1.2  christos }
   3506       1.1  christos 
   3507       1.1  christos /* Merge the Tag_ISA attribute values ARCH1 and ARCH2
   3508       1.1  christos    and return the merged value.  At present, all merges succeed, so no
   3509       1.1  christos    return value for errors is defined.  */
   3510       1.1  christos 
   3511       1.1  christos int
   3512       1.1  christos elf32_tic6x_merge_arch_attributes (int arch1, int arch2)
   3513       1.1  christos {
   3514       1.1  christos   int min_arch, max_arch;
   3515       1.1  christos 
   3516       1.1  christos   min_arch = (arch1 < arch2 ? arch1 : arch2);
   3517       1.1  christos   max_arch = (arch1 > arch2 ? arch1 : arch2);
   3518       1.1  christos 
   3519       1.1  christos   /* In most cases, the numerically greatest value is the correct
   3520       1.1  christos      merged value, but merging C64 and C67 results in C674X.  */
   3521       1.1  christos   if ((min_arch == C6XABI_Tag_ISA_C67X
   3522       1.1  christos        || min_arch == C6XABI_Tag_ISA_C67XP)
   3523       1.1  christos       && (max_arch == C6XABI_Tag_ISA_C64X
   3524       1.1  christos 	  || max_arch == C6XABI_Tag_ISA_C64XP))
   3525       1.1  christos     return C6XABI_Tag_ISA_C674X;
   3526       1.1  christos 
   3527       1.1  christos   return max_arch;
   3528       1.1  christos }
   3529       1.1  christos 
   3530       1.1  christos /* Convert a Tag_ABI_array_object_alignment or
   3531       1.1  christos    Tag_ABI_array_object_align_expected tag value TAG to a
   3532       1.1  christos    corresponding alignment value; return the alignment, or -1 for an
   3533       1.1  christos    unknown tag value.  */
   3534       1.1  christos 
   3535       1.1  christos static int
   3536       1.1  christos elf32_tic6x_tag_to_array_alignment (int tag)
   3537       1.1  christos {
   3538       1.1  christos   switch (tag)
   3539       1.1  christos     {
   3540       1.1  christos     case 0:
   3541       1.1  christos       return 8;
   3542       1.1  christos 
   3543       1.1  christos     case 1:
   3544       1.1  christos       return 4;
   3545       1.1  christos 
   3546       1.1  christos     case 2:
   3547       1.1  christos       return 16;
   3548       1.1  christos 
   3549       1.1  christos     default:
   3550       1.1  christos       return -1;
   3551       1.1  christos     }
   3552       1.1  christos }
   3553       1.1  christos 
   3554       1.1  christos /* Convert a Tag_ABI_array_object_alignment or
   3555       1.1  christos    Tag_ABI_array_object_align_expected alignment ALIGN to a
   3556       1.1  christos    corresponding tag value; return the tag value.  */
   3557       1.1  christos 
   3558       1.1  christos static int
   3559       1.1  christos elf32_tic6x_array_alignment_to_tag (int align)
   3560       1.1  christos {
   3561       1.1  christos   switch (align)
   3562       1.1  christos     {
   3563       1.1  christos     case 8:
   3564       1.1  christos       return 0;
   3565       1.1  christos 
   3566       1.1  christos     case 4:
   3567       1.1  christos       return 1;
   3568       1.1  christos 
   3569       1.1  christos     case 16:
   3570       1.1  christos       return 2;
   3571       1.1  christos 
   3572       1.1  christos     default:
   3573       1.1  christos       abort ();
   3574       1.1  christos     }
   3575       1.1  christos }
   3576       1.1  christos 
   3577       1.1  christos /* Merge attributes from IBFD and OBFD, returning TRUE if the merge
   3578       1.1  christos    succeeded, FALSE otherwise.  */
   3579   1.1.1.8  christos 
   3580   1.1.1.5  christos static bool
   3581       1.1  christos elf32_tic6x_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
   3582   1.1.1.5  christos {
   3583   1.1.1.8  christos   bfd *obfd = info->output_bfd;
   3584       1.1  christos   bool result = true;
   3585       1.1  christos   obj_attribute *in_attr;
   3586       1.1  christos   obj_attribute *out_attr;
   3587       1.1  christos   int i;
   3588       1.1  christos   int array_align_in, array_align_out, array_expect_in, array_expect_out;
   3589   1.1.1.8  christos 
   3590   1.1.1.8  christos   /* FIXME: What should be checked when linking shared libraries?  */
   3591   1.1.1.8  christos   if ((ibfd->flags & DYNAMIC) != 0)
   3592   1.1.1.8  christos     return true;
   3593       1.1  christos 
   3594       1.1  christos   if (!elf_known_obj_attributes_proc (obfd)[0].i)
   3595       1.1  christos     {
   3596       1.1  christos       /* This is the first object.  Copy the attributes.  */
   3597       1.1  christos       _bfd_elf_copy_obj_attributes (ibfd, obfd);
   3598       1.1  christos 
   3599       1.1  christos       out_attr = elf_known_obj_attributes_proc (obfd);
   3600       1.1  christos 
   3601       1.1  christos       /* Use the Tag_null value to indicate the attributes have been
   3602       1.1  christos 	 initialized.  */
   3603       1.1  christos       out_attr[0].i = 1;
   3604   1.1.1.8  christos 
   3605       1.1  christos       return true;
   3606       1.1  christos     }
   3607       1.1  christos 
   3608       1.1  christos   in_attr = elf_known_obj_attributes_proc (ibfd);
   3609       1.1  christos   out_attr = elf_known_obj_attributes_proc (obfd);
   3610       1.1  christos 
   3611       1.1  christos   /* No specification yet for handling of unknown attributes, so just
   3612       1.1  christos      ignore them and handle known ones.  */
   3613       1.1  christos 
   3614       1.1  christos   if (out_attr[Tag_ABI_stack_align_preserved].i
   3615       1.1  christos       < in_attr[Tag_ABI_stack_align_needed].i)
   3616       1.1  christos     {
   3617   1.1.1.5  christos       _bfd_error_handler
   3618   1.1.1.6  christos 	/* xgettext:c-format */
   3619       1.1  christos 	(_("error: %pB requires more stack alignment than %pB preserves"),
   3620   1.1.1.8  christos 	 ibfd, obfd);
   3621       1.1  christos       result = false;
   3622       1.1  christos     }
   3623       1.1  christos   if (in_attr[Tag_ABI_stack_align_preserved].i
   3624       1.1  christos       < out_attr[Tag_ABI_stack_align_needed].i)
   3625       1.1  christos     {
   3626   1.1.1.5  christos       _bfd_error_handler
   3627   1.1.1.6  christos 	/* xgettext:c-format */
   3628       1.1  christos 	(_("error: %pB requires more stack alignment than %pB preserves"),
   3629   1.1.1.8  christos 	 obfd, ibfd);
   3630       1.1  christos       result = false;
   3631       1.1  christos     }
   3632       1.1  christos 
   3633       1.1  christos   array_align_in = elf32_tic6x_tag_to_array_alignment
   3634       1.1  christos     (in_attr[Tag_ABI_array_object_alignment].i);
   3635       1.1  christos   if (array_align_in == -1)
   3636       1.1  christos     {
   3637   1.1.1.6  christos       _bfd_error_handler
   3638       1.1  christos 	(_("error: unknown Tag_ABI_array_object_alignment value in %pB"),
   3639   1.1.1.8  christos 	 ibfd);
   3640       1.1  christos       result = false;
   3641       1.1  christos     }
   3642       1.1  christos   array_align_out = elf32_tic6x_tag_to_array_alignment
   3643       1.1  christos     (out_attr[Tag_ABI_array_object_alignment].i);
   3644       1.1  christos   if (array_align_out == -1)
   3645       1.1  christos     {
   3646   1.1.1.6  christos       _bfd_error_handler
   3647       1.1  christos 	(_("error: unknown Tag_ABI_array_object_alignment value in %pB"),
   3648   1.1.1.8  christos 	 obfd);
   3649       1.1  christos       result = false;
   3650       1.1  christos     }
   3651       1.1  christos   array_expect_in = elf32_tic6x_tag_to_array_alignment
   3652       1.1  christos     (in_attr[Tag_ABI_array_object_align_expected].i);
   3653       1.1  christos   if (array_expect_in == -1)
   3654       1.1  christos     {
   3655   1.1.1.6  christos       _bfd_error_handler
   3656       1.1  christos 	(_("error: unknown Tag_ABI_array_object_align_expected value in %pB"),
   3657   1.1.1.8  christos 	 ibfd);
   3658       1.1  christos       result = false;
   3659       1.1  christos     }
   3660       1.1  christos   array_expect_out = elf32_tic6x_tag_to_array_alignment
   3661       1.1  christos     (out_attr[Tag_ABI_array_object_align_expected].i);
   3662       1.1  christos   if (array_expect_out == -1)
   3663       1.1  christos     {
   3664   1.1.1.6  christos       _bfd_error_handler
   3665       1.1  christos 	(_("error: unknown Tag_ABI_array_object_align_expected value in %pB"),
   3666   1.1.1.8  christos 	 obfd);
   3667       1.1  christos       result = false;
   3668       1.1  christos     }
   3669       1.1  christos 
   3670       1.1  christos   if (array_align_out < array_expect_in)
   3671       1.1  christos     {
   3672   1.1.1.5  christos       _bfd_error_handler
   3673   1.1.1.6  christos 	/* xgettext:c-format */
   3674       1.1  christos 	(_("error: %pB requires more array alignment than %pB preserves"),
   3675   1.1.1.8  christos 	 ibfd, obfd);
   3676       1.1  christos       result = false;
   3677       1.1  christos     }
   3678       1.1  christos   if (array_align_in < array_expect_out)
   3679       1.1  christos     {
   3680   1.1.1.5  christos       _bfd_error_handler
   3681   1.1.1.6  christos 	/* xgettext:c-format */
   3682       1.1  christos 	(_("error: %pB requires more array alignment than %pB preserves"),
   3683   1.1.1.8  christos 	 obfd, ibfd);
   3684       1.1  christos       result = false;
   3685       1.1  christos     }
   3686       1.1  christos 
   3687       1.1  christos   for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
   3688       1.1  christos     {
   3689       1.1  christos       switch (i)
   3690       1.1  christos 	{
   3691       1.1  christos 	case Tag_ISA:
   3692       1.1  christos 	  out_attr[i].i = elf32_tic6x_merge_arch_attributes (in_attr[i].i,
   3693       1.1  christos 							     out_attr[i].i);
   3694       1.1  christos 	  break;
   3695       1.1  christos 
   3696       1.1  christos 	case Tag_ABI_wchar_t:
   3697       1.1  christos 	  if (out_attr[i].i == 0)
   3698       1.1  christos 	    out_attr[i].i = in_attr[i].i;
   3699       1.1  christos 	  if (out_attr[i].i != 0
   3700       1.1  christos 	      && in_attr[i].i != 0
   3701       1.1  christos 	      && out_attr[i].i != in_attr[i].i)
   3702       1.1  christos 	    {
   3703   1.1.1.5  christos 	      _bfd_error_handler
   3704   1.1.1.6  christos 		/* xgettext:c-format */
   3705       1.1  christos 		(_("warning: %pB and %pB differ in wchar_t size"), obfd, ibfd);
   3706       1.1  christos 	    }
   3707       1.1  christos 	  break;
   3708       1.1  christos 
   3709       1.1  christos 	case Tag_ABI_stack_align_needed:
   3710       1.1  christos 	  if (out_attr[i].i < in_attr[i].i)
   3711       1.1  christos 	    out_attr[i].i = in_attr[i].i;
   3712       1.1  christos 	  break;
   3713       1.1  christos 
   3714       1.1  christos 	case Tag_ABI_stack_align_preserved:
   3715       1.1  christos 	  if (out_attr[i].i > in_attr[i].i)
   3716       1.1  christos 	    out_attr[i].i = in_attr[i].i;
   3717       1.1  christos 	  break;
   3718       1.1  christos 
   3719       1.1  christos 	case Tag_ABI_DSBT:
   3720       1.1  christos 	  if (out_attr[i].i != in_attr[i].i)
   3721       1.1  christos 	    {
   3722   1.1.1.5  christos 	      _bfd_error_handler
   3723   1.1.1.6  christos 		/* xgettext:c-format */
   3724       1.1  christos 		(_("warning: %pB and %pB differ in whether code is "
   3725       1.1  christos 		   "compiled for DSBT"),
   3726       1.1  christos 		 obfd, ibfd);
   3727       1.1  christos 	    }
   3728       1.1  christos 	  break;
   3729       1.1  christos 
   3730   1.1.1.2  christos 	case Tag_ABI_PIC:
   3731   1.1.1.8  christos 	case Tag_ABI_PID:
   3732   1.1.1.8  christos 	  /* Don't transfer these tags from dynamic objects.  */
   3733   1.1.1.8  christos 	  if ((ibfd->flags & DYNAMIC) != 0)
   3734   1.1.1.2  christos 	    continue;
   3735   1.1.1.2  christos 	  if (out_attr[i].i > in_attr[i].i)
   3736       1.1  christos 	    out_attr[i].i = in_attr[i].i;
   3737       1.1  christos 	  break;
   3738       1.1  christos 
   3739       1.1  christos 	case Tag_ABI_array_object_alignment:
   3740       1.1  christos 	  if (array_align_out != -1
   3741       1.1  christos 	      && array_align_in != -1
   3742       1.1  christos 	      && array_align_out > array_align_in)
   3743       1.1  christos 	    out_attr[i].i
   3744       1.1  christos 	      = elf32_tic6x_array_alignment_to_tag (array_align_in);
   3745       1.1  christos 	  break;
   3746       1.1  christos 
   3747       1.1  christos 	case Tag_ABI_array_object_align_expected:
   3748       1.1  christos 	  if (array_expect_out != -1
   3749       1.1  christos 	      && array_expect_in != -1
   3750       1.1  christos 	      && array_expect_out < array_expect_in)
   3751       1.1  christos 	    out_attr[i].i
   3752       1.1  christos 	      = elf32_tic6x_array_alignment_to_tag (array_expect_in);
   3753       1.1  christos 	  break;
   3754       1.1  christos 
   3755       1.1  christos 	case Tag_ABI_conformance:
   3756       1.1  christos 	  /* Merging for this attribute is not specified.  As on ARM,
   3757       1.1  christos 	     treat a missing attribute as no claim to conform and only
   3758       1.1  christos 	     merge identical values.  */
   3759       1.1  christos 	  if (out_attr[i].s == NULL
   3760       1.1  christos 	      || in_attr[i].s == NULL
   3761       1.1  christos 	      || strcmp (out_attr[i].s,
   3762       1.1  christos 			 in_attr[i].s) != 0)
   3763       1.1  christos 	    out_attr[i].s = NULL;
   3764       1.1  christos 	  break;
   3765   1.1.1.2  christos 
   3766   1.1.1.2  christos 	case Tag_ABI_compatibility:
   3767   1.1.1.2  christos 	  /* Merged in _bfd_elf_merge_object_attributes.  */
   3768   1.1.1.2  christos 	  break;
   3769       1.1  christos 
   3770   1.1.1.2  christos 	default:
   3771   1.1.1.2  christos 	  result
   3772       1.1  christos 	    = result && _bfd_elf_merge_unknown_attribute_low (ibfd, obfd, i);
   3773       1.1  christos 	  break;
   3774       1.1  christos 	}
   3775       1.1  christos 
   3776       1.1  christos       if (in_attr[i].type && !out_attr[i].type)
   3777       1.1  christos 	out_attr[i].type = in_attr[i].type;
   3778       1.1  christos     }
   3779       1.1  christos 
   3780   1.1.1.5  christos   /* Merge Tag_ABI_compatibility attributes and any common GNU ones.  */
   3781   1.1.1.8  christos   if (!_bfd_elf_merge_object_attributes (ibfd, info))
   3782       1.1  christos     return false;
   3783   1.1.1.2  christos 
   3784   1.1.1.2  christos   result &= _bfd_elf_merge_unknown_attribute_list (ibfd, obfd);
   3785       1.1  christos 
   3786       1.1  christos   return result;
   3787       1.1  christos }
   3788   1.1.1.8  christos 
   3789   1.1.1.5  christos static bool
   3790       1.1  christos elf32_tic6x_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   3791   1.1.1.5  christos {
   3792   1.1.1.8  christos   if (!_bfd_generic_verify_endian_match (ibfd, info))
   3793       1.1  christos     return false;
   3794  1.1.1.11  christos 
   3795   1.1.1.8  christos   if (! is_tic6x_elf (ibfd))
   3796   1.1.1.2  christos     return true;
   3797   1.1.1.5  christos 
   3798   1.1.1.8  christos   if (!elf32_tic6x_merge_attributes (ibfd, info))
   3799       1.1  christos     return false;
   3800   1.1.1.8  christos 
   3801       1.1  christos   return true;
   3802       1.1  christos }
   3803   1.1.1.2  christos 
   3804   1.1.1.2  christos /* Add a new unwind edit to the list described by HEAD, TAIL.  If TINDEX is zero,
   3805   1.1.1.2  christos    adds the edit to the start of the list.  (The list must be built in order of
   3806   1.1.1.2  christos    ascending TINDEX: the function's callers are primarily responsible for
   3807   1.1.1.2  christos    maintaining that condition).  */
   3808   1.1.1.2  christos 
   3809   1.1.1.2  christos static void
   3810   1.1.1.2  christos elf32_tic6x_add_unwind_table_edit (tic6x_unwind_table_edit **head,
   3811   1.1.1.2  christos 				   tic6x_unwind_table_edit **tail,
   3812   1.1.1.2  christos 				   tic6x_unwind_edit_type type,
   3813   1.1.1.2  christos 				   asection *linked_section,
   3814   1.1.1.2  christos 				   unsigned int tindex)
   3815   1.1.1.2  christos {
   3816   1.1.1.2  christos   tic6x_unwind_table_edit *new_edit = (tic6x_unwind_table_edit *)
   3817   1.1.1.3  christos       xmalloc (sizeof (tic6x_unwind_table_edit));
   3818   1.1.1.2  christos 
   3819   1.1.1.2  christos   new_edit->type = type;
   3820   1.1.1.2  christos   new_edit->linked_section = linked_section;
   3821   1.1.1.3  christos   new_edit->index = tindex;
   3822   1.1.1.2  christos 
   3823   1.1.1.2  christos   if (tindex > 0)
   3824   1.1.1.2  christos     {
   3825   1.1.1.2  christos       new_edit->next = NULL;
   3826   1.1.1.2  christos 
   3827   1.1.1.2  christos       if (*tail)
   3828   1.1.1.2  christos 	(*tail)->next = new_edit;
   3829   1.1.1.2  christos 
   3830   1.1.1.2  christos       (*tail) = new_edit;
   3831   1.1.1.2  christos 
   3832   1.1.1.2  christos       if (!*head)
   3833   1.1.1.2  christos 	(*head) = new_edit;
   3834   1.1.1.2  christos     }
   3835   1.1.1.2  christos   else
   3836   1.1.1.2  christos     {
   3837   1.1.1.2  christos       new_edit->next = *head;
   3838   1.1.1.2  christos 
   3839   1.1.1.2  christos       if (!*tail)
   3840   1.1.1.2  christos 	*tail = new_edit;
   3841   1.1.1.2  christos 
   3842   1.1.1.2  christos       *head = new_edit;
   3843   1.1.1.2  christos     }
   3844   1.1.1.2  christos }
   3845   1.1.1.2  christos 
   3846   1.1.1.2  christos static _tic6x_elf_section_data *
   3847   1.1.1.2  christos get_tic6x_elf_section_data (asection * sec)
   3848   1.1.1.2  christos {
   3849   1.1.1.2  christos   if (sec && sec->owner && is_tic6x_elf (sec->owner))
   3850   1.1.1.2  christos     return elf32_tic6x_section_data (sec);
   3851   1.1.1.2  christos   else
   3852   1.1.1.2  christos     return NULL;
   3853   1.1.1.2  christos }
   3854   1.1.1.2  christos 
   3855   1.1.1.2  christos 
   3856   1.1.1.2  christos /* Increase the size of EXIDX_SEC by ADJUST bytes.  ADJUST must be negative.  */
   3857   1.1.1.2  christos static void
   3858   1.1.1.2  christos elf32_tic6x_adjust_exidx_size (asection *exidx_sec, int adjust)
   3859   1.1.1.2  christos {
   3860   1.1.1.2  christos   asection *out_sec;
   3861   1.1.1.2  christos 
   3862   1.1.1.2  christos   if (!exidx_sec->rawsize)
   3863   1.1.1.2  christos     exidx_sec->rawsize = exidx_sec->size;
   3864   1.1.1.7  christos 
   3865   1.1.1.2  christos   bfd_set_section_size (exidx_sec, exidx_sec->size + adjust);
   3866   1.1.1.2  christos   out_sec = exidx_sec->output_section;
   3867   1.1.1.7  christos   /* Adjust size of output section.  */
   3868   1.1.1.2  christos   bfd_set_section_size (out_sec, out_sec->size +adjust);
   3869   1.1.1.2  christos }
   3870   1.1.1.2  christos 
   3871   1.1.1.2  christos /* Insert an EXIDX_CANTUNWIND marker at the end of a section.  */
   3872   1.1.1.2  christos static void
   3873   1.1.1.2  christos elf32_tic6x_insert_cantunwind_after (asection *text_sec, asection *exidx_sec)
   3874   1.1.1.2  christos {
   3875   1.1.1.2  christos   struct _tic6x_elf_section_data *exidx_data;
   3876   1.1.1.2  christos 
   3877   1.1.1.2  christos   exidx_data = get_tic6x_elf_section_data (exidx_sec);
   3878   1.1.1.2  christos   elf32_tic6x_add_unwind_table_edit (
   3879   1.1.1.2  christos     &exidx_data->u.exidx.unwind_edit_list,
   3880   1.1.1.2  christos     &exidx_data->u.exidx.unwind_edit_tail,
   3881   1.1.1.2  christos     INSERT_EXIDX_CANTUNWIND_AT_END, text_sec, UINT_MAX);
   3882   1.1.1.2  christos 
   3883   1.1.1.2  christos   elf32_tic6x_adjust_exidx_size (exidx_sec, 8);
   3884   1.1.1.2  christos }
   3885   1.1.1.2  christos 
   3886   1.1.1.2  christos /* Scan .cx6abi.exidx tables, and create a list describing edits which
   3887   1.1.1.3  christos    should be made to those tables, such that:
   3888   1.1.1.2  christos 
   3889   1.1.1.2  christos      1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
   3890   1.1.1.5  christos      2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
   3891   1.1.1.2  christos 	codes which have been inlined into the index).
   3892   1.1.1.2  christos 
   3893   1.1.1.2  christos    If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
   3894   1.1.1.2  christos 
   3895   1.1.1.2  christos    The edits are applied when the tables are written
   3896   1.1.1.2  christos    (in elf32_tic6x_write_section).
   3897   1.1.1.2  christos */
   3898   1.1.1.8  christos 
   3899   1.1.1.2  christos bool
   3900   1.1.1.2  christos elf32_tic6x_fix_exidx_coverage (asection **text_section_order,
   3901   1.1.1.2  christos 				unsigned int num_text_sections,
   3902   1.1.1.8  christos 				struct bfd_link_info *info,
   3903   1.1.1.2  christos 				bool merge_exidx_entries)
   3904   1.1.1.2  christos {
   3905   1.1.1.2  christos   bfd *inp;
   3906   1.1.1.2  christos   unsigned int last_second_word = 0, i;
   3907   1.1.1.2  christos   asection *last_exidx_sec = NULL;
   3908   1.1.1.2  christos   asection *last_text_sec = NULL;
   3909   1.1.1.2  christos   int last_unwind_type = -1;
   3910   1.1.1.2  christos 
   3911   1.1.1.2  christos   /* Walk over all EXIDX sections, and create backlinks from the corrsponding
   3912   1.1.1.3  christos      text sections.  */
   3913   1.1.1.2  christos   for (inp = info->input_bfds; inp != NULL; inp = inp->link.next)
   3914   1.1.1.2  christos     {
   3915   1.1.1.3  christos       asection *sec;
   3916   1.1.1.2  christos 
   3917   1.1.1.5  christos       for (sec = inp->sections; sec != NULL; sec = sec->next)
   3918   1.1.1.2  christos 	{
   3919   1.1.1.2  christos 	  struct bfd_elf_section_data *elf_sec = elf_section_data (sec);
   3920   1.1.1.3  christos 	  Elf_Internal_Shdr *hdr = &elf_sec->this_hdr;
   3921   1.1.1.2  christos 
   3922   1.1.1.2  christos 	  if (!hdr || hdr->sh_type != SHT_C6000_UNWIND)
   3923   1.1.1.3  christos 	    continue;
   3924   1.1.1.2  christos 
   3925   1.1.1.2  christos 	  if (elf_sec->linked_to)
   3926   1.1.1.2  christos 	    {
   3927   1.1.1.5  christos 	      Elf_Internal_Shdr *linked_hdr
   3928   1.1.1.2  christos 		= &elf_section_data (elf_sec->linked_to)->this_hdr;
   3929   1.1.1.5  christos 	      struct _tic6x_elf_section_data *linked_sec_tic6x_data
   3930   1.1.1.2  christos 		= get_tic6x_elf_section_data (linked_hdr->bfd_section);
   3931   1.1.1.2  christos 
   3932   1.1.1.5  christos 	      if (linked_sec_tic6x_data == NULL)
   3933   1.1.1.2  christos 		continue;
   3934   1.1.1.2  christos 
   3935   1.1.1.2  christos 	      /* Link this .c6xabi.exidx section back from the
   3936   1.1.1.2  christos 		 text section it describes.  */
   3937   1.1.1.2  christos 	      linked_sec_tic6x_data->u.text.tic6x_exidx_sec = sec;
   3938   1.1.1.2  christos 	    }
   3939   1.1.1.2  christos 	}
   3940   1.1.1.2  christos     }
   3941   1.1.1.2  christos 
   3942   1.1.1.2  christos   /* Walk all text sections in order of increasing VMA.  Eilminate duplicate
   3943   1.1.1.2  christos      index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
   3944   1.1.1.2  christos      and add EXIDX_CANTUNWIND entries for sections with no unwind table data.  */
   3945   1.1.1.2  christos 
   3946   1.1.1.2  christos   for (i = 0; i < num_text_sections; i++)
   3947   1.1.1.2  christos     {
   3948   1.1.1.2  christos       asection *sec = text_section_order[i];
   3949   1.1.1.2  christos       asection *exidx_sec;
   3950   1.1.1.5  christos       struct _tic6x_elf_section_data *tic6x_data
   3951   1.1.1.2  christos 	= get_tic6x_elf_section_data (sec);
   3952   1.1.1.2  christos       struct _tic6x_elf_section_data *exidx_data;
   3953   1.1.1.2  christos       bfd_byte *contents = NULL;
   3954   1.1.1.2  christos       int deleted_exidx_bytes = 0;
   3955   1.1.1.2  christos       bfd_vma j;
   3956   1.1.1.2  christos       tic6x_unwind_table_edit *unwind_edit_head = NULL;
   3957   1.1.1.2  christos       tic6x_unwind_table_edit *unwind_edit_tail = NULL;
   3958   1.1.1.2  christos       Elf_Internal_Shdr *hdr;
   3959   1.1.1.2  christos       bfd *ibfd;
   3960   1.1.1.2  christos 
   3961   1.1.1.5  christos       if (tic6x_data == NULL)
   3962   1.1.1.2  christos 	continue;
   3963   1.1.1.2  christos 
   3964   1.1.1.2  christos       exidx_sec = tic6x_data->u.text.tic6x_exidx_sec;
   3965   1.1.1.2  christos       if (exidx_sec == NULL)
   3966   1.1.1.2  christos 	{
   3967   1.1.1.2  christos 	  /* Section has no unwind data.  */
   3968   1.1.1.2  christos 	  if (last_unwind_type == 0 || !last_exidx_sec)
   3969   1.1.1.2  christos 	    continue;
   3970   1.1.1.2  christos 
   3971   1.1.1.2  christos 	  /* Ignore zero sized sections.  */
   3972   1.1.1.2  christos 	  if (sec->size == 0)
   3973   1.1.1.2  christos 	    continue;
   3974   1.1.1.2  christos 
   3975   1.1.1.2  christos 	  elf32_tic6x_insert_cantunwind_after (last_text_sec, last_exidx_sec);
   3976   1.1.1.2  christos 	  last_unwind_type = 0;
   3977   1.1.1.2  christos 	  continue;
   3978   1.1.1.2  christos 	}
   3979   1.1.1.2  christos 
   3980   1.1.1.2  christos       /* Skip /DISCARD/ sections.  */
   3981   1.1.1.2  christos       if (bfd_is_abs_section (exidx_sec->output_section))
   3982   1.1.1.2  christos 	continue;
   3983   1.1.1.2  christos 
   3984   1.1.1.2  christos       hdr = &elf_section_data (exidx_sec)->this_hdr;
   3985   1.1.1.5  christos       if (hdr->sh_type != SHT_C6000_UNWIND)
   3986   1.1.1.3  christos 	continue;
   3987   1.1.1.2  christos 
   3988   1.1.1.2  christos       exidx_data = get_tic6x_elf_section_data (exidx_sec);
   3989   1.1.1.5  christos       if (exidx_data == NULL)
   3990   1.1.1.3  christos 	continue;
   3991   1.1.1.2  christos 
   3992   1.1.1.3  christos       ibfd = exidx_sec->owner;
   3993   1.1.1.2  christos 
   3994   1.1.1.2  christos       if (hdr->contents != NULL)
   3995   1.1.1.2  christos 	contents = hdr->contents;
   3996   1.1.1.2  christos       else if (! bfd_malloc_and_get_section (ibfd, exidx_sec, &contents))
   3997   1.1.1.2  christos 	/* An error?  */
   3998   1.1.1.2  christos 	continue;
   3999   1.1.1.2  christos 
   4000   1.1.1.2  christos       for (j = 0; j < hdr->sh_size; j += 8)
   4001   1.1.1.2  christos 	{
   4002   1.1.1.2  christos 	  unsigned int second_word = bfd_get_32 (ibfd, contents + j + 4);
   4003   1.1.1.2  christos 	  int unwind_type;
   4004   1.1.1.2  christos 	  int elide = 0;
   4005   1.1.1.2  christos 
   4006   1.1.1.2  christos 	  /* An EXIDX_CANTUNWIND entry.  */
   4007   1.1.1.2  christos 	  if (second_word == 1)
   4008   1.1.1.2  christos 	    {
   4009   1.1.1.2  christos 	      if (last_unwind_type == 0)
   4010   1.1.1.2  christos 		elide = 1;
   4011   1.1.1.2  christos 	      unwind_type = 0;
   4012   1.1.1.2  christos 	    }
   4013   1.1.1.2  christos 	  /* Inlined unwinding data.  Merge if equal to previous.  */
   4014   1.1.1.2  christos 	  else if ((second_word & 0x80000000) != 0)
   4015   1.1.1.2  christos 	    {
   4016   1.1.1.2  christos 	      if (merge_exidx_entries
   4017   1.1.1.2  christos 		  && last_second_word == second_word
   4018   1.1.1.2  christos 		  && last_unwind_type == 1)
   4019   1.1.1.2  christos 		elide = 1;
   4020   1.1.1.2  christos 	      unwind_type = 1;
   4021   1.1.1.2  christos 	      last_second_word = second_word;
   4022   1.1.1.2  christos 	    }
   4023   1.1.1.2  christos 	  /* Normal table entry.  In theory we could merge these too,
   4024   1.1.1.2  christos 	     but duplicate entries are likely to be much less common.  */
   4025   1.1.1.2  christos 	  else
   4026   1.1.1.2  christos 	    unwind_type = 2;
   4027   1.1.1.2  christos 
   4028   1.1.1.2  christos 	  if (elide)
   4029   1.1.1.2  christos 	    {
   4030   1.1.1.2  christos 	      elf32_tic6x_add_unwind_table_edit (&unwind_edit_head,
   4031   1.1.1.2  christos 		  &unwind_edit_tail, DELETE_EXIDX_ENTRY, NULL, j / 8);
   4032   1.1.1.2  christos 
   4033   1.1.1.2  christos 	      deleted_exidx_bytes += 8;
   4034   1.1.1.2  christos 	    }
   4035   1.1.1.2  christos 
   4036   1.1.1.2  christos 	  last_unwind_type = unwind_type;
   4037   1.1.1.2  christos 	}
   4038   1.1.1.2  christos 
   4039   1.1.1.2  christos       /* Free contents if we allocated it ourselves.  */
   4040   1.1.1.5  christos       if (contents != hdr->contents)
   4041   1.1.1.2  christos 	free (contents);
   4042   1.1.1.2  christos 
   4043   1.1.1.2  christos       /* Record edits to be applied later (in elf32_tic6x_write_section).  */
   4044   1.1.1.2  christos       exidx_data->u.exidx.unwind_edit_list = unwind_edit_head;
   4045   1.1.1.3  christos       exidx_data->u.exidx.unwind_edit_tail = unwind_edit_tail;
   4046   1.1.1.2  christos 
   4047   1.1.1.2  christos       if (deleted_exidx_bytes > 0)
   4048   1.1.1.2  christos 	elf32_tic6x_adjust_exidx_size (exidx_sec, -deleted_exidx_bytes);
   4049   1.1.1.2  christos 
   4050   1.1.1.2  christos       last_exidx_sec = exidx_sec;
   4051   1.1.1.2  christos       last_text_sec = sec;
   4052   1.1.1.2  christos     }
   4053   1.1.1.2  christos 
   4054   1.1.1.2  christos   /* Add terminating CANTUNWIND entry.  */
   4055   1.1.1.2  christos   if (last_exidx_sec && last_unwind_type != 0)
   4056   1.1.1.2  christos     elf32_tic6x_insert_cantunwind_after (last_text_sec, last_exidx_sec);
   4057   1.1.1.8  christos 
   4058   1.1.1.2  christos   return true;
   4059   1.1.1.2  christos }
   4060   1.1.1.2  christos 
   4061   1.1.1.2  christos /* Add ADDEND to lower 31 bits of VAL, leaving other bits unmodified.  */
   4062   1.1.1.2  christos 
   4063   1.1.1.2  christos static unsigned long
   4064   1.1.1.2  christos elf32_tic6x_add_low31 (unsigned long val, bfd_vma addend)
   4065   1.1.1.2  christos {
   4066   1.1.1.2  christos   return (val & ~0x7ffffffful) | ((val + addend) & 0x7ffffffful);
   4067   1.1.1.2  christos }
   4068   1.1.1.2  christos 
   4069   1.1.1.2  christos /* Copy an .c6xabi.exidx table entry, adding OFFSET to (applied) PREL31
   4070   1.1.1.2  christos    relocations.  OFFSET is in bytes, and will be scaled before encoding.  */
   4071   1.1.1.2  christos 
   4072   1.1.1.2  christos 
   4073   1.1.1.2  christos static void
   4074   1.1.1.2  christos elf32_tic6x_copy_exidx_entry (bfd *output_bfd, bfd_byte *to, bfd_byte *from,
   4075   1.1.1.2  christos 			      bfd_vma offset)
   4076   1.1.1.2  christos {
   4077   1.1.1.2  christos   unsigned long first_word = bfd_get_32 (output_bfd, from);
   4078   1.1.1.2  christos   unsigned long second_word = bfd_get_32 (output_bfd, from + 4);
   4079   1.1.1.2  christos 
   4080   1.1.1.2  christos   offset >>= 1;
   4081   1.1.1.2  christos   /* High bit of first word is supposed to be zero.  */
   4082   1.1.1.2  christos   if ((first_word & 0x80000000ul) == 0)
   4083   1.1.1.3  christos     first_word = elf32_tic6x_add_low31 (first_word, offset);
   4084   1.1.1.2  christos 
   4085   1.1.1.2  christos   /* If the high bit of the first word is clear, and the bit pattern is not 0x1
   4086   1.1.1.2  christos      (EXIDX_CANTUNWIND), this is an offset to an .c6xabi.extab entry.  */
   4087   1.1.1.2  christos   if ((second_word != 0x1) && ((second_word & 0x80000000ul) == 0))
   4088   1.1.1.3  christos     second_word = elf32_tic6x_add_low31 (second_word, offset);
   4089   1.1.1.2  christos 
   4090   1.1.1.2  christos   bfd_put_32 (output_bfd, first_word, to);
   4091   1.1.1.2  christos   bfd_put_32 (output_bfd, second_word, to + 4);
   4092   1.1.1.2  christos }
   4093   1.1.1.2  christos 
   4094   1.1.1.2  christos /* Do the actual mangling of exception index tables.  */
   4095   1.1.1.8  christos 
   4096   1.1.1.2  christos static bool
   4097   1.1.1.2  christos elf32_tic6x_write_section (bfd *output_bfd,
   4098   1.1.1.2  christos 			 struct bfd_link_info *link_info,
   4099   1.1.1.2  christos 			 asection *sec,
   4100   1.1.1.2  christos 			 bfd_byte *contents)
   4101   1.1.1.2  christos {
   4102   1.1.1.2  christos   _tic6x_elf_section_data *tic6x_data;
   4103   1.1.1.2  christos   struct elf32_tic6x_link_hash_table *globals
   4104   1.1.1.2  christos     = elf32_tic6x_hash_table (link_info);
   4105   1.1.1.2  christos   bfd_vma offset = sec->output_section->vma + sec->output_offset;
   4106   1.1.1.2  christos 
   4107   1.1.1.8  christos   if (globals == NULL)
   4108   1.1.1.2  christos     return false;
   4109   1.1.1.2  christos 
   4110   1.1.1.2  christos   /* If this section has not been allocated an _tic6x_elf_section_data
   4111   1.1.1.2  christos      structure then we cannot record anything.  */
   4112   1.1.1.2  christos   tic6x_data = get_tic6x_elf_section_data (sec);
   4113   1.1.1.8  christos   if (tic6x_data == NULL)
   4114   1.1.1.2  christos     return false;
   4115   1.1.1.2  christos 
   4116   1.1.1.8  christos   if (tic6x_data->elf.this_hdr.sh_type != SHT_C6000_UNWIND)
   4117   1.1.1.2  christos     return false;
   4118   1.1.1.2  christos 
   4119   1.1.1.2  christos   tic6x_unwind_table_edit *edit_node
   4120   1.1.1.2  christos     = tic6x_data->u.exidx.unwind_edit_list;
   4121   1.1.1.2  christos   /* Now, sec->size is the size of the section we will write.  The original
   4122   1.1.1.2  christos      size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
   4123   1.1.1.2  christos      markers) was sec->rawsize.  (This isn't the case if we perform no
   4124   1.1.1.2  christos      edits, then rawsize will be zero and we should use size).  */
   4125   1.1.1.2  christos   bfd_byte *edited_contents = (bfd_byte *) bfd_malloc (sec->size);
   4126   1.1.1.2  christos   unsigned int input_size = sec->rawsize ? sec->rawsize : sec->size;
   4127   1.1.1.2  christos   unsigned int in_index, out_index;
   4128   1.1.1.2  christos   bfd_vma add_to_offsets = 0;
   4129   1.1.1.2  christos 
   4130   1.1.1.2  christos   for (in_index = 0, out_index = 0; in_index * 8 < input_size || edit_node;)
   4131   1.1.1.2  christos     {
   4132   1.1.1.2  christos       if (edit_node)
   4133   1.1.1.2  christos 	{
   4134   1.1.1.3  christos 	  unsigned int edit_index = edit_node->index;
   4135   1.1.1.2  christos 
   4136   1.1.1.2  christos 	  if (in_index < edit_index && in_index * 8 < input_size)
   4137   1.1.1.2  christos 	    {
   4138   1.1.1.2  christos 	      elf32_tic6x_copy_exidx_entry (output_bfd,
   4139   1.1.1.2  christos 		  edited_contents + out_index * 8,
   4140   1.1.1.2  christos 		  contents + in_index * 8, add_to_offsets);
   4141   1.1.1.2  christos 	      out_index++;
   4142   1.1.1.2  christos 	      in_index++;
   4143   1.1.1.2  christos 	    }
   4144   1.1.1.2  christos 	  else if (in_index == edit_index
   4145   1.1.1.2  christos 		   || (in_index * 8 >= input_size
   4146   1.1.1.2  christos 		       && edit_index == UINT_MAX))
   4147   1.1.1.2  christos 	    {
   4148   1.1.1.2  christos 	      switch (edit_node->type)
   4149   1.1.1.2  christos 		{
   4150   1.1.1.2  christos 		case DELETE_EXIDX_ENTRY:
   4151   1.1.1.2  christos 		  in_index++;
   4152   1.1.1.2  christos 		  add_to_offsets += 8;
   4153   1.1.1.3  christos 		  break;
   4154   1.1.1.2  christos 
   4155   1.1.1.2  christos 		case INSERT_EXIDX_CANTUNWIND_AT_END:
   4156   1.1.1.2  christos 		  {
   4157   1.1.1.2  christos 		    asection *text_sec = edit_node->linked_section;
   4158   1.1.1.2  christos 		    bfd_vma text_offset = text_sec->output_section->vma
   4159   1.1.1.2  christos 					  + text_sec->output_offset
   4160   1.1.1.2  christos 					  + text_sec->size;
   4161   1.1.1.2  christos 		    bfd_vma exidx_offset = offset + out_index * 8;
   4162   1.1.1.2  christos 		    unsigned long prel31_offset;
   4163   1.1.1.2  christos 
   4164   1.1.1.2  christos 		    /* Note: this is meant to be equivalent to an
   4165   1.1.1.2  christos 		       R_C6000_PREL31 relocation.  These synthetic
   4166   1.1.1.2  christos 		       EXIDX_CANTUNWIND markers are not relocated by the
   4167   1.1.1.2  christos 		       usual BFD method.  */
   4168   1.1.1.2  christos 		    prel31_offset = ((text_offset - exidx_offset) >> 1)
   4169   1.1.1.2  christos 				    & 0x7ffffffful;
   4170   1.1.1.2  christos 
   4171   1.1.1.2  christos 		    /* First address we can't unwind.  */
   4172   1.1.1.2  christos 		    bfd_put_32 (output_bfd, prel31_offset,
   4173   1.1.1.2  christos 				&edited_contents[out_index * 8]);
   4174   1.1.1.2  christos 
   4175   1.1.1.2  christos 		    /* Code for EXIDX_CANTUNWIND.  */
   4176   1.1.1.2  christos 		    bfd_put_32 (output_bfd, 0x1,
   4177   1.1.1.2  christos 				&edited_contents[out_index * 8 + 4]);
   4178   1.1.1.2  christos 
   4179   1.1.1.2  christos 		    out_index++;
   4180   1.1.1.2  christos 		    add_to_offsets -= 8;
   4181   1.1.1.2  christos 		  }
   4182   1.1.1.2  christos 		  break;
   4183   1.1.1.3  christos 		}
   4184   1.1.1.2  christos 
   4185   1.1.1.2  christos 	      edit_node = edit_node->next;
   4186   1.1.1.2  christos 	    }
   4187   1.1.1.2  christos 	}
   4188   1.1.1.2  christos       else
   4189   1.1.1.2  christos 	{
   4190   1.1.1.2  christos 	  /* No more edits, copy remaining entries verbatim.  */
   4191   1.1.1.2  christos 	  elf32_tic6x_copy_exidx_entry (output_bfd,
   4192   1.1.1.2  christos 	      edited_contents + out_index * 8,
   4193   1.1.1.2  christos 	      contents + in_index * 8, add_to_offsets);
   4194   1.1.1.2  christos 	  out_index++;
   4195   1.1.1.2  christos 	  in_index++;
   4196   1.1.1.2  christos 	}
   4197   1.1.1.2  christos     }
   4198   1.1.1.2  christos 
   4199   1.1.1.2  christos   if (!(sec->flags & SEC_EXCLUDE) && !(sec->flags & SEC_NEVER_LOAD))
   4200   1.1.1.2  christos     bfd_set_section_contents (output_bfd, sec->output_section,
   4201   1.1.1.2  christos 			      edited_contents,
   4202   1.1.1.2  christos 			      (file_ptr) sec->output_offset, sec->size);
   4203   1.1.1.8  christos 
   4204   1.1.1.2  christos   return true;
   4205   1.1.1.2  christos }
   4206   1.1.1.8  christos 
   4207   1.1.1.8  christos #define	elf32_bed		elf32_tic6x_bed
   4208   1.1.1.3  christos 
   4209       1.1  christos #define TARGET_LITTLE_SYM	tic6x_elf32_le_vec
   4210   1.1.1.3  christos #define TARGET_LITTLE_NAME	"elf32-tic6x-le"
   4211       1.1  christos #define TARGET_BIG_SYM		tic6x_elf32_be_vec
   4212       1.1  christos #define TARGET_BIG_NAME		"elf32-tic6x-be"
   4213       1.1  christos #define ELF_ARCH		bfd_arch_tic6x
   4214       1.1  christos #define ELF_TARGET_ID		TIC6X_ELF_DATA
   4215   1.1.1.2  christos #define ELF_MACHINE_CODE	EM_TI_C6000
   4216       1.1  christos #define ELF_MAXPAGESIZE		0x1000
   4217       1.1  christos #define bfd_elf32_bfd_reloc_type_lookup elf32_tic6x_reloc_type_lookup
   4218       1.1  christos #define bfd_elf32_bfd_reloc_name_lookup elf32_tic6x_reloc_name_lookup
   4219       1.1  christos #define bfd_elf32_bfd_merge_private_bfd_data	elf32_tic6x_merge_private_bfd_data
   4220   1.1.1.2  christos #define bfd_elf32_mkobject		elf32_tic6x_mkobject
   4221       1.1  christos #define bfd_elf32_bfd_link_hash_table_create  elf32_tic6x_link_hash_table_create
   4222   1.1.1.3  christos #define bfd_elf32_new_section_hook	elf32_tic6x_new_section_hook
   4223       1.1  christos #define elf_backend_stack_align		8
   4224       1.1  christos #define elf_backend_can_gc_sections	1
   4225       1.1  christos #define elf_backend_default_use_rela_p	1
   4226       1.1  christos #define elf_backend_may_use_rel_p	1
   4227       1.1  christos #define elf_backend_may_use_rela_p	1
   4228   1.1.1.2  christos #define elf_backend_obj_attrs_arg_type	elf32_tic6x_obj_attrs_arg_type
   4229       1.1  christos #define elf_backend_obj_attrs_handle_unknown	elf32_tic6x_obj_attrs_handle_unknown
   4230       1.1  christos #define elf_backend_obj_attrs_order	elf32_tic6x_obj_attrs_order
   4231       1.1  christos #define elf_backend_obj_attrs_section	".c6xabi.attributes"
   4232       1.1  christos #define elf_backend_obj_attrs_section_type	SHT_C6000_ATTRIBUTES
   4233   1.1.1.2  christos #define elf_backend_obj_attrs_vendor	"c6xabi"
   4234   1.1.1.2  christos #define elf_backend_can_refcount	1
   4235   1.1.1.2  christos #define elf_backend_want_got_plt	1
   4236   1.1.1.5  christos #define elf_backend_want_dynbss		1
   4237   1.1.1.2  christos #define elf_backend_want_dynrelro	1
   4238       1.1  christos #define elf_backend_plt_readonly	1
   4239   1.1.1.2  christos #define elf_backend_rela_normal		1
   4240   1.1.1.2  christos #define elf_backend_got_header_size     8
   4241   1.1.1.2  christos #define elf_backend_fake_sections       elf32_tic6x_fake_sections
   4242   1.1.1.2  christos #define elf_backend_gc_mark_extra_sections elf32_tic6x_gc_mark_extra_sections
   4243   1.1.1.2  christos #define elf_backend_create_dynamic_sections \
   4244   1.1.1.2  christos   elf32_tic6x_create_dynamic_sections
   4245   1.1.1.2  christos #define elf_backend_adjust_dynamic_symbol \
   4246   1.1.1.5  christos   elf32_tic6x_adjust_dynamic_symbol
   4247   1.1.1.2  christos #define elf_backend_check_relocs	elf32_tic6x_check_relocs
   4248   1.1.1.2  christos #define elf_backend_add_symbol_hook     elf32_tic6x_add_symbol_hook
   4249   1.1.1.2  christos #define elf_backend_symbol_processing   elf32_tic6x_symbol_processing
   4250   1.1.1.2  christos #define elf_backend_link_output_symbol_hook \
   4251   1.1.1.2  christos   elf32_tic6x_link_output_symbol_hook
   4252   1.1.1.2  christos #define elf_backend_section_from_bfd_section \
   4253       1.1  christos   elf32_tic6x_section_from_bfd_section
   4254   1.1.1.2  christos #define elf_backend_relocate_section	elf32_tic6x_relocate_section
   4255   1.1.1.2  christos #define elf_backend_relocs_compatible	_bfd_elf_relocs_compatible
   4256   1.1.1.2  christos #define elf_backend_finish_dynamic_symbol \
   4257  1.1.1.10  christos   elf32_tic6x_finish_dynamic_symbol
   4258  1.1.1.10  christos #define elf_backend_early_size_sections \
   4259  1.1.1.10  christos   elf32_tic6x_early_size_sections
   4260  1.1.1.10  christos #define elf_backend_late_size_sections \
   4261   1.1.1.2  christos   elf32_tic6x_late_size_sections
   4262   1.1.1.2  christos #define elf_backend_finish_dynamic_sections \
   4263   1.1.1.2  christos   elf32_tic6x_finish_dynamic_sections
   4264   1.1.1.2  christos #define bfd_elf32_bfd_final_link \
   4265   1.1.1.2  christos 	elf32_tic6x_final_link
   4266       1.1  christos #define elf_backend_write_section	elf32_tic6x_write_section
   4267       1.1  christos #define elf_info_to_howto		elf32_tic6x_info_to_howto
   4268       1.1  christos #define elf_info_to_howto_rel		elf32_tic6x_info_to_howto_rel
   4269   1.1.1.2  christos 
   4270   1.1.1.2  christos #undef elf_backend_omit_section_dynsym
   4271   1.1.1.2  christos #define elf_backend_omit_section_dynsym elf32_tic6x_link_omit_section_dynsym
   4272   1.1.1.2  christos #define elf_backend_plt_sym_val		elf32_tic6x_plt_sym_val
   4273   1.1.1.2  christos 
   4274   1.1.1.2  christos #include "elf32-target.h"
   4275   1.1.1.2  christos 
   4276   1.1.1.2  christos #undef elf32_bed
   4277   1.1.1.2  christos #define	elf32_bed		elf32_tic6x_linux_bed
   4278   1.1.1.2  christos 
   4279   1.1.1.3  christos #undef TARGET_LITTLE_SYM
   4280   1.1.1.2  christos #define	TARGET_LITTLE_SYM		tic6x_elf32_linux_le_vec
   4281   1.1.1.2  christos #undef TARGET_LITTLE_NAME
   4282   1.1.1.2  christos #define	TARGET_LITTLE_NAME		"elf32-tic6x-linux-le"
   4283   1.1.1.3  christos #undef TARGET_BIG_SYM
   4284   1.1.1.2  christos #define TARGET_BIG_SYM			tic6x_elf32_linux_be_vec
   4285   1.1.1.2  christos #undef TARGET_BIG_NAME
   4286   1.1.1.2  christos #define	TARGET_BIG_NAME			"elf32-tic6x-linux-be"
   4287   1.1.1.2  christos #undef ELF_OSABI
   4288  1.1.1.11  christos #define	ELF_OSABI			ELFOSABI_C6000_LINUX
   4289  1.1.1.11  christos #undef ELF_OSABI_EXACT
   4290   1.1.1.2  christos #define ELF_OSABI_EXACT			1
   4291   1.1.1.2  christos 
   4292   1.1.1.2  christos #include "elf32-target.h"
   4293   1.1.1.2  christos 
   4294   1.1.1.2  christos #undef elf32_bed
   4295   1.1.1.2  christos #define	elf32_bed		elf32_tic6x_elf_bed
   4296   1.1.1.2  christos 
   4297   1.1.1.3  christos #undef TARGET_LITTLE_SYM
   4298   1.1.1.2  christos #define	TARGET_LITTLE_SYM		tic6x_elf32_c6000_le_vec
   4299   1.1.1.2  christos #undef TARGET_LITTLE_NAME
   4300   1.1.1.2  christos #define	TARGET_LITTLE_NAME		"elf32-tic6x-elf-le"
   4301   1.1.1.3  christos #undef TARGET_BIG_SYM
   4302   1.1.1.2  christos #define TARGET_BIG_SYM			tic6x_elf32_c6000_be_vec
   4303   1.1.1.2  christos #undef TARGET_BIG_NAME
   4304   1.1.1.2  christos #define	TARGET_BIG_NAME			"elf32-tic6x-elf-be"
   4305   1.1.1.2  christos #undef ELF_OSABI
   4306  1.1.1.11  christos #define	ELF_OSABI			ELFOSABI_C6000_ELFABI
   4307  1.1.1.11  christos #undef ELF_OSABI_EXACT
   4308   1.1.1.2  christos #define ELF_OSABI_EXACT			1
   4309       1.1  christos 
   4310                     #include "elf32-target.h"
   4311