| 1 | /* PowerPC-specific support for 32-bit ELF |
| 2 | Copyright 1994, 95, 96, 97, 98, 1999 Free Software Foundation, Inc. |
| 3 | Written by Ian Lance Taylor, Cygnus Support. |
| 4 | |
| 5 | This file is part of BFD, the Binary File Descriptor library. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | /* This file is based on a preliminary PowerPC ELF ABI. The |
| 22 | information may not match the final PowerPC ELF ABI. It includes |
| 23 | suggestions from the in-progress Embedded PowerPC ABI, and that |
| 24 | information may also not match. */ |
| 25 | |
| 26 | #include "bfd.h" |
| 27 | #include "sysdep.h" |
| 28 | #include "bfdlink.h" |
| 29 | #include "libbfd.h" |
| 30 | #include "elf-bfd.h" |
| 31 | #include "elf/ppc.h" |
| 32 | |
| 33 | #define USE_RELA /* we want RELA relocations, not REL */ |
| 34 | |
| 35 | static reloc_howto_type *ppc_elf_reloc_type_lookup |
| 36 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); |
| 37 | static void ppc_elf_info_to_howto |
| 38 | PARAMS ((bfd *abfd, arelent *cache_ptr, Elf32_Internal_Rela *dst)); |
| 39 | static void ppc_elf_howto_init PARAMS ((void)); |
| 40 | static bfd_reloc_status_type ppc_elf_addr16_ha_reloc |
| 41 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); |
| 42 | static boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword)); |
| 43 | static boolean ppc_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *)); |
| 44 | static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *)); |
| 45 | |
| 46 | static int ppc_elf_additional_program_headers PARAMS ((bfd *)); |
| 47 | static boolean ppc_elf_modify_segment_map PARAMS ((bfd *)); |
| 48 | |
| 49 | static boolean ppc_elf_create_dynamic_sections |
| 50 | PARAMS ((bfd *, struct bfd_link_info *)); |
| 51 | |
| 52 | static boolean ppc_elf_section_from_shdr PARAMS ((bfd *, |
| 53 | Elf32_Internal_Shdr *, |
| 54 | char *)); |
| 55 | static boolean ppc_elf_fake_sections |
| 56 | PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *)); |
| 57 | |
| 58 | static elf_linker_section_t *ppc_elf_create_linker_section |
| 59 | PARAMS ((bfd *abfd, |
| 60 | struct bfd_link_info *info, |
| 61 | enum elf_linker_section_enum)); |
| 62 | |
| 63 | static boolean ppc_elf_check_relocs PARAMS ((bfd *, |
| 64 | struct bfd_link_info *, |
| 65 | asection *, |
| 66 | const Elf_Internal_Rela *)); |
| 67 | |
| 68 | static asection * ppc_elf_gc_mark_hook PARAMS ((bfd *abfd, |
| 69 | struct bfd_link_info *info, |
| 70 | Elf_Internal_Rela *rel, |
| 71 | struct elf_link_hash_entry *h, |
| 72 | Elf_Internal_Sym *sym)); |
| 73 | |
| 74 | static boolean ppc_elf_gc_sweep_hook PARAMS ((bfd *abfd, |
| 75 | struct bfd_link_info *info, |
| 76 | asection *sec, |
| 77 | const Elf_Internal_Rela *relocs)); |
| 78 | |
| 79 | static boolean ppc_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *, |
| 80 | struct elf_link_hash_entry *)); |
| 81 | |
| 82 | static boolean ppc_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *)); |
| 83 | |
| 84 | static boolean ppc_elf_relocate_section PARAMS ((bfd *, |
| 85 | struct bfd_link_info *info, |
| 86 | bfd *, |
| 87 | asection *, |
| 88 | bfd_byte *, |
| 89 | Elf_Internal_Rela *relocs, |
| 90 | Elf_Internal_Sym *local_syms, |
| 91 | asection **)); |
| 92 | |
| 93 | static boolean ppc_elf_add_symbol_hook PARAMS ((bfd *, |
| 94 | struct bfd_link_info *, |
| 95 | const Elf_Internal_Sym *, |
| 96 | const char **, |
| 97 | flagword *, |
| 98 | asection **, |
| 99 | bfd_vma *)); |
| 100 | |
| 101 | static boolean ppc_elf_finish_dynamic_symbol PARAMS ((bfd *, |
| 102 | struct bfd_link_info *, |
| 103 | struct elf_link_hash_entry *, |
| 104 | Elf_Internal_Sym *)); |
| 105 | |
| 106 | static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *)); |
| 107 | |
| 108 | #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */ |
| 109 | #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */ |
| 110 | #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */ |
| 111 | |
| 112 | /* The name of the dynamic interpreter. This is put in the .interp |
| 113 | section. */ |
| 114 | |
| 115 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
| 116 | |
| 117 | /* The size in bytes of an entry in the procedure linkage table. */ |
| 118 | #define PLT_ENTRY_SIZE 12 |
| 119 | /* The initial size of the plt reserved for the dynamic linker. */ |
| 120 | #define PLT_INITIAL_ENTRY_SIZE 72 |
| 121 | /* The size of the gap between entries in the PLT. */ |
| 122 | #define PLT_SLOT_SIZE 8 |
| 123 | /* The number of single-slot PLT entries (the rest use two slots). */ |
| 124 | #define PLT_NUM_SINGLE_ENTRIES 8192 |
| 125 | |
| 126 | /* Will references to this symbol always reference the symbol |
| 127 | in this object? */ |
| 128 | #define SYMBOL_REFERENCES_LOCAL(INFO, H) \ |
| 129 | ((! INFO->shared \ |
| 130 | || INFO->symbolic \ |
| 131 | || H->dynindx == -1 \ |
| 132 | || ELF_ST_VISIBILITY (H->other) == STV_INTERNAL \ |
| 133 | || ELF_ST_VISIBILITY (H->other) == STV_HIDDEN) \ |
| 134 | && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0) |
| 135 | |
| 136 | /* Will _calls_ to this symbol always call the version in this object? */ |
| 137 | #define SYMBOL_CALLS_LOCAL(INFO, H) \ |
| 138 | ((! INFO->shared \ |
| 139 | || INFO->symbolic \ |
| 140 | || H->dynindx == -1 \ |
| 141 | || ELF_ST_VISIBILITY (H->other) != STV_DEFAULT) \ |
| 142 | && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0) |
| 143 | \f |
| 144 | static reloc_howto_type *ppc_elf_howto_table[ (int)R_PPC_max ]; |
| 145 | |
| 146 | static reloc_howto_type ppc_elf_howto_raw[] = |
| 147 | { |
| 148 | /* This reloc does nothing. */ |
| 149 | HOWTO (R_PPC_NONE, /* type */ |
| 150 | 0, /* rightshift */ |
| 151 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 152 | 32, /* bitsize */ |
| 153 | false, /* pc_relative */ |
| 154 | 0, /* bitpos */ |
| 155 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 156 | bfd_elf_generic_reloc, /* special_function */ |
| 157 | "R_PPC_NONE", /* name */ |
| 158 | false, /* partial_inplace */ |
| 159 | 0, /* src_mask */ |
| 160 | 0, /* dst_mask */ |
| 161 | false), /* pcrel_offset */ |
| 162 | |
| 163 | /* A standard 32 bit relocation. */ |
| 164 | HOWTO (R_PPC_ADDR32, /* type */ |
| 165 | 0, /* rightshift */ |
| 166 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 167 | 32, /* bitsize */ |
| 168 | false, /* pc_relative */ |
| 169 | 0, /* bitpos */ |
| 170 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 171 | bfd_elf_generic_reloc, /* special_function */ |
| 172 | "R_PPC_ADDR32", /* name */ |
| 173 | false, /* partial_inplace */ |
| 174 | 0, /* src_mask */ |
| 175 | 0xffffffff, /* dst_mask */ |
| 176 | false), /* pcrel_offset */ |
| 177 | |
| 178 | /* An absolute 26 bit branch; the lower two bits must be zero. |
| 179 | FIXME: we don't check that, we just clear them. */ |
| 180 | HOWTO (R_PPC_ADDR24, /* type */ |
| 181 | 0, /* rightshift */ |
| 182 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 183 | 26, /* bitsize */ |
| 184 | false, /* pc_relative */ |
| 185 | 0, /* bitpos */ |
| 186 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 187 | bfd_elf_generic_reloc, /* special_function */ |
| 188 | "R_PPC_ADDR24", /* name */ |
| 189 | false, /* partial_inplace */ |
| 190 | 0, /* src_mask */ |
| 191 | 0x3fffffc, /* dst_mask */ |
| 192 | false), /* pcrel_offset */ |
| 193 | |
| 194 | /* A standard 16 bit relocation. */ |
| 195 | HOWTO (R_PPC_ADDR16, /* type */ |
| 196 | 0, /* rightshift */ |
| 197 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 198 | 16, /* bitsize */ |
| 199 | false, /* pc_relative */ |
| 200 | 0, /* bitpos */ |
| 201 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 202 | bfd_elf_generic_reloc, /* special_function */ |
| 203 | "R_PPC_ADDR16", /* name */ |
| 204 | false, /* partial_inplace */ |
| 205 | 0, /* src_mask */ |
| 206 | 0xffff, /* dst_mask */ |
| 207 | false), /* pcrel_offset */ |
| 208 | |
| 209 | /* A 16 bit relocation without overflow. */ |
| 210 | HOWTO (R_PPC_ADDR16_LO, /* type */ |
| 211 | 0, /* rightshift */ |
| 212 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 213 | 16, /* bitsize */ |
| 214 | false, /* pc_relative */ |
| 215 | 0, /* bitpos */ |
| 216 | complain_overflow_dont,/* complain_on_overflow */ |
| 217 | bfd_elf_generic_reloc, /* special_function */ |
| 218 | "R_PPC_ADDR16_LO", /* name */ |
| 219 | false, /* partial_inplace */ |
| 220 | 0, /* src_mask */ |
| 221 | 0xffff, /* dst_mask */ |
| 222 | false), /* pcrel_offset */ |
| 223 | |
| 224 | /* The high order 16 bits of an address. */ |
| 225 | HOWTO (R_PPC_ADDR16_HI, /* type */ |
| 226 | 16, /* rightshift */ |
| 227 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 228 | 16, /* bitsize */ |
| 229 | false, /* pc_relative */ |
| 230 | 0, /* bitpos */ |
| 231 | complain_overflow_dont, /* complain_on_overflow */ |
| 232 | bfd_elf_generic_reloc, /* special_function */ |
| 233 | "R_PPC_ADDR16_HI", /* name */ |
| 234 | false, /* partial_inplace */ |
| 235 | 0, /* src_mask */ |
| 236 | 0xffff, /* dst_mask */ |
| 237 | false), /* pcrel_offset */ |
| 238 | |
| 239 | /* The high order 16 bits of an address, plus 1 if the contents of |
| 240 | the low 16 bits, treated as a signed number, is negative. */ |
| 241 | HOWTO (R_PPC_ADDR16_HA, /* type */ |
| 242 | 16, /* rightshift */ |
| 243 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 244 | 16, /* bitsize */ |
| 245 | false, /* pc_relative */ |
| 246 | 0, /* bitpos */ |
| 247 | complain_overflow_dont, /* complain_on_overflow */ |
| 248 | ppc_elf_addr16_ha_reloc, /* special_function */ |
| 249 | "R_PPC_ADDR16_HA", /* name */ |
| 250 | false, /* partial_inplace */ |
| 251 | 0, /* src_mask */ |
| 252 | 0xffff, /* dst_mask */ |
| 253 | false), /* pcrel_offset */ |
| 254 | |
| 255 | /* An absolute 16 bit branch; the lower two bits must be zero. |
| 256 | FIXME: we don't check that, we just clear them. */ |
| 257 | HOWTO (R_PPC_ADDR14, /* type */ |
| 258 | 0, /* rightshift */ |
| 259 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 260 | 16, /* bitsize */ |
| 261 | false, /* pc_relative */ |
| 262 | 0, /* bitpos */ |
| 263 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 264 | bfd_elf_generic_reloc, /* special_function */ |
| 265 | "R_PPC_ADDR14", /* name */ |
| 266 | false, /* partial_inplace */ |
| 267 | 0, /* src_mask */ |
| 268 | 0xfffc, /* dst_mask */ |
| 269 | false), /* pcrel_offset */ |
| 270 | |
| 271 | /* An absolute 16 bit branch, for which bit 10 should be set to |
| 272 | indicate that the branch is expected to be taken. The lower two |
| 273 | bits must be zero. */ |
| 274 | HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */ |
| 275 | 0, /* rightshift */ |
| 276 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 277 | 16, /* bitsize */ |
| 278 | false, /* pc_relative */ |
| 279 | 0, /* bitpos */ |
| 280 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 281 | bfd_elf_generic_reloc, /* special_function */ |
| 282 | "R_PPC_ADDR14_BRTAKEN",/* name */ |
| 283 | false, /* partial_inplace */ |
| 284 | 0, /* src_mask */ |
| 285 | 0xfffc, /* dst_mask */ |
| 286 | false), /* pcrel_offset */ |
| 287 | |
| 288 | /* An absolute 16 bit branch, for which bit 10 should be set to |
| 289 | indicate that the branch is not expected to be taken. The lower |
| 290 | two bits must be zero. */ |
| 291 | HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */ |
| 292 | 0, /* rightshift */ |
| 293 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 294 | 16, /* bitsize */ |
| 295 | false, /* pc_relative */ |
| 296 | 0, /* bitpos */ |
| 297 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 298 | bfd_elf_generic_reloc, /* special_function */ |
| 299 | "R_PPC_ADDR14_BRNTAKEN",/* name */ |
| 300 | false, /* partial_inplace */ |
| 301 | 0, /* src_mask */ |
| 302 | 0xfffc, /* dst_mask */ |
| 303 | false), /* pcrel_offset */ |
| 304 | |
| 305 | /* A relative 26 bit branch; the lower two bits must be zero. */ |
| 306 | HOWTO (R_PPC_REL24, /* type */ |
| 307 | 0, /* rightshift */ |
| 308 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 309 | 26, /* bitsize */ |
| 310 | true, /* pc_relative */ |
| 311 | 0, /* bitpos */ |
| 312 | complain_overflow_signed, /* complain_on_overflow */ |
| 313 | bfd_elf_generic_reloc, /* special_function */ |
| 314 | "R_PPC_REL24", /* name */ |
| 315 | false, /* partial_inplace */ |
| 316 | 0, /* src_mask */ |
| 317 | 0x3fffffc, /* dst_mask */ |
| 318 | true), /* pcrel_offset */ |
| 319 | |
| 320 | /* A relative 16 bit branch; the lower two bits must be zero. */ |
| 321 | HOWTO (R_PPC_REL14, /* type */ |
| 322 | 0, /* rightshift */ |
| 323 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 324 | 16, /* bitsize */ |
| 325 | true, /* pc_relative */ |
| 326 | 0, /* bitpos */ |
| 327 | complain_overflow_signed, /* complain_on_overflow */ |
| 328 | bfd_elf_generic_reloc, /* special_function */ |
| 329 | "R_PPC_REL14", /* name */ |
| 330 | false, /* partial_inplace */ |
| 331 | 0, /* src_mask */ |
| 332 | 0xfffc, /* dst_mask */ |
| 333 | true), /* pcrel_offset */ |
| 334 | |
| 335 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
| 336 | the branch is expected to be taken. The lower two bits must be |
| 337 | zero. */ |
| 338 | HOWTO (R_PPC_REL14_BRTAKEN, /* type */ |
| 339 | 0, /* rightshift */ |
| 340 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 341 | 16, /* bitsize */ |
| 342 | true, /* pc_relative */ |
| 343 | 0, /* bitpos */ |
| 344 | complain_overflow_signed, /* complain_on_overflow */ |
| 345 | bfd_elf_generic_reloc, /* special_function */ |
| 346 | "R_PPC_REL14_BRTAKEN", /* name */ |
| 347 | false, /* partial_inplace */ |
| 348 | 0, /* src_mask */ |
| 349 | 0xfffc, /* dst_mask */ |
| 350 | true), /* pcrel_offset */ |
| 351 | |
| 352 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
| 353 | the branch is not expected to be taken. The lower two bits must |
| 354 | be zero. */ |
| 355 | HOWTO (R_PPC_REL14_BRNTAKEN, /* type */ |
| 356 | 0, /* rightshift */ |
| 357 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 358 | 16, /* bitsize */ |
| 359 | true, /* pc_relative */ |
| 360 | 0, /* bitpos */ |
| 361 | complain_overflow_signed, /* complain_on_overflow */ |
| 362 | bfd_elf_generic_reloc, /* special_function */ |
| 363 | "R_PPC_REL14_BRNTAKEN",/* name */ |
| 364 | false, /* partial_inplace */ |
| 365 | 0, /* src_mask */ |
| 366 | 0xfffc, /* dst_mask */ |
| 367 | true), /* pcrel_offset */ |
| 368 | |
| 369 | /* Like R_PPC_ADDR16, but referring to the GOT table entry for the |
| 370 | symbol. */ |
| 371 | HOWTO (R_PPC_GOT16, /* type */ |
| 372 | 0, /* rightshift */ |
| 373 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 374 | 16, /* bitsize */ |
| 375 | false, /* pc_relative */ |
| 376 | 0, /* bitpos */ |
| 377 | complain_overflow_signed, /* complain_on_overflow */ |
| 378 | bfd_elf_generic_reloc, /* special_function */ |
| 379 | "R_PPC_GOT16", /* name */ |
| 380 | false, /* partial_inplace */ |
| 381 | 0, /* src_mask */ |
| 382 | 0xffff, /* dst_mask */ |
| 383 | false), /* pcrel_offset */ |
| 384 | |
| 385 | /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for |
| 386 | the symbol. */ |
| 387 | HOWTO (R_PPC_GOT16_LO, /* type */ |
| 388 | 0, /* rightshift */ |
| 389 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 390 | 16, /* bitsize */ |
| 391 | false, /* pc_relative */ |
| 392 | 0, /* bitpos */ |
| 393 | complain_overflow_dont, /* complain_on_overflow */ |
| 394 | bfd_elf_generic_reloc, /* special_function */ |
| 395 | "R_PPC_GOT16_LO", /* name */ |
| 396 | false, /* partial_inplace */ |
| 397 | 0, /* src_mask */ |
| 398 | 0xffff, /* dst_mask */ |
| 399 | false), /* pcrel_offset */ |
| 400 | |
| 401 | /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for |
| 402 | the symbol. */ |
| 403 | HOWTO (R_PPC_GOT16_HI, /* type */ |
| 404 | 16, /* rightshift */ |
| 405 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 406 | 16, /* bitsize */ |
| 407 | false, /* pc_relative */ |
| 408 | 0, /* bitpos */ |
| 409 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 410 | bfd_elf_generic_reloc, /* special_function */ |
| 411 | "R_PPC_GOT16_HI", /* name */ |
| 412 | false, /* partial_inplace */ |
| 413 | 0, /* src_mask */ |
| 414 | 0xffff, /* dst_mask */ |
| 415 | false), /* pcrel_offset */ |
| 416 | |
| 417 | /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for |
| 418 | the symbol. */ |
| 419 | HOWTO (R_PPC_GOT16_HA, /* type */ |
| 420 | 16, /* rightshift */ |
| 421 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 422 | 16, /* bitsize */ |
| 423 | false, /* pc_relative */ |
| 424 | 0, /* bitpos */ |
| 425 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 426 | ppc_elf_addr16_ha_reloc, /* special_function */ |
| 427 | "R_PPC_GOT16_HA", /* name */ |
| 428 | false, /* partial_inplace */ |
| 429 | 0, /* src_mask */ |
| 430 | 0xffff, /* dst_mask */ |
| 431 | false), /* pcrel_offset */ |
| 432 | |
| 433 | /* Like R_PPC_REL24, but referring to the procedure linkage table |
| 434 | entry for the symbol. */ |
| 435 | HOWTO (R_PPC_PLTREL24, /* type */ |
| 436 | 0, /* rightshift */ |
| 437 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 438 | 26, /* bitsize */ |
| 439 | true, /* pc_relative */ |
| 440 | 0, /* bitpos */ |
| 441 | complain_overflow_signed, /* complain_on_overflow */ |
| 442 | bfd_elf_generic_reloc, /* special_function */ |
| 443 | "R_PPC_PLTREL24", /* name */ |
| 444 | false, /* partial_inplace */ |
| 445 | 0, /* src_mask */ |
| 446 | 0x3fffffc, /* dst_mask */ |
| 447 | true), /* pcrel_offset */ |
| 448 | |
| 449 | /* This is used only by the dynamic linker. The symbol should exist |
| 450 | both in the object being run and in some shared library. The |
| 451 | dynamic linker copies the data addressed by the symbol from the |
| 452 | shared library into the object, because the object being |
| 453 | run has to have the data at some particular address. */ |
| 454 | HOWTO (R_PPC_COPY, /* type */ |
| 455 | 0, /* rightshift */ |
| 456 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 457 | 32, /* bitsize */ |
| 458 | false, /* pc_relative */ |
| 459 | 0, /* bitpos */ |
| 460 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 461 | bfd_elf_generic_reloc, /* special_function */ |
| 462 | "R_PPC_COPY", /* name */ |
| 463 | false, /* partial_inplace */ |
| 464 | 0, /* src_mask */ |
| 465 | 0, /* dst_mask */ |
| 466 | false), /* pcrel_offset */ |
| 467 | |
| 468 | /* Like R_PPC_ADDR32, but used when setting global offset table |
| 469 | entries. */ |
| 470 | HOWTO (R_PPC_GLOB_DAT, /* type */ |
| 471 | 0, /* rightshift */ |
| 472 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 473 | 32, /* bitsize */ |
| 474 | false, /* pc_relative */ |
| 475 | 0, /* bitpos */ |
| 476 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 477 | bfd_elf_generic_reloc, /* special_function */ |
| 478 | "R_PPC_GLOB_DAT", /* name */ |
| 479 | false, /* partial_inplace */ |
| 480 | 0, /* src_mask */ |
| 481 | 0xffffffff, /* dst_mask */ |
| 482 | false), /* pcrel_offset */ |
| 483 | |
| 484 | /* Marks a procedure linkage table entry for a symbol. */ |
| 485 | HOWTO (R_PPC_JMP_SLOT, /* type */ |
| 486 | 0, /* rightshift */ |
| 487 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 488 | 32, /* bitsize */ |
| 489 | false, /* pc_relative */ |
| 490 | 0, /* bitpos */ |
| 491 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 492 | bfd_elf_generic_reloc, /* special_function */ |
| 493 | "R_PPC_JMP_SLOT", /* name */ |
| 494 | false, /* partial_inplace */ |
| 495 | 0, /* src_mask */ |
| 496 | 0, /* dst_mask */ |
| 497 | false), /* pcrel_offset */ |
| 498 | |
| 499 | /* Used only by the dynamic linker. When the object is run, this |
| 500 | longword is set to the load address of the object, plus the |
| 501 | addend. */ |
| 502 | HOWTO (R_PPC_RELATIVE, /* type */ |
| 503 | 0, /* rightshift */ |
| 504 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 505 | 32, /* bitsize */ |
| 506 | false, /* pc_relative */ |
| 507 | 0, /* bitpos */ |
| 508 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 509 | bfd_elf_generic_reloc, /* special_function */ |
| 510 | "R_PPC_RELATIVE", /* name */ |
| 511 | false, /* partial_inplace */ |
| 512 | 0, /* src_mask */ |
| 513 | 0xffffffff, /* dst_mask */ |
| 514 | false), /* pcrel_offset */ |
| 515 | |
| 516 | /* Like R_PPC_REL24, but uses the value of the symbol within the |
| 517 | object rather than the final value. Normally used for |
| 518 | _GLOBAL_OFFSET_TABLE_. */ |
| 519 | HOWTO (R_PPC_LOCAL24PC, /* type */ |
| 520 | 0, /* rightshift */ |
| 521 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 522 | 26, /* bitsize */ |
| 523 | true, /* pc_relative */ |
| 524 | 0, /* bitpos */ |
| 525 | complain_overflow_signed, /* complain_on_overflow */ |
| 526 | bfd_elf_generic_reloc, /* special_function */ |
| 527 | "R_PPC_LOCAL24PC", /* name */ |
| 528 | false, /* partial_inplace */ |
| 529 | 0, /* src_mask */ |
| 530 | 0x3fffffc, /* dst_mask */ |
| 531 | true), /* pcrel_offset */ |
| 532 | |
| 533 | /* Like R_PPC_ADDR32, but may be unaligned. */ |
| 534 | HOWTO (R_PPC_UADDR32, /* type */ |
| 535 | 0, /* rightshift */ |
| 536 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 537 | 32, /* bitsize */ |
| 538 | false, /* pc_relative */ |
| 539 | 0, /* bitpos */ |
| 540 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 541 | bfd_elf_generic_reloc, /* special_function */ |
| 542 | "R_PPC_UADDR32", /* name */ |
| 543 | false, /* partial_inplace */ |
| 544 | 0, /* src_mask */ |
| 545 | 0xffffffff, /* dst_mask */ |
| 546 | false), /* pcrel_offset */ |
| 547 | |
| 548 | /* Like R_PPC_ADDR16, but may be unaligned. */ |
| 549 | HOWTO (R_PPC_UADDR16, /* type */ |
| 550 | 0, /* rightshift */ |
| 551 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 552 | 16, /* bitsize */ |
| 553 | false, /* pc_relative */ |
| 554 | 0, /* bitpos */ |
| 555 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 556 | bfd_elf_generic_reloc, /* special_function */ |
| 557 | "R_PPC_UADDR16", /* name */ |
| 558 | false, /* partial_inplace */ |
| 559 | 0, /* src_mask */ |
| 560 | 0xffff, /* dst_mask */ |
| 561 | false), /* pcrel_offset */ |
| 562 | |
| 563 | /* 32-bit PC relative */ |
| 564 | HOWTO (R_PPC_REL32, /* type */ |
| 565 | 0, /* rightshift */ |
| 566 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 567 | 32, /* bitsize */ |
| 568 | true, /* pc_relative */ |
| 569 | 0, /* bitpos */ |
| 570 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 571 | bfd_elf_generic_reloc, /* special_function */ |
| 572 | "R_PPC_REL32", /* name */ |
| 573 | false, /* partial_inplace */ |
| 574 | 0, /* src_mask */ |
| 575 | 0xffffffff, /* dst_mask */ |
| 576 | true), /* pcrel_offset */ |
| 577 | |
| 578 | /* 32-bit relocation to the symbol's procedure linkage table. |
| 579 | FIXME: not supported. */ |
| 580 | HOWTO (R_PPC_PLT32, /* type */ |
| 581 | 0, /* rightshift */ |
| 582 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 583 | 32, /* bitsize */ |
| 584 | false, /* pc_relative */ |
| 585 | 0, /* bitpos */ |
| 586 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 587 | bfd_elf_generic_reloc, /* special_function */ |
| 588 | "R_PPC_PLT32", /* name */ |
| 589 | false, /* partial_inplace */ |
| 590 | 0, /* src_mask */ |
| 591 | 0, /* dst_mask */ |
| 592 | false), /* pcrel_offset */ |
| 593 | |
| 594 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. |
| 595 | FIXME: not supported. */ |
| 596 | HOWTO (R_PPC_PLTREL32, /* type */ |
| 597 | 0, /* rightshift */ |
| 598 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 599 | 32, /* bitsize */ |
| 600 | true, /* pc_relative */ |
| 601 | 0, /* bitpos */ |
| 602 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 603 | bfd_elf_generic_reloc, /* special_function */ |
| 604 | "R_PPC_PLTREL32", /* name */ |
| 605 | false, /* partial_inplace */ |
| 606 | 0, /* src_mask */ |
| 607 | 0, /* dst_mask */ |
| 608 | true), /* pcrel_offset */ |
| 609 | |
| 610 | /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for |
| 611 | the symbol. */ |
| 612 | HOWTO (R_PPC_PLT16_LO, /* type */ |
| 613 | 0, /* rightshift */ |
| 614 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 615 | 16, /* bitsize */ |
| 616 | false, /* pc_relative */ |
| 617 | 0, /* bitpos */ |
| 618 | complain_overflow_dont, /* complain_on_overflow */ |
| 619 | bfd_elf_generic_reloc, /* special_function */ |
| 620 | "R_PPC_PLT16_LO", /* name */ |
| 621 | false, /* partial_inplace */ |
| 622 | 0, /* src_mask */ |
| 623 | 0xffff, /* dst_mask */ |
| 624 | false), /* pcrel_offset */ |
| 625 | |
| 626 | /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for |
| 627 | the symbol. */ |
| 628 | HOWTO (R_PPC_PLT16_HI, /* type */ |
| 629 | 16, /* rightshift */ |
| 630 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 631 | 16, /* bitsize */ |
| 632 | false, /* pc_relative */ |
| 633 | 0, /* bitpos */ |
| 634 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 635 | bfd_elf_generic_reloc, /* special_function */ |
| 636 | "R_PPC_PLT16_HI", /* name */ |
| 637 | false, /* partial_inplace */ |
| 638 | 0, /* src_mask */ |
| 639 | 0xffff, /* dst_mask */ |
| 640 | false), /* pcrel_offset */ |
| 641 | |
| 642 | /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for |
| 643 | the symbol. */ |
| 644 | HOWTO (R_PPC_PLT16_HA, /* type */ |
| 645 | 16, /* rightshift */ |
| 646 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 647 | 16, /* bitsize */ |
| 648 | false, /* pc_relative */ |
| 649 | 0, /* bitpos */ |
| 650 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 651 | ppc_elf_addr16_ha_reloc, /* special_function */ |
| 652 | "R_PPC_PLT16_HA", /* name */ |
| 653 | false, /* partial_inplace */ |
| 654 | 0, /* src_mask */ |
| 655 | 0xffff, /* dst_mask */ |
| 656 | false), /* pcrel_offset */ |
| 657 | |
| 658 | /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with |
| 659 | small data items. */ |
| 660 | HOWTO (R_PPC_SDAREL16, /* type */ |
| 661 | 0, /* rightshift */ |
| 662 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 663 | 16, /* bitsize */ |
| 664 | false, /* pc_relative */ |
| 665 | 0, /* bitpos */ |
| 666 | complain_overflow_signed, /* complain_on_overflow */ |
| 667 | bfd_elf_generic_reloc, /* special_function */ |
| 668 | "R_PPC_SDAREL16", /* name */ |
| 669 | false, /* partial_inplace */ |
| 670 | 0, /* src_mask */ |
| 671 | 0xffff, /* dst_mask */ |
| 672 | false), /* pcrel_offset */ |
| 673 | |
| 674 | /* 32-bit section relative relocation. */ |
| 675 | HOWTO (R_PPC_SECTOFF, /* type */ |
| 676 | 0, /* rightshift */ |
| 677 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 678 | 32, /* bitsize */ |
| 679 | true, /* pc_relative */ |
| 680 | 0, /* bitpos */ |
| 681 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 682 | bfd_elf_generic_reloc, /* special_function */ |
| 683 | "R_PPC_SECTOFF", /* name */ |
| 684 | false, /* partial_inplace */ |
| 685 | 0, /* src_mask */ |
| 686 | 0, /* dst_mask */ |
| 687 | true), /* pcrel_offset */ |
| 688 | |
| 689 | /* 16-bit lower half section relative relocation. */ |
| 690 | HOWTO (R_PPC_SECTOFF_LO, /* type */ |
| 691 | 0, /* rightshift */ |
| 692 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 693 | 16, /* bitsize */ |
| 694 | false, /* pc_relative */ |
| 695 | 0, /* bitpos */ |
| 696 | complain_overflow_dont, /* complain_on_overflow */ |
| 697 | bfd_elf_generic_reloc, /* special_function */ |
| 698 | "R_PPC_SECTOFF_LO", /* name */ |
| 699 | false, /* partial_inplace */ |
| 700 | 0, /* src_mask */ |
| 701 | 0xffff, /* dst_mask */ |
| 702 | false), /* pcrel_offset */ |
| 703 | |
| 704 | /* 16-bit upper half section relative relocation. */ |
| 705 | HOWTO (R_PPC_SECTOFF_HI, /* type */ |
| 706 | 16, /* rightshift */ |
| 707 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 708 | 16, /* bitsize */ |
| 709 | false, /* pc_relative */ |
| 710 | 0, /* bitpos */ |
| 711 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 712 | bfd_elf_generic_reloc, /* special_function */ |
| 713 | "R_PPC_SECTOFF_HI", /* name */ |
| 714 | false, /* partial_inplace */ |
| 715 | 0, /* src_mask */ |
| 716 | 0xffff, /* dst_mask */ |
| 717 | false), /* pcrel_offset */ |
| 718 | |
| 719 | /* 16-bit upper half adjusted section relative relocation. */ |
| 720 | HOWTO (R_PPC_SECTOFF_HA, /* type */ |
| 721 | 16, /* rightshift */ |
| 722 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 723 | 16, /* bitsize */ |
| 724 | false, /* pc_relative */ |
| 725 | 0, /* bitpos */ |
| 726 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 727 | ppc_elf_addr16_ha_reloc, /* special_function */ |
| 728 | "R_PPC_SECTOFF_HA", /* name */ |
| 729 | false, /* partial_inplace */ |
| 730 | 0, /* src_mask */ |
| 731 | 0xffff, /* dst_mask */ |
| 732 | false), /* pcrel_offset */ |
| 733 | |
| 734 | /* The remaining relocs are from the Embedded ELF ABI, and are not |
| 735 | in the SVR4 ELF ABI. */ |
| 736 | |
| 737 | /* 32 bit value resulting from the addend minus the symbol */ |
| 738 | HOWTO (R_PPC_EMB_NADDR32, /* type */ |
| 739 | 0, /* rightshift */ |
| 740 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 741 | 32, /* bitsize */ |
| 742 | false, /* pc_relative */ |
| 743 | 0, /* bitpos */ |
| 744 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 745 | bfd_elf_generic_reloc, /* special_function */ |
| 746 | "R_PPC_EMB_NADDR32", /* name */ |
| 747 | false, /* partial_inplace */ |
| 748 | 0, /* src_mask */ |
| 749 | 0xffffffff, /* dst_mask */ |
| 750 | false), /* pcrel_offset */ |
| 751 | |
| 752 | /* 16 bit value resulting from the addend minus the symbol */ |
| 753 | HOWTO (R_PPC_EMB_NADDR16, /* type */ |
| 754 | 0, /* rightshift */ |
| 755 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 756 | 16, /* bitsize */ |
| 757 | false, /* pc_relative */ |
| 758 | 0, /* bitpos */ |
| 759 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 760 | bfd_elf_generic_reloc, /* special_function */ |
| 761 | "R_PPC_EMB_NADDR16", /* name */ |
| 762 | false, /* partial_inplace */ |
| 763 | 0, /* src_mask */ |
| 764 | 0xffff, /* dst_mask */ |
| 765 | false), /* pcrel_offset */ |
| 766 | |
| 767 | /* 16 bit value resulting from the addend minus the symbol */ |
| 768 | HOWTO (R_PPC_EMB_NADDR16_LO, /* type */ |
| 769 | 0, /* rightshift */ |
| 770 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 771 | 16, /* bitsize */ |
| 772 | false, /* pc_relative */ |
| 773 | 0, /* bitpos */ |
| 774 | complain_overflow_dont,/* complain_on_overflow */ |
| 775 | bfd_elf_generic_reloc, /* special_function */ |
| 776 | "R_PPC_EMB_ADDR16_LO", /* name */ |
| 777 | false, /* partial_inplace */ |
| 778 | 0, /* src_mask */ |
| 779 | 0xffff, /* dst_mask */ |
| 780 | false), /* pcrel_offset */ |
| 781 | |
| 782 | /* The high order 16 bits of the addend minus the symbol */ |
| 783 | HOWTO (R_PPC_EMB_NADDR16_HI, /* type */ |
| 784 | 16, /* rightshift */ |
| 785 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 786 | 16, /* bitsize */ |
| 787 | false, /* pc_relative */ |
| 788 | 0, /* bitpos */ |
| 789 | complain_overflow_dont, /* complain_on_overflow */ |
| 790 | bfd_elf_generic_reloc, /* special_function */ |
| 791 | "R_PPC_EMB_NADDR16_HI", /* name */ |
| 792 | false, /* partial_inplace */ |
| 793 | 0, /* src_mask */ |
| 794 | 0xffff, /* dst_mask */ |
| 795 | false), /* pcrel_offset */ |
| 796 | |
| 797 | /* The high order 16 bits of the result of the addend minus the address, |
| 798 | plus 1 if the contents of the low 16 bits, treated as a signed number, |
| 799 | is negative. */ |
| 800 | HOWTO (R_PPC_EMB_NADDR16_HA, /* type */ |
| 801 | 16, /* rightshift */ |
| 802 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 803 | 16, /* bitsize */ |
| 804 | false, /* pc_relative */ |
| 805 | 0, /* bitpos */ |
| 806 | complain_overflow_dont, /* complain_on_overflow */ |
| 807 | ppc_elf_addr16_ha_reloc, /* special_function */ |
| 808 | "R_PPC_EMB_NADDR16_HA", /* name */ |
| 809 | false, /* partial_inplace */ |
| 810 | 0, /* src_mask */ |
| 811 | 0xffff, /* dst_mask */ |
| 812 | false), /* pcrel_offset */ |
| 813 | |
| 814 | /* 16 bit value resulting from allocating a 4 byte word to hold an |
| 815 | address in the .sdata section, and returning the offset from |
| 816 | _SDA_BASE_ for that relocation */ |
| 817 | HOWTO (R_PPC_EMB_SDAI16, /* type */ |
| 818 | 0, /* rightshift */ |
| 819 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 820 | 16, /* bitsize */ |
| 821 | false, /* pc_relative */ |
| 822 | 0, /* bitpos */ |
| 823 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 824 | bfd_elf_generic_reloc, /* special_function */ |
| 825 | "R_PPC_EMB_SDAI16", /* name */ |
| 826 | false, /* partial_inplace */ |
| 827 | 0, /* src_mask */ |
| 828 | 0xffff, /* dst_mask */ |
| 829 | false), /* pcrel_offset */ |
| 830 | |
| 831 | /* 16 bit value resulting from allocating a 4 byte word to hold an |
| 832 | address in the .sdata2 section, and returning the offset from |
| 833 | _SDA2_BASE_ for that relocation */ |
| 834 | HOWTO (R_PPC_EMB_SDA2I16, /* type */ |
| 835 | 0, /* rightshift */ |
| 836 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 837 | 16, /* bitsize */ |
| 838 | false, /* pc_relative */ |
| 839 | 0, /* bitpos */ |
| 840 | complain_overflow_bitfield, /* complain_on_overflow */ |
| 841 | bfd_elf_generic_reloc, /* special_function */ |
| 842 | "R_PPC_EMB_SDA2I16", /* name */ |
| 843 | false, /* partial_inplace */ |
| 844 | 0, /* src_mask */ |
| 845 | 0xffff, /* dst_mask */ |
| 846 | false), /* pcrel_offset */ |
| 847 | |
| 848 | /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with |
| 849 | small data items. */ |
| 850 | HOWTO (R_PPC_EMB_SDA2REL, /* type */ |
| 851 | 0, /* rightshift */ |
| 852 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 853 | 16, /* bitsize */ |
| 854 | false, /* pc_relative */ |
| 855 | 0, /* bitpos */ |
| 856 | complain_overflow_signed, /* complain_on_overflow */ |
| 857 | bfd_elf_generic_reloc, /* special_function */ |
| 858 | "R_PPC_EMB_SDA2REL", /* name */ |
| 859 | false, /* partial_inplace */ |
| 860 | 0, /* src_mask */ |
| 861 | 0xffff, /* dst_mask */ |
| 862 | false), /* pcrel_offset */ |
| 863 | |
| 864 | /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit |
| 865 | signed offset from the appropriate base, and filling in the register |
| 866 | field with the appropriate register (0, 2, or 13). */ |
| 867 | HOWTO (R_PPC_EMB_SDA21, /* type */ |
| 868 | 0, /* rightshift */ |
| 869 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 870 | 16, /* bitsize */ |
| 871 | false, /* pc_relative */ |
| 872 | 0, /* bitpos */ |
| 873 | complain_overflow_signed, /* complain_on_overflow */ |
| 874 | bfd_elf_generic_reloc, /* special_function */ |
| 875 | "R_PPC_EMB_SDA21", /* name */ |
| 876 | false, /* partial_inplace */ |
| 877 | 0, /* src_mask */ |
| 878 | 0xffff, /* dst_mask */ |
| 879 | false), /* pcrel_offset */ |
| 880 | |
| 881 | /* Relocation not handled: R_PPC_EMB_MRKREF */ |
| 882 | /* Relocation not handled: R_PPC_EMB_RELSEC16 */ |
| 883 | /* Relocation not handled: R_PPC_EMB_RELST_LO */ |
| 884 | /* Relocation not handled: R_PPC_EMB_RELST_HI */ |
| 885 | /* Relocation not handled: R_PPC_EMB_RELST_HA */ |
| 886 | /* Relocation not handled: R_PPC_EMB_BIT_FLD */ |
| 887 | |
| 888 | /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling |
| 889 | in the 16 bit signed offset from the appropriate base, and filling in the |
| 890 | register field with the appropriate register (0, 2, or 13). */ |
| 891 | HOWTO (R_PPC_EMB_RELSDA, /* type */ |
| 892 | 0, /* rightshift */ |
| 893 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 894 | 16, /* bitsize */ |
| 895 | true, /* pc_relative */ |
| 896 | 0, /* bitpos */ |
| 897 | complain_overflow_signed, /* complain_on_overflow */ |
| 898 | bfd_elf_generic_reloc, /* special_function */ |
| 899 | "R_PPC_EMB_RELSDA", /* name */ |
| 900 | false, /* partial_inplace */ |
| 901 | 0, /* src_mask */ |
| 902 | 0xffff, /* dst_mask */ |
| 903 | false), /* pcrel_offset */ |
| 904 | |
| 905 | /* GNU extension to record C++ vtable hierarchy */ |
| 906 | HOWTO (R_PPC_GNU_VTINHERIT, /* type */ |
| 907 | 0, /* rightshift */ |
| 908 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 909 | 0, /* bitsize */ |
| 910 | false, /* pc_relative */ |
| 911 | 0, /* bitpos */ |
| 912 | complain_overflow_dont, /* complain_on_overflow */ |
| 913 | NULL, /* special_function */ |
| 914 | "R_PPC_GNU_VTINHERIT", /* name */ |
| 915 | false, /* partial_inplace */ |
| 916 | 0, /* src_mask */ |
| 917 | 0, /* dst_mask */ |
| 918 | false), /* pcrel_offset */ |
| 919 | |
| 920 | /* GNU extension to record C++ vtable member usage */ |
| 921 | HOWTO (R_PPC_GNU_VTENTRY, /* type */ |
| 922 | 0, /* rightshift */ |
| 923 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 924 | 0, /* bitsize */ |
| 925 | false, /* pc_relative */ |
| 926 | 0, /* bitpos */ |
| 927 | complain_overflow_dont, /* complain_on_overflow */ |
| 928 | NULL, /* special_function */ |
| 929 | "R_PPC_GNU_VTENTRY", /* name */ |
| 930 | false, /* partial_inplace */ |
| 931 | 0, /* src_mask */ |
| 932 | 0, /* dst_mask */ |
| 933 | false), /* pcrel_offset */ |
| 934 | |
| 935 | /* Phony reloc to handle AIX style TOC entries */ |
| 936 | HOWTO (R_PPC_TOC16, /* type */ |
| 937 | 0, /* rightshift */ |
| 938 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 939 | 16, /* bitsize */ |
| 940 | false, /* pc_relative */ |
| 941 | 0, /* bitpos */ |
| 942 | complain_overflow_signed, /* complain_on_overflow */ |
| 943 | bfd_elf_generic_reloc, /* special_function */ |
| 944 | "R_PPC_TOC16", /* name */ |
| 945 | false, /* partial_inplace */ |
| 946 | 0, /* src_mask */ |
| 947 | 0xffff, /* dst_mask */ |
| 948 | false), /* pcrel_offset */ |
| 949 | }; |
| 950 | |
| 951 | \f |
| 952 | /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */ |
| 953 | |
| 954 | static void |
| 955 | ppc_elf_howto_init () |
| 956 | { |
| 957 | unsigned int i, type; |
| 958 | |
| 959 | for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++) |
| 960 | { |
| 961 | type = ppc_elf_howto_raw[i].type; |
| 962 | BFD_ASSERT (type < sizeof (ppc_elf_howto_table) / sizeof (ppc_elf_howto_table[0])); |
| 963 | ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i]; |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | \f |
| 968 | /* This function handles relaxing for the PPC with option --mpc860c0[=<n>]. |
| 969 | |
| 970 | The MPC860, revision C0 or earlier contains a bug in the die. |
| 971 | If all of the following conditions are true, the next instruction |
| 972 | to be executed *may* be treated as a no-op. |
| 973 | 1/ A forward branch is executed. |
| 974 | 2/ The branch is predicted as not taken. |
| 975 | 3/ The branch is taken. |
| 976 | 4/ The branch is located in the last 5 words of a page. |
| 977 | (The EOP limit is 5 by default but may be specified as any value from 1-10.) |
| 978 | |
| 979 | Our software solution is to detect these problematic branches in a |
| 980 | linker pass and modify them as follows: |
| 981 | 1/ Unconditional branches - Since these are always predicted taken, |
| 982 | there is no problem and no action is required. |
| 983 | 2/ Conditional backward branches - No problem, no action required. |
| 984 | 3/ Conditional forward branches - Ensure that the "inverse prediction |
| 985 | bit" is set (ensure it is predicted taken). |
| 986 | 4/ Conditional register branches - Ensure that the "y bit" is set |
| 987 | (ensure it is predicted taken). |
| 988 | */ |
| 989 | |
| 990 | /* Sort sections by address. */ |
| 991 | |
| 992 | static int |
| 993 | ppc_elf_sort_rela (arg1, arg2) |
| 994 | const void *arg1; |
| 995 | const void *arg2; |
| 996 | { |
| 997 | const Elf_Internal_Rela **rela1 = (const Elf_Internal_Rela**) arg1; |
| 998 | const Elf_Internal_Rela **rela2 = (const Elf_Internal_Rela**) arg2; |
| 999 | |
| 1000 | /* Sort by offset. */ |
| 1001 | return ((*rela1)->r_offset - (*rela2)->r_offset); |
| 1002 | } |
| 1003 | |
| 1004 | static boolean |
| 1005 | ppc_elf_relax_section (abfd, isec, link_info, again) |
| 1006 | bfd *abfd; |
| 1007 | asection *isec; |
| 1008 | struct bfd_link_info *link_info; |
| 1009 | boolean *again; |
| 1010 | { |
| 1011 | #define PAGESIZE 0x1000 |
| 1012 | |
| 1013 | bfd_byte *contents = NULL; |
| 1014 | bfd_byte *free_contents = NULL; |
| 1015 | Elf_Internal_Rela *internal_relocs = NULL; |
| 1016 | Elf_Internal_Rela *free_relocs = NULL; |
| 1017 | Elf_Internal_Rela **rela_comb = NULL; |
| 1018 | int comb_curr, comb_count; |
| 1019 | |
| 1020 | /* We never have to do this more than once per input section. */ |
| 1021 | *again = false; |
| 1022 | |
| 1023 | /* If needed, initialize this section's cooked size. */ |
| 1024 | if (isec->_cooked_size == 0) |
| 1025 | isec->_cooked_size = isec->_raw_size; |
| 1026 | |
| 1027 | /* We're only interested in text sections which overlap the |
| 1028 | troublesome area at the end of a page. */ |
| 1029 | if (link_info->mpc860c0 && (isec->flags & SEC_CODE) && isec->_cooked_size) |
| 1030 | { |
| 1031 | bfd_vma dot, end_page, end_section; |
| 1032 | boolean section_modified; |
| 1033 | |
| 1034 | /* Get the section contents. */ |
| 1035 | /* Get cached copy if it exists. */ |
| 1036 | if (elf_section_data (isec)->this_hdr.contents != NULL) |
| 1037 | contents = elf_section_data (isec)->this_hdr.contents; |
| 1038 | else |
| 1039 | { |
| 1040 | /* Go get them off disk. */ |
| 1041 | contents = (bfd_byte *) bfd_malloc (isec->_raw_size); |
| 1042 | if (contents == NULL) |
| 1043 | goto error_return; |
| 1044 | free_contents = contents; |
| 1045 | |
| 1046 | if (! bfd_get_section_contents (abfd, isec, contents, |
| 1047 | (file_ptr) 0, isec->_raw_size)) |
| 1048 | goto error_return; |
| 1049 | } |
| 1050 | |
| 1051 | comb_curr = 0; |
| 1052 | comb_count = 0; |
| 1053 | if (isec->reloc_count) |
| 1054 | { |
| 1055 | unsigned n; |
| 1056 | |
| 1057 | /* Get a copy of the native relocations. */ |
| 1058 | internal_relocs = _bfd_elf32_link_read_relocs ( |
| 1059 | abfd, isec, (PTR) NULL, (Elf_Internal_Rela *) NULL, |
| 1060 | link_info->keep_memory); |
| 1061 | if (internal_relocs == NULL) |
| 1062 | goto error_return; |
| 1063 | if (! link_info->keep_memory) |
| 1064 | free_relocs = internal_relocs; |
| 1065 | |
| 1066 | /* Setup a faster access method for the reloc info we need. */ |
| 1067 | rela_comb = (Elf_Internal_Rela**) |
| 1068 | bfd_malloc (isec->reloc_count*sizeof (Elf_Internal_Rela*)); |
| 1069 | if (rela_comb == NULL) |
| 1070 | goto error_return; |
| 1071 | for (n=0; n<isec->reloc_count; ++n) |
| 1072 | { |
| 1073 | long r_type; |
| 1074 | |
| 1075 | r_type = ELF32_R_TYPE (internal_relocs[n].r_info); |
| 1076 | if (r_type < 0 || r_type >= (int)R_PPC_max) |
| 1077 | goto error_return; |
| 1078 | |
| 1079 | /* Prologue constants are sometimes present in the ".text" |
| 1080 | sections and they can be identified by their associated relocation. |
| 1081 | We don't want to process those words and some others which |
| 1082 | can also be identified by their relocations. However, not all |
| 1083 | conditional branches will have a relocation so we will |
| 1084 | only ignore words that 1) have a reloc, and 2) the reloc |
| 1085 | is not applicable to a conditional branch. |
| 1086 | The array rela_comb is built here for use in the EOP scan loop. */ |
| 1087 | switch (r_type) |
| 1088 | { |
| 1089 | case R_PPC_ADDR14_BRNTAKEN: /* absolute, predicted not taken */ |
| 1090 | case R_PPC_REL14: /* relative cond. br. */ |
| 1091 | case R_PPC_REL14_BRNTAKEN: /* rel. cond. br., predicted not taken */ |
| 1092 | /* We should check the instruction. */ |
| 1093 | break; |
| 1094 | default: |
| 1095 | /* The word is not a conditional branch - ignore it. */ |
| 1096 | rela_comb[comb_count++] = &internal_relocs[n]; |
| 1097 | break; |
| 1098 | } |
| 1099 | } |
| 1100 | if (comb_count > 1) |
| 1101 | qsort (rela_comb, (size_t) comb_count, sizeof (int), ppc_elf_sort_rela); |
| 1102 | } |
| 1103 | |
| 1104 | /* Enumerate each EOP region that overlaps this section. */ |
| 1105 | end_section = isec->vma + isec->_cooked_size; |
| 1106 | dot = end_page = (isec->vma | (PAGESIZE - 1)) + 1; |
| 1107 | dot -= link_info->mpc860c0; |
| 1108 | section_modified = false; |
| 1109 | if (dot < isec->vma) /* Increment the start position if this section */ |
| 1110 | dot = isec->vma; /* begins in the middle of its first EOP region. */ |
| 1111 | for (; |
| 1112 | dot < end_section; |
| 1113 | dot += PAGESIZE, end_page += PAGESIZE) |
| 1114 | { |
| 1115 | |
| 1116 | /* Check each word in this EOP region. */ |
| 1117 | for (; dot < end_page; dot += 4) |
| 1118 | { |
| 1119 | bfd_vma isec_offset; |
| 1120 | unsigned long insn; |
| 1121 | boolean skip, modified; |
| 1122 | |
| 1123 | /* Don't process this word if there is a relocation for it and |
| 1124 | the relocation indicates the word is not a conditional branch. */ |
| 1125 | skip = false; |
| 1126 | isec_offset = dot - isec->vma; |
| 1127 | for (; comb_curr<comb_count; ++comb_curr) |
| 1128 | { |
| 1129 | bfd_vma r_offset; |
| 1130 | |
| 1131 | r_offset = rela_comb[comb_curr]->r_offset; |
| 1132 | if (r_offset >= isec_offset) |
| 1133 | { |
| 1134 | if (r_offset == isec_offset) skip = true; |
| 1135 | break; |
| 1136 | } |
| 1137 | } |
| 1138 | if (skip) continue; |
| 1139 | |
| 1140 | /* Check the current word for a problematic conditional branch. */ |
| 1141 | #define BO0(insn) ((insn) & 0x02000000) |
| 1142 | #define BO2(insn) ((insn) & 0x00800000) |
| 1143 | #define BO4(insn) ((insn) & 0x00200000) |
| 1144 | insn = (unsigned long) bfd_get_32 (abfd, contents + isec_offset); |
| 1145 | modified = false; |
| 1146 | if ((insn & 0xFc000000) == 0x40000000) |
| 1147 | { |
| 1148 | /* Instruction is BCx */ |
| 1149 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn)) |
| 1150 | { |
| 1151 | bfd_vma target; |
| 1152 | /* This branch is predicted as "normal". |
| 1153 | If this is a forward branch, it is problematic. */ |
| 1154 | |
| 1155 | target = insn & 0x0000Fffc; /*extract*/ |
| 1156 | target = (target ^ 0x8000) - 0x8000; /*sign extend*/ |
| 1157 | if ((insn & 0x00000002) == 0) |
| 1158 | target += dot; /*convert to abs*/ |
| 1159 | if (target > dot) |
| 1160 | { |
| 1161 | insn |= 0x00200000; /* set the prediction bit */ |
| 1162 | modified = true; |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | else if ((insn & 0xFc00Fffe) == 0x4c000420) |
| 1167 | { |
| 1168 | /* Instruction is BCCTRx */ |
| 1169 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn)) |
| 1170 | { |
| 1171 | /* This branch is predicted as not-taken. |
| 1172 | If this is a forward branch, it is problematic. |
| 1173 | Since we can't tell statically if it will branch forward, |
| 1174 | always set the prediction bit. */ |
| 1175 | insn |= 0x00200000; /* set the prediction bit */ |
| 1176 | modified = true; |
| 1177 | } |
| 1178 | } |
| 1179 | else if ((insn & 0xFc00Fffe) == 0x4c000020) |
| 1180 | { |
| 1181 | /* Instruction is BCLRx */ |
| 1182 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn)) |
| 1183 | { |
| 1184 | /* This branch is predicted as not-taken. |
| 1185 | If this is a forward branch, it is problematic. |
| 1186 | Since we can't tell statically if it will branch forward, |
| 1187 | always set the prediction bit. */ |
| 1188 | insn |= 0x00200000; /* set the prediction bit */ |
| 1189 | modified = true; |
| 1190 | } |
| 1191 | } |
| 1192 | #undef BO0 |
| 1193 | #undef BO2 |
| 1194 | #undef BO4 |
| 1195 | if (modified) |
| 1196 | { |
| 1197 | bfd_put_32 (abfd, insn, contents + isec_offset); |
| 1198 | section_modified = true; |
| 1199 | } |
| 1200 | } |
| 1201 | } |
| 1202 | if (section_modified) |
| 1203 | { |
| 1204 | elf_section_data (isec)->this_hdr.contents = contents; |
| 1205 | free_contents = NULL; |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | if (rela_comb != NULL) |
| 1210 | { |
| 1211 | free (rela_comb); |
| 1212 | rela_comb = NULL; |
| 1213 | } |
| 1214 | |
| 1215 | if (free_relocs != NULL) |
| 1216 | { |
| 1217 | free (free_relocs); |
| 1218 | free_relocs = NULL; |
| 1219 | } |
| 1220 | |
| 1221 | if (free_contents != NULL) |
| 1222 | { |
| 1223 | if (! link_info->keep_memory) |
| 1224 | free (free_contents); |
| 1225 | else |
| 1226 | { |
| 1227 | /* Cache the section contents for elf_link_input_bfd. */ |
| 1228 | elf_section_data (isec)->this_hdr.contents = contents; |
| 1229 | } |
| 1230 | free_contents = NULL; |
| 1231 | } |
| 1232 | |
| 1233 | return true; |
| 1234 | |
| 1235 | error_return: |
| 1236 | if (rela_comb != NULL) |
| 1237 | free (rela_comb); |
| 1238 | if (free_relocs != NULL) |
| 1239 | free (free_relocs); |
| 1240 | if (free_contents != NULL) |
| 1241 | free (free_contents); |
| 1242 | return false; |
| 1243 | } |
| 1244 | |
| 1245 | \f |
| 1246 | static reloc_howto_type * |
| 1247 | ppc_elf_reloc_type_lookup (abfd, code) |
| 1248 | bfd *abfd ATTRIBUTE_UNUSED; |
| 1249 | bfd_reloc_code_real_type code; |
| 1250 | { |
| 1251 | enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE; |
| 1252 | |
| 1253 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) |
| 1254 | /* Initialize howto table if needed */ |
| 1255 | ppc_elf_howto_init (); |
| 1256 | |
| 1257 | switch ((int)code) |
| 1258 | { |
| 1259 | default: |
| 1260 | return (reloc_howto_type *)NULL; |
| 1261 | |
| 1262 | case BFD_RELOC_NONE: ppc_reloc = R_PPC_NONE; break; |
| 1263 | case BFD_RELOC_32: ppc_reloc = R_PPC_ADDR32; break; |
| 1264 | case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC_ADDR24; break; |
| 1265 | case BFD_RELOC_16: ppc_reloc = R_PPC_ADDR16; break; |
| 1266 | case BFD_RELOC_LO16: ppc_reloc = R_PPC_ADDR16_LO; break; |
| 1267 | case BFD_RELOC_HI16: ppc_reloc = R_PPC_ADDR16_HI; break; |
| 1268 | case BFD_RELOC_HI16_S: ppc_reloc = R_PPC_ADDR16_HA; break; |
| 1269 | case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC_ADDR14; break; |
| 1270 | case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC_ADDR14_BRTAKEN; break; |
| 1271 | case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC_ADDR14_BRNTAKEN; break; |
| 1272 | case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC_REL24; break; |
| 1273 | case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC_REL14; break; |
| 1274 | case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC_REL14_BRTAKEN; break; |
| 1275 | case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC_REL14_BRNTAKEN; break; |
| 1276 | case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC_GOT16; break; |
| 1277 | case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC_GOT16_LO; break; |
| 1278 | case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC_GOT16_HI; break; |
| 1279 | case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC_GOT16_HA; break; |
| 1280 | case BFD_RELOC_24_PLT_PCREL: ppc_reloc = R_PPC_PLTREL24; break; |
| 1281 | case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC_COPY; break; |
| 1282 | case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC_GLOB_DAT; break; |
| 1283 | case BFD_RELOC_PPC_LOCAL24PC: ppc_reloc = R_PPC_LOCAL24PC; break; |
| 1284 | case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC_REL32; break; |
| 1285 | case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC_PLT32; break; |
| 1286 | case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC_PLTREL32; break; |
| 1287 | case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC_PLT16_LO; break; |
| 1288 | case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC_PLT16_HI; break; |
| 1289 | case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC_PLT16_HA; break; |
| 1290 | case BFD_RELOC_GPREL16: ppc_reloc = R_PPC_SDAREL16; break; |
| 1291 | case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC_SECTOFF; break; |
| 1292 | case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC_SECTOFF_LO; break; |
| 1293 | case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC_SECTOFF_HI; break; |
| 1294 | case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC_SECTOFF_HA; break; |
| 1295 | case BFD_RELOC_CTOR: ppc_reloc = R_PPC_ADDR32; break; |
| 1296 | case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC_TOC16; break; |
| 1297 | case BFD_RELOC_PPC_EMB_NADDR32: ppc_reloc = R_PPC_EMB_NADDR32; break; |
| 1298 | case BFD_RELOC_PPC_EMB_NADDR16: ppc_reloc = R_PPC_EMB_NADDR16; break; |
| 1299 | case BFD_RELOC_PPC_EMB_NADDR16_LO: ppc_reloc = R_PPC_EMB_NADDR16_LO; break; |
| 1300 | case BFD_RELOC_PPC_EMB_NADDR16_HI: ppc_reloc = R_PPC_EMB_NADDR16_HI; break; |
| 1301 | case BFD_RELOC_PPC_EMB_NADDR16_HA: ppc_reloc = R_PPC_EMB_NADDR16_HA; break; |
| 1302 | case BFD_RELOC_PPC_EMB_SDAI16: ppc_reloc = R_PPC_EMB_SDAI16; break; |
| 1303 | case BFD_RELOC_PPC_EMB_SDA2I16: ppc_reloc = R_PPC_EMB_SDA2I16; break; |
| 1304 | case BFD_RELOC_PPC_EMB_SDA2REL: ppc_reloc = R_PPC_EMB_SDA2REL; break; |
| 1305 | case BFD_RELOC_PPC_EMB_SDA21: ppc_reloc = R_PPC_EMB_SDA21; break; |
| 1306 | case BFD_RELOC_PPC_EMB_MRKREF: ppc_reloc = R_PPC_EMB_MRKREF; break; |
| 1307 | case BFD_RELOC_PPC_EMB_RELSEC16: ppc_reloc = R_PPC_EMB_RELSEC16; break; |
| 1308 | case BFD_RELOC_PPC_EMB_RELST_LO: ppc_reloc = R_PPC_EMB_RELST_LO; break; |
| 1309 | case BFD_RELOC_PPC_EMB_RELST_HI: ppc_reloc = R_PPC_EMB_RELST_HI; break; |
| 1310 | case BFD_RELOC_PPC_EMB_RELST_HA: ppc_reloc = R_PPC_EMB_RELST_HA; break; |
| 1311 | case BFD_RELOC_PPC_EMB_BIT_FLD: ppc_reloc = R_PPC_EMB_BIT_FLD; break; |
| 1312 | case BFD_RELOC_PPC_EMB_RELSDA: ppc_reloc = R_PPC_EMB_RELSDA; break; |
| 1313 | case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC_GNU_VTINHERIT; break; |
| 1314 | case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC_GNU_VTENTRY; break; |
| 1315 | } |
| 1316 | |
| 1317 | return ppc_elf_howto_table[ (int)ppc_reloc ]; |
| 1318 | }; |
| 1319 | |
| 1320 | /* Set the howto pointer for a PowerPC ELF reloc. */ |
| 1321 | |
| 1322 | static void |
| 1323 | ppc_elf_info_to_howto (abfd, cache_ptr, dst) |
| 1324 | bfd *abfd ATTRIBUTE_UNUSED; |
| 1325 | arelent *cache_ptr; |
| 1326 | Elf32_Internal_Rela *dst; |
| 1327 | { |
| 1328 | if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */ |
| 1329 | ppc_elf_howto_init (); |
| 1330 | |
| 1331 | BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max); |
| 1332 | cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)]; |
| 1333 | } |
| 1334 | |
| 1335 | /* Handle the R_PPC_ADDR16_HA reloc. */ |
| 1336 | |
| 1337 | static bfd_reloc_status_type |
| 1338 | ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section, |
| 1339 | output_bfd, error_message) |
| 1340 | bfd *abfd ATTRIBUTE_UNUSED; |
| 1341 | arelent *reloc_entry; |
| 1342 | asymbol *symbol; |
| 1343 | PTR data ATTRIBUTE_UNUSED; |
| 1344 | asection *input_section; |
| 1345 | bfd *output_bfd; |
| 1346 | char **error_message ATTRIBUTE_UNUSED; |
| 1347 | { |
| 1348 | bfd_vma relocation; |
| 1349 | |
| 1350 | if (output_bfd != NULL) |
| 1351 | { |
| 1352 | reloc_entry->address += input_section->output_offset; |
| 1353 | return bfd_reloc_ok; |
| 1354 | } |
| 1355 | |
| 1356 | if (reloc_entry->address > input_section->_cooked_size) |
| 1357 | return bfd_reloc_outofrange; |
| 1358 | |
| 1359 | if (bfd_is_com_section (symbol->section)) |
| 1360 | relocation = 0; |
| 1361 | else |
| 1362 | relocation = symbol->value; |
| 1363 | |
| 1364 | relocation += symbol->section->output_section->vma; |
| 1365 | relocation += symbol->section->output_offset; |
| 1366 | relocation += reloc_entry->addend; |
| 1367 | |
| 1368 | reloc_entry->addend += (relocation & 0x8000) << 1; |
| 1369 | |
| 1370 | return bfd_reloc_continue; |
| 1371 | } |
| 1372 | |
| 1373 | /* Function to set whether a module needs the -mrelocatable bit set. */ |
| 1374 | |
| 1375 | static boolean |
| 1376 | ppc_elf_set_private_flags (abfd, flags) |
| 1377 | bfd *abfd; |
| 1378 | flagword flags; |
| 1379 | { |
| 1380 | BFD_ASSERT (!elf_flags_init (abfd) |
| 1381 | || elf_elfheader (abfd)->e_flags == flags); |
| 1382 | |
| 1383 | elf_elfheader (abfd)->e_flags = flags; |
| 1384 | elf_flags_init (abfd) = true; |
| 1385 | return true; |
| 1386 | } |
| 1387 | |
| 1388 | /* Copy backend specific data from one object module to another */ |
| 1389 | static boolean |
| 1390 | ppc_elf_copy_private_bfd_data (ibfd, obfd) |
| 1391 | bfd *ibfd; |
| 1392 | bfd *obfd; |
| 1393 | { |
| 1394 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 1395 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 1396 | return true; |
| 1397 | |
| 1398 | BFD_ASSERT (!elf_flags_init (obfd) |
| 1399 | || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags); |
| 1400 | |
| 1401 | elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags; |
| 1402 | elf_flags_init (obfd) = true; |
| 1403 | return true; |
| 1404 | } |
| 1405 | |
| 1406 | /* Merge backend specific data from an object file to the output |
| 1407 | object file when linking */ |
| 1408 | static boolean |
| 1409 | ppc_elf_merge_private_bfd_data (ibfd, obfd) |
| 1410 | bfd *ibfd; |
| 1411 | bfd *obfd; |
| 1412 | { |
| 1413 | flagword old_flags; |
| 1414 | flagword new_flags; |
| 1415 | boolean error; |
| 1416 | |
| 1417 | /* Check if we have the same endianess */ |
| 1418 | if (_bfd_generic_verify_endian_match (ibfd, obfd) == false) |
| 1419 | return false; |
| 1420 | |
| 1421 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 1422 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 1423 | return true; |
| 1424 | |
| 1425 | new_flags = elf_elfheader (ibfd)->e_flags; |
| 1426 | old_flags = elf_elfheader (obfd)->e_flags; |
| 1427 | if (!elf_flags_init (obfd)) /* First call, no flags set */ |
| 1428 | { |
| 1429 | elf_flags_init (obfd) = true; |
| 1430 | elf_elfheader (obfd)->e_flags = new_flags; |
| 1431 | } |
| 1432 | |
| 1433 | else if (new_flags == old_flags) /* Compatible flags are ok */ |
| 1434 | ; |
| 1435 | |
| 1436 | else /* Incompatible flags */ |
| 1437 | { |
| 1438 | /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked |
| 1439 | with either. */ |
| 1440 | error = false; |
| 1441 | if ((new_flags & EF_PPC_RELOCATABLE) != 0 |
| 1442 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) |
| 1443 | { |
| 1444 | error = true; |
| 1445 | (*_bfd_error_handler) |
| 1446 | (_("%s: compiled with -mrelocatable and linked with modules compiled normally"), |
| 1447 | bfd_get_filename (ibfd)); |
| 1448 | } |
| 1449 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 |
| 1450 | && (old_flags & EF_PPC_RELOCATABLE) != 0) |
| 1451 | { |
| 1452 | error = true; |
| 1453 | (*_bfd_error_handler) |
| 1454 | (_("%s: compiled normally and linked with modules compiled with -mrelocatable"), |
| 1455 | bfd_get_filename (ibfd)); |
| 1456 | } |
| 1457 | |
| 1458 | /* The output is -mrelocatable-lib iff both the input files are. */ |
| 1459 | if (! (new_flags & EF_PPC_RELOCATABLE_LIB)) |
| 1460 | elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB; |
| 1461 | |
| 1462 | /* The output is -mrelocatable iff it can't be -mrelocatable-lib, |
| 1463 | but each input file is either -mrelocatable or -mrelocatable-lib. */ |
| 1464 | if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB) |
| 1465 | && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)) |
| 1466 | && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))) |
| 1467 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE; |
| 1468 | |
| 1469 | /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */ |
| 1470 | elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB); |
| 1471 | |
| 1472 | new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); |
| 1473 | old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); |
| 1474 | |
| 1475 | /* Warn about any other mismatches */ |
| 1476 | if (new_flags != old_flags) |
| 1477 | { |
| 1478 | error = true; |
| 1479 | (*_bfd_error_handler) |
| 1480 | (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"), |
| 1481 | bfd_get_filename (ibfd), (long)new_flags, (long)old_flags); |
| 1482 | } |
| 1483 | |
| 1484 | if (error) |
| 1485 | { |
| 1486 | bfd_set_error (bfd_error_bad_value); |
| 1487 | return false; |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | return true; |
| 1492 | } |
| 1493 | |
| 1494 | \f |
| 1495 | /* Handle a PowerPC specific section when reading an object file. This |
| 1496 | is called when elfcode.h finds a section with an unknown type. */ |
| 1497 | |
| 1498 | static boolean |
| 1499 | ppc_elf_section_from_shdr (abfd, hdr, name) |
| 1500 | bfd *abfd; |
| 1501 | Elf32_Internal_Shdr *hdr; |
| 1502 | char *name; |
| 1503 | { |
| 1504 | asection *newsect; |
| 1505 | flagword flags; |
| 1506 | |
| 1507 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) |
| 1508 | return false; |
| 1509 | |
| 1510 | newsect = hdr->bfd_section; |
| 1511 | flags = bfd_get_section_flags (abfd, newsect); |
| 1512 | if (hdr->sh_flags & SHF_EXCLUDE) |
| 1513 | flags |= SEC_EXCLUDE; |
| 1514 | |
| 1515 | if (hdr->sh_type == SHT_ORDERED) |
| 1516 | flags |= SEC_SORT_ENTRIES; |
| 1517 | |
| 1518 | bfd_set_section_flags (abfd, newsect, flags); |
| 1519 | return true; |
| 1520 | } |
| 1521 | |
| 1522 | \f |
| 1523 | /* Set up any other section flags and such that may be necessary. */ |
| 1524 | |
| 1525 | static boolean |
| 1526 | ppc_elf_fake_sections (abfd, shdr, asect) |
| 1527 | bfd *abfd ATTRIBUTE_UNUSED; |
| 1528 | Elf32_Internal_Shdr *shdr; |
| 1529 | asection *asect; |
| 1530 | { |
| 1531 | if ((asect->flags & SEC_EXCLUDE) != 0) |
| 1532 | shdr->sh_flags |= SHF_EXCLUDE; |
| 1533 | |
| 1534 | if ((asect->flags & SEC_SORT_ENTRIES) != 0) |
| 1535 | shdr->sh_type = SHT_ORDERED; |
| 1536 | |
| 1537 | return true; |
| 1538 | } |
| 1539 | |
| 1540 | \f |
| 1541 | /* Create a special linker section */ |
| 1542 | static elf_linker_section_t * |
| 1543 | ppc_elf_create_linker_section (abfd, info, which) |
| 1544 | bfd *abfd; |
| 1545 | struct bfd_link_info *info; |
| 1546 | enum elf_linker_section_enum which; |
| 1547 | { |
| 1548 | bfd *dynobj = elf_hash_table (info)->dynobj; |
| 1549 | elf_linker_section_t *lsect; |
| 1550 | |
| 1551 | /* Record the first bfd section that needs the special section */ |
| 1552 | if (!dynobj) |
| 1553 | dynobj = elf_hash_table (info)->dynobj = abfd; |
| 1554 | |
| 1555 | /* If this is the first time, create the section */ |
| 1556 | lsect = elf_linker_section (dynobj, which); |
| 1557 | if (!lsect) |
| 1558 | { |
| 1559 | elf_linker_section_t defaults; |
| 1560 | static elf_linker_section_t zero_section; |
| 1561 | |
| 1562 | defaults = zero_section; |
| 1563 | defaults.which = which; |
| 1564 | defaults.hole_written_p = false; |
| 1565 | defaults.alignment = 2; |
| 1566 | |
| 1567 | /* Both of these sections are (technically) created by the user |
| 1568 | putting data in them, so they shouldn't be marked |
| 1569 | SEC_LINKER_CREATED. |
| 1570 | |
| 1571 | The linker creates them so it has somewhere to attach their |
| 1572 | respective symbols. In fact, if they were empty it would |
| 1573 | be OK to leave the symbol set to 0 (or any random number), because |
| 1574 | the appropriate register should never be used. */ |
| 1575 | defaults.flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS |
| 1576 | | SEC_IN_MEMORY); |
| 1577 | |
| 1578 | switch (which) |
| 1579 | { |
| 1580 | default: |
| 1581 | (*_bfd_error_handler) (_("%s: Unknown special linker type %d"), |
| 1582 | bfd_get_filename (abfd), |
| 1583 | (int)which); |
| 1584 | |
| 1585 | bfd_set_error (bfd_error_bad_value); |
| 1586 | return (elf_linker_section_t *)0; |
| 1587 | |
| 1588 | case LINKER_SECTION_SDATA: /* .sdata/.sbss section */ |
| 1589 | defaults.name = ".sdata"; |
| 1590 | defaults.rel_name = ".rela.sdata"; |
| 1591 | defaults.bss_name = ".sbss"; |
| 1592 | defaults.sym_name = "_SDA_BASE_"; |
| 1593 | defaults.sym_offset = 32768; |
| 1594 | break; |
| 1595 | |
| 1596 | case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */ |
| 1597 | defaults.name = ".sdata2"; |
| 1598 | defaults.rel_name = ".rela.sdata2"; |
| 1599 | defaults.bss_name = ".sbss2"; |
| 1600 | defaults.sym_name = "_SDA2_BASE_"; |
| 1601 | defaults.sym_offset = 32768; |
| 1602 | defaults.flags |= SEC_READONLY; |
| 1603 | break; |
| 1604 | } |
| 1605 | |
| 1606 | lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults); |
| 1607 | } |
| 1608 | |
| 1609 | return lsect; |
| 1610 | } |
| 1611 | |
| 1612 | \f |
| 1613 | /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we need to bump up |
| 1614 | the number of section headers. */ |
| 1615 | |
| 1616 | static int |
| 1617 | ppc_elf_additional_program_headers (abfd) |
| 1618 | bfd *abfd; |
| 1619 | { |
| 1620 | asection *s; |
| 1621 | int ret; |
| 1622 | |
| 1623 | ret = 0; |
| 1624 | |
| 1625 | s = bfd_get_section_by_name (abfd, ".interp"); |
| 1626 | if (s != NULL) |
| 1627 | ++ret; |
| 1628 | |
| 1629 | s = bfd_get_section_by_name (abfd, ".sbss2"); |
| 1630 | if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0) |
| 1631 | ++ret; |
| 1632 | |
| 1633 | s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0"); |
| 1634 | if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0) |
| 1635 | ++ret; |
| 1636 | |
| 1637 | return ret; |
| 1638 | } |
| 1639 | |
| 1640 | /* Modify the segment map if needed */ |
| 1641 | |
| 1642 | static boolean |
| 1643 | ppc_elf_modify_segment_map (abfd) |
| 1644 | bfd *abfd ATTRIBUTE_UNUSED; |
| 1645 | { |
| 1646 | return true; |
| 1647 | } |
| 1648 | \f |
| 1649 | /* We have to create .dynsbss and .rela.sbss here so that they get mapped |
| 1650 | to output sections (just like _bfd_elf_create_dynamic_sections has |
| 1651 | to create .dynbss and .rela.bss). */ |
| 1652 | |
| 1653 | static boolean |
| 1654 | ppc_elf_create_dynamic_sections (abfd, info) |
| 1655 | bfd *abfd; |
| 1656 | struct bfd_link_info *info; |
| 1657 | { |
| 1658 | register asection *s; |
| 1659 | flagword flags; |
| 1660 | |
| 1661 | if (!_bfd_elf_create_dynamic_sections(abfd, info)) |
| 1662 | return false; |
| 1663 | |
| 1664 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
| 1665 | | SEC_LINKER_CREATED); |
| 1666 | |
| 1667 | s = bfd_make_section (abfd, ".dynsbss"); |
| 1668 | if (s == NULL |
| 1669 | || ! bfd_set_section_flags (abfd, s, SEC_ALLOC)) |
| 1670 | return false; |
| 1671 | |
| 1672 | if (! info->shared) |
| 1673 | { |
| 1674 | s = bfd_make_section (abfd, ".rela.sbss"); |
| 1675 | if (s == NULL |
| 1676 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) |
| 1677 | || ! bfd_set_section_alignment (abfd, s, 2)) |
| 1678 | return false; |
| 1679 | } |
| 1680 | return true; |
| 1681 | } |
| 1682 | |
| 1683 | /* Adjust a symbol defined by a dynamic object and referenced by a |
| 1684 | regular object. The current definition is in some section of the |
| 1685 | dynamic object, but we're not including those sections. We have to |
| 1686 | change the definition to something the rest of the link can |
| 1687 | understand. */ |
| 1688 | |
| 1689 | static boolean |
| 1690 | ppc_elf_adjust_dynamic_symbol (info, h) |
| 1691 | struct bfd_link_info *info; |
| 1692 | struct elf_link_hash_entry *h; |
| 1693 | { |
| 1694 | bfd *dynobj = elf_hash_table (info)->dynobj; |
| 1695 | asection *s; |
| 1696 | unsigned int power_of_two; |
| 1697 | bfd_vma plt_offset; |
| 1698 | |
| 1699 | #ifdef DEBUG |
| 1700 | fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", h->root.root.string); |
| 1701 | #endif |
| 1702 | |
| 1703 | /* Make sure we know what is going on here. */ |
| 1704 | BFD_ASSERT (dynobj != NULL |
| 1705 | && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) |
| 1706 | || h->weakdef != NULL |
| 1707 | || ((h->elf_link_hash_flags |
| 1708 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
| 1709 | && (h->elf_link_hash_flags |
| 1710 | & ELF_LINK_HASH_REF_REGULAR) != 0 |
| 1711 | && (h->elf_link_hash_flags |
| 1712 | & ELF_LINK_HASH_DEF_REGULAR) == 0))); |
| 1713 | |
| 1714 | /* If this is a function, put it in the procedure linkage table. We |
| 1715 | will fill in the contents of the procedure linkage table later, |
| 1716 | when we know the address of the .got section. */ |
| 1717 | if (h->type == STT_FUNC |
| 1718 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) |
| 1719 | { |
| 1720 | if (! elf_hash_table (info)->dynamic_sections_created |
| 1721 | || SYMBOL_CALLS_LOCAL (info, h) |
| 1722 | || (info->shared && h->plt.refcount <= 0)) |
| 1723 | { |
| 1724 | /* A PLT entry is not required/allowed when: |
| 1725 | |
| 1726 | 1. We are not using ld.so; because then the PLT entry |
| 1727 | can't be set up, so we can't use one. |
| 1728 | |
| 1729 | 2. We know for certain that a call to this symbol |
| 1730 | will go to this object. |
| 1731 | |
| 1732 | 3. GC has rendered the entry unused. |
| 1733 | Note, however, that in an executable all references to the |
| 1734 | symbol go to the PLT, so we can't turn it off in that case. |
| 1735 | ??? The correct thing to do here is to reference count |
| 1736 | all uses of the symbol, not just those to the GOT or PLT. */ |
| 1737 | h->plt.offset = (bfd_vma) -1; |
| 1738 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
| 1739 | return true; |
| 1740 | } |
| 1741 | |
| 1742 | /* Make sure this symbol is output as a dynamic symbol. */ |
| 1743 | if (h->dynindx == -1) |
| 1744 | { |
| 1745 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) |
| 1746 | return false; |
| 1747 | } |
| 1748 | BFD_ASSERT (h->dynindx != -1); |
| 1749 | |
| 1750 | s = bfd_get_section_by_name (dynobj, ".plt"); |
| 1751 | BFD_ASSERT (s != NULL); |
| 1752 | |
| 1753 | /* If this is the first .plt entry, make room for the special |
| 1754 | first entry. */ |
| 1755 | if (s->_raw_size == 0) |
| 1756 | s->_raw_size += PLT_INITIAL_ENTRY_SIZE; |
| 1757 | |
| 1758 | /* The PowerPC PLT is actually composed of two parts, the first part |
| 1759 | is 2 words (for a load and a jump), and then there is a remaining |
| 1760 | word available at the end. */ |
| 1761 | plt_offset = (PLT_INITIAL_ENTRY_SIZE |
| 1762 | + (PLT_SLOT_SIZE |
| 1763 | * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) |
| 1764 | / PLT_ENTRY_SIZE))); |
| 1765 | |
| 1766 | /* If this symbol is not defined in a regular file, and we are |
| 1767 | not generating a shared library, then set the symbol to this |
| 1768 | location in the .plt. This is required to make function |
| 1769 | pointers compare as equal between the normal executable and |
| 1770 | the shared library. */ |
| 1771 | if (! info->shared |
| 1772 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
| 1773 | { |
| 1774 | h->root.u.def.section = s; |
| 1775 | h->root.u.def.value = plt_offset; |
| 1776 | } |
| 1777 | |
| 1778 | h->plt.offset = plt_offset; |
| 1779 | |
| 1780 | /* Make room for this entry. After the 8192nd entry, room |
| 1781 | for two entries is allocated. */ |
| 1782 | if ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE |
| 1783 | >= PLT_NUM_SINGLE_ENTRIES) |
| 1784 | s->_raw_size += 2 * PLT_ENTRY_SIZE; |
| 1785 | else |
| 1786 | s->_raw_size += PLT_ENTRY_SIZE; |
| 1787 | |
| 1788 | /* We also need to make an entry in the .rela.plt section. */ |
| 1789 | s = bfd_get_section_by_name (dynobj, ".rela.plt"); |
| 1790 | BFD_ASSERT (s != NULL); |
| 1791 | s->_raw_size += sizeof (Elf32_External_Rela); |
| 1792 | |
| 1793 | return true; |
| 1794 | } |
| 1795 | |
| 1796 | /* If this is a weak symbol, and there is a real definition, the |
| 1797 | processor independent code will have arranged for us to see the |
| 1798 | real definition first, and we can just use the same value. */ |
| 1799 | if (h->weakdef != NULL) |
| 1800 | { |
| 1801 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined |
| 1802 | || h->weakdef->root.type == bfd_link_hash_defweak); |
| 1803 | h->root.u.def.section = h->weakdef->root.u.def.section; |
| 1804 | h->root.u.def.value = h->weakdef->root.u.def.value; |
| 1805 | return true; |
| 1806 | } |
| 1807 | |
| 1808 | /* This is a reference to a symbol defined by a dynamic object which |
| 1809 | is not a function. */ |
| 1810 | |
| 1811 | /* If we are creating a shared library, we must presume that the |
| 1812 | only references to the symbol are via the global offset table. |
| 1813 | For such cases we need not do anything here; the relocations will |
| 1814 | be handled correctly by relocate_section. */ |
| 1815 | if (info->shared) |
| 1816 | return true; |
| 1817 | |
| 1818 | /* We must allocate the symbol in our .dynbss section, which will |
| 1819 | become part of the .bss section of the executable. There will be |
| 1820 | an entry for this symbol in the .dynsym section. The dynamic |
| 1821 | object will contain position independent code, so all references |
| 1822 | from the dynamic object to this symbol will go through the global |
| 1823 | offset table. The dynamic linker will use the .dynsym entry to |
| 1824 | determine the address it must put in the global offset table, so |
| 1825 | both the dynamic object and the regular object will refer to the |
| 1826 | same memory location for the variable. |
| 1827 | |
| 1828 | Of course, if the symbol is sufficiently small, we must instead |
| 1829 | allocate it in .sbss. FIXME: It would be better to do this if and |
| 1830 | only if there were actually SDAREL relocs for that symbol. */ |
| 1831 | |
| 1832 | if (h->size <= elf_gp_size (dynobj)) |
| 1833 | s = bfd_get_section_by_name (dynobj, ".dynsbss"); |
| 1834 | else |
| 1835 | s = bfd_get_section_by_name (dynobj, ".dynbss"); |
| 1836 | BFD_ASSERT (s != NULL); |
| 1837 | |
| 1838 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to |
| 1839 | copy the initial value out of the dynamic object and into the |
| 1840 | runtime process image. We need to remember the offset into the |
| 1841 | .rela.bss section we are going to use. */ |
| 1842 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
| 1843 | { |
| 1844 | asection *srel; |
| 1845 | |
| 1846 | if (h->size <= elf_gp_size (dynobj)) |
| 1847 | srel = bfd_get_section_by_name (dynobj, ".rela.sbss"); |
| 1848 | else |
| 1849 | srel = bfd_get_section_by_name (dynobj, ".rela.bss"); |
| 1850 | BFD_ASSERT (srel != NULL); |
| 1851 | srel->_raw_size += sizeof (Elf32_External_Rela); |
| 1852 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
| 1853 | } |
| 1854 | |
| 1855 | /* We need to figure out the alignment required for this symbol. I |
| 1856 | have no idea how ELF linkers handle this. */ |
| 1857 | power_of_two = bfd_log2 (h->size); |
| 1858 | if (power_of_two > 4) |
| 1859 | power_of_two = 4; |
| 1860 | |
| 1861 | /* Apply the required alignment. */ |
| 1862 | s->_raw_size = BFD_ALIGN (s->_raw_size, |
| 1863 | (bfd_size_type) (1 << power_of_two)); |
| 1864 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) |
| 1865 | { |
| 1866 | if (! bfd_set_section_alignment (dynobj, s, power_of_two)) |
| 1867 | return false; |
| 1868 | } |
| 1869 | |
| 1870 | /* Define the symbol as being at this point in the section. */ |
| 1871 | h->root.u.def.section = s; |
| 1872 | h->root.u.def.value = s->_raw_size; |
| 1873 | |
| 1874 | /* Increment the section size to make room for the symbol. */ |
| 1875 | s->_raw_size += h->size; |
| 1876 | |
| 1877 | return true; |
| 1878 | } |
| 1879 | |
| 1880 | \f |
| 1881 | /* Set the sizes of the dynamic sections. */ |
| 1882 | |
| 1883 | static boolean |
| 1884 | ppc_elf_size_dynamic_sections (output_bfd, info) |
| 1885 | bfd *output_bfd; |
| 1886 | struct bfd_link_info *info; |
| 1887 | { |
| 1888 | bfd *dynobj; |
| 1889 | asection *s; |
| 1890 | boolean plt; |
| 1891 | boolean relocs; |
| 1892 | boolean reltext; |
| 1893 | |
| 1894 | #ifdef DEBUG |
| 1895 | fprintf (stderr, "ppc_elf_size_dynamic_sections called\n"); |
| 1896 | #endif |
| 1897 | |
| 1898 | dynobj = elf_hash_table (info)->dynobj; |
| 1899 | BFD_ASSERT (dynobj != NULL); |
| 1900 | |
| 1901 | if (elf_hash_table (info)->dynamic_sections_created) |
| 1902 | { |
| 1903 | /* Set the contents of the .interp section to the interpreter. */ |
| 1904 | if (! info->shared) |
| 1905 | { |
| 1906 | s = bfd_get_section_by_name (dynobj, ".interp"); |
| 1907 | BFD_ASSERT (s != NULL); |
| 1908 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; |
| 1909 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
| 1910 | } |
| 1911 | } |
| 1912 | else |
| 1913 | { |
| 1914 | /* We may have created entries in the .rela.got, .rela.sdata, and |
| 1915 | .rela.sdata2 sections. However, if we are not creating the |
| 1916 | dynamic sections, we will not actually use these entries. Reset |
| 1917 | the size of .rela.got, et al, which will cause it to get |
| 1918 | stripped from the output file below. */ |
| 1919 | static char *rela_sections[] = { ".rela.got", ".rela.sdata", |
| 1920 | ".rela.sdata2", ".rela.sbss", |
| 1921 | (char *)0 }; |
| 1922 | char **p; |
| 1923 | |
| 1924 | for (p = rela_sections; *p != (char *)0; p++) |
| 1925 | { |
| 1926 | s = bfd_get_section_by_name (dynobj, *p); |
| 1927 | if (s != NULL) |
| 1928 | s->_raw_size = 0; |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | /* The check_relocs and adjust_dynamic_symbol entry points have |
| 1933 | determined the sizes of the various dynamic sections. Allocate |
| 1934 | memory for them. */ |
| 1935 | plt = false; |
| 1936 | relocs = false; |
| 1937 | reltext = false; |
| 1938 | for (s = dynobj->sections; s != NULL; s = s->next) |
| 1939 | { |
| 1940 | const char *name; |
| 1941 | boolean strip; |
| 1942 | |
| 1943 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
| 1944 | continue; |
| 1945 | |
| 1946 | /* It's OK to base decisions on the section name, because none |
| 1947 | of the dynobj section names depend upon the input files. */ |
| 1948 | name = bfd_get_section_name (dynobj, s); |
| 1949 | |
| 1950 | strip = false; |
| 1951 | |
| 1952 | if (strcmp (name, ".plt") == 0) |
| 1953 | { |
| 1954 | if (s->_raw_size == 0) |
| 1955 | { |
| 1956 | /* Strip this section if we don't need it; see the |
| 1957 | comment below. */ |
| 1958 | strip = true; |
| 1959 | } |
| 1960 | else |
| 1961 | { |
| 1962 | /* Remember whether there is a PLT. */ |
| 1963 | plt = true; |
| 1964 | } |
| 1965 | } |
| 1966 | else if (strncmp (name, ".rela", 5) == 0) |
| 1967 | { |
| 1968 | if (s->_raw_size == 0) |
| 1969 | { |
| 1970 | /* If we don't need this section, strip it from the |
| 1971 | output file. This is mostly to handle .rela.bss and |
| 1972 | .rela.plt. We must create both sections in |
| 1973 | create_dynamic_sections, because they must be created |
| 1974 | before the linker maps input sections to output |
| 1975 | sections. The linker does that before |
| 1976 | adjust_dynamic_symbol is called, and it is that |
| 1977 | function which decides whether anything needs to go |
| 1978 | into these sections. */ |
| 1979 | strip = true; |
| 1980 | } |
| 1981 | else |
| 1982 | { |
| 1983 | asection *target; |
| 1984 | const char *outname; |
| 1985 | |
| 1986 | /* Remember whether there are any relocation sections. */ |
| 1987 | relocs = true; |
| 1988 | |
| 1989 | /* If this relocation section applies to a read only |
| 1990 | section, then we probably need a DT_TEXTREL entry. */ |
| 1991 | outname = bfd_get_section_name (output_bfd, |
| 1992 | s->output_section); |
| 1993 | target = bfd_get_section_by_name (output_bfd, outname + 5); |
| 1994 | if (target != NULL |
| 1995 | && (target->flags & SEC_READONLY) != 0 |
| 1996 | && (target->flags & SEC_ALLOC) != 0) |
| 1997 | reltext = true; |
| 1998 | |
| 1999 | /* We use the reloc_count field as a counter if we need |
| 2000 | to copy relocs into the output file. */ |
| 2001 | s->reloc_count = 0; |
| 2002 | } |
| 2003 | } |
| 2004 | else if (strcmp (name, ".got") != 0 |
| 2005 | && strcmp (name, ".sdata") != 0 |
| 2006 | && strcmp (name, ".sdata2") != 0) |
| 2007 | { |
| 2008 | /* It's not one of our sections, so don't allocate space. */ |
| 2009 | continue; |
| 2010 | } |
| 2011 | |
| 2012 | if (strip) |
| 2013 | { |
| 2014 | _bfd_strip_section_from_output (info, s); |
| 2015 | continue; |
| 2016 | } |
| 2017 | |
| 2018 | /* Allocate memory for the section contents. */ |
| 2019 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); |
| 2020 | if (s->contents == NULL && s->_raw_size != 0) |
| 2021 | return false; |
| 2022 | } |
| 2023 | |
| 2024 | if (elf_hash_table (info)->dynamic_sections_created) |
| 2025 | { |
| 2026 | /* Add some entries to the .dynamic section. We fill in the |
| 2027 | values later, in ppc_elf_finish_dynamic_sections, but we |
| 2028 | must add the entries now so that we get the correct size for |
| 2029 | the .dynamic section. The DT_DEBUG entry is filled in by the |
| 2030 | dynamic linker and used by the debugger. */ |
| 2031 | if (! info->shared) |
| 2032 | { |
| 2033 | if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0)) |
| 2034 | return false; |
| 2035 | } |
| 2036 | |
| 2037 | if (plt) |
| 2038 | { |
| 2039 | if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0) |
| 2040 | || ! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0) |
| 2041 | || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA) |
| 2042 | || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0)) |
| 2043 | return false; |
| 2044 | } |
| 2045 | |
| 2046 | if (relocs) |
| 2047 | { |
| 2048 | if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0) |
| 2049 | || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0) |
| 2050 | || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT, |
| 2051 | sizeof (Elf32_External_Rela))) |
| 2052 | return false; |
| 2053 | } |
| 2054 | |
| 2055 | if (reltext) |
| 2056 | { |
| 2057 | if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0)) |
| 2058 | return false; |
| 2059 | info->flags |= DF_TEXTREL; |
| 2060 | } |
| 2061 | } |
| 2062 | |
| 2063 | return true; |
| 2064 | } |
| 2065 | |
| 2066 | \f |
| 2067 | /* Look through the relocs for a section during the first phase, and |
| 2068 | allocate space in the global offset table or procedure linkage |
| 2069 | table. */ |
| 2070 | |
| 2071 | static boolean |
| 2072 | ppc_elf_check_relocs (abfd, info, sec, relocs) |
| 2073 | bfd *abfd; |
| 2074 | struct bfd_link_info *info; |
| 2075 | asection *sec; |
| 2076 | const Elf_Internal_Rela *relocs; |
| 2077 | { |
| 2078 | bfd *dynobj; |
| 2079 | Elf_Internal_Shdr *symtab_hdr; |
| 2080 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; |
| 2081 | const Elf_Internal_Rela *rel; |
| 2082 | const Elf_Internal_Rela *rel_end; |
| 2083 | bfd_signed_vma *local_got_refcounts; |
| 2084 | elf_linker_section_t *sdata; |
| 2085 | elf_linker_section_t *sdata2; |
| 2086 | asection *sreloc; |
| 2087 | asection *sgot = NULL; |
| 2088 | asection *srelgot = NULL; |
| 2089 | |
| 2090 | if (info->relocateable) |
| 2091 | return true; |
| 2092 | |
| 2093 | #ifdef DEBUG |
| 2094 | fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n", |
| 2095 | bfd_get_section_name (abfd, sec), |
| 2096 | bfd_get_filename (abfd)); |
| 2097 | #endif |
| 2098 | |
| 2099 | /* Create the linker generated sections all the time so that the |
| 2100 | special symbols are created. */ |
| 2101 | |
| 2102 | if ((sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA)) == NULL) |
| 2103 | { |
| 2104 | sdata = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA); |
| 2105 | if (!sdata) |
| 2106 | return false; |
| 2107 | } |
| 2108 | |
| 2109 | if ((sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2)) == NULL) |
| 2110 | { |
| 2111 | sdata2 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA2); |
| 2112 | if (!sdata2) |
| 2113 | return false; |
| 2114 | } |
| 2115 | |
| 2116 | dynobj = elf_hash_table (info)->dynobj; |
| 2117 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 2118 | local_got_refcounts = elf_local_got_refcounts (abfd); |
| 2119 | |
| 2120 | sym_hashes = elf_sym_hashes (abfd); |
| 2121 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym); |
| 2122 | if (!elf_bad_symtab (abfd)) |
| 2123 | sym_hashes_end -= symtab_hdr->sh_info; |
| 2124 | |
| 2125 | sreloc = NULL; |
| 2126 | |
| 2127 | rel_end = relocs + sec->reloc_count; |
| 2128 | for (rel = relocs; rel < rel_end; rel++) |
| 2129 | { |
| 2130 | unsigned long r_symndx; |
| 2131 | struct elf_link_hash_entry *h; |
| 2132 | |
| 2133 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 2134 | if (r_symndx < symtab_hdr->sh_info) |
| 2135 | h = NULL; |
| 2136 | else |
| 2137 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 2138 | |
| 2139 | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. |
| 2140 | This shows up in particular in an R_PPC_ADDR32 in the eabi |
| 2141 | startup code. */ |
| 2142 | if (h && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
| 2143 | { |
| 2144 | if (sgot == NULL) |
| 2145 | { |
| 2146 | if (dynobj == NULL) |
| 2147 | elf_hash_table (info)->dynobj = dynobj = abfd; |
| 2148 | if (! _bfd_elf_create_got_section (dynobj, info)) |
| 2149 | return false; |
| 2150 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 2151 | BFD_ASSERT (sgot != NULL); |
| 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | switch (ELF32_R_TYPE (rel->r_info)) |
| 2156 | { |
| 2157 | /* GOT16 relocations */ |
| 2158 | case R_PPC_GOT16: |
| 2159 | case R_PPC_GOT16_LO: |
| 2160 | case R_PPC_GOT16_HI: |
| 2161 | case R_PPC_GOT16_HA: |
| 2162 | /* This symbol requires a global offset table entry. */ |
| 2163 | |
| 2164 | if (sgot == NULL) |
| 2165 | { |
| 2166 | if (dynobj == NULL) |
| 2167 | elf_hash_table (info)->dynobj = dynobj = abfd; |
| 2168 | if (! _bfd_elf_create_got_section (dynobj, info)) |
| 2169 | return false; |
| 2170 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 2171 | BFD_ASSERT (sgot != NULL); |
| 2172 | } |
| 2173 | |
| 2174 | if (srelgot == NULL |
| 2175 | && (h != NULL || info->shared)) |
| 2176 | { |
| 2177 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 2178 | if (srelgot == NULL) |
| 2179 | { |
| 2180 | srelgot = bfd_make_section (dynobj, ".rela.got"); |
| 2181 | if (srelgot == NULL |
| 2182 | || ! bfd_set_section_flags (dynobj, srelgot, |
| 2183 | (SEC_ALLOC |
| 2184 | | SEC_LOAD |
| 2185 | | SEC_HAS_CONTENTS |
| 2186 | | SEC_IN_MEMORY |
| 2187 | | SEC_LINKER_CREATED |
| 2188 | | SEC_READONLY)) |
| 2189 | || ! bfd_set_section_alignment (dynobj, srelgot, 2)) |
| 2190 | return false; |
| 2191 | } |
| 2192 | } |
| 2193 | |
| 2194 | if (h != NULL) |
| 2195 | { |
| 2196 | if (h->got.refcount == -1) |
| 2197 | { |
| 2198 | /* Make sure this symbol is output as a dynamic symbol. */ |
| 2199 | if (h->dynindx == -1) |
| 2200 | if (!bfd_elf32_link_record_dynamic_symbol (info, h)) |
| 2201 | return false; |
| 2202 | |
| 2203 | /* Allocate space in the .got. */ |
| 2204 | sgot->_raw_size += 4; |
| 2205 | /* Allocate relocation space. */ |
| 2206 | srelgot->_raw_size += sizeof (Elf32_External_Rela); |
| 2207 | |
| 2208 | h->got.refcount = 1; |
| 2209 | } |
| 2210 | else |
| 2211 | h->got.refcount++; |
| 2212 | } |
| 2213 | else |
| 2214 | { |
| 2215 | /* This is a global offset table entry for a local symbol. */ |
| 2216 | if (local_got_refcounts == NULL) |
| 2217 | { |
| 2218 | size_t size; |
| 2219 | |
| 2220 | size = symtab_hdr->sh_info * sizeof (bfd_signed_vma); |
| 2221 | local_got_refcounts = (bfd_signed_vma *) |
| 2222 | bfd_alloc (abfd, size); |
| 2223 | if (local_got_refcounts == NULL) |
| 2224 | return false; |
| 2225 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
| 2226 | memset (local_got_refcounts, -1, size); |
| 2227 | } |
| 2228 | if (local_got_refcounts[r_symndx] == -1) |
| 2229 | { |
| 2230 | sgot->_raw_size += 4; |
| 2231 | |
| 2232 | /* If we are generating a shared object, we need to |
| 2233 | output a R_PPC_RELATIVE reloc so that the |
| 2234 | dynamic linker can adjust this GOT entry. */ |
| 2235 | if (info->shared) |
| 2236 | srelgot->_raw_size += sizeof (Elf32_External_Rela); |
| 2237 | |
| 2238 | local_got_refcounts[r_symndx] = 1; |
| 2239 | } |
| 2240 | else |
| 2241 | local_got_refcounts[r_symndx]++; |
| 2242 | } |
| 2243 | break; |
| 2244 | |
| 2245 | /* Indirect .sdata relocation */ |
| 2246 | case R_PPC_EMB_SDAI16: |
| 2247 | if (info->shared) |
| 2248 | { |
| 2249 | ((*_bfd_error_handler) |
| 2250 | (_("%s: relocation %s cannot be used when making a shared object"), |
| 2251 | bfd_get_filename (abfd), "R_PPC_EMB_SDAI16")); |
| 2252 | return false; |
| 2253 | } |
| 2254 | |
| 2255 | if (srelgot == NULL && (h != NULL || info->shared)) |
| 2256 | { |
| 2257 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 2258 | if (srelgot == NULL) |
| 2259 | { |
| 2260 | srelgot = bfd_make_section (dynobj, ".rela.got"); |
| 2261 | if (srelgot == NULL |
| 2262 | || ! bfd_set_section_flags (dynobj, srelgot, |
| 2263 | (SEC_ALLOC |
| 2264 | | SEC_LOAD |
| 2265 | | SEC_HAS_CONTENTS |
| 2266 | | SEC_IN_MEMORY |
| 2267 | | SEC_LINKER_CREATED |
| 2268 | | SEC_READONLY)) |
| 2269 | || ! bfd_set_section_alignment (dynobj, srelgot, 2)) |
| 2270 | return false; |
| 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata, h, rel)) |
| 2275 | return false; |
| 2276 | |
| 2277 | break; |
| 2278 | |
| 2279 | /* Indirect .sdata2 relocation */ |
| 2280 | case R_PPC_EMB_SDA2I16: |
| 2281 | if (info->shared) |
| 2282 | { |
| 2283 | ((*_bfd_error_handler) |
| 2284 | (_("%s: relocation %s cannot be used when making a shared object"), |
| 2285 | bfd_get_filename (abfd), "R_PPC_EMB_SDA2I16")); |
| 2286 | return false; |
| 2287 | } |
| 2288 | |
| 2289 | if (srelgot == NULL && (h != NULL || info->shared)) |
| 2290 | { |
| 2291 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 2292 | if (srelgot == NULL) |
| 2293 | { |
| 2294 | srelgot = bfd_make_section (dynobj, ".rela.got"); |
| 2295 | if (srelgot == NULL |
| 2296 | || ! bfd_set_section_flags (dynobj, srelgot, |
| 2297 | (SEC_ALLOC |
| 2298 | | SEC_LOAD |
| 2299 | | SEC_HAS_CONTENTS |
| 2300 | | SEC_IN_MEMORY |
| 2301 | | SEC_LINKER_CREATED |
| 2302 | | SEC_READONLY)) |
| 2303 | || ! bfd_set_section_alignment (dynobj, srelgot, 2)) |
| 2304 | return false; |
| 2305 | } |
| 2306 | } |
| 2307 | |
| 2308 | if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata2, h, rel)) |
| 2309 | return false; |
| 2310 | |
| 2311 | break; |
| 2312 | |
| 2313 | case R_PPC_SDAREL16: |
| 2314 | case R_PPC_EMB_SDA2REL: |
| 2315 | case R_PPC_EMB_SDA21: |
| 2316 | if (info->shared) |
| 2317 | { |
| 2318 | ((*_bfd_error_handler) |
| 2319 | (_("%s: relocation %s cannot be used when making a shared object"), |
| 2320 | bfd_get_filename (abfd), |
| 2321 | ppc_elf_howto_table[(int)ELF32_R_TYPE (rel->r_info)]->name)); |
| 2322 | return false; |
| 2323 | } |
| 2324 | break; |
| 2325 | |
| 2326 | case R_PPC_PLT32: |
| 2327 | case R_PPC_PLTREL24: |
| 2328 | case R_PPC_PLT16_LO: |
| 2329 | case R_PPC_PLT16_HI: |
| 2330 | case R_PPC_PLT16_HA: |
| 2331 | #ifdef DEBUG |
| 2332 | fprintf (stderr, "Reloc requires a PLT entry\n"); |
| 2333 | #endif |
| 2334 | /* This symbol requires a procedure linkage table entry. We |
| 2335 | actually build the entry in adjust_dynamic_symbol, |
| 2336 | because this might be a case of linking PIC code without |
| 2337 | linking in any dynamic objects, in which case we don't |
| 2338 | need to generate a procedure linkage table after all. */ |
| 2339 | |
| 2340 | if (h == NULL) |
| 2341 | { |
| 2342 | /* It does not make sense to have a procedure linkage |
| 2343 | table entry for a local symbol. */ |
| 2344 | bfd_set_error (bfd_error_bad_value); |
| 2345 | return false; |
| 2346 | } |
| 2347 | |
| 2348 | /* Make sure this symbol is output as a dynamic symbol. */ |
| 2349 | if (h->dynindx == -1) |
| 2350 | { |
| 2351 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) |
| 2352 | return false; |
| 2353 | } |
| 2354 | if (h->plt.refcount == -1) |
| 2355 | { |
| 2356 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
| 2357 | h->plt.refcount = 1; |
| 2358 | } |
| 2359 | else |
| 2360 | h->plt.refcount++; |
| 2361 | break; |
| 2362 | |
| 2363 | /* The following relocations don't need to propagate the |
| 2364 | relocation if linking a shared object since they are |
| 2365 | section relative. */ |
| 2366 | case R_PPC_SECTOFF: |
| 2367 | case R_PPC_SECTOFF_LO: |
| 2368 | case R_PPC_SECTOFF_HI: |
| 2369 | case R_PPC_SECTOFF_HA: |
| 2370 | break; |
| 2371 | |
| 2372 | /* This refers only to functions defined in the shared library */ |
| 2373 | case R_PPC_LOCAL24PC: |
| 2374 | break; |
| 2375 | |
| 2376 | /* This relocation describes the C++ object vtable hierarchy. |
| 2377 | Reconstruct it for later use during GC. */ |
| 2378 | case R_PPC_GNU_VTINHERIT: |
| 2379 | if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
| 2380 | return false; |
| 2381 | break; |
| 2382 | |
| 2383 | /* This relocation describes which C++ vtable entries are actually |
| 2384 | used. Record for later use during GC. */ |
| 2385 | case R_PPC_GNU_VTENTRY: |
| 2386 | if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
| 2387 | return false; |
| 2388 | break; |
| 2389 | |
| 2390 | /* When creating a shared object, we must copy these |
| 2391 | relocs into the output file. We create a reloc |
| 2392 | section in dynobj and make room for the reloc. */ |
| 2393 | case R_PPC_REL24: |
| 2394 | case R_PPC_REL14: |
| 2395 | case R_PPC_REL14_BRTAKEN: |
| 2396 | case R_PPC_REL14_BRNTAKEN: |
| 2397 | case R_PPC_REL32: |
| 2398 | if (h == NULL |
| 2399 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 |
| 2400 | || SYMBOL_REFERENCES_LOCAL (info, h)) |
| 2401 | break; |
| 2402 | /* fall through */ |
| 2403 | |
| 2404 | default: |
| 2405 | if (info->shared) |
| 2406 | { |
| 2407 | #ifdef DEBUG |
| 2408 | fprintf (stderr, "ppc_elf_check_relocs need to create relocation for %s\n", |
| 2409 | (h && h->root.root.string) ? h->root.root.string : "<unknown>"); |
| 2410 | #endif |
| 2411 | if (sreloc == NULL) |
| 2412 | { |
| 2413 | const char *name; |
| 2414 | |
| 2415 | name = (bfd_elf_string_from_elf_section |
| 2416 | (abfd, |
| 2417 | elf_elfheader (abfd)->e_shstrndx, |
| 2418 | elf_section_data (sec)->rel_hdr.sh_name)); |
| 2419 | if (name == NULL) |
| 2420 | return false; |
| 2421 | |
| 2422 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 |
| 2423 | && strcmp (bfd_get_section_name (abfd, sec), |
| 2424 | name + 5) == 0); |
| 2425 | |
| 2426 | sreloc = bfd_get_section_by_name (dynobj, name); |
| 2427 | if (sreloc == NULL) |
| 2428 | { |
| 2429 | flagword flags; |
| 2430 | |
| 2431 | sreloc = bfd_make_section (dynobj, name); |
| 2432 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
| 2433 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); |
| 2434 | if ((sec->flags & SEC_ALLOC) != 0) |
| 2435 | flags |= SEC_ALLOC | SEC_LOAD; |
| 2436 | if (sreloc == NULL |
| 2437 | || ! bfd_set_section_flags (dynobj, sreloc, flags) |
| 2438 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) |
| 2439 | return false; |
| 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | sreloc->_raw_size += sizeof (Elf32_External_Rela); |
| 2444 | |
| 2445 | /* FIXME: We should here do what the m68k and i386 |
| 2446 | backends do: if the reloc is pc-relative, record it |
| 2447 | in case it turns out that the reloc is unnecessary |
| 2448 | because the symbol is forced local by versioning or |
| 2449 | we are linking with -Bdynamic. Fortunately this |
| 2450 | case is not frequent. */ |
| 2451 | } |
| 2452 | |
| 2453 | break; |
| 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | return true; |
| 2458 | } |
| 2459 | |
| 2460 | /* Return the section that should be marked against GC for a given |
| 2461 | relocation. */ |
| 2462 | |
| 2463 | static asection * |
| 2464 | ppc_elf_gc_mark_hook (abfd, info, rel, h, sym) |
| 2465 | bfd *abfd; |
| 2466 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
| 2467 | Elf_Internal_Rela *rel; |
| 2468 | struct elf_link_hash_entry *h; |
| 2469 | Elf_Internal_Sym *sym; |
| 2470 | { |
| 2471 | if (h != NULL) |
| 2472 | { |
| 2473 | switch (ELF32_R_TYPE (rel->r_info)) |
| 2474 | { |
| 2475 | case R_PPC_GNU_VTINHERIT: |
| 2476 | case R_PPC_GNU_VTENTRY: |
| 2477 | break; |
| 2478 | |
| 2479 | default: |
| 2480 | switch (h->root.type) |
| 2481 | { |
| 2482 | case bfd_link_hash_defined: |
| 2483 | case bfd_link_hash_defweak: |
| 2484 | return h->root.u.def.section; |
| 2485 | |
| 2486 | case bfd_link_hash_common: |
| 2487 | return h->root.u.c.p->section; |
| 2488 | |
| 2489 | default: |
| 2490 | break; |
| 2491 | } |
| 2492 | } |
| 2493 | } |
| 2494 | else |
| 2495 | { |
| 2496 | if (!(elf_bad_symtab (abfd) |
| 2497 | && ELF_ST_BIND (sym->st_info) != STB_LOCAL) |
| 2498 | && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE) |
| 2499 | && sym->st_shndx != SHN_COMMON)) |
| 2500 | { |
| 2501 | return bfd_section_from_elf_index (abfd, sym->st_shndx); |
| 2502 | } |
| 2503 | } |
| 2504 | |
| 2505 | return NULL; |
| 2506 | } |
| 2507 | |
| 2508 | /* Update the got entry reference counts for the section being removed. */ |
| 2509 | |
| 2510 | static boolean |
| 2511 | ppc_elf_gc_sweep_hook (abfd, info, sec, relocs) |
| 2512 | bfd *abfd; |
| 2513 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
| 2514 | asection *sec; |
| 2515 | const Elf_Internal_Rela *relocs; |
| 2516 | { |
| 2517 | Elf_Internal_Shdr *symtab_hdr; |
| 2518 | struct elf_link_hash_entry **sym_hashes; |
| 2519 | bfd_signed_vma *local_got_refcounts; |
| 2520 | const Elf_Internal_Rela *rel, *relend; |
| 2521 | unsigned long r_symndx; |
| 2522 | struct elf_link_hash_entry *h; |
| 2523 | |
| 2524 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 2525 | sym_hashes = elf_sym_hashes (abfd); |
| 2526 | local_got_refcounts = elf_local_got_refcounts (abfd); |
| 2527 | |
| 2528 | relend = relocs + sec->reloc_count; |
| 2529 | for (rel = relocs; rel < relend; rel++) |
| 2530 | switch (ELF32_R_TYPE (rel->r_info)) |
| 2531 | { |
| 2532 | case R_PPC_GOT16: |
| 2533 | case R_PPC_GOT16_LO: |
| 2534 | case R_PPC_GOT16_HI: |
| 2535 | case R_PPC_GOT16_HA: |
| 2536 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 2537 | if (r_symndx >= symtab_hdr->sh_info) |
| 2538 | { |
| 2539 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 2540 | if (h->got.refcount > 0) |
| 2541 | h->got.refcount--; |
| 2542 | } |
| 2543 | else if (local_got_refcounts != NULL) |
| 2544 | { |
| 2545 | if (local_got_refcounts[r_symndx] > 0) |
| 2546 | local_got_refcounts[r_symndx]--; |
| 2547 | } |
| 2548 | break; |
| 2549 | |
| 2550 | case R_PPC_PLT32: |
| 2551 | case R_PPC_PLTREL24: |
| 2552 | case R_PPC_PLT16_LO: |
| 2553 | case R_PPC_PLT16_HI: |
| 2554 | case R_PPC_PLT16_HA: |
| 2555 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 2556 | if (r_symndx >= symtab_hdr->sh_info) |
| 2557 | { |
| 2558 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 2559 | if (h->plt.refcount > 0) |
| 2560 | h->plt.refcount--; |
| 2561 | } |
| 2562 | break; |
| 2563 | |
| 2564 | default: |
| 2565 | break; |
| 2566 | } |
| 2567 | |
| 2568 | return true; |
| 2569 | } |
| 2570 | \f |
| 2571 | /* Hook called by the linker routine which adds symbols from an object |
| 2572 | file. We use it to put .comm items in .sbss, and not .bss. */ |
| 2573 | |
| 2574 | /*ARGSUSED*/ |
| 2575 | static boolean |
| 2576 | ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) |
| 2577 | bfd *abfd; |
| 2578 | struct bfd_link_info *info; |
| 2579 | const Elf_Internal_Sym *sym; |
| 2580 | const char **namep ATTRIBUTE_UNUSED; |
| 2581 | flagword *flagsp ATTRIBUTE_UNUSED; |
| 2582 | asection **secp; |
| 2583 | bfd_vma *valp; |
| 2584 | { |
| 2585 | if (sym->st_shndx == SHN_COMMON |
| 2586 | && !info->relocateable |
| 2587 | && sym->st_size <= (bfd_vma) bfd_get_gp_size (abfd)) |
| 2588 | { |
| 2589 | /* Common symbols less than or equal to -G nn bytes are automatically |
| 2590 | put into .sdata. */ |
| 2591 | elf_linker_section_t *sdata |
| 2592 | = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA); |
| 2593 | |
| 2594 | if (!sdata->bss_section) |
| 2595 | { |
| 2596 | /* We don't go through bfd_make_section, because we don't |
| 2597 | want to attach this common section to DYNOBJ. The linker |
| 2598 | will move the symbols to the appropriate output section |
| 2599 | when it defines common symbols. */ |
| 2600 | sdata->bss_section = ((asection *) |
| 2601 | bfd_zalloc (abfd, sizeof (asection))); |
| 2602 | if (sdata->bss_section == NULL) |
| 2603 | return false; |
| 2604 | sdata->bss_section->name = sdata->bss_name; |
| 2605 | sdata->bss_section->flags = SEC_IS_COMMON; |
| 2606 | sdata->bss_section->output_section = sdata->bss_section; |
| 2607 | sdata->bss_section->symbol = |
| 2608 | (asymbol *) bfd_zalloc (abfd, sizeof (asymbol)); |
| 2609 | sdata->bss_section->symbol_ptr_ptr = |
| 2610 | (asymbol **) bfd_zalloc (abfd, sizeof (asymbol *)); |
| 2611 | if (sdata->bss_section->symbol == NULL |
| 2612 | || sdata->bss_section->symbol_ptr_ptr == NULL) |
| 2613 | return false; |
| 2614 | sdata->bss_section->symbol->name = sdata->bss_name; |
| 2615 | sdata->bss_section->symbol->flags = BSF_SECTION_SYM; |
| 2616 | sdata->bss_section->symbol->section = sdata->bss_section; |
| 2617 | *sdata->bss_section->symbol_ptr_ptr = sdata->bss_section->symbol; |
| 2618 | } |
| 2619 | |
| 2620 | *secp = sdata->bss_section; |
| 2621 | *valp = sym->st_size; |
| 2622 | } |
| 2623 | |
| 2624 | return true; |
| 2625 | } |
| 2626 | |
| 2627 | \f |
| 2628 | /* Finish up dynamic symbol handling. We set the contents of various |
| 2629 | dynamic sections here. */ |
| 2630 | |
| 2631 | static boolean |
| 2632 | ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym) |
| 2633 | bfd *output_bfd; |
| 2634 | struct bfd_link_info *info; |
| 2635 | struct elf_link_hash_entry *h; |
| 2636 | Elf_Internal_Sym *sym; |
| 2637 | { |
| 2638 | bfd *dynobj; |
| 2639 | |
| 2640 | #ifdef DEBUG |
| 2641 | fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s", |
| 2642 | h->root.root.string); |
| 2643 | #endif |
| 2644 | |
| 2645 | dynobj = elf_hash_table (info)->dynobj; |
| 2646 | BFD_ASSERT (dynobj != NULL); |
| 2647 | |
| 2648 | if (h->plt.offset != (bfd_vma) -1) |
| 2649 | { |
| 2650 | asection *splt; |
| 2651 | asection *srela; |
| 2652 | Elf_Internal_Rela rela; |
| 2653 | bfd_vma reloc_index; |
| 2654 | |
| 2655 | #ifdef DEBUG |
| 2656 | fprintf (stderr, ", plt_offset = %d", h->plt.offset); |
| 2657 | #endif |
| 2658 | |
| 2659 | /* This symbol has an entry in the procedure linkage table. Set |
| 2660 | it up. */ |
| 2661 | |
| 2662 | BFD_ASSERT (h->dynindx != -1); |
| 2663 | |
| 2664 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 2665 | srela = bfd_get_section_by_name (dynobj, ".rela.plt"); |
| 2666 | BFD_ASSERT (splt != NULL && srela != NULL); |
| 2667 | |
| 2668 | /* We don't need to fill in the .plt. The ppc dynamic linker |
| 2669 | will fill it in. */ |
| 2670 | |
| 2671 | /* Fill in the entry in the .rela.plt section. */ |
| 2672 | rela.r_offset = (splt->output_section->vma |
| 2673 | + splt->output_offset |
| 2674 | + h->plt.offset); |
| 2675 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT); |
| 2676 | rela.r_addend = 0; |
| 2677 | |
| 2678 | reloc_index = (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_SLOT_SIZE; |
| 2679 | if (reloc_index > PLT_NUM_SINGLE_ENTRIES) |
| 2680 | reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2; |
| 2681 | bfd_elf32_swap_reloca_out (output_bfd, &rela, |
| 2682 | ((Elf32_External_Rela *) srela->contents |
| 2683 | + reloc_index)); |
| 2684 | |
| 2685 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
| 2686 | { |
| 2687 | /* Mark the symbol as undefined, rather than as defined in |
| 2688 | the .plt section. Leave the value alone. */ |
| 2689 | sym->st_shndx = SHN_UNDEF; |
| 2690 | /* If the symbol is weak, we do need to clear the value. |
| 2691 | Otherwise, the PLT entry would provide a definition for |
| 2692 | the symbol even if the symbol wasn't defined anywhere, |
| 2693 | and so the symbol would never be NULL. */ |
| 2694 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK) |
| 2695 | == 0) |
| 2696 | sym->st_value = 0; |
| 2697 | } |
| 2698 | } |
| 2699 | |
| 2700 | if (h->got.offset != (bfd_vma) -1) |
| 2701 | { |
| 2702 | asection *sgot; |
| 2703 | asection *srela; |
| 2704 | Elf_Internal_Rela rela; |
| 2705 | |
| 2706 | /* This symbol has an entry in the global offset table. Set it |
| 2707 | up. */ |
| 2708 | |
| 2709 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 2710 | srela = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 2711 | BFD_ASSERT (sgot != NULL && srela != NULL); |
| 2712 | |
| 2713 | rela.r_offset = (sgot->output_section->vma |
| 2714 | + sgot->output_offset |
| 2715 | + (h->got.offset &~ 1)); |
| 2716 | |
| 2717 | /* If this is a -Bsymbolic link, and the symbol is defined |
| 2718 | locally, we just want to emit a RELATIVE reloc. The entry in |
| 2719 | the global offset table will already have been initialized in |
| 2720 | the relocate_section function. */ |
| 2721 | if (info->shared |
| 2722 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
| 2723 | { |
| 2724 | rela.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); |
| 2725 | rela.r_addend = (h->root.u.def.value |
| 2726 | + h->root.u.def.section->output_section->vma |
| 2727 | + h->root.u.def.section->output_offset); |
| 2728 | } |
| 2729 | else |
| 2730 | { |
| 2731 | BFD_ASSERT((h->got.offset & 1) == 0); |
| 2732 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); |
| 2733 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_GLOB_DAT); |
| 2734 | rela.r_addend = 0; |
| 2735 | } |
| 2736 | |
| 2737 | bfd_elf32_swap_reloca_out (output_bfd, &rela, |
| 2738 | ((Elf32_External_Rela *) srela->contents |
| 2739 | + srela->reloc_count)); |
| 2740 | ++srela->reloc_count; |
| 2741 | } |
| 2742 | |
| 2743 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) |
| 2744 | { |
| 2745 | asection *s; |
| 2746 | Elf_Internal_Rela rela; |
| 2747 | |
| 2748 | /* This symbols needs a copy reloc. Set it up. */ |
| 2749 | |
| 2750 | #ifdef DEBUG |
| 2751 | fprintf (stderr, ", copy"); |
| 2752 | #endif |
| 2753 | |
| 2754 | BFD_ASSERT (h->dynindx != -1); |
| 2755 | |
| 2756 | if (h->size <= elf_gp_size (dynobj)) |
| 2757 | s = bfd_get_section_by_name (h->root.u.def.section->owner, |
| 2758 | ".rela.sbss"); |
| 2759 | else |
| 2760 | s = bfd_get_section_by_name (h->root.u.def.section->owner, |
| 2761 | ".rela.bss"); |
| 2762 | BFD_ASSERT (s != NULL); |
| 2763 | |
| 2764 | rela.r_offset = (h->root.u.def.value |
| 2765 | + h->root.u.def.section->output_section->vma |
| 2766 | + h->root.u.def.section->output_offset); |
| 2767 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY); |
| 2768 | rela.r_addend = 0; |
| 2769 | bfd_elf32_swap_reloca_out (output_bfd, &rela, |
| 2770 | ((Elf32_External_Rela *) s->contents |
| 2771 | + s->reloc_count)); |
| 2772 | ++s->reloc_count; |
| 2773 | } |
| 2774 | |
| 2775 | #ifdef DEBUG |
| 2776 | fprintf (stderr, "\n"); |
| 2777 | #endif |
| 2778 | |
| 2779 | /* Mark some specially defined symbols as absolute. */ |
| 2780 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
| 2781 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 |
| 2782 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0) |
| 2783 | sym->st_shndx = SHN_ABS; |
| 2784 | |
| 2785 | return true; |
| 2786 | } |
| 2787 | |
| 2788 | \f |
| 2789 | /* Finish up the dynamic sections. */ |
| 2790 | |
| 2791 | static boolean |
| 2792 | ppc_elf_finish_dynamic_sections (output_bfd, info) |
| 2793 | bfd *output_bfd; |
| 2794 | struct bfd_link_info *info; |
| 2795 | { |
| 2796 | asection *sdyn; |
| 2797 | bfd *dynobj = elf_hash_table (info)->dynobj; |
| 2798 | asection *sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 2799 | |
| 2800 | #ifdef DEBUG |
| 2801 | fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n"); |
| 2802 | #endif |
| 2803 | |
| 2804 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
| 2805 | |
| 2806 | if (elf_hash_table (info)->dynamic_sections_created) |
| 2807 | { |
| 2808 | asection *splt; |
| 2809 | Elf32_External_Dyn *dyncon, *dynconend; |
| 2810 | |
| 2811 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 2812 | BFD_ASSERT (splt != NULL && sdyn != NULL); |
| 2813 | |
| 2814 | dyncon = (Elf32_External_Dyn *) sdyn->contents; |
| 2815 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size); |
| 2816 | for (; dyncon < dynconend; dyncon++) |
| 2817 | { |
| 2818 | Elf_Internal_Dyn dyn; |
| 2819 | const char *name; |
| 2820 | boolean size; |
| 2821 | |
| 2822 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
| 2823 | |
| 2824 | switch (dyn.d_tag) |
| 2825 | { |
| 2826 | case DT_PLTGOT: name = ".plt"; size = false; break; |
| 2827 | case DT_PLTRELSZ: name = ".rela.plt"; size = true; break; |
| 2828 | case DT_JMPREL: name = ".rela.plt"; size = false; break; |
| 2829 | default: name = NULL; size = false; break; |
| 2830 | } |
| 2831 | |
| 2832 | if (name != NULL) |
| 2833 | { |
| 2834 | asection *s; |
| 2835 | |
| 2836 | s = bfd_get_section_by_name (output_bfd, name); |
| 2837 | if (s == NULL) |
| 2838 | dyn.d_un.d_val = 0; |
| 2839 | else |
| 2840 | { |
| 2841 | if (! size) |
| 2842 | dyn.d_un.d_ptr = s->vma; |
| 2843 | else |
| 2844 | { |
| 2845 | if (s->_cooked_size != 0) |
| 2846 | dyn.d_un.d_val = s->_cooked_size; |
| 2847 | else |
| 2848 | dyn.d_un.d_val = s->_raw_size; |
| 2849 | } |
| 2850 | } |
| 2851 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 2852 | } |
| 2853 | } |
| 2854 | } |
| 2855 | |
| 2856 | /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can |
| 2857 | easily find the address of the _GLOBAL_OFFSET_TABLE_. */ |
| 2858 | if (sgot) |
| 2859 | { |
| 2860 | unsigned char *contents = sgot->contents; |
| 2861 | bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents); |
| 2862 | |
| 2863 | if (sdyn == NULL) |
| 2864 | bfd_put_32 (output_bfd, (bfd_vma) 0, contents+4); |
| 2865 | else |
| 2866 | bfd_put_32 (output_bfd, |
| 2867 | sdyn->output_section->vma + sdyn->output_offset, |
| 2868 | contents+4); |
| 2869 | |
| 2870 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
| 2871 | } |
| 2872 | |
| 2873 | return true; |
| 2874 | } |
| 2875 | |
| 2876 | \f |
| 2877 | /* The RELOCATE_SECTION function is called by the ELF backend linker |
| 2878 | to handle the relocations for a section. |
| 2879 | |
| 2880 | The relocs are always passed as Rela structures; if the section |
| 2881 | actually uses Rel structures, the r_addend field will always be |
| 2882 | zero. |
| 2883 | |
| 2884 | This function is responsible for adjust the section contents as |
| 2885 | necessary, and (if using Rela relocs and generating a |
| 2886 | relocateable output file) adjusting the reloc addend as |
| 2887 | necessary. |
| 2888 | |
| 2889 | This function does not have to worry about setting the reloc |
| 2890 | address or the reloc symbol index. |
| 2891 | |
| 2892 | LOCAL_SYMS is a pointer to the swapped in local symbols. |
| 2893 | |
| 2894 | LOCAL_SECTIONS is an array giving the section in the input file |
| 2895 | corresponding to the st_shndx field of each local symbol. |
| 2896 | |
| 2897 | The global hash table entry for the global symbols can be found |
| 2898 | via elf_sym_hashes (input_bfd). |
| 2899 | |
| 2900 | When generating relocateable output, this function must handle |
| 2901 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
| 2902 | going to be the section symbol corresponding to the output |
| 2903 | section, which means that the addend must be adjusted |
| 2904 | accordingly. */ |
| 2905 | |
| 2906 | static boolean |
| 2907 | ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section, |
| 2908 | contents, relocs, local_syms, local_sections) |
| 2909 | bfd *output_bfd; |
| 2910 | struct bfd_link_info *info; |
| 2911 | bfd *input_bfd; |
| 2912 | asection *input_section; |
| 2913 | bfd_byte *contents; |
| 2914 | Elf_Internal_Rela *relocs; |
| 2915 | Elf_Internal_Sym *local_syms; |
| 2916 | asection **local_sections; |
| 2917 | { |
| 2918 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
| 2919 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); |
| 2920 | bfd *dynobj = elf_hash_table (info)->dynobj; |
| 2921 | elf_linker_section_t *sdata = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA) : NULL; |
| 2922 | elf_linker_section_t *sdata2 = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA2) : NULL; |
| 2923 | Elf_Internal_Rela *rel = relocs; |
| 2924 | Elf_Internal_Rela *relend = relocs + input_section->reloc_count; |
| 2925 | asection *sreloc = NULL; |
| 2926 | asection *splt; |
| 2927 | asection *sgot; |
| 2928 | bfd_vma *local_got_offsets; |
| 2929 | boolean ret = true; |
| 2930 | long insn; |
| 2931 | |
| 2932 | #ifdef DEBUG |
| 2933 | fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n", |
| 2934 | bfd_get_filename (input_bfd), |
| 2935 | bfd_section_name(input_bfd, input_section), |
| 2936 | (long)input_section->reloc_count, |
| 2937 | (info->relocateable) ? " (relocatable)" : ""); |
| 2938 | #endif |
| 2939 | |
| 2940 | if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */ |
| 2941 | ppc_elf_howto_init (); |
| 2942 | |
| 2943 | local_got_offsets = elf_local_got_offsets (input_bfd); |
| 2944 | |
| 2945 | splt = sgot = NULL; |
| 2946 | if (dynobj != NULL) |
| 2947 | { |
| 2948 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 2949 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 2950 | } |
| 2951 | |
| 2952 | for (; rel < relend; rel++) |
| 2953 | { |
| 2954 | enum elf_ppc_reloc_type r_type = (enum elf_ppc_reloc_type)ELF32_R_TYPE (rel->r_info); |
| 2955 | bfd_vma offset = rel->r_offset; |
| 2956 | bfd_vma addend = rel->r_addend; |
| 2957 | bfd_reloc_status_type r = bfd_reloc_other; |
| 2958 | Elf_Internal_Sym *sym = (Elf_Internal_Sym *)0; |
| 2959 | asection *sec = (asection *)0; |
| 2960 | struct elf_link_hash_entry *h = (struct elf_link_hash_entry *)0; |
| 2961 | const char *sym_name = (const char *)0; |
| 2962 | reloc_howto_type *howto; |
| 2963 | unsigned long r_symndx; |
| 2964 | bfd_vma relocation; |
| 2965 | int will_become_local; |
| 2966 | |
| 2967 | /* Unknown relocation handling */ |
| 2968 | if ((unsigned)r_type >= (unsigned)R_PPC_max || !ppc_elf_howto_table[(int)r_type]) |
| 2969 | { |
| 2970 | (*_bfd_error_handler) (_("%s: unknown relocation type %d"), |
| 2971 | bfd_get_filename (input_bfd), |
| 2972 | (int)r_type); |
| 2973 | |
| 2974 | bfd_set_error (bfd_error_bad_value); |
| 2975 | ret = false; |
| 2976 | continue; |
| 2977 | } |
| 2978 | |
| 2979 | howto = ppc_elf_howto_table[(int)r_type]; |
| 2980 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 2981 | |
| 2982 | if (info->relocateable) |
| 2983 | { |
| 2984 | /* This is a relocateable link. We don't have to change |
| 2985 | anything, unless the reloc is against a section symbol, |
| 2986 | in which case we have to adjust according to where the |
| 2987 | section symbol winds up in the output section. */ |
| 2988 | if (r_symndx < symtab_hdr->sh_info) |
| 2989 | { |
| 2990 | sym = local_syms + r_symndx; |
| 2991 | if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION) |
| 2992 | { |
| 2993 | sec = local_sections[r_symndx]; |
| 2994 | addend = rel->r_addend += sec->output_offset + sym->st_value; |
| 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | #ifdef DEBUG |
| 2999 | fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n", |
| 3000 | howto->name, |
| 3001 | (int)r_type, |
| 3002 | r_symndx, |
| 3003 | (long)offset, |
| 3004 | (long)addend); |
| 3005 | #endif |
| 3006 | continue; |
| 3007 | } |
| 3008 | |
| 3009 | /* This is a final link. */ |
| 3010 | if (r_symndx < symtab_hdr->sh_info) |
| 3011 | { |
| 3012 | sym = local_syms + r_symndx; |
| 3013 | sec = local_sections[r_symndx]; |
| 3014 | sym_name = "<local symbol>"; |
| 3015 | |
| 3016 | relocation = (sec->output_section->vma |
| 3017 | + sec->output_offset |
| 3018 | + sym->st_value); |
| 3019 | /* Relocs to local symbols are always resolved. */ |
| 3020 | will_become_local = 1; |
| 3021 | } |
| 3022 | else |
| 3023 | { |
| 3024 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 3025 | while (h->root.type == bfd_link_hash_indirect |
| 3026 | || h->root.type == bfd_link_hash_warning) |
| 3027 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 3028 | sym_name = h->root.root.string; |
| 3029 | |
| 3030 | /* Can this relocation be resolved immediately? */ |
| 3031 | will_become_local = SYMBOL_REFERENCES_LOCAL (info, h); |
| 3032 | |
| 3033 | if (h->root.type == bfd_link_hash_defined |
| 3034 | || h->root.type == bfd_link_hash_defweak) |
| 3035 | { |
| 3036 | sec = h->root.u.def.section; |
| 3037 | if (((r_type == R_PPC_PLT32 |
| 3038 | || r_type == R_PPC_PLTREL24) |
| 3039 | && splt != NULL |
| 3040 | && h->plt.offset != (bfd_vma) -1) |
| 3041 | || (r_type == R_PPC_LOCAL24PC |
| 3042 | && sec->output_section == NULL) |
| 3043 | || ((r_type == R_PPC_GOT16 |
| 3044 | || r_type == R_PPC_GOT16_LO |
| 3045 | || r_type == R_PPC_GOT16_HI |
| 3046 | || r_type == R_PPC_GOT16_HA) |
| 3047 | && elf_hash_table (info)->dynamic_sections_created |
| 3048 | && (! info->shared || ! will_become_local)) |
| 3049 | || (info->shared |
| 3050 | && ! will_become_local |
| 3051 | && ((input_section->flags & SEC_ALLOC) != 0 |
| 3052 | /* Testing SEC_DEBUGGING here may be wrong. |
| 3053 | It's here to avoid a crash when |
| 3054 | generating a shared library with DWARF |
| 3055 | debugging information. */ |
| 3056 | || ((input_section->flags & SEC_DEBUGGING) != 0 |
| 3057 | && (h->elf_link_hash_flags |
| 3058 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) |
| 3059 | && (r_type == R_PPC_ADDR32 |
| 3060 | || r_type == R_PPC_ADDR24 |
| 3061 | || r_type == R_PPC_ADDR16 |
| 3062 | || r_type == R_PPC_ADDR16_LO |
| 3063 | || r_type == R_PPC_ADDR16_HI |
| 3064 | || r_type == R_PPC_ADDR16_HA |
| 3065 | || r_type == R_PPC_ADDR14 |
| 3066 | || r_type == R_PPC_ADDR14_BRTAKEN |
| 3067 | || r_type == R_PPC_ADDR14_BRNTAKEN |
| 3068 | || r_type == R_PPC_COPY |
| 3069 | || r_type == R_PPC_GLOB_DAT |
| 3070 | || r_type == R_PPC_JMP_SLOT |
| 3071 | || r_type == R_PPC_UADDR32 |
| 3072 | || r_type == R_PPC_UADDR16 |
| 3073 | || r_type == R_PPC_SDAREL16 |
| 3074 | || r_type == R_PPC_EMB_NADDR32 |
| 3075 | || r_type == R_PPC_EMB_NADDR16 |
| 3076 | || r_type == R_PPC_EMB_NADDR16_LO |
| 3077 | || r_type == R_PPC_EMB_NADDR16_HI |
| 3078 | || r_type == R_PPC_EMB_NADDR16_HA |
| 3079 | || r_type == R_PPC_EMB_SDAI16 |
| 3080 | || r_type == R_PPC_EMB_SDA2I16 |
| 3081 | || r_type == R_PPC_EMB_SDA2REL |
| 3082 | || r_type == R_PPC_EMB_SDA21 |
| 3083 | || r_type == R_PPC_EMB_MRKREF |
| 3084 | || r_type == R_PPC_EMB_BIT_FLD |
| 3085 | || r_type == R_PPC_EMB_RELSDA |
| 3086 | || ((r_type == R_PPC_REL24 |
| 3087 | || r_type == R_PPC_REL32 |
| 3088 | || r_type == R_PPC_REL14 |
| 3089 | || r_type == R_PPC_REL14_BRTAKEN |
| 3090 | || r_type == R_PPC_REL14_BRNTAKEN |
| 3091 | || r_type == R_PPC_RELATIVE) |
| 3092 | && strcmp (h->root.root.string, |
| 3093 | "_GLOBAL_OFFSET_TABLE_") != 0)))) |
| 3094 | { |
| 3095 | /* In these cases, we don't need the relocation |
| 3096 | value. We check specially because in some |
| 3097 | obscure cases sec->output_section will be NULL. */ |
| 3098 | relocation = 0; |
| 3099 | } |
| 3100 | else if (sec->output_section == NULL) |
| 3101 | { |
| 3102 | (*_bfd_error_handler) |
| 3103 | (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"), |
| 3104 | bfd_get_filename (input_bfd), h->root.root.string, |
| 3105 | bfd_get_section_name (input_bfd, input_section)); |
| 3106 | relocation = 0; |
| 3107 | } |
| 3108 | else |
| 3109 | relocation = (h->root.u.def.value |
| 3110 | + sec->output_section->vma |
| 3111 | + sec->output_offset); |
| 3112 | } |
| 3113 | else if (h->root.type == bfd_link_hash_undefweak) |
| 3114 | relocation = 0; |
| 3115 | else if (info->shared && !info->symbolic && !info->no_undefined |
| 3116 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
| 3117 | relocation = 0; |
| 3118 | else |
| 3119 | { |
| 3120 | if (! (*info->callbacks->undefined_symbol) (info, |
| 3121 | h->root.root.string, |
| 3122 | input_bfd, |
| 3123 | input_section, |
| 3124 | rel->r_offset, |
| 3125 | (!info->shared |
| 3126 | || info->no_undefined |
| 3127 | || ELF_ST_VISIBILITY (h->other)))) |
| 3128 | return false; |
| 3129 | relocation = 0; |
| 3130 | } |
| 3131 | } |
| 3132 | |
| 3133 | switch ((int)r_type) |
| 3134 | { |
| 3135 | default: |
| 3136 | (*_bfd_error_handler) (_("%s: unknown relocation type %d for symbol %s"), |
| 3137 | bfd_get_filename (input_bfd), |
| 3138 | (int)r_type, sym_name); |
| 3139 | |
| 3140 | bfd_set_error (bfd_error_bad_value); |
| 3141 | ret = false; |
| 3142 | continue; |
| 3143 | |
| 3144 | /* Relocations that need no special processing. */ |
| 3145 | case (int)R_PPC_LOCAL24PC: |
| 3146 | /* It makes no sense to point a local relocation |
| 3147 | at a symbol not in this object. */ |
| 3148 | if (h != NULL |
| 3149 | && (h->root.type == bfd_link_hash_defined |
| 3150 | || h->root.type == bfd_link_hash_defweak) |
| 3151 | && sec->output_section == NULL) |
| 3152 | { |
| 3153 | if (! (*info->callbacks->undefined_symbol) (info, |
| 3154 | h->root.root.string, |
| 3155 | input_bfd, |
| 3156 | input_section, |
| 3157 | rel->r_offset, |
| 3158 | true)) |
| 3159 | return false; |
| 3160 | continue; |
| 3161 | } |
| 3162 | break; |
| 3163 | |
| 3164 | /* Relocations that may need to be propagated if this is a shared |
| 3165 | object. */ |
| 3166 | case (int)R_PPC_REL24: |
| 3167 | case (int)R_PPC_REL32: |
| 3168 | case (int)R_PPC_REL14: |
| 3169 | /* If these relocations are not to a named symbol, they can be |
| 3170 | handled right here, no need to bother the dynamic linker. */ |
| 3171 | if (h == NULL |
| 3172 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 |
| 3173 | || SYMBOL_REFERENCES_LOCAL (info, h)) |
| 3174 | break; |
| 3175 | /* fall through */ |
| 3176 | |
| 3177 | /* Relocations that always need to be propagated if this is a shared |
| 3178 | object. */ |
| 3179 | case (int)R_PPC_NONE: |
| 3180 | case (int)R_PPC_ADDR32: |
| 3181 | case (int)R_PPC_ADDR24: |
| 3182 | case (int)R_PPC_ADDR16: |
| 3183 | case (int)R_PPC_ADDR16_LO: |
| 3184 | case (int)R_PPC_ADDR16_HI: |
| 3185 | case (int)R_PPC_ADDR16_HA: |
| 3186 | case (int)R_PPC_ADDR14: |
| 3187 | case (int)R_PPC_UADDR32: |
| 3188 | case (int)R_PPC_UADDR16: |
| 3189 | if (info->shared) |
| 3190 | { |
| 3191 | Elf_Internal_Rela outrel; |
| 3192 | boolean skip; |
| 3193 | |
| 3194 | #ifdef DEBUG |
| 3195 | fprintf (stderr, "ppc_elf_relocate_section need to create relocation for %s\n", |
| 3196 | (h && h->root.root.string) ? h->root.root.string : "<unknown>"); |
| 3197 | #endif |
| 3198 | |
| 3199 | /* When generating a shared object, these relocations |
| 3200 | are copied into the output file to be resolved at run |
| 3201 | time. */ |
| 3202 | |
| 3203 | if (sreloc == NULL) |
| 3204 | { |
| 3205 | const char *name; |
| 3206 | |
| 3207 | name = (bfd_elf_string_from_elf_section |
| 3208 | (input_bfd, |
| 3209 | elf_elfheader (input_bfd)->e_shstrndx, |
| 3210 | elf_section_data (input_section)->rel_hdr.sh_name)); |
| 3211 | if (name == NULL) |
| 3212 | return false; |
| 3213 | |
| 3214 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 |
| 3215 | && strcmp (bfd_get_section_name (input_bfd, |
| 3216 | input_section), |
| 3217 | name + 5) == 0); |
| 3218 | |
| 3219 | sreloc = bfd_get_section_by_name (dynobj, name); |
| 3220 | BFD_ASSERT (sreloc != NULL); |
| 3221 | } |
| 3222 | |
| 3223 | skip = false; |
| 3224 | |
| 3225 | if (elf_section_data (input_section)->stab_info == NULL) |
| 3226 | outrel.r_offset = rel->r_offset; |
| 3227 | else |
| 3228 | { |
| 3229 | bfd_vma off; |
| 3230 | |
| 3231 | off = (_bfd_stab_section_offset |
| 3232 | (output_bfd, &elf_hash_table (info)->stab_info, |
| 3233 | input_section, |
| 3234 | &elf_section_data (input_section)->stab_info, |
| 3235 | rel->r_offset)); |
| 3236 | if (off == (bfd_vma) -1) |
| 3237 | skip = true; |
| 3238 | outrel.r_offset = off; |
| 3239 | } |
| 3240 | |
| 3241 | outrel.r_offset += (input_section->output_section->vma |
| 3242 | + input_section->output_offset); |
| 3243 | |
| 3244 | if (skip) |
| 3245 | memset (&outrel, 0, sizeof outrel); |
| 3246 | /* h->dynindx may be -1 if this symbol was marked to |
| 3247 | become local. */ |
| 3248 | else if (! will_become_local) |
| 3249 | { |
| 3250 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
| 3251 | outrel.r_addend = rel->r_addend; |
| 3252 | } |
| 3253 | else |
| 3254 | { |
| 3255 | if (r_type == R_PPC_ADDR32) |
| 3256 | { |
| 3257 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); |
| 3258 | outrel.r_addend = relocation + rel->r_addend; |
| 3259 | } |
| 3260 | else |
| 3261 | { |
| 3262 | long indx; |
| 3263 | |
| 3264 | if (h == NULL) |
| 3265 | sec = local_sections[r_symndx]; |
| 3266 | else |
| 3267 | { |
| 3268 | BFD_ASSERT (h->root.type == bfd_link_hash_defined |
| 3269 | || (h->root.type |
| 3270 | == bfd_link_hash_defweak)); |
| 3271 | sec = h->root.u.def.section; |
| 3272 | } |
| 3273 | if (sec != NULL && bfd_is_abs_section (sec)) |
| 3274 | indx = 0; |
| 3275 | else if (sec == NULL || sec->owner == NULL) |
| 3276 | { |
| 3277 | bfd_set_error (bfd_error_bad_value); |
| 3278 | return false; |
| 3279 | } |
| 3280 | else |
| 3281 | { |
| 3282 | asection *osec; |
| 3283 | |
| 3284 | osec = sec->output_section; |
| 3285 | indx = elf_section_data (osec)->dynindx; |
| 3286 | BFD_ASSERT(indx > 0); |
| 3287 | #ifdef DEBUG |
| 3288 | if (indx <= 0) |
| 3289 | { |
| 3290 | printf ("indx=%d section=%s flags=%08x name=%s\n", |
| 3291 | indx, osec->name, osec->flags, |
| 3292 | h->root.root.string); |
| 3293 | } |
| 3294 | #endif |
| 3295 | } |
| 3296 | |
| 3297 | outrel.r_info = ELF32_R_INFO (indx, r_type); |
| 3298 | outrel.r_addend = relocation + rel->r_addend; |
| 3299 | } |
| 3300 | } |
| 3301 | |
| 3302 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, |
| 3303 | (((Elf32_External_Rela *) |
| 3304 | sreloc->contents) |
| 3305 | + sreloc->reloc_count)); |
| 3306 | ++sreloc->reloc_count; |
| 3307 | |
| 3308 | /* This reloc will be computed at runtime, so there's no |
| 3309 | need to do anything now, unless this is a RELATIVE |
| 3310 | reloc in an unallocated section. */ |
| 3311 | if (skip |
| 3312 | || (input_section->flags & SEC_ALLOC) != 0 |
| 3313 | || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE) |
| 3314 | continue; |
| 3315 | } |
| 3316 | |
| 3317 | /* Arithmetic adjust relocations that aren't going into a |
| 3318 | shared object. */ |
| 3319 | if (r_type == R_PPC_ADDR16_HA |
| 3320 | /* It's just possible that this symbol is a weak symbol |
| 3321 | that's not actually defined anywhere. In that case, |
| 3322 | 'sec' would be NULL, and we should leave the symbol |
| 3323 | alone (it will be set to zero elsewhere in the link). */ |
| 3324 | && sec != NULL) |
| 3325 | { |
| 3326 | addend += ((relocation + addend) & 0x8000) << 1; |
| 3327 | } |
| 3328 | break; |
| 3329 | |
| 3330 | /* branch taken prediction relocations */ |
| 3331 | case (int)R_PPC_ADDR14_BRTAKEN: |
| 3332 | case (int)R_PPC_REL14_BRTAKEN: |
| 3333 | insn = bfd_get_32 (output_bfd, contents + offset); |
| 3334 | if ((relocation - offset) & 0x8000) |
| 3335 | insn &= ~BRANCH_PREDICT_BIT; |
| 3336 | else |
| 3337 | insn |= BRANCH_PREDICT_BIT; |
| 3338 | bfd_put_32 (output_bfd, insn, contents + offset); |
| 3339 | break; |
| 3340 | |
| 3341 | /* branch not taken predicition relocations */ |
| 3342 | case (int)R_PPC_ADDR14_BRNTAKEN: |
| 3343 | case (int)R_PPC_REL14_BRNTAKEN: |
| 3344 | insn = bfd_get_32 (output_bfd, contents + offset); |
| 3345 | if ((relocation - offset) & 0x8000) |
| 3346 | insn |= BRANCH_PREDICT_BIT; |
| 3347 | else |
| 3348 | insn &= ~BRANCH_PREDICT_BIT; |
| 3349 | bfd_put_32 (output_bfd, insn, contents + offset); |
| 3350 | break; |
| 3351 | |
| 3352 | /* GOT16 relocations */ |
| 3353 | case (int)R_PPC_GOT16: |
| 3354 | case (int)R_PPC_GOT16_LO: |
| 3355 | case (int)R_PPC_GOT16_HI: |
| 3356 | case (int)R_PPC_GOT16_HA: |
| 3357 | /* Relocation is to the entry for this symbol in the global |
| 3358 | offset table. */ |
| 3359 | BFD_ASSERT (sgot != NULL); |
| 3360 | |
| 3361 | if (h != NULL) |
| 3362 | { |
| 3363 | bfd_vma off; |
| 3364 | |
| 3365 | off = h->got.offset; |
| 3366 | BFD_ASSERT (off != (bfd_vma) -1); |
| 3367 | |
| 3368 | if (! elf_hash_table (info)->dynamic_sections_created |
| 3369 | || (info->shared |
| 3370 | && SYMBOL_REFERENCES_LOCAL (info, h))) |
| 3371 | { |
| 3372 | /* This is actually a static link, or it is a |
| 3373 | -Bsymbolic link and the symbol is defined |
| 3374 | locally. We must initialize this entry in the |
| 3375 | global offset table. Since the offset must |
| 3376 | always be a multiple of 4, we use the least |
| 3377 | significant bit to record whether we have |
| 3378 | initialized it already. |
| 3379 | |
| 3380 | When doing a dynamic link, we create a .rela.got |
| 3381 | relocation entry to initialize the value. This |
| 3382 | is done in the finish_dynamic_symbol routine. */ |
| 3383 | if ((off & 1) != 0) |
| 3384 | off &= ~1; |
| 3385 | else |
| 3386 | { |
| 3387 | bfd_put_32 (output_bfd, relocation, |
| 3388 | sgot->contents + off); |
| 3389 | h->got.offset |= 1; |
| 3390 | } |
| 3391 | } |
| 3392 | |
| 3393 | relocation = sgot->output_offset + off - 4; |
| 3394 | } |
| 3395 | else |
| 3396 | { |
| 3397 | bfd_vma off; |
| 3398 | |
| 3399 | BFD_ASSERT (local_got_offsets != NULL |
| 3400 | && local_got_offsets[r_symndx] != (bfd_vma) -1); |
| 3401 | |
| 3402 | off = local_got_offsets[r_symndx]; |
| 3403 | |
| 3404 | /* The offset must always be a multiple of 4. We use |
| 3405 | the least significant bit to record whether we have |
| 3406 | already processed this entry. */ |
| 3407 | if ((off & 1) != 0) |
| 3408 | off &= ~1; |
| 3409 | else |
| 3410 | { |
| 3411 | bfd_put_32 (output_bfd, relocation, sgot->contents + off); |
| 3412 | |
| 3413 | if (info->shared) |
| 3414 | { |
| 3415 | asection *srelgot; |
| 3416 | Elf_Internal_Rela outrel; |
| 3417 | |
| 3418 | /* We need to generate a R_PPC_RELATIVE reloc |
| 3419 | for the dynamic linker. */ |
| 3420 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 3421 | BFD_ASSERT (srelgot != NULL); |
| 3422 | |
| 3423 | outrel.r_offset = (sgot->output_section->vma |
| 3424 | + sgot->output_offset |
| 3425 | + off); |
| 3426 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); |
| 3427 | outrel.r_addend = relocation; |
| 3428 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, |
| 3429 | (((Elf32_External_Rela *) |
| 3430 | srelgot->contents) |
| 3431 | + srelgot->reloc_count)); |
| 3432 | ++srelgot->reloc_count; |
| 3433 | } |
| 3434 | |
| 3435 | local_got_offsets[r_symndx] |= 1; |
| 3436 | } |
| 3437 | |
| 3438 | relocation = sgot->output_offset + off - 4; |
| 3439 | } |
| 3440 | break; |
| 3441 | |
| 3442 | /* Indirect .sdata relocation */ |
| 3443 | case (int)R_PPC_EMB_SDAI16: |
| 3444 | BFD_ASSERT (sdata != NULL); |
| 3445 | relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info, |
| 3446 | sdata, h, relocation, rel, |
| 3447 | R_PPC_RELATIVE); |
| 3448 | break; |
| 3449 | |
| 3450 | /* Indirect .sdata2 relocation */ |
| 3451 | case (int)R_PPC_EMB_SDA2I16: |
| 3452 | BFD_ASSERT (sdata2 != NULL); |
| 3453 | relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info, |
| 3454 | sdata2, h, relocation, rel, |
| 3455 | R_PPC_RELATIVE); |
| 3456 | break; |
| 3457 | |
| 3458 | /* Handle the TOC16 reloc. We want to use the offset within the .got |
| 3459 | section, not the actual VMA. This is appropriate when generating |
| 3460 | an embedded ELF object, for which the .got section acts like the |
| 3461 | AIX .toc section. */ |
| 3462 | case (int)R_PPC_TOC16: /* phony GOT16 relocations */ |
| 3463 | BFD_ASSERT (sec != (asection *)0); |
| 3464 | BFD_ASSERT (bfd_is_und_section (sec) |
| 3465 | || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0 |
| 3466 | || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0) |
| 3467 | |
| 3468 | addend -= sec->output_section->vma + sec->output_offset + 0x8000; |
| 3469 | break; |
| 3470 | |
| 3471 | case (int)R_PPC_PLTREL24: |
| 3472 | /* Relocation is to the entry for this symbol in the |
| 3473 | procedure linkage table. */ |
| 3474 | BFD_ASSERT (h != NULL); |
| 3475 | |
| 3476 | if (h->plt.offset == (bfd_vma) -1 |
| 3477 | || splt == NULL) |
| 3478 | { |
| 3479 | /* We didn't make a PLT entry for this symbol. This |
| 3480 | happens when statically linking PIC code, or when |
| 3481 | using -Bsymbolic. */ |
| 3482 | break; |
| 3483 | } |
| 3484 | |
| 3485 | relocation = (splt->output_section->vma |
| 3486 | + splt->output_offset |
| 3487 | + h->plt.offset); |
| 3488 | break; |
| 3489 | |
| 3490 | /* relocate against _SDA_BASE_ */ |
| 3491 | case (int)R_PPC_SDAREL16: |
| 3492 | { |
| 3493 | const char *name; |
| 3494 | |
| 3495 | BFD_ASSERT (sec != (asection *)0); |
| 3496 | name = bfd_get_section_name (abfd, sec->output_section); |
| 3497 | if (strcmp (name, ".sdata") != 0 |
| 3498 | && strcmp (name, ".sbss") != 0) |
| 3499 | { |
| 3500 | (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"), |
| 3501 | bfd_get_filename (input_bfd), |
| 3502 | sym_name, |
| 3503 | ppc_elf_howto_table[ (int)r_type ]->name, |
| 3504 | name); |
| 3505 | } |
| 3506 | addend -= (sdata->sym_hash->root.u.def.value |
| 3507 | + sdata->sym_hash->root.u.def.section->output_section->vma |
| 3508 | + sdata->sym_hash->root.u.def.section->output_offset); |
| 3509 | } |
| 3510 | break; |
| 3511 | |
| 3512 | /* relocate against _SDA2_BASE_ */ |
| 3513 | case (int)R_PPC_EMB_SDA2REL: |
| 3514 | { |
| 3515 | const char *name; |
| 3516 | |
| 3517 | BFD_ASSERT (sec != (asection *)0); |
| 3518 | name = bfd_get_section_name (abfd, sec->output_section); |
| 3519 | if (strcmp (name, ".sdata2") != 0 && strcmp (name, ".sbss2") != 0) |
| 3520 | { |
| 3521 | (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"), |
| 3522 | bfd_get_filename (input_bfd), |
| 3523 | sym_name, |
| 3524 | ppc_elf_howto_table[ (int)r_type ]->name, |
| 3525 | name); |
| 3526 | |
| 3527 | bfd_set_error (bfd_error_bad_value); |
| 3528 | ret = false; |
| 3529 | continue; |
| 3530 | } |
| 3531 | addend -= (sdata2->sym_hash->root.u.def.value |
| 3532 | + sdata2->sym_hash->root.u.def.section->output_section->vma |
| 3533 | + sdata2->sym_hash->root.u.def.section->output_offset); |
| 3534 | } |
| 3535 | break; |
| 3536 | |
| 3537 | /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */ |
| 3538 | case (int)R_PPC_EMB_SDA21: |
| 3539 | case (int)R_PPC_EMB_RELSDA: |
| 3540 | { |
| 3541 | const char *name; |
| 3542 | int reg; |
| 3543 | |
| 3544 | BFD_ASSERT (sec != (asection *)0); |
| 3545 | name = bfd_get_section_name (abfd, sec->output_section); |
| 3546 | if (strcmp (name, ".sdata") == 0 || strcmp (name, ".sbss") == 0) |
| 3547 | { |
| 3548 | reg = 13; |
| 3549 | addend -= (sdata->sym_hash->root.u.def.value |
| 3550 | + sdata->sym_hash->root.u.def.section->output_section->vma |
| 3551 | + sdata->sym_hash->root.u.def.section->output_offset); |
| 3552 | } |
| 3553 | |
| 3554 | else if (strcmp (name, ".sdata2") == 0 || strcmp (name, ".sbss2") == 0) |
| 3555 | { |
| 3556 | reg = 2; |
| 3557 | addend -= (sdata2->sym_hash->root.u.def.value |
| 3558 | + sdata2->sym_hash->root.u.def.section->output_section->vma |
| 3559 | + sdata2->sym_hash->root.u.def.section->output_offset); |
| 3560 | } |
| 3561 | |
| 3562 | else if (strcmp (name, ".PPC.EMB.sdata0") == 0 || strcmp (name, ".PPC.EMB.sbss0") == 0) |
| 3563 | { |
| 3564 | reg = 0; |
| 3565 | } |
| 3566 | |
| 3567 | else |
| 3568 | { |
| 3569 | (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"), |
| 3570 | bfd_get_filename (input_bfd), |
| 3571 | sym_name, |
| 3572 | ppc_elf_howto_table[ (int)r_type ]->name, |
| 3573 | name); |
| 3574 | |
| 3575 | bfd_set_error (bfd_error_bad_value); |
| 3576 | ret = false; |
| 3577 | continue; |
| 3578 | } |
| 3579 | |
| 3580 | if (r_type == R_PPC_EMB_SDA21) |
| 3581 | { /* fill in register field */ |
| 3582 | insn = bfd_get_32 (output_bfd, contents + offset); |
| 3583 | insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT); |
| 3584 | bfd_put_32 (output_bfd, insn, contents + offset); |
| 3585 | } |
| 3586 | } |
| 3587 | break; |
| 3588 | |
| 3589 | /* Relocate against the beginning of the section */ |
| 3590 | case (int)R_PPC_SECTOFF: |
| 3591 | case (int)R_PPC_SECTOFF_LO: |
| 3592 | case (int)R_PPC_SECTOFF_HI: |
| 3593 | BFD_ASSERT (sec != (asection *)0); |
| 3594 | addend -= sec->output_section->vma; |
| 3595 | break; |
| 3596 | |
| 3597 | case (int)R_PPC_SECTOFF_HA: |
| 3598 | BFD_ASSERT (sec != (asection *)0); |
| 3599 | addend -= sec->output_section->vma; |
| 3600 | addend += ((relocation + addend) & 0x8000) << 1; |
| 3601 | break; |
| 3602 | |
| 3603 | /* Negative relocations */ |
| 3604 | case (int)R_PPC_EMB_NADDR32: |
| 3605 | case (int)R_PPC_EMB_NADDR16: |
| 3606 | case (int)R_PPC_EMB_NADDR16_LO: |
| 3607 | case (int)R_PPC_EMB_NADDR16_HI: |
| 3608 | addend -= 2*relocation; |
| 3609 | break; |
| 3610 | |
| 3611 | case (int)R_PPC_EMB_NADDR16_HA: |
| 3612 | addend -= 2*relocation; |
| 3613 | addend += ((relocation + addend) & 0x8000) << 1; |
| 3614 | break; |
| 3615 | |
| 3616 | /* NOP relocation that prevents garbage collecting linkers from omitting a |
| 3617 | reference. */ |
| 3618 | case (int)R_PPC_EMB_MRKREF: |
| 3619 | continue; |
| 3620 | |
| 3621 | case (int)R_PPC_COPY: |
| 3622 | case (int)R_PPC_GLOB_DAT: |
| 3623 | case (int)R_PPC_JMP_SLOT: |
| 3624 | case (int)R_PPC_RELATIVE: |
| 3625 | case (int)R_PPC_PLT32: |
| 3626 | case (int)R_PPC_PLTREL32: |
| 3627 | case (int)R_PPC_PLT16_LO: |
| 3628 | case (int)R_PPC_PLT16_HI: |
| 3629 | case (int)R_PPC_PLT16_HA: |
| 3630 | case (int)R_PPC_EMB_RELSEC16: |
| 3631 | case (int)R_PPC_EMB_RELST_LO: |
| 3632 | case (int)R_PPC_EMB_RELST_HI: |
| 3633 | case (int)R_PPC_EMB_RELST_HA: |
| 3634 | case (int)R_PPC_EMB_BIT_FLD: |
| 3635 | (*_bfd_error_handler) (_("%s: Relocation %s is not yet supported for symbol %s."), |
| 3636 | bfd_get_filename (input_bfd), |
| 3637 | ppc_elf_howto_table[ (int)r_type ]->name, |
| 3638 | sym_name); |
| 3639 | |
| 3640 | bfd_set_error (bfd_error_invalid_operation); |
| 3641 | ret = false; |
| 3642 | continue; |
| 3643 | |
| 3644 | case (int)R_PPC_GNU_VTINHERIT: |
| 3645 | case (int)R_PPC_GNU_VTENTRY: |
| 3646 | /* These are no-ops in the end. */ |
| 3647 | continue; |
| 3648 | } |
| 3649 | |
| 3650 | #ifdef DEBUG |
| 3651 | fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n", |
| 3652 | howto->name, |
| 3653 | (int)r_type, |
| 3654 | sym_name, |
| 3655 | r_symndx, |
| 3656 | (long)offset, |
| 3657 | (long)addend); |
| 3658 | #endif |
| 3659 | |
| 3660 | r = _bfd_final_link_relocate (howto, |
| 3661 | input_bfd, |
| 3662 | input_section, |
| 3663 | contents, |
| 3664 | offset, |
| 3665 | relocation, |
| 3666 | addend); |
| 3667 | |
| 3668 | if (r == bfd_reloc_ok) |
| 3669 | ; |
| 3670 | else if (r == bfd_reloc_overflow) |
| 3671 | { |
| 3672 | const char *name; |
| 3673 | |
| 3674 | if (h != NULL) |
| 3675 | { |
| 3676 | if (h->root.type == bfd_link_hash_undefweak |
| 3677 | && howto->pc_relative) |
| 3678 | { |
| 3679 | /* Assume this is a call protected by other code that |
| 3680 | detect the symbol is undefined. If this is the case, |
| 3681 | we can safely ignore the overflow. If not, the |
| 3682 | program is hosed anyway, and a little warning isn't |
| 3683 | going to help. */ |
| 3684 | |
| 3685 | continue; |
| 3686 | } |
| 3687 | |
| 3688 | name = h->root.root.string; |
| 3689 | } |
| 3690 | else |
| 3691 | { |
| 3692 | name = bfd_elf_string_from_elf_section (input_bfd, |
| 3693 | symtab_hdr->sh_link, |
| 3694 | sym->st_name); |
| 3695 | if (name == NULL) |
| 3696 | continue; |
| 3697 | if (*name == '\0') |
| 3698 | name = bfd_section_name (input_bfd, sec); |
| 3699 | } |
| 3700 | |
| 3701 | if (! (*info->callbacks->reloc_overflow) (info, |
| 3702 | name, |
| 3703 | howto->name, |
| 3704 | (bfd_vma) 0, |
| 3705 | input_bfd, |
| 3706 | input_section, |
| 3707 | offset)) |
| 3708 | return false; |
| 3709 | } |
| 3710 | else |
| 3711 | ret = false; |
| 3712 | } |
| 3713 | |
| 3714 | #ifdef DEBUG |
| 3715 | fprintf (stderr, "\n"); |
| 3716 | #endif |
| 3717 | |
| 3718 | return ret; |
| 3719 | } |
| 3720 | |
| 3721 | \f |
| 3722 | #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec |
| 3723 | #define TARGET_LITTLE_NAME "elf32-powerpcle" |
| 3724 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vec |
| 3725 | #define TARGET_BIG_NAME "elf32-powerpc" |
| 3726 | #define ELF_ARCH bfd_arch_powerpc |
| 3727 | #define ELF_MACHINE_CODE EM_PPC |
| 3728 | #define ELF_MAXPAGESIZE 0x10000 |
| 3729 | #define elf_info_to_howto ppc_elf_info_to_howto |
| 3730 | |
| 3731 | #ifdef EM_CYGNUS_POWERPC |
| 3732 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC |
| 3733 | #endif |
| 3734 | |
| 3735 | #ifdef EM_PPC_OLD |
| 3736 | #define ELF_MACHINE_ALT2 EM_PPC_OLD |
| 3737 | #endif |
| 3738 | |
| 3739 | #define elf_backend_plt_not_loaded 1 |
| 3740 | #define elf_backend_got_symbol_offset 4 |
| 3741 | #define elf_backend_can_gc_sections 1 |
| 3742 | #define elf_backend_got_header_size 12 |
| 3743 | #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE |
| 3744 | |
| 3745 | #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data |
| 3746 | #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data |
| 3747 | #define bfd_elf32_bfd_relax_section ppc_elf_relax_section |
| 3748 | #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup |
| 3749 | #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags |
| 3750 | #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link |
| 3751 | |
| 3752 | #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook |
| 3753 | #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook |
| 3754 | #define elf_backend_section_from_shdr ppc_elf_section_from_shdr |
| 3755 | #define elf_backend_relocate_section ppc_elf_relocate_section |
| 3756 | #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections |
| 3757 | #define elf_backend_check_relocs ppc_elf_check_relocs |
| 3758 | #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol |
| 3759 | #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook |
| 3760 | #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections |
| 3761 | #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol |
| 3762 | #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections |
| 3763 | #define elf_backend_fake_sections ppc_elf_fake_sections |
| 3764 | #define elf_backend_additional_program_headers ppc_elf_additional_program_headers |
| 3765 | #define elf_backend_modify_segment_map ppc_elf_modify_segment_map |
| 3766 | |
| 3767 | #include "elf32-target.h" |