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