| 1 | /* SuperH SH64-specific support for 64-bit ELF |
| 2 | Copyright (C) 2000-2018 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of BFD, the Binary File Descriptor library. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
| 19 | MA 02110-1301, USA. */ |
| 20 | |
| 21 | #define SH64_ELF64 |
| 22 | |
| 23 | #include "sysdep.h" |
| 24 | #include "bfd.h" |
| 25 | #include "bfdlink.h" |
| 26 | #include "libbfd.h" |
| 27 | #include "elf-bfd.h" |
| 28 | #include "elf/sh.h" |
| 29 | |
| 30 | /* Add a suffix for datalabel indirection symbols. It must not match any |
| 31 | other symbols; user symbols with or without version or other |
| 32 | decoration. It must only be used internally and not emitted by any |
| 33 | means. */ |
| 34 | #define DATALABEL_SUFFIX " DL" |
| 35 | |
| 36 | #define GOT_BIAS (-((long)-32768)) |
| 37 | |
| 38 | #define PLT_ENTRY_SIZE 64 |
| 39 | |
| 40 | /* Return size of a PLT entry. */ |
| 41 | #define elf_sh64_sizeof_plt(info) PLT_ENTRY_SIZE |
| 42 | |
| 43 | /* Return offset of the PLT0 address in an absolute PLT entry. */ |
| 44 | #define elf_sh64_plt_plt0_offset(info) 32 |
| 45 | |
| 46 | /* Return offset of the linker in PLT0 entry. */ |
| 47 | #define elf_sh64_plt0_gotplt_offset(info) 0 |
| 48 | |
| 49 | /* Return offset of the trampoline in PLT entry */ |
| 50 | #define elf_sh64_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */ |
| 51 | |
| 52 | /* Return offset of the symbol in PLT entry. */ |
| 53 | #define elf_sh64_plt_symbol_offset(info) 0 |
| 54 | |
| 55 | /* Return offset of the relocation in PLT entry. */ |
| 56 | #define elf_sh64_plt_reloc_offset(info) (bfd_link_pic (info) ? 52 : 44) |
| 57 | |
| 58 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1" |
| 59 | |
| 60 | /* The sh linker needs to keep track of the number of relocs that it |
| 61 | decides to copy in check_relocs for each symbol. This is so that |
| 62 | it can discard PC relative relocs if it doesn't need them when |
| 63 | linking with -Bsymbolic. We store the information in a field |
| 64 | extending the regular ELF linker hash table. */ |
| 65 | |
| 66 | /* This structure keeps track of the number of PC relative relocs we |
| 67 | have copied for a given symbol. */ |
| 68 | |
| 69 | struct elf_sh64_pcrel_relocs_copied |
| 70 | { |
| 71 | /* Next section. */ |
| 72 | struct elf_sh64_pcrel_relocs_copied *next; |
| 73 | /* A section in dynobj. */ |
| 74 | asection *section; |
| 75 | /* Number of relocs copied in this section. */ |
| 76 | bfd_size_type count; |
| 77 | }; |
| 78 | |
| 79 | /* sh ELF linker hash entry. */ |
| 80 | |
| 81 | struct elf_sh64_link_hash_entry |
| 82 | { |
| 83 | struct elf_link_hash_entry root; |
| 84 | |
| 85 | bfd_vma datalabel_got_offset; |
| 86 | |
| 87 | /* Number of PC relative relocs copied for this symbol. */ |
| 88 | struct elf_sh64_pcrel_relocs_copied *pcrel_relocs_copied; |
| 89 | }; |
| 90 | |
| 91 | /* Traverse an sh ELF linker hash table. */ |
| 92 | |
| 93 | #define sh64_elf64_link_hash_traverse(table, func, info) \ |
| 94 | (elf_link_hash_traverse \ |
| 95 | ((table), \ |
| 96 | (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ |
| 97 | (info))) |
| 98 | |
| 99 | static bfd_reloc_status_type sh_elf64_ignore_reloc |
| 100 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 101 | static bfd_reloc_status_type sh_elf64_reloc |
| 102 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 103 | |
| 104 | static reloc_howto_type sh_elf64_howto_table[] = { |
| 105 | /* No relocation. */ |
| 106 | HOWTO (R_SH_NONE, /* type */ |
| 107 | 0, /* rightshift */ |
| 108 | 3, /* size (0 = byte, 1 = short, 2 = long) */ |
| 109 | 0, /* bitsize */ |
| 110 | FALSE, /* pc_relative */ |
| 111 | 0, /* bitpos */ |
| 112 | complain_overflow_dont, /* complain_on_overflow */ |
| 113 | sh_elf64_ignore_reloc, /* special_function */ |
| 114 | "R_SH_NONE", /* name */ |
| 115 | FALSE, /* partial_inplace */ |
| 116 | 0, /* src_mask */ |
| 117 | 0, /* dst_mask */ |
| 118 | FALSE), /* pcrel_offset */ |
| 119 | |
| 120 | /* 32 bit absolute relocation. Setting partial_inplace to TRUE and |
| 121 | src_mask to a non-zero value is similar to the COFF toolchain. */ |
| 122 | HOWTO (R_SH_DIR32, /* type */ |
| 123 | 0, /* rightshift */ |
| 124 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 125 | 32, /* bitsize */ |
| 126 | FALSE, /* pc_relative */ |
| 127 | 0, /* bitpos */ |
| 128 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 129 | sh_elf64_reloc, /* special_function */ |
| 130 | "R_SH_DIR32", /* name */ |
| 131 | TRUE, /* partial_inplace */ |
| 132 | 0xffffffff, /* src_mask */ |
| 133 | 0xffffffff, /* dst_mask */ |
| 134 | FALSE), /* pcrel_offset */ |
| 135 | |
| 136 | /* 32 bit PC relative relocation. */ |
| 137 | HOWTO (R_SH_REL32, /* type */ |
| 138 | 0, /* rightshift */ |
| 139 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 140 | 32, /* bitsize */ |
| 141 | TRUE, /* pc_relative */ |
| 142 | 0, /* bitpos */ |
| 143 | complain_overflow_signed, /* complain_on_overflow */ |
| 144 | sh_elf64_ignore_reloc, /* special_function */ |
| 145 | "R_SH_REL32", /* name */ |
| 146 | FALSE, /* partial_inplace */ |
| 147 | 0, /* src_mask */ |
| 148 | 0xffffffff, /* dst_mask */ |
| 149 | TRUE), /* pcrel_offset */ |
| 150 | |
| 151 | /* For 32-bit sh, this is R_SH_DIR8WPN. */ |
| 152 | EMPTY_HOWTO (3), |
| 153 | |
| 154 | /* For 32-bit sh, this is R_SH_IND12W. */ |
| 155 | EMPTY_HOWTO (4), |
| 156 | |
| 157 | /* For 32-bit sh, this is R_SH_DIR8WPL. */ |
| 158 | EMPTY_HOWTO (5), |
| 159 | |
| 160 | /* For 32-bit sh, this is R_SH_DIR8WPZ. */ |
| 161 | EMPTY_HOWTO (6), |
| 162 | |
| 163 | /* For 32-bit sh, this is R_SH_DIR8BP. */ |
| 164 | EMPTY_HOWTO (7), |
| 165 | |
| 166 | /* For 32-bit sh, this is R_SH_DIR8W. */ |
| 167 | EMPTY_HOWTO (8), |
| 168 | |
| 169 | /* For 32-bit sh, this is R_SH_DIR8L. */ |
| 170 | EMPTY_HOWTO (9), |
| 171 | |
| 172 | EMPTY_HOWTO (10), |
| 173 | EMPTY_HOWTO (11), |
| 174 | EMPTY_HOWTO (12), |
| 175 | EMPTY_HOWTO (13), |
| 176 | EMPTY_HOWTO (14), |
| 177 | EMPTY_HOWTO (15), |
| 178 | EMPTY_HOWTO (16), |
| 179 | EMPTY_HOWTO (17), |
| 180 | EMPTY_HOWTO (18), |
| 181 | EMPTY_HOWTO (19), |
| 182 | EMPTY_HOWTO (20), |
| 183 | EMPTY_HOWTO (21), |
| 184 | EMPTY_HOWTO (22), |
| 185 | EMPTY_HOWTO (23), |
| 186 | EMPTY_HOWTO (24), |
| 187 | |
| 188 | /* The remaining relocs are a GNU extension used for relaxing. The |
| 189 | final pass of the linker never needs to do anything with any of |
| 190 | these relocs. Any required operations are handled by the |
| 191 | relaxation code. */ |
| 192 | |
| 193 | /* A 16 bit switch table entry. This is generated for an expression |
| 194 | such as ``.word L1 - L2''. The offset holds the difference |
| 195 | between the reloc address and L2. */ |
| 196 | HOWTO (R_SH_SWITCH16, /* type */ |
| 197 | 0, /* rightshift */ |
| 198 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 199 | 16, /* bitsize */ |
| 200 | FALSE, /* pc_relative */ |
| 201 | 0, /* bitpos */ |
| 202 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 203 | sh_elf64_ignore_reloc, /* special_function */ |
| 204 | "R_SH_SWITCH16", /* name */ |
| 205 | FALSE, /* partial_inplace */ |
| 206 | 0, /* src_mask */ |
| 207 | 0, /* dst_mask */ |
| 208 | TRUE), /* pcrel_offset */ |
| 209 | |
| 210 | /* A 32 bit switch table entry. This is generated for an expression |
| 211 | such as ``.long L1 - L2''. The offset holds the difference |
| 212 | between the reloc address and L2. */ |
| 213 | HOWTO (R_SH_SWITCH32, /* type */ |
| 214 | 0, /* rightshift */ |
| 215 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 216 | 32, /* bitsize */ |
| 217 | FALSE, /* pc_relative */ |
| 218 | 0, /* bitpos */ |
| 219 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 220 | sh_elf64_ignore_reloc, /* special_function */ |
| 221 | "R_SH_SWITCH32", /* name */ |
| 222 | FALSE, /* partial_inplace */ |
| 223 | 0, /* src_mask */ |
| 224 | 0, /* dst_mask */ |
| 225 | TRUE), /* pcrel_offset */ |
| 226 | |
| 227 | /* For 32-bit sh, this is R_SH_USES. */ |
| 228 | EMPTY_HOWTO (27), |
| 229 | |
| 230 | /* For 32-bit sh, this is R_SH_COUNT. */ |
| 231 | EMPTY_HOWTO (28), |
| 232 | |
| 233 | /* For 32-bit sh, this is R_SH_ALIGN. FIXME: For linker relaxation, |
| 234 | this might be emitted. When linker relaxation is implemented, we |
| 235 | might want to use it. */ |
| 236 | EMPTY_HOWTO (29), |
| 237 | |
| 238 | /* For 32-bit sh, this is R_SH_CODE. FIXME: For linker relaxation, |
| 239 | this might be emitted. When linker relaxation is implemented, we |
| 240 | might want to use it. */ |
| 241 | EMPTY_HOWTO (30), |
| 242 | |
| 243 | /* For 32-bit sh, this is R_SH_DATA. FIXME: For linker relaxation, |
| 244 | this might be emitted. When linker relaxation is implemented, we |
| 245 | might want to use it. */ |
| 246 | EMPTY_HOWTO (31), |
| 247 | |
| 248 | /* For 32-bit sh, this is R_SH_LABEL. FIXME: For linker relaxation, |
| 249 | this might be emitted. When linker relaxation is implemented, we |
| 250 | might want to use it. */ |
| 251 | EMPTY_HOWTO (32), |
| 252 | |
| 253 | /* An 8 bit switch table entry. This is generated for an expression |
| 254 | such as ``.word L1 - L2''. The offset holds the difference |
| 255 | between the reloc address and L2. */ |
| 256 | HOWTO (R_SH_SWITCH8, /* type */ |
| 257 | 0, /* rightshift */ |
| 258 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 259 | 8, /* bitsize */ |
| 260 | FALSE, /* pc_relative */ |
| 261 | 0, /* bitpos */ |
| 262 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 263 | sh_elf64_ignore_reloc, /* special_function */ |
| 264 | "R_SH_SWITCH8", /* name */ |
| 265 | FALSE, /* partial_inplace */ |
| 266 | 0, /* src_mask */ |
| 267 | 0, /* dst_mask */ |
| 268 | TRUE), /* pcrel_offset */ |
| 269 | |
| 270 | /* GNU extension to record C++ vtable hierarchy */ |
| 271 | HOWTO (R_SH_GNU_VTINHERIT, /* type */ |
| 272 | 0, /* rightshift */ |
| 273 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 274 | 0, /* bitsize */ |
| 275 | FALSE, /* pc_relative */ |
| 276 | 0, /* bitpos */ |
| 277 | complain_overflow_dont, /* complain_on_overflow */ |
| 278 | NULL, /* special_function */ |
| 279 | "R_SH_GNU_VTINHERIT", /* name */ |
| 280 | FALSE, /* partial_inplace */ |
| 281 | 0, /* src_mask */ |
| 282 | 0, /* dst_mask */ |
| 283 | FALSE), /* pcrel_offset */ |
| 284 | |
| 285 | /* GNU extension to record C++ vtable member usage */ |
| 286 | HOWTO (R_SH_GNU_VTENTRY, /* type */ |
| 287 | 0, /* rightshift */ |
| 288 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 289 | 0, /* bitsize */ |
| 290 | FALSE, /* pc_relative */ |
| 291 | 0, /* bitpos */ |
| 292 | complain_overflow_dont, /* complain_on_overflow */ |
| 293 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ |
| 294 | "R_SH_GNU_VTENTRY", /* name */ |
| 295 | FALSE, /* partial_inplace */ |
| 296 | 0, /* src_mask */ |
| 297 | 0, /* dst_mask */ |
| 298 | FALSE), /* pcrel_offset */ |
| 299 | |
| 300 | /* For 32-bit sh, this is R_SH_LOOP_START. */ |
| 301 | EMPTY_HOWTO (36), |
| 302 | |
| 303 | /* For 32-bit sh, this is R_SH_LOOP_END. */ |
| 304 | EMPTY_HOWTO (37), |
| 305 | |
| 306 | EMPTY_HOWTO (38), |
| 307 | EMPTY_HOWTO (39), |
| 308 | EMPTY_HOWTO (40), |
| 309 | EMPTY_HOWTO (41), |
| 310 | EMPTY_HOWTO (42), |
| 311 | EMPTY_HOWTO (43), |
| 312 | EMPTY_HOWTO (44), |
| 313 | |
| 314 | /* Used in SHLLI.L and SHLRI.L. */ |
| 315 | HOWTO (R_SH_DIR5U, /* type */ |
| 316 | 0, /* rightshift */ |
| 317 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 318 | 5, /* bitsize */ |
| 319 | FALSE, /* pc_relative */ |
| 320 | 10, /* bitpos */ |
| 321 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 322 | bfd_elf_generic_reloc, /* special_function */ |
| 323 | "R_SH_DIR5U", /* name */ |
| 324 | FALSE, /* partial_inplace */ |
| 325 | 0, /* src_mask */ |
| 326 | 0xfc00, /* dst_mask */ |
| 327 | FALSE), /* pcrel_offset */ |
| 328 | |
| 329 | /* Used in SHARI, SHLLI et al. */ |
| 330 | HOWTO (R_SH_DIR6U, /* type */ |
| 331 | 0, /* rightshift */ |
| 332 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 333 | 6, /* bitsize */ |
| 334 | FALSE, /* pc_relative */ |
| 335 | 10, /* bitpos */ |
| 336 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 337 | bfd_elf_generic_reloc, /* special_function */ |
| 338 | "R_SH_DIR6U", /* name */ |
| 339 | FALSE, /* partial_inplace */ |
| 340 | 0, /* src_mask */ |
| 341 | 0xfc00, /* dst_mask */ |
| 342 | FALSE), /* pcrel_offset */ |
| 343 | |
| 344 | /* Used in BxxI, LDHI.L et al. */ |
| 345 | HOWTO (R_SH_DIR6S, /* type */ |
| 346 | 0, /* rightshift */ |
| 347 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 348 | 6, /* bitsize */ |
| 349 | FALSE, /* pc_relative */ |
| 350 | 10, /* bitpos */ |
| 351 | complain_overflow_signed, /* complain_on_overflow */ |
| 352 | bfd_elf_generic_reloc, /* special_function */ |
| 353 | "R_SH_DIR6S", /* name */ |
| 354 | FALSE, /* partial_inplace */ |
| 355 | 0, /* src_mask */ |
| 356 | 0xfc00, /* dst_mask */ |
| 357 | FALSE), /* pcrel_offset */ |
| 358 | |
| 359 | /* Used in ADDI, ANDI et al. */ |
| 360 | HOWTO (R_SH_DIR10S, /* type */ |
| 361 | 0, /* rightshift */ |
| 362 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 363 | 10, /* bitsize */ |
| 364 | FALSE, /* pc_relative */ |
| 365 | 10, /* bitpos */ |
| 366 | complain_overflow_signed, /* complain_on_overflow */ |
| 367 | bfd_elf_generic_reloc, /* special_function */ |
| 368 | "R_SH_DIR10S", /* name */ |
| 369 | FALSE, /* partial_inplace */ |
| 370 | 0, /* src_mask */ |
| 371 | 0xffc00, /* dst_mask */ |
| 372 | FALSE), /* pcrel_offset */ |
| 373 | |
| 374 | /* Used in LD.UW, ST.W et al. */ |
| 375 | HOWTO (R_SH_DIR10SW, /* type */ |
| 376 | 1, /* rightshift */ |
| 377 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 378 | 11, /* bitsize */ |
| 379 | FALSE, /* pc_relative */ |
| 380 | 10, /* bitpos */ |
| 381 | complain_overflow_signed, /* complain_on_overflow */ |
| 382 | bfd_elf_generic_reloc, /* special_function */ |
| 383 | "R_SH_DIR10SW", /* name */ |
| 384 | FALSE, /* partial_inplace */ |
| 385 | 0, /* src_mask */ |
| 386 | 0xffc00, /* dst_mask */ |
| 387 | FALSE), /* pcrel_offset */ |
| 388 | |
| 389 | /* Used in LD.L, FLD.S et al. */ |
| 390 | HOWTO (R_SH_DIR10SL, /* type */ |
| 391 | 2, /* rightshift */ |
| 392 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 393 | 12, /* bitsize */ |
| 394 | FALSE, /* pc_relative */ |
| 395 | 10, /* bitpos */ |
| 396 | complain_overflow_signed, /* complain_on_overflow */ |
| 397 | bfd_elf_generic_reloc, /* special_function */ |
| 398 | "R_SH_DIR10SL", /* name */ |
| 399 | FALSE, /* partial_inplace */ |
| 400 | 0, /* src_mask */ |
| 401 | 0xffc00, /* dst_mask */ |
| 402 | FALSE), /* pcrel_offset */ |
| 403 | |
| 404 | /* Used in FLD.D, FST.P et al. */ |
| 405 | HOWTO (R_SH_DIR10SQ, /* type */ |
| 406 | 3, /* rightshift */ |
| 407 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 408 | 13, /* bitsize */ |
| 409 | FALSE, /* pc_relative */ |
| 410 | 10, /* bitpos */ |
| 411 | complain_overflow_signed, /* complain_on_overflow */ |
| 412 | bfd_elf_generic_reloc, /* special_function */ |
| 413 | "R_SH_DIR10SQ", /* name */ |
| 414 | FALSE, /* partial_inplace */ |
| 415 | 0, /* src_mask */ |
| 416 | 0xffc00, /* dst_mask */ |
| 417 | FALSE), /* pcrel_offset */ |
| 418 | |
| 419 | EMPTY_HOWTO (52), |
| 420 | EMPTY_HOWTO (53), |
| 421 | EMPTY_HOWTO (54), |
| 422 | EMPTY_HOWTO (55), |
| 423 | EMPTY_HOWTO (56), |
| 424 | EMPTY_HOWTO (57), |
| 425 | EMPTY_HOWTO (58), |
| 426 | EMPTY_HOWTO (59), |
| 427 | EMPTY_HOWTO (60), |
| 428 | EMPTY_HOWTO (61), |
| 429 | EMPTY_HOWTO (62), |
| 430 | EMPTY_HOWTO (63), |
| 431 | EMPTY_HOWTO (64), |
| 432 | EMPTY_HOWTO (65), |
| 433 | EMPTY_HOWTO (66), |
| 434 | EMPTY_HOWTO (67), |
| 435 | EMPTY_HOWTO (68), |
| 436 | EMPTY_HOWTO (69), |
| 437 | EMPTY_HOWTO (70), |
| 438 | EMPTY_HOWTO (71), |
| 439 | EMPTY_HOWTO (72), |
| 440 | EMPTY_HOWTO (73), |
| 441 | EMPTY_HOWTO (74), |
| 442 | EMPTY_HOWTO (75), |
| 443 | EMPTY_HOWTO (76), |
| 444 | EMPTY_HOWTO (77), |
| 445 | EMPTY_HOWTO (78), |
| 446 | EMPTY_HOWTO (79), |
| 447 | EMPTY_HOWTO (80), |
| 448 | EMPTY_HOWTO (81), |
| 449 | EMPTY_HOWTO (82), |
| 450 | EMPTY_HOWTO (83), |
| 451 | EMPTY_HOWTO (84), |
| 452 | EMPTY_HOWTO (85), |
| 453 | EMPTY_HOWTO (86), |
| 454 | EMPTY_HOWTO (87), |
| 455 | EMPTY_HOWTO (88), |
| 456 | EMPTY_HOWTO (89), |
| 457 | EMPTY_HOWTO (90), |
| 458 | EMPTY_HOWTO (91), |
| 459 | EMPTY_HOWTO (92), |
| 460 | EMPTY_HOWTO (93), |
| 461 | EMPTY_HOWTO (94), |
| 462 | EMPTY_HOWTO (95), |
| 463 | EMPTY_HOWTO (96), |
| 464 | EMPTY_HOWTO (97), |
| 465 | EMPTY_HOWTO (98), |
| 466 | EMPTY_HOWTO (99), |
| 467 | EMPTY_HOWTO (100), |
| 468 | EMPTY_HOWTO (101), |
| 469 | EMPTY_HOWTO (102), |
| 470 | EMPTY_HOWTO (103), |
| 471 | EMPTY_HOWTO (104), |
| 472 | EMPTY_HOWTO (105), |
| 473 | EMPTY_HOWTO (106), |
| 474 | EMPTY_HOWTO (107), |
| 475 | EMPTY_HOWTO (108), |
| 476 | EMPTY_HOWTO (109), |
| 477 | EMPTY_HOWTO (110), |
| 478 | EMPTY_HOWTO (111), |
| 479 | EMPTY_HOWTO (112), |
| 480 | EMPTY_HOWTO (113), |
| 481 | EMPTY_HOWTO (114), |
| 482 | EMPTY_HOWTO (115), |
| 483 | EMPTY_HOWTO (116), |
| 484 | EMPTY_HOWTO (117), |
| 485 | EMPTY_HOWTO (118), |
| 486 | EMPTY_HOWTO (119), |
| 487 | EMPTY_HOWTO (120), |
| 488 | EMPTY_HOWTO (121), |
| 489 | EMPTY_HOWTO (122), |
| 490 | EMPTY_HOWTO (123), |
| 491 | EMPTY_HOWTO (124), |
| 492 | EMPTY_HOWTO (125), |
| 493 | EMPTY_HOWTO (126), |
| 494 | EMPTY_HOWTO (127), |
| 495 | EMPTY_HOWTO (128), |
| 496 | EMPTY_HOWTO (129), |
| 497 | EMPTY_HOWTO (130), |
| 498 | EMPTY_HOWTO (131), |
| 499 | EMPTY_HOWTO (132), |
| 500 | EMPTY_HOWTO (133), |
| 501 | EMPTY_HOWTO (134), |
| 502 | EMPTY_HOWTO (135), |
| 503 | EMPTY_HOWTO (136), |
| 504 | EMPTY_HOWTO (137), |
| 505 | EMPTY_HOWTO (138), |
| 506 | EMPTY_HOWTO (139), |
| 507 | EMPTY_HOWTO (140), |
| 508 | EMPTY_HOWTO (141), |
| 509 | EMPTY_HOWTO (142), |
| 510 | EMPTY_HOWTO (143), |
| 511 | EMPTY_HOWTO (144), |
| 512 | EMPTY_HOWTO (145), |
| 513 | EMPTY_HOWTO (146), |
| 514 | EMPTY_HOWTO (147), |
| 515 | EMPTY_HOWTO (148), |
| 516 | EMPTY_HOWTO (149), |
| 517 | EMPTY_HOWTO (150), |
| 518 | EMPTY_HOWTO (151), |
| 519 | EMPTY_HOWTO (152), |
| 520 | EMPTY_HOWTO (153), |
| 521 | EMPTY_HOWTO (154), |
| 522 | EMPTY_HOWTO (155), |
| 523 | EMPTY_HOWTO (156), |
| 524 | EMPTY_HOWTO (157), |
| 525 | EMPTY_HOWTO (158), |
| 526 | EMPTY_HOWTO (159), |
| 527 | |
| 528 | /* Relocs for dynamic linking for 32-bit SH would follow. We don't have |
| 529 | any dynamic linking support for 64-bit SH at present. */ |
| 530 | |
| 531 | EMPTY_HOWTO (160), |
| 532 | EMPTY_HOWTO (161), |
| 533 | EMPTY_HOWTO (162), |
| 534 | EMPTY_HOWTO (163), |
| 535 | EMPTY_HOWTO (164), |
| 536 | EMPTY_HOWTO (165), |
| 537 | EMPTY_HOWTO (166), |
| 538 | EMPTY_HOWTO (167), |
| 539 | EMPTY_HOWTO (168), |
| 540 | |
| 541 | /* Back to SH5 relocations. */ |
| 542 | /* Used in MOVI and SHORI (x & 65536). */ |
| 543 | HOWTO (R_SH_GOT_LOW16, /* type */ |
| 544 | 0, /* rightshift */ |
| 545 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 546 | 64, /* bitsize */ |
| 547 | FALSE, /* pc_relative */ |
| 548 | 10, /* bitpos */ |
| 549 | complain_overflow_dont, /* complain_on_overflow */ |
| 550 | bfd_elf_generic_reloc, /* special_function */ |
| 551 | "R_SH_GOT_LOW16", /* name */ |
| 552 | FALSE, /* partial_inplace */ |
| 553 | 0, /* src_mask */ |
| 554 | 0x3fffc00, /* dst_mask */ |
| 555 | FALSE), /* pcrel_offset */ |
| 556 | |
| 557 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 558 | HOWTO (R_SH_GOT_MEDLOW16, /* type */ |
| 559 | 16, /* rightshift */ |
| 560 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 561 | 64, /* bitsize */ |
| 562 | FALSE, /* pc_relative */ |
| 563 | 10, /* bitpos */ |
| 564 | complain_overflow_dont, /* complain_on_overflow */ |
| 565 | bfd_elf_generic_reloc, /* special_function */ |
| 566 | "R_SH_GOT_MEDLOW16", /* name */ |
| 567 | FALSE, /* partial_inplace */ |
| 568 | 0, /* src_mask */ |
| 569 | 0x3fffc00, /* dst_mask */ |
| 570 | FALSE), /* pcrel_offset */ |
| 571 | |
| 572 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 573 | HOWTO (R_SH_GOT_MEDHI16, /* type */ |
| 574 | 32, /* rightshift */ |
| 575 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 576 | 64, /* bitsize */ |
| 577 | FALSE, /* pc_relative */ |
| 578 | 10, /* bitpos */ |
| 579 | complain_overflow_dont, /* complain_on_overflow */ |
| 580 | bfd_elf_generic_reloc, /* special_function */ |
| 581 | "R_SH_GOT_MEDHI16", /* name */ |
| 582 | FALSE, /* partial_inplace */ |
| 583 | 0, /* src_mask */ |
| 584 | 0x3fffc00, /* dst_mask */ |
| 585 | FALSE), /* pcrel_offset */ |
| 586 | |
| 587 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 588 | HOWTO (R_SH_GOT_HI16, /* type */ |
| 589 | 48, /* rightshift */ |
| 590 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 591 | 64, /* bitsize */ |
| 592 | FALSE, /* pc_relative */ |
| 593 | 10, /* bitpos */ |
| 594 | complain_overflow_dont, /* complain_on_overflow */ |
| 595 | bfd_elf_generic_reloc, /* special_function */ |
| 596 | "R_SH_GOT_HI16", /* name */ |
| 597 | FALSE, /* partial_inplace */ |
| 598 | 0, /* src_mask */ |
| 599 | 0x3fffc00, /* dst_mask */ |
| 600 | FALSE), /* pcrel_offset */ |
| 601 | |
| 602 | /* Used in MOVI and SHORI (x & 65536). */ |
| 603 | HOWTO (R_SH_GOTPLT_LOW16, /* type */ |
| 604 | 0, /* rightshift */ |
| 605 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 606 | 64, /* bitsize */ |
| 607 | FALSE, /* pc_relative */ |
| 608 | 10, /* bitpos */ |
| 609 | complain_overflow_dont, /* complain_on_overflow */ |
| 610 | bfd_elf_generic_reloc, /* special_function */ |
| 611 | "R_SH_GOTPLT_LOW16", /* name */ |
| 612 | FALSE, /* partial_inplace */ |
| 613 | 0, /* src_mask */ |
| 614 | 0x3fffc00, /* dst_mask */ |
| 615 | FALSE), /* pcrel_offset */ |
| 616 | |
| 617 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 618 | HOWTO (R_SH_GOTPLT_MEDLOW16, /* type */ |
| 619 | 16, /* rightshift */ |
| 620 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 621 | 64, /* bitsize */ |
| 622 | FALSE, /* pc_relative */ |
| 623 | 10, /* bitpos */ |
| 624 | complain_overflow_dont, /* complain_on_overflow */ |
| 625 | bfd_elf_generic_reloc, /* special_function */ |
| 626 | "R_SH_GOTPLT_MEDLOW16", /* name */ |
| 627 | FALSE, /* partial_inplace */ |
| 628 | 0, /* src_mask */ |
| 629 | 0x3fffc00, /* dst_mask */ |
| 630 | FALSE), /* pcrel_offset */ |
| 631 | |
| 632 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 633 | HOWTO (R_SH_GOTPLT_MEDHI16, /* type */ |
| 634 | 32, /* rightshift */ |
| 635 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 636 | 64, /* bitsize */ |
| 637 | FALSE, /* pc_relative */ |
| 638 | 10, /* bitpos */ |
| 639 | complain_overflow_dont, /* complain_on_overflow */ |
| 640 | bfd_elf_generic_reloc, /* special_function */ |
| 641 | "R_SH_GOTPLT_MEDHI16", /* name */ |
| 642 | FALSE, /* partial_inplace */ |
| 643 | 0, /* src_mask */ |
| 644 | 0x3fffc00, /* dst_mask */ |
| 645 | FALSE), /* pcrel_offset */ |
| 646 | |
| 647 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 648 | HOWTO (R_SH_GOTPLT_HI16, /* type */ |
| 649 | 48, /* rightshift */ |
| 650 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 651 | 64, /* bitsize */ |
| 652 | FALSE, /* pc_relative */ |
| 653 | 10, /* bitpos */ |
| 654 | complain_overflow_dont, /* complain_on_overflow */ |
| 655 | bfd_elf_generic_reloc, /* special_function */ |
| 656 | "R_SH_GOTPLT_HI16", /* name */ |
| 657 | FALSE, /* partial_inplace */ |
| 658 | 0, /* src_mask */ |
| 659 | 0x3fffc00, /* dst_mask */ |
| 660 | FALSE), /* pcrel_offset */ |
| 661 | |
| 662 | /* Used in MOVI and SHORI (x & 65536). */ |
| 663 | HOWTO (R_SH_PLT_LOW16, /* type */ |
| 664 | 0, /* rightshift */ |
| 665 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 666 | 64, /* bitsize */ |
| 667 | TRUE, /* pc_relative */ |
| 668 | 10, /* bitpos */ |
| 669 | complain_overflow_dont, /* complain_on_overflow */ |
| 670 | bfd_elf_generic_reloc, /* special_function */ |
| 671 | "R_SH_PLT_LOW16", /* name */ |
| 672 | FALSE, /* partial_inplace */ |
| 673 | 0, /* src_mask */ |
| 674 | 0x3fffc00, /* dst_mask */ |
| 675 | TRUE), /* pcrel_offset */ |
| 676 | |
| 677 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 678 | HOWTO (R_SH_PLT_MEDLOW16, /* type */ |
| 679 | 16, /* rightshift */ |
| 680 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 681 | 64, /* bitsize */ |
| 682 | TRUE, /* pc_relative */ |
| 683 | 10, /* bitpos */ |
| 684 | complain_overflow_dont, /* complain_on_overflow */ |
| 685 | bfd_elf_generic_reloc, /* special_function */ |
| 686 | "R_SH_PLT_MEDLOW16", /* name */ |
| 687 | FALSE, /* partial_inplace */ |
| 688 | 0, /* src_mask */ |
| 689 | 0x3fffc00, /* dst_mask */ |
| 690 | TRUE), /* pcrel_offset */ |
| 691 | |
| 692 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 693 | HOWTO (R_SH_PLT_MEDHI16, /* type */ |
| 694 | 32, /* rightshift */ |
| 695 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 696 | 64, /* bitsize */ |
| 697 | TRUE, /* pc_relative */ |
| 698 | 10, /* bitpos */ |
| 699 | complain_overflow_dont, /* complain_on_overflow */ |
| 700 | bfd_elf_generic_reloc, /* special_function */ |
| 701 | "R_SH_PLT_MEDHI16", /* name */ |
| 702 | FALSE, /* partial_inplace */ |
| 703 | 0, /* src_mask */ |
| 704 | 0x3fffc00, /* dst_mask */ |
| 705 | TRUE), /* pcrel_offset */ |
| 706 | |
| 707 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 708 | HOWTO (R_SH_PLT_HI16, /* type */ |
| 709 | 48, /* rightshift */ |
| 710 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 711 | 64, /* bitsize */ |
| 712 | TRUE, /* pc_relative */ |
| 713 | 10, /* bitpos */ |
| 714 | complain_overflow_dont, /* complain_on_overflow */ |
| 715 | bfd_elf_generic_reloc, /* special_function */ |
| 716 | "R_SH_PLT_HI16", /* name */ |
| 717 | FALSE, /* partial_inplace */ |
| 718 | 0, /* src_mask */ |
| 719 | 0x3fffc00, /* dst_mask */ |
| 720 | TRUE), /* pcrel_offset */ |
| 721 | |
| 722 | /* Used in MOVI and SHORI (x & 65536). */ |
| 723 | HOWTO (R_SH_GOTOFF_LOW16, /* type */ |
| 724 | 0, /* rightshift */ |
| 725 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 726 | 64, /* bitsize */ |
| 727 | FALSE, /* pc_relative */ |
| 728 | 10, /* bitpos */ |
| 729 | complain_overflow_dont, /* complain_on_overflow */ |
| 730 | bfd_elf_generic_reloc, /* special_function */ |
| 731 | "R_SH_GOTOFF_LOW16", /* name */ |
| 732 | FALSE, /* partial_inplace */ |
| 733 | 0, /* src_mask */ |
| 734 | 0x3fffc00, /* dst_mask */ |
| 735 | FALSE), /* pcrel_offset */ |
| 736 | |
| 737 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 738 | HOWTO (R_SH_GOTOFF_MEDLOW16, /* type */ |
| 739 | 16, /* rightshift */ |
| 740 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 741 | 64, /* bitsize */ |
| 742 | FALSE, /* pc_relative */ |
| 743 | 10, /* bitpos */ |
| 744 | complain_overflow_dont, /* complain_on_overflow */ |
| 745 | bfd_elf_generic_reloc, /* special_function */ |
| 746 | "R_SH_GOTOFF_MEDLOW16", /* name */ |
| 747 | FALSE, /* partial_inplace */ |
| 748 | 0, /* src_mask */ |
| 749 | 0x3fffc00, /* dst_mask */ |
| 750 | FALSE), /* pcrel_offset */ |
| 751 | |
| 752 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 753 | HOWTO (R_SH_GOTOFF_MEDHI16, /* type */ |
| 754 | 32, /* rightshift */ |
| 755 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 756 | 64, /* bitsize */ |
| 757 | FALSE, /* pc_relative */ |
| 758 | 10, /* bitpos */ |
| 759 | complain_overflow_dont, /* complain_on_overflow */ |
| 760 | bfd_elf_generic_reloc, /* special_function */ |
| 761 | "R_SH_GOTOFF_MEDHI16", /* name */ |
| 762 | FALSE, /* partial_inplace */ |
| 763 | 0, /* src_mask */ |
| 764 | 0x3fffc00, /* dst_mask */ |
| 765 | FALSE), /* pcrel_offset */ |
| 766 | |
| 767 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 768 | HOWTO (R_SH_GOTOFF_HI16, /* type */ |
| 769 | 48, /* rightshift */ |
| 770 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 771 | 64, /* bitsize */ |
| 772 | FALSE, /* pc_relative */ |
| 773 | 10, /* bitpos */ |
| 774 | complain_overflow_dont, /* complain_on_overflow */ |
| 775 | bfd_elf_generic_reloc, /* special_function */ |
| 776 | "R_SH_GOTOFF_HI16", /* name */ |
| 777 | FALSE, /* partial_inplace */ |
| 778 | 0, /* src_mask */ |
| 779 | 0x3fffc00, /* dst_mask */ |
| 780 | FALSE), /* pcrel_offset */ |
| 781 | |
| 782 | /* Used in MOVI and SHORI (x & 65536). */ |
| 783 | HOWTO (R_SH_GOTPC_LOW16, /* type */ |
| 784 | 0, /* rightshift */ |
| 785 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 786 | 64, /* bitsize */ |
| 787 | TRUE, /* pc_relative */ |
| 788 | 10, /* bitpos */ |
| 789 | complain_overflow_dont, /* complain_on_overflow */ |
| 790 | bfd_elf_generic_reloc, /* special_function */ |
| 791 | "R_SH_GOTPC_LOW16", /* name */ |
| 792 | FALSE, /* partial_inplace */ |
| 793 | 0, /* src_mask */ |
| 794 | 0x3fffc00, /* dst_mask */ |
| 795 | TRUE), /* pcrel_offset */ |
| 796 | |
| 797 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 798 | HOWTO (R_SH_GOTPC_MEDLOW16, /* type */ |
| 799 | 16, /* rightshift */ |
| 800 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 801 | 64, /* bitsize */ |
| 802 | TRUE, /* pc_relative */ |
| 803 | 10, /* bitpos */ |
| 804 | complain_overflow_dont, /* complain_on_overflow */ |
| 805 | bfd_elf_generic_reloc, /* special_function */ |
| 806 | "R_SH_GOTPC_MEDLOW16", /* name */ |
| 807 | FALSE, /* partial_inplace */ |
| 808 | 0, /* src_mask */ |
| 809 | 0x3fffc00, /* dst_mask */ |
| 810 | TRUE), /* pcrel_offset */ |
| 811 | |
| 812 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 813 | HOWTO (R_SH_GOTPC_MEDHI16, /* type */ |
| 814 | 32, /* rightshift */ |
| 815 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 816 | 64, /* bitsize */ |
| 817 | TRUE, /* pc_relative */ |
| 818 | 10, /* bitpos */ |
| 819 | complain_overflow_dont, /* complain_on_overflow */ |
| 820 | bfd_elf_generic_reloc, /* special_function */ |
| 821 | "R_SH_GOTPC_MEDHI16", /* name */ |
| 822 | FALSE, /* partial_inplace */ |
| 823 | 0, /* src_mask */ |
| 824 | 0x3fffc00, /* dst_mask */ |
| 825 | TRUE), /* pcrel_offset */ |
| 826 | |
| 827 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 828 | HOWTO (R_SH_GOTPC_HI16, /* type */ |
| 829 | 48, /* rightshift */ |
| 830 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 831 | 64, /* bitsize */ |
| 832 | TRUE, /* pc_relative */ |
| 833 | 10, /* bitpos */ |
| 834 | complain_overflow_dont, /* complain_on_overflow */ |
| 835 | bfd_elf_generic_reloc, /* special_function */ |
| 836 | "R_SH_GOTPC_HI16", /* name */ |
| 837 | FALSE, /* partial_inplace */ |
| 838 | 0, /* src_mask */ |
| 839 | 0x3fffc00, /* dst_mask */ |
| 840 | TRUE), /* pcrel_offset */ |
| 841 | |
| 842 | /* Used in LD.L, FLD.S et al. */ |
| 843 | HOWTO (R_SH_GOT10BY4, /* type */ |
| 844 | 2, /* rightshift */ |
| 845 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 846 | 12, /* bitsize */ |
| 847 | FALSE, /* pc_relative */ |
| 848 | 10, /* bitpos */ |
| 849 | complain_overflow_signed, /* complain_on_overflow */ |
| 850 | bfd_elf_generic_reloc, /* special_function */ |
| 851 | "R_SH_GOT10BY4", /* name */ |
| 852 | FALSE, /* partial_inplace */ |
| 853 | 0, /* src_mask */ |
| 854 | 0xffc00, /* dst_mask */ |
| 855 | FALSE), /* pcrel_offset */ |
| 856 | |
| 857 | /* Used in LD.L, FLD.S et al. */ |
| 858 | HOWTO (R_SH_GOTPLT10BY4, /* type */ |
| 859 | 2, /* rightshift */ |
| 860 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 861 | 12, /* bitsize */ |
| 862 | FALSE, /* pc_relative */ |
| 863 | 10, /* bitpos */ |
| 864 | complain_overflow_signed, /* complain_on_overflow */ |
| 865 | bfd_elf_generic_reloc, /* special_function */ |
| 866 | "R_SH_GOTPLT10BY4", /* name */ |
| 867 | FALSE, /* partial_inplace */ |
| 868 | 0, /* src_mask */ |
| 869 | 0xffc00, /* dst_mask */ |
| 870 | FALSE), /* pcrel_offset */ |
| 871 | |
| 872 | /* Used in FLD.D, FST.P et al. */ |
| 873 | HOWTO (R_SH_GOT10BY8, /* type */ |
| 874 | 3, /* rightshift */ |
| 875 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 876 | 13, /* bitsize */ |
| 877 | FALSE, /* pc_relative */ |
| 878 | 10, /* bitpos */ |
| 879 | complain_overflow_signed, /* complain_on_overflow */ |
| 880 | bfd_elf_generic_reloc, /* special_function */ |
| 881 | "R_SH_GOT10BY8", /* name */ |
| 882 | FALSE, /* partial_inplace */ |
| 883 | 0, /* src_mask */ |
| 884 | 0xffc00, /* dst_mask */ |
| 885 | FALSE), /* pcrel_offset */ |
| 886 | |
| 887 | /* Used in FLD.D, FST.P et al. */ |
| 888 | HOWTO (R_SH_GOTPLT10BY8, /* type */ |
| 889 | 3, /* rightshift */ |
| 890 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 891 | 13, /* bitsize */ |
| 892 | FALSE, /* pc_relative */ |
| 893 | 10, /* bitpos */ |
| 894 | complain_overflow_signed, /* complain_on_overflow */ |
| 895 | bfd_elf_generic_reloc, /* special_function */ |
| 896 | "R_SH_GOTPLT10BY8", /* name */ |
| 897 | FALSE, /* partial_inplace */ |
| 898 | 0, /* src_mask */ |
| 899 | 0xffc00, /* dst_mask */ |
| 900 | FALSE), /* pcrel_offset */ |
| 901 | |
| 902 | HOWTO (R_SH_COPY64, /* type */ |
| 903 | 0, /* rightshift */ |
| 904 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 905 | 64, /* bitsize */ |
| 906 | FALSE, /* pc_relative */ |
| 907 | 0, /* bitpos */ |
| 908 | complain_overflow_dont, /* complain_on_overflow */ |
| 909 | bfd_elf_generic_reloc, /* special_function */ |
| 910 | "R_SH_COPY64", /* name */ |
| 911 | FALSE, /* partial_inplace */ |
| 912 | 0, /* src_mask */ |
| 913 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 914 | FALSE), /* pcrel_offset */ |
| 915 | |
| 916 | HOWTO (R_SH_GLOB_DAT64, /* type */ |
| 917 | 0, /* rightshift */ |
| 918 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 919 | 64, /* bitsize */ |
| 920 | FALSE, /* pc_relative */ |
| 921 | 0, /* bitpos */ |
| 922 | complain_overflow_dont, /* complain_on_overflow */ |
| 923 | bfd_elf_generic_reloc, /* special_function */ |
| 924 | "R_SH_GLOB_DAT64", /* name */ |
| 925 | FALSE, /* partial_inplace */ |
| 926 | 0, /* src_mask */ |
| 927 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 928 | FALSE), /* pcrel_offset */ |
| 929 | |
| 930 | HOWTO (R_SH_JMP_SLOT64, /* type */ |
| 931 | 0, /* rightshift */ |
| 932 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 933 | 64, /* bitsize */ |
| 934 | FALSE, /* pc_relative */ |
| 935 | 0, /* bitpos */ |
| 936 | complain_overflow_dont, /* complain_on_overflow */ |
| 937 | bfd_elf_generic_reloc, /* special_function */ |
| 938 | "R_SH_JMP_SLOT64", /* name */ |
| 939 | FALSE, /* partial_inplace */ |
| 940 | 0, /* src_mask */ |
| 941 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 942 | FALSE), /* pcrel_offset */ |
| 943 | |
| 944 | HOWTO (R_SH_RELATIVE64, /* type */ |
| 945 | 0, /* rightshift */ |
| 946 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 947 | 64, /* bitsize */ |
| 948 | FALSE, /* pc_relative */ |
| 949 | 0, /* bitpos */ |
| 950 | complain_overflow_dont, /* complain_on_overflow */ |
| 951 | bfd_elf_generic_reloc, /* special_function */ |
| 952 | "R_SH_RELATIVE64", /* name */ |
| 953 | FALSE, /* partial_inplace */ |
| 954 | 0, /* src_mask */ |
| 955 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 956 | FALSE), /* pcrel_offset */ |
| 957 | |
| 958 | EMPTY_HOWTO (197), |
| 959 | EMPTY_HOWTO (198), |
| 960 | EMPTY_HOWTO (199), |
| 961 | EMPTY_HOWTO (200), |
| 962 | EMPTY_HOWTO (201), |
| 963 | EMPTY_HOWTO (202), |
| 964 | EMPTY_HOWTO (203), |
| 965 | EMPTY_HOWTO (204), |
| 966 | EMPTY_HOWTO (205), |
| 967 | EMPTY_HOWTO (206), |
| 968 | EMPTY_HOWTO (207), |
| 969 | EMPTY_HOWTO (208), |
| 970 | EMPTY_HOWTO (209), |
| 971 | EMPTY_HOWTO (210), |
| 972 | EMPTY_HOWTO (211), |
| 973 | EMPTY_HOWTO (212), |
| 974 | EMPTY_HOWTO (213), |
| 975 | EMPTY_HOWTO (214), |
| 976 | EMPTY_HOWTO (215), |
| 977 | EMPTY_HOWTO (216), |
| 978 | EMPTY_HOWTO (217), |
| 979 | EMPTY_HOWTO (218), |
| 980 | EMPTY_HOWTO (219), |
| 981 | EMPTY_HOWTO (220), |
| 982 | EMPTY_HOWTO (221), |
| 983 | EMPTY_HOWTO (222), |
| 984 | EMPTY_HOWTO (223), |
| 985 | EMPTY_HOWTO (224), |
| 986 | EMPTY_HOWTO (225), |
| 987 | EMPTY_HOWTO (226), |
| 988 | EMPTY_HOWTO (227), |
| 989 | EMPTY_HOWTO (228), |
| 990 | EMPTY_HOWTO (229), |
| 991 | EMPTY_HOWTO (230), |
| 992 | EMPTY_HOWTO (231), |
| 993 | EMPTY_HOWTO (232), |
| 994 | EMPTY_HOWTO (233), |
| 995 | EMPTY_HOWTO (234), |
| 996 | EMPTY_HOWTO (235), |
| 997 | EMPTY_HOWTO (236), |
| 998 | EMPTY_HOWTO (237), |
| 999 | EMPTY_HOWTO (238), |
| 1000 | EMPTY_HOWTO (239), |
| 1001 | EMPTY_HOWTO (240), |
| 1002 | EMPTY_HOWTO (241), |
| 1003 | |
| 1004 | /* Relocations for SHmedia code. None of these are partial_inplace or |
| 1005 | use the field being relocated. */ |
| 1006 | |
| 1007 | /* The assembler will generate this reloc before a block of SHmedia |
| 1008 | instructions. A section should be processed as assuming it contains |
| 1009 | data, unless this reloc is seen. Note that a block of SHcompact |
| 1010 | instructions are instead preceded by R_SH_CODE. |
| 1011 | This is currently not implemented, but should be used for SHmedia |
| 1012 | linker relaxation. */ |
| 1013 | HOWTO (R_SH_SHMEDIA_CODE, /* type */ |
| 1014 | 0, /* rightshift */ |
| 1015 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1016 | 0, /* bitsize */ |
| 1017 | FALSE, /* pc_relative */ |
| 1018 | 0, /* bitpos */ |
| 1019 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 1020 | sh_elf64_ignore_reloc, /* special_function */ |
| 1021 | "R_SH_SHMEDIA_CODE", /* name */ |
| 1022 | FALSE, /* partial_inplace */ |
| 1023 | 0, /* src_mask */ |
| 1024 | 0, /* dst_mask */ |
| 1025 | FALSE), /* pcrel_offset */ |
| 1026 | |
| 1027 | /* The assembler will generate this reloc at a PTA or PTB instruction, |
| 1028 | and the linker checks the right type of target, or changes a PTA to a |
| 1029 | PTB, if the original insn was PT. */ |
| 1030 | HOWTO (R_SH_PT_16, /* type */ |
| 1031 | 2, /* rightshift */ |
| 1032 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1033 | 18, /* bitsize */ |
| 1034 | TRUE, /* pc_relative */ |
| 1035 | 10, /* bitpos */ |
| 1036 | complain_overflow_signed, /* complain_on_overflow */ |
| 1037 | bfd_elf_generic_reloc, /* special_function */ |
| 1038 | "R_SH_PT_16", /* name */ |
| 1039 | FALSE, /* partial_inplace */ |
| 1040 | 0, /* src_mask */ |
| 1041 | 0x3fffc00, /* dst_mask */ |
| 1042 | TRUE), /* pcrel_offset */ |
| 1043 | |
| 1044 | /* Used in unexpanded MOVI. */ |
| 1045 | HOWTO (R_SH_IMMS16, /* type */ |
| 1046 | 0, /* rightshift */ |
| 1047 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1048 | 16, /* bitsize */ |
| 1049 | FALSE, /* pc_relative */ |
| 1050 | 10, /* bitpos */ |
| 1051 | complain_overflow_signed, /* complain_on_overflow */ |
| 1052 | bfd_elf_generic_reloc, /* special_function */ |
| 1053 | "R_SH_IMMS16", /* name */ |
| 1054 | FALSE, /* partial_inplace */ |
| 1055 | 0, /* src_mask */ |
| 1056 | 0x3fffc00, /* dst_mask */ |
| 1057 | FALSE), /* pcrel_offset */ |
| 1058 | |
| 1059 | /* Used in SHORI. */ |
| 1060 | HOWTO (R_SH_IMMU16, /* type */ |
| 1061 | 0, /* rightshift */ |
| 1062 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1063 | 16, /* bitsize */ |
| 1064 | FALSE, /* pc_relative */ |
| 1065 | 10, /* bitpos */ |
| 1066 | complain_overflow_unsigned, /* complain_on_overflow */ |
| 1067 | bfd_elf_generic_reloc, /* special_function */ |
| 1068 | "R_SH_IMMU16", /* name */ |
| 1069 | FALSE, /* partial_inplace */ |
| 1070 | 0, /* src_mask */ |
| 1071 | 0x3fffc00, /* dst_mask */ |
| 1072 | FALSE), /* pcrel_offset */ |
| 1073 | |
| 1074 | /* Used in MOVI and SHORI (x & 65536). */ |
| 1075 | HOWTO (R_SH_IMM_LOW16, /* type */ |
| 1076 | 0, /* rightshift */ |
| 1077 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1078 | 64, /* bitsize */ |
| 1079 | FALSE, /* pc_relative */ |
| 1080 | 10, /* bitpos */ |
| 1081 | complain_overflow_dont, /* complain_on_overflow */ |
| 1082 | bfd_elf_generic_reloc, /* special_function */ |
| 1083 | "R_SH_IMM_LOW16", /* name */ |
| 1084 | FALSE, /* partial_inplace */ |
| 1085 | 0, /* src_mask */ |
| 1086 | 0x3fffc00, /* dst_mask */ |
| 1087 | FALSE), /* pcrel_offset */ |
| 1088 | |
| 1089 | /* Used in MOVI and SHORI ((x - $) & 65536). */ |
| 1090 | HOWTO (R_SH_IMM_LOW16_PCREL, /* type */ |
| 1091 | 0, /* rightshift */ |
| 1092 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1093 | 64, /* bitsize */ |
| 1094 | TRUE, /* pc_relative */ |
| 1095 | 10, /* bitpos */ |
| 1096 | complain_overflow_dont, /* complain_on_overflow */ |
| 1097 | bfd_elf_generic_reloc, /* special_function */ |
| 1098 | "R_SH_IMM_LOW16_PCREL", /* name */ |
| 1099 | FALSE, /* partial_inplace */ |
| 1100 | 0, /* src_mask */ |
| 1101 | 0x3fffc00, /* dst_mask */ |
| 1102 | TRUE), /* pcrel_offset */ |
| 1103 | |
| 1104 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ |
| 1105 | HOWTO (R_SH_IMM_MEDLOW16, /* type */ |
| 1106 | 16, /* rightshift */ |
| 1107 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1108 | 64, /* bitsize */ |
| 1109 | FALSE, /* pc_relative */ |
| 1110 | 10, /* bitpos */ |
| 1111 | complain_overflow_dont, /* complain_on_overflow */ |
| 1112 | bfd_elf_generic_reloc, /* special_function */ |
| 1113 | "R_SH_IMM_MEDLOW16", /* name */ |
| 1114 | FALSE, /* partial_inplace */ |
| 1115 | 0, /* src_mask */ |
| 1116 | 0x3fffc00, /* dst_mask */ |
| 1117 | FALSE), /* pcrel_offset */ |
| 1118 | |
| 1119 | /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */ |
| 1120 | HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */ |
| 1121 | 16, /* rightshift */ |
| 1122 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1123 | 64, /* bitsize */ |
| 1124 | TRUE, /* pc_relative */ |
| 1125 | 10, /* bitpos */ |
| 1126 | complain_overflow_dont, /* complain_on_overflow */ |
| 1127 | bfd_elf_generic_reloc, /* special_function */ |
| 1128 | "R_SH_IMM_MEDLOW16_PCREL", /* name */ |
| 1129 | FALSE, /* partial_inplace */ |
| 1130 | 0, /* src_mask */ |
| 1131 | 0x3fffc00, /* dst_mask */ |
| 1132 | TRUE), /* pcrel_offset */ |
| 1133 | |
| 1134 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ |
| 1135 | HOWTO (R_SH_IMM_MEDHI16, /* type */ |
| 1136 | 32, /* rightshift */ |
| 1137 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1138 | 64, /* bitsize */ |
| 1139 | FALSE, /* pc_relative */ |
| 1140 | 10, /* bitpos */ |
| 1141 | complain_overflow_dont, /* complain_on_overflow */ |
| 1142 | bfd_elf_generic_reloc, /* special_function */ |
| 1143 | "R_SH_IMM_MEDHI16", /* name */ |
| 1144 | FALSE, /* partial_inplace */ |
| 1145 | 0, /* src_mask */ |
| 1146 | 0x3fffc00, /* dst_mask */ |
| 1147 | FALSE), /* pcrel_offset */ |
| 1148 | |
| 1149 | /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */ |
| 1150 | HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */ |
| 1151 | 32, /* rightshift */ |
| 1152 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1153 | 64, /* bitsize */ |
| 1154 | TRUE, /* pc_relative */ |
| 1155 | 10, /* bitpos */ |
| 1156 | complain_overflow_dont, /* complain_on_overflow */ |
| 1157 | bfd_elf_generic_reloc, /* special_function */ |
| 1158 | "R_SH_IMM_MEDHI16_PCREL", /* name */ |
| 1159 | FALSE, /* partial_inplace */ |
| 1160 | 0, /* src_mask */ |
| 1161 | 0x3fffc00, /* dst_mask */ |
| 1162 | TRUE), /* pcrel_offset */ |
| 1163 | |
| 1164 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ |
| 1165 | HOWTO (R_SH_IMM_HI16, /* type */ |
| 1166 | 48, /* rightshift */ |
| 1167 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1168 | 64, /* bitsize */ |
| 1169 | FALSE, /* pc_relative */ |
| 1170 | 10, /* bitpos */ |
| 1171 | complain_overflow_dont, /* complain_on_overflow */ |
| 1172 | bfd_elf_generic_reloc, /* special_function */ |
| 1173 | "R_SH_IMM_HI16", /* name */ |
| 1174 | FALSE, /* partial_inplace */ |
| 1175 | 0, /* src_mask */ |
| 1176 | 0x3fffc00, /* dst_mask */ |
| 1177 | FALSE), /* pcrel_offset */ |
| 1178 | |
| 1179 | /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */ |
| 1180 | HOWTO (R_SH_IMM_HI16_PCREL, /* type */ |
| 1181 | 48, /* rightshift */ |
| 1182 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1183 | 64, /* bitsize */ |
| 1184 | TRUE, /* pc_relative */ |
| 1185 | 10, /* bitpos */ |
| 1186 | complain_overflow_dont, /* complain_on_overflow */ |
| 1187 | bfd_elf_generic_reloc, /* special_function */ |
| 1188 | "R_SH_IMM_HI16_PCREL", /* name */ |
| 1189 | FALSE, /* partial_inplace */ |
| 1190 | 0, /* src_mask */ |
| 1191 | 0x3fffc00, /* dst_mask */ |
| 1192 | TRUE), /* pcrel_offset */ |
| 1193 | |
| 1194 | /* For the .uaquad pseudo. */ |
| 1195 | HOWTO (R_SH_64, /* type */ |
| 1196 | 0, /* rightshift */ |
| 1197 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1198 | 64, /* bitsize */ |
| 1199 | FALSE, /* pc_relative */ |
| 1200 | 0, /* bitpos */ |
| 1201 | complain_overflow_dont, /* complain_on_overflow */ |
| 1202 | bfd_elf_generic_reloc, /* special_function */ |
| 1203 | "R_SH_64", /* name */ |
| 1204 | FALSE, /* partial_inplace */ |
| 1205 | 0, /* src_mask */ |
| 1206 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 1207 | FALSE), /* pcrel_offset */ |
| 1208 | |
| 1209 | /* For the .uaquad pseudo, (x - $). */ |
| 1210 | HOWTO (R_SH_64_PCREL, /* type */ |
| 1211 | 48, /* rightshift */ |
| 1212 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1213 | 64, /* bitsize */ |
| 1214 | TRUE, /* pc_relative */ |
| 1215 | 10, /* bitpos */ |
| 1216 | complain_overflow_dont, /* complain_on_overflow */ |
| 1217 | bfd_elf_generic_reloc, /* special_function */ |
| 1218 | "R_SH_64_PCREL", /* name */ |
| 1219 | FALSE, /* partial_inplace */ |
| 1220 | 0, /* src_mask */ |
| 1221 | ((bfd_vma) 0) - 1, /* dst_mask */ |
| 1222 | TRUE), /* pcrel_offset */ |
| 1223 | |
| 1224 | }; |
| 1225 | |
| 1226 | /* This function is used for relocs which are only used for relaxing, |
| 1227 | which the linker should otherwise ignore. */ |
| 1228 | |
| 1229 | static bfd_reloc_status_type |
| 1230 | sh_elf64_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry, |
| 1231 | asymbol *symbol ATTRIBUTE_UNUSED, |
| 1232 | void *data ATTRIBUTE_UNUSED, asection *input_section, |
| 1233 | bfd *output_bfd, |
| 1234 | char **error_message ATTRIBUTE_UNUSED) |
| 1235 | { |
| 1236 | if (output_bfd != NULL) |
| 1237 | reloc_entry->address += input_section->output_offset; |
| 1238 | return bfd_reloc_ok; |
| 1239 | } |
| 1240 | |
| 1241 | /* This function is used for normal relocs. This used to be like the COFF |
| 1242 | function, and is almost certainly incorrect for other ELF targets. |
| 1243 | |
| 1244 | See sh_elf_reloc in elf32-sh.c for the original. */ |
| 1245 | |
| 1246 | static bfd_reloc_status_type |
| 1247 | sh_elf64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in, |
| 1248 | void *data, asection *input_section, bfd *output_bfd, |
| 1249 | char **error_message ATTRIBUTE_UNUSED) |
| 1250 | { |
| 1251 | unsigned long insn; |
| 1252 | bfd_vma sym_value; |
| 1253 | enum elf_sh_reloc_type r_type; |
| 1254 | bfd_vma addr = reloc_entry->address; |
| 1255 | bfd_byte *hit_data = addr + (bfd_byte *) data; |
| 1256 | |
| 1257 | r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type; |
| 1258 | |
| 1259 | if (output_bfd != NULL) |
| 1260 | { |
| 1261 | /* Partial linking--do nothing. */ |
| 1262 | reloc_entry->address += input_section->output_offset; |
| 1263 | return bfd_reloc_ok; |
| 1264 | } |
| 1265 | |
| 1266 | if (symbol_in != NULL |
| 1267 | && bfd_is_und_section (symbol_in->section)) |
| 1268 | return bfd_reloc_undefined; |
| 1269 | |
| 1270 | if (bfd_is_com_section (symbol_in->section)) |
| 1271 | sym_value = 0; |
| 1272 | else |
| 1273 | sym_value = (symbol_in->value + |
| 1274 | symbol_in->section->output_section->vma + |
| 1275 | symbol_in->section->output_offset); |
| 1276 | |
| 1277 | switch (r_type) |
| 1278 | { |
| 1279 | case R_SH_DIR32: |
| 1280 | insn = bfd_get_32 (abfd, hit_data); |
| 1281 | insn += sym_value + reloc_entry->addend; |
| 1282 | bfd_put_32 (abfd, insn, hit_data); |
| 1283 | break; |
| 1284 | |
| 1285 | default: |
| 1286 | abort (); |
| 1287 | break; |
| 1288 | } |
| 1289 | |
| 1290 | return bfd_reloc_ok; |
| 1291 | } |
| 1292 | |
| 1293 | /* This structure is used to map BFD reloc codes to SH ELF relocs. */ |
| 1294 | |
| 1295 | struct elf_reloc_map |
| 1296 | { |
| 1297 | bfd_reloc_code_real_type bfd_reloc_val; |
| 1298 | unsigned char elf_reloc_val; |
| 1299 | }; |
| 1300 | |
| 1301 | /* An array mapping BFD reloc codes to SH ELF relocs. */ |
| 1302 | |
| 1303 | static const struct elf_reloc_map sh64_reloc_map[] = |
| 1304 | { |
| 1305 | { BFD_RELOC_NONE, R_SH_NONE }, |
| 1306 | { BFD_RELOC_32, R_SH_DIR32 }, |
| 1307 | { BFD_RELOC_CTOR, R_SH_DIR32 }, |
| 1308 | { BFD_RELOC_32_PCREL, R_SH_REL32 }, |
| 1309 | { BFD_RELOC_8_PCREL, R_SH_SWITCH8 }, |
| 1310 | { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 }, |
| 1311 | { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 }, |
| 1312 | { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT }, |
| 1313 | { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY }, |
| 1314 | { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 }, |
| 1315 | { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 }, |
| 1316 | { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 }, |
| 1317 | { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 }, |
| 1318 | { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 }, |
| 1319 | { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 }, |
| 1320 | { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 }, |
| 1321 | { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 }, |
| 1322 | { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 }, |
| 1323 | { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 }, |
| 1324 | { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 }, |
| 1325 | { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 }, |
| 1326 | { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 }, |
| 1327 | { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 }, |
| 1328 | { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 }, |
| 1329 | { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 }, |
| 1330 | { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 }, |
| 1331 | { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 }, |
| 1332 | { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 }, |
| 1333 | { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 }, |
| 1334 | { BFD_RELOC_SH_COPY64, R_SH_COPY64 }, |
| 1335 | { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 }, |
| 1336 | { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 }, |
| 1337 | { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 }, |
| 1338 | { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 }, |
| 1339 | { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 }, |
| 1340 | { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 }, |
| 1341 | { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 }, |
| 1342 | { BFD_RELOC_SH_PT_16, R_SH_PT_16 }, |
| 1343 | { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE }, |
| 1344 | { BFD_RELOC_SH_IMMU5, R_SH_DIR5U }, |
| 1345 | { BFD_RELOC_SH_IMMS6, R_SH_DIR6S }, |
| 1346 | { BFD_RELOC_SH_IMMU6, R_SH_DIR6U }, |
| 1347 | { BFD_RELOC_SH_IMMS10, R_SH_DIR10S }, |
| 1348 | { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW }, |
| 1349 | { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL }, |
| 1350 | { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ }, |
| 1351 | { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 }, |
| 1352 | { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 }, |
| 1353 | { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 }, |
| 1354 | { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL }, |
| 1355 | { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 }, |
| 1356 | { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL }, |
| 1357 | { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 }, |
| 1358 | { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL }, |
| 1359 | { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 }, |
| 1360 | { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL }, |
| 1361 | { BFD_RELOC_64, R_SH_64 }, |
| 1362 | { BFD_RELOC_64_PCREL, R_SH_64_PCREL }, |
| 1363 | }; |
| 1364 | |
| 1365 | /* Given a BFD reloc code, return the howto structure for the |
| 1366 | corresponding SH ELf reloc. */ |
| 1367 | |
| 1368 | static reloc_howto_type * |
| 1369 | sh_elf64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
| 1370 | bfd_reloc_code_real_type code) |
| 1371 | { |
| 1372 | unsigned int i; |
| 1373 | |
| 1374 | for (i = 0; i < sizeof (sh64_reloc_map) / sizeof (struct elf_reloc_map); i++) |
| 1375 | { |
| 1376 | if (sh64_reloc_map[i].bfd_reloc_val == code) |
| 1377 | return &sh_elf64_howto_table[(int) sh64_reloc_map[i].elf_reloc_val]; |
| 1378 | } |
| 1379 | |
| 1380 | return NULL; |
| 1381 | } |
| 1382 | |
| 1383 | static reloc_howto_type * |
| 1384 | sh_elf64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
| 1385 | const char *r_name) |
| 1386 | { |
| 1387 | unsigned int i; |
| 1388 | |
| 1389 | for (i = 0; |
| 1390 | i < sizeof (sh_elf64_howto_table) / sizeof (sh_elf64_howto_table[0]); |
| 1391 | i++) |
| 1392 | if (sh_elf64_howto_table[i].name != NULL |
| 1393 | && strcasecmp (sh_elf64_howto_table[i].name, r_name) == 0) |
| 1394 | return &sh_elf64_howto_table[i]; |
| 1395 | |
| 1396 | return NULL; |
| 1397 | } |
| 1398 | |
| 1399 | /* Given an ELF reloc, fill in the howto field of a relent. |
| 1400 | |
| 1401 | See sh_elf_info_to_howto in elf32-sh.c for the original. */ |
| 1402 | |
| 1403 | static void |
| 1404 | sh_elf64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, |
| 1405 | Elf_Internal_Rela *dst) |
| 1406 | { |
| 1407 | unsigned int r; |
| 1408 | |
| 1409 | r = ELF64_R_TYPE (dst->r_info); |
| 1410 | |
| 1411 | BFD_ASSERT (r <= (unsigned int) R_SH_64_PCREL); |
| 1412 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC); |
| 1413 | BFD_ASSERT (r < R_SH_DIR8WPN || r > R_SH_LAST_INVALID_RELOC_2); |
| 1414 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_GOTPLT32); |
| 1415 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4); |
| 1416 | |
| 1417 | cache_ptr->howto = &sh_elf64_howto_table[r]; |
| 1418 | } |
| 1419 | |
| 1420 | /* Relocate an SH ELF section. |
| 1421 | |
| 1422 | See sh_elf_info_to_howto in elf32-sh.c for the original. */ |
| 1423 | |
| 1424 | static bfd_boolean |
| 1425 | sh_elf64_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, |
| 1426 | struct bfd_link_info *info, bfd *input_bfd, |
| 1427 | asection *input_section, bfd_byte *contents, |
| 1428 | Elf_Internal_Rela *relocs, |
| 1429 | Elf_Internal_Sym *local_syms, |
| 1430 | asection **local_sections) |
| 1431 | { |
| 1432 | Elf_Internal_Shdr *symtab_hdr; |
| 1433 | struct elf_link_hash_entry **sym_hashes; |
| 1434 | Elf_Internal_Rela *rel, *relend; |
| 1435 | bfd_vma *local_got_offsets; |
| 1436 | asection *sgot; |
| 1437 | asection *sgotplt; |
| 1438 | asection *splt; |
| 1439 | asection *sreloc; |
| 1440 | bfd_vma disp, dropped; |
| 1441 | |
| 1442 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
| 1443 | sym_hashes = elf_sym_hashes (input_bfd); |
| 1444 | local_got_offsets = elf_local_got_offsets (input_bfd); |
| 1445 | |
| 1446 | sreloc = NULL; |
| 1447 | |
| 1448 | rel = relocs; |
| 1449 | relend = relocs + input_section->reloc_count; |
| 1450 | for (; rel < relend; rel++) |
| 1451 | { |
| 1452 | int r_type; |
| 1453 | reloc_howto_type *howto; |
| 1454 | unsigned long r_symndx; |
| 1455 | Elf_Internal_Sym *sym; |
| 1456 | asection *sec; |
| 1457 | struct elf_link_hash_entry *h; |
| 1458 | bfd_vma relocation; |
| 1459 | bfd_vma addend = (bfd_vma)0; |
| 1460 | bfd_reloc_status_type r; |
| 1461 | int seen_stt_datalabel = 0; |
| 1462 | |
| 1463 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 1464 | |
| 1465 | r_type = ELF64_R_TYPE (rel->r_info); |
| 1466 | |
| 1467 | if (r_type == (int) R_SH_NONE) |
| 1468 | continue; |
| 1469 | |
| 1470 | if (r_type < 0 |
| 1471 | || r_type > R_SH_64_PCREL |
| 1472 | || (r_type >= (int) R_SH_FIRST_INVALID_RELOC |
| 1473 | && r_type <= (int) R_SH_LAST_INVALID_RELOC) |
| 1474 | || (r_type >= (int) R_SH_DIR8WPN |
| 1475 | && r_type <= (int) R_SH_LAST_INVALID_RELOC) |
| 1476 | || (r_type >= (int) R_SH_GNU_VTINHERIT |
| 1477 | && r_type <= (int) R_SH_PSHL) |
| 1478 | || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2 |
| 1479 | && r_type <= R_SH_GOTPLT32) |
| 1480 | || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_4 |
| 1481 | && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)) |
| 1482 | { |
| 1483 | bfd_set_error (bfd_error_bad_value); |
| 1484 | return FALSE; |
| 1485 | } |
| 1486 | |
| 1487 | howto = sh_elf64_howto_table + r_type; |
| 1488 | |
| 1489 | h = NULL; |
| 1490 | sym = NULL; |
| 1491 | sec = NULL; |
| 1492 | relocation = 0; |
| 1493 | if (r_symndx < symtab_hdr->sh_info) |
| 1494 | { |
| 1495 | sym = local_syms + r_symndx; |
| 1496 | sec = local_sections[r_symndx]; |
| 1497 | relocation = ((sec->output_section->vma |
| 1498 | + sec->output_offset |
| 1499 | + sym->st_value) |
| 1500 | | ((sym->st_other & STO_SH5_ISA32) != 0)); |
| 1501 | |
| 1502 | /* A local symbol never has STO_SH5_ISA32, so we don't need |
| 1503 | datalabel processing here. Make sure this does not change |
| 1504 | without notice. */ |
| 1505 | if ((sym->st_other & STO_SH5_ISA32) != 0) |
| 1506 | (*info->callbacks->reloc_dangerous) |
| 1507 | (info, |
| 1508 | _("Unexpected STO_SH5_ISA32 on local symbol is not handled"), |
| 1509 | input_bfd, input_section, rel->r_offset); |
| 1510 | |
| 1511 | if (sec != NULL && discarded_section (sec)) |
| 1512 | /* Handled below. */ |
| 1513 | ; |
| 1514 | else if (bfd_link_relocatable (info)) |
| 1515 | { |
| 1516 | /* This is a relocatable link. We don't have to change |
| 1517 | anything, unless the reloc is against a section symbol, |
| 1518 | in which case we have to adjust according to where the |
| 1519 | section symbol winds up in the output section. */ |
| 1520 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) |
| 1521 | goto final_link_relocate; |
| 1522 | |
| 1523 | continue; |
| 1524 | } |
| 1525 | else if (! howto->partial_inplace) |
| 1526 | { |
| 1527 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
| 1528 | relocation |= ((sym->st_other & STO_SH5_ISA32) != 0); |
| 1529 | } |
| 1530 | else if ((sec->flags & SEC_MERGE) |
| 1531 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION) |
| 1532 | { |
| 1533 | asection *msec; |
| 1534 | |
| 1535 | if (howto->rightshift || howto->src_mask != 0xffffffff) |
| 1536 | { |
| 1537 | _bfd_error_handler |
| 1538 | /* xgettext:c-format */ |
| 1539 | (_("%pB(%pA+%#" PRIx64 "): " |
| 1540 | "%s relocation against SEC_MERGE section"), |
| 1541 | input_bfd, input_section, |
| 1542 | (uint64_t) rel->r_offset, howto->name); |
| 1543 | return FALSE; |
| 1544 | } |
| 1545 | |
| 1546 | addend = bfd_get_32 (input_bfd, contents + rel->r_offset); |
| 1547 | msec = sec; |
| 1548 | addend = |
| 1549 | _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) |
| 1550 | - relocation; |
| 1551 | addend += msec->output_section->vma + msec->output_offset; |
| 1552 | bfd_put_32 (input_bfd, addend, contents + rel->r_offset); |
| 1553 | addend = 0; |
| 1554 | } |
| 1555 | } |
| 1556 | else |
| 1557 | { |
| 1558 | /* ??? Could we use the RELOC_FOR_GLOBAL_SYMBOL macro here ? */ |
| 1559 | |
| 1560 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 1561 | while (h->root.type == bfd_link_hash_indirect |
| 1562 | || h->root.type == bfd_link_hash_warning) |
| 1563 | { |
| 1564 | /* If the reference passes a symbol marked with |
| 1565 | STT_DATALABEL, then any STO_SH5_ISA32 on the final value |
| 1566 | doesn't count. */ |
| 1567 | seen_stt_datalabel |= h->type == STT_DATALABEL; |
| 1568 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 1569 | } |
| 1570 | |
| 1571 | if (h->root.type == bfd_link_hash_defined |
| 1572 | || h->root.type == bfd_link_hash_defweak) |
| 1573 | { |
| 1574 | sec = h->root.u.def.section; |
| 1575 | /* In these cases, we don't need the relocation value. |
| 1576 | We check specially because in some obscure cases |
| 1577 | sec->output_section will be NULL. */ |
| 1578 | if (r_type == R_SH_GOTPC_LOW16 |
| 1579 | || r_type == R_SH_GOTPC_MEDLOW16 |
| 1580 | || r_type == R_SH_GOTPC_MEDHI16 |
| 1581 | || r_type == R_SH_GOTPC_HI16 |
| 1582 | || ((r_type == R_SH_PLT_LOW16 |
| 1583 | || r_type == R_SH_PLT_MEDLOW16 |
| 1584 | || r_type == R_SH_PLT_MEDHI16 |
| 1585 | || r_type == R_SH_PLT_HI16) |
| 1586 | && h->plt.offset != (bfd_vma) -1) |
| 1587 | || ((r_type == R_SH_GOT_LOW16 |
| 1588 | || r_type == R_SH_GOT_MEDLOW16 |
| 1589 | || r_type == R_SH_GOT_MEDHI16 |
| 1590 | || r_type == R_SH_GOT_HI16) |
| 1591 | && elf_hash_table (info)->dynamic_sections_created |
| 1592 | && (! bfd_link_pic (info) |
| 1593 | || (! info->symbolic && h->dynindx != -1) |
| 1594 | || !h->def_regular)) |
| 1595 | /* The cases above are those in which relocation is |
| 1596 | overwritten in the switch block below. The cases |
| 1597 | below are those in which we must defer relocation |
| 1598 | to run-time, because we can't resolve absolute |
| 1599 | addresses when creating a shared library. */ |
| 1600 | || (bfd_link_pic (info) |
| 1601 | && ((! info->symbolic && h->dynindx != -1) |
| 1602 | || !h->def_regular) |
| 1603 | && ((r_type == R_SH_64 |
| 1604 | && !(ELF_ST_VISIBILITY (h->other) == STV_INTERNAL |
| 1605 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)) |
| 1606 | || r_type == R_SH_64_PCREL) |
| 1607 | && ((input_section->flags & SEC_ALLOC) != 0 |
| 1608 | /* DWARF will emit R_SH_DIR32 relocations in its |
| 1609 | sections against symbols defined externally |
| 1610 | in shared libraries. We can't do anything |
| 1611 | with them here. */ |
| 1612 | || (input_section->flags & SEC_DEBUGGING) != 0)) |
| 1613 | /* Dynamic relocs are not propagated for SEC_DEBUGGING |
| 1614 | sections because such sections are not SEC_ALLOC and |
| 1615 | thus ld.so will not process them. */ |
| 1616 | || (sec->output_section == NULL |
| 1617 | && ((input_section->flags & SEC_DEBUGGING) != 0 |
| 1618 | && h->def_dynamic))) |
| 1619 | ; |
| 1620 | else if (sec->output_section != NULL) |
| 1621 | relocation = ((h->root.u.def.value |
| 1622 | + sec->output_section->vma |
| 1623 | + sec->output_offset) |
| 1624 | /* A STO_SH5_ISA32 causes a "bitor 1" to the |
| 1625 | symbol value, unless we've seen |
| 1626 | STT_DATALABEL on the way to it. */ |
| 1627 | | ((h->other & STO_SH5_ISA32) != 0 |
| 1628 | && ! seen_stt_datalabel)); |
| 1629 | else if (!bfd_link_relocatable (info) |
| 1630 | && (_bfd_elf_section_offset (output_bfd, info, |
| 1631 | input_section, |
| 1632 | rel->r_offset) |
| 1633 | != (bfd_vma) -1)) |
| 1634 | { |
| 1635 | _bfd_error_handler |
| 1636 | /* xgettext:c-format */ |
| 1637 | (_("%pB(%pA+%#" PRIx64 "): " |
| 1638 | "unresolvable %s relocation against symbol `%s'"), |
| 1639 | input_bfd, |
| 1640 | input_section, |
| 1641 | (uint64_t) rel->r_offset, |
| 1642 | howto->name, |
| 1643 | h->root.root.string); |
| 1644 | } |
| 1645 | } |
| 1646 | else if (h->root.type == bfd_link_hash_undefweak) |
| 1647 | ; |
| 1648 | else if (info->unresolved_syms_in_objects == RM_IGNORE |
| 1649 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
| 1650 | ; |
| 1651 | else if (!bfd_link_relocatable (info)) |
| 1652 | (*info->callbacks->undefined_symbol) |
| 1653 | (info, h->root.root.string, input_bfd, |
| 1654 | input_section, rel->r_offset, |
| 1655 | (info->unresolved_syms_in_objects == RM_GENERATE_ERROR |
| 1656 | || ELF_ST_VISIBILITY (h->other))); |
| 1657 | } |
| 1658 | |
| 1659 | if (sec != NULL && discarded_section (sec)) |
| 1660 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
| 1661 | rel, 1, relend, howto, 0, contents); |
| 1662 | |
| 1663 | if (bfd_link_relocatable (info)) |
| 1664 | continue; |
| 1665 | |
| 1666 | disp = (relocation |
| 1667 | - input_section->output_section->vma |
| 1668 | - input_section->output_offset |
| 1669 | - rel->r_offset); |
| 1670 | dropped = 0; |
| 1671 | switch ((int)r_type) |
| 1672 | { |
| 1673 | case R_SH_PT_16: dropped = disp & 2; break; |
| 1674 | case R_SH_DIR10SW: dropped = disp & 1; break; |
| 1675 | case R_SH_DIR10SL: dropped = disp & 3; break; |
| 1676 | case R_SH_DIR10SQ: dropped = disp & 7; break; |
| 1677 | } |
| 1678 | if (dropped != 0) |
| 1679 | { |
| 1680 | _bfd_error_handler |
| 1681 | /* xgettext:c-format */ |
| 1682 | (_("%pB: error: unaligned relocation type %d at " |
| 1683 | "%08" PRIx64 " reloc %08" PRIx64 ""), |
| 1684 | input_bfd, (int) r_type, |
| 1685 | (uint64_t) rel->r_offset, (uint64_t) relocation); |
| 1686 | bfd_set_error (bfd_error_bad_value); |
| 1687 | return FALSE; |
| 1688 | } |
| 1689 | switch ((int)r_type) |
| 1690 | { |
| 1691 | case R_SH_64: |
| 1692 | case R_SH_64_PCREL: |
| 1693 | if (bfd_link_pic (info) |
| 1694 | && (input_section->flags & SEC_ALLOC) != 0 |
| 1695 | && (r_type != R_SH_64_PCREL |
| 1696 | || (h != NULL |
| 1697 | && h->dynindx != -1 |
| 1698 | && (! info->symbolic |
| 1699 | || !h->def_regular)))) |
| 1700 | { |
| 1701 | Elf_Internal_Rela outrel; |
| 1702 | bfd_byte *loc; |
| 1703 | bfd_boolean skip, relocate; |
| 1704 | |
| 1705 | /* When generating a shared object, these relocations |
| 1706 | are copied into the output file to be resolved at run |
| 1707 | time. */ |
| 1708 | |
| 1709 | if (sreloc == NULL) |
| 1710 | { |
| 1711 | sreloc = _bfd_elf_get_dynamic_reloc_section |
| 1712 | (input_bfd, input_section, /*rela?*/ TRUE); |
| 1713 | if (sreloc == NULL) |
| 1714 | return FALSE; |
| 1715 | } |
| 1716 | |
| 1717 | skip = FALSE; |
| 1718 | relocate = FALSE; |
| 1719 | |
| 1720 | outrel.r_offset |
| 1721 | = _bfd_elf_section_offset (output_bfd, info, |
| 1722 | input_section, rel->r_offset); |
| 1723 | |
| 1724 | if (outrel.r_offset == (bfd_vma) -1) |
| 1725 | skip = TRUE; |
| 1726 | else if (outrel.r_offset == (bfd_vma) -2) |
| 1727 | skip = TRUE, relocate = TRUE; |
| 1728 | |
| 1729 | outrel.r_offset += (input_section->output_section->vma |
| 1730 | + input_section->output_offset); |
| 1731 | |
| 1732 | if (skip) |
| 1733 | memset (&outrel, 0, sizeof outrel); |
| 1734 | else if (r_type == R_SH_64_PCREL) |
| 1735 | { |
| 1736 | BFD_ASSERT (h != NULL && h->dynindx != -1); |
| 1737 | outrel.r_info = ELF64_R_INFO (h->dynindx, R_SH_64_PCREL); |
| 1738 | outrel.r_addend = rel->r_addend; |
| 1739 | } |
| 1740 | else |
| 1741 | { |
| 1742 | /* h->dynindx may be -1 if this symbol was marked to |
| 1743 | become local. */ |
| 1744 | if (h == NULL |
| 1745 | || ((info->symbolic || h->dynindx == -1) |
| 1746 | && h->def_regular)) |
| 1747 | { |
| 1748 | relocate = TRUE; |
| 1749 | outrel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64); |
| 1750 | outrel.r_addend = relocation + rel->r_addend; |
| 1751 | } |
| 1752 | else |
| 1753 | { |
| 1754 | BFD_ASSERT (h->dynindx != -1); |
| 1755 | outrel.r_info = ELF64_R_INFO (h->dynindx, R_SH_64); |
| 1756 | outrel.r_addend = relocation + rel->r_addend; |
| 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | loc = sreloc->contents; |
| 1761 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); |
| 1762 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
| 1763 | |
| 1764 | /* If this reloc is against an external symbol, we do |
| 1765 | not want to fiddle with the addend. Otherwise, we |
| 1766 | need to include the symbol value so that it becomes |
| 1767 | an addend for the dynamic reloc. */ |
| 1768 | if (! relocate) |
| 1769 | continue; |
| 1770 | } |
| 1771 | else if (r_type == R_SH_64) |
| 1772 | addend = rel->r_addend; |
| 1773 | goto final_link_relocate; |
| 1774 | |
| 1775 | case R_SH_GOTPLT_LOW16: |
| 1776 | case R_SH_GOTPLT_MEDLOW16: |
| 1777 | case R_SH_GOTPLT_MEDHI16: |
| 1778 | case R_SH_GOTPLT_HI16: |
| 1779 | case R_SH_GOTPLT10BY4: |
| 1780 | case R_SH_GOTPLT10BY8: |
| 1781 | /* Relocation is to the entry for this symbol in the |
| 1782 | procedure linkage table. */ |
| 1783 | |
| 1784 | if (h == NULL |
| 1785 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL |
| 1786 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN |
| 1787 | || ! bfd_link_pic (info) |
| 1788 | || info->symbolic |
| 1789 | || h->dynindx == -1 |
| 1790 | || h->plt.offset == (bfd_vma) -1 |
| 1791 | || h->got.offset != (bfd_vma) -1) |
| 1792 | goto force_got; |
| 1793 | |
| 1794 | /* Relocation is to the entry for this symbol in the global |
| 1795 | offset table extension for the procedure linkage table. */ |
| 1796 | sgotplt = elf_hash_table (info)->sgotplt; |
| 1797 | BFD_ASSERT (sgotplt != NULL); |
| 1798 | |
| 1799 | relocation = (sgotplt->output_offset |
| 1800 | + ((h->plt.offset / elf_sh64_sizeof_plt (info) |
| 1801 | - 1 + 3) * 8)); |
| 1802 | |
| 1803 | relocation -= GOT_BIAS; |
| 1804 | |
| 1805 | goto final_link_relocate; |
| 1806 | |
| 1807 | force_got: |
| 1808 | case R_SH_GOT_LOW16: |
| 1809 | case R_SH_GOT_MEDLOW16: |
| 1810 | case R_SH_GOT_MEDHI16: |
| 1811 | case R_SH_GOT_HI16: |
| 1812 | case R_SH_GOT10BY4: |
| 1813 | case R_SH_GOT10BY8: |
| 1814 | /* Relocation is to the entry for this symbol in the global |
| 1815 | offset table. */ |
| 1816 | sgot = elf_hash_table (info)->sgot; |
| 1817 | BFD_ASSERT (sgot != NULL); |
| 1818 | |
| 1819 | if (h != NULL) |
| 1820 | { |
| 1821 | bfd_vma off; |
| 1822 | |
| 1823 | off = h->got.offset; |
| 1824 | if (seen_stt_datalabel) |
| 1825 | { |
| 1826 | struct elf_sh64_link_hash_entry *hsh; |
| 1827 | |
| 1828 | hsh = (struct elf_sh64_link_hash_entry *)h; |
| 1829 | off = hsh->datalabel_got_offset; |
| 1830 | } |
| 1831 | BFD_ASSERT (off != (bfd_vma) -1); |
| 1832 | |
| 1833 | if (! elf_hash_table (info)->dynamic_sections_created |
| 1834 | || (bfd_link_pic (info) |
| 1835 | && (info->symbolic || h->dynindx == -1 |
| 1836 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL |
| 1837 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN) |
| 1838 | && h->def_regular)) |
| 1839 | { |
| 1840 | /* This is actually a static link, or it is a |
| 1841 | -Bsymbolic link and the symbol is defined |
| 1842 | locally, or the symbol was forced to be local |
| 1843 | because of a version file. We must initialize |
| 1844 | this entry in the global offset table. Since the |
| 1845 | offset must always be a multiple of 4, we use the |
| 1846 | least significant bit to record whether we have |
| 1847 | initialized it already. |
| 1848 | |
| 1849 | When doing a dynamic link, we create a .rela.got |
| 1850 | relocation entry to initialize the value. This |
| 1851 | is done in the finish_dynamic_symbol routine. */ |
| 1852 | if ((off & 1) != 0) |
| 1853 | off &= ~1; |
| 1854 | else |
| 1855 | { |
| 1856 | bfd_put_64 (output_bfd, relocation, |
| 1857 | sgot->contents + off); |
| 1858 | if (seen_stt_datalabel) |
| 1859 | { |
| 1860 | struct elf_sh64_link_hash_entry *hsh; |
| 1861 | |
| 1862 | hsh = (struct elf_sh64_link_hash_entry *)h; |
| 1863 | hsh->datalabel_got_offset |= 1; |
| 1864 | } |
| 1865 | else |
| 1866 | h->got.offset |= 1; |
| 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | relocation = sgot->output_offset + off; |
| 1871 | } |
| 1872 | else |
| 1873 | { |
| 1874 | bfd_vma off; |
| 1875 | |
| 1876 | if (rel->r_addend) |
| 1877 | { |
| 1878 | BFD_ASSERT (local_got_offsets != NULL |
| 1879 | && (local_got_offsets[symtab_hdr->sh_info |
| 1880 | + r_symndx] |
| 1881 | != (bfd_vma) -1)); |
| 1882 | |
| 1883 | off = local_got_offsets[symtab_hdr->sh_info |
| 1884 | + r_symndx]; |
| 1885 | } |
| 1886 | else |
| 1887 | { |
| 1888 | BFD_ASSERT (local_got_offsets != NULL |
| 1889 | && local_got_offsets[r_symndx] != (bfd_vma) -1); |
| 1890 | |
| 1891 | off = local_got_offsets[r_symndx]; |
| 1892 | } |
| 1893 | |
| 1894 | /* The offset must always be a multiple of 8. We use |
| 1895 | the least significant bit to record whether we have |
| 1896 | already generated the necessary reloc. */ |
| 1897 | if ((off & 1) != 0) |
| 1898 | off &= ~1; |
| 1899 | else |
| 1900 | { |
| 1901 | bfd_put_64 (output_bfd, relocation, sgot->contents + off); |
| 1902 | |
| 1903 | if (bfd_link_pic (info)) |
| 1904 | { |
| 1905 | asection *s; |
| 1906 | Elf_Internal_Rela outrel; |
| 1907 | bfd_byte *loc; |
| 1908 | |
| 1909 | s = elf_hash_table (info)->srelgot; |
| 1910 | BFD_ASSERT (s != NULL); |
| 1911 | |
| 1912 | outrel.r_offset = (sgot->output_section->vma |
| 1913 | + sgot->output_offset |
| 1914 | + off); |
| 1915 | outrel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64); |
| 1916 | outrel.r_addend = relocation; |
| 1917 | loc = s->contents; |
| 1918 | loc += s->reloc_count++ * sizeof (Elf64_External_Rela); |
| 1919 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
| 1920 | } |
| 1921 | |
| 1922 | if (rel->r_addend) |
| 1923 | local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1; |
| 1924 | else |
| 1925 | local_got_offsets[r_symndx] |= 1; |
| 1926 | } |
| 1927 | |
| 1928 | relocation = sgot->output_offset + off; |
| 1929 | } |
| 1930 | |
| 1931 | relocation -= GOT_BIAS; |
| 1932 | |
| 1933 | goto final_link_relocate; |
| 1934 | |
| 1935 | case R_SH_GOTOFF_LOW16: |
| 1936 | case R_SH_GOTOFF_MEDLOW16: |
| 1937 | case R_SH_GOTOFF_MEDHI16: |
| 1938 | case R_SH_GOTOFF_HI16: |
| 1939 | /* Relocation is relative to the start of the global offset |
| 1940 | table. */ |
| 1941 | |
| 1942 | sgot = elf_hash_table (info)->sgot; |
| 1943 | BFD_ASSERT (sgot != NULL); |
| 1944 | |
| 1945 | /* Note that sgot->output_offset is not involved in this |
| 1946 | calculation. We always want the start of .got. If we |
| 1947 | defined _GLOBAL_OFFSET_TABLE in a different way, as is |
| 1948 | permitted by the ABI, we might have to change this |
| 1949 | calculation. */ |
| 1950 | relocation -= sgot->output_section->vma; |
| 1951 | |
| 1952 | relocation -= GOT_BIAS; |
| 1953 | |
| 1954 | addend = rel->r_addend; |
| 1955 | |
| 1956 | goto final_link_relocate; |
| 1957 | |
| 1958 | case R_SH_GOTPC_LOW16: |
| 1959 | case R_SH_GOTPC_MEDLOW16: |
| 1960 | case R_SH_GOTPC_MEDHI16: |
| 1961 | case R_SH_GOTPC_HI16: |
| 1962 | /* Use global offset table as symbol value. */ |
| 1963 | |
| 1964 | sgot = elf_hash_table (info)->sgot; |
| 1965 | BFD_ASSERT (sgot != NULL); |
| 1966 | |
| 1967 | relocation = sgot->output_section->vma; |
| 1968 | |
| 1969 | relocation += GOT_BIAS; |
| 1970 | |
| 1971 | addend = rel->r_addend; |
| 1972 | |
| 1973 | goto final_link_relocate; |
| 1974 | |
| 1975 | case R_SH_PLT_LOW16: |
| 1976 | case R_SH_PLT_MEDLOW16: |
| 1977 | case R_SH_PLT_MEDHI16: |
| 1978 | case R_SH_PLT_HI16: |
| 1979 | /* Relocation is to the entry for this symbol in the |
| 1980 | procedure linkage table. */ |
| 1981 | |
| 1982 | /* Resolve a PLT reloc against a local symbol directly, |
| 1983 | without using the procedure linkage table. */ |
| 1984 | if (h == NULL) |
| 1985 | goto final_link_relocate; |
| 1986 | |
| 1987 | if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL |
| 1988 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN) |
| 1989 | goto final_link_relocate; |
| 1990 | |
| 1991 | if (h->plt.offset == (bfd_vma) -1) |
| 1992 | { |
| 1993 | /* We didn't make a PLT entry for this symbol. This |
| 1994 | happens when statically linking PIC code, or when |
| 1995 | using -Bsymbolic. */ |
| 1996 | goto final_link_relocate; |
| 1997 | } |
| 1998 | |
| 1999 | splt = elf_hash_table (info)->splt; |
| 2000 | BFD_ASSERT (splt != NULL); |
| 2001 | |
| 2002 | relocation = (splt->output_section->vma |
| 2003 | + splt->output_offset |
| 2004 | + h->plt.offset); |
| 2005 | relocation++; |
| 2006 | |
| 2007 | addend = rel->r_addend; |
| 2008 | |
| 2009 | goto final_link_relocate; |
| 2010 | |
| 2011 | case R_SH_DIR32: |
| 2012 | case R_SH_SHMEDIA_CODE: |
| 2013 | case R_SH_PT_16: |
| 2014 | case R_SH_DIR5U: |
| 2015 | case R_SH_DIR6S: |
| 2016 | case R_SH_DIR6U: |
| 2017 | case R_SH_DIR10S: |
| 2018 | case R_SH_DIR10SW: |
| 2019 | case R_SH_DIR10SL: |
| 2020 | case R_SH_DIR10SQ: |
| 2021 | case R_SH_IMMS16: |
| 2022 | case R_SH_IMMU16: |
| 2023 | case R_SH_IMM_LOW16: |
| 2024 | case R_SH_IMM_LOW16_PCREL: |
| 2025 | case R_SH_IMM_MEDLOW16: |
| 2026 | case R_SH_IMM_MEDLOW16_PCREL: |
| 2027 | case R_SH_IMM_MEDHI16: |
| 2028 | case R_SH_IMM_MEDHI16_PCREL: |
| 2029 | case R_SH_IMM_HI16: |
| 2030 | case R_SH_IMM_HI16_PCREL: |
| 2031 | addend = rel->r_addend; |
| 2032 | /* Fall through. */ |
| 2033 | case R_SH_REL32: |
| 2034 | final_link_relocate: |
| 2035 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 2036 | contents, rel->r_offset, |
| 2037 | relocation, addend); |
| 2038 | break; |
| 2039 | |
| 2040 | default: |
| 2041 | bfd_set_error (bfd_error_bad_value); |
| 2042 | return FALSE; |
| 2043 | |
| 2044 | } |
| 2045 | |
| 2046 | if (r != bfd_reloc_ok) |
| 2047 | { |
| 2048 | switch (r) |
| 2049 | { |
| 2050 | default: |
| 2051 | case bfd_reloc_outofrange: |
| 2052 | abort (); |
| 2053 | case bfd_reloc_overflow: |
| 2054 | { |
| 2055 | const char *name; |
| 2056 | |
| 2057 | if (h != NULL) |
| 2058 | name = NULL; |
| 2059 | else |
| 2060 | { |
| 2061 | name = (bfd_elf_string_from_elf_section |
| 2062 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); |
| 2063 | if (name == NULL) |
| 2064 | return FALSE; |
| 2065 | if (*name == '\0') |
| 2066 | name = bfd_section_name (input_bfd, sec); |
| 2067 | } |
| 2068 | (*info->callbacks->reloc_overflow) |
| 2069 | (info, (h ? &h->root : NULL), name, howto->name, |
| 2070 | (bfd_vma) 0, input_bfd, input_section, rel->r_offset); |
| 2071 | } |
| 2072 | break; |
| 2073 | } |
| 2074 | } |
| 2075 | } |
| 2076 | |
| 2077 | return TRUE; |
| 2078 | } |
| 2079 | |
| 2080 | /* This is a version of bfd_generic_get_relocated_section_contents |
| 2081 | that uses sh_elf64_relocate_section. |
| 2082 | |
| 2083 | See sh_elf_relocate_section in elf32-sh.c for the original. */ |
| 2084 | |
| 2085 | static bfd_byte * |
| 2086 | sh_elf64_get_relocated_section_contents (bfd *output_bfd, |
| 2087 | struct bfd_link_info *link_info, |
| 2088 | struct bfd_link_order *link_order, |
| 2089 | bfd_byte *data, |
| 2090 | bfd_boolean relocatable, |
| 2091 | asymbol **symbols) |
| 2092 | { |
| 2093 | Elf_Internal_Shdr *symtab_hdr; |
| 2094 | asection *input_section = link_order->u.indirect.section; |
| 2095 | bfd *input_bfd = input_section->owner; |
| 2096 | asection **sections = NULL; |
| 2097 | Elf_Internal_Rela *internal_relocs = NULL; |
| 2098 | Elf_Internal_Sym *isymbuf = NULL; |
| 2099 | |
| 2100 | /* We only need to handle the case of relaxing, or of having a |
| 2101 | particular set of section contents, specially. */ |
| 2102 | if (relocatable |
| 2103 | || elf_section_data (input_section)->this_hdr.contents == NULL) |
| 2104 | return bfd_generic_get_relocated_section_contents (output_bfd, link_info, |
| 2105 | link_order, data, |
| 2106 | relocatable, |
| 2107 | symbols); |
| 2108 | |
| 2109 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
| 2110 | |
| 2111 | memcpy (data, elf_section_data (input_section)->this_hdr.contents, |
| 2112 | input_section->size); |
| 2113 | |
| 2114 | if ((input_section->flags & SEC_RELOC) != 0 |
| 2115 | && input_section->reloc_count > 0) |
| 2116 | { |
| 2117 | Elf_Internal_Sym *isymp; |
| 2118 | Elf_Internal_Sym *isymend; |
| 2119 | asection **secpp; |
| 2120 | |
| 2121 | /* Read this BFD's local symbols. */ |
| 2122 | if (symtab_hdr->sh_info != 0) |
| 2123 | { |
| 2124 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; |
| 2125 | if (isymbuf == NULL) |
| 2126 | isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, |
| 2127 | symtab_hdr->sh_info, 0, |
| 2128 | NULL, NULL, NULL); |
| 2129 | if (isymbuf == NULL) |
| 2130 | goto error_return; |
| 2131 | } |
| 2132 | |
| 2133 | internal_relocs = (_bfd_elf_link_read_relocs |
| 2134 | (input_bfd, input_section, NULL, |
| 2135 | (Elf_Internal_Rela *) NULL, FALSE)); |
| 2136 | if (internal_relocs == NULL) |
| 2137 | goto error_return; |
| 2138 | |
| 2139 | sections = (asection **) bfd_malloc (symtab_hdr->sh_info |
| 2140 | * sizeof (asection *)); |
| 2141 | if (sections == NULL && symtab_hdr->sh_info > 0) |
| 2142 | goto error_return; |
| 2143 | |
| 2144 | secpp = sections; |
| 2145 | isymend = isymbuf + symtab_hdr->sh_info; |
| 2146 | for (isymp = isymbuf; isymp < isymend; ++isymp, ++secpp) |
| 2147 | { |
| 2148 | asection *isec; |
| 2149 | |
| 2150 | if (isymp->st_shndx == SHN_UNDEF) |
| 2151 | isec = bfd_und_section_ptr; |
| 2152 | else if (isymp->st_shndx == SHN_ABS) |
| 2153 | isec = bfd_abs_section_ptr; |
| 2154 | else if (isymp->st_shndx == SHN_COMMON) |
| 2155 | isec = bfd_com_section_ptr; |
| 2156 | else |
| 2157 | isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx); |
| 2158 | |
| 2159 | *secpp = isec; |
| 2160 | } |
| 2161 | |
| 2162 | if (! sh_elf64_relocate_section (output_bfd, link_info, input_bfd, |
| 2163 | input_section, data, internal_relocs, |
| 2164 | isymbuf, sections)) |
| 2165 | goto error_return; |
| 2166 | |
| 2167 | if (sections != NULL) |
| 2168 | free (sections); |
| 2169 | if (internal_relocs != elf_section_data (input_section)->relocs) |
| 2170 | free (internal_relocs); |
| 2171 | if (isymbuf != NULL |
| 2172 | && (unsigned char *) isymbuf != symtab_hdr->contents) |
| 2173 | free (isymbuf); |
| 2174 | } |
| 2175 | |
| 2176 | return data; |
| 2177 | |
| 2178 | error_return: |
| 2179 | if (sections != NULL) |
| 2180 | free (sections); |
| 2181 | if (internal_relocs != NULL |
| 2182 | && internal_relocs != elf_section_data (input_section)->relocs) |
| 2183 | free (internal_relocs); |
| 2184 | if (isymbuf != NULL |
| 2185 | && (unsigned char *) isymbuf != symtab_hdr->contents) |
| 2186 | free (isymbuf); |
| 2187 | return NULL; |
| 2188 | } |
| 2189 | |
| 2190 | /* Set the SHF_SH5_ISA32 flag for ISA SHmedia code sections. */ |
| 2191 | |
| 2192 | static bfd_boolean |
| 2193 | sh64_elf64_fake_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
| 2194 | Elf_Internal_Shdr *elf_section_hdr, |
| 2195 | asection *asect) |
| 2196 | { |
| 2197 | /* Code sections can only contain SH64 code, so mark them as such. */ |
| 2198 | if (bfd_get_section_flags (output_bfd, asect) & SEC_CODE) |
| 2199 | elf_section_hdr->sh_flags |= SHF_SH5_ISA32; |
| 2200 | |
| 2201 | return TRUE; |
| 2202 | } |
| 2203 | |
| 2204 | static bfd_boolean |
| 2205 | sh_elf64_set_mach_from_flags (bfd *abfd) |
| 2206 | { |
| 2207 | flagword flags = elf_elfheader (abfd)->e_flags; |
| 2208 | |
| 2209 | switch (flags & EF_SH_MACH_MASK) |
| 2210 | { |
| 2211 | case EF_SH5: |
| 2212 | /* Just one, but keep the switch construct to make additions easy. */ |
| 2213 | bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh5); |
| 2214 | break; |
| 2215 | |
| 2216 | default: |
| 2217 | bfd_set_error (bfd_error_wrong_format); |
| 2218 | return FALSE; |
| 2219 | } |
| 2220 | return TRUE; |
| 2221 | } |
| 2222 | |
| 2223 | /* Function to keep SH64 specific file flags. |
| 2224 | |
| 2225 | See sh64_elf_set_private_flags in elf32-sh64.c for the original. */ |
| 2226 | |
| 2227 | static bfd_boolean |
| 2228 | sh_elf64_set_private_flags (bfd *abfd, flagword flags) |
| 2229 | { |
| 2230 | BFD_ASSERT (! elf_flags_init (abfd) |
| 2231 | || elf_elfheader (abfd)->e_flags == flags); |
| 2232 | |
| 2233 | elf_elfheader (abfd)->e_flags = flags; |
| 2234 | elf_flags_init (abfd) = TRUE; |
| 2235 | return sh_elf64_set_mach_from_flags (abfd); |
| 2236 | } |
| 2237 | |
| 2238 | /* Copy the SHF_SH5_ISA32 attribute that we keep on all sections with |
| 2239 | code, to keep attributes the same as for SHmedia in 32-bit ELF. */ |
| 2240 | |
| 2241 | static bfd_boolean |
| 2242 | sh_elf64_copy_private_data_internal (bfd *ibfd, bfd *obfd) |
| 2243 | { |
| 2244 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 2245 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 2246 | return TRUE; |
| 2247 | |
| 2248 | /* Copy object attributes. */ |
| 2249 | _bfd_elf_copy_private_bfd_data (ibfd, obfd); |
| 2250 | |
| 2251 | return sh_elf64_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags); |
| 2252 | } |
| 2253 | |
| 2254 | static bfd_boolean |
| 2255 | sh_elf64_copy_private_data (bfd *ibfd, bfd *obfd) |
| 2256 | { |
| 2257 | return sh_elf64_copy_private_data_internal (ibfd, obfd); |
| 2258 | } |
| 2259 | |
| 2260 | static bfd_boolean |
| 2261 | sh_elf64_merge_private_data (bfd *ibfd, struct bfd_link_info *info) |
| 2262 | { |
| 2263 | bfd *obfd = info->output_bfd; |
| 2264 | flagword old_flags, new_flags; |
| 2265 | |
| 2266 | if (! _bfd_generic_verify_endian_match (ibfd, info)) |
| 2267 | return FALSE; |
| 2268 | |
| 2269 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 2270 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 2271 | return TRUE; |
| 2272 | |
| 2273 | if (bfd_get_arch_size (ibfd) != bfd_get_arch_size (obfd)) |
| 2274 | { |
| 2275 | const char *msg; |
| 2276 | |
| 2277 | if (bfd_get_arch_size (ibfd) == 32 |
| 2278 | && bfd_get_arch_size (obfd) == 64) |
| 2279 | /* xgettext:c-format */ |
| 2280 | msg = _("%pB: compiled as 32-bit object and %pB is 64-bit"); |
| 2281 | else if (bfd_get_arch_size (ibfd) == 64 |
| 2282 | && bfd_get_arch_size (obfd) == 32) |
| 2283 | /* xgettext:c-format */ |
| 2284 | msg = _("%pB: compiled as 64-bit object and %pB is 32-bit"); |
| 2285 | else |
| 2286 | /* xgettext:c-format */ |
| 2287 | msg = _("%pB: object size does not match that of target %pB"); |
| 2288 | |
| 2289 | _bfd_error_handler (msg, ibfd, obfd); |
| 2290 | bfd_set_error (bfd_error_wrong_format); |
| 2291 | return FALSE; |
| 2292 | } |
| 2293 | |
| 2294 | old_flags = elf_elfheader (obfd)->e_flags; |
| 2295 | new_flags = elf_elfheader (ibfd)->e_flags; |
| 2296 | if (! elf_flags_init (obfd)) |
| 2297 | { |
| 2298 | /* This happens when ld starts out with a 'blank' output file. */ |
| 2299 | elf_flags_init (obfd) = TRUE; |
| 2300 | elf_elfheader (obfd)->e_flags = old_flags = new_flags; |
| 2301 | } |
| 2302 | /* We don't allow linking in anything else than SH64 code, and since |
| 2303 | this is a 64-bit ELF, we assume the 64-bit ABI is used. Add code |
| 2304 | here as things change. */ |
| 2305 | else if ((new_flags & EF_SH_MACH_MASK) != EF_SH5) |
| 2306 | { |
| 2307 | _bfd_error_handler |
| 2308 | ("%pB: does not use the SH64 64-bit ABI as previous modules do", ibfd); |
| 2309 | bfd_set_error (bfd_error_bad_value); |
| 2310 | return FALSE; |
| 2311 | } |
| 2312 | |
| 2313 | sh_elf64_copy_private_data_internal (ibfd, obfd); |
| 2314 | |
| 2315 | /* I can't think of anything sane other than old_flags being EF_SH5 and |
| 2316 | that we need to preserve that. */ |
| 2317 | elf_elfheader (obfd)->e_flags = old_flags; |
| 2318 | |
| 2319 | return sh_elf64_set_mach_from_flags (obfd); |
| 2320 | } |
| 2321 | |
| 2322 | /* Return the section that should be marked against GC for a given |
| 2323 | relocation. */ |
| 2324 | |
| 2325 | static asection * |
| 2326 | sh_elf64_gc_mark_hook (asection *sec, |
| 2327 | struct bfd_link_info *info, |
| 2328 | Elf_Internal_Rela *rel, |
| 2329 | struct elf_link_hash_entry *h, |
| 2330 | Elf_Internal_Sym *sym) |
| 2331 | { |
| 2332 | if (h != NULL) |
| 2333 | switch (ELF64_R_TYPE (rel->r_info)) |
| 2334 | { |
| 2335 | case R_SH_GNU_VTINHERIT: |
| 2336 | case R_SH_GNU_VTENTRY: |
| 2337 | return NULL; |
| 2338 | } |
| 2339 | |
| 2340 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); |
| 2341 | } |
| 2342 | |
| 2343 | /* Look through the relocs for a section during the first phase. |
| 2344 | Since we don't do .gots or .plts, we just need to consider the |
| 2345 | virtual table relocs for gc. */ |
| 2346 | |
| 2347 | static bfd_boolean |
| 2348 | sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info, |
| 2349 | asection *sec, const Elf_Internal_Rela *relocs) |
| 2350 | { |
| 2351 | Elf_Internal_Shdr *symtab_hdr; |
| 2352 | struct elf_link_hash_entry **sym_hashes; |
| 2353 | const Elf_Internal_Rela *rel; |
| 2354 | const Elf_Internal_Rela *rel_end; |
| 2355 | bfd *dynobj; |
| 2356 | bfd_vma *local_got_offsets; |
| 2357 | asection *sgot; |
| 2358 | asection *srelgot; |
| 2359 | asection *sreloc; |
| 2360 | |
| 2361 | sreloc = NULL; |
| 2362 | |
| 2363 | if (bfd_link_relocatable (info)) |
| 2364 | return TRUE; |
| 2365 | |
| 2366 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 2367 | sym_hashes = elf_sym_hashes (abfd); |
| 2368 | |
| 2369 | dynobj = elf_hash_table (info)->dynobj; |
| 2370 | local_got_offsets = elf_local_got_offsets (abfd); |
| 2371 | |
| 2372 | rel_end = relocs + sec->reloc_count; |
| 2373 | for (rel = relocs; rel < rel_end; rel++) |
| 2374 | { |
| 2375 | struct elf_link_hash_entry *h; |
| 2376 | unsigned long r_symndx; |
| 2377 | |
| 2378 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 2379 | if (r_symndx < symtab_hdr->sh_info) |
| 2380 | h = NULL; |
| 2381 | else |
| 2382 | { |
| 2383 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 2384 | while (h->root.type == bfd_link_hash_indirect |
| 2385 | || h->root.type == bfd_link_hash_warning) |
| 2386 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 2387 | } |
| 2388 | |
| 2389 | /* Some relocs require a global offset table. */ |
| 2390 | if (dynobj == NULL) |
| 2391 | { |
| 2392 | switch (ELF64_R_TYPE (rel->r_info)) |
| 2393 | { |
| 2394 | case R_SH_GOTPLT_LOW16: |
| 2395 | case R_SH_GOTPLT_MEDLOW16: |
| 2396 | case R_SH_GOTPLT_MEDHI16: |
| 2397 | case R_SH_GOTPLT_HI16: |
| 2398 | case R_SH_GOTPLT10BY4: |
| 2399 | case R_SH_GOTPLT10BY8: |
| 2400 | case R_SH_GOT_LOW16: |
| 2401 | case R_SH_GOT_MEDLOW16: |
| 2402 | case R_SH_GOT_MEDHI16: |
| 2403 | case R_SH_GOT_HI16: |
| 2404 | case R_SH_GOT10BY4: |
| 2405 | case R_SH_GOT10BY8: |
| 2406 | case R_SH_GOTOFF_LOW16: |
| 2407 | case R_SH_GOTOFF_MEDLOW16: |
| 2408 | case R_SH_GOTOFF_MEDHI16: |
| 2409 | case R_SH_GOTOFF_HI16: |
| 2410 | case R_SH_GOTPC_LOW16: |
| 2411 | case R_SH_GOTPC_MEDLOW16: |
| 2412 | case R_SH_GOTPC_MEDHI16: |
| 2413 | case R_SH_GOTPC_HI16: |
| 2414 | elf_hash_table (info)->dynobj = dynobj = abfd; |
| 2415 | if (! _bfd_elf_create_got_section (dynobj, info)) |
| 2416 | return FALSE; |
| 2417 | break; |
| 2418 | |
| 2419 | default: |
| 2420 | break; |
| 2421 | } |
| 2422 | } |
| 2423 | |
| 2424 | switch (ELF64_R_TYPE (rel->r_info)) |
| 2425 | { |
| 2426 | /* This relocation describes the C++ object vtable hierarchy. |
| 2427 | Reconstruct it for later use during GC. */ |
| 2428 | case R_SH_GNU_VTINHERIT: |
| 2429 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
| 2430 | return FALSE; |
| 2431 | break; |
| 2432 | |
| 2433 | /* This relocation describes which C++ vtable entries are actually |
| 2434 | used. Record for later use during GC. */ |
| 2435 | case R_SH_GNU_VTENTRY: |
| 2436 | BFD_ASSERT (h != NULL); |
| 2437 | if (h != NULL |
| 2438 | && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
| 2439 | return FALSE; |
| 2440 | break; |
| 2441 | |
| 2442 | force_got: |
| 2443 | case R_SH_GOT_LOW16: |
| 2444 | case R_SH_GOT_MEDLOW16: |
| 2445 | case R_SH_GOT_MEDHI16: |
| 2446 | case R_SH_GOT_HI16: |
| 2447 | case R_SH_GOT10BY4: |
| 2448 | case R_SH_GOT10BY8: |
| 2449 | /* This symbol requires a global offset table entry. */ |
| 2450 | |
| 2451 | sgot = elf_hash_table (info)->sgot; |
| 2452 | srelgot = elf_hash_table (info)->srelgot; |
| 2453 | BFD_ASSERT (sgot != NULL && srelgot != NULL); |
| 2454 | |
| 2455 | if (h != NULL) |
| 2456 | { |
| 2457 | if (h->type == STT_DATALABEL) |
| 2458 | { |
| 2459 | struct elf_sh64_link_hash_entry *hsh; |
| 2460 | |
| 2461 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 2462 | hsh = (struct elf_sh64_link_hash_entry *)h; |
| 2463 | if (hsh->datalabel_got_offset != (bfd_vma) -1) |
| 2464 | break; |
| 2465 | |
| 2466 | hsh->datalabel_got_offset = sgot->size; |
| 2467 | } |
| 2468 | else |
| 2469 | { |
| 2470 | if (h->got.offset != (bfd_vma) -1) |
| 2471 | { |
| 2472 | /* We have already allocated space in the .got. */ |
| 2473 | break; |
| 2474 | } |
| 2475 | h->got.offset = sgot->size; |
| 2476 | } |
| 2477 | |
| 2478 | /* Make sure this symbol is output as a dynamic symbol. */ |
| 2479 | if (h->dynindx == -1) |
| 2480 | { |
| 2481 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 2482 | return FALSE; |
| 2483 | } |
| 2484 | |
| 2485 | srelgot->size += sizeof (Elf64_External_Rela); |
| 2486 | } |
| 2487 | else |
| 2488 | { |
| 2489 | /* This is a global offset table entry for a local |
| 2490 | symbol. */ |
| 2491 | if (local_got_offsets == NULL) |
| 2492 | { |
| 2493 | size_t size; |
| 2494 | register unsigned int i; |
| 2495 | |
| 2496 | size = symtab_hdr->sh_info * sizeof (bfd_vma); |
| 2497 | /* Reserve space for both the datalabel and |
| 2498 | codelabel local GOT offsets. */ |
| 2499 | size *= 2; |
| 2500 | local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size); |
| 2501 | if (local_got_offsets == NULL) |
| 2502 | return FALSE; |
| 2503 | elf_local_got_offsets (abfd) = local_got_offsets; |
| 2504 | for (i = 0; i < symtab_hdr->sh_info; i++) |
| 2505 | local_got_offsets[i] = (bfd_vma) -1; |
| 2506 | for (; i < 2 * symtab_hdr->sh_info; i++) |
| 2507 | local_got_offsets[i] = (bfd_vma) -1; |
| 2508 | } |
| 2509 | if ((rel->r_addend & 1) != 0) |
| 2510 | { |
| 2511 | if (local_got_offsets[symtab_hdr->sh_info |
| 2512 | + r_symndx] != (bfd_vma) -1) |
| 2513 | { |
| 2514 | /* We have already allocated space in the .got. */ |
| 2515 | break; |
| 2516 | } |
| 2517 | local_got_offsets[symtab_hdr->sh_info |
| 2518 | + r_symndx] = sgot->size; |
| 2519 | } |
| 2520 | else |
| 2521 | { |
| 2522 | if (local_got_offsets[r_symndx] != (bfd_vma) -1) |
| 2523 | { |
| 2524 | /* We have already allocated space in the .got. */ |
| 2525 | break; |
| 2526 | } |
| 2527 | local_got_offsets[r_symndx] = sgot->size; |
| 2528 | } |
| 2529 | |
| 2530 | if (bfd_link_pic (info)) |
| 2531 | { |
| 2532 | /* If we are generating a shared object, we need to |
| 2533 | output a R_SH_RELATIVE reloc so that the dynamic |
| 2534 | linker can adjust this GOT entry. */ |
| 2535 | srelgot->size += sizeof (Elf64_External_Rela); |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | sgot->size += 8; |
| 2540 | |
| 2541 | break; |
| 2542 | |
| 2543 | case R_SH_GOTPLT_LOW16: |
| 2544 | case R_SH_GOTPLT_MEDLOW16: |
| 2545 | case R_SH_GOTPLT_MEDHI16: |
| 2546 | case R_SH_GOTPLT_HI16: |
| 2547 | case R_SH_GOTPLT10BY4: |
| 2548 | case R_SH_GOTPLT10BY8: |
| 2549 | /* If this is a local symbol, we resolve it directly without |
| 2550 | creating a procedure linkage table entry. */ |
| 2551 | |
| 2552 | if (h == NULL |
| 2553 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL |
| 2554 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN |
| 2555 | || ! bfd_link_pic (info) |
| 2556 | || info->symbolic |
| 2557 | || h->dynindx == -1 |
| 2558 | || h->got.offset != (bfd_vma) -1) |
| 2559 | goto force_got; |
| 2560 | |
| 2561 | /* Make sure this symbol is output as a dynamic symbol. */ |
| 2562 | if (h->dynindx == -1) |
| 2563 | { |
| 2564 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 2565 | return FALSE; |
| 2566 | } |
| 2567 | |
| 2568 | h->needs_plt = 1; |
| 2569 | |
| 2570 | break; |
| 2571 | |
| 2572 | case R_SH_PLT_LOW16: |
| 2573 | case R_SH_PLT_MEDLOW16: |
| 2574 | case R_SH_PLT_MEDHI16: |
| 2575 | case R_SH_PLT_HI16: |
| 2576 | /* This symbol requires a procedure linkage table entry. We |
| 2577 | actually build the entry in adjust_dynamic_symbol, |
| 2578 | because this might be a case of linking PIC code which is |
| 2579 | never referenced by a dynamic object, in which case we |
| 2580 | don't need to generate a procedure linkage table entry |
| 2581 | after all. */ |
| 2582 | |
| 2583 | /* If this is a local symbol, we resolve it directly without |
| 2584 | creating a procedure linkage table entry. */ |
| 2585 | if (h == NULL) |
| 2586 | continue; |
| 2587 | |
| 2588 | if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL |
| 2589 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN) |
| 2590 | break; |
| 2591 | |
| 2592 | h->needs_plt = 1; |
| 2593 | |
| 2594 | break; |
| 2595 | |
| 2596 | case R_SH_64: |
| 2597 | case R_SH_64_PCREL: |
| 2598 | if (h != NULL) |
| 2599 | h->non_got_ref = 1; |
| 2600 | |
| 2601 | /* If we are creating a shared library, and this is a reloc |
| 2602 | against a global symbol, or a non PC relative reloc |
| 2603 | against a local symbol, then we need to copy the reloc |
| 2604 | into the shared library. However, if we are linking with |
| 2605 | -Bsymbolic, we do not need to copy a reloc against a |
| 2606 | global symbol which is defined in an object we are |
| 2607 | including in the link (i.e., DEF_REGULAR is set). At |
| 2608 | this point we have not seen all the input files, so it is |
| 2609 | possible that DEF_REGULAR is not set now but will be set |
| 2610 | later (it is never cleared). We account for that |
| 2611 | possibility below by storing information in the |
| 2612 | pcrel_relocs_copied field of the hash table entry. */ |
| 2613 | if (bfd_link_pic (info) |
| 2614 | && (sec->flags & SEC_ALLOC) != 0 |
| 2615 | && (ELF32_R_TYPE (rel->r_info) != R_SH_64_PCREL |
| 2616 | || (h != NULL |
| 2617 | && (! info->symbolic |
| 2618 | || !h->def_regular)))) |
| 2619 | { |
| 2620 | /* When creating a shared object, we must copy these |
| 2621 | reloc types into the output file. We create a reloc |
| 2622 | section in dynobj and make room for this reloc. */ |
| 2623 | if (sreloc == NULL) |
| 2624 | { |
| 2625 | sreloc = _bfd_elf_make_dynamic_reloc_section |
| 2626 | (sec, dynobj, 2, abfd, /*rela?*/ TRUE); |
| 2627 | |
| 2628 | if (sreloc == NULL) |
| 2629 | return FALSE; |
| 2630 | } |
| 2631 | |
| 2632 | sreloc->size += sizeof (Elf64_External_Rela); |
| 2633 | |
| 2634 | /* If we are linking with -Bsymbolic, and this is a |
| 2635 | global symbol, we count the number of PC relative |
| 2636 | relocations we have entered for this symbol, so that |
| 2637 | we can discard them again if the symbol is later |
| 2638 | defined by a regular object. Note that this function |
| 2639 | is only called if we are using an elf_sh linker |
| 2640 | hash table, which means that h is really a pointer to |
| 2641 | an elf_sh_link_hash_entry. */ |
| 2642 | if (h != NULL && info->symbolic |
| 2643 | && ELF64_R_TYPE (rel->r_info) == R_SH_64_PCREL) |
| 2644 | { |
| 2645 | struct elf_sh64_link_hash_entry *eh; |
| 2646 | struct elf_sh64_pcrel_relocs_copied *p; |
| 2647 | |
| 2648 | eh = (struct elf_sh64_link_hash_entry *) h; |
| 2649 | |
| 2650 | for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next) |
| 2651 | if (p->section == sreloc) |
| 2652 | break; |
| 2653 | |
| 2654 | if (p == NULL) |
| 2655 | { |
| 2656 | p = ((struct elf_sh64_pcrel_relocs_copied *) |
| 2657 | bfd_alloc (dynobj, sizeof *p)); |
| 2658 | if (p == NULL) |
| 2659 | return FALSE; |
| 2660 | p->next = eh->pcrel_relocs_copied; |
| 2661 | eh->pcrel_relocs_copied = p; |
| 2662 | p->section = sreloc; |
| 2663 | p->count = 0; |
| 2664 | } |
| 2665 | |
| 2666 | ++p->count; |
| 2667 | } |
| 2668 | } |
| 2669 | |
| 2670 | break; |
| 2671 | } |
| 2672 | } |
| 2673 | |
| 2674 | return TRUE; |
| 2675 | } |
| 2676 | |
| 2677 | static int |
| 2678 | sh64_elf64_get_symbol_type (Elf_Internal_Sym * elf_sym, int type) |
| 2679 | { |
| 2680 | if (ELF_ST_TYPE (elf_sym->st_info) == STT_DATALABEL) |
| 2681 | return STT_DATALABEL; |
| 2682 | |
| 2683 | return type; |
| 2684 | } |
| 2685 | |
| 2686 | /* FIXME: This is a copy of sh64_elf_add_symbol_hook in elf32-sh64.c. |
| 2687 | Either file can presumably exist without the other, but do not differ |
| 2688 | in elf-size-ness. How to share? |
| 2689 | |
| 2690 | Hook called by the linker routine which adds symbols from an object |
| 2691 | file. We must make indirect symbols for undefined symbols marked with |
| 2692 | STT_DATALABEL, so relocations passing them will pick up that attribute |
| 2693 | and neutralize STO_SH5_ISA32 found on the symbol definition. |
| 2694 | |
| 2695 | There is a problem, though: We want to fill in the hash-table entry for |
| 2696 | this symbol and signal to the caller that no further processing is |
| 2697 | needed. But we don't have the index for this hash-table entry. We |
| 2698 | rely here on that the current entry is the first hash-entry with NULL, |
| 2699 | which seems brittle. Also, iterating over the hash-table to find that |
| 2700 | entry is a linear operation on the number of symbols in this input |
| 2701 | file, and this function should take constant time, so that's not good |
| 2702 | too. Only comfort is that DataLabel references should only be found in |
| 2703 | hand-written assembly code and thus be rare. FIXME: Talk maintainers |
| 2704 | into adding an option to elf_add_symbol_hook (preferably) for the index |
| 2705 | or the hash entry, alternatively adding the index to Elf_Internal_Sym |
| 2706 | (not so good). */ |
| 2707 | |
| 2708 | static bfd_boolean |
| 2709 | sh64_elf64_add_symbol_hook (bfd *abfd, struct bfd_link_info *info, |
| 2710 | Elf_Internal_Sym *sym, const char **namep, |
| 2711 | flagword *flagsp ATTRIBUTE_UNUSED, |
| 2712 | asection **secp, bfd_vma *valp) |
| 2713 | { |
| 2714 | /* We want to do this for relocatable as well as final linking. */ |
| 2715 | if (ELF_ST_TYPE (sym->st_info) == STT_DATALABEL |
| 2716 | && is_elf_hash_table (info->hash)) |
| 2717 | { |
| 2718 | struct elf_link_hash_entry *h; |
| 2719 | |
| 2720 | /* For relocatable links, we register the DataLabel sym in its own |
| 2721 | right, and tweak the name when it's output. Otherwise, we make |
| 2722 | an indirect symbol of it. */ |
| 2723 | flagword flags |
| 2724 | = bfd_link_relocatable (info) || info->emitrelocations |
| 2725 | ? BSF_GLOBAL : BSF_GLOBAL | BSF_INDIRECT; |
| 2726 | |
| 2727 | char *dl_name |
| 2728 | = bfd_malloc (strlen (*namep) + sizeof (DATALABEL_SUFFIX)); |
| 2729 | struct elf_link_hash_entry ** sym_hash = elf_sym_hashes (abfd); |
| 2730 | |
| 2731 | BFD_ASSERT (sym_hash != NULL); |
| 2732 | |
| 2733 | /* Allocation may fail. */ |
| 2734 | if (dl_name == NULL) |
| 2735 | return FALSE; |
| 2736 | |
| 2737 | strcpy (dl_name, *namep); |
| 2738 | strcat (dl_name, DATALABEL_SUFFIX); |
| 2739 | |
| 2740 | h = (struct elf_link_hash_entry *) |
| 2741 | bfd_link_hash_lookup (info->hash, dl_name, FALSE, FALSE, FALSE); |
| 2742 | |
| 2743 | if (h == NULL) |
| 2744 | { |
| 2745 | /* No previous datalabel symbol. Make one. */ |
| 2746 | struct bfd_link_hash_entry *bh = NULL; |
| 2747 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); |
| 2748 | |
| 2749 | if (! _bfd_generic_link_add_one_symbol (info, abfd, dl_name, |
| 2750 | flags, *secp, *valp, |
| 2751 | *namep, FALSE, |
| 2752 | bed->collect, &bh)) |
| 2753 | { |
| 2754 | free (dl_name); |
| 2755 | return FALSE; |
| 2756 | } |
| 2757 | |
| 2758 | h = (struct elf_link_hash_entry *) bh; |
| 2759 | h->non_elf = 0; |
| 2760 | h->type = STT_DATALABEL; |
| 2761 | } |
| 2762 | else |
| 2763 | /* If a new symbol was created, it holds the allocated name. |
| 2764 | Otherwise, we don't need it anymore and should deallocate it. */ |
| 2765 | free (dl_name); |
| 2766 | |
| 2767 | if (h->type != STT_DATALABEL |
| 2768 | || ((bfd_link_relocatable (info) || info->emitrelocations) |
| 2769 | && h->root.type != bfd_link_hash_undefined) |
| 2770 | || (! bfd_link_relocatable (info) && !info->emitrelocations |
| 2771 | && h->root.type != bfd_link_hash_indirect)) |
| 2772 | { |
| 2773 | /* Make sure we don't get confused on invalid input. */ |
| 2774 | _bfd_error_handler |
| 2775 | (_("%pB: encountered datalabel symbol in input"), abfd); |
| 2776 | bfd_set_error (bfd_error_bad_value); |
| 2777 | return FALSE; |
| 2778 | } |
| 2779 | |
| 2780 | /* Now find the hash-table slot for this entry and fill it in. */ |
| 2781 | while (*sym_hash != NULL) |
| 2782 | sym_hash++; |
| 2783 | *sym_hash = h; |
| 2784 | |
| 2785 | /* Signal to caller to skip this symbol - we've handled it. */ |
| 2786 | *namep = NULL; |
| 2787 | } |
| 2788 | |
| 2789 | return TRUE; |
| 2790 | } |
| 2791 | |
| 2792 | /* This hook function is called before the linker writes out a global |
| 2793 | symbol. For relocatable links, DataLabel symbols will be present in |
| 2794 | linker output. We cut off the special suffix on those symbols, so the |
| 2795 | right name appears in the output. |
| 2796 | |
| 2797 | When linking and emitting relocations, there can appear global symbols |
| 2798 | that are not referenced by relocs, but rather only implicitly through |
| 2799 | DataLabel references, a relation that is not visible to the linker. |
| 2800 | Since no stripping of global symbols in done when doing such linking, |
| 2801 | we don't need to look up and make sure to emit the main symbol for each |
| 2802 | DataLabel symbol. */ |
| 2803 | |
| 2804 | static int |
| 2805 | sh64_elf64_link_output_symbol_hook (struct bfd_link_info *info, |
| 2806 | const char *cname, |
| 2807 | Elf_Internal_Sym *sym, |
| 2808 | asection *input_sec ATTRIBUTE_UNUSED, |
| 2809 | struct elf_link_hash_entry *h ATTRIBUTE_UNUSED) |
| 2810 | { |
| 2811 | char *name = (char *) cname; |
| 2812 | |
| 2813 | if (bfd_link_relocatable (info) || info->emitrelocations) |
| 2814 | { |
| 2815 | if (ELF_ST_TYPE (sym->st_info) == STT_DATALABEL) |
| 2816 | name[strlen (name) - strlen (DATALABEL_SUFFIX)] = 0; |
| 2817 | } |
| 2818 | |
| 2819 | return 1; |
| 2820 | } |
| 2821 | |
| 2822 | /* Set bit 0 on the entry address; it always points to SHmedia code. This |
| 2823 | is mostly for symmetry with the 32-bit format, where code can be |
| 2824 | SHcompact and we need to make a distinction to make sure execution |
| 2825 | starts in the right ISA mode. It is also convenient for a loader, |
| 2826 | which would otherwise have to set this bit when loading a TR register |
| 2827 | before jumping to the program entry. */ |
| 2828 | |
| 2829 | static void |
| 2830 | sh64_elf64_final_write_processing (bfd *abfd, |
| 2831 | bfd_boolean linker ATTRIBUTE_UNUSED) |
| 2832 | { |
| 2833 | /* FIXME: Perhaps we shouldn't do this if the entry address was supplied |
| 2834 | numerically, but we currently lack the infrastructure to recognize |
| 2835 | that: The entry symbol, and info whether it is numeric or a symbol |
| 2836 | name is kept private in the linker. */ |
| 2837 | if (elf_elfheader (abfd)->e_type == ET_EXEC) |
| 2838 | elf_elfheader (abfd)->e_entry |= 1; |
| 2839 | } |
| 2840 | |
| 2841 | /* First entry in an absolute procedure linkage table look like this. */ |
| 2842 | |
| 2843 | static const bfd_byte elf_sh64_plt0_entry_be[PLT_ENTRY_SIZE] = |
| 2844 | { |
| 2845 | 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 48, r17 */ |
| 2846 | 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 32) & 65535, r17 */ |
| 2847 | 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 16) & 65535, r17 */ |
| 2848 | 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */ |
| 2849 | 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */ |
| 2850 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ |
| 2851 | 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */ |
| 2852 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ |
| 2853 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2854 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2855 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2856 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2857 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2858 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2859 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2860 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2861 | }; |
| 2862 | |
| 2863 | static const bfd_byte elf_sh64_plt0_entry_le[PLT_ENTRY_SIZE] = |
| 2864 | { |
| 2865 | 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */ |
| 2866 | 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 32) & 65535, r17 */ |
| 2867 | 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 16) & 65535, r17 */ |
| 2868 | 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */ |
| 2869 | 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */ |
| 2870 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ |
| 2871 | 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */ |
| 2872 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ |
| 2873 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2874 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2875 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2876 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2877 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2878 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2879 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2880 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2881 | }; |
| 2882 | |
| 2883 | /* Sebsequent entries in an absolute procedure linkage table look like |
| 2884 | this. */ |
| 2885 | |
| 2886 | static const bfd_byte elf_sh64_plt_entry_be[PLT_ENTRY_SIZE] = |
| 2887 | { |
| 2888 | 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 48, r25 */ |
| 2889 | 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 32) & 65535, r25 */ |
| 2890 | 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 16) & 65535, r25 */ |
| 2891 | 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */ |
| 2892 | 0x8d, 0x90, 0x01, 0x90, /* ld.q r25, 0, r25 */ |
| 2893 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ |
| 2894 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ |
| 2895 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2896 | 0xcc, 0x00, 0x01, 0x90, /* movi (.+8-.PLT0) >> 16, r25 */ |
| 2897 | 0xc8, 0x00, 0x01, 0x90, /* shori (.+4-.PLT0) & 65535, r25 */ |
| 2898 | 0x6b, 0xf5, 0x66, 0x00, /* ptrel r25, tr0 */ |
| 2899 | 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */ |
| 2900 | 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */ |
| 2901 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ |
| 2902 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2903 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2904 | }; |
| 2905 | |
| 2906 | static const bfd_byte elf_sh64_plt_entry_le[PLT_ENTRY_SIZE] = |
| 2907 | { |
| 2908 | 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */ |
| 2909 | 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */ |
| 2910 | 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */ |
| 2911 | 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */ |
| 2912 | 0x90, 0x01, 0x90, 0x8d, /* ld.q r25, 0, r25 */ |
| 2913 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ |
| 2914 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ |
| 2915 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2916 | 0x90, 0x01, 0x00, 0xcc, /* movi (.+8-.PLT0) >> 16, r25 */ |
| 2917 | 0x90, 0x01, 0x00, 0xc8, /* shori (.+4-.PLT0) & 65535, r25 */ |
| 2918 | 0x00, 0x66, 0xf5, 0x6b, /* ptrel r25, tr0 */ |
| 2919 | 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */ |
| 2920 | 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */ |
| 2921 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ |
| 2922 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2923 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2924 | }; |
| 2925 | |
| 2926 | /* Entries in a PIC procedure linkage table look like this. */ |
| 2927 | |
| 2928 | static const bfd_byte elf_sh64_pic_plt_entry_be[PLT_ENTRY_SIZE] = |
| 2929 | { |
| 2930 | 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */ |
| 2931 | 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */ |
| 2932 | 0x40, 0xc3, 0x65, 0x90, /* ldx.q r12, r25, r25 */ |
| 2933 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ |
| 2934 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ |
| 2935 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2936 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2937 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ |
| 2938 | 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */ |
| 2939 | 0x00, 0xc9, 0x45, 0x10, /* add r12, r17, r17 */ |
| 2940 | 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */ |
| 2941 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ |
| 2942 | 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */ |
| 2943 | 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */ |
| 2944 | 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */ |
| 2945 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ |
| 2946 | }; |
| 2947 | |
| 2948 | static const bfd_byte elf_sh64_pic_plt_entry_le[PLT_ENTRY_SIZE] = |
| 2949 | { |
| 2950 | 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */ |
| 2951 | 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */ |
| 2952 | 0x90, 0x65, 0xc3, 0x40, /* ldx.q r12, r25, r25 */ |
| 2953 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ |
| 2954 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ |
| 2955 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2956 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2957 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ |
| 2958 | 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */ |
| 2959 | 0x10, 0x45, 0xc9, 0x00, /* add r12, r17, r17 */ |
| 2960 | 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */ |
| 2961 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ |
| 2962 | 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */ |
| 2963 | 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */ |
| 2964 | 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */ |
| 2965 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ |
| 2966 | }; |
| 2967 | |
| 2968 | static const bfd_byte *elf_sh64_plt0_entry; |
| 2969 | static const bfd_byte *elf_sh64_plt_entry; |
| 2970 | static const bfd_byte *elf_sh64_pic_plt_entry; |
| 2971 | |
| 2972 | /* Create an entry in an sh ELF linker hash table. */ |
| 2973 | |
| 2974 | static struct bfd_hash_entry * |
| 2975 | sh64_elf64_link_hash_newfunc (struct bfd_hash_entry *entry, |
| 2976 | struct bfd_hash_table *table, |
| 2977 | const char *string) |
| 2978 | { |
| 2979 | struct elf_sh64_link_hash_entry *ret = |
| 2980 | (struct elf_sh64_link_hash_entry *) entry; |
| 2981 | |
| 2982 | /* Allocate the structure if it has not already been allocated by a |
| 2983 | subclass. */ |
| 2984 | if (ret == (struct elf_sh64_link_hash_entry *) NULL) |
| 2985 | ret = ((struct elf_sh64_link_hash_entry *) |
| 2986 | bfd_hash_allocate (table, |
| 2987 | sizeof (struct elf_sh64_link_hash_entry))); |
| 2988 | if (ret == (struct elf_sh64_link_hash_entry *) NULL) |
| 2989 | return (struct bfd_hash_entry *) ret; |
| 2990 | |
| 2991 | /* Call the allocation method of the superclass. */ |
| 2992 | ret = ((struct elf_sh64_link_hash_entry *) |
| 2993 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
| 2994 | table, string)); |
| 2995 | if (ret != (struct elf_sh64_link_hash_entry *) NULL) |
| 2996 | { |
| 2997 | ret->pcrel_relocs_copied = NULL; |
| 2998 | ret->datalabel_got_offset = (bfd_vma) -1; |
| 2999 | } |
| 3000 | |
| 3001 | return (struct bfd_hash_entry *) ret; |
| 3002 | } |
| 3003 | |
| 3004 | /* Create an sh64 ELF linker hash table. */ |
| 3005 | |
| 3006 | static struct bfd_link_hash_table * |
| 3007 | sh64_elf64_link_hash_table_create (bfd *abfd) |
| 3008 | { |
| 3009 | struct elf_link_hash_table *ret; |
| 3010 | |
| 3011 | ret = (struct elf_link_hash_table *) bfd_zmalloc (sizeof (* ret)); |
| 3012 | if (ret == (struct elf_link_hash_table *) NULL) |
| 3013 | return NULL; |
| 3014 | |
| 3015 | if (!_bfd_elf_link_hash_table_init (ret, abfd, |
| 3016 | sh64_elf64_link_hash_newfunc, |
| 3017 | sizeof (struct elf_sh64_link_hash_entry), |
| 3018 | GENERIC_ELF_DATA)) |
| 3019 | { |
| 3020 | free (ret); |
| 3021 | return NULL; |
| 3022 | } |
| 3023 | |
| 3024 | return &ret->root; |
| 3025 | } |
| 3026 | |
| 3027 | inline static void |
| 3028 | movi_shori_putval (bfd *output_bfd, unsigned long value, bfd_byte *addr) |
| 3029 | { |
| 3030 | bfd_put_32 (output_bfd, |
| 3031 | bfd_get_32 (output_bfd, addr) |
| 3032 | | ((value >> 6) & 0x3fffc00), |
| 3033 | addr); |
| 3034 | bfd_put_32 (output_bfd, |
| 3035 | bfd_get_32 (output_bfd, addr + 4) |
| 3036 | | ((value << 10) & 0x3fffc00), |
| 3037 | addr + 4); |
| 3038 | } |
| 3039 | |
| 3040 | inline static void |
| 3041 | movi_3shori_putval (bfd *output_bfd, bfd_vma value, bfd_byte *addr) |
| 3042 | { |
| 3043 | bfd_put_32 (output_bfd, |
| 3044 | bfd_get_32 (output_bfd, addr) |
| 3045 | | ((value >> 38) & 0x3fffc00), |
| 3046 | addr); |
| 3047 | bfd_put_32 (output_bfd, |
| 3048 | bfd_get_32 (output_bfd, addr + 4) |
| 3049 | | ((value >> 22) & 0x3fffc00), |
| 3050 | addr + 4); |
| 3051 | bfd_put_32 (output_bfd, |
| 3052 | bfd_get_32 (output_bfd, addr + 8) |
| 3053 | | ((value >> 6) & 0x3fffc00), |
| 3054 | addr + 8); |
| 3055 | bfd_put_32 (output_bfd, |
| 3056 | bfd_get_32 (output_bfd, addr + 12) |
| 3057 | | ((value << 10) & 0x3fffc00), |
| 3058 | addr + 12); |
| 3059 | } |
| 3060 | |
| 3061 | /* Create dynamic sections when linking against a dynamic object. */ |
| 3062 | |
| 3063 | static bfd_boolean |
| 3064 | sh64_elf64_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) |
| 3065 | { |
| 3066 | flagword flags, pltflags; |
| 3067 | register asection *s; |
| 3068 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); |
| 3069 | int ptralign = 0; |
| 3070 | |
| 3071 | switch (bed->s->arch_size) |
| 3072 | { |
| 3073 | case 32: |
| 3074 | ptralign = 2; |
| 3075 | break; |
| 3076 | |
| 3077 | case 64: |
| 3078 | ptralign = 3; |
| 3079 | break; |
| 3080 | |
| 3081 | default: |
| 3082 | bfd_set_error (bfd_error_bad_value); |
| 3083 | return FALSE; |
| 3084 | } |
| 3085 | |
| 3086 | /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and |
| 3087 | .rel[a].bss sections. */ |
| 3088 | |
| 3089 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
| 3090 | | SEC_LINKER_CREATED); |
| 3091 | |
| 3092 | pltflags = flags; |
| 3093 | pltflags |= SEC_CODE; |
| 3094 | if (bed->plt_not_loaded) |
| 3095 | pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS); |
| 3096 | if (bed->plt_readonly) |
| 3097 | pltflags |= SEC_READONLY; |
| 3098 | |
| 3099 | s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags); |
| 3100 | if (s == NULL |
| 3101 | || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) |
| 3102 | return FALSE; |
| 3103 | |
| 3104 | if (bed->want_plt_sym) |
| 3105 | { |
| 3106 | /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the |
| 3107 | .plt section. */ |
| 3108 | struct elf_link_hash_entry *h; |
| 3109 | struct bfd_link_hash_entry *bh = NULL; |
| 3110 | |
| 3111 | if (! (_bfd_generic_link_add_one_symbol |
| 3112 | (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, |
| 3113 | (bfd_vma) 0, (const char *) NULL, FALSE, bed->collect, &bh))) |
| 3114 | return FALSE; |
| 3115 | |
| 3116 | h = (struct elf_link_hash_entry *) bh; |
| 3117 | h->def_regular = 1; |
| 3118 | h->type = STT_OBJECT; |
| 3119 | elf_hash_table (info)->hplt = h; |
| 3120 | |
| 3121 | if (bfd_link_pic (info) |
| 3122 | && ! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 3123 | return FALSE; |
| 3124 | } |
| 3125 | |
| 3126 | s = bfd_make_section_anyway_with_flags (abfd, |
| 3127 | bed->default_use_rela_p |
| 3128 | ? ".rela.plt" : ".rel.plt", |
| 3129 | flags | SEC_READONLY); |
| 3130 | if (s == NULL |
| 3131 | || ! bfd_set_section_alignment (abfd, s, ptralign)) |
| 3132 | return FALSE; |
| 3133 | |
| 3134 | if (! _bfd_elf_create_got_section (abfd, info)) |
| 3135 | return FALSE; |
| 3136 | |
| 3137 | if (bed->want_dynbss) |
| 3138 | { |
| 3139 | /* The .dynbss section is a place to put symbols which are defined |
| 3140 | by dynamic objects, are referenced by regular objects, and are |
| 3141 | not functions. We must allocate space for them in the process |
| 3142 | image and use a R_*_COPY reloc to tell the dynamic linker to |
| 3143 | initialize them at run time. The linker script puts the .dynbss |
| 3144 | section into the .bss section of the final image. */ |
| 3145 | s = bfd_make_section_anyway_with_flags (abfd, ".dynbss", |
| 3146 | SEC_ALLOC | SEC_LINKER_CREATED); |
| 3147 | if (s == NULL) |
| 3148 | return FALSE; |
| 3149 | |
| 3150 | /* The .rel[a].bss section holds copy relocs. This section is not |
| 3151 | normally needed. We need to create it here, though, so that the |
| 3152 | linker will map it to an output section. We can't just create it |
| 3153 | only if we need it, because we will not know whether we need it |
| 3154 | until we have seen all the input files, and the first time the |
| 3155 | main linker code calls BFD after examining all the input files |
| 3156 | (size_dynamic_sections) the input sections have already been |
| 3157 | mapped to the output sections. If the section turns out not to |
| 3158 | be needed, we can discard it later. We will never need this |
| 3159 | section when generating a shared object, since they do not use |
| 3160 | copy relocs. */ |
| 3161 | if (! bfd_link_pic (info)) |
| 3162 | { |
| 3163 | s = bfd_make_section_anyway_with_flags (abfd, |
| 3164 | (bed->default_use_rela_p |
| 3165 | ? ".rela.bss" : ".rel.bss"), |
| 3166 | flags | SEC_READONLY); |
| 3167 | if (s == NULL |
| 3168 | || ! bfd_set_section_alignment (abfd, s, ptralign)) |
| 3169 | return FALSE; |
| 3170 | } |
| 3171 | } |
| 3172 | |
| 3173 | return TRUE; |
| 3174 | } |
| 3175 | \f |
| 3176 | /* Adjust a symbol defined by a dynamic object and referenced by a |
| 3177 | regular object. The current definition is in some section of the |
| 3178 | dynamic object, but we're not including those sections. We have to |
| 3179 | change the definition to something the rest of the link can |
| 3180 | understand. */ |
| 3181 | |
| 3182 | static bfd_boolean |
| 3183 | sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info, |
| 3184 | struct elf_link_hash_entry *h) |
| 3185 | { |
| 3186 | bfd *dynobj; |
| 3187 | asection *s; |
| 3188 | |
| 3189 | dynobj = elf_hash_table (info)->dynobj; |
| 3190 | |
| 3191 | /* Make sure we know what is going on here. */ |
| 3192 | BFD_ASSERT (dynobj != NULL |
| 3193 | && (h->needs_plt |
| 3194 | || h->is_weakalias |
| 3195 | || (h->def_dynamic |
| 3196 | && h->ref_regular |
| 3197 | && !h->def_regular))); |
| 3198 | |
| 3199 | /* If this is a function, put it in the procedure linkage table. We |
| 3200 | will fill in the contents of the procedure linkage table later, |
| 3201 | when we know the address of the .got section. */ |
| 3202 | if (h->type == STT_FUNC |
| 3203 | || h->needs_plt) |
| 3204 | { |
| 3205 | if (! bfd_link_pic (info) |
| 3206 | && !h->def_dynamic |
| 3207 | && !h->ref_dynamic) |
| 3208 | { |
| 3209 | /* This case can occur if we saw a PLT reloc in an input |
| 3210 | file, but the symbol was never referred to by a dynamic |
| 3211 | object. In such a case, we don't actually need to build |
| 3212 | a procedure linkage table, and we can just do a REL64 |
| 3213 | reloc instead. */ |
| 3214 | BFD_ASSERT (h->needs_plt); |
| 3215 | return TRUE; |
| 3216 | } |
| 3217 | |
| 3218 | /* Make sure this symbol is output as a dynamic symbol. */ |
| 3219 | if (h->dynindx == -1) |
| 3220 | { |
| 3221 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 3222 | return FALSE; |
| 3223 | } |
| 3224 | |
| 3225 | s = elf_hash_table (info)->splt; |
| 3226 | BFD_ASSERT (s != NULL); |
| 3227 | |
| 3228 | /* If this is the first .plt entry, make room for the special |
| 3229 | first entry. */ |
| 3230 | if (s->size == 0) |
| 3231 | s->size += PLT_ENTRY_SIZE; |
| 3232 | |
| 3233 | /* If this symbol is not defined in a regular file, and we are |
| 3234 | not generating a shared library, then set the symbol to this |
| 3235 | location in the .plt. This is required to make function |
| 3236 | pointers compare as equal between the normal executable and |
| 3237 | the shared library. */ |
| 3238 | if (! bfd_link_pic (info) |
| 3239 | && !h->def_regular) |
| 3240 | { |
| 3241 | h->root.u.def.section = s; |
| 3242 | h->root.u.def.value = s->size; |
| 3243 | } |
| 3244 | |
| 3245 | h->plt.offset = s->size; |
| 3246 | |
| 3247 | /* Make room for this entry. */ |
| 3248 | s->size += elf_sh64_sizeof_plt (info); |
| 3249 | |
| 3250 | /* We also need to make an entry in the .got.plt section, which |
| 3251 | will be placed in the .got section by the linker script. */ |
| 3252 | |
| 3253 | s = elf_hash_table (info)->sgotplt; |
| 3254 | BFD_ASSERT (s != NULL); |
| 3255 | s->size += 8; |
| 3256 | |
| 3257 | /* We also need to make an entry in the .rela.plt section. */ |
| 3258 | |
| 3259 | s = elf_hash_table (info)->srelplt; |
| 3260 | BFD_ASSERT (s != NULL); |
| 3261 | s->size += sizeof (Elf64_External_Rela); |
| 3262 | |
| 3263 | return TRUE; |
| 3264 | } |
| 3265 | |
| 3266 | /* If this is a weak symbol, and there is a real definition, the |
| 3267 | processor independent code will have arranged for us to see the |
| 3268 | real definition first, and we can just use the same value. */ |
| 3269 | if (h->is_weakalias) |
| 3270 | { |
| 3271 | struct elf_link_hash_entry *def = weakdef (h); |
| 3272 | BFD_ASSERT (def->root.type == bfd_link_hash_defined); |
| 3273 | h->root.u.def.section = def->root.u.def.section; |
| 3274 | h->root.u.def.value = def->root.u.def.value; |
| 3275 | return TRUE; |
| 3276 | } |
| 3277 | |
| 3278 | /* This is a reference to a symbol defined by a dynamic object which |
| 3279 | is not a function. */ |
| 3280 | |
| 3281 | /* If we are creating a shared library, we must presume that the |
| 3282 | only references to the symbol are via the global offset table. |
| 3283 | For such cases we need not do anything here; the relocations will |
| 3284 | be handled correctly by relocate_section. */ |
| 3285 | if (bfd_link_pic (info)) |
| 3286 | return TRUE; |
| 3287 | |
| 3288 | /* If there are no references to this symbol that do not use the |
| 3289 | GOT, we don't need to generate a copy reloc. */ |
| 3290 | if (!h->non_got_ref) |
| 3291 | return TRUE; |
| 3292 | |
| 3293 | /* We must allocate the symbol in our .dynbss section, which will |
| 3294 | become part of the .bss section of the executable. There will be |
| 3295 | an entry for this symbol in the .dynsym section. The dynamic |
| 3296 | object will contain position independent code, so all references |
| 3297 | from the dynamic object to this symbol will go through the global |
| 3298 | offset table. The dynamic linker will use the .dynsym entry to |
| 3299 | determine the address it must put in the global offset table, so |
| 3300 | both the dynamic object and the regular object will refer to the |
| 3301 | same memory location for the variable. */ |
| 3302 | |
| 3303 | s = bfd_get_linker_section (dynobj, ".dynbss"); |
| 3304 | BFD_ASSERT (s != NULL); |
| 3305 | |
| 3306 | /* We must generate a R_SH_COPY reloc to tell the dynamic linker to |
| 3307 | copy the initial value out of the dynamic object and into the |
| 3308 | runtime process image. We need to remember the offset into the |
| 3309 | .rela.bss section we are going to use. */ |
| 3310 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) |
| 3311 | { |
| 3312 | asection *srel; |
| 3313 | |
| 3314 | srel = bfd_get_linker_section (dynobj, ".rela.bss"); |
| 3315 | BFD_ASSERT (srel != NULL); |
| 3316 | srel->size += sizeof (Elf64_External_Rela); |
| 3317 | h->needs_copy = 1; |
| 3318 | } |
| 3319 | |
| 3320 | return _bfd_elf_adjust_dynamic_copy (info, h, s); |
| 3321 | } |
| 3322 | |
| 3323 | /* This function is called via sh_elf_link_hash_traverse if we are |
| 3324 | creating a shared object with -Bsymbolic. It discards the space |
| 3325 | allocated to copy PC relative relocs against symbols which are |
| 3326 | defined in regular objects. We allocated space for them in the |
| 3327 | check_relocs routine, but we won't fill them in in the |
| 3328 | relocate_section routine. */ |
| 3329 | |
| 3330 | static bfd_boolean |
| 3331 | sh64_elf64_discard_copies (struct elf_sh64_link_hash_entry *h, |
| 3332 | void *ignore ATTRIBUTE_UNUSED) |
| 3333 | { |
| 3334 | struct elf_sh64_pcrel_relocs_copied *s; |
| 3335 | |
| 3336 | /* We only discard relocs for symbols defined in a regular object. */ |
| 3337 | if (!h->root.def_regular) |
| 3338 | return TRUE; |
| 3339 | |
| 3340 | for (s = h->pcrel_relocs_copied; s != NULL; s = s->next) |
| 3341 | s->section->size -= s->count * sizeof (Elf64_External_Rela); |
| 3342 | |
| 3343 | return TRUE; |
| 3344 | } |
| 3345 | |
| 3346 | /* Set the sizes of the dynamic sections. */ |
| 3347 | |
| 3348 | static bfd_boolean |
| 3349 | sh64_elf64_size_dynamic_sections (bfd *output_bfd, |
| 3350 | struct bfd_link_info *info) |
| 3351 | { |
| 3352 | bfd *dynobj; |
| 3353 | asection *s; |
| 3354 | bfd_boolean plt; |
| 3355 | bfd_boolean relocs; |
| 3356 | bfd_boolean reltext; |
| 3357 | |
| 3358 | dynobj = elf_hash_table (info)->dynobj; |
| 3359 | BFD_ASSERT (dynobj != NULL); |
| 3360 | |
| 3361 | if (elf_hash_table (info)->dynamic_sections_created) |
| 3362 | { |
| 3363 | /* Set the contents of the .interp section to the interpreter. */ |
| 3364 | if (bfd_link_executable (info) && !info->nointerp) |
| 3365 | { |
| 3366 | s = bfd_get_linker_section (dynobj, ".interp"); |
| 3367 | BFD_ASSERT (s != NULL); |
| 3368 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
| 3369 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
| 3370 | } |
| 3371 | } |
| 3372 | else |
| 3373 | { |
| 3374 | /* We may have created entries in the .rela.got section. |
| 3375 | However, if we are not creating the dynamic sections, we will |
| 3376 | not actually use these entries. Reset the size of .rela.got, |
| 3377 | which will cause it to get stripped from the output file |
| 3378 | below. */ |
| 3379 | s = elf_hash_table (info)->srelgot; |
| 3380 | if (s != NULL) |
| 3381 | s->size = 0; |
| 3382 | } |
| 3383 | |
| 3384 | /* If this is a -Bsymbolic shared link, then we need to discard all |
| 3385 | PC relative relocs against symbols defined in a regular object. |
| 3386 | We allocated space for them in the check_relocs routine, but we |
| 3387 | will not fill them in in the relocate_section routine. */ |
| 3388 | if (bfd_link_pic (info) && info->symbolic) |
| 3389 | sh64_elf64_link_hash_traverse (elf_hash_table (info), |
| 3390 | sh64_elf64_discard_copies, NULL); |
| 3391 | |
| 3392 | /* The check_relocs and adjust_dynamic_symbol entry points have |
| 3393 | determined the sizes of the various dynamic sections. Allocate |
| 3394 | memory for them. */ |
| 3395 | plt = FALSE; |
| 3396 | relocs = FALSE; |
| 3397 | reltext = FALSE; |
| 3398 | for (s = dynobj->sections; s != NULL; s = s->next) |
| 3399 | { |
| 3400 | const char *name; |
| 3401 | |
| 3402 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
| 3403 | continue; |
| 3404 | |
| 3405 | /* It's OK to base decisions on the section name, because none |
| 3406 | of the dynobj section names depend upon the input files. */ |
| 3407 | name = bfd_get_section_name (dynobj, s); |
| 3408 | |
| 3409 | if (strcmp (name, ".plt") == 0) |
| 3410 | { |
| 3411 | /* Remember whether there is a PLT. */ |
| 3412 | plt = s->size != 0; |
| 3413 | } |
| 3414 | else if (CONST_STRNEQ (name, ".rela")) |
| 3415 | { |
| 3416 | if (s->size != 0) |
| 3417 | { |
| 3418 | asection *target; |
| 3419 | |
| 3420 | /* Remember whether there are any reloc sections other |
| 3421 | than .rela.plt. */ |
| 3422 | if (strcmp (name, ".rela.plt") != 0) |
| 3423 | { |
| 3424 | const char *outname; |
| 3425 | |
| 3426 | relocs = TRUE; |
| 3427 | |
| 3428 | /* If this relocation section applies to a read only |
| 3429 | section, then we probably need a DT_TEXTREL |
| 3430 | entry. The entries in the .rela.plt section |
| 3431 | really apply to the .got section, which we |
| 3432 | created ourselves and so know is not readonly. */ |
| 3433 | outname = bfd_get_section_name (output_bfd, |
| 3434 | s->output_section); |
| 3435 | target = bfd_get_section_by_name (output_bfd, outname + 5); |
| 3436 | if (target != NULL |
| 3437 | && (target->flags & SEC_READONLY) != 0 |
| 3438 | && (target->flags & SEC_ALLOC) != 0) |
| 3439 | reltext = TRUE; |
| 3440 | } |
| 3441 | |
| 3442 | /* We use the reloc_count field as a counter if we need |
| 3443 | to copy relocs into the output file. */ |
| 3444 | s->reloc_count = 0; |
| 3445 | } |
| 3446 | } |
| 3447 | else if (! CONST_STRNEQ (name, ".got") |
| 3448 | && strcmp (name, ".dynbss") != 0) |
| 3449 | { |
| 3450 | /* It's not one of our sections, so don't allocate space. */ |
| 3451 | continue; |
| 3452 | } |
| 3453 | |
| 3454 | if (s->size == 0) |
| 3455 | { |
| 3456 | /* If we don't need this section, strip it from the |
| 3457 | output file. This is mostly to handle .rela.bss and |
| 3458 | .rela.plt. We must create both sections in |
| 3459 | create_dynamic_sections, because they must be created |
| 3460 | before the linker maps input sections to output |
| 3461 | sections. The linker does that before |
| 3462 | adjust_dynamic_symbol is called, and it is that |
| 3463 | function which decides whether anything needs to go |
| 3464 | into these sections. */ |
| 3465 | s->flags |= SEC_EXCLUDE; |
| 3466 | continue; |
| 3467 | } |
| 3468 | |
| 3469 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
| 3470 | continue; |
| 3471 | |
| 3472 | /* Allocate memory for the section contents. */ |
| 3473 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
| 3474 | if (s->contents == NULL) |
| 3475 | return FALSE; |
| 3476 | } |
| 3477 | |
| 3478 | if (elf_hash_table (info)->dynamic_sections_created) |
| 3479 | { |
| 3480 | /* Add some entries to the .dynamic section. We fill in the |
| 3481 | values later, in sh64_elf64_finish_dynamic_sections, but we |
| 3482 | must add the entries now so that we get the correct size for |
| 3483 | the .dynamic section. The DT_DEBUG entry is filled in by the |
| 3484 | dynamic linker and used by the debugger. */ |
| 3485 | if (bfd_link_executable (info)) |
| 3486 | { |
| 3487 | if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0)) |
| 3488 | return FALSE; |
| 3489 | } |
| 3490 | |
| 3491 | if (plt) |
| 3492 | { |
| 3493 | if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0) |
| 3494 | || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0) |
| 3495 | || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA) |
| 3496 | || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0)) |
| 3497 | return FALSE; |
| 3498 | } |
| 3499 | |
| 3500 | if (relocs) |
| 3501 | { |
| 3502 | if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0) |
| 3503 | || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0) |
| 3504 | || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT, |
| 3505 | sizeof (Elf64_External_Rela))) |
| 3506 | return FALSE; |
| 3507 | } |
| 3508 | |
| 3509 | if (reltext) |
| 3510 | { |
| 3511 | if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0)) |
| 3512 | return FALSE; |
| 3513 | } |
| 3514 | } |
| 3515 | |
| 3516 | return TRUE; |
| 3517 | } |
| 3518 | |
| 3519 | /* Finish up dynamic symbol handling. We set the contents of various |
| 3520 | dynamic sections here. */ |
| 3521 | |
| 3522 | static bfd_boolean |
| 3523 | sh64_elf64_finish_dynamic_symbol (bfd *output_bfd, |
| 3524 | struct bfd_link_info *info, |
| 3525 | struct elf_link_hash_entry *h, |
| 3526 | Elf_Internal_Sym *sym) |
| 3527 | { |
| 3528 | bfd *dynobj; |
| 3529 | |
| 3530 | dynobj = elf_hash_table (info)->dynobj; |
| 3531 | |
| 3532 | if (h->plt.offset != (bfd_vma) -1) |
| 3533 | { |
| 3534 | asection *splt; |
| 3535 | asection *sgot; |
| 3536 | asection *srel; |
| 3537 | |
| 3538 | bfd_vma plt_index; |
| 3539 | bfd_vma got_offset; |
| 3540 | Elf_Internal_Rela rel; |
| 3541 | bfd_byte *loc; |
| 3542 | |
| 3543 | /* This symbol has an entry in the procedure linkage table. Set |
| 3544 | it up. */ |
| 3545 | |
| 3546 | BFD_ASSERT (h->dynindx != -1); |
| 3547 | |
| 3548 | splt = elf_hash_table (info)->splt; |
| 3549 | sgot = elf_hash_table (info)->sgotplt; |
| 3550 | srel = elf_hash_table (info)->srelplt; |
| 3551 | BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL); |
| 3552 | |
| 3553 | /* Get the index in the procedure linkage table which |
| 3554 | corresponds to this symbol. This is the index of this symbol |
| 3555 | in all the symbols for which we are making plt entries. The |
| 3556 | first entry in the procedure linkage table is reserved. */ |
| 3557 | plt_index = h->plt.offset / elf_sh64_sizeof_plt (info) - 1; |
| 3558 | |
| 3559 | /* Get the offset into the .got table of the entry that |
| 3560 | corresponds to this function. Each .got entry is 8 bytes. |
| 3561 | The first three are reserved. */ |
| 3562 | got_offset = (plt_index + 3) * 8; |
| 3563 | |
| 3564 | if (bfd_link_pic (info)) |
| 3565 | got_offset -= GOT_BIAS; |
| 3566 | |
| 3567 | /* Fill in the entry in the procedure linkage table. */ |
| 3568 | if (! bfd_link_pic (info)) |
| 3569 | { |
| 3570 | if (elf_sh64_plt_entry == NULL) |
| 3571 | { |
| 3572 | elf_sh64_plt_entry = (bfd_big_endian (output_bfd) ? |
| 3573 | elf_sh64_plt_entry_be : elf_sh64_plt_entry_le); |
| 3574 | } |
| 3575 | memcpy (splt->contents + h->plt.offset, elf_sh64_plt_entry, |
| 3576 | elf_sh64_sizeof_plt (info)); |
| 3577 | movi_3shori_putval (output_bfd, |
| 3578 | (sgot->output_section->vma |
| 3579 | + sgot->output_offset |
| 3580 | + got_offset), |
| 3581 | (splt->contents + h->plt.offset |
| 3582 | + elf_sh64_plt_symbol_offset (info))); |
| 3583 | |
| 3584 | /* Set bottom bit because its for a branch to SHmedia */ |
| 3585 | movi_shori_putval (output_bfd, |
| 3586 | -(h->plt.offset |
| 3587 | + elf_sh64_plt_plt0_offset (info) + 8) |
| 3588 | | 1, |
| 3589 | (splt->contents + h->plt.offset |
| 3590 | + elf_sh64_plt_plt0_offset (info))); |
| 3591 | } |
| 3592 | else |
| 3593 | { |
| 3594 | if (elf_sh64_pic_plt_entry == NULL) |
| 3595 | { |
| 3596 | elf_sh64_pic_plt_entry = (bfd_big_endian (output_bfd) ? |
| 3597 | elf_sh64_pic_plt_entry_be : |
| 3598 | elf_sh64_pic_plt_entry_le); |
| 3599 | } |
| 3600 | memcpy (splt->contents + h->plt.offset, elf_sh64_pic_plt_entry, |
| 3601 | elf_sh64_sizeof_plt (info)); |
| 3602 | movi_shori_putval (output_bfd, got_offset, |
| 3603 | (splt->contents + h->plt.offset |
| 3604 | + elf_sh64_plt_symbol_offset (info))); |
| 3605 | } |
| 3606 | |
| 3607 | if (bfd_link_pic (info)) |
| 3608 | got_offset += GOT_BIAS; |
| 3609 | |
| 3610 | movi_shori_putval (output_bfd, |
| 3611 | plt_index * sizeof (Elf64_External_Rela), |
| 3612 | (splt->contents + h->plt.offset |
| 3613 | + elf_sh64_plt_reloc_offset (info))); |
| 3614 | |
| 3615 | /* Fill in the entry in the global offset table. */ |
| 3616 | bfd_put_64 (output_bfd, |
| 3617 | (splt->output_section->vma |
| 3618 | + splt->output_offset |
| 3619 | + h->plt.offset |
| 3620 | + elf_sh64_plt_temp_offset (info)), |
| 3621 | sgot->contents + got_offset); |
| 3622 | |
| 3623 | /* Fill in the entry in the .rela.plt section. */ |
| 3624 | rel.r_offset = (sgot->output_section->vma |
| 3625 | + sgot->output_offset |
| 3626 | + got_offset); |
| 3627 | rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_JMP_SLOT64); |
| 3628 | rel.r_addend = 0; |
| 3629 | rel.r_addend = GOT_BIAS; |
| 3630 | loc = srel->contents + plt_index * sizeof (Elf64_External_Rela); |
| 3631 | bfd_elf64_swap_reloca_out (output_bfd, &rel, loc); |
| 3632 | |
| 3633 | if (!h->def_regular) |
| 3634 | { |
| 3635 | /* Mark the symbol as undefined, rather than as defined in |
| 3636 | the .plt section. Leave the value alone. */ |
| 3637 | sym->st_shndx = SHN_UNDEF; |
| 3638 | } |
| 3639 | } |
| 3640 | |
| 3641 | if (h->got.offset != (bfd_vma) -1) |
| 3642 | { |
| 3643 | asection *sgot; |
| 3644 | asection *srel; |
| 3645 | Elf_Internal_Rela rel; |
| 3646 | bfd_byte *loc; |
| 3647 | |
| 3648 | /* This symbol has an entry in the global offset table. Set it |
| 3649 | up. */ |
| 3650 | |
| 3651 | sgot = elf_hash_table (info)->sgot; |
| 3652 | srel = elf_hash_table (info)->srelgot; |
| 3653 | BFD_ASSERT (sgot != NULL && srel != NULL); |
| 3654 | |
| 3655 | rel.r_offset = (sgot->output_section->vma |
| 3656 | + sgot->output_offset |
| 3657 | + (h->got.offset &~ 1)); |
| 3658 | |
| 3659 | /* If this is a -Bsymbolic link, and the symbol is defined |
| 3660 | locally, we just want to emit a RELATIVE reloc. Likewise if |
| 3661 | the symbol was forced to be local because of a version file. |
| 3662 | The entry in the global offset table will already have been |
| 3663 | initialized in the relocate_section function. */ |
| 3664 | if (bfd_link_pic (info) |
| 3665 | && (info->symbolic || h->dynindx == -1) |
| 3666 | && h->def_regular) |
| 3667 | { |
| 3668 | rel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64); |
| 3669 | rel.r_addend = (h->root.u.def.value |
| 3670 | + h->root.u.def.section->output_section->vma |
| 3671 | + h->root.u.def.section->output_offset); |
| 3672 | } |
| 3673 | else |
| 3674 | { |
| 3675 | bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); |
| 3676 | rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_GLOB_DAT64); |
| 3677 | rel.r_addend = 0; |
| 3678 | } |
| 3679 | |
| 3680 | loc = srel->contents; |
| 3681 | loc += srel->reloc_count++ * sizeof (Elf64_External_Rela); |
| 3682 | bfd_elf64_swap_reloca_out (output_bfd, &rel, loc); |
| 3683 | } |
| 3684 | |
| 3685 | if (h->needs_copy) |
| 3686 | { |
| 3687 | asection *s; |
| 3688 | Elf_Internal_Rela rel; |
| 3689 | bfd_byte *loc; |
| 3690 | |
| 3691 | /* This symbol needs a copy reloc. Set it up. */ |
| 3692 | |
| 3693 | BFD_ASSERT (h->dynindx != -1 |
| 3694 | && (h->root.type == bfd_link_hash_defined |
| 3695 | || h->root.type == bfd_link_hash_defweak)); |
| 3696 | |
| 3697 | s = bfd_get_linker_section (dynobj, ".rela.bss"); |
| 3698 | BFD_ASSERT (s != NULL); |
| 3699 | |
| 3700 | rel.r_offset = (h->root.u.def.value |
| 3701 | + h->root.u.def.section->output_section->vma |
| 3702 | + h->root.u.def.section->output_offset); |
| 3703 | rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_COPY64); |
| 3704 | rel.r_addend = 0; |
| 3705 | loc = s->contents; |
| 3706 | loc += s->reloc_count++ * sizeof (Elf64_External_Rela); |
| 3707 | bfd_elf64_swap_reloca_out (output_bfd, &rel, loc); |
| 3708 | } |
| 3709 | |
| 3710 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ |
| 3711 | if (h == elf_hash_table (info)->hdynamic |
| 3712 | || h == elf_hash_table (info)->hgot) |
| 3713 | sym->st_shndx = SHN_ABS; |
| 3714 | |
| 3715 | return TRUE; |
| 3716 | } |
| 3717 | |
| 3718 | /* Finish up the dynamic sections. */ |
| 3719 | |
| 3720 | static bfd_boolean |
| 3721 | sh64_elf64_finish_dynamic_sections (bfd *output_bfd, |
| 3722 | struct bfd_link_info *info) |
| 3723 | { |
| 3724 | bfd *dynobj; |
| 3725 | asection *sgot; |
| 3726 | asection *sdyn; |
| 3727 | |
| 3728 | dynobj = elf_hash_table (info)->dynobj; |
| 3729 | |
| 3730 | sgot = elf_hash_table (info)->sgotplt; |
| 3731 | BFD_ASSERT (sgot != NULL); |
| 3732 | sdyn = bfd_get_linker_section (dynobj, ".dynamic"); |
| 3733 | |
| 3734 | if (elf_hash_table (info)->dynamic_sections_created) |
| 3735 | { |
| 3736 | asection *splt; |
| 3737 | Elf64_External_Dyn *dyncon, *dynconend; |
| 3738 | |
| 3739 | BFD_ASSERT (sdyn != NULL); |
| 3740 | |
| 3741 | dyncon = (Elf64_External_Dyn *) sdyn->contents; |
| 3742 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); |
| 3743 | for (; dyncon < dynconend; dyncon++) |
| 3744 | { |
| 3745 | Elf_Internal_Dyn dyn; |
| 3746 | const char *name; |
| 3747 | asection *s; |
| 3748 | struct elf_link_hash_entry *h; |
| 3749 | |
| 3750 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); |
| 3751 | |
| 3752 | switch (dyn.d_tag) |
| 3753 | { |
| 3754 | default: |
| 3755 | break; |
| 3756 | |
| 3757 | case DT_INIT: |
| 3758 | name = info->init_function; |
| 3759 | goto get_sym; |
| 3760 | |
| 3761 | case DT_FINI: |
| 3762 | name = info->fini_function; |
| 3763 | get_sym: |
| 3764 | if (dyn.d_un.d_val != 0) |
| 3765 | { |
| 3766 | h = elf_link_hash_lookup (elf_hash_table (info), name, |
| 3767 | FALSE, FALSE, TRUE); |
| 3768 | if (h != NULL && (h->other & STO_SH5_ISA32)) |
| 3769 | { |
| 3770 | dyn.d_un.d_val |= 1; |
| 3771 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 3772 | } |
| 3773 | } |
| 3774 | break; |
| 3775 | |
| 3776 | case DT_PLTGOT: |
| 3777 | s = elf_hash_table (info)->sgotplt; |
| 3778 | goto get_vma; |
| 3779 | |
| 3780 | case DT_JMPREL: |
| 3781 | s = elf_hash_table (info)->srelplt; |
| 3782 | get_vma: |
| 3783 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
| 3784 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 3785 | break; |
| 3786 | |
| 3787 | case DT_PLTRELSZ: |
| 3788 | s = elf_hash_table (info)->srelplt; |
| 3789 | dyn.d_un.d_val = s->size; |
| 3790 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 3791 | break; |
| 3792 | } |
| 3793 | } |
| 3794 | |
| 3795 | /* Fill in the first entry in the procedure linkage table. */ |
| 3796 | splt = elf_hash_table (info)->splt; |
| 3797 | if (splt && splt->size > 0) |
| 3798 | { |
| 3799 | if (bfd_link_pic (info)) |
| 3800 | { |
| 3801 | if (elf_sh64_pic_plt_entry == NULL) |
| 3802 | { |
| 3803 | elf_sh64_pic_plt_entry = (bfd_big_endian (output_bfd) ? |
| 3804 | elf_sh64_pic_plt_entry_be : |
| 3805 | elf_sh64_pic_plt_entry_le); |
| 3806 | } |
| 3807 | memcpy (splt->contents, elf_sh64_pic_plt_entry, |
| 3808 | elf_sh64_sizeof_plt (info)); |
| 3809 | } |
| 3810 | else |
| 3811 | { |
| 3812 | if (elf_sh64_plt0_entry == NULL) |
| 3813 | { |
| 3814 | elf_sh64_plt0_entry = (bfd_big_endian (output_bfd) ? |
| 3815 | elf_sh64_plt0_entry_be : |
| 3816 | elf_sh64_plt0_entry_le); |
| 3817 | } |
| 3818 | memcpy (splt->contents, elf_sh64_plt0_entry, PLT_ENTRY_SIZE); |
| 3819 | movi_3shori_putval (output_bfd, |
| 3820 | sgot->output_section->vma |
| 3821 | + sgot->output_offset, |
| 3822 | splt->contents |
| 3823 | + elf_sh64_plt0_gotplt_offset (info)); |
| 3824 | } |
| 3825 | |
| 3826 | /* UnixWare sets the entsize of .plt to 8, although that doesn't |
| 3827 | really seem like the right value. */ |
| 3828 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = 8; |
| 3829 | } |
| 3830 | } |
| 3831 | |
| 3832 | /* Fill in the first three entries in the global offset table. */ |
| 3833 | if (sgot->size > 0) |
| 3834 | { |
| 3835 | if (sdyn == NULL) |
| 3836 | bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents); |
| 3837 | else |
| 3838 | bfd_put_64 (output_bfd, |
| 3839 | sdyn->output_section->vma + sdyn->output_offset, |
| 3840 | sgot->contents); |
| 3841 | bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + 8); |
| 3842 | bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + 16); |
| 3843 | } |
| 3844 | |
| 3845 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 8; |
| 3846 | |
| 3847 | return TRUE; |
| 3848 | } |
| 3849 | |
| 3850 | /* Merge non visibility st_other attribute when the symbol comes from |
| 3851 | a dynamic object. */ |
| 3852 | static void |
| 3853 | sh64_elf64_merge_symbol_attribute (struct elf_link_hash_entry *h, |
| 3854 | const Elf_Internal_Sym *isym, |
| 3855 | bfd_boolean definition, |
| 3856 | bfd_boolean dynamic ATTRIBUTE_UNUSED) |
| 3857 | { |
| 3858 | if ((isym->st_other & ~ELF_ST_VISIBILITY (-1)) != 0) |
| 3859 | { |
| 3860 | unsigned char other; |
| 3861 | |
| 3862 | /* Take the balance of OTHER from the definition. */ |
| 3863 | other = (definition ? isym->st_other : h->other); |
| 3864 | other &= ~ ELF_ST_VISIBILITY (-1); |
| 3865 | h->other = other | ELF_ST_VISIBILITY (h->other); |
| 3866 | } |
| 3867 | |
| 3868 | return; |
| 3869 | } |
| 3870 | |
| 3871 | static const struct bfd_elf_special_section sh64_elf64_special_sections[]= |
| 3872 | { |
| 3873 | { STRING_COMMA_LEN (".cranges"), 0, SHT_PROGBITS, 0 }, |
| 3874 | { NULL, 0, 0, 0, 0 } |
| 3875 | }; |
| 3876 | |
| 3877 | #define TARGET_BIG_SYM sh64_elf64_vec |
| 3878 | #define TARGET_BIG_NAME "elf64-sh64" |
| 3879 | #define TARGET_LITTLE_SYM sh64_elf64_le_vec |
| 3880 | #define TARGET_LITTLE_NAME "elf64-sh64l" |
| 3881 | #define ELF_ARCH bfd_arch_sh |
| 3882 | #define ELF_MACHINE_CODE EM_SH |
| 3883 | #define ELF_MAXPAGESIZE 128 |
| 3884 | |
| 3885 | #define elf_symbol_leading_char '_' |
| 3886 | |
| 3887 | #define bfd_elf64_bfd_reloc_type_lookup sh_elf64_reloc_type_lookup |
| 3888 | #define bfd_elf64_bfd_reloc_name_lookup \ |
| 3889 | sh_elf64_reloc_name_lookup |
| 3890 | #define elf_info_to_howto sh_elf64_info_to_howto |
| 3891 | |
| 3892 | /* Note: there's no relaxation at present. */ |
| 3893 | |
| 3894 | #define elf_backend_relocate_section sh_elf64_relocate_section |
| 3895 | #define bfd_elf64_bfd_get_relocated_section_contents \ |
| 3896 | sh_elf64_get_relocated_section_contents |
| 3897 | #define elf_backend_object_p sh_elf64_set_mach_from_flags |
| 3898 | #define bfd_elf64_bfd_set_private_flags \ |
| 3899 | sh_elf64_set_private_flags |
| 3900 | #define bfd_elf64_bfd_copy_private_bfd_data \ |
| 3901 | sh_elf64_copy_private_data |
| 3902 | #define bfd_elf64_bfd_merge_private_bfd_data \ |
| 3903 | sh_elf64_merge_private_data |
| 3904 | #define elf_backend_fake_sections sh64_elf64_fake_sections |
| 3905 | |
| 3906 | #define elf_backend_gc_mark_hook sh_elf64_gc_mark_hook |
| 3907 | #define elf_backend_check_relocs sh_elf64_check_relocs |
| 3908 | |
| 3909 | #define elf_backend_can_gc_sections 1 |
| 3910 | |
| 3911 | #define elf_backend_get_symbol_type sh64_elf64_get_symbol_type |
| 3912 | |
| 3913 | #define elf_backend_add_symbol_hook sh64_elf64_add_symbol_hook |
| 3914 | |
| 3915 | #define elf_backend_link_output_symbol_hook \ |
| 3916 | sh64_elf64_link_output_symbol_hook |
| 3917 | |
| 3918 | #define elf_backend_merge_symbol_attribute \ |
| 3919 | sh64_elf64_merge_symbol_attribute |
| 3920 | |
| 3921 | #define elf_backend_final_write_processing \ |
| 3922 | sh64_elf64_final_write_processing |
| 3923 | |
| 3924 | #define elf_backend_create_dynamic_sections \ |
| 3925 | sh64_elf64_create_dynamic_sections |
| 3926 | #define bfd_elf64_bfd_link_hash_table_create \ |
| 3927 | sh64_elf64_link_hash_table_create |
| 3928 | #define elf_backend_adjust_dynamic_symbol \ |
| 3929 | sh64_elf64_adjust_dynamic_symbol |
| 3930 | #define elf_backend_size_dynamic_sections \ |
| 3931 | sh64_elf64_size_dynamic_sections |
| 3932 | #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all |
| 3933 | #define elf_backend_finish_dynamic_symbol \ |
| 3934 | sh64_elf64_finish_dynamic_symbol |
| 3935 | #define elf_backend_finish_dynamic_sections \ |
| 3936 | sh64_elf64_finish_dynamic_sections |
| 3937 | #define elf_backend_special_sections sh64_elf64_special_sections |
| 3938 | |
| 3939 | #define elf_backend_want_got_plt 1 |
| 3940 | #define elf_backend_plt_readonly 1 |
| 3941 | #define elf_backend_want_plt_sym 0 |
| 3942 | #define elf_backend_got_header_size 24 |
| 3943 | #define elf_backend_dtrel_excludes_plt 1 |
| 3944 | |
| 3945 | #define elf_backend_linux_prpsinfo64_ugid16 TRUE |
| 3946 | |
| 3947 | #include "elf64-target.h" |
| 3948 | |
| 3949 | /* NetBSD support. */ |
| 3950 | #undef TARGET_BIG_SYM |
| 3951 | #define TARGET_BIG_SYM sh64_elf64_nbsd_vec |
| 3952 | #undef TARGET_BIG_NAME |
| 3953 | #define TARGET_BIG_NAME "elf64-sh64-nbsd" |
| 3954 | #undef TARGET_LITTLE_SYM |
| 3955 | #define TARGET_LITTLE_SYM sh64_elf64_nbsd_le_vec |
| 3956 | #undef TARGET_LITTLE_NAME |
| 3957 | #define TARGET_LITTLE_NAME "elf64-sh64l-nbsd" |
| 3958 | #undef ELF_MAXPAGESIZE |
| 3959 | #define ELF_MAXPAGESIZE 0x10000 |
| 3960 | #undef elf_symbol_leading_char |
| 3961 | #define elf_symbol_leading_char 0 |
| 3962 | |
| 3963 | #define elf64_bed elf64_sh64_nbsd_bed |
| 3964 | |
| 3965 | #include "elf64-target.h" |
| 3966 | |
| 3967 | /* Linux support. */ |
| 3968 | #undef TARGET_BIG_SYM |
| 3969 | #define TARGET_BIG_SYM sh64_elf64_linux_be_vec |
| 3970 | #undef TARGET_BIG_NAME |
| 3971 | #define TARGET_BIG_NAME "elf64-sh64big-linux" |
| 3972 | #undef TARGET_LITTLE_SYM |
| 3973 | #define TARGET_LITTLE_SYM sh64_elf64_linux_vec |
| 3974 | #undef TARGET_LITTLE_NAME |
| 3975 | #define TARGET_LITTLE_NAME "elf64-sh64-linux" |
| 3976 | #undef elf64_bed |
| 3977 | #define elf64_bed elf64_sh64_linux_bed |
| 3978 | |
| 3979 | #include "elf64-target.h" |