Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/elf32-sh.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    1 /* Hitachi SH specific support for 32-bit ELF
    2    Copyright 1996, 1997, 1998, 1999, 2000, 2001
     1/* Renesas / SuperH SH specific support for 32-bit ELF
     2   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    33   Free Software Foundation, Inc.
    44   Contributed by Ian Lance Taylor, Cygnus Support.
    55
    6 This file is part of BFD, the Binary File Descriptor library.
    7 
    8 This program is free software; you can redistribute it and/or modify
    9 it under the terms of the GNU General Public License as published by
    10 the Free Software Foundation; either version 2 of the License, or
    11 (at your option) any later version.
    12 
    13 This program is distributed in the hope that it will be useful,
    14 but WITHOUT ANY WARRANTY; without even the implied warranty of
    15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16 GNU General Public License for more details.
    17 
    18 You should have received a copy of the GNU General Public License
    19 along with this program; if not, write to the Free Software
    20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
     6   This file is part of BFD, the Binary File Descriptor library.
     7
     8   This program is free software; you can redistribute it and/or modify
     9   it under the terms of the GNU General Public License as published by
     10   the Free Software Foundation; either version 2 of the License, or
     11   (at your option) any later version.
     12
     13   This program is distributed in the hope that it will be useful,
     14   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16   GNU General Public License for more details.
     17
     18   You should have received a copy of the GNU General Public License
     19   along with this program; if not, write to the Free Software
     20   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    2121
    2222#include "bfd.h"
     
    3535static void sh_elf_info_to_howto
    3636  PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
    37 static boolean sh_elf_set_private_flags
     37static bfd_boolean sh_elf_set_private_flags
    3838  PARAMS ((bfd *, flagword));
    39 static boolean sh_elf_copy_private_data
     39static bfd_boolean sh_elf_copy_private_data
    4040  PARAMS ((bfd *, bfd *));
    41 static boolean sh_elf_merge_private_data
     41static bfd_boolean sh_elf_merge_private_data
    4242  PARAMS ((bfd *, bfd *));
    43 static boolean sh_elf_set_mach_from_flags
     43static bfd_boolean sh_elf_set_mach_from_flags
    4444  PARAMS ((bfd *));
    45 static boolean sh_elf_relax_section
    46   PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *));
    47 static boolean sh_elf_relax_delete_bytes
     45static bfd_boolean sh_elf_relax_section
     46  PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
     47static bfd_boolean sh_elf_relax_delete_bytes
    4848  PARAMS ((bfd *, asection *, bfd_vma, int));
    49 static boolean sh_elf_align_loads
    50   PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, boolean *));
    51 static boolean sh_elf_swap_insns
     49static bfd_boolean sh_elf_align_loads
     50  PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_boolean *));
     51static bfd_boolean sh_elf_swap_insns
    5252  PARAMS ((bfd *, asection *, PTR, bfd_byte *, bfd_vma));
    53 static boolean sh_elf_relocate_section
     53static bfd_boolean sh_elf_relocate_section
    5454  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
    5555           Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
    5656static bfd_byte *sh_elf_get_relocated_section_contents
    5757  PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
    58            bfd_byte *, boolean, asymbol **));
    59 static boolean sh_elf_check_relocs
     58           bfd_byte *, bfd_boolean, asymbol **));
     59static void sh_elf_copy_indirect_symbol
     60  PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *,
     61           struct elf_link_hash_entry *));
     62static int sh_elf_optimized_tls_reloc
     63  PARAMS ((struct bfd_link_info *, int, int));
     64static bfd_boolean sh_elf_mkobject
     65  PARAMS ((bfd *));
     66static bfd_boolean sh_elf_object_p
     67  PARAMS ((bfd *));
     68static bfd_boolean sh_elf_check_relocs
    6069  PARAMS ((bfd *, struct bfd_link_info *, asection *,
    6170           const Elf_Internal_Rela *));
     
    6473static struct bfd_link_hash_table *sh_elf_link_hash_table_create
    6574  PARAMS ((bfd *));
    66 static boolean sh_elf_adjust_dynamic_symbol
     75static bfd_boolean sh_elf_adjust_dynamic_symbol
    6776  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
    68 static boolean sh_elf_size_dynamic_sections
     77static bfd_boolean sh_elf_size_dynamic_sections
    6978  PARAMS ((bfd *, struct bfd_link_info *));
    70 static boolean sh_elf_finish_dynamic_symbol
     79static bfd_boolean sh_elf_finish_dynamic_symbol
    7180  PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
    7281           Elf_Internal_Sym *));
    73 static boolean sh_elf_finish_dynamic_sections
     82static bfd_boolean sh_elf_finish_dynamic_sections
    7483  PARAMS ((bfd *, struct bfd_link_info *));
     84static bfd_reloc_status_type sh_elf_reloc_loop
     85  PARAMS ((int, bfd *, asection *, bfd_byte *, bfd_vma, asection *,
     86           bfd_vma, bfd_vma));
     87static bfd_boolean create_got_section
     88  PARAMS ((bfd *, struct bfd_link_info *));
     89static bfd_boolean sh_elf_create_dynamic_sections
     90  PARAMS ((bfd *, struct bfd_link_info *));
     91static bfd_vma dtpoff_base
     92  PARAMS ((struct bfd_link_info *));
     93static bfd_vma tpoff
     94  PARAMS ((struct bfd_link_info *, bfd_vma));
     95static asection * sh_elf_gc_mark_hook
     96  PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
     97           struct elf_link_hash_entry *, Elf_Internal_Sym *));
     98static bfd_boolean sh_elf_gc_sweep_hook
     99  PARAMS ((bfd *, struct bfd_link_info *, asection *,
     100           const Elf_Internal_Rela *));
     101static bfd_boolean allocate_dynrelocs
     102  PARAMS ((struct elf_link_hash_entry *, PTR));
     103static bfd_boolean readonly_dynrelocs
     104  PARAMS ((struct elf_link_hash_entry *, PTR));
     105static enum elf_reloc_type_class sh_elf_reloc_type_class
     106  PARAMS ((const Elf_Internal_Rela *));
     107#ifdef INCLUDE_SHMEDIA
     108inline static void movi_shori_putval PARAMS ((bfd *, unsigned long, char *));
     109#endif
     110static bfd_boolean elf32_shlin_grok_prstatus
     111  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
     112static bfd_boolean elf32_shlin_grok_psinfo
     113  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
    75114
    76115/* The name of the dynamic interpreter.  This is put in the .interp
     
    86125         0,                     /* size (0 = byte, 1 = short, 2 = long) */
    87126         0,                     /* bitsize */
    88          false,                 /* pc_relative */
     127         FALSE,                 /* pc_relative */
    89128         0,                     /* bitpos */
    90129         complain_overflow_dont, /* complain_on_overflow */
    91130         sh_elf_ignore_reloc,   /* special_function */
    92131         "R_SH_NONE",           /* name */
    93          false,                 /* partial_inplace */
     132         FALSE,                 /* partial_inplace */
    94133         0,                     /* src_mask */
    95134         0,                     /* dst_mask */
    96          false),                /* pcrel_offset */
    97 
    98   /* 32 bit absolute relocation.  Setting partial_inplace to true and
     135         FALSE),                /* pcrel_offset */
     136
     137  /* 32 bit absolute relocation.  Setting partial_inplace to TRUE and
    99138     src_mask to a non-zero value is similar to the COFF toolchain.  */
    100139  HOWTO (R_SH_DIR32,            /* type */
     
    102141         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    103142         32,                    /* bitsize */
    104          false,                 /* pc_relative */
     143         FALSE,                 /* pc_relative */
    105144         0,                     /* bitpos */
    106145         complain_overflow_bitfield, /* complain_on_overflow */
    107146         sh_elf_reloc,          /* special_function */
    108147         "R_SH_DIR32",          /* name */
    109          true,                  /* partial_inplace */
     148         TRUE,                  /* partial_inplace */
    110149         0xffffffff,            /* src_mask */
    111150         0xffffffff,            /* dst_mask */
    112          false),                /* pcrel_offset */
     151         FALSE),                /* pcrel_offset */
    113152
    114153  /* 32 bit PC relative relocation.  */
     
    117156         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    118157         32,                    /* bitsize */
    119          true,                  /* pc_relative */
     158         TRUE,                  /* pc_relative */
    120159         0,                     /* bitpos */
    121160         complain_overflow_signed, /* complain_on_overflow */
    122161         sh_elf_ignore_reloc,   /* special_function */
    123162         "R_SH_REL32",          /* name */
    124          false,                 /* partial_inplace */
    125          0,                     /* src_mask */
     163         TRUE,                  /* partial_inplace */
     164         0xffffffff,            /* src_mask */
    126165         0xffffffff,            /* dst_mask */
    127          true),                 /* pcrel_offset */
     166         TRUE),                 /* pcrel_offset */
    128167
    129168  /* 8 bit PC relative branch divided by 2.  */
     
    132171         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    133172         8,                     /* bitsize */
    134          true,                  /* pc_relative */
     173         TRUE,                  /* pc_relative */
    135174         0,                     /* bitpos */
    136175         complain_overflow_signed, /* complain_on_overflow */
    137176         sh_elf_ignore_reloc,   /* special_function */
    138177         "R_SH_DIR8WPN",        /* name */
    139          true,                  /* partial_inplace */
     178         TRUE,                  /* partial_inplace */
    140179         0xff,                  /* src_mask */
    141180         0xff,                  /* dst_mask */
    142          true),                 /* pcrel_offset */
     181         TRUE),                 /* pcrel_offset */
    143182
    144183  /* 12 bit PC relative branch divided by 2.  */
     184  /* This cannot be partial_inplace because relaxation can't know the
     185     eventual value of a symbol.  */
    145186  HOWTO (R_SH_IND12W,           /* type */
    146187         1,                     /* rightshift */
    147188         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    148189         12,                    /* bitsize */
    149          true,                  /* pc_relative */
     190         TRUE,                  /* pc_relative */
    150191         0,                     /* bitpos */
    151192         complain_overflow_signed, /* complain_on_overflow */
    152          sh_elf_reloc,          /* special_function */
     193         NULL,                  /* special_function */
    153194         "R_SH_IND12W",         /* name */
    154          true,                  /* partial_inplace */
    155          0xfff,                 /* src_mask */
     195         FALSE,                 /* partial_inplace */
     196         0x0,                   /* src_mask */
    156197         0xfff,                 /* dst_mask */
    157          true),                 /* pcrel_offset */
     198         TRUE),                 /* pcrel_offset */
    158199
    159200  /* 8 bit unsigned PC relative divided by 4.  */
     
    162203         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    163204         8,                     /* bitsize */
    164          true,                  /* pc_relative */
     205         TRUE,                  /* pc_relative */
    165206         0,                     /* bitpos */
    166207         complain_overflow_unsigned, /* complain_on_overflow */
    167208         sh_elf_ignore_reloc,   /* special_function */
    168209         "R_SH_DIR8WPL",        /* name */
    169          true,                  /* partial_inplace */
     210         TRUE,                  /* partial_inplace */
    170211         0xff,                  /* src_mask */
    171212         0xff,                  /* dst_mask */
    172          true),                 /* pcrel_offset */
     213         TRUE),                 /* pcrel_offset */
    173214
    174215  /* 8 bit unsigned PC relative divided by 2.  */
     
    177218         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    178219         8,                     /* bitsize */
    179          true,                  /* pc_relative */
     220         TRUE,                  /* pc_relative */
    180221         0,                     /* bitpos */
    181222         complain_overflow_unsigned, /* complain_on_overflow */
    182223         sh_elf_ignore_reloc,   /* special_function */
    183224         "R_SH_DIR8WPZ",        /* name */
    184          true,                  /* partial_inplace */
     225         TRUE,                  /* partial_inplace */
    185226         0xff,                  /* src_mask */
    186227         0xff,                  /* dst_mask */
    187          true),                 /* pcrel_offset */
     228         TRUE),                 /* pcrel_offset */
    188229
    189230  /* 8 bit GBR relative.  FIXME: This only makes sense if we have some
     
    194235         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    195236         8,                     /* bitsize */
    196          false,                 /* pc_relative */
     237         FALSE,                 /* pc_relative */
    197238         0,                     /* bitpos */
    198239         complain_overflow_unsigned, /* complain_on_overflow */
    199240         sh_elf_ignore_reloc,   /* special_function */
    200241         "R_SH_DIR8BP",         /* name */
    201          false,                 /* partial_inplace */
     242         FALSE,                 /* partial_inplace */
    202243         0,                     /* src_mask */
    203244         0xff,                  /* dst_mask */
    204          true),                 /* pcrel_offset */
     245         TRUE),                 /* pcrel_offset */
    205246
    206247  /* 8 bit GBR relative divided by 2.  FIXME: This only makes sense if
     
    211252         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    212253         8,                     /* bitsize */
    213          false,                 /* pc_relative */
     254         FALSE,                 /* pc_relative */
    214255         0,                     /* bitpos */
    215256         complain_overflow_unsigned, /* complain_on_overflow */
    216257         sh_elf_ignore_reloc,   /* special_function */
    217258         "R_SH_DIR8W",          /* name */
    218          false,                 /* partial_inplace */
     259         FALSE,                 /* partial_inplace */
    219260         0,                     /* src_mask */
    220261         0xff,                  /* dst_mask */
    221          true),                 /* pcrel_offset */
     262         TRUE),                 /* pcrel_offset */
    222263
    223264  /* 8 bit GBR relative divided by 4.  FIXME: This only makes sense if
     
    228269         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    229270         8,                     /* bitsize */
    230          false,                 /* pc_relative */
     271         FALSE,                 /* pc_relative */
    231272         0,                     /* bitpos */
    232273         complain_overflow_unsigned, /* complain_on_overflow */
    233274         sh_elf_ignore_reloc,   /* special_function */
    234275         "R_SH_DIR8L",          /* name */
    235          false,                 /* partial_inplace */
     276         FALSE,                 /* partial_inplace */
    236277         0,                     /* src_mask */
    237278         0xff,                  /* dst_mask */
    238          true),                 /* pcrel_offset */
     279         TRUE),                 /* pcrel_offset */
    239280
    240281  EMPTY_HOWTO (10),
     
    266307         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    267308         16,                    /* bitsize */
    268          false,                 /* pc_relative */
     309         FALSE,                 /* pc_relative */
    269310         0,                     /* bitpos */
    270311         complain_overflow_unsigned, /* complain_on_overflow */
    271312         sh_elf_ignore_reloc,   /* special_function */
    272313         "R_SH_SWITCH16",       /* name */
    273          false,                 /* partial_inplace */
     314         FALSE,                 /* partial_inplace */
    274315         0,                     /* src_mask */
    275316         0,                     /* dst_mask */
    276          true),                 /* pcrel_offset */
     317         TRUE),                 /* pcrel_offset */
    277318
    278319  /* A 32 bit switch table entry.  This is generated for an expression
     
    283324         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    284325         32,                    /* bitsize */
    285          false,                 /* pc_relative */
     326         FALSE,                 /* pc_relative */
    286327         0,                     /* bitpos */
    287328         complain_overflow_unsigned, /* complain_on_overflow */
    288329         sh_elf_ignore_reloc,   /* special_function */
    289330         "R_SH_SWITCH32",       /* name */
    290          false,                 /* partial_inplace */
     331         FALSE,                 /* partial_inplace */
    291332         0,                     /* src_mask */
    292333         0,                     /* dst_mask */
    293          true),                 /* pcrel_offset */
     334         TRUE),                 /* pcrel_offset */
    294335
    295336  /* Indicates a .uses pseudo-op.  The compiler will generate .uses
     
    301342         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    302343         0,                     /* bitsize */
    303          false,                 /* pc_relative */
     344         FALSE,                 /* pc_relative */
    304345         0,                     /* bitpos */
    305346         complain_overflow_unsigned, /* complain_on_overflow */
    306347         sh_elf_ignore_reloc,   /* special_function */
    307348         "R_SH_USES",           /* name */
    308          false,                 /* partial_inplace */
     349         FALSE,                 /* partial_inplace */
    309350         0,                     /* src_mask */
    310351         0,                     /* dst_mask */
    311          true),                 /* pcrel_offset */
     352         TRUE),                 /* pcrel_offset */
    312353
    313354  /* The assembler will generate this reloc for addresses referred to
     
    319360         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    320361         0,                     /* bitsize */
    321          false,                 /* pc_relative */
     362         FALSE,                 /* pc_relative */
    322363         0,                     /* bitpos */
    323364         complain_overflow_unsigned, /* complain_on_overflow */
    324365         sh_elf_ignore_reloc,   /* special_function */
    325366         "R_SH_COUNT",          /* name */
    326          false,                 /* partial_inplace */
     367         FALSE,                 /* partial_inplace */
    327368         0,                     /* src_mask */
    328369         0,                     /* dst_mask */
    329          true),                 /* pcrel_offset */
     370         TRUE),                 /* pcrel_offset */
    330371
    331372  /* Indicates an alignment statement.  The offset field is the power
     
    336377         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    337378         0,                     /* bitsize */
    338          false,                 /* pc_relative */
     379         FALSE,                 /* pc_relative */
    339380         0,                     /* bitpos */
    340381         complain_overflow_unsigned, /* complain_on_overflow */
    341382         sh_elf_ignore_reloc,   /* special_function */
    342383         "R_SH_ALIGN",  /* name */
    343          false,                 /* partial_inplace */
     384         FALSE,                 /* partial_inplace */
    344385         0,                     /* src_mask */
    345386         0,                     /* dst_mask */
    346          true),                 /* pcrel_offset */
     387         TRUE),                 /* pcrel_offset */
    347388
    348389  /* The assembler will generate this reloc before a block of
     
    353394         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    354395         0,                     /* bitsize */
    355          false,                 /* pc_relative */
     396         FALSE,                 /* pc_relative */
    356397         0,                     /* bitpos */
    357398         complain_overflow_unsigned, /* complain_on_overflow */
    358399         sh_elf_ignore_reloc,   /* special_function */
    359400         "R_SH_CODE",           /* name */
    360          false,                 /* partial_inplace */
     401         FALSE,                 /* partial_inplace */
    361402         0,                     /* src_mask */
    362403         0,                     /* dst_mask */
    363          true),                 /* pcrel_offset */
     404         TRUE),                 /* pcrel_offset */
    364405
    365406  /* The assembler will generate this reloc after a block of
     
    369410         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    370411         0,                     /* bitsize */
    371          false,                 /* pc_relative */
     412         FALSE,                 /* pc_relative */
    372413         0,                     /* bitpos */
    373414         complain_overflow_unsigned, /* complain_on_overflow */
    374415         sh_elf_ignore_reloc,   /* special_function */
    375416         "R_SH_DATA",           /* name */
    376          false,                 /* partial_inplace */
     417         FALSE,                 /* partial_inplace */
    377418         0,                     /* src_mask */
    378419         0,                     /* dst_mask */
    379          true),                 /* pcrel_offset */
     420         TRUE),                 /* pcrel_offset */
    380421
    381422  /* The assembler generates this reloc for each label within a block
     
    386427         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    387428         0,                     /* bitsize */
    388          false,                 /* pc_relative */
     429         FALSE,                 /* pc_relative */
    389430         0,                     /* bitpos */
    390431         complain_overflow_unsigned, /* complain_on_overflow */
    391432         sh_elf_ignore_reloc,   /* special_function */
    392433         "R_SH_LABEL",          /* name */
    393          false,                 /* partial_inplace */
     434         FALSE,                 /* partial_inplace */
    394435         0,                     /* src_mask */
    395436         0,                     /* dst_mask */
    396          true),                 /* pcrel_offset */
     437         TRUE),                 /* pcrel_offset */
    397438
    398439  /* An 8 bit switch table entry.  This is generated for an expression
     
    403444         0,                     /* size (0 = byte, 1 = short, 2 = long) */
    404445         8,                     /* bitsize */
    405          false,                 /* pc_relative */
     446         FALSE,                 /* pc_relative */
    406447         0,                     /* bitpos */
    407448         complain_overflow_unsigned, /* complain_on_overflow */
    408449         sh_elf_ignore_reloc,   /* special_function */
    409450         "R_SH_SWITCH8",        /* name */
    410          false,                 /* partial_inplace */
     451         FALSE,                 /* partial_inplace */
    411452         0,                     /* src_mask */
    412453         0,                     /* dst_mask */
    413          true),                 /* pcrel_offset */
     454         TRUE),                 /* pcrel_offset */
    414455
    415456  /* GNU extension to record C++ vtable hierarchy */
    416457  HOWTO (R_SH_GNU_VTINHERIT, /* type */
    417          0,                     /* rightshift */
    418          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    419          0,                     /* bitsize */
    420          false,                 /* pc_relative */
    421          0,                     /* bitpos */
    422         complain_overflow_dont, /* complain_on_overflow */
    423          NULL,                  /* special_function */
    424         "R_SH_GNU_VTINHERIT", /* name */
    425          false,                 /* partial_inplace */
    426          0,                     /* src_mask */
    427          0,                     /* dst_mask */
    428          false),                /* pcrel_offset */
     458         0,                     /* rightshift */
     459         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     460         0,                     /* bitsize */
     461         FALSE,                 /* pc_relative */
     462         0,                     /* bitpos */
     463        complain_overflow_dont, /* complain_on_overflow */
     464         NULL,                  /* special_function */
     465        "R_SH_GNU_VTINHERIT", /* name */
     466         FALSE,                 /* partial_inplace */
     467         0,                     /* src_mask */
     468         0,                     /* dst_mask */
     469         FALSE),                /* pcrel_offset */
    429470
    430471  /* GNU extension to record C++ vtable member usage */
    431472  HOWTO (R_SH_GNU_VTENTRY,     /* type */
    432          0,                     /* rightshift */
    433          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    434          0,                     /* bitsize */
    435          false,                 /* pc_relative */
    436          0,                     /* bitpos */
    437         complain_overflow_dont, /* complain_on_overflow */
    438          _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
    439         "R_SH_GNU_VTENTRY",   /* name */
    440          false,                 /* partial_inplace */
    441          0,                     /* src_mask */
    442          0,                     /* dst_mask */
    443          false),                /* pcrel_offset */
     473         0,                     /* rightshift */
     474         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     475         0,                     /* bitsize */
     476         FALSE,                 /* pc_relative */
     477         0,                     /* bitpos */
     478        complain_overflow_dont, /* complain_on_overflow */
     479         _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
     480        "R_SH_GNU_VTENTRY",   /* name */
     481         FALSE,                 /* partial_inplace */
     482         0,                     /* src_mask */
     483         0,                     /* dst_mask */
     484         FALSE),                /* pcrel_offset */
    444485
    445486  /* 8 bit PC relative divided by 2 - but specified in a very odd way.  */
     
    448489         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    449490         8,                     /* bitsize */
    450          false,                 /* pc_relative */
     491         FALSE,                 /* pc_relative */
    451492         0,                     /* bitpos */
    452493         complain_overflow_signed, /* complain_on_overflow */
    453494         sh_elf_ignore_reloc,   /* special_function */
    454495         "R_SH_LOOP_START",     /* name */
    455          true,                  /* partial_inplace */
     496         TRUE,                  /* partial_inplace */
    456497         0xff,                  /* src_mask */
    457498         0xff,                  /* dst_mask */
    458          true),                 /* pcrel_offset */
     499         TRUE),                 /* pcrel_offset */
    459500
    460501  /* 8 bit PC relative divided by 2 - but specified in a very odd way.  */
     
    463504         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    464505         8,                     /* bitsize */
    465          false,                 /* pc_relative */
     506         FALSE,                 /* pc_relative */
    466507         0,                     /* bitpos */
    467508         complain_overflow_signed, /* complain_on_overflow */
    468509         sh_elf_ignore_reloc,   /* special_function */
    469510         "R_SH_LOOP_END",       /* name */
    470          true,                  /* partial_inplace */
     511         TRUE,                  /* partial_inplace */
    471512         0xff,                  /* src_mask */
    472513         0xff,                  /* dst_mask */
    473          true),                 /* pcrel_offset */
     514         TRUE),                 /* pcrel_offset */
    474515
    475516  EMPTY_HOWTO (38),
     
    480521  EMPTY_HOWTO (43),
    481522  EMPTY_HOWTO (44),
     523
     524#ifdef INCLUDE_SHMEDIA
     525  /* Used in SHLLI.L and SHLRI.L.  */
     526  HOWTO (R_SH_DIR5U,            /* type */
     527         0,                     /* rightshift */
     528         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     529         5,                     /* bitsize */
     530         FALSE,                 /* pc_relative */
     531         10,                    /* bitpos */
     532         complain_overflow_unsigned, /* complain_on_overflow */
     533         bfd_elf_generic_reloc, /* special_function */
     534         "R_SH_DIR5U",          /* name */
     535         FALSE,                 /* partial_inplace */
     536         0,                     /* src_mask */
     537         0xfc00,                /* dst_mask */
     538         FALSE),                /* pcrel_offset */
     539
     540  /* Used in SHARI, SHLLI et al.  */
     541  HOWTO (R_SH_DIR6U,            /* type */
     542         0,                     /* rightshift */
     543         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     544         6,                     /* bitsize */
     545         FALSE,                 /* pc_relative */
     546         10,                    /* bitpos */
     547         complain_overflow_unsigned, /* complain_on_overflow */
     548         bfd_elf_generic_reloc, /* special_function */
     549         "R_SH_DIR6U",          /* name */
     550         FALSE,                 /* partial_inplace */
     551         0,                     /* src_mask */
     552         0xfc00,                /* dst_mask */
     553         FALSE),                /* pcrel_offset */
     554
     555  /* Used in BxxI, LDHI.L et al.  */
     556  HOWTO (R_SH_DIR6S,            /* type */
     557         0,                     /* rightshift */
     558         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     559         6,                     /* bitsize */
     560         FALSE,                 /* pc_relative */
     561         10,                    /* bitpos */
     562         complain_overflow_signed, /* complain_on_overflow */
     563         bfd_elf_generic_reloc, /* special_function */
     564         "R_SH_DIR6S",          /* name */
     565         FALSE,                 /* partial_inplace */
     566         0,                     /* src_mask */
     567         0xfc00,                /* dst_mask */
     568         FALSE),                /* pcrel_offset */
     569
     570  /* Used in ADDI, ANDI et al.  */
     571  HOWTO (R_SH_DIR10S,           /* type */
     572         0,                     /* rightshift */
     573         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     574         10,                    /* bitsize */
     575         FALSE,                 /* pc_relative */
     576         10,                    /* bitpos */
     577         complain_overflow_signed, /* complain_on_overflow */
     578         bfd_elf_generic_reloc, /* special_function */
     579         "R_SH_DIR10S",         /* name */
     580         FALSE,                 /* partial_inplace */
     581         0,                     /* src_mask */
     582         0xffc00,               /* dst_mask */
     583         FALSE),                /* pcrel_offset */
     584
     585  /* Used in LD.UW, ST.W et al.  */
     586  HOWTO (R_SH_DIR10SW,  /* type */
     587         1,                     /* rightshift */
     588         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     589         11,                    /* bitsize */
     590         FALSE,                 /* pc_relative */
     591         10,                    /* bitpos */
     592         complain_overflow_signed, /* complain_on_overflow */
     593         bfd_elf_generic_reloc, /* special_function */
     594         "R_SH_DIR10SW",        /* name */
     595         FALSE,                 /* partial_inplace */
     596         0,                     /* src_mask */
     597         0xffc00,               /* dst_mask */
     598         FALSE),                /* pcrel_offset */
     599
     600  /* Used in LD.L, FLD.S et al.  */
     601  HOWTO (R_SH_DIR10SL,  /* type */
     602         2,                     /* rightshift */
     603         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     604         12,                    /* bitsize */
     605         FALSE,                 /* pc_relative */
     606         10,                    /* bitpos */
     607         complain_overflow_signed, /* complain_on_overflow */
     608         bfd_elf_generic_reloc, /* special_function */
     609         "R_SH_DIR10SL",        /* name */
     610         FALSE,                 /* partial_inplace */
     611         0,                     /* src_mask */
     612         0xffc00,               /* dst_mask */
     613         FALSE),                /* pcrel_offset */
     614
     615  /* Used in FLD.D, FST.P et al.  */
     616  HOWTO (R_SH_DIR10SQ,  /* type */
     617         3,                     /* rightshift */
     618         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     619         13,                    /* bitsize */
     620         FALSE,                 /* pc_relative */
     621         10,                    /* bitpos */
     622         complain_overflow_signed, /* complain_on_overflow */
     623         bfd_elf_generic_reloc, /* special_function */
     624         "R_SH_DIR10SQ",        /* name */
     625         FALSE,                 /* partial_inplace */
     626         0,                     /* src_mask */
     627         0xffc00,               /* dst_mask */
     628         FALSE),                /* pcrel_offset */
     629
     630#else
    482631  EMPTY_HOWTO (45),
    483632  EMPTY_HOWTO (46),
     
    487636  EMPTY_HOWTO (50),
    488637  EMPTY_HOWTO (51),
     638#endif
     639
    489640  EMPTY_HOWTO (52),
    490641  EMPTY_HOWTO (53),
     
    579730  EMPTY_HOWTO (142),
    580731  EMPTY_HOWTO (143),
    581   EMPTY_HOWTO (144),
    582   EMPTY_HOWTO (145),
    583   EMPTY_HOWTO (146),
    584   EMPTY_HOWTO (147),
    585   EMPTY_HOWTO (148),
    586   EMPTY_HOWTO (149),
    587   EMPTY_HOWTO (150),
    588   EMPTY_HOWTO (151),
     732
     733  HOWTO (R_SH_TLS_GD_32,        /* type */
     734         0,                     /* rightshift */
     735         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     736         32,                    /* bitsize */
     737         FALSE,                 /* pc_relative */
     738         0,                     /* bitpos */
     739         complain_overflow_bitfield, /* complain_on_overflow */
     740         bfd_elf_generic_reloc, /* */
     741         "R_SH_TLS_GD_32",      /* name */
     742         TRUE,                  /* partial_inplace */
     743         0xffffffff,            /* src_mask */
     744         0xffffffff,            /* dst_mask */
     745         FALSE),                /* pcrel_offset */
     746
     747  HOWTO (R_SH_TLS_LD_32,        /* type */
     748         0,                     /* rightshift */
     749         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     750         32,                    /* bitsize */
     751         FALSE,                 /* pc_relative */
     752         0,                     /* bitpos */
     753         complain_overflow_bitfield, /* complain_on_overflow */
     754         bfd_elf_generic_reloc, /* */
     755         "R_SH_TLS_LD_32",      /* name */
     756         TRUE,                  /* partial_inplace */
     757         0xffffffff,            /* src_mask */
     758         0xffffffff,            /* dst_mask */
     759         FALSE),                /* pcrel_offset */
     760
     761  HOWTO (R_SH_TLS_LDO_32,       /* type */
     762         0,                     /* rightshift */
     763         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     764         32,                    /* bitsize */
     765         FALSE,                 /* pc_relative */
     766         0,                     /* bitpos */
     767         complain_overflow_bitfield, /* complain_on_overflow */
     768         bfd_elf_generic_reloc, /* */
     769         "R_SH_TLS_LDO_32",     /* name */
     770         TRUE,                  /* partial_inplace */
     771         0xffffffff,            /* src_mask */
     772         0xffffffff,            /* dst_mask */
     773         FALSE),                /* pcrel_offset */
     774
     775  HOWTO (R_SH_TLS_IE_32,        /* type */
     776         0,                     /* rightshift */
     777         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     778         32,                    /* bitsize */
     779         FALSE,                 /* pc_relative */
     780         0,                     /* bitpos */
     781         complain_overflow_bitfield, /* complain_on_overflow */
     782         bfd_elf_generic_reloc, /* */
     783         "R_SH_TLS_IE_32",      /* name */
     784         TRUE,                  /* partial_inplace */
     785         0xffffffff,            /* src_mask */
     786         0xffffffff,            /* dst_mask */
     787         FALSE),                /* pcrel_offset */
     788
     789  HOWTO (R_SH_TLS_LE_32,        /* type */
     790         0,                     /* rightshift */
     791         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     792         32,                    /* bitsize */
     793         FALSE,                 /* pc_relative */
     794         0,                     /* bitpos */
     795         complain_overflow_bitfield, /* complain_on_overflow */
     796         bfd_elf_generic_reloc, /* */
     797         "R_SH_TLS_LE_32",      /* name */
     798         TRUE,                  /* partial_inplace */
     799         0xffffffff,            /* src_mask */
     800         0xffffffff,            /* dst_mask */
     801         FALSE),                /* pcrel_offset */
     802
     803  HOWTO (R_SH_TLS_DTPMOD32,     /* type */
     804         0,                     /* rightshift */
     805         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     806         32,                    /* bitsize */
     807         FALSE,                 /* pc_relative */
     808         0,                     /* bitpos */
     809         complain_overflow_bitfield, /* complain_on_overflow */
     810         bfd_elf_generic_reloc, /* */
     811         "R_SH_TLS_DTPMOD32",   /* name */
     812         TRUE,                  /* partial_inplace */
     813         0xffffffff,            /* src_mask */
     814         0xffffffff,            /* dst_mask */
     815         FALSE),                /* pcrel_offset */
     816
     817  HOWTO (R_SH_TLS_DTPOFF32,     /* type */
     818         0,                     /* rightshift */
     819         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     820         32,                    /* bitsize */
     821         FALSE,                 /* pc_relative */
     822         0,                     /* bitpos */
     823         complain_overflow_bitfield, /* complain_on_overflow */
     824         bfd_elf_generic_reloc, /* */
     825         "R_SH_TLS_DTPOFF32",   /* name */
     826         TRUE,                  /* partial_inplace */
     827         0xffffffff,            /* src_mask */
     828         0xffffffff,            /* dst_mask */
     829         FALSE),                /* pcrel_offset */
     830
     831  HOWTO (R_SH_TLS_TPOFF32,      /* type */
     832         0,                     /* rightshift */
     833         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     834         32,                    /* bitsize */
     835         FALSE,                 /* pc_relative */
     836         0,                     /* bitpos */
     837         complain_overflow_bitfield, /* complain_on_overflow */
     838         bfd_elf_generic_reloc, /* */
     839         "R_SH_TLS_TPOFF32",    /* name */
     840         TRUE,                  /* partial_inplace */
     841         0xffffffff,            /* src_mask */
     842         0xffffffff,            /* dst_mask */
     843         FALSE),                /* pcrel_offset */
     844
    589845  EMPTY_HOWTO (152),
    590846  EMPTY_HOWTO (153),
     
    600856         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    601857         32,                    /* bitsize */
    602          false,                 /* pc_relative */
     858         FALSE,                 /* pc_relative */
    603859         0,                     /* bitpos */
    604860         complain_overflow_bitfield, /* complain_on_overflow */
    605861         bfd_elf_generic_reloc, /* */
    606862         "R_SH_GOT32",          /* name */
    607          true,                  /* partial_inplace */
     863         TRUE,                  /* partial_inplace */
    608864         0xffffffff,            /* src_mask */
    609865         0xffffffff,            /* dst_mask */
    610          false),                /* pcrel_offset */
     866         FALSE),                /* pcrel_offset */
    611867
    612868  HOWTO (R_SH_PLT32,            /* type */
     
    614870         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    615871         32,                    /* bitsize */
    616          true,                  /* pc_relative */
     872         TRUE,                  /* pc_relative */
    617873         0,                     /* bitpos */
    618874         complain_overflow_bitfield, /* complain_on_overflow */
    619875         bfd_elf_generic_reloc, /* */
    620876         "R_SH_PLT32",          /* name */
    621          true,                  /* partial_inplace */
     877         TRUE,                  /* partial_inplace */
    622878         0xffffffff,            /* src_mask */
    623879         0xffffffff,            /* dst_mask */
    624          true),                 /* pcrel_offset */
     880         TRUE),                 /* pcrel_offset */
    625881
    626882  HOWTO (R_SH_COPY,             /* type */
     
    628884         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    629885         32,                    /* bitsize */
    630          false,                 /* pc_relative */
     886         FALSE,                 /* pc_relative */
    631887         0,                     /* bitpos */
    632888         complain_overflow_bitfield, /* complain_on_overflow */
    633889         bfd_elf_generic_reloc, /* */
    634890         "R_SH_COPY",           /* name */
    635          true,                  /* partial_inplace */
     891         TRUE,                  /* partial_inplace */
    636892         0xffffffff,            /* src_mask */
    637893         0xffffffff,            /* dst_mask */
    638          false),                /* pcrel_offset */
     894         FALSE),                /* pcrel_offset */
    639895
    640896  HOWTO (R_SH_GLOB_DAT,         /* type */
     
    642898         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    643899         32,                    /* bitsize */
    644          false,                 /* pc_relative */
     900         FALSE,                 /* pc_relative */
    645901         0,                     /* bitpos */
    646902         complain_overflow_bitfield, /* complain_on_overflow */
    647903         bfd_elf_generic_reloc, /* */
    648904         "R_SH_GLOB_DAT",       /* name */
    649          true,                  /* partial_inplace */
     905         TRUE,                  /* partial_inplace */
    650906         0xffffffff,            /* src_mask */
    651907         0xffffffff,            /* dst_mask */
    652          false),                /* pcrel_offset */
     908         FALSE),                /* pcrel_offset */
    653909
    654910  HOWTO (R_SH_JMP_SLOT,         /* type */
     
    656912         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    657913         32,                    /* bitsize */
    658          false,                 /* pc_relative */
     914         FALSE,                 /* pc_relative */
    659915         0,                     /* bitpos */
    660916         complain_overflow_bitfield, /* complain_on_overflow */
    661917         bfd_elf_generic_reloc, /* */
    662918         "R_SH_JMP_SLOT",       /* name */
    663          true,                  /* partial_inplace */
     919         TRUE,                  /* partial_inplace */
    664920         0xffffffff,            /* src_mask */
    665921         0xffffffff,            /* dst_mask */
    666          false),                /* pcrel_offset */
     922         FALSE),                /* pcrel_offset */
    667923
    668924  HOWTO (R_SH_RELATIVE,         /* type */
     
    670926         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    671927         32,                    /* bitsize */
    672          false,                 /* pc_relative */
     928         FALSE,                 /* pc_relative */
    673929         0,                     /* bitpos */
    674930         complain_overflow_bitfield, /* complain_on_overflow */
    675931         bfd_elf_generic_reloc, /* */
    676932         "R_SH_RELATIVE",       /* name */
    677          true,                  /* partial_inplace */
     933         TRUE,                  /* partial_inplace */
    678934         0xffffffff,            /* src_mask */
    679935         0xffffffff,            /* dst_mask */
    680          false),                /* pcrel_offset */
     936         FALSE),                /* pcrel_offset */
    681937
    682938  HOWTO (R_SH_GOTOFF,           /* type */
     
    684940         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    685941         32,                    /* bitsize */
    686          false,                 /* pc_relative */
     942         FALSE,                 /* pc_relative */
    687943         0,                     /* bitpos */
    688944         complain_overflow_bitfield, /* complain_on_overflow */
    689945         bfd_elf_generic_reloc, /* */
    690946         "R_SH_GOTOFF",         /* name */
    691          true,                  /* partial_inplace */
     947         TRUE,                  /* partial_inplace */
    692948         0xffffffff,            /* src_mask */
    693949         0xffffffff,            /* dst_mask */
    694          false),                /* pcrel_offset */
     950         FALSE),                /* pcrel_offset */
    695951
    696952  HOWTO (R_SH_GOTPC,            /* type */
     
    698954         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    699955         32,                    /* bitsize */
    700          true,                  /* pc_relative */
     956         TRUE,                  /* pc_relative */
    701957         0,                     /* bitpos */
    702958         complain_overflow_bitfield, /* complain_on_overflow */
    703959         bfd_elf_generic_reloc, /* */
    704960         "R_SH_GOTPC",          /* name */
    705          true,                  /* partial_inplace */
     961         TRUE,                  /* partial_inplace */
    706962         0xffffffff,            /* src_mask */
    707963         0xffffffff,            /* dst_mask */
    708          true),                 /* pcrel_offset */
    709 
     964         TRUE),                 /* pcrel_offset */
     965
     966  HOWTO (R_SH_GOTPLT32,         /* type */
     967         0,                     /* rightshift */
     968         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     969         32,                    /* bitsize */
     970         FALSE,                 /* pc_relative */
     971         0,                     /* bitpos */
     972         complain_overflow_bitfield, /* complain_on_overflow */
     973         bfd_elf_generic_reloc, /* */
     974         "R_SH_GOTPLT32",       /* name */
     975         FALSE,                 /* partial_inplace */
     976         0xffffffff,            /* src_mask */
     977         0xffffffff,            /* dst_mask */
     978         FALSE),                /* pcrel_offset */
     979
     980#ifdef INCLUDE_SHMEDIA
     981  /* Used in MOVI and SHORI (x & 65536).  */
     982  HOWTO (R_SH_GOT_LOW16,        /* type */
     983         0,                     /* rightshift */
     984         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     985         64,                    /* bitsize */
     986         FALSE,                 /* pc_relative */
     987         10,                    /* bitpos */
     988         complain_overflow_dont, /* complain_on_overflow */
     989         bfd_elf_generic_reloc, /* special_function */
     990         "R_SH_GOT_LOW16",      /* name */
     991         FALSE,                 /* partial_inplace */
     992         0,                     /* src_mask */
     993         0x3fffc00,             /* dst_mask */
     994         FALSE),                /* pcrel_offset */
     995
     996  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
     997  HOWTO (R_SH_GOT_MEDLOW16,     /* type */
     998         16,                    /* rightshift */
     999         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1000         64,                    /* bitsize */
     1001         FALSE,                 /* pc_relative */
     1002         10,                    /* bitpos */
     1003         complain_overflow_dont, /* complain_on_overflow */
     1004         bfd_elf_generic_reloc, /* special_function */
     1005         "R_SH_GOT_MEDLOW16",   /* name */
     1006         FALSE,                 /* partial_inplace */
     1007         0,                     /* src_mask */
     1008         0x3fffc00,             /* dst_mask */
     1009         FALSE),                /* pcrel_offset */
     1010
     1011  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
     1012  HOWTO (R_SH_GOT_MEDHI16,      /* type */
     1013         32,                    /* rightshift */
     1014         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1015         64,                    /* bitsize */
     1016         FALSE,                 /* pc_relative */
     1017         10,                    /* bitpos */
     1018         complain_overflow_dont, /* complain_on_overflow */
     1019         bfd_elf_generic_reloc, /* special_function */
     1020         "R_SH_GOT_MEDHI16",    /* name */
     1021         FALSE,                 /* partial_inplace */
     1022         0,                     /* src_mask */
     1023         0x3fffc00,             /* dst_mask */
     1024         FALSE),                /* pcrel_offset */
     1025
     1026  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
     1027  HOWTO (R_SH_GOT_HI16,         /* type */
     1028         48,                    /* rightshift */
     1029         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1030         64,                    /* bitsize */
     1031         FALSE,                 /* pc_relative */
     1032         10,                    /* bitpos */
     1033         complain_overflow_dont, /* complain_on_overflow */
     1034         bfd_elf_generic_reloc, /* special_function */
     1035         "R_SH_GOT_HI16",       /* name */
     1036         FALSE,                 /* partial_inplace */
     1037         0,                     /* src_mask */
     1038         0x3fffc00,             /* dst_mask */
     1039         FALSE),                /* pcrel_offset */
     1040
     1041  /* Used in MOVI and SHORI (x & 65536).  */
     1042  HOWTO (R_SH_GOTPLT_LOW16,     /* type */
     1043         0,                     /* rightshift */
     1044         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1045         64,                    /* bitsize */
     1046         FALSE,                 /* pc_relative */
     1047         10,                    /* bitpos */
     1048         complain_overflow_dont, /* complain_on_overflow */
     1049         bfd_elf_generic_reloc, /* special_function */
     1050         "R_SH_GOTPLT_LOW16",   /* name */
     1051         FALSE,                 /* partial_inplace */
     1052         0,                     /* src_mask */
     1053         0x3fffc00,             /* dst_mask */
     1054         FALSE),                /* pcrel_offset */
     1055
     1056  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
     1057  HOWTO (R_SH_GOTPLT_MEDLOW16,  /* type */
     1058         16,                    /* rightshift */
     1059         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1060         64,                    /* bitsize */
     1061         FALSE,                 /* pc_relative */
     1062         10,                    /* bitpos */
     1063         complain_overflow_dont, /* complain_on_overflow */
     1064         bfd_elf_generic_reloc, /* special_function */
     1065         "R_SH_GOTPLT_MEDLOW16", /* name */
     1066         FALSE,                 /* partial_inplace */
     1067         0,                     /* src_mask */
     1068         0x3fffc00,             /* dst_mask */
     1069         FALSE),                /* pcrel_offset */
     1070
     1071  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
     1072  HOWTO (R_SH_GOTPLT_MEDHI16,   /* type */
     1073         32,                    /* rightshift */
     1074         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1075         64,                    /* bitsize */
     1076         FALSE,                 /* pc_relative */
     1077         10,                    /* bitpos */
     1078         complain_overflow_dont, /* complain_on_overflow */
     1079         bfd_elf_generic_reloc, /* special_function */
     1080         "R_SH_GOTPLT_MEDHI16", /* name */
     1081         FALSE,                 /* partial_inplace */
     1082         0,                     /* src_mask */
     1083         0x3fffc00,             /* dst_mask */
     1084         FALSE),                /* pcrel_offset */
     1085
     1086  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
     1087  HOWTO (R_SH_GOTPLT_HI16,      /* type */
     1088         48,                    /* rightshift */
     1089         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1090         64,                    /* bitsize */
     1091         FALSE,                 /* pc_relative */
     1092         10,                    /* bitpos */
     1093         complain_overflow_dont, /* complain_on_overflow */
     1094         bfd_elf_generic_reloc, /* special_function */
     1095         "R_SH_GOTPLT_HI16",    /* name */
     1096         FALSE,                 /* partial_inplace */
     1097         0,                     /* src_mask */
     1098         0x3fffc00,             /* dst_mask */
     1099         FALSE),                /* pcrel_offset */
     1100
     1101  /* Used in MOVI and SHORI (x & 65536).  */
     1102  HOWTO (R_SH_PLT_LOW16,        /* type */
     1103         0,                     /* rightshift */
     1104         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1105         64,                    /* bitsize */
     1106         TRUE,                  /* pc_relative */
     1107         10,                    /* bitpos */
     1108         complain_overflow_dont, /* complain_on_overflow */
     1109         bfd_elf_generic_reloc, /* special_function */
     1110         "R_SH_PLT_LOW16",      /* name */
     1111         FALSE,                 /* partial_inplace */
     1112         0,                     /* src_mask */
     1113         0x3fffc00,             /* dst_mask */
     1114         TRUE),                 /* pcrel_offset */
     1115
     1116  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
     1117  HOWTO (R_SH_PLT_MEDLOW16,     /* type */
     1118         16,                    /* rightshift */
     1119         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1120         64,                    /* bitsize */
     1121         TRUE,                  /* pc_relative */
     1122         10,                    /* bitpos */
     1123         complain_overflow_dont, /* complain_on_overflow */
     1124         bfd_elf_generic_reloc, /* special_function */
     1125         "R_SH_PLT_MEDLOW16",   /* name */
     1126         FALSE,                 /* partial_inplace */
     1127         0,                     /* src_mask */
     1128         0x3fffc00,             /* dst_mask */
     1129         TRUE),                 /* pcrel_offset */
     1130
     1131  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
     1132  HOWTO (R_SH_PLT_MEDHI16,      /* type */
     1133         32,                    /* rightshift */
     1134         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1135         64,                    /* bitsize */
     1136         TRUE,                  /* pc_relative */
     1137         10,                    /* bitpos */
     1138         complain_overflow_dont, /* complain_on_overflow */
     1139         bfd_elf_generic_reloc, /* special_function */
     1140         "R_SH_PLT_MEDHI16",    /* name */
     1141         FALSE,                 /* partial_inplace */
     1142         0,                     /* src_mask */
     1143         0x3fffc00,             /* dst_mask */
     1144         TRUE),                 /* pcrel_offset */
     1145
     1146  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
     1147  HOWTO (R_SH_PLT_HI16,         /* type */
     1148         48,                    /* rightshift */
     1149         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1150         64,                    /* bitsize */
     1151         TRUE,                  /* pc_relative */
     1152         10,                    /* bitpos */
     1153         complain_overflow_dont, /* complain_on_overflow */
     1154         bfd_elf_generic_reloc, /* special_function */
     1155         "R_SH_PLT_HI16",       /* name */
     1156         FALSE,                 /* partial_inplace */
     1157         0,                     /* src_mask */
     1158         0x3fffc00,             /* dst_mask */
     1159         TRUE),                 /* pcrel_offset */
     1160
     1161  /* Used in MOVI and SHORI (x & 65536).  */
     1162  HOWTO (R_SH_GOTOFF_LOW16,     /* type */
     1163         0,                     /* rightshift */
     1164         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1165         64,                    /* bitsize */
     1166         FALSE,                 /* pc_relative */
     1167         10,                    /* bitpos */
     1168         complain_overflow_dont, /* complain_on_overflow */
     1169         bfd_elf_generic_reloc, /* special_function */
     1170         "R_SH_GOTOFF_LOW16",   /* name */
     1171         FALSE,                 /* partial_inplace */
     1172         0,                     /* src_mask */
     1173         0x3fffc00,             /* dst_mask */
     1174         FALSE),                /* pcrel_offset */
     1175
     1176  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
     1177  HOWTO (R_SH_GOTOFF_MEDLOW16,  /* type */
     1178         16,                    /* rightshift */
     1179         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1180         64,                    /* bitsize */
     1181         FALSE,                 /* pc_relative */
     1182         10,                    /* bitpos */
     1183         complain_overflow_dont, /* complain_on_overflow */
     1184         bfd_elf_generic_reloc, /* special_function */
     1185         "R_SH_GOTOFF_MEDLOW16", /* name */
     1186         FALSE,                 /* partial_inplace */
     1187         0,                     /* src_mask */
     1188         0x3fffc00,             /* dst_mask */
     1189         FALSE),                /* pcrel_offset */
     1190
     1191  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
     1192  HOWTO (R_SH_GOTOFF_MEDHI16,   /* type */
     1193         32,                    /* rightshift */
     1194         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1195         64,                    /* bitsize */
     1196         FALSE,                 /* pc_relative */
     1197         10,                    /* bitpos */
     1198         complain_overflow_dont, /* complain_on_overflow */
     1199         bfd_elf_generic_reloc, /* special_function */
     1200         "R_SH_GOTOFF_MEDHI16", /* name */
     1201         FALSE,                 /* partial_inplace */
     1202         0,                     /* src_mask */
     1203         0x3fffc00,             /* dst_mask */
     1204         FALSE),                /* pcrel_offset */
     1205
     1206  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
     1207  HOWTO (R_SH_GOTOFF_HI16,      /* type */
     1208         48,                    /* rightshift */
     1209         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1210         64,                    /* bitsize */
     1211         FALSE,                 /* pc_relative */
     1212         10,                    /* bitpos */
     1213         complain_overflow_dont, /* complain_on_overflow */
     1214         bfd_elf_generic_reloc, /* special_function */
     1215         "R_SH_GOTOFF_HI16",    /* name */
     1216         FALSE,                 /* partial_inplace */
     1217         0,                     /* src_mask */
     1218         0x3fffc00,             /* dst_mask */
     1219         FALSE),                /* pcrel_offset */
     1220
     1221  /* Used in MOVI and SHORI (x & 65536).  */
     1222  HOWTO (R_SH_GOTPC_LOW16,      /* type */
     1223         0,                     /* rightshift */
     1224         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1225         64,                    /* bitsize */
     1226         TRUE,                  /* pc_relative */
     1227         10,                    /* bitpos */
     1228         complain_overflow_dont, /* complain_on_overflow */
     1229         bfd_elf_generic_reloc, /* special_function */
     1230         "R_SH_GOTPC_LOW16",    /* name */
     1231         FALSE,                 /* partial_inplace */
     1232         0,                     /* src_mask */
     1233         0x3fffc00,             /* dst_mask */
     1234         TRUE),                 /* pcrel_offset */
     1235
     1236  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
     1237  HOWTO (R_SH_GOTPC_MEDLOW16,   /* type */
     1238         16,                    /* rightshift */
     1239         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1240         64,                    /* bitsize */
     1241         TRUE,                  /* pc_relative */
     1242         10,                    /* bitpos */
     1243         complain_overflow_dont, /* complain_on_overflow */
     1244         bfd_elf_generic_reloc, /* special_function */
     1245         "R_SH_GOTPC_MEDLOW16", /* name */
     1246         FALSE,                 /* partial_inplace */
     1247         0,                     /* src_mask */
     1248         0x3fffc00,             /* dst_mask */
     1249         TRUE),                 /* pcrel_offset */
     1250
     1251  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
     1252  HOWTO (R_SH_GOTPC_MEDHI16,    /* type */
     1253         32,                    /* rightshift */
     1254         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1255         64,                    /* bitsize */
     1256         TRUE,                  /* pc_relative */
     1257         10,                    /* bitpos */
     1258         complain_overflow_dont, /* complain_on_overflow */
     1259         bfd_elf_generic_reloc, /* special_function */
     1260         "R_SH_GOTPC_MEDHI16",  /* name */
     1261         FALSE,                 /* partial_inplace */
     1262         0,                     /* src_mask */
     1263         0x3fffc00,             /* dst_mask */
     1264         TRUE),                 /* pcrel_offset */
     1265
     1266  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
     1267  HOWTO (R_SH_GOTPC_HI16,       /* type */
     1268         48,                    /* rightshift */
     1269         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1270         64,                    /* bitsize */
     1271         TRUE,                  /* pc_relative */
     1272         10,                    /* bitpos */
     1273         complain_overflow_dont, /* complain_on_overflow */
     1274         bfd_elf_generic_reloc, /* special_function */
     1275         "R_SH_GOTPC_HI16",     /* name */
     1276         FALSE,                 /* partial_inplace */
     1277         0,                     /* src_mask */
     1278         0x3fffc00,             /* dst_mask */
     1279         TRUE),                 /* pcrel_offset */
     1280
     1281  /* Used in LD.L, FLD.S et al.  */
     1282  HOWTO (R_SH_GOT10BY4,         /* type */
     1283         2,                     /* rightshift */
     1284         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1285         12,                    /* bitsize */
     1286         FALSE,                 /* pc_relative */
     1287         10,                    /* bitpos */
     1288         complain_overflow_signed, /* complain_on_overflow */
     1289         bfd_elf_generic_reloc, /* special_function */
     1290         "R_SH_GOT10BY4",       /* name */
     1291         FALSE,                 /* partial_inplace */
     1292         0,                     /* src_mask */
     1293         0xffc00,               /* dst_mask */
     1294         FALSE),                /* pcrel_offset */
     1295
     1296  /* Used in LD.L, FLD.S et al.  */
     1297  HOWTO (R_SH_GOTPLT10BY4,      /* type */
     1298         2,                     /* rightshift */
     1299         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1300         12,                    /* bitsize */
     1301         FALSE,                 /* pc_relative */
     1302         10,                    /* bitpos */
     1303         complain_overflow_signed, /* complain_on_overflow */
     1304         bfd_elf_generic_reloc, /* special_function */
     1305         "R_SH_GOTPLT10BY4",    /* name */
     1306         FALSE,                 /* partial_inplace */
     1307         0,                     /* src_mask */
     1308         0xffc00,               /* dst_mask */
     1309         FALSE),                /* pcrel_offset */
     1310
     1311  /* Used in FLD.D, FST.P et al.  */
     1312  HOWTO (R_SH_GOT10BY8,         /* type */
     1313         3,                     /* rightshift */
     1314         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1315         13,                    /* bitsize */
     1316         FALSE,                 /* pc_relative */
     1317         10,                    /* bitpos */
     1318         complain_overflow_signed, /* complain_on_overflow */
     1319         bfd_elf_generic_reloc, /* special_function */
     1320         "R_SH_GOT10BY8",       /* name */
     1321         FALSE,                 /* partial_inplace */
     1322         0,                     /* src_mask */
     1323         0xffc00,               /* dst_mask */
     1324         FALSE),                /* pcrel_offset */
     1325
     1326  /* Used in FLD.D, FST.P et al.  */
     1327  HOWTO (R_SH_GOTPLT10BY8,      /* type */
     1328         3,                     /* rightshift */
     1329         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1330         13,                    /* bitsize */
     1331         FALSE,                 /* pc_relative */
     1332         10,                    /* bitpos */
     1333         complain_overflow_signed, /* complain_on_overflow */
     1334         bfd_elf_generic_reloc, /* special_function */
     1335         "R_SH_GOTPLT10BY8",    /* name */
     1336         FALSE,                 /* partial_inplace */
     1337         0,                     /* src_mask */
     1338         0xffc00,               /* dst_mask */
     1339         FALSE),                /* pcrel_offset */
     1340
     1341  HOWTO (R_SH_COPY64,           /* type */
     1342         0,                     /* rightshift */
     1343         4,                     /* size (0 = byte, 1 = short, 2 = long) */
     1344         64,                    /* bitsize */
     1345         FALSE,                 /* pc_relative */
     1346         0,                     /* bitpos */
     1347         complain_overflow_dont, /* complain_on_overflow */
     1348         bfd_elf_generic_reloc, /* special_function */
     1349         "R_SH_COPY64",         /* name */
     1350         FALSE,                 /* partial_inplace */
     1351         0,                     /* src_mask */
     1352         ((bfd_vma) 0) - 1,     /* dst_mask */
     1353         FALSE),                /* pcrel_offset */
     1354
     1355  HOWTO (R_SH_GLOB_DAT64,       /* type */
     1356         0,                     /* rightshift */
     1357         4,                     /* size (0 = byte, 1 = short, 2 = long) */
     1358         64,                    /* bitsize */
     1359         FALSE,                 /* pc_relative */
     1360         0,                     /* bitpos */
     1361         complain_overflow_dont, /* complain_on_overflow */
     1362         bfd_elf_generic_reloc, /* special_function */
     1363         "R_SH_GLOB_DAT64",     /* name */
     1364         FALSE,                 /* partial_inplace */
     1365         0,                     /* src_mask */
     1366         ((bfd_vma) 0) - 1,     /* dst_mask */
     1367         FALSE),                /* pcrel_offset */
     1368
     1369  HOWTO (R_SH_JMP_SLOT64,       /* type */
     1370         0,                     /* rightshift */
     1371         4,                     /* size (0 = byte, 1 = short, 2 = long) */
     1372         64,                    /* bitsize */
     1373         FALSE,                 /* pc_relative */
     1374         0,                     /* bitpos */
     1375         complain_overflow_dont, /* complain_on_overflow */
     1376         bfd_elf_generic_reloc, /* special_function */
     1377         "R_SH_JMP_SLOT64",     /* name */
     1378         FALSE,                 /* partial_inplace */
     1379         0,                     /* src_mask */
     1380         ((bfd_vma) 0) - 1,     /* dst_mask */
     1381         FALSE),                /* pcrel_offset */
     1382
     1383  HOWTO (R_SH_RELATIVE64,       /* type */
     1384         0,                     /* rightshift */
     1385         4,                     /* size (0 = byte, 1 = short, 2 = long) */
     1386         64,                    /* bitsize */
     1387         FALSE,                 /* pc_relative */
     1388         0,                     /* bitpos */
     1389         complain_overflow_dont, /* complain_on_overflow */
     1390         bfd_elf_generic_reloc, /* special_function */
     1391         "R_SH_RELATIVE64",     /* name */
     1392         FALSE,                 /* partial_inplace */
     1393         0,                     /* src_mask */
     1394         ((bfd_vma) 0) - 1,     /* dst_mask */
     1395         FALSE),                /* pcrel_offset */
     1396
     1397  EMPTY_HOWTO (197),
     1398  EMPTY_HOWTO (198),
     1399  EMPTY_HOWTO (199),
     1400  EMPTY_HOWTO (200),
     1401  EMPTY_HOWTO (201),
     1402  EMPTY_HOWTO (202),
     1403  EMPTY_HOWTO (203),
     1404  EMPTY_HOWTO (204),
     1405  EMPTY_HOWTO (205),
     1406  EMPTY_HOWTO (206),
     1407  EMPTY_HOWTO (207),
     1408  EMPTY_HOWTO (208),
     1409  EMPTY_HOWTO (209),
     1410  EMPTY_HOWTO (210),
     1411  EMPTY_HOWTO (211),
     1412  EMPTY_HOWTO (212),
     1413  EMPTY_HOWTO (213),
     1414  EMPTY_HOWTO (214),
     1415  EMPTY_HOWTO (215),
     1416  EMPTY_HOWTO (216),
     1417  EMPTY_HOWTO (217),
     1418  EMPTY_HOWTO (218),
     1419  EMPTY_HOWTO (219),
     1420  EMPTY_HOWTO (220),
     1421  EMPTY_HOWTO (221),
     1422  EMPTY_HOWTO (222),
     1423  EMPTY_HOWTO (223),
     1424  EMPTY_HOWTO (224),
     1425  EMPTY_HOWTO (225),
     1426  EMPTY_HOWTO (226),
     1427  EMPTY_HOWTO (227),
     1428  EMPTY_HOWTO (228),
     1429  EMPTY_HOWTO (229),
     1430  EMPTY_HOWTO (230),
     1431  EMPTY_HOWTO (231),
     1432  EMPTY_HOWTO (232),
     1433  EMPTY_HOWTO (233),
     1434  EMPTY_HOWTO (234),
     1435  EMPTY_HOWTO (235),
     1436  EMPTY_HOWTO (236),
     1437  EMPTY_HOWTO (237),
     1438  EMPTY_HOWTO (238),
     1439  EMPTY_HOWTO (239),
     1440  EMPTY_HOWTO (240),
     1441  EMPTY_HOWTO (241),
     1442
     1443  /* Relocations for SHmedia code.  None of these are partial_inplace or
     1444     use the field being relocated (except R_SH_PT_16).  */
     1445
     1446  /* The assembler will generate this reloc before a block of SHmedia
     1447     instructions.  A section should be processed as assuming it contains
     1448     data, unless this reloc is seen.  Note that a block of SHcompact
     1449     instructions are instead preceded by R_SH_CODE.
     1450     This is currently not implemented, but should be used for SHmedia
     1451     linker relaxation.  */
     1452  HOWTO (R_SH_SHMEDIA_CODE,     /* type */
     1453         0,                     /* rightshift */
     1454         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     1455         0,                     /* bitsize */
     1456         FALSE,                 /* pc_relative */
     1457         0,                     /* bitpos */
     1458         complain_overflow_unsigned, /* complain_on_overflow */
     1459         sh_elf_ignore_reloc,   /* special_function */
     1460         "R_SH_SHMEDIA_CODE",   /* name */
     1461         FALSE,                 /* partial_inplace */
     1462         0,                     /* src_mask */
     1463         0,                     /* dst_mask */
     1464         FALSE),                /* pcrel_offset */
     1465
     1466  /* The assembler will generate this reloc at a PTA or PTB instruction,
     1467     and the linker checks the right type of target, or changes a PTA to a
     1468     PTB, if the original insn was PT.  */
     1469  HOWTO (R_SH_PT_16,            /* type */
     1470         2,                     /* rightshift */
     1471         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1472         18,                    /* bitsize */
     1473         TRUE,                  /* pc_relative */
     1474         10,                    /* bitpos */
     1475         complain_overflow_signed, /* complain_on_overflow */
     1476         bfd_elf_generic_reloc, /* special_function */
     1477         "R_SH_PT_16",          /* name */
     1478         FALSE,                 /* partial_inplace */
     1479         0,                     /* src_mask */
     1480         0x3fffc00,             /* dst_mask */
     1481         TRUE),                 /* pcrel_offset */
     1482
     1483  /* Used in unexpanded MOVI.  */
     1484  HOWTO (R_SH_IMMS16,           /* type */
     1485         0,                     /* rightshift */
     1486         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1487         16,                    /* bitsize */
     1488         FALSE,                 /* pc_relative */
     1489         10,                    /* bitpos */
     1490         complain_overflow_signed, /* complain_on_overflow */
     1491         bfd_elf_generic_reloc, /* special_function */
     1492         "R_SH_IMMS16",         /* name */
     1493         FALSE,                 /* partial_inplace */
     1494         0,                     /* src_mask */
     1495         0x3fffc00,             /* dst_mask */
     1496         FALSE),                /* pcrel_offset */
     1497
     1498  /* Used in SHORI.  */
     1499  HOWTO (R_SH_IMMU16,           /* type */
     1500         0,                     /* rightshift */
     1501         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1502         16,                    /* bitsize */
     1503         FALSE,                 /* pc_relative */
     1504         10,                    /* bitpos */
     1505         complain_overflow_unsigned, /* complain_on_overflow */
     1506         bfd_elf_generic_reloc, /* special_function */
     1507         "R_SH_IMMU16",         /* name */
     1508         FALSE,                 /* partial_inplace */
     1509         0,                     /* src_mask */
     1510         0x3fffc00,             /* dst_mask */
     1511         FALSE),                /* pcrel_offset */
     1512
     1513  /* Used in MOVI and SHORI (x & 65536).  */
     1514  HOWTO (R_SH_IMM_LOW16,        /* type */
     1515         0,                     /* rightshift */
     1516         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1517         64,                    /* bitsize */
     1518         FALSE,                 /* pc_relative */
     1519         10,                    /* bitpos */
     1520         complain_overflow_dont, /* complain_on_overflow */
     1521         bfd_elf_generic_reloc, /* special_function */
     1522         "R_SH_IMM_LOW16",      /* name */
     1523         FALSE,                 /* partial_inplace */
     1524         0,                     /* src_mask */
     1525         0x3fffc00,             /* dst_mask */
     1526         FALSE),                /* pcrel_offset */
     1527
     1528  /* Used in MOVI and SHORI ((x - $) & 65536).  */
     1529  HOWTO (R_SH_IMM_LOW16_PCREL,  /* type */
     1530         0,                     /* rightshift */
     1531         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1532         64,                    /* bitsize */
     1533         TRUE,                  /* pc_relative */
     1534         10,                    /* bitpos */
     1535         complain_overflow_dont, /* complain_on_overflow */
     1536         bfd_elf_generic_reloc, /* special_function */
     1537         "R_SH_IMM_LOW16_PCREL", /* name */
     1538         FALSE,                 /* partial_inplace */
     1539         0,                     /* src_mask */
     1540         0x3fffc00,             /* dst_mask */
     1541         TRUE),                 /* pcrel_offset */
     1542
     1543  /* Used in MOVI and SHORI ((x >> 16) & 65536).  */
     1544  HOWTO (R_SH_IMM_MEDLOW16,     /* type */
     1545         16,                    /* rightshift */
     1546         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1547         64,                    /* bitsize */
     1548         FALSE,                 /* pc_relative */
     1549         10,                    /* bitpos */
     1550         complain_overflow_dont, /* complain_on_overflow */
     1551         bfd_elf_generic_reloc, /* special_function */
     1552         "R_SH_IMM_MEDLOW16",   /* name */
     1553         FALSE,                 /* partial_inplace */
     1554         0,                     /* src_mask */
     1555         0x3fffc00,             /* dst_mask */
     1556         FALSE),                /* pcrel_offset */
     1557
     1558  /* Used in MOVI and SHORI (((x - $) >> 16) & 65536).  */
     1559  HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */
     1560         16,                    /* rightshift */
     1561         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1562         64,                    /* bitsize */
     1563         TRUE,                  /* pc_relative */
     1564         10,                    /* bitpos */
     1565         complain_overflow_dont, /* complain_on_overflow */
     1566         bfd_elf_generic_reloc, /* special_function */
     1567         "R_SH_IMM_MEDLOW16_PCREL", /* name */
     1568         FALSE,                 /* partial_inplace */
     1569         0,                     /* src_mask */
     1570         0x3fffc00,             /* dst_mask */
     1571         TRUE),                 /* pcrel_offset */
     1572
     1573  /* Used in MOVI and SHORI ((x >> 32) & 65536).  */
     1574  HOWTO (R_SH_IMM_MEDHI16,      /* type */
     1575         32,                    /* rightshift */
     1576         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1577         64,                    /* bitsize */
     1578         FALSE,                 /* pc_relative */
     1579         10,                    /* bitpos */
     1580         complain_overflow_dont, /* complain_on_overflow */
     1581         bfd_elf_generic_reloc, /* special_function */
     1582         "R_SH_IMM_MEDHI16",    /* name */
     1583         FALSE,                 /* partial_inplace */
     1584         0,                     /* src_mask */
     1585         0x3fffc00,             /* dst_mask */
     1586         FALSE),                /* pcrel_offset */
     1587
     1588  /* Used in MOVI and SHORI (((x - $) >> 32) & 65536).  */
     1589  HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */
     1590         32,                    /* rightshift */
     1591         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1592         64,                    /* bitsize */
     1593         TRUE,                  /* pc_relative */
     1594         10,                    /* bitpos */
     1595         complain_overflow_dont, /* complain_on_overflow */
     1596         bfd_elf_generic_reloc, /* special_function */
     1597         "R_SH_IMM_MEDHI16_PCREL", /* name */
     1598         FALSE,                 /* partial_inplace */
     1599         0,                     /* src_mask */
     1600         0x3fffc00,             /* dst_mask */
     1601         TRUE),                 /* pcrel_offset */
     1602
     1603  /* Used in MOVI and SHORI ((x >> 48) & 65536).  */
     1604  HOWTO (R_SH_IMM_HI16,         /* type */
     1605         48,                    /* rightshift */
     1606         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1607         64,                    /* bitsize */
     1608         FALSE,                 /* pc_relative */
     1609         10,                    /* bitpos */
     1610         complain_overflow_dont, /* complain_on_overflow */
     1611         bfd_elf_generic_reloc, /* special_function */
     1612         "R_SH_IMM_HI16",       /* name */
     1613         FALSE,                 /* partial_inplace */
     1614         0,                     /* src_mask */
     1615         0x3fffc00,             /* dst_mask */
     1616         FALSE),                /* pcrel_offset */
     1617
     1618  /* Used in MOVI and SHORI (((x - $) >> 48) & 65536).  */
     1619  HOWTO (R_SH_IMM_HI16_PCREL,   /* type */
     1620         48,                    /* rightshift */
     1621         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1622         64,                    /* bitsize */
     1623         TRUE,                  /* pc_relative */
     1624         10,                    /* bitpos */
     1625         complain_overflow_dont, /* complain_on_overflow */
     1626         bfd_elf_generic_reloc, /* special_function */
     1627         "R_SH_IMM_HI16_PCREL", /* name */
     1628         FALSE,                 /* partial_inplace */
     1629         0,                     /* src_mask */
     1630         0x3fffc00,             /* dst_mask */
     1631         TRUE),                 /* pcrel_offset */
     1632
     1633  /* For the .uaquad pseudo.  */
     1634  HOWTO (R_SH_64,               /* type */
     1635         0,                     /* rightshift */
     1636         4,                     /* size (0 = byte, 1 = short, 2 = long) */
     1637         64,                    /* bitsize */
     1638         FALSE,                 /* pc_relative */
     1639         0,                     /* bitpos */
     1640         complain_overflow_dont, /* complain_on_overflow */
     1641         bfd_elf_generic_reloc, /* special_function */
     1642         "R_SH_64",             /* name */
     1643         FALSE,                 /* partial_inplace */
     1644         0,                     /* src_mask */
     1645         ((bfd_vma) 0) - 1,     /* dst_mask */
     1646         FALSE),                /* pcrel_offset */
     1647
     1648  /* For the .uaquad pseudo, (x - $).  */
     1649  HOWTO (R_SH_64_PCREL,         /* type */
     1650         48,                    /* rightshift */
     1651         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     1652         64,                    /* bitsize */
     1653         TRUE,                  /* pc_relative */
     1654         10,                    /* bitpos */
     1655         complain_overflow_dont, /* complain_on_overflow */
     1656         bfd_elf_generic_reloc, /* special_function */
     1657         "R_SH_64_PCREL",       /* name */
     1658         FALSE,                 /* partial_inplace */
     1659         0,                     /* src_mask */
     1660         ((bfd_vma) 0) - 1,     /* dst_mask */
     1661         TRUE),                 /* pcrel_offset */
     1662
     1663#endif
    7101664};
    7111665
     
    7231677  static bfd_vma last_addr;
    7241678  static asection *last_symbol_section;
    725   bfd_byte *free_contents = NULL;
    7261679  bfd_byte *start_ptr, *ptr, *last_ptr;
    7271680  int diff, cum_diff;
     
    7551708      else
    7561709        {
    757           free_contents = contents
    758             = (bfd_byte *) bfd_malloc (symbol_section->_raw_size);
     1710          contents = (bfd_byte *) bfd_malloc (symbol_section->_raw_size);
    7591711          if (contents == NULL)
    7601712            return bfd_reloc_outofrange;
     
    7981750    }
    7991751
    800   if (free_contents)
    801     free (free_contents);
     1752  if (contents != NULL
     1753      && elf_section_data (symbol_section)->this_hdr.contents != contents)
     1754    free (contents);
    8021755
    8031756  insn = bfd_get_16 (input_bfd, contents + addr);
     
    8131766
    8141767  x = (insn & ~0xff) | (x & 0xff);
    815   bfd_put_16 (input_bfd, x, contents + addr);
     1768  bfd_put_16 (input_bfd, (bfd_vma) x, contents + addr);
    8161769
    8171770  return bfd_reloc_ok;
     
    8681821      insn = bfd_get_32 (abfd, hit_data);
    8691822      insn += sym_value + reloc_entry->addend;
    870       bfd_put_32 (abfd, insn, hit_data);
     1823      bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
    8711824      break;
    8721825    case R_SH_IND12W:
     
    8811834        sym_value -= 0x1000;
    8821835      insn = (insn & 0xf000) | (sym_value & 0xfff);
    883       bfd_put_16 (abfd, insn, hit_data);
     1836      bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
    8841837      if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
    8851838        return bfd_reloc_overflow;
     
    9451898  { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },
    9461899  { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },
     1900  { BFD_RELOC_SH_TLS_GD_32, R_SH_TLS_GD_32 },
     1901  { BFD_RELOC_SH_TLS_LD_32, R_SH_TLS_LD_32 },
     1902  { BFD_RELOC_SH_TLS_LDO_32, R_SH_TLS_LDO_32 },
     1903  { BFD_RELOC_SH_TLS_IE_32, R_SH_TLS_IE_32 },
     1904  { BFD_RELOC_SH_TLS_LE_32, R_SH_TLS_LE_32 },
     1905  { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 },
     1906  { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 },
     1907  { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 },
    9471908  { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
    9481909  { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
     
    9531914  { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF },
    9541915  { BFD_RELOC_SH_GOTPC, R_SH_GOTPC },
     1916  { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 },
     1917#ifdef INCLUDE_SHMEDIA
     1918  { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
     1919  { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
     1920  { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
     1921  { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
     1922  { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
     1923  { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
     1924  { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
     1925  { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
     1926  { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
     1927  { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
     1928  { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
     1929  { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
     1930  { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
     1931  { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
     1932  { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
     1933  { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
     1934  { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
     1935  { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
     1936  { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
     1937  { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
     1938  { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
     1939  { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
     1940  { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
     1941  { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
     1942  { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
     1943  { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
     1944  { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
     1945  { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
     1946  { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
     1947  { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
     1948  { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
     1949  { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
     1950  { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
     1951  { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
     1952  { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
     1953  { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
     1954  { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
     1955  { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
     1956  { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
     1957  { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
     1958  { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
     1959  { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
     1960  { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
     1961  { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
     1962  { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
     1963  { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
     1964  { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
     1965  { BFD_RELOC_64, R_SH_64 },
     1966  { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
     1967#endif /* not INCLUDE_SHMEDIA */
    9551968};
    9561969
     
    9892002  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
    9902003  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2);
     2004  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3);
     2005  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
     2006  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_5 || r > R_SH_LAST_INVALID_RELOC_5);
    9912007
    9922008  cache_ptr->howto = &sh_elf_howto_table[r];
     
    10042020   they come from enum elf_sh_reloc_type in include/elf/sh.h.  */
    10052021
    1006 static boolean
     2022static bfd_boolean
    10072023sh_elf_relax_section (abfd, sec, link_info, again)
    10082024     bfd *abfd;
    10092025     asection *sec;
    10102026     struct bfd_link_info *link_info;
    1011      boolean *again;
     2027     bfd_boolean *again;
    10122028{
    10132029  Elf_Internal_Shdr *symtab_hdr;
    10142030  Elf_Internal_Rela *internal_relocs;
    1015   Elf_Internal_Rela *free_relocs = NULL;
    1016   boolean have_code;
     2031  bfd_boolean have_code;
    10172032  Elf_Internal_Rela *irel, *irelend;
    10182033  bfd_byte *contents = NULL;
    1019   bfd_byte *free_contents = NULL;
    1020   Elf32_External_Sym *extsyms = NULL;
    1021   Elf32_External_Sym *free_extsyms = NULL;
    1022 
    1023   *again = false;
     2034  Elf_Internal_Sym *isymbuf = NULL;
     2035
     2036  *again = FALSE;
    10242037
    10252038  if (link_info->relocateable
    10262039      || (sec->flags & SEC_RELOC) == 0
    10272040      || sec->reloc_count == 0)
    1028     return true;
     2041    return TRUE;
     2042
     2043#ifdef INCLUDE_SHMEDIA
     2044  if (elf_section_data (sec)->this_hdr.sh_flags
     2045      & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))
     2046    {
     2047      return TRUE;
     2048    }
     2049#endif
    10292050
    10302051  /* If this is the first time we have been called for this section,
     
    10402061  if (internal_relocs == NULL)
    10412062    goto error_return;
    1042   if (! link_info->keep_memory)
    1043     free_relocs = internal_relocs;
    1044 
    1045   have_code = false;
     2063
     2064  have_code = FALSE;
    10462065
    10472066  irelend = internal_relocs + sec->reloc_count;
     
    10542073
    10552074      if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)
    1056         have_code = true;
     2075        have_code = TRUE;
    10572076
    10582077      if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)
     
    10692088              if (contents == NULL)
    10702089                goto error_return;
    1071               free_contents = contents;
    10722090
    10732091              if (! bfd_get_section_contents (abfd, sec, contents,
     
    10782096
    10792097      /* The r_addend field of the R_SH_USES reloc will point us to
    1080         the register load.  The 4 is because the r_addend field is
    1081         computed as though it were a jump offset, which are based
    1082         from 4 bytes after the jump instruction.  */
     2098        the register load.  The 4 is because the r_addend field is
     2099        computed as though it were a jump offset, which are based
     2100        from 4 bytes after the jump instruction.  */
    10832101      laddr = irel->r_offset + 4 + irel->r_addend;
    10842102      if (laddr >= sec->_raw_size)
    10852103        {
    10862104          (*_bfd_error_handler) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
    1087                                  bfd_get_filename (abfd),
     2105                                 bfd_archive_filename (abfd),
    10882106                                 (unsigned long) irel->r_offset);
    10892107          continue;
     
    10922110
    10932111      /* If the instruction is not mov.l NN,rN, we don't know what to
    1094         do.  */
     2112        do.  */
    10952113      if ((insn & 0xf000) != 0xd000)
    10962114        {
    10972115          ((*_bfd_error_handler)
    10982116           (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
    1099             bfd_get_filename (abfd), (unsigned long) irel->r_offset, insn));
     2117            bfd_archive_filename (abfd), (unsigned long) irel->r_offset, insn));
    11002118          continue;
    11012119        }
    11022120
    11032121      /* Get the address from which the register is being loaded.  The
    1104          displacement in the mov.l instruction is quadrupled.  It is a
    1105          displacement from four bytes after the movl instruction, but,
    1106          before adding in the PC address, two least significant bits
    1107          of the PC are cleared.  We assume that the section is aligned
    1108          on a four byte boundary.  */
     2122         displacement in the mov.l instruction is quadrupled.  It is a
     2123         displacement from four bytes after the movl instruction, but,
     2124         before adding in the PC address, two least significant bits
     2125         of the PC are cleared.  We assume that the section is aligned
     2126         on a four byte boundary.  */
    11092127      paddr = insn & 0xff;
    11102128      paddr *= 4;
    1111       paddr += (laddr + 4) & ~3;
     2129      paddr += (laddr + 4) &~ (bfd_vma) 3;
    11122130      if (paddr >= sec->_raw_size)
    11132131        {
    11142132          ((*_bfd_error_handler)
    11152133           (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
    1116             bfd_get_filename (abfd), (unsigned long) irel->r_offset));
     2134            bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
    11172135          continue;
    11182136        }
    11192137
    11202138      /* Get the reloc for the address from which the register is
    1121         being loaded.  This reloc will tell us which function is
    1122         actually being called.  */
     2139        being loaded.  This reloc will tell us which function is
     2140        actually being called.  */
    11232141      for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
    11242142        if (irelfn->r_offset == paddr
     
    11292147          ((*_bfd_error_handler)
    11302148           (_("%s: 0x%lx: warning: could not find expected reloc"),
    1131             bfd_get_filename (abfd), (unsigned long) paddr));
     2149            bfd_archive_filename (abfd), (unsigned long) paddr));
    11322150          continue;
    11332151        }
    11342152
    11352153      /* Read this BFD's symbols if we haven't done so already.  */
    1136       if (extsyms == NULL)
     2154      if (isymbuf == NULL && symtab_hdr->sh_info != 0)
    11372155        {
    1138           if (symtab_hdr->contents != NULL)
    1139             extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
    1140           else
    1141             {
    1142               extsyms = ((Elf32_External_Sym *)
    1143                          bfd_malloc (symtab_hdr->sh_size));
    1144               if (extsyms == NULL)
    1145                 goto error_return;
    1146               free_extsyms = extsyms;
    1147               if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
    1148                   || (bfd_read (extsyms, 1, symtab_hdr->sh_size, abfd)
    1149                       != symtab_hdr->sh_size))
    1150                 goto error_return;
    1151             }
     2156          isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
     2157          if (isymbuf == NULL)
     2158            isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
     2159                                            symtab_hdr->sh_info, 0,
     2160                                            NULL, NULL, NULL);
     2161          if (isymbuf == NULL)
     2162            goto error_return;
    11522163        }
    11532164
     
    11552166      if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
    11562167        {
    1157           Elf_Internal_Sym isym;
    1158 
    11592168          /* A local symbol.  */
    1160           bfd_elf32_swap_symbol_in (abfd,
    1161                                     extsyms + ELF32_R_SYM (irelfn->r_info),
    1162                                     &isym);
    1163 
    1164           if (isym.st_shndx != _bfd_elf_section_from_bfd_section (abfd, sec))
     2169          Elf_Internal_Sym *isym;
     2170
     2171          isym = isymbuf + ELF32_R_SYM (irelfn->r_info);
     2172          if (isym->st_shndx
     2173              != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))
    11652174            {
    11662175              ((*_bfd_error_handler)
    11672176               (_("%s: 0x%lx: warning: symbol in unexpected section"),
    1168                 bfd_get_filename (abfd), (unsigned long) paddr));
     2177                bfd_archive_filename (abfd), (unsigned long) paddr));
    11692178              continue;
    11702179            }
    11712180
    1172           symval = (isym.st_value
     2181          symval = (isym->st_value
    11732182                    + sec->output_section->vma
    11742183                    + sec->output_offset);
     
    11862195            {
    11872196              /* This appears to be a reference to an undefined
    1188                 symbol.  Just ignore it--it will be caught by the
    1189                 regular reloc processing.  */
     2197                symbol.  Just ignore it--it will be caught by the
     2198                regular reloc processing.  */
    11902199              continue;
    11912200            }
     
    12212230
    12222231      elf_section_data (sec)->relocs = internal_relocs;
    1223       free_relocs = NULL;
    1224 
    12252232      elf_section_data (sec)->this_hdr.contents = contents;
    1226       free_contents = NULL;
    1227 
    1228       symtab_hdr->contents = (bfd_byte *) extsyms;
    1229       free_extsyms = NULL;
     2233      symtab_hdr->contents = (unsigned char *) isymbuf;
    12302234
    12312235      /* Replace the jsr with a bsr.  */
    12322236
    12332237      /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
    1234         replace the jsr with a bsr.  */
     2238        replace the jsr with a bsr.  */
    12352239      irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
     2240      /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
     2241         here, but that only checks if the symbol is an external symbol,
     2242         not if the symbol is in a different section.  Besides, we need
     2243         a consistent meaning for the relocation, so we just assume here that
     2244         the value of the symbol is not available.  */
     2245#if 0
    12362246      if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
    12372247        {
    12382248          /* If this needs to be changed because of future relaxing,
    1239              it will be handled here like other internal IND12W
    1240              relocs.  */
     2249             it will be handled here like other internal IND12W
     2250             relocs.  */
    12412251          bfd_put_16 (abfd,
    1242                       0xb000 | ((foff >> 1) & 0xfff),
     2252                      (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff),
    12432253                      contents + irel->r_offset);
    12442254        }
    12452255      else
     2256#endif
    12462257        {
    12472258          /* We can't fully resolve this yet, because the external
    1248              symbol value may be changed by future relaxing.  We let
    1249              the final link phase handle it.  */
    1250           bfd_put_16 (abfd, 0xb000, contents + irel->r_offset);
     2259             symbol value may be changed by future relaxing.  We let
     2260             the final link phase handle it.  */
     2261          bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
    12512262        }
     2263      irel->r_addend = -4;
    12522264
    12532265      /* See if there is another R_SH_USES reloc referring to the same
    1254         register load.  */
     2266        register load.  */
    12552267      for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
    12562268        if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES
     
    12672279
    12682280      /* Look for a R_SH_COUNT reloc on the location where the
    1269         function address is stored.  Do this before deleting any
    1270         bytes, to avoid confusion about the address.  */
     2281        function address is stored.  Do this before deleting any
     2282        bytes, to avoid confusion about the address.  */
    12712283      for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
    12722284        if (irelcount->r_offset == paddr
     
    12792291
    12802292      /* That will change things, so, just in case it permits some
    1281         other function call to come within range, we should relax
    1282         again.  Note that this is not required, and it may be slow.  */
    1283       *again = true;
     2293        other function call to come within range, we should relax
     2294        again.  Note that this is not required, and it may be slow.  */
     2295      *again = TRUE;
    12842296
    12852297      /* Now check whether we got a COUNT reloc.  */
     
    12882300          ((*_bfd_error_handler)
    12892301           (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
    1290             bfd_get_filename (abfd), (unsigned long) paddr));
     2302            bfd_archive_filename (abfd), (unsigned long) paddr));
    12912303          continue;
    12922304        }
    12932305
    12942306      /* The number of uses is stored in the r_addend field.  We've
    1295         just deleted one.  */
     2307        just deleted one.  */
    12962308      if (irelcount->r_addend == 0)
    12972309        {
    12982310          ((*_bfd_error_handler) (_("%s: 0x%lx: warning: bad count"),
    1299                                   bfd_get_filename (abfd),
     2311                                  bfd_archive_filename (abfd),
    13002312                                  (unsigned long) paddr));
    13012313          continue;
     
    13052317
    13062318      /* If there are no more uses, we can delete the address.  Reload
    1307         the address from irelfn, in case it was changed by the
    1308         previous call to sh_elf_relax_delete_bytes.  */
     2319        the address from irelfn, in case it was changed by the
     2320        previous call to sh_elf_relax_delete_bytes.  */
    13092321      if (irelcount->r_addend == 0)
    13102322        {
     
    13182330  /* Look for load and store instructions that we can align on four
    13192331     byte boundaries.  */
    1320   if (have_code)
     2332  if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
     2333      && have_code)
    13212334    {
    1322       boolean swapped;
     2335      bfd_boolean swapped;
    13232336
    13242337      /* Get the section contents.  */
     
    13322345              if (contents == NULL)
    13332346                goto error_return;
    1334               free_contents = contents;
    13352347
    13362348              if (! bfd_get_section_contents (abfd, sec, contents,
     
    13472359        {
    13482360          elf_section_data (sec)->relocs = internal_relocs;
    1349           free_relocs = NULL;
    1350 
    13512361          elf_section_data (sec)->this_hdr.contents = contents;
    1352           free_contents = NULL;
    1353 
    1354           symtab_hdr->contents = (bfd_byte *) extsyms;
    1355           free_extsyms = NULL;
     2362          symtab_hdr->contents = (unsigned char *) isymbuf;
    13562363        }
    13572364    }
    13582365
    1359   if (free_relocs != NULL)
    1360     {
    1361       free (free_relocs);
    1362       free_relocs = NULL;
    1363     }
    1364 
    1365   if (free_contents != NULL)
     2366  if (isymbuf != NULL
     2367      && symtab_hdr->contents != (unsigned char *) isymbuf)
    13662368    {
    13672369      if (! link_info->keep_memory)
    1368         free (free_contents);
     2370        free (isymbuf);
     2371      else
     2372        {
     2373          /* Cache the symbols for elf_link_input_bfd.  */
     2374          symtab_hdr->contents = (unsigned char *) isymbuf;
     2375        }
     2376    }
     2377
     2378  if (contents != NULL
     2379      && elf_section_data (sec)->this_hdr.contents != contents)
     2380    {
     2381      if (! link_info->keep_memory)
     2382        free (contents);
    13692383      else
    13702384        {
     
    13722386          elf_section_data (sec)->this_hdr.contents = contents;
    13732387        }
    1374       free_contents = NULL;
    13752388    }
    13762389
    1377   if (free_extsyms != NULL)
    1378     {
    1379       if (! link_info->keep_memory)
    1380         free (free_extsyms);
    1381       else
    1382         {
    1383           /* Cache the symbols for elf_link_input_bfd.  */
    1384           symtab_hdr->contents = extsyms;
    1385         }
    1386       free_extsyms = NULL;
    1387     }
    1388 
    1389   return true;
     2390  if (internal_relocs != NULL
     2391      && elf_section_data (sec)->relocs != internal_relocs)
     2392    free (internal_relocs);
     2393
     2394  return TRUE;
    13902395
    13912396 error_return:
    1392   if (free_relocs != NULL)
    1393     free (free_relocs);
    1394   if (free_contents != NULL)
    1395     free (free_contents);
    1396   if (free_extsyms != NULL)
    1397     free (free_extsyms);
    1398   return false;
     2397  if (isymbuf != NULL
     2398      && symtab_hdr->contents != (unsigned char *) isymbuf)
     2399    free (isymbuf);
     2400  if (contents != NULL
     2401      && elf_section_data (sec)->this_hdr.contents != contents)
     2402    free (contents);
     2403  if (internal_relocs != NULL
     2404      && elf_section_data (sec)->relocs != internal_relocs)
     2405    free (internal_relocs);
     2406
     2407  return FALSE;
    13992408}
    14002409
     
    14032412   in coff-sh.c.  */
    14042413
    1405 static boolean
     2414static bfd_boolean
    14062415sh_elf_relax_delete_bytes (abfd, sec, addr, count)
    14072416     bfd *abfd;
     
    14112420{
    14122421  Elf_Internal_Shdr *symtab_hdr;
    1413   Elf32_External_Sym *extsyms;
    1414   int shndx, index;
     2422  unsigned int sec_shndx;
    14152423  bfd_byte *contents;
    14162424  Elf_Internal_Rela *irel, *irelend;
    14172425  Elf_Internal_Rela *irelalign;
    14182426  bfd_vma toaddr;
    1419   Elf32_External_Sym *esym, *esymend;
    1420   struct elf_link_hash_entry *sym_hash;
     2427  Elf_Internal_Sym *isymbuf, *isym, *isymend;
     2428  struct elf_link_hash_entry **sym_hashes;
     2429  struct elf_link_hash_entry **end_hashes;
     2430  unsigned int symcount;
    14212431  asection *o;
    14222432
    14232433  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
    1424   extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
    1425 
    1426   shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
     2434  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
     2435
     2436  sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
    14272437
    14282438  contents = elf_section_data (sec)->this_hdr.contents;
     
    14492459
    14502460  /* Actually delete the bytes.  */
    1451   memmove (contents + addr, contents + addr + count, toaddr - addr - count);
     2461  memmove (contents + addr, contents + addr + count,
     2462           (size_t) (toaddr - addr - count));
    14522463  if (irelalign == NULL)
    14532464    sec->_cooked_size -= count;
     
    14602471      BFD_ASSERT ((count & 1) == 0);
    14612472      for (i = 0; i < count; i += 2)
    1462         bfd_put_16 (abfd, NOP_OPCODE, contents + toaddr - count + i);
     2473        bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
    14632474    }
    14642475
     
    14692480      bfd_vma start = 0;
    14702481      int insn = 0;
    1471       Elf_Internal_Sym sym;
    14722482      int off, adjust, oinsn;
    14732483      bfd_signed_vma voff = 0;
    1474       boolean overflow;
     2484      bfd_boolean overflow;
    14752485
    14762486      /* Get the new reloc address.  */
     
    14952505
    14962506      /* If this is a PC relative reloc, see if the range it covers
    1497         includes the bytes we have deleted.  */
     2507        includes the bytes we have deleted.  */
    14982508      switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
    14992509        {
     
    15182528        case R_SH_DIR32:
    15192529          /* If this reloc is against a symbol defined in this
    1520              section, and the symbol will not be adjusted below, we
    1521              must check the addend to see it will put the value in
    1522              range to be adjusted, and hence must be changed.  */
     2530             section, and the symbol will not be adjusted below, we
     2531             must check the addend to see it will put the value in
     2532             range to be adjusted, and hence must be changed.  */
    15232533          if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
    15242534            {
    1525               bfd_elf32_swap_symbol_in (abfd,
    1526                                         extsyms + ELF32_R_SYM (irel->r_info),
    1527                                         &sym);
    1528               if (sym.st_shndx == shndx
    1529                   && (sym.st_value <= addr
    1530                       || sym.st_value >= toaddr))
     2535              isym = isymbuf + ELF32_R_SYM (irel->r_info);
     2536              if (isym->st_shndx == sec_shndx
     2537                  && (isym->st_value <= addr
     2538                      || isym->st_value >= toaddr))
    15312539                {
    15322540                  bfd_vma val;
    15332541
    15342542                  val = bfd_get_32 (abfd, contents + nraddr);
    1535                   val += sym.st_value;
     2543                  val += isym->st_value;
    15362544                  if (val > addr && val < toaddr)
    15372545                    bfd_put_32 (abfd, val - count, contents + nraddr);
     
    15492557
    15502558        case R_SH_IND12W:
    1551           if (ELF32_R_SYM (irel->r_info) >= symtab_hdr->sh_info)
    1552             start = stop = addr;
     2559          off = insn & 0xfff;
     2560          if (! off)
     2561            {
     2562              /* This has been made by previous relaxation.  Since the
     2563                 relocation will be against an external symbol, the
     2564                 final relocation will just do the right thing.  */
     2565              start = stop = addr;
     2566            }
    15532567          else
    15542568            {
    1555               off = insn & 0xfff;
    15562569              if (off & 0x800)
    15572570                off -= 0x1000;
    15582571              stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
     2572
     2573              /* The addend will be against the section symbol, thus
     2574                 for adjusting the addend, the relevant start is the
     2575                 start of the section.
     2576                 N.B. If we want to abandom in-place changes here and
     2577                 test directly using symbol + addend, we have to take into
     2578                 account that the addend has already been adjusted by -4.  */
     2579              if (stop > addr && stop < toaddr)
     2580                irel->r_addend -= count;
    15592581            }
    15602582          break;
     
    16262648        {
    16272649          oinsn = insn;
    1628           overflow = false;
     2650          overflow = FALSE;
    16292651          switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
    16302652            {
     
    16372659              insn += adjust / 2;
    16382660              if ((oinsn & 0xff00) != (insn & 0xff00))
    1639                 overflow = true;
    1640               bfd_put_16 (abfd, insn, contents + nraddr);
     2661                overflow = TRUE;
     2662              bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
    16412663              break;
    16422664
     
    16442666              insn += adjust / 2;
    16452667              if ((oinsn & 0xf000) != (insn & 0xf000))
    1646                 overflow = true;
    1647               bfd_put_16 (abfd, insn, contents + nraddr);
     2668                overflow = TRUE;
     2669              bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
    16482670              break;
    16492671
     
    16582680                }
    16592681              if ((oinsn & 0xff00) != (insn & 0xff00))
    1660                 overflow = true;
    1661               bfd_put_16 (abfd, insn, contents + nraddr);
     2682                overflow = TRUE;
     2683              bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
    16622684              break;
    16632685
     
    16652687              voff += adjust;
    16662688              if (voff < 0 || voff >= 0xff)
    1667                 overflow = true;
     2689                overflow = TRUE;
    16682690              bfd_put_8 (abfd, voff, contents + nraddr);
    16692691              break;
     
    16722694              voff += adjust;
    16732695              if (voff < - 0x8000 || voff >= 0x8000)
    1674                 overflow = true;
    1675               bfd_put_signed_16 (abfd, voff, contents + nraddr);
     2696                overflow = TRUE;
     2697              bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
    16762698              break;
    16772699
    16782700            case R_SH_SWITCH32:
    16792701              voff += adjust;
    1680               bfd_put_signed_32 (abfd, voff, contents + nraddr);
     2702              bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
    16812703              break;
    16822704
     
    16902712              ((*_bfd_error_handler)
    16912713               (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
    1692                 bfd_get_filename (abfd), (unsigned long) irel->r_offset));
     2714                bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
    16932715              bfd_set_error (bfd_error_bad_value);
    1694               return false;
     2716              return FALSE;
    16952717            }
    16962718        }
     
    17142736
    17152737      /* We always cache the relocs.  Perhaps, if info->keep_memory is
    1716          false, we should free them, if we are permitted to, when we
    1717         leave sh_coff_relax_section.  */
     2738         FALSE, we should free them, if we are permitted to, when we
     2739        leave sh_coff_relax_section.  */
    17182740      internal_relocs = (_bfd_elf32_link_read_relocs
    17192741                         (abfd, o, (PTR) NULL, (Elf_Internal_Rela *) NULL,
    1720                           true));
     2742                          TRUE));
    17212743      if (internal_relocs == NULL)
    1722         return false;
     2744        return FALSE;
    17232745
    17242746      ocontents = NULL;
     
    17262748      for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
    17272749        {
    1728           Elf_Internal_Sym sym;
    1729 
    17302750          /* Dwarf line numbers use R_SH_SWITCH32 relocs.  */
    17312751          if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32)
     
    17412761                    {
    17422762                      /* We always cache the section contents.
    1743                          Perhaps, if info->keep_memory is false, we
    1744                         should free them, if we are permitted to,
    1745                         when we leave sh_coff_relax_section.  */
     2763                         Perhaps, if info->keep_memory is FALSE, we
     2764                        should free them, if we are permitted to,
     2765                        when we leave sh_coff_relax_section.  */
    17462766                      ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
    17472767                      if (ocontents == NULL)
    1748                         return false;
     2768                        return FALSE;
    17492769                      if (! bfd_get_section_contents (abfd, o, ocontents,
    17502770                                                      (file_ptr) 0,
    17512771                                                      o->_raw_size))
    1752                         return false;
     2772                        return FALSE;
    17532773                      elf_section_data (o)->this_hdr.contents = ocontents;
    17542774                    }
     
    17692789                  && start < toaddr
    17702790                  && (stop <= addr || stop >= toaddr))
    1771                 bfd_put_signed_32 (abfd, voff + count,
     2791                bfd_put_signed_32 (abfd, (bfd_vma) voff + count,
    17722792                                   ocontents + irelscan->r_offset);
    17732793              else if (stop > addr
    17742794                       && stop < toaddr
    17752795                       && (start <= addr || start >= toaddr))
    1776                 bfd_put_signed_32 (abfd, voff - count,
     2796                bfd_put_signed_32 (abfd, (bfd_vma) voff - count,
    17772797                                   ocontents + irelscan->r_offset);
    17782798            }
     
    17842804            continue;
    17852805
    1786           bfd_elf32_swap_symbol_in (abfd,
    1787                                     extsyms + ELF32_R_SYM (irelscan->r_info),
    1788                                     &sym);
    1789 
    1790           if (sym.st_shndx == shndx
    1791               && (sym.st_value <= addr
    1792                   || sym.st_value >= toaddr))
     2806
     2807          isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
     2808          if (isym->st_shndx == sec_shndx
     2809              && (isym->st_value <= addr
     2810                  || isym->st_value >= toaddr))
    17932811            {
    17942812              bfd_vma val;
     
    18012819                    {
    18022820                      /* We always cache the section contents.
    1803                          Perhaps, if info->keep_memory is false, we
    1804                         should free them, if we are permitted to,
    1805                         when we leave sh_coff_relax_section.  */
     2821                         Perhaps, if info->keep_memory is FALSE, we
     2822                        should free them, if we are permitted to,
     2823                        when we leave sh_coff_relax_section.  */
    18062824                      ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
    18072825                      if (ocontents == NULL)
    1808                         return false;
     2826                        return FALSE;
    18092827                      if (! bfd_get_section_contents (abfd, o, ocontents,
    18102828                                                      (file_ptr) 0,
    18112829                                                      o->_raw_size))
    1812                         return false;
     2830                        return FALSE;
    18132831                      elf_section_data (o)->this_hdr.contents = ocontents;
    18142832                    }
     
    18162834
    18172835              val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
    1818               val += sym.st_value;
     2836              val += isym->st_value;
    18192837              if (val > addr && val < toaddr)
    18202838                bfd_put_32 (abfd, val - count,
     
    18252843
    18262844  /* Adjust the local symbols defined in this section.  */
    1827   esym = extsyms;
    1828   esymend = esym + symtab_hdr->sh_info;
    1829   for (; esym < esymend; esym++)
     2845  isymend = isymbuf + symtab_hdr->sh_info;
     2846  for (isym = isymbuf; isym < isymend; isym++)
    18302847    {
    1831       Elf_Internal_Sym isym;
    1832 
    1833       bfd_elf32_swap_symbol_in (abfd, esym, &isym);
    1834 
    1835       if (isym.st_shndx == shndx
    1836           && isym.st_value > addr
    1837           && isym.st_value < toaddr)
     2848      if (isym->st_shndx == sec_shndx
     2849          && isym->st_value > addr
     2850          && isym->st_value < toaddr)
     2851        isym->st_value -= count;
     2852    }
     2853
     2854  /* Now adjust the global symbols defined in this section.  */
     2855  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
     2856              - symtab_hdr->sh_info);
     2857  sym_hashes = elf_sym_hashes (abfd);
     2858  end_hashes = sym_hashes + symcount;
     2859  for (; sym_hashes < end_hashes; sym_hashes++)
     2860    {
     2861      struct elf_link_hash_entry *sym_hash = *sym_hashes;
     2862      if ((sym_hash->root.type == bfd_link_hash_defined
     2863           || sym_hash->root.type == bfd_link_hash_defweak)
     2864          && sym_hash->root.u.def.section == sec
     2865          && sym_hash->root.u.def.value > addr
     2866          && sym_hash->root.u.def.value < toaddr)
    18382867        {
    1839           isym.st_value -= count;
    1840           bfd_elf32_swap_symbol_out (abfd, &isym, esym);
    1841         }
    1842     }
    1843 
    1844   /* Now adjust the global symbols defined in this section.  */
    1845   esym = extsyms + symtab_hdr->sh_info;
    1846   esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
    1847   for (index = 0; esym < esymend; esym++, index++)
    1848     {
    1849       Elf_Internal_Sym isym;
    1850 
    1851       bfd_elf32_swap_symbol_in (abfd, esym, &isym);
    1852       sym_hash = elf_sym_hashes (abfd)[index];
    1853       if (isym.st_shndx == shndx
    1854           && ((sym_hash)->root.type == bfd_link_hash_defined
    1855               || (sym_hash)->root.type == bfd_link_hash_defweak)
    1856           && (sym_hash)->root.u.def.section == sec
    1857           && (sym_hash)->root.u.def.value > addr
    1858           && (sym_hash)->root.u.def.value < toaddr)
    1859         {
    1860           (sym_hash)->root.u.def.value -= count;
     2868          sym_hash->root.u.def.value -= count;
    18612869        }
    18622870    }
     
    18752883          /* Tail recursion.  */
    18762884          return sh_elf_relax_delete_bytes (abfd, sec, alignaddr,
    1877                                             alignto - alignaddr);
     2885                                            (int) (alignto - alignaddr));
    18782886        }
    18792887    }
    18802888
    1881   return true;
     2889  return TRUE;
    18822890}
    18832891
     
    18852893   boundaries.  This is like sh_align_loads in coff-sh.c.  */
    18862894
    1887 static boolean
     2895static bfd_boolean
    18882896sh_elf_align_loads (abfd, sec, internal_relocs, contents, pswapped)
    1889      bfd *abfd;
     2897     bfd *abfd ATTRIBUTE_UNUSED;
    18902898     asection *sec;
    18912899     Elf_Internal_Rela *internal_relocs;
    1892      bfd_byte *contents;
    1893      boolean *pswapped;
     2900     bfd_byte *contents ATTRIBUTE_UNUSED;
     2901     bfd_boolean *pswapped;
    18942902{
    18952903  Elf_Internal_Rela *irel, *irelend;
    18962904  bfd_vma *labels = NULL;
    18972905  bfd_vma *label, *label_end;
    1898 
    1899   *pswapped = false;
     2906  bfd_size_type amt;
     2907
     2908  *pswapped = FALSE;
    19002909
    19012910  irelend = internal_relocs + sec->reloc_count;
    19022911
    19032912  /* Get all the addresses with labels on them.  */
    1904   labels = (bfd_vma *) bfd_malloc (sec->reloc_count * sizeof (bfd_vma));
     2913  amt = sec->reloc_count;
     2914  amt *= sizeof (bfd_vma);
     2915  labels = (bfd_vma *) bfd_malloc (amt);
    19052916  if (labels == NULL)
    19062917    goto error_return;
     
    19462957  free (labels);
    19472958
    1948   return true;
     2959  return TRUE;
    19492960
    19502961 error_return:
    19512962  if (labels != NULL)
    19522963    free (labels);
    1953   return false;
     2964  return FALSE;
    19542965}
    19552966
    19562967/* Swap two SH instructions.  This is like sh_swap_insns in coff-sh.c.  */
    19572968
    1958 static boolean
     2969static bfd_boolean
    19592970sh_elf_swap_insns (abfd, sec, relocs, contents, addr)
    19602971     bfd *abfd;
     
    19712982  i1 = bfd_get_16 (abfd, contents + addr);
    19722983  i2 = bfd_get_16 (abfd, contents + addr + 2);
    1973   bfd_put_16 (abfd, i2, contents + addr);
    1974   bfd_put_16 (abfd, i1, contents + addr + 2);
     2984  bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
     2985  bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
    19752986
    19762987  /* Adjust all reloc addresses.  */
     
    19822993
    19832994      /* There are a few special types of relocs that we don't want to
    1984         adjust.  These relocs do not apply to the instruction itself,
    1985         but are only associated with the address.  */
     2995        adjust.  These relocs do not apply to the instruction itself,
     2996        but are only associated with the address.  */
    19862997      type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);
    19872998      if (type == R_SH_ALIGN
     
    19923003
    19933004      /* If an R_SH_USES reloc points to one of the addresses being
    1994         swapped, we must adjust it.  It would be incorrect to do this
    1995         for a jump, though, since we want to execute both
    1996         instructions after the jump.  (We have avoided swapping
    1997         around a label, so the jump will not wind up executing an
    1998         instruction it shouldn't).  */
     3005        swapped, we must adjust it.  It would be incorrect to do this
     3006        for a jump, though, since we want to execute both
     3007        instructions after the jump.  (We have avoided swapping
     3008        around a label, so the jump will not wind up executing an
     3009        instruction it shouldn't).  */
    19993010      if (type == R_SH_USES)
    20003011        {
     
    20253036          bfd_byte *loc;
    20263037          unsigned short insn, oinsn;
    2027           boolean overflow;
     3038          bfd_boolean overflow;
    20283039
    20293040          loc = contents + irel->r_offset;
    2030           overflow = false;
     3041          overflow = FALSE;
    20313042          switch (type)
    20323043            {
     
    20403051              insn += add / 2;
    20413052              if ((oinsn & 0xff00) != (insn & 0xff00))
    2042                 overflow = true;
    2043               bfd_put_16 (abfd, insn, loc);
     3053                overflow = TRUE;
     3054              bfd_put_16 (abfd, (bfd_vma) insn, loc);
    20443055              break;
    20453056
     
    20493060              insn += add / 2;
    20503061              if ((oinsn & 0xf000) != (insn & 0xf000))
    2051                 overflow = true;
    2052               bfd_put_16 (abfd, insn, loc);
     3062                overflow = TRUE;
     3063              bfd_put_16 (abfd, (bfd_vma) insn, loc);
    20533064              break;
    20543065
    20553066            case R_SH_DIR8WPL:
    20563067              /* This reloc ignores the least significant 3 bits of
    2057                 the program counter before adding in the offset.
    2058                 This means that if ADDR is at an even address, the
    2059                 swap will not affect the offset.  If ADDR is an at an
    2060                 odd address, then the instruction will be crossing a
    2061                 four byte boundary, and must be adjusted.  */
     3068                the program counter before adding in the offset.
     3069                This means that if ADDR is at an even address, the
     3070                swap will not affect the offset.  If ADDR is an at an
     3071                odd address, then the instruction will be crossing a
     3072                four byte boundary, and must be adjusted.  */
    20623073              if ((addr & 3) != 0)
    20633074                {
     
    20663077                  insn += add / 2;
    20673078                  if ((oinsn & 0xff00) != (insn & 0xff00))
    2068                     overflow = true;
    2069                   bfd_put_16 (abfd, insn, loc);
     3079                    overflow = TRUE;
     3080                  bfd_put_16 (abfd, (bfd_vma) insn, loc);
    20703081                }
    20713082
     
    20773088              ((*_bfd_error_handler)
    20783089               (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
    2079                 bfd_get_filename (abfd), (unsigned long) irel->r_offset));
     3090                bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
    20803091              bfd_set_error (bfd_error_bad_value);
    2081               return false;
     3092              return FALSE;
    20823093            }
    20833094        }
    20843095    }
    20853096
    2086   return true;
     3097  return TRUE;
    20873098}
    20883099
    20893100
     3101#ifdef INCLUDE_SHMEDIA
     3102
    20903103/* The size in bytes of an entry in the procedure linkage table.  */
    20913104
     3105#define PLT_ENTRY_SIZE 64
     3106
     3107/* First entry in an absolute procedure linkage table look like this.  */
     3108
     3109static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
     3110{
     3111  0xcc, 0x00, 0x01, 0x10, /* movi  .got.plt >> 16, r17 */
     3112  0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
     3113  0x89, 0x10, 0x09, 0x90, /* ld.l  r17, 8, r25 */
     3114  0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
     3115  0x89, 0x10, 0x05, 0x10, /* ld.l  r17, 4, r17 */
     3116  0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
     3117  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3118  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3119  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3120  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3121  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3122  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3123  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3124  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3125  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3126  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3127};
     3128
     3129static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
     3130{
     3131  0x10, 0x01, 0x00, 0xcc, /* movi  .got.plt >> 16, r17 */
     3132  0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
     3133  0x90, 0x09, 0x10, 0x89, /* ld.l  r17, 8, r25 */
     3134  0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
     3135  0x10, 0x05, 0x10, 0x89, /* ld.l  r17, 4, r17 */
     3136  0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
     3137  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3138  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3139  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3140  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3141  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3142  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3143  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3144  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3145  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3146  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3147};
     3148
     3149/* Sebsequent entries in an absolute procedure linkage table look like
     3150   this.  */
     3151
     3152static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
     3153{
     3154  0xcc, 0x00, 0x01, 0x90, /* movi  nameN-in-GOT >> 16, r25 */
     3155  0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
     3156  0x89, 0x90, 0x01, 0x90, /* ld.l  r25, 0, r25 */
     3157  0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
     3158  0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
     3159  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3160  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3161  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3162  0xcc, 0x00, 0x01, 0x90, /* movi  .PLT0 >> 16, r25 */
     3163  0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
     3164  0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
     3165  0xcc, 0x00, 0x01, 0x50, /* movi  reloc-offset >> 16, r21 */
     3166  0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
     3167  0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
     3168  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3169  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3170};
     3171
     3172static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
     3173{
     3174  0x90, 0x01, 0x00, 0xcc, /* movi  nameN-in-GOT >> 16, r25 */
     3175  0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
     3176  0x90, 0x01, 0x90, 0x89, /* ld.l  r25, 0, r25 */
     3177  0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
     3178  0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
     3179  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3180  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3181  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3182  0x90, 0x01, 0x00, 0xcc, /* movi  .PLT0 >> 16, r25 */
     3183  0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
     3184  0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
     3185  0x50, 0x01, 0x00, 0xcc, /* movi  reloc-offset >> 16, r21 */
     3186  0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
     3187  0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
     3188  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3189  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3190};
     3191
     3192/* Entries in a PIC procedure linkage table look like this.  */
     3193
     3194static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
     3195{
     3196  0xcc, 0x00, 0x01, 0x90, /* movi  nameN@GOT >> 16, r25 */
     3197  0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
     3198  0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
     3199  0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
     3200  0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
     3201  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3202  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3203  0x6f, 0xf0, 0xff, 0xf0, /* nop */
     3204  0xce, 0x00, 0x01, 0x10, /* movi  -GOT_BIAS, r17 */
     3205  0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
     3206  0x89, 0x10, 0x09, 0x90, /* ld.l  r17, 8, r25 */
     3207  0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
     3208  0x89, 0x10, 0x05, 0x10, /* ld.l  r17, 4, r17 */
     3209  0xcc, 0x00, 0x01, 0x50, /* movi  reloc-offset >> 16, r21 */
     3210  0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
     3211  0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
     3212};
     3213
     3214static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
     3215{
     3216  0x90, 0x01, 0x00, 0xcc, /* movi  nameN@GOT >> 16, r25 */
     3217  0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
     3218  0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
     3219  0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
     3220  0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
     3221  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3222  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3223  0xf0, 0xff, 0xf0, 0x6f, /* nop */
     3224  0x10, 0x01, 0x00, 0xce, /* movi  -GOT_BIAS, r17 */
     3225  0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
     3226  0x90, 0x09, 0x10, 0x89, /* ld.l  r17, 8, r25 */
     3227  0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
     3228  0x10, 0x05, 0x10, 0x89, /* ld.l  r17, 4, r17 */
     3229  0x50, 0x01, 0x00, 0xcc, /* movi  reloc-offset >> 16, r21 */
     3230  0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
     3231  0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
     3232};
     3233
     3234static const bfd_byte *elf_sh_plt0_entry;
     3235static const bfd_byte *elf_sh_plt_entry;
     3236static const bfd_byte *elf_sh_pic_plt_entry;
     3237
     3238/* Return size of a PLT entry.  */
     3239#define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
     3240
     3241/* Return offset of the PLT0 address in an absolute PLT entry.  */
     3242#define elf_sh_plt_plt0_offset(info) 32
     3243
     3244/* Return offset of the linker in PLT0 entry.  */
     3245#define elf_sh_plt0_gotplt_offset(info) 0
     3246
     3247/* Return offset of the trampoline in PLT entry */
     3248#define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia.  */
     3249
     3250/* Return offset of the symbol in PLT entry.  */
     3251#define elf_sh_plt_symbol_offset(info) 0
     3252
     3253/* Return offset of the relocation in PLT entry.  */
     3254#define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
     3255
     3256inline static void
     3257movi_shori_putval (output_bfd, value, addr)
     3258     bfd *output_bfd;
     3259     unsigned long value;
     3260     char *addr;
     3261{
     3262  bfd_put_32 (output_bfd,
     3263              bfd_get_32 (output_bfd, addr)
     3264              | ((value >> 6) & 0x3fffc00),
     3265              addr);
     3266  bfd_put_32 (output_bfd,
     3267              bfd_get_32 (output_bfd, addr + 4)
     3268              | ((value << 10) & 0x3fffc00),
     3269              addr + 4);
     3270}
     3271
     3272#else
     3273/* The size in bytes of an entry in the procedure linkage table.  */
     3274
    20923275#define PLT_ENTRY_SIZE 28
    20933276
    20943277/* First entry in an absolute procedure linkage table look like this.  */
    20953278
     3279#if 1
     3280/* Note - this code has been "optimised" not to use r2.  r2 is used by
     3281   GCC to return the address of large strutcures, so it should not be
     3282   corrupted here.  This does mean however, that this PLT does not conform
     3283   to the SH PIC ABI.  That spec says that r0 contains the type of the PLT
     3284   and r2 contains the GOT id.  This version stores the GOT id in r0 and
     3285   ignores the type.  Loaders can easily detect this difference however,
     3286   since the type will always be 0 or 8, and the GOT ids will always be
     3287   greater than or equal to 12.  */
     3288static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
     3289{
     3290  0xd0, 0x05,   /* mov.l 2f,r0 */
     3291  0x60, 0x02,   /* mov.l @r0,r0 */
     3292  0x2f, 0x06,   /* mov.l r0,@-r15 */
     3293  0xd0, 0x03,   /* mov.l 1f,r0 */
     3294  0x60, 0x02,   /* mov.l @r0,r0 */
     3295  0x40, 0x2b,   /* jmp @r0 */
     3296  0x60, 0xf6,   /*  mov.l @r15+,r0 */
     3297  0x00, 0x09,   /* nop */
     3298  0x00, 0x09,   /* nop */
     3299  0x00, 0x09,   /* nop */
     3300  0, 0, 0, 0,   /* 1: replaced with address of .got.plt + 8.  */
     3301  0, 0, 0, 0,   /* 2: replaced with address of .got.plt + 4.  */
     3302};
     3303
     3304static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
     3305{
     3306  0x05, 0xd0,   /* mov.l 2f,r0 */
     3307  0x02, 0x60,   /* mov.l @r0,r0 */
     3308  0x06, 0x2f,   /* mov.l r0,@-r15 */
     3309  0x03, 0xd0,   /* mov.l 1f,r0 */
     3310  0x02, 0x60,   /* mov.l @r0,r0 */
     3311  0x2b, 0x40,   /* jmp @r0 */
     3312  0xf6, 0x60,   /*  mov.l @r15+,r0 */
     3313  0x09, 0x00,   /* nop */
     3314  0x09, 0x00,   /* nop */
     3315  0x09, 0x00,   /* nop */
     3316  0, 0, 0, 0,   /* 1: replaced with address of .got.plt + 8.  */
     3317  0, 0, 0, 0,   /* 2: replaced with address of .got.plt + 4.  */
     3318};
     3319
     3320/* Sebsequent entries in an absolute procedure linkage table look like
     3321   this.  */
     3322
     3323static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
     3324{
     3325  0xd0, 0x04,   /* mov.l 1f,r0 */
     3326  0x60, 0x02,   /* mov.l @r0,r0 */
     3327  0xd1, 0x02,   /* mov.l 0f,r1 */
     3328  0x40, 0x2b,   /* jmp @r0 */
     3329  0x60, 0x13,   /*  mov r1,r0 */
     3330  0xd1, 0x03,   /* mov.l 2f,r1 */
     3331  0x40, 0x2b,   /* jmp @r0 */
     3332  0x00, 0x09,   /* nop */
     3333  0, 0, 0, 0,   /* 0: replaced with address of .PLT0.  */
     3334  0, 0, 0, 0,   /* 1: replaced with address of this symbol in .got.  */
     3335  0, 0, 0, 0,   /* 2: replaced with offset into relocation table.  */
     3336};
     3337
     3338static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
     3339{
     3340  0x04, 0xd0,   /* mov.l 1f,r0 */
     3341  0x02, 0x60,   /* mov.l @r0,r0 */
     3342  0x02, 0xd1,   /* mov.l 0f,r1 */
     3343  0x2b, 0x40,   /* jmp @r0 */
     3344  0x13, 0x60,   /*  mov r1,r0 */
     3345  0x03, 0xd1,   /* mov.l 2f,r1 */
     3346  0x2b, 0x40,   /* jmp @r0 */
     3347  0x09, 0x00,   /*  nop */
     3348  0, 0, 0, 0,   /* 0: replaced with address of .PLT0.  */
     3349  0, 0, 0, 0,   /* 1: replaced with address of this symbol in .got.  */
     3350  0, 0, 0, 0,   /* 2: replaced with offset into relocation table.  */
     3351};
     3352
     3353/* Entries in a PIC procedure linkage table look like this.  */
     3354
     3355static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
     3356{
     3357  0xd0, 0x04,   /* mov.l 1f,r0 */
     3358  0x00, 0xce,   /* mov.l @(r0,r12),r0 */
     3359  0x40, 0x2b,   /* jmp @r0 */
     3360  0x00, 0x09,   /*  nop */
     3361  0x50, 0xc2,   /* mov.l @(8,r12),r0 */
     3362  0xd1, 0x03,   /* mov.l 2f,r1 */
     3363  0x40, 0x2b,   /* jmp @r0 */
     3364  0x50, 0xc1,   /*  mov.l @(4,r12),r0 */
     3365  0x00, 0x09,   /* nop */
     3366  0x00, 0x09,   /* nop */
     3367  0, 0, 0, 0,   /* 1: replaced with address of this symbol in .got.  */
     3368  0, 0, 0, 0    /* 2: replaced with offset into relocation table.  */
     3369};
     3370
     3371static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
     3372{
     3373  0x04, 0xd0,   /* mov.l 1f,r0 */
     3374  0xce, 0x00,   /* mov.l @(r0,r12),r0 */
     3375  0x2b, 0x40,   /* jmp @r0 */
     3376  0x09, 0x00,   /*  nop */
     3377  0xc2, 0x50,   /* mov.l @(8,r12),r0 */
     3378  0x03, 0xd1,   /* mov.l 2f,r1 */
     3379  0x2b, 0x40,   /* jmp @r0 */
     3380  0xc1, 0x50,   /*  mov.l @(4,r12),r0 */
     3381  0x09, 0x00,   /*  nop */
     3382  0x09, 0x00,   /* nop */
     3383  0, 0, 0, 0,   /* 1: replaced with address of this symbol in .got.  */
     3384  0, 0, 0, 0    /* 2: replaced with offset into relocation table.  */
     3385};
     3386
     3387#else /* These are the old style PLT entries.  */
    20963388static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
    20973389{
     
    21923484  0, 0, 0, 0    /* 2: replaced with offset into relocation table.  */
    21933485};
     3486#endif /* old style PLT entries.  */
    21943487
    21953488static const bfd_byte *elf_sh_plt0_entry;
     
    22173510/* Return offset of the relocation in PLT entry.  */
    22183511#define elf_sh_plt_reloc_offset(info) 24
     3512#endif
    22193513
    22203514/* The sh linker needs to keep track of the number of relocs that it
    2221    decides to copy in check_relocs for each symbol.  This is so that
    2222    it can discard PC relative relocs if it doesn't need them when
    2223    linking with -Bsymbolic.  We store the information in a field
    2224    extending the regular ELF linker hash table.  */
    2225 
    2226 /* This structure keeps track of the number of PC relative relocs we
    2227    have copied for a given symbol.  */
    2228 
    2229 struct elf_sh_pcrel_relocs_copied
     3515   decides to copy as dynamic relocs in check_relocs for each symbol.
     3516   This is so that it can later discard them if they are found to be
     3517   unnecessary.  We store the information in a field extending the
     3518   regular ELF linker hash table.  */
     3519
     3520struct elf_sh_dyn_relocs
    22303521{
    2231   /* Next section.  */
    2232   struct elf_sh_pcrel_relocs_copied *next;
    2233   /* A section in dynobj.  */
    2234   asection *section;
    2235   /* Number of relocs copied in this section.  */
     3522  struct elf_sh_dyn_relocs *next;
     3523
     3524  /* The input section of the reloc.  */
     3525  asection *sec;
     3526
     3527  /* Total number of relocs copied for the input section.  */
    22363528  bfd_size_type count;
     3529
     3530  /* Number of pc-relative relocs copied for the input section.  */
     3531  bfd_size_type pc_count;
    22373532};
    22383533
     
    22433538  struct elf_link_hash_entry root;
    22443539
    2245   /* Number of PC relative relocs copied for this symbol.  */
    2246   struct elf_sh_pcrel_relocs_copied *pcrel_relocs_copied;
     3540#ifdef INCLUDE_SHMEDIA
     3541  union
     3542  {
     3543    bfd_signed_vma refcount;
     3544    bfd_vma offset;
     3545  } datalabel_got;
     3546#endif
     3547
     3548  /* Track dynamic relocs copied for this symbol.  */
     3549  struct elf_sh_dyn_relocs *dyn_relocs;
     3550
     3551  bfd_signed_vma gotplt_refcount;
     3552
     3553  enum {
     3554    GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE
     3555  } tls_type;
    22473556};
     3557
     3558#define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
     3559
     3560struct sh_elf_obj_tdata
     3561{
     3562  struct elf_obj_tdata root;
     3563
     3564  /* tls_type for each local got entry.  */
     3565  char *local_got_tls_type;
     3566};
     3567
     3568#define sh_elf_tdata(abfd) \
     3569  ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
     3570
     3571#define sh_elf_local_got_tls_type(abfd) \
     3572  (sh_elf_tdata (abfd)->local_got_tls_type)
     3573
     3574/* Override the generic function because we need to store sh_elf_obj_tdata
     3575   as the specific tdata.  */
     3576
     3577static bfd_boolean
     3578sh_elf_mkobject (abfd)
     3579     bfd *abfd;
     3580{
     3581  bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
     3582  abfd->tdata.any = bfd_zalloc (abfd, amt);
     3583  if (abfd->tdata.any == NULL)
     3584    return FALSE;
     3585  return TRUE;
     3586}
    22483587
    22493588/* sh ELF linker hash table.  */
     
    22523591{
    22533592  struct elf_link_hash_table root;
     3593
     3594  /* Short-cuts to get to dynamic linker sections.  */
     3595  asection *sgot;
     3596  asection *sgotplt;
     3597  asection *srelgot;
     3598  asection *splt;
     3599  asection *srelplt;
     3600  asection *sdynbss;
     3601  asection *srelbss;
     3602
     3603  /* Small local sym to section mapping cache.  */
     3604  struct sym_sec_cache sym_sec;
     3605
     3606  /* A counter or offset to track a TLS got entry.  */
     3607  union
     3608    {
     3609      bfd_signed_vma refcount;
     3610      bfd_vma offset;
     3611    } tls_ldm_got;
    22543612};
    2255 
    2256 /* Declare this now that the above structures are defined.  */
    2257 
    2258 static boolean sh_elf_discard_copies
    2259   PARAMS ((struct elf_sh_link_hash_entry *, PTR));
    22603613
    22613614/* Traverse an sh ELF linker hash table.  */
     
    22643617  (elf_link_hash_traverse                                               \
    22653618   (&(table)->root,                                                     \
    2266     (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func),  \
     3619    (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
    22673620    (info)))
    22683621
     
    22983651  if (ret != (struct elf_sh_link_hash_entry *) NULL)
    22993652    {
    2300       ret->pcrel_relocs_copied = NULL;
     3653      ret->dyn_relocs = NULL;
     3654      ret->gotplt_refcount = 0;
     3655#ifdef INCLUDE_SHMEDIA
     3656      ret->datalabel_got.refcount = ret->root.got.refcount;
     3657#endif
     3658      ret->tls_type = GOT_UNKNOWN;
    23013659    }
    23023660
     
    23113669{
    23123670  struct elf_sh_link_hash_table *ret;
    2313 
    2314   ret = ((struct elf_sh_link_hash_table *)
    2315          bfd_alloc (abfd, sizeof (struct elf_sh_link_hash_table)));
     3671  bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
     3672
     3673  ret = (struct elf_sh_link_hash_table *) bfd_malloc (amt);
    23163674  if (ret == (struct elf_sh_link_hash_table *) NULL)
    23173675    return NULL;
     
    23203678                                       sh_elf_link_hash_newfunc))
    23213679    {
    2322       bfd_release (abfd, ret);
     3680      free (ret);
    23233681      return NULL;
    23243682    }
    23253683
     3684  ret->sgot = NULL;
     3685  ret->sgotplt = NULL;
     3686  ret->srelgot = NULL;
     3687  ret->splt = NULL;
     3688  ret->srelplt = NULL;
     3689  ret->sdynbss = NULL;
     3690  ret->srelbss = NULL;
     3691  ret->sym_sec.abfd = NULL;
     3692  ret->tls_ldm_got.refcount = 0;
     3693
    23263694  return &ret->root.root;
    23273695}
    23283696
     3697/* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
     3698   shortcuts to them in our hash table.  */
     3699
     3700static bfd_boolean
     3701create_got_section (dynobj, info)
     3702     bfd *dynobj;
     3703     struct bfd_link_info *info;
     3704{
     3705  struct elf_sh_link_hash_table *htab;
     3706
     3707  if (! _bfd_elf_create_got_section (dynobj, info))
     3708    return FALSE;
     3709
     3710  htab = sh_elf_hash_table (info);
     3711  htab->sgot = bfd_get_section_by_name (dynobj, ".got");
     3712  htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
     3713  if (! htab->sgot || ! htab->sgotplt)
     3714    abort ();
     3715
     3716  htab->srelgot = bfd_make_section (dynobj, ".rela.got");
     3717  if (htab->srelgot == NULL
     3718      || ! bfd_set_section_flags (dynobj, htab->srelgot,
     3719                                  (SEC_ALLOC
     3720                                   | SEC_LOAD
     3721                                   | SEC_HAS_CONTENTS
     3722                                   | SEC_IN_MEMORY
     3723                                   | SEC_LINKER_CREATED
     3724                                   | SEC_READONLY))
     3725      || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
     3726    return FALSE;
     3727  return TRUE;
     3728}
     3729
    23293730/* Create dynamic sections when linking against a dynamic object.  */
    23303731
    2331 static boolean
     3732static bfd_boolean
    23323733sh_elf_create_dynamic_sections (abfd, info)
    23333734     bfd *abfd;
    23343735     struct bfd_link_info *info;
    23353736{
     3737  struct elf_sh_link_hash_table *htab;
    23363738  flagword flags, pltflags;
    23373739  register asection *s;
     
    23513753    default:
    23523754      bfd_set_error (bfd_error_bad_value);
    2353       return false;
     3755      return FALSE;
    23543756    }
     3757
     3758  htab = sh_elf_hash_table (info);
    23553759
    23563760  /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
     
    23683772
    23693773  s = bfd_make_section (abfd, ".plt");
     3774  htab->splt = s;
    23703775  if (s == NULL
    23713776      || ! bfd_set_section_flags (abfd, s, pltflags)
    23723777      || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
    2373     return false;
     3778    return FALSE;
    23743779
    23753780  if (bed->want_plt_sym)
     
    23773782      /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
    23783783         .plt section.  */
    2379       struct elf_link_hash_entry *h = NULL;
     3784      struct elf_link_hash_entry *h;
     3785      struct bfd_link_hash_entry *bh = NULL;
     3786
    23803787      if (! (_bfd_generic_link_add_one_symbol
    23813788             (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
    2382               (bfd_vma) 0, (const char *) NULL, false,
    2383               get_elf_backend_data (abfd)->collect,
    2384               (struct bfd_link_hash_entry **) &h)))
    2385         return false;
     3789              (bfd_vma) 0, (const char *) NULL, FALSE,
     3790              get_elf_backend_data (abfd)->collect, &bh)))
     3791        return FALSE;
     3792
     3793      h = (struct elf_link_hash_entry *) bh;
    23863794      h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
    23873795      h->type = STT_OBJECT;
     
    23893797      if (info->shared
    23903798          && ! _bfd_elf_link_record_dynamic_symbol (info, h))
    2391         return false;
     3799        return FALSE;
    23923800    }
    23933801
    23943802  s = bfd_make_section (abfd,
    23953803                        bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
     3804  htab->srelplt = s;
    23963805  if (s == NULL
    23973806      || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
    23983807      || ! bfd_set_section_alignment (abfd, s, ptralign))
    2399     return false;
    2400 
    2401   if (! _bfd_elf_create_got_section (abfd, info))
    2402     return false;
     3808    return FALSE;
     3809
     3810  if (! create_got_section (abfd, info))
     3811    return FALSE;
    24033812
    24043813  {
     
    24153824          continue;
    24163825        secname = bfd_get_section_name (abfd, sec);
    2417         relname = (char *) bfd_malloc (strlen (secname) + 6);
     3826        relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
    24183827        strcpy (relname, ".rela");
    24193828        strcat (relname, secname);
     
    24223831            || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
    24233832            || ! bfd_set_section_alignment (abfd, s, ptralign))
    2424           return false;
     3833          return FALSE;
    24253834      }
    24263835  }
     
    24353844         section into the .bss section of the final image.  */
    24363845      s = bfd_make_section (abfd, ".dynbss");
     3846      htab->sdynbss = s;
    24373847      if (s == NULL
    24383848          || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
    2439         return false;
     3849        return FALSE;
    24403850
    24413851      /* The .rel[a].bss section holds copy relocs.  This section is not
     
    24553865                                (bed->default_use_rela_p
    24563866                                 ? ".rela.bss" : ".rel.bss"));
     3867          htab->srelbss = s;
    24573868          if (s == NULL
    24583869              || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
    24593870              || ! bfd_set_section_alignment (abfd, s, ptralign))
    2460             return false;
     3871            return FALSE;
    24613872        }
    24623873    }
    24633874
    2464   return true;
     3875  return TRUE;
    24653876}
    24663877
     
    24723883   understand.  */
    24733884
    2474 static boolean
     3885static bfd_boolean
    24753886sh_elf_adjust_dynamic_symbol (info, h)
    24763887     struct bfd_link_info *info;
    24773888     struct elf_link_hash_entry *h;
    24783889{
     3890  struct elf_sh_link_hash_table *htab;
     3891  struct elf_sh_link_hash_entry *eh;
     3892  struct elf_sh_dyn_relocs *p;
    24793893  bfd *dynobj;
    24803894  asection *s;
     
    25003914      || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
    25013915    {
    2502       if (! info->shared
    2503           && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
    2504           && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
     3916      if (h->plt.refcount <= 0
     3917          || (! info->shared
     3918              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
     3919              && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
     3920              && h->root.type != bfd_link_hash_undefweak
     3921              && h->root.type != bfd_link_hash_undefined))
    25053922        {
    25063923          /* This case can occur if we saw a PLT reloc in an input
     
    25093926             a procedure linkage table, and we can just do a REL32
    25103927             reloc instead.  */
    2511           BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
    2512           return true;
     3928          h->plt.offset = (bfd_vma) -1;
     3929          h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
    25133930        }
    25143931
    2515       /* Make sure this symbol is output as a dynamic symbol.  */
    2516       if (h->dynindx == -1)
    2517         {
    2518           if (! bfd_elf32_link_record_dynamic_symbol (info, h))
    2519             return false;
    2520         }
    2521 
    2522       s = bfd_get_section_by_name (dynobj, ".plt");
    2523       BFD_ASSERT (s != NULL);
    2524 
    2525       /* If this is the first .plt entry, make room for the special
    2526          first entry.  */
    2527       if (s->_raw_size == 0)
    2528         s->_raw_size += PLT_ENTRY_SIZE;
    2529 
    2530       /* If this symbol is not defined in a regular file, and we are
    2531          not generating a shared library, then set the symbol to this
    2532          location in the .plt.  This is required to make function
    2533          pointers compare as equal between the normal executable and
    2534          the shared library.  */
    2535       if (! info->shared
    2536           && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
    2537         {
    2538           h->root.u.def.section = s;
    2539           h->root.u.def.value = s->_raw_size;
    2540         }
    2541 
    2542       h->plt.offset = s->_raw_size;
    2543 
    2544       /* Make room for this entry.  */
    2545       s->_raw_size += elf_sh_sizeof_plt (info);
    2546 
    2547       /* We also need to make an entry in the .got.plt section, which
    2548          will be placed in the .got section by the linker script.  */
    2549 
    2550       s = bfd_get_section_by_name (dynobj, ".got.plt");
    2551       BFD_ASSERT (s != NULL);
    2552       s->_raw_size += 4;
    2553 
    2554       /* We also need to make an entry in the .rela.plt section.  */
    2555 
    2556       s = bfd_get_section_by_name (dynobj, ".rela.plt");
    2557       BFD_ASSERT (s != NULL);
    2558       s->_raw_size += sizeof (Elf32_External_Rela);
    2559 
    2560       return true;
     3932      return TRUE;
    25613933    }
     3934  else
     3935    h->plt.offset = (bfd_vma) -1;
    25623936
    25633937  /* If this is a weak symbol, and there is a real definition, the
     
    25703944      h->root.u.def.section = h->weakdef->root.u.def.section;
    25713945      h->root.u.def.value = h->weakdef->root.u.def.value;
    2572       return true;
     3946      return TRUE;
    25733947    }
    25743948
     
    25813955     be handled correctly by relocate_section.  */
    25823956  if (info->shared)
    2583     return true;
     3957    return TRUE;
    25843958
    25853959  /* If there are no references to this symbol that do not use the
    25863960     GOT, we don't need to generate a copy reloc.  */
    25873961  if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
    2588     return true;
     3962    return TRUE;
     3963
     3964  /* If -z nocopyreloc was given, we won't generate them either.  */
     3965  if (info->nocopyreloc)
     3966    {
     3967      h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
     3968      return TRUE;
     3969    }
     3970
     3971  eh = (struct elf_sh_link_hash_entry *) h;
     3972  for (p = eh->dyn_relocs; p != NULL; p = p->next)
     3973    {
     3974      s = p->sec->output_section;
     3975      if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
     3976        break;
     3977    }
     3978
     3979  /* If we didn't find any dynamic relocs in sections which needs the
     3980     copy reloc, then we'll be keeping the dynamic relocs and avoiding
     3981     the copy reloc.  */
     3982  if (p == NULL)
     3983    {
     3984      h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
     3985      return TRUE;
     3986    }
    25893987
    25903988  /* We must allocate the symbol in our .dynbss section, which will
     
    25983996     same memory location for the variable.  */
    25993997
    2600   s = bfd_get_section_by_name (dynobj, ".dynbss");
     3998  htab = sh_elf_hash_table (info);
     3999  s = htab->sdynbss;
    26014000  BFD_ASSERT (s != NULL);
    26024001
     
    26094008      asection *srel;
    26104009
    2611       srel = bfd_get_section_by_name (dynobj, ".rela.bss");
     4010      srel = htab->srelbss;
    26124011      BFD_ASSERT (srel != NULL);
    26134012      srel->_raw_size += sizeof (Elf32_External_Rela);
     
    26224021
    26234022  /* Apply the required alignment.  */
    2624   s->_raw_size = BFD_ALIGN (s->_raw_size,
    2625                             (bfd_size_type) (1 << power_of_two));
     4023  s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
    26264024  if (power_of_two > bfd_get_section_alignment (dynobj, s))
    26274025    {
    26284026      if (! bfd_set_section_alignment (dynobj, s, power_of_two))
    2629         return false;
     4027        return FALSE;
    26304028    }
    26314029
     
    26374035  s->_raw_size += h->size;
    26384036
    2639   return true;
     4037  return TRUE;
    26404038}
    26414039
     4040/* This is the condition under which sh_elf_finish_dynamic_symbol
     4041   will be called from elflink.h.  If elflink.h doesn't call our
     4042   finish_dynamic_symbol routine, we'll need to do something about
     4043   initializing any .plt and .got entries in sh_elf_relocate_section.  */
     4044#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
     4045  ((DYN)                                                                \
     4046   && ((SHARED)                                                         \
     4047       || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)      \
     4048   && ((H)->dynindx != -1                                               \
     4049       || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
     4050
     4051/* Allocate space in .plt, .got and associated reloc sections for
     4052   dynamic relocs.  */
     4053
     4054static bfd_boolean
     4055allocate_dynrelocs (h, inf)
     4056     struct elf_link_hash_entry *h;
     4057     PTR inf;
     4058{
     4059  struct bfd_link_info *info;
     4060  struct elf_sh_link_hash_table *htab;
     4061  struct elf_sh_link_hash_entry *eh;
     4062  struct elf_sh_dyn_relocs *p;
     4063
     4064  if (h->root.type == bfd_link_hash_indirect)
     4065    return TRUE;
     4066
     4067  if (h->root.type == bfd_link_hash_warning)
     4068    /* When warning symbols are created, they **replace** the "real"
     4069       entry in the hash table, thus we never get to see the real
     4070       symbol in a hash traversal.  So look at it now.  */
     4071    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     4072
     4073  info = (struct bfd_link_info *) inf;
     4074  htab = sh_elf_hash_table (info);
     4075
     4076  eh = (struct elf_sh_link_hash_entry *) h;
     4077  if ((h->got.refcount > 0
     4078      || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
     4079      && eh->gotplt_refcount > 0)
     4080    {
     4081      /* The symbol has been forced local, or we have some direct got refs,
     4082         so treat all the gotplt refs as got refs. */
     4083      h->got.refcount += eh->gotplt_refcount;
     4084      if (h->plt.refcount >= eh->gotplt_refcount)
     4085        h->plt.refcount -= eh->gotplt_refcount;
     4086    }
     4087
     4088  if (htab->root.dynamic_sections_created
     4089      && h->plt.refcount > 0)
     4090    {
     4091      /* Make sure this symbol is output as a dynamic symbol.
     4092         Undefined weak syms won't yet be marked as dynamic.  */
     4093      if (h->dynindx == -1
     4094          && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
     4095        {
     4096          if (! bfd_elf32_link_record_dynamic_symbol (info, h))
     4097            return FALSE;
     4098        }
     4099
     4100      if (info->shared
     4101          || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
     4102        {
     4103          asection *s = htab->splt;
     4104
     4105          /* If this is the first .plt entry, make room for the special
     4106             first entry.  */
     4107          if (s->_raw_size == 0)
     4108            s->_raw_size += PLT_ENTRY_SIZE;
     4109
     4110          h->plt.offset = s->_raw_size;
     4111
     4112          /* If this symbol is not defined in a regular file, and we are
     4113             not generating a shared library, then set the symbol to this
     4114             location in the .plt.  This is required to make function
     4115             pointers compare as equal between the normal executable and
     4116             the shared library.  */
     4117          if (! info->shared
     4118              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
     4119            {
     4120              h->root.u.def.section = s;
     4121              h->root.u.def.value = h->plt.offset;
     4122            }
     4123
     4124          /* Make room for this entry.  */
     4125          s->_raw_size += PLT_ENTRY_SIZE;
     4126
     4127          /* We also need to make an entry in the .got.plt section, which
     4128             will be placed in the .got section by the linker script.  */
     4129          htab->sgotplt->_raw_size += 4;
     4130
     4131          /* We also need to make an entry in the .rel.plt section.  */
     4132          htab->srelplt->_raw_size += sizeof (Elf32_External_Rela);
     4133        }
     4134      else
     4135        {
     4136          h->plt.offset = (bfd_vma) -1;
     4137          h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
     4138        }
     4139    }
     4140  else
     4141    {
     4142      h->plt.offset = (bfd_vma) -1;
     4143      h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
     4144    }
     4145
     4146  if (h->got.refcount > 0)
     4147    {
     4148      asection *s;
     4149      bfd_boolean dyn;
     4150      int tls_type = sh_elf_hash_entry (h)->tls_type;
     4151
     4152      /* Make sure this symbol is output as a dynamic symbol.
     4153         Undefined weak syms won't yet be marked as dynamic.  */
     4154      if (h->dynindx == -1
     4155          && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
     4156        {
     4157          if (! bfd_elf32_link_record_dynamic_symbol (info, h))
     4158            return FALSE;
     4159        }
     4160
     4161      s = htab->sgot;
     4162      h->got.offset = s->_raw_size;
     4163      s->_raw_size += 4;
     4164      /* R_SH_TLS_GD needs 2 consecutive GOT slots.  */
     4165      if (tls_type == GOT_TLS_GD)
     4166        s->_raw_size += 4;
     4167      dyn = htab->root.dynamic_sections_created;
     4168      /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
     4169         R_SH_TLS_GD needs one if local symbol and two if global.  */
     4170      if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
     4171          || (tls_type == GOT_TLS_IE && dyn))
     4172        htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
     4173      else if (tls_type == GOT_TLS_GD)
     4174        htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rela);
     4175      else if (info->shared ||
     4176               WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
     4177        htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
     4178    }
     4179  else
     4180    h->got.offset = (bfd_vma) -1;
     4181
     4182#ifdef INCLUDE_SHMEDIA
     4183  if (eh->datalabel_got.refcount > 0)
     4184    {
     4185      asection *s;
     4186      bfd_boolean dyn;
     4187
     4188      /* Make sure this symbol is output as a dynamic symbol.
     4189         Undefined weak syms won't yet be marked as dynamic.  */
     4190      if (h->dynindx == -1
     4191          && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
     4192        {
     4193          if (! bfd_elf32_link_record_dynamic_symbol (info, h))
     4194            return FALSE;
     4195        }
     4196
     4197      s = htab->sgot;
     4198      eh->datalabel_got.offset = s->_raw_size;
     4199      s->_raw_size += 4;
     4200      dyn = htab->root.dynamic_sections_created;
     4201      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
     4202        htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
     4203    }
     4204  else
     4205    eh->datalabel_got.offset = (bfd_vma) -1;
     4206#endif
     4207
     4208  if (eh->dyn_relocs == NULL)
     4209    return TRUE;
     4210
     4211  /* In the shared -Bsymbolic case, discard space allocated for
     4212     dynamic pc-relative relocs against symbols which turn out to be
     4213     defined in regular objects.  For the normal shared case, discard
     4214     space for pc-relative relocs that have become local due to symbol
     4215     visibility changes.  */
     4216
     4217  if (info->shared)
     4218    {
     4219      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
     4220          && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
     4221              || info->symbolic))
     4222        {
     4223          struct elf_sh_dyn_relocs **pp;
     4224
     4225          for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
     4226            {
     4227              p->count -= p->pc_count;
     4228              p->pc_count = 0;
     4229              if (p->count == 0)
     4230                *pp = p->next;
     4231              else
     4232                pp = &p->next;
     4233            }
     4234        }
     4235    }
     4236  else
     4237    {
     4238      /* For the non-shared case, discard space for relocs against
     4239         symbols which turn out to need copy relocs or are not
     4240         dynamic.  */
     4241
     4242      if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
     4243          && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
     4244               && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
     4245              || (htab->root.dynamic_sections_created
     4246                  && (h->root.type == bfd_link_hash_undefweak
     4247                      || h->root.type == bfd_link_hash_undefined))))
     4248        {
     4249          /* Make sure this symbol is output as a dynamic symbol.
     4250             Undefined weak syms won't yet be marked as dynamic.  */
     4251          if (h->dynindx == -1
     4252              && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
     4253            {
     4254              if (! bfd_elf32_link_record_dynamic_symbol (info, h))
     4255                return FALSE;
     4256            }
     4257
     4258          /* If that succeeded, we know we'll be keeping all the
     4259             relocs.  */
     4260          if (h->dynindx != -1)
     4261            goto keep;
     4262        }
     4263
     4264      eh->dyn_relocs = NULL;
     4265
     4266    keep: ;
     4267    }
     4268
     4269  /* Finally, allocate space.  */
     4270  for (p = eh->dyn_relocs; p != NULL; p = p->next)
     4271    {
     4272      asection *sreloc = elf_section_data (p->sec)->sreloc;
     4273      sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
     4274    }
     4275
     4276  return TRUE;
     4277}
     4278
     4279/* Find any dynamic relocs that apply to read-only sections.  */
     4280
     4281static bfd_boolean
     4282readonly_dynrelocs (h, inf)
     4283     struct elf_link_hash_entry *h;
     4284     PTR inf;
     4285{
     4286  struct elf_sh_link_hash_entry *eh;
     4287  struct elf_sh_dyn_relocs *p;
     4288
     4289  if (h->root.type == bfd_link_hash_warning)
     4290    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     4291
     4292  eh = (struct elf_sh_link_hash_entry *) h;
     4293  for (p = eh->dyn_relocs; p != NULL; p = p->next)
     4294    {
     4295      asection *s = p->sec->output_section;
     4296
     4297      if (s != NULL && (s->flags & SEC_READONLY) != 0)
     4298        {
     4299          struct bfd_link_info *info = (struct bfd_link_info *) inf;
     4300
     4301          info->flags |= DF_TEXTREL;
     4302
     4303          /* Not an error, just cut short the traversal.  */
     4304          return FALSE;
     4305        }
     4306    }
     4307  return TRUE;
     4308}
     4309
    26424310/* Set the sizes of the dynamic sections.  */
    26434311
    2644 static boolean
     4312static bfd_boolean
    26454313sh_elf_size_dynamic_sections (output_bfd, info)
    2646      bfd *output_bfd;
     4314     bfd *output_bfd ATTRIBUTE_UNUSED;
    26474315     struct bfd_link_info *info;
    26484316{
     4317  struct elf_sh_link_hash_table *htab;
    26494318  bfd *dynobj;
    26504319  asection *s;
    2651   boolean plt;
    2652   boolean relocs;
    2653   boolean reltext;
    2654 
    2655   dynobj = elf_hash_table (info)->dynobj;
     4320  bfd_boolean relocs;
     4321  bfd *ibfd;
     4322
     4323  htab = sh_elf_hash_table (info);
     4324  dynobj = htab->root.dynobj;
    26564325  BFD_ASSERT (dynobj != NULL);
    26574326
    2658   if (elf_hash_table (info)->dynamic_sections_created)
     4327  if (htab->root.dynamic_sections_created)
    26594328    {
    26604329      /* Set the contents of the .interp section to the interpreter.  */
     
    26674336        }
    26684337    }
     4338
     4339  /* Set up .got offsets for local syms, and space for local dynamic
     4340     relocs.  */
     4341  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
     4342    {
     4343      bfd_signed_vma *local_got;
     4344      bfd_signed_vma *end_local_got;
     4345      char *local_tls_type;
     4346      bfd_size_type locsymcount;
     4347      Elf_Internal_Shdr *symtab_hdr;
     4348      asection *srel;
     4349
     4350      if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
     4351        continue;
     4352
     4353      for (s = ibfd->sections; s != NULL; s = s->next)
     4354        {
     4355          struct elf_sh_dyn_relocs *p;
     4356
     4357          for (p = ((struct elf_sh_dyn_relocs *)
     4358                    elf_section_data (s)->local_dynrel);
     4359               p != NULL;
     4360               p = p->next)
     4361            {
     4362              if (! bfd_is_abs_section (p->sec)
     4363                  && bfd_is_abs_section (p->sec->output_section))
     4364                {
     4365                  /* Input section has been discarded, either because
     4366                     it is a copy of a linkonce section or due to
     4367                     linker script /DISCARD/, so we'll be discarding
     4368                     the relocs too.  */
     4369                }
     4370              else if (p->count != 0)
     4371                {
     4372                  srel = elf_section_data (p->sec)->sreloc;
     4373                  srel->_raw_size += p->count * sizeof (Elf32_External_Rela);
     4374                  if ((p->sec->output_section->flags & SEC_READONLY) != 0)
     4375                    info->flags |= DF_TEXTREL;
     4376                }
     4377            }
     4378        }
     4379
     4380      local_got = elf_local_got_refcounts (ibfd);
     4381      if (!local_got)
     4382        continue;
     4383
     4384      symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
     4385      locsymcount = symtab_hdr->sh_info;
     4386#ifdef INCLUDE_SHMEDIA
     4387      /* Count datalabel local GOT.  */
     4388      locsymcount *= 2;
     4389#endif
     4390      end_local_got = local_got + locsymcount;
     4391      local_tls_type = sh_elf_local_got_tls_type (ibfd);
     4392      s = htab->sgot;
     4393      srel = htab->srelgot;
     4394      for (; local_got < end_local_got; ++local_got)
     4395        {
     4396          if (*local_got > 0)
     4397            {
     4398              *local_got = s->_raw_size;
     4399              s->_raw_size += 4;
     4400              if (*local_tls_type == GOT_TLS_GD)
     4401                s->_raw_size += 4;
     4402              if (info->shared)
     4403                srel->_raw_size += sizeof (Elf32_External_Rela);
     4404            }
     4405          else
     4406            *local_got = (bfd_vma) -1;
     4407          ++local_tls_type;
     4408        }
     4409    }
     4410
     4411  if (htab->tls_ldm_got.refcount > 0)
     4412    {
     4413      /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
     4414         relocs.  */
     4415      htab->tls_ldm_got.offset = htab->sgot->_raw_size;
     4416      htab->sgot->_raw_size += 8;
     4417      htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
     4418    }
    26694419  else
    2670     {
    2671       /* We may have created entries in the .rela.got section.
    2672          However, if we are not creating the dynamic sections, we will
    2673          not actually use these entries.  Reset the size of .rela.got,
    2674          which will cause it to get stripped from the output file
    2675          below.  */
    2676       s = bfd_get_section_by_name (dynobj, ".rela.got");
    2677       if (s != NULL)
    2678         s->_raw_size = 0;
    2679     }
    2680 
    2681   /* If this is a -Bsymbolic shared link, then we need to discard all
    2682      PC relative relocs against symbols defined in a regular object.
    2683      We allocated space for them in the check_relocs routine, but we
    2684      will not fill them in in the relocate_section routine.  */
    2685   if (info->shared && info->symbolic)
    2686     sh_elf_link_hash_traverse (sh_elf_hash_table (info),
    2687                                  sh_elf_discard_copies,
    2688                                  (PTR) NULL);
    2689 
    2690   /* The check_relocs and adjust_dynamic_symbol entry points have
    2691      determined the sizes of the various dynamic sections.  Allocate
    2692      memory for them.  */
    2693   plt = false;
    2694   relocs = false;
    2695   reltext = false;
     4420    htab->tls_ldm_got.offset = -1;
     4421
     4422  /* Allocate global sym .plt and .got entries, and space for global
     4423     sym dynamic relocs.  */
     4424  elf_link_hash_traverse (&htab->root, allocate_dynrelocs, (PTR) info);
     4425
     4426  /* We now have determined the sizes of the various dynamic sections.
     4427     Allocate memory for them.  */
     4428  relocs = FALSE;
    26964429  for (s = dynobj->sections; s != NULL; s = s->next)
    26974430    {
    2698       const char *name;
    2699       boolean strip;
    2700 
    27014431      if ((s->flags & SEC_LINKER_CREATED) == 0)
    27024432        continue;
    27034433
    2704       /* It's OK to base decisions on the section name, because none
    2705          of the dynobj section names depend upon the input files.  */
    2706       name = bfd_get_section_name (dynobj, s);
    2707 
    2708       strip = false;
    2709 
    2710       if (strcmp (name, ".plt") == 0)
     4434      if (s == htab->splt
     4435          || s == htab->sgot
     4436          || s == htab->sgotplt)
    27114437        {
    2712           if (s->_raw_size == 0)
    2713             {
    2714               /* Strip this section if we don't need it; see the
    2715                  comment below.  */
    2716               strip = true;
    2717             }
    2718           else
    2719             {
    2720               /* Remember whether there is a PLT.  */
    2721               plt = true;
    2722             }
     4438          /* Strip this section if we don't need it; see the
     4439             comment below.  */
    27234440        }
    2724       else if (strncmp (name, ".rela", 5) == 0)
     4441      else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
    27254442        {
    2726           if (s->_raw_size == 0)
    2727             {
    2728               /* If we don't need this section, strip it from the
    2729                  output file.  This is mostly to handle .rela.bss and
    2730                  .rela.plt.  We must create both sections in
    2731                  create_dynamic_sections, because they must be created
    2732                  before the linker maps input sections to output
    2733                  sections.  The linker does that before
    2734                  adjust_dynamic_symbol is called, and it is that
    2735                  function which decides whether anything needs to go
    2736                  into these sections.  */
    2737               strip = true;
    2738             }
    2739           else
    2740             {
    2741               asection *target;
    2742 
    2743               /* Remember whether there are any reloc sections other
    2744                  than .rela.plt.  */
    2745               if (strcmp (name, ".rela.plt") != 0)
    2746                 {
    2747                   const char *outname;
    2748 
    2749                   relocs = true;
    2750 
    2751                   /* If this relocation section applies to a read only
    2752                      section, then we probably need a DT_TEXTREL
    2753                      entry.  The entries in the .rela.plt section
    2754                      really apply to the .got section, which we
    2755                      created ourselves and so know is not readonly.  */
    2756                   outname = bfd_get_section_name (output_bfd,
    2757                                                   s->output_section);
    2758                   target = bfd_get_section_by_name (output_bfd, outname + 5);
    2759                   if (target != NULL
    2760                       && (target->flags & SEC_READONLY) != 0
    2761                       && (target->flags & SEC_ALLOC) != 0)
    2762                     reltext = true;
    2763                 }
    2764 
    2765               /* We use the reloc_count field as a counter if we need
    2766                  to copy relocs into the output file.  */
    2767               s->reloc_count = 0;
    2768             }
     4443          if (s->_raw_size != 0 && s != htab->srelplt)
     4444            relocs = TRUE;
     4445
     4446          /* We use the reloc_count field as a counter if we need
     4447             to copy relocs into the output file.  */
     4448          s->reloc_count = 0;
    27694449        }
    2770       else if (strncmp (name, ".got", 4) != 0)
     4450      else
    27714451        {
    27724452          /* It's not one of our sections, so don't allocate space.  */
     
    27744454        }
    27754455
    2776       if (strip)
     4456      if (s->_raw_size == 0)
    27774457        {
     4458          /* If we don't need this section, strip it from the
     4459             output file.  This is mostly to handle .rela.bss and
     4460             .rela.plt.  We must create both sections in
     4461             create_dynamic_sections, because they must be created
     4462             before the linker maps input sections to output
     4463             sections.  The linker does that before
     4464             adjust_dynamic_symbol is called, and it is that
     4465             function which decides whether anything needs to go
     4466             into these sections.  */
     4467
    27784468          _bfd_strip_section_from_output (info, s);
    27794469          continue;
    27804470        }
    27814471
    2782       /* Allocate memory for the section contents.  */
    2783       s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
    2784       if (s->contents == NULL && s->_raw_size != 0)
    2785         return false;
     4472      /* Allocate memory for the section contents.  We use bfd_zalloc
     4473         here in case unused entries are not reclaimed before the
     4474         section's contents are written out.  This should not happen,
     4475         but this way if it does, we get a R_SH_NONE reloc instead
     4476         of garbage.  */
     4477      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
     4478      if (s->contents == NULL)
     4479        return FALSE;
    27864480    }
    27874481
    2788   if (elf_hash_table (info)->dynamic_sections_created)
     4482  if (htab->root.dynamic_sections_created)
    27894483    {
    27904484      /* Add some entries to the .dynamic section.  We fill in the
     
    27934487         the .dynamic section.  The DT_DEBUG entry is filled in by the
    27944488         dynamic linker and used by the debugger.  */
     4489#define add_dynamic_entry(TAG, VAL) \
     4490  bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
     4491
    27954492      if (! info->shared)
    27964493        {
    2797           if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
    2798             return false;
     4494          if (! add_dynamic_entry (DT_DEBUG, 0))
     4495            return FALSE;
    27994496        }
    28004497
    2801       if (plt)
     4498      if (htab->splt->_raw_size != 0)
    28024499        {
    2803           if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)
    2804               || ! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
    2805               || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
    2806               || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
    2807             return false;
     4500          if (! add_dynamic_entry (DT_PLTGOT, 0)
     4501              || ! add_dynamic_entry (DT_PLTRELSZ, 0)
     4502              || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
     4503              || ! add_dynamic_entry (DT_JMPREL, 0))
     4504            return FALSE;
    28084505        }
    28094506
    28104507      if (relocs)
    28114508        {
    2812           if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
    2813               || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
    2814               || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
    2815                                                 sizeof (Elf32_External_Rela)))
    2816             return false;
    2817         }
    2818 
    2819       if (reltext)
    2820         {
    2821           if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
    2822             return false;
     4509          if (! add_dynamic_entry (DT_RELA, 0)
     4510              || ! add_dynamic_entry (DT_RELASZ, 0)
     4511              || ! add_dynamic_entry (DT_RELAENT,
     4512                                      sizeof (Elf32_External_Rela)))
     4513            return FALSE;
     4514
     4515          /* If any dynamic relocs apply to a read-only section,
     4516             then we need a DT_TEXTREL entry.  */
     4517          if ((info->flags & DF_TEXTREL) == 0)
     4518            elf_link_hash_traverse (&htab->root, readonly_dynrelocs,
     4519                                    (PTR) info);
     4520
     4521          if ((info->flags & DF_TEXTREL) != 0)
     4522            {
     4523              if (! add_dynamic_entry (DT_TEXTREL, 0))
     4524                return FALSE;
     4525            }
    28234526        }
    28244527    }
    2825 
    2826   return true;
     4528#undef add_dynamic_entry
     4529
     4530  return TRUE;
    28274531}
    28284532
    2829 /* This function is called via sh_elf_link_hash_traverse if we are
    2830    creating a shared object with -Bsymbolic.  It discards the space
    2831    allocated to copy PC relative relocs against symbols which are
    2832    defined in regular objects.  We allocated space for them in the
    2833    check_relocs routine, but we won't fill them in in the
    2834    relocate_section routine.  */
    2835 
    2836 static boolean
    2837 sh_elf_discard_copies (h, ignore)
    2838      struct elf_sh_link_hash_entry *h;
    2839      PTR ignore ATTRIBUTE_UNUSED;
    2840 {
    2841   struct elf_sh_pcrel_relocs_copied *s;
    2842 
    2843   /* We only discard relocs for symbols defined in a regular object.  */
    2844   if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
    2845     return true;
    2846 
    2847   for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
    2848     s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
    2849 
    2850   return true;
    2851 }
    2852 
    28534533
    28544534/* Relocate an SH ELF section.  */
    28554535
    2856 static boolean
     4536static bfd_boolean
    28574537sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
    28584538                         contents, relocs, local_syms, local_sections)
    2859      bfd *output_bfd ATTRIBUTE_UNUSED;
     4539     bfd *output_bfd;
    28604540     struct bfd_link_info *info;
    28614541     bfd *input_bfd;
     
    28664546     asection **local_sections;
    28674547{
     4548  struct elf_sh_link_hash_table *htab;
    28684549  Elf_Internal_Shdr *symtab_hdr;
    28694550  struct elf_link_hash_entry **sym_hashes;
     
    28724553  bfd_vma *local_got_offsets;
    28734554  asection *sgot;
     4555  asection *sgotplt;
    28744556  asection *splt;
    28754557  asection *sreloc;
    2876 
     4558  asection *srelgot;
     4559
     4560  htab = sh_elf_hash_table (info);
    28774561  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
    28784562  sym_hashes = elf_sym_hashes (input_bfd);
    2879   dynobj = elf_hash_table (info)->dynobj;
     4563  dynobj = htab->root.dynobj;
    28804564  local_got_offsets = elf_local_got_offsets (input_bfd);
    28814565
    2882   sgot = NULL;
    2883   splt = NULL;
     4566  sgot = htab->sgot;
     4567  sgotplt = htab->sgotplt;
     4568  splt = htab->splt;
    28844569  sreloc = NULL;
     4570  srelgot = NULL;
    28854571
    28864572  rel = relocs;
     
    28974583      bfd_vma addend = (bfd_vma) 0;
    28984584      bfd_reloc_status_type r;
     4585      int seen_stt_datalabel = 0;
     4586      bfd_vma off;
     4587      int tls_type;
    28994588
    29004589      r_symndx = ELF32_R_SYM (rel->r_info);
     
    29034592
    29044593      /* Many of the relocs are only used for relaxing, and are
    2905         handled entirely by the relaxation code.  */
     4594        handled entirely by the relaxation code.  */
    29064595      if (r_type > (int) R_SH_LAST_INVALID_RELOC
    29074596          && r_type < (int) R_SH_LOOP_START)
     
    29144603          || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
    29154604              && r_type <= (int) R_SH_LAST_INVALID_RELOC)
     4605          || (   r_type >= (int) R_SH_FIRST_INVALID_RELOC_3
     4606              && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)
     4607          || (   r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
     4608              && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)
     4609          || (   r_type >= (int) R_SH_FIRST_INVALID_RELOC_5
     4610              && r_type <= (int) R_SH_LAST_INVALID_RELOC_5)
    29164611          || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
    29174612              && r_type <= (int) R_SH_LAST_INVALID_RELOC_2))
    29184613        {
    29194614          bfd_set_error (bfd_error_bad_value);
    2920           return false;
     4615          return FALSE;
    29214616        }
    29224617
    29234618      howto = sh_elf_howto_table + r_type;
    29244619
    2925       /* This is a final link.  */
     4620      /* For relocs that aren't partial_inplace, we get the addend from
     4621         the relocation.  */
     4622      if (! howto->partial_inplace)
     4623        addend = rel->r_addend;
     4624
    29264625      h = NULL;
    29274626      sym = NULL;
     
    29344633                        + sec->output_offset
    29354634                        + sym->st_value);
    2936 
     4635          /* A local symbol never has STO_SH5_ISA32, so we don't need
     4636             datalabel processing here.  Make sure this does not change
     4637             without notice.  */
     4638          if ((sym->st_other & STO_SH5_ISA32) != 0)
     4639            ((*info->callbacks->reloc_dangerous)
     4640             (info,
     4641              _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
     4642              input_bfd, input_section, rel->r_offset));
    29374643          if (info->relocateable)
    29384644            {
     
    29434649              sym = local_syms + r_symndx;
    29444650              if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
    2945                 goto final_link_relocate;
     4651                {
     4652                  if (! howto->partial_inplace)
     4653                    {
     4654                      /* For relocations with the addend in the
     4655                         relocation, we need just to update the addend.
     4656                         All real relocs are of type partial_inplace; this
     4657                         code is mostly for completeness.  */
     4658                      rel->r_addend += sec->output_offset + sym->st_value;
     4659
     4660                      continue;
     4661                    }
     4662
     4663                  /* Relocs of type partial_inplace need to pick up the
     4664                     contents in the contents and add the offset resulting
     4665                     from the changed location of the section symbol.
     4666                     Using _bfd_final_link_relocate (e.g. goto
     4667                     final_link_relocate) here would be wrong, because
     4668                     relocations marked pc_relative would get the current
     4669                     location subtracted, and we must only do that at the
     4670                     final link.  */
     4671                  r = _bfd_relocate_contents (howto, input_bfd,
     4672                                              sec->output_offset
     4673                                              + sym->st_value,
     4674                                              contents + rel->r_offset);
     4675                  goto relocation_done;
     4676                }
    29464677
    29474678              continue;
     4679            }
     4680          else if (! howto->partial_inplace)
     4681            {
     4682              relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
     4683              addend = rel->r_addend;
     4684            }
     4685          else if ((sec->flags & SEC_MERGE)
     4686                   && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
     4687            {
     4688              asection *msec;
     4689
     4690              if (howto->rightshift || howto->src_mask != 0xffffffff)
     4691                {
     4692                  (*_bfd_error_handler)
     4693                    (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
     4694                     bfd_archive_filename (input_bfd),
     4695                     bfd_get_section_name (input_bfd, input_section),
     4696                     (long) rel->r_offset, howto->name);
     4697                  return FALSE;
     4698                }
     4699
     4700              addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
     4701              msec = sec;
     4702              addend =
     4703                _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
     4704                - relocation;
     4705              addend += msec->output_section->vma + msec->output_offset;
     4706              bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
     4707              addend = 0;
    29484708            }
    29494709        }
     
    29594719          while (h->root.type == bfd_link_hash_indirect
    29604720                 || h->root.type == bfd_link_hash_warning)
    2961             h = (struct elf_link_hash_entry *) h->root.u.i.link;
     4721            {
     4722#ifdef INCLUDE_SHMEDIA
     4723              /* If the reference passes a symbol marked with
     4724                 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
     4725                 doesn't count.  */
     4726              seen_stt_datalabel |= h->type == STT_DATALABEL;
     4727#endif
     4728              h = (struct elf_link_hash_entry *) h->root.u.i.link;
     4729            }
    29624730          if (h->root.type == bfd_link_hash_defined
    29634731              || h->root.type == bfd_link_hash_defweak)
    29644732            {
     4733              bfd_boolean dyn;
     4734
     4735              dyn = htab->root.dynamic_sections_created;
    29654736              sec = h->root.u.def.section;
    29664737              /* In these cases, we don't need the relocation value.
     
    29684739                 sec->output_section will be NULL.  */
    29694740              if (r_type == R_SH_GOTPC
    2970                   || (r_type == R_SH_PLT32
     4741                  || r_type == R_SH_GOTPC_LOW16
     4742                  || r_type == R_SH_GOTPC_MEDLOW16
     4743                  || r_type == R_SH_GOTPC_MEDHI16
     4744                  || r_type == R_SH_GOTPC_HI16
     4745                  || ((r_type == R_SH_PLT32
     4746                       || r_type == R_SH_PLT_LOW16
     4747                       || r_type == R_SH_PLT_MEDLOW16
     4748                       || r_type == R_SH_PLT_MEDHI16
     4749                       || r_type == R_SH_PLT_HI16)
    29714750                      && h->plt.offset != (bfd_vma) -1)
    2972                   || (r_type == R_SH_GOT32
    2973                       && elf_hash_table (info)->dynamic_sections_created
     4751                  || ((r_type == R_SH_GOT32
     4752                       || r_type == R_SH_GOT_LOW16
     4753                       || r_type == R_SH_GOT_MEDLOW16
     4754                       || r_type == R_SH_GOT_MEDHI16
     4755                       || r_type == R_SH_GOT_HI16)
     4756                      && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
    29744757                      && (! info->shared
    29754758                          || (! info->symbolic && h->dynindx != -1)
     
    29864769                              & ELF_LINK_HASH_DEF_REGULAR) == 0)
    29874770                      && ((r_type == R_SH_DIR32
    2988                            && !(ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
    2989                                 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN))
     4771                           && (h->elf_link_hash_flags
     4772                               & ELF_LINK_FORCED_LOCAL) == 0)
    29904773                          || r_type == R_SH_REL32)
    29914774                      && ((input_section->flags & SEC_ALLOC) != 0
     
    29944777                             in shared libraries.  We can't do anything
    29954778                             with them here.  */
    2996                           || (input_section->flags & SEC_DEBUGGING) != 0)))
     4779                          || ((input_section->flags & SEC_DEBUGGING) != 0
     4780                              && (h->elf_link_hash_flags
     4781                                  & ELF_LINK_HASH_DEF_DYNAMIC) != 0)))
     4782                  /* Dynamic relocs are not propagated for SEC_DEBUGGING
     4783                     sections because such sections are not SEC_ALLOC and
     4784                     thus ld.so will not process them.  */
     4785                  || (sec->output_section == NULL
     4786                      && ((input_section->flags & SEC_DEBUGGING) != 0
     4787                          && (h->elf_link_hash_flags
     4788                              & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
     4789                  || (sec->output_section == NULL
     4790                      && (sh_elf_hash_entry (h)->tls_type == GOT_TLS_IE
     4791                          || sh_elf_hash_entry (h)->tls_type == GOT_TLS_GD)))
    29974792                relocation = 0;
    29984793              else if (sec->output_section == NULL)
    29994794                {
    30004795                  (*_bfd_error_handler)
    3001                     (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
    3002                      bfd_get_filename (input_bfd), h->root.root.string,
     4796                    (_("%s: unresolvable relocation against symbol `%s' from %s section"),
     4797                     bfd_archive_filename (input_bfd), h->root.root.string,
    30034798                     bfd_get_section_name (input_bfd, input_section));
    3004                   relocation = 0;
     4799                  return FALSE;
    30054800                }
    30064801              else
    3007                 relocation = (h->root.u.def.value
     4802                relocation = ((h->root.u.def.value
    30084803                              + sec->output_section->vma
    3009                               + sec->output_offset);
     4804                              + sec->output_offset)
     4805                              /* A STO_SH5_ISA32 causes a "bitor 1" to the
     4806                                 symbol value, unless we've seen
     4807                                 STT_DATALABEL on the way to it.  */
     4808                              | ((h->other & STO_SH5_ISA32) != 0
     4809                                 && ! seen_stt_datalabel));
    30104810            }
    30114811          else if (h->root.type == bfd_link_hash_undefweak)
    30124812            relocation = 0;
    3013           else if (info->shared && !info->symbolic && !info->no_undefined)
     4813          else if (info->shared
     4814                   && ! info->no_undefined
     4815                   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
    30144816            relocation = 0;
    30154817          else
     
    30174819              if (! ((*info->callbacks->undefined_symbol)
    30184820                     (info, h->root.root.string, input_bfd,
    3019                       input_section, rel->r_offset, true)))
    3020                 return false;
     4821                      input_section, rel->r_offset,
     4822                      (!info->shared || info->no_undefined
     4823                       || ELF_ST_VISIBILITY (h->other)))))
     4824                return FALSE;
    30214825              relocation = 0;
    30224826            }
     
    30344838
    30354839        case R_SH_IND12W:
     4840          goto final_link_relocate;
     4841
    30364842        case R_SH_DIR8WPN:
    30374843        case R_SH_DIR8WPZ:
    30384844        case R_SH_DIR8WPL:
    3039           /* These should normally be handled by the assembler, but at
    3040              least IND12W is generated by ourselves, so we must deal
    3041              with it.  */
    3042           relocation -= 4;
    3043           goto final_link_relocate;
     4845          /* If the reloc is against the start of this section, then
     4846             the assembler has already taken care of it and the reloc
     4847             is here only to assist in relaxing.  If the reloc is not
     4848             against the start of this section, then it's against an
     4849             external symbol and we must deal with it ourselves.  */
     4850          if (input_section->output_section->vma + input_section->output_offset
     4851              != relocation)
     4852            {
     4853              int disp = (relocation
     4854                          - input_section->output_section->vma
     4855                          - input_section->output_offset
     4856                          - rel->r_offset);
     4857              int mask = 0;
     4858              switch (r_type)
     4859                {
     4860                case R_SH_DIR8WPN:
     4861                case R_SH_DIR8WPZ: mask = 1; break;
     4862                case R_SH_DIR8WPL: mask = 3; break;
     4863                default: mask = 0; break;
     4864                }
     4865              if (disp & mask)
     4866                {
     4867                  ((*_bfd_error_handler)
     4868                   (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
     4869                    bfd_archive_filename (input_section->owner),
     4870                    (unsigned long) rel->r_offset));
     4871                  bfd_set_error (bfd_error_bad_value);
     4872                  return FALSE;
     4873                }
     4874              relocation -= 4;
     4875              goto final_link_relocate;
     4876            }
     4877          r = bfd_reloc_ok;
     4878          break;
    30444879
    30454880        default:
     4881#ifdef INCLUDE_SHMEDIA
     4882          if (shmedia_prepare_reloc (info, input_bfd, input_section,
     4883                                     contents, rel, &relocation))
     4884            goto final_link_relocate;
     4885#endif
    30464886          bfd_set_error (bfd_error_bad_value);
    3047           return false;
     4887          return FALSE;
    30484888
    30494889        case R_SH_DIR32:
    30504890        case R_SH_REL32:
    30514891          if (info->shared
     4892              && r_symndx != 0
    30524893              && (input_section->flags & SEC_ALLOC) != 0
    30534894              && (r_type != R_SH_REL32
     
    30594900            {
    30604901              Elf_Internal_Rela outrel;
    3061               boolean skip, relocate;
     4902              bfd_byte *loc;
     4903              bfd_boolean skip, relocate;
    30624904
    30634905              /* When generating a shared object, these relocations
     
    30744916                           elf_section_data (input_section)->rel_hdr.sh_name));
    30754917                  if (name == NULL)
    3076                     return false;
     4918                    return FALSE;
    30774919
    30784920                  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
     
    30854927                }
    30864928
    3087               skip = false;
    3088 
    3089               if (elf_section_data (input_section)->stab_info == NULL)
    3090                 outrel.r_offset = rel->r_offset;
    3091               else
    3092                 {
    3093                   bfd_vma off;
    3094 
    3095                   off = (_bfd_stab_section_offset
    3096                          (output_bfd, &elf_hash_table (info)->stab_info,
    3097                           input_section,
    3098                           &elf_section_data (input_section)->stab_info,
    3099                           rel->r_offset));
    3100                   if (off == (bfd_vma) -1)
    3101                     skip = true;
    3102                   outrel.r_offset = off;
    3103                 }
    3104 
     4929              skip = FALSE;
     4930              relocate = FALSE;
     4931
     4932              outrel.r_offset =
     4933                _bfd_elf_section_offset (output_bfd, info, input_section,
     4934                                         rel->r_offset);
     4935              if (outrel.r_offset == (bfd_vma) -1)
     4936                skip = TRUE;
     4937              else if (outrel.r_offset == (bfd_vma) -2)
     4938                skip = TRUE, relocate = TRUE;
    31054939              outrel.r_offset += (input_section->output_section->vma
    31064940                                  + input_section->output_offset);
    31074941
    31084942              if (skip)
    3109                 {
    3110                   memset (&outrel, 0, sizeof outrel);
    3111                   relocate = false;
    3112                 }
     4943                memset (&outrel, 0, sizeof outrel);
    31134944              else if (r_type == R_SH_REL32)
    31144945                {
    31154946                  BFD_ASSERT (h != NULL && h->dynindx != -1);
    3116                   relocate = false;
    31174947                  outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32);
    3118                   outrel.r_addend = rel->r_addend;
     4948                  outrel.r_addend
     4949                    = bfd_get_32 (input_bfd, contents + rel->r_offset);
    31194950                }
    31204951              else
     
    31274958                              & ELF_LINK_HASH_DEF_REGULAR) != 0))
    31284959                    {
    3129                       relocate = true;
     4960                      relocate = TRUE;
    31304961                      outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
    3131                       outrel.r_addend = relocation + rel->r_addend;
     4962                      outrel.r_addend
     4963                        = relocation + bfd_get_32 (input_bfd,
     4964                                                   contents + rel->r_offset);
    31324965                    }
    31334966                  else
    31344967                    {
    31354968                      BFD_ASSERT (h->dynindx != -1);
    3136                       relocate = false;
    31374969                      outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32);
    3138                       outrel.r_addend = relocation + rel->r_addend;
     4970                      outrel.r_addend
     4971                        = relocation + bfd_get_32 (input_bfd,
     4972                                                   contents + rel->r_offset);
    31394973                    }
    31404974                }
    31414975
    3142               bfd_elf32_swap_reloca_out (output_bfd, &outrel,
    3143                                          (((Elf32_External_Rela *)
    3144                                            sreloc->contents)
    3145                                           + sreloc->reloc_count));
    3146               ++sreloc->reloc_count;
     4976              loc = sreloc->contents;
     4977              loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
     4978              bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
    31474979
    31484980              /* If this reloc is against an external symbol, we do
     
    31534985                continue;
    31544986            }
    3155           else if (r_type == R_SH_DIR32)
    3156             addend = rel->r_addend;
    31574987          goto final_link_relocate;
    31584988
     4989        case R_SH_GOTPLT32:
     4990#ifdef INCLUDE_SHMEDIA
     4991        case R_SH_GOTPLT_LOW16:
     4992        case R_SH_GOTPLT_MEDLOW16:
     4993        case R_SH_GOTPLT_MEDHI16:
     4994        case R_SH_GOTPLT_HI16:
     4995        case R_SH_GOTPLT10BY4:
     4996        case R_SH_GOTPLT10BY8:
     4997#endif
     4998          /* Relocation is to the entry for this symbol in the
     4999             procedure linkage table.  */
     5000
     5001          if (h == NULL
     5002              || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
     5003              || ! info->shared
     5004              || info->symbolic
     5005              || h->dynindx == -1
     5006              || h->plt.offset == (bfd_vma) -1
     5007              || h->got.offset != (bfd_vma) -1)
     5008            goto force_got;
     5009
     5010          /* Relocation is to the entry for this symbol in the global
     5011             offset table extension for the procedure linkage table.  */
     5012
     5013          BFD_ASSERT (sgotplt != NULL);
     5014          relocation = (sgotplt->output_offset
     5015                        + ((h->plt.offset / elf_sh_sizeof_plt (info)
     5016                            - 1 + 3) * 4));
     5017
     5018#ifdef GOT_BIAS
     5019          relocation -= GOT_BIAS;
     5020#endif
     5021
     5022          goto final_link_relocate;
     5023
     5024        force_got:
    31595025        case R_SH_GOT32:
     5026#ifdef INCLUDE_SHMEDIA
     5027        case R_SH_GOT_LOW16:
     5028        case R_SH_GOT_MEDLOW16:
     5029        case R_SH_GOT_MEDHI16:
     5030        case R_SH_GOT_HI16:
     5031        case R_SH_GOT10BY4:
     5032        case R_SH_GOT10BY8:
     5033#endif
    31605034          /* Relocation is to the entry for this symbol in the global
    31615035             offset table.  */
    3162           if (sgot == NULL)
    3163             {
    3164               sgot = bfd_get_section_by_name (dynobj, ".got");
    3165               BFD_ASSERT (sgot != NULL);
    3166             }
     5036
     5037          BFD_ASSERT (sgot != NULL);
    31675038
    31685039          if (h != NULL)
    31695040            {
    3170               bfd_vma off;
     5041              bfd_boolean dyn;
    31715042
    31725043              off = h->got.offset;
     5044#ifdef INCLUDE_SHMEDIA
     5045              if (seen_stt_datalabel)
     5046                {
     5047                  struct elf_sh_link_hash_entry *hsh;
     5048
     5049                  hsh = (struct elf_sh_link_hash_entry *)h;
     5050                  off = hsh->datalabel_got.offset;
     5051                }
     5052#endif
    31735053              BFD_ASSERT (off != (bfd_vma) -1);
    31745054
    3175               if (! elf_hash_table (info)->dynamic_sections_created
     5055              dyn = htab->root.dynamic_sections_created;
     5056              if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
    31765057                  || (info->shared
    31775058                      && (info->symbolic || h->dynindx == -1
    3178                           || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
    3179                           || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
     5059                          || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
    31805060                      && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
    31815061                {
     
    31985078                      bfd_put_32 (output_bfd, relocation,
    31995079                                  sgot->contents + off);
    3200                       h->got.offset |= 1;
     5080#ifdef INCLUDE_SHMEDIA
     5081                      if (seen_stt_datalabel)
     5082                        {
     5083                          struct elf_sh_link_hash_entry *hsh;
     5084
     5085                          hsh = (struct elf_sh_link_hash_entry *)h;
     5086                          hsh->datalabel_got.offset |= 1;
     5087                        }
     5088                      else
     5089#endif
     5090                        h->got.offset |= 1;
    32015091                    }
    32025092                }
     
    32065096          else
    32075097            {
    3208               bfd_vma off;
    3209 
     5098#ifdef INCLUDE_SHMEDIA
     5099              if (rel->r_addend)
     5100                {
     5101                  BFD_ASSERT (local_got_offsets != NULL
     5102                              && (local_got_offsets[symtab_hdr->sh_info
     5103                                                    + r_symndx]
     5104                                  != (bfd_vma) -1));
     5105
     5106                  off = local_got_offsets[symtab_hdr->sh_info
     5107                                          + r_symndx];
     5108                }
     5109              else
     5110                {
     5111#endif
    32105112              BFD_ASSERT (local_got_offsets != NULL
    32115113                          && local_got_offsets[r_symndx] != (bfd_vma) -1);
    32125114
    32135115              off = local_got_offsets[r_symndx];
     5116#ifdef INCLUDE_SHMEDIA
     5117                }
     5118#endif
    32145119
    32155120              /* The offset must always be a multiple of 4.  We use
     
    32245129                  if (info->shared)
    32255130                    {
    3226                       asection *srelgot;
    32275131                      Elf_Internal_Rela outrel;
    3228 
    3229                       srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
    3230                       BFD_ASSERT (srelgot != NULL);
     5132                      bfd_byte *loc;
     5133
     5134                      if (srelgot == NULL)
     5135                        {
     5136                          srelgot = bfd_get_section_by_name (dynobj,
     5137                                                             ".rela.got");
     5138                          BFD_ASSERT (srelgot != NULL);
     5139                        }
    32315140
    32325141                      outrel.r_offset = (sgot->output_section->vma
     
    32355144                      outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
    32365145                      outrel.r_addend = relocation;
    3237                       bfd_elf32_swap_reloca_out (output_bfd, &outrel,
    3238                                                 (((Elf32_External_Rela *)
    3239                                                   srelgot->contents)
    3240                                                  + srelgot->reloc_count));
    3241                       ++srelgot->reloc_count;
     5146                      loc = srelgot->contents;
     5147                      loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
     5148                      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
    32425149                    }
    32435150
    3244                   local_got_offsets[r_symndx] |= 1;
     5151#ifdef INCLUDE_SHMEDIA
     5152                  if (rel->r_addend)
     5153                    local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
     5154                  else
     5155#endif
     5156                    local_got_offsets[r_symndx] |= 1;
    32455157                }
    32465158
     
    32485160            }
    32495161
     5162#ifdef GOT_BIAS
     5163          relocation -= GOT_BIAS;
     5164#endif
     5165
    32505166          goto final_link_relocate;
    32515167
    32525168        case R_SH_GOTOFF:
     5169#ifdef INCLUDE_SHMEDIA
     5170        case R_SH_GOTOFF_LOW16:
     5171        case R_SH_GOTOFF_MEDLOW16:
     5172        case R_SH_GOTOFF_MEDHI16:
     5173        case R_SH_GOTOFF_HI16:
     5174#endif
    32535175          /* Relocation is relative to the start of the global offset
    32545176             table.  */
    32555177
    3256           if (sgot == NULL)
    3257             {
    3258               sgot = bfd_get_section_by_name (dynobj, ".got");
    3259               BFD_ASSERT (sgot != NULL);
    3260             }
     5178          BFD_ASSERT (sgot != NULL);
    32615179
    32625180          /* Note that sgot->output_offset is not involved in this
     
    32675185          relocation -= sgot->output_section->vma;
    32685186
     5187#ifdef GOT_BIAS
     5188          relocation -= GOT_BIAS;
     5189#endif
     5190
     5191          addend = rel->r_addend;
     5192
    32695193          goto final_link_relocate;
    32705194
    32715195        case R_SH_GOTPC:
     5196#ifdef INCLUDE_SHMEDIA
     5197        case R_SH_GOTPC_LOW16:
     5198        case R_SH_GOTPC_MEDLOW16:
     5199        case R_SH_GOTPC_MEDHI16:
     5200        case R_SH_GOTPC_HI16:
     5201#endif
    32725202          /* Use global offset table as symbol value.  */
    32735203
    3274           if (sgot == NULL)
    3275             {
    3276               sgot = bfd_get_section_by_name (dynobj, ".got");
    3277               BFD_ASSERT (sgot != NULL);
    3278             }
    3279 
     5204          BFD_ASSERT (sgot != NULL);
    32805205          relocation = sgot->output_section->vma;
    32815206
     5207#ifdef GOT_BIAS
     5208          relocation += GOT_BIAS;
     5209#endif
     5210
     5211          addend = rel->r_addend;
     5212
    32825213          goto final_link_relocate;
    32835214
    32845215        case R_SH_PLT32:
     5216#ifdef INCLUDE_SHMEDIA
     5217        case R_SH_PLT_LOW16:
     5218        case R_SH_PLT_MEDLOW16:
     5219        case R_SH_PLT_MEDHI16:
     5220        case R_SH_PLT_HI16:
     5221#endif
    32855222          /* Relocation is to the entry for this symbol in the
    32865223             procedure linkage table.  */
     
    32915228            goto final_link_relocate;
    32925229
    3293           if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
    3294               || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
     5230          if (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
    32955231            goto final_link_relocate;
    32965232
     
    33035239            }
    33045240
    3305           if (splt == NULL)
    3306             {
    3307               splt = bfd_get_section_by_name (dynobj, ".plt");
    3308               BFD_ASSERT (splt != NULL);
    3309             }
    3310 
     5241          BFD_ASSERT (splt != NULL);
    33115242          relocation = (splt->output_section->vma
    33125243                        + splt->output_offset
    33135244                        + h->plt.offset);
     5245
     5246#ifdef INCLUDE_SHMEDIA
     5247          relocation++;
     5248#endif
     5249
     5250          addend = rel->r_addend;
    33145251
    33155252          goto final_link_relocate;
     
    33325269            break;
    33335270          }
     5271
     5272        case R_SH_TLS_GD_32:
     5273        case R_SH_TLS_IE_32:
     5274          r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
     5275          tls_type = GOT_UNKNOWN;
     5276          if (h == NULL && local_got_offsets)
     5277            tls_type = sh_elf_local_got_tls_type (input_bfd) [r_symndx];
     5278          else if (h != NULL)
     5279            {
     5280              tls_type = sh_elf_hash_entry (h)->tls_type;
     5281              if (! info->shared
     5282                  && (h->dynindx == -1
     5283                      || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
     5284                r_type = R_SH_TLS_LE_32;
     5285            }
     5286
     5287          if (r_type == R_SH_TLS_GD_32 && tls_type == GOT_TLS_IE)
     5288            r_type = R_SH_TLS_IE_32;
     5289
     5290          if (r_type == R_SH_TLS_LE_32)
     5291            {
     5292              bfd_vma offset;
     5293              unsigned short insn;
     5294
     5295              if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
     5296                {
     5297                  /* GD->LE transition:
     5298                       mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
     5299                       jsr @r1; add r12,r4; bra 3f; nop; .align 2;
     5300                       1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
     5301                     We change it into:
     5302                       mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
     5303                       nop; nop; ...
     5304                       1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:.  */
     5305
     5306                  offset = rel->r_offset;
     5307                  BFD_ASSERT (offset >= 16);
     5308                  /* Size of GD instructions is 16 or 18.  */
     5309                  offset -= 16;
     5310                  insn = bfd_get_16 (input_bfd, contents + offset + 0);
     5311                  if ((insn & 0xff00) == 0xc700)
     5312                    {
     5313                      BFD_ASSERT (offset >= 2);
     5314                      offset -= 2;
     5315                      insn = bfd_get_16 (input_bfd, contents + offset + 0);
     5316                    }
     5317
     5318                  BFD_ASSERT ((insn & 0xff00) == 0xd400);
     5319                  insn = bfd_get_16 (input_bfd, contents + offset + 2);
     5320                  BFD_ASSERT ((insn & 0xff00) == 0xc700);
     5321                  insn = bfd_get_16 (input_bfd, contents + offset + 4);
     5322                  BFD_ASSERT ((insn & 0xff00) == 0xd100);
     5323                  insn = bfd_get_16 (input_bfd, contents + offset + 6);
     5324                  BFD_ASSERT (insn == 0x310c);
     5325                  insn = bfd_get_16 (input_bfd, contents + offset + 8);
     5326                  BFD_ASSERT (insn == 0x410b);
     5327                  insn = bfd_get_16 (input_bfd, contents + offset + 10);
     5328                  BFD_ASSERT (insn == 0x34cc);
     5329
     5330                  bfd_put_16 (output_bfd, 0x0012, contents + offset + 2);
     5331                  bfd_put_16 (output_bfd, 0x304c, contents + offset + 4);
     5332                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
     5333                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
     5334                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
     5335                }
     5336              else
     5337                {
     5338                  int index;
     5339
     5340                  /* IE->LE transition:
     5341                     mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
     5342                     bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
     5343                     We change it into:
     5344                     mov.l .Ln,rM; stc gbr,rN; nop; ...;
     5345                     1: x@TPOFF; 2:.  */
     5346
     5347                  offset = rel->r_offset;
     5348                  BFD_ASSERT (offset >= 16);
     5349                  /* Size of IE instructions is 10 or 12.  */
     5350                  offset -= 10;
     5351                  insn = bfd_get_16 (input_bfd, contents + offset + 0);
     5352                  if ((insn & 0xf0ff) == 0x0012)
     5353                    {
     5354                      BFD_ASSERT (offset >= 2);
     5355                      offset -= 2;
     5356                      insn = bfd_get_16 (input_bfd, contents + offset + 0);
     5357                    }
     5358
     5359                  BFD_ASSERT ((insn & 0xff00) == 0xd000);
     5360                  index = insn & 0x00ff;
     5361                  insn = bfd_get_16 (input_bfd, contents + offset + 2);
     5362                  BFD_ASSERT ((insn & 0xf0ff) == 0x0012);
     5363                  insn = bfd_get_16 (input_bfd, contents + offset + 4);
     5364                  BFD_ASSERT ((insn & 0xf0ff) == 0x00ce);
     5365                  insn = 0xd000 | (insn & 0x0f00) | index;
     5366                  bfd_put_16 (output_bfd, insn, contents + offset + 0);
     5367                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
     5368                }
     5369
     5370              bfd_put_32 (output_bfd, tpoff (info, relocation),
     5371                          contents + rel->r_offset);
     5372              continue;
     5373            }
     5374
     5375          sgot = htab->sgot;
     5376          if (sgot == NULL)
     5377            abort ();
     5378
     5379          if (h != NULL)
     5380            off = h->got.offset;
     5381          else
     5382            {
     5383              if (local_got_offsets == NULL)
     5384                abort ();
     5385
     5386              off = local_got_offsets[r_symndx];
     5387            }
     5388
     5389          /* Relocate R_SH_TLS_IE_32 directly when statically linking.  */
     5390          if (r_type == R_SH_TLS_IE_32
     5391              && ! htab->root.dynamic_sections_created)
     5392            {
     5393              off &= ~1;
     5394              bfd_put_32 (output_bfd, tpoff (info, relocation),
     5395                          sgot->contents + off);
     5396              bfd_put_32 (output_bfd, sgot->output_offset + off,
     5397                          contents + rel->r_offset);
     5398              continue;
     5399            }
     5400
     5401          if ((off & 1) != 0)
     5402            off &= ~1;
     5403          else
     5404            {
     5405              Elf_Internal_Rela outrel;
     5406              bfd_byte *loc;
     5407              int dr_type, indx;
     5408
     5409              if (srelgot == NULL)
     5410                {
     5411                  srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
     5412                  BFD_ASSERT (srelgot != NULL);
     5413                }
     5414
     5415              outrel.r_offset = (sgot->output_section->vma
     5416                                 + sgot->output_offset + off);
     5417
     5418              if (h == NULL || h->dynindx == -1)
     5419                indx = 0;
     5420              else
     5421                indx = h->dynindx;
     5422
     5423              dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
     5424                         R_SH_TLS_TPOFF32);
     5425              if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
     5426                outrel.r_addend = relocation - dtpoff_base (info);
     5427              else
     5428                outrel.r_addend = 0;
     5429              outrel.r_info = ELF32_R_INFO (indx, dr_type);
     5430              loc = srelgot->contents;
     5431              loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
     5432              bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
     5433
     5434              if (r_type == R_SH_TLS_GD_32)
     5435                {
     5436                  if (indx == 0)
     5437                    {
     5438                      bfd_put_32 (output_bfd,
     5439                                  relocation - dtpoff_base (info),
     5440                                  sgot->contents + off + 4);
     5441                    }
     5442                  else
     5443                    {
     5444                      outrel.r_info = ELF32_R_INFO (indx,
     5445                                                    R_SH_TLS_DTPOFF32);
     5446                      outrel.r_offset += 4;
     5447                      outrel.r_addend = 0;
     5448                      srelgot->reloc_count++;
     5449                      loc += sizeof (Elf32_External_Rela);
     5450                      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
     5451                    }
     5452                }
     5453
     5454              if (h != NULL)
     5455                h->got.offset |= 1;
     5456              else
     5457                local_got_offsets[r_symndx] |= 1;
     5458            }
     5459
     5460          if (off >= (bfd_vma) -2)
     5461            abort ();
     5462
     5463          if (r_type == (int) ELF32_R_TYPE (rel->r_info))
     5464            relocation = sgot->output_offset + off;
     5465          else
     5466            {
     5467              bfd_vma offset;
     5468              unsigned short insn;
     5469
     5470              /* GD->IE transition:
     5471                   mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
     5472                   jsr @r1; add r12,r4; bra 3f; nop; .align 2;
     5473                   1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
     5474                 We change it into:
     5475                   mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
     5476                   nop; nop; bra 3f; nop; .align 2;
     5477                   1: .long x@TPOFF; 2:...; 3:.  */
     5478
     5479              offset = rel->r_offset;
     5480              BFD_ASSERT (offset >= 16);
     5481              /* Size of GD instructions is 16 or 18.  */
     5482              offset -= 16;
     5483              insn = bfd_get_16 (input_bfd, contents + offset + 0);
     5484              if ((insn & 0xff00) == 0xc700)
     5485                {
     5486                  BFD_ASSERT (offset >= 2);
     5487                  offset -= 2;
     5488                  insn = bfd_get_16 (input_bfd, contents + offset + 0);
     5489                }
     5490
     5491              BFD_ASSERT ((insn & 0xff00) == 0xd400);
     5492
     5493              /* Replace mov.l 1f,R4 with mov.l 1f,r0.  */
     5494              bfd_put_16 (output_bfd, insn & 0xf0ff, contents + offset);
     5495
     5496              insn = bfd_get_16 (input_bfd, contents + offset + 2);
     5497              BFD_ASSERT ((insn & 0xff00) == 0xc700);
     5498              insn = bfd_get_16 (input_bfd, contents + offset + 4);
     5499              BFD_ASSERT ((insn & 0xff00) == 0xd100);
     5500              insn = bfd_get_16 (input_bfd, contents + offset + 6);
     5501              BFD_ASSERT (insn == 0x310c);
     5502              insn = bfd_get_16 (input_bfd, contents + offset + 8);
     5503              BFD_ASSERT (insn == 0x410b);
     5504              insn = bfd_get_16 (input_bfd, contents + offset + 10);
     5505              BFD_ASSERT (insn == 0x34cc);
     5506
     5507              bfd_put_16 (output_bfd, 0x0412, contents + offset + 2);
     5508              bfd_put_16 (output_bfd, 0x00ce, contents + offset + 4);
     5509              bfd_put_16 (output_bfd, 0x304c, contents + offset + 6);
     5510              bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
     5511              bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
     5512
     5513              bfd_put_32 (output_bfd, sgot->output_offset + off,
     5514                          contents + rel->r_offset);
     5515
     5516              continue;
     5517          }
     5518
     5519          addend = rel->r_addend;
     5520
     5521          goto final_link_relocate;
     5522
     5523        case R_SH_TLS_LD_32:
     5524          if (! info->shared)
     5525            {
     5526              bfd_vma offset;
     5527              unsigned short insn;
     5528
     5529              /* LD->LE transition:
     5530                   mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
     5531                   jsr @r1; add r12,r4; bra 3f; nop; .align 2;
     5532                   1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
     5533                 We change it into:
     5534                   stc gbr,r0; nop; nop; nop;
     5535                   nop; nop; bra 3f; ...; 3:.  */
     5536
     5537              offset = rel->r_offset;
     5538              BFD_ASSERT (offset >= 16);
     5539              /* Size of LD instructions is 16 or 18.  */
     5540              offset -= 16;
     5541              insn = bfd_get_16 (input_bfd, contents + offset + 0);
     5542              if ((insn & 0xff00) == 0xc700)
     5543                {
     5544                  BFD_ASSERT (offset >= 2);
     5545                  offset -= 2;
     5546                  insn = bfd_get_16 (input_bfd, contents + offset + 0);
     5547                }
     5548
     5549              BFD_ASSERT ((insn & 0xff00) == 0xd400);
     5550              insn = bfd_get_16 (input_bfd, contents + offset + 2);
     5551              BFD_ASSERT ((insn & 0xff00) == 0xc700);
     5552              insn = bfd_get_16 (input_bfd, contents + offset + 4);
     5553              BFD_ASSERT ((insn & 0xff00) == 0xd100);
     5554              insn = bfd_get_16 (input_bfd, contents + offset + 6);
     5555              BFD_ASSERT (insn == 0x310c);
     5556              insn = bfd_get_16 (input_bfd, contents + offset + 8);
     5557              BFD_ASSERT (insn == 0x410b);
     5558              insn = bfd_get_16 (input_bfd, contents + offset + 10);
     5559              BFD_ASSERT (insn == 0x34cc);
     5560
     5561              bfd_put_16 (output_bfd, 0x0012, contents + offset + 0);
     5562              bfd_put_16 (output_bfd, 0x0009, contents + offset + 2);
     5563              bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
     5564              bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
     5565              bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
     5566              bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
     5567
     5568              continue;
     5569            }
     5570
     5571          sgot = htab->sgot;
     5572          if (sgot == NULL)
     5573            abort ();
     5574
     5575          off = htab->tls_ldm_got.offset;
     5576          if (off & 1)
     5577            off &= ~1;
     5578          else
     5579            {
     5580              Elf_Internal_Rela outrel;
     5581              bfd_byte *loc;
     5582
     5583              srelgot = htab->srelgot;
     5584              if (srelgot == NULL)
     5585                abort ();
     5586
     5587              outrel.r_offset = (sgot->output_section->vma
     5588                                 + sgot->output_offset + off);
     5589              outrel.r_addend = 0;
     5590              outrel.r_info = ELF32_R_INFO (0, R_SH_TLS_DTPMOD32);
     5591              loc = srelgot->contents;
     5592              loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
     5593              bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
     5594              htab->tls_ldm_got.offset |= 1;
     5595            }
     5596
     5597          relocation = sgot->output_offset + off;
     5598          addend = rel->r_addend;
     5599
     5600          goto final_link_relocate;
     5601
     5602        case R_SH_TLS_LDO_32:
     5603          if (! info->shared)
     5604            relocation = tpoff (info, relocation);
     5605          else
     5606            relocation -= dtpoff_base (info);
     5607
     5608          addend = rel->r_addend;
     5609          goto final_link_relocate;
     5610
     5611        case R_SH_TLS_LE_32:
     5612          {
     5613            int indx;
     5614            Elf_Internal_Rela outrel;
     5615            bfd_byte *loc;
     5616
     5617            if (! info->shared)
     5618              {
     5619                relocation = tpoff (info, relocation);
     5620                addend = rel->r_addend;
     5621                goto final_link_relocate;
     5622              }
     5623
     5624            if (sreloc == NULL)
     5625              {
     5626                const char *name;
     5627
     5628                name = (bfd_elf_string_from_elf_section
     5629                        (input_bfd,
     5630                         elf_elfheader (input_bfd)->e_shstrndx,
     5631                         elf_section_data (input_section)->rel_hdr.sh_name));
     5632                if (name == NULL)
     5633                  return FALSE;
     5634
     5635                BFD_ASSERT (strncmp (name, ".rela", 5) == 0
     5636                            && strcmp (bfd_get_section_name (input_bfd,
     5637                                                             input_section),
     5638                                       name + 5) == 0);
     5639
     5640                sreloc = bfd_get_section_by_name (dynobj, name);
     5641                BFD_ASSERT (sreloc != NULL);
     5642              }
     5643
     5644            if (h == NULL || h->dynindx == -1)
     5645              indx = 0;
     5646            else
     5647              indx = h->dynindx;
     5648
     5649            outrel.r_offset = (input_section->output_section->vma
     5650                               + input_section->output_offset
     5651                               + rel->r_offset);
     5652            outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
     5653            if (indx == 0)
     5654              outrel.r_addend = relocation - dtpoff_base (info);
     5655            else
     5656              outrel.r_addend = 0;
     5657
     5658            loc = sreloc->contents;
     5659            loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
     5660            bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
     5661            continue;
     5662          }
    33345663        }
    33355664
     5665    relocation_done:
    33365666      if (r != bfd_reloc_ok)
    33375667        {
     
    33525682                            (input_bfd, symtab_hdr->sh_link, sym->st_name));
    33535683                    if (name == NULL)
    3354                       return false;
     5684                      return FALSE;
    33555685                    if (*name == '\0')
    33565686                      name = bfd_section_name (input_bfd, sec);
     
    33595689                       (info, name, howto->name, (bfd_vma) 0,
    33605690                        input_bfd, input_section, rel->r_offset)))
    3361                   return false;
     5691                  return FALSE;
    33625692              }
    33635693              break;
     
    33665696    }
    33675697
    3368   return true;
     5698  return TRUE;
    33695699}
    33705700
     
    33795709     struct bfd_link_order *link_order;
    33805710     bfd_byte *data;
    3381      boolean relocateable;
     5711     bfd_boolean relocateable;
    33825712     asymbol **symbols;
    33835713{
     
    33875717  asection **sections = NULL;
    33885718  Elf_Internal_Rela *internal_relocs = NULL;
    3389   Elf32_External_Sym *external_syms = NULL;
    3390   Elf_Internal_Sym *internal_syms = NULL;
     5719  Elf_Internal_Sym *isymbuf = NULL;
    33915720
    33925721  /* We only need to handle the case of relaxing, or of having a
     
    34025731
    34035732  memcpy (data, elf_section_data (input_section)->this_hdr.contents,
    3404           input_section->_raw_size);
     5733          (size_t) input_section->_raw_size);
    34055734
    34065735  if ((input_section->flags & SEC_RELOC) != 0
    34075736      && input_section->reloc_count > 0)
    34085737    {
    3409       Elf_Internal_Sym *isymp;
    34105738      asection **secpp;
    3411       Elf32_External_Sym *esym, *esymend;
    3412 
    3413       if (symtab_hdr->contents != NULL)
    3414         external_syms = (Elf32_External_Sym *) symtab_hdr->contents;
    3415       else
     5739      Elf_Internal_Sym *isym, *isymend;
     5740      bfd_size_type amt;
     5741
     5742      internal_relocs = (_bfd_elf32_link_read_relocs
     5743                         (input_bfd, input_section, (PTR) NULL,
     5744                          (Elf_Internal_Rela *) NULL, FALSE));
     5745      if (internal_relocs == NULL)
     5746        goto error_return;
     5747
     5748      if (symtab_hdr->sh_info != 0)
    34165749        {
    3417           external_syms = ((Elf32_External_Sym *)
    3418                            bfd_malloc (symtab_hdr->sh_info
    3419                                        * sizeof (Elf32_External_Sym)));
    3420           if (external_syms == NULL && symtab_hdr->sh_info > 0)
    3421             goto error_return;
    3422           if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
    3423               || (bfd_read (external_syms, sizeof (Elf32_External_Sym),
    3424                             symtab_hdr->sh_info, input_bfd)
    3425                   != (symtab_hdr->sh_info * sizeof (Elf32_External_Sym))))
     5750          isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
     5751          if (isymbuf == NULL)
     5752            isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
     5753                                            symtab_hdr->sh_info, 0,
     5754                                            NULL, NULL, NULL);
     5755          if (isymbuf == NULL)
    34265756            goto error_return;
    34275757        }
    34285758
    3429       internal_relocs = (_bfd_elf32_link_read_relocs
    3430                          (input_bfd, input_section, (PTR) NULL,
    3431                           (Elf_Internal_Rela *) NULL, false));
    3432       if (internal_relocs == NULL)
     5759      amt = symtab_hdr->sh_info;
     5760      amt *= sizeof (asection *);
     5761      sections = (asection **) bfd_malloc (amt);
     5762      if (sections == NULL && amt != 0)
    34335763        goto error_return;
    34345764
    3435       internal_syms = ((Elf_Internal_Sym *)
    3436                        bfd_malloc (symtab_hdr->sh_info
    3437                                    * sizeof (Elf_Internal_Sym)));
    3438       if (internal_syms == NULL && symtab_hdr->sh_info > 0)
    3439         goto error_return;
    3440 
    3441       sections = (asection **) bfd_malloc (symtab_hdr->sh_info
    3442                                            * sizeof (asection *));
    3443       if (sections == NULL && symtab_hdr->sh_info > 0)
    3444         goto error_return;
    3445 
    3446       isymp = internal_syms;
    3447       secpp = sections;
    3448       esym = external_syms;
    3449       esymend = esym + symtab_hdr->sh_info;
    3450       for (; esym < esymend; ++esym, ++isymp, ++secpp)
     5765      isymend = isymbuf + symtab_hdr->sh_info;
     5766      for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
    34515767        {
    34525768          asection *isec;
    34535769
    3454           bfd_elf32_swap_symbol_in (input_bfd, esym, isymp);
    3455 
    3456           if (isymp->st_shndx == SHN_UNDEF)
     5770          if (isym->st_shndx == SHN_UNDEF)
    34575771            isec = bfd_und_section_ptr;
    3458           else if (isymp->st_shndx > 0 && isymp->st_shndx < SHN_LORESERVE)
    3459             isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx);
    3460           else if (isymp->st_shndx == SHN_ABS)
     5772          else if (isym->st_shndx == SHN_ABS)
    34615773            isec = bfd_abs_section_ptr;
    3462           else if (isymp->st_shndx == SHN_COMMON)
     5774          else if (isym->st_shndx == SHN_COMMON)
    34635775            isec = bfd_com_section_ptr;
    34645776          else
    3465             {
    3466               /* Who knows?  */
    3467               isec = NULL;
    3468             }
     5777            isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
    34695778
    34705779          *secpp = isec;
     
    34735782      if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd,
    34745783                                     input_section, data, internal_relocs,
    3475                                      internal_syms, sections))
     5784                                     isymbuf, sections))
    34765785        goto error_return;
    34775786
    34785787      if (sections != NULL)
    34795788        free (sections);
    3480       sections = NULL;
    3481       if (internal_syms != NULL)
    3482         free (internal_syms);
    3483       internal_syms = NULL;
    3484       if (external_syms != NULL && symtab_hdr->contents == NULL)
    3485         free (external_syms);
    3486       external_syms = NULL;
    3487       if (internal_relocs != elf_section_data (input_section)->relocs)
     5789      if (isymbuf != NULL
     5790          && symtab_hdr->contents != (unsigned char *) isymbuf)
     5791        free (isymbuf);
     5792      if (elf_section_data (input_section)->relocs != internal_relocs)
    34885793        free (internal_relocs);
    3489       internal_relocs = NULL;
    34905794    }
    34915795
     
    34935797
    34945798 error_return:
    3495   if (internal_relocs != NULL
    3496       && internal_relocs != elf_section_data (input_section)->relocs)
    3497     free (internal_relocs);
    3498   if (external_syms != NULL && symtab_hdr->contents == NULL)
    3499     free (external_syms);
    3500   if (internal_syms != NULL)
    3501     free (internal_syms);
    35025799  if (sections != NULL)
    35035800    free (sections);
     5801  if (isymbuf != NULL
     5802      && symtab_hdr->contents != (unsigned char *) isymbuf)
     5803    free (isymbuf);
     5804  if (internal_relocs != NULL
     5805      && elf_section_data (input_section)->relocs != internal_relocs)
     5806    free (internal_relocs);
    35045807  return NULL;
    35055808}
     5809
     5810/* Return the base VMA address which should be subtracted from real addresses
     5811   when resolving @dtpoff relocation.
     5812   This is PT_TLS segment p_vaddr.  */
     5813
     5814static bfd_vma
     5815dtpoff_base (info)
     5816     struct bfd_link_info *info;
     5817{
     5818  /* If tls_segment is NULL, we should have signalled an error already.  */
     5819  if (elf_hash_table (info)->tls_segment == NULL)
     5820    return 0;
     5821  return elf_hash_table (info)->tls_segment->start;
     5822}
     5823
     5824/* Return the relocation value for R_SH_TLS_TPOFF32..  */
     5825
     5826static bfd_vma
     5827tpoff (info, address)
     5828     struct bfd_link_info *info;
     5829     bfd_vma address;
     5830{
     5831  /* If tls_segment is NULL, we should have signalled an error already.  */
     5832  if (elf_hash_table (info)->tls_segment == NULL)
     5833    return 0;
     5834  /* SH TLS ABI is variant I and static TLS block start just after tcbhead
     5835     structure which has 2 pointer fields.  */
     5836  return (address - dtpoff_base (info) + 8);
     5837}
     5838
    35065839static asection *
    3507 sh_elf_gc_mark_hook (abfd, info, rel, h, sym)
    3508      bfd *abfd;
     5840sh_elf_gc_mark_hook (sec, info, rel, h, sym)
     5841     asection *sec;
    35095842     struct bfd_link_info *info ATTRIBUTE_UNUSED;
    35105843     Elf_Internal_Rela *rel;
     
    35215854
    35225855        default:
     5856#ifdef INCLUDE_SHMEDIA
     5857          while (h->root.type == bfd_link_hash_indirect
     5858                 && h->root.u.i.link)
     5859            h = (struct elf_link_hash_entry *) h->root.u.i.link;
     5860#endif
    35235861          switch (h->root.type)
    35245862            {
     
    35365874    }
    35375875  else
    3538     {
    3539       if (!(elf_bad_symtab (abfd)
    3540             && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
    3541           && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
    3542                 && sym->st_shndx != SHN_COMMON))
    3543         return bfd_section_from_elf_index (abfd, sym->st_shndx);
    3544     }
     5876    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
     5877
    35455878  return NULL;
    35465879}
     
    35485881/* Update the got entry reference counts for the section being removed.  */
    35495882
    3550 static boolean
     5883static bfd_boolean
    35515884sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
    3552      bfd *abfd ATTRIBUTE_UNUSED;
    3553      struct bfd_link_info *info ATTRIBUTE_UNUSED;
    3554      asection *sec ATTRIBUTE_UNUSED;
    3555      const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
     5885     bfd *abfd;
     5886     struct bfd_link_info *info;
     5887     asection *sec;
     5888     const Elf_Internal_Rela *relocs;
    35565889{
    3557   /* We use got and plt entries for sh, but it would seem that the
    3558      existing SH code does no sort of reference counting or whatnot on
    3559      its GOT and PLT entries, so it is not possible to garbage collect
    3560      them at this time.  */
    3561   return true;
     5890  Elf_Internal_Shdr *symtab_hdr;
     5891  struct elf_link_hash_entry **sym_hashes;
     5892  bfd_signed_vma *local_got_refcounts;
     5893  const Elf_Internal_Rela *rel, *relend;
     5894
     5895  elf_section_data (sec)->local_dynrel = NULL;
     5896
     5897  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     5898  sym_hashes = elf_sym_hashes (abfd);
     5899  local_got_refcounts = elf_local_got_refcounts (abfd);
     5900
     5901  relend = relocs + sec->reloc_count;
     5902  for (rel = relocs; rel < relend; rel++)
     5903    {
     5904      unsigned long r_symndx;
     5905      unsigned int r_type;
     5906      struct elf_link_hash_entry *h = NULL;
     5907#ifdef INCLUDE_SHMEDIA
     5908      int seen_stt_datalabel = 0;
     5909#endif
     5910
     5911      r_symndx = ELF32_R_SYM (rel->r_info);
     5912      if (r_symndx >= symtab_hdr->sh_info)
     5913        {
     5914          struct elf_sh_link_hash_entry *eh;
     5915          struct elf_sh_dyn_relocs **pp;
     5916          struct elf_sh_dyn_relocs *p;
     5917
     5918          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
     5919#ifdef INCLUDE_SHMEDIA
     5920          while (h->root.type == bfd_link_hash_indirect
     5921                 || h->root.type == bfd_link_hash_warning)
     5922            {
     5923              seen_stt_datalabel |= h->type == STT_DATALABEL;
     5924              h = (struct elf_link_hash_entry *) h->root.u.i.link;
     5925            }
     5926#endif
     5927          eh = (struct elf_sh_link_hash_entry *) h;
     5928          for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
     5929            if (p->sec == sec)
     5930              {
     5931                /* Everything must go for SEC.  */
     5932                *pp = p->next;
     5933                break;
     5934              }
     5935        }
     5936
     5937      r_type = ELF32_R_TYPE (rel->r_info);
     5938      switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL))
     5939        {
     5940        case R_SH_TLS_LD_32:
     5941          if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
     5942            sh_elf_hash_table (info)->tls_ldm_got.refcount -= 1;
     5943          break;
     5944
     5945        case R_SH_GOT32:
     5946        case R_SH_GOTOFF:
     5947        case R_SH_GOTPC:
     5948#ifdef INCLUDE_SHMEDIA
     5949        case R_SH_GOT_LOW16:
     5950        case R_SH_GOT_MEDLOW16:
     5951        case R_SH_GOT_MEDHI16:
     5952        case R_SH_GOT_HI16:
     5953        case R_SH_GOT10BY4:
     5954        case R_SH_GOT10BY8:
     5955        case R_SH_GOTOFF_LOW16:
     5956        case R_SH_GOTOFF_MEDLOW16:
     5957        case R_SH_GOTOFF_MEDHI16:
     5958        case R_SH_GOTOFF_HI16:
     5959        case R_SH_GOTPC_LOW16:
     5960        case R_SH_GOTPC_MEDLOW16:
     5961        case R_SH_GOTPC_MEDHI16:
     5962        case R_SH_GOTPC_HI16:
     5963#endif
     5964        case R_SH_TLS_GD_32:
     5965        case R_SH_TLS_IE_32:
     5966          if (h != NULL)
     5967            {
     5968#ifdef INCLUDE_SHMEDIA
     5969              if (seen_stt_datalabel)
     5970                {
     5971                  struct elf_sh_link_hash_entry *eh;
     5972                  eh = (struct elf_sh_link_hash_entry *) h;
     5973                  if (eh->datalabel_got.refcount > 0)
     5974                    eh->datalabel_got.refcount -= 1;
     5975                }
     5976              else
     5977#endif
     5978                if (h->got.refcount > 0)
     5979                  h->got.refcount -= 1;
     5980            }
     5981          else if (local_got_refcounts != NULL)
     5982            {
     5983#ifdef INCLUDE_SHMEDIA
     5984              if (rel->r_addend & 1)
     5985                {
     5986                  if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
     5987                    local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
     5988                }
     5989              else
     5990#endif
     5991                if (local_got_refcounts[r_symndx] > 0)
     5992                  local_got_refcounts[r_symndx] -= 1;
     5993            }
     5994          break;
     5995
     5996        case R_SH_DIR32:
     5997        case R_SH_REL32:
     5998          if (info->shared)
     5999            break;
     6000          /* Fall thru */
     6001
     6002        case R_SH_PLT32:
     6003#ifdef INCLUDE_SHMEDIA
     6004        case R_SH_PLT_LOW16:
     6005        case R_SH_PLT_MEDLOW16:
     6006        case R_SH_PLT_MEDHI16:
     6007        case R_SH_PLT_HI16:
     6008#endif
     6009          if (h != NULL)
     6010            {
     6011              if (h->plt.refcount > 0)
     6012                h->plt.refcount -= 1;
     6013            }
     6014          break;
     6015
     6016        case R_SH_GOTPLT32:
     6017#ifdef INCLUDE_SHMEDIA
     6018        case R_SH_GOTPLT_LOW16:
     6019        case R_SH_GOTPLT_MEDLOW16:
     6020        case R_SH_GOTPLT_MEDHI16:
     6021        case R_SH_GOTPLT_HI16:
     6022        case R_SH_GOTPLT10BY4:
     6023        case R_SH_GOTPLT10BY8:
     6024#endif
     6025          if (h != NULL)
     6026            {
     6027              struct elf_sh_link_hash_entry *eh;
     6028              eh = (struct elf_sh_link_hash_entry *) h;
     6029              if (eh->gotplt_refcount > 0)
     6030                {
     6031                  eh->gotplt_refcount -= 1;
     6032                  if (h->plt.refcount > 0)
     6033                    h->plt.refcount -= 1;
     6034                }
     6035#ifdef INCLUDE_SHMEDIA
     6036              else if (seen_stt_datalabel)
     6037                {
     6038                  if (eh->datalabel_got.refcount > 0)
     6039                    eh->datalabel_got.refcount -= 1;
     6040                }
     6041#endif
     6042              else if (h->got.refcount > 0)
     6043                h->got.refcount -= 1;
     6044            }
     6045          else if (local_got_refcounts != NULL)
     6046            {
     6047#ifdef INCLUDE_SHMEDIA
     6048              if (rel->r_addend & 1)
     6049                {
     6050                  if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
     6051                    local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
     6052                }
     6053              else
     6054#endif
     6055                if (local_got_refcounts[r_symndx] > 0)
     6056                  local_got_refcounts[r_symndx] -= 1;
     6057            }
     6058          break;
     6059
     6060        default:
     6061          break;
     6062        }
     6063    }
     6064
     6065  return TRUE;
     6066}
     6067
     6068/* Copy the extra info we tack onto an elf_link_hash_entry.  */
     6069
     6070static void
     6071sh_elf_copy_indirect_symbol (bed, dir, ind)
     6072     struct elf_backend_data *bed;
     6073     struct elf_link_hash_entry *dir, *ind;
     6074{
     6075  struct elf_sh_link_hash_entry *edir, *eind;
     6076#ifdef INCLUDE_SHMEDIA
     6077  bfd_signed_vma tmp;
     6078#endif
     6079
     6080  edir = (struct elf_sh_link_hash_entry *) dir;
     6081  eind = (struct elf_sh_link_hash_entry *) ind;
     6082
     6083  if (eind->dyn_relocs != NULL)
     6084    {
     6085      if (edir->dyn_relocs != NULL)
     6086        {
     6087          struct elf_sh_dyn_relocs **pp;
     6088          struct elf_sh_dyn_relocs *p;
     6089
     6090          BFD_ASSERT (ind->root.type != bfd_link_hash_indirect);
     6091
     6092          /* Add reloc counts against the weak sym to the strong sym
     6093             list.  Merge any entries against the same section.  */
     6094          for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
     6095            {
     6096              struct elf_sh_dyn_relocs *q;
     6097
     6098              for (q = edir->dyn_relocs; q != NULL; q = q->next)
     6099                if (q->sec == p->sec)
     6100                  {
     6101                    q->pc_count += p->pc_count;
     6102                    q->count += p->count;
     6103                    *pp = p->next;
     6104                    break;
     6105                  }
     6106              if (q == NULL)
     6107                pp = &p->next;
     6108            }
     6109          *pp = edir->dyn_relocs;
     6110        }
     6111
     6112      edir->dyn_relocs = eind->dyn_relocs;
     6113      eind->dyn_relocs = NULL;
     6114    }
     6115  edir->gotplt_refcount = eind->gotplt_refcount;
     6116  eind->gotplt_refcount = 0;
     6117#ifdef INCLUDE_SHMEDIA
     6118  tmp = edir->datalabel_got.refcount;
     6119  if (tmp < 1)
     6120    {
     6121      edir->datalabel_got.refcount = eind->datalabel_got.refcount;
     6122      eind->datalabel_got.refcount = tmp;
     6123    }
     6124  else
     6125    BFD_ASSERT (eind->datalabel_got.refcount < 1);
     6126#endif
     6127
     6128  if (ind->root.type == bfd_link_hash_indirect
     6129      && dir->got.refcount <= 0)
     6130    {
     6131      edir->tls_type = eind->tls_type;
     6132      eind->tls_type = GOT_UNKNOWN;
     6133    }
     6134
     6135  _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
     6136}
     6137
     6138static int
     6139sh_elf_optimized_tls_reloc (info, r_type, is_local)
     6140     struct bfd_link_info *info;
     6141     int r_type;
     6142     int is_local;
     6143{
     6144  if (info->shared)
     6145    return r_type;
     6146
     6147  switch (r_type)
     6148    {
     6149    case R_SH_TLS_GD_32:
     6150    case R_SH_TLS_IE_32:
     6151      if (is_local)
     6152        return R_SH_TLS_LE_32;
     6153      return R_SH_TLS_IE_32;
     6154    case R_SH_TLS_LD_32:
     6155      return R_SH_TLS_LE_32;
     6156    }
     6157
     6158  return r_type;
    35626159}
    35636160
     
    35666163   virtual table relocs for gc.  */
    35676164
    3568 static boolean
     6165static bfd_boolean
    35696166sh_elf_check_relocs (abfd, info, sec, relocs)
    35706167     bfd *abfd;
     
    35756172  Elf_Internal_Shdr *symtab_hdr;
    35766173  struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
     6174  struct elf_sh_link_hash_table *htab;
    35776175  const Elf_Internal_Rela *rel;
    35786176  const Elf_Internal_Rela *rel_end;
     
    35826180  asection *srelgot;
    35836181  asection *sreloc;
     6182  unsigned int r_type;
     6183  int tls_type, old_tls_type;
    35846184
    35856185  sgot = NULL;
     
    35886188
    35896189  if (info->relocateable)
    3590     return true;
     6190    return TRUE;
    35916191
    35926192  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     
    35966196    sym_hashes_end -= symtab_hdr->sh_info;
    35976197
    3598   dynobj = elf_hash_table (info)->dynobj;
     6198  htab = sh_elf_hash_table (info);
     6199  dynobj = htab->root.dynobj;
    35996200  local_got_offsets = elf_local_got_offsets (abfd);
    36006201
     
    36046205      struct elf_link_hash_entry *h;
    36056206      unsigned long r_symndx;
     6207#ifdef INCLUDE_SHMEDIA
     6208      int seen_stt_datalabel = 0;
     6209#endif
    36066210
    36076211      r_symndx = ELF32_R_SYM (rel->r_info);
     6212      r_type = ELF32_R_TYPE (rel->r_info);
     6213
    36086214      if (r_symndx < symtab_hdr->sh_info)
    36096215        h = NULL;
    36106216      else
    3611         h = sym_hashes[r_symndx - symtab_hdr->sh_info];
     6217        {
     6218          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
     6219#ifdef INCLUDE_SHMEDIA
     6220          while (h->root.type == bfd_link_hash_indirect
     6221                 || h->root.type == bfd_link_hash_warning)
     6222            {
     6223              seen_stt_datalabel |= h->type == STT_DATALABEL;
     6224              h = (struct elf_link_hash_entry *) h->root.u.i.link;
     6225            }
     6226#endif
     6227        }
     6228
     6229      r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
     6230      if (! info->shared
     6231          && r_type == R_SH_TLS_IE_32
     6232          && h != NULL
     6233          && h->root.type != bfd_link_hash_undefined
     6234          && h->root.type != bfd_link_hash_undefweak
     6235          && (h->dynindx == -1
     6236              || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
     6237        r_type = R_SH_TLS_LE_32;
    36126238
    36136239      /* Some relocs require a global offset table.  */
    3614       if (dynobj == NULL)
     6240      if (htab->sgot == NULL)
    36156241        {
    3616           switch (ELF32_R_TYPE (rel->r_info))
     6242          switch (r_type)
    36176243            {
     6244            case R_SH_GOTPLT32:
    36186245            case R_SH_GOT32:
    36196246            case R_SH_GOTOFF:
    36206247            case R_SH_GOTPC:
    3621               elf_hash_table (info)->dynobj = dynobj = abfd;
    3622               if (! _bfd_elf_create_got_section (dynobj, info))
    3623                 return false;
     6248#ifdef INCLUDE_SHMEDIA
     6249            case R_SH_GOTPLT_LOW16:
     6250            case R_SH_GOTPLT_MEDLOW16:
     6251            case R_SH_GOTPLT_MEDHI16:
     6252            case R_SH_GOTPLT_HI16:
     6253            case R_SH_GOTPLT10BY4:
     6254            case R_SH_GOTPLT10BY8:
     6255            case R_SH_GOT_LOW16:
     6256            case R_SH_GOT_MEDLOW16:
     6257            case R_SH_GOT_MEDHI16:
     6258            case R_SH_GOT_HI16:
     6259            case R_SH_GOT10BY4:
     6260            case R_SH_GOT10BY8:
     6261            case R_SH_GOTOFF_LOW16:
     6262            case R_SH_GOTOFF_MEDLOW16:
     6263            case R_SH_GOTOFF_MEDHI16:
     6264            case R_SH_GOTOFF_HI16:
     6265            case R_SH_GOTPC_LOW16:
     6266            case R_SH_GOTPC_MEDLOW16:
     6267            case R_SH_GOTPC_MEDHI16:
     6268            case R_SH_GOTPC_HI16:
     6269#endif
     6270            case R_SH_TLS_GD_32:
     6271            case R_SH_TLS_LD_32:
     6272            case R_SH_TLS_IE_32:
     6273              if (dynobj == NULL)
     6274                htab->root.dynobj = dynobj = abfd;
     6275              if (! create_got_section (dynobj, info))
     6276                return FALSE;
    36246277              break;
    36256278
     
    36296282        }
    36306283
    3631       switch (ELF32_R_TYPE (rel->r_info))
    3632         {
    3633         /* This relocation describes the C++ object vtable hierarchy.
    3634            Reconstruct it for later use during GC.  */
     6284      switch (r_type)
     6285        {
     6286          /* This relocation describes the C++ object vtable hierarchy.
     6287             Reconstruct it for later use during GC.  */
    36356288        case R_SH_GNU_VTINHERIT:
    36366289          if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
    3637             return false;
     6290            return FALSE;
    36386291          break;
    36396292
    3640         /* This relocation describes which C++ vtable entries are actually
    3641            used.  Record for later use during GC.  */
     6293          /* This relocation describes which C++ vtable entries are actually
     6294             used.  Record for later use during GC.  */
    36426295        case R_SH_GNU_VTENTRY:
    36436296          if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
    3644             return false;
     6297            return FALSE;
    36456298          break;
    36466299
     6300        case R_SH_TLS_IE_32:
     6301          if (info->shared)
     6302            info->flags |= DF_STATIC_TLS;
     6303
     6304          /* FALLTHROUGH */
     6305        force_got:
     6306        case R_SH_TLS_GD_32:
    36476307        case R_SH_GOT32:
    3648           /* This symbol requires a global offset table entry.  */
    3649 
    3650           if (sgot == NULL)
     6308#ifdef INCLUDE_SHMEDIA
     6309        case R_SH_GOT_LOW16:
     6310        case R_SH_GOT_MEDLOW16:
     6311        case R_SH_GOT_MEDHI16:
     6312        case R_SH_GOT_HI16:
     6313        case R_SH_GOT10BY4:
     6314        case R_SH_GOT10BY8:
     6315#endif
     6316          switch (r_type)
    36516317            {
    3652               sgot = bfd_get_section_by_name (dynobj, ".got");
    3653               BFD_ASSERT (sgot != NULL);
    3654             }
    3655 
    3656           if (srelgot == NULL
    3657               && (h != NULL || info->shared))
    3658             {
    3659               srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
    3660               if (srelgot == NULL)
    3661                 {
    3662                   srelgot = bfd_make_section (dynobj, ".rela.got");
    3663                   if (srelgot == NULL
    3664                       || ! bfd_set_section_flags (dynobj, srelgot,
    3665                                                   (SEC_ALLOC
    3666                                                    | SEC_LOAD
    3667                                                    | SEC_HAS_CONTENTS
    3668                                                    | SEC_IN_MEMORY
    3669                                                    | SEC_LINKER_CREATED
    3670                                                    | SEC_READONLY))
    3671                       || ! bfd_set_section_alignment (dynobj, srelgot, 2))
    3672                     return false;
    3673                 }
     6318            default:
     6319              tls_type = GOT_NORMAL;
     6320              break;
     6321            case R_SH_TLS_GD_32:
     6322              tls_type = GOT_TLS_GD;
     6323              break;
     6324            case R_SH_TLS_IE_32:
     6325              tls_type = GOT_TLS_IE;
     6326              break;
    36746327            }
    36756328
    36766329          if (h != NULL)
    36776330            {
    3678               if (h->got.offset != (bfd_vma) -1)
     6331#ifdef INCLUDE_SHMEDIA
     6332              if (seen_stt_datalabel)
    36796333                {
    3680                   /* We have already allocated space in the .got.  */
    3681                   break;
     6334                  struct elf_sh_link_hash_entry *eh
     6335                    = (struct elf_sh_link_hash_entry *) h;
     6336
     6337                  eh->datalabel_got.refcount += 1;
    36826338                }
    3683               h->got.offset = sgot->_raw_size;
    3684 
    3685               /* Make sure this symbol is output as a dynamic symbol.  */
    3686               if (h->dynindx == -1)
    3687                 {
    3688                   if (! bfd_elf32_link_record_dynamic_symbol (info, h))
    3689                     return false;
    3690                 }
    3691 
    3692               srelgot->_raw_size += sizeof (Elf32_External_Rela);
     6339              else
     6340#endif
     6341                h->got.refcount += 1;
     6342              old_tls_type = sh_elf_hash_entry (h)->tls_type;
    36936343            }
    36946344          else
    36956345            {
     6346              bfd_signed_vma *local_got_refcounts;
     6347
    36966348              /* This is a global offset table entry for a local
    3697                  symbol.  */
    3698               if (local_got_offsets == NULL)
     6349                 symbol.  */
     6350              local_got_refcounts = elf_local_got_refcounts (abfd);
     6351              if (local_got_refcounts == NULL)
    36996352                {
    3700                   size_t size;
    3701                   register unsigned int i;
    3702 
    3703                   size = symtab_hdr->sh_info * sizeof (bfd_vma);
    3704                   local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
    3705                   if (local_got_offsets == NULL)
    3706                     return false;
    3707                   elf_local_got_offsets (abfd) = local_got_offsets;
    3708                   for (i = 0; i < symtab_hdr->sh_info; i++)
    3709                     local_got_offsets[i] = (bfd_vma) -1;
     6353                  bfd_size_type size;
     6354
     6355                  size = symtab_hdr->sh_info;
     6356                  size *= sizeof (bfd_signed_vma);
     6357#ifdef INCLUDE_SHMEDIA
     6358                  /* Reserve space for both the datalabel and
     6359                     codelabel local GOT offsets.  */
     6360                  size *= 2;
     6361#endif
     6362                  size += symtab_hdr->sh_info;
     6363                  local_got_refcounts = ((bfd_signed_vma *)
     6364                                         bfd_zalloc (abfd, size));
     6365                  if (local_got_refcounts == NULL)
     6366                    return FALSE;
     6367                  elf_local_got_refcounts (abfd) = local_got_refcounts;
     6368#ifdef  INCLUDE_SHMEDIA
     6369                  /* Take care of both the datalabel and codelabel local
     6370                     GOT offsets.  */
     6371                  sh_elf_local_got_tls_type (abfd)
     6372                    = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
     6373#else
     6374                  sh_elf_local_got_tls_type (abfd)
     6375                    = (char *) (local_got_refcounts + symtab_hdr->sh_info);
     6376#endif
    37106377                }
    3711               if (local_got_offsets[r_symndx] != (bfd_vma) -1)
     6378#ifdef INCLUDE_SHMEDIA
     6379              if (rel->r_addend & 1)
     6380                local_got_refcounts[symtab_hdr->sh_info + r_symndx] += 1;
     6381              else
     6382#endif
     6383                local_got_refcounts[r_symndx] += 1;
     6384              old_tls_type = sh_elf_local_got_tls_type (abfd) [r_symndx];
     6385            }
     6386
     6387          /* If a TLS symbol is accessed using IE at least once,
     6388             there is no point to use dynamic model for it.  */
     6389          if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
     6390              && (old_tls_type != GOT_TLS_GD || tls_type != GOT_TLS_IE))
     6391            {
     6392              if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
     6393                tls_type = GOT_TLS_IE;
     6394              else
    37126395                {
    3713                   /* We have already allocated space in the .got.  */
    3714                   break;
    3715                 }
    3716               local_got_offsets[r_symndx] = sgot->_raw_size;
    3717 
    3718               if (info->shared)
    3719                 {
    3720                   /* If we are generating a shared object, we need to
    3721                      output a R_SH_RELATIVE reloc so that the dynamic
    3722                      linker can adjust this GOT entry.  */
    3723                   srelgot->_raw_size += sizeof (Elf32_External_Rela);
     6396                  (*_bfd_error_handler)
     6397                    (_("%s: `%s' accessed both as normal and thread local symbol"),
     6398                     bfd_archive_filename (abfd), h->root.root.string);
     6399                  return FALSE;
    37246400                }
    37256401            }
    37266402
    3727           sgot->_raw_size += 4;
     6403          if (old_tls_type != tls_type)
     6404            {
     6405              if (h != NULL)
     6406                sh_elf_hash_entry (h)->tls_type = tls_type;
     6407              else
     6408                sh_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
     6409            }
    37286410
    37296411          break;
    37306412
     6413        case R_SH_TLS_LD_32:
     6414          sh_elf_hash_table(info)->tls_ldm_got.refcount += 1;
     6415          break;
     6416
     6417        case R_SH_GOTPLT32:
     6418#ifdef INCLUDE_SHMEDIA
     6419        case R_SH_GOTPLT_LOW16:
     6420        case R_SH_GOTPLT_MEDLOW16:
     6421        case R_SH_GOTPLT_MEDHI16:
     6422        case R_SH_GOTPLT_HI16:
     6423        case R_SH_GOTPLT10BY4:
     6424        case R_SH_GOTPLT10BY8:
     6425#endif
     6426          /* If this is a local symbol, we resolve it directly without
     6427             creating a procedure linkage table entry.  */
     6428
     6429          if (h == NULL
     6430              || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
     6431              || ! info->shared
     6432              || info->symbolic
     6433              || h->dynindx == -1)
     6434            goto force_got;
     6435
     6436          h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
     6437          h->plt.refcount += 1;
     6438          ((struct elf_sh_link_hash_entry *) h)->gotplt_refcount += 1;
     6439
     6440          break;
     6441
    37316442        case R_SH_PLT32:
     6443#ifdef INCLUDE_SHMEDIA
     6444        case R_SH_PLT_LOW16:
     6445        case R_SH_PLT_MEDLOW16:
     6446        case R_SH_PLT_MEDHI16:
     6447        case R_SH_PLT_HI16:
     6448#endif
    37326449          /* This symbol requires a procedure linkage table entry.  We
    37336450             actually build the entry in adjust_dynamic_symbol,
     
    37426459            continue;
    37436460
    3744           if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
    3745               || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
     6461          if (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
    37466462            break;
    37476463
    37486464          h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
    3749 
     6465          h->plt.refcount += 1;
    37506466          break;
    37516467
    37526468        case R_SH_DIR32:
    37536469        case R_SH_REL32:
    3754           if (h != NULL)
    3755             h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
     6470          if (h != NULL && ! info->shared)
     6471            {
     6472              h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
     6473              h->plt.refcount += 1;
     6474            }
    37566475
    37576476          /* If we are creating a shared library, and this is a reloc
     
    37666485             later (it is never cleared).  We account for that
    37676486             possibility below by storing information in the
    3768              pcrel_relocs_copied field of the hash table entry.  */
    3769           if (info->shared
    3770               && (sec->flags & SEC_ALLOC) != 0
    3771               && (ELF32_R_TYPE (rel->r_info) != R_SH_REL32
    3772                   || (h != NULL
    3773                       && (! info->symbolic
    3774                           || (h->elf_link_hash_flags
    3775                               & ELF_LINK_HASH_DEF_REGULAR) == 0))))
     6487             dyn_relocs field of the hash table entry. A similar
     6488             situation occurs when creating shared libraries and symbol
     6489             visibility changes render the symbol local.
     6490
     6491             If on the other hand, we are creating an executable, we
     6492             may need to keep relocations for symbols satisfied by a
     6493             dynamic library if we manage to avoid copy relocs for the
     6494             symbol.  */
     6495          if ((info->shared
     6496               && (sec->flags & SEC_ALLOC) != 0
     6497               && (r_type != R_SH_REL32
     6498                   || (h != NULL
     6499                       && (! info->symbolic
     6500                           || h->root.type == bfd_link_hash_defweak
     6501                           || (h->elf_link_hash_flags
     6502                               & ELF_LINK_HASH_DEF_REGULAR) == 0))))
     6503              || (! info->shared
     6504                  && (sec->flags & SEC_ALLOC) != 0
     6505                  && h != NULL
     6506                  && (h->root.type == bfd_link_hash_defweak
     6507                      || (h->elf_link_hash_flags
     6508                          & ELF_LINK_HASH_DEF_REGULAR) == 0)))
    37766509            {
     6510              struct elf_sh_dyn_relocs *p;
     6511              struct elf_sh_dyn_relocs **head;
     6512
     6513              if (dynobj == NULL)
     6514                htab->root.dynobj = dynobj = abfd;
     6515
    37776516              /* When creating a shared object, we must copy these
    37786517                 reloc types into the output file.  We create a reloc
     
    37876526                           elf_section_data (sec)->rel_hdr.sh_name));
    37886527                  if (name == NULL)
    3789                     return false;
     6528                    return FALSE;
    37906529
    37916530                  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
     
    38066545                          || ! bfd_set_section_flags (dynobj, sreloc, flags)
    38076546                          || ! bfd_set_section_alignment (dynobj, sreloc, 2))
    3808                         return false;
     6547                        return FALSE;
    38096548                    }
     6549                  if (sec->flags & SEC_READONLY)
     6550                    info->flags |= DF_TEXTREL;
     6551                  elf_section_data (sec)->sreloc = sreloc;
    38106552                }
    38116553
    3812               sreloc->_raw_size += sizeof (Elf32_External_Rela);
    3813 
    3814               /* If we are linking with -Bsymbolic, and this is a
    3815                  global symbol, we count the number of PC relative
    3816                  relocations we have entered for this symbol, so that
    3817                  we can discard them again if the symbol is later
    3818                  defined by a regular object.  Note that this function
    3819                  is only called if we are using an elf_sh linker
    3820                  hash table, which means that h is really a pointer to
    3821                  an elf_sh_link_hash_entry.  */
    3822               if (h != NULL && info->symbolic
    3823                   && ELF32_R_TYPE (rel->r_info) == R_SH_REL32)
     6554              /* If this is a global symbol, we count the number of
     6555                 relocations we need for this symbol.  */
     6556              if (h != NULL)
     6557                head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
     6558              else
    38246559                {
    3825                   struct elf_sh_link_hash_entry *eh;
    3826                   struct elf_sh_pcrel_relocs_copied *p;
    3827 
    3828                   eh = (struct elf_sh_link_hash_entry *) h;
    3829 
    3830                   for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
    3831                     if (p->section == sreloc)
    3832                       break;
    3833 
     6560                  asection *s;
     6561
     6562                  /* Track dynamic relocs needed for local syms too.  */
     6563                  s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
     6564                                                 sec, r_symndx);
     6565                  if (s == NULL)
     6566                    return FALSE;
     6567
     6568                  head = ((struct elf_sh_dyn_relocs **)
     6569                          &elf_section_data (s)->local_dynrel);
     6570                }
     6571
     6572              p = *head;
     6573              if (p == NULL || p->sec != sec)
     6574                {
     6575                  bfd_size_type amt = sizeof (*p);
     6576                  p = ((struct elf_sh_dyn_relocs *) bfd_alloc (dynobj, amt));
    38346577                  if (p == NULL)
    3835                     {
    3836                       p = ((struct elf_sh_pcrel_relocs_copied *)
    3837                            bfd_alloc (dynobj, sizeof *p));
    3838                       if (p == NULL)
    3839                         return false;
    3840                       p->next = eh->pcrel_relocs_copied;
    3841                       eh->pcrel_relocs_copied = p;
    3842                       p->section = sreloc;
    3843                       p->count = 0;
    3844                     }
    3845 
    3846                   ++p->count;
     6578                    return FALSE;
     6579                  p->next = *head;
     6580                  *head = p;
     6581                  p->sec = sec;
     6582                  p->count = 0;
     6583                  p->pc_count = 0;
    38476584                }
     6585
     6586              p->count += 1;
     6587              if (r_type == R_SH_REL32)
     6588                p->pc_count += 1;
    38486589            }
    38496590
     6591          break;
     6592
     6593        case R_SH_TLS_LE_32:
     6594          if (info->shared)
     6595            {
     6596              (*_bfd_error_handler) (_("%s: TLS local exec code cannot be linked into shared objects"),
     6597                                     bfd_archive_filename (abfd));
     6598              return FALSE;
     6599            }
     6600
     6601          break;
     6602
     6603        case R_SH_TLS_LDO_32:
     6604          /* Nothing to do.  */
     6605          break;
     6606
     6607        default:
    38506608          break;
    38516609        }
    38526610    }
    38536611
    3854   return true;
     6612  return TRUE;
    38556613}
    38566614
    3857 static boolean
     6615#ifndef sh_elf_set_mach_from_flags
     6616static bfd_boolean
    38586617sh_elf_set_mach_from_flags (abfd)
    38596618     bfd *abfd;
     
    38686627    case EF_SH2:
    38696628      bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2);
     6629      break;
     6630    case EF_SH2E:
     6631      bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2e);
    38706632      break;
    38716633    case EF_SH_DSP:
     
    38866648      break;
    38876649    default:
    3888       return false;
     6650      return FALSE;
    38896651    }
    3890   return true;
     6652  return TRUE;
    38916653}
    3892 
     6654#endif /* not sh_elf_set_mach_from_flags */
     6655
     6656#ifndef sh_elf_set_private_flags
    38936657/* Function to keep SH specific file flags.  */
    38946658
    3895 static boolean
     6659static bfd_boolean
    38966660sh_elf_set_private_flags (abfd, flags)
    38976661     bfd *abfd;
     
    39026666
    39036667  elf_elfheader (abfd)->e_flags = flags;
    3904   elf_flags_init (abfd) = true;
     6668  elf_flags_init (abfd) = TRUE;
    39056669  return sh_elf_set_mach_from_flags (abfd);
    39066670}
    3907 
     6671#endif /* not sh_elf_set_private_flags */
     6672
     6673#ifndef sh_elf_copy_private_data
    39086674/* Copy backend specific data from one object module to another */
    39096675
    3910 static boolean
     6676static bfd_boolean
    39116677sh_elf_copy_private_data (ibfd, obfd)
    39126678     bfd * ibfd;
     
    39156681  if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    39166682      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    3917     return true;
     6683    return TRUE;
    39186684
    39196685  return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
    39206686}
    3921 
     6687#endif /* not sh_elf_copy_private_data */
     6688
     6689#ifndef sh_elf_merge_private_data
    39226690/* This routine checks for linking big and little endian objects
    39236691   together, and for linking sh-dsp with sh3e / sh4 objects.  */
    39246692
    3925 static boolean
     6693static bfd_boolean
    39266694sh_elf_merge_private_data (ibfd, obfd)
    39276695     bfd *ibfd;
     
    39306698  flagword old_flags, new_flags;
    39316699
    3932   if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
    3933     return false;
     6700  if (! _bfd_generic_verify_endian_match (ibfd, obfd))
     6701    return FALSE;
    39346702
    39356703  if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    39366704      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    3937     return true;
     6705    return TRUE;
    39386706
    39396707  if (! elf_flags_init (obfd))
    39406708    {
    39416709      /* This happens when ld starts out with a 'blank' output file.  */
    3942       elf_flags_init (obfd) = true;
     6710      elf_flags_init (obfd) = TRUE;
    39436711      elf_elfheader (obfd)->e_flags = EF_SH1;
    39446712    }
     
    39506718      (*_bfd_error_handler)
    39516719        ("%s: uses %s instructions while previous modules use %s instructions",
    3952          bfd_get_filename (ibfd),
     6720         bfd_archive_filename (ibfd),
    39536721         EF_SH_HAS_DSP (new_flags) ? "dsp" : "floating point",
    39546722         EF_SH_HAS_DSP (new_flags) ? "floating point" : "dsp");
    39556723      bfd_set_error (bfd_error_bad_value);
    3956       return false;
     6724      return FALSE;
    39576725    }
    39586726  elf_elfheader (obfd)->e_flags = EF_SH_MERGE_MACH (old_flags, new_flags);
     
    39606728  return sh_elf_set_mach_from_flags (obfd);
    39616729}
     6730#endif /* not sh_elf_merge_private_data */
     6731
     6732/* Override the generic function because we need to store sh_elf_obj_tdata
     6733   as the specific tdata.  We set also the machine architecture from flags
     6734   here.  */
     6735
     6736static bfd_boolean
     6737sh_elf_object_p (abfd)
     6738  bfd *abfd;
     6739{
     6740  struct sh_elf_obj_tdata *new_tdata;
     6741  bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
     6742
     6743  if (!sh_elf_set_mach_from_flags (abfd))
     6744    return FALSE;
     6745
     6746  /* Allocate our special target data.  */
     6747  new_tdata = bfd_zalloc (abfd, amt);
     6748  if (new_tdata == NULL)
     6749    return FALSE;
     6750  new_tdata->root = *abfd->tdata.elf_obj_data;
     6751  abfd->tdata.any = new_tdata;
     6752  return TRUE;
     6753}
    39626754
    39636755/* Finish up dynamic symbol handling.  We set the contents of various
    39646756   dynamic sections here.  */
    39656757
    3966 static boolean
     6758static bfd_boolean
    39676759sh_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
    39686760     bfd *output_bfd;
     
    39716763     Elf_Internal_Sym *sym;
    39726764{
     6765  struct elf_sh_link_hash_table *htab;
    39736766  bfd *dynobj;
    39746767
    3975   dynobj = elf_hash_table (info)->dynobj;
     6768  htab = sh_elf_hash_table (info);
     6769  dynobj = htab->root.dynobj;
    39766770
    39776771  if (h->plt.offset != (bfd_vma) -1)
     
    39846778      bfd_vma got_offset;
    39856779      Elf_Internal_Rela rel;
     6780      bfd_byte *loc;
    39866781
    39876782      /* This symbol has an entry in the procedure linkage table.  Set
     
    39906785      BFD_ASSERT (h->dynindx != -1);
    39916786
    3992       splt = bfd_get_section_by_name (dynobj, ".plt");
    3993       sgot = bfd_get_section_by_name (dynobj, ".got.plt");
    3994       srel = bfd_get_section_by_name (dynobj, ".rela.plt");
     6787      splt = htab->splt;
     6788      sgot = htab->sgotplt;
     6789      srel = htab->srelplt;
    39956790      BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
    39966791
     
    40056800         The first three are reserved.  */
    40066801      got_offset = (plt_index + 3) * 4;
     6802
     6803#ifdef GOT_BIAS
     6804      if (info->shared)
     6805        got_offset -= GOT_BIAS;
     6806#endif
    40076807
    40086808      /* Fill in the entry in the procedure linkage table.  */
     
    40166816          memcpy (splt->contents + h->plt.offset, elf_sh_plt_entry,
    40176817                  elf_sh_sizeof_plt (info));
     6818#ifdef INCLUDE_SHMEDIA
     6819          movi_shori_putval (output_bfd,
     6820                             (sgot->output_section->vma
     6821                              + sgot->output_offset
     6822                              + got_offset),
     6823                             (splt->contents + h->plt.offset
     6824                              + elf_sh_plt_symbol_offset (info)));
     6825
     6826          /* Set bottom bit because its for a branch to SHmedia */
     6827          movi_shori_putval (output_bfd,
     6828                             (splt->output_section->vma + splt->output_offset)
     6829                             | 1,
     6830                             (splt->contents + h->plt.offset
     6831                              + elf_sh_plt_plt0_offset (info)));
     6832#else
    40186833          bfd_put_32 (output_bfd,
    40196834                      (sgot->output_section->vma
     
    40276842                      (splt->contents + h->plt.offset
    40286843                       + elf_sh_plt_plt0_offset (info)));
     6844#endif
    40296845        }
    40306846      else
     
    40386854          memcpy (splt->contents + h->plt.offset, elf_sh_pic_plt_entry,
    40396855                  elf_sh_sizeof_plt (info));
     6856#ifdef INCLUDE_SHMEDIA
     6857          movi_shori_putval (output_bfd, got_offset,
     6858                             (splt->contents + h->plt.offset
     6859                              + elf_sh_plt_symbol_offset (info)));
     6860#else
    40406861          bfd_put_32 (output_bfd, got_offset,
    40416862                      (splt->contents + h->plt.offset
    40426863                       + elf_sh_plt_symbol_offset (info)));
     6864#endif
    40436865        }
    40446866
     6867#ifdef GOT_BIAS
     6868      if (info->shared)
     6869        got_offset += GOT_BIAS;
     6870#endif
     6871
     6872#ifdef INCLUDE_SHMEDIA
     6873      movi_shori_putval (output_bfd,
     6874                         plt_index * sizeof (Elf32_External_Rela),
     6875                         (splt->contents + h->plt.offset
     6876                          + elf_sh_plt_reloc_offset (info)));
     6877#else
    40456878      bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
    40466879                  (splt->contents + h->plt.offset
    40476880                   + elf_sh_plt_reloc_offset (info)));
     6881#endif
    40486882
    40496883      /* Fill in the entry in the global offset table.  */
     
    40616895      rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT);
    40626896      rel.r_addend = 0;
    4063       bfd_elf32_swap_reloca_out (output_bfd, &rel,
    4064                                 ((Elf32_External_Rela *) srel->contents
    4065                                  + plt_index));
     6897#ifdef GOT_BIAS
     6898      rel.r_addend = GOT_BIAS;
     6899#endif
     6900      loc = srel->contents + plt_index * sizeof (Elf32_External_Rela);
     6901      bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
    40666902
    40676903      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
     
    40736909    }
    40746910
    4075   if (h->got.offset != (bfd_vma) -1)
     6911  if (h->got.offset != (bfd_vma) -1
     6912      && sh_elf_hash_entry (h)->tls_type != GOT_TLS_GD
     6913      && sh_elf_hash_entry (h)->tls_type != GOT_TLS_IE)
    40766914    {
    40776915      asection *sgot;
    40786916      asection *srel;
    40796917      Elf_Internal_Rela rel;
     6918      bfd_byte *loc;
    40806919
    40816920      /* This symbol has an entry in the global offset table.  Set it
    40826921         up.  */
    40836922
    4084       sgot = bfd_get_section_by_name (dynobj, ".got");
    4085       srel = bfd_get_section_by_name (dynobj, ".rela.got");
     6923      sgot = htab->sgot;
     6924      srel = htab->srelgot;
    40866925      BFD_ASSERT (sgot != NULL && srel != NULL);
    40876926
    40886927      rel.r_offset = (sgot->output_section->vma
    40896928                      + sgot->output_offset
    4090                       + (h->got.offset &~ 1));
    4091 
    4092       /* If this is a -Bsymbolic link, and the symbol is defined
    4093          locally, we just want to emit a RELATIVE reloc.  Likewise if
    4094          the symbol was forced to be local because of a version file.
     6929                      + (h->got.offset &~ (bfd_vma) 1));
     6930
     6931      /* If this is a static link, or it is a -Bsymbolic link and the
     6932         symbol is defined locally or was forced to be local because
     6933         of a version file, we just want to emit a RELATIVE reloc.
    40956934         The entry in the global offset table will already have been
    40966935         initialized in the relocate_section function.  */
    40976936      if (info->shared
    4098           && (info->symbolic || h->dynindx == -1)
     6937          && (info->symbolic
     6938              || h->dynindx == -1
     6939              || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
    40996940          && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
    41006941        {
     
    41116952        }
    41126953
    4113       bfd_elf32_swap_reloca_out (output_bfd, &rel,
    4114                                  ((Elf32_External_Rela *) srel->contents
    4115                                   + srel->reloc_count));
    4116       ++srel->reloc_count;
     6954      loc = srel->contents;
     6955      loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
     6956      bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
    41176957    }
     6958
     6959#ifdef INCLUDE_SHMEDIA
     6960  {
     6961    struct elf_sh_link_hash_entry *eh;
     6962
     6963    eh = (struct elf_sh_link_hash_entry *) h;
     6964    if (eh->datalabel_got.offset != (bfd_vma) -1)
     6965      {
     6966        asection *sgot;
     6967        asection *srel;
     6968        Elf_Internal_Rela rel;
     6969        bfd_byte *loc;
     6970
     6971        /* This symbol has a datalabel entry in the global offset table.
     6972           Set it up.  */
     6973
     6974        sgot = htab->sgot;
     6975        srel = htab->srelgot;
     6976        BFD_ASSERT (sgot != NULL && srel != NULL);
     6977
     6978        rel.r_offset = (sgot->output_section->vma
     6979                        + sgot->output_offset
     6980                        + (eh->datalabel_got.offset &~ (bfd_vma) 1));
     6981
     6982        /* If this is a static link, or it is a -Bsymbolic link and the
     6983           symbol is defined locally or was forced to be local because
     6984           of a version file, we just want to emit a RELATIVE reloc.
     6985           The entry in the global offset table will already have been
     6986           initialized in the relocate_section function.  */
     6987        if (info->shared
     6988            && (info->symbolic
     6989                || h->dynindx == -1
     6990                || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
     6991            && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
     6992          {
     6993            rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
     6994            rel.r_addend = (h->root.u.def.value
     6995                            + h->root.u.def.section->output_section->vma
     6996                            + h->root.u.def.section->output_offset);
     6997          }
     6998        else
     6999          {
     7000            bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents
     7001                        + eh->datalabel_got.offset);
     7002            rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
     7003            rel.r_addend = 0;
     7004          }
     7005
     7006        loc = srel->contents;
     7007        loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
     7008        bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
     7009      }
     7010  }
     7011#endif
    41187012
    41197013  if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
     
    41217015      asection *s;
    41227016      Elf_Internal_Rela rel;
     7017      bfd_byte *loc;
    41237018
    41247019      /* This symbol needs a copy reloc.  Set it up.  */
     
    41377032      rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);
    41387033      rel.r_addend = 0;
    4139       bfd_elf32_swap_reloca_out (output_bfd, &rel,
    4140                                  ((Elf32_External_Rela *) s->contents
    4141                                   + s->reloc_count));
    4142       ++s->reloc_count;
     7034      loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
     7035      bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
    41437036    }
    41447037
     
    41487041    sym->st_shndx = SHN_ABS;
    41497042
    4150   return true;
     7043  return TRUE;
    41517044}
    41527045
    41537046/* Finish up the dynamic sections.  */
    41547047
    4155 static boolean
     7048static bfd_boolean
    41567049sh_elf_finish_dynamic_sections (output_bfd, info)
    41577050     bfd *output_bfd;
    41587051     struct bfd_link_info *info;
    41597052{
     7053  struct elf_sh_link_hash_table *htab;
    41607054  bfd *dynobj;
    41617055  asection *sgot;
    41627056  asection *sdyn;
    41637057
    4164   dynobj = elf_hash_table (info)->dynobj;
    4165 
    4166   sgot = bfd_get_section_by_name (dynobj, ".got.plt");
    4167   BFD_ASSERT (sgot != NULL);
     7058  htab = sh_elf_hash_table (info);
     7059  dynobj = htab->root.dynobj;
     7060
     7061  sgot = htab->sgotplt;
    41687062  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
    41697063
    4170   if (elf_hash_table (info)->dynamic_sections_created)
     7064  if (htab->root.dynamic_sections_created)
    41717065    {
    41727066      asection *splt;
    41737067      Elf32_External_Dyn *dyncon, *dynconend;
    41747068
    4175       BFD_ASSERT (sdyn != NULL);
     7069      BFD_ASSERT (sgot != NULL && sdyn != NULL);
    41767070
    41777071      dyncon = (Elf32_External_Dyn *) sdyn->contents;
     
    41807074        {
    41817075          Elf_Internal_Dyn dyn;
     7076          asection *s;
     7077#ifdef INCLUDE_SHMEDIA
    41827078          const char *name;
    4183           asection *s;
     7079#endif
    41847080
    41857081          bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
     
    41907086              break;
    41917087
     7088#ifdef INCLUDE_SHMEDIA
     7089            case DT_INIT:
     7090              name = info->init_function;
     7091              goto get_sym;
     7092
     7093            case DT_FINI:
     7094              name = info->fini_function;
     7095            get_sym:
     7096              if (dyn.d_un.d_val != 0)
     7097                {
     7098                  struct elf_link_hash_entry *h;
     7099
     7100                  h = elf_link_hash_lookup (&htab->root, name,
     7101                                            FALSE, FALSE, TRUE);
     7102                  if (h != NULL && (h->other & STO_SH5_ISA32))
     7103                    {
     7104                      dyn.d_un.d_val |= 1;
     7105                      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
     7106                    }
     7107                }
     7108              break;
     7109#endif
     7110
    41927111            case DT_PLTGOT:
    4193               name = ".got";
     7112              s = htab->sgot->output_section;
    41947113              goto get_vma;
    41957114
    41967115            case DT_JMPREL:
    4197               name = ".rela.plt";
     7116              s = htab->srelplt->output_section;
    41987117            get_vma:
    4199               s = bfd_get_section_by_name (output_bfd, name);
    42007118              BFD_ASSERT (s != NULL);
    42017119              dyn.d_un.d_ptr = s->vma;
     
    42047122
    42057123            case DT_PLTRELSZ:
    4206               s = bfd_get_section_by_name (output_bfd, ".rela.plt");
     7124              s = htab->srelplt->output_section;
    42077125              BFD_ASSERT (s != NULL);
    42087126              if (s->_cooked_size != 0)
     
    42237141                 other relocation sections, we don't have to worry
    42247142                 about changing the DT_RELA entry.  */
    4225               s = bfd_get_section_by_name (output_bfd, ".rela.plt");
    4226               if (s != NULL)
     7143              if (htab->srelplt != NULL)
    42277144                {
     7145                  s = htab->srelplt->output_section;
    42287146                  if (s->_cooked_size != 0)
    42297147                    dyn.d_un.d_val -= s->_cooked_size;
     
    42377155
    42387156      /* Fill in the first entry in the procedure linkage table.  */
    4239       splt = bfd_get_section_by_name (dynobj, ".plt");
     7157      splt = htab->splt;
    42407158      if (splt && splt->_raw_size > 0)
    42417159        {
     
    42607178                }
    42617179              memcpy (splt->contents, elf_sh_plt0_entry, PLT_ENTRY_SIZE);
     7180#ifdef INCLUDE_SHMEDIA
     7181              movi_shori_putval (output_bfd,
     7182                                 sgot->output_section->vma
     7183                                 + sgot->output_offset,
     7184                                 splt->contents
     7185                                 + elf_sh_plt0_gotplt_offset (info));
     7186#else
    42627187              bfd_put_32 (output_bfd,
    42637188                          sgot->output_section->vma + sgot->output_offset + 4,
     
    42667191                          sgot->output_section->vma + sgot->output_offset + 8,
    42677192                          splt->contents + elf_sh_plt0_linker_offset (info));
     7193#endif
    42687194            }
    42697195
     
    42757201
    42767202  /* Fill in the first three entries in the global offset table.  */
    4277   if (sgot->_raw_size > 0)
     7203  if (sgot && sgot->_raw_size > 0)
    42787204    {
    42797205      if (sdyn == NULL)
     
    42857211      bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
    42867212      bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
     7213
     7214      elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
    42877215    }
    42887216
    4289   elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
    4290 
    4291   return true;
     7217  return TRUE;
    42927218}
    42937219
    4294 #ifndef ELF_ARCH
     7220static enum elf_reloc_type_class
     7221sh_elf_reloc_type_class (rela)
     7222     const Elf_Internal_Rela *rela;
     7223{
     7224  switch ((int) ELF32_R_TYPE (rela->r_info))
     7225    {
     7226    case R_SH_RELATIVE:
     7227      return reloc_class_relative;
     7228    case R_SH_JMP_SLOT:
     7229      return reloc_class_plt;
     7230    case R_SH_COPY:
     7231      return reloc_class_copy;
     7232    default:
     7233      return reloc_class_normal;
     7234    }
     7235}
     7236
     7237/* Support for Linux core dump NOTE sections.  */
     7238static bfd_boolean
     7239elf32_shlin_grok_prstatus (abfd, note)
     7240     bfd *abfd;
     7241     Elf_Internal_Note *note;
     7242{
     7243  int offset;
     7244  unsigned int raw_size;
     7245
     7246  switch (note->descsz)
     7247    {
     7248      default:
     7249        return FALSE;
     7250
     7251      case 168:         /* Linux/SH */
     7252        /* pr_cursig */
     7253        elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
     7254
     7255        /* pr_pid */
     7256        elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
     7257
     7258        /* pr_reg */
     7259        offset = 72;
     7260        raw_size = 92;
     7261
     7262        break;
     7263    }
     7264
     7265  /* Make a ".reg/999" section.  */
     7266  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
     7267                                          raw_size, note->descpos + offset);
     7268}
     7269
     7270static bfd_boolean
     7271elf32_shlin_grok_psinfo (abfd, note)
     7272     bfd *abfd;
     7273     Elf_Internal_Note *note;
     7274{
     7275  switch (note->descsz)
     7276    {
     7277      default:
     7278        return FALSE;
     7279
     7280      case 124:         /* Linux/SH elf_prpsinfo */
     7281        elf_tdata (abfd)->core_program
     7282         = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
     7283        elf_tdata (abfd)->core_command
     7284         = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
     7285    }
     7286
     7287  /* Note that for some reason, a spurious space is tacked
     7288     onto the end of the args in some (at least one anyway)
     7289     implementations, so strip it off if it exists.  */
     7290
     7291  {
     7292    char *command = elf_tdata (abfd)->core_command;
     7293    int n = strlen (command);
     7294
     7295    if (0 < n && command[n - 1] == ' ')
     7296      command[n - 1] = '\0';
     7297  }
     7298
     7299  return TRUE;
     7300}
     7301
    42957302#define TARGET_BIG_SYM          bfd_elf32_sh_vec
    42967303#define TARGET_BIG_NAME         "elf32-sh"
     
    43027309
    43037310#define elf_symbol_leading_char '_'
    4304 #endif /* ELF_ARCH */
    43057311
    43067312#define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
     
    43107316#define bfd_elf32_bfd_get_relocated_section_contents \
    43117317                                        sh_elf_get_relocated_section_contents
    4312 #define elf_backend_object_p            sh_elf_set_mach_from_flags
     7318#define bfd_elf32_mkobject              sh_elf_mkobject
     7319#define elf_backend_object_p            sh_elf_object_p
    43137320#define bfd_elf32_bfd_set_private_bfd_flags \
    43147321                                        sh_elf_set_private_flags
     
    43187325                                        sh_elf_merge_private_data
    43197326
    4320 #define elf_backend_gc_mark_hook        sh_elf_gc_mark_hook
    4321 #define elf_backend_gc_sweep_hook       sh_elf_gc_sweep_hook
    4322 #define elf_backend_check_relocs        sh_elf_check_relocs
    4323 
    4324 #define elf_backend_can_gc_sections     1
     7327#define elf_backend_gc_mark_hook        sh_elf_gc_mark_hook
     7328#define elf_backend_gc_sweep_hook       sh_elf_gc_sweep_hook
     7329#define elf_backend_check_relocs        sh_elf_check_relocs
     7330#define elf_backend_copy_indirect_symbol \
     7331                                        sh_elf_copy_indirect_symbol
    43257332#define elf_backend_create_dynamic_sections \
    43267333                                        sh_elf_create_dynamic_sections
     
    43357342#define elf_backend_finish_dynamic_sections \
    43367343                                        sh_elf_finish_dynamic_sections
    4337 
     7344#define elf_backend_reloc_type_class    sh_elf_reloc_type_class
     7345
     7346#define elf_backend_can_gc_sections     1
     7347#define elf_backend_can_refcount        1
    43387348#define elf_backend_want_got_plt        1
    43397349#define elf_backend_plt_readonly        1
     
    43417351#define elf_backend_got_header_size     12
    43427352#define elf_backend_plt_header_size     PLT_ENTRY_SIZE
     7353
     7354#ifndef INCLUDE_SHMEDIA
     7355
    43437356#include "elf32-target.h"
     7357
     7358/* NetBSD support.  */
     7359#undef  TARGET_BIG_SYM
     7360#define TARGET_BIG_SYM                  bfd_elf32_shnbsd_vec
     7361#undef  TARGET_BIG_NAME
     7362#define TARGET_BIG_NAME                 "elf32-sh-nbsd"
     7363#undef  TARGET_LITTLE_SYM
     7364#define TARGET_LITTLE_SYM               bfd_elf32_shlnbsd_vec
     7365#undef  TARGET_LITTLE_NAME
     7366#define TARGET_LITTLE_NAME              "elf32-shl-nbsd"
     7367#undef  ELF_MAXPAGESIZE
     7368#define ELF_MAXPAGESIZE                 0x10000
     7369#undef  elf_symbol_leading_char
     7370#define elf_symbol_leading_char         0
     7371#undef  elf32_bed
     7372#define elf32_bed                       elf32_sh_nbsd_bed
     7373
     7374#include "elf32-target.h"
     7375
     7376
     7377/* Linux support.  */
     7378#undef  TARGET_BIG_SYM
     7379#define TARGET_BIG_SYM                  bfd_elf32_shblin_vec
     7380#undef  TARGET_BIG_NAME
     7381#define TARGET_BIG_NAME                 "elf32-shbig-linux"
     7382#undef  TARGET_LITTLE_SYM
     7383#define TARGET_LITTLE_SYM               bfd_elf32_shlin_vec
     7384#undef  TARGET_LITTLE_NAME
     7385#define TARGET_LITTLE_NAME              "elf32-sh-linux"
     7386
     7387#undef  elf_backend_grok_prstatus
     7388#define elf_backend_grok_prstatus       elf32_shlin_grok_prstatus
     7389#undef  elf_backend_grok_psinfo
     7390#define elf_backend_grok_psinfo         elf32_shlin_grok_psinfo
     7391#undef  elf32_bed
     7392#define elf32_bed                       elf32_sh_lin_bed
     7393
     7394#include "elf32-target.h"
     7395
     7396#endif /* INCLUDE_SHMEDIA */
Note: See TracChangeset for help on using the changeset viewer.