| 1 | /* PowerPC64-specific support for 64-bit ELF. |
| 2 | Copyright 1999, 2000, 2001, 2002, 2003, 2004 |
| 3 | Free Software Foundation, Inc. |
| 4 | Written by Linus Nordberg, Swox AB <info@swox.com>, |
| 5 | based on elf32-ppc.c by Ian Lance Taylor. |
| 6 | Largely rewritten by Alan Modra <amodra@bigpond.net.au> |
| 7 | |
| 8 | This file is part of BFD, the Binary File Descriptor library. |
| 9 | |
| 10 | This program is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; either version 2 of the License, or |
| 13 | (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License along |
| 21 | with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 23 | |
| 24 | /* The 64-bit PowerPC ELF ABI may be found at |
| 25 | http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and |
| 26 | http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */ |
| 27 | |
| 28 | #include "bfd.h" |
| 29 | #include "sysdep.h" |
| 30 | #include "bfdlink.h" |
| 31 | #include "libbfd.h" |
| 32 | #include "elf-bfd.h" |
| 33 | #include "elf/ppc64.h" |
| 34 | #include "elf64-ppc.h" |
| 35 | |
| 36 | static bfd_reloc_status_type ppc64_elf_ha_reloc |
| 37 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 38 | static bfd_reloc_status_type ppc64_elf_brtaken_reloc |
| 39 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 40 | static bfd_reloc_status_type ppc64_elf_sectoff_reloc |
| 41 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 42 | static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc |
| 43 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 44 | static bfd_reloc_status_type ppc64_elf_toc_reloc |
| 45 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 46 | static bfd_reloc_status_type ppc64_elf_toc_ha_reloc |
| 47 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 48 | static bfd_reloc_status_type ppc64_elf_toc64_reloc |
| 49 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 50 | static bfd_reloc_status_type ppc64_elf_unhandled_reloc |
| 51 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 52 | |
| 53 | |
| 54 | #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec |
| 55 | #define TARGET_LITTLE_NAME "elf64-powerpcle" |
| 56 | #define TARGET_BIG_SYM bfd_elf64_powerpc_vec |
| 57 | #define TARGET_BIG_NAME "elf64-powerpc" |
| 58 | #define ELF_ARCH bfd_arch_powerpc |
| 59 | #define ELF_MACHINE_CODE EM_PPC64 |
| 60 | #define ELF_MAXPAGESIZE 0x10000 |
| 61 | #define elf_info_to_howto ppc64_elf_info_to_howto |
| 62 | |
| 63 | #define elf_backend_want_got_sym 0 |
| 64 | #define elf_backend_want_plt_sym 0 |
| 65 | #define elf_backend_plt_alignment 3 |
| 66 | #define elf_backend_plt_not_loaded 1 |
| 67 | #define elf_backend_got_symbol_offset 0 |
| 68 | #define elf_backend_got_header_size 8 |
| 69 | #define elf_backend_can_gc_sections 1 |
| 70 | #define elf_backend_can_refcount 1 |
| 71 | #define elf_backend_rela_normal 1 |
| 72 | |
| 73 | #define bfd_elf64_mkobject ppc64_elf_mkobject |
| 74 | #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup |
| 75 | #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data |
| 76 | #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook |
| 77 | #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create |
| 78 | #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free |
| 79 | |
| 80 | #define elf_backend_object_p ppc64_elf_object_p |
| 81 | #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus |
| 82 | #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo |
| 83 | #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections |
| 84 | #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol |
| 85 | #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook |
| 86 | #define elf_backend_check_relocs ppc64_elf_check_relocs |
| 87 | #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook |
| 88 | #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook |
| 89 | #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol |
| 90 | #define elf_backend_hide_symbol ppc64_elf_hide_symbol |
| 91 | #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust |
| 92 | #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections |
| 93 | #define elf_backend_relocate_section ppc64_elf_relocate_section |
| 94 | #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol |
| 95 | #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class |
| 96 | #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections |
| 97 | #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook |
| 98 | #define elf_backend_special_sections ppc64_elf_special_sections |
| 99 | |
| 100 | /* The name of the dynamic interpreter. This is put in the .interp |
| 101 | section. */ |
| 102 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
| 103 | |
| 104 | /* The size in bytes of an entry in the procedure linkage table. */ |
| 105 | #define PLT_ENTRY_SIZE 24 |
| 106 | |
| 107 | /* The initial size of the plt reserved for the dynamic linker. */ |
| 108 | #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE |
| 109 | |
| 110 | /* TOC base pointers offset from start of TOC. */ |
| 111 | #define TOC_BASE_OFF 0x8000 |
| 112 | |
| 113 | /* Offset of tp and dtp pointers from start of TLS block. */ |
| 114 | #define TP_OFFSET 0x7000 |
| 115 | #define DTP_OFFSET 0x8000 |
| 116 | |
| 117 | /* .plt call stub instructions. The normal stub is like this, but |
| 118 | sometimes the .plt entry crosses a 64k boundary and we need to |
| 119 | insert an addis to adjust r12. */ |
| 120 | #define PLT_CALL_STUB_SIZE (7*4) |
| 121 | #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ |
| 122 | #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ |
| 123 | #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ |
| 124 | #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ |
| 125 | #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ |
| 126 | /* ld %r11,xxx+16@l(%r12) */ |
| 127 | #define BCTR 0x4e800420 /* bctr */ |
| 128 | |
| 129 | |
| 130 | #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */ |
| 131 | #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */ |
| 132 | |
| 133 | #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ |
| 134 | |
| 135 | /* glink call stub instructions. We enter with the index in R0, and the |
| 136 | address of glink entry in CTR. From that, we can calculate PLT0. */ |
| 137 | #define GLINK_CALL_STUB_SIZE (16*4) |
| 138 | #define MFCTR_R12 0x7d8902a6 /* mfctr %r12 */ |
| 139 | #define SLDI_R11_R0_3 0x780b1f24 /* sldi %r11,%r0,3 */ |
| 140 | #define ADDIC_R2_R0_32K 0x34408000 /* addic. %r2,%r0,-32768 */ |
| 141 | #define SUB_R12_R12_R11 0x7d8b6050 /* sub %r12,%r12,%r11 */ |
| 142 | #define SRADI_R2_R2_63 0x7c42fe76 /* sradi %r2,%r2,63 */ |
| 143 | #define SLDI_R11_R0_2 0x780b1764 /* sldi %r11,%r0,2 */ |
| 144 | #define AND_R2_R2_R11 0x7c425838 /* and %r2,%r2,%r11 */ |
| 145 | /* sub %r12,%r12,%r11 */ |
| 146 | #define ADD_R12_R12_R2 0x7d8c1214 /* add %r12,%r12,%r2 */ |
| 147 | #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */ |
| 148 | /* ld %r11,xxx@l(%r12) */ |
| 149 | #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,xxx@l */ |
| 150 | /* ld %r2,8(%r12) */ |
| 151 | /* mtctr %r11 */ |
| 152 | /* ld %r11,16(%r12) */ |
| 153 | /* bctr */ |
| 154 | |
| 155 | /* Pad with this. */ |
| 156 | #define NOP 0x60000000 |
| 157 | |
| 158 | /* Some other nops. */ |
| 159 | #define CROR_151515 0x4def7b82 |
| 160 | #define CROR_313131 0x4ffffb82 |
| 161 | |
| 162 | /* .glink entries for the first 32k functions are two instructions. */ |
| 163 | #define LI_R0_0 0x38000000 /* li %r0,0 */ |
| 164 | #define B_DOT 0x48000000 /* b . */ |
| 165 | |
| 166 | /* After that, we need two instructions to load the index, followed by |
| 167 | a branch. */ |
| 168 | #define LIS_R0_0 0x3c000000 /* lis %r0,0 */ |
| 169 | #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */ |
| 170 | |
| 171 | /* Instructions to save and restore floating point regs. */ |
| 172 | #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */ |
| 173 | #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */ |
| 174 | #define BLR 0x4e800020 /* blr */ |
| 175 | |
| 176 | /* Since .opd is an array of descriptors and each entry will end up |
| 177 | with identical R_PPC64_RELATIVE relocs, there is really no need to |
| 178 | propagate .opd relocs; The dynamic linker should be taught to |
| 179 | relocate .opd without reloc entries. */ |
| 180 | #ifndef NO_OPD_RELOCS |
| 181 | #define NO_OPD_RELOCS 0 |
| 182 | #endif |
| 183 | \f |
| 184 | #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1) |
| 185 | |
| 186 | /* Relocation HOWTO's. */ |
| 187 | static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max]; |
| 188 | |
| 189 | static reloc_howto_type ppc64_elf_howto_raw[] = { |
| 190 | /* This reloc does nothing. */ |
| 191 | HOWTO (R_PPC64_NONE, /* type */ |
| 192 | 0, /* rightshift */ |
| 193 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 194 | 32, /* bitsize */ |
| 195 | FALSE, /* pc_relative */ |
| 196 | 0, /* bitpos */ |
| 197 | complain_overflow_dont, /* complain_on_overflow */ |
| 198 | bfd_elf_generic_reloc, /* special_function */ |
| 199 | "R_PPC64_NONE", /* name */ |
| 200 | FALSE, /* partial_inplace */ |
| 201 | 0, /* src_mask */ |
| 202 | 0, /* dst_mask */ |
| 203 | FALSE), /* pcrel_offset */ |
| 204 | |
| 205 | /* A standard 32 bit relocation. */ |
| 206 | HOWTO (R_PPC64_ADDR32, /* type */ |
| 207 | 0, /* rightshift */ |
| 208 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 209 | 32, /* bitsize */ |
| 210 | FALSE, /* pc_relative */ |
| 211 | 0, /* bitpos */ |
| 212 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 213 | bfd_elf_generic_reloc, /* special_function */ |
| 214 | "R_PPC64_ADDR32", /* name */ |
| 215 | FALSE, /* partial_inplace */ |
| 216 | 0, /* src_mask */ |
| 217 | 0xffffffff, /* dst_mask */ |
| 218 | FALSE), /* pcrel_offset */ |
| 219 | |
| 220 | /* An absolute 26 bit branch; the lower two bits must be zero. |
| 221 | FIXME: we don't check that, we just clear them. */ |
| 222 | HOWTO (R_PPC64_ADDR24, /* type */ |
| 223 | 0, /* rightshift */ |
| 224 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 225 | 26, /* bitsize */ |
| 226 | FALSE, /* pc_relative */ |
| 227 | 0, /* bitpos */ |
| 228 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 229 | bfd_elf_generic_reloc, /* special_function */ |
| 230 | "R_PPC64_ADDR24", /* name */ |
| 231 | FALSE, /* partial_inplace */ |
| 232 | 0, /* src_mask */ |
| 233 | 0x03fffffc, /* dst_mask */ |
| 234 | FALSE), /* pcrel_offset */ |
| 235 | |
| 236 | /* A standard 16 bit relocation. */ |
| 237 | HOWTO (R_PPC64_ADDR16, /* type */ |
| 238 | 0, /* rightshift */ |
| 239 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 240 | 16, /* bitsize */ |
| 241 | FALSE, /* pc_relative */ |
| 242 | 0, /* bitpos */ |
| 243 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 244 | bfd_elf_generic_reloc, /* special_function */ |
| 245 | "R_PPC64_ADDR16", /* name */ |
| 246 | FALSE, /* partial_inplace */ |
| 247 | 0, /* src_mask */ |
| 248 | 0xffff, /* dst_mask */ |
| 249 | FALSE), /* pcrel_offset */ |
| 250 | |
| 251 | /* A 16 bit relocation without overflow. */ |
| 252 | HOWTO (R_PPC64_ADDR16_LO, /* type */ |
| 253 | 0, /* rightshift */ |
| 254 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 255 | 16, /* bitsize */ |
| 256 | FALSE, /* pc_relative */ |
| 257 | 0, /* bitpos */ |
| 258 | complain_overflow_dont,/* complain_on_overflow */ |
| 259 | bfd_elf_generic_reloc, /* special_function */ |
| 260 | "R_PPC64_ADDR16_LO", /* name */ |
| 261 | FALSE, /* partial_inplace */ |
| 262 | 0, /* src_mask */ |
| 263 | 0xffff, /* dst_mask */ |
| 264 | FALSE), /* pcrel_offset */ |
| 265 | |
| 266 | /* Bits 16-31 of an address. */ |
| 267 | HOWTO (R_PPC64_ADDR16_HI, /* type */ |
| 268 | 16, /* rightshift */ |
| 269 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 270 | 16, /* bitsize */ |
| 271 | FALSE, /* pc_relative */ |
| 272 | 0, /* bitpos */ |
| 273 | complain_overflow_dont, /* complain_on_overflow */ |
| 274 | bfd_elf_generic_reloc, /* special_function */ |
| 275 | "R_PPC64_ADDR16_HI", /* name */ |
| 276 | FALSE, /* partial_inplace */ |
| 277 | 0, /* src_mask */ |
| 278 | 0xffff, /* dst_mask */ |
| 279 | FALSE), /* pcrel_offset */ |
| 280 | |
| 281 | /* Bits 16-31 of an address, plus 1 if the contents of the low 16 |
| 282 | bits, treated as a signed number, is negative. */ |
| 283 | HOWTO (R_PPC64_ADDR16_HA, /* type */ |
| 284 | 16, /* rightshift */ |
| 285 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 286 | 16, /* bitsize */ |
| 287 | FALSE, /* pc_relative */ |
| 288 | 0, /* bitpos */ |
| 289 | complain_overflow_dont, /* complain_on_overflow */ |
| 290 | ppc64_elf_ha_reloc, /* special_function */ |
| 291 | "R_PPC64_ADDR16_HA", /* name */ |
| 292 | FALSE, /* partial_inplace */ |
| 293 | 0, /* src_mask */ |
| 294 | 0xffff, /* dst_mask */ |
| 295 | FALSE), /* pcrel_offset */ |
| 296 | |
| 297 | /* An absolute 16 bit branch; the lower two bits must be zero. |
| 298 | FIXME: we don't check that, we just clear them. */ |
| 299 | HOWTO (R_PPC64_ADDR14, /* type */ |
| 300 | 0, /* rightshift */ |
| 301 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 302 | 16, /* bitsize */ |
| 303 | FALSE, /* pc_relative */ |
| 304 | 0, /* bitpos */ |
| 305 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 306 | bfd_elf_generic_reloc, /* special_function */ |
| 307 | "R_PPC64_ADDR14", /* name */ |
| 308 | FALSE, /* partial_inplace */ |
| 309 | 0, /* src_mask */ |
| 310 | 0x0000fffc, /* dst_mask */ |
| 311 | FALSE), /* pcrel_offset */ |
| 312 | |
| 313 | /* An absolute 16 bit branch, for which bit 10 should be set to |
| 314 | indicate that the branch is expected to be taken. The lower two |
| 315 | bits must be zero. */ |
| 316 | HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */ |
| 317 | 0, /* rightshift */ |
| 318 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 319 | 16, /* bitsize */ |
| 320 | FALSE, /* pc_relative */ |
| 321 | 0, /* bitpos */ |
| 322 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 323 | ppc64_elf_brtaken_reloc, /* special_function */ |
| 324 | "R_PPC64_ADDR14_BRTAKEN",/* name */ |
| 325 | FALSE, /* partial_inplace */ |
| 326 | 0, /* src_mask */ |
| 327 | 0x0000fffc, /* dst_mask */ |
| 328 | FALSE), /* pcrel_offset */ |
| 329 | |
| 330 | /* An absolute 16 bit branch, for which bit 10 should be set to |
| 331 | indicate that the branch is not expected to be taken. The lower |
| 332 | two bits must be zero. */ |
| 333 | HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */ |
| 334 | 0, /* rightshift */ |
| 335 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 336 | 16, /* bitsize */ |
| 337 | FALSE, /* pc_relative */ |
| 338 | 0, /* bitpos */ |
| 339 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 340 | ppc64_elf_brtaken_reloc, /* special_function */ |
| 341 | "R_PPC64_ADDR14_BRNTAKEN",/* name */ |
| 342 | FALSE, /* partial_inplace */ |
| 343 | 0, /* src_mask */ |
| 344 | 0x0000fffc, /* dst_mask */ |
| 345 | FALSE), /* pcrel_offset */ |
| 346 | |
| 347 | /* A relative 26 bit branch; the lower two bits must be zero. */ |
| 348 | HOWTO (R_PPC64_REL24, /* type */ |
| 349 | 0, /* rightshift */ |
| 350 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 351 | 26, /* bitsize */ |
| 352 | TRUE, /* pc_relative */ |
| 353 | 0, /* bitpos */ |
| 354 | complain_overflow_signed, /* complain_on_overflow */ |
| 355 | bfd_elf_generic_reloc, /* special_function */ |
| 356 | "R_PPC64_REL24", /* name */ |
| 357 | FALSE, /* partial_inplace */ |
| 358 | 0, /* src_mask */ |
| 359 | 0x03fffffc, /* dst_mask */ |
| 360 | TRUE), /* pcrel_offset */ |
| 361 | |
| 362 | /* A relative 16 bit branch; the lower two bits must be zero. */ |
| 363 | HOWTO (R_PPC64_REL14, /* type */ |
| 364 | 0, /* rightshift */ |
| 365 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 366 | 16, /* bitsize */ |
| 367 | TRUE, /* pc_relative */ |
| 368 | 0, /* bitpos */ |
| 369 | complain_overflow_signed, /* complain_on_overflow */ |
| 370 | bfd_elf_generic_reloc, /* special_function */ |
| 371 | "R_PPC64_REL14", /* name */ |
| 372 | FALSE, /* partial_inplace */ |
| 373 | 0, /* src_mask */ |
| 374 | 0x0000fffc, /* dst_mask */ |
| 375 | TRUE), /* pcrel_offset */ |
| 376 | |
| 377 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
| 378 | the branch is expected to be taken. The lower two bits must be |
| 379 | zero. */ |
| 380 | HOWTO (R_PPC64_REL14_BRTAKEN, /* type */ |
| 381 | 0, /* rightshift */ |
| 382 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 383 | 16, /* bitsize */ |
| 384 | TRUE, /* pc_relative */ |
| 385 | 0, /* bitpos */ |
| 386 | complain_overflow_signed, /* complain_on_overflow */ |
| 387 | ppc64_elf_brtaken_reloc, /* special_function */ |
| 388 | "R_PPC64_REL14_BRTAKEN", /* name */ |
| 389 | FALSE, /* partial_inplace */ |
| 390 | 0, /* src_mask */ |
| 391 | 0x0000fffc, /* dst_mask */ |
| 392 | TRUE), /* pcrel_offset */ |
| 393 | |
| 394 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
| 395 | the branch is not expected to be taken. The lower two bits must |
| 396 | be zero. */ |
| 397 | HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */ |
| 398 | 0, /* rightshift */ |
| 399 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 400 | 16, /* bitsize */ |
| 401 | TRUE, /* pc_relative */ |
| 402 | 0, /* bitpos */ |
| 403 | complain_overflow_signed, /* complain_on_overflow */ |
| 404 | ppc64_elf_brtaken_reloc, /* special_function */ |
| 405 | "R_PPC64_REL14_BRNTAKEN",/* name */ |
| 406 | FALSE, /* partial_inplace */ |
| 407 | 0, /* src_mask */ |
| 408 | 0x0000fffc, /* dst_mask */ |
| 409 | TRUE), /* pcrel_offset */ |
| 410 | |
| 411 | /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the |
| 412 | symbol. */ |
| 413 | HOWTO (R_PPC64_GOT16, /* type */ |
| 414 | 0, /* rightshift */ |
| 415 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 416 | 16, /* bitsize */ |
| 417 | FALSE, /* pc_relative */ |
| 418 | 0, /* bitpos */ |
| 419 | complain_overflow_signed, /* complain_on_overflow */ |
| 420 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 421 | "R_PPC64_GOT16", /* name */ |
| 422 | FALSE, /* partial_inplace */ |
| 423 | 0, /* src_mask */ |
| 424 | 0xffff, /* dst_mask */ |
| 425 | FALSE), /* pcrel_offset */ |
| 426 | |
| 427 | /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for |
| 428 | the symbol. */ |
| 429 | HOWTO (R_PPC64_GOT16_LO, /* type */ |
| 430 | 0, /* rightshift */ |
| 431 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 432 | 16, /* bitsize */ |
| 433 | FALSE, /* pc_relative */ |
| 434 | 0, /* bitpos */ |
| 435 | complain_overflow_dont, /* complain_on_overflow */ |
| 436 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 437 | "R_PPC64_GOT16_LO", /* name */ |
| 438 | FALSE, /* partial_inplace */ |
| 439 | 0, /* src_mask */ |
| 440 | 0xffff, /* dst_mask */ |
| 441 | FALSE), /* pcrel_offset */ |
| 442 | |
| 443 | /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for |
| 444 | the symbol. */ |
| 445 | HOWTO (R_PPC64_GOT16_HI, /* type */ |
| 446 | 16, /* rightshift */ |
| 447 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 448 | 16, /* bitsize */ |
| 449 | FALSE, /* pc_relative */ |
| 450 | 0, /* bitpos */ |
| 451 | complain_overflow_dont,/* complain_on_overflow */ |
| 452 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 453 | "R_PPC64_GOT16_HI", /* name */ |
| 454 | FALSE, /* partial_inplace */ |
| 455 | 0, /* src_mask */ |
| 456 | 0xffff, /* dst_mask */ |
| 457 | FALSE), /* pcrel_offset */ |
| 458 | |
| 459 | /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for |
| 460 | the symbol. */ |
| 461 | HOWTO (R_PPC64_GOT16_HA, /* type */ |
| 462 | 16, /* rightshift */ |
| 463 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 464 | 16, /* bitsize */ |
| 465 | FALSE, /* pc_relative */ |
| 466 | 0, /* bitpos */ |
| 467 | complain_overflow_dont,/* complain_on_overflow */ |
| 468 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 469 | "R_PPC64_GOT16_HA", /* name */ |
| 470 | FALSE, /* partial_inplace */ |
| 471 | 0, /* src_mask */ |
| 472 | 0xffff, /* dst_mask */ |
| 473 | FALSE), /* pcrel_offset */ |
| 474 | |
| 475 | /* This is used only by the dynamic linker. The symbol should exist |
| 476 | both in the object being run and in some shared library. The |
| 477 | dynamic linker copies the data addressed by the symbol from the |
| 478 | shared library into the object, because the object being |
| 479 | run has to have the data at some particular address. */ |
| 480 | HOWTO (R_PPC64_COPY, /* type */ |
| 481 | 0, /* rightshift */ |
| 482 | 0, /* this one is variable size */ |
| 483 | 0, /* bitsize */ |
| 484 | FALSE, /* pc_relative */ |
| 485 | 0, /* bitpos */ |
| 486 | complain_overflow_dont, /* complain_on_overflow */ |
| 487 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 488 | "R_PPC64_COPY", /* name */ |
| 489 | FALSE, /* partial_inplace */ |
| 490 | 0, /* src_mask */ |
| 491 | 0, /* dst_mask */ |
| 492 | FALSE), /* pcrel_offset */ |
| 493 | |
| 494 | /* Like R_PPC64_ADDR64, but used when setting global offset table |
| 495 | entries. */ |
| 496 | HOWTO (R_PPC64_GLOB_DAT, /* type */ |
| 497 | 0, /* rightshift */ |
| 498 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 499 | 64, /* bitsize */ |
| 500 | FALSE, /* pc_relative */ |
| 501 | 0, /* bitpos */ |
| 502 | complain_overflow_dont, /* complain_on_overflow */ |
| 503 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 504 | "R_PPC64_GLOB_DAT", /* name */ |
| 505 | FALSE, /* partial_inplace */ |
| 506 | 0, /* src_mask */ |
| 507 | ONES (64), /* dst_mask */ |
| 508 | FALSE), /* pcrel_offset */ |
| 509 | |
| 510 | /* Created by the link editor. Marks a procedure linkage table |
| 511 | entry for a symbol. */ |
| 512 | HOWTO (R_PPC64_JMP_SLOT, /* type */ |
| 513 | 0, /* rightshift */ |
| 514 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 515 | 0, /* bitsize */ |
| 516 | FALSE, /* pc_relative */ |
| 517 | 0, /* bitpos */ |
| 518 | complain_overflow_dont, /* complain_on_overflow */ |
| 519 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 520 | "R_PPC64_JMP_SLOT", /* name */ |
| 521 | FALSE, /* partial_inplace */ |
| 522 | 0, /* src_mask */ |
| 523 | 0, /* dst_mask */ |
| 524 | FALSE), /* pcrel_offset */ |
| 525 | |
| 526 | /* Used only by the dynamic linker. When the object is run, this |
| 527 | doubleword64 is set to the load address of the object, plus the |
| 528 | addend. */ |
| 529 | HOWTO (R_PPC64_RELATIVE, /* type */ |
| 530 | 0, /* rightshift */ |
| 531 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 532 | 64, /* bitsize */ |
| 533 | FALSE, /* pc_relative */ |
| 534 | 0, /* bitpos */ |
| 535 | complain_overflow_dont, /* complain_on_overflow */ |
| 536 | bfd_elf_generic_reloc, /* special_function */ |
| 537 | "R_PPC64_RELATIVE", /* name */ |
| 538 | FALSE, /* partial_inplace */ |
| 539 | 0, /* src_mask */ |
| 540 | ONES (64), /* dst_mask */ |
| 541 | FALSE), /* pcrel_offset */ |
| 542 | |
| 543 | /* Like R_PPC64_ADDR32, but may be unaligned. */ |
| 544 | HOWTO (R_PPC64_UADDR32, /* type */ |
| 545 | 0, /* rightshift */ |
| 546 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 547 | 32, /* bitsize */ |
| 548 | FALSE, /* pc_relative */ |
| 549 | 0, /* bitpos */ |
| 550 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 551 | bfd_elf_generic_reloc, /* special_function */ |
| 552 | "R_PPC64_UADDR32", /* name */ |
| 553 | FALSE, /* partial_inplace */ |
| 554 | 0, /* src_mask */ |
| 555 | 0xffffffff, /* dst_mask */ |
| 556 | FALSE), /* pcrel_offset */ |
| 557 | |
| 558 | /* Like R_PPC64_ADDR16, but may be unaligned. */ |
| 559 | HOWTO (R_PPC64_UADDR16, /* type */ |
| 560 | 0, /* rightshift */ |
| 561 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 562 | 16, /* bitsize */ |
| 563 | FALSE, /* pc_relative */ |
| 564 | 0, /* bitpos */ |
| 565 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 566 | bfd_elf_generic_reloc, /* special_function */ |
| 567 | "R_PPC64_UADDR16", /* name */ |
| 568 | FALSE, /* partial_inplace */ |
| 569 | 0, /* src_mask */ |
| 570 | 0xffff, /* dst_mask */ |
| 571 | FALSE), /* pcrel_offset */ |
| 572 | |
| 573 | /* 32-bit PC relative. */ |
| 574 | HOWTO (R_PPC64_REL32, /* type */ |
| 575 | 0, /* rightshift */ |
| 576 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 577 | 32, /* bitsize */ |
| 578 | TRUE, /* pc_relative */ |
| 579 | 0, /* bitpos */ |
| 580 | /* FIXME: Verify. Was complain_overflow_bitfield. */ |
| 581 | complain_overflow_signed, /* complain_on_overflow */ |
| 582 | bfd_elf_generic_reloc, /* special_function */ |
| 583 | "R_PPC64_REL32", /* name */ |
| 584 | FALSE, /* partial_inplace */ |
| 585 | 0, /* src_mask */ |
| 586 | 0xffffffff, /* dst_mask */ |
| 587 | TRUE), /* pcrel_offset */ |
| 588 | |
| 589 | /* 32-bit relocation to the symbol's procedure linkage table. */ |
| 590 | HOWTO (R_PPC64_PLT32, /* type */ |
| 591 | 0, /* rightshift */ |
| 592 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 593 | 32, /* bitsize */ |
| 594 | FALSE, /* pc_relative */ |
| 595 | 0, /* bitpos */ |
| 596 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 597 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 598 | "R_PPC64_PLT32", /* name */ |
| 599 | FALSE, /* partial_inplace */ |
| 600 | 0, /* src_mask */ |
| 601 | 0xffffffff, /* dst_mask */ |
| 602 | FALSE), /* pcrel_offset */ |
| 603 | |
| 604 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. |
| 605 | FIXME: R_PPC64_PLTREL32 not supported. */ |
| 606 | HOWTO (R_PPC64_PLTREL32, /* type */ |
| 607 | 0, /* rightshift */ |
| 608 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 609 | 32, /* bitsize */ |
| 610 | TRUE, /* pc_relative */ |
| 611 | 0, /* bitpos */ |
| 612 | complain_overflow_signed, /* complain_on_overflow */ |
| 613 | bfd_elf_generic_reloc, /* special_function */ |
| 614 | "R_PPC64_PLTREL32", /* name */ |
| 615 | FALSE, /* partial_inplace */ |
| 616 | 0, /* src_mask */ |
| 617 | 0xffffffff, /* dst_mask */ |
| 618 | TRUE), /* pcrel_offset */ |
| 619 | |
| 620 | /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for |
| 621 | the symbol. */ |
| 622 | HOWTO (R_PPC64_PLT16_LO, /* type */ |
| 623 | 0, /* rightshift */ |
| 624 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 625 | 16, /* bitsize */ |
| 626 | FALSE, /* pc_relative */ |
| 627 | 0, /* bitpos */ |
| 628 | complain_overflow_dont, /* complain_on_overflow */ |
| 629 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 630 | "R_PPC64_PLT16_LO", /* name */ |
| 631 | FALSE, /* partial_inplace */ |
| 632 | 0, /* src_mask */ |
| 633 | 0xffff, /* dst_mask */ |
| 634 | FALSE), /* pcrel_offset */ |
| 635 | |
| 636 | /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for |
| 637 | the symbol. */ |
| 638 | HOWTO (R_PPC64_PLT16_HI, /* type */ |
| 639 | 16, /* rightshift */ |
| 640 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 641 | 16, /* bitsize */ |
| 642 | FALSE, /* pc_relative */ |
| 643 | 0, /* bitpos */ |
| 644 | complain_overflow_dont, /* complain_on_overflow */ |
| 645 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 646 | "R_PPC64_PLT16_HI", /* name */ |
| 647 | FALSE, /* partial_inplace */ |
| 648 | 0, /* src_mask */ |
| 649 | 0xffff, /* dst_mask */ |
| 650 | FALSE), /* pcrel_offset */ |
| 651 | |
| 652 | /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for |
| 653 | the symbol. */ |
| 654 | HOWTO (R_PPC64_PLT16_HA, /* type */ |
| 655 | 16, /* rightshift */ |
| 656 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 657 | 16, /* bitsize */ |
| 658 | FALSE, /* pc_relative */ |
| 659 | 0, /* bitpos */ |
| 660 | complain_overflow_dont, /* complain_on_overflow */ |
| 661 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 662 | "R_PPC64_PLT16_HA", /* name */ |
| 663 | FALSE, /* partial_inplace */ |
| 664 | 0, /* src_mask */ |
| 665 | 0xffff, /* dst_mask */ |
| 666 | FALSE), /* pcrel_offset */ |
| 667 | |
| 668 | /* 16-bit section relative relocation. */ |
| 669 | HOWTO (R_PPC64_SECTOFF, /* type */ |
| 670 | 0, /* rightshift */ |
| 671 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 672 | 16, /* bitsize */ |
| 673 | FALSE, /* pc_relative */ |
| 674 | 0, /* bitpos */ |
| 675 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 676 | ppc64_elf_sectoff_reloc, /* special_function */ |
| 677 | "R_PPC64_SECTOFF", /* name */ |
| 678 | FALSE, /* partial_inplace */ |
| 679 | 0, /* src_mask */ |
| 680 | 0xffff, /* dst_mask */ |
| 681 | FALSE), /* pcrel_offset */ |
| 682 | |
| 683 | /* Like R_PPC64_SECTOFF, but no overflow warning. */ |
| 684 | HOWTO (R_PPC64_SECTOFF_LO, /* type */ |
| 685 | 0, /* rightshift */ |
| 686 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 687 | 16, /* bitsize */ |
| 688 | FALSE, /* pc_relative */ |
| 689 | 0, /* bitpos */ |
| 690 | complain_overflow_dont, /* complain_on_overflow */ |
| 691 | ppc64_elf_sectoff_reloc, /* special_function */ |
| 692 | "R_PPC64_SECTOFF_LO", /* name */ |
| 693 | FALSE, /* partial_inplace */ |
| 694 | 0, /* src_mask */ |
| 695 | 0xffff, /* dst_mask */ |
| 696 | FALSE), /* pcrel_offset */ |
| 697 | |
| 698 | /* 16-bit upper half section relative relocation. */ |
| 699 | HOWTO (R_PPC64_SECTOFF_HI, /* type */ |
| 700 | 16, /* rightshift */ |
| 701 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 702 | 16, /* bitsize */ |
| 703 | FALSE, /* pc_relative */ |
| 704 | 0, /* bitpos */ |
| 705 | complain_overflow_dont, /* complain_on_overflow */ |
| 706 | ppc64_elf_sectoff_reloc, /* special_function */ |
| 707 | "R_PPC64_SECTOFF_HI", /* name */ |
| 708 | FALSE, /* partial_inplace */ |
| 709 | 0, /* src_mask */ |
| 710 | 0xffff, /* dst_mask */ |
| 711 | FALSE), /* pcrel_offset */ |
| 712 | |
| 713 | /* 16-bit upper half adjusted section relative relocation. */ |
| 714 | HOWTO (R_PPC64_SECTOFF_HA, /* type */ |
| 715 | 16, /* rightshift */ |
| 716 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 717 | 16, /* bitsize */ |
| 718 | FALSE, /* pc_relative */ |
| 719 | 0, /* bitpos */ |
| 720 | complain_overflow_dont, /* complain_on_overflow */ |
| 721 | ppc64_elf_sectoff_ha_reloc, /* special_function */ |
| 722 | "R_PPC64_SECTOFF_HA", /* name */ |
| 723 | FALSE, /* partial_inplace */ |
| 724 | 0, /* src_mask */ |
| 725 | 0xffff, /* dst_mask */ |
| 726 | FALSE), /* pcrel_offset */ |
| 727 | |
| 728 | /* Like R_PPC64_REL24 without touching the two least significant bits. */ |
| 729 | HOWTO (R_PPC64_REL30, /* type */ |
| 730 | 2, /* rightshift */ |
| 731 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 732 | 30, /* bitsize */ |
| 733 | TRUE, /* pc_relative */ |
| 734 | 0, /* bitpos */ |
| 735 | complain_overflow_dont, /* complain_on_overflow */ |
| 736 | bfd_elf_generic_reloc, /* special_function */ |
| 737 | "R_PPC64_REL30", /* name */ |
| 738 | FALSE, /* partial_inplace */ |
| 739 | 0, /* src_mask */ |
| 740 | 0xfffffffc, /* dst_mask */ |
| 741 | TRUE), /* pcrel_offset */ |
| 742 | |
| 743 | /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */ |
| 744 | |
| 745 | /* A standard 64-bit relocation. */ |
| 746 | HOWTO (R_PPC64_ADDR64, /* type */ |
| 747 | 0, /* rightshift */ |
| 748 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 749 | 64, /* bitsize */ |
| 750 | FALSE, /* pc_relative */ |
| 751 | 0, /* bitpos */ |
| 752 | complain_overflow_dont, /* complain_on_overflow */ |
| 753 | bfd_elf_generic_reloc, /* special_function */ |
| 754 | "R_PPC64_ADDR64", /* name */ |
| 755 | FALSE, /* partial_inplace */ |
| 756 | 0, /* src_mask */ |
| 757 | ONES (64), /* dst_mask */ |
| 758 | FALSE), /* pcrel_offset */ |
| 759 | |
| 760 | /* The bits 32-47 of an address. */ |
| 761 | HOWTO (R_PPC64_ADDR16_HIGHER, /* type */ |
| 762 | 32, /* rightshift */ |
| 763 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 764 | 16, /* bitsize */ |
| 765 | FALSE, /* pc_relative */ |
| 766 | 0, /* bitpos */ |
| 767 | complain_overflow_dont, /* complain_on_overflow */ |
| 768 | bfd_elf_generic_reloc, /* special_function */ |
| 769 | "R_PPC64_ADDR16_HIGHER", /* name */ |
| 770 | FALSE, /* partial_inplace */ |
| 771 | 0, /* src_mask */ |
| 772 | 0xffff, /* dst_mask */ |
| 773 | FALSE), /* pcrel_offset */ |
| 774 | |
| 775 | /* The bits 32-47 of an address, plus 1 if the contents of the low |
| 776 | 16 bits, treated as a signed number, is negative. */ |
| 777 | HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */ |
| 778 | 32, /* rightshift */ |
| 779 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 780 | 16, /* bitsize */ |
| 781 | FALSE, /* pc_relative */ |
| 782 | 0, /* bitpos */ |
| 783 | complain_overflow_dont, /* complain_on_overflow */ |
| 784 | ppc64_elf_ha_reloc, /* special_function */ |
| 785 | "R_PPC64_ADDR16_HIGHERA", /* name */ |
| 786 | FALSE, /* partial_inplace */ |
| 787 | 0, /* src_mask */ |
| 788 | 0xffff, /* dst_mask */ |
| 789 | FALSE), /* pcrel_offset */ |
| 790 | |
| 791 | /* The bits 48-63 of an address. */ |
| 792 | HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */ |
| 793 | 48, /* rightshift */ |
| 794 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 795 | 16, /* bitsize */ |
| 796 | FALSE, /* pc_relative */ |
| 797 | 0, /* bitpos */ |
| 798 | complain_overflow_dont, /* complain_on_overflow */ |
| 799 | bfd_elf_generic_reloc, /* special_function */ |
| 800 | "R_PPC64_ADDR16_HIGHEST", /* name */ |
| 801 | FALSE, /* partial_inplace */ |
| 802 | 0, /* src_mask */ |
| 803 | 0xffff, /* dst_mask */ |
| 804 | FALSE), /* pcrel_offset */ |
| 805 | |
| 806 | /* The bits 48-63 of an address, plus 1 if the contents of the low |
| 807 | 16 bits, treated as a signed number, is negative. */ |
| 808 | HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */ |
| 809 | 48, /* rightshift */ |
| 810 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 811 | 16, /* bitsize */ |
| 812 | FALSE, /* pc_relative */ |
| 813 | 0, /* bitpos */ |
| 814 | complain_overflow_dont, /* complain_on_overflow */ |
| 815 | ppc64_elf_ha_reloc, /* special_function */ |
| 816 | "R_PPC64_ADDR16_HIGHESTA", /* name */ |
| 817 | FALSE, /* partial_inplace */ |
| 818 | 0, /* src_mask */ |
| 819 | 0xffff, /* dst_mask */ |
| 820 | FALSE), /* pcrel_offset */ |
| 821 | |
| 822 | /* Like ADDR64, but may be unaligned. */ |
| 823 | HOWTO (R_PPC64_UADDR64, /* type */ |
| 824 | 0, /* rightshift */ |
| 825 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 826 | 64, /* bitsize */ |
| 827 | FALSE, /* pc_relative */ |
| 828 | 0, /* bitpos */ |
| 829 | complain_overflow_dont, /* complain_on_overflow */ |
| 830 | bfd_elf_generic_reloc, /* special_function */ |
| 831 | "R_PPC64_UADDR64", /* name */ |
| 832 | FALSE, /* partial_inplace */ |
| 833 | 0, /* src_mask */ |
| 834 | ONES (64), /* dst_mask */ |
| 835 | FALSE), /* pcrel_offset */ |
| 836 | |
| 837 | /* 64-bit relative relocation. */ |
| 838 | HOWTO (R_PPC64_REL64, /* type */ |
| 839 | 0, /* rightshift */ |
| 840 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 841 | 64, /* bitsize */ |
| 842 | TRUE, /* pc_relative */ |
| 843 | 0, /* bitpos */ |
| 844 | complain_overflow_dont, /* complain_on_overflow */ |
| 845 | bfd_elf_generic_reloc, /* special_function */ |
| 846 | "R_PPC64_REL64", /* name */ |
| 847 | FALSE, /* partial_inplace */ |
| 848 | 0, /* src_mask */ |
| 849 | ONES (64), /* dst_mask */ |
| 850 | TRUE), /* pcrel_offset */ |
| 851 | |
| 852 | /* 64-bit relocation to the symbol's procedure linkage table. */ |
| 853 | HOWTO (R_PPC64_PLT64, /* type */ |
| 854 | 0, /* rightshift */ |
| 855 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 856 | 64, /* bitsize */ |
| 857 | FALSE, /* pc_relative */ |
| 858 | 0, /* bitpos */ |
| 859 | complain_overflow_dont, /* complain_on_overflow */ |
| 860 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 861 | "R_PPC64_PLT64", /* name */ |
| 862 | FALSE, /* partial_inplace */ |
| 863 | 0, /* src_mask */ |
| 864 | ONES (64), /* dst_mask */ |
| 865 | FALSE), /* pcrel_offset */ |
| 866 | |
| 867 | /* 64-bit PC relative relocation to the symbol's procedure linkage |
| 868 | table. */ |
| 869 | /* FIXME: R_PPC64_PLTREL64 not supported. */ |
| 870 | HOWTO (R_PPC64_PLTREL64, /* type */ |
| 871 | 0, /* rightshift */ |
| 872 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 873 | 64, /* bitsize */ |
| 874 | TRUE, /* pc_relative */ |
| 875 | 0, /* bitpos */ |
| 876 | complain_overflow_dont, /* complain_on_overflow */ |
| 877 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 878 | "R_PPC64_PLTREL64", /* name */ |
| 879 | FALSE, /* partial_inplace */ |
| 880 | 0, /* src_mask */ |
| 881 | ONES (64), /* dst_mask */ |
| 882 | TRUE), /* pcrel_offset */ |
| 883 | |
| 884 | /* 16 bit TOC-relative relocation. */ |
| 885 | |
| 886 | /* R_PPC64_TOC16 47 half16* S + A - .TOC. */ |
| 887 | HOWTO (R_PPC64_TOC16, /* 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_signed, /* complain_on_overflow */ |
| 894 | ppc64_elf_toc_reloc, /* special_function */ |
| 895 | "R_PPC64_TOC16", /* name */ |
| 896 | FALSE, /* partial_inplace */ |
| 897 | 0, /* src_mask */ |
| 898 | 0xffff, /* dst_mask */ |
| 899 | FALSE), /* pcrel_offset */ |
| 900 | |
| 901 | /* 16 bit TOC-relative relocation without overflow. */ |
| 902 | |
| 903 | /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */ |
| 904 | HOWTO (R_PPC64_TOC16_LO, /* type */ |
| 905 | 0, /* 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 | ppc64_elf_toc_reloc, /* special_function */ |
| 912 | "R_PPC64_TOC16_LO", /* 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. */ |
| 919 | |
| 920 | /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */ |
| 921 | HOWTO (R_PPC64_TOC16_HI, /* type */ |
| 922 | 16, /* rightshift */ |
| 923 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 924 | 16, /* bitsize */ |
| 925 | FALSE, /* pc_relative */ |
| 926 | 0, /* bitpos */ |
| 927 | complain_overflow_dont, /* complain_on_overflow */ |
| 928 | ppc64_elf_toc_reloc, /* special_function */ |
| 929 | "R_PPC64_TOC16_HI", /* name */ |
| 930 | FALSE, /* partial_inplace */ |
| 931 | 0, /* src_mask */ |
| 932 | 0xffff, /* dst_mask */ |
| 933 | FALSE), /* pcrel_offset */ |
| 934 | |
| 935 | /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the |
| 936 | contents of the low 16 bits, treated as a signed number, is |
| 937 | negative. */ |
| 938 | |
| 939 | /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */ |
| 940 | HOWTO (R_PPC64_TOC16_HA, /* type */ |
| 941 | 16, /* rightshift */ |
| 942 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 943 | 16, /* bitsize */ |
| 944 | FALSE, /* pc_relative */ |
| 945 | 0, /* bitpos */ |
| 946 | complain_overflow_dont, /* complain_on_overflow */ |
| 947 | ppc64_elf_toc_ha_reloc, /* special_function */ |
| 948 | "R_PPC64_TOC16_HA", /* name */ |
| 949 | FALSE, /* partial_inplace */ |
| 950 | 0, /* src_mask */ |
| 951 | 0xffff, /* dst_mask */ |
| 952 | FALSE), /* pcrel_offset */ |
| 953 | |
| 954 | /* 64-bit relocation; insert value of TOC base (.TOC.). */ |
| 955 | |
| 956 | /* R_PPC64_TOC 51 doubleword64 .TOC. */ |
| 957 | HOWTO (R_PPC64_TOC, /* type */ |
| 958 | 0, /* rightshift */ |
| 959 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ |
| 960 | 64, /* bitsize */ |
| 961 | FALSE, /* pc_relative */ |
| 962 | 0, /* bitpos */ |
| 963 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 964 | ppc64_elf_toc64_reloc, /* special_function */ |
| 965 | "R_PPC64_TOC", /* name */ |
| 966 | FALSE, /* partial_inplace */ |
| 967 | 0, /* src_mask */ |
| 968 | ONES (64), /* dst_mask */ |
| 969 | FALSE), /* pcrel_offset */ |
| 970 | |
| 971 | /* Like R_PPC64_GOT16, but also informs the link editor that the |
| 972 | value to relocate may (!) refer to a PLT entry which the link |
| 973 | editor (a) may replace with the symbol value. If the link editor |
| 974 | is unable to fully resolve the symbol, it may (b) create a PLT |
| 975 | entry and store the address to the new PLT entry in the GOT. |
| 976 | This permits lazy resolution of function symbols at run time. |
| 977 | The link editor may also skip all of this and just (c) emit a |
| 978 | R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */ |
| 979 | /* FIXME: R_PPC64_PLTGOT16 not implemented. */ |
| 980 | HOWTO (R_PPC64_PLTGOT16, /* type */ |
| 981 | 0, /* rightshift */ |
| 982 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 983 | 16, /* bitsize */ |
| 984 | FALSE, /* pc_relative */ |
| 985 | 0, /* bitpos */ |
| 986 | complain_overflow_signed, /* complain_on_overflow */ |
| 987 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 988 | "R_PPC64_PLTGOT16", /* name */ |
| 989 | FALSE, /* partial_inplace */ |
| 990 | 0, /* src_mask */ |
| 991 | 0xffff, /* dst_mask */ |
| 992 | FALSE), /* pcrel_offset */ |
| 993 | |
| 994 | /* Like R_PPC64_PLTGOT16, but without overflow. */ |
| 995 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ |
| 996 | HOWTO (R_PPC64_PLTGOT16_LO, /* type */ |
| 997 | 0, /* rightshift */ |
| 998 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 999 | 16, /* bitsize */ |
| 1000 | FALSE, /* pc_relative */ |
| 1001 | 0, /* bitpos */ |
| 1002 | complain_overflow_dont, /* complain_on_overflow */ |
| 1003 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1004 | "R_PPC64_PLTGOT16_LO", /* name */ |
| 1005 | FALSE, /* partial_inplace */ |
| 1006 | 0, /* src_mask */ |
| 1007 | 0xffff, /* dst_mask */ |
| 1008 | FALSE), /* pcrel_offset */ |
| 1009 | |
| 1010 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */ |
| 1011 | /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */ |
| 1012 | HOWTO (R_PPC64_PLTGOT16_HI, /* type */ |
| 1013 | 16, /* rightshift */ |
| 1014 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1015 | 16, /* bitsize */ |
| 1016 | FALSE, /* pc_relative */ |
| 1017 | 0, /* bitpos */ |
| 1018 | complain_overflow_dont, /* complain_on_overflow */ |
| 1019 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1020 | "R_PPC64_PLTGOT16_HI", /* name */ |
| 1021 | FALSE, /* partial_inplace */ |
| 1022 | 0, /* src_mask */ |
| 1023 | 0xffff, /* dst_mask */ |
| 1024 | FALSE), /* pcrel_offset */ |
| 1025 | |
| 1026 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus |
| 1027 | 1 if the contents of the low 16 bits, treated as a signed number, |
| 1028 | is negative. */ |
| 1029 | /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */ |
| 1030 | HOWTO (R_PPC64_PLTGOT16_HA, /* type */ |
| 1031 | 16, /* rightshift */ |
| 1032 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1033 | 16, /* bitsize */ |
| 1034 | FALSE, /* pc_relative */ |
| 1035 | 0, /* bitpos */ |
| 1036 | complain_overflow_dont,/* complain_on_overflow */ |
| 1037 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1038 | "R_PPC64_PLTGOT16_HA", /* name */ |
| 1039 | FALSE, /* partial_inplace */ |
| 1040 | 0, /* src_mask */ |
| 1041 | 0xffff, /* dst_mask */ |
| 1042 | FALSE), /* pcrel_offset */ |
| 1043 | |
| 1044 | /* Like R_PPC64_ADDR16, but for instructions with a DS field. */ |
| 1045 | HOWTO (R_PPC64_ADDR16_DS, /* type */ |
| 1046 | 0, /* rightshift */ |
| 1047 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1048 | 16, /* bitsize */ |
| 1049 | FALSE, /* pc_relative */ |
| 1050 | 0, /* bitpos */ |
| 1051 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 1052 | bfd_elf_generic_reloc, /* special_function */ |
| 1053 | "R_PPC64_ADDR16_DS", /* name */ |
| 1054 | FALSE, /* partial_inplace */ |
| 1055 | 0, /* src_mask */ |
| 1056 | 0xfffc, /* dst_mask */ |
| 1057 | FALSE), /* pcrel_offset */ |
| 1058 | |
| 1059 | /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */ |
| 1060 | HOWTO (R_PPC64_ADDR16_LO_DS, /* type */ |
| 1061 | 0, /* rightshift */ |
| 1062 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1063 | 16, /* bitsize */ |
| 1064 | FALSE, /* pc_relative */ |
| 1065 | 0, /* bitpos */ |
| 1066 | complain_overflow_dont,/* complain_on_overflow */ |
| 1067 | bfd_elf_generic_reloc, /* special_function */ |
| 1068 | "R_PPC64_ADDR16_LO_DS",/* name */ |
| 1069 | FALSE, /* partial_inplace */ |
| 1070 | 0, /* src_mask */ |
| 1071 | 0xfffc, /* dst_mask */ |
| 1072 | FALSE), /* pcrel_offset */ |
| 1073 | |
| 1074 | /* Like R_PPC64_GOT16, but for instructions with a DS field. */ |
| 1075 | HOWTO (R_PPC64_GOT16_DS, /* type */ |
| 1076 | 0, /* rightshift */ |
| 1077 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1078 | 16, /* bitsize */ |
| 1079 | FALSE, /* pc_relative */ |
| 1080 | 0, /* bitpos */ |
| 1081 | complain_overflow_signed, /* complain_on_overflow */ |
| 1082 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1083 | "R_PPC64_GOT16_DS", /* name */ |
| 1084 | FALSE, /* partial_inplace */ |
| 1085 | 0, /* src_mask */ |
| 1086 | 0xfffc, /* dst_mask */ |
| 1087 | FALSE), /* pcrel_offset */ |
| 1088 | |
| 1089 | /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */ |
| 1090 | HOWTO (R_PPC64_GOT16_LO_DS, /* type */ |
| 1091 | 0, /* rightshift */ |
| 1092 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1093 | 16, /* bitsize */ |
| 1094 | FALSE, /* pc_relative */ |
| 1095 | 0, /* bitpos */ |
| 1096 | complain_overflow_dont, /* complain_on_overflow */ |
| 1097 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1098 | "R_PPC64_GOT16_LO_DS", /* name */ |
| 1099 | FALSE, /* partial_inplace */ |
| 1100 | 0, /* src_mask */ |
| 1101 | 0xfffc, /* dst_mask */ |
| 1102 | FALSE), /* pcrel_offset */ |
| 1103 | |
| 1104 | /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */ |
| 1105 | HOWTO (R_PPC64_PLT16_LO_DS, /* type */ |
| 1106 | 0, /* rightshift */ |
| 1107 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1108 | 16, /* bitsize */ |
| 1109 | FALSE, /* pc_relative */ |
| 1110 | 0, /* bitpos */ |
| 1111 | complain_overflow_dont, /* complain_on_overflow */ |
| 1112 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1113 | "R_PPC64_PLT16_LO_DS", /* name */ |
| 1114 | FALSE, /* partial_inplace */ |
| 1115 | 0, /* src_mask */ |
| 1116 | 0xfffc, /* dst_mask */ |
| 1117 | FALSE), /* pcrel_offset */ |
| 1118 | |
| 1119 | /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */ |
| 1120 | HOWTO (R_PPC64_SECTOFF_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_bitfield, /* complain_on_overflow */ |
| 1127 | ppc64_elf_sectoff_reloc, /* special_function */ |
| 1128 | "R_PPC64_SECTOFF_DS", /* name */ |
| 1129 | FALSE, /* partial_inplace */ |
| 1130 | 0, /* src_mask */ |
| 1131 | 0xfffc, /* dst_mask */ |
| 1132 | FALSE), /* pcrel_offset */ |
| 1133 | |
| 1134 | /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */ |
| 1135 | HOWTO (R_PPC64_SECTOFF_LO_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_dont, /* complain_on_overflow */ |
| 1142 | ppc64_elf_sectoff_reloc, /* special_function */ |
| 1143 | "R_PPC64_SECTOFF_LO_DS",/* name */ |
| 1144 | FALSE, /* partial_inplace */ |
| 1145 | 0, /* src_mask */ |
| 1146 | 0xfffc, /* dst_mask */ |
| 1147 | FALSE), /* pcrel_offset */ |
| 1148 | |
| 1149 | /* Like R_PPC64_TOC16, but for instructions with a DS field. */ |
| 1150 | HOWTO (R_PPC64_TOC16_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_signed, /* complain_on_overflow */ |
| 1157 | ppc64_elf_toc_reloc, /* special_function */ |
| 1158 | "R_PPC64_TOC16_DS", /* name */ |
| 1159 | FALSE, /* partial_inplace */ |
| 1160 | 0, /* src_mask */ |
| 1161 | 0xfffc, /* dst_mask */ |
| 1162 | FALSE), /* pcrel_offset */ |
| 1163 | |
| 1164 | /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */ |
| 1165 | HOWTO (R_PPC64_TOC16_LO_DS, /* type */ |
| 1166 | 0, /* rightshift */ |
| 1167 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1168 | 16, /* bitsize */ |
| 1169 | FALSE, /* pc_relative */ |
| 1170 | 0, /* bitpos */ |
| 1171 | complain_overflow_dont, /* complain_on_overflow */ |
| 1172 | ppc64_elf_toc_reloc, /* special_function */ |
| 1173 | "R_PPC64_TOC16_LO_DS", /* name */ |
| 1174 | FALSE, /* partial_inplace */ |
| 1175 | 0, /* src_mask */ |
| 1176 | 0xfffc, /* dst_mask */ |
| 1177 | FALSE), /* pcrel_offset */ |
| 1178 | |
| 1179 | /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */ |
| 1180 | /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */ |
| 1181 | HOWTO (R_PPC64_PLTGOT16_DS, /* type */ |
| 1182 | 0, /* rightshift */ |
| 1183 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1184 | 16, /* bitsize */ |
| 1185 | FALSE, /* pc_relative */ |
| 1186 | 0, /* bitpos */ |
| 1187 | complain_overflow_signed, /* complain_on_overflow */ |
| 1188 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1189 | "R_PPC64_PLTGOT16_DS", /* name */ |
| 1190 | FALSE, /* partial_inplace */ |
| 1191 | 0, /* src_mask */ |
| 1192 | 0xfffc, /* dst_mask */ |
| 1193 | FALSE), /* pcrel_offset */ |
| 1194 | |
| 1195 | /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */ |
| 1196 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ |
| 1197 | HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */ |
| 1198 | 0, /* rightshift */ |
| 1199 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1200 | 16, /* bitsize */ |
| 1201 | FALSE, /* pc_relative */ |
| 1202 | 0, /* bitpos */ |
| 1203 | complain_overflow_dont, /* complain_on_overflow */ |
| 1204 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1205 | "R_PPC64_PLTGOT16_LO_DS",/* name */ |
| 1206 | FALSE, /* partial_inplace */ |
| 1207 | 0, /* src_mask */ |
| 1208 | 0xfffc, /* dst_mask */ |
| 1209 | FALSE), /* pcrel_offset */ |
| 1210 | |
| 1211 | /* Marker reloc for TLS. */ |
| 1212 | HOWTO (R_PPC64_TLS, |
| 1213 | 0, /* rightshift */ |
| 1214 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1215 | 32, /* bitsize */ |
| 1216 | FALSE, /* pc_relative */ |
| 1217 | 0, /* bitpos */ |
| 1218 | complain_overflow_dont, /* complain_on_overflow */ |
| 1219 | bfd_elf_generic_reloc, /* special_function */ |
| 1220 | "R_PPC64_TLS", /* name */ |
| 1221 | FALSE, /* partial_inplace */ |
| 1222 | 0, /* src_mask */ |
| 1223 | 0, /* dst_mask */ |
| 1224 | FALSE), /* pcrel_offset */ |
| 1225 | |
| 1226 | /* Computes the load module index of the load module that contains the |
| 1227 | definition of its TLS sym. */ |
| 1228 | HOWTO (R_PPC64_DTPMOD64, |
| 1229 | 0, /* rightshift */ |
| 1230 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1231 | 64, /* bitsize */ |
| 1232 | FALSE, /* pc_relative */ |
| 1233 | 0, /* bitpos */ |
| 1234 | complain_overflow_dont, /* complain_on_overflow */ |
| 1235 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1236 | "R_PPC64_DTPMOD64", /* name */ |
| 1237 | FALSE, /* partial_inplace */ |
| 1238 | 0, /* src_mask */ |
| 1239 | ONES (64), /* dst_mask */ |
| 1240 | FALSE), /* pcrel_offset */ |
| 1241 | |
| 1242 | /* Computes a dtv-relative displacement, the difference between the value |
| 1243 | of sym+add and the base address of the thread-local storage block that |
| 1244 | contains the definition of sym, minus 0x8000. */ |
| 1245 | HOWTO (R_PPC64_DTPREL64, |
| 1246 | 0, /* rightshift */ |
| 1247 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1248 | 64, /* bitsize */ |
| 1249 | FALSE, /* pc_relative */ |
| 1250 | 0, /* bitpos */ |
| 1251 | complain_overflow_dont, /* complain_on_overflow */ |
| 1252 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1253 | "R_PPC64_DTPREL64", /* name */ |
| 1254 | FALSE, /* partial_inplace */ |
| 1255 | 0, /* src_mask */ |
| 1256 | ONES (64), /* dst_mask */ |
| 1257 | FALSE), /* pcrel_offset */ |
| 1258 | |
| 1259 | /* A 16 bit dtprel reloc. */ |
| 1260 | HOWTO (R_PPC64_DTPREL16, |
| 1261 | 0, /* rightshift */ |
| 1262 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1263 | 16, /* bitsize */ |
| 1264 | FALSE, /* pc_relative */ |
| 1265 | 0, /* bitpos */ |
| 1266 | complain_overflow_signed, /* complain_on_overflow */ |
| 1267 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1268 | "R_PPC64_DTPREL16", /* name */ |
| 1269 | FALSE, /* partial_inplace */ |
| 1270 | 0, /* src_mask */ |
| 1271 | 0xffff, /* dst_mask */ |
| 1272 | FALSE), /* pcrel_offset */ |
| 1273 | |
| 1274 | /* Like DTPREL16, but no overflow. */ |
| 1275 | HOWTO (R_PPC64_DTPREL16_LO, |
| 1276 | 0, /* rightshift */ |
| 1277 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1278 | 16, /* bitsize */ |
| 1279 | FALSE, /* pc_relative */ |
| 1280 | 0, /* bitpos */ |
| 1281 | complain_overflow_dont, /* complain_on_overflow */ |
| 1282 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1283 | "R_PPC64_DTPREL16_LO", /* name */ |
| 1284 | FALSE, /* partial_inplace */ |
| 1285 | 0, /* src_mask */ |
| 1286 | 0xffff, /* dst_mask */ |
| 1287 | FALSE), /* pcrel_offset */ |
| 1288 | |
| 1289 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ |
| 1290 | HOWTO (R_PPC64_DTPREL16_HI, |
| 1291 | 16, /* rightshift */ |
| 1292 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1293 | 16, /* bitsize */ |
| 1294 | FALSE, /* pc_relative */ |
| 1295 | 0, /* bitpos */ |
| 1296 | complain_overflow_dont, /* complain_on_overflow */ |
| 1297 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1298 | "R_PPC64_DTPREL16_HI", /* name */ |
| 1299 | FALSE, /* partial_inplace */ |
| 1300 | 0, /* src_mask */ |
| 1301 | 0xffff, /* dst_mask */ |
| 1302 | FALSE), /* pcrel_offset */ |
| 1303 | |
| 1304 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ |
| 1305 | HOWTO (R_PPC64_DTPREL16_HA, |
| 1306 | 16, /* rightshift */ |
| 1307 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1308 | 16, /* bitsize */ |
| 1309 | FALSE, /* pc_relative */ |
| 1310 | 0, /* bitpos */ |
| 1311 | complain_overflow_dont, /* complain_on_overflow */ |
| 1312 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1313 | "R_PPC64_DTPREL16_HA", /* name */ |
| 1314 | FALSE, /* partial_inplace */ |
| 1315 | 0, /* src_mask */ |
| 1316 | 0xffff, /* dst_mask */ |
| 1317 | FALSE), /* pcrel_offset */ |
| 1318 | |
| 1319 | /* Like DTPREL16_HI, but next higher group of 16 bits. */ |
| 1320 | HOWTO (R_PPC64_DTPREL16_HIGHER, |
| 1321 | 32, /* rightshift */ |
| 1322 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1323 | 16, /* bitsize */ |
| 1324 | FALSE, /* pc_relative */ |
| 1325 | 0, /* bitpos */ |
| 1326 | complain_overflow_dont, /* complain_on_overflow */ |
| 1327 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1328 | "R_PPC64_DTPREL16_HIGHER", /* name */ |
| 1329 | FALSE, /* partial_inplace */ |
| 1330 | 0, /* src_mask */ |
| 1331 | 0xffff, /* dst_mask */ |
| 1332 | FALSE), /* pcrel_offset */ |
| 1333 | |
| 1334 | /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */ |
| 1335 | HOWTO (R_PPC64_DTPREL16_HIGHERA, |
| 1336 | 32, /* rightshift */ |
| 1337 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1338 | 16, /* bitsize */ |
| 1339 | FALSE, /* pc_relative */ |
| 1340 | 0, /* bitpos */ |
| 1341 | complain_overflow_dont, /* complain_on_overflow */ |
| 1342 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1343 | "R_PPC64_DTPREL16_HIGHERA", /* name */ |
| 1344 | FALSE, /* partial_inplace */ |
| 1345 | 0, /* src_mask */ |
| 1346 | 0xffff, /* dst_mask */ |
| 1347 | FALSE), /* pcrel_offset */ |
| 1348 | |
| 1349 | /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */ |
| 1350 | HOWTO (R_PPC64_DTPREL16_HIGHEST, |
| 1351 | 48, /* rightshift */ |
| 1352 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1353 | 16, /* bitsize */ |
| 1354 | FALSE, /* pc_relative */ |
| 1355 | 0, /* bitpos */ |
| 1356 | complain_overflow_dont, /* complain_on_overflow */ |
| 1357 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1358 | "R_PPC64_DTPREL16_HIGHEST", /* name */ |
| 1359 | FALSE, /* partial_inplace */ |
| 1360 | 0, /* src_mask */ |
| 1361 | 0xffff, /* dst_mask */ |
| 1362 | FALSE), /* pcrel_offset */ |
| 1363 | |
| 1364 | /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */ |
| 1365 | HOWTO (R_PPC64_DTPREL16_HIGHESTA, |
| 1366 | 48, /* rightshift */ |
| 1367 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1368 | 16, /* bitsize */ |
| 1369 | FALSE, /* pc_relative */ |
| 1370 | 0, /* bitpos */ |
| 1371 | complain_overflow_dont, /* complain_on_overflow */ |
| 1372 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1373 | "R_PPC64_DTPREL16_HIGHESTA", /* name */ |
| 1374 | FALSE, /* partial_inplace */ |
| 1375 | 0, /* src_mask */ |
| 1376 | 0xffff, /* dst_mask */ |
| 1377 | FALSE), /* pcrel_offset */ |
| 1378 | |
| 1379 | /* Like DTPREL16, but for insns with a DS field. */ |
| 1380 | HOWTO (R_PPC64_DTPREL16_DS, |
| 1381 | 0, /* rightshift */ |
| 1382 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1383 | 16, /* bitsize */ |
| 1384 | FALSE, /* pc_relative */ |
| 1385 | 0, /* bitpos */ |
| 1386 | complain_overflow_signed, /* complain_on_overflow */ |
| 1387 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1388 | "R_PPC64_DTPREL16_DS", /* name */ |
| 1389 | FALSE, /* partial_inplace */ |
| 1390 | 0, /* src_mask */ |
| 1391 | 0xfffc, /* dst_mask */ |
| 1392 | FALSE), /* pcrel_offset */ |
| 1393 | |
| 1394 | /* Like DTPREL16_DS, but no overflow. */ |
| 1395 | HOWTO (R_PPC64_DTPREL16_LO_DS, |
| 1396 | 0, /* rightshift */ |
| 1397 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1398 | 16, /* bitsize */ |
| 1399 | FALSE, /* pc_relative */ |
| 1400 | 0, /* bitpos */ |
| 1401 | complain_overflow_dont, /* complain_on_overflow */ |
| 1402 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1403 | "R_PPC64_DTPREL16_LO_DS", /* name */ |
| 1404 | FALSE, /* partial_inplace */ |
| 1405 | 0, /* src_mask */ |
| 1406 | 0xfffc, /* dst_mask */ |
| 1407 | FALSE), /* pcrel_offset */ |
| 1408 | |
| 1409 | /* Computes a tp-relative displacement, the difference between the value of |
| 1410 | sym+add and the value of the thread pointer (r13). */ |
| 1411 | HOWTO (R_PPC64_TPREL64, |
| 1412 | 0, /* rightshift */ |
| 1413 | 4, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1414 | 64, /* bitsize */ |
| 1415 | FALSE, /* pc_relative */ |
| 1416 | 0, /* bitpos */ |
| 1417 | complain_overflow_dont, /* complain_on_overflow */ |
| 1418 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1419 | "R_PPC64_TPREL64", /* name */ |
| 1420 | FALSE, /* partial_inplace */ |
| 1421 | 0, /* src_mask */ |
| 1422 | ONES (64), /* dst_mask */ |
| 1423 | FALSE), /* pcrel_offset */ |
| 1424 | |
| 1425 | /* A 16 bit tprel reloc. */ |
| 1426 | HOWTO (R_PPC64_TPREL16, |
| 1427 | 0, /* rightshift */ |
| 1428 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1429 | 16, /* bitsize */ |
| 1430 | FALSE, /* pc_relative */ |
| 1431 | 0, /* bitpos */ |
| 1432 | complain_overflow_signed, /* complain_on_overflow */ |
| 1433 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1434 | "R_PPC64_TPREL16", /* name */ |
| 1435 | FALSE, /* partial_inplace */ |
| 1436 | 0, /* src_mask */ |
| 1437 | 0xffff, /* dst_mask */ |
| 1438 | FALSE), /* pcrel_offset */ |
| 1439 | |
| 1440 | /* Like TPREL16, but no overflow. */ |
| 1441 | HOWTO (R_PPC64_TPREL16_LO, |
| 1442 | 0, /* rightshift */ |
| 1443 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1444 | 16, /* bitsize */ |
| 1445 | FALSE, /* pc_relative */ |
| 1446 | 0, /* bitpos */ |
| 1447 | complain_overflow_dont, /* complain_on_overflow */ |
| 1448 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1449 | "R_PPC64_TPREL16_LO", /* name */ |
| 1450 | FALSE, /* partial_inplace */ |
| 1451 | 0, /* src_mask */ |
| 1452 | 0xffff, /* dst_mask */ |
| 1453 | FALSE), /* pcrel_offset */ |
| 1454 | |
| 1455 | /* Like TPREL16_LO, but next higher group of 16 bits. */ |
| 1456 | HOWTO (R_PPC64_TPREL16_HI, |
| 1457 | 16, /* rightshift */ |
| 1458 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1459 | 16, /* bitsize */ |
| 1460 | FALSE, /* pc_relative */ |
| 1461 | 0, /* bitpos */ |
| 1462 | complain_overflow_dont, /* complain_on_overflow */ |
| 1463 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1464 | "R_PPC64_TPREL16_HI", /* name */ |
| 1465 | FALSE, /* partial_inplace */ |
| 1466 | 0, /* src_mask */ |
| 1467 | 0xffff, /* dst_mask */ |
| 1468 | FALSE), /* pcrel_offset */ |
| 1469 | |
| 1470 | /* Like TPREL16_HI, but adjust for low 16 bits. */ |
| 1471 | HOWTO (R_PPC64_TPREL16_HA, |
| 1472 | 16, /* rightshift */ |
| 1473 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1474 | 16, /* bitsize */ |
| 1475 | FALSE, /* pc_relative */ |
| 1476 | 0, /* bitpos */ |
| 1477 | complain_overflow_dont, /* complain_on_overflow */ |
| 1478 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1479 | "R_PPC64_TPREL16_HA", /* name */ |
| 1480 | FALSE, /* partial_inplace */ |
| 1481 | 0, /* src_mask */ |
| 1482 | 0xffff, /* dst_mask */ |
| 1483 | FALSE), /* pcrel_offset */ |
| 1484 | |
| 1485 | /* Like TPREL16_HI, but next higher group of 16 bits. */ |
| 1486 | HOWTO (R_PPC64_TPREL16_HIGHER, |
| 1487 | 32, /* rightshift */ |
| 1488 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1489 | 16, /* bitsize */ |
| 1490 | FALSE, /* pc_relative */ |
| 1491 | 0, /* bitpos */ |
| 1492 | complain_overflow_dont, /* complain_on_overflow */ |
| 1493 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1494 | "R_PPC64_TPREL16_HIGHER", /* name */ |
| 1495 | FALSE, /* partial_inplace */ |
| 1496 | 0, /* src_mask */ |
| 1497 | 0xffff, /* dst_mask */ |
| 1498 | FALSE), /* pcrel_offset */ |
| 1499 | |
| 1500 | /* Like TPREL16_HIGHER, but adjust for low 16 bits. */ |
| 1501 | HOWTO (R_PPC64_TPREL16_HIGHERA, |
| 1502 | 32, /* rightshift */ |
| 1503 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1504 | 16, /* bitsize */ |
| 1505 | FALSE, /* pc_relative */ |
| 1506 | 0, /* bitpos */ |
| 1507 | complain_overflow_dont, /* complain_on_overflow */ |
| 1508 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1509 | "R_PPC64_TPREL16_HIGHERA", /* name */ |
| 1510 | FALSE, /* partial_inplace */ |
| 1511 | 0, /* src_mask */ |
| 1512 | 0xffff, /* dst_mask */ |
| 1513 | FALSE), /* pcrel_offset */ |
| 1514 | |
| 1515 | /* Like TPREL16_HIGHER, but next higher group of 16 bits. */ |
| 1516 | HOWTO (R_PPC64_TPREL16_HIGHEST, |
| 1517 | 48, /* rightshift */ |
| 1518 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1519 | 16, /* bitsize */ |
| 1520 | FALSE, /* pc_relative */ |
| 1521 | 0, /* bitpos */ |
| 1522 | complain_overflow_dont, /* complain_on_overflow */ |
| 1523 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1524 | "R_PPC64_TPREL16_HIGHEST", /* name */ |
| 1525 | FALSE, /* partial_inplace */ |
| 1526 | 0, /* src_mask */ |
| 1527 | 0xffff, /* dst_mask */ |
| 1528 | FALSE), /* pcrel_offset */ |
| 1529 | |
| 1530 | /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */ |
| 1531 | HOWTO (R_PPC64_TPREL16_HIGHESTA, |
| 1532 | 48, /* rightshift */ |
| 1533 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1534 | 16, /* bitsize */ |
| 1535 | FALSE, /* pc_relative */ |
| 1536 | 0, /* bitpos */ |
| 1537 | complain_overflow_dont, /* complain_on_overflow */ |
| 1538 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1539 | "R_PPC64_TPREL16_HIGHESTA", /* name */ |
| 1540 | FALSE, /* partial_inplace */ |
| 1541 | 0, /* src_mask */ |
| 1542 | 0xffff, /* dst_mask */ |
| 1543 | FALSE), /* pcrel_offset */ |
| 1544 | |
| 1545 | /* Like TPREL16, but for insns with a DS field. */ |
| 1546 | HOWTO (R_PPC64_TPREL16_DS, |
| 1547 | 0, /* rightshift */ |
| 1548 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1549 | 16, /* bitsize */ |
| 1550 | FALSE, /* pc_relative */ |
| 1551 | 0, /* bitpos */ |
| 1552 | complain_overflow_signed, /* complain_on_overflow */ |
| 1553 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1554 | "R_PPC64_TPREL16_DS", /* name */ |
| 1555 | FALSE, /* partial_inplace */ |
| 1556 | 0, /* src_mask */ |
| 1557 | 0xfffc, /* dst_mask */ |
| 1558 | FALSE), /* pcrel_offset */ |
| 1559 | |
| 1560 | /* Like TPREL16_DS, but no overflow. */ |
| 1561 | HOWTO (R_PPC64_TPREL16_LO_DS, |
| 1562 | 0, /* rightshift */ |
| 1563 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1564 | 16, /* bitsize */ |
| 1565 | FALSE, /* pc_relative */ |
| 1566 | 0, /* bitpos */ |
| 1567 | complain_overflow_dont, /* complain_on_overflow */ |
| 1568 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1569 | "R_PPC64_TPREL16_LO_DS", /* name */ |
| 1570 | FALSE, /* partial_inplace */ |
| 1571 | 0, /* src_mask */ |
| 1572 | 0xfffc, /* dst_mask */ |
| 1573 | FALSE), /* pcrel_offset */ |
| 1574 | |
| 1575 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, |
| 1576 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset |
| 1577 | to the first entry relative to the TOC base (r2). */ |
| 1578 | HOWTO (R_PPC64_GOT_TLSGD16, |
| 1579 | 0, /* rightshift */ |
| 1580 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1581 | 16, /* bitsize */ |
| 1582 | FALSE, /* pc_relative */ |
| 1583 | 0, /* bitpos */ |
| 1584 | complain_overflow_signed, /* complain_on_overflow */ |
| 1585 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1586 | "R_PPC64_GOT_TLSGD16", /* name */ |
| 1587 | FALSE, /* partial_inplace */ |
| 1588 | 0, /* src_mask */ |
| 1589 | 0xffff, /* dst_mask */ |
| 1590 | FALSE), /* pcrel_offset */ |
| 1591 | |
| 1592 | /* Like GOT_TLSGD16, but no overflow. */ |
| 1593 | HOWTO (R_PPC64_GOT_TLSGD16_LO, |
| 1594 | 0, /* rightshift */ |
| 1595 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1596 | 16, /* bitsize */ |
| 1597 | FALSE, /* pc_relative */ |
| 1598 | 0, /* bitpos */ |
| 1599 | complain_overflow_dont, /* complain_on_overflow */ |
| 1600 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1601 | "R_PPC64_GOT_TLSGD16_LO", /* name */ |
| 1602 | FALSE, /* partial_inplace */ |
| 1603 | 0, /* src_mask */ |
| 1604 | 0xffff, /* dst_mask */ |
| 1605 | FALSE), /* pcrel_offset */ |
| 1606 | |
| 1607 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
| 1608 | HOWTO (R_PPC64_GOT_TLSGD16_HI, |
| 1609 | 16, /* rightshift */ |
| 1610 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1611 | 16, /* bitsize */ |
| 1612 | FALSE, /* pc_relative */ |
| 1613 | 0, /* bitpos */ |
| 1614 | complain_overflow_dont, /* complain_on_overflow */ |
| 1615 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1616 | "R_PPC64_GOT_TLSGD16_HI", /* name */ |
| 1617 | FALSE, /* partial_inplace */ |
| 1618 | 0, /* src_mask */ |
| 1619 | 0xffff, /* dst_mask */ |
| 1620 | FALSE), /* pcrel_offset */ |
| 1621 | |
| 1622 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
| 1623 | HOWTO (R_PPC64_GOT_TLSGD16_HA, |
| 1624 | 16, /* rightshift */ |
| 1625 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1626 | 16, /* bitsize */ |
| 1627 | FALSE, /* pc_relative */ |
| 1628 | 0, /* bitpos */ |
| 1629 | complain_overflow_dont, /* complain_on_overflow */ |
| 1630 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1631 | "R_PPC64_GOT_TLSGD16_HA", /* name */ |
| 1632 | FALSE, /* partial_inplace */ |
| 1633 | 0, /* src_mask */ |
| 1634 | 0xffff, /* dst_mask */ |
| 1635 | FALSE), /* pcrel_offset */ |
| 1636 | |
| 1637 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, |
| 1638 | with values (sym+add)@dtpmod and zero, and computes the offset to the |
| 1639 | first entry relative to the TOC base (r2). */ |
| 1640 | HOWTO (R_PPC64_GOT_TLSLD16, |
| 1641 | 0, /* rightshift */ |
| 1642 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1643 | 16, /* bitsize */ |
| 1644 | FALSE, /* pc_relative */ |
| 1645 | 0, /* bitpos */ |
| 1646 | complain_overflow_signed, /* complain_on_overflow */ |
| 1647 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1648 | "R_PPC64_GOT_TLSLD16", /* name */ |
| 1649 | FALSE, /* partial_inplace */ |
| 1650 | 0, /* src_mask */ |
| 1651 | 0xffff, /* dst_mask */ |
| 1652 | FALSE), /* pcrel_offset */ |
| 1653 | |
| 1654 | /* Like GOT_TLSLD16, but no overflow. */ |
| 1655 | HOWTO (R_PPC64_GOT_TLSLD16_LO, |
| 1656 | 0, /* rightshift */ |
| 1657 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1658 | 16, /* bitsize */ |
| 1659 | FALSE, /* pc_relative */ |
| 1660 | 0, /* bitpos */ |
| 1661 | complain_overflow_dont, /* complain_on_overflow */ |
| 1662 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1663 | "R_PPC64_GOT_TLSLD16_LO", /* name */ |
| 1664 | FALSE, /* partial_inplace */ |
| 1665 | 0, /* src_mask */ |
| 1666 | 0xffff, /* dst_mask */ |
| 1667 | FALSE), /* pcrel_offset */ |
| 1668 | |
| 1669 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
| 1670 | HOWTO (R_PPC64_GOT_TLSLD16_HI, |
| 1671 | 16, /* rightshift */ |
| 1672 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1673 | 16, /* bitsize */ |
| 1674 | FALSE, /* pc_relative */ |
| 1675 | 0, /* bitpos */ |
| 1676 | complain_overflow_dont, /* complain_on_overflow */ |
| 1677 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1678 | "R_PPC64_GOT_TLSLD16_HI", /* name */ |
| 1679 | FALSE, /* partial_inplace */ |
| 1680 | 0, /* src_mask */ |
| 1681 | 0xffff, /* dst_mask */ |
| 1682 | FALSE), /* pcrel_offset */ |
| 1683 | |
| 1684 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
| 1685 | HOWTO (R_PPC64_GOT_TLSLD16_HA, |
| 1686 | 16, /* rightshift */ |
| 1687 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1688 | 16, /* bitsize */ |
| 1689 | FALSE, /* pc_relative */ |
| 1690 | 0, /* bitpos */ |
| 1691 | complain_overflow_dont, /* complain_on_overflow */ |
| 1692 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1693 | "R_PPC64_GOT_TLSLD16_HA", /* name */ |
| 1694 | FALSE, /* partial_inplace */ |
| 1695 | 0, /* src_mask */ |
| 1696 | 0xffff, /* dst_mask */ |
| 1697 | FALSE), /* pcrel_offset */ |
| 1698 | |
| 1699 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes |
| 1700 | the offset to the entry relative to the TOC base (r2). */ |
| 1701 | HOWTO (R_PPC64_GOT_DTPREL16_DS, |
| 1702 | 0, /* rightshift */ |
| 1703 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1704 | 16, /* bitsize */ |
| 1705 | FALSE, /* pc_relative */ |
| 1706 | 0, /* bitpos */ |
| 1707 | complain_overflow_signed, /* complain_on_overflow */ |
| 1708 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1709 | "R_PPC64_GOT_DTPREL16_DS", /* name */ |
| 1710 | FALSE, /* partial_inplace */ |
| 1711 | 0, /* src_mask */ |
| 1712 | 0xfffc, /* dst_mask */ |
| 1713 | FALSE), /* pcrel_offset */ |
| 1714 | |
| 1715 | /* Like GOT_DTPREL16_DS, but no overflow. */ |
| 1716 | HOWTO (R_PPC64_GOT_DTPREL16_LO_DS, |
| 1717 | 0, /* rightshift */ |
| 1718 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1719 | 16, /* bitsize */ |
| 1720 | FALSE, /* pc_relative */ |
| 1721 | 0, /* bitpos */ |
| 1722 | complain_overflow_dont, /* complain_on_overflow */ |
| 1723 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1724 | "R_PPC64_GOT_DTPREL16_LO_DS", /* name */ |
| 1725 | FALSE, /* partial_inplace */ |
| 1726 | 0, /* src_mask */ |
| 1727 | 0xfffc, /* dst_mask */ |
| 1728 | FALSE), /* pcrel_offset */ |
| 1729 | |
| 1730 | /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */ |
| 1731 | HOWTO (R_PPC64_GOT_DTPREL16_HI, |
| 1732 | 16, /* rightshift */ |
| 1733 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1734 | 16, /* bitsize */ |
| 1735 | FALSE, /* pc_relative */ |
| 1736 | 0, /* bitpos */ |
| 1737 | complain_overflow_dont, /* complain_on_overflow */ |
| 1738 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1739 | "R_PPC64_GOT_DTPREL16_HI", /* name */ |
| 1740 | FALSE, /* partial_inplace */ |
| 1741 | 0, /* src_mask */ |
| 1742 | 0xffff, /* dst_mask */ |
| 1743 | FALSE), /* pcrel_offset */ |
| 1744 | |
| 1745 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
| 1746 | HOWTO (R_PPC64_GOT_DTPREL16_HA, |
| 1747 | 16, /* rightshift */ |
| 1748 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1749 | 16, /* bitsize */ |
| 1750 | FALSE, /* pc_relative */ |
| 1751 | 0, /* bitpos */ |
| 1752 | complain_overflow_dont, /* complain_on_overflow */ |
| 1753 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1754 | "R_PPC64_GOT_DTPREL16_HA", /* name */ |
| 1755 | FALSE, /* partial_inplace */ |
| 1756 | 0, /* src_mask */ |
| 1757 | 0xffff, /* dst_mask */ |
| 1758 | FALSE), /* pcrel_offset */ |
| 1759 | |
| 1760 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the |
| 1761 | offset to the entry relative to the TOC base (r2). */ |
| 1762 | HOWTO (R_PPC64_GOT_TPREL16_DS, |
| 1763 | 0, /* rightshift */ |
| 1764 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1765 | 16, /* bitsize */ |
| 1766 | FALSE, /* pc_relative */ |
| 1767 | 0, /* bitpos */ |
| 1768 | complain_overflow_signed, /* complain_on_overflow */ |
| 1769 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1770 | "R_PPC64_GOT_TPREL16_DS", /* name */ |
| 1771 | FALSE, /* partial_inplace */ |
| 1772 | 0, /* src_mask */ |
| 1773 | 0xfffc, /* dst_mask */ |
| 1774 | FALSE), /* pcrel_offset */ |
| 1775 | |
| 1776 | /* Like GOT_TPREL16_DS, but no overflow. */ |
| 1777 | HOWTO (R_PPC64_GOT_TPREL16_LO_DS, |
| 1778 | 0, /* rightshift */ |
| 1779 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1780 | 16, /* bitsize */ |
| 1781 | FALSE, /* pc_relative */ |
| 1782 | 0, /* bitpos */ |
| 1783 | complain_overflow_dont, /* complain_on_overflow */ |
| 1784 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1785 | "R_PPC64_GOT_TPREL16_LO_DS", /* name */ |
| 1786 | FALSE, /* partial_inplace */ |
| 1787 | 0, /* src_mask */ |
| 1788 | 0xfffc, /* dst_mask */ |
| 1789 | FALSE), /* pcrel_offset */ |
| 1790 | |
| 1791 | /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */ |
| 1792 | HOWTO (R_PPC64_GOT_TPREL16_HI, |
| 1793 | 16, /* rightshift */ |
| 1794 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1795 | 16, /* bitsize */ |
| 1796 | FALSE, /* pc_relative */ |
| 1797 | 0, /* bitpos */ |
| 1798 | complain_overflow_dont, /* complain_on_overflow */ |
| 1799 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1800 | "R_PPC64_GOT_TPREL16_HI", /* name */ |
| 1801 | FALSE, /* partial_inplace */ |
| 1802 | 0, /* src_mask */ |
| 1803 | 0xffff, /* dst_mask */ |
| 1804 | FALSE), /* pcrel_offset */ |
| 1805 | |
| 1806 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ |
| 1807 | HOWTO (R_PPC64_GOT_TPREL16_HA, |
| 1808 | 16, /* rightshift */ |
| 1809 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1810 | 16, /* bitsize */ |
| 1811 | FALSE, /* pc_relative */ |
| 1812 | 0, /* bitpos */ |
| 1813 | complain_overflow_dont, /* complain_on_overflow */ |
| 1814 | ppc64_elf_unhandled_reloc, /* special_function */ |
| 1815 | "R_PPC64_GOT_TPREL16_HA", /* name */ |
| 1816 | FALSE, /* partial_inplace */ |
| 1817 | 0, /* src_mask */ |
| 1818 | 0xffff, /* dst_mask */ |
| 1819 | FALSE), /* pcrel_offset */ |
| 1820 | |
| 1821 | /* GNU extension to record C++ vtable hierarchy. */ |
| 1822 | HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ |
| 1823 | 0, /* rightshift */ |
| 1824 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1825 | 0, /* bitsize */ |
| 1826 | FALSE, /* pc_relative */ |
| 1827 | 0, /* bitpos */ |
| 1828 | complain_overflow_dont, /* complain_on_overflow */ |
| 1829 | NULL, /* special_function */ |
| 1830 | "R_PPC64_GNU_VTINHERIT", /* name */ |
| 1831 | FALSE, /* partial_inplace */ |
| 1832 | 0, /* src_mask */ |
| 1833 | 0, /* dst_mask */ |
| 1834 | FALSE), /* pcrel_offset */ |
| 1835 | |
| 1836 | /* GNU extension to record C++ vtable member usage. */ |
| 1837 | HOWTO (R_PPC64_GNU_VTENTRY, /* type */ |
| 1838 | 0, /* rightshift */ |
| 1839 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 1840 | 0, /* bitsize */ |
| 1841 | FALSE, /* pc_relative */ |
| 1842 | 0, /* bitpos */ |
| 1843 | complain_overflow_dont, /* complain_on_overflow */ |
| 1844 | NULL, /* special_function */ |
| 1845 | "R_PPC64_GNU_VTENTRY", /* name */ |
| 1846 | FALSE, /* partial_inplace */ |
| 1847 | 0, /* src_mask */ |
| 1848 | 0, /* dst_mask */ |
| 1849 | FALSE), /* pcrel_offset */ |
| 1850 | }; |
| 1851 | |
| 1852 | \f |
| 1853 | /* Initialize the ppc64_elf_howto_table, so that linear accesses can |
| 1854 | be done. */ |
| 1855 | |
| 1856 | static void |
| 1857 | ppc_howto_init (void) |
| 1858 | { |
| 1859 | unsigned int i, type; |
| 1860 | |
| 1861 | for (i = 0; |
| 1862 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); |
| 1863 | i++) |
| 1864 | { |
| 1865 | type = ppc64_elf_howto_raw[i].type; |
| 1866 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) |
| 1867 | / sizeof (ppc64_elf_howto_table[0]))); |
| 1868 | ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i]; |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | static reloc_howto_type * |
| 1873 | ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
| 1874 | bfd_reloc_code_real_type code) |
| 1875 | { |
| 1876 | enum elf_ppc64_reloc_type r = R_PPC64_NONE; |
| 1877 | |
| 1878 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
| 1879 | /* Initialize howto table if needed. */ |
| 1880 | ppc_howto_init (); |
| 1881 | |
| 1882 | switch (code) |
| 1883 | { |
| 1884 | default: |
| 1885 | return NULL; |
| 1886 | |
| 1887 | case BFD_RELOC_NONE: r = R_PPC64_NONE; |
| 1888 | break; |
| 1889 | case BFD_RELOC_32: r = R_PPC64_ADDR32; |
| 1890 | break; |
| 1891 | case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24; |
| 1892 | break; |
| 1893 | case BFD_RELOC_16: r = R_PPC64_ADDR16; |
| 1894 | break; |
| 1895 | case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO; |
| 1896 | break; |
| 1897 | case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI; |
| 1898 | break; |
| 1899 | case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA; |
| 1900 | break; |
| 1901 | case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14; |
| 1902 | break; |
| 1903 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN; |
| 1904 | break; |
| 1905 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN; |
| 1906 | break; |
| 1907 | case BFD_RELOC_PPC_B26: r = R_PPC64_REL24; |
| 1908 | break; |
| 1909 | case BFD_RELOC_PPC_B16: r = R_PPC64_REL14; |
| 1910 | break; |
| 1911 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN; |
| 1912 | break; |
| 1913 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN; |
| 1914 | break; |
| 1915 | case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16; |
| 1916 | break; |
| 1917 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO; |
| 1918 | break; |
| 1919 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI; |
| 1920 | break; |
| 1921 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA; |
| 1922 | break; |
| 1923 | case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY; |
| 1924 | break; |
| 1925 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT; |
| 1926 | break; |
| 1927 | case BFD_RELOC_32_PCREL: r = R_PPC64_REL32; |
| 1928 | break; |
| 1929 | case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32; |
| 1930 | break; |
| 1931 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32; |
| 1932 | break; |
| 1933 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO; |
| 1934 | break; |
| 1935 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI; |
| 1936 | break; |
| 1937 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA; |
| 1938 | break; |
| 1939 | case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF; |
| 1940 | break; |
| 1941 | case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO; |
| 1942 | break; |
| 1943 | case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI; |
| 1944 | break; |
| 1945 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA; |
| 1946 | break; |
| 1947 | case BFD_RELOC_CTOR: r = R_PPC64_ADDR64; |
| 1948 | break; |
| 1949 | case BFD_RELOC_64: r = R_PPC64_ADDR64; |
| 1950 | break; |
| 1951 | case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER; |
| 1952 | break; |
| 1953 | case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA; |
| 1954 | break; |
| 1955 | case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST; |
| 1956 | break; |
| 1957 | case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA; |
| 1958 | break; |
| 1959 | case BFD_RELOC_64_PCREL: r = R_PPC64_REL64; |
| 1960 | break; |
| 1961 | case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64; |
| 1962 | break; |
| 1963 | case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64; |
| 1964 | break; |
| 1965 | case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16; |
| 1966 | break; |
| 1967 | case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO; |
| 1968 | break; |
| 1969 | case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI; |
| 1970 | break; |
| 1971 | case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA; |
| 1972 | break; |
| 1973 | case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC; |
| 1974 | break; |
| 1975 | case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16; |
| 1976 | break; |
| 1977 | case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO; |
| 1978 | break; |
| 1979 | case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI; |
| 1980 | break; |
| 1981 | case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA; |
| 1982 | break; |
| 1983 | case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS; |
| 1984 | break; |
| 1985 | case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS; |
| 1986 | break; |
| 1987 | case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS; |
| 1988 | break; |
| 1989 | case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS; |
| 1990 | break; |
| 1991 | case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS; |
| 1992 | break; |
| 1993 | case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS; |
| 1994 | break; |
| 1995 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS; |
| 1996 | break; |
| 1997 | case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS; |
| 1998 | break; |
| 1999 | case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS; |
| 2000 | break; |
| 2001 | case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS; |
| 2002 | break; |
| 2003 | case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS; |
| 2004 | break; |
| 2005 | case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS; |
| 2006 | break; |
| 2007 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64; |
| 2008 | break; |
| 2009 | case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16; |
| 2010 | break; |
| 2011 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO; |
| 2012 | break; |
| 2013 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI; |
| 2014 | break; |
| 2015 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA; |
| 2016 | break; |
| 2017 | case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64; |
| 2018 | break; |
| 2019 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16; |
| 2020 | break; |
| 2021 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO; |
| 2022 | break; |
| 2023 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI; |
| 2024 | break; |
| 2025 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA; |
| 2026 | break; |
| 2027 | case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64; |
| 2028 | break; |
| 2029 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16; |
| 2030 | break; |
| 2031 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO; |
| 2032 | break; |
| 2033 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI; |
| 2034 | break; |
| 2035 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA; |
| 2036 | break; |
| 2037 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16; |
| 2038 | break; |
| 2039 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO; |
| 2040 | break; |
| 2041 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI; |
| 2042 | break; |
| 2043 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA; |
| 2044 | break; |
| 2045 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS; |
| 2046 | break; |
| 2047 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS; |
| 2048 | break; |
| 2049 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI; |
| 2050 | break; |
| 2051 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA; |
| 2052 | break; |
| 2053 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS; |
| 2054 | break; |
| 2055 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS; |
| 2056 | break; |
| 2057 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI; |
| 2058 | break; |
| 2059 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA; |
| 2060 | break; |
| 2061 | case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS; |
| 2062 | break; |
| 2063 | case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS; |
| 2064 | break; |
| 2065 | case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER; |
| 2066 | break; |
| 2067 | case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA; |
| 2068 | break; |
| 2069 | case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST; |
| 2070 | break; |
| 2071 | case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA; |
| 2072 | break; |
| 2073 | case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS; |
| 2074 | break; |
| 2075 | case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS; |
| 2076 | break; |
| 2077 | case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER; |
| 2078 | break; |
| 2079 | case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA; |
| 2080 | break; |
| 2081 | case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST; |
| 2082 | break; |
| 2083 | case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA; |
| 2084 | break; |
| 2085 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT; |
| 2086 | break; |
| 2087 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY; |
| 2088 | break; |
| 2089 | } |
| 2090 | |
| 2091 | return ppc64_elf_howto_table[r]; |
| 2092 | }; |
| 2093 | |
| 2094 | /* Set the howto pointer for a PowerPC ELF reloc. */ |
| 2095 | |
| 2096 | static void |
| 2097 | ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, |
| 2098 | Elf_Internal_Rela *dst) |
| 2099 | { |
| 2100 | unsigned int type; |
| 2101 | |
| 2102 | /* Initialize howto table if needed. */ |
| 2103 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
| 2104 | ppc_howto_init (); |
| 2105 | |
| 2106 | type = ELF64_R_TYPE (dst->r_info); |
| 2107 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) |
| 2108 | / sizeof (ppc64_elf_howto_table[0]))); |
| 2109 | cache_ptr->howto = ppc64_elf_howto_table[type]; |
| 2110 | } |
| 2111 | |
| 2112 | /* Handle the R_PPC64_ADDR16_HA and similar relocs. */ |
| 2113 | |
| 2114 | static bfd_reloc_status_type |
| 2115 | ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
| 2116 | void *data, asection *input_section, |
| 2117 | bfd *output_bfd, char **error_message) |
| 2118 | { |
| 2119 | /* If this is a relocatable link (output_bfd test tells us), just |
| 2120 | call the generic function. Any adjustment will be done at final |
| 2121 | link time. */ |
| 2122 | if (output_bfd != NULL) |
| 2123 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
| 2124 | input_section, output_bfd, error_message); |
| 2125 | |
| 2126 | /* Adjust the addend for sign extension of the low 16 bits. |
| 2127 | We won't actually be using the low 16 bits, so trashing them |
| 2128 | doesn't matter. */ |
| 2129 | reloc_entry->addend += 0x8000; |
| 2130 | return bfd_reloc_continue; |
| 2131 | } |
| 2132 | |
| 2133 | static bfd_reloc_status_type |
| 2134 | ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
| 2135 | void *data, asection *input_section, |
| 2136 | bfd *output_bfd, char **error_message) |
| 2137 | { |
| 2138 | long insn; |
| 2139 | enum elf_ppc64_reloc_type r_type; |
| 2140 | bfd_size_type octets; |
| 2141 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ |
| 2142 | bfd_boolean is_power4 = FALSE; |
| 2143 | |
| 2144 | /* If this is a relocatable link (output_bfd test tells us), just |
| 2145 | call the generic function. Any adjustment will be done at final |
| 2146 | link time. */ |
| 2147 | if (output_bfd != NULL) |
| 2148 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
| 2149 | input_section, output_bfd, error_message); |
| 2150 | |
| 2151 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); |
| 2152 | insn = bfd_get_32 (abfd, (bfd_byte *) data + octets); |
| 2153 | insn &= ~(0x01 << 21); |
| 2154 | r_type = reloc_entry->howto->type; |
| 2155 | if (r_type == R_PPC64_ADDR14_BRTAKEN |
| 2156 | || r_type == R_PPC64_REL14_BRTAKEN) |
| 2157 | insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
| 2158 | |
| 2159 | if (is_power4) |
| 2160 | { |
| 2161 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
| 2162 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 |
| 2163 | for branch on CTR insns (BO == 1a00t or 1a01t). */ |
| 2164 | if ((insn & (0x14 << 21)) == (0x04 << 21)) |
| 2165 | insn |= 0x02 << 21; |
| 2166 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) |
| 2167 | insn |= 0x08 << 21; |
| 2168 | else |
| 2169 | return bfd_reloc_continue; |
| 2170 | } |
| 2171 | else |
| 2172 | { |
| 2173 | bfd_vma target = 0; |
| 2174 | bfd_vma from; |
| 2175 | |
| 2176 | if (!bfd_is_com_section (symbol->section)) |
| 2177 | target = symbol->value; |
| 2178 | target += symbol->section->output_section->vma; |
| 2179 | target += symbol->section->output_offset; |
| 2180 | target += reloc_entry->addend; |
| 2181 | |
| 2182 | from = (reloc_entry->address |
| 2183 | + input_section->output_offset |
| 2184 | + input_section->output_section->vma); |
| 2185 | |
| 2186 | /* Invert 'y' bit if not the default. */ |
| 2187 | if ((bfd_signed_vma) (target - from) < 0) |
| 2188 | insn ^= 0x01 << 21; |
| 2189 | } |
| 2190 | bfd_put_32 (abfd, insn, (bfd_byte *) data + octets); |
| 2191 | return bfd_reloc_continue; |
| 2192 | } |
| 2193 | |
| 2194 | static bfd_reloc_status_type |
| 2195 | ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
| 2196 | void *data, asection *input_section, |
| 2197 | bfd *output_bfd, char **error_message) |
| 2198 | { |
| 2199 | /* If this is a relocatable link (output_bfd test tells us), just |
| 2200 | call the generic function. Any adjustment will be done at final |
| 2201 | link time. */ |
| 2202 | if (output_bfd != NULL) |
| 2203 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
| 2204 | input_section, output_bfd, error_message); |
| 2205 | |
| 2206 | /* Subtract the symbol section base address. */ |
| 2207 | reloc_entry->addend -= symbol->section->output_section->vma; |
| 2208 | return bfd_reloc_continue; |
| 2209 | } |
| 2210 | |
| 2211 | static bfd_reloc_status_type |
| 2212 | ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
| 2213 | void *data, asection *input_section, |
| 2214 | bfd *output_bfd, char **error_message) |
| 2215 | { |
| 2216 | /* If this is a relocatable link (output_bfd test tells us), just |
| 2217 | call the generic function. Any adjustment will be done at final |
| 2218 | link time. */ |
| 2219 | if (output_bfd != NULL) |
| 2220 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
| 2221 | input_section, output_bfd, error_message); |
| 2222 | |
| 2223 | /* Subtract the symbol section base address. */ |
| 2224 | reloc_entry->addend -= symbol->section->output_section->vma; |
| 2225 | |
| 2226 | /* Adjust the addend for sign extension of the low 16 bits. */ |
| 2227 | reloc_entry->addend += 0x8000; |
| 2228 | return bfd_reloc_continue; |
| 2229 | } |
| 2230 | |
| 2231 | static bfd_reloc_status_type |
| 2232 | ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
| 2233 | void *data, asection *input_section, |
| 2234 | bfd *output_bfd, char **error_message) |
| 2235 | { |
| 2236 | bfd_vma TOCstart; |
| 2237 | |
| 2238 | /* If this is a relocatable link (output_bfd test tells us), just |
| 2239 | call the generic function. Any adjustment will be done at final |
| 2240 | link time. */ |
| 2241 | if (output_bfd != NULL) |
| 2242 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
| 2243 | input_section, output_bfd, error_message); |
| 2244 | |
| 2245 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); |
| 2246 | if (TOCstart == 0) |
| 2247 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); |
| 2248 | |
| 2249 | /* Subtract the TOC base address. */ |
| 2250 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; |
| 2251 | return bfd_reloc_continue; |
| 2252 | } |
| 2253 | |
| 2254 | static bfd_reloc_status_type |
| 2255 | ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
| 2256 | void *data, asection *input_section, |
| 2257 | bfd *output_bfd, char **error_message) |
| 2258 | { |
| 2259 | bfd_vma TOCstart; |
| 2260 | |
| 2261 | /* If this is a relocatable link (output_bfd test tells us), just |
| 2262 | call the generic function. Any adjustment will be done at final |
| 2263 | link time. */ |
| 2264 | if (output_bfd != NULL) |
| 2265 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
| 2266 | input_section, output_bfd, error_message); |
| 2267 | |
| 2268 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); |
| 2269 | if (TOCstart == 0) |
| 2270 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); |
| 2271 | |
| 2272 | /* Subtract the TOC base address. */ |
| 2273 | reloc_entry->addend -= TOCstart + TOC_BASE_OFF; |
| 2274 | |
| 2275 | /* Adjust the addend for sign extension of the low 16 bits. */ |
| 2276 | reloc_entry->addend += 0x8000; |
| 2277 | return bfd_reloc_continue; |
| 2278 | } |
| 2279 | |
| 2280 | static bfd_reloc_status_type |
| 2281 | ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
| 2282 | void *data, asection *input_section, |
| 2283 | bfd *output_bfd, char **error_message) |
| 2284 | { |
| 2285 | bfd_vma TOCstart; |
| 2286 | bfd_size_type octets; |
| 2287 | |
| 2288 | /* If this is a relocatable link (output_bfd test tells us), just |
| 2289 | call the generic function. Any adjustment will be done at final |
| 2290 | link time. */ |
| 2291 | if (output_bfd != NULL) |
| 2292 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
| 2293 | input_section, output_bfd, error_message); |
| 2294 | |
| 2295 | TOCstart = _bfd_get_gp_value (input_section->output_section->owner); |
| 2296 | if (TOCstart == 0) |
| 2297 | TOCstart = ppc64_elf_toc (input_section->output_section->owner); |
| 2298 | |
| 2299 | octets = reloc_entry->address * bfd_octets_per_byte (abfd); |
| 2300 | bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets); |
| 2301 | return bfd_reloc_ok; |
| 2302 | } |
| 2303 | |
| 2304 | static bfd_reloc_status_type |
| 2305 | ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
| 2306 | void *data, asection *input_section, |
| 2307 | bfd *output_bfd, char **error_message) |
| 2308 | { |
| 2309 | /* If this is a relocatable link (output_bfd test tells us), just |
| 2310 | call the generic function. Any adjustment will be done at final |
| 2311 | link time. */ |
| 2312 | if (output_bfd != NULL) |
| 2313 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, |
| 2314 | input_section, output_bfd, error_message); |
| 2315 | |
| 2316 | if (error_message != NULL) |
| 2317 | { |
| 2318 | static char buf[60]; |
| 2319 | sprintf (buf, "generic linker can't handle %s", |
| 2320 | reloc_entry->howto->name); |
| 2321 | *error_message = buf; |
| 2322 | } |
| 2323 | return bfd_reloc_dangerous; |
| 2324 | } |
| 2325 | |
| 2326 | struct ppc64_elf_obj_tdata |
| 2327 | { |
| 2328 | struct elf_obj_tdata elf; |
| 2329 | |
| 2330 | /* Shortcuts to dynamic linker sections. */ |
| 2331 | asection *got; |
| 2332 | asection *relgot; |
| 2333 | |
| 2334 | /* TLS local dynamic got entry handling. Suppose for multiple GOT |
| 2335 | sections means we potentially need one of these for each input bfd. */ |
| 2336 | union { |
| 2337 | bfd_signed_vma refcount; |
| 2338 | bfd_vma offset; |
| 2339 | } tlsld_got; |
| 2340 | }; |
| 2341 | |
| 2342 | #define ppc64_elf_tdata(bfd) \ |
| 2343 | ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any) |
| 2344 | |
| 2345 | #define ppc64_tlsld_got(bfd) \ |
| 2346 | (&ppc64_elf_tdata (bfd)->tlsld_got) |
| 2347 | |
| 2348 | /* Override the generic function because we store some extras. */ |
| 2349 | |
| 2350 | static bfd_boolean |
| 2351 | ppc64_elf_mkobject (bfd *abfd) |
| 2352 | { |
| 2353 | bfd_size_type amt = sizeof (struct ppc64_elf_obj_tdata); |
| 2354 | abfd->tdata.any = bfd_zalloc (abfd, amt); |
| 2355 | if (abfd->tdata.any == NULL) |
| 2356 | return FALSE; |
| 2357 | return TRUE; |
| 2358 | } |
| 2359 | |
| 2360 | /* Fix bad default arch selected for a 64 bit input bfd when the |
| 2361 | default is 32 bit. */ |
| 2362 | |
| 2363 | static bfd_boolean |
| 2364 | ppc64_elf_object_p (bfd *abfd) |
| 2365 | { |
| 2366 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32) |
| 2367 | { |
| 2368 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); |
| 2369 | |
| 2370 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64) |
| 2371 | { |
| 2372 | /* Relies on arch after 32 bit default being 64 bit default. */ |
| 2373 | abfd->arch_info = abfd->arch_info->next; |
| 2374 | BFD_ASSERT (abfd->arch_info->bits_per_word == 64); |
| 2375 | } |
| 2376 | } |
| 2377 | return TRUE; |
| 2378 | } |
| 2379 | |
| 2380 | /* Support for core dump NOTE sections. */ |
| 2381 | |
| 2382 | static bfd_boolean |
| 2383 | ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
| 2384 | { |
| 2385 | size_t offset, size; |
| 2386 | |
| 2387 | if (note->descsz != 504) |
| 2388 | return FALSE; |
| 2389 | |
| 2390 | /* pr_cursig */ |
| 2391 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); |
| 2392 | |
| 2393 | /* pr_pid */ |
| 2394 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32); |
| 2395 | |
| 2396 | /* pr_reg */ |
| 2397 | offset = 112; |
| 2398 | size = 384; |
| 2399 | |
| 2400 | /* Make a ".reg/999" section. */ |
| 2401 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", |
| 2402 | size, note->descpos + offset); |
| 2403 | } |
| 2404 | |
| 2405 | static bfd_boolean |
| 2406 | ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
| 2407 | { |
| 2408 | if (note->descsz != 136) |
| 2409 | return FALSE; |
| 2410 | |
| 2411 | elf_tdata (abfd)->core_program |
| 2412 | = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); |
| 2413 | elf_tdata (abfd)->core_command |
| 2414 | = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); |
| 2415 | |
| 2416 | return TRUE; |
| 2417 | } |
| 2418 | |
| 2419 | /* Merge backend specific data from an object file to the output |
| 2420 | object file when linking. */ |
| 2421 | |
| 2422 | static bfd_boolean |
| 2423 | ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) |
| 2424 | { |
| 2425 | /* Check if we have the same endianess. */ |
| 2426 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder |
| 2427 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
| 2428 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
| 2429 | { |
| 2430 | const char *msg; |
| 2431 | |
| 2432 | if (bfd_big_endian (ibfd)) |
| 2433 | msg = _("%s: compiled for a big endian system " |
| 2434 | "and target is little endian"); |
| 2435 | else |
| 2436 | msg = _("%s: compiled for a little endian system " |
| 2437 | "and target is big endian"); |
| 2438 | |
| 2439 | (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd)); |
| 2440 | |
| 2441 | bfd_set_error (bfd_error_wrong_format); |
| 2442 | return FALSE; |
| 2443 | } |
| 2444 | |
| 2445 | return TRUE; |
| 2446 | } |
| 2447 | |
| 2448 | /* Add extra PPC sections. */ |
| 2449 | |
| 2450 | static struct bfd_elf_special_section const ppc64_elf_special_sections[]= |
| 2451 | { |
| 2452 | { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, |
| 2453 | { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, |
| 2454 | { ".plt", 4, 0, SHT_NOBITS, 0 }, |
| 2455 | { ".toc", 4, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, |
| 2456 | { ".toc1", 5, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, |
| 2457 | { ".tocbss", 7, 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, |
| 2458 | { NULL, 0, 0, 0, 0 } |
| 2459 | }; |
| 2460 | |
| 2461 | struct _ppc64_elf_section_data |
| 2462 | { |
| 2463 | struct bfd_elf_section_data elf; |
| 2464 | |
| 2465 | /* An array with one entry for each opd function descriptor. */ |
| 2466 | union |
| 2467 | { |
| 2468 | /* Points to the function code section for local opd entries. */ |
| 2469 | asection **func_sec; |
| 2470 | /* After editing .opd, adjust references to opd local syms. */ |
| 2471 | long *adjust; |
| 2472 | } opd; |
| 2473 | |
| 2474 | /* An array for toc sections, indexed by offset/8. |
| 2475 | Specifies the relocation symbol index used at a given toc offset. */ |
| 2476 | unsigned *t_symndx; |
| 2477 | }; |
| 2478 | |
| 2479 | #define ppc64_elf_section_data(sec) \ |
| 2480 | ((struct _ppc64_elf_section_data *) elf_section_data (sec)) |
| 2481 | |
| 2482 | static bfd_boolean |
| 2483 | ppc64_elf_new_section_hook (bfd *abfd, asection *sec) |
| 2484 | { |
| 2485 | struct _ppc64_elf_section_data *sdata; |
| 2486 | bfd_size_type amt = sizeof (*sdata); |
| 2487 | |
| 2488 | sdata = bfd_zalloc (abfd, amt); |
| 2489 | if (sdata == NULL) |
| 2490 | return FALSE; |
| 2491 | sec->used_by_bfd = sdata; |
| 2492 | |
| 2493 | return _bfd_elf_new_section_hook (abfd, sec); |
| 2494 | } |
| 2495 | |
| 2496 | static void * |
| 2497 | get_opd_info (asection * sec) |
| 2498 | { |
| 2499 | if (sec != NULL |
| 2500 | && ppc64_elf_section_data (sec) != NULL |
| 2501 | && ppc64_elf_section_data (sec)->opd.adjust != NULL) |
| 2502 | return ppc64_elf_section_data (sec)->opd.adjust; |
| 2503 | return NULL; |
| 2504 | } |
| 2505 | \f |
| 2506 | /* The following functions are specific to the ELF linker, while |
| 2507 | functions above are used generally. Those named ppc64_elf_* are |
| 2508 | called by the main ELF linker code. They appear in this file more |
| 2509 | or less in the order in which they are called. eg. |
| 2510 | ppc64_elf_check_relocs is called early in the link process, |
| 2511 | ppc64_elf_finish_dynamic_sections is one of the last functions |
| 2512 | called. |
| 2513 | |
| 2514 | PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that |
| 2515 | functions have both a function code symbol and a function descriptor |
| 2516 | symbol. A call to foo in a relocatable object file looks like: |
| 2517 | |
| 2518 | . .text |
| 2519 | . x: |
| 2520 | . bl .foo |
| 2521 | . nop |
| 2522 | |
| 2523 | The function definition in another object file might be: |
| 2524 | |
| 2525 | . .section .opd |
| 2526 | . foo: .quad .foo |
| 2527 | . .quad .TOC.@tocbase |
| 2528 | . .quad 0 |
| 2529 | . |
| 2530 | . .text |
| 2531 | . .foo: blr |
| 2532 | |
| 2533 | When the linker resolves the call during a static link, the branch |
| 2534 | unsurprisingly just goes to .foo and the .opd information is unused. |
| 2535 | If the function definition is in a shared library, things are a little |
| 2536 | different: The call goes via a plt call stub, the opd information gets |
| 2537 | copied to the plt, and the linker patches the nop. |
| 2538 | |
| 2539 | . x: |
| 2540 | . bl .foo_stub |
| 2541 | . ld 2,40(1) |
| 2542 | . |
| 2543 | . |
| 2544 | . .foo_stub: |
| 2545 | . addis 12,2,Lfoo@toc@ha # in practice, the call stub |
| 2546 | . addi 12,12,Lfoo@toc@l # is slightly optimized, but |
| 2547 | . std 2,40(1) # this is the general idea |
| 2548 | . ld 11,0(12) |
| 2549 | . ld 2,8(12) |
| 2550 | . mtctr 11 |
| 2551 | . ld 11,16(12) |
| 2552 | . bctr |
| 2553 | . |
| 2554 | . .section .plt |
| 2555 | . Lfoo: reloc (R_PPC64_JMP_SLOT, foo) |
| 2556 | |
| 2557 | The "reloc ()" notation is supposed to indicate that the linker emits |
| 2558 | an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd |
| 2559 | copying. |
| 2560 | |
| 2561 | What are the difficulties here? Well, firstly, the relocations |
| 2562 | examined by the linker in check_relocs are against the function code |
| 2563 | sym .foo, while the dynamic relocation in the plt is emitted against |
| 2564 | the function descriptor symbol, foo. Somewhere along the line, we need |
| 2565 | to carefully copy dynamic link information from one symbol to the other. |
| 2566 | Secondly, the generic part of the elf linker will make .foo a dynamic |
| 2567 | symbol as is normal for most other backends. We need foo dynamic |
| 2568 | instead, at least for an application final link. However, when |
| 2569 | creating a shared library containing foo, we need to have both symbols |
| 2570 | dynamic so that references to .foo are satisfied during the early |
| 2571 | stages of linking. Otherwise the linker might decide to pull in a |
| 2572 | definition from some other object, eg. a static library. */ |
| 2573 | |
| 2574 | /* The linker needs to keep track of the number of relocs that it |
| 2575 | decides to copy as dynamic relocs in check_relocs for each symbol. |
| 2576 | This is so that it can later discard them if they are found to be |
| 2577 | unnecessary. We store the information in a field extending the |
| 2578 | regular ELF linker hash table. */ |
| 2579 | |
| 2580 | struct ppc_dyn_relocs |
| 2581 | { |
| 2582 | struct ppc_dyn_relocs *next; |
| 2583 | |
| 2584 | /* The input section of the reloc. */ |
| 2585 | asection *sec; |
| 2586 | |
| 2587 | /* Total number of relocs copied for the input section. */ |
| 2588 | bfd_size_type count; |
| 2589 | |
| 2590 | /* Number of pc-relative relocs copied for the input section. */ |
| 2591 | bfd_size_type pc_count; |
| 2592 | }; |
| 2593 | |
| 2594 | /* Track GOT entries needed for a given symbol. We might need more |
| 2595 | than one got entry per symbol. */ |
| 2596 | struct got_entry |
| 2597 | { |
| 2598 | struct got_entry *next; |
| 2599 | |
| 2600 | /* The symbol addend that we'll be placing in the GOT. */ |
| 2601 | bfd_vma addend; |
| 2602 | |
| 2603 | /* Unlike other ELF targets, we use separate GOT entries for the same |
| 2604 | symbol referenced from different input files. This is to support |
| 2605 | automatic multiple TOC/GOT sections, where the TOC base can vary |
| 2606 | from one input file to another. |
| 2607 | |
| 2608 | Point to the BFD owning this GOT entry. */ |
| 2609 | bfd *owner; |
| 2610 | |
| 2611 | /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD, |
| 2612 | TLS_TPREL or TLS_DTPREL for tls entries. */ |
| 2613 | char tls_type; |
| 2614 | |
| 2615 | /* Reference count until size_dynamic_sections, GOT offset thereafter. */ |
| 2616 | union |
| 2617 | { |
| 2618 | bfd_signed_vma refcount; |
| 2619 | bfd_vma offset; |
| 2620 | } got; |
| 2621 | }; |
| 2622 | |
| 2623 | /* The same for PLT. */ |
| 2624 | struct plt_entry |
| 2625 | { |
| 2626 | struct plt_entry *next; |
| 2627 | |
| 2628 | bfd_vma addend; |
| 2629 | |
| 2630 | union |
| 2631 | { |
| 2632 | bfd_signed_vma refcount; |
| 2633 | bfd_vma offset; |
| 2634 | } plt; |
| 2635 | }; |
| 2636 | |
| 2637 | /* Of those relocs that might be copied as dynamic relocs, this macro |
| 2638 | selects those that must be copied when linking a shared library, |
| 2639 | even when the symbol is local. */ |
| 2640 | |
| 2641 | #define MUST_BE_DYN_RELOC(RTYPE) \ |
| 2642 | ((RTYPE) != R_PPC64_REL32 \ |
| 2643 | && (RTYPE) != R_PPC64_REL64 \ |
| 2644 | && (RTYPE) != R_PPC64_REL30) |
| 2645 | |
| 2646 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
| 2647 | copying dynamic variables from a shared lib into an app's dynbss |
| 2648 | section, and instead use a dynamic relocation to point into the |
| 2649 | shared lib. With code that gcc generates, it's vital that this be |
| 2650 | enabled; In the PowerPC64 ABI, the address of a function is actually |
| 2651 | the address of a function descriptor, which resides in the .opd |
| 2652 | section. gcc uses the descriptor directly rather than going via the |
| 2653 | GOT as some other ABI's do, which means that initialized function |
| 2654 | pointers must reference the descriptor. Thus, a function pointer |
| 2655 | initialized to the address of a function in a shared library will |
| 2656 | either require a copy reloc, or a dynamic reloc. Using a copy reloc |
| 2657 | redefines the function descriptor symbol to point to the copy. This |
| 2658 | presents a problem as a plt entry for that function is also |
| 2659 | initialized from the function descriptor symbol and the copy reloc |
| 2660 | may not be initialized first. */ |
| 2661 | #define ELIMINATE_COPY_RELOCS 1 |
| 2662 | |
| 2663 | /* Section name for stubs is the associated section name plus this |
| 2664 | string. */ |
| 2665 | #define STUB_SUFFIX ".stub" |
| 2666 | |
| 2667 | /* Linker stubs. |
| 2668 | ppc_stub_long_branch: |
| 2669 | Used when a 14 bit branch (or even a 24 bit branch) can't reach its |
| 2670 | destination, but a 24 bit branch in a stub section will reach. |
| 2671 | . b dest |
| 2672 | |
| 2673 | ppc_stub_plt_branch: |
| 2674 | Similar to the above, but a 24 bit branch in the stub section won't |
| 2675 | reach its destination. |
| 2676 | . addis %r12,%r2,xxx@toc@ha |
| 2677 | . ld %r11,xxx@toc@l(%r12) |
| 2678 | . mtctr %r11 |
| 2679 | . bctr |
| 2680 | |
| 2681 | ppc_stub_plt_call: |
| 2682 | Used to call a function in a shared library. If it so happens that |
| 2683 | the plt entry referenced crosses a 64k boundary, then an extra |
| 2684 | "addis %r12,%r12,1" will be inserted before the load at xxx+8 or |
| 2685 | xxx+16 as appropriate. |
| 2686 | . addis %r12,%r2,xxx@toc@ha |
| 2687 | . std %r2,40(%r1) |
| 2688 | . ld %r11,xxx+0@toc@l(%r12) |
| 2689 | . ld %r2,xxx+8@toc@l(%r12) |
| 2690 | . mtctr %r11 |
| 2691 | . ld %r11,xxx+16@toc@l(%r12) |
| 2692 | . bctr |
| 2693 | |
| 2694 | ppc_stub_long_branch and ppc_stub_plt_branch may also have additional |
| 2695 | code to adjust the value and save r2 to support multiple toc sections. |
| 2696 | A ppc_stub_long_branch with an r2 offset looks like: |
| 2697 | . std %r2,40(%r1) |
| 2698 | . addis %r2,%r2,off@ha |
| 2699 | . addi %r2,%r2,off@l |
| 2700 | . b dest |
| 2701 | |
| 2702 | A ppc_stub_plt_branch with an r2 offset looks like: |
| 2703 | . std %r2,40(%r1) |
| 2704 | . addis %r12,%r2,xxx@toc@ha |
| 2705 | . ld %r11,xxx@toc@l(%r12) |
| 2706 | . addis %r2,%r2,off@ha |
| 2707 | . addi %r2,%r2,off@l |
| 2708 | . mtctr %r11 |
| 2709 | . bctr |
| 2710 | */ |
| 2711 | |
| 2712 | enum ppc_stub_type { |
| 2713 | ppc_stub_none, |
| 2714 | ppc_stub_long_branch, |
| 2715 | ppc_stub_long_branch_r2off, |
| 2716 | ppc_stub_plt_branch, |
| 2717 | ppc_stub_plt_branch_r2off, |
| 2718 | ppc_stub_plt_call |
| 2719 | }; |
| 2720 | |
| 2721 | struct ppc_stub_hash_entry { |
| 2722 | |
| 2723 | /* Base hash table entry structure. */ |
| 2724 | struct bfd_hash_entry root; |
| 2725 | |
| 2726 | enum ppc_stub_type stub_type; |
| 2727 | |
| 2728 | /* The stub section. */ |
| 2729 | asection *stub_sec; |
| 2730 | |
| 2731 | /* Offset within stub_sec of the beginning of this stub. */ |
| 2732 | bfd_vma stub_offset; |
| 2733 | |
| 2734 | /* Given the symbol's value and its section we can determine its final |
| 2735 | value when building the stubs (so the stub knows where to jump. */ |
| 2736 | bfd_vma target_value; |
| 2737 | asection *target_section; |
| 2738 | |
| 2739 | /* The symbol table entry, if any, that this was derived from. */ |
| 2740 | struct ppc_link_hash_entry *h; |
| 2741 | |
| 2742 | /* And the reloc addend that this was derived from. */ |
| 2743 | bfd_vma addend; |
| 2744 | |
| 2745 | /* Where this stub is being called from, or, in the case of combined |
| 2746 | stub sections, the first input section in the group. */ |
| 2747 | asection *id_sec; |
| 2748 | }; |
| 2749 | |
| 2750 | struct ppc_branch_hash_entry { |
| 2751 | |
| 2752 | /* Base hash table entry structure. */ |
| 2753 | struct bfd_hash_entry root; |
| 2754 | |
| 2755 | /* Offset within .branch_lt. */ |
| 2756 | unsigned int offset; |
| 2757 | |
| 2758 | /* Generation marker. */ |
| 2759 | unsigned int iter; |
| 2760 | }; |
| 2761 | |
| 2762 | struct ppc_link_hash_entry |
| 2763 | { |
| 2764 | struct elf_link_hash_entry elf; |
| 2765 | |
| 2766 | /* A pointer to the most recently used stub hash entry against this |
| 2767 | symbol. */ |
| 2768 | struct ppc_stub_hash_entry *stub_cache; |
| 2769 | |
| 2770 | /* Track dynamic relocs copied for this symbol. */ |
| 2771 | struct ppc_dyn_relocs *dyn_relocs; |
| 2772 | |
| 2773 | /* Link between function code and descriptor symbols. */ |
| 2774 | struct ppc_link_hash_entry *oh; |
| 2775 | |
| 2776 | /* Flag function code and descriptor symbols. */ |
| 2777 | unsigned int is_func:1; |
| 2778 | unsigned int is_func_descriptor:1; |
| 2779 | |
| 2780 | /* Whether global opd sym has been adjusted or not. */ |
| 2781 | unsigned int adjust_done:1; |
| 2782 | |
| 2783 | /* Contexts in which symbol is used in the GOT (or TOC). |
| 2784 | TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the |
| 2785 | corresponding relocs are encountered during check_relocs. |
| 2786 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to |
| 2787 | indicate the corresponding GOT entry type is not needed. |
| 2788 | tls_optimize may also set TLS_TPRELGD when a GD reloc turns into |
| 2789 | a TPREL one. We use a separate flag rather than setting TPREL |
| 2790 | just for convenience in distinguishing the two cases. */ |
| 2791 | #define TLS_GD 1 /* GD reloc. */ |
| 2792 | #define TLS_LD 2 /* LD reloc. */ |
| 2793 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ |
| 2794 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ |
| 2795 | #define TLS_TLS 16 /* Any TLS reloc. */ |
| 2796 | #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */ |
| 2797 | #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */ |
| 2798 | char tls_mask; |
| 2799 | }; |
| 2800 | |
| 2801 | /* ppc64 ELF linker hash table. */ |
| 2802 | |
| 2803 | struct ppc_link_hash_table |
| 2804 | { |
| 2805 | struct elf_link_hash_table elf; |
| 2806 | |
| 2807 | /* The stub hash table. */ |
| 2808 | struct bfd_hash_table stub_hash_table; |
| 2809 | |
| 2810 | /* Another hash table for plt_branch stubs. */ |
| 2811 | struct bfd_hash_table branch_hash_table; |
| 2812 | |
| 2813 | /* Linker stub bfd. */ |
| 2814 | bfd *stub_bfd; |
| 2815 | |
| 2816 | /* Linker call-backs. */ |
| 2817 | asection * (*add_stub_section) (const char *, asection *); |
| 2818 | void (*layout_sections_again) (void); |
| 2819 | |
| 2820 | /* Array to keep track of which stub sections have been created, and |
| 2821 | information on stub grouping. */ |
| 2822 | struct map_stub { |
| 2823 | /* This is the section to which stubs in the group will be attached. */ |
| 2824 | asection *link_sec; |
| 2825 | /* The stub section. */ |
| 2826 | asection *stub_sec; |
| 2827 | /* Along with elf_gp, specifies the TOC pointer used in this group. */ |
| 2828 | bfd_vma toc_off; |
| 2829 | } *stub_group; |
| 2830 | |
| 2831 | /* Support for multiple toc sections. */ |
| 2832 | unsigned int no_multi_toc; |
| 2833 | unsigned int multi_toc_needed; |
| 2834 | |
| 2835 | /* Temp used when calculating TOC pointers. */ |
| 2836 | bfd_vma toc_curr; |
| 2837 | |
| 2838 | /* Highest input section id. */ |
| 2839 | int top_id; |
| 2840 | |
| 2841 | /* Highest output section index. */ |
| 2842 | int top_index; |
| 2843 | |
| 2844 | /* List of input sections for each output section. */ |
| 2845 | asection **input_list; |
| 2846 | |
| 2847 | /* Short-cuts to get to dynamic linker sections. */ |
| 2848 | asection *got; |
| 2849 | asection *plt; |
| 2850 | asection *relplt; |
| 2851 | asection *dynbss; |
| 2852 | asection *relbss; |
| 2853 | asection *glink; |
| 2854 | asection *sfpr; |
| 2855 | asection *brlt; |
| 2856 | asection *relbrlt; |
| 2857 | |
| 2858 | /* Shortcut to .__tls_get_addr. */ |
| 2859 | struct elf_link_hash_entry *tls_get_addr; |
| 2860 | |
| 2861 | /* Statistics. */ |
| 2862 | unsigned long stub_count[ppc_stub_plt_call]; |
| 2863 | |
| 2864 | /* Set if we should emit symbols for stubs. */ |
| 2865 | unsigned int emit_stub_syms; |
| 2866 | |
| 2867 | /* Set on error. */ |
| 2868 | unsigned int stub_error; |
| 2869 | |
| 2870 | /* Flag set when small branches are detected. Used to |
| 2871 | select suitable defaults for the stub group size. */ |
| 2872 | unsigned int has_14bit_branch; |
| 2873 | |
| 2874 | /* Incremented every time we size stubs. */ |
| 2875 | unsigned int stub_iteration; |
| 2876 | |
| 2877 | /* Small local sym to section mapping cache. */ |
| 2878 | struct sym_sec_cache sym_sec; |
| 2879 | }; |
| 2880 | |
| 2881 | /* Get the ppc64 ELF linker hash table from a link_info structure. */ |
| 2882 | |
| 2883 | #define ppc_hash_table(p) \ |
| 2884 | ((struct ppc_link_hash_table *) ((p)->hash)) |
| 2885 | |
| 2886 | #define ppc_stub_hash_lookup(table, string, create, copy) \ |
| 2887 | ((struct ppc_stub_hash_entry *) \ |
| 2888 | bfd_hash_lookup ((table), (string), (create), (copy))) |
| 2889 | |
| 2890 | #define ppc_branch_hash_lookup(table, string, create, copy) \ |
| 2891 | ((struct ppc_branch_hash_entry *) \ |
| 2892 | bfd_hash_lookup ((table), (string), (create), (copy))) |
| 2893 | |
| 2894 | /* Create an entry in the stub hash table. */ |
| 2895 | |
| 2896 | static struct bfd_hash_entry * |
| 2897 | stub_hash_newfunc (struct bfd_hash_entry *entry, |
| 2898 | struct bfd_hash_table *table, |
| 2899 | const char *string) |
| 2900 | { |
| 2901 | /* Allocate the structure if it has not already been allocated by a |
| 2902 | subclass. */ |
| 2903 | if (entry == NULL) |
| 2904 | { |
| 2905 | entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry)); |
| 2906 | if (entry == NULL) |
| 2907 | return entry; |
| 2908 | } |
| 2909 | |
| 2910 | /* Call the allocation method of the superclass. */ |
| 2911 | entry = bfd_hash_newfunc (entry, table, string); |
| 2912 | if (entry != NULL) |
| 2913 | { |
| 2914 | struct ppc_stub_hash_entry *eh; |
| 2915 | |
| 2916 | /* Initialize the local fields. */ |
| 2917 | eh = (struct ppc_stub_hash_entry *) entry; |
| 2918 | eh->stub_type = ppc_stub_none; |
| 2919 | eh->stub_sec = NULL; |
| 2920 | eh->stub_offset = 0; |
| 2921 | eh->target_value = 0; |
| 2922 | eh->target_section = NULL; |
| 2923 | eh->h = NULL; |
| 2924 | eh->id_sec = NULL; |
| 2925 | } |
| 2926 | |
| 2927 | return entry; |
| 2928 | } |
| 2929 | |
| 2930 | /* Create an entry in the branch hash table. */ |
| 2931 | |
| 2932 | static struct bfd_hash_entry * |
| 2933 | branch_hash_newfunc (struct bfd_hash_entry *entry, |
| 2934 | struct bfd_hash_table *table, |
| 2935 | const char *string) |
| 2936 | { |
| 2937 | /* Allocate the structure if it has not already been allocated by a |
| 2938 | subclass. */ |
| 2939 | if (entry == NULL) |
| 2940 | { |
| 2941 | entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry)); |
| 2942 | if (entry == NULL) |
| 2943 | return entry; |
| 2944 | } |
| 2945 | |
| 2946 | /* Call the allocation method of the superclass. */ |
| 2947 | entry = bfd_hash_newfunc (entry, table, string); |
| 2948 | if (entry != NULL) |
| 2949 | { |
| 2950 | struct ppc_branch_hash_entry *eh; |
| 2951 | |
| 2952 | /* Initialize the local fields. */ |
| 2953 | eh = (struct ppc_branch_hash_entry *) entry; |
| 2954 | eh->offset = 0; |
| 2955 | eh->iter = 0; |
| 2956 | } |
| 2957 | |
| 2958 | return entry; |
| 2959 | } |
| 2960 | |
| 2961 | /* Create an entry in a ppc64 ELF linker hash table. */ |
| 2962 | |
| 2963 | static struct bfd_hash_entry * |
| 2964 | link_hash_newfunc (struct bfd_hash_entry *entry, |
| 2965 | struct bfd_hash_table *table, |
| 2966 | const char *string) |
| 2967 | { |
| 2968 | /* Allocate the structure if it has not already been allocated by a |
| 2969 | subclass. */ |
| 2970 | if (entry == NULL) |
| 2971 | { |
| 2972 | entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry)); |
| 2973 | if (entry == NULL) |
| 2974 | return entry; |
| 2975 | } |
| 2976 | |
| 2977 | /* Call the allocation method of the superclass. */ |
| 2978 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); |
| 2979 | if (entry != NULL) |
| 2980 | { |
| 2981 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry; |
| 2982 | |
| 2983 | eh->stub_cache = NULL; |
| 2984 | eh->dyn_relocs = NULL; |
| 2985 | eh->oh = NULL; |
| 2986 | eh->is_func = 0; |
| 2987 | eh->is_func_descriptor = 0; |
| 2988 | eh->adjust_done = 0; |
| 2989 | eh->tls_mask = 0; |
| 2990 | } |
| 2991 | |
| 2992 | return entry; |
| 2993 | } |
| 2994 | |
| 2995 | /* Create a ppc64 ELF linker hash table. */ |
| 2996 | |
| 2997 | static struct bfd_link_hash_table * |
| 2998 | ppc64_elf_link_hash_table_create (bfd *abfd) |
| 2999 | { |
| 3000 | struct ppc_link_hash_table *htab; |
| 3001 | bfd_size_type amt = sizeof (struct ppc_link_hash_table); |
| 3002 | |
| 3003 | htab = bfd_zmalloc (amt); |
| 3004 | if (htab == NULL) |
| 3005 | return NULL; |
| 3006 | |
| 3007 | if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc)) |
| 3008 | { |
| 3009 | free (htab); |
| 3010 | return NULL; |
| 3011 | } |
| 3012 | |
| 3013 | /* Init the stub hash table too. */ |
| 3014 | if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc)) |
| 3015 | return NULL; |
| 3016 | |
| 3017 | /* And the branch hash table. */ |
| 3018 | if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc)) |
| 3019 | return NULL; |
| 3020 | |
| 3021 | /* Initializing two fields of the union is just cosmetic. We really |
| 3022 | only care about glist, but when compiled on a 32-bit host the |
| 3023 | bfd_vma fields are larger. Setting the bfd_vma to zero makes |
| 3024 | debugger inspection of these fields look nicer. */ |
| 3025 | htab->elf.init_refcount.refcount = 0; |
| 3026 | htab->elf.init_refcount.glist = NULL; |
| 3027 | htab->elf.init_offset.offset = 0; |
| 3028 | htab->elf.init_offset.glist = NULL; |
| 3029 | |
| 3030 | return &htab->elf.root; |
| 3031 | } |
| 3032 | |
| 3033 | /* Free the derived linker hash table. */ |
| 3034 | |
| 3035 | static void |
| 3036 | ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash) |
| 3037 | { |
| 3038 | struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash; |
| 3039 | |
| 3040 | bfd_hash_table_free (&ret->stub_hash_table); |
| 3041 | bfd_hash_table_free (&ret->branch_hash_table); |
| 3042 | _bfd_generic_link_hash_table_free (hash); |
| 3043 | } |
| 3044 | |
| 3045 | /* Satisfy the ELF linker by filling in some fields in our fake bfd. */ |
| 3046 | |
| 3047 | void |
| 3048 | ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info) |
| 3049 | { |
| 3050 | struct ppc_link_hash_table *htab; |
| 3051 | |
| 3052 | elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64; |
| 3053 | |
| 3054 | /* Always hook our dynamic sections into the first bfd, which is the |
| 3055 | linker created stub bfd. This ensures that the GOT header is at |
| 3056 | the start of the output TOC section. */ |
| 3057 | htab = ppc_hash_table (info); |
| 3058 | htab->stub_bfd = abfd; |
| 3059 | htab->elf.dynobj = abfd; |
| 3060 | } |
| 3061 | |
| 3062 | /* Build a name for an entry in the stub hash table. */ |
| 3063 | |
| 3064 | static char * |
| 3065 | ppc_stub_name (const asection *input_section, |
| 3066 | const asection *sym_sec, |
| 3067 | const struct ppc_link_hash_entry *h, |
| 3068 | const Elf_Internal_Rela *rel) |
| 3069 | { |
| 3070 | char *stub_name; |
| 3071 | bfd_size_type len; |
| 3072 | |
| 3073 | /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31 |
| 3074 | offsets from a sym as a branch target? In fact, we could |
| 3075 | probably assume the addend is always zero. */ |
| 3076 | BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend); |
| 3077 | |
| 3078 | if (h) |
| 3079 | { |
| 3080 | len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1; |
| 3081 | stub_name = bfd_malloc (len); |
| 3082 | if (stub_name != NULL) |
| 3083 | { |
| 3084 | sprintf (stub_name, "%08x.%s+%x", |
| 3085 | input_section->id & 0xffffffff, |
| 3086 | h->elf.root.root.string, |
| 3087 | (int) rel->r_addend & 0xffffffff); |
| 3088 | } |
| 3089 | } |
| 3090 | else |
| 3091 | { |
| 3092 | len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1; |
| 3093 | stub_name = bfd_malloc (len); |
| 3094 | if (stub_name != NULL) |
| 3095 | { |
| 3096 | sprintf (stub_name, "%08x.%x:%x+%x", |
| 3097 | input_section->id & 0xffffffff, |
| 3098 | sym_sec->id & 0xffffffff, |
| 3099 | (int) ELF64_R_SYM (rel->r_info) & 0xffffffff, |
| 3100 | (int) rel->r_addend & 0xffffffff); |
| 3101 | } |
| 3102 | } |
| 3103 | return stub_name; |
| 3104 | } |
| 3105 | |
| 3106 | /* Look up an entry in the stub hash. Stub entries are cached because |
| 3107 | creating the stub name takes a bit of time. */ |
| 3108 | |
| 3109 | static struct ppc_stub_hash_entry * |
| 3110 | ppc_get_stub_entry (const asection *input_section, |
| 3111 | const asection *sym_sec, |
| 3112 | struct elf_link_hash_entry *hash, |
| 3113 | const Elf_Internal_Rela *rel, |
| 3114 | struct ppc_link_hash_table *htab) |
| 3115 | { |
| 3116 | struct ppc_stub_hash_entry *stub_entry; |
| 3117 | struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash; |
| 3118 | const asection *id_sec; |
| 3119 | |
| 3120 | /* If this input section is part of a group of sections sharing one |
| 3121 | stub section, then use the id of the first section in the group. |
| 3122 | Stub names need to include a section id, as there may well be |
| 3123 | more than one stub used to reach say, printf, and we need to |
| 3124 | distinguish between them. */ |
| 3125 | id_sec = htab->stub_group[input_section->id].link_sec; |
| 3126 | |
| 3127 | if (h != NULL && h->stub_cache != NULL |
| 3128 | && h->stub_cache->h == h |
| 3129 | && h->stub_cache->id_sec == id_sec) |
| 3130 | { |
| 3131 | stub_entry = h->stub_cache; |
| 3132 | } |
| 3133 | else |
| 3134 | { |
| 3135 | char *stub_name; |
| 3136 | |
| 3137 | stub_name = ppc_stub_name (id_sec, sym_sec, h, rel); |
| 3138 | if (stub_name == NULL) |
| 3139 | return NULL; |
| 3140 | |
| 3141 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, |
| 3142 | stub_name, FALSE, FALSE); |
| 3143 | if (h != NULL) |
| 3144 | h->stub_cache = stub_entry; |
| 3145 | |
| 3146 | free (stub_name); |
| 3147 | } |
| 3148 | |
| 3149 | return stub_entry; |
| 3150 | } |
| 3151 | |
| 3152 | /* Add a new stub entry to the stub hash. Not all fields of the new |
| 3153 | stub entry are initialised. */ |
| 3154 | |
| 3155 | static struct ppc_stub_hash_entry * |
| 3156 | ppc_add_stub (const char *stub_name, |
| 3157 | asection *section, |
| 3158 | struct ppc_link_hash_table *htab) |
| 3159 | { |
| 3160 | asection *link_sec; |
| 3161 | asection *stub_sec; |
| 3162 | struct ppc_stub_hash_entry *stub_entry; |
| 3163 | |
| 3164 | link_sec = htab->stub_group[section->id].link_sec; |
| 3165 | stub_sec = htab->stub_group[section->id].stub_sec; |
| 3166 | if (stub_sec == NULL) |
| 3167 | { |
| 3168 | stub_sec = htab->stub_group[link_sec->id].stub_sec; |
| 3169 | if (stub_sec == NULL) |
| 3170 | { |
| 3171 | size_t namelen; |
| 3172 | bfd_size_type len; |
| 3173 | char *s_name; |
| 3174 | |
| 3175 | namelen = strlen (link_sec->name); |
| 3176 | len = namelen + sizeof (STUB_SUFFIX); |
| 3177 | s_name = bfd_alloc (htab->stub_bfd, len); |
| 3178 | if (s_name == NULL) |
| 3179 | return NULL; |
| 3180 | |
| 3181 | memcpy (s_name, link_sec->name, namelen); |
| 3182 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); |
| 3183 | stub_sec = (*htab->add_stub_section) (s_name, link_sec); |
| 3184 | if (stub_sec == NULL) |
| 3185 | return NULL; |
| 3186 | htab->stub_group[link_sec->id].stub_sec = stub_sec; |
| 3187 | } |
| 3188 | htab->stub_group[section->id].stub_sec = stub_sec; |
| 3189 | } |
| 3190 | |
| 3191 | /* Enter this entry into the linker stub hash table. */ |
| 3192 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name, |
| 3193 | TRUE, FALSE); |
| 3194 | if (stub_entry == NULL) |
| 3195 | { |
| 3196 | (*_bfd_error_handler) (_("%s: cannot create stub entry %s"), |
| 3197 | bfd_archive_filename (section->owner), |
| 3198 | stub_name); |
| 3199 | return NULL; |
| 3200 | } |
| 3201 | |
| 3202 | stub_entry->stub_sec = stub_sec; |
| 3203 | stub_entry->stub_offset = 0; |
| 3204 | stub_entry->id_sec = link_sec; |
| 3205 | return stub_entry; |
| 3206 | } |
| 3207 | |
| 3208 | /* Create sections for linker generated code. */ |
| 3209 | |
| 3210 | static bfd_boolean |
| 3211 | create_linkage_sections (bfd *dynobj, struct bfd_link_info *info) |
| 3212 | { |
| 3213 | struct ppc_link_hash_table *htab; |
| 3214 | flagword flags; |
| 3215 | |
| 3216 | htab = ppc_hash_table (info); |
| 3217 | |
| 3218 | /* Create .sfpr for code to save and restore fp regs. */ |
| 3219 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY |
| 3220 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); |
| 3221 | htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr"); |
| 3222 | if (htab->sfpr == NULL |
| 3223 | || ! bfd_set_section_flags (dynobj, htab->sfpr, flags) |
| 3224 | || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2)) |
| 3225 | return FALSE; |
| 3226 | |
| 3227 | /* Create .glink for lazy dynamic linking support. */ |
| 3228 | htab->glink = bfd_make_section_anyway (dynobj, ".glink"); |
| 3229 | if (htab->glink == NULL |
| 3230 | || ! bfd_set_section_flags (dynobj, htab->glink, flags) |
| 3231 | || ! bfd_set_section_alignment (dynobj, htab->glink, 2)) |
| 3232 | return FALSE; |
| 3233 | |
| 3234 | /* Create .branch_lt for plt_branch stubs. */ |
| 3235 | flags = (SEC_ALLOC | SEC_LOAD |
| 3236 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); |
| 3237 | htab->brlt = bfd_make_section_anyway (dynobj, ".branch_lt"); |
| 3238 | if (htab->brlt == NULL |
| 3239 | || ! bfd_set_section_flags (dynobj, htab->brlt, flags) |
| 3240 | || ! bfd_set_section_alignment (dynobj, htab->brlt, 3)) |
| 3241 | return FALSE; |
| 3242 | |
| 3243 | if (info->shared) |
| 3244 | { |
| 3245 | flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY |
| 3246 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); |
| 3247 | htab->relbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt"); |
| 3248 | if (!htab->relbrlt |
| 3249 | || ! bfd_set_section_flags (dynobj, htab->relbrlt, flags) |
| 3250 | || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3)) |
| 3251 | return FALSE; |
| 3252 | } |
| 3253 | return TRUE; |
| 3254 | } |
| 3255 | |
| 3256 | /* Create .got and .rela.got sections in ABFD, and .got in dynobj if |
| 3257 | not already done. */ |
| 3258 | |
| 3259 | static bfd_boolean |
| 3260 | create_got_section (bfd *abfd, struct bfd_link_info *info) |
| 3261 | { |
| 3262 | asection *got, *relgot; |
| 3263 | flagword flags; |
| 3264 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
| 3265 | |
| 3266 | if (!htab->got) |
| 3267 | { |
| 3268 | if (! _bfd_elf_create_got_section (htab->elf.dynobj, info)) |
| 3269 | return FALSE; |
| 3270 | |
| 3271 | htab->got = bfd_get_section_by_name (htab->elf.dynobj, ".got"); |
| 3272 | if (!htab->got) |
| 3273 | abort (); |
| 3274 | } |
| 3275 | |
| 3276 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
| 3277 | | SEC_LINKER_CREATED); |
| 3278 | |
| 3279 | got = bfd_make_section (abfd, ".got"); |
| 3280 | if (!got |
| 3281 | || !bfd_set_section_flags (abfd, got, flags) |
| 3282 | || !bfd_set_section_alignment (abfd, got, 3)) |
| 3283 | return FALSE; |
| 3284 | |
| 3285 | relgot = bfd_make_section (abfd, ".rela.got"); |
| 3286 | if (!relgot |
| 3287 | || ! bfd_set_section_flags (abfd, relgot, flags | SEC_READONLY) |
| 3288 | || ! bfd_set_section_alignment (abfd, relgot, 3)) |
| 3289 | return FALSE; |
| 3290 | |
| 3291 | ppc64_elf_tdata (abfd)->got = got; |
| 3292 | ppc64_elf_tdata (abfd)->relgot = relgot; |
| 3293 | return TRUE; |
| 3294 | } |
| 3295 | |
| 3296 | /* Create the dynamic sections, and set up shortcuts. */ |
| 3297 | |
| 3298 | static bfd_boolean |
| 3299 | ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
| 3300 | { |
| 3301 | struct ppc_link_hash_table *htab; |
| 3302 | |
| 3303 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
| 3304 | return FALSE; |
| 3305 | |
| 3306 | htab = ppc_hash_table (info); |
| 3307 | if (!htab->got) |
| 3308 | htab->got = bfd_get_section_by_name (dynobj, ".got"); |
| 3309 | htab->plt = bfd_get_section_by_name (dynobj, ".plt"); |
| 3310 | htab->relplt = bfd_get_section_by_name (dynobj, ".rela.plt"); |
| 3311 | htab->dynbss = bfd_get_section_by_name (dynobj, ".dynbss"); |
| 3312 | if (!info->shared) |
| 3313 | htab->relbss = bfd_get_section_by_name (dynobj, ".rela.bss"); |
| 3314 | |
| 3315 | if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss |
| 3316 | || (!info->shared && !htab->relbss)) |
| 3317 | abort (); |
| 3318 | |
| 3319 | return TRUE; |
| 3320 | } |
| 3321 | |
| 3322 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
| 3323 | |
| 3324 | static void |
| 3325 | ppc64_elf_copy_indirect_symbol |
| 3326 | (const struct elf_backend_data *bed ATTRIBUTE_UNUSED, |
| 3327 | struct elf_link_hash_entry *dir, |
| 3328 | struct elf_link_hash_entry *ind) |
| 3329 | { |
| 3330 | struct ppc_link_hash_entry *edir, *eind; |
| 3331 | flagword mask; |
| 3332 | |
| 3333 | edir = (struct ppc_link_hash_entry *) dir; |
| 3334 | eind = (struct ppc_link_hash_entry *) ind; |
| 3335 | |
| 3336 | /* Copy over any dynamic relocs we may have on the indirect sym. */ |
| 3337 | if (eind->dyn_relocs != NULL) |
| 3338 | { |
| 3339 | if (edir->dyn_relocs != NULL) |
| 3340 | { |
| 3341 | struct ppc_dyn_relocs **pp; |
| 3342 | struct ppc_dyn_relocs *p; |
| 3343 | |
| 3344 | if (eind->elf.root.type == bfd_link_hash_indirect) |
| 3345 | abort (); |
| 3346 | |
| 3347 | /* Add reloc counts against the weak sym to the strong sym |
| 3348 | list. Merge any entries against the same section. */ |
| 3349 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) |
| 3350 | { |
| 3351 | struct ppc_dyn_relocs *q; |
| 3352 | |
| 3353 | for (q = edir->dyn_relocs; q != NULL; q = q->next) |
| 3354 | if (q->sec == p->sec) |
| 3355 | { |
| 3356 | q->pc_count += p->pc_count; |
| 3357 | q->count += p->count; |
| 3358 | *pp = p->next; |
| 3359 | break; |
| 3360 | } |
| 3361 | if (q == NULL) |
| 3362 | pp = &p->next; |
| 3363 | } |
| 3364 | *pp = edir->dyn_relocs; |
| 3365 | } |
| 3366 | |
| 3367 | edir->dyn_relocs = eind->dyn_relocs; |
| 3368 | eind->dyn_relocs = NULL; |
| 3369 | } |
| 3370 | |
| 3371 | edir->is_func |= eind->is_func; |
| 3372 | edir->is_func_descriptor |= eind->is_func_descriptor; |
| 3373 | edir->tls_mask |= eind->tls_mask; |
| 3374 | |
| 3375 | mask = (ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR |
| 3376 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK | ELF_LINK_NON_GOT_REF |
| 3377 | | ELF_LINK_HASH_NEEDS_PLT); |
| 3378 | /* If called to transfer flags for a weakdef during processing |
| 3379 | of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF. |
| 3380 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ |
| 3381 | if (ELIMINATE_COPY_RELOCS |
| 3382 | && eind->elf.root.type != bfd_link_hash_indirect |
| 3383 | && (edir->elf.elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0) |
| 3384 | mask &= ~ELF_LINK_NON_GOT_REF; |
| 3385 | |
| 3386 | edir->elf.elf_link_hash_flags |= eind->elf.elf_link_hash_flags & mask; |
| 3387 | |
| 3388 | /* If we were called to copy over info for a weak sym, that's all. */ |
| 3389 | if (eind->elf.root.type != bfd_link_hash_indirect) |
| 3390 | return; |
| 3391 | |
| 3392 | /* Copy over got entries that we may have already seen to the |
| 3393 | symbol which just became indirect. */ |
| 3394 | if (eind->elf.got.glist != NULL) |
| 3395 | { |
| 3396 | if (edir->elf.got.glist != NULL) |
| 3397 | { |
| 3398 | struct got_entry **entp; |
| 3399 | struct got_entry *ent; |
| 3400 | |
| 3401 | for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; ) |
| 3402 | { |
| 3403 | struct got_entry *dent; |
| 3404 | |
| 3405 | for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next) |
| 3406 | if (dent->addend == ent->addend |
| 3407 | && dent->owner == ent->owner |
| 3408 | && dent->tls_type == ent->tls_type) |
| 3409 | { |
| 3410 | dent->got.refcount += ent->got.refcount; |
| 3411 | *entp = ent->next; |
| 3412 | break; |
| 3413 | } |
| 3414 | if (dent == NULL) |
| 3415 | entp = &ent->next; |
| 3416 | } |
| 3417 | *entp = edir->elf.got.glist; |
| 3418 | } |
| 3419 | |
| 3420 | edir->elf.got.glist = eind->elf.got.glist; |
| 3421 | eind->elf.got.glist = NULL; |
| 3422 | } |
| 3423 | |
| 3424 | /* And plt entries. */ |
| 3425 | if (eind->elf.plt.plist != NULL) |
| 3426 | { |
| 3427 | if (edir->elf.plt.plist != NULL) |
| 3428 | { |
| 3429 | struct plt_entry **entp; |
| 3430 | struct plt_entry *ent; |
| 3431 | |
| 3432 | for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; ) |
| 3433 | { |
| 3434 | struct plt_entry *dent; |
| 3435 | |
| 3436 | for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next) |
| 3437 | if (dent->addend == ent->addend) |
| 3438 | { |
| 3439 | dent->plt.refcount += ent->plt.refcount; |
| 3440 | *entp = ent->next; |
| 3441 | break; |
| 3442 | } |
| 3443 | if (dent == NULL) |
| 3444 | entp = &ent->next; |
| 3445 | } |
| 3446 | *entp = edir->elf.plt.plist; |
| 3447 | } |
| 3448 | |
| 3449 | edir->elf.plt.plist = eind->elf.plt.plist; |
| 3450 | eind->elf.plt.plist = NULL; |
| 3451 | } |
| 3452 | |
| 3453 | if (edir->elf.dynindx == -1) |
| 3454 | { |
| 3455 | edir->elf.dynindx = eind->elf.dynindx; |
| 3456 | edir->elf.dynstr_index = eind->elf.dynstr_index; |
| 3457 | eind->elf.dynindx = -1; |
| 3458 | eind->elf.dynstr_index = 0; |
| 3459 | } |
| 3460 | else |
| 3461 | BFD_ASSERT (eind->elf.dynindx == -1); |
| 3462 | } |
| 3463 | |
| 3464 | /* Hack symbols defined in .opd sections to be function type. */ |
| 3465 | |
| 3466 | static bfd_boolean |
| 3467 | ppc64_elf_add_symbol_hook (bfd *ibfd ATTRIBUTE_UNUSED, |
| 3468 | struct bfd_link_info *info ATTRIBUTE_UNUSED, |
| 3469 | Elf_Internal_Sym *isym, |
| 3470 | const char **name ATTRIBUTE_UNUSED, |
| 3471 | flagword *flags ATTRIBUTE_UNUSED, |
| 3472 | asection **sec, |
| 3473 | bfd_vma *value ATTRIBUTE_UNUSED) |
| 3474 | { |
| 3475 | if (strcmp (bfd_get_section_name (ibfd, *sec), ".opd") == 0) |
| 3476 | isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC); |
| 3477 | return TRUE; |
| 3478 | } |
| 3479 | |
| 3480 | static bfd_boolean |
| 3481 | update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr, |
| 3482 | unsigned long r_symndx, bfd_vma r_addend, int tls_type) |
| 3483 | { |
| 3484 | struct got_entry **local_got_ents = elf_local_got_ents (abfd); |
| 3485 | char *local_got_tls_masks; |
| 3486 | |
| 3487 | if (local_got_ents == NULL) |
| 3488 | { |
| 3489 | bfd_size_type size = symtab_hdr->sh_info; |
| 3490 | |
| 3491 | size *= sizeof (*local_got_ents) + sizeof (*local_got_tls_masks); |
| 3492 | local_got_ents = bfd_zalloc (abfd, size); |
| 3493 | if (local_got_ents == NULL) |
| 3494 | return FALSE; |
| 3495 | elf_local_got_ents (abfd) = local_got_ents; |
| 3496 | } |
| 3497 | |
| 3498 | if ((tls_type & TLS_EXPLICIT) == 0) |
| 3499 | { |
| 3500 | struct got_entry *ent; |
| 3501 | |
| 3502 | for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next) |
| 3503 | if (ent->addend == r_addend |
| 3504 | && ent->owner == abfd |
| 3505 | && ent->tls_type == tls_type) |
| 3506 | break; |
| 3507 | if (ent == NULL) |
| 3508 | { |
| 3509 | bfd_size_type amt = sizeof (*ent); |
| 3510 | ent = bfd_alloc (abfd, amt); |
| 3511 | if (ent == NULL) |
| 3512 | return FALSE; |
| 3513 | ent->next = local_got_ents[r_symndx]; |
| 3514 | ent->addend = r_addend; |
| 3515 | ent->owner = abfd; |
| 3516 | ent->tls_type = tls_type; |
| 3517 | ent->got.refcount = 0; |
| 3518 | local_got_ents[r_symndx] = ent; |
| 3519 | } |
| 3520 | ent->got.refcount += 1; |
| 3521 | } |
| 3522 | |
| 3523 | local_got_tls_masks = (char *) (local_got_ents + symtab_hdr->sh_info); |
| 3524 | local_got_tls_masks[r_symndx] |= tls_type; |
| 3525 | return TRUE; |
| 3526 | } |
| 3527 | |
| 3528 | static bfd_boolean |
| 3529 | update_plt_info (bfd *abfd, struct ppc_link_hash_entry *eh, bfd_vma addend) |
| 3530 | { |
| 3531 | struct plt_entry *ent; |
| 3532 | |
| 3533 | for (ent = eh->elf.plt.plist; ent != NULL; ent = ent->next) |
| 3534 | if (ent->addend == addend) |
| 3535 | break; |
| 3536 | if (ent == NULL) |
| 3537 | { |
| 3538 | bfd_size_type amt = sizeof (*ent); |
| 3539 | ent = bfd_alloc (abfd, amt); |
| 3540 | if (ent == NULL) |
| 3541 | return FALSE; |
| 3542 | ent->next = eh->elf.plt.plist; |
| 3543 | ent->addend = addend; |
| 3544 | ent->plt.refcount = 0; |
| 3545 | eh->elf.plt.plist = ent; |
| 3546 | } |
| 3547 | ent->plt.refcount += 1; |
| 3548 | eh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
| 3549 | eh->is_func = 1; |
| 3550 | return TRUE; |
| 3551 | } |
| 3552 | |
| 3553 | /* Find the function descriptor hash entry from the given function code |
| 3554 | hash entry FH. Link the entries via their OH fields. */ |
| 3555 | static struct ppc_link_hash_entry * |
| 3556 | get_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab) |
| 3557 | { |
| 3558 | struct ppc_link_hash_entry *fdh = fh->oh; |
| 3559 | |
| 3560 | if (fdh == NULL) |
| 3561 | { |
| 3562 | const char *fd_name = fh->elf.root.root.string + 1; |
| 3563 | |
| 3564 | fdh = (struct ppc_link_hash_entry *) |
| 3565 | elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE); |
| 3566 | if (fdh != NULL) |
| 3567 | { |
| 3568 | fdh->is_func_descriptor = 1; |
| 3569 | fdh->oh = fh; |
| 3570 | fh->is_func = 1; |
| 3571 | fh->oh = fdh; |
| 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | return fdh; |
| 3576 | } |
| 3577 | |
| 3578 | /* Look through the relocs for a section during the first phase, and |
| 3579 | calculate needed space in the global offset table, procedure |
| 3580 | linkage table, and dynamic reloc sections. */ |
| 3581 | |
| 3582 | static bfd_boolean |
| 3583 | ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, |
| 3584 | asection *sec, const Elf_Internal_Rela *relocs) |
| 3585 | { |
| 3586 | struct ppc_link_hash_table *htab; |
| 3587 | Elf_Internal_Shdr *symtab_hdr; |
| 3588 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; |
| 3589 | const Elf_Internal_Rela *rel; |
| 3590 | const Elf_Internal_Rela *rel_end; |
| 3591 | asection *sreloc; |
| 3592 | asection **opd_sym_map; |
| 3593 | |
| 3594 | if (info->relocatable) |
| 3595 | return TRUE; |
| 3596 | |
| 3597 | /* Don't do anything special with non-loaded, non-alloced sections. |
| 3598 | In particular, any relocs in such sections should not affect GOT |
| 3599 | and PLT reference counting (ie. we don't allow them to create GOT |
| 3600 | or PLT entries), there's no possibility or desire to optimize TLS |
| 3601 | relocs, and there's not much point in propagating relocs to shared |
| 3602 | libs that the dynamic linker won't relocate. */ |
| 3603 | if ((sec->flags & SEC_ALLOC) == 0) |
| 3604 | return TRUE; |
| 3605 | |
| 3606 | htab = ppc_hash_table (info); |
| 3607 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 3608 | |
| 3609 | sym_hashes = elf_sym_hashes (abfd); |
| 3610 | sym_hashes_end = (sym_hashes |
| 3611 | + symtab_hdr->sh_size / sizeof (Elf64_External_Sym) |
| 3612 | - symtab_hdr->sh_info); |
| 3613 | |
| 3614 | sreloc = NULL; |
| 3615 | opd_sym_map = NULL; |
| 3616 | if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0) |
| 3617 | { |
| 3618 | /* Garbage collection needs some extra help with .opd sections. |
| 3619 | We don't want to necessarily keep everything referenced by |
| 3620 | relocs in .opd, as that would keep all functions. Instead, |
| 3621 | if we reference an .opd symbol (a function descriptor), we |
| 3622 | want to keep the function code symbol's section. This is |
| 3623 | easy for global symbols, but for local syms we need to keep |
| 3624 | information about the associated function section. Later, if |
| 3625 | edit_opd deletes entries, we'll use this array to adjust |
| 3626 | local syms in .opd. */ |
| 3627 | union opd_info { |
| 3628 | asection *func_section; |
| 3629 | long entry_adjust; |
| 3630 | }; |
| 3631 | bfd_size_type amt; |
| 3632 | |
| 3633 | amt = sec->size * sizeof (union opd_info) / 24; |
| 3634 | opd_sym_map = bfd_zalloc (abfd, amt); |
| 3635 | if (opd_sym_map == NULL) |
| 3636 | return FALSE; |
| 3637 | ppc64_elf_section_data (sec)->opd.func_sec = opd_sym_map; |
| 3638 | } |
| 3639 | |
| 3640 | if (htab->sfpr == NULL |
| 3641 | && !create_linkage_sections (htab->elf.dynobj, info)) |
| 3642 | return FALSE; |
| 3643 | |
| 3644 | rel_end = relocs + sec->reloc_count; |
| 3645 | for (rel = relocs; rel < rel_end; rel++) |
| 3646 | { |
| 3647 | unsigned long r_symndx; |
| 3648 | struct elf_link_hash_entry *h; |
| 3649 | enum elf_ppc64_reloc_type r_type; |
| 3650 | int tls_type = 0; |
| 3651 | |
| 3652 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 3653 | if (r_symndx < symtab_hdr->sh_info) |
| 3654 | h = NULL; |
| 3655 | else |
| 3656 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 3657 | |
| 3658 | r_type = ELF64_R_TYPE (rel->r_info); |
| 3659 | switch (r_type) |
| 3660 | { |
| 3661 | case R_PPC64_GOT_TLSLD16: |
| 3662 | case R_PPC64_GOT_TLSLD16_LO: |
| 3663 | case R_PPC64_GOT_TLSLD16_HI: |
| 3664 | case R_PPC64_GOT_TLSLD16_HA: |
| 3665 | ppc64_tlsld_got (abfd)->refcount += 1; |
| 3666 | tls_type = TLS_TLS | TLS_LD; |
| 3667 | goto dogottls; |
| 3668 | |
| 3669 | case R_PPC64_GOT_TLSGD16: |
| 3670 | case R_PPC64_GOT_TLSGD16_LO: |
| 3671 | case R_PPC64_GOT_TLSGD16_HI: |
| 3672 | case R_PPC64_GOT_TLSGD16_HA: |
| 3673 | tls_type = TLS_TLS | TLS_GD; |
| 3674 | goto dogottls; |
| 3675 | |
| 3676 | case R_PPC64_GOT_TPREL16_DS: |
| 3677 | case R_PPC64_GOT_TPREL16_LO_DS: |
| 3678 | case R_PPC64_GOT_TPREL16_HI: |
| 3679 | case R_PPC64_GOT_TPREL16_HA: |
| 3680 | if (info->shared) |
| 3681 | info->flags |= DF_STATIC_TLS; |
| 3682 | tls_type = TLS_TLS | TLS_TPREL; |
| 3683 | goto dogottls; |
| 3684 | |
| 3685 | case R_PPC64_GOT_DTPREL16_DS: |
| 3686 | case R_PPC64_GOT_DTPREL16_LO_DS: |
| 3687 | case R_PPC64_GOT_DTPREL16_HI: |
| 3688 | case R_PPC64_GOT_DTPREL16_HA: |
| 3689 | tls_type = TLS_TLS | TLS_DTPREL; |
| 3690 | dogottls: |
| 3691 | sec->has_tls_reloc = 1; |
| 3692 | /* Fall thru */ |
| 3693 | |
| 3694 | case R_PPC64_GOT16: |
| 3695 | case R_PPC64_GOT16_DS: |
| 3696 | case R_PPC64_GOT16_HA: |
| 3697 | case R_PPC64_GOT16_HI: |
| 3698 | case R_PPC64_GOT16_LO: |
| 3699 | case R_PPC64_GOT16_LO_DS: |
| 3700 | /* This symbol requires a global offset table entry. */ |
| 3701 | sec->has_gp_reloc = 1; |
| 3702 | if (ppc64_elf_tdata (abfd)->got == NULL |
| 3703 | && !create_got_section (abfd, info)) |
| 3704 | return FALSE; |
| 3705 | |
| 3706 | if (h != NULL) |
| 3707 | { |
| 3708 | struct ppc_link_hash_entry *eh; |
| 3709 | struct got_entry *ent; |
| 3710 | |
| 3711 | eh = (struct ppc_link_hash_entry *) h; |
| 3712 | for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next) |
| 3713 | if (ent->addend == rel->r_addend |
| 3714 | && ent->owner == abfd |
| 3715 | && ent->tls_type == tls_type) |
| 3716 | break; |
| 3717 | if (ent == NULL) |
| 3718 | { |
| 3719 | bfd_size_type amt = sizeof (*ent); |
| 3720 | ent = bfd_alloc (abfd, amt); |
| 3721 | if (ent == NULL) |
| 3722 | return FALSE; |
| 3723 | ent->next = eh->elf.got.glist; |
| 3724 | ent->addend = rel->r_addend; |
| 3725 | ent->owner = abfd; |
| 3726 | ent->tls_type = tls_type; |
| 3727 | ent->got.refcount = 0; |
| 3728 | eh->elf.got.glist = ent; |
| 3729 | } |
| 3730 | ent->got.refcount += 1; |
| 3731 | eh->tls_mask |= tls_type; |
| 3732 | } |
| 3733 | else |
| 3734 | /* This is a global offset table entry for a local symbol. */ |
| 3735 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, |
| 3736 | rel->r_addend, tls_type)) |
| 3737 | return FALSE; |
| 3738 | break; |
| 3739 | |
| 3740 | case R_PPC64_PLT16_HA: |
| 3741 | case R_PPC64_PLT16_HI: |
| 3742 | case R_PPC64_PLT16_LO: |
| 3743 | case R_PPC64_PLT32: |
| 3744 | case R_PPC64_PLT64: |
| 3745 | /* This symbol requires a procedure linkage table entry. We |
| 3746 | actually build the entry in adjust_dynamic_symbol, |
| 3747 | because this might be a case of linking PIC code without |
| 3748 | linking in any dynamic objects, in which case we don't |
| 3749 | need to generate a procedure linkage table after all. */ |
| 3750 | if (h == NULL) |
| 3751 | { |
| 3752 | /* It does not make sense to have a procedure linkage |
| 3753 | table entry for a local symbol. */ |
| 3754 | bfd_set_error (bfd_error_bad_value); |
| 3755 | return FALSE; |
| 3756 | } |
| 3757 | else |
| 3758 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, |
| 3759 | rel->r_addend)) |
| 3760 | return FALSE; |
| 3761 | break; |
| 3762 | |
| 3763 | /* The following relocations don't need to propagate the |
| 3764 | relocation if linking a shared object since they are |
| 3765 | section relative. */ |
| 3766 | case R_PPC64_SECTOFF: |
| 3767 | case R_PPC64_SECTOFF_LO: |
| 3768 | case R_PPC64_SECTOFF_HI: |
| 3769 | case R_PPC64_SECTOFF_HA: |
| 3770 | case R_PPC64_SECTOFF_DS: |
| 3771 | case R_PPC64_SECTOFF_LO_DS: |
| 3772 | case R_PPC64_DTPREL16: |
| 3773 | case R_PPC64_DTPREL16_LO: |
| 3774 | case R_PPC64_DTPREL16_HI: |
| 3775 | case R_PPC64_DTPREL16_HA: |
| 3776 | case R_PPC64_DTPREL16_DS: |
| 3777 | case R_PPC64_DTPREL16_LO_DS: |
| 3778 | case R_PPC64_DTPREL16_HIGHER: |
| 3779 | case R_PPC64_DTPREL16_HIGHERA: |
| 3780 | case R_PPC64_DTPREL16_HIGHEST: |
| 3781 | case R_PPC64_DTPREL16_HIGHESTA: |
| 3782 | break; |
| 3783 | |
| 3784 | /* Nor do these. */ |
| 3785 | case R_PPC64_TOC16: |
| 3786 | case R_PPC64_TOC16_LO: |
| 3787 | case R_PPC64_TOC16_HI: |
| 3788 | case R_PPC64_TOC16_HA: |
| 3789 | case R_PPC64_TOC16_DS: |
| 3790 | case R_PPC64_TOC16_LO_DS: |
| 3791 | sec->has_gp_reloc = 1; |
| 3792 | break; |
| 3793 | |
| 3794 | /* This relocation describes the C++ object vtable hierarchy. |
| 3795 | Reconstruct it for later use during GC. */ |
| 3796 | case R_PPC64_GNU_VTINHERIT: |
| 3797 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
| 3798 | return FALSE; |
| 3799 | break; |
| 3800 | |
| 3801 | /* This relocation describes which C++ vtable entries are actually |
| 3802 | used. Record for later use during GC. */ |
| 3803 | case R_PPC64_GNU_VTENTRY: |
| 3804 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
| 3805 | return FALSE; |
| 3806 | break; |
| 3807 | |
| 3808 | case R_PPC64_REL14: |
| 3809 | case R_PPC64_REL14_BRTAKEN: |
| 3810 | case R_PPC64_REL14_BRNTAKEN: |
| 3811 | htab->has_14bit_branch = 1; |
| 3812 | /* Fall through. */ |
| 3813 | |
| 3814 | case R_PPC64_REL24: |
| 3815 | if (h != NULL |
| 3816 | && h->root.root.string[0] == '.' |
| 3817 | && h->root.root.string[1] != 0) |
| 3818 | { |
| 3819 | /* We may need a .plt entry if the function this reloc |
| 3820 | refers to is in a shared lib. */ |
| 3821 | if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, |
| 3822 | rel->r_addend)) |
| 3823 | return FALSE; |
| 3824 | if (h == htab->tls_get_addr) |
| 3825 | sec->has_tls_reloc = 1; |
| 3826 | else if ((strncmp (h->root.root.string, ".__tls_get_addr", 15) |
| 3827 | == 0) |
| 3828 | && (h->root.root.string[15] == 0 |
| 3829 | || h->root.root.string[15] == '@')) |
| 3830 | { |
| 3831 | htab->tls_get_addr = h; |
| 3832 | sec->has_tls_reloc = 1; |
| 3833 | } |
| 3834 | } |
| 3835 | break; |
| 3836 | |
| 3837 | case R_PPC64_TPREL64: |
| 3838 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL; |
| 3839 | if (info->shared) |
| 3840 | info->flags |= DF_STATIC_TLS; |
| 3841 | goto dotlstoc; |
| 3842 | |
| 3843 | case R_PPC64_DTPMOD64: |
| 3844 | if (rel + 1 < rel_end |
| 3845 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) |
| 3846 | && rel[1].r_offset == rel->r_offset + 8) |
| 3847 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD; |
| 3848 | else |
| 3849 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD; |
| 3850 | goto dotlstoc; |
| 3851 | |
| 3852 | case R_PPC64_DTPREL64: |
| 3853 | tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL; |
| 3854 | if (rel != relocs |
| 3855 | && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64) |
| 3856 | && rel[-1].r_offset == rel->r_offset - 8) |
| 3857 | /* This is the second reloc of a dtpmod, dtprel pair. |
| 3858 | Don't mark with TLS_DTPREL. */ |
| 3859 | goto dodyn; |
| 3860 | |
| 3861 | dotlstoc: |
| 3862 | sec->has_tls_reloc = 1; |
| 3863 | if (h != NULL) |
| 3864 | { |
| 3865 | struct ppc_link_hash_entry *eh; |
| 3866 | eh = (struct ppc_link_hash_entry *) h; |
| 3867 | eh->tls_mask |= tls_type; |
| 3868 | } |
| 3869 | else |
| 3870 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, |
| 3871 | rel->r_addend, tls_type)) |
| 3872 | return FALSE; |
| 3873 | |
| 3874 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) |
| 3875 | { |
| 3876 | /* One extra to simplify get_tls_mask. */ |
| 3877 | bfd_size_type amt = sec->size * sizeof (unsigned) / 8 + 1; |
| 3878 | ppc64_elf_section_data (sec)->t_symndx = bfd_zalloc (abfd, amt); |
| 3879 | if (ppc64_elf_section_data (sec)->t_symndx == NULL) |
| 3880 | return FALSE; |
| 3881 | } |
| 3882 | BFD_ASSERT (rel->r_offset % 8 == 0); |
| 3883 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8] = r_symndx; |
| 3884 | |
| 3885 | /* Mark the second slot of a GD or LD entry. |
| 3886 | -1 to indicate GD and -2 to indicate LD. */ |
| 3887 | if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD)) |
| 3888 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -1; |
| 3889 | else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD)) |
| 3890 | ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -2; |
| 3891 | goto dodyn; |
| 3892 | |
| 3893 | case R_PPC64_TPREL16: |
| 3894 | case R_PPC64_TPREL16_LO: |
| 3895 | case R_PPC64_TPREL16_HI: |
| 3896 | case R_PPC64_TPREL16_HA: |
| 3897 | case R_PPC64_TPREL16_DS: |
| 3898 | case R_PPC64_TPREL16_LO_DS: |
| 3899 | case R_PPC64_TPREL16_HIGHER: |
| 3900 | case R_PPC64_TPREL16_HIGHERA: |
| 3901 | case R_PPC64_TPREL16_HIGHEST: |
| 3902 | case R_PPC64_TPREL16_HIGHESTA: |
| 3903 | if (info->shared) |
| 3904 | { |
| 3905 | info->flags |= DF_STATIC_TLS; |
| 3906 | goto dodyn; |
| 3907 | } |
| 3908 | break; |
| 3909 | |
| 3910 | case R_PPC64_ADDR64: |
| 3911 | if (opd_sym_map != NULL |
| 3912 | && h != NULL |
| 3913 | && h->root.root.string[0] == '.' |
| 3914 | && h->root.root.string[1] != 0) |
| 3915 | get_fdh ((struct ppc_link_hash_entry *) h, htab); |
| 3916 | |
| 3917 | if (opd_sym_map != NULL |
| 3918 | && h == NULL |
| 3919 | && rel + 1 < rel_end |
| 3920 | && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC) |
| 3921 | { |
| 3922 | asection *s; |
| 3923 | |
| 3924 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec, |
| 3925 | r_symndx); |
| 3926 | if (s == NULL) |
| 3927 | return FALSE; |
| 3928 | else if (s != sec) |
| 3929 | opd_sym_map[rel->r_offset / 24] = s; |
| 3930 | } |
| 3931 | /* Fall through. */ |
| 3932 | |
| 3933 | case R_PPC64_REL30: |
| 3934 | case R_PPC64_REL32: |
| 3935 | case R_PPC64_REL64: |
| 3936 | case R_PPC64_ADDR14: |
| 3937 | case R_PPC64_ADDR14_BRNTAKEN: |
| 3938 | case R_PPC64_ADDR14_BRTAKEN: |
| 3939 | case R_PPC64_ADDR16: |
| 3940 | case R_PPC64_ADDR16_DS: |
| 3941 | case R_PPC64_ADDR16_HA: |
| 3942 | case R_PPC64_ADDR16_HI: |
| 3943 | case R_PPC64_ADDR16_HIGHER: |
| 3944 | case R_PPC64_ADDR16_HIGHERA: |
| 3945 | case R_PPC64_ADDR16_HIGHEST: |
| 3946 | case R_PPC64_ADDR16_HIGHESTA: |
| 3947 | case R_PPC64_ADDR16_LO: |
| 3948 | case R_PPC64_ADDR16_LO_DS: |
| 3949 | case R_PPC64_ADDR24: |
| 3950 | case R_PPC64_ADDR32: |
| 3951 | case R_PPC64_UADDR16: |
| 3952 | case R_PPC64_UADDR32: |
| 3953 | case R_PPC64_UADDR64: |
| 3954 | case R_PPC64_TOC: |
| 3955 | if (h != NULL && !info->shared) |
| 3956 | /* We may need a copy reloc. */ |
| 3957 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; |
| 3958 | |
| 3959 | /* Don't propagate .opd relocs. */ |
| 3960 | if (NO_OPD_RELOCS && opd_sym_map != NULL) |
| 3961 | break; |
| 3962 | |
| 3963 | /* If we are creating a shared library, and this is a reloc |
| 3964 | against a global symbol, or a non PC relative reloc |
| 3965 | against a local symbol, then we need to copy the reloc |
| 3966 | into the shared library. However, if we are linking with |
| 3967 | -Bsymbolic, we do not need to copy a reloc against a |
| 3968 | global symbol which is defined in an object we are |
| 3969 | including in the link (i.e., DEF_REGULAR is set). At |
| 3970 | this point we have not seen all the input files, so it is |
| 3971 | possible that DEF_REGULAR is not set now but will be set |
| 3972 | later (it is never cleared). In case of a weak definition, |
| 3973 | DEF_REGULAR may be cleared later by a strong definition in |
| 3974 | a shared library. We account for that possibility below by |
| 3975 | storing information in the dyn_relocs field of the hash |
| 3976 | table entry. A similar situation occurs when creating |
| 3977 | shared libraries and symbol visibility changes render the |
| 3978 | symbol local. |
| 3979 | |
| 3980 | If on the other hand, we are creating an executable, we |
| 3981 | may need to keep relocations for symbols satisfied by a |
| 3982 | dynamic library if we manage to avoid copy relocs for the |
| 3983 | symbol. */ |
| 3984 | dodyn: |
| 3985 | if ((info->shared |
| 3986 | && (MUST_BE_DYN_RELOC (r_type) |
| 3987 | || (h != NULL |
| 3988 | && (! info->symbolic |
| 3989 | || h->root.type == bfd_link_hash_defweak |
| 3990 | || (h->elf_link_hash_flags |
| 3991 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) |
| 3992 | || (ELIMINATE_COPY_RELOCS |
| 3993 | && !info->shared |
| 3994 | && h != NULL |
| 3995 | && (h->root.type == bfd_link_hash_defweak |
| 3996 | || (h->elf_link_hash_flags |
| 3997 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) |
| 3998 | { |
| 3999 | struct ppc_dyn_relocs *p; |
| 4000 | struct ppc_dyn_relocs **head; |
| 4001 | |
| 4002 | /* We must copy these reloc types into the output file. |
| 4003 | Create a reloc section in dynobj and make room for |
| 4004 | this reloc. */ |
| 4005 | if (sreloc == NULL) |
| 4006 | { |
| 4007 | const char *name; |
| 4008 | bfd *dynobj; |
| 4009 | |
| 4010 | name = (bfd_elf_string_from_elf_section |
| 4011 | (abfd, |
| 4012 | elf_elfheader (abfd)->e_shstrndx, |
| 4013 | elf_section_data (sec)->rel_hdr.sh_name)); |
| 4014 | if (name == NULL) |
| 4015 | return FALSE; |
| 4016 | |
| 4017 | if (strncmp (name, ".rela", 5) != 0 |
| 4018 | || strcmp (bfd_get_section_name (abfd, sec), |
| 4019 | name + 5) != 0) |
| 4020 | { |
| 4021 | (*_bfd_error_handler) |
| 4022 | (_("%s: bad relocation section name `%s\'"), |
| 4023 | bfd_archive_filename (abfd), name); |
| 4024 | bfd_set_error (bfd_error_bad_value); |
| 4025 | } |
| 4026 | |
| 4027 | dynobj = htab->elf.dynobj; |
| 4028 | sreloc = bfd_get_section_by_name (dynobj, name); |
| 4029 | if (sreloc == NULL) |
| 4030 | { |
| 4031 | flagword flags; |
| 4032 | |
| 4033 | sreloc = bfd_make_section (dynobj, name); |
| 4034 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
| 4035 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); |
| 4036 | if ((sec->flags & SEC_ALLOC) != 0) |
| 4037 | flags |= SEC_ALLOC | SEC_LOAD; |
| 4038 | if (sreloc == NULL |
| 4039 | || ! bfd_set_section_flags (dynobj, sreloc, flags) |
| 4040 | || ! bfd_set_section_alignment (dynobj, sreloc, 3)) |
| 4041 | return FALSE; |
| 4042 | } |
| 4043 | elf_section_data (sec)->sreloc = sreloc; |
| 4044 | } |
| 4045 | |
| 4046 | /* If this is a global symbol, we count the number of |
| 4047 | relocations we need for this symbol. */ |
| 4048 | if (h != NULL) |
| 4049 | { |
| 4050 | head = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
| 4051 | } |
| 4052 | else |
| 4053 | { |
| 4054 | /* Track dynamic relocs needed for local syms too. |
| 4055 | We really need local syms available to do this |
| 4056 | easily. Oh well. */ |
| 4057 | |
| 4058 | asection *s; |
| 4059 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, |
| 4060 | sec, r_symndx); |
| 4061 | if (s == NULL) |
| 4062 | return FALSE; |
| 4063 | |
| 4064 | head = ((struct ppc_dyn_relocs **) |
| 4065 | &elf_section_data (s)->local_dynrel); |
| 4066 | } |
| 4067 | |
| 4068 | p = *head; |
| 4069 | if (p == NULL || p->sec != sec) |
| 4070 | { |
| 4071 | p = bfd_alloc (htab->elf.dynobj, sizeof *p); |
| 4072 | if (p == NULL) |
| 4073 | return FALSE; |
| 4074 | p->next = *head; |
| 4075 | *head = p; |
| 4076 | p->sec = sec; |
| 4077 | p->count = 0; |
| 4078 | p->pc_count = 0; |
| 4079 | } |
| 4080 | |
| 4081 | p->count += 1; |
| 4082 | if (!MUST_BE_DYN_RELOC (r_type)) |
| 4083 | p->pc_count += 1; |
| 4084 | } |
| 4085 | break; |
| 4086 | |
| 4087 | default: |
| 4088 | break; |
| 4089 | } |
| 4090 | } |
| 4091 | |
| 4092 | return TRUE; |
| 4093 | } |
| 4094 | |
| 4095 | /* Return the section that should be marked against GC for a given |
| 4096 | relocation. */ |
| 4097 | |
| 4098 | static asection * |
| 4099 | ppc64_elf_gc_mark_hook (asection *sec, |
| 4100 | struct bfd_link_info *info, |
| 4101 | Elf_Internal_Rela *rel, |
| 4102 | struct elf_link_hash_entry *h, |
| 4103 | Elf_Internal_Sym *sym) |
| 4104 | { |
| 4105 | asection *rsec; |
| 4106 | |
| 4107 | /* First mark all our entry sym sections. */ |
| 4108 | if (info->gc_sym_list != NULL) |
| 4109 | { |
| 4110 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
| 4111 | struct bfd_sym_chain *sym = info->gc_sym_list; |
| 4112 | |
| 4113 | info->gc_sym_list = NULL; |
| 4114 | do |
| 4115 | { |
| 4116 | struct ppc_link_hash_entry *eh; |
| 4117 | |
| 4118 | eh = (struct ppc_link_hash_entry *) |
| 4119 | elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE); |
| 4120 | if (eh == NULL) |
| 4121 | continue; |
| 4122 | if (eh->elf.root.type != bfd_link_hash_defined |
| 4123 | && eh->elf.root.type != bfd_link_hash_defweak) |
| 4124 | continue; |
| 4125 | |
| 4126 | if (eh->is_func_descriptor) |
| 4127 | rsec = eh->oh->elf.root.u.def.section; |
| 4128 | else |
| 4129 | continue; |
| 4130 | |
| 4131 | if (!rsec->gc_mark) |
| 4132 | _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook); |
| 4133 | |
| 4134 | rsec = eh->elf.root.u.def.section; |
| 4135 | if (!rsec->gc_mark) |
| 4136 | _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook); |
| 4137 | |
| 4138 | sym = sym->next; |
| 4139 | } |
| 4140 | while (sym != NULL); |
| 4141 | } |
| 4142 | |
| 4143 | /* Syms return NULL if we're marking .opd, so we avoid marking all |
| 4144 | function sections, as all functions are referenced in .opd. */ |
| 4145 | rsec = NULL; |
| 4146 | if (get_opd_info (sec) != NULL) |
| 4147 | return rsec; |
| 4148 | |
| 4149 | if (h != NULL) |
| 4150 | { |
| 4151 | enum elf_ppc64_reloc_type r_type; |
| 4152 | struct ppc_link_hash_entry *eh; |
| 4153 | |
| 4154 | r_type = ELF64_R_TYPE (rel->r_info); |
| 4155 | switch (r_type) |
| 4156 | { |
| 4157 | case R_PPC64_GNU_VTINHERIT: |
| 4158 | case R_PPC64_GNU_VTENTRY: |
| 4159 | break; |
| 4160 | |
| 4161 | default: |
| 4162 | switch (h->root.type) |
| 4163 | { |
| 4164 | case bfd_link_hash_defined: |
| 4165 | case bfd_link_hash_defweak: |
| 4166 | eh = (struct ppc_link_hash_entry *) h; |
| 4167 | if (eh->oh != NULL && eh->oh->is_func_descriptor) |
| 4168 | eh = eh->oh; |
| 4169 | |
| 4170 | /* Function descriptor syms cause the associated |
| 4171 | function code sym section to be marked. */ |
| 4172 | if (eh->is_func_descriptor) |
| 4173 | { |
| 4174 | /* They also mark their opd section. */ |
| 4175 | if (!eh->elf.root.u.def.section->gc_mark) |
| 4176 | _bfd_elf_gc_mark (info, eh->elf.root.u.def.section, |
| 4177 | ppc64_elf_gc_mark_hook); |
| 4178 | |
| 4179 | rsec = eh->oh->elf.root.u.def.section; |
| 4180 | } |
| 4181 | else |
| 4182 | rsec = h->root.u.def.section; |
| 4183 | break; |
| 4184 | |
| 4185 | case bfd_link_hash_common: |
| 4186 | rsec = h->root.u.c.p->section; |
| 4187 | break; |
| 4188 | |
| 4189 | default: |
| 4190 | break; |
| 4191 | } |
| 4192 | } |
| 4193 | } |
| 4194 | else |
| 4195 | { |
| 4196 | asection **opd_sym_section; |
| 4197 | |
| 4198 | rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
| 4199 | opd_sym_section = get_opd_info (rsec); |
| 4200 | if (opd_sym_section != NULL) |
| 4201 | { |
| 4202 | if (!rsec->gc_mark) |
| 4203 | _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook); |
| 4204 | |
| 4205 | rsec = opd_sym_section[sym->st_value / 24]; |
| 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | return rsec; |
| 4210 | } |
| 4211 | |
| 4212 | /* Update the .got, .plt. and dynamic reloc reference counts for the |
| 4213 | section being removed. */ |
| 4214 | |
| 4215 | static bfd_boolean |
| 4216 | ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, |
| 4217 | asection *sec, const Elf_Internal_Rela *relocs) |
| 4218 | { |
| 4219 | struct ppc_link_hash_table *htab; |
| 4220 | Elf_Internal_Shdr *symtab_hdr; |
| 4221 | struct elf_link_hash_entry **sym_hashes; |
| 4222 | struct got_entry **local_got_ents; |
| 4223 | const Elf_Internal_Rela *rel, *relend; |
| 4224 | |
| 4225 | if ((sec->flags & SEC_ALLOC) == 0) |
| 4226 | return TRUE; |
| 4227 | |
| 4228 | elf_section_data (sec)->local_dynrel = NULL; |
| 4229 | |
| 4230 | htab = ppc_hash_table (info); |
| 4231 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 4232 | sym_hashes = elf_sym_hashes (abfd); |
| 4233 | local_got_ents = elf_local_got_ents (abfd); |
| 4234 | |
| 4235 | relend = relocs + sec->reloc_count; |
| 4236 | for (rel = relocs; rel < relend; rel++) |
| 4237 | { |
| 4238 | unsigned long r_symndx; |
| 4239 | enum elf_ppc64_reloc_type r_type; |
| 4240 | struct elf_link_hash_entry *h = NULL; |
| 4241 | char tls_type = 0; |
| 4242 | |
| 4243 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 4244 | r_type = ELF64_R_TYPE (rel->r_info); |
| 4245 | if (r_symndx >= symtab_hdr->sh_info) |
| 4246 | { |
| 4247 | struct ppc_link_hash_entry *eh; |
| 4248 | struct ppc_dyn_relocs **pp; |
| 4249 | struct ppc_dyn_relocs *p; |
| 4250 | |
| 4251 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 4252 | eh = (struct ppc_link_hash_entry *) h; |
| 4253 | |
| 4254 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) |
| 4255 | if (p->sec == sec) |
| 4256 | { |
| 4257 | /* Everything must go for SEC. */ |
| 4258 | *pp = p->next; |
| 4259 | break; |
| 4260 | } |
| 4261 | } |
| 4262 | |
| 4263 | switch (r_type) |
| 4264 | { |
| 4265 | case R_PPC64_GOT_TLSLD16: |
| 4266 | case R_PPC64_GOT_TLSLD16_LO: |
| 4267 | case R_PPC64_GOT_TLSLD16_HI: |
| 4268 | case R_PPC64_GOT_TLSLD16_HA: |
| 4269 | ppc64_tlsld_got (abfd)->refcount -= 1; |
| 4270 | tls_type = TLS_TLS | TLS_LD; |
| 4271 | goto dogot; |
| 4272 | |
| 4273 | case R_PPC64_GOT_TLSGD16: |
| 4274 | case R_PPC64_GOT_TLSGD16_LO: |
| 4275 | case R_PPC64_GOT_TLSGD16_HI: |
| 4276 | case R_PPC64_GOT_TLSGD16_HA: |
| 4277 | tls_type = TLS_TLS | TLS_GD; |
| 4278 | goto dogot; |
| 4279 | |
| 4280 | case R_PPC64_GOT_TPREL16_DS: |
| 4281 | case R_PPC64_GOT_TPREL16_LO_DS: |
| 4282 | case R_PPC64_GOT_TPREL16_HI: |
| 4283 | case R_PPC64_GOT_TPREL16_HA: |
| 4284 | tls_type = TLS_TLS | TLS_TPREL; |
| 4285 | goto dogot; |
| 4286 | |
| 4287 | case R_PPC64_GOT_DTPREL16_DS: |
| 4288 | case R_PPC64_GOT_DTPREL16_LO_DS: |
| 4289 | case R_PPC64_GOT_DTPREL16_HI: |
| 4290 | case R_PPC64_GOT_DTPREL16_HA: |
| 4291 | tls_type = TLS_TLS | TLS_DTPREL; |
| 4292 | goto dogot; |
| 4293 | |
| 4294 | case R_PPC64_GOT16: |
| 4295 | case R_PPC64_GOT16_DS: |
| 4296 | case R_PPC64_GOT16_HA: |
| 4297 | case R_PPC64_GOT16_HI: |
| 4298 | case R_PPC64_GOT16_LO: |
| 4299 | case R_PPC64_GOT16_LO_DS: |
| 4300 | dogot: |
| 4301 | { |
| 4302 | struct got_entry *ent; |
| 4303 | |
| 4304 | if (h != NULL) |
| 4305 | ent = h->got.glist; |
| 4306 | else |
| 4307 | ent = local_got_ents[r_symndx]; |
| 4308 | |
| 4309 | for (; ent != NULL; ent = ent->next) |
| 4310 | if (ent->addend == rel->r_addend |
| 4311 | && ent->owner == abfd |
| 4312 | && ent->tls_type == tls_type) |
| 4313 | break; |
| 4314 | if (ent == NULL) |
| 4315 | abort (); |
| 4316 | if (ent->got.refcount > 0) |
| 4317 | ent->got.refcount -= 1; |
| 4318 | } |
| 4319 | break; |
| 4320 | |
| 4321 | case R_PPC64_PLT16_HA: |
| 4322 | case R_PPC64_PLT16_HI: |
| 4323 | case R_PPC64_PLT16_LO: |
| 4324 | case R_PPC64_PLT32: |
| 4325 | case R_PPC64_PLT64: |
| 4326 | case R_PPC64_REL14: |
| 4327 | case R_PPC64_REL14_BRNTAKEN: |
| 4328 | case R_PPC64_REL14_BRTAKEN: |
| 4329 | case R_PPC64_REL24: |
| 4330 | if (h != NULL) |
| 4331 | { |
| 4332 | struct plt_entry *ent; |
| 4333 | |
| 4334 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
| 4335 | if (ent->addend == rel->r_addend) |
| 4336 | break; |
| 4337 | if (ent == NULL) |
| 4338 | abort (); |
| 4339 | if (ent->plt.refcount > 0) |
| 4340 | ent->plt.refcount -= 1; |
| 4341 | } |
| 4342 | break; |
| 4343 | |
| 4344 | default: |
| 4345 | break; |
| 4346 | } |
| 4347 | } |
| 4348 | return TRUE; |
| 4349 | } |
| 4350 | |
| 4351 | /* Called via elf_link_hash_traverse to transfer dynamic linking |
| 4352 | information on function code symbol entries to their corresponding |
| 4353 | function descriptor symbol entries. */ |
| 4354 | static bfd_boolean |
| 4355 | func_desc_adjust (struct elf_link_hash_entry *h, void *inf) |
| 4356 | { |
| 4357 | struct bfd_link_info *info; |
| 4358 | struct ppc_link_hash_table *htab; |
| 4359 | struct plt_entry *ent; |
| 4360 | struct ppc_link_hash_entry *fh; |
| 4361 | struct ppc_link_hash_entry *fdh; |
| 4362 | bfd_boolean force_local; |
| 4363 | |
| 4364 | fh = (struct ppc_link_hash_entry *) h; |
| 4365 | if (fh->elf.root.type == bfd_link_hash_indirect) |
| 4366 | return TRUE; |
| 4367 | |
| 4368 | if (fh->elf.root.type == bfd_link_hash_warning) |
| 4369 | fh = (struct ppc_link_hash_entry *) fh->elf.root.u.i.link; |
| 4370 | |
| 4371 | info = inf; |
| 4372 | htab = ppc_hash_table (info); |
| 4373 | |
| 4374 | /* If this is a function code symbol, transfer dynamic linking |
| 4375 | information to the function descriptor symbol. */ |
| 4376 | if (!fh->is_func) |
| 4377 | return TRUE; |
| 4378 | |
| 4379 | for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next) |
| 4380 | if (ent->plt.refcount > 0) |
| 4381 | break; |
| 4382 | if (ent == NULL |
| 4383 | || fh->elf.root.root.string[0] != '.' |
| 4384 | || fh->elf.root.root.string[1] == '\0') |
| 4385 | return TRUE; |
| 4386 | |
| 4387 | /* Find the corresponding function descriptor symbol. Create it |
| 4388 | as undefined if necessary. */ |
| 4389 | |
| 4390 | fdh = get_fdh (fh, htab); |
| 4391 | if (fdh != NULL) |
| 4392 | while (fdh->elf.root.type == bfd_link_hash_indirect |
| 4393 | || fdh->elf.root.type == bfd_link_hash_warning) |
| 4394 | fdh = (struct ppc_link_hash_entry *) fdh->elf.root.u.i.link; |
| 4395 | |
| 4396 | if (fdh == NULL |
| 4397 | && info->shared |
| 4398 | && (fh->elf.root.type == bfd_link_hash_undefined |
| 4399 | || fh->elf.root.type == bfd_link_hash_undefweak)) |
| 4400 | { |
| 4401 | bfd *abfd; |
| 4402 | asymbol *newsym; |
| 4403 | struct bfd_link_hash_entry *bh; |
| 4404 | |
| 4405 | abfd = fh->elf.root.u.undef.abfd; |
| 4406 | newsym = bfd_make_empty_symbol (abfd); |
| 4407 | newsym->name = fh->elf.root.root.string + 1; |
| 4408 | newsym->section = bfd_und_section_ptr; |
| 4409 | newsym->value = 0; |
| 4410 | newsym->flags = BSF_OBJECT; |
| 4411 | if (fh->elf.root.type == bfd_link_hash_undefweak) |
| 4412 | newsym->flags |= BSF_WEAK; |
| 4413 | |
| 4414 | bh = &fdh->elf.root; |
| 4415 | if ( !(_bfd_generic_link_add_one_symbol |
| 4416 | (info, abfd, newsym->name, newsym->flags, |
| 4417 | newsym->section, newsym->value, NULL, FALSE, FALSE, &bh))) |
| 4418 | { |
| 4419 | return FALSE; |
| 4420 | } |
| 4421 | fdh = (struct ppc_link_hash_entry *) bh; |
| 4422 | fdh->elf.elf_link_hash_flags &= ~ELF_LINK_NON_ELF; |
| 4423 | fdh->elf.size = 24; |
| 4424 | fdh->elf.type = STT_OBJECT; |
| 4425 | } |
| 4426 | |
| 4427 | if (fdh != NULL |
| 4428 | && (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0 |
| 4429 | && (info->shared |
| 4430 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
| 4431 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0 |
| 4432 | || (fdh->elf.root.type == bfd_link_hash_undefweak |
| 4433 | && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT))) |
| 4434 | { |
| 4435 | if (fdh->elf.dynindx == -1) |
| 4436 | if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf)) |
| 4437 | return FALSE; |
| 4438 | fdh->elf.elf_link_hash_flags |
| 4439 | |= (fh->elf.elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR |
| 4440 | | ELF_LINK_HASH_REF_DYNAMIC |
| 4441 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK |
| 4442 | | ELF_LINK_NON_GOT_REF)); |
| 4443 | if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT) |
| 4444 | { |
| 4445 | fdh->elf.plt.plist = fh->elf.plt.plist; |
| 4446 | fdh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
| 4447 | } |
| 4448 | fdh->is_func_descriptor = 1; |
| 4449 | fdh->oh = fh; |
| 4450 | fh->oh = fdh; |
| 4451 | } |
| 4452 | |
| 4453 | /* Now that the info is on the function descriptor, clear the |
| 4454 | function code sym info. Any function code syms for which we |
| 4455 | don't have a definition in a regular file, we force local. |
| 4456 | This prevents a shared library from exporting syms that have |
| 4457 | been imported from another library. Function code syms that |
| 4458 | are really in the library we must leave global to prevent the |
| 4459 | linker dragging in a definition from a static library. */ |
| 4460 | force_local |
| 4461 | = (info->shared |
| 4462 | && ((fh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 |
| 4463 | || fdh == NULL |
| 4464 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 |
| 4465 | || (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)); |
| 4466 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); |
| 4467 | |
| 4468 | return TRUE; |
| 4469 | } |
| 4470 | |
| 4471 | #define MIN_SAVE_FPR 14 |
| 4472 | #define MAX_SAVE_FPR 31 |
| 4473 | |
| 4474 | /* Called near the start of bfd_elf_size_dynamic_sections. We use |
| 4475 | this hook to a) provide some gcc support functions, and b) transfer |
| 4476 | dynamic linking information gathered so far on function code symbol |
| 4477 | entries, to their corresponding function descriptor symbol entries. */ |
| 4478 | static bfd_boolean |
| 4479 | ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED, |
| 4480 | struct bfd_link_info *info) |
| 4481 | { |
| 4482 | struct ppc_link_hash_table *htab; |
| 4483 | unsigned int lowest_savef = MAX_SAVE_FPR + 2; |
| 4484 | unsigned int lowest_restf = MAX_SAVE_FPR + 2; |
| 4485 | unsigned int i; |
| 4486 | struct elf_link_hash_entry *h; |
| 4487 | bfd_byte *p; |
| 4488 | char sym[10]; |
| 4489 | |
| 4490 | htab = ppc_hash_table (info); |
| 4491 | |
| 4492 | if (htab->sfpr == NULL) |
| 4493 | /* We don't have any relocs. */ |
| 4494 | return TRUE; |
| 4495 | |
| 4496 | /* First provide any missing ._savef* and ._restf* functions. */ |
| 4497 | memcpy (sym, "._savef14", 10); |
| 4498 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) |
| 4499 | { |
| 4500 | sym[7] = i / 10 + '0'; |
| 4501 | sym[8] = i % 10 + '0'; |
| 4502 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
| 4503 | if (h != NULL |
| 4504 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
| 4505 | { |
| 4506 | if (lowest_savef > i) |
| 4507 | lowest_savef = i; |
| 4508 | h->root.type = bfd_link_hash_defined; |
| 4509 | h->root.u.def.section = htab->sfpr; |
| 4510 | h->root.u.def.value = (i - lowest_savef) * 4; |
| 4511 | h->type = STT_FUNC; |
| 4512 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; |
| 4513 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
| 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | memcpy (sym, "._restf14", 10); |
| 4518 | for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++) |
| 4519 | { |
| 4520 | sym[7] = i / 10 + '0'; |
| 4521 | sym[8] = i % 10 + '0'; |
| 4522 | h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE); |
| 4523 | if (h != NULL |
| 4524 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
| 4525 | { |
| 4526 | if (lowest_restf > i) |
| 4527 | lowest_restf = i; |
| 4528 | h->root.type = bfd_link_hash_defined; |
| 4529 | h->root.u.def.section = htab->sfpr; |
| 4530 | h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 |
| 4531 | + (i - lowest_restf) * 4); |
| 4532 | h->type = STT_FUNC; |
| 4533 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; |
| 4534 | _bfd_elf_link_hash_hide_symbol (info, h, TRUE); |
| 4535 | } |
| 4536 | } |
| 4537 | |
| 4538 | elf_link_hash_traverse (&htab->elf, func_desc_adjust, info); |
| 4539 | |
| 4540 | htab->sfpr->size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4 |
| 4541 | + (MAX_SAVE_FPR + 2 - lowest_restf) * 4); |
| 4542 | |
| 4543 | if (htab->sfpr->size == 0) |
| 4544 | { |
| 4545 | _bfd_strip_section_from_output (info, htab->sfpr); |
| 4546 | return TRUE; |
| 4547 | } |
| 4548 | |
| 4549 | p = bfd_alloc (htab->elf.dynobj, htab->sfpr->size); |
| 4550 | if (p == NULL) |
| 4551 | return FALSE; |
| 4552 | htab->sfpr->contents = p; |
| 4553 | |
| 4554 | for (i = lowest_savef; i <= MAX_SAVE_FPR; i++) |
| 4555 | { |
| 4556 | unsigned int fpr = i << 21; |
| 4557 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; |
| 4558 | bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p); |
| 4559 | p += 4; |
| 4560 | } |
| 4561 | if (lowest_savef <= MAX_SAVE_FPR) |
| 4562 | { |
| 4563 | bfd_put_32 (htab->elf.dynobj, BLR, p); |
| 4564 | p += 4; |
| 4565 | } |
| 4566 | |
| 4567 | for (i = lowest_restf; i <= MAX_SAVE_FPR; i++) |
| 4568 | { |
| 4569 | unsigned int fpr = i << 21; |
| 4570 | unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8; |
| 4571 | bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p); |
| 4572 | p += 4; |
| 4573 | } |
| 4574 | if (lowest_restf <= MAX_SAVE_FPR) |
| 4575 | bfd_put_32 (htab->elf.dynobj, BLR, p); |
| 4576 | |
| 4577 | return TRUE; |
| 4578 | } |
| 4579 | |
| 4580 | /* Adjust a symbol defined by a dynamic object and referenced by a |
| 4581 | regular object. The current definition is in some section of the |
| 4582 | dynamic object, but we're not including those sections. We have to |
| 4583 | change the definition to something the rest of the link can |
| 4584 | understand. */ |
| 4585 | |
| 4586 | static bfd_boolean |
| 4587 | ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info, |
| 4588 | struct elf_link_hash_entry *h) |
| 4589 | { |
| 4590 | struct ppc_link_hash_table *htab; |
| 4591 | asection *s; |
| 4592 | unsigned int power_of_two; |
| 4593 | |
| 4594 | htab = ppc_hash_table (info); |
| 4595 | |
| 4596 | /* Deal with function syms. */ |
| 4597 | if (h->type == STT_FUNC |
| 4598 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) |
| 4599 | { |
| 4600 | /* Clear procedure linkage table information for any symbol that |
| 4601 | won't need a .plt entry. */ |
| 4602 | struct plt_entry *ent; |
| 4603 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
| 4604 | if (ent->plt.refcount > 0) |
| 4605 | break; |
| 4606 | if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor |
| 4607 | || ent == NULL |
| 4608 | || SYMBOL_CALLS_LOCAL (info, h) |
| 4609 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
| 4610 | && h->root.type == bfd_link_hash_undefweak)) |
| 4611 | { |
| 4612 | h->plt.plist = NULL; |
| 4613 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
| 4614 | } |
| 4615 | } |
| 4616 | else |
| 4617 | h->plt.plist = NULL; |
| 4618 | |
| 4619 | /* If this is a weak symbol, and there is a real definition, the |
| 4620 | processor independent code will have arranged for us to see the |
| 4621 | real definition first, and we can just use the same value. */ |
| 4622 | if (h->weakdef != NULL) |
| 4623 | { |
| 4624 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined |
| 4625 | || h->weakdef->root.type == bfd_link_hash_defweak); |
| 4626 | h->root.u.def.section = h->weakdef->root.u.def.section; |
| 4627 | h->root.u.def.value = h->weakdef->root.u.def.value; |
| 4628 | if (ELIMINATE_COPY_RELOCS) |
| 4629 | h->elf_link_hash_flags |
| 4630 | = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF) |
| 4631 | | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF)); |
| 4632 | return TRUE; |
| 4633 | } |
| 4634 | |
| 4635 | /* If we are creating a shared library, we must presume that the |
| 4636 | only references to the symbol are via the global offset table. |
| 4637 | For such cases we need not do anything here; the relocations will |
| 4638 | be handled correctly by relocate_section. */ |
| 4639 | if (info->shared) |
| 4640 | return TRUE; |
| 4641 | |
| 4642 | /* If there are no references to this symbol that do not use the |
| 4643 | GOT, we don't need to generate a copy reloc. */ |
| 4644 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) |
| 4645 | return TRUE; |
| 4646 | |
| 4647 | if (ELIMINATE_COPY_RELOCS) |
| 4648 | { |
| 4649 | struct ppc_link_hash_entry * eh; |
| 4650 | struct ppc_dyn_relocs *p; |
| 4651 | |
| 4652 | eh = (struct ppc_link_hash_entry *) h; |
| 4653 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
| 4654 | { |
| 4655 | s = p->sec->output_section; |
| 4656 | if (s != NULL && (s->flags & SEC_READONLY) != 0) |
| 4657 | break; |
| 4658 | } |
| 4659 | |
| 4660 | /* If we didn't find any dynamic relocs in read-only sections, then |
| 4661 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ |
| 4662 | if (p == NULL) |
| 4663 | { |
| 4664 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; |
| 4665 | return TRUE; |
| 4666 | } |
| 4667 | } |
| 4668 | |
| 4669 | if (h->plt.plist != NULL) |
| 4670 | { |
| 4671 | /* We should never get here, but unfortunately there are versions |
| 4672 | of gcc out there that improperly (for this ABI) put initialized |
| 4673 | function pointers, vtable refs and suchlike in read-only |
| 4674 | sections. Allow them to proceed, but warn that this might |
| 4675 | break at runtime. */ |
| 4676 | (*_bfd_error_handler) |
| 4677 | (_("copy reloc against `%s' requires lazy plt linking; " |
| 4678 | "avoid setting LD_BIND_NOW=1 or upgrade gcc"), |
| 4679 | h->root.root.string); |
| 4680 | } |
| 4681 | |
| 4682 | /* This is a reference to a symbol defined by a dynamic object which |
| 4683 | is not a function. */ |
| 4684 | |
| 4685 | /* We must allocate the symbol in our .dynbss section, which will |
| 4686 | become part of the .bss section of the executable. There will be |
| 4687 | an entry for this symbol in the .dynsym section. The dynamic |
| 4688 | object will contain position independent code, so all references |
| 4689 | from the dynamic object to this symbol will go through the global |
| 4690 | offset table. The dynamic linker will use the .dynsym entry to |
| 4691 | determine the address it must put in the global offset table, so |
| 4692 | both the dynamic object and the regular object will refer to the |
| 4693 | same memory location for the variable. */ |
| 4694 | |
| 4695 | /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker |
| 4696 | to copy the initial value out of the dynamic object and into the |
| 4697 | runtime process image. We need to remember the offset into the |
| 4698 | .rela.bss section we are going to use. */ |
| 4699 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
| 4700 | { |
| 4701 | htab->relbss->size += sizeof (Elf64_External_Rela); |
| 4702 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
| 4703 | } |
| 4704 | |
| 4705 | /* We need to figure out the alignment required for this symbol. I |
| 4706 | have no idea how ELF linkers handle this. */ |
| 4707 | power_of_two = bfd_log2 (h->size); |
| 4708 | if (power_of_two > 4) |
| 4709 | power_of_two = 4; |
| 4710 | |
| 4711 | /* Apply the required alignment. */ |
| 4712 | s = htab->dynbss; |
| 4713 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
| 4714 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) |
| 4715 | { |
| 4716 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
| 4717 | return FALSE; |
| 4718 | } |
| 4719 | |
| 4720 | /* Define the symbol as being at this point in the section. */ |
| 4721 | h->root.u.def.section = s; |
| 4722 | h->root.u.def.value = s->size; |
| 4723 | |
| 4724 | /* Increment the section size to make room for the symbol. */ |
| 4725 | s->size += h->size; |
| 4726 | |
| 4727 | return TRUE; |
| 4728 | } |
| 4729 | |
| 4730 | /* If given a function descriptor symbol, hide both the function code |
| 4731 | sym and the descriptor. */ |
| 4732 | static void |
| 4733 | ppc64_elf_hide_symbol (struct bfd_link_info *info, |
| 4734 | struct elf_link_hash_entry *h, |
| 4735 | bfd_boolean force_local) |
| 4736 | { |
| 4737 | struct ppc_link_hash_entry *eh; |
| 4738 | _bfd_elf_link_hash_hide_symbol (info, h, force_local); |
| 4739 | |
| 4740 | eh = (struct ppc_link_hash_entry *) h; |
| 4741 | if (eh->is_func_descriptor) |
| 4742 | { |
| 4743 | struct ppc_link_hash_entry *fh = eh->oh; |
| 4744 | |
| 4745 | if (fh == NULL) |
| 4746 | { |
| 4747 | const char *p, *q; |
| 4748 | struct ppc_link_hash_table *htab; |
| 4749 | char save; |
| 4750 | |
| 4751 | /* We aren't supposed to use alloca in BFD because on |
| 4752 | systems which do not have alloca the version in libiberty |
| 4753 | calls xmalloc, which might cause the program to crash |
| 4754 | when it runs out of memory. This function doesn't have a |
| 4755 | return status, so there's no way to gracefully return an |
| 4756 | error. So cheat. We know that string[-1] can be safely |
| 4757 | accessed; It's either a string in an ELF string table, |
| 4758 | or allocated in an objalloc structure. */ |
| 4759 | |
| 4760 | p = eh->elf.root.root.string - 1; |
| 4761 | save = *p; |
| 4762 | *(char *) p = '.'; |
| 4763 | htab = ppc_hash_table (info); |
| 4764 | fh = (struct ppc_link_hash_entry *) |
| 4765 | elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); |
| 4766 | *(char *) p = save; |
| 4767 | |
| 4768 | /* Unfortunately, if it so happens that the string we were |
| 4769 | looking for was allocated immediately before this string, |
| 4770 | then we overwrote the string terminator. That's the only |
| 4771 | reason the lookup should fail. */ |
| 4772 | if (fh == NULL) |
| 4773 | { |
| 4774 | q = eh->elf.root.root.string + strlen (eh->elf.root.root.string); |
| 4775 | while (q >= eh->elf.root.root.string && *q == *p) |
| 4776 | --q, --p; |
| 4777 | if (q < eh->elf.root.root.string && *p == '.') |
| 4778 | fh = (struct ppc_link_hash_entry *) |
| 4779 | elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); |
| 4780 | } |
| 4781 | if (fh != NULL) |
| 4782 | { |
| 4783 | eh->oh = fh; |
| 4784 | fh->oh = eh; |
| 4785 | } |
| 4786 | } |
| 4787 | if (fh != NULL) |
| 4788 | _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local); |
| 4789 | } |
| 4790 | } |
| 4791 | |
| 4792 | static bfd_boolean |
| 4793 | get_sym_h (struct elf_link_hash_entry **hp, Elf_Internal_Sym **symp, |
| 4794 | asection **symsecp, char **tls_maskp, Elf_Internal_Sym **locsymsp, |
| 4795 | unsigned long r_symndx, bfd *ibfd) |
| 4796 | { |
| 4797 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
| 4798 | |
| 4799 | if (r_symndx >= symtab_hdr->sh_info) |
| 4800 | { |
| 4801 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); |
| 4802 | struct elf_link_hash_entry *h; |
| 4803 | |
| 4804 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 4805 | while (h->root.type == bfd_link_hash_indirect |
| 4806 | || h->root.type == bfd_link_hash_warning) |
| 4807 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 4808 | |
| 4809 | if (hp != NULL) |
| 4810 | *hp = h; |
| 4811 | |
| 4812 | if (symp != NULL) |
| 4813 | *symp = NULL; |
| 4814 | |
| 4815 | if (symsecp != NULL) |
| 4816 | { |
| 4817 | asection *symsec = NULL; |
| 4818 | if (h->root.type == bfd_link_hash_defined |
| 4819 | || h->root.type == bfd_link_hash_defweak) |
| 4820 | symsec = h->root.u.def.section; |
| 4821 | *symsecp = symsec; |
| 4822 | } |
| 4823 | |
| 4824 | if (tls_maskp != NULL) |
| 4825 | { |
| 4826 | struct ppc_link_hash_entry *eh; |
| 4827 | |
| 4828 | eh = (struct ppc_link_hash_entry *) h; |
| 4829 | *tls_maskp = &eh->tls_mask; |
| 4830 | } |
| 4831 | } |
| 4832 | else |
| 4833 | { |
| 4834 | Elf_Internal_Sym *sym; |
| 4835 | Elf_Internal_Sym *locsyms = *locsymsp; |
| 4836 | |
| 4837 | if (locsyms == NULL) |
| 4838 | { |
| 4839 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; |
| 4840 | if (locsyms == NULL) |
| 4841 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, |
| 4842 | symtab_hdr->sh_info, |
| 4843 | 0, NULL, NULL, NULL); |
| 4844 | if (locsyms == NULL) |
| 4845 | return FALSE; |
| 4846 | *locsymsp = locsyms; |
| 4847 | } |
| 4848 | sym = locsyms + r_symndx; |
| 4849 | |
| 4850 | if (hp != NULL) |
| 4851 | *hp = NULL; |
| 4852 | |
| 4853 | if (symp != NULL) |
| 4854 | *symp = sym; |
| 4855 | |
| 4856 | if (symsecp != NULL) |
| 4857 | { |
| 4858 | asection *symsec = NULL; |
| 4859 | if ((sym->st_shndx != SHN_UNDEF |
| 4860 | && sym->st_shndx < SHN_LORESERVE) |
| 4861 | || sym->st_shndx > SHN_HIRESERVE) |
| 4862 | symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx); |
| 4863 | *symsecp = symsec; |
| 4864 | } |
| 4865 | |
| 4866 | if (tls_maskp != NULL) |
| 4867 | { |
| 4868 | struct got_entry **lgot_ents; |
| 4869 | char *tls_mask; |
| 4870 | |
| 4871 | tls_mask = NULL; |
| 4872 | lgot_ents = elf_local_got_ents (ibfd); |
| 4873 | if (lgot_ents != NULL) |
| 4874 | { |
| 4875 | char *lgot_masks = (char *) (lgot_ents + symtab_hdr->sh_info); |
| 4876 | tls_mask = &lgot_masks[r_symndx]; |
| 4877 | } |
| 4878 | *tls_maskp = tls_mask; |
| 4879 | } |
| 4880 | } |
| 4881 | return TRUE; |
| 4882 | } |
| 4883 | |
| 4884 | /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on |
| 4885 | error, 2 on a toc GD type suitable for optimization, 3 on a toc LD |
| 4886 | type suitable for optimization, and 1 otherwise. */ |
| 4887 | |
| 4888 | static int |
| 4889 | get_tls_mask (char **tls_maskp, unsigned long *toc_symndx, |
| 4890 | Elf_Internal_Sym **locsymsp, |
| 4891 | const Elf_Internal_Rela *rel, bfd *ibfd) |
| 4892 | { |
| 4893 | unsigned long r_symndx; |
| 4894 | int next_r; |
| 4895 | struct elf_link_hash_entry *h; |
| 4896 | Elf_Internal_Sym *sym; |
| 4897 | asection *sec; |
| 4898 | bfd_vma off; |
| 4899 | |
| 4900 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 4901 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
| 4902 | return 0; |
| 4903 | |
| 4904 | if ((*tls_maskp != NULL && **tls_maskp != 0) |
| 4905 | || sec == NULL |
| 4906 | || ppc64_elf_section_data (sec)->t_symndx == NULL) |
| 4907 | return 1; |
| 4908 | |
| 4909 | /* Look inside a TOC section too. */ |
| 4910 | if (h != NULL) |
| 4911 | { |
| 4912 | BFD_ASSERT (h->root.type == bfd_link_hash_defined); |
| 4913 | off = h->root.u.def.value; |
| 4914 | } |
| 4915 | else |
| 4916 | off = sym->st_value; |
| 4917 | off += rel->r_addend; |
| 4918 | BFD_ASSERT (off % 8 == 0); |
| 4919 | r_symndx = ppc64_elf_section_data (sec)->t_symndx[off / 8]; |
| 4920 | next_r = ppc64_elf_section_data (sec)->t_symndx[off / 8 + 1]; |
| 4921 | if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) |
| 4922 | return 0; |
| 4923 | if (toc_symndx != NULL) |
| 4924 | *toc_symndx = r_symndx; |
| 4925 | if ((h == NULL |
| 4926 | || ((h->root.type == bfd_link_hash_defined |
| 4927 | || h->root.type == bfd_link_hash_defweak) |
| 4928 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) |
| 4929 | && (next_r == -1 || next_r == -2)) |
| 4930 | return 1 - next_r; |
| 4931 | return 1; |
| 4932 | } |
| 4933 | |
| 4934 | /* Adjust all global syms defined in opd sections. In gcc generated |
| 4935 | code these will already have been done, but I suppose we have to |
| 4936 | cater for all sorts of hand written assembly. */ |
| 4937 | |
| 4938 | static bfd_boolean |
| 4939 | adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED) |
| 4940 | { |
| 4941 | struct ppc_link_hash_entry *eh; |
| 4942 | asection *sym_sec; |
| 4943 | long *opd_adjust; |
| 4944 | |
| 4945 | if (h->root.type == bfd_link_hash_indirect) |
| 4946 | return TRUE; |
| 4947 | |
| 4948 | if (h->root.type == bfd_link_hash_warning) |
| 4949 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 4950 | |
| 4951 | if (h->root.type != bfd_link_hash_defined |
| 4952 | && h->root.type != bfd_link_hash_defweak) |
| 4953 | return TRUE; |
| 4954 | |
| 4955 | eh = (struct ppc_link_hash_entry *) h; |
| 4956 | if (eh->adjust_done) |
| 4957 | return TRUE; |
| 4958 | |
| 4959 | sym_sec = eh->elf.root.u.def.section; |
| 4960 | opd_adjust = get_opd_info (sym_sec); |
| 4961 | if (opd_adjust != NULL) |
| 4962 | { |
| 4963 | long adjust = opd_adjust[eh->elf.root.u.def.value / 24]; |
| 4964 | if (adjust == -1) |
| 4965 | { |
| 4966 | /* This entry has been deleted. */ |
| 4967 | eh->elf.root.u.def.value = 0; |
| 4968 | eh->elf.root.u.def.section = &bfd_abs_section; |
| 4969 | } |
| 4970 | else |
| 4971 | eh->elf.root.u.def.value += adjust; |
| 4972 | eh->adjust_done = 1; |
| 4973 | } |
| 4974 | return TRUE; |
| 4975 | } |
| 4976 | |
| 4977 | /* Remove unused Official Procedure Descriptor entries. Currently we |
| 4978 | only remove those associated with functions in discarded link-once |
| 4979 | sections, or weakly defined functions that have been overridden. It |
| 4980 | would be possible to remove many more entries for statically linked |
| 4981 | applications. */ |
| 4982 | |
| 4983 | bfd_boolean |
| 4984 | ppc64_elf_edit_opd (bfd *obfd, struct bfd_link_info *info) |
| 4985 | { |
| 4986 | bfd *ibfd; |
| 4987 | bfd_boolean some_edited = FALSE; |
| 4988 | |
| 4989 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
| 4990 | { |
| 4991 | asection *sec; |
| 4992 | Elf_Internal_Rela *relstart, *rel, *relend; |
| 4993 | Elf_Internal_Shdr *symtab_hdr; |
| 4994 | Elf_Internal_Sym *local_syms; |
| 4995 | struct elf_link_hash_entry **sym_hashes; |
| 4996 | bfd_vma offset; |
| 4997 | bfd_size_type amt; |
| 4998 | long *opd_adjust; |
| 4999 | bfd_boolean need_edit; |
| 5000 | |
| 5001 | sec = bfd_get_section_by_name (ibfd, ".opd"); |
| 5002 | if (sec == NULL) |
| 5003 | continue; |
| 5004 | |
| 5005 | amt = sec->size * sizeof (long) / 24; |
| 5006 | opd_adjust = get_opd_info (sec); |
| 5007 | if (opd_adjust == NULL) |
| 5008 | { |
| 5009 | /* Must be a ld -r link. ie. check_relocs hasn't been |
| 5010 | called. */ |
| 5011 | opd_adjust = bfd_zalloc (obfd, amt); |
| 5012 | ppc64_elf_section_data (sec)->opd.adjust = opd_adjust; |
| 5013 | } |
| 5014 | memset (opd_adjust, 0, amt); |
| 5015 | |
| 5016 | if (sec->output_section == bfd_abs_section_ptr) |
| 5017 | continue; |
| 5018 | |
| 5019 | /* Look through the section relocs. */ |
| 5020 | if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0) |
| 5021 | continue; |
| 5022 | |
| 5023 | local_syms = NULL; |
| 5024 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
| 5025 | sym_hashes = elf_sym_hashes (ibfd); |
| 5026 | |
| 5027 | /* Read the relocations. */ |
| 5028 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
| 5029 | info->keep_memory); |
| 5030 | if (relstart == NULL) |
| 5031 | return FALSE; |
| 5032 | |
| 5033 | /* First run through the relocs to check they are sane, and to |
| 5034 | determine whether we need to edit this opd section. */ |
| 5035 | need_edit = FALSE; |
| 5036 | offset = 0; |
| 5037 | relend = relstart + sec->reloc_count; |
| 5038 | for (rel = relstart; rel < relend; ) |
| 5039 | { |
| 5040 | enum elf_ppc64_reloc_type r_type; |
| 5041 | unsigned long r_symndx; |
| 5042 | asection *sym_sec; |
| 5043 | struct elf_link_hash_entry *h; |
| 5044 | Elf_Internal_Sym *sym; |
| 5045 | |
| 5046 | /* .opd contains a regular array of 24 byte entries. We're |
| 5047 | only interested in the reloc pointing to a function entry |
| 5048 | point. */ |
| 5049 | if (rel->r_offset != offset |
| 5050 | || rel + 1 >= relend |
| 5051 | || (rel + 1)->r_offset != offset + 8) |
| 5052 | { |
| 5053 | /* If someone messes with .opd alignment then after a |
| 5054 | "ld -r" we might have padding in the middle of .opd. |
| 5055 | Also, there's nothing to prevent someone putting |
| 5056 | something silly in .opd with the assembler. No .opd |
| 5057 | optimization for them! */ |
| 5058 | (*_bfd_error_handler) |
| 5059 | (_("%s: .opd is not a regular array of opd entries"), |
| 5060 | bfd_archive_filename (ibfd)); |
| 5061 | need_edit = FALSE; |
| 5062 | break; |
| 5063 | } |
| 5064 | |
| 5065 | if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64 |
| 5066 | || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC) |
| 5067 | { |
| 5068 | (*_bfd_error_handler) |
| 5069 | (_("%s: unexpected reloc type %u in .opd section"), |
| 5070 | bfd_archive_filename (ibfd), r_type); |
| 5071 | need_edit = FALSE; |
| 5072 | break; |
| 5073 | } |
| 5074 | |
| 5075 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 5076 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
| 5077 | r_symndx, ibfd)) |
| 5078 | goto error_ret; |
| 5079 | |
| 5080 | if (sym_sec == NULL || sym_sec->owner == NULL) |
| 5081 | { |
| 5082 | const char *sym_name; |
| 5083 | if (h != NULL) |
| 5084 | sym_name = h->root.root.string; |
| 5085 | else |
| 5086 | sym_name = bfd_elf_local_sym_name (ibfd, sym); |
| 5087 | |
| 5088 | (*_bfd_error_handler) |
| 5089 | (_("%s: undefined sym `%s' in .opd section"), |
| 5090 | bfd_archive_filename (ibfd), |
| 5091 | sym_name); |
| 5092 | need_edit = FALSE; |
| 5093 | break; |
| 5094 | } |
| 5095 | |
| 5096 | /* opd entries are always for functions defined in the |
| 5097 | current input bfd. If the symbol isn't defined in the |
| 5098 | input bfd, then we won't be using the function in this |
| 5099 | bfd; It must be defined in a linkonce section in another |
| 5100 | bfd, or is weak. It's also possible that we are |
| 5101 | discarding the function due to a linker script /DISCARD/, |
| 5102 | which we test for via the output_section. */ |
| 5103 | if (sym_sec->owner != ibfd |
| 5104 | || sym_sec->output_section == bfd_abs_section_ptr) |
| 5105 | need_edit = TRUE; |
| 5106 | |
| 5107 | offset += 24; |
| 5108 | rel += 2; |
| 5109 | /* Allow for the possibility of a reloc on the third word. */ |
| 5110 | if (rel < relend |
| 5111 | && rel->r_offset == offset - 8) |
| 5112 | rel += 1; |
| 5113 | } |
| 5114 | |
| 5115 | if (need_edit) |
| 5116 | { |
| 5117 | Elf_Internal_Rela *write_rel; |
| 5118 | bfd_byte *rptr, *wptr; |
| 5119 | bfd_boolean skip; |
| 5120 | |
| 5121 | /* This seems a waste of time as input .opd sections are all |
| 5122 | zeros as generated by gcc, but I suppose there's no reason |
| 5123 | this will always be so. We might start putting something in |
| 5124 | the third word of .opd entries. */ |
| 5125 | if ((sec->flags & SEC_IN_MEMORY) == 0) |
| 5126 | { |
| 5127 | bfd_byte *loc; |
| 5128 | if (!bfd_malloc_and_get_section (ibfd, sec, &loc)) |
| 5129 | { |
| 5130 | if (loc != NULL) |
| 5131 | free (loc); |
| 5132 | error_ret: |
| 5133 | if (local_syms != NULL |
| 5134 | && symtab_hdr->contents != (unsigned char *) local_syms) |
| 5135 | free (local_syms); |
| 5136 | if (elf_section_data (sec)->relocs != relstart) |
| 5137 | free (relstart); |
| 5138 | return FALSE; |
| 5139 | } |
| 5140 | sec->contents = loc; |
| 5141 | sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS); |
| 5142 | } |
| 5143 | |
| 5144 | elf_section_data (sec)->relocs = relstart; |
| 5145 | |
| 5146 | wptr = sec->contents; |
| 5147 | rptr = sec->contents; |
| 5148 | write_rel = relstart; |
| 5149 | skip = FALSE; |
| 5150 | offset = 0; |
| 5151 | for (rel = relstart; rel < relend; rel++) |
| 5152 | { |
| 5153 | unsigned long r_symndx; |
| 5154 | asection *sym_sec; |
| 5155 | struct elf_link_hash_entry *h; |
| 5156 | Elf_Internal_Sym *sym; |
| 5157 | |
| 5158 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 5159 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
| 5160 | r_symndx, ibfd)) |
| 5161 | goto error_ret; |
| 5162 | |
| 5163 | if (rel->r_offset == offset) |
| 5164 | { |
| 5165 | struct ppc_link_hash_entry *fdh = NULL; |
| 5166 | if (h != NULL |
| 5167 | && h->root.root.string[0] == '.') |
| 5168 | fdh = get_fdh ((struct ppc_link_hash_entry *) h, |
| 5169 | ppc_hash_table (info)); |
| 5170 | |
| 5171 | skip = (sym_sec->owner != ibfd |
| 5172 | || sym_sec->output_section == bfd_abs_section_ptr); |
| 5173 | if (skip) |
| 5174 | { |
| 5175 | if (fdh != NULL && sym_sec->owner == ibfd) |
| 5176 | { |
| 5177 | /* Arrange for the function descriptor sym |
| 5178 | to be dropped. */ |
| 5179 | fdh->elf.root.u.def.value = 0; |
| 5180 | fdh->elf.root.u.def.section = sym_sec; |
| 5181 | } |
| 5182 | opd_adjust[rel->r_offset / 24] = -1; |
| 5183 | } |
| 5184 | else |
| 5185 | { |
| 5186 | /* We'll be keeping this opd entry. */ |
| 5187 | |
| 5188 | if (fdh != NULL) |
| 5189 | { |
| 5190 | /* Redefine the function descriptor symbol to |
| 5191 | this location in the opd section. It is |
| 5192 | necessary to update the value here rather |
| 5193 | than using an array of adjustments as we do |
| 5194 | for local symbols, because various places |
| 5195 | in the generic ELF code use the value |
| 5196 | stored in u.def.value. */ |
| 5197 | fdh->elf.root.u.def.value = wptr - sec->contents; |
| 5198 | fdh->adjust_done = 1; |
| 5199 | } |
| 5200 | |
| 5201 | /* Local syms are a bit tricky. We could |
| 5202 | tweak them as they can be cached, but |
| 5203 | we'd need to look through the local syms |
| 5204 | for the function descriptor sym which we |
| 5205 | don't have at the moment. So keep an |
| 5206 | array of adjustments. */ |
| 5207 | opd_adjust[rel->r_offset / 24] = wptr - rptr; |
| 5208 | |
| 5209 | if (wptr != rptr) |
| 5210 | memcpy (wptr, rptr, 24); |
| 5211 | wptr += 24; |
| 5212 | } |
| 5213 | rptr += 24; |
| 5214 | offset += 24; |
| 5215 | } |
| 5216 | |
| 5217 | if (skip) |
| 5218 | { |
| 5219 | BFD_ASSERT (MUST_BE_DYN_RELOC (ELF64_R_TYPE (rel->r_info))); |
| 5220 | if (info->shared) |
| 5221 | { |
| 5222 | /* We won't be needing dynamic relocs here. */ |
| 5223 | struct ppc_dyn_relocs **pp; |
| 5224 | struct ppc_dyn_relocs *p; |
| 5225 | |
| 5226 | if (h != NULL) |
| 5227 | pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
| 5228 | else if (sym_sec != NULL) |
| 5229 | pp = ((struct ppc_dyn_relocs **) |
| 5230 | &elf_section_data (sym_sec)->local_dynrel); |
| 5231 | else |
| 5232 | pp = ((struct ppc_dyn_relocs **) |
| 5233 | &elf_section_data (sec)->local_dynrel); |
| 5234 | while ((p = *pp) != NULL) |
| 5235 | { |
| 5236 | if (p->sec == sec) |
| 5237 | { |
| 5238 | p->count -= 1; |
| 5239 | if (p->count == 0) |
| 5240 | *pp = p->next; |
| 5241 | break; |
| 5242 | } |
| 5243 | pp = &p->next; |
| 5244 | } |
| 5245 | } |
| 5246 | } |
| 5247 | else |
| 5248 | { |
| 5249 | /* We need to adjust any reloc offsets to point to the |
| 5250 | new opd entries. While we're at it, we may as well |
| 5251 | remove redundant relocs. */ |
| 5252 | rel->r_offset += wptr - rptr; |
| 5253 | if (write_rel != rel) |
| 5254 | memcpy (write_rel, rel, sizeof (*rel)); |
| 5255 | ++write_rel; |
| 5256 | } |
| 5257 | } |
| 5258 | |
| 5259 | sec->size = wptr - sec->contents; |
| 5260 | sec->reloc_count = write_rel - relstart; |
| 5261 | /* Fudge the size too, as this is used later in |
| 5262 | elf_bfd_final_link if we are emitting relocs. */ |
| 5263 | elf_section_data (sec)->rel_hdr.sh_size |
| 5264 | = sec->reloc_count * elf_section_data (sec)->rel_hdr.sh_entsize; |
| 5265 | BFD_ASSERT (elf_section_data (sec)->rel_hdr2 == NULL); |
| 5266 | some_edited = TRUE; |
| 5267 | } |
| 5268 | else if (elf_section_data (sec)->relocs != relstart) |
| 5269 | free (relstart); |
| 5270 | |
| 5271 | if (local_syms != NULL |
| 5272 | && symtab_hdr->contents != (unsigned char *) local_syms) |
| 5273 | { |
| 5274 | if (!info->keep_memory) |
| 5275 | free (local_syms); |
| 5276 | else |
| 5277 | symtab_hdr->contents = (unsigned char *) local_syms; |
| 5278 | } |
| 5279 | } |
| 5280 | |
| 5281 | if (some_edited) |
| 5282 | elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL); |
| 5283 | |
| 5284 | return TRUE; |
| 5285 | } |
| 5286 | |
| 5287 | /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */ |
| 5288 | |
| 5289 | asection * |
| 5290 | ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) |
| 5291 | { |
| 5292 | struct ppc_link_hash_table *htab; |
| 5293 | |
| 5294 | htab = ppc_hash_table (info); |
| 5295 | if (htab->tls_get_addr != NULL) |
| 5296 | { |
| 5297 | struct elf_link_hash_entry *h = htab->tls_get_addr; |
| 5298 | |
| 5299 | while (h->root.type == bfd_link_hash_indirect |
| 5300 | || h->root.type == bfd_link_hash_warning) |
| 5301 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 5302 | |
| 5303 | htab->tls_get_addr = h; |
| 5304 | } |
| 5305 | |
| 5306 | return _bfd_elf_tls_setup (obfd, info); |
| 5307 | } |
| 5308 | |
| 5309 | /* Run through all the TLS relocs looking for optimization |
| 5310 | opportunities. The linker has been hacked (see ppc64elf.em) to do |
| 5311 | a preliminary section layout so that we know the TLS segment |
| 5312 | offsets. We can't optimize earlier because some optimizations need |
| 5313 | to know the tp offset, and we need to optimize before allocating |
| 5314 | dynamic relocations. */ |
| 5315 | |
| 5316 | bfd_boolean |
| 5317 | ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) |
| 5318 | { |
| 5319 | bfd *ibfd; |
| 5320 | asection *sec; |
| 5321 | struct ppc_link_hash_table *htab; |
| 5322 | |
| 5323 | if (info->relocatable || info->shared) |
| 5324 | return TRUE; |
| 5325 | |
| 5326 | htab = ppc_hash_table (info); |
| 5327 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
| 5328 | { |
| 5329 | Elf_Internal_Sym *locsyms = NULL; |
| 5330 | |
| 5331 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
| 5332 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) |
| 5333 | { |
| 5334 | Elf_Internal_Rela *relstart, *rel, *relend; |
| 5335 | int expecting_tls_get_addr; |
| 5336 | |
| 5337 | /* Read the relocations. */ |
| 5338 | relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, |
| 5339 | info->keep_memory); |
| 5340 | if (relstart == NULL) |
| 5341 | return FALSE; |
| 5342 | |
| 5343 | expecting_tls_get_addr = 0; |
| 5344 | relend = relstart + sec->reloc_count; |
| 5345 | for (rel = relstart; rel < relend; rel++) |
| 5346 | { |
| 5347 | enum elf_ppc64_reloc_type r_type; |
| 5348 | unsigned long r_symndx; |
| 5349 | struct elf_link_hash_entry *h; |
| 5350 | Elf_Internal_Sym *sym; |
| 5351 | asection *sym_sec; |
| 5352 | char *tls_mask; |
| 5353 | char tls_set, tls_clear, tls_type = 0; |
| 5354 | bfd_vma value; |
| 5355 | bfd_boolean ok_tprel, is_local; |
| 5356 | |
| 5357 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 5358 | if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms, |
| 5359 | r_symndx, ibfd)) |
| 5360 | { |
| 5361 | err_free_rel: |
| 5362 | if (elf_section_data (sec)->relocs != relstart) |
| 5363 | free (relstart); |
| 5364 | if (locsyms != NULL |
| 5365 | && (elf_tdata (ibfd)->symtab_hdr.contents |
| 5366 | != (unsigned char *) locsyms)) |
| 5367 | free (locsyms); |
| 5368 | return FALSE; |
| 5369 | } |
| 5370 | |
| 5371 | if (h != NULL) |
| 5372 | { |
| 5373 | if (h->root.type != bfd_link_hash_defined |
| 5374 | && h->root.type != bfd_link_hash_defweak) |
| 5375 | continue; |
| 5376 | value = h->root.u.def.value; |
| 5377 | } |
| 5378 | else |
| 5379 | /* Symbols referenced by TLS relocs must be of type |
| 5380 | STT_TLS. So no need for .opd local sym adjust. */ |
| 5381 | value = sym->st_value; |
| 5382 | |
| 5383 | ok_tprel = FALSE; |
| 5384 | is_local = FALSE; |
| 5385 | if (h == NULL |
| 5386 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) |
| 5387 | { |
| 5388 | is_local = TRUE; |
| 5389 | value += sym_sec->output_offset; |
| 5390 | value += sym_sec->output_section->vma; |
| 5391 | value -= htab->elf.tls_sec->vma; |
| 5392 | ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31) |
| 5393 | < (bfd_vma) 1 << 32); |
| 5394 | } |
| 5395 | |
| 5396 | r_type = ELF64_R_TYPE (rel->r_info); |
| 5397 | switch (r_type) |
| 5398 | { |
| 5399 | case R_PPC64_GOT_TLSLD16: |
| 5400 | case R_PPC64_GOT_TLSLD16_LO: |
| 5401 | case R_PPC64_GOT_TLSLD16_HI: |
| 5402 | case R_PPC64_GOT_TLSLD16_HA: |
| 5403 | /* These relocs should never be against a symbol |
| 5404 | defined in a shared lib. Leave them alone if |
| 5405 | that turns out to be the case. */ |
| 5406 | ppc64_tlsld_got (ibfd)->refcount -= 1; |
| 5407 | if (!is_local) |
| 5408 | continue; |
| 5409 | |
| 5410 | /* LD -> LE */ |
| 5411 | tls_set = 0; |
| 5412 | tls_clear = TLS_LD; |
| 5413 | tls_type = TLS_TLS | TLS_LD; |
| 5414 | expecting_tls_get_addr = 1; |
| 5415 | break; |
| 5416 | |
| 5417 | case R_PPC64_GOT_TLSGD16: |
| 5418 | case R_PPC64_GOT_TLSGD16_LO: |
| 5419 | case R_PPC64_GOT_TLSGD16_HI: |
| 5420 | case R_PPC64_GOT_TLSGD16_HA: |
| 5421 | if (ok_tprel) |
| 5422 | /* GD -> LE */ |
| 5423 | tls_set = 0; |
| 5424 | else |
| 5425 | /* GD -> IE */ |
| 5426 | tls_set = TLS_TLS | TLS_TPRELGD; |
| 5427 | tls_clear = TLS_GD; |
| 5428 | tls_type = TLS_TLS | TLS_GD; |
| 5429 | expecting_tls_get_addr = 1; |
| 5430 | break; |
| 5431 | |
| 5432 | case R_PPC64_GOT_TPREL16_DS: |
| 5433 | case R_PPC64_GOT_TPREL16_LO_DS: |
| 5434 | case R_PPC64_GOT_TPREL16_HI: |
| 5435 | case R_PPC64_GOT_TPREL16_HA: |
| 5436 | expecting_tls_get_addr = 0; |
| 5437 | if (ok_tprel) |
| 5438 | { |
| 5439 | /* IE -> LE */ |
| 5440 | tls_set = 0; |
| 5441 | tls_clear = TLS_TPREL; |
| 5442 | tls_type = TLS_TLS | TLS_TPREL; |
| 5443 | break; |
| 5444 | } |
| 5445 | else |
| 5446 | continue; |
| 5447 | |
| 5448 | case R_PPC64_REL14: |
| 5449 | case R_PPC64_REL14_BRTAKEN: |
| 5450 | case R_PPC64_REL14_BRNTAKEN: |
| 5451 | case R_PPC64_REL24: |
| 5452 | if (h != NULL |
| 5453 | && h == htab->tls_get_addr) |
| 5454 | { |
| 5455 | if (!expecting_tls_get_addr |
| 5456 | && rel != relstart |
| 5457 | && ((ELF64_R_TYPE (rel[-1].r_info) |
| 5458 | == R_PPC64_TOC16) |
| 5459 | || (ELF64_R_TYPE (rel[-1].r_info) |
| 5460 | == R_PPC64_TOC16_LO))) |
| 5461 | { |
| 5462 | /* Check for toc tls entries. */ |
| 5463 | char *toc_tls; |
| 5464 | int retval; |
| 5465 | |
| 5466 | retval = get_tls_mask (&toc_tls, NULL, &locsyms, |
| 5467 | rel - 1, ibfd); |
| 5468 | if (retval == 0) |
| 5469 | goto err_free_rel; |
| 5470 | if (toc_tls != NULL) |
| 5471 | expecting_tls_get_addr = retval > 1; |
| 5472 | } |
| 5473 | |
| 5474 | if (expecting_tls_get_addr) |
| 5475 | { |
| 5476 | struct plt_entry *ent; |
| 5477 | for (ent = h->plt.plist; ent; ent = ent->next) |
| 5478 | if (ent->addend == 0) |
| 5479 | { |
| 5480 | if (ent->plt.refcount > 0) |
| 5481 | ent->plt.refcount -= 1; |
| 5482 | break; |
| 5483 | } |
| 5484 | } |
| 5485 | } |
| 5486 | expecting_tls_get_addr = 0; |
| 5487 | continue; |
| 5488 | |
| 5489 | case R_PPC64_TPREL64: |
| 5490 | expecting_tls_get_addr = 0; |
| 5491 | if (ok_tprel) |
| 5492 | { |
| 5493 | /* IE -> LE */ |
| 5494 | tls_set = TLS_EXPLICIT; |
| 5495 | tls_clear = TLS_TPREL; |
| 5496 | break; |
| 5497 | } |
| 5498 | else |
| 5499 | continue; |
| 5500 | |
| 5501 | case R_PPC64_DTPMOD64: |
| 5502 | expecting_tls_get_addr = 0; |
| 5503 | if (rel + 1 < relend |
| 5504 | && (rel[1].r_info |
| 5505 | == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)) |
| 5506 | && rel[1].r_offset == rel->r_offset + 8) |
| 5507 | { |
| 5508 | if (ok_tprel) |
| 5509 | /* GD -> LE */ |
| 5510 | tls_set = TLS_EXPLICIT | TLS_GD; |
| 5511 | else |
| 5512 | /* GD -> IE */ |
| 5513 | tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD; |
| 5514 | tls_clear = TLS_GD; |
| 5515 | } |
| 5516 | else |
| 5517 | { |
| 5518 | if (!is_local) |
| 5519 | continue; |
| 5520 | |
| 5521 | /* LD -> LE */ |
| 5522 | tls_set = TLS_EXPLICIT; |
| 5523 | tls_clear = TLS_LD; |
| 5524 | } |
| 5525 | break; |
| 5526 | |
| 5527 | default: |
| 5528 | expecting_tls_get_addr = 0; |
| 5529 | continue; |
| 5530 | } |
| 5531 | |
| 5532 | if ((tls_set & TLS_EXPLICIT) == 0) |
| 5533 | { |
| 5534 | struct got_entry *ent; |
| 5535 | |
| 5536 | /* Adjust got entry for this reloc. */ |
| 5537 | if (h != NULL) |
| 5538 | ent = h->got.glist; |
| 5539 | else |
| 5540 | ent = elf_local_got_ents (ibfd)[r_symndx]; |
| 5541 | |
| 5542 | for (; ent != NULL; ent = ent->next) |
| 5543 | if (ent->addend == rel->r_addend |
| 5544 | && ent->owner == ibfd |
| 5545 | && ent->tls_type == tls_type) |
| 5546 | break; |
| 5547 | if (ent == NULL) |
| 5548 | abort (); |
| 5549 | |
| 5550 | if (tls_set == 0) |
| 5551 | { |
| 5552 | /* We managed to get rid of a got entry. */ |
| 5553 | if (ent->got.refcount > 0) |
| 5554 | ent->got.refcount -= 1; |
| 5555 | } |
| 5556 | } |
| 5557 | else if (h != NULL) |
| 5558 | { |
| 5559 | struct ppc_link_hash_entry * eh; |
| 5560 | struct ppc_dyn_relocs **pp; |
| 5561 | struct ppc_dyn_relocs *p; |
| 5562 | |
| 5563 | /* Adjust dynamic relocs. */ |
| 5564 | eh = (struct ppc_link_hash_entry *) h; |
| 5565 | for (pp = &eh->dyn_relocs; |
| 5566 | (p = *pp) != NULL; |
| 5567 | pp = &p->next) |
| 5568 | if (p->sec == sec) |
| 5569 | { |
| 5570 | /* If we got rid of a DTPMOD/DTPREL reloc |
| 5571 | pair then we'll lose one or two dyn |
| 5572 | relocs. */ |
| 5573 | if (tls_set == (TLS_EXPLICIT | TLS_GD)) |
| 5574 | p->count -= 1; |
| 5575 | p->count -= 1; |
| 5576 | if (p->count == 0) |
| 5577 | *pp = p->next; |
| 5578 | break; |
| 5579 | } |
| 5580 | } |
| 5581 | |
| 5582 | *tls_mask |= tls_set; |
| 5583 | *tls_mask &= ~tls_clear; |
| 5584 | } |
| 5585 | |
| 5586 | if (elf_section_data (sec)->relocs != relstart) |
| 5587 | free (relstart); |
| 5588 | } |
| 5589 | |
| 5590 | if (locsyms != NULL |
| 5591 | && (elf_tdata (ibfd)->symtab_hdr.contents |
| 5592 | != (unsigned char *) locsyms)) |
| 5593 | { |
| 5594 | if (!info->keep_memory) |
| 5595 | free (locsyms); |
| 5596 | else |
| 5597 | elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms; |
| 5598 | } |
| 5599 | } |
| 5600 | return TRUE; |
| 5601 | } |
| 5602 | |
| 5603 | /* Allocate space in .plt, .got and associated reloc sections for |
| 5604 | dynamic relocs. */ |
| 5605 | |
| 5606 | static bfd_boolean |
| 5607 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
| 5608 | { |
| 5609 | struct bfd_link_info *info; |
| 5610 | struct ppc_link_hash_table *htab; |
| 5611 | asection *s; |
| 5612 | struct ppc_link_hash_entry *eh; |
| 5613 | struct ppc_dyn_relocs *p; |
| 5614 | struct got_entry *gent; |
| 5615 | |
| 5616 | if (h->root.type == bfd_link_hash_indirect) |
| 5617 | return TRUE; |
| 5618 | |
| 5619 | if (h->root.type == bfd_link_hash_warning) |
| 5620 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 5621 | |
| 5622 | info = (struct bfd_link_info *) inf; |
| 5623 | htab = ppc_hash_table (info); |
| 5624 | |
| 5625 | if (htab->elf.dynamic_sections_created |
| 5626 | && h->dynindx != -1 |
| 5627 | && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)) |
| 5628 | { |
| 5629 | struct plt_entry *pent; |
| 5630 | bfd_boolean doneone = FALSE; |
| 5631 | for (pent = h->plt.plist; pent != NULL; pent = pent->next) |
| 5632 | if (pent->plt.refcount > 0) |
| 5633 | { |
| 5634 | BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor); |
| 5635 | |
| 5636 | /* If this is the first .plt entry, make room for the special |
| 5637 | first entry. */ |
| 5638 | s = htab->plt; |
| 5639 | if (s->size == 0) |
| 5640 | s->size += PLT_INITIAL_ENTRY_SIZE; |
| 5641 | |
| 5642 | pent->plt.offset = s->size; |
| 5643 | |
| 5644 | /* Make room for this entry. */ |
| 5645 | s->size += PLT_ENTRY_SIZE; |
| 5646 | |
| 5647 | /* Make room for the .glink code. */ |
| 5648 | s = htab->glink; |
| 5649 | if (s->size == 0) |
| 5650 | s->size += GLINK_CALL_STUB_SIZE; |
| 5651 | /* We need bigger stubs past index 32767. */ |
| 5652 | if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4) |
| 5653 | s->size += 4; |
| 5654 | s->size += 2*4; |
| 5655 | |
| 5656 | /* We also need to make an entry in the .rela.plt section. */ |
| 5657 | s = htab->relplt; |
| 5658 | s->size += sizeof (Elf64_External_Rela); |
| 5659 | doneone = TRUE; |
| 5660 | } |
| 5661 | else |
| 5662 | pent->plt.offset = (bfd_vma) -1; |
| 5663 | if (!doneone) |
| 5664 | { |
| 5665 | h->plt.plist = NULL; |
| 5666 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
| 5667 | } |
| 5668 | } |
| 5669 | else |
| 5670 | { |
| 5671 | h->plt.plist = NULL; |
| 5672 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
| 5673 | } |
| 5674 | |
| 5675 | eh = (struct ppc_link_hash_entry *) h; |
| 5676 | /* Run through the TLS GD got entries first if we're changing them |
| 5677 | to TPREL. */ |
| 5678 | if ((eh->tls_mask & TLS_TPRELGD) != 0) |
| 5679 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
| 5680 | if (gent->got.refcount > 0 |
| 5681 | && (gent->tls_type & TLS_GD) != 0) |
| 5682 | { |
| 5683 | /* This was a GD entry that has been converted to TPREL. If |
| 5684 | there happens to be a TPREL entry we can use that one. */ |
| 5685 | struct got_entry *ent; |
| 5686 | for (ent = h->got.glist; ent != NULL; ent = ent->next) |
| 5687 | if (ent->got.refcount > 0 |
| 5688 | && (ent->tls_type & TLS_TPREL) != 0 |
| 5689 | && ent->addend == gent->addend |
| 5690 | && ent->owner == gent->owner) |
| 5691 | { |
| 5692 | gent->got.refcount = 0; |
| 5693 | break; |
| 5694 | } |
| 5695 | |
| 5696 | /* If not, then we'll be using our own TPREL entry. */ |
| 5697 | if (gent->got.refcount != 0) |
| 5698 | gent->tls_type = TLS_TLS | TLS_TPREL; |
| 5699 | } |
| 5700 | |
| 5701 | for (gent = h->got.glist; gent != NULL; gent = gent->next) |
| 5702 | if (gent->got.refcount > 0) |
| 5703 | { |
| 5704 | bfd_boolean dyn; |
| 5705 | |
| 5706 | /* Make sure this symbol is output as a dynamic symbol. |
| 5707 | Undefined weak syms won't yet be marked as dynamic, |
| 5708 | nor will all TLS symbols. */ |
| 5709 | if (h->dynindx == -1 |
| 5710 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) |
| 5711 | { |
| 5712 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 5713 | return FALSE; |
| 5714 | } |
| 5715 | |
| 5716 | if ((gent->tls_type & TLS_LD) != 0 |
| 5717 | && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) |
| 5718 | { |
| 5719 | gent->got.offset = ppc64_tlsld_got (gent->owner)->offset; |
| 5720 | continue; |
| 5721 | } |
| 5722 | |
| 5723 | s = ppc64_elf_tdata (gent->owner)->got; |
| 5724 | gent->got.offset = s->size; |
| 5725 | s->size |
| 5726 | += (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8; |
| 5727 | dyn = htab->elf.dynamic_sections_created; |
| 5728 | if ((info->shared |
| 5729 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) |
| 5730 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
| 5731 | || h->root.type != bfd_link_hash_undefweak)) |
| 5732 | ppc64_elf_tdata (gent->owner)->relgot->size |
| 5733 | += (gent->tls_type & eh->tls_mask & TLS_GD |
| 5734 | ? 2 * sizeof (Elf64_External_Rela) |
| 5735 | : sizeof (Elf64_External_Rela)); |
| 5736 | } |
| 5737 | else |
| 5738 | gent->got.offset = (bfd_vma) -1; |
| 5739 | |
| 5740 | if (eh->dyn_relocs == NULL) |
| 5741 | return TRUE; |
| 5742 | |
| 5743 | /* In the shared -Bsymbolic case, discard space allocated for |
| 5744 | dynamic pc-relative relocs against symbols which turn out to be |
| 5745 | defined in regular objects. For the normal shared case, discard |
| 5746 | space for relocs that have become local due to symbol visibility |
| 5747 | changes. */ |
| 5748 | |
| 5749 | if (info->shared) |
| 5750 | { |
| 5751 | /* Relocs that use pc_count are those that appear on a call insn, |
| 5752 | or certain REL relocs (see MUST_BE_DYN_RELOC) that can be |
| 5753 | generated via assembly. We want calls to protected symbols to |
| 5754 | resolve directly to the function rather than going via the plt. |
| 5755 | If people want function pointer comparisons to work as expected |
| 5756 | then they should avoid writing weird assembly. */ |
| 5757 | if (SYMBOL_CALLS_LOCAL (info, h)) |
| 5758 | { |
| 5759 | struct ppc_dyn_relocs **pp; |
| 5760 | |
| 5761 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) |
| 5762 | { |
| 5763 | p->count -= p->pc_count; |
| 5764 | p->pc_count = 0; |
| 5765 | if (p->count == 0) |
| 5766 | *pp = p->next; |
| 5767 | else |
| 5768 | pp = &p->next; |
| 5769 | } |
| 5770 | } |
| 5771 | |
| 5772 | /* Also discard relocs on undefined weak syms with non-default |
| 5773 | visibility. */ |
| 5774 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
| 5775 | && h->root.type == bfd_link_hash_undefweak) |
| 5776 | eh->dyn_relocs = NULL; |
| 5777 | } |
| 5778 | else if (ELIMINATE_COPY_RELOCS) |
| 5779 | { |
| 5780 | /* For the non-shared case, discard space for relocs against |
| 5781 | symbols which turn out to need copy relocs or are not |
| 5782 | dynamic. */ |
| 5783 | |
| 5784 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 |
| 5785 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
| 5786 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
| 5787 | { |
| 5788 | /* Make sure this symbol is output as a dynamic symbol. |
| 5789 | Undefined weak syms won't yet be marked as dynamic. */ |
| 5790 | if (h->dynindx == -1 |
| 5791 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) |
| 5792 | { |
| 5793 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 5794 | return FALSE; |
| 5795 | } |
| 5796 | |
| 5797 | /* If that succeeded, we know we'll be keeping all the |
| 5798 | relocs. */ |
| 5799 | if (h->dynindx != -1) |
| 5800 | goto keep; |
| 5801 | } |
| 5802 | |
| 5803 | eh->dyn_relocs = NULL; |
| 5804 | |
| 5805 | keep: ; |
| 5806 | } |
| 5807 | |
| 5808 | /* Finally, allocate space. */ |
| 5809 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
| 5810 | { |
| 5811 | asection *sreloc = elf_section_data (p->sec)->sreloc; |
| 5812 | sreloc->size += p->count * sizeof (Elf64_External_Rela); |
| 5813 | } |
| 5814 | |
| 5815 | return TRUE; |
| 5816 | } |
| 5817 | |
| 5818 | /* Find any dynamic relocs that apply to read-only sections. */ |
| 5819 | |
| 5820 | static bfd_boolean |
| 5821 | readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
| 5822 | { |
| 5823 | struct ppc_link_hash_entry *eh; |
| 5824 | struct ppc_dyn_relocs *p; |
| 5825 | |
| 5826 | if (h->root.type == bfd_link_hash_warning) |
| 5827 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 5828 | |
| 5829 | eh = (struct ppc_link_hash_entry *) h; |
| 5830 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
| 5831 | { |
| 5832 | asection *s = p->sec->output_section; |
| 5833 | |
| 5834 | if (s != NULL && (s->flags & SEC_READONLY) != 0) |
| 5835 | { |
| 5836 | struct bfd_link_info *info = inf; |
| 5837 | |
| 5838 | info->flags |= DF_TEXTREL; |
| 5839 | |
| 5840 | /* Not an error, just cut short the traversal. */ |
| 5841 | return FALSE; |
| 5842 | } |
| 5843 | } |
| 5844 | return TRUE; |
| 5845 | } |
| 5846 | |
| 5847 | /* Set the sizes of the dynamic sections. */ |
| 5848 | |
| 5849 | static bfd_boolean |
| 5850 | ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
| 5851 | struct bfd_link_info *info) |
| 5852 | { |
| 5853 | struct ppc_link_hash_table *htab; |
| 5854 | bfd *dynobj; |
| 5855 | asection *s; |
| 5856 | bfd_boolean relocs; |
| 5857 | bfd *ibfd; |
| 5858 | |
| 5859 | htab = ppc_hash_table (info); |
| 5860 | dynobj = htab->elf.dynobj; |
| 5861 | if (dynobj == NULL) |
| 5862 | abort (); |
| 5863 | |
| 5864 | if (htab->elf.dynamic_sections_created) |
| 5865 | { |
| 5866 | /* Set the contents of the .interp section to the interpreter. */ |
| 5867 | if (info->executable) |
| 5868 | { |
| 5869 | s = bfd_get_section_by_name (dynobj, ".interp"); |
| 5870 | if (s == NULL) |
| 5871 | abort (); |
| 5872 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
| 5873 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
| 5874 | } |
| 5875 | } |
| 5876 | |
| 5877 | /* Set up .got offsets for local syms, and space for local dynamic |
| 5878 | relocs. */ |
| 5879 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
| 5880 | { |
| 5881 | struct got_entry **lgot_ents; |
| 5882 | struct got_entry **end_lgot_ents; |
| 5883 | char *lgot_masks; |
| 5884 | bfd_size_type locsymcount; |
| 5885 | Elf_Internal_Shdr *symtab_hdr; |
| 5886 | asection *srel; |
| 5887 | |
| 5888 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) |
| 5889 | continue; |
| 5890 | |
| 5891 | if (ppc64_tlsld_got (ibfd)->refcount > 0) |
| 5892 | { |
| 5893 | s = ppc64_elf_tdata (ibfd)->got; |
| 5894 | ppc64_tlsld_got (ibfd)->offset = s->size; |
| 5895 | s->size += 16; |
| 5896 | if (info->shared) |
| 5897 | { |
| 5898 | srel = ppc64_elf_tdata (ibfd)->relgot; |
| 5899 | srel->size += sizeof (Elf64_External_Rela); |
| 5900 | } |
| 5901 | } |
| 5902 | else |
| 5903 | ppc64_tlsld_got (ibfd)->offset = (bfd_vma) -1; |
| 5904 | |
| 5905 | for (s = ibfd->sections; s != NULL; s = s->next) |
| 5906 | { |
| 5907 | struct ppc_dyn_relocs *p; |
| 5908 | |
| 5909 | for (p = *((struct ppc_dyn_relocs **) |
| 5910 | &elf_section_data (s)->local_dynrel); |
| 5911 | p != NULL; |
| 5912 | p = p->next) |
| 5913 | { |
| 5914 | if (!bfd_is_abs_section (p->sec) |
| 5915 | && bfd_is_abs_section (p->sec->output_section)) |
| 5916 | { |
| 5917 | /* Input section has been discarded, either because |
| 5918 | it is a copy of a linkonce section or due to |
| 5919 | linker script /DISCARD/, so we'll be discarding |
| 5920 | the relocs too. */ |
| 5921 | } |
| 5922 | else if (p->count != 0) |
| 5923 | { |
| 5924 | srel = elf_section_data (p->sec)->sreloc; |
| 5925 | srel->size += p->count * sizeof (Elf64_External_Rela); |
| 5926 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
| 5927 | info->flags |= DF_TEXTREL; |
| 5928 | } |
| 5929 | } |
| 5930 | } |
| 5931 | |
| 5932 | lgot_ents = elf_local_got_ents (ibfd); |
| 5933 | if (!lgot_ents) |
| 5934 | continue; |
| 5935 | |
| 5936 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
| 5937 | locsymcount = symtab_hdr->sh_info; |
| 5938 | end_lgot_ents = lgot_ents + locsymcount; |
| 5939 | lgot_masks = (char *) end_lgot_ents; |
| 5940 | s = ppc64_elf_tdata (ibfd)->got; |
| 5941 | srel = ppc64_elf_tdata (ibfd)->relgot; |
| 5942 | for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks) |
| 5943 | { |
| 5944 | struct got_entry *ent; |
| 5945 | |
| 5946 | for (ent = *lgot_ents; ent != NULL; ent = ent->next) |
| 5947 | if (ent->got.refcount > 0) |
| 5948 | { |
| 5949 | if ((ent->tls_type & *lgot_masks & TLS_LD) != 0) |
| 5950 | { |
| 5951 | if (ppc64_tlsld_got (ibfd)->offset == (bfd_vma) -1) |
| 5952 | { |
| 5953 | ppc64_tlsld_got (ibfd)->offset = s->size; |
| 5954 | s->size += 16; |
| 5955 | if (info->shared) |
| 5956 | srel->size += sizeof (Elf64_External_Rela); |
| 5957 | } |
| 5958 | ent->got.offset = ppc64_tlsld_got (ibfd)->offset; |
| 5959 | } |
| 5960 | else |
| 5961 | { |
| 5962 | ent->got.offset = s->size; |
| 5963 | if ((ent->tls_type & *lgot_masks & TLS_GD) != 0) |
| 5964 | { |
| 5965 | s->size += 16; |
| 5966 | if (info->shared) |
| 5967 | srel->size += 2 * sizeof (Elf64_External_Rela); |
| 5968 | } |
| 5969 | else |
| 5970 | { |
| 5971 | s->size += 8; |
| 5972 | if (info->shared) |
| 5973 | srel->size += sizeof (Elf64_External_Rela); |
| 5974 | } |
| 5975 | } |
| 5976 | } |
| 5977 | else |
| 5978 | ent->got.offset = (bfd_vma) -1; |
| 5979 | } |
| 5980 | } |
| 5981 | |
| 5982 | /* Allocate global sym .plt and .got entries, and space for global |
| 5983 | sym dynamic relocs. */ |
| 5984 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); |
| 5985 | |
| 5986 | /* We now have determined the sizes of the various dynamic sections. |
| 5987 | Allocate memory for them. */ |
| 5988 | relocs = FALSE; |
| 5989 | for (s = dynobj->sections; s != NULL; s = s->next) |
| 5990 | { |
| 5991 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
| 5992 | continue; |
| 5993 | |
| 5994 | if (s == htab->brlt || s == htab->relbrlt) |
| 5995 | /* These haven't been allocated yet; don't strip. */ |
| 5996 | continue; |
| 5997 | else if (s == htab->got |
| 5998 | || s == htab->plt |
| 5999 | || s == htab->glink) |
| 6000 | { |
| 6001 | /* Strip this section if we don't need it; see the |
| 6002 | comment below. */ |
| 6003 | } |
| 6004 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
| 6005 | { |
| 6006 | if (s->size == 0) |
| 6007 | { |
| 6008 | /* If we don't need this section, strip it from the |
| 6009 | output file. This is mostly to handle .rela.bss and |
| 6010 | .rela.plt. We must create both sections in |
| 6011 | create_dynamic_sections, because they must be created |
| 6012 | before the linker maps input sections to output |
| 6013 | sections. The linker does that before |
| 6014 | adjust_dynamic_symbol is called, and it is that |
| 6015 | function which decides whether anything needs to go |
| 6016 | into these sections. */ |
| 6017 | } |
| 6018 | else |
| 6019 | { |
| 6020 | if (s != htab->relplt) |
| 6021 | relocs = TRUE; |
| 6022 | |
| 6023 | /* We use the reloc_count field as a counter if we need |
| 6024 | to copy relocs into the output file. */ |
| 6025 | s->reloc_count = 0; |
| 6026 | } |
| 6027 | } |
| 6028 | else |
| 6029 | { |
| 6030 | /* It's not one of our sections, so don't allocate space. */ |
| 6031 | continue; |
| 6032 | } |
| 6033 | |
| 6034 | if (s->size == 0) |
| 6035 | { |
| 6036 | _bfd_strip_section_from_output (info, s); |
| 6037 | continue; |
| 6038 | } |
| 6039 | |
| 6040 | /* .plt is in the bss section. We don't initialise it. */ |
| 6041 | if (s == htab->plt) |
| 6042 | continue; |
| 6043 | |
| 6044 | /* Allocate memory for the section contents. We use bfd_zalloc |
| 6045 | here in case unused entries are not reclaimed before the |
| 6046 | section's contents are written out. This should not happen, |
| 6047 | but this way if it does we get a R_PPC64_NONE reloc in .rela |
| 6048 | sections instead of garbage. |
| 6049 | We also rely on the section contents being zero when writing |
| 6050 | the GOT. */ |
| 6051 | s->contents = bfd_zalloc (dynobj, s->size); |
| 6052 | if (s->contents == NULL) |
| 6053 | return FALSE; |
| 6054 | } |
| 6055 | |
| 6056 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
| 6057 | { |
| 6058 | s = ppc64_elf_tdata (ibfd)->got; |
| 6059 | if (s != NULL && s != htab->got) |
| 6060 | { |
| 6061 | if (s->size == 0) |
| 6062 | _bfd_strip_section_from_output (info, s); |
| 6063 | else |
| 6064 | { |
| 6065 | s->contents = bfd_zalloc (ibfd, s->size); |
| 6066 | if (s->contents == NULL) |
| 6067 | return FALSE; |
| 6068 | } |
| 6069 | } |
| 6070 | s = ppc64_elf_tdata (ibfd)->relgot; |
| 6071 | if (s != NULL) |
| 6072 | { |
| 6073 | if (s->size == 0) |
| 6074 | _bfd_strip_section_from_output (info, s); |
| 6075 | else |
| 6076 | { |
| 6077 | s->contents = bfd_zalloc (ibfd, s->size); |
| 6078 | if (s->contents == NULL) |
| 6079 | return FALSE; |
| 6080 | relocs = TRUE; |
| 6081 | s->reloc_count = 0; |
| 6082 | } |
| 6083 | } |
| 6084 | } |
| 6085 | |
| 6086 | if (htab->elf.dynamic_sections_created) |
| 6087 | { |
| 6088 | /* Add some entries to the .dynamic section. We fill in the |
| 6089 | values later, in ppc64_elf_finish_dynamic_sections, but we |
| 6090 | must add the entries now so that we get the correct size for |
| 6091 | the .dynamic section. The DT_DEBUG entry is filled in by the |
| 6092 | dynamic linker and used by the debugger. */ |
| 6093 | #define add_dynamic_entry(TAG, VAL) \ |
| 6094 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
| 6095 | |
| 6096 | if (info->executable) |
| 6097 | { |
| 6098 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
| 6099 | return FALSE; |
| 6100 | } |
| 6101 | |
| 6102 | if (htab->plt != NULL && htab->plt->size != 0) |
| 6103 | { |
| 6104 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
| 6105 | || !add_dynamic_entry (DT_PLTRELSZ, 0) |
| 6106 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) |
| 6107 | || !add_dynamic_entry (DT_JMPREL, 0) |
| 6108 | || !add_dynamic_entry (DT_PPC64_GLINK, 0)) |
| 6109 | return FALSE; |
| 6110 | } |
| 6111 | |
| 6112 | if (NO_OPD_RELOCS) |
| 6113 | { |
| 6114 | if (!add_dynamic_entry (DT_PPC64_OPD, 0) |
| 6115 | || !add_dynamic_entry (DT_PPC64_OPDSZ, 0)) |
| 6116 | return FALSE; |
| 6117 | } |
| 6118 | |
| 6119 | if (relocs) |
| 6120 | { |
| 6121 | if (!add_dynamic_entry (DT_RELA, 0) |
| 6122 | || !add_dynamic_entry (DT_RELASZ, 0) |
| 6123 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) |
| 6124 | return FALSE; |
| 6125 | |
| 6126 | /* If any dynamic relocs apply to a read-only section, |
| 6127 | then we need a DT_TEXTREL entry. */ |
| 6128 | if ((info->flags & DF_TEXTREL) == 0) |
| 6129 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info); |
| 6130 | |
| 6131 | if ((info->flags & DF_TEXTREL) != 0) |
| 6132 | { |
| 6133 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
| 6134 | return FALSE; |
| 6135 | } |
| 6136 | } |
| 6137 | } |
| 6138 | #undef add_dynamic_entry |
| 6139 | |
| 6140 | return TRUE; |
| 6141 | } |
| 6142 | |
| 6143 | /* Determine the type of stub needed, if any, for a call. */ |
| 6144 | |
| 6145 | static inline enum ppc_stub_type |
| 6146 | ppc_type_of_stub (asection *input_sec, |
| 6147 | const Elf_Internal_Rela *rel, |
| 6148 | struct ppc_link_hash_entry **hash, |
| 6149 | bfd_vma destination) |
| 6150 | { |
| 6151 | struct ppc_link_hash_entry *h = *hash; |
| 6152 | bfd_vma location; |
| 6153 | bfd_vma branch_offset; |
| 6154 | bfd_vma max_branch_offset; |
| 6155 | enum elf_ppc64_reloc_type r_type; |
| 6156 | |
| 6157 | if (h != NULL) |
| 6158 | { |
| 6159 | if (h->oh != NULL |
| 6160 | && h->oh->elf.dynindx != -1) |
| 6161 | { |
| 6162 | struct plt_entry *ent; |
| 6163 | for (ent = h->oh->elf.plt.plist; ent != NULL; ent = ent->next) |
| 6164 | if (ent->addend == rel->r_addend |
| 6165 | && ent->plt.offset != (bfd_vma) -1) |
| 6166 | { |
| 6167 | *hash = h->oh; |
| 6168 | return ppc_stub_plt_call; |
| 6169 | } |
| 6170 | } |
| 6171 | |
| 6172 | if (!(h->elf.root.type == bfd_link_hash_defined |
| 6173 | || h->elf.root.type == bfd_link_hash_defweak) |
| 6174 | || h->elf.root.u.def.section->output_section == NULL) |
| 6175 | return ppc_stub_none; |
| 6176 | } |
| 6177 | |
| 6178 | /* Determine where the call point is. */ |
| 6179 | location = (input_sec->output_offset |
| 6180 | + input_sec->output_section->vma |
| 6181 | + rel->r_offset); |
| 6182 | |
| 6183 | branch_offset = destination - location; |
| 6184 | r_type = ELF64_R_TYPE (rel->r_info); |
| 6185 | |
| 6186 | /* Determine if a long branch stub is needed. */ |
| 6187 | max_branch_offset = 1 << 25; |
| 6188 | if (r_type != R_PPC64_REL24) |
| 6189 | max_branch_offset = 1 << 15; |
| 6190 | |
| 6191 | if (branch_offset + max_branch_offset >= 2 * max_branch_offset) |
| 6192 | /* We need a stub. Figure out whether a long_branch or plt_branch |
| 6193 | is needed later. */ |
| 6194 | return ppc_stub_long_branch; |
| 6195 | |
| 6196 | return ppc_stub_none; |
| 6197 | } |
| 6198 | |
| 6199 | /* Build a .plt call stub. */ |
| 6200 | |
| 6201 | static inline bfd_byte * |
| 6202 | build_plt_stub (bfd *obfd, bfd_byte *p, int offset) |
| 6203 | { |
| 6204 | #define PPC_LO(v) ((v) & 0xffff) |
| 6205 | #define PPC_HI(v) (((v) >> 16) & 0xffff) |
| 6206 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) |
| 6207 | |
| 6208 | bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; |
| 6209 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; |
| 6210 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; |
| 6211 | if (PPC_HA (offset + 8) != PPC_HA (offset)) |
| 6212 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
| 6213 | offset += 8; |
| 6214 | bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4; |
| 6215 | if (PPC_HA (offset + 8) != PPC_HA (offset)) |
| 6216 | bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; |
| 6217 | offset += 8; |
| 6218 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; |
| 6219 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; |
| 6220 | bfd_put_32 (obfd, BCTR, p), p += 4; |
| 6221 | return p; |
| 6222 | } |
| 6223 | |
| 6224 | static bfd_boolean |
| 6225 | ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
| 6226 | { |
| 6227 | struct ppc_stub_hash_entry *stub_entry; |
| 6228 | struct ppc_branch_hash_entry *br_entry; |
| 6229 | struct bfd_link_info *info; |
| 6230 | struct ppc_link_hash_table *htab; |
| 6231 | bfd_byte *loc; |
| 6232 | bfd_byte *p; |
| 6233 | unsigned int indx; |
| 6234 | struct plt_entry *ent; |
| 6235 | bfd_vma off; |
| 6236 | int size; |
| 6237 | |
| 6238 | /* Massage our args to the form they really have. */ |
| 6239 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; |
| 6240 | info = in_arg; |
| 6241 | |
| 6242 | htab = ppc_hash_table (info); |
| 6243 | |
| 6244 | /* Make a note of the offset within the stubs for this entry. */ |
| 6245 | stub_entry->stub_offset = stub_entry->stub_sec->size; |
| 6246 | loc = stub_entry->stub_sec->contents + stub_entry->stub_offset; |
| 6247 | |
| 6248 | htab->stub_count[stub_entry->stub_type - 1] += 1; |
| 6249 | switch (stub_entry->stub_type) |
| 6250 | { |
| 6251 | case ppc_stub_long_branch: |
| 6252 | case ppc_stub_long_branch_r2off: |
| 6253 | /* Branches are relative. This is where we are going to. */ |
| 6254 | off = (stub_entry->target_value |
| 6255 | + stub_entry->target_section->output_offset |
| 6256 | + stub_entry->target_section->output_section->vma); |
| 6257 | |
| 6258 | /* And this is where we are coming from. */ |
| 6259 | off -= (stub_entry->stub_offset |
| 6260 | + stub_entry->stub_sec->output_offset |
| 6261 | + stub_entry->stub_sec->output_section->vma); |
| 6262 | |
| 6263 | if (stub_entry->stub_type != ppc_stub_long_branch_r2off) |
| 6264 | size = 4; |
| 6265 | else |
| 6266 | { |
| 6267 | bfd_vma r2off; |
| 6268 | |
| 6269 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off |
| 6270 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
| 6271 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
| 6272 | loc += 4; |
| 6273 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
| 6274 | loc += 4; |
| 6275 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
| 6276 | loc += 4; |
| 6277 | off -= 12; |
| 6278 | size = 16; |
| 6279 | } |
| 6280 | bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc); |
| 6281 | |
| 6282 | BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26)); |
| 6283 | break; |
| 6284 | |
| 6285 | case ppc_stub_plt_branch: |
| 6286 | case ppc_stub_plt_branch_r2off: |
| 6287 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, |
| 6288 | stub_entry->root.string + 9, |
| 6289 | FALSE, FALSE); |
| 6290 | if (br_entry == NULL) |
| 6291 | { |
| 6292 | (*_bfd_error_handler) (_("can't find branch stub `%s'"), |
| 6293 | stub_entry->root.string + 9); |
| 6294 | htab->stub_error = TRUE; |
| 6295 | return FALSE; |
| 6296 | } |
| 6297 | |
| 6298 | off = (stub_entry->target_value |
| 6299 | + stub_entry->target_section->output_offset |
| 6300 | + stub_entry->target_section->output_section->vma); |
| 6301 | |
| 6302 | bfd_put_64 (htab->brlt->owner, off, |
| 6303 | htab->brlt->contents + br_entry->offset); |
| 6304 | |
| 6305 | if (info->shared) |
| 6306 | { |
| 6307 | /* Create a reloc for the branch lookup table entry. */ |
| 6308 | Elf_Internal_Rela rela; |
| 6309 | bfd_byte *rl; |
| 6310 | |
| 6311 | rela.r_offset = (br_entry->offset |
| 6312 | + htab->brlt->output_offset |
| 6313 | + htab->brlt->output_section->vma); |
| 6314 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
| 6315 | rela.r_addend = off; |
| 6316 | |
| 6317 | rl = htab->relbrlt->contents; |
| 6318 | rl += htab->relbrlt->reloc_count++ * sizeof (Elf64_External_Rela); |
| 6319 | bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl); |
| 6320 | } |
| 6321 | |
| 6322 | off = (br_entry->offset |
| 6323 | + htab->brlt->output_offset |
| 6324 | + htab->brlt->output_section->vma |
| 6325 | - elf_gp (htab->brlt->output_section->owner) |
| 6326 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
| 6327 | |
| 6328 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
| 6329 | { |
| 6330 | (*_bfd_error_handler) |
| 6331 | (_("linkage table error against `%s'"), |
| 6332 | stub_entry->root.string); |
| 6333 | bfd_set_error (bfd_error_bad_value); |
| 6334 | htab->stub_error = TRUE; |
| 6335 | return FALSE; |
| 6336 | } |
| 6337 | |
| 6338 | indx = off; |
| 6339 | if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) |
| 6340 | { |
| 6341 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
| 6342 | loc += 4; |
| 6343 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
| 6344 | size = 16; |
| 6345 | } |
| 6346 | else |
| 6347 | { |
| 6348 | bfd_vma r2off; |
| 6349 | |
| 6350 | r2off = (htab->stub_group[stub_entry->target_section->id].toc_off |
| 6351 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
| 6352 | bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); |
| 6353 | loc += 4; |
| 6354 | bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); |
| 6355 | loc += 4; |
| 6356 | bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); |
| 6357 | loc += 4; |
| 6358 | bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); |
| 6359 | loc += 4; |
| 6360 | bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
| 6361 | size = 28; |
| 6362 | } |
| 6363 | loc += 4; |
| 6364 | bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc); |
| 6365 | loc += 4; |
| 6366 | bfd_put_32 (htab->stub_bfd, BCTR, loc); |
| 6367 | break; |
| 6368 | |
| 6369 | case ppc_stub_plt_call: |
| 6370 | /* Do the best we can for shared libraries built without |
| 6371 | exporting ".foo" for each "foo". This can happen when symbol |
| 6372 | versioning scripts strip all bar a subset of symbols. */ |
| 6373 | if (stub_entry->h->oh->elf.root.type != bfd_link_hash_defined |
| 6374 | && stub_entry->h->oh->elf.root.type != bfd_link_hash_defweak) |
| 6375 | { |
| 6376 | /* Point the symbol at the stub. There may be multiple stubs, |
| 6377 | we don't really care; The main thing is to make this sym |
| 6378 | defined somewhere. Maybe defining the symbol in the stub |
| 6379 | section is a silly idea. If we didn't do this, htab->top_id |
| 6380 | could disappear. */ |
| 6381 | stub_entry->h->oh->elf.root.type = bfd_link_hash_defined; |
| 6382 | stub_entry->h->oh->elf.root.u.def.section = stub_entry->stub_sec; |
| 6383 | stub_entry->h->oh->elf.root.u.def.value = stub_entry->stub_offset; |
| 6384 | } |
| 6385 | |
| 6386 | /* Now build the stub. */ |
| 6387 | off = (bfd_vma) -1; |
| 6388 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) |
| 6389 | if (ent->addend == stub_entry->addend) |
| 6390 | { |
| 6391 | off = ent->plt.offset; |
| 6392 | break; |
| 6393 | } |
| 6394 | if (off >= (bfd_vma) -2) |
| 6395 | abort (); |
| 6396 | |
| 6397 | off &= ~ (bfd_vma) 1; |
| 6398 | off += (htab->plt->output_offset |
| 6399 | + htab->plt->output_section->vma |
| 6400 | - elf_gp (htab->plt->output_section->owner) |
| 6401 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
| 6402 | |
| 6403 | if (off + 0x80008000 > 0xffffffff || (off & 7) != 0) |
| 6404 | { |
| 6405 | (*_bfd_error_handler) |
| 6406 | (_("linkage table error against `%s'"), |
| 6407 | stub_entry->h->elf.root.root.string); |
| 6408 | bfd_set_error (bfd_error_bad_value); |
| 6409 | htab->stub_error = TRUE; |
| 6410 | return FALSE; |
| 6411 | } |
| 6412 | |
| 6413 | p = build_plt_stub (htab->stub_bfd, loc, off); |
| 6414 | size = p - loc; |
| 6415 | break; |
| 6416 | |
| 6417 | default: |
| 6418 | BFD_FAIL (); |
| 6419 | return FALSE; |
| 6420 | } |
| 6421 | |
| 6422 | stub_entry->stub_sec->size += size; |
| 6423 | |
| 6424 | if (htab->emit_stub_syms |
| 6425 | && !(stub_entry->stub_type == ppc_stub_plt_call |
| 6426 | && stub_entry->h->oh->elf.root.type == bfd_link_hash_defined |
| 6427 | && stub_entry->h->oh->elf.root.u.def.section == stub_entry->stub_sec |
| 6428 | && stub_entry->h->oh->elf.root.u.def.value == stub_entry->stub_offset)) |
| 6429 | { |
| 6430 | struct elf_link_hash_entry *h; |
| 6431 | h = elf_link_hash_lookup (&htab->elf, stub_entry->root.string, |
| 6432 | TRUE, FALSE, FALSE); |
| 6433 | if (h == NULL) |
| 6434 | return FALSE; |
| 6435 | if (h->root.type == bfd_link_hash_new) |
| 6436 | { |
| 6437 | h->root.type = bfd_link_hash_defined; |
| 6438 | h->root.u.def.section = stub_entry->stub_sec; |
| 6439 | h->root.u.def.value = stub_entry->stub_offset; |
| 6440 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR |
| 6441 | | ELF_LINK_HASH_DEF_REGULAR |
| 6442 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK |
| 6443 | | ELF_LINK_FORCED_LOCAL); |
| 6444 | } |
| 6445 | } |
| 6446 | |
| 6447 | return TRUE; |
| 6448 | } |
| 6449 | |
| 6450 | /* As above, but don't actually build the stub. Just bump offset so |
| 6451 | we know stub section sizes, and select plt_branch stubs where |
| 6452 | long_branch stubs won't do. */ |
| 6453 | |
| 6454 | static bfd_boolean |
| 6455 | ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
| 6456 | { |
| 6457 | struct ppc_stub_hash_entry *stub_entry; |
| 6458 | struct bfd_link_info *info; |
| 6459 | struct ppc_link_hash_table *htab; |
| 6460 | bfd_vma off; |
| 6461 | int size; |
| 6462 | |
| 6463 | /* Massage our args to the form they really have. */ |
| 6464 | stub_entry = (struct ppc_stub_hash_entry *) gen_entry; |
| 6465 | info = in_arg; |
| 6466 | |
| 6467 | htab = ppc_hash_table (info); |
| 6468 | |
| 6469 | if (stub_entry->stub_type == ppc_stub_plt_call) |
| 6470 | { |
| 6471 | struct plt_entry *ent; |
| 6472 | off = (bfd_vma) -1; |
| 6473 | for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next) |
| 6474 | if (ent->addend == stub_entry->addend) |
| 6475 | { |
| 6476 | off = ent->plt.offset & ~(bfd_vma) 1; |
| 6477 | break; |
| 6478 | } |
| 6479 | if (off >= (bfd_vma) -2) |
| 6480 | abort (); |
| 6481 | off += (htab->plt->output_offset |
| 6482 | + htab->plt->output_section->vma |
| 6483 | - elf_gp (htab->plt->output_section->owner) |
| 6484 | - htab->stub_group[stub_entry->id_sec->id].toc_off); |
| 6485 | |
| 6486 | size = PLT_CALL_STUB_SIZE; |
| 6487 | if (PPC_HA (off + 16) != PPC_HA (off)) |
| 6488 | size += 4; |
| 6489 | } |
| 6490 | else |
| 6491 | { |
| 6492 | /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off |
| 6493 | variants. */ |
| 6494 | off = (stub_entry->target_value |
| 6495 | + stub_entry->target_section->output_offset |
| 6496 | + stub_entry->target_section->output_section->vma); |
| 6497 | off -= (stub_entry->stub_sec->size |
| 6498 | + stub_entry->stub_sec->output_offset |
| 6499 | + stub_entry->stub_sec->output_section->vma); |
| 6500 | |
| 6501 | /* Reset the stub type from the plt variant in case we now |
| 6502 | can reach with a shorter stub. */ |
| 6503 | if (stub_entry->stub_type >= ppc_stub_plt_branch) |
| 6504 | stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch; |
| 6505 | |
| 6506 | size = 4; |
| 6507 | if (stub_entry->stub_type == ppc_stub_long_branch_r2off) |
| 6508 | { |
| 6509 | off -= 12; |
| 6510 | size = 16; |
| 6511 | } |
| 6512 | |
| 6513 | /* If the branch offset if too big, use a ppc_stub_plt_branch. */ |
| 6514 | if (off + (1 << 25) >= (bfd_vma) (1 << 26)) |
| 6515 | { |
| 6516 | struct ppc_branch_hash_entry *br_entry; |
| 6517 | |
| 6518 | br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, |
| 6519 | stub_entry->root.string + 9, |
| 6520 | TRUE, FALSE); |
| 6521 | if (br_entry == NULL) |
| 6522 | { |
| 6523 | (*_bfd_error_handler) (_("can't build branch stub `%s'"), |
| 6524 | stub_entry->root.string + 9); |
| 6525 | htab->stub_error = TRUE; |
| 6526 | return FALSE; |
| 6527 | } |
| 6528 | |
| 6529 | if (br_entry->iter != htab->stub_iteration) |
| 6530 | { |
| 6531 | br_entry->iter = htab->stub_iteration; |
| 6532 | br_entry->offset = htab->brlt->size; |
| 6533 | htab->brlt->size += 8; |
| 6534 | |
| 6535 | if (info->shared) |
| 6536 | htab->relbrlt->size += sizeof (Elf64_External_Rela); |
| 6537 | } |
| 6538 | |
| 6539 | stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch; |
| 6540 | size = 16; |
| 6541 | if (stub_entry->stub_type != ppc_stub_plt_branch) |
| 6542 | size = 28; |
| 6543 | } |
| 6544 | } |
| 6545 | |
| 6546 | stub_entry->stub_sec->size += size; |
| 6547 | return TRUE; |
| 6548 | } |
| 6549 | |
| 6550 | /* Set up various things so that we can make a list of input sections |
| 6551 | for each output section included in the link. Returns -1 on error, |
| 6552 | 0 when no stubs will be needed, and 1 on success. */ |
| 6553 | |
| 6554 | int |
| 6555 | ppc64_elf_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) |
| 6556 | { |
| 6557 | bfd *input_bfd; |
| 6558 | int top_id, top_index, id; |
| 6559 | asection *section; |
| 6560 | asection **input_list; |
| 6561 | bfd_size_type amt; |
| 6562 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
| 6563 | |
| 6564 | if (htab->brlt == NULL) |
| 6565 | return 0; |
| 6566 | |
| 6567 | /* Find the top input section id. */ |
| 6568 | for (input_bfd = info->input_bfds, top_id = 3; |
| 6569 | input_bfd != NULL; |
| 6570 | input_bfd = input_bfd->link_next) |
| 6571 | { |
| 6572 | for (section = input_bfd->sections; |
| 6573 | section != NULL; |
| 6574 | section = section->next) |
| 6575 | { |
| 6576 | if (top_id < section->id) |
| 6577 | top_id = section->id; |
| 6578 | } |
| 6579 | } |
| 6580 | |
| 6581 | htab->top_id = top_id; |
| 6582 | amt = sizeof (struct map_stub) * (top_id + 1); |
| 6583 | htab->stub_group = bfd_zmalloc (amt); |
| 6584 | if (htab->stub_group == NULL) |
| 6585 | return -1; |
| 6586 | |
| 6587 | /* Set toc_off for com, und, abs and ind sections. */ |
| 6588 | for (id = 0; id < 3; id++) |
| 6589 | htab->stub_group[id].toc_off = TOC_BASE_OFF; |
| 6590 | |
| 6591 | elf_gp (output_bfd) = htab->toc_curr = ppc64_elf_toc (output_bfd); |
| 6592 | |
| 6593 | /* We can't use output_bfd->section_count here to find the top output |
| 6594 | section index as some sections may have been removed, and |
| 6595 | _bfd_strip_section_from_output doesn't renumber the indices. */ |
| 6596 | for (section = output_bfd->sections, top_index = 0; |
| 6597 | section != NULL; |
| 6598 | section = section->next) |
| 6599 | { |
| 6600 | if (top_index < section->index) |
| 6601 | top_index = section->index; |
| 6602 | } |
| 6603 | |
| 6604 | htab->top_index = top_index; |
| 6605 | amt = sizeof (asection *) * (top_index + 1); |
| 6606 | input_list = bfd_zmalloc (amt); |
| 6607 | htab->input_list = input_list; |
| 6608 | if (input_list == NULL) |
| 6609 | return -1; |
| 6610 | |
| 6611 | return 1; |
| 6612 | } |
| 6613 | |
| 6614 | /* The linker repeatedly calls this function for each TOC input section |
| 6615 | and linker generated GOT section. Group input bfds such that the toc |
| 6616 | within a group is less than 64k in size. Will break with cute linker |
| 6617 | scripts that play games with dot in the output toc section. */ |
| 6618 | |
| 6619 | void |
| 6620 | ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec) |
| 6621 | { |
| 6622 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
| 6623 | |
| 6624 | if (!htab->no_multi_toc) |
| 6625 | { |
| 6626 | bfd_vma addr = isec->output_offset + isec->output_section->vma; |
| 6627 | bfd_vma off = addr - htab->toc_curr; |
| 6628 | if (off + isec->size > 0x10000) |
| 6629 | { |
| 6630 | htab->toc_curr = addr; |
| 6631 | htab->multi_toc_needed = 1; |
| 6632 | } |
| 6633 | elf_gp (isec->owner) = (htab->toc_curr |
| 6634 | - elf_gp (isec->output_section->owner) |
| 6635 | + TOC_BASE_OFF); |
| 6636 | } |
| 6637 | } |
| 6638 | |
| 6639 | /* Called after the last call to the above function. */ |
| 6640 | |
| 6641 | void |
| 6642 | ppc64_elf_reinit_toc (bfd *output_bfd ATTRIBUTE_UNUSED, |
| 6643 | struct bfd_link_info *info) |
| 6644 | { |
| 6645 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
| 6646 | |
| 6647 | /* toc_curr tracks the TOC offset used for code sections below in |
| 6648 | ppc64_elf_next_input_section. Start off at 0x8000. */ |
| 6649 | htab->toc_curr = TOC_BASE_OFF; |
| 6650 | } |
| 6651 | |
| 6652 | /* No toc references were found in ISEC. If the code in ISEC makes no |
| 6653 | calls, then there's no need to use toc adjusting stubs when branching |
| 6654 | into ISEC. Actually, indirect calls from ISEC are OK as they will |
| 6655 | load r2. */ |
| 6656 | |
| 6657 | static int |
| 6658 | toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec) |
| 6659 | { |
| 6660 | bfd_byte *contents; |
| 6661 | bfd_size_type i; |
| 6662 | int ret; |
| 6663 | int branch_ok; |
| 6664 | |
| 6665 | /* We know none of our code bearing sections will need toc stubs. */ |
| 6666 | if ((isec->flags & SEC_LINKER_CREATED) != 0) |
| 6667 | return 0; |
| 6668 | |
| 6669 | if (isec->size == 0) |
| 6670 | return 0; |
| 6671 | |
| 6672 | /* Hack for linux kernel. .fixup contains branches, but only back to |
| 6673 | the function that hit an exception. */ |
| 6674 | branch_ok = strcmp (isec->name, ".fixup") == 0; |
| 6675 | |
| 6676 | contents = elf_section_data (isec)->this_hdr.contents; |
| 6677 | if (contents == NULL) |
| 6678 | { |
| 6679 | if (!bfd_malloc_and_get_section (isec->owner, isec, &contents)) |
| 6680 | { |
| 6681 | if (contents != NULL) |
| 6682 | free (contents); |
| 6683 | return -1; |
| 6684 | } |
| 6685 | if (info->keep_memory) |
| 6686 | elf_section_data (isec)->this_hdr.contents = contents; |
| 6687 | } |
| 6688 | |
| 6689 | /* Code scan, because we don't necessarily have relocs on calls to |
| 6690 | static functions. */ |
| 6691 | ret = 0; |
| 6692 | for (i = 0; i < isec->size; i += 4) |
| 6693 | { |
| 6694 | unsigned long insn = bfd_get_32 (isec->owner, contents + i); |
| 6695 | /* Is this a branch? */ |
| 6696 | if ((insn & (0x3f << 26)) == (18 << 26) |
| 6697 | /* If branch and link, it's a function call. */ |
| 6698 | && ((insn & 1) != 0 |
| 6699 | /* Sibling calls use a plain branch. I don't know a way |
| 6700 | of deciding whether a branch is really a sibling call. */ |
| 6701 | || !branch_ok)) |
| 6702 | { |
| 6703 | ret = 1; |
| 6704 | break; |
| 6705 | } |
| 6706 | } |
| 6707 | |
| 6708 | if (elf_section_data (isec)->this_hdr.contents != contents) |
| 6709 | free (contents); |
| 6710 | return ret; |
| 6711 | } |
| 6712 | |
| 6713 | /* The linker repeatedly calls this function for each input section, |
| 6714 | in the order that input sections are linked into output sections. |
| 6715 | Build lists of input sections to determine groupings between which |
| 6716 | we may insert linker stubs. */ |
| 6717 | |
| 6718 | bfd_boolean |
| 6719 | ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec) |
| 6720 | { |
| 6721 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
| 6722 | int ret; |
| 6723 | |
| 6724 | if ((isec->output_section->flags & SEC_CODE) != 0 |
| 6725 | && isec->output_section->index <= htab->top_index) |
| 6726 | { |
| 6727 | asection **list = htab->input_list + isec->output_section->index; |
| 6728 | /* Steal the link_sec pointer for our list. */ |
| 6729 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
| 6730 | /* This happens to make the list in reverse order, |
| 6731 | which is what we want. */ |
| 6732 | PREV_SEC (isec) = *list; |
| 6733 | *list = isec; |
| 6734 | } |
| 6735 | |
| 6736 | /* If a code section has a function that uses the TOC then we need |
| 6737 | to use the right TOC (obviously). Also, make sure that .opd gets |
| 6738 | the correct TOC value for R_PPC64_TOC relocs that don't have or |
| 6739 | can't find their function symbol (shouldn't ever happen now). */ |
| 6740 | if (isec->has_gp_reloc || (isec->flags & SEC_CODE) == 0) |
| 6741 | { |
| 6742 | if (elf_gp (isec->owner) != 0) |
| 6743 | htab->toc_curr = elf_gp (isec->owner); |
| 6744 | } |
| 6745 | else if ((ret = toc_adjusting_stub_needed (info, isec)) < 0) |
| 6746 | return FALSE; |
| 6747 | else |
| 6748 | isec->has_gp_reloc = ret; |
| 6749 | |
| 6750 | /* Functions that don't use the TOC can belong in any TOC group. |
| 6751 | Use the last TOC base. This happens to make _init and _fini |
| 6752 | pasting work. */ |
| 6753 | htab->stub_group[isec->id].toc_off = htab->toc_curr; |
| 6754 | return TRUE; |
| 6755 | } |
| 6756 | |
| 6757 | /* See whether we can group stub sections together. Grouping stub |
| 6758 | sections may result in fewer stubs. More importantly, we need to |
| 6759 | put all .init* and .fini* stubs at the beginning of the .init or |
| 6760 | .fini output sections respectively, because glibc splits the |
| 6761 | _init and _fini functions into multiple parts. Putting a stub in |
| 6762 | the middle of a function is not a good idea. */ |
| 6763 | |
| 6764 | static void |
| 6765 | group_sections (struct ppc_link_hash_table *htab, |
| 6766 | bfd_size_type stub_group_size, |
| 6767 | bfd_boolean stubs_always_before_branch) |
| 6768 | { |
| 6769 | asection **list = htab->input_list + htab->top_index; |
| 6770 | do |
| 6771 | { |
| 6772 | asection *tail = *list; |
| 6773 | while (tail != NULL) |
| 6774 | { |
| 6775 | asection *curr; |
| 6776 | asection *prev; |
| 6777 | bfd_size_type total; |
| 6778 | bfd_boolean big_sec; |
| 6779 | bfd_vma curr_toc; |
| 6780 | |
| 6781 | curr = tail; |
| 6782 | total = tail->size; |
| 6783 | big_sec = total >= stub_group_size; |
| 6784 | curr_toc = htab->stub_group[tail->id].toc_off; |
| 6785 | |
| 6786 | while ((prev = PREV_SEC (curr)) != NULL |
| 6787 | && ((total += curr->output_offset - prev->output_offset) |
| 6788 | < stub_group_size) |
| 6789 | && htab->stub_group[prev->id].toc_off == curr_toc) |
| 6790 | curr = prev; |
| 6791 | |
| 6792 | /* OK, the size from the start of CURR to the end is less |
| 6793 | than stub_group_size and thus can be handled by one stub |
| 6794 | section. (or the tail section is itself larger than |
| 6795 | stub_group_size, in which case we may be toast.) We |
| 6796 | should really be keeping track of the total size of stubs |
| 6797 | added here, as stubs contribute to the final output |
| 6798 | section size. That's a little tricky, and this way will |
| 6799 | only break if stubs added make the total size more than |
| 6800 | 2^25, ie. for the default stub_group_size, if stubs total |
| 6801 | more than 2097152 bytes, or nearly 75000 plt call stubs. */ |
| 6802 | do |
| 6803 | { |
| 6804 | prev = PREV_SEC (tail); |
| 6805 | /* Set up this stub group. */ |
| 6806 | htab->stub_group[tail->id].link_sec = curr; |
| 6807 | } |
| 6808 | while (tail != curr && (tail = prev) != NULL); |
| 6809 | |
| 6810 | /* But wait, there's more! Input sections up to stub_group_size |
| 6811 | bytes before the stub section can be handled by it too. |
| 6812 | Don't do this if we have a really large section after the |
| 6813 | stubs, as adding more stubs increases the chance that |
| 6814 | branches may not reach into the stub section. */ |
| 6815 | if (!stubs_always_before_branch && !big_sec) |
| 6816 | { |
| 6817 | total = 0; |
| 6818 | while (prev != NULL |
| 6819 | && ((total += tail->output_offset - prev->output_offset) |
| 6820 | < stub_group_size) |
| 6821 | && htab->stub_group[prev->id].toc_off == curr_toc) |
| 6822 | { |
| 6823 | tail = prev; |
| 6824 | prev = PREV_SEC (tail); |
| 6825 | htab->stub_group[tail->id].link_sec = curr; |
| 6826 | } |
| 6827 | } |
| 6828 | tail = prev; |
| 6829 | } |
| 6830 | } |
| 6831 | while (list-- != htab->input_list); |
| 6832 | free (htab->input_list); |
| 6833 | #undef PREV_SEC |
| 6834 | } |
| 6835 | |
| 6836 | /* Determine and set the size of the stub section for a final link. |
| 6837 | |
| 6838 | The basic idea here is to examine all the relocations looking for |
| 6839 | PC-relative calls to a target that is unreachable with a "bl" |
| 6840 | instruction. */ |
| 6841 | |
| 6842 | bfd_boolean |
| 6843 | ppc64_elf_size_stubs (bfd *output_bfd, |
| 6844 | struct bfd_link_info *info, |
| 6845 | bfd_signed_vma group_size, |
| 6846 | asection *(*add_stub_section) (const char *, asection *), |
| 6847 | void (*layout_sections_again) (void)) |
| 6848 | { |
| 6849 | bfd_size_type stub_group_size; |
| 6850 | bfd_boolean stubs_always_before_branch; |
| 6851 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
| 6852 | |
| 6853 | /* Stash our params away. */ |
| 6854 | htab->add_stub_section = add_stub_section; |
| 6855 | htab->layout_sections_again = layout_sections_again; |
| 6856 | stubs_always_before_branch = group_size < 0; |
| 6857 | if (group_size < 0) |
| 6858 | stub_group_size = -group_size; |
| 6859 | else |
| 6860 | stub_group_size = group_size; |
| 6861 | if (stub_group_size == 1) |
| 6862 | { |
| 6863 | /* Default values. */ |
| 6864 | if (stubs_always_before_branch) |
| 6865 | { |
| 6866 | stub_group_size = 0x1e00000; |
| 6867 | if (htab->has_14bit_branch) |
| 6868 | stub_group_size = 0x7800; |
| 6869 | } |
| 6870 | else |
| 6871 | { |
| 6872 | stub_group_size = 0x1c00000; |
| 6873 | if (htab->has_14bit_branch) |
| 6874 | stub_group_size = 0x7000; |
| 6875 | } |
| 6876 | } |
| 6877 | |
| 6878 | group_sections (htab, stub_group_size, stubs_always_before_branch); |
| 6879 | |
| 6880 | while (1) |
| 6881 | { |
| 6882 | bfd *input_bfd; |
| 6883 | unsigned int bfd_indx; |
| 6884 | asection *stub_sec; |
| 6885 | bfd_boolean stub_changed; |
| 6886 | |
| 6887 | htab->stub_iteration += 1; |
| 6888 | stub_changed = FALSE; |
| 6889 | |
| 6890 | for (input_bfd = info->input_bfds, bfd_indx = 0; |
| 6891 | input_bfd != NULL; |
| 6892 | input_bfd = input_bfd->link_next, bfd_indx++) |
| 6893 | { |
| 6894 | Elf_Internal_Shdr *symtab_hdr; |
| 6895 | asection *section; |
| 6896 | Elf_Internal_Sym *local_syms = NULL; |
| 6897 | |
| 6898 | /* We'll need the symbol table in a second. */ |
| 6899 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
| 6900 | if (symtab_hdr->sh_info == 0) |
| 6901 | continue; |
| 6902 | |
| 6903 | /* Walk over each section attached to the input bfd. */ |
| 6904 | for (section = input_bfd->sections; |
| 6905 | section != NULL; |
| 6906 | section = section->next) |
| 6907 | { |
| 6908 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
| 6909 | |
| 6910 | /* If there aren't any relocs, then there's nothing more |
| 6911 | to do. */ |
| 6912 | if ((section->flags & SEC_RELOC) == 0 |
| 6913 | || section->reloc_count == 0) |
| 6914 | continue; |
| 6915 | |
| 6916 | /* If this section is a link-once section that will be |
| 6917 | discarded, then don't create any stubs. */ |
| 6918 | if (section->output_section == NULL |
| 6919 | || section->output_section->owner != output_bfd) |
| 6920 | continue; |
| 6921 | |
| 6922 | /* Get the relocs. */ |
| 6923 | internal_relocs |
| 6924 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, |
| 6925 | info->keep_memory); |
| 6926 | if (internal_relocs == NULL) |
| 6927 | goto error_ret_free_local; |
| 6928 | |
| 6929 | /* Now examine each relocation. */ |
| 6930 | irela = internal_relocs; |
| 6931 | irelaend = irela + section->reloc_count; |
| 6932 | for (; irela < irelaend; irela++) |
| 6933 | { |
| 6934 | enum elf_ppc64_reloc_type r_type; |
| 6935 | unsigned int r_indx; |
| 6936 | enum ppc_stub_type stub_type; |
| 6937 | struct ppc_stub_hash_entry *stub_entry; |
| 6938 | asection *sym_sec; |
| 6939 | bfd_vma sym_value; |
| 6940 | bfd_vma destination; |
| 6941 | struct ppc_link_hash_entry *hash; |
| 6942 | struct elf_link_hash_entry *h; |
| 6943 | Elf_Internal_Sym *sym; |
| 6944 | char *stub_name; |
| 6945 | const asection *id_sec; |
| 6946 | |
| 6947 | r_type = ELF64_R_TYPE (irela->r_info); |
| 6948 | r_indx = ELF64_R_SYM (irela->r_info); |
| 6949 | |
| 6950 | if (r_type >= R_PPC64_max) |
| 6951 | { |
| 6952 | bfd_set_error (bfd_error_bad_value); |
| 6953 | goto error_ret_free_internal; |
| 6954 | } |
| 6955 | |
| 6956 | /* Only look for stubs on branch instructions. */ |
| 6957 | if (r_type != R_PPC64_REL24 |
| 6958 | && r_type != R_PPC64_REL14 |
| 6959 | && r_type != R_PPC64_REL14_BRTAKEN |
| 6960 | && r_type != R_PPC64_REL14_BRNTAKEN) |
| 6961 | continue; |
| 6962 | |
| 6963 | /* Now determine the call target, its name, value, |
| 6964 | section. */ |
| 6965 | destination = 0; |
| 6966 | if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, |
| 6967 | r_indx, input_bfd)) |
| 6968 | goto error_ret_free_internal; |
| 6969 | hash = (struct ppc_link_hash_entry *) h; |
| 6970 | |
| 6971 | if (hash == NULL) |
| 6972 | { |
| 6973 | /* It's a local symbol. */ |
| 6974 | sym_value = sym->st_value; |
| 6975 | destination = (sym_value + irela->r_addend |
| 6976 | + sym_sec->output_offset |
| 6977 | + sym_sec->output_section->vma); |
| 6978 | } |
| 6979 | else |
| 6980 | { |
| 6981 | /* It's an external symbol. */ |
| 6982 | sym_value = 0; |
| 6983 | if (hash->elf.root.type == bfd_link_hash_defined |
| 6984 | || hash->elf.root.type == bfd_link_hash_defweak) |
| 6985 | { |
| 6986 | sym_value = hash->elf.root.u.def.value; |
| 6987 | if (sym_sec->output_section != NULL) |
| 6988 | destination = (sym_value + irela->r_addend |
| 6989 | + sym_sec->output_offset |
| 6990 | + sym_sec->output_section->vma); |
| 6991 | } |
| 6992 | else if (hash->elf.root.type == bfd_link_hash_undefweak) |
| 6993 | ; |
| 6994 | else if (hash->elf.root.type == bfd_link_hash_undefined) |
| 6995 | ; |
| 6996 | else |
| 6997 | { |
| 6998 | bfd_set_error (bfd_error_bad_value); |
| 6999 | goto error_ret_free_internal; |
| 7000 | } |
| 7001 | } |
| 7002 | |
| 7003 | /* Determine what (if any) linker stub is needed. */ |
| 7004 | stub_type = ppc_type_of_stub (section, irela, &hash, |
| 7005 | destination); |
| 7006 | |
| 7007 | if (stub_type != ppc_stub_plt_call) |
| 7008 | { |
| 7009 | /* Check whether we need a TOC adjusting stub. |
| 7010 | Since the linker pastes together pieces from |
| 7011 | different object files when creating the |
| 7012 | _init and _fini functions, it may be that a |
| 7013 | call to what looks like a local sym is in |
| 7014 | fact a call needing a TOC adjustment. */ |
| 7015 | if (sym_sec != NULL |
| 7016 | && sym_sec->output_section != NULL |
| 7017 | && (htab->stub_group[sym_sec->id].toc_off |
| 7018 | != htab->stub_group[section->id].toc_off) |
| 7019 | && sym_sec->has_gp_reloc |
| 7020 | && section->has_gp_reloc) |
| 7021 | stub_type = ppc_stub_long_branch_r2off; |
| 7022 | } |
| 7023 | |
| 7024 | if (stub_type == ppc_stub_none) |
| 7025 | continue; |
| 7026 | |
| 7027 | /* __tls_get_addr calls might be eliminated. */ |
| 7028 | if (stub_type != ppc_stub_plt_call |
| 7029 | && hash != NULL |
| 7030 | && &hash->elf == htab->tls_get_addr |
| 7031 | && section->has_tls_reloc |
| 7032 | && irela != internal_relocs) |
| 7033 | { |
| 7034 | /* Get tls info. */ |
| 7035 | char *tls_mask; |
| 7036 | |
| 7037 | if (!get_tls_mask (&tls_mask, NULL, &local_syms, |
| 7038 | irela - 1, input_bfd)) |
| 7039 | goto error_ret_free_internal; |
| 7040 | if (*tls_mask != 0) |
| 7041 | continue; |
| 7042 | } |
| 7043 | |
| 7044 | /* Support for grouping stub sections. */ |
| 7045 | id_sec = htab->stub_group[section->id].link_sec; |
| 7046 | |
| 7047 | /* Get the name of this stub. */ |
| 7048 | stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela); |
| 7049 | if (!stub_name) |
| 7050 | goto error_ret_free_internal; |
| 7051 | |
| 7052 | stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, |
| 7053 | stub_name, FALSE, FALSE); |
| 7054 | if (stub_entry != NULL) |
| 7055 | { |
| 7056 | /* The proper stub has already been created. */ |
| 7057 | free (stub_name); |
| 7058 | continue; |
| 7059 | } |
| 7060 | |
| 7061 | stub_entry = ppc_add_stub (stub_name, section, htab); |
| 7062 | if (stub_entry == NULL) |
| 7063 | { |
| 7064 | free (stub_name); |
| 7065 | error_ret_free_internal: |
| 7066 | if (elf_section_data (section)->relocs == NULL) |
| 7067 | free (internal_relocs); |
| 7068 | error_ret_free_local: |
| 7069 | if (local_syms != NULL |
| 7070 | && (symtab_hdr->contents |
| 7071 | != (unsigned char *) local_syms)) |
| 7072 | free (local_syms); |
| 7073 | return FALSE; |
| 7074 | } |
| 7075 | |
| 7076 | stub_entry->stub_type = stub_type; |
| 7077 | stub_entry->target_value = sym_value; |
| 7078 | stub_entry->target_section = sym_sec; |
| 7079 | stub_entry->h = hash; |
| 7080 | stub_entry->addend = irela->r_addend; |
| 7081 | stub_changed = TRUE; |
| 7082 | } |
| 7083 | |
| 7084 | /* We're done with the internal relocs, free them. */ |
| 7085 | if (elf_section_data (section)->relocs != internal_relocs) |
| 7086 | free (internal_relocs); |
| 7087 | } |
| 7088 | |
| 7089 | if (local_syms != NULL |
| 7090 | && symtab_hdr->contents != (unsigned char *) local_syms) |
| 7091 | { |
| 7092 | if (!info->keep_memory) |
| 7093 | free (local_syms); |
| 7094 | else |
| 7095 | symtab_hdr->contents = (unsigned char *) local_syms; |
| 7096 | } |
| 7097 | } |
| 7098 | |
| 7099 | if (!stub_changed) |
| 7100 | break; |
| 7101 | |
| 7102 | /* OK, we've added some stubs. Find out the new size of the |
| 7103 | stub sections. */ |
| 7104 | for (stub_sec = htab->stub_bfd->sections; |
| 7105 | stub_sec != NULL; |
| 7106 | stub_sec = stub_sec->next) |
| 7107 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
| 7108 | stub_sec->size = 0; |
| 7109 | |
| 7110 | htab->brlt->size = 0; |
| 7111 | if (info->shared) |
| 7112 | htab->relbrlt->size = 0; |
| 7113 | |
| 7114 | bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info); |
| 7115 | |
| 7116 | /* Ask the linker to do its stuff. */ |
| 7117 | (*htab->layout_sections_again) (); |
| 7118 | } |
| 7119 | |
| 7120 | /* It would be nice to strip .branch_lt from the output if the |
| 7121 | section is empty, but it's too late. If we strip sections here, |
| 7122 | the dynamic symbol table is corrupted since the section symbol |
| 7123 | for the stripped section isn't written. */ |
| 7124 | |
| 7125 | return TRUE; |
| 7126 | } |
| 7127 | |
| 7128 | /* Called after we have determined section placement. If sections |
| 7129 | move, we'll be called again. Provide a value for TOCstart. */ |
| 7130 | |
| 7131 | bfd_vma |
| 7132 | ppc64_elf_toc (bfd *obfd) |
| 7133 | { |
| 7134 | asection *s; |
| 7135 | bfd_vma TOCstart; |
| 7136 | |
| 7137 | /* The TOC consists of sections .got, .toc, .tocbss, .plt in that |
| 7138 | order. The TOC starts where the first of these sections starts. */ |
| 7139 | s = bfd_get_section_by_name (obfd, ".got"); |
| 7140 | if (s == NULL) |
| 7141 | s = bfd_get_section_by_name (obfd, ".toc"); |
| 7142 | if (s == NULL) |
| 7143 | s = bfd_get_section_by_name (obfd, ".tocbss"); |
| 7144 | if (s == NULL) |
| 7145 | s = bfd_get_section_by_name (obfd, ".plt"); |
| 7146 | if (s == NULL) |
| 7147 | { |
| 7148 | /* This may happen for |
| 7149 | o references to TOC base (SYM@toc / TOC[tc0]) without a |
| 7150 | .toc directive |
| 7151 | o bad linker script |
| 7152 | o --gc-sections and empty TOC sections |
| 7153 | |
| 7154 | FIXME: Warn user? */ |
| 7155 | |
| 7156 | /* Look for a likely section. We probably won't even be |
| 7157 | using TOCstart. */ |
| 7158 | for (s = obfd->sections; s != NULL; s = s->next) |
| 7159 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY)) |
| 7160 | == (SEC_ALLOC | SEC_SMALL_DATA)) |
| 7161 | break; |
| 7162 | if (s == NULL) |
| 7163 | for (s = obfd->sections; s != NULL; s = s->next) |
| 7164 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA)) |
| 7165 | == (SEC_ALLOC | SEC_SMALL_DATA)) |
| 7166 | break; |
| 7167 | if (s == NULL) |
| 7168 | for (s = obfd->sections; s != NULL; s = s->next) |
| 7169 | if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC) |
| 7170 | break; |
| 7171 | if (s == NULL) |
| 7172 | for (s = obfd->sections; s != NULL; s = s->next) |
| 7173 | if ((s->flags & SEC_ALLOC) == SEC_ALLOC) |
| 7174 | break; |
| 7175 | } |
| 7176 | |
| 7177 | TOCstart = 0; |
| 7178 | if (s != NULL) |
| 7179 | TOCstart = s->output_section->vma + s->output_offset; |
| 7180 | |
| 7181 | return TOCstart; |
| 7182 | } |
| 7183 | |
| 7184 | /* Build all the stubs associated with the current output file. |
| 7185 | The stubs are kept in a hash table attached to the main linker |
| 7186 | hash table. This function is called via gldelf64ppc_finish. */ |
| 7187 | |
| 7188 | bfd_boolean |
| 7189 | ppc64_elf_build_stubs (bfd_boolean emit_stub_syms, |
| 7190 | struct bfd_link_info *info, |
| 7191 | char **stats) |
| 7192 | { |
| 7193 | struct ppc_link_hash_table *htab = ppc_hash_table (info); |
| 7194 | asection *stub_sec; |
| 7195 | bfd_byte *p; |
| 7196 | int stub_sec_count = 0; |
| 7197 | |
| 7198 | htab->emit_stub_syms = emit_stub_syms; |
| 7199 | |
| 7200 | /* Allocate memory to hold the linker stubs. */ |
| 7201 | for (stub_sec = htab->stub_bfd->sections; |
| 7202 | stub_sec != NULL; |
| 7203 | stub_sec = stub_sec->next) |
| 7204 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0 |
| 7205 | && stub_sec->size != 0) |
| 7206 | { |
| 7207 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size); |
| 7208 | if (stub_sec->contents == NULL) |
| 7209 | return FALSE; |
| 7210 | /* We want to check that built size is the same as calculated |
| 7211 | size. rawsize is a convenient location to use. */ |
| 7212 | stub_sec->rawsize = stub_sec->size; |
| 7213 | stub_sec->size = 0; |
| 7214 | } |
| 7215 | |
| 7216 | if (htab->plt != NULL) |
| 7217 | { |
| 7218 | unsigned int indx; |
| 7219 | bfd_vma plt0; |
| 7220 | |
| 7221 | /* Build the .glink plt call stub. */ |
| 7222 | plt0 = (htab->plt->output_section->vma |
| 7223 | + htab->plt->output_offset |
| 7224 | - (htab->glink->output_section->vma |
| 7225 | + htab->glink->output_offset |
| 7226 | + GLINK_CALL_STUB_SIZE)); |
| 7227 | if (plt0 + 0x80008000 > 0xffffffff) |
| 7228 | { |
| 7229 | (*_bfd_error_handler) (_(".glink and .plt too far apart")); |
| 7230 | bfd_set_error (bfd_error_bad_value); |
| 7231 | return FALSE; |
| 7232 | } |
| 7233 | |
| 7234 | if (htab->emit_stub_syms) |
| 7235 | { |
| 7236 | struct elf_link_hash_entry *h; |
| 7237 | h = elf_link_hash_lookup (&htab->elf, "__glink", TRUE, FALSE, FALSE); |
| 7238 | if (h == NULL) |
| 7239 | return FALSE; |
| 7240 | if (h->root.type == bfd_link_hash_new) |
| 7241 | { |
| 7242 | h->root.type = bfd_link_hash_defined; |
| 7243 | h->root.u.def.section = htab->glink; |
| 7244 | h->root.u.def.value = 0; |
| 7245 | h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR |
| 7246 | | ELF_LINK_HASH_DEF_REGULAR |
| 7247 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK |
| 7248 | | ELF_LINK_FORCED_LOCAL); |
| 7249 | } |
| 7250 | } |
| 7251 | p = htab->glink->contents; |
| 7252 | bfd_put_32 (htab->glink->owner, MFCTR_R12, p); |
| 7253 | p += 4; |
| 7254 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_3, p); |
| 7255 | p += 4; |
| 7256 | bfd_put_32 (htab->glink->owner, ADDIC_R2_R0_32K, p); |
| 7257 | p += 4; |
| 7258 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
| 7259 | p += 4; |
| 7260 | bfd_put_32 (htab->glink->owner, SRADI_R2_R2_63, p); |
| 7261 | p += 4; |
| 7262 | bfd_put_32 (htab->glink->owner, SLDI_R11_R0_2, p); |
| 7263 | p += 4; |
| 7264 | bfd_put_32 (htab->glink->owner, AND_R2_R2_R11, p); |
| 7265 | p += 4; |
| 7266 | bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p); |
| 7267 | p += 4; |
| 7268 | bfd_put_32 (htab->glink->owner, ADD_R12_R12_R2, p); |
| 7269 | p += 4; |
| 7270 | bfd_put_32 (htab->glink->owner, ADDIS_R12_R12 | PPC_HA (plt0), p); |
| 7271 | p += 4; |
| 7272 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | PPC_LO (plt0), p); |
| 7273 | p += 4; |
| 7274 | bfd_put_32 (htab->glink->owner, ADDI_R12_R12 | PPC_LO (plt0), p); |
| 7275 | p += 4; |
| 7276 | bfd_put_32 (htab->glink->owner, LD_R2_0R12 | 8, p); |
| 7277 | p += 4; |
| 7278 | bfd_put_32 (htab->glink->owner, MTCTR_R11, p); |
| 7279 | p += 4; |
| 7280 | bfd_put_32 (htab->glink->owner, LD_R11_0R12 | 16, p); |
| 7281 | p += 4; |
| 7282 | bfd_put_32 (htab->glink->owner, BCTR, p); |
| 7283 | p += 4; |
| 7284 | |
| 7285 | /* Build the .glink lazy link call stubs. */ |
| 7286 | indx = 0; |
| 7287 | while (p < htab->glink->contents + htab->glink->size) |
| 7288 | { |
| 7289 | if (indx < 0x8000) |
| 7290 | { |
| 7291 | bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p); |
| 7292 | p += 4; |
| 7293 | } |
| 7294 | else |
| 7295 | { |
| 7296 | bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p); |
| 7297 | p += 4; |
| 7298 | bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx), p); |
| 7299 | p += 4; |
| 7300 | } |
| 7301 | bfd_put_32 (htab->glink->owner, |
| 7302 | B_DOT | ((htab->glink->contents - p) & 0x3fffffc), p); |
| 7303 | indx++; |
| 7304 | p += 4; |
| 7305 | } |
| 7306 | htab->glink->rawsize = p - htab->glink->contents; |
| 7307 | } |
| 7308 | |
| 7309 | if (htab->brlt->size != 0) |
| 7310 | { |
| 7311 | htab->brlt->contents = bfd_zalloc (htab->brlt->owner, |
| 7312 | htab->brlt->size); |
| 7313 | if (htab->brlt->contents == NULL) |
| 7314 | return FALSE; |
| 7315 | } |
| 7316 | if (info->shared && htab->relbrlt->size != 0) |
| 7317 | { |
| 7318 | htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner, |
| 7319 | htab->relbrlt->size); |
| 7320 | if (htab->relbrlt->contents == NULL) |
| 7321 | return FALSE; |
| 7322 | } |
| 7323 | |
| 7324 | /* Build the stubs as directed by the stub hash table. */ |
| 7325 | bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info); |
| 7326 | |
| 7327 | for (stub_sec = htab->stub_bfd->sections; |
| 7328 | stub_sec != NULL; |
| 7329 | stub_sec = stub_sec->next) |
| 7330 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) |
| 7331 | { |
| 7332 | stub_sec_count += 1; |
| 7333 | if (stub_sec->rawsize != stub_sec->size) |
| 7334 | break; |
| 7335 | } |
| 7336 | |
| 7337 | if (stub_sec != NULL |
| 7338 | || htab->glink->rawsize != htab->glink->size) |
| 7339 | { |
| 7340 | htab->stub_error = TRUE; |
| 7341 | (*_bfd_error_handler) (_("stubs don't match calculated size")); |
| 7342 | } |
| 7343 | |
| 7344 | if (htab->stub_error) |
| 7345 | return FALSE; |
| 7346 | |
| 7347 | if (stats != NULL) |
| 7348 | { |
| 7349 | *stats = bfd_malloc (500); |
| 7350 | if (*stats == NULL) |
| 7351 | return FALSE; |
| 7352 | |
| 7353 | sprintf (*stats, _("linker stubs in %u groups\n" |
| 7354 | " branch %lu\n" |
| 7355 | " toc adjust %lu\n" |
| 7356 | " long branch %lu\n" |
| 7357 | " long toc adj %lu\n" |
| 7358 | " plt call %lu"), |
| 7359 | stub_sec_count, |
| 7360 | htab->stub_count[ppc_stub_long_branch - 1], |
| 7361 | htab->stub_count[ppc_stub_long_branch_r2off - 1], |
| 7362 | htab->stub_count[ppc_stub_plt_branch - 1], |
| 7363 | htab->stub_count[ppc_stub_plt_branch_r2off - 1], |
| 7364 | htab->stub_count[ppc_stub_plt_call - 1]); |
| 7365 | } |
| 7366 | return TRUE; |
| 7367 | } |
| 7368 | |
| 7369 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
| 7370 | to handle the relocations for a section. |
| 7371 | |
| 7372 | The relocs are always passed as Rela structures; if the section |
| 7373 | actually uses Rel structures, the r_addend field will always be |
| 7374 | zero. |
| 7375 | |
| 7376 | This function is responsible for adjust the section contents as |
| 7377 | necessary, and (if using Rela relocs and generating a |
| 7378 | relocatable output file) adjusting the reloc addend as |
| 7379 | necessary. |
| 7380 | |
| 7381 | This function does not have to worry about setting the reloc |
| 7382 | address or the reloc symbol index. |
| 7383 | |
| 7384 | LOCAL_SYMS is a pointer to the swapped in local symbols. |
| 7385 | |
| 7386 | LOCAL_SECTIONS is an array giving the section in the input file |
| 7387 | corresponding to the st_shndx field of each local symbol. |
| 7388 | |
| 7389 | The global hash table entry for the global symbols can be found |
| 7390 | via elf_sym_hashes (input_bfd). |
| 7391 | |
| 7392 | When generating relocatable output, this function must handle |
| 7393 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
| 7394 | going to be the section symbol corresponding to the output |
| 7395 | section, which means that the addend must be adjusted |
| 7396 | accordingly. */ |
| 7397 | |
| 7398 | static bfd_boolean |
| 7399 | ppc64_elf_relocate_section (bfd *output_bfd, |
| 7400 | struct bfd_link_info *info, |
| 7401 | bfd *input_bfd, |
| 7402 | asection *input_section, |
| 7403 | bfd_byte *contents, |
| 7404 | Elf_Internal_Rela *relocs, |
| 7405 | Elf_Internal_Sym *local_syms, |
| 7406 | asection **local_sections) |
| 7407 | { |
| 7408 | struct ppc_link_hash_table *htab; |
| 7409 | Elf_Internal_Shdr *symtab_hdr; |
| 7410 | struct elf_link_hash_entry **sym_hashes; |
| 7411 | Elf_Internal_Rela *rel; |
| 7412 | Elf_Internal_Rela *relend; |
| 7413 | Elf_Internal_Rela outrel; |
| 7414 | bfd_byte *loc; |
| 7415 | struct got_entry **local_got_ents; |
| 7416 | bfd_vma TOCstart; |
| 7417 | bfd_boolean ret = TRUE; |
| 7418 | bfd_boolean is_opd; |
| 7419 | /* Disabled until we sort out how ld should choose 'y' vs 'at'. */ |
| 7420 | bfd_boolean is_power4 = FALSE; |
| 7421 | |
| 7422 | if (info->relocatable) |
| 7423 | return TRUE; |
| 7424 | |
| 7425 | /* Initialize howto table if needed. */ |
| 7426 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
| 7427 | ppc_howto_init (); |
| 7428 | |
| 7429 | htab = ppc_hash_table (info); |
| 7430 | local_got_ents = elf_local_got_ents (input_bfd); |
| 7431 | TOCstart = elf_gp (output_bfd); |
| 7432 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
| 7433 | sym_hashes = elf_sym_hashes (input_bfd); |
| 7434 | is_opd = ppc64_elf_section_data (input_section)->opd.adjust != NULL; |
| 7435 | |
| 7436 | rel = relocs; |
| 7437 | relend = relocs + input_section->reloc_count; |
| 7438 | for (; rel < relend; rel++) |
| 7439 | { |
| 7440 | enum elf_ppc64_reloc_type r_type; |
| 7441 | bfd_vma addend; |
| 7442 | bfd_reloc_status_type r; |
| 7443 | Elf_Internal_Sym *sym; |
| 7444 | asection *sec; |
| 7445 | struct elf_link_hash_entry *h; |
| 7446 | struct elf_link_hash_entry *fdh; |
| 7447 | const char *sym_name; |
| 7448 | unsigned long r_symndx, toc_symndx; |
| 7449 | char tls_mask, tls_gd, tls_type; |
| 7450 | char sym_type; |
| 7451 | bfd_vma relocation; |
| 7452 | bfd_boolean unresolved_reloc; |
| 7453 | bfd_boolean warned; |
| 7454 | unsigned long insn, mask; |
| 7455 | struct ppc_stub_hash_entry *stub_entry; |
| 7456 | bfd_vma max_br_offset; |
| 7457 | bfd_vma from; |
| 7458 | |
| 7459 | r_type = ELF64_R_TYPE (rel->r_info); |
| 7460 | r_symndx = ELF64_R_SYM (rel->r_info); |
| 7461 | |
| 7462 | /* For old style R_PPC64_TOC relocs with a zero symbol, use the |
| 7463 | symbol of the previous ADDR64 reloc. The symbol gives us the |
| 7464 | proper TOC base to use. */ |
| 7465 | if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC) |
| 7466 | && rel != relocs |
| 7467 | && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64 |
| 7468 | && is_opd) |
| 7469 | r_symndx = ELF64_R_SYM (rel[-1].r_info); |
| 7470 | |
| 7471 | sym = NULL; |
| 7472 | sec = NULL; |
| 7473 | h = NULL; |
| 7474 | sym_name = NULL; |
| 7475 | unresolved_reloc = FALSE; |
| 7476 | warned = FALSE; |
| 7477 | |
| 7478 | if (r_symndx < symtab_hdr->sh_info) |
| 7479 | { |
| 7480 | /* It's a local symbol. */ |
| 7481 | long *opd_adjust; |
| 7482 | |
| 7483 | sym = local_syms + r_symndx; |
| 7484 | sec = local_sections[r_symndx]; |
| 7485 | sym_name = bfd_elf_local_sym_name (input_bfd, sym); |
| 7486 | sym_type = ELF64_ST_TYPE (sym->st_info); |
| 7487 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
| 7488 | opd_adjust = get_opd_info (sec); |
| 7489 | if (opd_adjust != NULL) |
| 7490 | { |
| 7491 | long adjust = opd_adjust[(sym->st_value + rel->r_addend) / 24]; |
| 7492 | if (adjust == -1) |
| 7493 | relocation = 0; |
| 7494 | else |
| 7495 | relocation += adjust; |
| 7496 | } |
| 7497 | } |
| 7498 | else |
| 7499 | { |
| 7500 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
| 7501 | r_symndx, symtab_hdr, sym_hashes, |
| 7502 | h, sec, relocation, |
| 7503 | unresolved_reloc, warned); |
| 7504 | sym_name = h->root.root.string; |
| 7505 | sym_type = h->type; |
| 7506 | } |
| 7507 | |
| 7508 | /* TLS optimizations. Replace instruction sequences and relocs |
| 7509 | based on information we collected in tls_optimize. We edit |
| 7510 | RELOCS so that --emit-relocs will output something sensible |
| 7511 | for the final instruction stream. */ |
| 7512 | tls_mask = 0; |
| 7513 | tls_gd = 0; |
| 7514 | toc_symndx = 0; |
| 7515 | if (IS_PPC64_TLS_RELOC (r_type)) |
| 7516 | { |
| 7517 | if (h != NULL) |
| 7518 | tls_mask = ((struct ppc_link_hash_entry *) h)->tls_mask; |
| 7519 | else if (local_got_ents != NULL) |
| 7520 | { |
| 7521 | char *lgot_masks; |
| 7522 | lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info); |
| 7523 | tls_mask = lgot_masks[r_symndx]; |
| 7524 | } |
| 7525 | if (tls_mask == 0 && r_type == R_PPC64_TLS) |
| 7526 | { |
| 7527 | /* Check for toc tls entries. */ |
| 7528 | char *toc_tls; |
| 7529 | |
| 7530 | if (!get_tls_mask (&toc_tls, &toc_symndx, &local_syms, |
| 7531 | rel, input_bfd)) |
| 7532 | return FALSE; |
| 7533 | |
| 7534 | if (toc_tls) |
| 7535 | tls_mask = *toc_tls; |
| 7536 | } |
| 7537 | } |
| 7538 | |
| 7539 | /* Check that tls relocs are used with tls syms, and non-tls |
| 7540 | relocs are used with non-tls syms. */ |
| 7541 | if (r_symndx != 0 |
| 7542 | && r_type != R_PPC64_NONE |
| 7543 | && (h == NULL |
| 7544 | || h->root.type == bfd_link_hash_defined |
| 7545 | || h->root.type == bfd_link_hash_defweak) |
| 7546 | && IS_PPC64_TLS_RELOC (r_type) != (sym_type == STT_TLS)) |
| 7547 | { |
| 7548 | if (r_type == R_PPC64_TLS && tls_mask != 0) |
| 7549 | /* R_PPC64_TLS is OK against a symbol in the TOC. */ |
| 7550 | ; |
| 7551 | else |
| 7552 | (*_bfd_error_handler) |
| 7553 | (sym_type == STT_TLS |
| 7554 | ? _("%s(%s+0x%lx): %s used with TLS symbol %s") |
| 7555 | : _("%s(%s+0x%lx): %s used with non-TLS symbol %s"), |
| 7556 | bfd_archive_filename (input_bfd), |
| 7557 | input_section->name, |
| 7558 | (long) rel->r_offset, |
| 7559 | ppc64_elf_howto_table[r_type]->name, |
| 7560 | sym_name); |
| 7561 | } |
| 7562 | |
| 7563 | /* Ensure reloc mapping code below stays sane. */ |
| 7564 | if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1 |
| 7565 | || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1 |
| 7566 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3) |
| 7567 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3) |
| 7568 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3) |
| 7569 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3) |
| 7570 | || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3) |
| 7571 | || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3) |
| 7572 | || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3) |
| 7573 | || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3)) |
| 7574 | abort (); |
| 7575 | |
| 7576 | switch (r_type) |
| 7577 | { |
| 7578 | default: |
| 7579 | break; |
| 7580 | |
| 7581 | case R_PPC64_TOC16: |
| 7582 | case R_PPC64_TOC16_LO: |
| 7583 | case R_PPC64_TOC16_DS: |
| 7584 | case R_PPC64_TOC16_LO_DS: |
| 7585 | { |
| 7586 | /* Check for toc tls entries. */ |
| 7587 | char *toc_tls; |
| 7588 | int retval; |
| 7589 | |
| 7590 | retval = get_tls_mask (&toc_tls, &toc_symndx, &local_syms, |
| 7591 | rel, input_bfd); |
| 7592 | if (retval == 0) |
| 7593 | return FALSE; |
| 7594 | |
| 7595 | if (toc_tls) |
| 7596 | { |
| 7597 | tls_mask = *toc_tls; |
| 7598 | if (r_type == R_PPC64_TOC16_DS |
| 7599 | || r_type == R_PPC64_TOC16_LO_DS) |
| 7600 | { |
| 7601 | if (tls_mask != 0 |
| 7602 | && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0) |
| 7603 | goto toctprel; |
| 7604 | } |
| 7605 | else |
| 7606 | { |
| 7607 | /* If we found a GD reloc pair, then we might be |
| 7608 | doing a GD->IE transition. */ |
| 7609 | if (retval == 2) |
| 7610 | { |
| 7611 | tls_gd = TLS_TPRELGD; |
| 7612 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) |
| 7613 | goto tls_get_addr_check; |
| 7614 | } |
| 7615 | else if (retval == 3) |
| 7616 | { |
| 7617 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) |
| 7618 | goto tls_get_addr_check; |
| 7619 | } |
| 7620 | } |
| 7621 | } |
| 7622 | } |
| 7623 | break; |
| 7624 | |
| 7625 | case R_PPC64_GOT_TPREL16_DS: |
| 7626 | case R_PPC64_GOT_TPREL16_LO_DS: |
| 7627 | if (tls_mask != 0 |
| 7628 | && (tls_mask & TLS_TPREL) == 0) |
| 7629 | { |
| 7630 | toctprel: |
| 7631 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2); |
| 7632 | insn &= 31 << 21; |
| 7633 | insn |= 0x3c0d0000; /* addis 0,13,0 */ |
| 7634 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2); |
| 7635 | r_type = R_PPC64_TPREL16_HA; |
| 7636 | if (toc_symndx != 0) |
| 7637 | { |
| 7638 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); |
| 7639 | /* We changed the symbol. Start over in order to |
| 7640 | get h, sym, sec etc. right. */ |
| 7641 | rel--; |
| 7642 | continue; |
| 7643 | } |
| 7644 | else |
| 7645 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
| 7646 | } |
| 7647 | break; |
| 7648 | |
| 7649 | case R_PPC64_TLS: |
| 7650 | if (tls_mask != 0 |
| 7651 | && (tls_mask & TLS_TPREL) == 0) |
| 7652 | { |
| 7653 | bfd_vma rtra; |
| 7654 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
| 7655 | if ((insn & ((0x3f << 26) | (31 << 11))) |
| 7656 | == ((31 << 26) | (13 << 11))) |
| 7657 | rtra = insn & ((1 << 26) - (1 << 16)); |
| 7658 | else if ((insn & ((0x3f << 26) | (31 << 16))) |
| 7659 | == ((31 << 26) | (13 << 16))) |
| 7660 | rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5); |
| 7661 | else |
| 7662 | abort (); |
| 7663 | if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1) |
| 7664 | /* add -> addi. */ |
| 7665 | insn = 14 << 26; |
| 7666 | else if ((insn & (31 << 1)) == 23 << 1 |
| 7667 | && ((insn & (31 << 6)) < 14 << 6 |
| 7668 | || ((insn & (31 << 6)) >= 16 << 6 |
| 7669 | && (insn & (31 << 6)) < 24 << 6))) |
| 7670 | /* load and store indexed -> dform. */ |
| 7671 | insn = (32 | ((insn >> 6) & 31)) << 26; |
| 7672 | else if ((insn & (31 << 1)) == 21 << 1 |
| 7673 | && (insn & (0x1a << 6)) == 0) |
| 7674 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ |
| 7675 | insn = (((58 | ((insn >> 6) & 4)) << 26) |
| 7676 | | ((insn >> 6) & 1)); |
| 7677 | else if ((insn & (31 << 1)) == 21 << 1 |
| 7678 | && (insn & ((1 << 11) - (1 << 1))) == 341 << 1) |
| 7679 | /* lwax -> lwa. */ |
| 7680 | insn = (58 << 26) | 2; |
| 7681 | else |
| 7682 | abort (); |
| 7683 | insn |= rtra; |
| 7684 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
| 7685 | /* Was PPC64_TLS which sits on insn boundary, now |
| 7686 | PPC64_TPREL16_LO which is at insn+2. */ |
| 7687 | rel->r_offset += 2; |
| 7688 | r_type = R_PPC64_TPREL16_LO; |
| 7689 | if (toc_symndx != 0) |
| 7690 | { |
| 7691 | rel->r_info = ELF64_R_INFO (toc_symndx, r_type); |
| 7692 | /* We changed the symbol. Start over in order to |
| 7693 | get h, sym, sec etc. right. */ |
| 7694 | rel--; |
| 7695 | continue; |
| 7696 | } |
| 7697 | else |
| 7698 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
| 7699 | } |
| 7700 | break; |
| 7701 | |
| 7702 | case R_PPC64_GOT_TLSGD16_HI: |
| 7703 | case R_PPC64_GOT_TLSGD16_HA: |
| 7704 | tls_gd = TLS_TPRELGD; |
| 7705 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) |
| 7706 | goto tls_gdld_hi; |
| 7707 | break; |
| 7708 | |
| 7709 | case R_PPC64_GOT_TLSLD16_HI: |
| 7710 | case R_PPC64_GOT_TLSLD16_HA: |
| 7711 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) |
| 7712 | { |
| 7713 | tls_gdld_hi: |
| 7714 | if ((tls_mask & tls_gd) != 0) |
| 7715 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) |
| 7716 | + R_PPC64_GOT_TPREL16_DS); |
| 7717 | else |
| 7718 | { |
| 7719 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
| 7720 | rel->r_offset -= 2; |
| 7721 | r_type = R_PPC64_NONE; |
| 7722 | } |
| 7723 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
| 7724 | } |
| 7725 | break; |
| 7726 | |
| 7727 | case R_PPC64_GOT_TLSGD16: |
| 7728 | case R_PPC64_GOT_TLSGD16_LO: |
| 7729 | tls_gd = TLS_TPRELGD; |
| 7730 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) |
| 7731 | goto tls_get_addr_check; |
| 7732 | break; |
| 7733 | |
| 7734 | case R_PPC64_GOT_TLSLD16: |
| 7735 | case R_PPC64_GOT_TLSLD16_LO: |
| 7736 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) |
| 7737 | { |
| 7738 | tls_get_addr_check: |
| 7739 | if (rel + 1 < relend) |
| 7740 | { |
| 7741 | enum elf_ppc64_reloc_type r_type2; |
| 7742 | unsigned long r_symndx2; |
| 7743 | struct elf_link_hash_entry *h2; |
| 7744 | bfd_vma insn1, insn2, insn3; |
| 7745 | bfd_vma offset; |
| 7746 | |
| 7747 | /* The next instruction should be a call to |
| 7748 | __tls_get_addr. Peek at the reloc to be sure. */ |
| 7749 | r_type2 = ELF64_R_TYPE (rel[1].r_info); |
| 7750 | r_symndx2 = ELF64_R_SYM (rel[1].r_info); |
| 7751 | if (r_symndx2 < symtab_hdr->sh_info |
| 7752 | || (r_type2 != R_PPC64_REL14 |
| 7753 | && r_type2 != R_PPC64_REL14_BRTAKEN |
| 7754 | && r_type2 != R_PPC64_REL14_BRNTAKEN |
| 7755 | && r_type2 != R_PPC64_REL24)) |
| 7756 | break; |
| 7757 | |
| 7758 | h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info]; |
| 7759 | while (h2->root.type == bfd_link_hash_indirect |
| 7760 | || h2->root.type == bfd_link_hash_warning) |
| 7761 | h2 = (struct elf_link_hash_entry *) h2->root.u.i.link; |
| 7762 | if (h2 == NULL || h2 != htab->tls_get_addr) |
| 7763 | break; |
| 7764 | |
| 7765 | /* OK, it checks out. Replace the call. */ |
| 7766 | offset = rel[1].r_offset; |
| 7767 | insn1 = bfd_get_32 (output_bfd, |
| 7768 | contents + rel->r_offset - 2); |
| 7769 | insn3 = bfd_get_32 (output_bfd, |
| 7770 | contents + offset + 4); |
| 7771 | if ((tls_mask & tls_gd) != 0) |
| 7772 | { |
| 7773 | /* IE */ |
| 7774 | insn1 &= (1 << 26) - (1 << 2); |
| 7775 | insn1 |= 58 << 26; /* ld */ |
| 7776 | insn2 = 0x7c636a14; /* add 3,3,13 */ |
| 7777 | rel[1].r_info = ELF64_R_INFO (r_symndx2, R_PPC64_NONE); |
| 7778 | if ((tls_mask & TLS_EXPLICIT) == 0) |
| 7779 | r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) |
| 7780 | + R_PPC64_GOT_TPREL16_DS); |
| 7781 | else |
| 7782 | r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16; |
| 7783 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
| 7784 | } |
| 7785 | else |
| 7786 | { |
| 7787 | /* LE */ |
| 7788 | insn1 = 0x3c6d0000; /* addis 3,13,0 */ |
| 7789 | insn2 = 0x38630000; /* addi 3,3,0 */ |
| 7790 | if (tls_gd == 0) |
| 7791 | { |
| 7792 | /* Was an LD reloc. */ |
| 7793 | r_symndx = 0; |
| 7794 | rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
| 7795 | rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; |
| 7796 | } |
| 7797 | else if (toc_symndx != 0) |
| 7798 | r_symndx = toc_symndx; |
| 7799 | r_type = R_PPC64_TPREL16_HA; |
| 7800 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
| 7801 | rel[1].r_info = ELF64_R_INFO (r_symndx, |
| 7802 | R_PPC64_TPREL16_LO); |
| 7803 | rel[1].r_offset += 2; |
| 7804 | } |
| 7805 | if (insn3 == NOP |
| 7806 | || insn3 == CROR_151515 || insn3 == CROR_313131) |
| 7807 | { |
| 7808 | insn3 = insn2; |
| 7809 | insn2 = NOP; |
| 7810 | rel[1].r_offset += 4; |
| 7811 | } |
| 7812 | bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2); |
| 7813 | bfd_put_32 (output_bfd, insn2, contents + offset); |
| 7814 | bfd_put_32 (output_bfd, insn3, contents + offset + 4); |
| 7815 | if (tls_gd == 0 || toc_symndx != 0) |
| 7816 | { |
| 7817 | /* We changed the symbol. Start over in order |
| 7818 | to get h, sym, sec etc. right. */ |
| 7819 | rel--; |
| 7820 | continue; |
| 7821 | } |
| 7822 | } |
| 7823 | } |
| 7824 | break; |
| 7825 | |
| 7826 | case R_PPC64_DTPMOD64: |
| 7827 | if (rel + 1 < relend |
| 7828 | && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) |
| 7829 | && rel[1].r_offset == rel->r_offset + 8) |
| 7830 | { |
| 7831 | if ((tls_mask & TLS_GD) == 0) |
| 7832 | { |
| 7833 | rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE); |
| 7834 | if ((tls_mask & TLS_TPRELGD) != 0) |
| 7835 | r_type = R_PPC64_TPREL64; |
| 7836 | else |
| 7837 | { |
| 7838 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
| 7839 | r_type = R_PPC64_NONE; |
| 7840 | } |
| 7841 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
| 7842 | } |
| 7843 | } |
| 7844 | else |
| 7845 | { |
| 7846 | if ((tls_mask & TLS_LD) == 0) |
| 7847 | { |
| 7848 | bfd_put_64 (output_bfd, 1, contents + rel->r_offset); |
| 7849 | r_type = R_PPC64_NONE; |
| 7850 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
| 7851 | } |
| 7852 | } |
| 7853 | break; |
| 7854 | |
| 7855 | case R_PPC64_TPREL64: |
| 7856 | if ((tls_mask & TLS_TPREL) == 0) |
| 7857 | { |
| 7858 | r_type = R_PPC64_NONE; |
| 7859 | rel->r_info = ELF64_R_INFO (r_symndx, r_type); |
| 7860 | } |
| 7861 | break; |
| 7862 | } |
| 7863 | |
| 7864 | /* Handle other relocations that tweak non-addend part of insn. */ |
| 7865 | insn = 0; |
| 7866 | max_br_offset = 1 << 25; |
| 7867 | addend = rel->r_addend; |
| 7868 | switch (r_type) |
| 7869 | { |
| 7870 | default: |
| 7871 | break; |
| 7872 | |
| 7873 | /* Branch taken prediction relocations. */ |
| 7874 | case R_PPC64_ADDR14_BRTAKEN: |
| 7875 | case R_PPC64_REL14_BRTAKEN: |
| 7876 | insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */ |
| 7877 | /* Fall thru. */ |
| 7878 | |
| 7879 | /* Branch not taken prediction relocations. */ |
| 7880 | case R_PPC64_ADDR14_BRNTAKEN: |
| 7881 | case R_PPC64_REL14_BRNTAKEN: |
| 7882 | insn |= bfd_get_32 (output_bfd, |
| 7883 | contents + rel->r_offset) & ~(0x01 << 21); |
| 7884 | /* Fall thru. */ |
| 7885 | |
| 7886 | case R_PPC64_REL14: |
| 7887 | max_br_offset = 1 << 15; |
| 7888 | /* Fall thru. */ |
| 7889 | |
| 7890 | case R_PPC64_REL24: |
| 7891 | /* Calls to functions with a different TOC, such as calls to |
| 7892 | shared objects, need to alter the TOC pointer. This is |
| 7893 | done using a linkage stub. A REL24 branching to these |
| 7894 | linkage stubs needs to be followed by a nop, as the nop |
| 7895 | will be replaced with an instruction to restore the TOC |
| 7896 | base pointer. */ |
| 7897 | stub_entry = NULL; |
| 7898 | if (((h != NULL |
| 7899 | && (fdh = &((struct ppc_link_hash_entry *) h)->oh->elf) != NULL |
| 7900 | && fdh->plt.plist != NULL) |
| 7901 | || ((fdh = h, sec) != NULL |
| 7902 | && sec->output_section != NULL |
| 7903 | && sec->id <= htab->top_id |
| 7904 | && (htab->stub_group[sec->id].toc_off |
| 7905 | != htab->stub_group[input_section->id].toc_off))) |
| 7906 | && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh, |
| 7907 | rel, htab)) != NULL |
| 7908 | && (stub_entry->stub_type == ppc_stub_plt_call |
| 7909 | || stub_entry->stub_type == ppc_stub_plt_branch_r2off |
| 7910 | || stub_entry->stub_type == ppc_stub_long_branch_r2off)) |
| 7911 | { |
| 7912 | bfd_boolean can_plt_call = FALSE; |
| 7913 | |
| 7914 | if (rel->r_offset + 8 <= input_section->size) |
| 7915 | { |
| 7916 | unsigned long nop; |
| 7917 | nop = bfd_get_32 (input_bfd, contents + rel->r_offset + 4); |
| 7918 | if (nop == NOP |
| 7919 | || nop == CROR_151515 || nop == CROR_313131) |
| 7920 | { |
| 7921 | bfd_put_32 (input_bfd, LD_R2_40R1, |
| 7922 | contents + rel->r_offset + 4); |
| 7923 | can_plt_call = TRUE; |
| 7924 | } |
| 7925 | } |
| 7926 | |
| 7927 | if (!can_plt_call) |
| 7928 | { |
| 7929 | if (stub_entry->stub_type == ppc_stub_plt_call) |
| 7930 | { |
| 7931 | /* If this is a plain branch rather than a branch |
| 7932 | and link, don't require a nop. */ |
| 7933 | unsigned long br; |
| 7934 | br = bfd_get_32 (input_bfd, contents + rel->r_offset); |
| 7935 | if ((br & 1) == 0) |
| 7936 | can_plt_call = TRUE; |
| 7937 | } |
| 7938 | else if (h != NULL |
| 7939 | && strcmp (h->root.root.string, |
| 7940 | ".__libc_start_main") == 0) |
| 7941 | { |
| 7942 | /* Allow crt1 branch to go via a toc adjusting stub. */ |
| 7943 | can_plt_call = TRUE; |
| 7944 | } |
| 7945 | else |
| 7946 | { |
| 7947 | if (strcmp (input_section->output_section->name, |
| 7948 | ".init") == 0 |
| 7949 | || strcmp (input_section->output_section->name, |
| 7950 | ".fini") == 0) |
| 7951 | (*_bfd_error_handler) |
| 7952 | (_("%s(%s+0x%lx): automatic multiple TOCs " |
| 7953 | "not supported using your crt files; " |
| 7954 | "recompile with -mminimal-toc or upgrade gcc"), |
| 7955 | bfd_archive_filename (input_bfd), |
| 7956 | input_section->name, |
| 7957 | (long) rel->r_offset); |
| 7958 | else |
| 7959 | (*_bfd_error_handler) |
| 7960 | (_("%s(%s+0x%lx): sibling call optimization to `%s' " |
| 7961 | "does not allow automatic multiple TOCs; " |
| 7962 | "recompile with -mminimal-toc or " |
| 7963 | "-fno-optimize-sibling-calls, " |
| 7964 | "or make `%s' extern"), |
| 7965 | bfd_archive_filename (input_bfd), |
| 7966 | input_section->name, |
| 7967 | (long) rel->r_offset, |
| 7968 | sym_name, |
| 7969 | sym_name); |
| 7970 | bfd_set_error (bfd_error_bad_value); |
| 7971 | ret = FALSE; |
| 7972 | } |
| 7973 | } |
| 7974 | |
| 7975 | if (can_plt_call |
| 7976 | && stub_entry->stub_type == ppc_stub_plt_call) |
| 7977 | unresolved_reloc = FALSE; |
| 7978 | } |
| 7979 | |
| 7980 | /* If the branch is out of reach we ought to have a long |
| 7981 | branch stub. */ |
| 7982 | from = (rel->r_offset |
| 7983 | + input_section->output_offset |
| 7984 | + input_section->output_section->vma); |
| 7985 | |
| 7986 | if (stub_entry == NULL |
| 7987 | && (relocation + rel->r_addend - from + max_br_offset |
| 7988 | >= 2 * max_br_offset) |
| 7989 | && r_type != R_PPC64_ADDR14_BRTAKEN |
| 7990 | && r_type != R_PPC64_ADDR14_BRNTAKEN) |
| 7991 | stub_entry = ppc_get_stub_entry (input_section, sec, h, rel, htab); |
| 7992 | |
| 7993 | if (stub_entry != NULL) |
| 7994 | { |
| 7995 | /* Munge up the value and addend so that we call the stub |
| 7996 | rather than the procedure directly. */ |
| 7997 | relocation = (stub_entry->stub_offset |
| 7998 | + stub_entry->stub_sec->output_offset |
| 7999 | + stub_entry->stub_sec->output_section->vma); |
| 8000 | addend = 0; |
| 8001 | } |
| 8002 | |
| 8003 | if (insn != 0) |
| 8004 | { |
| 8005 | if (is_power4) |
| 8006 | { |
| 8007 | /* Set 'a' bit. This is 0b00010 in BO field for branch |
| 8008 | on CR(BI) insns (BO == 001at or 011at), and 0b01000 |
| 8009 | for branch on CTR insns (BO == 1a00t or 1a01t). */ |
| 8010 | if ((insn & (0x14 << 21)) == (0x04 << 21)) |
| 8011 | insn |= 0x02 << 21; |
| 8012 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) |
| 8013 | insn |= 0x08 << 21; |
| 8014 | else |
| 8015 | break; |
| 8016 | } |
| 8017 | else |
| 8018 | { |
| 8019 | /* Invert 'y' bit if not the default. */ |
| 8020 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) |
| 8021 | insn ^= 0x01 << 21; |
| 8022 | } |
| 8023 | |
| 8024 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
| 8025 | } |
| 8026 | |
| 8027 | /* NOP out calls to undefined weak functions. |
| 8028 | We can thus call a weak function without first |
| 8029 | checking whether the function is defined. */ |
| 8030 | else if (h != NULL |
| 8031 | && h->root.type == bfd_link_hash_undefweak |
| 8032 | && r_type == R_PPC64_REL24 |
| 8033 | && relocation == 0 |
| 8034 | && rel->r_addend == 0) |
| 8035 | { |
| 8036 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); |
| 8037 | continue; |
| 8038 | } |
| 8039 | break; |
| 8040 | } |
| 8041 | |
| 8042 | /* Set `addend'. */ |
| 8043 | tls_type = 0; |
| 8044 | switch (r_type) |
| 8045 | { |
| 8046 | default: |
| 8047 | (*_bfd_error_handler) |
| 8048 | (_("%s: unknown relocation type %d for symbol %s"), |
| 8049 | bfd_archive_filename (input_bfd), (int) r_type, sym_name); |
| 8050 | |
| 8051 | bfd_set_error (bfd_error_bad_value); |
| 8052 | ret = FALSE; |
| 8053 | continue; |
| 8054 | |
| 8055 | case R_PPC64_NONE: |
| 8056 | case R_PPC64_TLS: |
| 8057 | case R_PPC64_GNU_VTINHERIT: |
| 8058 | case R_PPC64_GNU_VTENTRY: |
| 8059 | continue; |
| 8060 | |
| 8061 | /* GOT16 relocations. Like an ADDR16 using the symbol's |
| 8062 | address in the GOT as relocation value instead of the |
| 8063 | symbol's value itself. Also, create a GOT entry for the |
| 8064 | symbol and put the symbol value there. */ |
| 8065 | case R_PPC64_GOT_TLSGD16: |
| 8066 | case R_PPC64_GOT_TLSGD16_LO: |
| 8067 | case R_PPC64_GOT_TLSGD16_HI: |
| 8068 | case R_PPC64_GOT_TLSGD16_HA: |
| 8069 | tls_type = TLS_TLS | TLS_GD; |
| 8070 | goto dogot; |
| 8071 | |
| 8072 | case R_PPC64_GOT_TLSLD16: |
| 8073 | case R_PPC64_GOT_TLSLD16_LO: |
| 8074 | case R_PPC64_GOT_TLSLD16_HI: |
| 8075 | case R_PPC64_GOT_TLSLD16_HA: |
| 8076 | tls_type = TLS_TLS | TLS_LD; |
| 8077 | goto dogot; |
| 8078 | |
| 8079 | case R_PPC64_GOT_TPREL16_DS: |
| 8080 | case R_PPC64_GOT_TPREL16_LO_DS: |
| 8081 | case R_PPC64_GOT_TPREL16_HI: |
| 8082 | case R_PPC64_GOT_TPREL16_HA: |
| 8083 | tls_type = TLS_TLS | TLS_TPREL; |
| 8084 | goto dogot; |
| 8085 | |
| 8086 | case R_PPC64_GOT_DTPREL16_DS: |
| 8087 | case R_PPC64_GOT_DTPREL16_LO_DS: |
| 8088 | case R_PPC64_GOT_DTPREL16_HI: |
| 8089 | case R_PPC64_GOT_DTPREL16_HA: |
| 8090 | tls_type = TLS_TLS | TLS_DTPREL; |
| 8091 | goto dogot; |
| 8092 | |
| 8093 | case R_PPC64_GOT16: |
| 8094 | case R_PPC64_GOT16_LO: |
| 8095 | case R_PPC64_GOT16_HI: |
| 8096 | case R_PPC64_GOT16_HA: |
| 8097 | case R_PPC64_GOT16_DS: |
| 8098 | case R_PPC64_GOT16_LO_DS: |
| 8099 | dogot: |
| 8100 | { |
| 8101 | /* Relocation is to the entry for this symbol in the global |
| 8102 | offset table. */ |
| 8103 | asection *got; |
| 8104 | bfd_vma *offp; |
| 8105 | bfd_vma off; |
| 8106 | unsigned long indx = 0; |
| 8107 | |
| 8108 | if (tls_type == (TLS_TLS | TLS_LD) |
| 8109 | && (h == NULL |
| 8110 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) |
| 8111 | offp = &ppc64_tlsld_got (input_bfd)->offset; |
| 8112 | else |
| 8113 | { |
| 8114 | struct got_entry *ent; |
| 8115 | |
| 8116 | if (h != NULL) |
| 8117 | { |
| 8118 | bfd_boolean dyn = htab->elf.dynamic_sections_created; |
| 8119 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
| 8120 | || (info->shared |
| 8121 | && SYMBOL_REFERENCES_LOCAL (info, h))) |
| 8122 | /* This is actually a static link, or it is a |
| 8123 | -Bsymbolic link and the symbol is defined |
| 8124 | locally, or the symbol was forced to be local |
| 8125 | because of a version file. */ |
| 8126 | ; |
| 8127 | else |
| 8128 | { |
| 8129 | indx = h->dynindx; |
| 8130 | unresolved_reloc = FALSE; |
| 8131 | } |
| 8132 | ent = h->got.glist; |
| 8133 | } |
| 8134 | else |
| 8135 | { |
| 8136 | if (local_got_ents == NULL) |
| 8137 | abort (); |
| 8138 | ent = local_got_ents[r_symndx]; |
| 8139 | } |
| 8140 | |
| 8141 | for (; ent != NULL; ent = ent->next) |
| 8142 | if (ent->addend == rel->r_addend |
| 8143 | && ent->owner == input_bfd |
| 8144 | && ent->tls_type == tls_type) |
| 8145 | break; |
| 8146 | if (ent == NULL) |
| 8147 | abort (); |
| 8148 | offp = &ent->got.offset; |
| 8149 | } |
| 8150 | |
| 8151 | got = ppc64_elf_tdata (input_bfd)->got; |
| 8152 | if (got == NULL) |
| 8153 | abort (); |
| 8154 | |
| 8155 | /* The offset must always be a multiple of 8. We use the |
| 8156 | least significant bit to record whether we have already |
| 8157 | processed this entry. */ |
| 8158 | off = *offp; |
| 8159 | if ((off & 1) != 0) |
| 8160 | off &= ~1; |
| 8161 | else |
| 8162 | { |
| 8163 | /* Generate relocs for the dynamic linker, except in |
| 8164 | the case of TLSLD where we'll use one entry per |
| 8165 | module. */ |
| 8166 | asection *relgot = ppc64_elf_tdata (input_bfd)->relgot; |
| 8167 | |
| 8168 | *offp = off | 1; |
| 8169 | if ((info->shared || indx != 0) |
| 8170 | && (h == NULL |
| 8171 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
| 8172 | || h->root.type != bfd_link_hash_undefweak)) |
| 8173 | { |
| 8174 | outrel.r_offset = (got->output_section->vma |
| 8175 | + got->output_offset |
| 8176 | + off); |
| 8177 | outrel.r_addend = rel->r_addend; |
| 8178 | if (tls_type & (TLS_LD | TLS_GD)) |
| 8179 | { |
| 8180 | outrel.r_addend = 0; |
| 8181 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64); |
| 8182 | if (tls_type == (TLS_TLS | TLS_GD)) |
| 8183 | { |
| 8184 | loc = relgot->contents; |
| 8185 | loc += (relgot->reloc_count++ |
| 8186 | * sizeof (Elf64_External_Rela)); |
| 8187 | bfd_elf64_swap_reloca_out (output_bfd, |
| 8188 | &outrel, loc); |
| 8189 | outrel.r_offset += 8; |
| 8190 | outrel.r_addend = rel->r_addend; |
| 8191 | outrel.r_info |
| 8192 | = ELF64_R_INFO (indx, R_PPC64_DTPREL64); |
| 8193 | } |
| 8194 | } |
| 8195 | else if (tls_type == (TLS_TLS | TLS_DTPREL)) |
| 8196 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64); |
| 8197 | else if (tls_type == (TLS_TLS | TLS_TPREL)) |
| 8198 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64); |
| 8199 | else if (indx == 0) |
| 8200 | { |
| 8201 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE); |
| 8202 | |
| 8203 | /* Write the .got section contents for the sake |
| 8204 | of prelink. */ |
| 8205 | loc = got->contents + off; |
| 8206 | bfd_put_64 (output_bfd, outrel.r_addend + relocation, |
| 8207 | loc); |
| 8208 | } |
| 8209 | else |
| 8210 | outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT); |
| 8211 | |
| 8212 | if (indx == 0 && tls_type != (TLS_TLS | TLS_LD)) |
| 8213 | { |
| 8214 | outrel.r_addend += relocation; |
| 8215 | if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL)) |
| 8216 | outrel.r_addend -= htab->elf.tls_sec->vma; |
| 8217 | } |
| 8218 | loc = relgot->contents; |
| 8219 | loc += (relgot->reloc_count++ |
| 8220 | * sizeof (Elf64_External_Rela)); |
| 8221 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
| 8222 | } |
| 8223 | |
| 8224 | /* Init the .got section contents here if we're not |
| 8225 | emitting a reloc. */ |
| 8226 | else |
| 8227 | { |
| 8228 | relocation += rel->r_addend; |
| 8229 | if (tls_type == (TLS_TLS | TLS_LD)) |
| 8230 | relocation = 1; |
| 8231 | else if (tls_type != 0) |
| 8232 | { |
| 8233 | relocation -= htab->elf.tls_sec->vma + DTP_OFFSET; |
| 8234 | if (tls_type == (TLS_TLS | TLS_TPREL)) |
| 8235 | relocation += DTP_OFFSET - TP_OFFSET; |
| 8236 | |
| 8237 | if (tls_type == (TLS_TLS | TLS_GD)) |
| 8238 | { |
| 8239 | bfd_put_64 (output_bfd, relocation, |
| 8240 | got->contents + off + 8); |
| 8241 | relocation = 1; |
| 8242 | } |
| 8243 | } |
| 8244 | |
| 8245 | bfd_put_64 (output_bfd, relocation, |
| 8246 | got->contents + off); |
| 8247 | } |
| 8248 | } |
| 8249 | |
| 8250 | if (off >= (bfd_vma) -2) |
| 8251 | abort (); |
| 8252 | |
| 8253 | relocation = got->output_offset + off; |
| 8254 | |
| 8255 | /* TOC base (r2) is TOC start plus 0x8000. */ |
| 8256 | addend = -TOC_BASE_OFF; |
| 8257 | } |
| 8258 | break; |
| 8259 | |
| 8260 | case R_PPC64_PLT16_HA: |
| 8261 | case R_PPC64_PLT16_HI: |
| 8262 | case R_PPC64_PLT16_LO: |
| 8263 | case R_PPC64_PLT32: |
| 8264 | case R_PPC64_PLT64: |
| 8265 | /* Relocation is to the entry for this symbol in the |
| 8266 | procedure linkage table. */ |
| 8267 | |
| 8268 | /* Resolve a PLT reloc against a local symbol directly, |
| 8269 | without using the procedure linkage table. */ |
| 8270 | if (h == NULL) |
| 8271 | break; |
| 8272 | |
| 8273 | /* It's possible that we didn't make a PLT entry for this |
| 8274 | symbol. This happens when statically linking PIC code, |
| 8275 | or when using -Bsymbolic. Go find a match if there is a |
| 8276 | PLT entry. */ |
| 8277 | if (htab->plt != NULL) |
| 8278 | { |
| 8279 | struct plt_entry *ent; |
| 8280 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
| 8281 | if (ent->addend == rel->r_addend |
| 8282 | && ent->plt.offset != (bfd_vma) -1) |
| 8283 | { |
| 8284 | relocation = (htab->plt->output_section->vma |
| 8285 | + htab->plt->output_offset |
| 8286 | + ent->plt.offset); |
| 8287 | unresolved_reloc = FALSE; |
| 8288 | } |
| 8289 | } |
| 8290 | break; |
| 8291 | |
| 8292 | case R_PPC64_TOC: |
| 8293 | /* Relocation value is TOC base. */ |
| 8294 | relocation = TOCstart; |
| 8295 | if (r_symndx == 0) |
| 8296 | relocation += htab->stub_group[input_section->id].toc_off; |
| 8297 | else if (unresolved_reloc) |
| 8298 | ; |
| 8299 | else if (sec != NULL && sec->id <= htab->top_id) |
| 8300 | relocation += htab->stub_group[sec->id].toc_off; |
| 8301 | else |
| 8302 | unresolved_reloc = TRUE; |
| 8303 | goto dodyn2; |
| 8304 | |
| 8305 | /* TOC16 relocs. We want the offset relative to the TOC base, |
| 8306 | which is the address of the start of the TOC plus 0x8000. |
| 8307 | The TOC consists of sections .got, .toc, .tocbss, and .plt, |
| 8308 | in this order. */ |
| 8309 | case R_PPC64_TOC16: |
| 8310 | case R_PPC64_TOC16_LO: |
| 8311 | case R_PPC64_TOC16_HI: |
| 8312 | case R_PPC64_TOC16_DS: |
| 8313 | case R_PPC64_TOC16_LO_DS: |
| 8314 | case R_PPC64_TOC16_HA: |
| 8315 | addend -= TOCstart + htab->stub_group[input_section->id].toc_off; |
| 8316 | break; |
| 8317 | |
| 8318 | /* Relocate against the beginning of the section. */ |
| 8319 | case R_PPC64_SECTOFF: |
| 8320 | case R_PPC64_SECTOFF_LO: |
| 8321 | case R_PPC64_SECTOFF_HI: |
| 8322 | case R_PPC64_SECTOFF_DS: |
| 8323 | case R_PPC64_SECTOFF_LO_DS: |
| 8324 | case R_PPC64_SECTOFF_HA: |
| 8325 | if (sec != NULL) |
| 8326 | addend -= sec->output_section->vma; |
| 8327 | break; |
| 8328 | |
| 8329 | case R_PPC64_REL14: |
| 8330 | case R_PPC64_REL14_BRNTAKEN: |
| 8331 | case R_PPC64_REL14_BRTAKEN: |
| 8332 | case R_PPC64_REL24: |
| 8333 | break; |
| 8334 | |
| 8335 | case R_PPC64_TPREL16: |
| 8336 | case R_PPC64_TPREL16_LO: |
| 8337 | case R_PPC64_TPREL16_HI: |
| 8338 | case R_PPC64_TPREL16_HA: |
| 8339 | case R_PPC64_TPREL16_DS: |
| 8340 | case R_PPC64_TPREL16_LO_DS: |
| 8341 | case R_PPC64_TPREL16_HIGHER: |
| 8342 | case R_PPC64_TPREL16_HIGHERA: |
| 8343 | case R_PPC64_TPREL16_HIGHEST: |
| 8344 | case R_PPC64_TPREL16_HIGHESTA: |
| 8345 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
| 8346 | if (info->shared) |
| 8347 | /* The TPREL16 relocs shouldn't really be used in shared |
| 8348 | libs as they will result in DT_TEXTREL being set, but |
| 8349 | support them anyway. */ |
| 8350 | goto dodyn; |
| 8351 | break; |
| 8352 | |
| 8353 | case R_PPC64_DTPREL16: |
| 8354 | case R_PPC64_DTPREL16_LO: |
| 8355 | case R_PPC64_DTPREL16_HI: |
| 8356 | case R_PPC64_DTPREL16_HA: |
| 8357 | case R_PPC64_DTPREL16_DS: |
| 8358 | case R_PPC64_DTPREL16_LO_DS: |
| 8359 | case R_PPC64_DTPREL16_HIGHER: |
| 8360 | case R_PPC64_DTPREL16_HIGHERA: |
| 8361 | case R_PPC64_DTPREL16_HIGHEST: |
| 8362 | case R_PPC64_DTPREL16_HIGHESTA: |
| 8363 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
| 8364 | break; |
| 8365 | |
| 8366 | case R_PPC64_DTPMOD64: |
| 8367 | relocation = 1; |
| 8368 | addend = 0; |
| 8369 | goto dodyn; |
| 8370 | |
| 8371 | case R_PPC64_TPREL64: |
| 8372 | addend -= htab->elf.tls_sec->vma + TP_OFFSET; |
| 8373 | goto dodyn; |
| 8374 | |
| 8375 | case R_PPC64_DTPREL64: |
| 8376 | addend -= htab->elf.tls_sec->vma + DTP_OFFSET; |
| 8377 | /* Fall thru */ |
| 8378 | |
| 8379 | /* Relocations that may need to be propagated if this is a |
| 8380 | dynamic object. */ |
| 8381 | case R_PPC64_REL30: |
| 8382 | case R_PPC64_REL32: |
| 8383 | case R_PPC64_REL64: |
| 8384 | case R_PPC64_ADDR14: |
| 8385 | case R_PPC64_ADDR14_BRNTAKEN: |
| 8386 | case R_PPC64_ADDR14_BRTAKEN: |
| 8387 | case R_PPC64_ADDR16: |
| 8388 | case R_PPC64_ADDR16_DS: |
| 8389 | case R_PPC64_ADDR16_HA: |
| 8390 | case R_PPC64_ADDR16_HI: |
| 8391 | case R_PPC64_ADDR16_HIGHER: |
| 8392 | case R_PPC64_ADDR16_HIGHERA: |
| 8393 | case R_PPC64_ADDR16_HIGHEST: |
| 8394 | case R_PPC64_ADDR16_HIGHESTA: |
| 8395 | case R_PPC64_ADDR16_LO: |
| 8396 | case R_PPC64_ADDR16_LO_DS: |
| 8397 | case R_PPC64_ADDR24: |
| 8398 | case R_PPC64_ADDR32: |
| 8399 | case R_PPC64_ADDR64: |
| 8400 | case R_PPC64_UADDR16: |
| 8401 | case R_PPC64_UADDR32: |
| 8402 | case R_PPC64_UADDR64: |
| 8403 | /* r_symndx will be zero only for relocs against symbols |
| 8404 | from removed linkonce sections, or sections discarded by |
| 8405 | a linker script. */ |
| 8406 | dodyn: |
| 8407 | if (r_symndx == 0) |
| 8408 | break; |
| 8409 | /* Fall thru. */ |
| 8410 | |
| 8411 | dodyn2: |
| 8412 | if ((input_section->flags & SEC_ALLOC) == 0) |
| 8413 | break; |
| 8414 | |
| 8415 | if (NO_OPD_RELOCS && is_opd) |
| 8416 | break; |
| 8417 | |
| 8418 | if ((info->shared |
| 8419 | && (h == NULL |
| 8420 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
| 8421 | || h->root.type != bfd_link_hash_undefweak) |
| 8422 | && (MUST_BE_DYN_RELOC (r_type) |
| 8423 | || !SYMBOL_CALLS_LOCAL (info, h))) |
| 8424 | || (ELIMINATE_COPY_RELOCS |
| 8425 | && !info->shared |
| 8426 | && h != NULL |
| 8427 | && h->dynindx != -1 |
| 8428 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 |
| 8429 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
| 8430 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)) |
| 8431 | { |
| 8432 | Elf_Internal_Rela outrel; |
| 8433 | bfd_boolean skip, relocate; |
| 8434 | asection *sreloc; |
| 8435 | bfd_byte *loc; |
| 8436 | bfd_vma out_off; |
| 8437 | |
| 8438 | /* When generating a dynamic object, these relocations |
| 8439 | are copied into the output file to be resolved at run |
| 8440 | time. */ |
| 8441 | |
| 8442 | skip = FALSE; |
| 8443 | relocate = FALSE; |
| 8444 | |
| 8445 | out_off = _bfd_elf_section_offset (output_bfd, info, |
| 8446 | input_section, rel->r_offset); |
| 8447 | if (out_off == (bfd_vma) -1) |
| 8448 | skip = TRUE; |
| 8449 | else if (out_off == (bfd_vma) -2) |
| 8450 | skip = TRUE, relocate = TRUE; |
| 8451 | out_off += (input_section->output_section->vma |
| 8452 | + input_section->output_offset); |
| 8453 | outrel.r_offset = out_off; |
| 8454 | outrel.r_addend = rel->r_addend; |
| 8455 | |
| 8456 | /* Optimize unaligned reloc use. */ |
| 8457 | if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0) |
| 8458 | || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0)) |
| 8459 | r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64; |
| 8460 | else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0) |
| 8461 | || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0)) |
| 8462 | r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32; |
| 8463 | else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0) |
| 8464 | || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0)) |
| 8465 | r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16; |
| 8466 | |
| 8467 | if (skip) |
| 8468 | memset (&outrel, 0, sizeof outrel); |
| 8469 | else if (!SYMBOL_REFERENCES_LOCAL (info, h) |
| 8470 | && !is_opd |
| 8471 | && r_type != R_PPC64_TOC) |
| 8472 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
| 8473 | else |
| 8474 | { |
| 8475 | /* This symbol is local, or marked to become local, |
| 8476 | or this is an opd section reloc which must point |
| 8477 | at a local function. */ |
| 8478 | outrel.r_addend += relocation; |
| 8479 | if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) |
| 8480 | { |
| 8481 | if (is_opd && h != NULL) |
| 8482 | { |
| 8483 | /* Lie about opd entries. This case occurs |
| 8484 | when building shared libraries and we |
| 8485 | reference a function in another shared |
| 8486 | lib. The same thing happens for a weak |
| 8487 | definition in an application that's |
| 8488 | overridden by a strong definition in a |
| 8489 | shared lib. (I believe this is a generic |
| 8490 | bug in binutils handling of weak syms.) |
| 8491 | In these cases we won't use the opd |
| 8492 | entry in this lib. */ |
| 8493 | unresolved_reloc = FALSE; |
| 8494 | } |
| 8495 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
| 8496 | |
| 8497 | /* We need to relocate .opd contents for ld.so. |
| 8498 | Prelink also wants simple and consistent rules |
| 8499 | for relocs. This make all RELATIVE relocs have |
| 8500 | *r_offset equal to r_addend. */ |
| 8501 | relocate = TRUE; |
| 8502 | } |
| 8503 | else |
| 8504 | { |
| 8505 | long indx = 0; |
| 8506 | |
| 8507 | if (bfd_is_abs_section (sec)) |
| 8508 | ; |
| 8509 | else if (sec == NULL || sec->owner == NULL) |
| 8510 | { |
| 8511 | bfd_set_error (bfd_error_bad_value); |
| 8512 | return FALSE; |
| 8513 | } |
| 8514 | else |
| 8515 | { |
| 8516 | asection *osec; |
| 8517 | |
| 8518 | osec = sec->output_section; |
| 8519 | indx = elf_section_data (osec)->dynindx; |
| 8520 | |
| 8521 | /* We are turning this relocation into one |
| 8522 | against a section symbol, so subtract out |
| 8523 | the output section's address but not the |
| 8524 | offset of the input section in the output |
| 8525 | section. */ |
| 8526 | outrel.r_addend -= osec->vma; |
| 8527 | } |
| 8528 | |
| 8529 | outrel.r_info = ELF64_R_INFO (indx, r_type); |
| 8530 | } |
| 8531 | } |
| 8532 | |
| 8533 | sreloc = elf_section_data (input_section)->sreloc; |
| 8534 | if (sreloc == NULL) |
| 8535 | abort (); |
| 8536 | |
| 8537 | loc = sreloc->contents; |
| 8538 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); |
| 8539 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
| 8540 | |
| 8541 | /* If this reloc is against an external symbol, it will |
| 8542 | be computed at runtime, so there's no need to do |
| 8543 | anything now. However, for the sake of prelink ensure |
| 8544 | that the section contents are a known value. */ |
| 8545 | if (! relocate) |
| 8546 | { |
| 8547 | unresolved_reloc = FALSE; |
| 8548 | /* The value chosen here is quite arbitrary as ld.so |
| 8549 | ignores section contents except for the special |
| 8550 | case of .opd where the contents might be accessed |
| 8551 | before relocation. Choose zero, as that won't |
| 8552 | cause reloc overflow. */ |
| 8553 | relocation = 0; |
| 8554 | addend = 0; |
| 8555 | /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs |
| 8556 | to improve backward compatibility with older |
| 8557 | versions of ld. */ |
| 8558 | if (r_type == R_PPC64_ADDR64) |
| 8559 | addend = outrel.r_addend; |
| 8560 | /* Adjust pc_relative relocs to have zero in *r_offset. */ |
| 8561 | else if (ppc64_elf_howto_table[r_type]->pc_relative) |
| 8562 | addend = (input_section->output_section->vma |
| 8563 | + input_section->output_offset |
| 8564 | + rel->r_offset); |
| 8565 | } |
| 8566 | } |
| 8567 | break; |
| 8568 | |
| 8569 | case R_PPC64_COPY: |
| 8570 | case R_PPC64_GLOB_DAT: |
| 8571 | case R_PPC64_JMP_SLOT: |
| 8572 | case R_PPC64_RELATIVE: |
| 8573 | /* We shouldn't ever see these dynamic relocs in relocatable |
| 8574 | files. */ |
| 8575 | /* Fall through. */ |
| 8576 | |
| 8577 | case R_PPC64_PLTGOT16: |
| 8578 | case R_PPC64_PLTGOT16_DS: |
| 8579 | case R_PPC64_PLTGOT16_HA: |
| 8580 | case R_PPC64_PLTGOT16_HI: |
| 8581 | case R_PPC64_PLTGOT16_LO: |
| 8582 | case R_PPC64_PLTGOT16_LO_DS: |
| 8583 | case R_PPC64_PLTREL32: |
| 8584 | case R_PPC64_PLTREL64: |
| 8585 | /* These ones haven't been implemented yet. */ |
| 8586 | |
| 8587 | (*_bfd_error_handler) |
| 8588 | (_("%s: relocation %s is not supported for symbol %s."), |
| 8589 | bfd_archive_filename (input_bfd), |
| 8590 | ppc64_elf_howto_table[r_type]->name, sym_name); |
| 8591 | |
| 8592 | bfd_set_error (bfd_error_invalid_operation); |
| 8593 | ret = FALSE; |
| 8594 | continue; |
| 8595 | } |
| 8596 | |
| 8597 | /* Do any further special processing. */ |
| 8598 | switch (r_type) |
| 8599 | { |
| 8600 | default: |
| 8601 | break; |
| 8602 | |
| 8603 | case R_PPC64_ADDR16_HA: |
| 8604 | case R_PPC64_ADDR16_HIGHERA: |
| 8605 | case R_PPC64_ADDR16_HIGHESTA: |
| 8606 | case R_PPC64_GOT16_HA: |
| 8607 | case R_PPC64_PLTGOT16_HA: |
| 8608 | case R_PPC64_PLT16_HA: |
| 8609 | case R_PPC64_TOC16_HA: |
| 8610 | case R_PPC64_SECTOFF_HA: |
| 8611 | case R_PPC64_TPREL16_HA: |
| 8612 | case R_PPC64_DTPREL16_HA: |
| 8613 | case R_PPC64_GOT_TLSGD16_HA: |
| 8614 | case R_PPC64_GOT_TLSLD16_HA: |
| 8615 | case R_PPC64_GOT_TPREL16_HA: |
| 8616 | case R_PPC64_GOT_DTPREL16_HA: |
| 8617 | case R_PPC64_TPREL16_HIGHER: |
| 8618 | case R_PPC64_TPREL16_HIGHERA: |
| 8619 | case R_PPC64_TPREL16_HIGHEST: |
| 8620 | case R_PPC64_TPREL16_HIGHESTA: |
| 8621 | case R_PPC64_DTPREL16_HIGHER: |
| 8622 | case R_PPC64_DTPREL16_HIGHERA: |
| 8623 | case R_PPC64_DTPREL16_HIGHEST: |
| 8624 | case R_PPC64_DTPREL16_HIGHESTA: |
| 8625 | /* It's just possible that this symbol is a weak symbol |
| 8626 | that's not actually defined anywhere. In that case, |
| 8627 | 'sec' would be NULL, and we should leave the symbol |
| 8628 | alone (it will be set to zero elsewhere in the link). */ |
| 8629 | if (sec != NULL) |
| 8630 | /* Add 0x10000 if sign bit in 0:15 is set. |
| 8631 | Bits 0:15 are not used. */ |
| 8632 | addend += 0x8000; |
| 8633 | break; |
| 8634 | |
| 8635 | case R_PPC64_ADDR16_DS: |
| 8636 | case R_PPC64_ADDR16_LO_DS: |
| 8637 | case R_PPC64_GOT16_DS: |
| 8638 | case R_PPC64_GOT16_LO_DS: |
| 8639 | case R_PPC64_PLT16_LO_DS: |
| 8640 | case R_PPC64_SECTOFF_DS: |
| 8641 | case R_PPC64_SECTOFF_LO_DS: |
| 8642 | case R_PPC64_TOC16_DS: |
| 8643 | case R_PPC64_TOC16_LO_DS: |
| 8644 | case R_PPC64_PLTGOT16_DS: |
| 8645 | case R_PPC64_PLTGOT16_LO_DS: |
| 8646 | case R_PPC64_GOT_TPREL16_DS: |
| 8647 | case R_PPC64_GOT_TPREL16_LO_DS: |
| 8648 | case R_PPC64_GOT_DTPREL16_DS: |
| 8649 | case R_PPC64_GOT_DTPREL16_LO_DS: |
| 8650 | case R_PPC64_TPREL16_DS: |
| 8651 | case R_PPC64_TPREL16_LO_DS: |
| 8652 | case R_PPC64_DTPREL16_DS: |
| 8653 | case R_PPC64_DTPREL16_LO_DS: |
| 8654 | insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3)); |
| 8655 | mask = 3; |
| 8656 | /* If this reloc is against an lq insn, then the value must be |
| 8657 | a multiple of 16. This is somewhat of a hack, but the |
| 8658 | "correct" way to do this by defining _DQ forms of all the |
| 8659 | _DS relocs bloats all reloc switches in this file. It |
| 8660 | doesn't seem to make much sense to use any of these relocs |
| 8661 | in data, so testing the insn should be safe. */ |
| 8662 | if ((insn & (0x3f << 26)) == (56u << 26)) |
| 8663 | mask = 15; |
| 8664 | if (((relocation + addend) & mask) != 0) |
| 8665 | { |
| 8666 | (*_bfd_error_handler) |
| 8667 | (_("%s: error: relocation %s not a multiple of %d"), |
| 8668 | bfd_archive_filename (input_bfd), |
| 8669 | ppc64_elf_howto_table[r_type]->name, |
| 8670 | mask + 1); |
| 8671 | bfd_set_error (bfd_error_bad_value); |
| 8672 | ret = FALSE; |
| 8673 | continue; |
| 8674 | } |
| 8675 | break; |
| 8676 | } |
| 8677 | |
| 8678 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
| 8679 | because such sections are not SEC_ALLOC and thus ld.so will |
| 8680 | not process them. */ |
| 8681 | if (unresolved_reloc |
| 8682 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
| 8683 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) |
| 8684 | { |
| 8685 | (*_bfd_error_handler) |
| 8686 | (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"), |
| 8687 | bfd_archive_filename (input_bfd), |
| 8688 | bfd_get_section_name (input_bfd, input_section), |
| 8689 | (long) rel->r_offset, |
| 8690 | ppc64_elf_howto_table[(int) r_type]->name, |
| 8691 | h->root.root.string); |
| 8692 | ret = FALSE; |
| 8693 | } |
| 8694 | |
| 8695 | r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type], |
| 8696 | input_bfd, |
| 8697 | input_section, |
| 8698 | contents, |
| 8699 | rel->r_offset, |
| 8700 | relocation, |
| 8701 | addend); |
| 8702 | |
| 8703 | if (r != bfd_reloc_ok) |
| 8704 | { |
| 8705 | if (sym_name == NULL) |
| 8706 | sym_name = "(null)"; |
| 8707 | if (r == bfd_reloc_overflow) |
| 8708 | { |
| 8709 | if (warned) |
| 8710 | continue; |
| 8711 | if (h != NULL |
| 8712 | && h->root.type == bfd_link_hash_undefweak |
| 8713 | && ppc64_elf_howto_table[r_type]->pc_relative) |
| 8714 | { |
| 8715 | /* Assume this is a call protected by other code that |
| 8716 | detects the symbol is undefined. If this is the case, |
| 8717 | we can safely ignore the overflow. If not, the |
| 8718 | program is hosed anyway, and a little warning isn't |
| 8719 | going to help. */ |
| 8720 | |
| 8721 | continue; |
| 8722 | } |
| 8723 | |
| 8724 | if (!((*info->callbacks->reloc_overflow) |
| 8725 | (info, sym_name, ppc64_elf_howto_table[r_type]->name, |
| 8726 | rel->r_addend, input_bfd, input_section, rel->r_offset))) |
| 8727 | return FALSE; |
| 8728 | } |
| 8729 | else |
| 8730 | { |
| 8731 | (*_bfd_error_handler) |
| 8732 | (_("%s(%s+0x%lx): %s reloc against `%s': error %d"), |
| 8733 | bfd_archive_filename (input_bfd), |
| 8734 | bfd_get_section_name (input_bfd, input_section), |
| 8735 | (long) rel->r_offset, |
| 8736 | ppc64_elf_howto_table[r_type]->name, |
| 8737 | sym_name, |
| 8738 | (int) r); |
| 8739 | ret = FALSE; |
| 8740 | } |
| 8741 | } |
| 8742 | } |
| 8743 | |
| 8744 | return ret; |
| 8745 | } |
| 8746 | |
| 8747 | /* Adjust the value of any local symbols in opd sections. */ |
| 8748 | |
| 8749 | static bfd_boolean |
| 8750 | ppc64_elf_output_symbol_hook (struct bfd_link_info *info, |
| 8751 | const char *name ATTRIBUTE_UNUSED, |
| 8752 | Elf_Internal_Sym *elfsym, |
| 8753 | asection *input_sec, |
| 8754 | struct elf_link_hash_entry *h) |
| 8755 | { |
| 8756 | long *opd_adjust, adjust; |
| 8757 | bfd_vma value; |
| 8758 | |
| 8759 | if (h != NULL) |
| 8760 | return TRUE; |
| 8761 | |
| 8762 | opd_adjust = get_opd_info (input_sec); |
| 8763 | if (opd_adjust == NULL) |
| 8764 | return TRUE; |
| 8765 | |
| 8766 | value = elfsym->st_value - input_sec->output_offset; |
| 8767 | if (!info->relocatable) |
| 8768 | value -= input_sec->output_section->vma; |
| 8769 | |
| 8770 | adjust = opd_adjust[value / 24]; |
| 8771 | if (adjust == -1) |
| 8772 | elfsym->st_value = 0; |
| 8773 | else |
| 8774 | elfsym->st_value += adjust; |
| 8775 | return TRUE; |
| 8776 | } |
| 8777 | |
| 8778 | /* Finish up dynamic symbol handling. We set the contents of various |
| 8779 | dynamic sections here. */ |
| 8780 | |
| 8781 | static bfd_boolean |
| 8782 | ppc64_elf_finish_dynamic_symbol (bfd *output_bfd, |
| 8783 | struct bfd_link_info *info, |
| 8784 | struct elf_link_hash_entry *h, |
| 8785 | Elf_Internal_Sym *sym) |
| 8786 | { |
| 8787 | struct ppc_link_hash_table *htab; |
| 8788 | bfd *dynobj; |
| 8789 | |
| 8790 | htab = ppc_hash_table (info); |
| 8791 | dynobj = htab->elf.dynobj; |
| 8792 | |
| 8793 | if (((struct ppc_link_hash_entry *) h)->is_func_descriptor) |
| 8794 | { |
| 8795 | struct plt_entry *ent; |
| 8796 | Elf_Internal_Rela rela; |
| 8797 | bfd_byte *loc; |
| 8798 | |
| 8799 | for (ent = h->plt.plist; ent != NULL; ent = ent->next) |
| 8800 | if (ent->plt.offset != (bfd_vma) -1) |
| 8801 | { |
| 8802 | /* This symbol has an entry in the procedure linkage |
| 8803 | table. Set it up. */ |
| 8804 | |
| 8805 | if (htab->plt == NULL |
| 8806 | || htab->relplt == NULL |
| 8807 | || htab->glink == NULL) |
| 8808 | abort (); |
| 8809 | |
| 8810 | /* Create a JMP_SLOT reloc to inform the dynamic linker to |
| 8811 | fill in the PLT entry. */ |
| 8812 | rela.r_offset = (htab->plt->output_section->vma |
| 8813 | + htab->plt->output_offset |
| 8814 | + ent->plt.offset); |
| 8815 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT); |
| 8816 | rela.r_addend = ent->addend; |
| 8817 | |
| 8818 | loc = htab->relplt->contents; |
| 8819 | loc += ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE |
| 8820 | * sizeof (Elf64_External_Rela)); |
| 8821 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
| 8822 | } |
| 8823 | } |
| 8824 | |
| 8825 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) |
| 8826 | { |
| 8827 | Elf_Internal_Rela rela; |
| 8828 | bfd_byte *loc; |
| 8829 | |
| 8830 | /* This symbol needs a copy reloc. Set it up. */ |
| 8831 | |
| 8832 | if (h->dynindx == -1 |
| 8833 | || (h->root.type != bfd_link_hash_defined |
| 8834 | && h->root.type != bfd_link_hash_defweak) |
| 8835 | || htab->relbss == NULL) |
| 8836 | abort (); |
| 8837 | |
| 8838 | rela.r_offset = (h->root.u.def.value |
| 8839 | + h->root.u.def.section->output_section->vma |
| 8840 | + h->root.u.def.section->output_offset); |
| 8841 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY); |
| 8842 | rela.r_addend = 0; |
| 8843 | loc = htab->relbss->contents; |
| 8844 | loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela); |
| 8845 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
| 8846 | } |
| 8847 | |
| 8848 | /* Mark some specially defined symbols as absolute. */ |
| 8849 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0) |
| 8850 | sym->st_shndx = SHN_ABS; |
| 8851 | |
| 8852 | return TRUE; |
| 8853 | } |
| 8854 | |
| 8855 | /* Used to decide how to sort relocs in an optimal manner for the |
| 8856 | dynamic linker, before writing them out. */ |
| 8857 | |
| 8858 | static enum elf_reloc_type_class |
| 8859 | ppc64_elf_reloc_type_class (const Elf_Internal_Rela *rela) |
| 8860 | { |
| 8861 | enum elf_ppc64_reloc_type r_type; |
| 8862 | |
| 8863 | r_type = ELF64_R_TYPE (rela->r_info); |
| 8864 | switch (r_type) |
| 8865 | { |
| 8866 | case R_PPC64_RELATIVE: |
| 8867 | return reloc_class_relative; |
| 8868 | case R_PPC64_JMP_SLOT: |
| 8869 | return reloc_class_plt; |
| 8870 | case R_PPC64_COPY: |
| 8871 | return reloc_class_copy; |
| 8872 | default: |
| 8873 | return reloc_class_normal; |
| 8874 | } |
| 8875 | } |
| 8876 | |
| 8877 | /* Finish up the dynamic sections. */ |
| 8878 | |
| 8879 | static bfd_boolean |
| 8880 | ppc64_elf_finish_dynamic_sections (bfd *output_bfd, |
| 8881 | struct bfd_link_info *info) |
| 8882 | { |
| 8883 | struct ppc_link_hash_table *htab; |
| 8884 | bfd *dynobj; |
| 8885 | asection *sdyn; |
| 8886 | |
| 8887 | htab = ppc_hash_table (info); |
| 8888 | dynobj = htab->elf.dynobj; |
| 8889 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
| 8890 | |
| 8891 | if (htab->elf.dynamic_sections_created) |
| 8892 | { |
| 8893 | Elf64_External_Dyn *dyncon, *dynconend; |
| 8894 | |
| 8895 | if (sdyn == NULL || htab->got == NULL) |
| 8896 | abort (); |
| 8897 | |
| 8898 | dyncon = (Elf64_External_Dyn *) sdyn->contents; |
| 8899 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); |
| 8900 | for (; dyncon < dynconend; dyncon++) |
| 8901 | { |
| 8902 | Elf_Internal_Dyn dyn; |
| 8903 | asection *s; |
| 8904 | |
| 8905 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); |
| 8906 | |
| 8907 | switch (dyn.d_tag) |
| 8908 | { |
| 8909 | default: |
| 8910 | continue; |
| 8911 | |
| 8912 | case DT_PPC64_GLINK: |
| 8913 | s = htab->glink; |
| 8914 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
| 8915 | /* We stupidly defined DT_PPC64_GLINK to be the start |
| 8916 | of glink rather than the first entry point, which is |
| 8917 | what ld.so needs, and now have a bigger stub to |
| 8918 | support automatic multiple TOCs. */ |
| 8919 | dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 32; |
| 8920 | break; |
| 8921 | |
| 8922 | case DT_PPC64_OPD: |
| 8923 | s = bfd_get_section_by_name (output_bfd, ".opd"); |
| 8924 | if (s == NULL) |
| 8925 | continue; |
| 8926 | dyn.d_un.d_ptr = s->vma; |
| 8927 | break; |
| 8928 | |
| 8929 | case DT_PPC64_OPDSZ: |
| 8930 | s = bfd_get_section_by_name (output_bfd, ".opd"); |
| 8931 | if (s == NULL) |
| 8932 | continue; |
| 8933 | dyn.d_un.d_val = s->size; |
| 8934 | break; |
| 8935 | |
| 8936 | case DT_PLTGOT: |
| 8937 | s = htab->plt; |
| 8938 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
| 8939 | break; |
| 8940 | |
| 8941 | case DT_JMPREL: |
| 8942 | s = htab->relplt; |
| 8943 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
| 8944 | break; |
| 8945 | |
| 8946 | case DT_PLTRELSZ: |
| 8947 | dyn.d_un.d_val = htab->relplt->size; |
| 8948 | break; |
| 8949 | |
| 8950 | case DT_RELASZ: |
| 8951 | /* Don't count procedure linkage table relocs in the |
| 8952 | overall reloc count. */ |
| 8953 | s = htab->relplt; |
| 8954 | if (s == NULL) |
| 8955 | continue; |
| 8956 | dyn.d_un.d_val -= s->size; |
| 8957 | break; |
| 8958 | |
| 8959 | case DT_RELA: |
| 8960 | /* We may not be using the standard ELF linker script. |
| 8961 | If .rela.plt is the first .rela section, we adjust |
| 8962 | DT_RELA to not include it. */ |
| 8963 | s = htab->relplt; |
| 8964 | if (s == NULL) |
| 8965 | continue; |
| 8966 | if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) |
| 8967 | continue; |
| 8968 | dyn.d_un.d_ptr += s->size; |
| 8969 | break; |
| 8970 | } |
| 8971 | |
| 8972 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 8973 | } |
| 8974 | } |
| 8975 | |
| 8976 | if (htab->got != NULL && htab->got->size != 0) |
| 8977 | { |
| 8978 | /* Fill in the first entry in the global offset table. |
| 8979 | We use it to hold the link-time TOCbase. */ |
| 8980 | bfd_put_64 (output_bfd, |
| 8981 | elf_gp (output_bfd) + TOC_BASE_OFF, |
| 8982 | htab->got->contents); |
| 8983 | |
| 8984 | /* Set .got entry size. */ |
| 8985 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8; |
| 8986 | } |
| 8987 | |
| 8988 | if (htab->plt != NULL && htab->plt->size != 0) |
| 8989 | { |
| 8990 | /* Set .plt entry size. */ |
| 8991 | elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize |
| 8992 | = PLT_ENTRY_SIZE; |
| 8993 | } |
| 8994 | |
| 8995 | /* We need to handle writing out multiple GOT sections ourselves, |
| 8996 | since we didn't add them to DYNOBJ. */ |
| 8997 | while ((dynobj = dynobj->link_next) != NULL) |
| 8998 | { |
| 8999 | asection *s; |
| 9000 | s = ppc64_elf_tdata (dynobj)->got; |
| 9001 | if (s != NULL |
| 9002 | && s->size != 0 |
| 9003 | && s->output_section != bfd_abs_section_ptr |
| 9004 | && !bfd_set_section_contents (output_bfd, s->output_section, |
| 9005 | s->contents, s->output_offset, |
| 9006 | s->size)) |
| 9007 | return FALSE; |
| 9008 | s = ppc64_elf_tdata (dynobj)->relgot; |
| 9009 | if (s != NULL |
| 9010 | && s->size != 0 |
| 9011 | && s->output_section != bfd_abs_section_ptr |
| 9012 | && !bfd_set_section_contents (output_bfd, s->output_section, |
| 9013 | s->contents, s->output_offset, |
| 9014 | s->size)) |
| 9015 | return FALSE; |
| 9016 | } |
| 9017 | |
| 9018 | return TRUE; |
| 9019 | } |
| 9020 | |
| 9021 | #include "elf64-target.h" |