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-v850.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* V850-specific support for 32-bit ELF
    2    Copyright 1996, 1997, 1998, 1999, 2000, 2001
     2   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
    33   Free Software Foundation, Inc.
    44
    5 This file is part of BFD, the Binary File Descriptor library.
    6 
    7 This program is free software; you can redistribute it and/or modify
    8 it under the terms of the GNU General Public License as published by
    9 the Free Software Foundation; either version 2 of the License, or
    10 (at your option) any later version.
    11 
    12 This program is distributed in the hope that it will be useful,
    13 but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 GNU General Public License for more details.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with this program; if not, write to the Free Software
    19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
     5   This file is part of BFD, the Binary File Descriptor library.
     6
     7   This program is free software; you can redistribute it and/or modify
     8   it under the terms of the GNU General Public License as published by
     9   the Free Software Foundation; either version 2 of the License, or
     10   (at your option) any later version.
     11
     12   This program is distributed in the hope that it will be useful,
     13   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15   GNU General Public License for more details.
     16
     17   You should have received a copy of the GNU General Public License
     18   along with this program; if not, write to the Free Software
     19   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    2020
    2121/* XXX FIXME: This code is littered with 32bit int, 16bit short, 8bit char
    22    dependencies.  As is the gas & simulator code or the v850.  */
     22   dependencies.  As is the gas & simulator code for the v850.  */
    2323
    2424#include "bfd.h"
     
    2828#include "elf-bfd.h"
    2929#include "elf/v850.h"
    30 
    31 /* sign-extend a 24-bit number */
    32 #define SEXT24(x)       ((((x) & 0xffffff) ^ (~ 0x7fffff)) + 0x800000)
     30#include "libiberty.h"
     31
     32/* Sign-extend a 24-bit number.  */
     33#define SEXT24(x)       ((((x) & 0xffffff) ^ 0x800000) - 0x800000)
    3334
    3435static reloc_howto_type *v850_elf_reloc_type_lookup
    3536  PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
    3637static void v850_elf_info_to_howto_rel
    37   PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
     38  PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
    3839static void v850_elf_info_to_howto_rela
    39   PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
     40  PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
    4041static bfd_reloc_status_type v850_elf_reloc
    4142  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
    42 static boolean v850_elf_is_local_label_name
     43static bfd_boolean v850_elf_is_local_label_name
    4344  PARAMS ((bfd *, const char *));
    44 static boolean v850_elf_relocate_section
     45static bfd_boolean v850_elf_relocate_section
    4546  PARAMS((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
    4647          Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
    4748static bfd_reloc_status_type v850_elf_perform_relocation
    48   PARAMS ((bfd *, int, bfd_vma, bfd_byte *));
    49 static boolean v850_elf_check_relocs
     49  PARAMS ((bfd *, unsigned int, bfd_vma, bfd_byte *));
     50static bfd_boolean v850_elf_check_relocs
    5051  PARAMS ((bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *));
    5152static void remember_hi16s_reloc
    5253  PARAMS ((bfd *, bfd_vma, bfd_byte *));
    5354static bfd_byte * find_remembered_hi16s_reloc
    54   PARAMS ((bfd_vma, boolean *));
     55  PARAMS ((bfd_vma, bfd_boolean *));
    5556static bfd_reloc_status_type v850_elf_final_link_relocate
    5657  PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *, bfd_vma,
    5758           bfd_vma, bfd_vma, struct bfd_link_info *, asection *, int));
    58 static boolean v850_elf_object_p
     59static bfd_boolean v850_elf_object_p
    5960  PARAMS ((bfd *));
    60 static boolean v850_elf_fake_sections
    61   PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *));
     61static bfd_boolean v850_elf_fake_sections
     62  PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
    6263static void v850_elf_final_write_processing
    63   PARAMS ((bfd *, boolean));
    64 static boolean v850_elf_set_private_flags
     64  PARAMS ((bfd *, bfd_boolean));
     65static bfd_boolean v850_elf_set_private_flags
    6566  PARAMS ((bfd *, flagword));
    66 static boolean v850_elf_copy_private_bfd_data
     67static bfd_boolean v850_elf_merge_private_bfd_data
    6768  PARAMS ((bfd *, bfd *));
    68 static boolean v850_elf_merge_private_bfd_data
    69   PARAMS ((bfd *, bfd *));
    70 static boolean v850_elf_print_private_bfd_data
     69static bfd_boolean v850_elf_print_private_bfd_data
    7170  PARAMS ((bfd *, PTR));
    72 static boolean v850_elf_section_from_bfd_section
    73   PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *));
     71static bfd_boolean v850_elf_section_from_bfd_section
     72  PARAMS ((bfd *, asection *, int *));
    7473static void v850_elf_symbol_processing
    7574  PARAMS ((bfd *, asymbol *));
    76 static boolean v850_elf_add_symbol_hook
     75static bfd_boolean v850_elf_add_symbol_hook
    7776  PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
    7877           const char **, flagword *, asection **, bfd_vma *));
    79 static boolean v850_elf_link_output_symbol_hook
     78static bfd_boolean v850_elf_link_output_symbol_hook
    8079  PARAMS ((bfd *, struct bfd_link_info *, const char *,
    8180           Elf_Internal_Sym *, asection *));
    82 static boolean v850_elf_section_from_shdr
    83   PARAMS ((bfd *, Elf_Internal_Shdr *, char *));
    84 
    85 /* Note: It is REQUIRED that the 'type' value of each entry in this array
    86    match the index of the entry in the array.  */
     81static bfd_boolean v850_elf_section_from_shdr
     82  PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
     83static bfd_boolean v850_elf_gc_sweep_hook
     84  PARAMS ((bfd *, struct bfd_link_info *, asection *,
     85           const Elf_Internal_Rela *));
     86static asection * v850_elf_gc_mark_hook
     87  PARAMS ((asection *, struct bfd_link_info *,
     88           Elf_Internal_Rela *, struct elf_link_hash_entry *,
     89           Elf_Internal_Sym *));
     90static bfd_reloc_status_type v850_elf_ignore_reloc
     91  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
     92static bfd_boolean v850_elf_relax_delete_bytes
     93  PARAMS ((bfd *, asection *, bfd_vma, bfd_vma, int));
     94static bfd_boolean v850_elf_relax_section
     95  PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
     96
     97/* Note: It is REQUIRED that the 'type' value of each entry
     98   in this array match the index of the entry in the array.  */
    8799static reloc_howto_type v850_elf_howto_table[] =
    88100{
     
    92104         2,                             /* size (0 = byte, 1 = short, 2 = long) */
    93105         32,                            /* bitsize */
    94          false,                         /* pc_relative */
     106         FALSE,                         /* pc_relative */
    95107         0,                             /* bitpos */
    96108         complain_overflow_bitfield,    /* complain_on_overflow */
    97109         bfd_elf_generic_reloc,         /* special_function */
    98110         "R_V850_NONE",                 /* name */
    99          false,                         /* partial_inplace */
     111         FALSE,                         /* partial_inplace */
    100112         0,                             /* src_mask */
    101113         0,                             /* dst_mask */
    102          false),                        /* pcrel_offset */
     114         FALSE),                        /* pcrel_offset */
    103115
    104116  /* A PC relative 9 bit branch.  */
     
    107119         2,                             /* size (0 = byte, 1 = short, 2 = long) */
    108120         26,                            /* bitsize */
    109          true,                          /* pc_relative */
     121         TRUE,                          /* pc_relative */
    110122         0,                             /* bitpos */
    111123         complain_overflow_bitfield,    /* complain_on_overflow */
    112124         v850_elf_reloc,                /* special_function */
    113125         "R_V850_9_PCREL",              /* name */
    114          false,                         /* partial_inplace */
     126         FALSE,                         /* partial_inplace */
    115127         0x00ffffff,                    /* src_mask */
    116128         0x00ffffff,                    /* dst_mask */
    117          true),                         /* pcrel_offset */
     129         TRUE),                         /* pcrel_offset */
    118130
    119131  /* A PC relative 22 bit branch.  */
     
    122134         2,                             /* size (0 = byte, 1 = short, 2 = long) */
    123135         22,                            /* bitsize */
    124          true,                          /* pc_relative */
     136         TRUE,                          /* pc_relative */
    125137         7,                             /* bitpos */
    126138         complain_overflow_signed,      /* complain_on_overflow */
    127139         v850_elf_reloc,                /* special_function */
    128140         "R_V850_22_PCREL",             /* name */
    129          false,                         /* partial_inplace */
     141         FALSE,                         /* partial_inplace */
    130142         0x07ffff80,                    /* src_mask */
    131143         0x07ffff80,                    /* dst_mask */
    132          true),                         /* pcrel_offset */
     144         TRUE),                         /* pcrel_offset */
    133145
    134146  /* High 16 bits of symbol value.  */
     
    137149         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    138150         16,                            /* bitsize */
    139          false,                         /* pc_relative */
     151         FALSE,                         /* pc_relative */
    140152         0,                             /* bitpos */
    141153         complain_overflow_dont,        /* complain_on_overflow */
    142154         v850_elf_reloc,                /* special_function */
    143155         "R_V850_HI16_S",               /* name */
    144          false,                         /* partial_inplace */
     156         FALSE,                         /* partial_inplace */
    145157         0xffff,                        /* src_mask */
    146158         0xffff,                        /* dst_mask */
    147          false),                        /* pcrel_offset */
     159         FALSE),                        /* pcrel_offset */
    148160
    149161  /* High 16 bits of symbol value.  */
     
    152164         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    153165         16,                            /* bitsize */
    154          false,                         /* pc_relative */
     166         FALSE,                         /* pc_relative */
    155167         0,                             /* bitpos */
    156168         complain_overflow_dont,        /* complain_on_overflow */
    157169         v850_elf_reloc,                /* special_function */
    158170         "R_V850_HI16",                 /* name */
    159          false,                         /* partial_inplace */
     171         FALSE,                         /* partial_inplace */
    160172         0xffff,                        /* src_mask */
    161173         0xffff,                        /* dst_mask */
    162          false),                        /* pcrel_offset */
     174         FALSE),                        /* pcrel_offset */
    163175
    164176  /* Low 16 bits of symbol value.  */
     
    167179         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    168180         16,                            /* bitsize */
    169          false,                         /* pc_relative */
     181         FALSE,                         /* pc_relative */
    170182         0,                             /* bitpos */
    171183         complain_overflow_dont,        /* complain_on_overflow */
    172184         v850_elf_reloc,                /* special_function */
    173185         "R_V850_LO16",                 /* name */
    174          false,                         /* partial_inplace */
     186         FALSE,                         /* partial_inplace */
    175187         0xffff,                        /* src_mask */
    176188         0xffff,                        /* dst_mask */
    177          false),                        /* pcrel_offset */
     189         FALSE),                        /* pcrel_offset */
    178190
    179191  /* Simple 32bit reloc.  */
    180   HOWTO (R_V850_32,                     /* type */
     192  HOWTO (R_V850_ABS32,                  /* type */
    181193         0,                             /* rightshift */
    182194         2,                             /* size (0 = byte, 1 = short, 2 = long) */
    183195         32,                            /* bitsize */
    184          false,                         /* pc_relative */
     196         FALSE,                         /* pc_relative */
    185197         0,                             /* bitpos */
    186198         complain_overflow_dont,        /* complain_on_overflow */
    187199         v850_elf_reloc,                /* special_function */
    188          "R_V850_32",                   /* name */
    189          false,                         /* partial_inplace */
     200         "R_V850_ABS32",                /* name */
     201         FALSE,                         /* partial_inplace */
    190202         0xffffffff,                    /* src_mask */
    191203         0xffffffff,                    /* dst_mask */
    192          false),                        /* pcrel_offset */
     204         FALSE),                        /* pcrel_offset */
    193205
    194206  /* Simple 16bit reloc.  */
     
    197209         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    198210         16,                            /* bitsize */
    199          false,                         /* pc_relative */
     211         FALSE,                         /* pc_relative */
    200212         0,                             /* bitpos */
    201213         complain_overflow_dont,        /* complain_on_overflow */
    202214         bfd_elf_generic_reloc,         /* special_function */
    203215         "R_V850_16",                   /* name */
    204          false,                         /* partial_inplace */
     216         FALSE,                         /* partial_inplace */
    205217         0xffff,                        /* src_mask */
    206218         0xffff,                        /* dst_mask */
    207          false),                        /* pcrel_offset */
     219         FALSE),                        /* pcrel_offset */
    208220
    209221  /* Simple 8bit reloc.  */
     
    212224         0,                             /* size (0 = byte, 1 = short, 2 = long) */
    213225         8,                             /* bitsize */
    214          false,                         /* pc_relative */
     226         FALSE,                         /* pc_relative */
    215227         0,                             /* bitpos */
    216228         complain_overflow_dont,        /* complain_on_overflow */
    217229         bfd_elf_generic_reloc,         /* special_function */
    218230         "R_V850_8",                    /* name */
    219          false,                         /* partial_inplace */
     231         FALSE,                         /* partial_inplace */
    220232         0xff,                          /* src_mask */
    221233         0xff,                          /* dst_mask */
    222          false),                        /* pcrel_offset */
     234         FALSE),                        /* pcrel_offset */
    223235
    224236  /* 16 bit offset from the short data area pointer.  */
     
    227239         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    228240         16,                            /* bitsize */
    229          false,                         /* pc_relative */
     241         FALSE,                         /* pc_relative */
    230242         0,                             /* bitpos */
    231243         complain_overflow_dont,        /* complain_on_overflow */
    232244         v850_elf_reloc,                /* special_function */
    233245         "R_V850_SDA_16_16_OFFSET",     /* name */
    234          false,                         /* partial_inplace */
     246         FALSE,                         /* partial_inplace */
    235247         0xffff,                        /* src_mask */
    236248         0xffff,                        /* dst_mask */
    237          false),                        /* pcrel_offset */
     249         FALSE),                        /* pcrel_offset */
    238250
    239251  /* 15 bit offset from the short data area pointer.  */
     
    242254         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    243255         16,                            /* bitsize */
    244          false,                         /* pc_relative */
     256         FALSE,                         /* pc_relative */
    245257         1,                             /* bitpos */
    246258         complain_overflow_dont,        /* complain_on_overflow */
    247259         v850_elf_reloc,                /* special_function */
    248260         "R_V850_SDA_15_16_OFFSET",     /* name */
    249          false,                         /* partial_inplace */
     261         FALSE,                         /* partial_inplace */
    250262         0xfffe,                        /* src_mask */
    251263         0xfffe,                        /* dst_mask */
    252          false),                        /* pcrel_offset */
     264         FALSE),                        /* pcrel_offset */
    253265
    254266  /* 16 bit offset from the zero data area pointer.  */
     
    257269         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    258270         16,                            /* bitsize */
    259          false,                         /* pc_relative */
     271         FALSE,                         /* pc_relative */
    260272         0,                             /* bitpos */
    261273         complain_overflow_dont,        /* complain_on_overflow */
    262274         v850_elf_reloc,                /* special_function */
    263275         "R_V850_ZDA_16_16_OFFSET",     /* name */
    264          false,                         /* partial_inplace */
     276         FALSE,                         /* partial_inplace */
    265277         0xffff,                        /* src_mask */
    266278         0xffff,                        /* dst_mask */
    267          false),                        /* pcrel_offset */
     279         FALSE),                        /* pcrel_offset */
    268280
    269281  /* 15 bit offset from the zero data area pointer.  */
     
    272284         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    273285         16,                            /* bitsize */
    274          false,                         /* pc_relative */
     286         FALSE,                         /* pc_relative */
    275287         1,                             /* bitpos */
    276288         complain_overflow_dont,        /* complain_on_overflow */
    277289         v850_elf_reloc,                /* special_function */
    278290         "R_V850_ZDA_15_16_OFFSET",     /* name */
    279          false,                         /* partial_inplace */
     291         FALSE,                         /* partial_inplace */
    280292         0xfffe,                        /* src_mask */
    281293         0xfffe,                        /* dst_mask */
    282          false),                        /* pcrel_offset */
     294         FALSE),                        /* pcrel_offset */
    283295
    284296  /* 6 bit offset from the tiny data area pointer.  */
     
    287299         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    288300         8,                             /* bitsize */
    289          false,                         /* pc_relative */
     301         FALSE,                         /* pc_relative */
    290302         1,                             /* bitpos */
    291303         complain_overflow_dont,        /* complain_on_overflow */
    292304         v850_elf_reloc,                /* special_function */
    293305         "R_V850_TDA_6_8_OFFSET",       /* name */
    294          false,                         /* partial_inplace */
     306         FALSE,                         /* partial_inplace */
    295307         0x7e,                          /* src_mask */
    296308         0x7e,                          /* dst_mask */
    297          false),                        /* pcrel_offset */
     309         FALSE),                        /* pcrel_offset */
    298310
    299311  /* 8 bit offset from the tiny data area pointer.  */
     
    302314         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    303315         8,                             /* bitsize */
    304          false,                         /* pc_relative */
     316         FALSE,                         /* pc_relative */
    305317         0,                             /* bitpos */
    306318         complain_overflow_dont,        /* complain_on_overflow */
    307319         v850_elf_reloc,                /* special_function */
    308320         "R_V850_TDA_7_8_OFFSET",       /* name */
    309          false,                         /* partial_inplace */
     321         FALSE,                         /* partial_inplace */
    310322         0x7f,                          /* src_mask */
    311323         0x7f,                          /* dst_mask */
    312          false),                        /* pcrel_offset */
     324         FALSE),                        /* pcrel_offset */
    313325
    314326  /* 7 bit offset from the tiny data area pointer.  */
     
    317329         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    318330         7,                             /* bitsize */
    319          false,                         /* pc_relative */
     331         FALSE,                         /* pc_relative */
    320332         0,                             /* bitpos */
    321333         complain_overflow_dont,        /* complain_on_overflow */
    322334         v850_elf_reloc,                /* special_function */
    323335         "R_V850_TDA_7_7_OFFSET",       /* name */
    324          false,                         /* partial_inplace */
     336         FALSE,                         /* partial_inplace */
    325337         0x7f,                          /* src_mask */
    326338         0x7f,                          /* dst_mask */
    327          false),                        /* pcrel_offset */
     339         FALSE),                        /* pcrel_offset */
    328340
    329341  /* 16 bit offset from the tiny data area pointer!  */
     
    332344         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    333345         16,                            /* bitsize */
    334          false,                         /* pc_relative */
     346         FALSE,                         /* pc_relative */
    335347         0,                             /* bitpos */
    336348         complain_overflow_dont,        /* complain_on_overflow */
    337349         v850_elf_reloc,                /* special_function */
    338350         "R_V850_TDA_16_16_OFFSET",     /* name */
    339          false,                         /* partial_inplace */
     351         FALSE,                         /* partial_inplace */
    340352         0xffff,                        /* src_mask */
    341353         0xfff,                         /* dst_mask */
    342          false),                        /* pcrel_offset */
     354         FALSE),                        /* pcrel_offset */
    343355
    344356  /* 5 bit offset from the tiny data area pointer.  */
     
    347359         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    348360         5,                             /* bitsize */
    349          false,                         /* pc_relative */
     361         FALSE,                         /* pc_relative */
    350362         0,                             /* bitpos */
    351363         complain_overflow_dont,        /* complain_on_overflow */
    352364         v850_elf_reloc,                /* special_function */
    353365         "R_V850_TDA_4_5_OFFSET",       /* name */
    354          false,                         /* partial_inplace */
     366         FALSE,                         /* partial_inplace */
    355367         0x0f,                          /* src_mask */
    356368         0x0f,                          /* dst_mask */
    357          false),                        /* pcrel_offset */
     369         FALSE),                        /* pcrel_offset */
    358370
    359371  /* 4 bit offset from the tiny data area pointer.  */
     
    362374         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    363375         4,                             /* bitsize */
    364          false,                         /* pc_relative */
     376         FALSE,                         /* pc_relative */
    365377         0,                             /* bitpos */
    366378         complain_overflow_dont,        /* complain_on_overflow */
    367379         v850_elf_reloc,                /* special_function */
    368380         "R_V850_TDA_4_4_OFFSET",       /* name */
    369          false,                         /* partial_inplace */
     381         FALSE,                         /* partial_inplace */
    370382         0x0f,                          /* src_mask */
    371383         0x0f,                          /* dst_mask */
    372          false),                        /* pcrel_offset */
     384         FALSE),                        /* pcrel_offset */
    373385
    374386  /* 16 bit offset from the short data area pointer.  */
     
    377389         2,                             /* size (0 = byte, 1 = short, 2 = long) */
    378390         16,                            /* bitsize */
    379          false,                         /* pc_relative */
     391         FALSE,                         /* pc_relative */
    380392         0,                             /* bitpos */
    381393         complain_overflow_dont,        /* complain_on_overflow */
    382394         v850_elf_reloc,                /* special_function */
    383395         "R_V850_SDA_16_16_SPLIT_OFFSET",/* name */
    384          false,                         /* partial_inplace */
     396         FALSE,                         /* partial_inplace */
    385397         0xfffe0020,                    /* src_mask */
    386398         0xfffe0020,                    /* dst_mask */
    387          false),                        /* pcrel_offset */
     399         FALSE),                        /* pcrel_offset */
    388400
    389401  /* 16 bit offset from the zero data area pointer.  */
     
    392404         2,                             /* size (0 = byte, 1 = short, 2 = long) */
    393405         16,                            /* bitsize */
    394          false,                         /* pc_relative */
     406         FALSE,                         /* pc_relative */
    395407         0,                             /* bitpos */
    396408         complain_overflow_dont,        /* complain_on_overflow */
    397409         v850_elf_reloc,                /* special_function */
    398410         "R_V850_ZDA_16_16_SPLIT_OFFSET",/* name */
    399          false,                         /* partial_inplace */
     411         FALSE,                         /* partial_inplace */
    400412         0xfffe0020,                    /* src_mask */
    401413         0xfffe0020,                    /* dst_mask */
    402          false),                        /* pcrel_offset */
     414         FALSE),                        /* pcrel_offset */
    403415
    404416  /* 6 bit offset from the call table base pointer.  */
     
    407419         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    408420         7,                             /* bitsize */
    409          false,                         /* pc_relative */
     421         FALSE,                         /* pc_relative */
    410422         0,                             /* bitpos */
    411423         complain_overflow_dont,        /* complain_on_overflow */
    412424         v850_elf_reloc,                /* special_function */
    413425         "R_V850_CALLT_6_7_OFFSET",     /* name */
    414          false,                         /* partial_inplace */
     426         FALSE,                         /* partial_inplace */
    415427         0x3f,                          /* src_mask */
    416428         0x3f,                          /* dst_mask */
    417          false),                        /* pcrel_offset */
     429         FALSE),                        /* pcrel_offset */
    418430
    419431  /* 16 bit offset from the call table base pointer.  */
     
    422434         1,                             /* size (0 = byte, 1 = short, 2 = long) */
    423435         16,                            /* bitsize */
    424          false,                         /* pc_relative */
     436         FALSE,                         /* pc_relative */
    425437         0,                             /* bitpos */
    426438         complain_overflow_dont,        /* complain_on_overflow */
    427439         v850_elf_reloc,                /* special_function */
    428440         "R_V850_CALLT_16_16_OFFSET",   /* name */
    429          false,                         /* partial_inplace */
     441         FALSE,                         /* partial_inplace */
    430442         0xffff,                        /* src_mask */
    431443         0xffff,                        /* dst_mask */
    432          false),                        /* pcrel_offset */
     444         FALSE),                        /* pcrel_offset */
    433445
    434446  /* GNU extension to record C++ vtable hierarchy */
     
    437449         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    438450         0,                     /* bitsize */
    439          false,                 /* pc_relative */
     451         FALSE,                 /* pc_relative */
    440452         0,                     /* bitpos */
    441453         complain_overflow_dont, /* complain_on_overflow */
    442454         NULL,                  /* special_function */
    443455         "R_V850_GNU_VTINHERIT", /* name */
    444          false,                 /* partial_inplace */
     456         FALSE,                 /* partial_inplace */
    445457         0,                     /* src_mask */
    446458         0,                     /* dst_mask */
    447          false),                /* pcrel_offset */
     459         FALSE),                /* pcrel_offset */
    448460
    449461  /* GNU extension to record C++ vtable member usage */
     
    452464         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    453465         0,                     /* bitsize */
    454          false,                 /* pc_relative */
     466         FALSE,                 /* pc_relative */
    455467         0,                     /* bitpos */
    456468         complain_overflow_dont, /* complain_on_overflow */
    457469         _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
    458470         "R_V850_GNU_VTENTRY",   /* name */
    459          false,                 /* partial_inplace */
     471         FALSE,                 /* partial_inplace */
    460472         0,                     /* src_mask */
    461473         0,                     /* dst_mask */
    462          false),                /* pcrel_offset */
    463 
     474         FALSE),                /* pcrel_offset */
     475
     476  /* Indicates a .longcall pseudo-op.  The compiler will generate a .longcall
     477     pseudo-op when it finds a function call which can be relaxed.  */
     478  HOWTO (R_V850_LONGCALL,     /* type */
     479       0,                     /* rightshift */
     480       2,                     /* size (0 = byte, 1 = short, 2 = long) */
     481       32,                    /* bitsize */
     482       TRUE,                  /* pc_relative */
     483       0,                     /* bitpos */
     484       complain_overflow_signed, /* complain_on_overflow */
     485       v850_elf_ignore_reloc, /* special_function */
     486       "R_V850_LONGCALL",     /* name */
     487       FALSE,                 /* partial_inplace */
     488       0,                     /* src_mask */
     489       0,                     /* dst_mask */
     490       TRUE),                 /* pcrel_offset */
     491
     492  /* Indicates a .longjump pseudo-op.  The compiler will generate a
     493     .longjump pseudo-op when it finds a branch which can be relaxed.  */
     494  HOWTO (R_V850_LONGJUMP,     /* type */
     495       0,                     /* rightshift */
     496       2,                     /* size (0 = byte, 1 = short, 2 = long) */
     497       32,                    /* bitsize */
     498       TRUE,                  /* pc_relative */
     499       0,                     /* bitpos */
     500       complain_overflow_signed, /* complain_on_overflow */
     501       v850_elf_ignore_reloc, /* special_function */
     502       "R_V850_LONGJUMP",     /* name */
     503       FALSE,                 /* partial_inplace */
     504       0,                     /* src_mask */
     505       0,                     /* dst_mask */
     506       TRUE),                 /* pcrel_offset */
     507
     508  HOWTO (R_V850_ALIGN,        /* type */
     509       0,                     /* rightshift */
     510       1,                     /* size (0 = byte, 1 = short, 2 = long) */
     511       0,                     /* bitsize */
     512       FALSE,                 /* pc_relative */
     513       0,                     /* bitpos */
     514       complain_overflow_unsigned, /* complain_on_overflow */
     515       v850_elf_ignore_reloc, /* special_function */
     516       "R_V850_ALIGN",        /* name */
     517       FALSE,                 /* partial_inplace */
     518       0,                     /* src_mask */
     519       0,                     /* dst_mask */
     520       TRUE),                 /* pcrel_offset */
     521 
     522  /* Simple pc-relative 32bit reloc.  */
     523  HOWTO (R_V850_REL32,                  /* type */
     524         0,                             /* rightshift */
     525         2,                             /* size (0 = byte, 1 = short, 2 = long) */
     526         32,                            /* bitsize */
     527         TRUE,                          /* pc_relative */
     528         0,                             /* bitpos */
     529         complain_overflow_dont,        /* complain_on_overflow */
     530         v850_elf_reloc,                /* special_function */
     531         "R_V850_REL32",                /* name */
     532         FALSE,                         /* partial_inplace */
     533         0xffffffff,                    /* src_mask */
     534         0xffffffff,                    /* dst_mask */
     535         FALSE),                        /* pcrel_offset */
    464536};
    465537
     
    471543     unsigned char.  */
    472544  bfd_reloc_code_real_type bfd_reloc_val;
    473   unsigned char elf_reloc_val;
     545  unsigned int elf_reloc_val;
    474546};
    475547
    476548static const struct v850_elf_reloc_map v850_elf_reloc_map[] =
    477549{
    478   { BFD_RELOC_NONE,             R_V850_NONE },
    479   { BFD_RELOC_V850_9_PCREL,     R_V850_9_PCREL },
    480   { BFD_RELOC_V850_22_PCREL,    R_V850_22_PCREL },
    481   { BFD_RELOC_HI16_S,           R_V850_HI16_S },
    482   { BFD_RELOC_HI16,             R_V850_HI16 },
    483   { BFD_RELOC_LO16,             R_V850_LO16 },
    484   { BFD_RELOC_32,               R_V850_32 },
    485   { BFD_RELOC_16,               R_V850_16 },
    486   { BFD_RELOC_8,                R_V850_8 },
    487   { BFD_RELOC_V850_SDA_16_16_OFFSET, R_V850_SDA_16_16_OFFSET },
    488   { BFD_RELOC_V850_SDA_15_16_OFFSET, R_V850_SDA_15_16_OFFSET },
    489   { BFD_RELOC_V850_ZDA_16_16_OFFSET, R_V850_ZDA_16_16_OFFSET },
    490   { BFD_RELOC_V850_ZDA_15_16_OFFSET, R_V850_ZDA_15_16_OFFSET },
    491   { BFD_RELOC_V850_TDA_6_8_OFFSET,   R_V850_TDA_6_8_OFFSET   },
    492   { BFD_RELOC_V850_TDA_7_8_OFFSET,   R_V850_TDA_7_8_OFFSET   },
    493   { BFD_RELOC_V850_TDA_7_7_OFFSET,   R_V850_TDA_7_7_OFFSET   },
    494   { BFD_RELOC_V850_TDA_16_16_OFFSET, R_V850_TDA_16_16_OFFSET },
     550  { BFD_RELOC_NONE,                        R_V850_NONE                   },
     551  { BFD_RELOC_V850_9_PCREL,                R_V850_9_PCREL                },
     552  { BFD_RELOC_V850_22_PCREL,               R_V850_22_PCREL               },
     553  { BFD_RELOC_HI16_S,                      R_V850_HI16_S                 },
     554  { BFD_RELOC_HI16,                        R_V850_HI16                   },
     555  { BFD_RELOC_LO16,                        R_V850_LO16                   },
     556  { BFD_RELOC_32,                          R_V850_ABS32                  },
     557  { BFD_RELOC_32_PCREL,                    R_V850_REL32                  },
     558  { BFD_RELOC_16,                          R_V850_16                     },
     559  { BFD_RELOC_8,                           R_V850_8                      },
     560  { BFD_RELOC_V850_SDA_16_16_OFFSET,       R_V850_SDA_16_16_OFFSET       },
     561  { BFD_RELOC_V850_SDA_15_16_OFFSET,       R_V850_SDA_15_16_OFFSET       },
     562  { BFD_RELOC_V850_ZDA_16_16_OFFSET,       R_V850_ZDA_16_16_OFFSET       },
     563  { BFD_RELOC_V850_ZDA_15_16_OFFSET,       R_V850_ZDA_15_16_OFFSET       },
     564  { BFD_RELOC_V850_TDA_6_8_OFFSET,         R_V850_TDA_6_8_OFFSET         },
     565  { BFD_RELOC_V850_TDA_7_8_OFFSET,         R_V850_TDA_7_8_OFFSET         },
     566  { BFD_RELOC_V850_TDA_7_7_OFFSET,         R_V850_TDA_7_7_OFFSET         },
     567  { BFD_RELOC_V850_TDA_16_16_OFFSET,       R_V850_TDA_16_16_OFFSET       },
    495568  { BFD_RELOC_V850_TDA_4_5_OFFSET,         R_V850_TDA_4_5_OFFSET         },
    496569  { BFD_RELOC_V850_TDA_4_4_OFFSET,         R_V850_TDA_4_4_OFFSET         },
     
    499572  { BFD_RELOC_V850_CALLT_6_7_OFFSET,       R_V850_CALLT_6_7_OFFSET       },
    500573  { BFD_RELOC_V850_CALLT_16_16_OFFSET,     R_V850_CALLT_16_16_OFFSET     },
    501   { BFD_RELOC_VTABLE_INHERIT,               R_V850_GNU_VTINHERIT },
    502   { BFD_RELOC_VTABLE_ENTRY,                 R_V850_GNU_VTENTRY },
     574  { BFD_RELOC_VTABLE_INHERIT,              R_V850_GNU_VTINHERIT          },
     575  { BFD_RELOC_VTABLE_ENTRY,                R_V850_GNU_VTENTRY            },
     576  { BFD_RELOC_V850_LONGCALL,               R_V850_LONGCALL               },
     577  { BFD_RELOC_V850_LONGJUMP,               R_V850_LONGJUMP               },
     578  { BFD_RELOC_V850_ALIGN,                  R_V850_ALIGN                  },
    503579
    504580};
    505581
    506582
    507 /* Map a bfd relocation into the appropriate howto structure */
     583/* Map a bfd relocation into the appropriate howto structure.  */
     584
    508585static reloc_howto_type *
    509586v850_elf_reloc_type_lookup (abfd, code)
    510      bfd *                     abfd ATTRIBUTE_UNUSED;
    511      bfd_reloc_code_real_type  code;
     587     bfd *abfd ATTRIBUTE_UNUSED;
     588     bfd_reloc_code_real_type code;
    512589{
    513590  unsigned int i;
    514591
    515   for (i = 0;
    516        i < sizeof (v850_elf_reloc_map) / sizeof (struct v850_elf_reloc_map);
    517        i++)
    518     {
    519       if (v850_elf_reloc_map[i].bfd_reloc_val == code)
    520         {
    521           BFD_ASSERT (v850_elf_howto_table[v850_elf_reloc_map[i].elf_reloc_val].type == v850_elf_reloc_map[i].elf_reloc_val);
    522 
    523           return & v850_elf_howto_table[v850_elf_reloc_map[i].elf_reloc_val];
    524         }
    525     }
     592  for (i = ARRAY_SIZE (v850_elf_reloc_map); i --;)
     593    if (v850_elf_reloc_map[i].bfd_reloc_val == code)
     594      {
     595        unsigned int elf_reloc_val = v850_elf_reloc_map[i].elf_reloc_val;
     596
     597        BFD_ASSERT (v850_elf_howto_table[elf_reloc_val].type == elf_reloc_val);
     598
     599        return v850_elf_howto_table + elf_reloc_val;
     600      }
    526601
    527602  return NULL;
     
    530605
    531606/* Set the howto pointer for an V850 ELF reloc.  */
     607
    532608static void
    533609v850_elf_info_to_howto_rel (abfd, cache_ptr, dst)
    534      bfd *                 abfd ATTRIBUTE_UNUSED;
    535      arelent *             cache_ptr;
    536      Elf32_Internal_Rel *  dst;
     610     bfd *abfd ATTRIBUTE_UNUSED;
     611     arelent *cache_ptr;
     612     Elf_Internal_Rela *dst;
    537613{
    538614  unsigned int r_type;
     
    546622static void
    547623v850_elf_info_to_howto_rela (abfd, cache_ptr, dst)
    548      bfd *                 abfd ATTRIBUTE_UNUSED;
    549      arelent *             cache_ptr;
    550      Elf32_Internal_Rela  *dst;
     624     bfd *abfd ATTRIBUTE_UNUSED;
     625     arelent * cache_ptr;
     626     Elf_Internal_Rela *dst;
    551627{
    552628  unsigned int r_type;
     
    562638   table.  */
    563639
    564 static boolean
     640static bfd_boolean
    565641v850_elf_check_relocs (abfd, info, sec, relocs)
    566      bfd *                      abfd;
    567      struct bfd_link_info *     info;
    568      asection *                 sec;
    569      const Elf_Internal_Rela *  relocs;
     642     bfd *abfd;
     643     struct bfd_link_info *info;
     644     asection *sec;
     645     const Elf_Internal_Rela *relocs;
    570646{
    571   boolean ret = true;
     647  bfd_boolean ret = TRUE;
    572648  bfd *dynobj;
    573649  Elf_Internal_Shdr *symtab_hdr;
     
    581657
    582658  if (info->relocateable)
    583     return true;
     659    return TRUE;
    584660
    585661#ifdef DEBUG
    586662  fprintf (stderr, "v850_elf_check_relocs called for section %s in %s\n",
    587663           bfd_get_section_name (abfd, sec),
    588            bfd_get_filename (abfd));
     664           bfd_archive_filename (abfd));
    589665#endif
    590666
     
    616692        case R_V850_HI16:
    617693        case R_V850_LO16:
    618         case R_V850_32:
     694        case R_V850_ABS32:
     695        case R_V850_REL32:
    619696        case R_V850_16:
    620697        case R_V850_8:
     
    627704        case R_V850_GNU_VTINHERIT:
    628705          if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
    629             return false;
     706            return FALSE;
    630707          break;
    631708
    632         /* This relocation describes which C++ vtable entries are actually
    633           used.  Record for later use during GC.  */
     709        /* This relocation describes which C++ vtable entries
     710           are actually used.  Record for later use during GC.  */
    634711        case R_V850_GNU_VTENTRY:
    635712          if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
    636             return false;
     713            return FALSE;
    637714          break;
    638715
     
    666743          if (h)
    667744            {
    668               h->other |= other;        /* flag which type of relocation was used */
     745              /* Flag which type of relocation was used.  */
     746              h->other |= other;
    669747              if ((h->other & V850_OTHER_MASK) != (other & V850_OTHER_MASK)
    670748                  && (h->other & V850_OTHER_ERROR) == 0)
     
    694772                  sprintf (buff, msg, h->root.root.string);
    695773                  info->callbacks->warning (info, buff, h->root.root.string,
    696                                             abfd, h->root.u.def.section, 0);
     774                                            abfd, h->root.u.def.section,
     775                                            (bfd_vma) 0);
    697776
    698777                  bfd_set_error (bfd_error_bad_value);
    699778                  h->other |= V850_OTHER_ERROR;
    700                   ret = false;
     779                  ret = FALSE;
    701780                }
    702781            }
     
    706785              && !strcmp (bfd_get_section_name (abfd, h->root.u.c.p->section), "COMMON"))
    707786            {
    708               asection *section = h->root.u.c.p->section = bfd_make_section_old_way (abfd, common);
     787              asection * section;
     788
     789              section = h->root.u.c.p->section = bfd_make_section_old_way (abfd, common);
    709790              section->flags |= SEC_IS_COMMON;
    710791            }
     
    723804}
    724805
    725 /*
    726  * In the old version, when an entry was checked out from the table,
    727  * it was deleted.  This produced an error if the entry was needed
    728  * more than once, as the second attempted retry failed.
    729  *
    730  * In the current version, the entry is not deleted, instead we set
    731  * the field 'found' to true.  If a second lookup matches the same
    732  * entry, then we know that the hi16s reloc has already been updated
    733  * and does not need to be updated a second time.
    734  *
    735  * TODO - TOFIX: If it is possible that we need to restore 2 different
    736  * addresses from the same table entry, where the first generates an
    737  * overflow, whilst the second do not, then this code will fail.
    738  */
     806/* In the old version, when an entry was checked out from the table,
     807   it was deleted.  This produced an error if the entry was needed
     808   more than once, as the second attempted retry failed.
     809
     810   In the current version, the entry is not deleted, instead we set
     811   the field 'found' to TRUE.  If a second lookup matches the same
     812   entry, then we know that the hi16s reloc has already been updated
     813   and does not need to be updated a second time.
     814
     815   TODO - TOFIX: If it is possible that we need to restore 2 different
     816   addresses from the same table entry, where the first generates an
     817   overflow, whilst the second do not, then this code will fail.  */
    739818
    740819typedef struct hi16s_location
    741820{
    742   bfd_vma       addend;
    743   bfd_byte *    address;
     821  bfd_vma addend;
     822  bfd_byte *address;
    744823  unsigned long counter;
    745   boolean      found;
    746   struct hi16s_location * next;
     824  bfd_boolean found;
     825  struct hi16s_location *next;
    747826}
    748827hi16s_location;
    749828
    750 static hi16s_location *  previous_hi16s;
    751 static hi16s_location *  free_hi16s;
    752 static unsigned long     hi16s_counter;
     829static hi16s_location *previous_hi16s;
     830static hi16s_location *free_hi16s;
     831static unsigned long hi16s_counter;
    753832
    754833static void
    755834remember_hi16s_reloc (abfd, addend, address)
    756      bfd *      abfd;
    757      bfd_vma    addend;
    758      bfd_byte * address;
     835     bfd *abfd;
     836     bfd_vma addend;
     837     bfd_byte *address;
    759838{
    760839  hi16s_location * entry = NULL;
     840  bfd_size_type amt = sizeof (* free_hi16s);
    761841
    762842  /* Find a free structure.  */
    763843  if (free_hi16s == NULL)
    764     free_hi16s = (hi16s_location *) bfd_zalloc (abfd, sizeof (* free_hi16s));
     844    free_hi16s = (hi16s_location *) bfd_zalloc (abfd, amt);
    765845
    766846  entry      = free_hi16s;
     
    770850  entry->address = address;
    771851  entry->counter = hi16s_counter ++;
    772   entry->found   = false;
     852  entry->found   = FALSE;
    773853  entry->next    = previous_hi16s;
    774854  previous_hi16s = entry;
     
    789869static bfd_byte *
    790870find_remembered_hi16s_reloc (addend, already_found)
    791      bfd_vma   addend;
    792      boolean * already_found;
     871     bfd_vma addend;
     872     bfd_boolean *already_found;
    793873{
    794   hi16s_location * match = NULL;
    795   hi16s_location * entry;
    796   hi16s_location * previous = NULL;
    797   hi16s_location * prev;
    798   bfd_byte *       addr;
     874  hi16s_location *match = NULL;
     875  hi16s_location *entry;
     876  hi16s_location *previous = NULL;
     877  hi16s_location *prev;
     878  bfd_byte *addr;
    799879
    800880  /* Search the table.  Record the most recent entry that matches.  */
     
    822902
    823903  /* Note that this entry has now been used.  */
    824   match->found = true;
     904  match->found = TRUE;
    825905
    826906  return addr;
     
    829909/* FIXME:  The code here probably ought to be removed and the code in reloc.c
    830910   allowed to do its  stuff instead.  At least for most of the relocs, anwyay.  */
     911
    831912static bfd_reloc_status_type
    832913v850_elf_perform_relocation (abfd, r_type, addend, address)
    833      bfd *      abfd;
    834      int        r_type;
    835      bfd_vma    addend;
    836      bfd_byte * address;
     914     bfd *abfd;
     915     unsigned int r_type;
     916     bfd_vma addend;
     917     bfd_byte *address;
    837918{
    838919  unsigned long insn;
     
    845926      return bfd_reloc_notsupported;
    846927
    847     case R_V850_32:
     928    case R_V850_REL32:
     929    case R_V850_ABS32:
    848930      bfd_put_32 (abfd, addend, address);
    849931      return bfd_reloc_ok;
     
    859941      insn &= ~0xfffe003f;
    860942      insn |= (((addend & 0xfffe) << 16) | ((addend & 0x3f0000) >> 16));
    861       bfd_put_32 (abfd, insn, address);
     943      bfd_put_32 (abfd, (bfd_vma) insn, address);
    862944      return bfd_reloc_ok;
    863945
     
    10331115           + 0x00006fff   (bit 15 not set, so the top half is zero)
    10341116           ------------
    1035              0x00006fff   which is wrong (assuming that fred is at 0xffff)
    1036          */
    1037 
     1117             0x00006fff   which is wrong (assuming that fred is at 0xffff).  */
    10381118      {
    10391119        long result;
     
    10491129                && ((! BIT15_SET (insn)) || (BIT15_SET (addend)))))
    10501130          {
    1051             boolean already_updated;
    1052             bfd_byte * hi16s_address = find_remembered_hi16s_reloc
     1131            bfd_boolean already_updated;
     1132            bfd_byte *hi16s_address = find_remembered_hi16s_reloc
    10531133              (addend, & already_updated);
    10541134
     
    10601140                    insn = bfd_get_16 (abfd, hi16s_address);
    10611141                    insn += 1;
    1062                     bfd_put_16 (abfd, insn, hi16s_address);
     1142                    bfd_put_16 (abfd, (bfd_vma) insn, hi16s_address);
    10631143                  }
    10641144              }
     
    11261206        return bfd_reloc_dangerous;
    11271207
    1128       insn = (addend & ~1) | (insn & 1);
     1208      insn = (addend &~ (bfd_vma) 1) | (insn & 1);
    11291209      break;
    11301210
     
    12151295      insn &= 0x0001ffdf;
    12161296      insn |= (addend & 1) << 5;
    1217       insn |= (addend & ~1) << 16;
    1218 
    1219       bfd_put_32 (abfd, insn, address);
     1297      insn |= (addend &~ (bfd_vma) 1) << 16;
     1298
     1299      bfd_put_32 (abfd, (bfd_vma) insn, address);
    12201300      return bfd_reloc_ok;
    12211301
     
    12421322    }
    12431323
    1244   bfd_put_16 (abfd, insn, address);
     1324  bfd_put_16 (abfd, (bfd_vma) insn, address);
    12451325  return bfd_reloc_ok;
    12461326}
     
    12481328
    12491329/* Insert the addend into the instruction.  */
     1330
    12501331static bfd_reloc_status_type
    12511332v850_elf_reloc (abfd, reloc, symbol, data, isection, obfd, err)
    1252      bfd *       abfd ATTRIBUTE_UNUSED;
    1253      arelent *   reloc;
    1254      asymbol *   symbol;
    1255      PTR         data ATTRIBUTE_UNUSED;
    1256      asection *  isection;
    1257      bfd *       obfd;
    1258      char **     err ATTRIBUTE_UNUSED;
     1333     bfd *abfd ATTRIBUTE_UNUSED;
     1334     arelent *reloc;
     1335     asymbol *symbol;
     1336     PTR data ATTRIBUTE_UNUSED;
     1337     asection *isection;
     1338     bfd *obfd;
     1339     char **err ATTRIBUTE_UNUSED;
    12591340{
    12601341  long relocation;
     
    12631344     and the symbol is not a section name (which is only defined at final link time),
    12641345     and either we are not putting the addend into the instruction
    1265          or the addend is zero, so there is nothing to add into the instruction
     1346      or the addend is zero, so there is nothing to add into the instruction
    12661347     then just fixup the address and return.  */
    12671348  if (obfd != (bfd *) NULL
     
    12731354      return bfd_reloc_ok;
    12741355    }
    1275 #if 0
    1276   else if (obfd != NULL)
    1277     {
    1278       return bfd_reloc_continue;
    1279     }
    1280 #endif
    12811356
    12821357  /* Catch relocs involving undefined symbols.  */
     
    12951370     initial relocation command value.  */
    12961371
     1372  if (reloc->howto->pc_relative)
     1373    return bfd_reloc_ok;
     1374
    12971375  /* Get symbol value.  (Common symbols are special.)  */
    12981376  if (bfd_is_com_section (symbol->section))
     
    13131391                .globl _start
    13141392                nop
    1315         _start:         
     1393        _start:
    13161394                jr foo
    13171395
     
    13191397                nop
    13201398        foo:
    1321                 nop
    1322       */
    1323   if (reloc->howto->pc_relative == true)
     1399                nop      */
     1400  if (reloc->howto->pc_relative)
    13241401    {
    13251402      /* Here the variable relocation holds the final address of the
     
    13271404      relocation -= isection->output_section->vma + isection->output_offset;
    13281405
    1329       /* Deal with pcrel_offset */
     1406      /* Deal with pcrel_offset. */
    13301407      relocation -= reloc->address;
    13311408    }
     
    13351412}
    13361413
    1337 
    1338 static boolean
     1414/* This function is used for relocs which are only used
     1415   for relaxing, which the linker should otherwise ignore.  */
     1416
     1417static bfd_reloc_status_type
     1418v850_elf_ignore_reloc (abfd, reloc_entry, symbol, data, input_section,
     1419                       output_bfd, error_message)
     1420     bfd *abfd ATTRIBUTE_UNUSED;
     1421     arelent *reloc_entry;
     1422     asymbol *symbol ATTRIBUTE_UNUSED;
     1423     PTR data ATTRIBUTE_UNUSED;
     1424     asection *input_section;
     1425     bfd *output_bfd;
     1426     char **error_message ATTRIBUTE_UNUSED;
     1427{
     1428  if (output_bfd != NULL)
     1429    reloc_entry->address += input_section->output_offset;
     1430
     1431  return bfd_reloc_ok;
     1432}
     1433
     1434
     1435static bfd_boolean
    13391436v850_elf_is_local_label_name (abfd, name)
    1340      bfd *         abfd ATTRIBUTE_UNUSED;
    1341      const char *  name;
     1437     bfd *abfd ATTRIBUTE_UNUSED;
     1438     const char *name;
    13421439{
    13431440  return (   (name[0] == '.' && (name[1] == 'L' || name[1] == '.'))
     
    13461443
    13471444
     1445/* We overload some of the bfd_reloc error codes for own purposes.  */
     1446#define bfd_reloc_gp_not_found          bfd_reloc_other
     1447#define bfd_reloc_ep_not_found          bfd_reloc_continue
     1448#define bfd_reloc_ctbp_not_found        (bfd_reloc_dangerous + 1)
     1449
    13481450/* Perform a relocation as part of a final link.  */
     1451
    13491452static bfd_reloc_status_type
    13501453v850_elf_final_link_relocate (howto, input_bfd, output_bfd,
    1351                                     input_section, contents, offset, value,
    1352                                     addend, info, sym_sec, is_local)
    1353      reloc_howto_type *      howto;
    1354      bfd *                   input_bfd;
    1355      bfd *                   output_bfd ATTRIBUTE_UNUSED;
    1356      asection *              input_section;
    1357      bfd_byte *              contents;
    1358      bfd_vma                 offset;
    1359      bfd_vma                 value;
    1360      bfd_vma                 addend;
    1361      struct bfd_link_info *  info;
    1362      asection *              sym_sec;
    1363      int                     is_local ATTRIBUTE_UNUSED;
     1454                              input_section, contents, offset, value,
     1455                              addend, info, sym_sec, is_local)
     1456     reloc_howto_type *howto;
     1457     bfd *input_bfd;
     1458     bfd *output_bfd ATTRIBUTE_UNUSED;
     1459     asection *input_section;
     1460     bfd_byte *contents;
     1461     bfd_vma offset;
     1462     bfd_vma value;
     1463     bfd_vma addend;
     1464     struct bfd_link_info *info;
     1465     asection *sym_sec;
     1466     int is_local ATTRIBUTE_UNUSED;
    13641467{
    1365   unsigned long  r_type  = howto->type;
    1366   bfd_byte *     hit_data = contents + offset;
     1468  unsigned int r_type = howto->type;
     1469  bfd_byte *hit_data = contents + offset;
    13671470
    13681471  /* Adjust the value according to the relocation.  */
     
    13841487        return bfd_reloc_overflow;
    13851488
    1386       value = SEXT24 (value);  /* Only the bottom 24 bits of the PC are valid */
     1489      /* Only the bottom 24 bits of the PC are valid */
     1490      value = SEXT24 (value);
     1491      break;
     1492
     1493    case R_V850_REL32:
     1494      value -= (input_section->output_section->vma
     1495                + input_section->output_offset
     1496                + offset);
    13871497      break;
    13881498
     
    13911501    case R_V850_LO16:
    13921502    case R_V850_16:
    1393     case R_V850_32:
     1503    case R_V850_ABS32:
    13941504    case R_V850_8:
    13951505      break;
     
    14151525
    14161526        /* Get the value of __gp.  */
    1417         h = bfd_link_hash_lookup (info->hash, "__gp", false, false, true);
     1527        h = bfd_link_hash_lookup (info->hash, "__gp", FALSE, FALSE, TRUE);
    14181528        if (h == (struct bfd_link_hash_entry *) NULL
    14191529            || h->type != bfd_link_hash_defined)
    1420           return bfd_reloc_other;
     1530          return bfd_reloc_gp_not_found;
    14211531
    14221532        gp = (h->u.def.value
     
    14401550
    14411551        /* Get the value of __ep.  */
    1442         h = bfd_link_hash_lookup (info->hash, "__ep", false, false, true);
     1552        h = bfd_link_hash_lookup (info->hash, "__ep", FALSE, FALSE, TRUE);
    14431553        if (h == (struct bfd_link_hash_entry *) NULL
    14441554            || h->type != bfd_link_hash_defined)
    1445           return bfd_reloc_continue;  /* Actually this indicates that __ep could not be found.  */
     1555          return bfd_reloc_ep_not_found;
    14461556
    14471557        ep = (h->u.def.value
     
    14591569
    14601570        /* Get the value of __ctbp.  */
    1461         h = bfd_link_hash_lookup (info->hash, "__ctbp", false, false, true);
     1571        h = bfd_link_hash_lookup (info->hash, "__ctbp", FALSE, FALSE, TRUE);
    14621572        if (h == (struct bfd_link_hash_entry *) NULL
    14631573            || h->type != bfd_link_hash_defined)
    1464           return (bfd_reloc_dangerous + 1);  /* Actually this indicates that __ctbp could not be found.  */
     1574          return bfd_reloc_ctbp_not_found;
    14651575
    14661576        ctbp = (h->u.def.value
     
    14801590
    14811591        /* Get the value of __ctbp.  */
    1482         h = bfd_link_hash_lookup (info->hash, "__ctbp", false, false, true);
     1592        h = bfd_link_hash_lookup (info->hash, "__ctbp", FALSE, FALSE, TRUE);
    14831593        if (h == (struct bfd_link_hash_entry *) NULL
    14841594            || h->type != bfd_link_hash_defined)
    1485           return (bfd_reloc_dangerous + 1);
     1595          return bfd_reloc_ctbp_not_found;
    14861596
    14871597        ctbp = (h->u.def.value
     
    14971607    case R_V850_GNU_VTINHERIT:
    14981608    case R_V850_GNU_VTENTRY:
     1609    case R_V850_LONGCALL:
     1610    case R_V850_LONGJUMP:
     1611    case R_V850_ALIGN:
    14991612      return bfd_reloc_ok;
    15001613
     
    15091622
    15101623/* Relocate an V850 ELF section.  */
    1511 static boolean
     1624
     1625static bfd_boolean
    15121626v850_elf_relocate_section (output_bfd, info, input_bfd, input_section,
    15131627                           contents, relocs, local_syms, local_sections)
    1514      bfd *                  output_bfd;
    1515      struct bfd_link_info * info;
    1516      bfd *                  input_bfd;
    1517      asection *             input_section;
    1518      bfd_byte *             contents;
    1519      Elf_Internal_Rela *    relocs;
    1520      Elf_Internal_Sym *     local_syms;
    1521      asection **            local_sections;
     1628     bfd *output_bfd;
     1629     struct bfd_link_info *info;
     1630     bfd *input_bfd;
     1631     asection *input_section;
     1632     bfd_byte *contents;
     1633     Elf_Internal_Rela *relocs;
     1634     Elf_Internal_Sym *local_syms;
     1635     asection **local_sections;
    15221636{
    1523   Elf_Internal_Shdr *           symtab_hdr;
    1524   struct elf_link_hash_entry ** sym_hashes;
    1525   Elf_Internal_Rela *           rel;
    1526   Elf_Internal_Rela *           relend;
     1637  Elf_Internal_Shdr *symtab_hdr;
     1638  struct elf_link_hash_entry **sym_hashes;
     1639  Elf_Internal_Rela *rel;
     1640  Elf_Internal_Rela *relend;
     1641
     1642  if (info->relocateable)
     1643    return TRUE;
    15271644
    15281645  symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
     
    15321649    {
    15331650      info->callbacks->warning
    1534         (info, "no hash table available", NULL, input_bfd, input_section, 0);
    1535 
    1536       return false;
     1651        (info, "no hash table available",
     1652         NULL, input_bfd, input_section, (bfd_vma) 0);
     1653
     1654      return FALSE;
    15371655    }
    15381656
     
    15461664  for (; rel < relend; rel++)
    15471665    {
    1548       int                          r_type;
    1549       reloc_howto_type *           howto;
    1550       unsigned long                r_symndx;
    1551       Elf_Internal_Sym *           sym;
    1552       asection *                   sec;
    1553       struct elf_link_hash_entry * h;
    1554       bfd_vma                      relocation;
    1555       bfd_reloc_status_type        r;
     1666      int r_type;
     1667      reloc_howto_type *howto;
     1668      unsigned long r_symndx;
     1669      Elf_Internal_Sym *sym;
     1670      asection *sec;
     1671      struct elf_link_hash_entry *h;
     1672      bfd_vma relocation;
     1673      bfd_reloc_status_type r;
    15561674
    15571675      r_symndx = ELF32_R_SYM (rel->r_info);
     
    15621680        continue;
    15631681
     1682      /* This is a final link.  */
    15641683      howto = v850_elf_howto_table + r_type;
    1565 
    1566       if (info->relocateable)
    1567         {
    1568           /* This is a relocateable link.  We don't have to change
    1569              anything, unless the reloc is against a section symbol,
    1570              in which case we have to adjust according to where the
    1571              section symbol winds up in the output section.  */
    1572           if (r_symndx < symtab_hdr->sh_info)
    1573             {
    1574               sym = local_syms + r_symndx;
    1575               if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
    1576                 {
    1577                   sec = local_sections[r_symndx];
    1578                   rel->r_addend += sec->output_offset + sym->st_value;
    1579                 }
    1580             }
    1581 
    1582           continue;
    1583         }
    1584 
    1585       /* This is a final link.  */
    15861684      h = NULL;
    15871685      sym = NULL;
     
    15911689          sym = local_syms + r_symndx;
    15921690          sec = local_sections[r_symndx];
    1593           relocation = (sec->output_section->vma
    1594                         + sec->output_offset
    1595                         + sym->st_value);
     1691          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
    15961692#if 0
    15971693          {
    15981694            char * name;
     1695
    15991696            name = bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link, sym->st_name);
    16001697            name = (name == NULL) ? "<none>" : name;
    1601 fprintf (stderr, "local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
    1602         sec->name, name, sym->st_name,
    1603         sec->output_section->vma, sec->output_offset, sym->st_value, rel->r_addend);
     1698            fprintf (stderr, "local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
     1699                    sec->name, name, sym->st_name,
     1700                    sec->output_section->vma, sec->output_offset, sym->st_value, rel->r_addend);
    16041701          }
    16051702#endif
     
    16211718                            + sec->output_offset);
    16221719#if 0
    1623 fprintf (stderr, "defined: sec: %s, name: %s, value: %x + %x + %x gives: %x\n",
    1624         sec->name, h->root.root.string, h->root.u.def.value, sec->output_section->vma, sec->output_offset, relocation);
     1720              fprintf (stderr, "defined: sec: %s, name: %s, value: %x + %x + %x gives: %x\n",
     1721                      sec->name, h->root.root.string, h->root.u.def.value, sec->output_section->vma, sec->output_offset, relocation);
    16251722#endif
    16261723            }
     
    16281725            {
    16291726#if 0
    1630 fprintf (stderr, "undefined: sec: %s, name: %s\n",
    1631         sec->name, h->root.root.string);
     1727              fprintf (stderr, "undefined: sec: %s, name: %s\n",
     1728                      sec->name, h->root.root.string);
    16321729#endif
    16331730              relocation = 0;
     
    16371734              if (! ((*info->callbacks->undefined_symbol)
    16381735                     (info, h->root.root.string, input_bfd,
    1639                       input_section, rel->r_offset, true)))
    1640                 return false;
     1736                      input_section, rel->r_offset, TRUE)))
     1737                return FALSE;
    16411738#if 0
    1642 fprintf (stderr, "unknown: name: %s\n", h->root.root.string);
     1739              fprintf (stderr, "unknown: name: %s\n", h->root.root.string);
    16431740#endif
    16441741              relocation = 0;
     
    16461743        }
    16471744
    1648       /* FIXME: We should use the addend, but the COFF relocations
    1649          don't.  */
     1745      /* FIXME: We should use the addend, but the COFF relocations don't.  */
    16501746      r = v850_elf_final_link_relocate (howto, input_bfd, output_bfd,
    16511747                                        input_section,
     
    16751771                     (info, name, howto->name, (bfd_vma) 0,
    16761772                      input_bfd, input_section, rel->r_offset)))
    1677                 return false;
     1773                return FALSE;
    16781774              break;
    16791775
     
    16811777              if (! ((*info->callbacks->undefined_symbol)
    16821778                     (info, name, input_bfd, input_section,
    1683                       rel->r_offset, true)))
    1684                 return false;
     1779                      rel->r_offset, TRUE)))
     1780                return FALSE;
    16851781              break;
    16861782
     
    16971793              goto common_error;
    16981794
    1699             case bfd_reloc_other:
     1795            case bfd_reloc_gp_not_found:
    17001796              msg = _("could not locate special linker symbol __gp");
    17011797              goto common_error;
    17021798
    1703             case bfd_reloc_continue:
     1799            case bfd_reloc_ep_not_found:
    17041800              msg = _("could not locate special linker symbol __ep");
    17051801              goto common_error;
    17061802
    1707             case (bfd_reloc_dangerous + 1):
     1803            case bfd_reloc_ctbp_not_found:
    17081804              msg = _("could not locate special linker symbol __ctbp");
    17091805              goto common_error;
     
    17171813                    (info, msg, name, input_bfd, input_section,
    17181814                     rel->r_offset)))
    1719                 return false;
     1815                return FALSE;
    17201816              break;
    17211817            }
     
    17231819    }
    17241820
    1725   return true;
     1821  return TRUE;
    17261822}
    17271823
    1728 static boolean
     1824static bfd_boolean
    17291825v850_elf_gc_sweep_hook (abfd, info, sec, relocs)
    17301826     bfd *abfd ATTRIBUTE_UNUSED;
     
    17331829     const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
    17341830{
    1735   /* No got and plt entries for v850-elf */
    1736   return true;
     1831  /* No got and plt entries for v850-elf. */
     1832  return TRUE;
    17371833}
    17381834
    17391835static asection *
    1740 v850_elf_gc_mark_hook (abfd, info, rel, h, sym)
    1741        bfd *abfd;
     1836v850_elf_gc_mark_hook (sec, info, rel, h, sym)
     1837       asection *sec;
    17421838       struct bfd_link_info *info ATTRIBUTE_UNUSED;
    17431839       Elf_Internal_Rela *rel;
     
    17691865     }
    17701866   else
    1771      {
    1772        if (!(elf_bad_symtab (abfd)
    1773            && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
    1774          && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
    1775                 && sym->st_shndx != SHN_COMMON))
    1776           {
    1777             return bfd_section_from_elf_index (abfd, sym->st_shndx);
    1778           }
    1779       }
     1867     return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
     1868
    17801869  return NULL;
    17811870}
     1871
    17821872/* Set the right machine number.  */
    1783 static boolean
     1873
     1874static bfd_boolean
    17841875v850_elf_object_p (abfd)
    17851876     bfd *abfd;
     
    17881879    {
    17891880    default:
    1790     case E_V850_ARCH:   (void) bfd_default_set_arch_mach (abfd, bfd_arch_v850, 0); break;
    1791     case E_V850E_ARCH:  (void) bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850e); break;
    1792     case E_V850EA_ARCH: (void) bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850ea); break;
     1881    case E_V850_ARCH:
     1882      bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850);
     1883      break;
     1884    case E_V850E_ARCH:
     1885      bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850e);
     1886      break;
    17931887    }
    1794   return true;
     1888  return TRUE;
    17951889}
    17961890
    17971891/* Store the machine number in the flags field.  */
     1892
    17981893static void
    17991894v850_elf_final_write_processing (abfd, linker)
    1800      bfd *   abfd;
    1801      boolean linker ATTRIBUTE_UNUSED;
     1895     bfd *abfd;
     1896     bfd_boolean linker ATTRIBUTE_UNUSED;
    18021897{
    18031898  unsigned long val;
     
    18061901    {
    18071902    default:
    1808     case 0: val = E_V850_ARCH; break;
    1809     case bfd_mach_v850e:  val = E_V850E_ARCH; break;
    1810     case bfd_mach_v850ea: val = E_V850EA_ARCH;  break;
     1903    case bfd_mach_v850:  val = E_V850_ARCH; break;
     1904    case bfd_mach_v850e: val = E_V850E_ARCH; break;
    18111905    }
    18121906
     
    18161910
    18171911/* Function to keep V850 specific file flags.  */
    1818 static boolean
     1912
     1913static bfd_boolean
    18191914v850_elf_set_private_flags (abfd, flags)
    1820      bfd *    abfd;
     1915     bfd *abfd;
    18211916     flagword flags;
    18221917{
     
    18251920
    18261921  elf_elfheader (abfd)->e_flags = flags;
    1827   elf_flags_init (abfd) = true;
    1828   return true;
     1922  elf_flags_init (abfd) = TRUE;
     1923  return TRUE;
    18291924}
    18301925
    1831 /* Copy backend specific data from one object module to another */
    1832 static boolean
    1833 v850_elf_copy_private_bfd_data (ibfd, obfd)
    1834      bfd * ibfd;
    1835      bfd * obfd;
    1836 {
    1837   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    1838       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    1839     return true;
    1840 
    1841   BFD_ASSERT (!elf_flags_init (obfd)
    1842               || (elf_elfheader (obfd)->e_flags
    1843                   == elf_elfheader (ibfd)->e_flags));
    1844 
    1845   elf_gp (obfd) = elf_gp (ibfd);
    1846   elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
    1847   elf_flags_init (obfd) = true;
    1848   return true;
    1849 }
    1850 
    1851 /* Merge backend specific data from an object file to the output
    1852    object file when linking.  */
    1853 static boolean
     1926/* Merge backend specific data from an object file
     1927   to the output object file when linking.  */
     1928static bfd_boolean
    18541929v850_elf_merge_private_bfd_data (ibfd, obfd)
    1855      bfd * ibfd;
    1856      bfd * obfd;
     1930     bfd *ibfd;
     1931     bfd *obfd;
    18571932{
    18581933  flagword out_flags;
     
    18611936  if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    18621937      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    1863     return true;
     1938    return TRUE;
    18641939
    18651940  in_flags = elf_elfheader (ibfd)->e_flags;
     
    18751950         to the default values.  */
    18761951      if (bfd_get_arch_info (ibfd)->the_default)
    1877         return true;
    1878 
    1879       elf_flags_init (obfd) = true;
     1952        return TRUE;
     1953
     1954      elf_flags_init (obfd) = TRUE;
    18801955      elf_elfheader (obfd)->e_flags = in_flags;
    18811956
    18821957      if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
    18831958          && bfd_get_arch_info (obfd)->the_default)
    1884         {
    1885           return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
    1886         }
    1887 
    1888       return true;
     1959        return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
     1960
     1961      return TRUE;
    18891962    }
    18901963
    18911964  /* Check flag compatibility.  */
    18921965  if (in_flags == out_flags)
    1893     return true;
     1966    return TRUE;
    18941967
    18951968  if ((in_flags & EF_V850_ARCH) != (out_flags & EF_V850_ARCH)
    18961969      && (in_flags & EF_V850_ARCH) != E_V850_ARCH)
    18971970    _bfd_error_handler (_("%s: Architecture mismatch with previous modules"),
    1898                         bfd_get_filename (ibfd));
    1899 
    1900   return true;
     1971                        bfd_archive_filename (ibfd));
     1972
     1973  return TRUE;
    19011974}
    1902 /* Display the flags field */
    1903 
    1904 static boolean
     1975
     1976/* Display the flags field.  */
     1977
     1978static bfd_boolean
    19051979v850_elf_print_private_bfd_data (abfd, ptr)
    1906      bfd *   abfd;
    1907      PTR     ptr;
     1980     bfd *abfd;
     1981     PTR ptr;
    19081982{
    19091983  FILE * file = (FILE *) ptr;
     
    19211995    case E_V850_ARCH: fprintf (file, _("v850 architecture")); break;
    19221996    case E_V850E_ARCH:  fprintf (file, _("v850e architecture")); break;
    1923     case E_V850EA_ARCH: fprintf (file, _("v850ea architecture")); break;
    19241997    }
    19251998
    19261999  fputc ('\n', file);
    19272000
    1928   return true;
     2001  return TRUE;
    19292002}
    19302003
     
    19462019static asymbol * v850_elf_zcom_symbol_ptr;
    19472020
    1948 /* Given a BFD section, try to locate the corresponding ELF section
    1949    index.  */
    1950 
    1951 static boolean
    1952 v850_elf_section_from_bfd_section (abfd, hdr, sec, retval)
    1953      bfd *                 abfd ATTRIBUTE_UNUSED;
    1954      Elf32_Internal_Shdr * hdr ATTRIBUTE_UNUSED;
    1955      asection *            sec;
    1956      int *                 retval;
     2021/* Given a BFD section, try to locate the
     2022   corresponding ELF section index.  */
     2023
     2024static bfd_boolean
     2025v850_elf_section_from_bfd_section (abfd, sec, retval)
     2026     bfd *abfd ATTRIBUTE_UNUSED;
     2027     asection *sec;
     2028     int *retval;
    19572029{
    19582030  if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
     
    19632035    *retval = SHN_V850_ZCOMMON;
    19642036  else
    1965     return false;
    1966 
    1967   return true;
     2037    return FALSE;
     2038
     2039  return TRUE;
    19682040}
    19692041
     
    19722044static void
    19732045v850_elf_symbol_processing (abfd, asym)
    1974      bfd *     abfd;
    1975      asymbol * asym;
     2046     bfd *abfd;
     2047     asymbol *asym;
    19762048{
    19772049  elf_symbol_type * elfsym = (elf_symbol_type *) asym;
    1978   unsigned short index;
    1979 
    1980   index = elfsym->internal_elf_sym.st_shndx;
     2050  unsigned int indx;
     2051
     2052  indx = elfsym->internal_elf_sym.st_shndx;
    19812053
    19822054  /* If the section index is an "ordinary" index, then it may
     
    19862058     FIXME: Should we alter the st_shndx field as well ?  */
    19872059
    1988   if (index < elf_elfheader(abfd)[0].e_shnum)
    1989     switch (elf_elfsections(abfd)[index]->sh_type)
     2060  if (indx < elf_numsections (abfd))
     2061    switch (elf_elfsections(abfd)[indx]->sh_type)
    19902062      {
    19912063      case SHT_V850_SCOMMON:
    1992         index = SHN_V850_SCOMMON;
     2064        indx = SHN_V850_SCOMMON;
    19932065        break;
    19942066
    19952067      case SHT_V850_TCOMMON:
    1996         index = SHN_V850_TCOMMON;
     2068        indx = SHN_V850_TCOMMON;
    19972069        break;
    19982070
    19992071      case SHT_V850_ZCOMMON:
    2000         index = SHN_V850_ZCOMMON;
     2072        indx = SHN_V850_ZCOMMON;
    20012073        break;
    20022074
     
    20052077      }
    20062078
    2007   switch (index)
     2079  switch (indx)
    20082080    {
    20092081    case SHN_V850_SCOMMON:
     
    20662138   file.  We must handle the special v850 section numbers here.  */
    20672139
    2068 static boolean
     2140static bfd_boolean
    20692141v850_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
    2070      bfd *                    abfd;
    2071      struct bfd_link_info *   info ATTRIBUTE_UNUSED;
    2072      const Elf_Internal_Sym * sym;
    2073      const char **            namep ATTRIBUTE_UNUSED;
    2074      flagword *               flagsp ATTRIBUTE_UNUSED;
    2075      asection **              secp;
    2076      bfd_vma *                valp;
     2142     bfd *abfd;
     2143     struct bfd_link_info *info ATTRIBUTE_UNUSED;
     2144     const Elf_Internal_Sym *sym;
     2145     const char **namep ATTRIBUTE_UNUSED;
     2146     flagword *flagsp ATTRIBUTE_UNUSED;
     2147     asection **secp;
     2148     bfd_vma *valp;
    20772149{
    2078   int index = sym->st_shndx;
     2150  unsigned int indx = sym->st_shndx;
    20792151
    20802152  /* If the section index is an "ordinary" index, then it may
     
    20842156     FIXME: Should we alter the st_shndx field as well ?  */
    20852157
    2086   if (index < elf_elfheader(abfd)[0].e_shnum)
    2087     switch (elf_elfsections(abfd)[index]->sh_type)
     2158  if (indx < elf_numsections (abfd))
     2159    switch (elf_elfsections(abfd)[indx]->sh_type)
    20882160      {
    20892161      case SHT_V850_SCOMMON:
    2090         index = SHN_V850_SCOMMON;
     2162        indx = SHN_V850_SCOMMON;
    20912163        break;
    20922164
    20932165      case SHT_V850_TCOMMON:
    2094         index = SHN_V850_TCOMMON;
     2166        indx = SHN_V850_TCOMMON;
    20952167        break;
    20962168
    20972169      case SHT_V850_ZCOMMON:
    2098         index = SHN_V850_ZCOMMON;
     2170        indx = SHN_V850_ZCOMMON;
    20992171        break;
    21002172
     
    21032175      }
    21042176
    2105   switch (index)
     2177  switch (indx)
    21062178    {
    21072179    case SHN_V850_SCOMMON:
     
    21242196    }
    21252197
    2126   return true;
     2198  return TRUE;
    21272199}
    21282200
    2129 /*ARGSIGNORED*/
    2130 static boolean
     2201static bfd_boolean
    21312202v850_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec)
    2132      bfd *                  abfd ATTRIBUTE_UNUSED;
    2133      struct bfd_link_info * info ATTRIBUTE_UNUSED;
    2134      const char *           name ATTRIBUTE_UNUSED;
    2135      Elf_Internal_Sym *     sym;
    2136      asection *             input_sec;
     2203     bfd *abfd ATTRIBUTE_UNUSED;
     2204     struct bfd_link_info *info ATTRIBUTE_UNUSED;
     2205     const char *name ATTRIBUTE_UNUSED;
     2206     Elf_Internal_Sym *sym;
     2207     asection *input_sec;
    21372208{
    21382209  /* If we see a common symbol, which implies a relocatable link, then
     
    21502221    }
    21512222
    2152   return true;
     2223  return TRUE;
    21532224}
    21542225
    2155 static boolean
     2226static bfd_boolean
    21562227v850_elf_section_from_shdr (abfd, hdr, name)
    2157      bfd *               abfd;
    2158      Elf_Internal_Shdr * hdr;
    2159      char *              name;
     2228     bfd *abfd;
     2229     Elf_Internal_Shdr *hdr;
     2230     const char *name;
    21602231{
    21612232  /* There ought to be a place to keep ELF backend specific flags, but
     
    21642235
    21652236  if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
    2166     return false;
     2237    return FALSE;
    21672238
    21682239  switch (hdr->sh_type)
     
    21752246                                                           hdr->bfd_section)
    21762247                                    | SEC_IS_COMMON)))
    2177         return false;
     2248        return FALSE;
    21782249    }
    21792250
    2180   return true;
     2251  return TRUE;
    21812252}
    21822253
    2183 /* Set the correct type for a V850 ELF section.  We do this by the
    2184    section name, which is a hack, but ought to work.  */
    2185 static boolean
     2254/* Set the correct type for a V850 ELF section.  We do this
     2255   by the section name, which is a hack, but ought to work.  */
     2256
     2257static bfd_boolean
    21862258v850_elf_fake_sections (abfd, hdr, sec)
    2187      bfd *                 abfd ATTRIBUTE_UNUSED;
    2188      Elf32_Internal_Shdr * hdr;
    2189      asection *            sec;
     2259     bfd *abfd ATTRIBUTE_UNUSED;
     2260     Elf_Internal_Shdr *hdr;
     2261     asection *sec;
    21902262{
    21912263  register const char * name;
     
    22042276    hdr->sh_type = SHT_V850_ZCOMMON;
    22052277
    2206   return true;
     2278  return TRUE;
     2279}
     2280
     2281/* Delete some bytes from a section while relaxing.  */
     2282
     2283static bfd_boolean
     2284v850_elf_relax_delete_bytes (abfd, sec, addr, toaddr, count)
     2285     bfd *abfd;
     2286     asection *sec;
     2287     bfd_vma addr;
     2288     bfd_vma toaddr;
     2289     int count;
     2290{
     2291  Elf_Internal_Shdr *symtab_hdr;
     2292  Elf32_External_Sym *extsyms;
     2293  Elf32_External_Sym *esym;
     2294  Elf32_External_Sym *esymend;
     2295  int index;
     2296  unsigned int sec_shndx;
     2297  bfd_byte *contents;
     2298  Elf_Internal_Rela *irel;
     2299  Elf_Internal_Rela *irelend;
     2300  struct elf_link_hash_entry *sym_hash;
     2301  Elf_Internal_Shdr *shndx_hdr;
     2302  Elf_External_Sym_Shndx *shndx;
     2303
     2304  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     2305  extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
     2306
     2307  sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
     2308
     2309  contents = elf_section_data (sec)->this_hdr.contents;
     2310
     2311  /* The deletion must stop at the next ALIGN reloc for an alignment
     2312     power larger than the number of bytes we are deleting.  */
     2313
     2314  /* Actually delete the bytes.  */
     2315#if (DEBUG_RELAX & 2)
     2316  fprintf (stderr, "relax_delete: contents: sec: %s  %p .. %p %x\n",
     2317           sec->name, addr, toaddr, count );
     2318#endif
     2319  memmove (contents + addr, contents + addr + count,
     2320           toaddr - addr - count);
     2321  memset (contents + toaddr-count, 0, count);
     2322
     2323  /* Adjust all the relocs.  */
     2324  irel = elf_section_data (sec)->relocs;
     2325  irelend = irel + sec->reloc_count;
     2326  shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
     2327  shndx = (Elf_External_Sym_Shndx *) shndx_hdr->contents;
     2328
     2329  for (; irel < irelend; irel++)
     2330    {
     2331      bfd_vma raddr, paddr, symval;
     2332      Elf_Internal_Sym isym;
     2333
     2334      /* Get the new reloc address.  */
     2335      raddr = irel->r_offset;
     2336      if ((raddr >= (addr + count) && raddr < toaddr))
     2337        irel->r_offset -= count;
     2338
     2339      if (raddr >= addr && raddr < addr + count)
     2340        {
     2341          irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
     2342                                       (int) R_V850_NONE);
     2343          continue;
     2344        }
     2345
     2346      if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN)
     2347        continue;
     2348
     2349      bfd_elf32_swap_symbol_in (abfd,
     2350                                extsyms + ELF32_R_SYM (irel->r_info),
     2351                                shndx ? shndx + ELF32_R_SYM (irel->r_info) : NULL,
     2352                                & isym);
     2353
     2354      if (isym.st_shndx != sec_shndx)
     2355        continue;
     2356
     2357      /* Get the value of the symbol referred to by the reloc.  */
     2358      if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
     2359        {
     2360          symval = isym.st_value;
     2361#if (DEBUG_RELAX & 2)
     2362          {
     2363            char * name = bfd_elf_string_from_elf_section
     2364                           (abfd, symtab_hdr->sh_link, isym.st_name);
     2365            fprintf (stderr,
     2366               "relax_delete: local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
     2367               sec->name, name, isym.st_name,
     2368               sec->output_section->vma, sec->output_offset,
     2369               isym.st_value, irel->r_addend);
     2370          }
     2371#endif
     2372        }
     2373      else
     2374        {
     2375          unsigned long indx;
     2376          struct elf_link_hash_entry * h;
     2377
     2378          /* An external symbol.  */
     2379          indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
     2380
     2381          h = elf_sym_hashes (abfd) [indx];
     2382          BFD_ASSERT (h != NULL);
     2383
     2384          symval = h->root.u.def.value;
     2385#if (DEBUG_RELAX & 2)
     2386          fprintf (stderr,
     2387                   "relax_delete: defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
     2388                   sec->name, h->root.root.string, h->root.u.def.value,
     2389                   sec->output_section->vma, sec->output_offset, irel->r_addend);
     2390#endif
     2391        }
     2392
     2393      paddr = symval + irel->r_addend;
     2394
     2395      if ( (symval >= addr + count && symval < toaddr)
     2396          && (paddr < addr + count || paddr >= toaddr))
     2397        irel->r_addend += count;
     2398      else if (    (symval < addr + count || symval >= toaddr)
     2399                && (paddr >= addr + count && paddr < toaddr))
     2400        irel->r_addend -= count;
     2401    }
     2402
     2403  /* Adjust the local symbols defined in this section.  */
     2404  esym = extsyms;
     2405  esymend = esym + symtab_hdr->sh_info;
     2406
     2407  for (; esym < esymend; esym++, shndx = (shndx ? shndx + 1 : NULL))
     2408    {
     2409      Elf_Internal_Sym isym;
     2410
     2411      bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
     2412
     2413      if (isym.st_shndx == sec_shndx
     2414          && isym.st_value >= addr + count
     2415          && isym.st_value < toaddr)
     2416        {
     2417          isym.st_value -= count;
     2418
     2419          if (isym.st_value + isym.st_size >= toaddr)
     2420            isym.st_size += count;
     2421
     2422          bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
     2423        }
     2424      else if (isym.st_shndx == sec_shndx
     2425               && isym.st_value < addr + count)
     2426        {
     2427          if (isym.st_value+isym.st_size >= addr + count
     2428              && isym.st_value+isym.st_size < toaddr)
     2429            isym.st_size -= count;
     2430
     2431          if (isym.st_value >= addr
     2432              && isym.st_value <  addr + count)
     2433            isym.st_value = addr;
     2434
     2435          bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
     2436        }
     2437    }
     2438
     2439  /* Now adjust the global symbols defined in this section.  */
     2440  esym = extsyms + symtab_hdr->sh_info;
     2441  esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
     2442
     2443  for (index = 0; esym < esymend; esym ++, index ++)
     2444    {
     2445      Elf_Internal_Sym isym;
     2446
     2447      bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
     2448      sym_hash = elf_sym_hashes (abfd) [index];
     2449
     2450      if (isym.st_shndx == sec_shndx
     2451          && ((sym_hash)->root.type == bfd_link_hash_defined
     2452              || (sym_hash)->root.type == bfd_link_hash_defweak)
     2453          && (sym_hash)->root.u.def.section == sec
     2454          && (sym_hash)->root.u.def.value >= addr + count
     2455          && (sym_hash)->root.u.def.value < toaddr)
     2456        {
     2457          if ((sym_hash)->root.u.def.value + isym.st_size >= toaddr)
     2458            {
     2459              isym.st_size += count;
     2460              bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
     2461            }
     2462
     2463          (sym_hash)->root.u.def.value -= count;
     2464        }
     2465      else if (isym.st_shndx == sec_shndx
     2466               && ((sym_hash)->root.type == bfd_link_hash_defined
     2467                   || (sym_hash)->root.type == bfd_link_hash_defweak)
     2468               && (sym_hash)->root.u.def.section == sec
     2469               && (sym_hash)->root.u.def.value < addr + count)
     2470        {
     2471          if ((sym_hash)->root.u.def.value+isym.st_size >= addr + count
     2472              && (sym_hash)->root.u.def.value+isym.st_size < toaddr)
     2473            isym.st_size -= count;
     2474
     2475          if ((sym_hash)->root.u.def.value >= addr
     2476              && (sym_hash)->root.u.def.value < addr + count)
     2477            (sym_hash)->root.u.def.value = addr;
     2478
     2479          bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
     2480        }
     2481
     2482      if (shndx)
     2483        ++ shndx;
     2484    }
     2485
     2486  return TRUE;
     2487}
     2488
     2489#define NOP_OPCODE      (0x0000)
     2490#define MOVHI           0x0640                          /* 4byte */
     2491#define MOVHI_MASK      0x07e0
     2492#define MOVHI_R1(insn)  ((insn) & 0x1f)                 /* 4byte */
     2493#define MOVHI_R2(insn)  ((insn) >> 11)
     2494#define MOVEA           0x0620                          /* 2byte */
     2495#define MOVEA_MASK      0x07e0
     2496#define MOVEA_R1(insn)  ((insn) & 0x1f)
     2497#define MOVEA_R2(insn)  ((insn) >> 11)
     2498#define JARL_4          0x00040780                              /* 4byte */
     2499#define JARL_4_MASK     0xFFFF07FF
     2500#define JARL_R2(insn)   (int)(((insn) & (~JARL_4_MASK)) >> 11)
     2501#define ADD_I           0x0240                                  /* 2byte */
     2502#define ADD_I_MASK      0x07e0
     2503#define ADD_I5(insn)    ((((insn) & 0x001f) << 11) >> 11)       /* 2byte */
     2504#define ADD_R2(insn)    ((insn) >> 11)
     2505#define JMP_R           0x0060                                  /* 2byte */
     2506#define JMP_R_MASK      0xFFE0
     2507#define JMP_R1(insn)    ((insn) & 0x1f)
     2508
     2509static bfd_boolean
     2510v850_elf_relax_section (abfd, sec, link_info, again)
     2511     bfd *abfd;
     2512     asection *sec;
     2513     struct bfd_link_info *link_info;
     2514     bfd_boolean *again;
     2515{
     2516  Elf_Internal_Shdr *symtab_hdr;
     2517  Elf_Internal_Rela *internal_relocs;
     2518  Elf_Internal_Rela *irel;
     2519  Elf_Internal_Rela *irelend;
     2520  Elf_Internal_Rela *irelalign = NULL;
     2521  Elf_Internal_Sym *isymbuf = NULL;
     2522  bfd_byte *contents = NULL;
     2523  bfd_vma addr = 0;
     2524  bfd_vma toaddr;
     2525  int align_pad_size = 0;
     2526  bfd_boolean result = TRUE;
     2527
     2528  *again = FALSE;
     2529
     2530  if (link_info->relocateable
     2531      || (sec->flags & SEC_RELOC) == 0
     2532      || sec->reloc_count == 0)
     2533    return TRUE;
     2534
     2535  /* If this is the first time we have been called
     2536     for this section, initialize the cooked size.  */
     2537  if (sec->_cooked_size == 0)
     2538    sec->_cooked_size = sec->_raw_size;
     2539
     2540  symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
     2541
     2542  internal_relocs = (_bfd_elf32_link_read_relocs
     2543                     (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
     2544                      link_info->keep_memory));
     2545  if (internal_relocs == NULL)
     2546    goto error_return;
     2547
     2548  irelend = internal_relocs + sec->reloc_count;
     2549
     2550  while (addr < sec->_cooked_size)
     2551    {
     2552      toaddr = sec->_cooked_size;
     2553
     2554      for (irel = internal_relocs; irel < irelend; irel ++)
     2555        if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
     2556            && irel->r_offset > addr
     2557            && irel->r_offset < toaddr)
     2558          toaddr = irel->r_offset;
     2559
     2560#ifdef DEBUG_RELAX
     2561      fprintf (stderr, "relax region 0x%x to 0x%x align pad %d\n",
     2562               addr, toaddr, align_pad_size);
     2563#endif
     2564      if (irelalign)
     2565        {
     2566          bfd_vma alignto;
     2567          bfd_vma alignmoveto;
     2568
     2569          alignmoveto = BFD_ALIGN (addr - align_pad_size, 1 << irelalign->r_addend);
     2570          alignto = BFD_ALIGN (addr, 1 << irelalign->r_addend);
     2571
     2572          if (alignmoveto < alignto)
     2573            {
     2574              unsigned int i;
     2575
     2576              align_pad_size = alignto - alignmoveto;
     2577#ifdef DEBUG_RELAX
     2578              fprintf (stderr, "relax move region 0x%x to 0x%x delete size 0x%x\n",
     2579                       alignmoveto, toaddr, align_pad_size);
     2580#endif
     2581              if (!v850_elf_relax_delete_bytes (abfd, sec, alignmoveto,
     2582                                                toaddr, align_pad_size))
     2583                goto error_return;
     2584
     2585              for (i  = BFD_ALIGN (toaddr - align_pad_size, 1);
     2586                   (i + 1) < toaddr; i += 2)
     2587                bfd_put_16 (abfd, NOP_OPCODE, contents + i);
     2588
     2589              addr = alignmoveto;
     2590            }
     2591          else
     2592            align_pad_size = 0;
     2593        }
     2594
     2595      for (irel = internal_relocs; irel < irelend; irel++)
     2596        {
     2597          bfd_vma laddr;
     2598          bfd_vma addend;
     2599          bfd_vma symval;
     2600          int insn[5];
     2601          int no_match = -1;
     2602          Elf_Internal_Rela *hi_irelfn;
     2603          Elf_Internal_Rela *lo_irelfn;
     2604          Elf_Internal_Rela *irelcall;
     2605          bfd_signed_vma foff;
     2606
     2607          if (! (irel->r_offset >= addr && irel->r_offset < toaddr
     2608                 && (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL
     2609                     || ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)))
     2610            continue;
     2611
     2612#ifdef DEBUG_RELAX
     2613          fprintf (stderr, "relax check r_info 0x%x r_offset 0x%x r_addend 0x%x\n",
     2614                   irel->r_info,
     2615                   irel->r_offset,
     2616                   irel->r_addend );
     2617#endif
     2618
     2619          /* Get the section contents.  */
     2620          if (contents == NULL)
     2621            {
     2622              if (elf_section_data (sec)->this_hdr.contents != NULL)
     2623                contents = elf_section_data (sec)->this_hdr.contents;
     2624              else
     2625                {
     2626                  contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
     2627                  if (contents == NULL)
     2628                    goto error_return;
     2629
     2630                  if (! bfd_get_section_contents (abfd, sec, contents,
     2631                                                  (file_ptr) 0, sec->_raw_size))
     2632                    goto error_return;
     2633                }
     2634            }
     2635
     2636          /* Read this BFD's local symbols if we haven't done so already.  */
     2637          if (isymbuf == NULL && symtab_hdr->sh_info != 0)
     2638            {
     2639              isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
     2640              if (isymbuf == NULL)
     2641                isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
     2642                                                symtab_hdr->sh_info, 0,
     2643                                                NULL, NULL, NULL);
     2644              if (isymbuf == NULL)
     2645                goto error_return;
     2646            }
     2647
     2648          laddr = irel->r_offset;
     2649
     2650          if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL)
     2651            {
     2652              /* Check code for -mlong-calls output. */
     2653              if (laddr + 16 <= (bfd_vma) sec->_raw_size)
     2654                {
     2655                  insn[0] = bfd_get_16 (abfd, contents + laddr);
     2656                  insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
     2657                  insn[2] = bfd_get_32 (abfd, contents + laddr + 8);
     2658                  insn[3] = bfd_get_16 (abfd, contents + laddr + 12);
     2659                  insn[4] = bfd_get_16 (abfd, contents + laddr + 14);
     2660
     2661                  if ((insn[0] & MOVHI_MASK) != MOVHI
     2662                       || MOVHI_R1 (insn[0]) != 0)
     2663                    no_match = 0;
     2664
     2665                  if (no_match < 0
     2666                      && ((insn[1] & MOVEA_MASK) != MOVEA
     2667                           || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
     2668                    no_match = 1;
     2669
     2670                  if (no_match < 0
     2671                      && (insn[2] & JARL_4_MASK) != JARL_4)
     2672                    no_match = 2;
     2673
     2674                  if (no_match < 0
     2675                      && ((insn[3] & ADD_I_MASK) != ADD_I
     2676                           || ADD_I5 (insn[3]) != 4
     2677                           || JARL_R2 (insn[2]) != ADD_R2 (insn[3])))
     2678                    no_match = 3;
     2679
     2680                  if (no_match < 0
     2681                      && ((insn[4] & JMP_R_MASK) != JMP_R
     2682                           || MOVEA_R2 (insn[1]) != JMP_R1 (insn[4])))
     2683                    no_match = 4;
     2684                }
     2685              else
     2686                {
     2687                  ((*_bfd_error_handler)
     2688                   ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized insns",
     2689                    bfd_get_filename (abfd), (unsigned long) irel->r_offset));
     2690
     2691                  continue;
     2692                }
     2693
     2694              if (no_match >= 0)
     2695                {
     2696                  ((*_bfd_error_handler)
     2697                   ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized insn 0x%x",
     2698                    bfd_get_filename (abfd), (unsigned long) irel->r_offset+no_match, insn[no_match]));
     2699
     2700                  continue;
     2701                }
     2702
     2703              /* Get the reloc for the address from which the register is
     2704                 being loaded.  This reloc will tell us which function is
     2705                 actually being called.  */
     2706              for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
     2707                if (hi_irelfn->r_offset == laddr + 2
     2708                    && ELF32_R_TYPE (hi_irelfn->r_info)
     2709                        == (int) R_V850_HI16_S)
     2710                  break;
     2711
     2712              for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
     2713                if (lo_irelfn->r_offset == laddr + 6
     2714                    && ELF32_R_TYPE (lo_irelfn->r_info)
     2715                        == (int) R_V850_LO16)
     2716                  break;
     2717
     2718              for (irelcall = internal_relocs; irelcall < irelend; irelcall ++)
     2719                if (irelcall->r_offset == laddr + 8
     2720                    && ELF32_R_TYPE (irelcall->r_info)
     2721                        == (int) R_V850_22_PCREL)
     2722                  break;
     2723
     2724              if (   hi_irelfn == irelend
     2725                  || lo_irelfn == irelend
     2726                  || irelcall  == irelend)
     2727                {
     2728                  ((*_bfd_error_handler)
     2729                   ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized reloc",
     2730                    bfd_get_filename (abfd), (unsigned long) irel->r_offset ));
     2731
     2732                  continue;
     2733                }
     2734
     2735              if (ELF32_R_SYM (irelcall->r_info) < symtab_hdr->sh_info)
     2736                {
     2737                  Elf_Internal_Sym *  isym;
     2738
     2739                  /* A local symbol.  */
     2740                  isym = isymbuf + ELF32_R_SYM (irelcall->r_info);
     2741
     2742                  symval = isym->st_value;
     2743                }
     2744              else
     2745                {
     2746                  unsigned long indx;
     2747                  struct elf_link_hash_entry * h;
     2748
     2749                  /* An external symbol.  */
     2750                  indx = ELF32_R_SYM (irelcall->r_info) - symtab_hdr->sh_info;
     2751                  h = elf_sym_hashes (abfd)[indx];
     2752                  BFD_ASSERT (h != NULL);
     2753
     2754                  if (   h->root.type != bfd_link_hash_defined
     2755                      && h->root.type != bfd_link_hash_defweak)
     2756                    /* This appears to be a reference to an undefined
     2757                       symbol.  Just ignore it--it will be caught by the
     2758                       regular reloc processing.  */
     2759                    continue;
     2760
     2761                  symval = h->root.u.def.value;
     2762                }
     2763
     2764              if (symval + irelcall->r_addend != irelcall->r_offset + 4)
     2765                {
     2766                  ((*_bfd_error_handler)
     2767                   ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized reloc 0x%lx",
     2768                    bfd_get_filename (abfd), (unsigned long) irel->r_offset, irelcall->r_offset ));
     2769
     2770                  continue;
     2771                }
     2772
     2773              /* Get the value of the symbol referred to by the reloc.  */
     2774              if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
     2775                {
     2776                  Elf_Internal_Sym *isym;
     2777                  asection *sym_sec;
     2778
     2779                  /* A local symbol.  */
     2780                  isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
     2781
     2782                  if (isym->st_shndx == SHN_UNDEF)
     2783                    sym_sec = bfd_und_section_ptr;
     2784                  else if (isym->st_shndx == SHN_ABS)
     2785                    sym_sec = bfd_abs_section_ptr;
     2786                  else if (isym->st_shndx == SHN_COMMON)
     2787                    sym_sec = bfd_com_section_ptr;
     2788                  else
     2789                    sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
     2790                  symval = (isym->st_value
     2791                            + sym_sec->output_section->vma
     2792                            + sym_sec->output_offset);
     2793                }
     2794              else
     2795                {
     2796                  unsigned long indx;
     2797                  struct elf_link_hash_entry *h;
     2798
     2799                  /* An external symbol.  */
     2800                  indx = ELF32_R_SYM (hi_irelfn->r_info) - symtab_hdr->sh_info;
     2801                  h = elf_sym_hashes (abfd)[indx];
     2802                  BFD_ASSERT (h != NULL);
     2803
     2804                  if (   h->root.type != bfd_link_hash_defined
     2805                      && h->root.type != bfd_link_hash_defweak)
     2806                    /* This appears to be a reference to an undefined
     2807                       symbol.  Just ignore it--it will be caught by the
     2808                       regular reloc processing.  */
     2809                    continue;
     2810
     2811                  symval = (h->root.u.def.value
     2812                            + h->root.u.def.section->output_section->vma
     2813                            + h->root.u.def.section->output_offset);
     2814                }
     2815
     2816              addend = irel->r_addend;
     2817
     2818              foff = (symval + addend
     2819                      - (irel->r_offset
     2820                         + sec->output_section->vma
     2821                         + sec->output_offset
     2822                         + 4));
     2823#ifdef DEBUG_RELAX
     2824              fprintf (stderr, "relax longcall r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
     2825                       irel->r_offset,
     2826                       (irel->r_offset
     2827                        + sec->output_section->vma
     2828                        + sec->output_offset),
     2829                       symval, addend, foff);
     2830#endif
     2831
     2832              if (foff < -0x100000 || foff >= 0x100000)
     2833                /* After all that work, we can't shorten this function call.  */
     2834                continue;
     2835
     2836              /* For simplicity of coding, we are going to modify the section
     2837                 contents, the section relocs, and the BFD symbol table.  We
     2838                 must tell the rest of the code not to free up this
     2839                 information.  It would be possible to instead create a table
     2840                 of changes which have to be made, as is done in coff-mips.c;
     2841                 that would be more work, but would require less memory when
     2842                 the linker is run.  */
     2843              elf_section_data (sec)->relocs = internal_relocs;
     2844              elf_section_data (sec)->this_hdr.contents = contents;
     2845              symtab_hdr->contents = (bfd_byte *) isymbuf;
     2846
     2847              /* Replace the long call with a jarl.  */
     2848              irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_22_PCREL);
     2849
     2850              addend = 0;
     2851
     2852              if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
     2853                /* If this needs to be changed because of future relaxing,
     2854                   it will be handled here like other internal IND12W
     2855                   relocs.  */
     2856                bfd_put_32 (abfd,
     2857                            0x00000780 | (JARL_R2 (insn[2])<<11) | ((addend << 16) & 0xffff) | ((addend >> 16) & 0xf),
     2858                            contents + irel->r_offset);
     2859              else
     2860                /* We can't fully resolve this yet, because the external
     2861                   symbol value may be changed by future relaxing.
     2862                   We let the final link phase handle it.  */
     2863                bfd_put_32 (abfd, 0x00000780 | (JARL_R2 (insn[2])<<11),
     2864                            contents + irel->r_offset);
     2865
     2866              hi_irelfn->r_info =
     2867                ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
     2868              lo_irelfn->r_info =
     2869                ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
     2870              irelcall->r_info =
     2871                ELF32_R_INFO (ELF32_R_SYM (irelcall->r_info), R_V850_NONE);
     2872
     2873              if (! v850_elf_relax_delete_bytes (abfd, sec,
     2874                                                 irel->r_offset + 4, toaddr, 12))
     2875                goto error_return;
     2876
     2877              align_pad_size += 12;
     2878            }
     2879          else if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)
     2880            {
     2881              /* Check code for -mlong-jumps output.  */
     2882              if (laddr + 10 <= (bfd_vma) sec->_raw_size)
     2883                {
     2884                  insn[0] = bfd_get_16 (abfd, contents + laddr);
     2885                  insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
     2886                  insn[2] = bfd_get_16 (abfd, contents + laddr + 8);
     2887
     2888                  if ((insn[0] & MOVHI_MASK) != MOVHI
     2889                       || MOVHI_R1 (insn[0]) != 0)
     2890                    no_match = 0;
     2891
     2892                  if (no_match < 0
     2893                      && ((insn[1] & MOVEA_MASK) != MOVEA
     2894                           || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
     2895                    no_match = 1;
     2896
     2897                  if (no_match < 0
     2898                      && ((insn[2] & JMP_R_MASK) != JMP_R
     2899                           || MOVEA_R2 (insn[1]) != JMP_R1 (insn[2])))
     2900                    no_match = 4;
     2901                }
     2902              else
     2903                {
     2904                  ((*_bfd_error_handler)
     2905                   ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized insns",
     2906                    bfd_get_filename (abfd), (unsigned long) irel->r_offset));
     2907
     2908                  continue;
     2909                }
     2910
     2911              if (no_match >= 0)
     2912                {
     2913                  ((*_bfd_error_handler)
     2914                   ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized insn 0x%x",
     2915                    bfd_get_filename (abfd), (unsigned long) irel->r_offset+no_match, insn[no_match]));
     2916
     2917                  continue;
     2918                }
     2919
     2920              /* Get the reloc for the address from which the register is
     2921                 being loaded.  This reloc will tell us which function is
     2922                 actually being called.  */
     2923              for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
     2924                if (hi_irelfn->r_offset == laddr + 2
     2925                    && ELF32_R_TYPE (hi_irelfn->r_info) == (int) R_V850_HI16_S)
     2926                  break;
     2927
     2928              for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
     2929                if (lo_irelfn->r_offset == laddr + 6
     2930                    && ELF32_R_TYPE (lo_irelfn->r_info) == (int) R_V850_LO16)
     2931                  break;
     2932
     2933              if (   hi_irelfn == irelend
     2934                  || lo_irelfn == irelend)
     2935                {
     2936                  ((*_bfd_error_handler)
     2937                   ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized reloc",
     2938                    bfd_get_filename (abfd), (unsigned long) irel->r_offset ));
     2939
     2940                  continue;
     2941                }
     2942
     2943              /* Get the value of the symbol referred to by the reloc.  */
     2944              if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
     2945                {
     2946                  Elf_Internal_Sym *  isym;
     2947                  asection *          sym_sec;
     2948
     2949                  /* A local symbol.  */
     2950                  isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
     2951
     2952                  if (isym->st_shndx == SHN_UNDEF)
     2953                    sym_sec = bfd_und_section_ptr;
     2954                  else if (isym->st_shndx == SHN_ABS)
     2955                    sym_sec = bfd_abs_section_ptr;
     2956                  else if (isym->st_shndx == SHN_COMMON)
     2957                    sym_sec = bfd_com_section_ptr;
     2958                  else
     2959                    sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
     2960                  symval = (isym->st_value
     2961                            + sym_sec->output_section->vma
     2962                            + sym_sec->output_offset);
     2963#ifdef DEBUG_RELAX
     2964                  {
     2965                    char * name = bfd_elf_string_from_elf_section
     2966                      (abfd, symtab_hdr->sh_link, isym->st_name);
     2967
     2968                    fprintf (stderr, "relax long jump local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
     2969                             sym_sec->name, name, isym->st_name,
     2970                             sym_sec->output_section->vma,
     2971                             sym_sec->output_offset,
     2972                             isym->st_value, irel->r_addend);
     2973                  }
     2974#endif
     2975                }
     2976              else
     2977                {
     2978                  unsigned long indx;
     2979                  struct elf_link_hash_entry * h;
     2980
     2981                  /* An external symbol.  */
     2982                  indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
     2983                  h = elf_sym_hashes (abfd)[indx];
     2984                  BFD_ASSERT (h != NULL);
     2985
     2986                  if (   h->root.type != bfd_link_hash_defined
     2987                      && h->root.type != bfd_link_hash_defweak)
     2988                    /* This appears to be a reference to an undefined
     2989                       symbol.  Just ignore it--it will be caught by the
     2990                       regular reloc processing.  */
     2991                    continue;
     2992
     2993                  symval = (h->root.u.def.value
     2994                            + h->root.u.def.section->output_section->vma
     2995                            + h->root.u.def.section->output_offset);
     2996#ifdef DEBUG_RELAX
     2997                  fprintf (stderr,
     2998                           "relax longjump defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
     2999                           sec->name, h->root.root.string, h->root.u.def.value,
     3000                           sec->output_section->vma, sec->output_offset, irel->r_addend);
     3001#endif
     3002                }
     3003
     3004              addend = irel->r_addend;
     3005
     3006              foff = (symval + addend
     3007                      - (irel->r_offset
     3008                         + sec->output_section->vma
     3009                         + sec->output_offset
     3010                         + 4));
     3011#ifdef DEBUG_RELAX
     3012              fprintf (stderr, "relax longjump r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
     3013                       irel->r_offset,
     3014                       (irel->r_offset
     3015                        + sec->output_section->vma
     3016                        + sec->output_offset),
     3017                       symval, addend, foff);
     3018#endif
     3019              if (foff < -0x100000 || foff >= 0x100000)
     3020                /* After all that work, we can't shorten this function call.  */
     3021                continue;
     3022
     3023              /* For simplicity of coding, we are going to modify the section
     3024                 contents, the section relocs, and the BFD symbol table.  We
     3025                 must tell the rest of the code not to free up this
     3026                 information.  It would be possible to instead create a table
     3027                 of changes which have to be made, as is done in coff-mips.c;
     3028                 that would be more work, but would require less memory when
     3029                 the linker is run.  */
     3030              elf_section_data (sec)->relocs = internal_relocs;
     3031              elf_section_data (sec)->this_hdr.contents = contents;
     3032              symtab_hdr->contents = (bfd_byte *) isymbuf;
     3033
     3034              if (foff < -0x100 || foff >= 0x100)
     3035                {
     3036                  /* Replace the long jump with a jr.  */
     3037
     3038                  irel->r_info =
     3039                    ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_22_PCREL);
     3040
     3041                  irel->r_addend = addend;
     3042                  addend = 0;
     3043
     3044                  if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
     3045                    /* If this needs to be changed because of future relaxing,
     3046                       it will be handled here like other internal IND12W
     3047                       relocs.  */
     3048                    bfd_put_32 (abfd,
     3049                                0x00000780 | ((addend << 15) & 0xffff0000) | ((addend >> 17) & 0xf),
     3050                                contents + irel->r_offset);
     3051                  else
     3052                    /* We can't fully resolve this yet, because the external
     3053                       symbol value may be changed by future relaxing.
     3054                       We let the final link phase handle it.  */
     3055                    bfd_put_32 (abfd, 0x00000780, contents + irel->r_offset);
     3056
     3057                  hi_irelfn->r_info =
     3058                        ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
     3059                  lo_irelfn->r_info =
     3060                        ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
     3061                  if (!v850_elf_relax_delete_bytes (abfd, sec,
     3062                                                    irel->r_offset + 4, toaddr, 6))
     3063                    goto error_return;
     3064
     3065                  align_pad_size += 6;
     3066                }
     3067              else
     3068                {
     3069                  /* Replace the long jump with a br.  */
     3070
     3071                  irel->r_info =
     3072                        ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_9_PCREL);
     3073
     3074                  irel->r_addend = addend;
     3075                  addend = 0;
     3076
     3077                  if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
     3078                    /* If this needs to be changed because of future relaxing,
     3079                       it will be handled here like other internal IND12W
     3080                       relocs.  */
     3081                    bfd_put_16 (abfd,
     3082                                0x0585 | ((addend << 10) & 0xf800) | ((addend << 3) & 0x0070),
     3083                                contents + irel->r_offset);
     3084                  else
     3085                    /* We can't fully resolve this yet, because the external
     3086                       symbol value may be changed by future relaxing.
     3087                       We let the final link phase handle it.  */
     3088                    bfd_put_16 (abfd, 0x0585, contents + irel->r_offset);
     3089
     3090                  hi_irelfn->r_info =
     3091                        ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
     3092                  lo_irelfn->r_info =
     3093                        ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
     3094                  if (!v850_elf_relax_delete_bytes (abfd, sec,
     3095                                                    irel->r_offset + 2, toaddr, 8))
     3096                    goto error_return;
     3097
     3098                  align_pad_size += 8;
     3099                }
     3100            }
     3101        }
     3102
     3103      irelalign = NULL;
     3104      for (irel = internal_relocs; irel < irelend; irel++)
     3105        {
     3106          if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
     3107              && irel->r_offset == toaddr)
     3108            {
     3109              irel->r_offset -= align_pad_size;
     3110
     3111              if (irelalign == NULL || irelalign->r_addend > irel->r_addend)
     3112                irelalign = irel;
     3113            }
     3114        }
     3115
     3116      addr = toaddr;
     3117    }
     3118
     3119  if (!irelalign)
     3120    {
     3121#ifdef DEBUG_RELAX
     3122      fprintf (stderr, "relax pad %d shorten %d -> %d\n",
     3123               align_pad_size,
     3124               sec->_cooked_size,
     3125               sec->_cooked_size - align_pad_size);
     3126#endif
     3127      sec->_cooked_size -= align_pad_size;
     3128    }
     3129
     3130 finish:
     3131  if (internal_relocs != NULL
     3132      && elf_section_data (sec)->relocs != internal_relocs)
     3133    free (internal_relocs);
     3134
     3135  if (contents != NULL
     3136      && elf_section_data (sec)->this_hdr.contents != (unsigned char *) contents)
     3137    free (contents);
     3138
     3139  if (isymbuf != NULL
     3140      && symtab_hdr->contents != (bfd_byte *) isymbuf)
     3141    free (isymbuf);
     3142
     3143  return result;
     3144
     3145 error_return:
     3146  result = FALSE;
     3147  goto finish;
    22073148}
    22083149
     
    22113152#define TARGET_LITTLE_NAME                      "elf32-v850"
    22123153#define ELF_ARCH                                bfd_arch_v850
    2213 #define ELF_MACHINE_CODE                        EM_CYGNUS_V850
     3154#define ELF_MACHINE_CODE                        EM_V850
     3155#define ELF_MACHINE_ALT1                        EM_CYGNUS_V850
    22143156#define ELF_MAXPAGESIZE                         0x1000
    22153157
     
    22313173
    22323174#define elf_backend_can_gc_sections 1
     3175#define elf_backend_rela_normal 1
    22333176
    22343177#define bfd_elf32_bfd_is_local_label_name       v850_elf_is_local_label_name
    22353178#define bfd_elf32_bfd_reloc_type_lookup         v850_elf_reloc_type_lookup
    2236 #define bfd_elf32_bfd_copy_private_bfd_data     v850_elf_copy_private_bfd_data
    22373179#define bfd_elf32_bfd_merge_private_bfd_data    v850_elf_merge_private_bfd_data
    22383180#define bfd_elf32_bfd_set_private_flags         v850_elf_set_private_flags
    22393181#define bfd_elf32_bfd_print_private_bfd_data    v850_elf_print_private_bfd_data
     3182#define bfd_elf32_bfd_relax_section             v850_elf_relax_section
    22403183
    22413184#define elf_symbol_leading_char                 '_'
Note: See TracChangeset for help on using the changeset viewer.