1 /* 32-bit ELF support for ARM 2 Copyright (C) 1998-2014 Free Software Foundation, Inc. 3 4 This file is part of BFD, the Binary File Descriptor library. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19 MA 02110-1301, USA. */ 20 21 #include "sysdep.h" 22 #include <limits.h> 23 24 #include "bfd.h" 25 #include "bfd_stdint.h" 26 #include "libiberty.h" 27 #include "libbfd.h" 28 #include "elf-bfd.h" 29 #include "elf-nacl.h" 30 #include "elf-vxworks.h" 31 #include "elf/arm.h" 32 33 /* Return the relocation section associated with NAME. HTAB is the 34 bfd's elf32_arm_link_hash_entry. */ 35 #define RELOC_SECTION(HTAB, NAME) \ 36 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME) 37 38 /* Return size of a relocation entry. HTAB is the bfd's 39 elf32_arm_link_hash_entry. */ 40 #define RELOC_SIZE(HTAB) \ 41 ((HTAB)->use_rel \ 42 ? sizeof (Elf32_External_Rel) \ 43 : sizeof (Elf32_External_Rela)) 44 45 /* Return function to swap relocations in. HTAB is the bfd's 46 elf32_arm_link_hash_entry. */ 47 #define SWAP_RELOC_IN(HTAB) \ 48 ((HTAB)->use_rel \ 49 ? bfd_elf32_swap_reloc_in \ 50 : bfd_elf32_swap_reloca_in) 51 52 /* Return function to swap relocations out. HTAB is the bfd's 53 elf32_arm_link_hash_entry. */ 54 #define SWAP_RELOC_OUT(HTAB) \ 55 ((HTAB)->use_rel \ 56 ? bfd_elf32_swap_reloc_out \ 57 : bfd_elf32_swap_reloca_out) 58 59 #define elf_info_to_howto 0 60 #define elf_info_to_howto_rel elf32_arm_info_to_howto 61 62 #define ARM_ELF_ABI_VERSION 0 63 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM 64 65 /* The Adjusted Place, as defined by AAELF. */ 66 #define Pa(X) ((X) & 0xfffffffc) 67 68 static bfd_boolean elf32_arm_write_section (bfd *output_bfd, 69 struct bfd_link_info *link_info, 70 asection *sec, 71 bfd_byte *contents); 72 73 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g. 74 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO 75 in that slot. */ 76 77 static reloc_howto_type elf32_arm_howto_table_1[] = 78 { 79 /* No relocation. */ 80 HOWTO (R_ARM_NONE, /* type */ 81 0, /* rightshift */ 82 0, /* size (0 = byte, 1 = short, 2 = long) */ 83 0, /* bitsize */ 84 FALSE, /* pc_relative */ 85 0, /* bitpos */ 86 complain_overflow_dont,/* complain_on_overflow */ 87 bfd_elf_generic_reloc, /* special_function */ 88 "R_ARM_NONE", /* name */ 89 FALSE, /* partial_inplace */ 90 0, /* src_mask */ 91 0, /* dst_mask */ 92 FALSE), /* pcrel_offset */ 93 94 HOWTO (R_ARM_PC24, /* type */ 95 2, /* rightshift */ 96 2, /* size (0 = byte, 1 = short, 2 = long) */ 97 24, /* bitsize */ 98 TRUE, /* pc_relative */ 99 0, /* bitpos */ 100 complain_overflow_signed,/* complain_on_overflow */ 101 bfd_elf_generic_reloc, /* special_function */ 102 "R_ARM_PC24", /* name */ 103 FALSE, /* partial_inplace */ 104 0x00ffffff, /* src_mask */ 105 0x00ffffff, /* dst_mask */ 106 TRUE), /* pcrel_offset */ 107 108 /* 32 bit absolute */ 109 HOWTO (R_ARM_ABS32, /* type */ 110 0, /* rightshift */ 111 2, /* size (0 = byte, 1 = short, 2 = long) */ 112 32, /* bitsize */ 113 FALSE, /* pc_relative */ 114 0, /* bitpos */ 115 complain_overflow_bitfield,/* complain_on_overflow */ 116 bfd_elf_generic_reloc, /* special_function */ 117 "R_ARM_ABS32", /* name */ 118 FALSE, /* partial_inplace */ 119 0xffffffff, /* src_mask */ 120 0xffffffff, /* dst_mask */ 121 FALSE), /* pcrel_offset */ 122 123 /* standard 32bit pc-relative reloc */ 124 HOWTO (R_ARM_REL32, /* type */ 125 0, /* rightshift */ 126 2, /* size (0 = byte, 1 = short, 2 = long) */ 127 32, /* bitsize */ 128 TRUE, /* pc_relative */ 129 0, /* bitpos */ 130 complain_overflow_bitfield,/* complain_on_overflow */ 131 bfd_elf_generic_reloc, /* special_function */ 132 "R_ARM_REL32", /* name */ 133 FALSE, /* partial_inplace */ 134 0xffffffff, /* src_mask */ 135 0xffffffff, /* dst_mask */ 136 TRUE), /* pcrel_offset */ 137 138 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */ 139 HOWTO (R_ARM_LDR_PC_G0, /* type */ 140 0, /* rightshift */ 141 0, /* size (0 = byte, 1 = short, 2 = long) */ 142 32, /* bitsize */ 143 TRUE, /* pc_relative */ 144 0, /* bitpos */ 145 complain_overflow_dont,/* complain_on_overflow */ 146 bfd_elf_generic_reloc, /* special_function */ 147 "R_ARM_LDR_PC_G0", /* name */ 148 FALSE, /* partial_inplace */ 149 0xffffffff, /* src_mask */ 150 0xffffffff, /* dst_mask */ 151 TRUE), /* pcrel_offset */ 152 153 /* 16 bit absolute */ 154 HOWTO (R_ARM_ABS16, /* type */ 155 0, /* rightshift */ 156 1, /* size (0 = byte, 1 = short, 2 = long) */ 157 16, /* bitsize */ 158 FALSE, /* pc_relative */ 159 0, /* bitpos */ 160 complain_overflow_bitfield,/* complain_on_overflow */ 161 bfd_elf_generic_reloc, /* special_function */ 162 "R_ARM_ABS16", /* name */ 163 FALSE, /* partial_inplace */ 164 0x0000ffff, /* src_mask */ 165 0x0000ffff, /* dst_mask */ 166 FALSE), /* pcrel_offset */ 167 168 /* 12 bit absolute */ 169 HOWTO (R_ARM_ABS12, /* type */ 170 0, /* rightshift */ 171 2, /* size (0 = byte, 1 = short, 2 = long) */ 172 12, /* bitsize */ 173 FALSE, /* pc_relative */ 174 0, /* bitpos */ 175 complain_overflow_bitfield,/* complain_on_overflow */ 176 bfd_elf_generic_reloc, /* special_function */ 177 "R_ARM_ABS12", /* name */ 178 FALSE, /* partial_inplace */ 179 0x00000fff, /* src_mask */ 180 0x00000fff, /* dst_mask */ 181 FALSE), /* pcrel_offset */ 182 183 HOWTO (R_ARM_THM_ABS5, /* type */ 184 6, /* rightshift */ 185 1, /* size (0 = byte, 1 = short, 2 = long) */ 186 5, /* bitsize */ 187 FALSE, /* pc_relative */ 188 0, /* bitpos */ 189 complain_overflow_bitfield,/* complain_on_overflow */ 190 bfd_elf_generic_reloc, /* special_function */ 191 "R_ARM_THM_ABS5", /* name */ 192 FALSE, /* partial_inplace */ 193 0x000007e0, /* src_mask */ 194 0x000007e0, /* dst_mask */ 195 FALSE), /* pcrel_offset */ 196 197 /* 8 bit absolute */ 198 HOWTO (R_ARM_ABS8, /* type */ 199 0, /* rightshift */ 200 0, /* size (0 = byte, 1 = short, 2 = long) */ 201 8, /* bitsize */ 202 FALSE, /* pc_relative */ 203 0, /* bitpos */ 204 complain_overflow_bitfield,/* complain_on_overflow */ 205 bfd_elf_generic_reloc, /* special_function */ 206 "R_ARM_ABS8", /* name */ 207 FALSE, /* partial_inplace */ 208 0x000000ff, /* src_mask */ 209 0x000000ff, /* dst_mask */ 210 FALSE), /* pcrel_offset */ 211 212 HOWTO (R_ARM_SBREL32, /* type */ 213 0, /* rightshift */ 214 2, /* size (0 = byte, 1 = short, 2 = long) */ 215 32, /* bitsize */ 216 FALSE, /* pc_relative */ 217 0, /* bitpos */ 218 complain_overflow_dont,/* complain_on_overflow */ 219 bfd_elf_generic_reloc, /* special_function */ 220 "R_ARM_SBREL32", /* name */ 221 FALSE, /* partial_inplace */ 222 0xffffffff, /* src_mask */ 223 0xffffffff, /* dst_mask */ 224 FALSE), /* pcrel_offset */ 225 226 HOWTO (R_ARM_THM_CALL, /* type */ 227 1, /* rightshift */ 228 2, /* size (0 = byte, 1 = short, 2 = long) */ 229 24, /* bitsize */ 230 TRUE, /* pc_relative */ 231 0, /* bitpos */ 232 complain_overflow_signed,/* complain_on_overflow */ 233 bfd_elf_generic_reloc, /* special_function */ 234 "R_ARM_THM_CALL", /* name */ 235 FALSE, /* partial_inplace */ 236 0x07ff2fff, /* src_mask */ 237 0x07ff2fff, /* dst_mask */ 238 TRUE), /* pcrel_offset */ 239 240 HOWTO (R_ARM_THM_PC8, /* type */ 241 1, /* rightshift */ 242 1, /* size (0 = byte, 1 = short, 2 = long) */ 243 8, /* bitsize */ 244 TRUE, /* pc_relative */ 245 0, /* bitpos */ 246 complain_overflow_signed,/* complain_on_overflow */ 247 bfd_elf_generic_reloc, /* special_function */ 248 "R_ARM_THM_PC8", /* name */ 249 FALSE, /* partial_inplace */ 250 0x000000ff, /* src_mask */ 251 0x000000ff, /* dst_mask */ 252 TRUE), /* pcrel_offset */ 253 254 HOWTO (R_ARM_BREL_ADJ, /* type */ 255 1, /* rightshift */ 256 1, /* size (0 = byte, 1 = short, 2 = long) */ 257 32, /* bitsize */ 258 FALSE, /* pc_relative */ 259 0, /* bitpos */ 260 complain_overflow_signed,/* complain_on_overflow */ 261 bfd_elf_generic_reloc, /* special_function */ 262 "R_ARM_BREL_ADJ", /* name */ 263 FALSE, /* partial_inplace */ 264 0xffffffff, /* src_mask */ 265 0xffffffff, /* dst_mask */ 266 FALSE), /* pcrel_offset */ 267 268 HOWTO (R_ARM_TLS_DESC, /* type */ 269 0, /* rightshift */ 270 2, /* size (0 = byte, 1 = short, 2 = long) */ 271 32, /* bitsize */ 272 FALSE, /* pc_relative */ 273 0, /* bitpos */ 274 complain_overflow_bitfield,/* complain_on_overflow */ 275 bfd_elf_generic_reloc, /* special_function */ 276 "R_ARM_TLS_DESC", /* name */ 277 FALSE, /* partial_inplace */ 278 0xffffffff, /* src_mask */ 279 0xffffffff, /* dst_mask */ 280 FALSE), /* pcrel_offset */ 281 282 HOWTO (R_ARM_THM_SWI8, /* type */ 283 0, /* rightshift */ 284 0, /* size (0 = byte, 1 = short, 2 = long) */ 285 0, /* bitsize */ 286 FALSE, /* pc_relative */ 287 0, /* bitpos */ 288 complain_overflow_signed,/* complain_on_overflow */ 289 bfd_elf_generic_reloc, /* special_function */ 290 "R_ARM_SWI8", /* name */ 291 FALSE, /* partial_inplace */ 292 0x00000000, /* src_mask */ 293 0x00000000, /* dst_mask */ 294 FALSE), /* pcrel_offset */ 295 296 /* BLX instruction for the ARM. */ 297 HOWTO (R_ARM_XPC25, /* type */ 298 2, /* rightshift */ 299 2, /* size (0 = byte, 1 = short, 2 = long) */ 300 24, /* bitsize */ 301 TRUE, /* pc_relative */ 302 0, /* bitpos */ 303 complain_overflow_signed,/* complain_on_overflow */ 304 bfd_elf_generic_reloc, /* special_function */ 305 "R_ARM_XPC25", /* name */ 306 FALSE, /* partial_inplace */ 307 0x00ffffff, /* src_mask */ 308 0x00ffffff, /* dst_mask */ 309 TRUE), /* pcrel_offset */ 310 311 /* BLX instruction for the Thumb. */ 312 HOWTO (R_ARM_THM_XPC22, /* type */ 313 2, /* rightshift */ 314 2, /* size (0 = byte, 1 = short, 2 = long) */ 315 24, /* bitsize */ 316 TRUE, /* pc_relative */ 317 0, /* bitpos */ 318 complain_overflow_signed,/* complain_on_overflow */ 319 bfd_elf_generic_reloc, /* special_function */ 320 "R_ARM_THM_XPC22", /* name */ 321 FALSE, /* partial_inplace */ 322 0x07ff2fff, /* src_mask */ 323 0x07ff2fff, /* dst_mask */ 324 TRUE), /* pcrel_offset */ 325 326 /* Dynamic TLS relocations. */ 327 328 HOWTO (R_ARM_TLS_DTPMOD32, /* type */ 329 0, /* rightshift */ 330 2, /* size (0 = byte, 1 = short, 2 = long) */ 331 32, /* bitsize */ 332 FALSE, /* pc_relative */ 333 0, /* bitpos */ 334 complain_overflow_bitfield,/* complain_on_overflow */ 335 bfd_elf_generic_reloc, /* special_function */ 336 "R_ARM_TLS_DTPMOD32", /* name */ 337 TRUE, /* partial_inplace */ 338 0xffffffff, /* src_mask */ 339 0xffffffff, /* dst_mask */ 340 FALSE), /* pcrel_offset */ 341 342 HOWTO (R_ARM_TLS_DTPOFF32, /* type */ 343 0, /* rightshift */ 344 2, /* size (0 = byte, 1 = short, 2 = long) */ 345 32, /* bitsize */ 346 FALSE, /* pc_relative */ 347 0, /* bitpos */ 348 complain_overflow_bitfield,/* complain_on_overflow */ 349 bfd_elf_generic_reloc, /* special_function */ 350 "R_ARM_TLS_DTPOFF32", /* name */ 351 TRUE, /* partial_inplace */ 352 0xffffffff, /* src_mask */ 353 0xffffffff, /* dst_mask */ 354 FALSE), /* pcrel_offset */ 355 356 HOWTO (R_ARM_TLS_TPOFF32, /* type */ 357 0, /* rightshift */ 358 2, /* size (0 = byte, 1 = short, 2 = long) */ 359 32, /* bitsize */ 360 FALSE, /* pc_relative */ 361 0, /* bitpos */ 362 complain_overflow_bitfield,/* complain_on_overflow */ 363 bfd_elf_generic_reloc, /* special_function */ 364 "R_ARM_TLS_TPOFF32", /* name */ 365 TRUE, /* partial_inplace */ 366 0xffffffff, /* src_mask */ 367 0xffffffff, /* dst_mask */ 368 FALSE), /* pcrel_offset */ 369 370 /* Relocs used in ARM Linux */ 371 372 HOWTO (R_ARM_COPY, /* type */ 373 0, /* rightshift */ 374 2, /* size (0 = byte, 1 = short, 2 = long) */ 375 32, /* bitsize */ 376 FALSE, /* pc_relative */ 377 0, /* bitpos */ 378 complain_overflow_bitfield,/* complain_on_overflow */ 379 bfd_elf_generic_reloc, /* special_function */ 380 "R_ARM_COPY", /* name */ 381 TRUE, /* partial_inplace */ 382 0xffffffff, /* src_mask */ 383 0xffffffff, /* dst_mask */ 384 FALSE), /* pcrel_offset */ 385 386 HOWTO (R_ARM_GLOB_DAT, /* type */ 387 0, /* rightshift */ 388 2, /* size (0 = byte, 1 = short, 2 = long) */ 389 32, /* bitsize */ 390 FALSE, /* pc_relative */ 391 0, /* bitpos */ 392 complain_overflow_bitfield,/* complain_on_overflow */ 393 bfd_elf_generic_reloc, /* special_function */ 394 "R_ARM_GLOB_DAT", /* name */ 395 TRUE, /* partial_inplace */ 396 0xffffffff, /* src_mask */ 397 0xffffffff, /* dst_mask */ 398 FALSE), /* pcrel_offset */ 399 400 HOWTO (R_ARM_JUMP_SLOT, /* type */ 401 0, /* rightshift */ 402 2, /* size (0 = byte, 1 = short, 2 = long) */ 403 32, /* bitsize */ 404 FALSE, /* pc_relative */ 405 0, /* bitpos */ 406 complain_overflow_bitfield,/* complain_on_overflow */ 407 bfd_elf_generic_reloc, /* special_function */ 408 "R_ARM_JUMP_SLOT", /* name */ 409 TRUE, /* partial_inplace */ 410 0xffffffff, /* src_mask */ 411 0xffffffff, /* dst_mask */ 412 FALSE), /* pcrel_offset */ 413 414 HOWTO (R_ARM_RELATIVE, /* type */ 415 0, /* rightshift */ 416 2, /* size (0 = byte, 1 = short, 2 = long) */ 417 32, /* bitsize */ 418 FALSE, /* pc_relative */ 419 0, /* bitpos */ 420 complain_overflow_bitfield,/* complain_on_overflow */ 421 bfd_elf_generic_reloc, /* special_function */ 422 "R_ARM_RELATIVE", /* name */ 423 TRUE, /* partial_inplace */ 424 0xffffffff, /* src_mask */ 425 0xffffffff, /* dst_mask */ 426 FALSE), /* pcrel_offset */ 427 428 HOWTO (R_ARM_GOTOFF32, /* type */ 429 0, /* rightshift */ 430 2, /* size (0 = byte, 1 = short, 2 = long) */ 431 32, /* bitsize */ 432 FALSE, /* pc_relative */ 433 0, /* bitpos */ 434 complain_overflow_bitfield,/* complain_on_overflow */ 435 bfd_elf_generic_reloc, /* special_function */ 436 "R_ARM_GOTOFF32", /* name */ 437 TRUE, /* partial_inplace */ 438 0xffffffff, /* src_mask */ 439 0xffffffff, /* dst_mask */ 440 FALSE), /* pcrel_offset */ 441 442 HOWTO (R_ARM_GOTPC, /* type */ 443 0, /* rightshift */ 444 2, /* size (0 = byte, 1 = short, 2 = long) */ 445 32, /* bitsize */ 446 TRUE, /* pc_relative */ 447 0, /* bitpos */ 448 complain_overflow_bitfield,/* complain_on_overflow */ 449 bfd_elf_generic_reloc, /* special_function */ 450 "R_ARM_GOTPC", /* name */ 451 TRUE, /* partial_inplace */ 452 0xffffffff, /* src_mask */ 453 0xffffffff, /* dst_mask */ 454 TRUE), /* pcrel_offset */ 455 456 HOWTO (R_ARM_GOT32, /* type */ 457 0, /* rightshift */ 458 2, /* size (0 = byte, 1 = short, 2 = long) */ 459 32, /* bitsize */ 460 FALSE, /* pc_relative */ 461 0, /* bitpos */ 462 complain_overflow_bitfield,/* complain_on_overflow */ 463 bfd_elf_generic_reloc, /* special_function */ 464 "R_ARM_GOT32", /* name */ 465 TRUE, /* partial_inplace */ 466 0xffffffff, /* src_mask */ 467 0xffffffff, /* dst_mask */ 468 FALSE), /* pcrel_offset */ 469 470 HOWTO (R_ARM_PLT32, /* type */ 471 2, /* rightshift */ 472 2, /* size (0 = byte, 1 = short, 2 = long) */ 473 24, /* bitsize */ 474 TRUE, /* pc_relative */ 475 0, /* bitpos */ 476 complain_overflow_bitfield,/* complain_on_overflow */ 477 bfd_elf_generic_reloc, /* special_function */ 478 "R_ARM_PLT32", /* name */ 479 FALSE, /* partial_inplace */ 480 0x00ffffff, /* src_mask */ 481 0x00ffffff, /* dst_mask */ 482 TRUE), /* pcrel_offset */ 483 484 HOWTO (R_ARM_CALL, /* type */ 485 2, /* rightshift */ 486 2, /* size (0 = byte, 1 = short, 2 = long) */ 487 24, /* bitsize */ 488 TRUE, /* pc_relative */ 489 0, /* bitpos */ 490 complain_overflow_signed,/* complain_on_overflow */ 491 bfd_elf_generic_reloc, /* special_function */ 492 "R_ARM_CALL", /* name */ 493 FALSE, /* partial_inplace */ 494 0x00ffffff, /* src_mask */ 495 0x00ffffff, /* dst_mask */ 496 TRUE), /* pcrel_offset */ 497 498 HOWTO (R_ARM_JUMP24, /* type */ 499 2, /* rightshift */ 500 2, /* size (0 = byte, 1 = short, 2 = long) */ 501 24, /* bitsize */ 502 TRUE, /* pc_relative */ 503 0, /* bitpos */ 504 complain_overflow_signed,/* complain_on_overflow */ 505 bfd_elf_generic_reloc, /* special_function */ 506 "R_ARM_JUMP24", /* name */ 507 FALSE, /* partial_inplace */ 508 0x00ffffff, /* src_mask */ 509 0x00ffffff, /* dst_mask */ 510 TRUE), /* pcrel_offset */ 511 512 HOWTO (R_ARM_THM_JUMP24, /* type */ 513 1, /* rightshift */ 514 2, /* size (0 = byte, 1 = short, 2 = long) */ 515 24, /* bitsize */ 516 TRUE, /* pc_relative */ 517 0, /* bitpos */ 518 complain_overflow_signed,/* complain_on_overflow */ 519 bfd_elf_generic_reloc, /* special_function */ 520 "R_ARM_THM_JUMP24", /* name */ 521 FALSE, /* partial_inplace */ 522 0x07ff2fff, /* src_mask */ 523 0x07ff2fff, /* dst_mask */ 524 TRUE), /* pcrel_offset */ 525 526 HOWTO (R_ARM_BASE_ABS, /* type */ 527 0, /* rightshift */ 528 2, /* size (0 = byte, 1 = short, 2 = long) */ 529 32, /* bitsize */ 530 FALSE, /* pc_relative */ 531 0, /* bitpos */ 532 complain_overflow_dont,/* complain_on_overflow */ 533 bfd_elf_generic_reloc, /* special_function */ 534 "R_ARM_BASE_ABS", /* name */ 535 FALSE, /* partial_inplace */ 536 0xffffffff, /* src_mask */ 537 0xffffffff, /* dst_mask */ 538 FALSE), /* pcrel_offset */ 539 540 HOWTO (R_ARM_ALU_PCREL7_0, /* type */ 541 0, /* rightshift */ 542 2, /* size (0 = byte, 1 = short, 2 = long) */ 543 12, /* bitsize */ 544 TRUE, /* pc_relative */ 545 0, /* bitpos */ 546 complain_overflow_dont,/* complain_on_overflow */ 547 bfd_elf_generic_reloc, /* special_function */ 548 "R_ARM_ALU_PCREL_7_0", /* name */ 549 FALSE, /* partial_inplace */ 550 0x00000fff, /* src_mask */ 551 0x00000fff, /* dst_mask */ 552 TRUE), /* pcrel_offset */ 553 554 HOWTO (R_ARM_ALU_PCREL15_8, /* type */ 555 0, /* rightshift */ 556 2, /* size (0 = byte, 1 = short, 2 = long) */ 557 12, /* bitsize */ 558 TRUE, /* pc_relative */ 559 8, /* bitpos */ 560 complain_overflow_dont,/* complain_on_overflow */ 561 bfd_elf_generic_reloc, /* special_function */ 562 "R_ARM_ALU_PCREL_15_8",/* name */ 563 FALSE, /* partial_inplace */ 564 0x00000fff, /* src_mask */ 565 0x00000fff, /* dst_mask */ 566 TRUE), /* pcrel_offset */ 567 568 HOWTO (R_ARM_ALU_PCREL23_15, /* type */ 569 0, /* rightshift */ 570 2, /* size (0 = byte, 1 = short, 2 = long) */ 571 12, /* bitsize */ 572 TRUE, /* pc_relative */ 573 16, /* bitpos */ 574 complain_overflow_dont,/* complain_on_overflow */ 575 bfd_elf_generic_reloc, /* special_function */ 576 "R_ARM_ALU_PCREL_23_15",/* name */ 577 FALSE, /* partial_inplace */ 578 0x00000fff, /* src_mask */ 579 0x00000fff, /* dst_mask */ 580 TRUE), /* pcrel_offset */ 581 582 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */ 583 0, /* rightshift */ 584 2, /* size (0 = byte, 1 = short, 2 = long) */ 585 12, /* bitsize */ 586 FALSE, /* pc_relative */ 587 0, /* bitpos */ 588 complain_overflow_dont,/* complain_on_overflow */ 589 bfd_elf_generic_reloc, /* special_function */ 590 "R_ARM_LDR_SBREL_11_0",/* name */ 591 FALSE, /* partial_inplace */ 592 0x00000fff, /* src_mask */ 593 0x00000fff, /* dst_mask */ 594 FALSE), /* pcrel_offset */ 595 596 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */ 597 0, /* rightshift */ 598 2, /* size (0 = byte, 1 = short, 2 = long) */ 599 8, /* bitsize */ 600 FALSE, /* pc_relative */ 601 12, /* bitpos */ 602 complain_overflow_dont,/* complain_on_overflow */ 603 bfd_elf_generic_reloc, /* special_function */ 604 "R_ARM_ALU_SBREL_19_12",/* name */ 605 FALSE, /* partial_inplace */ 606 0x000ff000, /* src_mask */ 607 0x000ff000, /* dst_mask */ 608 FALSE), /* pcrel_offset */ 609 610 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */ 611 0, /* rightshift */ 612 2, /* size (0 = byte, 1 = short, 2 = long) */ 613 8, /* bitsize */ 614 FALSE, /* pc_relative */ 615 20, /* bitpos */ 616 complain_overflow_dont,/* complain_on_overflow */ 617 bfd_elf_generic_reloc, /* special_function */ 618 "R_ARM_ALU_SBREL_27_20",/* name */ 619 FALSE, /* partial_inplace */ 620 0x0ff00000, /* src_mask */ 621 0x0ff00000, /* dst_mask */ 622 FALSE), /* pcrel_offset */ 623 624 HOWTO (R_ARM_TARGET1, /* type */ 625 0, /* rightshift */ 626 2, /* size (0 = byte, 1 = short, 2 = long) */ 627 32, /* bitsize */ 628 FALSE, /* pc_relative */ 629 0, /* bitpos */ 630 complain_overflow_dont,/* complain_on_overflow */ 631 bfd_elf_generic_reloc, /* special_function */ 632 "R_ARM_TARGET1", /* name */ 633 FALSE, /* partial_inplace */ 634 0xffffffff, /* src_mask */ 635 0xffffffff, /* dst_mask */ 636 FALSE), /* pcrel_offset */ 637 638 HOWTO (R_ARM_ROSEGREL32, /* type */ 639 0, /* rightshift */ 640 2, /* size (0 = byte, 1 = short, 2 = long) */ 641 32, /* bitsize */ 642 FALSE, /* pc_relative */ 643 0, /* bitpos */ 644 complain_overflow_dont,/* complain_on_overflow */ 645 bfd_elf_generic_reloc, /* special_function */ 646 "R_ARM_ROSEGREL32", /* name */ 647 FALSE, /* partial_inplace */ 648 0xffffffff, /* src_mask */ 649 0xffffffff, /* dst_mask */ 650 FALSE), /* pcrel_offset */ 651 652 HOWTO (R_ARM_V4BX, /* type */ 653 0, /* rightshift */ 654 2, /* size (0 = byte, 1 = short, 2 = long) */ 655 32, /* bitsize */ 656 FALSE, /* pc_relative */ 657 0, /* bitpos */ 658 complain_overflow_dont,/* complain_on_overflow */ 659 bfd_elf_generic_reloc, /* special_function */ 660 "R_ARM_V4BX", /* name */ 661 FALSE, /* partial_inplace */ 662 0xffffffff, /* src_mask */ 663 0xffffffff, /* dst_mask */ 664 FALSE), /* pcrel_offset */ 665 666 HOWTO (R_ARM_TARGET2, /* type */ 667 0, /* rightshift */ 668 2, /* size (0 = byte, 1 = short, 2 = long) */ 669 32, /* bitsize */ 670 FALSE, /* pc_relative */ 671 0, /* bitpos */ 672 complain_overflow_signed,/* complain_on_overflow */ 673 bfd_elf_generic_reloc, /* special_function */ 674 "R_ARM_TARGET2", /* name */ 675 FALSE, /* partial_inplace */ 676 0xffffffff, /* src_mask */ 677 0xffffffff, /* dst_mask */ 678 TRUE), /* pcrel_offset */ 679 680 HOWTO (R_ARM_PREL31, /* type */ 681 0, /* rightshift */ 682 2, /* size (0 = byte, 1 = short, 2 = long) */ 683 31, /* bitsize */ 684 TRUE, /* pc_relative */ 685 0, /* bitpos */ 686 complain_overflow_signed,/* complain_on_overflow */ 687 bfd_elf_generic_reloc, /* special_function */ 688 "R_ARM_PREL31", /* name */ 689 FALSE, /* partial_inplace */ 690 0x7fffffff, /* src_mask */ 691 0x7fffffff, /* dst_mask */ 692 TRUE), /* pcrel_offset */ 693 694 HOWTO (R_ARM_MOVW_ABS_NC, /* type */ 695 0, /* rightshift */ 696 2, /* size (0 = byte, 1 = short, 2 = long) */ 697 16, /* bitsize */ 698 FALSE, /* pc_relative */ 699 0, /* bitpos */ 700 complain_overflow_dont,/* complain_on_overflow */ 701 bfd_elf_generic_reloc, /* special_function */ 702 "R_ARM_MOVW_ABS_NC", /* name */ 703 FALSE, /* partial_inplace */ 704 0x000f0fff, /* src_mask */ 705 0x000f0fff, /* dst_mask */ 706 FALSE), /* pcrel_offset */ 707 708 HOWTO (R_ARM_MOVT_ABS, /* type */ 709 0, /* rightshift */ 710 2, /* size (0 = byte, 1 = short, 2 = long) */ 711 16, /* bitsize */ 712 FALSE, /* pc_relative */ 713 0, /* bitpos */ 714 complain_overflow_bitfield,/* complain_on_overflow */ 715 bfd_elf_generic_reloc, /* special_function */ 716 "R_ARM_MOVT_ABS", /* name */ 717 FALSE, /* partial_inplace */ 718 0x000f0fff, /* src_mask */ 719 0x000f0fff, /* dst_mask */ 720 FALSE), /* pcrel_offset */ 721 722 HOWTO (R_ARM_MOVW_PREL_NC, /* type */ 723 0, /* rightshift */ 724 2, /* size (0 = byte, 1 = short, 2 = long) */ 725 16, /* bitsize */ 726 TRUE, /* pc_relative */ 727 0, /* bitpos */ 728 complain_overflow_dont,/* complain_on_overflow */ 729 bfd_elf_generic_reloc, /* special_function */ 730 "R_ARM_MOVW_PREL_NC", /* name */ 731 FALSE, /* partial_inplace */ 732 0x000f0fff, /* src_mask */ 733 0x000f0fff, /* dst_mask */ 734 TRUE), /* pcrel_offset */ 735 736 HOWTO (R_ARM_MOVT_PREL, /* type */ 737 0, /* rightshift */ 738 2, /* size (0 = byte, 1 = short, 2 = long) */ 739 16, /* bitsize */ 740 TRUE, /* pc_relative */ 741 0, /* bitpos */ 742 complain_overflow_bitfield,/* complain_on_overflow */ 743 bfd_elf_generic_reloc, /* special_function */ 744 "R_ARM_MOVT_PREL", /* name */ 745 FALSE, /* partial_inplace */ 746 0x000f0fff, /* src_mask */ 747 0x000f0fff, /* dst_mask */ 748 TRUE), /* pcrel_offset */ 749 750 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */ 751 0, /* rightshift */ 752 2, /* size (0 = byte, 1 = short, 2 = long) */ 753 16, /* bitsize */ 754 FALSE, /* pc_relative */ 755 0, /* bitpos */ 756 complain_overflow_dont,/* complain_on_overflow */ 757 bfd_elf_generic_reloc, /* special_function */ 758 "R_ARM_THM_MOVW_ABS_NC",/* name */ 759 FALSE, /* partial_inplace */ 760 0x040f70ff, /* src_mask */ 761 0x040f70ff, /* dst_mask */ 762 FALSE), /* pcrel_offset */ 763 764 HOWTO (R_ARM_THM_MOVT_ABS, /* type */ 765 0, /* rightshift */ 766 2, /* size (0 = byte, 1 = short, 2 = long) */ 767 16, /* bitsize */ 768 FALSE, /* pc_relative */ 769 0, /* bitpos */ 770 complain_overflow_bitfield,/* complain_on_overflow */ 771 bfd_elf_generic_reloc, /* special_function */ 772 "R_ARM_THM_MOVT_ABS", /* name */ 773 FALSE, /* partial_inplace */ 774 0x040f70ff, /* src_mask */ 775 0x040f70ff, /* dst_mask */ 776 FALSE), /* pcrel_offset */ 777 778 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */ 779 0, /* rightshift */ 780 2, /* size (0 = byte, 1 = short, 2 = long) */ 781 16, /* bitsize */ 782 TRUE, /* pc_relative */ 783 0, /* bitpos */ 784 complain_overflow_dont,/* complain_on_overflow */ 785 bfd_elf_generic_reloc, /* special_function */ 786 "R_ARM_THM_MOVW_PREL_NC",/* name */ 787 FALSE, /* partial_inplace */ 788 0x040f70ff, /* src_mask */ 789 0x040f70ff, /* dst_mask */ 790 TRUE), /* pcrel_offset */ 791 792 HOWTO (R_ARM_THM_MOVT_PREL, /* type */ 793 0, /* rightshift */ 794 2, /* size (0 = byte, 1 = short, 2 = long) */ 795 16, /* bitsize */ 796 TRUE, /* pc_relative */ 797 0, /* bitpos */ 798 complain_overflow_bitfield,/* complain_on_overflow */ 799 bfd_elf_generic_reloc, /* special_function */ 800 "R_ARM_THM_MOVT_PREL", /* name */ 801 FALSE, /* partial_inplace */ 802 0x040f70ff, /* src_mask */ 803 0x040f70ff, /* dst_mask */ 804 TRUE), /* pcrel_offset */ 805 806 HOWTO (R_ARM_THM_JUMP19, /* type */ 807 1, /* rightshift */ 808 2, /* size (0 = byte, 1 = short, 2 = long) */ 809 19, /* bitsize */ 810 TRUE, /* pc_relative */ 811 0, /* bitpos */ 812 complain_overflow_signed,/* complain_on_overflow */ 813 bfd_elf_generic_reloc, /* special_function */ 814 "R_ARM_THM_JUMP19", /* name */ 815 FALSE, /* partial_inplace */ 816 0x043f2fff, /* src_mask */ 817 0x043f2fff, /* dst_mask */ 818 TRUE), /* pcrel_offset */ 819 820 HOWTO (R_ARM_THM_JUMP6, /* type */ 821 1, /* rightshift */ 822 1, /* size (0 = byte, 1 = short, 2 = long) */ 823 6, /* bitsize */ 824 TRUE, /* pc_relative */ 825 0, /* bitpos */ 826 complain_overflow_unsigned,/* complain_on_overflow */ 827 bfd_elf_generic_reloc, /* special_function */ 828 "R_ARM_THM_JUMP6", /* name */ 829 FALSE, /* partial_inplace */ 830 0x02f8, /* src_mask */ 831 0x02f8, /* dst_mask */ 832 TRUE), /* pcrel_offset */ 833 834 /* These are declared as 13-bit signed relocations because we can 835 address -4095 .. 4095(base) by altering ADDW to SUBW or vice 836 versa. */ 837 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */ 838 0, /* rightshift */ 839 2, /* size (0 = byte, 1 = short, 2 = long) */ 840 13, /* bitsize */ 841 TRUE, /* pc_relative */ 842 0, /* bitpos */ 843 complain_overflow_dont,/* complain_on_overflow */ 844 bfd_elf_generic_reloc, /* special_function */ 845 "R_ARM_THM_ALU_PREL_11_0",/* name */ 846 FALSE, /* partial_inplace */ 847 0xffffffff, /* src_mask */ 848 0xffffffff, /* dst_mask */ 849 TRUE), /* pcrel_offset */ 850 851 HOWTO (R_ARM_THM_PC12, /* type */ 852 0, /* rightshift */ 853 2, /* size (0 = byte, 1 = short, 2 = long) */ 854 13, /* bitsize */ 855 TRUE, /* pc_relative */ 856 0, /* bitpos */ 857 complain_overflow_dont,/* complain_on_overflow */ 858 bfd_elf_generic_reloc, /* special_function */ 859 "R_ARM_THM_PC12", /* name */ 860 FALSE, /* partial_inplace */ 861 0xffffffff, /* src_mask */ 862 0xffffffff, /* dst_mask */ 863 TRUE), /* pcrel_offset */ 864 865 HOWTO (R_ARM_ABS32_NOI, /* type */ 866 0, /* rightshift */ 867 2, /* size (0 = byte, 1 = short, 2 = long) */ 868 32, /* bitsize */ 869 FALSE, /* pc_relative */ 870 0, /* bitpos */ 871 complain_overflow_dont,/* complain_on_overflow */ 872 bfd_elf_generic_reloc, /* special_function */ 873 "R_ARM_ABS32_NOI", /* name */ 874 FALSE, /* partial_inplace */ 875 0xffffffff, /* src_mask */ 876 0xffffffff, /* dst_mask */ 877 FALSE), /* pcrel_offset */ 878 879 HOWTO (R_ARM_REL32_NOI, /* type */ 880 0, /* rightshift */ 881 2, /* size (0 = byte, 1 = short, 2 = long) */ 882 32, /* bitsize */ 883 TRUE, /* pc_relative */ 884 0, /* bitpos */ 885 complain_overflow_dont,/* complain_on_overflow */ 886 bfd_elf_generic_reloc, /* special_function */ 887 "R_ARM_REL32_NOI", /* name */ 888 FALSE, /* partial_inplace */ 889 0xffffffff, /* src_mask */ 890 0xffffffff, /* dst_mask */ 891 FALSE), /* pcrel_offset */ 892 893 /* Group relocations. */ 894 895 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */ 896 0, /* rightshift */ 897 2, /* size (0 = byte, 1 = short, 2 = long) */ 898 32, /* bitsize */ 899 TRUE, /* pc_relative */ 900 0, /* bitpos */ 901 complain_overflow_dont,/* complain_on_overflow */ 902 bfd_elf_generic_reloc, /* special_function */ 903 "R_ARM_ALU_PC_G0_NC", /* name */ 904 FALSE, /* partial_inplace */ 905 0xffffffff, /* src_mask */ 906 0xffffffff, /* dst_mask */ 907 TRUE), /* pcrel_offset */ 908 909 HOWTO (R_ARM_ALU_PC_G0, /* type */ 910 0, /* rightshift */ 911 2, /* size (0 = byte, 1 = short, 2 = long) */ 912 32, /* bitsize */ 913 TRUE, /* pc_relative */ 914 0, /* bitpos */ 915 complain_overflow_dont,/* complain_on_overflow */ 916 bfd_elf_generic_reloc, /* special_function */ 917 "R_ARM_ALU_PC_G0", /* name */ 918 FALSE, /* partial_inplace */ 919 0xffffffff, /* src_mask */ 920 0xffffffff, /* dst_mask */ 921 TRUE), /* pcrel_offset */ 922 923 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */ 924 0, /* rightshift */ 925 2, /* size (0 = byte, 1 = short, 2 = long) */ 926 32, /* bitsize */ 927 TRUE, /* pc_relative */ 928 0, /* bitpos */ 929 complain_overflow_dont,/* complain_on_overflow */ 930 bfd_elf_generic_reloc, /* special_function */ 931 "R_ARM_ALU_PC_G1_NC", /* name */ 932 FALSE, /* partial_inplace */ 933 0xffffffff, /* src_mask */ 934 0xffffffff, /* dst_mask */ 935 TRUE), /* pcrel_offset */ 936 937 HOWTO (R_ARM_ALU_PC_G1, /* type */ 938 0, /* rightshift */ 939 2, /* size (0 = byte, 1 = short, 2 = long) */ 940 32, /* bitsize */ 941 TRUE, /* pc_relative */ 942 0, /* bitpos */ 943 complain_overflow_dont,/* complain_on_overflow */ 944 bfd_elf_generic_reloc, /* special_function */ 945 "R_ARM_ALU_PC_G1", /* name */ 946 FALSE, /* partial_inplace */ 947 0xffffffff, /* src_mask */ 948 0xffffffff, /* dst_mask */ 949 TRUE), /* pcrel_offset */ 950 951 HOWTO (R_ARM_ALU_PC_G2, /* type */ 952 0, /* rightshift */ 953 2, /* size (0 = byte, 1 = short, 2 = long) */ 954 32, /* bitsize */ 955 TRUE, /* pc_relative */ 956 0, /* bitpos */ 957 complain_overflow_dont,/* complain_on_overflow */ 958 bfd_elf_generic_reloc, /* special_function */ 959 "R_ARM_ALU_PC_G2", /* name */ 960 FALSE, /* partial_inplace */ 961 0xffffffff, /* src_mask */ 962 0xffffffff, /* dst_mask */ 963 TRUE), /* pcrel_offset */ 964 965 HOWTO (R_ARM_LDR_PC_G1, /* type */ 966 0, /* rightshift */ 967 2, /* size (0 = byte, 1 = short, 2 = long) */ 968 32, /* bitsize */ 969 TRUE, /* pc_relative */ 970 0, /* bitpos */ 971 complain_overflow_dont,/* complain_on_overflow */ 972 bfd_elf_generic_reloc, /* special_function */ 973 "R_ARM_LDR_PC_G1", /* name */ 974 FALSE, /* partial_inplace */ 975 0xffffffff, /* src_mask */ 976 0xffffffff, /* dst_mask */ 977 TRUE), /* pcrel_offset */ 978 979 HOWTO (R_ARM_LDR_PC_G2, /* type */ 980 0, /* rightshift */ 981 2, /* size (0 = byte, 1 = short, 2 = long) */ 982 32, /* bitsize */ 983 TRUE, /* pc_relative */ 984 0, /* bitpos */ 985 complain_overflow_dont,/* complain_on_overflow */ 986 bfd_elf_generic_reloc, /* special_function */ 987 "R_ARM_LDR_PC_G2", /* name */ 988 FALSE, /* partial_inplace */ 989 0xffffffff, /* src_mask */ 990 0xffffffff, /* dst_mask */ 991 TRUE), /* pcrel_offset */ 992 993 HOWTO (R_ARM_LDRS_PC_G0, /* type */ 994 0, /* rightshift */ 995 2, /* size (0 = byte, 1 = short, 2 = long) */ 996 32, /* bitsize */ 997 TRUE, /* pc_relative */ 998 0, /* bitpos */ 999 complain_overflow_dont,/* complain_on_overflow */ 1000 bfd_elf_generic_reloc, /* special_function */ 1001 "R_ARM_LDRS_PC_G0", /* name */ 1002 FALSE, /* partial_inplace */ 1003 0xffffffff, /* src_mask */ 1004 0xffffffff, /* dst_mask */ 1005 TRUE), /* pcrel_offset */ 1006 1007 HOWTO (R_ARM_LDRS_PC_G1, /* type */ 1008 0, /* rightshift */ 1009 2, /* size (0 = byte, 1 = short, 2 = long) */ 1010 32, /* bitsize */ 1011 TRUE, /* pc_relative */ 1012 0, /* bitpos */ 1013 complain_overflow_dont,/* complain_on_overflow */ 1014 bfd_elf_generic_reloc, /* special_function */ 1015 "R_ARM_LDRS_PC_G1", /* name */ 1016 FALSE, /* partial_inplace */ 1017 0xffffffff, /* src_mask */ 1018 0xffffffff, /* dst_mask */ 1019 TRUE), /* pcrel_offset */ 1020 1021 HOWTO (R_ARM_LDRS_PC_G2, /* type */ 1022 0, /* rightshift */ 1023 2, /* size (0 = byte, 1 = short, 2 = long) */ 1024 32, /* bitsize */ 1025 TRUE, /* pc_relative */ 1026 0, /* bitpos */ 1027 complain_overflow_dont,/* complain_on_overflow */ 1028 bfd_elf_generic_reloc, /* special_function */ 1029 "R_ARM_LDRS_PC_G2", /* name */ 1030 FALSE, /* partial_inplace */ 1031 0xffffffff, /* src_mask */ 1032 0xffffffff, /* dst_mask */ 1033 TRUE), /* pcrel_offset */ 1034 1035 HOWTO (R_ARM_LDC_PC_G0, /* type */ 1036 0, /* rightshift */ 1037 2, /* size (0 = byte, 1 = short, 2 = long) */ 1038 32, /* bitsize */ 1039 TRUE, /* pc_relative */ 1040 0, /* bitpos */ 1041 complain_overflow_dont,/* complain_on_overflow */ 1042 bfd_elf_generic_reloc, /* special_function */ 1043 "R_ARM_LDC_PC_G0", /* name */ 1044 FALSE, /* partial_inplace */ 1045 0xffffffff, /* src_mask */ 1046 0xffffffff, /* dst_mask */ 1047 TRUE), /* pcrel_offset */ 1048 1049 HOWTO (R_ARM_LDC_PC_G1, /* type */ 1050 0, /* rightshift */ 1051 2, /* size (0 = byte, 1 = short, 2 = long) */ 1052 32, /* bitsize */ 1053 TRUE, /* pc_relative */ 1054 0, /* bitpos */ 1055 complain_overflow_dont,/* complain_on_overflow */ 1056 bfd_elf_generic_reloc, /* special_function */ 1057 "R_ARM_LDC_PC_G1", /* name */ 1058 FALSE, /* partial_inplace */ 1059 0xffffffff, /* src_mask */ 1060 0xffffffff, /* dst_mask */ 1061 TRUE), /* pcrel_offset */ 1062 1063 HOWTO (R_ARM_LDC_PC_G2, /* type */ 1064 0, /* rightshift */ 1065 2, /* size (0 = byte, 1 = short, 2 = long) */ 1066 32, /* bitsize */ 1067 TRUE, /* pc_relative */ 1068 0, /* bitpos */ 1069 complain_overflow_dont,/* complain_on_overflow */ 1070 bfd_elf_generic_reloc, /* special_function */ 1071 "R_ARM_LDC_PC_G2", /* name */ 1072 FALSE, /* partial_inplace */ 1073 0xffffffff, /* src_mask */ 1074 0xffffffff, /* dst_mask */ 1075 TRUE), /* pcrel_offset */ 1076 1077 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */ 1078 0, /* rightshift */ 1079 2, /* size (0 = byte, 1 = short, 2 = long) */ 1080 32, /* bitsize */ 1081 TRUE, /* pc_relative */ 1082 0, /* bitpos */ 1083 complain_overflow_dont,/* complain_on_overflow */ 1084 bfd_elf_generic_reloc, /* special_function */ 1085 "R_ARM_ALU_SB_G0_NC", /* name */ 1086 FALSE, /* partial_inplace */ 1087 0xffffffff, /* src_mask */ 1088 0xffffffff, /* dst_mask */ 1089 TRUE), /* pcrel_offset */ 1090 1091 HOWTO (R_ARM_ALU_SB_G0, /* type */ 1092 0, /* rightshift */ 1093 2, /* size (0 = byte, 1 = short, 2 = long) */ 1094 32, /* bitsize */ 1095 TRUE, /* pc_relative */ 1096 0, /* bitpos */ 1097 complain_overflow_dont,/* complain_on_overflow */ 1098 bfd_elf_generic_reloc, /* special_function */ 1099 "R_ARM_ALU_SB_G0", /* name */ 1100 FALSE, /* partial_inplace */ 1101 0xffffffff, /* src_mask */ 1102 0xffffffff, /* dst_mask */ 1103 TRUE), /* pcrel_offset */ 1104 1105 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */ 1106 0, /* rightshift */ 1107 2, /* size (0 = byte, 1 = short, 2 = long) */ 1108 32, /* bitsize */ 1109 TRUE, /* pc_relative */ 1110 0, /* bitpos */ 1111 complain_overflow_dont,/* complain_on_overflow */ 1112 bfd_elf_generic_reloc, /* special_function */ 1113 "R_ARM_ALU_SB_G1_NC", /* name */ 1114 FALSE, /* partial_inplace */ 1115 0xffffffff, /* src_mask */ 1116 0xffffffff, /* dst_mask */ 1117 TRUE), /* pcrel_offset */ 1118 1119 HOWTO (R_ARM_ALU_SB_G1, /* type */ 1120 0, /* rightshift */ 1121 2, /* size (0 = byte, 1 = short, 2 = long) */ 1122 32, /* bitsize */ 1123 TRUE, /* pc_relative */ 1124 0, /* bitpos */ 1125 complain_overflow_dont,/* complain_on_overflow */ 1126 bfd_elf_generic_reloc, /* special_function */ 1127 "R_ARM_ALU_SB_G1", /* name */ 1128 FALSE, /* partial_inplace */ 1129 0xffffffff, /* src_mask */ 1130 0xffffffff, /* dst_mask */ 1131 TRUE), /* pcrel_offset */ 1132 1133 HOWTO (R_ARM_ALU_SB_G2, /* type */ 1134 0, /* rightshift */ 1135 2, /* size (0 = byte, 1 = short, 2 = long) */ 1136 32, /* bitsize */ 1137 TRUE, /* pc_relative */ 1138 0, /* bitpos */ 1139 complain_overflow_dont,/* complain_on_overflow */ 1140 bfd_elf_generic_reloc, /* special_function */ 1141 "R_ARM_ALU_SB_G2", /* name */ 1142 FALSE, /* partial_inplace */ 1143 0xffffffff, /* src_mask */ 1144 0xffffffff, /* dst_mask */ 1145 TRUE), /* pcrel_offset */ 1146 1147 HOWTO (R_ARM_LDR_SB_G0, /* type */ 1148 0, /* rightshift */ 1149 2, /* size (0 = byte, 1 = short, 2 = long) */ 1150 32, /* bitsize */ 1151 TRUE, /* pc_relative */ 1152 0, /* bitpos */ 1153 complain_overflow_dont,/* complain_on_overflow */ 1154 bfd_elf_generic_reloc, /* special_function */ 1155 "R_ARM_LDR_SB_G0", /* name */ 1156 FALSE, /* partial_inplace */ 1157 0xffffffff, /* src_mask */ 1158 0xffffffff, /* dst_mask */ 1159 TRUE), /* pcrel_offset */ 1160 1161 HOWTO (R_ARM_LDR_SB_G1, /* type */ 1162 0, /* rightshift */ 1163 2, /* size (0 = byte, 1 = short, 2 = long) */ 1164 32, /* bitsize */ 1165 TRUE, /* pc_relative */ 1166 0, /* bitpos */ 1167 complain_overflow_dont,/* complain_on_overflow */ 1168 bfd_elf_generic_reloc, /* special_function */ 1169 "R_ARM_LDR_SB_G1", /* name */ 1170 FALSE, /* partial_inplace */ 1171 0xffffffff, /* src_mask */ 1172 0xffffffff, /* dst_mask */ 1173 TRUE), /* pcrel_offset */ 1174 1175 HOWTO (R_ARM_LDR_SB_G2, /* type */ 1176 0, /* rightshift */ 1177 2, /* size (0 = byte, 1 = short, 2 = long) */ 1178 32, /* bitsize */ 1179 TRUE, /* pc_relative */ 1180 0, /* bitpos */ 1181 complain_overflow_dont,/* complain_on_overflow */ 1182 bfd_elf_generic_reloc, /* special_function */ 1183 "R_ARM_LDR_SB_G2", /* name */ 1184 FALSE, /* partial_inplace */ 1185 0xffffffff, /* src_mask */ 1186 0xffffffff, /* dst_mask */ 1187 TRUE), /* pcrel_offset */ 1188 1189 HOWTO (R_ARM_LDRS_SB_G0, /* type */ 1190 0, /* rightshift */ 1191 2, /* size (0 = byte, 1 = short, 2 = long) */ 1192 32, /* bitsize */ 1193 TRUE, /* pc_relative */ 1194 0, /* bitpos */ 1195 complain_overflow_dont,/* complain_on_overflow */ 1196 bfd_elf_generic_reloc, /* special_function */ 1197 "R_ARM_LDRS_SB_G0", /* name */ 1198 FALSE, /* partial_inplace */ 1199 0xffffffff, /* src_mask */ 1200 0xffffffff, /* dst_mask */ 1201 TRUE), /* pcrel_offset */ 1202 1203 HOWTO (R_ARM_LDRS_SB_G1, /* type */ 1204 0, /* rightshift */ 1205 2, /* size (0 = byte, 1 = short, 2 = long) */ 1206 32, /* bitsize */ 1207 TRUE, /* pc_relative */ 1208 0, /* bitpos */ 1209 complain_overflow_dont,/* complain_on_overflow */ 1210 bfd_elf_generic_reloc, /* special_function */ 1211 "R_ARM_LDRS_SB_G1", /* name */ 1212 FALSE, /* partial_inplace */ 1213 0xffffffff, /* src_mask */ 1214 0xffffffff, /* dst_mask */ 1215 TRUE), /* pcrel_offset */ 1216 1217 HOWTO (R_ARM_LDRS_SB_G2, /* type */ 1218 0, /* rightshift */ 1219 2, /* size (0 = byte, 1 = short, 2 = long) */ 1220 32, /* bitsize */ 1221 TRUE, /* pc_relative */ 1222 0, /* bitpos */ 1223 complain_overflow_dont,/* complain_on_overflow */ 1224 bfd_elf_generic_reloc, /* special_function */ 1225 "R_ARM_LDRS_SB_G2", /* name */ 1226 FALSE, /* partial_inplace */ 1227 0xffffffff, /* src_mask */ 1228 0xffffffff, /* dst_mask */ 1229 TRUE), /* pcrel_offset */ 1230 1231 HOWTO (R_ARM_LDC_SB_G0, /* type */ 1232 0, /* rightshift */ 1233 2, /* size (0 = byte, 1 = short, 2 = long) */ 1234 32, /* bitsize */ 1235 TRUE, /* pc_relative */ 1236 0, /* bitpos */ 1237 complain_overflow_dont,/* complain_on_overflow */ 1238 bfd_elf_generic_reloc, /* special_function */ 1239 "R_ARM_LDC_SB_G0", /* name */ 1240 FALSE, /* partial_inplace */ 1241 0xffffffff, /* src_mask */ 1242 0xffffffff, /* dst_mask */ 1243 TRUE), /* pcrel_offset */ 1244 1245 HOWTO (R_ARM_LDC_SB_G1, /* type */ 1246 0, /* rightshift */ 1247 2, /* size (0 = byte, 1 = short, 2 = long) */ 1248 32, /* bitsize */ 1249 TRUE, /* pc_relative */ 1250 0, /* bitpos */ 1251 complain_overflow_dont,/* complain_on_overflow */ 1252 bfd_elf_generic_reloc, /* special_function */ 1253 "R_ARM_LDC_SB_G1", /* name */ 1254 FALSE, /* partial_inplace */ 1255 0xffffffff, /* src_mask */ 1256 0xffffffff, /* dst_mask */ 1257 TRUE), /* pcrel_offset */ 1258 1259 HOWTO (R_ARM_LDC_SB_G2, /* type */ 1260 0, /* rightshift */ 1261 2, /* size (0 = byte, 1 = short, 2 = long) */ 1262 32, /* bitsize */ 1263 TRUE, /* pc_relative */ 1264 0, /* bitpos */ 1265 complain_overflow_dont,/* complain_on_overflow */ 1266 bfd_elf_generic_reloc, /* special_function */ 1267 "R_ARM_LDC_SB_G2", /* name */ 1268 FALSE, /* partial_inplace */ 1269 0xffffffff, /* src_mask */ 1270 0xffffffff, /* dst_mask */ 1271 TRUE), /* pcrel_offset */ 1272 1273 /* End of group relocations. */ 1274 1275 HOWTO (R_ARM_MOVW_BREL_NC, /* type */ 1276 0, /* rightshift */ 1277 2, /* size (0 = byte, 1 = short, 2 = long) */ 1278 16, /* bitsize */ 1279 FALSE, /* pc_relative */ 1280 0, /* bitpos */ 1281 complain_overflow_dont,/* complain_on_overflow */ 1282 bfd_elf_generic_reloc, /* special_function */ 1283 "R_ARM_MOVW_BREL_NC", /* name */ 1284 FALSE, /* partial_inplace */ 1285 0x0000ffff, /* src_mask */ 1286 0x0000ffff, /* dst_mask */ 1287 FALSE), /* pcrel_offset */ 1288 1289 HOWTO (R_ARM_MOVT_BREL, /* type */ 1290 0, /* rightshift */ 1291 2, /* size (0 = byte, 1 = short, 2 = long) */ 1292 16, /* bitsize */ 1293 FALSE, /* pc_relative */ 1294 0, /* bitpos */ 1295 complain_overflow_bitfield,/* complain_on_overflow */ 1296 bfd_elf_generic_reloc, /* special_function */ 1297 "R_ARM_MOVT_BREL", /* name */ 1298 FALSE, /* partial_inplace */ 1299 0x0000ffff, /* src_mask */ 1300 0x0000ffff, /* dst_mask */ 1301 FALSE), /* pcrel_offset */ 1302 1303 HOWTO (R_ARM_MOVW_BREL, /* type */ 1304 0, /* rightshift */ 1305 2, /* size (0 = byte, 1 = short, 2 = long) */ 1306 16, /* bitsize */ 1307 FALSE, /* pc_relative */ 1308 0, /* bitpos */ 1309 complain_overflow_dont,/* complain_on_overflow */ 1310 bfd_elf_generic_reloc, /* special_function */ 1311 "R_ARM_MOVW_BREL", /* name */ 1312 FALSE, /* partial_inplace */ 1313 0x0000ffff, /* src_mask */ 1314 0x0000ffff, /* dst_mask */ 1315 FALSE), /* pcrel_offset */ 1316 1317 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */ 1318 0, /* rightshift */ 1319 2, /* size (0 = byte, 1 = short, 2 = long) */ 1320 16, /* bitsize */ 1321 FALSE, /* pc_relative */ 1322 0, /* bitpos */ 1323 complain_overflow_dont,/* complain_on_overflow */ 1324 bfd_elf_generic_reloc, /* special_function */ 1325 "R_ARM_THM_MOVW_BREL_NC",/* name */ 1326 FALSE, /* partial_inplace */ 1327 0x040f70ff, /* src_mask */ 1328 0x040f70ff, /* dst_mask */ 1329 FALSE), /* pcrel_offset */ 1330 1331 HOWTO (R_ARM_THM_MOVT_BREL, /* type */ 1332 0, /* rightshift */ 1333 2, /* size (0 = byte, 1 = short, 2 = long) */ 1334 16, /* bitsize */ 1335 FALSE, /* pc_relative */ 1336 0, /* bitpos */ 1337 complain_overflow_bitfield,/* complain_on_overflow */ 1338 bfd_elf_generic_reloc, /* special_function */ 1339 "R_ARM_THM_MOVT_BREL", /* name */ 1340 FALSE, /* partial_inplace */ 1341 0x040f70ff, /* src_mask */ 1342 0x040f70ff, /* dst_mask */ 1343 FALSE), /* pcrel_offset */ 1344 1345 HOWTO (R_ARM_THM_MOVW_BREL, /* type */ 1346 0, /* rightshift */ 1347 2, /* size (0 = byte, 1 = short, 2 = long) */ 1348 16, /* bitsize */ 1349 FALSE, /* pc_relative */ 1350 0, /* bitpos */ 1351 complain_overflow_dont,/* complain_on_overflow */ 1352 bfd_elf_generic_reloc, /* special_function */ 1353 "R_ARM_THM_MOVW_BREL", /* name */ 1354 FALSE, /* partial_inplace */ 1355 0x040f70ff, /* src_mask */ 1356 0x040f70ff, /* dst_mask */ 1357 FALSE), /* pcrel_offset */ 1358 1359 HOWTO (R_ARM_TLS_GOTDESC, /* type */ 1360 0, /* rightshift */ 1361 2, /* size (0 = byte, 1 = short, 2 = long) */ 1362 32, /* bitsize */ 1363 FALSE, /* pc_relative */ 1364 0, /* bitpos */ 1365 complain_overflow_bitfield,/* complain_on_overflow */ 1366 NULL, /* special_function */ 1367 "R_ARM_TLS_GOTDESC", /* name */ 1368 TRUE, /* partial_inplace */ 1369 0xffffffff, /* src_mask */ 1370 0xffffffff, /* dst_mask */ 1371 FALSE), /* pcrel_offset */ 1372 1373 HOWTO (R_ARM_TLS_CALL, /* type */ 1374 0, /* rightshift */ 1375 2, /* size (0 = byte, 1 = short, 2 = long) */ 1376 24, /* bitsize */ 1377 FALSE, /* pc_relative */ 1378 0, /* bitpos */ 1379 complain_overflow_dont,/* complain_on_overflow */ 1380 bfd_elf_generic_reloc, /* special_function */ 1381 "R_ARM_TLS_CALL", /* name */ 1382 FALSE, /* partial_inplace */ 1383 0x00ffffff, /* src_mask */ 1384 0x00ffffff, /* dst_mask */ 1385 FALSE), /* pcrel_offset */ 1386 1387 HOWTO (R_ARM_TLS_DESCSEQ, /* type */ 1388 0, /* rightshift */ 1389 2, /* size (0 = byte, 1 = short, 2 = long) */ 1390 0, /* bitsize */ 1391 FALSE, /* pc_relative */ 1392 0, /* bitpos */ 1393 complain_overflow_bitfield,/* complain_on_overflow */ 1394 bfd_elf_generic_reloc, /* special_function */ 1395 "R_ARM_TLS_DESCSEQ", /* name */ 1396 FALSE, /* partial_inplace */ 1397 0x00000000, /* src_mask */ 1398 0x00000000, /* dst_mask */ 1399 FALSE), /* pcrel_offset */ 1400 1401 HOWTO (R_ARM_THM_TLS_CALL, /* type */ 1402 0, /* rightshift */ 1403 2, /* size (0 = byte, 1 = short, 2 = long) */ 1404 24, /* bitsize */ 1405 FALSE, /* pc_relative */ 1406 0, /* bitpos */ 1407 complain_overflow_dont,/* complain_on_overflow */ 1408 bfd_elf_generic_reloc, /* special_function */ 1409 "R_ARM_THM_TLS_CALL", /* name */ 1410 FALSE, /* partial_inplace */ 1411 0x07ff07ff, /* src_mask */ 1412 0x07ff07ff, /* dst_mask */ 1413 FALSE), /* pcrel_offset */ 1414 1415 HOWTO (R_ARM_PLT32_ABS, /* type */ 1416 0, /* rightshift */ 1417 2, /* size (0 = byte, 1 = short, 2 = long) */ 1418 32, /* bitsize */ 1419 FALSE, /* pc_relative */ 1420 0, /* bitpos */ 1421 complain_overflow_dont,/* complain_on_overflow */ 1422 bfd_elf_generic_reloc, /* special_function */ 1423 "R_ARM_PLT32_ABS", /* name */ 1424 FALSE, /* partial_inplace */ 1425 0xffffffff, /* src_mask */ 1426 0xffffffff, /* dst_mask */ 1427 FALSE), /* pcrel_offset */ 1428 1429 HOWTO (R_ARM_GOT_ABS, /* type */ 1430 0, /* rightshift */ 1431 2, /* size (0 = byte, 1 = short, 2 = long) */ 1432 32, /* bitsize */ 1433 FALSE, /* pc_relative */ 1434 0, /* bitpos */ 1435 complain_overflow_dont,/* complain_on_overflow */ 1436 bfd_elf_generic_reloc, /* special_function */ 1437 "R_ARM_GOT_ABS", /* name */ 1438 FALSE, /* partial_inplace */ 1439 0xffffffff, /* src_mask */ 1440 0xffffffff, /* dst_mask */ 1441 FALSE), /* pcrel_offset */ 1442 1443 HOWTO (R_ARM_GOT_PREL, /* type */ 1444 0, /* rightshift */ 1445 2, /* size (0 = byte, 1 = short, 2 = long) */ 1446 32, /* bitsize */ 1447 TRUE, /* pc_relative */ 1448 0, /* bitpos */ 1449 complain_overflow_dont, /* complain_on_overflow */ 1450 bfd_elf_generic_reloc, /* special_function */ 1451 "R_ARM_GOT_PREL", /* name */ 1452 FALSE, /* partial_inplace */ 1453 0xffffffff, /* src_mask */ 1454 0xffffffff, /* dst_mask */ 1455 TRUE), /* pcrel_offset */ 1456 1457 HOWTO (R_ARM_GOT_BREL12, /* type */ 1458 0, /* rightshift */ 1459 2, /* size (0 = byte, 1 = short, 2 = long) */ 1460 12, /* bitsize */ 1461 FALSE, /* pc_relative */ 1462 0, /* bitpos */ 1463 complain_overflow_bitfield,/* complain_on_overflow */ 1464 bfd_elf_generic_reloc, /* special_function */ 1465 "R_ARM_GOT_BREL12", /* name */ 1466 FALSE, /* partial_inplace */ 1467 0x00000fff, /* src_mask */ 1468 0x00000fff, /* dst_mask */ 1469 FALSE), /* pcrel_offset */ 1470 1471 HOWTO (R_ARM_GOTOFF12, /* type */ 1472 0, /* rightshift */ 1473 2, /* size (0 = byte, 1 = short, 2 = long) */ 1474 12, /* bitsize */ 1475 FALSE, /* pc_relative */ 1476 0, /* bitpos */ 1477 complain_overflow_bitfield,/* complain_on_overflow */ 1478 bfd_elf_generic_reloc, /* special_function */ 1479 "R_ARM_GOTOFF12", /* name */ 1480 FALSE, /* partial_inplace */ 1481 0x00000fff, /* src_mask */ 1482 0x00000fff, /* dst_mask */ 1483 FALSE), /* pcrel_offset */ 1484 1485 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */ 1486 1487 /* GNU extension to record C++ vtable member usage */ 1488 HOWTO (R_ARM_GNU_VTENTRY, /* type */ 1489 0, /* rightshift */ 1490 2, /* size (0 = byte, 1 = short, 2 = long) */ 1491 0, /* bitsize */ 1492 FALSE, /* pc_relative */ 1493 0, /* bitpos */ 1494 complain_overflow_dont, /* complain_on_overflow */ 1495 _bfd_elf_rel_vtable_reloc_fn, /* special_function */ 1496 "R_ARM_GNU_VTENTRY", /* name */ 1497 FALSE, /* partial_inplace */ 1498 0, /* src_mask */ 1499 0, /* dst_mask */ 1500 FALSE), /* pcrel_offset */ 1501 1502 /* GNU extension to record C++ vtable hierarchy */ 1503 HOWTO (R_ARM_GNU_VTINHERIT, /* type */ 1504 0, /* rightshift */ 1505 2, /* size (0 = byte, 1 = short, 2 = long) */ 1506 0, /* bitsize */ 1507 FALSE, /* pc_relative */ 1508 0, /* bitpos */ 1509 complain_overflow_dont, /* complain_on_overflow */ 1510 NULL, /* special_function */ 1511 "R_ARM_GNU_VTINHERIT", /* name */ 1512 FALSE, /* partial_inplace */ 1513 0, /* src_mask */ 1514 0, /* dst_mask */ 1515 FALSE), /* pcrel_offset */ 1516 1517 HOWTO (R_ARM_THM_JUMP11, /* type */ 1518 1, /* rightshift */ 1519 1, /* size (0 = byte, 1 = short, 2 = long) */ 1520 11, /* bitsize */ 1521 TRUE, /* pc_relative */ 1522 0, /* bitpos */ 1523 complain_overflow_signed, /* complain_on_overflow */ 1524 bfd_elf_generic_reloc, /* special_function */ 1525 "R_ARM_THM_JUMP11", /* name */ 1526 FALSE, /* partial_inplace */ 1527 0x000007ff, /* src_mask */ 1528 0x000007ff, /* dst_mask */ 1529 TRUE), /* pcrel_offset */ 1530 1531 HOWTO (R_ARM_THM_JUMP8, /* type */ 1532 1, /* rightshift */ 1533 1, /* size (0 = byte, 1 = short, 2 = long) */ 1534 8, /* bitsize */ 1535 TRUE, /* pc_relative */ 1536 0, /* bitpos */ 1537 complain_overflow_signed, /* complain_on_overflow */ 1538 bfd_elf_generic_reloc, /* special_function */ 1539 "R_ARM_THM_JUMP8", /* name */ 1540 FALSE, /* partial_inplace */ 1541 0x000000ff, /* src_mask */ 1542 0x000000ff, /* dst_mask */ 1543 TRUE), /* pcrel_offset */ 1544 1545 /* TLS relocations */ 1546 HOWTO (R_ARM_TLS_GD32, /* type */ 1547 0, /* rightshift */ 1548 2, /* size (0 = byte, 1 = short, 2 = long) */ 1549 32, /* bitsize */ 1550 FALSE, /* pc_relative */ 1551 0, /* bitpos */ 1552 complain_overflow_bitfield,/* complain_on_overflow */ 1553 NULL, /* special_function */ 1554 "R_ARM_TLS_GD32", /* name */ 1555 TRUE, /* partial_inplace */ 1556 0xffffffff, /* src_mask */ 1557 0xffffffff, /* dst_mask */ 1558 FALSE), /* pcrel_offset */ 1559 1560 HOWTO (R_ARM_TLS_LDM32, /* type */ 1561 0, /* rightshift */ 1562 2, /* size (0 = byte, 1 = short, 2 = long) */ 1563 32, /* bitsize */ 1564 FALSE, /* pc_relative */ 1565 0, /* bitpos */ 1566 complain_overflow_bitfield,/* complain_on_overflow */ 1567 bfd_elf_generic_reloc, /* special_function */ 1568 "R_ARM_TLS_LDM32", /* name */ 1569 TRUE, /* partial_inplace */ 1570 0xffffffff, /* src_mask */ 1571 0xffffffff, /* dst_mask */ 1572 FALSE), /* pcrel_offset */ 1573 1574 HOWTO (R_ARM_TLS_LDO32, /* type */ 1575 0, /* rightshift */ 1576 2, /* size (0 = byte, 1 = short, 2 = long) */ 1577 32, /* bitsize */ 1578 FALSE, /* pc_relative */ 1579 0, /* bitpos */ 1580 complain_overflow_bitfield,/* complain_on_overflow */ 1581 bfd_elf_generic_reloc, /* special_function */ 1582 "R_ARM_TLS_LDO32", /* name */ 1583 TRUE, /* partial_inplace */ 1584 0xffffffff, /* src_mask */ 1585 0xffffffff, /* dst_mask */ 1586 FALSE), /* pcrel_offset */ 1587 1588 HOWTO (R_ARM_TLS_IE32, /* type */ 1589 0, /* rightshift */ 1590 2, /* size (0 = byte, 1 = short, 2 = long) */ 1591 32, /* bitsize */ 1592 FALSE, /* pc_relative */ 1593 0, /* bitpos */ 1594 complain_overflow_bitfield,/* complain_on_overflow */ 1595 NULL, /* special_function */ 1596 "R_ARM_TLS_IE32", /* name */ 1597 TRUE, /* partial_inplace */ 1598 0xffffffff, /* src_mask */ 1599 0xffffffff, /* dst_mask */ 1600 FALSE), /* pcrel_offset */ 1601 1602 HOWTO (R_ARM_TLS_LE32, /* type */ 1603 0, /* rightshift */ 1604 2, /* size (0 = byte, 1 = short, 2 = long) */ 1605 32, /* bitsize */ 1606 FALSE, /* pc_relative */ 1607 0, /* bitpos */ 1608 complain_overflow_bitfield,/* complain_on_overflow */ 1609 bfd_elf_generic_reloc, /* special_function */ 1610 "R_ARM_TLS_LE32", /* name */ 1611 TRUE, /* partial_inplace */ 1612 0xffffffff, /* src_mask */ 1613 0xffffffff, /* dst_mask */ 1614 FALSE), /* pcrel_offset */ 1615 1616 HOWTO (R_ARM_TLS_LDO12, /* type */ 1617 0, /* rightshift */ 1618 2, /* size (0 = byte, 1 = short, 2 = long) */ 1619 12, /* bitsize */ 1620 FALSE, /* pc_relative */ 1621 0, /* bitpos */ 1622 complain_overflow_bitfield,/* complain_on_overflow */ 1623 bfd_elf_generic_reloc, /* special_function */ 1624 "R_ARM_TLS_LDO12", /* name */ 1625 FALSE, /* partial_inplace */ 1626 0x00000fff, /* src_mask */ 1627 0x00000fff, /* dst_mask */ 1628 FALSE), /* pcrel_offset */ 1629 1630 HOWTO (R_ARM_TLS_LE12, /* type */ 1631 0, /* rightshift */ 1632 2, /* size (0 = byte, 1 = short, 2 = long) */ 1633 12, /* bitsize */ 1634 FALSE, /* pc_relative */ 1635 0, /* bitpos */ 1636 complain_overflow_bitfield,/* complain_on_overflow */ 1637 bfd_elf_generic_reloc, /* special_function */ 1638 "R_ARM_TLS_LE12", /* name */ 1639 FALSE, /* partial_inplace */ 1640 0x00000fff, /* src_mask */ 1641 0x00000fff, /* dst_mask */ 1642 FALSE), /* pcrel_offset */ 1643 1644 HOWTO (R_ARM_TLS_IE12GP, /* type */ 1645 0, /* rightshift */ 1646 2, /* size (0 = byte, 1 = short, 2 = long) */ 1647 12, /* bitsize */ 1648 FALSE, /* pc_relative */ 1649 0, /* bitpos */ 1650 complain_overflow_bitfield,/* complain_on_overflow */ 1651 bfd_elf_generic_reloc, /* special_function */ 1652 "R_ARM_TLS_IE12GP", /* name */ 1653 FALSE, /* partial_inplace */ 1654 0x00000fff, /* src_mask */ 1655 0x00000fff, /* dst_mask */ 1656 FALSE), /* pcrel_offset */ 1657 1658 /* 112-127 private relocations. */ 1659 EMPTY_HOWTO (112), 1660 EMPTY_HOWTO (113), 1661 EMPTY_HOWTO (114), 1662 EMPTY_HOWTO (115), 1663 EMPTY_HOWTO (116), 1664 EMPTY_HOWTO (117), 1665 EMPTY_HOWTO (118), 1666 EMPTY_HOWTO (119), 1667 EMPTY_HOWTO (120), 1668 EMPTY_HOWTO (121), 1669 EMPTY_HOWTO (122), 1670 EMPTY_HOWTO (123), 1671 EMPTY_HOWTO (124), 1672 EMPTY_HOWTO (125), 1673 EMPTY_HOWTO (126), 1674 EMPTY_HOWTO (127), 1675 1676 /* R_ARM_ME_TOO, obsolete. */ 1677 EMPTY_HOWTO (128), 1678 1679 HOWTO (R_ARM_THM_TLS_DESCSEQ, /* type */ 1680 0, /* rightshift */ 1681 1, /* size (0 = byte, 1 = short, 2 = long) */ 1682 0, /* bitsize */ 1683 FALSE, /* pc_relative */ 1684 0, /* bitpos */ 1685 complain_overflow_bitfield,/* complain_on_overflow */ 1686 bfd_elf_generic_reloc, /* special_function */ 1687 "R_ARM_THM_TLS_DESCSEQ",/* name */ 1688 FALSE, /* partial_inplace */ 1689 0x00000000, /* src_mask */ 1690 0x00000000, /* dst_mask */ 1691 FALSE), /* pcrel_offset */ 1692 }; 1693 1694 /* 160 onwards: */ 1695 static reloc_howto_type elf32_arm_howto_table_2[1] = 1696 { 1697 HOWTO (R_ARM_IRELATIVE, /* type */ 1698 0, /* rightshift */ 1699 2, /* size (0 = byte, 1 = short, 2 = long) */ 1700 32, /* bitsize */ 1701 FALSE, /* pc_relative */ 1702 0, /* bitpos */ 1703 complain_overflow_bitfield,/* complain_on_overflow */ 1704 bfd_elf_generic_reloc, /* special_function */ 1705 "R_ARM_IRELATIVE", /* name */ 1706 TRUE, /* partial_inplace */ 1707 0xffffffff, /* src_mask */ 1708 0xffffffff, /* dst_mask */ 1709 FALSE) /* pcrel_offset */ 1710 }; 1711 1712 /* 249-255 extended, currently unused, relocations: */ 1713 static reloc_howto_type elf32_arm_howto_table_3[4] = 1714 { 1715 HOWTO (R_ARM_RREL32, /* type */ 1716 0, /* rightshift */ 1717 0, /* size (0 = byte, 1 = short, 2 = long) */ 1718 0, /* bitsize */ 1719 FALSE, /* pc_relative */ 1720 0, /* bitpos */ 1721 complain_overflow_dont,/* complain_on_overflow */ 1722 bfd_elf_generic_reloc, /* special_function */ 1723 "R_ARM_RREL32", /* name */ 1724 FALSE, /* partial_inplace */ 1725 0, /* src_mask */ 1726 0, /* dst_mask */ 1727 FALSE), /* pcrel_offset */ 1728 1729 HOWTO (R_ARM_RABS32, /* type */ 1730 0, /* rightshift */ 1731 0, /* size (0 = byte, 1 = short, 2 = long) */ 1732 0, /* bitsize */ 1733 FALSE, /* pc_relative */ 1734 0, /* bitpos */ 1735 complain_overflow_dont,/* complain_on_overflow */ 1736 bfd_elf_generic_reloc, /* special_function */ 1737 "R_ARM_RABS32", /* name */ 1738 FALSE, /* partial_inplace */ 1739 0, /* src_mask */ 1740 0, /* dst_mask */ 1741 FALSE), /* pcrel_offset */ 1742 1743 HOWTO (R_ARM_RPC24, /* type */ 1744 0, /* rightshift */ 1745 0, /* size (0 = byte, 1 = short, 2 = long) */ 1746 0, /* bitsize */ 1747 FALSE, /* pc_relative */ 1748 0, /* bitpos */ 1749 complain_overflow_dont,/* complain_on_overflow */ 1750 bfd_elf_generic_reloc, /* special_function */ 1751 "R_ARM_RPC24", /* name */ 1752 FALSE, /* partial_inplace */ 1753 0, /* src_mask */ 1754 0, /* dst_mask */ 1755 FALSE), /* pcrel_offset */ 1756 1757 HOWTO (R_ARM_RBASE, /* type */ 1758 0, /* rightshift */ 1759 0, /* size (0 = byte, 1 = short, 2 = long) */ 1760 0, /* bitsize */ 1761 FALSE, /* pc_relative */ 1762 0, /* bitpos */ 1763 complain_overflow_dont,/* complain_on_overflow */ 1764 bfd_elf_generic_reloc, /* special_function */ 1765 "R_ARM_RBASE", /* name */ 1766 FALSE, /* partial_inplace */ 1767 0, /* src_mask */ 1768 0, /* dst_mask */ 1769 FALSE) /* pcrel_offset */ 1770 }; 1771 1772 static reloc_howto_type * 1773 elf32_arm_howto_from_type (unsigned int r_type) 1774 { 1775 if (r_type < ARRAY_SIZE (elf32_arm_howto_table_1)) 1776 return &elf32_arm_howto_table_1[r_type]; 1777 1778 if (r_type == R_ARM_IRELATIVE) 1779 return &elf32_arm_howto_table_2[r_type - R_ARM_IRELATIVE]; 1780 1781 if (r_type >= R_ARM_RREL32 1782 && r_type < R_ARM_RREL32 + ARRAY_SIZE (elf32_arm_howto_table_3)) 1783 return &elf32_arm_howto_table_3[r_type - R_ARM_RREL32]; 1784 1785 return NULL; 1786 } 1787 1788 static void 1789 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc, 1790 Elf_Internal_Rela * elf_reloc) 1791 { 1792 unsigned int r_type; 1793 1794 r_type = ELF32_R_TYPE (elf_reloc->r_info); 1795 bfd_reloc->howto = elf32_arm_howto_from_type (r_type); 1796 } 1797 1798 struct elf32_arm_reloc_map 1799 { 1800 bfd_reloc_code_real_type bfd_reloc_val; 1801 unsigned char elf_reloc_val; 1802 }; 1803 1804 /* All entries in this list must also be present in elf32_arm_howto_table. */ 1805 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] = 1806 { 1807 {BFD_RELOC_NONE, R_ARM_NONE}, 1808 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24}, 1809 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL}, 1810 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24}, 1811 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25}, 1812 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22}, 1813 {BFD_RELOC_32, R_ARM_ABS32}, 1814 {BFD_RELOC_32_PCREL, R_ARM_REL32}, 1815 {BFD_RELOC_8, R_ARM_ABS8}, 1816 {BFD_RELOC_16, R_ARM_ABS16}, 1817 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12}, 1818 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5}, 1819 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24}, 1820 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL}, 1821 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11}, 1822 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19}, 1823 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8}, 1824 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6}, 1825 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT}, 1826 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT}, 1827 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE}, 1828 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32}, 1829 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC}, 1830 {BFD_RELOC_ARM_GOT_PREL, R_ARM_GOT_PREL}, 1831 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32}, 1832 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, 1833 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1}, 1834 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32}, 1835 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32}, 1836 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31}, 1837 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2}, 1838 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, 1839 {BFD_RELOC_ARM_TLS_GOTDESC, R_ARM_TLS_GOTDESC}, 1840 {BFD_RELOC_ARM_TLS_CALL, R_ARM_TLS_CALL}, 1841 {BFD_RELOC_ARM_THM_TLS_CALL, R_ARM_THM_TLS_CALL}, 1842 {BFD_RELOC_ARM_TLS_DESCSEQ, R_ARM_TLS_DESCSEQ}, 1843 {BFD_RELOC_ARM_THM_TLS_DESCSEQ, R_ARM_THM_TLS_DESCSEQ}, 1844 {BFD_RELOC_ARM_TLS_DESC, R_ARM_TLS_DESC}, 1845 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32}, 1846 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32}, 1847 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32}, 1848 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32}, 1849 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32}, 1850 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32}, 1851 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32}, 1852 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32}, 1853 {BFD_RELOC_ARM_IRELATIVE, R_ARM_IRELATIVE}, 1854 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT}, 1855 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY}, 1856 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC}, 1857 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS}, 1858 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC}, 1859 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL}, 1860 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC}, 1861 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS}, 1862 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC}, 1863 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL}, 1864 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC}, 1865 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0}, 1866 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC}, 1867 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1}, 1868 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2}, 1869 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0}, 1870 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1}, 1871 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2}, 1872 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0}, 1873 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1}, 1874 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2}, 1875 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0}, 1876 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1}, 1877 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2}, 1878 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC}, 1879 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0}, 1880 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC}, 1881 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1}, 1882 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2}, 1883 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0}, 1884 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1}, 1885 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2}, 1886 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0}, 1887 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1}, 1888 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2}, 1889 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0}, 1890 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1}, 1891 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2}, 1892 {BFD_RELOC_ARM_V4BX, R_ARM_V4BX} 1893 }; 1894 1895 static reloc_howto_type * 1896 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1897 bfd_reloc_code_real_type code) 1898 { 1899 unsigned int i; 1900 1901 for (i = 0; i < ARRAY_SIZE (elf32_arm_reloc_map); i ++) 1902 if (elf32_arm_reloc_map[i].bfd_reloc_val == code) 1903 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val); 1904 1905 return NULL; 1906 } 1907 1908 static reloc_howto_type * 1909 elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1910 const char *r_name) 1911 { 1912 unsigned int i; 1913 1914 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_1); i++) 1915 if (elf32_arm_howto_table_1[i].name != NULL 1916 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0) 1917 return &elf32_arm_howto_table_1[i]; 1918 1919 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_2); i++) 1920 if (elf32_arm_howto_table_2[i].name != NULL 1921 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0) 1922 return &elf32_arm_howto_table_2[i]; 1923 1924 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_3); i++) 1925 if (elf32_arm_howto_table_3[i].name != NULL 1926 && strcasecmp (elf32_arm_howto_table_3[i].name, r_name) == 0) 1927 return &elf32_arm_howto_table_3[i]; 1928 1929 return NULL; 1930 } 1931 1932 /* Support for core dump NOTE sections. */ 1933 1934 static bfd_boolean 1935 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) 1936 { 1937 int offset; 1938 size_t size; 1939 1940 switch (note->descsz) 1941 { 1942 default: 1943 return FALSE; 1944 1945 case 148: /* Linux/ARM 32-bit. */ 1946 /* pr_cursig */ 1947 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); 1948 1949 /* pr_pid */ 1950 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24); 1951 1952 /* pr_reg */ 1953 offset = 72; 1954 size = 72; 1955 1956 break; 1957 } 1958 1959 /* Make a ".reg/999" section. */ 1960 return _bfd_elfcore_make_pseudosection (abfd, ".reg", 1961 size, note->descpos + offset); 1962 } 1963 1964 static bfd_boolean 1965 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) 1966 { 1967 switch (note->descsz) 1968 { 1969 default: 1970 return FALSE; 1971 1972 case 124: /* Linux/ARM elf_prpsinfo. */ 1973 elf_tdata (abfd)->core->pid 1974 = bfd_get_32 (abfd, note->descdata + 12); 1975 elf_tdata (abfd)->core->program 1976 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); 1977 elf_tdata (abfd)->core->command 1978 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); 1979 } 1980 1981 /* Note that for some reason, a spurious space is tacked 1982 onto the end of the args in some (at least one anyway) 1983 implementations, so strip it off if it exists. */ 1984 { 1985 char *command = elf_tdata (abfd)->core->command; 1986 int n = strlen (command); 1987 1988 if (0 < n && command[n - 1] == ' ') 1989 command[n - 1] = '\0'; 1990 } 1991 1992 return TRUE; 1993 } 1994 1995 static char * 1996 elf32_arm_nabi_write_core_note (bfd *abfd, char *buf, int *bufsiz, 1997 int note_type, ...) 1998 { 1999 switch (note_type) 2000 { 2001 default: 2002 return NULL; 2003 2004 case NT_PRPSINFO: 2005 { 2006 char data[124]; 2007 va_list ap; 2008 2009 va_start (ap, note_type); 2010 memset (data, 0, sizeof (data)); 2011 strncpy (data + 28, va_arg (ap, const char *), 16); 2012 strncpy (data + 44, va_arg (ap, const char *), 80); 2013 va_end (ap); 2014 2015 return elfcore_write_note (abfd, buf, bufsiz, 2016 "CORE", note_type, data, sizeof (data)); 2017 } 2018 2019 case NT_PRSTATUS: 2020 { 2021 char data[148]; 2022 va_list ap; 2023 long pid; 2024 int cursig; 2025 const void *greg; 2026 2027 va_start (ap, note_type); 2028 memset (data, 0, sizeof (data)); 2029 pid = va_arg (ap, long); 2030 bfd_put_32 (abfd, pid, data + 24); 2031 cursig = va_arg (ap, int); 2032 bfd_put_16 (abfd, cursig, data + 12); 2033 greg = va_arg (ap, const void *); 2034 memcpy (data + 72, greg, 72); 2035 va_end (ap); 2036 2037 return elfcore_write_note (abfd, buf, bufsiz, 2038 "CORE", note_type, data, sizeof (data)); 2039 } 2040 } 2041 } 2042 2043 #define TARGET_LITTLE_SYM arm_elf32_le_vec 2044 #define TARGET_LITTLE_NAME "elf32-littlearm" 2045 #define TARGET_BIG_SYM arm_elf32_be_vec 2046 #define TARGET_BIG_NAME "elf32-bigarm" 2047 2048 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus 2049 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo 2050 #define elf_backend_write_core_note elf32_arm_nabi_write_core_note 2051 2052 typedef unsigned long int insn32; 2053 typedef unsigned short int insn16; 2054 2055 /* In lieu of proper flags, assume all EABIv4 or later objects are 2056 interworkable. */ 2057 #define INTERWORK_FLAG(abfd) \ 2058 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \ 2059 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK) \ 2060 || ((abfd)->flags & BFD_LINKER_CREATED)) 2061 2062 /* The linker script knows the section names for placement. 2063 The entry_names are used to do simple name mangling on the stubs. 2064 Given a function name, and its type, the stub can be found. The 2065 name can be changed. The only requirement is the %s be present. */ 2066 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t" 2067 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb" 2068 2069 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7" 2070 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm" 2071 2072 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer" 2073 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x" 2074 2075 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx" 2076 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d" 2077 2078 #define STUB_ENTRY_NAME "__%s_veneer" 2079 2080 /* The name of the dynamic interpreter. This is put in the .interp 2081 section. */ 2082 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" 2083 2084 static const unsigned long tls_trampoline [] = 2085 { 2086 0xe08e0000, /* add r0, lr, r0 */ 2087 0xe5901004, /* ldr r1, [r0,#4] */ 2088 0xe12fff11, /* bx r1 */ 2089 }; 2090 2091 static const unsigned long dl_tlsdesc_lazy_trampoline [] = 2092 { 2093 0xe52d2004, /* push {r2} */ 2094 0xe59f200c, /* ldr r2, [pc, #3f - . - 8] */ 2095 0xe59f100c, /* ldr r1, [pc, #4f - . - 8] */ 2096 0xe79f2002, /* 1: ldr r2, [pc, r2] */ 2097 0xe081100f, /* 2: add r1, pc */ 2098 0xe12fff12, /* bx r2 */ 2099 0x00000014, /* 3: .word _GLOBAL_OFFSET_TABLE_ - 1b - 8 2100 + dl_tlsdesc_lazy_resolver(GOT) */ 2101 0x00000018, /* 4: .word _GLOBAL_OFFSET_TABLE_ - 2b - 8 */ 2102 }; 2103 2104 #ifdef FOUR_WORD_PLT 2105 2106 /* The first entry in a procedure linkage table looks like 2107 this. It is set up so that any shared library function that is 2108 called before the relocation has been set up calls the dynamic 2109 linker first. */ 2110 static const bfd_vma elf32_arm_plt0_entry [] = 2111 { 2112 0xe52de004, /* str lr, [sp, #-4]! */ 2113 0xe59fe010, /* ldr lr, [pc, #16] */ 2114 0xe08fe00e, /* add lr, pc, lr */ 2115 0xe5bef008, /* ldr pc, [lr, #8]! */ 2116 }; 2117 2118 /* Subsequent entries in a procedure linkage table look like 2119 this. */ 2120 static const bfd_vma elf32_arm_plt_entry [] = 2121 { 2122 0xe28fc600, /* add ip, pc, #NN */ 2123 0xe28cca00, /* add ip, ip, #NN */ 2124 0xe5bcf000, /* ldr pc, [ip, #NN]! */ 2125 0x00000000, /* unused */ 2126 }; 2127 2128 #else /* not FOUR_WORD_PLT */ 2129 2130 /* The first entry in a procedure linkage table looks like 2131 this. It is set up so that any shared library function that is 2132 called before the relocation has been set up calls the dynamic 2133 linker first. */ 2134 static const bfd_vma elf32_arm_plt0_entry [] = 2135 { 2136 0xe52de004, /* str lr, [sp, #-4]! */ 2137 0xe59fe004, /* ldr lr, [pc, #4] */ 2138 0xe08fe00e, /* add lr, pc, lr */ 2139 0xe5bef008, /* ldr pc, [lr, #8]! */ 2140 0x00000000, /* &GOT[0] - . */ 2141 }; 2142 2143 /* By default subsequent entries in a procedure linkage table look like 2144 this. Offsets that don't fit into 28 bits will cause link error. */ 2145 static const bfd_vma elf32_arm_plt_entry_short [] = 2146 { 2147 0xe28fc600, /* add ip, pc, #0xNN00000 */ 2148 0xe28cca00, /* add ip, ip, #0xNN000 */ 2149 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */ 2150 }; 2151 2152 /* When explicitly asked, we'll use this "long" entry format 2153 which can cope with arbitrary displacements. */ 2154 static const bfd_vma elf32_arm_plt_entry_long [] = 2155 { 2156 0xe28fc200, /* add ip, pc, #0xN0000000 */ 2157 0xe28cc600, /* add ip, ip, #0xNN00000 */ 2158 0xe28cca00, /* add ip, ip, #0xNN000 */ 2159 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */ 2160 }; 2161 2162 static bfd_boolean elf32_arm_use_long_plt_entry = FALSE; 2163 2164 #endif /* not FOUR_WORD_PLT */ 2165 2166 /* The first entry in a procedure linkage table looks like this. 2167 It is set up so that any shared library function that is called before the 2168 relocation has been set up calls the dynamic linker first. */ 2169 static const bfd_vma elf32_thumb2_plt0_entry [] = 2170 { 2171 /* NOTE: As this is a mixture of 16-bit and 32-bit instructions, 2172 an instruction maybe encoded to one or two array elements. */ 2173 0xf8dfb500, /* push {lr} */ 2174 0x44fee008, /* ldr.w lr, [pc, #8] */ 2175 /* add lr, pc */ 2176 0xff08f85e, /* ldr.w pc, [lr, #8]! */ 2177 0x00000000, /* &GOT[0] - . */ 2178 }; 2179 2180 /* Subsequent entries in a procedure linkage table for thumb only target 2181 look like this. */ 2182 static const bfd_vma elf32_thumb2_plt_entry [] = 2183 { 2184 /* NOTE: As this is a mixture of 16-bit and 32-bit instructions, 2185 an instruction maybe encoded to one or two array elements. */ 2186 0x0c00f240, /* movw ip, #0xNNNN */ 2187 0x0c00f2c0, /* movt ip, #0xNNNN */ 2188 0xf8dc44fc, /* add ip, pc */ 2189 0xbf00f000 /* ldr.w pc, [ip] */ 2190 /* nop */ 2191 }; 2192 2193 /* The format of the first entry in the procedure linkage table 2194 for a VxWorks executable. */ 2195 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] = 2196 { 2197 0xe52dc008, /* str ip,[sp,#-8]! */ 2198 0xe59fc000, /* ldr ip,[pc] */ 2199 0xe59cf008, /* ldr pc,[ip,#8] */ 2200 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */ 2201 }; 2202 2203 /* The format of subsequent entries in a VxWorks executable. */ 2204 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] = 2205 { 2206 0xe59fc000, /* ldr ip,[pc] */ 2207 0xe59cf000, /* ldr pc,[ip] */ 2208 0x00000000, /* .long @got */ 2209 0xe59fc000, /* ldr ip,[pc] */ 2210 0xea000000, /* b _PLT */ 2211 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */ 2212 }; 2213 2214 /* The format of entries in a VxWorks shared library. */ 2215 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] = 2216 { 2217 0xe59fc000, /* ldr ip,[pc] */ 2218 0xe79cf009, /* ldr pc,[ip,r9] */ 2219 0x00000000, /* .long @got */ 2220 0xe59fc000, /* ldr ip,[pc] */ 2221 0xe599f008, /* ldr pc,[r9,#8] */ 2222 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */ 2223 }; 2224 2225 /* An initial stub used if the PLT entry is referenced from Thumb code. */ 2226 #define PLT_THUMB_STUB_SIZE 4 2227 static const bfd_vma elf32_arm_plt_thumb_stub [] = 2228 { 2229 0x4778, /* bx pc */ 2230 0x46c0 /* nop */ 2231 }; 2232 2233 /* The entries in a PLT when using a DLL-based target with multiple 2234 address spaces. */ 2235 static const bfd_vma elf32_arm_symbian_plt_entry [] = 2236 { 2237 0xe51ff004, /* ldr pc, [pc, #-4] */ 2238 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */ 2239 }; 2240 2241 /* The first entry in a procedure linkage table looks like 2242 this. It is set up so that any shared library function that is 2243 called before the relocation has been set up calls the dynamic 2244 linker first. */ 2245 static const bfd_vma elf32_arm_nacl_plt0_entry [] = 2246 { 2247 /* First bundle: */ 2248 0xe300c000, /* movw ip, #:lower16:&GOT[2]-.+8 */ 2249 0xe340c000, /* movt ip, #:upper16:&GOT[2]-.+8 */ 2250 0xe08cc00f, /* add ip, ip, pc */ 2251 0xe52dc008, /* str ip, [sp, #-8]! */ 2252 /* Second bundle: */ 2253 0xe3ccc103, /* bic ip, ip, #0xc0000000 */ 2254 0xe59cc000, /* ldr ip, [ip] */ 2255 0xe3ccc13f, /* bic ip, ip, #0xc000000f */ 2256 0xe12fff1c, /* bx ip */ 2257 /* Third bundle: */ 2258 0xe320f000, /* nop */ 2259 0xe320f000, /* nop */ 2260 0xe320f000, /* nop */ 2261 /* .Lplt_tail: */ 2262 0xe50dc004, /* str ip, [sp, #-4] */ 2263 /* Fourth bundle: */ 2264 0xe3ccc103, /* bic ip, ip, #0xc0000000 */ 2265 0xe59cc000, /* ldr ip, [ip] */ 2266 0xe3ccc13f, /* bic ip, ip, #0xc000000f */ 2267 0xe12fff1c, /* bx ip */ 2268 }; 2269 #define ARM_NACL_PLT_TAIL_OFFSET (11 * 4) 2270 2271 /* Subsequent entries in a procedure linkage table look like this. */ 2272 static const bfd_vma elf32_arm_nacl_plt_entry [] = 2273 { 2274 0xe300c000, /* movw ip, #:lower16:&GOT[n]-.+8 */ 2275 0xe340c000, /* movt ip, #:upper16:&GOT[n]-.+8 */ 2276 0xe08cc00f, /* add ip, ip, pc */ 2277 0xea000000, /* b .Lplt_tail */ 2278 }; 2279 2280 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8) 2281 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8) 2282 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4) 2283 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4) 2284 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4) 2285 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4) 2286 #define THM2_MAX_FWD_COND_BRANCH_OFFSET (((1 << 20) -2) + 4) 2287 #define THM2_MAX_BWD_COND_BRANCH_OFFSET (-(1 << 20) + 4) 2288 2289 enum stub_insn_type 2290 { 2291 THUMB16_TYPE = 1, 2292 THUMB32_TYPE, 2293 ARM_TYPE, 2294 DATA_TYPE 2295 }; 2296 2297 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0} 2298 /* A bit of a hack. A Thumb conditional branch, in which the proper condition 2299 is inserted in arm_build_one_stub(). */ 2300 #define THUMB16_BCOND_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 1} 2301 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0} 2302 #define THUMB32_B_INSN(X, Z) {(X), THUMB32_TYPE, R_ARM_THM_JUMP24, (Z)} 2303 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0} 2304 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)} 2305 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)} 2306 2307 typedef struct 2308 { 2309 bfd_vma data; 2310 enum stub_insn_type type; 2311 unsigned int r_type; 2312 int reloc_addend; 2313 } insn_sequence; 2314 2315 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx 2316 to reach the stub if necessary. */ 2317 static const insn_sequence elf32_arm_stub_long_branch_any_any[] = 2318 { 2319 ARM_INSN (0xe51ff004), /* ldr pc, [pc, #-4] */ 2320 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */ 2321 }; 2322 2323 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not 2324 available. */ 2325 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb[] = 2326 { 2327 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */ 2328 ARM_INSN (0xe12fff1c), /* bx ip */ 2329 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */ 2330 }; 2331 2332 /* Thumb -> Thumb long branch stub. Used on M-profile architectures. */ 2333 static const insn_sequence elf32_arm_stub_long_branch_thumb_only[] = 2334 { 2335 THUMB16_INSN (0xb401), /* push {r0} */ 2336 THUMB16_INSN (0x4802), /* ldr r0, [pc, #8] */ 2337 THUMB16_INSN (0x4684), /* mov ip, r0 */ 2338 THUMB16_INSN (0xbc01), /* pop {r0} */ 2339 THUMB16_INSN (0x4760), /* bx ip */ 2340 THUMB16_INSN (0xbf00), /* nop */ 2341 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */ 2342 }; 2343 2344 /* V4T Thumb -> Thumb long branch stub. Using the stack is not 2345 allowed. */ 2346 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb[] = 2347 { 2348 THUMB16_INSN (0x4778), /* bx pc */ 2349 THUMB16_INSN (0x46c0), /* nop */ 2350 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */ 2351 ARM_INSN (0xe12fff1c), /* bx ip */ 2352 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */ 2353 }; 2354 2355 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not 2356 available. */ 2357 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm[] = 2358 { 2359 THUMB16_INSN (0x4778), /* bx pc */ 2360 THUMB16_INSN (0x46c0), /* nop */ 2361 ARM_INSN (0xe51ff004), /* ldr pc, [pc, #-4] */ 2362 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */ 2363 }; 2364 2365 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above 2366 one, when the destination is close enough. */ 2367 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm[] = 2368 { 2369 THUMB16_INSN (0x4778), /* bx pc */ 2370 THUMB16_INSN (0x46c0), /* nop */ 2371 ARM_REL_INSN (0xea000000, -8), /* b (X-8) */ 2372 }; 2373 2374 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use 2375 blx to reach the stub if necessary. */ 2376 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic[] = 2377 { 2378 ARM_INSN (0xe59fc000), /* ldr ip, [pc] */ 2379 ARM_INSN (0xe08ff00c), /* add pc, pc, ip */ 2380 DATA_WORD (0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X-4) */ 2381 }; 2382 2383 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use 2384 blx to reach the stub if necessary. We can not add into pc; 2385 it is not guaranteed to mode switch (different in ARMv6 and 2386 ARMv7). */ 2387 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic[] = 2388 { 2389 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */ 2390 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */ 2391 ARM_INSN (0xe12fff1c), /* bx ip */ 2392 DATA_WORD (0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */ 2393 }; 2394 2395 /* V4T ARM -> ARM long branch stub, PIC. */ 2396 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic[] = 2397 { 2398 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */ 2399 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */ 2400 ARM_INSN (0xe12fff1c), /* bx ip */ 2401 DATA_WORD (0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */ 2402 }; 2403 2404 /* V4T Thumb -> ARM long branch stub, PIC. */ 2405 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic[] = 2406 { 2407 THUMB16_INSN (0x4778), /* bx pc */ 2408 THUMB16_INSN (0x46c0), /* nop */ 2409 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */ 2410 ARM_INSN (0xe08cf00f), /* add pc, ip, pc */ 2411 DATA_WORD (0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X) */ 2412 }; 2413 2414 /* Thumb -> Thumb long branch stub, PIC. Used on M-profile 2415 architectures. */ 2416 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic[] = 2417 { 2418 THUMB16_INSN (0xb401), /* push {r0} */ 2419 THUMB16_INSN (0x4802), /* ldr r0, [pc, #8] */ 2420 THUMB16_INSN (0x46fc), /* mov ip, pc */ 2421 THUMB16_INSN (0x4484), /* add ip, r0 */ 2422 THUMB16_INSN (0xbc01), /* pop {r0} */ 2423 THUMB16_INSN (0x4760), /* bx ip */ 2424 DATA_WORD (0, R_ARM_REL32, 4), /* dcd R_ARM_REL32(X) */ 2425 }; 2426 2427 /* V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not 2428 allowed. */ 2429 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb_pic[] = 2430 { 2431 THUMB16_INSN (0x4778), /* bx pc */ 2432 THUMB16_INSN (0x46c0), /* nop */ 2433 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */ 2434 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */ 2435 ARM_INSN (0xe12fff1c), /* bx ip */ 2436 DATA_WORD (0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */ 2437 }; 2438 2439 /* Thumb2/ARM -> TLS trampoline. Lowest common denominator, which is a 2440 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */ 2441 static const insn_sequence elf32_arm_stub_long_branch_any_tls_pic[] = 2442 { 2443 ARM_INSN (0xe59f1000), /* ldr r1, [pc] */ 2444 ARM_INSN (0xe08ff001), /* add pc, pc, r1 */ 2445 DATA_WORD (0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X-4) */ 2446 }; 2447 2448 /* V4T Thumb -> TLS trampoline. lowest common denominator, which is a 2449 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */ 2450 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_tls_pic[] = 2451 { 2452 THUMB16_INSN (0x4778), /* bx pc */ 2453 THUMB16_INSN (0x46c0), /* nop */ 2454 ARM_INSN (0xe59f1000), /* ldr r1, [pc, #0] */ 2455 ARM_INSN (0xe081f00f), /* add pc, r1, pc */ 2456 DATA_WORD (0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X) */ 2457 }; 2458 2459 /* NaCl ARM -> ARM long branch stub. */ 2460 static const insn_sequence elf32_arm_stub_long_branch_arm_nacl[] = 2461 { 2462 ARM_INSN (0xe59fc00c), /* ldr ip, [pc, #12] */ 2463 ARM_INSN (0xe3ccc13f), /* bic ip, ip, #0xc000000f */ 2464 ARM_INSN (0xe12fff1c), /* bx ip */ 2465 ARM_INSN (0xe320f000), /* nop */ 2466 ARM_INSN (0xe125be70), /* bkpt 0x5be0 */ 2467 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */ 2468 DATA_WORD (0, R_ARM_NONE, 0), /* .word 0 */ 2469 DATA_WORD (0, R_ARM_NONE, 0), /* .word 0 */ 2470 }; 2471 2472 /* NaCl ARM -> ARM long branch stub, PIC. */ 2473 static const insn_sequence elf32_arm_stub_long_branch_arm_nacl_pic[] = 2474 { 2475 ARM_INSN (0xe59fc00c), /* ldr ip, [pc, #12] */ 2476 ARM_INSN (0xe08cc00f), /* add ip, ip, pc */ 2477 ARM_INSN (0xe3ccc13f), /* bic ip, ip, #0xc000000f */ 2478 ARM_INSN (0xe12fff1c), /* bx ip */ 2479 ARM_INSN (0xe125be70), /* bkpt 0x5be0 */ 2480 DATA_WORD (0, R_ARM_REL32, 8), /* dcd R_ARM_REL32(X+8) */ 2481 DATA_WORD (0, R_ARM_NONE, 0), /* .word 0 */ 2482 DATA_WORD (0, R_ARM_NONE, 0), /* .word 0 */ 2483 }; 2484 2485 2486 /* Cortex-A8 erratum-workaround stubs. */ 2487 2488 /* Stub used for conditional branches (which may be beyond +/-1MB away, so we 2489 can't use a conditional branch to reach this stub). */ 2490 2491 static const insn_sequence elf32_arm_stub_a8_veneer_b_cond[] = 2492 { 2493 THUMB16_BCOND_INSN (0xd001), /* b<cond>.n true. */ 2494 THUMB32_B_INSN (0xf000b800, -4), /* b.w insn_after_original_branch. */ 2495 THUMB32_B_INSN (0xf000b800, -4) /* true: b.w original_branch_dest. */ 2496 }; 2497 2498 /* Stub used for b.w and bl.w instructions. */ 2499 2500 static const insn_sequence elf32_arm_stub_a8_veneer_b[] = 2501 { 2502 THUMB32_B_INSN (0xf000b800, -4) /* b.w original_branch_dest. */ 2503 }; 2504 2505 static const insn_sequence elf32_arm_stub_a8_veneer_bl[] = 2506 { 2507 THUMB32_B_INSN (0xf000b800, -4) /* b.w original_branch_dest. */ 2508 }; 2509 2510 /* Stub used for Thumb-2 blx.w instructions. We modified the original blx.w 2511 instruction (which switches to ARM mode) to point to this stub. Jump to the 2512 real destination using an ARM-mode branch. */ 2513 2514 static const insn_sequence elf32_arm_stub_a8_veneer_blx[] = 2515 { 2516 ARM_REL_INSN (0xea000000, -8) /* b original_branch_dest. */ 2517 }; 2518 2519 /* For each section group there can be a specially created linker section 2520 to hold the stubs for that group. The name of the stub section is based 2521 upon the name of another section within that group with the suffix below 2522 applied. 2523 2524 PR 13049: STUB_SUFFIX used to be ".stub", but this allowed the user to 2525 create what appeared to be a linker stub section when it actually 2526 contained user code/data. For example, consider this fragment: 2527 2528 const char * stubborn_problems[] = { "np" }; 2529 2530 If this is compiled with "-fPIC -fdata-sections" then gcc produces a 2531 section called: 2532 2533 .data.rel.local.stubborn_problems 2534 2535 This then causes problems in arm32_arm_build_stubs() as it triggers: 2536 2537 // Ignore non-stub sections. 2538 if (!strstr (stub_sec->name, STUB_SUFFIX)) 2539 continue; 2540 2541 And so the section would be ignored instead of being processed. Hence 2542 the change in definition of STUB_SUFFIX to a name that cannot be a valid 2543 C identifier. */ 2544 #define STUB_SUFFIX ".__stub" 2545 2546 /* One entry per long/short branch stub defined above. */ 2547 #define DEF_STUBS \ 2548 DEF_STUB(long_branch_any_any) \ 2549 DEF_STUB(long_branch_v4t_arm_thumb) \ 2550 DEF_STUB(long_branch_thumb_only) \ 2551 DEF_STUB(long_branch_v4t_thumb_thumb) \ 2552 DEF_STUB(long_branch_v4t_thumb_arm) \ 2553 DEF_STUB(short_branch_v4t_thumb_arm) \ 2554 DEF_STUB(long_branch_any_arm_pic) \ 2555 DEF_STUB(long_branch_any_thumb_pic) \ 2556 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \ 2557 DEF_STUB(long_branch_v4t_arm_thumb_pic) \ 2558 DEF_STUB(long_branch_v4t_thumb_arm_pic) \ 2559 DEF_STUB(long_branch_thumb_only_pic) \ 2560 DEF_STUB(long_branch_any_tls_pic) \ 2561 DEF_STUB(long_branch_v4t_thumb_tls_pic) \ 2562 DEF_STUB(long_branch_arm_nacl) \ 2563 DEF_STUB(long_branch_arm_nacl_pic) \ 2564 DEF_STUB(a8_veneer_b_cond) \ 2565 DEF_STUB(a8_veneer_b) \ 2566 DEF_STUB(a8_veneer_bl) \ 2567 DEF_STUB(a8_veneer_blx) 2568 2569 #define DEF_STUB(x) arm_stub_##x, 2570 enum elf32_arm_stub_type 2571 { 2572 arm_stub_none, 2573 DEF_STUBS 2574 /* Note the first a8_veneer type. */ 2575 arm_stub_a8_veneer_lwm = arm_stub_a8_veneer_b_cond 2576 }; 2577 #undef DEF_STUB 2578 2579 typedef struct 2580 { 2581 const insn_sequence* template_sequence; 2582 int template_size; 2583 } stub_def; 2584 2585 #define DEF_STUB(x) {elf32_arm_stub_##x, ARRAY_SIZE(elf32_arm_stub_##x)}, 2586 static const stub_def stub_definitions[] = 2587 { 2588 {NULL, 0}, 2589 DEF_STUBS 2590 }; 2591 2592 struct elf32_arm_stub_hash_entry 2593 { 2594 /* Base hash table entry structure. */ 2595 struct bfd_hash_entry root; 2596 2597 /* The stub section. */ 2598 asection *stub_sec; 2599 2600 /* Offset within stub_sec of the beginning of this stub. */ 2601 bfd_vma stub_offset; 2602 2603 /* Given the symbol's value and its section we can determine its final 2604 value when building the stubs (so the stub knows where to jump). */ 2605 bfd_vma target_value; 2606 asection *target_section; 2607 2608 /* Offset to apply to relocation referencing target_value. */ 2609 bfd_vma target_addend; 2610 2611 /* The instruction which caused this stub to be generated (only valid for 2612 Cortex-A8 erratum workaround stubs at present). */ 2613 unsigned long orig_insn; 2614 2615 /* The stub type. */ 2616 enum elf32_arm_stub_type stub_type; 2617 /* Its encoding size in bytes. */ 2618 int stub_size; 2619 /* Its template. */ 2620 const insn_sequence *stub_template; 2621 /* The size of the template (number of entries). */ 2622 int stub_template_size; 2623 2624 /* The symbol table entry, if any, that this was derived from. */ 2625 struct elf32_arm_link_hash_entry *h; 2626 2627 /* Type of branch. */ 2628 enum arm_st_branch_type branch_type; 2629 2630 /* Where this stub is being called from, or, in the case of combined 2631 stub sections, the first input section in the group. */ 2632 asection *id_sec; 2633 2634 /* The name for the local symbol at the start of this stub. The 2635 stub name in the hash table has to be unique; this does not, so 2636 it can be friendlier. */ 2637 char *output_name; 2638 }; 2639 2640 /* Used to build a map of a section. This is required for mixed-endian 2641 code/data. */ 2642 2643 typedef struct elf32_elf_section_map 2644 { 2645 bfd_vma vma; 2646 char type; 2647 } 2648 elf32_arm_section_map; 2649 2650 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */ 2651 2652 typedef enum 2653 { 2654 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER, 2655 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER, 2656 VFP11_ERRATUM_ARM_VENEER, 2657 VFP11_ERRATUM_THUMB_VENEER 2658 } 2659 elf32_vfp11_erratum_type; 2660 2661 typedef struct elf32_vfp11_erratum_list 2662 { 2663 struct elf32_vfp11_erratum_list *next; 2664 bfd_vma vma; 2665 union 2666 { 2667 struct 2668 { 2669 struct elf32_vfp11_erratum_list *veneer; 2670 unsigned int vfp_insn; 2671 } b; 2672 struct 2673 { 2674 struct elf32_vfp11_erratum_list *branch; 2675 unsigned int id; 2676 } v; 2677 } u; 2678 elf32_vfp11_erratum_type type; 2679 } 2680 elf32_vfp11_erratum_list; 2681 2682 typedef enum 2683 { 2684 DELETE_EXIDX_ENTRY, 2685 INSERT_EXIDX_CANTUNWIND_AT_END 2686 } 2687 arm_unwind_edit_type; 2688 2689 /* A (sorted) list of edits to apply to an unwind table. */ 2690 typedef struct arm_unwind_table_edit 2691 { 2692 arm_unwind_edit_type type; 2693 /* Note: we sometimes want to insert an unwind entry corresponding to a 2694 section different from the one we're currently writing out, so record the 2695 (text) section this edit relates to here. */ 2696 asection *linked_section; 2697 unsigned int index; 2698 struct arm_unwind_table_edit *next; 2699 } 2700 arm_unwind_table_edit; 2701 2702 typedef struct _arm_elf_section_data 2703 { 2704 /* Information about mapping symbols. */ 2705 struct bfd_elf_section_data elf; 2706 unsigned int mapcount; 2707 unsigned int mapsize; 2708 elf32_arm_section_map *map; 2709 /* Information about CPU errata. */ 2710 unsigned int erratumcount; 2711 elf32_vfp11_erratum_list *erratumlist; 2712 /* Information about unwind tables. */ 2713 union 2714 { 2715 /* Unwind info attached to a text section. */ 2716 struct 2717 { 2718 asection *arm_exidx_sec; 2719 } text; 2720 2721 /* Unwind info attached to an .ARM.exidx section. */ 2722 struct 2723 { 2724 arm_unwind_table_edit *unwind_edit_list; 2725 arm_unwind_table_edit *unwind_edit_tail; 2726 } exidx; 2727 } u; 2728 } 2729 _arm_elf_section_data; 2730 2731 #define elf32_arm_section_data(sec) \ 2732 ((_arm_elf_section_data *) elf_section_data (sec)) 2733 2734 /* A fix which might be required for Cortex-A8 Thumb-2 branch/TLB erratum. 2735 These fixes are subject to a relaxation procedure (in elf32_arm_size_stubs), 2736 so may be created multiple times: we use an array of these entries whilst 2737 relaxing which we can refresh easily, then create stubs for each potentially 2738 erratum-triggering instruction once we've settled on a solution. */ 2739 2740 struct a8_erratum_fix 2741 { 2742 bfd *input_bfd; 2743 asection *section; 2744 bfd_vma offset; 2745 bfd_vma addend; 2746 unsigned long orig_insn; 2747 char *stub_name; 2748 enum elf32_arm_stub_type stub_type; 2749 enum arm_st_branch_type branch_type; 2750 }; 2751 2752 /* A table of relocs applied to branches which might trigger Cortex-A8 2753 erratum. */ 2754 2755 struct a8_erratum_reloc 2756 { 2757 bfd_vma from; 2758 bfd_vma destination; 2759 struct elf32_arm_link_hash_entry *hash; 2760 const char *sym_name; 2761 unsigned int r_type; 2762 enum arm_st_branch_type branch_type; 2763 bfd_boolean non_a8_stub; 2764 }; 2765 2766 /* The size of the thread control block. */ 2767 #define TCB_SIZE 8 2768 2769 /* ARM-specific information about a PLT entry, over and above the usual 2770 gotplt_union. */ 2771 struct arm_plt_info 2772 { 2773 /* We reference count Thumb references to a PLT entry separately, 2774 so that we can emit the Thumb trampoline only if needed. */ 2775 bfd_signed_vma thumb_refcount; 2776 2777 /* Some references from Thumb code may be eliminated by BL->BLX 2778 conversion, so record them separately. */ 2779 bfd_signed_vma maybe_thumb_refcount; 2780 2781 /* How many of the recorded PLT accesses were from non-call relocations. 2782 This information is useful when deciding whether anything takes the 2783 address of an STT_GNU_IFUNC PLT. A value of 0 means that all 2784 non-call references to the function should resolve directly to the 2785 real runtime target. */ 2786 unsigned int noncall_refcount; 2787 2788 /* Since PLT entries have variable size if the Thumb prologue is 2789 used, we need to record the index into .got.plt instead of 2790 recomputing it from the PLT offset. */ 2791 bfd_signed_vma got_offset; 2792 }; 2793 2794 /* Information about an .iplt entry for a local STT_GNU_IFUNC symbol. */ 2795 struct arm_local_iplt_info 2796 { 2797 /* The information that is usually found in the generic ELF part of 2798 the hash table entry. */ 2799 union gotplt_union root; 2800 2801 /* The information that is usually found in the ARM-specific part of 2802 the hash table entry. */ 2803 struct arm_plt_info arm; 2804 2805 /* A list of all potential dynamic relocations against this symbol. */ 2806 struct elf_dyn_relocs *dyn_relocs; 2807 }; 2808 2809 struct elf_arm_obj_tdata 2810 { 2811 struct elf_obj_tdata root; 2812 2813 /* tls_type for each local got entry. */ 2814 char *local_got_tls_type; 2815 2816 /* GOTPLT entries for TLS descriptors. */ 2817 bfd_vma *local_tlsdesc_gotent; 2818 2819 /* Information for local symbols that need entries in .iplt. */ 2820 struct arm_local_iplt_info **local_iplt; 2821 2822 /* Zero to warn when linking objects with incompatible enum sizes. */ 2823 int no_enum_size_warning; 2824 2825 /* Zero to warn when linking objects with incompatible wchar_t sizes. */ 2826 int no_wchar_size_warning; 2827 }; 2828 2829 #define elf_arm_tdata(bfd) \ 2830 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any) 2831 2832 #define elf32_arm_local_got_tls_type(bfd) \ 2833 (elf_arm_tdata (bfd)->local_got_tls_type) 2834 2835 #define elf32_arm_local_tlsdesc_gotent(bfd) \ 2836 (elf_arm_tdata (bfd)->local_tlsdesc_gotent) 2837 2838 #define elf32_arm_local_iplt(bfd) \ 2839 (elf_arm_tdata (bfd)->local_iplt) 2840 2841 #define is_arm_elf(bfd) \ 2842 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ 2843 && elf_tdata (bfd) != NULL \ 2844 && elf_object_id (bfd) == ARM_ELF_DATA) 2845 2846 static bfd_boolean 2847 elf32_arm_mkobject (bfd *abfd) 2848 { 2849 return bfd_elf_allocate_object (abfd, sizeof (struct elf_arm_obj_tdata), 2850 ARM_ELF_DATA); 2851 } 2852 2853 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent)) 2854 2855 /* Arm ELF linker hash entry. */ 2856 struct elf32_arm_link_hash_entry 2857 { 2858 struct elf_link_hash_entry root; 2859 2860 /* Track dynamic relocs copied for this symbol. */ 2861 struct elf_dyn_relocs *dyn_relocs; 2862 2863 /* ARM-specific PLT information. */ 2864 struct arm_plt_info plt; 2865 2866 #define GOT_UNKNOWN 0 2867 #define GOT_NORMAL 1 2868 #define GOT_TLS_GD 2 2869 #define GOT_TLS_IE 4 2870 #define GOT_TLS_GDESC 8 2871 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLS_GDESC)) 2872 unsigned int tls_type : 8; 2873 2874 /* True if the symbol's PLT entry is in .iplt rather than .plt. */ 2875 unsigned int is_iplt : 1; 2876 2877 unsigned int unused : 23; 2878 2879 /* Offset of the GOTPLT entry reserved for the TLS descriptor, 2880 starting at the end of the jump table. */ 2881 bfd_vma tlsdesc_got; 2882 2883 /* The symbol marking the real symbol location for exported thumb 2884 symbols with Arm stubs. */ 2885 struct elf_link_hash_entry *export_glue; 2886 2887 /* A pointer to the most recently used stub hash entry against this 2888 symbol. */ 2889 struct elf32_arm_stub_hash_entry *stub_cache; 2890 }; 2891 2892 /* Traverse an arm ELF linker hash table. */ 2893 #define elf32_arm_link_hash_traverse(table, func, info) \ 2894 (elf_link_hash_traverse \ 2895 (&(table)->root, \ 2896 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ 2897 (info))) 2898 2899 /* Get the ARM elf linker hash table from a link_info structure. */ 2900 #define elf32_arm_hash_table(info) \ 2901 (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \ 2902 == ARM_ELF_DATA ? ((struct elf32_arm_link_hash_table *) ((info)->hash)) : NULL) 2903 2904 #define arm_stub_hash_lookup(table, string, create, copy) \ 2905 ((struct elf32_arm_stub_hash_entry *) \ 2906 bfd_hash_lookup ((table), (string), (create), (copy))) 2907 2908 /* Array to keep track of which stub sections have been created, and 2909 information on stub grouping. */ 2910 struct map_stub 2911 { 2912 /* This is the section to which stubs in the group will be 2913 attached. */ 2914 asection *link_sec; 2915 /* The stub section. */ 2916 asection *stub_sec; 2917 }; 2918 2919 #define elf32_arm_compute_jump_table_size(htab) \ 2920 ((htab)->next_tls_desc_index * 4) 2921 2922 /* ARM ELF linker hash table. */ 2923 struct elf32_arm_link_hash_table 2924 { 2925 /* The main hash table. */ 2926 struct elf_link_hash_table root; 2927 2928 /* The size in bytes of the section containing the Thumb-to-ARM glue. */ 2929 bfd_size_type thumb_glue_size; 2930 2931 /* The size in bytes of the section containing the ARM-to-Thumb glue. */ 2932 bfd_size_type arm_glue_size; 2933 2934 /* The size in bytes of section containing the ARMv4 BX veneers. */ 2935 bfd_size_type bx_glue_size; 2936 2937 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when 2938 veneer has been populated. */ 2939 bfd_vma bx_glue_offset[15]; 2940 2941 /* The size in bytes of the section containing glue for VFP11 erratum 2942 veneers. */ 2943 bfd_size_type vfp11_erratum_glue_size; 2944 2945 /* A table of fix locations for Cortex-A8 Thumb-2 branch/TLB erratum. This 2946 holds Cortex-A8 erratum fix locations between elf32_arm_size_stubs() and 2947 elf32_arm_write_section(). */ 2948 struct a8_erratum_fix *a8_erratum_fixes; 2949 unsigned int num_a8_erratum_fixes; 2950 2951 /* An arbitrary input BFD chosen to hold the glue sections. */ 2952 bfd * bfd_of_glue_owner; 2953 2954 /* Nonzero to output a BE8 image. */ 2955 int byteswap_code; 2956 2957 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32. 2958 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */ 2959 int target1_is_rel; 2960 2961 /* The relocation to use for R_ARM_TARGET2 relocations. */ 2962 int target2_reloc; 2963 2964 /* 0 = Ignore R_ARM_V4BX. 2965 1 = Convert BX to MOV PC. 2966 2 = Generate v4 interworing stubs. */ 2967 int fix_v4bx; 2968 2969 /* Whether we should fix the Cortex-A8 Thumb-2 branch/TLB erratum. */ 2970 int fix_cortex_a8; 2971 2972 /* Whether we should fix the ARM1176 BLX immediate issue. */ 2973 int fix_arm1176; 2974 2975 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */ 2976 int use_blx; 2977 2978 /* What sort of code sequences we should look for which may trigger the 2979 VFP11 denorm erratum. */ 2980 bfd_arm_vfp11_fix vfp11_fix; 2981 2982 /* Global counter for the number of fixes we have emitted. */ 2983 int num_vfp11_fixes; 2984 2985 /* Nonzero to force PIC branch veneers. */ 2986 int pic_veneer; 2987 2988 /* The number of bytes in the initial entry in the PLT. */ 2989 bfd_size_type plt_header_size; 2990 2991 /* The number of bytes in the subsequent PLT etries. */ 2992 bfd_size_type plt_entry_size; 2993 2994 /* True if the target system is VxWorks. */ 2995 int vxworks_p; 2996 2997 /* True if the target system is Symbian OS. */ 2998 int symbian_p; 2999 3000 /* True if the target system is Native Client. */ 3001 int nacl_p; 3002 3003 /* True if the target uses REL relocations. */ 3004 int use_rel; 3005 3006 /* The index of the next unused R_ARM_TLS_DESC slot in .rel.plt. */ 3007 bfd_vma next_tls_desc_index; 3008 3009 /* How many R_ARM_TLS_DESC relocations were generated so far. */ 3010 bfd_vma num_tls_desc; 3011 3012 /* Short-cuts to get to dynamic linker sections. */ 3013 asection *sdynbss; 3014 asection *srelbss; 3015 3016 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */ 3017 asection *srelplt2; 3018 3019 /* The offset into splt of the PLT entry for the TLS descriptor 3020 resolver. Special values are 0, if not necessary (or not found 3021 to be necessary yet), and -1 if needed but not determined 3022 yet. */ 3023 bfd_vma dt_tlsdesc_plt; 3024 3025 /* The offset into sgot of the GOT entry used by the PLT entry 3026 above. */ 3027 bfd_vma dt_tlsdesc_got; 3028 3029 /* Offset in .plt section of tls_arm_trampoline. */ 3030 bfd_vma tls_trampoline; 3031 3032 /* Data for R_ARM_TLS_LDM32 relocations. */ 3033 union 3034 { 3035 bfd_signed_vma refcount; 3036 bfd_vma offset; 3037 } tls_ldm_got; 3038 3039 /* Small local sym cache. */ 3040 struct sym_cache sym_cache; 3041 3042 /* For convenience in allocate_dynrelocs. */ 3043 bfd * obfd; 3044 3045 /* The amount of space used by the reserved portion of the sgotplt 3046 section, plus whatever space is used by the jump slots. */ 3047 bfd_vma sgotplt_jump_table_size; 3048 3049 /* The stub hash table. */ 3050 struct bfd_hash_table stub_hash_table; 3051 3052 /* Linker stub bfd. */ 3053 bfd *stub_bfd; 3054 3055 /* Linker call-backs. */ 3056 asection * (*add_stub_section) (const char *, asection *, unsigned int); 3057 void (*layout_sections_again) (void); 3058 3059 /* Array to keep track of which stub sections have been created, and 3060 information on stub grouping. */ 3061 struct map_stub *stub_group; 3062 3063 /* Number of elements in stub_group. */ 3064 int top_id; 3065 3066 /* Assorted information used by elf32_arm_size_stubs. */ 3067 unsigned int bfd_count; 3068 int top_index; 3069 asection **input_list; 3070 }; 3071 3072 /* Create an entry in an ARM ELF linker hash table. */ 3073 3074 static struct bfd_hash_entry * 3075 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry, 3076 struct bfd_hash_table * table, 3077 const char * string) 3078 { 3079 struct elf32_arm_link_hash_entry * ret = 3080 (struct elf32_arm_link_hash_entry *) entry; 3081 3082 /* Allocate the structure if it has not already been allocated by a 3083 subclass. */ 3084 if (ret == NULL) 3085 ret = (struct elf32_arm_link_hash_entry *) 3086 bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry)); 3087 if (ret == NULL) 3088 return (struct bfd_hash_entry *) ret; 3089 3090 /* Call the allocation method of the superclass. */ 3091 ret = ((struct elf32_arm_link_hash_entry *) 3092 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, 3093 table, string)); 3094 if (ret != NULL) 3095 { 3096 ret->dyn_relocs = NULL; 3097 ret->tls_type = GOT_UNKNOWN; 3098 ret->tlsdesc_got = (bfd_vma) -1; 3099 ret->plt.thumb_refcount = 0; 3100 ret->plt.maybe_thumb_refcount = 0; 3101 ret->plt.noncall_refcount = 0; 3102 ret->plt.got_offset = -1; 3103 ret->is_iplt = FALSE; 3104 ret->export_glue = NULL; 3105 3106 ret->stub_cache = NULL; 3107 } 3108 3109 return (struct bfd_hash_entry *) ret; 3110 } 3111 3112 /* Ensure that we have allocated bookkeeping structures for ABFD's local 3113 symbols. */ 3114 3115 static bfd_boolean 3116 elf32_arm_allocate_local_sym_info (bfd *abfd) 3117 { 3118 if (elf_local_got_refcounts (abfd) == NULL) 3119 { 3120 bfd_size_type num_syms; 3121 bfd_size_type size; 3122 char *data; 3123 3124 num_syms = elf_tdata (abfd)->symtab_hdr.sh_info; 3125 size = num_syms * (sizeof (bfd_signed_vma) 3126 + sizeof (struct arm_local_iplt_info *) 3127 + sizeof (bfd_vma) 3128 + sizeof (char)); 3129 data = bfd_zalloc (abfd, size); 3130 if (data == NULL) 3131 return FALSE; 3132 3133 elf_local_got_refcounts (abfd) = (bfd_signed_vma *) data; 3134 data += num_syms * sizeof (bfd_signed_vma); 3135 3136 elf32_arm_local_iplt (abfd) = (struct arm_local_iplt_info **) data; 3137 data += num_syms * sizeof (struct arm_local_iplt_info *); 3138 3139 elf32_arm_local_tlsdesc_gotent (abfd) = (bfd_vma *) data; 3140 data += num_syms * sizeof (bfd_vma); 3141 3142 elf32_arm_local_got_tls_type (abfd) = data; 3143 } 3144 return TRUE; 3145 } 3146 3147 /* Return the .iplt information for local symbol R_SYMNDX, which belongs 3148 to input bfd ABFD. Create the information if it doesn't already exist. 3149 Return null if an allocation fails. */ 3150 3151 static struct arm_local_iplt_info * 3152 elf32_arm_create_local_iplt (bfd *abfd, unsigned long r_symndx) 3153 { 3154 struct arm_local_iplt_info **ptr; 3155 3156 if (!elf32_arm_allocate_local_sym_info (abfd)) 3157 return NULL; 3158 3159 BFD_ASSERT (r_symndx < elf_tdata (abfd)->symtab_hdr.sh_info); 3160 ptr = &elf32_arm_local_iplt (abfd)[r_symndx]; 3161 if (*ptr == NULL) 3162 *ptr = bfd_zalloc (abfd, sizeof (**ptr)); 3163 return *ptr; 3164 } 3165 3166 /* Try to obtain PLT information for the symbol with index R_SYMNDX 3167 in ABFD's symbol table. If the symbol is global, H points to its 3168 hash table entry, otherwise H is null. 3169 3170 Return true if the symbol does have PLT information. When returning 3171 true, point *ROOT_PLT at the target-independent reference count/offset 3172 union and *ARM_PLT at the ARM-specific information. */ 3173 3174 static bfd_boolean 3175 elf32_arm_get_plt_info (bfd *abfd, struct elf32_arm_link_hash_entry *h, 3176 unsigned long r_symndx, union gotplt_union **root_plt, 3177 struct arm_plt_info **arm_plt) 3178 { 3179 struct arm_local_iplt_info *local_iplt; 3180 3181 if (h != NULL) 3182 { 3183 *root_plt = &h->root.plt; 3184 *arm_plt = &h->plt; 3185 return TRUE; 3186 } 3187 3188 if (elf32_arm_local_iplt (abfd) == NULL) 3189 return FALSE; 3190 3191 local_iplt = elf32_arm_local_iplt (abfd)[r_symndx]; 3192 if (local_iplt == NULL) 3193 return FALSE; 3194 3195 *root_plt = &local_iplt->root; 3196 *arm_plt = &local_iplt->arm; 3197 return TRUE; 3198 } 3199 3200 /* Return true if the PLT described by ARM_PLT requires a Thumb stub 3201 before it. */ 3202 3203 static bfd_boolean 3204 elf32_arm_plt_needs_thumb_stub_p (struct bfd_link_info *info, 3205 struct arm_plt_info *arm_plt) 3206 { 3207 struct elf32_arm_link_hash_table *htab; 3208 3209 htab = elf32_arm_hash_table (info); 3210 return (arm_plt->thumb_refcount != 0 3211 || (!htab->use_blx && arm_plt->maybe_thumb_refcount != 0)); 3212 } 3213 3214 /* Return a pointer to the head of the dynamic reloc list that should 3215 be used for local symbol ISYM, which is symbol number R_SYMNDX in 3216 ABFD's symbol table. Return null if an error occurs. */ 3217 3218 static struct elf_dyn_relocs ** 3219 elf32_arm_get_local_dynreloc_list (bfd *abfd, unsigned long r_symndx, 3220 Elf_Internal_Sym *isym) 3221 { 3222 if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) 3223 { 3224 struct arm_local_iplt_info *local_iplt; 3225 3226 local_iplt = elf32_arm_create_local_iplt (abfd, r_symndx); 3227 if (local_iplt == NULL) 3228 return NULL; 3229 return &local_iplt->dyn_relocs; 3230 } 3231 else 3232 { 3233 /* Track dynamic relocs needed for local syms too. 3234 We really need local syms available to do this 3235 easily. Oh well. */ 3236 asection *s; 3237 void *vpp; 3238 3239 s = bfd_section_from_elf_index (abfd, isym->st_shndx); 3240 if (s == NULL) 3241 abort (); 3242 3243 vpp = &elf_section_data (s)->local_dynrel; 3244 return (struct elf_dyn_relocs **) vpp; 3245 } 3246 } 3247 3248 /* Initialize an entry in the stub hash table. */ 3249 3250 static struct bfd_hash_entry * 3251 stub_hash_newfunc (struct bfd_hash_entry *entry, 3252 struct bfd_hash_table *table, 3253 const char *string) 3254 { 3255 /* Allocate the structure if it has not already been allocated by a 3256 subclass. */ 3257 if (entry == NULL) 3258 { 3259 entry = (struct bfd_hash_entry *) 3260 bfd_hash_allocate (table, sizeof (struct elf32_arm_stub_hash_entry)); 3261 if (entry == NULL) 3262 return entry; 3263 } 3264 3265 /* Call the allocation method of the superclass. */ 3266 entry = bfd_hash_newfunc (entry, table, string); 3267 if (entry != NULL) 3268 { 3269 struct elf32_arm_stub_hash_entry *eh; 3270 3271 /* Initialize the local fields. */ 3272 eh = (struct elf32_arm_stub_hash_entry *) entry; 3273 eh->stub_sec = NULL; 3274 eh->stub_offset = 0; 3275 eh->target_value = 0; 3276 eh->target_section = NULL; 3277 eh->target_addend = 0; 3278 eh->orig_insn = 0; 3279 eh->stub_type = arm_stub_none; 3280 eh->stub_size = 0; 3281 eh->stub_template = NULL; 3282 eh->stub_template_size = 0; 3283 eh->h = NULL; 3284 eh->id_sec = NULL; 3285 eh->output_name = NULL; 3286 } 3287 3288 return entry; 3289 } 3290 3291 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up 3292 shortcuts to them in our hash table. */ 3293 3294 static bfd_boolean 3295 create_got_section (bfd *dynobj, struct bfd_link_info *info) 3296 { 3297 struct elf32_arm_link_hash_table *htab; 3298 3299 htab = elf32_arm_hash_table (info); 3300 if (htab == NULL) 3301 return FALSE; 3302 3303 /* BPABI objects never have a GOT, or associated sections. */ 3304 if (htab->symbian_p) 3305 return TRUE; 3306 3307 if (! _bfd_elf_create_got_section (dynobj, info)) 3308 return FALSE; 3309 3310 return TRUE; 3311 } 3312 3313 /* Create the .iplt, .rel(a).iplt and .igot.plt sections. */ 3314 3315 static bfd_boolean 3316 create_ifunc_sections (struct bfd_link_info *info) 3317 { 3318 struct elf32_arm_link_hash_table *htab; 3319 const struct elf_backend_data *bed; 3320 bfd *dynobj; 3321 asection *s; 3322 flagword flags; 3323 3324 htab = elf32_arm_hash_table (info); 3325 dynobj = htab->root.dynobj; 3326 bed = get_elf_backend_data (dynobj); 3327 flags = bed->dynamic_sec_flags; 3328 3329 if (htab->root.iplt == NULL) 3330 { 3331 s = bfd_make_section_anyway_with_flags (dynobj, ".iplt", 3332 flags | SEC_READONLY | SEC_CODE); 3333 if (s == NULL 3334 || !bfd_set_section_alignment (dynobj, s, bed->plt_alignment)) 3335 return FALSE; 3336 htab->root.iplt = s; 3337 } 3338 3339 if (htab->root.irelplt == NULL) 3340 { 3341 s = bfd_make_section_anyway_with_flags (dynobj, 3342 RELOC_SECTION (htab, ".iplt"), 3343 flags | SEC_READONLY); 3344 if (s == NULL 3345 || !bfd_set_section_alignment (dynobj, s, bed->s->log_file_align)) 3346 return FALSE; 3347 htab->root.irelplt = s; 3348 } 3349 3350 if (htab->root.igotplt == NULL) 3351 { 3352 s = bfd_make_section_anyway_with_flags (dynobj, ".igot.plt", flags); 3353 if (s == NULL 3354 || !bfd_set_section_alignment (dynobj, s, bed->s->log_file_align)) 3355 return FALSE; 3356 htab->root.igotplt = s; 3357 } 3358 return TRUE; 3359 } 3360 3361 /* Determine if we're dealing with a Thumb only architecture. */ 3362 3363 static bfd_boolean 3364 using_thumb_only (struct elf32_arm_link_hash_table *globals) 3365 { 3366 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC, 3367 Tag_CPU_arch); 3368 int profile; 3369 3370 if (arch == TAG_CPU_ARCH_V6_M || arch == TAG_CPU_ARCH_V6S_M) 3371 return TRUE; 3372 3373 if (arch != TAG_CPU_ARCH_V7 && arch != TAG_CPU_ARCH_V7E_M) 3374 return FALSE; 3375 3376 profile = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC, 3377 Tag_CPU_arch_profile); 3378 3379 return profile == 'M'; 3380 } 3381 3382 /* Determine if we're dealing with a Thumb-2 object. */ 3383 3384 static bfd_boolean 3385 using_thumb2 (struct elf32_arm_link_hash_table *globals) 3386 { 3387 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC, 3388 Tag_CPU_arch); 3389 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7; 3390 } 3391 3392 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and 3393 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our 3394 hash table. */ 3395 3396 static bfd_boolean 3397 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) 3398 { 3399 struct elf32_arm_link_hash_table *htab; 3400 3401 htab = elf32_arm_hash_table (info); 3402 if (htab == NULL) 3403 return FALSE; 3404 3405 if (!htab->root.sgot && !create_got_section (dynobj, info)) 3406 return FALSE; 3407 3408 if (!_bfd_elf_create_dynamic_sections (dynobj, info)) 3409 return FALSE; 3410 3411 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss"); 3412 if (!info->shared) 3413 htab->srelbss = bfd_get_linker_section (dynobj, 3414 RELOC_SECTION (htab, ".bss")); 3415 3416 if (htab->vxworks_p) 3417 { 3418 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2)) 3419 return FALSE; 3420 3421 if (info->shared) 3422 { 3423 htab->plt_header_size = 0; 3424 htab->plt_entry_size 3425 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry); 3426 } 3427 else 3428 { 3429 htab->plt_header_size 3430 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry); 3431 htab->plt_entry_size 3432 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry); 3433 } 3434 } 3435 else 3436 { 3437 /* PR ld/16017 3438 Test for thumb only architectures. Note - we cannot just call 3439 using_thumb_only() as the attributes in the output bfd have not been 3440 initialised at this point, so instead we use the input bfd. */ 3441 bfd * saved_obfd = htab->obfd; 3442 3443 htab->obfd = dynobj; 3444 if (using_thumb_only (htab)) 3445 { 3446 htab->plt_header_size = 4 * ARRAY_SIZE (elf32_thumb2_plt0_entry); 3447 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_thumb2_plt_entry); 3448 } 3449 htab->obfd = saved_obfd; 3450 } 3451 3452 if (!htab->root.splt 3453 || !htab->root.srelplt 3454 || !htab->sdynbss 3455 || (!info->shared && !htab->srelbss)) 3456 abort (); 3457 3458 return TRUE; 3459 } 3460 3461 /* Copy the extra info we tack onto an elf_link_hash_entry. */ 3462 3463 static void 3464 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info, 3465 struct elf_link_hash_entry *dir, 3466 struct elf_link_hash_entry *ind) 3467 { 3468 struct elf32_arm_link_hash_entry *edir, *eind; 3469 3470 edir = (struct elf32_arm_link_hash_entry *) dir; 3471 eind = (struct elf32_arm_link_hash_entry *) ind; 3472 3473 if (eind->dyn_relocs != NULL) 3474 { 3475 if (edir->dyn_relocs != NULL) 3476 { 3477 struct elf_dyn_relocs **pp; 3478 struct elf_dyn_relocs *p; 3479 3480 /* Add reloc counts against the indirect sym to the direct sym 3481 list. Merge any entries against the same section. */ 3482 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) 3483 { 3484 struct elf_dyn_relocs *q; 3485 3486 for (q = edir->dyn_relocs; q != NULL; q = q->next) 3487 if (q->sec == p->sec) 3488 { 3489 q->pc_count += p->pc_count; 3490 q->count += p->count; 3491 *pp = p->next; 3492 break; 3493 } 3494 if (q == NULL) 3495 pp = &p->next; 3496 } 3497 *pp = edir->dyn_relocs; 3498 } 3499 3500 edir->dyn_relocs = eind->dyn_relocs; 3501 eind->dyn_relocs = NULL; 3502 } 3503 3504 if (ind->root.type == bfd_link_hash_indirect) 3505 { 3506 /* Copy over PLT info. */ 3507 edir->plt.thumb_refcount += eind->plt.thumb_refcount; 3508 eind->plt.thumb_refcount = 0; 3509 edir->plt.maybe_thumb_refcount += eind->plt.maybe_thumb_refcount; 3510 eind->plt.maybe_thumb_refcount = 0; 3511 edir->plt.noncall_refcount += eind->plt.noncall_refcount; 3512 eind->plt.noncall_refcount = 0; 3513 3514 /* We should only allocate a function to .iplt once the final 3515 symbol information is known. */ 3516 BFD_ASSERT (!eind->is_iplt); 3517 3518 if (dir->got.refcount <= 0) 3519 { 3520 edir->tls_type = eind->tls_type; 3521 eind->tls_type = GOT_UNKNOWN; 3522 } 3523 } 3524 3525 _bfd_elf_link_hash_copy_indirect (info, dir, ind); 3526 } 3527 3528 /* Destroy an ARM elf linker hash table. */ 3529 3530 static void 3531 elf32_arm_link_hash_table_free (bfd *obfd) 3532 { 3533 struct elf32_arm_link_hash_table *ret 3534 = (struct elf32_arm_link_hash_table *) obfd->link.hash; 3535 3536 bfd_hash_table_free (&ret->stub_hash_table); 3537 _bfd_elf_link_hash_table_free (obfd); 3538 } 3539 3540 /* Create an ARM elf linker hash table. */ 3541 3542 static struct bfd_link_hash_table * 3543 elf32_arm_link_hash_table_create (bfd *abfd) 3544 { 3545 struct elf32_arm_link_hash_table *ret; 3546 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table); 3547 3548 ret = (struct elf32_arm_link_hash_table *) bfd_zmalloc (amt); 3549 if (ret == NULL) 3550 return NULL; 3551 3552 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd, 3553 elf32_arm_link_hash_newfunc, 3554 sizeof (struct elf32_arm_link_hash_entry), 3555 ARM_ELF_DATA)) 3556 { 3557 free (ret); 3558 return NULL; 3559 } 3560 3561 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE; 3562 #ifdef FOUR_WORD_PLT 3563 ret->plt_header_size = 16; 3564 ret->plt_entry_size = 16; 3565 #else 3566 ret->plt_header_size = 20; 3567 ret->plt_entry_size = elf32_arm_use_long_plt_entry ? 16 : 12; 3568 #endif 3569 ret->use_rel = 1; 3570 ret->obfd = abfd; 3571 3572 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc, 3573 sizeof (struct elf32_arm_stub_hash_entry))) 3574 { 3575 _bfd_elf_link_hash_table_free (abfd); 3576 return NULL; 3577 } 3578 ret->root.root.hash_table_free = elf32_arm_link_hash_table_free; 3579 3580 return &ret->root.root; 3581 } 3582 3583 /* Determine what kind of NOPs are available. */ 3584 3585 static bfd_boolean 3586 arch_has_arm_nop (struct elf32_arm_link_hash_table *globals) 3587 { 3588 const int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC, 3589 Tag_CPU_arch); 3590 return arch == TAG_CPU_ARCH_V6T2 3591 || arch == TAG_CPU_ARCH_V6K 3592 || arch == TAG_CPU_ARCH_V7 3593 || arch == TAG_CPU_ARCH_V7E_M; 3594 } 3595 3596 static bfd_boolean 3597 arch_has_thumb2_nop (struct elf32_arm_link_hash_table *globals) 3598 { 3599 const int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC, 3600 Tag_CPU_arch); 3601 return (arch == TAG_CPU_ARCH_V6T2 || arch == TAG_CPU_ARCH_V7 3602 || arch == TAG_CPU_ARCH_V7E_M); 3603 } 3604 3605 static bfd_boolean 3606 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type) 3607 { 3608 switch (stub_type) 3609 { 3610 case arm_stub_long_branch_thumb_only: 3611 case arm_stub_long_branch_v4t_thumb_arm: 3612 case arm_stub_short_branch_v4t_thumb_arm: 3613 case arm_stub_long_branch_v4t_thumb_arm_pic: 3614 case arm_stub_long_branch_v4t_thumb_tls_pic: 3615 case arm_stub_long_branch_thumb_only_pic: 3616 return TRUE; 3617 case arm_stub_none: 3618 BFD_FAIL (); 3619 return FALSE; 3620 break; 3621 default: 3622 return FALSE; 3623 } 3624 } 3625 3626 /* Determine the type of stub needed, if any, for a call. */ 3627 3628 static enum elf32_arm_stub_type 3629 arm_type_of_stub (struct bfd_link_info *info, 3630 asection *input_sec, 3631 const Elf_Internal_Rela *rel, 3632 unsigned char st_type, 3633 enum arm_st_branch_type *actual_branch_type, 3634 struct elf32_arm_link_hash_entry *hash, 3635 bfd_vma destination, 3636 asection *sym_sec, 3637 bfd *input_bfd, 3638 const char *name) 3639 { 3640 bfd_vma location; 3641 bfd_signed_vma branch_offset; 3642 unsigned int r_type; 3643 struct elf32_arm_link_hash_table * globals; 3644 int thumb2; 3645 int thumb_only; 3646 enum elf32_arm_stub_type stub_type = arm_stub_none; 3647 int use_plt = 0; 3648 enum arm_st_branch_type branch_type = *actual_branch_type; 3649 union gotplt_union *root_plt; 3650 struct arm_plt_info *arm_plt; 3651 3652 if (branch_type == ST_BRANCH_LONG) 3653 return stub_type; 3654 3655 globals = elf32_arm_hash_table (info); 3656 if (globals == NULL) 3657 return stub_type; 3658 3659 thumb_only = using_thumb_only (globals); 3660 3661 thumb2 = using_thumb2 (globals); 3662 3663 /* Determine where the call point is. */ 3664 location = (input_sec->output_offset 3665 + input_sec->output_section->vma 3666 + rel->r_offset); 3667 3668 r_type = ELF32_R_TYPE (rel->r_info); 3669 3670 /* ST_BRANCH_TO_ARM is nonsense to thumb-only targets when we 3671 are considering a function call relocation. */ 3672 if (thumb_only && (r_type == R_ARM_THM_CALL || r_type == R_ARM_THM_JUMP24 3673 || r_type == R_ARM_THM_JUMP19) 3674 && branch_type == ST_BRANCH_TO_ARM) 3675 branch_type = ST_BRANCH_TO_THUMB; 3676 3677 /* For TLS call relocs, it is the caller's responsibility to provide 3678 the address of the appropriate trampoline. */ 3679 if (r_type != R_ARM_TLS_CALL 3680 && r_type != R_ARM_THM_TLS_CALL 3681 && elf32_arm_get_plt_info (input_bfd, hash, ELF32_R_SYM (rel->r_info), 3682 &root_plt, &arm_plt) 3683 && root_plt->offset != (bfd_vma) -1) 3684 { 3685 asection *splt; 3686 3687 if (hash == NULL || hash->is_iplt) 3688 splt = globals->root.iplt; 3689 else 3690 splt = globals->root.splt; 3691 if (splt != NULL) 3692 { 3693 use_plt = 1; 3694 3695 /* Note when dealing with PLT entries: the main PLT stub is in 3696 ARM mode, so if the branch is in Thumb mode, another 3697 Thumb->ARM stub will be inserted later just before the ARM 3698 PLT stub. We don't take this extra distance into account 3699 here, because if a long branch stub is needed, we'll add a 3700 Thumb->Arm one and branch directly to the ARM PLT entry 3701 because it avoids spreading offset corrections in several 3702 places. */ 3703 3704 destination = (splt->output_section->vma 3705 + splt->output_offset 3706 + root_plt->offset); 3707 st_type = STT_FUNC; 3708 branch_type = ST_BRANCH_TO_ARM; 3709 } 3710 } 3711 /* Calls to STT_GNU_IFUNC symbols should go through a PLT. */ 3712 BFD_ASSERT (st_type != STT_GNU_IFUNC); 3713 3714 branch_offset = (bfd_signed_vma)(destination - location); 3715 3716 if (r_type == R_ARM_THM_CALL || r_type == R_ARM_THM_JUMP24 3717 || r_type == R_ARM_THM_TLS_CALL || r_type == R_ARM_THM_JUMP19) 3718 { 3719 /* Handle cases where: 3720 - this call goes too far (different Thumb/Thumb2 max 3721 distance) 3722 - it's a Thumb->Arm call and blx is not available, or it's a 3723 Thumb->Arm branch (not bl). A stub is needed in this case, 3724 but only if this call is not through a PLT entry. Indeed, 3725 PLT stubs handle mode switching already. 3726 */ 3727 if ((!thumb2 3728 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET 3729 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET))) 3730 || (thumb2 3731 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET 3732 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET))) 3733 || (thumb2 3734 && (branch_offset > THM2_MAX_FWD_COND_BRANCH_OFFSET 3735 || (branch_offset < THM2_MAX_BWD_COND_BRANCH_OFFSET)) 3736 && (r_type == R_ARM_THM_JUMP19)) 3737 || (branch_type == ST_BRANCH_TO_ARM 3738 && (((r_type == R_ARM_THM_CALL 3739 || r_type == R_ARM_THM_TLS_CALL) && !globals->use_blx) 3740 || (r_type == R_ARM_THM_JUMP24) 3741 || (r_type == R_ARM_THM_JUMP19)) 3742 && !use_plt)) 3743 { 3744 if (branch_type == ST_BRANCH_TO_THUMB) 3745 { 3746 /* Thumb to thumb. */ 3747 if (!thumb_only) 3748 { 3749 stub_type = (info->shared | globals->pic_veneer) 3750 /* PIC stubs. */ 3751 ? ((globals->use_blx 3752 && (r_type == R_ARM_THM_CALL)) 3753 /* V5T and above. Stub starts with ARM code, so 3754 we must be able to switch mode before 3755 reaching it, which is only possible for 'bl' 3756 (ie R_ARM_THM_CALL relocation). */ 3757 ? arm_stub_long_branch_any_thumb_pic 3758 /* On V4T, use Thumb code only. */ 3759 : arm_stub_long_branch_v4t_thumb_thumb_pic) 3760 3761 /* non-PIC stubs. */ 3762 : ((globals->use_blx 3763 && (r_type == R_ARM_THM_CALL)) 3764 /* V5T and above. */ 3765 ? arm_stub_long_branch_any_any 3766 /* V4T. */ 3767 : arm_stub_long_branch_v4t_thumb_thumb); 3768 } 3769 else 3770 { 3771 stub_type = (info->shared | globals->pic_veneer) 3772 /* PIC stub. */ 3773 ? arm_stub_long_branch_thumb_only_pic 3774 /* non-PIC stub. */ 3775 : arm_stub_long_branch_thumb_only; 3776 } 3777 } 3778 else 3779 { 3780 /* Thumb to arm. */ 3781 if (sym_sec != NULL 3782 && sym_sec->owner != NULL 3783 && !INTERWORK_FLAG (sym_sec->owner)) 3784 { 3785 (*_bfd_error_handler) 3786 (_("%B(%s): warning: interworking not enabled.\n" 3787 " first occurrence: %B: Thumb call to ARM"), 3788 sym_sec->owner, input_bfd, name); 3789 } 3790 3791 stub_type = 3792 (info->shared | globals->pic_veneer) 3793 /* PIC stubs. */ 3794 ? (r_type == R_ARM_THM_TLS_CALL 3795 /* TLS PIC stubs. */ 3796 ? (globals->use_blx ? arm_stub_long_branch_any_tls_pic 3797 : arm_stub_long_branch_v4t_thumb_tls_pic) 3798 : ((globals->use_blx && r_type == R_ARM_THM_CALL) 3799 /* V5T PIC and above. */ 3800 ? arm_stub_long_branch_any_arm_pic 3801 /* V4T PIC stub. */ 3802 : arm_stub_long_branch_v4t_thumb_arm_pic)) 3803 3804 /* non-PIC stubs. */ 3805 : ((globals->use_blx && r_type == R_ARM_THM_CALL) 3806 /* V5T and above. */ 3807 ? arm_stub_long_branch_any_any 3808 /* V4T. */ 3809 : arm_stub_long_branch_v4t_thumb_arm); 3810 3811 /* Handle v4t short branches. */ 3812 if ((stub_type == arm_stub_long_branch_v4t_thumb_arm) 3813 && (branch_offset <= THM_MAX_FWD_BRANCH_OFFSET) 3814 && (branch_offset >= THM_MAX_BWD_BRANCH_OFFSET)) 3815 stub_type = arm_stub_short_branch_v4t_thumb_arm; 3816 } 3817 } 3818 } 3819 else if (r_type == R_ARM_CALL 3820 || r_type == R_ARM_JUMP24 3821 || r_type == R_ARM_PLT32 3822 || r_type == R_ARM_TLS_CALL) 3823 { 3824 if (branch_type == ST_BRANCH_TO_THUMB) 3825 { 3826 /* Arm to thumb. */ 3827 3828 if (sym_sec != NULL 3829 && sym_sec->owner != NULL 3830 && !INTERWORK_FLAG (sym_sec->owner)) 3831 { 3832 (*_bfd_error_handler) 3833 (_("%B(%s): warning: interworking not enabled.\n" 3834 " first occurrence: %B: ARM call to Thumb"), 3835 sym_sec->owner, input_bfd, name); 3836 } 3837 3838 /* We have an extra 2-bytes reach because of 3839 the mode change (bit 24 (H) of BLX encoding). */ 3840 if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2) 3841 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET) 3842 || (r_type == R_ARM_CALL && !globals->use_blx) 3843 || (r_type == R_ARM_JUMP24) 3844 || (r_type == R_ARM_PLT32)) 3845 { 3846 stub_type = (info->shared | globals->pic_veneer) 3847 /* PIC stubs. */ 3848 ? ((globals->use_blx) 3849 /* V5T and above. */ 3850 ? arm_stub_long_branch_any_thumb_pic 3851 /* V4T stub. */ 3852 : arm_stub_long_branch_v4t_arm_thumb_pic) 3853 3854 /* non-PIC stubs. */ 3855 : ((globals->use_blx) 3856 /* V5T and above. */ 3857 ? arm_stub_long_branch_any_any 3858 /* V4T. */ 3859 : arm_stub_long_branch_v4t_arm_thumb); 3860 } 3861 } 3862 else 3863 { 3864 /* Arm to arm. */ 3865 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET 3866 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)) 3867 { 3868 stub_type = 3869 (info->shared | globals->pic_veneer) 3870 /* PIC stubs. */ 3871 ? (r_type == R_ARM_TLS_CALL 3872 /* TLS PIC Stub. */ 3873 ? arm_stub_long_branch_any_tls_pic 3874 : (globals->nacl_p 3875 ? arm_stub_long_branch_arm_nacl_pic 3876 : arm_stub_long_branch_any_arm_pic)) 3877 /* non-PIC stubs. */ 3878 : (globals->nacl_p 3879 ? arm_stub_long_branch_arm_nacl 3880 : arm_stub_long_branch_any_any); 3881 } 3882 } 3883 } 3884 3885 /* If a stub is needed, record the actual destination type. */ 3886 if (stub_type != arm_stub_none) 3887 *actual_branch_type = branch_type; 3888 3889 return stub_type; 3890 } 3891 3892 /* Build a name for an entry in the stub hash table. */ 3893 3894 static char * 3895 elf32_arm_stub_name (const asection *input_section, 3896 const asection *sym_sec, 3897 const struct elf32_arm_link_hash_entry *hash, 3898 const Elf_Internal_Rela *rel, 3899 enum elf32_arm_stub_type stub_type) 3900 { 3901 char *stub_name; 3902 bfd_size_type len; 3903 3904 if (hash) 3905 { 3906 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 8 + 1 + 2 + 1; 3907 stub_name = (char *) bfd_malloc (len); 3908 if (stub_name != NULL) 3909 sprintf (stub_name, "%08x_%s+%x_%d", 3910 input_section->id & 0xffffffff, 3911 hash->root.root.root.string, 3912 (int) rel->r_addend & 0xffffffff, 3913 (int) stub_type); 3914 } 3915 else 3916 { 3917 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 2 + 1; 3918 stub_name = (char *) bfd_malloc (len); 3919 if (stub_name != NULL) 3920 sprintf (stub_name, "%08x_%x:%x+%x_%d", 3921 input_section->id & 0xffffffff, 3922 sym_sec->id & 0xffffffff, 3923 ELF32_R_TYPE (rel->r_info) == R_ARM_TLS_CALL 3924 || ELF32_R_TYPE (rel->r_info) == R_ARM_THM_TLS_CALL 3925 ? 0 : (int) ELF32_R_SYM (rel->r_info) & 0xffffffff, 3926 (int) rel->r_addend & 0xffffffff, 3927 (int) stub_type); 3928 } 3929 3930 return stub_name; 3931 } 3932 3933 /* Look up an entry in the stub hash. Stub entries are cached because 3934 creating the stub name takes a bit of time. */ 3935 3936 static struct elf32_arm_stub_hash_entry * 3937 elf32_arm_get_stub_entry (const asection *input_section, 3938 const asection *sym_sec, 3939 struct elf_link_hash_entry *hash, 3940 const Elf_Internal_Rela *rel, 3941 struct elf32_arm_link_hash_table *htab, 3942 enum elf32_arm_stub_type stub_type) 3943 { 3944 struct elf32_arm_stub_hash_entry *stub_entry; 3945 struct elf32_arm_link_hash_entry *h = (struct elf32_arm_link_hash_entry *) hash; 3946 const asection *id_sec; 3947 3948 if ((input_section->flags & SEC_CODE) == 0) 3949 return NULL; 3950 3951 /* If this input section is part of a group of sections sharing one 3952 stub section, then use the id of the first section in the group. 3953 Stub names need to include a section id, as there may well be 3954 more than one stub used to reach say, printf, and we need to 3955 distinguish between them. */ 3956 id_sec = htab->stub_group[input_section->id].link_sec; 3957 3958 if (h != NULL && h->stub_cache != NULL 3959 && h->stub_cache->h == h 3960 && h->stub_cache->id_sec == id_sec 3961 && h->stub_cache->stub_type == stub_type) 3962 { 3963 stub_entry = h->stub_cache; 3964 } 3965 else 3966 { 3967 char *stub_name; 3968 3969 stub_name = elf32_arm_stub_name (id_sec, sym_sec, h, rel, stub_type); 3970 if (stub_name == NULL) 3971 return NULL; 3972 3973 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, 3974 stub_name, FALSE, FALSE); 3975 if (h != NULL) 3976 h->stub_cache = stub_entry; 3977 3978 free (stub_name); 3979 } 3980 3981 return stub_entry; 3982 } 3983 3984 /* Find or create a stub section. Returns a pointer to the stub section, and 3985 the section to which the stub section will be attached (in *LINK_SEC_P). 3986 LINK_SEC_P may be NULL. */ 3987 3988 static asection * 3989 elf32_arm_create_or_find_stub_sec (asection **link_sec_p, asection *section, 3990 struct elf32_arm_link_hash_table *htab) 3991 { 3992 asection *link_sec; 3993 asection *stub_sec; 3994 3995 link_sec = htab->stub_group[section->id].link_sec; 3996 BFD_ASSERT (link_sec != NULL); 3997 stub_sec = htab->stub_group[section->id].stub_sec; 3998 3999 if (stub_sec == NULL) 4000 { 4001 stub_sec = htab->stub_group[link_sec->id].stub_sec; 4002 if (stub_sec == NULL) 4003 { 4004 size_t namelen; 4005 bfd_size_type len; 4006 char *s_name; 4007 4008 namelen = strlen (link_sec->name); 4009 len = namelen + sizeof (STUB_SUFFIX); 4010 s_name = (char *) bfd_alloc (htab->stub_bfd, len); 4011 if (s_name == NULL) 4012 return NULL; 4013 4014 memcpy (s_name, link_sec->name, namelen); 4015 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); 4016 stub_sec = (*htab->add_stub_section) (s_name, link_sec, 4017 htab->nacl_p ? 4 : 3); 4018 if (stub_sec == NULL) 4019 return NULL; 4020 htab->stub_group[link_sec->id].stub_sec = stub_sec; 4021 } 4022 htab->stub_group[section->id].stub_sec = stub_sec; 4023 } 4024 4025 if (link_sec_p) 4026 *link_sec_p = link_sec; 4027 4028 return stub_sec; 4029 } 4030 4031 /* Add a new stub entry to the stub hash. Not all fields of the new 4032 stub entry are initialised. */ 4033 4034 static struct elf32_arm_stub_hash_entry * 4035 elf32_arm_add_stub (const char *stub_name, 4036 asection *section, 4037 struct elf32_arm_link_hash_table *htab) 4038 { 4039 asection *link_sec; 4040 asection *stub_sec; 4041 struct elf32_arm_stub_hash_entry *stub_entry; 4042 4043 stub_sec = elf32_arm_create_or_find_stub_sec (&link_sec, section, htab); 4044 if (stub_sec == NULL) 4045 return NULL; 4046 4047 /* Enter this entry into the linker stub hash table. */ 4048 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name, 4049 TRUE, FALSE); 4050 if (stub_entry == NULL) 4051 { 4052 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"), 4053 section->owner, 4054 stub_name); 4055 return NULL; 4056 } 4057 4058 stub_entry->stub_sec = stub_sec; 4059 stub_entry->stub_offset = 0; 4060 stub_entry->id_sec = link_sec; 4061 4062 return stub_entry; 4063 } 4064 4065 /* Store an Arm insn into an output section not processed by 4066 elf32_arm_write_section. */ 4067 4068 static void 4069 put_arm_insn (struct elf32_arm_link_hash_table * htab, 4070 bfd * output_bfd, bfd_vma val, void * ptr) 4071 { 4072 if (htab->byteswap_code != bfd_little_endian (output_bfd)) 4073 bfd_putl32 (val, ptr); 4074 else 4075 bfd_putb32 (val, ptr); 4076 } 4077 4078 /* Store a 16-bit Thumb insn into an output section not processed by 4079 elf32_arm_write_section. */ 4080 4081 static void 4082 put_thumb_insn (struct elf32_arm_link_hash_table * htab, 4083 bfd * output_bfd, bfd_vma val, void * ptr) 4084 { 4085 if (htab->byteswap_code != bfd_little_endian (output_bfd)) 4086 bfd_putl16 (val, ptr); 4087 else 4088 bfd_putb16 (val, ptr); 4089 } 4090 4091 /* If it's possible to change R_TYPE to a more efficient access 4092 model, return the new reloc type. */ 4093 4094 static unsigned 4095 elf32_arm_tls_transition (struct bfd_link_info *info, int r_type, 4096 struct elf_link_hash_entry *h) 4097 { 4098 int is_local = (h == NULL); 4099 4100 if (info->shared || (h && h->root.type == bfd_link_hash_undefweak)) 4101 return r_type; 4102 4103 /* We do not support relaxations for Old TLS models. */ 4104 switch (r_type) 4105 { 4106 case R_ARM_TLS_GOTDESC: 4107 case R_ARM_TLS_CALL: 4108 case R_ARM_THM_TLS_CALL: 4109 case R_ARM_TLS_DESCSEQ: 4110 case R_ARM_THM_TLS_DESCSEQ: 4111 return is_local ? R_ARM_TLS_LE32 : R_ARM_TLS_IE32; 4112 } 4113 4114 return r_type; 4115 } 4116 4117 static bfd_reloc_status_type elf32_arm_final_link_relocate 4118 (reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *, 4119 Elf_Internal_Rela *, bfd_vma, struct bfd_link_info *, asection *, 4120 const char *, unsigned char, enum arm_st_branch_type, 4121 struct elf_link_hash_entry *, bfd_boolean *, char **); 4122 4123 static unsigned int 4124 arm_stub_required_alignment (enum elf32_arm_stub_type stub_type) 4125 { 4126 switch (stub_type) 4127 { 4128 case arm_stub_a8_veneer_b_cond: 4129 case arm_stub_a8_veneer_b: 4130 case arm_stub_a8_veneer_bl: 4131 return 2; 4132 4133 case arm_stub_long_branch_any_any: 4134 case arm_stub_long_branch_v4t_arm_thumb: 4135 case arm_stub_long_branch_thumb_only: 4136 case arm_stub_long_branch_v4t_thumb_thumb: 4137 case arm_stub_long_branch_v4t_thumb_arm: 4138 case arm_stub_short_branch_v4t_thumb_arm: 4139 case arm_stub_long_branch_any_arm_pic: 4140 case arm_stub_long_branch_any_thumb_pic: 4141 case arm_stub_long_branch_v4t_thumb_thumb_pic: 4142 case arm_stub_long_branch_v4t_arm_thumb_pic: 4143 case arm_stub_long_branch_v4t_thumb_arm_pic: 4144 case arm_stub_long_branch_thumb_only_pic: 4145 case arm_stub_long_branch_any_tls_pic: 4146 case arm_stub_long_branch_v4t_thumb_tls_pic: 4147 case arm_stub_a8_veneer_blx: 4148 return 4; 4149 4150 case arm_stub_long_branch_arm_nacl: 4151 case arm_stub_long_branch_arm_nacl_pic: 4152 return 16; 4153 4154 default: 4155 abort (); /* Should be unreachable. */ 4156 } 4157 } 4158 4159 static bfd_boolean 4160 arm_build_one_stub (struct bfd_hash_entry *gen_entry, 4161 void * in_arg) 4162 { 4163 #define MAXRELOCS 3 4164 struct elf32_arm_stub_hash_entry *stub_entry; 4165 struct elf32_arm_link_hash_table *globals; 4166 struct bfd_link_info *info; 4167 asection *stub_sec; 4168 bfd *stub_bfd; 4169 bfd_byte *loc; 4170 bfd_vma sym_value; 4171 int template_size; 4172 int size; 4173 const insn_sequence *template_sequence; 4174 int i; 4175 int stub_reloc_idx[MAXRELOCS] = {-1, -1}; 4176 int stub_reloc_offset[MAXRELOCS] = {0, 0}; 4177 int nrelocs = 0; 4178 4179 /* Massage our args to the form they really have. */ 4180 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry; 4181 info = (struct bfd_link_info *) in_arg; 4182 4183 globals = elf32_arm_hash_table (info); 4184 if (globals == NULL) 4185 return FALSE; 4186 4187 stub_sec = stub_entry->stub_sec; 4188 4189 if ((globals->fix_cortex_a8 < 0) 4190 != (arm_stub_required_alignment (stub_entry->stub_type) == 2)) 4191 /* We have to do less-strictly-aligned fixes last. */ 4192 return TRUE; 4193 4194 /* Make a note of the offset within the stubs for this entry. */ 4195 stub_entry->stub_offset = stub_sec->size; 4196 loc = stub_sec->contents + stub_entry->stub_offset; 4197 4198 stub_bfd = stub_sec->owner; 4199 4200 /* This is the address of the stub destination. */ 4201 sym_value = (stub_entry->target_value 4202 + stub_entry->target_section->output_offset 4203 + stub_entry->target_section->output_section->vma); 4204 4205 template_sequence = stub_entry->stub_template; 4206 template_size = stub_entry->stub_template_size; 4207 4208 size = 0; 4209 for (i = 0; i < template_size; i++) 4210 { 4211 switch (template_sequence[i].type) 4212 { 4213 case THUMB16_TYPE: 4214 { 4215 bfd_vma data = (bfd_vma) template_sequence[i].data; 4216 if (template_sequence[i].reloc_addend != 0) 4217 { 4218 /* We've borrowed the reloc_addend field to mean we should 4219 insert a condition code into this (Thumb-1 branch) 4220 instruction. See THUMB16_BCOND_INSN. */ 4221 BFD_ASSERT ((data & 0xff00) == 0xd000); 4222 data |= ((stub_entry->orig_insn >> 22) & 0xf) << 8; 4223 } 4224 bfd_put_16 (stub_bfd, data, loc + size); 4225 size += 2; 4226 } 4227 break; 4228 4229 case THUMB32_TYPE: 4230 bfd_put_16 (stub_bfd, 4231 (template_sequence[i].data >> 16) & 0xffff, 4232 loc + size); 4233 bfd_put_16 (stub_bfd, template_sequence[i].data & 0xffff, 4234 loc + size + 2); 4235 if (template_sequence[i].r_type != R_ARM_NONE) 4236 { 4237 stub_reloc_idx[nrelocs] = i; 4238 stub_reloc_offset[nrelocs++] = size; 4239 } 4240 size += 4; 4241 break; 4242 4243 case ARM_TYPE: 4244 bfd_put_32 (stub_bfd, template_sequence[i].data, 4245 loc + size); 4246 /* Handle cases where the target is encoded within the 4247 instruction. */ 4248 if (template_sequence[i].r_type == R_ARM_JUMP24) 4249 { 4250 stub_reloc_idx[nrelocs] = i; 4251 stub_reloc_offset[nrelocs++] = size; 4252 } 4253 size += 4; 4254 break; 4255 4256 case DATA_TYPE: 4257 bfd_put_32 (stub_bfd, template_sequence[i].data, loc + size); 4258 stub_reloc_idx[nrelocs] = i; 4259 stub_reloc_offset[nrelocs++] = size; 4260 size += 4; 4261 break; 4262 4263 default: 4264 BFD_FAIL (); 4265 return FALSE; 4266 } 4267 } 4268 4269 stub_sec->size += size; 4270 4271 /* Stub size has already been computed in arm_size_one_stub. Check 4272 consistency. */ 4273 BFD_ASSERT (size == stub_entry->stub_size); 4274 4275 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */ 4276 if (stub_entry->branch_type == ST_BRANCH_TO_THUMB) 4277 sym_value |= 1; 4278 4279 /* Assume there is at least one and at most MAXRELOCS entries to relocate 4280 in each stub. */ 4281 BFD_ASSERT (nrelocs != 0 && nrelocs <= MAXRELOCS); 4282 4283 for (i = 0; i < nrelocs; i++) 4284 if (template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_JUMP24 4285 || template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_JUMP19 4286 || template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_CALL 4287 || template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_XPC22) 4288 { 4289 Elf_Internal_Rela rel; 4290 bfd_boolean unresolved_reloc; 4291 char *error_message; 4292 enum arm_st_branch_type branch_type 4293 = (template_sequence[stub_reloc_idx[i]].r_type != R_ARM_THM_XPC22 4294 ? ST_BRANCH_TO_THUMB : ST_BRANCH_TO_ARM); 4295 bfd_vma points_to = sym_value + stub_entry->target_addend; 4296 4297 rel.r_offset = stub_entry->stub_offset + stub_reloc_offset[i]; 4298 rel.r_info = ELF32_R_INFO (0, 4299 template_sequence[stub_reloc_idx[i]].r_type); 4300 rel.r_addend = template_sequence[stub_reloc_idx[i]].reloc_addend; 4301 4302 if (stub_entry->stub_type == arm_stub_a8_veneer_b_cond && i == 0) 4303 /* The first relocation in the elf32_arm_stub_a8_veneer_b_cond[] 4304 template should refer back to the instruction after the original 4305 branch. */ 4306 points_to = sym_value; 4307 4308 /* There may be unintended consequences if this is not true. */ 4309 BFD_ASSERT (stub_entry->h == NULL); 4310 4311 /* Note: _bfd_final_link_relocate doesn't handle these relocations 4312 properly. We should probably use this function unconditionally, 4313 rather than only for certain relocations listed in the enclosing 4314 conditional, for the sake of consistency. */ 4315 elf32_arm_final_link_relocate (elf32_arm_howto_from_type 4316 (template_sequence[stub_reloc_idx[i]].r_type), 4317 stub_bfd, info->output_bfd, stub_sec, stub_sec->contents, &rel, 4318 points_to, info, stub_entry->target_section, "", STT_FUNC, 4319 branch_type, (struct elf_link_hash_entry *) stub_entry->h, 4320 &unresolved_reloc, &error_message); 4321 } 4322 else 4323 { 4324 Elf_Internal_Rela rel; 4325 bfd_boolean unresolved_reloc; 4326 char *error_message; 4327 bfd_vma points_to = sym_value + stub_entry->target_addend 4328 + template_sequence[stub_reloc_idx[i]].reloc_addend; 4329 4330 rel.r_offset = stub_entry->stub_offset + stub_reloc_offset[i]; 4331 rel.r_info = ELF32_R_INFO (0, 4332 template_sequence[stub_reloc_idx[i]].r_type); 4333 rel.r_addend = 0; 4334 4335 elf32_arm_final_link_relocate (elf32_arm_howto_from_type 4336 (template_sequence[stub_reloc_idx[i]].r_type), 4337 stub_bfd, info->output_bfd, stub_sec, stub_sec->contents, &rel, 4338 points_to, info, stub_entry->target_section, "", STT_FUNC, 4339 stub_entry->branch_type, 4340 (struct elf_link_hash_entry *) stub_entry->h, &unresolved_reloc, 4341 &error_message); 4342 } 4343 4344 return TRUE; 4345 #undef MAXRELOCS 4346 } 4347 4348 /* Calculate the template, template size and instruction size for a stub. 4349 Return value is the instruction size. */ 4350 4351 static unsigned int 4352 find_stub_size_and_template (enum elf32_arm_stub_type stub_type, 4353 const insn_sequence **stub_template, 4354 int *stub_template_size) 4355 { 4356 const insn_sequence *template_sequence = NULL; 4357 int template_size = 0, i; 4358 unsigned int size; 4359 4360 template_sequence = stub_definitions[stub_type].template_sequence; 4361 if (stub_template) 4362 *stub_template = template_sequence; 4363 4364 template_size = stub_definitions[stub_type].template_size; 4365 if (stub_template_size) 4366 *stub_template_size = template_size; 4367 4368 size = 0; 4369 for (i = 0; i < template_size; i++) 4370 { 4371 switch (template_sequence[i].type) 4372 { 4373 case THUMB16_TYPE: 4374 size += 2; 4375 break; 4376 4377 case ARM_TYPE: 4378 case THUMB32_TYPE: 4379 case DATA_TYPE: 4380 size += 4; 4381 break; 4382 4383 default: 4384 BFD_FAIL (); 4385 return 0; 4386 } 4387 } 4388 4389 return size; 4390 } 4391 4392 /* As above, but don't actually build the stub. Just bump offset so 4393 we know stub section sizes. */ 4394 4395 static bfd_boolean 4396 arm_size_one_stub (struct bfd_hash_entry *gen_entry, 4397 void *in_arg ATTRIBUTE_UNUSED) 4398 { 4399 struct elf32_arm_stub_hash_entry *stub_entry; 4400 const insn_sequence *template_sequence; 4401 int template_size, size; 4402 4403 /* Massage our args to the form they really have. */ 4404 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry; 4405 4406 BFD_ASSERT((stub_entry->stub_type > arm_stub_none) 4407 && stub_entry->stub_type < ARRAY_SIZE(stub_definitions)); 4408 4409 size = find_stub_size_and_template (stub_entry->stub_type, &template_sequence, 4410 &template_size); 4411 4412 stub_entry->stub_size = size; 4413 stub_entry->stub_template = template_sequence; 4414 stub_entry->stub_template_size = template_size; 4415 4416 size = (size + 7) & ~7; 4417 stub_entry->stub_sec->size += size; 4418 4419 return TRUE; 4420 } 4421 4422 /* External entry points for sizing and building linker stubs. */ 4423 4424 /* Set up various things so that we can make a list of input sections 4425 for each output section included in the link. Returns -1 on error, 4426 0 when no stubs will be needed, and 1 on success. */ 4427 4428 int 4429 elf32_arm_setup_section_lists (bfd *output_bfd, 4430 struct bfd_link_info *info) 4431 { 4432 bfd *input_bfd; 4433 unsigned int bfd_count; 4434 int top_id, top_index; 4435 asection *section; 4436 asection **input_list, **list; 4437 bfd_size_type amt; 4438 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info); 4439 4440 if (htab == NULL) 4441 return 0; 4442 if (! is_elf_hash_table (htab)) 4443 return 0; 4444 4445 /* Count the number of input BFDs and find the top input section id. */ 4446 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0; 4447 input_bfd != NULL; 4448 input_bfd = input_bfd->link.next) 4449 { 4450 bfd_count += 1; 4451 for (section = input_bfd->sections; 4452 section != NULL; 4453 section = section->next) 4454 { 4455 if (top_id < section->id) 4456 top_id = section->id; 4457 } 4458 } 4459 htab->bfd_count = bfd_count; 4460 4461 amt = sizeof (struct map_stub) * (top_id + 1); 4462 htab->stub_group = (struct map_stub *) bfd_zmalloc (amt); 4463 if (htab->stub_group == NULL) 4464 return -1; 4465 htab->top_id = top_id; 4466 4467 /* We can't use output_bfd->section_count here to find the top output 4468 section index as some sections may have been removed, and 4469 _bfd_strip_section_from_output doesn't renumber the indices. */ 4470 for (section = output_bfd->sections, top_index = 0; 4471 section != NULL; 4472 section = section->next) 4473 { 4474 if (top_index < section->index) 4475 top_index = section->index; 4476 } 4477 4478 htab->top_index = top_index; 4479 amt = sizeof (asection *) * (top_index + 1); 4480 input_list = (asection **) bfd_malloc (amt); 4481 htab->input_list = input_list; 4482 if (input_list == NULL) 4483 return -1; 4484 4485 /* For sections we aren't interested in, mark their entries with a 4486 value we can check later. */ 4487 list = input_list + top_index; 4488 do 4489 *list = bfd_abs_section_ptr; 4490 while (list-- != input_list); 4491 4492 for (section = output_bfd->sections; 4493 section != NULL; 4494 section = section->next) 4495 { 4496 if ((section->flags & SEC_CODE) != 0) 4497 input_list[section->index] = NULL; 4498 } 4499 4500 return 1; 4501 } 4502 4503 /* The linker repeatedly calls this function for each input section, 4504 in the order that input sections are linked into output sections. 4505 Build lists of input sections to determine groupings between which 4506 we may insert linker stubs. */ 4507 4508 void 4509 elf32_arm_next_input_section (struct bfd_link_info *info, 4510 asection *isec) 4511 { 4512 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info); 4513 4514 if (htab == NULL) 4515 return; 4516 4517 if (isec->output_section->index <= htab->top_index) 4518 { 4519 asection **list = htab->input_list + isec->output_section->index; 4520 4521 if (*list != bfd_abs_section_ptr && (isec->flags & SEC_CODE) != 0) 4522 { 4523 /* Steal the link_sec pointer for our list. */ 4524 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) 4525 /* This happens to make the list in reverse order, 4526 which we reverse later. */ 4527 PREV_SEC (isec) = *list; 4528 *list = isec; 4529 } 4530 } 4531 } 4532 4533 /* See whether we can group stub sections together. Grouping stub 4534 sections may result in fewer stubs. More importantly, we need to 4535 put all .init* and .fini* stubs at the end of the .init or 4536 .fini output sections respectively, because glibc splits the 4537 _init and _fini functions into multiple parts. Putting a stub in 4538 the middle of a function is not a good idea. */ 4539 4540 static void 4541 group_sections (struct elf32_arm_link_hash_table *htab, 4542 bfd_size_type stub_group_size, 4543 bfd_boolean stubs_always_after_branch) 4544 { 4545 asection **list = htab->input_list; 4546 4547 do 4548 { 4549 asection *tail = *list; 4550 asection *head; 4551 4552 if (tail == bfd_abs_section_ptr) 4553 continue; 4554 4555 /* Reverse the list: we must avoid placing stubs at the 4556 beginning of the section because the beginning of the text 4557 section may be required for an interrupt vector in bare metal 4558 code. */ 4559 #define NEXT_SEC PREV_SEC 4560 head = NULL; 4561 while (tail != NULL) 4562 { 4563 /* Pop from tail. */ 4564 asection *item = tail; 4565 tail = PREV_SEC (item); 4566 4567 /* Push on head. */ 4568 NEXT_SEC (item) = head; 4569 head = item; 4570 } 4571 4572 while (head != NULL) 4573 { 4574 asection *curr; 4575 asection *next; 4576 bfd_vma stub_group_start = head->output_offset; 4577 bfd_vma end_of_next; 4578 4579 curr = head; 4580 while (NEXT_SEC (curr) != NULL) 4581 { 4582 next = NEXT_SEC (curr); 4583 end_of_next = next->output_offset + next->size; 4584 if (end_of_next - stub_group_start >= stub_group_size) 4585 /* End of NEXT is too far from start, so stop. */ 4586 break; 4587 /* Add NEXT to the group. */ 4588 curr = next; 4589 } 4590 4591 /* OK, the size from the start to the start of CURR is less 4592 than stub_group_size and thus can be handled by one stub 4593 section. (Or the head section is itself larger than 4594 stub_group_size, in which case we may be toast.) 4595 We should really be keeping track of the total size of 4596 stubs added here, as stubs contribute to the final output 4597 section size. */ 4598 do 4599 { 4600 next = NEXT_SEC (head); 4601 /* Set up this stub group. */ 4602 htab->stub_group[head->id].link_sec = curr; 4603 } 4604 while (head != curr && (head = next) != NULL); 4605 4606 /* But wait, there's more! Input sections up to stub_group_size 4607 bytes after the stub section can be handled by it too. */ 4608 if (!stubs_always_after_branch) 4609 { 4610 stub_group_start = curr->output_offset + curr->size; 4611 4612 while (next != NULL) 4613 { 4614 end_of_next = next->output_offset + next->size; 4615 if (end_of_next - stub_group_start >= stub_group_size) 4616 /* End of NEXT is too far from stubs, so stop. */ 4617 break; 4618 /* Add NEXT to the stub group. */ 4619 head = next; 4620 next = NEXT_SEC (head); 4621 htab->stub_group[head->id].link_sec = curr; 4622 } 4623 } 4624 head = next; 4625 } 4626 } 4627 while (list++ != htab->input_list + htab->top_index); 4628 4629 free (htab->input_list); 4630 #undef PREV_SEC 4631 #undef NEXT_SEC 4632 } 4633 4634 /* Comparison function for sorting/searching relocations relating to Cortex-A8 4635 erratum fix. */ 4636 4637 static int 4638 a8_reloc_compare (const void *a, const void *b) 4639 { 4640 const struct a8_erratum_reloc *ra = (const struct a8_erratum_reloc *) a; 4641 const struct a8_erratum_reloc *rb = (const struct a8_erratum_reloc *) b; 4642 4643 if (ra->from < rb->from) 4644 return -1; 4645 else if (ra->from > rb->from) 4646 return 1; 4647 else 4648 return 0; 4649 } 4650 4651 static struct elf_link_hash_entry *find_thumb_glue (struct bfd_link_info *, 4652 const char *, char **); 4653 4654 /* Helper function to scan code for sequences which might trigger the Cortex-A8 4655 branch/TLB erratum. Fill in the table described by A8_FIXES_P, 4656 NUM_A8_FIXES_P, A8_FIX_TABLE_SIZE_P. Returns true if an error occurs, false 4657 otherwise. */ 4658 4659 static bfd_boolean 4660 cortex_a8_erratum_scan (bfd *input_bfd, 4661 struct bfd_link_info *info, 4662 struct a8_erratum_fix **a8_fixes_p, 4663 unsigned int *num_a8_fixes_p, 4664 unsigned int *a8_fix_table_size_p, 4665 struct a8_erratum_reloc *a8_relocs, 4666 unsigned int num_a8_relocs, 4667 unsigned prev_num_a8_fixes, 4668 bfd_boolean *stub_changed_p) 4669 { 4670 asection *section; 4671 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info); 4672 struct a8_erratum_fix *a8_fixes = *a8_fixes_p; 4673 unsigned int num_a8_fixes = *num_a8_fixes_p; 4674 unsigned int a8_fix_table_size = *a8_fix_table_size_p; 4675 4676 if (htab == NULL) 4677 return FALSE; 4678 4679 for (section = input_bfd->sections; 4680 section != NULL; 4681 section = section->next) 4682 { 4683 bfd_byte *contents = NULL; 4684 struct _arm_elf_section_data *sec_data; 4685 unsigned int span; 4686 bfd_vma base_vma; 4687 4688 if (elf_section_type (section) != SHT_PROGBITS 4689 || (elf_section_flags (section) & SHF_EXECINSTR) == 0 4690 || (section->flags & SEC_EXCLUDE) != 0 4691 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) 4692 || (section->output_section == bfd_abs_section_ptr)) 4693 continue; 4694 4695 base_vma = section->output_section->vma + section->output_offset; 4696 4697 if (elf_section_data (section)->this_hdr.contents != NULL) 4698 contents = elf_section_data (section)->this_hdr.contents; 4699 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents)) 4700 return TRUE; 4701 4702 sec_data = elf32_arm_section_data (section); 4703 4704 for (span = 0; span < sec_data->mapcount; span++) 4705 { 4706 unsigned int span_start = sec_data->map[span].vma; 4707 unsigned int span_end = (span == sec_data->mapcount - 1) 4708 ? section->size : sec_data->map[span + 1].vma; 4709 unsigned int i; 4710 char span_type = sec_data->map[span].type; 4711 bfd_boolean last_was_32bit = FALSE, last_was_branch = FALSE; 4712 4713 if (span_type != 't') 4714 continue; 4715 4716 /* Span is entirely within a single 4KB region: skip scanning. */ 4717 if (((base_vma + span_start) & ~0xfff) 4718 == ((base_vma + span_end) & ~0xfff)) 4719 continue; 4720 4721 /* Scan for 32-bit Thumb-2 branches which span two 4K regions, where: 4722 4723 * The opcode is BLX.W, BL.W, B.W, Bcc.W 4724 * The branch target is in the same 4KB region as the 4725 first half of the branch. 4726 * The instruction before the branch is a 32-bit 4727 length non-branch instruction. */ 4728 for (i = span_start; i < span_end;) 4729 { 4730 unsigned int insn = bfd_getl16 (&contents[i]); 4731 bfd_boolean insn_32bit = FALSE, is_blx = FALSE, is_b = FALSE; 4732 bfd_boolean is_bl = FALSE, is_bcc = FALSE, is_32bit_branch; 4733 4734 if ((insn & 0xe000) == 0xe000 && (insn & 0x1800) != 0x0000) 4735 insn_32bit = TRUE; 4736 4737 if (insn_32bit) 4738 { 4739 /* Load the rest of the insn (in manual-friendly order). */ 4740 insn = (insn << 16) | bfd_getl16 (&contents[i + 2]); 4741 4742 /* Encoding T4: B<c>.W. */ 4743 is_b = (insn & 0xf800d000) == 0xf0009000; 4744 /* Encoding T1: BL<c>.W. */ 4745 is_bl = (insn & 0xf800d000) == 0xf000d000; 4746 /* Encoding T2: BLX<c>.W. */ 4747 is_blx = (insn & 0xf800d000) == 0xf000c000; 4748 /* Encoding T3: B<c>.W (not permitted in IT block). */ 4749 is_bcc = (insn & 0xf800d000) == 0xf0008000 4750 && (insn & 0x07f00000) != 0x03800000; 4751 } 4752 4753 is_32bit_branch = is_b || is_bl || is_blx || is_bcc; 4754 4755 if (((base_vma + i) & 0xfff) == 0xffe 4756 && insn_32bit 4757 && is_32bit_branch 4758 && last_was_32bit 4759 && ! last_was_branch) 4760 { 4761 bfd_signed_vma offset = 0; 4762 bfd_boolean force_target_arm = FALSE; 4763 bfd_boolean force_target_thumb = FALSE; 4764 bfd_vma target; 4765 enum elf32_arm_stub_type stub_type = arm_stub_none; 4766 struct a8_erratum_reloc key, *found; 4767 bfd_boolean use_plt = FALSE; 4768 4769 key.from = base_vma + i; 4770 found = (struct a8_erratum_reloc *) 4771 bsearch (&key, a8_relocs, num_a8_relocs, 4772 sizeof (struct a8_erratum_reloc), 4773 &a8_reloc_compare); 4774 4775 if (found) 4776 { 4777 char *error_message = NULL; 4778 struct elf_link_hash_entry *entry; 4779 4780 /* We don't care about the error returned from this 4781 function, only if there is glue or not. */ 4782 entry = find_thumb_glue (info, found->sym_name, 4783 &error_message); 4784 4785 if (entry) 4786 found->non_a8_stub = TRUE; 4787 4788 /* Keep a simpler condition, for the sake of clarity. */ 4789 if (htab->root.splt != NULL && found->hash != NULL 4790 && found->hash->root.plt.offset != (bfd_vma) -1) 4791 use_plt = TRUE; 4792 4793 if (found->r_type == R_ARM_THM_CALL) 4794 { 4795 if (found->branch_type == ST_BRANCH_TO_ARM 4796 || use_plt) 4797 force_target_arm = TRUE; 4798 else 4799 force_target_thumb = TRUE; 4800 } 4801 } 4802 4803 /* Check if we have an offending branch instruction. */ 4804 4805 if (found && found->non_a8_stub) 4806 /* We've already made a stub for this instruction, e.g. 4807 it's a long branch or a Thumb->ARM stub. Assume that 4808 stub will suffice to work around the A8 erratum (see 4809 setting of always_after_branch above). */ 4810 ; 4811 else if (is_bcc) 4812 { 4813 offset = (insn & 0x7ff) << 1; 4814 offset |= (insn & 0x3f0000) >> 4; 4815 offset |= (insn & 0x2000) ? 0x40000 : 0; 4816 offset |= (insn & 0x800) ? 0x80000 : 0; 4817 offset |= (insn & 0x4000000) ? 0x100000 : 0; 4818 if (offset & 0x100000) 4819 offset |= ~ ((bfd_signed_vma) 0xfffff); 4820 stub_type = arm_stub_a8_veneer_b_cond; 4821 } 4822 else if (is_b || is_bl || is_blx) 4823 { 4824 int s = (insn & 0x4000000) != 0; 4825 int j1 = (insn & 0x2000) != 0; 4826 int j2 = (insn & 0x800) != 0; 4827 int i1 = !(j1 ^ s); 4828 int i2 = !(j2 ^ s); 4829 4830 offset = (insn & 0x7ff) << 1; 4831 offset |= (insn & 0x3ff0000) >> 4; 4832 offset |= i2 << 22; 4833 offset |= i1 << 23; 4834 offset |= s << 24; 4835 if (offset & 0x1000000) 4836 offset |= ~ ((bfd_signed_vma) 0xffffff); 4837 4838 if (is_blx) 4839 offset &= ~ ((bfd_signed_vma) 3); 4840 4841 stub_type = is_blx ? arm_stub_a8_veneer_blx : 4842 is_bl ? arm_stub_a8_veneer_bl : arm_stub_a8_veneer_b; 4843 } 4844 4845 if (stub_type != arm_stub_none) 4846 { 4847 bfd_vma pc_for_insn = base_vma + i + 4; 4848 4849 /* The original instruction is a BL, but the target is 4850 an ARM instruction. If we were not making a stub, 4851 the BL would have been converted to a BLX. Use the 4852 BLX stub instead in that case. */ 4853 if (htab->use_blx && force_target_arm 4854 && stub_type == arm_stub_a8_veneer_bl) 4855 { 4856 stub_type = arm_stub_a8_veneer_blx; 4857 is_blx = TRUE; 4858 is_bl = FALSE; 4859 } 4860 /* Conversely, if the original instruction was 4861 BLX but the target is Thumb mode, use the BL 4862 stub. */ 4863 else if (force_target_thumb 4864 && stub_type == arm_stub_a8_veneer_blx) 4865 { 4866 stub_type = arm_stub_a8_veneer_bl; 4867 is_blx = FALSE; 4868 is_bl = TRUE; 4869 } 4870 4871 if (is_blx) 4872 pc_for_insn &= ~ ((bfd_vma) 3); 4873 4874 /* If we found a relocation, use the proper destination, 4875 not the offset in the (unrelocated) instruction. 4876 Note this is always done if we switched the stub type 4877 above. */ 4878 if (found) 4879 offset = 4880 (bfd_signed_vma) (found->destination - pc_for_insn); 4881 4882 /* If the stub will use a Thumb-mode branch to a 4883 PLT target, redirect it to the preceding Thumb 4884 entry point. */ 4885 if (stub_type != arm_stub_a8_veneer_blx && use_plt) 4886 offset -= PLT_THUMB_STUB_SIZE; 4887 4888 target = pc_for_insn + offset; 4889 4890 /* The BLX stub is ARM-mode code. Adjust the offset to 4891 take the different PC value (+8 instead of +4) into 4892 account. */ 4893 if (stub_type == arm_stub_a8_veneer_blx) 4894 offset += 4; 4895 4896 if (((base_vma + i) & ~0xfff) == (target & ~0xfff)) 4897 { 4898 char *stub_name = NULL; 4899 4900 if (num_a8_fixes == a8_fix_table_size) 4901 { 4902 a8_fix_table_size *= 2; 4903 a8_fixes = (struct a8_erratum_fix *) 4904 bfd_realloc (a8_fixes, 4905 sizeof (struct a8_erratum_fix) 4906 * a8_fix_table_size); 4907 } 4908 4909 if (num_a8_fixes < prev_num_a8_fixes) 4910 { 4911 /* If we're doing a subsequent scan, 4912 check if we've found the same fix as 4913 before, and try and reuse the stub 4914 name. */ 4915 stub_name = a8_fixes[num_a8_fixes].stub_name; 4916 if ((a8_fixes[num_a8_fixes].section != section) 4917 || (a8_fixes[num_a8_fixes].offset != i)) 4918 { 4919 free (stub_name); 4920 stub_name = NULL; 4921 *stub_changed_p = TRUE; 4922 } 4923 } 4924 4925 if (!stub_name) 4926 { 4927 stub_name = (char *) bfd_malloc (8 + 1 + 8 + 1); 4928 if (stub_name != NULL) 4929 sprintf (stub_name, "%x:%x", section->id, i); 4930 } 4931 4932 a8_fixes[num_a8_fixes].input_bfd = input_bfd; 4933 a8_fixes[num_a8_fixes].section = section; 4934 a8_fixes[num_a8_fixes].offset = i; 4935 a8_fixes[num_a8_fixes].addend = offset; 4936 a8_fixes[num_a8_fixes].orig_insn = insn; 4937 a8_fixes[num_a8_fixes].stub_name = stub_name; 4938 a8_fixes[num_a8_fixes].stub_type = stub_type; 4939 a8_fixes[num_a8_fixes].branch_type = 4940 is_blx ? ST_BRANCH_TO_ARM : ST_BRANCH_TO_THUMB; 4941 4942 num_a8_fixes++; 4943 } 4944 } 4945 } 4946 4947 i += insn_32bit ? 4 : 2; 4948 last_was_32bit = insn_32bit; 4949 last_was_branch = is_32bit_branch; 4950 } 4951 } 4952 4953 if (elf_section_data (section)->this_hdr.contents == NULL) 4954 free (contents); 4955 } 4956 4957 *a8_fixes_p = a8_fixes; 4958 *num_a8_fixes_p = num_a8_fixes; 4959 *a8_fix_table_size_p = a8_fix_table_size; 4960 4961 return FALSE; 4962 } 4963 4964 /* Determine and set the size of the stub section for a final link. 4965 4966 The basic idea here is to examine all the relocations looking for 4967 PC-relative calls to a target that is unreachable with a "bl" 4968 instruction. */ 4969 4970 bfd_boolean 4971 elf32_arm_size_stubs (bfd *output_bfd, 4972 bfd *stub_bfd, 4973 struct bfd_link_info *info, 4974 bfd_signed_vma group_size, 4975 asection * (*add_stub_section) (const char *, asection *, 4976 unsigned int), 4977 void (*layout_sections_again) (void)) 4978 { 4979 bfd_size_type stub_group_size; 4980 bfd_boolean stubs_always_after_branch; 4981 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info); 4982 struct a8_erratum_fix *a8_fixes = NULL; 4983 unsigned int num_a8_fixes = 0, a8_fix_table_size = 10; 4984 struct a8_erratum_reloc *a8_relocs = NULL; 4985 unsigned int num_a8_relocs = 0, a8_reloc_table_size = 10, i; 4986 4987 if (htab == NULL) 4988 return FALSE; 4989 4990 if (htab->fix_cortex_a8) 4991 { 4992 a8_fixes = (struct a8_erratum_fix *) 4993 bfd_zmalloc (sizeof (struct a8_erratum_fix) * a8_fix_table_size); 4994 a8_relocs = (struct a8_erratum_reloc *) 4995 bfd_zmalloc (sizeof (struct a8_erratum_reloc) * a8_reloc_table_size); 4996 } 4997 4998 /* Propagate mach to stub bfd, because it may not have been 4999 finalized when we created stub_bfd. */ 5000 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd), 5001 bfd_get_mach (output_bfd)); 5002 5003 /* Stash our params away. */ 5004 htab->stub_bfd = stub_bfd; 5005 htab->add_stub_section = add_stub_section; 5006 htab->layout_sections_again = layout_sections_again; 5007 stubs_always_after_branch = group_size < 0; 5008 5009 /* The Cortex-A8 erratum fix depends on stubs not being in the same 4K page 5010 as the first half of a 32-bit branch straddling two 4K pages. This is a 5011 crude way of enforcing that. */ 5012 if (htab->fix_cortex_a8) 5013 stubs_always_after_branch = 1; 5014 5015 if (group_size < 0) 5016 stub_group_size = -group_size; 5017 else 5018 stub_group_size = group_size; 5019 5020 if (stub_group_size == 1) 5021 { 5022 /* Default values. */ 5023 /* Thumb branch range is +-4MB has to be used as the default 5024 maximum size (a given section can contain both ARM and Thumb 5025 code, so the worst case has to be taken into account). 5026 5027 This value is 24K less than that, which allows for 2025 5028 12-byte stubs. If we exceed that, then we will fail to link. 5029 The user will have to relink with an explicit group size 5030 option. */ 5031 stub_group_size = 4170000; 5032 } 5033 5034 group_sections (htab, stub_group_size, stubs_always_after_branch); 5035 5036 /* If we're applying the cortex A8 fix, we need to determine the 5037 program header size now, because we cannot change it later -- 5038 that could alter section placements. Notice the A8 erratum fix 5039 ends up requiring the section addresses to remain unchanged 5040 modulo the page size. That's something we cannot represent 5041 inside BFD, and we don't want to force the section alignment to 5042 be the page size. */ 5043 if (htab->fix_cortex_a8) 5044 (*htab->layout_sections_again) (); 5045 5046 while (1) 5047 { 5048 bfd *input_bfd; 5049 unsigned int bfd_indx; 5050 asection *stub_sec; 5051 bfd_boolean stub_changed = FALSE; 5052 unsigned prev_num_a8_fixes = num_a8_fixes; 5053 5054 num_a8_fixes = 0; 5055 for (input_bfd = info->input_bfds, bfd_indx = 0; 5056 input_bfd != NULL; 5057 input_bfd = input_bfd->link.next, bfd_indx++) 5058 { 5059 Elf_Internal_Shdr *symtab_hdr; 5060 asection *section; 5061 Elf_Internal_Sym *local_syms = NULL; 5062 5063 if (!is_arm_elf (input_bfd)) 5064 continue; 5065 5066 num_a8_relocs = 0; 5067 5068 /* We'll need the symbol table in a second. */ 5069 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 5070 if (symtab_hdr->sh_info == 0) 5071 continue; 5072 5073 /* Walk over each section attached to the input bfd. */ 5074 for (section = input_bfd->sections; 5075 section != NULL; 5076 section = section->next) 5077 { 5078 Elf_Internal_Rela *internal_relocs, *irelaend, *irela; 5079 5080 /* If there aren't any relocs, then there's nothing more 5081 to do. */ 5082 if ((section->flags & SEC_RELOC) == 0 5083 || section->reloc_count == 0 5084 || (section->flags & SEC_CODE) == 0) 5085 continue; 5086 5087 /* If this section is a link-once section that will be 5088 discarded, then don't create any stubs. */ 5089 if (section->output_section == NULL 5090 || section->output_section->owner != output_bfd) 5091 continue; 5092 5093 /* Get the relocs. */ 5094 internal_relocs 5095 = _bfd_elf_link_read_relocs (input_bfd, section, NULL, 5096 NULL, info->keep_memory); 5097 if (internal_relocs == NULL) 5098 goto error_ret_free_local; 5099 5100 /* Now examine each relocation. */ 5101 irela = internal_relocs; 5102 irelaend = irela + section->reloc_count; 5103 for (; irela < irelaend; irela++) 5104 { 5105 unsigned int r_type, r_indx; 5106 enum elf32_arm_stub_type stub_type; 5107 struct elf32_arm_stub_hash_entry *stub_entry; 5108 asection *sym_sec; 5109 bfd_vma sym_value; 5110 bfd_vma destination; 5111 struct elf32_arm_link_hash_entry *hash; 5112 const char *sym_name; 5113 char *stub_name; 5114 const asection *id_sec; 5115 unsigned char st_type; 5116 enum arm_st_branch_type branch_type; 5117 bfd_boolean created_stub = FALSE; 5118 5119 r_type = ELF32_R_TYPE (irela->r_info); 5120 r_indx = ELF32_R_SYM (irela->r_info); 5121 5122 if (r_type >= (unsigned int) R_ARM_max) 5123 { 5124 bfd_set_error (bfd_error_bad_value); 5125 error_ret_free_internal: 5126 if (elf_section_data (section)->relocs == NULL) 5127 free (internal_relocs); 5128 goto error_ret_free_local; 5129 } 5130 5131 hash = NULL; 5132 if (r_indx >= symtab_hdr->sh_info) 5133 hash = elf32_arm_hash_entry 5134 (elf_sym_hashes (input_bfd) 5135 [r_indx - symtab_hdr->sh_info]); 5136 5137 /* Only look for stubs on branch instructions, or 5138 non-relaxed TLSCALL */ 5139 if ((r_type != (unsigned int) R_ARM_CALL) 5140 && (r_type != (unsigned int) R_ARM_THM_CALL) 5141 && (r_type != (unsigned int) R_ARM_JUMP24) 5142 && (r_type != (unsigned int) R_ARM_THM_JUMP19) 5143 && (r_type != (unsigned int) R_ARM_THM_XPC22) 5144 && (r_type != (unsigned int) R_ARM_THM_JUMP24) 5145 && (r_type != (unsigned int) R_ARM_PLT32) 5146 && !((r_type == (unsigned int) R_ARM_TLS_CALL 5147 || r_type == (unsigned int) R_ARM_THM_TLS_CALL) 5148 && r_type == elf32_arm_tls_transition 5149 (info, r_type, &hash->root) 5150 && ((hash ? hash->tls_type 5151 : (elf32_arm_local_got_tls_type 5152 (input_bfd)[r_indx])) 5153 & GOT_TLS_GDESC) != 0)) 5154 continue; 5155 5156 /* Now determine the call target, its name, value, 5157 section. */ 5158 sym_sec = NULL; 5159 sym_value = 0; 5160 destination = 0; 5161 sym_name = NULL; 5162 5163 if (r_type == (unsigned int) R_ARM_TLS_CALL 5164 || r_type == (unsigned int) R_ARM_THM_TLS_CALL) 5165 { 5166 /* A non-relaxed TLS call. The target is the 5167 plt-resident trampoline and nothing to do 5168 with the symbol. */ 5169 BFD_ASSERT (htab->tls_trampoline > 0); 5170 sym_sec = htab->root.splt; 5171 sym_value = htab->tls_trampoline; 5172 hash = 0; 5173 st_type = STT_FUNC; 5174 branch_type = ST_BRANCH_TO_ARM; 5175 } 5176 else if (!hash) 5177 { 5178 /* It's a local symbol. */ 5179 Elf_Internal_Sym *sym; 5180 5181 if (local_syms == NULL) 5182 { 5183 local_syms 5184 = (Elf_Internal_Sym *) symtab_hdr->contents; 5185 if (local_syms == NULL) 5186 local_syms 5187 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, 5188 symtab_hdr->sh_info, 0, 5189 NULL, NULL, NULL); 5190 if (local_syms == NULL) 5191 goto error_ret_free_internal; 5192 } 5193 5194 sym = local_syms + r_indx; 5195 if (sym->st_shndx == SHN_UNDEF) 5196 sym_sec = bfd_und_section_ptr; 5197 else if (sym->st_shndx == SHN_ABS) 5198 sym_sec = bfd_abs_section_ptr; 5199 else if (sym->st_shndx == SHN_COMMON) 5200 sym_sec = bfd_com_section_ptr; 5201 else 5202 sym_sec = 5203 bfd_section_from_elf_index (input_bfd, sym->st_shndx); 5204 5205 if (!sym_sec) 5206 /* This is an undefined symbol. It can never 5207 be resolved. */ 5208 continue; 5209 5210 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) 5211 sym_value = sym->st_value; 5212 destination = (sym_value + irela->r_addend 5213 + sym_sec->output_offset 5214 + sym_sec->output_section->vma); 5215 st_type = ELF_ST_TYPE (sym->st_info); 5216 branch_type = ARM_SYM_BRANCH_TYPE (sym); 5217 sym_name 5218 = bfd_elf_string_from_elf_section (input_bfd, 5219 symtab_hdr->sh_link, 5220 sym->st_name); 5221 } 5222 else 5223 { 5224 /* It's an external symbol. */ 5225 while (hash->root.root.type == bfd_link_hash_indirect 5226 || hash->root.root.type == bfd_link_hash_warning) 5227 hash = ((struct elf32_arm_link_hash_entry *) 5228 hash->root.root.u.i.link); 5229 5230 if (hash->root.root.type == bfd_link_hash_defined 5231 || hash->root.root.type == bfd_link_hash_defweak) 5232 { 5233 sym_sec = hash->root.root.u.def.section; 5234 sym_value = hash->root.root.u.def.value; 5235 5236 struct elf32_arm_link_hash_table *globals = 5237 elf32_arm_hash_table (info); 5238 5239 /* For a destination in a shared library, 5240 use the PLT stub as target address to 5241 decide whether a branch stub is 5242 needed. */ 5243 if (globals != NULL 5244 && globals->root.splt != NULL 5245 && hash != NULL 5246 && hash->root.plt.offset != (bfd_vma) -1) 5247 { 5248 sym_sec = globals->root.splt; 5249 sym_value = hash->root.plt.offset; 5250 if (sym_sec->output_section != NULL) 5251 destination = (sym_value 5252 + sym_sec->output_offset 5253 + sym_sec->output_section->vma); 5254 } 5255 else if (sym_sec->output_section != NULL) 5256 destination = (sym_value + irela->r_addend 5257 + sym_sec->output_offset 5258 + sym_sec->output_section->vma); 5259 } 5260 else if ((hash->root.root.type == bfd_link_hash_undefined) 5261 || (hash->root.root.type == bfd_link_hash_undefweak)) 5262 { 5263 /* For a shared library, use the PLT stub as 5264 target address to decide whether a long 5265 branch stub is needed. 5266 For absolute code, they cannot be handled. */ 5267 struct elf32_arm_link_hash_table *globals = 5268 elf32_arm_hash_table (info); 5269 5270 if (globals != NULL 5271 && globals->root.splt != NULL 5272 && hash != NULL 5273 && hash->root.plt.offset != (bfd_vma) -1) 5274 { 5275 sym_sec = globals->root.splt; 5276 sym_value = hash->root.plt.offset; 5277 if (sym_sec->output_section != NULL) 5278 destination = (sym_value 5279 + sym_sec->output_offset 5280 + sym_sec->output_section->vma); 5281 } 5282 else 5283 continue; 5284 } 5285 else 5286 { 5287 bfd_set_error (bfd_error_bad_value); 5288 goto error_ret_free_internal; 5289 } 5290 st_type = hash->root.type; 5291 branch_type = hash->root.target_internal; 5292 sym_name = hash->root.root.root.string; 5293 } 5294 5295 do 5296 { 5297 /* Determine what (if any) linker stub is needed. */ 5298 stub_type = arm_type_of_stub (info, section, irela, 5299 st_type, &branch_type, 5300 hash, destination, sym_sec, 5301 input_bfd, sym_name); 5302 if (stub_type == arm_stub_none) 5303 break; 5304 5305 /* Support for grouping stub sections. */ 5306 id_sec = htab->stub_group[section->id].link_sec; 5307 5308 /* Get the name of this stub. */ 5309 stub_name = elf32_arm_stub_name (id_sec, sym_sec, hash, 5310 irela, stub_type); 5311 if (!stub_name) 5312 goto error_ret_free_internal; 5313 5314 /* We've either created a stub for this reloc already, 5315 or we are about to. */ 5316 created_stub = TRUE; 5317 5318 stub_entry = arm_stub_hash_lookup 5319 (&htab->stub_hash_table, stub_name, 5320 FALSE, FALSE); 5321 if (stub_entry != NULL) 5322 { 5323 /* The proper stub has already been created. */ 5324 free (stub_name); 5325 stub_entry->target_value = sym_value; 5326 break; 5327 } 5328 5329 stub_entry = elf32_arm_add_stub (stub_name, section, 5330 htab); 5331 if (stub_entry == NULL) 5332 { 5333 free (stub_name); 5334 goto error_ret_free_internal; 5335 } 5336 5337 stub_entry->target_value = sym_value; 5338 stub_entry->target_section = sym_sec; 5339 stub_entry->stub_type = stub_type; 5340 stub_entry->h = hash; 5341 stub_entry->branch_type = branch_type; 5342 5343 if (sym_name == NULL) 5344 sym_name = "unnamed"; 5345 stub_entry->output_name = (char *) 5346 bfd_alloc (htab->stub_bfd, 5347 sizeof (THUMB2ARM_GLUE_ENTRY_NAME) 5348 + strlen (sym_name)); 5349 if (stub_entry->output_name == NULL) 5350 { 5351 free (stub_name); 5352 goto error_ret_free_internal; 5353 } 5354 5355 /* For historical reasons, use the existing names for 5356 ARM-to-Thumb and Thumb-to-ARM stubs. */ 5357 if ((r_type == (unsigned int) R_ARM_THM_CALL 5358 || r_type == (unsigned int) R_ARM_THM_JUMP24 5359 || r_type == (unsigned int) R_ARM_THM_JUMP19) 5360 && branch_type == ST_BRANCH_TO_ARM) 5361 sprintf (stub_entry->output_name, 5362 THUMB2ARM_GLUE_ENTRY_NAME, sym_name); 5363 else if ((r_type == (unsigned int) R_ARM_CALL 5364 || r_type == (unsigned int) R_ARM_JUMP24) 5365 && branch_type == ST_BRANCH_TO_THUMB) 5366 sprintf (stub_entry->output_name, 5367 ARM2THUMB_GLUE_ENTRY_NAME, sym_name); 5368 else 5369 sprintf (stub_entry->output_name, STUB_ENTRY_NAME, 5370 sym_name); 5371 5372 stub_changed = TRUE; 5373 } 5374 while (0); 5375 5376 /* Look for relocations which might trigger Cortex-A8 5377 erratum. */ 5378 if (htab->fix_cortex_a8 5379 && (r_type == (unsigned int) R_ARM_THM_JUMP24 5380 || r_type == (unsigned int) R_ARM_THM_JUMP19 5381 || r_type == (unsigned int) R_ARM_THM_CALL 5382 || r_type == (unsigned int) R_ARM_THM_XPC22)) 5383 { 5384 bfd_vma from = section->output_section->vma 5385 + section->output_offset 5386 + irela->r_offset; 5387 5388 if ((from & 0xfff) == 0xffe) 5389 { 5390 /* Found a candidate. Note we haven't checked the 5391 destination is within 4K here: if we do so (and 5392 don't create an entry in a8_relocs) we can't tell 5393 that a branch should have been relocated when 5394 scanning later. */ 5395 if (num_a8_relocs == a8_reloc_table_size) 5396 { 5397 a8_reloc_table_size *= 2; 5398 a8_relocs = (struct a8_erratum_reloc *) 5399 bfd_realloc (a8_relocs, 5400 sizeof (struct a8_erratum_reloc) 5401 * a8_reloc_table_size); 5402 } 5403 5404 a8_relocs[num_a8_relocs].from = from; 5405 a8_relocs[num_a8_relocs].destination = destination; 5406 a8_relocs[num_a8_relocs].r_type = r_type; 5407 a8_relocs[num_a8_relocs].branch_type = branch_type; 5408 a8_relocs[num_a8_relocs].sym_name = sym_name; 5409 a8_relocs[num_a8_relocs].non_a8_stub = created_stub; 5410 a8_relocs[num_a8_relocs].hash = hash; 5411 5412 num_a8_relocs++; 5413 } 5414 } 5415 } 5416 5417 /* We're done with the internal relocs, free them. */ 5418 if (elf_section_data (section)->relocs == NULL) 5419 free (internal_relocs); 5420 } 5421 5422 if (htab->fix_cortex_a8) 5423 { 5424 /* Sort relocs which might apply to Cortex-A8 erratum. */ 5425 qsort (a8_relocs, num_a8_relocs, 5426 sizeof (struct a8_erratum_reloc), 5427 &a8_reloc_compare); 5428 5429 /* Scan for branches which might trigger Cortex-A8 erratum. */ 5430 if (cortex_a8_erratum_scan (input_bfd, info, &a8_fixes, 5431 &num_a8_fixes, &a8_fix_table_size, 5432 a8_relocs, num_a8_relocs, 5433 prev_num_a8_fixes, &stub_changed) 5434 != 0) 5435 goto error_ret_free_local; 5436 } 5437 } 5438 5439 if (prev_num_a8_fixes != num_a8_fixes) 5440 stub_changed = TRUE; 5441 5442 if (!stub_changed) 5443 break; 5444 5445 /* OK, we've added some stubs. Find out the new size of the 5446 stub sections. */ 5447 for (stub_sec = htab->stub_bfd->sections; 5448 stub_sec != NULL; 5449 stub_sec = stub_sec->next) 5450 { 5451 /* Ignore non-stub sections. */ 5452 if (!strstr (stub_sec->name, STUB_SUFFIX)) 5453 continue; 5454 5455 stub_sec->size = 0; 5456 } 5457 5458 bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab); 5459 5460 /* Add Cortex-A8 erratum veneers to stub section sizes too. */ 5461 if (htab->fix_cortex_a8) 5462 for (i = 0; i < num_a8_fixes; i++) 5463 { 5464 stub_sec = elf32_arm_create_or_find_stub_sec (NULL, 5465 a8_fixes[i].section, htab); 5466 5467 if (stub_sec == NULL) 5468 goto error_ret_free_local; 5469 5470 stub_sec->size 5471 += find_stub_size_and_template (a8_fixes[i].stub_type, NULL, 5472 NULL); 5473 } 5474 5475 5476 /* Ask the linker to do its stuff. */ 5477 (*htab->layout_sections_again) (); 5478 } 5479 5480 /* Add stubs for Cortex-A8 erratum fixes now. */ 5481 if (htab->fix_cortex_a8) 5482 { 5483 for (i = 0; i < num_a8_fixes; i++) 5484 { 5485 struct elf32_arm_stub_hash_entry *stub_entry; 5486 char *stub_name = a8_fixes[i].stub_name; 5487 asection *section = a8_fixes[i].section; 5488 unsigned int section_id = a8_fixes[i].section->id; 5489 asection *link_sec = htab->stub_group[section_id].link_sec; 5490 asection *stub_sec = htab->stub_group[section_id].stub_sec; 5491 const insn_sequence *template_sequence; 5492 int template_size, size = 0; 5493 5494 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name, 5495 TRUE, FALSE); 5496 if (stub_entry == NULL) 5497 { 5498 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"), 5499 section->owner, 5500 stub_name); 5501 return FALSE; 5502 } 5503 5504 stub_entry->stub_sec = stub_sec; 5505 stub_entry->stub_offset = 0; 5506 stub_entry->id_sec = link_sec; 5507 stub_entry->stub_type = a8_fixes[i].stub_type; 5508 stub_entry->target_section = a8_fixes[i].section; 5509 stub_entry->target_value = a8_fixes[i].offset; 5510 stub_entry->target_addend = a8_fixes[i].addend; 5511 stub_entry->orig_insn = a8_fixes[i].orig_insn; 5512 stub_entry->branch_type = a8_fixes[i].branch_type; 5513 5514 size = find_stub_size_and_template (a8_fixes[i].stub_type, 5515 &template_sequence, 5516 &template_size); 5517 5518 stub_entry->stub_size = size; 5519 stub_entry->stub_template = template_sequence; 5520 stub_entry->stub_template_size = template_size; 5521 } 5522 5523 /* Stash the Cortex-A8 erratum fix array for use later in 5524 elf32_arm_write_section(). */ 5525 htab->a8_erratum_fixes = a8_fixes; 5526 htab->num_a8_erratum_fixes = num_a8_fixes; 5527 } 5528 else 5529 { 5530 htab->a8_erratum_fixes = NULL; 5531 htab->num_a8_erratum_fixes = 0; 5532 } 5533 return TRUE; 5534 5535 error_ret_free_local: 5536 return FALSE; 5537 } 5538 5539 /* Build all the stubs associated with the current output file. The 5540 stubs are kept in a hash table attached to the main linker hash 5541 table. We also set up the .plt entries for statically linked PIC 5542 functions here. This function is called via arm_elf_finish in the 5543 linker. */ 5544 5545 bfd_boolean 5546 elf32_arm_build_stubs (struct bfd_link_info *info) 5547 { 5548 asection *stub_sec; 5549 struct bfd_hash_table *table; 5550 struct elf32_arm_link_hash_table *htab; 5551 5552 htab = elf32_arm_hash_table (info); 5553 if (htab == NULL) 5554 return FALSE; 5555 5556 for (stub_sec = htab->stub_bfd->sections; 5557 stub_sec != NULL; 5558 stub_sec = stub_sec->next) 5559 { 5560 bfd_size_type size; 5561 5562 /* Ignore non-stub sections. */ 5563 if (!strstr (stub_sec->name, STUB_SUFFIX)) 5564 continue; 5565 5566 /* Allocate memory to hold the linker stubs. */ 5567 size = stub_sec->size; 5568 stub_sec->contents = (unsigned char *) bfd_zalloc (htab->stub_bfd, size); 5569 if (stub_sec->contents == NULL && size != 0) 5570 return FALSE; 5571 stub_sec->size = 0; 5572 } 5573 5574 /* Build the stubs as directed by the stub hash table. */ 5575 table = &htab->stub_hash_table; 5576 bfd_hash_traverse (table, arm_build_one_stub, info); 5577 if (htab->fix_cortex_a8) 5578 { 5579 /* Place the cortex a8 stubs last. */ 5580 htab->fix_cortex_a8 = -1; 5581 bfd_hash_traverse (table, arm_build_one_stub, info); 5582 } 5583 5584 return TRUE; 5585 } 5586 5587 /* Locate the Thumb encoded calling stub for NAME. */ 5588 5589 static struct elf_link_hash_entry * 5590 find_thumb_glue (struct bfd_link_info *link_info, 5591 const char *name, 5592 char **error_message) 5593 { 5594 char *tmp_name; 5595 struct elf_link_hash_entry *hash; 5596 struct elf32_arm_link_hash_table *hash_table; 5597 5598 /* We need a pointer to the armelf specific hash table. */ 5599 hash_table = elf32_arm_hash_table (link_info); 5600 if (hash_table == NULL) 5601 return NULL; 5602 5603 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name) 5604 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); 5605 5606 BFD_ASSERT (tmp_name); 5607 5608 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); 5609 5610 hash = elf_link_hash_lookup 5611 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); 5612 5613 if (hash == NULL 5614 && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"), 5615 tmp_name, name) == -1) 5616 *error_message = (char *) bfd_errmsg (bfd_error_system_call); 5617 5618 free (tmp_name); 5619 5620 return hash; 5621 } 5622 5623 /* Locate the ARM encoded calling stub for NAME. */ 5624 5625 static struct elf_link_hash_entry * 5626 find_arm_glue (struct bfd_link_info *link_info, 5627 const char *name, 5628 char **error_message) 5629 { 5630 char *tmp_name; 5631 struct elf_link_hash_entry *myh; 5632 struct elf32_arm_link_hash_table *hash_table; 5633 5634 /* We need a pointer to the elfarm specific hash table. */ 5635 hash_table = elf32_arm_hash_table (link_info); 5636 if (hash_table == NULL) 5637 return NULL; 5638 5639 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name) 5640 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); 5641 5642 BFD_ASSERT (tmp_name); 5643 5644 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); 5645 5646 myh = elf_link_hash_lookup 5647 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); 5648 5649 if (myh == NULL 5650 && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"), 5651 tmp_name, name) == -1) 5652 *error_message = (char *) bfd_errmsg (bfd_error_system_call); 5653 5654 free (tmp_name); 5655 5656 return myh; 5657 } 5658 5659 /* ARM->Thumb glue (static images): 5660 5661 .arm 5662 __func_from_arm: 5663 ldr r12, __func_addr 5664 bx r12 5665 __func_addr: 5666 .word func @ behave as if you saw a ARM_32 reloc. 5667 5668 (v5t static images) 5669 .arm 5670 __func_from_arm: 5671 ldr pc, __func_addr 5672 __func_addr: 5673 .word func @ behave as if you saw a ARM_32 reloc. 5674 5675 (relocatable images) 5676 .arm 5677 __func_from_arm: 5678 ldr r12, __func_offset 5679 add r12, r12, pc 5680 bx r12 5681 __func_offset: 5682 .word func - . */ 5683 5684 #define ARM2THUMB_STATIC_GLUE_SIZE 12 5685 static const insn32 a2t1_ldr_insn = 0xe59fc000; 5686 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c; 5687 static const insn32 a2t3_func_addr_insn = 0x00000001; 5688 5689 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8 5690 static const insn32 a2t1v5_ldr_insn = 0xe51ff004; 5691 static const insn32 a2t2v5_func_addr_insn = 0x00000001; 5692 5693 #define ARM2THUMB_PIC_GLUE_SIZE 16 5694 static const insn32 a2t1p_ldr_insn = 0xe59fc004; 5695 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f; 5696 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c; 5697 5698 /* Thumb->ARM: Thumb->(non-interworking aware) ARM 5699 5700 .thumb .thumb 5701 .align 2 .align 2 5702 __func_from_thumb: __func_from_thumb: 5703 bx pc push {r6, lr} 5704 nop ldr r6, __func_addr 5705 .arm mov lr, pc 5706 b func bx r6 5707 .arm 5708 ;; back_to_thumb 5709 ldmia r13! {r6, lr} 5710 bx lr 5711 __func_addr: 5712 .word func */ 5713 5714 #define THUMB2ARM_GLUE_SIZE 8 5715 static const insn16 t2a1_bx_pc_insn = 0x4778; 5716 static const insn16 t2a2_noop_insn = 0x46c0; 5717 static const insn32 t2a3_b_insn = 0xea000000; 5718 5719 #define VFP11_ERRATUM_VENEER_SIZE 8 5720 5721 #define ARM_BX_VENEER_SIZE 12 5722 static const insn32 armbx1_tst_insn = 0xe3100001; 5723 static const insn32 armbx2_moveq_insn = 0x01a0f000; 5724 static const insn32 armbx3_bx_insn = 0xe12fff10; 5725 5726 #ifndef ELFARM_NABI_C_INCLUDED 5727 static void 5728 arm_allocate_glue_section_space (bfd * abfd, bfd_size_type size, const char * name) 5729 { 5730 asection * s; 5731 bfd_byte * contents; 5732 5733 if (size == 0) 5734 { 5735 /* Do not include empty glue sections in the output. */ 5736 if (abfd != NULL) 5737 { 5738 s = bfd_get_linker_section (abfd, name); 5739 if (s != NULL) 5740 s->flags |= SEC_EXCLUDE; 5741 } 5742 return; 5743 } 5744 5745 BFD_ASSERT (abfd != NULL); 5746 5747 s = bfd_get_linker_section (abfd, name); 5748 BFD_ASSERT (s != NULL); 5749 5750 contents = (bfd_byte *) bfd_alloc (abfd, size); 5751 5752 BFD_ASSERT (s->size == size); 5753 s->contents = contents; 5754 } 5755 5756 bfd_boolean 5757 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info) 5758 { 5759 struct elf32_arm_link_hash_table * globals; 5760 5761 globals = elf32_arm_hash_table (info); 5762 BFD_ASSERT (globals != NULL); 5763 5764 arm_allocate_glue_section_space (globals->bfd_of_glue_owner, 5765 globals->arm_glue_size, 5766 ARM2THUMB_GLUE_SECTION_NAME); 5767 5768 arm_allocate_glue_section_space (globals->bfd_of_glue_owner, 5769 globals->thumb_glue_size, 5770 THUMB2ARM_GLUE_SECTION_NAME); 5771 5772 arm_allocate_glue_section_space (globals->bfd_of_glue_owner, 5773 globals->vfp11_erratum_glue_size, 5774 VFP11_ERRATUM_VENEER_SECTION_NAME); 5775 5776 arm_allocate_glue_section_space (globals->bfd_of_glue_owner, 5777 globals->bx_glue_size, 5778 ARM_BX_GLUE_SECTION_NAME); 5779 5780 return TRUE; 5781 } 5782 5783 /* Allocate space and symbols for calling a Thumb function from Arm mode. 5784 returns the symbol identifying the stub. */ 5785 5786 static struct elf_link_hash_entry * 5787 record_arm_to_thumb_glue (struct bfd_link_info * link_info, 5788 struct elf_link_hash_entry * h) 5789 { 5790 const char * name = h->root.root.string; 5791 asection * s; 5792 char * tmp_name; 5793 struct elf_link_hash_entry * myh; 5794 struct bfd_link_hash_entry * bh; 5795 struct elf32_arm_link_hash_table * globals; 5796 bfd_vma val; 5797 bfd_size_type size; 5798 5799 globals = elf32_arm_hash_table (link_info); 5800 BFD_ASSERT (globals != NULL); 5801 BFD_ASSERT (globals->bfd_of_glue_owner != NULL); 5802 5803 s = bfd_get_linker_section 5804 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME); 5805 5806 BFD_ASSERT (s != NULL); 5807 5808 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name) 5809 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); 5810 5811 BFD_ASSERT (tmp_name); 5812 5813 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); 5814 5815 myh = elf_link_hash_lookup 5816 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); 5817 5818 if (myh != NULL) 5819 { 5820 /* We've already seen this guy. */ 5821 free (tmp_name); 5822 return myh; 5823 } 5824 5825 /* The only trick here is using hash_table->arm_glue_size as the value. 5826 Even though the section isn't allocated yet, this is where we will be 5827 putting it. The +1 on the value marks that the stub has not been 5828 output yet - not that it is a Thumb function. */ 5829 bh = NULL; 5830 val = globals->arm_glue_size + 1; 5831 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner, 5832 tmp_name, BSF_GLOBAL, s, val, 5833 NULL, TRUE, FALSE, &bh); 5834 5835 myh = (struct elf_link_hash_entry *) bh; 5836 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); 5837 myh->forced_local = 1; 5838 5839 free (tmp_name); 5840 5841 if (link_info->shared || globals->root.is_relocatable_executable 5842 || globals->pic_veneer) 5843 size = ARM2THUMB_PIC_GLUE_SIZE; 5844 else if (globals->use_blx) 5845 size = ARM2THUMB_V5_STATIC_GLUE_SIZE; 5846 else 5847 size = ARM2THUMB_STATIC_GLUE_SIZE; 5848 5849 s->size += size; 5850 globals->arm_glue_size += size; 5851 5852 return myh; 5853 } 5854 5855 /* Allocate space for ARMv4 BX veneers. */ 5856 5857 static void 5858 record_arm_bx_glue (struct bfd_link_info * link_info, int reg) 5859 { 5860 asection * s; 5861 struct elf32_arm_link_hash_table *globals; 5862 char *tmp_name; 5863 struct elf_link_hash_entry *myh; 5864 struct bfd_link_hash_entry *bh; 5865 bfd_vma val; 5866 5867 /* BX PC does not need a veneer. */ 5868 if (reg == 15) 5869 return; 5870 5871 globals = elf32_arm_hash_table (link_info); 5872 BFD_ASSERT (globals != NULL); 5873 BFD_ASSERT (globals->bfd_of_glue_owner != NULL); 5874 5875 /* Check if this veneer has already been allocated. */ 5876 if (globals->bx_glue_offset[reg]) 5877 return; 5878 5879 s = bfd_get_linker_section 5880 (globals->bfd_of_glue_owner, ARM_BX_GLUE_SECTION_NAME); 5881 5882 BFD_ASSERT (s != NULL); 5883 5884 /* Add symbol for veneer. */ 5885 tmp_name = (char *) 5886 bfd_malloc ((bfd_size_type) strlen (ARM_BX_GLUE_ENTRY_NAME) + 1); 5887 5888 BFD_ASSERT (tmp_name); 5889 5890 sprintf (tmp_name, ARM_BX_GLUE_ENTRY_NAME, reg); 5891 5892 myh = elf_link_hash_lookup 5893 (&(globals)->root, tmp_name, FALSE, FALSE, FALSE); 5894 5895 BFD_ASSERT (myh == NULL); 5896 5897 bh = NULL; 5898 val = globals->bx_glue_size; 5899 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner, 5900 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val, 5901 NULL, TRUE, FALSE, &bh); 5902 5903 myh = (struct elf_link_hash_entry *) bh; 5904 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); 5905 myh->forced_local = 1; 5906 5907 s->size += ARM_BX_VENEER_SIZE; 5908 globals->bx_glue_offset[reg] = globals->bx_glue_size | 2; 5909 globals->bx_glue_size += ARM_BX_VENEER_SIZE; 5910 } 5911 5912 5913 /* Add an entry to the code/data map for section SEC. */ 5914 5915 static void 5916 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma) 5917 { 5918 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec); 5919 unsigned int newidx; 5920 5921 if (sec_data->map == NULL) 5922 { 5923 sec_data->map = (elf32_arm_section_map *) 5924 bfd_malloc (sizeof (elf32_arm_section_map)); 5925 sec_data->mapcount = 0; 5926 sec_data->mapsize = 1; 5927 } 5928 5929 newidx = sec_data->mapcount++; 5930 5931 if (sec_data->mapcount > sec_data->mapsize) 5932 { 5933 sec_data->mapsize *= 2; 5934 sec_data->map = (elf32_arm_section_map *) 5935 bfd_realloc_or_free (sec_data->map, sec_data->mapsize 5936 * sizeof (elf32_arm_section_map)); 5937 } 5938 5939 if (sec_data->map) 5940 { 5941 sec_data->map[newidx].vma = vma; 5942 sec_data->map[newidx].type = type; 5943 } 5944 } 5945 5946 5947 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode 5948 veneers are handled for now. */ 5949 5950 static bfd_vma 5951 record_vfp11_erratum_veneer (struct bfd_link_info *link_info, 5952 elf32_vfp11_erratum_list *branch, 5953 bfd *branch_bfd, 5954 asection *branch_sec, 5955 unsigned int offset) 5956 { 5957 asection *s; 5958 struct elf32_arm_link_hash_table *hash_table; 5959 char *tmp_name; 5960 struct elf_link_hash_entry *myh; 5961 struct bfd_link_hash_entry *bh; 5962 bfd_vma val; 5963 struct _arm_elf_section_data *sec_data; 5964 elf32_vfp11_erratum_list *newerr; 5965 5966 hash_table = elf32_arm_hash_table (link_info); 5967 BFD_ASSERT (hash_table != NULL); 5968 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); 5969 5970 s = bfd_get_linker_section 5971 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME); 5972 5973 sec_data = elf32_arm_section_data (s); 5974 5975 BFD_ASSERT (s != NULL); 5976 5977 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen 5978 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10); 5979 5980 BFD_ASSERT (tmp_name); 5981 5982 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME, 5983 hash_table->num_vfp11_fixes); 5