| 1 | /* Renesas / SuperH SH specific support for 32-bit ELF |
| 2 | Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 |
| 3 | Free Software Foundation, Inc. |
| 4 | Contributed by Ian Lance Taylor, Cygnus Support. |
| 5 | |
| 6 | This file is part of BFD, the Binary File Descriptor library. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 21 | |
| 22 | #include "bfd.h" |
| 23 | #include "sysdep.h" |
| 24 | #include "bfdlink.h" |
| 25 | #include "libbfd.h" |
| 26 | #include "elf-bfd.h" |
| 27 | #include "elf/sh.h" |
| 28 | #include "libiberty.h" |
| 29 | #include "../opcodes/sh-opc.h" |
| 30 | |
| 31 | static bfd_reloc_status_type sh_elf_reloc |
| 32 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 33 | static bfd_reloc_status_type sh_elf_ignore_reloc |
| 34 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 35 | static reloc_howto_type *sh_elf_reloc_type_lookup |
| 36 | (bfd *, bfd_reloc_code_real_type); |
| 37 | static void sh_elf_info_to_howto |
| 38 | (bfd *, arelent *, Elf_Internal_Rela *); |
| 39 | static bfd_boolean sh_elf_set_private_flags |
| 40 | (bfd *, flagword); |
| 41 | static bfd_boolean sh_elf_copy_private_data |
| 42 | (bfd *, bfd *); |
| 43 | static bfd_boolean sh_elf_merge_private_data |
| 44 | (bfd *, bfd *); |
| 45 | static bfd_boolean sh_elf_set_mach_from_flags |
| 46 | (bfd *); |
| 47 | static bfd_boolean sh_elf_relax_section |
| 48 | (bfd *, asection *, struct bfd_link_info *, bfd_boolean *); |
| 49 | static bfd_boolean sh_elf_relax_delete_bytes |
| 50 | (bfd *, asection *, bfd_vma, int); |
| 51 | static bfd_boolean sh_elf_align_loads |
| 52 | (bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_boolean *); |
| 53 | #ifndef SH64_ELF |
| 54 | static bfd_boolean sh_elf_swap_insns |
| 55 | (bfd *, asection *, void *, bfd_byte *, bfd_vma); |
| 56 | #endif |
| 57 | static bfd_boolean sh_elf_relocate_section |
| 58 | (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, |
| 59 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **); |
| 60 | static bfd_byte *sh_elf_get_relocated_section_contents |
| 61 | (bfd *, struct bfd_link_info *, struct bfd_link_order *, bfd_byte *, |
| 62 | bfd_boolean, asymbol **); |
| 63 | static void sh_elf_copy_indirect_symbol |
| 64 | (const struct elf_backend_data *, struct elf_link_hash_entry *, |
| 65 | struct elf_link_hash_entry *); |
| 66 | static int sh_elf_optimized_tls_reloc |
| 67 | (struct bfd_link_info *, int, int); |
| 68 | static bfd_boolean sh_elf_mkobject |
| 69 | (bfd *); |
| 70 | static bfd_boolean sh_elf_object_p |
| 71 | (bfd *); |
| 72 | static bfd_boolean sh_elf_check_relocs |
| 73 | (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *); |
| 74 | static struct bfd_hash_entry *sh_elf_link_hash_newfunc |
| 75 | (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); |
| 76 | static struct bfd_link_hash_table *sh_elf_link_hash_table_create |
| 77 | (bfd *); |
| 78 | static bfd_boolean sh_elf_adjust_dynamic_symbol |
| 79 | (struct bfd_link_info *, struct elf_link_hash_entry *); |
| 80 | static bfd_boolean sh_elf_size_dynamic_sections |
| 81 | (bfd *, struct bfd_link_info *); |
| 82 | static bfd_boolean sh_elf_finish_dynamic_symbol |
| 83 | (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, |
| 84 | Elf_Internal_Sym *); |
| 85 | static bfd_boolean sh_elf_finish_dynamic_sections |
| 86 | (bfd *, struct bfd_link_info *); |
| 87 | static bfd_reloc_status_type sh_elf_reloc_loop |
| 88 | (int, bfd *, asection *, bfd_byte *, bfd_vma, asection *, bfd_vma, |
| 89 | bfd_vma); |
| 90 | static bfd_boolean create_got_section |
| 91 | (bfd *, struct bfd_link_info *); |
| 92 | static bfd_boolean sh_elf_create_dynamic_sections |
| 93 | (bfd *, struct bfd_link_info *); |
| 94 | static bfd_vma dtpoff_base |
| 95 | (struct bfd_link_info *); |
| 96 | static bfd_vma tpoff |
| 97 | (struct bfd_link_info *, bfd_vma); |
| 98 | static asection * sh_elf_gc_mark_hook |
| 99 | (asection *, struct bfd_link_info *, Elf_Internal_Rela *, |
| 100 | struct elf_link_hash_entry *, Elf_Internal_Sym *); |
| 101 | static bfd_boolean sh_elf_gc_sweep_hook |
| 102 | (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *); |
| 103 | static bfd_boolean allocate_dynrelocs |
| 104 | (struct elf_link_hash_entry *, void *); |
| 105 | static bfd_boolean readonly_dynrelocs |
| 106 | (struct elf_link_hash_entry *, void *); |
| 107 | static enum elf_reloc_type_class sh_elf_reloc_type_class |
| 108 | (const Elf_Internal_Rela *); |
| 109 | #ifdef INCLUDE_SHMEDIA |
| 110 | inline static void movi_shori_putval (bfd *, unsigned long, char *); |
| 111 | #endif |
| 112 | #if !defined SH_TARGET_ALREADY_DEFINED |
| 113 | static bfd_boolean elf32_shlin_grok_prstatus |
| 114 | (bfd *abfd, Elf_Internal_Note *note); |
| 115 | static bfd_boolean elf32_shlin_grok_psinfo |
| 116 | (bfd *abfd, Elf_Internal_Note *note); |
| 117 | #endif |
| 118 | |
| 119 | /* The name of the dynamic interpreter. This is put in the .interp |
| 120 | section. */ |
| 121 | |
| 122 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1" |
| 123 | |
| 124 | static reloc_howto_type sh_elf_howto_table[] = |
| 125 | { |
| 126 | /* No relocation. */ |
| 127 | HOWTO (R_SH_NONE, /* type */ |
| 128 | 0, /* rightshift */ |
| 129 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 130 | 0, /* bitsize */ |
| 131 | FALSE, /* pc_relative */ |
| 132 | 0, /* bitpos */ |
| 133 | complain_overflow_dont, /* complain_on_overflow */ |
| 134 | sh_elf_ignore_reloc, /* special_function */ |
| 135 | "R_SH_NONE", /* name */ |
| 136 | FALSE, /* partial_inplace */ |
| 137 | 0, /* src_mask */ |
| 138 | 0, /* dst_mask */ |
| 139 | FALSE), /* pcrel_offset */ |
| 140 | |
| 141 | /* 32 bit absolute relocation. Setting partial_inplace to TRUE and |
| 142 | src_mask to a non-zero value is similar to the COFF toolchain. */ |
| 143 | HOWTO (R_SH_DIR32, /* type */ |
| 144 | 0, /* rightshift */ |
| 145 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 146 | 32, /* bitsize */ |
| 147 | FALSE, /* pc_relative */ |
| 148 | 0, /* bitpos */ |
| 149 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 150 | sh_elf_reloc, /* special_function */ |
| 151 | "R_SH_DIR32", /* name */ |
| 152 | TRUE, /* partial_inplace */ |
| 153 | 0xffffffff, /* src_mask */ |
| 154 | 0xffffffff, /* dst_mask */ |
| 155 | FALSE), /* pcrel_offset */ |
| 156 | |
| 157 | /* 32 bit PC relative relocation. */ |
| 158 | HOWTO (R_SH_REL32, /* type */ |
| 159 | 0, /* rightshift */ |
| 160 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 161 | 32, /* bitsize */ |
| 162 | TRUE, /* pc_relative */ |
| 163 | 0, /* bitpos */ |
| 164 | complain_overflow_signed, /* complain_on_overflow */ |
| 165 | sh_elf_ignore_reloc, /* special_function */ |
| 166 | "R_SH_REL32", /* name */ |
| 167 | TRUE, /* partial_inplace */ |
| 168 | 0xffffffff, /* src_mask */ |
| 169 | 0xffffffff, /* dst_mask */ |
| 170 | TRUE), /* pcrel_offset */ |
| 171 | |
| 172 | /* 8 bit PC relative branch divided by 2. */ |
| 173 | HOWTO (R_SH_DIR8WPN, /* type */ |
| 174 | 1, /* rightshift */ |
| 175 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 176 | 8, /* bitsize */ |
| 177 | TRUE, /* pc_relative */ |
| 178 | 0, /* bitpos */ |
| 179 | complain_overflow_signed, /* complain_on_overflow */ |
| 180 | sh_elf_ignore_reloc, /* special_function */ |
| 181 | "R_SH_DIR8WPN", /* name */ |
| 182 | TRUE, /* partial_inplace */ |
| 183 | 0xff, /* src_mask */ |
| 184 | 0xff, /* dst_mask */ |
| 185 | TRUE), /* pcrel_offset */ |
| 186 | |
| 187 | /* 12 bit PC relative branch divided by 2. */ |
| 188 | /* This cannot be partial_inplace because relaxation can't know the |
| 189 | eventual value of a symbol. */ |
| 190 | HOWTO (R_SH_IND12W, /* type */ |
| 191 | 1, /* rightshift */ |
| 192 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 193 | 12, /* bitsize */ |
| 194 | TRUE, /* pc_relative */ |
| 195 | 0, /* bitpos */ |
| 196 | complain_overflow_signed, /* complain_on_overflow */ |
| 197 | NULL, /* special_function */ |
| 198 | "R_SH_IND12W", /* name */ |
| 199 | FALSE, /* partial_inplace */ |
| 200 | 0x0, /* src_mask */ |
| 201 | 0xfff, /* dst_mask */ |
| 202 | TRUE), /* pcrel_offset */ |
| 203 | |
| 204 | /* 8 bit unsigned PC relative divided by 4. */ |
| 205 | HOWTO (R_SH_DIR8WPL, /* type */ |
| 206 | 2, /* rightshift */ |
| 207 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 208 | 8, /* bitsize */ |
| 209 | TRUE, /* pc_relative */ |
| 210 | 0, /* bitpos */ |
| 211 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 212 | sh_elf_ignore_reloc, /* special_function */ |
| 213 | "R_SH_DIR8WPL", /* name */ |
| 214 | TRUE, /* partial_inplace */ |
| 215 | 0xff, /* src_mask */ |
| 216 | 0xff, /* dst_mask */ |
| 217 | TRUE), /* pcrel_offset */ |
| 218 | |
| 219 | /* 8 bit unsigned PC relative divided by 2. */ |
| 220 | HOWTO (R_SH_DIR8WPZ, /* type */ |
| 221 | 1, /* rightshift */ |
| 222 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 223 | 8, /* bitsize */ |
| 224 | TRUE, /* pc_relative */ |
| 225 | 0, /* bitpos */ |
| 226 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 227 | sh_elf_ignore_reloc, /* special_function */ |
| 228 | "R_SH_DIR8WPZ", /* name */ |
| 229 | TRUE, /* partial_inplace */ |
| 230 | 0xff, /* src_mask */ |
| 231 | 0xff, /* dst_mask */ |
| 232 | TRUE), /* pcrel_offset */ |
| 233 | |
| 234 | /* 8 bit GBR relative. FIXME: This only makes sense if we have some |
| 235 | special symbol for the GBR relative area, and that is not |
| 236 | implemented. */ |
| 237 | HOWTO (R_SH_DIR8BP, /* type */ |
| 238 | 0, /* rightshift */ |
| 239 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 240 | 8, /* bitsize */ |
| 241 | FALSE, /* pc_relative */ |
| 242 | 0, /* bitpos */ |
| 243 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 244 | sh_elf_ignore_reloc, /* special_function */ |
| 245 | "R_SH_DIR8BP", /* name */ |
| 246 | FALSE, /* partial_inplace */ |
| 247 | 0, /* src_mask */ |
| 248 | 0xff, /* dst_mask */ |
| 249 | TRUE), /* pcrel_offset */ |
| 250 | |
| 251 | /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if |
| 252 | we have some special symbol for the GBR relative area, and that |
| 253 | is not implemented. */ |
| 254 | HOWTO (R_SH_DIR8W, /* type */ |
| 255 | 1, /* rightshift */ |
| 256 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 257 | 8, /* bitsize */ |
| 258 | FALSE, /* pc_relative */ |
| 259 | 0, /* bitpos */ |
| 260 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 261 | sh_elf_ignore_reloc, /* special_function */ |
| 262 | "R_SH_DIR8W", /* name */ |
| 263 | FALSE, /* partial_inplace */ |
| 264 | 0, /* src_mask */ |
| 265 | 0xff, /* dst_mask */ |
| 266 | TRUE), /* pcrel_offset */ |
| 267 | |
| 268 | /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if |
| 269 | we have some special symbol for the GBR relative area, and that |
| 270 | is not implemented. */ |
| 271 | HOWTO (R_SH_DIR8L, /* type */ |
| 272 | 2, /* rightshift */ |
| 273 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 274 | 8, /* bitsize */ |
| 275 | FALSE, /* pc_relative */ |
| 276 | 0, /* bitpos */ |
| 277 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 278 | sh_elf_ignore_reloc, /* special_function */ |
| 279 | "R_SH_DIR8L", /* name */ |
| 280 | FALSE, /* partial_inplace */ |
| 281 | 0, /* src_mask */ |
| 282 | 0xff, /* dst_mask */ |
| 283 | TRUE), /* pcrel_offset */ |
| 284 | |
| 285 | /* 8 bit PC relative divided by 2 - but specified in a very odd way. */ |
| 286 | HOWTO (R_SH_LOOP_START, /* type */ |
| 287 | 1, /* rightshift */ |
| 288 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 289 | 8, /* bitsize */ |
| 290 | FALSE, /* pc_relative */ |
| 291 | 0, /* bitpos */ |
| 292 | complain_overflow_signed, /* complain_on_overflow */ |
| 293 | sh_elf_ignore_reloc, /* special_function */ |
| 294 | "R_SH_LOOP_START", /* name */ |
| 295 | TRUE, /* partial_inplace */ |
| 296 | 0xff, /* src_mask */ |
| 297 | 0xff, /* dst_mask */ |
| 298 | TRUE), /* pcrel_offset */ |
| 299 | |
| 300 | /* 8 bit PC relative divided by 2 - but specified in a very odd way. */ |
| 301 | HOWTO (R_SH_LOOP_END, /* type */ |
| 302 | 1, /* rightshift */ |
| 303 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 304 | 8, /* bitsize */ |
| 305 | FALSE, /* pc_relative */ |
| 306 | 0, /* bitpos */ |
| 307 | complain_overflow_signed, /* complain_on_overflow */ |
| 308 | sh_elf_ignore_reloc, /* special_function */ |
| 309 | "R_SH_LOOP_END", /* name */ |
| 310 | TRUE, /* partial_inplace */ |
| 311 | 0xff, /* src_mask */ |
| 312 | 0xff, /* dst_mask */ |
| 313 | TRUE), /* pcrel_offset */ |
| 314 | |
| 315 | EMPTY_HOWTO (12), |
| 316 | EMPTY_HOWTO (13), |
| 317 | EMPTY_HOWTO (14), |
| 318 | EMPTY_HOWTO (15), |
| 319 | EMPTY_HOWTO (16), |
| 320 | EMPTY_HOWTO (17), |
| 321 | EMPTY_HOWTO (18), |
| 322 | EMPTY_HOWTO (19), |
| 323 | EMPTY_HOWTO (20), |
| 324 | EMPTY_HOWTO (21), |
| 325 | |
| 326 | /* The remaining relocs are a GNU extension used for relaxing. The |
| 327 | final pass of the linker never needs to do anything with any of |
| 328 | these relocs. Any required operations are handled by the |
| 329 | relaxation code. */ |
| 330 | |
| 331 | /* GNU extension to record C++ vtable hierarchy */ |
| 332 | HOWTO (R_SH_GNU_VTINHERIT, /* type */ |
| 333 | 0, /* rightshift */ |
| 334 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 335 | 0, /* bitsize */ |
| 336 | FALSE, /* pc_relative */ |
| 337 | 0, /* bitpos */ |
| 338 | complain_overflow_dont, /* complain_on_overflow */ |
| 339 | NULL, /* special_function */ |
| 340 | "R_SH_GNU_VTINHERIT", /* name */ |
| 341 | FALSE, /* partial_inplace */ |
| 342 | 0, /* src_mask */ |
| 343 | 0, /* dst_mask */ |
| 344 | FALSE), /* pcrel_offset */ |
| 345 | |
| 346 | /* GNU extension to record C++ vtable member usage */ |
| 347 | HOWTO (R_SH_GNU_VTENTRY, /* type */ |
| 348 | 0, /* rightshift */ |
| 349 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 350 | 0, /* bitsize */ |
| 351 | FALSE, /* pc_relative */ |
| 352 | 0, /* bitpos */ |
| 353 | complain_overflow_dont, /* complain_on_overflow */ |
| 354 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ |
| 355 | "R_SH_GNU_VTENTRY", /* name */ |
| 356 | FALSE, /* partial_inplace */ |
| 357 | 0, /* src_mask */ |
| 358 | 0, /* dst_mask */ |
| 359 | FALSE), /* pcrel_offset */ |
| 360 | |
| 361 | /* An 8 bit switch table entry. This is generated for an expression |
| 362 | such as ``.word L1 - L2''. The offset holds the difference |
| 363 | between the reloc address and L2. */ |
| 364 | HOWTO (R_SH_SWITCH8, /* type */ |
| 365 | 0, /* rightshift */ |
| 366 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 367 | 8, /* bitsize */ |
| 368 | FALSE, /* pc_relative */ |
| 369 | 0, /* bitpos */ |
| 370 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 371 | sh_elf_ignore_reloc, /* special_function */ |
| 372 | "R_SH_SWITCH8", /* name */ |
| 373 | FALSE, /* partial_inplace */ |
| 374 | 0, /* src_mask */ |
| 375 | 0, /* dst_mask */ |
| 376 | TRUE), /* pcrel_offset */ |
| 377 | |
| 378 | /* A 16 bit switch table entry. This is generated for an expression |
| 379 | such as ``.word L1 - L2''. The offset holds the difference |
| 380 | between the reloc address and L2. */ |
| 381 | HOWTO (R_SH_SWITCH16, /* type */ |
| 382 | 0, /* rightshift */ |
| 383 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 384 | 16, /* bitsize */ |
| 385 | FALSE, /* pc_relative */ |
| 386 | 0, /* bitpos */ |
| 387 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 388 | sh_elf_ignore_reloc, /* special_function */ |
| 389 | "R_SH_SWITCH16", /* name */ |
| 390 | FALSE, /* partial_inplace */ |
| 391 | 0, /* src_mask */ |
| 392 | 0, /* dst_mask */ |
| 393 | TRUE), /* pcrel_offset */ |
| 394 | |
| 395 | /* A 32 bit switch table entry. This is generated for an expression |
| 396 | such as ``.long L1 - L2''. The offset holds the difference |
| 397 | between the reloc address and L2. */ |
| 398 | HOWTO (R_SH_SWITCH32, /* type */ |
| 399 | 0, /* rightshift */ |
| 400 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 401 | 32, /* bitsize */ |
| 402 | FALSE, /* pc_relative */ |
| 403 | 0, /* bitpos */ |
| 404 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 405 | sh_elf_ignore_reloc, /* special_function */ |
| 406 | "R_SH_SWITCH32", /* name */ |
| 407 | FALSE, /* partial_inplace */ |
| 408 | 0, /* src_mask */ |
| 409 | 0, /* dst_mask */ |
| 410 | TRUE), /* pcrel_offset */ |
| 411 | |
| 412 | /* Indicates a .uses pseudo-op. The compiler will generate .uses |
| 413 | pseudo-ops when it finds a function call which can be relaxed. |
| 414 | The offset field holds the PC relative offset to the instruction |
| 415 | which loads the register used in the function call. */ |
| 416 | HOWTO (R_SH_USES, /* type */ |
| 417 | 0, /* rightshift */ |
| 418 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 419 | 0, /* bitsize */ |
| 420 | FALSE, /* pc_relative */ |
| 421 | 0, /* bitpos */ |
| 422 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 423 | sh_elf_ignore_reloc, /* special_function */ |
| 424 | "R_SH_USES", /* name */ |
| 425 | FALSE, /* partial_inplace */ |
| 426 | 0, /* src_mask */ |
| 427 | 0, /* dst_mask */ |
| 428 | TRUE), /* pcrel_offset */ |
| 429 | |
| 430 | /* The assembler will generate this reloc for addresses referred to |
| 431 | by the register loads associated with USES relocs. The offset |
| 432 | field holds the number of times the address is referenced in the |
| 433 | object file. */ |
| 434 | HOWTO (R_SH_COUNT, /* type */ |
| 435 | 0, /* rightshift */ |
| 436 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 437 | 0, /* bitsize */ |
| 438 | FALSE, /* pc_relative */ |
| 439 | 0, /* bitpos */ |
| 440 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 441 | sh_elf_ignore_reloc, /* special_function */ |
| 442 | "R_SH_COUNT", /* name */ |
| 443 | FALSE, /* partial_inplace */ |
| 444 | 0, /* src_mask */ |
| 445 | 0, /* dst_mask */ |
| 446 | TRUE), /* pcrel_offset */ |
| 447 | |
| 448 | /* Indicates an alignment statement. The offset field is the power |
| 449 | of 2 to which subsequent portions of the object file must be |
| 450 | aligned. */ |
| 451 | HOWTO (R_SH_ALIGN, /* type */ |
| 452 | 0, /* rightshift */ |
| 453 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 454 | 0, /* bitsize */ |
| 455 | FALSE, /* pc_relative */ |
| 456 | 0, /* bitpos */ |
| 457 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 458 | sh_elf_ignore_reloc, /* special_function */ |
| 459 | "R_SH_ALIGN", /* name */ |
| 460 | FALSE, /* partial_inplace */ |
| 461 | 0, /* src_mask */ |
| 462 | 0, /* dst_mask */ |
| 463 | TRUE), /* pcrel_offset */ |
| 464 | |
| 465 | /* The assembler will generate this reloc before a block of |
| 466 | instructions. A section should be processed as assuming it |
| 467 | contains data, unless this reloc is seen. */ |
| 468 | HOWTO (R_SH_CODE, /* type */ |
| 469 | 0, /* rightshift */ |
| 470 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 471 | 0, /* bitsize */ |
| 472 | FALSE, /* pc_relative */ |
| 473 | 0, /* bitpos */ |
| 474 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 475 | sh_elf_ignore_reloc, /* special_function */ |
| 476 | "R_SH_CODE", /* name */ |
| 477 | FALSE, /* partial_inplace */ |
| 478 | 0, /* src_mask */ |
| 479 | 0, /* dst_mask */ |
| 480 | TRUE), /* pcrel_offset */ |
| 481 | |
| 482 | /* The assembler will generate this reloc after a block of |
| 483 | instructions when it sees data that is not instructions. */ |
| 484 | HOWTO (R_SH_DATA, /* type */ |
| 485 | 0, /* rightshift */ |
| 486 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 487 | 0, /* bitsize */ |
| 488 | FALSE, /* pc_relative */ |
| 489 | 0, /* bitpos */ |
| 490 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 491 | sh_elf_ignore_reloc, /* special_function */ |
| 492 | "R_SH_DATA", /* name */ |
| 493 | FALSE, /* partial_inplace */ |
| 494 | 0, /* src_mask */ |
| 495 | 0, /* dst_mask */ |
| 496 | TRUE), /* pcrel_offset */ |
| 497 | |
| 498 | /* The assembler generates this reloc for each label within a block |
| 499 | of instructions. This permits the linker to avoid swapping |
| 500 | instructions which are the targets of branches. */ |
| 501 | HOWTO (R_SH_LABEL, /* type */ |
| 502 | 0, /* rightshift */ |
| 503 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 504 | 0, /* bitsize */ |
| 505 | FALSE, /* pc_relative */ |
| 506 | 0, /* bitpos */ |
| 507 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 508 | sh_elf_ignore_reloc, /* special_function */ |
| 509 | "R_SH_LABEL", /* name */ |
| 510 | FALSE, /* partial_inplace */ |
| 511 | 0, /* src_mask */ |
| 512 | 0, /* dst_mask */ |
| 513 | TRUE), /* pcrel_offset */ |
| 514 | |
| 515 | /* The next 12 are only supported via linking in SHC-generated objects. */ |
| 516 | HOWTO (R_SH_DIR16, /* type */ |
| 517 | 0, /* rightshift */ |
| 518 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 519 | 16, /* bitsize */ |
| 520 | FALSE, /* pc_relative */ |
| 521 | 0, /* bitpos */ |
| 522 | complain_overflow_dont, /* complain_on_overflow */ |
| 523 | bfd_elf_generic_reloc, /* special_function */ |
| 524 | "R_SH_DIR16", /* name */ |
| 525 | FALSE, /* partial_inplace */ |
| 526 | 0, /* src_mask */ |
| 527 | 0xffff, /* dst_mask */ |
| 528 | FALSE), /* pcrel_offset */ |
| 529 | |
| 530 | HOWTO (R_SH_DIR8, /* type */ |
| 531 | 0, /* rightshift */ |
| 532 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 533 | 8, /* bitsize */ |
| 534 | FALSE, /* pc_relative */ |
| 535 | 0, /* bitpos */ |
| 536 | complain_overflow_dont, /* complain_on_overflow */ |
| 537 | bfd_elf_generic_reloc, /* special_function */ |
| 538 | "R_SH_DIR8", /* name */ |
| 539 | FALSE, /* partial_inplace */ |
| 540 | 0, /* src_mask */ |
| 541 | 0xff, /* dst_mask */ |
| 542 | FALSE), /* pcrel_offset */ |
| 543 | |
| 544 | HOWTO (R_SH_DIR8UL, /* type */ |
| 545 | 2, /* rightshift */ |
| 546 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 547 | 8, /* bitsize */ |
| 548 | FALSE, /* pc_relative */ |
| 549 | 0, /* bitpos */ |
| 550 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 551 | bfd_elf_generic_reloc, /* special_function */ |
| 552 | "R_SH_DIR8UL", /* name */ |
| 553 | FALSE, /* partial_inplace */ |
| 554 | 0, /* src_mask */ |
| 555 | 0xff, /* dst_mask */ |
| 556 | FALSE), /* pcrel_offset */ |
| 557 | |
| 558 | HOWTO (R_SH_DIR8UW, /* type */ |
| 559 | 1, /* rightshift */ |
| 560 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 561 | 8, /* bitsize */ |
| 562 | FALSE, /* pc_relative */ |
| 563 | 0, /* bitpos */ |
| 564 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 565 | bfd_elf_generic_reloc, /* special_function */ |
| 566 | "R_SH_DIR8UW", /* name */ |
| 567 | FALSE, /* partial_inplace */ |
| 568 | 0, /* src_mask */ |
| 569 | 0xff, /* dst_mask */ |
| 570 | FALSE), /* pcrel_offset */ |
| 571 | |
| 572 | HOWTO (R_SH_DIR8U, /* type */ |
| 573 | 0, /* rightshift */ |
| 574 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 575 | 8, /* bitsize */ |
| 576 | FALSE, /* pc_relative */ |
| 577 | 0, /* bitpos */ |
| 578 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 579 | bfd_elf_generic_reloc, /* special_function */ |
| 580 | "R_SH_DIR8U", /* name */ |
| 581 | FALSE, /* partial_inplace */ |
| 582 | 0, /* src_mask */ |
| 583 | 0xff, /* dst_mask */ |
| 584 | FALSE), /* pcrel_offset */ |
| 585 | |
| 586 | HOWTO (R_SH_DIR8SW, /* type */ |
| 587 | 1, /* rightshift */ |
| 588 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 589 | 8, /* bitsize */ |
| 590 | FALSE, /* pc_relative */ |
| 591 | 0, /* bitpos */ |
| 592 | complain_overflow_signed, /* complain_on_overflow */ |
| 593 | bfd_elf_generic_reloc, /* special_function */ |
| 594 | "R_SH_DIR8SW", /* name */ |
| 595 | FALSE, /* partial_inplace */ |
| 596 | 0, /* src_mask */ |
| 597 | 0xff, /* dst_mask */ |
| 598 | FALSE), /* pcrel_offset */ |
| 599 | |
| 600 | HOWTO (R_SH_DIR8S, /* type */ |
| 601 | 0, /* rightshift */ |
| 602 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 603 | 8, /* bitsize */ |
| 604 | FALSE, /* pc_relative */ |
| 605 | 0, /* bitpos */ |
| 606 | complain_overflow_signed, /* complain_on_overflow */ |
| 607 | bfd_elf_generic_reloc, /* special_function */ |
| 608 | "R_SH_DIR8S", /* name */ |
| 609 | FALSE, /* partial_inplace */ |
| 610 | 0, /* src_mask */ |
| 611 | 0xff, /* dst_mask */ |
| 612 | FALSE), /* pcrel_offset */ |
| 613 | |
| 614 | HOWTO (R_SH_DIR4UL, /* type */ |
| 615 | 2, /* rightshift */ |
| 616 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 617 | 4, /* bitsize */ |
| 618 | FALSE, /* pc_relative */ |
| 619 | 0, /* bitpos */ |
| 620 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 621 | bfd_elf_generic_reloc, /* special_function */ |
| 622 | "R_SH_DIR4UL", /* name */ |
| 623 | FALSE, /* partial_inplace */ |
| 624 | 0, /* src_mask */ |
| 625 | 0x0f, /* dst_mask */ |
| 626 | FALSE), /* pcrel_offset */ |
| 627 | |
| 628 | HOWTO (R_SH_DIR4UW, /* type */ |
| 629 | 1, /* rightshift */ |
| 630 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 631 | 4, /* bitsize */ |
| 632 | FALSE, /* pc_relative */ |
| 633 | 0, /* bitpos */ |
| 634 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 635 | bfd_elf_generic_reloc, /* special_function */ |
| 636 | "R_SH_DIR4UW", /* name */ |
| 637 | FALSE, /* partial_inplace */ |
| 638 | 0, /* src_mask */ |
| 639 | 0x0f, /* dst_mask */ |
| 640 | FALSE), /* pcrel_offset */ |
| 641 | |
| 642 | HOWTO (R_SH_DIR4U, /* type */ |
| 643 | 0, /* rightshift */ |
| 644 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 645 | 4, /* bitsize */ |
| 646 | FALSE, /* pc_relative */ |
| 647 | 0, /* bitpos */ |
| 648 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 649 | bfd_elf_generic_reloc, /* special_function */ |
| 650 | "R_SH_DIR4U", /* name */ |
| 651 | FALSE, /* partial_inplace */ |
| 652 | 0, /* src_mask */ |
| 653 | 0x0f, /* dst_mask */ |
| 654 | FALSE), /* pcrel_offset */ |
| 655 | |
| 656 | HOWTO (R_SH_PSHA, /* type */ |
| 657 | 0, /* rightshift */ |
| 658 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 659 | 7, /* bitsize */ |
| 660 | FALSE, /* pc_relative */ |
| 661 | 4, /* bitpos */ |
| 662 | complain_overflow_signed, /* complain_on_overflow */ |
| 663 | bfd_elf_generic_reloc, /* special_function */ |
| 664 | "R_SH_PSHA", /* name */ |
| 665 | FALSE, /* partial_inplace */ |
| 666 | 0, /* src_mask */ |
| 667 | 0x0f, /* dst_mask */ |
| 668 | FALSE), /* pcrel_offset */ |
| 669 | |
| 670 | HOWTO (R_SH_PSHL, /* type */ |
| 671 | 0, /* rightshift */ |
| 672 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 673 | 7, /* bitsize */ |
| 674 | FALSE, /* pc_relative */ |
| 675 | 4, /* bitpos */ |
| 676 | complain_overflow_signed, /* complain_on_overflow */ |
| 677 | bfd_elf_generic_reloc, /* special_function */ |
| 678 | "R_SH_PSHL", /* name */ |
| 679 | FALSE, /* partial_inplace */ |
| 680 | 0, /* src_mask */ |
| 681 | 0x0f, /* dst_mask */ |
| 682 | FALSE), /* pcrel_offset */ |
| 683 | |
| 684 | #ifdef INCLUDE_SHMEDIA |
| 685 | /* Used in SHLLI.L and SHLRI.L. */ |
| 686 | HOWTO (R_SH_DIR5U, /* type */ |
| 687 | 0, /* rightshift */ |
| 688 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 689 | 5, /* bitsize */ |
| 690 | FALSE, /* pc_relative */ |
| 691 | 10, /* bitpos */ |
| 692 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 693 | bfd_elf_generic_reloc, /* special_function */ |
| 694 | "R_SH_DIR5U", /* name */ |
| 695 | FALSE, /* partial_inplace */ |
| 696 | 0, /* src_mask */ |
| 697 | 0xfc00, /* dst_mask */ |
| 698 | FALSE), /* pcrel_offset */ |
| 699 | |
| 700 | /* Used in SHARI, SHLLI et al. */ |
| 701 | HOWTO (R_SH_DIR6U, /* type */ |
| 702 | 0, /* rightshift */ |
| 703 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 704 | 6, /* bitsize */ |
| 705 | FALSE, /* pc_relative */ |
| 706 | 10, /* bitpos */ |
| 707 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 708 | bfd_elf_generic_reloc, /* special_function */ |
| 709 | "R_SH_DIR6U", /* name */ |
| 710 | FALSE, /* partial_inplace */ |
| 711 | 0, /* src_mask */ |
| 712 | 0xfc00, /* dst_mask */ |
| 713 | FALSE), /* pcrel_offset */ |
| 714 | |
| 715 | /* Used in BxxI, LDHI.L et al. */ |
| 716 | HOWTO (R_SH_DIR6S, /* type */ |
| 717 | 0, /* rightshift */ |
| 718 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 719 | 6, /* bitsize */ |
| 720 | FALSE, /* pc_relative */ |
| 721 | 10, /* bitpos */ |
| 722 | complain_overflow_signed, /* complain_on_overflow */ |
| 723 | bfd_elf_generic_reloc, /* special_function */ |
| 724 | "R_SH_DIR6S", /* name */ |
| 725 | FALSE, /* partial_inplace */ |
| 726 | 0, /* src_mask */ |
| 727 | 0xfc00, /* dst_mask */ |
| 728 | FALSE), /* pcrel_offset */ |
| 729 | |
| 730 | /* Used in ADDI, ANDI et al. */ |
| 731 | HOWTO (R_SH_DIR10S, /* type */ |
| 732 | 0, /* rightshift */ |
| 733 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 734 | 10, /* bitsize */ |
| 735 | FALSE, /* pc_relative */ |
| 736 | 10, /* bitpos */ |
| 737 | complain_overflow_signed, /* complain_on_overflow */ |
| 738 | bfd_elf_generic_reloc, /* special_function */ |
| 739 | "R_SH_DIR10S", /* name */ |
| 740 | FALSE, /* partial_inplace */ |
| 741 | 0, /* src_mask */ |
| 742 | 0xffc00, /* dst_mask */ |
| 743 | FALSE), /* pcrel_offset */ |
| 744 | |
| 745 | /* Used in LD.UW, ST.W et al. */ |
| 746 | HOWTO (R_SH_DIR10SW, /* type */ |
| 747 | 1, /* rightshift */ |
| 748 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 749 | 11, /* bitsize */ |
| 750 | FALSE, /* pc_relative */ |
| 751 | 10, /* bitpos */ |
| 752 | complain_overflow_signed, /* complain_on_overflow */ |
| 753 | bfd_elf_generic_reloc, /* special_function */ |
| 754 | "R_SH_DIR10SW", /* name */ |
| 755 | FALSE, /* partial_inplace */ |
| 756 | 0, /* src_mask */ |
| 757 | 0xffc00, /* dst_mask */ |
| 758 | FALSE), /* pcrel_offset */ |
| 759 | |
| 760 | /* Used in LD.L, FLD.S et al. */ |
| 761 | HOWTO (R_SH_DIR10SL, /* type */ |
| 762 | 2, /* rightshift */ |
| 763 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 764 | 12, /* bitsize */ |
| 765 | FALSE, /* pc_relative */ |
| 766 | 10, /* bitpos */ |
| 767 | complain_overflow_signed, /* complain_on_overflow */ |
| 768 | bfd_elf_generic_reloc, /* special_function */ |
| 769 | "R_SH_DIR10SL", /* name */ |
| 770 | FALSE, /* partial_inplace */ |
| 771 | 0, /* src_mask */ |
| 772 | 0xffc00, /* dst_mask */ |
| 773 | FALSE), /* pcrel_offset */ |
| 774 | |
| 775 | /* Used in FLD.D, FST.P et al. */ |
| 776 | HOWTO (R_SH_DIR10SQ, /* type */ |
| 777 | 3, /* rightshift */ |
| 778 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 779 | 13, /* bitsize */ |
| 780 | FALSE, /* pc_relative */ |
| 781 | 10, /* bitpos */ |
| 782 | complain_overflow_signed, /* complain_on_overflow */ |
| 783 | bfd_elf_generic_reloc, /* special_function */ |
| 784 | "R_SH_DIR10SQ", /* name */ |
| 785 | FALSE, /* partial_inplace */ |
| 786 | 0, /* src_mask */ |
| 787 | 0xffc00, /* dst_mask */ |
| 788 | FALSE), /* pcrel_offset */ |
| 789 | |
| 790 | #else |
| 791 | EMPTY_HOWTO (45), |
| 792 | EMPTY_HOWTO (46), |
| 793 | EMPTY_HOWTO (47), |
| 794 | EMPTY_HOWTO (48), |
| 795 | EMPTY_HOWTO (49), |
| 796 | EMPTY_HOWTO (50), |
| 797 | EMPTY_HOWTO (51), |
| 798 | #endif |
| 799 | |
| 800 | EMPTY_HOWTO (52), |
| 801 | |
| 802 | HOWTO (R_SH_DIR16S, /* type */ |
| 803 | 0, /* rightshift */ |
| 804 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 805 | 16, /* bitsize */ |
| 806 | FALSE, /* pc_relative */ |
| 807 | 0, /* bitpos */ |
| 808 | complain_overflow_signed, /* complain_on_overflow */ |
| 809 | bfd_elf_generic_reloc, /* special_function */ |
| 810 | "R_SH_DIR16S", /* name */ |
| 811 | FALSE, /* partial_inplace */ |
| 812 | 0, /* src_mask */ |
| 813 | 0xffff, /* dst_mask */ |
| 814 | FALSE), /* pcrel_offset */ |
| 815 | |
| 816 | EMPTY_HOWTO (54), |
| 817 | EMPTY_HOWTO (55), |
| 818 | EMPTY_HOWTO (56), |
| 819 | EMPTY_HOWTO (57), |
| 820 | EMPTY_HOWTO (58), |
| 821 | EMPTY_HOWTO (59), |
| 822 | EMPTY_HOWTO (60), |
| 823 | EMPTY_HOWTO (61), |
| 824 | EMPTY_HOWTO (62), |
| 825 | EMPTY_HOWTO (63), |
| 826 | EMPTY_HOWTO (64), |
| 827 | EMPTY_HOWTO (65), |
| 828 | EMPTY_HOWTO (66), |
| 829 | EMPTY_HOWTO (67), |
| 830 | EMPTY_HOWTO (68), |
| 831 | EMPTY_HOWTO (69), |
| 832 | EMPTY_HOWTO (70), |
| 833 | EMPTY_HOWTO (71), |
| 834 | EMPTY_HOWTO (72), |
| 835 | EMPTY_HOWTO (73), |
| 836 | EMPTY_HOWTO (74), |
| 837 | EMPTY_HOWTO (75), |
| 838 | EMPTY_HOWTO (76), |
| 839 | EMPTY_HOWTO (77), |
| 840 | EMPTY_HOWTO (78), |
| 841 | EMPTY_HOWTO (79), |
| 842 | EMPTY_HOWTO (80), |
| 843 | EMPTY_HOWTO (81), |
| 844 | EMPTY_HOWTO (82), |
| 845 | EMPTY_HOWTO (83), |
| 846 | EMPTY_HOWTO (84), |
| 847 | EMPTY_HOWTO (85), |
| 848 | EMPTY_HOWTO (86), |
| 849 | EMPTY_HOWTO (87), |
| 850 | EMPTY_HOWTO (88), |
| 851 | EMPTY_HOWTO (89), |
| 852 | EMPTY_HOWTO (90), |
| 853 | EMPTY_HOWTO (91), |
| 854 | EMPTY_HOWTO (92), |
| 855 | EMPTY_HOWTO (93), |
| 856 | EMPTY_HOWTO (94), |
| 857 | EMPTY_HOWTO (95), |
| 858 | EMPTY_HOWTO (96), |
| 859 | EMPTY_HOWTO (97), |
| 860 | EMPTY_HOWTO (98), |
| 861 | EMPTY_HOWTO (99), |
| 862 | EMPTY_HOWTO (100), |
| 863 | EMPTY_HOWTO (101), |
| 864 | EMPTY_HOWTO (102), |
| 865 | EMPTY_HOWTO (103), |
| 866 | EMPTY_HOWTO (104), |
| 867 | EMPTY_HOWTO (105), |
| 868 | EMPTY_HOWTO (106), |
| 869 | EMPTY_HOWTO (107), |
| 870 | EMPTY_HOWTO (108), |
| 871 | EMPTY_HOWTO (109), |
| 872 | EMPTY_HOWTO (110), |
| 873 | EMPTY_HOWTO (111), |
| 874 | EMPTY_HOWTO (112), |
| 875 | EMPTY_HOWTO (113), |
| 876 | EMPTY_HOWTO (114), |
| 877 | EMPTY_HOWTO (115), |
| 878 | EMPTY_HOWTO (116), |
| 879 | EMPTY_HOWTO (117), |
| 880 | EMPTY_HOWTO (118), |
| 881 | EMPTY_HOWTO (119), |
| 882 | EMPTY_HOWTO (120), |
| 883 | EMPTY_HOWTO (121), |
| 884 | EMPTY_HOWTO (122), |
| 885 | EMPTY_HOWTO (123), |
| 886 | EMPTY_HOWTO (124), |
| 887 | EMPTY_HOWTO (125), |
| 888 | EMPTY_HOWTO (126), |
| 889 | EMPTY_HOWTO (127), |
| 890 | EMPTY_HOWTO (128), |
| 891 | EMPTY_HOWTO (129), |
| 892 | EMPTY_HOWTO (130), |
| 893 | EMPTY_HOWTO (131), |
| 894 | EMPTY_HOWTO (132), |
| 895 | EMPTY_HOWTO (133), |
| 896 | EMPTY_HOWTO (134), |
| 897 | EMPTY_HOWTO (135), |
| 898 | EMPTY_HOWTO (136), |
| 899 | EMPTY_HOWTO (137), |
| 900 | EMPTY_HOWTO (138), |
| 901 | EMPTY_HOWTO (139), |
| 902 | EMPTY_HOWTO (140), |
| 903 | EMPTY_HOWTO (141), |
| 904 | EMPTY_HOWTO (142), |
| 905 | EMPTY_HOWTO (143), |
| 906 | |
| 907 | HOWTO (R_SH_TLS_GD_32, /* type */ |
| 908 | 0, /* rightshift */ |
| 909 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 910 | 32, /* bitsize */ |
| 911 | FALSE, /* pc_relative */ |
| 912 | 0, /* bitpos */ |
| 913 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 914 | bfd_elf_generic_reloc, /* */ |
| 915 | "R_SH_TLS_GD_32", /* name */ |
| 916 | TRUE, /* partial_inplace */ |
| 917 | 0xffffffff, /* src_mask */ |
| 918 | 0xffffffff, /* dst_mask */ |
| 919 | FALSE), /* pcrel_offset */ |
| 920 | |
| 921 | HOWTO (R_SH_TLS_LD_32, /* type */ |
| 922 | 0, /* rightshift */ |
| 923 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 924 | 32, /* bitsize */ |
| 925 | FALSE, /* pc_relative */ |
| 926 | 0, /* bitpos */ |
| 927 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 928 | bfd_elf_generic_reloc, /* */ |
| 929 | "R_SH_TLS_LD_32", /* name */ |
| 930 | TRUE, /* partial_inplace */ |
| 931 | 0xffffffff, /* src_mask */ |
| 932 | 0xffffffff, /* dst_mask */ |
| 933 | FALSE), /* pcrel_offset */ |
| 934 | |
| 935 | HOWTO (R_SH_TLS_LDO_32, /* type */ |
| 936 | 0, /* rightshift */ |
| 937 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 938 | 32, /* bitsize */ |
| 939 | FALSE, /* pc_relative */ |
| 940 | 0, /* bitpos */ |
| 941 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 942 | bfd_elf_generic_reloc, /* */ |
| 943 | "R_SH_TLS_LDO_32", /* name */ |
| 944 | TRUE, /* partial_inplace */ |
| 945 | 0xffffffff, /* src_mask */ |
| 946 | 0xffffffff, /* dst_mask */ |
| 947 | FALSE), /* pcrel_offset */ |
| 948 | |
| 949 | HOWTO (R_SH_TLS_IE_32, /* type */ |
| 950 | 0, /* rightshift */ |
| 951 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 952 | 32, /* bitsize */ |
| 953 | FALSE, /* pc_relative */ |
| 954 | 0, /* bitpos */ |
| 955 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 956 | bfd_elf_generic_reloc, /* */ |
| 957 | "R_SH_TLS_IE_32", /* name */ |
| 958 | TRUE, /* partial_inplace */ |
| 959 | 0xffffffff, /* src_mask */ |
| 960 | 0xffffffff, /* dst_mask */ |
| 961 | FALSE), /* pcrel_offset */ |
| 962 | |
| 963 | HOWTO (R_SH_TLS_LE_32, /* type */ |
| 964 | 0, /* rightshift */ |
| 965 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 966 | 32, /* bitsize */ |
| 967 | FALSE, /* pc_relative */ |
| 968 | 0, /* bitpos */ |
| 969 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 970 | bfd_elf_generic_reloc, /* */ |
| 971 | "R_SH_TLS_LE_32", /* name */ |
| 972 | TRUE, /* partial_inplace */ |
| 973 | 0xffffffff, /* src_mask */ |
| 974 | 0xffffffff, /* dst_mask */ |
| 975 | FALSE), /* pcrel_offset */ |
| 976 | |
| 977 | HOWTO (R_SH_TLS_DTPMOD32, /* type */ |
| 978 | 0, /* rightshift */ |
| 979 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 980 | 32, /* bitsize */ |
| 981 | FALSE, /* pc_relative */ |
| 982 | 0, /* bitpos */ |
| 983 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 984 | bfd_elf_generic_reloc, /* */ |
| 985 | "R_SH_TLS_DTPMOD32", /* name */ |
| 986 | TRUE, /* partial_inplace */ |
| 987 | 0xffffffff, /* src_mask */ |
| 988 | 0xffffffff, /* dst_mask */ |
| 989 | FALSE), /* pcrel_offset */ |
| 990 | |
| 991 | HOWTO (R_SH_TLS_DTPOFF32, /* type */ |
| 992 | 0, /* rightshift */ |
| 993 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 994 | 32, /* bitsize */ |
| 995 | FALSE, /* pc_relative */ |
| 996 | 0, /* bitpos */ |
| 997 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 998 | bfd_elf_generic_reloc, /* */ |
| 999 | "R_SH_TLS_DTPOFF32", /* name */ |
| 1000 | TRUE, /* partial_inplace */ |
| 1001 | 0xffffffff, /* src_mask */ |
| 1002 | 0xffffffff, /* dst_mask */ |
| 1003 | FALSE), /* pcrel_offset */ |
| 1004 | |
| 1005 | HOWTO (R_SH_TLS_TPOFF32, /* type */ |
| 1006 | 0, /* rightshift */ |
| 1007 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1008 | 32, /* bitsize */ |
| 1009 | FALSE, /* pc_relative */ |
| 1010 | 0, /* bitpos */ |
| 1011 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1012 | bfd_elf_generic_reloc, /* */ |
| 1013 | "R_SH_TLS_TPOFF32", /* name */ |
| 1014 | TRUE, /* partial_inplace */ |
| 1015 | 0xffffffff, /* src_mask */ |
| 1016 | 0xffffffff, /* dst_mask */ |
| 1017 | FALSE), /* pcrel_offset */ |
| 1018 | |
| 1019 | EMPTY_HOWTO (152), |
| 1020 | EMPTY_HOWTO (153), |
| 1021 | EMPTY_HOWTO (154), |
| 1022 | EMPTY_HOWTO (155), |
| 1023 | EMPTY_HOWTO (156), |
| 1024 | EMPTY_HOWTO (157), |
| 1025 | EMPTY_HOWTO (158), |
| 1026 | EMPTY_HOWTO (159), |
| 1027 | |
| 1028 | HOWTO (R_SH_GOT32, /* type */ |
| 1029 | 0, /* rightshift */ |
| 1030 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1031 | 32, /* bitsize */ |
| 1032 | FALSE, /* pc_relative */ |
| 1033 | 0, /* bitpos */ |
| 1034 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1035 | bfd_elf_generic_reloc, /* */ |
| 1036 | "R_SH_GOT32", /* name */ |
| 1037 | TRUE, /* partial_inplace */ |
| 1038 | 0xffffffff, /* src_mask */ |
| 1039 | 0xffffffff, /* dst_mask */ |
| 1040 | FALSE), /* pcrel_offset */ |
| 1041 | |
| 1042 | HOWTO (R_SH_PLT32, /* type */ |
| 1043 | 0, /* rightshift */ |
| 1044 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1045 | 32, /* bitsize */ |
| 1046 | TRUE, /* pc_relative */ |
| 1047 | 0, /* bitpos */ |
| 1048 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1049 | bfd_elf_generic_reloc, /* */ |
| 1050 | "R_SH_PLT32", /* name */ |
| 1051 | TRUE, /* partial_inplace */ |
| 1052 | 0xffffffff, /* src_mask */ |
| 1053 | 0xffffffff, /* dst_mask */ |
| 1054 | TRUE), /* pcrel_offset */ |
| 1055 | |
| 1056 | HOWTO (R_SH_COPY, /* type */ |
| 1057 | 0, /* rightshift */ |
| 1058 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1059 | 32, /* bitsize */ |
| 1060 | FALSE, /* pc_relative */ |
| 1061 | 0, /* bitpos */ |
| 1062 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1063 | bfd_elf_generic_reloc, /* */ |
| 1064 | "R_SH_COPY", /* name */ |
| 1065 | TRUE, /* partial_inplace */ |
| 1066 | 0xffffffff, /* src_mask */ |
| 1067 | 0xffffffff, /* dst_mask */ |
| 1068 | FALSE), /* pcrel_offset */ |
| 1069 | |
| 1070 | HOWTO (R_SH_GLOB_DAT, /* type */ |
| 1071 | 0, /* rightshift */ |
| 1072 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1073 | 32, /* bitsize */ |
| 1074 | FALSE, /* pc_relative */ |
| 1075 | 0, /* bitpos */ |
| 1076 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1077 | bfd_elf_generic_reloc, /* */ |
| 1078 | "R_SH_GLOB_DAT", /* name */ |
| 1079 | TRUE, /* partial_inplace */ |
| 1080 | 0xffffffff, /* src_mask */ |
| 1081 | 0xffffffff, /* dst_mask */ |
| 1082 | FALSE), /* pcrel_offset */ |
| 1083 | |
| 1084 | HOWTO (R_SH_JMP_SLOT, /* type */ |
| 1085 | 0, /* rightshift */ |
| 1086 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1087 | 32, /* bitsize */ |
| 1088 | FALSE, /* pc_relative */ |
| 1089 | 0, /* bitpos */ |
| 1090 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1091 | bfd_elf_generic_reloc, /* */ |
| 1092 | "R_SH_JMP_SLOT", /* name */ |
| 1093 | TRUE, /* partial_inplace */ |
| 1094 | 0xffffffff, /* src_mask */ |
| 1095 | 0xffffffff, /* dst_mask */ |
| 1096 | FALSE), /* pcrel_offset */ |
| 1097 | |
| 1098 | HOWTO (R_SH_RELATIVE, /* type */ |
| 1099 | 0, /* rightshift */ |
| 1100 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1101 | 32, /* bitsize */ |
| 1102 | FALSE, /* pc_relative */ |
| 1103 | 0, /* bitpos */ |
| 1104 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1105 | bfd_elf_generic_reloc, /* */ |
| 1106 | "R_SH_RELATIVE", /* name */ |
| 1107 | TRUE, /* partial_inplace */ |
| 1108 | 0xffffffff, /* src_mask */ |
| 1109 | 0xffffffff, /* dst_mask */ |
| 1110 | FALSE), /* pcrel_offset */ |
| 1111 | |
| 1112 | HOWTO (R_SH_GOTOFF, /* type */ |
| 1113 | 0, /* rightshift */ |
| 1114 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1115 | 32, /* bitsize */ |
| 1116 | FALSE, /* pc_relative */ |
| 1117 | 0, /* bitpos */ |
| 1118 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1119 | bfd_elf_generic_reloc, /* */ |
| 1120 | "R_SH_GOTOFF", /* name */ |
| 1121 | TRUE, /* partial_inplace */ |
| 1122 | 0xffffffff, /* src_mask */ |
| 1123 | 0xffffffff, /* dst_mask */ |
| 1124 | FALSE), /* pcrel_offset */ |
| 1125 | |
| 1126 | HOWTO (R_SH_GOTPC, /* type */ |
| 1127 | 0, /* rightshift */ |
| 1128 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1129 | 32, /* bitsize */ |
| 1130 | TRUE, /* pc_relative */ |
| 1131 | 0, /* bitpos */ |
| 1132 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1133 | bfd_elf_generic_reloc, /* */ |
| 1134 | "R_SH_GOTPC", /* name */ |
| 1135 | TRUE, /* partial_inplace */ |
| 1136 | 0xffffffff, /* src_mask */ |
| 1137 | 0xffffffff, /* dst_mask */ |
| 1138 | TRUE), /* pcrel_offset */ |
| 1139 | |
| 1140 | HOWTO (R_SH_GOTPLT32, /* type */ |
| 1141 | 0, /* rightshift */ |
| 1142 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1143 | 32, /* bitsize */ |
| 1144 | FALSE, /* pc_relative */ |
| 1145 | 0, /* bitpos */ |
| 1146 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1147 | bfd_elf_generic_reloc, /* */ |
| 1148 | "R_SH_GOTPLT32", /* name */ |
| 1149 | FALSE, /* partial_inplace */ |
| 1150 | 0xffffffff, /* src_mask */ |
| 1151 | 0xffffffff, /* dst_mask */ |
| 1152 | FALSE), /* pcrel_offset */ |
| 1153 | |
| 1154 | #ifdef INCLUDE_SHMEDIA |
| 1155 | /* Used in MOVI and SHORI (x & 65536). */ |
| 1156 | HOWTO (R_SH_GOT_LOW16, /* type */ |
| 1157 | 0, /* rightshift */ |
| 1158 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1159 | 64, /* bitsize */ |
| 1160 | FALSE, /* pc_relative */ |
| 1161 | 10, /* bitpos */ |
| 1162 | complain_overflow_dont, /* complain_on_overflow */ |
| 1163 | bfd_elf_generic_reloc, /* special_function */ |
| 1164 | "R_SH_GOT_LOW16", /* name */ |
| 1165 | FALSE, /* partial_inplace */ |
| 1166 | 0, /* src_mask */ |
| 1167 | 0x3fffc00, /* dst_mask */ |
| 1168 | FALSE), /* pcrel_offset */ |
| 1169 | |
| 1170 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 1171 | HOWTO (R_SH_GOT_MEDLOW16, /* type */ |
| 1172 | 16, /* rightshift */ |
| 1173 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1174 | 64, /* bitsize */ |
| 1175 | FALSE, /* pc_relative */ |
| 1176 | 10, /* bitpos */ |
| 1177 | complain_overflow_dont, /* complain_on_overflow */ |
| 1178 | bfd_elf_generic_reloc, /* special_function */ |
| 1179 | "R_SH_GOT_MEDLOW16", /* name */ |
| 1180 | FALSE, /* partial_inplace */ |
| 1181 | 0, /* src_mask */ |
| 1182 | 0x3fffc00, /* dst_mask */ |
| 1183 | FALSE), /* pcrel_offset */ |
| 1184 | |
| 1185 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 1186 | HOWTO (R_SH_GOT_MEDHI16, /* type */ |
| 1187 | 32, /* rightshift */ |
| 1188 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1189 | 64, /* bitsize */ |
| 1190 | FALSE, /* pc_relative */ |
| 1191 | 10, /* bitpos */ |
| 1192 | complain_overflow_dont, /* complain_on_overflow */ |
| 1193 | bfd_elf_generic_reloc, /* special_function */ |
| 1194 | "R_SH_GOT_MEDHI16", /* name */ |
| 1195 | FALSE, /* partial_inplace */ |
| 1196 | 0, /* src_mask */ |
| 1197 | 0x3fffc00, /* dst_mask */ |
| 1198 | FALSE), /* pcrel_offset */ |
| 1199 | |
| 1200 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 1201 | HOWTO (R_SH_GOT_HI16, /* type */ |
| 1202 | 48, /* rightshift */ |
| 1203 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1204 | 64, /* bitsize */ |
| 1205 | FALSE, /* pc_relative */ |
| 1206 | 10, /* bitpos */ |
| 1207 | complain_overflow_dont, /* complain_on_overflow */ |
| 1208 | bfd_elf_generic_reloc, /* special_function */ |
| 1209 | "R_SH_GOT_HI16", /* name */ |
| 1210 | FALSE, /* partial_inplace */ |
| 1211 | 0, /* src_mask */ |
| 1212 | 0x3fffc00, /* dst_mask */ |
| 1213 | FALSE), /* pcrel_offset */ |
| 1214 | |
| 1215 | /* Used in MOVI and SHORI (x & 65536). */ |
| 1216 | HOWTO (R_SH_GOTPLT_LOW16, /* type */ |
| 1217 | 0, /* rightshift */ |
| 1218 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1219 | 64, /* bitsize */ |
| 1220 | FALSE, /* pc_relative */ |
| 1221 | 10, /* bitpos */ |
| 1222 | complain_overflow_dont, /* complain_on_overflow */ |
| 1223 | bfd_elf_generic_reloc, /* special_function */ |
| 1224 | "R_SH_GOTPLT_LOW16", /* name */ |
| 1225 | FALSE, /* partial_inplace */ |
| 1226 | 0, /* src_mask */ |
| 1227 | 0x3fffc00, /* dst_mask */ |
| 1228 | FALSE), /* pcrel_offset */ |
| 1229 | |
| 1230 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 1231 | HOWTO (R_SH_GOTPLT_MEDLOW16, /* type */ |
| 1232 | 16, /* rightshift */ |
| 1233 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1234 | 64, /* bitsize */ |
| 1235 | FALSE, /* pc_relative */ |
| 1236 | 10, /* bitpos */ |
| 1237 | complain_overflow_dont, /* complain_on_overflow */ |
| 1238 | bfd_elf_generic_reloc, /* special_function */ |
| 1239 | "R_SH_GOTPLT_MEDLOW16", /* name */ |
| 1240 | FALSE, /* partial_inplace */ |
| 1241 | 0, /* src_mask */ |
| 1242 | 0x3fffc00, /* dst_mask */ |
| 1243 | FALSE), /* pcrel_offset */ |
| 1244 | |
| 1245 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 1246 | HOWTO (R_SH_GOTPLT_MEDHI16, /* type */ |
| 1247 | 32, /* rightshift */ |
| 1248 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1249 | 64, /* bitsize */ |
| 1250 | FALSE, /* pc_relative */ |
| 1251 | 10, /* bitpos */ |
| 1252 | complain_overflow_dont, /* complain_on_overflow */ |
| 1253 | bfd_elf_generic_reloc, /* special_function */ |
| 1254 | "R_SH_GOTPLT_MEDHI16", /* name */ |
| 1255 | FALSE, /* partial_inplace */ |
| 1256 | 0, /* src_mask */ |
| 1257 | 0x3fffc00, /* dst_mask */ |
| 1258 | FALSE), /* pcrel_offset */ |
| 1259 | |
| 1260 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 1261 | HOWTO (R_SH_GOTPLT_HI16, /* type */ |
| 1262 | 48, /* rightshift */ |
| 1263 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1264 | 64, /* bitsize */ |
| 1265 | FALSE, /* pc_relative */ |
| 1266 | 10, /* bitpos */ |
| 1267 | complain_overflow_dont, /* complain_on_overflow */ |
| 1268 | bfd_elf_generic_reloc, /* special_function */ |
| 1269 | "R_SH_GOTPLT_HI16", /* name */ |
| 1270 | FALSE, /* partial_inplace */ |
| 1271 | 0, /* src_mask */ |
| 1272 | 0x3fffc00, /* dst_mask */ |
| 1273 | FALSE), /* pcrel_offset */ |
| 1274 | |
| 1275 | /* Used in MOVI and SHORI (x & 65536). */ |
| 1276 | HOWTO (R_SH_PLT_LOW16, /* type */ |
| 1277 | 0, /* rightshift */ |
| 1278 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1279 | 64, /* bitsize */ |
| 1280 | TRUE, /* pc_relative */ |
| 1281 | 10, /* bitpos */ |
| 1282 | complain_overflow_dont, /* complain_on_overflow */ |
| 1283 | bfd_elf_generic_reloc, /* special_function */ |
| 1284 | "R_SH_PLT_LOW16", /* name */ |
| 1285 | FALSE, /* partial_inplace */ |
| 1286 | 0, /* src_mask */ |
| 1287 | 0x3fffc00, /* dst_mask */ |
| 1288 | TRUE), /* pcrel_offset */ |
| 1289 | |
| 1290 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 1291 | HOWTO (R_SH_PLT_MEDLOW16, /* type */ |
| 1292 | 16, /* rightshift */ |
| 1293 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1294 | 64, /* bitsize */ |
| 1295 | TRUE, /* pc_relative */ |
| 1296 | 10, /* bitpos */ |
| 1297 | complain_overflow_dont, /* complain_on_overflow */ |
| 1298 | bfd_elf_generic_reloc, /* special_function */ |
| 1299 | "R_SH_PLT_MEDLOW16", /* name */ |
| 1300 | FALSE, /* partial_inplace */ |
| 1301 | 0, /* src_mask */ |
| 1302 | 0x3fffc00, /* dst_mask */ |
| 1303 | TRUE), /* pcrel_offset */ |
| 1304 | |
| 1305 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 1306 | HOWTO (R_SH_PLT_MEDHI16, /* type */ |
| 1307 | 32, /* rightshift */ |
| 1308 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1309 | 64, /* bitsize */ |
| 1310 | TRUE, /* pc_relative */ |
| 1311 | 10, /* bitpos */ |
| 1312 | complain_overflow_dont, /* complain_on_overflow */ |
| 1313 | bfd_elf_generic_reloc, /* special_function */ |
| 1314 | "R_SH_PLT_MEDHI16", /* name */ |
| 1315 | FALSE, /* partial_inplace */ |
| 1316 | 0, /* src_mask */ |
| 1317 | 0x3fffc00, /* dst_mask */ |
| 1318 | TRUE), /* pcrel_offset */ |
| 1319 | |
| 1320 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 1321 | HOWTO (R_SH_PLT_HI16, /* type */ |
| 1322 | 48, /* rightshift */ |
| 1323 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1324 | 64, /* bitsize */ |
| 1325 | TRUE, /* pc_relative */ |
| 1326 | 10, /* bitpos */ |
| 1327 | complain_overflow_dont, /* complain_on_overflow */ |
| 1328 | bfd_elf_generic_reloc, /* special_function */ |
| 1329 | "R_SH_PLT_HI16", /* name */ |
| 1330 | FALSE, /* partial_inplace */ |
| 1331 | 0, /* src_mask */ |
| 1332 | 0x3fffc00, /* dst_mask */ |
| 1333 | TRUE), /* pcrel_offset */ |
| 1334 | |
| 1335 | /* Used in MOVI and SHORI (x & 65536). */ |
| 1336 | HOWTO (R_SH_GOTOFF_LOW16, /* type */ |
| 1337 | 0, /* rightshift */ |
| 1338 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1339 | 64, /* bitsize */ |
| 1340 | FALSE, /* pc_relative */ |
| 1341 | 10, /* bitpos */ |
| 1342 | complain_overflow_dont, /* complain_on_overflow */ |
| 1343 | bfd_elf_generic_reloc, /* special_function */ |
| 1344 | "R_SH_GOTOFF_LOW16", /* name */ |
| 1345 | FALSE, /* partial_inplace */ |
| 1346 | 0, /* src_mask */ |
| 1347 | 0x3fffc00, /* dst_mask */ |
| 1348 | FALSE), /* pcrel_offset */ |
| 1349 | |
| 1350 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 1351 | HOWTO (R_SH_GOTOFF_MEDLOW16, /* type */ |
| 1352 | 16, /* rightshift */ |
| 1353 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1354 | 64, /* bitsize */ |
| 1355 | FALSE, /* pc_relative */ |
| 1356 | 10, /* bitpos */ |
| 1357 | complain_overflow_dont, /* complain_on_overflow */ |
| 1358 | bfd_elf_generic_reloc, /* special_function */ |
| 1359 | "R_SH_GOTOFF_MEDLOW16", /* name */ |
| 1360 | FALSE, /* partial_inplace */ |
| 1361 | 0, /* src_mask */ |
| 1362 | 0x3fffc00, /* dst_mask */ |
| 1363 | FALSE), /* pcrel_offset */ |
| 1364 | |
| 1365 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 1366 | HOWTO (R_SH_GOTOFF_MEDHI16, /* type */ |
| 1367 | 32, /* rightshift */ |
| 1368 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1369 | 64, /* bitsize */ |
| 1370 | FALSE, /* pc_relative */ |
| 1371 | 10, /* bitpos */ |
| 1372 | complain_overflow_dont, /* complain_on_overflow */ |
| 1373 | bfd_elf_generic_reloc, /* special_function */ |
| 1374 | "R_SH_GOTOFF_MEDHI16", /* name */ |
| 1375 | FALSE, /* partial_inplace */ |
| 1376 | 0, /* src_mask */ |
| 1377 | 0x3fffc00, /* dst_mask */ |
| 1378 | FALSE), /* pcrel_offset */ |
| 1379 | |
| 1380 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 1381 | HOWTO (R_SH_GOTOFF_HI16, /* type */ |
| 1382 | 48, /* rightshift */ |
| 1383 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1384 | 64, /* bitsize */ |
| 1385 | FALSE, /* pc_relative */ |
| 1386 | 10, /* bitpos */ |
| 1387 | complain_overflow_dont, /* complain_on_overflow */ |
| 1388 | bfd_elf_generic_reloc, /* special_function */ |
| 1389 | "R_SH_GOTOFF_HI16", /* name */ |
| 1390 | FALSE, /* partial_inplace */ |
| 1391 | 0, /* src_mask */ |
| 1392 | 0x3fffc00, /* dst_mask */ |
| 1393 | FALSE), /* pcrel_offset */ |
| 1394 | |
| 1395 | /* Used in MOVI and SHORI (x & 65536). */ |
| 1396 | HOWTO (R_SH_GOTPC_LOW16, /* type */ |
| 1397 | 0, /* rightshift */ |
| 1398 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1399 | 64, /* bitsize */ |
| 1400 | TRUE, /* pc_relative */ |
| 1401 | 10, /* bitpos */ |
| 1402 | complain_overflow_dont, /* complain_on_overflow */ |
| 1403 | bfd_elf_generic_reloc, /* special_function */ |
| 1404 | "R_SH_GOTPC_LOW16", /* name */ |
| 1405 | FALSE, /* partial_inplace */ |
| 1406 | 0, /* src_mask */ |
| 1407 | 0x3fffc00, /* dst_mask */ |
| 1408 | TRUE), /* pcrel_offset */ |
| 1409 | |
| 1410 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 1411 | HOWTO (R_SH_GOTPC_MEDLOW16, /* type */ |
| 1412 | 16, /* rightshift */ |
| 1413 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1414 | 64, /* bitsize */ |
| 1415 | TRUE, /* pc_relative */ |
| 1416 | 10, /* bitpos */ |
| 1417 | complain_overflow_dont, /* complain_on_overflow */ |
| 1418 | bfd_elf_generic_reloc, /* special_function */ |
| 1419 | "R_SH_GOTPC_MEDLOW16", /* name */ |
| 1420 | FALSE, /* partial_inplace */ |
| 1421 | 0, /* src_mask */ |
| 1422 | 0x3fffc00, /* dst_mask */ |
| 1423 | TRUE), /* pcrel_offset */ |
| 1424 | |
| 1425 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 1426 | HOWTO (R_SH_GOTPC_MEDHI16, /* type */ |
| 1427 | 32, /* rightshift */ |
| 1428 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1429 | 64, /* bitsize */ |
| 1430 | TRUE, /* pc_relative */ |
| 1431 | 10, /* bitpos */ |
| 1432 | complain_overflow_dont, /* complain_on_overflow */ |
| 1433 | bfd_elf_generic_reloc, /* special_function */ |
| 1434 | "R_SH_GOTPC_MEDHI16", /* name */ |
| 1435 | FALSE, /* partial_inplace */ |
| 1436 | 0, /* src_mask */ |
| 1437 | 0x3fffc00, /* dst_mask */ |
| 1438 | TRUE), /* pcrel_offset */ |
| 1439 | |
| 1440 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 1441 | HOWTO (R_SH_GOTPC_HI16, /* type */ |
| 1442 | 48, /* rightshift */ |
| 1443 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1444 | 64, /* bitsize */ |
| 1445 | TRUE, /* pc_relative */ |
| 1446 | 10, /* bitpos */ |
| 1447 | complain_overflow_dont, /* complain_on_overflow */ |
| 1448 | bfd_elf_generic_reloc, /* special_function */ |
| 1449 | "R_SH_GOTPC_HI16", /* name */ |
| 1450 | FALSE, /* partial_inplace */ |
| 1451 | 0, /* src_mask */ |
| 1452 | 0x3fffc00, /* dst_mask */ |
| 1453 | TRUE), /* pcrel_offset */ |
| 1454 | |
| 1455 | /* Used in LD.L, FLD.S et al. */ |
| 1456 | HOWTO (R_SH_GOT10BY4, /* type */ |
| 1457 | 2, /* rightshift */ |
| 1458 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1459 | 12, /* bitsize */ |
| 1460 | FALSE, /* pc_relative */ |
| 1461 | 10, /* bitpos */ |
| 1462 | complain_overflow_signed, /* complain_on_overflow */ |
| 1463 | bfd_elf_generic_reloc, /* special_function */ |
| 1464 | "R_SH_GOT10BY4", /* name */ |
| 1465 | FALSE, /* partial_inplace */ |
| 1466 | 0, /* src_mask */ |
| 1467 | 0xffc00, /* dst_mask */ |
| 1468 | FALSE), /* pcrel_offset */ |
| 1469 | |
| 1470 | /* Used in LD.L, FLD.S et al. */ |
| 1471 | HOWTO (R_SH_GOTPLT10BY4, /* type */ |
| 1472 | 2, /* rightshift */ |
| 1473 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1474 | 12, /* bitsize */ |
| 1475 | FALSE, /* pc_relative */ |
| 1476 | 10, /* bitpos */ |
| 1477 | complain_overflow_signed, /* complain_on_overflow */ |
| 1478 | bfd_elf_generic_reloc, /* special_function */ |
| 1479 | "R_SH_GOTPLT10BY4", /* name */ |
| 1480 | FALSE, /* partial_inplace */ |
| 1481 | 0, /* src_mask */ |
| 1482 | 0xffc00, /* dst_mask */ |
| 1483 | FALSE), /* pcrel_offset */ |
| 1484 | |
| 1485 | /* Used in FLD.D, FST.P et al. */ |
| 1486 | HOWTO (R_SH_GOT10BY8, /* type */ |
| 1487 | 3, /* rightshift */ |
| 1488 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1489 | 13, /* bitsize */ |
| 1490 | FALSE, /* pc_relative */ |
| 1491 | 10, /* bitpos */ |
| 1492 | complain_overflow_signed, /* complain_on_overflow */ |
| 1493 | bfd_elf_generic_reloc, /* special_function */ |
| 1494 | "R_SH_GOT10BY8", /* name */ |
| 1495 | FALSE, /* partial_inplace */ |
| 1496 | 0, /* src_mask */ |
| 1497 | 0xffc00, /* dst_mask */ |
| 1498 | FALSE), /* pcrel_offset */ |
| 1499 | |
| 1500 | /* Used in FLD.D, FST.P et al. */ |
| 1501 | HOWTO (R_SH_GOTPLT10BY8, /* type */ |
| 1502 | 3, /* rightshift */ |
| 1503 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1504 | 13, /* bitsize */ |
| 1505 | FALSE, /* pc_relative */ |
| 1506 | 10, /* bitpos */ |
| 1507 | complain_overflow_signed, /* complain_on_overflow */ |
| 1508 | bfd_elf_generic_reloc, /* special_function */ |
| 1509 | "R_SH_GOTPLT10BY8", /* name */ |
| 1510 | FALSE, /* partial_inplace */ |
| 1511 | 0, /* src_mask */ |
| 1512 | 0xffc00, /* dst_mask */ |
| 1513 | FALSE), /* pcrel_offset */ |
| 1514 | |
| 1515 | HOWTO (R_SH_COPY64, /* type */ |
| 1516 | 0, /* rightshift */ |
| 1517 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1518 | 64, /* bitsize */ |
| 1519 | FALSE, /* pc_relative */ |
| 1520 | 0, /* bitpos */ |
| 1521 | complain_overflow_dont, /* complain_on_overflow */ |
| 1522 | bfd_elf_generic_reloc, /* special_function */ |
| 1523 | "R_SH_COPY64", /* name */ |
| 1524 | FALSE, /* partial_inplace */ |
| 1525 | 0, /* src_mask */ |
| 1526 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 1527 | FALSE), /* pcrel_offset */ |
| 1528 | |
| 1529 | HOWTO (R_SH_GLOB_DAT64, /* type */ |
| 1530 | 0, /* rightshift */ |
| 1531 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1532 | 64, /* bitsize */ |
| 1533 | FALSE, /* pc_relative */ |
| 1534 | 0, /* bitpos */ |
| 1535 | complain_overflow_dont, /* complain_on_overflow */ |
| 1536 | bfd_elf_generic_reloc, /* special_function */ |
| 1537 | "R_SH_GLOB_DAT64", /* name */ |
| 1538 | FALSE, /* partial_inplace */ |
| 1539 | 0, /* src_mask */ |
| 1540 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 1541 | FALSE), /* pcrel_offset */ |
| 1542 | |
| 1543 | HOWTO (R_SH_JMP_SLOT64, /* type */ |
| 1544 | 0, /* rightshift */ |
| 1545 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1546 | 64, /* bitsize */ |
| 1547 | FALSE, /* pc_relative */ |
| 1548 | 0, /* bitpos */ |
| 1549 | complain_overflow_dont, /* complain_on_overflow */ |
| 1550 | bfd_elf_generic_reloc, /* special_function */ |
| 1551 | "R_SH_JMP_SLOT64", /* name */ |
| 1552 | FALSE, /* partial_inplace */ |
| 1553 | 0, /* src_mask */ |
| 1554 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 1555 | FALSE), /* pcrel_offset */ |
| 1556 | |
| 1557 | HOWTO (R_SH_RELATIVE64, /* type */ |
| 1558 | 0, /* rightshift */ |
| 1559 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1560 | 64, /* bitsize */ |
| 1561 | FALSE, /* pc_relative */ |
| 1562 | 0, /* bitpos */ |
| 1563 | complain_overflow_dont, /* complain_on_overflow */ |
| 1564 | bfd_elf_generic_reloc, /* special_function */ |
| 1565 | "R_SH_RELATIVE64", /* name */ |
| 1566 | FALSE, /* partial_inplace */ |
| 1567 | 0, /* src_mask */ |
| 1568 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 1569 | FALSE), /* pcrel_offset */ |
| 1570 | |
| 1571 | EMPTY_HOWTO (197), |
| 1572 | EMPTY_HOWTO (198), |
| 1573 | EMPTY_HOWTO (199), |
| 1574 | EMPTY_HOWTO (200), |
| 1575 | EMPTY_HOWTO (201), |
| 1576 | EMPTY_HOWTO (202), |
| 1577 | EMPTY_HOWTO (203), |
| 1578 | EMPTY_HOWTO (204), |
| 1579 | EMPTY_HOWTO (205), |
| 1580 | EMPTY_HOWTO (206), |
| 1581 | EMPTY_HOWTO (207), |
| 1582 | EMPTY_HOWTO (208), |
| 1583 | EMPTY_HOWTO (209), |
| 1584 | EMPTY_HOWTO (210), |
| 1585 | EMPTY_HOWTO (211), |
| 1586 | EMPTY_HOWTO (212), |
| 1587 | EMPTY_HOWTO (213), |
| 1588 | EMPTY_HOWTO (214), |
| 1589 | EMPTY_HOWTO (215), |
| 1590 | EMPTY_HOWTO (216), |
| 1591 | EMPTY_HOWTO (217), |
| 1592 | EMPTY_HOWTO (218), |
| 1593 | EMPTY_HOWTO (219), |
| 1594 | EMPTY_HOWTO (220), |
| 1595 | EMPTY_HOWTO (221), |
| 1596 | EMPTY_HOWTO (222), |
| 1597 | EMPTY_HOWTO (223), |
| 1598 | EMPTY_HOWTO (224), |
| 1599 | EMPTY_HOWTO (225), |
| 1600 | EMPTY_HOWTO (226), |
| 1601 | EMPTY_HOWTO (227), |
| 1602 | EMPTY_HOWTO (228), |
| 1603 | EMPTY_HOWTO (229), |
| 1604 | EMPTY_HOWTO (230), |
| 1605 | EMPTY_HOWTO (231), |
| 1606 | EMPTY_HOWTO (232), |
| 1607 | EMPTY_HOWTO (233), |
| 1608 | EMPTY_HOWTO (234), |
| 1609 | EMPTY_HOWTO (235), |
| 1610 | EMPTY_HOWTO (236), |
| 1611 | EMPTY_HOWTO (237), |
| 1612 | EMPTY_HOWTO (238), |
| 1613 | EMPTY_HOWTO (239), |
| 1614 | EMPTY_HOWTO (240), |
| 1615 | EMPTY_HOWTO (241), |
| 1616 | |
| 1617 | /* Relocations for SHmedia code. None of these are partial_inplace or |
| 1618 | use the field being relocated (except R_SH_PT_16). */ |
| 1619 | |
| 1620 | /* The assembler will generate this reloc before a block of SHmedia |
| 1621 | instructions. A section should be processed as assuming it contains |
| 1622 | data, unless this reloc is seen. Note that a block of SHcompact |
| 1623 | instructions are instead preceded by R_SH_CODE. |
| 1624 | This is currently not implemented, but should be used for SHmedia |
| 1625 | linker relaxation. */ |
| 1626 | HOWTO (R_SH_SHMEDIA_CODE, /* type */ |
| 1627 | 0, /* rightshift */ |
| 1628 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1629 | 0, /* bitsize */ |
| 1630 | FALSE, /* pc_relative */ |
| 1631 | 0, /* bitpos */ |
| 1632 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 1633 | sh_elf_ignore_reloc, /* special_function */ |
| 1634 | "R_SH_SHMEDIA_CODE", /* name */ |
| 1635 | FALSE, /* partial_inplace */ |
| 1636 | 0, /* src_mask */ |
| 1637 | 0, /* dst_mask */ |
| 1638 | FALSE), /* pcrel_offset */ |
| 1639 | |
| 1640 | /* The assembler will generate this reloc at a PTA or PTB instruction, |
| 1641 | and the linker checks the right type of target, or changes a PTA to a |
| 1642 | PTB, if the original insn was PT. */ |
| 1643 | HOWTO (R_SH_PT_16, /* type */ |
| 1644 | 2, /* rightshift */ |
| 1645 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1646 | 18, /* bitsize */ |
| 1647 | TRUE, /* pc_relative */ |
| 1648 | 10, /* bitpos */ |
| 1649 | complain_overflow_signed, /* complain_on_overflow */ |
| 1650 | bfd_elf_generic_reloc, /* special_function */ |
| 1651 | "R_SH_PT_16", /* name */ |
| 1652 | FALSE, /* partial_inplace */ |
| 1653 | 0, /* src_mask */ |
| 1654 | 0x3fffc00, /* dst_mask */ |
| 1655 | TRUE), /* pcrel_offset */ |
| 1656 | |
| 1657 | /* Used in unexpanded MOVI. */ |
| 1658 | HOWTO (R_SH_IMMS16, /* type */ |
| 1659 | 0, /* rightshift */ |
| 1660 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1661 | 16, /* bitsize */ |
| 1662 | FALSE, /* pc_relative */ |
| 1663 | 10, /* bitpos */ |
| 1664 | complain_overflow_signed, /* complain_on_overflow */ |
| 1665 | bfd_elf_generic_reloc, /* special_function */ |
| 1666 | "R_SH_IMMS16", /* name */ |
| 1667 | FALSE, /* partial_inplace */ |
| 1668 | 0, /* src_mask */ |
| 1669 | 0x3fffc00, /* dst_mask */ |
| 1670 | FALSE), /* pcrel_offset */ |
| 1671 | |
| 1672 | /* Used in SHORI. */ |
| 1673 | HOWTO (R_SH_IMMU16, /* type */ |
| 1674 | 0, /* rightshift */ |
| 1675 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1676 | 16, /* bitsize */ |
| 1677 | FALSE, /* pc_relative */ |
| 1678 | 10, /* bitpos */ |
| 1679 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 1680 | bfd_elf_generic_reloc, /* special_function */ |
| 1681 | "R_SH_IMMU16", /* name */ |
| 1682 | FALSE, /* partial_inplace */ |
| 1683 | 0, /* src_mask */ |
| 1684 | 0x3fffc00, /* dst_mask */ |
| 1685 | FALSE), /* pcrel_offset */ |
| 1686 | |
| 1687 | /* Used in MOVI and SHORI (x & 65536). */ |
| 1688 | HOWTO (R_SH_IMM_LOW16, /* type */ |
| 1689 | 0, /* rightshift */ |
| 1690 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1691 | 64, /* bitsize */ |
| 1692 | FALSE, /* pc_relative */ |
| 1693 | 10, /* bitpos */ |
| 1694 | complain_overflow_dont, /* complain_on_overflow */ |
| 1695 | bfd_elf_generic_reloc, /* special_function */ |
| 1696 | "R_SH_IMM_LOW16", /* name */ |
| 1697 | FALSE, /* partial_inplace */ |
| 1698 | 0, /* src_mask */ |
| 1699 | 0x3fffc00, /* dst_mask */ |
| 1700 | FALSE), /* pcrel_offset */ |
| 1701 | |
| 1702 | /* Used in MOVI and SHORI ((x - $) & 65536). */ |
| 1703 | HOWTO (R_SH_IMM_LOW16_PCREL, /* type */ |
| 1704 | 0, /* rightshift */ |
| 1705 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1706 | 64, /* bitsize */ |
| 1707 | TRUE, /* pc_relative */ |
| 1708 | 10, /* bitpos */ |
| 1709 | complain_overflow_dont, /* complain_on_overflow */ |
| 1710 | bfd_elf_generic_reloc, /* special_function */ |
| 1711 | "R_SH_IMM_LOW16_PCREL", /* name */ |
| 1712 | FALSE, /* partial_inplace */ |
| 1713 | 0, /* src_mask */ |
| 1714 | 0x3fffc00, /* dst_mask */ |
| 1715 | TRUE), /* pcrel_offset */ |
| 1716 | |
| 1717 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 1718 | HOWTO (R_SH_IMM_MEDLOW16, /* type */ |
| 1719 | 16, /* rightshift */ |
| 1720 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1721 | 64, /* bitsize */ |
| 1722 | FALSE, /* pc_relative */ |
| 1723 | 10, /* bitpos */ |
| 1724 | complain_overflow_dont, /* complain_on_overflow */ |
| 1725 | bfd_elf_generic_reloc, /* special_function */ |
| 1726 | "R_SH_IMM_MEDLOW16", /* name */ |
| 1727 | FALSE, /* partial_inplace */ |
| 1728 | 0, /* src_mask */ |
| 1729 | 0x3fffc00, /* dst_mask */ |
| 1730 | FALSE), /* pcrel_offset */ |
| 1731 | |
| 1732 | /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */ |
| 1733 | HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */ |
| 1734 | 16, /* rightshift */ |
| 1735 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1736 | 64, /* bitsize */ |
| 1737 | TRUE, /* pc_relative */ |
| 1738 | 10, /* bitpos */ |
| 1739 | complain_overflow_dont, /* complain_on_overflow */ |
| 1740 | bfd_elf_generic_reloc, /* special_function */ |
| 1741 | "R_SH_IMM_MEDLOW16_PCREL", /* name */ |
| 1742 | FALSE, /* partial_inplace */ |
| 1743 | 0, /* src_mask */ |
| 1744 | 0x3fffc00, /* dst_mask */ |
| 1745 | TRUE), /* pcrel_offset */ |
| 1746 | |
| 1747 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 1748 | HOWTO (R_SH_IMM_MEDHI16, /* type */ |
| 1749 | 32, /* rightshift */ |
| 1750 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1751 | 64, /* bitsize */ |
| 1752 | FALSE, /* pc_relative */ |
| 1753 | 10, /* bitpos */ |
| 1754 | complain_overflow_dont, /* complain_on_overflow */ |
| 1755 | bfd_elf_generic_reloc, /* special_function */ |
| 1756 | "R_SH_IMM_MEDHI16", /* name */ |
| 1757 | FALSE, /* partial_inplace */ |
| 1758 | 0, /* src_mask */ |
| 1759 | 0x3fffc00, /* dst_mask */ |
| 1760 | FALSE), /* pcrel_offset */ |
| 1761 | |
| 1762 | /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */ |
| 1763 | HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */ |
| 1764 | 32, /* rightshift */ |
| 1765 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1766 | 64, /* bitsize */ |
| 1767 | TRUE, /* pc_relative */ |
| 1768 | 10, /* bitpos */ |
| 1769 | complain_overflow_dont, /* complain_on_overflow */ |
| 1770 | bfd_elf_generic_reloc, /* special_function */ |
| 1771 | "R_SH_IMM_MEDHI16_PCREL", /* name */ |
| 1772 | FALSE, /* partial_inplace */ |
| 1773 | 0, /* src_mask */ |
| 1774 | 0x3fffc00, /* dst_mask */ |
| 1775 | TRUE), /* pcrel_offset */ |
| 1776 | |
| 1777 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 1778 | HOWTO (R_SH_IMM_HI16, /* type */ |
| 1779 | 48, /* rightshift */ |
| 1780 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1781 | 64, /* bitsize */ |
| 1782 | FALSE, /* pc_relative */ |
| 1783 | 10, /* bitpos */ |
| 1784 | complain_overflow_dont, /* complain_on_overflow */ |
| 1785 | bfd_elf_generic_reloc, /* special_function */ |
| 1786 | "R_SH_IMM_HI16", /* name */ |
| 1787 | FALSE, /* partial_inplace */ |
| 1788 | 0, /* src_mask */ |
| 1789 | 0x3fffc00, /* dst_mask */ |
| 1790 | FALSE), /* pcrel_offset */ |
| 1791 | |
| 1792 | /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */ |
| 1793 | HOWTO (R_SH_IMM_HI16_PCREL, /* type */ |
| 1794 | 48, /* rightshift */ |
| 1795 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1796 | 64, /* bitsize */ |
| 1797 | TRUE, /* pc_relative */ |
| 1798 | 10, /* bitpos */ |
| 1799 | complain_overflow_dont, /* complain_on_overflow */ |
| 1800 | bfd_elf_generic_reloc, /* special_function */ |
| 1801 | "R_SH_IMM_HI16_PCREL", /* name */ |
| 1802 | FALSE, /* partial_inplace */ |
| 1803 | 0, /* src_mask */ |
| 1804 | 0x3fffc00, /* dst_mask */ |
| 1805 | TRUE), /* pcrel_offset */ |
| 1806 | |
| 1807 | /* For the .uaquad pseudo. */ |
| 1808 | HOWTO (R_SH_64, /* type */ |
| 1809 | 0, /* rightshift */ |
| 1810 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1811 | 64, /* bitsize */ |
| 1812 | FALSE, /* pc_relative */ |
| 1813 | 0, /* bitpos */ |
| 1814 | complain_overflow_dont, /* complain_on_overflow */ |
| 1815 | bfd_elf_generic_reloc, /* special_function */ |
| 1816 | "R_SH_64", /* name */ |
| 1817 | FALSE, /* partial_inplace */ |
| 1818 | 0, /* src_mask */ |
| 1819 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 1820 | FALSE), /* pcrel_offset */ |
| 1821 | |
| 1822 | /* For the .uaquad pseudo, (x - $). */ |
| 1823 | HOWTO (R_SH_64_PCREL, /* type */ |
| 1824 | 48, /* rightshift */ |
| 1825 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1826 | 64, /* bitsize */ |
| 1827 | TRUE, /* pc_relative */ |
| 1828 | 10, /* bitpos */ |
| 1829 | complain_overflow_dont, /* complain_on_overflow */ |
| 1830 | bfd_elf_generic_reloc, /* special_function */ |
| 1831 | "R_SH_64_PCREL", /* name */ |
| 1832 | FALSE, /* partial_inplace */ |
| 1833 | 0, /* src_mask */ |
| 1834 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 1835 | TRUE), /* pcrel_offset */ |
| 1836 | |
| 1837 | #endif |
| 1838 | }; |
| 1839 | |
| 1840 | static bfd_reloc_status_type |
| 1841 | sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd, |
| 1842 | asection *input_section, bfd_byte *contents, |
| 1843 | bfd_vma addr, asection *symbol_section, |
| 1844 | bfd_vma start, bfd_vma end) |
| 1845 | { |
| 1846 | static bfd_vma last_addr; |
| 1847 | static asection *last_symbol_section; |
| 1848 | bfd_byte *start_ptr, *ptr, *last_ptr; |
| 1849 | int diff, cum_diff; |
| 1850 | bfd_signed_vma x; |
| 1851 | int insn; |
| 1852 | |
| 1853 | /* Sanity check the address. */ |
| 1854 | if (addr > bfd_get_section_limit (input_bfd, input_section)) |
| 1855 | return bfd_reloc_outofrange; |
| 1856 | |
| 1857 | /* We require the start and end relocations to be processed consecutively - |
| 1858 | although we allow then to be processed forwards or backwards. */ |
| 1859 | if (! last_addr) |
| 1860 | { |
| 1861 | last_addr = addr; |
| 1862 | last_symbol_section = symbol_section; |
| 1863 | return bfd_reloc_ok; |
| 1864 | } |
| 1865 | if (last_addr != addr) |
| 1866 | abort (); |
| 1867 | last_addr = 0; |
| 1868 | |
| 1869 | if (! symbol_section || last_symbol_section != symbol_section || end < start) |
| 1870 | return bfd_reloc_outofrange; |
| 1871 | |
| 1872 | /* Get the symbol_section contents. */ |
| 1873 | if (symbol_section != input_section) |
| 1874 | { |
| 1875 | if (elf_section_data (symbol_section)->this_hdr.contents != NULL) |
| 1876 | contents = elf_section_data (symbol_section)->this_hdr.contents; |
| 1877 | else |
| 1878 | { |
| 1879 | if (!bfd_malloc_and_get_section (input_bfd, symbol_section, |
| 1880 | &contents)) |
| 1881 | { |
| 1882 | if (contents != NULL) |
| 1883 | free (contents); |
| 1884 | return bfd_reloc_outofrange; |
| 1885 | } |
| 1886 | } |
| 1887 | } |
| 1888 | #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800) |
| 1889 | start_ptr = contents + start; |
| 1890 | for (cum_diff = -6, ptr = contents + end; cum_diff < 0 && ptr > start_ptr;) |
| 1891 | { |
| 1892 | for (last_ptr = ptr, ptr -= 4; ptr >= start_ptr && IS_PPI (ptr);) |
| 1893 | ptr -= 2; |
| 1894 | ptr += 2; |
| 1895 | diff = (last_ptr - ptr) >> 1; |
| 1896 | cum_diff += diff & 1; |
| 1897 | cum_diff += diff; |
| 1898 | } |
| 1899 | /* Calculate the start / end values to load into rs / re minus four - |
| 1900 | so that will cancel out the four we would otherwise have to add to |
| 1901 | addr to get the value to subtract in order to get relative addressing. */ |
| 1902 | if (cum_diff >= 0) |
| 1903 | { |
| 1904 | start -= 4; |
| 1905 | end = (ptr + cum_diff * 2) - contents; |
| 1906 | } |
| 1907 | else |
| 1908 | { |
| 1909 | bfd_vma start0 = start - 4; |
| 1910 | |
| 1911 | while (start0 && IS_PPI (contents + start0)) |
| 1912 | start0 -= 2; |
| 1913 | start0 = start - 2 - ((start - start0) & 2); |
| 1914 | start = start0 - cum_diff - 2; |
| 1915 | end = start0; |
| 1916 | } |
| 1917 | |
| 1918 | if (contents != NULL |
| 1919 | && elf_section_data (symbol_section)->this_hdr.contents != contents) |
| 1920 | free (contents); |
| 1921 | |
| 1922 | insn = bfd_get_16 (input_bfd, contents + addr); |
| 1923 | |
| 1924 | x = (insn & 0x200 ? end : start) - addr; |
| 1925 | if (input_section != symbol_section) |
| 1926 | x += ((symbol_section->output_section->vma + symbol_section->output_offset) |
| 1927 | - (input_section->output_section->vma |
| 1928 | + input_section->output_offset)); |
| 1929 | x >>= 1; |
| 1930 | if (x < -128 || x > 127) |
| 1931 | return bfd_reloc_overflow; |
| 1932 | |
| 1933 | x = (insn & ~0xff) | (x & 0xff); |
| 1934 | bfd_put_16 (input_bfd, (bfd_vma) x, contents + addr); |
| 1935 | |
| 1936 | return bfd_reloc_ok; |
| 1937 | } |
| 1938 | |
| 1939 | /* This function is used for normal relocs. This used to be like the COFF |
| 1940 | function, and is almost certainly incorrect for other ELF targets. */ |
| 1941 | |
| 1942 | static bfd_reloc_status_type |
| 1943 | sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in, |
| 1944 | void *data, asection *input_section, bfd *output_bfd, |
| 1945 | char **error_message ATTRIBUTE_UNUSED) |
| 1946 | { |
| 1947 | unsigned long insn; |
| 1948 | bfd_vma sym_value; |
| 1949 | enum elf_sh_reloc_type r_type; |
| 1950 | bfd_vma addr = reloc_entry->address; |
| 1951 | bfd_byte *hit_data = addr + (bfd_byte *) data; |
| 1952 | |
| 1953 | r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type; |
| 1954 | |
| 1955 | if (output_bfd != NULL) |
| 1956 | { |
| 1957 | /* Partial linking--do nothing. */ |
| 1958 | reloc_entry->address += input_section->output_offset; |
| 1959 | return bfd_reloc_ok; |
| 1960 | } |
| 1961 | |
| 1962 | /* Almost all relocs have to do with relaxing. If any work must be |
| 1963 | done for them, it has been done in sh_relax_section. */ |
| 1964 | if (r_type == R_SH_IND12W && (symbol_in->flags & BSF_LOCAL) != 0) |
| 1965 | return bfd_reloc_ok; |
| 1966 | |
| 1967 | if (symbol_in != NULL |
| 1968 | && bfd_is_und_section (symbol_in->section)) |
| 1969 | return bfd_reloc_undefined; |
| 1970 | |
| 1971 | if (bfd_is_com_section (symbol_in->section)) |
| 1972 | sym_value = 0; |
| 1973 | else |
| 1974 | sym_value = (symbol_in->value + |
| 1975 | symbol_in->section->output_section->vma + |
| 1976 | symbol_in->section->output_offset); |
| 1977 | |
| 1978 | switch (r_type) |
| 1979 | { |
| 1980 | case R_SH_DIR32: |
| 1981 | insn = bfd_get_32 (abfd, hit_data); |
| 1982 | insn += sym_value + reloc_entry->addend; |
| 1983 | bfd_put_32 (abfd, (bfd_vma) insn, hit_data); |
| 1984 | break; |
| 1985 | case R_SH_IND12W: |
| 1986 | insn = bfd_get_16 (abfd, hit_data); |
| 1987 | sym_value += reloc_entry->addend; |
| 1988 | sym_value -= (input_section->output_section->vma |
| 1989 | + input_section->output_offset |
| 1990 | + addr |
| 1991 | + 4); |
| 1992 | sym_value += (insn & 0xfff) << 1; |
| 1993 | if (insn & 0x800) |
| 1994 | sym_value -= 0x1000; |
| 1995 | insn = (insn & 0xf000) | (sym_value & 0xfff); |
| 1996 | bfd_put_16 (abfd, (bfd_vma) insn, hit_data); |
| 1997 | if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000) |
| 1998 | return bfd_reloc_overflow; |
| 1999 | break; |
| 2000 | default: |
| 2001 | abort (); |
| 2002 | break; |
| 2003 | } |
| 2004 | |
| 2005 | return bfd_reloc_ok; |
| 2006 | } |
| 2007 | |
| 2008 | /* This function is used for relocs which are only used for relaxing, |
| 2009 | which the linker should otherwise ignore. */ |
| 2010 | |
| 2011 | static bfd_reloc_status_type |
| 2012 | sh_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry, |
| 2013 | asymbol *symbol ATTRIBUTE_UNUSED, |
| 2014 | void *data ATTRIBUTE_UNUSED, asection *input_section, |
| 2015 | bfd *output_bfd, |
| 2016 | char **error_message ATTRIBUTE_UNUSED) |
| 2017 | { |
| 2018 | if (output_bfd != NULL) |
| 2019 | reloc_entry->address += input_section->output_offset; |
| 2020 | return bfd_reloc_ok; |
| 2021 | } |
| 2022 | |
| 2023 | /* This structure is used to map BFD reloc codes to SH ELF relocs. */ |
| 2024 | |
| 2025 | struct elf_reloc_map |
| 2026 | { |
| 2027 | bfd_reloc_code_real_type bfd_reloc_val; |
| 2028 | unsigned char elf_reloc_val; |
| 2029 | }; |
| 2030 | |
| 2031 | /* An array mapping BFD reloc codes to SH ELF relocs. */ |
| 2032 | |
| 2033 | static const struct elf_reloc_map sh_reloc_map[] = |
| 2034 | { |
| 2035 | { BFD_RELOC_NONE, R_SH_NONE }, |
| 2036 | { BFD_RELOC_32, R_SH_DIR32 }, |
| 2037 | { BFD_RELOC_16, R_SH_DIR16 }, |
| 2038 | { BFD_RELOC_8, R_SH_DIR8 }, |
| 2039 | { BFD_RELOC_CTOR, R_SH_DIR32 }, |
| 2040 | { BFD_RELOC_32_PCREL, R_SH_REL32 }, |
| 2041 | { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN }, |
| 2042 | { BFD_RELOC_SH_PCDISP12BY2, R_SH_IND12W }, |
| 2043 | { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_DIR8WPZ }, |
| 2044 | { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_DIR8WPL }, |
| 2045 | { BFD_RELOC_8_PCREL, R_SH_SWITCH8 }, |
| 2046 | { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 }, |
| 2047 | { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 }, |
| 2048 | { BFD_RELOC_SH_USES, R_SH_USES }, |
| 2049 | { BFD_RELOC_SH_COUNT, R_SH_COUNT }, |
| 2050 | { BFD_RELOC_SH_ALIGN, R_SH_ALIGN }, |
| 2051 | { BFD_RELOC_SH_CODE, R_SH_CODE }, |
| 2052 | { BFD_RELOC_SH_DATA, R_SH_DATA }, |
| 2053 | { BFD_RELOC_SH_LABEL, R_SH_LABEL }, |
| 2054 | { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT }, |
| 2055 | { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY }, |
| 2056 | { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START }, |
| 2057 | { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END }, |
| 2058 | { BFD_RELOC_SH_TLS_GD_32, R_SH_TLS_GD_32 }, |
| 2059 | { BFD_RELOC_SH_TLS_LD_32, R_SH_TLS_LD_32 }, |
| 2060 | { BFD_RELOC_SH_TLS_LDO_32, R_SH_TLS_LDO_32 }, |
| 2061 | { BFD_RELOC_SH_TLS_IE_32, R_SH_TLS_IE_32 }, |
| 2062 | { BFD_RELOC_SH_TLS_LE_32, R_SH_TLS_LE_32 }, |
| 2063 | { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 }, |
| 2064 | { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 }, |
| 2065 | { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 }, |
| 2066 | { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 }, |
| 2067 | { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 }, |
| 2068 | { BFD_RELOC_SH_COPY, R_SH_COPY }, |
| 2069 | { BFD_RELOC_SH_GLOB_DAT, R_SH_GLOB_DAT }, |
| 2070 | { BFD_RELOC_SH_JMP_SLOT, R_SH_JMP_SLOT }, |
| 2071 | { BFD_RELOC_SH_RELATIVE, R_SH_RELATIVE }, |
| 2072 | { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF }, |
| 2073 | { BFD_RELOC_SH_GOTPC, R_SH_GOTPC }, |
| 2074 | { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 }, |
| 2075 | #ifdef INCLUDE_SHMEDIA |
| 2076 | { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 }, |
| 2077 | { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 }, |
| 2078 | { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 }, |
| 2079 | { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 }, |
| 2080 | { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 }, |
| 2081 | { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 }, |
| 2082 | { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 }, |
| 2083 | { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 }, |
| 2084 | { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 }, |
| 2085 | { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 }, |
| 2086 | { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 }, |
| 2087 | { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 }, |
| 2088 | { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 }, |
| 2089 | { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 }, |
| 2090 | { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 }, |
| 2091 | { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 }, |
| 2092 | { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 }, |
| 2093 | { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 }, |
| 2094 | { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 }, |
| 2095 | { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 }, |
| 2096 | { BFD_RELOC_SH_COPY64, R_SH_COPY64 }, |
| 2097 | { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 }, |
| 2098 | { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 }, |
| 2099 | { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 }, |
| 2100 | { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 }, |
| 2101 | { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 }, |
| 2102 | { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 }, |
| 2103 | { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 }, |
| 2104 | { BFD_RELOC_SH_PT_16, R_SH_PT_16 }, |
| 2105 | { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE }, |
| 2106 | { BFD_RELOC_SH_IMMU5, R_SH_DIR5U }, |
| 2107 | { BFD_RELOC_SH_IMMS6, R_SH_DIR6S }, |
| 2108 | { BFD_RELOC_SH_IMMU6, R_SH_DIR6U }, |
| 2109 | { BFD_RELOC_SH_IMMS10, R_SH_DIR10S }, |
| 2110 | { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW }, |
| 2111 | { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL }, |
| 2112 | { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ }, |
| 2113 | { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 }, |
| 2114 | { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 }, |
| 2115 | { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 }, |
| 2116 | { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL }, |
| 2117 | { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 }, |
| 2118 | { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL }, |
| 2119 | { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 }, |
| 2120 | { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL }, |
| 2121 | { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 }, |
| 2122 | { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL }, |
| 2123 | { BFD_RELOC_64, R_SH_64 }, |
| 2124 | { BFD_RELOC_64_PCREL, R_SH_64_PCREL }, |
| 2125 | #endif /* not INCLUDE_SHMEDIA */ |
| 2126 | }; |
| 2127 | |
| 2128 | /* Given a BFD reloc code, return the howto structure for the |
| 2129 | corresponding SH ELf reloc. */ |
| 2130 | |
| 2131 | static reloc_howto_type * |
| 2132 | sh_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
| 2133 | bfd_reloc_code_real_type code) |
| 2134 | { |
| 2135 | unsigned int i; |
| 2136 | |
| 2137 | for (i = 0; i < sizeof (sh_reloc_map) / sizeof (struct elf_reloc_map); i++) |
| 2138 | { |
| 2139 | if (sh_reloc_map[i].bfd_reloc_val == code) |
| 2140 | return &sh_elf_howto_table[(int) sh_reloc_map[i].elf_reloc_val]; |
| 2141 | } |
| 2142 | |
| 2143 | return NULL; |
| 2144 | } |
| 2145 | |
| 2146 | /* Given an ELF reloc, fill in the howto field of a relent. */ |
| 2147 | |
| 2148 | static void |
| 2149 | sh_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, |
| 2150 | Elf_Internal_Rela *dst) |
| 2151 | { |
| 2152 | unsigned int r; |
| 2153 | |
| 2154 | r = ELF32_R_TYPE (dst->r_info); |
| 2155 | |
| 2156 | BFD_ASSERT (r < (unsigned int) R_SH_max); |
| 2157 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC); |
| 2158 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2); |
| 2159 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3); |
| 2160 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4); |
| 2161 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_5 || r > R_SH_LAST_INVALID_RELOC_5); |
| 2162 | |
| 2163 | cache_ptr->howto = &sh_elf_howto_table[r]; |
| 2164 | } |
| 2165 | \f |
| 2166 | /* This function handles relaxing for SH ELF. See the corresponding |
| 2167 | function in coff-sh.c for a description of what this does. FIXME: |
| 2168 | There is a lot of duplication here between this code and the COFF |
| 2169 | specific code. The format of relocs and symbols is wound deeply |
| 2170 | into this code, but it would still be better if the duplication |
| 2171 | could be eliminated somehow. Note in particular that although both |
| 2172 | functions use symbols like R_SH_CODE, those symbols have different |
| 2173 | values; in coff-sh.c they come from include/coff/sh.h, whereas here |
| 2174 | they come from enum elf_sh_reloc_type in include/elf/sh.h. */ |
| 2175 | |
| 2176 | static bfd_boolean |
| 2177 | sh_elf_relax_section (bfd *abfd, asection *sec, |
| 2178 | struct bfd_link_info *link_info, bfd_boolean *again) |
| 2179 | { |
| 2180 | Elf_Internal_Shdr *symtab_hdr; |
| 2181 | Elf_Internal_Rela *internal_relocs; |
| 2182 | bfd_boolean have_code; |
| 2183 | Elf_Internal_Rela *irel, *irelend; |
| 2184 | bfd_byte *contents = NULL; |
| 2185 | Elf_Internal_Sym *isymbuf = NULL; |
| 2186 | |
| 2187 | *again = FALSE; |
| 2188 | |
| 2189 | if (link_info->relocatable |
| 2190 | || (sec->flags & SEC_RELOC) == 0 |
| 2191 | || sec->reloc_count == 0) |
| 2192 | return TRUE; |
| 2193 | |
| 2194 | #ifdef INCLUDE_SHMEDIA |
| 2195 | if (elf_section_data (sec)->this_hdr.sh_flags |
| 2196 | & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED)) |
| 2197 | { |
| 2198 | return TRUE; |
| 2199 | } |
| 2200 | #endif |
| 2201 | |
| 2202 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 2203 | |
| 2204 | internal_relocs = (_bfd_elf_link_read_relocs |
| 2205 | (abfd, sec, NULL, (Elf_Internal_Rela *) NULL, |
| 2206 | link_info->keep_memory)); |
| 2207 | if (internal_relocs == NULL) |
| 2208 | goto error_return; |
| 2209 | |
| 2210 | have_code = FALSE; |
| 2211 | |
| 2212 | irelend = internal_relocs + sec->reloc_count; |
| 2213 | for (irel = internal_relocs; irel < irelend; irel++) |
| 2214 | { |
| 2215 | bfd_vma laddr, paddr, symval; |
| 2216 | unsigned short insn; |
| 2217 | Elf_Internal_Rela *irelfn, *irelscan, *irelcount; |
| 2218 | bfd_signed_vma foff; |
| 2219 | |
| 2220 | if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE) |
| 2221 | have_code = TRUE; |
| 2222 | |
| 2223 | if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES) |
| 2224 | continue; |
| 2225 | |
| 2226 | /* Get the section contents. */ |
| 2227 | if (contents == NULL) |
| 2228 | { |
| 2229 | if (elf_section_data (sec)->this_hdr.contents != NULL) |
| 2230 | contents = elf_section_data (sec)->this_hdr.contents; |
| 2231 | else |
| 2232 | { |
| 2233 | if (!bfd_malloc_and_get_section (abfd, sec, &contents)) |
| 2234 | goto error_return; |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | /* The r_addend field of the R_SH_USES reloc will point us to |
| 2239 | the register load. The 4 is because the r_addend field is |
| 2240 | computed as though it were a jump offset, which are based |
| 2241 | from 4 bytes after the jump instruction. */ |
| 2242 | laddr = irel->r_offset + 4 + irel->r_addend; |
| 2243 | if (laddr >= sec->size) |
| 2244 | { |
| 2245 | (*_bfd_error_handler) (_("%B: 0x%lx: warning: bad R_SH_USES offset"), |
| 2246 | abfd, |
| 2247 | (unsigned long) irel->r_offset); |
| 2248 | continue; |
| 2249 | } |
| 2250 | insn = bfd_get_16 (abfd, contents + laddr); |
| 2251 | |
| 2252 | /* If the instruction is not mov.l NN,rN, we don't know what to |
| 2253 | do. */ |
| 2254 | if ((insn & 0xf000) != 0xd000) |
| 2255 | { |
| 2256 | ((*_bfd_error_handler) |
| 2257 | (_("%B: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"), |
| 2258 | abfd, (unsigned long) irel->r_offset, insn)); |
| 2259 | continue; |
| 2260 | } |
| 2261 | |
| 2262 | /* Get the address from which the register is being loaded. The |
| 2263 | displacement in the mov.l instruction is quadrupled. It is a |
| 2264 | displacement from four bytes after the movl instruction, but, |
| 2265 | before adding in the PC address, two least significant bits |
| 2266 | of the PC are cleared. We assume that the section is aligned |
| 2267 | on a four byte boundary. */ |
| 2268 | paddr = insn & 0xff; |
| 2269 | paddr *= 4; |
| 2270 | paddr += (laddr + 4) &~ (bfd_vma) 3; |
| 2271 | if (paddr >= sec->size) |
| 2272 | { |
| 2273 | ((*_bfd_error_handler) |
| 2274 | (_("%B: 0x%lx: warning: bad R_SH_USES load offset"), |
| 2275 | abfd, (unsigned long) irel->r_offset)); |
| 2276 | continue; |
| 2277 | } |
| 2278 | |
| 2279 | /* Get the reloc for the address from which the register is |
| 2280 | being loaded. This reloc will tell us which function is |
| 2281 | actually being called. */ |
| 2282 | for (irelfn = internal_relocs; irelfn < irelend; irelfn++) |
| 2283 | if (irelfn->r_offset == paddr |
| 2284 | && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32) |
| 2285 | break; |
| 2286 | if (irelfn >= irelend) |
| 2287 | { |
| 2288 | ((*_bfd_error_handler) |
| 2289 | (_("%B: 0x%lx: warning: could not find expected reloc"), |
| 2290 | abfd, (unsigned long) paddr)); |
| 2291 | continue; |
| 2292 | } |
| 2293 | |
| 2294 | /* Read this BFD's symbols if we haven't done so already. */ |
| 2295 | if (isymbuf == NULL && symtab_hdr->sh_info != 0) |
| 2296 | { |
| 2297 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; |
| 2298 | if (isymbuf == NULL) |
| 2299 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, |
| 2300 | symtab_hdr->sh_info, 0, |
| 2301 | NULL, NULL, NULL); |
| 2302 | if (isymbuf == NULL) |
| 2303 | goto error_return; |
| 2304 | } |
| 2305 | |
| 2306 | /* Get the value of the symbol referred to by the reloc. */ |
| 2307 | if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info) |
| 2308 | { |
| 2309 | /* A local symbol. */ |
| 2310 | Elf_Internal_Sym *isym; |
| 2311 | |
| 2312 | isym = isymbuf + ELF32_R_SYM (irelfn->r_info); |
| 2313 | if (isym->st_shndx |
| 2314 | != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec)) |
| 2315 | { |
| 2316 | ((*_bfd_error_handler) |
| 2317 | (_("%B: 0x%lx: warning: symbol in unexpected section"), |
| 2318 | abfd, (unsigned long) paddr)); |
| 2319 | continue; |
| 2320 | } |
| 2321 | |
| 2322 | symval = (isym->st_value |
| 2323 | + sec->output_section->vma |
| 2324 | + sec->output_offset); |
| 2325 | } |
| 2326 | else |
| 2327 | { |
| 2328 | unsigned long indx; |
| 2329 | struct elf_link_hash_entry *h; |
| 2330 | |
| 2331 | indx = ELF32_R_SYM (irelfn->r_info) - symtab_hdr->sh_info; |
| 2332 | h = elf_sym_hashes (abfd)[indx]; |
| 2333 | BFD_ASSERT (h != NULL); |
| 2334 | if (h->root.type != bfd_link_hash_defined |
| 2335 | && h->root.type != bfd_link_hash_defweak) |
| 2336 | { |
| 2337 | /* This appears to be a reference to an undefined |
| 2338 | symbol. Just ignore it--it will be caught by the |
| 2339 | regular reloc processing. */ |
| 2340 | continue; |
| 2341 | } |
| 2342 | |
| 2343 | symval = (h->root.u.def.value |
| 2344 | + h->root.u.def.section->output_section->vma |
| 2345 | + h->root.u.def.section->output_offset); |
| 2346 | } |
| 2347 | |
| 2348 | symval += bfd_get_32 (abfd, contents + paddr); |
| 2349 | |
| 2350 | /* See if this function call can be shortened. */ |
| 2351 | foff = (symval |
| 2352 | - (irel->r_offset |
| 2353 | + sec->output_section->vma |
| 2354 | + sec->output_offset |
| 2355 | + 4)); |
| 2356 | if (foff < -0x1000 || foff >= 0x1000) |
| 2357 | { |
| 2358 | /* After all that work, we can't shorten this function call. */ |
| 2359 | continue; |
| 2360 | } |
| 2361 | |
| 2362 | /* Shorten the function call. */ |
| 2363 | |
| 2364 | /* For simplicity of coding, we are going to modify the section |
| 2365 | contents, the section relocs, and the BFD symbol table. We |
| 2366 | must tell the rest of the code not to free up this |
| 2367 | information. It would be possible to instead create a table |
| 2368 | of changes which have to be made, as is done in coff-mips.c; |
| 2369 | that would be more work, but would require less memory when |
| 2370 | the linker is run. */ |
| 2371 | |
| 2372 | elf_section_data (sec)->relocs = internal_relocs; |
| 2373 | elf_section_data (sec)->this_hdr.contents = contents; |
| 2374 | symtab_hdr->contents = (unsigned char *) isymbuf; |
| 2375 | |
| 2376 | /* Replace the jsr with a bsr. */ |
| 2377 | |
| 2378 | /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and |
| 2379 | replace the jsr with a bsr. */ |
| 2380 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W); |
| 2381 | /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info) |
| 2382 | here, but that only checks if the symbol is an external symbol, |
| 2383 | not if the symbol is in a different section. Besides, we need |
| 2384 | a consistent meaning for the relocation, so we just assume here that |
| 2385 | the value of the symbol is not available. */ |
| 2386 | #if 0 |
| 2387 | if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info) |
| 2388 | { |
| 2389 | /* If this needs to be changed because of future relaxing, |
| 2390 | it will be handled here like other internal IND12W |
| 2391 | relocs. */ |
| 2392 | bfd_put_16 (abfd, |
| 2393 | (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff), |
| 2394 | contents + irel->r_offset); |
| 2395 | } |
| 2396 | else |
| 2397 | #endif |
| 2398 | { |
| 2399 | /* We can't fully resolve this yet, because the external |
| 2400 | symbol value may be changed by future relaxing. We let |
| 2401 | the final link phase handle it. */ |
| 2402 | bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset); |
| 2403 | } |
| 2404 | irel->r_addend = -4; |
| 2405 | |
| 2406 | /* See if there is another R_SH_USES reloc referring to the same |
| 2407 | register load. */ |
| 2408 | for (irelscan = internal_relocs; irelscan < irelend; irelscan++) |
| 2409 | if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES |
| 2410 | && laddr == irelscan->r_offset + 4 + irelscan->r_addend) |
| 2411 | break; |
| 2412 | if (irelscan < irelend) |
| 2413 | { |
| 2414 | /* Some other function call depends upon this register load, |
| 2415 | and we have not yet converted that function call. |
| 2416 | Indeed, we may never be able to convert it. There is |
| 2417 | nothing else we can do at this point. */ |
| 2418 | continue; |
| 2419 | } |
| 2420 | |
| 2421 | /* Look for a R_SH_COUNT reloc on the location where the |
| 2422 | function address is stored. Do this before deleting any |
| 2423 | bytes, to avoid confusion about the address. */ |
| 2424 | for (irelcount = internal_relocs; irelcount < irelend; irelcount++) |
| 2425 | if (irelcount->r_offset == paddr |
| 2426 | && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT) |
| 2427 | break; |
| 2428 | |
| 2429 | /* Delete the register load. */ |
| 2430 | if (! sh_elf_relax_delete_bytes (abfd, sec, laddr, 2)) |
| 2431 | goto error_return; |
| 2432 | |
| 2433 | /* That will change things, so, just in case it permits some |
| 2434 | other function call to come within range, we should relax |
| 2435 | again. Note that this is not required, and it may be slow. */ |
| 2436 | *again = TRUE; |
| 2437 | |
| 2438 | /* Now check whether we got a COUNT reloc. */ |
| 2439 | if (irelcount >= irelend) |
| 2440 | { |
| 2441 | ((*_bfd_error_handler) |
| 2442 | (_("%B: 0x%lx: warning: could not find expected COUNT reloc"), |
| 2443 | abfd, (unsigned long) paddr)); |
| 2444 | continue; |
| 2445 | } |
| 2446 | |
| 2447 | /* The number of uses is stored in the r_addend field. We've |
| 2448 | just deleted one. */ |
| 2449 | if (irelcount->r_addend == 0) |
| 2450 | { |
| 2451 | ((*_bfd_error_handler) (_("%B: 0x%lx: warning: bad count"), |
| 2452 | abfd, |
| 2453 | (unsigned long) paddr)); |
| 2454 | continue; |
| 2455 | } |
| 2456 | |
| 2457 | --irelcount->r_addend; |
| 2458 | |
| 2459 | /* If there are no more uses, we can delete the address. Reload |
| 2460 | the address from irelfn, in case it was changed by the |
| 2461 | previous call to sh_elf_relax_delete_bytes. */ |
| 2462 | if (irelcount->r_addend == 0) |
| 2463 | { |
| 2464 | if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4)) |
| 2465 | goto error_return; |
| 2466 | } |
| 2467 | |
| 2468 | /* We've done all we can with that function call. */ |
| 2469 | } |
| 2470 | |
| 2471 | /* Look for load and store instructions that we can align on four |
| 2472 | byte boundaries. */ |
| 2473 | if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4 |
| 2474 | && have_code) |
| 2475 | { |
| 2476 | bfd_boolean swapped; |
| 2477 | |
| 2478 | /* Get the section contents. */ |
| 2479 | if (contents == NULL) |
| 2480 | { |
| 2481 | if (elf_section_data (sec)->this_hdr.contents != NULL) |
| 2482 | contents = elf_section_data (sec)->this_hdr.contents; |
| 2483 | else |
| 2484 | { |
| 2485 | if (!bfd_malloc_and_get_section (abfd, sec, &contents)) |
| 2486 | goto error_return; |
| 2487 | } |
| 2488 | } |
| 2489 | |
| 2490 | if (! sh_elf_align_loads (abfd, sec, internal_relocs, contents, |
| 2491 | &swapped)) |
| 2492 | goto error_return; |
| 2493 | |
| 2494 | if (swapped) |
| 2495 | { |
| 2496 | elf_section_data (sec)->relocs = internal_relocs; |
| 2497 | elf_section_data (sec)->this_hdr.contents = contents; |
| 2498 | symtab_hdr->contents = (unsigned char *) isymbuf; |
| 2499 | } |
| 2500 | } |
| 2501 | |
| 2502 | if (isymbuf != NULL |
| 2503 | && symtab_hdr->contents != (unsigned char *) isymbuf) |
| 2504 | { |
| 2505 | if (! link_info->keep_memory) |
| 2506 | free (isymbuf); |
| 2507 | else |
| 2508 | { |
| 2509 | /* Cache the symbols for elf_link_input_bfd. */ |
| 2510 | symtab_hdr->contents = (unsigned char *) isymbuf; |
| 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | if (contents != NULL |
| 2515 | && elf_section_data (sec)->this_hdr.contents != contents) |
| 2516 | { |
| 2517 | if (! link_info->keep_memory) |
| 2518 | free (contents); |
| 2519 | else |
| 2520 | { |
| 2521 | /* Cache the section contents for elf_link_input_bfd. */ |
| 2522 | elf_section_data (sec)->this_hdr.contents = contents; |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | if (internal_relocs != NULL |
| 2527 | && elf_section_data (sec)->relocs != internal_relocs) |
| 2528 | free (internal_relocs); |
| 2529 | |
| 2530 | return TRUE; |
| 2531 | |
| 2532 | error_return: |
| 2533 | if (isymbuf != NULL |
| 2534 | && symtab_hdr->contents != (unsigned char *) isymbuf) |
| 2535 | free (isymbuf); |
| 2536 | if (contents != NULL |
| 2537 | && elf_section_data (sec)->this_hdr.contents != contents) |
| 2538 | free (contents); |
| 2539 | if (internal_relocs != NULL |
| 2540 | && elf_section_data (sec)->relocs != internal_relocs) |
| 2541 | free (internal_relocs); |
| 2542 | |
| 2543 | return FALSE; |
| 2544 | } |
| 2545 | |
| 2546 | /* Delete some bytes from a section while relaxing. FIXME: There is a |
| 2547 | lot of duplication between this function and sh_relax_delete_bytes |
| 2548 | in coff-sh.c. */ |
| 2549 | |
| 2550 | static bfd_boolean |
| 2551 | sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr, |
| 2552 | int count) |
| 2553 | { |
| 2554 | Elf_Internal_Shdr *symtab_hdr; |
| 2555 | unsigned int sec_shndx; |
| 2556 | bfd_byte *contents; |
| 2557 | Elf_Internal_Rela *irel, *irelend; |
| 2558 | Elf_Internal_Rela *irelalign; |
| 2559 | bfd_vma toaddr; |
| 2560 | Elf_Internal_Sym *isymbuf, *isym, *isymend; |
| 2561 | struct elf_link_hash_entry **sym_hashes; |
| 2562 | struct elf_link_hash_entry **end_hashes; |
| 2563 | unsigned int symcount; |
| 2564 | asection *o; |
| 2565 | |
| 2566 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 2567 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; |
| 2568 | |
| 2569 | sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec); |
| 2570 | |
| 2571 | contents = elf_section_data (sec)->this_hdr.contents; |
| 2572 | |
| 2573 | /* The deletion must stop at the next ALIGN reloc for an aligment |
| 2574 | power larger than the number of bytes we are deleting. */ |
| 2575 | |
| 2576 | irelalign = NULL; |
| 2577 | toaddr = sec->size; |
| 2578 | |
| 2579 | irel = elf_section_data (sec)->relocs; |
| 2580 | irelend = irel + sec->reloc_count; |
| 2581 | for (; irel < irelend; irel++) |
| 2582 | { |
| 2583 | if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN |
| 2584 | && irel->r_offset > addr |
| 2585 | && count < (1 << irel->r_addend)) |
| 2586 | { |
| 2587 | irelalign = irel; |
| 2588 | toaddr = irel->r_offset; |
| 2589 | break; |
| 2590 | } |
| 2591 | } |
| 2592 | |
| 2593 | /* Actually delete the bytes. */ |
| 2594 | memmove (contents + addr, contents + addr + count, |
| 2595 | (size_t) (toaddr - addr - count)); |
| 2596 | if (irelalign == NULL) |
| 2597 | sec->size -= count; |
| 2598 | else |
| 2599 | { |
| 2600 | int i; |
| 2601 | |
| 2602 | #define NOP_OPCODE (0x0009) |
| 2603 | |
| 2604 | BFD_ASSERT ((count & 1) == 0); |
| 2605 | for (i = 0; i < count; i += 2) |
| 2606 | bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i); |
| 2607 | } |
| 2608 | |
| 2609 | /* Adjust all the relocs. */ |
| 2610 | for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++) |
| 2611 | { |
| 2612 | bfd_vma nraddr, stop; |
| 2613 | bfd_vma start = 0; |
| 2614 | int insn = 0; |
| 2615 | int off, adjust, oinsn; |
| 2616 | bfd_signed_vma voff = 0; |
| 2617 | bfd_boolean overflow; |
| 2618 | |
| 2619 | /* Get the new reloc address. */ |
| 2620 | nraddr = irel->r_offset; |
| 2621 | if ((irel->r_offset > addr |
| 2622 | && irel->r_offset < toaddr) |
| 2623 | || (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN |
| 2624 | && irel->r_offset == toaddr)) |
| 2625 | nraddr -= count; |
| 2626 | |
| 2627 | /* See if this reloc was for the bytes we have deleted, in which |
| 2628 | case we no longer care about it. Don't delete relocs which |
| 2629 | represent addresses, though. */ |
| 2630 | if (irel->r_offset >= addr |
| 2631 | && irel->r_offset < addr + count |
| 2632 | && ELF32_R_TYPE (irel->r_info) != (int) R_SH_ALIGN |
| 2633 | && ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE |
| 2634 | && ELF32_R_TYPE (irel->r_info) != (int) R_SH_DATA |
| 2635 | && ELF32_R_TYPE (irel->r_info) != (int) R_SH_LABEL) |
| 2636 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), |
| 2637 | (int) R_SH_NONE); |
| 2638 | |
| 2639 | /* If this is a PC relative reloc, see if the range it covers |
| 2640 | includes the bytes we have deleted. */ |
| 2641 | switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info)) |
| 2642 | { |
| 2643 | default: |
| 2644 | break; |
| 2645 | |
| 2646 | case R_SH_DIR8WPN: |
| 2647 | case R_SH_IND12W: |
| 2648 | case R_SH_DIR8WPZ: |
| 2649 | case R_SH_DIR8WPL: |
| 2650 | start = irel->r_offset; |
| 2651 | insn = bfd_get_16 (abfd, contents + nraddr); |
| 2652 | break; |
| 2653 | } |
| 2654 | |
| 2655 | switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info)) |
| 2656 | { |
| 2657 | default: |
| 2658 | start = stop = addr; |
| 2659 | break; |
| 2660 | |
| 2661 | case R_SH_DIR32: |
| 2662 | /* If this reloc is against a symbol defined in this |
| 2663 | section, and the symbol will not be adjusted below, we |
| 2664 | must check the addend to see it will put the value in |
| 2665 | range to be adjusted, and hence must be changed. */ |
| 2666 | if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) |
| 2667 | { |
| 2668 | isym = isymbuf + ELF32_R_SYM (irel->r_info); |
| 2669 | if (isym->st_shndx == sec_shndx |
| 2670 | && (isym->st_value <= addr |
| 2671 | || isym->st_value >= toaddr)) |
| 2672 | { |
| 2673 | bfd_vma val; |
| 2674 | |
| 2675 | val = bfd_get_32 (abfd, contents + nraddr); |
| 2676 | val += isym->st_value; |
| 2677 | if (val > addr && val < toaddr) |
| 2678 | bfd_put_32 (abfd, val - count, contents + nraddr); |
| 2679 | } |
| 2680 | } |
| 2681 | start = stop = addr; |
| 2682 | break; |
| 2683 | |
| 2684 | case R_SH_DIR8WPN: |
| 2685 | off = insn & 0xff; |
| 2686 | if (off & 0x80) |
| 2687 | off -= 0x100; |
| 2688 | stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2); |
| 2689 | break; |
| 2690 | |
| 2691 | case R_SH_IND12W: |
| 2692 | off = insn & 0xfff; |
| 2693 | if (! off) |
| 2694 | { |
| 2695 | /* This has been made by previous relaxation. Since the |
| 2696 | relocation will be against an external symbol, the |
| 2697 | final relocation will just do the right thing. */ |
| 2698 | start = stop = addr; |
| 2699 | } |
| 2700 | else |
| 2701 | { |
| 2702 | if (off & 0x800) |
| 2703 | off -= 0x1000; |
| 2704 | stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2); |
| 2705 | |
| 2706 | /* The addend will be against the section symbol, thus |
| 2707 | for adjusting the addend, the relevant start is the |
| 2708 | start of the section. |
| 2709 | N.B. If we want to abandon in-place changes here and |
| 2710 | test directly using symbol + addend, we have to take into |
| 2711 | account that the addend has already been adjusted by -4. */ |
| 2712 | if (stop > addr && stop < toaddr) |
| 2713 | irel->r_addend -= count; |
| 2714 | } |
| 2715 | break; |
| 2716 | |
| 2717 | case R_SH_DIR8WPZ: |
| 2718 | off = insn & 0xff; |
| 2719 | stop = start + 4 + off * 2; |
| 2720 | break; |
| 2721 | |
| 2722 | case R_SH_DIR8WPL: |
| 2723 | off = insn & 0xff; |
| 2724 | stop = (start & ~(bfd_vma) 3) + 4 + off * 4; |
| 2725 | break; |
| 2726 | |
| 2727 | case R_SH_SWITCH8: |
| 2728 | case R_SH_SWITCH16: |
| 2729 | case R_SH_SWITCH32: |
| 2730 | /* These relocs types represent |
| 2731 | .word L2-L1 |
| 2732 | The r_addend field holds the difference between the reloc |
| 2733 | address and L1. That is the start of the reloc, and |
| 2734 | adding in the contents gives us the top. We must adjust |
| 2735 | both the r_offset field and the section contents. |
| 2736 | N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset, |
| 2737 | and the elf bfd r_offset is called r_vaddr. */ |
| 2738 | |
| 2739 | stop = irel->r_offset; |
| 2740 | start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend); |
| 2741 | |
| 2742 | if (start > addr |
| 2743 | && start < toaddr |
| 2744 | && (stop <= addr || stop >= toaddr)) |
| 2745 | irel->r_addend += count; |
| 2746 | else if (stop > addr |
| 2747 | && stop < toaddr |
| 2748 | && (start <= addr || start >= toaddr)) |
| 2749 | irel->r_addend -= count; |
| 2750 | |
| 2751 | if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16) |
| 2752 | voff = bfd_get_signed_16 (abfd, contents + nraddr); |
| 2753 | else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8) |
| 2754 | voff = bfd_get_8 (abfd, contents + nraddr); |
| 2755 | else |
| 2756 | voff = bfd_get_signed_32 (abfd, contents + nraddr); |
| 2757 | stop = (bfd_vma) ((bfd_signed_vma) start + voff); |
| 2758 | |
| 2759 | break; |
| 2760 | |
| 2761 | case R_SH_USES: |
| 2762 | start = irel->r_offset; |
| 2763 | stop = (bfd_vma) ((bfd_signed_vma) start |
| 2764 | + (long) irel->r_addend |
| 2765 | + 4); |
| 2766 | break; |
| 2767 | } |
| 2768 | |
| 2769 | if (start > addr |
| 2770 | && start < toaddr |
| 2771 | && (stop <= addr || stop >= toaddr)) |
| 2772 | adjust = count; |
| 2773 | else if (stop > addr |
| 2774 | && stop < toaddr |
| 2775 | && (start <= addr || start >= toaddr)) |
| 2776 | adjust = - count; |
| 2777 | else |
| 2778 | adjust = 0; |
| 2779 | |
| 2780 | if (adjust != 0) |
| 2781 | { |
| 2782 | oinsn = insn; |
| 2783 | overflow = FALSE; |
| 2784 | switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info)) |
| 2785 | { |
| 2786 | default: |
| 2787 | abort (); |
| 2788 | break; |
| 2789 | |
| 2790 | case R_SH_DIR8WPN: |
| 2791 | case R_SH_DIR8WPZ: |
| 2792 | insn += adjust / 2; |
| 2793 | if ((oinsn & 0xff00) != (insn & 0xff00)) |
| 2794 | overflow = TRUE; |
| 2795 | bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr); |
| 2796 | break; |
| 2797 | |
| 2798 | case R_SH_IND12W: |
| 2799 | insn += adjust / 2; |
| 2800 | if ((oinsn & 0xf000) != (insn & 0xf000)) |
| 2801 | overflow = TRUE; |
| 2802 | bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr); |
| 2803 | break; |
| 2804 | |
| 2805 | case R_SH_DIR8WPL: |
| 2806 | BFD_ASSERT (adjust == count || count >= 4); |
| 2807 | if (count >= 4) |
| 2808 | insn += adjust / 4; |
| 2809 | else |
| 2810 | { |
| 2811 | if ((irel->r_offset & 3) == 0) |
| 2812 | ++insn; |
| 2813 | } |
| 2814 | if ((oinsn & 0xff00) != (insn & 0xff00)) |
| 2815 | overflow = TRUE; |
| 2816 | bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr); |
| 2817 | break; |
| 2818 | |
| 2819 | case R_SH_SWITCH8: |
| 2820 | voff += adjust; |
| 2821 | if (voff < 0 || voff >= 0xff) |
| 2822 | overflow = TRUE; |
| 2823 | bfd_put_8 (abfd, voff, contents + nraddr); |
| 2824 | break; |
| 2825 | |
| 2826 | case R_SH_SWITCH16: |
| 2827 | voff += adjust; |
| 2828 | if (voff < - 0x8000 || voff >= 0x8000) |
| 2829 | overflow = TRUE; |
| 2830 | bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr); |
| 2831 | break; |
| 2832 | |
| 2833 | case R_SH_SWITCH32: |
| 2834 | voff += adjust; |
| 2835 | bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr); |
| 2836 | break; |
| 2837 | |
| 2838 | case R_SH_USES: |
| 2839 | irel->r_addend += adjust; |
| 2840 | break; |
| 2841 | } |
| 2842 | |
| 2843 | if (overflow) |
| 2844 | { |
| 2845 | ((*_bfd_error_handler) |
| 2846 | (_("%B: 0x%lx: fatal: reloc overflow while relaxing"), |
| 2847 | abfd, (unsigned long) irel->r_offset)); |
| 2848 | bfd_set_error (bfd_error_bad_value); |
| 2849 | return FALSE; |
| 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | irel->r_offset = nraddr; |
| 2854 | } |
| 2855 | |
| 2856 | /* Look through all the other sections. If there contain any IMM32 |
| 2857 | relocs against internal symbols which we are not going to adjust |
| 2858 | below, we may need to adjust the addends. */ |
| 2859 | for (o = abfd->sections; o != NULL; o = o->next) |
| 2860 | { |
| 2861 | Elf_Internal_Rela *internal_relocs; |
| 2862 | Elf_Internal_Rela *irelscan, *irelscanend; |
| 2863 | bfd_byte *ocontents; |
| 2864 | |
| 2865 | if (o == sec |
| 2866 | || (o->flags & SEC_RELOC) == 0 |
| 2867 | || o->reloc_count == 0) |
| 2868 | continue; |
| 2869 | |
| 2870 | /* We always cache the relocs. Perhaps, if info->keep_memory is |
| 2871 | FALSE, we should free them, if we are permitted to, when we |
| 2872 | leave sh_coff_relax_section. */ |
| 2873 | internal_relocs = (_bfd_elf_link_read_relocs |
| 2874 | (abfd, o, NULL, (Elf_Internal_Rela *) NULL, TRUE)); |
| 2875 | if (internal_relocs == NULL) |
| 2876 | return FALSE; |
| 2877 | |
| 2878 | ocontents = NULL; |
| 2879 | irelscanend = internal_relocs + o->reloc_count; |
| 2880 | for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++) |
| 2881 | { |
| 2882 | /* Dwarf line numbers use R_SH_SWITCH32 relocs. */ |
| 2883 | if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32) |
| 2884 | { |
| 2885 | bfd_vma start, stop; |
| 2886 | bfd_signed_vma voff; |
| 2887 | |
| 2888 | if (ocontents == NULL) |
| 2889 | { |
| 2890 | if (elf_section_data (o)->this_hdr.contents != NULL) |
| 2891 | ocontents = elf_section_data (o)->this_hdr.contents; |
| 2892 | else |
| 2893 | { |
| 2894 | /* We always cache the section contents. |
| 2895 | Perhaps, if info->keep_memory is FALSE, we |
| 2896 | should free them, if we are permitted to, |
| 2897 | when we leave sh_coff_relax_section. */ |
| 2898 | if (!bfd_malloc_and_get_section (abfd, o, &ocontents)) |
| 2899 | { |
| 2900 | if (ocontents != NULL) |
| 2901 | free (ocontents); |
| 2902 | return FALSE; |
| 2903 | } |
| 2904 | |
| 2905 | elf_section_data (o)->this_hdr.contents = ocontents; |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | stop = irelscan->r_offset; |
| 2910 | start |
| 2911 | = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend); |
| 2912 | |
| 2913 | /* STOP is in a different section, so it won't change. */ |
| 2914 | if (start > addr && start < toaddr) |
| 2915 | irelscan->r_addend += count; |
| 2916 | |
| 2917 | voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset); |
| 2918 | stop = (bfd_vma) ((bfd_signed_vma) start + voff); |
| 2919 | |
| 2920 | if (start > addr |
| 2921 | && start < toaddr |
| 2922 | && (stop <= addr || stop >= toaddr)) |
| 2923 | bfd_put_signed_32 (abfd, (bfd_vma) voff + count, |
| 2924 | ocontents + irelscan->r_offset); |
| 2925 | else if (stop > addr |
| 2926 | && stop < toaddr |
| 2927 | && (start <= addr || start >= toaddr)) |
| 2928 | bfd_put_signed_32 (abfd, (bfd_vma) voff - count, |
| 2929 | ocontents + irelscan->r_offset); |
| 2930 | } |
| 2931 | |
| 2932 | if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32) |
| 2933 | continue; |
| 2934 | |
| 2935 | if (ELF32_R_SYM (irelscan->r_info) >= symtab_hdr->sh_info) |
| 2936 | continue; |
| 2937 | |
| 2938 | |
| 2939 | isym = isymbuf + ELF32_R_SYM (irelscan->r_info); |
| 2940 | if (isym->st_shndx == sec_shndx |
| 2941 | && (isym->st_value <= addr |
| 2942 | || isym->st_value >= toaddr)) |
| 2943 | { |
| 2944 | bfd_vma val; |
| 2945 | |
| 2946 | if (ocontents == NULL) |
| 2947 | { |
| 2948 | if (elf_section_data (o)->this_hdr.contents != NULL) |
| 2949 | ocontents = elf_section_data (o)->this_hdr.contents; |
| 2950 | else |
| 2951 | { |
| 2952 | /* We always cache the section contents. |
| 2953 | Perhaps, if info->keep_memory is FALSE, we |
| 2954 | should free them, if we are permitted to, |
| 2955 | when we leave sh_coff_relax_section. */ |
| 2956 | if (!bfd_malloc_and_get_section (abfd, o, &ocontents)) |
| 2957 | { |
| 2958 | if (ocontents != NULL) |
| 2959 | free (ocontents); |
| 2960 | return FALSE; |
| 2961 | } |
| 2962 | |
| 2963 | elf_section_data (o)->this_hdr.contents = ocontents; |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | val = bfd_get_32 (abfd, ocontents + irelscan->r_offset); |
| 2968 | val += isym->st_value; |
| 2969 | if (val > addr && val < toaddr) |
| 2970 | bfd_put_32 (abfd, val - count, |
| 2971 | ocontents + irelscan->r_offset); |
| 2972 | } |
| 2973 | } |
| 2974 | } |
| 2975 | |
| 2976 | /* Adjust the local symbols defined in this section. */ |
| 2977 | isymend = isymbuf + symtab_hdr->sh_info; |
| 2978 | for (isym = isymbuf; isym < isymend; isym++) |
| 2979 | { |
| 2980 | if (isym->st_shndx == sec_shndx |
| 2981 | && isym->st_value > addr |
| 2982 | && isym->st_value < toaddr) |
| 2983 | isym->st_value -= count; |
| 2984 | } |
| 2985 | |
| 2986 | /* Now adjust the global symbols defined in this section. */ |
| 2987 | symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) |
| 2988 | - symtab_hdr->sh_info); |
| 2989 | sym_hashes = elf_sym_hashes (abfd); |
| 2990 | end_hashes = sym_hashes + symcount; |
| 2991 | for (; sym_hashes < end_hashes; sym_hashes++) |
| 2992 | { |
| 2993 | struct elf_link_hash_entry *sym_hash = *sym_hashes; |
| 2994 | if ((sym_hash->root.type == bfd_link_hash_defined |
| 2995 | || sym_hash->root.type == bfd_link_hash_defweak) |
| 2996 | && sym_hash->root.u.def.section == sec |
| 2997 | && sym_hash->root.u.def.value > addr |
| 2998 | && sym_hash->root.u.def.value < toaddr) |
| 2999 | { |
| 3000 | sym_hash->root.u.def.value -= count; |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | /* See if we can move the ALIGN reloc forward. We have adjusted |
| 3005 | r_offset for it already. */ |
| 3006 | if (irelalign != NULL) |
| 3007 | { |
| 3008 | bfd_vma alignto, alignaddr; |
| 3009 | |
| 3010 | alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend); |
| 3011 | alignaddr = BFD_ALIGN (irelalign->r_offset, |
| 3012 | 1 << irelalign->r_addend); |
| 3013 | if (alignto != alignaddr) |
| 3014 | { |
| 3015 | /* Tail recursion. */ |
| 3016 | return sh_elf_relax_delete_bytes (abfd, sec, alignaddr, |
| 3017 | (int) (alignto - alignaddr)); |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | return TRUE; |
| 3022 | } |
| 3023 | |
| 3024 | /* Look for loads and stores which we can align to four byte |
| 3025 | boundaries. This is like sh_align_loads in coff-sh.c. */ |
| 3026 | |
| 3027 | static bfd_boolean |
| 3028 | sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, |
| 3029 | Elf_Internal_Rela *internal_relocs, |
| 3030 | bfd_byte *contents ATTRIBUTE_UNUSED, |
| 3031 | bfd_boolean *pswapped) |
| 3032 | { |
| 3033 | Elf_Internal_Rela *irel, *irelend; |
| 3034 | bfd_vma *labels = NULL; |
| 3035 | bfd_vma *label, *label_end; |
| 3036 | bfd_size_type amt; |
| 3037 | |
| 3038 | *pswapped = FALSE; |
| 3039 | |
| 3040 | irelend = internal_relocs + sec->reloc_count; |
| 3041 | |
| 3042 | /* Get all the addresses with labels on them. */ |
| 3043 | amt = sec->reloc_count; |
| 3044 | amt *= sizeof (bfd_vma); |
| 3045 | labels = (bfd_vma *) bfd_malloc (amt); |
| 3046 | if (labels == NULL) |
| 3047 | goto error_return; |
| 3048 | label_end = labels; |
| 3049 | for (irel = internal_relocs; irel < irelend; irel++) |
| 3050 | { |
| 3051 | if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_LABEL) |
| 3052 | { |
| 3053 | *label_end = irel->r_offset; |
| 3054 | ++label_end; |
| 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | /* Note that the assembler currently always outputs relocs in |
| 3059 | address order. If that ever changes, this code will need to sort |
| 3060 | the label values and the relocs. */ |
| 3061 | |
| 3062 | label = labels; |
| 3063 | |
| 3064 | for (irel = internal_relocs; irel < irelend; irel++) |
| 3065 | { |
| 3066 | bfd_vma start, stop; |
| 3067 | |
| 3068 | if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE) |
| 3069 | continue; |
| 3070 | |
| 3071 | start = irel->r_offset; |
| 3072 | |
| 3073 | for (irel++; irel < irelend; irel++) |
| 3074 | if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_DATA) |
| 3075 | break; |
| 3076 | if (irel < irelend) |
| 3077 | stop = irel->r_offset; |
| 3078 | else |
| 3079 | stop = sec->size; |
| 3080 | |
| 3081 | if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns, |
| 3082 | internal_relocs, &label, |
| 3083 | label_end, start, stop, pswapped)) |
| 3084 | goto error_return; |
| 3085 | } |
| 3086 | |
| 3087 | free (labels); |
| 3088 | |
| 3089 | return TRUE; |
| 3090 | |
| 3091 | error_return: |
| 3092 | if (labels != NULL) |
| 3093 | free (labels); |
| 3094 | return FALSE; |
| 3095 | } |
| 3096 | |
| 3097 | #ifndef SH64_ELF |
| 3098 | /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */ |
| 3099 | |
| 3100 | static bfd_boolean |
| 3101 | sh_elf_swap_insns (bfd *abfd, asection *sec, void *relocs, |
| 3102 | bfd_byte *contents, bfd_vma addr) |
| 3103 | { |
| 3104 | Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs; |
| 3105 | unsigned short i1, i2; |
| 3106 | Elf_Internal_Rela *irel, *irelend; |
| 3107 | |
| 3108 | /* Swap the instructions themselves. */ |
| 3109 | i1 = bfd_get_16 (abfd, contents + addr); |
| 3110 | i2 = bfd_get_16 (abfd, contents + addr + 2); |
| 3111 | bfd_put_16 (abfd, (bfd_vma) i2, contents + addr); |
| 3112 | bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2); |
| 3113 | |
| 3114 | /* Adjust all reloc addresses. */ |
| 3115 | irelend = internal_relocs + sec->reloc_count; |
| 3116 | for (irel = internal_relocs; irel < irelend; irel++) |
| 3117 | { |
| 3118 | enum elf_sh_reloc_type type; |
| 3119 | int add; |
| 3120 | |
| 3121 | /* There are a few special types of relocs that we don't want to |
| 3122 | adjust. These relocs do not apply to the instruction itself, |
| 3123 | but are only associated with the address. */ |
| 3124 | type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info); |
| 3125 | if (type == R_SH_ALIGN |
| 3126 | || type == R_SH_CODE |
| 3127 | || type == R_SH_DATA |
| 3128 | || type == R_SH_LABEL) |
| 3129 | continue; |
| 3130 | |
| 3131 | /* If an R_SH_USES reloc points to one of the addresses being |
| 3132 | swapped, we must adjust it. It would be incorrect to do this |
| 3133 | for a jump, though, since we want to execute both |
| 3134 | instructions after the jump. (We have avoided swapping |
| 3135 | around a label, so the jump will not wind up executing an |
| 3136 | instruction it shouldn't). */ |
| 3137 | if (type == R_SH_USES) |
| 3138 | { |
| 3139 | bfd_vma off; |
| 3140 | |
| 3141 | off = irel->r_offset + 4 + irel->r_addend; |
| 3142 | if (off == addr) |
| 3143 | irel->r_offset += 2; |
| 3144 | else if (off == addr + 2) |
| 3145 | irel->r_offset -= 2; |
| 3146 | } |
| 3147 | |
| 3148 | if (irel->r_offset == addr) |
| 3149 | { |
| 3150 | irel->r_offset += 2; |
| 3151 | add = -2; |
| 3152 | } |
| 3153 | else if (irel->r_offset == addr + 2) |
| 3154 | { |
| 3155 | irel->r_offset -= 2; |
| 3156 | add = 2; |
| 3157 | } |
| 3158 | else |
| 3159 | add = 0; |
| 3160 | |
| 3161 | if (add != 0) |
| 3162 | { |
| 3163 | bfd_byte *loc; |
| 3164 | unsigned short insn, oinsn; |
| 3165 | bfd_boolean overflow; |
| 3166 | |
| 3167 | loc = contents + irel->r_offset; |
| 3168 | overflow = FALSE; |
| 3169 | switch (type) |
| 3170 | { |
| 3171 | default: |
| 3172 | break; |
| 3173 | |
| 3174 | case R_SH_DIR8WPN: |
| 3175 | case R_SH_DIR8WPZ: |
| 3176 | insn = bfd_get_16 (abfd, loc); |
| 3177 | oinsn = insn; |
| 3178 | insn += add / 2; |
| 3179 | if ((oinsn & 0xff00) != (insn & 0xff00)) |
| 3180 | overflow = TRUE; |
| 3181 | bfd_put_16 (abfd, (bfd_vma) insn, loc); |
| 3182 | break; |
| 3183 | |
| 3184 | case R_SH_IND12W: |
| 3185 | insn = bfd_get_16 (abfd, loc); |
| 3186 | oinsn = insn; |
| 3187 | insn += add / 2; |
| 3188 | if ((oinsn & 0xf000) != (insn & 0xf000)) |
| 3189 | overflow = TRUE; |
| 3190 | bfd_put_16 (abfd, (bfd_vma) insn, loc); |
| 3191 | break; |
| 3192 | |
| 3193 | case R_SH_DIR8WPL: |
| 3194 | /* This reloc ignores the least significant 3 bits of |
| 3195 | the program counter before adding in the offset. |
| 3196 | This means that if ADDR is at an even address, the |
| 3197 | swap will not affect the offset. If ADDR is an at an |
| 3198 | odd address, then the instruction will be crossing a |
| 3199 | four byte boundary, and must be adjusted. */ |
| 3200 | if ((addr & 3) != 0) |
| 3201 | { |
| 3202 | insn = bfd_get_16 (abfd, loc); |
| 3203 | oinsn = insn; |
| 3204 | insn += add / 2; |
| 3205 | if ((oinsn & 0xff00) != (insn & 0xff00)) |
| 3206 | overflow = TRUE; |
| 3207 | bfd_put_16 (abfd, (bfd_vma) insn, loc); |
| 3208 | } |
| 3209 | |
| 3210 | break; |
| 3211 | } |
| 3212 | |
| 3213 | if (overflow) |
| 3214 | { |
| 3215 | ((*_bfd_error_handler) |
| 3216 | (_("%B: 0x%lx: fatal: reloc overflow while relaxing"), |
| 3217 | abfd, (unsigned long) irel->r_offset)); |
| 3218 | bfd_set_error (bfd_error_bad_value); |
| 3219 | return FALSE; |
| 3220 | } |
| 3221 | } |
| 3222 | } |
| 3223 | |
| 3224 | return TRUE; |
| 3225 | } |
| 3226 | #endif /* defined SH64_ELF */ |
| 3227 | \f |
| 3228 | #ifdef INCLUDE_SHMEDIA |
| 3229 | |
| 3230 | /* The size in bytes of an entry in the procedure linkage table. */ |
| 3231 | |
| 3232 | #define PLT_ENTRY_SIZE 64 |
| 3233 | |
| 3234 | /* First entry in an absolute procedure linkage table look like this. */ |
| 3235 | |
| 3236 | static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] = |
| 3237 | { |
| 3238 | 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */ |
| 3239 | 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */ |
| 3240 | 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */ |
| 3241 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ |
| 3242 | 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */ |
| 3243 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ |
| 3244 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3245 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3246 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3247 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3248 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3249 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3250 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3251 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3252 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3253 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3254 | }; |
| 3255 | |
| 3256 | static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] = |
| 3257 | { |
| 3258 | 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */ |
| 3259 | 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */ |
| 3260 | 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */ |
| 3261 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ |
| 3262 | 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */ |
| 3263 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ |
| 3264 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3265 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3266 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3267 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3268 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3269 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3270 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3271 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3272 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3273 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3274 | }; |
| 3275 | |
| 3276 | /* Sebsequent entries in an absolute procedure linkage table look like |
| 3277 | this. */ |
| 3278 | |
| 3279 | static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] = |
| 3280 | { |
| 3281 | 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */ |
| 3282 | 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */ |
| 3283 | 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */ |
| 3284 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ |
| 3285 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ |
| 3286 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3287 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3288 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3289 | 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */ |
| 3290 | 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */ |
| 3291 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ |
| 3292 | 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */ |
| 3293 | 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */ |
| 3294 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ |
| 3295 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3296 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3297 | }; |
| 3298 | |
| 3299 | static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] = |
| 3300 | { |
| 3301 | 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */ |
| 3302 | 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */ |
| 3303 | 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */ |
| 3304 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ |
| 3305 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ |
| 3306 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3307 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3308 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3309 | 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */ |
| 3310 | 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */ |
| 3311 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ |
| 3312 | 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */ |
| 3313 | 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */ |
| 3314 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ |
| 3315 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3316 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3317 | }; |
| 3318 | |
| 3319 | /* Entries in a PIC procedure linkage table look like this. */ |
| 3320 | |
| 3321 | static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] = |
| 3322 | { |
| 3323 | 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */ |
| 3324 | 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */ |
| 3325 | 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */ |
| 3326 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ |
| 3327 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ |
| 3328 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3329 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3330 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 3331 | 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */ |
| 3332 | 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */ |
| 3333 | 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */ |
| 3334 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ |
| 3335 | 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */ |
| 3336 | 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */ |
| 3337 | 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */ |
| 3338 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ |
| 3339 | }; |
| 3340 | |
| 3341 | static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] = |
| 3342 | { |
| 3343 | 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */ |
| 3344 | 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */ |
| 3345 | 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */ |
| 3346 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ |
| 3347 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ |
| 3348 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3349 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3350 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 3351 | 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */ |
| 3352 | 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */ |
| 3353 | 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */ |
| 3354 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ |
| 3355 | 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */ |
| 3356 | 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */ |
| 3357 | 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */ |
| 3358 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ |
| 3359 | }; |
| 3360 | |
| 3361 | static const bfd_byte *elf_sh_plt0_entry; |
| 3362 | static const bfd_byte *elf_sh_plt_entry; |
| 3363 | static const bfd_byte *elf_sh_pic_plt_entry; |
| 3364 | |
| 3365 | /* Return size of a PLT entry. */ |
| 3366 | #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE |
| 3367 | |
| 3368 | /* Return offset of the PLT0 address in an absolute PLT entry. */ |
| 3369 | #define elf_sh_plt_plt0_offset(info) 32 |
| 3370 | |
| 3371 | /* Return offset of the linker in PLT0 entry. */ |
| 3372 | #define elf_sh_plt0_gotplt_offset(info) 0 |
| 3373 | |
| 3374 | /* Return offset of the trampoline in PLT entry */ |
| 3375 | #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */ |
| 3376 | |
| 3377 | /* Return offset of the symbol in PLT entry. */ |
| 3378 | #define elf_sh_plt_symbol_offset(info) 0 |
| 3379 | |
| 3380 | /* Return offset of the relocation in PLT entry. */ |
| 3381 | #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44) |
| 3382 | |
| 3383 | inline static void |
| 3384 | movi_shori_putval (bfd *output_bfd, unsigned long value, char *addr) |
| 3385 | { |
| 3386 | bfd_put_32 (output_bfd, |
| 3387 | bfd_get_32 (output_bfd, addr) |
| 3388 | | ((value >> 6) & 0x3fffc00), |
| 3389 | addr); |
| 3390 | bfd_put_32 (output_bfd, |
| 3391 | bfd_get_32 (output_bfd, addr + 4) |
| 3392 | | ((value << 10) & 0x3fffc00), |
| 3393 | addr + 4); |
| 3394 | } |
| 3395 | |
| 3396 | #else |
| 3397 | /* The size in bytes of an entry in the procedure linkage table. */ |
| 3398 | |
| 3399 | #define PLT_ENTRY_SIZE 28 |
| 3400 | |
| 3401 | /* First entry in an absolute procedure linkage table look like this. */ |
| 3402 | |
| 3403 | #if 1 |
| 3404 | /* Note - this code has been "optimised" not to use r2. r2 is used by |
| 3405 | GCC to return the address of large structures, so it should not be |
| 3406 | corrupted here. This does mean however, that this PLT does not conform |
| 3407 | to the SH PIC ABI. That spec says that r0 contains the type of the PLT |
| 3408 | and r2 contains the GOT id. This version stores the GOT id in r0 and |
| 3409 | ignores the type. Loaders can easily detect this difference however, |
| 3410 | since the type will always be 0 or 8, and the GOT ids will always be |
| 3411 | greater than or equal to 12. */ |
| 3412 | static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] = |
| 3413 | { |
| 3414 | 0xd0, 0x05, /* mov.l 2f,r0 */ |
| 3415 | 0x60, 0x02, /* mov.l @r0,r0 */ |
| 3416 | 0x2f, 0x06, /* mov.l r0,@-r15 */ |
| 3417 | 0xd0, 0x03, /* mov.l 1f,r0 */ |
| 3418 | 0x60, 0x02, /* mov.l @r0,r0 */ |
| 3419 | 0x40, 0x2b, /* jmp @r0 */ |
| 3420 | 0x60, 0xf6, /* mov.l @r15+,r0 */ |
| 3421 | 0x00, 0x09, /* nop */ |
| 3422 | 0x00, 0x09, /* nop */ |
| 3423 | 0x00, 0x09, /* nop */ |
| 3424 | 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */ |
| 3425 | 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */ |
| 3426 | }; |
| 3427 | |
| 3428 | static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] = |
| 3429 | { |
| 3430 | 0x05, 0xd0, /* mov.l 2f,r0 */ |
| 3431 | 0x02, 0x60, /* mov.l @r0,r0 */ |
| 3432 | 0x06, 0x2f, /* mov.l r0,@-r15 */ |
| 3433 | 0x03, 0xd0, /* mov.l 1f,r0 */ |
| 3434 | 0x02, 0x60, /* mov.l @r0,r0 */ |
| 3435 | 0x2b, 0x40, /* jmp @r0 */ |
| 3436 | 0xf6, 0x60, /* mov.l @r15+,r0 */ |
| 3437 | 0x09, 0x00, /* nop */ |
| 3438 | 0x09, 0x00, /* nop */ |
| 3439 | 0x09, 0x00, /* nop */ |
| 3440 | 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */ |
| 3441 | 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */ |
| 3442 | }; |
| 3443 | |
| 3444 | /* Sebsequent entries in an absolute procedure linkage table look like |
| 3445 | this. */ |
| 3446 | |
| 3447 | static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] = |
| 3448 | { |
| 3449 | 0xd0, 0x04, /* mov.l 1f,r0 */ |
| 3450 | 0x60, 0x02, /* mov.l @r0,r0 */ |
| 3451 | 0xd1, 0x02, /* mov.l 0f,r1 */ |
| 3452 | 0x40, 0x2b, /* jmp @r0 */ |
| 3453 | 0x60, 0x13, /* mov r1,r0 */ |
| 3454 | 0xd1, 0x03, /* mov.l 2f,r1 */ |
| 3455 | 0x40, 0x2b, /* jmp @r0 */ |
| 3456 | 0x00, 0x09, /* nop */ |
| 3457 | 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */ |
| 3458 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ |
| 3459 | 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */ |
| 3460 | }; |
| 3461 | |
| 3462 | static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] = |
| 3463 | { |
| 3464 | 0x04, 0xd0, /* mov.l 1f,r0 */ |
| 3465 | 0x02, 0x60, /* mov.l @r0,r0 */ |
| 3466 | 0x02, 0xd1, /* mov.l 0f,r1 */ |
| 3467 | 0x2b, 0x40, /* jmp @r0 */ |
| 3468 | 0x13, 0x60, /* mov r1,r0 */ |
| 3469 | 0x03, 0xd1, /* mov.l 2f,r1 */ |
| 3470 | 0x2b, 0x40, /* jmp @r0 */ |
| 3471 | 0x09, 0x00, /* nop */ |
| 3472 | 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */ |
| 3473 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ |
| 3474 | 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */ |
| 3475 | }; |
| 3476 | |
| 3477 | /* Entries in a PIC procedure linkage table look like this. */ |
| 3478 | |
| 3479 | static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] = |
| 3480 | { |
| 3481 | 0xd0, 0x04, /* mov.l 1f,r0 */ |
| 3482 | 0x00, 0xce, /* mov.l @(r0,r12),r0 */ |
| 3483 | 0x40, 0x2b, /* jmp @r0 */ |
| 3484 | 0x00, 0x09, /* nop */ |
| 3485 | 0x50, 0xc2, /* mov.l @(8,r12),r0 */ |
| 3486 | 0xd1, 0x03, /* mov.l 2f,r1 */ |
| 3487 | 0x40, 0x2b, /* jmp @r0 */ |
| 3488 | 0x50, 0xc1, /* mov.l @(4,r12),r0 */ |
| 3489 | 0x00, 0x09, /* nop */ |
| 3490 | 0x00, 0x09, /* nop */ |
| 3491 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ |
| 3492 | 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */ |
| 3493 | }; |
| 3494 | |
| 3495 | static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] = |
| 3496 | { |
| 3497 | 0x04, 0xd0, /* mov.l 1f,r0 */ |
| 3498 | 0xce, 0x00, /* mov.l @(r0,r12),r0 */ |
| 3499 | 0x2b, 0x40, /* jmp @r0 */ |
| 3500 | 0x09, 0x00, /* nop */ |
| 3501 | 0xc2, 0x50, /* mov.l @(8,r12),r0 */ |
| 3502 | 0x03, 0xd1, /* mov.l 2f,r1 */ |
| 3503 | 0x2b, 0x40, /* jmp @r0 */ |
| 3504 | 0xc1, 0x50, /* mov.l @(4,r12),r0 */ |
| 3505 | 0x09, 0x00, /* nop */ |
| 3506 | 0x09, 0x00, /* nop */ |
| 3507 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ |
| 3508 | 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */ |
| 3509 | }; |
| 3510 | |
| 3511 | #else /* These are the old style PLT entries. */ |
| 3512 | static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] = |
| 3513 | { |
| 3514 | 0xd0, 0x04, /* mov.l 1f,r0 */ |
| 3515 | 0xd2, 0x05, /* mov.l 2f,r2 */ |
| 3516 | 0x60, 0x02, /* mov.l @r0,r0 */ |
| 3517 | 0x62, 0x22, /* mov.l @r2,r2 */ |
| 3518 | 0x40, 0x2b, /* jmp @r0 */ |
| 3519 | 0xe0, 0x00, /* mov #0,r0 */ |
| 3520 | 0x00, 0x09, /* nop */ |
| 3521 | 0x00, 0x09, /* nop */ |
| 3522 | 0x00, 0x09, /* nop */ |
| 3523 | 0x00, 0x09, /* nop */ |
| 3524 | 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */ |
| 3525 | 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */ |
| 3526 | }; |
| 3527 | |
| 3528 | static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] = |
| 3529 | { |
| 3530 | 0x04, 0xd0, /* mov.l 1f,r0 */ |
| 3531 | 0x05, 0xd2, /* mov.l 2f,r2 */ |
| 3532 | 0x02, 0x60, /* mov.l @r0,r0 */ |
| 3533 | 0x22, 0x62, /* mov.l @r2,r2 */ |
| 3534 | 0x2b, 0x40, /* jmp @r0 */ |
| 3535 | 0x00, 0xe0, /* mov #0,r0 */ |
| 3536 | 0x09, 0x00, /* nop */ |
| 3537 | 0x09, 0x00, /* nop */ |
| 3538 | 0x09, 0x00, /* nop */ |
| 3539 | 0x09, 0x00, /* nop */ |
| 3540 | 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */ |
| 3541 | 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */ |
| 3542 | }; |
| 3543 | |
| 3544 | /* Sebsequent entries in an absolute procedure linkage table look like |
| 3545 | this. */ |
| 3546 | |
| 3547 | static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] = |
| 3548 | { |
| 3549 | 0xd0, 0x04, /* mov.l 1f,r0 */ |
| 3550 | 0x60, 0x02, /* mov.l @r0,r0 */ |
| 3551 | 0xd2, 0x02, /* mov.l 0f,r2 */ |
| 3552 | 0x40, 0x2b, /* jmp @r0 */ |
| 3553 | 0x60, 0x23, /* mov r2,r0 */ |
| 3554 | 0xd1, 0x03, /* mov.l 2f,r1 */ |
| 3555 | 0x40, 0x2b, /* jmp @r0 */ |
| 3556 | 0x00, 0x09, /* nop */ |
| 3557 | 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */ |
| 3558 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ |
| 3559 | 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */ |
| 3560 | }; |
| 3561 | |
| 3562 | static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] = |
| 3563 | { |
| 3564 | 0x04, 0xd0, /* mov.l 1f,r0 */ |
| 3565 | 0x02, 0x60, /* mov.l @r0,r0 */ |
| 3566 | 0x02, 0xd2, /* mov.l 0f,r2 */ |
| 3567 | 0x2b, 0x40, /* jmp @r0 */ |
| 3568 | 0x23, 0x60, /* mov r2,r0 */ |
| 3569 | 0x03, 0xd1, /* mov.l 2f,r1 */ |
| 3570 | 0x2b, 0x40, /* jmp @r0 */ |
| 3571 | 0x09, 0x00, /* nop */ |
| 3572 | 0, 0, 0, 0, /* 0: replaced with address of .PLT. */ |
| 3573 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ |
| 3574 | 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */ |
| 3575 | }; |
| 3576 | |
| 3577 | /* Entries in a PIC procedure linkage table look like this. */ |
| 3578 | |
| 3579 | static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] = |
| 3580 | { |
| 3581 | 0xd0, 0x04, /* mov.l 1f,r0 */ |
| 3582 | 0x00, 0xce, /* mov.l @(r0,r12),r0 */ |
| 3583 | 0x40, 0x2b, /* jmp @r0 */ |
| 3584 | 0x00, 0x09, /* nop */ |
| 3585 | 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */ |
| 3586 | 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */ |
| 3587 | 0xd1, 0x02, /* mov.l 2f,r1 */ |
| 3588 | 0x40, 0x2b, /* jmp @r0 */ |
| 3589 | 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */ |
| 3590 | 0x00, 0x09, /* nop */ |
| 3591 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ |
| 3592 | 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */ |
| 3593 | }; |
| 3594 | |
| 3595 | static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] = |
| 3596 | { |
| 3597 | 0x04, 0xd0, /* mov.l 1f,r0 */ |
| 3598 | 0xce, 0x00, /* mov.l @(r0,r12),r0 */ |
| 3599 | 0x2b, 0x40, /* jmp @r0 */ |
| 3600 | 0x09, 0x00, /* nop */ |
| 3601 | 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */ |
| 3602 | 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */ |
| 3603 | 0x02, 0xd1, /* mov.l 2f,r1 */ |
| 3604 | 0x2b, 0x40, /* jmp @r0 */ |
| 3605 | 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */ |
| 3606 | 0x09, 0x00, /* nop */ |
| 3607 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ |
| 3608 | 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */ |
| 3609 | }; |
| 3610 | #endif /* old style PLT entries. */ |
| 3611 | |
| 3612 | static const bfd_byte *elf_sh_plt0_entry; |
| 3613 | static const bfd_byte *elf_sh_plt_entry; |
| 3614 | static const bfd_byte *elf_sh_pic_plt_entry; |
| 3615 | |
| 3616 | /* Return size of a PLT entry. */ |
| 3617 | #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE |
| 3618 | |
| 3619 | /* Return offset of the PLT0 address in an absolute PLT entry. */ |
| 3620 | #define elf_sh_plt_plt0_offset(info) 16 |
| 3621 | |
| 3622 | /* Return offset of the linker in PLT0 entry. */ |
| 3623 | #define elf_sh_plt0_linker_offset(info) 20 |
| 3624 | |
| 3625 | /* Return offset of the GOT id in PLT0 entry. */ |
| 3626 | #define elf_sh_plt0_gotid_offset(info) 24 |
| 3627 | |
| 3628 | /* Return offset of the temporary in PLT entry */ |
| 3629 | #define elf_sh_plt_temp_offset(info) 8 |
| 3630 | |
| 3631 | /* Return offset of the symbol in PLT entry. */ |
| 3632 | #define elf_sh_plt_symbol_offset(info) 20 |
| 3633 | |
| 3634 | /* Return offset of the relocation in PLT entry. */ |
| 3635 | #define elf_sh_plt_reloc_offset(info) 24 |
| 3636 | #endif |
| 3637 | |
| 3638 | /* The sh linker needs to keep track of the number of relocs that it |
| 3639 | decides to copy as dynamic relocs in check_relocs for each symbol. |
| 3640 | This is so that it can later discard them if they are found to be |
| 3641 | unnecessary. We store the information in a field extending the |
| 3642 | regular ELF linker hash table. */ |
| 3643 | |
| 3644 | struct elf_sh_dyn_relocs |
| 3645 | { |
| 3646 | struct elf_sh_dyn_relocs *next; |
| 3647 | |
| 3648 | /* The input section of the reloc. */ |
| 3649 | asection *sec; |
| 3650 | |
| 3651 | /* Total number of relocs copied for the input section. */ |
| 3652 | bfd_size_type count; |
| 3653 | |
| 3654 | /* Number of pc-relative relocs copied for the input section. */ |
| 3655 | bfd_size_type pc_count; |
| 3656 | }; |
| 3657 | |
| 3658 | /* sh ELF linker hash entry. */ |
| 3659 | |
| 3660 | struct elf_sh_link_hash_entry |
| 3661 | { |
| 3662 | struct elf_link_hash_entry root; |
| 3663 | |
| 3664 | #ifdef INCLUDE_SHMEDIA |
| 3665 | union |
| 3666 | { |
| 3667 | bfd_signed_vma refcount; |
| 3668 | bfd_vma offset; |
| 3669 | } datalabel_got; |
| 3670 | #endif |
| 3671 | |
| 3672 | /* Track dynamic relocs copied for this symbol. */ |
| 3673 | struct elf_sh_dyn_relocs *dyn_relocs; |
| 3674 | |
| 3675 | bfd_signed_vma gotplt_refcount; |
| 3676 | |
| 3677 | enum { |
| 3678 | GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE |
| 3679 | } tls_type; |
| 3680 | }; |
| 3681 | |
| 3682 | #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent)) |
| 3683 | |
| 3684 | struct sh_elf_obj_tdata |
| 3685 | { |
| 3686 | struct elf_obj_tdata root; |
| 3687 | |
| 3688 | /* tls_type for each local got entry. */ |
| 3689 | char *local_got_tls_type; |
| 3690 | }; |
| 3691 | |
| 3692 | #define sh_elf_tdata(abfd) \ |
| 3693 | ((struct sh_elf_obj_tdata *) (abfd)->tdata.any) |
| 3694 | |
| 3695 | #define sh_elf_local_got_tls_type(abfd) \ |
| 3696 | (sh_elf_tdata (abfd)->local_got_tls_type) |
| 3697 | |
| 3698 | /* Override the generic function because we need to store sh_elf_obj_tdata |
| 3699 | as the specific tdata. */ |
| 3700 | |
| 3701 | static bfd_boolean |
| 3702 | sh_elf_mkobject (bfd *abfd) |
| 3703 | { |
| 3704 | bfd_size_type amt = sizeof (struct sh_elf_obj_tdata); |
| 3705 | abfd->tdata.any = bfd_zalloc (abfd, amt); |
| 3706 | if (abfd->tdata.any == NULL) |
| 3707 | return FALSE; |
| 3708 | return TRUE; |
| 3709 | } |
| 3710 | |
| 3711 | /* sh ELF linker hash table. */ |
| 3712 | |
| 3713 | struct elf_sh_link_hash_table |
| 3714 | { |
| 3715 | struct elf_link_hash_table root; |
| 3716 | |
| 3717 | /* Short-cuts to get to dynamic linker sections. */ |
| 3718 | asection *sgot; |
| 3719 | asection *sgotplt; |
| 3720 | asection *srelgot; |
| 3721 | asection *splt; |
| 3722 | asection *srelplt; |
| 3723 | asection *sdynbss; |
| 3724 | asection *srelbss; |
| 3725 | |
| 3726 | /* Small local sym to section mapping cache. */ |
| 3727 | struct sym_sec_cache sym_sec; |
| 3728 | |
| 3729 | /* A counter or offset to track a TLS got entry. */ |
| 3730 | union |
| 3731 | { |
| 3732 | bfd_signed_vma refcount; |
| 3733 | bfd_vma offset; |
| 3734 | } tls_ldm_got; |
| 3735 | }; |
| 3736 | |
| 3737 | /* Traverse an sh ELF linker hash table. */ |
| 3738 | |
| 3739 | #define sh_elf_link_hash_traverse(table, func, info) \ |
| 3740 | (elf_link_hash_traverse \ |
| 3741 | (&(table)->root, \ |
| 3742 | (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ |
| 3743 | (info))) |
| 3744 | |
| 3745 | /* Get the sh ELF linker hash table from a link_info structure. */ |
| 3746 | |
| 3747 | #define sh_elf_hash_table(p) \ |
| 3748 | ((struct elf_sh_link_hash_table *) ((p)->hash)) |
| 3749 | |
| 3750 | /* Create an entry in an sh ELF linker hash table. */ |
| 3751 | |
| 3752 | static struct bfd_hash_entry * |
| 3753 | sh_elf_link_hash_newfunc (struct bfd_hash_entry *entry, |
| 3754 | struct bfd_hash_table *table, |
| 3755 | const char *string) |
| 3756 | { |
| 3757 | struct elf_sh_link_hash_entry *ret = |
| 3758 | (struct elf_sh_link_hash_entry *) entry; |
| 3759 | |
| 3760 | /* Allocate the structure if it has not already been allocated by a |
| 3761 | subclass. */ |
| 3762 | if (ret == (struct elf_sh_link_hash_entry *) NULL) |
| 3763 | ret = ((struct elf_sh_link_hash_entry *) |
| 3764 | bfd_hash_allocate (table, |
| 3765 | sizeof (struct elf_sh_link_hash_entry))); |
| 3766 | if (ret == (struct elf_sh_link_hash_entry *) NULL) |
| 3767 | return (struct bfd_hash_entry *) ret; |
| 3768 | |
| 3769 | /* Call the allocation method of the superclass. */ |
| 3770 | ret = ((struct elf_sh_link_hash_entry *) |
| 3771 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
| 3772 | table, string)); |
| 3773 | if (ret != (struct elf_sh_link_hash_entry *) NULL) |
| 3774 | { |
| 3775 | ret->dyn_relocs = NULL; |
| 3776 | ret->gotplt_refcount = 0; |
| 3777 | #ifdef INCLUDE_SHMEDIA |
| 3778 | ret->datalabel_got.refcount = ret->root.got.refcount; |
| 3779 | #endif |
| 3780 | ret->tls_type = GOT_UNKNOWN; |
| 3781 | } |
| 3782 | |
| 3783 | return (struct bfd_hash_entry *) ret; |
| 3784 | } |
| 3785 | |
| 3786 | /* Create an sh ELF linker hash table. */ |
| 3787 | |
| 3788 | static struct bfd_link_hash_table * |
| 3789 | sh_elf_link_hash_table_create (bfd *abfd) |
| 3790 | { |
| 3791 | struct elf_sh_link_hash_table *ret; |
| 3792 | bfd_size_type amt = sizeof (struct elf_sh_link_hash_table); |
| 3793 | |
| 3794 | ret = (struct elf_sh_link_hash_table *) bfd_malloc (amt); |
| 3795 | if (ret == (struct elf_sh_link_hash_table *) NULL) |
| 3796 | return NULL; |
| 3797 | |
| 3798 | if (! _bfd_elf_link_hash_table_init (&ret->root, abfd, |
| 3799 | sh_elf_link_hash_newfunc)) |
| 3800 | { |
| 3801 | free (ret); |
| 3802 | return NULL; |
| 3803 | } |
| 3804 | |
| 3805 | ret->sgot = NULL; |
| 3806 | ret->sgotplt = NULL; |
| 3807 | ret->srelgot = NULL; |
| 3808 | ret->splt = NULL; |
| 3809 | ret->srelplt = NULL; |
| 3810 | ret->sdynbss = NULL; |
| 3811 | ret->srelbss = NULL; |
| 3812 | ret->sym_sec.abfd = NULL; |
| 3813 | ret->tls_ldm_got.refcount = 0; |
| 3814 | |
| 3815 | return &ret->root.root; |
| 3816 | } |
| 3817 | |
| 3818 | /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up |
| 3819 | shortcuts to them in our hash table. */ |
| 3820 | |
| 3821 | static bfd_boolean |
| 3822 | create_got_section (bfd *dynobj, struct bfd_link_info *info) |
| 3823 | { |
| 3824 | struct elf_sh_link_hash_table *htab; |
| 3825 | |
| 3826 | if (! _bfd_elf_create_got_section (dynobj, info)) |
| 3827 | return FALSE; |
| 3828 | |
| 3829 | htab = sh_elf_hash_table (info); |
| 3830 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 3831 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 3832 | if (! htab->sgot || ! htab->sgotplt) |
| 3833 | abort (); |
| 3834 | |
| 3835 | htab->srelgot = bfd_make_section (dynobj, ".rela.got"); |
| 3836 | if (htab->srelgot == NULL |
| 3837 | || ! bfd_set_section_flags (dynobj, htab->srelgot, |
| 3838 | (SEC_ALLOC |
| 3839 | | SEC_LOAD |
| 3840 | | SEC_HAS_CONTENTS |
| 3841 | | SEC_IN_MEMORY |
| 3842 | | SEC_LINKER_CREATED |
| 3843 | | SEC_READONLY)) |
| 3844 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) |
| 3845 | return FALSE; |
| 3846 | return TRUE; |
| 3847 | } |
| 3848 | |
| 3849 | /* Create dynamic sections when linking against a dynamic object. */ |
| 3850 | |
| 3851 | static bfd_boolean |
| 3852 | sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) |
| 3853 | { |
| 3854 | struct elf_sh_link_hash_table *htab; |
| 3855 | flagword flags, pltflags; |
| 3856 | register asection *s; |
| 3857 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); |
| 3858 | int ptralign = 0; |
| 3859 | |
| 3860 | switch (bed->s->arch_size) |
| 3861 | { |
| 3862 | case 32: |
| 3863 | ptralign = 2; |
| 3864 | break; |
| 3865 | |
| 3866 | case 64: |
| 3867 | ptralign = 3; |
| 3868 | break; |
| 3869 | |
| 3870 | default: |
| 3871 | bfd_set_error (bfd_error_bad_value); |
| 3872 | return FALSE; |
| 3873 | } |
| 3874 | |
| 3875 | htab = sh_elf_hash_table (info); |
| 3876 | if (htab->root.dynamic_sections_created) |
| 3877 | return TRUE; |
| 3878 | |
| 3879 | /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and |
| 3880 | .rel[a].bss sections. */ |
| 3881 | |
| 3882 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
| 3883 | | SEC_LINKER_CREATED); |
| 3884 | |
| 3885 | pltflags = flags; |
| 3886 | pltflags |= SEC_CODE; |
| 3887 | if (bed->plt_not_loaded) |
| 3888 | pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS); |
| 3889 | if (bed->plt_readonly) |
| 3890 | pltflags |= SEC_READONLY; |
| 3891 | |
| 3892 | s = bfd_make_section (abfd, ".plt"); |
| 3893 | htab->splt = s; |
| 3894 | if (s == NULL |
| 3895 | || ! bfd_set_section_flags (abfd, s, pltflags) |
| 3896 | || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) |
| 3897 | return FALSE; |
| 3898 | |
| 3899 | if (bed->want_plt_sym) |
| 3900 | { |
| 3901 | /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the |
| 3902 | .plt section. */ |
| 3903 | struct elf_link_hash_entry *h; |
| 3904 | struct bfd_link_hash_entry *bh = NULL; |
| 3905 | |
| 3906 | if (! (_bfd_generic_link_add_one_symbol |
| 3907 | (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, |
| 3908 | (bfd_vma) 0, (const char *) NULL, FALSE, |
| 3909 | get_elf_backend_data (abfd)->collect, &bh))) |
| 3910 | return FALSE; |
| 3911 | |
| 3912 | h = (struct elf_link_hash_entry *) bh; |
| 3913 | h->def_regular = 1; |
| 3914 | h->type = STT_OBJECT; |
| 3915 | |
| 3916 | if (info->shared |
| 3917 | && ! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 3918 | return FALSE; |
| 3919 | } |
| 3920 | |
| 3921 | s = bfd_make_section (abfd, |
| 3922 | bed->default_use_rela_p ? ".rela.plt" : ".rel.plt"); |
| 3923 | htab->srelplt = s; |
| 3924 | if (s == NULL |
| 3925 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) |
| 3926 | || ! bfd_set_section_alignment (abfd, s, ptralign)) |
| 3927 | return FALSE; |
| 3928 | |
| 3929 | if (htab->sgot == NULL |
| 3930 | && !create_got_section (abfd, info)) |
| 3931 | return FALSE; |
| 3932 | |
| 3933 | { |
| 3934 | const char *secname; |
| 3935 | char *relname; |
| 3936 | flagword secflags; |
| 3937 | asection *sec; |
| 3938 | |
| 3939 | for (sec = abfd->sections; sec; sec = sec->next) |
| 3940 | { |
| 3941 | secflags = bfd_get_section_flags (abfd, sec); |
| 3942 | if ((secflags & (SEC_DATA | SEC_LINKER_CREATED)) |
| 3943 | || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS)) |
| 3944 | continue; |
| 3945 | secname = bfd_get_section_name (abfd, sec); |
| 3946 | relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6); |
| 3947 | strcpy (relname, ".rela"); |
| 3948 | strcat (relname, secname); |
| 3949 | if (bfd_get_section_by_name (abfd, secname)) |
| 3950 | continue; |
| 3951 | s = bfd_make_section (abfd, relname); |
| 3952 | if (s == NULL |
| 3953 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) |
| 3954 | || ! bfd_set_section_alignment (abfd, s, ptralign)) |
| 3955 | return FALSE; |
| 3956 | } |
| 3957 | } |
| 3958 | |
| 3959 | if (bed->want_dynbss) |
| 3960 | { |
| 3961 | /* The .dynbss section is a place to put symbols which are defined |
| 3962 | by dynamic objects, are referenced by regular objects, and are |
| 3963 | not functions. We must allocate space for them in the process |
| 3964 | image and use a R_*_COPY reloc to tell the dynamic linker to |
| 3965 | initialize them at run time. The linker script puts the .dynbss |
| 3966 | section into the .bss section of the final image. */ |
| 3967 | s = bfd_make_section (abfd, ".dynbss"); |
| 3968 | htab->sdynbss = s; |
| 3969 | if (s == NULL |
| 3970 | || ! bfd_set_section_flags (abfd, s, SEC_ALLOC)) |
| 3971 | return FALSE; |
| 3972 | |
| 3973 | /* The .rel[a].bss section holds copy relocs. This section is not |
| 3974 | normally needed. We need to create it here, though, so that the |
| 3975 | linker will map it to an output section. We can't just create it |
| 3976 | only if we need it, because we will not know whether we need it |
| 3977 | until we have seen all the input files, and the first time the |
| 3978 | main linker code calls BFD after examining all the input files |
| 3979 | (size_dynamic_sections) the input sections have already been |
| 3980 | mapped to the output sections. If the section turns out not to |
| 3981 | be needed, we can discard it later. We will never need this |
| 3982 | section when generating a shared object, since they do not use |
| 3983 | copy relocs. */ |
| 3984 | if (! info->shared) |
| 3985 | { |
| 3986 | s = bfd_make_section (abfd, |
| 3987 | (bed->default_use_rela_p |
| 3988 | ? ".rela.bss" : ".rel.bss")); |
| 3989 | htab->srelbss = s; |
| 3990 | if (s == NULL |
| 3991 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) |
| 3992 | || ! bfd_set_section_alignment (abfd, s, ptralign)) |
| 3993 | return FALSE; |
| 3994 | } |
| 3995 | } |
| 3996 | |
| 3997 | return TRUE; |
| 3998 | } |
| 3999 | \f |
| 4000 | /* Adjust a symbol defined by a dynamic object and referenced by a |
| 4001 | regular object. The current definition is in some section of the |
| 4002 | dynamic object, but we're not including those sections. We have to |
| 4003 | change the definition to something the rest of the link can |
| 4004 | understand. */ |
| 4005 | |
| 4006 | static bfd_boolean |
| 4007 | sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info, |
| 4008 | struct elf_link_hash_entry *h) |
| 4009 | { |
| 4010 | struct elf_sh_link_hash_table *htab; |
| 4011 | struct elf_sh_link_hash_entry *eh; |
| 4012 | struct elf_sh_dyn_relocs *p; |
| 4013 | asection *s; |
| 4014 | unsigned int power_of_two; |
| 4015 | |
| 4016 | htab = sh_elf_hash_table (info); |
| 4017 | |
| 4018 | /* Make sure we know what is going on here. */ |
| 4019 | BFD_ASSERT (htab->root.dynobj != NULL |
| 4020 | && (h->needs_plt |
| 4021 | || h->u.weakdef != NULL |
| 4022 | || (h->def_dynamic |
| 4023 | && h->ref_regular |
| 4024 | && !h->def_regular))); |
| 4025 | |
| 4026 | /* If this is a function, put it in the procedure linkage table. We |
| 4027 | will fill in the contents of the procedure linkage table later, |
| 4028 | when we know the address of the .got section. */ |
| 4029 | if (h->type == STT_FUNC |
| 4030 | || h->needs_plt) |
| 4031 | { |
| 4032 | if (h->plt.refcount <= 0 |
| 4033 | || SYMBOL_CALLS_LOCAL (info, h) |
| 4034 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
| 4035 | && h->root.type == bfd_link_hash_undefweak)) |
| 4036 | { |
| 4037 | /* This case can occur if we saw a PLT reloc in an input |
| 4038 | file, but the symbol was never referred to by a dynamic |
| 4039 | object. In such a case, we don't actually need to build |
| 4040 | a procedure linkage table, and we can just do a REL32 |
| 4041 | reloc instead. */ |
| 4042 | h->plt.offset = (bfd_vma) -1; |
| 4043 | h->needs_plt = 0; |
| 4044 | } |
| 4045 | |
| 4046 | return TRUE; |
| 4047 | } |
| 4048 | else |
| 4049 | h->plt.offset = (bfd_vma) -1; |
| 4050 | |
| 4051 | /* If this is a weak symbol, and there is a real definition, the |
| 4052 | processor independent code will have arranged for us to see the |
| 4053 | real definition first, and we can just use the same value. */ |
| 4054 | if (h->u.weakdef != NULL) |
| 4055 | { |
| 4056 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
| 4057 | || h->u.weakdef->root.type == bfd_link_hash_defweak); |
| 4058 | h->root.u.def.section = h->u.weakdef->root.u.def.section; |
| 4059 | h->root.u.def.value = h->u.weakdef->root.u.def.value; |
| 4060 | if (info->nocopyreloc) |
| 4061 | h->non_got_ref = h->u.weakdef->non_got_ref; |
| 4062 | return TRUE; |
| 4063 | } |
| 4064 | |
| 4065 | /* This is a reference to a symbol defined by a dynamic object which |
| 4066 | is not a function. */ |
| 4067 | |
| 4068 | /* If we are creating a shared library, we must presume that the |
| 4069 | only references to the symbol are via the global offset table. |
| 4070 | For such cases we need not do anything here; the relocations will |
| 4071 | be handled correctly by relocate_section. */ |
| 4072 | if (info->shared) |
| 4073 | return TRUE; |
| 4074 | |
| 4075 | /* If there are no references to this symbol that do not use the |
| 4076 | GOT, we don't need to generate a copy reloc. */ |
| 4077 | if (!h->non_got_ref) |
| 4078 | return TRUE; |
| 4079 | |
| 4080 | /* If -z nocopyreloc was given, we won't generate them either. */ |
| 4081 | if (info->nocopyreloc) |
| 4082 | { |
| 4083 | h->non_got_ref = 0; |
| 4084 | return TRUE; |
| 4085 | } |
| 4086 | |
| 4087 | eh = (struct elf_sh_link_hash_entry *) h; |
| 4088 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
| 4089 | { |
| 4090 | s = p->sec->output_section; |
| 4091 | if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0) |
| 4092 | break; |
| 4093 | } |
| 4094 | |
| 4095 | /* If we didn't find any dynamic relocs in sections which needs the |
| 4096 | copy reloc, then we'll be keeping the dynamic relocs and avoiding |
| 4097 | the copy reloc. */ |
| 4098 | if (p == NULL) |
| 4099 | { |
| 4100 | h->non_got_ref = 0; |
| 4101 | return TRUE; |
| 4102 | } |
| 4103 | |
| 4104 | /* We must allocate the symbol in our .dynbss section, which will |
| 4105 | become part of the .bss section of the executable. There will be |
| 4106 | an entry for this symbol in the .dynsym section. The dynamic |
| 4107 | object will contain position independent code, so all references |
| 4108 | from the dynamic object to this symbol will go through the global |
| 4109 | offset table. The dynamic linker will use the .dynsym entry to |
| 4110 | determine the address it must put in the global offset table, so |
| 4111 | both the dynamic object and the regular object will refer to the |
| 4112 | same memory location for the variable. */ |
| 4113 | |
| 4114 | s = htab->sdynbss; |
| 4115 | BFD_ASSERT (s != NULL); |
| 4116 | |
| 4117 | /* We must generate a R_SH_COPY reloc to tell the dynamic linker to |
| 4118 | copy the initial value out of the dynamic object and into the |
| 4119 | runtime process image. We need to remember the offset into the |
| 4120 | .rela.bss section we are going to use. */ |
| 4121 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
| 4122 | { |
| 4123 | asection *srel; |
| 4124 | |
| 4125 | srel = htab->srelbss; |
| 4126 | BFD_ASSERT (srel != NULL); |
| 4127 | srel->size += sizeof (Elf32_External_Rela); |
| 4128 | h->needs_copy = 1; |
| 4129 | } |
| 4130 | |
| 4131 | /* We need to figure out the alignment required for this symbol. I |
| 4132 | have no idea how ELF linkers handle this. */ |
| 4133 | power_of_two = bfd_log2 (h->size); |
| 4134 | if (power_of_two > 3) |
| 4135 | power_of_two = 3; |
| 4136 | |
| 4137 | /* Apply the required alignment. */ |
| 4138 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
| 4139 | if (power_of_two > bfd_get_section_alignment (htab->root.dynobj, s)) |
| 4140 | { |
| 4141 | if (! bfd_set_section_alignment (htab->root.dynobj, s, power_of_two)) |
| 4142 | return FALSE; |
| 4143 | } |
| 4144 | |
| 4145 | /* Define the symbol as being at this point in the section. */ |
| 4146 | h->root.u.def.section = s; |
| 4147 | h->root.u.def.value = s->size; |
| 4148 | |
| 4149 | /* Increment the section size to make room for the symbol. */ |
| 4150 | s->size += h->size; |
| 4151 | |
| 4152 | return TRUE; |
| 4153 | } |
| 4154 | |
| 4155 | /* Allocate space in .plt, .got and associated reloc sections for |
| 4156 | dynamic relocs. */ |
| 4157 | |
| 4158 | static bfd_boolean |
| 4159 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
| 4160 | { |
| 4161 | struct bfd_link_info *info; |
| 4162 | struct elf_sh_link_hash_table *htab; |
| 4163 | struct elf_sh_link_hash_entry *eh; |
| 4164 | struct elf_sh_dyn_relocs *p; |
| 4165 | |
| 4166 | if (h->root.type == bfd_link_hash_indirect) |
| 4167 | return TRUE; |
| 4168 | |
| 4169 | if (h->root.type == bfd_link_hash_warning) |
| 4170 | /* When warning symbols are created, they **replace** the "real" |
| 4171 | entry in the hash table, thus we never get to see the real |
| 4172 | symbol in a hash traversal. So look at it now. */ |
| 4173 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 4174 | |
| 4175 | info = (struct bfd_link_info *) inf; |
| 4176 | htab = sh_elf_hash_table (info); |
| 4177 | |
| 4178 | eh = (struct elf_sh_link_hash_entry *) h; |
| 4179 | if ((h->got.refcount > 0 |
| 4180 | || h->forced_local) |
| 4181 | && eh->gotplt_refcount > 0) |
| 4182 | { |
| 4183 | /* The symbol has been forced local, or we have some direct got refs, |
| 4184 | so treat all the gotplt refs as got refs. */ |
| 4185 | h->got.refcount += eh->gotplt_refcount; |
| 4186 | if (h->plt.refcount >= eh->gotplt_refcount) |
| 4187 | h->plt.refcount -= eh->gotplt_refcount; |
| 4188 | } |
| 4189 | |
| 4190 | if (htab->root.dynamic_sections_created |
| 4191 | && h->plt.refcount > 0 |
| 4192 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
| 4193 | || h->root.type != bfd_link_hash_undefweak)) |
| 4194 | { |
| 4195 | /* Make sure this symbol is output as a dynamic symbol. |
| 4196 | Undefined weak syms won't yet be marked as dynamic. */ |
| 4197 | if (h->dynindx == -1 |
| 4198 | && !h->forced_local) |
| 4199 | { |
| 4200 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 4201 | return FALSE; |
| 4202 | } |
| 4203 | |
| 4204 | if (info->shared |
| 4205 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
| 4206 | { |
| 4207 | asection *s = htab->splt; |
| 4208 | |
| 4209 | /* If this is the first .plt entry, make room for the special |
| 4210 | first entry. */ |
| 4211 | if (s->size == 0) |
| 4212 | s->size += PLT_ENTRY_SIZE; |
| 4213 | |
| 4214 | h->plt.offset = s->size; |
| 4215 | |
| 4216 | /* If this symbol is not defined in a regular file, and we are |
| 4217 | not generating a shared library, then set the symbol to this |
| 4218 | location in the .plt. This is required to make function |
| 4219 | pointers compare as equal between the normal executable and |
| 4220 | the shared library. */ |
| 4221 | if (! info->shared |
| 4222 | && !h->def_regular) |
| 4223 | { |
| 4224 | h->root.u.def.section = s; |
| 4225 | h->root.u.def.value = h->plt.offset; |
| 4226 | } |
| 4227 | |
| 4228 | /* Make room for this entry. */ |
| 4229 | s->size += PLT_ENTRY_SIZE; |
| 4230 | |
| 4231 | /* We also need to make an entry in the .got.plt section, which |
| 4232 | will be placed in the .got section by the linker script. */ |
| 4233 | htab->sgotplt->size += 4; |
| 4234 | |
| 4235 | /* We also need to make an entry in the .rel.plt section. */ |
| 4236 | htab->srelplt->size += sizeof (Elf32_External_Rela); |
| 4237 | } |
| 4238 | else |
| 4239 | { |
| 4240 | h->plt.offset = (bfd_vma) -1; |
| 4241 | h->needs_plt = 0; |
| 4242 | } |
| 4243 | } |
| 4244 | else |
| 4245 | { |
| 4246 | h->plt.offset = (bfd_vma) -1; |
| 4247 | h->needs_plt = 0; |
| 4248 | } |
| 4249 | |
| 4250 | if (h->got.refcount > 0) |
| 4251 | { |
| 4252 | asection *s; |
| 4253 | bfd_boolean dyn; |
| 4254 | int tls_type = sh_elf_hash_entry (h)->tls_type; |
| 4255 | |
| 4256 | /* Make sure this symbol is output as a dynamic symbol. |
| 4257 | Undefined weak syms won't yet be marked as dynamic. */ |
| 4258 | if (h->dynindx == -1 |
| 4259 | && !h->forced_local) |
| 4260 | { |
| 4261 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 4262 | return FALSE; |
| 4263 | } |
| 4264 | |
| 4265 | s = htab->sgot; |
| 4266 | h->got.offset = s->size; |
| 4267 | s->size += 4; |
| 4268 | /* R_SH_TLS_GD needs 2 consecutive GOT slots. */ |
| 4269 | if (tls_type == GOT_TLS_GD) |
| 4270 | s->size += 4; |
| 4271 | dyn = htab->root.dynamic_sections_created; |
| 4272 | /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic, |
| 4273 | R_SH_TLS_GD needs one if local symbol and two if global. */ |
| 4274 | if ((tls_type == GOT_TLS_GD && h->dynindx == -1) |
| 4275 | || (tls_type == GOT_TLS_IE && dyn)) |
| 4276 | htab->srelgot->size += sizeof (Elf32_External_Rela); |
| 4277 | else if (tls_type == GOT_TLS_GD) |
| 4278 | htab->srelgot->size += 2 * sizeof (Elf32_External_Rela); |
| 4279 | else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
| 4280 | || h->root.type != bfd_link_hash_undefweak) |
| 4281 | && (info->shared |
| 4282 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) |
| 4283 | htab->srelgot->size += sizeof (Elf32_External_Rela); |
| 4284 | } |
| 4285 | else |
| 4286 | h->got.offset = (bfd_vma) -1; |
| 4287 | |
| 4288 | #ifdef INCLUDE_SHMEDIA |
| 4289 | if (eh->datalabel_got.refcount > 0) |
| 4290 | { |
| 4291 | asection *s; |
| 4292 | bfd_boolean dyn; |
| 4293 | |
| 4294 | /* Make sure this symbol is output as a dynamic symbol. |
| 4295 | Undefined weak syms won't yet be marked as dynamic. */ |
| 4296 | if (h->dynindx == -1 |
| 4297 | && !h->forced_local) |
| 4298 | { |
| 4299 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 4300 | return FALSE; |
| 4301 | } |
| 4302 | |
| 4303 | s = htab->sgot; |
| 4304 | eh->datalabel_got.offset = s->size; |
| 4305 | s->size += 4; |
| 4306 | dyn = htab->root.dynamic_sections_created; |
| 4307 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)) |
| 4308 | htab->srelgot->size += sizeof (Elf32_External_Rela); |
| 4309 | } |
| 4310 | else |
| 4311 | eh->datalabel_got.offset = (bfd_vma) -1; |
| 4312 | #endif |
| 4313 | |
| 4314 | if (eh->dyn_relocs == NULL) |
| 4315 | return TRUE; |
| 4316 | |
| 4317 | /* In the shared -Bsymbolic case, discard space allocated for |
| 4318 | dynamic pc-relative relocs against symbols which turn out to be |
| 4319 | defined in regular objects. For the normal shared case, discard |
| 4320 | space for pc-relative relocs that have become local due to symbol |
| 4321 | visibility changes. */ |
| 4322 | |
| 4323 | if (info->shared) |
| 4324 | { |
| 4325 | if (SYMBOL_CALLS_LOCAL (info, h)) |
| 4326 | { |
| 4327 | struct elf_sh_dyn_relocs **pp; |
| 4328 | |
| 4329 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) |
| 4330 | { |
| 4331 | p->count -= p->pc_count; |
| 4332 | p->pc_count = 0; |
| 4333 | if (p->count == 0) |
| 4334 | *pp = p->next; |
| 4335 | else |
| 4336 | pp = &p->next; |
| 4337 | } |
| 4338 | } |
| 4339 | |
| 4340 | /* Also discard relocs on undefined weak syms with non-default |
| 4341 | visibility. */ |
| 4342 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
| 4343 | && h->root.type == bfd_link_hash_undefweak) |
| 4344 | eh->dyn_relocs = NULL; |
| 4345 | } |
| 4346 | else |
| 4347 | { |
| 4348 | /* For the non-shared case, discard space for relocs against |
| 4349 | symbols which turn out to need copy relocs or are not |
| 4350 | dynamic. */ |
| 4351 | |
| 4352 | if (!h->non_got_ref |
| 4353 | && ((h->def_dynamic |
| 4354 | && !h->def_regular) |
| 4355 | || (htab->root.dynamic_sections_created |
| 4356 | && (h->root.type == bfd_link_hash_undefweak |
| 4357 | || h->root.type == bfd_link_hash_undefined)))) |
| 4358 | { |
| 4359 | /* Make sure this symbol is output as a dynamic symbol. |
| 4360 | Undefined weak syms won't yet be marked as dynamic. */ |
| 4361 | if (h->dynindx == -1 |
| 4362 | && !h->forced_local) |
| 4363 | { |
| 4364 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 4365 | return FALSE; |
| 4366 | } |
| 4367 | |
| 4368 | /* If that succeeded, we know we'll be keeping all the |
| 4369 | relocs. */ |
| 4370 | if (h->dynindx != -1) |
| 4371 | goto keep; |
| 4372 | } |
| 4373 | |
| 4374 | eh->dyn_relocs = NULL; |
| 4375 | |
| 4376 | keep: ; |
| 4377 | } |
| 4378 | |
| 4379 | /* Finally, allocate space. */ |
| 4380 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
| 4381 | { |
| 4382 | asection *sreloc = elf_section_data (p->sec)->sreloc; |
| 4383 | sreloc->size += p->count * sizeof (Elf32_External_Rela); |
| 4384 | } |
| 4385 | |
| 4386 | return TRUE; |
| 4387 | } |
| 4388 | |
| 4389 | /* Find any dynamic relocs that apply to read-only sections. */ |
| 4390 | |
| 4391 | static bfd_boolean |
| 4392 | readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
| 4393 | { |
| 4394 | struct elf_sh_link_hash_entry *eh; |
| 4395 | struct elf_sh_dyn_relocs *p; |
| 4396 | |
| 4397 | if (h->root.type == bfd_link_hash_warning) |
| 4398 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 4399 | |
| 4400 | eh = (struct elf_sh_link_hash_entry *) h; |
| 4401 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
| 4402 | { |
| 4403 | asection *s = p->sec->output_section; |
| 4404 | |
| 4405 | if (s != NULL && (s->flags & SEC_READONLY) != 0) |
| 4406 | { |
| 4407 | struct bfd_link_info *info = (struct bfd_link_info *) inf; |
| 4408 | |
| 4409 | info->flags |= DF_TEXTREL; |
| 4410 | |
| 4411 | /* Not an error, just cut short the traversal. */ |
| 4412 | return FALSE; |
| 4413 | } |
| 4414 | } |
| 4415 | return TRUE; |
| 4416 | } |
| 4417 | |
| 4418 | /* Set the sizes of the dynamic sections. */ |
| 4419 | |
| 4420 | static bfd_boolean |
| 4421 | sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
| 4422 | struct bfd_link_info *info) |
| 4423 | { |
| 4424 | struct elf_sh_link_hash_table *htab; |
| 4425 | bfd *dynobj; |
| 4426 | asection *s; |
| 4427 | bfd_boolean relocs; |
| 4428 | bfd *ibfd; |
| 4429 | |
| 4430 | htab = sh_elf_hash_table (info); |
| 4431 | dynobj = htab->root.dynobj; |
| 4432 | BFD_ASSERT (dynobj != NULL); |
| 4433 | |
| 4434 | if (htab->root.dynamic_sections_created) |
| 4435 | { |
| 4436 | /* Set the contents of the .interp section to the interpreter. */ |
| 4437 | if (info->executable) |
| 4438 | { |
| 4439 | s = bfd_get_section_by_name (dynobj, ".interp"); |
| 4440 | BFD_ASSERT (s != NULL); |
| 4441 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
| 4442 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
| 4443 | } |
| 4444 | } |
| 4445 | |
| 4446 | /* Set up .got offsets for local syms, and space for local dynamic |
| 4447 | relocs. */ |
| 4448 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
| 4449 | { |
| 4450 | bfd_signed_vma *local_got; |
| 4451 | bfd_signed_vma *end_local_got; |
| 4452 | char *local_tls_type; |
| 4453 | bfd_size_type locsymcount; |
| 4454 | Elf_Internal_Shdr *symtab_hdr; |
| 4455 | asection *srel; |
| 4456 | |
| 4457 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) |
| 4458 | continue; |
| 4459 | |
| 4460 | for (s = ibfd->sections; s != NULL; s = s->next) |
| 4461 | { |
| 4462 | struct elf_sh_dyn_relocs *p; |
| 4463 | |
| 4464 | for (p = ((struct elf_sh_dyn_relocs *) |
| 4465 | elf_section_data (s)->local_dynrel); |
| 4466 | p != NULL; |
| 4467 | p = p->next) |
| 4468 | { |
| 4469 | if (! bfd_is_abs_section (p->sec) |
| 4470 | && bfd_is_abs_section (p->sec->output_section)) |
| 4471 | { |
| 4472 | /* Input section has been discarded, either because |
| 4473 | it is a copy of a linkonce section or due to |
| 4474 | linker script /DISCARD/, so we'll be discarding |
| 4475 | the relocs too. */ |
| 4476 | } |
| 4477 | else if (p->count != 0) |
| 4478 | { |
| 4479 | srel = elf_section_data (p->sec)->sreloc; |
| 4480 | srel->size += p->count * sizeof (Elf32_External_Rela); |
| 4481 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
| 4482 | info->flags |= DF_TEXTREL; |
| 4483 | } |
| 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | local_got = elf_local_got_refcounts (ibfd); |
| 4488 | if (!local_got) |
| 4489 | continue; |
| 4490 | |
| 4491 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
| 4492 | locsymcount = symtab_hdr->sh_info; |
| 4493 | #ifdef INCLUDE_SHMEDIA |
| 4494 | /* Count datalabel local GOT. */ |
| 4495 | locsymcount *= 2; |
| 4496 | #endif |
| 4497 | end_local_got = local_got + locsymcount; |
| 4498 | local_tls_type = sh_elf_local_got_tls_type (ibfd); |
| 4499 | s = htab->sgot; |
| 4500 | srel = htab->srelgot; |
| 4501 | for (; local_got < end_local_got; ++local_got) |
| 4502 | { |
| 4503 | if (*local_got > 0) |
| 4504 | { |
| 4505 | *local_got = s->size; |
| 4506 | s->size += 4; |
| 4507 | if (*local_tls_type == GOT_TLS_GD) |
| 4508 | s->size += 4; |
| 4509 | if (info->shared) |
| 4510 | srel->size += sizeof (Elf32_External_Rela); |
| 4511 | } |
| 4512 | else |
| 4513 | *local_got = (bfd_vma) -1; |
| 4514 | ++local_tls_type; |
| 4515 | } |
| 4516 | } |
| 4517 | |
| 4518 | if (htab->tls_ldm_got.refcount > 0) |
| 4519 | { |
| 4520 | /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32 |
| 4521 | relocs. */ |
| 4522 | htab->tls_ldm_got.offset = htab->sgot->size; |
| 4523 | htab->sgot->size += 8; |
| 4524 | htab->srelgot->size += sizeof (Elf32_External_Rela); |
| 4525 | } |
| 4526 | else |
| 4527 | htab->tls_ldm_got.offset = -1; |
| 4528 | |
| 4529 | /* Allocate global sym .plt and .got entries, and space for global |
| 4530 | sym dynamic relocs. */ |
| 4531 | elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info); |
| 4532 | |
| 4533 | /* We now have determined the sizes of the various dynamic sections. |
| 4534 | Allocate memory for them. */ |
| 4535 | relocs = FALSE; |
| 4536 | for (s = dynobj->sections; s != NULL; s = s->next) |
| 4537 | { |
| 4538 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
| 4539 | continue; |
| 4540 | |
| 4541 | if (s == htab->splt |
| 4542 | || s == htab->sgot |
| 4543 | || s == htab->sgotplt) |
| 4544 | { |
| 4545 | /* Strip this section if we don't need it; see the |
| 4546 | comment below. */ |
| 4547 | } |
| 4548 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
| 4549 | { |
| 4550 | if (s->size != 0 && s != htab->srelplt) |
| 4551 | relocs = TRUE; |
| 4552 | |
| 4553 | /* We use the reloc_count field as a counter if we need |
| 4554 | to copy relocs into the output file. */ |
| 4555 | s->reloc_count = 0; |
| 4556 | } |
| 4557 | else |
| 4558 | { |
| 4559 | /* It's not one of our sections, so don't allocate space. */ |
| 4560 | continue; |
| 4561 | } |
| 4562 | |
| 4563 | if (s->size == 0) |
| 4564 | { |
| 4565 | /* If we don't need this section, strip it from the |
| 4566 | output file. This is mostly to handle .rela.bss and |
| 4567 | .rela.plt. We must create both sections in |
| 4568 | create_dynamic_sections, because they must be created |
| 4569 | before the linker maps input sections to output |
| 4570 | sections. The linker does that before |
| 4571 | adjust_dynamic_symbol is called, and it is that |
| 4572 | function which decides whether anything needs to go |
| 4573 | into these sections. */ |
| 4574 | |
| 4575 | _bfd_strip_section_from_output (info, s); |
| 4576 | continue; |
| 4577 | } |
| 4578 | |
| 4579 | /* Allocate memory for the section contents. We use bfd_zalloc |
| 4580 | here in case unused entries are not reclaimed before the |
| 4581 | section's contents are written out. This should not happen, |
| 4582 | but this way if it does, we get a R_SH_NONE reloc instead |
| 4583 | of garbage. */ |
| 4584 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
| 4585 | if (s->contents == NULL) |
| 4586 | return FALSE; |
| 4587 | } |
| 4588 | |
| 4589 | if (htab->root.dynamic_sections_created) |
| 4590 | { |
| 4591 | /* Add some entries to the .dynamic section. We fill in the |
| 4592 | values later, in sh_elf_finish_dynamic_sections, but we |
| 4593 | must add the entries now so that we get the correct size for |
| 4594 | the .dynamic section. The DT_DEBUG entry is filled in by the |
| 4595 | dynamic linker and used by the debugger. */ |
| 4596 | #define add_dynamic_entry(TAG, VAL) \ |
| 4597 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
| 4598 | |
| 4599 | if (info->executable) |
| 4600 | { |
| 4601 | if (! add_dynamic_entry (DT_DEBUG, 0)) |
| 4602 | return FALSE; |
| 4603 | } |
| 4604 | |
| 4605 | if (htab->splt->size != 0) |
| 4606 | { |
| 4607 | if (! add_dynamic_entry (DT_PLTGOT, 0) |
| 4608 | || ! add_dynamic_entry (DT_PLTRELSZ, 0) |
| 4609 | || ! add_dynamic_entry (DT_PLTREL, DT_RELA) |
| 4610 | || ! add_dynamic_entry (DT_JMPREL, 0)) |
| 4611 | return FALSE; |
| 4612 | } |
| 4613 | |
| 4614 | if (relocs) |
| 4615 | { |
| 4616 | if (! add_dynamic_entry (DT_RELA, 0) |
| 4617 | || ! add_dynamic_entry (DT_RELASZ, 0) |
| 4618 | || ! add_dynamic_entry (DT_RELAENT, |
| 4619 | sizeof (Elf32_External_Rela))) |
| 4620 | return FALSE; |
| 4621 | |
| 4622 | /* If any dynamic relocs apply to a read-only section, |
| 4623 | then we need a DT_TEXTREL entry. */ |
| 4624 | if ((info->flags & DF_TEXTREL) == 0) |
| 4625 | elf_link_hash_traverse (&htab->root, readonly_dynrelocs, info); |
| 4626 | |
| 4627 | if ((info->flags & DF_TEXTREL) != 0) |
| 4628 | { |
| 4629 | if (! add_dynamic_entry (DT_TEXTREL, 0)) |
| 4630 | return FALSE; |
| 4631 | } |
| 4632 | } |
| 4633 | } |
| 4634 | #undef add_dynamic_entry |
| 4635 | |
| 4636 | return TRUE; |
| 4637 | } |
| 4638 | \f |
| 4639 | /* Relocate an SH ELF section. */ |
| 4640 | |
| 4641 | static bfd_boolean |
| 4642 | sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, |
| 4643 | bfd *input_bfd, asection *input_section, |
| 4644 | bfd_byte *contents, Elf_Internal_Rela *relocs, |
| 4645 | Elf_Internal_Sym *local_syms, |
| 4646 | asection **local_sections) |
| 4647 | { |
| 4648 | struct elf_sh_link_hash_table *htab; |
| 4649 | Elf_Internal_Shdr *symtab_hdr; |
| 4650 | struct elf_link_hash_entry **sym_hashes; |
| 4651 | Elf_Internal_Rela *rel, *relend; |
| 4652 | bfd *dynobj; |
| 4653 | bfd_vma *local_got_offsets; |
| 4654 | asection *sgot; |
| 4655 | asection *sgotplt; |
| 4656 | asection *splt; |
| 4657 | asection *sreloc; |
| 4658 | asection *srelgot; |
| 4659 | |
| 4660 | htab = sh_elf_hash_table (info); |
| 4661 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
| 4662 | sym_hashes = elf_sym_hashes (input_bfd); |
| 4663 | dynobj = htab->root.dynobj; |
| 4664 | local_got_offsets = elf_local_got_offsets (input_bfd); |
| 4665 | |
| 4666 | sgot = htab->sgot; |
| 4667 | sgotplt = htab->sgotplt; |
| 4668 | splt = htab->splt; |
| 4669 | sreloc = NULL; |
| 4670 | srelgot = NULL; |
| 4671 | |
| 4672 | rel = relocs; |
| 4673 | relend = relocs + input_section->reloc_count; |
| 4674 | for (; rel < relend; rel++) |
| 4675 | { |
| 4676 | int r_type; |
| 4677 | reloc_howto_type *howto; |
| 4678 | unsigned long r_symndx; |
| 4679 | Elf_Internal_Sym *sym; |
| 4680 | asection *sec; |
| 4681 | struct elf_link_hash_entry *h; |
| 4682 | bfd_vma relocation; |
| 4683 | bfd_vma addend = (bfd_vma) 0; |
| 4684 | bfd_reloc_status_type r; |
| 4685 | int seen_stt_datalabel = 0; |
| 4686 | bfd_vma off; |
| 4687 | int tls_type; |
| 4688 | |
| 4689 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 4690 | |
| 4691 | r_type = ELF32_R_TYPE (rel->r_info); |
| 4692 | |
| 4693 | /* Many of the relocs are only used for relaxing, and are |
| 4694 | handled entirely by the relaxation code. */ |
| 4695 | if (r_type >= (int) R_SH_GNU_VTINHERIT |
| 4696 | && r_type <= (int) R_SH_LABEL) |
| 4697 | continue; |
| 4698 | if (r_type == (int) R_SH_NONE) |
| 4699 | continue; |
| 4700 | |
| 4701 | if (r_type < 0 |
| 4702 | || r_type >= R_SH_max |
| 4703 | || (r_type >= (int) R_SH_FIRST_INVALID_RELOC |
| 4704 | && r_type <= (int) R_SH_LAST_INVALID_RELOC) |
| 4705 | || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_3 |
| 4706 | && r_type <= (int) R_SH_LAST_INVALID_RELOC_3) |
| 4707 | || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_4 |
| 4708 | && r_type <= (int) R_SH_LAST_INVALID_RELOC_4) |
| 4709 | || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_5 |
| 4710 | && r_type <= (int) R_SH_LAST_INVALID_RELOC_5) |
| 4711 | || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2 |
| 4712 | && r_type <= (int) R_SH_LAST_INVALID_RELOC_2)) |
| 4713 | { |
| 4714 | bfd_set_error (bfd_error_bad_value); |
| 4715 | return FALSE; |
| 4716 | } |
| 4717 | |
| 4718 | howto = sh_elf_howto_table + r_type; |
| 4719 | |
| 4720 | /* For relocs that aren't partial_inplace, we get the addend from |
| 4721 | the relocation. */ |
| 4722 | if (! howto->partial_inplace) |
| 4723 | addend = rel->r_addend; |
| 4724 | |
| 4725 | h = NULL; |
| 4726 | sym = NULL; |
| 4727 | sec = NULL; |
| 4728 | if (r_symndx < symtab_hdr->sh_info) |
| 4729 | { |
| 4730 | sym = local_syms + r_symndx; |
| 4731 | sec = local_sections[r_symndx]; |
| 4732 | relocation = (sec->output_section->vma |
| 4733 | + sec->output_offset |
| 4734 | + sym->st_value); |
| 4735 | /* A local symbol never has STO_SH5_ISA32, so we don't need |
| 4736 | datalabel processing here. Make sure this does not change |
| 4737 | without notice. */ |
| 4738 | if ((sym->st_other & STO_SH5_ISA32) != 0) |
| 4739 | ((*info->callbacks->reloc_dangerous) |
| 4740 | (info, |
| 4741 | _("Unexpected STO_SH5_ISA32 on local symbol is not handled"), |
| 4742 | input_bfd, input_section, rel->r_offset)); |
| 4743 | if (info->relocatable) |
| 4744 | { |
| 4745 | /* This is a relocatable link. We don't have to change |
| 4746 | anything, unless the reloc is against a section symbol, |
| 4747 | in which case we have to adjust according to where the |
| 4748 | section symbol winds up in the output section. */ |
| 4749 | sym = local_syms + r_symndx; |
| 4750 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) |
| 4751 | { |
| 4752 | if (! howto->partial_inplace) |
| 4753 | { |
| 4754 | /* For relocations with the addend in the |
| 4755 | relocation, we need just to update the addend. |
| 4756 | All real relocs are of type partial_inplace; this |
| 4757 | code is mostly for completeness. */ |
| 4758 | rel->r_addend += sec->output_offset + sym->st_value; |
| 4759 | |
| 4760 | continue; |
| 4761 | } |
| 4762 | |
| 4763 | /* Relocs of type partial_inplace need to pick up the |
| 4764 | contents in the contents and add the offset resulting |
| 4765 | from the changed location of the section symbol. |
| 4766 | Using _bfd_final_link_relocate (e.g. goto |
| 4767 | final_link_relocate) here would be wrong, because |
| 4768 | relocations marked pc_relative would get the current |
| 4769 | location subtracted, and we must only do that at the |
| 4770 | final link. */ |
| 4771 | r = _bfd_relocate_contents (howto, input_bfd, |
| 4772 | sec->output_offset |
| 4773 | + sym->st_value, |
| 4774 | contents + rel->r_offset); |
| 4775 | goto relocation_done; |
| 4776 | } |
| 4777 | |
| 4778 | continue; |
| 4779 | } |
| 4780 | else if (! howto->partial_inplace) |
| 4781 | { |
| 4782 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
| 4783 | addend = rel->r_addend; |
| 4784 | } |
| 4785 | else if ((sec->flags & SEC_MERGE) |
| 4786 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION) |
| 4787 | { |
| 4788 | asection *msec; |
| 4789 | |
| 4790 | if (howto->rightshift || howto->src_mask != 0xffffffff) |
| 4791 | { |
| 4792 | (*_bfd_error_handler) |
| 4793 | (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"), |
| 4794 | input_bfd, input_section, |
| 4795 | (long) rel->r_offset, howto->name); |
| 4796 | return FALSE; |
| 4797 | } |
| 4798 | |
| 4799 | addend = bfd_get_32 (input_bfd, contents + rel->r_offset); |
| 4800 | msec = sec; |
| 4801 | addend = |
| 4802 | _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) |
| 4803 | - relocation; |
| 4804 | addend += msec->output_section->vma + msec->output_offset; |
| 4805 | bfd_put_32 (input_bfd, addend, contents + rel->r_offset); |
| 4806 | addend = 0; |
| 4807 | } |
| 4808 | } |
| 4809 | else |
| 4810 | { |
| 4811 | /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro. */ |
| 4812 | |
| 4813 | /* Section symbol are never (?) placed in the hash table, so |
| 4814 | we can just ignore hash relocations when creating a |
| 4815 | relocatable object file. */ |
| 4816 | if (info->relocatable) |
| 4817 | continue; |
| 4818 | |
| 4819 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 4820 | while (h->root.type == bfd_link_hash_indirect |
| 4821 | || h->root.type == bfd_link_hash_warning) |
| 4822 | { |
| 4823 | #ifdef INCLUDE_SHMEDIA |
| 4824 | /* If the reference passes a symbol marked with |
| 4825 | STT_DATALABEL, then any STO_SH5_ISA32 on the final value |
| 4826 | doesn't count. */ |
| 4827 | seen_stt_datalabel |= h->type == STT_DATALABEL; |
| 4828 | #endif |
| 4829 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 4830 | } |
| 4831 | if (h->root.type == bfd_link_hash_defined |
| 4832 | || h->root.type == bfd_link_hash_defweak) |
| 4833 | { |
| 4834 | bfd_boolean dyn; |
| 4835 | |
| 4836 | dyn = htab->root.dynamic_sections_created; |
| 4837 | sec = h->root.u.def.section; |
| 4838 | /* In these cases, we don't need the relocation value. |
| 4839 | We check specially because in some obscure cases |
| 4840 | sec->output_section will be NULL. */ |
| 4841 | if (r_type == R_SH_GOTPC |
| 4842 | || r_type == R_SH_GOTPC_LOW16 |
| 4843 | || r_type == R_SH_GOTPC_MEDLOW16 |
| 4844 | || r_type == R_SH_GOTPC_MEDHI16 |
| 4845 | || r_type == R_SH_GOTPC_HI16 |
| 4846 | || ((r_type == R_SH_PLT32 |
| 4847 | || r_type == R_SH_PLT_LOW16 |
| 4848 | || r_type == R_SH_PLT_MEDLOW16 |
| 4849 | || r_type == R_SH_PLT_MEDHI16 |
| 4850 | || r_type == R_SH_PLT_HI16) |
| 4851 | && h->plt.offset != (bfd_vma) -1) |
| 4852 | || ((r_type == R_SH_GOT32 |
| 4853 | || r_type == R_SH_GOT_LOW16 |
| 4854 | || r_type == R_SH_GOT_MEDLOW16 |
| 4855 | || r_type == R_SH_GOT_MEDHI16 |
| 4856 | || r_type == R_SH_GOT_HI16) |
| 4857 | && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
| 4858 | && (! info->shared |
| 4859 | || (! info->symbolic && h->dynindx != -1) |
| 4860 | || !h->def_regular)) |
| 4861 | /* The cases above are those in which relocation is |
| 4862 | overwritten in the switch block below. The cases |
| 4863 | below are those in which we must defer relocation |
| 4864 | to run-time, because we can't resolve absolute |
| 4865 | addresses when creating a shared library. */ |
| 4866 | || (info->shared |
| 4867 | && ((! info->symbolic && h->dynindx != -1) |
| 4868 | || !h->def_regular) |
| 4869 | && ((r_type == R_SH_DIR32 |
| 4870 | && !h->forced_local) |
| 4871 | || r_type == R_SH_REL32) |
| 4872 | && ((input_section->flags & SEC_ALLOC) != 0 |
| 4873 | /* DWARF will emit R_SH_DIR32 relocations in its |
| 4874 | sections against symbols defined externally |
| 4875 | in shared libraries. We can't do anything |
| 4876 | with them here. */ |
| 4877 | || ((input_section->flags & SEC_DEBUGGING) != 0 |
| 4878 | && h->def_dynamic))) |
| 4879 | /* Dynamic relocs are not propagated for SEC_DEBUGGING |
| 4880 | sections because such sections are not SEC_ALLOC and |
| 4881 | thus ld.so will not process them. */ |
| 4882 | || (sec->output_section == NULL |
| 4883 | && ((input_section->flags & SEC_DEBUGGING) != 0 |
| 4884 | && h->def_dynamic)) |
| 4885 | || (sec->output_section == NULL |
| 4886 | && (sh_elf_hash_entry (h)->tls_type == GOT_TLS_IE |
| 4887 | || sh_elf_hash_entry (h)->tls_type == GOT_TLS_GD))) |
| 4888 | relocation = 0; |
| 4889 | else if (sec->output_section == NULL) |
| 4890 | { |
| 4891 | (*_bfd_error_handler) |
| 4892 | (_("%B(%A): unresolvable relocation against symbol `%s'"), |
| 4893 | input_bfd, input_section, h->root.root.string); |
| 4894 | return FALSE; |
| 4895 | } |
| 4896 | else |
| 4897 | relocation = ((h->root.u.def.value |
| 4898 | + sec->output_section->vma |
| 4899 | + sec->output_offset) |
| 4900 | /* A STO_SH5_ISA32 causes a "bitor 1" to the |
| 4901 | symbol value, unless we've seen |
| 4902 | STT_DATALABEL on the way to it. */ |
| 4903 | | ((h->other & STO_SH5_ISA32) != 0 |
| 4904 | && ! seen_stt_datalabel)); |
| 4905 | } |
| 4906 | else if (h->root.type == bfd_link_hash_undefweak) |
| 4907 | relocation = 0; |
| 4908 | else if (info->unresolved_syms_in_objects == RM_IGNORE |
| 4909 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
| 4910 | relocation = 0; |
| 4911 | else |
| 4912 | { |
| 4913 | if (! info->callbacks->undefined_symbol |
| 4914 | (info, h->root.root.string, input_bfd, |
| 4915 | input_section, rel->r_offset, |
| 4916 | (info->unresolved_syms_in_objects == RM_GENERATE_ERROR |
| 4917 | || ELF_ST_VISIBILITY (h->other)))) |
| 4918 | return FALSE; |
| 4919 | relocation = 0; |
| 4920 | } |
| 4921 | } |
| 4922 | |
| 4923 | switch ((int) r_type) |
| 4924 | { |
| 4925 | final_link_relocate: |
| 4926 | /* COFF relocs don't use the addend. The addend is used for |
| 4927 | R_SH_DIR32 to be compatible with other compilers. */ |
| 4928 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 4929 | contents, rel->r_offset, |
| 4930 | relocation, addend); |
| 4931 | break; |
| 4932 | |
| 4933 | case R_SH_IND12W: |
| 4934 | goto final_link_relocate; |
| 4935 | |
| 4936 | case R_SH_DIR8WPN: |
| 4937 | case R_SH_DIR8WPZ: |
| 4938 | case R_SH_DIR8WPL: |
| 4939 | /* If the reloc is against the start of this section, then |
| 4940 | the assembler has already taken care of it and the reloc |
| 4941 | is here only to assist in relaxing. If the reloc is not |
| 4942 | against the start of this section, then it's against an |
| 4943 | external symbol and we must deal with it ourselves. */ |
| 4944 | if (input_section->output_section->vma + input_section->output_offset |
| 4945 | != relocation) |
| 4946 | { |
| 4947 | int disp = (relocation |
| 4948 | - input_section->output_section->vma |
| 4949 | - input_section->output_offset |
| 4950 | - rel->r_offset); |
| 4951 | int mask = 0; |
| 4952 | switch (r_type) |
| 4953 | { |
| 4954 | case R_SH_DIR8WPN: |
| 4955 | case R_SH_DIR8WPZ: mask = 1; break; |
| 4956 | case R_SH_DIR8WPL: mask = 3; break; |
| 4957 | default: mask = 0; break; |
| 4958 | } |
| 4959 | if (disp & mask) |
| 4960 | { |
| 4961 | ((*_bfd_error_handler) |
| 4962 | (_("%B: 0x%lx: fatal: unaligned branch target for relax-support relocation"), |
| 4963 | input_section->owner, |
| 4964 | (unsigned long) rel->r_offset)); |
| 4965 | bfd_set_error (bfd_error_bad_value); |
| 4966 | return FALSE; |
| 4967 | } |
| 4968 | relocation -= 4; |
| 4969 | goto final_link_relocate; |
| 4970 | } |
| 4971 | r = bfd_reloc_ok; |
| 4972 | break; |
| 4973 | |
| 4974 | default: |
| 4975 | #ifdef INCLUDE_SHMEDIA |
| 4976 | if (shmedia_prepare_reloc (info, input_bfd, input_section, |
| 4977 | contents, rel, &relocation)) |
| 4978 | goto final_link_relocate; |
| 4979 | #endif |
| 4980 | bfd_set_error (bfd_error_bad_value); |
| 4981 | return FALSE; |
| 4982 | |
| 4983 | case R_SH_DIR16: |
| 4984 | case R_SH_DIR8: |
| 4985 | case R_SH_DIR8U: |
| 4986 | case R_SH_DIR8S: |
| 4987 | case R_SH_DIR4U: |
| 4988 | goto final_link_relocate; |
| 4989 | |
| 4990 | case R_SH_DIR8UL: |
| 4991 | case R_SH_DIR4UL: |
| 4992 | if (relocation & 3) |
| 4993 | { |
| 4994 | ((*_bfd_error_handler) |
| 4995 | (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"), |
| 4996 | input_section->owner, |
| 4997 | (unsigned long) rel->r_offset, howto->name, |
| 4998 | (unsigned long) relocation)); |
| 4999 | bfd_set_error (bfd_error_bad_value); |
| 5000 | return FALSE; |
| 5001 | } |
| 5002 | goto final_link_relocate; |
| 5003 | |
| 5004 | case R_SH_DIR8UW: |
| 5005 | case R_SH_DIR8SW: |
| 5006 | case R_SH_DIR4UW: |
| 5007 | if (relocation & 1) |
| 5008 | { |
| 5009 | ((*_bfd_error_handler) |
| 5010 | (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"), |
| 5011 | input_section->owner, |
| 5012 | (unsigned long) rel->r_offset, howto->name, |
| 5013 | (unsigned long) relocation)); |
| 5014 | bfd_set_error (bfd_error_bad_value); |
| 5015 | return FALSE; |
| 5016 | } |
| 5017 | goto final_link_relocate; |
| 5018 | |
| 5019 | case R_SH_PSHA: |
| 5020 | if ((signed int)relocation < -32 |
| 5021 | || (signed int)relocation > 32) |
| 5022 | { |
| 5023 | ((*_bfd_error_handler) |
| 5024 | (_("%B: 0x%lx: fatal: R_SH_PSHA relocation %d not in range -32..32"), |
| 5025 | input_section->owner, |
| 5026 | (unsigned long) rel->r_offset, |
| 5027 | (unsigned long) relocation)); |
| 5028 | bfd_set_error (bfd_error_bad_value); |
| 5029 | return FALSE; |
| 5030 | } |
| 5031 | goto final_link_relocate; |
| 5032 | |
| 5033 | case R_SH_PSHL: |
| 5034 | if ((signed int)relocation < -16 |
| 5035 | || (signed int)relocation > 16) |
| 5036 | { |
| 5037 | ((*_bfd_error_handler) |
| 5038 | (_("%B: 0x%lx: fatal: R_SH_PSHL relocation %d not in range -32..32"), |
| 5039 | input_section->owner, |
| 5040 | (unsigned long) rel->r_offset, |
| 5041 | (unsigned long) relocation)); |
| 5042 | bfd_set_error (bfd_error_bad_value); |
| 5043 | return FALSE; |
| 5044 | } |
| 5045 | goto final_link_relocate; |
| 5046 | |
| 5047 | case R_SH_DIR32: |
| 5048 | case R_SH_REL32: |
| 5049 | #ifdef INCLUDE_SHMEDIA |
| 5050 | case R_SH_IMM_LOW16_PCREL: |
| 5051 | case R_SH_IMM_MEDLOW16_PCREL: |
| 5052 | case R_SH_IMM_MEDHI16_PCREL: |
| 5053 | case R_SH_IMM_HI16_PCREL: |
| 5054 | #endif |
| 5055 | if (info->shared |
| 5056 | && (h == NULL |
| 5057 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
| 5058 | || h->root.type != bfd_link_hash_undefweak) |
| 5059 | && r_symndx != 0 |
| 5060 | && (input_section->flags & SEC_ALLOC) != 0 |
| 5061 | && (r_type == R_SH_DIR32 |
| 5062 | || !SYMBOL_CALLS_LOCAL (info, h))) |
| 5063 | { |
| 5064 | Elf_Internal_Rela outrel; |
| 5065 | bfd_byte *loc; |
| 5066 | bfd_boolean skip, relocate; |
| 5067 | |
| 5068 | /* When generating a shared object, these relocations |
| 5069 | are copied into the output file to be resolved at run |
| 5070 | time. */ |
| 5071 | |
| 5072 | if (sreloc == NULL) |
| 5073 | { |
| 5074 | const char *name; |
| 5075 | |
| 5076 | name = (bfd_elf_string_from_elf_section |
| 5077 | (input_bfd, |
| 5078 | elf_elfheader (input_bfd)->e_shstrndx, |
| 5079 | elf_section_data (input_section)->rel_hdr.sh_name)); |
| 5080 | if (name == NULL) |
| 5081 | return FALSE; |
| 5082 | |
| 5083 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 |
| 5084 | && strcmp (bfd_get_section_name (input_bfd, |
| 5085 | input_section), |
| 5086 | name + 5) == 0); |
| 5087 | |
| 5088 | sreloc = bfd_get_section_by_name (dynobj, name); |
| 5089 | BFD_ASSERT (sreloc != NULL); |
| 5090 | } |
| 5091 | |
| 5092 | skip = FALSE; |
| 5093 | relocate = FALSE; |
| 5094 | |
| 5095 | outrel.r_offset = |
| 5096 | _bfd_elf_section_offset (output_bfd, info, input_section, |
| 5097 | rel->r_offset); |
| 5098 | if (outrel.r_offset == (bfd_vma) -1) |
| 5099 | skip = TRUE; |
| 5100 | else if (outrel.r_offset == (bfd_vma) -2) |
| 5101 | skip = TRUE, relocate = TRUE; |
| 5102 | outrel.r_offset += (input_section->output_section->vma |
| 5103 | + input_section->output_offset); |
| 5104 | |
| 5105 | if (skip) |
| 5106 | memset (&outrel, 0, sizeof outrel); |
| 5107 | else if (r_type == R_SH_REL32) |
| 5108 | { |
| 5109 | BFD_ASSERT (h != NULL && h->dynindx != -1); |
| 5110 | outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32); |
| 5111 | outrel.r_addend |
| 5112 | = bfd_get_32 (input_bfd, contents + rel->r_offset); |
| 5113 | } |
| 5114 | #ifdef INCLUDE_SHMEDIA |
| 5115 | else if (r_type == R_SH_IMM_LOW16_PCREL |
| 5116 | || r_type == R_SH_IMM_MEDLOW16_PCREL |
| 5117 | || r_type == R_SH_IMM_MEDHI16_PCREL |
| 5118 | || r_type == R_SH_IMM_HI16_PCREL) |
| 5119 | { |
| 5120 | BFD_ASSERT (h != NULL && h->dynindx != -1); |
| 5121 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
| 5122 | outrel.r_addend = addend; |
| 5123 | } |
| 5124 | #endif |
| 5125 | else |
| 5126 | { |
| 5127 | /* h->dynindx may be -1 if this symbol was marked to |
| 5128 | become local. */ |
| 5129 | if (h == NULL |
| 5130 | || ((info->symbolic || h->dynindx == -1) |
| 5131 | && h->def_regular)) |
| 5132 | { |
| 5133 | relocate = TRUE; |
| 5134 | outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE); |
| 5135 | outrel.r_addend |
| 5136 | = relocation + bfd_get_32 (input_bfd, |
| 5137 | contents + rel->r_offset); |
| 5138 | } |
| 5139 | else |
| 5140 | { |
| 5141 | BFD_ASSERT (h->dynindx != -1); |
| 5142 | outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32); |
| 5143 | outrel.r_addend |
| 5144 | = relocation + bfd_get_32 (input_bfd, |
| 5145 | contents + rel->r_offset); |
| 5146 | } |
| 5147 | } |
| 5148 | |
| 5149 | loc = sreloc->contents; |
| 5150 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); |
| 5151 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
| 5152 | |
| 5153 | /* If this reloc is against an external symbol, we do |
| 5154 | not want to fiddle with the addend. Otherwise, we |
| 5155 | need to include the symbol value so that it becomes |
| 5156 | an addend for the dynamic reloc. */ |
| 5157 | if (! relocate) |
| 5158 | continue; |
| 5159 | } |
| 5160 | goto final_link_relocate; |
| 5161 | |
| 5162 | case R_SH_GOTPLT32: |
| 5163 | #ifdef INCLUDE_SHMEDIA |
| 5164 | case R_SH_GOTPLT_LOW16: |
| 5165 | case R_SH_GOTPLT_MEDLOW16: |
| 5166 | case R_SH_GOTPLT_MEDHI16: |
| 5167 | case R_SH_GOTPLT_HI16: |
| 5168 | case R_SH_GOTPLT10BY4: |
| 5169 | case R_SH_GOTPLT10BY8: |
| 5170 | #endif |
| 5171 | /* Relocation is to the entry for this symbol in the |
| 5172 | procedure linkage table. */ |
| 5173 | |
| 5174 | if (h == NULL |
| 5175 | || h->forced_local |
| 5176 | || ! info->shared |
| 5177 | || info->symbolic |
| 5178 | || h->dynindx == -1 |
| 5179 | || h->plt.offset == (bfd_vma) -1 |
| 5180 | || h->got.offset != (bfd_vma) -1) |
| 5181 | goto force_got; |
| 5182 | |
| 5183 | /* Relocation is to the entry for this symbol in the global |
| 5184 | offset table extension for the procedure linkage table. */ |
| 5185 | |
| 5186 | BFD_ASSERT (sgotplt != NULL); |
| 5187 | relocation = (sgotplt->output_offset |
| 5188 | + ((h->plt.offset / elf_sh_sizeof_plt (info) |
| 5189 | - 1 + 3) * 4)); |
| 5190 | |
| 5191 | #ifdef GOT_BIAS |
| 5192 | relocation -= GOT_BIAS; |
| 5193 | #endif |
| 5194 | |
| 5195 | goto final_link_relocate; |
| 5196 | |
| 5197 | force_got: |
| 5198 | case R_SH_GOT32: |
| 5199 | #ifdef INCLUDE_SHMEDIA |
| 5200 | case R_SH_GOT_LOW16: |
| 5201 | case R_SH_GOT_MEDLOW16: |
| 5202 | case R_SH_GOT_MEDHI16: |
| 5203 | case R_SH_GOT_HI16: |
| 5204 | case R_SH_GOT10BY4: |
| 5205 | case R_SH_GOT10BY8: |
| 5206 | #endif |
| 5207 | /* Relocation is to the entry for this symbol in the global |
| 5208 | offset table. */ |
| 5209 | |
| 5210 | BFD_ASSERT (sgot != NULL); |
| 5211 | |
| 5212 | if (h != NULL) |
| 5213 | { |
| 5214 | bfd_boolean dyn; |
| 5215 | |
| 5216 | off = h->got.offset; |
| 5217 | #ifdef INCLUDE_SHMEDIA |
| 5218 | if (seen_stt_datalabel) |
| 5219 | { |
| 5220 | struct elf_sh_link_hash_entry *hsh; |
| 5221 | |
| 5222 | hsh = (struct elf_sh_link_hash_entry *)h; |
| 5223 | off = hsh->datalabel_got.offset; |
| 5224 | } |
| 5225 | #endif |
| 5226 | BFD_ASSERT (off != (bfd_vma) -1); |
| 5227 | |
| 5228 | dyn = htab->root.dynamic_sections_created; |
| 5229 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
| 5230 | || (info->shared |
| 5231 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
| 5232 | || (ELF_ST_VISIBILITY (h->other) |
| 5233 | && h->root.type == bfd_link_hash_undefweak)) |
| 5234 | { |
| 5235 | /* This is actually a static link, or it is a |
| 5236 | -Bsymbolic link and the symbol is defined |
| 5237 | locally, or the symbol was forced to be local |
| 5238 | because of a version file. We must initialize |
| 5239 | this entry in the global offset table. Since the |
| 5240 | offset must always be a multiple of 4, we use the |
| 5241 | least significant bit to record whether we have |
| 5242 | initialized it already. |
| 5243 | |
| 5244 | When doing a dynamic link, we create a .rela.got |
| 5245 | relocation entry to initialize the value. This |
| 5246 | is done in the finish_dynamic_symbol routine. */ |
| 5247 | if ((off & 1) != 0) |
| 5248 | off &= ~1; |
| 5249 | else |
| 5250 | { |
| 5251 | bfd_put_32 (output_bfd, relocation, |
| 5252 | sgot->contents + off); |
| 5253 | #ifdef INCLUDE_SHMEDIA |
| 5254 | if (seen_stt_datalabel) |
| 5255 | { |
| 5256 | struct elf_sh_link_hash_entry *hsh; |
| 5257 | |
| 5258 | hsh = (struct elf_sh_link_hash_entry *)h; |
| 5259 | hsh->datalabel_got.offset |= 1; |
| 5260 | } |
| 5261 | else |
| 5262 | #endif |
| 5263 | h->got.offset |= 1; |
| 5264 | } |
| 5265 | } |
| 5266 | |
| 5267 | relocation = sgot->output_offset + off; |
| 5268 | } |
| 5269 | else |
| 5270 | { |
| 5271 | #ifdef INCLUDE_SHMEDIA |
| 5272 | if (rel->r_addend) |
| 5273 | { |
| 5274 | BFD_ASSERT (local_got_offsets != NULL |
| 5275 | && (local_got_offsets[symtab_hdr->sh_info |
| 5276 | + r_symndx] |
| 5277 | != (bfd_vma) -1)); |
| 5278 | |
| 5279 | off = local_got_offsets[symtab_hdr->sh_info |
| 5280 | + r_symndx]; |
| 5281 | } |
| 5282 | else |
| 5283 | { |
| 5284 | #endif |
| 5285 | BFD_ASSERT (local_got_offsets != NULL |
| 5286 | && local_got_offsets[r_symndx] != (bfd_vma) -1); |
| 5287 | |
| 5288 | off = local_got_offsets[r_symndx]; |
| 5289 | #ifdef INCLUDE_SHMEDIA |
| 5290 | } |
| 5291 | #endif |
| 5292 | |
| 5293 | /* The offset must always be a multiple of 4. We use |
| 5294 | the least significant bit to record whether we have |
| 5295 | already generated the necessary reloc. */ |
| 5296 | if ((off & 1) != 0) |
| 5297 | off &= ~1; |
| 5298 | else |
| 5299 | { |
| 5300 | bfd_put_32 (output_bfd, relocation, sgot->contents + off); |
| 5301 | |
| 5302 | if (info->shared) |
| 5303 | { |
| 5304 | Elf_Internal_Rela outrel; |
| 5305 | bfd_byte *loc; |
| 5306 | |
| 5307 | if (srelgot == NULL) |
| 5308 | { |
| 5309 | srelgot = bfd_get_section_by_name (dynobj, |
| 5310 | ".rela.got"); |
| 5311 | BFD_ASSERT (srelgot != NULL); |
| 5312 | } |
| 5313 | |
| 5314 | outrel.r_offset = (sgot->output_section->vma |
| 5315 | + sgot->output_offset |
| 5316 | + off); |
| 5317 | outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE); |
| 5318 | outrel.r_addend = relocation; |
| 5319 | loc = srelgot->contents; |
| 5320 | loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela); |
| 5321 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
| 5322 | } |
| 5323 | |
| 5324 | #ifdef INCLUDE_SHMEDIA |
| 5325 | if (rel->r_addend) |
| 5326 | local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1; |
| 5327 | else |
| 5328 | #endif |
| 5329 | local_got_offsets[r_symndx] |= 1; |
| 5330 | } |
| 5331 | |
| 5332 | relocation = sgot->output_offset + off; |
| 5333 | } |
| 5334 | |
| 5335 | #ifdef GOT_BIAS |
| 5336 | relocation -= GOT_BIAS; |
| 5337 | #endif |
| 5338 | |
| 5339 | goto final_link_relocate; |
| 5340 | |
| 5341 | case R_SH_GOTOFF: |
| 5342 | #ifdef INCLUDE_SHMEDIA |
| 5343 | case R_SH_GOTOFF_LOW16: |
| 5344 | case R_SH_GOTOFF_MEDLOW16: |
| 5345 | case R_SH_GOTOFF_MEDHI16: |
| 5346 | case R_SH_GOTOFF_HI16: |
| 5347 | #endif |
| 5348 | /* Relocation is relative to the start of the global offset |
| 5349 | table. */ |
| 5350 | |
| 5351 | BFD_ASSERT (sgot != NULL); |
| 5352 | |
| 5353 | /* Note that sgot->output_offset is not involved in this |
| 5354 | calculation. We always want the start of .got. If we |
| 5355 | defined _GLOBAL_OFFSET_TABLE in a different way, as is |
| 5356 | permitted by the ABI, we might have to change this |
| 5357 | calculation. */ |
| 5358 | relocation -= sgot->output_section->vma; |
| 5359 | |
| 5360 | #ifdef GOT_BIAS |
| 5361 | relocation -= GOT_BIAS; |
| 5362 | #endif |
| 5363 | |
| 5364 | addend = rel->r_addend; |
| 5365 | |
| 5366 | goto final_link_relocate; |
| 5367 | |
| 5368 | case R_SH_GOTPC: |
| 5369 | #ifdef INCLUDE_SHMEDIA |
| 5370 | case R_SH_GOTPC_LOW16: |
| 5371 | case R_SH_GOTPC_MEDLOW16: |
| 5372 | case R_SH_GOTPC_MEDHI16: |
| 5373 | case R_SH_GOTPC_HI16: |
| 5374 | #endif |
| 5375 | /* Use global offset table as symbol value. */ |
| 5376 | |
| 5377 | BFD_ASSERT (sgot != NULL); |
| 5378 | relocation = sgot->output_section->vma; |
| 5379 | |
| 5380 | #ifdef GOT_BIAS |
| 5381 | relocation += GOT_BIAS; |
| 5382 | #endif |
| 5383 | |
| 5384 | addend = rel->r_addend; |
| 5385 | |
| 5386 | goto final_link_relocate; |
| 5387 | |
| 5388 | case R_SH_PLT32: |
| 5389 | #ifdef INCLUDE_SHMEDIA |
| 5390 | case R_SH_PLT_LOW16: |
| 5391 | case R_SH_PLT_MEDLOW16: |
| 5392 | case R_SH_PLT_MEDHI16: |
| 5393 | case R_SH_PLT_HI16: |
| 5394 | #endif |
| 5395 | /* Relocation is to the entry for this symbol in the |
| 5396 | procedure linkage table. */ |
| 5397 | |
| 5398 | /* Resolve a PLT reloc against a local symbol directly, |
| 5399 | without using the procedure linkage table. */ |
| 5400 | if (h == NULL) |
| 5401 | goto final_link_relocate; |
| 5402 | |
| 5403 | if (h->forced_local) |
| 5404 | goto final_link_relocate; |
| 5405 | |
| 5406 | if (h->plt.offset == (bfd_vma) -1) |
| 5407 | { |
| 5408 | /* We didn't make a PLT entry for this symbol. This |
| 5409 | happens when statically linking PIC code, or when |
| 5410 | using -Bsymbolic. */ |
| 5411 | goto final_link_relocate; |
| 5412 | } |
| 5413 | |
| 5414 | BFD_ASSERT (splt != NULL); |
| 5415 | relocation = (splt->output_section->vma |
| 5416 | + splt->output_offset |
| 5417 | + h->plt.offset); |
| 5418 | |
| 5419 | #ifdef INCLUDE_SHMEDIA |
| 5420 | relocation++; |
| 5421 | #endif |
| 5422 | |
| 5423 | addend = rel->r_addend; |
| 5424 | |
| 5425 | goto final_link_relocate; |
| 5426 | |
| 5427 | case R_SH_LOOP_START: |
| 5428 | { |
| 5429 | static bfd_vma start, end; |
| 5430 | |
| 5431 | start = (relocation + rel->r_addend |
| 5432 | - (sec->output_section->vma + sec->output_offset)); |
| 5433 | r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents, |
| 5434 | rel->r_offset, sec, start, end); |
| 5435 | break; |
| 5436 | |
| 5437 | case R_SH_LOOP_END: |
| 5438 | end = (relocation + rel->r_addend |
| 5439 | - (sec->output_section->vma + sec->output_offset)); |
| 5440 | r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents, |
| 5441 | rel->r_offset, sec, start, end); |
| 5442 | break; |
| 5443 | } |
| 5444 | |
| 5445 | case R_SH_TLS_GD_32: |
| 5446 | case R_SH_TLS_IE_32: |
| 5447 | r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL); |
| 5448 | tls_type = GOT_UNKNOWN; |
| 5449 | if (h == NULL && local_got_offsets) |
| 5450 | tls_type = sh_elf_local_got_tls_type (input_bfd) [r_symndx]; |
| 5451 | else if (h != NULL) |
| 5452 | { |
| 5453 | tls_type = sh_elf_hash_entry (h)->tls_type; |
| 5454 | if (! info->shared |
| 5455 | && (h->dynindx == -1 |
| 5456 | || h->def_regular)) |
| 5457 | r_type = R_SH_TLS_LE_32; |
| 5458 | } |
| 5459 | |
| 5460 | if (r_type == R_SH_TLS_GD_32 && tls_type == GOT_TLS_IE) |
| 5461 | r_type = R_SH_TLS_IE_32; |
| 5462 | |
| 5463 | if (r_type == R_SH_TLS_LE_32) |
| 5464 | { |
| 5465 | bfd_vma offset; |
| 5466 | unsigned short insn; |
| 5467 | |
| 5468 | if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32) |
| 5469 | { |
| 5470 | /* GD->LE transition: |
| 5471 | mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1; |
| 5472 | jsr @r1; add r12,r4; bra 3f; nop; .align 2; |
| 5473 | 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3: |
| 5474 | We change it into: |
| 5475 | mov.l 1f,r4; stc gbr,r0; add r4,r0; nop; |
| 5476 | nop; nop; ... |
| 5477 | 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */ |
| 5478 | |
| 5479 | offset = rel->r_offset; |
| 5480 | BFD_ASSERT (offset >= 16); |
| 5481 | /* Size of GD instructions is 16 or 18. */ |
| 5482 | offset -= 16; |
| 5483 | insn = bfd_get_16 (input_bfd, contents + offset + 0); |
| 5484 | if ((insn & 0xff00) == 0xc700) |
| 5485 | { |
| 5486 | BFD_ASSERT (offset >= 2); |
| 5487 | offset -= 2; |
| 5488 | insn = bfd_get_16 (input_bfd, contents + offset + 0); |
| 5489 | } |
| 5490 | |
| 5491 | BFD_ASSERT ((insn & 0xff00) == 0xd400); |
| 5492 | insn = bfd_get_16 (input_bfd, contents + offset + 2); |
| 5493 | BFD_ASSERT ((insn & 0xff00) == 0xc700); |
| 5494 | insn = bfd_get_16 (input_bfd, contents + offset + 4); |
| 5495 | BFD_ASSERT ((insn & 0xff00) == 0xd100); |
| 5496 | insn = bfd_get_16 (input_bfd, contents + offset + 6); |
| 5497 | BFD_ASSERT (insn == 0x310c); |
| 5498 | insn = bfd_get_16 (input_bfd, contents + offset + 8); |
| 5499 | BFD_ASSERT (insn == 0x410b); |
| 5500 | insn = bfd_get_16 (input_bfd, contents + offset + 10); |
| 5501 | BFD_ASSERT (insn == 0x34cc); |
| 5502 | |
| 5503 | bfd_put_16 (output_bfd, 0x0012, contents + offset + 2); |
| 5504 | bfd_put_16 (output_bfd, 0x304c, contents + offset + 4); |
| 5505 | bfd_put_16 (output_bfd, 0x0009, contents + offset + 6); |
| 5506 | bfd_put_16 (output_bfd, 0x0009, contents + offset + 8); |
| 5507 | bfd_put_16 (output_bfd, 0x0009, contents + offset + 10); |
| 5508 | } |
| 5509 | else |
| 5510 | { |
| 5511 | int index; |
| 5512 | |
| 5513 | /* IE->LE transition: |
| 5514 | mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM; |
| 5515 | bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2: |
| 5516 | We change it into: |
| 5517 | mov.l .Ln,rM; stc gbr,rN; nop; ...; |
| 5518 | 1: x@TPOFF; 2:. */ |
| 5519 | |
| 5520 | offset = rel->r_offset; |
| 5521 | BFD_ASSERT (offset >= 16); |
| 5522 | /* Size of IE instructions is 10 or 12. */ |
| 5523 | offset -= 10; |
| 5524 | insn = bfd_get_16 (input_bfd, contents + offset + 0); |
| 5525 | if ((insn & 0xf0ff) == 0x0012) |
| 5526 | { |
| 5527 | BFD_ASSERT (offset >= 2); |
| 5528 | offset -= 2; |
| 5529 | insn = bfd_get_16 (input_bfd, contents + offset + 0); |
| 5530 | } |
| 5531 | |
| 5532 | BFD_ASSERT ((insn & 0xff00) == 0xd000); |
| 5533 | index = insn & 0x00ff; |
| 5534 | insn = bfd_get_16 (input_bfd, contents + offset + 2); |
| 5535 | BFD_ASSERT ((insn & 0xf0ff) == 0x0012); |
| 5536 | insn = bfd_get_16 (input_bfd, contents + offset + 4); |
| 5537 | BFD_ASSERT ((insn & 0xf0ff) == 0x00ce); |
| 5538 | insn = 0xd000 | (insn & 0x0f00) | index; |
| 5539 | bfd_put_16 (output_bfd, insn, contents + offset + 0); |
| 5540 | bfd_put_16 (output_bfd, 0x0009, contents + offset + 4); |
| 5541 | } |
| 5542 | |
| 5543 | bfd_put_32 (output_bfd, tpoff (info, relocation), |
| 5544 | contents + rel->r_offset); |
| 5545 | continue; |
| 5546 | } |
| 5547 | |
| 5548 | sgot = htab->sgot; |
| 5549 | if (sgot == NULL) |
| 5550 | abort (); |
| 5551 | |
| 5552 | if (h != NULL) |
| 5553 | off = h->got.offset; |
| 5554 | else |
| 5555 | { |
| 5556 | if (local_got_offsets == NULL) |
| 5557 | abort (); |
| 5558 | |
| 5559 | off = local_got_offsets[r_symndx]; |
| 5560 | } |
| 5561 | |
| 5562 | /* Relocate R_SH_TLS_IE_32 directly when statically linking. */ |
| 5563 | if (r_type == R_SH_TLS_IE_32 |
| 5564 | && ! htab->root.dynamic_sections_created) |
| 5565 | { |
| 5566 | off &= ~1; |
| 5567 | bfd_put_32 (output_bfd, tpoff (info, relocation), |
| 5568 | sgot->contents + off); |
| 5569 | bfd_put_32 (output_bfd, sgot->output_offset + off, |
| 5570 | contents + rel->r_offset); |
| 5571 | continue; |
| 5572 | } |
| 5573 | |
| 5574 | if ((off & 1) != 0) |
| 5575 | off &= ~1; |
| 5576 | else |
| 5577 | { |
| 5578 | Elf_Internal_Rela outrel; |
| 5579 | bfd_byte *loc; |
| 5580 | int dr_type, indx; |
| 5581 | |
| 5582 | if (srelgot == NULL) |
| 5583 | { |
| 5584 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 5585 | BFD_ASSERT (srelgot != NULL); |
| 5586 | } |
| 5587 | |
| 5588 | outrel.r_offset = (sgot->output_section->vma |
| 5589 | + sgot->output_offset + off); |
| 5590 | |
| 5591 | if (h == NULL || h->dynindx == -1) |
| 5592 | indx = 0; |
| 5593 | else |
| 5594 | indx = h->dynindx; |
| 5595 | |
| 5596 | dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 : |
| 5597 | R_SH_TLS_TPOFF32); |
| 5598 | if (dr_type == R_SH_TLS_TPOFF32 && indx == 0) |
| 5599 | outrel.r_addend = relocation - dtpoff_base (info); |
| 5600 | else |
| 5601 | outrel.r_addend = 0; |
| 5602 | outrel.r_info = ELF32_R_INFO (indx, dr_type); |
| 5603 | loc = srelgot->contents; |
| 5604 | loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela); |
| 5605 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
| 5606 | |
| 5607 | if (r_type == R_SH_TLS_GD_32) |
| 5608 | { |
| 5609 | if (indx == 0) |
| 5610 | { |
| 5611 | bfd_put_32 (output_bfd, |
| 5612 | relocation - dtpoff_base (info), |
| 5613 | sgot->contents + off + 4); |
| 5614 | } |
| 5615 | else |
| 5616 | { |
| 5617 | outrel.r_info = ELF32_R_INFO (indx, |
| 5618 | R_SH_TLS_DTPOFF32); |
| 5619 | outrel.r_offset += 4; |
| 5620 | outrel.r_addend = 0; |
| 5621 | srelgot->reloc_count++; |
| 5622 | loc += sizeof (Elf32_External_Rela); |
| 5623 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
| 5624 | } |
| 5625 | } |
| 5626 | |
| 5627 | if (h != NULL) |
| 5628 | h->got.offset |= 1; |
| 5629 | else |
| 5630 | local_got_offsets[r_symndx] |= 1; |
| 5631 | } |
| 5632 | |
| 5633 | if (off >= (bfd_vma) -2) |
| 5634 | abort (); |
| 5635 | |
| 5636 | if (r_type == (int) ELF32_R_TYPE (rel->r_info)) |
| 5637 | relocation = sgot->output_offset + off; |
| 5638 | else |
| 5639 | { |
| 5640 | bfd_vma offset; |
| 5641 | unsigned short insn; |
| 5642 | |
| 5643 | /* GD->IE transition: |
| 5644 | mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1; |
| 5645 | jsr @r1; add r12,r4; bra 3f; nop; .align 2; |
| 5646 | 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3: |
| 5647 | We change it into: |
| 5648 | mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0; |
| 5649 | nop; nop; bra 3f; nop; .align 2; |
| 5650 | 1: .long x@TPOFF; 2:...; 3:. */ |
| 5651 | |
| 5652 | offset = rel->r_offset; |
| 5653 | BFD_ASSERT (offset >= 16); |
| 5654 | /* Size of GD instructions is 16 or 18. */ |
| 5655 | offset -= 16; |
| 5656 | insn = bfd_get_16 (input_bfd, contents + offset + 0); |
| 5657 | if ((insn & 0xff00) == 0xc700) |
| 5658 | { |
| 5659 | BFD_ASSERT (offset >= 2); |
| 5660 | offset -= 2; |
| 5661 | insn = bfd_get_16 (input_bfd, contents + offset + 0); |
| 5662 | } |
| 5663 | |
| 5664 | BFD_ASSERT ((insn & 0xff00) == 0xd400); |
| 5665 | |
| 5666 | /* Replace mov.l 1f,R4 with mov.l 1f,r0. */ |
| 5667 | bfd_put_16 (output_bfd, insn & 0xf0ff, contents + offset); |
| 5668 | |
| 5669 | insn = bfd_get_16 (input_bfd, contents + offset + 2); |
| 5670 | BFD_ASSERT ((insn & 0xff00) == 0xc700); |
| 5671 | insn = bfd_get_16 (input_bfd, contents + offset + 4); |
| 5672 | BFD_ASSERT ((insn & 0xff00) == 0xd100); |
| 5673 | insn = bfd_get_16 (input_bfd, contents + offset + 6); |
| 5674 | BFD_ASSERT (insn == 0x310c); |
| 5675 | insn = bfd_get_16 (input_bfd, contents + offset + 8); |
| 5676 | BFD_ASSERT (insn == 0x410b); |
| 5677 | insn = bfd_get_16 (input_bfd, contents + offset + 10); |
| 5678 | BFD_ASSERT (insn == 0x34cc); |
| 5679 | |
| 5680 | bfd_put_16 (output_bfd, 0x0412, contents + offset + 2); |
| 5681 | bfd_put_16 (output_bfd, 0x00ce, contents + offset + 4); |
| 5682 | bfd_put_16 (output_bfd, 0x304c, contents + offset + 6); |
| 5683 | bfd_put_16 (output_bfd, 0x0009, contents + offset + 8); |
| 5684 | bfd_put_16 (output_bfd, 0x0009, contents + offset + 10); |
| 5685 | |
| 5686 | bfd_put_32 (output_bfd, sgot->output_offset + off, |
| 5687 | contents + rel->r_offset); |
| 5688 | |
| 5689 | continue; |
| 5690 | } |
| 5691 | |
| 5692 | addend = rel->r_addend; |
| 5693 | |
| 5694 | goto final_link_relocate; |
| 5695 | |
| 5696 | case R_SH_TLS_LD_32: |
| 5697 | if (! info->shared) |
| 5698 | { |
| 5699 | bfd_vma offset; |
| 5700 | unsigned short insn; |
| 5701 | |
| 5702 | /* LD->LE transition: |
| 5703 | mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1; |
| 5704 | jsr @r1; add r12,r4; bra 3f; nop; .align 2; |
| 5705 | 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3: |
| 5706 | We change it into: |
| 5707 | stc gbr,r0; nop; nop; nop; |
| 5708 | nop; nop; bra 3f; ...; 3:. */ |
| 5709 | |
| 5710 | offset = rel->r_offset; |
| 5711 | BFD_ASSERT (offset >= 16); |
| 5712 | /* Size of LD instructions is 16 or 18. */ |
| 5713 | offset -= 16; |
| 5714 | insn = bfd_get_16 (input_bfd, contents + offset + 0); |
| 5715 | if ((insn & 0xff00) == 0xc700) |
| 5716 | { |
| 5717 | BFD_ASSERT (offset >= 2); |
| 5718 | offset -= 2; |
| 5719 | insn = bfd_get_16 (input_bfd, contents + offset + 0); |
| 5720 | } |
| 5721 | |
| 5722 | BFD_ASSERT ((insn & 0xff00) == 0xd400); |
| 5723 | insn = bfd_get_16 (input_bfd, contents + offset + 2); |
| 5724 | BFD_ASSERT ((insn & 0xff00) == 0xc700); |
| 5725 | insn = bfd_get_16 (input_bfd, contents + offset + 4); |
| 5726 | BFD_ASSERT ((insn & 0xff00) == 0xd100); |
| 5727 | insn = bfd_get_16 (input_bfd, contents + offset + 6); |
| 5728 | BFD_ASSERT (insn == 0x310c); |
| 5729 | insn = bfd_get_16 (input_bfd, contents + offset + 8); |
| 5730 | BFD_ASSERT (insn == 0x410b); |
| 5731 | insn = bfd_get_16 (input_bfd, contents + offset + 10); |
| 5732 | BFD_ASSERT (insn == 0x34cc); |
| 5733 | |
| 5734 | bfd_put_16 (output_bfd, 0x0012, contents + offset + 0); |
| 5735 | bfd_put_16 (output_bfd, 0x0009, contents + offset + 2); |
| 5736 | bfd_put_16 (output_bfd, 0x0009, contents + offset + 4); |
| 5737 | bfd_put_16 (output_bfd, 0x0009, contents + offset + 6); |
| 5738 | bfd_put_16 (output_bfd, 0x0009, contents + offset + 8); |
| 5739 | bfd_put_16 (output_bfd, 0x0009, contents + offset + 10); |
| 5740 | |
| 5741 | continue; |
| 5742 | } |
| 5743 | |
| 5744 | sgot = htab->sgot; |
| 5745 | if (sgot == NULL) |
| 5746 | abort (); |
| 5747 | |
| 5748 | off = htab->tls_ldm_got.offset; |
| 5749 | if (off & 1) |
| 5750 | off &= ~1; |
| 5751 | else |
| 5752 | { |
| 5753 | Elf_Internal_Rela outrel; |
| 5754 | bfd_byte *loc; |
| 5755 | |
| 5756 | srelgot = htab->srelgot; |
| 5757 | if (srelgot == NULL) |
| 5758 | abort (); |
| 5759 | |
| 5760 | outrel.r_offset = (sgot->output_section->vma |
| 5761 | + sgot->output_offset + off); |
| 5762 | outrel.r_addend = 0; |
| 5763 | outrel.r_info = ELF32_R_INFO (0, R_SH_TLS_DTPMOD32); |
| 5764 | loc = srelgot->contents; |
| 5765 | loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela); |
| 5766 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
| 5767 | htab->tls_ldm_got.offset |= 1; |
| 5768 | } |
| 5769 | |
| 5770 | relocation = sgot->output_offset + off; |
| 5771 | addend = rel->r_addend; |
| 5772 | |
| 5773 | goto final_link_relocate; |
| 5774 | |
| 5775 | case R_SH_TLS_LDO_32: |
| 5776 | if (! info->shared) |
| 5777 | relocation = tpoff (info, relocation); |
| 5778 | else |
| 5779 | relocation -= dtpoff_base (info); |
| 5780 | |
| 5781 | addend = rel->r_addend; |
| 5782 | goto final_link_relocate; |
| 5783 | |
| 5784 | case R_SH_TLS_LE_32: |
| 5785 | { |
| 5786 | int indx; |
| 5787 | Elf_Internal_Rela outrel; |
| 5788 | bfd_byte *loc; |
| 5789 | |
| 5790 | if (! info->shared) |
| 5791 | { |
| 5792 | relocation = tpoff (info, relocation); |
| 5793 | addend = rel->r_addend; |
| 5794 | goto final_link_relocate; |
| 5795 | } |
| 5796 | |
| 5797 | if (sreloc == NULL) |
| 5798 | { |
| 5799 | const char *name; |
| 5800 | |
| 5801 | name = (bfd_elf_string_from_elf_section |
| 5802 | (input_bfd, |
| 5803 | elf_elfheader (input_bfd)->e_shstrndx, |
| 5804 | elf_section_data (input_section)->rel_hdr.sh_name)); |
| 5805 | if (name == NULL) |
| 5806 | return FALSE; |
| 5807 | |
| 5808 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 |
| 5809 | && strcmp (bfd_get_section_name (input_bfd, |
| 5810 | input_section), |
| 5811 | name + 5) == 0); |
| 5812 | |
| 5813 | sreloc = bfd_get_section_by_name (dynobj, name); |
| 5814 | BFD_ASSERT (sreloc != NULL); |
| 5815 | } |
| 5816 | |
| 5817 | if (h == NULL || h->dynindx == -1) |
| 5818 | indx = 0; |
| 5819 | else |
| 5820 | indx = h->dynindx; |
| 5821 | |
| 5822 | outrel.r_offset = (input_section->output_section->vma |
| 5823 | + input_section->output_offset |
| 5824 | + rel->r_offset); |
| 5825 | outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32); |
| 5826 | if (indx == 0) |
| 5827 | outrel.r_addend = relocation - dtpoff_base (info); |
| 5828 | else |
| 5829 | outrel.r_addend = 0; |
| 5830 | |
| 5831 | loc = sreloc->contents; |
| 5832 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); |
| 5833 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
| 5834 | continue; |
| 5835 | } |
| 5836 | } |
| 5837 | |
| 5838 | relocation_done: |
| 5839 | if (r != bfd_reloc_ok) |
| 5840 | { |
| 5841 | switch (r) |
| 5842 | { |
| 5843 | default: |
| 5844 | case bfd_reloc_outofrange: |
| 5845 | abort (); |
| 5846 | case bfd_reloc_overflow: |
| 5847 | { |
| 5848 | const char *name; |
| 5849 | |
| 5850 | if (h != NULL) |
| 5851 | name = NULL; |
| 5852 | else |
| 5853 | { |
| 5854 | name = (bfd_elf_string_from_elf_section |
| 5855 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); |
| 5856 | if (name == NULL) |
| 5857 | return FALSE; |
| 5858 | if (*name == '\0') |
| 5859 | name = bfd_section_name (input_bfd, sec); |
| 5860 | } |
| 5861 | if (! ((*info->callbacks->reloc_overflow) |
| 5862 | (info, (h ? &h->root : NULL), name, howto->name, |
| 5863 | (bfd_vma) 0, input_bfd, input_section, |
| 5864 | rel->r_offset))) |
| 5865 | return FALSE; |
| 5866 | } |
| 5867 | break; |
| 5868 | } |
| 5869 | } |
| 5870 | } |
| 5871 | |
| 5872 | return TRUE; |
| 5873 | } |
| 5874 | |
| 5875 | /* This is a version of bfd_generic_get_relocated_section_contents |
| 5876 | which uses sh_elf_relocate_section. */ |
| 5877 | |
| 5878 | static bfd_byte * |
| 5879 | sh_elf_get_relocated_section_contents (bfd *output_bfd, |
| 5880 | struct bfd_link_info *link_info, |
| 5881 | struct bfd_link_order *link_order, |
| 5882 | bfd_byte *data, |
| 5883 | bfd_boolean relocatable, |
| 5884 | asymbol **symbols) |
| 5885 | { |
| 5886 | Elf_Internal_Shdr *symtab_hdr; |
| 5887 | asection *input_section = link_order->u.indirect.section; |
| 5888 | bfd *input_bfd = input_section->owner; |
| 5889 | asection **sections = NULL; |
| 5890 | Elf_Internal_Rela *internal_relocs = NULL; |
| 5891 | Elf_Internal_Sym *isymbuf = NULL; |
| 5892 | |
| 5893 | /* We only need to handle the case of relaxing, or of having a |
| 5894 | particular set of section contents, specially. */ |
| 5895 | if (relocatable |
| 5896 | || elf_section_data (input_section)->this_hdr.contents == NULL) |
| 5897 | return bfd_generic_get_relocated_section_contents (output_bfd, link_info, |
| 5898 | link_order, data, |
| 5899 | relocatable, |
| 5900 | symbols); |
| 5901 | |
| 5902 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
| 5903 | |
| 5904 | memcpy (data, elf_section_data (input_section)->this_hdr.contents, |
| 5905 | (size_t) input_section->size); |
| 5906 | |
| 5907 | if ((input_section->flags & SEC_RELOC) != 0 |
| 5908 | && input_section->reloc_count > 0) |
| 5909 | { |
| 5910 | asection **secpp; |
| 5911 | Elf_Internal_Sym *isym, *isymend; |
| 5912 | bfd_size_type amt; |
| 5913 | |
| 5914 | internal_relocs = (_bfd_elf_link_read_relocs |
| 5915 | (input_bfd, input_section, NULL, |
| 5916 | (Elf_Internal_Rela *) NULL, FALSE)); |
| 5917 | if (internal_relocs == NULL) |
| 5918 | goto error_return; |
| 5919 | |
| 5920 | if (symtab_hdr->sh_info != 0) |
| 5921 | { |
| 5922 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; |
| 5923 | if (isymbuf == NULL) |
| 5924 | isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, |
| 5925 | symtab_hdr->sh_info, 0, |
| 5926 | NULL, NULL, NULL); |
| 5927 | if (isymbuf == NULL) |
| 5928 | goto error_return; |
| 5929 | } |
| 5930 | |
| 5931 | amt = symtab_hdr->sh_info; |
| 5932 | amt *= sizeof (asection *); |
| 5933 | sections = (asection **) bfd_malloc (amt); |
| 5934 | if (sections == NULL && amt != 0) |
| 5935 | goto error_return; |
| 5936 | |
| 5937 | isymend = isymbuf + symtab_hdr->sh_info; |
| 5938 | for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp) |
| 5939 | { |
| 5940 | asection *isec; |
| 5941 | |
| 5942 | if (isym->st_shndx == SHN_UNDEF) |
| 5943 | isec = bfd_und_section_ptr; |
| 5944 | else if (isym->st_shndx == SHN_ABS) |
| 5945 | isec = bfd_abs_section_ptr; |
| 5946 | else if (isym->st_shndx == SHN_COMMON) |
| 5947 | isec = bfd_com_section_ptr; |
| 5948 | else |
| 5949 | isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx); |
| 5950 | |
| 5951 | *secpp = isec; |
| 5952 | } |
| 5953 | |
| 5954 | if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd, |
| 5955 | input_section, data, internal_relocs, |
| 5956 | isymbuf, sections)) |
| 5957 | goto error_return; |
| 5958 | |
| 5959 | if (sections != NULL) |
| 5960 | free (sections); |
| 5961 | if (isymbuf != NULL |
| 5962 | && symtab_hdr->contents != (unsigned char *) isymbuf) |
| 5963 | free (isymbuf); |
| 5964 | if (elf_section_data (input_section)->relocs != internal_relocs) |
| 5965 | free (internal_relocs); |
| 5966 | } |
| 5967 | |
| 5968 | return data; |
| 5969 | |
| 5970 | error_return: |
| 5971 | if (sections != NULL) |
| 5972 | free (sections); |
| 5973 | if (isymbuf != NULL |
| 5974 | && symtab_hdr->contents != (unsigned char *) isymbuf) |
| 5975 | free (isymbuf); |
| 5976 | if (internal_relocs != NULL |
| 5977 | && elf_section_data (input_section)->relocs != internal_relocs) |
| 5978 | free (internal_relocs); |
| 5979 | return NULL; |
| 5980 | } |
| 5981 | |
| 5982 | /* Return the base VMA address which should be subtracted from real addresses |
| 5983 | when resolving @dtpoff relocation. |
| 5984 | This is PT_TLS segment p_vaddr. */ |
| 5985 | |
| 5986 | static bfd_vma |
| 5987 | dtpoff_base (struct bfd_link_info *info) |
| 5988 | { |
| 5989 | /* If tls_sec is NULL, we should have signalled an error already. */ |
| 5990 | if (elf_hash_table (info)->tls_sec == NULL) |
| 5991 | return 0; |
| 5992 | return elf_hash_table (info)->tls_sec->vma; |
| 5993 | } |
| 5994 | |
| 5995 | /* Return the relocation value for R_SH_TLS_TPOFF32.. */ |
| 5996 | |
| 5997 | static bfd_vma |
| 5998 | tpoff (struct bfd_link_info *info, bfd_vma address) |
| 5999 | { |
| 6000 | /* If tls_sec is NULL, we should have signalled an error already. */ |
| 6001 | if (elf_hash_table (info)->tls_sec == NULL) |
| 6002 | return 0; |
| 6003 | /* SH TLS ABI is variant I and static TLS block start just after tcbhead |
| 6004 | structure which has 2 pointer fields. */ |
| 6005 | return (address - elf_hash_table (info)->tls_sec->vma |
| 6006 | + align_power ((bfd_vma) 8, |
| 6007 | elf_hash_table (info)->tls_sec->alignment_power)); |
| 6008 | } |
| 6009 | |
| 6010 | static asection * |
| 6011 | sh_elf_gc_mark_hook (asection *sec, |
| 6012 | struct bfd_link_info *info ATTRIBUTE_UNUSED, |
| 6013 | Elf_Internal_Rela *rel, struct elf_link_hash_entry *h, |
| 6014 | Elf_Internal_Sym *sym) |
| 6015 | { |
| 6016 | if (h != NULL) |
| 6017 | { |
| 6018 | switch (ELF32_R_TYPE (rel->r_info)) |
| 6019 | { |
| 6020 | case R_SH_GNU_VTINHERIT: |
| 6021 | case R_SH_GNU_VTENTRY: |
| 6022 | break; |
| 6023 | |
| 6024 | default: |
| 6025 | #ifdef INCLUDE_SHMEDIA |
| 6026 | while (h->root.type == bfd_link_hash_indirect |
| 6027 | && h->root.u.i.link) |
| 6028 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 6029 | #endif |
| 6030 | switch (h->root.type) |
| 6031 | { |
| 6032 | case bfd_link_hash_defined: |
| 6033 | case bfd_link_hash_defweak: |
| 6034 | return h->root.u.def.section; |
| 6035 | |
| 6036 | case bfd_link_hash_common: |
| 6037 | return h->root.u.c.p->section; |
| 6038 | |
| 6039 | default: |
| 6040 | break; |
| 6041 | } |
| 6042 | } |
| 6043 | } |
| 6044 | else |
| 6045 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
| 6046 | |
| 6047 | return NULL; |
| 6048 | } |
| 6049 | |
| 6050 | /* Update the got entry reference counts for the section being removed. */ |
| 6051 | |
| 6052 | static bfd_boolean |
| 6053 | sh_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, |
| 6054 | asection *sec, const Elf_Internal_Rela *relocs) |
| 6055 | { |
| 6056 | Elf_Internal_Shdr *symtab_hdr; |
| 6057 | struct elf_link_hash_entry **sym_hashes; |
| 6058 | bfd_signed_vma *local_got_refcounts; |
| 6059 | const Elf_Internal_Rela *rel, *relend; |
| 6060 | |
| 6061 | elf_section_data (sec)->local_dynrel = NULL; |
| 6062 | |
| 6063 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 6064 | sym_hashes = elf_sym_hashes (abfd); |
| 6065 | local_got_refcounts = elf_local_got_refcounts (abfd); |
| 6066 | |
| 6067 | relend = relocs + sec->reloc_count; |
| 6068 | for (rel = relocs; rel < relend; rel++) |
| 6069 | { |
| 6070 | unsigned long r_symndx; |
| 6071 | unsigned int r_type; |
| 6072 | struct elf_link_hash_entry *h = NULL; |
| 6073 | #ifdef INCLUDE_SHMEDIA |
| 6074 | int seen_stt_datalabel = 0; |
| 6075 | #endif |
| 6076 | |
| 6077 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 6078 | if (r_symndx >= symtab_hdr->sh_info) |
| 6079 | { |
| 6080 | struct elf_sh_link_hash_entry *eh; |
| 6081 | struct elf_sh_dyn_relocs **pp; |
| 6082 | struct elf_sh_dyn_relocs *p; |
| 6083 | |
| 6084 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 6085 | #ifdef INCLUDE_SHMEDIA |
| 6086 | while (h->root.type == bfd_link_hash_indirect |
| 6087 | || h->root.type == bfd_link_hash_warning) |
| 6088 | { |
| 6089 | seen_stt_datalabel |= h->type == STT_DATALABEL; |
| 6090 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 6091 | } |
| 6092 | #endif |
| 6093 | eh = (struct elf_sh_link_hash_entry *) h; |
| 6094 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) |
| 6095 | if (p->sec == sec) |
| 6096 | { |
| 6097 | /* Everything must go for SEC. */ |
| 6098 | *pp = p->next; |
| 6099 | break; |
| 6100 | } |
| 6101 | } |
| 6102 | |
| 6103 | r_type = ELF32_R_TYPE (rel->r_info); |
| 6104 | switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL)) |
| 6105 | { |
| 6106 | case R_SH_TLS_LD_32: |
| 6107 | if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0) |
| 6108 | sh_elf_hash_table (info)->tls_ldm_got.refcount -= 1; |
| 6109 | break; |
| 6110 | |
| 6111 | case R_SH_GOT32: |
| 6112 | case R_SH_GOTOFF: |
| 6113 | case R_SH_GOTPC: |
| 6114 | #ifdef INCLUDE_SHMEDIA |
| 6115 | case R_SH_GOT_LOW16: |
| 6116 | case R_SH_GOT_MEDLOW16: |
| 6117 | case R_SH_GOT_MEDHI16: |
| 6118 | case R_SH_GOT_HI16: |
| 6119 | case R_SH_GOT10BY4: |
| 6120 | case R_SH_GOT10BY8: |
| 6121 | case R_SH_GOTOFF_LOW16: |
| 6122 | case R_SH_GOTOFF_MEDLOW16: |
| 6123 | case R_SH_GOTOFF_MEDHI16: |
| 6124 | case R_SH_GOTOFF_HI16: |
| 6125 | case R_SH_GOTPC_LOW16: |
| 6126 | case R_SH_GOTPC_MEDLOW16: |
| 6127 | case R_SH_GOTPC_MEDHI16: |
| 6128 | case R_SH_GOTPC_HI16: |
| 6129 | #endif |
| 6130 | case R_SH_TLS_GD_32: |
| 6131 | case R_SH_TLS_IE_32: |
| 6132 | if (h != NULL) |
| 6133 | { |
| 6134 | #ifdef INCLUDE_SHMEDIA |
| 6135 | if (seen_stt_datalabel) |
| 6136 | { |
| 6137 | struct elf_sh_link_hash_entry *eh; |
| 6138 | eh = (struct elf_sh_link_hash_entry *) h; |
| 6139 | if (eh->datalabel_got.refcount > 0) |
| 6140 | eh->datalabel_got.refcount -= 1; |
| 6141 | } |
| 6142 | else |
| 6143 | #endif |
| 6144 | if (h->got.refcount > 0) |
| 6145 | h->got.refcount -= 1; |
| 6146 | } |
| 6147 | else if (local_got_refcounts != NULL) |
| 6148 | { |
| 6149 | #ifdef INCLUDE_SHMEDIA |
| 6150 | if (rel->r_addend & 1) |
| 6151 | { |
| 6152 | if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0) |
| 6153 | local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1; |
| 6154 | } |
| 6155 | else |
| 6156 | #endif |
| 6157 | if (local_got_refcounts[r_symndx] > 0) |
| 6158 | local_got_refcounts[r_symndx] -= 1; |
| 6159 | } |
| 6160 | break; |
| 6161 | |
| 6162 | case R_SH_DIR32: |
| 6163 | case R_SH_REL32: |
| 6164 | if (info->shared) |
| 6165 | break; |
| 6166 | /* Fall thru */ |
| 6167 | |
| 6168 | case R_SH_PLT32: |
| 6169 | #ifdef INCLUDE_SHMEDIA |
| 6170 | case R_SH_PLT_LOW16: |
| 6171 | case R_SH_PLT_MEDLOW16: |
| 6172 | case R_SH_PLT_MEDHI16: |
| 6173 | case R_SH_PLT_HI16: |
| 6174 | #endif |
| 6175 | if (h != NULL) |
| 6176 | { |
| 6177 | if (h->plt.refcount > 0) |
| 6178 | h->plt.refcount -= 1; |
| 6179 | } |
| 6180 | break; |
| 6181 | |
| 6182 | case R_SH_GOTPLT32: |
| 6183 | #ifdef INCLUDE_SHMEDIA |
| 6184 | case R_SH_GOTPLT_LOW16: |
| 6185 | case R_SH_GOTPLT_MEDLOW16: |
| 6186 | case R_SH_GOTPLT_MEDHI16: |
| 6187 | case R_SH_GOTPLT_HI16: |
| 6188 | case R_SH_GOTPLT10BY4: |
| 6189 | case R_SH_GOTPLT10BY8: |
| 6190 | #endif |
| 6191 | if (h != NULL) |
| 6192 | { |
| 6193 | struct elf_sh_link_hash_entry *eh; |
| 6194 | eh = (struct elf_sh_link_hash_entry *) h; |
| 6195 | if (eh->gotplt_refcount > 0) |
| 6196 | { |
| 6197 | eh->gotplt_refcount -= 1; |
| 6198 | if (h->plt.refcount > 0) |
| 6199 | h->plt.refcount -= 1; |
| 6200 | } |
| 6201 | #ifdef INCLUDE_SHMEDIA |
| 6202 | else if (seen_stt_datalabel) |
| 6203 | { |
| 6204 | if (eh->datalabel_got.refcount > 0) |
| 6205 | eh->datalabel_got.refcount -= 1; |
| 6206 | } |
| 6207 | #endif |
| 6208 | else if (h->got.refcount > 0) |
| 6209 | h->got.refcount -= 1; |
| 6210 | } |
| 6211 | else if (local_got_refcounts != NULL) |
| 6212 | { |
| 6213 | #ifdef INCLUDE_SHMEDIA |
| 6214 | if (rel->r_addend & 1) |
| 6215 | { |
| 6216 | if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0) |
| 6217 | local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1; |
| 6218 | } |
| 6219 | else |
| 6220 | #endif |
| 6221 | if (local_got_refcounts[r_symndx] > 0) |
| 6222 | local_got_refcounts[r_symndx] -= 1; |
| 6223 | } |
| 6224 | break; |
| 6225 | |
| 6226 | default: |
| 6227 | break; |
| 6228 | } |
| 6229 | } |
| 6230 | |
| 6231 | return TRUE; |
| 6232 | } |
| 6233 | |
| 6234 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
| 6235 | |
| 6236 | static void |
| 6237 | sh_elf_copy_indirect_symbol (const struct elf_backend_data *bed, |
| 6238 | struct elf_link_hash_entry *dir, |
| 6239 | struct elf_link_hash_entry *ind) |
| 6240 | { |
| 6241 | struct elf_sh_link_hash_entry *edir, *eind; |
| 6242 | #ifdef INCLUDE_SHMEDIA |
| 6243 | bfd_signed_vma tmp; |
| 6244 | #endif |
| 6245 | |
| 6246 | edir = (struct elf_sh_link_hash_entry *) dir; |
| 6247 | eind = (struct elf_sh_link_hash_entry *) ind; |
| 6248 | |
| 6249 | if (eind->dyn_relocs != NULL) |
| 6250 | { |
| 6251 | if (edir->dyn_relocs != NULL) |
| 6252 | { |
| 6253 | struct elf_sh_dyn_relocs **pp; |
| 6254 | struct elf_sh_dyn_relocs *p; |
| 6255 | |
| 6256 | BFD_ASSERT (ind->root.type != bfd_link_hash_indirect); |
| 6257 | |
| 6258 | /* Add reloc counts against the weak sym to the strong sym |
| 6259 | list. Merge any entries against the same section. */ |
| 6260 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) |
| 6261 | { |
| 6262 | struct elf_sh_dyn_relocs *q; |
| 6263 | |
| 6264 | for (q = edir->dyn_relocs; q != NULL; q = q->next) |
| 6265 | if (q->sec == p->sec) |
| 6266 | { |
| 6267 | q->pc_count += p->pc_count; |
| 6268 | q->count += p->count; |
| 6269 | *pp = p->next; |
| 6270 | break; |
| 6271 | } |
| 6272 | if (q == NULL) |
| 6273 | pp = &p->next; |
| 6274 | } |
| 6275 | *pp = edir->dyn_relocs; |
| 6276 | } |
| 6277 | |
| 6278 | edir->dyn_relocs = eind->dyn_relocs; |
| 6279 | eind->dyn_relocs = NULL; |
| 6280 | } |
| 6281 | edir->gotplt_refcount = eind->gotplt_refcount; |
| 6282 | eind->gotplt_refcount = 0; |
| 6283 | #ifdef INCLUDE_SHMEDIA |
| 6284 | tmp = edir->datalabel_got.refcount; |
| 6285 | if (tmp < 1) |
| 6286 | { |
| 6287 | edir->datalabel_got.refcount = eind->datalabel_got.refcount; |
| 6288 | eind->datalabel_got.refcount = tmp; |
| 6289 | } |
| 6290 | else |
| 6291 | BFD_ASSERT (eind->datalabel_got.refcount < 1); |
| 6292 | #endif |
| 6293 | |
| 6294 | if (ind->root.type == bfd_link_hash_indirect |
| 6295 | && dir->got.refcount <= 0) |
| 6296 | { |
| 6297 | edir->tls_type = eind->tls_type; |
| 6298 | eind->tls_type = GOT_UNKNOWN; |
| 6299 | } |
| 6300 | |
| 6301 | if (ind->root.type != bfd_link_hash_indirect |
| 6302 | && dir->dynamic_adjusted) |
| 6303 | { |
| 6304 | /* If called to transfer flags for a weakdef during processing |
| 6305 | of elf_adjust_dynamic_symbol, don't copy non_got_ref. |
| 6306 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ |
| 6307 | dir->ref_dynamic |= ind->ref_dynamic; |
| 6308 | dir->ref_regular |= ind->ref_regular; |
| 6309 | dir->ref_regular_nonweak |= ind->ref_regular_nonweak; |
| 6310 | dir->needs_plt |= ind->needs_plt; |
| 6311 | } |
| 6312 | else |
| 6313 | _bfd_elf_link_hash_copy_indirect (bed, dir, ind); |
| 6314 | } |
| 6315 | |
| 6316 | static int |
| 6317 | sh_elf_optimized_tls_reloc (struct bfd_link_info *info, int r_type, |
| 6318 | int is_local) |
| 6319 | { |
| 6320 | if (info->shared) |
| 6321 | return r_type; |
| 6322 | |
| 6323 | switch (r_type) |
| 6324 | { |
| 6325 | case R_SH_TLS_GD_32: |
| 6326 | case R_SH_TLS_IE_32: |
| 6327 | if (is_local) |
| 6328 | return R_SH_TLS_LE_32; |
| 6329 | return R_SH_TLS_IE_32; |
| 6330 | case R_SH_TLS_LD_32: |
| 6331 | return R_SH_TLS_LE_32; |
| 6332 | } |
| 6333 | |
| 6334 | return r_type; |
| 6335 | } |
| 6336 | |
| 6337 | /* Look through the relocs for a section during the first phase. |
| 6338 | Since we don't do .gots or .plts, we just need to consider the |
| 6339 | virtual table relocs for gc. */ |
| 6340 | |
| 6341 | static bfd_boolean |
| 6342 | sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, |
| 6343 | const Elf_Internal_Rela *relocs) |
| 6344 | { |
| 6345 | Elf_Internal_Shdr *symtab_hdr; |
| 6346 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; |
| 6347 | struct elf_sh_link_hash_table *htab; |
| 6348 | const Elf_Internal_Rela *rel; |
| 6349 | const Elf_Internal_Rela *rel_end; |
| 6350 | bfd_vma *local_got_offsets; |
| 6351 | asection *sgot; |
| 6352 | asection *srelgot; |
| 6353 | asection *sreloc; |
| 6354 | unsigned int r_type; |
| 6355 | int tls_type, old_tls_type; |
| 6356 | |
| 6357 | sgot = NULL; |
| 6358 | srelgot = NULL; |
| 6359 | sreloc = NULL; |
| 6360 | |
| 6361 | if (info->relocatable) |
| 6362 | return TRUE; |
| 6363 | |
| 6364 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 6365 | sym_hashes = elf_sym_hashes (abfd); |
| 6366 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym); |
| 6367 | if (!elf_bad_symtab (abfd)) |
| 6368 | sym_hashes_end -= symtab_hdr->sh_info; |
| 6369 | |
| 6370 | htab = sh_elf_hash_table (info); |
| 6371 | local_got_offsets = elf_local_got_offsets (abfd); |
| 6372 | |
| 6373 | rel_end = relocs + sec->reloc_count; |
| 6374 | for (rel = relocs; rel < rel_end; rel++) |
| 6375 | { |
| 6376 | struct elf_link_hash_entry *h; |
| 6377 | unsigned long r_symndx; |
| 6378 | #ifdef INCLUDE_SHMEDIA |
| 6379 | int seen_stt_datalabel = 0; |
| 6380 | #endif |
| 6381 | |
| 6382 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 6383 | r_type = ELF32_R_TYPE (rel->r_info); |
| 6384 | |
| 6385 | if (r_symndx < symtab_hdr->sh_info) |
| 6386 | h = NULL; |
| 6387 | else |
| 6388 | { |
| 6389 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 6390 | #ifdef INCLUDE_SHMEDIA |
| 6391 | while (h->root.type == bfd_link_hash_indirect |
| 6392 | || h->root.type == bfd_link_hash_warning) |
| 6393 | { |
| 6394 | seen_stt_datalabel |= h->type == STT_DATALABEL; |
| 6395 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 6396 | } |
| 6397 | #endif |
| 6398 | } |
| 6399 | |
| 6400 | r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL); |
| 6401 | if (! info->shared |
| 6402 | && r_type == R_SH_TLS_IE_32 |
| 6403 | && h != NULL |
| 6404 | && h->root.type != bfd_link_hash_undefined |
| 6405 | && h->root.type != bfd_link_hash_undefweak |
| 6406 | && (h->dynindx == -1 |
| 6407 | || h->def_regular)) |
| 6408 | r_type = R_SH_TLS_LE_32; |
| 6409 | |
| 6410 | /* Some relocs require a global offset table. */ |
| 6411 | if (htab->sgot == NULL) |
| 6412 | { |
| 6413 | switch (r_type) |
| 6414 | { |
| 6415 | case R_SH_GOTPLT32: |
| 6416 | case R_SH_GOT32: |
| 6417 | case R_SH_GOTOFF: |
| 6418 | case R_SH_GOTPC: |
| 6419 | #ifdef INCLUDE_SHMEDIA |
| 6420 | case R_SH_GOTPLT_LOW16: |
| 6421 | case R_SH_GOTPLT_MEDLOW16: |
| 6422 | case R_SH_GOTPLT_MEDHI16: |
| 6423 | case R_SH_GOTPLT_HI16: |
| 6424 | case R_SH_GOTPLT10BY4: |
| 6425 | case R_SH_GOTPLT10BY8: |
| 6426 | case R_SH_GOT_LOW16: |
| 6427 | case R_SH_GOT_MEDLOW16: |
| 6428 | case R_SH_GOT_MEDHI16: |
| 6429 | case R_SH_GOT_HI16: |
| 6430 | case R_SH_GOT10BY4: |
| 6431 | case R_SH_GOT10BY8: |
| 6432 | case R_SH_GOTOFF_LOW16: |
| 6433 | case R_SH_GOTOFF_MEDLOW16: |
| 6434 | case R_SH_GOTOFF_MEDHI16: |
| 6435 | case R_SH_GOTOFF_HI16: |
| 6436 | case R_SH_GOTPC_LOW16: |
| 6437 | case R_SH_GOTPC_MEDLOW16: |
| 6438 | case R_SH_GOTPC_MEDHI16: |
| 6439 | case R_SH_GOTPC_HI16: |
| 6440 | #endif |
| 6441 | case R_SH_TLS_GD_32: |
| 6442 | case R_SH_TLS_LD_32: |
| 6443 | case R_SH_TLS_IE_32: |
| 6444 | if (htab->sgot == NULL) |
| 6445 | { |
| 6446 | if (htab->root.dynobj == NULL) |
| 6447 | htab->root.dynobj = abfd; |
| 6448 | if (!create_got_section (htab->root.dynobj, info)) |
| 6449 | return FALSE; |
| 6450 | } |
| 6451 | break; |
| 6452 | |
| 6453 | default: |
| 6454 | break; |
| 6455 | } |
| 6456 | } |
| 6457 | |
| 6458 | switch (r_type) |
| 6459 | { |
| 6460 | /* This relocation describes the C++ object vtable hierarchy. |
| 6461 | Reconstruct it for later use during GC. */ |
| 6462 | case R_SH_GNU_VTINHERIT: |
| 6463 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
| 6464 | return FALSE; |
| 6465 | break; |
| 6466 | |
| 6467 | /* This relocation describes which C++ vtable entries are actually |
| 6468 | used. Record for later use during GC. */ |
| 6469 | case R_SH_GNU_VTENTRY: |
| 6470 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
| 6471 | return FALSE; |
| 6472 | break; |
| 6473 | |
| 6474 | case R_SH_TLS_IE_32: |
| 6475 | if (info->shared) |
| 6476 | info->flags |= DF_STATIC_TLS; |
| 6477 | |
| 6478 | /* FALLTHROUGH */ |
| 6479 | force_got: |
| 6480 | case R_SH_TLS_GD_32: |
| 6481 | case R_SH_GOT32: |
| 6482 | #ifdef INCLUDE_SHMEDIA |
| 6483 | case R_SH_GOT_LOW16: |
| 6484 | case R_SH_GOT_MEDLOW16: |
| 6485 | case R_SH_GOT_MEDHI16: |
| 6486 | case R_SH_GOT_HI16: |
| 6487 | case R_SH_GOT10BY4: |
| 6488 | case R_SH_GOT10BY8: |
| 6489 | #endif |
| 6490 | switch (r_type) |
| 6491 | { |
| 6492 | default: |
| 6493 | tls_type = GOT_NORMAL; |
| 6494 | break; |
| 6495 | case R_SH_TLS_GD_32: |
| 6496 | tls_type = GOT_TLS_GD; |
| 6497 | break; |
| 6498 | case R_SH_TLS_IE_32: |
| 6499 | tls_type = GOT_TLS_IE; |
| 6500 | break; |
| 6501 | } |
| 6502 | |
| 6503 | if (h != NULL) |
| 6504 | { |
| 6505 | #ifdef INCLUDE_SHMEDIA |
| 6506 | if (seen_stt_datalabel) |
| 6507 | { |
| 6508 | struct elf_sh_link_hash_entry *eh |
| 6509 | = (struct elf_sh_link_hash_entry *) h; |
| 6510 | |
| 6511 | eh->datalabel_got.refcount += 1; |
| 6512 | } |
| 6513 | else |
| 6514 | #endif |
| 6515 | h->got.refcount += 1; |
| 6516 | old_tls_type = sh_elf_hash_entry (h)->tls_type; |
| 6517 | } |
| 6518 | else |
| 6519 | { |
| 6520 | bfd_signed_vma *local_got_refcounts; |
| 6521 | |
| 6522 | /* This is a global offset table entry for a local |
| 6523 | symbol. */ |
| 6524 | local_got_refcounts = elf_local_got_refcounts (abfd); |
| 6525 | if (local_got_refcounts == NULL) |
| 6526 | { |
| 6527 | bfd_size_type size; |
| 6528 | |
| 6529 | size = symtab_hdr->sh_info; |
| 6530 | size *= sizeof (bfd_signed_vma); |
| 6531 | #ifdef INCLUDE_SHMEDIA |
| 6532 | /* Reserve space for both the datalabel and |
| 6533 | codelabel local GOT offsets. */ |
| 6534 | size *= 2; |
| 6535 | #endif |
| 6536 | size += symtab_hdr->sh_info; |
| 6537 | local_got_refcounts = ((bfd_signed_vma *) |
| 6538 | bfd_zalloc (abfd, size)); |
| 6539 | if (local_got_refcounts == NULL) |
| 6540 | return FALSE; |
| 6541 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
| 6542 | #ifdef INCLUDE_SHMEDIA |
| 6543 | /* Take care of both the datalabel and codelabel local |
| 6544 | GOT offsets. */ |
| 6545 | sh_elf_local_got_tls_type (abfd) |
| 6546 | = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info); |
| 6547 | #else |
| 6548 | sh_elf_local_got_tls_type (abfd) |
| 6549 | = (char *) (local_got_refcounts + symtab_hdr->sh_info); |
| 6550 | #endif |
| 6551 | } |
| 6552 | #ifdef INCLUDE_SHMEDIA |
| 6553 | if (rel->r_addend & 1) |
| 6554 | local_got_refcounts[symtab_hdr->sh_info + r_symndx] += 1; |
| 6555 | else |
| 6556 | #endif |
| 6557 | local_got_refcounts[r_symndx] += 1; |
| 6558 | old_tls_type = sh_elf_local_got_tls_type (abfd) [r_symndx]; |
| 6559 | } |
| 6560 | |
| 6561 | /* If a TLS symbol is accessed using IE at least once, |
| 6562 | there is no point to use dynamic model for it. */ |
| 6563 | if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN |
| 6564 | && (old_tls_type != GOT_TLS_GD || tls_type != GOT_TLS_IE)) |
| 6565 | { |
| 6566 | if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD) |
| 6567 | tls_type = GOT_TLS_IE; |
| 6568 | else |
| 6569 | { |
| 6570 | (*_bfd_error_handler) |
| 6571 | (_("%B: `%s' accessed both as normal and thread local symbol"), |
| 6572 | abfd, h->root.root.string); |
| 6573 | return FALSE; |
| 6574 | } |
| 6575 | } |
| 6576 | |
| 6577 | if (old_tls_type != tls_type) |
| 6578 | { |
| 6579 | if (h != NULL) |
| 6580 | sh_elf_hash_entry (h)->tls_type = tls_type; |
| 6581 | else |
| 6582 | sh_elf_local_got_tls_type (abfd) [r_symndx] = tls_type; |
| 6583 | } |
| 6584 | |
| 6585 | break; |
| 6586 | |
| 6587 | case R_SH_TLS_LD_32: |
| 6588 | sh_elf_hash_table(info)->tls_ldm_got.refcount += 1; |
| 6589 | break; |
| 6590 | |
| 6591 | case R_SH_GOTPLT32: |
| 6592 | #ifdef INCLUDE_SHMEDIA |
| 6593 | case R_SH_GOTPLT_LOW16: |
| 6594 | case R_SH_GOTPLT_MEDLOW16: |
| 6595 | case R_SH_GOTPLT_MEDHI16: |
| 6596 | case R_SH_GOTPLT_HI16: |
| 6597 | case R_SH_GOTPLT10BY4: |
| 6598 | case R_SH_GOTPLT10BY8: |
| 6599 | #endif |
| 6600 | /* If this is a local symbol, we resolve it directly without |
| 6601 | creating a procedure linkage table entry. */ |
| 6602 | |
| 6603 | if (h == NULL |
| 6604 | || h->forced_local |
| 6605 | || ! info->shared |
| 6606 | || info->symbolic |
| 6607 | || h->dynindx == -1) |
| 6608 | goto force_got; |
| 6609 | |
| 6610 | h->needs_plt = 1; |
| 6611 | h->plt.refcount += 1; |
| 6612 | ((struct elf_sh_link_hash_entry *) h)->gotplt_refcount += 1; |
| 6613 | |
| 6614 | break; |
| 6615 | |
| 6616 | case R_SH_PLT32: |
| 6617 | #ifdef INCLUDE_SHMEDIA |
| 6618 | case R_SH_PLT_LOW16: |
| 6619 | case R_SH_PLT_MEDLOW16: |
| 6620 | case R_SH_PLT_MEDHI16: |
| 6621 | case R_SH_PLT_HI16: |
| 6622 | #endif |
| 6623 | /* This symbol requires a procedure linkage table entry. We |
| 6624 | actually build the entry in adjust_dynamic_symbol, |
| 6625 | because this might be a case of linking PIC code which is |
| 6626 | never referenced by a dynamic object, in which case we |
| 6627 | don't need to generate a procedure linkage table entry |
| 6628 | after all. */ |
| 6629 | |
| 6630 | /* If this is a local symbol, we resolve it directly without |
| 6631 | creating a procedure linkage table entry. */ |
| 6632 | if (h == NULL) |
| 6633 | continue; |
| 6634 | |
| 6635 | if (h->forced_local) |
| 6636 | break; |
| 6637 | |
| 6638 | h->needs_plt = 1; |
| 6639 | h->plt.refcount += 1; |
| 6640 | break; |
| 6641 | |
| 6642 | case R_SH_DIR32: |
| 6643 | case R_SH_REL32: |
| 6644 | #ifdef INCLUDE_SHMEDIA |
| 6645 | case R_SH_IMM_LOW16_PCREL: |
| 6646 | case R_SH_IMM_MEDLOW16_PCREL: |
| 6647 | case R_SH_IMM_MEDHI16_PCREL: |
| 6648 | case R_SH_IMM_HI16_PCREL: |
| 6649 | #endif |
| 6650 | if (h != NULL && ! info->shared) |
| 6651 | { |
| 6652 | h->non_got_ref = 1; |
| 6653 | h->plt.refcount += 1; |
| 6654 | } |
| 6655 | |
| 6656 | /* If we are creating a shared library, and this is a reloc |
| 6657 | against a global symbol, or a non PC relative reloc |
| 6658 | against a local symbol, then we need to copy the reloc |
| 6659 | into the shared library. However, if we are linking with |
| 6660 | -Bsymbolic, we do not need to copy a reloc against a |
| 6661 | global symbol which is defined in an object we are |
| 6662 | including in the link (i.e., DEF_REGULAR is set). At |
| 6663 | this point we have not seen all the input files, so it is |
| 6664 | possible that DEF_REGULAR is not set now but will be set |
| 6665 | later (it is never cleared). We account for that |
| 6666 | possibility below by storing information in the |
| 6667 | dyn_relocs field of the hash table entry. A similar |
| 6668 | situation occurs when creating shared libraries and symbol |
| 6669 | visibility changes render the symbol local. |
| 6670 | |
| 6671 | If on the other hand, we are creating an executable, we |
| 6672 | may need to keep relocations for symbols satisfied by a |
| 6673 | dynamic library if we manage to avoid copy relocs for the |
| 6674 | symbol. */ |
| 6675 | if ((info->shared |
| 6676 | && (sec->flags & SEC_ALLOC) != 0 |
| 6677 | && (r_type != R_SH_REL32 |
| 6678 | || (h != NULL |
| 6679 | && (! info->symbolic |
| 6680 | || h->root.type == bfd_link_hash_defweak |
| 6681 | || !h->def_regular)))) |
| 6682 | || (! info->shared |
| 6683 | && (sec->flags & SEC_ALLOC) != 0 |
| 6684 | && h != NULL |
| 6685 | && (h->root.type == bfd_link_hash_defweak |
| 6686 | || !h->def_regular))) |
| 6687 | { |
| 6688 | struct elf_sh_dyn_relocs *p; |
| 6689 | struct elf_sh_dyn_relocs **head; |
| 6690 | |
| 6691 | if (htab->root.dynobj == NULL) |
| 6692 | htab->root.dynobj = abfd; |
| 6693 | |
| 6694 | /* When creating a shared object, we must copy these |
| 6695 | reloc types into the output file. We create a reloc |
| 6696 | section in dynobj and make room for this reloc. */ |
| 6697 | if (sreloc == NULL) |
| 6698 | { |
| 6699 | const char *name; |
| 6700 | |
| 6701 | name = (bfd_elf_string_from_elf_section |
| 6702 | (abfd, |
| 6703 | elf_elfheader (abfd)->e_shstrndx, |
| 6704 | elf_section_data (sec)->rel_hdr.sh_name)); |
| 6705 | if (name == NULL) |
| 6706 | return FALSE; |
| 6707 | |
| 6708 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 |
| 6709 | && strcmp (bfd_get_section_name (abfd, sec), |
| 6710 | name + 5) == 0); |
| 6711 | |
| 6712 | sreloc = bfd_get_section_by_name (htab->root.dynobj, name); |
| 6713 | if (sreloc == NULL) |
| 6714 | { |
| 6715 | flagword flags; |
| 6716 | |
| 6717 | sreloc = bfd_make_section (htab->root.dynobj, name); |
| 6718 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
| 6719 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); |
| 6720 | if ((sec->flags & SEC_ALLOC) != 0) |
| 6721 | flags |= SEC_ALLOC | SEC_LOAD; |
| 6722 | if (sreloc == NULL |
| 6723 | || ! bfd_set_section_flags (htab->root.dynobj, |
| 6724 | sreloc, flags) |
| 6725 | || ! bfd_set_section_alignment (htab->root.dynobj, |
| 6726 | sreloc, 2)) |
| 6727 | return FALSE; |
| 6728 | } |
| 6729 | elf_section_data (sec)->sreloc = sreloc; |
| 6730 | } |
| 6731 | |
| 6732 | /* If this is a global symbol, we count the number of |
| 6733 | relocations we need for this symbol. */ |
| 6734 | if (h != NULL) |
| 6735 | head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs; |
| 6736 | else |
| 6737 | { |
| 6738 | asection *s; |
| 6739 | |
| 6740 | /* Track dynamic relocs needed for local syms too. */ |
| 6741 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, |
| 6742 | sec, r_symndx); |
| 6743 | if (s == NULL) |
| 6744 | return FALSE; |
| 6745 | |
| 6746 | head = ((struct elf_sh_dyn_relocs **) |
| 6747 | &elf_section_data (s)->local_dynrel); |
| 6748 | } |
| 6749 | |
| 6750 | p = *head; |
| 6751 | if (p == NULL || p->sec != sec) |
| 6752 | { |
| 6753 | bfd_size_type amt = sizeof (*p); |
| 6754 | p = bfd_alloc (htab->root.dynobj, amt); |
| 6755 | if (p == NULL) |
| 6756 | return FALSE; |
| 6757 | p->next = *head; |
| 6758 | *head = p; |
| 6759 | p->sec = sec; |
| 6760 | p->count = 0; |
| 6761 | p->pc_count = 0; |
| 6762 | } |
| 6763 | |
| 6764 | p->count += 1; |
| 6765 | if (r_type == R_SH_REL32 |
| 6766 | #ifdef INCLUDE_SHMEDIA |
| 6767 | || r_type == R_SH_IMM_LOW16_PCREL |
| 6768 | || r_type == R_SH_IMM_MEDLOW16_PCREL |
| 6769 | || r_type == R_SH_IMM_MEDHI16_PCREL |
| 6770 | || r_type == R_SH_IMM_HI16_PCREL |
| 6771 | #endif |
| 6772 | ) |
| 6773 | p->pc_count += 1; |
| 6774 | } |
| 6775 | |
| 6776 | break; |
| 6777 | |
| 6778 | case R_SH_TLS_LE_32: |
| 6779 | if (info->shared) |
| 6780 | { |
| 6781 | (*_bfd_error_handler) |
| 6782 | (_("%B: TLS local exec code cannot be linked into shared objects"), |
| 6783 | abfd); |
| 6784 | return FALSE; |
| 6785 | } |
| 6786 | |
| 6787 | break; |
| 6788 | |
| 6789 | case R_SH_TLS_LDO_32: |
| 6790 | /* Nothing to do. */ |
| 6791 | break; |
| 6792 | |
| 6793 | default: |
| 6794 | break; |
| 6795 | } |
| 6796 | } |
| 6797 | |
| 6798 | return TRUE; |
| 6799 | } |
| 6800 | |
| 6801 | #ifndef sh_elf_set_mach_from_flags |
| 6802 | static unsigned int sh_ef_bfd_table[] = { EF_SH_BFD_TABLE }; |
| 6803 | |
| 6804 | static bfd_boolean |
| 6805 | sh_elf_set_mach_from_flags (bfd *abfd) |
| 6806 | { |
| 6807 | flagword flags = elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK; |
| 6808 | |
| 6809 | if (flags >= sizeof(sh_ef_bfd_table)) |
| 6810 | return FALSE; |
| 6811 | |
| 6812 | if (sh_ef_bfd_table[flags] == 0) |
| 6813 | return FALSE; |
| 6814 | |
| 6815 | bfd_default_set_arch_mach (abfd, bfd_arch_sh, sh_ef_bfd_table[flags]); |
| 6816 | |
| 6817 | return TRUE; |
| 6818 | } |
| 6819 | |
| 6820 | |
| 6821 | /* Reverse table lookup for sh_ef_bfd_table[]. |
| 6822 | Given a bfd MACH value from archures.c |
| 6823 | return the equivalent ELF flags from the table. |
| 6824 | Return -1 if no match is found. */ |
| 6825 | |
| 6826 | int |
| 6827 | sh_elf_get_flags_from_mach (unsigned long mach) |
| 6828 | { |
| 6829 | int i = ARRAY_SIZE (sh_ef_bfd_table); |
| 6830 | |
| 6831 | for (; i>0; i--) |
| 6832 | if (sh_ef_bfd_table[i] == mach) |
| 6833 | return i; |
| 6834 | |
| 6835 | /* shouldn't get here */ |
| 6836 | BFD_FAIL(); |
| 6837 | |
| 6838 | return -1; |
| 6839 | } |
| 6840 | #endif /* not sh_elf_set_mach_from_flags */ |
| 6841 | |
| 6842 | #ifndef sh_elf_set_private_flags |
| 6843 | /* Function to keep SH specific file flags. */ |
| 6844 | |
| 6845 | static bfd_boolean |
| 6846 | sh_elf_set_private_flags (bfd *abfd, flagword flags) |
| 6847 | { |
| 6848 | BFD_ASSERT (! elf_flags_init (abfd) |
| 6849 | || elf_elfheader (abfd)->e_flags == flags); |
| 6850 | |
| 6851 | elf_elfheader (abfd)->e_flags = flags; |
| 6852 | elf_flags_init (abfd) = TRUE; |
| 6853 | return sh_elf_set_mach_from_flags (abfd); |
| 6854 | } |
| 6855 | #endif /* not sh_elf_set_private_flags */ |
| 6856 | |
| 6857 | #ifndef sh_elf_copy_private_data |
| 6858 | /* Copy backend specific data from one object module to another */ |
| 6859 | |
| 6860 | static bfd_boolean |
| 6861 | sh_elf_copy_private_data (bfd * ibfd, bfd * obfd) |
| 6862 | { |
| 6863 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 6864 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 6865 | return TRUE; |
| 6866 | |
| 6867 | return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags); |
| 6868 | } |
| 6869 | #endif /* not sh_elf_copy_private_data */ |
| 6870 | |
| 6871 | #ifndef sh_elf_merge_private_data |
| 6872 | |
| 6873 | /* This function returns the ELF architecture number that |
| 6874 | corresponds to the given arch_sh* flags. */ |
| 6875 | |
| 6876 | int |
| 6877 | sh_find_elf_flags (unsigned int arch_set) |
| 6878 | { |
| 6879 | extern unsigned long sh_get_bfd_mach_from_arch_set (unsigned int); |
| 6880 | unsigned long bfd_mach = sh_get_bfd_mach_from_arch_set (arch_set); |
| 6881 | |
| 6882 | return sh_elf_get_flags_from_mach (bfd_mach); |
| 6883 | } |
| 6884 | |
| 6885 | /* This routine initialises the elf flags when required and |
| 6886 | calls sh_merge_bfd_arch() to check dsp/fpu compatibility. */ |
| 6887 | |
| 6888 | static bfd_boolean |
| 6889 | sh_elf_merge_private_data (bfd *ibfd, bfd *obfd) |
| 6890 | { |
| 6891 | extern bfd_boolean sh_merge_bfd_arch (bfd *, bfd *); |
| 6892 | |
| 6893 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 6894 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 6895 | return TRUE; |
| 6896 | |
| 6897 | if (! elf_flags_init (obfd)) |
| 6898 | { |
| 6899 | /* This happens when ld starts out with a 'blank' output file. */ |
| 6900 | elf_flags_init (obfd) = TRUE; |
| 6901 | elf_elfheader (obfd)->e_flags = EF_SH1; |
| 6902 | sh_elf_set_mach_from_flags (obfd); |
| 6903 | } |
| 6904 | |
| 6905 | if (! sh_merge_bfd_arch (ibfd, obfd)) |
| 6906 | { |
| 6907 | _bfd_error_handler ("%B: uses instructions which are incompatible " |
| 6908 | "with instructions used in previous modules", |
| 6909 | ibfd); |
| 6910 | bfd_set_error (bfd_error_bad_value); |
| 6911 | return FALSE; |
| 6912 | } |
| 6913 | |
| 6914 | elf_elfheader (obfd)->e_flags = |
| 6915 | sh_elf_get_flags_from_mach (bfd_get_mach (obfd)); |
| 6916 | |
| 6917 | return TRUE; |
| 6918 | } |
| 6919 | #endif /* not sh_elf_merge_private_data */ |
| 6920 | |
| 6921 | /* Override the generic function because we need to store sh_elf_obj_tdata |
| 6922 | as the specific tdata. We set also the machine architecture from flags |
| 6923 | here. */ |
| 6924 | |
| 6925 | static bfd_boolean |
| 6926 | sh_elf_object_p (bfd *abfd) |
| 6927 | { |
| 6928 | return sh_elf_set_mach_from_flags (abfd); |
| 6929 | } |
| 6930 | |
| 6931 | /* Finish up dynamic symbol handling. We set the contents of various |
| 6932 | dynamic sections here. */ |
| 6933 | |
| 6934 | static bfd_boolean |
| 6935 | sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info, |
| 6936 | struct elf_link_hash_entry *h, |
| 6937 | Elf_Internal_Sym *sym) |
| 6938 | { |
| 6939 | struct elf_sh_link_hash_table *htab; |
| 6940 | |
| 6941 | htab = sh_elf_hash_table (info); |
| 6942 | |
| 6943 | if (h->plt.offset != (bfd_vma) -1) |
| 6944 | { |
| 6945 | asection *splt; |
| 6946 | asection *sgot; |
| 6947 | asection *srel; |
| 6948 | |
| 6949 | bfd_vma plt_index; |
| 6950 | bfd_vma got_offset; |
| 6951 | Elf_Internal_Rela rel; |
| 6952 | bfd_byte *loc; |
| 6953 | |
| 6954 | /* This symbol has an entry in the procedure linkage table. Set |
| 6955 | it up. */ |
| 6956 | |
| 6957 | BFD_ASSERT (h->dynindx != -1); |
| 6958 | |
| 6959 | splt = htab->splt; |
| 6960 | sgot = htab->sgotplt; |
| 6961 | srel = htab->srelplt; |
| 6962 | BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL); |
| 6963 | |
| 6964 | /* Get the index in the procedure linkage table which |
| 6965 | corresponds to this symbol. This is the index of this symbol |
| 6966 | in all the symbols for which we are making plt entries. The |
| 6967 | first entry in the procedure linkage table is reserved. */ |
| 6968 | plt_index = h->plt.offset / elf_sh_sizeof_plt (info) - 1; |
| 6969 | |
| 6970 | /* Get the offset into the .got table of the entry that |
| 6971 | corresponds to this function. Each .got entry is 4 bytes. |
| 6972 | The first three are reserved. */ |
| 6973 | got_offset = (plt_index + 3) * 4; |
| 6974 | |
| 6975 | #ifdef GOT_BIAS |
| 6976 | if (info->shared) |
| 6977 | got_offset -= GOT_BIAS; |
| 6978 | #endif |
| 6979 | |
| 6980 | /* Fill in the entry in the procedure linkage table. */ |
| 6981 | if (! info->shared) |
| 6982 | { |
| 6983 | if (elf_sh_plt_entry == NULL) |
| 6984 | { |
| 6985 | elf_sh_plt_entry = (bfd_big_endian (output_bfd) ? |
| 6986 | elf_sh_plt_entry_be : elf_sh_plt_entry_le); |
| 6987 | } |
| 6988 | memcpy (splt->contents + h->plt.offset, elf_sh_plt_entry, |
| 6989 | elf_sh_sizeof_plt (info)); |
| 6990 | #ifdef INCLUDE_SHMEDIA |
| 6991 | movi_shori_putval (output_bfd, |
| 6992 | (sgot->output_section->vma |
| 6993 | + sgot->output_offset |
| 6994 | + got_offset), |
| 6995 | (splt->contents + h->plt.offset |
| 6996 | + elf_sh_plt_symbol_offset (info))); |
| 6997 | |
| 6998 | /* Set bottom bit because its for a branch to SHmedia */ |
| 6999 | movi_shori_putval (output_bfd, |
| 7000 | (splt->output_section->vma + splt->output_offset) |
| 7001 | | 1, |
| 7002 | (splt->contents + h->plt.offset |
| 7003 | + elf_sh_plt_plt0_offset (info))); |
| 7004 | #else |
| 7005 | bfd_put_32 (output_bfd, |
| 7006 | (sgot->output_section->vma |
| 7007 | + sgot->output_offset |
| 7008 | + got_offset), |
| 7009 | (splt->contents + h->plt.offset |
| 7010 | + elf_sh_plt_symbol_offset (info))); |
| 7011 | |
| 7012 | bfd_put_32 (output_bfd, |
| 7013 | (splt->output_section->vma + splt->output_offset), |
| 7014 | (splt->contents + h->plt.offset |
| 7015 | + elf_sh_plt_plt0_offset (info))); |
| 7016 | #endif |
| 7017 | } |
| 7018 | else |
| 7019 | { |
| 7020 | if (elf_sh_pic_plt_entry == NULL) |
| 7021 | { |
| 7022 | elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ? |
| 7023 | elf_sh_pic_plt_entry_be : |
| 7024 | elf_sh_pic_plt_entry_le); |
| 7025 | } |
| 7026 | memcpy (splt->contents + h->plt.offset, elf_sh_pic_plt_entry, |
| 7027 | elf_sh_sizeof_plt (info)); |
| 7028 | #ifdef INCLUDE_SHMEDIA |
| 7029 | movi_shori_putval (output_bfd, got_offset, |
| 7030 | (splt->contents + h->plt.offset |
| 7031 | + elf_sh_plt_symbol_offset (info))); |
| 7032 | #else |
| 7033 | bfd_put_32 (output_bfd, got_offset, |
| 7034 | (splt->contents + h->plt.offset |
| 7035 | + elf_sh_plt_symbol_offset (info))); |
| 7036 | #endif |
| 7037 | } |
| 7038 | |
| 7039 | #ifdef GOT_BIAS |
| 7040 | if (info->shared) |
| 7041 | got_offset += GOT_BIAS; |
| 7042 | #endif |
| 7043 | |
| 7044 | #ifdef INCLUDE_SHMEDIA |
| 7045 | movi_shori_putval (output_bfd, |
| 7046 | plt_index * sizeof (Elf32_External_Rela), |
| 7047 | (splt->contents + h->plt.offset |
| 7048 | + elf_sh_plt_reloc_offset (info))); |
| 7049 | #else |
| 7050 | bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), |
| 7051 | (splt->contents + h->plt.offset |
| 7052 | + elf_sh_plt_reloc_offset (info))); |
| 7053 | #endif |
| 7054 | |
| 7055 | /* Fill in the entry in the global offset table. */ |
| 7056 | bfd_put_32 (output_bfd, |
| 7057 | (splt->output_section->vma |
| 7058 | + splt->output_offset |
| 7059 | + h->plt.offset |
| 7060 | + elf_sh_plt_temp_offset (info)), |
| 7061 | sgot->contents + got_offset); |
| 7062 | |
| 7063 | /* Fill in the entry in the .rela.plt section. */ |
| 7064 | rel.r_offset = (sgot->output_section->vma |
| 7065 | + sgot->output_offset |
| 7066 | + got_offset); |
| 7067 | rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT); |
| 7068 | rel.r_addend = 0; |
| 7069 | #ifdef GOT_BIAS |
| 7070 | rel.r_addend = GOT_BIAS; |
| 7071 | #endif |
| 7072 | loc = srel->contents + plt_index * sizeof (Elf32_External_Rela); |
| 7073 | bfd_elf32_swap_reloca_out (output_bfd, &rel, loc); |
| 7074 | |
| 7075 | if (!h->def_regular) |
| 7076 | { |
| 7077 | /* Mark the symbol as undefined, rather than as defined in |
| 7078 | the .plt section. Leave the value alone. */ |
| 7079 | sym->st_shndx = SHN_UNDEF; |
| 7080 | } |
| 7081 | } |
| 7082 | |
| 7083 | if (h->got.offset != (bfd_vma) -1 |
| 7084 | && sh_elf_hash_entry (h)->tls_type != GOT_TLS_GD |
| 7085 | && sh_elf_hash_entry (h)->tls_type != GOT_TLS_IE) |
| 7086 | { |
| 7087 | asection *sgot; |
| 7088 | asection *srel; |
| 7089 | Elf_Internal_Rela rel; |
| 7090 | bfd_byte *loc; |
| 7091 | |
| 7092 | /* This symbol has an entry in the global offset table. Set it |
| 7093 | up. */ |
| 7094 | |
| 7095 | sgot = htab->sgot; |
| 7096 | srel = htab->srelgot; |
| 7097 | BFD_ASSERT (sgot != NULL && srel != NULL); |
| 7098 | |
| 7099 | rel.r_offset = (sgot->output_section->vma |
| 7100 | + sgot->output_offset |
| 7101 | + (h->got.offset &~ (bfd_vma) 1)); |
| 7102 | |
| 7103 | /* If this is a static link, or it is a -Bsymbolic link and the |
| 7104 | symbol is defined locally or was forced to be local because |
| 7105 | of a version file, we just want to emit a RELATIVE reloc. |
| 7106 | The entry in the global offset table will already have been |
| 7107 | initialized in the relocate_section function. */ |
| 7108 | if (info->shared |
| 7109 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
| 7110 | { |
| 7111 | rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE); |
| 7112 | rel.r_addend = (h->root.u.def.value |
| 7113 | + h->root.u.def.section->output_section->vma |
| 7114 | + h->root.u.def.section->output_offset); |
| 7115 | } |
| 7116 | else |
| 7117 | { |
| 7118 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); |
| 7119 | rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT); |
| 7120 | rel.r_addend = 0; |
| 7121 | } |
| 7122 | |
| 7123 | loc = srel->contents; |
| 7124 | loc += srel->reloc_count++ * sizeof (Elf32_External_Rela); |
| 7125 | bfd_elf32_swap_reloca_out (output_bfd, &rel, loc); |
| 7126 | } |
| 7127 | |
| 7128 | #ifdef INCLUDE_SHMEDIA |
| 7129 | { |
| 7130 | struct elf_sh_link_hash_entry *eh; |
| 7131 | |
| 7132 | eh = (struct elf_sh_link_hash_entry *) h; |
| 7133 | if (eh->datalabel_got.offset != (bfd_vma) -1) |
| 7134 | { |
| 7135 | asection *sgot; |
| 7136 | asection *srel; |
| 7137 | Elf_Internal_Rela rel; |
| 7138 | bfd_byte *loc; |
| 7139 | |
| 7140 | /* This symbol has a datalabel entry in the global offset table. |
| 7141 | Set it up. */ |
| 7142 | |
| 7143 | sgot = htab->sgot; |
| 7144 | srel = htab->srelgot; |
| 7145 | BFD_ASSERT (sgot != NULL && srel != NULL); |
| 7146 | |
| 7147 | rel.r_offset = (sgot->output_section->vma |
| 7148 | + sgot->output_offset |
| 7149 | + (eh->datalabel_got.offset &~ (bfd_vma) 1)); |
| 7150 | |
| 7151 | /* If this is a static link, or it is a -Bsymbolic link and the |
| 7152 | symbol is defined locally or was forced to be local because |
| 7153 | of a version file, we just want to emit a RELATIVE reloc. |
| 7154 | The entry in the global offset table will already have been |
| 7155 | initialized in the relocate_section function. */ |
| 7156 | if (info->shared |
| 7157 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
| 7158 | { |
| 7159 | rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE); |
| 7160 | rel.r_addend = (h->root.u.def.value |
| 7161 | + h->root.u.def.section->output_section->vma |
| 7162 | + h->root.u.def.section->output_offset); |
| 7163 | } |
| 7164 | else |
| 7165 | { |
| 7166 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents |
| 7167 | + eh->datalabel_got.offset); |
| 7168 | rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT); |
| 7169 | rel.r_addend = 0; |
| 7170 | } |
| 7171 | |
| 7172 | loc = srel->contents; |
| 7173 | loc += srel->reloc_count++ * sizeof (Elf32_External_Rela); |
| 7174 | bfd_elf32_swap_reloca_out (output_bfd, &rel, loc); |
| 7175 | } |
| 7176 | } |
| 7177 | #endif |
| 7178 | |
| 7179 | if (h->needs_copy) |
| 7180 | { |
| 7181 | asection *s; |
| 7182 | Elf_Internal_Rela rel; |
| 7183 | bfd_byte *loc; |
| 7184 | |
| 7185 | /* This symbol needs a copy reloc. Set it up. */ |
| 7186 | |
| 7187 | BFD_ASSERT (h->dynindx != -1 |
| 7188 | && (h->root.type == bfd_link_hash_defined |
| 7189 | || h->root.type == bfd_link_hash_defweak)); |
| 7190 | |
| 7191 | s = bfd_get_section_by_name (h->root.u.def.section->owner, |
| 7192 | ".rela.bss"); |
| 7193 | BFD_ASSERT (s != NULL); |
| 7194 | |
| 7195 | rel.r_offset = (h->root.u.def.value |
| 7196 | + h->root.u.def.section->output_section->vma |
| 7197 | + h->root.u.def.section->output_offset); |
| 7198 | rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY); |
| 7199 | rel.r_addend = 0; |
| 7200 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); |
| 7201 | bfd_elf32_swap_reloca_out (output_bfd, &rel, loc); |
| 7202 | } |
| 7203 | |
| 7204 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ |
| 7205 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
| 7206 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
| 7207 | sym->st_shndx = SHN_ABS; |
| 7208 | |
| 7209 | return TRUE; |
| 7210 | } |
| 7211 | |
| 7212 | /* Finish up the dynamic sections. */ |
| 7213 | |
| 7214 | static bfd_boolean |
| 7215 | sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) |
| 7216 | { |
| 7217 | struct elf_sh_link_hash_table *htab; |
| 7218 | asection *sgot; |
| 7219 | asection *sdyn; |
| 7220 | |
| 7221 | htab = sh_elf_hash_table (info); |
| 7222 | sgot = htab->sgotplt; |
| 7223 | sdyn = bfd_get_section_by_name (htab->root.dynobj, ".dynamic"); |
| 7224 | |
| 7225 | if (htab->root.dynamic_sections_created) |
| 7226 | { |
| 7227 | asection *splt; |
| 7228 | Elf32_External_Dyn *dyncon, *dynconend; |
| 7229 | |
| 7230 | BFD_ASSERT (sgot != NULL && sdyn != NULL); |
| 7231 | |
| 7232 | dyncon = (Elf32_External_Dyn *) sdyn->contents; |
| 7233 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
| 7234 | for (; dyncon < dynconend; dyncon++) |
| 7235 | { |
| 7236 | Elf_Internal_Dyn dyn; |
| 7237 | asection *s; |
| 7238 | #ifdef INCLUDE_SHMEDIA |
| 7239 | const char *name; |
| 7240 | #endif |
| 7241 | |
| 7242 | bfd_elf32_swap_dyn_in (htab->root.dynobj, dyncon, &dyn); |
| 7243 | |
| 7244 | switch (dyn.d_tag) |
| 7245 | { |
| 7246 | default: |
| 7247 | break; |
| 7248 | |
| 7249 | #ifdef INCLUDE_SHMEDIA |
| 7250 | case DT_INIT: |
| 7251 | name = info->init_function; |
| 7252 | goto get_sym; |
| 7253 | |
| 7254 | case DT_FINI: |
| 7255 | name = info->fini_function; |
| 7256 | get_sym: |
| 7257 | if (dyn.d_un.d_val != 0) |
| 7258 | { |
| 7259 | struct elf_link_hash_entry *h; |
| 7260 | |
| 7261 | h = elf_link_hash_lookup (&htab->root, name, |
| 7262 | FALSE, FALSE, TRUE); |
| 7263 | if (h != NULL && (h->other & STO_SH5_ISA32)) |
| 7264 | { |
| 7265 | dyn.d_un.d_val |= 1; |
| 7266 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 7267 | } |
| 7268 | } |
| 7269 | break; |
| 7270 | #endif |
| 7271 | |
| 7272 | case DT_PLTGOT: |
| 7273 | s = htab->sgot->output_section; |
| 7274 | goto get_vma; |
| 7275 | |
| 7276 | case DT_JMPREL: |
| 7277 | s = htab->srelplt->output_section; |
| 7278 | get_vma: |
| 7279 | BFD_ASSERT (s != NULL); |
| 7280 | dyn.d_un.d_ptr = s->vma; |
| 7281 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 7282 | break; |
| 7283 | |
| 7284 | case DT_PLTRELSZ: |
| 7285 | s = htab->srelplt->output_section; |
| 7286 | BFD_ASSERT (s != NULL); |
| 7287 | dyn.d_un.d_val = s->size; |
| 7288 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 7289 | break; |
| 7290 | |
| 7291 | case DT_RELASZ: |
| 7292 | /* My reading of the SVR4 ABI indicates that the |
| 7293 | procedure linkage table relocs (DT_JMPREL) should be |
| 7294 | included in the overall relocs (DT_RELA). This is |
| 7295 | what Solaris does. However, UnixWare can not handle |
| 7296 | that case. Therefore, we override the DT_RELASZ entry |
| 7297 | here to make it not include the JMPREL relocs. Since |
| 7298 | the linker script arranges for .rela.plt to follow all |
| 7299 | other relocation sections, we don't have to worry |
| 7300 | about changing the DT_RELA entry. */ |
| 7301 | if (htab->srelplt != NULL) |
| 7302 | { |
| 7303 | s = htab->srelplt->output_section; |
| 7304 | dyn.d_un.d_val -= s->size; |
| 7305 | } |
| 7306 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 7307 | break; |
| 7308 | } |
| 7309 | } |
| 7310 | |
| 7311 | /* Fill in the first entry in the procedure linkage table. */ |
| 7312 | splt = htab->splt; |
| 7313 | if (splt && splt->size > 0) |
| 7314 | { |
| 7315 | if (info->shared) |
| 7316 | { |
| 7317 | if (elf_sh_pic_plt_entry == NULL) |
| 7318 | { |
| 7319 | elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ? |
| 7320 | elf_sh_pic_plt_entry_be : |
| 7321 | elf_sh_pic_plt_entry_le); |
| 7322 | } |
| 7323 | memcpy (splt->contents, elf_sh_pic_plt_entry, |
| 7324 | elf_sh_sizeof_plt (info)); |
| 7325 | } |
| 7326 | else |
| 7327 | { |
| 7328 | if (elf_sh_plt0_entry == NULL) |
| 7329 | { |
| 7330 | elf_sh_plt0_entry = (bfd_big_endian (output_bfd) ? |
| 7331 | elf_sh_plt0_entry_be : |
| 7332 | elf_sh_plt0_entry_le); |
| 7333 | } |
| 7334 | memcpy (splt->contents, elf_sh_plt0_entry, PLT_ENTRY_SIZE); |
| 7335 | #ifdef INCLUDE_SHMEDIA |
| 7336 | movi_shori_putval (output_bfd, |
| 7337 | sgot->output_section->vma |
| 7338 | + sgot->output_offset, |
| 7339 | splt->contents |
| 7340 | + elf_sh_plt0_gotplt_offset (info)); |
| 7341 | #else |
| 7342 | bfd_put_32 (output_bfd, |
| 7343 | sgot->output_section->vma + sgot->output_offset + 4, |
| 7344 | splt->contents + elf_sh_plt0_gotid_offset (info)); |
| 7345 | bfd_put_32 (output_bfd, |
| 7346 | sgot->output_section->vma + sgot->output_offset + 8, |
| 7347 | splt->contents + elf_sh_plt0_linker_offset (info)); |
| 7348 | #endif |
| 7349 | } |
| 7350 | |
| 7351 | /* UnixWare sets the entsize of .plt to 4, although that doesn't |
| 7352 | really seem like the right value. */ |
| 7353 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; |
| 7354 | } |
| 7355 | } |
| 7356 | |
| 7357 | /* Fill in the first three entries in the global offset table. */ |
| 7358 | if (sgot && sgot->size > 0) |
| 7359 | { |
| 7360 | if (sdyn == NULL) |
| 7361 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); |
| 7362 | else |
| 7363 | bfd_put_32 (output_bfd, |
| 7364 | sdyn->output_section->vma + sdyn->output_offset, |
| 7365 | sgot->contents); |
| 7366 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); |
| 7367 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); |
| 7368 | |
| 7369 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
| 7370 | } |
| 7371 | |
| 7372 | return TRUE; |
| 7373 | } |
| 7374 | |
| 7375 | static enum elf_reloc_type_class |
| 7376 | sh_elf_reloc_type_class (const Elf_Internal_Rela *rela) |
| 7377 | { |
| 7378 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
| 7379 | { |
| 7380 | case R_SH_RELATIVE: |
| 7381 | return reloc_class_relative; |
| 7382 | case R_SH_JMP_SLOT: |
| 7383 | return reloc_class_plt; |
| 7384 | case R_SH_COPY: |
| 7385 | return reloc_class_copy; |
| 7386 | default: |
| 7387 | return reloc_class_normal; |
| 7388 | } |
| 7389 | } |
| 7390 | |
| 7391 | #if !defined SH_TARGET_ALREADY_DEFINED |
| 7392 | /* Support for Linux core dump NOTE sections. */ |
| 7393 | |
| 7394 | static bfd_boolean |
| 7395 | elf32_shlin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
| 7396 | { |
| 7397 | int offset; |
| 7398 | unsigned int size; |
| 7399 | |
| 7400 | switch (note->descsz) |
| 7401 | { |
| 7402 | default: |
| 7403 | return FALSE; |
| 7404 | |
| 7405 | case 168: /* Linux/SH */ |
| 7406 | /* pr_cursig */ |
| 7407 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); |
| 7408 | |
| 7409 | /* pr_pid */ |
| 7410 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); |
| 7411 | |
| 7412 | /* pr_reg */ |
| 7413 | offset = 72; |
| 7414 | size = 92; |
| 7415 | |
| 7416 | break; |
| 7417 | } |
| 7418 | |
| 7419 | /* Make a ".reg/999" section. */ |
| 7420 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", |
| 7421 | size, note->descpos + offset); |
| 7422 | } |
| 7423 | |
| 7424 | static bfd_boolean |
| 7425 | elf32_shlin_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
| 7426 | { |
| 7427 | switch (note->descsz) |
| 7428 | { |
| 7429 | default: |
| 7430 | return FALSE; |
| 7431 | |
| 7432 | case 124: /* Linux/SH elf_prpsinfo */ |
| 7433 | elf_tdata (abfd)->core_program |
| 7434 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); |
| 7435 | elf_tdata (abfd)->core_command |
| 7436 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); |
| 7437 | } |
| 7438 | |
| 7439 | /* Note that for some reason, a spurious space is tacked |
| 7440 | onto the end of the args in some (at least one anyway) |
| 7441 | implementations, so strip it off if it exists. */ |
| 7442 | |
| 7443 | { |
| 7444 | char *command = elf_tdata (abfd)->core_command; |
| 7445 | int n = strlen (command); |
| 7446 | |
| 7447 | if (0 < n && command[n - 1] == ' ') |
| 7448 | command[n - 1] = '\0'; |
| 7449 | } |
| 7450 | |
| 7451 | return TRUE; |
| 7452 | } |
| 7453 | #endif /* not SH_TARGET_ALREADY_DEFINED */ |
| 7454 | |
| 7455 | |
| 7456 | /* Return address for Ith PLT stub in section PLT, for relocation REL |
| 7457 | or (bfd_vma) -1 if it should not be included. */ |
| 7458 | |
| 7459 | static bfd_vma |
| 7460 | sh_elf_plt_sym_val (bfd_vma i, const asection *plt, |
| 7461 | const arelent *rel ATTRIBUTE_UNUSED) |
| 7462 | { |
| 7463 | return plt->vma + (i + 1) * PLT_ENTRY_SIZE; |
| 7464 | } |
| 7465 | |
| 7466 | #if !defined SH_TARGET_ALREADY_DEFINED |
| 7467 | #define TARGET_BIG_SYM bfd_elf32_sh_vec |
| 7468 | #define TARGET_BIG_NAME "elf32-sh" |
| 7469 | #define TARGET_LITTLE_SYM bfd_elf32_shl_vec |
| 7470 | #define TARGET_LITTLE_NAME "elf32-shl" |
| 7471 | #endif |
| 7472 | |
| 7473 | #define ELF_ARCH bfd_arch_sh |
| 7474 | #define ELF_MACHINE_CODE EM_SH |
| 7475 | #ifdef __QNXTARGET__ |
| 7476 | #define ELF_MAXPAGESIZE 0x1000 |
| 7477 | #else |
| 7478 | #define ELF_MAXPAGESIZE 0x80 |
| 7479 | #endif |
| 7480 | |
| 7481 | #define elf_symbol_leading_char '_' |
| 7482 | |
| 7483 | #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup |
| 7484 | #define elf_info_to_howto sh_elf_info_to_howto |
| 7485 | #define bfd_elf32_bfd_relax_section sh_elf_relax_section |
| 7486 | #define elf_backend_relocate_section sh_elf_relocate_section |
| 7487 | #define bfd_elf32_bfd_get_relocated_section_contents \ |
| 7488 | sh_elf_get_relocated_section_contents |
| 7489 | #define bfd_elf32_mkobject sh_elf_mkobject |
| 7490 | #define elf_backend_object_p sh_elf_object_p |
| 7491 | #define bfd_elf32_bfd_set_private_bfd_flags \ |
| 7492 | sh_elf_set_private_flags |
| 7493 | #define bfd_elf32_bfd_copy_private_bfd_data \ |
| 7494 | sh_elf_copy_private_data |
| 7495 | #define bfd_elf32_bfd_merge_private_bfd_data \ |
| 7496 | sh_elf_merge_private_data |
| 7497 | |
| 7498 | #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook |
| 7499 | #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook |
| 7500 | #define elf_backend_check_relocs sh_elf_check_relocs |
| 7501 | #define elf_backend_copy_indirect_symbol \ |
| 7502 | sh_elf_copy_indirect_symbol |
| 7503 | #define elf_backend_create_dynamic_sections \ |
| 7504 | sh_elf_create_dynamic_sections |
| 7505 | #define bfd_elf32_bfd_link_hash_table_create \ |
| 7506 | sh_elf_link_hash_table_create |
| 7507 | #define elf_backend_adjust_dynamic_symbol \ |
| 7508 | sh_elf_adjust_dynamic_symbol |
| 7509 | #define elf_backend_size_dynamic_sections \ |
| 7510 | sh_elf_size_dynamic_sections |
| 7511 | #define elf_backend_finish_dynamic_symbol \ |
| 7512 | sh_elf_finish_dynamic_symbol |
| 7513 | #define elf_backend_finish_dynamic_sections \ |
| 7514 | sh_elf_finish_dynamic_sections |
| 7515 | #define elf_backend_reloc_type_class sh_elf_reloc_type_class |
| 7516 | #define elf_backend_plt_sym_val sh_elf_plt_sym_val |
| 7517 | |
| 7518 | #define elf_backend_can_gc_sections 1 |
| 7519 | #define elf_backend_can_refcount 1 |
| 7520 | #define elf_backend_want_got_plt 1 |
| 7521 | #define elf_backend_plt_readonly 1 |
| 7522 | #define elf_backend_want_plt_sym 0 |
| 7523 | #define elf_backend_got_header_size 12 |
| 7524 | |
| 7525 | #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED |
| 7526 | |
| 7527 | #include "elf32-target.h" |
| 7528 | |
| 7529 | /* NetBSD support. */ |
| 7530 | #undef TARGET_BIG_SYM |
| 7531 | #define TARGET_BIG_SYM bfd_elf32_shnbsd_vec |
| 7532 | #undef TARGET_BIG_NAME |
| 7533 | #define TARGET_BIG_NAME "elf32-sh-nbsd" |
| 7534 | #undef TARGET_LITTLE_SYM |
| 7535 | #define TARGET_LITTLE_SYM bfd_elf32_shlnbsd_vec |
| 7536 | #undef TARGET_LITTLE_NAME |
| 7537 | #define TARGET_LITTLE_NAME "elf32-shl-nbsd" |
| 7538 | #undef ELF_MAXPAGESIZE |
| 7539 | #define ELF_MAXPAGESIZE 0x10000 |
| 7540 | #undef elf_symbol_leading_char |
| 7541 | #define elf_symbol_leading_char 0 |
| 7542 | #undef elf32_bed |
| 7543 | #define elf32_bed elf32_sh_nbsd_bed |
| 7544 | |
| 7545 | #include "elf32-target.h" |
| 7546 | |
| 7547 | |
| 7548 | /* Linux support. */ |
| 7549 | #undef TARGET_BIG_SYM |
| 7550 | #define TARGET_BIG_SYM bfd_elf32_shblin_vec |
| 7551 | #undef TARGET_BIG_NAME |
| 7552 | #define TARGET_BIG_NAME "elf32-shbig-linux" |
| 7553 | #undef TARGET_LITTLE_SYM |
| 7554 | #define TARGET_LITTLE_SYM bfd_elf32_shlin_vec |
| 7555 | #undef TARGET_LITTLE_NAME |
| 7556 | #define TARGET_LITTLE_NAME "elf32-sh-linux" |
| 7557 | |
| 7558 | #undef elf_backend_grok_prstatus |
| 7559 | #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus |
| 7560 | #undef elf_backend_grok_psinfo |
| 7561 | #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo |
| 7562 | #undef elf32_bed |
| 7563 | #define elf32_bed elf32_sh_lin_bed |
| 7564 | |
| 7565 | #include "elf32-target.h" |
| 7566 | |
| 7567 | #endif /* neither INCLUDE_SHMEDIA nor SH_TARGET_ALREADY_DEFINED */ |