| 1 | /* PowerPC64-specific support for 64-bit ELF. |
| 2 | Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
| 3 | Written by Linus Nordberg, Swox AB <info@swox.com>, |
| 4 | based on elf32-ppc.c by Ian Lance Taylor. |
| 5 | |
| 6 | This file is part of BFD, the Binary File Descriptor library. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 21 | |
| 22 | /* This file is based on the 64-bit PowerPC ELF ABI. It is also based |
| 23 | on the file elf32-ppc.c. */ |
| 24 | |
| 25 | #include "bfd.h" |
| 26 | #include "sysdep.h" |
| 27 | #include "bfdlink.h" |
| 28 | #include "libbfd.h" |
| 29 | #include "elf-bfd.h" |
| 30 | #include "elf/ppc.h" |
| 31 | #include "elf64-ppc.h" |
| 32 | |
| 33 | #define USE_RELA /* we want RELA relocations, not REL. */ |
| 34 | |
| 35 | |
| 36 | static void ppc_howto_init |
| 37 | PARAMS ((void)); |
| 38 | static reloc_howto_type *ppc64_elf_reloc_type_lookup |
| 39 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); |
| 40 | static void ppc64_elf_info_to_howto |
| 41 | PARAMS ((bfd *abfd, arelent *cache_ptr, Elf64_Internal_Rela *dst)); |
| 42 | static bfd_reloc_status_type ppc64_elf_addr16_ha_reloc |
| 43 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); |
| 44 | static boolean ppc64_elf_set_private_flags |
| 45 | PARAMS ((bfd *, flagword)); |
| 46 | static boolean ppc64_elf_merge_private_bfd_data |
| 47 | PARAMS ((bfd *, bfd *)); |
| 48 | static boolean ppc64_elf_section_from_shdr |
| 49 | PARAMS ((bfd *, Elf64_Internal_Shdr *, char *)); |
| 50 | static struct bfd_hash_entry *link_hash_newfunc |
| 51 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); |
| 52 | static struct bfd_link_hash_table *ppc64_elf_link_hash_table_create |
| 53 | PARAMS ((bfd *)); |
| 54 | static boolean create_got_section |
| 55 | PARAMS ((bfd *, struct bfd_link_info *)); |
| 56 | static boolean ppc64_elf_create_dynamic_sections |
| 57 | PARAMS ((bfd *, struct bfd_link_info *)); |
| 58 | static void ppc64_elf_copy_indirect_symbol |
| 59 | PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *)); |
| 60 | static boolean ppc64_elf_check_relocs |
| 61 | PARAMS ((bfd *, struct bfd_link_info *, asection *, |
| 62 | const Elf_Internal_Rela *)); |
| 63 | static asection * ppc64_elf_gc_mark_hook |
| 64 | PARAMS ((bfd *abfd, struct bfd_link_info *info, Elf_Internal_Rela *rel, |
| 65 | struct elf_link_hash_entry *h, Elf_Internal_Sym *sym)); |
| 66 | static boolean ppc64_elf_gc_sweep_hook |
| 67 | PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec, |
| 68 | const Elf_Internal_Rela *relocs)); |
| 69 | static boolean func_desc_adjust |
| 70 | PARAMS ((struct elf_link_hash_entry *, PTR)); |
| 71 | static boolean ppc64_elf_func_desc_adjust |
| 72 | PARAMS ((bfd *, struct bfd_link_info *)); |
| 73 | static boolean ppc64_elf_adjust_dynamic_symbol |
| 74 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); |
| 75 | static void ppc64_elf_hide_symbol |
| 76 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean)); |
| 77 | static boolean allocate_dynrelocs |
| 78 | PARAMS ((struct elf_link_hash_entry *, PTR)); |
| 79 | static boolean readonly_dynrelocs |
| 80 | PARAMS ((struct elf_link_hash_entry *, PTR)); |
| 81 | static enum elf_reloc_type_class ppc64_elf_reloc_type_class |
| 82 | PARAMS ((const Elf_Internal_Rela *)); |
| 83 | static boolean ppc64_elf_size_dynamic_sections |
| 84 | PARAMS ((bfd *, struct bfd_link_info *)); |
| 85 | static bfd_byte *build_plt_stub |
| 86 | PARAMS ((bfd *, bfd_byte *, int, int)); |
| 87 | static boolean build_one_stub |
| 88 | PARAMS ((struct elf_link_hash_entry *, PTR)); |
| 89 | static boolean ppc64_elf_fake_sections |
| 90 | PARAMS ((bfd *, Elf64_Internal_Shdr *, asection *)); |
| 91 | static boolean ppc64_elf_relocate_section |
| 92 | PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *, |
| 93 | Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms, |
| 94 | asection **)); |
| 95 | static boolean ppc64_elf_finish_dynamic_symbol |
| 96 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, |
| 97 | Elf_Internal_Sym *)); |
| 98 | static boolean ppc64_elf_finish_dynamic_sections |
| 99 | PARAMS ((bfd *, struct bfd_link_info *)); |
| 100 | |
| 101 | |
| 102 | /* Mask to set RA in memory instructions. */ |
| 103 | #define RA_REGISTER_MASK 0x001f0000 |
| 104 | |
| 105 | /* Value to shift register by to insert RA. */ |
| 106 | #define RA_REGISTER_SHIFT 16 |
| 107 | |
| 108 | /* The name of the dynamic interpreter. This is put in the .interp |
| 109 | section. */ |
| 110 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
| 111 | |
| 112 | /* The size in bytes of an entry in the procedure linkage table. */ |
| 113 | #define PLT_ENTRY_SIZE 24 |
| 114 | |
| 115 | /* The initial size of the plt reserved for the dynamic linker. */ |
| 116 | #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE |
| 117 | |
| 118 | /* TOC base pointers offset from start of TOC. */ |
| 119 | #define TOC_BASE_OFF (0x8000) |
| 120 | |
| 121 | /* .plt call stub instructions. */ |
| 122 | #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ |
| 123 | #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ |
| 124 | #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ |
| 125 | #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ |
| 126 | #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ |
| 127 | /* ld %r11,xxx+16@l(%r12) */ |
| 128 | #define BCTR 0x4e800420 /* bctr */ |
| 129 | |
| 130 | /* The normal stub is this size. */ |
| 131 | #define PLT_CALL_STUB_SIZE (7*4) |
| 132 | |
| 133 | /* But sometimes the .plt entry crosses a 64k boundary, and we need |
| 134 | to adjust the high word with this insn. */ |
| 135 | #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */ |
| 136 | |
| 137 | /* The .glink fixup call stub is the same as the .plt call stub, but |
| 138 | the first instruction restores r2, and the std is omitted. */ |
| 139 | #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ |
| 140 | |
| 141 | /* Always allow this much space. */ |
| 142 | #define GLINK_CALL_STUB_SIZE (8*4) |
| 143 | |
| 144 | /* Pad with this. */ |
| 145 | #define NOP 0x60000000 |
| 146 | |
| 147 | /* .glink entries for the first 32k functions are two instructions. */ |
| 148 | #define LI_R0_0 0x38000000 /* li %r0,0 */ |
| 149 | #define B_DOT 0x48000000 /* b . */ |
| 150 | |
| 151 | /* After that, we need two instructions to load the index, followed by |
| 152 | a branch. */ |
| 153 | #define LIS_R0_0 0x3c000000 /* lis %r0,0 */ |
| 154 | #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */ |
| 155 | |
| 156 | /* Since .opd is an array of descriptors and each entry will end up |
| 157 | with identical R_PPC64_RELATIVE relocs, there is really no need to |
| 158 | propagate .opd relocs; The dynamic linker should be taught to |
| 159 | relocate .opd without reloc entries. FIXME: .opd should be trimmed |
| 160 | of unused values. */ |
| 161 | #ifndef NO_OPD_RELOCS |
| 162 | #define NO_OPD_RELOCS 0 |
| 163 | #endif |
| 164 | \f |
| 165 | /* Relocation HOWTO's. */ |
| 166 | static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC_max]; |
| 167 | |
| 168 | static reloc_howto_type ppc64_elf_howto_raw[] = { |
| 169 | /* This reloc does nothing. */ |
| 170 | HOWTO (R_PPC64_NONE, /* type */ |
| 171 | 0, /* rightshift */ |
| 172 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 173 | 32, /* bitsize */ |
| 174 | false, /* pc_relative */ |
| 175 | 0, /* bitpos */ |
| 176 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 177 | bfd_elf_generic_reloc, /* special_function */ |
| 178 | "R_PPC64_NONE", /* name */ |
| 179 | false, /* partial_inplace */ |
| 180 | 0, /* src_mask */ |
| 181 | 0, /* dst_mask */ |
| 182 | false), /* pcrel_offset */ |
| 183 | |
| 184 | /* A standard 32 bit relocation. */ |
| 185 | HOWTO (R_PPC64_ADDR32, /* type */ |
| 186 | 0, /* rightshift */ |
| 187 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 188 | 32, /* bitsize */ |
| 189 | false, /* pc_relative */ |
| 190 | 0, /* bitpos */ |
| 191 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 192 | bfd_elf_generic_reloc, /* special_function */ |
| 193 | "R_PPC64_ADDR32", /* name */ |
| 194 | false, /* partial_inplace */ |
| 195 | 0, /* src_mask */ |
| 196 | 0xffffffff, /* dst_mask */ |
| 197 | false), /* pcrel_offset */ |
| 198 | |
| 199 | /* An absolute 26 bit branch; the lower two bits must be zero. |
| 200 | FIXME: we don't check that, we just clear them. */ |
| 201 | HOWTO (R_PPC64_ADDR24, /* type */ |
| 202 | 0, /* rightshift */ |
| 203 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 204 | 26, /* bitsize */ |
| 205 | false, /* pc_relative */ |
| 206 | 0, /* bitpos */ |
| 207 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 208 | bfd_elf_generic_reloc, /* special_function */ |
| 209 | "R_PPC64_ADDR24", /* name */ |
| 210 | false, /* partial_inplace */ |
| 211 | 0, /* src_mask */ |
| 212 | 0x3fffffc, /* dst_mask */ |
| 213 | false), /* pcrel_offset */ |
| 214 | |
| 215 | /* A standard 16 bit relocation. */ |
| 216 | HOWTO (R_PPC64_ADDR16, /* type */ |
| 217 | 0, /* rightshift */ |
| 218 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 219 | 16, /* bitsize */ |
| 220 | false, /* pc_relative */ |
| 221 | 0, /* bitpos */ |
| 222 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 223 | bfd_elf_generic_reloc, /* special_function */ |
| 224 | "R_PPC64_ADDR16", /* name */ |
| 225 | false, /* partial_inplace */ |
| 226 | 0, /* src_mask */ |
| 227 | 0xffff, /* dst_mask */ |
| 228 | false), /* pcrel_offset */ |
| 229 | |
| 230 | /* A 16 bit relocation without overflow. */ |
| 231 | HOWTO (R_PPC64_ADDR16_LO, /* type */ |
| 232 | 0, /* rightshift */ |
| 233 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 234 | 16, /* bitsize */ |
| 235 | false, /* pc_relative */ |
| 236 | 0, /* bitpos */ |
| 237 | complain_overflow_dont,/* complain_on_overflow */ |
| 238 | bfd_elf_generic_reloc, /* special_function */ |
| 239 | "R_PPC64_ADDR16_LO", /* name */ |
| 240 | false, /* partial_inplace */ |
| 241 | 0, /* src_mask */ |
| 242 | 0xffff, /* dst_mask */ |
| 243 | false), /* pcrel_offset */ |
| 244 | |
| 245 | /* Bits 16-31 of an address. */ |
| 246 | HOWTO (R_PPC64_ADDR16_HI, /* type */ |
| 247 | 16, /* rightshift */ |
| 248 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 249 | 16, /* bitsize */ |
| 250 | false, /* pc_relative */ |
| 251 | 0, /* bitpos */ |
| 252 | complain_overflow_dont, /* complain_on_overflow */ |
| 253 | bfd_elf_generic_reloc, /* special_function */ |
| 254 | "R_PPC64_ADDR16_HI", /* name */ |
| 255 | false, /* partial_inplace */ |
| 256 | 0, /* src_mask */ |
| 257 | 0xffff, /* dst_mask */ |
| 258 | false), /* pcrel_offset */ |
| 259 | |
| 260 | /* Bits 16-31 of an address, plus 1 if the contents of the low 16 |
| 261 | bits, treated as a signed number, is negative. */ |
| 262 | HOWTO (R_PPC64_ADDR16_HA, /* type */ |
| 263 | 16, /* rightshift */ |
| 264 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 265 | 16, /* bitsize */ |
| 266 | false, /* pc_relative */ |
| 267 | 0, /* bitpos */ |
| 268 | complain_overflow_dont, /* complain_on_overflow */ |
| 269 | ppc64_elf_addr16_ha_reloc, /* special_function */ |
| 270 | "R_PPC64_ADDR16_HA", /* name */ |
| 271 | false, /* partial_inplace */ |
| 272 | 0, /* src_mask */ |
| 273 | 0xffff, /* dst_mask */ |
| 274 | false), /* pcrel_offset */ |
| 275 | |
| 276 | /* An absolute 16 bit branch; the lower two bits must be zero. |
| 277 | FIXME: we don't check that, we just clear them. */ |
| 278 | HOWTO (R_PPC64_ADDR14, /* type */ |
| 279 | 0, /* rightshift */ |
| 280 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 281 | 16, /* bitsize */ |
| 282 | false, /* pc_relative */ |
| 283 | 0, /* bitpos */ |
| 284 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 285 | bfd_elf_generic_reloc, /* special_function */ |
| 286 | "R_PPC64_ADDR14", /* name */ |
| 287 | false, /* partial_inplace */ |
| 288 | 0, /* src_mask */ |
| 289 | 0xfffc, /* dst_mask */ |
| 290 | false), /* pcrel_offset */ |
| 291 | |
| 292 | /* An absolute 16 bit branch, for which bit 10 should be set to |
| 293 | indicate that the branch is expected to be taken. The lower two |
| 294 | bits must be zero. */ |
| 295 | HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */ |
| 296 | 0, /* rightshift */ |
| 297 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 298 | 16, /* bitsize */ |
| 299 | false, /* pc_relative */ |
| 300 | 0, /* bitpos */ |
| 301 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 302 | bfd_elf_generic_reloc, /* special_function */ |
| 303 | "R_PPC64_ADDR14_BRTAKEN",/* name */ |
| 304 | false, /* partial_inplace */ |
| 305 | 0, /* src_mask */ |
| 306 | 0xfffc, /* dst_mask */ |
| 307 | false), /* pcrel_offset */ |
| 308 | |
| 309 | /* An absolute 16 bit branch, for which bit 10 should be set to |
| 310 | indicate that the branch is not expected to be taken. The lower |
| 311 | two bits must be zero. */ |
| 312 | HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */ |
| 313 | 0, /* rightshift */ |
| 314 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 315 | 16, /* bitsize */ |
| 316 | false, /* pc_relative */ |
| 317 | 0, /* bitpos */ |
| 318 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 319 | bfd_elf_generic_reloc, /* special_function */ |
| 320 | "R_PPC64_ADDR14_BRNTAKEN",/* name */ |
| 321 | false, /* partial_inplace */ |
| 322 | 0, /* src_mask */ |
| 323 | 0xfffc, /* dst_mask */ |
| 324 | false), /* pcrel_offset */ |
| 325 | |
| 326 | /* A relative 26 bit branch; the lower two bits must be zero. */ |
| 327 | HOWTO (R_PPC64_REL24, /* type */ |
| 328 | 0, /* rightshift */ |
| 329 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 330 | 26, /* bitsize */ |
| 331 | true, /* pc_relative */ |
| 332 | 0, /* bitpos */ |
| 333 | complain_overflow_signed, /* complain_on_overflow */ |
| 334 | bfd_elf_generic_reloc, /* special_function */ |
| 335 | "R_PPC64_REL24", /* name */ |
| 336 | false, /* partial_inplace */ |
| 337 | 0, /* src_mask */ |
| 338 | 0x3fffffc, /* dst_mask */ |
| 339 | true), /* pcrel_offset */ |
| 340 | |
| 341 | /* A relative 16 bit branch; the lower two bits must be zero. */ |
| 342 | HOWTO (R_PPC64_REL14, /* type */ |
| 343 | 0, /* rightshift */ |
| 344 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 345 | 16, /* bitsize */ |
| 346 | true, /* pc_relative */ |
| 347 | 0, /* bitpos */ |
| 348 | complain_overflow_signed, /* complain_on_overflow */ |
| 349 | bfd_elf_generic_reloc, /* special_function */ |
| 350 | "R_PPC64_REL14", /* name */ |
| 351 | false, /* partial_inplace */ |
| 352 | 0, /* src_mask */ |
| 353 | 0xfffc, /* dst_mask */ |
| 354 | true), /* pcrel_offset */ |
| 355 | |
| 356 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
| 357 | the branch is expected to be taken. The lower two bits must be |
| 358 | zero. */ |
| 359 | HOWTO (R_PPC64_REL14_BRTAKEN, /* type */ |
| 360 | 0, /* rightshift */ |
| 361 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 362 | 16, /* bitsize */ |
| 363 | true, /* pc_relative */ |
| 364 | 0, /* bitpos */ |
| 365 | complain_overflow_signed, /* complain_on_overflow */ |
| 366 | bfd_elf_generic_reloc, /* special_function */ |
| 367 | "R_PPC64_REL14_BRTAKEN", /* name */ |
| 368 | false, /* partial_inplace */ |
| 369 | 0, /* src_mask */ |
| 370 | 0xfffc, /* dst_mask */ |
| 371 | true), /* pcrel_offset */ |
| 372 | |
| 373 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
| 374 | the branch is not expected to be taken. The lower two bits must |
| 375 | be zero. */ |
| 376 | HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */ |
| 377 | 0, /* rightshift */ |
| 378 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 379 | 16, /* bitsize */ |
| 380 | true, /* pc_relative */ |
| 381 | 0, /* bitpos */ |
| 382 | complain_overflow_signed, /* complain_on_overflow */ |
| 383 | bfd_elf_generic_reloc, /* special_function */ |
| 384 | "R_PPC64_REL14_BRNTAKEN",/* name */ |
| 385 | false, /* partial_inplace */ |
| 386 | 0, /* src_mask */ |
| 387 | 0xfffc, /* dst_mask */ |
| 388 | true), /* pcrel_offset */ |
| 389 | |
| 390 | /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the |
| 391 | symbol. */ |
| 392 | HOWTO (R_PPC64_GOT16, /* type */ |
| 393 | 0, /* rightshift */ |
| 394 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 395 | 16, /* bitsize */ |
| 396 | false, /* pc_relative */ |
| 397 | 0, /* bitpos */ |
| 398 | complain_overflow_signed, /* complain_on_overflow */ |
| 399 | bfd_elf_generic_reloc, /* special_function */ |
| 400 | "R_PPC64_GOT16", /* name */ |
| 401 | false, /* partial_inplace */ |
| 402 | 0, /* src_mask */ |
| 403 | 0xffff, /* dst_mask */ |
| 404 | false), /* pcrel_offset */ |
| 405 | |
| 406 | /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for |
| 407 | the symbol. */ |
| 408 | HOWTO (R_PPC64_GOT16_LO, /* type */ |
| 409 | 0, /* rightshift */ |
| 410 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 411 | 16, /* bitsize */ |
| 412 | false, /* pc_relative */ |
| 413 | 0, /* bitpos */ |
| 414 | complain_overflow_dont, /* complain_on_overflow */ |
| 415 | bfd_elf_generic_reloc, /* special_function */ |
| 416 | "R_PPC64_GOT16_LO", /* name */ |
| 417 | false, /* partial_inplace */ |
| 418 | 0, /* src_mask */ |
| 419 | 0xffff, /* dst_mask */ |
| 420 | false), /* pcrel_offset */ |
| 421 | |
| 422 | /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for |
| 423 | the symbol. */ |
| 424 | HOWTO (R_PPC64_GOT16_HI, /* type */ |
| 425 | 16, /* rightshift */ |
| 426 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 427 | 16, /* bitsize */ |
| 428 | false, /* pc_relative */ |
| 429 | 0, /* bitpos */ |
| 430 | complain_overflow_dont,/* complain_on_overflow */ |
| 431 | bfd_elf_generic_reloc, /* special_function */ |
| 432 | "R_PPC64_GOT16_HI", /* name */ |
| 433 | false, /* partial_inplace */ |
| 434 | 0, /* src_mask */ |
| 435 | 0xffff, /* dst_mask */ |
| 436 | false), /* pcrel_offset */ |
| 437 | |
| 438 | /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for |
| 439 | the symbol. */ |
| 440 | HOWTO (R_PPC64_GOT16_HA, /* type */ |
| 441 | 16, /* rightshift */ |
| 442 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 443 | 16, /* bitsize */ |
| 444 | false, /* pc_relative */ |
| 445 | 0, /* bitpos */ |
| 446 | complain_overflow_dont,/* complain_on_overflow */ |
| 447 | ppc64_elf_addr16_ha_reloc, /* special_function */ |
| 448 | "R_PPC64_GOT16_HA", /* name */ |
| 449 | false, /* partial_inplace */ |
| 450 | 0, /* src_mask */ |
| 451 | 0xffff, /* dst_mask */ |
| 452 | false), /* pcrel_offset */ |
| 453 | |
| 454 | /* This is used only by the dynamic linker. The symbol should exist |
| 455 | both in the object being run and in some shared library. The |
| 456 | dynamic linker copies the data addressed by the symbol from the |
| 457 | shared library into the object, because the object being |
| 458 | run has to have the data at some particular address. */ |
| 459 | HOWTO (R_PPC64_COPY, /* type */ |
| 460 | 0, /* rightshift */ |
| 461 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 462 | 32, /* bitsize */ |
| 463 | false, /* pc_relative */ |
| 464 | 0, /* bitpos */ |
| 465 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 466 | bfd_elf_generic_reloc, /* special_function */ |
| 467 | "R_PPC64_COPY", /* name */ |
| 468 | false, /* partial_inplace */ |
| 469 | 0, /* src_mask */ |
| 470 | 0, /* dst_mask */ |
| 471 | false), /* pcrel_offset */ |
| 472 | |
| 473 | /* Like R_PPC64_ADDR64, but used when setting global offset table |
| 474 | entries. */ |
| 475 | HOWTO (R_PPC64_GLOB_DAT, /* type */ |
| 476 | 0, /* rightshift */ |
| 477 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 478 | 64, /* bitsize */ |
| 479 | false, /* pc_relative */ |
| 480 | 0, /* bitpos */ |
| 481 | complain_overflow_dont, /* complain_on_overflow */ |
| 482 | bfd_elf_generic_reloc, /* special_function */ |
| 483 | "R_PPC64_GLOB_DAT", /* name */ |
| 484 | false, /* partial_inplace */ |
| 485 | 0, /* src_mask */ |
| 486 | 0xffffffffffffffff, /* dst_mask */ |
| 487 | false), /* pcrel_offset */ |
| 488 | |
| 489 | /* Created by the link editor. Marks a procedure linkage table |
| 490 | entry for a symbol. */ |
| 491 | HOWTO (R_PPC64_JMP_SLOT, /* type */ |
| 492 | 0, /* rightshift */ |
| 493 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 494 | 0, /* bitsize */ |
| 495 | false, /* pc_relative */ |
| 496 | 0, /* bitpos */ |
| 497 | complain_overflow_dont, /* complain_on_overflow */ |
| 498 | bfd_elf_generic_reloc, /* special_function */ |
| 499 | "R_PPC64_JMP_SLOT", /* name */ |
| 500 | false, /* partial_inplace */ |
| 501 | 0, /* src_mask */ |
| 502 | 0, /* dst_mask */ |
| 503 | false), /* pcrel_offset */ |
| 504 | |
| 505 | /* Used only by the dynamic linker. When the object is run, this |
| 506 | doubleword64 is set to the load address of the object, plus the |
| 507 | addend. */ |
| 508 | HOWTO (R_PPC64_RELATIVE, /* type */ |
| 509 | 0, /* rightshift */ |
| 510 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 511 | 64, /* bitsize */ |
| 512 | false, /* pc_relative */ |
| 513 | 0, /* bitpos */ |
| 514 | complain_overflow_dont, /* complain_on_overflow */ |
| 515 | bfd_elf_generic_reloc, /* special_function */ |
| 516 | "R_PPC64_RELATIVE", /* name */ |
| 517 | false, /* partial_inplace */ |
| 518 | 0, /* src_mask */ |
| 519 | 0xffffffffffffffff, /* dst_mask */ |
| 520 | false), /* pcrel_offset */ |
| 521 | |
| 522 | /* Like R_PPC64_ADDR32, but may be unaligned. */ |
| 523 | HOWTO (R_PPC64_UADDR32, /* type */ |
| 524 | 0, /* rightshift */ |
| 525 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 526 | 32, /* bitsize */ |
| 527 | false, /* pc_relative */ |
| 528 | 0, /* bitpos */ |
| 529 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 530 | bfd_elf_generic_reloc, /* special_function */ |
| 531 | "R_PPC64_UADDR32", /* name */ |
| 532 | false, /* partial_inplace */ |
| 533 | 0, /* src_mask */ |
| 534 | 0xffffffff, /* dst_mask */ |
| 535 | false), /* pcrel_offset */ |
| 536 | |
| 537 | /* Like R_PPC64_ADDR16, but may be unaligned. */ |
| 538 | HOWTO (R_PPC64_UADDR16, /* type */ |
| 539 | 0, /* rightshift */ |
| 540 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 541 | 16, /* bitsize */ |
| 542 | false, /* pc_relative */ |
| 543 | 0, /* bitpos */ |
| 544 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 545 | bfd_elf_generic_reloc, /* special_function */ |
| 546 | "R_PPC64_UADDR16", /* name */ |
| 547 | false, /* partial_inplace */ |
| 548 | 0, /* src_mask */ |
| 549 | 0xffff, /* dst_mask */ |
| 550 | false), /* pcrel_offset */ |
| 551 | |
| 552 | /* 32-bit PC relative. */ |
| 553 | HOWTO (R_PPC64_REL32, /* type */ |
| 554 | 0, /* rightshift */ |
| 555 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 556 | 32, /* bitsize */ |
| 557 | true, /* pc_relative */ |
| 558 | 0, /* bitpos */ |
| 559 | /* FIXME: Verify. Was complain_overflow_bitfield. */ |
| 560 | complain_overflow_signed, /* complain_on_overflow */ |
| 561 | bfd_elf_generic_reloc, /* special_function */ |
| 562 | "R_PPC64_REL32", /* name */ |
| 563 | false, /* partial_inplace */ |
| 564 | 0, /* src_mask */ |
| 565 | 0xffffffff, /* dst_mask */ |
| 566 | true), /* pcrel_offset */ |
| 567 | |
| 568 | /* 32-bit relocation to the symbol's procedure linkage table. */ |
| 569 | HOWTO (R_PPC64_PLT32, /* type */ |
| 570 | 0, /* rightshift */ |
| 571 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 572 | 32, /* bitsize */ |
| 573 | false, /* pc_relative */ |
| 574 | 0, /* bitpos */ |
| 575 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 576 | bfd_elf_generic_reloc, /* special_function */ |
| 577 | "R_PPC64_PLT32", /* name */ |
| 578 | false, /* partial_inplace */ |
| 579 | 0, /* src_mask */ |
| 580 | 0, /* dst_mask */ |
| 581 | false), /* pcrel_offset */ |
| 582 | |
| 583 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. |
| 584 | FIXME: R_PPC64_PLTREL32 not supported. */ |
| 585 | HOWTO (R_PPC64_PLTREL32, /* type */ |
| 586 | 0, /* rightshift */ |
| 587 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 588 | 32, /* bitsize */ |
| 589 | true, /* pc_relative */ |
| 590 | 0, /* bitpos */ |
| 591 | complain_overflow_signed, /* complain_on_overflow */ |
| 592 | bfd_elf_generic_reloc, /* special_function */ |
| 593 | "R_PPC64_PLTREL32", /* name */ |
| 594 | false, /* partial_inplace */ |
| 595 | 0, /* src_mask */ |
| 596 | 0, /* dst_mask */ |
| 597 | true), /* pcrel_offset */ |
| 598 | |
| 599 | /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for |
| 600 | the symbol. */ |
| 601 | HOWTO (R_PPC64_PLT16_LO, /* type */ |
| 602 | 0, /* rightshift */ |
| 603 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 604 | 16, /* bitsize */ |
| 605 | false, /* pc_relative */ |
| 606 | 0, /* bitpos */ |
| 607 | complain_overflow_dont, /* complain_on_overflow */ |
| 608 | bfd_elf_generic_reloc, /* special_function */ |
| 609 | "R_PPC64_PLT16_LO", /* name */ |
| 610 | false, /* partial_inplace */ |
| 611 | 0, /* src_mask */ |
| 612 | 0xffff, /* dst_mask */ |
| 613 | false), /* pcrel_offset */ |
| 614 | |
| 615 | /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for |
| 616 | the symbol. */ |
| 617 | HOWTO (R_PPC64_PLT16_HI, /* type */ |
| 618 | 16, /* rightshift */ |
| 619 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 620 | 16, /* bitsize */ |
| 621 | false, /* pc_relative */ |
| 622 | 0, /* bitpos */ |
| 623 | complain_overflow_dont, /* complain_on_overflow */ |
| 624 | bfd_elf_generic_reloc, /* special_function */ |
| 625 | "R_PPC64_PLT16_HI", /* name */ |
| 626 | false, /* partial_inplace */ |
| 627 | 0, /* src_mask */ |
| 628 | 0xffff, /* dst_mask */ |
| 629 | false), /* pcrel_offset */ |
| 630 | |
| 631 | /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for |
| 632 | the symbol. */ |
| 633 | HOWTO (R_PPC64_PLT16_HA, /* type */ |
| 634 | 16, /* rightshift */ |
| 635 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 636 | 16, /* bitsize */ |
| 637 | false, /* pc_relative */ |
| 638 | 0, /* bitpos */ |
| 639 | complain_overflow_dont, /* complain_on_overflow */ |
| 640 | ppc64_elf_addr16_ha_reloc, /* special_function */ |
| 641 | "R_PPC64_PLT16_HA", /* name */ |
| 642 | false, /* partial_inplace */ |
| 643 | 0, /* src_mask */ |
| 644 | 0xffff, /* dst_mask */ |
| 645 | false), /* pcrel_offset */ |
| 646 | |
| 647 | /* 32-bit section relative relocation. */ |
| 648 | /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and |
| 649 | dst_mask=0. */ |
| 650 | HOWTO (R_PPC64_SECTOFF, /* type */ |
| 651 | 0, /* rightshift */ |
| 652 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 653 | 32, /* bitsize */ |
| 654 | true, /* pc_relative */ |
| 655 | 0, /* bitpos */ |
| 656 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 657 | bfd_elf_generic_reloc, /* special_function */ |
| 658 | "R_PPC64_SECTOFF", /* name */ |
| 659 | false, /* partial_inplace */ |
| 660 | 0, /* src_mask */ |
| 661 | 0, /* dst_mask */ |
| 662 | true), /* pcrel_offset */ |
| 663 | |
| 664 | /* 16-bit lower half section relative relocation. */ |
| 665 | HOWTO (R_PPC64_SECTOFF_LO, /* type */ |
| 666 | 0, /* rightshift */ |
| 667 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 668 | 16, /* bitsize */ |
| 669 | false, /* pc_relative */ |
| 670 | 0, /* bitpos */ |
| 671 | complain_overflow_dont, /* complain_on_overflow */ |
| 672 | bfd_elf_generic_reloc, /* special_function */ |
| 673 | "R_PPC64_SECTOFF_LO", /* name */ |
| 674 | false, /* partial_inplace */ |
| 675 | 0, /* src_mask */ |
| 676 | 0xffff, /* dst_mask */ |
| 677 | false), /* pcrel_offset */ |
| 678 | |
| 679 | /* 16-bit upper half section relative relocation. */ |
| 680 | HOWTO (R_PPC64_SECTOFF_HI, /* type */ |
| 681 | 16, /* rightshift */ |
| 682 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 683 | 16, /* bitsize */ |
| 684 | false, /* pc_relative */ |
| 685 | 0, /* bitpos */ |
| 686 | complain_overflow_dont, /* complain_on_overflow */ |
| 687 | bfd_elf_generic_reloc, /* special_function */ |
| 688 | "R_PPC64_SECTOFF_HI", /* name */ |
| 689 | false, /* partial_inplace */ |
| 690 | 0, /* src_mask */ |
| 691 | 0xffff, /* dst_mask */ |
| 692 | false), /* pcrel_offset */ |
| 693 | |
| 694 | /* 16-bit upper half adjusted section relative relocation. */ |
| 695 | HOWTO (R_PPC64_SECTOFF_HA, /* type */ |
| 696 | 16, /* rightshift */ |
| 697 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 698 | 16, /* bitsize */ |
| 699 | false, /* pc_relative */ |
| 700 | 0, /* bitpos */ |
| 701 | complain_overflow_dont, /* complain_on_overflow */ |
| 702 | ppc64_elf_addr16_ha_reloc, /* special_function */ |
| 703 | "R_PPC64_SECTOFF_HA", /* name */ |
| 704 | false, /* partial_inplace */ |
| 705 | 0, /* src_mask */ |
| 706 | 0xffff, /* dst_mask */ |
| 707 | false), /* pcrel_offset */ |
| 708 | |
| 709 | /* Like R_PPC64_REL24 without touching the two least significant |
| 710 | bits. */ |
| 711 | /* FIXME: Verify R_PPC64_ADDR30. */ |
| 712 | HOWTO (R_PPC64_ADDR30, /* type */ |
| 713 | 2, /* rightshift */ |
| 714 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 715 | 30, /* bitsize */ |
| 716 | true, /* pc_relative */ |
| 717 | 0, /* bitpos */ |
| 718 | complain_overflow_dont, /* complain_on_overflow */ |
| 719 | bfd_elf_generic_reloc, /* special_function */ |
| 720 | "R_PPC64_ADDR30", /* name */ |
| 721 | false, /* partial_inplace */ |
| 722 | 0, /* src_mask */ |
| 723 | 0xfffffffc, /* dst_mask */ |
| 724 | true), /* pcrel_offset */ |
| 725 | |
| 726 | /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */ |
| 727 | |
| 728 | /* A standard 64-bit relocation. */ |
| 729 | HOWTO (R_PPC64_ADDR64, /* type */ |
| 730 | 0, /* rightshift */ |
| 731 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 732 | 64, /* bitsize */ |
| 733 | false, /* pc_relative */ |
| 734 | 0, /* bitpos */ |
| 735 | complain_overflow_dont, /* complain_on_overflow */ |
| 736 | bfd_elf_generic_reloc, /* special_function */ |
| 737 | "R_PPC64_ADDR64", /* name */ |
| 738 | false, /* partial_inplace */ |
| 739 | 0, /* src_mask */ |
| 740 | 0xffffffffffffffff, /* dst_mask */ |
| 741 | false), /* pcrel_offset */ |
| 742 | |
| 743 | /* The bits 32-47 of an address. */ |
| 744 | HOWTO (R_PPC64_ADDR16_HIGHER, /* type */ |
| 745 | 32, /* rightshift */ |
| 746 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 747 | 16, /* bitsize */ |
| 748 | false, /* pc_relative */ |
| 749 | 0, /* bitpos */ |
| 750 | complain_overflow_dont, /* complain_on_overflow */ |
| 751 | bfd_elf_generic_reloc, /* special_function */ |
| 752 | "R_PPC64_ADDR16_HIGHER", /* name */ |
| 753 | false, /* partial_inplace */ |
| 754 | 0, /* src_mask */ |
| 755 | 0xffff, /* dst_mask */ |
| 756 | false), /* pcrel_offset */ |
| 757 | |
| 758 | /* The bits 32-47 of an address, plus 1 if the contents of the low |
| 759 | 16 bits, treated as a signed number, is negative. */ |
| 760 | HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */ |
| 761 | 32, /* rightshift */ |
| 762 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 763 | 16, /* bitsize */ |
| 764 | false, /* pc_relative */ |
| 765 | 0, /* bitpos */ |
| 766 | complain_overflow_dont, /* complain_on_overflow */ |
| 767 | ppc64_elf_addr16_ha_reloc, /* special_function */ |
| 768 | "R_PPC64_ADDR16_HIGHERA", /* name */ |
| 769 | false, /* partial_inplace */ |
| 770 | 0, /* src_mask */ |
| 771 | 0xffff, /* dst_mask */ |
| 772 | false), /* pcrel_offset */ |
| 773 | |
| 774 | /* The bits 48-63 of an address. */ |
| 775 | HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */ |
| 776 | 48, /* rightshift */ |
| 777 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 778 | 16, /* bitsize */ |
| 779 | false, /* pc_relative */ |
| 780 | 0, /* bitpos */ |
| 781 | complain_overflow_dont, /* complain_on_overflow */ |
| 782 | bfd_elf_generic_reloc, /* special_function */ |
| 783 | "R_PPC64_ADDR16_HIGHEST", /* name */ |
| 784 | false, /* partial_inplace */ |
| 785 | 0, /* src_mask */ |
| 786 | 0xffff, /* dst_mask */ |
| 787 | false), /* pcrel_offset */ |
| 788 | |
| 789 | /* The bits 48-63 of an address, plus 1 if the contents of the low |
| 790 | 16 bits, treated as a signed number, is negative. */ |
| 791 | HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */ |
| 792 | 48, /* rightshift */ |
| 793 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 794 | 16, /* bitsize */ |
| 795 | false, /* pc_relative */ |
| 796 | 0, /* bitpos */ |
| 797 | complain_overflow_dont, /* complain_on_overflow */ |
| 798 | ppc64_elf_addr16_ha_reloc, /* special_function */ |
| 799 | "R_PPC64_ADDR16_HIGHESTA", /* name */ |
| 800 | false, /* partial_inplace */ |
| 801 | 0, /* src_mask */ |
| 802 | 0xffff, /* dst_mask */ |
| 803 | false), /* pcrel_offset */ |
| 804 | |
| 805 | /* Like ADDR64, but may be unaligned. */ |
| 806 | HOWTO (R_PPC64_UADDR64, /* type */ |
| 807 | 0, /* rightshift */ |
| 808 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 809 | 64, /* bitsize */ |
| 810 | false, /* pc_relative */ |
| 811 | 0, /* bitpos */ |
| 812 | complain_overflow_dont, /* complain_on_overflow */ |
| 813 | bfd_elf_generic_reloc, /* special_function */ |
| 814 | "R_PPC64_UADDR64", /* name */ |
| 815 | false, /* partial_inplace */ |
| 816 | 0, /* src_mask */ |
| 817 | 0xffffffffffffffff, /* dst_mask */ |
| 818 | false), /* pcrel_offset */ |
| 819 | |
| 820 | /* 64-bit relative relocation. */ |
| 821 | HOWTO (R_PPC64_REL64, /* type */ |
| 822 | 0, /* rightshift */ |
| 823 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 824 | 64, /* bitsize */ |
| 825 | true, /* pc_relative */ |
| 826 | 0, /* bitpos */ |
| 827 | complain_overflow_dont, /* complain_on_overflow */ |
| 828 | bfd_elf_generic_reloc, /* special_function */ |
| 829 | "R_PPC64_REL64", /* name */ |
| 830 | false, /* partial_inplace */ |
| 831 | 0, /* src_mask */ |
| 832 | 0xffffffffffffffff, /* dst_mask */ |
| 833 | true), /* pcrel_offset */ |
| 834 | |
| 835 | /* 64-bit relocation to the symbol's procedure linkage table. */ |
| 836 | HOWTO (R_PPC64_PLT64, /* type */ |
| 837 | 0, /* rightshift */ |
| 838 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 839 | 64, /* bitsize */ |
| 840 | false, /* pc_relative */ |
| 841 | 0, /* bitpos */ |
| 842 | complain_overflow_dont, /* complain_on_overflow */ |
| 843 | bfd_elf_generic_reloc, /* special_function */ |
| 844 | "R_PPC64_PLT64", /* name */ |
| 845 | false, /* partial_inplace */ |
| 846 | 0, /* src_mask */ |
| 847 | 0, /* dst_mask */ |
| 848 | false), /* pcrel_offset */ |
| 849 | |
| 850 | /* 64-bit PC relative relocation to the symbol's procedure linkage |
| 851 | table. */ |
| 852 | /* FIXME: R_PPC64_PLTREL64 not supported. */ |
| 853 | HOWTO (R_PPC64_PLTREL64, /* type */ |
| 854 | 0, /* rightshift */ |
| 855 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 856 | 64, /* bitsize */ |
| 857 | true, /* pc_relative */ |
| 858 | 0, /* bitpos */ |
| 859 | complain_overflow_dont, /* complain_on_overflow */ |
| 860 | bfd_elf_generic_reloc, /* special_function */ |
| 861 | "R_PPC64_PLTREL64", /* name */ |
| 862 | false, /* partial_inplace */ |
| 863 | 0, /* src_mask */ |
| 864 | 0, /* dst_mask */ |
| 865 | true), /* pcrel_offset */ |
| 866 | |
| 867 | /* 16 bit TOC-relative relocation. */ |
| 868 | |
| 869 | /* R_PPC64_TOC16 47 half16* S + A - .TOC. */ |
| 870 | HOWTO (R_PPC64_TOC16, /* type */ |
| 871 | 0, /* rightshift */ |
| 872 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 873 | 16, /* bitsize */ |
| 874 | false, /* pc_relative */ |
| 875 | 0, /* bitpos */ |
| 876 | complain_overflow_signed, /* complain_on_overflow */ |
| 877 | bfd_elf_generic_reloc, /* special_function */ |
| 878 | "R_PPC64_TOC16", /* name */ |
| 879 | false, /* partial_inplace */ |
| 880 | 0, /* src_mask */ |
| 881 | 0xffff, /* dst_mask */ |
| 882 | false), /* pcrel_offset */ |
| 883 | |
| 884 | /* 16 bit TOC-relative relocation without overflow. */ |
| 885 | |
| 886 | /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */ |
| 887 | HOWTO (R_PPC64_TOC16_LO, /* type */ |
| 888 | 0, /* rightshift */ |
| 889 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 890 | 16, /* bitsize */ |
| 891 | false, /* pc_relative */ |
| 892 | 0, /* bitpos */ |
| 893 | complain_overflow_dont, /* complain_on_overflow */ |
| 894 | bfd_elf_generic_reloc, /* special_function */ |
| 895 | "R_PPC64_TOC16_LO", /* name */ |
| 896 | false, /* partial_inplace */ |
| 897 | 0, /* src_mask */ |
| 898 | 0xffff, /* dst_mask */ |
| 899 | false), /* pcrel_offset */ |
| 900 | |
| 901 | /* 16 bit TOC-relative relocation, high 16 bits. */ |
| 902 | |
| 903 | /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */ |
| 904 | HOWTO (R_PPC64_TOC16_HI, /* type */ |
| 905 | 16, /* rightshift */ |
| 906 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 907 | 16, /* bitsize */ |
| 908 | false, /* pc_relative */ |
| 909 | 0, /* bitpos */ |
| 910 | complain_overflow_dont, /* complain_on_overflow */ |
| 911 | bfd_elf_generic_reloc, /* special_function */ |
| 912 | "R_PPC64_TOC16_HI", /* name */ |
| 913 | false, /* partial_inplace */ |
| 914 | 0, /* src_mask */ |
| 915 | 0xffff, /* dst_mask */ |
| 916 | false), /* pcrel_offset */ |
| 917 | |
| 918 | /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the |
| 919 | contents of the low 16 bits, treated as a signed number, is |
| 920 | negative. */ |
| 921 | |
| 922 | /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */ |
| 923 | HOWTO (R_PPC64_TOC16_HA, /* type */ |
| 924 | 16, /* rightshift */ |
| 925 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 926 | 16, /* bitsize */ |
| 927 | false, /* pc_relative */ |
| 928 | 0, /* bitpos */ |
| 929 | complain_overflow_dont, /* complain_on_overflow */ |
| 930 | ppc64_elf_addr16_ha_reloc, /* special_function */ |
| 931 | "R_PPC64_TOC16_HA", /* name */ |
| 932 | false, /* partial_inplace */ |
| 933 | 0, /* src_mask */ |
| 934 | 0xffff, /* dst_mask */ |
| 935 | false), /* pcrel_offset */ |
| 936 | |
| 937 | /* 64-bit relocation; insert value of TOC base (.TOC.). */ |
| 938 | |
| 939 | /* R_PPC64_TOC 51 doubleword64 .TOC. */ |
| 940 | HOWTO (R_PPC64_TOC, /* type */ |
| 941 | 0, /* rightshift */ |
| 942 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 943 | 64, /* bitsize */ |
| 944 | false, /* pc_relative */ |
| 945 | 0, /* bitpos */ |
| 946 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 947 | bfd_elf_generic_reloc, /* special_function */ |
| 948 | "R_PPC64_TOC", /* name */ |
| 949 | false, /* partial_inplace */ |
| 950 | 0, /* src_mask */ |
| 951 | 0xffffffffffffffff, /* dst_mask */ |
| 952 | false), /* pcrel_offset */ |
| 953 | |
| 954 | /* Like R_PPC64_GOT16, but also informs the link editor that the |
| 955 | value to relocate may (!) refer to a PLT entry which the link |
| 956 | editor (a) may replace with the symbol value. If the link editor |
| 957 | is unable to fully resolve the symbol, it may (b) create a PLT |
| 958 | entry and store the address to the new PLT entry in the GOT. |
| 959 | This permits lazy resolution of function symbols at run time. |
| 960 | The link editor may also skip all of this and just (c) emit a |
| 961 | R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */ |
| 962 | /* FIXME: R_PPC64_PLTGOT16 not implemented. */ |
| 963 | HOWTO (R_PPC64_PLTGOT16, /* type */ |
| 964 | 0, /* rightshift */ |
| 965 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 966 | 16, /* bitsize */ |
| 967 | false, /* pc_relative */ |
| 968 | 0, /* bitpos */ |
| 969 | complain_overflow_signed, /* complain_on_overflow */ |
| 970 | bfd_elf_generic_reloc, /* special_function */ |
| 971 | "R_PPC64_PLTGOT16", /* name */ |
| 972 | false, /* partial_inplace */ |
| 973 | 0, /* src_mask */ |
| 974 | 0xffff, /* dst_mask */ |
| 975 | false), /* pcrel_offset */ |
| 976 | |
| 977 | /* Like R_PPC64_PLTGOT16, but without overflow. */ |
| 978 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ |
| 979 | HOWTO (R_PPC64_PLTGOT16_LO, /* type */ |
| 980 | 0, /* rightshift */ |
| 981 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 982 | 16, /* bitsize */ |
| 983 | false, /* pc_relative */ |
| 984 | 0, /* bitpos */ |
| 985 | complain_overflow_dont, /* complain_on_overflow */ |
| 986 | bfd_elf_generic_reloc, /* special_function */ |
| 987 | "R_PPC64_PLTGOT16_LO", /* name */ |
| 988 | false, /* partial_inplace */ |
| 989 | 0, /* src_mask */ |
| 990 | 0xffff, /* dst_mask */ |
| 991 | false), /* pcrel_offset */ |
| 992 | |
| 993 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */ |
| 994 | /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */ |
| 995 | HOWTO (R_PPC64_PLTGOT16_HI, /* type */ |
| 996 | 16, /* rightshift */ |
| 997 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 998 | 16, /* bitsize */ |
| 999 | false, /* pc_relative */ |
| 1000 | 0, /* bitpos */ |
| 1001 | complain_overflow_dont, /* complain_on_overflow */ |
| 1002 | bfd_elf_generic_reloc, /* special_function */ |
| 1003 | "R_PPC64_PLTGOT16_HI", /* name */ |
| 1004 | false, /* partial_inplace */ |
| 1005 | 0, /* src_mask */ |
| 1006 | 0xffff, /* dst_mask */ |
| 1007 | false), /* pcrel_offset */ |
| 1008 | |
| 1009 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus |
| 1010 | 1 if the contents of the low 16 bits, treated as a signed number, |
| 1011 | is negative. */ |
| 1012 | /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */ |
| 1013 | HOWTO (R_PPC64_PLTGOT16_HA, /* type */ |
| 1014 | 16, /* rightshift */ |
| 1015 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1016 | 16, /* bitsize */ |
| 1017 | false, /* pc_relative */ |
| 1018 | 0, /* bitpos */ |
| 1019 | complain_overflow_dont,/* complain_on_overflow */ |
| 1020 | ppc64_elf_addr16_ha_reloc, /* special_function */ |
| 1021 | "R_PPC64_PLTGOT16_HA", /* name */ |
| 1022 | false, /* partial_inplace */ |
| 1023 | 0, /* src_mask */ |
| 1024 | 0xffff, /* dst_mask */ |
| 1025 | false), /* pcrel_offset */ |
| 1026 | |
| 1027 | /* Like R_PPC64_ADDR16, but for instructions with a DS field. */ |
| 1028 | HOWTO (R_PPC64_ADDR16_DS, /* type */ |
| 1029 | 0, /* rightshift */ |
| 1030 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1031 | 16, /* bitsize */ |
| 1032 | false, /* pc_relative */ |
| 1033 | 0, /* bitpos */ |
| 1034 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1035 | bfd_elf_generic_reloc, /* special_function */ |
| 1036 | "R_PPC64_ADDR16_DS", /* name */ |
| 1037 | false, /* partial_inplace */ |
| 1038 | 0, /* src_mask */ |
| 1039 | 0xfffc, /* dst_mask */ |
| 1040 | false), /* pcrel_offset */ |
| 1041 | |
| 1042 | /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */ |
| 1043 | HOWTO (R_PPC64_ADDR16_LO_DS, /* type */ |
| 1044 | 0, /* rightshift */ |
| 1045 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1046 | 16, /* bitsize */ |
| 1047 | false, /* pc_relative */ |
| 1048 | 0, /* bitpos */ |
| 1049 | complain_overflow_dont,/* complain_on_overflow */ |
| 1050 | bfd_elf_generic_reloc, /* special_function */ |
| 1051 | "R_PPC64_ADDR16_LO_DS",/* name */ |
| 1052 | false, /* partial_inplace */ |
| 1053 | 0, /* src_mask */ |
| 1054 | 0xfffc, /* dst_mask */ |
| 1055 | false), /* pcrel_offset */ |
| 1056 | |
| 1057 | /* Like R_PPC64_GOT16, but for instructions with a DS field. */ |
| 1058 | HOWTO (R_PPC64_GOT16_DS, /* type */ |
| 1059 | 0, /* rightshift */ |
| 1060 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1061 | 16, /* bitsize */ |
| 1062 | false, /* pc_relative */ |
| 1063 | 0, /* bitpos */ |
| 1064 | complain_overflow_signed, /* complain_on_overflow */ |
| 1065 | bfd_elf_generic_reloc, /* special_function */ |
| 1066 | "R_PPC64_GOT16_DS", /* name */ |
| 1067 | false, /* partial_inplace */ |
| 1068 | 0, /* src_mask */ |
| 1069 | 0xfffc, /* dst_mask */ |
| 1070 | false), /* pcrel_offset */ |
| 1071 | |
| 1072 | /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */ |
| 1073 | HOWTO (R_PPC64_GOT16_LO_DS, /* type */ |
| 1074 | 0, /* rightshift */ |
| 1075 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1076 | 16, /* bitsize */ |
| 1077 | false, /* pc_relative */ |
| 1078 | 0, /* bitpos */ |
| 1079 | complain_overflow_dont, /* complain_on_overflow */ |
| 1080 | bfd_elf_generic_reloc, /* special_function */ |
| 1081 | "R_PPC64_GOT16_LO_DS", /* name */ |
| 1082 | false, /* partial_inplace */ |
| 1083 | 0, /* src_mask */ |
| 1084 | 0xfffc, /* dst_mask */ |
| 1085 | false), /* pcrel_offset */ |
| 1086 | |
| 1087 | /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */ |
| 1088 | HOWTO (R_PPC64_PLT16_LO_DS, /* type */ |
| 1089 | 0, /* rightshift */ |
| 1090 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1091 | 16, /* bitsize */ |
| 1092 | false, /* pc_relative */ |
| 1093 | 0, /* bitpos */ |
| 1094 | complain_overflow_dont, /* complain_on_overflow */ |
| 1095 | bfd_elf_generic_reloc, /* special_function */ |
| 1096 | "R_PPC64_PLT16_LO_DS", /* name */ |
| 1097 | false, /* partial_inplace */ |
| 1098 | 0, /* src_mask */ |
| 1099 | 0xfffc, /* dst_mask */ |
| 1100 | false), /* pcrel_offset */ |
| 1101 | |
| 1102 | /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */ |
| 1103 | /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and |
| 1104 | dst_mask=0. */ |
| 1105 | HOWTO (R_PPC64_SECTOFF_DS, /* type */ |
| 1106 | 0, /* rightshift */ |
| 1107 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1108 | 32, /* bitsize */ |
| 1109 | true, /* pc_relative */ |
| 1110 | 0, /* bitpos */ |
| 1111 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1112 | bfd_elf_generic_reloc, /* special_function */ |
| 1113 | "R_PPC64_SECTOFF_DS", /* name */ |
| 1114 | false, /* partial_inplace */ |
| 1115 | 0, /* src_mask */ |
| 1116 | 0, /* dst_mask */ |
| 1117 | true), /* pcrel_offset */ |
| 1118 | |
| 1119 | /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */ |
| 1120 | HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */ |
| 1121 | 0, /* rightshift */ |
| 1122 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1123 | 16, /* bitsize */ |
| 1124 | false, /* pc_relative */ |
| 1125 | 0, /* bitpos */ |
| 1126 | complain_overflow_dont, /* complain_on_overflow */ |
| 1127 | bfd_elf_generic_reloc, /* special_function */ |
| 1128 | "R_PPC64_SECTOFF_LO_DS",/* name */ |
| 1129 | false, /* partial_inplace */ |
| 1130 | 0, /* src_mask */ |
| 1131 | 0xfffc, /* dst_mask */ |
| 1132 | false), /* pcrel_offset */ |
| 1133 | |
| 1134 | /* Like R_PPC64_TOC16, but for instructions with a DS field. */ |
| 1135 | HOWTO (R_PPC64_TOC16_DS, /* type */ |
| 1136 | 0, /* rightshift */ |
| 1137 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1138 | 16, /* bitsize */ |
| 1139 | false, /* pc_relative */ |
| 1140 | 0, /* bitpos */ |
| 1141 | complain_overflow_signed, /* complain_on_overflow */ |
| 1142 | bfd_elf_generic_reloc, /* special_function */ |
| 1143 | "R_PPC64_TOC16_DS", /* name */ |
| 1144 | false, /* partial_inplace */ |
| 1145 | 0, /* src_mask */ |
| 1146 | 0xfffc, /* dst_mask */ |
| 1147 | false), /* pcrel_offset */ |
| 1148 | |
| 1149 | /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */ |
| 1150 | HOWTO (R_PPC64_TOC16_LO_DS, /* type */ |
| 1151 | 0, /* rightshift */ |
| 1152 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1153 | 16, /* bitsize */ |
| 1154 | false, /* pc_relative */ |
| 1155 | 0, /* bitpos */ |
| 1156 | complain_overflow_dont, /* complain_on_overflow */ |
| 1157 | bfd_elf_generic_reloc, /* special_function */ |
| 1158 | "R_PPC64_TOC16_LO_DS", /* name */ |
| 1159 | false, /* partial_inplace */ |
| 1160 | 0, /* src_mask */ |
| 1161 | 0xfffc, /* dst_mask */ |
| 1162 | false), /* pcrel_offset */ |
| 1163 | |
| 1164 | /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */ |
| 1165 | /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */ |
| 1166 | HOWTO (R_PPC64_PLTGOT16_DS, /* type */ |
| 1167 | 0, /* rightshift */ |
| 1168 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1169 | 16, /* bitsize */ |
| 1170 | false, /* pc_relative */ |
| 1171 | 0, /* bitpos */ |
| 1172 | complain_overflow_signed, /* complain_on_overflow */ |
| 1173 | bfd_elf_generic_reloc, /* special_function */ |
| 1174 | "R_PPC64_PLTGOT16_DS", /* name */ |
| 1175 | false, /* partial_inplace */ |
| 1176 | 0, /* src_mask */ |
| 1177 | 0xfffc, /* dst_mask */ |
| 1178 | false), /* pcrel_offset */ |
| 1179 | |
| 1180 | /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */ |
| 1181 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ |
| 1182 | HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */ |
| 1183 | 0, /* rightshift */ |
| 1184 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1185 | 16, /* bitsize */ |
| 1186 | false, /* pc_relative */ |
| 1187 | 0, /* bitpos */ |
| 1188 | complain_overflow_dont, /* complain_on_overflow */ |
| 1189 | bfd_elf_generic_reloc, /* special_function */ |
| 1190 | "R_PPC64_PLTGOT16_LO_DS",/* name */ |
| 1191 | false, /* partial_inplace */ |
| 1192 | 0, /* src_mask */ |
| 1193 | 0xfffc, /* dst_mask */ |
| 1194 | false), /* pcrel_offset */ |
| 1195 | |
| 1196 | /* GNU extension to record C++ vtable hierarchy. */ |
| 1197 | HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ |
| 1198 | 0, /* rightshift */ |
| 1199 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1200 | 0, /* bitsize */ |
| 1201 | false, /* pc_relative */ |
| 1202 | 0, /* bitpos */ |
| 1203 | complain_overflow_dont, /* complain_on_overflow */ |
| 1204 | NULL, /* special_function */ |
| 1205 | "R_PPC64_GNU_VTINHERIT", /* name */ |
| 1206 | false, /* partial_inplace */ |
| 1207 | 0, /* src_mask */ |
| 1208 | 0, /* dst_mask */ |
| 1209 | false), /* pcrel_offset */ |
| 1210 | |
| 1211 | /* GNU extension to record C++ vtable member usage. */ |
| 1212 | HOWTO (R_PPC64_GNU_VTENTRY, /* type */ |
| 1213 | 0, /* rightshift */ |
| 1214 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1215 | 0, /* bitsize */ |
| 1216 | false, /* pc_relative */ |
| 1217 | 0, /* bitpos */ |
| 1218 | complain_overflow_dont, /* complain_on_overflow */ |
| 1219 | NULL, /* special_function */ |
| 1220 | "R_PPC64_GNU_VTENTRY", /* name */ |
| 1221 | false, /* partial_inplace */ |
| 1222 | 0, /* src_mask */ |
| 1223 | 0, /* dst_mask */ |
| 1224 | false), /* pcrel_offset */ |
| 1225 | }; |
| 1226 | |
| 1227 | \f |
| 1228 | /* Initialize the ppc64_elf_howto_table, so that linear accesses can |
| 1229 | be done. */ |
| 1230 | |
| 1231 | static void |
| 1232 | ppc_howto_init () |
| 1233 | { |
| 1234 | unsigned int i, type; |
| 1235 | |
| 1236 | for (i = 0; |
| 1237 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); |
| 1238 | i++) |
| 1239 | { |
| 1240 | type = ppc64_elf_howto_raw[i].type; |
| 1241 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) |
| 1242 | / sizeof (ppc64_elf_howto_table[0]))); |
| 1243 | ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i]; |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | static reloc_howto_type * |
| 1248 | ppc64_elf_reloc_type_lookup (abfd, code) |
| 1249 | bfd *abfd ATTRIBUTE_UNUSED; |
| 1250 | bfd_reloc_code_real_type code; |
| 1251 | { |
| 1252 | enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE; |
| 1253 | |
| 1254 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
| 1255 | /* Initialize howto table if needed. */ |
| 1256 | ppc_howto_init (); |
| 1257 | |
| 1258 | switch ((int) code) |
| 1259 | { |
| 1260 | default: |
| 1261 | return (reloc_howto_type *) NULL; |
| 1262 | |
| 1263 | case BFD_RELOC_NONE: ppc_reloc = R_PPC64_NONE; |
| 1264 | break; |
| 1265 | case BFD_RELOC_32: ppc_reloc = R_PPC64_ADDR32; |
| 1266 | break; |
| 1267 | case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC64_ADDR24; |
| 1268 | break; |
| 1269 | case BFD_RELOC_16: ppc_reloc = R_PPC64_ADDR16; |
| 1270 | break; |
| 1271 | case BFD_RELOC_LO16: ppc_reloc = R_PPC64_ADDR16_LO; |
| 1272 | break; |
| 1273 | case BFD_RELOC_HI16: ppc_reloc = R_PPC64_ADDR16_HI; |
| 1274 | break; |
| 1275 | case BFD_RELOC_HI16_S: ppc_reloc = R_PPC64_ADDR16_HA; |
| 1276 | break; |
| 1277 | case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC64_ADDR14; |
| 1278 | break; |
| 1279 | case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC64_ADDR14_BRTAKEN; |
| 1280 | break; |
| 1281 | case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC64_ADDR14_BRNTAKEN; |
| 1282 | break; |
| 1283 | case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC64_REL24; |
| 1284 | break; |
| 1285 | case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC64_REL14; |
| 1286 | break; |
| 1287 | case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC64_REL14_BRTAKEN; |
| 1288 | break; |
| 1289 | case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC64_REL14_BRNTAKEN; |
| 1290 | break; |
| 1291 | case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC64_GOT16; |
| 1292 | break; |
| 1293 | case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC64_GOT16_LO; |
| 1294 | break; |
| 1295 | case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC64_GOT16_HI; |
| 1296 | break; |
| 1297 | case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC64_GOT16_HA; |
| 1298 | break; |
| 1299 | case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC64_COPY; |
| 1300 | break; |
| 1301 | case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC64_GLOB_DAT; |
| 1302 | break; |
| 1303 | case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC64_REL32; |
| 1304 | break; |
| 1305 | case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC64_PLT32; |
| 1306 | break; |
| 1307 | case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL32; |
| 1308 | break; |
| 1309 | case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC64_PLT16_LO; |
| 1310 | break; |
| 1311 | case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC64_PLT16_HI; |
| 1312 | break; |
| 1313 | case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC64_PLT16_HA; |
| 1314 | break; |
| 1315 | case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC64_SECTOFF; |
| 1316 | break; |
| 1317 | case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_LO; |
| 1318 | break; |
| 1319 | case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HI; |
| 1320 | break; |
| 1321 | case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HA; |
| 1322 | break; |
| 1323 | case BFD_RELOC_CTOR: ppc_reloc = R_PPC64_ADDR64; |
| 1324 | break; |
| 1325 | case BFD_RELOC_64: ppc_reloc = R_PPC64_ADDR64; |
| 1326 | break; |
| 1327 | case BFD_RELOC_PPC64_HIGHER: ppc_reloc = R_PPC64_ADDR16_HIGHER; |
| 1328 | break; |
| 1329 | case BFD_RELOC_PPC64_HIGHER_S: ppc_reloc = R_PPC64_ADDR16_HIGHERA; |
| 1330 | break; |
| 1331 | case BFD_RELOC_PPC64_HIGHEST: ppc_reloc = R_PPC64_ADDR16_HIGHEST; |
| 1332 | break; |
| 1333 | case BFD_RELOC_PPC64_HIGHEST_S: ppc_reloc = R_PPC64_ADDR16_HIGHESTA; |
| 1334 | break; |
| 1335 | case BFD_RELOC_64_PCREL: ppc_reloc = R_PPC64_REL64; |
| 1336 | break; |
| 1337 | case BFD_RELOC_64_PLTOFF: ppc_reloc = R_PPC64_PLT64; |
| 1338 | break; |
| 1339 | case BFD_RELOC_64_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL64; |
| 1340 | break; |
| 1341 | case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC64_TOC16; |
| 1342 | break; |
| 1343 | case BFD_RELOC_PPC64_TOC16_LO: ppc_reloc = R_PPC64_TOC16_LO; |
| 1344 | break; |
| 1345 | case BFD_RELOC_PPC64_TOC16_HI: ppc_reloc = R_PPC64_TOC16_HI; |
| 1346 | break; |
| 1347 | case BFD_RELOC_PPC64_TOC16_HA: ppc_reloc = R_PPC64_TOC16_HA; |
| 1348 | break; |
| 1349 | case BFD_RELOC_PPC64_TOC: ppc_reloc = R_PPC64_TOC; |
| 1350 | break; |
| 1351 | case BFD_RELOC_PPC64_PLTGOT16: ppc_reloc = R_PPC64_PLTGOT16; |
| 1352 | break; |
| 1353 | case BFD_RELOC_PPC64_PLTGOT16_LO: ppc_reloc = R_PPC64_PLTGOT16_LO; |
| 1354 | break; |
| 1355 | case BFD_RELOC_PPC64_PLTGOT16_HI: ppc_reloc = R_PPC64_PLTGOT16_HI; |
| 1356 | break; |
| 1357 | case BFD_RELOC_PPC64_PLTGOT16_HA: ppc_reloc = R_PPC64_PLTGOT16_HA; |
| 1358 | break; |
| 1359 | case BFD_RELOC_PPC64_ADDR16_DS: ppc_reloc = R_PPC64_ADDR16_DS; |
| 1360 | break; |
| 1361 | case BFD_RELOC_PPC64_ADDR16_LO_DS: ppc_reloc = R_PPC64_ADDR16_LO_DS; |
| 1362 | break; |
| 1363 | case BFD_RELOC_PPC64_GOT16_DS: ppc_reloc = R_PPC64_GOT16_DS; |
| 1364 | break; |
| 1365 | case BFD_RELOC_PPC64_GOT16_LO_DS: ppc_reloc = R_PPC64_GOT16_LO_DS; |
| 1366 | break; |
| 1367 | case BFD_RELOC_PPC64_PLT16_LO_DS: ppc_reloc = R_PPC64_PLT16_LO_DS; |
| 1368 | break; |
| 1369 | case BFD_RELOC_PPC64_SECTOFF_DS: ppc_reloc = R_PPC64_SECTOFF_DS; |
| 1370 | break; |
| 1371 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: ppc_reloc = R_PPC64_SECTOFF_LO_DS; |
| 1372 | break; |
| 1373 | case BFD_RELOC_PPC64_TOC16_DS: ppc_reloc = R_PPC64_TOC16_DS; |
| 1374 | break; |
| 1375 | case BFD_RELOC_PPC64_TOC16_LO_DS: ppc_reloc = R_PPC64_TOC16_LO_DS; |
| 1376 | break; |
| 1377 | case BFD_RELOC_PPC64_PLTGOT16_DS: ppc_reloc = R_PPC64_PLTGOT16_DS; |
| 1378 | break; |
| 1379 | case BFD_RELOC_PPC64_PLTGOT16_LO_DS: ppc_reloc = R_PPC64_PLTGOT16_LO_DS; |
| 1380 | break; |
| 1381 | case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC64_GNU_VTINHERIT; |
| 1382 | break; |
| 1383 | case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC64_GNU_VTENTRY; |
| 1384 | break; |
| 1385 | } |
| 1386 | |
| 1387 | return ppc64_elf_howto_table[(int) ppc_reloc]; |
| 1388 | }; |
| 1389 | |
| 1390 | /* Set the howto pointer for a PowerPC ELF reloc. */ |
| 1391 | |
| 1392 | static void |
| 1393 | ppc64_elf_info_to_howto (abfd, cache_ptr, dst) |
| 1394 | bfd *abfd ATTRIBUTE_UNUSED; |
| 1395 | arelent *cache_ptr; |
| 1396 | Elf64_Internal_Rela *dst; |
| 1397 | { |
| 1398 | unsigned int type; |
| 1399 | |
| 1400 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
| 1401 | /* Initialize howto table if needed. */ |
| 1402 | ppc_howto_init (); |
| 1403 | |
| 1404 | type = ELF64_R_TYPE (dst->r_info); |
| 1405 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) |
| 1406 | / sizeof (ppc64_elf_howto_table[0]))); |
| 1407 | cache_ptr->howto = ppc64_elf_howto_table[type]; |
| 1408 | } |
| 1409 | |
| 1410 | /* Handle the R_PPC_ADDR16_HA and similar relocs. */ |
| 1411 | |
| 1412 | static bfd_reloc_status_type |
| 1413 | ppc64_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section, |
| 1414 | output_bfd, error_message) |
| 1415 | bfd *abfd ATTRIBUTE_UNUSED; |
| 1416 | arelent *reloc_entry; |
| 1417 | asymbol *symbol; |
| 1418 | PTR data ATTRIBUTE_UNUSED; |
| 1419 | asection *input_section; |
| 1420 | bfd *output_bfd; |
| 1421 | char **error_message ATTRIBUTE_UNUSED; |
| 1422 | { |
| 1423 | bfd_vma relocation; |
| 1424 | |
| 1425 | if (output_bfd != NULL) |
| 1426 | { |
| 1427 | reloc_entry->address += input_section->output_offset; |
| 1428 | return bfd_reloc_ok; |
| 1429 | } |
| 1430 | |
| 1431 | if (reloc_entry->address > input_section->_cooked_size) |
| 1432 | return bfd_reloc_outofrange; |
| 1433 | |
| 1434 | if (bfd_is_com_section (symbol->section)) |
| 1435 | relocation = 0; |
| 1436 | else |
| 1437 | relocation = symbol->value; |
| 1438 | |
| 1439 | relocation += symbol->section->output_section->vma; |
| 1440 | relocation += symbol->section->output_offset; |
| 1441 | relocation += reloc_entry->addend; |
| 1442 | |
| 1443 | reloc_entry->addend += (relocation & 0x8000) << 1; |
| 1444 | |
| 1445 | return bfd_reloc_continue; |
| 1446 | } |
| 1447 | |
| 1448 | /* Function to set whether a module needs the -mrelocatable bit set. */ |
| 1449 | |
| 1450 | static boolean |
| 1451 | ppc64_elf_set_private_flags (abfd, flags) |
| 1452 | bfd *abfd; |
| 1453 | flagword flags; |
| 1454 | { |
| 1455 | BFD_ASSERT (!elf_flags_init (abfd) |
| 1456 | || elf_elfheader (abfd)->e_flags == flags); |
| 1457 | |
| 1458 | elf_elfheader (abfd)->e_flags = flags; |
| 1459 | elf_flags_init (abfd) = true; |
| 1460 | return true; |
| 1461 | } |
| 1462 | |
| 1463 | /* Merge backend specific data from an object file to the output |
| 1464 | object file when linking. */ |
| 1465 | static boolean |
| 1466 | ppc64_elf_merge_private_bfd_data (ibfd, obfd) |
| 1467 | bfd *ibfd; |
| 1468 | bfd *obfd; |
| 1469 | { |
| 1470 | flagword old_flags; |
| 1471 | flagword new_flags; |
| 1472 | boolean error; |
| 1473 | |
| 1474 | /* Check if we have the same endianess. */ |
| 1475 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder |
| 1476 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
| 1477 | { |
| 1478 | const char *msg; |
| 1479 | |
| 1480 | if (bfd_big_endian (ibfd)) |
| 1481 | msg = _("%s: compiled for a big endian system and target is little endian"); |
| 1482 | else |
| 1483 | msg = _("%s: compiled for a little endian system and target is big endian"); |
| 1484 | |
| 1485 | (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd)); |
| 1486 | |
| 1487 | bfd_set_error (bfd_error_wrong_format); |
| 1488 | return false; |
| 1489 | } |
| 1490 | |
| 1491 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 1492 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 1493 | return true; |
| 1494 | |
| 1495 | new_flags = elf_elfheader (ibfd)->e_flags; |
| 1496 | old_flags = elf_elfheader (obfd)->e_flags; |
| 1497 | if (!elf_flags_init (obfd)) |
| 1498 | { |
| 1499 | /* First call, no flags set. */ |
| 1500 | elf_flags_init (obfd) = true; |
| 1501 | elf_elfheader (obfd)->e_flags = new_flags; |
| 1502 | } |
| 1503 | |
| 1504 | else if (new_flags == old_flags) |
| 1505 | /* Compatible flags are ok. */ |
| 1506 | ; |
| 1507 | |
| 1508 | else |
| 1509 | { |
| 1510 | /* Incompatible flags. Warn about -mrelocatable mismatch. |
| 1511 | Allow -mrelocatable-lib to be linked with either. */ |
| 1512 | error = false; |
| 1513 | if ((new_flags & EF_PPC_RELOCATABLE) != 0 |
| 1514 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) |
| 1515 | { |
| 1516 | error = true; |
| 1517 | (*_bfd_error_handler) |
| 1518 | (_("%s: compiled with -mrelocatable and linked with modules compiled normally"), |
| 1519 | bfd_archive_filename (ibfd)); |
| 1520 | } |
| 1521 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 |
| 1522 | && (old_flags & EF_PPC_RELOCATABLE) != 0) |
| 1523 | { |
| 1524 | error = true; |
| 1525 | (*_bfd_error_handler) |
| 1526 | (_("%s: compiled normally and linked with modules compiled with -mrelocatable"), |
| 1527 | bfd_archive_filename (ibfd)); |
| 1528 | } |
| 1529 | |
| 1530 | /* The output is -mrelocatable-lib iff both the input files are. */ |
| 1531 | if (! (new_flags & EF_PPC_RELOCATABLE_LIB)) |
| 1532 | elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB; |
| 1533 | |
| 1534 | /* The output is -mrelocatable iff it can't be -mrelocatable-lib, |
| 1535 | but each input file is either -mrelocatable or -mrelocatable-lib. */ |
| 1536 | if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB) |
| 1537 | && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)) |
| 1538 | && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))) |
| 1539 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE; |
| 1540 | |
| 1541 | /* Do not warn about eabi vs. V.4 mismatch, just or in the bit |
| 1542 | if any module uses it. */ |
| 1543 | elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB); |
| 1544 | |
| 1545 | new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); |
| 1546 | old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); |
| 1547 | |
| 1548 | /* Warn about any other mismatches. */ |
| 1549 | if (new_flags != old_flags) |
| 1550 | { |
| 1551 | error = true; |
| 1552 | (*_bfd_error_handler) |
| 1553 | (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"), |
| 1554 | bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags); |
| 1555 | } |
| 1556 | |
| 1557 | if (error) |
| 1558 | { |
| 1559 | bfd_set_error (bfd_error_bad_value); |
| 1560 | return false; |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | return true; |
| 1565 | } |
| 1566 | |
| 1567 | /* Handle a PowerPC specific section when reading an object file. This |
| 1568 | is called when elfcode.h finds a section with an unknown type. */ |
| 1569 | |
| 1570 | static boolean |
| 1571 | ppc64_elf_section_from_shdr (abfd, hdr, name) |
| 1572 | bfd *abfd; |
| 1573 | Elf64_Internal_Shdr *hdr; |
| 1574 | char *name; |
| 1575 | { |
| 1576 | asection *newsect; |
| 1577 | flagword flags; |
| 1578 | |
| 1579 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) |
| 1580 | return false; |
| 1581 | |
| 1582 | newsect = hdr->bfd_section; |
| 1583 | flags = bfd_get_section_flags (abfd, newsect); |
| 1584 | if (hdr->sh_flags & SHF_EXCLUDE) |
| 1585 | flags |= SEC_EXCLUDE; |
| 1586 | |
| 1587 | if (hdr->sh_type == SHT_ORDERED) |
| 1588 | flags |= SEC_SORT_ENTRIES; |
| 1589 | |
| 1590 | bfd_set_section_flags (abfd, newsect, flags); |
| 1591 | return true; |
| 1592 | } |
| 1593 | \f |
| 1594 | /* The following functions are specific to the ELF linker, while |
| 1595 | functions above are used generally. Those named ppc64_elf_* are |
| 1596 | called by the main ELF linker code. They appear in this file more |
| 1597 | or less in the order in which they are called. eg. |
| 1598 | ppc64_elf_check_relocs is called early in the link process, |
| 1599 | ppc64_elf_finish_dynamic_sections is one of the last functions |
| 1600 | called. |
| 1601 | |
| 1602 | PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that |
| 1603 | functions have both a function code symbol and a function descriptor |
| 1604 | symbol. A call to foo in a relocatable object file looks like: |
| 1605 | |
| 1606 | . .text |
| 1607 | . x: |
| 1608 | . bl .foo |
| 1609 | . nop |
| 1610 | |
| 1611 | The function definition in another object file might be: |
| 1612 | |
| 1613 | . .section .opd |
| 1614 | . foo: .quad .foo |
| 1615 | . .quad .TOC.@tocbase |
| 1616 | . .quad 0 |
| 1617 | . |
| 1618 | . .text |
| 1619 | . .foo: blr |
| 1620 | |
| 1621 | When the linker resolves the call during a static link, the branch |
| 1622 | unsurprisingly just goes to .foo and the .opd information is unused. |
| 1623 | If the function definition is in a shared library, things are a little |
| 1624 | different: The call goes via a plt call stub, the opd information gets |
| 1625 | copied to the plt, and the linker patches the nop. |
| 1626 | |
| 1627 | . x: |
| 1628 | . bl .foo_stub |
| 1629 | . ld 2,40(1) |
| 1630 | . |
| 1631 | . |
| 1632 | . .foo_stub: |
| 1633 | . addis 12,2,Lfoo@toc@ha # in practice, the call stub |
| 1634 | . addi 12,12,Lfoo@toc@l # is slightly optimised, but |
| 1635 | . std 2,40(1) # this is the general idea |
| 1636 | . ld 11,0(12) |
| 1637 | . ld 2,8(12) |
| 1638 | . mtctr 11 |
| 1639 | . ld 11,16(12) |
| 1640 | . bctr |
| 1641 | . |
| 1642 | . .section .plt |
| 1643 | . Lfoo: reloc (R_PPC64_JMP_SLOT, foo) |
| 1644 | |
| 1645 | The "reloc ()" notation is supposed to indicate that the linker emits |
| 1646 | an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd |
| 1647 | copying. |
| 1648 | |
| 1649 | What are the difficulties here? Well, firstly, the relocations |
| 1650 | examined by the linker in check_relocs are against the function code |
| 1651 | sym .foo, while the dynamic relocation in the plt is emitted against |
| 1652 | the function descriptor symbol, foo. Somewhere along the line, we need |
| 1653 | to carefully copy dynamic link information from one symbol to the other. |
| 1654 | Secondly, the generic part of the elf linker will make .foo a dynamic |
| 1655 | symbol as is normal for most other backends. We need foo dynamic |
| 1656 | instead, at least for an application final link. However, when |
| 1657 | creating a shared library containing foo, we need to have both symbols |
| 1658 | dynamic so that references to .foo are satisfied during the early |
| 1659 | stages of linking. Otherwise the linker might decide to pull in a |
| 1660 | definition from some other object, eg. a static library. */ |
| 1661 | |
| 1662 | /* The linker needs to keep track of the number of relocs that it |
| 1663 | decides to copy as dynamic relocs in check_relocs for each symbol. |
| 1664 | This is so that it can later discard them if they are found to be |
| 1665 | unnecessary. We store the information in a field extending the |
| 1666 | regular ELF linker hash table. */ |
| 1667 | |
| 1668 | struct ppc_dyn_relocs |
| 1669 | { |
| 1670 | struct ppc_dyn_relocs *next; |
| 1671 | |
| 1672 | /* The input section of the reloc. */ |
| 1673 | asection *sec; |
| 1674 | |
| 1675 | /* Total number of relocs copied for the input section. */ |
| 1676 | bfd_size_type count; |
| 1677 | |
| 1678 | /* Number of pc-relative relocs copied for the input section. */ |
| 1679 | bfd_size_type pc_count; |
| 1680 | }; |
| 1681 | |
| 1682 | /* Of those relocs that might be copied as dynamic relocs, this macro |
| 1683 | selects between relative and absolute types. */ |
| 1684 | |
| 1685 | #define IS_ABSOLUTE_RELOC(RTYPE) \ |
| 1686 | ((RTYPE) != R_PPC64_REL14 \ |
| 1687 | && (RTYPE) != R_PPC64_REL14_BRNTAKEN \ |
| 1688 | && (RTYPE) != R_PPC64_REL14_BRTAKEN \ |
| 1689 | && (RTYPE) != R_PPC64_REL24 \ |
| 1690 | && (RTYPE) != R_PPC64_REL32 \ |
| 1691 | && (RTYPE) != R_PPC64_REL64) |
| 1692 | |
| 1693 | /* ppc64 ELF linker hash entry. */ |
| 1694 | |
| 1695 | struct ppc_link_hash_entry |
| 1696 | { |
| 1697 | struct elf_link_hash_entry elf; |
| 1698 | |
| 1699 | /* Track dynamic relocs copied for this symbol. */ |
| 1700 | struct ppc_dyn_relocs *dyn_relocs; |
| 1701 | |
| 1702 | /* Flag function code and descriptor symbols. */ |
| 1703 | unsigned int is_func:1; |
| 1704 | unsigned int is_func_descriptor:1; |
| 1705 | }; |
| 1706 | |
| 1707 | /* ppc64 ELF linker hash table. */ |
| 1708 | |
| 1709 | struct ppc_link_hash_table |
| 1710 | { |
| 1711 | struct elf_link_hash_table elf; |
| 1712 | |
| 1713 | /* Short-cuts to get to dynamic linker sections. */ |
| 1714 | asection *sgot; |
| 1715 | asection *srelgot; |
| 1716 | asection *splt; |
| 1717 | asection *srelplt; |
| 1718 | asection *sdynbss; |
| 1719 | asection *srelbss; |
| 1720 | asection *sstub; |
| 1721 | asection *sglink; |
| 1722 | |
| 1723 | /* Set on error. */ |
| 1724 | int plt_overflow; |
| 1725 | |
| 1726 | /* Small local sym to section mapping cache. */ |
| 1727 | struct sym_sec_cache sym_sec; |
| 1728 | }; |
| 1729 | |
| 1730 | /* Get the ppc64 ELF linker hash table from a link_info structure. */ |
| 1731 | |
| 1732 | #define ppc_hash_table(p) \ |
| 1733 | ((struct ppc_link_hash_table *) ((p)->hash)) |
| 1734 | |
| 1735 | /* Create an entry in a ppc64 ELF linker hash table. */ |
| 1736 | |
| 1737 | static struct bfd_hash_entry * |
| 1738 | link_hash_newfunc (entry, table, string) |
| 1739 | struct bfd_hash_entry *entry; |
| 1740 | struct bfd_hash_table *table; |
| 1741 | const char *string; |
| 1742 | { |
| 1743 | /* Allocate the structure if it has not already been allocated by a |
| 1744 | subclass. */ |
| 1745 | if (entry == NULL) |
| 1746 | { |
| 1747 | entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry)); |
| 1748 | if (entry == NULL) |
| 1749 | return entry; |
| 1750 | } |
| 1751 | |
| 1752 | /* Call the allocation method of the superclass. */ |
| 1753 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); |
| 1754 | if (entry != NULL) |
| 1755 | { |
| 1756 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry; |
| 1757 | |
| 1758 | eh->dyn_relocs = NULL; |
| 1759 | eh->is_func = 0; |
| 1760 | eh->is_func_descriptor = 0; |
| 1761 | } |
| 1762 | |
| 1763 | return entry; |
| 1764 | } |
| 1765 | |
| 1766 | /* Create a ppc64 ELF linker hash table. */ |
| 1767 | |
| 1768 | static struct bfd_link_hash_table * |
| 1769 | ppc64_elf_link_hash_table_create (abfd) |
| 1770 | bfd *abfd; |
| 1771 | { |
| 1772 | struct ppc_link_hash_table *htab; |
| 1773 | bfd_size_type amt = sizeof (struct ppc_link_hash_table); |
| 1774 | |
| 1775 | htab = (struct ppc_link_hash_table *) bfd_alloc (abfd, amt); |
| 1776 | if (htab == NULL) |
| 1777 | return NULL; |
| 1778 | |
| 1779 | if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc)) |
| 1780 | { |
| 1781 | bfd_release (abfd, htab); |
| 1782 | return NULL; |
| 1783 | } |
| 1784 | |
| 1785 | htab->sgot = NULL; |
| 1786 | htab->srelgot = NULL; |
| 1787 | htab->splt = NULL; |
| 1788 | htab->srelplt = NULL; |
| 1789 | htab->sdynbss = NULL; |
| 1790 | htab->srelbss = NULL; |
| 1791 | htab->sstub = NULL; |
| 1792 | htab->sglink = NULL; |
| 1793 | htab->plt_overflow = 0; |
| 1794 | htab->sym_sec.abfd = NULL; |
| 1795 | |
| 1796 | return &htab->elf.root; |
| 1797 | } |
| 1798 | |
| 1799 | /* Create .got and .rela.got sections in DYNOBJ, and set up |
| 1800 | shortcuts to them in our hash table. */ |
| 1801 | |
| 1802 | static boolean |
| 1803 | create_got_section (dynobj, info) |
| 1804 | bfd *dynobj; |
| 1805 | struct bfd_link_info *info; |
| 1806 | { |
| 1807 | struct ppc_link_hash_table *htab; |
| 1808 | |
| 1809 | if (! _bfd_elf_create_got_section (dynobj, info)) |
| 1810 | return false; |
| 1811 | |
| 1812 | htab = ppc_hash_table (info); |
| 1813 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 1814 | if (!htab->sgot) |
| 1815 | abort (); |
| 1816 | |
| 1817 | htab->srelgot = bfd_make_section (dynobj, ".rela.got"); |
| 1818 | if (!htab->srelgot |
| 1819 | || ! bfd_set_section_flags (dynobj, htab->srelgot, |
| 1820 | (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS |
| 1821 | | SEC_IN_MEMORY | SEC_LINKER_CREATED |
| 1822 | | SEC_READONLY)) |
| 1823 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3)) |
| 1824 | return false; |
| 1825 | return true; |
| 1826 | } |
| 1827 | |
| 1828 | /* Create the .stub and .glink sections as well as the ordinary |
| 1829 | dynamic sections. */ |
| 1830 | |
| 1831 | static boolean |
| 1832 | ppc64_elf_create_dynamic_sections (dynobj, info) |
| 1833 | bfd *dynobj; |
| 1834 | struct bfd_link_info *info; |
| 1835 | { |
| 1836 | struct ppc_link_hash_table *htab; |
| 1837 | flagword flags; |
| 1838 | |
| 1839 | htab = ppc_hash_table (info); |
| 1840 | if (!htab->sgot && !create_got_section (dynobj, info)) |
| 1841 | return false; |
| 1842 | |
| 1843 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
| 1844 | return false; |
| 1845 | |
| 1846 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 1847 | htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt"); |
| 1848 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); |
| 1849 | if (!info->shared) |
| 1850 | htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss"); |
| 1851 | |
| 1852 | if (!htab->splt || !htab->srelplt || !htab->sdynbss |
| 1853 | || (!info->shared && !htab->srelbss)) |
| 1854 | abort (); |
| 1855 | |
| 1856 | /* Create .stub and .glink for global linkage functions. */ |
| 1857 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY |
| 1858 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); |
| 1859 | htab->sstub = bfd_make_section (dynobj, ".stub"); |
| 1860 | if (htab->sstub == NULL |
| 1861 | || ! bfd_set_section_flags (dynobj, htab->sstub, flags) |
| 1862 | || ! bfd_set_section_alignment (dynobj, htab->sstub, 2)) |
| 1863 | return false; |
| 1864 | htab->sglink = bfd_make_section (dynobj, ".glink"); |
| 1865 | if (htab->sglink == NULL |
| 1866 | || ! bfd_set_section_flags (dynobj, htab->sglink, flags) |
| 1867 | || ! bfd_set_section_alignment (dynobj, htab->sglink, 3)) |
| 1868 | return false; |
| 1869 | |
| 1870 | return true; |
| 1871 | } |
| 1872 | |
| 1873 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
| 1874 | |
| 1875 | static void |
| 1876 | ppc64_elf_copy_indirect_symbol (dir, ind) |
| 1877 | struct elf_link_hash_entry *dir, *ind; |
| 1878 | { |
| 1879 | struct ppc_link_hash_entry *edir, *eind; |
| 1880 | |
| 1881 | edir = (struct ppc_link_hash_entry *) dir; |
| 1882 | eind = (struct ppc_link_hash_entry *) ind; |
| 1883 | |
| 1884 | if (eind->dyn_relocs != NULL) |
| 1885 | { |
| 1886 | if (edir->dyn_relocs != NULL) |
| 1887 | { |
| 1888 | struct ppc_dyn_relocs **pp; |
| 1889 | struct ppc_dyn_relocs *p; |
| 1890 | |
| 1891 | if (ind->root.type == bfd_link_hash_indirect) |
| 1892 | abort (); |
| 1893 | |
| 1894 | /* Add reloc counts against the weak sym to the strong sym |
| 1895 | list. Merge any entries against the same section. */ |
| 1896 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) |
| 1897 | { |
| 1898 | struct ppc_dyn_relocs *q; |
| 1899 | |
| 1900 | for (q = edir->dyn_relocs; q != NULL; q = q->next) |
| 1901 | if (q->sec == p->sec) |
| 1902 | { |
| 1903 | q->pc_count += p->pc_count; |
| 1904 | q->count += p->count; |
| 1905 | *pp = p->next; |
| 1906 | break; |
| 1907 | } |
| 1908 | if (q == NULL) |
| 1909 | pp = &p->next; |
| 1910 | } |
| 1911 | *pp = edir->dyn_relocs; |
| 1912 | } |
| 1913 | |
| 1914 | edir->dyn_relocs = eind->dyn_relocs; |
| 1915 | eind->dyn_relocs = NULL; |
| 1916 | } |
| 1917 | |
| 1918 | edir->is_func |= eind->is_func; |
| 1919 | edir->is_func_descriptor |= eind->is_func_descriptor; |
| 1920 | |
| 1921 | _bfd_elf_link_hash_copy_indirect (dir, ind); |
| 1922 | } |
| 1923 | |
| 1924 | /* Look through the relocs for a section during the first phase, and |
| 1925 | calculate needed space in the global offset table, procedure |
| 1926 | linkage table, and dynamic reloc sections. */ |
| 1927 | |
| 1928 | static boolean |
| 1929 | ppc64_elf_check_relocs (abfd, info, sec, relocs) |
| 1930 | bfd *abfd; |
| 1931 | struct bfd_link_info *info; |
| 1932 | asection *sec; |
| 1933 | const Elf_Internal_Rela *relocs; |
| 1934 | { |
| 1935 | struct ppc_link_hash_table *htab; |
| 1936 | Elf_Internal_Shdr *symtab_hdr; |
| 1937 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; |
| 1938 | const Elf_Internal_Rela *rel; |
| 1939 | const Elf_Internal_Rela *rel_end; |
| 1940 | asection *sreloc; |
| 1941 | boolean is_opd; |
| 1942 | |
| 1943 | if (info->relocateable) |
| 1944 | return true; |
| 1945 | |
| 1946 | htab = ppc_hash_table (info); |
| 1947 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 1948 | |
| 1949 | sym_hashes = elf_sym_hashes (abfd); |
| 1950 | sym_hashes_end = (sym_hashes |
| 1951 | + symtab_hdr->sh_size / sizeof (Elf64_External_Sym)); |
| 1952 | if (!elf_bad_symtab (abfd)) |
| 1953 | sym_hashes_end -= symtab_hdr->sh_info; |
| 1954 | |
| 1955 | sreloc = NULL; |
| 1956 | is_opd = strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0; |
| 1957 | |
| 1958 | rel_end = relocs + sec->reloc_count; |
| 1959 | for (rel = relocs; rel < rel_end; rel++) |
| 1960 | { |
| 1961 | unsigned long r_symndx; |
| 1962 | struct elf_link_hash_entry *h; |
| 1963 | enum elf_ppc_reloc_type r_type; |
| 1964 | |
| 1965 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 1966 | if (r_symndx < symtab_hdr->sh_info) |
| 1967 | h = NULL; |
| 1968 | else |
| 1969 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 1970 | |
| 1971 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); |
| 1972 | switch (r_type) |
| 1973 | { |
| 1974 | /* GOT16 relocations */ |
| 1975 | case R_PPC64_GOT16: |
| 1976 | case R_PPC64_GOT16_DS: |
| 1977 | case R_PPC64_GOT16_HA: |
| 1978 | case R_PPC64_GOT16_HI: |
| 1979 | case R_PPC64_GOT16_LO: |
| 1980 | case R_PPC64_GOT16_LO_DS: |
| 1981 | |
| 1982 | /* This symbol requires a global offset table entry. */ |
| 1983 | if (htab->sgot == NULL) |
| 1984 | { |
| 1985 | if (htab->elf.dynobj == NULL) |
| 1986 | htab->elf.dynobj = abfd; |
| 1987 | if (!create_got_section (htab->elf.dynobj, info)) |
| 1988 | return false; |
| 1989 | } |
| 1990 | |
| 1991 | if (h != NULL) |
| 1992 | { |
| 1993 | h->got.refcount += 1; |
| 1994 | } |
| 1995 | else |
| 1996 | { |
| 1997 | bfd_signed_vma *local_got_refcounts; |
| 1998 | |
| 1999 | /* This is a global offset table entry for a local symbol. */ |
| 2000 | local_got_refcounts = elf_local_got_refcounts (abfd); |
| 2001 | if (local_got_refcounts == NULL) |
| 2002 | { |
| 2003 | bfd_size_type size; |
| 2004 | |
| 2005 | size = symtab_hdr->sh_info; |
| 2006 | size *= sizeof (bfd_signed_vma); |
| 2007 | local_got_refcounts = ((bfd_signed_vma *) |
| 2008 | bfd_zalloc (abfd, size)); |
| 2009 | if (local_got_refcounts == NULL) |
| 2010 | return false; |
| 2011 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
| 2012 | } |
| 2013 | local_got_refcounts[r_symndx] += 1; |
| 2014 | } |
| 2015 | break; |
| 2016 | |
| 2017 | case R_PPC64_PLT16_HA: |
| 2018 | case R_PPC64_PLT16_HI: |
| 2019 | case R_PPC64_PLT16_LO: |
| 2020 | case R_PPC64_PLT32: |
| 2021 | case R_PPC64_PLT64: |
| 2022 | /* This symbol requires a procedure linkage table entry. We |
| 2023 | actually build the entry in adjust_dynamic_symbol, |
| 2024 | because this might be a case of linking PIC code without |
| 2025 | linking in any dynamic objects, in which case we don't |
| 2026 | need to generate a procedure linkage table after all. */ |
| 2027 | if (h == NULL) |
| 2028 | { |
| 2029 | /* It does not make sense to have a procedure linkage |
| 2030 | table entry for a local symbol. */ |
| 2031 | bfd_set_error (bfd_error_bad_value); |
| 2032 | return false; |
| 2033 | } |
| 2034 | |
| 2035 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
| 2036 | h->plt.refcount += 1; |
| 2037 | ((struct ppc_link_hash_entry *) h)->is_func = 1; |
| 2038 | break; |
| 2039 | |
| 2040 | /* The following relocations don't need to propagate the |
| 2041 | relocation if linking a shared object since they are |
| 2042 | section relative. */ |
| 2043 | case R_PPC64_SECTOFF: |
| 2044 | case R_PPC64_SECTOFF_LO: |
| 2045 | case R_PPC64_SECTOFF_HI: |
| 2046 | case R_PPC64_SECTOFF_HA: |
| 2047 | case R_PPC64_SECTOFF_DS: |
| 2048 | case R_PPC64_SECTOFF_LO_DS: |
| 2049 | case R_PPC64_TOC16: |
| 2050 | case R_PPC64_TOC16_LO: |
| 2051 | case R_PPC64_TOC16_HI: |
| 2052 | case R_PPC64_TOC16_HA: |
| 2053 | case R_PPC64_TOC16_DS: |
| 2054 | case R_PPC64_TOC16_LO_DS: |
| 2055 | break; |
| 2056 | |
| 2057 | /* This relocation describes the C++ object vtable hierarchy. |
| 2058 | Reconstruct it for later use during GC. */ |
| 2059 | case R_PPC64_GNU_VTINHERIT: |
| 2060 | if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
| 2061 | return false; |
| 2062 | break; |
| 2063 | |
| 2064 | /* This relocation describes which C++ vtable entries are actually |
| 2065 | used. Record for later use during GC. */ |
| 2066 | case R_PPC64_GNU_VTENTRY: |
| 2067 | if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
| 2068 | return false; |
| 2069 | break; |
| 2070 | |
| 2071 | case R_PPC64_REL24: |
| 2072 | if (h != NULL |
| 2073 | && h->root.root.string[0] == '.' |
| 2074 | && h->root.root.string[1] != 0) |
| 2075 | { |
| 2076 | /* We may need a .plt entry if the function this reloc |
| 2077 | refers to is in a shared lib. */ |
| 2078 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
| 2079 | h->plt.refcount += 1; |
| 2080 | ((struct ppc_link_hash_entry *) h)->is_func = 1; |
| 2081 | } |
| 2082 | break; |
| 2083 | |
| 2084 | case R_PPC64_ADDR64: |
| 2085 | if (is_opd |
| 2086 | && h != NULL |
| 2087 | && h->root.root.string[0] == '.' |
| 2088 | && h->root.root.string[1] != 0) |
| 2089 | { |
| 2090 | struct elf_link_hash_entry *fdh; |
| 2091 | |
| 2092 | fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1, |
| 2093 | false, false, false); |
| 2094 | if (fdh != NULL) |
| 2095 | { |
| 2096 | /* Ensure the function descriptor symbol string is |
| 2097 | part of the code symbol string. We aren't |
| 2098 | changing the name here, just allowing some tricks |
| 2099 | in ppc64_elf_hide_symbol. */ |
| 2100 | fdh->root.root.string = h->root.root.string + 1; |
| 2101 | ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1; |
| 2102 | ((struct ppc_link_hash_entry *) h)->is_func = 1; |
| 2103 | } |
| 2104 | } |
| 2105 | /* Fall through. */ |
| 2106 | |
| 2107 | case R_PPC64_REL64: |
| 2108 | case R_PPC64_REL32: |
| 2109 | case R_PPC64_REL14: |
| 2110 | case R_PPC64_REL14_BRTAKEN: |
| 2111 | case R_PPC64_REL14_BRNTAKEN: |
| 2112 | case R_PPC64_ADDR14: |
| 2113 | case R_PPC64_ADDR14_BRNTAKEN: |
| 2114 | case R_PPC64_ADDR14_BRTAKEN: |
| 2115 | case R_PPC64_ADDR16: |
| 2116 | case R_PPC64_ADDR16_DS: |
| 2117 | case R_PPC64_ADDR16_HA: |
| 2118 | case R_PPC64_ADDR16_HI: |
| 2119 | case R_PPC64_ADDR16_HIGHER: |
| 2120 | case R_PPC64_ADDR16_HIGHERA: |
| 2121 | case R_PPC64_ADDR16_HIGHEST: |
| 2122 | case R_PPC64_ADDR16_HIGHESTA: |
| 2123 | case R_PPC64_ADDR16_LO: |
| 2124 | case R_PPC64_ADDR16_LO_DS: |
| 2125 | case R_PPC64_ADDR24: |
| 2126 | case R_PPC64_ADDR30: |
| 2127 | case R_PPC64_ADDR32: |
| 2128 | case R_PPC64_UADDR16: |
| 2129 | case R_PPC64_UADDR32: |
| 2130 | case R_PPC64_UADDR64: |
| 2131 | case R_PPC64_TOC: |
| 2132 | /* Don't propagate .opd relocs. */ |
| 2133 | if (NO_OPD_RELOCS && is_opd) |
| 2134 | break; |
| 2135 | |
| 2136 | /* If we are creating a shared library, and this is a reloc |
| 2137 | against a global symbol, or a non PC relative reloc |
| 2138 | against a local symbol, then we need to copy the reloc |
| 2139 | into the shared library. However, if we are linking with |
| 2140 | -Bsymbolic, we do not need to copy a reloc against a |
| 2141 | global symbol which is defined in an object we are |
| 2142 | including in the link (i.e., DEF_REGULAR is set). At |
| 2143 | this point we have not seen all the input files, so it is |
| 2144 | possible that DEF_REGULAR is not set now but will be set |
| 2145 | later (it is never cleared). In case of a weak definition, |
| 2146 | DEF_REGULAR may be cleared later by a strong definition in |
| 2147 | a shared library. We account for that possibility below by |
| 2148 | storing information in the relocs_copied field of the hash |
| 2149 | table entry. A similar situation occurs when creating |
| 2150 | shared libraries and symbol visibility changes render the |
| 2151 | symbol local. |
| 2152 | |
| 2153 | If on the other hand, we are creating an executable, we |
| 2154 | may need to keep relocations for symbols satisfied by a |
| 2155 | dynamic library if we manage to avoid copy relocs for the |
| 2156 | symbol. */ |
| 2157 | if ((info->shared |
| 2158 | && (sec->flags & SEC_ALLOC) != 0 |
| 2159 | && (IS_ABSOLUTE_RELOC (r_type) |
| 2160 | || (h != NULL |
| 2161 | && (! info->symbolic |
| 2162 | || h->root.type == bfd_link_hash_defweak |
| 2163 | || (h->elf_link_hash_flags |
| 2164 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) |
| 2165 | || (!info->shared |
| 2166 | && (sec->flags & SEC_ALLOC) != 0 |
| 2167 | && h != NULL |
| 2168 | && (h->root.type == bfd_link_hash_defweak |
| 2169 | || (h->elf_link_hash_flags |
| 2170 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) |
| 2171 | { |
| 2172 | struct ppc_dyn_relocs *p; |
| 2173 | struct ppc_dyn_relocs **head; |
| 2174 | |
| 2175 | /* We must copy these reloc types into the output file. |
| 2176 | Create a reloc section in dynobj and make room for |
| 2177 | this reloc. */ |
| 2178 | if (sreloc == NULL) |
| 2179 | { |
| 2180 | const char *name; |
| 2181 | bfd *dynobj; |
| 2182 | |
| 2183 | name = (bfd_elf_string_from_elf_section |
| 2184 | (abfd, |
| 2185 | elf_elfheader (abfd)->e_shstrndx, |
| 2186 | elf_section_data (sec)->rel_hdr.sh_name)); |
| 2187 | if (name == NULL) |
| 2188 | return false; |
| 2189 | |
| 2190 | if (strncmp (name, ".rela", 5) != 0 |
| 2191 | || strcmp (bfd_get_section_name (abfd, sec), |
| 2192 | name + 5) != 0) |
| 2193 | { |
| 2194 | (*_bfd_error_handler) |
| 2195 | (_("%s: bad relocation section name `%s\'"), |
| 2196 | bfd_archive_filename (abfd), name); |
| 2197 | bfd_set_error (bfd_error_bad_value); |
| 2198 | } |
| 2199 | |
| 2200 | if (htab->elf.dynobj == NULL) |
| 2201 | htab->elf.dynobj = abfd; |
| 2202 | |
| 2203 | dynobj = htab->elf.dynobj; |
| 2204 | sreloc = bfd_get_section_by_name (dynobj, name); |
| 2205 | if (sreloc == NULL) |
| 2206 | { |
| 2207 | flagword flags; |
| 2208 | |
| 2209 | sreloc = bfd_make_section (dynobj, name); |
| 2210 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
| 2211 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); |
| 2212 | if ((sec->flags & SEC_ALLOC) != 0) |
| 2213 | flags |= SEC_ALLOC | SEC_LOAD; |
| 2214 | if (sreloc == NULL |
| 2215 | || ! bfd_set_section_flags (dynobj, sreloc, flags) |
| 2216 | || ! bfd_set_section_alignment (dynobj, sreloc, 3)) |
| 2217 | return false; |
| 2218 | } |
| 2219 | elf_section_data (sec)->sreloc = sreloc; |
| 2220 | } |
| 2221 | |
| 2222 | /* If this is a global symbol, we count the number of |
| 2223 | relocations we need for this symbol. */ |
| 2224 | if (h != NULL) |
| 2225 | { |
| 2226 | head = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
| 2227 | } |
| 2228 | else |
| 2229 | { |
| 2230 | /* Track dynamic relocs needed for local syms too. |
| 2231 | We really need local syms available to do this |
| 2232 | easily. Oh well. */ |
| 2233 | |
| 2234 | asection *s; |
| 2235 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, |
| 2236 | sec, r_symndx); |
| 2237 | if (s == NULL) |
| 2238 | return false; |
| 2239 | |
| 2240 | head = ((struct ppc_dyn_relocs **) |
| 2241 | &elf_section_data (s)->local_dynrel); |
| 2242 | } |
| 2243 | |
| 2244 | p = *head; |
| 2245 | if (p == NULL || p->sec != sec) |
| 2246 | { |
| 2247 | p = ((struct ppc_dyn_relocs *) |
| 2248 | bfd_alloc (htab->elf.dynobj, |
| 2249 | (bfd_size_type) sizeof *p)); |
| 2250 | if (p == NULL) |
| 2251 | return false; |
| 2252 | p->next = *head; |
| 2253 | *head = p; |
| 2254 | p->sec = sec; |
| 2255 | p->count = 0; |
| 2256 | p->pc_count = 0; |
| 2257 | } |
| 2258 | |
| 2259 | p->count += 1; |
| 2260 | if (!IS_ABSOLUTE_RELOC (r_type)) |
| 2261 | p->pc_count += 1; |
| 2262 | } |
| 2263 | break; |
| 2264 | |
| 2265 | default: |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | return true; |
| 2270 | } |
| 2271 | |
| 2272 | /* Return the section that should be marked against GC for a given |
| 2273 | relocation. */ |
| 2274 | |
| 2275 | static asection * |
| 2276 | ppc64_elf_gc_mark_hook (abfd, info, rel, h, sym) |
| 2277 | bfd *abfd; |
| 2278 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
| 2279 | Elf_Internal_Rela *rel; |
| 2280 | struct elf_link_hash_entry *h; |
| 2281 | Elf_Internal_Sym *sym; |
| 2282 | { |
| 2283 | if (h != NULL) |
| 2284 | { |
| 2285 | enum elf_ppc_reloc_type r_type; |
| 2286 | |
| 2287 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); |
| 2288 | switch (r_type) |
| 2289 | { |
| 2290 | case R_PPC64_GNU_VTINHERIT: |
| 2291 | case R_PPC64_GNU_VTENTRY: |
| 2292 | break; |
| 2293 | |
| 2294 | default: |
| 2295 | switch (h->root.type) |
| 2296 | { |
| 2297 | case bfd_link_hash_defined: |
| 2298 | case bfd_link_hash_defweak: |
| 2299 | return h->root.u.def.section; |
| 2300 | |
| 2301 | case bfd_link_hash_common: |
| 2302 | return h->root.u.c.p->section; |
| 2303 | |
| 2304 | default: |
| 2305 | break; |
| 2306 | } |
| 2307 | } |
| 2308 | } |
| 2309 | else |
| 2310 | { |
| 2311 | return bfd_section_from_elf_index (abfd, sym->st_shndx); |
| 2312 | } |
| 2313 | |
| 2314 | return NULL; |
| 2315 | } |
| 2316 | |
| 2317 | /* Update the .got, .plt. and dynamic reloc reference counts for the |
| 2318 | section being removed. */ |
| 2319 | |
| 2320 | static boolean |
| 2321 | ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs) |
| 2322 | bfd *abfd; |
| 2323 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
| 2324 | asection *sec; |
| 2325 | const Elf_Internal_Rela *relocs; |
| 2326 | { |
| 2327 | Elf_Internal_Shdr *symtab_hdr; |
| 2328 | struct elf_link_hash_entry **sym_hashes; |
| 2329 | bfd_signed_vma *local_got_refcounts; |
| 2330 | const Elf_Internal_Rela *rel, *relend; |
| 2331 | |
| 2332 | elf_section_data (sec)->local_dynrel = NULL; |
| 2333 | |
| 2334 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 2335 | sym_hashes = elf_sym_hashes (abfd); |
| 2336 | local_got_refcounts = elf_local_got_refcounts (abfd); |
| 2337 | |
| 2338 | relend = relocs + sec->reloc_count; |
| 2339 | for (rel = relocs; rel < relend; rel++) |
| 2340 | { |
| 2341 | unsigned long r_symndx; |
| 2342 | enum elf_ppc_reloc_type r_type; |
| 2343 | struct elf_link_hash_entry *h; |
| 2344 | |
| 2345 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 2346 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); |
| 2347 | switch (r_type) |
| 2348 | { |
| 2349 | case R_PPC64_GOT16: |
| 2350 | case R_PPC64_GOT16_DS: |
| 2351 | case R_PPC64_GOT16_HA: |
| 2352 | case R_PPC64_GOT16_HI: |
| 2353 | case R_PPC64_GOT16_LO: |
| 2354 | case R_PPC64_GOT16_LO_DS: |
| 2355 | if (r_symndx >= symtab_hdr->sh_info) |
| 2356 | { |
| 2357 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 2358 | if (h->got.refcount > 0) |
| 2359 | h->got.refcount--; |
| 2360 | } |
| 2361 | else |
| 2362 | { |
| 2363 | if (local_got_refcounts[r_symndx] > 0) |
| 2364 | local_got_refcounts[r_symndx]--; |
| 2365 | } |
| 2366 | break; |
| 2367 | |
| 2368 | case R_PPC64_PLT16_HA: |
| 2369 | case R_PPC64_PLT16_HI: |
| 2370 | case R_PPC64_PLT16_LO: |
| 2371 | case R_PPC64_PLT32: |
| 2372 | case R_PPC64_PLT64: |
| 2373 | if (r_symndx >= symtab_hdr->sh_info) |
| 2374 | { |
| 2375 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 2376 | if (h->plt.refcount > 0) |
| 2377 | h->plt.refcount--; |
| 2378 | } |
| 2379 | break; |
| 2380 | |
| 2381 | case R_PPC64_REL24: |
| 2382 | if (r_symndx >= symtab_hdr->sh_info) |
| 2383 | { |
| 2384 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 2385 | if (h->plt.refcount > 0) |
| 2386 | h->plt.refcount--; |
| 2387 | } |
| 2388 | break; |
| 2389 | |
| 2390 | case R_PPC64_REL14: |
| 2391 | case R_PPC64_REL14_BRNTAKEN: |
| 2392 | case R_PPC64_REL14_BRTAKEN: |
| 2393 | case R_PPC64_REL32: |
| 2394 | case R_PPC64_REL64: |
| 2395 | if (r_symndx >= symtab_hdr->sh_info) |
| 2396 | { |
| 2397 | struct ppc_link_hash_entry *eh; |
| 2398 | struct ppc_dyn_relocs **pp; |
| 2399 | struct ppc_dyn_relocs *p; |
| 2400 | |
| 2401 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 2402 | eh = (struct ppc_link_hash_entry *) h; |
| 2403 | |
| 2404 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) |
| 2405 | if (p->sec == sec) |
| 2406 | { |
| 2407 | p->pc_count -= 1; |
| 2408 | p->count -= 1; |
| 2409 | if (p->count == 0) |
| 2410 | *pp = p->next; |
| 2411 | break; |
| 2412 | } |
| 2413 | } |
| 2414 | break; |
| 2415 | |
| 2416 | case R_PPC64_ADDR14: |
| 2417 | case R_PPC64_ADDR14_BRNTAKEN: |
| 2418 | case R_PPC64_ADDR14_BRTAKEN: |
| 2419 | case R_PPC64_ADDR16: |
| 2420 | case R_PPC64_ADDR16_DS: |
| 2421 | case R_PPC64_ADDR16_HA: |
| 2422 | case R_PPC64_ADDR16_HI: |
| 2423 | case R_PPC64_ADDR16_HIGHER: |
| 2424 | case R_PPC64_ADDR16_HIGHERA: |
| 2425 | case R_PPC64_ADDR16_HIGHEST: |
| 2426 | case R_PPC64_ADDR16_HIGHESTA: |
| 2427 | case R_PPC64_ADDR16_LO: |
| 2428 | case R_PPC64_ADDR16_LO_DS: |
| 2429 | case R_PPC64_ADDR24: |
| 2430 | case R_PPC64_ADDR30: |
| 2431 | case R_PPC64_ADDR32: |
| 2432 | case R_PPC64_ADDR64: |
| 2433 | case R_PPC64_UADDR16: |
| 2434 | case R_PPC64_UADDR32: |
| 2435 | case R_PPC64_UADDR64: |
| 2436 | case R_PPC64_TOC: |
| 2437 | if (r_symndx >= symtab_hdr->sh_info) |
| 2438 | { |
| 2439 | struct ppc_link_hash_entry *eh; |
| 2440 | struct ppc_dyn_relocs **pp; |
| 2441 | struct ppc_dyn_relocs *p; |
| 2442 | |
| 2443 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 2444 | eh = (struct ppc_link_hash_entry *) h; |
| 2445 | |
| 2446 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) |
| 2447 | if (p->sec == sec) |
| 2448 | { |
| 2449 | p->count -= 1; |
| 2450 | if (p->count == 0) |
| 2451 | *pp = p->next; |
| 2452 | break; |
| 2453 | } |
| 2454 | } |
| 2455 | break; |
| 2456 | |
| 2457 | default: |
| 2458 | break; |
| 2459 | } |
| 2460 | } |
| 2461 | return true; |
| 2462 | } |
| 2463 | |
| 2464 | /* Called via elf_link_hash_traverse to transfer dynamic linking |
| 2465 | information on function code symbol entries to their corresponding |
| 2466 | function descriptor symbol entries. */ |
| 2467 | static boolean |
| 2468 | func_desc_adjust (h, inf) |
| 2469 | struct elf_link_hash_entry *h; |
| 2470 | PTR inf; |
| 2471 | { |
| 2472 | struct bfd_link_info *info; |
| 2473 | struct ppc_link_hash_table *htab; |
| 2474 | |
| 2475 | if (h->root.type == bfd_link_hash_indirect |
| 2476 | || h->root.type == bfd_link_hash_warning) |
| 2477 | return true; |
| 2478 | |
| 2479 | info = (struct bfd_link_info *) inf; |
| 2480 | htab = ppc_hash_table (info); |
| 2481 | |
| 2482 | /* If this is a function code symbol, transfer dynamic linking |
| 2483 | information to the function descriptor symbol. */ |
| 2484 | if (!((struct ppc_link_hash_entry *) h)->is_func) |
| 2485 | return true; |
| 2486 | |
| 2487 | if (h->plt.refcount > 0 |
| 2488 | && h->root.root.string[0] == '.' |
| 2489 | && h->root.root.string[1] != '\0') |
| 2490 | { |
| 2491 | struct elf_link_hash_entry *fdh; |
| 2492 | boolean force_local; |
| 2493 | |
| 2494 | /* Find the corresponding function descriptor symbol. Create it |
| 2495 | as undefined if necessary. */ |
| 2496 | |
| 2497 | fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1, |
| 2498 | false, false, true); |
| 2499 | |
| 2500 | if (fdh == NULL |
| 2501 | && info->shared |
| 2502 | && (h->root.type == bfd_link_hash_undefined |
| 2503 | || h->root.type == bfd_link_hash_undefweak)) |
| 2504 | { |
| 2505 | bfd *abfd; |
| 2506 | asymbol *newsym; |
| 2507 | |
| 2508 | abfd = h->root.u.undef.abfd; |
| 2509 | newsym = bfd_make_empty_symbol (abfd); |
| 2510 | newsym->name = h->root.root.string + 1; |
| 2511 | newsym->section = bfd_und_section_ptr; |
| 2512 | newsym->value = 0; |
| 2513 | newsym->flags = BSF_OBJECT; |
| 2514 | if (h->root.type == bfd_link_hash_undefweak) |
| 2515 | newsym->flags |= BSF_WEAK; |
| 2516 | |
| 2517 | if ( !(_bfd_generic_link_add_one_symbol |
| 2518 | (info, abfd, newsym->name, newsym->flags, |
| 2519 | newsym->section, newsym->value, NULL, false, false, |
| 2520 | (struct bfd_link_hash_entry **) &fdh))) |
| 2521 | { |
| 2522 | return false; |
| 2523 | } |
| 2524 | fdh->elf_link_hash_flags &= ~ELF_LINK_NON_ELF; |
| 2525 | } |
| 2526 | |
| 2527 | if (fdh != NULL |
| 2528 | && (fdh->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 |
| 2529 | && (info->shared |
| 2530 | || (fdh->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
| 2531 | || (fdh->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)) |
| 2532 | { |
| 2533 | if (fdh->dynindx == -1) |
| 2534 | if (! bfd_elf64_link_record_dynamic_symbol (info, fdh)) |
| 2535 | return false; |
| 2536 | fdh->elf_link_hash_flags |= (h->elf_link_hash_flags |
| 2537 | & (ELF_LINK_HASH_REF_REGULAR |
| 2538 | | ELF_LINK_HASH_REF_DYNAMIC |
| 2539 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK |
| 2540 | | ELF_LINK_NON_GOT_REF)); |
| 2541 | if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
| 2542 | { |
| 2543 | fdh->plt.refcount = h->plt.refcount; |
| 2544 | fdh->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
| 2545 | } |
| 2546 | ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1; |
| 2547 | fdh->root.root.string = h->root.root.string + 1; |
| 2548 | } |
| 2549 | |
| 2550 | /* Now that the info is on the function descriptor, clear the |
| 2551 | function code sym info. Any function code syms for which we |
| 2552 | don't have a definition in a regular file, we force local. |
| 2553 | This prevents a shared library from exporting syms that have |
| 2554 | been imported from another library. Function code syms that |
| 2555 | are really in the library we must leave global to prevent the |
| 2556 | linker dragging in a definition from a static library. */ |
| 2557 | force_local = (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0; |
| 2558 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); |
| 2559 | } |
| 2560 | |
| 2561 | return true; |
| 2562 | } |
| 2563 | |
| 2564 | /* Called near the start of bfd_elf_size_dynamic_sections. We use |
| 2565 | this hook to transfer dynamic linking information gathered so far |
| 2566 | on function code symbol entries, to their corresponding function |
| 2567 | descriptor symbol entries. */ |
| 2568 | static boolean |
| 2569 | ppc64_elf_func_desc_adjust (obfd, info) |
| 2570 | bfd *obfd ATTRIBUTE_UNUSED; |
| 2571 | struct bfd_link_info *info; |
| 2572 | { |
| 2573 | struct ppc_link_hash_table *htab; |
| 2574 | |
| 2575 | htab = ppc_hash_table (info); |
| 2576 | elf_link_hash_traverse (&htab->elf, func_desc_adjust, (PTR) info); |
| 2577 | return true; |
| 2578 | } |
| 2579 | |
| 2580 | /* Adjust a symbol defined by a dynamic object and referenced by a |
| 2581 | regular object. The current definition is in some section of the |
| 2582 | dynamic object, but we're not including those sections. We have to |
| 2583 | change the definition to something the rest of the link can |
| 2584 | understand. */ |
| 2585 | |
| 2586 | static boolean |
| 2587 | ppc64_elf_adjust_dynamic_symbol (info, h) |
| 2588 | struct bfd_link_info *info; |
| 2589 | struct elf_link_hash_entry *h; |
| 2590 | { |
| 2591 | struct ppc_link_hash_table *htab; |
| 2592 | struct ppc_link_hash_entry * eh; |
| 2593 | struct ppc_dyn_relocs *p; |
| 2594 | asection *s; |
| 2595 | unsigned int power_of_two; |
| 2596 | |
| 2597 | htab = ppc_hash_table (info); |
| 2598 | |
| 2599 | /* Deal with function syms. */ |
| 2600 | if (h->type == STT_FUNC |
| 2601 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) |
| 2602 | { |
| 2603 | /* Clear procedure linkage table information for any symbol that |
| 2604 | won't need a .plt entry. */ |
| 2605 | if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor |
| 2606 | || h->plt.refcount <= 0 |
| 2607 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 |
| 2608 | || (! info->shared |
| 2609 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 |
| 2610 | && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)) |
| 2611 | { |
| 2612 | h->plt.offset = (bfd_vma) -1; |
| 2613 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
| 2614 | } |
| 2615 | return true; |
| 2616 | } |
| 2617 | else |
| 2618 | h->plt.offset = (bfd_vma) -1; |
| 2619 | |
| 2620 | /* If this is a weak symbol, and there is a real definition, the |
| 2621 | processor independent code will have arranged for us to see the |
| 2622 | real definition first, and we can just use the same value. */ |
| 2623 | if (h->weakdef != NULL) |
| 2624 | { |
| 2625 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined |
| 2626 | || h->weakdef->root.type == bfd_link_hash_defweak); |
| 2627 | h->root.u.def.section = h->weakdef->root.u.def.section; |
| 2628 | h->root.u.def.value = h->weakdef->root.u.def.value; |
| 2629 | return true; |
| 2630 | } |
| 2631 | |
| 2632 | /* This is a reference to a symbol defined by a dynamic object which |
| 2633 | is not a function. */ |
| 2634 | |
| 2635 | /* If we are creating a shared library, we must presume that the |
| 2636 | only references to the symbol are via the global offset table. |
| 2637 | For such cases we need not do anything here; the relocations will |
| 2638 | be handled correctly by relocate_section. */ |
| 2639 | if (info->shared) |
| 2640 | return true; |
| 2641 | |
| 2642 | /* If there are no references to this symbol that do not use the |
| 2643 | GOT, we don't need to generate a copy reloc. */ |
| 2644 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) |
| 2645 | return true; |
| 2646 | |
| 2647 | eh = (struct ppc_link_hash_entry *) h; |
| 2648 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
| 2649 | { |
| 2650 | s = p->sec->output_section; |
| 2651 | if (s != NULL && (s->flags & SEC_READONLY) != 0) |
| 2652 | break; |
| 2653 | } |
| 2654 | |
| 2655 | /* If we didn't find any dynamic relocs in read-only sections, then |
| 2656 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ |
| 2657 | if (p == NULL) |
| 2658 | { |
| 2659 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; |
| 2660 | return true; |
| 2661 | } |
| 2662 | |
| 2663 | /* We must allocate the symbol in our .dynbss section, which will |
| 2664 | become part of the .bss section of the executable. There will be |
| 2665 | an entry for this symbol in the .dynsym section. The dynamic |
| 2666 | object will contain position independent code, so all references |
| 2667 | from the dynamic object to this symbol will go through the global |
| 2668 | offset table. The dynamic linker will use the .dynsym entry to |
| 2669 | determine the address it must put in the global offset table, so |
| 2670 | both the dynamic object and the regular object will refer to the |
| 2671 | same memory location for the variable. */ |
| 2672 | |
| 2673 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to |
| 2674 | copy the initial value out of the dynamic object and into the |
| 2675 | runtime process image. We need to remember the offset into the |
| 2676 | .rela.bss section we are going to use. */ |
| 2677 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
| 2678 | { |
| 2679 | htab->srelbss->_raw_size += sizeof (Elf64_External_Rela); |
| 2680 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
| 2681 | } |
| 2682 | |
| 2683 | /* We need to figure out the alignment required for this symbol. I |
| 2684 | have no idea how ELF linkers handle this. */ |
| 2685 | power_of_two = bfd_log2 (h->size); |
| 2686 | if (power_of_two > 4) |
| 2687 | power_of_two = 4; |
| 2688 | |
| 2689 | /* Apply the required alignment. */ |
| 2690 | s = htab->sdynbss; |
| 2691 | s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two)); |
| 2692 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) |
| 2693 | { |
| 2694 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
| 2695 | return false; |
| 2696 | } |
| 2697 | |
| 2698 | /* Define the symbol as being at this point in the section. */ |
| 2699 | h->root.u.def.section = s; |
| 2700 | h->root.u.def.value = s->_raw_size; |
| 2701 | |
| 2702 | /* Increment the section size to make room for the symbol. */ |
| 2703 | s->_raw_size += h->size; |
| 2704 | |
| 2705 | return true; |
| 2706 | } |
| 2707 | |
| 2708 | /* If given a function descriptor symbol, hide both the function code |
| 2709 | sym and the descriptor. */ |
| 2710 | static void |
| 2711 | ppc64_elf_hide_symbol (info, h, force_local) |
| 2712 | struct bfd_link_info *info; |
| 2713 | struct elf_link_hash_entry *h; |
| 2714 | boolean force_local; |
| 2715 | { |
| 2716 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); |
| 2717 | |
| 2718 | if (((struct ppc_link_hash_entry *) h)->is_func_descriptor) |
| 2719 | { |
| 2720 | const char *name; |
| 2721 | struct elf_link_hash_entry *fh; |
| 2722 | struct ppc_link_hash_table *htab; |
| 2723 | |
| 2724 | name = h->root.root.string - 1; |
| 2725 | htab = ppc_hash_table (info); |
| 2726 | fh = elf_link_hash_lookup (&htab->elf, name, false, false, false); |
| 2727 | if (fh != NULL) |
| 2728 | _bfd_elf_link_hash_hide_symbol (info, fh, force_local); |
| 2729 | } |
| 2730 | } |
| 2731 | |
| 2732 | /* This is the condition under which ppc64_elf_finish_dynamic_symbol |
| 2733 | will be called from elflink.h. If elflink.h doesn't call our |
| 2734 | finish_dynamic_symbol routine, we'll need to do something about |
| 2735 | initializing any .plt and .got entries in ppc64_elf_relocate_section. */ |
| 2736 | #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \ |
| 2737 | ((DYN) \ |
| 2738 | && ((INFO)->shared \ |
| 2739 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ |
| 2740 | && ((H)->dynindx != -1 \ |
| 2741 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) |
| 2742 | |
| 2743 | /* Allocate space in .plt, .got and associated reloc sections for |
| 2744 | dynamic relocs. */ |
| 2745 | |
| 2746 | static boolean |
| 2747 | allocate_dynrelocs (h, inf) |
| 2748 | struct elf_link_hash_entry *h; |
| 2749 | PTR inf; |
| 2750 | { |
| 2751 | struct bfd_link_info *info; |
| 2752 | struct ppc_link_hash_table *htab; |
| 2753 | asection *s; |
| 2754 | struct ppc_link_hash_entry *eh; |
| 2755 | struct ppc_dyn_relocs *p; |
| 2756 | |
| 2757 | if (h->root.type == bfd_link_hash_indirect |
| 2758 | || h->root.type == bfd_link_hash_warning) |
| 2759 | return true; |
| 2760 | |
| 2761 | info = (struct bfd_link_info *) inf; |
| 2762 | htab = ppc_hash_table (info); |
| 2763 | |
| 2764 | if (htab->elf.dynamic_sections_created |
| 2765 | && h->plt.refcount > 0 |
| 2766 | && h->dynindx != -1) |
| 2767 | { |
| 2768 | BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor); |
| 2769 | |
| 2770 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h)) |
| 2771 | { |
| 2772 | /* If this is the first .plt entry, make room for the special |
| 2773 | first entry. */ |
| 2774 | s = htab->splt; |
| 2775 | if (s->_raw_size == 0) |
| 2776 | s->_raw_size += PLT_INITIAL_ENTRY_SIZE; |
| 2777 | |
| 2778 | h->plt.offset = s->_raw_size; |
| 2779 | |
| 2780 | /* Make room for this entry. */ |
| 2781 | s->_raw_size += PLT_ENTRY_SIZE; |
| 2782 | |
| 2783 | /* Make room for the .stub and .glink code. */ |
| 2784 | s = htab->sstub; |
| 2785 | s->_raw_size += PLT_CALL_STUB_SIZE; |
| 2786 | |
| 2787 | s = htab->sglink; |
| 2788 | if (s->_raw_size == 0) |
| 2789 | s->_raw_size += GLINK_CALL_STUB_SIZE; |
| 2790 | /* We need bigger stubs past index 32767. */ |
| 2791 | if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4) |
| 2792 | s->_raw_size += 4; |
| 2793 | s->_raw_size += 2*4; |
| 2794 | |
| 2795 | /* We also need to make an entry in the .rela.plt section. */ |
| 2796 | s = htab->srelplt; |
| 2797 | s->_raw_size += sizeof (Elf64_External_Rela); |
| 2798 | } |
| 2799 | else |
| 2800 | { |
| 2801 | h->plt.offset = (bfd_vma) -1; |
| 2802 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
| 2803 | } |
| 2804 | } |
| 2805 | else |
| 2806 | { |
| 2807 | h->plt.offset = (bfd_vma) -1; |
| 2808 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
| 2809 | } |
| 2810 | |
| 2811 | if (h->got.refcount > 0) |
| 2812 | { |
| 2813 | boolean dyn; |
| 2814 | |
| 2815 | /* Make sure this symbol is output as a dynamic symbol. |
| 2816 | Undefined weak syms won't yet be marked as dynamic. */ |
| 2817 | if (h->dynindx == -1 |
| 2818 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) |
| 2819 | { |
| 2820 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) |
| 2821 | return false; |
| 2822 | } |
| 2823 | |
| 2824 | s = htab->sgot; |
| 2825 | h->got.offset = s->_raw_size; |
| 2826 | s->_raw_size += 8; |
| 2827 | dyn = htab->elf.dynamic_sections_created; |
| 2828 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)) |
| 2829 | htab->srelgot->_raw_size += sizeof (Elf64_External_Rela); |
| 2830 | } |
| 2831 | else |
| 2832 | h->got.offset = (bfd_vma) -1; |
| 2833 | |
| 2834 | eh = (struct ppc_link_hash_entry *) h; |
| 2835 | if (eh->dyn_relocs == NULL) |
| 2836 | return true; |
| 2837 | |
| 2838 | /* In the shared -Bsymbolic case, discard space allocated for |
| 2839 | dynamic pc-relative relocs against symbols which turn out to be |
| 2840 | defined in regular objects. For the normal shared case, discard |
| 2841 | space for relocs that have become local due to symbol visibility |
| 2842 | changes. */ |
| 2843 | |
| 2844 | if (info->shared) |
| 2845 | { |
| 2846 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 |
| 2847 | && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 |
| 2848 | || info->symbolic)) |
| 2849 | { |
| 2850 | struct ppc_dyn_relocs **pp; |
| 2851 | |
| 2852 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) |
| 2853 | { |
| 2854 | p->count -= p->pc_count; |
| 2855 | p->pc_count = 0; |
| 2856 | if (p->count == 0) |
| 2857 | *pp = p->next; |
| 2858 | else |
| 2859 | pp = &p->next; |
| 2860 | } |
| 2861 | } |
| 2862 | } |
| 2863 | else |
| 2864 | { |
| 2865 | /* For the non-shared case, discard space for relocs against |
| 2866 | symbols which turn out to need copy relocs or are not |
| 2867 | dynamic. */ |
| 2868 | |
| 2869 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 |
| 2870 | && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
| 2871 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
| 2872 | || (htab->elf.dynamic_sections_created |
| 2873 | && (h->root.type == bfd_link_hash_undefweak |
| 2874 | || h->root.type == bfd_link_hash_undefined)))) |
| 2875 | { |
| 2876 | /* Make sure this symbol is output as a dynamic symbol. |
| 2877 | Undefined weak syms won't yet be marked as dynamic. */ |
| 2878 | if (h->dynindx == -1 |
| 2879 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) |
| 2880 | { |
| 2881 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) |
| 2882 | return false; |
| 2883 | } |
| 2884 | |
| 2885 | /* If that succeeded, we know we'll be keeping all the |
| 2886 | relocs. */ |
| 2887 | if (h->dynindx != -1) |
| 2888 | goto keep; |
| 2889 | } |
| 2890 | |
| 2891 | eh->dyn_relocs = NULL; |
| 2892 | |
| 2893 | keep: ; |
| 2894 | } |
| 2895 | |
| 2896 | /* Finally, allocate space. */ |
| 2897 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
| 2898 | { |
| 2899 | asection *sreloc = elf_section_data (p->sec)->sreloc; |
| 2900 | sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela); |
| 2901 | } |
| 2902 | |
| 2903 | return true; |
| 2904 | } |
| 2905 | |
| 2906 | /* Find any dynamic relocs that apply to read-only sections. */ |
| 2907 | |
| 2908 | static boolean |
| 2909 | readonly_dynrelocs (h, inf) |
| 2910 | struct elf_link_hash_entry *h; |
| 2911 | PTR inf; |
| 2912 | { |
| 2913 | struct ppc_link_hash_entry *eh; |
| 2914 | struct ppc_dyn_relocs *p; |
| 2915 | |
| 2916 | eh = (struct ppc_link_hash_entry *) h; |
| 2917 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
| 2918 | { |
| 2919 | asection *s = p->sec->output_section; |
| 2920 | |
| 2921 | if (s != NULL && (s->flags & SEC_READONLY) != 0) |
| 2922 | { |
| 2923 | struct bfd_link_info *info = (struct bfd_link_info *) inf; |
| 2924 | |
| 2925 | info->flags |= DF_TEXTREL; |
| 2926 | |
| 2927 | /* Not an error, just cut short the traversal. */ |
| 2928 | return false; |
| 2929 | } |
| 2930 | } |
| 2931 | return true; |
| 2932 | } |
| 2933 | |
| 2934 | /* Set the sizes of the dynamic sections. */ |
| 2935 | |
| 2936 | static boolean |
| 2937 | ppc64_elf_size_dynamic_sections (output_bfd, info) |
| 2938 | bfd *output_bfd ATTRIBUTE_UNUSED; |
| 2939 | struct bfd_link_info *info; |
| 2940 | { |
| 2941 | struct ppc_link_hash_table *htab; |
| 2942 | bfd *dynobj; |
| 2943 | asection *s; |
| 2944 | boolean relocs; |
| 2945 | bfd *ibfd; |
| 2946 | |
| 2947 | htab = ppc_hash_table (info); |
| 2948 | dynobj = htab->elf.dynobj; |
| 2949 | if (dynobj == NULL) |
| 2950 | abort (); |
| 2951 | |
| 2952 | if (htab->elf.dynamic_sections_created) |
| 2953 | { |
| 2954 | /* Set the contents of the .interp section to the interpreter. */ |
| 2955 | if (! info->shared) |
| 2956 | { |
| 2957 | s = bfd_get_section_by_name (dynobj, ".interp"); |
| 2958 | if (s == NULL) |
| 2959 | abort (); |
| 2960 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; |
| 2961 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
| 2962 | } |
| 2963 | } |
| 2964 | |
| 2965 | /* Set up .got offsets for local syms, and space for local dynamic |
| 2966 | relocs. */ |
| 2967 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
| 2968 | { |
| 2969 | bfd_signed_vma *local_got; |
| 2970 | bfd_signed_vma *end_local_got; |
| 2971 | bfd_size_type locsymcount; |
| 2972 | Elf_Internal_Shdr *symtab_hdr; |
| 2973 | asection *srel; |
| 2974 | |
| 2975 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) |
| 2976 | continue; |
| 2977 | |
| 2978 | for (s = ibfd->sections; s != NULL; s = s->next) |
| 2979 | { |
| 2980 | struct ppc_dyn_relocs *p; |
| 2981 | |
| 2982 | for (p = *((struct ppc_dyn_relocs **) |
| 2983 | &elf_section_data (s)->local_dynrel); |
| 2984 | p != NULL; |
| 2985 | p = p->next) |
| 2986 | { |
| 2987 | if (!bfd_is_abs_section (p->sec) |
| 2988 | && bfd_is_abs_section (p->sec->output_section)) |
| 2989 | { |
| 2990 | /* Input section has been discarded, either because |
| 2991 | it is a copy of a linkonce section or due to |
| 2992 | linker script /DISCARD/, so we'll be discarding |
| 2993 | the relocs too. */ |
| 2994 | } |
| 2995 | else if (p->count != 0) |
| 2996 | { |
| 2997 | srel = elf_section_data (p->sec)->sreloc; |
| 2998 | srel->_raw_size += p->count * sizeof (Elf64_External_Rela); |
| 2999 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
| 3000 | info->flags |= DF_TEXTREL; |
| 3001 | } |
| 3002 | } |
| 3003 | } |
| 3004 | |
| 3005 | local_got = elf_local_got_refcounts (ibfd); |
| 3006 | if (!local_got) |
| 3007 | continue; |
| 3008 | |
| 3009 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
| 3010 | locsymcount = symtab_hdr->sh_info; |
| 3011 | end_local_got = local_got + locsymcount; |
| 3012 | s = htab->sgot; |
| 3013 | srel = htab->srelgot; |
| 3014 | for (; local_got < end_local_got; ++local_got) |
| 3015 | { |
| 3016 | if (*local_got > 0) |
| 3017 | { |
| 3018 | *local_got = s->_raw_size; |
| 3019 | s->_raw_size += 8; |
| 3020 | if (info->shared) |
| 3021 | srel->_raw_size += sizeof (Elf64_External_Rela); |
| 3022 | } |
| 3023 | else |
| 3024 | *local_got = (bfd_vma) -1; |
| 3025 | } |
| 3026 | } |
| 3027 | |
| 3028 | /* Allocate global sym .plt and .got entries, and space for global |
| 3029 | sym dynamic relocs. */ |
| 3030 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info); |
| 3031 | |
| 3032 | /* We now have determined the sizes of the various dynamic sections. |
| 3033 | Allocate memory for them. */ |
| 3034 | relocs = false; |
| 3035 | for (s = dynobj->sections; s != NULL; s = s->next) |
| 3036 | { |
| 3037 | bfd_vma size; |
| 3038 | |
| 3039 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
| 3040 | continue; |
| 3041 | |
| 3042 | if (s == htab->splt |
| 3043 | || s == htab->sgot |
| 3044 | || s == htab->sstub |
| 3045 | || s == htab->sglink) |
| 3046 | { |
| 3047 | /* Strip this section if we don't need it; see the |
| 3048 | comment below. */ |
| 3049 | } |
| 3050 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
| 3051 | { |
| 3052 | if (s->_raw_size == 0) |
| 3053 | { |
| 3054 | /* If we don't need this section, strip it from the |
| 3055 | output file. This is mostly to handle .rela.bss and |
| 3056 | .rela.plt. We must create both sections in |
| 3057 | create_dynamic_sections, because they must be created |
| 3058 | before the linker maps input sections to output |
| 3059 | sections. The linker does that before |
| 3060 | adjust_dynamic_symbol is called, and it is that |
| 3061 | function which decides whether anything needs to go |
| 3062 | into these sections. */ |
| 3063 | } |
| 3064 | else |
| 3065 | { |
| 3066 | if (s != htab->srelplt) |
| 3067 | relocs = true; |
| 3068 | |
| 3069 | /* We use the reloc_count field as a counter if we need |
| 3070 | to copy relocs into the output file. */ |
| 3071 | s->reloc_count = 0; |
| 3072 | } |
| 3073 | } |
| 3074 | else |
| 3075 | { |
| 3076 | /* It's not one of our sections, so don't allocate space. */ |
| 3077 | continue; |
| 3078 | } |
| 3079 | |
| 3080 | if (s->_raw_size == 0) |
| 3081 | { |
| 3082 | _bfd_strip_section_from_output (info, s); |
| 3083 | continue; |
| 3084 | } |
| 3085 | |
| 3086 | /* Allocate memory for the section contents. We use bfd_zalloc |
| 3087 | here in case unused entries are not reclaimed before the |
| 3088 | section's contents are written out. This should not happen, |
| 3089 | but this way if it does, we get a R_PPC64_NONE reloc instead |
| 3090 | of garbage. */ |
| 3091 | size = s->_raw_size; |
| 3092 | if (s == htab->sstub) |
| 3093 | { |
| 3094 | /* .stub may grow. Allocate enough for the maximum growth. */ |
| 3095 | size += (size + 65536 + 65535) / 65536 * 4; |
| 3096 | } |
| 3097 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, size); |
| 3098 | if (s->contents == NULL) |
| 3099 | return false; |
| 3100 | } |
| 3101 | |
| 3102 | if (htab->elf.dynamic_sections_created) |
| 3103 | { |
| 3104 | /* Add some entries to the .dynamic section. We fill in the |
| 3105 | values later, in ppc64_elf_finish_dynamic_sections, but we |
| 3106 | must add the entries now so that we get the correct size for |
| 3107 | the .dynamic section. The DT_DEBUG entry is filled in by the |
| 3108 | dynamic linker and used by the debugger. */ |
| 3109 | #define add_dynamic_entry(TAG, VAL) \ |
| 3110 | bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) |
| 3111 | |
| 3112 | if (!info->shared) |
| 3113 | { |
| 3114 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
| 3115 | return false; |
| 3116 | } |
| 3117 | |
| 3118 | if (htab->splt->_raw_size != 0) |
| 3119 | { |
| 3120 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
| 3121 | || !add_dynamic_entry (DT_PLTRELSZ, 0) |
| 3122 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) |
| 3123 | || !add_dynamic_entry (DT_JMPREL, 0) |
| 3124 | || !add_dynamic_entry (DT_PPC64_GLINK, 0)) |
| 3125 | return false; |
| 3126 | } |
| 3127 | |
| 3128 | if (NO_OPD_RELOCS) |
| 3129 | { |
| 3130 | if (!add_dynamic_entry (DT_PPC64_OPD, 0) |
| 3131 | || !add_dynamic_entry (DT_PPC64_OPDSZ, 0)) |
| 3132 | return false; |
| 3133 | } |
| 3134 | |
| 3135 | if (relocs) |
| 3136 | { |
| 3137 | if (!add_dynamic_entry (DT_RELA, 0) |
| 3138 | || !add_dynamic_entry (DT_RELASZ, 0) |
| 3139 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) |
| 3140 | return false; |
| 3141 | |
| 3142 | /* If any dynamic relocs apply to a read-only section, |
| 3143 | then we need a DT_TEXTREL entry. */ |
| 3144 | if ((info->flags & DF_TEXTREL) == 0) |
| 3145 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, |
| 3146 | (PTR) info); |
| 3147 | |
| 3148 | if ((info->flags & DF_TEXTREL) != 0) |
| 3149 | { |
| 3150 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
| 3151 | return false; |
| 3152 | } |
| 3153 | } |
| 3154 | } |
| 3155 | #undef add_dynamic_entry |
| 3156 | |
| 3157 | return true; |
| 3158 | } |
| 3159 | |
| 3160 | /* Called after we have seen all the input files/sections, but before |
| 3161 | final symbol resolution and section placement has been determined. |
| 3162 | |
| 3163 | We use this hook to provide a value for TOCstart, which we store in |
| 3164 | the output bfd elf_gp. */ |
| 3165 | |
| 3166 | boolean |
| 3167 | ppc64_elf_set_toc (obfd, info) |
| 3168 | bfd *obfd; |
| 3169 | struct bfd_link_info *info; |
| 3170 | { |
| 3171 | if (!info->relocateable) |
| 3172 | { |
| 3173 | asection *s; |
| 3174 | bfd_vma TOCstart; |
| 3175 | |
| 3176 | /* The TOC consists of sections .got, .toc, .tocbss, .plt in that |
| 3177 | order. The TOC starts where the first of these sections starts. */ |
| 3178 | s = bfd_get_section_by_name (obfd, ".got"); |
| 3179 | if (s == NULL) |
| 3180 | s = bfd_get_section_by_name (obfd, ".toc"); |
| 3181 | if (s == NULL) |
| 3182 | s = bfd_get_section_by_name (obfd, ".tocbss"); |
| 3183 | if (s == NULL) |
| 3184 | s = bfd_get_section_by_name (obfd, ".plt"); |
| 3185 | if (s == NULL) |
| 3186 | { |
| 3187 | /* This may happen for |
| 3188 | o references to TOC base (SYM@toc / TOC[tc0]) without a |
| 3189 | .toc directive |
| 3190 | o bad linker script |
| 3191 | o --gc-sections and empty TOC sections |
| 3192 | |
| 3193 | FIXME: Warn user? */ |
| 3194 | |
| 3195 | /* Look for a likely section. We probably won't even be |
| 3196 | using TOCstart. */ |
| 3197 | for (s = obfd->sections; s != NULL; s = s->next) |
| 3198 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY)) |
| 3199 | == (SEC_ALLOC | SEC_SMALL_DATA)) |
| 3200 | break; |
| 3201 | if (s == NULL) |
| 3202 | for (s = obfd->sections; s != NULL; s = s->next) |
| 3203 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA)) |
| 3204 | == (SEC_ALLOC | SEC_SMALL_DATA)) |
| 3205 | break; |
| 3206 | if (s == NULL) |
| 3207 | for (s = obfd->sections; s != NULL; s = s->next) |
| 3208 | if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC) |
| 3209 | break; |
| 3210 | if (s == NULL) |
| 3211 | for (s = obfd->sections; s != NULL; s = s->next) |
| 3212 | if ((s->flags & SEC_ALLOC) == SEC_ALLOC) |
| 3213 | break; |
| 3214 | } |
| 3215 | |
| 3216 | TOCstart = 0; |
| 3217 | if (s != NULL) |
| 3218 | TOCstart = s->output_section->vma + s->output_offset; |
| 3219 | |
| 3220 | elf_gp (obfd) = TOCstart; |
| 3221 | } |
| 3222 | return true; |
| 3223 | } |
| 3224 | |
| 3225 | /* PowerPC64 .plt entries are 24 bytes long, which doesn't divide |
| 3226 | evenly into 64k. Sometimes with a large enough .plt, we'll need to |
| 3227 | use offsets differing in the high 16 bits when accessing a .plt |
| 3228 | entry from a .plt call stub. This function adjusts the size of |
| 3229 | .stub to accommodate the extra stub instruction needed in such |
| 3230 | cases. */ |
| 3231 | |
| 3232 | boolean |
| 3233 | ppc64_elf_size_stubs (obfd, info, changed) |
| 3234 | bfd *obfd; |
| 3235 | struct bfd_link_info *info; |
| 3236 | int *changed; |
| 3237 | { |
| 3238 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
| 3239 | bfd_vma plt_offset, next_64k; |
| 3240 | long base, num, extra; |
| 3241 | |
| 3242 | /* .plt and .stub should be both present, or both absent. */ |
| 3243 | if ((htab->splt == NULL || htab->splt->_raw_size == 0) |
| 3244 | != (htab->sstub == NULL || htab->sstub->_raw_size == 0)) |
| 3245 | abort (); |
| 3246 | |
| 3247 | /* If no .plt, then nothing to do. */ |
| 3248 | if (htab->splt == NULL || htab->splt->_raw_size == 0) |
| 3249 | return true; |
| 3250 | |
| 3251 | plt_offset = (htab->splt->output_section->vma |
| 3252 | + htab->splt->output_offset |
| 3253 | - elf_gp (obfd)); |
| 3254 | next_64k = (plt_offset + 65535) & -65536; |
| 3255 | |
| 3256 | /* If the .plt doesn't have any entries crossing a 64k boundary, |
| 3257 | then there is no need for bigger stubs. */ |
| 3258 | if (plt_offset + htab->splt->_raw_size <= next_64k) |
| 3259 | return true; |
| 3260 | |
| 3261 | /* OK, so we have at least one transition. Since .plt entries are |
| 3262 | 24 bytes long, we'll strike it lucky every 3*64k, with the 64k |
| 3263 | boundary between .plt entries. */ |
| 3264 | base = next_64k / 65536; |
| 3265 | num = (plt_offset + htab->splt->_raw_size - next_64k) / 65536; |
| 3266 | extra = (base % 3 + num + 1) * 2 / 3; |
| 3267 | |
| 3268 | /* Allow one extra instruction for each EXTRA. The change in .stub |
| 3269 | may change the location of .toc and .plt. .toc and .plt ought to |
| 3270 | move as a group, but someone might be playing with eg. .plt |
| 3271 | alignment, so don't allow .stub size to decrease. */ |
| 3272 | if (htab->sstub->_cooked_size < htab->sstub->_raw_size + extra * 4) |
| 3273 | { |
| 3274 | htab->sstub->_cooked_size = htab->sstub->_raw_size + extra * 4; |
| 3275 | *changed = true; |
| 3276 | } |
| 3277 | return true; |
| 3278 | } |
| 3279 | |
| 3280 | /* Build a .plt call stub. */ |
| 3281 | |
| 3282 | static bfd_byte * |
| 3283 | build_plt_stub (obfd, p, offset, glink) |
| 3284 | bfd *obfd; |
| 3285 | bfd_byte *p; |
| 3286 | int offset; |
| 3287 | int glink; |
| 3288 | { |
| 3289 | #define PPC_LO(v) ((v) & 0xffff) |
| 3290 | #define PPC_HI(v) (((v) >> 16) & 0xffff) |
| 3291 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) |
| 3292 | |
| 3293 | if (glink) |
| 3294 | bfd_put_32 (obfd, LD_R2_40R1, p), p += 4; |
| 3295 | bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; |
| 3296 | if (!glink) |
| 3297 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; |
| 3298 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; |
| 3299 | if (PPC_HA (offset + 8) != PPC_HA (offset)) |
| 3300 | bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4; |
| 3301 | offset += 8; |
| 3302 | bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4; |
| 3303 | if (PPC_HA (offset + 8) != PPC_HA (offset)) |
| 3304 | bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4; |
| 3305 | offset += 8; |
| 3306 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; |
| 3307 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; |
| 3308 | bfd_put_32 (obfd, BCTR, p), p += 4; |
| 3309 | return p; |
| 3310 | } |
| 3311 | |
| 3312 | /* Build the stubs for one function call. */ |
| 3313 | |
| 3314 | static boolean |
| 3315 | build_one_stub (h, inf) |
| 3316 | struct elf_link_hash_entry *h; |
| 3317 | PTR inf; |
| 3318 | { |
| 3319 | struct bfd_link_info *info; |
| 3320 | struct ppc_link_hash_table *htab; |
| 3321 | |
| 3322 | if (h->root.type == bfd_link_hash_indirect |
| 3323 | || h->root.type == bfd_link_hash_warning) |
| 3324 | return true; |
| 3325 | |
| 3326 | info = (struct bfd_link_info *) inf; |
| 3327 | htab = ppc_hash_table (info); |
| 3328 | |
| 3329 | if (htab->elf.dynamic_sections_created |
| 3330 | && h->plt.offset != (bfd_vma) -1 |
| 3331 | && ((struct ppc_link_hash_entry *) h)->is_func_descriptor) |
| 3332 | { |
| 3333 | struct elf_link_hash_entry *fh; |
| 3334 | asection *s; |
| 3335 | bfd_vma plt_r2; |
| 3336 | bfd_byte *p; |
| 3337 | unsigned int indx; |
| 3338 | |
| 3339 | fh = elf_link_hash_lookup (&htab->elf, h->root.root.string - 1, |
| 3340 | false, false, true); |
| 3341 | |
| 3342 | if (fh == NULL) |
| 3343 | abort (); |
| 3344 | |
| 3345 | BFD_ASSERT (((struct ppc_link_hash_entry *) fh)->is_func); |
| 3346 | |
| 3347 | /* Build the .plt call stub. */ |
| 3348 | plt_r2 = (htab->splt->output_section->vma |
| 3349 | + htab->splt->output_offset |
| 3350 | + h->plt.offset |
| 3351 | - elf_gp (htab->splt->output_section->owner) |
| 3352 | - TOC_BASE_OFF); |
| 3353 | |
| 3354 | if (plt_r2 + 0x80000000 > 0xffffffff |
| 3355 | || (plt_r2 & 3) != 0) |
| 3356 | { |
| 3357 | (*_bfd_error_handler) |
| 3358 | (_("linkage table error against `%s'"), |
| 3359 | h->root.root.string); |
| 3360 | bfd_set_error (bfd_error_bad_value); |
| 3361 | htab->plt_overflow = true; |
| 3362 | return false; |
| 3363 | } |
| 3364 | |
| 3365 | s = htab->sstub; |
| 3366 | /* Steal plt.offset to store the stub offset. */ |
| 3367 | fh->plt.offset = s->_cooked_size; |
| 3368 | p = s->contents + s->_cooked_size; |
| 3369 | p = build_plt_stub (s->owner, p, (int) plt_r2, 0); |
| 3370 | s->_cooked_size = p - s->contents; |
| 3371 | |
| 3372 | /* Build the .glink lazy link call stub. */ |
| 3373 | s = htab->sglink; |
| 3374 | p = s->contents + s->_cooked_size; |
| 3375 | indx = s->reloc_count; |
| 3376 | if (indx < 0x8000) |
| 3377 | { |
| 3378 | bfd_put_32 (s->owner, LI_R0_0 | indx, p); |
| 3379 | p += 4; |
| 3380 | } |
| 3381 | else |
| 3382 | { |
| 3383 | bfd_put_32 (s->owner, LIS_R0_0 | PPC_HI (indx), p); |
| 3384 | p += 4; |
| 3385 | bfd_put_32 (s->owner, ORI_R0_R0_0 | PPC_LO (indx), p); |
| 3386 | p += 4; |
| 3387 | } |
| 3388 | bfd_put_32 (s->owner, B_DOT | ((s->contents - p) & 0x3fffffc), p); |
| 3389 | p += 4; |
| 3390 | s->_cooked_size = p - s->contents; |
| 3391 | s->reloc_count += 1; |
| 3392 | } |
| 3393 | return true; |
| 3394 | } |
| 3395 | |
| 3396 | boolean |
| 3397 | ppc64_elf_build_stubs (obfd, info) |
| 3398 | bfd *obfd; |
| 3399 | struct bfd_link_info *info; |
| 3400 | { |
| 3401 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
| 3402 | bfd_vma old_stub_size; |
| 3403 | bfd_vma plt_r2; |
| 3404 | bfd_byte *p; |
| 3405 | |
| 3406 | /* If no .plt stubs, then nothing to do. */ |
| 3407 | if (htab->sstub == NULL || htab->sstub->_raw_size == 0) |
| 3408 | return true; |
| 3409 | |
| 3410 | old_stub_size = htab->sstub->_cooked_size; |
| 3411 | htab->sstub->_cooked_size = 0; |
| 3412 | |
| 3413 | /* Build the .glink plt call stub. */ |
| 3414 | plt_r2 = (htab->splt->output_section->vma |
| 3415 | + htab->splt->output_offset |
| 3416 | - elf_gp (obfd) |
| 3417 | - TOC_BASE_OFF); |
| 3418 | p = htab->sglink->contents; |
| 3419 | p = build_plt_stub (htab->sglink->owner, p, (int) plt_r2, 1); |
| 3420 | while (p - htab->sglink->contents < GLINK_CALL_STUB_SIZE) |
| 3421 | { |
| 3422 | bfd_put_32 (htab->sglink->owner, NOP, p); |
| 3423 | p += 4; |
| 3424 | } |
| 3425 | htab->sglink->_cooked_size = p - htab->sglink->contents; |
| 3426 | |
| 3427 | /* Use reloc_count to count entries. */ |
| 3428 | htab->sglink->reloc_count = 0; |
| 3429 | |
| 3430 | elf_link_hash_traverse (&htab->elf, build_one_stub, (PTR) info); |
| 3431 | htab->sglink->reloc_count = 0; |
| 3432 | |
| 3433 | if (htab->plt_overflow) |
| 3434 | return false; |
| 3435 | |
| 3436 | if (old_stub_size != htab->sstub->_cooked_size |
| 3437 | || htab->sglink->_raw_size != htab->sglink->_cooked_size) |
| 3438 | { |
| 3439 | (*_bfd_error_handler) |
| 3440 | (_("stub section size doesn't match calculated size")); |
| 3441 | bfd_set_error (bfd_error_bad_value); |
| 3442 | return false; |
| 3443 | } |
| 3444 | return true; |
| 3445 | } |
| 3446 | |
| 3447 | /* Set up any other section flags and such that may be necessary. */ |
| 3448 | |
| 3449 | static boolean |
| 3450 | ppc64_elf_fake_sections (abfd, shdr, asect) |
| 3451 | bfd *abfd ATTRIBUTE_UNUSED; |
| 3452 | Elf64_Internal_Shdr *shdr; |
| 3453 | asection *asect; |
| 3454 | { |
| 3455 | if ((asect->flags & SEC_EXCLUDE) != 0) |
| 3456 | shdr->sh_flags |= SHF_EXCLUDE; |
| 3457 | |
| 3458 | if ((asect->flags & SEC_SORT_ENTRIES) != 0) |
| 3459 | shdr->sh_type = SHT_ORDERED; |
| 3460 | |
| 3461 | return true; |
| 3462 | } |
| 3463 | |
| 3464 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
| 3465 | to handle the relocations for a section. |
| 3466 | |
| 3467 | The relocs are always passed as Rela structures; if the section |
| 3468 | actually uses Rel structures, the r_addend field will always be |
| 3469 | zero. |
| 3470 | |
| 3471 | This function is responsible for adjust the section contents as |
| 3472 | necessary, and (if using Rela relocs and generating a |
| 3473 | relocateable output file) adjusting the reloc addend as |
| 3474 | necessary. |
| 3475 | |
| 3476 | This function does not have to worry about setting the reloc |
| 3477 | address or the reloc symbol index. |
| 3478 | |
| 3479 | LOCAL_SYMS is a pointer to the swapped in local symbols. |
| 3480 | |
| 3481 | LOCAL_SECTIONS is an array giving the section in the input file |
| 3482 | corresponding to the st_shndx field of each local symbol. |
| 3483 | |
| 3484 | The global hash table entry for the global symbols can be found |
| 3485 | via elf_sym_hashes (input_bfd). |
| 3486 | |
| 3487 | When generating relocateable output, this function must handle |
| 3488 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
| 3489 | going to be the section symbol corresponding to the output |
| 3490 | section, which means that the addend must be adjusted |
| 3491 | accordingly. */ |
| 3492 | |
| 3493 | static boolean |
| 3494 | ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section, |
| 3495 | contents, relocs, local_syms, local_sections) |
| 3496 | bfd *output_bfd; |
| 3497 | struct bfd_link_info *info; |
| 3498 | bfd *input_bfd; |
| 3499 | asection *input_section; |
| 3500 | bfd_byte *contents; |
| 3501 | Elf_Internal_Rela *relocs; |
| 3502 | Elf_Internal_Sym *local_syms; |
| 3503 | asection **local_sections; |
| 3504 | { |
| 3505 | struct ppc_link_hash_table *htab; |
| 3506 | Elf_Internal_Shdr *symtab_hdr; |
| 3507 | struct elf_link_hash_entry **sym_hashes; |
| 3508 | Elf_Internal_Rela *rel; |
| 3509 | Elf_Internal_Rela *relend; |
| 3510 | bfd_vma *local_got_offsets; |
| 3511 | bfd_vma TOCstart; |
| 3512 | boolean ret = true; |
| 3513 | boolean is_opd; |
| 3514 | |
| 3515 | /* Initialize howto table if needed. */ |
| 3516 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
| 3517 | ppc_howto_init (); |
| 3518 | |
| 3519 | htab = ppc_hash_table (info); |
| 3520 | local_got_offsets = elf_local_got_offsets (input_bfd); |
| 3521 | TOCstart = elf_gp (output_bfd); |
| 3522 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
| 3523 | sym_hashes = elf_sym_hashes (input_bfd); |
| 3524 | is_opd = strcmp (bfd_get_section_name (abfd, input_section), ".opd") == 0; |
| 3525 | |
| 3526 | rel = relocs; |
| 3527 | relend = relocs + input_section->reloc_count; |
| 3528 | for (; rel < relend; rel++) |
| 3529 | { |
| 3530 | enum elf_ppc_reloc_type r_type; |
| 3531 | bfd_vma offset; |
| 3532 | bfd_vma addend; |
| 3533 | bfd_reloc_status_type r; |
| 3534 | Elf_Internal_Sym *sym; |
| 3535 | asection *sec; |
| 3536 | struct elf_link_hash_entry *h; |
| 3537 | const char *sym_name; |
| 3538 | unsigned long r_symndx; |
| 3539 | bfd_vma relocation; |
| 3540 | boolean unresolved_reloc; |
| 3541 | boolean has_nop; |
| 3542 | long insn; |
| 3543 | |
| 3544 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); |
| 3545 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 3546 | |
| 3547 | if (info->relocateable) |
| 3548 | { |
| 3549 | /* This is a relocatable link. We don't have to change |
| 3550 | anything, unless the reloc is against a section symbol, |
| 3551 | in which case we have to adjust according to where the |
| 3552 | section symbol winds up in the output section. */ |
| 3553 | if (r_symndx < symtab_hdr->sh_info) |
| 3554 | { |
| 3555 | sym = local_syms + r_symndx; |
| 3556 | if ((unsigned) ELF_ST_TYPE (sym->st_info) == STT_SECTION) |
| 3557 | { |
| 3558 | sec = local_sections[r_symndx]; |
| 3559 | rel->r_addend += sec->output_offset + sym->st_value; |
| 3560 | } |
| 3561 | } |
| 3562 | continue; |
| 3563 | } |
| 3564 | |
| 3565 | /* This is a final link. */ |
| 3566 | |
| 3567 | offset = rel->r_offset; |
| 3568 | addend = rel->r_addend; |
| 3569 | r = bfd_reloc_other; |
| 3570 | sym = (Elf_Internal_Sym *) 0; |
| 3571 | sec = (asection *) 0; |
| 3572 | h = (struct elf_link_hash_entry *) 0; |
| 3573 | sym_name = (const char *) 0; |
| 3574 | unresolved_reloc = false; |
| 3575 | |
| 3576 | if (r_type == R_PPC64_TOC) |
| 3577 | { |
| 3578 | /* Relocation value is TOC base. Symbol is ignored. */ |
| 3579 | relocation = TOCstart + TOC_BASE_OFF; |
| 3580 | } |
| 3581 | else if (r_symndx < symtab_hdr->sh_info) |
| 3582 | { |
| 3583 | /* It's a local symbol. */ |
| 3584 | sym = local_syms + r_symndx; |
| 3585 | sec = local_sections[r_symndx]; |
| 3586 | sym_name = "<local symbol>"; |
| 3587 | |
| 3588 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
| 3589 | addend = rel->r_addend; |
| 3590 | } |
| 3591 | else |
| 3592 | { |
| 3593 | /* It's a global symbol. */ |
| 3594 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 3595 | while (h->root.type == bfd_link_hash_indirect |
| 3596 | || h->root.type == bfd_link_hash_warning) |
| 3597 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 3598 | sym_name = h->root.root.string; |
| 3599 | relocation = 0; |
| 3600 | if (h->root.type == bfd_link_hash_defined |
| 3601 | || h->root.type == bfd_link_hash_defweak) |
| 3602 | { |
| 3603 | sec = h->root.u.def.section; |
| 3604 | if (sec->output_section == NULL) |
| 3605 | /* Set a flag that will be cleared later if we find a |
| 3606 | relocation value for this symbol. output_section |
| 3607 | is typically NULL for symbols satisfied by a shared |
| 3608 | library. */ |
| 3609 | unresolved_reloc = true; |
| 3610 | else |
| 3611 | relocation = (h->root.u.def.value |
| 3612 | + sec->output_section->vma |
| 3613 | + sec->output_offset); |
| 3614 | } |
| 3615 | else if (h->root.type == bfd_link_hash_undefweak) |
| 3616 | ; |
| 3617 | else if (info->shared |
| 3618 | && (!info->symbolic || info->allow_shlib_undefined) |
| 3619 | && !info->no_undefined |
| 3620 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
| 3621 | ; |
| 3622 | else |
| 3623 | { |
| 3624 | if (! ((*info->callbacks->undefined_symbol) |
| 3625 | (info, h->root.root.string, input_bfd, input_section, |
| 3626 | offset, (!info->shared |
| 3627 | || info->no_undefined |
| 3628 | || ELF_ST_VISIBILITY (h->other))))) |
| 3629 | return false; |
| 3630 | } |
| 3631 | } |
| 3632 | |
| 3633 | /* First handle relocations that tweak non-addend part of insn. */ |
| 3634 | insn = 0; |
| 3635 | switch (r_type) |
| 3636 | { |
| 3637 | default: |
| 3638 | break; |
| 3639 | |
| 3640 | /* Branch taken prediction relocations. */ |
| 3641 | case R_PPC64_ADDR14_BRTAKEN: |
| 3642 | case R_PPC64_REL14_BRTAKEN: |
| 3643 | insn = 0x01 << 21; /* Set 't' bit, lowest bit of BO field. */ |
| 3644 | /* Fall thru. */ |
| 3645 | |
| 3646 | /* Branch not taken prediction relocations. */ |
| 3647 | case R_PPC64_ADDR14_BRNTAKEN: |
| 3648 | case R_PPC64_REL14_BRNTAKEN: |
| 3649 | insn |= bfd_get_32 (output_bfd, contents + offset) & ~(0x01 << 21); |
| 3650 | /* Set 'a' bit. This is 0b00010 in BO field for branch on CR(BI) |
| 3651 | insns (BO == 001at or 011at), and 0b01000 for branch on CTR |
| 3652 | insns (BO == 1a00t or 1a01t). */ |
| 3653 | if ((insn & (0x14 << 21)) == (0x04 << 21)) |
| 3654 | insn |= 0x02 << 21; |
| 3655 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) |
| 3656 | insn |= 0x08 << 21; |
| 3657 | else |
| 3658 | break; |
| 3659 | |
| 3660 | bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset); |
| 3661 | break; |
| 3662 | |
| 3663 | case R_PPC64_REL24: |
| 3664 | case R_PPC64_ADDR24: |
| 3665 | /* An ADDR24 or REL24 branching to a linkage function may be |
| 3666 | followed by a nop that we have to replace with a ld in |
| 3667 | order to restore the TOC base pointer. Only calls to |
| 3668 | shared objects need to alter the TOC base. These are |
| 3669 | recognized by their need for a PLT entry. */ |
| 3670 | has_nop = 0; |
| 3671 | if (h != NULL |
| 3672 | && h->plt.offset != (bfd_vma) -1 |
| 3673 | && htab->sstub != NULL) |
| 3674 | { |
| 3675 | /* plt.offset here is the offset into the stub section. */ |
| 3676 | relocation = (htab->sstub->output_section->vma |
| 3677 | + htab->sstub->output_offset |
| 3678 | + h->plt.offset); |
| 3679 | unresolved_reloc = false; |
| 3680 | |
| 3681 | /* Make sure that there really is an instruction after |
| 3682 | the branch that we can decode. */ |
| 3683 | if (offset + 8 <= input_section->_cooked_size) |
| 3684 | { |
| 3685 | bfd_byte *pnext; |
| 3686 | |
| 3687 | pnext = contents + offset + 4; |
| 3688 | insn = bfd_get_32 (input_bfd, pnext); |
| 3689 | |
| 3690 | if (insn == 0x60000000 /* nop (ori r0,r0,0) */ |
| 3691 | || insn == 0x4def7b82 /* cror 15,15,15 */ |
| 3692 | || insn == 0x4ffffb82) /* cror 31,31,31 */ |
| 3693 | { |
| 3694 | bfd_put_32 (input_bfd, |
| 3695 | (bfd_vma) 0xe8410028, /* ld r2,40(r1) */ |
| 3696 | pnext); |
| 3697 | has_nop = 1; |
| 3698 | } |
| 3699 | } |
| 3700 | } |
| 3701 | |
| 3702 | if (h != NULL |
| 3703 | && h->root.type == bfd_link_hash_undefweak |
| 3704 | && r_type == R_PPC64_REL24 |
| 3705 | && addend == 0 |
| 3706 | && relocation == 0) |
| 3707 | { |
| 3708 | /* Tweak calls to undefined weak functions to behave as |
| 3709 | if the "called" function immediately returns. We can |
| 3710 | thus call to a weak function without first checking |
| 3711 | whether the function is defined. */ |
| 3712 | relocation = 4; |
| 3713 | if (has_nop) |
| 3714 | relocation = 8; |
| 3715 | } |
| 3716 | break; |
| 3717 | } |
| 3718 | |
| 3719 | /* Set `addend'. */ |
| 3720 | switch (r_type) |
| 3721 | { |
| 3722 | default: |
| 3723 | (*_bfd_error_handler) |
| 3724 | (_("%s: unknown relocation type %d for symbol %s"), |
| 3725 | bfd_archive_filename (input_bfd), (int) r_type, sym_name); |
| 3726 | |
| 3727 | bfd_set_error (bfd_error_bad_value); |
| 3728 | ret = false; |
| 3729 | continue; |
| 3730 | |
| 3731 | case R_PPC64_NONE: |
| 3732 | case R_PPC_GNU_VTINHERIT: |
| 3733 | case R_PPC_GNU_VTENTRY: |
| 3734 | continue; |
| 3735 | |
| 3736 | /* GOT16 relocations. Like an ADDR16 using the symbol's |
| 3737 | address in the GOT as relocation value instead of the |
| 3738 | symbols value itself. Also, create a GOT entry for the |
| 3739 | symbol and put the symbol value there. */ |
| 3740 | case R_PPC64_GOT16: |
| 3741 | case R_PPC64_GOT16_LO: |
| 3742 | case R_PPC64_GOT16_HI: |
| 3743 | case R_PPC64_GOT16_HA: |
| 3744 | case R_PPC64_GOT16_DS: |
| 3745 | case R_PPC64_GOT16_LO_DS: |
| 3746 | { |
| 3747 | /* Relocation is to the entry for this symbol in the global |
| 3748 | offset table. */ |
| 3749 | bfd_vma off; |
| 3750 | |
| 3751 | if (htab->sgot == NULL) |
| 3752 | abort (); |
| 3753 | |
| 3754 | if (h != NULL) |
| 3755 | { |
| 3756 | boolean dyn; |
| 3757 | |
| 3758 | off = h->got.offset; |
| 3759 | dyn = htab->elf.dynamic_sections_created; |
| 3760 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h) |
| 3761 | || (info->shared |
| 3762 | && (info->symbolic |
| 3763 | || h->dynindx == -1 |
| 3764 | || (h->elf_link_hash_flags |
| 3765 | & ELF_LINK_FORCED_LOCAL)) |
| 3766 | && (h->elf_link_hash_flags |
| 3767 | & ELF_LINK_HASH_DEF_REGULAR))) |
| 3768 | { |
| 3769 | /* This is actually a static link, or it is a |
| 3770 | -Bsymbolic link and the symbol is defined |
| 3771 | locally, or the symbol was forced to be local |
| 3772 | because of a version file. We must initialize |
| 3773 | this entry in the global offset table. Since the |
| 3774 | offset must always be a multiple of 8, we use the |
| 3775 | least significant bit to record whether we have |
| 3776 | initialized it already. |
| 3777 | |
| 3778 | When doing a dynamic link, we create a .rel.got |
| 3779 | relocation entry to initialize the value. This |
| 3780 | is done in the finish_dynamic_symbol routine. */ |
| 3781 | if ((off & 1) != 0) |
| 3782 | off &= ~1; |
| 3783 | else |
| 3784 | { |
| 3785 | bfd_put_64 (output_bfd, relocation, |
| 3786 | htab->sgot->contents + off); |
| 3787 | h->got.offset |= 1; |
| 3788 | } |
| 3789 | } |
| 3790 | else |
| 3791 | unresolved_reloc = false; |
| 3792 | } |
| 3793 | else |
| 3794 | { |
| 3795 | if (local_got_offsets == NULL) |
| 3796 | abort (); |
| 3797 | |
| 3798 | off = local_got_offsets[r_symndx]; |
| 3799 | |
| 3800 | /* The offset must always be a multiple of 8. We use |
| 3801 | the least significant bit to record whether we have |
| 3802 | already processed this entry. */ |
| 3803 | if ((off & 1) != 0) |
| 3804 | off &= ~1; |
| 3805 | else |
| 3806 | { |
| 3807 | bfd_put_64 (output_bfd, relocation, |
| 3808 | htab->sgot->contents + off); |
| 3809 | |
| 3810 | if (info->shared) |
| 3811 | { |
| 3812 | Elf_Internal_Rela outrel; |
| 3813 | Elf64_External_Rela *loc; |
| 3814 | |
| 3815 | /* We need to generate a R_PPC64_RELATIVE reloc |
| 3816 | for the dynamic linker. */ |
| 3817 | outrel.r_offset = (htab->sgot->output_section->vma |
| 3818 | + htab->sgot->output_offset |
| 3819 | + off); |
| 3820 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
| 3821 | outrel.r_addend = relocation; |
| 3822 | loc = (Elf64_External_Rela *) htab->srelgot->contents; |
| 3823 | loc += htab->srelgot->reloc_count++; |
| 3824 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
| 3825 | } |
| 3826 | |
| 3827 | local_got_offsets[r_symndx] |= 1; |
| 3828 | } |
| 3829 | } |
| 3830 | |
| 3831 | if (off >= (bfd_vma) -2) |
| 3832 | abort (); |
| 3833 | |
| 3834 | relocation = htab->sgot->output_offset + off; |
| 3835 | |
| 3836 | /* TOC base (r2) is TOC start plus 0x8000. */ |
| 3837 | addend -= TOC_BASE_OFF; |
| 3838 | } |
| 3839 | break; |
| 3840 | |
| 3841 | case R_PPC64_PLT16_HA: |
| 3842 | case R_PPC64_PLT16_HI: |
| 3843 | case R_PPC64_PLT16_LO: |
| 3844 | case R_PPC64_PLT32: |
| 3845 | case R_PPC64_PLT64: |
| 3846 | /* Relocation is to the entry for this symbol in the |
| 3847 | procedure linkage table. */ |
| 3848 | |
| 3849 | /* Resolve a PLT reloc against a local symbol directly, |
| 3850 | without using the procedure linkage table. */ |
| 3851 | if (h == NULL) |
| 3852 | break; |
| 3853 | |
| 3854 | if (h->plt.offset == (bfd_vma) -1 |
| 3855 | || htab->splt == NULL) |
| 3856 | { |
| 3857 | /* We didn't make a PLT entry for this symbol. This |
| 3858 | happens when statically linking PIC code, or when |
| 3859 | using -Bsymbolic. */ |
| 3860 | break; |
| 3861 | } |
| 3862 | |
| 3863 | relocation = (htab->splt->output_section->vma |
| 3864 | + htab->splt->output_offset |
| 3865 | + h->plt.offset); |
| 3866 | unresolved_reloc = false; |
| 3867 | break; |
| 3868 | |
| 3869 | /* TOC16 relocs. We want the offset relative to the TOC base, |
| 3870 | which is the address of the start of the TOC plus 0x8000. |
| 3871 | The TOC consists of sections .got, .toc, .tocbss, and .plt, |
| 3872 | in this order. */ |
| 3873 | case R_PPC64_TOC16: |
| 3874 | case R_PPC64_TOC16_LO: |
| 3875 | case R_PPC64_TOC16_HI: |
| 3876 | case R_PPC64_TOC16_DS: |
| 3877 | case R_PPC64_TOC16_LO_DS: |
| 3878 | case R_PPC64_TOC16_HA: |
| 3879 | addend -= TOCstart + TOC_BASE_OFF; |
| 3880 | break; |
| 3881 | |
| 3882 | /* Relocate against the beginning of the section. */ |
| 3883 | case R_PPC64_SECTOFF: |
| 3884 | case R_PPC64_SECTOFF_LO: |
| 3885 | case R_PPC64_SECTOFF_HI: |
| 3886 | case R_PPC64_SECTOFF_DS: |
| 3887 | case R_PPC64_SECTOFF_LO_DS: |
| 3888 | case R_PPC64_SECTOFF_HA: |
| 3889 | if (sec != (asection *) 0) |
| 3890 | addend -= sec->output_section->vma; |
| 3891 | break; |
| 3892 | |
| 3893 | case R_PPC64_REL24: |
| 3894 | break; |
| 3895 | |
| 3896 | /* Relocations that may need to be propagated if this is a |
| 3897 | dynamic object. */ |
| 3898 | case R_PPC64_REL14: |
| 3899 | case R_PPC64_REL14_BRNTAKEN: |
| 3900 | case R_PPC64_REL14_BRTAKEN: |
| 3901 | case R_PPC64_REL32: |
| 3902 | case R_PPC64_REL64: |
| 3903 | case R_PPC64_ADDR14: |
| 3904 | case R_PPC64_ADDR14_BRNTAKEN: |
| 3905 | case R_PPC64_ADDR14_BRTAKEN: |
| 3906 | case R_PPC64_ADDR16: |
| 3907 | case R_PPC64_ADDR16_DS: |
| 3908 | case R_PPC64_ADDR16_HA: |
| 3909 | case R_PPC64_ADDR16_HI: |
| 3910 | case R_PPC64_ADDR16_HIGHER: |
| 3911 | case R_PPC64_ADDR16_HIGHERA: |
| 3912 | case R_PPC64_ADDR16_HIGHEST: |
| 3913 | case R_PPC64_ADDR16_HIGHESTA: |
| 3914 | case R_PPC64_ADDR16_LO: |
| 3915 | case R_PPC64_ADDR16_LO_DS: |
| 3916 | case R_PPC64_ADDR24: |
| 3917 | case R_PPC64_ADDR30: |
| 3918 | case R_PPC64_ADDR32: |
| 3919 | case R_PPC64_ADDR64: |
| 3920 | case R_PPC64_UADDR16: |
| 3921 | case R_PPC64_UADDR32: |
| 3922 | case R_PPC64_UADDR64: |
| 3923 | /* r_symndx will be zero only for relocs against symbols |
| 3924 | from removed linkonce sections, or sections discarded by |
| 3925 | a linker script. */ |
| 3926 | if (r_symndx == 0) |
| 3927 | break; |
| 3928 | /* Fall thru. */ |
| 3929 | |
| 3930 | case R_PPC64_TOC: |
| 3931 | if ((input_section->flags & SEC_ALLOC) == 0) |
| 3932 | break; |
| 3933 | |
| 3934 | if (NO_OPD_RELOCS && is_opd) |
| 3935 | break; |
| 3936 | |
| 3937 | if ((info->shared |
| 3938 | && (IS_ABSOLUTE_RELOC (r_type) |
| 3939 | || (h != NULL |
| 3940 | && h->dynindx != -1 |
| 3941 | && (! info->symbolic |
| 3942 | || (h->elf_link_hash_flags |
| 3943 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) |
| 3944 | || (!info->shared |
| 3945 | && h != NULL |
| 3946 | && h->dynindx != -1 |
| 3947 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 |
| 3948 | && (((h->elf_link_hash_flags |
| 3949 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
| 3950 | && (h->elf_link_hash_flags |
| 3951 | & ELF_LINK_HASH_DEF_REGULAR) == 0) |
| 3952 | || h->root.type == bfd_link_hash_undefweak |
| 3953 | || h->root.type == bfd_link_hash_undefined))) |
| 3954 | { |
| 3955 | Elf_Internal_Rela outrel; |
| 3956 | boolean skip, relocate; |
| 3957 | asection *sreloc; |
| 3958 | Elf64_External_Rela *loc; |
| 3959 | |
| 3960 | /* When generating a dynamic object, these relocations |
| 3961 | are copied into the output file to be resolved at run |
| 3962 | time. */ |
| 3963 | |
| 3964 | skip = false; |
| 3965 | |
| 3966 | outrel.r_offset = |
| 3967 | _bfd_elf_section_offset (output_bfd, info, input_section, |
| 3968 | rel->r_offset); |
| 3969 | if (outrel.r_offset == (bfd_vma) -1) |
| 3970 | skip = true; |
| 3971 | |
| 3972 | outrel.r_offset += (input_section->output_section->vma |
| 3973 | + input_section->output_offset); |
| 3974 | outrel.r_addend = addend; |
| 3975 | |
| 3976 | if (skip) |
| 3977 | { |
| 3978 | relocate = false; |
| 3979 | memset (&outrel, 0, sizeof outrel); |
| 3980 | } |
| 3981 | else if (h != NULL |
| 3982 | && h->dynindx != -1 |
| 3983 | && !is_opd |
| 3984 | && (!IS_ABSOLUTE_RELOC (r_type) |
| 3985 | || !info->shared |
| 3986 | || !info->symbolic |
| 3987 | || (h->elf_link_hash_flags |
| 3988 | & ELF_LINK_HASH_DEF_REGULAR) == 0)) |
| 3989 | { |
| 3990 | relocate = false; |
| 3991 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
| 3992 | } |
| 3993 | else |
| 3994 | { |
| 3995 | /* This symbol is local, or marked to become local, |
| 3996 | or this is an opd section reloc which must point |
| 3997 | at a local function. */ |
| 3998 | outrel.r_addend += relocation; |
| 3999 | relocate = true; |
| 4000 | if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) |
| 4001 | { |
| 4002 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
| 4003 | } |
| 4004 | else |
| 4005 | { |
| 4006 | long indx = 0; |
| 4007 | |
| 4008 | if (bfd_is_abs_section (sec)) |
| 4009 | ; |
| 4010 | else if (sec == NULL || sec->owner == NULL) |
| 4011 | { |
| 4012 | bfd_set_error (bfd_error_bad_value); |
| 4013 | return false; |
| 4014 | } |
| 4015 | else |
| 4016 | { |
| 4017 | asection *osec; |
| 4018 | |
| 4019 | osec = sec->output_section; |
| 4020 | indx = elf_section_data (osec)->dynindx; |
| 4021 | |
| 4022 | /* We are turning this relocation into one |
| 4023 | against a section symbol, so subtract out |
| 4024 | the output section's address but not the |
| 4025 | offset of the input section in the output |
| 4026 | section. */ |
| 4027 | outrel.r_addend -= osec->vma; |
| 4028 | } |
| 4029 | |
| 4030 | outrel.r_info = ELF64_R_INFO (indx, r_type); |
| 4031 | } |
| 4032 | } |
| 4033 | |
| 4034 | sreloc = elf_section_data (input_section)->sreloc; |
| 4035 | if (sreloc == NULL) |
| 4036 | abort (); |
| 4037 | |
| 4038 | loc = (Elf64_External_Rela *) sreloc->contents; |
| 4039 | loc += sreloc->reloc_count++; |
| 4040 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
| 4041 | |
| 4042 | /* If this reloc is against an external symbol, it will |
| 4043 | be computed at runtime, so there's no need to do |
| 4044 | anything now. */ |
| 4045 | if (! relocate) |
| 4046 | continue; |
| 4047 | } |
| 4048 | break; |
| 4049 | |
| 4050 | case R_PPC64_COPY: |
| 4051 | case R_PPC64_GLOB_DAT: |
| 4052 | case R_PPC64_JMP_SLOT: |
| 4053 | case R_PPC64_RELATIVE: |
| 4054 | /* We shouldn't ever see these dynamic relocs in relocatable |
| 4055 | files. */ |
| 4056 | /* Fall thru */ |
| 4057 | |
| 4058 | case R_PPC64_PLTGOT16: |
| 4059 | case R_PPC64_PLTGOT16_DS: |
| 4060 | case R_PPC64_PLTGOT16_HA: |
| 4061 | case R_PPC64_PLTGOT16_HI: |
| 4062 | case R_PPC64_PLTGOT16_LO: |
| 4063 | case R_PPC64_PLTGOT16_LO_DS: |
| 4064 | case R_PPC64_PLTREL32: |
| 4065 | case R_PPC64_PLTREL64: |
| 4066 | /* These ones haven't been implemented yet. */ |
| 4067 | |
| 4068 | (*_bfd_error_handler) |
| 4069 | (_("%s: Relocation %s is not supported for symbol %s."), |
| 4070 | bfd_archive_filename (input_bfd), |
| 4071 | ppc64_elf_howto_table[(int) r_type]->name, sym_name); |
| 4072 | |
| 4073 | bfd_set_error (bfd_error_invalid_operation); |
| 4074 | ret = false; |
| 4075 | continue; |
| 4076 | } |
| 4077 | |
| 4078 | /* Do any further special processing. */ |
| 4079 | switch (r_type) |
| 4080 | { |
| 4081 | default: |
| 4082 | break; |
| 4083 | |
| 4084 | case R_PPC64_ADDR16_HA: |
| 4085 | case R_PPC64_ADDR16_HIGHERA: |
| 4086 | case R_PPC64_ADDR16_HIGHESTA: |
| 4087 | case R_PPC64_PLT16_HA: |
| 4088 | case R_PPC64_TOC16_HA: |
| 4089 | case R_PPC64_SECTOFF_HA: |
| 4090 | /* It's just possible that this symbol is a weak symbol |
| 4091 | that's not actually defined anywhere. In that case, |
| 4092 | 'sec' would be NULL, and we should leave the symbol |
| 4093 | alone (it will be set to zero elsewhere in the link). */ |
| 4094 | if (sec != NULL) |
| 4095 | /* Add 0x10000 if sign bit in 0:15 is set. */ |
| 4096 | addend += ((relocation + addend) & 0x8000) << 1; |
| 4097 | break; |
| 4098 | |
| 4099 | case R_PPC64_ADDR16_DS: |
| 4100 | case R_PPC64_ADDR16_LO_DS: |
| 4101 | case R_PPC64_GOT16_DS: |
| 4102 | case R_PPC64_GOT16_LO_DS: |
| 4103 | case R_PPC64_PLT16_LO_DS: |
| 4104 | case R_PPC64_SECTOFF_DS: |
| 4105 | case R_PPC64_SECTOFF_LO_DS: |
| 4106 | case R_PPC64_TOC16_DS: |
| 4107 | case R_PPC64_TOC16_LO_DS: |
| 4108 | case R_PPC64_PLTGOT16_DS: |
| 4109 | case R_PPC64_PLTGOT16_LO_DS: |
| 4110 | if (((relocation + addend) & 3) != 0) |
| 4111 | { |
| 4112 | (*_bfd_error_handler) |
| 4113 | (_("%s: error: relocation %s not a multiple of 4"), |
| 4114 | bfd_archive_filename (input_bfd), |
| 4115 | ppc64_elf_howto_table[(int) r_type]->name); |
| 4116 | bfd_set_error (bfd_error_bad_value); |
| 4117 | ret = false; |
| 4118 | continue; |
| 4119 | } |
| 4120 | break; |
| 4121 | } |
| 4122 | |
| 4123 | /* FIXME: Why do we allow debugging sections to escape this error? |
| 4124 | More importantly, why do we not emit dynamic relocs above in |
| 4125 | debugging sections (which are ! SEC_ALLOC)? If we had |
| 4126 | emitted the dynamic reloc, we could remove the fudge here. */ |
| 4127 | if (unresolved_reloc |
| 4128 | && !(info->shared |
| 4129 | && (input_section->flags & SEC_DEBUGGING) != 0 |
| 4130 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) |
| 4131 | (*_bfd_error_handler) |
| 4132 | (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"), |
| 4133 | bfd_archive_filename (input_bfd), |
| 4134 | bfd_get_section_name (input_bfd, input_section), |
| 4135 | (long) rel->r_offset, |
| 4136 | h->root.root.string); |
| 4137 | |
| 4138 | r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type], |
| 4139 | input_bfd, |
| 4140 | input_section, |
| 4141 | contents, |
| 4142 | offset, |
| 4143 | relocation, |
| 4144 | addend); |
| 4145 | |
| 4146 | if (r == bfd_reloc_ok) |
| 4147 | ; |
| 4148 | else if (r == bfd_reloc_overflow) |
| 4149 | { |
| 4150 | const char *name; |
| 4151 | |
| 4152 | if (h != NULL) |
| 4153 | { |
| 4154 | if (h->root.type == bfd_link_hash_undefweak |
| 4155 | && ppc64_elf_howto_table[(int) r_type]->pc_relative) |
| 4156 | { |
| 4157 | /* Assume this is a call protected by other code that |
| 4158 | detects the symbol is undefined. If this is the case, |
| 4159 | we can safely ignore the overflow. If not, the |
| 4160 | program is hosed anyway, and a little warning isn't |
| 4161 | going to help. */ |
| 4162 | |
| 4163 | continue; |
| 4164 | } |
| 4165 | |
| 4166 | name = h->root.root.string; |
| 4167 | } |
| 4168 | else |
| 4169 | { |
| 4170 | name = bfd_elf_string_from_elf_section (input_bfd, |
| 4171 | symtab_hdr->sh_link, |
| 4172 | sym->st_name); |
| 4173 | if (name == NULL) |
| 4174 | continue; |
| 4175 | if (*name == '\0') |
| 4176 | name = bfd_section_name (input_bfd, sec); |
| 4177 | } |
| 4178 | |
| 4179 | if (! ((*info->callbacks->reloc_overflow) |
| 4180 | (info, name, ppc64_elf_howto_table[(int) r_type]->name, |
| 4181 | (bfd_vma) 0, input_bfd, input_section, offset))) |
| 4182 | return false; |
| 4183 | } |
| 4184 | else |
| 4185 | ret = false; |
| 4186 | } |
| 4187 | |
| 4188 | return ret; |
| 4189 | } |
| 4190 | |
| 4191 | /* Finish up dynamic symbol handling. We set the contents of various |
| 4192 | dynamic sections here. */ |
| 4193 | |
| 4194 | static boolean |
| 4195 | ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym) |
| 4196 | bfd *output_bfd; |
| 4197 | struct bfd_link_info *info; |
| 4198 | struct elf_link_hash_entry *h; |
| 4199 | Elf_Internal_Sym *sym; |
| 4200 | { |
| 4201 | struct ppc_link_hash_table *htab; |
| 4202 | bfd *dynobj; |
| 4203 | |
| 4204 | htab = ppc_hash_table (info); |
| 4205 | dynobj = htab->elf.dynobj; |
| 4206 | |
| 4207 | if (h->plt.offset != (bfd_vma) -1 |
| 4208 | && ((struct ppc_link_hash_entry *) h)->is_func_descriptor) |
| 4209 | { |
| 4210 | Elf_Internal_Rela rela; |
| 4211 | Elf64_External_Rela *loc; |
| 4212 | |
| 4213 | /* This symbol has an entry in the procedure linkage table. Set |
| 4214 | it up. */ |
| 4215 | |
| 4216 | if (htab->splt == NULL |
| 4217 | || htab->srelplt == NULL |
| 4218 | || htab->sglink == NULL) |
| 4219 | abort (); |
| 4220 | |
| 4221 | /* Create a JMP_SLOT reloc to inform the dynamic linker to |
| 4222 | fill in the PLT entry. */ |
| 4223 | |
| 4224 | rela.r_offset = (htab->splt->output_section->vma |
| 4225 | + htab->splt->output_offset |
| 4226 | + h->plt.offset); |
| 4227 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT); |
| 4228 | rela.r_addend = 0; |
| 4229 | |
| 4230 | loc = (Elf64_External_Rela *) htab->srelplt->contents; |
| 4231 | loc += (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE; |
| 4232 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
| 4233 | } |
| 4234 | |
| 4235 | if (h->got.offset != (bfd_vma) -1) |
| 4236 | { |
| 4237 | Elf_Internal_Rela rela; |
| 4238 | Elf64_External_Rela *loc; |
| 4239 | |
| 4240 | /* This symbol has an entry in the global offset table. Set it |
| 4241 | up. */ |
| 4242 | |
| 4243 | if (htab->sgot == NULL || htab->srelgot == NULL) |
| 4244 | abort (); |
| 4245 | |
| 4246 | rela.r_offset = (htab->sgot->output_section->vma |
| 4247 | + htab->sgot->output_offset |
| 4248 | + (h->got.offset &~ (bfd_vma) 1)); |
| 4249 | |
| 4250 | /* If this is a static link, or it is a -Bsymbolic link and the |
| 4251 | symbol is defined locally or was forced to be local because |
| 4252 | of a version file, we just want to emit a RELATIVE reloc. |
| 4253 | The entry in the global offset table will already have been |
| 4254 | initialized in the relocate_section function. */ |
| 4255 | if (info->shared |
| 4256 | && (info->symbolic |
| 4257 | || h->dynindx == -1 |
| 4258 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) |
| 4259 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) |
| 4260 | { |
| 4261 | BFD_ASSERT((h->got.offset & 1) != 0); |
| 4262 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
| 4263 | rela.r_addend = (h->root.u.def.value |
| 4264 | + h->root.u.def.section->output_section->vma |
| 4265 | + h->root.u.def.section->output_offset); |
| 4266 | } |
| 4267 | else |
| 4268 | { |
| 4269 | BFD_ASSERT ((h->got.offset & 1) == 0); |
| 4270 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
| 4271 | htab->sgot->contents + h->got.offset); |
| 4272 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_GLOB_DAT); |
| 4273 | rela.r_addend = 0; |
| 4274 | } |
| 4275 | |
| 4276 | loc = (Elf64_External_Rela *) htab->srelgot->contents; |
| 4277 | loc += htab->srelgot->reloc_count++; |
| 4278 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
| 4279 | } |
| 4280 | |
| 4281 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) |
| 4282 | { |
| 4283 | Elf_Internal_Rela rela; |
| 4284 | Elf64_External_Rela *loc; |
| 4285 | |
| 4286 | /* This symbol needs a copy reloc. Set it up. */ |
| 4287 | |
| 4288 | if (h->dynindx == -1 |
| 4289 | || (h->root.type != bfd_link_hash_defined |
| 4290 | && h->root.type != bfd_link_hash_defweak) |
| 4291 | || htab->srelbss == NULL) |
| 4292 | abort (); |
| 4293 | |
| 4294 | rela.r_offset = (h->root.u.def.value |
| 4295 | + h->root.u.def.section->output_section->vma |
| 4296 | + h->root.u.def.section->output_offset); |
| 4297 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY); |
| 4298 | rela.r_addend = 0; |
| 4299 | loc = (Elf64_External_Rela *) htab->srelbss->contents; |
| 4300 | loc += htab->srelbss->reloc_count++; |
| 4301 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
| 4302 | } |
| 4303 | |
| 4304 | /* Mark some specially defined symbols as absolute. */ |
| 4305 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0) |
| 4306 | sym->st_shndx = SHN_ABS; |
| 4307 | |
| 4308 | return true; |
| 4309 | } |
| 4310 | |
| 4311 | /* Used to decide how to sort relocs in an optimal manner for the |
| 4312 | dynamic linker, before writing them out. */ |
| 4313 | |
| 4314 | static enum elf_reloc_type_class |
| 4315 | ppc64_elf_reloc_type_class (rela) |
| 4316 | const Elf_Internal_Rela *rela; |
| 4317 | { |
| 4318 | enum elf_ppc_reloc_type r_type; |
| 4319 | |
| 4320 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rela->r_info); |
| 4321 | switch (r_type) |
| 4322 | { |
| 4323 | case R_PPC64_RELATIVE: |
| 4324 | return reloc_class_relative; |
| 4325 | case R_PPC64_JMP_SLOT: |
| 4326 | return reloc_class_plt; |
| 4327 | case R_PPC64_COPY: |
| 4328 | return reloc_class_copy; |
| 4329 | default: |
| 4330 | return reloc_class_normal; |
| 4331 | } |
| 4332 | } |
| 4333 | |
| 4334 | /* Finish up the dynamic sections. */ |
| 4335 | |
| 4336 | static boolean |
| 4337 | ppc64_elf_finish_dynamic_sections (output_bfd, info) |
| 4338 | bfd *output_bfd; |
| 4339 | struct bfd_link_info *info; |
| 4340 | { |
| 4341 | struct ppc_link_hash_table *htab; |
| 4342 | bfd *dynobj; |
| 4343 | asection *sdyn; |
| 4344 | |
| 4345 | htab = ppc_hash_table (info); |
| 4346 | dynobj = htab->elf.dynobj; |
| 4347 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
| 4348 | |
| 4349 | if (htab->elf.dynamic_sections_created) |
| 4350 | { |
| 4351 | Elf64_External_Dyn *dyncon, *dynconend; |
| 4352 | |
| 4353 | if (sdyn == NULL || htab->sgot == NULL) |
| 4354 | abort (); |
| 4355 | |
| 4356 | dyncon = (Elf64_External_Dyn *) sdyn->contents; |
| 4357 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size); |
| 4358 | for (; dyncon < dynconend; dyncon++) |
| 4359 | { |
| 4360 | Elf_Internal_Dyn dyn; |
| 4361 | asection *s; |
| 4362 | |
| 4363 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); |
| 4364 | |
| 4365 | switch (dyn.d_tag) |
| 4366 | { |
| 4367 | default: |
| 4368 | continue; |
| 4369 | |
| 4370 | case DT_PPC64_GLINK: |
| 4371 | dyn.d_un.d_ptr = (htab->sglink->output_section->vma |
| 4372 | + htab->sglink->output_offset); |
| 4373 | break; |
| 4374 | |
| 4375 | case DT_PPC64_OPD: |
| 4376 | s = bfd_get_section_by_name (output_bfd, ".opd"); |
| 4377 | if (s != NULL) |
| 4378 | dyn.d_un.d_ptr = s->vma; |
| 4379 | break; |
| 4380 | |
| 4381 | case DT_PPC64_OPDSZ: |
| 4382 | s = bfd_get_section_by_name (output_bfd, ".opd"); |
| 4383 | if (s != NULL) |
| 4384 | dyn.d_un.d_val = s->_raw_size; |
| 4385 | break; |
| 4386 | |
| 4387 | case DT_PLTGOT: |
| 4388 | dyn.d_un.d_ptr = (htab->splt->output_section->vma |
| 4389 | + htab->splt->output_offset); |
| 4390 | break; |
| 4391 | |
| 4392 | case DT_JMPREL: |
| 4393 | dyn.d_un.d_ptr = (htab->srelplt->output_section->vma |
| 4394 | + htab->srelplt->output_offset); |
| 4395 | break; |
| 4396 | |
| 4397 | case DT_PLTRELSZ: |
| 4398 | dyn.d_un.d_val = htab->srelplt->_raw_size; |
| 4399 | break; |
| 4400 | |
| 4401 | case DT_RELASZ: |
| 4402 | /* Don't count procedure linkage table relocs in the |
| 4403 | overall reloc count. */ |
| 4404 | if (htab->srelplt != NULL) |
| 4405 | dyn.d_un.d_val -= htab->srelplt->_raw_size; |
| 4406 | break; |
| 4407 | } |
| 4408 | |
| 4409 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 4410 | } |
| 4411 | } |
| 4412 | |
| 4413 | if (htab->sgot != NULL && htab->sgot->_raw_size != 0) |
| 4414 | { |
| 4415 | /* Fill in the first entry in the global offset table. |
| 4416 | We use it to hold the link-time TOCbase. */ |
| 4417 | bfd_put_64 (output_bfd, |
| 4418 | elf_gp (output_bfd) + TOC_BASE_OFF, |
| 4419 | htab->sgot->contents); |
| 4420 | |
| 4421 | /* Set .got entry size. */ |
| 4422 | elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 8; |
| 4423 | } |
| 4424 | |
| 4425 | if (htab->splt != NULL && htab->splt->_raw_size != 0) |
| 4426 | { |
| 4427 | /* Set .plt entry size. */ |
| 4428 | elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize |
| 4429 | = PLT_ENTRY_SIZE; |
| 4430 | } |
| 4431 | |
| 4432 | return true; |
| 4433 | } |
| 4434 | |
| 4435 | #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec |
| 4436 | #define TARGET_LITTLE_NAME "elf64-powerpcle" |
| 4437 | #define TARGET_BIG_SYM bfd_elf64_powerpc_vec |
| 4438 | #define TARGET_BIG_NAME "elf64-powerpc" |
| 4439 | #define ELF_ARCH bfd_arch_powerpc |
| 4440 | #define ELF_MACHINE_CODE EM_PPC64 |
| 4441 | #define ELF_MAXPAGESIZE 0x10000 |
| 4442 | #define elf_info_to_howto ppc64_elf_info_to_howto |
| 4443 | |
| 4444 | #ifdef EM_CYGNUS_POWERPC |
| 4445 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC |
| 4446 | #endif |
| 4447 | |
| 4448 | #ifdef EM_PPC_OLD |
| 4449 | #define ELF_MACHINE_ALT2 EM_PPC_OLD |
| 4450 | #endif |
| 4451 | |
| 4452 | #define elf_backend_want_got_sym 0 |
| 4453 | #define elf_backend_want_plt_sym 0 |
| 4454 | #define elf_backend_plt_alignment 3 |
| 4455 | #define elf_backend_plt_not_loaded 1 |
| 4456 | #define elf_backend_got_symbol_offset 0 |
| 4457 | #define elf_backend_got_header_size 8 |
| 4458 | #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE |
| 4459 | #define elf_backend_can_gc_sections 1 |
| 4460 | #define elf_backend_can_refcount 1 |
| 4461 | |
| 4462 | #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup |
| 4463 | #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags |
| 4464 | #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data |
| 4465 | #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create |
| 4466 | |
| 4467 | #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr |
| 4468 | #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections |
| 4469 | #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol |
| 4470 | #define elf_backend_check_relocs ppc64_elf_check_relocs |
| 4471 | #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook |
| 4472 | #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook |
| 4473 | #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol |
| 4474 | #define elf_backend_hide_symbol ppc64_elf_hide_symbol |
| 4475 | #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust |
| 4476 | #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections |
| 4477 | #define elf_backend_fake_sections ppc64_elf_fake_sections |
| 4478 | #define elf_backend_relocate_section ppc64_elf_relocate_section |
| 4479 | #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol |
| 4480 | #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class |
| 4481 | #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections |
| 4482 | |
| 4483 | #include "elf64-target.h" |