Home | History | Annotate | Line # | Download | only in bfd
elf-m10300.c revision 1.1.1.9
      1      1.1  christos /* Matsushita 10300 specific support for 32-bit ELF
      2  1.1.1.9  christos    Copyright (C) 1996-2020 Free Software Foundation, Inc.
      3      1.1  christos 
      4      1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      5      1.1  christos 
      6      1.1  christos    This program is free software; you can redistribute it and/or modify
      7      1.1  christos    it under the terms of the GNU General Public License as published by
      8      1.1  christos    the Free Software Foundation; either version 3 of the License, or
      9      1.1  christos    (at your option) any later version.
     10      1.1  christos 
     11      1.1  christos    This program is distributed in the hope that it will be useful,
     12      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14      1.1  christos    GNU General Public License for more details.
     15      1.1  christos 
     16      1.1  christos    You should have received a copy of the GNU General Public License
     17      1.1  christos    along with this program; if not, write to the Free Software
     18      1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     19      1.1  christos    MA 02110-1301, USA.  */
     20      1.1  christos 
     21      1.1  christos #include "sysdep.h"
     22      1.1  christos #include "bfd.h"
     23      1.1  christos #include "libbfd.h"
     24      1.1  christos #include "elf-bfd.h"
     25      1.1  christos #include "elf/mn10300.h"
     26      1.1  christos #include "libiberty.h"
     27      1.1  christos 
     28      1.1  christos /* The mn10300 linker needs to keep track of the number of relocs that
     29      1.1  christos    it decides to copy in check_relocs for each symbol.  This is so
     30      1.1  christos    that it can discard PC relative relocs if it doesn't need them when
     31      1.1  christos    linking with -Bsymbolic.  We store the information in a field
     32      1.1  christos    extending the regular ELF linker hash table.  */
     33      1.1  christos 
     34      1.1  christos struct elf32_mn10300_link_hash_entry
     35      1.1  christos {
     36      1.1  christos   /* The basic elf link hash table entry.  */
     37      1.1  christos   struct elf_link_hash_entry root;
     38      1.1  christos 
     39      1.1  christos   /* For function symbols, the number of times this function is
     40      1.1  christos      called directly (ie by name).  */
     41      1.1  christos   unsigned int direct_calls;
     42      1.1  christos 
     43      1.1  christos   /* For function symbols, the size of this function's stack
     44      1.1  christos      (if <= 255 bytes).  We stuff this into "call" instructions
     45      1.1  christos      to this target when it's valid and profitable to do so.
     46      1.1  christos 
     47      1.1  christos      This does not include stack allocated by movm!  */
     48      1.1  christos   unsigned char stack_size;
     49      1.1  christos 
     50      1.1  christos   /* For function symbols, arguments (if any) for movm instruction
     51      1.1  christos      in the prologue.  We stuff this value into "call" instructions
     52      1.1  christos      to the target when it's valid and profitable to do so.  */
     53      1.1  christos   unsigned char movm_args;
     54      1.1  christos 
     55      1.1  christos   /* For function symbols, the amount of stack space that would be allocated
     56      1.1  christos      by the movm instruction.  This is redundant with movm_args, but we
     57      1.1  christos      add it to the hash table to avoid computing it over and over.  */
     58      1.1  christos   unsigned char movm_stack_size;
     59      1.1  christos 
     60      1.1  christos /* When set, convert all "call" instructions to this target into "calls"
     61      1.1  christos    instructions.  */
     62      1.1  christos #define MN10300_CONVERT_CALL_TO_CALLS 0x1
     63      1.1  christos 
     64      1.1  christos /* Used to mark functions which have had redundant parts of their
     65      1.1  christos    prologue deleted.  */
     66      1.1  christos #define MN10300_DELETED_PROLOGUE_BYTES 0x2
     67      1.1  christos   unsigned char flags;
     68      1.1  christos 
     69      1.1  christos   /* Calculated value.  */
     70      1.1  christos   bfd_vma value;
     71  1.1.1.2  christos 
     72  1.1.1.2  christos #define GOT_UNKNOWN	0
     73  1.1.1.2  christos #define GOT_NORMAL	1
     74  1.1.1.2  christos #define GOT_TLS_GD	2
     75  1.1.1.2  christos #define GOT_TLS_LD	3
     76  1.1.1.2  christos #define GOT_TLS_IE	4
     77  1.1.1.2  christos   /* Used to distinguish GOT entries for TLS types from normal GOT entries.  */
     78  1.1.1.2  christos   unsigned char tls_type;
     79      1.1  christos };
     80      1.1  christos 
     81      1.1  christos /* We derive a hash table from the main elf linker hash table so
     82      1.1  christos    we can store state variables and a secondary hash table without
     83      1.1  christos    resorting to global variables.  */
     84      1.1  christos struct elf32_mn10300_link_hash_table
     85      1.1  christos {
     86      1.1  christos   /* The main hash table.  */
     87      1.1  christos   struct elf_link_hash_table root;
     88      1.1  christos 
     89      1.1  christos   /* A hash table for static functions.  We could derive a new hash table
     90      1.1  christos      instead of using the full elf32_mn10300_link_hash_table if we wanted
     91      1.1  christos      to save some memory.  */
     92      1.1  christos   struct elf32_mn10300_link_hash_table *static_hash_table;
     93      1.1  christos 
     94      1.1  christos   /* Random linker state flags.  */
     95      1.1  christos #define MN10300_HASH_ENTRIES_INITIALIZED 0x1
     96      1.1  christos   char flags;
     97  1.1.1.2  christos   struct
     98  1.1.1.2  christos   {
     99  1.1.1.2  christos     bfd_signed_vma  refcount;
    100  1.1.1.8  christos     bfd_vma	    offset;
    101  1.1.1.8  christos     char	    got_allocated;
    102  1.1.1.8  christos     char	    rel_emitted;
    103  1.1.1.2  christos   } tls_ldm_got;
    104  1.1.1.2  christos };
    105  1.1.1.2  christos 
    106  1.1.1.2  christos #define elf_mn10300_hash_entry(ent) ((struct elf32_mn10300_link_hash_entry *)(ent))
    107  1.1.1.2  christos 
    108  1.1.1.2  christos struct elf_mn10300_obj_tdata
    109  1.1.1.2  christos {
    110  1.1.1.2  christos   struct elf_obj_tdata root;
    111  1.1.1.2  christos 
    112  1.1.1.2  christos   /* tls_type for each local got entry.  */
    113  1.1.1.2  christos   char * local_got_tls_type;
    114      1.1  christos };
    115      1.1  christos 
    116  1.1.1.2  christos #define elf_mn10300_tdata(abfd) \
    117  1.1.1.2  christos   ((struct elf_mn10300_obj_tdata *) (abfd)->tdata.any)
    118  1.1.1.2  christos 
    119  1.1.1.2  christos #define elf_mn10300_local_got_tls_type(abfd) \
    120  1.1.1.2  christos   (elf_mn10300_tdata (abfd)->local_got_tls_type)
    121  1.1.1.2  christos 
    122      1.1  christos #ifndef streq
    123      1.1  christos #define streq(a, b) (strcmp ((a),(b)) == 0)
    124      1.1  christos #endif
    125      1.1  christos 
    126      1.1  christos /* For MN10300 linker hash table.  */
    127      1.1  christos 
    128      1.1  christos /* Get the MN10300 ELF linker hash table from a link_info structure.  */
    129      1.1  christos 
    130      1.1  christos #define elf32_mn10300_hash_table(p) \
    131  1.1.1.9  christos   ((is_elf_hash_table ((p)->hash)					\
    132  1.1.1.9  christos     && elf_hash_table_id (elf_hash_table (p)) == MN10300_ELF_DATA)	\
    133  1.1.1.9  christos    ? (struct elf32_mn10300_link_hash_table *) (p)->hash : NULL)
    134      1.1  christos 
    135      1.1  christos #define elf32_mn10300_link_hash_traverse(table, func, info)		\
    136      1.1  christos   (elf_link_hash_traverse						\
    137      1.1  christos    (&(table)->root,							\
    138      1.1  christos     (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func),	\
    139      1.1  christos     (info)))
    140      1.1  christos 
    141      1.1  christos static reloc_howto_type elf_mn10300_howto_table[] =
    142      1.1  christos {
    143      1.1  christos   /* Dummy relocation.  Does nothing.  */
    144      1.1  christos   HOWTO (R_MN10300_NONE,
    145      1.1  christos 	 0,
    146  1.1.1.5  christos 	 3,
    147  1.1.1.5  christos 	 0,
    148      1.1  christos 	 FALSE,
    149      1.1  christos 	 0,
    150  1.1.1.5  christos 	 complain_overflow_dont,
    151      1.1  christos 	 bfd_elf_generic_reloc,
    152      1.1  christos 	 "R_MN10300_NONE",
    153      1.1  christos 	 FALSE,
    154      1.1  christos 	 0,
    155      1.1  christos 	 0,
    156      1.1  christos 	 FALSE),
    157      1.1  christos   /* Standard 32 bit reloc.  */
    158      1.1  christos   HOWTO (R_MN10300_32,
    159      1.1  christos 	 0,
    160      1.1  christos 	 2,
    161      1.1  christos 	 32,
    162      1.1  christos 	 FALSE,
    163      1.1  christos 	 0,
    164      1.1  christos 	 complain_overflow_bitfield,
    165      1.1  christos 	 bfd_elf_generic_reloc,
    166      1.1  christos 	 "R_MN10300_32",
    167      1.1  christos 	 FALSE,
    168      1.1  christos 	 0xffffffff,
    169      1.1  christos 	 0xffffffff,
    170      1.1  christos 	 FALSE),
    171      1.1  christos   /* Standard 16 bit reloc.  */
    172      1.1  christos   HOWTO (R_MN10300_16,
    173      1.1  christos 	 0,
    174      1.1  christos 	 1,
    175      1.1  christos 	 16,
    176      1.1  christos 	 FALSE,
    177      1.1  christos 	 0,
    178      1.1  christos 	 complain_overflow_bitfield,
    179      1.1  christos 	 bfd_elf_generic_reloc,
    180      1.1  christos 	 "R_MN10300_16",
    181      1.1  christos 	 FALSE,
    182      1.1  christos 	 0xffff,
    183      1.1  christos 	 0xffff,
    184      1.1  christos 	 FALSE),
    185      1.1  christos   /* Standard 8 bit reloc.  */
    186      1.1  christos   HOWTO (R_MN10300_8,
    187      1.1  christos 	 0,
    188      1.1  christos 	 0,
    189      1.1  christos 	 8,
    190      1.1  christos 	 FALSE,
    191      1.1  christos 	 0,
    192      1.1  christos 	 complain_overflow_bitfield,
    193      1.1  christos 	 bfd_elf_generic_reloc,
    194      1.1  christos 	 "R_MN10300_8",
    195      1.1  christos 	 FALSE,
    196      1.1  christos 	 0xff,
    197      1.1  christos 	 0xff,
    198      1.1  christos 	 FALSE),
    199      1.1  christos   /* Standard 32bit pc-relative reloc.  */
    200      1.1  christos   HOWTO (R_MN10300_PCREL32,
    201      1.1  christos 	 0,
    202      1.1  christos 	 2,
    203      1.1  christos 	 32,
    204      1.1  christos 	 TRUE,
    205      1.1  christos 	 0,
    206      1.1  christos 	 complain_overflow_bitfield,
    207      1.1  christos 	 bfd_elf_generic_reloc,
    208      1.1  christos 	 "R_MN10300_PCREL32",
    209      1.1  christos 	 FALSE,
    210      1.1  christos 	 0xffffffff,
    211      1.1  christos 	 0xffffffff,
    212      1.1  christos 	 TRUE),
    213      1.1  christos   /* Standard 16bit pc-relative reloc.  */
    214      1.1  christos   HOWTO (R_MN10300_PCREL16,
    215      1.1  christos 	 0,
    216      1.1  christos 	 1,
    217      1.1  christos 	 16,
    218      1.1  christos 	 TRUE,
    219      1.1  christos 	 0,
    220      1.1  christos 	 complain_overflow_bitfield,
    221      1.1  christos 	 bfd_elf_generic_reloc,
    222      1.1  christos 	 "R_MN10300_PCREL16",
    223      1.1  christos 	 FALSE,
    224      1.1  christos 	 0xffff,
    225      1.1  christos 	 0xffff,
    226      1.1  christos 	 TRUE),
    227      1.1  christos   /* Standard 8 pc-relative reloc.  */
    228      1.1  christos   HOWTO (R_MN10300_PCREL8,
    229      1.1  christos 	 0,
    230      1.1  christos 	 0,
    231      1.1  christos 	 8,
    232      1.1  christos 	 TRUE,
    233      1.1  christos 	 0,
    234      1.1  christos 	 complain_overflow_bitfield,
    235      1.1  christos 	 bfd_elf_generic_reloc,
    236      1.1  christos 	 "R_MN10300_PCREL8",
    237      1.1  christos 	 FALSE,
    238      1.1  christos 	 0xff,
    239      1.1  christos 	 0xff,
    240      1.1  christos 	 TRUE),
    241      1.1  christos 
    242      1.1  christos   /* GNU extension to record C++ vtable hierarchy.  */
    243      1.1  christos   HOWTO (R_MN10300_GNU_VTINHERIT, /* type */
    244      1.1  christos 	 0,			/* rightshift */
    245      1.1  christos 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    246      1.1  christos 	 0,			/* bitsize */
    247      1.1  christos 	 FALSE,			/* pc_relative */
    248      1.1  christos 	 0,			/* bitpos */
    249      1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    250      1.1  christos 	 NULL,			/* special_function */
    251      1.1  christos 	 "R_MN10300_GNU_VTINHERIT", /* name */
    252      1.1  christos 	 FALSE,			/* partial_inplace */
    253      1.1  christos 	 0,			/* src_mask */
    254      1.1  christos 	 0,			/* dst_mask */
    255      1.1  christos 	 FALSE),		/* pcrel_offset */
    256      1.1  christos 
    257      1.1  christos   /* GNU extension to record C++ vtable member usage */
    258      1.1  christos   HOWTO (R_MN10300_GNU_VTENTRY,	/* type */
    259      1.1  christos 	 0,			/* rightshift */
    260      1.1  christos 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    261      1.1  christos 	 0,			/* bitsize */
    262      1.1  christos 	 FALSE,			/* pc_relative */
    263      1.1  christos 	 0,			/* bitpos */
    264      1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    265      1.1  christos 	 NULL,			/* special_function */
    266      1.1  christos 	 "R_MN10300_GNU_VTENTRY", /* name */
    267      1.1  christos 	 FALSE,			/* partial_inplace */
    268      1.1  christos 	 0,			/* src_mask */
    269      1.1  christos 	 0,			/* dst_mask */
    270      1.1  christos 	 FALSE),		/* pcrel_offset */
    271      1.1  christos 
    272      1.1  christos   /* Standard 24 bit reloc.  */
    273      1.1  christos   HOWTO (R_MN10300_24,
    274      1.1  christos 	 0,
    275      1.1  christos 	 2,
    276      1.1  christos 	 24,
    277      1.1  christos 	 FALSE,
    278      1.1  christos 	 0,
    279      1.1  christos 	 complain_overflow_bitfield,
    280      1.1  christos 	 bfd_elf_generic_reloc,
    281      1.1  christos 	 "R_MN10300_24",
    282      1.1  christos 	 FALSE,
    283      1.1  christos 	 0xffffff,
    284      1.1  christos 	 0xffffff,
    285      1.1  christos 	 FALSE),
    286      1.1  christos   HOWTO (R_MN10300_GOTPC32,	/* type */
    287      1.1  christos 	 0,			/* rightshift */
    288      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    289      1.1  christos 	 32,			/* bitsize */
    290      1.1  christos 	 TRUE,			/* pc_relative */
    291      1.1  christos 	 0,			/* bitpos */
    292      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    293      1.1  christos 	 bfd_elf_generic_reloc, /* */
    294      1.1  christos 	 "R_MN10300_GOTPC32",	/* name */
    295      1.1  christos 	 FALSE,			/* partial_inplace */
    296      1.1  christos 	 0xffffffff,		/* src_mask */
    297      1.1  christos 	 0xffffffff,		/* dst_mask */
    298      1.1  christos 	 TRUE),			/* pcrel_offset */
    299      1.1  christos 
    300      1.1  christos   HOWTO (R_MN10300_GOTPC16,	/* type */
    301      1.1  christos 	 0,			/* rightshift */
    302      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    303      1.1  christos 	 16,			/* bitsize */
    304      1.1  christos 	 TRUE,			/* pc_relative */
    305      1.1  christos 	 0,			/* bitpos */
    306      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    307      1.1  christos 	 bfd_elf_generic_reloc, /* */
    308      1.1  christos 	 "R_MN10300_GOTPC16",	/* name */
    309      1.1  christos 	 FALSE,			/* partial_inplace */
    310      1.1  christos 	 0xffff,		/* src_mask */
    311      1.1  christos 	 0xffff,		/* dst_mask */
    312      1.1  christos 	 TRUE),			/* pcrel_offset */
    313      1.1  christos 
    314      1.1  christos   HOWTO (R_MN10300_GOTOFF32,	/* type */
    315      1.1  christos 	 0,			/* rightshift */
    316      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    317      1.1  christos 	 32,			/* bitsize */
    318      1.1  christos 	 FALSE,			/* pc_relative */
    319      1.1  christos 	 0,			/* bitpos */
    320      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    321      1.1  christos 	 bfd_elf_generic_reloc, /* */
    322      1.1  christos 	 "R_MN10300_GOTOFF32",	/* name */
    323      1.1  christos 	 FALSE,			/* partial_inplace */
    324      1.1  christos 	 0xffffffff,		/* src_mask */
    325      1.1  christos 	 0xffffffff,		/* dst_mask */
    326      1.1  christos 	 FALSE),		/* pcrel_offset */
    327      1.1  christos 
    328      1.1  christos   HOWTO (R_MN10300_GOTOFF24,	/* type */
    329      1.1  christos 	 0,			/* rightshift */
    330      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    331      1.1  christos 	 24,			/* bitsize */
    332      1.1  christos 	 FALSE,			/* pc_relative */
    333      1.1  christos 	 0,			/* bitpos */
    334      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    335      1.1  christos 	 bfd_elf_generic_reloc, /* */
    336      1.1  christos 	 "R_MN10300_GOTOFF24",	/* name */
    337      1.1  christos 	 FALSE,			/* partial_inplace */
    338      1.1  christos 	 0xffffff,		/* src_mask */
    339      1.1  christos 	 0xffffff,		/* dst_mask */
    340      1.1  christos 	 FALSE),		/* pcrel_offset */
    341      1.1  christos 
    342      1.1  christos   HOWTO (R_MN10300_GOTOFF16,	/* type */
    343      1.1  christos 	 0,			/* rightshift */
    344      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    345      1.1  christos 	 16,			/* bitsize */
    346      1.1  christos 	 FALSE,			/* pc_relative */
    347      1.1  christos 	 0,			/* bitpos */
    348      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    349      1.1  christos 	 bfd_elf_generic_reloc, /* */
    350      1.1  christos 	 "R_MN10300_GOTOFF16",	/* name */
    351      1.1  christos 	 FALSE,			/* partial_inplace */
    352      1.1  christos 	 0xffff,		/* src_mask */
    353      1.1  christos 	 0xffff,		/* dst_mask */
    354      1.1  christos 	 FALSE),		/* pcrel_offset */
    355      1.1  christos 
    356      1.1  christos   HOWTO (R_MN10300_PLT32,	/* type */
    357      1.1  christos 	 0,			/* rightshift */
    358      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    359      1.1  christos 	 32,			/* bitsize */
    360      1.1  christos 	 TRUE,			/* pc_relative */
    361      1.1  christos 	 0,			/* bitpos */
    362      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    363      1.1  christos 	 bfd_elf_generic_reloc, /* */
    364      1.1  christos 	 "R_MN10300_PLT32",	/* name */
    365      1.1  christos 	 FALSE,			/* partial_inplace */
    366      1.1  christos 	 0xffffffff,		/* src_mask */
    367      1.1  christos 	 0xffffffff,		/* dst_mask */
    368      1.1  christos 	 TRUE),			/* pcrel_offset */
    369      1.1  christos 
    370      1.1  christos   HOWTO (R_MN10300_PLT16,	/* type */
    371      1.1  christos 	 0,			/* rightshift */
    372      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    373      1.1  christos 	 16,			/* bitsize */
    374      1.1  christos 	 TRUE,			/* pc_relative */
    375      1.1  christos 	 0,			/* bitpos */
    376      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    377      1.1  christos 	 bfd_elf_generic_reloc, /* */
    378      1.1  christos 	 "R_MN10300_PLT16",	/* name */
    379      1.1  christos 	 FALSE,			/* partial_inplace */
    380      1.1  christos 	 0xffff,		/* src_mask */
    381      1.1  christos 	 0xffff,		/* dst_mask */
    382      1.1  christos 	 TRUE),			/* pcrel_offset */
    383      1.1  christos 
    384      1.1  christos   HOWTO (R_MN10300_GOT32,	/* type */
    385      1.1  christos 	 0,			/* rightshift */
    386      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    387      1.1  christos 	 32,			/* bitsize */
    388      1.1  christos 	 FALSE,			/* pc_relative */
    389      1.1  christos 	 0,			/* bitpos */
    390      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    391      1.1  christos 	 bfd_elf_generic_reloc, /* */
    392      1.1  christos 	 "R_MN10300_GOT32",	/* name */
    393      1.1  christos 	 FALSE,			/* partial_inplace */
    394      1.1  christos 	 0xffffffff,		/* src_mask */
    395      1.1  christos 	 0xffffffff,		/* dst_mask */
    396      1.1  christos 	 FALSE),		/* pcrel_offset */
    397      1.1  christos 
    398      1.1  christos   HOWTO (R_MN10300_GOT24,	/* type */
    399      1.1  christos 	 0,			/* rightshift */
    400      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    401      1.1  christos 	 24,			/* bitsize */
    402      1.1  christos 	 FALSE,			/* pc_relative */
    403      1.1  christos 	 0,			/* bitpos */
    404      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    405      1.1  christos 	 bfd_elf_generic_reloc, /* */
    406      1.1  christos 	 "R_MN10300_GOT24",	/* name */
    407      1.1  christos 	 FALSE,			/* partial_inplace */
    408      1.1  christos 	 0xffffffff,		/* src_mask */
    409      1.1  christos 	 0xffffffff,		/* dst_mask */
    410      1.1  christos 	 FALSE),		/* pcrel_offset */
    411      1.1  christos 
    412      1.1  christos   HOWTO (R_MN10300_GOT16,	/* type */
    413      1.1  christos 	 0,			/* rightshift */
    414      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    415      1.1  christos 	 16,			/* bitsize */
    416      1.1  christos 	 FALSE,			/* pc_relative */
    417      1.1  christos 	 0,			/* bitpos */
    418      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    419      1.1  christos 	 bfd_elf_generic_reloc, /* */
    420      1.1  christos 	 "R_MN10300_GOT16",	/* name */
    421      1.1  christos 	 FALSE,			/* partial_inplace */
    422      1.1  christos 	 0xffffffff,		/* src_mask */
    423      1.1  christos 	 0xffffffff,		/* dst_mask */
    424      1.1  christos 	 FALSE),		/* pcrel_offset */
    425      1.1  christos 
    426      1.1  christos   HOWTO (R_MN10300_COPY,	/* type */
    427      1.1  christos 	 0,			/* rightshift */
    428      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    429      1.1  christos 	 32,			/* bitsize */
    430      1.1  christos 	 FALSE,			/* pc_relative */
    431      1.1  christos 	 0,			/* bitpos */
    432      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    433      1.1  christos 	 bfd_elf_generic_reloc, /* */
    434      1.1  christos 	 "R_MN10300_COPY",		/* name */
    435      1.1  christos 	 FALSE,			/* partial_inplace */
    436      1.1  christos 	 0xffffffff,		/* src_mask */
    437      1.1  christos 	 0xffffffff,		/* dst_mask */
    438      1.1  christos 	 FALSE),		/* pcrel_offset */
    439      1.1  christos 
    440      1.1  christos   HOWTO (R_MN10300_GLOB_DAT,	/* type */
    441      1.1  christos 	 0,			/* rightshift */
    442      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    443      1.1  christos 	 32,			/* bitsize */
    444      1.1  christos 	 FALSE,			/* pc_relative */
    445      1.1  christos 	 0,			/* bitpos */
    446      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    447      1.1  christos 	 bfd_elf_generic_reloc, /* */
    448      1.1  christos 	 "R_MN10300_GLOB_DAT",	/* name */
    449      1.1  christos 	 FALSE,			/* partial_inplace */
    450      1.1  christos 	 0xffffffff,		/* src_mask */
    451      1.1  christos 	 0xffffffff,		/* dst_mask */
    452      1.1  christos 	 FALSE),		/* pcrel_offset */
    453      1.1  christos 
    454      1.1  christos   HOWTO (R_MN10300_JMP_SLOT,	/* type */
    455      1.1  christos 	 0,			/* rightshift */
    456      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    457      1.1  christos 	 32,			/* bitsize */
    458      1.1  christos 	 FALSE,			/* pc_relative */
    459      1.1  christos 	 0,			/* bitpos */
    460      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    461      1.1  christos 	 bfd_elf_generic_reloc, /* */
    462      1.1  christos 	 "R_MN10300_JMP_SLOT",	/* name */
    463      1.1  christos 	 FALSE,			/* partial_inplace */
    464      1.1  christos 	 0xffffffff,		/* src_mask */
    465      1.1  christos 	 0xffffffff,		/* dst_mask */
    466      1.1  christos 	 FALSE),		/* pcrel_offset */
    467      1.1  christos 
    468      1.1  christos   HOWTO (R_MN10300_RELATIVE,	/* type */
    469      1.1  christos 	 0,			/* rightshift */
    470      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    471      1.1  christos 	 32,			/* bitsize */
    472      1.1  christos 	 FALSE,			/* pc_relative */
    473      1.1  christos 	 0,			/* bitpos */
    474      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    475      1.1  christos 	 bfd_elf_generic_reloc, /* */
    476      1.1  christos 	 "R_MN10300_RELATIVE",	/* name */
    477      1.1  christos 	 FALSE,			/* partial_inplace */
    478      1.1  christos 	 0xffffffff,		/* src_mask */
    479      1.1  christos 	 0xffffffff,		/* dst_mask */
    480      1.1  christos 	 FALSE),		/* pcrel_offset */
    481      1.1  christos 
    482  1.1.1.2  christos   HOWTO (R_MN10300_TLS_GD,	/* type */
    483  1.1.1.2  christos 	 0,			/* rightshift */
    484  1.1.1.2  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    485  1.1.1.2  christos 	 32,			/* bitsize */
    486  1.1.1.2  christos 	 FALSE,			/* pc_relative */
    487  1.1.1.2  christos 	 0,			/* bitpos */
    488  1.1.1.2  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    489  1.1.1.2  christos 	 bfd_elf_generic_reloc, /* */
    490  1.1.1.2  christos 	 "R_MN10300_TLS_GD",	/* name */
    491  1.1.1.2  christos 	 FALSE,			/* partial_inplace */
    492  1.1.1.2  christos 	 0xffffffff,		/* src_mask */
    493  1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
    494  1.1.1.2  christos 	 FALSE),		/* pcrel_offset */
    495  1.1.1.2  christos 
    496  1.1.1.2  christos   HOWTO (R_MN10300_TLS_LD,	/* type */
    497  1.1.1.2  christos 	 0,			/* rightshift */
    498  1.1.1.2  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    499  1.1.1.2  christos 	 32,			/* bitsize */
    500  1.1.1.2  christos 	 FALSE,			/* pc_relative */
    501  1.1.1.2  christos 	 0,			/* bitpos */
    502  1.1.1.2  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    503  1.1.1.2  christos 	 bfd_elf_generic_reloc, /* */
    504  1.1.1.2  christos 	 "R_MN10300_TLS_LD",	/* name */
    505  1.1.1.2  christos 	 FALSE,			/* partial_inplace */
    506  1.1.1.2  christos 	 0xffffffff,		/* src_mask */
    507  1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
    508  1.1.1.2  christos 	 FALSE),		/* pcrel_offset */
    509  1.1.1.2  christos 
    510  1.1.1.2  christos   HOWTO (R_MN10300_TLS_LDO,	/* type */
    511  1.1.1.2  christos 	 0,			/* rightshift */
    512  1.1.1.2  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    513  1.1.1.2  christos 	 32,			/* bitsize */
    514  1.1.1.2  christos 	 FALSE,			/* pc_relative */
    515  1.1.1.2  christos 	 0,			/* bitpos */
    516  1.1.1.2  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    517  1.1.1.2  christos 	 bfd_elf_generic_reloc, /* */
    518  1.1.1.2  christos 	 "R_MN10300_TLS_LDO",	/* name */
    519  1.1.1.2  christos 	 FALSE,			/* partial_inplace */
    520  1.1.1.2  christos 	 0xffffffff,		/* src_mask */
    521  1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
    522  1.1.1.2  christos 	 FALSE),		/* pcrel_offset */
    523  1.1.1.2  christos 
    524  1.1.1.2  christos   HOWTO (R_MN10300_TLS_GOTIE,	/* type */
    525  1.1.1.2  christos 	 0,			/* rightshift */
    526  1.1.1.2  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    527  1.1.1.2  christos 	 32,			/* bitsize */
    528  1.1.1.2  christos 	 FALSE,			/* pc_relative */
    529  1.1.1.2  christos 	 0,			/* bitpos */
    530  1.1.1.2  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    531  1.1.1.2  christos 	 bfd_elf_generic_reloc, /* */
    532  1.1.1.2  christos 	 "R_MN10300_TLS_GOTIE",	/* name */
    533  1.1.1.2  christos 	 FALSE,			/* partial_inplace */
    534  1.1.1.2  christos 	 0xffffffff,		/* src_mask */
    535  1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
    536  1.1.1.2  christos 	 FALSE),		/* pcrel_offset */
    537  1.1.1.2  christos 
    538  1.1.1.2  christos   HOWTO (R_MN10300_TLS_IE,	/* type */
    539  1.1.1.2  christos 	 0,			/* rightshift */
    540  1.1.1.2  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    541  1.1.1.2  christos 	 32,			/* bitsize */
    542  1.1.1.2  christos 	 FALSE,			/* pc_relative */
    543  1.1.1.2  christos 	 0,			/* bitpos */
    544  1.1.1.2  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    545  1.1.1.2  christos 	 bfd_elf_generic_reloc, /* */
    546  1.1.1.2  christos 	 "R_MN10300_TLS_IE",	/* name */
    547  1.1.1.2  christos 	 FALSE,			/* partial_inplace */
    548  1.1.1.2  christos 	 0xffffffff,		/* src_mask */
    549  1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
    550  1.1.1.2  christos 	 FALSE),		/* pcrel_offset */
    551  1.1.1.2  christos 
    552  1.1.1.2  christos   HOWTO (R_MN10300_TLS_LE,	/* type */
    553  1.1.1.2  christos 	 0,			/* rightshift */
    554  1.1.1.2  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    555  1.1.1.2  christos 	 32,			/* bitsize */
    556  1.1.1.2  christos 	 FALSE,			/* pc_relative */
    557  1.1.1.2  christos 	 0,			/* bitpos */
    558  1.1.1.2  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    559  1.1.1.2  christos 	 bfd_elf_generic_reloc, /* */
    560  1.1.1.2  christos 	 "R_MN10300_TLS_LE",	/* name */
    561  1.1.1.2  christos 	 FALSE,			/* partial_inplace */
    562  1.1.1.2  christos 	 0xffffffff,		/* src_mask */
    563  1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
    564  1.1.1.2  christos 	 FALSE),		/* pcrel_offset */
    565  1.1.1.2  christos 
    566  1.1.1.2  christos   HOWTO (R_MN10300_TLS_DTPMOD,	/* type */
    567  1.1.1.2  christos 	 0,			/* rightshift */
    568  1.1.1.2  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    569  1.1.1.2  christos 	 32,			/* bitsize */
    570  1.1.1.2  christos 	 FALSE,			/* pc_relative */
    571  1.1.1.2  christos 	 0,			/* bitpos */
    572  1.1.1.2  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    573  1.1.1.2  christos 	 bfd_elf_generic_reloc, /* */
    574  1.1.1.2  christos 	 "R_MN10300_TLS_DTPMOD",	/* name */
    575  1.1.1.2  christos 	 FALSE,			/* partial_inplace */
    576  1.1.1.2  christos 	 0xffffffff,		/* src_mask */
    577  1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
    578  1.1.1.2  christos 	 FALSE),		/* pcrel_offset */
    579  1.1.1.2  christos 
    580  1.1.1.2  christos   HOWTO (R_MN10300_TLS_DTPOFF,	/* type */
    581  1.1.1.2  christos 	 0,			/* rightshift */
    582  1.1.1.2  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    583  1.1.1.2  christos 	 32,			/* bitsize */
    584  1.1.1.2  christos 	 FALSE,			/* pc_relative */
    585  1.1.1.2  christos 	 0,			/* bitpos */
    586  1.1.1.2  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    587  1.1.1.2  christos 	 bfd_elf_generic_reloc, /* */
    588  1.1.1.2  christos 	 "R_MN10300_TLS_DTPOFF",	/* name */
    589  1.1.1.2  christos 	 FALSE,			/* partial_inplace */
    590  1.1.1.2  christos 	 0xffffffff,		/* src_mask */
    591  1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
    592  1.1.1.2  christos 	 FALSE),		/* pcrel_offset */
    593  1.1.1.2  christos 
    594  1.1.1.2  christos   HOWTO (R_MN10300_TLS_TPOFF,	/* type */
    595  1.1.1.2  christos 	 0,			/* rightshift */
    596  1.1.1.2  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    597  1.1.1.2  christos 	 32,			/* bitsize */
    598  1.1.1.2  christos 	 FALSE,			/* pc_relative */
    599  1.1.1.2  christos 	 0,			/* bitpos */
    600  1.1.1.2  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    601  1.1.1.2  christos 	 bfd_elf_generic_reloc, /* */
    602  1.1.1.2  christos 	 "R_MN10300_TLS_TPOFF",	/* name */
    603  1.1.1.2  christos 	 FALSE,			/* partial_inplace */
    604  1.1.1.2  christos 	 0xffffffff,		/* src_mask */
    605  1.1.1.2  christos 	 0xffffffff,		/* dst_mask */
    606  1.1.1.2  christos 	 FALSE),		/* pcrel_offset */
    607  1.1.1.2  christos 
    608      1.1  christos   HOWTO (R_MN10300_SYM_DIFF,	/* type */
    609      1.1  christos 	 0,			/* rightshift */
    610      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    611      1.1  christos 	 32,			/* bitsize */
    612      1.1  christos 	 FALSE,			/* pc_relative */
    613      1.1  christos 	 0,			/* bitpos */
    614      1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    615  1.1.1.8  christos 	 NULL,			/* special handler.  */
    616      1.1  christos 	 "R_MN10300_SYM_DIFF",	/* name */
    617      1.1  christos 	 FALSE,			/* partial_inplace */
    618      1.1  christos 	 0xffffffff,		/* src_mask */
    619      1.1  christos 	 0xffffffff,		/* dst_mask */
    620      1.1  christos 	 FALSE),		/* pcrel_offset */
    621      1.1  christos 
    622      1.1  christos   HOWTO (R_MN10300_ALIGN,	/* type */
    623      1.1  christos 	 0,			/* rightshift */
    624      1.1  christos 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    625      1.1  christos 	 32,			/* bitsize */
    626      1.1  christos 	 FALSE,			/* pc_relative */
    627      1.1  christos 	 0,			/* bitpos */
    628      1.1  christos 	 complain_overflow_dont,/* complain_on_overflow */
    629  1.1.1.8  christos 	 NULL,			/* special handler.  */
    630      1.1  christos 	 "R_MN10300_ALIGN",	/* name */
    631      1.1  christos 	 FALSE,			/* partial_inplace */
    632      1.1  christos 	 0,			/* src_mask */
    633      1.1  christos 	 0,			/* dst_mask */
    634      1.1  christos 	 FALSE)			/* pcrel_offset */
    635      1.1  christos };
    636      1.1  christos 
    637      1.1  christos struct mn10300_reloc_map
    638      1.1  christos {
    639      1.1  christos   bfd_reloc_code_real_type bfd_reloc_val;
    640      1.1  christos   unsigned char elf_reloc_val;
    641      1.1  christos };
    642      1.1  christos 
    643      1.1  christos static const struct mn10300_reloc_map mn10300_reloc_map[] =
    644      1.1  christos {
    645      1.1  christos   { BFD_RELOC_NONE, R_MN10300_NONE, },
    646      1.1  christos   { BFD_RELOC_32, R_MN10300_32, },
    647      1.1  christos   { BFD_RELOC_16, R_MN10300_16, },
    648      1.1  christos   { BFD_RELOC_8, R_MN10300_8, },
    649      1.1  christos   { BFD_RELOC_32_PCREL, R_MN10300_PCREL32, },
    650      1.1  christos   { BFD_RELOC_16_PCREL, R_MN10300_PCREL16, },
    651      1.1  christos   { BFD_RELOC_8_PCREL, R_MN10300_PCREL8, },
    652      1.1  christos   { BFD_RELOC_24, R_MN10300_24, },
    653      1.1  christos   { BFD_RELOC_VTABLE_INHERIT, R_MN10300_GNU_VTINHERIT },
    654      1.1  christos   { BFD_RELOC_VTABLE_ENTRY, R_MN10300_GNU_VTENTRY },
    655      1.1  christos   { BFD_RELOC_32_GOT_PCREL, R_MN10300_GOTPC32 },
    656      1.1  christos   { BFD_RELOC_16_GOT_PCREL, R_MN10300_GOTPC16 },
    657      1.1  christos   { BFD_RELOC_32_GOTOFF, R_MN10300_GOTOFF32 },
    658      1.1  christos   { BFD_RELOC_MN10300_GOTOFF24, R_MN10300_GOTOFF24 },
    659      1.1  christos   { BFD_RELOC_16_GOTOFF, R_MN10300_GOTOFF16 },
    660      1.1  christos   { BFD_RELOC_32_PLT_PCREL, R_MN10300_PLT32 },
    661      1.1  christos   { BFD_RELOC_16_PLT_PCREL, R_MN10300_PLT16 },
    662      1.1  christos   { BFD_RELOC_MN10300_GOT32, R_MN10300_GOT32 },
    663      1.1  christos   { BFD_RELOC_MN10300_GOT24, R_MN10300_GOT24 },
    664      1.1  christos   { BFD_RELOC_MN10300_GOT16, R_MN10300_GOT16 },
    665      1.1  christos   { BFD_RELOC_MN10300_COPY, R_MN10300_COPY },
    666      1.1  christos   { BFD_RELOC_MN10300_GLOB_DAT, R_MN10300_GLOB_DAT },
    667      1.1  christos   { BFD_RELOC_MN10300_JMP_SLOT, R_MN10300_JMP_SLOT },
    668      1.1  christos   { BFD_RELOC_MN10300_RELATIVE, R_MN10300_RELATIVE },
    669  1.1.1.2  christos   { BFD_RELOC_MN10300_TLS_GD, R_MN10300_TLS_GD },
    670  1.1.1.2  christos   { BFD_RELOC_MN10300_TLS_LD, R_MN10300_TLS_LD },
    671  1.1.1.2  christos   { BFD_RELOC_MN10300_TLS_LDO, R_MN10300_TLS_LDO },
    672  1.1.1.2  christos   { BFD_RELOC_MN10300_TLS_GOTIE, R_MN10300_TLS_GOTIE },
    673  1.1.1.2  christos   { BFD_RELOC_MN10300_TLS_IE, R_MN10300_TLS_IE },
    674  1.1.1.2  christos   { BFD_RELOC_MN10300_TLS_LE, R_MN10300_TLS_LE },
    675  1.1.1.2  christos   { BFD_RELOC_MN10300_TLS_DTPMOD, R_MN10300_TLS_DTPMOD },
    676  1.1.1.2  christos   { BFD_RELOC_MN10300_TLS_DTPOFF, R_MN10300_TLS_DTPOFF },
    677  1.1.1.2  christos   { BFD_RELOC_MN10300_TLS_TPOFF, R_MN10300_TLS_TPOFF },
    678      1.1  christos   { BFD_RELOC_MN10300_SYM_DIFF, R_MN10300_SYM_DIFF },
    679      1.1  christos   { BFD_RELOC_MN10300_ALIGN, R_MN10300_ALIGN }
    680      1.1  christos };
    681      1.1  christos 
    682      1.1  christos /* Create the GOT section.  */
    683      1.1  christos 
    684      1.1  christos static bfd_boolean
    685      1.1  christos _bfd_mn10300_elf_create_got_section (bfd * abfd,
    686      1.1  christos 				     struct bfd_link_info * info)
    687      1.1  christos {
    688      1.1  christos   flagword   flags;
    689      1.1  christos   flagword   pltflags;
    690      1.1  christos   asection * s;
    691      1.1  christos   struct elf_link_hash_entry * h;
    692      1.1  christos   const struct elf_backend_data * bed = get_elf_backend_data (abfd);
    693  1.1.1.2  christos   struct elf_link_hash_table *htab;
    694      1.1  christos   int ptralign;
    695      1.1  christos 
    696      1.1  christos   /* This function may be called more than once.  */
    697  1.1.1.2  christos   htab = elf_hash_table (info);
    698  1.1.1.2  christos   if (htab->sgot != NULL)
    699      1.1  christos     return TRUE;
    700      1.1  christos 
    701      1.1  christos   switch (bed->s->arch_size)
    702      1.1  christos     {
    703      1.1  christos     case 32:
    704      1.1  christos       ptralign = 2;
    705      1.1  christos       break;
    706      1.1  christos 
    707      1.1  christos     case 64:
    708      1.1  christos       ptralign = 3;
    709      1.1  christos       break;
    710      1.1  christos 
    711      1.1  christos     default:
    712      1.1  christos       bfd_set_error (bfd_error_bad_value);
    713      1.1  christos       return FALSE;
    714      1.1  christos     }
    715      1.1  christos 
    716      1.1  christos   flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
    717      1.1  christos 	   | SEC_LINKER_CREATED);
    718      1.1  christos 
    719      1.1  christos   pltflags = flags;
    720      1.1  christos   pltflags |= SEC_CODE;
    721      1.1  christos   if (bed->plt_not_loaded)
    722      1.1  christos     pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
    723      1.1  christos   if (bed->plt_readonly)
    724      1.1  christos     pltflags |= SEC_READONLY;
    725      1.1  christos 
    726  1.1.1.2  christos   s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
    727  1.1.1.2  christos   htab->splt = s;
    728      1.1  christos   if (s == NULL
    729  1.1.1.9  christos       || !bfd_set_section_alignment (s, bed->plt_alignment))
    730      1.1  christos     return FALSE;
    731      1.1  christos 
    732      1.1  christos   /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
    733      1.1  christos      .plt section.  */
    734      1.1  christos   if (bed->want_plt_sym)
    735      1.1  christos     {
    736      1.1  christos       h = _bfd_elf_define_linkage_sym (abfd, info, s,
    737      1.1  christos 				       "_PROCEDURE_LINKAGE_TABLE_");
    738  1.1.1.2  christos       htab->hplt = h;
    739      1.1  christos       if (h == NULL)
    740      1.1  christos 	return FALSE;
    741      1.1  christos     }
    742      1.1  christos 
    743  1.1.1.2  christos   s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
    744  1.1.1.2  christos   htab->sgot = s;
    745      1.1  christos   if (s == NULL
    746  1.1.1.9  christos       || !bfd_set_section_alignment (s, ptralign))
    747      1.1  christos     return FALSE;
    748      1.1  christos 
    749      1.1  christos   if (bed->want_got_plt)
    750      1.1  christos     {
    751  1.1.1.2  christos       s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
    752  1.1.1.2  christos       htab->sgotplt = s;
    753      1.1  christos       if (s == NULL
    754  1.1.1.9  christos 	  || !bfd_set_section_alignment (s, ptralign))
    755      1.1  christos 	return FALSE;
    756      1.1  christos     }
    757      1.1  christos 
    758      1.1  christos   /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
    759      1.1  christos      (or .got.plt) section.  We don't do this in the linker script
    760      1.1  christos      because we don't want to define the symbol if we are not creating
    761      1.1  christos      a global offset table.  */
    762      1.1  christos   h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
    763  1.1.1.2  christos   htab->hgot = h;
    764      1.1  christos   if (h == NULL)
    765      1.1  christos     return FALSE;
    766      1.1  christos 
    767      1.1  christos   /* The first bit of the global offset table is the header.  */
    768      1.1  christos   s->size += bed->got_header_size;
    769      1.1  christos 
    770      1.1  christos   return TRUE;
    771      1.1  christos }
    772      1.1  christos 
    773      1.1  christos static reloc_howto_type *
    774      1.1  christos bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    775      1.1  christos 				 bfd_reloc_code_real_type code)
    776      1.1  christos {
    777      1.1  christos   unsigned int i;
    778      1.1  christos 
    779      1.1  christos   for (i = ARRAY_SIZE (mn10300_reloc_map); i--;)
    780      1.1  christos     if (mn10300_reloc_map[i].bfd_reloc_val == code)
    781      1.1  christos       return &elf_mn10300_howto_table[mn10300_reloc_map[i].elf_reloc_val];
    782      1.1  christos 
    783      1.1  christos   return NULL;
    784      1.1  christos }
    785      1.1  christos 
    786      1.1  christos static reloc_howto_type *
    787      1.1  christos bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    788      1.1  christos 				 const char *r_name)
    789      1.1  christos {
    790      1.1  christos   unsigned int i;
    791      1.1  christos 
    792      1.1  christos   for (i = ARRAY_SIZE (elf_mn10300_howto_table); i--;)
    793      1.1  christos     if (elf_mn10300_howto_table[i].name != NULL
    794      1.1  christos 	&& strcasecmp (elf_mn10300_howto_table[i].name, r_name) == 0)
    795      1.1  christos       return elf_mn10300_howto_table + i;
    796      1.1  christos 
    797      1.1  christos   return NULL;
    798      1.1  christos }
    799      1.1  christos 
    800      1.1  christos /* Set the howto pointer for an MN10300 ELF reloc.  */
    801      1.1  christos 
    802  1.1.1.8  christos static bfd_boolean
    803  1.1.1.8  christos mn10300_info_to_howto (bfd *abfd,
    804      1.1  christos 		       arelent *cache_ptr,
    805      1.1  christos 		       Elf_Internal_Rela *dst)
    806      1.1  christos {
    807      1.1  christos   unsigned int r_type;
    808      1.1  christos 
    809      1.1  christos   r_type = ELF32_R_TYPE (dst->r_info);
    810  1.1.1.5  christos   if (r_type >= R_MN10300_MAX)
    811  1.1.1.5  christos     {
    812  1.1.1.7  christos       /* xgettext:c-format */
    813  1.1.1.8  christos       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
    814  1.1.1.7  christos 			  abfd, r_type);
    815  1.1.1.5  christos       bfd_set_error (bfd_error_bad_value);
    816  1.1.1.8  christos       return FALSE;
    817  1.1.1.5  christos     }
    818      1.1  christos   cache_ptr->howto = elf_mn10300_howto_table + r_type;
    819  1.1.1.8  christos   return TRUE;
    820      1.1  christos }
    821      1.1  christos 
    822  1.1.1.2  christos static int
    823  1.1.1.8  christos elf_mn10300_tls_transition (struct bfd_link_info *	  info,
    824  1.1.1.8  christos 			    int				  r_type,
    825  1.1.1.2  christos 			    struct elf_link_hash_entry *  h,
    826  1.1.1.8  christos 			    asection *			  sec,
    827  1.1.1.8  christos 			    bfd_boolean			  counting)
    828  1.1.1.2  christos {
    829  1.1.1.2  christos   bfd_boolean is_local;
    830  1.1.1.2  christos 
    831  1.1.1.2  christos   if (r_type == R_MN10300_TLS_GD
    832  1.1.1.2  christos       && h != NULL
    833  1.1.1.2  christos       && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_IE)
    834  1.1.1.2  christos     return R_MN10300_TLS_GOTIE;
    835  1.1.1.2  christos 
    836  1.1.1.6  christos   if (bfd_link_pic (info))
    837  1.1.1.2  christos     return r_type;
    838  1.1.1.2  christos 
    839  1.1.1.2  christos   if (! (sec->flags & SEC_CODE))
    840  1.1.1.2  christos     return r_type;
    841  1.1.1.2  christos 
    842  1.1.1.2  christos   if (! counting && h != NULL && ! elf_hash_table (info)->dynamic_sections_created)
    843  1.1.1.2  christos     is_local = TRUE;
    844  1.1.1.2  christos   else
    845  1.1.1.2  christos     is_local = SYMBOL_CALLS_LOCAL (info, h);
    846  1.1.1.2  christos 
    847  1.1.1.2  christos   /* For the main program, these are the transitions we do.  */
    848  1.1.1.2  christos   switch (r_type)
    849  1.1.1.2  christos     {
    850  1.1.1.2  christos     case R_MN10300_TLS_GD: return is_local ? R_MN10300_TLS_LE : R_MN10300_TLS_GOTIE;
    851  1.1.1.2  christos     case R_MN10300_TLS_LD: return R_MN10300_NONE;
    852  1.1.1.2  christos     case R_MN10300_TLS_LDO: return R_MN10300_TLS_LE;
    853  1.1.1.2  christos     case R_MN10300_TLS_IE:
    854  1.1.1.2  christos     case R_MN10300_TLS_GOTIE: return is_local ? R_MN10300_TLS_LE : r_type;
    855  1.1.1.2  christos     }
    856  1.1.1.2  christos 
    857  1.1.1.2  christos   return r_type;
    858  1.1.1.2  christos }
    859  1.1.1.2  christos 
    860  1.1.1.2  christos /* Return the relocation value for @tpoff relocation
    861  1.1.1.2  christos    if STT_TLS virtual address is ADDRESS.  */
    862  1.1.1.2  christos 
    863  1.1.1.2  christos static bfd_vma
    864  1.1.1.2  christos dtpoff (struct bfd_link_info * info, bfd_vma address)
    865  1.1.1.2  christos {
    866  1.1.1.2  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
    867  1.1.1.2  christos 
    868  1.1.1.2  christos   /* If tls_sec is NULL, we should have signalled an error already.  */
    869  1.1.1.2  christos   if (htab->tls_sec == NULL)
    870  1.1.1.2  christos     return 0;
    871  1.1.1.2  christos   return address - htab->tls_sec->vma;
    872  1.1.1.2  christos }
    873  1.1.1.2  christos 
    874  1.1.1.2  christos /* Return the relocation value for @tpoff relocation
    875  1.1.1.2  christos    if STT_TLS virtual address is ADDRESS.  */
    876  1.1.1.2  christos 
    877  1.1.1.2  christos static bfd_vma
    878  1.1.1.2  christos tpoff (struct bfd_link_info * info, bfd_vma address)
    879  1.1.1.2  christos {
    880  1.1.1.2  christos   struct elf_link_hash_table *htab = elf_hash_table (info);
    881  1.1.1.2  christos 
    882  1.1.1.2  christos   /* If tls_sec is NULL, we should have signalled an error already.  */
    883  1.1.1.2  christos   if (htab->tls_sec == NULL)
    884  1.1.1.2  christos     return 0;
    885  1.1.1.2  christos   return address - (htab->tls_size + htab->tls_sec->vma);
    886  1.1.1.2  christos }
    887  1.1.1.2  christos 
    888  1.1.1.2  christos /* Returns nonzero if there's a R_MN10300_PLT32 reloc that we now need
    889  1.1.1.2  christos    to skip, after this one.  The actual value is the offset between
    890  1.1.1.2  christos    this reloc and the PLT reloc.  */
    891  1.1.1.2  christos 
    892  1.1.1.2  christos static int
    893  1.1.1.8  christos mn10300_do_tls_transition (bfd *	 input_bfd,
    894  1.1.1.8  christos 			   unsigned int	 r_type,
    895  1.1.1.8  christos 			   unsigned int	 tls_r_type,
    896  1.1.1.8  christos 			   bfd_byte *	 contents,
    897  1.1.1.8  christos 			   bfd_vma	 offset)
    898  1.1.1.2  christos {
    899  1.1.1.2  christos   bfd_byte *op = contents + offset;
    900  1.1.1.2  christos   int gotreg = 0;
    901  1.1.1.2  christos 
    902  1.1.1.2  christos #define TLS_PAIR(r1,r2) ((r1) * R_MN10300_MAX + (r2))
    903  1.1.1.2  christos 
    904  1.1.1.2  christos   /* This is common to all GD/LD transitions, so break it out.  */
    905  1.1.1.2  christos   if (r_type == R_MN10300_TLS_GD
    906  1.1.1.2  christos       || r_type == R_MN10300_TLS_LD)
    907  1.1.1.2  christos     {
    908  1.1.1.2  christos       op -= 2;
    909  1.1.1.2  christos       /* mov imm,d0.  */
    910  1.1.1.2  christos       BFD_ASSERT (bfd_get_8 (input_bfd, op) == 0xFC);
    911  1.1.1.2  christos       BFD_ASSERT (bfd_get_8 (input_bfd, op + 1) == 0xCC);
    912  1.1.1.2  christos       /* add aN,d0.  */
    913  1.1.1.2  christos       BFD_ASSERT (bfd_get_8 (input_bfd, op + 6) == 0xF1);
    914  1.1.1.2  christos       gotreg = (bfd_get_8 (input_bfd, op + 7) & 0x0c) >> 2;
    915  1.1.1.2  christos       /* Call.  */
    916  1.1.1.2  christos       BFD_ASSERT (bfd_get_8 (input_bfd, op + 8) == 0xDD);
    917  1.1.1.2  christos     }
    918  1.1.1.2  christos 
    919  1.1.1.2  christos   switch (TLS_PAIR (r_type, tls_r_type))
    920  1.1.1.2  christos     {
    921  1.1.1.2  christos     case TLS_PAIR (R_MN10300_TLS_GD, R_MN10300_TLS_GOTIE):
    922  1.1.1.2  christos       {
    923  1.1.1.2  christos 	/* Keep track of which register we put GOTptr in.  */
    924  1.1.1.2  christos 	/* mov (_x@indntpoff,a2),a0.  */
    925  1.1.1.2  christos 	memcpy (op, "\xFC\x20\x00\x00\x00\x00", 6);
    926  1.1.1.2  christos 	op[1] |= gotreg;
    927  1.1.1.2  christos 	/* add e2,a0.  */
    928  1.1.1.2  christos 	memcpy (op+6, "\xF9\x78\x28", 3);
    929  1.1.1.2  christos 	/* or  0x00000000, d0 - six byte nop.  */
    930  1.1.1.2  christos 	memcpy (op+9, "\xFC\xE4\x00\x00\x00\x00", 6);
    931  1.1.1.2  christos       }
    932  1.1.1.2  christos       return 7;
    933  1.1.1.2  christos 
    934  1.1.1.2  christos     case TLS_PAIR (R_MN10300_TLS_GD, R_MN10300_TLS_LE):
    935  1.1.1.2  christos       {
    936  1.1.1.2  christos 	/* Register is *always* a0.  */
    937  1.1.1.2  christos 	/* mov _x@tpoff,a0.  */
    938  1.1.1.2  christos 	memcpy (op, "\xFC\xDC\x00\x00\x00\x00", 6);
    939  1.1.1.2  christos 	/* add e2,a0.  */
    940  1.1.1.2  christos 	memcpy (op+6, "\xF9\x78\x28", 3);
    941  1.1.1.2  christos 	/* or  0x00000000, d0 - six byte nop.  */
    942  1.1.1.2  christos 	memcpy (op+9, "\xFC\xE4\x00\x00\x00\x00", 6);
    943  1.1.1.2  christos       }
    944  1.1.1.2  christos       return 7;
    945  1.1.1.2  christos     case TLS_PAIR (R_MN10300_TLS_LD, R_MN10300_NONE):
    946  1.1.1.2  christos       {
    947  1.1.1.2  christos 	/* Register is *always* a0.  */
    948  1.1.1.2  christos 	/* mov e2,a0.  */
    949  1.1.1.2  christos 	memcpy (op, "\xF5\x88", 2);
    950  1.1.1.2  christos 	/* or  0x00000000, d0 - six byte nop.  */
    951  1.1.1.2  christos 	memcpy (op+2, "\xFC\xE4\x00\x00\x00\x00", 6);
    952  1.1.1.2  christos 	/* or  0x00000000, e2 - seven byte nop.  */
    953  1.1.1.2  christos 	memcpy (op+8, "\xFE\x19\x22\x00\x00\x00\x00", 7);
    954  1.1.1.2  christos       }
    955  1.1.1.2  christos       return 7;
    956  1.1.1.2  christos 
    957  1.1.1.2  christos     case TLS_PAIR (R_MN10300_TLS_LDO, R_MN10300_TLS_LE):
    958  1.1.1.2  christos       /* No changes needed, just the reloc change.  */
    959  1.1.1.2  christos       return 0;
    960  1.1.1.2  christos 
    961  1.1.1.2  christos     /*  These are a little tricky, because we have to detect which
    962  1.1.1.2  christos 	opcode is being used (they're different sizes, with the reloc
    963  1.1.1.2  christos 	at different offsets within the opcode) and convert each
    964  1.1.1.2  christos 	accordingly, copying the operands as needed.  The conversions
    965  1.1.1.2  christos 	we do are as follows (IE,GOTIE,LE):
    966  1.1.1.2  christos 
    967  1.1.1.8  christos 		   1111 1100  1010 01Dn  [-- abs32 --]  MOV (x@indntpoff),Dn
    968  1.1.1.8  christos 		   1111 1100  0000 DnAm  [-- abs32 --]  MOV (x@gotntpoff,Am),Dn
    969  1.1.1.8  christos 		   1111 1100  1100 11Dn  [-- abs32 --]  MOV x@tpoff,Dn
    970  1.1.1.8  christos 
    971  1.1.1.8  christos 		   1111 1100  1010 00An  [-- abs32 --]  MOV (x@indntpoff),An
    972  1.1.1.8  christos 		   1111 1100  0010 AnAm  [-- abs32 --]  MOV (x@gotntpoff,Am),An
    973  1.1.1.8  christos 		   1111 1100  1101 11An  [-- abs32 --]  MOV x@tpoff,An
    974  1.1.1.2  christos 
    975  1.1.1.2  christos 	1111 1110  0000 1110  Rnnn Xxxx  [-- abs32 --]  MOV (x@indntpoff),Rn
    976  1.1.1.2  christos 	1111 1110  0000 1010  Rnnn Rmmm  [-- abs32 --]  MOV (x@indntpoff,Rm),Rn
    977  1.1.1.2  christos 	1111 1110  0000 1000  Rnnn Xxxx  [-- abs32 --]  MOV x@tpoff,Rn
    978  1.1.1.2  christos 
    979  1.1.1.2  christos 	Since the GOT pointer is always $a2, we assume the last
    980  1.1.1.2  christos 	normally won't happen, but let's be paranoid and plan for the
    981  1.1.1.2  christos 	day that GCC optimizes it somewhow.  */
    982  1.1.1.2  christos 
    983  1.1.1.2  christos     case TLS_PAIR (R_MN10300_TLS_IE, R_MN10300_TLS_LE):
    984  1.1.1.2  christos       if (op[-2] == 0xFC)
    985  1.1.1.2  christos 	{
    986  1.1.1.2  christos 	  op -= 2;
    987  1.1.1.2  christos 	  if ((op[1] & 0xFC) == 0xA4) /* Dn */
    988  1.1.1.2  christos 	    {
    989  1.1.1.2  christos 	      op[1] &= 0x03; /* Leaves Dn.  */
    990  1.1.1.2  christos 	      op[1] |= 0xCC;
    991  1.1.1.2  christos 	    }
    992  1.1.1.2  christos 	  else /* An */
    993  1.1.1.2  christos 	    {
    994  1.1.1.2  christos 	      op[1] &= 0x03; /* Leaves An. */
    995  1.1.1.2  christos 	      op[1] |= 0xDC;
    996  1.1.1.2  christos 	    }
    997  1.1.1.2  christos 	}
    998  1.1.1.2  christos       else if (op[-3] == 0xFE)
    999  1.1.1.2  christos 	op[-2] = 0x08;
   1000  1.1.1.2  christos       else
   1001  1.1.1.2  christos 	abort ();
   1002  1.1.1.2  christos       break;
   1003  1.1.1.2  christos 
   1004  1.1.1.2  christos     case TLS_PAIR (R_MN10300_TLS_GOTIE, R_MN10300_TLS_LE):
   1005  1.1.1.2  christos       if (op[-2] == 0xFC)
   1006  1.1.1.2  christos 	{
   1007  1.1.1.2  christos 	  op -= 2;
   1008  1.1.1.2  christos 	  if ((op[1] & 0xF0) == 0x00) /* Dn */
   1009  1.1.1.2  christos 	    {
   1010  1.1.1.2  christos 	      op[1] &= 0x0C; /* Leaves Dn.  */
   1011  1.1.1.2  christos 	      op[1] >>= 2;
   1012  1.1.1.2  christos 	      op[1] |= 0xCC;
   1013  1.1.1.2  christos 	    }
   1014  1.1.1.2  christos 	  else /* An */
   1015  1.1.1.2  christos 	    {
   1016  1.1.1.2  christos 	      op[1] &= 0x0C; /* Leaves An.  */
   1017  1.1.1.2  christos 	      op[1] >>= 2;
   1018  1.1.1.2  christos 	      op[1] |= 0xDC;
   1019  1.1.1.2  christos 	    }
   1020  1.1.1.2  christos 	}
   1021  1.1.1.2  christos       else if (op[-3] == 0xFE)
   1022  1.1.1.2  christos 	op[-2] = 0x08;
   1023  1.1.1.2  christos       else
   1024  1.1.1.2  christos 	abort ();
   1025  1.1.1.2  christos       break;
   1026  1.1.1.2  christos 
   1027  1.1.1.2  christos     default:
   1028  1.1.1.7  christos       _bfd_error_handler
   1029  1.1.1.7  christos 	/* xgettext:c-format */
   1030  1.1.1.8  christos 	(_("%pB: unsupported transition from %s to %s"),
   1031  1.1.1.7  christos 	 input_bfd,
   1032  1.1.1.2  christos 	 elf_mn10300_howto_table[r_type].name,
   1033  1.1.1.2  christos 	 elf_mn10300_howto_table[tls_r_type].name);
   1034  1.1.1.2  christos       break;
   1035  1.1.1.2  christos     }
   1036  1.1.1.2  christos #undef TLS_PAIR
   1037  1.1.1.2  christos   return 0;
   1038  1.1.1.2  christos }
   1039  1.1.1.2  christos 
   1040      1.1  christos /* Look through the relocs for a section during the first phase.
   1041      1.1  christos    Since we don't do .gots or .plts, we just need to consider the
   1042      1.1  christos    virtual table relocs for gc.  */
   1043      1.1  christos 
   1044      1.1  christos static bfd_boolean
   1045      1.1  christos mn10300_elf_check_relocs (bfd *abfd,
   1046      1.1  christos 			  struct bfd_link_info *info,
   1047      1.1  christos 			  asection *sec,
   1048      1.1  christos 			  const Elf_Internal_Rela *relocs)
   1049      1.1  christos {
   1050  1.1.1.2  christos   struct elf32_mn10300_link_hash_table * htab = elf32_mn10300_hash_table (info);
   1051      1.1  christos   bfd_boolean sym_diff_reloc_seen;
   1052      1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   1053      1.1  christos   Elf_Internal_Sym * isymbuf = NULL;
   1054      1.1  christos   struct elf_link_hash_entry **sym_hashes;
   1055      1.1  christos   const Elf_Internal_Rela *rel;
   1056      1.1  christos   const Elf_Internal_Rela *rel_end;
   1057      1.1  christos   bfd *      dynobj;
   1058      1.1  christos   bfd_vma *  local_got_offsets;
   1059      1.1  christos   asection * sgot;
   1060      1.1  christos   asection * srelgot;
   1061      1.1  christos   asection * sreloc;
   1062      1.1  christos   bfd_boolean result = FALSE;
   1063      1.1  christos 
   1064      1.1  christos   sgot    = NULL;
   1065      1.1  christos   srelgot = NULL;
   1066      1.1  christos   sreloc  = NULL;
   1067      1.1  christos 
   1068  1.1.1.6  christos   if (bfd_link_relocatable (info))
   1069      1.1  christos     return TRUE;
   1070      1.1  christos 
   1071      1.1  christos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   1072      1.1  christos   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   1073      1.1  christos   sym_hashes = elf_sym_hashes (abfd);
   1074      1.1  christos 
   1075      1.1  christos   dynobj = elf_hash_table (info)->dynobj;
   1076      1.1  christos   local_got_offsets = elf_local_got_offsets (abfd);
   1077      1.1  christos   rel_end = relocs + sec->reloc_count;
   1078      1.1  christos   sym_diff_reloc_seen = FALSE;
   1079      1.1  christos 
   1080      1.1  christos   for (rel = relocs; rel < rel_end; rel++)
   1081      1.1  christos     {
   1082      1.1  christos       struct elf_link_hash_entry *h;
   1083      1.1  christos       unsigned long r_symndx;
   1084      1.1  christos       unsigned int r_type;
   1085  1.1.1.2  christos       int tls_type = GOT_NORMAL;
   1086      1.1  christos 
   1087      1.1  christos       r_symndx = ELF32_R_SYM (rel->r_info);
   1088      1.1  christos       if (r_symndx < symtab_hdr->sh_info)
   1089      1.1  christos 	h = NULL;
   1090      1.1  christos       else
   1091      1.1  christos 	{
   1092      1.1  christos 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
   1093      1.1  christos 	  while (h->root.type == bfd_link_hash_indirect
   1094      1.1  christos 		 || h->root.type == bfd_link_hash_warning)
   1095      1.1  christos 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
   1096      1.1  christos 	}
   1097      1.1  christos 
   1098      1.1  christos       r_type = ELF32_R_TYPE (rel->r_info);
   1099  1.1.1.2  christos       r_type = elf_mn10300_tls_transition (info, r_type, h, sec, TRUE);
   1100      1.1  christos 
   1101      1.1  christos       /* Some relocs require a global offset table.  */
   1102      1.1  christos       if (dynobj == NULL)
   1103      1.1  christos 	{
   1104      1.1  christos 	  switch (r_type)
   1105      1.1  christos 	    {
   1106      1.1  christos 	    case R_MN10300_GOT32:
   1107      1.1  christos 	    case R_MN10300_GOT24:
   1108      1.1  christos 	    case R_MN10300_GOT16:
   1109      1.1  christos 	    case R_MN10300_GOTOFF32:
   1110      1.1  christos 	    case R_MN10300_GOTOFF24:
   1111      1.1  christos 	    case R_MN10300_GOTOFF16:
   1112      1.1  christos 	    case R_MN10300_GOTPC32:
   1113      1.1  christos 	    case R_MN10300_GOTPC16:
   1114  1.1.1.2  christos 	    case R_MN10300_TLS_GD:
   1115  1.1.1.2  christos 	    case R_MN10300_TLS_LD:
   1116  1.1.1.2  christos 	    case R_MN10300_TLS_GOTIE:
   1117  1.1.1.2  christos 	    case R_MN10300_TLS_IE:
   1118      1.1  christos 	      elf_hash_table (info)->dynobj = dynobj = abfd;
   1119      1.1  christos 	      if (! _bfd_mn10300_elf_create_got_section (dynobj, info))
   1120      1.1  christos 		goto fail;
   1121      1.1  christos 	      break;
   1122      1.1  christos 
   1123      1.1  christos 	    default:
   1124      1.1  christos 	      break;
   1125      1.1  christos 	    }
   1126      1.1  christos 	}
   1127      1.1  christos 
   1128      1.1  christos       switch (r_type)
   1129      1.1  christos 	{
   1130      1.1  christos 	/* This relocation describes the C++ object vtable hierarchy.
   1131      1.1  christos 	   Reconstruct it for later use during GC.  */
   1132      1.1  christos 	case R_MN10300_GNU_VTINHERIT:
   1133      1.1  christos 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
   1134      1.1  christos 	    goto fail;
   1135      1.1  christos 	  break;
   1136      1.1  christos 
   1137      1.1  christos 	/* This relocation describes which C++ vtable entries are actually
   1138      1.1  christos 	   used.  Record for later use during GC.  */
   1139      1.1  christos 	case R_MN10300_GNU_VTENTRY:
   1140  1.1.1.9  christos 	  if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
   1141      1.1  christos 	    goto fail;
   1142      1.1  christos 	  break;
   1143      1.1  christos 
   1144  1.1.1.2  christos 	case R_MN10300_TLS_LD:
   1145  1.1.1.2  christos 	  htab->tls_ldm_got.refcount ++;
   1146  1.1.1.2  christos 	  tls_type = GOT_TLS_LD;
   1147  1.1.1.2  christos 
   1148  1.1.1.2  christos 	  if (htab->tls_ldm_got.got_allocated)
   1149  1.1.1.2  christos 	    break;
   1150  1.1.1.2  christos 	  goto create_got;
   1151  1.1.1.2  christos 
   1152  1.1.1.2  christos 	case R_MN10300_TLS_IE:
   1153  1.1.1.2  christos 	case R_MN10300_TLS_GOTIE:
   1154  1.1.1.6  christos 	  if (bfd_link_pic (info))
   1155  1.1.1.2  christos 	    info->flags |= DF_STATIC_TLS;
   1156  1.1.1.2  christos 	  /* Fall through */
   1157  1.1.1.2  christos 
   1158  1.1.1.2  christos 	case R_MN10300_TLS_GD:
   1159      1.1  christos 	case R_MN10300_GOT32:
   1160      1.1  christos 	case R_MN10300_GOT24:
   1161      1.1  christos 	case R_MN10300_GOT16:
   1162  1.1.1.2  christos 	create_got:
   1163      1.1  christos 	  /* This symbol requires a global offset table entry.  */
   1164      1.1  christos 
   1165  1.1.1.2  christos 	  switch (r_type)
   1166  1.1.1.2  christos 	    {
   1167  1.1.1.2  christos 	    case R_MN10300_TLS_IE:
   1168  1.1.1.2  christos 	    case R_MN10300_TLS_GOTIE: tls_type = GOT_TLS_IE; break;
   1169  1.1.1.2  christos 	    case R_MN10300_TLS_GD:    tls_type = GOT_TLS_GD; break;
   1170  1.1.1.8  christos 	    default:		      tls_type = GOT_NORMAL; break;
   1171  1.1.1.2  christos 	    }
   1172  1.1.1.2  christos 
   1173  1.1.1.7  christos 	  sgot = htab->root.sgot;
   1174  1.1.1.7  christos 	  srelgot = htab->root.srelgot;
   1175  1.1.1.7  christos 	  BFD_ASSERT (sgot != NULL && srelgot != NULL);
   1176      1.1  christos 
   1177  1.1.1.2  christos 	  if (r_type == R_MN10300_TLS_LD)
   1178      1.1  christos 	    {
   1179  1.1.1.2  christos 	      htab->tls_ldm_got.offset = sgot->size;
   1180  1.1.1.2  christos 	      htab->tls_ldm_got.got_allocated ++;
   1181  1.1.1.2  christos 	    }
   1182  1.1.1.2  christos 	  else if (h != NULL)
   1183  1.1.1.2  christos 	    {
   1184  1.1.1.2  christos 	      if (elf_mn10300_hash_entry (h)->tls_type != tls_type
   1185  1.1.1.2  christos 		  && elf_mn10300_hash_entry (h)->tls_type != GOT_UNKNOWN)
   1186  1.1.1.2  christos 		{
   1187  1.1.1.2  christos 		  if (tls_type == GOT_TLS_IE
   1188  1.1.1.2  christos 		      && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_GD)
   1189  1.1.1.2  christos 		    /* No change - this is ok.  */;
   1190  1.1.1.2  christos 		  else if (tls_type == GOT_TLS_GD
   1191  1.1.1.2  christos 		      && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_IE)
   1192  1.1.1.2  christos 		    /* Transition GD->IE.  */
   1193  1.1.1.2  christos 		    tls_type = GOT_TLS_IE;
   1194  1.1.1.2  christos 		  else
   1195  1.1.1.7  christos 		    _bfd_error_handler
   1196  1.1.1.7  christos 		      /* xgettext:c-format */
   1197  1.1.1.8  christos 		      (_("%pB: %s' accessed both as normal and thread local symbol"),
   1198  1.1.1.2  christos 		       abfd, h ? h->root.root.string : "<local>");
   1199  1.1.1.2  christos 		}
   1200  1.1.1.2  christos 
   1201  1.1.1.2  christos 	      elf_mn10300_hash_entry (h)->tls_type = tls_type;
   1202  1.1.1.2  christos 
   1203      1.1  christos 	      if (h->got.offset != (bfd_vma) -1)
   1204      1.1  christos 		/* We have already allocated space in the .got.  */
   1205      1.1  christos 		break;
   1206      1.1  christos 
   1207      1.1  christos 	      h->got.offset = sgot->size;
   1208      1.1  christos 
   1209  1.1.1.2  christos 	      if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
   1210  1.1.1.2  christos 		  /* Make sure this symbol is output as a dynamic symbol.  */
   1211  1.1.1.2  christos 		  && h->dynindx == -1)
   1212      1.1  christos 		{
   1213      1.1  christos 		  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   1214      1.1  christos 		    goto fail;
   1215      1.1  christos 		}
   1216      1.1  christos 
   1217      1.1  christos 	      srelgot->size += sizeof (Elf32_External_Rela);
   1218  1.1.1.2  christos 	      if (r_type == R_MN10300_TLS_GD)
   1219  1.1.1.2  christos 		srelgot->size += sizeof (Elf32_External_Rela);
   1220      1.1  christos 	    }
   1221      1.1  christos 	  else
   1222      1.1  christos 	    {
   1223      1.1  christos 	      /* This is a global offset table entry for a local
   1224      1.1  christos 		 symbol.  */
   1225      1.1  christos 	      if (local_got_offsets == NULL)
   1226      1.1  christos 		{
   1227      1.1  christos 		  size_t       size;
   1228      1.1  christos 		  unsigned int i;
   1229      1.1  christos 
   1230  1.1.1.2  christos 		  size = symtab_hdr->sh_info * (sizeof (bfd_vma) + sizeof (char));
   1231      1.1  christos 		  local_got_offsets = bfd_alloc (abfd, size);
   1232      1.1  christos 
   1233      1.1  christos 		  if (local_got_offsets == NULL)
   1234      1.1  christos 		    goto fail;
   1235      1.1  christos 
   1236      1.1  christos 		  elf_local_got_offsets (abfd) = local_got_offsets;
   1237  1.1.1.2  christos 		  elf_mn10300_local_got_tls_type (abfd)
   1238  1.1.1.2  christos 		      = (char *) (local_got_offsets + symtab_hdr->sh_info);
   1239      1.1  christos 
   1240      1.1  christos 		  for (i = 0; i < symtab_hdr->sh_info; i++)
   1241      1.1  christos 		    local_got_offsets[i] = (bfd_vma) -1;
   1242      1.1  christos 		}
   1243      1.1  christos 
   1244      1.1  christos 	      if (local_got_offsets[r_symndx] != (bfd_vma) -1)
   1245      1.1  christos 		/* We have already allocated space in the .got.  */
   1246      1.1  christos 		break;
   1247      1.1  christos 
   1248      1.1  christos 	      local_got_offsets[r_symndx] = sgot->size;
   1249      1.1  christos 
   1250  1.1.1.6  christos 	      if (bfd_link_pic (info))
   1251  1.1.1.2  christos 		{
   1252  1.1.1.2  christos 		  /* If we are generating a shared object, we need to
   1253  1.1.1.2  christos 		     output a R_MN10300_RELATIVE reloc so that the dynamic
   1254  1.1.1.2  christos 		     linker can adjust this GOT entry.  */
   1255  1.1.1.2  christos 		  srelgot->size += sizeof (Elf32_External_Rela);
   1256  1.1.1.2  christos 
   1257  1.1.1.2  christos 		  if (r_type == R_MN10300_TLS_GD)
   1258  1.1.1.2  christos 		    /* And a R_MN10300_TLS_DTPOFF reloc as well.  */
   1259  1.1.1.2  christos 		    srelgot->size += sizeof (Elf32_External_Rela);
   1260  1.1.1.2  christos 		}
   1261  1.1.1.2  christos 
   1262  1.1.1.2  christos 	      elf_mn10300_local_got_tls_type (abfd) [r_symndx] = tls_type;
   1263      1.1  christos 	    }
   1264      1.1  christos 
   1265      1.1  christos 	  sgot->size += 4;
   1266  1.1.1.2  christos 	  if (r_type == R_MN10300_TLS_GD
   1267  1.1.1.2  christos 	      || r_type == R_MN10300_TLS_LD)
   1268  1.1.1.2  christos 	    sgot->size += 4;
   1269  1.1.1.2  christos 
   1270  1.1.1.2  christos 	  goto need_shared_relocs;
   1271      1.1  christos 
   1272      1.1  christos 	case R_MN10300_PLT32:
   1273      1.1  christos 	case R_MN10300_PLT16:
   1274      1.1  christos 	  /* This symbol requires a procedure linkage table entry.  We
   1275      1.1  christos 	     actually build the entry in adjust_dynamic_symbol,
   1276      1.1  christos 	     because this might be a case of linking PIC code which is
   1277      1.1  christos 	     never referenced by a dynamic object, in which case we
   1278      1.1  christos 	     don't need to generate a procedure linkage table entry
   1279      1.1  christos 	     after all.  */
   1280      1.1  christos 
   1281      1.1  christos 	  /* If this is a local symbol, we resolve it directly without
   1282      1.1  christos 	     creating a procedure linkage table entry.  */
   1283      1.1  christos 	  if (h == NULL)
   1284      1.1  christos 	    continue;
   1285      1.1  christos 
   1286      1.1  christos 	  if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
   1287      1.1  christos 	      || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
   1288      1.1  christos 	    break;
   1289      1.1  christos 
   1290      1.1  christos 	  h->needs_plt = 1;
   1291      1.1  christos 	  break;
   1292      1.1  christos 
   1293      1.1  christos 	case R_MN10300_24:
   1294      1.1  christos 	case R_MN10300_16:
   1295      1.1  christos 	case R_MN10300_8:
   1296      1.1  christos 	case R_MN10300_PCREL32:
   1297      1.1  christos 	case R_MN10300_PCREL16:
   1298      1.1  christos 	case R_MN10300_PCREL8:
   1299      1.1  christos 	  if (h != NULL)
   1300      1.1  christos 	    h->non_got_ref = 1;
   1301      1.1  christos 	  break;
   1302      1.1  christos 
   1303      1.1  christos 	case R_MN10300_SYM_DIFF:
   1304      1.1  christos 	  sym_diff_reloc_seen = TRUE;
   1305      1.1  christos 	  break;
   1306      1.1  christos 
   1307      1.1  christos 	case R_MN10300_32:
   1308      1.1  christos 	  if (h != NULL)
   1309      1.1  christos 	    h->non_got_ref = 1;
   1310      1.1  christos 
   1311  1.1.1.2  christos 	need_shared_relocs:
   1312      1.1  christos 	  /* If we are creating a shared library, then we
   1313      1.1  christos 	     need to copy the reloc into the shared library.  */
   1314  1.1.1.6  christos 	  if (bfd_link_pic (info)
   1315      1.1  christos 	      && (sec->flags & SEC_ALLOC) != 0
   1316      1.1  christos 	      /* Do not generate a dynamic reloc for a
   1317      1.1  christos 		 reloc associated with a SYM_DIFF operation.  */
   1318      1.1  christos 	      && ! sym_diff_reloc_seen)
   1319      1.1  christos 	    {
   1320      1.1  christos 	      asection * sym_section = NULL;
   1321      1.1  christos 
   1322      1.1  christos 	      /* Find the section containing the
   1323      1.1  christos 		 symbol involved in the relocation.  */
   1324      1.1  christos 	      if (h == NULL)
   1325      1.1  christos 		{
   1326      1.1  christos 		  Elf_Internal_Sym * isym;
   1327      1.1  christos 
   1328      1.1  christos 		  if (isymbuf == NULL)
   1329      1.1  christos 		    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
   1330      1.1  christos 						    symtab_hdr->sh_info, 0,
   1331      1.1  christos 						    NULL, NULL, NULL);
   1332      1.1  christos 		  if (isymbuf)
   1333      1.1  christos 		    {
   1334      1.1  christos 		      isym = isymbuf + r_symndx;
   1335      1.1  christos 		      /* All we care about is whether this local symbol is absolute.  */
   1336      1.1  christos 		      if (isym->st_shndx == SHN_ABS)
   1337      1.1  christos 			sym_section = bfd_abs_section_ptr;
   1338      1.1  christos 		    }
   1339      1.1  christos 		}
   1340      1.1  christos 	      else
   1341      1.1  christos 		{
   1342      1.1  christos 		  if (h->root.type == bfd_link_hash_defined
   1343      1.1  christos 		      || h->root.type == bfd_link_hash_defweak)
   1344      1.1  christos 		    sym_section = h->root.u.def.section;
   1345      1.1  christos 		}
   1346      1.1  christos 
   1347      1.1  christos 	      /* If the symbol is absolute then the relocation can
   1348      1.1  christos 		 be resolved during linking and there is no need for
   1349      1.1  christos 		 a dynamic reloc.  */
   1350      1.1  christos 	      if (sym_section != bfd_abs_section_ptr)
   1351      1.1  christos 		{
   1352      1.1  christos 		  /* When creating a shared object, we must copy these
   1353      1.1  christos 		     reloc types into the output file.  We create a reloc
   1354      1.1  christos 		     section in dynobj and make room for this reloc.  */
   1355      1.1  christos 		  if (sreloc == NULL)
   1356      1.1  christos 		    {
   1357      1.1  christos 		      sreloc = _bfd_elf_make_dynamic_reloc_section
   1358      1.1  christos 			(sec, dynobj, 2, abfd, /*rela?*/ TRUE);
   1359      1.1  christos 		      if (sreloc == NULL)
   1360      1.1  christos 			goto fail;
   1361      1.1  christos 		    }
   1362      1.1  christos 
   1363      1.1  christos 		  sreloc->size += sizeof (Elf32_External_Rela);
   1364      1.1  christos 		}
   1365      1.1  christos 	    }
   1366      1.1  christos 
   1367      1.1  christos 	  break;
   1368      1.1  christos 	}
   1369      1.1  christos 
   1370      1.1  christos       if (ELF32_R_TYPE (rel->r_info) != R_MN10300_SYM_DIFF)
   1371      1.1  christos 	sym_diff_reloc_seen = FALSE;
   1372      1.1  christos     }
   1373      1.1  christos 
   1374      1.1  christos   result = TRUE;
   1375      1.1  christos  fail:
   1376  1.1.1.9  christos   if (symtab_hdr->contents != (unsigned char *) isymbuf)
   1377      1.1  christos     free (isymbuf);
   1378      1.1  christos 
   1379      1.1  christos   return result;
   1380      1.1  christos }
   1381      1.1  christos 
   1382      1.1  christos /* Return the section that should be marked against GC for a given
   1383      1.1  christos    relocation.  */
   1384      1.1  christos 
   1385      1.1  christos static asection *
   1386      1.1  christos mn10300_elf_gc_mark_hook (asection *sec,
   1387      1.1  christos 			  struct bfd_link_info *info,
   1388      1.1  christos 			  Elf_Internal_Rela *rel,
   1389      1.1  christos 			  struct elf_link_hash_entry *h,
   1390      1.1  christos 			  Elf_Internal_Sym *sym)
   1391      1.1  christos {
   1392      1.1  christos   if (h != NULL)
   1393      1.1  christos     switch (ELF32_R_TYPE (rel->r_info))
   1394      1.1  christos       {
   1395      1.1  christos       case R_MN10300_GNU_VTINHERIT:
   1396      1.1  christos       case R_MN10300_GNU_VTENTRY:
   1397      1.1  christos 	return NULL;
   1398      1.1  christos       }
   1399      1.1  christos 
   1400      1.1  christos   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
   1401      1.1  christos }
   1402      1.1  christos 
   1403      1.1  christos /* Perform a relocation as part of a final link.  */
   1404      1.1  christos 
   1405      1.1  christos static bfd_reloc_status_type
   1406      1.1  christos mn10300_elf_final_link_relocate (reloc_howto_type *howto,
   1407      1.1  christos 				 bfd *input_bfd,
   1408      1.1  christos 				 bfd *output_bfd ATTRIBUTE_UNUSED,
   1409      1.1  christos 				 asection *input_section,
   1410      1.1  christos 				 bfd_byte *contents,
   1411      1.1  christos 				 bfd_vma offset,
   1412      1.1  christos 				 bfd_vma value,
   1413      1.1  christos 				 bfd_vma addend,
   1414      1.1  christos 				 struct elf_link_hash_entry * h,
   1415      1.1  christos 				 unsigned long symndx,
   1416      1.1  christos 				 struct bfd_link_info *info,
   1417      1.1  christos 				 asection *sym_sec ATTRIBUTE_UNUSED,
   1418      1.1  christos 				 int is_local ATTRIBUTE_UNUSED)
   1419      1.1  christos {
   1420  1.1.1.2  christos   struct elf32_mn10300_link_hash_table * htab = elf32_mn10300_hash_table (info);
   1421      1.1  christos   static asection *  sym_diff_section;
   1422      1.1  christos   static bfd_vma     sym_diff_value;
   1423      1.1  christos   bfd_boolean is_sym_diff_reloc;
   1424      1.1  christos   unsigned long r_type = howto->type;
   1425      1.1  christos   bfd_byte * hit_data = contents + offset;
   1426      1.1  christos   bfd *      dynobj;
   1427      1.1  christos   asection * sgot;
   1428      1.1  christos   asection * splt;
   1429      1.1  christos   asection * sreloc;
   1430      1.1  christos 
   1431      1.1  christos   dynobj = elf_hash_table (info)->dynobj;
   1432      1.1  christos   sgot   = NULL;
   1433      1.1  christos   splt   = NULL;
   1434      1.1  christos   sreloc = NULL;
   1435      1.1  christos 
   1436      1.1  christos   switch (r_type)
   1437      1.1  christos     {
   1438      1.1  christos     case R_MN10300_24:
   1439      1.1  christos     case R_MN10300_16:
   1440      1.1  christos     case R_MN10300_8:
   1441      1.1  christos     case R_MN10300_PCREL8:
   1442      1.1  christos     case R_MN10300_PCREL16:
   1443      1.1  christos     case R_MN10300_PCREL32:
   1444      1.1  christos     case R_MN10300_GOTOFF32:
   1445      1.1  christos     case R_MN10300_GOTOFF24:
   1446      1.1  christos     case R_MN10300_GOTOFF16:
   1447  1.1.1.6  christos       if (bfd_link_pic (info)
   1448      1.1  christos 	  && (input_section->flags & SEC_ALLOC) != 0
   1449      1.1  christos 	  && h != NULL
   1450      1.1  christos 	  && ! SYMBOL_REFERENCES_LOCAL (info, h))
   1451      1.1  christos 	return bfd_reloc_dangerous;
   1452  1.1.1.7  christos       /* Fall through.  */
   1453  1.1.1.2  christos     case R_MN10300_GOT32:
   1454  1.1.1.2  christos       /* Issue 2052223:
   1455  1.1.1.2  christos 	 Taking the address of a protected function in a shared library
   1456  1.1.1.2  christos 	 is illegal.  Issue an error message here.  */
   1457  1.1.1.6  christos       if (bfd_link_pic (info)
   1458  1.1.1.2  christos 	  && (input_section->flags & SEC_ALLOC) != 0
   1459  1.1.1.2  christos 	  && h != NULL
   1460  1.1.1.2  christos 	  && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED
   1461  1.1.1.2  christos 	  && (h->type == STT_FUNC || h->type == STT_GNU_IFUNC)
   1462  1.1.1.2  christos 	  && ! SYMBOL_REFERENCES_LOCAL (info, h))
   1463  1.1.1.2  christos 	return bfd_reloc_dangerous;
   1464      1.1  christos     }
   1465      1.1  christos 
   1466      1.1  christos   is_sym_diff_reloc = FALSE;
   1467      1.1  christos   if (sym_diff_section != NULL)
   1468      1.1  christos     {
   1469      1.1  christos       BFD_ASSERT (sym_diff_section == input_section);
   1470      1.1  christos 
   1471      1.1  christos       switch (r_type)
   1472      1.1  christos 	{
   1473      1.1  christos 	case R_MN10300_32:
   1474      1.1  christos 	case R_MN10300_24:
   1475      1.1  christos 	case R_MN10300_16:
   1476      1.1  christos 	case R_MN10300_8:
   1477      1.1  christos 	  value -= sym_diff_value;
   1478      1.1  christos 	  /* If we are computing a 32-bit value for the location lists
   1479      1.1  christos 	     and the result is 0 then we add one to the value.  A zero
   1480      1.1  christos 	     value can result because of linker relaxation deleteing
   1481      1.1  christos 	     prologue instructions and using a value of 1 (for the begin
   1482      1.1  christos 	     and end offsets in the location list entry) results in a
   1483      1.1  christos 	     nul entry which does not prevent the following entries from
   1484      1.1  christos 	     being parsed.  */
   1485      1.1  christos 	  if (r_type == R_MN10300_32
   1486      1.1  christos 	      && value == 0
   1487      1.1  christos 	      && strcmp (input_section->name, ".debug_loc") == 0)
   1488      1.1  christos 	    value = 1;
   1489      1.1  christos 	  sym_diff_section = NULL;
   1490      1.1  christos 	  is_sym_diff_reloc = TRUE;
   1491      1.1  christos 	  break;
   1492      1.1  christos 
   1493      1.1  christos 	default:
   1494      1.1  christos 	  sym_diff_section = NULL;
   1495      1.1  christos 	  break;
   1496      1.1  christos 	}
   1497      1.1  christos     }
   1498      1.1  christos 
   1499      1.1  christos   switch (r_type)
   1500      1.1  christos     {
   1501      1.1  christos     case R_MN10300_SYM_DIFF:
   1502      1.1  christos       BFD_ASSERT (addend == 0);
   1503      1.1  christos       /* Cache the input section and value.
   1504      1.1  christos 	 The offset is unreliable, since relaxation may
   1505      1.1  christos 	 have reduced the following reloc's offset.  */
   1506      1.1  christos       sym_diff_section = input_section;
   1507      1.1  christos       sym_diff_value = value;
   1508      1.1  christos       return bfd_reloc_ok;
   1509      1.1  christos 
   1510      1.1  christos     case R_MN10300_ALIGN:
   1511      1.1  christos     case R_MN10300_NONE:
   1512      1.1  christos       return bfd_reloc_ok;
   1513      1.1  christos 
   1514      1.1  christos     case R_MN10300_32:
   1515  1.1.1.6  christos       if (bfd_link_pic (info)
   1516      1.1  christos 	  /* Do not generate relocs when an R_MN10300_32 has been used
   1517      1.1  christos 	     with an R_MN10300_SYM_DIFF to compute a difference of two
   1518      1.1  christos 	     symbols.  */
   1519  1.1.1.8  christos 	  && !is_sym_diff_reloc
   1520      1.1  christos 	  /* Also, do not generate a reloc when the symbol associated
   1521      1.1  christos 	     with the R_MN10300_32 reloc is absolute - there is no
   1522      1.1  christos 	     need for a run time computation in this case.  */
   1523      1.1  christos 	  && sym_sec != bfd_abs_section_ptr
   1524      1.1  christos 	  /* If the section is not going to be allocated at load time
   1525      1.1  christos 	     then there is no need to generate relocs for it.  */
   1526      1.1  christos 	  && (input_section->flags & SEC_ALLOC) != 0)
   1527      1.1  christos 	{
   1528      1.1  christos 	  Elf_Internal_Rela outrel;
   1529      1.1  christos 	  bfd_boolean skip, relocate;
   1530      1.1  christos 
   1531      1.1  christos 	  /* When generating a shared object, these relocations are
   1532      1.1  christos 	     copied into the output file to be resolved at run
   1533      1.1  christos 	     time.  */
   1534      1.1  christos 	  if (sreloc == NULL)
   1535      1.1  christos 	    {
   1536      1.1  christos 	      sreloc = _bfd_elf_get_dynamic_reloc_section
   1537      1.1  christos 		(input_bfd, input_section, /*rela?*/ TRUE);
   1538      1.1  christos 	      if (sreloc == NULL)
   1539      1.1  christos 		return FALSE;
   1540      1.1  christos 	    }
   1541      1.1  christos 
   1542      1.1  christos 	  skip = FALSE;
   1543      1.1  christos 
   1544      1.1  christos 	  outrel.r_offset = _bfd_elf_section_offset (input_bfd, info,
   1545      1.1  christos 						     input_section, offset);
   1546      1.1  christos 	  if (outrel.r_offset == (bfd_vma) -1)
   1547      1.1  christos 	    skip = TRUE;
   1548      1.1  christos 
   1549      1.1  christos 	  outrel.r_offset += (input_section->output_section->vma
   1550      1.1  christos 			      + input_section->output_offset);
   1551      1.1  christos 
   1552      1.1  christos 	  if (skip)
   1553      1.1  christos 	    {
   1554      1.1  christos 	      memset (&outrel, 0, sizeof outrel);
   1555      1.1  christos 	      relocate = FALSE;
   1556      1.1  christos 	    }
   1557      1.1  christos 	  else
   1558      1.1  christos 	    {
   1559      1.1  christos 	      /* h->dynindx may be -1 if this symbol was marked to
   1560      1.1  christos 		 become local.  */
   1561      1.1  christos 	      if (h == NULL
   1562      1.1  christos 		  || SYMBOL_REFERENCES_LOCAL (info, h))
   1563      1.1  christos 		{
   1564      1.1  christos 		  relocate = TRUE;
   1565      1.1  christos 		  outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
   1566      1.1  christos 		  outrel.r_addend = value + addend;
   1567      1.1  christos 		}
   1568      1.1  christos 	      else
   1569      1.1  christos 		{
   1570      1.1  christos 		  BFD_ASSERT (h->dynindx != -1);
   1571      1.1  christos 		  relocate = FALSE;
   1572      1.1  christos 		  outrel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_32);
   1573      1.1  christos 		  outrel.r_addend = value + addend;
   1574      1.1  christos 		}
   1575      1.1  christos 	    }
   1576      1.1  christos 
   1577      1.1  christos 	  bfd_elf32_swap_reloca_out (output_bfd, &outrel,
   1578      1.1  christos 				     (bfd_byte *) (((Elf32_External_Rela *) sreloc->contents)
   1579      1.1  christos 						   + sreloc->reloc_count));
   1580      1.1  christos 	  ++sreloc->reloc_count;
   1581      1.1  christos 
   1582      1.1  christos 	  /* If this reloc is against an external symbol, we do
   1583      1.1  christos 	     not want to fiddle with the addend.  Otherwise, we
   1584      1.1  christos 	     need to include the symbol value so that it becomes
   1585      1.1  christos 	     an addend for the dynamic reloc.  */
   1586      1.1  christos 	  if (! relocate)
   1587      1.1  christos 	    return bfd_reloc_ok;
   1588      1.1  christos 	}
   1589      1.1  christos       value += addend;
   1590      1.1  christos       bfd_put_32 (input_bfd, value, hit_data);
   1591      1.1  christos       return bfd_reloc_ok;
   1592      1.1  christos 
   1593      1.1  christos     case R_MN10300_24:
   1594      1.1  christos       value += addend;
   1595      1.1  christos 
   1596      1.1  christos       if ((long) value > 0x7fffff || (long) value < -0x800000)
   1597      1.1  christos 	return bfd_reloc_overflow;
   1598      1.1  christos 
   1599      1.1  christos       bfd_put_8 (input_bfd, value & 0xff, hit_data);
   1600      1.1  christos       bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
   1601      1.1  christos       bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
   1602      1.1  christos       return bfd_reloc_ok;
   1603      1.1  christos 
   1604      1.1  christos     case R_MN10300_16:
   1605      1.1  christos       value += addend;
   1606      1.1  christos 
   1607      1.1  christos       if ((long) value > 0x7fff || (long) value < -0x8000)
   1608      1.1  christos 	return bfd_reloc_overflow;
   1609      1.1  christos 
   1610      1.1  christos       bfd_put_16 (input_bfd, value, hit_data);
   1611      1.1  christos       return bfd_reloc_ok;
   1612      1.1  christos 
   1613      1.1  christos     case R_MN10300_8:
   1614      1.1  christos       value += addend;
   1615      1.1  christos 
   1616      1.1  christos       if ((long) value > 0x7f || (long) value < -0x80)
   1617      1.1  christos 	return bfd_reloc_overflow;
   1618      1.1  christos 
   1619      1.1  christos       bfd_put_8 (input_bfd, value, hit_data);
   1620      1.1  christos       return bfd_reloc_ok;
   1621      1.1  christos 
   1622      1.1  christos     case R_MN10300_PCREL8:
   1623      1.1  christos       value -= (input_section->output_section->vma
   1624      1.1  christos 		+ input_section->output_offset);
   1625      1.1  christos       value -= offset;
   1626      1.1  christos       value += addend;
   1627      1.1  christos 
   1628      1.1  christos       if ((long) value > 0x7f || (long) value < -0x80)
   1629      1.1  christos 	return bfd_reloc_overflow;
   1630      1.1  christos 
   1631      1.1  christos       bfd_put_8 (input_bfd, value, hit_data);
   1632      1.1  christos       return bfd_reloc_ok;
   1633      1.1  christos 
   1634      1.1  christos     case R_MN10300_PCREL16:
   1635      1.1  christos       value -= (input_section->output_section->vma
   1636      1.1  christos 		+ input_section->output_offset);
   1637      1.1  christos       value -= offset;
   1638      1.1  christos       value += addend;
   1639      1.1  christos 
   1640      1.1  christos       if ((long) value > 0x7fff || (long) value < -0x8000)
   1641      1.1  christos 	return bfd_reloc_overflow;
   1642      1.1  christos 
   1643      1.1  christos       bfd_put_16 (input_bfd, value, hit_data);
   1644      1.1  christos       return bfd_reloc_ok;
   1645      1.1  christos 
   1646      1.1  christos     case R_MN10300_PCREL32:
   1647      1.1  christos       value -= (input_section->output_section->vma
   1648      1.1  christos 		+ input_section->output_offset);
   1649      1.1  christos       value -= offset;
   1650      1.1  christos       value += addend;
   1651      1.1  christos 
   1652      1.1  christos       bfd_put_32 (input_bfd, value, hit_data);
   1653      1.1  christos       return bfd_reloc_ok;
   1654      1.1  christos 
   1655      1.1  christos     case R_MN10300_GNU_VTINHERIT:
   1656      1.1  christos     case R_MN10300_GNU_VTENTRY:
   1657      1.1  christos       return bfd_reloc_ok;
   1658      1.1  christos 
   1659      1.1  christos     case R_MN10300_GOTPC32:
   1660  1.1.1.2  christos       if (dynobj == NULL)
   1661  1.1.1.2  christos 	return bfd_reloc_dangerous;
   1662  1.1.1.2  christos 
   1663      1.1  christos       /* Use global offset table as symbol value.  */
   1664  1.1.1.2  christos       value = htab->root.sgot->output_section->vma;
   1665      1.1  christos       value -= (input_section->output_section->vma
   1666      1.1  christos 		+ input_section->output_offset);
   1667      1.1  christos       value -= offset;
   1668      1.1  christos       value += addend;
   1669      1.1  christos 
   1670      1.1  christos       bfd_put_32 (input_bfd, value, hit_data);
   1671      1.1  christos       return bfd_reloc_ok;
   1672      1.1  christos 
   1673      1.1  christos     case R_MN10300_GOTPC16:
   1674  1.1.1.2  christos       if (dynobj == NULL)
   1675  1.1.1.2  christos 	return bfd_reloc_dangerous;
   1676  1.1.1.2  christos 
   1677      1.1  christos       /* Use global offset table as symbol value.  */
   1678  1.1.1.2  christos       value = htab->root.sgot->output_section->vma;
   1679      1.1  christos       value -= (input_section->output_section->vma
   1680      1.1  christos 		+ input_section->output_offset);
   1681      1.1  christos       value -= offset;
   1682      1.1  christos       value += addend;
   1683      1.1  christos 
   1684      1.1  christos       if ((long) value > 0x7fff || (long) value < -0x8000)
   1685      1.1  christos 	return bfd_reloc_overflow;
   1686      1.1  christos 
   1687      1.1  christos       bfd_put_16 (input_bfd, value, hit_data);
   1688      1.1  christos       return bfd_reloc_ok;
   1689      1.1  christos 
   1690      1.1  christos     case R_MN10300_GOTOFF32:
   1691  1.1.1.2  christos       if (dynobj == NULL)
   1692  1.1.1.2  christos 	return bfd_reloc_dangerous;
   1693  1.1.1.2  christos 
   1694  1.1.1.2  christos       value -= htab->root.sgot->output_section->vma;
   1695      1.1  christos       value += addend;
   1696      1.1  christos 
   1697      1.1  christos       bfd_put_32 (input_bfd, value, hit_data);
   1698      1.1  christos       return bfd_reloc_ok;
   1699      1.1  christos 
   1700      1.1  christos     case R_MN10300_GOTOFF24:
   1701  1.1.1.2  christos       if (dynobj == NULL)
   1702  1.1.1.2  christos 	return bfd_reloc_dangerous;
   1703  1.1.1.2  christos 
   1704  1.1.1.2  christos       value -= htab->root.sgot->output_section->vma;
   1705      1.1  christos       value += addend;
   1706      1.1  christos 
   1707      1.1  christos       if ((long) value > 0x7fffff || (long) value < -0x800000)
   1708      1.1  christos 	return bfd_reloc_overflow;
   1709      1.1  christos 
   1710      1.1  christos       bfd_put_8 (input_bfd, value, hit_data);
   1711      1.1  christos       bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
   1712      1.1  christos       bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
   1713      1.1  christos       return bfd_reloc_ok;
   1714      1.1  christos 
   1715      1.1  christos     case R_MN10300_GOTOFF16:
   1716  1.1.1.2  christos       if (dynobj == NULL)
   1717  1.1.1.2  christos 	return bfd_reloc_dangerous;
   1718  1.1.1.2  christos 
   1719  1.1.1.2  christos       value -= htab->root.sgot->output_section->vma;
   1720      1.1  christos       value += addend;
   1721      1.1  christos 
   1722      1.1  christos       if ((long) value > 0x7fff || (long) value < -0x8000)
   1723      1.1  christos 	return bfd_reloc_overflow;
   1724      1.1  christos 
   1725      1.1  christos       bfd_put_16 (input_bfd, value, hit_data);
   1726      1.1  christos       return bfd_reloc_ok;
   1727      1.1  christos 
   1728      1.1  christos     case R_MN10300_PLT32:
   1729      1.1  christos       if (h != NULL
   1730      1.1  christos 	  && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
   1731      1.1  christos 	  && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
   1732      1.1  christos 	  && h->plt.offset != (bfd_vma) -1)
   1733      1.1  christos 	{
   1734  1.1.1.2  christos 	  if (dynobj == NULL)
   1735  1.1.1.2  christos 	    return bfd_reloc_dangerous;
   1736      1.1  christos 
   1737  1.1.1.2  christos 	  splt = htab->root.splt;
   1738      1.1  christos 	  value = (splt->output_section->vma
   1739      1.1  christos 		   + splt->output_offset
   1740      1.1  christos 		   + h->plt.offset) - value;
   1741      1.1  christos 	}
   1742      1.1  christos 
   1743      1.1  christos       value -= (input_section->output_section->vma
   1744      1.1  christos 		+ input_section->output_offset);
   1745      1.1  christos       value -= offset;
   1746      1.1  christos       value += addend;
   1747      1.1  christos 
   1748      1.1  christos       bfd_put_32 (input_bfd, value, hit_data);
   1749      1.1  christos       return bfd_reloc_ok;
   1750      1.1  christos 
   1751      1.1  christos     case R_MN10300_PLT16:
   1752      1.1  christos       if (h != NULL
   1753      1.1  christos 	  && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
   1754      1.1  christos 	  && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
   1755      1.1  christos 	  && h->plt.offset != (bfd_vma) -1)
   1756      1.1  christos 	{
   1757  1.1.1.2  christos 	  if (dynobj == NULL)
   1758  1.1.1.2  christos 	    return bfd_reloc_dangerous;
   1759      1.1  christos 
   1760  1.1.1.2  christos 	  splt = htab->root.splt;
   1761      1.1  christos 	  value = (splt->output_section->vma
   1762      1.1  christos 		   + splt->output_offset
   1763      1.1  christos 		   + h->plt.offset) - value;
   1764      1.1  christos 	}
   1765      1.1  christos 
   1766      1.1  christos       value -= (input_section->output_section->vma
   1767      1.1  christos 		+ input_section->output_offset);
   1768      1.1  christos       value -= offset;
   1769      1.1  christos       value += addend;
   1770      1.1  christos 
   1771      1.1  christos       if ((long) value > 0x7fff || (long) value < -0x8000)
   1772      1.1  christos 	return bfd_reloc_overflow;
   1773      1.1  christos 
   1774      1.1  christos       bfd_put_16 (input_bfd, value, hit_data);
   1775      1.1  christos       return bfd_reloc_ok;
   1776      1.1  christos 
   1777  1.1.1.2  christos     case R_MN10300_TLS_LDO:
   1778  1.1.1.2  christos       value = dtpoff (info, value);
   1779  1.1.1.2  christos       bfd_put_32 (input_bfd, value + addend, hit_data);
   1780  1.1.1.2  christos       return bfd_reloc_ok;
   1781  1.1.1.2  christos 
   1782  1.1.1.2  christos     case R_MN10300_TLS_LE:
   1783  1.1.1.2  christos       value = tpoff (info, value);
   1784  1.1.1.2  christos       bfd_put_32 (input_bfd, value + addend, hit_data);
   1785  1.1.1.2  christos       return bfd_reloc_ok;
   1786  1.1.1.2  christos 
   1787  1.1.1.2  christos     case R_MN10300_TLS_LD:
   1788  1.1.1.2  christos       if (dynobj == NULL)
   1789  1.1.1.2  christos 	return bfd_reloc_dangerous;
   1790  1.1.1.2  christos 
   1791  1.1.1.2  christos       sgot = htab->root.sgot;
   1792  1.1.1.2  christos       BFD_ASSERT (sgot != NULL);
   1793  1.1.1.2  christos       value = htab->tls_ldm_got.offset + sgot->output_offset;
   1794  1.1.1.2  christos       bfd_put_32 (input_bfd, value, hit_data);
   1795  1.1.1.2  christos 
   1796  1.1.1.2  christos       if (!htab->tls_ldm_got.rel_emitted)
   1797  1.1.1.2  christos 	{
   1798  1.1.1.7  christos 	  asection *srelgot = htab->root.srelgot;
   1799  1.1.1.2  christos 	  Elf_Internal_Rela rel;
   1800  1.1.1.2  christos 
   1801  1.1.1.2  christos 	  BFD_ASSERT (srelgot != NULL);
   1802  1.1.1.2  christos 	  htab->tls_ldm_got.rel_emitted ++;
   1803  1.1.1.2  christos 	  rel.r_offset = (sgot->output_section->vma
   1804  1.1.1.2  christos 			  + sgot->output_offset
   1805  1.1.1.2  christos 			  + htab->tls_ldm_got.offset);
   1806  1.1.1.2  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + htab->tls_ldm_got.offset);
   1807  1.1.1.2  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + htab->tls_ldm_got.offset+4);
   1808  1.1.1.2  christos 	  rel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPMOD);
   1809  1.1.1.2  christos 	  rel.r_addend = 0;
   1810  1.1.1.2  christos 	  bfd_elf32_swap_reloca_out (output_bfd, & rel,
   1811  1.1.1.2  christos 				     (bfd_byte *) ((Elf32_External_Rela *) srelgot->contents
   1812  1.1.1.2  christos 						   + srelgot->reloc_count));
   1813  1.1.1.2  christos 	  ++ srelgot->reloc_count;
   1814  1.1.1.2  christos 	}
   1815  1.1.1.2  christos 
   1816  1.1.1.2  christos       return bfd_reloc_ok;
   1817  1.1.1.2  christos 
   1818  1.1.1.2  christos     case R_MN10300_TLS_GOTIE:
   1819  1.1.1.2  christos       value = tpoff (info, value);
   1820  1.1.1.2  christos       /* Fall Through.  */
   1821  1.1.1.2  christos 
   1822  1.1.1.2  christos     case R_MN10300_TLS_GD:
   1823  1.1.1.2  christos     case R_MN10300_TLS_IE:
   1824      1.1  christos     case R_MN10300_GOT32:
   1825      1.1  christos     case R_MN10300_GOT24:
   1826      1.1  christos     case R_MN10300_GOT16:
   1827  1.1.1.2  christos       if (dynobj == NULL)
   1828  1.1.1.2  christos 	return bfd_reloc_dangerous;
   1829      1.1  christos 
   1830  1.1.1.2  christos       sgot = htab->root.sgot;
   1831  1.1.1.2  christos       if (r_type == R_MN10300_TLS_GD)
   1832  1.1.1.2  christos 	value = dtpoff (info, value);
   1833  1.1.1.2  christos 
   1834  1.1.1.2  christos       if (h != NULL)
   1835  1.1.1.2  christos 	{
   1836  1.1.1.2  christos 	  bfd_vma off;
   1837  1.1.1.2  christos 
   1838  1.1.1.2  christos 	  off = h->got.offset;
   1839  1.1.1.2  christos 	  /* Offsets in the GOT are allocated in check_relocs
   1840  1.1.1.2  christos 	     which is not called for shared libraries... */
   1841  1.1.1.2  christos 	  if (off == (bfd_vma) -1)
   1842  1.1.1.2  christos 	    off = 0;
   1843  1.1.1.2  christos 
   1844  1.1.1.2  christos 	  if (sgot->contents != NULL
   1845  1.1.1.2  christos 	      && (! elf_hash_table (info)->dynamic_sections_created
   1846  1.1.1.2  christos 		  || SYMBOL_REFERENCES_LOCAL (info, h)))
   1847  1.1.1.2  christos 	    /* This is actually a static link, or it is a
   1848  1.1.1.2  christos 	       -Bsymbolic link and the symbol is defined
   1849  1.1.1.2  christos 	       locally, or the symbol was forced to be local
   1850  1.1.1.2  christos 	       because of a version file.  We must initialize
   1851  1.1.1.2  christos 	       this entry in the global offset table.
   1852  1.1.1.2  christos 
   1853  1.1.1.2  christos 	       When doing a dynamic link, we create a .rela.got
   1854  1.1.1.2  christos 	       relocation entry to initialize the value.  This
   1855  1.1.1.2  christos 	       is done in the finish_dynamic_symbol routine.  */
   1856  1.1.1.2  christos 	    bfd_put_32 (output_bfd, value,
   1857  1.1.1.2  christos 			sgot->contents + off);
   1858      1.1  christos 
   1859  1.1.1.2  christos 	  value = sgot->output_offset + off;
   1860  1.1.1.2  christos 	}
   1861  1.1.1.2  christos       else
   1862  1.1.1.2  christos 	{
   1863  1.1.1.2  christos 	  bfd_vma off;
   1864      1.1  christos 
   1865  1.1.1.2  christos 	  off = elf_local_got_offsets (input_bfd)[symndx];
   1866      1.1  christos 
   1867  1.1.1.2  christos 	  if (off & 1)
   1868  1.1.1.2  christos 	    bfd_put_32 (output_bfd, value, sgot->contents + (off & ~ 1));
   1869      1.1  christos 	  else
   1870      1.1  christos 	    {
   1871      1.1  christos 	      bfd_put_32 (output_bfd, value, sgot->contents + off);
   1872      1.1  christos 
   1873  1.1.1.6  christos 	      if (bfd_link_pic (info))
   1874      1.1  christos 		{
   1875  1.1.1.7  christos 		  asection *srelgot = htab->root.srelgot;;
   1876      1.1  christos 		  Elf_Internal_Rela outrel;
   1877      1.1  christos 
   1878      1.1  christos 		  BFD_ASSERT (srelgot != NULL);
   1879      1.1  christos 
   1880      1.1  christos 		  outrel.r_offset = (sgot->output_section->vma
   1881      1.1  christos 				     + sgot->output_offset
   1882      1.1  christos 				     + off);
   1883  1.1.1.2  christos 		  switch (r_type)
   1884  1.1.1.2  christos 		    {
   1885  1.1.1.2  christos 		    case R_MN10300_TLS_GD:
   1886  1.1.1.2  christos 		      outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPOFF);
   1887  1.1.1.2  christos 		      outrel.r_offset = (sgot->output_section->vma
   1888  1.1.1.2  christos 					 + sgot->output_offset
   1889  1.1.1.2  christos 					 + off + 4);
   1890  1.1.1.2  christos 		      bfd_elf32_swap_reloca_out (output_bfd, & outrel,
   1891  1.1.1.2  christos 						 (bfd_byte *) (((Elf32_External_Rela *)
   1892  1.1.1.2  christos 								srelgot->contents)
   1893  1.1.1.2  christos 							       + srelgot->reloc_count));
   1894  1.1.1.2  christos 		      ++ srelgot->reloc_count;
   1895  1.1.1.2  christos 		      outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPMOD);
   1896  1.1.1.2  christos 		      break;
   1897  1.1.1.2  christos 		    case R_MN10300_TLS_GOTIE:
   1898  1.1.1.2  christos 		    case R_MN10300_TLS_IE:
   1899  1.1.1.2  christos 		      outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_TPOFF);
   1900  1.1.1.2  christos 		      break;
   1901  1.1.1.2  christos 		    default:
   1902  1.1.1.2  christos 		      outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
   1903  1.1.1.2  christos 		      break;
   1904  1.1.1.2  christos 		    }
   1905  1.1.1.2  christos 
   1906      1.1  christos 		  outrel.r_addend = value;
   1907      1.1  christos 		  bfd_elf32_swap_reloca_out (output_bfd, &outrel,
   1908      1.1  christos 					     (bfd_byte *) (((Elf32_External_Rela *)
   1909      1.1  christos 							    srelgot->contents)
   1910      1.1  christos 							   + srelgot->reloc_count));
   1911      1.1  christos 		  ++ srelgot->reloc_count;
   1912  1.1.1.2  christos 		  elf_local_got_offsets (input_bfd)[symndx] |= 1;
   1913      1.1  christos 		}
   1914      1.1  christos 
   1915  1.1.1.2  christos 	      value = sgot->output_offset + (off & ~(bfd_vma) 1);
   1916      1.1  christos 	    }
   1917  1.1.1.2  christos 	}
   1918      1.1  christos 
   1919      1.1  christos       value += addend;
   1920      1.1  christos 
   1921  1.1.1.2  christos       if (r_type == R_MN10300_TLS_IE)
   1922  1.1.1.2  christos 	{
   1923  1.1.1.2  christos 	  value += sgot->output_section->vma;
   1924  1.1.1.2  christos 	  bfd_put_32 (input_bfd, value, hit_data);
   1925  1.1.1.2  christos 	  return bfd_reloc_ok;
   1926  1.1.1.2  christos 	}
   1927  1.1.1.2  christos       else if (r_type == R_MN10300_TLS_GOTIE
   1928  1.1.1.2  christos 	       || r_type == R_MN10300_TLS_GD
   1929  1.1.1.2  christos 	       || r_type == R_MN10300_TLS_LD)
   1930  1.1.1.2  christos 	{
   1931  1.1.1.2  christos 	  bfd_put_32 (input_bfd, value, hit_data);
   1932  1.1.1.2  christos 	  return bfd_reloc_ok;
   1933  1.1.1.2  christos 	}
   1934  1.1.1.2  christos       else if (r_type == R_MN10300_GOT32)
   1935      1.1  christos 	{
   1936      1.1  christos 	  bfd_put_32 (input_bfd, value, hit_data);
   1937      1.1  christos 	  return bfd_reloc_ok;
   1938      1.1  christos 	}
   1939      1.1  christos       else if (r_type == R_MN10300_GOT24)
   1940      1.1  christos 	{
   1941      1.1  christos 	  if ((long) value > 0x7fffff || (long) value < -0x800000)
   1942      1.1  christos 	    return bfd_reloc_overflow;
   1943      1.1  christos 
   1944      1.1  christos 	  bfd_put_8 (input_bfd, value & 0xff, hit_data);
   1945      1.1  christos 	  bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
   1946      1.1  christos 	  bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
   1947      1.1  christos 	  return bfd_reloc_ok;
   1948      1.1  christos 	}
   1949      1.1  christos       else if (r_type == R_MN10300_GOT16)
   1950      1.1  christos 	{
   1951      1.1  christos 	  if ((long) value > 0x7fff || (long) value < -0x8000)
   1952      1.1  christos 	    return bfd_reloc_overflow;
   1953      1.1  christos 
   1954      1.1  christos 	  bfd_put_16 (input_bfd, value, hit_data);
   1955      1.1  christos 	  return bfd_reloc_ok;
   1956      1.1  christos 	}
   1957      1.1  christos       /* Fall through.  */
   1958      1.1  christos 
   1959      1.1  christos     default:
   1960      1.1  christos       return bfd_reloc_notsupported;
   1961      1.1  christos     }
   1962      1.1  christos }
   1963      1.1  christos 
   1964      1.1  christos /* Relocate an MN10300 ELF section.  */
   1966      1.1  christos 
   1967      1.1  christos static bfd_boolean
   1968      1.1  christos mn10300_elf_relocate_section (bfd *output_bfd,
   1969      1.1  christos 			      struct bfd_link_info *info,
   1970      1.1  christos 			      bfd *input_bfd,
   1971      1.1  christos 			      asection *input_section,
   1972      1.1  christos 			      bfd_byte *contents,
   1973      1.1  christos 			      Elf_Internal_Rela *relocs,
   1974      1.1  christos 			      Elf_Internal_Sym *local_syms,
   1975      1.1  christos 			      asection **local_sections)
   1976      1.1  christos {
   1977      1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   1978      1.1  christos   struct elf_link_hash_entry **sym_hashes;
   1979  1.1.1.2  christos   Elf_Internal_Rela *rel, *relend;
   1980      1.1  christos   Elf_Internal_Rela * trel;
   1981      1.1  christos 
   1982      1.1  christos   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   1983      1.1  christos   sym_hashes = elf_sym_hashes (input_bfd);
   1984      1.1  christos 
   1985      1.1  christos   rel = relocs;
   1986      1.1  christos   relend = relocs + input_section->reloc_count;
   1987      1.1  christos   for (; rel < relend; rel++)
   1988      1.1  christos     {
   1989      1.1  christos       int r_type;
   1990      1.1  christos       reloc_howto_type *howto;
   1991      1.1  christos       unsigned long r_symndx;
   1992      1.1  christos       Elf_Internal_Sym *sym;
   1993      1.1  christos       asection *sec;
   1994      1.1  christos       struct elf32_mn10300_link_hash_entry *h;
   1995      1.1  christos       bfd_vma relocation;
   1996  1.1.1.2  christos       bfd_reloc_status_type r;
   1997  1.1.1.2  christos       int tls_r_type;
   1998  1.1.1.3  christos       bfd_boolean unresolved_reloc = FALSE;
   1999  1.1.1.2  christos       bfd_boolean warned, ignored;
   2000      1.1  christos       struct elf_link_hash_entry * hh;
   2001  1.1.1.2  christos 
   2002      1.1  christos       relocation = 0;
   2003      1.1  christos       r_symndx = ELF32_R_SYM (rel->r_info);
   2004      1.1  christos       r_type = ELF32_R_TYPE (rel->r_info);
   2005      1.1  christos       howto = elf_mn10300_howto_table + r_type;
   2006      1.1  christos 
   2007      1.1  christos       /* Just skip the vtable gc relocs.  */
   2008      1.1  christos       if (r_type == R_MN10300_GNU_VTINHERIT
   2009      1.1  christos 	  || r_type == R_MN10300_GNU_VTENTRY)
   2010      1.1  christos 	continue;
   2011      1.1  christos 
   2012      1.1  christos       h = NULL;
   2013      1.1  christos       sym = NULL;
   2014      1.1  christos       sec = NULL;
   2015  1.1.1.2  christos       if (r_symndx < symtab_hdr->sh_info)
   2016      1.1  christos 	hh = NULL;
   2017      1.1  christos       else
   2018      1.1  christos 	{
   2019      1.1  christos 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
   2020      1.1  christos 				   r_symndx, symtab_hdr, sym_hashes,
   2021  1.1.1.3  christos 				   hh, sec, relocation,
   2022  1.1.1.2  christos 				   unresolved_reloc, warned, ignored);
   2023  1.1.1.2  christos 	}
   2024  1.1.1.2  christos       h = elf_mn10300_hash_entry (hh);
   2025  1.1.1.2  christos 
   2026  1.1.1.2  christos       tls_r_type = elf_mn10300_tls_transition (info, r_type, hh, input_section, 0);
   2027  1.1.1.2  christos       if (tls_r_type != r_type)
   2028  1.1.1.2  christos 	{
   2029      1.1  christos 	  bfd_boolean had_plt;
   2030  1.1.1.2  christos 
   2031  1.1.1.2  christos 	  had_plt = mn10300_do_tls_transition (input_bfd, r_type, tls_r_type,
   2032  1.1.1.2  christos 					       contents, rel->r_offset);
   2033  1.1.1.2  christos 	  r_type = tls_r_type;
   2034  1.1.1.2  christos 	  howto = elf_mn10300_howto_table + r_type;
   2035  1.1.1.2  christos 
   2036  1.1.1.2  christos 	  if (had_plt)
   2037  1.1.1.2  christos 	    for (trel = rel+1; trel < relend; trel++)
   2038  1.1.1.2  christos 	      if ((ELF32_R_TYPE (trel->r_info) == R_MN10300_PLT32
   2039  1.1.1.2  christos 		   || ELF32_R_TYPE (trel->r_info) == R_MN10300_PCREL32)
   2040  1.1.1.2  christos 		  && rel->r_offset + had_plt == trel->r_offset)
   2041  1.1.1.2  christos 		trel->r_info = ELF32_R_INFO (0, R_MN10300_NONE);
   2042      1.1  christos 	}
   2043  1.1.1.2  christos 
   2044  1.1.1.2  christos       if (r_symndx < symtab_hdr->sh_info)
   2045  1.1.1.2  christos 	{
   2046  1.1.1.2  christos 	  sym = local_syms + r_symndx;
   2047  1.1.1.2  christos 	  sec = local_sections[r_symndx];
   2048  1.1.1.2  christos 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
   2049  1.1.1.2  christos 	}
   2050  1.1.1.2  christos       else
   2051      1.1  christos 	{
   2052      1.1  christos 	  if ((h->root.root.type == bfd_link_hash_defined
   2053      1.1  christos 	      || h->root.root.type == bfd_link_hash_defweak)
   2054      1.1  christos 	      && (   r_type == R_MN10300_GOTPC32
   2055      1.1  christos 		  || r_type == R_MN10300_GOTPC16
   2056      1.1  christos 		  || ((   r_type == R_MN10300_PLT32
   2057      1.1  christos 		       || r_type == R_MN10300_PLT16)
   2058      1.1  christos 		      && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
   2059      1.1  christos 		      && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
   2060      1.1  christos 		      && h->root.plt.offset != (bfd_vma) -1)
   2061      1.1  christos 		  || ((   r_type == R_MN10300_GOT32
   2062  1.1.1.2  christos 		       || r_type == R_MN10300_GOT24
   2063  1.1.1.2  christos 		       || r_type == R_MN10300_TLS_GD
   2064  1.1.1.2  christos 		       || r_type == R_MN10300_TLS_LD
   2065  1.1.1.2  christos 		       || r_type == R_MN10300_TLS_GOTIE
   2066      1.1  christos 		       || r_type == R_MN10300_TLS_IE
   2067      1.1  christos 		       || r_type == R_MN10300_GOT16)
   2068      1.1  christos 		      && elf_hash_table (info)->dynamic_sections_created
   2069      1.1  christos 		      && !SYMBOL_REFERENCES_LOCAL (info, hh))
   2070  1.1.1.9  christos 		  || (r_type == R_MN10300_32
   2071      1.1  christos 		      && !SYMBOL_REFERENCES_LOCAL (info, hh)
   2072      1.1  christos 		      /* _32 relocs in executables force _COPY relocs,
   2073      1.1  christos 			 such that the address of the symbol ends up
   2074  1.1.1.9  christos 			 being local.  */
   2075  1.1.1.9  christos 		      && (((input_section->flags & SEC_ALLOC) != 0
   2076      1.1  christos 			   && !bfd_link_executable (info))
   2077      1.1  christos 			  /* DWARF will emit R_MN10300_32 relocations
   2078      1.1  christos 			     in its sections against symbols defined
   2079      1.1  christos 			     externally in shared libraries.  We can't
   2080      1.1  christos 			     do anything with them here.  */
   2081      1.1  christos 			  || ((input_section->flags & SEC_DEBUGGING) != 0
   2082      1.1  christos 			      && h->root.def_dynamic)))))
   2083      1.1  christos 	    /* In these cases, we don't need the relocation
   2084      1.1  christos 	       value.  We check specially because in some
   2085      1.1  christos 	       obscure cases sec->output_section will be NULL.  */
   2086      1.1  christos 	    relocation = 0;
   2087  1.1.1.6  christos 
   2088  1.1.1.2  christos 	  else if (!bfd_link_relocatable (info) && unresolved_reloc
   2089  1.1.1.2  christos 		   && _bfd_elf_section_offset (output_bfd, info, input_section,
   2090  1.1.1.2  christos 					       rel->r_offset) != (bfd_vma) -1)
   2091  1.1.1.7  christos 
   2092  1.1.1.7  christos 	    _bfd_error_handler
   2093  1.1.1.8  christos 	      /* xgettext:c-format */
   2094  1.1.1.8  christos 	      (_("%pB(%pA+%#" PRIx64 "): "
   2095      1.1  christos 		 "unresolvable %s relocation against symbol `%s'"),
   2096      1.1  christos 	       input_bfd,
   2097  1.1.1.8  christos 	       input_section,
   2098      1.1  christos 	       (uint64_t) rel->r_offset,
   2099      1.1  christos 	       howto->name,
   2100      1.1  christos 	       h->root.root.root.string);
   2101      1.1  christos 	}
   2102  1.1.1.2  christos 
   2103      1.1  christos       if (sec != NULL && discarded_section (sec))
   2104  1.1.1.2  christos 	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   2105      1.1  christos 					 rel, 1, relend, howto, 0, contents);
   2106  1.1.1.6  christos 
   2107      1.1  christos       if (bfd_link_relocatable (info))
   2108      1.1  christos 	continue;
   2109      1.1  christos 
   2110      1.1  christos       r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
   2111      1.1  christos 					   input_section,
   2112      1.1  christos 					   contents, rel->r_offset,
   2113      1.1  christos 					   relocation, rel->r_addend,
   2114      1.1  christos 					   (struct elf_link_hash_entry *) h,
   2115      1.1  christos 					   r_symndx,
   2116      1.1  christos 					   info, sec, h == NULL);
   2117      1.1  christos 
   2118      1.1  christos       if (r != bfd_reloc_ok)
   2119      1.1  christos 	{
   2120      1.1  christos 	  const char *name;
   2121      1.1  christos 	  const char *msg = NULL;
   2122      1.1  christos 
   2123      1.1  christos 	  if (h != NULL)
   2124      1.1  christos 	    name = h->root.root.root.string;
   2125      1.1  christos 	  else
   2126      1.1  christos 	    {
   2127      1.1  christos 	      name = (bfd_elf_string_from_elf_section
   2128      1.1  christos 		      (input_bfd, symtab_hdr->sh_link, sym->st_name));
   2129  1.1.1.9  christos 	      if (name == NULL || *name == '\0')
   2130      1.1  christos 		name = bfd_section_name (sec);
   2131      1.1  christos 	    }
   2132      1.1  christos 
   2133      1.1  christos 	  switch (r)
   2134      1.1  christos 	    {
   2135  1.1.1.6  christos 	    case bfd_reloc_overflow:
   2136  1.1.1.6  christos 	      (*info->callbacks->reloc_overflow)
   2137  1.1.1.6  christos 		(info, (h ? &h->root.root : NULL), name, howto->name,
   2138      1.1  christos 		 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
   2139      1.1  christos 	      break;
   2140      1.1  christos 
   2141  1.1.1.6  christos 	    case bfd_reloc_undefined:
   2142  1.1.1.6  christos 	      (*info->callbacks->undefined_symbol)
   2143      1.1  christos 		(info, name, input_bfd, input_section, rel->r_offset, TRUE);
   2144      1.1  christos 	      break;
   2145      1.1  christos 
   2146      1.1  christos 	    case bfd_reloc_outofrange:
   2147      1.1  christos 	      msg = _("internal error: out of range error");
   2148      1.1  christos 	      goto common_error;
   2149      1.1  christos 
   2150      1.1  christos 	    case bfd_reloc_notsupported:
   2151      1.1  christos 	      msg = _("internal error: unsupported relocation error");
   2152      1.1  christos 	      goto common_error;
   2153      1.1  christos 
   2154      1.1  christos 	    case bfd_reloc_dangerous:
   2155      1.1  christos 	      if (r_type == R_MN10300_PCREL32)
   2156      1.1  christos 		msg = _("error: inappropriate relocation type for shared"
   2157  1.1.1.2  christos 			" library (did you forget -fpic?)");
   2158  1.1.1.7  christos 	      else if (r_type == R_MN10300_GOT32)
   2159  1.1.1.8  christos 		/* xgettext:c-format */
   2160  1.1.1.2  christos 		msg = _("%pB: taking the address of protected function"
   2161      1.1  christos 			" '%s' cannot be done when making a shared library");
   2162      1.1  christos 	      else
   2163      1.1  christos 		msg = _("internal error: suspicious relocation type used"
   2164      1.1  christos 			" in shared library");
   2165      1.1  christos 	      goto common_error;
   2166      1.1  christos 
   2167      1.1  christos 	    default:
   2168      1.1  christos 	      msg = _("internal error: unknown error");
   2169      1.1  christos 	      /* Fall through.  */
   2170      1.1  christos 
   2171  1.1.1.2  christos 	    common_error:
   2172  1.1.1.2  christos 	      _bfd_error_handler (msg, input_bfd, name);
   2173  1.1.1.2  christos 	      bfd_set_error (bfd_error_bad_value);
   2174      1.1  christos 	      return FALSE;
   2175      1.1  christos 	    }
   2176      1.1  christos 	}
   2177      1.1  christos     }
   2178      1.1  christos 
   2179      1.1  christos   return TRUE;
   2180      1.1  christos }
   2181      1.1  christos 
   2182      1.1  christos /* Finish initializing one hash table entry.  */
   2183      1.1  christos 
   2184      1.1  christos static bfd_boolean
   2185      1.1  christos elf32_mn10300_finish_hash_table_entry (struct bfd_hash_entry *gen_entry,
   2186      1.1  christos 				       void * in_args)
   2187      1.1  christos {
   2188      1.1  christos   struct elf32_mn10300_link_hash_entry *entry;
   2189      1.1  christos   struct bfd_link_info *link_info = (struct bfd_link_info *) in_args;
   2190      1.1  christos   unsigned int byte_count = 0;
   2191      1.1  christos 
   2192      1.1  christos   entry = (struct elf32_mn10300_link_hash_entry *) gen_entry;
   2193      1.1  christos 
   2194      1.1  christos   /* If we already know we want to convert "call" to "calls" for calls
   2195      1.1  christos      to this symbol, then return now.  */
   2196      1.1  christos   if (entry->flags == MN10300_CONVERT_CALL_TO_CALLS)
   2197      1.1  christos     return TRUE;
   2198      1.1  christos 
   2199      1.1  christos   /* If there are no named calls to this symbol, or there's nothing we
   2200      1.1  christos      can move from the function itself into the "call" instruction,
   2201      1.1  christos      then note that all "call" instructions should be converted into
   2202      1.1  christos      "calls" instructions and return.  If a symbol is available for
   2203      1.1  christos      dynamic symbol resolution (overridable or overriding), avoid
   2204      1.1  christos      custom calling conventions.  */
   2205      1.1  christos   if (entry->direct_calls == 0
   2206      1.1  christos       || (entry->stack_size == 0 && entry->movm_args == 0)
   2207      1.1  christos       || (elf_hash_table (link_info)->dynamic_sections_created
   2208      1.1  christos 	  && ELF_ST_VISIBILITY (entry->root.other) != STV_INTERNAL
   2209      1.1  christos 	  && ELF_ST_VISIBILITY (entry->root.other) != STV_HIDDEN))
   2210      1.1  christos     {
   2211      1.1  christos       /* Make a note that we should convert "call" instructions to "calls"
   2212      1.1  christos 	 instructions for calls to this symbol.  */
   2213      1.1  christos       entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
   2214      1.1  christos       return TRUE;
   2215      1.1  christos     }
   2216      1.1  christos 
   2217      1.1  christos   /* We may be able to move some instructions from the function itself into
   2218      1.1  christos      the "call" instruction.  Count how many bytes we might be able to
   2219      1.1  christos      eliminate in the function itself.  */
   2220      1.1  christos 
   2221      1.1  christos   /* A movm instruction is two bytes.  */
   2222      1.1  christos   if (entry->movm_args)
   2223      1.1  christos     byte_count += 2;
   2224      1.1  christos 
   2225      1.1  christos   /* Count the insn to allocate stack space too.  */
   2226      1.1  christos   if (entry->stack_size > 0)
   2227      1.1  christos     {
   2228      1.1  christos       if (entry->stack_size <= 128)
   2229      1.1  christos 	byte_count += 3;
   2230      1.1  christos       else
   2231      1.1  christos 	byte_count += 4;
   2232      1.1  christos     }
   2233      1.1  christos 
   2234      1.1  christos   /* If using "call" will result in larger code, then turn all
   2235      1.1  christos      the associated "call" instructions into "calls" instructions.  */
   2236      1.1  christos   if (byte_count < entry->direct_calls)
   2237      1.1  christos     entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
   2238      1.1  christos 
   2239      1.1  christos   /* This routine never fails.  */
   2240      1.1  christos   return TRUE;
   2241      1.1  christos }
   2242      1.1  christos 
   2243      1.1  christos /* Used to count hash table entries.  */
   2244      1.1  christos 
   2245      1.1  christos static bfd_boolean
   2246      1.1  christos elf32_mn10300_count_hash_table_entries (struct bfd_hash_entry *gen_entry ATTRIBUTE_UNUSED,
   2247      1.1  christos 					void * in_args)
   2248      1.1  christos {
   2249      1.1  christos   int *count = (int *) in_args;
   2250      1.1  christos 
   2251      1.1  christos   (*count) ++;
   2252      1.1  christos   return TRUE;
   2253      1.1  christos }
   2254      1.1  christos 
   2255      1.1  christos /* Used to enumerate hash table entries into a linear array.  */
   2256      1.1  christos 
   2257      1.1  christos static bfd_boolean
   2258      1.1  christos elf32_mn10300_list_hash_table_entries (struct bfd_hash_entry *gen_entry,
   2259      1.1  christos 				       void * in_args)
   2260      1.1  christos {
   2261      1.1  christos   struct bfd_hash_entry ***ptr = (struct bfd_hash_entry ***) in_args;
   2262      1.1  christos 
   2263      1.1  christos   **ptr = gen_entry;
   2264      1.1  christos   (*ptr) ++;
   2265      1.1  christos   return TRUE;
   2266      1.1  christos }
   2267      1.1  christos 
   2268      1.1  christos /* Used to sort the array created by the above.  */
   2269      1.1  christos 
   2270      1.1  christos static int
   2271      1.1  christos sort_by_value (const void *va, const void *vb)
   2272      1.1  christos {
   2273      1.1  christos   struct elf32_mn10300_link_hash_entry *a
   2274      1.1  christos     = *(struct elf32_mn10300_link_hash_entry **) va;
   2275      1.1  christos   struct elf32_mn10300_link_hash_entry *b
   2276      1.1  christos     = *(struct elf32_mn10300_link_hash_entry **) vb;
   2277      1.1  christos 
   2278      1.1  christos   return a->value - b->value;
   2279      1.1  christos }
   2280      1.1  christos 
   2281      1.1  christos /* Compute the stack size and movm arguments for the function
   2282      1.1  christos    referred to by HASH at address ADDR in section with
   2283      1.1  christos    contents CONTENTS, store the information in the hash table.  */
   2284      1.1  christos 
   2285      1.1  christos static void
   2286      1.1  christos compute_function_info (bfd *abfd,
   2287      1.1  christos 		       struct elf32_mn10300_link_hash_entry *hash,
   2288      1.1  christos 		       bfd_vma addr,
   2289      1.1  christos 		       unsigned char *contents)
   2290      1.1  christos {
   2291      1.1  christos   unsigned char byte1, byte2;
   2292      1.1  christos   /* We only care about a very small subset of the possible prologue
   2293      1.1  christos      sequences here.  Basically we look for:
   2294      1.1  christos 
   2295      1.1  christos      movm [d2,d3,a2,a3],sp (optional)
   2296      1.1  christos      add <size>,sp (optional, and only for sizes which fit in an unsigned
   2297      1.1  christos 		    8 bit number)
   2298      1.1  christos 
   2299      1.1  christos      If we find anything else, we quit.  */
   2300      1.1  christos 
   2301      1.1  christos   /* Look for movm [regs],sp.  */
   2302      1.1  christos   byte1 = bfd_get_8 (abfd, contents + addr);
   2303      1.1  christos   byte2 = bfd_get_8 (abfd, contents + addr + 1);
   2304      1.1  christos 
   2305      1.1  christos   if (byte1 == 0xcf)
   2306      1.1  christos     {
   2307      1.1  christos       hash->movm_args = byte2;
   2308      1.1  christos       addr += 2;
   2309      1.1  christos       byte1 = bfd_get_8 (abfd, contents + addr);
   2310      1.1  christos       byte2 = bfd_get_8 (abfd, contents + addr + 1);
   2311      1.1  christos     }
   2312      1.1  christos 
   2313      1.1  christos   /* Now figure out how much stack space will be allocated by the movm
   2314      1.1  christos      instruction.  We need this kept separate from the function's normal
   2315      1.1  christos      stack space.  */
   2316      1.1  christos   if (hash->movm_args)
   2317      1.1  christos     {
   2318      1.1  christos       /* Space for d2.  */
   2319      1.1  christos       if (hash->movm_args & 0x80)
   2320      1.1  christos 	hash->movm_stack_size += 4;
   2321      1.1  christos 
   2322      1.1  christos       /* Space for d3.  */
   2323      1.1  christos       if (hash->movm_args & 0x40)
   2324      1.1  christos 	hash->movm_stack_size += 4;
   2325      1.1  christos 
   2326      1.1  christos       /* Space for a2.  */
   2327      1.1  christos       if (hash->movm_args & 0x20)
   2328      1.1  christos 	hash->movm_stack_size += 4;
   2329      1.1  christos 
   2330      1.1  christos       /* Space for a3.  */
   2331      1.1  christos       if (hash->movm_args & 0x10)
   2332      1.1  christos 	hash->movm_stack_size += 4;
   2333      1.1  christos 
   2334      1.1  christos       /* "other" space.  d0, d1, a0, a1, mdr, lir, lar, 4 byte pad.  */
   2335      1.1  christos       if (hash->movm_args & 0x08)
   2336      1.1  christos 	hash->movm_stack_size += 8 * 4;
   2337      1.1  christos 
   2338      1.1  christos       if (bfd_get_mach (abfd) == bfd_mach_am33
   2339      1.1  christos 	  || bfd_get_mach (abfd) == bfd_mach_am33_2)
   2340      1.1  christos 	{
   2341      1.1  christos 	  /* "exother" space.  e0, e1, mdrq, mcrh, mcrl, mcvf */
   2342      1.1  christos 	  if (hash->movm_args & 0x1)
   2343      1.1  christos 	    hash->movm_stack_size += 6 * 4;
   2344      1.1  christos 
   2345      1.1  christos 	  /* exreg1 space.  e4, e5, e6, e7 */
   2346      1.1  christos 	  if (hash->movm_args & 0x2)
   2347      1.1  christos 	    hash->movm_stack_size += 4 * 4;
   2348      1.1  christos 
   2349      1.1  christos 	  /* exreg0 space.  e2, e3  */
   2350      1.1  christos 	  if (hash->movm_args & 0x4)
   2351      1.1  christos 	    hash->movm_stack_size += 2 * 4;
   2352      1.1  christos 	}
   2353      1.1  christos     }
   2354      1.1  christos 
   2355      1.1  christos   /* Now look for the two stack adjustment variants.  */
   2356      1.1  christos   if (byte1 == 0xf8 && byte2 == 0xfe)
   2357      1.1  christos     {
   2358      1.1  christos       int temp = bfd_get_8 (abfd, contents + addr + 2);
   2359      1.1  christos       temp = ((temp & 0xff) ^ (~0x7f)) + 0x80;
   2360      1.1  christos 
   2361      1.1  christos       hash->stack_size = -temp;
   2362      1.1  christos     }
   2363      1.1  christos   else if (byte1 == 0xfa && byte2 == 0xfe)
   2364      1.1  christos     {
   2365      1.1  christos       int temp = bfd_get_16 (abfd, contents + addr + 2);
   2366      1.1  christos       temp = ((temp & 0xffff) ^ (~0x7fff)) + 0x8000;
   2367      1.1  christos       temp = -temp;
   2368      1.1  christos 
   2369      1.1  christos       if (temp < 255)
   2370      1.1  christos 	hash->stack_size = temp;
   2371      1.1  christos     }
   2372      1.1  christos 
   2373      1.1  christos   /* If the total stack to be allocated by the call instruction is more
   2374      1.1  christos      than 255 bytes, then we can't remove the stack adjustment by using
   2375      1.1  christos      "call" (we might still be able to remove the "movm" instruction.  */
   2376      1.1  christos   if (hash->stack_size + hash->movm_stack_size > 255)
   2377      1.1  christos     hash->stack_size = 0;
   2378      1.1  christos }
   2379      1.1  christos 
   2380      1.1  christos /* Delete some bytes from a section while relaxing.  */
   2381      1.1  christos 
   2382      1.1  christos static bfd_boolean
   2383      1.1  christos mn10300_elf_relax_delete_bytes (bfd *abfd,
   2384      1.1  christos 				asection *sec,
   2385      1.1  christos 				bfd_vma addr,
   2386      1.1  christos 				int count)
   2387      1.1  christos {
   2388      1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   2389      1.1  christos   unsigned int sec_shndx;
   2390      1.1  christos   bfd_byte *contents;
   2391      1.1  christos   Elf_Internal_Rela *irel, *irelend;
   2392      1.1  christos   Elf_Internal_Rela *irelalign;
   2393      1.1  christos   bfd_vma toaddr;
   2394      1.1  christos   Elf_Internal_Sym *isym, *isymend;
   2395      1.1  christos   struct elf_link_hash_entry **sym_hashes;
   2396      1.1  christos   struct elf_link_hash_entry **end_hashes;
   2397      1.1  christos   unsigned int symcount;
   2398      1.1  christos 
   2399      1.1  christos   sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
   2400      1.1  christos 
   2401      1.1  christos   contents = elf_section_data (sec)->this_hdr.contents;
   2402      1.1  christos 
   2403      1.1  christos   irelalign = NULL;
   2404      1.1  christos   toaddr = sec->size;
   2405      1.1  christos 
   2406      1.1  christos   irel = elf_section_data (sec)->relocs;
   2407      1.1  christos   irelend = irel + sec->reloc_count;
   2408      1.1  christos 
   2409      1.1  christos   if (sec->reloc_count > 0)
   2410      1.1  christos     {
   2411      1.1  christos       /* If there is an align reloc at the end of the section ignore it.
   2412      1.1  christos 	 GAS creates these relocs for reasons of its own, and they just
   2413      1.1  christos 	 serve to keep the section artifically inflated.  */
   2414      1.1  christos       if (ELF32_R_TYPE ((irelend - 1)->r_info) == (int) R_MN10300_ALIGN)
   2415  1.1.1.2  christos 	--irelend;
   2416  1.1.1.8  christos 
   2417      1.1  christos       /* The deletion must stop at the next ALIGN reloc for an alignment
   2418      1.1  christos 	 power larger than, or not a multiple of, the number of bytes we
   2419      1.1  christos 	 are deleting.  */
   2420      1.1  christos       for (; irel < irelend; irel++)
   2421      1.1  christos 	{
   2422      1.1  christos 	  if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN
   2423  1.1.1.9  christos 	      && irel->r_offset > addr
   2424      1.1  christos 	      && irel->r_offset < toaddr)
   2425  1.1.1.9  christos 	    {
   2426  1.1.1.9  christos 	      int alignment = 1 << irel->r_addend;
   2427  1.1.1.9  christos 
   2428  1.1.1.9  christos 	      if (count < alignment
   2429  1.1.1.9  christos 		  || alignment % count != 0)
   2430  1.1.1.9  christos 		{
   2431  1.1.1.9  christos 		  irelalign = irel;
   2432  1.1.1.9  christos 		  toaddr = irel->r_offset;
   2433  1.1.1.9  christos 		  break;
   2434      1.1  christos 		}
   2435      1.1  christos 	    }
   2436      1.1  christos 	}
   2437      1.1  christos     }
   2438      1.1  christos 
   2439      1.1  christos   /* Actually delete the bytes.  */
   2440      1.1  christos   memmove (contents + addr, contents + addr + count,
   2441      1.1  christos 	   (size_t) (toaddr - addr - count));
   2442      1.1  christos 
   2443      1.1  christos   /* Adjust the section's size if we are shrinking it, or else
   2444      1.1  christos      pad the bytes between the end of the shrunken region and
   2445      1.1  christos      the start of the next region with NOP codes.  */
   2446      1.1  christos   if (irelalign == NULL)
   2447      1.1  christos     {
   2448      1.1  christos       sec->size -= count;
   2449      1.1  christos       /* Include symbols at the end of the section, but
   2450      1.1  christos 	 not at the end of a sub-region of the section.  */
   2451      1.1  christos       toaddr ++;
   2452      1.1  christos     }
   2453      1.1  christos   else
   2454      1.1  christos     {
   2455      1.1  christos       int i;
   2456      1.1  christos 
   2457      1.1  christos #define NOP_OPCODE 0xcb
   2458      1.1  christos 
   2459      1.1  christos       for (i = 0; i < count; i ++)
   2460      1.1  christos 	bfd_put_8 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
   2461      1.1  christos     }
   2462      1.1  christos 
   2463      1.1  christos   /* Adjust all the relocs.  */
   2464      1.1  christos   for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
   2465      1.1  christos     {
   2466      1.1  christos       /* Get the new reloc address.  */
   2467      1.1  christos       if ((irel->r_offset > addr
   2468      1.1  christos 	   && irel->r_offset < toaddr)
   2469      1.1  christos 	  || (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN
   2470      1.1  christos 	      && irel->r_offset == toaddr))
   2471      1.1  christos 	irel->r_offset -= count;
   2472      1.1  christos     }
   2473      1.1  christos 
   2474      1.1  christos   /* Adjust the local symbols in the section, reducing their value
   2475      1.1  christos      by the number of bytes deleted.  Note - symbols within the deleted
   2476      1.1  christos      region are moved to the address of the start of the region, which
   2477      1.1  christos      actually means that they will address the byte beyond the end of
   2478      1.1  christos      the region once the deletion has been completed.  */
   2479      1.1  christos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   2480      1.1  christos   isym = (Elf_Internal_Sym *) symtab_hdr->contents;
   2481      1.1  christos   for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
   2482      1.1  christos     {
   2483      1.1  christos       if (isym->st_shndx == sec_shndx
   2484      1.1  christos 	  && isym->st_value > addr
   2485      1.1  christos 	  && isym->st_value < toaddr)
   2486      1.1  christos 	{
   2487      1.1  christos 	  if (isym->st_value < addr + count)
   2488      1.1  christos 	    isym->st_value = addr;
   2489      1.1  christos 	  else
   2490      1.1  christos 	    isym->st_value -= count;
   2491      1.1  christos 	}
   2492      1.1  christos       /* Adjust the function symbol's size as well.  */
   2493      1.1  christos       else if (isym->st_shndx == sec_shndx
   2494      1.1  christos 	       && ELF_ST_TYPE (isym->st_info) == STT_FUNC
   2495      1.1  christos 	       && isym->st_value + isym->st_size > addr
   2496      1.1  christos 	       && isym->st_value + isym->st_size < toaddr)
   2497      1.1  christos 	isym->st_size -= count;
   2498      1.1  christos     }
   2499      1.1  christos 
   2500      1.1  christos   /* Now adjust the global symbols defined in this section.  */
   2501      1.1  christos   symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
   2502      1.1  christos 	      - symtab_hdr->sh_info);
   2503      1.1  christos   sym_hashes = elf_sym_hashes (abfd);
   2504      1.1  christos   end_hashes = sym_hashes + symcount;
   2505      1.1  christos   for (; sym_hashes < end_hashes; sym_hashes++)
   2506      1.1  christos     {
   2507      1.1  christos       struct elf_link_hash_entry *sym_hash = *sym_hashes;
   2508      1.1  christos 
   2509      1.1  christos       if ((sym_hash->root.type == bfd_link_hash_defined
   2510      1.1  christos 	   || sym_hash->root.type == bfd_link_hash_defweak)
   2511      1.1  christos 	  && sym_hash->root.u.def.section == sec
   2512      1.1  christos 	  && sym_hash->root.u.def.value > addr
   2513      1.1  christos 	  && sym_hash->root.u.def.value < toaddr)
   2514      1.1  christos 	{
   2515      1.1  christos 	  if (sym_hash->root.u.def.value < addr + count)
   2516      1.1  christos 	    sym_hash->root.u.def.value = addr;
   2517      1.1  christos 	  else
   2518      1.1  christos 	    sym_hash->root.u.def.value -= count;
   2519      1.1  christos 	}
   2520      1.1  christos       /* Adjust the function symbol's size as well.  */
   2521      1.1  christos       else if (sym_hash->root.type == bfd_link_hash_defined
   2522      1.1  christos 	       && sym_hash->root.u.def.section == sec
   2523      1.1  christos 	       && sym_hash->type == STT_FUNC
   2524      1.1  christos 	       && sym_hash->root.u.def.value + sym_hash->size > addr
   2525      1.1  christos 	       && sym_hash->root.u.def.value + sym_hash->size < toaddr)
   2526      1.1  christos 	sym_hash->size -= count;
   2527      1.1  christos     }
   2528      1.1  christos 
   2529      1.1  christos   /* See if we can move the ALIGN reloc forward.
   2530      1.1  christos      We have adjusted r_offset for it already.  */
   2531      1.1  christos   if (irelalign != NULL)
   2532      1.1  christos     {
   2533      1.1  christos       bfd_vma alignto, alignaddr;
   2534      1.1  christos 
   2535      1.1  christos       if ((int) irelalign->r_addend > 0)
   2536      1.1  christos 	{
   2537      1.1  christos 	  /* This is the old address.  */
   2538      1.1  christos 	  alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
   2539      1.1  christos 	  /* This is where the align points to now.  */
   2540      1.1  christos 	  alignaddr = BFD_ALIGN (irelalign->r_offset,
   2541      1.1  christos 				 1 << irelalign->r_addend);
   2542      1.1  christos 	  if (alignaddr < alignto)
   2543      1.1  christos 	    /* Tail recursion.  */
   2544      1.1  christos 	    return mn10300_elf_relax_delete_bytes (abfd, sec, alignaddr,
   2545      1.1  christos 						   (int) (alignto - alignaddr));
   2546      1.1  christos 	}
   2547      1.1  christos     }
   2548      1.1  christos 
   2549      1.1  christos   return TRUE;
   2550      1.1  christos }
   2551      1.1  christos 
   2552      1.1  christos /* Return TRUE if a symbol exists at the given address, else return
   2553      1.1  christos    FALSE.  */
   2554      1.1  christos 
   2555      1.1  christos static bfd_boolean
   2556      1.1  christos mn10300_elf_symbol_address_p (bfd *abfd,
   2557      1.1  christos 			      asection *sec,
   2558      1.1  christos 			      Elf_Internal_Sym *isym,
   2559      1.1  christos 			      bfd_vma addr)
   2560      1.1  christos {
   2561      1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   2562      1.1  christos   unsigned int sec_shndx;
   2563      1.1  christos   Elf_Internal_Sym *isymend;
   2564      1.1  christos   struct elf_link_hash_entry **sym_hashes;
   2565      1.1  christos   struct elf_link_hash_entry **end_hashes;
   2566      1.1  christos   unsigned int symcount;
   2567      1.1  christos 
   2568      1.1  christos   sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
   2569      1.1  christos 
   2570      1.1  christos   /* Examine all the symbols.  */
   2571      1.1  christos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   2572      1.1  christos   for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
   2573      1.1  christos     if (isym->st_shndx == sec_shndx
   2574      1.1  christos 	&& isym->st_value == addr)
   2575      1.1  christos       return TRUE;
   2576      1.1  christos 
   2577      1.1  christos   symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
   2578      1.1  christos 	      - symtab_hdr->sh_info);
   2579      1.1  christos   sym_hashes = elf_sym_hashes (abfd);
   2580      1.1  christos   end_hashes = sym_hashes + symcount;
   2581      1.1  christos   for (; sym_hashes < end_hashes; sym_hashes++)
   2582      1.1  christos     {
   2583      1.1  christos       struct elf_link_hash_entry *sym_hash = *sym_hashes;
   2584      1.1  christos 
   2585      1.1  christos       if ((sym_hash->root.type == bfd_link_hash_defined
   2586      1.1  christos 	   || sym_hash->root.type == bfd_link_hash_defweak)
   2587      1.1  christos 	  && sym_hash->root.u.def.section == sec
   2588      1.1  christos 	  && sym_hash->root.u.def.value == addr)
   2589      1.1  christos 	return TRUE;
   2590      1.1  christos     }
   2591      1.1  christos 
   2592      1.1  christos   return FALSE;
   2593      1.1  christos }
   2594      1.1  christos 
   2595      1.1  christos /* This function handles relaxing for the mn10300.
   2596      1.1  christos 
   2597      1.1  christos    There are quite a few relaxing opportunities available on the mn10300:
   2598  1.1.1.8  christos 
   2599      1.1  christos 	* calls:32 -> calls:16					   2 bytes
   2600      1.1  christos 	* call:32  -> call:16					   2 bytes
   2601      1.1  christos 
   2602      1.1  christos 	* call:32 -> calls:32					   1 byte
   2603      1.1  christos 	* call:16 -> calls:16					   1 byte
   2604      1.1  christos 		* These are done anytime using "calls" would result
   2605      1.1  christos 		in smaller code, or when necessary to preserve the
   2606      1.1  christos 		meaning of the program.
   2607      1.1  christos 
   2608      1.1  christos 	* call:32						   varies
   2609      1.1  christos 	* call:16
   2610      1.1  christos 		* In some circumstances we can move instructions
   2611      1.1  christos 		from a function prologue into a "call" instruction.
   2612      1.1  christos 		This is only done if the resulting code is no larger
   2613      1.1  christos 		than the original code.
   2614      1.1  christos 
   2615      1.1  christos 	* jmp:32 -> jmp:16					   2 bytes
   2616      1.1  christos 	* jmp:16 -> bra:8					   1 byte
   2617      1.1  christos 
   2618      1.1  christos 		* If the previous instruction is a conditional branch
   2619      1.1  christos 		around the jump/bra, we may be able to reverse its condition
   2620      1.1  christos 		and change its target to the jump's target.  The jump/bra
   2621      1.1  christos 		can then be deleted.				   2 bytes
   2622      1.1  christos 
   2623      1.1  christos 	* mov abs32 -> mov abs16				   1 or 2 bytes
   2624      1.1  christos 
   2625      1.1  christos 	* Most instructions which accept imm32 can relax to imm16  1 or 2 bytes
   2626      1.1  christos 	- Most instructions which accept imm16 can relax to imm8   1 or 2 bytes
   2627      1.1  christos 
   2628      1.1  christos 	* Most instructions which accept d32 can relax to d16	   1 or 2 bytes
   2629      1.1  christos 	- Most instructions which accept d16 can relax to d8	   1 or 2 bytes
   2630      1.1  christos 
   2631      1.1  christos 	We don't handle imm16->imm8 or d16->d8 as they're very rare
   2632      1.1  christos 	and somewhat more difficult to support.  */
   2633      1.1  christos 
   2634      1.1  christos static bfd_boolean
   2635      1.1  christos mn10300_elf_relax_section (bfd *abfd,
   2636      1.1  christos 			   asection *sec,
   2637      1.1  christos 			   struct bfd_link_info *link_info,
   2638      1.1  christos 			   bfd_boolean *again)
   2639      1.1  christos {
   2640      1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   2641      1.1  christos   Elf_Internal_Rela *internal_relocs = NULL;
   2642      1.1  christos   Elf_Internal_Rela *irel, *irelend;
   2643      1.1  christos   bfd_byte *contents = NULL;
   2644      1.1  christos   Elf_Internal_Sym *isymbuf = NULL;
   2645      1.1  christos   struct elf32_mn10300_link_hash_table *hash_table;
   2646      1.1  christos   asection *section = sec;
   2647      1.1  christos   bfd_vma align_gap_adjustment;
   2648  1.1.1.6  christos 
   2649      1.1  christos   if (bfd_link_relocatable (link_info))
   2650      1.1  christos     (*link_info->callbacks->einfo)
   2651      1.1  christos       (_("%P%F: --relax and -r may not be used together\n"));
   2652      1.1  christos 
   2653      1.1  christos   /* Assume nothing changes.  */
   2654      1.1  christos   *again = FALSE;
   2655      1.1  christos 
   2656      1.1  christos   /* We need a pointer to the mn10300 specific hash table.  */
   2657      1.1  christos   hash_table = elf32_mn10300_hash_table (link_info);
   2658      1.1  christos   if (hash_table == NULL)
   2659      1.1  christos     return FALSE;
   2660      1.1  christos 
   2661      1.1  christos   /* Initialize fields in each hash table entry the first time through.  */
   2662      1.1  christos   if ((hash_table->flags & MN10300_HASH_ENTRIES_INITIALIZED) == 0)
   2663      1.1  christos     {
   2664      1.1  christos       bfd *input_bfd;
   2665      1.1  christos 
   2666      1.1  christos       /* Iterate over all the input bfds.  */
   2667      1.1  christos       for (input_bfd = link_info->input_bfds;
   2668  1.1.1.4  christos 	   input_bfd != NULL;
   2669      1.1  christos 	   input_bfd = input_bfd->link.next)
   2670      1.1  christos 	{
   2671      1.1  christos 	  /* We're going to need all the symbols for each bfd.  */
   2672      1.1  christos 	  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   2673      1.1  christos 	  if (symtab_hdr->sh_info != 0)
   2674      1.1  christos 	    {
   2675      1.1  christos 	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   2676      1.1  christos 	      if (isymbuf == NULL)
   2677      1.1  christos 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
   2678      1.1  christos 						symtab_hdr->sh_info, 0,
   2679      1.1  christos 						NULL, NULL, NULL);
   2680      1.1  christos 	      if (isymbuf == NULL)
   2681      1.1  christos 		goto error_return;
   2682      1.1  christos 	    }
   2683      1.1  christos 
   2684      1.1  christos 	  /* Iterate over each section in this bfd.  */
   2685      1.1  christos 	  for (section = input_bfd->sections;
   2686      1.1  christos 	       section != NULL;
   2687      1.1  christos 	       section = section->next)
   2688      1.1  christos 	    {
   2689      1.1  christos 	      struct elf32_mn10300_link_hash_entry *hash;
   2690      1.1  christos 	      asection *sym_sec = NULL;
   2691      1.1  christos 	      const char *sym_name;
   2692      1.1  christos 	      char *new_name;
   2693      1.1  christos 
   2694      1.1  christos 	      /* If there's nothing to do in this section, skip it.  */
   2695      1.1  christos 	      if (! ((section->flags & SEC_RELOC) != 0
   2696      1.1  christos 		     && section->reloc_count != 0))
   2697      1.1  christos 		continue;
   2698      1.1  christos 	      if ((section->flags & SEC_ALLOC) == 0)
   2699      1.1  christos 		continue;
   2700      1.1  christos 
   2701      1.1  christos 	      /* Get cached copy of section contents if it exists.  */
   2702      1.1  christos 	      if (elf_section_data (section)->this_hdr.contents != NULL)
   2703      1.1  christos 		contents = elf_section_data (section)->this_hdr.contents;
   2704      1.1  christos 	      else if (section->size != 0)
   2705      1.1  christos 		{
   2706      1.1  christos 		  /* Go get them off disk.  */
   2707      1.1  christos 		  if (!bfd_malloc_and_get_section (input_bfd, section,
   2708      1.1  christos 						   &contents))
   2709      1.1  christos 		    goto error_return;
   2710      1.1  christos 		}
   2711      1.1  christos 	      else
   2712      1.1  christos 		contents = NULL;
   2713      1.1  christos 
   2714      1.1  christos 	      /* If there aren't any relocs, then there's nothing to do.  */
   2715      1.1  christos 	      if ((section->flags & SEC_RELOC) != 0
   2716      1.1  christos 		  && section->reloc_count != 0)
   2717      1.1  christos 		{
   2718      1.1  christos 		  /* Get a copy of the native relocations.  */
   2719      1.1  christos 		  internal_relocs = _bfd_elf_link_read_relocs (input_bfd, section,
   2720      1.1  christos 							       NULL, NULL,
   2721      1.1  christos 							       link_info->keep_memory);
   2722      1.1  christos 		  if (internal_relocs == NULL)
   2723      1.1  christos 		    goto error_return;
   2724      1.1  christos 
   2725      1.1  christos 		  /* Now examine each relocation.  */
   2726      1.1  christos 		  irel = internal_relocs;
   2727      1.1  christos 		  irelend = irel + section->reloc_count;
   2728      1.1  christos 		  for (; irel < irelend; irel++)
   2729      1.1  christos 		    {
   2730      1.1  christos 		      long r_type;
   2731      1.1  christos 		      unsigned long r_index;
   2732      1.1  christos 		      unsigned char code;
   2733      1.1  christos 
   2734      1.1  christos 		      r_type = ELF32_R_TYPE (irel->r_info);
   2735      1.1  christos 		      r_index = ELF32_R_SYM (irel->r_info);
   2736      1.1  christos 
   2737      1.1  christos 		      if (r_type < 0 || r_type >= (int) R_MN10300_MAX)
   2738      1.1  christos 			goto error_return;
   2739      1.1  christos 
   2740      1.1  christos 		      /* We need the name and hash table entry of the target
   2741      1.1  christos 			 symbol!  */
   2742      1.1  christos 		      hash = NULL;
   2743      1.1  christos 		      sym_sec = NULL;
   2744      1.1  christos 
   2745      1.1  christos 		      if (r_index < symtab_hdr->sh_info)
   2746      1.1  christos 			{
   2747      1.1  christos 			  /* A local symbol.  */
   2748      1.1  christos 			  Elf_Internal_Sym *isym;
   2749  1.1.1.9  christos 			  struct elf_link_hash_table *elftab;
   2750      1.1  christos 			  size_t amt;
   2751      1.1  christos 
   2752      1.1  christos 			  isym = isymbuf + r_index;
   2753      1.1  christos 			  if (isym->st_shndx == SHN_UNDEF)
   2754      1.1  christos 			    sym_sec = bfd_und_section_ptr;
   2755      1.1  christos 			  else if (isym->st_shndx == SHN_ABS)
   2756      1.1  christos 			    sym_sec = bfd_abs_section_ptr;
   2757      1.1  christos 			  else if (isym->st_shndx == SHN_COMMON)
   2758      1.1  christos 			    sym_sec = bfd_com_section_ptr;
   2759      1.1  christos 			  else
   2760      1.1  christos 			    sym_sec
   2761      1.1  christos 			      = bfd_section_from_elf_index (input_bfd,
   2762      1.1  christos 							    isym->st_shndx);
   2763      1.1  christos 
   2764      1.1  christos 			  sym_name
   2765      1.1  christos 			    = bfd_elf_string_from_elf_section (input_bfd,
   2766      1.1  christos 							       (symtab_hdr
   2767      1.1  christos 								->sh_link),
   2768      1.1  christos 							       isym->st_name);
   2769      1.1  christos 
   2770      1.1  christos 			  /* If it isn't a function, then we don't care
   2771      1.1  christos 			     about it.  */
   2772      1.1  christos 			  if (ELF_ST_TYPE (isym->st_info) != STT_FUNC)
   2773      1.1  christos 			    continue;
   2774      1.1  christos 
   2775      1.1  christos 			  /* Tack on an ID so we can uniquely identify this
   2776      1.1  christos 			     local symbol in the global hash table.  */
   2777      1.1  christos 			  amt = strlen (sym_name) + 10;
   2778      1.1  christos 			  new_name = bfd_malloc (amt);
   2779      1.1  christos 			  if (new_name == NULL)
   2780      1.1  christos 			    goto error_return;
   2781      1.1  christos 
   2782      1.1  christos 			  sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
   2783      1.1  christos 			  sym_name = new_name;
   2784      1.1  christos 
   2785      1.1  christos 			  elftab = &hash_table->static_hash_table->root;
   2786      1.1  christos 			  hash = ((struct elf32_mn10300_link_hash_entry *)
   2787      1.1  christos 				  elf_link_hash_lookup (elftab, sym_name,
   2788      1.1  christos 							TRUE, TRUE, FALSE));
   2789      1.1  christos 			  free (new_name);
   2790      1.1  christos 			}
   2791      1.1  christos 		      else
   2792      1.1  christos 			{
   2793      1.1  christos 			  r_index -= symtab_hdr->sh_info;
   2794      1.1  christos 			  hash = (struct elf32_mn10300_link_hash_entry *)
   2795      1.1  christos 				   elf_sym_hashes (input_bfd)[r_index];
   2796      1.1  christos 			}
   2797      1.1  christos 
   2798      1.1  christos 		      sym_name = hash->root.root.root.string;
   2799      1.1  christos 		      if ((section->flags & SEC_CODE) != 0)
   2800      1.1  christos 			{
   2801      1.1  christos 			  /* If this is not a "call" instruction, then we
   2802      1.1  christos 			     should convert "call" instructions to "calls"
   2803      1.1  christos 			     instructions.  */
   2804      1.1  christos 			  code = bfd_get_8 (input_bfd,
   2805      1.1  christos 					    contents + irel->r_offset - 1);
   2806      1.1  christos 			  if (code != 0xdd && code != 0xcd)
   2807      1.1  christos 			    hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
   2808      1.1  christos 			}
   2809      1.1  christos 
   2810      1.1  christos 		      /* If this is a jump/call, then bump the
   2811      1.1  christos 			 direct_calls counter.  Else force "call" to
   2812      1.1  christos 			 "calls" conversions.  */
   2813      1.1  christos 		      if (r_type == R_MN10300_PCREL32
   2814      1.1  christos 			  || r_type == R_MN10300_PLT32
   2815      1.1  christos 			  || r_type == R_MN10300_PLT16
   2816      1.1  christos 			  || r_type == R_MN10300_PCREL16)
   2817      1.1  christos 			hash->direct_calls++;
   2818      1.1  christos 		      else
   2819      1.1  christos 			hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
   2820      1.1  christos 		    }
   2821      1.1  christos 		}
   2822      1.1  christos 
   2823      1.1  christos 	      /* Now look at the actual contents to get the stack size,
   2824      1.1  christos 		 and a list of what registers were saved in the prologue
   2825      1.1  christos 		 (ie movm_args).  */
   2826      1.1  christos 	      if ((section->flags & SEC_CODE) != 0)
   2827      1.1  christos 		{
   2828      1.1  christos 		  Elf_Internal_Sym *isym, *isymend;
   2829      1.1  christos 		  unsigned int sec_shndx;
   2830      1.1  christos 		  struct elf_link_hash_entry **hashes;
   2831      1.1  christos 		  struct elf_link_hash_entry **end_hashes;
   2832      1.1  christos 		  unsigned int symcount;
   2833      1.1  christos 
   2834      1.1  christos 		  sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
   2835      1.1  christos 								 section);
   2836      1.1  christos 
   2837      1.1  christos 		  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
   2838      1.1  christos 			      - symtab_hdr->sh_info);
   2839      1.1  christos 		  hashes = elf_sym_hashes (input_bfd);
   2840      1.1  christos 		  end_hashes = hashes + symcount;
   2841      1.1  christos 
   2842      1.1  christos 		  /* Look at each function defined in this section and
   2843      1.1  christos 		     update info for that function.  */
   2844      1.1  christos 		  isymend = isymbuf + symtab_hdr->sh_info;
   2845      1.1  christos 		  for (isym = isymbuf; isym < isymend; isym++)
   2846      1.1  christos 		    {
   2847      1.1  christos 		      if (isym->st_shndx == sec_shndx
   2848      1.1  christos 			  && ELF_ST_TYPE (isym->st_info) == STT_FUNC)
   2849      1.1  christos 			{
   2850  1.1.1.9  christos 			  struct elf_link_hash_table *elftab;
   2851      1.1  christos 			  size_t amt;
   2852      1.1  christos 			  struct elf_link_hash_entry **lhashes = hashes;
   2853      1.1  christos 
   2854      1.1  christos 			  /* Skip a local symbol if it aliases a
   2855      1.1  christos 			     global one.  */
   2856      1.1  christos 			  for (; lhashes < end_hashes; lhashes++)
   2857      1.1  christos 			    {
   2858      1.1  christos 			      hash = (struct elf32_mn10300_link_hash_entry *) *lhashes;
   2859      1.1  christos 			      if ((hash->root.root.type == bfd_link_hash_defined
   2860      1.1  christos 				   || hash->root.root.type == bfd_link_hash_defweak)
   2861      1.1  christos 				  && hash->root.root.u.def.section == section
   2862      1.1  christos 				  && hash->root.type == STT_FUNC
   2863      1.1  christos 				  && hash->root.root.u.def.value == isym->st_value)
   2864      1.1  christos 				break;
   2865      1.1  christos 			    }
   2866      1.1  christos 			  if (lhashes != end_hashes)
   2867      1.1  christos 			    continue;
   2868      1.1  christos 
   2869      1.1  christos 			  if (isym->st_shndx == SHN_UNDEF)
   2870      1.1  christos 			    sym_sec = bfd_und_section_ptr;
   2871      1.1  christos 			  else if (isym->st_shndx == SHN_ABS)
   2872      1.1  christos 			    sym_sec = bfd_abs_section_ptr;
   2873      1.1  christos 			  else if (isym->st_shndx == SHN_COMMON)
   2874      1.1  christos 			    sym_sec = bfd_com_section_ptr;
   2875      1.1  christos 			  else
   2876      1.1  christos 			    sym_sec
   2877      1.1  christos 			      = bfd_section_from_elf_index (input_bfd,
   2878      1.1  christos 							    isym->st_shndx);
   2879      1.1  christos 
   2880      1.1  christos 			  sym_name = (bfd_elf_string_from_elf_section
   2881      1.1  christos 				      (input_bfd, symtab_hdr->sh_link,
   2882      1.1  christos 				       isym->st_name));
   2883      1.1  christos 
   2884      1.1  christos 			  /* Tack on an ID so we can uniquely identify this
   2885      1.1  christos 			     local symbol in the global hash table.  */
   2886      1.1  christos 			  amt = strlen (sym_name) + 10;
   2887      1.1  christos 			  new_name = bfd_malloc (amt);
   2888      1.1  christos 			  if (new_name == NULL)
   2889      1.1  christos 			    goto error_return;
   2890      1.1  christos 
   2891      1.1  christos 			  sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
   2892      1.1  christos 			  sym_name = new_name;
   2893      1.1  christos 
   2894      1.1  christos 			  elftab = &hash_table->static_hash_table->root;
   2895      1.1  christos 			  hash = ((struct elf32_mn10300_link_hash_entry *)
   2896      1.1  christos 				  elf_link_hash_lookup (elftab, sym_name,
   2897      1.1  christos 							TRUE, TRUE, FALSE));
   2898      1.1  christos 			  free (new_name);
   2899      1.1  christos 			  compute_function_info (input_bfd, hash,
   2900      1.1  christos 						 isym->st_value, contents);
   2901      1.1  christos 			  hash->value = isym->st_value;
   2902      1.1  christos 			}
   2903      1.1  christos 		    }
   2904      1.1  christos 
   2905      1.1  christos 		  for (; hashes < end_hashes; hashes++)
   2906      1.1  christos 		    {
   2907      1.1  christos 		      hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
   2908      1.1  christos 		      if ((hash->root.root.type == bfd_link_hash_defined
   2909      1.1  christos 			   || hash->root.root.type == bfd_link_hash_defweak)
   2910      1.1  christos 			  && hash->root.root.u.def.section == section
   2911      1.1  christos 			  && hash->root.type == STT_FUNC)
   2912      1.1  christos 			compute_function_info (input_bfd, hash,
   2913      1.1  christos 					       (hash)->root.root.u.def.value,
   2914      1.1  christos 					       contents);
   2915      1.1  christos 		    }
   2916      1.1  christos 		}
   2917      1.1  christos 
   2918  1.1.1.9  christos 	      /* Cache or free any memory we allocated for the relocs.  */
   2919      1.1  christos 	      if (elf_section_data (section)->relocs != internal_relocs)
   2920      1.1  christos 		free (internal_relocs);
   2921      1.1  christos 	      internal_relocs = NULL;
   2922      1.1  christos 
   2923      1.1  christos 	      /* Cache or free any memory we allocated for the contents.  */
   2924      1.1  christos 	      if (contents != NULL
   2925      1.1  christos 		  && elf_section_data (section)->this_hdr.contents != contents)
   2926      1.1  christos 		{
   2927      1.1  christos 		  if (! link_info->keep_memory)
   2928      1.1  christos 		    free (contents);
   2929      1.1  christos 		  else
   2930      1.1  christos 		    {
   2931      1.1  christos 		      /* Cache the section contents for elf_link_input_bfd.  */
   2932      1.1  christos 		      elf_section_data (section)->this_hdr.contents = contents;
   2933      1.1  christos 		    }
   2934      1.1  christos 		}
   2935      1.1  christos 	      contents = NULL;
   2936      1.1  christos 	    }
   2937      1.1  christos 
   2938      1.1  christos 	  /* Cache or free any memory we allocated for the symbols.  */
   2939      1.1  christos 	  if (isymbuf != NULL
   2940      1.1  christos 	      && symtab_hdr->contents != (unsigned char *) isymbuf)
   2941      1.1  christos 	    {
   2942      1.1  christos 	      if (! link_info->keep_memory)
   2943      1.1  christos 		free (isymbuf);
   2944      1.1  christos 	      else
   2945      1.1  christos 		{
   2946      1.1  christos 		  /* Cache the symbols for elf_link_input_bfd.  */
   2947      1.1  christos 		  symtab_hdr->contents = (unsigned char *) isymbuf;
   2948      1.1  christos 		}
   2949      1.1  christos 	    }
   2950      1.1  christos 	  isymbuf = NULL;
   2951      1.1  christos 	}
   2952      1.1  christos 
   2953      1.1  christos       /* Now iterate on each symbol in the hash table and perform
   2954      1.1  christos 	 the final initialization steps on each.  */
   2955      1.1  christos       elf32_mn10300_link_hash_traverse (hash_table,
   2956      1.1  christos 					elf32_mn10300_finish_hash_table_entry,
   2957      1.1  christos 					link_info);
   2958      1.1  christos       elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
   2959      1.1  christos 					elf32_mn10300_finish_hash_table_entry,
   2960      1.1  christos 					link_info);
   2961      1.1  christos 
   2962      1.1  christos       {
   2963      1.1  christos 	/* This section of code collects all our local symbols, sorts
   2964      1.1  christos 	   them by value, and looks for multiple symbols referring to
   2965      1.1  christos 	   the same address.  For those symbols, the flags are merged.
   2966      1.1  christos 	   At this point, the only flag that can be set is
   2967      1.1  christos 	   MN10300_CONVERT_CALL_TO_CALLS, so we simply OR the flags
   2968      1.1  christos 	   together.  */
   2969      1.1  christos 	int static_count = 0, i;
   2970      1.1  christos 	struct elf32_mn10300_link_hash_entry **entries;
   2971      1.1  christos 	struct elf32_mn10300_link_hash_entry **ptr;
   2972      1.1  christos 
   2973      1.1  christos 	elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
   2974      1.1  christos 					  elf32_mn10300_count_hash_table_entries,
   2975      1.1  christos 					  &static_count);
   2976      1.1  christos 
   2977      1.1  christos 	entries = bfd_malloc (static_count * sizeof (* ptr));
   2978      1.1  christos 
   2979      1.1  christos 	ptr = entries;
   2980      1.1  christos 	elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
   2981      1.1  christos 					  elf32_mn10300_list_hash_table_entries,
   2982      1.1  christos 					  & ptr);
   2983      1.1  christos 
   2984      1.1  christos 	qsort (entries, static_count, sizeof (entries[0]), sort_by_value);
   2985      1.1  christos 
   2986      1.1  christos 	for (i = 0; i < static_count - 1; i++)
   2987      1.1  christos 	  if (entries[i]->value && entries[i]->value == entries[i+1]->value)
   2988      1.1  christos 	    {
   2989      1.1  christos 	      int v = entries[i]->flags;
   2990      1.1  christos 	      int j;
   2991      1.1  christos 
   2992      1.1  christos 	      for (j = i + 1; j < static_count && entries[j]->value == entries[i]->value; j++)
   2993      1.1  christos 		v |= entries[j]->flags;
   2994      1.1  christos 
   2995      1.1  christos 	      for (j = i; j < static_count && entries[j]->value == entries[i]->value; j++)
   2996      1.1  christos 		entries[j]->flags = v;
   2997      1.1  christos 
   2998      1.1  christos 	      i = j - 1;
   2999      1.1  christos 	    }
   3000      1.1  christos       }
   3001      1.1  christos 
   3002      1.1  christos       /* All entries in the hash table are fully initialized.  */
   3003      1.1  christos       hash_table->flags |= MN10300_HASH_ENTRIES_INITIALIZED;
   3004      1.1  christos 
   3005      1.1  christos       /* Now that everything has been initialized, go through each
   3006      1.1  christos 	 code section and delete any prologue insns which will be
   3007      1.1  christos 	 redundant because their operations will be performed by
   3008      1.1  christos 	 a "call" instruction.  */
   3009      1.1  christos       for (input_bfd = link_info->input_bfds;
   3010  1.1.1.4  christos 	   input_bfd != NULL;
   3011      1.1  christos 	   input_bfd = input_bfd->link.next)
   3012      1.1  christos 	{
   3013      1.1  christos 	  /* We're going to need all the local symbols for each bfd.  */
   3014      1.1  christos 	  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   3015      1.1  christos 	  if (symtab_hdr->sh_info != 0)
   3016      1.1  christos 	    {
   3017      1.1  christos 	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   3018      1.1  christos 	      if (isymbuf == NULL)
   3019      1.1  christos 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
   3020      1.1  christos 						symtab_hdr->sh_info, 0,
   3021      1.1  christos 						NULL, NULL, NULL);
   3022      1.1  christos 	      if (isymbuf == NULL)
   3023      1.1  christos 		goto error_return;
   3024      1.1  christos 	    }
   3025      1.1  christos 
   3026      1.1  christos 	  /* Walk over each section in this bfd.  */
   3027      1.1  christos 	  for (section = input_bfd->sections;
   3028      1.1  christos 	       section != NULL;
   3029      1.1  christos 	       section = section->next)
   3030      1.1  christos 	    {
   3031      1.1  christos 	      unsigned int sec_shndx;
   3032      1.1  christos 	      Elf_Internal_Sym *isym, *isymend;
   3033      1.1  christos 	      struct elf_link_hash_entry **hashes;
   3034      1.1  christos 	      struct elf_link_hash_entry **end_hashes;
   3035      1.1  christos 	      unsigned int symcount;
   3036      1.1  christos 
   3037      1.1  christos 	      /* Skip non-code sections and empty sections.  */
   3038      1.1  christos 	      if ((section->flags & SEC_CODE) == 0 || section->size == 0)
   3039      1.1  christos 		continue;
   3040      1.1  christos 
   3041      1.1  christos 	      if (section->reloc_count != 0)
   3042      1.1  christos 		{
   3043      1.1  christos 		  /* Get a copy of the native relocations.  */
   3044      1.1  christos 		  internal_relocs = _bfd_elf_link_read_relocs (input_bfd, section,
   3045      1.1  christos 							       NULL, NULL,
   3046      1.1  christos 							       link_info->keep_memory);
   3047      1.1  christos 		  if (internal_relocs == NULL)
   3048      1.1  christos 		    goto error_return;
   3049      1.1  christos 		}
   3050      1.1  christos 
   3051      1.1  christos 	      /* Get cached copy of section contents if it exists.  */
   3052      1.1  christos 	      if (elf_section_data (section)->this_hdr.contents != NULL)
   3053      1.1  christos 		contents = elf_section_data (section)->this_hdr.contents;
   3054      1.1  christos 	      else
   3055      1.1  christos 		{
   3056      1.1  christos 		  /* Go get them off disk.  */
   3057      1.1  christos 		  if (!bfd_malloc_and_get_section (input_bfd, section,
   3058      1.1  christos 						   &contents))
   3059      1.1  christos 		    goto error_return;
   3060      1.1  christos 		}
   3061      1.1  christos 
   3062      1.1  christos 	      sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
   3063      1.1  christos 							     section);
   3064      1.1  christos 
   3065      1.1  christos 	      /* Now look for any function in this section which needs
   3066      1.1  christos 		 insns deleted from its prologue.  */
   3067      1.1  christos 	      isymend = isymbuf + symtab_hdr->sh_info;
   3068      1.1  christos 	      for (isym = isymbuf; isym < isymend; isym++)
   3069      1.1  christos 		{
   3070      1.1  christos 		  struct elf32_mn10300_link_hash_entry *sym_hash;
   3071      1.1  christos 		  asection *sym_sec = NULL;
   3072      1.1  christos 		  const char *sym_name;
   3073      1.1  christos 		  char *new_name;
   3074  1.1.1.9  christos 		  struct elf_link_hash_table *elftab;
   3075      1.1  christos 		  size_t amt;
   3076      1.1  christos 
   3077      1.1  christos 		  if (isym->st_shndx != sec_shndx)
   3078      1.1  christos 		    continue;
   3079      1.1  christos 
   3080      1.1  christos 		  if (isym->st_shndx == SHN_UNDEF)
   3081      1.1  christos 		    sym_sec = bfd_und_section_ptr;
   3082      1.1  christos 		  else if (isym->st_shndx == SHN_ABS)
   3083      1.1  christos 		    sym_sec = bfd_abs_section_ptr;
   3084      1.1  christos 		  else if (isym->st_shndx == SHN_COMMON)
   3085      1.1  christos 		    sym_sec = bfd_com_section_ptr;
   3086      1.1  christos 		  else
   3087      1.1  christos 		    sym_sec
   3088      1.1  christos 		      = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
   3089      1.1  christos 
   3090      1.1  christos 		  sym_name
   3091      1.1  christos 		    = bfd_elf_string_from_elf_section (input_bfd,
   3092      1.1  christos 						       symtab_hdr->sh_link,
   3093      1.1  christos 						       isym->st_name);
   3094      1.1  christos 
   3095      1.1  christos 		  /* Tack on an ID so we can uniquely identify this
   3096      1.1  christos 		     local symbol in the global hash table.  */
   3097      1.1  christos 		  amt = strlen (sym_name) + 10;
   3098      1.1  christos 		  new_name = bfd_malloc (amt);
   3099      1.1  christos 		  if (new_name == NULL)
   3100      1.1  christos 		    goto error_return;
   3101      1.1  christos 		  sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
   3102      1.1  christos 		  sym_name = new_name;
   3103      1.1  christos 
   3104      1.1  christos 		  elftab = & hash_table->static_hash_table->root;
   3105      1.1  christos 		  sym_hash = (struct elf32_mn10300_link_hash_entry *)
   3106      1.1  christos 		    elf_link_hash_lookup (elftab, sym_name,
   3107      1.1  christos 					  FALSE, FALSE, FALSE);
   3108      1.1  christos 
   3109      1.1  christos 		  free (new_name);
   3110      1.1  christos 		  if (sym_hash == NULL)
   3111      1.1  christos 		    continue;
   3112      1.1  christos 
   3113      1.1  christos 		  if (! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
   3114      1.1  christos 		      && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
   3115      1.1  christos 		    {
   3116      1.1  christos 		      int bytes = 0;
   3117      1.1  christos 
   3118      1.1  christos 		      /* Note that we've changed things.  */
   3119      1.1  christos 		      elf_section_data (section)->relocs = internal_relocs;
   3120      1.1  christos 		      elf_section_data (section)->this_hdr.contents = contents;
   3121      1.1  christos 		      symtab_hdr->contents = (unsigned char *) isymbuf;
   3122      1.1  christos 
   3123      1.1  christos 		      /* Count how many bytes we're going to delete.  */
   3124      1.1  christos 		      if (sym_hash->movm_args)
   3125      1.1  christos 			bytes += 2;
   3126      1.1  christos 
   3127      1.1  christos 		      if (sym_hash->stack_size > 0)
   3128      1.1  christos 			{
   3129      1.1  christos 			  if (sym_hash->stack_size <= 128)
   3130      1.1  christos 			    bytes += 3;
   3131      1.1  christos 			  else
   3132      1.1  christos 			    bytes += 4;
   3133      1.1  christos 			}
   3134      1.1  christos 
   3135      1.1  christos 		      /* Note that we've deleted prologue bytes for this
   3136      1.1  christos 			 function.  */
   3137      1.1  christos 		      sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
   3138      1.1  christos 
   3139      1.1  christos 		      /* Actually delete the bytes.  */
   3140      1.1  christos 		      if (!mn10300_elf_relax_delete_bytes (input_bfd,
   3141      1.1  christos 							   section,
   3142      1.1  christos 							   isym->st_value,
   3143      1.1  christos 							   bytes))
   3144      1.1  christos 			goto error_return;
   3145      1.1  christos 
   3146      1.1  christos 		      /* Something changed.  Not strictly necessary, but
   3147      1.1  christos 			 may lead to more relaxing opportunities.  */
   3148      1.1  christos 		      *again = TRUE;
   3149      1.1  christos 		    }
   3150      1.1  christos 		}
   3151      1.1  christos 
   3152      1.1  christos 	      /* Look for any global functions in this section which
   3153      1.1  christos 		 need insns deleted from their prologues.  */
   3154      1.1  christos 	      symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
   3155      1.1  christos 			  - symtab_hdr->sh_info);
   3156      1.1  christos 	      hashes = elf_sym_hashes (input_bfd);
   3157      1.1  christos 	      end_hashes = hashes + symcount;
   3158      1.1  christos 	      for (; hashes < end_hashes; hashes++)
   3159      1.1  christos 		{
   3160      1.1  christos 		  struct elf32_mn10300_link_hash_entry *sym_hash;
   3161      1.1  christos 
   3162      1.1  christos 		  sym_hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
   3163      1.1  christos 		  if ((sym_hash->root.root.type == bfd_link_hash_defined
   3164      1.1  christos 		       || sym_hash->root.root.type == bfd_link_hash_defweak)
   3165      1.1  christos 		      && sym_hash->root.root.u.def.section == section
   3166      1.1  christos 		      && ! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
   3167      1.1  christos 		      && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
   3168      1.1  christos 		    {
   3169      1.1  christos 		      int bytes = 0;
   3170  1.1.1.2  christos 		      bfd_vma symval;
   3171      1.1  christos 		      struct elf_link_hash_entry **hh;
   3172      1.1  christos 
   3173      1.1  christos 		      /* Note that we've changed things.  */
   3174      1.1  christos 		      elf_section_data (section)->relocs = internal_relocs;
   3175      1.1  christos 		      elf_section_data (section)->this_hdr.contents = contents;
   3176      1.1  christos 		      symtab_hdr->contents = (unsigned char *) isymbuf;
   3177      1.1  christos 
   3178      1.1  christos 		      /* Count how many bytes we're going to delete.  */
   3179      1.1  christos 		      if (sym_hash->movm_args)
   3180      1.1  christos 			bytes += 2;
   3181      1.1  christos 
   3182      1.1  christos 		      if (sym_hash->stack_size > 0)
   3183      1.1  christos 			{
   3184      1.1  christos 			  if (sym_hash->stack_size <= 128)
   3185      1.1  christos 			    bytes += 3;
   3186      1.1  christos 			  else
   3187      1.1  christos 			    bytes += 4;
   3188      1.1  christos 			}
   3189      1.1  christos 
   3190      1.1  christos 		      /* Note that we've deleted prologue bytes for this
   3191      1.1  christos 			 function.  */
   3192      1.1  christos 		      sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
   3193      1.1  christos 
   3194      1.1  christos 		      /* Actually delete the bytes.  */
   3195      1.1  christos 		      symval = sym_hash->root.root.u.def.value;
   3196      1.1  christos 		      if (!mn10300_elf_relax_delete_bytes (input_bfd,
   3197      1.1  christos 							   section,
   3198      1.1  christos 							   symval,
   3199      1.1  christos 							   bytes))
   3200      1.1  christos 			goto error_return;
   3201  1.1.1.2  christos 
   3202  1.1.1.2  christos 		      /* There may be other C++ functions symbols with the same
   3203  1.1.1.2  christos 			 address.  If so then mark these as having had their
   3204  1.1.1.2  christos 			 prologue bytes deleted as well.  */
   3205  1.1.1.2  christos 		      for (hh = elf_sym_hashes (input_bfd); hh < end_hashes; hh++)
   3206  1.1.1.2  christos 			{
   3207  1.1.1.2  christos 			  struct elf32_mn10300_link_hash_entry *h;
   3208  1.1.1.2  christos 
   3209  1.1.1.2  christos 			  h = (struct elf32_mn10300_link_hash_entry *) * hh;
   3210  1.1.1.2  christos 
   3211  1.1.1.2  christos 			  if (h != sym_hash
   3212  1.1.1.2  christos 			      && (h->root.root.type == bfd_link_hash_defined
   3213  1.1.1.2  christos 				  || h->root.root.type == bfd_link_hash_defweak)
   3214  1.1.1.2  christos 			      && h->root.root.u.def.section == section
   3215  1.1.1.2  christos 			      && ! (h->flags & MN10300_CONVERT_CALL_TO_CALLS)
   3216  1.1.1.2  christos 			      && h->root.root.u.def.value == symval
   3217  1.1.1.2  christos 			      && h->root.type == STT_FUNC)
   3218  1.1.1.2  christos 			    h->flags |= MN10300_DELETED_PROLOGUE_BYTES;
   3219  1.1.1.2  christos 			}
   3220      1.1  christos 
   3221      1.1  christos 		      /* Something changed.  Not strictly necessary, but
   3222      1.1  christos 			 may lead to more relaxing opportunities.  */
   3223      1.1  christos 		      *again = TRUE;
   3224      1.1  christos 		    }
   3225      1.1  christos 		}
   3226      1.1  christos 
   3227  1.1.1.9  christos 	      /* Cache or free any memory we allocated for the relocs.  */
   3228      1.1  christos 	      if (elf_section_data (section)->relocs != internal_relocs)
   3229      1.1  christos 		free (internal_relocs);
   3230      1.1  christos 	      internal_relocs = NULL;
   3231      1.1  christos 
   3232      1.1  christos 	      /* Cache or free any memory we allocated for the contents.  */
   3233      1.1  christos 	      if (contents != NULL
   3234      1.1  christos 		  && elf_section_data (section)->this_hdr.contents != contents)
   3235      1.1  christos 		{
   3236      1.1  christos 		  if (! link_info->keep_memory)
   3237      1.1  christos 		    free (contents);
   3238      1.1  christos 		  else
   3239      1.1  christos 		    /* Cache the section contents for elf_link_input_bfd.  */
   3240      1.1  christos 		    elf_section_data (section)->this_hdr.contents = contents;
   3241      1.1  christos 		}
   3242      1.1  christos 	      contents = NULL;
   3243      1.1  christos 	    }
   3244      1.1  christos 
   3245      1.1  christos 	  /* Cache or free any memory we allocated for the symbols.  */
   3246      1.1  christos 	  if (isymbuf != NULL
   3247      1.1  christos 	      && symtab_hdr->contents != (unsigned char *) isymbuf)
   3248      1.1  christos 	    {
   3249      1.1  christos 	      if (! link_info->keep_memory)
   3250      1.1  christos 		free (isymbuf);
   3251      1.1  christos 	      else
   3252      1.1  christos 		/* Cache the symbols for elf_link_input_bfd.  */
   3253      1.1  christos 		symtab_hdr->contents = (unsigned char *) isymbuf;
   3254      1.1  christos 	    }
   3255      1.1  christos 	  isymbuf = NULL;
   3256      1.1  christos 	}
   3257      1.1  christos     }
   3258      1.1  christos 
   3259      1.1  christos   /* (Re)initialize for the basic instruction shortening/relaxing pass.  */
   3260      1.1  christos   contents = NULL;
   3261      1.1  christos   internal_relocs = NULL;
   3262      1.1  christos   isymbuf = NULL;
   3263      1.1  christos   /* For error_return.  */
   3264      1.1  christos   section = sec;
   3265      1.1  christos 
   3266      1.1  christos   /* We don't have to do anything for a relocatable link, if
   3267      1.1  christos      this section does not have relocs, or if this is not a
   3268  1.1.1.6  christos      code section.  */
   3269      1.1  christos   if (bfd_link_relocatable (link_info)
   3270      1.1  christos       || (sec->flags & SEC_RELOC) == 0
   3271      1.1  christos       || sec->reloc_count == 0
   3272      1.1  christos       || (sec->flags & SEC_CODE) == 0)
   3273      1.1  christos     return TRUE;
   3274      1.1  christos 
   3275      1.1  christos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   3276      1.1  christos 
   3277      1.1  christos   /* Get a copy of the native relocations.  */
   3278      1.1  christos   internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL,
   3279      1.1  christos 					       link_info->keep_memory);
   3280      1.1  christos   if (internal_relocs == NULL)
   3281      1.1  christos     goto error_return;
   3282      1.1  christos 
   3283      1.1  christos   /* Scan for worst case alignment gap changes.  Note that this logic
   3284      1.1  christos      is not ideal; what we should do is run this scan for every
   3285      1.1  christos      opcode/address range and adjust accordingly, but that's
   3286      1.1  christos      expensive.  Worst case is that for an alignment of N bytes, we
   3287      1.1  christos      move by 2*N-N-1 bytes, assuming we have aligns of 1, 2, 4, 8, etc
   3288      1.1  christos      all before it.  Plus, this still doesn't cover cross-section
   3289      1.1  christos      jumps with section alignment.  */
   3290      1.1  christos   irelend = internal_relocs + sec->reloc_count;
   3291      1.1  christos   align_gap_adjustment = 0;
   3292      1.1  christos   for (irel = internal_relocs; irel < irelend; irel++)
   3293      1.1  christos     {
   3294      1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN)
   3295      1.1  christos 	{
   3296      1.1  christos 	  bfd_vma adj = 1 << irel->r_addend;
   3297      1.1  christos 	  bfd_vma aend = irel->r_offset;
   3298      1.1  christos 
   3299      1.1  christos 	  aend = BFD_ALIGN (aend, 1 << irel->r_addend);
   3300      1.1  christos 	  adj = 2 * adj - adj - 1;
   3301      1.1  christos 
   3302      1.1  christos 	  /* Record the biggest adjustmnet.  Skip any alignment at the
   3303      1.1  christos 	     end of our section.  */
   3304      1.1  christos 	  if (align_gap_adjustment < adj
   3305      1.1  christos 	      && aend < sec->output_section->vma + sec->output_offset + sec->size)
   3306      1.1  christos 	    align_gap_adjustment = adj;
   3307      1.1  christos 	}
   3308      1.1  christos     }
   3309      1.1  christos 
   3310      1.1  christos   /* Walk through them looking for relaxing opportunities.  */
   3311      1.1  christos   irelend = internal_relocs + sec->reloc_count;
   3312      1.1  christos   for (irel = internal_relocs; irel < irelend; irel++)
   3313      1.1  christos     {
   3314      1.1  christos       bfd_vma symval;
   3315      1.1  christos       bfd_signed_vma jump_offset;
   3316      1.1  christos       asection *sym_sec = NULL;
   3317      1.1  christos       struct elf32_mn10300_link_hash_entry *h = NULL;
   3318      1.1  christos 
   3319      1.1  christos       /* If this isn't something that can be relaxed, then ignore
   3320      1.1  christos 	 this reloc.  */
   3321      1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_NONE
   3322      1.1  christos 	  || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_8
   3323      1.1  christos 	  || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_MAX)
   3324      1.1  christos 	continue;
   3325      1.1  christos 
   3326      1.1  christos       /* Get the section contents if we haven't done so already.  */
   3327      1.1  christos       if (contents == NULL)
   3328      1.1  christos 	{
   3329      1.1  christos 	  /* Get cached copy if it exists.  */
   3330      1.1  christos 	  if (elf_section_data (sec)->this_hdr.contents != NULL)
   3331      1.1  christos 	    contents = elf_section_data (sec)->this_hdr.contents;
   3332      1.1  christos 	  else
   3333      1.1  christos 	    {
   3334      1.1  christos 	      /* Go get them off disk.  */
   3335      1.1  christos 	      if (!bfd_malloc_and_get_section (abfd, sec, &contents))
   3336      1.1  christos 		goto error_return;
   3337      1.1  christos 	    }
   3338      1.1  christos 	}
   3339      1.1  christos 
   3340      1.1  christos       /* Read this BFD's symbols if we haven't done so already.  */
   3341      1.1  christos       if (isymbuf == NULL && symtab_hdr->sh_info != 0)
   3342      1.1  christos 	{
   3343      1.1  christos 	  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   3344      1.1  christos 	  if (isymbuf == NULL)
   3345      1.1  christos 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
   3346      1.1  christos 					    symtab_hdr->sh_info, 0,
   3347      1.1  christos 					    NULL, NULL, NULL);
   3348      1.1  christos 	  if (isymbuf == NULL)
   3349      1.1  christos 	    goto error_return;
   3350      1.1  christos 	}
   3351      1.1  christos 
   3352      1.1  christos       /* Get the value of the symbol referred to by the reloc.  */
   3353      1.1  christos       if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
   3354      1.1  christos 	{
   3355      1.1  christos 	  Elf_Internal_Sym *isym;
   3356      1.1  christos 	  const char *sym_name;
   3357      1.1  christos 	  char *new_name;
   3358      1.1  christos 
   3359      1.1  christos 	  /* A local symbol.  */
   3360      1.1  christos 	  isym = isymbuf + ELF32_R_SYM (irel->r_info);
   3361      1.1  christos 	  if (isym->st_shndx == SHN_UNDEF)
   3362      1.1  christos 	    sym_sec = bfd_und_section_ptr;
   3363      1.1  christos 	  else if (isym->st_shndx == SHN_ABS)
   3364      1.1  christos 	    sym_sec = bfd_abs_section_ptr;
   3365      1.1  christos 	  else if (isym->st_shndx == SHN_COMMON)
   3366      1.1  christos 	    sym_sec = bfd_com_section_ptr;
   3367      1.1  christos 	  else
   3368      1.1  christos 	    sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
   3369      1.1  christos 
   3370      1.1  christos 	  sym_name = bfd_elf_string_from_elf_section (abfd,
   3371      1.1  christos 						      symtab_hdr->sh_link,
   3372      1.1  christos 						      isym->st_name);
   3373      1.1  christos 
   3374  1.1.1.2  christos 	  if ((sym_sec->flags & SEC_MERGE)
   3375      1.1  christos 	      && sym_sec->sec_info_type == SEC_INFO_TYPE_MERGE)
   3376      1.1  christos 	    {
   3377      1.1  christos 	      symval = isym->st_value;
   3378      1.1  christos 
   3379      1.1  christos 	      /* GAS may reduce relocations against symbols in SEC_MERGE
   3380      1.1  christos 		 sections to a relocation against the section symbol when
   3381      1.1  christos 		 the original addend was zero.  When the reloc is against
   3382      1.1  christos 		 a section symbol we should include the addend in the
   3383      1.1  christos 		 offset passed to _bfd_merged_section_offset, since the
   3384      1.1  christos 		 location of interest is the original symbol.  On the
   3385      1.1  christos 		 other hand, an access to "sym+addend" where "sym" is not
   3386      1.1  christos 		 a section symbol should not include the addend;  Such an
   3387      1.1  christos 		 access is presumed to be an offset from "sym";  The
   3388      1.1  christos 		 location of interest is just "sym".  */
   3389      1.1  christos 	      if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
   3390      1.1  christos 		symval += irel->r_addend;
   3391      1.1  christos 
   3392      1.1  christos 	      symval = _bfd_merged_section_offset (abfd, & sym_sec,
   3393      1.1  christos 						   elf_section_data (sym_sec)->sec_info,
   3394      1.1  christos 						   symval);
   3395      1.1  christos 
   3396      1.1  christos 	      if (ELF_ST_TYPE (isym->st_info) != STT_SECTION)
   3397      1.1  christos 		symval += irel->r_addend;
   3398      1.1  christos 
   3399      1.1  christos 	      symval += sym_sec->output_section->vma
   3400      1.1  christos 		+ sym_sec->output_offset - irel->r_addend;
   3401      1.1  christos 	    }
   3402      1.1  christos 	  else
   3403      1.1  christos 	    symval = (isym->st_value
   3404      1.1  christos 		      + sym_sec->output_section->vma
   3405      1.1  christos 		      + sym_sec->output_offset);
   3406      1.1  christos 
   3407      1.1  christos 	  /* Tack on an ID so we can uniquely identify this
   3408      1.1  christos 	     local symbol in the global hash table.  */
   3409      1.1  christos 	  new_name = bfd_malloc ((bfd_size_type) strlen (sym_name) + 10);
   3410      1.1  christos 	  if (new_name == NULL)
   3411      1.1  christos 	    goto error_return;
   3412      1.1  christos 	  sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
   3413      1.1  christos 	  sym_name = new_name;
   3414      1.1  christos 
   3415      1.1  christos 	  h = (struct elf32_mn10300_link_hash_entry *)
   3416      1.1  christos 		elf_link_hash_lookup (&hash_table->static_hash_table->root,
   3417      1.1  christos 				      sym_name, FALSE, FALSE, FALSE);
   3418      1.1  christos 	  free (new_name);
   3419      1.1  christos 	}
   3420      1.1  christos       else
   3421      1.1  christos 	{
   3422      1.1  christos 	  unsigned long indx;
   3423      1.1  christos 
   3424      1.1  christos 	  /* An external symbol.  */
   3425      1.1  christos 	  indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
   3426      1.1  christos 	  h = (struct elf32_mn10300_link_hash_entry *)
   3427      1.1  christos 		(elf_sym_hashes (abfd)[indx]);
   3428      1.1  christos 	  BFD_ASSERT (h != NULL);
   3429      1.1  christos 	  if (h->root.root.type != bfd_link_hash_defined
   3430      1.1  christos 	      && h->root.root.type != bfd_link_hash_defweak)
   3431      1.1  christos 	    /* This appears to be a reference to an undefined
   3432      1.1  christos 	       symbol.  Just ignore it--it will be caught by the
   3433      1.1  christos 	       regular reloc processing.  */
   3434      1.1  christos 	    continue;
   3435      1.1  christos 
   3436      1.1  christos 	  /* Check for a reference to a discarded symbol and ignore it.  */
   3437      1.1  christos 	  if (h->root.root.u.def.section->output_section == NULL)
   3438      1.1  christos 	    continue;
   3439      1.1  christos 
   3440      1.1  christos 	  sym_sec = h->root.root.u.def.section->output_section;
   3441      1.1  christos 
   3442      1.1  christos 	  symval = (h->root.root.u.def.value
   3443      1.1  christos 		    + h->root.root.u.def.section->output_section->vma
   3444      1.1  christos 		    + h->root.root.u.def.section->output_offset);
   3445      1.1  christos 	}
   3446      1.1  christos 
   3447      1.1  christos       /* For simplicity of coding, we are going to modify the section
   3448      1.1  christos 	 contents, the section relocs, and the BFD symbol table.  We
   3449      1.1  christos 	 must tell the rest of the code not to free up this
   3450      1.1  christos 	 information.  It would be possible to instead create a table
   3451      1.1  christos 	 of changes which have to be made, as is done in coff-mips.c;
   3452      1.1  christos 	 that would be more work, but would require less memory when
   3453      1.1  christos 	 the linker is run.  */
   3454      1.1  christos 
   3455      1.1  christos       /* Try to turn a 32bit pc-relative branch/call into a 16bit pc-relative
   3456      1.1  christos 	 branch/call, also deal with "call" -> "calls" conversions and
   3457      1.1  christos 	 insertion of prologue data into "call" instructions.  */
   3458      1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL32
   3459      1.1  christos 	  || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32)
   3460      1.1  christos 	{
   3461      1.1  christos 	  bfd_vma value = symval;
   3462      1.1  christos 
   3463      1.1  christos 	  if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32
   3464      1.1  christos 	      && h != NULL
   3465      1.1  christos 	      && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
   3466      1.1  christos 	      && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
   3467      1.1  christos 	      && h->root.plt.offset != (bfd_vma) -1)
   3468      1.1  christos 	    {
   3469      1.1  christos 	      asection * splt;
   3470  1.1.1.2  christos 
   3471      1.1  christos 	      splt = hash_table->root.splt;
   3472      1.1  christos 	      value = ((splt->output_section->vma
   3473      1.1  christos 			+ splt->output_offset
   3474      1.1  christos 			+ h->root.plt.offset)
   3475      1.1  christos 		       - (sec->output_section->vma
   3476      1.1  christos 			  + sec->output_offset
   3477      1.1  christos 			  + irel->r_offset));
   3478      1.1  christos 	    }
   3479      1.1  christos 
   3480      1.1  christos 	  /* If we've got a "call" instruction that needs to be turned
   3481      1.1  christos 	     into a "calls" instruction, do so now.  It saves a byte.  */
   3482      1.1  christos 	  if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
   3483      1.1  christos 	    {
   3484      1.1  christos 	      unsigned char code;
   3485      1.1  christos 
   3486      1.1  christos 	      /* Get the opcode.  */
   3487      1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3488      1.1  christos 
   3489      1.1  christos 	      /* Make sure we're working with a "call" instruction!  */
   3490      1.1  christos 	      if (code == 0xdd)
   3491      1.1  christos 		{
   3492      1.1  christos 		  /* Note that we've changed the relocs, section contents,
   3493      1.1  christos 		     etc.  */
   3494      1.1  christos 		  elf_section_data (sec)->relocs = internal_relocs;
   3495      1.1  christos 		  elf_section_data (sec)->this_hdr.contents = contents;
   3496      1.1  christos 		  symtab_hdr->contents = (unsigned char *) isymbuf;
   3497      1.1  christos 
   3498      1.1  christos 		  /* Fix the opcode.  */
   3499      1.1  christos 		  bfd_put_8 (abfd, 0xfc, contents + irel->r_offset - 1);
   3500      1.1  christos 		  bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
   3501      1.1  christos 
   3502      1.1  christos 		  /* Fix irel->r_offset and irel->r_addend.  */
   3503      1.1  christos 		  irel->r_offset += 1;
   3504      1.1  christos 		  irel->r_addend += 1;
   3505      1.1  christos 
   3506      1.1  christos 		  /* Delete one byte of data.  */
   3507      1.1  christos 		  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3508      1.1  christos 						       irel->r_offset + 3, 1))
   3509      1.1  christos 		    goto error_return;
   3510      1.1  christos 
   3511      1.1  christos 		  /* That will change things, so, we should relax again.
   3512      1.1  christos 		     Note that this is not required, and it may be slow.  */
   3513      1.1  christos 		  *again = TRUE;
   3514      1.1  christos 		}
   3515      1.1  christos 	    }
   3516      1.1  christos 	  else if (h)
   3517      1.1  christos 	    {
   3518      1.1  christos 	      /* We've got a "call" instruction which needs some data
   3519      1.1  christos 		 from target function filled in.  */
   3520      1.1  christos 	      unsigned char code;
   3521      1.1  christos 
   3522      1.1  christos 	      /* Get the opcode.  */
   3523      1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3524      1.1  christos 
   3525      1.1  christos 	      /* Insert data from the target function into the "call"
   3526      1.1  christos 		 instruction if needed.  */
   3527      1.1  christos 	      if (code == 0xdd)
   3528      1.1  christos 		{
   3529      1.1  christos 		  bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 4);
   3530      1.1  christos 		  bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
   3531      1.1  christos 			     contents + irel->r_offset + 5);
   3532      1.1  christos 		}
   3533      1.1  christos 	    }
   3534      1.1  christos 
   3535      1.1  christos 	  /* Deal with pc-relative gunk.  */
   3536      1.1  christos 	  value -= (sec->output_section->vma + sec->output_offset);
   3537      1.1  christos 	  value -= irel->r_offset;
   3538      1.1  christos 	  value += irel->r_addend;
   3539      1.1  christos 
   3540      1.1  christos 	  /* See if the value will fit in 16 bits, note the high value is
   3541      1.1  christos 	     0x7fff + 2 as the target will be two bytes closer if we are
   3542      1.1  christos 	     able to relax, if it's in the same section.  */
   3543      1.1  christos 	  if (sec->output_section == sym_sec->output_section)
   3544      1.1  christos 	    jump_offset = 0x8001;
   3545      1.1  christos 	  else
   3546      1.1  christos 	    jump_offset = 0x7fff;
   3547      1.1  christos 
   3548      1.1  christos 	  /* Account for jumps across alignment boundaries using
   3549      1.1  christos 	     align_gap_adjustment.  */
   3550      1.1  christos 	  if ((bfd_signed_vma) value < jump_offset - (bfd_signed_vma) align_gap_adjustment
   3551      1.1  christos 	      && ((bfd_signed_vma) value > -0x8000 + (bfd_signed_vma) align_gap_adjustment))
   3552      1.1  christos 	    {
   3553      1.1  christos 	      unsigned char code;
   3554      1.1  christos 
   3555      1.1  christos 	      /* Get the opcode.  */
   3556      1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3557      1.1  christos 
   3558      1.1  christos 	      if (code != 0xdc && code != 0xdd && code != 0xff)
   3559      1.1  christos 		continue;
   3560      1.1  christos 
   3561      1.1  christos 	      /* Note that we've changed the relocs, section contents, etc.  */
   3562      1.1  christos 	      elf_section_data (sec)->relocs = internal_relocs;
   3563      1.1  christos 	      elf_section_data (sec)->this_hdr.contents = contents;
   3564      1.1  christos 	      symtab_hdr->contents = (unsigned char *) isymbuf;
   3565      1.1  christos 
   3566      1.1  christos 	      /* Fix the opcode.  */
   3567      1.1  christos 	      if (code == 0xdc)
   3568      1.1  christos 		bfd_put_8 (abfd, 0xcc, contents + irel->r_offset - 1);
   3569      1.1  christos 	      else if (code == 0xdd)
   3570      1.1  christos 		bfd_put_8 (abfd, 0xcd, contents + irel->r_offset - 1);
   3571      1.1  christos 	      else if (code == 0xff)
   3572      1.1  christos 		bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
   3573      1.1  christos 
   3574      1.1  christos 	      /* Fix the relocation's type.  */
   3575      1.1  christos 	      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   3576      1.1  christos 					   (ELF32_R_TYPE (irel->r_info)
   3577      1.1  christos 					    == (int) R_MN10300_PLT32)
   3578      1.1  christos 					   ? R_MN10300_PLT16 :
   3579      1.1  christos 					   R_MN10300_PCREL16);
   3580      1.1  christos 
   3581      1.1  christos 	      /* Delete two bytes of data.  */
   3582      1.1  christos 	      if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3583      1.1  christos 						   irel->r_offset + 1, 2))
   3584      1.1  christos 		goto error_return;
   3585      1.1  christos 
   3586      1.1  christos 	      /* That will change things, so, we should relax again.
   3587      1.1  christos 		 Note that this is not required, and it may be slow.  */
   3588      1.1  christos 	      *again = TRUE;
   3589      1.1  christos 	    }
   3590      1.1  christos 	}
   3591      1.1  christos 
   3592      1.1  christos       /* Try to turn a 16bit pc-relative branch into a 8bit pc-relative
   3593      1.1  christos 	 branch.  */
   3594      1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL16)
   3595      1.1  christos 	{
   3596      1.1  christos 	  bfd_vma value = symval;
   3597      1.1  christos 
   3598      1.1  christos 	  /* If we've got a "call" instruction that needs to be turned
   3599      1.1  christos 	     into a "calls" instruction, do so now.  It saves a byte.  */
   3600      1.1  christos 	  if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
   3601      1.1  christos 	    {
   3602      1.1  christos 	      unsigned char code;
   3603      1.1  christos 
   3604      1.1  christos 	      /* Get the opcode.  */
   3605      1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3606      1.1  christos 
   3607      1.1  christos 	      /* Make sure we're working with a "call" instruction!  */
   3608      1.1  christos 	      if (code == 0xcd)
   3609      1.1  christos 		{
   3610      1.1  christos 		  /* Note that we've changed the relocs, section contents,
   3611      1.1  christos 		     etc.  */
   3612      1.1  christos 		  elf_section_data (sec)->relocs = internal_relocs;
   3613      1.1  christos 		  elf_section_data (sec)->this_hdr.contents = contents;
   3614      1.1  christos 		  symtab_hdr->contents = (unsigned char *) isymbuf;
   3615      1.1  christos 
   3616      1.1  christos 		  /* Fix the opcode.  */
   3617      1.1  christos 		  bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 1);
   3618      1.1  christos 		  bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
   3619      1.1  christos 
   3620      1.1  christos 		  /* Fix irel->r_offset and irel->r_addend.  */
   3621      1.1  christos 		  irel->r_offset += 1;
   3622      1.1  christos 		  irel->r_addend += 1;
   3623      1.1  christos 
   3624      1.1  christos 		  /* Delete one byte of data.  */
   3625      1.1  christos 		  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3626      1.1  christos 						       irel->r_offset + 1, 1))
   3627      1.1  christos 		    goto error_return;
   3628      1.1  christos 
   3629      1.1  christos 		  /* That will change things, so, we should relax again.
   3630      1.1  christos 		     Note that this is not required, and it may be slow.  */
   3631      1.1  christos 		  *again = TRUE;
   3632      1.1  christos 		}
   3633      1.1  christos 	    }
   3634      1.1  christos 	  else if (h)
   3635      1.1  christos 	    {
   3636      1.1  christos 	      unsigned char code;
   3637      1.1  christos 
   3638      1.1  christos 	      /* Get the opcode.  */
   3639      1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3640      1.1  christos 
   3641      1.1  christos 	      /* Insert data from the target function into the "call"
   3642      1.1  christos 		 instruction if needed.  */
   3643      1.1  christos 	      if (code == 0xcd)
   3644      1.1  christos 		{
   3645      1.1  christos 		  bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 2);
   3646      1.1  christos 		  bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
   3647      1.1  christos 			     contents + irel->r_offset + 3);
   3648      1.1  christos 		}
   3649      1.1  christos 	    }
   3650      1.1  christos 
   3651      1.1  christos 	  /* Deal with pc-relative gunk.  */
   3652      1.1  christos 	  value -= (sec->output_section->vma + sec->output_offset);
   3653      1.1  christos 	  value -= irel->r_offset;
   3654      1.1  christos 	  value += irel->r_addend;
   3655      1.1  christos 
   3656      1.1  christos 	  /* See if the value will fit in 8 bits, note the high value is
   3657      1.1  christos 	     0x7f + 1 as the target will be one bytes closer if we are
   3658      1.1  christos 	     able to relax.  */
   3659      1.1  christos 	  if ((long) value < 0x80 && (long) value > -0x80)
   3660      1.1  christos 	    {
   3661      1.1  christos 	      unsigned char code;
   3662      1.1  christos 
   3663      1.1  christos 	      /* Get the opcode.  */
   3664      1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3665      1.1  christos 
   3666      1.1  christos 	      if (code != 0xcc)
   3667      1.1  christos 		continue;
   3668      1.1  christos 
   3669      1.1  christos 	      /* Note that we've changed the relocs, section contents, etc.  */
   3670      1.1  christos 	      elf_section_data (sec)->relocs = internal_relocs;
   3671      1.1  christos 	      elf_section_data (sec)->this_hdr.contents = contents;
   3672      1.1  christos 	      symtab_hdr->contents = (unsigned char *) isymbuf;
   3673      1.1  christos 
   3674      1.1  christos 	      /* Fix the opcode.  */
   3675      1.1  christos 	      bfd_put_8 (abfd, 0xca, contents + irel->r_offset - 1);
   3676      1.1  christos 
   3677      1.1  christos 	      /* Fix the relocation's type.  */
   3678      1.1  christos 	      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   3679      1.1  christos 					   R_MN10300_PCREL8);
   3680      1.1  christos 
   3681      1.1  christos 	      /* Delete one byte of data.  */
   3682      1.1  christos 	      if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3683      1.1  christos 						   irel->r_offset + 1, 1))
   3684      1.1  christos 		goto error_return;
   3685      1.1  christos 
   3686      1.1  christos 	      /* That will change things, so, we should relax again.
   3687      1.1  christos 		 Note that this is not required, and it may be slow.  */
   3688      1.1  christos 	      *again = TRUE;
   3689      1.1  christos 	    }
   3690      1.1  christos 	}
   3691      1.1  christos 
   3692      1.1  christos       /* Try to eliminate an unconditional 8 bit pc-relative branch
   3693      1.1  christos 	 which immediately follows a conditional 8 bit pc-relative
   3694      1.1  christos 	 branch around the unconditional branch.
   3695      1.1  christos 
   3696      1.1  christos 	    original:		new:
   3697      1.1  christos 	    bCC lab1		bCC' lab2
   3698      1.1  christos 	    bra lab2
   3699      1.1  christos 	   lab1:	       lab1:
   3700      1.1  christos 
   3701      1.1  christos 	 This happens when the bCC can't reach lab2 at assembly time,
   3702      1.1  christos 	 but due to other relaxations it can reach at link time.  */
   3703      1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL8)
   3704      1.1  christos 	{
   3705      1.1  christos 	  Elf_Internal_Rela *nrel;
   3706      1.1  christos 	  bfd_vma value = symval;
   3707      1.1  christos 	  unsigned char code;
   3708      1.1  christos 
   3709      1.1  christos 	  /* Deal with pc-relative gunk.  */
   3710      1.1  christos 	  value -= (sec->output_section->vma + sec->output_offset);
   3711      1.1  christos 	  value -= irel->r_offset;
   3712      1.1  christos 	  value += irel->r_addend;
   3713      1.1  christos 
   3714      1.1  christos 	  /* Do nothing if this reloc is the last byte in the section.  */
   3715      1.1  christos 	  if (irel->r_offset == sec->size)
   3716      1.1  christos 	    continue;
   3717      1.1  christos 
   3718      1.1  christos 	  /* See if the next instruction is an unconditional pc-relative
   3719      1.1  christos 	     branch, more often than not this test will fail, so we
   3720      1.1  christos 	     test it first to speed things up.  */
   3721      1.1  christos 	  code = bfd_get_8 (abfd, contents + irel->r_offset + 1);
   3722      1.1  christos 	  if (code != 0xca)
   3723      1.1  christos 	    continue;
   3724      1.1  christos 
   3725      1.1  christos 	  /* Also make sure the next relocation applies to the next
   3726      1.1  christos 	     instruction and that it's a pc-relative 8 bit branch.  */
   3727      1.1  christos 	  nrel = irel + 1;
   3728      1.1  christos 	  if (nrel == irelend
   3729      1.1  christos 	      || irel->r_offset + 2 != nrel->r_offset
   3730      1.1  christos 	      || ELF32_R_TYPE (nrel->r_info) != (int) R_MN10300_PCREL8)
   3731      1.1  christos 	    continue;
   3732      1.1  christos 
   3733      1.1  christos 	  /* Make sure our destination immediately follows the
   3734      1.1  christos 	     unconditional branch.  */
   3735      1.1  christos 	  if (symval != (sec->output_section->vma + sec->output_offset
   3736      1.1  christos 			 + irel->r_offset + 3))
   3737      1.1  christos 	    continue;
   3738      1.1  christos 
   3739      1.1  christos 	  /* Now make sure we are a conditional branch.  This may not
   3740      1.1  christos 	     be necessary, but why take the chance.
   3741      1.1  christos 
   3742      1.1  christos 	     Note these checks assume that R_MN10300_PCREL8 relocs
   3743      1.1  christos 	     only occur on bCC and bCCx insns.  If they occured
   3744      1.1  christos 	     elsewhere, we'd need to know the start of this insn
   3745      1.1  christos 	     for this check to be accurate.  */
   3746      1.1  christos 	  code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3747      1.1  christos 	  if (code != 0xc0 && code != 0xc1 && code != 0xc2
   3748      1.1  christos 	      && code != 0xc3 && code != 0xc4 && code != 0xc5
   3749      1.1  christos 	      && code != 0xc6 && code != 0xc7 && code != 0xc8
   3750      1.1  christos 	      && code != 0xc9 && code != 0xe8 && code != 0xe9
   3751      1.1  christos 	      && code != 0xea && code != 0xeb)
   3752      1.1  christos 	    continue;
   3753      1.1  christos 
   3754      1.1  christos 	  /* We also have to be sure there is no symbol/label
   3755      1.1  christos 	     at the unconditional branch.  */
   3756      1.1  christos 	  if (mn10300_elf_symbol_address_p (abfd, sec, isymbuf,
   3757      1.1  christos 					    irel->r_offset + 1))
   3758      1.1  christos 	    continue;
   3759      1.1  christos 
   3760      1.1  christos 	  /* Note that we've changed the relocs, section contents, etc.  */
   3761      1.1  christos 	  elf_section_data (sec)->relocs = internal_relocs;
   3762      1.1  christos 	  elf_section_data (sec)->this_hdr.contents = contents;
   3763      1.1  christos 	  symtab_hdr->contents = (unsigned char *) isymbuf;
   3764      1.1  christos 
   3765      1.1  christos 	  /* Reverse the condition of the first branch.  */
   3766      1.1  christos 	  switch (code)
   3767      1.1  christos 	    {
   3768      1.1  christos 	    case 0xc8:
   3769      1.1  christos 	      code = 0xc9;
   3770      1.1  christos 	      break;
   3771      1.1  christos 	    case 0xc9:
   3772      1.1  christos 	      code = 0xc8;
   3773      1.1  christos 	      break;
   3774      1.1  christos 	    case 0xc0:
   3775      1.1  christos 	      code = 0xc2;
   3776      1.1  christos 	      break;
   3777      1.1  christos 	    case 0xc2:
   3778      1.1  christos 	      code = 0xc0;
   3779      1.1  christos 	      break;
   3780      1.1  christos 	    case 0xc3:
   3781      1.1  christos 	      code = 0xc1;
   3782      1.1  christos 	      break;
   3783      1.1  christos 	    case 0xc1:
   3784      1.1  christos 	      code = 0xc3;
   3785      1.1  christos 	      break;
   3786      1.1  christos 	    case 0xc4:
   3787      1.1  christos 	      code = 0xc6;
   3788      1.1  christos 	      break;
   3789      1.1  christos 	    case 0xc6:
   3790      1.1  christos 	      code = 0xc4;
   3791      1.1  christos 	      break;
   3792      1.1  christos 	    case 0xc7:
   3793      1.1  christos 	      code = 0xc5;
   3794      1.1  christos 	      break;
   3795      1.1  christos 	    case 0xc5:
   3796      1.1  christos 	      code = 0xc7;
   3797      1.1  christos 	      break;
   3798      1.1  christos 	    case 0xe8:
   3799      1.1  christos 	      code = 0xe9;
   3800      1.1  christos 	      break;
   3801      1.1  christos 	    case 0x9d:
   3802      1.1  christos 	      code = 0xe8;
   3803      1.1  christos 	      break;
   3804      1.1  christos 	    case 0xea:
   3805      1.1  christos 	      code = 0xeb;
   3806      1.1  christos 	      break;
   3807      1.1  christos 	    case 0xeb:
   3808      1.1  christos 	      code = 0xea;
   3809      1.1  christos 	      break;
   3810      1.1  christos 	    }
   3811      1.1  christos 	  bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
   3812      1.1  christos 
   3813      1.1  christos 	  /* Set the reloc type and symbol for the first branch
   3814      1.1  christos 	     from the second branch.  */
   3815      1.1  christos 	  irel->r_info = nrel->r_info;
   3816      1.1  christos 
   3817      1.1  christos 	  /* Make the reloc for the second branch a null reloc.  */
   3818      1.1  christos 	  nrel->r_info = ELF32_R_INFO (ELF32_R_SYM (nrel->r_info),
   3819      1.1  christos 				       R_MN10300_NONE);
   3820      1.1  christos 
   3821      1.1  christos 	  /* Delete two bytes of data.  */
   3822      1.1  christos 	  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3823      1.1  christos 					       irel->r_offset + 1, 2))
   3824      1.1  christos 	    goto error_return;
   3825      1.1  christos 
   3826      1.1  christos 	  /* That will change things, so, we should relax again.
   3827      1.1  christos 	     Note that this is not required, and it may be slow.  */
   3828      1.1  christos 	  *again = TRUE;
   3829      1.1  christos 	}
   3830      1.1  christos 
   3831      1.1  christos       /* Try to turn a 24 immediate, displacement or absolute address
   3832      1.1  christos 	 into a 8 immediate, displacement or absolute address.  */
   3833      1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_24)
   3834      1.1  christos 	{
   3835      1.1  christos 	  bfd_vma value = symval;
   3836      1.1  christos 	  value += irel->r_addend;
   3837      1.1  christos 
   3838      1.1  christos 	  /* See if the value will fit in 8 bits.  */
   3839      1.1  christos 	  if ((long) value < 0x7f && (long) value > -0x80)
   3840      1.1  christos 	    {
   3841      1.1  christos 	      unsigned char code;
   3842      1.1  christos 
   3843      1.1  christos 	      /* AM33 insns which have 24 operands are 6 bytes long and
   3844      1.1  christos 		 will have 0xfd as the first byte.  */
   3845      1.1  christos 
   3846      1.1  christos 	      /* Get the first opcode.  */
   3847      1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
   3848      1.1  christos 
   3849      1.1  christos 	      if (code == 0xfd)
   3850      1.1  christos 		{
   3851      1.1  christos 		  /* Get the second opcode.  */
   3852      1.1  christos 		  code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
   3853      1.1  christos 
   3854      1.1  christos 		  /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
   3855      1.1  christos 		     equivalent instructions exists.  */
   3856      1.1  christos 		  if (code != 0x6b && code != 0x7b
   3857      1.1  christos 		      && code != 0x8b && code != 0x9b
   3858      1.1  christos 		      && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
   3859      1.1  christos 			  || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
   3860      1.1  christos 			  || (code & 0x0f) == 0x0e))
   3861      1.1  christos 		    {
   3862      1.1  christos 		      /* Not safe if the high bit is on as relaxing may
   3863      1.1  christos 			 move the value out of high mem and thus not fit
   3864      1.1  christos 			 in a signed 8bit value.  This is currently over
   3865      1.1  christos 			 conservative.  */
   3866      1.1  christos 		      if ((value & 0x80) == 0)
   3867      1.1  christos 			{
   3868      1.1  christos 			  /* Note that we've changed the relocation contents,
   3869      1.1  christos 			     etc.  */
   3870      1.1  christos 			  elf_section_data (sec)->relocs = internal_relocs;
   3871      1.1  christos 			  elf_section_data (sec)->this_hdr.contents = contents;
   3872      1.1  christos 			  symtab_hdr->contents = (unsigned char *) isymbuf;
   3873      1.1  christos 
   3874      1.1  christos 			  /* Fix the opcode.  */
   3875      1.1  christos 			  bfd_put_8 (abfd, 0xfb, contents + irel->r_offset - 3);
   3876      1.1  christos 			  bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
   3877      1.1  christos 
   3878      1.1  christos 			  /* Fix the relocation's type.  */
   3879      1.1  christos 			  irel->r_info =
   3880      1.1  christos 			    ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   3881      1.1  christos 					  R_MN10300_8);
   3882      1.1  christos 
   3883      1.1  christos 			  /* Delete two bytes of data.  */
   3884      1.1  christos 			  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3885      1.1  christos 							       irel->r_offset + 1, 2))
   3886      1.1  christos 			    goto error_return;
   3887      1.1  christos 
   3888      1.1  christos 			  /* That will change things, so, we should relax
   3889      1.1  christos 			     again.  Note that this is not required, and it
   3890      1.1  christos 			     may be slow.  */
   3891      1.1  christos 			  *again = TRUE;
   3892      1.1  christos 			  break;
   3893      1.1  christos 			}
   3894      1.1  christos 		    }
   3895      1.1  christos 		}
   3896      1.1  christos 	    }
   3897      1.1  christos 	}
   3898      1.1  christos 
   3899      1.1  christos       /* Try to turn a 32bit immediate, displacement or absolute address
   3900      1.1  christos 	 into a 16bit immediate, displacement or absolute address.  */
   3901      1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_32
   3902      1.1  christos 	  || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32
   3903      1.1  christos 	  || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
   3904      1.1  christos 	{
   3905      1.1  christos 	  bfd_vma value = symval;
   3906      1.1  christos 
   3907      1.1  christos 	  if (ELF32_R_TYPE (irel->r_info) != (int) R_MN10300_32)
   3908      1.1  christos 	    {
   3909      1.1  christos 	      asection * sgot;
   3910  1.1.1.2  christos 
   3911      1.1  christos 	      sgot = hash_table->root.sgot;
   3912      1.1  christos 	      if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32)
   3913      1.1  christos 		{
   3914      1.1  christos 		  value = sgot->output_offset;
   3915      1.1  christos 
   3916      1.1  christos 		  if (h)
   3917      1.1  christos 		    value += h->root.got.offset;
   3918      1.1  christos 		  else
   3919      1.1  christos 		    value += (elf_local_got_offsets
   3920      1.1  christos 			      (abfd)[ELF32_R_SYM (irel->r_info)]);
   3921      1.1  christos 		}
   3922      1.1  christos 	      else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
   3923      1.1  christos 		value -= sgot->output_section->vma;
   3924      1.1  christos 	      else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32)
   3925      1.1  christos 		value = (sgot->output_section->vma
   3926      1.1  christos 			 - (sec->output_section->vma
   3927      1.1  christos 			    + sec->output_offset
   3928      1.1  christos 			    + irel->r_offset));
   3929      1.1  christos 	      else
   3930      1.1  christos 		abort ();
   3931      1.1  christos 	    }
   3932      1.1  christos 
   3933      1.1  christos 	  value += irel->r_addend;
   3934      1.1  christos 
   3935      1.1  christos 	  /* See if the value will fit in 24 bits.
   3936      1.1  christos 	     We allow any 16bit match here.  We prune those we can't
   3937  1.1.1.9  christos 	     handle below.  */
   3938      1.1  christos 	  if (value + 0x800000 < 0x1000000 && irel->r_offset >= 3)
   3939      1.1  christos 	    {
   3940      1.1  christos 	      unsigned char code;
   3941      1.1  christos 
   3942      1.1  christos 	      /* AM33 insns which have 32bit operands are 7 bytes long and
   3943      1.1  christos 		 will have 0xfe as the first byte.  */
   3944      1.1  christos 
   3945      1.1  christos 	      /* Get the first opcode.  */
   3946      1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
   3947      1.1  christos 
   3948      1.1  christos 	      if (code == 0xfe)
   3949      1.1  christos 		{
   3950      1.1  christos 		  /* Get the second opcode.  */
   3951      1.1  christos 		  code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
   3952      1.1  christos 
   3953      1.1  christos 		  /* All the am33 32 -> 24 relaxing possibilities.  */
   3954      1.1  christos 		  /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
   3955      1.1  christos 		     equivalent instructions exists.  */
   3956      1.1  christos 		  if (code != 0x6b && code != 0x7b
   3957      1.1  christos 		      && code != 0x8b && code != 0x9b
   3958      1.1  christos 		      && (ELF32_R_TYPE (irel->r_info)
   3959      1.1  christos 			  != (int) R_MN10300_GOTPC32)
   3960      1.1  christos 		      && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
   3961      1.1  christos 			  || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
   3962      1.1  christos 			  || (code & 0x0f) == 0x0e))
   3963      1.1  christos 		    {
   3964      1.1  christos 		      /* Not safe if the high bit is on as relaxing may
   3965      1.1  christos 			 move the value out of high mem and thus not fit
   3966      1.1  christos 			 in a signed 16bit value.  This is currently over
   3967      1.1  christos 			 conservative.  */
   3968      1.1  christos 		      if ((value & 0x8000) == 0)
   3969      1.1  christos 			{
   3970      1.1  christos 			  /* Note that we've changed the relocation contents,
   3971      1.1  christos 			     etc.  */
   3972      1.1  christos 			  elf_section_data (sec)->relocs = internal_relocs;
   3973      1.1  christos 			  elf_section_data (sec)->this_hdr.contents = contents;
   3974      1.1  christos 			  symtab_hdr->contents = (unsigned char *) isymbuf;
   3975      1.1  christos 
   3976      1.1  christos 			  /* Fix the opcode.  */
   3977      1.1  christos 			  bfd_put_8 (abfd, 0xfd, contents + irel->r_offset - 3);
   3978      1.1  christos 			  bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
   3979      1.1  christos 
   3980      1.1  christos 			  /* Fix the relocation's type.  */
   3981      1.1  christos 			  irel->r_info =
   3982      1.1  christos 			    ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   3983      1.1  christos 					  (ELF32_R_TYPE (irel->r_info)
   3984      1.1  christos 					   == (int) R_MN10300_GOTOFF32)
   3985      1.1  christos 					  ? R_MN10300_GOTOFF24
   3986      1.1  christos 					  : (ELF32_R_TYPE (irel->r_info)
   3987      1.1  christos 					     == (int) R_MN10300_GOT32)
   3988      1.1  christos 					  ? R_MN10300_GOT24 :
   3989      1.1  christos 					  R_MN10300_24);
   3990      1.1  christos 
   3991      1.1  christos 			  /* Delete one byte of data.  */
   3992      1.1  christos 			  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3993      1.1  christos 							       irel->r_offset + 3, 1))
   3994      1.1  christos 			    goto error_return;
   3995      1.1  christos 
   3996      1.1  christos 			  /* That will change things, so, we should relax
   3997      1.1  christos 			     again.  Note that this is not required, and it
   3998      1.1  christos 			     may be slow.  */
   3999      1.1  christos 			  *again = TRUE;
   4000      1.1  christos 			  break;
   4001      1.1  christos 			}
   4002      1.1  christos 		    }
   4003      1.1  christos 		}
   4004      1.1  christos 	    }
   4005      1.1  christos 
   4006      1.1  christos 	  /* See if the value will fit in 16 bits.
   4007      1.1  christos 	     We allow any 16bit match here.  We prune those we can't
   4008  1.1.1.9  christos 	     handle below.  */
   4009      1.1  christos 	  if (value + 0x8000 < 0x10000 && irel->r_offset >= 2)
   4010      1.1  christos 	    {
   4011      1.1  christos 	      unsigned char code;
   4012      1.1  christos 
   4013      1.1  christos 	      /* Most insns which have 32bit operands are 6 bytes long;
   4014      1.1  christos 		 exceptions are pcrel insns and bit insns.
   4015      1.1  christos 
   4016      1.1  christos 		 We handle pcrel insns above.  We don't bother trying
   4017      1.1  christos 		 to handle the bit insns here.
   4018      1.1  christos 
   4019      1.1  christos 		 The first byte of the remaining insns will be 0xfc.  */
   4020      1.1  christos 
   4021      1.1  christos 	      /* Get the first opcode.  */
   4022      1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
   4023      1.1  christos 
   4024      1.1  christos 	      if (code != 0xfc)
   4025      1.1  christos 		continue;
   4026      1.1  christos 
   4027      1.1  christos 	      /* Get the second opcode.  */
   4028      1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   4029      1.1  christos 
   4030      1.1  christos 	      if ((code & 0xf0) < 0x80)
   4031      1.1  christos 		switch (code & 0xf0)
   4032      1.1  christos 		  {
   4033      1.1  christos 		  /* mov (d32,am),dn   -> mov (d32,am),dn
   4034      1.1  christos 		     mov dm,(d32,am)   -> mov dn,(d32,am)
   4035      1.1  christos 		     mov (d32,am),an   -> mov (d32,am),an
   4036      1.1  christos 		     mov dm,(d32,am)   -> mov dn,(d32,am)
   4037      1.1  christos 		     movbu (d32,am),dn -> movbu (d32,am),dn
   4038      1.1  christos 		     movbu dm,(d32,am) -> movbu dn,(d32,am)
   4039      1.1  christos 		     movhu (d32,am),dn -> movhu (d32,am),dn
   4040      1.1  christos 		     movhu dm,(d32,am) -> movhu dn,(d32,am) */
   4041      1.1  christos 		  case 0x00:
   4042      1.1  christos 		  case 0x10:
   4043      1.1  christos 		  case 0x20:
   4044      1.1  christos 		  case 0x30:
   4045      1.1  christos 		  case 0x40:
   4046      1.1  christos 		  case 0x50:
   4047      1.1  christos 		  case 0x60:
   4048      1.1  christos 		  case 0x70:
   4049      1.1  christos 		    /* Not safe if the high bit is on as relaxing may
   4050      1.1  christos 		       move the value out of high mem and thus not fit
   4051      1.1  christos 		       in a signed 16bit value.  */
   4052      1.1  christos 		    if (code == 0xcc
   4053      1.1  christos 			&& (value & 0x8000))
   4054      1.1  christos 		      continue;
   4055      1.1  christos 
   4056      1.1  christos 		    /* Note that we've changed the relocation contents, etc.  */
   4057      1.1  christos 		    elf_section_data (sec)->relocs = internal_relocs;
   4058      1.1  christos 		    elf_section_data (sec)->this_hdr.contents = contents;
   4059      1.1  christos 		    symtab_hdr->contents = (unsigned char *) isymbuf;
   4060      1.1  christos 
   4061      1.1  christos 		    /* Fix the opcode.  */
   4062      1.1  christos 		    bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
   4063      1.1  christos 		    bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
   4064      1.1  christos 
   4065      1.1  christos 		    /* Fix the relocation's type.  */
   4066      1.1  christos 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4067      1.1  christos 						 (ELF32_R_TYPE (irel->r_info)
   4068      1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4069      1.1  christos 						 ? R_MN10300_GOTOFF16
   4070      1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4071      1.1  christos 						    == (int) R_MN10300_GOT32)
   4072      1.1  christos 						 ? R_MN10300_GOT16
   4073      1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4074      1.1  christos 						    == (int) R_MN10300_GOTPC32)
   4075      1.1  christos 						 ? R_MN10300_GOTPC16 :
   4076      1.1  christos 						 R_MN10300_16);
   4077      1.1  christos 
   4078      1.1  christos 		    /* Delete two bytes of data.  */
   4079      1.1  christos 		    if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4080      1.1  christos 							 irel->r_offset + 2, 2))
   4081      1.1  christos 		      goto error_return;
   4082      1.1  christos 
   4083      1.1  christos 		    /* That will change things, so, we should relax again.
   4084      1.1  christos 		       Note that this is not required, and it may be slow.  */
   4085      1.1  christos 		    *again = TRUE;
   4086      1.1  christos 		    break;
   4087      1.1  christos 		  }
   4088      1.1  christos 	      else if ((code & 0xf0) == 0x80
   4089      1.1  christos 		       || (code & 0xf0) == 0x90)
   4090      1.1  christos 		switch (code & 0xf3)
   4091      1.1  christos 		  {
   4092      1.1  christos 		  /* mov dn,(abs32)   -> mov dn,(abs16)
   4093      1.1  christos 		     movbu dn,(abs32) -> movbu dn,(abs16)
   4094      1.1  christos 		     movhu dn,(abs32) -> movhu dn,(abs16)  */
   4095      1.1  christos 		  case 0x81:
   4096      1.1  christos 		  case 0x82:
   4097      1.1  christos 		  case 0x83:
   4098      1.1  christos 		    /* Note that we've changed the relocation contents, etc.  */
   4099      1.1  christos 		    elf_section_data (sec)->relocs = internal_relocs;
   4100      1.1  christos 		    elf_section_data (sec)->this_hdr.contents = contents;
   4101      1.1  christos 		    symtab_hdr->contents = (unsigned char *) isymbuf;
   4102      1.1  christos 
   4103      1.1  christos 		    if ((code & 0xf3) == 0x81)
   4104      1.1  christos 		      code = 0x01 + (code & 0x0c);
   4105      1.1  christos 		    else if ((code & 0xf3) == 0x82)
   4106      1.1  christos 		      code = 0x02 + (code & 0x0c);
   4107      1.1  christos 		    else if ((code & 0xf3) == 0x83)
   4108      1.1  christos 		      code = 0x03 + (code & 0x0c);
   4109      1.1  christos 		    else
   4110      1.1  christos 		      abort ();
   4111      1.1  christos 
   4112      1.1  christos 		    /* Fix the opcode.  */
   4113      1.1  christos 		    bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
   4114      1.1  christos 
   4115      1.1  christos 		    /* Fix the relocation's type.  */
   4116      1.1  christos 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4117      1.1  christos 						 (ELF32_R_TYPE (irel->r_info)
   4118      1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4119      1.1  christos 						 ? R_MN10300_GOTOFF16
   4120      1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4121      1.1  christos 						    == (int) R_MN10300_GOT32)
   4122      1.1  christos 						 ? R_MN10300_GOT16
   4123      1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4124      1.1  christos 						    == (int) R_MN10300_GOTPC32)
   4125      1.1  christos 						 ? R_MN10300_GOTPC16 :
   4126      1.1  christos 						 R_MN10300_16);
   4127      1.1  christos 
   4128      1.1  christos 		    /* The opcode got shorter too, so we have to fix the
   4129      1.1  christos 		       addend and offset too!  */
   4130      1.1  christos 		    irel->r_offset -= 1;
   4131      1.1  christos 
   4132      1.1  christos 		    /* Delete three bytes of data.  */
   4133      1.1  christos 		    if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4134      1.1  christos 							 irel->r_offset + 1, 3))
   4135      1.1  christos 		      goto error_return;
   4136      1.1  christos 
   4137      1.1  christos 		    /* That will change things, so, we should relax again.
   4138      1.1  christos 		       Note that this is not required, and it may be slow.  */
   4139      1.1  christos 		    *again = TRUE;
   4140      1.1  christos 		    break;
   4141      1.1  christos 
   4142      1.1  christos 		  /* mov am,(abs32)    -> mov am,(abs16)
   4143      1.1  christos 		     mov am,(d32,sp)   -> mov am,(d16,sp)
   4144      1.1  christos 		     mov dm,(d32,sp)   -> mov dm,(d32,sp)
   4145      1.1  christos 		     movbu dm,(d32,sp) -> movbu dm,(d32,sp)
   4146      1.1  christos 		     movhu dm,(d32,sp) -> movhu dm,(d32,sp) */
   4147      1.1  christos 		  case 0x80:
   4148      1.1  christos 		  case 0x90:
   4149      1.1  christos 		  case 0x91:
   4150      1.1  christos 		  case 0x92:
   4151      1.1  christos 		  case 0x93:
   4152      1.1  christos 		    /* sp-based offsets are zero-extended.  */
   4153      1.1  christos 		    if (code >= 0x90 && code <= 0x93
   4154      1.1  christos 			&& (long) value < 0)
   4155      1.1  christos 		      continue;
   4156      1.1  christos 
   4157      1.1  christos 		    /* Note that we've changed the relocation contents, etc.  */
   4158      1.1  christos 		    elf_section_data (sec)->relocs = internal_relocs;
   4159      1.1  christos 		    elf_section_data (sec)->this_hdr.contents = contents;
   4160      1.1  christos 		    symtab_hdr->contents = (unsigned char *) isymbuf;
   4161      1.1  christos 
   4162      1.1  christos 		    /* Fix the opcode.  */
   4163      1.1  christos 		    bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
   4164      1.1  christos 		    bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
   4165      1.1  christos 
   4166      1.1  christos 		    /* Fix the relocation's type.  */
   4167      1.1  christos 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4168      1.1  christos 						 (ELF32_R_TYPE (irel->r_info)
   4169      1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4170      1.1  christos 						 ? R_MN10300_GOTOFF16
   4171      1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4172      1.1  christos 						    == (int) R_MN10300_GOT32)
   4173      1.1  christos 						 ? R_MN10300_GOT16
   4174      1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4175      1.1  christos 						    == (int) R_MN10300_GOTPC32)
   4176      1.1  christos 						 ? R_MN10300_GOTPC16 :
   4177      1.1  christos 						 R_MN10300_16);
   4178      1.1  christos 
   4179      1.1  christos 		    /* Delete two bytes of data.  */
   4180      1.1  christos 		    if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4181      1.1  christos 							 irel->r_offset + 2, 2))
   4182      1.1  christos 		      goto error_return;
   4183      1.1  christos 
   4184      1.1  christos 		    /* That will change things, so, we should relax again.
   4185      1.1  christos 		       Note that this is not required, and it may be slow.  */
   4186      1.1  christos 		    *again = TRUE;
   4187      1.1  christos 		    break;
   4188      1.1  christos 		  }
   4189      1.1  christos 	      else if ((code & 0xf0) < 0xf0)
   4190      1.1  christos 		switch (code & 0xfc)
   4191      1.1  christos 		  {
   4192      1.1  christos 		  /* mov imm32,dn     -> mov imm16,dn
   4193      1.1  christos 		     mov imm32,an     -> mov imm16,an
   4194      1.1  christos 		     mov (abs32),dn   -> mov (abs16),dn
   4195      1.1  christos 		     movbu (abs32),dn -> movbu (abs16),dn
   4196      1.1  christos 		     movhu (abs32),dn -> movhu (abs16),dn  */
   4197      1.1  christos 		  case 0xcc:
   4198      1.1  christos 		  case 0xdc:
   4199      1.1  christos 		  case 0xa4:
   4200      1.1  christos 		  case 0xa8:
   4201      1.1  christos 		  case 0xac:
   4202      1.1  christos 		    /* Not safe if the high bit is on as relaxing may
   4203      1.1  christos 		       move the value out of high mem and thus not fit
   4204      1.1  christos 		       in a signed 16bit value.  */
   4205      1.1  christos 		    if (code == 0xcc
   4206      1.1  christos 			&& (value & 0x8000))
   4207      1.1  christos 		      continue;
   4208  1.1.1.2  christos 
   4209  1.1.1.2  christos 		    /* "mov imm16, an" zero-extends the immediate.  */
   4210      1.1  christos 		    if ((code & 0xfc) == 0xdc
   4211      1.1  christos 			&& (long) value < 0)
   4212      1.1  christos 		      continue;
   4213      1.1  christos 
   4214      1.1  christos 		    /* Note that we've changed the relocation contents, etc.  */
   4215      1.1  christos 		    elf_section_data (sec)->relocs = internal_relocs;
   4216      1.1  christos 		    elf_section_data (sec)->this_hdr.contents = contents;
   4217      1.1  christos 		    symtab_hdr->contents = (unsigned char *) isymbuf;
   4218      1.1  christos 
   4219      1.1  christos 		    if ((code & 0xfc) == 0xcc)
   4220      1.1  christos 		      code = 0x2c + (code & 0x03);
   4221      1.1  christos 		    else if ((code & 0xfc) == 0xdc)
   4222      1.1  christos 		      code = 0x24 + (code & 0x03);
   4223      1.1  christos 		    else if ((code & 0xfc) == 0xa4)
   4224      1.1  christos 		      code = 0x30 + (code & 0x03);
   4225      1.1  christos 		    else if ((code & 0xfc) == 0xa8)
   4226      1.1  christos 		      code = 0x34 + (code & 0x03);
   4227      1.1  christos 		    else if ((code & 0xfc) == 0xac)
   4228      1.1  christos 		      code = 0x38 + (code & 0x03);
   4229      1.1  christos 		    else
   4230      1.1  christos 		      abort ();
   4231      1.1  christos 
   4232      1.1  christos 		    /* Fix the opcode.  */
   4233      1.1  christos 		    bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
   4234      1.1  christos 
   4235      1.1  christos 		    /* Fix the relocation's type.  */
   4236      1.1  christos 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4237      1.1  christos 						 (ELF32_R_TYPE (irel->r_info)
   4238      1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4239      1.1  christos 						 ? R_MN10300_GOTOFF16
   4240      1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4241      1.1  christos 						    == (int) R_MN10300_GOT32)
   4242      1.1  christos 						 ? R_MN10300_GOT16
   4243      1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4244      1.1  christos 						    == (int) R_MN10300_GOTPC32)
   4245      1.1  christos 						 ? R_MN10300_GOTPC16 :
   4246      1.1  christos 						 R_MN10300_16);
   4247      1.1  christos 
   4248      1.1  christos 		    /* The opcode got shorter too, so we have to fix the
   4249      1.1  christos 		       addend and offset too!  */
   4250      1.1  christos 		    irel->r_offset -= 1;
   4251      1.1  christos 
   4252      1.1  christos 		    /* Delete three bytes of data.  */
   4253      1.1  christos 		    if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4254      1.1  christos 							 irel->r_offset + 1, 3))
   4255      1.1  christos 		      goto error_return;
   4256      1.1  christos 
   4257      1.1  christos 		    /* That will change things, so, we should relax again.
   4258      1.1  christos 		       Note that this is not required, and it may be slow.  */
   4259      1.1  christos 		    *again = TRUE;
   4260      1.1  christos 		    break;
   4261      1.1  christos 
   4262      1.1  christos 		  /* mov (abs32),an    -> mov (abs16),an
   4263      1.1  christos 		     mov (d32,sp),an   -> mov (d16,sp),an
   4264      1.1  christos 		     mov (d32,sp),dn   -> mov (d16,sp),dn
   4265      1.1  christos 		     movbu (d32,sp),dn -> movbu (d16,sp),dn
   4266      1.1  christos 		     movhu (d32,sp),dn -> movhu (d16,sp),dn
   4267      1.1  christos 		     add imm32,dn      -> add imm16,dn
   4268      1.1  christos 		     cmp imm32,dn      -> cmp imm16,dn
   4269      1.1  christos 		     add imm32,an      -> add imm16,an
   4270      1.1  christos 		     cmp imm32,an      -> cmp imm16,an
   4271      1.1  christos 		     and imm32,dn      -> and imm16,dn
   4272      1.1  christos 		     or imm32,dn       -> or imm16,dn
   4273      1.1  christos 		     xor imm32,dn      -> xor imm16,dn
   4274      1.1  christos 		     btst imm32,dn     -> btst imm16,dn */
   4275      1.1  christos 
   4276      1.1  christos 		  case 0xa0:
   4277      1.1  christos 		  case 0xb0:
   4278      1.1  christos 		  case 0xb1:
   4279      1.1  christos 		  case 0xb2:
   4280      1.1  christos 		  case 0xb3:
   4281      1.1  christos 		  case 0xc0:
   4282      1.1  christos 		  case 0xc8:
   4283      1.1  christos 
   4284      1.1  christos 		  case 0xd0:
   4285      1.1  christos 		  case 0xd8:
   4286      1.1  christos 		  case 0xe0:
   4287      1.1  christos 		  case 0xe1:
   4288      1.1  christos 		  case 0xe2:
   4289      1.1  christos 		  case 0xe3:
   4290      1.1  christos 		    /* cmp imm16, an zero-extends the immediate.  */
   4291      1.1  christos 		    if (code == 0xdc
   4292      1.1  christos 			&& (long) value < 0)
   4293      1.1  christos 		      continue;
   4294      1.1  christos 
   4295      1.1  christos 		    /* So do sp-based offsets.  */
   4296      1.1  christos 		    if (code >= 0xb0 && code <= 0xb3
   4297      1.1  christos 			&& (long) value < 0)
   4298      1.1  christos 		      continue;
   4299      1.1  christos 
   4300      1.1  christos 		    /* Note that we've changed the relocation contents, etc.  */
   4301      1.1  christos 		    elf_section_data (sec)->relocs = internal_relocs;
   4302      1.1  christos 		    elf_section_data (sec)->this_hdr.contents = contents;
   4303      1.1  christos 		    symtab_hdr->contents = (unsigned char *) isymbuf;
   4304      1.1  christos 
   4305      1.1  christos 		    /* Fix the opcode.  */
   4306      1.1  christos 		    bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
   4307      1.1  christos 		    bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
   4308      1.1  christos 
   4309      1.1  christos 		    /* Fix the relocation's type.  */
   4310      1.1  christos 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4311      1.1  christos 						 (ELF32_R_TYPE (irel->r_info)
   4312      1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4313      1.1  christos 						 ? R_MN10300_GOTOFF16
   4314      1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4315      1.1  christos 						    == (int) R_MN10300_GOT32)
   4316      1.1  christos 						 ? R_MN10300_GOT16
   4317      1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4318      1.1  christos 						    == (int) R_MN10300_GOTPC32)
   4319      1.1  christos 						 ? R_MN10300_GOTPC16 :
   4320      1.1  christos 						 R_MN10300_16);
   4321      1.1  christos 
   4322      1.1  christos 		    /* Delete two bytes of data.  */
   4323      1.1  christos 		    if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4324      1.1  christos 							 irel->r_offset + 2, 2))
   4325      1.1  christos 		      goto error_return;
   4326      1.1  christos 
   4327      1.1  christos 		    /* That will change things, so, we should relax again.
   4328      1.1  christos 		       Note that this is not required, and it may be slow.  */
   4329      1.1  christos 		    *again = TRUE;
   4330      1.1  christos 		    break;
   4331      1.1  christos 		  }
   4332      1.1  christos 	      else if (code == 0xfe)
   4333      1.1  christos 		{
   4334      1.1  christos 		  /* add imm32,sp -> add imm16,sp  */
   4335      1.1  christos 
   4336      1.1  christos 		  /* Note that we've changed the relocation contents, etc.  */
   4337      1.1  christos 		  elf_section_data (sec)->relocs = internal_relocs;
   4338      1.1  christos 		  elf_section_data (sec)->this_hdr.contents = contents;
   4339      1.1  christos 		  symtab_hdr->contents = (unsigned char *) isymbuf;
   4340      1.1  christos 
   4341      1.1  christos 		  /* Fix the opcode.  */
   4342      1.1  christos 		  bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
   4343      1.1  christos 		  bfd_put_8 (abfd, 0xfe, contents + irel->r_offset - 1);
   4344      1.1  christos 
   4345      1.1  christos 		  /* Fix the relocation's type.  */
   4346      1.1  christos 		  irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4347      1.1  christos 					       (ELF32_R_TYPE (irel->r_info)
   4348      1.1  christos 						== (int) R_MN10300_GOT32)
   4349      1.1  christos 					       ? R_MN10300_GOT16
   4350      1.1  christos 					       : (ELF32_R_TYPE (irel->r_info)
   4351      1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4352      1.1  christos 					       ? R_MN10300_GOTOFF16
   4353      1.1  christos 					       : (ELF32_R_TYPE (irel->r_info)
   4354      1.1  christos 						  == (int) R_MN10300_GOTPC32)
   4355      1.1  christos 					       ? R_MN10300_GOTPC16 :
   4356      1.1  christos 					       R_MN10300_16);
   4357      1.1  christos 
   4358      1.1  christos 		  /* Delete two bytes of data.  */
   4359      1.1  christos 		  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4360      1.1  christos 						       irel->r_offset + 2, 2))
   4361      1.1  christos 		    goto error_return;
   4362      1.1  christos 
   4363      1.1  christos 		  /* That will change things, so, we should relax again.
   4364      1.1  christos 		     Note that this is not required, and it may be slow.  */
   4365      1.1  christos 		  *again = TRUE;
   4366      1.1  christos 		  break;
   4367      1.1  christos 		}
   4368      1.1  christos 	    }
   4369      1.1  christos 	}
   4370      1.1  christos     }
   4371      1.1  christos 
   4372      1.1  christos   if (isymbuf != NULL
   4373      1.1  christos       && symtab_hdr->contents != (unsigned char *) isymbuf)
   4374      1.1  christos     {
   4375      1.1  christos       if (! link_info->keep_memory)
   4376      1.1  christos 	free (isymbuf);
   4377      1.1  christos       else
   4378      1.1  christos 	{
   4379      1.1  christos 	  /* Cache the symbols for elf_link_input_bfd.  */
   4380      1.1  christos 	  symtab_hdr->contents = (unsigned char *) isymbuf;
   4381      1.1  christos 	}
   4382      1.1  christos     }
   4383      1.1  christos 
   4384      1.1  christos   if (contents != NULL
   4385      1.1  christos       && elf_section_data (sec)->this_hdr.contents != contents)
   4386      1.1  christos     {
   4387      1.1  christos       if (! link_info->keep_memory)
   4388      1.1  christos 	free (contents);
   4389      1.1  christos       else
   4390      1.1  christos 	{
   4391      1.1  christos 	  /* Cache the section contents for elf_link_input_bfd.  */
   4392      1.1  christos 	  elf_section_data (sec)->this_hdr.contents = contents;
   4393      1.1  christos 	}
   4394      1.1  christos     }
   4395  1.1.1.9  christos 
   4396      1.1  christos   if (elf_section_data (sec)->relocs != internal_relocs)
   4397      1.1  christos     free (internal_relocs);
   4398      1.1  christos 
   4399      1.1  christos   return TRUE;
   4400      1.1  christos 
   4401  1.1.1.9  christos  error_return:
   4402      1.1  christos   if (symtab_hdr->contents != (unsigned char *) isymbuf)
   4403  1.1.1.9  christos     free (isymbuf);
   4404      1.1  christos   if (elf_section_data (section)->this_hdr.contents != contents)
   4405  1.1.1.9  christos     free (contents);
   4406      1.1  christos   if (elf_section_data (section)->relocs != internal_relocs)
   4407      1.1  christos     free (internal_relocs);
   4408      1.1  christos 
   4409      1.1  christos   return FALSE;
   4410      1.1  christos }
   4411      1.1  christos 
   4412      1.1  christos /* This is a version of bfd_generic_get_relocated_section_contents
   4413      1.1  christos    which uses mn10300_elf_relocate_section.  */
   4414      1.1  christos 
   4415      1.1  christos static bfd_byte *
   4416      1.1  christos mn10300_elf_get_relocated_section_contents (bfd *output_bfd,
   4417      1.1  christos 					    struct bfd_link_info *link_info,
   4418      1.1  christos 					    struct bfd_link_order *link_order,
   4419      1.1  christos 					    bfd_byte *data,
   4420      1.1  christos 					    bfd_boolean relocatable,
   4421      1.1  christos 					    asymbol **symbols)
   4422      1.1  christos {
   4423      1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   4424      1.1  christos   asection *input_section = link_order->u.indirect.section;
   4425      1.1  christos   bfd *input_bfd = input_section->owner;
   4426      1.1  christos   asection **sections = NULL;
   4427      1.1  christos   Elf_Internal_Rela *internal_relocs = NULL;
   4428      1.1  christos   Elf_Internal_Sym *isymbuf = NULL;
   4429      1.1  christos 
   4430      1.1  christos   /* We only need to handle the case of relaxing, or of having a
   4431      1.1  christos      particular set of section contents, specially.  */
   4432      1.1  christos   if (relocatable
   4433      1.1  christos       || elf_section_data (input_section)->this_hdr.contents == NULL)
   4434      1.1  christos     return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
   4435      1.1  christos 						       link_order, data,
   4436      1.1  christos 						       relocatable,
   4437      1.1  christos 						       symbols);
   4438      1.1  christos 
   4439      1.1  christos   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   4440      1.1  christos 
   4441      1.1  christos   memcpy (data, elf_section_data (input_section)->this_hdr.contents,
   4442      1.1  christos 	  (size_t) input_section->size);
   4443      1.1  christos 
   4444      1.1  christos   if ((input_section->flags & SEC_RELOC) != 0
   4445      1.1  christos       && input_section->reloc_count > 0)
   4446      1.1  christos     {
   4447      1.1  christos       asection **secpp;
   4448      1.1  christos       Elf_Internal_Sym *isym, *isymend;
   4449      1.1  christos       bfd_size_type amt;
   4450      1.1  christos 
   4451      1.1  christos       internal_relocs = _bfd_elf_link_read_relocs (input_bfd, input_section,
   4452      1.1  christos 						   NULL, NULL, FALSE);
   4453      1.1  christos       if (internal_relocs == NULL)
   4454      1.1  christos 	goto error_return;
   4455      1.1  christos 
   4456      1.1  christos       if (symtab_hdr->sh_info != 0)
   4457      1.1  christos 	{
   4458      1.1  christos 	  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   4459      1.1  christos 	  if (isymbuf == NULL)
   4460      1.1  christos 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
   4461      1.1  christos 					    symtab_hdr->sh_info, 0,
   4462      1.1  christos 					    NULL, NULL, NULL);
   4463      1.1  christos 	  if (isymbuf == NULL)
   4464      1.1  christos 	    goto error_return;
   4465      1.1  christos 	}
   4466      1.1  christos 
   4467      1.1  christos       amt = symtab_hdr->sh_info;
   4468      1.1  christos       amt *= sizeof (asection *);
   4469      1.1  christos       sections = bfd_malloc (amt);
   4470      1.1  christos       if (sections == NULL && amt != 0)
   4471      1.1  christos 	goto error_return;
   4472      1.1  christos 
   4473      1.1  christos       isymend = isymbuf + symtab_hdr->sh_info;
   4474      1.1  christos       for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
   4475      1.1  christos 	{
   4476      1.1  christos 	  asection *isec;
   4477      1.1  christos 
   4478      1.1  christos 	  if (isym->st_shndx == SHN_UNDEF)
   4479      1.1  christos 	    isec = bfd_und_section_ptr;
   4480      1.1  christos 	  else if (isym->st_shndx == SHN_ABS)
   4481      1.1  christos 	    isec = bfd_abs_section_ptr;
   4482      1.1  christos 	  else if (isym->st_shndx == SHN_COMMON)
   4483      1.1  christos 	    isec = bfd_com_section_ptr;
   4484      1.1  christos 	  else
   4485      1.1  christos 	    isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
   4486      1.1  christos 
   4487      1.1  christos 	  *secpp = isec;
   4488      1.1  christos 	}
   4489      1.1  christos 
   4490      1.1  christos       if (! mn10300_elf_relocate_section (output_bfd, link_info, input_bfd,
   4491      1.1  christos 					  input_section, data, internal_relocs,
   4492      1.1  christos 					  isymbuf, sections))
   4493      1.1  christos 	goto error_return;
   4494  1.1.1.9  christos 
   4495  1.1.1.9  christos       free (sections);
   4496      1.1  christos       if (symtab_hdr->contents != (unsigned char *) isymbuf)
   4497      1.1  christos 	free (isymbuf);
   4498      1.1  christos       if (internal_relocs != elf_section_data (input_section)->relocs)
   4499      1.1  christos 	free (internal_relocs);
   4500      1.1  christos     }
   4501      1.1  christos 
   4502      1.1  christos   return data;
   4503      1.1  christos 
   4504  1.1.1.9  christos  error_return:
   4505  1.1.1.9  christos   free (sections);
   4506      1.1  christos   if (symtab_hdr->contents != (unsigned char *) isymbuf)
   4507  1.1.1.9  christos     free (isymbuf);
   4508      1.1  christos   if (internal_relocs != elf_section_data (input_section)->relocs)
   4509      1.1  christos     free (internal_relocs);
   4510      1.1  christos   return NULL;
   4511      1.1  christos }
   4512      1.1  christos 
   4513      1.1  christos /* Assorted hash table functions.  */
   4514      1.1  christos 
   4515      1.1  christos /* Initialize an entry in the link hash table.  */
   4516      1.1  christos 
   4517      1.1  christos /* Create an entry in an MN10300 ELF linker hash table.  */
   4518      1.1  christos 
   4519      1.1  christos static struct bfd_hash_entry *
   4520      1.1  christos elf32_mn10300_link_hash_newfunc (struct bfd_hash_entry *entry,
   4521      1.1  christos 				 struct bfd_hash_table *table,
   4522      1.1  christos 				 const char *string)
   4523      1.1  christos {
   4524      1.1  christos   struct elf32_mn10300_link_hash_entry *ret =
   4525      1.1  christos     (struct elf32_mn10300_link_hash_entry *) entry;
   4526      1.1  christos 
   4527      1.1  christos   /* Allocate the structure if it has not already been allocated by a
   4528      1.1  christos      subclass.  */
   4529      1.1  christos   if (ret == NULL)
   4530      1.1  christos     ret = (struct elf32_mn10300_link_hash_entry *)
   4531      1.1  christos 	   bfd_hash_allocate (table, sizeof (* ret));
   4532      1.1  christos   if (ret == NULL)
   4533      1.1  christos     return (struct bfd_hash_entry *) ret;
   4534      1.1  christos 
   4535      1.1  christos   /* Call the allocation method of the superclass.  */
   4536      1.1  christos   ret = (struct elf32_mn10300_link_hash_entry *)
   4537      1.1  christos 	 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
   4538      1.1  christos 				     table, string);
   4539      1.1  christos   if (ret != NULL)
   4540      1.1  christos     {
   4541      1.1  christos       ret->direct_calls = 0;
   4542      1.1  christos       ret->stack_size = 0;
   4543      1.1  christos       ret->movm_args = 0;
   4544      1.1  christos       ret->movm_stack_size = 0;
   4545      1.1  christos       ret->flags = 0;
   4546  1.1.1.2  christos       ret->value = 0;
   4547      1.1  christos       ret->tls_type = GOT_UNKNOWN;
   4548      1.1  christos     }
   4549      1.1  christos 
   4550      1.1  christos   return (struct bfd_hash_entry *) ret;
   4551      1.1  christos }
   4552  1.1.1.2  christos 
   4553  1.1.1.8  christos static void
   4554  1.1.1.8  christos _bfd_mn10300_copy_indirect_symbol (struct bfd_link_info *	 info,
   4555  1.1.1.8  christos 				   struct elf_link_hash_entry *	 dir,
   4556  1.1.1.2  christos 				   struct elf_link_hash_entry *	 ind)
   4557  1.1.1.2  christos {
   4558  1.1.1.2  christos   struct elf32_mn10300_link_hash_entry * edir;
   4559  1.1.1.2  christos   struct elf32_mn10300_link_hash_entry * eind;
   4560  1.1.1.2  christos 
   4561  1.1.1.2  christos   edir = elf_mn10300_hash_entry (dir);
   4562  1.1.1.2  christos   eind = elf_mn10300_hash_entry (ind);
   4563  1.1.1.2  christos 
   4564  1.1.1.2  christos   if (ind->root.type == bfd_link_hash_indirect
   4565  1.1.1.2  christos       && dir->got.refcount <= 0)
   4566  1.1.1.2  christos     {
   4567  1.1.1.2  christos       edir->tls_type = eind->tls_type;
   4568  1.1.1.2  christos       eind->tls_type = GOT_UNKNOWN;
   4569  1.1.1.2  christos     }
   4570  1.1.1.2  christos   edir->direct_calls = eind->direct_calls;
   4571  1.1.1.2  christos   edir->stack_size = eind->stack_size;
   4572  1.1.1.2  christos   edir->movm_args = eind->movm_args;
   4573  1.1.1.2  christos   edir->movm_stack_size = eind->movm_stack_size;
   4574  1.1.1.2  christos   edir->flags = eind->flags;
   4575  1.1.1.2  christos 
   4576  1.1.1.2  christos   _bfd_elf_link_hash_copy_indirect (info, dir, ind);
   4577  1.1.1.2  christos }
   4578  1.1.1.4  christos 
   4579  1.1.1.4  christos /* Destroy an mn10300 ELF linker hash table.  */
   4580  1.1.1.4  christos 
   4581  1.1.1.4  christos static void
   4582  1.1.1.4  christos elf32_mn10300_link_hash_table_free (bfd *obfd)
   4583  1.1.1.4  christos {
   4584  1.1.1.4  christos   struct elf32_mn10300_link_hash_table *ret
   4585  1.1.1.4  christos     = (struct elf32_mn10300_link_hash_table *) obfd->link.hash;
   4586  1.1.1.4  christos 
   4587  1.1.1.4  christos   obfd->link.hash = &ret->static_hash_table->root.root;
   4588  1.1.1.4  christos   _bfd_elf_link_hash_table_free (obfd);
   4589  1.1.1.4  christos   obfd->is_linker_output = TRUE;
   4590  1.1.1.4  christos   obfd->link.hash = &ret->root.root;
   4591  1.1.1.4  christos   _bfd_elf_link_hash_table_free (obfd);
   4592  1.1.1.4  christos }
   4593      1.1  christos 
   4594      1.1  christos /* Create an mn10300 ELF linker hash table.  */
   4595      1.1  christos 
   4596      1.1  christos static struct bfd_link_hash_table *
   4597      1.1  christos elf32_mn10300_link_hash_table_create (bfd *abfd)
   4598      1.1  christos {
   4599  1.1.1.9  christos   struct elf32_mn10300_link_hash_table *ret;
   4600      1.1  christos   size_t amt = sizeof (* ret);
   4601  1.1.1.2  christos 
   4602      1.1  christos   ret = bfd_zmalloc (amt);
   4603      1.1  christos   if (ret == NULL)
   4604      1.1  christos     return NULL;
   4605      1.1  christos 
   4606  1.1.1.2  christos   amt = sizeof (struct elf_link_hash_table);
   4607      1.1  christos   ret->static_hash_table = bfd_zmalloc (amt);
   4608      1.1  christos   if (ret->static_hash_table == NULL)
   4609      1.1  christos     {
   4610      1.1  christos       free (ret);
   4611      1.1  christos       return NULL;
   4612      1.1  christos     }
   4613      1.1  christos 
   4614      1.1  christos   if (!_bfd_elf_link_hash_table_init (&ret->static_hash_table->root, abfd,
   4615      1.1  christos 				      elf32_mn10300_link_hash_newfunc,
   4616      1.1  christos 				      sizeof (struct elf32_mn10300_link_hash_entry),
   4617      1.1  christos 				      MN10300_ELF_DATA))
   4618      1.1  christos     {
   4619      1.1  christos       free (ret->static_hash_table);
   4620      1.1  christos       free (ret);
   4621      1.1  christos       return NULL;
   4622      1.1  christos     }
   4623  1.1.1.4  christos 
   4624  1.1.1.4  christos   abfd->is_linker_output = FALSE;
   4625  1.1.1.4  christos   abfd->link.hash = NULL;
   4626  1.1.1.4  christos   if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
   4627  1.1.1.4  christos 				      elf32_mn10300_link_hash_newfunc,
   4628  1.1.1.4  christos 				      sizeof (struct elf32_mn10300_link_hash_entry),
   4629  1.1.1.4  christos 				      MN10300_ELF_DATA))
   4630  1.1.1.4  christos     {
   4631  1.1.1.4  christos       abfd->is_linker_output = TRUE;
   4632  1.1.1.4  christos       abfd->link.hash = &ret->static_hash_table->root.root;
   4633  1.1.1.4  christos       _bfd_elf_link_hash_table_free (abfd);
   4634  1.1.1.4  christos       free (ret);
   4635  1.1.1.4  christos       return NULL;
   4636  1.1.1.4  christos     }
   4637      1.1  christos   ret->root.root.hash_table_free = elf32_mn10300_link_hash_table_free;
   4638  1.1.1.4  christos 
   4639      1.1  christos   ret->tls_ldm_got.offset = -1;
   4640  1.1.1.4  christos 
   4641      1.1  christos   return & ret->root.root;
   4642      1.1  christos }
   4643      1.1  christos 
   4644      1.1  christos static unsigned long
   4645      1.1  christos elf_mn10300_mach (flagword flags)
   4646      1.1  christos {
   4647      1.1  christos   switch (flags & EF_MN10300_MACH)
   4648      1.1  christos     {
   4649      1.1  christos     case E_MN10300_MACH_MN10300:
   4650      1.1  christos     default:
   4651      1.1  christos       return bfd_mach_mn10300;
   4652      1.1  christos 
   4653      1.1  christos     case E_MN10300_MACH_AM33:
   4654      1.1  christos       return bfd_mach_am33;
   4655      1.1  christos 
   4656      1.1  christos     case E_MN10300_MACH_AM33_2:
   4657      1.1  christos       return bfd_mach_am33_2;
   4658      1.1  christos     }
   4659      1.1  christos }
   4660      1.1  christos 
   4661      1.1  christos /* The final processing done just before writing out a MN10300 ELF object
   4662      1.1  christos    file.  This gets the MN10300 architecture right based on the machine
   4663      1.1  christos    number.  */
   4664  1.1.1.9  christos 
   4665  1.1.1.9  christos static bfd_boolean
   4666      1.1  christos _bfd_mn10300_elf_final_write_processing (bfd *abfd)
   4667      1.1  christos {
   4668      1.1  christos   unsigned long val;
   4669      1.1  christos 
   4670      1.1  christos   switch (bfd_get_mach (abfd))
   4671      1.1  christos     {
   4672      1.1  christos     default:
   4673      1.1  christos     case bfd_mach_mn10300:
   4674      1.1  christos       val = E_MN10300_MACH_MN10300;
   4675      1.1  christos       break;
   4676      1.1  christos 
   4677      1.1  christos     case bfd_mach_am33:
   4678      1.1  christos       val = E_MN10300_MACH_AM33;
   4679      1.1  christos       break;
   4680      1.1  christos 
   4681      1.1  christos     case bfd_mach_am33_2:
   4682      1.1  christos       val = E_MN10300_MACH_AM33_2;
   4683      1.1  christos       break;
   4684      1.1  christos     }
   4685      1.1  christos 
   4686      1.1  christos   elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH);
   4687  1.1.1.9  christos   elf_elfheader (abfd)->e_flags |= val;
   4688      1.1  christos   return _bfd_elf_final_write_processing (abfd);
   4689      1.1  christos }
   4690      1.1  christos 
   4691      1.1  christos static bfd_boolean
   4692      1.1  christos _bfd_mn10300_elf_object_p (bfd *abfd)
   4693      1.1  christos {
   4694      1.1  christos   bfd_default_set_arch_mach (abfd, bfd_arch_mn10300,
   4695      1.1  christos 			     elf_mn10300_mach (elf_elfheader (abfd)->e_flags));
   4696      1.1  christos   return TRUE;
   4697      1.1  christos }
   4698      1.1  christos 
   4699      1.1  christos /* Merge backend specific data from an object file to the output
   4700      1.1  christos    object file when linking.  */
   4701      1.1  christos 
   4702  1.1.1.7  christos static bfd_boolean
   4703      1.1  christos _bfd_mn10300_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   4704  1.1.1.7  christos {
   4705  1.1.1.7  christos   bfd *obfd = info->output_bfd;
   4706      1.1  christos 
   4707      1.1  christos   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
   4708      1.1  christos       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
   4709      1.1  christos     return TRUE;
   4710      1.1  christos 
   4711      1.1  christos   if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
   4712      1.1  christos       && bfd_get_mach (obfd) < bfd_get_mach (ibfd))
   4713      1.1  christos     {
   4714      1.1  christos       if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
   4715      1.1  christos 			       bfd_get_mach (ibfd)))
   4716      1.1  christos 	return FALSE;
   4717      1.1  christos     }
   4718      1.1  christos 
   4719      1.1  christos   return TRUE;
   4720      1.1  christos }
   4721      1.1  christos 
   4722      1.1  christos #define PLT0_ENTRY_SIZE     15
   4723      1.1  christos #define PLT_ENTRY_SIZE      20
   4724      1.1  christos #define PIC_PLT_ENTRY_SIZE  24
   4725      1.1  christos 
   4726      1.1  christos static const bfd_byte elf_mn10300_plt0_entry[PLT0_ENTRY_SIZE] =
   4727      1.1  christos {
   4728      1.1  christos   0xfc, 0xa0, 0, 0, 0, 0,	/* mov	(.got+8),a0 */
   4729      1.1  christos   0xfe, 0xe, 0x10, 0, 0, 0, 0,	/* mov	(.got+4),r1 */
   4730      1.1  christos   0xf0, 0xf4,			/* jmp	(a0) */
   4731      1.1  christos };
   4732      1.1  christos 
   4733      1.1  christos static const bfd_byte elf_mn10300_plt_entry[PLT_ENTRY_SIZE] =
   4734      1.1  christos {
   4735      1.1  christos   0xfc, 0xa0, 0, 0, 0, 0,	/* mov	(nameN@GOT + .got),a0 */
   4736      1.1  christos   0xf0, 0xf4,			/* jmp	(a0) */
   4737      1.1  christos   0xfe, 8, 0, 0, 0, 0, 0,	/* mov	reloc-table-address,r0 */
   4738      1.1  christos   0xdc, 0, 0, 0, 0,		/* jmp	.plt0 */
   4739      1.1  christos };
   4740      1.1  christos 
   4741      1.1  christos static const bfd_byte elf_mn10300_pic_plt_entry[PIC_PLT_ENTRY_SIZE] =
   4742      1.1  christos {
   4743      1.1  christos   0xfc, 0x22, 0, 0, 0, 0,	/* mov	(nameN@GOT,a2),a0 */
   4744      1.1  christos   0xf0, 0xf4,			/* jmp	(a0) */
   4745      1.1  christos   0xfe, 8, 0, 0, 0, 0, 0,	/* mov	reloc-table-address,r0 */
   4746      1.1  christos   0xf8, 0x22, 8,		/* mov	(8,a2),a0 */
   4747      1.1  christos   0xfb, 0xa, 0x1a, 4,		/* mov	(4,a2),r1 */
   4748      1.1  christos   0xf0, 0xf4,			/* jmp	(a0) */
   4749      1.1  christos };
   4750      1.1  christos 
   4751      1.1  christos /* Return size of the first PLT entry.  */
   4752  1.1.1.6  christos #define elf_mn10300_sizeof_plt0(info) \
   4753      1.1  christos   (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE)
   4754      1.1  christos 
   4755      1.1  christos /* Return size of a PLT entry.  */
   4756  1.1.1.6  christos #define elf_mn10300_sizeof_plt(info) \
   4757      1.1  christos   (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE)
   4758      1.1  christos 
   4759      1.1  christos /* Return offset of the PLT0 address in an absolute PLT entry.  */
   4760      1.1  christos #define elf_mn10300_plt_plt0_offset(info) 16
   4761      1.1  christos 
   4762      1.1  christos /* Return offset of the linker in PLT0 entry.  */
   4763      1.1  christos #define elf_mn10300_plt0_linker_offset(info) 2
   4764      1.1  christos 
   4765      1.1  christos /* Return offset of the GOT id in PLT0 entry.  */
   4766      1.1  christos #define elf_mn10300_plt0_gotid_offset(info) 9
   4767      1.1  christos 
   4768      1.1  christos /* Return offset of the temporary in PLT entry.  */
   4769      1.1  christos #define elf_mn10300_plt_temp_offset(info) 8
   4770      1.1  christos 
   4771      1.1  christos /* Return offset of the symbol in PLT entry.  */
   4772      1.1  christos #define elf_mn10300_plt_symbol_offset(info) 2
   4773      1.1  christos 
   4774      1.1  christos /* Return offset of the relocation in PLT entry.  */
   4775      1.1  christos #define elf_mn10300_plt_reloc_offset(info) 11
   4776      1.1  christos 
   4777      1.1  christos /* The name of the dynamic interpreter.  This is put in the .interp
   4778      1.1  christos    section.  */
   4779      1.1  christos 
   4780      1.1  christos #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
   4781      1.1  christos 
   4782      1.1  christos /* Create dynamic sections when linking against a dynamic object.  */
   4783      1.1  christos 
   4784      1.1  christos static bfd_boolean
   4785      1.1  christos _bfd_mn10300_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   4786      1.1  christos {
   4787      1.1  christos   flagword   flags;
   4788      1.1  christos   asection * s;
   4789  1.1.1.2  christos   const struct elf_backend_data * bed = get_elf_backend_data (abfd);
   4790      1.1  christos   struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   4791      1.1  christos   int ptralign = 0;
   4792      1.1  christos 
   4793      1.1  christos   switch (bed->s->arch_size)
   4794      1.1  christos     {
   4795      1.1  christos     case 32:
   4796      1.1  christos       ptralign = 2;
   4797      1.1  christos       break;
   4798      1.1  christos 
   4799      1.1  christos     case 64:
   4800      1.1  christos       ptralign = 3;
   4801      1.1  christos       break;
   4802      1.1  christos 
   4803      1.1  christos     default:
   4804      1.1  christos       bfd_set_error (bfd_error_bad_value);
   4805      1.1  christos       return FALSE;
   4806      1.1  christos     }
   4807      1.1  christos 
   4808      1.1  christos   /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
   4809      1.1  christos      .rel[a].bss sections.  */
   4810      1.1  christos   flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
   4811      1.1  christos 	   | SEC_LINKER_CREATED);
   4812  1.1.1.2  christos 
   4813  1.1.1.2  christos   s = bfd_make_section_anyway_with_flags (abfd,
   4814  1.1.1.2  christos 					  (bed->default_use_rela_p
   4815  1.1.1.2  christos 					   ? ".rela.plt" : ".rel.plt"),
   4816  1.1.1.2  christos 					  flags | SEC_READONLY);
   4817      1.1  christos   htab->root.srelplt = s;
   4818  1.1.1.9  christos   if (s == NULL
   4819      1.1  christos       || !bfd_set_section_alignment (s, ptralign))
   4820      1.1  christos     return FALSE;
   4821      1.1  christos 
   4822      1.1  christos   if (! _bfd_mn10300_elf_create_got_section (abfd, info))
   4823      1.1  christos     return FALSE;
   4824      1.1  christos 
   4825      1.1  christos   if (bed->want_dynbss)
   4826      1.1  christos     {
   4827      1.1  christos       /* The .dynbss section is a place to put symbols which are defined
   4828      1.1  christos 	 by dynamic objects, are referenced by regular objects, and are
   4829      1.1  christos 	 not functions.  We must allocate space for them in the process
   4830      1.1  christos 	 image and use a R_*_COPY reloc to tell the dynamic linker to
   4831      1.1  christos 	 initialize them at run time.  The linker script puts the .dynbss
   4832  1.1.1.2  christos 	 section into the .bss section of the final image.  */
   4833  1.1.1.2  christos       s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
   4834      1.1  christos 					      SEC_ALLOC | SEC_LINKER_CREATED);
   4835      1.1  christos       if (s == NULL)
   4836      1.1  christos 	return FALSE;
   4837      1.1  christos 
   4838      1.1  christos       /* The .rel[a].bss section holds copy relocs.  This section is not
   4839      1.1  christos 	 normally needed.  We need to create it here, though, so that the
   4840      1.1  christos 	 linker will map it to an output section.  We can't just create it
   4841      1.1  christos 	 only if we need it, because we will not know whether we need it
   4842      1.1  christos 	 until we have seen all the input files, and the first time the
   4843      1.1  christos 	 main linker code calls BFD after examining all the input files
   4844      1.1  christos 	 (size_dynamic_sections) the input sections have already been
   4845      1.1  christos 	 mapped to the output sections.  If the section turns out not to
   4846      1.1  christos 	 be needed, we can discard it later.  We will never need this
   4847      1.1  christos 	 section when generating a shared object, since they do not use
   4848  1.1.1.6  christos 	 copy relocs.  */
   4849      1.1  christos       if (! bfd_link_pic (info))
   4850  1.1.1.2  christos 	{
   4851  1.1.1.2  christos 	  s = bfd_make_section_anyway_with_flags (abfd,
   4852  1.1.1.2  christos 						  (bed->default_use_rela_p
   4853  1.1.1.2  christos 						   ? ".rela.bss" : ".rel.bss"),
   4854      1.1  christos 						  flags | SEC_READONLY);
   4855  1.1.1.9  christos 	  if (s == NULL
   4856      1.1  christos 	      || !bfd_set_section_alignment (s, ptralign))
   4857      1.1  christos 	    return FALSE;
   4858      1.1  christos 	}
   4859      1.1  christos     }
   4860      1.1  christos 
   4861      1.1  christos   return TRUE;
   4862      1.1  christos }
   4863      1.1  christos 
   4864      1.1  christos /* Adjust a symbol defined by a dynamic object and referenced by a
   4866      1.1  christos    regular object.  The current definition is in some section of the
   4867      1.1  christos    dynamic object, but we're not including those sections.  We have to
   4868      1.1  christos    change the definition to something the rest of the link can
   4869      1.1  christos    understand.  */
   4870      1.1  christos 
   4871      1.1  christos static bfd_boolean
   4872      1.1  christos _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
   4873  1.1.1.2  christos 					struct elf_link_hash_entry * h)
   4874      1.1  christos {
   4875      1.1  christos   struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   4876      1.1  christos   bfd * dynobj;
   4877  1.1.1.2  christos   asection * s;
   4878      1.1  christos 
   4879      1.1  christos   dynobj = htab->root.dynobj;
   4880      1.1  christos 
   4881      1.1  christos   /* Make sure we know what is going on here.  */
   4882  1.1.1.8  christos   BFD_ASSERT (dynobj != NULL
   4883      1.1  christos 	      && (h->needs_plt
   4884      1.1  christos 		  || h->is_weakalias
   4885      1.1  christos 		  || (h->def_dynamic
   4886      1.1  christos 		      && h->ref_regular
   4887      1.1  christos 		      && !h->def_regular)));
   4888      1.1  christos 
   4889      1.1  christos   /* If this is a function, put it in the procedure linkage table.  We
   4890      1.1  christos      will fill in the contents of the procedure linkage table later,
   4891      1.1  christos      when we know the address of the .got section.  */
   4892      1.1  christos   if (h->type == STT_FUNC
   4893  1.1.1.6  christos       || h->needs_plt)
   4894      1.1  christos     {
   4895      1.1  christos       if (! bfd_link_pic (info)
   4896      1.1  christos 	  && !h->def_dynamic
   4897      1.1  christos 	  && !h->ref_dynamic)
   4898      1.1  christos 	{
   4899      1.1  christos 	  /* This case can occur if we saw a PLT reloc in an input
   4900      1.1  christos 	     file, but the symbol was never referred to by a dynamic
   4901      1.1  christos 	     object.  In such a case, we don't actually need to build
   4902      1.1  christos 	     a procedure linkage table, and we can just do a REL32
   4903      1.1  christos 	     reloc instead.  */
   4904      1.1  christos 	  BFD_ASSERT (h->needs_plt);
   4905      1.1  christos 	  return TRUE;
   4906      1.1  christos 	}
   4907      1.1  christos 
   4908      1.1  christos       /* Make sure this symbol is output as a dynamic symbol.  */
   4909      1.1  christos       if (h->dynindx == -1)
   4910      1.1  christos 	{
   4911      1.1  christos 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   4912      1.1  christos 	    return FALSE;
   4913  1.1.1.2  christos 	}
   4914      1.1  christos 
   4915      1.1  christos       s = htab->root.splt;
   4916      1.1  christos       BFD_ASSERT (s != NULL);
   4917      1.1  christos 
   4918      1.1  christos       /* If this is the first .plt entry, make room for the special
   4919      1.1  christos 	 first entry.  */
   4920      1.1  christos       if (s->size == 0)
   4921      1.1  christos 	s->size += elf_mn10300_sizeof_plt0 (info);
   4922      1.1  christos 
   4923      1.1  christos       /* If this symbol is not defined in a regular file, and we are
   4924      1.1  christos 	 not generating a shared library, then set the symbol to this
   4925      1.1  christos 	 location in the .plt.  This is required to make function
   4926  1.1.1.6  christos 	 pointers compare as equal between the normal executable and
   4927      1.1  christos 	 the shared library.  */
   4928      1.1  christos       if (! bfd_link_pic (info)
   4929      1.1  christos 	  && !h->def_regular)
   4930      1.1  christos 	{
   4931      1.1  christos 	  h->root.u.def.section = s;
   4932      1.1  christos 	  h->root.u.def.value = s->size;
   4933      1.1  christos 	}
   4934      1.1  christos 
   4935      1.1  christos       h->plt.offset = s->size;
   4936      1.1  christos 
   4937      1.1  christos       /* Make room for this entry.  */
   4938      1.1  christos       s->size += elf_mn10300_sizeof_plt (info);
   4939      1.1  christos 
   4940  1.1.1.2  christos       /* We also need to make an entry in the .got.plt section, which
   4941      1.1  christos 	 will be placed in the .got section by the linker script.  */
   4942      1.1  christos       s = htab->root.sgotplt;
   4943      1.1  christos       BFD_ASSERT (s != NULL);
   4944      1.1  christos       s->size += 4;
   4945  1.1.1.7  christos 
   4946      1.1  christos       /* We also need to make an entry in the .rela.plt section.  */
   4947      1.1  christos       s = htab->root.srelplt;
   4948      1.1  christos       BFD_ASSERT (s != NULL);
   4949      1.1  christos       s->size += sizeof (Elf32_External_Rela);
   4950      1.1  christos 
   4951      1.1  christos       return TRUE;
   4952      1.1  christos     }
   4953      1.1  christos 
   4954      1.1  christos   /* If this is a weak symbol, and there is a real definition, the
   4955  1.1.1.8  christos      processor independent code will have arranged for us to see the
   4956      1.1  christos      real definition first, and we can just use the same value.  */
   4957  1.1.1.8  christos   if (h->is_weakalias)
   4958  1.1.1.8  christos     {
   4959  1.1.1.8  christos       struct elf_link_hash_entry *def = weakdef (h);
   4960  1.1.1.8  christos       BFD_ASSERT (def->root.type == bfd_link_hash_defined);
   4961      1.1  christos       h->root.u.def.section = def->root.u.def.section;
   4962      1.1  christos       h->root.u.def.value = def->root.u.def.value;
   4963      1.1  christos       return TRUE;
   4964      1.1  christos     }
   4965      1.1  christos 
   4966      1.1  christos   /* This is a reference to a symbol defined by a dynamic object which
   4967      1.1  christos      is not a function.  */
   4968      1.1  christos 
   4969      1.1  christos   /* If we are creating a shared library, we must presume that the
   4970      1.1  christos      only references to the symbol are via the global offset table.
   4971  1.1.1.6  christos      For such cases we need not do anything here; the relocations will
   4972      1.1  christos      be handled correctly by relocate_section.  */
   4973      1.1  christos   if (bfd_link_pic (info))
   4974      1.1  christos     return TRUE;
   4975      1.1  christos 
   4976      1.1  christos   /* If there are no references to this symbol that do not use the
   4977      1.1  christos      GOT, we don't need to generate a copy reloc.  */
   4978      1.1  christos   if (!h->non_got_ref)
   4979      1.1  christos     return TRUE;
   4980      1.1  christos 
   4981      1.1  christos   /* We must allocate the symbol in our .dynbss section, which will
   4982      1.1  christos      become part of the .bss section of the executable.  There will be
   4983      1.1  christos      an entry for this symbol in the .dynsym section.  The dynamic
   4984      1.1  christos      object will contain position independent code, so all references
   4985      1.1  christos      from the dynamic object to this symbol will go through the global
   4986      1.1  christos      offset table.  The dynamic linker will use the .dynsym entry to
   4987      1.1  christos      determine the address it must put in the global offset table, so
   4988      1.1  christos      both the dynamic object and the regular object will refer to the
   4989  1.1.1.2  christos      same memory location for the variable.  */
   4990      1.1  christos 
   4991      1.1  christos   s = bfd_get_linker_section (dynobj, ".dynbss");
   4992      1.1  christos   BFD_ASSERT (s != NULL);
   4993      1.1  christos 
   4994      1.1  christos   /* We must generate a R_MN10300_COPY reloc to tell the dynamic linker to
   4995      1.1  christos      copy the initial value out of the dynamic object and into the
   4996  1.1.1.2  christos      runtime process image.  We need to remember the offset into the
   4997      1.1  christos      .rela.bss section we are going to use.  */
   4998      1.1  christos   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
   4999      1.1  christos     {
   5000  1.1.1.2  christos       asection * srel;
   5001      1.1  christos 
   5002      1.1  christos       srel = bfd_get_linker_section (dynobj, ".rela.bss");
   5003      1.1  christos       BFD_ASSERT (srel != NULL);
   5004      1.1  christos       srel->size += sizeof (Elf32_External_Rela);
   5005      1.1  christos       h->needs_copy = 1;
   5006  1.1.1.4  christos     }
   5007      1.1  christos 
   5008      1.1  christos   return _bfd_elf_adjust_dynamic_copy (info, h, s);
   5009      1.1  christos }
   5010      1.1  christos 
   5011      1.1  christos /* Set the sizes of the dynamic sections.  */
   5012      1.1  christos 
   5013      1.1  christos static bfd_boolean
   5014      1.1  christos _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
   5015  1.1.1.2  christos 					struct bfd_link_info * info)
   5016      1.1  christos {
   5017      1.1  christos   struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   5018      1.1  christos   bfd * dynobj;
   5019      1.1  christos   asection * s;
   5020  1.1.1.2  christos   bfd_boolean relocs;
   5021      1.1  christos 
   5022      1.1  christos   dynobj = htab->root.dynobj;
   5023      1.1  christos   BFD_ASSERT (dynobj != NULL);
   5024      1.1  christos 
   5025      1.1  christos   if (elf_hash_table (info)->dynamic_sections_created)
   5026  1.1.1.7  christos     {
   5027      1.1  christos       /* Set the contents of the .interp section to the interpreter.  */
   5028  1.1.1.2  christos       if (bfd_link_executable (info) && !info->nointerp)
   5029      1.1  christos 	{
   5030      1.1  christos 	  s = bfd_get_linker_section (dynobj, ".interp");
   5031      1.1  christos 	  BFD_ASSERT (s != NULL);
   5032      1.1  christos 	  s->size = sizeof ELF_DYNAMIC_INTERPRETER;
   5033      1.1  christos 	  s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
   5034      1.1  christos 	}
   5035      1.1  christos     }
   5036      1.1  christos   else
   5037      1.1  christos     {
   5038      1.1  christos       /* We may have created entries in the .rela.got section.
   5039      1.1  christos 	 However, if we are not creating the dynamic sections, we will
   5040      1.1  christos 	 not actually use these entries.  Reset the size of .rela.got,
   5041  1.1.1.2  christos 	 which will cause it to get stripped from the output file
   5042      1.1  christos 	 below.  */
   5043      1.1  christos       s = htab->root.sgot;
   5044      1.1  christos       if (s != NULL)
   5045      1.1  christos 	s->size = 0;
   5046  1.1.1.2  christos     }
   5047  1.1.1.2  christos 
   5048  1.1.1.7  christos   if (htab->tls_ldm_got.refcount > 0)
   5049  1.1.1.2  christos     {
   5050  1.1.1.2  christos       s = htab->root.srelgot;
   5051  1.1.1.2  christos       BFD_ASSERT (s != NULL);
   5052  1.1.1.2  christos       s->size += sizeof (Elf32_External_Rela);
   5053      1.1  christos     }
   5054      1.1  christos 
   5055      1.1  christos   /* The check_relocs and adjust_dynamic_symbol entry points have
   5056      1.1  christos      determined the sizes of the various dynamic sections.  Allocate
   5057      1.1  christos      memory for them.  */
   5058      1.1  christos   relocs = FALSE;
   5059      1.1  christos   for (s = dynobj->sections; s != NULL; s = s->next)
   5060      1.1  christos     {
   5061      1.1  christos       const char * name;
   5062      1.1  christos 
   5063      1.1  christos       if ((s->flags & SEC_LINKER_CREATED) == 0)
   5064      1.1  christos 	continue;
   5065      1.1  christos 
   5066  1.1.1.9  christos       /* It's OK to base decisions on the section name, because none
   5067      1.1  christos 	 of the dynobj section names depend upon the input files.  */
   5068      1.1  christos       name = bfd_section_name (s);
   5069      1.1  christos 
   5070      1.1  christos       if (streq (name, ".plt"))
   5071  1.1.1.9  christos 	{
   5072      1.1  christos 	  /* Remember whether there is a PLT.  */
   5073      1.1  christos 	  ;
   5074      1.1  christos 	}
   5075      1.1  christos       else if (CONST_STRNEQ (name, ".rela"))
   5076      1.1  christos 	{
   5077      1.1  christos 	  if (s->size != 0)
   5078      1.1  christos 	    {
   5079      1.1  christos 	      /* Remember whether there are any reloc sections other
   5080  1.1.1.9  christos 		 than .rela.plt.  */
   5081      1.1  christos 	      if (! streq (name, ".rela.plt"))
   5082      1.1  christos 		relocs = TRUE;
   5083      1.1  christos 
   5084      1.1  christos 	      /* We use the reloc_count field as a counter if we need
   5085      1.1  christos 		 to copy relocs into the output file.  */
   5086      1.1  christos 	      s->reloc_count = 0;
   5087      1.1  christos 	    }
   5088      1.1  christos 	}
   5089      1.1  christos       else if (! CONST_STRNEQ (name, ".got")
   5090      1.1  christos 	       && ! streq (name, ".dynbss"))
   5091      1.1  christos 	/* It's not one of our sections, so don't allocate space.  */
   5092      1.1  christos 	continue;
   5093      1.1  christos 
   5094      1.1  christos       if (s->size == 0)
   5095      1.1  christos 	{
   5096      1.1  christos 	  /* If we don't need this section, strip it from the
   5097      1.1  christos 	     output file.  This is mostly to handle .rela.bss and
   5098      1.1  christos 	     .rela.plt.  We must create both sections in
   5099      1.1  christos 	     create_dynamic_sections, because they must be created
   5100      1.1  christos 	     before the linker maps input sections to output
   5101      1.1  christos 	     sections.  The linker does that before
   5102      1.1  christos 	     adjust_dynamic_symbol is called, and it is that
   5103      1.1  christos 	     function which decides whether anything needs to go
   5104      1.1  christos 	     into these sections.  */
   5105      1.1  christos 	  s->flags |= SEC_EXCLUDE;
   5106      1.1  christos 	  continue;
   5107      1.1  christos 	}
   5108      1.1  christos 
   5109      1.1  christos 	if ((s->flags & SEC_HAS_CONTENTS) == 0)
   5110      1.1  christos 	  continue;
   5111      1.1  christos 
   5112      1.1  christos       /* Allocate memory for the section contents.  We use bfd_zalloc
   5113      1.1  christos 	 here in case unused entries are not reclaimed before the
   5114      1.1  christos 	 section's contents are written out.  This should not happen,
   5115      1.1  christos 	 but this way if it does, we get a R_MN10300_NONE reloc
   5116      1.1  christos 	 instead of garbage.  */
   5117      1.1  christos       s->contents = bfd_zalloc (dynobj, s->size);
   5118      1.1  christos       if (s->contents == NULL)
   5119      1.1  christos 	return FALSE;
   5120  1.1.1.9  christos     }
   5121      1.1  christos 
   5122      1.1  christos   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
   5123      1.1  christos }
   5124      1.1  christos 
   5125      1.1  christos /* Finish up dynamic symbol handling.  We set the contents of various
   5126      1.1  christos    dynamic sections here.  */
   5127      1.1  christos 
   5128      1.1  christos static bfd_boolean
   5129      1.1  christos _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
   5130      1.1  christos 					struct bfd_link_info * info,
   5131      1.1  christos 					struct elf_link_hash_entry * h,
   5132  1.1.1.2  christos 					Elf_Internal_Sym * sym)
   5133      1.1  christos {
   5134      1.1  christos   struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   5135  1.1.1.2  christos   bfd * dynobj;
   5136      1.1  christos 
   5137      1.1  christos   dynobj = htab->root.dynobj;
   5138      1.1  christos 
   5139  1.1.1.8  christos   if (h->plt.offset != (bfd_vma) -1)
   5140  1.1.1.8  christos     {
   5141  1.1.1.8  christos       asection *	splt;
   5142  1.1.1.8  christos       asection *	sgot;
   5143  1.1.1.8  christos       asection *	srel;
   5144      1.1  christos       bfd_vma		plt_index;
   5145      1.1  christos       bfd_vma		got_offset;
   5146      1.1  christos       Elf_Internal_Rela rel;
   5147      1.1  christos 
   5148      1.1  christos       /* This symbol has an entry in the procedure linkage table.  Set
   5149      1.1  christos 	 it up.  */
   5150      1.1  christos 
   5151  1.1.1.2  christos       BFD_ASSERT (h->dynindx != -1);
   5152  1.1.1.2  christos 
   5153  1.1.1.7  christos       splt = htab->root.splt;
   5154      1.1  christos       sgot = htab->root.sgotplt;
   5155      1.1  christos       srel = htab->root.srelplt;
   5156      1.1  christos       BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
   5157      1.1  christos 
   5158      1.1  christos       /* Get the index in the procedure linkage table which
   5159      1.1  christos 	 corresponds to this symbol.  This is the index of this symbol
   5160      1.1  christos 	 in all the symbols for which we are making plt entries.  The
   5161      1.1  christos 	 first entry in the procedure linkage table is reserved.  */
   5162      1.1  christos       plt_index = ((h->plt.offset - elf_mn10300_sizeof_plt0 (info))
   5163      1.1  christos 		   / elf_mn10300_sizeof_plt (info));
   5164      1.1  christos 
   5165      1.1  christos       /* Get the offset into the .got table of the entry that
   5166      1.1  christos 	 corresponds to this function.  Each .got entry is 4 bytes.
   5167      1.1  christos 	 The first three are reserved.  */
   5168      1.1  christos       got_offset = (plt_index + 3) * 4;
   5169  1.1.1.6  christos 
   5170      1.1  christos       /* Fill in the entry in the procedure linkage table.  */
   5171      1.1  christos       if (! bfd_link_pic (info))
   5172      1.1  christos 	{
   5173      1.1  christos 	  memcpy (splt->contents + h->plt.offset, elf_mn10300_plt_entry,
   5174      1.1  christos 		  elf_mn10300_sizeof_plt (info));
   5175      1.1  christos 	  bfd_put_32 (output_bfd,
   5176      1.1  christos 		      (sgot->output_section->vma
   5177      1.1  christos 		       + sgot->output_offset
   5178      1.1  christos 		       + got_offset),
   5179      1.1  christos 		      (splt->contents + h->plt.offset
   5180      1.1  christos 		       + elf_mn10300_plt_symbol_offset (info)));
   5181      1.1  christos 
   5182      1.1  christos 	  bfd_put_32 (output_bfd,
   5183      1.1  christos 		      (1 - h->plt.offset - elf_mn10300_plt_plt0_offset (info)),
   5184      1.1  christos 		      (splt->contents + h->plt.offset
   5185      1.1  christos 		       + elf_mn10300_plt_plt0_offset (info)));
   5186      1.1  christos 	}
   5187      1.1  christos       else
   5188      1.1  christos 	{
   5189      1.1  christos 	  memcpy (splt->contents + h->plt.offset, elf_mn10300_pic_plt_entry,
   5190      1.1  christos 		  elf_mn10300_sizeof_plt (info));
   5191      1.1  christos 
   5192      1.1  christos 	  bfd_put_32 (output_bfd, got_offset,
   5193      1.1  christos 		      (splt->contents + h->plt.offset
   5194      1.1  christos 		       + elf_mn10300_plt_symbol_offset (info)));
   5195      1.1  christos 	}
   5196      1.1  christos 
   5197      1.1  christos       bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
   5198      1.1  christos 		  (splt->contents + h->plt.offset
   5199      1.1  christos 		   + elf_mn10300_plt_reloc_offset (info)));
   5200      1.1  christos 
   5201      1.1  christos       /* Fill in the entry in the global offset table.  */
   5202      1.1  christos       bfd_put_32 (output_bfd,
   5203      1.1  christos 		  (splt->output_section->vma
   5204      1.1  christos 		   + splt->output_offset
   5205      1.1  christos 		   + h->plt.offset
   5206      1.1  christos 		   + elf_mn10300_plt_temp_offset (info)),
   5207      1.1  christos 		  sgot->contents + got_offset);
   5208      1.1  christos 
   5209      1.1  christos       /* Fill in the entry in the .rela.plt section.  */
   5210      1.1  christos       rel.r_offset = (sgot->output_section->vma
   5211      1.1  christos 		      + sgot->output_offset
   5212      1.1  christos 		      + got_offset);
   5213      1.1  christos       rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_JMP_SLOT);
   5214      1.1  christos       rel.r_addend = 0;
   5215      1.1  christos       bfd_elf32_swap_reloca_out (output_bfd, &rel,
   5216      1.1  christos 				 (bfd_byte *) ((Elf32_External_Rela *) srel->contents
   5217      1.1  christos 					       + plt_index));
   5218      1.1  christos 
   5219      1.1  christos       if (!h->def_regular)
   5220      1.1  christos 	/* Mark the symbol as undefined, rather than as defined in
   5221      1.1  christos 	   the .plt section.  Leave the value alone.  */
   5222      1.1  christos 	sym->st_shndx = SHN_UNDEF;
   5223      1.1  christos     }
   5224      1.1  christos 
   5225  1.1.1.8  christos   if (h->got.offset != (bfd_vma) -1)
   5226  1.1.1.8  christos     {
   5227      1.1  christos       asection *	sgot;
   5228      1.1  christos       asection *	srel;
   5229      1.1  christos       Elf_Internal_Rela rel;
   5230  1.1.1.2  christos 
   5231  1.1.1.7  christos       /* This symbol has an entry in the global offset table.  Set it up.  */
   5232      1.1  christos       sgot = htab->root.sgot;
   5233      1.1  christos       srel = htab->root.srelgot;
   5234      1.1  christos       BFD_ASSERT (sgot != NULL && srel != NULL);
   5235      1.1  christos 
   5236      1.1  christos       rel.r_offset = (sgot->output_section->vma
   5237      1.1  christos 		      + sgot->output_offset
   5238  1.1.1.2  christos 		      + (h->got.offset & ~1));
   5239      1.1  christos 
   5240  1.1.1.2  christos       switch (elf_mn10300_hash_entry (h)->tls_type)
   5241      1.1  christos 	{
   5242  1.1.1.2  christos 	case GOT_TLS_GD:
   5243  1.1.1.2  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
   5244  1.1.1.2  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset + 4);
   5245  1.1.1.2  christos 	  rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_DTPMOD);
   5246  1.1.1.2  christos 	  rel.r_addend = 0;
   5247  1.1.1.2  christos 	  bfd_elf32_swap_reloca_out (output_bfd, & rel,
   5248  1.1.1.2  christos 				     (bfd_byte *) ((Elf32_External_Rela *) srel->contents
   5249  1.1.1.2  christos 						   + srel->reloc_count));
   5250  1.1.1.2  christos 	  ++ srel->reloc_count;
   5251      1.1  christos 	  rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_DTPOFF);
   5252  1.1.1.2  christos 	  rel.r_offset += 4;
   5253  1.1.1.2  christos 	  rel.r_addend = 0;
   5254  1.1.1.2  christos 	  break;
   5255  1.1.1.2  christos 
   5256  1.1.1.2  christos 	case GOT_TLS_IE:
   5257  1.1.1.2  christos 	  /* We originally stored the addend in the GOT, but at this
   5258  1.1.1.2  christos 	     point, we want to move it to the reloc instead as that's
   5259  1.1.1.2  christos 	     where the dynamic linker wants it.  */
   5260  1.1.1.2  christos 	  rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + h->got.offset);
   5261  1.1.1.2  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
   5262  1.1.1.2  christos 	  if (h->dynindx == -1)
   5263  1.1.1.2  christos 	    rel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_TPOFF);
   5264  1.1.1.2  christos 	  else
   5265  1.1.1.2  christos 	    rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_TPOFF);
   5266  1.1.1.2  christos 	  break;
   5267  1.1.1.2  christos 
   5268  1.1.1.2  christos 	default:
   5269  1.1.1.2  christos 	  /* If this is a -Bsymbolic link, and the symbol is defined
   5270  1.1.1.2  christos 	     locally, we just want to emit a RELATIVE reloc.  Likewise if
   5271  1.1.1.2  christos 	     the symbol was forced to be local because of a version file.
   5272  1.1.1.6  christos 	     The entry in the global offset table will already have been
   5273  1.1.1.2  christos 	     initialized in the relocate_section function.  */
   5274  1.1.1.2  christos 	  if (bfd_link_pic (info)
   5275  1.1.1.2  christos 	      && (info->symbolic || h->dynindx == -1)
   5276  1.1.1.2  christos 	      && h->def_regular)
   5277  1.1.1.2  christos 	    {
   5278  1.1.1.2  christos 	      rel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
   5279  1.1.1.2  christos 	      rel.r_addend = (h->root.u.def.value
   5280  1.1.1.2  christos 			      + h->root.u.def.section->output_section->vma
   5281  1.1.1.2  christos 			      + h->root.u.def.section->output_offset);
   5282  1.1.1.2  christos 	    }
   5283  1.1.1.2  christos 	  else
   5284  1.1.1.2  christos 	    {
   5285  1.1.1.2  christos 	      bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
   5286  1.1.1.2  christos 	      rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_GLOB_DAT);
   5287      1.1  christos 	      rel.r_addend = 0;
   5288      1.1  christos 	    }
   5289  1.1.1.2  christos 	}
   5290  1.1.1.2  christos 
   5291  1.1.1.2  christos       if (ELF32_R_TYPE (rel.r_info) != R_MN10300_NONE)
   5292  1.1.1.2  christos 	{
   5293  1.1.1.2  christos 	  bfd_elf32_swap_reloca_out (output_bfd, &rel,
   5294  1.1.1.2  christos 				     (bfd_byte *) ((Elf32_External_Rela *) srel->contents
   5295  1.1.1.2  christos 						   + srel->reloc_count));
   5296      1.1  christos 	  ++ srel->reloc_count;
   5297      1.1  christos 	}
   5298      1.1  christos     }
   5299      1.1  christos 
   5300  1.1.1.8  christos   if (h->needs_copy)
   5301      1.1  christos     {
   5302      1.1  christos       asection *	s;
   5303      1.1  christos       Elf_Internal_Rela rel;
   5304      1.1  christos 
   5305      1.1  christos       /* This symbol needs a copy reloc.  Set it up.  */
   5306      1.1  christos       BFD_ASSERT (h->dynindx != -1
   5307      1.1  christos 		  && (h->root.type == bfd_link_hash_defined
   5308  1.1.1.2  christos 		      || h->root.type == bfd_link_hash_defweak));
   5309      1.1  christos 
   5310      1.1  christos       s = bfd_get_linker_section (dynobj, ".rela.bss");
   5311      1.1  christos       BFD_ASSERT (s != NULL);
   5312      1.1  christos 
   5313      1.1  christos       rel.r_offset = (h->root.u.def.value
   5314      1.1  christos 		      + h->root.u.def.section->output_section->vma
   5315      1.1  christos 		      + h->root.u.def.section->output_offset);
   5316      1.1  christos       rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_COPY);
   5317      1.1  christos       rel.r_addend = 0;
   5318      1.1  christos       bfd_elf32_swap_reloca_out (output_bfd, & rel,
   5319      1.1  christos 				 (bfd_byte *) ((Elf32_External_Rela *) s->contents
   5320      1.1  christos 					       + s->reloc_count));
   5321      1.1  christos       ++ s->reloc_count;
   5322      1.1  christos     }
   5323  1.1.1.2  christos 
   5324      1.1  christos   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
   5325      1.1  christos   if (h == elf_hash_table (info)->hdynamic
   5326      1.1  christos       || h == elf_hash_table (info)->hgot)
   5327      1.1  christos     sym->st_shndx = SHN_ABS;
   5328      1.1  christos 
   5329      1.1  christos   return TRUE;
   5330      1.1  christos }
   5331      1.1  christos 
   5332      1.1  christos /* Finish up the dynamic sections.  */
   5333      1.1  christos 
   5334      1.1  christos static bfd_boolean
   5335      1.1  christos _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd,
   5336      1.1  christos 					  struct bfd_link_info * info)
   5337      1.1  christos {
   5338      1.1  christos   bfd *      dynobj;
   5339  1.1.1.2  christos   asection * sgot;
   5340      1.1  christos   asection * sdyn;
   5341  1.1.1.2  christos   struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   5342  1.1.1.2  christos 
   5343      1.1  christos   dynobj = htab->root.dynobj;
   5344  1.1.1.2  christos   sgot = htab->root.sgotplt;
   5345      1.1  christos   BFD_ASSERT (sgot != NULL);
   5346      1.1  christos   sdyn = bfd_get_linker_section (dynobj, ".dynamic");
   5347      1.1  christos 
   5348  1.1.1.8  christos   if (elf_hash_table (info)->dynamic_sections_created)
   5349      1.1  christos     {
   5350      1.1  christos       asection *	   splt;
   5351      1.1  christos       Elf32_External_Dyn * dyncon;
   5352      1.1  christos       Elf32_External_Dyn * dynconend;
   5353      1.1  christos 
   5354      1.1  christos       BFD_ASSERT (sdyn != NULL);
   5355      1.1  christos 
   5356      1.1  christos       dyncon = (Elf32_External_Dyn *) sdyn->contents;
   5357      1.1  christos       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
   5358      1.1  christos 
   5359      1.1  christos       for (; dyncon < dynconend; dyncon++)
   5360      1.1  christos 	{
   5361      1.1  christos 	  Elf_Internal_Dyn dyn;
   5362      1.1  christos 	  asection * s;
   5363      1.1  christos 
   5364      1.1  christos 	  bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
   5365      1.1  christos 
   5366      1.1  christos 	  switch (dyn.d_tag)
   5367      1.1  christos 	    {
   5368      1.1  christos 	    default:
   5369      1.1  christos 	      break;
   5370  1.1.1.7  christos 
   5371      1.1  christos 	    case DT_PLTGOT:
   5372      1.1  christos 	      s = htab->root.sgot;
   5373      1.1  christos 	      goto get_vma;
   5374  1.1.1.7  christos 
   5375      1.1  christos 	    case DT_JMPREL:
   5376  1.1.1.6  christos 	      s = htab->root.srelplt;
   5377      1.1  christos 	    get_vma:
   5378      1.1  christos 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   5379      1.1  christos 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   5380      1.1  christos 	      break;
   5381  1.1.1.7  christos 
   5382      1.1  christos 	    case DT_PLTRELSZ:
   5383      1.1  christos 	      s = htab->root.srelplt;
   5384      1.1  christos 	      dyn.d_un.d_val = s->size;
   5385      1.1  christos 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   5386      1.1  christos 	      break;
   5387      1.1  christos 	    }
   5388      1.1  christos 	}
   5389  1.1.1.2  christos 
   5390      1.1  christos       /* Fill in the first entry in the procedure linkage table.  */
   5391      1.1  christos       splt = htab->root.splt;
   5392  1.1.1.6  christos       if (splt && splt->size > 0)
   5393      1.1  christos 	{
   5394      1.1  christos 	  if (bfd_link_pic (info))
   5395      1.1  christos 	    {
   5396      1.1  christos 	      memcpy (splt->contents, elf_mn10300_pic_plt_entry,
   5397      1.1  christos 		      elf_mn10300_sizeof_plt (info));
   5398      1.1  christos 	    }
   5399      1.1  christos 	  else
   5400      1.1  christos 	    {
   5401      1.1  christos 	      memcpy (splt->contents, elf_mn10300_plt0_entry, PLT0_ENTRY_SIZE);
   5402      1.1  christos 	      bfd_put_32 (output_bfd,
   5403      1.1  christos 			  sgot->output_section->vma + sgot->output_offset + 4,
   5404      1.1  christos 			  splt->contents + elf_mn10300_plt0_gotid_offset (info));
   5405      1.1  christos 	      bfd_put_32 (output_bfd,
   5406      1.1  christos 			  sgot->output_section->vma + sgot->output_offset + 8,
   5407      1.1  christos 			  splt->contents + elf_mn10300_plt0_linker_offset (info));
   5408      1.1  christos 	    }
   5409      1.1  christos 
   5410      1.1  christos 	  /* UnixWare sets the entsize of .plt to 4, although that doesn't
   5411  1.1.1.2  christos 	     really seem like the right value.  */
   5412  1.1.1.2  christos 	  elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
   5413  1.1.1.2  christos 
   5414  1.1.1.2  christos 	  /* UnixWare sets the entsize of .plt to 4, but this is incorrect
   5415  1.1.1.2  christos 	     as it means that the size of the PLT0 section (15 bytes) is not
   5416  1.1.1.2  christos 	     a multiple of the sh_entsize.  Some ELF tools flag this as an
   5417  1.1.1.2  christos 	     error.  We could pad PLT0 to 16 bytes, but that would introduce
   5418  1.1.1.2  christos 	     compatibilty issues with previous toolchains, so instead we
   5419      1.1  christos 	     just set the entry size to 1.  */
   5420      1.1  christos 	  elf_section_data (splt->output_section)->this_hdr.sh_entsize = 1;
   5421      1.1  christos 	}
   5422      1.1  christos     }
   5423      1.1  christos 
   5424      1.1  christos   /* Fill in the first three entries in the global offset table.  */
   5425      1.1  christos   if (sgot->size > 0)
   5426      1.1  christos     {
   5427      1.1  christos       if (sdyn == NULL)
   5428      1.1  christos 	bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
   5429      1.1  christos       else
   5430      1.1  christos 	bfd_put_32 (output_bfd,
   5431      1.1  christos 		    sdyn->output_section->vma + sdyn->output_offset,
   5432      1.1  christos 		    sgot->contents);
   5433      1.1  christos       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
   5434      1.1  christos       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
   5435      1.1  christos     }
   5436      1.1  christos 
   5437      1.1  christos   elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
   5438      1.1  christos 
   5439      1.1  christos   return TRUE;
   5440      1.1  christos }
   5441      1.1  christos 
   5442      1.1  christos /* Classify relocation types, such that combreloc can sort them
   5443      1.1  christos    properly.  */
   5444  1.1.1.3  christos 
   5445  1.1.1.3  christos static enum elf_reloc_type_class
   5446  1.1.1.3  christos _bfd_mn10300_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
   5447      1.1  christos 				   const asection *rel_sec ATTRIBUTE_UNUSED,
   5448      1.1  christos 				   const Elf_Internal_Rela *rela)
   5449      1.1  christos {
   5450      1.1  christos   switch ((int) ELF32_R_TYPE (rela->r_info))
   5451      1.1  christos     {
   5452      1.1  christos     case R_MN10300_RELATIVE:	return reloc_class_relative;
   5453      1.1  christos     case R_MN10300_JMP_SLOT:	return reloc_class_plt;
   5454      1.1  christos     case R_MN10300_COPY:	return reloc_class_copy;
   5455      1.1  christos     default:			return reloc_class_normal;
   5456      1.1  christos     }
   5457  1.1.1.2  christos }
   5458  1.1.1.2  christos 
   5459  1.1.1.2  christos /* Allocate space for an MN10300 extension to the bfd elf data structure.  */
   5460  1.1.1.2  christos 
   5461  1.1.1.2  christos static bfd_boolean
   5462  1.1.1.2  christos mn10300_elf_mkobject (bfd *abfd)
   5463  1.1.1.2  christos {
   5464  1.1.1.2  christos   return bfd_elf_allocate_object (abfd, sizeof (struct elf_mn10300_obj_tdata),
   5465  1.1.1.2  christos 				  MN10300_ELF_DATA);
   5466  1.1.1.2  christos }
   5467  1.1.1.2  christos 
   5468      1.1  christos #define bfd_elf32_mkobject	mn10300_elf_mkobject
   5469  1.1.1.4  christos 
   5470      1.1  christos #ifndef ELF_ARCH
   5471      1.1  christos #define TARGET_LITTLE_SYM	mn10300_elf32_vec
   5472      1.1  christos #define TARGET_LITTLE_NAME	"elf32-mn10300"
   5473      1.1  christos #define ELF_ARCH		bfd_arch_mn10300
   5474      1.1  christos #define ELF_TARGET_ID		MN10300_ELF_DATA
   5475      1.1  christos #define ELF_MACHINE_CODE	EM_MN10300
   5476      1.1  christos #define ELF_MACHINE_ALT1	EM_CYGNUS_MN10300
   5477      1.1  christos #define ELF_MAXPAGESIZE		0x1000
   5478      1.1  christos #endif
   5479  1.1.1.8  christos 
   5480      1.1  christos #define elf_info_to_howto		mn10300_info_to_howto
   5481      1.1  christos #define elf_info_to_howto_rel		NULL
   5482      1.1  christos #define elf_backend_can_gc_sections	1
   5483      1.1  christos #define elf_backend_rela_normal		1
   5484      1.1  christos #define elf_backend_check_relocs	mn10300_elf_check_relocs
   5485      1.1  christos #define elf_backend_gc_mark_hook	mn10300_elf_gc_mark_hook
   5486      1.1  christos #define elf_backend_relocate_section	mn10300_elf_relocate_section
   5487      1.1  christos #define bfd_elf32_bfd_relax_section	mn10300_elf_relax_section
   5488      1.1  christos #define bfd_elf32_bfd_get_relocated_section_contents \
   5489      1.1  christos 				mn10300_elf_get_relocated_section_contents
   5490      1.1  christos #define bfd_elf32_bfd_link_hash_table_create \
   5491      1.1  christos 				elf32_mn10300_link_hash_table_create
   5492      1.1  christos 
   5493      1.1  christos #ifndef elf_symbol_leading_char
   5494      1.1  christos #define elf_symbol_leading_char '_'
   5495      1.1  christos #endif
   5496      1.1  christos 
   5497      1.1  christos /* So we can set bits in e_flags.  */
   5498      1.1  christos #define elf_backend_final_write_processing \
   5499      1.1  christos 					_bfd_mn10300_elf_final_write_processing
   5500      1.1  christos #define elf_backend_object_p		_bfd_mn10300_elf_object_p
   5501      1.1  christos 
   5502      1.1  christos #define bfd_elf32_bfd_merge_private_bfd_data \
   5503      1.1  christos 					_bfd_mn10300_elf_merge_private_bfd_data
   5504      1.1  christos 
   5505      1.1  christos #define elf_backend_can_gc_sections	1
   5506      1.1  christos #define elf_backend_create_dynamic_sections \
   5507      1.1  christos   _bfd_mn10300_elf_create_dynamic_sections
   5508      1.1  christos #define elf_backend_adjust_dynamic_symbol \
   5509      1.1  christos   _bfd_mn10300_elf_adjust_dynamic_symbol
   5510  1.1.1.8  christos #define elf_backend_size_dynamic_sections \
   5511      1.1  christos   _bfd_mn10300_elf_size_dynamic_sections
   5512      1.1  christos #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
   5513      1.1  christos #define elf_backend_finish_dynamic_symbol \
   5514      1.1  christos   _bfd_mn10300_elf_finish_dynamic_symbol
   5515  1.1.1.2  christos #define elf_backend_finish_dynamic_sections \
   5516  1.1.1.2  christos   _bfd_mn10300_elf_finish_dynamic_sections
   5517      1.1  christos #define elf_backend_copy_indirect_symbol \
   5518      1.1  christos   _bfd_mn10300_copy_indirect_symbol
   5519      1.1  christos #define elf_backend_reloc_type_class \
   5520      1.1  christos   _bfd_mn10300_elf_reloc_type_class
   5521      1.1  christos 
   5522      1.1  christos #define elf_backend_want_got_plt	1
   5523      1.1  christos #define elf_backend_plt_readonly	1
   5524  1.1.1.7  christos #define elf_backend_want_plt_sym	0
   5525      1.1  christos #define elf_backend_got_header_size	12
   5526      1.1  christos #define elf_backend_dtrel_excludes_plt	1
   5527                    
   5528                    #include "elf32-target.h"
   5529