Home | History | Annotate | Line # | Download | only in bfd
      1       1.1  christos /* Matsushita 10300 specific support for 32-bit ELF
      2  1.1.1.13  christos    Copyright (C) 1996-2025 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.1.10  christos     (bool (*) (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 	 0,
    147  1.1.1.10  christos 	 0,
    148  1.1.1.10  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.1.10  christos 	 false,
    154       1.1  christos 	 0,
    155       1.1  christos 	 0,
    156  1.1.1.10  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.1.10  christos 	 4,
    161       1.1  christos 	 32,
    162  1.1.1.10  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.1.10  christos 	 false,
    168       1.1  christos 	 0xffffffff,
    169       1.1  christos 	 0xffffffff,
    170  1.1.1.10  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.1.10  christos 	 2,
    175       1.1  christos 	 16,
    176  1.1.1.10  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.1.10  christos 	 false,
    182       1.1  christos 	 0xffff,
    183       1.1  christos 	 0xffff,
    184  1.1.1.10  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.1.10  christos 	 1,
    189       1.1  christos 	 8,
    190  1.1.1.10  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.1.10  christos 	 false,
    196       1.1  christos 	 0xff,
    197       1.1  christos 	 0xff,
    198  1.1.1.10  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.1.10  christos 	 4,
    203       1.1  christos 	 32,
    204  1.1.1.10  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.1.10  christos 	 false,
    210       1.1  christos 	 0xffffffff,
    211       1.1  christos 	 0xffffffff,
    212  1.1.1.10  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.1.10  christos 	 2,
    217       1.1  christos 	 16,
    218  1.1.1.10  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.1.10  christos 	 false,
    224       1.1  christos 	 0xffff,
    225       1.1  christos 	 0xffff,
    226  1.1.1.10  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.1.10  christos 	 1,
    231       1.1  christos 	 8,
    232  1.1.1.10  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.1.10  christos 	 false,
    238       1.1  christos 	 0xff,
    239       1.1  christos 	 0xff,
    240  1.1.1.10  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.1.10  christos 	 0,			/* size */
    246       1.1  christos 	 0,			/* bitsize */
    247  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    253       1.1  christos 	 0,			/* src_mask */
    254       1.1  christos 	 0,			/* dst_mask */
    255  1.1.1.10  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.1.10  christos 	 0,			/* size */
    261       1.1  christos 	 0,			/* bitsize */
    262  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    268       1.1  christos 	 0,			/* src_mask */
    269       1.1  christos 	 0,			/* dst_mask */
    270  1.1.1.10  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.1.10  christos 	 4,
    276       1.1  christos 	 24,
    277  1.1.1.10  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.1.10  christos 	 false,
    283       1.1  christos 	 0xffffff,
    284       1.1  christos 	 0xffffff,
    285  1.1.1.10  christos 	 false),
    286       1.1  christos   HOWTO (R_MN10300_GOTPC32,	/* type */
    287       1.1  christos 	 0,			/* rightshift */
    288  1.1.1.10  christos 	 4,			/* size */
    289       1.1  christos 	 32,			/* bitsize */
    290  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    296       1.1  christos 	 0xffffffff,		/* src_mask */
    297       1.1  christos 	 0xffffffff,		/* dst_mask */
    298  1.1.1.10  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.1.10  christos 	 2,			/* size */
    303       1.1  christos 	 16,			/* bitsize */
    304  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    310       1.1  christos 	 0xffff,		/* src_mask */
    311       1.1  christos 	 0xffff,		/* dst_mask */
    312  1.1.1.10  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.1.10  christos 	 4,			/* size */
    317       1.1  christos 	 32,			/* bitsize */
    318  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    324       1.1  christos 	 0xffffffff,		/* src_mask */
    325       1.1  christos 	 0xffffffff,		/* dst_mask */
    326  1.1.1.10  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.1.10  christos 	 4,			/* size */
    331       1.1  christos 	 24,			/* bitsize */
    332  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    338       1.1  christos 	 0xffffff,		/* src_mask */
    339       1.1  christos 	 0xffffff,		/* dst_mask */
    340  1.1.1.10  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.1.10  christos 	 2,			/* size */
    345       1.1  christos 	 16,			/* bitsize */
    346  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    352       1.1  christos 	 0xffff,		/* src_mask */
    353       1.1  christos 	 0xffff,		/* dst_mask */
    354  1.1.1.10  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.1.10  christos 	 4,			/* size */
    359       1.1  christos 	 32,			/* bitsize */
    360  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    366       1.1  christos 	 0xffffffff,		/* src_mask */
    367       1.1  christos 	 0xffffffff,		/* dst_mask */
    368  1.1.1.10  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.1.10  christos 	 2,			/* size */
    373       1.1  christos 	 16,			/* bitsize */
    374  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    380       1.1  christos 	 0xffff,		/* src_mask */
    381       1.1  christos 	 0xffff,		/* dst_mask */
    382  1.1.1.10  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.1.10  christos 	 4,			/* size */
    387       1.1  christos 	 32,			/* bitsize */
    388  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    394       1.1  christos 	 0xffffffff,		/* src_mask */
    395       1.1  christos 	 0xffffffff,		/* dst_mask */
    396  1.1.1.10  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.1.10  christos 	 4,			/* size */
    401       1.1  christos 	 24,			/* bitsize */
    402  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    408       1.1  christos 	 0xffffffff,		/* src_mask */
    409       1.1  christos 	 0xffffffff,		/* dst_mask */
    410  1.1.1.10  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.1.10  christos 	 2,			/* size */
    415       1.1  christos 	 16,			/* bitsize */
    416  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    422       1.1  christos 	 0xffffffff,		/* src_mask */
    423       1.1  christos 	 0xffffffff,		/* dst_mask */
    424  1.1.1.10  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.1.10  christos 	 4,			/* size */
    429       1.1  christos 	 32,			/* bitsize */
    430  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    436       1.1  christos 	 0xffffffff,		/* src_mask */
    437       1.1  christos 	 0xffffffff,		/* dst_mask */
    438  1.1.1.10  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.1.10  christos 	 4,			/* size */
    443       1.1  christos 	 32,			/* bitsize */
    444  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    450       1.1  christos 	 0xffffffff,		/* src_mask */
    451       1.1  christos 	 0xffffffff,		/* dst_mask */
    452  1.1.1.10  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.1.10  christos 	 4,			/* size */
    457       1.1  christos 	 32,			/* bitsize */
    458  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    464       1.1  christos 	 0xffffffff,		/* src_mask */
    465       1.1  christos 	 0xffffffff,		/* dst_mask */
    466  1.1.1.10  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.1.10  christos 	 4,			/* size */
    471       1.1  christos 	 32,			/* bitsize */
    472  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    478       1.1  christos 	 0xffffffff,		/* src_mask */
    479       1.1  christos 	 0xffffffff,		/* dst_mask */
    480  1.1.1.10  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.10  christos 	 4,			/* size */
    485   1.1.1.2  christos 	 32,			/* bitsize */
    486  1.1.1.10  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.10  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.10  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.10  christos 	 4,			/* size */
    499   1.1.1.2  christos 	 32,			/* bitsize */
    500  1.1.1.10  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.10  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.10  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.10  christos 	 4,			/* size */
    513   1.1.1.2  christos 	 32,			/* bitsize */
    514  1.1.1.10  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.10  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.10  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.10  christos 	 4,			/* size */
    527   1.1.1.2  christos 	 32,			/* bitsize */
    528  1.1.1.10  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.10  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.10  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.10  christos 	 4,			/* size */
    541   1.1.1.2  christos 	 32,			/* bitsize */
    542  1.1.1.10  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.10  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.10  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.10  christos 	 4,			/* size */
    555   1.1.1.2  christos 	 32,			/* bitsize */
    556  1.1.1.10  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.10  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.10  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.10  christos 	 4,			/* size */
    569   1.1.1.2  christos 	 32,			/* bitsize */
    570  1.1.1.10  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.10  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.10  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.10  christos 	 4,			/* size */
    583   1.1.1.2  christos 	 32,			/* bitsize */
    584  1.1.1.10  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.10  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.10  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.10  christos 	 4,			/* size */
    597   1.1.1.2  christos 	 32,			/* bitsize */
    598  1.1.1.10  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.10  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.10  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.1.10  christos 	 4,			/* size */
    611       1.1  christos 	 32,			/* bitsize */
    612  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    618       1.1  christos 	 0xffffffff,		/* src_mask */
    619       1.1  christos 	 0xffffffff,		/* dst_mask */
    620  1.1.1.10  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.1.10  christos 	 1,			/* size */
    625       1.1  christos 	 32,			/* bitsize */
    626  1.1.1.10  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.1.10  christos 	 false,			/* partial_inplace */
    632       1.1  christos 	 0,			/* src_mask */
    633       1.1  christos 	 0,			/* dst_mask */
    634  1.1.1.10  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.1.10  christos static bool
    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.1.10  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.1.10  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.1.10  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.1.10  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.1.10  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.1.10  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.1.10  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.1.10  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.10  christos static bool
    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.10  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.10  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.10  christos 			    bool			  counting)
    828   1.1.1.2  christos {
    829  1.1.1.10  christos   bool 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.10  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.1.10  christos static bool
   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.1.10  christos   bool 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.1.10  christos   bool 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.1.10  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.1.10  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.10  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.1.10  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.1.10  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.1.10  christos 	sym_diff_reloc_seen = false;
   1372       1.1  christos     }
   1373       1.1  christos 
   1374  1.1.1.10  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.1.10  christos   bool 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.1.10  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.1.10  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.1.10  christos 	  bool 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.1.10  christos 		(input_bfd, input_section, /*rela?*/ true);
   1538       1.1  christos 	      if (sreloc == NULL)
   1539  1.1.1.10  christos 		return false;
   1540       1.1  christos 	    }
   1541       1.1  christos 
   1542  1.1.1.10  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.1.10  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.1.10  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.1.10  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.1.10  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.1.10  christos 
   1967       1.1  christos static int
   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.10  christos       int tls_r_type;
   1998  1.1.1.10  christos       bool unresolved_reloc = false;
   1999   1.1.1.2  christos       bool 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.10  christos 	{
   2029       1.1  christos 	  bool 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.13  christos 	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   2105  1.1.1.13  christos 					 rel, 1, relend, R_MN10300_NONE,
   2106       1.1  christos 					 howto, 0, contents);
   2107   1.1.1.6  christos 
   2108       1.1  christos       if (bfd_link_relocatable (info))
   2109       1.1  christos 	continue;
   2110       1.1  christos 
   2111       1.1  christos       r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
   2112       1.1  christos 					   input_section,
   2113       1.1  christos 					   contents, rel->r_offset,
   2114       1.1  christos 					   relocation, rel->r_addend,
   2115       1.1  christos 					   (struct elf_link_hash_entry *) h,
   2116       1.1  christos 					   r_symndx,
   2117       1.1  christos 					   info, sec, h == NULL);
   2118       1.1  christos 
   2119       1.1  christos       if (r != bfd_reloc_ok)
   2120       1.1  christos 	{
   2121       1.1  christos 	  const char *name;
   2122       1.1  christos 	  const char *msg = NULL;
   2123       1.1  christos 
   2124       1.1  christos 	  if (h != NULL)
   2125       1.1  christos 	    name = h->root.root.root.string;
   2126       1.1  christos 	  else
   2127       1.1  christos 	    {
   2128       1.1  christos 	      name = (bfd_elf_string_from_elf_section
   2129       1.1  christos 		      (input_bfd, symtab_hdr->sh_link, sym->st_name));
   2130   1.1.1.9  christos 	      if (name == NULL || *name == '\0')
   2131       1.1  christos 		name = bfd_section_name (sec);
   2132       1.1  christos 	    }
   2133       1.1  christos 
   2134       1.1  christos 	  switch (r)
   2135       1.1  christos 	    {
   2136   1.1.1.6  christos 	    case bfd_reloc_overflow:
   2137   1.1.1.6  christos 	      (*info->callbacks->reloc_overflow)
   2138   1.1.1.6  christos 		(info, (h ? &h->root.root : NULL), name, howto->name,
   2139       1.1  christos 		 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
   2140       1.1  christos 	      break;
   2141       1.1  christos 
   2142   1.1.1.6  christos 	    case bfd_reloc_undefined:
   2143  1.1.1.10  christos 	      (*info->callbacks->undefined_symbol)
   2144       1.1  christos 		(info, name, input_bfd, input_section, rel->r_offset, true);
   2145       1.1  christos 	      break;
   2146       1.1  christos 
   2147       1.1  christos 	    case bfd_reloc_outofrange:
   2148       1.1  christos 	      msg = _("internal error: out of range error");
   2149       1.1  christos 	      goto common_error;
   2150       1.1  christos 
   2151       1.1  christos 	    case bfd_reloc_notsupported:
   2152       1.1  christos 	      msg = _("internal error: unsupported relocation error");
   2153       1.1  christos 	      goto common_error;
   2154       1.1  christos 
   2155       1.1  christos 	    case bfd_reloc_dangerous:
   2156       1.1  christos 	      if (r_type == R_MN10300_PCREL32)
   2157       1.1  christos 		msg = _("error: inappropriate relocation type for shared"
   2158   1.1.1.2  christos 			" library (did you forget -fpic?)");
   2159   1.1.1.7  christos 	      else if (r_type == R_MN10300_GOT32)
   2160   1.1.1.8  christos 		/* xgettext:c-format */
   2161   1.1.1.2  christos 		msg = _("%pB: taking the address of protected function"
   2162       1.1  christos 			" '%s' cannot be done when making a shared library");
   2163       1.1  christos 	      else
   2164       1.1  christos 		msg = _("internal error: suspicious relocation type used"
   2165       1.1  christos 			" in shared library");
   2166       1.1  christos 	      goto common_error;
   2167       1.1  christos 
   2168       1.1  christos 	    default:
   2169       1.1  christos 	      msg = _("internal error: unknown error");
   2170       1.1  christos 	      /* Fall through.  */
   2171       1.1  christos 
   2172   1.1.1.2  christos 	    common_error:
   2173   1.1.1.2  christos 	      _bfd_error_handler (msg, input_bfd, name);
   2174  1.1.1.10  christos 	      bfd_set_error (bfd_error_bad_value);
   2175       1.1  christos 	      return false;
   2176       1.1  christos 	    }
   2177       1.1  christos 	}
   2178       1.1  christos     }
   2179  1.1.1.10  christos 
   2180       1.1  christos   return true;
   2181       1.1  christos }
   2182       1.1  christos 
   2183       1.1  christos /* Finish initializing one hash table entry.  */
   2184  1.1.1.10  christos 
   2185       1.1  christos static bool
   2186       1.1  christos elf32_mn10300_finish_hash_table_entry (struct bfd_hash_entry *gen_entry,
   2187       1.1  christos 				       void * in_args)
   2188       1.1  christos {
   2189       1.1  christos   struct elf32_mn10300_link_hash_entry *entry;
   2190       1.1  christos   struct bfd_link_info *link_info = (struct bfd_link_info *) in_args;
   2191       1.1  christos   unsigned int byte_count = 0;
   2192       1.1  christos 
   2193       1.1  christos   entry = (struct elf32_mn10300_link_hash_entry *) gen_entry;
   2194       1.1  christos 
   2195       1.1  christos   /* If we already know we want to convert "call" to "calls" for calls
   2196       1.1  christos      to this symbol, then return now.  */
   2197  1.1.1.10  christos   if (entry->flags == MN10300_CONVERT_CALL_TO_CALLS)
   2198       1.1  christos     return true;
   2199       1.1  christos 
   2200       1.1  christos   /* If there are no named calls to this symbol, or there's nothing we
   2201       1.1  christos      can move from the function itself into the "call" instruction,
   2202       1.1  christos      then note that all "call" instructions should be converted into
   2203       1.1  christos      "calls" instructions and return.  If a symbol is available for
   2204       1.1  christos      dynamic symbol resolution (overridable or overriding), avoid
   2205       1.1  christos      custom calling conventions.  */
   2206       1.1  christos   if (entry->direct_calls == 0
   2207       1.1  christos       || (entry->stack_size == 0 && entry->movm_args == 0)
   2208       1.1  christos       || (elf_hash_table (link_info)->dynamic_sections_created
   2209       1.1  christos 	  && ELF_ST_VISIBILITY (entry->root.other) != STV_INTERNAL
   2210       1.1  christos 	  && ELF_ST_VISIBILITY (entry->root.other) != STV_HIDDEN))
   2211       1.1  christos     {
   2212       1.1  christos       /* Make a note that we should convert "call" instructions to "calls"
   2213       1.1  christos 	 instructions for calls to this symbol.  */
   2214  1.1.1.10  christos       entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
   2215       1.1  christos       return true;
   2216       1.1  christos     }
   2217       1.1  christos 
   2218       1.1  christos   /* We may be able to move some instructions from the function itself into
   2219       1.1  christos      the "call" instruction.  Count how many bytes we might be able to
   2220       1.1  christos      eliminate in the function itself.  */
   2221       1.1  christos 
   2222       1.1  christos   /* A movm instruction is two bytes.  */
   2223       1.1  christos   if (entry->movm_args)
   2224       1.1  christos     byte_count += 2;
   2225       1.1  christos 
   2226       1.1  christos   /* Count the insn to allocate stack space too.  */
   2227       1.1  christos   if (entry->stack_size > 0)
   2228       1.1  christos     {
   2229       1.1  christos       if (entry->stack_size <= 128)
   2230       1.1  christos 	byte_count += 3;
   2231       1.1  christos       else
   2232       1.1  christos 	byte_count += 4;
   2233       1.1  christos     }
   2234       1.1  christos 
   2235       1.1  christos   /* If using "call" will result in larger code, then turn all
   2236       1.1  christos      the associated "call" instructions into "calls" instructions.  */
   2237       1.1  christos   if (byte_count < entry->direct_calls)
   2238       1.1  christos     entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
   2239       1.1  christos 
   2240  1.1.1.10  christos   /* This routine never fails.  */
   2241       1.1  christos   return true;
   2242       1.1  christos }
   2243       1.1  christos 
   2244       1.1  christos /* Used to count hash table entries.  */
   2245  1.1.1.10  christos 
   2246       1.1  christos static bool
   2247       1.1  christos elf32_mn10300_count_hash_table_entries (struct bfd_hash_entry *gen_entry ATTRIBUTE_UNUSED,
   2248       1.1  christos 					void * in_args)
   2249       1.1  christos {
   2250       1.1  christos   int *count = (int *) in_args;
   2251       1.1  christos 
   2252  1.1.1.10  christos   (*count) ++;
   2253       1.1  christos   return true;
   2254       1.1  christos }
   2255       1.1  christos 
   2256       1.1  christos /* Used to enumerate hash table entries into a linear array.  */
   2257  1.1.1.10  christos 
   2258       1.1  christos static bool
   2259       1.1  christos elf32_mn10300_list_hash_table_entries (struct bfd_hash_entry *gen_entry,
   2260       1.1  christos 				       void * in_args)
   2261       1.1  christos {
   2262       1.1  christos   struct bfd_hash_entry ***ptr = (struct bfd_hash_entry ***) in_args;
   2263       1.1  christos 
   2264       1.1  christos   **ptr = gen_entry;
   2265  1.1.1.10  christos   (*ptr) ++;
   2266       1.1  christos   return true;
   2267       1.1  christos }
   2268       1.1  christos 
   2269       1.1  christos /* Used to sort the array created by the above.  */
   2270       1.1  christos 
   2271       1.1  christos static int
   2272       1.1  christos sort_by_value (const void *va, const void *vb)
   2273       1.1  christos {
   2274       1.1  christos   struct elf32_mn10300_link_hash_entry *a
   2275       1.1  christos     = *(struct elf32_mn10300_link_hash_entry **) va;
   2276       1.1  christos   struct elf32_mn10300_link_hash_entry *b
   2277       1.1  christos     = *(struct elf32_mn10300_link_hash_entry **) vb;
   2278       1.1  christos 
   2279       1.1  christos   return a->value - b->value;
   2280       1.1  christos }
   2281       1.1  christos 
   2282       1.1  christos /* Compute the stack size and movm arguments for the function
   2283       1.1  christos    referred to by HASH at address ADDR in section with
   2284       1.1  christos    contents CONTENTS, store the information in the hash table.  */
   2285       1.1  christos 
   2286       1.1  christos static void
   2287       1.1  christos compute_function_info (bfd *abfd,
   2288       1.1  christos 		       struct elf32_mn10300_link_hash_entry *hash,
   2289       1.1  christos 		       bfd_vma addr,
   2290       1.1  christos 		       unsigned char *contents)
   2291       1.1  christos {
   2292       1.1  christos   unsigned char byte1, byte2;
   2293       1.1  christos   /* We only care about a very small subset of the possible prologue
   2294       1.1  christos      sequences here.  Basically we look for:
   2295       1.1  christos 
   2296       1.1  christos      movm [d2,d3,a2,a3],sp (optional)
   2297       1.1  christos      add <size>,sp (optional, and only for sizes which fit in an unsigned
   2298       1.1  christos 		    8 bit number)
   2299       1.1  christos 
   2300       1.1  christos      If we find anything else, we quit.  */
   2301       1.1  christos 
   2302       1.1  christos   /* Look for movm [regs],sp.  */
   2303       1.1  christos   byte1 = bfd_get_8 (abfd, contents + addr);
   2304       1.1  christos   byte2 = bfd_get_8 (abfd, contents + addr + 1);
   2305       1.1  christos 
   2306       1.1  christos   if (byte1 == 0xcf)
   2307       1.1  christos     {
   2308       1.1  christos       hash->movm_args = byte2;
   2309       1.1  christos       addr += 2;
   2310       1.1  christos       byte1 = bfd_get_8 (abfd, contents + addr);
   2311       1.1  christos       byte2 = bfd_get_8 (abfd, contents + addr + 1);
   2312       1.1  christos     }
   2313       1.1  christos 
   2314       1.1  christos   /* Now figure out how much stack space will be allocated by the movm
   2315       1.1  christos      instruction.  We need this kept separate from the function's normal
   2316       1.1  christos      stack space.  */
   2317       1.1  christos   if (hash->movm_args)
   2318       1.1  christos     {
   2319       1.1  christos       /* Space for d2.  */
   2320       1.1  christos       if (hash->movm_args & 0x80)
   2321       1.1  christos 	hash->movm_stack_size += 4;
   2322       1.1  christos 
   2323       1.1  christos       /* Space for d3.  */
   2324       1.1  christos       if (hash->movm_args & 0x40)
   2325       1.1  christos 	hash->movm_stack_size += 4;
   2326       1.1  christos 
   2327       1.1  christos       /* Space for a2.  */
   2328       1.1  christos       if (hash->movm_args & 0x20)
   2329       1.1  christos 	hash->movm_stack_size += 4;
   2330       1.1  christos 
   2331       1.1  christos       /* Space for a3.  */
   2332       1.1  christos       if (hash->movm_args & 0x10)
   2333       1.1  christos 	hash->movm_stack_size += 4;
   2334       1.1  christos 
   2335       1.1  christos       /* "other" space.  d0, d1, a0, a1, mdr, lir, lar, 4 byte pad.  */
   2336       1.1  christos       if (hash->movm_args & 0x08)
   2337       1.1  christos 	hash->movm_stack_size += 8 * 4;
   2338       1.1  christos 
   2339       1.1  christos       if (bfd_get_mach (abfd) == bfd_mach_am33
   2340       1.1  christos 	  || bfd_get_mach (abfd) == bfd_mach_am33_2)
   2341       1.1  christos 	{
   2342       1.1  christos 	  /* "exother" space.  e0, e1, mdrq, mcrh, mcrl, mcvf */
   2343       1.1  christos 	  if (hash->movm_args & 0x1)
   2344       1.1  christos 	    hash->movm_stack_size += 6 * 4;
   2345       1.1  christos 
   2346       1.1  christos 	  /* exreg1 space.  e4, e5, e6, e7 */
   2347       1.1  christos 	  if (hash->movm_args & 0x2)
   2348       1.1  christos 	    hash->movm_stack_size += 4 * 4;
   2349       1.1  christos 
   2350       1.1  christos 	  /* exreg0 space.  e2, e3  */
   2351       1.1  christos 	  if (hash->movm_args & 0x4)
   2352       1.1  christos 	    hash->movm_stack_size += 2 * 4;
   2353       1.1  christos 	}
   2354       1.1  christos     }
   2355       1.1  christos 
   2356       1.1  christos   /* Now look for the two stack adjustment variants.  */
   2357       1.1  christos   if (byte1 == 0xf8 && byte2 == 0xfe)
   2358       1.1  christos     {
   2359       1.1  christos       int temp = bfd_get_8 (abfd, contents + addr + 2);
   2360       1.1  christos       temp = ((temp & 0xff) ^ (~0x7f)) + 0x80;
   2361       1.1  christos 
   2362       1.1  christos       hash->stack_size = -temp;
   2363       1.1  christos     }
   2364       1.1  christos   else if (byte1 == 0xfa && byte2 == 0xfe)
   2365       1.1  christos     {
   2366       1.1  christos       int temp = bfd_get_16 (abfd, contents + addr + 2);
   2367       1.1  christos       temp = ((temp & 0xffff) ^ (~0x7fff)) + 0x8000;
   2368       1.1  christos       temp = -temp;
   2369       1.1  christos 
   2370       1.1  christos       if (temp < 255)
   2371       1.1  christos 	hash->stack_size = temp;
   2372       1.1  christos     }
   2373       1.1  christos 
   2374       1.1  christos   /* If the total stack to be allocated by the call instruction is more
   2375       1.1  christos      than 255 bytes, then we can't remove the stack adjustment by using
   2376       1.1  christos      "call" (we might still be able to remove the "movm" instruction.  */
   2377       1.1  christos   if (hash->stack_size + hash->movm_stack_size > 255)
   2378       1.1  christos     hash->stack_size = 0;
   2379       1.1  christos }
   2380       1.1  christos 
   2381       1.1  christos /* Delete some bytes from a section while relaxing.  */
   2382  1.1.1.10  christos 
   2383       1.1  christos static bool
   2384       1.1  christos mn10300_elf_relax_delete_bytes (bfd *abfd,
   2385       1.1  christos 				asection *sec,
   2386       1.1  christos 				bfd_vma addr,
   2387       1.1  christos 				int count)
   2388       1.1  christos {
   2389       1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   2390       1.1  christos   unsigned int sec_shndx;
   2391       1.1  christos   bfd_byte *contents;
   2392       1.1  christos   Elf_Internal_Rela *irel, *irelend;
   2393       1.1  christos   Elf_Internal_Rela *irelalign;
   2394       1.1  christos   bfd_vma toaddr;
   2395       1.1  christos   Elf_Internal_Sym *isym, *isymend;
   2396       1.1  christos   struct elf_link_hash_entry **sym_hashes;
   2397       1.1  christos   struct elf_link_hash_entry **end_hashes;
   2398       1.1  christos   unsigned int symcount;
   2399       1.1  christos 
   2400       1.1  christos   sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
   2401       1.1  christos 
   2402       1.1  christos   contents = elf_section_data (sec)->this_hdr.contents;
   2403       1.1  christos 
   2404       1.1  christos   irelalign = NULL;
   2405       1.1  christos   toaddr = sec->size;
   2406       1.1  christos 
   2407       1.1  christos   irel = elf_section_data (sec)->relocs;
   2408       1.1  christos   irelend = irel + sec->reloc_count;
   2409       1.1  christos 
   2410       1.1  christos   if (sec->reloc_count > 0)
   2411       1.1  christos     {
   2412       1.1  christos       /* If there is an align reloc at the end of the section ignore it.
   2413       1.1  christos 	 GAS creates these relocs for reasons of its own, and they just
   2414       1.1  christos 	 serve to keep the section artifically inflated.  */
   2415       1.1  christos       if (ELF32_R_TYPE ((irelend - 1)->r_info) == (int) R_MN10300_ALIGN)
   2416   1.1.1.2  christos 	--irelend;
   2417   1.1.1.8  christos 
   2418       1.1  christos       /* The deletion must stop at the next ALIGN reloc for an alignment
   2419       1.1  christos 	 power larger than, or not a multiple of, the number of bytes we
   2420       1.1  christos 	 are deleting.  */
   2421       1.1  christos       for (; irel < irelend; irel++)
   2422       1.1  christos 	{
   2423       1.1  christos 	  if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN
   2424   1.1.1.9  christos 	      && irel->r_offset > addr
   2425       1.1  christos 	      && irel->r_offset < toaddr)
   2426   1.1.1.9  christos 	    {
   2427   1.1.1.9  christos 	      int alignment = 1 << irel->r_addend;
   2428   1.1.1.9  christos 
   2429   1.1.1.9  christos 	      if (count < alignment
   2430   1.1.1.9  christos 		  || alignment % count != 0)
   2431   1.1.1.9  christos 		{
   2432   1.1.1.9  christos 		  irelalign = irel;
   2433   1.1.1.9  christos 		  toaddr = irel->r_offset;
   2434   1.1.1.9  christos 		  break;
   2435       1.1  christos 		}
   2436       1.1  christos 	    }
   2437       1.1  christos 	}
   2438       1.1  christos     }
   2439       1.1  christos 
   2440       1.1  christos   /* Actually delete the bytes.  */
   2441       1.1  christos   memmove (contents + addr, contents + addr + count,
   2442       1.1  christos 	   (size_t) (toaddr - addr - count));
   2443       1.1  christos 
   2444       1.1  christos   /* Adjust the section's size if we are shrinking it, or else
   2445       1.1  christos      pad the bytes between the end of the shrunken region and
   2446       1.1  christos      the start of the next region with NOP codes.  */
   2447       1.1  christos   if (irelalign == NULL)
   2448       1.1  christos     {
   2449       1.1  christos       sec->size -= count;
   2450       1.1  christos       /* Include symbols at the end of the section, but
   2451       1.1  christos 	 not at the end of a sub-region of the section.  */
   2452       1.1  christos       toaddr ++;
   2453       1.1  christos     }
   2454       1.1  christos   else
   2455       1.1  christos     {
   2456       1.1  christos       int i;
   2457       1.1  christos 
   2458       1.1  christos #define NOP_OPCODE 0xcb
   2459       1.1  christos 
   2460       1.1  christos       for (i = 0; i < count; i ++)
   2461       1.1  christos 	bfd_put_8 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
   2462       1.1  christos     }
   2463       1.1  christos 
   2464       1.1  christos   /* Adjust all the relocs.  */
   2465       1.1  christos   for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
   2466       1.1  christos     {
   2467       1.1  christos       /* Get the new reloc address.  */
   2468       1.1  christos       if ((irel->r_offset > addr
   2469       1.1  christos 	   && irel->r_offset < toaddr)
   2470       1.1  christos 	  || (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN
   2471       1.1  christos 	      && irel->r_offset == toaddr))
   2472       1.1  christos 	irel->r_offset -= count;
   2473       1.1  christos     }
   2474       1.1  christos 
   2475       1.1  christos   /* Adjust the local symbols in the section, reducing their value
   2476       1.1  christos      by the number of bytes deleted.  Note - symbols within the deleted
   2477       1.1  christos      region are moved to the address of the start of the region, which
   2478       1.1  christos      actually means that they will address the byte beyond the end of
   2479       1.1  christos      the region once the deletion has been completed.  */
   2480       1.1  christos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   2481       1.1  christos   isym = (Elf_Internal_Sym *) symtab_hdr->contents;
   2482       1.1  christos   for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
   2483       1.1  christos     {
   2484       1.1  christos       if (isym->st_shndx == sec_shndx
   2485       1.1  christos 	  && isym->st_value > addr
   2486       1.1  christos 	  && isym->st_value < toaddr)
   2487       1.1  christos 	{
   2488       1.1  christos 	  if (isym->st_value < addr + count)
   2489       1.1  christos 	    isym->st_value = addr;
   2490       1.1  christos 	  else
   2491       1.1  christos 	    isym->st_value -= count;
   2492       1.1  christos 	}
   2493       1.1  christos       /* Adjust the function symbol's size as well.  */
   2494       1.1  christos       else if (isym->st_shndx == sec_shndx
   2495       1.1  christos 	       && ELF_ST_TYPE (isym->st_info) == STT_FUNC
   2496       1.1  christos 	       && isym->st_value + isym->st_size > addr
   2497       1.1  christos 	       && isym->st_value + isym->st_size < toaddr)
   2498       1.1  christos 	isym->st_size -= count;
   2499       1.1  christos     }
   2500       1.1  christos 
   2501       1.1  christos   /* Now adjust the global symbols defined in this section.  */
   2502       1.1  christos   symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
   2503       1.1  christos 	      - symtab_hdr->sh_info);
   2504       1.1  christos   sym_hashes = elf_sym_hashes (abfd);
   2505       1.1  christos   end_hashes = sym_hashes + symcount;
   2506       1.1  christos   for (; sym_hashes < end_hashes; sym_hashes++)
   2507       1.1  christos     {
   2508       1.1  christos       struct elf_link_hash_entry *sym_hash = *sym_hashes;
   2509       1.1  christos 
   2510       1.1  christos       if ((sym_hash->root.type == bfd_link_hash_defined
   2511       1.1  christos 	   || sym_hash->root.type == bfd_link_hash_defweak)
   2512       1.1  christos 	  && sym_hash->root.u.def.section == sec
   2513       1.1  christos 	  && sym_hash->root.u.def.value > addr
   2514       1.1  christos 	  && sym_hash->root.u.def.value < toaddr)
   2515       1.1  christos 	{
   2516       1.1  christos 	  if (sym_hash->root.u.def.value < addr + count)
   2517       1.1  christos 	    sym_hash->root.u.def.value = addr;
   2518       1.1  christos 	  else
   2519       1.1  christos 	    sym_hash->root.u.def.value -= count;
   2520       1.1  christos 	}
   2521       1.1  christos       /* Adjust the function symbol's size as well.  */
   2522       1.1  christos       else if (sym_hash->root.type == bfd_link_hash_defined
   2523       1.1  christos 	       && sym_hash->root.u.def.section == sec
   2524       1.1  christos 	       && sym_hash->type == STT_FUNC
   2525       1.1  christos 	       && sym_hash->root.u.def.value + sym_hash->size > addr
   2526       1.1  christos 	       && sym_hash->root.u.def.value + sym_hash->size < toaddr)
   2527       1.1  christos 	sym_hash->size -= count;
   2528       1.1  christos     }
   2529       1.1  christos 
   2530       1.1  christos   /* See if we can move the ALIGN reloc forward.
   2531       1.1  christos      We have adjusted r_offset for it already.  */
   2532       1.1  christos   if (irelalign != NULL)
   2533       1.1  christos     {
   2534       1.1  christos       bfd_vma alignto, alignaddr;
   2535       1.1  christos 
   2536       1.1  christos       if ((int) irelalign->r_addend > 0)
   2537       1.1  christos 	{
   2538       1.1  christos 	  /* This is the old address.  */
   2539       1.1  christos 	  alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
   2540       1.1  christos 	  /* This is where the align points to now.  */
   2541       1.1  christos 	  alignaddr = BFD_ALIGN (irelalign->r_offset,
   2542       1.1  christos 				 1 << irelalign->r_addend);
   2543       1.1  christos 	  if (alignaddr < alignto)
   2544       1.1  christos 	    /* Tail recursion.  */
   2545       1.1  christos 	    return mn10300_elf_relax_delete_bytes (abfd, sec, alignaddr,
   2546       1.1  christos 						   (int) (alignto - alignaddr));
   2547       1.1  christos 	}
   2548       1.1  christos     }
   2549  1.1.1.10  christos 
   2550       1.1  christos   return true;
   2551       1.1  christos }
   2552       1.1  christos 
   2553       1.1  christos /* Return TRUE if a symbol exists at the given address, else return
   2554       1.1  christos    FALSE.  */
   2555  1.1.1.10  christos 
   2556       1.1  christos static bool
   2557       1.1  christos mn10300_elf_symbol_address_p (bfd *abfd,
   2558       1.1  christos 			      asection *sec,
   2559       1.1  christos 			      Elf_Internal_Sym *isym,
   2560       1.1  christos 			      bfd_vma addr)
   2561       1.1  christos {
   2562       1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   2563       1.1  christos   unsigned int sec_shndx;
   2564       1.1  christos   Elf_Internal_Sym *isymend;
   2565       1.1  christos   struct elf_link_hash_entry **sym_hashes;
   2566       1.1  christos   struct elf_link_hash_entry **end_hashes;
   2567       1.1  christos   unsigned int symcount;
   2568       1.1  christos 
   2569       1.1  christos   sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
   2570       1.1  christos 
   2571       1.1  christos   /* Examine all the symbols.  */
   2572       1.1  christos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   2573       1.1  christos   for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
   2574       1.1  christos     if (isym->st_shndx == sec_shndx
   2575  1.1.1.10  christos 	&& isym->st_value == addr)
   2576       1.1  christos       return true;
   2577       1.1  christos 
   2578       1.1  christos   symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
   2579       1.1  christos 	      - symtab_hdr->sh_info);
   2580       1.1  christos   sym_hashes = elf_sym_hashes (abfd);
   2581       1.1  christos   end_hashes = sym_hashes + symcount;
   2582       1.1  christos   for (; sym_hashes < end_hashes; sym_hashes++)
   2583       1.1  christos     {
   2584       1.1  christos       struct elf_link_hash_entry *sym_hash = *sym_hashes;
   2585       1.1  christos 
   2586       1.1  christos       if ((sym_hash->root.type == bfd_link_hash_defined
   2587       1.1  christos 	   || sym_hash->root.type == bfd_link_hash_defweak)
   2588       1.1  christos 	  && sym_hash->root.u.def.section == sec
   2589  1.1.1.10  christos 	  && sym_hash->root.u.def.value == addr)
   2590       1.1  christos 	return true;
   2591       1.1  christos     }
   2592  1.1.1.10  christos 
   2593       1.1  christos   return false;
   2594       1.1  christos }
   2595       1.1  christos 
   2596       1.1  christos /* This function handles relaxing for the mn10300.
   2597       1.1  christos 
   2598       1.1  christos    There are quite a few relaxing opportunities available on the mn10300:
   2599   1.1.1.8  christos 
   2600       1.1  christos 	* calls:32 -> calls:16					   2 bytes
   2601       1.1  christos 	* call:32  -> call:16					   2 bytes
   2602       1.1  christos 
   2603       1.1  christos 	* call:32 -> calls:32					   1 byte
   2604       1.1  christos 	* call:16 -> calls:16					   1 byte
   2605       1.1  christos 		* These are done anytime using "calls" would result
   2606       1.1  christos 		in smaller code, or when necessary to preserve the
   2607       1.1  christos 		meaning of the program.
   2608       1.1  christos 
   2609       1.1  christos 	* call:32						   varies
   2610       1.1  christos 	* call:16
   2611       1.1  christos 		* In some circumstances we can move instructions
   2612       1.1  christos 		from a function prologue into a "call" instruction.
   2613       1.1  christos 		This is only done if the resulting code is no larger
   2614       1.1  christos 		than the original code.
   2615       1.1  christos 
   2616       1.1  christos 	* jmp:32 -> jmp:16					   2 bytes
   2617       1.1  christos 	* jmp:16 -> bra:8					   1 byte
   2618       1.1  christos 
   2619       1.1  christos 		* If the previous instruction is a conditional branch
   2620       1.1  christos 		around the jump/bra, we may be able to reverse its condition
   2621       1.1  christos 		and change its target to the jump's target.  The jump/bra
   2622       1.1  christos 		can then be deleted.				   2 bytes
   2623       1.1  christos 
   2624       1.1  christos 	* mov abs32 -> mov abs16				   1 or 2 bytes
   2625       1.1  christos 
   2626       1.1  christos 	* Most instructions which accept imm32 can relax to imm16  1 or 2 bytes
   2627       1.1  christos 	- Most instructions which accept imm16 can relax to imm8   1 or 2 bytes
   2628       1.1  christos 
   2629       1.1  christos 	* Most instructions which accept d32 can relax to d16	   1 or 2 bytes
   2630       1.1  christos 	- Most instructions which accept d16 can relax to d8	   1 or 2 bytes
   2631       1.1  christos 
   2632       1.1  christos 	We don't handle imm16->imm8 or d16->d8 as they're very rare
   2633       1.1  christos 	and somewhat more difficult to support.  */
   2634  1.1.1.10  christos 
   2635       1.1  christos static bool
   2636       1.1  christos mn10300_elf_relax_section (bfd *abfd,
   2637       1.1  christos 			   asection *sec,
   2638  1.1.1.10  christos 			   struct bfd_link_info *link_info,
   2639       1.1  christos 			   bool *again)
   2640       1.1  christos {
   2641       1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   2642       1.1  christos   Elf_Internal_Rela *internal_relocs = NULL;
   2643       1.1  christos   Elf_Internal_Rela *irel, *irelend;
   2644       1.1  christos   bfd_byte *contents = NULL;
   2645       1.1  christos   Elf_Internal_Sym *isymbuf = NULL;
   2646       1.1  christos   struct elf32_mn10300_link_hash_table *hash_table;
   2647       1.1  christos   asection *section = sec;
   2648       1.1  christos   bfd_vma align_gap_adjustment;
   2649   1.1.1.6  christos 
   2650  1.1.1.13  christos   if (bfd_link_relocatable (link_info))
   2651  1.1.1.13  christos     link_info->callbacks->fatal
   2652       1.1  christos       (_("%P: --relax and -r may not be used together\n"));
   2653       1.1  christos 
   2654  1.1.1.10  christos   /* Assume nothing changes.  */
   2655       1.1  christos   *again = false;
   2656       1.1  christos 
   2657       1.1  christos   /* We need a pointer to the mn10300 specific hash table.  */
   2658       1.1  christos   hash_table = elf32_mn10300_hash_table (link_info);
   2659  1.1.1.10  christos   if (hash_table == NULL)
   2660       1.1  christos     return false;
   2661       1.1  christos 
   2662       1.1  christos   /* Initialize fields in each hash table entry the first time through.  */
   2663       1.1  christos   if ((hash_table->flags & MN10300_HASH_ENTRIES_INITIALIZED) == 0)
   2664       1.1  christos     {
   2665       1.1  christos       bfd *input_bfd;
   2666       1.1  christos 
   2667       1.1  christos       /* Iterate over all the input bfds.  */
   2668       1.1  christos       for (input_bfd = link_info->input_bfds;
   2669   1.1.1.4  christos 	   input_bfd != NULL;
   2670       1.1  christos 	   input_bfd = input_bfd->link.next)
   2671       1.1  christos 	{
   2672       1.1  christos 	  /* We're going to need all the symbols for each bfd.  */
   2673       1.1  christos 	  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   2674       1.1  christos 	  if (symtab_hdr->sh_info != 0)
   2675       1.1  christos 	    {
   2676       1.1  christos 	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   2677       1.1  christos 	      if (isymbuf == NULL)
   2678       1.1  christos 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
   2679       1.1  christos 						symtab_hdr->sh_info, 0,
   2680       1.1  christos 						NULL, NULL, NULL);
   2681       1.1  christos 	      if (isymbuf == NULL)
   2682       1.1  christos 		goto error_return;
   2683       1.1  christos 	    }
   2684       1.1  christos 
   2685       1.1  christos 	  /* Iterate over each section in this bfd.  */
   2686       1.1  christos 	  for (section = input_bfd->sections;
   2687       1.1  christos 	       section != NULL;
   2688       1.1  christos 	       section = section->next)
   2689       1.1  christos 	    {
   2690       1.1  christos 	      struct elf32_mn10300_link_hash_entry *hash;
   2691       1.1  christos 	      asection *sym_sec = NULL;
   2692       1.1  christos 	      const char *sym_name;
   2693       1.1  christos 	      char *new_name;
   2694       1.1  christos 
   2695       1.1  christos 	      /* If there's nothing to do in this section, skip it.  */
   2696       1.1  christos 	      if (! ((section->flags & SEC_RELOC) != 0
   2697       1.1  christos 		     && section->reloc_count != 0))
   2698  1.1.1.11  christos 		continue;
   2699  1.1.1.11  christos 	      if ((section->flags & SEC_ALLOC) == 0
   2700       1.1  christos 		  || (section->flags & SEC_HAS_CONTENTS) == 0)
   2701       1.1  christos 		continue;
   2702       1.1  christos 
   2703       1.1  christos 	      /* Get cached copy of section contents if it exists.  */
   2704       1.1  christos 	      if (elf_section_data (section)->this_hdr.contents != NULL)
   2705       1.1  christos 		contents = elf_section_data (section)->this_hdr.contents;
   2706       1.1  christos 	      else if (section->size != 0)
   2707       1.1  christos 		{
   2708       1.1  christos 		  /* Go get them off disk.  */
   2709       1.1  christos 		  if (!bfd_malloc_and_get_section (input_bfd, section,
   2710       1.1  christos 						   &contents))
   2711       1.1  christos 		    goto error_return;
   2712       1.1  christos 		}
   2713       1.1  christos 	      else
   2714       1.1  christos 		contents = NULL;
   2715       1.1  christos 
   2716       1.1  christos 	      /* If there aren't any relocs, then there's nothing to do.  */
   2717       1.1  christos 	      if ((section->flags & SEC_RELOC) != 0
   2718       1.1  christos 		  && section->reloc_count != 0)
   2719       1.1  christos 		{
   2720       1.1  christos 		  /* Get a copy of the native relocations.  */
   2721       1.1  christos 		  internal_relocs = _bfd_elf_link_read_relocs (input_bfd, section,
   2722       1.1  christos 							       NULL, NULL,
   2723       1.1  christos 							       link_info->keep_memory);
   2724       1.1  christos 		  if (internal_relocs == NULL)
   2725       1.1  christos 		    goto error_return;
   2726       1.1  christos 
   2727       1.1  christos 		  /* Now examine each relocation.  */
   2728       1.1  christos 		  irel = internal_relocs;
   2729       1.1  christos 		  irelend = irel + section->reloc_count;
   2730       1.1  christos 		  for (; irel < irelend; irel++)
   2731       1.1  christos 		    {
   2732       1.1  christos 		      long r_type;
   2733       1.1  christos 		      unsigned long r_index;
   2734       1.1  christos 		      unsigned char code;
   2735       1.1  christos 
   2736       1.1  christos 		      r_type = ELF32_R_TYPE (irel->r_info);
   2737       1.1  christos 		      r_index = ELF32_R_SYM (irel->r_info);
   2738       1.1  christos 
   2739       1.1  christos 		      if (r_type < 0 || r_type >= (int) R_MN10300_MAX)
   2740       1.1  christos 			goto error_return;
   2741       1.1  christos 
   2742       1.1  christos 		      /* We need the name and hash table entry of the target
   2743       1.1  christos 			 symbol!  */
   2744       1.1  christos 		      hash = NULL;
   2745       1.1  christos 		      sym_sec = NULL;
   2746       1.1  christos 
   2747       1.1  christos 		      if (r_index < symtab_hdr->sh_info)
   2748       1.1  christos 			{
   2749       1.1  christos 			  /* A local symbol.  */
   2750       1.1  christos 			  Elf_Internal_Sym *isym;
   2751   1.1.1.9  christos 			  struct elf_link_hash_table *elftab;
   2752       1.1  christos 			  size_t amt;
   2753       1.1  christos 
   2754       1.1  christos 			  isym = isymbuf + r_index;
   2755       1.1  christos 			  if (isym->st_shndx == SHN_UNDEF)
   2756       1.1  christos 			    sym_sec = bfd_und_section_ptr;
   2757       1.1  christos 			  else if (isym->st_shndx == SHN_ABS)
   2758       1.1  christos 			    sym_sec = bfd_abs_section_ptr;
   2759       1.1  christos 			  else if (isym->st_shndx == SHN_COMMON)
   2760       1.1  christos 			    sym_sec = bfd_com_section_ptr;
   2761       1.1  christos 			  else
   2762       1.1  christos 			    sym_sec
   2763       1.1  christos 			      = bfd_section_from_elf_index (input_bfd,
   2764       1.1  christos 							    isym->st_shndx);
   2765       1.1  christos 
   2766       1.1  christos 			  sym_name
   2767       1.1  christos 			    = bfd_elf_string_from_elf_section (input_bfd,
   2768       1.1  christos 							       (symtab_hdr
   2769       1.1  christos 								->sh_link),
   2770       1.1  christos 							       isym->st_name);
   2771       1.1  christos 
   2772       1.1  christos 			  /* If it isn't a function, then we don't care
   2773       1.1  christos 			     about it.  */
   2774       1.1  christos 			  if (ELF_ST_TYPE (isym->st_info) != STT_FUNC)
   2775       1.1  christos 			    continue;
   2776       1.1  christos 
   2777       1.1  christos 			  /* Tack on an ID so we can uniquely identify this
   2778       1.1  christos 			     local symbol in the global hash table.  */
   2779       1.1  christos 			  amt = strlen (sym_name) + 10;
   2780       1.1  christos 			  new_name = bfd_malloc (amt);
   2781       1.1  christos 			  if (new_name == NULL)
   2782       1.1  christos 			    goto error_return;
   2783       1.1  christos 
   2784       1.1  christos 			  sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
   2785       1.1  christos 			  sym_name = new_name;
   2786       1.1  christos 
   2787       1.1  christos 			  elftab = &hash_table->static_hash_table->root;
   2788       1.1  christos 			  hash = ((struct elf32_mn10300_link_hash_entry *)
   2789  1.1.1.10  christos 				  elf_link_hash_lookup (elftab, sym_name,
   2790       1.1  christos 							true, true, false));
   2791       1.1  christos 			  free (new_name);
   2792       1.1  christos 			}
   2793       1.1  christos 		      else
   2794       1.1  christos 			{
   2795       1.1  christos 			  r_index -= symtab_hdr->sh_info;
   2796       1.1  christos 			  hash = (struct elf32_mn10300_link_hash_entry *)
   2797       1.1  christos 				   elf_sym_hashes (input_bfd)[r_index];
   2798       1.1  christos 			}
   2799       1.1  christos 
   2800       1.1  christos 		      sym_name = hash->root.root.root.string;
   2801       1.1  christos 		      if ((section->flags & SEC_CODE) != 0)
   2802       1.1  christos 			{
   2803       1.1  christos 			  /* If this is not a "call" instruction, then we
   2804       1.1  christos 			     should convert "call" instructions to "calls"
   2805       1.1  christos 			     instructions.  */
   2806       1.1  christos 			  code = bfd_get_8 (input_bfd,
   2807       1.1  christos 					    contents + irel->r_offset - 1);
   2808       1.1  christos 			  if (code != 0xdd && code != 0xcd)
   2809       1.1  christos 			    hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
   2810       1.1  christos 			}
   2811       1.1  christos 
   2812       1.1  christos 		      /* If this is a jump/call, then bump the
   2813       1.1  christos 			 direct_calls counter.  Else force "call" to
   2814       1.1  christos 			 "calls" conversions.  */
   2815       1.1  christos 		      if (r_type == R_MN10300_PCREL32
   2816       1.1  christos 			  || r_type == R_MN10300_PLT32
   2817       1.1  christos 			  || r_type == R_MN10300_PLT16
   2818       1.1  christos 			  || r_type == R_MN10300_PCREL16)
   2819       1.1  christos 			hash->direct_calls++;
   2820       1.1  christos 		      else
   2821       1.1  christos 			hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
   2822       1.1  christos 		    }
   2823       1.1  christos 		}
   2824       1.1  christos 
   2825       1.1  christos 	      /* Now look at the actual contents to get the stack size,
   2826       1.1  christos 		 and a list of what registers were saved in the prologue
   2827       1.1  christos 		 (ie movm_args).  */
   2828       1.1  christos 	      if ((section->flags & SEC_CODE) != 0)
   2829       1.1  christos 		{
   2830       1.1  christos 		  Elf_Internal_Sym *isym, *isymend;
   2831       1.1  christos 		  unsigned int sec_shndx;
   2832       1.1  christos 		  struct elf_link_hash_entry **hashes;
   2833       1.1  christos 		  struct elf_link_hash_entry **end_hashes;
   2834       1.1  christos 		  unsigned int symcount;
   2835       1.1  christos 
   2836       1.1  christos 		  sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
   2837       1.1  christos 								 section);
   2838       1.1  christos 
   2839       1.1  christos 		  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
   2840       1.1  christos 			      - symtab_hdr->sh_info);
   2841       1.1  christos 		  hashes = elf_sym_hashes (input_bfd);
   2842       1.1  christos 		  end_hashes = hashes + symcount;
   2843       1.1  christos 
   2844       1.1  christos 		  /* Look at each function defined in this section and
   2845       1.1  christos 		     update info for that function.  */
   2846       1.1  christos 		  isymend = isymbuf + symtab_hdr->sh_info;
   2847       1.1  christos 		  for (isym = isymbuf; isym < isymend; isym++)
   2848       1.1  christos 		    {
   2849       1.1  christos 		      if (isym->st_shndx == sec_shndx
   2850       1.1  christos 			  && ELF_ST_TYPE (isym->st_info) == STT_FUNC)
   2851       1.1  christos 			{
   2852   1.1.1.9  christos 			  struct elf_link_hash_table *elftab;
   2853       1.1  christos 			  size_t amt;
   2854       1.1  christos 			  struct elf_link_hash_entry **lhashes = hashes;
   2855       1.1  christos 
   2856       1.1  christos 			  /* Skip a local symbol if it aliases a
   2857       1.1  christos 			     global one.  */
   2858       1.1  christos 			  for (; lhashes < end_hashes; lhashes++)
   2859       1.1  christos 			    {
   2860       1.1  christos 			      hash = (struct elf32_mn10300_link_hash_entry *) *lhashes;
   2861       1.1  christos 			      if ((hash->root.root.type == bfd_link_hash_defined
   2862       1.1  christos 				   || hash->root.root.type == bfd_link_hash_defweak)
   2863       1.1  christos 				  && hash->root.root.u.def.section == section
   2864       1.1  christos 				  && hash->root.type == STT_FUNC
   2865       1.1  christos 				  && hash->root.root.u.def.value == isym->st_value)
   2866       1.1  christos 				break;
   2867       1.1  christos 			    }
   2868       1.1  christos 			  if (lhashes != end_hashes)
   2869       1.1  christos 			    continue;
   2870       1.1  christos 
   2871       1.1  christos 			  if (isym->st_shndx == SHN_UNDEF)
   2872       1.1  christos 			    sym_sec = bfd_und_section_ptr;
   2873       1.1  christos 			  else if (isym->st_shndx == SHN_ABS)
   2874       1.1  christos 			    sym_sec = bfd_abs_section_ptr;
   2875       1.1  christos 			  else if (isym->st_shndx == SHN_COMMON)
   2876       1.1  christos 			    sym_sec = bfd_com_section_ptr;
   2877       1.1  christos 			  else
   2878       1.1  christos 			    sym_sec
   2879       1.1  christos 			      = bfd_section_from_elf_index (input_bfd,
   2880       1.1  christos 							    isym->st_shndx);
   2881       1.1  christos 
   2882       1.1  christos 			  sym_name = (bfd_elf_string_from_elf_section
   2883       1.1  christos 				      (input_bfd, symtab_hdr->sh_link,
   2884       1.1  christos 				       isym->st_name));
   2885       1.1  christos 
   2886       1.1  christos 			  /* Tack on an ID so we can uniquely identify this
   2887       1.1  christos 			     local symbol in the global hash table.  */
   2888       1.1  christos 			  amt = strlen (sym_name) + 10;
   2889       1.1  christos 			  new_name = bfd_malloc (amt);
   2890       1.1  christos 			  if (new_name == NULL)
   2891       1.1  christos 			    goto error_return;
   2892       1.1  christos 
   2893       1.1  christos 			  sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
   2894       1.1  christos 			  sym_name = new_name;
   2895       1.1  christos 
   2896       1.1  christos 			  elftab = &hash_table->static_hash_table->root;
   2897       1.1  christos 			  hash = ((struct elf32_mn10300_link_hash_entry *)
   2898  1.1.1.10  christos 				  elf_link_hash_lookup (elftab, sym_name,
   2899       1.1  christos 							true, true, false));
   2900       1.1  christos 			  free (new_name);
   2901       1.1  christos 			  compute_function_info (input_bfd, hash,
   2902       1.1  christos 						 isym->st_value, contents);
   2903       1.1  christos 			  hash->value = isym->st_value;
   2904       1.1  christos 			}
   2905       1.1  christos 		    }
   2906       1.1  christos 
   2907       1.1  christos 		  for (; hashes < end_hashes; hashes++)
   2908       1.1  christos 		    {
   2909       1.1  christos 		      hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
   2910       1.1  christos 		      if ((hash->root.root.type == bfd_link_hash_defined
   2911       1.1  christos 			   || hash->root.root.type == bfd_link_hash_defweak)
   2912       1.1  christos 			  && hash->root.root.u.def.section == section
   2913       1.1  christos 			  && hash->root.type == STT_FUNC)
   2914       1.1  christos 			compute_function_info (input_bfd, hash,
   2915       1.1  christos 					       (hash)->root.root.u.def.value,
   2916       1.1  christos 					       contents);
   2917       1.1  christos 		    }
   2918       1.1  christos 		}
   2919       1.1  christos 
   2920   1.1.1.9  christos 	      /* Cache or free any memory we allocated for the relocs.  */
   2921       1.1  christos 	      if (elf_section_data (section)->relocs != internal_relocs)
   2922       1.1  christos 		free (internal_relocs);
   2923       1.1  christos 	      internal_relocs = NULL;
   2924       1.1  christos 
   2925       1.1  christos 	      /* Cache or free any memory we allocated for the contents.  */
   2926       1.1  christos 	      if (contents != NULL
   2927       1.1  christos 		  && elf_section_data (section)->this_hdr.contents != contents)
   2928       1.1  christos 		{
   2929       1.1  christos 		  if (! link_info->keep_memory)
   2930       1.1  christos 		    free (contents);
   2931       1.1  christos 		  else
   2932       1.1  christos 		    {
   2933       1.1  christos 		      /* Cache the section contents for elf_link_input_bfd.  */
   2934       1.1  christos 		      elf_section_data (section)->this_hdr.contents = contents;
   2935       1.1  christos 		    }
   2936       1.1  christos 		}
   2937       1.1  christos 	      contents = NULL;
   2938       1.1  christos 	    }
   2939       1.1  christos 
   2940       1.1  christos 	  /* Cache or free any memory we allocated for the symbols.  */
   2941       1.1  christos 	  if (isymbuf != NULL
   2942       1.1  christos 	      && symtab_hdr->contents != (unsigned char *) isymbuf)
   2943       1.1  christos 	    {
   2944       1.1  christos 	      if (! link_info->keep_memory)
   2945       1.1  christos 		free (isymbuf);
   2946       1.1  christos 	      else
   2947       1.1  christos 		{
   2948       1.1  christos 		  /* Cache the symbols for elf_link_input_bfd.  */
   2949       1.1  christos 		  symtab_hdr->contents = (unsigned char *) isymbuf;
   2950       1.1  christos 		}
   2951       1.1  christos 	    }
   2952       1.1  christos 	  isymbuf = NULL;
   2953       1.1  christos 	}
   2954       1.1  christos 
   2955       1.1  christos       /* Now iterate on each symbol in the hash table and perform
   2956       1.1  christos 	 the final initialization steps on each.  */
   2957       1.1  christos       elf32_mn10300_link_hash_traverse (hash_table,
   2958       1.1  christos 					elf32_mn10300_finish_hash_table_entry,
   2959       1.1  christos 					link_info);
   2960       1.1  christos       elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
   2961       1.1  christos 					elf32_mn10300_finish_hash_table_entry,
   2962       1.1  christos 					link_info);
   2963       1.1  christos 
   2964       1.1  christos       {
   2965       1.1  christos 	/* This section of code collects all our local symbols, sorts
   2966       1.1  christos 	   them by value, and looks for multiple symbols referring to
   2967       1.1  christos 	   the same address.  For those symbols, the flags are merged.
   2968       1.1  christos 	   At this point, the only flag that can be set is
   2969       1.1  christos 	   MN10300_CONVERT_CALL_TO_CALLS, so we simply OR the flags
   2970       1.1  christos 	   together.  */
   2971       1.1  christos 	int static_count = 0, i;
   2972       1.1  christos 	struct elf32_mn10300_link_hash_entry **entries;
   2973       1.1  christos 	struct elf32_mn10300_link_hash_entry **ptr;
   2974       1.1  christos 
   2975       1.1  christos 	elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
   2976       1.1  christos 					  elf32_mn10300_count_hash_table_entries,
   2977       1.1  christos 					  &static_count);
   2978       1.1  christos 
   2979       1.1  christos 	entries = bfd_malloc (static_count * sizeof (* ptr));
   2980       1.1  christos 
   2981       1.1  christos 	ptr = entries;
   2982       1.1  christos 	elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
   2983       1.1  christos 					  elf32_mn10300_list_hash_table_entries,
   2984       1.1  christos 					  & ptr);
   2985       1.1  christos 
   2986       1.1  christos 	qsort (entries, static_count, sizeof (entries[0]), sort_by_value);
   2987       1.1  christos 
   2988       1.1  christos 	for (i = 0; i < static_count - 1; i++)
   2989       1.1  christos 	  if (entries[i]->value && entries[i]->value == entries[i+1]->value)
   2990       1.1  christos 	    {
   2991       1.1  christos 	      int v = entries[i]->flags;
   2992       1.1  christos 	      int j;
   2993       1.1  christos 
   2994       1.1  christos 	      for (j = i + 1; j < static_count && entries[j]->value == entries[i]->value; j++)
   2995       1.1  christos 		v |= entries[j]->flags;
   2996       1.1  christos 
   2997       1.1  christos 	      for (j = i; j < static_count && entries[j]->value == entries[i]->value; j++)
   2998       1.1  christos 		entries[j]->flags = v;
   2999       1.1  christos 
   3000       1.1  christos 	      i = j - 1;
   3001       1.1  christos 	    }
   3002       1.1  christos       }
   3003       1.1  christos 
   3004       1.1  christos       /* All entries in the hash table are fully initialized.  */
   3005       1.1  christos       hash_table->flags |= MN10300_HASH_ENTRIES_INITIALIZED;
   3006       1.1  christos 
   3007       1.1  christos       /* Now that everything has been initialized, go through each
   3008       1.1  christos 	 code section and delete any prologue insns which will be
   3009       1.1  christos 	 redundant because their operations will be performed by
   3010       1.1  christos 	 a "call" instruction.  */
   3011       1.1  christos       for (input_bfd = link_info->input_bfds;
   3012   1.1.1.4  christos 	   input_bfd != NULL;
   3013       1.1  christos 	   input_bfd = input_bfd->link.next)
   3014       1.1  christos 	{
   3015       1.1  christos 	  /* We're going to need all the local symbols for each bfd.  */
   3016       1.1  christos 	  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   3017       1.1  christos 	  if (symtab_hdr->sh_info != 0)
   3018       1.1  christos 	    {
   3019       1.1  christos 	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   3020       1.1  christos 	      if (isymbuf == NULL)
   3021       1.1  christos 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
   3022       1.1  christos 						symtab_hdr->sh_info, 0,
   3023       1.1  christos 						NULL, NULL, NULL);
   3024       1.1  christos 	      if (isymbuf == NULL)
   3025       1.1  christos 		goto error_return;
   3026       1.1  christos 	    }
   3027       1.1  christos 
   3028       1.1  christos 	  /* Walk over each section in this bfd.  */
   3029       1.1  christos 	  for (section = input_bfd->sections;
   3030       1.1  christos 	       section != NULL;
   3031       1.1  christos 	       section = section->next)
   3032       1.1  christos 	    {
   3033       1.1  christos 	      unsigned int sec_shndx;
   3034       1.1  christos 	      Elf_Internal_Sym *isym, *isymend;
   3035       1.1  christos 	      struct elf_link_hash_entry **hashes;
   3036       1.1  christos 	      struct elf_link_hash_entry **end_hashes;
   3037       1.1  christos 	      unsigned int symcount;
   3038       1.1  christos 
   3039  1.1.1.11  christos 	      /* Skip non-code sections and empty sections.  */
   3040  1.1.1.11  christos 	      if ((section->flags & SEC_CODE) == 0
   3041  1.1.1.11  christos 		  || (section->flags & SEC_HAS_CONTENTS) == 0
   3042       1.1  christos 		  || section->size == 0)
   3043       1.1  christos 		continue;
   3044       1.1  christos 
   3045       1.1  christos 	      if (section->reloc_count != 0)
   3046       1.1  christos 		{
   3047       1.1  christos 		  /* Get a copy of the native relocations.  */
   3048       1.1  christos 		  internal_relocs = _bfd_elf_link_read_relocs (input_bfd, section,
   3049       1.1  christos 							       NULL, NULL,
   3050       1.1  christos 							       link_info->keep_memory);
   3051       1.1  christos 		  if (internal_relocs == NULL)
   3052       1.1  christos 		    goto error_return;
   3053       1.1  christos 		}
   3054       1.1  christos 
   3055       1.1  christos 	      /* Get cached copy of section contents if it exists.  */
   3056       1.1  christos 	      if (elf_section_data (section)->this_hdr.contents != NULL)
   3057       1.1  christos 		contents = elf_section_data (section)->this_hdr.contents;
   3058       1.1  christos 	      else
   3059       1.1  christos 		{
   3060       1.1  christos 		  /* Go get them off disk.  */
   3061       1.1  christos 		  if (!bfd_malloc_and_get_section (input_bfd, section,
   3062       1.1  christos 						   &contents))
   3063       1.1  christos 		    goto error_return;
   3064       1.1  christos 		}
   3065       1.1  christos 
   3066       1.1  christos 	      sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
   3067       1.1  christos 							     section);
   3068       1.1  christos 
   3069       1.1  christos 	      /* Now look for any function in this section which needs
   3070       1.1  christos 		 insns deleted from its prologue.  */
   3071       1.1  christos 	      isymend = isymbuf + symtab_hdr->sh_info;
   3072       1.1  christos 	      for (isym = isymbuf; isym < isymend; isym++)
   3073       1.1  christos 		{
   3074       1.1  christos 		  struct elf32_mn10300_link_hash_entry *sym_hash;
   3075       1.1  christos 		  asection *sym_sec = NULL;
   3076       1.1  christos 		  const char *sym_name;
   3077       1.1  christos 		  char *new_name;
   3078   1.1.1.9  christos 		  struct elf_link_hash_table *elftab;
   3079       1.1  christos 		  size_t amt;
   3080       1.1  christos 
   3081       1.1  christos 		  if (isym->st_shndx != sec_shndx)
   3082       1.1  christos 		    continue;
   3083       1.1  christos 
   3084       1.1  christos 		  if (isym->st_shndx == SHN_UNDEF)
   3085       1.1  christos 		    sym_sec = bfd_und_section_ptr;
   3086       1.1  christos 		  else if (isym->st_shndx == SHN_ABS)
   3087       1.1  christos 		    sym_sec = bfd_abs_section_ptr;
   3088       1.1  christos 		  else if (isym->st_shndx == SHN_COMMON)
   3089       1.1  christos 		    sym_sec = bfd_com_section_ptr;
   3090       1.1  christos 		  else
   3091       1.1  christos 		    sym_sec
   3092       1.1  christos 		      = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
   3093       1.1  christos 
   3094       1.1  christos 		  sym_name
   3095       1.1  christos 		    = bfd_elf_string_from_elf_section (input_bfd,
   3096       1.1  christos 						       symtab_hdr->sh_link,
   3097       1.1  christos 						       isym->st_name);
   3098       1.1  christos 
   3099       1.1  christos 		  /* Tack on an ID so we can uniquely identify this
   3100       1.1  christos 		     local symbol in the global hash table.  */
   3101       1.1  christos 		  amt = strlen (sym_name) + 10;
   3102       1.1  christos 		  new_name = bfd_malloc (amt);
   3103       1.1  christos 		  if (new_name == NULL)
   3104       1.1  christos 		    goto error_return;
   3105       1.1  christos 		  sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
   3106       1.1  christos 		  sym_name = new_name;
   3107       1.1  christos 
   3108       1.1  christos 		  elftab = & hash_table->static_hash_table->root;
   3109       1.1  christos 		  sym_hash = (struct elf32_mn10300_link_hash_entry *)
   3110  1.1.1.10  christos 		    elf_link_hash_lookup (elftab, sym_name,
   3111       1.1  christos 					  false, false, false);
   3112       1.1  christos 
   3113       1.1  christos 		  free (new_name);
   3114       1.1  christos 		  if (sym_hash == NULL)
   3115       1.1  christos 		    continue;
   3116       1.1  christos 
   3117       1.1  christos 		  if (! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
   3118       1.1  christos 		      && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
   3119       1.1  christos 		    {
   3120       1.1  christos 		      int bytes = 0;
   3121       1.1  christos 
   3122       1.1  christos 		      /* Note that we've changed things.  */
   3123       1.1  christos 		      elf_section_data (section)->relocs = internal_relocs;
   3124       1.1  christos 		      elf_section_data (section)->this_hdr.contents = contents;
   3125       1.1  christos 		      symtab_hdr->contents = (unsigned char *) isymbuf;
   3126       1.1  christos 
   3127       1.1  christos 		      /* Count how many bytes we're going to delete.  */
   3128       1.1  christos 		      if (sym_hash->movm_args)
   3129       1.1  christos 			bytes += 2;
   3130       1.1  christos 
   3131       1.1  christos 		      if (sym_hash->stack_size > 0)
   3132       1.1  christos 			{
   3133       1.1  christos 			  if (sym_hash->stack_size <= 128)
   3134       1.1  christos 			    bytes += 3;
   3135       1.1  christos 			  else
   3136       1.1  christos 			    bytes += 4;
   3137       1.1  christos 			}
   3138       1.1  christos 
   3139       1.1  christos 		      /* Note that we've deleted prologue bytes for this
   3140       1.1  christos 			 function.  */
   3141       1.1  christos 		      sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
   3142       1.1  christos 
   3143       1.1  christos 		      /* Actually delete the bytes.  */
   3144       1.1  christos 		      if (!mn10300_elf_relax_delete_bytes (input_bfd,
   3145       1.1  christos 							   section,
   3146       1.1  christos 							   isym->st_value,
   3147       1.1  christos 							   bytes))
   3148       1.1  christos 			goto error_return;
   3149       1.1  christos 
   3150       1.1  christos 		      /* Something changed.  Not strictly necessary, but
   3151  1.1.1.10  christos 			 may lead to more relaxing opportunities.  */
   3152       1.1  christos 		      *again = true;
   3153       1.1  christos 		    }
   3154       1.1  christos 		}
   3155       1.1  christos 
   3156       1.1  christos 	      /* Look for any global functions in this section which
   3157       1.1  christos 		 need insns deleted from their prologues.  */
   3158       1.1  christos 	      symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
   3159       1.1  christos 			  - symtab_hdr->sh_info);
   3160       1.1  christos 	      hashes = elf_sym_hashes (input_bfd);
   3161       1.1  christos 	      end_hashes = hashes + symcount;
   3162       1.1  christos 	      for (; hashes < end_hashes; hashes++)
   3163       1.1  christos 		{
   3164       1.1  christos 		  struct elf32_mn10300_link_hash_entry *sym_hash;
   3165       1.1  christos 
   3166       1.1  christos 		  sym_hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
   3167       1.1  christos 		  if ((sym_hash->root.root.type == bfd_link_hash_defined
   3168       1.1  christos 		       || sym_hash->root.root.type == bfd_link_hash_defweak)
   3169       1.1  christos 		      && sym_hash->root.root.u.def.section == section
   3170       1.1  christos 		      && ! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
   3171       1.1  christos 		      && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
   3172       1.1  christos 		    {
   3173       1.1  christos 		      int bytes = 0;
   3174   1.1.1.2  christos 		      bfd_vma symval;
   3175       1.1  christos 		      struct elf_link_hash_entry **hh;
   3176       1.1  christos 
   3177       1.1  christos 		      /* Note that we've changed things.  */
   3178       1.1  christos 		      elf_section_data (section)->relocs = internal_relocs;
   3179       1.1  christos 		      elf_section_data (section)->this_hdr.contents = contents;
   3180       1.1  christos 		      symtab_hdr->contents = (unsigned char *) isymbuf;
   3181       1.1  christos 
   3182       1.1  christos 		      /* Count how many bytes we're going to delete.  */
   3183       1.1  christos 		      if (sym_hash->movm_args)
   3184       1.1  christos 			bytes += 2;
   3185       1.1  christos 
   3186       1.1  christos 		      if (sym_hash->stack_size > 0)
   3187       1.1  christos 			{
   3188       1.1  christos 			  if (sym_hash->stack_size <= 128)
   3189       1.1  christos 			    bytes += 3;
   3190       1.1  christos 			  else
   3191       1.1  christos 			    bytes += 4;
   3192       1.1  christos 			}
   3193       1.1  christos 
   3194       1.1  christos 		      /* Note that we've deleted prologue bytes for this
   3195       1.1  christos 			 function.  */
   3196       1.1  christos 		      sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
   3197       1.1  christos 
   3198       1.1  christos 		      /* Actually delete the bytes.  */
   3199       1.1  christos 		      symval = sym_hash->root.root.u.def.value;
   3200       1.1  christos 		      if (!mn10300_elf_relax_delete_bytes (input_bfd,
   3201       1.1  christos 							   section,
   3202       1.1  christos 							   symval,
   3203       1.1  christos 							   bytes))
   3204       1.1  christos 			goto error_return;
   3205   1.1.1.2  christos 
   3206   1.1.1.2  christos 		      /* There may be other C++ functions symbols with the same
   3207   1.1.1.2  christos 			 address.  If so then mark these as having had their
   3208   1.1.1.2  christos 			 prologue bytes deleted as well.  */
   3209   1.1.1.2  christos 		      for (hh = elf_sym_hashes (input_bfd); hh < end_hashes; hh++)
   3210   1.1.1.2  christos 			{
   3211   1.1.1.2  christos 			  struct elf32_mn10300_link_hash_entry *h;
   3212   1.1.1.2  christos 
   3213   1.1.1.2  christos 			  h = (struct elf32_mn10300_link_hash_entry *) * hh;
   3214   1.1.1.2  christos 
   3215   1.1.1.2  christos 			  if (h != sym_hash
   3216   1.1.1.2  christos 			      && (h->root.root.type == bfd_link_hash_defined
   3217   1.1.1.2  christos 				  || h->root.root.type == bfd_link_hash_defweak)
   3218   1.1.1.2  christos 			      && h->root.root.u.def.section == section
   3219   1.1.1.2  christos 			      && ! (h->flags & MN10300_CONVERT_CALL_TO_CALLS)
   3220   1.1.1.2  christos 			      && h->root.root.u.def.value == symval
   3221   1.1.1.2  christos 			      && h->root.type == STT_FUNC)
   3222   1.1.1.2  christos 			    h->flags |= MN10300_DELETED_PROLOGUE_BYTES;
   3223   1.1.1.2  christos 			}
   3224       1.1  christos 
   3225       1.1  christos 		      /* Something changed.  Not strictly necessary, but
   3226  1.1.1.10  christos 			 may lead to more relaxing opportunities.  */
   3227       1.1  christos 		      *again = true;
   3228       1.1  christos 		    }
   3229       1.1  christos 		}
   3230       1.1  christos 
   3231   1.1.1.9  christos 	      /* Cache or free any memory we allocated for the relocs.  */
   3232       1.1  christos 	      if (elf_section_data (section)->relocs != internal_relocs)
   3233       1.1  christos 		free (internal_relocs);
   3234       1.1  christos 	      internal_relocs = NULL;
   3235       1.1  christos 
   3236       1.1  christos 	      /* Cache or free any memory we allocated for the contents.  */
   3237       1.1  christos 	      if (contents != NULL
   3238       1.1  christos 		  && elf_section_data (section)->this_hdr.contents != contents)
   3239       1.1  christos 		{
   3240       1.1  christos 		  if (! link_info->keep_memory)
   3241       1.1  christos 		    free (contents);
   3242       1.1  christos 		  else
   3243       1.1  christos 		    /* Cache the section contents for elf_link_input_bfd.  */
   3244       1.1  christos 		    elf_section_data (section)->this_hdr.contents = contents;
   3245       1.1  christos 		}
   3246       1.1  christos 	      contents = NULL;
   3247       1.1  christos 	    }
   3248       1.1  christos 
   3249       1.1  christos 	  /* Cache or free any memory we allocated for the symbols.  */
   3250       1.1  christos 	  if (isymbuf != NULL
   3251       1.1  christos 	      && symtab_hdr->contents != (unsigned char *) isymbuf)
   3252       1.1  christos 	    {
   3253       1.1  christos 	      if (! link_info->keep_memory)
   3254       1.1  christos 		free (isymbuf);
   3255       1.1  christos 	      else
   3256       1.1  christos 		/* Cache the symbols for elf_link_input_bfd.  */
   3257       1.1  christos 		symtab_hdr->contents = (unsigned char *) isymbuf;
   3258       1.1  christos 	    }
   3259       1.1  christos 	  isymbuf = NULL;
   3260       1.1  christos 	}
   3261       1.1  christos     }
   3262       1.1  christos 
   3263       1.1  christos   /* (Re)initialize for the basic instruction shortening/relaxing pass.  */
   3264       1.1  christos   contents = NULL;
   3265       1.1  christos   internal_relocs = NULL;
   3266       1.1  christos   isymbuf = NULL;
   3267       1.1  christos   /* For error_return.  */
   3268       1.1  christos   section = sec;
   3269       1.1  christos 
   3270       1.1  christos   /* We don't have to do anything for a relocatable link, if
   3271       1.1  christos      this section does not have relocs, or if this is not a
   3272   1.1.1.6  christos      code section.  */
   3273       1.1  christos   if (bfd_link_relocatable (link_info)
   3274       1.1  christos       || (sec->flags & SEC_RELOC) == 0
   3275       1.1  christos       || sec->reloc_count == 0
   3276  1.1.1.10  christos       || (sec->flags & SEC_CODE) == 0)
   3277       1.1  christos     return true;
   3278       1.1  christos 
   3279       1.1  christos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   3280       1.1  christos 
   3281       1.1  christos   /* Get a copy of the native relocations.  */
   3282       1.1  christos   internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL,
   3283       1.1  christos 					       link_info->keep_memory);
   3284       1.1  christos   if (internal_relocs == NULL)
   3285       1.1  christos     goto error_return;
   3286       1.1  christos 
   3287       1.1  christos   /* Scan for worst case alignment gap changes.  Note that this logic
   3288       1.1  christos      is not ideal; what we should do is run this scan for every
   3289       1.1  christos      opcode/address range and adjust accordingly, but that's
   3290       1.1  christos      expensive.  Worst case is that for an alignment of N bytes, we
   3291       1.1  christos      move by 2*N-N-1 bytes, assuming we have aligns of 1, 2, 4, 8, etc
   3292       1.1  christos      all before it.  Plus, this still doesn't cover cross-section
   3293       1.1  christos      jumps with section alignment.  */
   3294       1.1  christos   irelend = internal_relocs + sec->reloc_count;
   3295       1.1  christos   align_gap_adjustment = 0;
   3296       1.1  christos   for (irel = internal_relocs; irel < irelend; irel++)
   3297       1.1  christos     {
   3298       1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN)
   3299       1.1  christos 	{
   3300       1.1  christos 	  bfd_vma adj = 1 << irel->r_addend;
   3301       1.1  christos 	  bfd_vma aend = irel->r_offset;
   3302       1.1  christos 
   3303       1.1  christos 	  aend = BFD_ALIGN (aend, 1 << irel->r_addend);
   3304       1.1  christos 	  adj = 2 * adj - adj - 1;
   3305       1.1  christos 
   3306       1.1  christos 	  /* Record the biggest adjustmnet.  Skip any alignment at the
   3307       1.1  christos 	     end of our section.  */
   3308       1.1  christos 	  if (align_gap_adjustment < adj
   3309       1.1  christos 	      && aend < sec->output_section->vma + sec->output_offset + sec->size)
   3310       1.1  christos 	    align_gap_adjustment = adj;
   3311       1.1  christos 	}
   3312       1.1  christos     }
   3313       1.1  christos 
   3314       1.1  christos   /* Walk through them looking for relaxing opportunities.  */
   3315       1.1  christos   irelend = internal_relocs + sec->reloc_count;
   3316       1.1  christos   for (irel = internal_relocs; irel < irelend; irel++)
   3317       1.1  christos     {
   3318       1.1  christos       bfd_vma symval;
   3319       1.1  christos       bfd_signed_vma jump_offset;
   3320       1.1  christos       asection *sym_sec = NULL;
   3321       1.1  christos       struct elf32_mn10300_link_hash_entry *h = NULL;
   3322       1.1  christos 
   3323       1.1  christos       /* If this isn't something that can be relaxed, then ignore
   3324       1.1  christos 	 this reloc.  */
   3325       1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_NONE
   3326       1.1  christos 	  || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_8
   3327       1.1  christos 	  || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_MAX)
   3328       1.1  christos 	continue;
   3329       1.1  christos 
   3330       1.1  christos       /* Get the section contents if we haven't done so already.  */
   3331       1.1  christos       if (contents == NULL)
   3332       1.1  christos 	{
   3333       1.1  christos 	  /* Get cached copy if it exists.  */
   3334       1.1  christos 	  if (elf_section_data (sec)->this_hdr.contents != NULL)
   3335       1.1  christos 	    contents = elf_section_data (sec)->this_hdr.contents;
   3336       1.1  christos 	  else
   3337       1.1  christos 	    {
   3338       1.1  christos 	      /* Go get them off disk.  */
   3339       1.1  christos 	      if (!bfd_malloc_and_get_section (abfd, sec, &contents))
   3340       1.1  christos 		goto error_return;
   3341       1.1  christos 	    }
   3342       1.1  christos 	}
   3343       1.1  christos 
   3344       1.1  christos       /* Read this BFD's symbols if we haven't done so already.  */
   3345       1.1  christos       if (isymbuf == NULL && symtab_hdr->sh_info != 0)
   3346       1.1  christos 	{
   3347       1.1  christos 	  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   3348       1.1  christos 	  if (isymbuf == NULL)
   3349       1.1  christos 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
   3350       1.1  christos 					    symtab_hdr->sh_info, 0,
   3351       1.1  christos 					    NULL, NULL, NULL);
   3352       1.1  christos 	  if (isymbuf == NULL)
   3353       1.1  christos 	    goto error_return;
   3354       1.1  christos 	}
   3355       1.1  christos 
   3356       1.1  christos       /* Get the value of the symbol referred to by the reloc.  */
   3357       1.1  christos       if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
   3358       1.1  christos 	{
   3359       1.1  christos 	  Elf_Internal_Sym *isym;
   3360       1.1  christos 	  const char *sym_name;
   3361       1.1  christos 	  char *new_name;
   3362       1.1  christos 
   3363       1.1  christos 	  /* A local symbol.  */
   3364       1.1  christos 	  isym = isymbuf + ELF32_R_SYM (irel->r_info);
   3365       1.1  christos 	  if (isym->st_shndx == SHN_UNDEF)
   3366       1.1  christos 	    sym_sec = bfd_und_section_ptr;
   3367       1.1  christos 	  else if (isym->st_shndx == SHN_ABS)
   3368       1.1  christos 	    sym_sec = bfd_abs_section_ptr;
   3369       1.1  christos 	  else if (isym->st_shndx == SHN_COMMON)
   3370       1.1  christos 	    sym_sec = bfd_com_section_ptr;
   3371       1.1  christos 	  else
   3372       1.1  christos 	    sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
   3373       1.1  christos 
   3374       1.1  christos 	  sym_name = bfd_elf_string_from_elf_section (abfd,
   3375       1.1  christos 						      symtab_hdr->sh_link,
   3376       1.1  christos 						      isym->st_name);
   3377       1.1  christos 
   3378   1.1.1.2  christos 	  if ((sym_sec->flags & SEC_MERGE)
   3379       1.1  christos 	      && sym_sec->sec_info_type == SEC_INFO_TYPE_MERGE)
   3380       1.1  christos 	    {
   3381       1.1  christos 	      symval = isym->st_value;
   3382       1.1  christos 
   3383       1.1  christos 	      /* GAS may reduce relocations against symbols in SEC_MERGE
   3384       1.1  christos 		 sections to a relocation against the section symbol when
   3385       1.1  christos 		 the original addend was zero.  When the reloc is against
   3386       1.1  christos 		 a section symbol we should include the addend in the
   3387       1.1  christos 		 offset passed to _bfd_merged_section_offset, since the
   3388       1.1  christos 		 location of interest is the original symbol.  On the
   3389       1.1  christos 		 other hand, an access to "sym+addend" where "sym" is not
   3390       1.1  christos 		 a section symbol should not include the addend;  Such an
   3391       1.1  christos 		 access is presumed to be an offset from "sym";  The
   3392       1.1  christos 		 location of interest is just "sym".  */
   3393       1.1  christos 	      if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
   3394       1.1  christos 		symval += irel->r_addend;
   3395       1.1  christos 
   3396       1.1  christos 	      symval = _bfd_merged_section_offset (abfd, & sym_sec,
   3397       1.1  christos 						   elf_section_data (sym_sec)->sec_info,
   3398       1.1  christos 						   symval);
   3399       1.1  christos 
   3400       1.1  christos 	      if (ELF_ST_TYPE (isym->st_info) != STT_SECTION)
   3401       1.1  christos 		symval += irel->r_addend;
   3402       1.1  christos 
   3403       1.1  christos 	      symval += sym_sec->output_section->vma
   3404       1.1  christos 		+ sym_sec->output_offset - irel->r_addend;
   3405       1.1  christos 	    }
   3406       1.1  christos 	  else
   3407       1.1  christos 	    symval = (isym->st_value
   3408       1.1  christos 		      + sym_sec->output_section->vma
   3409       1.1  christos 		      + sym_sec->output_offset);
   3410       1.1  christos 
   3411       1.1  christos 	  /* Tack on an ID so we can uniquely identify this
   3412       1.1  christos 	     local symbol in the global hash table.  */
   3413       1.1  christos 	  new_name = bfd_malloc ((bfd_size_type) strlen (sym_name) + 10);
   3414       1.1  christos 	  if (new_name == NULL)
   3415       1.1  christos 	    goto error_return;
   3416       1.1  christos 	  sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
   3417       1.1  christos 	  sym_name = new_name;
   3418       1.1  christos 
   3419       1.1  christos 	  h = (struct elf32_mn10300_link_hash_entry *)
   3420  1.1.1.10  christos 		elf_link_hash_lookup (&hash_table->static_hash_table->root,
   3421       1.1  christos 				      sym_name, false, false, false);
   3422       1.1  christos 	  free (new_name);
   3423       1.1  christos 	}
   3424       1.1  christos       else
   3425       1.1  christos 	{
   3426       1.1  christos 	  unsigned long indx;
   3427       1.1  christos 
   3428       1.1  christos 	  /* An external symbol.  */
   3429       1.1  christos 	  indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
   3430       1.1  christos 	  h = (struct elf32_mn10300_link_hash_entry *)
   3431       1.1  christos 		(elf_sym_hashes (abfd)[indx]);
   3432       1.1  christos 	  BFD_ASSERT (h != NULL);
   3433       1.1  christos 	  if (h->root.root.type != bfd_link_hash_defined
   3434       1.1  christos 	      && h->root.root.type != bfd_link_hash_defweak)
   3435       1.1  christos 	    /* This appears to be a reference to an undefined
   3436       1.1  christos 	       symbol.  Just ignore it--it will be caught by the
   3437       1.1  christos 	       regular reloc processing.  */
   3438       1.1  christos 	    continue;
   3439       1.1  christos 
   3440       1.1  christos 	  /* Check for a reference to a discarded symbol and ignore it.  */
   3441       1.1  christos 	  if (h->root.root.u.def.section->output_section == NULL)
   3442       1.1  christos 	    continue;
   3443       1.1  christos 
   3444       1.1  christos 	  sym_sec = h->root.root.u.def.section->output_section;
   3445       1.1  christos 
   3446       1.1  christos 	  symval = (h->root.root.u.def.value
   3447       1.1  christos 		    + h->root.root.u.def.section->output_section->vma
   3448       1.1  christos 		    + h->root.root.u.def.section->output_offset);
   3449       1.1  christos 	}
   3450       1.1  christos 
   3451       1.1  christos       /* For simplicity of coding, we are going to modify the section
   3452       1.1  christos 	 contents, the section relocs, and the BFD symbol table.  We
   3453       1.1  christos 	 must tell the rest of the code not to free up this
   3454       1.1  christos 	 information.  It would be possible to instead create a table
   3455       1.1  christos 	 of changes which have to be made, as is done in coff-mips.c;
   3456       1.1  christos 	 that would be more work, but would require less memory when
   3457       1.1  christos 	 the linker is run.  */
   3458       1.1  christos 
   3459       1.1  christos       /* Try to turn a 32bit pc-relative branch/call into a 16bit pc-relative
   3460       1.1  christos 	 branch/call, also deal with "call" -> "calls" conversions and
   3461       1.1  christos 	 insertion of prologue data into "call" instructions.  */
   3462       1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL32
   3463       1.1  christos 	  || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32)
   3464       1.1  christos 	{
   3465       1.1  christos 	  bfd_vma value = symval;
   3466       1.1  christos 
   3467       1.1  christos 	  if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32
   3468       1.1  christos 	      && h != NULL
   3469       1.1  christos 	      && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
   3470       1.1  christos 	      && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
   3471       1.1  christos 	      && h->root.plt.offset != (bfd_vma) -1)
   3472       1.1  christos 	    {
   3473       1.1  christos 	      asection * splt;
   3474   1.1.1.2  christos 
   3475       1.1  christos 	      splt = hash_table->root.splt;
   3476       1.1  christos 	      value = ((splt->output_section->vma
   3477       1.1  christos 			+ splt->output_offset
   3478       1.1  christos 			+ h->root.plt.offset)
   3479       1.1  christos 		       - (sec->output_section->vma
   3480       1.1  christos 			  + sec->output_offset
   3481       1.1  christos 			  + irel->r_offset));
   3482       1.1  christos 	    }
   3483       1.1  christos 
   3484       1.1  christos 	  /* If we've got a "call" instruction that needs to be turned
   3485       1.1  christos 	     into a "calls" instruction, do so now.  It saves a byte.  */
   3486       1.1  christos 	  if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
   3487       1.1  christos 	    {
   3488       1.1  christos 	      unsigned char code;
   3489       1.1  christos 
   3490       1.1  christos 	      /* Get the opcode.  */
   3491       1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3492       1.1  christos 
   3493       1.1  christos 	      /* Make sure we're working with a "call" instruction!  */
   3494       1.1  christos 	      if (code == 0xdd)
   3495       1.1  christos 		{
   3496       1.1  christos 		  /* Note that we've changed the relocs, section contents,
   3497       1.1  christos 		     etc.  */
   3498       1.1  christos 		  elf_section_data (sec)->relocs = internal_relocs;
   3499       1.1  christos 		  elf_section_data (sec)->this_hdr.contents = contents;
   3500       1.1  christos 		  symtab_hdr->contents = (unsigned char *) isymbuf;
   3501       1.1  christos 
   3502       1.1  christos 		  /* Fix the opcode.  */
   3503       1.1  christos 		  bfd_put_8 (abfd, 0xfc, contents + irel->r_offset - 1);
   3504       1.1  christos 		  bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
   3505       1.1  christos 
   3506       1.1  christos 		  /* Fix irel->r_offset and irel->r_addend.  */
   3507       1.1  christos 		  irel->r_offset += 1;
   3508       1.1  christos 		  irel->r_addend += 1;
   3509       1.1  christos 
   3510       1.1  christos 		  /* Delete one byte of data.  */
   3511       1.1  christos 		  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3512       1.1  christos 						       irel->r_offset + 3, 1))
   3513       1.1  christos 		    goto error_return;
   3514       1.1  christos 
   3515       1.1  christos 		  /* That will change things, so, we should relax again.
   3516  1.1.1.10  christos 		     Note that this is not required, and it may be slow.  */
   3517       1.1  christos 		  *again = true;
   3518       1.1  christos 		}
   3519       1.1  christos 	    }
   3520       1.1  christos 	  else if (h)
   3521       1.1  christos 	    {
   3522       1.1  christos 	      /* We've got a "call" instruction which needs some data
   3523       1.1  christos 		 from target function filled in.  */
   3524       1.1  christos 	      unsigned char code;
   3525       1.1  christos 
   3526       1.1  christos 	      /* Get the opcode.  */
   3527       1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3528       1.1  christos 
   3529       1.1  christos 	      /* Insert data from the target function into the "call"
   3530       1.1  christos 		 instruction if needed.  */
   3531       1.1  christos 	      if (code == 0xdd)
   3532       1.1  christos 		{
   3533       1.1  christos 		  bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 4);
   3534       1.1  christos 		  bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
   3535       1.1  christos 			     contents + irel->r_offset + 5);
   3536       1.1  christos 		}
   3537       1.1  christos 	    }
   3538       1.1  christos 
   3539       1.1  christos 	  /* Deal with pc-relative gunk.  */
   3540       1.1  christos 	  value -= (sec->output_section->vma + sec->output_offset);
   3541       1.1  christos 	  value -= irel->r_offset;
   3542       1.1  christos 	  value += irel->r_addend;
   3543       1.1  christos 
   3544       1.1  christos 	  /* See if the value will fit in 16 bits, note the high value is
   3545       1.1  christos 	     0x7fff + 2 as the target will be two bytes closer if we are
   3546       1.1  christos 	     able to relax, if it's in the same section.  */
   3547       1.1  christos 	  if (sec->output_section == sym_sec->output_section)
   3548       1.1  christos 	    jump_offset = 0x8001;
   3549       1.1  christos 	  else
   3550       1.1  christos 	    jump_offset = 0x7fff;
   3551       1.1  christos 
   3552       1.1  christos 	  /* Account for jumps across alignment boundaries using
   3553       1.1  christos 	     align_gap_adjustment.  */
   3554       1.1  christos 	  if ((bfd_signed_vma) value < jump_offset - (bfd_signed_vma) align_gap_adjustment
   3555       1.1  christos 	      && ((bfd_signed_vma) value > -0x8000 + (bfd_signed_vma) align_gap_adjustment))
   3556       1.1  christos 	    {
   3557       1.1  christos 	      unsigned char code;
   3558       1.1  christos 
   3559       1.1  christos 	      /* Get the opcode.  */
   3560       1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3561       1.1  christos 
   3562       1.1  christos 	      if (code != 0xdc && code != 0xdd && code != 0xff)
   3563       1.1  christos 		continue;
   3564       1.1  christos 
   3565       1.1  christos 	      /* Note that we've changed the relocs, section contents, etc.  */
   3566       1.1  christos 	      elf_section_data (sec)->relocs = internal_relocs;
   3567       1.1  christos 	      elf_section_data (sec)->this_hdr.contents = contents;
   3568       1.1  christos 	      symtab_hdr->contents = (unsigned char *) isymbuf;
   3569       1.1  christos 
   3570       1.1  christos 	      /* Fix the opcode.  */
   3571       1.1  christos 	      if (code == 0xdc)
   3572       1.1  christos 		bfd_put_8 (abfd, 0xcc, contents + irel->r_offset - 1);
   3573       1.1  christos 	      else if (code == 0xdd)
   3574       1.1  christos 		bfd_put_8 (abfd, 0xcd, contents + irel->r_offset - 1);
   3575       1.1  christos 	      else if (code == 0xff)
   3576       1.1  christos 		bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
   3577       1.1  christos 
   3578       1.1  christos 	      /* Fix the relocation's type.  */
   3579       1.1  christos 	      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   3580       1.1  christos 					   (ELF32_R_TYPE (irel->r_info)
   3581       1.1  christos 					    == (int) R_MN10300_PLT32)
   3582       1.1  christos 					   ? R_MN10300_PLT16 :
   3583       1.1  christos 					   R_MN10300_PCREL16);
   3584       1.1  christos 
   3585       1.1  christos 	      /* Delete two bytes of data.  */
   3586       1.1  christos 	      if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3587       1.1  christos 						   irel->r_offset + 1, 2))
   3588       1.1  christos 		goto error_return;
   3589       1.1  christos 
   3590       1.1  christos 	      /* That will change things, so, we should relax again.
   3591  1.1.1.10  christos 		 Note that this is not required, and it may be slow.  */
   3592       1.1  christos 	      *again = true;
   3593       1.1  christos 	    }
   3594       1.1  christos 	}
   3595       1.1  christos 
   3596       1.1  christos       /* Try to turn a 16bit pc-relative branch into a 8bit pc-relative
   3597       1.1  christos 	 branch.  */
   3598       1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL16)
   3599       1.1  christos 	{
   3600       1.1  christos 	  bfd_vma value = symval;
   3601       1.1  christos 
   3602       1.1  christos 	  /* If we've got a "call" instruction that needs to be turned
   3603       1.1  christos 	     into a "calls" instruction, do so now.  It saves a byte.  */
   3604       1.1  christos 	  if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
   3605       1.1  christos 	    {
   3606       1.1  christos 	      unsigned char code;
   3607       1.1  christos 
   3608       1.1  christos 	      /* Get the opcode.  */
   3609       1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3610       1.1  christos 
   3611       1.1  christos 	      /* Make sure we're working with a "call" instruction!  */
   3612       1.1  christos 	      if (code == 0xcd)
   3613       1.1  christos 		{
   3614       1.1  christos 		  /* Note that we've changed the relocs, section contents,
   3615       1.1  christos 		     etc.  */
   3616       1.1  christos 		  elf_section_data (sec)->relocs = internal_relocs;
   3617       1.1  christos 		  elf_section_data (sec)->this_hdr.contents = contents;
   3618       1.1  christos 		  symtab_hdr->contents = (unsigned char *) isymbuf;
   3619       1.1  christos 
   3620       1.1  christos 		  /* Fix the opcode.  */
   3621       1.1  christos 		  bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 1);
   3622       1.1  christos 		  bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
   3623       1.1  christos 
   3624       1.1  christos 		  /* Fix irel->r_offset and irel->r_addend.  */
   3625       1.1  christos 		  irel->r_offset += 1;
   3626       1.1  christos 		  irel->r_addend += 1;
   3627       1.1  christos 
   3628       1.1  christos 		  /* Delete one byte of data.  */
   3629       1.1  christos 		  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3630       1.1  christos 						       irel->r_offset + 1, 1))
   3631       1.1  christos 		    goto error_return;
   3632       1.1  christos 
   3633       1.1  christos 		  /* That will change things, so, we should relax again.
   3634  1.1.1.10  christos 		     Note that this is not required, and it may be slow.  */
   3635       1.1  christos 		  *again = true;
   3636       1.1  christos 		}
   3637       1.1  christos 	    }
   3638       1.1  christos 	  else if (h)
   3639       1.1  christos 	    {
   3640       1.1  christos 	      unsigned char code;
   3641       1.1  christos 
   3642       1.1  christos 	      /* Get the opcode.  */
   3643       1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3644       1.1  christos 
   3645       1.1  christos 	      /* Insert data from the target function into the "call"
   3646       1.1  christos 		 instruction if needed.  */
   3647       1.1  christos 	      if (code == 0xcd)
   3648       1.1  christos 		{
   3649       1.1  christos 		  bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 2);
   3650       1.1  christos 		  bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
   3651       1.1  christos 			     contents + irel->r_offset + 3);
   3652       1.1  christos 		}
   3653       1.1  christos 	    }
   3654       1.1  christos 
   3655       1.1  christos 	  /* Deal with pc-relative gunk.  */
   3656       1.1  christos 	  value -= (sec->output_section->vma + sec->output_offset);
   3657       1.1  christos 	  value -= irel->r_offset;
   3658       1.1  christos 	  value += irel->r_addend;
   3659       1.1  christos 
   3660       1.1  christos 	  /* See if the value will fit in 8 bits, note the high value is
   3661       1.1  christos 	     0x7f + 1 as the target will be one bytes closer if we are
   3662       1.1  christos 	     able to relax.  */
   3663       1.1  christos 	  if ((long) value < 0x80 && (long) value > -0x80)
   3664       1.1  christos 	    {
   3665       1.1  christos 	      unsigned char code;
   3666       1.1  christos 
   3667       1.1  christos 	      /* Get the opcode.  */
   3668       1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3669       1.1  christos 
   3670       1.1  christos 	      if (code != 0xcc)
   3671       1.1  christos 		continue;
   3672       1.1  christos 
   3673       1.1  christos 	      /* Note that we've changed the relocs, section contents, etc.  */
   3674       1.1  christos 	      elf_section_data (sec)->relocs = internal_relocs;
   3675       1.1  christos 	      elf_section_data (sec)->this_hdr.contents = contents;
   3676       1.1  christos 	      symtab_hdr->contents = (unsigned char *) isymbuf;
   3677       1.1  christos 
   3678       1.1  christos 	      /* Fix the opcode.  */
   3679       1.1  christos 	      bfd_put_8 (abfd, 0xca, contents + irel->r_offset - 1);
   3680       1.1  christos 
   3681       1.1  christos 	      /* Fix the relocation's type.  */
   3682       1.1  christos 	      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   3683       1.1  christos 					   R_MN10300_PCREL8);
   3684       1.1  christos 
   3685       1.1  christos 	      /* Delete one byte of data.  */
   3686       1.1  christos 	      if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3687       1.1  christos 						   irel->r_offset + 1, 1))
   3688       1.1  christos 		goto error_return;
   3689       1.1  christos 
   3690       1.1  christos 	      /* That will change things, so, we should relax again.
   3691  1.1.1.10  christos 		 Note that this is not required, and it may be slow.  */
   3692       1.1  christos 	      *again = true;
   3693       1.1  christos 	    }
   3694       1.1  christos 	}
   3695       1.1  christos 
   3696       1.1  christos       /* Try to eliminate an unconditional 8 bit pc-relative branch
   3697       1.1  christos 	 which immediately follows a conditional 8 bit pc-relative
   3698       1.1  christos 	 branch around the unconditional branch.
   3699       1.1  christos 
   3700       1.1  christos 	    original:		new:
   3701       1.1  christos 	    bCC lab1		bCC' lab2
   3702       1.1  christos 	    bra lab2
   3703       1.1  christos 	   lab1:	       lab1:
   3704       1.1  christos 
   3705       1.1  christos 	 This happens when the bCC can't reach lab2 at assembly time,
   3706       1.1  christos 	 but due to other relaxations it can reach at link time.  */
   3707       1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL8)
   3708       1.1  christos 	{
   3709       1.1  christos 	  Elf_Internal_Rela *nrel;
   3710       1.1  christos 	  unsigned char code;
   3711       1.1  christos 
   3712       1.1  christos 	  /* Do nothing if this reloc is the last byte in the section.  */
   3713       1.1  christos 	  if (irel->r_offset == sec->size)
   3714       1.1  christos 	    continue;
   3715       1.1  christos 
   3716       1.1  christos 	  /* See if the next instruction is an unconditional pc-relative
   3717       1.1  christos 	     branch, more often than not this test will fail, so we
   3718       1.1  christos 	     test it first to speed things up.  */
   3719       1.1  christos 	  code = bfd_get_8 (abfd, contents + irel->r_offset + 1);
   3720       1.1  christos 	  if (code != 0xca)
   3721       1.1  christos 	    continue;
   3722       1.1  christos 
   3723       1.1  christos 	  /* Also make sure the next relocation applies to the next
   3724       1.1  christos 	     instruction and that it's a pc-relative 8 bit branch.  */
   3725       1.1  christos 	  nrel = irel + 1;
   3726       1.1  christos 	  if (nrel == irelend
   3727       1.1  christos 	      || irel->r_offset + 2 != nrel->r_offset
   3728       1.1  christos 	      || ELF32_R_TYPE (nrel->r_info) != (int) R_MN10300_PCREL8)
   3729       1.1  christos 	    continue;
   3730       1.1  christos 
   3731       1.1  christos 	  /* Make sure our destination immediately follows the
   3732       1.1  christos 	     unconditional branch.  */
   3733       1.1  christos 	  if (symval != (sec->output_section->vma + sec->output_offset
   3734       1.1  christos 			 + irel->r_offset + 3))
   3735       1.1  christos 	    continue;
   3736       1.1  christos 
   3737       1.1  christos 	  /* Now make sure we are a conditional branch.  This may not
   3738       1.1  christos 	     be necessary, but why take the chance.
   3739       1.1  christos 
   3740       1.1  christos 	     Note these checks assume that R_MN10300_PCREL8 relocs
   3741       1.1  christos 	     only occur on bCC and bCCx insns.  If they occured
   3742       1.1  christos 	     elsewhere, we'd need to know the start of this insn
   3743       1.1  christos 	     for this check to be accurate.  */
   3744       1.1  christos 	  code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   3745       1.1  christos 	  if (code != 0xc0 && code != 0xc1 && code != 0xc2
   3746       1.1  christos 	      && code != 0xc3 && code != 0xc4 && code != 0xc5
   3747       1.1  christos 	      && code != 0xc6 && code != 0xc7 && code != 0xc8
   3748       1.1  christos 	      && code != 0xc9 && code != 0xe8 && code != 0xe9
   3749       1.1  christos 	      && code != 0xea && code != 0xeb)
   3750       1.1  christos 	    continue;
   3751       1.1  christos 
   3752       1.1  christos 	  /* We also have to be sure there is no symbol/label
   3753       1.1  christos 	     at the unconditional branch.  */
   3754       1.1  christos 	  if (mn10300_elf_symbol_address_p (abfd, sec, isymbuf,
   3755       1.1  christos 					    irel->r_offset + 1))
   3756       1.1  christos 	    continue;
   3757       1.1  christos 
   3758       1.1  christos 	  /* Note that we've changed the relocs, section contents, etc.  */
   3759       1.1  christos 	  elf_section_data (sec)->relocs = internal_relocs;
   3760       1.1  christos 	  elf_section_data (sec)->this_hdr.contents = contents;
   3761       1.1  christos 	  symtab_hdr->contents = (unsigned char *) isymbuf;
   3762       1.1  christos 
   3763       1.1  christos 	  /* Reverse the condition of the first branch.  */
   3764       1.1  christos 	  switch (code)
   3765       1.1  christos 	    {
   3766       1.1  christos 	    case 0xc8:
   3767       1.1  christos 	      code = 0xc9;
   3768       1.1  christos 	      break;
   3769       1.1  christos 	    case 0xc9:
   3770       1.1  christos 	      code = 0xc8;
   3771       1.1  christos 	      break;
   3772       1.1  christos 	    case 0xc0:
   3773       1.1  christos 	      code = 0xc2;
   3774       1.1  christos 	      break;
   3775       1.1  christos 	    case 0xc2:
   3776       1.1  christos 	      code = 0xc0;
   3777       1.1  christos 	      break;
   3778       1.1  christos 	    case 0xc3:
   3779       1.1  christos 	      code = 0xc1;
   3780       1.1  christos 	      break;
   3781       1.1  christos 	    case 0xc1:
   3782       1.1  christos 	      code = 0xc3;
   3783       1.1  christos 	      break;
   3784       1.1  christos 	    case 0xc4:
   3785       1.1  christos 	      code = 0xc6;
   3786       1.1  christos 	      break;
   3787       1.1  christos 	    case 0xc6:
   3788       1.1  christos 	      code = 0xc4;
   3789       1.1  christos 	      break;
   3790       1.1  christos 	    case 0xc7:
   3791       1.1  christos 	      code = 0xc5;
   3792       1.1  christos 	      break;
   3793       1.1  christos 	    case 0xc5:
   3794       1.1  christos 	      code = 0xc7;
   3795       1.1  christos 	      break;
   3796       1.1  christos 	    case 0xe8:
   3797       1.1  christos 	      code = 0xe9;
   3798       1.1  christos 	      break;
   3799       1.1  christos 	    case 0x9d:
   3800       1.1  christos 	      code = 0xe8;
   3801       1.1  christos 	      break;
   3802       1.1  christos 	    case 0xea:
   3803       1.1  christos 	      code = 0xeb;
   3804       1.1  christos 	      break;
   3805       1.1  christos 	    case 0xeb:
   3806       1.1  christos 	      code = 0xea;
   3807       1.1  christos 	      break;
   3808       1.1  christos 	    }
   3809       1.1  christos 	  bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
   3810       1.1  christos 
   3811       1.1  christos 	  /* Set the reloc type and symbol for the first branch
   3812       1.1  christos 	     from the second branch.  */
   3813       1.1  christos 	  irel->r_info = nrel->r_info;
   3814       1.1  christos 
   3815       1.1  christos 	  /* Make the reloc for the second branch a null reloc.  */
   3816       1.1  christos 	  nrel->r_info = ELF32_R_INFO (ELF32_R_SYM (nrel->r_info),
   3817       1.1  christos 				       R_MN10300_NONE);
   3818       1.1  christos 
   3819       1.1  christos 	  /* Delete two bytes of data.  */
   3820       1.1  christos 	  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3821       1.1  christos 					       irel->r_offset + 1, 2))
   3822       1.1  christos 	    goto error_return;
   3823       1.1  christos 
   3824       1.1  christos 	  /* That will change things, so, we should relax again.
   3825  1.1.1.10  christos 	     Note that this is not required, and it may be slow.  */
   3826       1.1  christos 	  *again = true;
   3827       1.1  christos 	}
   3828       1.1  christos 
   3829       1.1  christos       /* Try to turn a 24 immediate, displacement or absolute address
   3830       1.1  christos 	 into a 8 immediate, displacement or absolute address.  */
   3831       1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_24)
   3832       1.1  christos 	{
   3833       1.1  christos 	  bfd_vma value = symval;
   3834       1.1  christos 	  value += irel->r_addend;
   3835       1.1  christos 
   3836       1.1  christos 	  /* See if the value will fit in 8 bits.  */
   3837       1.1  christos 	  if ((long) value < 0x7f && (long) value > -0x80)
   3838       1.1  christos 	    {
   3839       1.1  christos 	      unsigned char code;
   3840       1.1  christos 
   3841       1.1  christos 	      /* AM33 insns which have 24 operands are 6 bytes long and
   3842       1.1  christos 		 will have 0xfd as the first byte.  */
   3843       1.1  christos 
   3844       1.1  christos 	      /* Get the first opcode.  */
   3845       1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
   3846       1.1  christos 
   3847       1.1  christos 	      if (code == 0xfd)
   3848       1.1  christos 		{
   3849       1.1  christos 		  /* Get the second opcode.  */
   3850       1.1  christos 		  code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
   3851       1.1  christos 
   3852       1.1  christos 		  /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
   3853       1.1  christos 		     equivalent instructions exists.  */
   3854       1.1  christos 		  if (code != 0x6b && code != 0x7b
   3855       1.1  christos 		      && code != 0x8b && code != 0x9b
   3856       1.1  christos 		      && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
   3857       1.1  christos 			  || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
   3858       1.1  christos 			  || (code & 0x0f) == 0x0e))
   3859       1.1  christos 		    {
   3860       1.1  christos 		      /* Not safe if the high bit is on as relaxing may
   3861       1.1  christos 			 move the value out of high mem and thus not fit
   3862       1.1  christos 			 in a signed 8bit value.  This is currently over
   3863       1.1  christos 			 conservative.  */
   3864       1.1  christos 		      if ((value & 0x80) == 0)
   3865       1.1  christos 			{
   3866       1.1  christos 			  /* Note that we've changed the relocation contents,
   3867       1.1  christos 			     etc.  */
   3868       1.1  christos 			  elf_section_data (sec)->relocs = internal_relocs;
   3869       1.1  christos 			  elf_section_data (sec)->this_hdr.contents = contents;
   3870       1.1  christos 			  symtab_hdr->contents = (unsigned char *) isymbuf;
   3871       1.1  christos 
   3872       1.1  christos 			  /* Fix the opcode.  */
   3873       1.1  christos 			  bfd_put_8 (abfd, 0xfb, contents + irel->r_offset - 3);
   3874       1.1  christos 			  bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
   3875       1.1  christos 
   3876       1.1  christos 			  /* Fix the relocation's type.  */
   3877       1.1  christos 			  irel->r_info =
   3878       1.1  christos 			    ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   3879       1.1  christos 					  R_MN10300_8);
   3880       1.1  christos 
   3881       1.1  christos 			  /* Delete two bytes of data.  */
   3882       1.1  christos 			  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3883       1.1  christos 							       irel->r_offset + 1, 2))
   3884       1.1  christos 			    goto error_return;
   3885       1.1  christos 
   3886       1.1  christos 			  /* That will change things, so, we should relax
   3887       1.1  christos 			     again.  Note that this is not required, and it
   3888  1.1.1.10  christos 			     may be slow.  */
   3889       1.1  christos 			  *again = true;
   3890       1.1  christos 			  break;
   3891       1.1  christos 			}
   3892       1.1  christos 		    }
   3893       1.1  christos 		}
   3894       1.1  christos 	    }
   3895       1.1  christos 	}
   3896       1.1  christos 
   3897       1.1  christos       /* Try to turn a 32bit immediate, displacement or absolute address
   3898       1.1  christos 	 into a 16bit immediate, displacement or absolute address.  */
   3899       1.1  christos       if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_32
   3900       1.1  christos 	  || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32
   3901       1.1  christos 	  || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
   3902       1.1  christos 	{
   3903       1.1  christos 	  bfd_vma value = symval;
   3904       1.1  christos 
   3905       1.1  christos 	  if (ELF32_R_TYPE (irel->r_info) != (int) R_MN10300_32)
   3906       1.1  christos 	    {
   3907       1.1  christos 	      asection * sgot;
   3908   1.1.1.2  christos 
   3909       1.1  christos 	      sgot = hash_table->root.sgot;
   3910       1.1  christos 	      if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32)
   3911       1.1  christos 		{
   3912       1.1  christos 		  value = sgot->output_offset;
   3913       1.1  christos 
   3914       1.1  christos 		  if (h)
   3915       1.1  christos 		    value += h->root.got.offset;
   3916       1.1  christos 		  else
   3917       1.1  christos 		    value += (elf_local_got_offsets
   3918       1.1  christos 			      (abfd)[ELF32_R_SYM (irel->r_info)]);
   3919       1.1  christos 		}
   3920       1.1  christos 	      else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
   3921       1.1  christos 		value -= sgot->output_section->vma;
   3922       1.1  christos 	      else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32)
   3923       1.1  christos 		value = (sgot->output_section->vma
   3924       1.1  christos 			 - (sec->output_section->vma
   3925       1.1  christos 			    + sec->output_offset
   3926       1.1  christos 			    + irel->r_offset));
   3927       1.1  christos 	      else
   3928       1.1  christos 		abort ();
   3929       1.1  christos 	    }
   3930       1.1  christos 
   3931       1.1  christos 	  value += irel->r_addend;
   3932       1.1  christos 
   3933       1.1  christos 	  /* See if the value will fit in 24 bits.
   3934       1.1  christos 	     We allow any 16bit match here.  We prune those we can't
   3935   1.1.1.9  christos 	     handle below.  */
   3936       1.1  christos 	  if (value + 0x800000 < 0x1000000 && irel->r_offset >= 3)
   3937       1.1  christos 	    {
   3938       1.1  christos 	      unsigned char code;
   3939       1.1  christos 
   3940       1.1  christos 	      /* AM33 insns which have 32bit operands are 7 bytes long and
   3941       1.1  christos 		 will have 0xfe as the first byte.  */
   3942       1.1  christos 
   3943       1.1  christos 	      /* Get the first opcode.  */
   3944       1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
   3945       1.1  christos 
   3946       1.1  christos 	      if (code == 0xfe)
   3947       1.1  christos 		{
   3948       1.1  christos 		  /* Get the second opcode.  */
   3949       1.1  christos 		  code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
   3950       1.1  christos 
   3951       1.1  christos 		  /* All the am33 32 -> 24 relaxing possibilities.  */
   3952       1.1  christos 		  /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
   3953       1.1  christos 		     equivalent instructions exists.  */
   3954       1.1  christos 		  if (code != 0x6b && code != 0x7b
   3955       1.1  christos 		      && code != 0x8b && code != 0x9b
   3956       1.1  christos 		      && (ELF32_R_TYPE (irel->r_info)
   3957       1.1  christos 			  != (int) R_MN10300_GOTPC32)
   3958       1.1  christos 		      && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
   3959       1.1  christos 			  || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
   3960       1.1  christos 			  || (code & 0x0f) == 0x0e))
   3961       1.1  christos 		    {
   3962       1.1  christos 		      /* Not safe if the high bit is on as relaxing may
   3963       1.1  christos 			 move the value out of high mem and thus not fit
   3964       1.1  christos 			 in a signed 16bit value.  This is currently over
   3965       1.1  christos 			 conservative.  */
   3966       1.1  christos 		      if ((value & 0x8000) == 0)
   3967       1.1  christos 			{
   3968       1.1  christos 			  /* Note that we've changed the relocation contents,
   3969       1.1  christos 			     etc.  */
   3970       1.1  christos 			  elf_section_data (sec)->relocs = internal_relocs;
   3971       1.1  christos 			  elf_section_data (sec)->this_hdr.contents = contents;
   3972       1.1  christos 			  symtab_hdr->contents = (unsigned char *) isymbuf;
   3973       1.1  christos 
   3974       1.1  christos 			  /* Fix the opcode.  */
   3975       1.1  christos 			  bfd_put_8 (abfd, 0xfd, contents + irel->r_offset - 3);
   3976       1.1  christos 			  bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
   3977       1.1  christos 
   3978       1.1  christos 			  /* Fix the relocation's type.  */
   3979       1.1  christos 			  irel->r_info =
   3980       1.1  christos 			    ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   3981       1.1  christos 					  (ELF32_R_TYPE (irel->r_info)
   3982       1.1  christos 					   == (int) R_MN10300_GOTOFF32)
   3983       1.1  christos 					  ? R_MN10300_GOTOFF24
   3984       1.1  christos 					  : (ELF32_R_TYPE (irel->r_info)
   3985       1.1  christos 					     == (int) R_MN10300_GOT32)
   3986       1.1  christos 					  ? R_MN10300_GOT24 :
   3987       1.1  christos 					  R_MN10300_24);
   3988       1.1  christos 
   3989       1.1  christos 			  /* Delete one byte of data.  */
   3990       1.1  christos 			  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   3991       1.1  christos 							       irel->r_offset + 3, 1))
   3992       1.1  christos 			    goto error_return;
   3993       1.1  christos 
   3994       1.1  christos 			  /* That will change things, so, we should relax
   3995       1.1  christos 			     again.  Note that this is not required, and it
   3996  1.1.1.10  christos 			     may be slow.  */
   3997       1.1  christos 			  *again = true;
   3998       1.1  christos 			  break;
   3999       1.1  christos 			}
   4000       1.1  christos 		    }
   4001       1.1  christos 		}
   4002       1.1  christos 	    }
   4003       1.1  christos 
   4004       1.1  christos 	  /* See if the value will fit in 16 bits.
   4005       1.1  christos 	     We allow any 16bit match here.  We prune those we can't
   4006   1.1.1.9  christos 	     handle below.  */
   4007       1.1  christos 	  if (value + 0x8000 < 0x10000 && irel->r_offset >= 2)
   4008       1.1  christos 	    {
   4009       1.1  christos 	      unsigned char code;
   4010       1.1  christos 
   4011       1.1  christos 	      /* Most insns which have 32bit operands are 6 bytes long;
   4012       1.1  christos 		 exceptions are pcrel insns and bit insns.
   4013       1.1  christos 
   4014       1.1  christos 		 We handle pcrel insns above.  We don't bother trying
   4015       1.1  christos 		 to handle the bit insns here.
   4016       1.1  christos 
   4017       1.1  christos 		 The first byte of the remaining insns will be 0xfc.  */
   4018       1.1  christos 
   4019       1.1  christos 	      /* Get the first opcode.  */
   4020       1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
   4021       1.1  christos 
   4022       1.1  christos 	      if (code != 0xfc)
   4023       1.1  christos 		continue;
   4024       1.1  christos 
   4025       1.1  christos 	      /* Get the second opcode.  */
   4026       1.1  christos 	      code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
   4027       1.1  christos 
   4028       1.1  christos 	      if ((code & 0xf0) < 0x80)
   4029       1.1  christos 		switch (code & 0xf0)
   4030       1.1  christos 		  {
   4031       1.1  christos 		  /* mov (d32,am),dn   -> mov (d32,am),dn
   4032       1.1  christos 		     mov dm,(d32,am)   -> mov dn,(d32,am)
   4033       1.1  christos 		     mov (d32,am),an   -> mov (d32,am),an
   4034       1.1  christos 		     mov dm,(d32,am)   -> mov dn,(d32,am)
   4035       1.1  christos 		     movbu (d32,am),dn -> movbu (d32,am),dn
   4036       1.1  christos 		     movbu dm,(d32,am) -> movbu dn,(d32,am)
   4037       1.1  christos 		     movhu (d32,am),dn -> movhu (d32,am),dn
   4038       1.1  christos 		     movhu dm,(d32,am) -> movhu dn,(d32,am) */
   4039       1.1  christos 		  case 0x00:
   4040       1.1  christos 		  case 0x10:
   4041       1.1  christos 		  case 0x20:
   4042       1.1  christos 		  case 0x30:
   4043       1.1  christos 		  case 0x40:
   4044       1.1  christos 		  case 0x50:
   4045       1.1  christos 		  case 0x60:
   4046       1.1  christos 		  case 0x70:
   4047       1.1  christos 		    /* Not safe if the high bit is on as relaxing may
   4048       1.1  christos 		       move the value out of high mem and thus not fit
   4049       1.1  christos 		       in a signed 16bit value.  */
   4050       1.1  christos 		    if (code == 0xcc
   4051       1.1  christos 			&& (value & 0x8000))
   4052       1.1  christos 		      continue;
   4053       1.1  christos 
   4054       1.1  christos 		    /* Note that we've changed the relocation contents, etc.  */
   4055       1.1  christos 		    elf_section_data (sec)->relocs = internal_relocs;
   4056       1.1  christos 		    elf_section_data (sec)->this_hdr.contents = contents;
   4057       1.1  christos 		    symtab_hdr->contents = (unsigned char *) isymbuf;
   4058       1.1  christos 
   4059       1.1  christos 		    /* Fix the opcode.  */
   4060       1.1  christos 		    bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
   4061       1.1  christos 		    bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
   4062       1.1  christos 
   4063       1.1  christos 		    /* Fix the relocation's type.  */
   4064       1.1  christos 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4065       1.1  christos 						 (ELF32_R_TYPE (irel->r_info)
   4066       1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4067       1.1  christos 						 ? R_MN10300_GOTOFF16
   4068       1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4069       1.1  christos 						    == (int) R_MN10300_GOT32)
   4070       1.1  christos 						 ? R_MN10300_GOT16
   4071       1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4072       1.1  christos 						    == (int) R_MN10300_GOTPC32)
   4073       1.1  christos 						 ? R_MN10300_GOTPC16 :
   4074       1.1  christos 						 R_MN10300_16);
   4075       1.1  christos 
   4076       1.1  christos 		    /* Delete two bytes of data.  */
   4077       1.1  christos 		    if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4078       1.1  christos 							 irel->r_offset + 2, 2))
   4079       1.1  christos 		      goto error_return;
   4080       1.1  christos 
   4081       1.1  christos 		    /* That will change things, so, we should relax again.
   4082  1.1.1.10  christos 		       Note that this is not required, and it may be slow.  */
   4083       1.1  christos 		    *again = true;
   4084       1.1  christos 		    break;
   4085       1.1  christos 		  }
   4086       1.1  christos 	      else if ((code & 0xf0) == 0x80
   4087       1.1  christos 		       || (code & 0xf0) == 0x90)
   4088       1.1  christos 		switch (code & 0xf3)
   4089       1.1  christos 		  {
   4090       1.1  christos 		  /* mov dn,(abs32)   -> mov dn,(abs16)
   4091       1.1  christos 		     movbu dn,(abs32) -> movbu dn,(abs16)
   4092       1.1  christos 		     movhu dn,(abs32) -> movhu dn,(abs16)  */
   4093       1.1  christos 		  case 0x81:
   4094       1.1  christos 		  case 0x82:
   4095       1.1  christos 		  case 0x83:
   4096       1.1  christos 		    /* Note that we've changed the relocation contents, etc.  */
   4097       1.1  christos 		    elf_section_data (sec)->relocs = internal_relocs;
   4098       1.1  christos 		    elf_section_data (sec)->this_hdr.contents = contents;
   4099       1.1  christos 		    symtab_hdr->contents = (unsigned char *) isymbuf;
   4100       1.1  christos 
   4101       1.1  christos 		    if ((code & 0xf3) == 0x81)
   4102       1.1  christos 		      code = 0x01 + (code & 0x0c);
   4103       1.1  christos 		    else if ((code & 0xf3) == 0x82)
   4104       1.1  christos 		      code = 0x02 + (code & 0x0c);
   4105       1.1  christos 		    else if ((code & 0xf3) == 0x83)
   4106       1.1  christos 		      code = 0x03 + (code & 0x0c);
   4107       1.1  christos 		    else
   4108       1.1  christos 		      abort ();
   4109       1.1  christos 
   4110       1.1  christos 		    /* Fix the opcode.  */
   4111       1.1  christos 		    bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
   4112       1.1  christos 
   4113       1.1  christos 		    /* Fix the relocation's type.  */
   4114       1.1  christos 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4115       1.1  christos 						 (ELF32_R_TYPE (irel->r_info)
   4116       1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4117       1.1  christos 						 ? R_MN10300_GOTOFF16
   4118       1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4119       1.1  christos 						    == (int) R_MN10300_GOT32)
   4120       1.1  christos 						 ? R_MN10300_GOT16
   4121       1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4122       1.1  christos 						    == (int) R_MN10300_GOTPC32)
   4123       1.1  christos 						 ? R_MN10300_GOTPC16 :
   4124       1.1  christos 						 R_MN10300_16);
   4125       1.1  christos 
   4126       1.1  christos 		    /* The opcode got shorter too, so we have to fix the
   4127       1.1  christos 		       addend and offset too!  */
   4128       1.1  christos 		    irel->r_offset -= 1;
   4129       1.1  christos 
   4130       1.1  christos 		    /* Delete three bytes of data.  */
   4131       1.1  christos 		    if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4132       1.1  christos 							 irel->r_offset + 1, 3))
   4133       1.1  christos 		      goto error_return;
   4134       1.1  christos 
   4135       1.1  christos 		    /* That will change things, so, we should relax again.
   4136  1.1.1.10  christos 		       Note that this is not required, and it may be slow.  */
   4137       1.1  christos 		    *again = true;
   4138       1.1  christos 		    break;
   4139       1.1  christos 
   4140       1.1  christos 		  /* mov am,(abs32)    -> mov am,(abs16)
   4141       1.1  christos 		     mov am,(d32,sp)   -> mov am,(d16,sp)
   4142       1.1  christos 		     mov dm,(d32,sp)   -> mov dm,(d32,sp)
   4143       1.1  christos 		     movbu dm,(d32,sp) -> movbu dm,(d32,sp)
   4144       1.1  christos 		     movhu dm,(d32,sp) -> movhu dm,(d32,sp) */
   4145       1.1  christos 		  case 0x80:
   4146       1.1  christos 		  case 0x90:
   4147       1.1  christos 		  case 0x91:
   4148       1.1  christos 		  case 0x92:
   4149       1.1  christos 		  case 0x93:
   4150       1.1  christos 		    /* sp-based offsets are zero-extended.  */
   4151       1.1  christos 		    if (code >= 0x90 && code <= 0x93
   4152       1.1  christos 			&& (long) value < 0)
   4153       1.1  christos 		      continue;
   4154       1.1  christos 
   4155       1.1  christos 		    /* Note that we've changed the relocation contents, etc.  */
   4156       1.1  christos 		    elf_section_data (sec)->relocs = internal_relocs;
   4157       1.1  christos 		    elf_section_data (sec)->this_hdr.contents = contents;
   4158       1.1  christos 		    symtab_hdr->contents = (unsigned char *) isymbuf;
   4159       1.1  christos 
   4160       1.1  christos 		    /* Fix the opcode.  */
   4161       1.1  christos 		    bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
   4162       1.1  christos 		    bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
   4163       1.1  christos 
   4164       1.1  christos 		    /* Fix the relocation's type.  */
   4165       1.1  christos 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4166       1.1  christos 						 (ELF32_R_TYPE (irel->r_info)
   4167       1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4168       1.1  christos 						 ? R_MN10300_GOTOFF16
   4169       1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4170       1.1  christos 						    == (int) R_MN10300_GOT32)
   4171       1.1  christos 						 ? R_MN10300_GOT16
   4172       1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4173       1.1  christos 						    == (int) R_MN10300_GOTPC32)
   4174       1.1  christos 						 ? R_MN10300_GOTPC16 :
   4175       1.1  christos 						 R_MN10300_16);
   4176       1.1  christos 
   4177       1.1  christos 		    /* Delete two bytes of data.  */
   4178       1.1  christos 		    if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4179       1.1  christos 							 irel->r_offset + 2, 2))
   4180       1.1  christos 		      goto error_return;
   4181       1.1  christos 
   4182       1.1  christos 		    /* That will change things, so, we should relax again.
   4183  1.1.1.10  christos 		       Note that this is not required, and it may be slow.  */
   4184       1.1  christos 		    *again = true;
   4185       1.1  christos 		    break;
   4186       1.1  christos 		  }
   4187       1.1  christos 	      else if ((code & 0xf0) < 0xf0)
   4188       1.1  christos 		switch (code & 0xfc)
   4189       1.1  christos 		  {
   4190       1.1  christos 		  /* mov imm32,dn     -> mov imm16,dn
   4191       1.1  christos 		     mov imm32,an     -> mov imm16,an
   4192       1.1  christos 		     mov (abs32),dn   -> mov (abs16),dn
   4193       1.1  christos 		     movbu (abs32),dn -> movbu (abs16),dn
   4194       1.1  christos 		     movhu (abs32),dn -> movhu (abs16),dn  */
   4195       1.1  christos 		  case 0xcc:
   4196       1.1  christos 		  case 0xdc:
   4197       1.1  christos 		  case 0xa4:
   4198       1.1  christos 		  case 0xa8:
   4199       1.1  christos 		  case 0xac:
   4200       1.1  christos 		    /* Not safe if the high bit is on as relaxing may
   4201       1.1  christos 		       move the value out of high mem and thus not fit
   4202       1.1  christos 		       in a signed 16bit value.  */
   4203       1.1  christos 		    if (code == 0xcc
   4204       1.1  christos 			&& (value & 0x8000))
   4205       1.1  christos 		      continue;
   4206   1.1.1.2  christos 
   4207   1.1.1.2  christos 		    /* "mov imm16, an" zero-extends the immediate.  */
   4208       1.1  christos 		    if ((code & 0xfc) == 0xdc
   4209       1.1  christos 			&& (long) value < 0)
   4210       1.1  christos 		      continue;
   4211       1.1  christos 
   4212       1.1  christos 		    /* Note that we've changed the relocation contents, etc.  */
   4213       1.1  christos 		    elf_section_data (sec)->relocs = internal_relocs;
   4214       1.1  christos 		    elf_section_data (sec)->this_hdr.contents = contents;
   4215       1.1  christos 		    symtab_hdr->contents = (unsigned char *) isymbuf;
   4216       1.1  christos 
   4217       1.1  christos 		    if ((code & 0xfc) == 0xcc)
   4218       1.1  christos 		      code = 0x2c + (code & 0x03);
   4219       1.1  christos 		    else if ((code & 0xfc) == 0xdc)
   4220       1.1  christos 		      code = 0x24 + (code & 0x03);
   4221       1.1  christos 		    else if ((code & 0xfc) == 0xa4)
   4222       1.1  christos 		      code = 0x30 + (code & 0x03);
   4223       1.1  christos 		    else if ((code & 0xfc) == 0xa8)
   4224       1.1  christos 		      code = 0x34 + (code & 0x03);
   4225       1.1  christos 		    else if ((code & 0xfc) == 0xac)
   4226       1.1  christos 		      code = 0x38 + (code & 0x03);
   4227       1.1  christos 		    else
   4228       1.1  christos 		      abort ();
   4229       1.1  christos 
   4230       1.1  christos 		    /* Fix the opcode.  */
   4231       1.1  christos 		    bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
   4232       1.1  christos 
   4233       1.1  christos 		    /* Fix the relocation's type.  */
   4234       1.1  christos 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4235       1.1  christos 						 (ELF32_R_TYPE (irel->r_info)
   4236       1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4237       1.1  christos 						 ? R_MN10300_GOTOFF16
   4238       1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4239       1.1  christos 						    == (int) R_MN10300_GOT32)
   4240       1.1  christos 						 ? R_MN10300_GOT16
   4241       1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4242       1.1  christos 						    == (int) R_MN10300_GOTPC32)
   4243       1.1  christos 						 ? R_MN10300_GOTPC16 :
   4244       1.1  christos 						 R_MN10300_16);
   4245       1.1  christos 
   4246       1.1  christos 		    /* The opcode got shorter too, so we have to fix the
   4247       1.1  christos 		       addend and offset too!  */
   4248       1.1  christos 		    irel->r_offset -= 1;
   4249       1.1  christos 
   4250       1.1  christos 		    /* Delete three bytes of data.  */
   4251       1.1  christos 		    if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4252       1.1  christos 							 irel->r_offset + 1, 3))
   4253       1.1  christos 		      goto error_return;
   4254       1.1  christos 
   4255       1.1  christos 		    /* That will change things, so, we should relax again.
   4256  1.1.1.10  christos 		       Note that this is not required, and it may be slow.  */
   4257       1.1  christos 		    *again = true;
   4258       1.1  christos 		    break;
   4259       1.1  christos 
   4260       1.1  christos 		  /* mov (abs32),an    -> mov (abs16),an
   4261       1.1  christos 		     mov (d32,sp),an   -> mov (d16,sp),an
   4262       1.1  christos 		     mov (d32,sp),dn   -> mov (d16,sp),dn
   4263       1.1  christos 		     movbu (d32,sp),dn -> movbu (d16,sp),dn
   4264       1.1  christos 		     movhu (d32,sp),dn -> movhu (d16,sp),dn
   4265       1.1  christos 		     add imm32,dn      -> add imm16,dn
   4266       1.1  christos 		     cmp imm32,dn      -> cmp imm16,dn
   4267       1.1  christos 		     add imm32,an      -> add imm16,an
   4268       1.1  christos 		     cmp imm32,an      -> cmp imm16,an
   4269       1.1  christos 		     and imm32,dn      -> and imm16,dn
   4270       1.1  christos 		     or imm32,dn       -> or imm16,dn
   4271       1.1  christos 		     xor imm32,dn      -> xor imm16,dn
   4272       1.1  christos 		     btst imm32,dn     -> btst imm16,dn */
   4273       1.1  christos 
   4274       1.1  christos 		  case 0xa0:
   4275       1.1  christos 		  case 0xb0:
   4276       1.1  christos 		  case 0xb1:
   4277       1.1  christos 		  case 0xb2:
   4278       1.1  christos 		  case 0xb3:
   4279       1.1  christos 		  case 0xc0:
   4280       1.1  christos 		  case 0xc8:
   4281       1.1  christos 
   4282       1.1  christos 		  case 0xd0:
   4283       1.1  christos 		  case 0xd8:
   4284       1.1  christos 		  case 0xe0:
   4285       1.1  christos 		  case 0xe1:
   4286       1.1  christos 		  case 0xe2:
   4287       1.1  christos 		  case 0xe3:
   4288       1.1  christos 		    /* cmp imm16, an zero-extends the immediate.  */
   4289       1.1  christos 		    if (code == 0xdc
   4290       1.1  christos 			&& (long) value < 0)
   4291       1.1  christos 		      continue;
   4292       1.1  christos 
   4293       1.1  christos 		    /* So do sp-based offsets.  */
   4294       1.1  christos 		    if (code >= 0xb0 && code <= 0xb3
   4295       1.1  christos 			&& (long) value < 0)
   4296       1.1  christos 		      continue;
   4297       1.1  christos 
   4298       1.1  christos 		    /* Note that we've changed the relocation contents, etc.  */
   4299       1.1  christos 		    elf_section_data (sec)->relocs = internal_relocs;
   4300       1.1  christos 		    elf_section_data (sec)->this_hdr.contents = contents;
   4301       1.1  christos 		    symtab_hdr->contents = (unsigned char *) isymbuf;
   4302       1.1  christos 
   4303       1.1  christos 		    /* Fix the opcode.  */
   4304       1.1  christos 		    bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
   4305       1.1  christos 		    bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
   4306       1.1  christos 
   4307       1.1  christos 		    /* Fix the relocation's type.  */
   4308       1.1  christos 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4309       1.1  christos 						 (ELF32_R_TYPE (irel->r_info)
   4310       1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4311       1.1  christos 						 ? R_MN10300_GOTOFF16
   4312       1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4313       1.1  christos 						    == (int) R_MN10300_GOT32)
   4314       1.1  christos 						 ? R_MN10300_GOT16
   4315       1.1  christos 						 : (ELF32_R_TYPE (irel->r_info)
   4316       1.1  christos 						    == (int) R_MN10300_GOTPC32)
   4317       1.1  christos 						 ? R_MN10300_GOTPC16 :
   4318       1.1  christos 						 R_MN10300_16);
   4319       1.1  christos 
   4320       1.1  christos 		    /* Delete two bytes of data.  */
   4321       1.1  christos 		    if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4322       1.1  christos 							 irel->r_offset + 2, 2))
   4323       1.1  christos 		      goto error_return;
   4324       1.1  christos 
   4325       1.1  christos 		    /* That will change things, so, we should relax again.
   4326  1.1.1.10  christos 		       Note that this is not required, and it may be slow.  */
   4327       1.1  christos 		    *again = true;
   4328       1.1  christos 		    break;
   4329       1.1  christos 		  }
   4330       1.1  christos 	      else if (code == 0xfe)
   4331       1.1  christos 		{
   4332       1.1  christos 		  /* add imm32,sp -> add imm16,sp  */
   4333       1.1  christos 
   4334       1.1  christos 		  /* Note that we've changed the relocation contents, etc.  */
   4335       1.1  christos 		  elf_section_data (sec)->relocs = internal_relocs;
   4336       1.1  christos 		  elf_section_data (sec)->this_hdr.contents = contents;
   4337       1.1  christos 		  symtab_hdr->contents = (unsigned char *) isymbuf;
   4338       1.1  christos 
   4339       1.1  christos 		  /* Fix the opcode.  */
   4340       1.1  christos 		  bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
   4341       1.1  christos 		  bfd_put_8 (abfd, 0xfe, contents + irel->r_offset - 1);
   4342       1.1  christos 
   4343       1.1  christos 		  /* Fix the relocation's type.  */
   4344       1.1  christos 		  irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   4345       1.1  christos 					       (ELF32_R_TYPE (irel->r_info)
   4346       1.1  christos 						== (int) R_MN10300_GOT32)
   4347       1.1  christos 					       ? R_MN10300_GOT16
   4348       1.1  christos 					       : (ELF32_R_TYPE (irel->r_info)
   4349       1.1  christos 						  == (int) R_MN10300_GOTOFF32)
   4350       1.1  christos 					       ? R_MN10300_GOTOFF16
   4351       1.1  christos 					       : (ELF32_R_TYPE (irel->r_info)
   4352       1.1  christos 						  == (int) R_MN10300_GOTPC32)
   4353       1.1  christos 					       ? R_MN10300_GOTPC16 :
   4354       1.1  christos 					       R_MN10300_16);
   4355       1.1  christos 
   4356       1.1  christos 		  /* Delete two bytes of data.  */
   4357       1.1  christos 		  if (!mn10300_elf_relax_delete_bytes (abfd, sec,
   4358       1.1  christos 						       irel->r_offset + 2, 2))
   4359       1.1  christos 		    goto error_return;
   4360       1.1  christos 
   4361       1.1  christos 		  /* That will change things, so, we should relax again.
   4362  1.1.1.10  christos 		     Note that this is not required, and it may be slow.  */
   4363       1.1  christos 		  *again = true;
   4364       1.1  christos 		  break;
   4365       1.1  christos 		}
   4366       1.1  christos 	    }
   4367       1.1  christos 	}
   4368       1.1  christos     }
   4369       1.1  christos 
   4370       1.1  christos   if (isymbuf != NULL
   4371       1.1  christos       && symtab_hdr->contents != (unsigned char *) isymbuf)
   4372       1.1  christos     {
   4373       1.1  christos       if (! link_info->keep_memory)
   4374       1.1  christos 	free (isymbuf);
   4375       1.1  christos       else
   4376       1.1  christos 	{
   4377       1.1  christos 	  /* Cache the symbols for elf_link_input_bfd.  */
   4378       1.1  christos 	  symtab_hdr->contents = (unsigned char *) isymbuf;
   4379       1.1  christos 	}
   4380       1.1  christos     }
   4381       1.1  christos 
   4382       1.1  christos   if (contents != NULL
   4383       1.1  christos       && elf_section_data (sec)->this_hdr.contents != contents)
   4384       1.1  christos     {
   4385       1.1  christos       if (! link_info->keep_memory)
   4386       1.1  christos 	free (contents);
   4387       1.1  christos       else
   4388       1.1  christos 	{
   4389       1.1  christos 	  /* Cache the section contents for elf_link_input_bfd.  */
   4390       1.1  christos 	  elf_section_data (sec)->this_hdr.contents = contents;
   4391       1.1  christos 	}
   4392       1.1  christos     }
   4393   1.1.1.9  christos 
   4394       1.1  christos   if (elf_section_data (sec)->relocs != internal_relocs)
   4395       1.1  christos     free (internal_relocs);
   4396  1.1.1.10  christos 
   4397       1.1  christos   return true;
   4398       1.1  christos 
   4399   1.1.1.9  christos  error_return:
   4400       1.1  christos   if (symtab_hdr->contents != (unsigned char *) isymbuf)
   4401   1.1.1.9  christos     free (isymbuf);
   4402       1.1  christos   if (elf_section_data (section)->this_hdr.contents != contents)
   4403   1.1.1.9  christos     free (contents);
   4404       1.1  christos   if (elf_section_data (section)->relocs != internal_relocs)
   4405       1.1  christos     free (internal_relocs);
   4406  1.1.1.10  christos 
   4407       1.1  christos   return false;
   4408       1.1  christos }
   4409       1.1  christos 
   4410       1.1  christos /* This is a version of bfd_generic_get_relocated_section_contents
   4411       1.1  christos    which uses mn10300_elf_relocate_section.  */
   4412       1.1  christos 
   4413       1.1  christos static bfd_byte *
   4414       1.1  christos mn10300_elf_get_relocated_section_contents (bfd *output_bfd,
   4415       1.1  christos 					    struct bfd_link_info *link_info,
   4416       1.1  christos 					    struct bfd_link_order *link_order,
   4417  1.1.1.10  christos 					    bfd_byte *data,
   4418       1.1  christos 					    bool relocatable,
   4419       1.1  christos 					    asymbol **symbols)
   4420       1.1  christos {
   4421       1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   4422       1.1  christos   asection *input_section = link_order->u.indirect.section;
   4423       1.1  christos   bfd *input_bfd = input_section->owner;
   4424       1.1  christos   asection **sections = NULL;
   4425       1.1  christos   Elf_Internal_Rela *internal_relocs = NULL;
   4426       1.1  christos   Elf_Internal_Sym *isymbuf = NULL;
   4427       1.1  christos 
   4428       1.1  christos   /* We only need to handle the case of relaxing, or of having a
   4429       1.1  christos      particular set of section contents, specially.  */
   4430       1.1  christos   if (relocatable
   4431       1.1  christos       || elf_section_data (input_section)->this_hdr.contents == NULL)
   4432       1.1  christos     return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
   4433       1.1  christos 						       link_order, data,
   4434       1.1  christos 						       relocatable,
   4435       1.1  christos 						       symbols);
   4436       1.1  christos 
   4437       1.1  christos   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   4438  1.1.1.10  christos 
   4439  1.1.1.10  christos   bfd_byte *orig_data = data;
   4440  1.1.1.10  christos   if (data == NULL)
   4441  1.1.1.10  christos     {
   4442  1.1.1.10  christos       data = bfd_malloc (input_section->size);
   4443  1.1.1.10  christos       if (data == NULL)
   4444  1.1.1.10  christos 	return NULL;
   4445       1.1  christos     }
   4446       1.1  christos   memcpy (data, elf_section_data (input_section)->this_hdr.contents,
   4447       1.1  christos 	  (size_t) input_section->size);
   4448       1.1  christos 
   4449       1.1  christos   if ((input_section->flags & SEC_RELOC) != 0
   4450       1.1  christos       && input_section->reloc_count > 0)
   4451       1.1  christos     {
   4452       1.1  christos       asection **secpp;
   4453       1.1  christos       Elf_Internal_Sym *isym, *isymend;
   4454       1.1  christos       bfd_size_type amt;
   4455       1.1  christos 
   4456  1.1.1.10  christos       internal_relocs = _bfd_elf_link_read_relocs (input_bfd, input_section,
   4457       1.1  christos 						   NULL, NULL, false);
   4458       1.1  christos       if (internal_relocs == NULL)
   4459       1.1  christos 	goto error_return;
   4460       1.1  christos 
   4461       1.1  christos       if (symtab_hdr->sh_info != 0)
   4462       1.1  christos 	{
   4463       1.1  christos 	  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   4464       1.1  christos 	  if (isymbuf == NULL)
   4465       1.1  christos 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
   4466       1.1  christos 					    symtab_hdr->sh_info, 0,
   4467       1.1  christos 					    NULL, NULL, NULL);
   4468       1.1  christos 	  if (isymbuf == NULL)
   4469       1.1  christos 	    goto error_return;
   4470       1.1  christos 	}
   4471       1.1  christos 
   4472       1.1  christos       amt = symtab_hdr->sh_info;
   4473       1.1  christos       amt *= sizeof (asection *);
   4474       1.1  christos       sections = bfd_malloc (amt);
   4475       1.1  christos       if (sections == NULL && amt != 0)
   4476       1.1  christos 	goto error_return;
   4477       1.1  christos 
   4478       1.1  christos       isymend = isymbuf + symtab_hdr->sh_info;
   4479       1.1  christos       for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
   4480       1.1  christos 	{
   4481       1.1  christos 	  asection *isec;
   4482       1.1  christos 
   4483       1.1  christos 	  if (isym->st_shndx == SHN_UNDEF)
   4484       1.1  christos 	    isec = bfd_und_section_ptr;
   4485       1.1  christos 	  else if (isym->st_shndx == SHN_ABS)
   4486       1.1  christos 	    isec = bfd_abs_section_ptr;
   4487       1.1  christos 	  else if (isym->st_shndx == SHN_COMMON)
   4488       1.1  christos 	    isec = bfd_com_section_ptr;
   4489       1.1  christos 	  else
   4490       1.1  christos 	    isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
   4491       1.1  christos 
   4492       1.1  christos 	  *secpp = isec;
   4493       1.1  christos 	}
   4494       1.1  christos 
   4495       1.1  christos       if (! mn10300_elf_relocate_section (output_bfd, link_info, input_bfd,
   4496       1.1  christos 					  input_section, data, internal_relocs,
   4497       1.1  christos 					  isymbuf, sections))
   4498       1.1  christos 	goto error_return;
   4499   1.1.1.9  christos 
   4500   1.1.1.9  christos       free (sections);
   4501       1.1  christos       if (symtab_hdr->contents != (unsigned char *) isymbuf)
   4502       1.1  christos 	free (isymbuf);
   4503       1.1  christos       if (internal_relocs != elf_section_data (input_section)->relocs)
   4504       1.1  christos 	free (internal_relocs);
   4505       1.1  christos     }
   4506       1.1  christos 
   4507       1.1  christos   return data;
   4508       1.1  christos 
   4509   1.1.1.9  christos  error_return:
   4510   1.1.1.9  christos   free (sections);
   4511       1.1  christos   if (symtab_hdr->contents != (unsigned char *) isymbuf)
   4512   1.1.1.9  christos     free (isymbuf);
   4513       1.1  christos   if (internal_relocs != elf_section_data (input_section)->relocs)
   4514  1.1.1.10  christos     free (internal_relocs);
   4515  1.1.1.10  christos   if (orig_data == NULL)
   4516       1.1  christos     free (data);
   4517       1.1  christos   return NULL;
   4518       1.1  christos }
   4519       1.1  christos 
   4520       1.1  christos /* Assorted hash table functions.  */
   4521       1.1  christos 
   4522       1.1  christos /* Initialize an entry in the link hash table.  */
   4523       1.1  christos 
   4524       1.1  christos /* Create an entry in an MN10300 ELF linker hash table.  */
   4525       1.1  christos 
   4526       1.1  christos static struct bfd_hash_entry *
   4527       1.1  christos elf32_mn10300_link_hash_newfunc (struct bfd_hash_entry *entry,
   4528       1.1  christos 				 struct bfd_hash_table *table,
   4529       1.1  christos 				 const char *string)
   4530       1.1  christos {
   4531       1.1  christos   struct elf32_mn10300_link_hash_entry *ret =
   4532       1.1  christos     (struct elf32_mn10300_link_hash_entry *) entry;
   4533       1.1  christos 
   4534       1.1  christos   /* Allocate the structure if it has not already been allocated by a
   4535       1.1  christos      subclass.  */
   4536       1.1  christos   if (ret == NULL)
   4537       1.1  christos     ret = (struct elf32_mn10300_link_hash_entry *)
   4538       1.1  christos 	   bfd_hash_allocate (table, sizeof (* ret));
   4539       1.1  christos   if (ret == NULL)
   4540       1.1  christos     return (struct bfd_hash_entry *) ret;
   4541       1.1  christos 
   4542       1.1  christos   /* Call the allocation method of the superclass.  */
   4543       1.1  christos   ret = (struct elf32_mn10300_link_hash_entry *)
   4544       1.1  christos 	 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
   4545       1.1  christos 				     table, string);
   4546       1.1  christos   if (ret != NULL)
   4547       1.1  christos     {
   4548       1.1  christos       ret->direct_calls = 0;
   4549       1.1  christos       ret->stack_size = 0;
   4550       1.1  christos       ret->movm_args = 0;
   4551       1.1  christos       ret->movm_stack_size = 0;
   4552       1.1  christos       ret->flags = 0;
   4553   1.1.1.2  christos       ret->value = 0;
   4554       1.1  christos       ret->tls_type = GOT_UNKNOWN;
   4555       1.1  christos     }
   4556       1.1  christos 
   4557       1.1  christos   return (struct bfd_hash_entry *) ret;
   4558       1.1  christos }
   4559   1.1.1.2  christos 
   4560   1.1.1.8  christos static void
   4561   1.1.1.8  christos _bfd_mn10300_copy_indirect_symbol (struct bfd_link_info *	 info,
   4562   1.1.1.8  christos 				   struct elf_link_hash_entry *	 dir,
   4563   1.1.1.2  christos 				   struct elf_link_hash_entry *	 ind)
   4564   1.1.1.2  christos {
   4565   1.1.1.2  christos   struct elf32_mn10300_link_hash_entry * edir;
   4566   1.1.1.2  christos   struct elf32_mn10300_link_hash_entry * eind;
   4567   1.1.1.2  christos 
   4568   1.1.1.2  christos   edir = elf_mn10300_hash_entry (dir);
   4569   1.1.1.2  christos   eind = elf_mn10300_hash_entry (ind);
   4570   1.1.1.2  christos 
   4571   1.1.1.2  christos   if (ind->root.type == bfd_link_hash_indirect
   4572   1.1.1.2  christos       && dir->got.refcount <= 0)
   4573   1.1.1.2  christos     {
   4574   1.1.1.2  christos       edir->tls_type = eind->tls_type;
   4575   1.1.1.2  christos       eind->tls_type = GOT_UNKNOWN;
   4576   1.1.1.2  christos     }
   4577   1.1.1.2  christos   edir->direct_calls = eind->direct_calls;
   4578   1.1.1.2  christos   edir->stack_size = eind->stack_size;
   4579   1.1.1.2  christos   edir->movm_args = eind->movm_args;
   4580   1.1.1.2  christos   edir->movm_stack_size = eind->movm_stack_size;
   4581   1.1.1.2  christos   edir->flags = eind->flags;
   4582   1.1.1.2  christos 
   4583   1.1.1.2  christos   _bfd_elf_link_hash_copy_indirect (info, dir, ind);
   4584   1.1.1.2  christos }
   4585   1.1.1.4  christos 
   4586   1.1.1.4  christos /* Destroy an mn10300 ELF linker hash table.  */
   4587   1.1.1.4  christos 
   4588   1.1.1.4  christos static void
   4589   1.1.1.4  christos elf32_mn10300_link_hash_table_free (bfd *obfd)
   4590   1.1.1.4  christos {
   4591   1.1.1.4  christos   struct elf32_mn10300_link_hash_table *ret
   4592   1.1.1.4  christos     = (struct elf32_mn10300_link_hash_table *) obfd->link.hash;
   4593   1.1.1.4  christos 
   4594   1.1.1.4  christos   obfd->link.hash = &ret->static_hash_table->root.root;
   4595  1.1.1.10  christos   _bfd_elf_link_hash_table_free (obfd);
   4596   1.1.1.4  christos   obfd->is_linker_output = true;
   4597   1.1.1.4  christos   obfd->link.hash = &ret->root.root;
   4598   1.1.1.4  christos   _bfd_elf_link_hash_table_free (obfd);
   4599   1.1.1.4  christos }
   4600       1.1  christos 
   4601       1.1  christos /* Create an mn10300 ELF linker hash table.  */
   4602       1.1  christos 
   4603       1.1  christos static struct bfd_link_hash_table *
   4604       1.1  christos elf32_mn10300_link_hash_table_create (bfd *abfd)
   4605       1.1  christos {
   4606   1.1.1.9  christos   struct elf32_mn10300_link_hash_table *ret;
   4607       1.1  christos   size_t amt = sizeof (* ret);
   4608   1.1.1.2  christos 
   4609       1.1  christos   ret = bfd_zmalloc (amt);
   4610       1.1  christos   if (ret == NULL)
   4611       1.1  christos     return NULL;
   4612       1.1  christos 
   4613   1.1.1.2  christos   amt = sizeof (struct elf_link_hash_table);
   4614       1.1  christos   ret->static_hash_table = bfd_zmalloc (amt);
   4615       1.1  christos   if (ret->static_hash_table == NULL)
   4616       1.1  christos     {
   4617       1.1  christos       free (ret);
   4618       1.1  christos       return NULL;
   4619       1.1  christos     }
   4620       1.1  christos 
   4621       1.1  christos   if (!_bfd_elf_link_hash_table_init (&ret->static_hash_table->root, abfd,
   4622  1.1.1.12  christos 				      elf32_mn10300_link_hash_newfunc,
   4623       1.1  christos 				      sizeof (struct elf32_mn10300_link_hash_entry)))
   4624       1.1  christos     {
   4625       1.1  christos       free (ret->static_hash_table);
   4626       1.1  christos       free (ret);
   4627       1.1  christos       return NULL;
   4628       1.1  christos     }
   4629  1.1.1.10  christos 
   4630   1.1.1.4  christos   abfd->is_linker_output = false;
   4631   1.1.1.4  christos   abfd->link.hash = NULL;
   4632   1.1.1.4  christos   if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
   4633  1.1.1.12  christos 				      elf32_mn10300_link_hash_newfunc,
   4634   1.1.1.4  christos 				      sizeof (struct elf32_mn10300_link_hash_entry)))
   4635  1.1.1.10  christos     {
   4636   1.1.1.4  christos       abfd->is_linker_output = true;
   4637   1.1.1.4  christos       abfd->link.hash = &ret->static_hash_table->root.root;
   4638   1.1.1.4  christos       _bfd_elf_link_hash_table_free (abfd);
   4639   1.1.1.4  christos       free (ret);
   4640   1.1.1.4  christos       return NULL;
   4641   1.1.1.4  christos     }
   4642       1.1  christos   ret->root.root.hash_table_free = elf32_mn10300_link_hash_table_free;
   4643   1.1.1.4  christos 
   4644       1.1  christos   ret->tls_ldm_got.offset = -1;
   4645   1.1.1.4  christos 
   4646       1.1  christos   return & ret->root.root;
   4647       1.1  christos }
   4648       1.1  christos 
   4649       1.1  christos static unsigned long
   4650       1.1  christos elf_mn10300_mach (flagword flags)
   4651       1.1  christos {
   4652       1.1  christos   switch (flags & EF_MN10300_MACH)
   4653       1.1  christos     {
   4654       1.1  christos     case E_MN10300_MACH_MN10300:
   4655       1.1  christos     default:
   4656       1.1  christos       return bfd_mach_mn10300;
   4657       1.1  christos 
   4658       1.1  christos     case E_MN10300_MACH_AM33:
   4659       1.1  christos       return bfd_mach_am33;
   4660       1.1  christos 
   4661       1.1  christos     case E_MN10300_MACH_AM33_2:
   4662       1.1  christos       return bfd_mach_am33_2;
   4663       1.1  christos     }
   4664       1.1  christos }
   4665       1.1  christos 
   4666       1.1  christos /* The final processing done just before writing out a MN10300 ELF object
   4667       1.1  christos    file.  This gets the MN10300 architecture right based on the machine
   4668       1.1  christos    number.  */
   4669  1.1.1.10  christos 
   4670   1.1.1.9  christos static bool
   4671       1.1  christos _bfd_mn10300_elf_final_write_processing (bfd *abfd)
   4672       1.1  christos {
   4673       1.1  christos   unsigned long val;
   4674       1.1  christos 
   4675       1.1  christos   switch (bfd_get_mach (abfd))
   4676       1.1  christos     {
   4677       1.1  christos     default:
   4678       1.1  christos     case bfd_mach_mn10300:
   4679       1.1  christos       val = E_MN10300_MACH_MN10300;
   4680       1.1  christos       break;
   4681       1.1  christos 
   4682       1.1  christos     case bfd_mach_am33:
   4683       1.1  christos       val = E_MN10300_MACH_AM33;
   4684       1.1  christos       break;
   4685       1.1  christos 
   4686       1.1  christos     case bfd_mach_am33_2:
   4687       1.1  christos       val = E_MN10300_MACH_AM33_2;
   4688       1.1  christos       break;
   4689       1.1  christos     }
   4690       1.1  christos 
   4691       1.1  christos   elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH);
   4692   1.1.1.9  christos   elf_elfheader (abfd)->e_flags |= val;
   4693       1.1  christos   return _bfd_elf_final_write_processing (abfd);
   4694       1.1  christos }
   4695  1.1.1.10  christos 
   4696       1.1  christos static bool
   4697       1.1  christos _bfd_mn10300_elf_object_p (bfd *abfd)
   4698       1.1  christos {
   4699       1.1  christos   bfd_default_set_arch_mach (abfd, bfd_arch_mn10300,
   4700  1.1.1.10  christos 			     elf_mn10300_mach (elf_elfheader (abfd)->e_flags));
   4701       1.1  christos   return true;
   4702       1.1  christos }
   4703       1.1  christos 
   4704       1.1  christos /* Merge backend specific data from an object file to the output
   4705       1.1  christos    object file when linking.  */
   4706  1.1.1.10  christos 
   4707   1.1.1.7  christos static bool
   4708       1.1  christos _bfd_mn10300_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   4709   1.1.1.7  christos {
   4710   1.1.1.7  christos   bfd *obfd = info->output_bfd;
   4711       1.1  christos 
   4712       1.1  christos   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
   4713  1.1.1.10  christos       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
   4714       1.1  christos     return true;
   4715       1.1  christos 
   4716       1.1  christos   if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
   4717       1.1  christos       && bfd_get_mach (obfd) < bfd_get_mach (ibfd))
   4718       1.1  christos     {
   4719       1.1  christos       if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
   4720  1.1.1.10  christos 			       bfd_get_mach (ibfd)))
   4721       1.1  christos 	return false;
   4722       1.1  christos     }
   4723  1.1.1.10  christos 
   4724       1.1  christos   return true;
   4725       1.1  christos }
   4726       1.1  christos 
   4727       1.1  christos #define PLT0_ENTRY_SIZE     15
   4728       1.1  christos #define PLT_ENTRY_SIZE      20
   4729       1.1  christos #define PIC_PLT_ENTRY_SIZE  24
   4730       1.1  christos 
   4731       1.1  christos static const bfd_byte elf_mn10300_plt0_entry[PLT0_ENTRY_SIZE] =
   4732       1.1  christos {
   4733       1.1  christos   0xfc, 0xa0, 0, 0, 0, 0,	/* mov	(.got+8),a0 */
   4734       1.1  christos   0xfe, 0xe, 0x10, 0, 0, 0, 0,	/* mov	(.got+4),r1 */
   4735       1.1  christos   0xf0, 0xf4,			/* jmp	(a0) */
   4736       1.1  christos };
   4737       1.1  christos 
   4738       1.1  christos static const bfd_byte elf_mn10300_plt_entry[PLT_ENTRY_SIZE] =
   4739       1.1  christos {
   4740       1.1  christos   0xfc, 0xa0, 0, 0, 0, 0,	/* mov	(nameN@GOT + .got),a0 */
   4741       1.1  christos   0xf0, 0xf4,			/* jmp	(a0) */
   4742       1.1  christos   0xfe, 8, 0, 0, 0, 0, 0,	/* mov	reloc-table-address,r0 */
   4743       1.1  christos   0xdc, 0, 0, 0, 0,		/* jmp	.plt0 */
   4744       1.1  christos };
   4745       1.1  christos 
   4746       1.1  christos static const bfd_byte elf_mn10300_pic_plt_entry[PIC_PLT_ENTRY_SIZE] =
   4747       1.1  christos {
   4748       1.1  christos   0xfc, 0x22, 0, 0, 0, 0,	/* mov	(nameN@GOT,a2),a0 */
   4749       1.1  christos   0xf0, 0xf4,			/* jmp	(a0) */
   4750       1.1  christos   0xfe, 8, 0, 0, 0, 0, 0,	/* mov	reloc-table-address,r0 */
   4751       1.1  christos   0xf8, 0x22, 8,		/* mov	(8,a2),a0 */
   4752       1.1  christos   0xfb, 0xa, 0x1a, 4,		/* mov	(4,a2),r1 */
   4753       1.1  christos   0xf0, 0xf4,			/* jmp	(a0) */
   4754       1.1  christos };
   4755       1.1  christos 
   4756       1.1  christos /* Return size of the first PLT entry.  */
   4757   1.1.1.6  christos #define elf_mn10300_sizeof_plt0(info) \
   4758       1.1  christos   (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE)
   4759       1.1  christos 
   4760       1.1  christos /* Return size of a PLT entry.  */
   4761   1.1.1.6  christos #define elf_mn10300_sizeof_plt(info) \
   4762       1.1  christos   (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE)
   4763       1.1  christos 
   4764       1.1  christos /* Return offset of the PLT0 address in an absolute PLT entry.  */
   4765       1.1  christos #define elf_mn10300_plt_plt0_offset(info) 16
   4766       1.1  christos 
   4767       1.1  christos /* Return offset of the linker in PLT0 entry.  */
   4768       1.1  christos #define elf_mn10300_plt0_linker_offset(info) 2
   4769       1.1  christos 
   4770       1.1  christos /* Return offset of the GOT id in PLT0 entry.  */
   4771       1.1  christos #define elf_mn10300_plt0_gotid_offset(info) 9
   4772       1.1  christos 
   4773       1.1  christos /* Return offset of the temporary in PLT entry.  */
   4774       1.1  christos #define elf_mn10300_plt_temp_offset(info) 8
   4775       1.1  christos 
   4776       1.1  christos /* Return offset of the symbol in PLT entry.  */
   4777       1.1  christos #define elf_mn10300_plt_symbol_offset(info) 2
   4778       1.1  christos 
   4779       1.1  christos /* Return offset of the relocation in PLT entry.  */
   4780       1.1  christos #define elf_mn10300_plt_reloc_offset(info) 11
   4781       1.1  christos 
   4782       1.1  christos /* The name of the dynamic interpreter.  This is put in the .interp
   4783       1.1  christos    section.  */
   4784       1.1  christos 
   4785       1.1  christos #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
   4786       1.1  christos 
   4787       1.1  christos /* Create dynamic sections when linking against a dynamic object.  */
   4788  1.1.1.10  christos 
   4789       1.1  christos static bool
   4790       1.1  christos _bfd_mn10300_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   4791       1.1  christos {
   4792       1.1  christos   flagword   flags;
   4793       1.1  christos   asection * s;
   4794   1.1.1.2  christos   const struct elf_backend_data * bed = get_elf_backend_data (abfd);
   4795       1.1  christos   struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   4796       1.1  christos   int ptralign = 0;
   4797       1.1  christos 
   4798       1.1  christos   switch (bed->s->arch_size)
   4799       1.1  christos     {
   4800       1.1  christos     case 32:
   4801       1.1  christos       ptralign = 2;
   4802       1.1  christos       break;
   4803       1.1  christos 
   4804       1.1  christos     case 64:
   4805       1.1  christos       ptralign = 3;
   4806       1.1  christos       break;
   4807       1.1  christos 
   4808       1.1  christos     default:
   4809  1.1.1.10  christos       bfd_set_error (bfd_error_bad_value);
   4810       1.1  christos       return false;
   4811       1.1  christos     }
   4812       1.1  christos 
   4813       1.1  christos   /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
   4814       1.1  christos      .rel[a].bss sections.  */
   4815       1.1  christos   flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
   4816       1.1  christos 	   | SEC_LINKER_CREATED);
   4817   1.1.1.2  christos 
   4818   1.1.1.2  christos   s = bfd_make_section_anyway_with_flags (abfd,
   4819   1.1.1.2  christos 					  (bed->default_use_rela_p
   4820   1.1.1.2  christos 					   ? ".rela.plt" : ".rel.plt"),
   4821   1.1.1.2  christos 					  flags | SEC_READONLY);
   4822       1.1  christos   htab->root.srelplt = s;
   4823   1.1.1.9  christos   if (s == NULL
   4824  1.1.1.10  christos       || !bfd_set_section_alignment (s, ptralign))
   4825       1.1  christos     return false;
   4826       1.1  christos 
   4827  1.1.1.10  christos   if (! _bfd_mn10300_elf_create_got_section (abfd, info))
   4828       1.1  christos     return false;
   4829       1.1  christos 
   4830       1.1  christos   if (bed->want_dynbss)
   4831       1.1  christos     {
   4832       1.1  christos       /* The .dynbss section is a place to put symbols which are defined
   4833       1.1  christos 	 by dynamic objects, are referenced by regular objects, and are
   4834       1.1  christos 	 not functions.  We must allocate space for them in the process
   4835       1.1  christos 	 image and use a R_*_COPY reloc to tell the dynamic linker to
   4836       1.1  christos 	 initialize them at run time.  The linker script puts the .dynbss
   4837   1.1.1.2  christos 	 section into the .bss section of the final image.  */
   4838   1.1.1.2  christos       s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
   4839       1.1  christos 					      SEC_ALLOC | SEC_LINKER_CREATED);
   4840  1.1.1.10  christos       if (s == NULL)
   4841       1.1  christos 	return false;
   4842       1.1  christos 
   4843       1.1  christos       /* The .rel[a].bss section holds copy relocs.  This section is not
   4844       1.1  christos 	 normally needed.  We need to create it here, though, so that the
   4845       1.1  christos 	 linker will map it to an output section.  We can't just create it
   4846       1.1  christos 	 only if we need it, because we will not know whether we need it
   4847       1.1  christos 	 until we have seen all the input files, and the first time the
   4848       1.1  christos 	 main linker code calls BFD after examining all the input files
   4849       1.1  christos 	 (size_dynamic_sections) the input sections have already been
   4850       1.1  christos 	 mapped to the output sections.  If the section turns out not to
   4851       1.1  christos 	 be needed, we can discard it later.  We will never need this
   4852       1.1  christos 	 section when generating a shared object, since they do not use
   4853   1.1.1.6  christos 	 copy relocs.  */
   4854       1.1  christos       if (! bfd_link_pic (info))
   4855   1.1.1.2  christos 	{
   4856   1.1.1.2  christos 	  s = bfd_make_section_anyway_with_flags (abfd,
   4857   1.1.1.2  christos 						  (bed->default_use_rela_p
   4858   1.1.1.2  christos 						   ? ".rela.bss" : ".rel.bss"),
   4859       1.1  christos 						  flags | SEC_READONLY);
   4860   1.1.1.9  christos 	  if (s == NULL
   4861  1.1.1.10  christos 	      || !bfd_set_section_alignment (s, ptralign))
   4862       1.1  christos 	    return false;
   4863       1.1  christos 	}
   4864       1.1  christos     }
   4865  1.1.1.10  christos 
   4866       1.1  christos   return true;
   4867       1.1  christos }
   4868       1.1  christos 
   4869       1.1  christos /* Adjust a symbol defined by a dynamic object and referenced by a
   4871       1.1  christos    regular object.  The current definition is in some section of the
   4872       1.1  christos    dynamic object, but we're not including those sections.  We have to
   4873       1.1  christos    change the definition to something the rest of the link can
   4874  1.1.1.10  christos    understand.  */
   4875       1.1  christos 
   4876       1.1  christos static bool
   4877       1.1  christos _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info,
   4878   1.1.1.2  christos 					struct elf_link_hash_entry * h)
   4879       1.1  christos {
   4880       1.1  christos   struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   4881       1.1  christos   bfd * dynobj;
   4882   1.1.1.2  christos   asection * s;
   4883       1.1  christos 
   4884       1.1  christos   dynobj = htab->root.dynobj;
   4885       1.1  christos 
   4886       1.1  christos   /* Make sure we know what is going on here.  */
   4887   1.1.1.8  christos   BFD_ASSERT (dynobj != NULL
   4888       1.1  christos 	      && (h->needs_plt
   4889       1.1  christos 		  || h->is_weakalias
   4890       1.1  christos 		  || (h->def_dynamic
   4891       1.1  christos 		      && h->ref_regular
   4892       1.1  christos 		      && !h->def_regular)));
   4893       1.1  christos 
   4894       1.1  christos   /* If this is a function, put it in the procedure linkage table.  We
   4895       1.1  christos      will fill in the contents of the procedure linkage table later,
   4896       1.1  christos      when we know the address of the .got section.  */
   4897       1.1  christos   if (h->type == STT_FUNC
   4898   1.1.1.6  christos       || h->needs_plt)
   4899       1.1  christos     {
   4900       1.1  christos       if (! bfd_link_pic (info)
   4901       1.1  christos 	  && !h->def_dynamic
   4902       1.1  christos 	  && !h->ref_dynamic)
   4903       1.1  christos 	{
   4904       1.1  christos 	  /* This case can occur if we saw a PLT reloc in an input
   4905       1.1  christos 	     file, but the symbol was never referred to by a dynamic
   4906       1.1  christos 	     object.  In such a case, we don't actually need to build
   4907       1.1  christos 	     a procedure linkage table, and we can just do a REL32
   4908  1.1.1.10  christos 	     reloc instead.  */
   4909       1.1  christos 	  BFD_ASSERT (h->needs_plt);
   4910       1.1  christos 	  return true;
   4911       1.1  christos 	}
   4912       1.1  christos 
   4913       1.1  christos       /* Make sure this symbol is output as a dynamic symbol.  */
   4914       1.1  christos       if (h->dynindx == -1)
   4915  1.1.1.10  christos 	{
   4916       1.1  christos 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
   4917       1.1  christos 	    return false;
   4918   1.1.1.2  christos 	}
   4919       1.1  christos 
   4920       1.1  christos       s = htab->root.splt;
   4921       1.1  christos       BFD_ASSERT (s != NULL);
   4922       1.1  christos 
   4923       1.1  christos       /* If this is the first .plt entry, make room for the special
   4924       1.1  christos 	 first entry.  */
   4925       1.1  christos       if (s->size == 0)
   4926       1.1  christos 	s->size += elf_mn10300_sizeof_plt0 (info);
   4927       1.1  christos 
   4928       1.1  christos       /* If this symbol is not defined in a regular file, and we are
   4929       1.1  christos 	 not generating a shared library, then set the symbol to this
   4930       1.1  christos 	 location in the .plt.  This is required to make function
   4931   1.1.1.6  christos 	 pointers compare as equal between the normal executable and
   4932       1.1  christos 	 the shared library.  */
   4933       1.1  christos       if (! bfd_link_pic (info)
   4934       1.1  christos 	  && !h->def_regular)
   4935       1.1  christos 	{
   4936       1.1  christos 	  h->root.u.def.section = s;
   4937       1.1  christos 	  h->root.u.def.value = s->size;
   4938       1.1  christos 	}
   4939       1.1  christos 
   4940       1.1  christos       h->plt.offset = s->size;
   4941       1.1  christos 
   4942       1.1  christos       /* Make room for this entry.  */
   4943       1.1  christos       s->size += elf_mn10300_sizeof_plt (info);
   4944       1.1  christos 
   4945   1.1.1.2  christos       /* We also need to make an entry in the .got.plt section, which
   4946       1.1  christos 	 will be placed in the .got section by the linker script.  */
   4947       1.1  christos       s = htab->root.sgotplt;
   4948       1.1  christos       BFD_ASSERT (s != NULL);
   4949       1.1  christos       s->size += 4;
   4950   1.1.1.7  christos 
   4951       1.1  christos       /* We also need to make an entry in the .rela.plt section.  */
   4952       1.1  christos       s = htab->root.srelplt;
   4953       1.1  christos       BFD_ASSERT (s != NULL);
   4954  1.1.1.10  christos       s->size += sizeof (Elf32_External_Rela);
   4955       1.1  christos 
   4956       1.1  christos       return true;
   4957       1.1  christos     }
   4958       1.1  christos 
   4959       1.1  christos   /* If this is a weak symbol, and there is a real definition, the
   4960   1.1.1.8  christos      processor independent code will have arranged for us to see the
   4961       1.1  christos      real definition first, and we can just use the same value.  */
   4962   1.1.1.8  christos   if (h->is_weakalias)
   4963   1.1.1.8  christos     {
   4964   1.1.1.8  christos       struct elf_link_hash_entry *def = weakdef (h);
   4965   1.1.1.8  christos       BFD_ASSERT (def->root.type == bfd_link_hash_defined);
   4966  1.1.1.10  christos       h->root.u.def.section = def->root.u.def.section;
   4967       1.1  christos       h->root.u.def.value = def->root.u.def.value;
   4968       1.1  christos       return true;
   4969       1.1  christos     }
   4970       1.1  christos 
   4971       1.1  christos   /* This is a reference to a symbol defined by a dynamic object which
   4972       1.1  christos      is not a function.  */
   4973       1.1  christos 
   4974       1.1  christos   /* If we are creating a shared library, we must presume that the
   4975       1.1  christos      only references to the symbol are via the global offset table.
   4976   1.1.1.6  christos      For such cases we need not do anything here; the relocations will
   4977  1.1.1.10  christos      be handled correctly by relocate_section.  */
   4978       1.1  christos   if (bfd_link_pic (info))
   4979       1.1  christos     return true;
   4980       1.1  christos 
   4981       1.1  christos   /* If there are no references to this symbol that do not use the
   4982  1.1.1.10  christos      GOT, we don't need to generate a copy reloc.  */
   4983       1.1  christos   if (!h->non_got_ref)
   4984       1.1  christos     return true;
   4985       1.1  christos 
   4986       1.1  christos   /* We must allocate the symbol in our .dynbss section, which will
   4987       1.1  christos      become part of the .bss section of the executable.  There will be
   4988       1.1  christos      an entry for this symbol in the .dynsym section.  The dynamic
   4989       1.1  christos      object will contain position independent code, so all references
   4990       1.1  christos      from the dynamic object to this symbol will go through the global
   4991       1.1  christos      offset table.  The dynamic linker will use the .dynsym entry to
   4992       1.1  christos      determine the address it must put in the global offset table, so
   4993       1.1  christos      both the dynamic object and the regular object will refer to the
   4994   1.1.1.2  christos      same memory location for the variable.  */
   4995       1.1  christos 
   4996       1.1  christos   s = bfd_get_linker_section (dynobj, ".dynbss");
   4997       1.1  christos   BFD_ASSERT (s != NULL);
   4998       1.1  christos 
   4999       1.1  christos   /* We must generate a R_MN10300_COPY reloc to tell the dynamic linker to
   5000       1.1  christos      copy the initial value out of the dynamic object and into the
   5001   1.1.1.2  christos      runtime process image.  We need to remember the offset into the
   5002       1.1  christos      .rela.bss section we are going to use.  */
   5003       1.1  christos   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
   5004       1.1  christos     {
   5005   1.1.1.2  christos       asection * srel;
   5006       1.1  christos 
   5007       1.1  christos       srel = bfd_get_linker_section (dynobj, ".rela.bss");
   5008       1.1  christos       BFD_ASSERT (srel != NULL);
   5009       1.1  christos       srel->size += sizeof (Elf32_External_Rela);
   5010       1.1  christos       h->needs_copy = 1;
   5011   1.1.1.4  christos     }
   5012       1.1  christos 
   5013       1.1  christos   return _bfd_elf_adjust_dynamic_copy (info, h, s);
   5014       1.1  christos }
   5015       1.1  christos 
   5016  1.1.1.10  christos /* Set the sizes of the dynamic sections.  */
   5017  1.1.1.11  christos 
   5018  1.1.1.11  christos static bool
   5019       1.1  christos _bfd_mn10300_elf_late_size_sections (bfd * output_bfd,
   5020   1.1.1.2  christos 				     struct bfd_link_info * info)
   5021       1.1  christos {
   5022       1.1  christos   struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   5023  1.1.1.10  christos   bfd * dynobj;
   5024       1.1  christos   asection * s;
   5025   1.1.1.2  christos   bool relocs;
   5026  1.1.1.11  christos 
   5027  1.1.1.11  christos   dynobj = htab->root.dynobj;
   5028       1.1  christos   if (dynobj == NULL)
   5029       1.1  christos     return true;
   5030       1.1  christos 
   5031       1.1  christos   if (elf_hash_table (info)->dynamic_sections_created)
   5032   1.1.1.7  christos     {
   5033       1.1  christos       /* Set the contents of the .interp section to the interpreter.  */
   5034   1.1.1.2  christos       if (bfd_link_executable (info) && !info->nointerp)
   5035       1.1  christos 	{
   5036       1.1  christos 	  s = bfd_get_linker_section (dynobj, ".interp");
   5037       1.1  christos 	  BFD_ASSERT (s != NULL);
   5038  1.1.1.13  christos 	  s->size = sizeof ELF_DYNAMIC_INTERPRETER;
   5039       1.1  christos 	  s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
   5040       1.1  christos 	  s->alloced = 1;
   5041       1.1  christos 	}
   5042       1.1  christos     }
   5043       1.1  christos   else
   5044       1.1  christos     {
   5045       1.1  christos       /* We may have created entries in the .rela.got section.
   5046       1.1  christos 	 However, if we are not creating the dynamic sections, we will
   5047       1.1  christos 	 not actually use these entries.  Reset the size of .rela.got,
   5048   1.1.1.2  christos 	 which will cause it to get stripped from the output file
   5049       1.1  christos 	 below.  */
   5050       1.1  christos       s = htab->root.sgot;
   5051       1.1  christos       if (s != NULL)
   5052       1.1  christos 	s->size = 0;
   5053   1.1.1.2  christos     }
   5054   1.1.1.2  christos 
   5055   1.1.1.7  christos   if (htab->tls_ldm_got.refcount > 0)
   5056   1.1.1.2  christos     {
   5057   1.1.1.2  christos       s = htab->root.srelgot;
   5058   1.1.1.2  christos       BFD_ASSERT (s != NULL);
   5059   1.1.1.2  christos       s->size += sizeof (Elf32_External_Rela);
   5060       1.1  christos     }
   5061       1.1  christos 
   5062       1.1  christos   /* The check_relocs and adjust_dynamic_symbol entry points have
   5063  1.1.1.10  christos      determined the sizes of the various dynamic sections.  Allocate
   5064       1.1  christos      memory for them.  */
   5065       1.1  christos   relocs = false;
   5066       1.1  christos   for (s = dynobj->sections; s != NULL; s = s->next)
   5067       1.1  christos     {
   5068       1.1  christos       const char * name;
   5069       1.1  christos 
   5070       1.1  christos       if ((s->flags & SEC_LINKER_CREATED) == 0)
   5071       1.1  christos 	continue;
   5072       1.1  christos 
   5073   1.1.1.9  christos       /* It's OK to base decisions on the section name, because none
   5074       1.1  christos 	 of the dynobj section names depend upon the input files.  */
   5075       1.1  christos       name = bfd_section_name (s);
   5076       1.1  christos 
   5077       1.1  christos       if (streq (name, ".plt"))
   5078   1.1.1.9  christos 	{
   5079       1.1  christos 	  /* Remember whether there is a PLT.  */
   5080  1.1.1.10  christos 	  ;
   5081       1.1  christos 	}
   5082       1.1  christos       else if (startswith (name, ".rela"))
   5083       1.1  christos 	{
   5084       1.1  christos 	  if (s->size != 0)
   5085       1.1  christos 	    {
   5086       1.1  christos 	      /* Remember whether there are any reloc sections other
   5087  1.1.1.10  christos 		 than .rela.plt.  */
   5088       1.1  christos 	      if (! streq (name, ".rela.plt"))
   5089       1.1  christos 		relocs = true;
   5090       1.1  christos 
   5091       1.1  christos 	      /* We use the reloc_count field as a counter if we need
   5092       1.1  christos 		 to copy relocs into the output file.  */
   5093       1.1  christos 	      s->reloc_count = 0;
   5094  1.1.1.10  christos 	    }
   5095       1.1  christos 	}
   5096       1.1  christos       else if (! startswith (name, ".got")
   5097       1.1  christos 	       && ! streq (name, ".dynbss"))
   5098       1.1  christos 	/* It's not one of our sections, so don't allocate space.  */
   5099       1.1  christos 	continue;
   5100       1.1  christos 
   5101       1.1  christos       if (s->size == 0)
   5102       1.1  christos 	{
   5103       1.1  christos 	  /* If we don't need this section, strip it from the
   5104       1.1  christos 	     output file.  This is mostly to handle .rela.bss and
   5105       1.1  christos 	     .rela.plt.  We must create both sections in
   5106       1.1  christos 	     create_dynamic_sections, because they must be created
   5107       1.1  christos 	     before the linker maps input sections to output
   5108       1.1  christos 	     sections.  The linker does that before
   5109       1.1  christos 	     adjust_dynamic_symbol is called, and it is that
   5110       1.1  christos 	     function which decides whether anything needs to go
   5111       1.1  christos 	     into these sections.  */
   5112       1.1  christos 	  s->flags |= SEC_EXCLUDE;
   5113       1.1  christos 	  continue;
   5114       1.1  christos 	}
   5115       1.1  christos 
   5116       1.1  christos 	if ((s->flags & SEC_HAS_CONTENTS) == 0)
   5117       1.1  christos 	  continue;
   5118       1.1  christos 
   5119       1.1  christos       /* Allocate memory for the section contents.  We use bfd_zalloc
   5120       1.1  christos 	 here in case unused entries are not reclaimed before the
   5121       1.1  christos 	 section's contents are written out.  This should not happen,
   5122       1.1  christos 	 but this way if it does, we get a R_MN10300_NONE reloc
   5123       1.1  christos 	 instead of garbage.  */
   5124  1.1.1.10  christos       s->contents = bfd_zalloc (dynobj, s->size);
   5125  1.1.1.13  christos       if (s->contents == NULL)
   5126       1.1  christos 	return false;
   5127       1.1  christos       s->alloced = 1;
   5128   1.1.1.9  christos     }
   5129       1.1  christos 
   5130       1.1  christos   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
   5131       1.1  christos }
   5132       1.1  christos 
   5133       1.1  christos /* Finish up dynamic symbol handling.  We set the contents of various
   5134  1.1.1.10  christos    dynamic sections here.  */
   5135       1.1  christos 
   5136       1.1  christos static bool
   5137       1.1  christos _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd,
   5138       1.1  christos 					struct bfd_link_info * info,
   5139       1.1  christos 					struct elf_link_hash_entry * h,
   5140   1.1.1.2  christos 					Elf_Internal_Sym * sym)
   5141       1.1  christos {
   5142       1.1  christos   struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   5143   1.1.1.2  christos   bfd * dynobj;
   5144       1.1  christos 
   5145       1.1  christos   dynobj = htab->root.dynobj;
   5146       1.1  christos 
   5147   1.1.1.8  christos   if (h->plt.offset != (bfd_vma) -1)
   5148   1.1.1.8  christos     {
   5149   1.1.1.8  christos       asection *	splt;
   5150   1.1.1.8  christos       asection *	sgot;
   5151   1.1.1.8  christos       asection *	srel;
   5152       1.1  christos       bfd_vma		plt_index;
   5153       1.1  christos       bfd_vma		got_offset;
   5154       1.1  christos       Elf_Internal_Rela rel;
   5155       1.1  christos 
   5156       1.1  christos       /* This symbol has an entry in the procedure linkage table.  Set
   5157       1.1  christos 	 it up.  */
   5158       1.1  christos 
   5159   1.1.1.2  christos       BFD_ASSERT (h->dynindx != -1);
   5160   1.1.1.2  christos 
   5161   1.1.1.7  christos       splt = htab->root.splt;
   5162       1.1  christos       sgot = htab->root.sgotplt;
   5163       1.1  christos       srel = htab->root.srelplt;
   5164       1.1  christos       BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
   5165       1.1  christos 
   5166       1.1  christos       /* Get the index in the procedure linkage table which
   5167       1.1  christos 	 corresponds to this symbol.  This is the index of this symbol
   5168       1.1  christos 	 in all the symbols for which we are making plt entries.  The
   5169       1.1  christos 	 first entry in the procedure linkage table is reserved.  */
   5170       1.1  christos       plt_index = ((h->plt.offset - elf_mn10300_sizeof_plt0 (info))
   5171       1.1  christos 		   / elf_mn10300_sizeof_plt (info));
   5172       1.1  christos 
   5173       1.1  christos       /* Get the offset into the .got table of the entry that
   5174       1.1  christos 	 corresponds to this function.  Each .got entry is 4 bytes.
   5175       1.1  christos 	 The first three are reserved.  */
   5176       1.1  christos       got_offset = (plt_index + 3) * 4;
   5177   1.1.1.6  christos 
   5178       1.1  christos       /* Fill in the entry in the procedure linkage table.  */
   5179       1.1  christos       if (! bfd_link_pic (info))
   5180       1.1  christos 	{
   5181       1.1  christos 	  memcpy (splt->contents + h->plt.offset, elf_mn10300_plt_entry,
   5182       1.1  christos 		  elf_mn10300_sizeof_plt (info));
   5183       1.1  christos 	  bfd_put_32 (output_bfd,
   5184       1.1  christos 		      (sgot->output_section->vma
   5185       1.1  christos 		       + sgot->output_offset
   5186       1.1  christos 		       + got_offset),
   5187       1.1  christos 		      (splt->contents + h->plt.offset
   5188       1.1  christos 		       + elf_mn10300_plt_symbol_offset (info)));
   5189       1.1  christos 
   5190       1.1  christos 	  bfd_put_32 (output_bfd,
   5191       1.1  christos 		      (1 - h->plt.offset - elf_mn10300_plt_plt0_offset (info)),
   5192       1.1  christos 		      (splt->contents + h->plt.offset
   5193       1.1  christos 		       + elf_mn10300_plt_plt0_offset (info)));
   5194       1.1  christos 	}
   5195       1.1  christos       else
   5196       1.1  christos 	{
   5197       1.1  christos 	  memcpy (splt->contents + h->plt.offset, elf_mn10300_pic_plt_entry,
   5198       1.1  christos 		  elf_mn10300_sizeof_plt (info));
   5199       1.1  christos 
   5200       1.1  christos 	  bfd_put_32 (output_bfd, got_offset,
   5201       1.1  christos 		      (splt->contents + h->plt.offset
   5202       1.1  christos 		       + elf_mn10300_plt_symbol_offset (info)));
   5203       1.1  christos 	}
   5204       1.1  christos 
   5205       1.1  christos       bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
   5206       1.1  christos 		  (splt->contents + h->plt.offset
   5207       1.1  christos 		   + elf_mn10300_plt_reloc_offset (info)));
   5208       1.1  christos 
   5209       1.1  christos       /* Fill in the entry in the global offset table.  */
   5210       1.1  christos       bfd_put_32 (output_bfd,
   5211       1.1  christos 		  (splt->output_section->vma
   5212       1.1  christos 		   + splt->output_offset
   5213       1.1  christos 		   + h->plt.offset
   5214       1.1  christos 		   + elf_mn10300_plt_temp_offset (info)),
   5215       1.1  christos 		  sgot->contents + got_offset);
   5216       1.1  christos 
   5217       1.1  christos       /* Fill in the entry in the .rela.plt section.  */
   5218       1.1  christos       rel.r_offset = (sgot->output_section->vma
   5219       1.1  christos 		      + sgot->output_offset
   5220       1.1  christos 		      + got_offset);
   5221       1.1  christos       rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_JMP_SLOT);
   5222       1.1  christos       rel.r_addend = 0;
   5223       1.1  christos       bfd_elf32_swap_reloca_out (output_bfd, &rel,
   5224       1.1  christos 				 (bfd_byte *) ((Elf32_External_Rela *) srel->contents
   5225       1.1  christos 					       + plt_index));
   5226       1.1  christos 
   5227       1.1  christos       if (!h->def_regular)
   5228       1.1  christos 	/* Mark the symbol as undefined, rather than as defined in
   5229       1.1  christos 	   the .plt section.  Leave the value alone.  */
   5230       1.1  christos 	sym->st_shndx = SHN_UNDEF;
   5231       1.1  christos     }
   5232       1.1  christos 
   5233   1.1.1.8  christos   if (h->got.offset != (bfd_vma) -1)
   5234   1.1.1.8  christos     {
   5235       1.1  christos       asection *	sgot;
   5236       1.1  christos       asection *	srel;
   5237       1.1  christos       Elf_Internal_Rela rel;
   5238   1.1.1.2  christos 
   5239   1.1.1.7  christos       /* This symbol has an entry in the global offset table.  Set it up.  */
   5240       1.1  christos       sgot = htab->root.sgot;
   5241       1.1  christos       srel = htab->root.srelgot;
   5242       1.1  christos       BFD_ASSERT (sgot != NULL && srel != NULL);
   5243       1.1  christos 
   5244       1.1  christos       rel.r_offset = (sgot->output_section->vma
   5245       1.1  christos 		      + sgot->output_offset
   5246   1.1.1.2  christos 		      + (h->got.offset & ~1));
   5247       1.1  christos 
   5248   1.1.1.2  christos       switch (elf_mn10300_hash_entry (h)->tls_type)
   5249       1.1  christos 	{
   5250   1.1.1.2  christos 	case GOT_TLS_GD:
   5251   1.1.1.2  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
   5252   1.1.1.2  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset + 4);
   5253   1.1.1.2  christos 	  rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_DTPMOD);
   5254   1.1.1.2  christos 	  rel.r_addend = 0;
   5255   1.1.1.2  christos 	  bfd_elf32_swap_reloca_out (output_bfd, & rel,
   5256   1.1.1.2  christos 				     (bfd_byte *) ((Elf32_External_Rela *) srel->contents
   5257   1.1.1.2  christos 						   + srel->reloc_count));
   5258   1.1.1.2  christos 	  ++ srel->reloc_count;
   5259       1.1  christos 	  rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_DTPOFF);
   5260   1.1.1.2  christos 	  rel.r_offset += 4;
   5261   1.1.1.2  christos 	  rel.r_addend = 0;
   5262   1.1.1.2  christos 	  break;
   5263   1.1.1.2  christos 
   5264   1.1.1.2  christos 	case GOT_TLS_IE:
   5265   1.1.1.2  christos 	  /* We originally stored the addend in the GOT, but at this
   5266   1.1.1.2  christos 	     point, we want to move it to the reloc instead as that's
   5267   1.1.1.2  christos 	     where the dynamic linker wants it.  */
   5268   1.1.1.2  christos 	  rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + h->got.offset);
   5269   1.1.1.2  christos 	  bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
   5270   1.1.1.2  christos 	  if (h->dynindx == -1)
   5271   1.1.1.2  christos 	    rel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_TPOFF);
   5272   1.1.1.2  christos 	  else
   5273   1.1.1.2  christos 	    rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_TLS_TPOFF);
   5274   1.1.1.2  christos 	  break;
   5275   1.1.1.2  christos 
   5276   1.1.1.2  christos 	default:
   5277   1.1.1.2  christos 	  /* If this is a -Bsymbolic link, and the symbol is defined
   5278   1.1.1.2  christos 	     locally, we just want to emit a RELATIVE reloc.  Likewise if
   5279   1.1.1.2  christos 	     the symbol was forced to be local because of a version file.
   5280   1.1.1.6  christos 	     The entry in the global offset table will already have been
   5281   1.1.1.2  christos 	     initialized in the relocate_section function.  */
   5282   1.1.1.2  christos 	  if (bfd_link_pic (info)
   5283   1.1.1.2  christos 	      && (info->symbolic || h->dynindx == -1)
   5284   1.1.1.2  christos 	      && h->def_regular)
   5285   1.1.1.2  christos 	    {
   5286   1.1.1.2  christos 	      rel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
   5287   1.1.1.2  christos 	      rel.r_addend = (h->root.u.def.value
   5288   1.1.1.2  christos 			      + h->root.u.def.section->output_section->vma
   5289   1.1.1.2  christos 			      + h->root.u.def.section->output_offset);
   5290   1.1.1.2  christos 	    }
   5291   1.1.1.2  christos 	  else
   5292   1.1.1.2  christos 	    {
   5293   1.1.1.2  christos 	      bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
   5294   1.1.1.2  christos 	      rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_GLOB_DAT);
   5295       1.1  christos 	      rel.r_addend = 0;
   5296       1.1  christos 	    }
   5297   1.1.1.2  christos 	}
   5298   1.1.1.2  christos 
   5299   1.1.1.2  christos       if (ELF32_R_TYPE (rel.r_info) != R_MN10300_NONE)
   5300   1.1.1.2  christos 	{
   5301   1.1.1.2  christos 	  bfd_elf32_swap_reloca_out (output_bfd, &rel,
   5302   1.1.1.2  christos 				     (bfd_byte *) ((Elf32_External_Rela *) srel->contents
   5303   1.1.1.2  christos 						   + srel->reloc_count));
   5304       1.1  christos 	  ++ srel->reloc_count;
   5305       1.1  christos 	}
   5306       1.1  christos     }
   5307       1.1  christos 
   5308   1.1.1.8  christos   if (h->needs_copy)
   5309       1.1  christos     {
   5310       1.1  christos       asection *	s;
   5311       1.1  christos       Elf_Internal_Rela rel;
   5312       1.1  christos 
   5313       1.1  christos       /* This symbol needs a copy reloc.  Set it up.  */
   5314       1.1  christos       BFD_ASSERT (h->dynindx != -1
   5315       1.1  christos 		  && (h->root.type == bfd_link_hash_defined
   5316   1.1.1.2  christos 		      || h->root.type == bfd_link_hash_defweak));
   5317       1.1  christos 
   5318       1.1  christos       s = bfd_get_linker_section (dynobj, ".rela.bss");
   5319       1.1  christos       BFD_ASSERT (s != NULL);
   5320       1.1  christos 
   5321       1.1  christos       rel.r_offset = (h->root.u.def.value
   5322       1.1  christos 		      + h->root.u.def.section->output_section->vma
   5323       1.1  christos 		      + h->root.u.def.section->output_offset);
   5324       1.1  christos       rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_COPY);
   5325       1.1  christos       rel.r_addend = 0;
   5326       1.1  christos       bfd_elf32_swap_reloca_out (output_bfd, & rel,
   5327       1.1  christos 				 (bfd_byte *) ((Elf32_External_Rela *) s->contents
   5328       1.1  christos 					       + s->reloc_count));
   5329       1.1  christos       ++ s->reloc_count;
   5330       1.1  christos     }
   5331   1.1.1.2  christos 
   5332       1.1  christos   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
   5333       1.1  christos   if (h == elf_hash_table (info)->hdynamic
   5334       1.1  christos       || h == elf_hash_table (info)->hgot)
   5335  1.1.1.10  christos     sym->st_shndx = SHN_ABS;
   5336       1.1  christos 
   5337       1.1  christos   return true;
   5338       1.1  christos }
   5339       1.1  christos 
   5340  1.1.1.10  christos /* Finish up the dynamic sections.  */
   5341       1.1  christos 
   5342       1.1  christos static bool
   5343       1.1  christos _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd,
   5344       1.1  christos 					  struct bfd_link_info * info)
   5345       1.1  christos {
   5346       1.1  christos   bfd *      dynobj;
   5347   1.1.1.2  christos   asection * sgot;
   5348       1.1  christos   asection * sdyn;
   5349   1.1.1.2  christos   struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   5350   1.1.1.2  christos 
   5351       1.1  christos   dynobj = htab->root.dynobj;
   5352   1.1.1.2  christos   sgot = htab->root.sgotplt;
   5353       1.1  christos   BFD_ASSERT (sgot != NULL);
   5354       1.1  christos   sdyn = bfd_get_linker_section (dynobj, ".dynamic");
   5355       1.1  christos 
   5356   1.1.1.8  christos   if (elf_hash_table (info)->dynamic_sections_created)
   5357       1.1  christos     {
   5358       1.1  christos       asection *	   splt;
   5359       1.1  christos       Elf32_External_Dyn * dyncon;
   5360       1.1  christos       Elf32_External_Dyn * dynconend;
   5361       1.1  christos 
   5362       1.1  christos       BFD_ASSERT (sdyn != NULL);
   5363       1.1  christos 
   5364       1.1  christos       dyncon = (Elf32_External_Dyn *) sdyn->contents;
   5365       1.1  christos       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
   5366       1.1  christos 
   5367       1.1  christos       for (; dyncon < dynconend; dyncon++)
   5368       1.1  christos 	{
   5369       1.1  christos 	  Elf_Internal_Dyn dyn;
   5370       1.1  christos 	  asection * s;
   5371       1.1  christos 
   5372       1.1  christos 	  bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
   5373       1.1  christos 
   5374       1.1  christos 	  switch (dyn.d_tag)
   5375       1.1  christos 	    {
   5376       1.1  christos 	    default:
   5377       1.1  christos 	      break;
   5378   1.1.1.7  christos 
   5379       1.1  christos 	    case DT_PLTGOT:
   5380       1.1  christos 	      s = htab->root.sgot;
   5381       1.1  christos 	      goto get_vma;
   5382   1.1.1.7  christos 
   5383       1.1  christos 	    case DT_JMPREL:
   5384   1.1.1.6  christos 	      s = htab->root.srelplt;
   5385       1.1  christos 	    get_vma:
   5386       1.1  christos 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   5387       1.1  christos 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   5388       1.1  christos 	      break;
   5389   1.1.1.7  christos 
   5390       1.1  christos 	    case DT_PLTRELSZ:
   5391       1.1  christos 	      s = htab->root.srelplt;
   5392       1.1  christos 	      dyn.d_un.d_val = s->size;
   5393       1.1  christos 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   5394       1.1  christos 	      break;
   5395       1.1  christos 	    }
   5396       1.1  christos 	}
   5397   1.1.1.2  christos 
   5398       1.1  christos       /* Fill in the first entry in the procedure linkage table.  */
   5399       1.1  christos       splt = htab->root.splt;
   5400   1.1.1.6  christos       if (splt && splt->size > 0)
   5401       1.1  christos 	{
   5402       1.1  christos 	  if (bfd_link_pic (info))
   5403       1.1  christos 	    {
   5404       1.1  christos 	      memcpy (splt->contents, elf_mn10300_pic_plt_entry,
   5405       1.1  christos 		      elf_mn10300_sizeof_plt (info));
   5406       1.1  christos 	    }
   5407       1.1  christos 	  else
   5408       1.1  christos 	    {
   5409       1.1  christos 	      memcpy (splt->contents, elf_mn10300_plt0_entry, PLT0_ENTRY_SIZE);
   5410       1.1  christos 	      bfd_put_32 (output_bfd,
   5411       1.1  christos 			  sgot->output_section->vma + sgot->output_offset + 4,
   5412       1.1  christos 			  splt->contents + elf_mn10300_plt0_gotid_offset (info));
   5413       1.1  christos 	      bfd_put_32 (output_bfd,
   5414       1.1  christos 			  sgot->output_section->vma + sgot->output_offset + 8,
   5415       1.1  christos 			  splt->contents + elf_mn10300_plt0_linker_offset (info));
   5416       1.1  christos 	    }
   5417       1.1  christos 
   5418       1.1  christos 	  /* UnixWare sets the entsize of .plt to 4, although that doesn't
   5419   1.1.1.2  christos 	     really seem like the right value.  */
   5420   1.1.1.2  christos 	  elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
   5421   1.1.1.2  christos 
   5422   1.1.1.2  christos 	  /* UnixWare sets the entsize of .plt to 4, but this is incorrect
   5423   1.1.1.2  christos 	     as it means that the size of the PLT0 section (15 bytes) is not
   5424   1.1.1.2  christos 	     a multiple of the sh_entsize.  Some ELF tools flag this as an
   5425   1.1.1.2  christos 	     error.  We could pad PLT0 to 16 bytes, but that would introduce
   5426   1.1.1.2  christos 	     compatibilty issues with previous toolchains, so instead we
   5427       1.1  christos 	     just set the entry size to 1.  */
   5428       1.1  christos 	  elf_section_data (splt->output_section)->this_hdr.sh_entsize = 1;
   5429       1.1  christos 	}
   5430       1.1  christos     }
   5431       1.1  christos 
   5432       1.1  christos   /* Fill in the first three entries in the global offset table.  */
   5433       1.1  christos   if (sgot->size > 0)
   5434       1.1  christos     {
   5435       1.1  christos       if (sdyn == NULL)
   5436       1.1  christos 	bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
   5437       1.1  christos       else
   5438       1.1  christos 	bfd_put_32 (output_bfd,
   5439       1.1  christos 		    sdyn->output_section->vma + sdyn->output_offset,
   5440       1.1  christos 		    sgot->contents);
   5441       1.1  christos       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
   5442       1.1  christos       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
   5443       1.1  christos     }
   5444       1.1  christos 
   5445  1.1.1.10  christos   elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
   5446       1.1  christos 
   5447       1.1  christos   return true;
   5448       1.1  christos }
   5449       1.1  christos 
   5450       1.1  christos /* Classify relocation types, such that combreloc can sort them
   5451       1.1  christos    properly.  */
   5452   1.1.1.3  christos 
   5453   1.1.1.3  christos static enum elf_reloc_type_class
   5454   1.1.1.3  christos _bfd_mn10300_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
   5455       1.1  christos 				   const asection *rel_sec ATTRIBUTE_UNUSED,
   5456       1.1  christos 				   const Elf_Internal_Rela *rela)
   5457       1.1  christos {
   5458       1.1  christos   switch ((int) ELF32_R_TYPE (rela->r_info))
   5459       1.1  christos     {
   5460       1.1  christos     case R_MN10300_RELATIVE:	return reloc_class_relative;
   5461       1.1  christos     case R_MN10300_JMP_SLOT:	return reloc_class_plt;
   5462       1.1  christos     case R_MN10300_COPY:	return reloc_class_copy;
   5463       1.1  christos     default:			return reloc_class_normal;
   5464       1.1  christos     }
   5465   1.1.1.2  christos }
   5466   1.1.1.2  christos 
   5467  1.1.1.10  christos /* Allocate space for an MN10300 extension to the bfd elf data structure.  */
   5468   1.1.1.2  christos 
   5469   1.1.1.2  christos static bool
   5470  1.1.1.12  christos mn10300_elf_mkobject (bfd *abfd)
   5471   1.1.1.2  christos {
   5472   1.1.1.2  christos   return bfd_elf_allocate_object (abfd, sizeof (struct elf_mn10300_obj_tdata));
   5473   1.1.1.2  christos }
   5474   1.1.1.2  christos 
   5475       1.1  christos #define bfd_elf32_mkobject	mn10300_elf_mkobject
   5476   1.1.1.4  christos 
   5477       1.1  christos #ifndef ELF_ARCH
   5478       1.1  christos #define TARGET_LITTLE_SYM	mn10300_elf32_vec
   5479       1.1  christos #define TARGET_LITTLE_NAME	"elf32-mn10300"
   5480       1.1  christos #define ELF_ARCH		bfd_arch_mn10300
   5481       1.1  christos #define ELF_TARGET_ID		MN10300_ELF_DATA
   5482       1.1  christos #define ELF_MACHINE_CODE	EM_MN10300
   5483       1.1  christos #define ELF_MACHINE_ALT1	EM_CYGNUS_MN10300
   5484       1.1  christos #define ELF_MAXPAGESIZE		0x1000
   5485       1.1  christos #endif
   5486   1.1.1.8  christos 
   5487       1.1  christos #define elf_info_to_howto		mn10300_info_to_howto
   5488       1.1  christos #define elf_info_to_howto_rel		NULL
   5489       1.1  christos #define elf_backend_can_gc_sections	1
   5490       1.1  christos #define elf_backend_rela_normal		1
   5491       1.1  christos #define elf_backend_check_relocs	mn10300_elf_check_relocs
   5492       1.1  christos #define elf_backend_gc_mark_hook	mn10300_elf_gc_mark_hook
   5493       1.1  christos #define elf_backend_relocate_section	mn10300_elf_relocate_section
   5494       1.1  christos #define bfd_elf32_bfd_relax_section	mn10300_elf_relax_section
   5495       1.1  christos #define bfd_elf32_bfd_get_relocated_section_contents \
   5496       1.1  christos 				mn10300_elf_get_relocated_section_contents
   5497       1.1  christos #define bfd_elf32_bfd_link_hash_table_create \
   5498       1.1  christos 				elf32_mn10300_link_hash_table_create
   5499       1.1  christos 
   5500       1.1  christos #ifndef elf_symbol_leading_char
   5501       1.1  christos #define elf_symbol_leading_char '_'
   5502       1.1  christos #endif
   5503       1.1  christos 
   5504       1.1  christos /* So we can set bits in e_flags.  */
   5505       1.1  christos #define elf_backend_final_write_processing \
   5506       1.1  christos 					_bfd_mn10300_elf_final_write_processing
   5507       1.1  christos #define elf_backend_object_p		_bfd_mn10300_elf_object_p
   5508       1.1  christos 
   5509       1.1  christos #define bfd_elf32_bfd_merge_private_bfd_data \
   5510       1.1  christos 					_bfd_mn10300_elf_merge_private_bfd_data
   5511       1.1  christos 
   5512       1.1  christos #define elf_backend_can_gc_sections	1
   5513       1.1  christos #define elf_backend_create_dynamic_sections \
   5514       1.1  christos   _bfd_mn10300_elf_create_dynamic_sections
   5515  1.1.1.11  christos #define elf_backend_adjust_dynamic_symbol \
   5516  1.1.1.11  christos   _bfd_mn10300_elf_adjust_dynamic_symbol
   5517   1.1.1.8  christos #define elf_backend_late_size_sections \
   5518       1.1  christos   _bfd_mn10300_elf_late_size_sections
   5519       1.1  christos #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
   5520       1.1  christos #define elf_backend_finish_dynamic_symbol \
   5521       1.1  christos   _bfd_mn10300_elf_finish_dynamic_symbol
   5522   1.1.1.2  christos #define elf_backend_finish_dynamic_sections \
   5523   1.1.1.2  christos   _bfd_mn10300_elf_finish_dynamic_sections
   5524       1.1  christos #define elf_backend_copy_indirect_symbol \
   5525       1.1  christos   _bfd_mn10300_copy_indirect_symbol
   5526       1.1  christos #define elf_backend_reloc_type_class \
   5527       1.1  christos   _bfd_mn10300_elf_reloc_type_class
   5528       1.1  christos 
   5529       1.1  christos #define elf_backend_want_got_plt	1
   5530       1.1  christos #define elf_backend_plt_readonly	1
   5531   1.1.1.7  christos #define elf_backend_want_plt_sym	0
   5532       1.1  christos #define elf_backend_got_header_size	12
   5533       1.1  christos #define elf_backend_dtrel_excludes_plt	1
   5534                     
   5535                     #include "elf32-target.h"
   5536