| 1 | /* V850-specific support for 32-bit ELF | 
|---|
| 2 | Copyright 1996, 1997, 1998, 1999, 2000, 2001 | 
|---|
| 3 | Free Software Foundation, Inc. | 
|---|
| 4 |  | 
|---|
| 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.  */ | 
|---|
| 20 |  | 
|---|
| 21 | /* XXX FIXME: This code is littered with 32bit int, 16bit short, 8bit char | 
|---|
| 22 | dependencies.  As is the gas & simulator code or the v850.  */ | 
|---|
| 23 |  | 
|---|
| 24 | #include "bfd.h" | 
|---|
| 25 | #include "sysdep.h" | 
|---|
| 26 | #include "bfdlink.h" | 
|---|
| 27 | #include "libbfd.h" | 
|---|
| 28 | #include "elf-bfd.h" | 
|---|
| 29 | #include "elf/v850.h" | 
|---|
| 30 |  | 
|---|
| 31 | /* sign-extend a 24-bit number */ | 
|---|
| 32 | #define SEXT24(x)       ((((x) & 0xffffff) ^ (~ 0x7fffff)) + 0x800000) | 
|---|
| 33 |  | 
|---|
| 34 | static reloc_howto_type *v850_elf_reloc_type_lookup | 
|---|
| 35 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); | 
|---|
| 36 | static void v850_elf_info_to_howto_rel | 
|---|
| 37 | PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *)); | 
|---|
| 38 | static void v850_elf_info_to_howto_rela | 
|---|
| 39 | PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *)); | 
|---|
| 40 | static bfd_reloc_status_type v850_elf_reloc | 
|---|
| 41 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | 
|---|
| 42 | static boolean v850_elf_is_local_label_name | 
|---|
| 43 | PARAMS ((bfd *, const char *)); | 
|---|
| 44 | static boolean v850_elf_relocate_section | 
|---|
| 45 | PARAMS((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | 
|---|
| 46 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | 
|---|
| 47 | static bfd_reloc_status_type v850_elf_perform_relocation | 
|---|
| 48 | PARAMS ((bfd *, int, bfd_vma, bfd_byte *)); | 
|---|
| 49 | static boolean v850_elf_check_relocs | 
|---|
| 50 | PARAMS ((bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *)); | 
|---|
| 51 | static void remember_hi16s_reloc | 
|---|
| 52 | PARAMS ((bfd *, bfd_vma, bfd_byte *)); | 
|---|
| 53 | static bfd_byte * find_remembered_hi16s_reloc | 
|---|
| 54 | PARAMS ((bfd_vma, boolean *)); | 
|---|
| 55 | static bfd_reloc_status_type v850_elf_final_link_relocate | 
|---|
| 56 | PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *, bfd_vma, | 
|---|
| 57 | bfd_vma, bfd_vma, struct bfd_link_info *, asection *, int)); | 
|---|
| 58 | static boolean v850_elf_object_p | 
|---|
| 59 | PARAMS ((bfd *)); | 
|---|
| 60 | static boolean v850_elf_fake_sections | 
|---|
| 61 | PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *)); | 
|---|
| 62 | static void v850_elf_final_write_processing | 
|---|
| 63 | PARAMS ((bfd *, boolean)); | 
|---|
| 64 | static boolean v850_elf_set_private_flags | 
|---|
| 65 | PARAMS ((bfd *, flagword)); | 
|---|
| 66 | static boolean v850_elf_copy_private_bfd_data | 
|---|
| 67 | 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 | 
|---|
| 71 | PARAMS ((bfd *, PTR)); | 
|---|
| 72 | static boolean v850_elf_section_from_bfd_section | 
|---|
| 73 | PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *)); | 
|---|
| 74 | static void v850_elf_symbol_processing | 
|---|
| 75 | PARAMS ((bfd *, asymbol *)); | 
|---|
| 76 | static boolean v850_elf_add_symbol_hook | 
|---|
| 77 | PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, | 
|---|
| 78 | const char **, flagword *, asection **, bfd_vma *)); | 
|---|
| 79 | static boolean v850_elf_link_output_symbol_hook | 
|---|
| 80 | PARAMS ((bfd *, struct bfd_link_info *, const char *, | 
|---|
| 81 | 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.  */ | 
|---|
| 87 | static reloc_howto_type v850_elf_howto_table[] = | 
|---|
| 88 | { | 
|---|
| 89 | /* This reloc does nothing.  */ | 
|---|
| 90 | HOWTO (R_V850_NONE,                   /* type */ | 
|---|
| 91 | 0,                             /* rightshift */ | 
|---|
| 92 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 93 | 32,                            /* bitsize */ | 
|---|
| 94 | false,                         /* pc_relative */ | 
|---|
| 95 | 0,                             /* bitpos */ | 
|---|
| 96 | complain_overflow_bitfield,    /* complain_on_overflow */ | 
|---|
| 97 | bfd_elf_generic_reloc,         /* special_function */ | 
|---|
| 98 | "R_V850_NONE",                 /* name */ | 
|---|
| 99 | false,                         /* partial_inplace */ | 
|---|
| 100 | 0,                             /* src_mask */ | 
|---|
| 101 | 0,                             /* dst_mask */ | 
|---|
| 102 | false),                        /* pcrel_offset */ | 
|---|
| 103 |  | 
|---|
| 104 | /* A PC relative 9 bit branch.  */ | 
|---|
| 105 | HOWTO (R_V850_9_PCREL,                /* type */ | 
|---|
| 106 | 2,                             /* rightshift */ | 
|---|
| 107 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 108 | 26,                            /* bitsize */ | 
|---|
| 109 | true,                          /* pc_relative */ | 
|---|
| 110 | 0,                             /* bitpos */ | 
|---|
| 111 | complain_overflow_bitfield,    /* complain_on_overflow */ | 
|---|
| 112 | v850_elf_reloc,                /* special_function */ | 
|---|
| 113 | "R_V850_9_PCREL",              /* name */ | 
|---|
| 114 | false,                         /* partial_inplace */ | 
|---|
| 115 | 0x00ffffff,                    /* src_mask */ | 
|---|
| 116 | 0x00ffffff,                    /* dst_mask */ | 
|---|
| 117 | true),                         /* pcrel_offset */ | 
|---|
| 118 |  | 
|---|
| 119 | /* A PC relative 22 bit branch.  */ | 
|---|
| 120 | HOWTO (R_V850_22_PCREL,               /* type */ | 
|---|
| 121 | 2,                             /* rightshift */ | 
|---|
| 122 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 123 | 22,                            /* bitsize */ | 
|---|
| 124 | true,                          /* pc_relative */ | 
|---|
| 125 | 7,                             /* bitpos */ | 
|---|
| 126 | complain_overflow_signed,      /* complain_on_overflow */ | 
|---|
| 127 | v850_elf_reloc,                /* special_function */ | 
|---|
| 128 | "R_V850_22_PCREL",             /* name */ | 
|---|
| 129 | false,                         /* partial_inplace */ | 
|---|
| 130 | 0x07ffff80,                    /* src_mask */ | 
|---|
| 131 | 0x07ffff80,                    /* dst_mask */ | 
|---|
| 132 | true),                         /* pcrel_offset */ | 
|---|
| 133 |  | 
|---|
| 134 | /* High 16 bits of symbol value.  */ | 
|---|
| 135 | HOWTO (R_V850_HI16_S,                 /* type */ | 
|---|
| 136 | 0,                             /* rightshift */ | 
|---|
| 137 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 138 | 16,                            /* bitsize */ | 
|---|
| 139 | false,                         /* pc_relative */ | 
|---|
| 140 | 0,                             /* bitpos */ | 
|---|
| 141 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 142 | v850_elf_reloc,                /* special_function */ | 
|---|
| 143 | "R_V850_HI16_S",               /* name */ | 
|---|
| 144 | false,                         /* partial_inplace */ | 
|---|
| 145 | 0xffff,                        /* src_mask */ | 
|---|
| 146 | 0xffff,                        /* dst_mask */ | 
|---|
| 147 | false),                        /* pcrel_offset */ | 
|---|
| 148 |  | 
|---|
| 149 | /* High 16 bits of symbol value.  */ | 
|---|
| 150 | HOWTO (R_V850_HI16,                   /* type */ | 
|---|
| 151 | 0,                             /* rightshift */ | 
|---|
| 152 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 153 | 16,                            /* bitsize */ | 
|---|
| 154 | false,                         /* pc_relative */ | 
|---|
| 155 | 0,                             /* bitpos */ | 
|---|
| 156 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 157 | v850_elf_reloc,                /* special_function */ | 
|---|
| 158 | "R_V850_HI16",                 /* name */ | 
|---|
| 159 | false,                         /* partial_inplace */ | 
|---|
| 160 | 0xffff,                        /* src_mask */ | 
|---|
| 161 | 0xffff,                        /* dst_mask */ | 
|---|
| 162 | false),                        /* pcrel_offset */ | 
|---|
| 163 |  | 
|---|
| 164 | /* Low 16 bits of symbol value.  */ | 
|---|
| 165 | HOWTO (R_V850_LO16,                   /* type */ | 
|---|
| 166 | 0,                             /* rightshift */ | 
|---|
| 167 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 168 | 16,                            /* bitsize */ | 
|---|
| 169 | false,                         /* pc_relative */ | 
|---|
| 170 | 0,                             /* bitpos */ | 
|---|
| 171 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 172 | v850_elf_reloc,                /* special_function */ | 
|---|
| 173 | "R_V850_LO16",                 /* name */ | 
|---|
| 174 | false,                         /* partial_inplace */ | 
|---|
| 175 | 0xffff,                        /* src_mask */ | 
|---|
| 176 | 0xffff,                        /* dst_mask */ | 
|---|
| 177 | false),                        /* pcrel_offset */ | 
|---|
| 178 |  | 
|---|
| 179 | /* Simple 32bit reloc.  */ | 
|---|
| 180 | HOWTO (R_V850_32,                     /* type */ | 
|---|
| 181 | 0,                             /* rightshift */ | 
|---|
| 182 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 183 | 32,                            /* bitsize */ | 
|---|
| 184 | false,                         /* pc_relative */ | 
|---|
| 185 | 0,                             /* bitpos */ | 
|---|
| 186 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 187 | v850_elf_reloc,                /* special_function */ | 
|---|
| 188 | "R_V850_32",                   /* name */ | 
|---|
| 189 | false,                         /* partial_inplace */ | 
|---|
| 190 | 0xffffffff,                    /* src_mask */ | 
|---|
| 191 | 0xffffffff,                    /* dst_mask */ | 
|---|
| 192 | false),                        /* pcrel_offset */ | 
|---|
| 193 |  | 
|---|
| 194 | /* Simple 16bit reloc.  */ | 
|---|
| 195 | HOWTO (R_V850_16,                     /* type */ | 
|---|
| 196 | 0,                             /* rightshift */ | 
|---|
| 197 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 198 | 16,                            /* bitsize */ | 
|---|
| 199 | false,                         /* pc_relative */ | 
|---|
| 200 | 0,                             /* bitpos */ | 
|---|
| 201 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 202 | bfd_elf_generic_reloc,         /* special_function */ | 
|---|
| 203 | "R_V850_16",                   /* name */ | 
|---|
| 204 | false,                         /* partial_inplace */ | 
|---|
| 205 | 0xffff,                        /* src_mask */ | 
|---|
| 206 | 0xffff,                        /* dst_mask */ | 
|---|
| 207 | false),                        /* pcrel_offset */ | 
|---|
| 208 |  | 
|---|
| 209 | /* Simple 8bit reloc.  */ | 
|---|
| 210 | HOWTO (R_V850_8,                      /* type */ | 
|---|
| 211 | 0,                             /* rightshift */ | 
|---|
| 212 | 0,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 213 | 8,                             /* bitsize */ | 
|---|
| 214 | false,                         /* pc_relative */ | 
|---|
| 215 | 0,                             /* bitpos */ | 
|---|
| 216 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 217 | bfd_elf_generic_reloc,         /* special_function */ | 
|---|
| 218 | "R_V850_8",                    /* name */ | 
|---|
| 219 | false,                         /* partial_inplace */ | 
|---|
| 220 | 0xff,                          /* src_mask */ | 
|---|
| 221 | 0xff,                          /* dst_mask */ | 
|---|
| 222 | false),                        /* pcrel_offset */ | 
|---|
| 223 |  | 
|---|
| 224 | /* 16 bit offset from the short data area pointer.  */ | 
|---|
| 225 | HOWTO (R_V850_SDA_16_16_OFFSET,       /* type */ | 
|---|
| 226 | 0,                             /* rightshift */ | 
|---|
| 227 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 228 | 16,                            /* bitsize */ | 
|---|
| 229 | false,                         /* pc_relative */ | 
|---|
| 230 | 0,                             /* bitpos */ | 
|---|
| 231 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 232 | v850_elf_reloc,                /* special_function */ | 
|---|
| 233 | "R_V850_SDA_16_16_OFFSET",     /* name */ | 
|---|
| 234 | false,                         /* partial_inplace */ | 
|---|
| 235 | 0xffff,                        /* src_mask */ | 
|---|
| 236 | 0xffff,                        /* dst_mask */ | 
|---|
| 237 | false),                        /* pcrel_offset */ | 
|---|
| 238 |  | 
|---|
| 239 | /* 15 bit offset from the short data area pointer.  */ | 
|---|
| 240 | HOWTO (R_V850_SDA_15_16_OFFSET,       /* type */ | 
|---|
| 241 | 1,                             /* rightshift */ | 
|---|
| 242 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 243 | 16,                            /* bitsize */ | 
|---|
| 244 | false,                         /* pc_relative */ | 
|---|
| 245 | 1,                             /* bitpos */ | 
|---|
| 246 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 247 | v850_elf_reloc,                /* special_function */ | 
|---|
| 248 | "R_V850_SDA_15_16_OFFSET",     /* name */ | 
|---|
| 249 | false,                         /* partial_inplace */ | 
|---|
| 250 | 0xfffe,                        /* src_mask */ | 
|---|
| 251 | 0xfffe,                        /* dst_mask */ | 
|---|
| 252 | false),                        /* pcrel_offset */ | 
|---|
| 253 |  | 
|---|
| 254 | /* 16 bit offset from the zero data area pointer.  */ | 
|---|
| 255 | HOWTO (R_V850_ZDA_16_16_OFFSET,       /* type */ | 
|---|
| 256 | 0,                             /* rightshift */ | 
|---|
| 257 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 258 | 16,                            /* bitsize */ | 
|---|
| 259 | false,                         /* pc_relative */ | 
|---|
| 260 | 0,                             /* bitpos */ | 
|---|
| 261 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 262 | v850_elf_reloc,                /* special_function */ | 
|---|
| 263 | "R_V850_ZDA_16_16_OFFSET",     /* name */ | 
|---|
| 264 | false,                         /* partial_inplace */ | 
|---|
| 265 | 0xffff,                        /* src_mask */ | 
|---|
| 266 | 0xffff,                        /* dst_mask */ | 
|---|
| 267 | false),                        /* pcrel_offset */ | 
|---|
| 268 |  | 
|---|
| 269 | /* 15 bit offset from the zero data area pointer.  */ | 
|---|
| 270 | HOWTO (R_V850_ZDA_15_16_OFFSET,       /* type */ | 
|---|
| 271 | 1,                             /* rightshift */ | 
|---|
| 272 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 273 | 16,                            /* bitsize */ | 
|---|
| 274 | false,                         /* pc_relative */ | 
|---|
| 275 | 1,                             /* bitpos */ | 
|---|
| 276 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 277 | v850_elf_reloc,                /* special_function */ | 
|---|
| 278 | "R_V850_ZDA_15_16_OFFSET",     /* name */ | 
|---|
| 279 | false,                         /* partial_inplace */ | 
|---|
| 280 | 0xfffe,                        /* src_mask */ | 
|---|
| 281 | 0xfffe,                        /* dst_mask */ | 
|---|
| 282 | false),                        /* pcrel_offset */ | 
|---|
| 283 |  | 
|---|
| 284 | /* 6 bit offset from the tiny data area pointer.  */ | 
|---|
| 285 | HOWTO (R_V850_TDA_6_8_OFFSET,         /* type */ | 
|---|
| 286 | 2,                             /* rightshift */ | 
|---|
| 287 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 288 | 8,                             /* bitsize */ | 
|---|
| 289 | false,                         /* pc_relative */ | 
|---|
| 290 | 1,                             /* bitpos */ | 
|---|
| 291 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 292 | v850_elf_reloc,                /* special_function */ | 
|---|
| 293 | "R_V850_TDA_6_8_OFFSET",       /* name */ | 
|---|
| 294 | false,                         /* partial_inplace */ | 
|---|
| 295 | 0x7e,                          /* src_mask */ | 
|---|
| 296 | 0x7e,                          /* dst_mask */ | 
|---|
| 297 | false),                        /* pcrel_offset */ | 
|---|
| 298 |  | 
|---|
| 299 | /* 8 bit offset from the tiny data area pointer.  */ | 
|---|
| 300 | HOWTO (R_V850_TDA_7_8_OFFSET,         /* type */ | 
|---|
| 301 | 1,                             /* rightshift */ | 
|---|
| 302 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 303 | 8,                             /* bitsize */ | 
|---|
| 304 | false,                         /* pc_relative */ | 
|---|
| 305 | 0,                             /* bitpos */ | 
|---|
| 306 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 307 | v850_elf_reloc,                /* special_function */ | 
|---|
| 308 | "R_V850_TDA_7_8_OFFSET",       /* name */ | 
|---|
| 309 | false,                         /* partial_inplace */ | 
|---|
| 310 | 0x7f,                          /* src_mask */ | 
|---|
| 311 | 0x7f,                          /* dst_mask */ | 
|---|
| 312 | false),                        /* pcrel_offset */ | 
|---|
| 313 |  | 
|---|
| 314 | /* 7 bit offset from the tiny data area pointer.  */ | 
|---|
| 315 | HOWTO (R_V850_TDA_7_7_OFFSET,         /* type */ | 
|---|
| 316 | 0,                             /* rightshift */ | 
|---|
| 317 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 318 | 7,                             /* bitsize */ | 
|---|
| 319 | false,                         /* pc_relative */ | 
|---|
| 320 | 0,                             /* bitpos */ | 
|---|
| 321 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 322 | v850_elf_reloc,                /* special_function */ | 
|---|
| 323 | "R_V850_TDA_7_7_OFFSET",       /* name */ | 
|---|
| 324 | false,                         /* partial_inplace */ | 
|---|
| 325 | 0x7f,                          /* src_mask */ | 
|---|
| 326 | 0x7f,                          /* dst_mask */ | 
|---|
| 327 | false),                        /* pcrel_offset */ | 
|---|
| 328 |  | 
|---|
| 329 | /* 16 bit offset from the tiny data area pointer!  */ | 
|---|
| 330 | HOWTO (R_V850_TDA_16_16_OFFSET,       /* type */ | 
|---|
| 331 | 0,                             /* rightshift */ | 
|---|
| 332 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 333 | 16,                            /* bitsize */ | 
|---|
| 334 | false,                         /* pc_relative */ | 
|---|
| 335 | 0,                             /* bitpos */ | 
|---|
| 336 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 337 | v850_elf_reloc,                /* special_function */ | 
|---|
| 338 | "R_V850_TDA_16_16_OFFSET",     /* name */ | 
|---|
| 339 | false,                         /* partial_inplace */ | 
|---|
| 340 | 0xffff,                        /* src_mask */ | 
|---|
| 341 | 0xfff,                         /* dst_mask */ | 
|---|
| 342 | false),                        /* pcrel_offset */ | 
|---|
| 343 |  | 
|---|
| 344 | /* 5 bit offset from the tiny data area pointer.  */ | 
|---|
| 345 | HOWTO (R_V850_TDA_4_5_OFFSET,         /* type */ | 
|---|
| 346 | 1,                             /* rightshift */ | 
|---|
| 347 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 348 | 5,                             /* bitsize */ | 
|---|
| 349 | false,                         /* pc_relative */ | 
|---|
| 350 | 0,                             /* bitpos */ | 
|---|
| 351 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 352 | v850_elf_reloc,                /* special_function */ | 
|---|
| 353 | "R_V850_TDA_4_5_OFFSET",       /* name */ | 
|---|
| 354 | false,                         /* partial_inplace */ | 
|---|
| 355 | 0x0f,                          /* src_mask */ | 
|---|
| 356 | 0x0f,                          /* dst_mask */ | 
|---|
| 357 | false),                        /* pcrel_offset */ | 
|---|
| 358 |  | 
|---|
| 359 | /* 4 bit offset from the tiny data area pointer.  */ | 
|---|
| 360 | HOWTO (R_V850_TDA_4_4_OFFSET,         /* type */ | 
|---|
| 361 | 0,                             /* rightshift */ | 
|---|
| 362 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 363 | 4,                             /* bitsize */ | 
|---|
| 364 | false,                         /* pc_relative */ | 
|---|
| 365 | 0,                             /* bitpos */ | 
|---|
| 366 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 367 | v850_elf_reloc,                /* special_function */ | 
|---|
| 368 | "R_V850_TDA_4_4_OFFSET",       /* name */ | 
|---|
| 369 | false,                         /* partial_inplace */ | 
|---|
| 370 | 0x0f,                          /* src_mask */ | 
|---|
| 371 | 0x0f,                          /* dst_mask */ | 
|---|
| 372 | false),                        /* pcrel_offset */ | 
|---|
| 373 |  | 
|---|
| 374 | /* 16 bit offset from the short data area pointer.  */ | 
|---|
| 375 | HOWTO (R_V850_SDA_16_16_SPLIT_OFFSET, /* type */ | 
|---|
| 376 | 0,                             /* rightshift */ | 
|---|
| 377 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 378 | 16,                            /* bitsize */ | 
|---|
| 379 | false,                         /* pc_relative */ | 
|---|
| 380 | 0,                             /* bitpos */ | 
|---|
| 381 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 382 | v850_elf_reloc,                /* special_function */ | 
|---|
| 383 | "R_V850_SDA_16_16_SPLIT_OFFSET",/* name */ | 
|---|
| 384 | false,                         /* partial_inplace */ | 
|---|
| 385 | 0xfffe0020,                    /* src_mask */ | 
|---|
| 386 | 0xfffe0020,                    /* dst_mask */ | 
|---|
| 387 | false),                        /* pcrel_offset */ | 
|---|
| 388 |  | 
|---|
| 389 | /* 16 bit offset from the zero data area pointer.  */ | 
|---|
| 390 | HOWTO (R_V850_ZDA_16_16_SPLIT_OFFSET, /* type */ | 
|---|
| 391 | 0,                             /* rightshift */ | 
|---|
| 392 | 2,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 393 | 16,                            /* bitsize */ | 
|---|
| 394 | false,                         /* pc_relative */ | 
|---|
| 395 | 0,                             /* bitpos */ | 
|---|
| 396 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 397 | v850_elf_reloc,                /* special_function */ | 
|---|
| 398 | "R_V850_ZDA_16_16_SPLIT_OFFSET",/* name */ | 
|---|
| 399 | false,                         /* partial_inplace */ | 
|---|
| 400 | 0xfffe0020,                    /* src_mask */ | 
|---|
| 401 | 0xfffe0020,                    /* dst_mask */ | 
|---|
| 402 | false),                        /* pcrel_offset */ | 
|---|
| 403 |  | 
|---|
| 404 | /* 6 bit offset from the call table base pointer.  */ | 
|---|
| 405 | HOWTO (R_V850_CALLT_6_7_OFFSET,       /* type */ | 
|---|
| 406 | 0,                             /* rightshift */ | 
|---|
| 407 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 408 | 7,                             /* bitsize */ | 
|---|
| 409 | false,                         /* pc_relative */ | 
|---|
| 410 | 0,                             /* bitpos */ | 
|---|
| 411 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 412 | v850_elf_reloc,                /* special_function */ | 
|---|
| 413 | "R_V850_CALLT_6_7_OFFSET",     /* name */ | 
|---|
| 414 | false,                         /* partial_inplace */ | 
|---|
| 415 | 0x3f,                          /* src_mask */ | 
|---|
| 416 | 0x3f,                          /* dst_mask */ | 
|---|
| 417 | false),                        /* pcrel_offset */ | 
|---|
| 418 |  | 
|---|
| 419 | /* 16 bit offset from the call table base pointer.  */ | 
|---|
| 420 | HOWTO (R_V850_CALLT_16_16_OFFSET,     /* type */ | 
|---|
| 421 | 0,                             /* rightshift */ | 
|---|
| 422 | 1,                             /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 423 | 16,                            /* bitsize */ | 
|---|
| 424 | false,                         /* pc_relative */ | 
|---|
| 425 | 0,                             /* bitpos */ | 
|---|
| 426 | complain_overflow_dont,        /* complain_on_overflow */ | 
|---|
| 427 | v850_elf_reloc,                /* special_function */ | 
|---|
| 428 | "R_V850_CALLT_16_16_OFFSET",   /* name */ | 
|---|
| 429 | false,                         /* partial_inplace */ | 
|---|
| 430 | 0xffff,                        /* src_mask */ | 
|---|
| 431 | 0xffff,                        /* dst_mask */ | 
|---|
| 432 | false),                        /* pcrel_offset */ | 
|---|
| 433 |  | 
|---|
| 434 | /* GNU extension to record C++ vtable hierarchy */ | 
|---|
| 435 | HOWTO (R_V850_GNU_VTINHERIT, /* type */ | 
|---|
| 436 | 0,                     /* rightshift */ | 
|---|
| 437 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 438 | 0,                     /* bitsize */ | 
|---|
| 439 | false,                 /* pc_relative */ | 
|---|
| 440 | 0,                     /* bitpos */ | 
|---|
| 441 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 442 | NULL,                  /* special_function */ | 
|---|
| 443 | "R_V850_GNU_VTINHERIT", /* name */ | 
|---|
| 444 | false,                 /* partial_inplace */ | 
|---|
| 445 | 0,                     /* src_mask */ | 
|---|
| 446 | 0,                     /* dst_mask */ | 
|---|
| 447 | false),                /* pcrel_offset */ | 
|---|
| 448 |  | 
|---|
| 449 | /* GNU extension to record C++ vtable member usage */ | 
|---|
| 450 | HOWTO (R_V850_GNU_VTENTRY,     /* type */ | 
|---|
| 451 | 0,                     /* rightshift */ | 
|---|
| 452 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 453 | 0,                     /* bitsize */ | 
|---|
| 454 | false,                 /* pc_relative */ | 
|---|
| 455 | 0,                     /* bitpos */ | 
|---|
| 456 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 457 | _bfd_elf_rel_vtable_reloc_fn,  /* special_function */ | 
|---|
| 458 | "R_V850_GNU_VTENTRY",   /* name */ | 
|---|
| 459 | false,                 /* partial_inplace */ | 
|---|
| 460 | 0,                     /* src_mask */ | 
|---|
| 461 | 0,                     /* dst_mask */ | 
|---|
| 462 | false),                /* pcrel_offset */ | 
|---|
| 463 |  | 
|---|
| 464 | }; | 
|---|
| 465 |  | 
|---|
| 466 | /* Map BFD reloc types to V850 ELF reloc types.  */ | 
|---|
| 467 |  | 
|---|
| 468 | struct v850_elf_reloc_map | 
|---|
| 469 | { | 
|---|
| 470 | /* BFD_RELOC_V850_CALLT_16_16_OFFSET is 258, which will not fix in an | 
|---|
| 471 | unsigned char.  */ | 
|---|
| 472 | bfd_reloc_code_real_type bfd_reloc_val; | 
|---|
| 473 | unsigned char elf_reloc_val; | 
|---|
| 474 | }; | 
|---|
| 475 |  | 
|---|
| 476 | static const struct v850_elf_reloc_map v850_elf_reloc_map[] = | 
|---|
| 477 | { | 
|---|
| 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 }, | 
|---|
| 495 | { BFD_RELOC_V850_TDA_4_5_OFFSET,         R_V850_TDA_4_5_OFFSET         }, | 
|---|
| 496 | { BFD_RELOC_V850_TDA_4_4_OFFSET,         R_V850_TDA_4_4_OFFSET         }, | 
|---|
| 497 | { BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET, R_V850_SDA_16_16_SPLIT_OFFSET }, | 
|---|
| 498 | { BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET, R_V850_ZDA_16_16_SPLIT_OFFSET }, | 
|---|
| 499 | { BFD_RELOC_V850_CALLT_6_7_OFFSET,       R_V850_CALLT_6_7_OFFSET       }, | 
|---|
| 500 | { 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 }, | 
|---|
| 503 |  | 
|---|
| 504 | }; | 
|---|
| 505 |  | 
|---|
| 506 |  | 
|---|
| 507 | /* Map a bfd relocation into the appropriate howto structure */ | 
|---|
| 508 | static reloc_howto_type * | 
|---|
| 509 | v850_elf_reloc_type_lookup (abfd, code) | 
|---|
| 510 | bfd *                     abfd ATTRIBUTE_UNUSED; | 
|---|
| 511 | bfd_reloc_code_real_type  code; | 
|---|
| 512 | { | 
|---|
| 513 | unsigned int i; | 
|---|
| 514 |  | 
|---|
| 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 | } | 
|---|
| 526 |  | 
|---|
| 527 | return NULL; | 
|---|
| 528 | } | 
|---|
| 529 |  | 
|---|
| 530 |  | 
|---|
| 531 | /* Set the howto pointer for an V850 ELF reloc.  */ | 
|---|
| 532 | static void | 
|---|
| 533 | v850_elf_info_to_howto_rel (abfd, cache_ptr, dst) | 
|---|
| 534 | bfd *                 abfd ATTRIBUTE_UNUSED; | 
|---|
| 535 | arelent *             cache_ptr; | 
|---|
| 536 | Elf32_Internal_Rel *  dst; | 
|---|
| 537 | { | 
|---|
| 538 | unsigned int r_type; | 
|---|
| 539 |  | 
|---|
| 540 | r_type = ELF32_R_TYPE (dst->r_info); | 
|---|
| 541 | BFD_ASSERT (r_type < (unsigned int) R_V850_max); | 
|---|
| 542 | cache_ptr->howto = &v850_elf_howto_table[r_type]; | 
|---|
| 543 | } | 
|---|
| 544 |  | 
|---|
| 545 | /* Set the howto pointer for a V850 ELF reloc (type RELA).  */ | 
|---|
| 546 | static void | 
|---|
| 547 | v850_elf_info_to_howto_rela (abfd, cache_ptr, dst) | 
|---|
| 548 | bfd *                 abfd ATTRIBUTE_UNUSED; | 
|---|
| 549 | arelent *             cache_ptr; | 
|---|
| 550 | Elf32_Internal_Rela   *dst; | 
|---|
| 551 | { | 
|---|
| 552 | unsigned int r_type; | 
|---|
| 553 |  | 
|---|
| 554 | r_type = ELF32_R_TYPE (dst->r_info); | 
|---|
| 555 | BFD_ASSERT (r_type < (unsigned int) R_V850_max); | 
|---|
| 556 | cache_ptr->howto = &v850_elf_howto_table[r_type]; | 
|---|
| 557 | } | 
|---|
| 558 |  | 
|---|
| 559 |  | 
|---|
| 560 | /* Look through the relocs for a section during the first phase, and | 
|---|
| 561 | allocate space in the global offset table or procedure linkage | 
|---|
| 562 | table.  */ | 
|---|
| 563 |  | 
|---|
| 564 | static boolean | 
|---|
| 565 | v850_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; | 
|---|
| 570 | { | 
|---|
| 571 | boolean ret = true; | 
|---|
| 572 | bfd *dynobj; | 
|---|
| 573 | Elf_Internal_Shdr *symtab_hdr; | 
|---|
| 574 | struct elf_link_hash_entry **sym_hashes; | 
|---|
| 575 | const Elf_Internal_Rela *rel; | 
|---|
| 576 | const Elf_Internal_Rela *rel_end; | 
|---|
| 577 | asection *sreloc; | 
|---|
| 578 | enum v850_reloc_type r_type; | 
|---|
| 579 | int other = 0; | 
|---|
| 580 | const char *common = (const char *)0; | 
|---|
| 581 |  | 
|---|
| 582 | if (info->relocateable) | 
|---|
| 583 | return true; | 
|---|
| 584 |  | 
|---|
| 585 | #ifdef DEBUG | 
|---|
| 586 | fprintf (stderr, "v850_elf_check_relocs called for section %s in %s\n", | 
|---|
| 587 | bfd_get_section_name (abfd, sec), | 
|---|
| 588 | bfd_get_filename (abfd)); | 
|---|
| 589 | #endif | 
|---|
| 590 |  | 
|---|
| 591 | dynobj = elf_hash_table (info)->dynobj; | 
|---|
| 592 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | 
|---|
| 593 | sym_hashes = elf_sym_hashes (abfd); | 
|---|
| 594 | sreloc = NULL; | 
|---|
| 595 |  | 
|---|
| 596 | rel_end = relocs + sec->reloc_count; | 
|---|
| 597 | for (rel = relocs; rel < rel_end; rel++) | 
|---|
| 598 | { | 
|---|
| 599 | unsigned long r_symndx; | 
|---|
| 600 | struct elf_link_hash_entry *h; | 
|---|
| 601 |  | 
|---|
| 602 | r_symndx = ELF32_R_SYM (rel->r_info); | 
|---|
| 603 | if (r_symndx < symtab_hdr->sh_info) | 
|---|
| 604 | h = NULL; | 
|---|
| 605 | else | 
|---|
| 606 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | 
|---|
| 607 |  | 
|---|
| 608 | r_type = (enum v850_reloc_type) ELF32_R_TYPE (rel->r_info); | 
|---|
| 609 | switch (r_type) | 
|---|
| 610 | { | 
|---|
| 611 | default: | 
|---|
| 612 | case R_V850_NONE: | 
|---|
| 613 | case R_V850_9_PCREL: | 
|---|
| 614 | case R_V850_22_PCREL: | 
|---|
| 615 | case R_V850_HI16_S: | 
|---|
| 616 | case R_V850_HI16: | 
|---|
| 617 | case R_V850_LO16: | 
|---|
| 618 | case R_V850_32: | 
|---|
| 619 | case R_V850_16: | 
|---|
| 620 | case R_V850_8: | 
|---|
| 621 | case R_V850_CALLT_6_7_OFFSET: | 
|---|
| 622 | case R_V850_CALLT_16_16_OFFSET: | 
|---|
| 623 | break; | 
|---|
| 624 |  | 
|---|
| 625 | /* This relocation describes the C++ object vtable hierarchy. | 
|---|
| 626 | Reconstruct it for later use during GC.  */ | 
|---|
| 627 | case R_V850_GNU_VTINHERIT: | 
|---|
| 628 | if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | 
|---|
| 629 | return false; | 
|---|
| 630 | break; | 
|---|
| 631 |  | 
|---|
| 632 | /* This relocation describes which C++ vtable entries are actually | 
|---|
| 633 | used.  Record for later use during GC.  */ | 
|---|
| 634 | case R_V850_GNU_VTENTRY: | 
|---|
| 635 | if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | 
|---|
| 636 | return false; | 
|---|
| 637 | break; | 
|---|
| 638 |  | 
|---|
| 639 | case R_V850_SDA_16_16_SPLIT_OFFSET: | 
|---|
| 640 | case R_V850_SDA_16_16_OFFSET: | 
|---|
| 641 | case R_V850_SDA_15_16_OFFSET: | 
|---|
| 642 | other = V850_OTHER_SDA; | 
|---|
| 643 | common = ".scommon"; | 
|---|
| 644 | goto small_data_common; | 
|---|
| 645 |  | 
|---|
| 646 | case R_V850_ZDA_16_16_SPLIT_OFFSET: | 
|---|
| 647 | case R_V850_ZDA_16_16_OFFSET: | 
|---|
| 648 | case R_V850_ZDA_15_16_OFFSET: | 
|---|
| 649 | other = V850_OTHER_ZDA; | 
|---|
| 650 | common = ".zcommon"; | 
|---|
| 651 | goto small_data_common; | 
|---|
| 652 |  | 
|---|
| 653 | case R_V850_TDA_4_5_OFFSET: | 
|---|
| 654 | case R_V850_TDA_4_4_OFFSET: | 
|---|
| 655 | case R_V850_TDA_6_8_OFFSET: | 
|---|
| 656 | case R_V850_TDA_7_8_OFFSET: | 
|---|
| 657 | case R_V850_TDA_7_7_OFFSET: | 
|---|
| 658 | case R_V850_TDA_16_16_OFFSET: | 
|---|
| 659 | other = V850_OTHER_TDA; | 
|---|
| 660 | common = ".tcommon"; | 
|---|
| 661 | /* fall through */ | 
|---|
| 662 |  | 
|---|
| 663 | #define V850_OTHER_MASK (V850_OTHER_TDA | V850_OTHER_SDA | V850_OTHER_ZDA) | 
|---|
| 664 |  | 
|---|
| 665 | small_data_common: | 
|---|
| 666 | if (h) | 
|---|
| 667 | { | 
|---|
| 668 | h->other |= other;        /* flag which type of relocation was used */ | 
|---|
| 669 | if ((h->other & V850_OTHER_MASK) != (other & V850_OTHER_MASK) | 
|---|
| 670 | && (h->other & V850_OTHER_ERROR) == 0) | 
|---|
| 671 | { | 
|---|
| 672 | const char * msg; | 
|---|
| 673 | static char  buff[200]; /* XXX */ | 
|---|
| 674 |  | 
|---|
| 675 | switch (h->other & V850_OTHER_MASK) | 
|---|
| 676 | { | 
|---|
| 677 | default: | 
|---|
| 678 | msg = _("Variable `%s' cannot occupy in multiple small data regions"); | 
|---|
| 679 | break; | 
|---|
| 680 | case V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA: | 
|---|
| 681 | msg = _("Variable `%s' can only be in one of the small, zero, and tiny data regions"); | 
|---|
| 682 | break; | 
|---|
| 683 | case V850_OTHER_SDA | V850_OTHER_ZDA: | 
|---|
| 684 | msg = _("Variable `%s' cannot be in both small and zero data regions simultaneously"); | 
|---|
| 685 | break; | 
|---|
| 686 | case V850_OTHER_SDA | V850_OTHER_TDA: | 
|---|
| 687 | msg = _("Variable `%s' cannot be in both small and tiny data regions simultaneously"); | 
|---|
| 688 | break; | 
|---|
| 689 | case V850_OTHER_ZDA | V850_OTHER_TDA: | 
|---|
| 690 | msg = _("Variable `%s' cannot be in both zero and tiny data regions simultaneously"); | 
|---|
| 691 | break; | 
|---|
| 692 | } | 
|---|
| 693 |  | 
|---|
| 694 | sprintf (buff, msg, h->root.root.string); | 
|---|
| 695 | info->callbacks->warning (info, buff, h->root.root.string, | 
|---|
| 696 | abfd, h->root.u.def.section, 0); | 
|---|
| 697 |  | 
|---|
| 698 | bfd_set_error (bfd_error_bad_value); | 
|---|
| 699 | h->other |= V850_OTHER_ERROR; | 
|---|
| 700 | ret = false; | 
|---|
| 701 | } | 
|---|
| 702 | } | 
|---|
| 703 |  | 
|---|
| 704 | if (h && h->root.type == bfd_link_hash_common | 
|---|
| 705 | && h->root.u.c.p | 
|---|
| 706 | && !strcmp (bfd_get_section_name (abfd, h->root.u.c.p->section), "COMMON")) | 
|---|
| 707 | { | 
|---|
| 708 | asection *section = h->root.u.c.p->section = bfd_make_section_old_way (abfd, common); | 
|---|
| 709 | section->flags |= SEC_IS_COMMON; | 
|---|
| 710 | } | 
|---|
| 711 |  | 
|---|
| 712 | #ifdef DEBUG | 
|---|
| 713 | fprintf (stderr, "v850_elf_check_relocs, found %s relocation for %s%s\n", | 
|---|
| 714 | v850_elf_howto_table[ (int)r_type ].name, | 
|---|
| 715 | (h && h->root.root.string) ? h->root.root.string : "<unknown>", | 
|---|
| 716 | (h->root.type == bfd_link_hash_common) ? ", symbol is common" : ""); | 
|---|
| 717 | #endif | 
|---|
| 718 | break; | 
|---|
| 719 | } | 
|---|
| 720 | } | 
|---|
| 721 |  | 
|---|
| 722 | return ret; | 
|---|
| 723 | } | 
|---|
| 724 |  | 
|---|
| 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 | */ | 
|---|
| 739 |  | 
|---|
| 740 | typedef struct hi16s_location | 
|---|
| 741 | { | 
|---|
| 742 | bfd_vma       addend; | 
|---|
| 743 | bfd_byte *    address; | 
|---|
| 744 | unsigned long counter; | 
|---|
| 745 | boolean       found; | 
|---|
| 746 | struct hi16s_location * next; | 
|---|
| 747 | } | 
|---|
| 748 | hi16s_location; | 
|---|
| 749 |  | 
|---|
| 750 | static hi16s_location *  previous_hi16s; | 
|---|
| 751 | static hi16s_location *  free_hi16s; | 
|---|
| 752 | static unsigned long     hi16s_counter; | 
|---|
| 753 |  | 
|---|
| 754 | static void | 
|---|
| 755 | remember_hi16s_reloc (abfd, addend, address) | 
|---|
| 756 | bfd *      abfd; | 
|---|
| 757 | bfd_vma    addend; | 
|---|
| 758 | bfd_byte * address; | 
|---|
| 759 | { | 
|---|
| 760 | hi16s_location * entry = NULL; | 
|---|
| 761 |  | 
|---|
| 762 | /* Find a free structure.  */ | 
|---|
| 763 | if (free_hi16s == NULL) | 
|---|
| 764 | free_hi16s = (hi16s_location *) bfd_zalloc (abfd, sizeof (* free_hi16s)); | 
|---|
| 765 |  | 
|---|
| 766 | entry      = free_hi16s; | 
|---|
| 767 | free_hi16s = free_hi16s->next; | 
|---|
| 768 |  | 
|---|
| 769 | entry->addend  = addend; | 
|---|
| 770 | entry->address = address; | 
|---|
| 771 | entry->counter = hi16s_counter ++; | 
|---|
| 772 | entry->found   = false; | 
|---|
| 773 | entry->next    = previous_hi16s; | 
|---|
| 774 | previous_hi16s = entry; | 
|---|
| 775 |  | 
|---|
| 776 | /* Cope with wrap around of our counter.  */ | 
|---|
| 777 | if (hi16s_counter == 0) | 
|---|
| 778 | { | 
|---|
| 779 | /* XXX - Assume that all counter entries differ only in their low 16 bits.  */ | 
|---|
| 780 | for (entry = previous_hi16s; entry != NULL; entry = entry->next) | 
|---|
| 781 | entry->counter &= 0xffff; | 
|---|
| 782 |  | 
|---|
| 783 | hi16s_counter = 0x10000; | 
|---|
| 784 | } | 
|---|
| 785 |  | 
|---|
| 786 | return; | 
|---|
| 787 | } | 
|---|
| 788 |  | 
|---|
| 789 | static bfd_byte * | 
|---|
| 790 | find_remembered_hi16s_reloc (addend, already_found) | 
|---|
| 791 | bfd_vma   addend; | 
|---|
| 792 | boolean * already_found; | 
|---|
| 793 | { | 
|---|
| 794 | hi16s_location * match = NULL; | 
|---|
| 795 | hi16s_location * entry; | 
|---|
| 796 | hi16s_location * previous = NULL; | 
|---|
| 797 | hi16s_location * prev; | 
|---|
| 798 | bfd_byte *       addr; | 
|---|
| 799 |  | 
|---|
| 800 | /* Search the table.  Record the most recent entry that matches.  */ | 
|---|
| 801 | for (entry = previous_hi16s; entry; entry = entry->next) | 
|---|
| 802 | { | 
|---|
| 803 | if (entry->addend == addend | 
|---|
| 804 | && (match == NULL || match->counter < entry->counter)) | 
|---|
| 805 | { | 
|---|
| 806 | previous = prev; | 
|---|
| 807 | match    = entry; | 
|---|
| 808 | } | 
|---|
| 809 |  | 
|---|
| 810 | prev = entry; | 
|---|
| 811 | } | 
|---|
| 812 |  | 
|---|
| 813 | if (match == NULL) | 
|---|
| 814 | return NULL; | 
|---|
| 815 |  | 
|---|
| 816 | /* Extract the address.  */ | 
|---|
| 817 | addr = match->address; | 
|---|
| 818 |  | 
|---|
| 819 | /* Remeber if this entry has already been used before.  */ | 
|---|
| 820 | if (already_found) | 
|---|
| 821 | * already_found = match->found; | 
|---|
| 822 |  | 
|---|
| 823 | /* Note that this entry has now been used.  */ | 
|---|
| 824 | match->found = true; | 
|---|
| 825 |  | 
|---|
| 826 | return addr; | 
|---|
| 827 | } | 
|---|
| 828 |  | 
|---|
| 829 | /* FIXME:  The code here probably ought to be removed and the code in reloc.c | 
|---|
| 830 | allowed to do its  stuff instead.  At least for most of the relocs, anwyay.  */ | 
|---|
| 831 | static bfd_reloc_status_type | 
|---|
| 832 | v850_elf_perform_relocation (abfd, r_type, addend, address) | 
|---|
| 833 | bfd *      abfd; | 
|---|
| 834 | int        r_type; | 
|---|
| 835 | bfd_vma    addend; | 
|---|
| 836 | bfd_byte * address; | 
|---|
| 837 | { | 
|---|
| 838 | unsigned long insn; | 
|---|
| 839 | bfd_signed_vma saddend = (bfd_signed_vma) addend; | 
|---|
| 840 |  | 
|---|
| 841 | switch (r_type) | 
|---|
| 842 | { | 
|---|
| 843 | default: | 
|---|
| 844 | /* fprintf (stderr, "reloc type %d not SUPPORTED\n", r_type ); */ | 
|---|
| 845 | return bfd_reloc_notsupported; | 
|---|
| 846 |  | 
|---|
| 847 | case R_V850_32: | 
|---|
| 848 | bfd_put_32 (abfd, addend, address); | 
|---|
| 849 | return bfd_reloc_ok; | 
|---|
| 850 |  | 
|---|
| 851 | case R_V850_22_PCREL: | 
|---|
| 852 | if (saddend > 0x1fffff || saddend < -0x200000) | 
|---|
| 853 | return bfd_reloc_overflow; | 
|---|
| 854 |  | 
|---|
| 855 | if ((addend % 2) != 0) | 
|---|
| 856 | return bfd_reloc_dangerous; | 
|---|
| 857 |  | 
|---|
| 858 | insn  = bfd_get_32 (abfd, address); | 
|---|
| 859 | insn &= ~0xfffe003f; | 
|---|
| 860 | insn |= (((addend & 0xfffe) << 16) | ((addend & 0x3f0000) >> 16)); | 
|---|
| 861 | bfd_put_32 (abfd, insn, address); | 
|---|
| 862 | return bfd_reloc_ok; | 
|---|
| 863 |  | 
|---|
| 864 | case R_V850_9_PCREL: | 
|---|
| 865 | if (saddend > 0xff || saddend < -0x100) | 
|---|
| 866 | return bfd_reloc_overflow; | 
|---|
| 867 |  | 
|---|
| 868 | if ((addend % 2) != 0) | 
|---|
| 869 | return bfd_reloc_dangerous; | 
|---|
| 870 |  | 
|---|
| 871 | insn  = bfd_get_16 (abfd, address); | 
|---|
| 872 | insn &= ~ 0xf870; | 
|---|
| 873 | insn |= ((addend & 0x1f0) << 7) | ((addend & 0x0e) << 3); | 
|---|
| 874 | break; | 
|---|
| 875 |  | 
|---|
| 876 | case R_V850_HI16: | 
|---|
| 877 | addend += (bfd_get_16 (abfd, address) << 16); | 
|---|
| 878 | addend = (addend >> 16); | 
|---|
| 879 | insn = addend; | 
|---|
| 880 | break; | 
|---|
| 881 |  | 
|---|
| 882 | case R_V850_HI16_S: | 
|---|
| 883 | /* Remember where this relocation took place.  */ | 
|---|
| 884 | remember_hi16s_reloc (abfd, addend, address); | 
|---|
| 885 |  | 
|---|
| 886 | addend += (bfd_get_16 (abfd, address) << 16); | 
|---|
| 887 | addend = (addend >> 16) + ((addend & 0x8000) != 0); | 
|---|
| 888 |  | 
|---|
| 889 | /* This relocation cannot overflow.  */ | 
|---|
| 890 | if (addend > 0x7fff) | 
|---|
| 891 | addend = 0; | 
|---|
| 892 |  | 
|---|
| 893 | insn = addend; | 
|---|
| 894 | break; | 
|---|
| 895 |  | 
|---|
| 896 | case R_V850_LO16: | 
|---|
| 897 | /* Calculate the sum of the value stored in the instruction and the | 
|---|
| 898 | addend and check for overflow from the low 16 bits into the high | 
|---|
| 899 | 16 bits.  The assembler has already done some of this:  If the | 
|---|
| 900 | value stored in the instruction has its 15th bit set, (counting | 
|---|
| 901 | from zero) then the assembler will have added 1 to the value | 
|---|
| 902 | stored in the associated HI16S reloc.  So for example, these | 
|---|
| 903 | relocations: | 
|---|
| 904 |  | 
|---|
| 905 | movhi hi( fred ), r0, r1 | 
|---|
| 906 | movea lo( fred ), r1, r1 | 
|---|
| 907 |  | 
|---|
| 908 | will store 0 in the value fields for the MOVHI and MOVEA instructions | 
|---|
| 909 | and addend will be the address of fred, but for these instructions: | 
|---|
| 910 |  | 
|---|
| 911 | movhi hi( fred + 0x123456), r0, r1 | 
|---|
| 912 | movea lo( fred + 0x123456), r1, r1 | 
|---|
| 913 |  | 
|---|
| 914 | the value stored in the MOVHI instruction will be 0x12 and the value | 
|---|
| 915 | stored in the MOVEA instruction will be 0x3456.  If however the | 
|---|
| 916 | instructions were: | 
|---|
| 917 |  | 
|---|
| 918 | movhi hi( fred + 0x10ffff), r0, r1 | 
|---|
| 919 | movea lo( fred + 0x10ffff), r1, r1 | 
|---|
| 920 |  | 
|---|
| 921 | then the value stored in the MOVHI instruction would be 0x11 (not | 
|---|
| 922 | 0x10) and the value stored in the MOVEA instruction would be 0xffff. | 
|---|
| 923 | Thus (assuming for the moment that the addend is 0), at run time the | 
|---|
| 924 | MOVHI instruction loads 0x110000 into r1, then the MOVEA instruction | 
|---|
| 925 | adds 0xffffffff (sign extension!) producing 0x10ffff.  Similarly if | 
|---|
| 926 | the instructions were: | 
|---|
| 927 |  | 
|---|
| 928 | movhi hi( fred - 1), r0, r1 | 
|---|
| 929 | movea lo( fred - 1), r1, r1 | 
|---|
| 930 |  | 
|---|
| 931 | then 0 is stored in the MOVHI instruction and -1 is stored in the | 
|---|
| 932 | MOVEA instruction. | 
|---|
| 933 |  | 
|---|
| 934 | Overflow can occur if the addition of the value stored in the | 
|---|
| 935 | instruction plus the addend sets the 15th bit when before it was clear. | 
|---|
| 936 | This is because the 15th bit will be sign extended into the high part, | 
|---|
| 937 | thus reducing its value by one, but since the 15th bit was originally | 
|---|
| 938 | clear, the assembler will not have added 1 to the previous HI16S reloc | 
|---|
| 939 | to compensate for this effect.  For example: | 
|---|
| 940 |  | 
|---|
| 941 | movhi hi( fred + 0x123456), r0, r1 | 
|---|
| 942 | movea lo( fred + 0x123456), r1, r1 | 
|---|
| 943 |  | 
|---|
| 944 | The value stored in HI16S reloc is 0x12, the value stored in the LO16 | 
|---|
| 945 | reloc is 0x3456.  If we assume that the address of fred is 0x00007000 | 
|---|
| 946 | then the relocations become: | 
|---|
| 947 |  | 
|---|
| 948 | HI16S: 0x0012 + (0x00007000 >> 16)    = 0x12 | 
|---|
| 949 | LO16:  0x3456 + (0x00007000 & 0xffff) = 0xa456 | 
|---|
| 950 |  | 
|---|
| 951 | but when the instructions are executed, the MOVEA instruction's value | 
|---|
| 952 | is signed extended, so the sum becomes: | 
|---|
| 953 |  | 
|---|
| 954 | 0x00120000 | 
|---|
| 955 | + 0xffffa456 | 
|---|
| 956 | ------------ | 
|---|
| 957 | 0x0011a456    but 'fred + 0x123456' = 0x0012a456 | 
|---|
| 958 |  | 
|---|
| 959 | Note that if the 15th bit was set in the value stored in the LO16 | 
|---|
| 960 | reloc, then we do not have to do anything: | 
|---|
| 961 |  | 
|---|
| 962 | movhi hi( fred + 0x10ffff), r0, r1 | 
|---|
| 963 | movea lo( fred + 0x10ffff), r1, r1 | 
|---|
| 964 |  | 
|---|
| 965 | HI16S:  0x0011 + (0x00007000 >> 16)    = 0x11 | 
|---|
| 966 | LO16:   0xffff + (0x00007000 & 0xffff) = 0x6fff | 
|---|
| 967 |  | 
|---|
| 968 | 0x00110000 | 
|---|
| 969 | + 0x00006fff | 
|---|
| 970 | ------------ | 
|---|
| 971 | 0x00116fff  = fred + 0x10ffff = 0x7000 + 0x10ffff | 
|---|
| 972 |  | 
|---|
| 973 | Overflow can also occur if the computation carries into the 16th bit | 
|---|
| 974 | and it also results in the 15th bit having the same value as the 15th | 
|---|
| 975 | bit of the original value.   What happens is that the HI16S reloc | 
|---|
| 976 | will have already examined the 15th bit of the original value and | 
|---|
| 977 | added 1 to the high part if the bit is set.  This compensates for the | 
|---|
| 978 | sign extension of 15th bit of the result of the computation.  But now | 
|---|
| 979 | there is a carry into the 16th bit, and this has not been allowed for. | 
|---|
| 980 |  | 
|---|
| 981 | So, for example if fred is at address 0xf000: | 
|---|
| 982 |  | 
|---|
| 983 | movhi hi( fred + 0xffff), r0, r1    [bit 15 of the offset is set] | 
|---|
| 984 | movea lo( fred + 0xffff), r1, r1 | 
|---|
| 985 |  | 
|---|
| 986 | HI16S: 0x0001 + (0x0000f000 >> 16)    = 0x0001 | 
|---|
| 987 | LO16:  0xffff + (0x0000f000 & 0xffff) = 0xefff   (carry into bit 16 is lost) | 
|---|
| 988 |  | 
|---|
| 989 | 0x00010000 | 
|---|
| 990 | + 0xffffefff | 
|---|
| 991 | ------------ | 
|---|
| 992 | 0x0000efff   but 'fred + 0xffff' = 0x0001efff | 
|---|
| 993 |  | 
|---|
| 994 | Similarly, if the 15th bit remains clear, but overflow occurs into | 
|---|
| 995 | the 16th bit then (assuming the address of fred is 0xf000): | 
|---|
| 996 |  | 
|---|
| 997 | movhi hi( fred + 0x7000), r0, r1    [bit 15 of the offset is clear] | 
|---|
| 998 | movea lo( fred + 0x7000), r1, r1 | 
|---|
| 999 |  | 
|---|
| 1000 | HI16S: 0x0000 + (0x0000f000 >> 16)    = 0x0000 | 
|---|
| 1001 | LO16:  0x7000 + (0x0000f000 & 0xffff) = 0x6fff  (carry into bit 16 is lost) | 
|---|
| 1002 |  | 
|---|
| 1003 | 0x00000000 | 
|---|
| 1004 | + 0x00006fff | 
|---|
| 1005 | ------------ | 
|---|
| 1006 | 0x00006fff   but 'fred + 0x7000' = 0x00016fff | 
|---|
| 1007 |  | 
|---|
| 1008 | Note - there is no need to change anything if a carry occurs, and the | 
|---|
| 1009 | 15th bit changes its value from being set to being clear, as the HI16S | 
|---|
| 1010 | reloc will have already added in 1 to the high part for us: | 
|---|
| 1011 |  | 
|---|
| 1012 | movhi hi( fred + 0xffff), r0, r1     [bit 15 of the offset is set] | 
|---|
| 1013 | movea lo( fred + 0xffff), r1, r1 | 
|---|
| 1014 |  | 
|---|
| 1015 | HI16S: 0x0001 + (0x00007000 >> 16) | 
|---|
| 1016 | LO16:  0xffff + (0x00007000 & 0xffff) = 0x6fff  (carry into bit 16 is lost) | 
|---|
| 1017 |  | 
|---|
| 1018 | 0x00010000 | 
|---|
| 1019 | + 0x00006fff   (bit 15 not set, so the top half is zero) | 
|---|
| 1020 | ------------ | 
|---|
| 1021 | 0x00016fff   which is right (assuming that fred is at 0x7000) | 
|---|
| 1022 |  | 
|---|
| 1023 | but if the 15th bit goes from being clear to being set, then we must | 
|---|
| 1024 | once again handle overflow: | 
|---|
| 1025 |  | 
|---|
| 1026 | movhi hi( fred + 0x7000), r0, r1     [bit 15 of the offset is clear] | 
|---|
| 1027 | movea lo( fred + 0x7000), r1, r1 | 
|---|
| 1028 |  | 
|---|
| 1029 | HI16S: 0x0000 + (0x0000ffff >> 16) | 
|---|
| 1030 | LO16:  0x7000 + (0x0000ffff & 0xffff) = 0x6fff  (carry into bit 16) | 
|---|
| 1031 |  | 
|---|
| 1032 | 0x00000000 | 
|---|
| 1033 | + 0x00006fff   (bit 15 not set, so the top half is zero) | 
|---|
| 1034 | ------------ | 
|---|
| 1035 | 0x00006fff   which is wrong (assuming that fred is at 0xffff) | 
|---|
| 1036 | */ | 
|---|
| 1037 |  | 
|---|
| 1038 | { | 
|---|
| 1039 | long result; | 
|---|
| 1040 |  | 
|---|
| 1041 | insn   = bfd_get_16 (abfd, address); | 
|---|
| 1042 | result = insn + addend; | 
|---|
| 1043 |  | 
|---|
| 1044 | #define BIT15_SET(x) ((x) & 0x8000) | 
|---|
| 1045 | #define OVERFLOWS(a,i) ((((a) & 0xffff) + (i)) > 0xffff) | 
|---|
| 1046 |  | 
|---|
| 1047 | if ((BIT15_SET (result) && ! BIT15_SET (addend)) | 
|---|
| 1048 | || (OVERFLOWS (addend, insn) | 
|---|
| 1049 | && ((! BIT15_SET (insn)) || (BIT15_SET (addend))))) | 
|---|
| 1050 | { | 
|---|
| 1051 | boolean already_updated; | 
|---|
| 1052 | bfd_byte * hi16s_address = find_remembered_hi16s_reloc | 
|---|
| 1053 | (addend, & already_updated); | 
|---|
| 1054 |  | 
|---|
| 1055 | /* Amend the matching HI16_S relocation.  */ | 
|---|
| 1056 | if (hi16s_address != NULL) | 
|---|
| 1057 | { | 
|---|
| 1058 | if (! already_updated) | 
|---|
| 1059 | { | 
|---|
| 1060 | insn = bfd_get_16 (abfd, hi16s_address); | 
|---|
| 1061 | insn += 1; | 
|---|
| 1062 | bfd_put_16 (abfd, insn, hi16s_address); | 
|---|
| 1063 | } | 
|---|
| 1064 | } | 
|---|
| 1065 | else | 
|---|
| 1066 | { | 
|---|
| 1067 | fprintf (stderr, _("FAILED to find previous HI16 reloc\n")); | 
|---|
| 1068 | return bfd_reloc_overflow; | 
|---|
| 1069 | } | 
|---|
| 1070 | } | 
|---|
| 1071 |  | 
|---|
| 1072 | /* Do not complain if value has top bit set, as this has been anticipated.  */ | 
|---|
| 1073 | insn = result & 0xffff; | 
|---|
| 1074 | break; | 
|---|
| 1075 | } | 
|---|
| 1076 |  | 
|---|
| 1077 | case R_V850_8: | 
|---|
| 1078 | addend += (char) bfd_get_8 (abfd, address); | 
|---|
| 1079 |  | 
|---|
| 1080 | saddend = (bfd_signed_vma) addend; | 
|---|
| 1081 |  | 
|---|
| 1082 | if (saddend > 0x7f || saddend < -0x80) | 
|---|
| 1083 | return bfd_reloc_overflow; | 
|---|
| 1084 |  | 
|---|
| 1085 | bfd_put_8 (abfd, addend, address); | 
|---|
| 1086 | return bfd_reloc_ok; | 
|---|
| 1087 |  | 
|---|
| 1088 | case R_V850_CALLT_16_16_OFFSET: | 
|---|
| 1089 | addend += bfd_get_16 (abfd, address); | 
|---|
| 1090 |  | 
|---|
| 1091 | saddend = (bfd_signed_vma) addend; | 
|---|
| 1092 |  | 
|---|
| 1093 | if (saddend > 0xffff || saddend < 0) | 
|---|
| 1094 | return bfd_reloc_overflow; | 
|---|
| 1095 |  | 
|---|
| 1096 | insn = addend; | 
|---|
| 1097 | break; | 
|---|
| 1098 |  | 
|---|
| 1099 | case R_V850_16: | 
|---|
| 1100 |  | 
|---|
| 1101 | /* drop through */ | 
|---|
| 1102 | case R_V850_SDA_16_16_OFFSET: | 
|---|
| 1103 | case R_V850_ZDA_16_16_OFFSET: | 
|---|
| 1104 | case R_V850_TDA_16_16_OFFSET: | 
|---|
| 1105 | addend += bfd_get_16 (abfd, address); | 
|---|
| 1106 |  | 
|---|
| 1107 | saddend = (bfd_signed_vma) addend; | 
|---|
| 1108 |  | 
|---|
| 1109 | if (saddend > 0x7fff || saddend < -0x8000) | 
|---|
| 1110 | return bfd_reloc_overflow; | 
|---|
| 1111 |  | 
|---|
| 1112 | insn = addend; | 
|---|
| 1113 | break; | 
|---|
| 1114 |  | 
|---|
| 1115 | case R_V850_SDA_15_16_OFFSET: | 
|---|
| 1116 | case R_V850_ZDA_15_16_OFFSET: | 
|---|
| 1117 | insn = bfd_get_16 (abfd, address); | 
|---|
| 1118 | addend += (insn & 0xfffe); | 
|---|
| 1119 |  | 
|---|
| 1120 | saddend = (bfd_signed_vma) addend; | 
|---|
| 1121 |  | 
|---|
| 1122 | if (saddend > 0x7ffe || saddend < -0x8000) | 
|---|
| 1123 | return bfd_reloc_overflow; | 
|---|
| 1124 |  | 
|---|
| 1125 | if (addend & 1) | 
|---|
| 1126 | return bfd_reloc_dangerous; | 
|---|
| 1127 |  | 
|---|
| 1128 | insn = (addend & ~1) | (insn & 1); | 
|---|
| 1129 | break; | 
|---|
| 1130 |  | 
|---|
| 1131 | case R_V850_TDA_6_8_OFFSET: | 
|---|
| 1132 | insn = bfd_get_16 (abfd, address); | 
|---|
| 1133 | addend += ((insn & 0x7e) << 1); | 
|---|
| 1134 |  | 
|---|
| 1135 | saddend = (bfd_signed_vma) addend; | 
|---|
| 1136 |  | 
|---|
| 1137 | if (saddend > 0xfc || saddend < 0) | 
|---|
| 1138 | return bfd_reloc_overflow; | 
|---|
| 1139 |  | 
|---|
| 1140 | if (addend & 3) | 
|---|
| 1141 | return bfd_reloc_dangerous; | 
|---|
| 1142 |  | 
|---|
| 1143 | insn &= 0xff81; | 
|---|
| 1144 | insn |= (addend >> 1); | 
|---|
| 1145 | break; | 
|---|
| 1146 |  | 
|---|
| 1147 | case R_V850_TDA_7_8_OFFSET: | 
|---|
| 1148 | insn = bfd_get_16 (abfd, address); | 
|---|
| 1149 | addend += ((insn & 0x7f) << 1); | 
|---|
| 1150 |  | 
|---|
| 1151 | saddend = (bfd_signed_vma) addend; | 
|---|
| 1152 |  | 
|---|
| 1153 | if (saddend > 0xfe || saddend < 0) | 
|---|
| 1154 | return bfd_reloc_overflow; | 
|---|
| 1155 |  | 
|---|
| 1156 | if (addend & 1) | 
|---|
| 1157 | return bfd_reloc_dangerous; | 
|---|
| 1158 |  | 
|---|
| 1159 | insn &= 0xff80; | 
|---|
| 1160 | insn |= (addend >> 1); | 
|---|
| 1161 | break; | 
|---|
| 1162 |  | 
|---|
| 1163 | case R_V850_TDA_7_7_OFFSET: | 
|---|
| 1164 | insn = bfd_get_16 (abfd, address); | 
|---|
| 1165 | addend += insn & 0x7f; | 
|---|
| 1166 |  | 
|---|
| 1167 | saddend = (bfd_signed_vma) addend; | 
|---|
| 1168 |  | 
|---|
| 1169 | if (saddend > 0x7f || saddend < 0) | 
|---|
| 1170 | return bfd_reloc_overflow; | 
|---|
| 1171 |  | 
|---|
| 1172 | insn &= 0xff80; | 
|---|
| 1173 | insn |= addend; | 
|---|
| 1174 | break; | 
|---|
| 1175 |  | 
|---|
| 1176 | case R_V850_TDA_4_5_OFFSET: | 
|---|
| 1177 | insn = bfd_get_16 (abfd, address); | 
|---|
| 1178 | addend += ((insn & 0xf) << 1); | 
|---|
| 1179 |  | 
|---|
| 1180 | saddend = (bfd_signed_vma) addend; | 
|---|
| 1181 |  | 
|---|
| 1182 | if (saddend > 0x1e || saddend < 0) | 
|---|
| 1183 | return bfd_reloc_overflow; | 
|---|
| 1184 |  | 
|---|
| 1185 | if (addend & 1) | 
|---|
| 1186 | return bfd_reloc_dangerous; | 
|---|
| 1187 |  | 
|---|
| 1188 | insn &= 0xfff0; | 
|---|
| 1189 | insn |= (addend >> 1); | 
|---|
| 1190 | break; | 
|---|
| 1191 |  | 
|---|
| 1192 | case R_V850_TDA_4_4_OFFSET: | 
|---|
| 1193 | insn = bfd_get_16 (abfd, address); | 
|---|
| 1194 | addend += insn & 0xf; | 
|---|
| 1195 |  | 
|---|
| 1196 | saddend = (bfd_signed_vma) addend; | 
|---|
| 1197 |  | 
|---|
| 1198 | if (saddend > 0xf || saddend < 0) | 
|---|
| 1199 | return bfd_reloc_overflow; | 
|---|
| 1200 |  | 
|---|
| 1201 | insn &= 0xfff0; | 
|---|
| 1202 | insn |= addend; | 
|---|
| 1203 | break; | 
|---|
| 1204 |  | 
|---|
| 1205 | case R_V850_ZDA_16_16_SPLIT_OFFSET: | 
|---|
| 1206 | case R_V850_SDA_16_16_SPLIT_OFFSET: | 
|---|
| 1207 | insn = bfd_get_32 (abfd, address); | 
|---|
| 1208 | addend += ((insn & 0xfffe0000) >> 16) + ((insn & 0x20) >> 5); | 
|---|
| 1209 |  | 
|---|
| 1210 | saddend = (bfd_signed_vma) addend; | 
|---|
| 1211 |  | 
|---|
| 1212 | if (saddend > 0x7fff || saddend < -0x8000) | 
|---|
| 1213 | return bfd_reloc_overflow; | 
|---|
| 1214 |  | 
|---|
| 1215 | insn &= 0x0001ffdf; | 
|---|
| 1216 | insn |= (addend & 1) << 5; | 
|---|
| 1217 | insn |= (addend & ~1) << 16; | 
|---|
| 1218 |  | 
|---|
| 1219 | bfd_put_32 (abfd, insn, address); | 
|---|
| 1220 | return bfd_reloc_ok; | 
|---|
| 1221 |  | 
|---|
| 1222 | case R_V850_CALLT_6_7_OFFSET: | 
|---|
| 1223 | insn = bfd_get_16 (abfd, address); | 
|---|
| 1224 | addend += ((insn & 0x3f) << 1); | 
|---|
| 1225 |  | 
|---|
| 1226 | saddend = (bfd_signed_vma) addend; | 
|---|
| 1227 |  | 
|---|
| 1228 | if (saddend > 0x7e || saddend < 0) | 
|---|
| 1229 | return bfd_reloc_overflow; | 
|---|
| 1230 |  | 
|---|
| 1231 | if (addend & 1) | 
|---|
| 1232 | return bfd_reloc_dangerous; | 
|---|
| 1233 |  | 
|---|
| 1234 | insn &= 0xff80; | 
|---|
| 1235 | insn |= (addend >> 1); | 
|---|
| 1236 | break; | 
|---|
| 1237 |  | 
|---|
| 1238 | case R_V850_GNU_VTINHERIT: | 
|---|
| 1239 | case R_V850_GNU_VTENTRY: | 
|---|
| 1240 | return bfd_reloc_ok; | 
|---|
| 1241 |  | 
|---|
| 1242 | } | 
|---|
| 1243 |  | 
|---|
| 1244 | bfd_put_16 (abfd, insn, address); | 
|---|
| 1245 | return bfd_reloc_ok; | 
|---|
| 1246 | } | 
|---|
| 1247 |  | 
|---|
| 1248 |  | 
|---|
| 1249 | /* Insert the addend into the instruction.  */ | 
|---|
| 1250 | static bfd_reloc_status_type | 
|---|
| 1251 | v850_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; | 
|---|
| 1259 | { | 
|---|
| 1260 | long relocation; | 
|---|
| 1261 |  | 
|---|
| 1262 | /* If there is an output BFD, | 
|---|
| 1263 | and the symbol is not a section name (which is only defined at final link time), | 
|---|
| 1264 | 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 | 
|---|
| 1266 | then just fixup the address and return.  */ | 
|---|
| 1267 | if (obfd != (bfd *) NULL | 
|---|
| 1268 | && (symbol->flags & BSF_SECTION_SYM) == 0 | 
|---|
| 1269 | && (! reloc->howto->partial_inplace | 
|---|
| 1270 | || reloc->addend == 0)) | 
|---|
| 1271 | { | 
|---|
| 1272 | reloc->address += isection->output_offset; | 
|---|
| 1273 | return bfd_reloc_ok; | 
|---|
| 1274 | } | 
|---|
| 1275 | #if 0 | 
|---|
| 1276 | else if (obfd != NULL) | 
|---|
| 1277 | { | 
|---|
| 1278 | return bfd_reloc_continue; | 
|---|
| 1279 | } | 
|---|
| 1280 | #endif | 
|---|
| 1281 |  | 
|---|
| 1282 | /* Catch relocs involving undefined symbols.  */ | 
|---|
| 1283 | if (bfd_is_und_section (symbol->section) | 
|---|
| 1284 | && (symbol->flags & BSF_WEAK) == 0 | 
|---|
| 1285 | && obfd == NULL) | 
|---|
| 1286 | return bfd_reloc_undefined; | 
|---|
| 1287 |  | 
|---|
| 1288 | /* We handle final linking of some relocs ourselves.  */ | 
|---|
| 1289 |  | 
|---|
| 1290 | /* Is the address of the relocation really within the section?  */ | 
|---|
| 1291 | if (reloc->address > isection->_cooked_size) | 
|---|
| 1292 | return bfd_reloc_outofrange; | 
|---|
| 1293 |  | 
|---|
| 1294 | /* Work out which section the relocation is targetted at and the | 
|---|
| 1295 | initial relocation command value.  */ | 
|---|
| 1296 |  | 
|---|
| 1297 | /* Get symbol value.  (Common symbols are special.)  */ | 
|---|
| 1298 | if (bfd_is_com_section (symbol->section)) | 
|---|
| 1299 | relocation = 0; | 
|---|
| 1300 | else | 
|---|
| 1301 | relocation = symbol->value; | 
|---|
| 1302 |  | 
|---|
| 1303 | /* Convert input-section-relative symbol value to absolute + addend.  */ | 
|---|
| 1304 | relocation += symbol->section->output_section->vma; | 
|---|
| 1305 | relocation += symbol->section->output_offset; | 
|---|
| 1306 | relocation += reloc->addend; | 
|---|
| 1307 |  | 
|---|
| 1308 | #if 0 /* Since this reloc is going to be processed later on, we should | 
|---|
| 1309 | not make it pc-relative here.  To test this, try assembling and | 
|---|
| 1310 | linking this program: | 
|---|
| 1311 |  | 
|---|
| 1312 | .text | 
|---|
| 1313 | .globl _start | 
|---|
| 1314 | nop | 
|---|
| 1315 | _start: | 
|---|
| 1316 | jr foo | 
|---|
| 1317 |  | 
|---|
| 1318 | .section ".foo","ax" | 
|---|
| 1319 | nop | 
|---|
| 1320 | foo: | 
|---|
| 1321 | nop | 
|---|
| 1322 | */ | 
|---|
| 1323 | if (reloc->howto->pc_relative == true) | 
|---|
| 1324 | { | 
|---|
| 1325 | /* Here the variable relocation holds the final address of the | 
|---|
| 1326 | symbol we are relocating against, plus any addend.  */ | 
|---|
| 1327 | relocation -= isection->output_section->vma + isection->output_offset; | 
|---|
| 1328 |  | 
|---|
| 1329 | /* Deal with pcrel_offset */ | 
|---|
| 1330 | relocation -= reloc->address; | 
|---|
| 1331 | } | 
|---|
| 1332 | #endif | 
|---|
| 1333 | reloc->addend = relocation; | 
|---|
| 1334 | return bfd_reloc_ok; | 
|---|
| 1335 | } | 
|---|
| 1336 |  | 
|---|
| 1337 |  | 
|---|
| 1338 | static boolean | 
|---|
| 1339 | v850_elf_is_local_label_name (abfd, name) | 
|---|
| 1340 | bfd *         abfd ATTRIBUTE_UNUSED; | 
|---|
| 1341 | const char *  name; | 
|---|
| 1342 | { | 
|---|
| 1343 | return (   (name[0] == '.' && (name[1] == 'L' || name[1] == '.')) | 
|---|
| 1344 | || (name[0] == '_' &&  name[1] == '.' && name[2] == 'L' && name[3] == '_')); | 
|---|
| 1345 | } | 
|---|
| 1346 |  | 
|---|
| 1347 |  | 
|---|
| 1348 | /* Perform a relocation as part of a final link.  */ | 
|---|
| 1349 | static bfd_reloc_status_type | 
|---|
| 1350 | v850_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; | 
|---|
| 1364 | { | 
|---|
| 1365 | unsigned long  r_type   = howto->type; | 
|---|
| 1366 | bfd_byte *     hit_data = contents + offset; | 
|---|
| 1367 |  | 
|---|
| 1368 | /* Adjust the value according to the relocation.  */ | 
|---|
| 1369 | switch (r_type) | 
|---|
| 1370 | { | 
|---|
| 1371 | case R_V850_9_PCREL: | 
|---|
| 1372 | value -= (input_section->output_section->vma | 
|---|
| 1373 | + input_section->output_offset); | 
|---|
| 1374 | value -= offset; | 
|---|
| 1375 | break; | 
|---|
| 1376 |  | 
|---|
| 1377 | case R_V850_22_PCREL: | 
|---|
| 1378 | value -= (input_section->output_section->vma | 
|---|
| 1379 | + input_section->output_offset | 
|---|
| 1380 | + offset); | 
|---|
| 1381 |  | 
|---|
| 1382 | /* If the sign extension will corrupt the value then we have overflowed.  */ | 
|---|
| 1383 | if (((value & 0xff000000) != 0x0) && ((value & 0xff000000) != 0xff000000)) | 
|---|
| 1384 | return bfd_reloc_overflow; | 
|---|
| 1385 |  | 
|---|
| 1386 | value = SEXT24 (value);  /* Only the bottom 24 bits of the PC are valid */ | 
|---|
| 1387 | break; | 
|---|
| 1388 |  | 
|---|
| 1389 | case R_V850_HI16_S: | 
|---|
| 1390 | case R_V850_HI16: | 
|---|
| 1391 | case R_V850_LO16: | 
|---|
| 1392 | case R_V850_16: | 
|---|
| 1393 | case R_V850_32: | 
|---|
| 1394 | case R_V850_8: | 
|---|
| 1395 | break; | 
|---|
| 1396 |  | 
|---|
| 1397 | case R_V850_ZDA_15_16_OFFSET: | 
|---|
| 1398 | case R_V850_ZDA_16_16_OFFSET: | 
|---|
| 1399 | case R_V850_ZDA_16_16_SPLIT_OFFSET: | 
|---|
| 1400 | if (sym_sec == NULL) | 
|---|
| 1401 | return bfd_reloc_undefined; | 
|---|
| 1402 |  | 
|---|
| 1403 | value -= sym_sec->output_section->vma; | 
|---|
| 1404 | break; | 
|---|
| 1405 |  | 
|---|
| 1406 | case R_V850_SDA_15_16_OFFSET: | 
|---|
| 1407 | case R_V850_SDA_16_16_OFFSET: | 
|---|
| 1408 | case R_V850_SDA_16_16_SPLIT_OFFSET: | 
|---|
| 1409 | { | 
|---|
| 1410 | unsigned long                gp; | 
|---|
| 1411 | struct bfd_link_hash_entry * h; | 
|---|
| 1412 |  | 
|---|
| 1413 | if (sym_sec == NULL) | 
|---|
| 1414 | return bfd_reloc_undefined; | 
|---|
| 1415 |  | 
|---|
| 1416 | /* Get the value of __gp.  */ | 
|---|
| 1417 | h = bfd_link_hash_lookup (info->hash, "__gp", false, false, true); | 
|---|
| 1418 | if (h == (struct bfd_link_hash_entry *) NULL | 
|---|
| 1419 | || h->type != bfd_link_hash_defined) | 
|---|
| 1420 | return bfd_reloc_other; | 
|---|
| 1421 |  | 
|---|
| 1422 | gp = (h->u.def.value | 
|---|
| 1423 | + h->u.def.section->output_section->vma | 
|---|
| 1424 | + h->u.def.section->output_offset); | 
|---|
| 1425 |  | 
|---|
| 1426 | value -= sym_sec->output_section->vma; | 
|---|
| 1427 | value -= (gp - sym_sec->output_section->vma); | 
|---|
| 1428 | } | 
|---|
| 1429 | break; | 
|---|
| 1430 |  | 
|---|
| 1431 | case R_V850_TDA_4_4_OFFSET: | 
|---|
| 1432 | case R_V850_TDA_4_5_OFFSET: | 
|---|
| 1433 | case R_V850_TDA_16_16_OFFSET: | 
|---|
| 1434 | case R_V850_TDA_7_7_OFFSET: | 
|---|
| 1435 | case R_V850_TDA_7_8_OFFSET: | 
|---|
| 1436 | case R_V850_TDA_6_8_OFFSET: | 
|---|
| 1437 | { | 
|---|
| 1438 | unsigned long                ep; | 
|---|
| 1439 | struct bfd_link_hash_entry * h; | 
|---|
| 1440 |  | 
|---|
| 1441 | /* Get the value of __ep.  */ | 
|---|
| 1442 | h = bfd_link_hash_lookup (info->hash, "__ep", false, false, true); | 
|---|
| 1443 | if (h == (struct bfd_link_hash_entry *) NULL | 
|---|
| 1444 | || h->type != bfd_link_hash_defined) | 
|---|
| 1445 | return bfd_reloc_continue;  /* Actually this indicates that __ep could not be found.  */ | 
|---|
| 1446 |  | 
|---|
| 1447 | ep = (h->u.def.value | 
|---|
| 1448 | + h->u.def.section->output_section->vma | 
|---|
| 1449 | + h->u.def.section->output_offset); | 
|---|
| 1450 |  | 
|---|
| 1451 | value -= ep; | 
|---|
| 1452 | } | 
|---|
| 1453 | break; | 
|---|
| 1454 |  | 
|---|
| 1455 | case R_V850_CALLT_6_7_OFFSET: | 
|---|
| 1456 | { | 
|---|
| 1457 | unsigned long                ctbp; | 
|---|
| 1458 | struct bfd_link_hash_entry * h; | 
|---|
| 1459 |  | 
|---|
| 1460 | /* Get the value of __ctbp.  */ | 
|---|
| 1461 | h = bfd_link_hash_lookup (info->hash, "__ctbp", false, false, true); | 
|---|
| 1462 | if (h == (struct bfd_link_hash_entry *) NULL | 
|---|
| 1463 | || h->type != bfd_link_hash_defined) | 
|---|
| 1464 | return (bfd_reloc_dangerous + 1);  /* Actually this indicates that __ctbp could not be found.  */ | 
|---|
| 1465 |  | 
|---|
| 1466 | ctbp = (h->u.def.value | 
|---|
| 1467 | + h->u.def.section->output_section->vma | 
|---|
| 1468 | + h->u.def.section->output_offset); | 
|---|
| 1469 | value -= ctbp; | 
|---|
| 1470 | } | 
|---|
| 1471 | break; | 
|---|
| 1472 |  | 
|---|
| 1473 | case R_V850_CALLT_16_16_OFFSET: | 
|---|
| 1474 | { | 
|---|
| 1475 | unsigned long                ctbp; | 
|---|
| 1476 | struct bfd_link_hash_entry * h; | 
|---|
| 1477 |  | 
|---|
| 1478 | if (sym_sec == NULL) | 
|---|
| 1479 | return bfd_reloc_undefined; | 
|---|
| 1480 |  | 
|---|
| 1481 | /* Get the value of __ctbp.  */ | 
|---|
| 1482 | h = bfd_link_hash_lookup (info->hash, "__ctbp", false, false, true); | 
|---|
| 1483 | if (h == (struct bfd_link_hash_entry *) NULL | 
|---|
| 1484 | || h->type != bfd_link_hash_defined) | 
|---|
| 1485 | return (bfd_reloc_dangerous + 1); | 
|---|
| 1486 |  | 
|---|
| 1487 | ctbp = (h->u.def.value | 
|---|
| 1488 | + h->u.def.section->output_section->vma | 
|---|
| 1489 | + h->u.def.section->output_offset); | 
|---|
| 1490 |  | 
|---|
| 1491 | value -= sym_sec->output_section->vma; | 
|---|
| 1492 | value -= (ctbp - sym_sec->output_section->vma); | 
|---|
| 1493 | } | 
|---|
| 1494 | break; | 
|---|
| 1495 |  | 
|---|
| 1496 | case R_V850_NONE: | 
|---|
| 1497 | case R_V850_GNU_VTINHERIT: | 
|---|
| 1498 | case R_V850_GNU_VTENTRY: | 
|---|
| 1499 | return bfd_reloc_ok; | 
|---|
| 1500 |  | 
|---|
| 1501 | default: | 
|---|
| 1502 | return bfd_reloc_notsupported; | 
|---|
| 1503 | } | 
|---|
| 1504 |  | 
|---|
| 1505 | /* Perform the relocation.  */ | 
|---|
| 1506 | return v850_elf_perform_relocation (input_bfd, r_type, value + addend, hit_data); | 
|---|
| 1507 | } | 
|---|
| 1508 |  | 
|---|
| 1509 |  | 
|---|
| 1510 | /* Relocate an V850 ELF section.  */ | 
|---|
| 1511 | static boolean | 
|---|
| 1512 | v850_elf_relocate_section (output_bfd, info, input_bfd, input_section, | 
|---|
| 1513 | 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; | 
|---|
| 1522 | { | 
|---|
| 1523 | Elf_Internal_Shdr *           symtab_hdr; | 
|---|
| 1524 | struct elf_link_hash_entry ** sym_hashes; | 
|---|
| 1525 | Elf_Internal_Rela *           rel; | 
|---|
| 1526 | Elf_Internal_Rela *           relend; | 
|---|
| 1527 |  | 
|---|
| 1528 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; | 
|---|
| 1529 | sym_hashes = elf_sym_hashes (input_bfd); | 
|---|
| 1530 |  | 
|---|
| 1531 | if (sym_hashes == NULL) | 
|---|
| 1532 | { | 
|---|
| 1533 | info->callbacks->warning | 
|---|
| 1534 | (info, "no hash table available", NULL, input_bfd, input_section, 0); | 
|---|
| 1535 |  | 
|---|
| 1536 | return false; | 
|---|
| 1537 | } | 
|---|
| 1538 |  | 
|---|
| 1539 | /* Reset the list of remembered HI16S relocs to empty.  */ | 
|---|
| 1540 | free_hi16s     = previous_hi16s; | 
|---|
| 1541 | previous_hi16s = NULL; | 
|---|
| 1542 | hi16s_counter  = 0; | 
|---|
| 1543 |  | 
|---|
| 1544 | rel    = relocs; | 
|---|
| 1545 | relend = relocs + input_section->reloc_count; | 
|---|
| 1546 | for (; rel < relend; rel++) | 
|---|
| 1547 | { | 
|---|
| 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; | 
|---|
| 1556 |  | 
|---|
| 1557 | r_symndx = ELF32_R_SYM (rel->r_info); | 
|---|
| 1558 | r_type   = ELF32_R_TYPE (rel->r_info); | 
|---|
| 1559 |  | 
|---|
| 1560 | if (r_type == R_V850_GNU_VTENTRY | 
|---|
| 1561 | || r_type == R_V850_GNU_VTINHERIT) | 
|---|
| 1562 | continue; | 
|---|
| 1563 |  | 
|---|
| 1564 | 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.  */ | 
|---|
| 1586 | h = NULL; | 
|---|
| 1587 | sym = NULL; | 
|---|
| 1588 | sec = NULL; | 
|---|
| 1589 | if (r_symndx < symtab_hdr->sh_info) | 
|---|
| 1590 | { | 
|---|
| 1591 | sym = local_syms + r_symndx; | 
|---|
| 1592 | sec = local_sections[r_symndx]; | 
|---|
| 1593 | relocation = (sec->output_section->vma | 
|---|
| 1594 | + sec->output_offset | 
|---|
| 1595 | + sym->st_value); | 
|---|
| 1596 | #if 0 | 
|---|
| 1597 | { | 
|---|
| 1598 | char * name; | 
|---|
| 1599 | name = bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link, sym->st_name); | 
|---|
| 1600 | 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); | 
|---|
| 1604 | } | 
|---|
| 1605 | #endif | 
|---|
| 1606 | } | 
|---|
| 1607 | else | 
|---|
| 1608 | { | 
|---|
| 1609 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | 
|---|
| 1610 |  | 
|---|
| 1611 | while (h->root.type == bfd_link_hash_indirect | 
|---|
| 1612 | || h->root.type == bfd_link_hash_warning) | 
|---|
| 1613 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | 
|---|
| 1614 |  | 
|---|
| 1615 | if (h->root.type == bfd_link_hash_defined | 
|---|
| 1616 | || h->root.type == bfd_link_hash_defweak) | 
|---|
| 1617 | { | 
|---|
| 1618 | sec = h->root.u.def.section; | 
|---|
| 1619 | relocation = (h->root.u.def.value | 
|---|
| 1620 | + sec->output_section->vma | 
|---|
| 1621 | + sec->output_offset); | 
|---|
| 1622 | #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); | 
|---|
| 1625 | #endif | 
|---|
| 1626 | } | 
|---|
| 1627 | else if (h->root.type == bfd_link_hash_undefweak) | 
|---|
| 1628 | { | 
|---|
| 1629 | #if 0 | 
|---|
| 1630 | fprintf (stderr, "undefined: sec: %s, name: %s\n", | 
|---|
| 1631 | sec->name, h->root.root.string); | 
|---|
| 1632 | #endif | 
|---|
| 1633 | relocation = 0; | 
|---|
| 1634 | } | 
|---|
| 1635 | else | 
|---|
| 1636 | { | 
|---|
| 1637 | if (! ((*info->callbacks->undefined_symbol) | 
|---|
| 1638 | (info, h->root.root.string, input_bfd, | 
|---|
| 1639 | input_section, rel->r_offset, true))) | 
|---|
| 1640 | return false; | 
|---|
| 1641 | #if 0 | 
|---|
| 1642 | fprintf (stderr, "unknown: name: %s\n", h->root.root.string); | 
|---|
| 1643 | #endif | 
|---|
| 1644 | relocation = 0; | 
|---|
| 1645 | } | 
|---|
| 1646 | } | 
|---|
| 1647 |  | 
|---|
| 1648 | /* FIXME: We should use the addend, but the COFF relocations | 
|---|
| 1649 | don't.  */ | 
|---|
| 1650 | r = v850_elf_final_link_relocate (howto, input_bfd, output_bfd, | 
|---|
| 1651 | input_section, | 
|---|
| 1652 | contents, rel->r_offset, | 
|---|
| 1653 | relocation, rel->r_addend, | 
|---|
| 1654 | info, sec, h == NULL); | 
|---|
| 1655 |  | 
|---|
| 1656 | if (r != bfd_reloc_ok) | 
|---|
| 1657 | { | 
|---|
| 1658 | const char * name; | 
|---|
| 1659 | const char * msg = (const char *)0; | 
|---|
| 1660 |  | 
|---|
| 1661 | if (h != NULL) | 
|---|
| 1662 | name = h->root.root.string; | 
|---|
| 1663 | else | 
|---|
| 1664 | { | 
|---|
| 1665 | name = (bfd_elf_string_from_elf_section | 
|---|
| 1666 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | 
|---|
| 1667 | if (name == NULL || *name == '\0') | 
|---|
| 1668 | name = bfd_section_name (input_bfd, sec); | 
|---|
| 1669 | } | 
|---|
| 1670 |  | 
|---|
| 1671 | switch (r) | 
|---|
| 1672 | { | 
|---|
| 1673 | case bfd_reloc_overflow: | 
|---|
| 1674 | if (! ((*info->callbacks->reloc_overflow) | 
|---|
| 1675 | (info, name, howto->name, (bfd_vma) 0, | 
|---|
| 1676 | input_bfd, input_section, rel->r_offset))) | 
|---|
| 1677 | return false; | 
|---|
| 1678 | break; | 
|---|
| 1679 |  | 
|---|
| 1680 | case bfd_reloc_undefined: | 
|---|
| 1681 | if (! ((*info->callbacks->undefined_symbol) | 
|---|
| 1682 | (info, name, input_bfd, input_section, | 
|---|
| 1683 | rel->r_offset, true))) | 
|---|
| 1684 | return false; | 
|---|
| 1685 | break; | 
|---|
| 1686 |  | 
|---|
| 1687 | case bfd_reloc_outofrange: | 
|---|
| 1688 | msg = _("internal error: out of range error"); | 
|---|
| 1689 | goto common_error; | 
|---|
| 1690 |  | 
|---|
| 1691 | case bfd_reloc_notsupported: | 
|---|
| 1692 | msg = _("internal error: unsupported relocation error"); | 
|---|
| 1693 | goto common_error; | 
|---|
| 1694 |  | 
|---|
| 1695 | case bfd_reloc_dangerous: | 
|---|
| 1696 | msg = _("internal error: dangerous relocation"); | 
|---|
| 1697 | goto common_error; | 
|---|
| 1698 |  | 
|---|
| 1699 | case bfd_reloc_other: | 
|---|
| 1700 | msg = _("could not locate special linker symbol __gp"); | 
|---|
| 1701 | goto common_error; | 
|---|
| 1702 |  | 
|---|
| 1703 | case bfd_reloc_continue: | 
|---|
| 1704 | msg = _("could not locate special linker symbol __ep"); | 
|---|
| 1705 | goto common_error; | 
|---|
| 1706 |  | 
|---|
| 1707 | case (bfd_reloc_dangerous + 1): | 
|---|
| 1708 | msg = _("could not locate special linker symbol __ctbp"); | 
|---|
| 1709 | goto common_error; | 
|---|
| 1710 |  | 
|---|
| 1711 | default: | 
|---|
| 1712 | msg = _("internal error: unknown error"); | 
|---|
| 1713 | /* fall through */ | 
|---|
| 1714 |  | 
|---|
| 1715 | common_error: | 
|---|
| 1716 | if (!((*info->callbacks->warning) | 
|---|
| 1717 | (info, msg, name, input_bfd, input_section, | 
|---|
| 1718 | rel->r_offset))) | 
|---|
| 1719 | return false; | 
|---|
| 1720 | break; | 
|---|
| 1721 | } | 
|---|
| 1722 | } | 
|---|
| 1723 | } | 
|---|
| 1724 |  | 
|---|
| 1725 | return true; | 
|---|
| 1726 | } | 
|---|
| 1727 |  | 
|---|
| 1728 | static boolean | 
|---|
| 1729 | v850_elf_gc_sweep_hook (abfd, info, sec, relocs) | 
|---|
| 1730 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 1731 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | 
|---|
| 1732 | asection *sec ATTRIBUTE_UNUSED; | 
|---|
| 1733 | const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED; | 
|---|
| 1734 | { | 
|---|
| 1735 | /* No got and plt entries for v850-elf */ | 
|---|
| 1736 | return true; | 
|---|
| 1737 | } | 
|---|
| 1738 |  | 
|---|
| 1739 | static asection * | 
|---|
| 1740 | v850_elf_gc_mark_hook (abfd, info, rel, h, sym) | 
|---|
| 1741 | bfd *abfd; | 
|---|
| 1742 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | 
|---|
| 1743 | Elf_Internal_Rela *rel; | 
|---|
| 1744 | struct elf_link_hash_entry *h; | 
|---|
| 1745 | Elf_Internal_Sym *sym; | 
|---|
| 1746 | { | 
|---|
| 1747 | if (h != NULL) | 
|---|
| 1748 | { | 
|---|
| 1749 | switch (ELF32_R_TYPE (rel->r_info)) | 
|---|
| 1750 | { | 
|---|
| 1751 | case R_V850_GNU_VTINHERIT: | 
|---|
| 1752 | case R_V850_GNU_VTENTRY: | 
|---|
| 1753 | break; | 
|---|
| 1754 |  | 
|---|
| 1755 | default: | 
|---|
| 1756 | switch (h->root.type) | 
|---|
| 1757 | { | 
|---|
| 1758 | case bfd_link_hash_defined: | 
|---|
| 1759 | case bfd_link_hash_defweak: | 
|---|
| 1760 | return h->root.u.def.section; | 
|---|
| 1761 |  | 
|---|
| 1762 | case bfd_link_hash_common: | 
|---|
| 1763 | return h->root.u.c.p->section; | 
|---|
| 1764 |  | 
|---|
| 1765 | default: | 
|---|
| 1766 | break; | 
|---|
| 1767 | } | 
|---|
| 1768 | } | 
|---|
| 1769 | } | 
|---|
| 1770 | 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 | } | 
|---|
| 1780 | return NULL; | 
|---|
| 1781 | } | 
|---|
| 1782 | /* Set the right machine number.  */ | 
|---|
| 1783 | static boolean | 
|---|
| 1784 | v850_elf_object_p (abfd) | 
|---|
| 1785 | bfd *abfd; | 
|---|
| 1786 | { | 
|---|
| 1787 | switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH) | 
|---|
| 1788 | { | 
|---|
| 1789 | 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; | 
|---|
| 1793 | } | 
|---|
| 1794 | return true; | 
|---|
| 1795 | } | 
|---|
| 1796 |  | 
|---|
| 1797 | /* Store the machine number in the flags field.  */ | 
|---|
| 1798 | static void | 
|---|
| 1799 | v850_elf_final_write_processing (abfd, linker) | 
|---|
| 1800 | bfd *   abfd; | 
|---|
| 1801 | boolean linker ATTRIBUTE_UNUSED; | 
|---|
| 1802 | { | 
|---|
| 1803 | unsigned long val; | 
|---|
| 1804 |  | 
|---|
| 1805 | switch (bfd_get_mach (abfd)) | 
|---|
| 1806 | { | 
|---|
| 1807 | 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; | 
|---|
| 1811 | } | 
|---|
| 1812 |  | 
|---|
| 1813 | elf_elfheader (abfd)->e_flags &=~ EF_V850_ARCH; | 
|---|
| 1814 | elf_elfheader (abfd)->e_flags |= val; | 
|---|
| 1815 | } | 
|---|
| 1816 |  | 
|---|
| 1817 | /* Function to keep V850 specific file flags.  */ | 
|---|
| 1818 | static boolean | 
|---|
| 1819 | v850_elf_set_private_flags (abfd, flags) | 
|---|
| 1820 | bfd *    abfd; | 
|---|
| 1821 | flagword flags; | 
|---|
| 1822 | { | 
|---|
| 1823 | BFD_ASSERT (!elf_flags_init (abfd) | 
|---|
| 1824 | || elf_elfheader (abfd)->e_flags == flags); | 
|---|
| 1825 |  | 
|---|
| 1826 | elf_elfheader (abfd)->e_flags = flags; | 
|---|
| 1827 | elf_flags_init (abfd) = true; | 
|---|
| 1828 | return true; | 
|---|
| 1829 | } | 
|---|
| 1830 |  | 
|---|
| 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 | 
|---|
| 1854 | v850_elf_merge_private_bfd_data (ibfd, obfd) | 
|---|
| 1855 | bfd * ibfd; | 
|---|
| 1856 | bfd * obfd; | 
|---|
| 1857 | { | 
|---|
| 1858 | flagword out_flags; | 
|---|
| 1859 | flagword in_flags; | 
|---|
| 1860 |  | 
|---|
| 1861 | if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour | 
|---|
| 1862 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | 
|---|
| 1863 | return true; | 
|---|
| 1864 |  | 
|---|
| 1865 | in_flags = elf_elfheader (ibfd)->e_flags; | 
|---|
| 1866 | out_flags = elf_elfheader (obfd)->e_flags; | 
|---|
| 1867 |  | 
|---|
| 1868 | if (! elf_flags_init (obfd)) | 
|---|
| 1869 | { | 
|---|
| 1870 | /* If the input is the default architecture then do not | 
|---|
| 1871 | bother setting the flags for the output architecture, | 
|---|
| 1872 | instead allow future merges to do this.  If no future | 
|---|
| 1873 | merges ever set these flags then they will retain their | 
|---|
| 1874 | unitialised values, which surprise surprise, correspond | 
|---|
| 1875 | to the default values.  */ | 
|---|
| 1876 | if (bfd_get_arch_info (ibfd)->the_default) | 
|---|
| 1877 | return true; | 
|---|
| 1878 |  | 
|---|
| 1879 | elf_flags_init (obfd) = true; | 
|---|
| 1880 | elf_elfheader (obfd)->e_flags = in_flags; | 
|---|
| 1881 |  | 
|---|
| 1882 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) | 
|---|
| 1883 | && 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; | 
|---|
| 1889 | } | 
|---|
| 1890 |  | 
|---|
| 1891 | /* Check flag compatibility.  */ | 
|---|
| 1892 | if (in_flags == out_flags) | 
|---|
| 1893 | return true; | 
|---|
| 1894 |  | 
|---|
| 1895 | if ((in_flags & EF_V850_ARCH) != (out_flags & EF_V850_ARCH) | 
|---|
| 1896 | && (in_flags & EF_V850_ARCH) != E_V850_ARCH) | 
|---|
| 1897 | _bfd_error_handler (_("%s: Architecture mismatch with previous modules"), | 
|---|
| 1898 | bfd_get_filename (ibfd)); | 
|---|
| 1899 |  | 
|---|
| 1900 | return true; | 
|---|
| 1901 | } | 
|---|
| 1902 | /* Display the flags field */ | 
|---|
| 1903 |  | 
|---|
| 1904 | static boolean | 
|---|
| 1905 | v850_elf_print_private_bfd_data (abfd, ptr) | 
|---|
| 1906 | bfd *   abfd; | 
|---|
| 1907 | PTR     ptr; | 
|---|
| 1908 | { | 
|---|
| 1909 | FILE * file = (FILE *) ptr; | 
|---|
| 1910 |  | 
|---|
| 1911 | BFD_ASSERT (abfd != NULL && ptr != NULL); | 
|---|
| 1912 |  | 
|---|
| 1913 | _bfd_elf_print_private_bfd_data (abfd, ptr); | 
|---|
| 1914 |  | 
|---|
| 1915 | /* xgettext:c-format */ | 
|---|
| 1916 | fprintf (file, _("private flags = %lx: "), elf_elfheader (abfd)->e_flags); | 
|---|
| 1917 |  | 
|---|
| 1918 | switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH) | 
|---|
| 1919 | { | 
|---|
| 1920 | default: | 
|---|
| 1921 | case E_V850_ARCH: fprintf (file, _("v850 architecture")); break; | 
|---|
| 1922 | case E_V850E_ARCH:  fprintf (file, _("v850e architecture")); break; | 
|---|
| 1923 | case E_V850EA_ARCH: fprintf (file, _("v850ea architecture")); break; | 
|---|
| 1924 | } | 
|---|
| 1925 |  | 
|---|
| 1926 | fputc ('\n', file); | 
|---|
| 1927 |  | 
|---|
| 1928 | return true; | 
|---|
| 1929 | } | 
|---|
| 1930 |  | 
|---|
| 1931 | /* V850 ELF uses four common sections.  One is the usual one, and the | 
|---|
| 1932 | others are for (small) objects in one of the special data areas: | 
|---|
| 1933 | small, tiny and zero.  All the objects are kept together, and then | 
|---|
| 1934 | referenced via the gp register, the ep register or the r0 register | 
|---|
| 1935 | respectively, which yields smaller, faster assembler code.  This | 
|---|
| 1936 | approach is copied from elf32-mips.c.  */ | 
|---|
| 1937 |  | 
|---|
| 1938 | static asection  v850_elf_scom_section; | 
|---|
| 1939 | static asymbol   v850_elf_scom_symbol; | 
|---|
| 1940 | static asymbol * v850_elf_scom_symbol_ptr; | 
|---|
| 1941 | static asection  v850_elf_tcom_section; | 
|---|
| 1942 | static asymbol   v850_elf_tcom_symbol; | 
|---|
| 1943 | static asymbol * v850_elf_tcom_symbol_ptr; | 
|---|
| 1944 | static asection  v850_elf_zcom_section; | 
|---|
| 1945 | static asymbol   v850_elf_zcom_symbol; | 
|---|
| 1946 | static asymbol * v850_elf_zcom_symbol_ptr; | 
|---|
| 1947 |  | 
|---|
| 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; | 
|---|
| 1957 | { | 
|---|
| 1958 | if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0) | 
|---|
| 1959 | *retval = SHN_V850_SCOMMON; | 
|---|
| 1960 | else if (strcmp (bfd_get_section_name (abfd, sec), ".tcommon") == 0) | 
|---|
| 1961 | *retval = SHN_V850_TCOMMON; | 
|---|
| 1962 | else if (strcmp (bfd_get_section_name (abfd, sec), ".zcommon") == 0) | 
|---|
| 1963 | *retval = SHN_V850_ZCOMMON; | 
|---|
| 1964 | else | 
|---|
| 1965 | return false; | 
|---|
| 1966 |  | 
|---|
| 1967 | return true; | 
|---|
| 1968 | } | 
|---|
| 1969 |  | 
|---|
| 1970 | /* Handle the special V850 section numbers that a symbol may use.  */ | 
|---|
| 1971 |  | 
|---|
| 1972 | static void | 
|---|
| 1973 | v850_elf_symbol_processing (abfd, asym) | 
|---|
| 1974 | bfd *     abfd; | 
|---|
| 1975 | asymbol * asym; | 
|---|
| 1976 | { | 
|---|
| 1977 | elf_symbol_type * elfsym = (elf_symbol_type *) asym; | 
|---|
| 1978 | unsigned short index; | 
|---|
| 1979 |  | 
|---|
| 1980 | index = elfsym->internal_elf_sym.st_shndx; | 
|---|
| 1981 |  | 
|---|
| 1982 | /* If the section index is an "ordinary" index, then it may | 
|---|
| 1983 | refer to a v850 specific section created by the assembler. | 
|---|
| 1984 | Check the section's type and change the index it matches. | 
|---|
| 1985 |  | 
|---|
| 1986 | FIXME: Should we alter the st_shndx field as well ?  */ | 
|---|
| 1987 |  | 
|---|
| 1988 | if (index < elf_elfheader(abfd)[0].e_shnum) | 
|---|
| 1989 | switch (elf_elfsections(abfd)[index]->sh_type) | 
|---|
| 1990 | { | 
|---|
| 1991 | case SHT_V850_SCOMMON: | 
|---|
| 1992 | index = SHN_V850_SCOMMON; | 
|---|
| 1993 | break; | 
|---|
| 1994 |  | 
|---|
| 1995 | case SHT_V850_TCOMMON: | 
|---|
| 1996 | index = SHN_V850_TCOMMON; | 
|---|
| 1997 | break; | 
|---|
| 1998 |  | 
|---|
| 1999 | case SHT_V850_ZCOMMON: | 
|---|
| 2000 | index = SHN_V850_ZCOMMON; | 
|---|
| 2001 | break; | 
|---|
| 2002 |  | 
|---|
| 2003 | default: | 
|---|
| 2004 | break; | 
|---|
| 2005 | } | 
|---|
| 2006 |  | 
|---|
| 2007 | switch (index) | 
|---|
| 2008 | { | 
|---|
| 2009 | case SHN_V850_SCOMMON: | 
|---|
| 2010 | if (v850_elf_scom_section.name == NULL) | 
|---|
| 2011 | { | 
|---|
| 2012 | /* Initialize the small common section.  */ | 
|---|
| 2013 | v850_elf_scom_section.name           = ".scommon"; | 
|---|
| 2014 | v850_elf_scom_section.flags          = SEC_IS_COMMON | SEC_ALLOC | SEC_DATA; | 
|---|
| 2015 | v850_elf_scom_section.output_section = & v850_elf_scom_section; | 
|---|
| 2016 | v850_elf_scom_section.symbol         = & v850_elf_scom_symbol; | 
|---|
| 2017 | v850_elf_scom_section.symbol_ptr_ptr = & v850_elf_scom_symbol_ptr; | 
|---|
| 2018 | v850_elf_scom_symbol.name            = ".scommon"; | 
|---|
| 2019 | v850_elf_scom_symbol.flags           = BSF_SECTION_SYM; | 
|---|
| 2020 | v850_elf_scom_symbol.section         = & v850_elf_scom_section; | 
|---|
| 2021 | v850_elf_scom_symbol_ptr             = & v850_elf_scom_symbol; | 
|---|
| 2022 | } | 
|---|
| 2023 | asym->section = & v850_elf_scom_section; | 
|---|
| 2024 | asym->value = elfsym->internal_elf_sym.st_size; | 
|---|
| 2025 | break; | 
|---|
| 2026 |  | 
|---|
| 2027 | case SHN_V850_TCOMMON: | 
|---|
| 2028 | if (v850_elf_tcom_section.name == NULL) | 
|---|
| 2029 | { | 
|---|
| 2030 | /* Initialize the tcommon section.  */ | 
|---|
| 2031 | v850_elf_tcom_section.name           = ".tcommon"; | 
|---|
| 2032 | v850_elf_tcom_section.flags          = SEC_IS_COMMON; | 
|---|
| 2033 | v850_elf_tcom_section.output_section = & v850_elf_tcom_section; | 
|---|
| 2034 | v850_elf_tcom_section.symbol         = & v850_elf_tcom_symbol; | 
|---|
| 2035 | v850_elf_tcom_section.symbol_ptr_ptr = & v850_elf_tcom_symbol_ptr; | 
|---|
| 2036 | v850_elf_tcom_symbol.name            = ".tcommon"; | 
|---|
| 2037 | v850_elf_tcom_symbol.flags           = BSF_SECTION_SYM; | 
|---|
| 2038 | v850_elf_tcom_symbol.section         = & v850_elf_tcom_section; | 
|---|
| 2039 | v850_elf_tcom_symbol_ptr             = & v850_elf_tcom_symbol; | 
|---|
| 2040 | } | 
|---|
| 2041 | asym->section = & v850_elf_tcom_section; | 
|---|
| 2042 | asym->value = elfsym->internal_elf_sym.st_size; | 
|---|
| 2043 | break; | 
|---|
| 2044 |  | 
|---|
| 2045 | case SHN_V850_ZCOMMON: | 
|---|
| 2046 | if (v850_elf_zcom_section.name == NULL) | 
|---|
| 2047 | { | 
|---|
| 2048 | /* Initialize the zcommon section.  */ | 
|---|
| 2049 | v850_elf_zcom_section.name           = ".zcommon"; | 
|---|
| 2050 | v850_elf_zcom_section.flags          = SEC_IS_COMMON; | 
|---|
| 2051 | v850_elf_zcom_section.output_section = & v850_elf_zcom_section; | 
|---|
| 2052 | v850_elf_zcom_section.symbol         = & v850_elf_zcom_symbol; | 
|---|
| 2053 | v850_elf_zcom_section.symbol_ptr_ptr = & v850_elf_zcom_symbol_ptr; | 
|---|
| 2054 | v850_elf_zcom_symbol.name            = ".zcommon"; | 
|---|
| 2055 | v850_elf_zcom_symbol.flags           = BSF_SECTION_SYM; | 
|---|
| 2056 | v850_elf_zcom_symbol.section         = & v850_elf_zcom_section; | 
|---|
| 2057 | v850_elf_zcom_symbol_ptr             = & v850_elf_zcom_symbol; | 
|---|
| 2058 | } | 
|---|
| 2059 | asym->section = & v850_elf_zcom_section; | 
|---|
| 2060 | asym->value = elfsym->internal_elf_sym.st_size; | 
|---|
| 2061 | break; | 
|---|
| 2062 | } | 
|---|
| 2063 | } | 
|---|
| 2064 |  | 
|---|
| 2065 | /* Hook called by the linker routine which adds symbols from an object | 
|---|
| 2066 | file.  We must handle the special v850 section numbers here.  */ | 
|---|
| 2067 |  | 
|---|
| 2068 | static boolean | 
|---|
| 2069 | v850_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; | 
|---|
| 2077 | { | 
|---|
| 2078 | int index = sym->st_shndx; | 
|---|
| 2079 |  | 
|---|
| 2080 | /* If the section index is an "ordinary" index, then it may | 
|---|
| 2081 | refer to a v850 specific section created by the assembler. | 
|---|
| 2082 | Check the section's type and change the index it matches. | 
|---|
| 2083 |  | 
|---|
| 2084 | FIXME: Should we alter the st_shndx field as well ?  */ | 
|---|
| 2085 |  | 
|---|
| 2086 | if (index < elf_elfheader(abfd)[0].e_shnum) | 
|---|
| 2087 | switch (elf_elfsections(abfd)[index]->sh_type) | 
|---|
| 2088 | { | 
|---|
| 2089 | case SHT_V850_SCOMMON: | 
|---|
| 2090 | index = SHN_V850_SCOMMON; | 
|---|
| 2091 | break; | 
|---|
| 2092 |  | 
|---|
| 2093 | case SHT_V850_TCOMMON: | 
|---|
| 2094 | index = SHN_V850_TCOMMON; | 
|---|
| 2095 | break; | 
|---|
| 2096 |  | 
|---|
| 2097 | case SHT_V850_ZCOMMON: | 
|---|
| 2098 | index = SHN_V850_ZCOMMON; | 
|---|
| 2099 | break; | 
|---|
| 2100 |  | 
|---|
| 2101 | default: | 
|---|
| 2102 | break; | 
|---|
| 2103 | } | 
|---|
| 2104 |  | 
|---|
| 2105 | switch (index) | 
|---|
| 2106 | { | 
|---|
| 2107 | case SHN_V850_SCOMMON: | 
|---|
| 2108 | *secp = bfd_make_section_old_way (abfd, ".scommon"); | 
|---|
| 2109 | (*secp)->flags |= SEC_IS_COMMON; | 
|---|
| 2110 | *valp = sym->st_size; | 
|---|
| 2111 | break; | 
|---|
| 2112 |  | 
|---|
| 2113 | case SHN_V850_TCOMMON: | 
|---|
| 2114 | *secp = bfd_make_section_old_way (abfd, ".tcommon"); | 
|---|
| 2115 | (*secp)->flags |= SEC_IS_COMMON; | 
|---|
| 2116 | *valp = sym->st_size; | 
|---|
| 2117 | break; | 
|---|
| 2118 |  | 
|---|
| 2119 | case SHN_V850_ZCOMMON: | 
|---|
| 2120 | *secp = bfd_make_section_old_way (abfd, ".zcommon"); | 
|---|
| 2121 | (*secp)->flags |= SEC_IS_COMMON; | 
|---|
| 2122 | *valp = sym->st_size; | 
|---|
| 2123 | break; | 
|---|
| 2124 | } | 
|---|
| 2125 |  | 
|---|
| 2126 | return true; | 
|---|
| 2127 | } | 
|---|
| 2128 |  | 
|---|
| 2129 | /*ARGSIGNORED*/ | 
|---|
| 2130 | static boolean | 
|---|
| 2131 | v850_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; | 
|---|
| 2137 | { | 
|---|
| 2138 | /* If we see a common symbol, which implies a relocatable link, then | 
|---|
| 2139 | if a symbol was in a special common section in an input file, mark | 
|---|
| 2140 | it as a special common in the output file.  */ | 
|---|
| 2141 |  | 
|---|
| 2142 | if (sym->st_shndx == SHN_COMMON) | 
|---|
| 2143 | { | 
|---|
| 2144 | if (strcmp (input_sec->name, ".scommon") == 0) | 
|---|
| 2145 | sym->st_shndx = SHN_V850_SCOMMON; | 
|---|
| 2146 | else if (strcmp (input_sec->name, ".tcommon") == 0) | 
|---|
| 2147 | sym->st_shndx = SHN_V850_TCOMMON; | 
|---|
| 2148 | else if (strcmp (input_sec->name, ".zcommon") == 0) | 
|---|
| 2149 | sym->st_shndx = SHN_V850_ZCOMMON; | 
|---|
| 2150 | } | 
|---|
| 2151 |  | 
|---|
| 2152 | return true; | 
|---|
| 2153 | } | 
|---|
| 2154 |  | 
|---|
| 2155 | static boolean | 
|---|
| 2156 | v850_elf_section_from_shdr (abfd, hdr, name) | 
|---|
| 2157 | bfd *               abfd; | 
|---|
| 2158 | Elf_Internal_Shdr * hdr; | 
|---|
| 2159 | char *              name; | 
|---|
| 2160 | { | 
|---|
| 2161 | /* There ought to be a place to keep ELF backend specific flags, but | 
|---|
| 2162 | at the moment there isn't one.  We just keep track of the | 
|---|
| 2163 | sections by their name, instead.  */ | 
|---|
| 2164 |  | 
|---|
| 2165 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) | 
|---|
| 2166 | return false; | 
|---|
| 2167 |  | 
|---|
| 2168 | switch (hdr->sh_type) | 
|---|
| 2169 | { | 
|---|
| 2170 | case SHT_V850_SCOMMON: | 
|---|
| 2171 | case SHT_V850_TCOMMON: | 
|---|
| 2172 | case SHT_V850_ZCOMMON: | 
|---|
| 2173 | if (! bfd_set_section_flags (abfd, hdr->bfd_section, | 
|---|
| 2174 | (bfd_get_section_flags (abfd, | 
|---|
| 2175 | hdr->bfd_section) | 
|---|
| 2176 | | SEC_IS_COMMON))) | 
|---|
| 2177 | return false; | 
|---|
| 2178 | } | 
|---|
| 2179 |  | 
|---|
| 2180 | return true; | 
|---|
| 2181 | } | 
|---|
| 2182 |  | 
|---|
| 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 | 
|---|
| 2186 | v850_elf_fake_sections (abfd, hdr, sec) | 
|---|
| 2187 | bfd *                 abfd ATTRIBUTE_UNUSED; | 
|---|
| 2188 | Elf32_Internal_Shdr * hdr; | 
|---|
| 2189 | asection *            sec; | 
|---|
| 2190 | { | 
|---|
| 2191 | register const char * name; | 
|---|
| 2192 |  | 
|---|
| 2193 | name = bfd_get_section_name (abfd, sec); | 
|---|
| 2194 |  | 
|---|
| 2195 | if (strcmp (name, ".scommon") == 0) | 
|---|
| 2196 | { | 
|---|
| 2197 | hdr->sh_type = SHT_V850_SCOMMON; | 
|---|
| 2198 | } | 
|---|
| 2199 | else if (strcmp (name, ".tcommon") == 0) | 
|---|
| 2200 | { | 
|---|
| 2201 | hdr->sh_type = SHT_V850_TCOMMON; | 
|---|
| 2202 | } | 
|---|
| 2203 | else if (strcmp (name, ".zcommon") == 0) | 
|---|
| 2204 | hdr->sh_type = SHT_V850_ZCOMMON; | 
|---|
| 2205 |  | 
|---|
| 2206 | return true; | 
|---|
| 2207 | } | 
|---|
| 2208 |  | 
|---|
| 2209 |  | 
|---|
| 2210 | #define TARGET_LITTLE_SYM                       bfd_elf32_v850_vec | 
|---|
| 2211 | #define TARGET_LITTLE_NAME                      "elf32-v850" | 
|---|
| 2212 | #define ELF_ARCH                                bfd_arch_v850 | 
|---|
| 2213 | #define ELF_MACHINE_CODE                        EM_CYGNUS_V850 | 
|---|
| 2214 | #define ELF_MAXPAGESIZE                         0x1000 | 
|---|
| 2215 |  | 
|---|
| 2216 | #define elf_info_to_howto                       v850_elf_info_to_howto_rela | 
|---|
| 2217 | #define elf_info_to_howto_rel                   v850_elf_info_to_howto_rel | 
|---|
| 2218 |  | 
|---|
| 2219 | #define elf_backend_check_relocs                v850_elf_check_relocs | 
|---|
| 2220 | #define elf_backend_relocate_section            v850_elf_relocate_section | 
|---|
| 2221 | #define elf_backend_object_p                    v850_elf_object_p | 
|---|
| 2222 | #define elf_backend_final_write_processing      v850_elf_final_write_processing | 
|---|
| 2223 | #define elf_backend_section_from_bfd_section    v850_elf_section_from_bfd_section | 
|---|
| 2224 | #define elf_backend_symbol_processing           v850_elf_symbol_processing | 
|---|
| 2225 | #define elf_backend_add_symbol_hook             v850_elf_add_symbol_hook | 
|---|
| 2226 | #define elf_backend_link_output_symbol_hook     v850_elf_link_output_symbol_hook | 
|---|
| 2227 | #define elf_backend_section_from_shdr           v850_elf_section_from_shdr | 
|---|
| 2228 | #define elf_backend_fake_sections               v850_elf_fake_sections | 
|---|
| 2229 | #define elf_backend_gc_mark_hook                v850_elf_gc_mark_hook | 
|---|
| 2230 | #define elf_backend_gc_sweep_hook               v850_elf_gc_sweep_hook | 
|---|
| 2231 |  | 
|---|
| 2232 | #define elf_backend_can_gc_sections 1 | 
|---|
| 2233 |  | 
|---|
| 2234 | #define bfd_elf32_bfd_is_local_label_name       v850_elf_is_local_label_name | 
|---|
| 2235 | #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 | 
|---|
| 2237 | #define bfd_elf32_bfd_merge_private_bfd_data    v850_elf_merge_private_bfd_data | 
|---|
| 2238 | #define bfd_elf32_bfd_set_private_flags         v850_elf_set_private_flags | 
|---|
| 2239 | #define bfd_elf32_bfd_print_private_bfd_data    v850_elf_print_private_bfd_data | 
|---|
| 2240 |  | 
|---|
| 2241 | #define elf_symbol_leading_char                 '_' | 
|---|
| 2242 |  | 
|---|
| 2243 | #include "elf32-target.h" | 
|---|