| 1 | /* FR30-specific support for 32-bit ELF.
|
|---|
| 2 | Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of BFD, the Binary File Descriptor library.
|
|---|
| 5 |
|
|---|
| 6 | This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 9 | (at your option) any later version.
|
|---|
| 10 |
|
|---|
| 11 | This program is distributed in the hope that it will be useful,
|
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | GNU General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with this program; if not, write to the Free Software
|
|---|
| 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 19 |
|
|---|
| 20 | #include "bfd.h"
|
|---|
| 21 | #include "sysdep.h"
|
|---|
| 22 | #include "libbfd.h"
|
|---|
| 23 | #include "elf-bfd.h"
|
|---|
| 24 | #include "elf/fr30.h"
|
|---|
| 25 |
|
|---|
| 26 | /* Forward declarations. */
|
|---|
| 27 | static bfd_reloc_status_type fr30_elf_i20_reloc
|
|---|
| 28 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
|---|
| 29 | static bfd_reloc_status_type fr30_elf_i32_reloc
|
|---|
| 30 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
|---|
| 31 | static reloc_howto_type * fr30_reloc_type_lookup
|
|---|
| 32 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
|
|---|
| 33 | static void fr30_info_to_howto_rela
|
|---|
| 34 | PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
|
|---|
| 35 | static boolean fr30_elf_relocate_section
|
|---|
| 36 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
|
|---|
| 37 | static bfd_reloc_status_type fr30_final_link_relocate
|
|---|
| 38 | PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *, Elf_Internal_Rela *, bfd_vma));
|
|---|
| 39 | static boolean fr30_elf_gc_sweep_hook
|
|---|
| 40 | PARAMS ((bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *));
|
|---|
| 41 | static asection * fr30_elf_gc_mark_hook
|
|---|
| 42 | PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *, struct elf_link_hash_entry *, Elf_Internal_Sym *));
|
|---|
| 43 |
|
|---|
| 44 | static reloc_howto_type fr30_elf_howto_table [] =
|
|---|
| 45 | {
|
|---|
| 46 | /* This reloc does nothing. */
|
|---|
| 47 | HOWTO (R_FR30_NONE, /* type */
|
|---|
| 48 | 0, /* rightshift */
|
|---|
| 49 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 50 | 32, /* bitsize */
|
|---|
| 51 | false, /* pc_relative */
|
|---|
| 52 | 0, /* bitpos */
|
|---|
| 53 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 54 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 55 | "R_FR30_NONE", /* name */
|
|---|
| 56 | false, /* partial_inplace */
|
|---|
| 57 | 0, /* src_mask */
|
|---|
| 58 | 0, /* dst_mask */
|
|---|
| 59 | false), /* pcrel_offset */
|
|---|
| 60 |
|
|---|
| 61 | /* An 8 bit absolute relocation. */
|
|---|
| 62 | HOWTO (R_FR30_8, /* type */
|
|---|
| 63 | 0, /* rightshift */
|
|---|
| 64 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 65 | 8, /* bitsize */
|
|---|
| 66 | false, /* pc_relative */
|
|---|
| 67 | 4, /* bitpos */
|
|---|
| 68 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 69 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 70 | "R_FR30_8", /* name */
|
|---|
| 71 | true, /* partial_inplace */
|
|---|
| 72 | 0x0000, /* src_mask */
|
|---|
| 73 | 0x0ff0, /* dst_mask */
|
|---|
| 74 | false), /* pcrel_offset */
|
|---|
| 75 |
|
|---|
| 76 | /* A 20 bit absolute relocation. */
|
|---|
| 77 | HOWTO (R_FR30_20, /* type */
|
|---|
| 78 | 0, /* rightshift */
|
|---|
| 79 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 80 | 20, /* bitsize */
|
|---|
| 81 | false, /* pc_relative */
|
|---|
| 82 | 0, /* bitpos */
|
|---|
| 83 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 84 | fr30_elf_i20_reloc, /* special_function */
|
|---|
| 85 | "R_FR30_20", /* name */
|
|---|
| 86 | true, /* partial_inplace */
|
|---|
| 87 | 0x00000000, /* src_mask */
|
|---|
| 88 | 0x00f0ffff, /* dst_mask */
|
|---|
| 89 | false), /* pcrel_offset */
|
|---|
| 90 |
|
|---|
| 91 | /* A 32 bit absolute relocation. */
|
|---|
| 92 | HOWTO (R_FR30_32, /* type */
|
|---|
| 93 | 0, /* rightshift */
|
|---|
| 94 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 95 | 32, /* bitsize */
|
|---|
| 96 | false, /* pc_relative */
|
|---|
| 97 | 0, /* bitpos */
|
|---|
| 98 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 99 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 100 | "R_FR30_32", /* name */
|
|---|
| 101 | true, /* partial_inplace */
|
|---|
| 102 | 0x00000000, /* src_mask */
|
|---|
| 103 | 0xffffffff, /* dst_mask */
|
|---|
| 104 | false), /* pcrel_offset */
|
|---|
| 105 |
|
|---|
| 106 | /* A 32 bit into 48 bits absolute relocation. */
|
|---|
| 107 | HOWTO (R_FR30_48, /* type */
|
|---|
| 108 | 0, /* rightshift */
|
|---|
| 109 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 110 | 32, /* bitsize */
|
|---|
| 111 | false, /* pc_relative */
|
|---|
| 112 | 0, /* bitpos */
|
|---|
| 113 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 114 | fr30_elf_i32_reloc, /* special_function */
|
|---|
| 115 | "R_FR30_48", /* name */
|
|---|
| 116 | true, /* partial_inplace */
|
|---|
| 117 | 0x00000000, /* src_mask */
|
|---|
| 118 | 0xffffffff, /* dst_mask */
|
|---|
| 119 | false), /* pcrel_offset */
|
|---|
| 120 |
|
|---|
| 121 | /* A 6 bit absolute relocation. */
|
|---|
| 122 | HOWTO (R_FR30_6_IN_4, /* type */
|
|---|
| 123 | 2, /* rightshift */
|
|---|
| 124 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 125 | 6, /* bitsize */
|
|---|
| 126 | false, /* pc_relative */
|
|---|
| 127 | 4, /* bitpos */
|
|---|
| 128 | complain_overflow_unsigned, /* complain_on_overflow */
|
|---|
| 129 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 130 | "R_FR30_6_IN_4", /* name */
|
|---|
| 131 | true, /* partial_inplace */
|
|---|
| 132 | 0x0000, /* src_mask */
|
|---|
| 133 | 0x00f0, /* dst_mask */
|
|---|
| 134 | false), /* pcrel_offset */
|
|---|
| 135 |
|
|---|
| 136 | /* An 8 bit absolute relocation. */
|
|---|
| 137 | HOWTO (R_FR30_8_IN_8, /* type */
|
|---|
| 138 | 0, /* rightshift */
|
|---|
| 139 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 140 | 8, /* bitsize */
|
|---|
| 141 | false, /* pc_relative */
|
|---|
| 142 | 4, /* bitpos */
|
|---|
| 143 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 144 | bfd_elf_generic_reloc,/* special_function */
|
|---|
| 145 | "R_FR30_8_IN_8", /* name */
|
|---|
| 146 | true, /* partial_inplace */
|
|---|
| 147 | 0x0000, /* src_mask */
|
|---|
| 148 | 0x0ff0, /* dst_mask */
|
|---|
| 149 | false), /* pcrel_offset */
|
|---|
| 150 |
|
|---|
| 151 | /* A 9 bit absolute relocation. */
|
|---|
| 152 | HOWTO (R_FR30_9_IN_8, /* type */
|
|---|
| 153 | 1, /* rightshift */
|
|---|
| 154 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 155 | 9, /* bitsize */
|
|---|
| 156 | false, /* pc_relative */
|
|---|
| 157 | 4, /* bitpos */
|
|---|
| 158 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 159 | bfd_elf_generic_reloc,/* special_function */
|
|---|
| 160 | "R_FR30_9_IN_8", /* name */
|
|---|
| 161 | true, /* partial_inplace */
|
|---|
| 162 | 0x0000, /* src_mask */
|
|---|
| 163 | 0x0ff0, /* dst_mask */
|
|---|
| 164 | false), /* pcrel_offset */
|
|---|
| 165 |
|
|---|
| 166 | /* A 10 bit absolute relocation. */
|
|---|
| 167 | HOWTO (R_FR30_10_IN_8, /* type */
|
|---|
| 168 | 2, /* rightshift */
|
|---|
| 169 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 170 | 10, /* bitsize */
|
|---|
| 171 | false, /* pc_relative */
|
|---|
| 172 | 4, /* bitpos */
|
|---|
| 173 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 174 | bfd_elf_generic_reloc,/* special_function */
|
|---|
| 175 | "R_FR30_10_IN_8", /* name */
|
|---|
| 176 | true, /* partial_inplace */
|
|---|
| 177 | 0x0000, /* src_mask */
|
|---|
| 178 | 0x0ff0, /* dst_mask */
|
|---|
| 179 | false), /* pcrel_offset */
|
|---|
| 180 |
|
|---|
| 181 | /* A PC relative 9 bit relocation, right shifted by 1. */
|
|---|
| 182 | HOWTO (R_FR30_9_PCREL, /* type */
|
|---|
| 183 | 1, /* rightshift */
|
|---|
| 184 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 185 | 9, /* bitsize */
|
|---|
| 186 | true, /* pc_relative */
|
|---|
| 187 | 0, /* bitpos */
|
|---|
| 188 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 189 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 190 | "R_FR30_9_PCREL", /* name */
|
|---|
| 191 | false, /* partial_inplace */
|
|---|
| 192 | 0x0000, /* src_mask */
|
|---|
| 193 | 0x00ff, /* dst_mask */
|
|---|
| 194 | false), /* pcrel_offset */
|
|---|
| 195 |
|
|---|
| 196 | /* A PC relative 12 bit relocation, right shifted by 1. */
|
|---|
| 197 | HOWTO (R_FR30_12_PCREL, /* type */
|
|---|
| 198 | 1, /* rightshift */
|
|---|
| 199 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 200 | 12, /* bitsize */
|
|---|
| 201 | true, /* pc_relative */
|
|---|
| 202 | 0, /* bitpos */
|
|---|
| 203 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 204 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 205 | "R_FR30_12_PCREL", /* name */
|
|---|
| 206 | false, /* partial_inplace */
|
|---|
| 207 | 0x0000, /* src_mask */
|
|---|
| 208 | 0x07ff, /* dst_mask */
|
|---|
| 209 | false), /* pcrel_offset */
|
|---|
| 210 | /* GNU extension to record C++ vtable hierarchy */
|
|---|
| 211 | HOWTO (R_FR30_GNU_VTINHERIT, /* type */
|
|---|
| 212 | 0, /* rightshift */
|
|---|
| 213 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 214 | 0, /* bitsize */
|
|---|
| 215 | false, /* pc_relative */
|
|---|
| 216 | 0, /* bitpos */
|
|---|
| 217 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 218 | NULL, /* special_function */
|
|---|
| 219 | "R_FR30_GNU_VTINHERIT", /* name */
|
|---|
| 220 | false, /* partial_inplace */
|
|---|
| 221 | 0, /* src_mask */
|
|---|
| 222 | 0, /* dst_mask */
|
|---|
| 223 | false), /* pcrel_offset */
|
|---|
| 224 |
|
|---|
| 225 | /* GNU extension to record C++ vtable member usage */
|
|---|
| 226 | HOWTO (R_FR30_GNU_VTENTRY, /* type */
|
|---|
| 227 | 0, /* rightshift */
|
|---|
| 228 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 229 | 0, /* bitsize */
|
|---|
| 230 | false, /* pc_relative */
|
|---|
| 231 | 0, /* bitpos */
|
|---|
| 232 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 233 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */
|
|---|
| 234 | "R_FR30_GNU_VTENTRY", /* name */
|
|---|
| 235 | false, /* partial_inplace */
|
|---|
| 236 | 0, /* src_mask */
|
|---|
| 237 | 0, /* dst_mask */
|
|---|
| 238 | false), /* pcrel_offset */
|
|---|
| 239 | };
|
|---|
| 240 | |
|---|
| 241 |
|
|---|
| 242 | /* Utility to actually perform an R_FR30_20 reloc. */
|
|---|
| 243 |
|
|---|
| 244 | static bfd_reloc_status_type
|
|---|
| 245 | fr30_elf_i20_reloc (abfd, reloc_entry, symbol, data,
|
|---|
| 246 | input_section, output_bfd, error_message)
|
|---|
| 247 | bfd * abfd;
|
|---|
| 248 | arelent * reloc_entry;
|
|---|
| 249 | asymbol * symbol;
|
|---|
| 250 | PTR data;
|
|---|
| 251 | asection * input_section;
|
|---|
| 252 | bfd * output_bfd;
|
|---|
| 253 | char ** error_message ATTRIBUTE_UNUSED;
|
|---|
| 254 | {
|
|---|
| 255 | bfd_vma relocation;
|
|---|
| 256 | unsigned long x;
|
|---|
| 257 |
|
|---|
| 258 | /* This part is from bfd_elf_generic_reloc. */
|
|---|
| 259 | if (output_bfd != (bfd *) NULL
|
|---|
| 260 | && (symbol->flags & BSF_SECTION_SYM) == 0
|
|---|
| 261 | && (! reloc_entry->howto->partial_inplace
|
|---|
| 262 | || reloc_entry->addend == 0))
|
|---|
| 263 | {
|
|---|
| 264 | reloc_entry->address += input_section->output_offset;
|
|---|
| 265 | return bfd_reloc_ok;
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | if (output_bfd != NULL)
|
|---|
| 269 | /* FIXME: See bfd_perform_relocation. Is this right? */
|
|---|
| 270 | return bfd_reloc_ok;
|
|---|
| 271 |
|
|---|
| 272 | relocation =
|
|---|
| 273 | symbol->value
|
|---|
| 274 | + symbol->section->output_section->vma
|
|---|
| 275 | + symbol->section->output_offset
|
|---|
| 276 | + reloc_entry->addend;
|
|---|
| 277 |
|
|---|
| 278 | if (relocation > (((bfd_vma) 1 << 20) - 1))
|
|---|
| 279 | return bfd_reloc_overflow;
|
|---|
| 280 |
|
|---|
| 281 | x = bfd_get_32 (abfd, (char *) data + reloc_entry->address);
|
|---|
| 282 | x = (x & 0xff0f0000) | (relocation & 0x0000ffff) | ((relocation & 0x000f0000) << 4);
|
|---|
| 283 | bfd_put_32 (abfd, x, (char *) data + reloc_entry->address);
|
|---|
| 284 |
|
|---|
| 285 | return bfd_reloc_ok;
|
|---|
| 286 | }
|
|---|
| 287 | |
|---|
| 288 |
|
|---|
| 289 | /* Utility to actually perform a R_FR30_48 reloc. */
|
|---|
| 290 |
|
|---|
| 291 | static bfd_reloc_status_type
|
|---|
| 292 | fr30_elf_i32_reloc (abfd, reloc_entry, symbol, data,
|
|---|
| 293 | input_section, output_bfd, error_message)
|
|---|
| 294 | bfd * abfd;
|
|---|
| 295 | arelent * reloc_entry;
|
|---|
| 296 | asymbol * symbol;
|
|---|
| 297 | PTR data;
|
|---|
| 298 | asection * input_section;
|
|---|
| 299 | bfd * output_bfd;
|
|---|
| 300 | char ** error_message ATTRIBUTE_UNUSED;
|
|---|
| 301 | {
|
|---|
| 302 | bfd_vma relocation;
|
|---|
| 303 |
|
|---|
| 304 | /* This part is from bfd_elf_generic_reloc. */
|
|---|
| 305 | if (output_bfd != (bfd *) NULL
|
|---|
| 306 | && (symbol->flags & BSF_SECTION_SYM) == 0
|
|---|
| 307 | && (! reloc_entry->howto->partial_inplace
|
|---|
| 308 | || reloc_entry->addend == 0))
|
|---|
| 309 | {
|
|---|
| 310 | reloc_entry->address += input_section->output_offset;
|
|---|
| 311 | return bfd_reloc_ok;
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | if (output_bfd != NULL)
|
|---|
| 315 | /* FIXME: See bfd_perform_relocation. Is this right? */
|
|---|
| 316 | return bfd_reloc_ok;
|
|---|
| 317 |
|
|---|
| 318 | relocation =
|
|---|
| 319 | symbol->value
|
|---|
| 320 | + symbol->section->output_section->vma
|
|---|
| 321 | + symbol->section->output_offset
|
|---|
| 322 | + reloc_entry->addend;
|
|---|
| 323 |
|
|---|
| 324 | bfd_put_32 (abfd, relocation, (char *) data + reloc_entry->address + 2);
|
|---|
| 325 |
|
|---|
| 326 | return bfd_reloc_ok;
|
|---|
| 327 | }
|
|---|
| 328 | |
|---|
| 329 |
|
|---|
| 330 | /* Map BFD reloc types to FR30 ELF reloc types. */
|
|---|
| 331 |
|
|---|
| 332 | struct fr30_reloc_map
|
|---|
| 333 | {
|
|---|
| 334 | bfd_reloc_code_real_type bfd_reloc_val;
|
|---|
| 335 | unsigned int fr30_reloc_val;
|
|---|
| 336 | };
|
|---|
| 337 |
|
|---|
| 338 | static const struct fr30_reloc_map fr30_reloc_map [] =
|
|---|
| 339 | {
|
|---|
| 340 | { BFD_RELOC_NONE, R_FR30_NONE },
|
|---|
| 341 | { BFD_RELOC_8, R_FR30_8 },
|
|---|
| 342 | { BFD_RELOC_FR30_20, R_FR30_20 },
|
|---|
| 343 | { BFD_RELOC_32, R_FR30_32 },
|
|---|
| 344 | { BFD_RELOC_FR30_48, R_FR30_48 },
|
|---|
| 345 | { BFD_RELOC_FR30_6_IN_4, R_FR30_6_IN_4 },
|
|---|
| 346 | { BFD_RELOC_FR30_8_IN_8, R_FR30_8_IN_8 },
|
|---|
| 347 | { BFD_RELOC_FR30_9_IN_8, R_FR30_9_IN_8 },
|
|---|
| 348 | { BFD_RELOC_FR30_10_IN_8, R_FR30_10_IN_8 },
|
|---|
| 349 | { BFD_RELOC_FR30_9_PCREL, R_FR30_9_PCREL },
|
|---|
| 350 | { BFD_RELOC_FR30_12_PCREL, R_FR30_12_PCREL },
|
|---|
| 351 | { BFD_RELOC_VTABLE_INHERIT, R_FR30_GNU_VTINHERIT },
|
|---|
| 352 | { BFD_RELOC_VTABLE_ENTRY, R_FR30_GNU_VTENTRY },
|
|---|
| 353 | };
|
|---|
| 354 |
|
|---|
| 355 | static reloc_howto_type *
|
|---|
| 356 | fr30_reloc_type_lookup (abfd, code)
|
|---|
| 357 | bfd * abfd ATTRIBUTE_UNUSED;
|
|---|
| 358 | bfd_reloc_code_real_type code;
|
|---|
| 359 | {
|
|---|
| 360 | unsigned int i;
|
|---|
| 361 |
|
|---|
| 362 | for (i = sizeof (fr30_reloc_map) / sizeof (fr30_reloc_map[0]);
|
|---|
| 363 | --i;)
|
|---|
| 364 | if (fr30_reloc_map [i].bfd_reloc_val == code)
|
|---|
| 365 | return & fr30_elf_howto_table [fr30_reloc_map[i].fr30_reloc_val];
|
|---|
| 366 |
|
|---|
| 367 | return NULL;
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | /* Set the howto pointer for an FR30 ELF reloc. */
|
|---|
| 371 |
|
|---|
| 372 | static void
|
|---|
| 373 | fr30_info_to_howto_rela (abfd, cache_ptr, dst)
|
|---|
| 374 | bfd * abfd ATTRIBUTE_UNUSED;
|
|---|
| 375 | arelent * cache_ptr;
|
|---|
| 376 | Elf32_Internal_Rela * dst;
|
|---|
| 377 | {
|
|---|
| 378 | unsigned int r_type;
|
|---|
| 379 |
|
|---|
| 380 | r_type = ELF32_R_TYPE (dst->r_info);
|
|---|
| 381 | BFD_ASSERT (r_type < (unsigned int) R_FR30_max);
|
|---|
| 382 | cache_ptr->howto = & fr30_elf_howto_table [r_type];
|
|---|
| 383 | }
|
|---|
| 384 | |
|---|
| 385 |
|
|---|
| 386 | /* Perform a single relocation. By default we use the standard BFD
|
|---|
| 387 | routines, but a few relocs, we have to do them ourselves. */
|
|---|
| 388 |
|
|---|
| 389 | static bfd_reloc_status_type
|
|---|
| 390 | fr30_final_link_relocate (howto, input_bfd, input_section, contents, rel, relocation)
|
|---|
| 391 | reloc_howto_type * howto;
|
|---|
| 392 | bfd * input_bfd;
|
|---|
| 393 | asection * input_section;
|
|---|
| 394 | bfd_byte * contents;
|
|---|
| 395 | Elf_Internal_Rela * rel;
|
|---|
| 396 | bfd_vma relocation;
|
|---|
| 397 | {
|
|---|
| 398 | bfd_reloc_status_type r = bfd_reloc_ok;
|
|---|
| 399 | bfd_vma x;
|
|---|
| 400 | bfd_signed_vma srel;
|
|---|
| 401 |
|
|---|
| 402 | switch (howto->type)
|
|---|
| 403 | {
|
|---|
| 404 | case R_FR30_20:
|
|---|
| 405 | contents += rel->r_offset;
|
|---|
| 406 | relocation += rel->r_addend;
|
|---|
| 407 |
|
|---|
| 408 | if (relocation > ((1 << 20) - 1))
|
|---|
| 409 | return bfd_reloc_overflow;
|
|---|
| 410 |
|
|---|
| 411 | x = bfd_get_32 (input_bfd, contents);
|
|---|
| 412 | x = (x & 0xff0f0000) | (relocation & 0x0000ffff) | ((relocation & 0x000f0000) << 4);
|
|---|
| 413 | bfd_put_32 (input_bfd, x, contents);
|
|---|
| 414 | break;
|
|---|
| 415 |
|
|---|
| 416 | case R_FR30_48:
|
|---|
| 417 | contents += rel->r_offset + 2;
|
|---|
| 418 | relocation += rel->r_addend;
|
|---|
| 419 | bfd_put_32 (input_bfd, relocation, contents);
|
|---|
| 420 | break;
|
|---|
| 421 |
|
|---|
| 422 | case R_FR30_9_PCREL:
|
|---|
| 423 | contents += rel->r_offset + 1;
|
|---|
| 424 | srel = (bfd_signed_vma) relocation;
|
|---|
| 425 | srel += rel->r_addend;
|
|---|
| 426 | srel -= rel->r_offset;
|
|---|
| 427 | srel -= 2; /* Branch instructions add 2 to the PC... */
|
|---|
| 428 | srel -= (input_section->output_section->vma +
|
|---|
| 429 | input_section->output_offset);
|
|---|
| 430 |
|
|---|
| 431 | if (srel & 1)
|
|---|
| 432 | return bfd_reloc_outofrange;
|
|---|
| 433 | if (srel > ((1 << 8) - 1) || (srel < - (1 << 8)))
|
|---|
| 434 | return bfd_reloc_overflow;
|
|---|
| 435 |
|
|---|
| 436 | bfd_put_8 (input_bfd, srel >> 1, contents);
|
|---|
| 437 | break;
|
|---|
| 438 |
|
|---|
| 439 | case R_FR30_12_PCREL:
|
|---|
| 440 | contents += rel->r_offset;
|
|---|
| 441 | srel = (bfd_signed_vma) relocation;
|
|---|
| 442 | srel += rel->r_addend;
|
|---|
| 443 | srel -= rel->r_offset;
|
|---|
| 444 | srel -= 2; /* Branch instructions add 2 to the PC... */
|
|---|
| 445 | srel -= (input_section->output_section->vma +
|
|---|
| 446 | input_section->output_offset);
|
|---|
| 447 |
|
|---|
| 448 | if (srel & 1)
|
|---|
| 449 | return bfd_reloc_outofrange;
|
|---|
| 450 | if (srel > ((1 << 11) - 1) || (srel < - (1 << 11)))
|
|---|
| 451 | return bfd_reloc_overflow;
|
|---|
| 452 |
|
|---|
| 453 | x = bfd_get_16 (input_bfd, contents);
|
|---|
| 454 | x = (x & 0xf800) | ((srel >> 1) & 0x7ff);
|
|---|
| 455 | bfd_put_16 (input_bfd, x, contents);
|
|---|
| 456 | break;
|
|---|
| 457 |
|
|---|
| 458 | default:
|
|---|
| 459 | r = _bfd_final_link_relocate (howto, input_bfd, input_section,
|
|---|
| 460 | contents, rel->r_offset,
|
|---|
| 461 | relocation, rel->r_addend);
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 | return r;
|
|---|
| 465 | }
|
|---|
| 466 | |
|---|
| 467 |
|
|---|
| 468 | /* Relocate an FR30 ELF section.
|
|---|
| 469 | There is some attempt to make this function usable for many architectures,
|
|---|
| 470 | both USE_REL and USE_RELA ['twould be nice if such a critter existed],
|
|---|
| 471 | if only to serve as a learning tool.
|
|---|
| 472 |
|
|---|
| 473 | The RELOCATE_SECTION function is called by the new ELF backend linker
|
|---|
| 474 | to handle the relocations for a section.
|
|---|
| 475 |
|
|---|
| 476 | The relocs are always passed as Rela structures; if the section
|
|---|
| 477 | actually uses Rel structures, the r_addend field will always be
|
|---|
| 478 | zero.
|
|---|
| 479 |
|
|---|
| 480 | This function is responsible for adjusting the section contents as
|
|---|
| 481 | necessary, and (if using Rela relocs and generating a relocateable
|
|---|
| 482 | output file) adjusting the reloc addend as necessary.
|
|---|
| 483 |
|
|---|
| 484 | This function does not have to worry about setting the reloc
|
|---|
| 485 | address or the reloc symbol index.
|
|---|
| 486 |
|
|---|
| 487 | LOCAL_SYMS is a pointer to the swapped in local symbols.
|
|---|
| 488 |
|
|---|
| 489 | LOCAL_SECTIONS is an array giving the section in the input file
|
|---|
| 490 | corresponding to the st_shndx field of each local symbol.
|
|---|
| 491 |
|
|---|
| 492 | The global hash table entry for the global symbols can be found
|
|---|
| 493 | via elf_sym_hashes (input_bfd).
|
|---|
| 494 |
|
|---|
| 495 | When generating relocateable output, this function must handle
|
|---|
| 496 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is
|
|---|
| 497 | going to be the section symbol corresponding to the output
|
|---|
| 498 | section, which means that the addend must be adjusted
|
|---|
| 499 | accordingly. */
|
|---|
| 500 |
|
|---|
| 501 | static boolean
|
|---|
| 502 | fr30_elf_relocate_section (output_bfd, info, input_bfd, input_section,
|
|---|
| 503 | contents, relocs, local_syms, local_sections)
|
|---|
| 504 | bfd * output_bfd ATTRIBUTE_UNUSED;
|
|---|
| 505 | struct bfd_link_info * info;
|
|---|
| 506 | bfd * input_bfd;
|
|---|
| 507 | asection * input_section;
|
|---|
| 508 | bfd_byte * contents;
|
|---|
| 509 | Elf_Internal_Rela * relocs;
|
|---|
| 510 | Elf_Internal_Sym * local_syms;
|
|---|
| 511 | asection ** local_sections;
|
|---|
| 512 | {
|
|---|
| 513 | Elf_Internal_Shdr * symtab_hdr;
|
|---|
| 514 | struct elf_link_hash_entry ** sym_hashes;
|
|---|
| 515 | Elf_Internal_Rela * rel;
|
|---|
| 516 | Elf_Internal_Rela * relend;
|
|---|
| 517 |
|
|---|
| 518 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
|
|---|
| 519 | sym_hashes = elf_sym_hashes (input_bfd);
|
|---|
| 520 | relend = relocs + input_section->reloc_count;
|
|---|
| 521 |
|
|---|
| 522 | for (rel = relocs; rel < relend; rel ++)
|
|---|
| 523 | {
|
|---|
| 524 | reloc_howto_type * howto;
|
|---|
| 525 | unsigned long r_symndx;
|
|---|
| 526 | Elf_Internal_Sym * sym;
|
|---|
| 527 | asection * sec;
|
|---|
| 528 | struct elf_link_hash_entry * h;
|
|---|
| 529 | bfd_vma relocation;
|
|---|
| 530 | bfd_reloc_status_type r;
|
|---|
| 531 | const char * name = NULL;
|
|---|
| 532 | int r_type;
|
|---|
| 533 |
|
|---|
| 534 | r_type = ELF32_R_TYPE (rel->r_info);
|
|---|
| 535 |
|
|---|
| 536 | if ( r_type == R_FR30_GNU_VTINHERIT
|
|---|
| 537 | || r_type == R_FR30_GNU_VTENTRY)
|
|---|
| 538 | continue;
|
|---|
| 539 |
|
|---|
| 540 | r_symndx = ELF32_R_SYM (rel->r_info);
|
|---|
| 541 |
|
|---|
| 542 | if (info->relocateable)
|
|---|
| 543 | {
|
|---|
| 544 | /* This is a relocateable link. We don't have to change
|
|---|
| 545 | anything, unless the reloc is against a section symbol,
|
|---|
| 546 | in which case we have to adjust according to where the
|
|---|
| 547 | section symbol winds up in the output section. */
|
|---|
| 548 | if (r_symndx < symtab_hdr->sh_info)
|
|---|
| 549 | {
|
|---|
| 550 | sym = local_syms + r_symndx;
|
|---|
| 551 |
|
|---|
| 552 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
|
|---|
| 553 | {
|
|---|
| 554 | sec = local_sections [r_symndx];
|
|---|
| 555 | rel->r_addend += sec->output_offset + sym->st_value;
|
|---|
| 556 | }
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | continue;
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | /* This is a final link. */
|
|---|
| 563 | howto = fr30_elf_howto_table + ELF32_R_TYPE (rel->r_info);
|
|---|
| 564 | h = NULL;
|
|---|
| 565 | sym = NULL;
|
|---|
| 566 | sec = NULL;
|
|---|
| 567 |
|
|---|
| 568 | if (r_symndx < symtab_hdr->sh_info)
|
|---|
| 569 | {
|
|---|
| 570 | sym = local_syms + r_symndx;
|
|---|
| 571 | sec = local_sections [r_symndx];
|
|---|
| 572 | relocation = (sec->output_section->vma
|
|---|
| 573 | + sec->output_offset
|
|---|
| 574 | + sym->st_value);
|
|---|
| 575 |
|
|---|
| 576 | name = bfd_elf_string_from_elf_section
|
|---|
| 577 | (input_bfd, symtab_hdr->sh_link, sym->st_name);
|
|---|
| 578 | name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
|
|---|
| 579 | #if 0
|
|---|
| 580 | fprintf (stderr, "local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
|
|---|
| 581 | sec->name, name, sym->st_name,
|
|---|
| 582 | sec->output_section->vma, sec->output_offset,
|
|---|
| 583 | sym->st_value, rel->r_addend);
|
|---|
| 584 | #endif
|
|---|
| 585 | }
|
|---|
| 586 | else
|
|---|
| 587 | {
|
|---|
| 588 | h = sym_hashes [r_symndx - symtab_hdr->sh_info];
|
|---|
| 589 |
|
|---|
| 590 | while (h->root.type == bfd_link_hash_indirect
|
|---|
| 591 | || h->root.type == bfd_link_hash_warning)
|
|---|
| 592 | h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
|---|
| 593 |
|
|---|
| 594 | name = h->root.root.string;
|
|---|
| 595 |
|
|---|
| 596 | if (h->root.type == bfd_link_hash_defined
|
|---|
| 597 | || h->root.type == bfd_link_hash_defweak)
|
|---|
| 598 | {
|
|---|
| 599 | sec = h->root.u.def.section;
|
|---|
| 600 | relocation = (h->root.u.def.value
|
|---|
| 601 | + sec->output_section->vma
|
|---|
| 602 | + sec->output_offset);
|
|---|
| 603 | #if 0
|
|---|
| 604 | fprintf (stderr,
|
|---|
| 605 | "defined: sec: %s, name: %s, value: %x + %x + %x gives: %x\n",
|
|---|
| 606 | sec->name, name, h->root.u.def.value,
|
|---|
| 607 | sec->output_section->vma, sec->output_offset, relocation);
|
|---|
| 608 | #endif
|
|---|
| 609 | }
|
|---|
| 610 | else if (h->root.type == bfd_link_hash_undefweak)
|
|---|
| 611 | {
|
|---|
| 612 | #if 0
|
|---|
| 613 | fprintf (stderr, "undefined: sec: %s, name: %s\n",
|
|---|
| 614 | sec->name, name);
|
|---|
| 615 | #endif
|
|---|
| 616 | relocation = 0;
|
|---|
| 617 | }
|
|---|
| 618 | else
|
|---|
| 619 | {
|
|---|
| 620 | if (! ((*info->callbacks->undefined_symbol)
|
|---|
| 621 | (info, h->root.root.string, input_bfd,
|
|---|
| 622 | input_section, rel->r_offset, true)))
|
|---|
| 623 | return false;
|
|---|
| 624 | #if 0
|
|---|
| 625 | fprintf (stderr, "unknown: name: %s\n", name);
|
|---|
| 626 | #endif
|
|---|
| 627 | relocation = 0;
|
|---|
| 628 | }
|
|---|
| 629 | }
|
|---|
| 630 |
|
|---|
| 631 | r = fr30_final_link_relocate (howto, input_bfd, input_section,
|
|---|
| 632 | contents, rel, relocation);
|
|---|
| 633 |
|
|---|
| 634 | if (r != bfd_reloc_ok)
|
|---|
| 635 | {
|
|---|
| 636 | const char * msg = (const char *) NULL;
|
|---|
| 637 |
|
|---|
| 638 | switch (r)
|
|---|
| 639 | {
|
|---|
| 640 | case bfd_reloc_overflow:
|
|---|
| 641 | r = info->callbacks->reloc_overflow
|
|---|
| 642 | (info, name, howto->name, (bfd_vma) 0,
|
|---|
| 643 | input_bfd, input_section, rel->r_offset);
|
|---|
| 644 | break;
|
|---|
| 645 |
|
|---|
| 646 | case bfd_reloc_undefined:
|
|---|
| 647 | r = info->callbacks->undefined_symbol
|
|---|
| 648 | (info, name, input_bfd, input_section, rel->r_offset,
|
|---|
| 649 | true);
|
|---|
| 650 | break;
|
|---|
| 651 |
|
|---|
| 652 | case bfd_reloc_outofrange:
|
|---|
| 653 | msg = _("internal error: out of range error");
|
|---|
| 654 | break;
|
|---|
| 655 |
|
|---|
| 656 | case bfd_reloc_notsupported:
|
|---|
| 657 | msg = _("internal error: unsupported relocation error");
|
|---|
| 658 | break;
|
|---|
| 659 |
|
|---|
| 660 | case bfd_reloc_dangerous:
|
|---|
| 661 | msg = _("internal error: dangerous relocation");
|
|---|
| 662 | break;
|
|---|
| 663 |
|
|---|
| 664 | default:
|
|---|
| 665 | msg = _("internal error: unknown error");
|
|---|
| 666 | break;
|
|---|
| 667 | }
|
|---|
| 668 |
|
|---|
| 669 | if (msg)
|
|---|
| 670 | r = info->callbacks->warning
|
|---|
| 671 | (info, msg, name, input_bfd, input_section, rel->r_offset);
|
|---|
| 672 |
|
|---|
| 673 | if (! r)
|
|---|
| 674 | return false;
|
|---|
| 675 | }
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 | return true;
|
|---|
| 679 | }
|
|---|
| 680 | |
|---|
| 681 |
|
|---|
| 682 | /* Return the section that should be marked against GC for a given
|
|---|
| 683 | relocation. */
|
|---|
| 684 |
|
|---|
| 685 | static asection *
|
|---|
| 686 | fr30_elf_gc_mark_hook (abfd, info, rel, h, sym)
|
|---|
| 687 | bfd * abfd;
|
|---|
| 688 | struct bfd_link_info * info ATTRIBUTE_UNUSED;
|
|---|
| 689 | Elf_Internal_Rela * rel;
|
|---|
| 690 | struct elf_link_hash_entry * h;
|
|---|
| 691 | Elf_Internal_Sym * sym;
|
|---|
| 692 | {
|
|---|
| 693 | if (h != NULL)
|
|---|
| 694 | {
|
|---|
| 695 | switch (ELF32_R_TYPE (rel->r_info))
|
|---|
| 696 | {
|
|---|
| 697 | case R_FR30_GNU_VTINHERIT:
|
|---|
| 698 | case R_FR30_GNU_VTENTRY:
|
|---|
| 699 | break;
|
|---|
| 700 |
|
|---|
| 701 | default:
|
|---|
| 702 | switch (h->root.type)
|
|---|
| 703 | {
|
|---|
| 704 | case bfd_link_hash_defined:
|
|---|
| 705 | case bfd_link_hash_defweak:
|
|---|
| 706 | return h->root.u.def.section;
|
|---|
| 707 |
|
|---|
| 708 | case bfd_link_hash_common:
|
|---|
| 709 | return h->root.u.c.p->section;
|
|---|
| 710 |
|
|---|
| 711 | default:
|
|---|
| 712 | break;
|
|---|
| 713 | }
|
|---|
| 714 | }
|
|---|
| 715 | }
|
|---|
| 716 | else
|
|---|
| 717 | {
|
|---|
| 718 | if (!(elf_bad_symtab (abfd)
|
|---|
| 719 | && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
|
|---|
| 720 | && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
|
|---|
| 721 | && sym->st_shndx != SHN_COMMON))
|
|---|
| 722 | {
|
|---|
| 723 | return bfd_section_from_elf_index (abfd, sym->st_shndx);
|
|---|
| 724 | }
|
|---|
| 725 | }
|
|---|
| 726 |
|
|---|
| 727 | return NULL;
|
|---|
| 728 | }
|
|---|
| 729 |
|
|---|
| 730 | /* Update the got entry reference counts for the section being removed. */
|
|---|
| 731 |
|
|---|
| 732 | static boolean
|
|---|
| 733 | fr30_elf_gc_sweep_hook (abfd, info, sec, relocs)
|
|---|
| 734 | bfd * abfd ATTRIBUTE_UNUSED;
|
|---|
| 735 | struct bfd_link_info * info ATTRIBUTE_UNUSED;
|
|---|
| 736 | asection * sec ATTRIBUTE_UNUSED;
|
|---|
| 737 | const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED;
|
|---|
| 738 | {
|
|---|
| 739 | return true;
|
|---|
| 740 | }
|
|---|
| 741 |
|
|---|
| 742 | /* Look through the relocs for a section during the first phase.
|
|---|
| 743 | Since we don't do .gots or .plts, we just need to consider the
|
|---|
| 744 | virtual table relocs for gc. */
|
|---|
| 745 |
|
|---|
| 746 | static boolean
|
|---|
| 747 | fr30_elf_check_relocs (abfd, info, sec, relocs)
|
|---|
| 748 | bfd *abfd;
|
|---|
| 749 | struct bfd_link_info *info;
|
|---|
| 750 | asection *sec;
|
|---|
| 751 | const Elf_Internal_Rela *relocs;
|
|---|
| 752 | {
|
|---|
| 753 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 754 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
|
|---|
| 755 | const Elf_Internal_Rela *rel;
|
|---|
| 756 | const Elf_Internal_Rela *rel_end;
|
|---|
| 757 |
|
|---|
| 758 | if (info->relocateable)
|
|---|
| 759 | return true;
|
|---|
| 760 |
|
|---|
| 761 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
|---|
| 762 | sym_hashes = elf_sym_hashes (abfd);
|
|---|
| 763 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
|
|---|
| 764 | if (!elf_bad_symtab (abfd))
|
|---|
| 765 | sym_hashes_end -= symtab_hdr->sh_info;
|
|---|
| 766 |
|
|---|
| 767 | rel_end = relocs + sec->reloc_count;
|
|---|
| 768 | for (rel = relocs; rel < rel_end; rel++)
|
|---|
| 769 | {
|
|---|
| 770 | struct elf_link_hash_entry *h;
|
|---|
| 771 | unsigned long r_symndx;
|
|---|
| 772 |
|
|---|
| 773 | r_symndx = ELF32_R_SYM (rel->r_info);
|
|---|
| 774 | if (r_symndx < symtab_hdr->sh_info)
|
|---|
| 775 | h = NULL;
|
|---|
| 776 | else
|
|---|
| 777 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
|---|
| 778 |
|
|---|
| 779 | switch (ELF32_R_TYPE (rel->r_info))
|
|---|
| 780 | {
|
|---|
| 781 | /* This relocation describes the C++ object vtable hierarchy.
|
|---|
| 782 | Reconstruct it for later use during GC. */
|
|---|
| 783 | case R_FR30_GNU_VTINHERIT:
|
|---|
| 784 | if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
|
|---|
| 785 | return false;
|
|---|
| 786 | break;
|
|---|
| 787 |
|
|---|
| 788 | /* This relocation describes which C++ vtable entries are actually
|
|---|
| 789 | used. Record for later use during GC. */
|
|---|
| 790 | case R_FR30_GNU_VTENTRY:
|
|---|
| 791 | if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
|
|---|
| 792 | return false;
|
|---|
| 793 | break;
|
|---|
| 794 | }
|
|---|
| 795 | }
|
|---|
| 796 |
|
|---|
| 797 | return true;
|
|---|
| 798 | }
|
|---|
| 799 | |
|---|
| 800 |
|
|---|
| 801 | #define ELF_ARCH bfd_arch_fr30
|
|---|
| 802 | #define ELF_MACHINE_CODE EM_CYGNUS_FR30
|
|---|
| 803 | #define ELF_MAXPAGESIZE 0x1000
|
|---|
| 804 |
|
|---|
| 805 | #define TARGET_BIG_SYM bfd_elf32_fr30_vec
|
|---|
| 806 | #define TARGET_BIG_NAME "elf32-fr30"
|
|---|
| 807 |
|
|---|
| 808 | #define elf_info_to_howto_rel NULL
|
|---|
| 809 | #define elf_info_to_howto fr30_info_to_howto_rela
|
|---|
| 810 | #define elf_backend_relocate_section fr30_elf_relocate_section
|
|---|
| 811 | #define elf_backend_gc_mark_hook fr30_elf_gc_mark_hook
|
|---|
| 812 | #define elf_backend_gc_sweep_hook fr30_elf_gc_sweep_hook
|
|---|
| 813 | #define elf_backend_check_relocs fr30_elf_check_relocs
|
|---|
| 814 |
|
|---|
| 815 | #define elf_backend_can_gc_sections 1
|
|---|
| 816 |
|
|---|
| 817 | #define bfd_elf32_bfd_reloc_type_lookup fr30_reloc_type_lookup
|
|---|
| 818 |
|
|---|
| 819 | #include "elf32-target.h"
|
|---|