Home | History | Annotate | Line # | Download | only in bfd
elf32-arc.c revision 1.1.1.4
      1      1.1     skrll /* ARC-specific support for 32-bit ELF
      2  1.1.1.4  christos    Copyright (C) 1994-2018 Free Software Foundation, Inc.
      3  1.1.1.2  christos    Contributed by Cupertino Miranda (cmiranda (at) synopsys.com).
      4      1.1     skrll 
      5      1.1     skrll    This file is part of BFD, the Binary File Descriptor library.
      6      1.1     skrll 
      7      1.1     skrll    This program is free software; you can redistribute it and/or modify
      8      1.1     skrll    it under the terms of the GNU General Public License as published by
      9      1.1     skrll    the Free Software Foundation; either version 3 of the License, or
     10      1.1     skrll    (at your option) any later version.
     11      1.1     skrll 
     12      1.1     skrll    This program is distributed in the hope that it will be useful,
     13      1.1     skrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14      1.1     skrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15      1.1     skrll    GNU General Public License for more details.
     16      1.1     skrll 
     17      1.1     skrll    You should have received a copy of the GNU General Public License
     18      1.1     skrll    along with this program; if not, write to the Free Software
     19      1.1     skrll    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     20      1.1     skrll    MA 02110-1301, USA.  */
     21      1.1     skrll 
     22      1.1     skrll #include "sysdep.h"
     23      1.1     skrll #include "bfd.h"
     24      1.1     skrll #include "libbfd.h"
     25      1.1     skrll #include "elf-bfd.h"
     26      1.1     skrll #include "elf/arc.h"
     27      1.1     skrll #include "libiberty.h"
     28  1.1.1.2  christos #include "opcode/arc-func.h"
     29  1.1.1.3  christos #include "opcode/arc.h"
     30  1.1.1.3  christos #include "arc-plt.h"
     31  1.1.1.2  christos 
     32  1.1.1.4  christos #define FEATURE_LIST_NAME bfd_feature_list
     33  1.1.1.4  christos #define CONFLICT_LIST bfd_conflict_list
     34  1.1.1.4  christos #include "opcode/arc-attrs.h"
     35  1.1.1.4  christos 
     36  1.1.1.4  christos /* #define ARC_ENABLE_DEBUG 1  */
     37  1.1.1.4  christos #ifdef ARC_ENABLE_DEBUG
     38  1.1.1.4  christos static const char *
     39  1.1.1.3  christos name_for_global_symbol (struct elf_link_hash_entry *h)
     40  1.1.1.3  christos {
     41  1.1.1.3  christos   static char *local_str = "(local)";
     42  1.1.1.3  christos   if (h == NULL)
     43  1.1.1.3  christos     return local_str;
     44  1.1.1.4  christos   return h->root.root.string;
     45  1.1.1.3  christos }
     46  1.1.1.4  christos #define ARC_DEBUG(fmt, args...) fprintf (stderr, fmt, ##args)
     47  1.1.1.4  christos #else
     48  1.1.1.4  christos #define ARC_DEBUG(...)
     49  1.1.1.3  christos #endif
     50  1.1.1.2  christos 
     51  1.1.1.2  christos 
     52  1.1.1.3  christos #define ADD_RELA(BFD, SECTION, OFFSET, SYM_IDX, TYPE, ADDEND)		\
     53  1.1.1.3  christos   {									\
     54  1.1.1.3  christos     struct elf_link_hash_table *_htab = elf_hash_table (info);		\
     55  1.1.1.3  christos     Elf_Internal_Rela _rel;						\
     56  1.1.1.3  christos     bfd_byte * _loc;							\
     57  1.1.1.3  christos 									\
     58  1.1.1.4  christos     if (_htab->dynamic_sections_created == TRUE)				\
     59  1.1.1.4  christos       {									\
     60  1.1.1.4  christos 	BFD_ASSERT (_htab->srel##SECTION &&_htab->srel##SECTION->contents); \
     61  1.1.1.4  christos 	_loc = _htab->srel##SECTION->contents				\
     62  1.1.1.4  christos 	  + ((_htab->srel##SECTION->reloc_count)			\
     63  1.1.1.4  christos 	     * sizeof (Elf32_External_Rela));				\
     64  1.1.1.4  christos 	_htab->srel##SECTION->reloc_count++;				\
     65  1.1.1.4  christos 	_rel.r_addend = ADDEND;						\
     66  1.1.1.4  christos 	_rel.r_offset = (_htab->s##SECTION)->output_section->vma	\
     67  1.1.1.4  christos 	  + (_htab->s##SECTION)->output_offset + OFFSET;		\
     68  1.1.1.4  christos 	BFD_ASSERT ((long) SYM_IDX != -1);				\
     69  1.1.1.4  christos 	_rel.r_info = ELF32_R_INFO (SYM_IDX, TYPE);			\
     70  1.1.1.4  christos 	bfd_elf32_swap_reloca_out (BFD, &_rel, _loc);			\
     71  1.1.1.4  christos       }									\
     72  1.1.1.3  christos   }
     73  1.1.1.2  christos 
     74  1.1.1.3  christos 
     75  1.1.1.2  christos /* The default symbols representing the init and fini dyn values.
     76  1.1.1.2  christos    TODO: Check what is the relation of those strings with arclinux.em
     77  1.1.1.2  christos    and DT_INIT.  */
     78  1.1.1.2  christos #define INIT_SYM_STRING "_init"
     79  1.1.1.2  christos #define FINI_SYM_STRING "_fini"
     80  1.1.1.2  christos 
     81  1.1.1.2  christos char * init_str = INIT_SYM_STRING;
     82  1.1.1.2  christos char * fini_str = FINI_SYM_STRING;
     83  1.1.1.2  christos 
     84  1.1.1.2  christos #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
     85  1.1.1.2  christos       case VALUE: \
     86  1.1.1.3  christos 	return "R_" #TYPE; \
     87  1.1.1.2  christos 	break;
     88  1.1.1.2  christos 
     89  1.1.1.2  christos static ATTRIBUTE_UNUSED const char *
     90  1.1.1.2  christos reloc_type_to_name (unsigned int type)
     91  1.1.1.2  christos {
     92  1.1.1.2  christos   switch (type)
     93  1.1.1.2  christos     {
     94  1.1.1.2  christos       #include "elf/arc-reloc.def"
     95  1.1.1.2  christos 
     96  1.1.1.2  christos       default:
     97  1.1.1.2  christos 	return "UNKNOWN";
     98  1.1.1.2  christos 	break;
     99  1.1.1.2  christos     }
    100  1.1.1.2  christos }
    101  1.1.1.2  christos #undef ARC_RELOC_HOWTO
    102      1.1     skrll 
    103      1.1     skrll /* Try to minimize the amount of space occupied by relocation tables
    104      1.1     skrll    on the ROM (not that the ROM won't be swamped by other ELF overhead).  */
    105      1.1     skrll 
    106  1.1.1.2  christos #define USE_REL 1
    107  1.1.1.2  christos 
    108  1.1.1.2  christos static ATTRIBUTE_UNUSED bfd_boolean
    109  1.1.1.2  christos is_reloc_PC_relative (reloc_howto_type *howto)
    110  1.1.1.2  christos {
    111  1.1.1.2  christos   return (strstr (howto->name, "PC") != NULL) ? TRUE : FALSE;
    112  1.1.1.2  christos }
    113  1.1.1.2  christos 
    114  1.1.1.2  christos static bfd_boolean
    115  1.1.1.2  christos is_reloc_SDA_relative (reloc_howto_type *howto)
    116  1.1.1.2  christos {
    117  1.1.1.2  christos   return (strstr (howto->name, "SDA") != NULL) ? TRUE : FALSE;
    118  1.1.1.2  christos }
    119  1.1.1.2  christos 
    120  1.1.1.2  christos static bfd_boolean
    121  1.1.1.2  christos is_reloc_for_GOT (reloc_howto_type * howto)
    122  1.1.1.2  christos {
    123  1.1.1.3  christos   if (strstr (howto->name, "TLS") != NULL)
    124  1.1.1.3  christos     return FALSE;
    125  1.1.1.2  christos   return (strstr (howto->name, "GOT") != NULL) ? TRUE : FALSE;
    126  1.1.1.2  christos }
    127  1.1.1.2  christos 
    128  1.1.1.2  christos static bfd_boolean
    129  1.1.1.2  christos is_reloc_for_PLT (reloc_howto_type * howto)
    130  1.1.1.2  christos {
    131  1.1.1.2  christos   return (strstr (howto->name, "PLT") != NULL) ? TRUE : FALSE;
    132  1.1.1.2  christos }
    133  1.1.1.2  christos 
    134  1.1.1.3  christos static bfd_boolean
    135  1.1.1.3  christos is_reloc_for_TLS (reloc_howto_type *howto)
    136  1.1.1.3  christos {
    137  1.1.1.3  christos   return (strstr (howto->name, "TLS") != NULL) ? TRUE : FALSE;
    138  1.1.1.3  christos }
    139  1.1.1.3  christos 
    140  1.1.1.4  christos struct arc_relocation_data
    141  1.1.1.4  christos {
    142  1.1.1.4  christos   bfd_signed_vma  reloc_offset;
    143  1.1.1.4  christos   bfd_signed_vma  reloc_addend;
    144  1.1.1.4  christos   bfd_signed_vma  got_offset_value;
    145  1.1.1.4  christos 
    146  1.1.1.4  christos   bfd_signed_vma  sym_value;
    147  1.1.1.4  christos   asection *	  sym_section;
    148  1.1.1.4  christos 
    149  1.1.1.4  christos   reloc_howto_type *howto;
    150  1.1.1.4  christos 
    151  1.1.1.4  christos   asection *	  input_section;
    152  1.1.1.4  christos 
    153  1.1.1.4  christos   bfd_signed_vma  sdata_begin_symbol_vma;
    154  1.1.1.4  christos   bfd_boolean	  sdata_begin_symbol_vma_set;
    155  1.1.1.4  christos   bfd_signed_vma  got_symbol_vma;
    156  1.1.1.4  christos 
    157  1.1.1.4  christos   bfd_boolean	  should_relocate;
    158  1.1.1.4  christos 
    159  1.1.1.4  christos   const char *    symbol_name;
    160  1.1.1.4  christos };
    161  1.1.1.4  christos 
    162  1.1.1.4  christos /* Should be included at this location due to static declarations
    163  1.1.1.4  christos  * defined before this point.  */
    164  1.1.1.4  christos #include "arc-got.h"
    165  1.1.1.4  christos 
    166  1.1.1.2  christos #define arc_bfd_get_8(A,B,C) bfd_get_8(A,B)
    167  1.1.1.2  christos #define arc_bfd_get_16(A,B,C) bfd_get_16(A,B)
    168  1.1.1.3  christos #define arc_bfd_get_32(A,B,C) bfd_get_32(A,B)
    169  1.1.1.2  christos #define arc_bfd_put_8(A,B,C,D) bfd_put_8(A,B,C)
    170  1.1.1.2  christos #define arc_bfd_put_16(A,B,C,D) bfd_put_16(A,B,C)
    171  1.1.1.3  christos #define arc_bfd_put_32(A,B,C,D) bfd_put_32(A,B,C)
    172  1.1.1.2  christos 
    173      1.1     skrll 
    174      1.1     skrll static bfd_reloc_status_type
    175  1.1.1.2  christos arc_elf_reloc (bfd *abfd ATTRIBUTE_UNUSED,
    176  1.1.1.2  christos 	       arelent *reloc_entry,
    177  1.1.1.2  christos 	       asymbol *symbol_in,
    178  1.1.1.2  christos 	       void *data ATTRIBUTE_UNUSED,
    179  1.1.1.2  christos 	       asection *input_section,
    180  1.1.1.2  christos 	       bfd *output_bfd,
    181  1.1.1.2  christos 	       char ** error_message ATTRIBUTE_UNUSED)
    182  1.1.1.2  christos {
    183  1.1.1.2  christos   if (output_bfd != NULL)
    184  1.1.1.2  christos     {
    185  1.1.1.2  christos       reloc_entry->address += input_section->output_offset;
    186  1.1.1.2  christos 
    187  1.1.1.2  christos       /* In case of relocateable link and if the reloc is against a
    188  1.1.1.2  christos 	 section symbol, the addend needs to be adjusted according to
    189  1.1.1.2  christos 	 where the section symbol winds up in the output section.  */
    190  1.1.1.2  christos       if ((symbol_in->flags & BSF_SECTION_SYM) && symbol_in->section)
    191  1.1.1.2  christos 	reloc_entry->addend += symbol_in->section->output_offset;
    192  1.1.1.2  christos 
    193  1.1.1.2  christos       return bfd_reloc_ok;
    194  1.1.1.2  christos     }
    195  1.1.1.2  christos 
    196  1.1.1.2  christos   return bfd_reloc_continue;
    197  1.1.1.2  christos }
    198  1.1.1.2  christos 
    199  1.1.1.2  christos 
    200  1.1.1.2  christos #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
    201  1.1.1.2  christos   TYPE = VALUE,
    202  1.1.1.2  christos enum howto_list
    203  1.1.1.2  christos {
    204  1.1.1.2  christos #include "elf/arc-reloc.def"
    205  1.1.1.2  christos   HOWTO_LIST_LAST
    206      1.1     skrll };
    207  1.1.1.2  christos #undef ARC_RELOC_HOWTO
    208  1.1.1.2  christos 
    209  1.1.1.2  christos #define ARC_RELOC_HOWTO(TYPE, VALUE, RSIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
    210  1.1.1.4  christos   [TYPE] = HOWTO (R_##TYPE, 0, RSIZE, BITSIZE, FALSE, 0,		\
    211  1.1.1.4  christos 		  complain_overflow_##OVERFLOW, arc_elf_reloc,		\
    212  1.1.1.4  christos 		  "R_" #TYPE, FALSE, 0, 0, FALSE),
    213  1.1.1.2  christos 
    214  1.1.1.2  christos static struct reloc_howto_struct elf_arc_howto_table[] =
    215  1.1.1.2  christos {
    216  1.1.1.2  christos #include "elf/arc-reloc.def"
    217  1.1.1.3  christos /* Example of what is generated by the preprocessor.  Currently kept as an
    218  1.1.1.3  christos    example.
    219  1.1.1.2  christos  HOWTO (R_ARC_NONE, // Type.
    220  1.1.1.2  christos     0, // Rightshift.
    221  1.1.1.2  christos     2, // Size (0 = byte, 1 = short, 2 = long).
    222  1.1.1.2  christos     32, // Bitsize.
    223  1.1.1.2  christos     FALSE, // PC_relative.
    224  1.1.1.2  christos     0, // Bitpos.
    225  1.1.1.2  christos     complain_overflow_bitfield, // Complain_on_overflow.
    226  1.1.1.2  christos     bfd_elf_generic_reloc, // Special_function.
    227  1.1.1.2  christos     "R_ARC_NONE", // Name.
    228  1.1.1.2  christos     TRUE, // Partial_inplace.
    229  1.1.1.2  christos     0, // Src_mask.
    230  1.1.1.2  christos     0, // Dst_mask.
    231  1.1.1.2  christos     FALSE), // PCrel_offset.
    232  1.1.1.2  christos */
    233  1.1.1.2  christos };
    234  1.1.1.2  christos #undef ARC_RELOC_HOWTO
    235  1.1.1.2  christos 
    236  1.1.1.2  christos static void arc_elf_howto_init (void)
    237  1.1.1.2  christos {
    238  1.1.1.2  christos #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
    239  1.1.1.2  christos   elf_arc_howto_table[TYPE].pc_relative = \
    240  1.1.1.3  christos     (strstr (#FORMULA, " P ") != NULL || strstr (#FORMULA, " PDATA ") != NULL); \
    241  1.1.1.3  christos   elf_arc_howto_table[TYPE].dst_mask = RELOC_FUNCTION(0, ~0); \
    242  1.1.1.3  christos   /* Only 32 bit data relocations should be marked as ME.  */ \
    243  1.1.1.3  christos   if (strstr (#FORMULA, " ME ") != NULL) \
    244  1.1.1.3  christos     { \
    245  1.1.1.3  christos       BFD_ASSERT (SIZE == 2); \
    246  1.1.1.3  christos     }
    247  1.1.1.3  christos 
    248  1.1.1.3  christos #include "elf/arc-reloc.def"
    249  1.1.1.2  christos 
    250  1.1.1.2  christos }
    251  1.1.1.2  christos #undef ARC_RELOC_HOWTO
    252  1.1.1.2  christos 
    253  1.1.1.2  christos 
    254  1.1.1.2  christos #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
    255  1.1.1.2  christos   [TYPE] = VALUE,
    256  1.1.1.2  christos const int howto_table_lookup[] =
    257  1.1.1.2  christos {
    258  1.1.1.3  christos #include "elf/arc-reloc.def"
    259  1.1.1.2  christos };
    260  1.1.1.2  christos #undef ARC_RELOC_HOWTO
    261  1.1.1.2  christos 
    262  1.1.1.3  christos static reloc_howto_type *
    263  1.1.1.3  christos arc_elf_howto (unsigned int r_type)
    264  1.1.1.3  christos {
    265  1.1.1.3  christos   if (elf_arc_howto_table[R_ARC_32].dst_mask == 0)
    266  1.1.1.3  christos     arc_elf_howto_init ();
    267  1.1.1.3  christos   return &elf_arc_howto_table[r_type];
    268  1.1.1.3  christos }
    269      1.1     skrll 
    270      1.1     skrll /* Map BFD reloc types to ARC ELF reloc types.  */
    271      1.1     skrll 
    272      1.1     skrll struct arc_reloc_map
    273      1.1     skrll {
    274  1.1.1.3  christos   bfd_reloc_code_real_type  bfd_reloc_val;
    275  1.1.1.4  christos   unsigned char		    elf_reloc_val;
    276      1.1     skrll };
    277      1.1     skrll 
    278  1.1.1.4  christos /* ARC ELF linker hash entry.  */
    279  1.1.1.4  christos struct elf_arc_link_hash_entry
    280  1.1.1.4  christos {
    281  1.1.1.4  christos   struct elf_link_hash_entry root;
    282  1.1.1.4  christos 
    283  1.1.1.4  christos   /* Track dynamic relocs copied for this symbol.  */
    284  1.1.1.4  christos   struct elf_dyn_relocs *dyn_relocs;
    285  1.1.1.4  christos };
    286  1.1.1.4  christos 
    287  1.1.1.4  christos /* ARC ELF linker hash table.  */
    288  1.1.1.4  christos struct elf_arc_link_hash_table
    289  1.1.1.4  christos {
    290  1.1.1.4  christos   struct elf_link_hash_table elf;
    291  1.1.1.4  christos };
    292  1.1.1.4  christos 
    293  1.1.1.4  christos static struct bfd_hash_entry *
    294  1.1.1.4  christos elf_arc_link_hash_newfunc (struct bfd_hash_entry *entry,
    295  1.1.1.4  christos 			   struct bfd_hash_table *table,
    296  1.1.1.4  christos 			   const char *string)
    297  1.1.1.4  christos {
    298  1.1.1.4  christos   /* Allocate the structure if it has not already been allocated by a
    299  1.1.1.4  christos      subclass.  */
    300  1.1.1.4  christos   if (entry == NULL)
    301  1.1.1.4  christos     {
    302  1.1.1.4  christos       entry = (struct bfd_hash_entry *)
    303  1.1.1.4  christos 	  bfd_hash_allocate (table,
    304  1.1.1.4  christos 			     sizeof (struct elf_arc_link_hash_entry));
    305  1.1.1.4  christos       if (entry == NULL)
    306  1.1.1.4  christos 	return entry;
    307  1.1.1.4  christos     }
    308  1.1.1.4  christos 
    309  1.1.1.4  christos   /* Call the allocation method of the superclass.  */
    310  1.1.1.4  christos   entry = _bfd_elf_link_hash_newfunc (entry, table, string);
    311  1.1.1.4  christos   if (entry != NULL)
    312  1.1.1.4  christos     {
    313  1.1.1.4  christos       struct elf_arc_link_hash_entry *eh;
    314  1.1.1.4  christos 
    315  1.1.1.4  christos       eh = (struct elf_arc_link_hash_entry *) entry;
    316  1.1.1.4  christos       eh->dyn_relocs = NULL;
    317  1.1.1.4  christos     }
    318  1.1.1.4  christos 
    319  1.1.1.4  christos   return entry;
    320  1.1.1.4  christos }
    321  1.1.1.4  christos 
    322  1.1.1.4  christos /* Destroy an ARC ELF linker hash table.  */
    323  1.1.1.4  christos static void
    324  1.1.1.4  christos elf_arc_link_hash_table_free (bfd *obfd)
    325  1.1.1.4  christos {
    326  1.1.1.4  christos   _bfd_elf_link_hash_table_free (obfd);
    327  1.1.1.4  christos }
    328  1.1.1.4  christos 
    329  1.1.1.4  christos /* Create an ARC ELF linker hash table.  */
    330  1.1.1.4  christos 
    331  1.1.1.4  christos static struct bfd_link_hash_table *
    332  1.1.1.4  christos arc_elf_link_hash_table_create (bfd *abfd)
    333  1.1.1.4  christos {
    334  1.1.1.4  christos   struct elf_arc_link_hash_table *ret;
    335  1.1.1.4  christos 
    336  1.1.1.4  christos   ret = (struct elf_arc_link_hash_table *) bfd_zmalloc (sizeof (*ret));
    337  1.1.1.4  christos   if (ret == NULL)
    338  1.1.1.4  christos     return NULL;
    339  1.1.1.4  christos 
    340  1.1.1.4  christos   if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
    341  1.1.1.4  christos 				      elf_arc_link_hash_newfunc,
    342  1.1.1.4  christos 				      sizeof (struct elf_arc_link_hash_entry),
    343  1.1.1.4  christos 				      ARC_ELF_DATA))
    344  1.1.1.4  christos     {
    345  1.1.1.4  christos       free (ret);
    346  1.1.1.4  christos       return NULL;
    347  1.1.1.4  christos     }
    348  1.1.1.4  christos 
    349  1.1.1.4  christos   ret->elf.init_got_refcount.refcount = 0;
    350  1.1.1.4  christos   ret->elf.init_got_refcount.glist = NULL;
    351  1.1.1.4  christos   ret->elf.init_got_offset.offset = 0;
    352  1.1.1.4  christos   ret->elf.init_got_offset.glist = NULL;
    353  1.1.1.4  christos 
    354  1.1.1.4  christos   ret->elf.root.hash_table_free = elf_arc_link_hash_table_free;
    355  1.1.1.4  christos 
    356  1.1.1.4  christos   return &ret->elf.root;
    357  1.1.1.4  christos }
    358  1.1.1.4  christos 
    359  1.1.1.2  christos #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
    360  1.1.1.2  christos   { BFD_RELOC_##TYPE, R_##TYPE },
    361      1.1     skrll static const struct arc_reloc_map arc_reloc_map[] =
    362      1.1     skrll {
    363  1.1.1.3  christos #include "elf/arc-reloc.def"
    364  1.1.1.3  christos 
    365  1.1.1.2  christos   {BFD_RELOC_NONE,  R_ARC_NONE},
    366  1.1.1.2  christos   {BFD_RELOC_8,  R_ARC_8},
    367  1.1.1.2  christos   {BFD_RELOC_16, R_ARC_16},
    368  1.1.1.2  christos   {BFD_RELOC_24, R_ARC_24},
    369  1.1.1.2  christos   {BFD_RELOC_32, R_ARC_32},
    370      1.1     skrll };
    371  1.1.1.2  christos #undef ARC_RELOC_HOWTO
    372      1.1     skrll 
    373  1.1.1.3  christos typedef ATTRIBUTE_UNUSED bfd_vma (*replace_func) (unsigned, int ATTRIBUTE_UNUSED);
    374  1.1.1.3  christos 
    375  1.1.1.3  christos #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
    376  1.1.1.3  christos   case TYPE: \
    377  1.1.1.3  christos     func = (void *) RELOC_FUNCTION; \
    378  1.1.1.3  christos     break;
    379  1.1.1.3  christos static replace_func
    380  1.1.1.3  christos get_replace_function (bfd *abfd, unsigned int r_type)
    381      1.1     skrll {
    382  1.1.1.3  christos   void *func = NULL;
    383  1.1.1.2  christos 
    384  1.1.1.3  christos   switch (r_type)
    385  1.1.1.2  christos     {
    386  1.1.1.3  christos       #include "elf/arc-reloc.def"
    387  1.1.1.2  christos     }
    388      1.1     skrll 
    389  1.1.1.3  christos   if (func == replace_bits24 && bfd_big_endian (abfd))
    390  1.1.1.3  christos     return (replace_func) replace_bits24_be;
    391  1.1.1.3  christos 
    392  1.1.1.3  christos   return (replace_func) func;
    393  1.1.1.3  christos }
    394  1.1.1.3  christos #undef ARC_RELOC_HOWTO
    395  1.1.1.3  christos 
    396  1.1.1.3  christos static reloc_howto_type *
    397  1.1.1.3  christos arc_elf32_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
    398  1.1.1.3  christos 				 bfd_reloc_code_real_type code)
    399  1.1.1.3  christos {
    400  1.1.1.3  christos   unsigned int i;
    401  1.1.1.3  christos 
    402      1.1     skrll   for (i = ARRAY_SIZE (arc_reloc_map); i--;)
    403  1.1.1.2  christos     {
    404  1.1.1.2  christos       if (arc_reloc_map[i].bfd_reloc_val == code)
    405  1.1.1.3  christos 	return arc_elf_howto (arc_reloc_map[i].elf_reloc_val);
    406  1.1.1.2  christos     }
    407      1.1     skrll 
    408      1.1     skrll   return NULL;
    409      1.1     skrll }
    410      1.1     skrll 
    411  1.1.1.3  christos /* Function to set the ELF flag bits.  */
    412  1.1.1.3  christos static bfd_boolean
    413  1.1.1.3  christos arc_elf_set_private_flags (bfd *abfd, flagword flags)
    414  1.1.1.3  christos {
    415  1.1.1.3  christos   elf_elfheader (abfd)->e_flags = flags;
    416  1.1.1.3  christos   elf_flags_init (abfd) = TRUE;
    417  1.1.1.3  christos   return TRUE;
    418  1.1.1.3  christos }
    419  1.1.1.3  christos 
    420  1.1.1.3  christos /* Print private flags.  */
    421  1.1.1.3  christos static bfd_boolean
    422  1.1.1.3  christos arc_elf_print_private_bfd_data (bfd *abfd, void * ptr)
    423  1.1.1.3  christos {
    424  1.1.1.3  christos   FILE *file = (FILE *) ptr;
    425  1.1.1.3  christos   flagword flags;
    426  1.1.1.3  christos 
    427  1.1.1.3  christos   BFD_ASSERT (abfd != NULL && ptr != NULL);
    428  1.1.1.3  christos 
    429  1.1.1.3  christos   /* Print normal ELF private data.  */
    430  1.1.1.3  christos   _bfd_elf_print_private_bfd_data (abfd, ptr);
    431  1.1.1.3  christos 
    432  1.1.1.3  christos   flags = elf_elfheader (abfd)->e_flags;
    433  1.1.1.3  christos   fprintf (file, _("private flags = 0x%lx:"), (unsigned long) flags);
    434  1.1.1.3  christos 
    435  1.1.1.3  christos   switch (flags & EF_ARC_MACH_MSK)
    436  1.1.1.3  christos     {
    437  1.1.1.3  christos     case EF_ARC_CPU_ARCV2HS : fprintf (file, " -mcpu=ARCv2HS");    break;
    438  1.1.1.3  christos     case EF_ARC_CPU_ARCV2EM : fprintf (file, " -mcpu=ARCv2EM");    break;
    439  1.1.1.3  christos     case E_ARC_MACH_ARC600  : fprintf (file, " -mcpu=ARC600");     break;
    440  1.1.1.3  christos     case E_ARC_MACH_ARC601  : fprintf (file, " -mcpu=ARC601");     break;
    441  1.1.1.3  christos     case E_ARC_MACH_ARC700  : fprintf (file, " -mcpu=ARC700");     break;
    442  1.1.1.3  christos     default:
    443  1.1.1.3  christos       fprintf (file, "-mcpu=unknown");
    444  1.1.1.3  christos       break;
    445  1.1.1.3  christos     }
    446  1.1.1.3  christos 
    447  1.1.1.3  christos   switch (flags & EF_ARC_OSABI_MSK)
    448  1.1.1.3  christos     {
    449  1.1.1.3  christos     case E_ARC_OSABI_ORIG : fprintf (file, " (ABI:legacy)"); break;
    450  1.1.1.3  christos     case E_ARC_OSABI_V2   : fprintf (file, " (ABI:v2)");     break;
    451  1.1.1.3  christos     case E_ARC_OSABI_V3   : fprintf (file, " (ABI:v3)");     break;
    452  1.1.1.4  christos     case E_ARC_OSABI_V4   : fprintf (file, " (ABI:v4)");     break;
    453  1.1.1.3  christos     default:
    454  1.1.1.4  christos       fprintf (file, " (ABI:unknown)");
    455  1.1.1.3  christos       break;
    456  1.1.1.3  christos     }
    457  1.1.1.3  christos 
    458  1.1.1.3  christos   fputc ('\n', file);
    459  1.1.1.3  christos   return TRUE;
    460  1.1.1.3  christos }
    461  1.1.1.3  christos 
    462  1.1.1.3  christos /* Copy backend specific data from one object module to another.  */
    463  1.1.1.3  christos 
    464  1.1.1.3  christos static bfd_boolean
    465  1.1.1.3  christos arc_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
    466  1.1.1.3  christos {
    467  1.1.1.3  christos   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    468  1.1.1.3  christos       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    469  1.1.1.3  christos     return TRUE;
    470  1.1.1.3  christos 
    471  1.1.1.3  christos   BFD_ASSERT (!elf_flags_init (obfd)
    472  1.1.1.3  christos 	      || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
    473  1.1.1.3  christos 
    474  1.1.1.3  christos   elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
    475  1.1.1.3  christos   elf_flags_init (obfd) = TRUE;
    476  1.1.1.3  christos 
    477  1.1.1.3  christos   /* Copy object attributes.  */
    478  1.1.1.3  christos   _bfd_elf_copy_obj_attributes (ibfd, obfd);
    479  1.1.1.3  christos 
    480  1.1.1.3  christos   return _bfd_elf_copy_private_bfd_data (ibfd, obfd);
    481  1.1.1.3  christos }
    482  1.1.1.3  christos 
    483      1.1     skrll static reloc_howto_type *
    484  1.1.1.3  christos bfd_elf32_bfd_reloc_name_lookup (bfd * abfd ATTRIBUTE_UNUSED,
    485  1.1.1.3  christos 				 const char *r_name)
    486      1.1     skrll {
    487      1.1     skrll   unsigned int i;
    488      1.1     skrll 
    489  1.1.1.2  christos   for (i = 0; i < ARRAY_SIZE (elf_arc_howto_table); i++)
    490      1.1     skrll     if (elf_arc_howto_table[i].name != NULL
    491      1.1     skrll 	&& strcasecmp (elf_arc_howto_table[i].name, r_name) == 0)
    492  1.1.1.3  christos       return arc_elf_howto (i);
    493      1.1     skrll 
    494      1.1     skrll   return NULL;
    495      1.1     skrll }
    496      1.1     skrll 
    497  1.1.1.2  christos /* Set the howto pointer for an ARC ELF reloc.  */
    498  1.1.1.3  christos 
    499      1.1     skrll static void
    500  1.1.1.2  christos arc_info_to_howto_rel (bfd * abfd ATTRIBUTE_UNUSED,
    501  1.1.1.2  christos 		       arelent * cache_ptr,
    502  1.1.1.2  christos 		       Elf_Internal_Rela * dst)
    503      1.1     skrll {
    504      1.1     skrll   unsigned int r_type;
    505      1.1     skrll 
    506      1.1     skrll   r_type = ELF32_R_TYPE (dst->r_info);
    507      1.1     skrll   BFD_ASSERT (r_type < (unsigned int) R_ARC_max);
    508  1.1.1.3  christos   cache_ptr->howto = arc_elf_howto (r_type);
    509  1.1.1.3  christos }
    510  1.1.1.3  christos 
    511  1.1.1.4  christos /* Extract CPU features from an NTBS.  */
    512  1.1.1.4  christos 
    513  1.1.1.4  christos static unsigned
    514  1.1.1.4  christos arc_extract_features (const char *p)
    515  1.1.1.4  christos {
    516  1.1.1.4  christos   unsigned i, r = 0;
    517  1.1.1.4  christos 
    518  1.1.1.4  christos   if (!p)
    519  1.1.1.4  christos     return 0;
    520  1.1.1.4  christos 
    521  1.1.1.4  christos   for (i = 0; i < ARRAY_SIZE (bfd_feature_list); i++)
    522  1.1.1.4  christos     {
    523  1.1.1.4  christos       char *t = strstr (p, bfd_feature_list[i].attr);
    524  1.1.1.4  christos       unsigned l = strlen (bfd_feature_list[i].attr);
    525  1.1.1.4  christos       if ((t != NULL)
    526  1.1.1.4  christos 	  && (t[l] == ','
    527  1.1.1.4  christos 	      || t[l] == '\0'))
    528  1.1.1.4  christos 	r |= bfd_feature_list[i].feature;
    529  1.1.1.4  christos     }
    530  1.1.1.4  christos 
    531  1.1.1.4  christos   return r;
    532  1.1.1.4  christos }
    533  1.1.1.4  christos 
    534  1.1.1.4  christos /* Concatenate two strings.  s1 can be NULL but not
    535  1.1.1.4  christos    s2.  */
    536  1.1.1.4  christos 
    537  1.1.1.4  christos static char *
    538  1.1.1.4  christos arc_stralloc (char * s1, const char * s2)
    539  1.1.1.4  christos {
    540  1.1.1.4  christos   char *p;
    541  1.1.1.4  christos 
    542  1.1.1.4  christos   /* Only s1 can be null.  */
    543  1.1.1.4  christos   BFD_ASSERT (s2);
    544  1.1.1.4  christos 
    545  1.1.1.4  christos   p = s1 ? concat (s1, ",", s2, NULL) : (char *)s2;
    546  1.1.1.4  christos 
    547  1.1.1.4  christos   return p;
    548  1.1.1.4  christos }
    549  1.1.1.4  christos 
    550  1.1.1.4  christos /* Merge ARC object attributes from IBFD into OBFD.  Raise an error if
    551  1.1.1.4  christos    there are conflicting attributes.  */
    552  1.1.1.4  christos 
    553  1.1.1.4  christos static bfd_boolean
    554  1.1.1.4  christos arc_elf_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
    555  1.1.1.4  christos {
    556  1.1.1.4  christos   bfd *obfd = info->output_bfd;
    557  1.1.1.4  christos   obj_attribute *in_attr;
    558  1.1.1.4  christos   obj_attribute *out_attr;
    559  1.1.1.4  christos   int i;
    560  1.1.1.4  christos   bfd_boolean result = TRUE;
    561  1.1.1.4  christos   const char *sec_name = get_elf_backend_data (ibfd)->obj_attrs_section;
    562  1.1.1.4  christos   char *tagname = NULL;
    563  1.1.1.4  christos 
    564  1.1.1.4  christos   /* Skip the linker stubs file.  This preserves previous behavior
    565  1.1.1.4  christos      of accepting unknown attributes in the first input file - but
    566  1.1.1.4  christos      is that a bug?  */
    567  1.1.1.4  christos   if (ibfd->flags & BFD_LINKER_CREATED)
    568  1.1.1.4  christos     return TRUE;
    569  1.1.1.4  christos 
    570  1.1.1.4  christos   /* Skip any input that hasn't attribute section.
    571  1.1.1.4  christos      This enables to link object files without attribute section with
    572  1.1.1.4  christos      any others.  */
    573  1.1.1.4  christos   if (bfd_get_section_by_name (ibfd, sec_name) == NULL)
    574  1.1.1.4  christos     return TRUE;
    575  1.1.1.4  christos 
    576  1.1.1.4  christos   if (!elf_known_obj_attributes_proc (obfd)[0].i)
    577  1.1.1.4  christos     {
    578  1.1.1.4  christos       /* This is the first object.  Copy the attributes.  */
    579  1.1.1.4  christos       _bfd_elf_copy_obj_attributes (ibfd, obfd);
    580  1.1.1.4  christos 
    581  1.1.1.4  christos       out_attr = elf_known_obj_attributes_proc (obfd);
    582  1.1.1.4  christos 
    583  1.1.1.4  christos       /* Use the Tag_null value to indicate the attributes have been
    584  1.1.1.4  christos 	 initialized.  */
    585  1.1.1.4  christos       out_attr[0].i = 1;
    586  1.1.1.4  christos 
    587  1.1.1.4  christos       return TRUE;
    588  1.1.1.4  christos     }
    589  1.1.1.4  christos 
    590  1.1.1.4  christos   in_attr = elf_known_obj_attributes_proc (ibfd);
    591  1.1.1.4  christos   out_attr = elf_known_obj_attributes_proc (obfd);
    592  1.1.1.4  christos 
    593  1.1.1.4  christos   for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
    594  1.1.1.4  christos     {
    595  1.1.1.4  christos       /* Merge this attribute with existing attributes.  */
    596  1.1.1.4  christos       switch (i)
    597  1.1.1.4  christos 	{
    598  1.1.1.4  christos 	case Tag_ARC_PCS_config:
    599  1.1.1.4  christos 	  if (out_attr[i].i == 0)
    600  1.1.1.4  christos 	    out_attr[i].i = in_attr[i].i;
    601  1.1.1.4  christos 	  else if (in_attr[i].i != 0 && out_attr[i].i != in_attr[i].i)
    602  1.1.1.4  christos 	    {
    603  1.1.1.4  christos 	      const char *tagval[] = { "Absent", "Bare-metal/mwdt",
    604  1.1.1.4  christos 					"Bare-metal/newlib", "Linux/uclibc",
    605  1.1.1.4  christos 					"Linux/glibc" };
    606  1.1.1.4  christos 	      BFD_ASSERT (in_attr[i].i < 5);
    607  1.1.1.4  christos 	      BFD_ASSERT (out_attr[i].i < 5);
    608  1.1.1.4  christos 	      /* It's sometimes ok to mix different configs, so this is only
    609  1.1.1.4  christos 		 a warning.  */
    610  1.1.1.4  christos 	      _bfd_error_handler
    611  1.1.1.4  christos 		(_("Warning: %B: Conflicting platform configuration "
    612  1.1.1.4  christos 		   "%s with %s.\n"), ibfd,
    613  1.1.1.4  christos 		 tagval[in_attr[i].i],
    614  1.1.1.4  christos 		 tagval[out_attr[i].i]);
    615  1.1.1.4  christos 	    }
    616  1.1.1.4  christos 	  break;
    617  1.1.1.4  christos 
    618  1.1.1.4  christos 	case Tag_ARC_CPU_base:
    619  1.1.1.4  christos 	  if (out_attr[i].i == 0)
    620  1.1.1.4  christos 	    out_attr[i].i = in_attr[i].i;
    621  1.1.1.4  christos 	  else if (in_attr[i].i != 0 && out_attr[i].i != in_attr[i].i
    622  1.1.1.4  christos 		   && ((out_attr[i].i + in_attr[i].i) < 6))
    623  1.1.1.4  christos 	    {
    624  1.1.1.4  christos 	      const char *tagval[] = { "Absent", "ARC6xx", "ARC7xx",
    625  1.1.1.4  christos 					"ARCEM", "ARCHS" };
    626  1.1.1.4  christos 	      BFD_ASSERT (in_attr[i].i < 5);
    627  1.1.1.4  christos 	      BFD_ASSERT (out_attr[i].i < 5);
    628  1.1.1.4  christos 	      /* We cannot mix code for different CPUs.  */
    629  1.1.1.4  christos 	      _bfd_error_handler
    630  1.1.1.4  christos 		(_("error: %B: unable to merge CPU base attributes "
    631  1.1.1.4  christos 		   "%s with %s.\n"),
    632  1.1.1.4  christos 		 obfd,
    633  1.1.1.4  christos 		 tagval[in_attr[i].i],
    634  1.1.1.4  christos 		 tagval[out_attr[i].i]);
    635  1.1.1.4  christos 	      result = FALSE;
    636  1.1.1.4  christos 	      break;
    637  1.1.1.4  christos 	    }
    638  1.1.1.4  christos 	  else
    639  1.1.1.4  christos 	    {
    640  1.1.1.4  christos 	      /* The CPUs may be different, check if we can still mix
    641  1.1.1.4  christos 		 the objects against the output choosen CPU.  */
    642  1.1.1.4  christos 	      unsigned in_feature = 0;
    643  1.1.1.4  christos 	      unsigned out_feature = 0;
    644  1.1.1.4  christos 	      char *p1 = in_attr[Tag_ARC_ISA_config].s;
    645  1.1.1.4  christos 	      char *p2 = out_attr[Tag_ARC_ISA_config].s;
    646  1.1.1.4  christos 	      unsigned j;
    647  1.1.1.4  christos 	      unsigned cpu_out;
    648  1.1.1.4  christos 	      unsigned opcode_map[] = {0, ARC_OPCODE_ARC600, ARC_OPCODE_ARC700,
    649  1.1.1.4  christos 				       ARC_OPCODE_ARCv2EM, ARC_OPCODE_ARCv2HS};
    650  1.1.1.4  christos 
    651  1.1.1.4  christos 	      BFD_ASSERT (in_attr[i].i < (sizeof (opcode_map)
    652  1.1.1.4  christos 					  / sizeof (unsigned)));
    653  1.1.1.4  christos 	      BFD_ASSERT (out_attr[i].i < (sizeof (opcode_map)
    654  1.1.1.4  christos 					   / sizeof (unsigned)));
    655  1.1.1.4  christos 	      cpu_out = opcode_map[out_attr[i].i];
    656  1.1.1.4  christos 
    657  1.1.1.4  christos 	      in_feature = arc_extract_features (p1);
    658  1.1.1.4  christos 	      out_feature = arc_extract_features (p2);
    659  1.1.1.4  christos 
    660  1.1.1.4  christos 	      /* First, check if a feature is compatible with the
    661  1.1.1.4  christos 		 output object chosen CPU.  */
    662  1.1.1.4  christos 	      for (j = 0; j < ARRAY_SIZE (bfd_feature_list); j++)
    663  1.1.1.4  christos 		if (((in_feature | out_feature) & bfd_feature_list[j].feature)
    664  1.1.1.4  christos 		    && (!(cpu_out & bfd_feature_list[j].cpus)))
    665  1.1.1.4  christos 		  {
    666  1.1.1.4  christos 		    _bfd_error_handler
    667  1.1.1.4  christos 		      (_("error: %B: unable to merge ISA extension attributes "
    668  1.1.1.4  christos 			 "%s.\n"),
    669  1.1.1.4  christos 		       obfd, bfd_feature_list[j].name);
    670  1.1.1.4  christos 		    result = FALSE;
    671  1.1.1.4  christos 		    break;
    672  1.1.1.4  christos 		  }
    673  1.1.1.4  christos 	      /* Second, if we have compatible features with the
    674  1.1.1.4  christos 		 chosen CPU, check if they are compatible among
    675  1.1.1.4  christos 		 them.  */
    676  1.1.1.4  christos 	      for (j = 0; j < ARRAY_SIZE (bfd_conflict_list); j++)
    677  1.1.1.4  christos 		if (((in_feature | out_feature) & bfd_conflict_list[j])
    678  1.1.1.4  christos 		    == bfd_conflict_list[j])
    679  1.1.1.4  christos 		  {
    680  1.1.1.4  christos 		    unsigned k;
    681  1.1.1.4  christos 		    for (k = 0; k < ARRAY_SIZE (bfd_feature_list); k++)
    682  1.1.1.4  christos 		      {
    683  1.1.1.4  christos 			if (in_feature &  bfd_feature_list[k].feature
    684  1.1.1.4  christos 			    & bfd_conflict_list[j])
    685  1.1.1.4  christos 			  p1 = (char *) bfd_feature_list[k].name;
    686  1.1.1.4  christos 			if (out_feature &  bfd_feature_list[k].feature
    687  1.1.1.4  christos 			    & bfd_conflict_list[j])
    688  1.1.1.4  christos 			  p2 = (char *) bfd_feature_list[k].name;
    689  1.1.1.4  christos 		      }
    690  1.1.1.4  christos 		    _bfd_error_handler
    691  1.1.1.4  christos 		      (_("error: %B: conflicting ISA extension attributes "
    692  1.1.1.4  christos 			 "%s with %s.\n"),
    693  1.1.1.4  christos 		       obfd, p1, p2);
    694  1.1.1.4  christos 		    result = FALSE;
    695  1.1.1.4  christos 		    break;
    696  1.1.1.4  christos 		  }
    697  1.1.1.4  christos 	      /* Everithing is alright.  */
    698  1.1.1.4  christos 	      out_feature |= in_feature;
    699  1.1.1.4  christos 	      p1 = NULL;
    700  1.1.1.4  christos 	      for (j = 0; j < ARRAY_SIZE (bfd_feature_list); j++)
    701  1.1.1.4  christos 		if (out_feature & bfd_feature_list[j].feature)
    702  1.1.1.4  christos 		  p1 = arc_stralloc (p1, bfd_feature_list[j].attr);
    703  1.1.1.4  christos 	      if (p1)
    704  1.1.1.4  christos 		out_attr[Tag_ARC_ISA_config].s =
    705  1.1.1.4  christos 		  _bfd_elf_attr_strdup (obfd, p1);
    706  1.1.1.4  christos 	    }
    707  1.1.1.4  christos 	  /* Fall through.  */
    708  1.1.1.4  christos 	case Tag_ARC_CPU_variation:
    709  1.1.1.4  christos 	case Tag_ARC_ISA_mpy_option:
    710  1.1.1.4  christos 	case Tag_ARC_ABI_osver:
    711  1.1.1.4  christos 	  /* Use the largest value specified.  */
    712  1.1.1.4  christos 	  if (in_attr[i].i > out_attr[i].i)
    713  1.1.1.4  christos 	    out_attr[i].i = in_attr[i].i;
    714  1.1.1.4  christos 	  break;
    715  1.1.1.4  christos 
    716  1.1.1.4  christos 	case Tag_ARC_CPU_name:
    717  1.1.1.4  christos 	  break;
    718  1.1.1.4  christos 
    719  1.1.1.4  christos 	case Tag_ARC_ABI_rf16:
    720  1.1.1.4  christos 	  if (out_attr[i].i == 0)
    721  1.1.1.4  christos 	    out_attr[i].i = in_attr[i].i;
    722  1.1.1.4  christos 	  else if (out_attr[i].i != in_attr[i].i)
    723  1.1.1.4  christos 	    {
    724  1.1.1.4  christos 	      /* We cannot mix code with rf16 and without.  */
    725  1.1.1.4  christos 	      _bfd_error_handler
    726  1.1.1.4  christos 		(_("error: %B: cannot mix rf16 with full register set %B.\n"),
    727  1.1.1.4  christos 		 obfd, ibfd);
    728  1.1.1.4  christos 	      result = FALSE;
    729  1.1.1.4  christos 	    }
    730  1.1.1.4  christos 	  break;
    731  1.1.1.4  christos 
    732  1.1.1.4  christos 	case Tag_ARC_ABI_pic:
    733  1.1.1.4  christos 	  tagname = "PIC";
    734  1.1.1.4  christos 	  /* fall through */
    735  1.1.1.4  christos 	case Tag_ARC_ABI_sda:
    736  1.1.1.4  christos 	  if (!tagname)
    737  1.1.1.4  christos 	    tagname = "SDA";
    738  1.1.1.4  christos 	  /* fall through */
    739  1.1.1.4  christos 	case Tag_ARC_ABI_tls:
    740  1.1.1.4  christos 	  {
    741  1.1.1.4  christos 	    const char *tagval[] = { "Absent", "MWDT", "GNU" };
    742  1.1.1.4  christos 
    743  1.1.1.4  christos 	    if (!tagname)
    744  1.1.1.4  christos 	      tagname = "TLS";
    745  1.1.1.4  christos 
    746  1.1.1.4  christos 	    BFD_ASSERT (in_attr[i].i < 3);
    747  1.1.1.4  christos 	    BFD_ASSERT (out_attr[i].i < 3);
    748  1.1.1.4  christos 	    if (out_attr[i].i != 0 && in_attr[i].i != 0
    749  1.1.1.4  christos 		&& out_attr[i].i != in_attr[i].i)
    750  1.1.1.4  christos 	      {
    751  1.1.1.4  christos 		_bfd_error_handler
    752  1.1.1.4  christos 		  (_("error: %B: conflicting attributes %s: %s with %s.\n"),
    753  1.1.1.4  christos 		   obfd, tagname,
    754  1.1.1.4  christos 		   tagval[in_attr[i].i],
    755  1.1.1.4  christos 		   tagval[out_attr[i].i]);
    756  1.1.1.4  christos 		result = FALSE;
    757  1.1.1.4  christos 	      }
    758  1.1.1.4  christos 	    tagname = NULL;
    759  1.1.1.4  christos 	    break;
    760  1.1.1.4  christos 	  }
    761  1.1.1.4  christos 
    762  1.1.1.4  christos 	case Tag_ARC_ABI_double_size:
    763  1.1.1.4  christos 	  tagname = "Double size";
    764  1.1.1.4  christos 	  /* fall through */
    765  1.1.1.4  christos 	case Tag_ARC_ABI_enumsize:
    766  1.1.1.4  christos 	  if (!tagname)
    767  1.1.1.4  christos 	    tagname = "Enum size";
    768  1.1.1.4  christos 	  /* fall through */
    769  1.1.1.4  christos 	case Tag_ARC_ABI_exceptions:
    770  1.1.1.4  christos 	  if (!tagname)
    771  1.1.1.4  christos 	    tagname = "ABI exceptions";
    772  1.1.1.4  christos 
    773  1.1.1.4  christos 	  if (out_attr[i].i != 0 && in_attr[i].i != 0
    774  1.1.1.4  christos 	      && out_attr[i].i != in_attr[i].i)
    775  1.1.1.4  christos 	    {
    776  1.1.1.4  christos 	      _bfd_error_handler
    777  1.1.1.4  christos 		(_("error: %B: conflicting attributes %s.\n"),
    778  1.1.1.4  christos 		 obfd, tagname);
    779  1.1.1.4  christos 	      result = FALSE;
    780  1.1.1.4  christos 	    }
    781  1.1.1.4  christos 	  break;
    782  1.1.1.4  christos 
    783  1.1.1.4  christos 	case Tag_ARC_ISA_apex:
    784  1.1.1.4  christos 	  break; /* Do nothing for APEX attributes.  */
    785  1.1.1.4  christos 
    786  1.1.1.4  christos 	case Tag_ARC_ISA_config:
    787  1.1.1.4  christos 	  /* It is handled in Tag_ARC_CPU_base.  */
    788  1.1.1.4  christos 	  break;
    789  1.1.1.4  christos 
    790  1.1.1.4  christos 	default:
    791  1.1.1.4  christos 	  result
    792  1.1.1.4  christos 	    = result && _bfd_elf_merge_unknown_attribute_low (ibfd, obfd, i);
    793  1.1.1.4  christos 	}
    794  1.1.1.4  christos 
    795  1.1.1.4  christos       /* If out_attr was copied from in_attr then it won't have a type yet.  */
    796  1.1.1.4  christos       if (in_attr[i].type && !out_attr[i].type)
    797  1.1.1.4  christos 	out_attr[i].type = in_attr[i].type;
    798  1.1.1.4  christos     }
    799  1.1.1.4  christos 
    800  1.1.1.4  christos   /* Merge Tag_compatibility attributes and any common GNU ones.  */
    801  1.1.1.4  christos   if (!_bfd_elf_merge_object_attributes (ibfd, info))
    802  1.1.1.4  christos     return FALSE;
    803  1.1.1.4  christos 
    804  1.1.1.4  christos   /* Check for any attributes not known on ARC.  */
    805  1.1.1.4  christos   result &= _bfd_elf_merge_unknown_attribute_list (ibfd, obfd);
    806  1.1.1.4  christos 
    807  1.1.1.4  christos   return result;
    808  1.1.1.4  christos }
    809  1.1.1.4  christos 
    810  1.1.1.3  christos /* Merge backend specific data from an object file to the output
    811  1.1.1.3  christos    object file when linking.  */
    812  1.1.1.3  christos 
    813  1.1.1.3  christos static bfd_boolean
    814  1.1.1.4  christos arc_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
    815  1.1.1.3  christos {
    816  1.1.1.4  christos   bfd *obfd = info->output_bfd;
    817  1.1.1.3  christos   unsigned short mach_ibfd;
    818  1.1.1.3  christos   static unsigned short mach_obfd = EM_NONE;
    819  1.1.1.3  christos   flagword out_flags;
    820  1.1.1.3  christos   flagword in_flags;
    821  1.1.1.3  christos   asection *sec;
    822  1.1.1.3  christos 
    823  1.1.1.3  christos    /* Check if we have the same endianess.  */
    824  1.1.1.4  christos   if (! _bfd_generic_verify_endian_match (ibfd, info))
    825  1.1.1.4  christos     return FALSE;
    826  1.1.1.4  christos 
    827  1.1.1.4  christos   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    828  1.1.1.4  christos       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    829  1.1.1.4  christos     return TRUE;
    830  1.1.1.3  christos 
    831  1.1.1.3  christos   /* Collect ELF flags.  */
    832  1.1.1.3  christos   in_flags = elf_elfheader (ibfd)->e_flags & EF_ARC_MACH_MSK;
    833  1.1.1.3  christos   out_flags = elf_elfheader (obfd)->e_flags & EF_ARC_MACH_MSK;
    834  1.1.1.3  christos 
    835  1.1.1.3  christos   if (!elf_flags_init (obfd)) /* First call, no flags set.  */
    836  1.1.1.3  christos     {
    837  1.1.1.3  christos       elf_flags_init (obfd) = TRUE;
    838  1.1.1.3  christos       out_flags = in_flags;
    839  1.1.1.3  christos     }
    840  1.1.1.3  christos 
    841  1.1.1.4  christos   if (!arc_elf_merge_attributes (ibfd, info))
    842  1.1.1.4  christos     return FALSE;
    843  1.1.1.3  christos 
    844  1.1.1.3  christos   /* Check to see if the input BFD actually contains any sections.  Do
    845  1.1.1.3  christos      not short-circuit dynamic objects; their section list may be
    846  1.1.1.3  christos      emptied by elf_link_add_object_symbols.  */
    847  1.1.1.3  christos   if (!(ibfd->flags & DYNAMIC))
    848  1.1.1.3  christos     {
    849  1.1.1.3  christos       bfd_boolean null_input_bfd = TRUE;
    850  1.1.1.3  christos       bfd_boolean only_data_sections = TRUE;
    851  1.1.1.3  christos 
    852  1.1.1.3  christos       for (sec = ibfd->sections; sec != NULL; sec = sec->next)
    853  1.1.1.3  christos 	{
    854  1.1.1.3  christos 	  if ((bfd_get_section_flags (ibfd, sec)
    855  1.1.1.3  christos 	       & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
    856  1.1.1.3  christos 	      == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
    857  1.1.1.3  christos 	    only_data_sections = FALSE;
    858  1.1.1.3  christos 
    859  1.1.1.3  christos 	  null_input_bfd = FALSE;
    860  1.1.1.3  christos 	}
    861  1.1.1.3  christos 
    862  1.1.1.3  christos       if (null_input_bfd || only_data_sections)
    863  1.1.1.3  christos 	return TRUE;
    864  1.1.1.3  christos     }
    865  1.1.1.3  christos 
    866  1.1.1.3  christos   /* Complain about various flag/architecture mismatches.  */
    867  1.1.1.3  christos   mach_ibfd = elf_elfheader (ibfd)->e_machine;
    868  1.1.1.3  christos   if (mach_obfd == EM_NONE)
    869  1.1.1.3  christos     {
    870  1.1.1.3  christos       mach_obfd = mach_ibfd;
    871  1.1.1.3  christos     }
    872  1.1.1.3  christos   else
    873  1.1.1.3  christos     {
    874  1.1.1.3  christos       if (mach_ibfd != mach_obfd)
    875  1.1.1.3  christos 	{
    876  1.1.1.4  christos 	  /* xgettext:c-format */
    877  1.1.1.3  christos 	  _bfd_error_handler (_("ERROR: Attempting to link %B "
    878  1.1.1.4  christos 				"with a binary %B of different architecture"),
    879  1.1.1.4  christos 			      ibfd, obfd);
    880  1.1.1.3  christos 	  return FALSE;
    881  1.1.1.3  christos 	}
    882  1.1.1.4  christos       else if ((in_flags != out_flags)
    883  1.1.1.4  christos 	       /* If we have object attributes, then we already
    884  1.1.1.4  christos 		  checked the objects compatibility, skip it.  */
    885  1.1.1.4  christos 	       && !bfd_elf_get_obj_attr_int (ibfd, OBJ_ATTR_PROC,
    886  1.1.1.4  christos 					     Tag_ARC_CPU_base))
    887  1.1.1.3  christos 	{
    888  1.1.1.3  christos 	  /* Warn if different flags.  */
    889  1.1.1.4  christos 	  _bfd_error_handler
    890  1.1.1.4  christos 	    /* xgettext:c-format */
    891  1.1.1.4  christos 	    (_("%B: uses different e_flags (%#x) fields than "
    892  1.1.1.4  christos 	       "previous modules (%#x)"),
    893  1.1.1.4  christos 	     ibfd, in_flags, out_flags);
    894  1.1.1.3  christos 	  if (in_flags && out_flags)
    895  1.1.1.3  christos 	    return FALSE;
    896  1.1.1.3  christos 	  /* MWDT doesnt set the eflags hence make sure we choose the
    897  1.1.1.3  christos 	     eflags set by gcc.  */
    898  1.1.1.3  christos 	  in_flags = in_flags > out_flags ? in_flags : out_flags;
    899  1.1.1.3  christos 	}
    900  1.1.1.4  christos       else
    901  1.1.1.4  christos 	{
    902  1.1.1.4  christos 	  /* Everything is correct; don't change the output flags.  */
    903  1.1.1.4  christos 	  in_flags = out_flags;
    904  1.1.1.4  christos 	}
    905  1.1.1.3  christos     }
    906  1.1.1.3  christos 
    907  1.1.1.3  christos   /* Update the flags.  */
    908  1.1.1.3  christos   elf_elfheader (obfd)->e_flags = in_flags;
    909  1.1.1.3  christos 
    910  1.1.1.3  christos   if (bfd_get_mach (obfd) < bfd_get_mach (ibfd))
    911  1.1.1.3  christos     {
    912  1.1.1.3  christos       return bfd_set_arch_mach (obfd, bfd_arch_arc, bfd_get_mach (ibfd));
    913  1.1.1.3  christos     }
    914  1.1.1.3  christos 
    915  1.1.1.3  christos   return TRUE;
    916      1.1     skrll }
    917      1.1     skrll 
    918  1.1.1.4  christos /* Return a best guess for the machine number based on the attributes.  */
    919  1.1.1.4  christos 
    920  1.1.1.4  christos static unsigned int
    921  1.1.1.4  christos bfd_arc_get_mach_from_attributes (bfd * abfd)
    922  1.1.1.4  christos {
    923  1.1.1.4  christos   int arch = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC, Tag_ARC_CPU_base);
    924  1.1.1.4  christos   unsigned e_machine = elf_elfheader (abfd)->e_machine;
    925  1.1.1.4  christos 
    926  1.1.1.4  christos   switch (arch)
    927  1.1.1.4  christos     {
    928  1.1.1.4  christos     case TAG_CPU_ARC6xx:
    929  1.1.1.4  christos       return bfd_mach_arc_arc600;
    930  1.1.1.4  christos     case TAG_CPU_ARC7xx:
    931  1.1.1.4  christos       return bfd_mach_arc_arc700;
    932  1.1.1.4  christos     case TAG_CPU_ARCEM:
    933  1.1.1.4  christos     case TAG_CPU_ARCHS:
    934  1.1.1.4  christos       return bfd_mach_arc_arcv2;
    935  1.1.1.4  christos     default:
    936  1.1.1.4  christos       break;
    937  1.1.1.4  christos     }
    938  1.1.1.4  christos   return (e_machine == EM_ARC_COMPACT)
    939  1.1.1.4  christos     ? bfd_mach_arc_arc700 : bfd_mach_arc_arcv2;
    940  1.1.1.4  christos }
    941  1.1.1.4  christos 
    942      1.1     skrll /* Set the right machine number for an ARC ELF file.  */
    943      1.1     skrll static bfd_boolean
    944  1.1.1.2  christos arc_elf_object_p (bfd * abfd)
    945      1.1     skrll {
    946  1.1.1.2  christos   /* Make sure this is initialised, or you'll have the potential of passing
    947  1.1.1.2  christos      garbage---or misleading values---into the call to
    948  1.1.1.2  christos      bfd_default_set_arch_mach ().  */
    949  1.1.1.4  christos   unsigned int	  mach = bfd_mach_arc_arc700;
    950  1.1.1.2  christos   unsigned long   arch = elf_elfheader (abfd)->e_flags & EF_ARC_MACH_MSK;
    951  1.1.1.2  christos   unsigned	  e_machine = elf_elfheader (abfd)->e_machine;
    952      1.1     skrll 
    953  1.1.1.2  christos   if (e_machine == EM_ARC_COMPACT || e_machine == EM_ARC_COMPACT2)
    954      1.1     skrll     {
    955      1.1     skrll       switch (arch)
    956      1.1     skrll 	{
    957  1.1.1.2  christos 	  case E_ARC_MACH_ARC600:
    958  1.1.1.2  christos 	    mach = bfd_mach_arc_arc600;
    959  1.1.1.2  christos 	    break;
    960  1.1.1.2  christos 	  case E_ARC_MACH_ARC601:
    961  1.1.1.2  christos 	    mach = bfd_mach_arc_arc601;
    962  1.1.1.2  christos 	    break;
    963  1.1.1.2  christos 	  case E_ARC_MACH_ARC700:
    964  1.1.1.2  christos 	    mach = bfd_mach_arc_arc700;
    965  1.1.1.2  christos 	    break;
    966  1.1.1.2  christos 	  case EF_ARC_CPU_ARCV2HS:
    967  1.1.1.2  christos 	  case EF_ARC_CPU_ARCV2EM:
    968  1.1.1.2  christos 	    mach = bfd_mach_arc_arcv2;
    969  1.1.1.2  christos 	    break;
    970  1.1.1.2  christos 	  default:
    971  1.1.1.4  christos 	    mach = bfd_arc_get_mach_from_attributes (abfd);
    972  1.1.1.2  christos 	    break;
    973  1.1.1.2  christos 	}
    974  1.1.1.2  christos     }
    975  1.1.1.2  christos   else
    976  1.1.1.2  christos     {
    977  1.1.1.2  christos       if (e_machine == EM_ARC)
    978  1.1.1.2  christos 	{
    979  1.1.1.4  christos 	  _bfd_error_handler
    980  1.1.1.2  christos 	    (_("Error: The ARC4 architecture is no longer supported.\n"));
    981  1.1.1.2  christos 	  return FALSE;
    982  1.1.1.2  christos 	}
    983  1.1.1.2  christos       else
    984  1.1.1.2  christos 	{
    985  1.1.1.4  christos 	  _bfd_error_handler
    986  1.1.1.2  christos 	    (_("Warning: unset or old architecture flags. \n"
    987  1.1.1.2  christos 	       "	       Use default machine.\n"));
    988      1.1     skrll 	}
    989      1.1     skrll     }
    990  1.1.1.2  christos 
    991      1.1     skrll   return bfd_default_set_arch_mach (abfd, bfd_arch_arc, mach);
    992      1.1     skrll }
    993      1.1     skrll 
    994      1.1     skrll /* The final processing done just before writing out an ARC ELF object file.
    995      1.1     skrll    This gets the ARC architecture right based on the machine number.  */
    996      1.1     skrll 
    997      1.1     skrll static void
    998  1.1.1.3  christos arc_elf_final_write_processing (bfd * abfd,
    999  1.1.1.3  christos 				bfd_boolean linker ATTRIBUTE_UNUSED)
   1000      1.1     skrll {
   1001  1.1.1.2  christos   unsigned long emf;
   1002  1.1.1.4  christos   int osver = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC,
   1003  1.1.1.4  christos 					Tag_ARC_ABI_osver);
   1004  1.1.1.4  christos   flagword e_flags = elf_elfheader (abfd)->e_flags & ~EF_ARC_OSABI_MSK;
   1005      1.1     skrll 
   1006      1.1     skrll   switch (bfd_get_mach (abfd))
   1007      1.1     skrll     {
   1008  1.1.1.2  christos     case bfd_mach_arc_arc600:
   1009  1.1.1.2  christos       emf = EM_ARC_COMPACT;
   1010      1.1     skrll       break;
   1011  1.1.1.2  christos     case bfd_mach_arc_arc601:
   1012  1.1.1.2  christos       emf = EM_ARC_COMPACT;
   1013      1.1     skrll       break;
   1014  1.1.1.2  christos     case bfd_mach_arc_arc700:
   1015  1.1.1.2  christos       emf = EM_ARC_COMPACT;
   1016      1.1     skrll       break;
   1017  1.1.1.2  christos     case bfd_mach_arc_arcv2:
   1018  1.1.1.2  christos       emf = EM_ARC_COMPACT2;
   1019      1.1     skrll       break;
   1020  1.1.1.2  christos     default:
   1021  1.1.1.4  christos       return;
   1022      1.1     skrll     }
   1023  1.1.1.3  christos 
   1024  1.1.1.2  christos   elf_elfheader (abfd)->e_machine = emf;
   1025  1.1.1.2  christos 
   1026  1.1.1.2  christos   /* Record whatever is the current syscall ABI version.  */
   1027  1.1.1.4  christos   if (osver)
   1028  1.1.1.4  christos     e_flags |= ((osver & 0x0f) << 8);
   1029  1.1.1.4  christos   else
   1030  1.1.1.4  christos     e_flags |= E_ARC_OSABI_V3;
   1031  1.1.1.3  christos 
   1032  1.1.1.4  christos   elf_elfheader (abfd)->e_flags |=  e_flags;
   1033      1.1     skrll }
   1034      1.1     skrll 
   1035  1.1.1.4  christos #ifdef ARC_ENABLE_DEBUG
   1036  1.1.1.4  christos #define DEBUG_ARC_RELOC(A) debug_arc_reloc (A)
   1037  1.1.1.2  christos 
   1038  1.1.1.2  christos static void
   1039  1.1.1.2  christos debug_arc_reloc (struct arc_relocation_data reloc_data)
   1040  1.1.1.2  christos {
   1041  1.1.1.4  christos   ARC_DEBUG ("Reloc type=%s, should_relocate = %s\n",
   1042  1.1.1.4  christos 	     reloc_data.howto->name,
   1043  1.1.1.4  christos 	     reloc_data.should_relocate ? "true" : "false");
   1044  1.1.1.4  christos   ARC_DEBUG ("  offset = 0x%x, addend = 0x%x\n",
   1045  1.1.1.4  christos 	     (unsigned int) reloc_data.reloc_offset,
   1046  1.1.1.4  christos 	     (unsigned int) reloc_data.reloc_addend);
   1047  1.1.1.4  christos   ARC_DEBUG (" Symbol:\n");
   1048  1.1.1.4  christos   ARC_DEBUG ("  value = 0x%08x\n",
   1049  1.1.1.4  christos 	     (unsigned int) reloc_data.sym_value);
   1050  1.1.1.2  christos   if (reloc_data.sym_section != NULL)
   1051  1.1.1.2  christos     {
   1052  1.1.1.4  christos       ARC_DEBUG (" Symbol Section:\n");
   1053  1.1.1.4  christos       ARC_DEBUG ("  section name = %s, output_offset 0x%08x",
   1054  1.1.1.4  christos 		 reloc_data.sym_section->name,
   1055  1.1.1.4  christos 		 (unsigned int) reloc_data.sym_section->output_offset);
   1056  1.1.1.3  christos       if (reloc_data.sym_section->output_section != NULL)
   1057  1.1.1.4  christos 	ARC_DEBUG (", output_section->vma = 0x%08x",
   1058  1.1.1.3  christos 		   ((unsigned int) reloc_data.sym_section->output_section->vma));
   1059  1.1.1.4  christos       ARC_DEBUG ("\n");
   1060  1.1.1.4  christos       if (reloc_data.sym_section->owner && reloc_data.sym_section->owner->filename)
   1061  1.1.1.4  christos 	ARC_DEBUG ("  file: %s\n", reloc_data.sym_section->owner->filename);
   1062  1.1.1.2  christos     }
   1063  1.1.1.2  christos   else
   1064  1.1.1.3  christos     {
   1065  1.1.1.4  christos       ARC_DEBUG ("  symbol section is NULL\n");
   1066  1.1.1.3  christos     }
   1067  1.1.1.2  christos 
   1068  1.1.1.4  christos   ARC_DEBUG (" Input_section:\n");
   1069  1.1.1.2  christos   if (reloc_data.input_section != NULL)
   1070  1.1.1.2  christos     {
   1071  1.1.1.4  christos       ARC_DEBUG ("  section name = %s, output_offset 0x%08x, output_section->vma = 0x%08x\n",
   1072  1.1.1.4  christos 		 reloc_data.input_section->name,
   1073  1.1.1.4  christos 		 (unsigned int) reloc_data.input_section->output_offset,
   1074  1.1.1.4  christos 		 (unsigned int) reloc_data.input_section->output_section->vma);
   1075  1.1.1.4  christos       ARC_DEBUG ("  changed_address = 0x%08x\n",
   1076  1.1.1.4  christos 		 (unsigned int) (reloc_data.input_section->output_section->vma
   1077  1.1.1.4  christos 				 + reloc_data.input_section->output_offset
   1078  1.1.1.4  christos 				 + reloc_data.reloc_offset));
   1079  1.1.1.4  christos       ARC_DEBUG ("  file: %s\n", reloc_data.input_section->owner->filename);
   1080  1.1.1.2  christos     }
   1081  1.1.1.2  christos   else
   1082  1.1.1.3  christos     {
   1083  1.1.1.4  christos       ARC_DEBUG ("	input section is NULL\n");
   1084  1.1.1.3  christos     }
   1085  1.1.1.2  christos }
   1086  1.1.1.4  christos #else
   1087  1.1.1.4  christos #define DEBUG_ARC_RELOC(A)
   1088  1.1.1.4  christos #endif /* ARC_ENABLE_DEBUG */
   1089  1.1.1.2  christos 
   1090  1.1.1.3  christos static bfd_vma
   1091  1.1.1.3  christos middle_endian_convert (bfd_vma insn, bfd_boolean do_it)
   1092  1.1.1.2  christos {
   1093  1.1.1.3  christos   if (do_it)
   1094  1.1.1.3  christos     {
   1095  1.1.1.4  christos       insn
   1096  1.1.1.4  christos 	= ((insn & 0xffff0000) >> 16)
   1097  1.1.1.4  christos 	  | ((insn & 0xffff) << 16);
   1098  1.1.1.3  christos     }
   1099  1.1.1.3  christos   return insn;
   1100  1.1.1.2  christos }
   1101  1.1.1.2  christos 
   1102  1.1.1.3  christos /* This function is called for relocations that are otherwise marked as NOT
   1103  1.1.1.3  christos    requiring overflow checks.  In here we perform non-standard checks of
   1104  1.1.1.3  christos    the relocation value.  */
   1105  1.1.1.3  christos 
   1106  1.1.1.3  christos static inline bfd_reloc_status_type
   1107  1.1.1.3  christos arc_special_overflow_checks (const struct arc_relocation_data reloc_data,
   1108  1.1.1.4  christos 			     bfd_signed_vma relocation,
   1109  1.1.1.3  christos 			     struct bfd_link_info *info ATTRIBUTE_UNUSED)
   1110  1.1.1.3  christos {
   1111  1.1.1.3  christos   switch (reloc_data.howto->type)
   1112  1.1.1.3  christos     {
   1113  1.1.1.3  christos     case R_ARC_NPS_CMEM16:
   1114  1.1.1.3  christos       if (((relocation >> 16) & 0xffff) != NPS_CMEM_HIGH_VALUE)
   1115  1.1.1.4  christos 	{
   1116  1.1.1.4  christos 	  if (reloc_data.reloc_addend == 0)
   1117  1.1.1.4  christos 	    _bfd_error_handler
   1118  1.1.1.4  christos 	      /* xgettext:c-format */
   1119  1.1.1.4  christos 	      (_("%B(%A+%#Lx): CMEM relocation to `%s' is invalid, "
   1120  1.1.1.4  christos 		 "16 MSB should be %#x (value is %#Lx)"),
   1121  1.1.1.4  christos 	       reloc_data.input_section->owner,
   1122  1.1.1.4  christos 	       reloc_data.input_section,
   1123  1.1.1.4  christos 	       reloc_data.reloc_offset,
   1124  1.1.1.4  christos 	       reloc_data.symbol_name,
   1125  1.1.1.4  christos 	       NPS_CMEM_HIGH_VALUE,
   1126  1.1.1.4  christos 	       relocation);
   1127  1.1.1.4  christos 	  else
   1128  1.1.1.4  christos 	    _bfd_error_handler
   1129  1.1.1.4  christos 	      /* xgettext:c-format */
   1130  1.1.1.4  christos 	      (_("%B(%A+%#Lx): CMEM relocation to `%s+%#Lx' is invalid, "
   1131  1.1.1.4  christos 		 "16 MSB should be %#x (value is %#Lx)"),
   1132  1.1.1.4  christos 	       reloc_data.input_section->owner,
   1133  1.1.1.4  christos 	       reloc_data.input_section,
   1134  1.1.1.4  christos 	       reloc_data.reloc_offset,
   1135  1.1.1.4  christos 	       reloc_data.symbol_name,
   1136  1.1.1.4  christos 	       reloc_data.reloc_addend,
   1137  1.1.1.4  christos 	       NPS_CMEM_HIGH_VALUE,
   1138  1.1.1.4  christos 	       relocation);
   1139  1.1.1.4  christos 	  return bfd_reloc_overflow;
   1140  1.1.1.4  christos 	}
   1141  1.1.1.3  christos       break;
   1142  1.1.1.3  christos 
   1143  1.1.1.3  christos     default:
   1144  1.1.1.3  christos       break;
   1145  1.1.1.3  christos     }
   1146  1.1.1.2  christos 
   1147  1.1.1.3  christos   return bfd_reloc_ok;
   1148  1.1.1.3  christos }
   1149  1.1.1.3  christos 
   1150  1.1.1.3  christos #define ME(reloc) (reloc)
   1151  1.1.1.3  christos 
   1152  1.1.1.3  christos #define IS_ME(FORMULA,BFD) ((strstr (FORMULA, "ME") != NULL) \
   1153  1.1.1.3  christos 			    && (!bfd_big_endian (BFD)))
   1154  1.1.1.3  christos 
   1155  1.1.1.3  christos #define S ((bfd_signed_vma) (reloc_data.sym_value			\
   1156  1.1.1.3  christos 	   + (reloc_data.sym_section->output_section != NULL ?		\
   1157  1.1.1.3  christos 	      (reloc_data.sym_section->output_offset			\
   1158  1.1.1.3  christos 	       + reloc_data.sym_section->output_section->vma) : 0)))
   1159  1.1.1.3  christos #define L ((bfd_signed_vma) (reloc_data.sym_value			\
   1160  1.1.1.3  christos 	   + (reloc_data.sym_section->output_section != NULL ?		\
   1161  1.1.1.3  christos 	      (reloc_data.sym_section->output_offset			\
   1162  1.1.1.3  christos 	      + reloc_data.sym_section->output_section->vma) : 0)))
   1163  1.1.1.2  christos #define A (reloc_data.reloc_addend)
   1164  1.1.1.2  christos #define B (0)
   1165  1.1.1.2  christos #define G (reloc_data.got_offset_value)
   1166  1.1.1.3  christos #define GOT (reloc_data.got_symbol_vma)
   1167  1.1.1.3  christos #define GOT_BEGIN (htab->sgot->output_section->vma)
   1168  1.1.1.3  christos 
   1169  1.1.1.2  christos #define MES (0)
   1170  1.1.1.3  christos 	/* P: relative offset to PCL The offset should be to the
   1171  1.1.1.3  christos 	  current location aligned to 32 bits.  */
   1172  1.1.1.3  christos #define P ((bfd_signed_vma) (						\
   1173  1.1.1.3  christos 	   (								\
   1174  1.1.1.3  christos 	    (reloc_data.input_section->output_section != NULL ?		\
   1175  1.1.1.3  christos 	     reloc_data.input_section->output_section->vma : 0)		\
   1176  1.1.1.3  christos 	    + reloc_data.input_section->output_offset			\
   1177  1.1.1.3  christos 	    + (reloc_data.reloc_offset - (bitsize >= 32 ? 4 : 0)))	\
   1178  1.1.1.3  christos 	   & ~0x3))
   1179  1.1.1.3  christos #define PDATA ((bfd_signed_vma) ( \
   1180  1.1.1.2  christos 	    (reloc_data.input_section->output_section->vma \
   1181  1.1.1.2  christos 	     + reloc_data.input_section->output_offset \
   1182  1.1.1.3  christos 	     + (reloc_data.reloc_offset))))
   1183  1.1.1.3  christos #define SECTSTART (bfd_signed_vma) (reloc_data.sym_section->output_section->vma \
   1184  1.1.1.3  christos 				    + reloc_data.sym_section->output_offset)
   1185  1.1.1.4  christos #define JLI (bfd_signed_vma) (reloc_data.sym_section->output_section->vma)
   1186  1.1.1.3  christos #define _SDA_BASE_ (bfd_signed_vma) (reloc_data.sdata_begin_symbol_vma)
   1187  1.1.1.3  christos #define TLS_REL (bfd_signed_vma) \
   1188  1.1.1.3  christos   ((elf_hash_table (info))->tls_sec->output_section->vma)
   1189  1.1.1.3  christos #define TLS_TBSS (8)
   1190  1.1.1.2  christos 
   1191  1.1.1.2  christos #define none (0)
   1192  1.1.1.2  christos 
   1193  1.1.1.4  christos #ifdef ARC_ENABLE_DEBUG
   1194  1.1.1.4  christos #define PRINT_DEBUG_RELOC_INFO_BEFORE(FORMULA, TYPE)			\
   1195  1.1.1.4  christos   do									\
   1196  1.1.1.4  christos     {									\
   1197  1.1.1.4  christos       asection *sym_section = reloc_data.sym_section;			\
   1198  1.1.1.4  christos       asection *input_section = reloc_data.input_section;		\
   1199  1.1.1.4  christos       ARC_DEBUG ("RELOC_TYPE = " TYPE "\n");				\
   1200  1.1.1.4  christos       ARC_DEBUG ("FORMULA = " FORMULA "\n");				\
   1201  1.1.1.4  christos       ARC_DEBUG ("S = %#lx\n", S);					\
   1202  1.1.1.4  christos       ARC_DEBUG ("A = %#lx\n", A);					\
   1203  1.1.1.4  christos       ARC_DEBUG ("L = %lx\n", L);					\
   1204  1.1.1.4  christos       if (sym_section->output_section != NULL)				\
   1205  1.1.1.4  christos 	ARC_DEBUG ("symbol_section->vma = %#lx\n",			\
   1206  1.1.1.4  christos 		   sym_section->output_section->vma			\
   1207  1.1.1.4  christos 		   + sym_section->output_offset);			\
   1208  1.1.1.4  christos       else								\
   1209  1.1.1.4  christos 	ARC_DEBUG ("symbol_section->vma = NULL\n");			\
   1210  1.1.1.4  christos       if (input_section->output_section != NULL)			\
   1211  1.1.1.4  christos 	ARC_DEBUG ("symbol_section->vma = %#lx\n",			\
   1212  1.1.1.4  christos 		   input_section->output_section->vma			\
   1213  1.1.1.4  christos 		   + input_section->output_offset);			\
   1214  1.1.1.4  christos       else								\
   1215  1.1.1.4  christos 	ARC_DEBUG ("symbol_section->vma = NULL\n");			\
   1216  1.1.1.4  christos       ARC_DEBUG ("PCL = %#lx\n", P);					\
   1217  1.1.1.4  christos       ARC_DEBUG ("P = %#lx\n", P);					\
   1218  1.1.1.4  christos       ARC_DEBUG ("G = %#lx\n", G);					\
   1219  1.1.1.4  christos       ARC_DEBUG ("SDA_OFFSET = %#lx\n", _SDA_BASE_);			\
   1220  1.1.1.3  christos       ARC_DEBUG ("SDA_SET = %d\n", reloc_data.sdata_begin_symbol_vma_set); \
   1221  1.1.1.4  christos       ARC_DEBUG ("GOT_OFFSET = %#lx\n", GOT);				\
   1222  1.1.1.4  christos       ARC_DEBUG ("relocation = %#08lx\n", relocation);			\
   1223  1.1.1.4  christos       ARC_DEBUG ("before = %#08x\n", (unsigned) insn);			\
   1224  1.1.1.4  christos       ARC_DEBUG ("data   = %08x (%u) (%d)\n", (unsigned) relocation,	\
   1225  1.1.1.4  christos 		 (unsigned) relocation, (int) relocation);		\
   1226  1.1.1.4  christos     }									\
   1227  1.1.1.4  christos   while (0)
   1228  1.1.1.4  christos 
   1229  1.1.1.4  christos #define PRINT_DEBUG_RELOC_INFO_AFTER				\
   1230  1.1.1.4  christos   do								\
   1231  1.1.1.4  christos     {								\
   1232  1.1.1.4  christos       ARC_DEBUG ("after  = 0x%08x\n", (unsigned int) insn);	\
   1233  1.1.1.4  christos     }								\
   1234  1.1.1.4  christos   while (0)
   1235  1.1.1.3  christos 
   1236  1.1.1.4  christos #else
   1237  1.1.1.4  christos 
   1238  1.1.1.4  christos #define PRINT_DEBUG_RELOC_INFO_BEFORE(...)
   1239  1.1.1.4  christos #define PRINT_DEBUG_RELOC_INFO_AFTER
   1240  1.1.1.4  christos 
   1241  1.1.1.4  christos #endif /* ARC_ENABLE_DEBUG */
   1242  1.1.1.3  christos 
   1243  1.1.1.2  christos #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
   1244  1.1.1.4  christos   case R_##TYPE:							\
   1245  1.1.1.4  christos     {									\
   1246  1.1.1.4  christos       bfd_signed_vma bitsize ATTRIBUTE_UNUSED = BITSIZE;		\
   1247  1.1.1.4  christos       relocation = FORMULA  ;						\
   1248  1.1.1.4  christos       PRINT_DEBUG_RELOC_INFO_BEFORE (#FORMULA, #TYPE);			\
   1249  1.1.1.4  christos       insn = middle_endian_convert (insn, IS_ME (#FORMULA, abfd));	\
   1250  1.1.1.4  christos       insn = (* get_replace_function (abfd, TYPE)) (insn, relocation);	\
   1251  1.1.1.4  christos       insn = middle_endian_convert (insn, IS_ME (#FORMULA, abfd));	\
   1252  1.1.1.4  christos       PRINT_DEBUG_RELOC_INFO_AFTER;					\
   1253  1.1.1.4  christos     }									\
   1254  1.1.1.2  christos     break;
   1255  1.1.1.2  christos 
   1256  1.1.1.2  christos static bfd_reloc_status_type
   1257  1.1.1.3  christos arc_do_relocation (bfd_byte * contents,
   1258  1.1.1.3  christos 		   struct arc_relocation_data reloc_data,
   1259  1.1.1.3  christos 		   struct bfd_link_info *info)
   1260  1.1.1.2  christos {
   1261  1.1.1.3  christos   bfd_signed_vma relocation = 0;
   1262  1.1.1.2  christos   bfd_vma insn;
   1263  1.1.1.2  christos   bfd_vma orig_insn ATTRIBUTE_UNUSED;
   1264  1.1.1.3  christos   bfd * abfd = reloc_data.input_section->owner;
   1265  1.1.1.3  christos   struct elf_link_hash_table *htab ATTRIBUTE_UNUSED = elf_hash_table (info);
   1266  1.1.1.3  christos   bfd_reloc_status_type flag;
   1267  1.1.1.2  christos 
   1268  1.1.1.4  christos   if (!reloc_data.should_relocate)
   1269  1.1.1.3  christos     return bfd_reloc_ok;
   1270  1.1.1.2  christos 
   1271  1.1.1.2  christos   switch (reloc_data.howto->size)
   1272  1.1.1.2  christos     {
   1273  1.1.1.2  christos       case 2:
   1274  1.1.1.3  christos 	insn = arc_bfd_get_32 (abfd,
   1275  1.1.1.2  christos 			       contents + reloc_data.reloc_offset,
   1276  1.1.1.2  christos 			       reloc_data.input_section);
   1277  1.1.1.2  christos 	break;
   1278  1.1.1.2  christos       case 1:
   1279  1.1.1.3  christos 	insn = arc_bfd_get_16 (abfd,
   1280  1.1.1.3  christos 			       contents + reloc_data.reloc_offset,
   1281  1.1.1.3  christos 			       reloc_data.input_section);
   1282  1.1.1.3  christos 	break;
   1283  1.1.1.2  christos       case 0:
   1284  1.1.1.3  christos 	insn = arc_bfd_get_8 (abfd,
   1285  1.1.1.2  christos 			       contents + reloc_data.reloc_offset,
   1286  1.1.1.2  christos 			       reloc_data.input_section);
   1287  1.1.1.2  christos 	break;
   1288  1.1.1.2  christos       default:
   1289  1.1.1.2  christos 	insn = 0;
   1290  1.1.1.2  christos 	BFD_ASSERT (0);
   1291  1.1.1.2  christos 	break;
   1292  1.1.1.2  christos     }
   1293  1.1.1.2  christos 
   1294  1.1.1.2  christos   orig_insn = insn;
   1295  1.1.1.2  christos 
   1296  1.1.1.2  christos   switch (reloc_data.howto->type)
   1297  1.1.1.2  christos     {
   1298  1.1.1.3  christos #include "elf/arc-reloc.def"
   1299  1.1.1.2  christos 
   1300  1.1.1.2  christos       default:
   1301  1.1.1.2  christos 	BFD_ASSERT (0);
   1302  1.1.1.2  christos 	break;
   1303  1.1.1.2  christos     }
   1304  1.1.1.2  christos 
   1305  1.1.1.2  christos   /* Check for relocation overflow.  */
   1306  1.1.1.2  christos   if (reloc_data.howto->complain_on_overflow != complain_overflow_dont)
   1307  1.1.1.3  christos     flag = bfd_check_overflow (reloc_data.howto->complain_on_overflow,
   1308  1.1.1.4  christos 			       reloc_data.howto->bitsize,
   1309  1.1.1.4  christos 			       reloc_data.howto->rightshift,
   1310  1.1.1.4  christos 			       bfd_arch_bits_per_address (abfd),
   1311  1.1.1.4  christos 			       relocation);
   1312  1.1.1.3  christos   else
   1313  1.1.1.3  christos     flag = arc_special_overflow_checks (reloc_data, relocation, info);
   1314  1.1.1.2  christos 
   1315  1.1.1.3  christos   if (flag != bfd_reloc_ok)
   1316  1.1.1.3  christos     {
   1317  1.1.1.4  christos       ARC_DEBUG ("Relocation overflows !\n");
   1318  1.1.1.3  christos       DEBUG_ARC_RELOC (reloc_data);
   1319  1.1.1.4  christos       ARC_DEBUG ("Relocation value = signed -> %d, unsigned -> %u"
   1320  1.1.1.4  christos 		 ", hex -> (0x%08x)\n",
   1321  1.1.1.4  christos 		(int) relocation, (unsigned) relocation, (int) relocation);
   1322  1.1.1.2  christos 
   1323  1.1.1.3  christos       return flag;
   1324  1.1.1.2  christos     }
   1325  1.1.1.2  christos 
   1326  1.1.1.3  christos   /* Write updated instruction back to memory.  */
   1327  1.1.1.2  christos   switch (reloc_data.howto->size)
   1328  1.1.1.2  christos     {
   1329  1.1.1.2  christos       case 2:
   1330  1.1.1.3  christos 	arc_bfd_put_32 (abfd, insn,
   1331  1.1.1.2  christos 		       contents + reloc_data.reloc_offset,
   1332  1.1.1.2  christos 		       reloc_data.input_section);
   1333  1.1.1.2  christos 	break;
   1334  1.1.1.2  christos       case 1:
   1335  1.1.1.3  christos 	arc_bfd_put_16 (abfd, insn,
   1336  1.1.1.3  christos 		       contents + reloc_data.reloc_offset,
   1337  1.1.1.3  christos 		       reloc_data.input_section);
   1338  1.1.1.3  christos 	break;
   1339  1.1.1.2  christos       case 0:
   1340  1.1.1.3  christos 	arc_bfd_put_8 (abfd, insn,
   1341  1.1.1.2  christos 		       contents + reloc_data.reloc_offset,
   1342  1.1.1.2  christos 		       reloc_data.input_section);
   1343  1.1.1.2  christos 	break;
   1344  1.1.1.2  christos       default:
   1345  1.1.1.2  christos 	ARC_DEBUG ("size = %d\n", reloc_data.howto->size);
   1346  1.1.1.2  christos 	BFD_ASSERT (0);
   1347  1.1.1.2  christos 	break;
   1348  1.1.1.2  christos     }
   1349  1.1.1.2  christos 
   1350  1.1.1.2  christos   return bfd_reloc_ok;
   1351  1.1.1.2  christos }
   1352  1.1.1.2  christos #undef S
   1353  1.1.1.2  christos #undef A
   1354  1.1.1.2  christos #undef B
   1355  1.1.1.2  christos #undef G
   1356  1.1.1.2  christos #undef GOT
   1357  1.1.1.2  christos #undef L
   1358  1.1.1.2  christos #undef MES
   1359  1.1.1.2  christos #undef P
   1360  1.1.1.2  christos #undef SECTSTAR
   1361  1.1.1.2  christos #undef SECTSTART
   1362  1.1.1.4  christos #undef JLI
   1363  1.1.1.2  christos #undef _SDA_BASE_
   1364  1.1.1.2  christos #undef none
   1365  1.1.1.2  christos 
   1366  1.1.1.2  christos #undef ARC_RELOC_HOWTO
   1367  1.1.1.2  christos 
   1368  1.1.1.2  christos 
   1369  1.1.1.2  christos /* Relocate an arc ELF section.
   1370  1.1.1.2  christos    Function : elf_arc_relocate_section
   1371  1.1.1.2  christos    Brief    : Relocate an arc section, by handling all the relocations
   1372  1.1.1.3  christos 	     appearing in that section.
   1373  1.1.1.2  christos    Args     : output_bfd    : The bfd being written to.
   1374  1.1.1.3  christos 	      info	    : Link information.
   1375  1.1.1.3  christos 	      input_bfd     : The input bfd.
   1376  1.1.1.3  christos 	      input_section : The section being relocated.
   1377  1.1.1.3  christos 	      contents	    : contents of the section being relocated.
   1378  1.1.1.3  christos 	      relocs	    : List of relocations in the section.
   1379  1.1.1.3  christos 	      local_syms    : is a pointer to the swapped in local symbols.
   1380  1.1.1.3  christos 	      local_section : is an array giving the section in the input file
   1381  1.1.1.3  christos 			      corresponding to the st_shndx field of each
   1382  1.1.1.3  christos 			      local symbol.  */
   1383  1.1.1.2  christos static bfd_boolean
   1384  1.1.1.4  christos elf_arc_relocate_section (bfd *			  output_bfd,
   1385  1.1.1.2  christos 			  struct bfd_link_info *  info,
   1386  1.1.1.4  christos 			  bfd *			  input_bfd,
   1387  1.1.1.4  christos 			  asection *		  input_section,
   1388  1.1.1.4  christos 			  bfd_byte *		  contents,
   1389  1.1.1.2  christos 			  Elf_Internal_Rela *     relocs,
   1390  1.1.1.2  christos 			  Elf_Internal_Sym *      local_syms,
   1391  1.1.1.4  christos 			  asection **		  local_sections)
   1392  1.1.1.2  christos {
   1393  1.1.1.4  christos   Elf_Internal_Shdr *		 symtab_hdr;
   1394  1.1.1.4  christos   struct elf_link_hash_entry **  sym_hashes;
   1395  1.1.1.4  christos   Elf_Internal_Rela *		 rel;
   1396  1.1.1.4  christos   Elf_Internal_Rela *		 wrel;
   1397  1.1.1.4  christos   Elf_Internal_Rela *		 relend;
   1398  1.1.1.4  christos   struct elf_link_hash_table *   htab = elf_hash_table (info);
   1399  1.1.1.2  christos 
   1400  1.1.1.2  christos   symtab_hdr = &((elf_tdata (input_bfd))->symtab_hdr);
   1401  1.1.1.2  christos   sym_hashes = elf_sym_hashes (input_bfd);
   1402  1.1.1.2  christos 
   1403  1.1.1.3  christos   rel = wrel = relocs;
   1404  1.1.1.2  christos   relend = relocs + input_section->reloc_count;
   1405  1.1.1.3  christos   for (; rel < relend; wrel++, rel++)
   1406  1.1.1.2  christos     {
   1407  1.1.1.4  christos       enum elf_arc_reloc_type	    r_type;
   1408  1.1.1.3  christos       reloc_howto_type *	    howto;
   1409  1.1.1.4  christos       unsigned long		    r_symndx;
   1410  1.1.1.2  christos       struct elf_link_hash_entry *  h;
   1411  1.1.1.3  christos       Elf_Internal_Sym *	    sym;
   1412  1.1.1.3  christos       asection *		    sec;
   1413  1.1.1.4  christos       struct elf_link_hash_entry *  h2;
   1414  1.1.1.4  christos       const char *		    msg;
   1415  1.1.1.4  christos       bfd_boolean		    unresolved_reloc = FALSE;
   1416  1.1.1.2  christos 
   1417  1.1.1.2  christos       struct arc_relocation_data reloc_data =
   1418  1.1.1.2  christos       {
   1419  1.1.1.3  christos 	.reloc_offset = 0,
   1420  1.1.1.3  christos 	.reloc_addend = 0,
   1421  1.1.1.3  christos 	.got_offset_value = 0,
   1422  1.1.1.4  christos 	.sym_value = 0,
   1423  1.1.1.3  christos 	.sym_section = NULL,
   1424  1.1.1.3  christos 	.howto = NULL,
   1425  1.1.1.3  christos 	.input_section = NULL,
   1426  1.1.1.3  christos 	.sdata_begin_symbol_vma = 0,
   1427  1.1.1.3  christos 	.sdata_begin_symbol_vma_set = FALSE,
   1428  1.1.1.3  christos 	.got_symbol_vma = 0,
   1429  1.1.1.3  christos 	.should_relocate = FALSE
   1430  1.1.1.2  christos       };
   1431  1.1.1.2  christos 
   1432  1.1.1.3  christos       r_type = ELF32_R_TYPE (rel->r_info);
   1433  1.1.1.3  christos 
   1434  1.1.1.3  christos       if (r_type >= (int) R_ARC_max)
   1435  1.1.1.3  christos 	{
   1436  1.1.1.3  christos 	  bfd_set_error (bfd_error_bad_value);
   1437  1.1.1.3  christos 	  return FALSE;
   1438  1.1.1.3  christos 	}
   1439  1.1.1.3  christos       howto = arc_elf_howto (r_type);
   1440  1.1.1.3  christos 
   1441  1.1.1.3  christos       r_symndx = ELF32_R_SYM (rel->r_info);
   1442  1.1.1.3  christos 
   1443  1.1.1.3  christos       /* If we are generating another .o file and the symbol in not
   1444  1.1.1.3  christos 	 local, skip this relocation.  */
   1445  1.1.1.3  christos       if (bfd_link_relocatable (info))
   1446  1.1.1.3  christos 	{
   1447  1.1.1.3  christos 	  /* This is a relocateable link.  We don't have to change
   1448  1.1.1.3  christos 	     anything, unless the reloc is against a section symbol,
   1449  1.1.1.3  christos 	     in which case we have to adjust according to where the
   1450  1.1.1.3  christos 	     section symbol winds up in the output section.  */
   1451  1.1.1.3  christos 
   1452  1.1.1.3  christos 	  /* Checks if this is a local symbol and thus the reloc
   1453  1.1.1.3  christos 	     might (will??) be against a section symbol.  */
   1454  1.1.1.3  christos 	  if (r_symndx < symtab_hdr->sh_info)
   1455  1.1.1.3  christos 	    {
   1456  1.1.1.3  christos 	      sym = local_syms + r_symndx;
   1457  1.1.1.3  christos 	      if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
   1458  1.1.1.3  christos 		{
   1459  1.1.1.3  christos 		  sec = local_sections[r_symndx];
   1460  1.1.1.3  christos 
   1461  1.1.1.4  christos 		  /* For RELA relocs.  Just adjust the addend
   1462  1.1.1.3  christos 		     value in the relocation entry.  */
   1463  1.1.1.3  christos 		  rel->r_addend += sec->output_offset + sym->st_value;
   1464  1.1.1.3  christos 
   1465  1.1.1.4  christos 		  ARC_DEBUG ("local symbols reloc (section=%d %s) seen in %s\n",
   1466  1.1.1.4  christos 			     (int) r_symndx, local_sections[r_symndx]->name,
   1467  1.1.1.4  christos 			     __PRETTY_FUNCTION__);
   1468  1.1.1.3  christos 		}
   1469  1.1.1.3  christos 	    }
   1470  1.1.1.3  christos 	}
   1471  1.1.1.2  christos 
   1472  1.1.1.2  christos       h2 = elf_link_hash_lookup (elf_hash_table (info), "__SDATA_BEGIN__",
   1473  1.1.1.2  christos 				 FALSE, FALSE, TRUE);
   1474  1.1.1.2  christos 
   1475  1.1.1.4  christos       if (!reloc_data.sdata_begin_symbol_vma_set
   1476  1.1.1.4  christos 	  && h2 != NULL && h2->root.type != bfd_link_hash_undefined
   1477  1.1.1.4  christos 	  && h2->root.u.def.section->output_section != NULL)
   1478  1.1.1.3  christos 	/* TODO: Verify this condition.  */
   1479  1.1.1.2  christos 	{
   1480  1.1.1.2  christos 	  reloc_data.sdata_begin_symbol_vma =
   1481  1.1.1.4  christos 	    (h2->root.u.def.value
   1482  1.1.1.4  christos 	     + h2->root.u.def.section->output_section->vma);
   1483  1.1.1.2  christos 	  reloc_data.sdata_begin_symbol_vma_set = TRUE;
   1484  1.1.1.2  christos 	}
   1485  1.1.1.2  christos 
   1486  1.1.1.2  christos       reloc_data.input_section = input_section;
   1487  1.1.1.2  christos       reloc_data.howto = howto;
   1488  1.1.1.2  christos       reloc_data.reloc_offset = rel->r_offset;
   1489  1.1.1.2  christos       reloc_data.reloc_addend = rel->r_addend;
   1490  1.1.1.2  christos 
   1491  1.1.1.2  christos       /* This is a final link.  */
   1492  1.1.1.2  christos       h = NULL;
   1493  1.1.1.2  christos       sym = NULL;
   1494  1.1.1.2  christos       sec = NULL;
   1495  1.1.1.2  christos 
   1496  1.1.1.2  christos       if (r_symndx < symtab_hdr->sh_info) /* A local symbol.  */
   1497  1.1.1.2  christos 	{
   1498  1.1.1.2  christos 	  sym = local_syms + r_symndx;
   1499  1.1.1.2  christos 	  sec = local_sections[r_symndx];
   1500  1.1.1.2  christos 	}
   1501  1.1.1.3  christos       else
   1502  1.1.1.2  christos 	{
   1503  1.1.1.4  christos 	  bfd_boolean warned, ignored;
   1504  1.1.1.4  christos 	  bfd_vma relocation ATTRIBUTE_UNUSED;
   1505  1.1.1.4  christos 
   1506  1.1.1.4  christos 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
   1507  1.1.1.4  christos 				   r_symndx, symtab_hdr, sym_hashes,
   1508  1.1.1.4  christos 				   h, sec, relocation,
   1509  1.1.1.4  christos 				   unresolved_reloc, warned, ignored);
   1510  1.1.1.4  christos 
   1511  1.1.1.3  christos 	  /* TODO: This code is repeated from below.  We should
   1512  1.1.1.3  christos 	     clean it and remove duplications.
   1513  1.1.1.3  christos 	     Sec is used check for discarded sections.
   1514  1.1.1.3  christos 	     Need to redesign code below.  */
   1515  1.1.1.3  christos 
   1516  1.1.1.2  christos 	  /* Get the symbol's entry in the symtab.  */
   1517  1.1.1.2  christos 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   1518  1.1.1.2  christos 
   1519  1.1.1.2  christos 	  while (h->root.type == bfd_link_hash_indirect
   1520  1.1.1.2  christos 		 || h->root.type == bfd_link_hash_warning)
   1521  1.1.1.2  christos 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   1522  1.1.1.2  christos 
   1523  1.1.1.2  christos 	  /* If we have encountered a definition for this symbol.  */
   1524  1.1.1.2  christos 	  if (h->root.type == bfd_link_hash_defined
   1525  1.1.1.2  christos 	      || h->root.type == bfd_link_hash_defweak)
   1526  1.1.1.2  christos 	    {
   1527  1.1.1.2  christos 	      reloc_data.sym_value = h->root.u.def.value;
   1528  1.1.1.3  christos 	      sec = h->root.u.def.section;
   1529  1.1.1.3  christos 	    }
   1530  1.1.1.3  christos 	}
   1531  1.1.1.2  christos 
   1532  1.1.1.3  christos       /* Clean relocs for symbols in discarded sections.  */
   1533  1.1.1.3  christos       if (sec != NULL && discarded_section (sec))
   1534  1.1.1.3  christos 	{
   1535  1.1.1.3  christos 	  _bfd_clear_contents (howto, input_bfd, input_section,
   1536  1.1.1.3  christos 			       contents + rel->r_offset);
   1537  1.1.1.3  christos 	  rel->r_offset = rel->r_offset;
   1538  1.1.1.3  christos 	  rel->r_info = 0;
   1539  1.1.1.3  christos 	  rel->r_addend = 0;
   1540  1.1.1.3  christos 
   1541  1.1.1.3  christos 	  /* For ld -r, remove relocations in debug sections against
   1542  1.1.1.3  christos 	     sections defined in discarded sections.  Not done for
   1543  1.1.1.3  christos 	     eh_frame editing code expects to be present.  */
   1544  1.1.1.3  christos 	   if (bfd_link_relocatable (info)
   1545  1.1.1.3  christos 	       && (input_section->flags & SEC_DEBUGGING))
   1546  1.1.1.3  christos 	     wrel--;
   1547  1.1.1.2  christos 
   1548  1.1.1.3  christos 	  continue;
   1549  1.1.1.3  christos 	}
   1550  1.1.1.2  christos 
   1551  1.1.1.3  christos       if (bfd_link_relocatable (info))
   1552  1.1.1.3  christos 	{
   1553  1.1.1.3  christos 	  if (wrel != rel)
   1554  1.1.1.3  christos 	    *wrel = *rel;
   1555  1.1.1.3  christos 	  continue;
   1556  1.1.1.3  christos 	}
   1557  1.1.1.2  christos 
   1558  1.1.1.3  christos       if (r_symndx < symtab_hdr->sh_info) /* A local symbol.  */
   1559  1.1.1.3  christos 	{
   1560  1.1.1.3  christos 	  reloc_data.sym_value = sym->st_value;
   1561  1.1.1.3  christos 	  reloc_data.sym_section = sec;
   1562  1.1.1.3  christos 	  reloc_data.symbol_name =
   1563  1.1.1.3  christos 	    bfd_elf_string_from_elf_section (input_bfd,
   1564  1.1.1.3  christos 					     symtab_hdr->sh_link,
   1565  1.1.1.3  christos 					     sym->st_name);
   1566  1.1.1.3  christos 
   1567  1.1.1.3  christos 	  /* Mergeable section handling.  */
   1568  1.1.1.3  christos 	  if ((sec->flags & SEC_MERGE)
   1569  1.1.1.3  christos 	      && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
   1570  1.1.1.3  christos 	    {
   1571  1.1.1.3  christos 	      asection *msec;
   1572  1.1.1.3  christos 	      msec = sec;
   1573  1.1.1.3  christos 	      rel->r_addend = _bfd_elf_rel_local_sym (output_bfd, sym,
   1574  1.1.1.3  christos 						      &msec, rel->r_addend);
   1575  1.1.1.3  christos 	      rel->r_addend -= (sec->output_section->vma
   1576  1.1.1.3  christos 				+ sec->output_offset
   1577  1.1.1.3  christos 				+ sym->st_value);
   1578  1.1.1.3  christos 	      rel->r_addend += msec->output_section->vma + msec->output_offset;
   1579  1.1.1.3  christos 
   1580  1.1.1.3  christos 	      reloc_data.reloc_addend = rel->r_addend;
   1581  1.1.1.3  christos 	    }
   1582  1.1.1.3  christos 
   1583  1.1.1.3  christos 	  BFD_ASSERT (htab->sgot != NULL || !is_reloc_for_GOT (howto));
   1584  1.1.1.3  christos 	  if (htab->sgot != NULL)
   1585  1.1.1.3  christos 	    reloc_data.got_symbol_vma = htab->sgot->output_section->vma
   1586  1.1.1.3  christos 					+ htab->sgot->output_offset;
   1587  1.1.1.3  christos 
   1588  1.1.1.3  christos 	  reloc_data.should_relocate = TRUE;
   1589  1.1.1.3  christos 	}
   1590  1.1.1.3  christos       else /* Global symbol.  */
   1591  1.1.1.3  christos 	{
   1592  1.1.1.4  christos 	  /* FIXME: We should use the RELOC_FOR_GLOBAL_SYMBOL macro
   1593  1.1.1.4  christos 	     (defined in elf-bfd.h) here.  */
   1594  1.1.1.4  christos 
   1595  1.1.1.3  christos 	  /* Get the symbol's entry in the symtab.  */
   1596  1.1.1.3  christos 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   1597  1.1.1.3  christos 
   1598  1.1.1.3  christos 	  while (h->root.type == bfd_link_hash_indirect
   1599  1.1.1.3  christos 		 || h->root.type == bfd_link_hash_warning)
   1600  1.1.1.4  christos 	  {
   1601  1.1.1.4  christos 	    struct elf_link_hash_entry *h_old = h;
   1602  1.1.1.3  christos 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   1603  1.1.1.4  christos 	    if (h->got.glist == 0 && h_old->got.glist != h->got.glist)
   1604  1.1.1.4  christos 	      h->got.glist = h_old->got.glist;
   1605  1.1.1.4  christos 	  }
   1606  1.1.1.3  christos 
   1607  1.1.1.3  christos 	  /* TODO: Need to validate what was the intention.  */
   1608  1.1.1.3  christos 	  /* BFD_ASSERT ((h->dynindx == -1) || (h->forced_local != 0)); */
   1609  1.1.1.3  christos 	  reloc_data.symbol_name = h->root.root.string;
   1610  1.1.1.3  christos 
   1611  1.1.1.3  christos 	  /* If we have encountered a definition for this symbol.  */
   1612  1.1.1.3  christos 	  if (h->root.type == bfd_link_hash_defined
   1613  1.1.1.3  christos 	      || h->root.type == bfd_link_hash_defweak)
   1614  1.1.1.3  christos 	    {
   1615  1.1.1.3  christos 	      reloc_data.sym_value = h->root.u.def.value;
   1616  1.1.1.3  christos 	      reloc_data.sym_section = h->root.u.def.section;
   1617  1.1.1.3  christos 
   1618  1.1.1.3  christos 	      reloc_data.should_relocate = TRUE;
   1619  1.1.1.3  christos 
   1620  1.1.1.3  christos 	      if (is_reloc_for_GOT (howto) && !bfd_link_pic (info))
   1621  1.1.1.3  christos 		{
   1622  1.1.1.3  christos 		  /* TODO: Change it to use arc_do_relocation with
   1623  1.1.1.3  christos 		    ARC_32 reloc.  Try to use ADD_RELA macro.  */
   1624  1.1.1.3  christos 		  bfd_vma relocation =
   1625  1.1.1.3  christos 		    reloc_data.sym_value + reloc_data.reloc_addend
   1626  1.1.1.3  christos 		    + (reloc_data.sym_section->output_section != NULL ?
   1627  1.1.1.3  christos 			(reloc_data.sym_section->output_offset
   1628  1.1.1.3  christos 			 + reloc_data.sym_section->output_section->vma)
   1629  1.1.1.3  christos 		      : 0);
   1630  1.1.1.3  christos 
   1631  1.1.1.3  christos 		  BFD_ASSERT (h->got.glist);
   1632  1.1.1.3  christos 		  bfd_vma got_offset = h->got.glist->offset;
   1633  1.1.1.3  christos 		  bfd_put_32 (output_bfd, relocation,
   1634  1.1.1.3  christos 			      htab->sgot->contents + got_offset);
   1635  1.1.1.3  christos 		}
   1636  1.1.1.3  christos 	      if (is_reloc_for_PLT (howto) && h->plt.offset != (bfd_vma) -1)
   1637  1.1.1.3  christos 		{
   1638  1.1.1.3  christos 		  /* TODO: This is repeated up here.  */
   1639  1.1.1.3  christos 		  reloc_data.sym_value = h->plt.offset;
   1640  1.1.1.3  christos 		  reloc_data.sym_section = htab->splt;
   1641  1.1.1.3  christos 		}
   1642  1.1.1.3  christos 	    }
   1643  1.1.1.2  christos 	  else if (h->root.type == bfd_link_hash_undefweak)
   1644  1.1.1.2  christos 	    {
   1645  1.1.1.2  christos 	      /* Is weak symbol and has no definition.  */
   1646  1.1.1.3  christos 	      if (is_reloc_for_GOT (howto))
   1647  1.1.1.3  christos 		{
   1648  1.1.1.3  christos 		  reloc_data.sym_value = h->root.u.def.value;
   1649  1.1.1.3  christos 		  reloc_data.sym_section = htab->sgot;
   1650  1.1.1.3  christos 		  reloc_data.should_relocate = TRUE;
   1651  1.1.1.3  christos 		}
   1652  1.1.1.3  christos 	      else if (is_reloc_for_PLT (howto)
   1653  1.1.1.3  christos 		       && h->plt.offset != (bfd_vma) -1)
   1654  1.1.1.3  christos 		{
   1655  1.1.1.3  christos 		  /* TODO: This is repeated up here.  */
   1656  1.1.1.3  christos 		  reloc_data.sym_value = h->plt.offset;
   1657  1.1.1.3  christos 		  reloc_data.sym_section = htab->splt;
   1658  1.1.1.3  christos 		  reloc_data.should_relocate = TRUE;
   1659  1.1.1.3  christos 		}
   1660  1.1.1.3  christos 	      else
   1661  1.1.1.3  christos 		continue;
   1662  1.1.1.2  christos 	    }
   1663  1.1.1.2  christos 	  else
   1664  1.1.1.2  christos 	    {
   1665  1.1.1.2  christos 	      if (is_reloc_for_GOT (howto))
   1666  1.1.1.2  christos 		{
   1667  1.1.1.2  christos 		  reloc_data.sym_value = h->root.u.def.value;
   1668  1.1.1.3  christos 		  reloc_data.sym_section = htab->sgot;
   1669  1.1.1.2  christos 
   1670  1.1.1.2  christos 		  reloc_data.should_relocate = TRUE;
   1671  1.1.1.2  christos 		}
   1672  1.1.1.2  christos 	      else if (is_reloc_for_PLT (howto))
   1673  1.1.1.2  christos 		{
   1674  1.1.1.3  christos 		  /* Fail if it is linking for PIE and the symbol is
   1675  1.1.1.3  christos 		     undefined.  */
   1676  1.1.1.3  christos 		  if (bfd_link_executable (info))
   1677  1.1.1.3  christos 		    (*info->callbacks->undefined_symbol)
   1678  1.1.1.3  christos 		      (info, h->root.root.string, input_bfd, input_section,
   1679  1.1.1.3  christos 		       rel->r_offset, TRUE);
   1680  1.1.1.2  christos 		  reloc_data.sym_value = h->plt.offset;
   1681  1.1.1.3  christos 		  reloc_data.sym_section = htab->splt;
   1682  1.1.1.2  christos 
   1683  1.1.1.2  christos 		  reloc_data.should_relocate = TRUE;
   1684  1.1.1.2  christos 		}
   1685  1.1.1.4  christos 	      else if (!bfd_link_pic (info) || bfd_link_executable (info))
   1686  1.1.1.3  christos 		(*info->callbacks->undefined_symbol)
   1687  1.1.1.3  christos 		  (info, h->root.root.string, input_bfd, input_section,
   1688  1.1.1.3  christos 		   rel->r_offset, TRUE);
   1689  1.1.1.3  christos 	    }
   1690  1.1.1.3  christos 
   1691  1.1.1.4  christos 	  BFD_ASSERT (htab->sgot != NULL || !is_reloc_for_GOT (howto));
   1692  1.1.1.4  christos 	  if (htab->sgot != NULL)
   1693  1.1.1.4  christos 	    reloc_data.got_symbol_vma = htab->sgot->output_section->vma
   1694  1.1.1.4  christos 					+ htab->sgot->output_offset;
   1695  1.1.1.4  christos 	}
   1696  1.1.1.3  christos 
   1697  1.1.1.4  christos       if ((is_reloc_for_GOT (howto)
   1698  1.1.1.4  christos 	   || is_reloc_for_TLS (howto)))
   1699  1.1.1.4  christos 	{
   1700  1.1.1.4  christos 	  reloc_data.should_relocate = TRUE;
   1701  1.1.1.3  christos 
   1702  1.1.1.4  christos 	  struct got_entry **list
   1703  1.1.1.4  christos 	    = get_got_entry_list_for_symbol (output_bfd, r_symndx, h);
   1704  1.1.1.3  christos 
   1705  1.1.1.4  christos 	  reloc_data.got_offset_value
   1706  1.1.1.4  christos 	    = relocate_fix_got_relocs_for_got_info (list,
   1707  1.1.1.4  christos 						    tls_type_for_reloc (howto),
   1708  1.1.1.4  christos 						    info,
   1709  1.1.1.4  christos 						    output_bfd,
   1710  1.1.1.4  christos 						    r_symndx,
   1711  1.1.1.4  christos 						    local_syms,
   1712  1.1.1.4  christos 						    local_sections,
   1713  1.1.1.4  christos 						    h,
   1714  1.1.1.4  christos 						    &reloc_data);
   1715  1.1.1.3  christos 
   1716  1.1.1.4  christos 	  if (h == NULL)
   1717  1.1.1.4  christos 	    {
   1718  1.1.1.4  christos 	      create_got_dynrelocs_for_single_entry (
   1719  1.1.1.4  christos 		  got_entry_for_type (list,
   1720  1.1.1.4  christos 				arc_got_entry_type_for_reloc (howto)),
   1721  1.1.1.4  christos 		  output_bfd, info, NULL);
   1722  1.1.1.2  christos 	    }
   1723  1.1.1.3  christos 	}
   1724  1.1.1.3  christos 
   1725  1.1.1.4  christos 
   1726  1.1.1.4  christos #define IS_ARC_PCREL_TYPE(TYPE) \
   1727  1.1.1.4  christos   (   (TYPE == R_ARC_PC32)      \
   1728  1.1.1.4  christos    || (TYPE == R_ARC_32_PCREL))
   1729  1.1.1.4  christos 
   1730  1.1.1.3  christos       switch (r_type)
   1731  1.1.1.3  christos 	{
   1732  1.1.1.3  christos 	  case R_ARC_32:
   1733  1.1.1.3  christos 	  case R_ARC_32_ME:
   1734  1.1.1.3  christos 	  case R_ARC_PC32:
   1735  1.1.1.3  christos 	  case R_ARC_32_PCREL:
   1736  1.1.1.4  christos 	    if (bfd_link_pic (info)
   1737  1.1.1.4  christos 		&& (!IS_ARC_PCREL_TYPE (r_type)
   1738  1.1.1.3  christos 		    || (h != NULL
   1739  1.1.1.3  christos 			&& h->dynindx != -1
   1740  1.1.1.4  christos 			&& !h->def_regular
   1741  1.1.1.3  christos 			&& (!info->symbolic || !h->def_regular))))
   1742  1.1.1.3  christos 	      {
   1743  1.1.1.3  christos 		Elf_Internal_Rela outrel;
   1744  1.1.1.3  christos 		bfd_byte *loc;
   1745  1.1.1.3  christos 		bfd_boolean skip = FALSE;
   1746  1.1.1.3  christos 		bfd_boolean relocate = FALSE;
   1747  1.1.1.3  christos 		asection *sreloc = _bfd_elf_get_dynamic_reloc_section
   1748  1.1.1.3  christos 				 (input_bfd, input_section,
   1749  1.1.1.3  christos 				  /*RELA*/ TRUE);
   1750  1.1.1.3  christos 
   1751  1.1.1.3  christos 		BFD_ASSERT (sreloc != NULL);
   1752  1.1.1.3  christos 
   1753  1.1.1.3  christos 		outrel.r_offset = _bfd_elf_section_offset (output_bfd,
   1754  1.1.1.3  christos 							   info,
   1755  1.1.1.3  christos 							   input_section,
   1756  1.1.1.3  christos 							   rel->r_offset);
   1757  1.1.1.4  christos 
   1758  1.1.1.3  christos 		if (outrel.r_offset == (bfd_vma) -1)
   1759  1.1.1.3  christos 		  skip = TRUE;
   1760  1.1.1.3  christos 
   1761  1.1.1.3  christos 		outrel.r_addend = rel->r_addend;
   1762  1.1.1.3  christos 		outrel.r_offset += (input_section->output_section->vma
   1763  1.1.1.3  christos 				    + input_section->output_offset);
   1764  1.1.1.3  christos 
   1765  1.1.1.3  christos 		if (skip)
   1766  1.1.1.3  christos 		  {
   1767  1.1.1.3  christos 		    memset (&outrel, 0, sizeof outrel);
   1768  1.1.1.3  christos 		    relocate = FALSE;
   1769  1.1.1.3  christos 		  }
   1770  1.1.1.3  christos 		else if (h != NULL
   1771  1.1.1.3  christos 			 && h->dynindx != -1
   1772  1.1.1.4  christos 			 && (IS_ARC_PCREL_TYPE (r_type)
   1773  1.1.1.4  christos 			     || !(bfd_link_executable (info)
   1774  1.1.1.4  christos 				  || SYMBOLIC_BIND (info, h))
   1775  1.1.1.4  christos 			     || ! h->def_regular))
   1776  1.1.1.3  christos 		  {
   1777  1.1.1.3  christos 		    BFD_ASSERT (h != NULL);
   1778  1.1.1.3  christos 		    if ((input_section->flags & SEC_ALLOC) != 0)
   1779  1.1.1.3  christos 		      relocate = FALSE;
   1780  1.1.1.3  christos 		    else
   1781  1.1.1.3  christos 		      relocate = TRUE;
   1782  1.1.1.3  christos 
   1783  1.1.1.3  christos 		    BFD_ASSERT (h->dynindx != -1);
   1784  1.1.1.3  christos 		    outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
   1785  1.1.1.3  christos 		  }
   1786  1.1.1.3  christos 		else
   1787  1.1.1.3  christos 		  {
   1788  1.1.1.3  christos 		    /* Handle local symbols, they either do not have a
   1789  1.1.1.3  christos 		       global hash table entry (h == NULL), or are
   1790  1.1.1.3  christos 		       forced local due to a version script
   1791  1.1.1.3  christos 		       (h->forced_local), or the third condition is
   1792  1.1.1.3  christos 		       legacy, it appears to say something like, for
   1793  1.1.1.3  christos 		       links where we are pre-binding the symbols, or
   1794  1.1.1.3  christos 		       there's not an entry for this symbol in the
   1795  1.1.1.3  christos 		       dynamic symbol table, and it's a regular symbol
   1796  1.1.1.3  christos 		       not defined in a shared object, then treat the
   1797  1.1.1.3  christos 		       symbol as local, resolve it now.  */
   1798  1.1.1.3  christos 		    relocate = TRUE;
   1799  1.1.1.3  christos 		    /* outrel.r_addend = 0; */
   1800  1.1.1.3  christos 		    outrel.r_info = ELF32_R_INFO (0, R_ARC_RELATIVE);
   1801  1.1.1.3  christos 		  }
   1802  1.1.1.3  christos 
   1803  1.1.1.3  christos 		BFD_ASSERT (sreloc->contents != 0);
   1804  1.1.1.3  christos 
   1805  1.1.1.3  christos 		loc = sreloc->contents;
   1806  1.1.1.3  christos 		loc += sreloc->reloc_count * sizeof (Elf32_External_Rela);
   1807  1.1.1.3  christos 		sreloc->reloc_count += 1;
   1808  1.1.1.3  christos 
   1809  1.1.1.3  christos 		bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   1810  1.1.1.3  christos 
   1811  1.1.1.4  christos 		if (!relocate)
   1812  1.1.1.3  christos 		  continue;
   1813  1.1.1.3  christos 	      }
   1814  1.1.1.3  christos 	    break;
   1815  1.1.1.3  christos 	  default:
   1816  1.1.1.3  christos 	    break;
   1817  1.1.1.2  christos 	}
   1818  1.1.1.2  christos 
   1819  1.1.1.3  christos       if (is_reloc_SDA_relative (howto)
   1820  1.1.1.4  christos 	  && !reloc_data.sdata_begin_symbol_vma_set)
   1821  1.1.1.2  christos 	{
   1822  1.1.1.4  christos 	  _bfd_error_handler
   1823  1.1.1.4  christos 	    ("Error: Linker symbol __SDATA_BEGIN__ not found");
   1824  1.1.1.2  christos 	  bfd_set_error (bfd_error_bad_value);
   1825  1.1.1.2  christos 	  return FALSE;
   1826  1.1.1.2  christos 	}
   1827  1.1.1.2  christos 
   1828  1.1.1.2  christos       DEBUG_ARC_RELOC (reloc_data);
   1829  1.1.1.3  christos 
   1830  1.1.1.3  christos       /* Make sure we have with a dynamic linker.  In case of GOT and PLT
   1831  1.1.1.4  christos 	 the sym_section should point to .got or .plt respectively.  */
   1832  1.1.1.3  christos       if ((is_reloc_for_GOT (howto) || is_reloc_for_PLT (howto))
   1833  1.1.1.3  christos 	  && reloc_data.sym_section == NULL)
   1834  1.1.1.3  christos 	{
   1835  1.1.1.4  christos 	  _bfd_error_handler
   1836  1.1.1.3  christos 	    (_("GOT and PLT relocations cannot be fixed with a non dynamic linker."));
   1837  1.1.1.3  christos 	  bfd_set_error (bfd_error_bad_value);
   1838  1.1.1.3  christos 	  return FALSE;
   1839  1.1.1.3  christos 	}
   1840  1.1.1.3  christos 
   1841  1.1.1.4  christos       msg = NULL;
   1842  1.1.1.4  christos       switch (arc_do_relocation (contents, reloc_data, info))
   1843  1.1.1.4  christos 	{
   1844  1.1.1.4  christos 	case bfd_reloc_ok:
   1845  1.1.1.4  christos 	  continue; /* The reloc processing loop.  */
   1846  1.1.1.2  christos 
   1847  1.1.1.4  christos 	case bfd_reloc_overflow:
   1848  1.1.1.4  christos 	  (*info->callbacks->reloc_overflow)
   1849  1.1.1.4  christos 	    (info, (h ? &h->root : NULL), reloc_data.symbol_name, howto->name, (bfd_vma) 0,
   1850  1.1.1.4  christos 	     input_bfd, input_section, rel->r_offset);
   1851  1.1.1.4  christos 	  break;
   1852  1.1.1.4  christos 
   1853  1.1.1.4  christos 	case bfd_reloc_undefined:
   1854  1.1.1.4  christos 	  (*info->callbacks->undefined_symbol)
   1855  1.1.1.4  christos 	    (info, reloc_data.symbol_name, input_bfd, input_section, rel->r_offset, TRUE);
   1856  1.1.1.4  christos 	  break;
   1857  1.1.1.4  christos 
   1858  1.1.1.4  christos 	case bfd_reloc_other:
   1859  1.1.1.4  christos 	  /* xgettext:c-format */
   1860  1.1.1.4  christos 	  msg = _("%B(%A): warning: unaligned access to symbol '%s' in the small data area");
   1861  1.1.1.4  christos 	  break;
   1862  1.1.1.4  christos 
   1863  1.1.1.4  christos 	case bfd_reloc_outofrange:
   1864  1.1.1.4  christos 	  /* xgettext:c-format */
   1865  1.1.1.4  christos 	  msg = _("%B(%A): internal error: out of range error");
   1866  1.1.1.4  christos 	  break;
   1867  1.1.1.4  christos 
   1868  1.1.1.4  christos 	case bfd_reloc_notsupported:
   1869  1.1.1.4  christos 	  /* xgettext:c-format */
   1870  1.1.1.4  christos 	  msg = _("%B(%A): internal error: unsupported relocation error");
   1871  1.1.1.4  christos 	  break;
   1872  1.1.1.4  christos 
   1873  1.1.1.4  christos 	case bfd_reloc_dangerous:
   1874  1.1.1.4  christos 	  /* xgettext:c-format */
   1875  1.1.1.4  christos 	  msg = _("%B(%A): internal error: dangerous relocation");
   1876  1.1.1.4  christos 	  break;
   1877  1.1.1.4  christos 
   1878  1.1.1.4  christos 	default:
   1879  1.1.1.4  christos 	  /* xgettext:c-format */
   1880  1.1.1.4  christos 	  msg = _("%B(%A): internal error: unknown error");
   1881  1.1.1.4  christos 	  break;
   1882  1.1.1.4  christos 	}
   1883  1.1.1.3  christos 
   1884  1.1.1.4  christos       if (msg)
   1885  1.1.1.4  christos 	_bfd_error_handler (msg, input_bfd, input_section, reloc_data.symbol_name);
   1886  1.1.1.4  christos       return FALSE;
   1887  1.1.1.3  christos     }
   1888  1.1.1.2  christos 
   1889  1.1.1.4  christos   return TRUE;
   1890  1.1.1.2  christos }
   1891  1.1.1.2  christos 
   1892  1.1.1.4  christos #define elf_arc_hash_table(p) \
   1893  1.1.1.4  christos     (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
   1894  1.1.1.4  christos   == ARC_ELF_DATA ? ((struct elf_arc_link_hash_table *) ((p)->hash)) : NULL)
   1895  1.1.1.2  christos 
   1896  1.1.1.2  christos static bfd_boolean
   1897  1.1.1.4  christos elf_arc_check_relocs (bfd *			 abfd,
   1898  1.1.1.2  christos 		      struct bfd_link_info *     info,
   1899  1.1.1.3  christos 		      asection *		 sec,
   1900  1.1.1.2  christos 		      const Elf_Internal_Rela *  relocs)
   1901  1.1.1.2  christos {
   1902  1.1.1.3  christos   Elf_Internal_Shdr *		symtab_hdr;
   1903  1.1.1.3  christos   struct elf_link_hash_entry **	sym_hashes;
   1904  1.1.1.3  christos   const Elf_Internal_Rela *	rel;
   1905  1.1.1.3  christos   const Elf_Internal_Rela *	rel_end;
   1906  1.1.1.3  christos   bfd *				dynobj;
   1907  1.1.1.3  christos   asection *			sreloc = NULL;
   1908  1.1.1.4  christos   struct elf_link_hash_table *	htab = elf_hash_table (info);
   1909  1.1.1.3  christos 
   1910  1.1.1.3  christos   if (bfd_link_relocatable (info))
   1911  1.1.1.3  christos     return TRUE;
   1912  1.1.1.2  christos 
   1913  1.1.1.4  christos   if (htab->dynobj == NULL)
   1914  1.1.1.4  christos     htab->dynobj = abfd;
   1915  1.1.1.4  christos 
   1916  1.1.1.2  christos   dynobj = (elf_hash_table (info))->dynobj;
   1917  1.1.1.2  christos   symtab_hdr = &((elf_tdata (abfd))->symtab_hdr);
   1918  1.1.1.2  christos   sym_hashes = elf_sym_hashes (abfd);
   1919  1.1.1.2  christos 
   1920  1.1.1.2  christos   rel_end = relocs + sec->reloc_count;
   1921  1.1.1.2  christos   for (rel = relocs; rel < rel_end; rel++)
   1922  1.1.1.2  christos     {
   1923  1.1.1.2  christos       enum elf_arc_reloc_type r_type;
   1924  1.1.1.2  christos       reloc_howto_type *howto;
   1925  1.1.1.2  christos       unsigned long   r_symndx;
   1926  1.1.1.2  christos       struct elf_link_hash_entry *h;
   1927  1.1.1.2  christos 
   1928  1.1.1.2  christos       r_type = ELF32_R_TYPE (rel->r_info);
   1929  1.1.1.2  christos 
   1930  1.1.1.2  christos       if (r_type >= (int) R_ARC_max)
   1931  1.1.1.2  christos 	{
   1932  1.1.1.2  christos 	  bfd_set_error (bfd_error_bad_value);
   1933  1.1.1.2  christos 	  return FALSE;
   1934  1.1.1.2  christos 	}
   1935  1.1.1.3  christos       howto = arc_elf_howto (r_type);
   1936  1.1.1.3  christos 
   1937  1.1.1.2  christos       /* Load symbol information.  */
   1938  1.1.1.2  christos       r_symndx = ELF32_R_SYM (rel->r_info);
   1939  1.1.1.2  christos       if (r_symndx < symtab_hdr->sh_info) /* Is a local symbol.  */
   1940  1.1.1.2  christos 	h = NULL;
   1941  1.1.1.2  christos       else /* Global one.  */
   1942  1.1.1.2  christos 	h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   1943  1.1.1.2  christos 
   1944  1.1.1.3  christos       switch (r_type)
   1945  1.1.1.3  christos 	{
   1946  1.1.1.3  christos 	  case R_ARC_32:
   1947  1.1.1.3  christos 	  case R_ARC_32_ME:
   1948  1.1.1.3  christos 	    /* During shared library creation, these relocs should not
   1949  1.1.1.3  christos 	       appear in a shared library (as memory will be read only
   1950  1.1.1.3  christos 	       and the dynamic linker can not resolve these.  However
   1951  1.1.1.3  christos 	       the error should not occur for e.g. debugging or
   1952  1.1.1.3  christos 	       non-readonly sections.  */
   1953  1.1.1.4  christos 	    if (h != NULL
   1954  1.1.1.4  christos 		&& (bfd_link_dll (info) && !bfd_link_pie (info))
   1955  1.1.1.3  christos 		&& (sec->flags & SEC_ALLOC) != 0
   1956  1.1.1.3  christos 		&& (sec->flags & SEC_READONLY) != 0
   1957  1.1.1.3  christos 		&& ((sec->flags & SEC_CODE) != 0
   1958  1.1.1.3  christos 		    || (sec->flags & SEC_DEBUGGING) != 0))
   1959  1.1.1.3  christos 	      {
   1960  1.1.1.3  christos 		const char *name;
   1961  1.1.1.3  christos 		if (h)
   1962  1.1.1.3  christos 		  name = h->root.root.string;
   1963  1.1.1.3  christos 		else
   1964  1.1.1.3  christos 		  /* bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);  */
   1965  1.1.1.3  christos 		  name = "UNKNOWN";
   1966  1.1.1.4  christos 		_bfd_error_handler
   1967  1.1.1.4  christos 		  /* xgettext:c-format */
   1968  1.1.1.3  christos 		  (_("\
   1969  1.1.1.3  christos %B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
   1970  1.1.1.3  christos 		    abfd,
   1971  1.1.1.3  christos 		    arc_elf_howto (r_type)->name,
   1972  1.1.1.3  christos 		    name);
   1973  1.1.1.3  christos 		bfd_set_error (bfd_error_bad_value);
   1974  1.1.1.3  christos 		return FALSE;
   1975  1.1.1.3  christos 	      }
   1976  1.1.1.3  christos 
   1977  1.1.1.3  christos 	    /* In some cases we are not setting the 'non_got_ref'
   1978  1.1.1.3  christos 	       flag, even though the relocations don't require a GOT
   1979  1.1.1.3  christos 	       access.  We should extend the testing in this area to
   1980  1.1.1.3  christos 	       ensure that no significant cases are being missed.  */
   1981  1.1.1.3  christos 	    if (h)
   1982  1.1.1.3  christos 	      h->non_got_ref = 1;
   1983  1.1.1.3  christos 	    /* FALLTHROUGH */
   1984  1.1.1.3  christos 	  case R_ARC_PC32:
   1985  1.1.1.3  christos 	  case R_ARC_32_PCREL:
   1986  1.1.1.4  christos 	    if ((bfd_link_pic (info))
   1987  1.1.1.3  christos 		&& ((r_type != R_ARC_PC32 && r_type != R_ARC_32_PCREL)
   1988  1.1.1.3  christos 		    || (h != NULL
   1989  1.1.1.3  christos 			&& (!info->symbolic || !h->def_regular))))
   1990  1.1.1.3  christos 	      {
   1991  1.1.1.3  christos 		if (sreloc == NULL)
   1992  1.1.1.3  christos 		  {
   1993  1.1.1.4  christos 		    if (info->dynamic
   1994  1.1.1.4  christos 			&& ! htab->dynamic_sections_created
   1995  1.1.1.4  christos 			&& ! _bfd_elf_link_create_dynamic_sections (abfd, info))
   1996  1.1.1.4  christos 		      return FALSE;
   1997  1.1.1.3  christos 		    sreloc = _bfd_elf_make_dynamic_reloc_section (sec, dynobj,
   1998  1.1.1.3  christos 								  2, abfd,
   1999  1.1.1.3  christos 								  /*rela*/
   2000  1.1.1.3  christos 								  TRUE);
   2001  1.1.1.3  christos 
   2002  1.1.1.3  christos 		    if (sreloc == NULL)
   2003  1.1.1.3  christos 		      return FALSE;
   2004  1.1.1.3  christos 		  }
   2005  1.1.1.3  christos 		sreloc->size += sizeof (Elf32_External_Rela);
   2006  1.1.1.3  christos 
   2007  1.1.1.3  christos 	      }
   2008  1.1.1.3  christos 	  default:
   2009  1.1.1.3  christos 	    break;
   2010  1.1.1.3  christos 	}
   2011  1.1.1.3  christos 
   2012  1.1.1.4  christos       if (is_reloc_for_PLT (howto))
   2013  1.1.1.2  christos 	{
   2014  1.1.1.2  christos 	  if (h == NULL)
   2015  1.1.1.2  christos 	    continue;
   2016  1.1.1.2  christos 	  else
   2017  1.1.1.2  christos 	    h->needs_plt = 1;
   2018  1.1.1.2  christos 	}
   2019  1.1.1.2  christos 
   2020  1.1.1.4  christos       /* Add info to the symbol got_entry_list.  */
   2021  1.1.1.4  christos       if (is_reloc_for_GOT (howto)
   2022  1.1.1.4  christos 	  || is_reloc_for_TLS (howto))
   2023  1.1.1.3  christos 	{
   2024  1.1.1.4  christos 	  if (! _bfd_elf_create_got_section (dynobj, info))
   2025  1.1.1.4  christos 	    return FALSE;
   2026  1.1.1.2  christos 
   2027  1.1.1.4  christos 	  arc_fill_got_info_for_reloc (
   2028  1.1.1.4  christos 		  arc_got_entry_type_for_reloc (howto),
   2029  1.1.1.4  christos 		  get_got_entry_list_for_symbol (abfd, r_symndx, h),
   2030  1.1.1.4  christos 		  info,
   2031  1.1.1.4  christos 		  h);
   2032  1.1.1.3  christos 	}
   2033  1.1.1.3  christos     }
   2034  1.1.1.2  christos 
   2035  1.1.1.3  christos   return TRUE;
   2036  1.1.1.3  christos }
   2037  1.1.1.2  christos 
   2038  1.1.1.3  christos #define ELF_DYNAMIC_INTERPRETER  "/sbin/ld-uClibc.so"
   2039  1.1.1.2  christos 
   2040  1.1.1.3  christos static struct plt_version_t *
   2041  1.1.1.3  christos arc_get_plt_version (struct bfd_link_info *info)
   2042  1.1.1.2  christos {
   2043  1.1.1.3  christos   int i;
   2044  1.1.1.2  christos 
   2045  1.1.1.3  christos   for (i = 0; i < 1; i++)
   2046  1.1.1.3  christos     {
   2047  1.1.1.3  christos       ARC_DEBUG ("%d: size1 = %d, size2 = %d\n", i,
   2048  1.1.1.4  christos 		 (int) plt_versions[i].entry_size,
   2049  1.1.1.4  christos 		 (int) plt_versions[i].elem_size);
   2050  1.1.1.3  christos     }
   2051  1.1.1.2  christos 
   2052  1.1.1.3  christos   if (bfd_get_mach (info->output_bfd) == bfd_mach_arc_arcv2)
   2053  1.1.1.2  christos     {
   2054  1.1.1.3  christos       if (bfd_link_pic (info))
   2055  1.1.1.3  christos 	return &(plt_versions[ELF_ARCV2_PIC]);
   2056  1.1.1.3  christos       else
   2057  1.1.1.3  christos 	return &(plt_versions[ELF_ARCV2_ABS]);
   2058  1.1.1.3  christos     }
   2059  1.1.1.3  christos   else
   2060  1.1.1.2  christos     {
   2061  1.1.1.3  christos       if (bfd_link_pic (info))
   2062  1.1.1.3  christos 	return &(plt_versions[ELF_ARC_PIC]);
   2063  1.1.1.3  christos       else
   2064  1.1.1.3  christos 	return &(plt_versions[ELF_ARC_ABS]);
   2065  1.1.1.2  christos     }
   2066  1.1.1.2  christos }
   2067  1.1.1.2  christos 
   2068  1.1.1.2  christos static bfd_vma
   2069  1.1.1.2  christos add_symbol_to_plt (struct bfd_link_info *info)
   2070  1.1.1.2  christos {
   2071  1.1.1.3  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
   2072  1.1.1.2  christos   bfd_vma ret;
   2073  1.1.1.2  christos 
   2074  1.1.1.3  christos   struct plt_version_t *plt_data = arc_get_plt_version (info);
   2075  1.1.1.3  christos 
   2076  1.1.1.3  christos   /* If this is the first .plt entry, make room for the special first
   2077  1.1.1.3  christos      entry.  */
   2078  1.1.1.3  christos   if (htab->splt->size == 0)
   2079  1.1.1.3  christos     htab->splt->size += plt_data->entry_size;
   2080  1.1.1.3  christos 
   2081  1.1.1.3  christos   ret = htab->splt->size;
   2082  1.1.1.3  christos 
   2083  1.1.1.3  christos   htab->splt->size += plt_data->elem_size;
   2084  1.1.1.4  christos   ARC_DEBUG ("PLT_SIZE = %d\n", (int) htab->splt->size);
   2085  1.1.1.3  christos 
   2086  1.1.1.3  christos   htab->sgotplt->size += 4;
   2087  1.1.1.3  christos   htab->srelplt->size += sizeof (Elf32_External_Rela);
   2088  1.1.1.2  christos 
   2089  1.1.1.2  christos   return ret;
   2090  1.1.1.2  christos }
   2091  1.1.1.2  christos 
   2092  1.1.1.3  christos #define PLT_DO_RELOCS_FOR_ENTRY(ABFD, DS, RELOCS)	\
   2093  1.1.1.3  christos   plt_do_relocs_for_symbol (ABFD, DS, RELOCS, 0, 0)
   2094  1.1.1.2  christos 
   2095  1.1.1.2  christos static void
   2096  1.1.1.3  christos plt_do_relocs_for_symbol (bfd *abfd,
   2097  1.1.1.3  christos 			  struct elf_link_hash_table *htab,
   2098  1.1.1.3  christos 			  const struct plt_reloc *reloc,
   2099  1.1.1.2  christos 			  bfd_vma plt_offset,
   2100  1.1.1.2  christos 			  bfd_vma symbol_got_offset)
   2101  1.1.1.2  christos {
   2102  1.1.1.2  christos   while (SYM_ONLY (reloc->symbol) != LAST_RELOC)
   2103  1.1.1.2  christos     {
   2104  1.1.1.2  christos       bfd_vma relocation = 0;
   2105  1.1.1.2  christos 
   2106  1.1.1.2  christos       switch (SYM_ONLY (reloc->symbol))
   2107  1.1.1.2  christos 	{
   2108  1.1.1.2  christos 	  case SGOT:
   2109  1.1.1.4  christos 		relocation
   2110  1.1.1.4  christos 		  = htab->sgotplt->output_section->vma
   2111  1.1.1.4  christos 		    + htab->sgotplt->output_offset + symbol_got_offset;
   2112  1.1.1.2  christos 		break;
   2113  1.1.1.2  christos 	}
   2114  1.1.1.2  christos       relocation += reloc->addend;
   2115  1.1.1.2  christos 
   2116  1.1.1.3  christos       if (IS_RELATIVE (reloc->symbol))
   2117  1.1.1.3  christos 	{
   2118  1.1.1.3  christos 	  bfd_vma reloc_offset = reloc->offset;
   2119  1.1.1.3  christos 	  reloc_offset -= (IS_INSN_32 (reloc->symbol)) ? 4 : 0;
   2120  1.1.1.3  christos 	  reloc_offset -= (IS_INSN_24 (reloc->symbol)) ? 2 : 0;
   2121  1.1.1.2  christos 
   2122  1.1.1.3  christos 	  relocation -= htab->splt->output_section->vma
   2123  1.1.1.3  christos 			 + htab->splt->output_offset
   2124  1.1.1.3  christos 			 + plt_offset + reloc_offset;
   2125  1.1.1.3  christos 	}
   2126  1.1.1.3  christos 
   2127  1.1.1.3  christos       /* TODO: being ME is not a property of the relocation but of the
   2128  1.1.1.3  christos 	 section of which is applying the relocation. */
   2129  1.1.1.3  christos       if (IS_MIDDLE_ENDIAN (reloc->symbol) && !bfd_big_endian (abfd))
   2130  1.1.1.2  christos 	{
   2131  1.1.1.4  christos 	  relocation
   2132  1.1.1.4  christos 	    = ((relocation & 0xffff0000) >> 16)
   2133  1.1.1.4  christos 	      | ((relocation & 0xffff) << 16);
   2134  1.1.1.2  christos 	}
   2135  1.1.1.2  christos 
   2136  1.1.1.2  christos       switch (reloc->size)
   2137  1.1.1.2  christos 	{
   2138  1.1.1.2  christos 	  case 32:
   2139  1.1.1.3  christos 	    bfd_put_32 (htab->splt->output_section->owner,
   2140  1.1.1.2  christos 			relocation,
   2141  1.1.1.3  christos 			htab->splt->contents + plt_offset + reloc->offset);
   2142  1.1.1.2  christos 	    break;
   2143  1.1.1.2  christos 	}
   2144  1.1.1.2  christos 
   2145  1.1.1.3  christos       reloc = &(reloc[1]); /* Jump to next relocation.  */
   2146  1.1.1.2  christos     }
   2147  1.1.1.2  christos }
   2148  1.1.1.2  christos 
   2149  1.1.1.2  christos static void
   2150  1.1.1.3  christos relocate_plt_for_symbol (bfd *output_bfd,
   2151  1.1.1.3  christos 			 struct bfd_link_info *info,
   2152  1.1.1.2  christos 			 struct elf_link_hash_entry *h)
   2153  1.1.1.2  christos {
   2154  1.1.1.3  christos   struct plt_version_t *plt_data = arc_get_plt_version (info);
   2155  1.1.1.3  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
   2156  1.1.1.2  christos 
   2157  1.1.1.3  christos   bfd_vma plt_index = (h->plt.offset  - plt_data->entry_size)
   2158  1.1.1.3  christos 		      / plt_data->elem_size;
   2159  1.1.1.2  christos   bfd_vma got_offset = (plt_index + 3) * 4;
   2160  1.1.1.2  christos 
   2161  1.1.1.4  christos   ARC_DEBUG ("arc_info: PLT_OFFSET = %#lx, PLT_ENTRY_VMA = %#lx, \
   2162  1.1.1.4  christos GOT_ENTRY_OFFSET = %#lx, GOT_ENTRY_VMA = %#lx, for symbol %s\n",
   2163  1.1.1.4  christos 	     (long) h->plt.offset,
   2164  1.1.1.4  christos 	     (long) (htab->splt->output_section->vma
   2165  1.1.1.4  christos 		     + htab->splt->output_offset
   2166  1.1.1.4  christos 		     + h->plt.offset),
   2167  1.1.1.4  christos 	     (long) got_offset,
   2168  1.1.1.4  christos 	     (long) (htab->sgotplt->output_section->vma
   2169  1.1.1.4  christos 		     + htab->sgotplt->output_offset
   2170  1.1.1.4  christos 		     + got_offset),
   2171  1.1.1.3  christos 	     h->root.root.string);
   2172  1.1.1.3  christos 
   2173  1.1.1.3  christos   {
   2174  1.1.1.3  christos     bfd_vma i = 0;
   2175  1.1.1.3  christos     uint16_t *ptr = (uint16_t *) plt_data->elem;
   2176  1.1.1.4  christos 
   2177  1.1.1.3  christos     for (i = 0; i < plt_data->elem_size/2; i++)
   2178  1.1.1.3  christos       {
   2179  1.1.1.3  christos 	uint16_t data = ptr[i];
   2180  1.1.1.3  christos 	bfd_put_16 (output_bfd,
   2181  1.1.1.3  christos 		    (bfd_vma) data,
   2182  1.1.1.3  christos 		    htab->splt->contents + h->plt.offset + (i*2));
   2183  1.1.1.3  christos       }
   2184  1.1.1.3  christos   }
   2185  1.1.1.3  christos 
   2186  1.1.1.3  christos   plt_do_relocs_for_symbol (output_bfd, htab,
   2187  1.1.1.3  christos 			    plt_data->elem_relocs,
   2188  1.1.1.3  christos 			    h->plt.offset,
   2189  1.1.1.2  christos 			    got_offset);
   2190  1.1.1.3  christos 
   2191  1.1.1.3  christos   /* Fill in the entry in the global offset table.  */
   2192  1.1.1.3  christos   bfd_put_32 (output_bfd,
   2193  1.1.1.3  christos 	      (bfd_vma) (htab->splt->output_section->vma
   2194  1.1.1.3  christos 			 + htab->splt->output_offset),
   2195  1.1.1.3  christos 	      htab->sgotplt->contents + got_offset);
   2196  1.1.1.3  christos 
   2197  1.1.1.3  christos   /* TODO: Fill in the entry in the .rela.plt section.  */
   2198  1.1.1.3  christos   {
   2199  1.1.1.3  christos     Elf_Internal_Rela rel;
   2200  1.1.1.3  christos     bfd_byte *loc;
   2201  1.1.1.3  christos 
   2202  1.1.1.3  christos     rel.r_offset = (htab->sgotplt->output_section->vma
   2203  1.1.1.3  christos 		    + htab->sgotplt->output_offset
   2204  1.1.1.3  christos 		    + got_offset);
   2205  1.1.1.3  christos     rel.r_addend = 0;
   2206  1.1.1.3  christos 
   2207  1.1.1.3  christos     BFD_ASSERT (h->dynindx != -1);
   2208  1.1.1.3  christos     rel.r_info = ELF32_R_INFO (h->dynindx, R_ARC_JMP_SLOT);
   2209  1.1.1.3  christos 
   2210  1.1.1.3  christos     loc = htab->srelplt->contents;
   2211  1.1.1.3  christos     loc += plt_index * sizeof (Elf32_External_Rela); /* relA */
   2212  1.1.1.3  christos     bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
   2213  1.1.1.3  christos   }
   2214  1.1.1.2  christos }
   2215  1.1.1.2  christos 
   2216  1.1.1.2  christos static void
   2217  1.1.1.3  christos relocate_plt_for_entry (bfd *abfd,
   2218  1.1.1.3  christos 			struct bfd_link_info *info)
   2219  1.1.1.2  christos {
   2220  1.1.1.3  christos   struct plt_version_t *plt_data = arc_get_plt_version (info);
   2221  1.1.1.3  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
   2222  1.1.1.2  christos 
   2223  1.1.1.3  christos   {
   2224  1.1.1.3  christos     bfd_vma i = 0;
   2225  1.1.1.3  christos     uint16_t *ptr = (uint16_t *) plt_data->entry;
   2226  1.1.1.3  christos     for (i = 0; i < plt_data->entry_size/2; i++)
   2227  1.1.1.3  christos       {
   2228  1.1.1.3  christos 	uint16_t data = ptr[i];
   2229  1.1.1.3  christos 	bfd_put_16 (abfd,
   2230  1.1.1.3  christos 		    (bfd_vma) data,
   2231  1.1.1.3  christos 		    htab->splt->contents + (i*2));
   2232  1.1.1.3  christos       }
   2233  1.1.1.3  christos   }
   2234  1.1.1.3  christos   PLT_DO_RELOCS_FOR_ENTRY (abfd, htab, plt_data->entry_relocs);
   2235  1.1.1.2  christos }
   2236  1.1.1.2  christos 
   2237  1.1.1.3  christos /* Desc : Adjust a symbol defined by a dynamic object and referenced
   2238  1.1.1.3  christos    by a regular object.  The current definition is in some section of
   2239  1.1.1.3  christos    the dynamic object, but we're not including those sections.  We
   2240  1.1.1.3  christos    have to change the definition to something the rest of the link can
   2241  1.1.1.2  christos    understand.  */
   2242  1.1.1.2  christos 
   2243  1.1.1.2  christos static bfd_boolean
   2244  1.1.1.2  christos elf_arc_adjust_dynamic_symbol (struct bfd_link_info *info,
   2245  1.1.1.2  christos 			      struct elf_link_hash_entry *h)
   2246  1.1.1.2  christos {
   2247  1.1.1.3  christos   asection *s;
   2248  1.1.1.2  christos   bfd *dynobj = (elf_hash_table (info))->dynobj;
   2249  1.1.1.3  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
   2250  1.1.1.2  christos 
   2251  1.1.1.3  christos   if (h->type == STT_FUNC
   2252  1.1.1.3  christos       || h->type == STT_GNU_IFUNC
   2253  1.1.1.3  christos       || h->needs_plt == 1)
   2254  1.1.1.2  christos     {
   2255  1.1.1.2  christos       if (!bfd_link_pic (info) && !h->def_dynamic && !h->ref_dynamic)
   2256  1.1.1.2  christos 	{
   2257  1.1.1.2  christos 	  /* This case can occur if we saw a PLT32 reloc in an input
   2258  1.1.1.2  christos 	     file, but the symbol was never referred to by a dynamic
   2259  1.1.1.2  christos 	     object.  In such a case, we don't actually need to build
   2260  1.1.1.2  christos 	     a procedure linkage table, and we can just do a PC32
   2261  1.1.1.2  christos 	     reloc instead.  */
   2262  1.1.1.2  christos 	  BFD_ASSERT (h->needs_plt);
   2263  1.1.1.2  christos 	  return TRUE;
   2264  1.1.1.2  christos 	}
   2265  1.1.1.2  christos 
   2266  1.1.1.2  christos       /* Make sure this symbol is output as a dynamic symbol.  */
   2267  1.1.1.2  christos       if (h->dynindx == -1 && !h->forced_local
   2268  1.1.1.2  christos 	  && !bfd_elf_link_record_dynamic_symbol (info, h))
   2269  1.1.1.2  christos 	return FALSE;
   2270  1.1.1.2  christos 
   2271  1.1.1.3  christos       if (bfd_link_pic (info)
   2272  1.1.1.3  christos 	  || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
   2273  1.1.1.2  christos 	{
   2274  1.1.1.2  christos 	  bfd_vma loc = add_symbol_to_plt (info);
   2275  1.1.1.2  christos 
   2276  1.1.1.4  christos 	  if (bfd_link_executable (info) && !h->def_regular)
   2277  1.1.1.2  christos 	    {
   2278  1.1.1.3  christos 	      h->root.u.def.section = htab->splt;
   2279  1.1.1.2  christos 	      h->root.u.def.value = loc;
   2280  1.1.1.2  christos 	    }
   2281  1.1.1.2  christos 	  h->plt.offset = loc;
   2282  1.1.1.2  christos 	}
   2283  1.1.1.3  christos       else
   2284  1.1.1.3  christos 	{
   2285  1.1.1.3  christos 	  h->plt.offset = (bfd_vma) -1;
   2286  1.1.1.3  christos 	  h->needs_plt = 0;
   2287  1.1.1.3  christos 	}
   2288  1.1.1.3  christos       return TRUE;
   2289  1.1.1.2  christos     }
   2290  1.1.1.3  christos 
   2291  1.1.1.3  christos   /* If this is a weak symbol, and there is a real definition, the
   2292  1.1.1.3  christos      processor independent code will have arranged for us to see the
   2293  1.1.1.3  christos      real definition first, and we can just use the same value.  */
   2294  1.1.1.4  christos   if (h->is_weakalias)
   2295  1.1.1.2  christos     {
   2296  1.1.1.4  christos       struct elf_link_hash_entry *def = weakdef (h);
   2297  1.1.1.4  christos       BFD_ASSERT (def->root.type == bfd_link_hash_defined);
   2298  1.1.1.4  christos       h->root.u.def.section = def->root.u.def.section;
   2299  1.1.1.4  christos       h->root.u.def.value = def->root.u.def.value;
   2300  1.1.1.3  christos       return TRUE;
   2301  1.1.1.2  christos     }
   2302  1.1.1.2  christos 
   2303  1.1.1.3  christos   /* This is a reference to a symbol defined by a dynamic object which
   2304  1.1.1.3  christos      is not a function.  */
   2305  1.1.1.2  christos 
   2306  1.1.1.3  christos   /* If we are creating a shared library, we must presume that the
   2307  1.1.1.3  christos      only references to the symbol are via the global offset table.
   2308  1.1.1.3  christos      For such cases we need not do anything here; the relocations will
   2309  1.1.1.3  christos      be handled correctly by relocate_section.  */
   2310  1.1.1.3  christos   if (!bfd_link_executable (info))
   2311  1.1.1.3  christos     return TRUE;
   2312  1.1.1.3  christos 
   2313  1.1.1.3  christos   /* If there are no non-GOT references, we do not need a copy
   2314  1.1.1.3  christos      relocation.  */
   2315  1.1.1.3  christos   if (!h->non_got_ref)
   2316  1.1.1.3  christos     return TRUE;
   2317  1.1.1.3  christos 
   2318  1.1.1.3  christos   /* If -z nocopyreloc was given, we won't generate them either.  */
   2319  1.1.1.3  christos   if (info->nocopyreloc)
   2320  1.1.1.3  christos     {
   2321  1.1.1.3  christos       h->non_got_ref = 0;
   2322  1.1.1.3  christos       return TRUE;
   2323  1.1.1.3  christos     }
   2324  1.1.1.3  christos 
   2325  1.1.1.3  christos   /* We must allocate the symbol in our .dynbss section, which will
   2326  1.1.1.3  christos      become part of the .bss section of the executable.  There will be
   2327  1.1.1.3  christos      an entry for this symbol in the .dynsym section.  The dynamic
   2328  1.1.1.3  christos      object will contain position independent code, so all references
   2329  1.1.1.3  christos      from the dynamic object to this symbol will go through the global
   2330  1.1.1.3  christos      offset table.  The dynamic linker will use the .dynsym entry to
   2331  1.1.1.3  christos      determine the address it must put in the global offset table, so
   2332  1.1.1.3  christos      both the dynamic object and the regular object will refer to the
   2333  1.1.1.3  christos      same memory location for the variable.  */
   2334  1.1.1.3  christos 
   2335  1.1.1.3  christos   if (htab == NULL)
   2336  1.1.1.3  christos     return FALSE;
   2337  1.1.1.3  christos 
   2338  1.1.1.3  christos   /* We must generate a R_ARC_COPY reloc to tell the dynamic linker to
   2339  1.1.1.3  christos      copy the initial value out of the dynamic object and into the
   2340  1.1.1.3  christos      runtime process image.  We need to remember the offset into the
   2341  1.1.1.3  christos      .rela.bss section we are going to use.  */
   2342  1.1.1.3  christos   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
   2343  1.1.1.3  christos     {
   2344  1.1.1.4  christos       struct elf_arc_link_hash_table *arc_htab = elf_arc_hash_table (info);
   2345  1.1.1.3  christos 
   2346  1.1.1.4  christos       BFD_ASSERT (arc_htab->elf.srelbss != NULL);
   2347  1.1.1.4  christos       arc_htab->elf.srelbss->size += sizeof (Elf32_External_Rela);
   2348  1.1.1.3  christos       h->needs_copy = 1;
   2349  1.1.1.3  christos     }
   2350  1.1.1.3  christos 
   2351  1.1.1.4  christos   /* TODO: Move this also to arc_hash_table.  */
   2352  1.1.1.3  christos   s = bfd_get_section_by_name (dynobj, ".dynbss");
   2353  1.1.1.3  christos   BFD_ASSERT (s != NULL);
   2354  1.1.1.3  christos 
   2355  1.1.1.3  christos   return _bfd_elf_adjust_dynamic_copy (info, h, s);
   2356  1.1.1.2  christos }
   2357  1.1.1.2  christos 
   2358  1.1.1.2  christos /* Function :  elf_arc_finish_dynamic_symbol
   2359  1.1.1.2  christos    Brief    :  Finish up dynamic symbol handling.  We set the
   2360  1.1.1.3  christos 	     contents of various dynamic sections here.
   2361  1.1.1.2  christos    Args     :  output_bfd :
   2362  1.1.1.3  christos 	       info	  :
   2363  1.1.1.3  christos 	       h	  :
   2364  1.1.1.3  christos 	       sym	  :
   2365  1.1.1.2  christos    Returns  : True/False as the return status.  */
   2366  1.1.1.3  christos 
   2367  1.1.1.2  christos static bfd_boolean
   2368  1.1.1.2  christos elf_arc_finish_dynamic_symbol (bfd * output_bfd,
   2369  1.1.1.2  christos 			       struct bfd_link_info *info,
   2370  1.1.1.2  christos 			       struct elf_link_hash_entry *h,
   2371  1.1.1.2  christos 			       Elf_Internal_Sym * sym)
   2372  1.1.1.2  christos {
   2373  1.1.1.3  christos   if (h->plt.offset != (bfd_vma) -1)
   2374  1.1.1.2  christos     {
   2375  1.1.1.3  christos       relocate_plt_for_symbol (output_bfd, info, h);
   2376  1.1.1.3  christos 
   2377  1.1.1.3  christos       if (!h->def_regular)
   2378  1.1.1.2  christos 	{
   2379  1.1.1.3  christos 	  /* Mark the symbol as undefined, rather than as defined in
   2380  1.1.1.3  christos 	     the .plt section.  Leave the value alone.  */
   2381  1.1.1.3  christos 	  sym->st_shndx = SHN_UNDEF;
   2382  1.1.1.2  christos 	}
   2383  1.1.1.3  christos     }
   2384  1.1.1.3  christos 
   2385  1.1.1.3  christos 
   2386  1.1.1.4  christos   /* This function traverses list of GOT entries and
   2387  1.1.1.4  christos      create respective dynamic relocs.  */
   2388  1.1.1.4  christos   /* TODO: Make function to get list and not access the list directly.  */
   2389  1.1.1.4  christos   /* TODO: Move function to relocate_section create this relocs eagerly.  */
   2390  1.1.1.4  christos   create_got_dynrelocs_for_got_info (&h->got.glist,
   2391  1.1.1.4  christos 				     output_bfd,
   2392  1.1.1.4  christos 				     info,
   2393  1.1.1.4  christos 				     h);
   2394  1.1.1.3  christos 
   2395  1.1.1.3  christos   if (h->needs_copy)
   2396  1.1.1.3  christos     {
   2397  1.1.1.4  christos       struct elf_arc_link_hash_table *arc_htab = elf_arc_hash_table (info);
   2398  1.1.1.4  christos 
   2399  1.1.1.4  christos       if (h->dynindx == -1
   2400  1.1.1.4  christos 	  || (h->root.type != bfd_link_hash_defined
   2401  1.1.1.4  christos 	      && h->root.type != bfd_link_hash_defweak)
   2402  1.1.1.4  christos 	  || arc_htab->elf.srelbss == NULL)
   2403  1.1.1.4  christos 	abort ();
   2404  1.1.1.4  christos 
   2405  1.1.1.3  christos       bfd_vma rel_offset = (h->root.u.def.value
   2406  1.1.1.3  christos 			    + h->root.u.def.section->output_section->vma
   2407  1.1.1.3  christos 			    + h->root.u.def.section->output_offset);
   2408  1.1.1.3  christos 
   2409  1.1.1.4  christos       bfd_byte * loc = arc_htab->elf.srelbss->contents
   2410  1.1.1.4  christos 	+ (arc_htab->elf.srelbss->reloc_count * sizeof (Elf32_External_Rela));
   2411  1.1.1.4  christos       arc_htab->elf.srelbss->reloc_count++;
   2412  1.1.1.3  christos 
   2413  1.1.1.3  christos       Elf_Internal_Rela rel;
   2414  1.1.1.3  christos       rel.r_addend = 0;
   2415  1.1.1.3  christos       rel.r_offset = rel_offset;
   2416  1.1.1.3  christos 
   2417  1.1.1.3  christos       BFD_ASSERT (h->dynindx != -1);
   2418  1.1.1.3  christos       rel.r_info = ELF32_R_INFO (h->dynindx, R_ARC_COPY);
   2419  1.1.1.3  christos 
   2420  1.1.1.3  christos       bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
   2421  1.1.1.2  christos     }
   2422  1.1.1.2  christos 
   2423  1.1.1.2  christos   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
   2424  1.1.1.2  christos   if (strcmp (h->root.root.string, "_DYNAMIC") == 0
   2425  1.1.1.2  christos       || strcmp (h->root.root.string, "__DYNAMIC") == 0
   2426  1.1.1.2  christos       || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
   2427  1.1.1.2  christos     sym->st_shndx = SHN_ABS;
   2428  1.1.1.2  christos 
   2429  1.1.1.2  christos   return TRUE;
   2430  1.1.1.2  christos }
   2431  1.1.1.2  christos 
   2432  1.1.1.3  christos #define GET_SYMBOL_OR_SECTION(TAG, SYMBOL, SECTION)		\
   2433  1.1.1.3  christos   case TAG:							\
   2434  1.1.1.3  christos   if (SYMBOL != NULL)						\
   2435  1.1.1.3  christos     h = elf_link_hash_lookup (elf_hash_table (info),		\
   2436  1.1.1.3  christos 			      SYMBOL, FALSE, FALSE, TRUE);	\
   2437  1.1.1.3  christos   else if (SECTION != NULL)					\
   2438  1.1.1.3  christos     s = bfd_get_linker_section (dynobj, SECTION);		\
   2439  1.1.1.3  christos   break;
   2440  1.1.1.2  christos 
   2441  1.1.1.2  christos /* Function :  elf_arc_finish_dynamic_sections
   2442  1.1.1.2  christos    Brief    :  Finish up the dynamic sections handling.
   2443  1.1.1.2  christos    Args     :  output_bfd :
   2444  1.1.1.3  christos 	       info	  :
   2445  1.1.1.3  christos 	       h	  :
   2446  1.1.1.3  christos 	       sym	  :
   2447  1.1.1.2  christos    Returns  : True/False as the return status.  */
   2448  1.1.1.3  christos 
   2449  1.1.1.2  christos static bfd_boolean
   2450  1.1.1.3  christos elf_arc_finish_dynamic_sections (bfd * output_bfd,
   2451  1.1.1.3  christos 				 struct bfd_link_info *info)
   2452  1.1.1.2  christos {
   2453  1.1.1.3  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
   2454  1.1.1.2  christos   bfd *dynobj = (elf_hash_table (info))->dynobj;
   2455  1.1.1.4  christos   asection *sdyn = bfd_get_linker_section (dynobj, ".dynamic");
   2456  1.1.1.2  christos 
   2457  1.1.1.4  christos   if (sdyn)
   2458  1.1.1.2  christos     {
   2459  1.1.1.2  christos       Elf32_External_Dyn *dyncon, *dynconend;
   2460  1.1.1.2  christos 
   2461  1.1.1.4  christos       dyncon = (Elf32_External_Dyn *) sdyn->contents;
   2462  1.1.1.4  christos       dynconend
   2463  1.1.1.4  christos 	= (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
   2464  1.1.1.2  christos       for (; dyncon < dynconend; dyncon++)
   2465  1.1.1.2  christos 	{
   2466  1.1.1.2  christos 	  Elf_Internal_Dyn internal_dyn;
   2467  1.1.1.2  christos 	  bfd_boolean	  do_it = FALSE;
   2468  1.1.1.2  christos 
   2469  1.1.1.2  christos 	  struct elf_link_hash_entry *h = NULL;
   2470  1.1.1.2  christos 	  asection	 *s = NULL;
   2471  1.1.1.2  christos 
   2472  1.1.1.2  christos 	  bfd_elf32_swap_dyn_in (dynobj, dyncon, &internal_dyn);
   2473  1.1.1.2  christos 
   2474  1.1.1.2  christos 	  switch (internal_dyn.d_tag)
   2475  1.1.1.2  christos 	    {
   2476  1.1.1.4  christos 	      GET_SYMBOL_OR_SECTION (DT_INIT, info->init_function, NULL)
   2477  1.1.1.4  christos 	      GET_SYMBOL_OR_SECTION (DT_FINI, info->fini_function, NULL)
   2478  1.1.1.2  christos 	      GET_SYMBOL_OR_SECTION (DT_PLTGOT, NULL, ".plt")
   2479  1.1.1.2  christos 	      GET_SYMBOL_OR_SECTION (DT_JMPREL, NULL, ".rela.plt")
   2480  1.1.1.2  christos 	      GET_SYMBOL_OR_SECTION (DT_PLTRELSZ, NULL, ".rela.plt")
   2481  1.1.1.3  christos 	      GET_SYMBOL_OR_SECTION (DT_VERSYM, NULL, ".gnu.version")
   2482  1.1.1.3  christos 	      GET_SYMBOL_OR_SECTION (DT_VERDEF, NULL, ".gnu.version_d")
   2483  1.1.1.3  christos 	      GET_SYMBOL_OR_SECTION (DT_VERNEED, NULL, ".gnu.version_r")
   2484  1.1.1.2  christos 	      default:
   2485  1.1.1.2  christos 		break;
   2486  1.1.1.2  christos 	    }
   2487  1.1.1.2  christos 
   2488  1.1.1.3  christos 	  /* In case the dynamic symbols should be updated with a symbol.  */
   2489  1.1.1.2  christos 	  if (h != NULL
   2490  1.1.1.2  christos 	      && (h->root.type == bfd_link_hash_defined
   2491  1.1.1.3  christos 		  || h->root.type == bfd_link_hash_defweak))
   2492  1.1.1.2  christos 	    {
   2493  1.1.1.2  christos 	      asection	     *asec_ptr;
   2494  1.1.1.2  christos 
   2495  1.1.1.2  christos 	      internal_dyn.d_un.d_val = h->root.u.def.value;
   2496  1.1.1.2  christos 	      asec_ptr = h->root.u.def.section;
   2497  1.1.1.2  christos 	      if (asec_ptr->output_section != NULL)
   2498  1.1.1.2  christos 		{
   2499  1.1.1.2  christos 		  internal_dyn.d_un.d_val +=
   2500  1.1.1.4  christos 		    (asec_ptr->output_section->vma
   2501  1.1.1.4  christos 		     + asec_ptr->output_offset);
   2502  1.1.1.2  christos 		}
   2503  1.1.1.2  christos 	      else
   2504  1.1.1.2  christos 		{
   2505  1.1.1.3  christos 		  /* The symbol is imported from another shared
   2506  1.1.1.3  christos 		     library and does not apply to this one.  */
   2507  1.1.1.2  christos 		  internal_dyn.d_un.d_val = 0;
   2508  1.1.1.2  christos 		}
   2509  1.1.1.2  christos 	      do_it = TRUE;
   2510  1.1.1.2  christos 	    }
   2511  1.1.1.2  christos 	  else if (s != NULL) /* With a section information.  */
   2512  1.1.1.2  christos 	    {
   2513  1.1.1.2  christos 	      switch (internal_dyn.d_tag)
   2514  1.1.1.2  christos 		{
   2515  1.1.1.2  christos 		  case DT_PLTGOT:
   2516  1.1.1.2  christos 		  case DT_JMPREL:
   2517  1.1.1.3  christos 		  case DT_VERSYM:
   2518  1.1.1.3  christos 		  case DT_VERDEF:
   2519  1.1.1.3  christos 		  case DT_VERNEED:
   2520  1.1.1.3  christos 		    internal_dyn.d_un.d_ptr = (s->output_section->vma
   2521  1.1.1.3  christos 					       + s->output_offset);
   2522  1.1.1.2  christos 		    do_it = TRUE;
   2523  1.1.1.2  christos 		    break;
   2524  1.1.1.2  christos 
   2525  1.1.1.2  christos 		  case DT_PLTRELSZ:
   2526  1.1.1.2  christos 		    internal_dyn.d_un.d_val = s->size;
   2527  1.1.1.2  christos 		    do_it = TRUE;
   2528  1.1.1.2  christos 		    break;
   2529  1.1.1.2  christos 
   2530  1.1.1.2  christos 		  default:
   2531  1.1.1.2  christos 		    break;
   2532  1.1.1.2  christos 		}
   2533  1.1.1.2  christos 	    }
   2534  1.1.1.2  christos 
   2535  1.1.1.3  christos 	  if (do_it)
   2536  1.1.1.2  christos 	    bfd_elf32_swap_dyn_out (output_bfd, &internal_dyn, dyncon);
   2537  1.1.1.2  christos 	}
   2538  1.1.1.2  christos 
   2539  1.1.1.3  christos       if (htab->splt->size > 0)
   2540  1.1.1.2  christos 	{
   2541  1.1.1.3  christos 	  relocate_plt_for_entry (output_bfd, info);
   2542  1.1.1.2  christos 	}
   2543  1.1.1.2  christos 
   2544  1.1.1.3  christos       /* TODO: Validate this.  */
   2545  1.1.1.4  christos       if (htab->srelplt->output_section != bfd_abs_section_ptr)
   2546  1.1.1.4  christos 	elf_section_data (htab->srelplt->output_section)
   2547  1.1.1.4  christos 	  ->this_hdr.sh_entsize = 12;
   2548  1.1.1.2  christos     }
   2549  1.1.1.2  christos 
   2550  1.1.1.2  christos   /* Fill in the first three entries in the global offset table.  */
   2551  1.1.1.3  christos   if (htab->sgot)
   2552  1.1.1.2  christos     {
   2553  1.1.1.3  christos       struct elf_link_hash_entry *h;
   2554  1.1.1.3  christos       h = elf_link_hash_lookup (elf_hash_table (info), "_GLOBAL_OFFSET_TABLE_",
   2555  1.1.1.3  christos 				 FALSE, FALSE, TRUE);
   2556  1.1.1.3  christos 
   2557  1.1.1.3  christos 	if (h != NULL && h->root.type != bfd_link_hash_undefined
   2558  1.1.1.3  christos 	    && h->root.u.def.section != NULL)
   2559  1.1.1.2  christos 	{
   2560  1.1.1.3  christos 	  asection *sec = h->root.u.def.section;
   2561  1.1.1.3  christos 
   2562  1.1.1.4  christos 	  if (sdyn == NULL)
   2563  1.1.1.2  christos 	    bfd_put_32 (output_bfd, (bfd_vma) 0,
   2564  1.1.1.3  christos 			sec->contents);
   2565  1.1.1.2  christos 	  else
   2566  1.1.1.2  christos 	    bfd_put_32 (output_bfd,
   2567  1.1.1.4  christos 			sdyn->output_section->vma + sdyn->output_offset,
   2568  1.1.1.3  christos 			sec->contents);
   2569  1.1.1.3  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sec->contents + 4);
   2570  1.1.1.3  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sec->contents + 8);
   2571  1.1.1.2  christos 	}
   2572  1.1.1.2  christos     }
   2573  1.1.1.2  christos 
   2574  1.1.1.2  christos   return TRUE;
   2575  1.1.1.2  christos }
   2576  1.1.1.2  christos 
   2577  1.1.1.3  christos #define ADD_DYNAMIC_SYMBOL(NAME, TAG)					\
   2578  1.1.1.3  christos   h =  elf_link_hash_lookup (elf_hash_table (info),			\
   2579  1.1.1.3  christos 			     NAME, FALSE, FALSE, FALSE);		\
   2580  1.1.1.3  christos   if ((h != NULL && (h->ref_regular || h->def_regular)))		\
   2581  1.1.1.3  christos     if (! _bfd_elf_add_dynamic_entry (info, TAG, 0))			\
   2582  1.1.1.2  christos       return FALSE;
   2583  1.1.1.2  christos 
   2584  1.1.1.2  christos /* Set the sizes of the dynamic sections.  */
   2585  1.1.1.2  christos static bfd_boolean
   2586  1.1.1.4  christos elf_arc_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   2587  1.1.1.3  christos 			       struct bfd_link_info *info)
   2588  1.1.1.2  christos {
   2589  1.1.1.4  christos   bfd *dynobj;
   2590  1.1.1.4  christos   asection *s;
   2591  1.1.1.4  christos   bfd_boolean relocs_exist = FALSE;
   2592  1.1.1.4  christos   bfd_boolean reltext_exist = FALSE;
   2593  1.1.1.3  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
   2594  1.1.1.2  christos 
   2595  1.1.1.4  christos   dynobj = htab->dynobj;
   2596  1.1.1.2  christos   BFD_ASSERT (dynobj != NULL);
   2597  1.1.1.2  christos 
   2598  1.1.1.4  christos   if (htab->dynamic_sections_created)
   2599  1.1.1.2  christos     {
   2600  1.1.1.2  christos       struct elf_link_hash_entry *h;
   2601  1.1.1.2  christos 
   2602  1.1.1.3  christos       /* Set the contents of the .interp section to the
   2603  1.1.1.3  christos 	 interpreter.  */
   2604  1.1.1.4  christos       if (bfd_link_executable (info) && !info->nointerp)
   2605  1.1.1.2  christos 	{
   2606  1.1.1.2  christos 	  s = bfd_get_section_by_name (dynobj, ".interp");
   2607  1.1.1.2  christos 	  BFD_ASSERT (s != NULL);
   2608  1.1.1.3  christos 	  s->size = sizeof (ELF_DYNAMIC_INTERPRETER);
   2609  1.1.1.2  christos 	  s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
   2610  1.1.1.2  christos 	}
   2611  1.1.1.2  christos 
   2612  1.1.1.3  christos       /* Add some entries to the .dynamic section.  We fill in some of
   2613  1.1.1.3  christos 	 the values later, in elf_bfd_final_link, but we must add the
   2614  1.1.1.3  christos 	 entries now so that we know the final size of the .dynamic
   2615  1.1.1.3  christos 	 section.  Checking if the .init section is present.  We also
   2616  1.1.1.3  christos 	 create DT_INIT and DT_FINI entries if the init_str has been
   2617  1.1.1.3  christos 	 changed by the user.  */
   2618  1.1.1.4  christos       ADD_DYNAMIC_SYMBOL (info->init_function, DT_INIT);
   2619  1.1.1.4  christos       ADD_DYNAMIC_SYMBOL (info->fini_function, DT_FINI);
   2620  1.1.1.2  christos     }
   2621  1.1.1.2  christos   else
   2622  1.1.1.2  christos     {
   2623  1.1.1.3  christos       /* We may have created entries in the .rela.got section.
   2624  1.1.1.3  christos 	 However, if we are not creating the dynamic sections, we will
   2625  1.1.1.3  christos 	 not actually use these entries.  Reset the size of .rela.got,
   2626  1.1.1.3  christos 	 which will cause it to get stripped from the output file
   2627  1.1.1.3  christos 	 below.  */
   2628  1.1.1.3  christos       if (htab->srelgot != NULL)
   2629  1.1.1.3  christos 	htab->srelgot->size = 0;
   2630  1.1.1.2  christos     }
   2631  1.1.1.2  christos 
   2632  1.1.1.2  christos   for (s = dynobj->sections; s != NULL; s = s->next)
   2633  1.1.1.2  christos     {
   2634  1.1.1.3  christos       if ((s->flags & SEC_LINKER_CREATED) == 0)
   2635  1.1.1.2  christos 	continue;
   2636  1.1.1.2  christos 
   2637  1.1.1.4  christos       if (s == htab->splt
   2638  1.1.1.4  christos 	  || s == htab->sgot
   2639  1.1.1.4  christos 	  || s == htab->sgotplt
   2640  1.1.1.4  christos 	  || s == htab->sdynbss)
   2641  1.1.1.2  christos 	{
   2642  1.1.1.4  christos 	  /* Strip this section if we don't need it.  */
   2643  1.1.1.4  christos 	}
   2644  1.1.1.4  christos       else if (strncmp (s->name, ".rela", 5) == 0)
   2645  1.1.1.4  christos 	{
   2646  1.1.1.4  christos 	  if (s->size != 0 && s != htab->srelplt)
   2647  1.1.1.3  christos 	    {
   2648  1.1.1.4  christos 	      if (!reltext_exist)
   2649  1.1.1.3  christos 		{
   2650  1.1.1.4  christos 		  const char *name = s->name + 5;
   2651  1.1.1.4  christos 		  bfd *ibfd;
   2652  1.1.1.4  christos 		  for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link.next)
   2653  1.1.1.4  christos 		    if (bfd_get_flavour (ibfd) == bfd_target_elf_flavour
   2654  1.1.1.4  christos 			&& ibfd->flags & DYNAMIC)
   2655  1.1.1.4  christos 		      {
   2656  1.1.1.4  christos 			asection *target = bfd_get_section_by_name (ibfd, name);
   2657  1.1.1.4  christos 			if (target != NULL
   2658  1.1.1.4  christos 			    && elf_section_data (target)->sreloc == s
   2659  1.1.1.4  christos 			    && ((target->output_section->flags
   2660  1.1.1.4  christos 				 & (SEC_READONLY | SEC_ALLOC))
   2661  1.1.1.4  christos 				== (SEC_READONLY | SEC_ALLOC)))
   2662  1.1.1.4  christos 			  {
   2663  1.1.1.4  christos 			    reltext_exist = TRUE;
   2664  1.1.1.4  christos 			    break;
   2665  1.1.1.4  christos 			  }
   2666  1.1.1.4  christos 		      }
   2667  1.1.1.3  christos 		}
   2668  1.1.1.4  christos 	      relocs_exist = TRUE;
   2669  1.1.1.3  christos 	    }
   2670  1.1.1.2  christos 
   2671  1.1.1.3  christos 	  /* We use the reloc_count field as a counter if we need to
   2672  1.1.1.3  christos 	     copy relocs into the output file.  */
   2673  1.1.1.3  christos 	  s->reloc_count = 0;
   2674  1.1.1.2  christos 	}
   2675  1.1.1.4  christos       else
   2676  1.1.1.4  christos 	{
   2677  1.1.1.4  christos 	  /* It's not one of our sections, so don't allocate space.  */
   2678  1.1.1.4  christos 	  continue;
   2679  1.1.1.4  christos 	}
   2680  1.1.1.3  christos 
   2681  1.1.1.4  christos       if (s->size == 0)
   2682  1.1.1.4  christos 	{
   2683  1.1.1.4  christos 	  s->flags |= SEC_EXCLUDE;
   2684  1.1.1.4  christos 	  continue;
   2685  1.1.1.4  christos 	}
   2686  1.1.1.3  christos 
   2687  1.1.1.4  christos       if ((s->flags & SEC_HAS_CONTENTS) == 0)
   2688  1.1.1.4  christos 	continue;
   2689  1.1.1.3  christos 
   2690  1.1.1.4  christos       /* Allocate memory for the section contents.  */
   2691  1.1.1.4  christos       s->contents = bfd_zalloc (dynobj, s->size);
   2692  1.1.1.4  christos       if (s->contents == NULL)
   2693  1.1.1.3  christos 	return FALSE;
   2694  1.1.1.2  christos     }
   2695  1.1.1.2  christos 
   2696  1.1.1.4  christos   if (htab->dynamic_sections_created)
   2697  1.1.1.2  christos     {
   2698  1.1.1.3  christos       /* TODO: Check if this is needed.  */
   2699  1.1.1.3  christos       if (!bfd_link_pic (info))
   2700  1.1.1.3  christos 	if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
   2701  1.1.1.3  christos 		return FALSE;
   2702  1.1.1.3  christos 
   2703  1.1.1.3  christos       if (htab->splt && (htab->splt->flags & SEC_EXCLUDE) == 0)
   2704  1.1.1.2  christos 	if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
   2705  1.1.1.2  christos 	    || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
   2706  1.1.1.2  christos 	    || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
   2707  1.1.1.4  christos 	    || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
   2708  1.1.1.2  christos 	  return FALSE;
   2709  1.1.1.2  christos 
   2710  1.1.1.4  christos       if (relocs_exist)
   2711  1.1.1.2  christos 	if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
   2712  1.1.1.2  christos 	    || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
   2713  1.1.1.3  christos 	    || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
   2714  1.1.1.4  christos 					    sizeof (Elf32_External_Rela)))
   2715  1.1.1.2  christos 	  return FALSE;
   2716  1.1.1.2  christos 
   2717  1.1.1.4  christos       if (reltext_exist)
   2718  1.1.1.2  christos 	if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
   2719  1.1.1.2  christos 	  return FALSE;
   2720  1.1.1.2  christos     }
   2721  1.1.1.2  christos 
   2722  1.1.1.2  christos   return TRUE;
   2723  1.1.1.2  christos }
   2724  1.1.1.2  christos 
   2725  1.1.1.2  christos 
   2726  1.1.1.3  christos /* Classify dynamic relocs such that -z combreloc can reorder and combine
   2727  1.1.1.3  christos    them.  */
   2728  1.1.1.3  christos static enum elf_reloc_type_class
   2729  1.1.1.3  christos elf32_arc_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
   2730  1.1.1.3  christos 			    const asection *rel_sec ATTRIBUTE_UNUSED,
   2731  1.1.1.3  christos 			    const Elf_Internal_Rela *rela)
   2732  1.1.1.3  christos {
   2733  1.1.1.3  christos   switch ((int) ELF32_R_TYPE (rela->r_info))
   2734  1.1.1.3  christos     {
   2735  1.1.1.3  christos     case R_ARC_RELATIVE:
   2736  1.1.1.3  christos       return reloc_class_relative;
   2737  1.1.1.3  christos     case R_ARC_JMP_SLOT:
   2738  1.1.1.3  christos       return reloc_class_plt;
   2739  1.1.1.3  christos     case R_ARC_COPY:
   2740  1.1.1.3  christos       return reloc_class_copy;
   2741  1.1.1.3  christos     /* TODO: Needed in future to support ifunc.  */
   2742  1.1.1.3  christos     /*
   2743  1.1.1.3  christos     case R_ARC_IRELATIVE:
   2744  1.1.1.3  christos       return reloc_class_ifunc;
   2745  1.1.1.3  christos     */
   2746  1.1.1.3  christos     default:
   2747  1.1.1.3  christos       return reloc_class_normal;
   2748  1.1.1.3  christos     }
   2749  1.1.1.3  christos }
   2750  1.1.1.3  christos 
   2751  1.1.1.3  christos const struct elf_size_info arc_elf32_size_info =
   2752  1.1.1.3  christos {
   2753  1.1.1.3  christos   sizeof (Elf32_External_Ehdr),
   2754  1.1.1.3  christos   sizeof (Elf32_External_Phdr),
   2755  1.1.1.3  christos   sizeof (Elf32_External_Shdr),
   2756  1.1.1.3  christos   sizeof (Elf32_External_Rel),
   2757  1.1.1.3  christos   sizeof (Elf32_External_Rela),
   2758  1.1.1.3  christos   sizeof (Elf32_External_Sym),
   2759  1.1.1.3  christos   sizeof (Elf32_External_Dyn),
   2760  1.1.1.3  christos   sizeof (Elf_External_Note),
   2761  1.1.1.3  christos   4,
   2762  1.1.1.3  christos   1,
   2763  1.1.1.3  christos   32, 2,
   2764  1.1.1.3  christos   ELFCLASS32, EV_CURRENT,
   2765  1.1.1.3  christos   bfd_elf32_write_out_phdrs,
   2766  1.1.1.3  christos   bfd_elf32_write_shdrs_and_ehdr,
   2767  1.1.1.3  christos   bfd_elf32_checksum_contents,
   2768  1.1.1.3  christos   bfd_elf32_write_relocs,
   2769  1.1.1.3  christos   bfd_elf32_swap_symbol_in,
   2770  1.1.1.3  christos   bfd_elf32_swap_symbol_out,
   2771  1.1.1.3  christos   bfd_elf32_slurp_reloc_table,
   2772  1.1.1.3  christos   bfd_elf32_slurp_symbol_table,
   2773  1.1.1.3  christos   bfd_elf32_swap_dyn_in,
   2774  1.1.1.3  christos   bfd_elf32_swap_dyn_out,
   2775  1.1.1.3  christos   bfd_elf32_swap_reloc_in,
   2776  1.1.1.3  christos   bfd_elf32_swap_reloc_out,
   2777  1.1.1.3  christos   bfd_elf32_swap_reloca_in,
   2778  1.1.1.3  christos   bfd_elf32_swap_reloca_out
   2779  1.1.1.3  christos };
   2780  1.1.1.3  christos 
   2781  1.1.1.3  christos #define elf_backend_size_info		arc_elf32_size_info
   2782  1.1.1.3  christos 
   2783  1.1.1.3  christos /* Hook called by the linker routine which adds symbols from an object
   2784  1.1.1.3  christos    file.  */
   2785  1.1.1.3  christos 
   2786  1.1.1.3  christos static bfd_boolean
   2787  1.1.1.3  christos elf_arc_add_symbol_hook (bfd * abfd,
   2788  1.1.1.3  christos 			 struct bfd_link_info * info,
   2789  1.1.1.3  christos 			 Elf_Internal_Sym * sym,
   2790  1.1.1.3  christos 			 const char ** namep ATTRIBUTE_UNUSED,
   2791  1.1.1.3  christos 			 flagword * flagsp ATTRIBUTE_UNUSED,
   2792  1.1.1.3  christos 			 asection ** secp ATTRIBUTE_UNUSED,
   2793  1.1.1.3  christos 			 bfd_vma * valp ATTRIBUTE_UNUSED)
   2794  1.1.1.3  christos {
   2795  1.1.1.3  christos   if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
   2796  1.1.1.3  christos       && (abfd->flags & DYNAMIC) == 0
   2797  1.1.1.3  christos       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
   2798  1.1.1.3  christos     elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
   2799  1.1.1.3  christos 
   2800  1.1.1.3  christos   return TRUE;
   2801  1.1.1.3  christos }
   2802  1.1.1.3  christos 
   2803  1.1.1.4  christos /* GDB expects general purpose registers to be in section .reg.  However Linux
   2804  1.1.1.4  christos    kernel doesn't create this section and instead writes registers to NOTE
   2805  1.1.1.4  christos    section.  It is up to the binutils to create a pseudo-section .reg from the
   2806  1.1.1.4  christos    contents of NOTE.  Also BFD will read pid and signal number from NOTE.  This
   2807  1.1.1.4  christos    function relies on offsets inside elf_prstatus structure in Linux to be
   2808  1.1.1.4  christos    stable.  */
   2809  1.1.1.4  christos 
   2810  1.1.1.4  christos static bfd_boolean
   2811  1.1.1.4  christos elf32_arc_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
   2812  1.1.1.4  christos {
   2813  1.1.1.4  christos   int offset;
   2814  1.1.1.4  christos   size_t size;
   2815  1.1.1.4  christos 
   2816  1.1.1.4  christos   switch (note->descsz)
   2817  1.1.1.4  christos     {
   2818  1.1.1.4  christos     default:
   2819  1.1.1.4  christos       return FALSE;
   2820  1.1.1.4  christos 
   2821  1.1.1.4  christos     case 236: /* sizeof (struct elf_prstatus) on Linux/arc.  */
   2822  1.1.1.4  christos       /* pr_cursig */
   2823  1.1.1.4  christos       elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
   2824  1.1.1.4  christos       /* pr_pid */
   2825  1.1.1.4  christos       elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
   2826  1.1.1.4  christos       /* pr_regs */
   2827  1.1.1.4  christos       offset = 72;
   2828  1.1.1.4  christos       size = (40 * 4); /* There are 40 registers in user_regs_struct.  */
   2829  1.1.1.4  christos       break;
   2830  1.1.1.4  christos     }
   2831  1.1.1.4  christos   /* Make a ".reg/999" section.  */
   2832  1.1.1.4  christos   return _bfd_elfcore_make_pseudosection (abfd, ".reg", size,
   2833  1.1.1.4  christos 					  note->descpos + offset);
   2834  1.1.1.4  christos }
   2835  1.1.1.4  christos 
   2836  1.1.1.4  christos /* Determine whether an object attribute tag takes an integer, a
   2837  1.1.1.4  christos    string or both.  */
   2838  1.1.1.4  christos 
   2839  1.1.1.4  christos static int
   2840  1.1.1.4  christos elf32_arc_obj_attrs_arg_type (int tag)
   2841  1.1.1.4  christos {
   2842  1.1.1.4  christos   if (tag == Tag_ARC_CPU_name
   2843  1.1.1.4  christos 	   || tag == Tag_ARC_ISA_config
   2844  1.1.1.4  christos 	   || tag == Tag_ARC_ISA_apex)
   2845  1.1.1.4  christos     return ATTR_TYPE_FLAG_STR_VAL;
   2846  1.1.1.4  christos   else if (tag < (Tag_ARC_ISA_mpy_option + 1))
   2847  1.1.1.4  christos     return ATTR_TYPE_FLAG_INT_VAL;
   2848  1.1.1.4  christos   else
   2849  1.1.1.4  christos     return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;
   2850  1.1.1.4  christos }
   2851  1.1.1.4  christos 
   2852  1.1.1.4  christos /* Attribute numbers >=14 can be safely ignored.  */
   2853  1.1.1.4  christos 
   2854  1.1.1.4  christos static bfd_boolean
   2855  1.1.1.4  christos elf32_arc_obj_attrs_handle_unknown (bfd *abfd, int tag)
   2856  1.1.1.4  christos {
   2857  1.1.1.4  christos   if ((tag & 127) < (Tag_ARC_ISA_mpy_option + 1))
   2858  1.1.1.4  christos     {
   2859  1.1.1.4  christos       _bfd_error_handler
   2860  1.1.1.4  christos 	(_("%B: Unknown mandatory ARC object attribute %d."),
   2861  1.1.1.4  christos 	 abfd, tag);
   2862  1.1.1.4  christos       bfd_set_error (bfd_error_bad_value);
   2863  1.1.1.4  christos       return FALSE;
   2864  1.1.1.4  christos     }
   2865  1.1.1.4  christos   else
   2866  1.1.1.4  christos     {
   2867  1.1.1.4  christos       _bfd_error_handler
   2868  1.1.1.4  christos 	(_("Warning: %B: Unknown ARC object attribute %d."),
   2869  1.1.1.4  christos 	 abfd, tag);
   2870  1.1.1.4  christos       return TRUE;
   2871  1.1.1.4  christos     }
   2872  1.1.1.4  christos }
   2873  1.1.1.4  christos 
   2874  1.1.1.4  christos /* Handle an ARC specific section when reading an object file.  This is
   2875  1.1.1.4  christos    called when bfd_section_from_shdr finds a section with an unknown
   2876  1.1.1.4  christos    type.  */
   2877  1.1.1.4  christos 
   2878  1.1.1.4  christos static bfd_boolean
   2879  1.1.1.4  christos elf32_arc_section_from_shdr (bfd *abfd,
   2880  1.1.1.4  christos 			     Elf_Internal_Shdr * hdr,
   2881  1.1.1.4  christos 			     const char *name,
   2882  1.1.1.4  christos 			     int shindex)
   2883  1.1.1.4  christos {
   2884  1.1.1.4  christos   switch (hdr->sh_type)
   2885  1.1.1.4  christos     {
   2886  1.1.1.4  christos     case SHT_ARC_ATTRIBUTES:
   2887  1.1.1.4  christos       break;
   2888  1.1.1.4  christos 
   2889  1.1.1.4  christos     default:
   2890  1.1.1.4  christos       return FALSE;
   2891  1.1.1.4  christos     }
   2892  1.1.1.4  christos 
   2893  1.1.1.4  christos   if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
   2894  1.1.1.4  christos     return FALSE;
   2895  1.1.1.4  christos 
   2896  1.1.1.4  christos   return TRUE;
   2897  1.1.1.4  christos }
   2898  1.1.1.4  christos 
   2899  1.1.1.2  christos #define TARGET_LITTLE_SYM   arc_elf32_le_vec
   2900      1.1     skrll #define TARGET_LITTLE_NAME  "elf32-littlearc"
   2901  1.1.1.2  christos #define TARGET_BIG_SYM	    arc_elf32_be_vec
   2902  1.1.1.2  christos #define TARGET_BIG_NAME     "elf32-bigarc"
   2903  1.1.1.2  christos #define ELF_ARCH	    bfd_arch_arc
   2904  1.1.1.4  christos #define ELF_TARGET_ID	    ARC_ELF_DATA
   2905  1.1.1.2  christos #define ELF_MACHINE_CODE    EM_ARC_COMPACT
   2906  1.1.1.2  christos #define ELF_MACHINE_ALT1    EM_ARC_COMPACT2
   2907  1.1.1.2  christos #define ELF_MAXPAGESIZE     0x2000
   2908  1.1.1.2  christos 
   2909  1.1.1.3  christos #define bfd_elf32_bfd_link_hash_table_create	arc_elf_link_hash_table_create
   2910  1.1.1.3  christos 
   2911  1.1.1.3  christos #define bfd_elf32_bfd_merge_private_bfd_data    arc_elf_merge_private_bfd_data
   2912  1.1.1.3  christos #define bfd_elf32_bfd_reloc_type_lookup		arc_elf32_bfd_reloc_type_lookup
   2913  1.1.1.3  christos #define bfd_elf32_bfd_set_private_flags		arc_elf_set_private_flags
   2914  1.1.1.3  christos #define bfd_elf32_bfd_print_private_bfd_data    arc_elf_print_private_bfd_data
   2915  1.1.1.3  christos #define bfd_elf32_bfd_copy_private_bfd_data     arc_elf_copy_private_bfd_data
   2916  1.1.1.3  christos 
   2917  1.1.1.2  christos #define elf_info_to_howto_rel		     arc_info_to_howto_rel
   2918  1.1.1.2  christos #define elf_backend_object_p		     arc_elf_object_p
   2919  1.1.1.2  christos #define elf_backend_final_write_processing   arc_elf_final_write_processing
   2920  1.1.1.2  christos 
   2921  1.1.1.2  christos #define elf_backend_relocate_section	     elf_arc_relocate_section
   2922  1.1.1.2  christos #define elf_backend_check_relocs	     elf_arc_check_relocs
   2923  1.1.1.2  christos #define elf_backend_create_dynamic_sections  _bfd_elf_create_dynamic_sections
   2924  1.1.1.2  christos 
   2925  1.1.1.3  christos #define elf_backend_reloc_type_class		elf32_arc_reloc_type_class
   2926  1.1.1.3  christos 
   2927  1.1.1.2  christos #define elf_backend_adjust_dynamic_symbol    elf_arc_adjust_dynamic_symbol
   2928  1.1.1.2  christos #define elf_backend_finish_dynamic_symbol    elf_arc_finish_dynamic_symbol
   2929  1.1.1.2  christos 
   2930  1.1.1.2  christos #define elf_backend_finish_dynamic_sections  elf_arc_finish_dynamic_sections
   2931  1.1.1.2  christos #define elf_backend_size_dynamic_sections    elf_arc_size_dynamic_sections
   2932  1.1.1.4  christos #define elf_backend_add_symbol_hook	     elf_arc_add_symbol_hook
   2933  1.1.1.2  christos 
   2934  1.1.1.2  christos #define elf_backend_can_gc_sections	1
   2935  1.1.1.2  christos #define elf_backend_want_got_plt	1
   2936  1.1.1.2  christos #define elf_backend_plt_readonly	1
   2937  1.1.1.3  christos #define elf_backend_rela_plts_and_copies_p 1
   2938  1.1.1.2  christos #define elf_backend_want_plt_sym	0
   2939  1.1.1.2  christos #define elf_backend_got_header_size	12
   2940  1.1.1.4  christos #define elf_backend_dtrel_excludes_plt	1
   2941  1.1.1.2  christos 
   2942  1.1.1.2  christos #define elf_backend_may_use_rel_p	0
   2943  1.1.1.2  christos #define elf_backend_may_use_rela_p	1
   2944  1.1.1.2  christos #define elf_backend_default_use_rela_p	1
   2945      1.1     skrll 
   2946  1.1.1.4  christos #define elf_backend_grok_prstatus elf32_arc_grok_prstatus
   2947  1.1.1.4  christos 
   2948  1.1.1.3  christos #define elf_backend_default_execstack	0
   2949  1.1.1.3  christos 
   2950  1.1.1.4  christos #undef  elf_backend_obj_attrs_vendor
   2951  1.1.1.4  christos #define elf_backend_obj_attrs_vendor		"ARC"
   2952  1.1.1.4  christos #undef  elf_backend_obj_attrs_section
   2953  1.1.1.4  christos #define elf_backend_obj_attrs_section		".ARC.attributes"
   2954  1.1.1.4  christos #undef  elf_backend_obj_attrs_arg_type
   2955  1.1.1.4  christos #define elf_backend_obj_attrs_arg_type		elf32_arc_obj_attrs_arg_type
   2956  1.1.1.4  christos #undef  elf_backend_obj_attrs_section_type
   2957  1.1.1.4  christos #define elf_backend_obj_attrs_section_type	SHT_ARC_ATTRIBUTES
   2958  1.1.1.4  christos #define elf_backend_obj_attrs_handle_unknown	elf32_arc_obj_attrs_handle_unknown
   2959  1.1.1.4  christos 
   2960  1.1.1.4  christos #define elf_backend_section_from_shdr		elf32_arc_section_from_shdr
   2961  1.1.1.4  christos 
   2962      1.1     skrll #include "elf32-target.h"
   2963