1/* 32-bit ELF support for ARM 2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 3 Free Software Foundation, Inc. 4 5 This file is part of BFD, the Binary File Descriptor library. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 20 21#include "sysdep.h" 22#include "bfd.h" 23#include "libiberty.h" 24#include "libbfd.h" 25#include "elf-bfd.h" 26#include "elf-vxworks.h" 27#include "elf/arm.h" 28 29#ifndef NUM_ELEM 30#define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0])) 31#endif 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 62static struct elf_backend_data elf32_arm_vxworks_bed; 63 64/* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g. 65 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO 66 in that slot. */ 67 68static reloc_howto_type elf32_arm_howto_table_1[] = 69{ 70 /* No relocation */ 71 HOWTO (R_ARM_NONE, /* type */ 72 0, /* rightshift */ 73 0, /* size (0 = byte, 1 = short, 2 = long) */ 74 0, /* bitsize */ 75 FALSE, /* pc_relative */ 76 0, /* bitpos */ 77 complain_overflow_dont,/* complain_on_overflow */ 78 bfd_elf_generic_reloc, /* special_function */ 79 "R_ARM_NONE", /* name */ 80 FALSE, /* partial_inplace */ 81 0, /* src_mask */ 82 0, /* dst_mask */ 83 FALSE), /* pcrel_offset */ 84 85 HOWTO (R_ARM_PC24, /* type */ 86 2, /* rightshift */ 87 2, /* size (0 = byte, 1 = short, 2 = long) */ 88 24, /* bitsize */ 89 TRUE, /* pc_relative */ 90 0, /* bitpos */ 91 complain_overflow_signed,/* complain_on_overflow */ 92 bfd_elf_generic_reloc, /* special_function */ 93 "R_ARM_PC24", /* name */ 94 FALSE, /* partial_inplace */ 95 0x00ffffff, /* src_mask */ 96 0x00ffffff, /* dst_mask */ 97 TRUE), /* pcrel_offset */ 98 99 /* 32 bit absolute */ 100 HOWTO (R_ARM_ABS32, /* type */ 101 0, /* rightshift */ 102 2, /* size (0 = byte, 1 = short, 2 = long) */ 103 32, /* bitsize */ 104 FALSE, /* pc_relative */ 105 0, /* bitpos */ 106 complain_overflow_bitfield,/* complain_on_overflow */ 107 bfd_elf_generic_reloc, /* special_function */ 108 "R_ARM_ABS32", /* name */ 109 FALSE, /* partial_inplace */ 110 0xffffffff, /* src_mask */ 111 0xffffffff, /* dst_mask */ 112 FALSE), /* pcrel_offset */ 113 114 /* standard 32bit pc-relative reloc */ 115 HOWTO (R_ARM_REL32, /* type */ 116 0, /* rightshift */ 117 2, /* size (0 = byte, 1 = short, 2 = long) */ 118 32, /* bitsize */ 119 TRUE, /* pc_relative */ 120 0, /* bitpos */ 121 complain_overflow_bitfield,/* complain_on_overflow */ 122 bfd_elf_generic_reloc, /* special_function */ 123 "R_ARM_REL32", /* name */ 124 FALSE, /* partial_inplace */ 125 0xffffffff, /* src_mask */ 126 0xffffffff, /* dst_mask */ 127 TRUE), /* pcrel_offset */ 128 129 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */ 130 HOWTO (R_ARM_LDR_PC_G0, /* type */ 131 0, /* rightshift */ 132 0, /* size (0 = byte, 1 = short, 2 = long) */ 133 32, /* bitsize */ 134 TRUE, /* pc_relative */ 135 0, /* bitpos */ 136 complain_overflow_dont,/* complain_on_overflow */ 137 bfd_elf_generic_reloc, /* special_function */ 138 "R_ARM_LDR_PC_G0", /* name */ 139 FALSE, /* partial_inplace */ 140 0xffffffff, /* src_mask */ 141 0xffffffff, /* dst_mask */ 142 TRUE), /* pcrel_offset */ 143 144 /* 16 bit absolute */ 145 HOWTO (R_ARM_ABS16, /* type */ 146 0, /* rightshift */ 147 1, /* size (0 = byte, 1 = short, 2 = long) */ 148 16, /* bitsize */ 149 FALSE, /* pc_relative */ 150 0, /* bitpos */ 151 complain_overflow_bitfield,/* complain_on_overflow */ 152 bfd_elf_generic_reloc, /* special_function */ 153 "R_ARM_ABS16", /* name */ 154 FALSE, /* partial_inplace */ 155 0x0000ffff, /* src_mask */ 156 0x0000ffff, /* dst_mask */ 157 FALSE), /* pcrel_offset */ 158 159 /* 12 bit absolute */ 160 HOWTO (R_ARM_ABS12, /* type */ 161 0, /* rightshift */ 162 2, /* size (0 = byte, 1 = short, 2 = long) */ 163 12, /* bitsize */ 164 FALSE, /* pc_relative */ 165 0, /* bitpos */ 166 complain_overflow_bitfield,/* complain_on_overflow */ 167 bfd_elf_generic_reloc, /* special_function */ 168 "R_ARM_ABS12", /* name */ 169 FALSE, /* partial_inplace */ 170 0x00000fff, /* src_mask */ 171 0x00000fff, /* dst_mask */ 172 FALSE), /* pcrel_offset */ 173 174 HOWTO (R_ARM_THM_ABS5, /* type */ 175 6, /* rightshift */ 176 1, /* size (0 = byte, 1 = short, 2 = long) */ 177 5, /* bitsize */ 178 FALSE, /* pc_relative */ 179 0, /* bitpos */ 180 complain_overflow_bitfield,/* complain_on_overflow */ 181 bfd_elf_generic_reloc, /* special_function */ 182 "R_ARM_THM_ABS5", /* name */ 183 FALSE, /* partial_inplace */ 184 0x000007e0, /* src_mask */ 185 0x000007e0, /* dst_mask */ 186 FALSE), /* pcrel_offset */ 187 188 /* 8 bit absolute */ 189 HOWTO (R_ARM_ABS8, /* type */ 190 0, /* rightshift */ 191 0, /* size (0 = byte, 1 = short, 2 = long) */ 192 8, /* bitsize */ 193 FALSE, /* pc_relative */ 194 0, /* bitpos */ 195 complain_overflow_bitfield,/* complain_on_overflow */ 196 bfd_elf_generic_reloc, /* special_function */ 197 "R_ARM_ABS8", /* name */ 198 FALSE, /* partial_inplace */ 199 0x000000ff, /* src_mask */ 200 0x000000ff, /* dst_mask */ 201 FALSE), /* pcrel_offset */ 202 203 HOWTO (R_ARM_SBREL32, /* type */ 204 0, /* rightshift */ 205 2, /* size (0 = byte, 1 = short, 2 = long) */ 206 32, /* bitsize */ 207 FALSE, /* pc_relative */ 208 0, /* bitpos */ 209 complain_overflow_dont,/* complain_on_overflow */ 210 bfd_elf_generic_reloc, /* special_function */ 211 "R_ARM_SBREL32", /* name */ 212 FALSE, /* partial_inplace */ 213 0xffffffff, /* src_mask */ 214 0xffffffff, /* dst_mask */ 215 FALSE), /* pcrel_offset */ 216 217 HOWTO (R_ARM_THM_CALL, /* type */ 218 1, /* rightshift */ 219 2, /* size (0 = byte, 1 = short, 2 = long) */ 220 25, /* bitsize */ 221 TRUE, /* pc_relative */ 222 0, /* bitpos */ 223 complain_overflow_signed,/* complain_on_overflow */ 224 bfd_elf_generic_reloc, /* special_function */ 225 "R_ARM_THM_CALL", /* name */ 226 FALSE, /* partial_inplace */ 227 0x07ff07ff, /* src_mask */ 228 0x07ff07ff, /* dst_mask */ 229 TRUE), /* pcrel_offset */ 230 231 HOWTO (R_ARM_THM_PC8, /* type */ 232 1, /* rightshift */ 233 1, /* size (0 = byte, 1 = short, 2 = long) */ 234 8, /* bitsize */ 235 TRUE, /* pc_relative */ 236 0, /* bitpos */ 237 complain_overflow_signed,/* complain_on_overflow */ 238 bfd_elf_generic_reloc, /* special_function */ 239 "R_ARM_THM_PC8", /* name */ 240 FALSE, /* partial_inplace */ 241 0x000000ff, /* src_mask */ 242 0x000000ff, /* dst_mask */ 243 TRUE), /* pcrel_offset */ 244 245 HOWTO (R_ARM_BREL_ADJ, /* type */ 246 1, /* rightshift */ 247 1, /* size (0 = byte, 1 = short, 2 = long) */ 248 32, /* bitsize */ 249 FALSE, /* pc_relative */ 250 0, /* bitpos */ 251 complain_overflow_signed,/* complain_on_overflow */ 252 bfd_elf_generic_reloc, /* special_function */ 253 "R_ARM_BREL_ADJ", /* name */ 254 FALSE, /* partial_inplace */ 255 0xffffffff, /* src_mask */ 256 0xffffffff, /* dst_mask */ 257 FALSE), /* pcrel_offset */ 258 259 HOWTO (R_ARM_SWI24, /* type */ 260 0, /* rightshift */ 261 0, /* size (0 = byte, 1 = short, 2 = long) */ 262 0, /* bitsize */ 263 FALSE, /* pc_relative */ 264 0, /* bitpos */ 265 complain_overflow_signed,/* complain_on_overflow */ 266 bfd_elf_generic_reloc, /* special_function */ 267 "R_ARM_SWI24", /* name */ 268 FALSE, /* partial_inplace */ 269 0x00000000, /* src_mask */ 270 0x00000000, /* dst_mask */ 271 FALSE), /* pcrel_offset */ 272 273 HOWTO (R_ARM_THM_SWI8, /* type */ 274 0, /* rightshift */ 275 0, /* size (0 = byte, 1 = short, 2 = long) */ 276 0, /* bitsize */ 277 FALSE, /* pc_relative */ 278 0, /* bitpos */ 279 complain_overflow_signed,/* complain_on_overflow */ 280 bfd_elf_generic_reloc, /* special_function */ 281 "R_ARM_SWI8", /* name */ 282 FALSE, /* partial_inplace */ 283 0x00000000, /* src_mask */ 284 0x00000000, /* dst_mask */ 285 FALSE), /* pcrel_offset */ 286 287 /* BLX instruction for the ARM. */ 288 HOWTO (R_ARM_XPC25, /* type */ 289 2, /* rightshift */ 290 2, /* size (0 = byte, 1 = short, 2 = long) */ 291 25, /* bitsize */ 292 TRUE, /* pc_relative */ 293 0, /* bitpos */ 294 complain_overflow_signed,/* complain_on_overflow */ 295 bfd_elf_generic_reloc, /* special_function */ 296 "R_ARM_XPC25", /* name */ 297 FALSE, /* partial_inplace */ 298 0x00ffffff, /* src_mask */ 299 0x00ffffff, /* dst_mask */ 300 TRUE), /* pcrel_offset */ 301 302 /* BLX instruction for the Thumb. */ 303 HOWTO (R_ARM_THM_XPC22, /* type */ 304 2, /* rightshift */ 305 2, /* size (0 = byte, 1 = short, 2 = long) */ 306 22, /* bitsize */ 307 TRUE, /* pc_relative */ 308 0, /* bitpos */ 309 complain_overflow_signed,/* complain_on_overflow */ 310 bfd_elf_generic_reloc, /* special_function */ 311 "R_ARM_THM_XPC22", /* name */ 312 FALSE, /* partial_inplace */ 313 0x07ff07ff, /* src_mask */ 314 0x07ff07ff, /* dst_mask */ 315 TRUE), /* pcrel_offset */ 316 317 /* Dynamic TLS relocations. */ 318 319 HOWTO (R_ARM_TLS_DTPMOD32, /* type */ 320 0, /* rightshift */ 321 2, /* size (0 = byte, 1 = short, 2 = long) */ 322 32, /* bitsize */ 323 FALSE, /* pc_relative */ 324 0, /* bitpos */ 325 complain_overflow_bitfield,/* complain_on_overflow */ 326 bfd_elf_generic_reloc, /* special_function */ 327 "R_ARM_TLS_DTPMOD32", /* name */ 328 TRUE, /* partial_inplace */ 329 0xffffffff, /* src_mask */ 330 0xffffffff, /* dst_mask */ 331 FALSE), /* pcrel_offset */ 332 333 HOWTO (R_ARM_TLS_DTPOFF32, /* type */ 334 0, /* rightshift */ 335 2, /* size (0 = byte, 1 = short, 2 = long) */ 336 32, /* bitsize */ 337 FALSE, /* pc_relative */ 338 0, /* bitpos */ 339 complain_overflow_bitfield,/* complain_on_overflow */ 340 bfd_elf_generic_reloc, /* special_function */ 341 "R_ARM_TLS_DTPOFF32", /* name */ 342 TRUE, /* partial_inplace */ 343 0xffffffff, /* src_mask */ 344 0xffffffff, /* dst_mask */ 345 FALSE), /* pcrel_offset */ 346 347 HOWTO (R_ARM_TLS_TPOFF32, /* type */ 348 0, /* rightshift */ 349 2, /* size (0 = byte, 1 = short, 2 = long) */ 350 32, /* bitsize */ 351 FALSE, /* pc_relative */ 352 0, /* bitpos */ 353 complain_overflow_bitfield,/* complain_on_overflow */ 354 bfd_elf_generic_reloc, /* special_function */ 355 "R_ARM_TLS_TPOFF32", /* name */ 356 TRUE, /* partial_inplace */ 357 0xffffffff, /* src_mask */ 358 0xffffffff, /* dst_mask */ 359 FALSE), /* pcrel_offset */ 360 361 /* Relocs used in ARM Linux */ 362 363 HOWTO (R_ARM_COPY, /* type */ 364 0, /* rightshift */ 365 2, /* size (0 = byte, 1 = short, 2 = long) */ 366 32, /* bitsize */ 367 FALSE, /* pc_relative */ 368 0, /* bitpos */ 369 complain_overflow_bitfield,/* complain_on_overflow */ 370 bfd_elf_generic_reloc, /* special_function */ 371 "R_ARM_COPY", /* name */ 372 TRUE, /* partial_inplace */ 373 0xffffffff, /* src_mask */ 374 0xffffffff, /* dst_mask */ 375 FALSE), /* pcrel_offset */ 376 377 HOWTO (R_ARM_GLOB_DAT, /* type */ 378 0, /* rightshift */ 379 2, /* size (0 = byte, 1 = short, 2 = long) */ 380 32, /* bitsize */ 381 FALSE, /* pc_relative */ 382 0, /* bitpos */ 383 complain_overflow_bitfield,/* complain_on_overflow */ 384 bfd_elf_generic_reloc, /* special_function */ 385 "R_ARM_GLOB_DAT", /* name */ 386 TRUE, /* partial_inplace */ 387 0xffffffff, /* src_mask */ 388 0xffffffff, /* dst_mask */ 389 FALSE), /* pcrel_offset */ 390 391 HOWTO (R_ARM_JUMP_SLOT, /* type */ 392 0, /* rightshift */ 393 2, /* size (0 = byte, 1 = short, 2 = long) */ 394 32, /* bitsize */ 395 FALSE, /* pc_relative */ 396 0, /* bitpos */ 397 complain_overflow_bitfield,/* complain_on_overflow */ 398 bfd_elf_generic_reloc, /* special_function */ 399 "R_ARM_JUMP_SLOT", /* name */ 400 TRUE, /* partial_inplace */ 401 0xffffffff, /* src_mask */ 402 0xffffffff, /* dst_mask */ 403 FALSE), /* pcrel_offset */ 404 405 HOWTO (R_ARM_RELATIVE, /* type */ 406 0, /* rightshift */ 407 2, /* size (0 = byte, 1 = short, 2 = long) */ 408 32, /* bitsize */ 409 FALSE, /* pc_relative */ 410 0, /* bitpos */ 411 complain_overflow_bitfield,/* complain_on_overflow */ 412 bfd_elf_generic_reloc, /* special_function */ 413 "R_ARM_RELATIVE", /* name */ 414 TRUE, /* partial_inplace */ 415 0xffffffff, /* src_mask */ 416 0xffffffff, /* dst_mask */ 417 FALSE), /* pcrel_offset */ 418 419 HOWTO (R_ARM_GOTOFF32, /* type */ 420 0, /* rightshift */ 421 2, /* size (0 = byte, 1 = short, 2 = long) */ 422 32, /* bitsize */ 423 FALSE, /* pc_relative */ 424 0, /* bitpos */ 425 complain_overflow_bitfield,/* complain_on_overflow */ 426 bfd_elf_generic_reloc, /* special_function */ 427 "R_ARM_GOTOFF32", /* name */ 428 TRUE, /* partial_inplace */ 429 0xffffffff, /* src_mask */ 430 0xffffffff, /* dst_mask */ 431 FALSE), /* pcrel_offset */ 432 433 HOWTO (R_ARM_GOTPC, /* type */ 434 0, /* rightshift */ 435 2, /* size (0 = byte, 1 = short, 2 = long) */ 436 32, /* bitsize */ 437 TRUE, /* pc_relative */ 438 0, /* bitpos */ 439 complain_overflow_bitfield,/* complain_on_overflow */ 440 bfd_elf_generic_reloc, /* special_function */ 441 "R_ARM_GOTPC", /* name */ 442 TRUE, /* partial_inplace */ 443 0xffffffff, /* src_mask */ 444 0xffffffff, /* dst_mask */ 445 TRUE), /* pcrel_offset */ 446 447 HOWTO (R_ARM_GOT32, /* type */ 448 0, /* rightshift */ 449 2, /* size (0 = byte, 1 = short, 2 = long) */ 450 32, /* bitsize */ 451 FALSE, /* pc_relative */ 452 0, /* bitpos */ 453 complain_overflow_bitfield,/* complain_on_overflow */ 454 bfd_elf_generic_reloc, /* special_function */ 455 "R_ARM_GOT32", /* name */ 456 TRUE, /* partial_inplace */ 457 0xffffffff, /* src_mask */ 458 0xffffffff, /* dst_mask */ 459 FALSE), /* pcrel_offset */ 460 461 HOWTO (R_ARM_PLT32, /* type */ 462 2, /* rightshift */ 463 2, /* size (0 = byte, 1 = short, 2 = long) */ 464 24, /* bitsize */ 465 TRUE, /* pc_relative */ 466 0, /* bitpos */ 467 complain_overflow_bitfield,/* complain_on_overflow */ 468 bfd_elf_generic_reloc, /* special_function */ 469 "R_ARM_PLT32", /* name */ 470 FALSE, /* partial_inplace */ 471 0x00ffffff, /* src_mask */ 472 0x00ffffff, /* dst_mask */ 473 TRUE), /* pcrel_offset */ 474 475 HOWTO (R_ARM_CALL, /* type */ 476 2, /* rightshift */ 477 2, /* size (0 = byte, 1 = short, 2 = long) */ 478 24, /* bitsize */ 479 TRUE, /* pc_relative */ 480 0, /* bitpos */ 481 complain_overflow_signed,/* complain_on_overflow */ 482 bfd_elf_generic_reloc, /* special_function */ 483 "R_ARM_CALL", /* name */ 484 FALSE, /* partial_inplace */ 485 0x00ffffff, /* src_mask */ 486 0x00ffffff, /* dst_mask */ 487 TRUE), /* pcrel_offset */ 488 489 HOWTO (R_ARM_JUMP24, /* type */ 490 2, /* rightshift */ 491 2, /* size (0 = byte, 1 = short, 2 = long) */ 492 24, /* bitsize */ 493 TRUE, /* pc_relative */ 494 0, /* bitpos */ 495 complain_overflow_signed,/* complain_on_overflow */ 496 bfd_elf_generic_reloc, /* special_function */ 497 "R_ARM_JUMP24", /* name */ 498 FALSE, /* partial_inplace */ 499 0x00ffffff, /* src_mask */ 500 0x00ffffff, /* dst_mask */ 501 TRUE), /* pcrel_offset */ 502 503 HOWTO (R_ARM_THM_JUMP24, /* type */ 504 1, /* rightshift */ 505 2, /* size (0 = byte, 1 = short, 2 = long) */ 506 24, /* bitsize */ 507 TRUE, /* pc_relative */ 508 0, /* bitpos */ 509 complain_overflow_signed,/* complain_on_overflow */ 510 bfd_elf_generic_reloc, /* special_function */ 511 "R_ARM_THM_JUMP24", /* name */ 512 FALSE, /* partial_inplace */ 513 0x07ff2fff, /* src_mask */ 514 0x07ff2fff, /* dst_mask */ 515 TRUE), /* pcrel_offset */ 516 517 HOWTO (R_ARM_BASE_ABS, /* type */ 518 0, /* rightshift */ 519 2, /* size (0 = byte, 1 = short, 2 = long) */ 520 32, /* bitsize */ 521 FALSE, /* pc_relative */ 522 0, /* bitpos */ 523 complain_overflow_dont,/* complain_on_overflow */ 524 bfd_elf_generic_reloc, /* special_function */ 525 "R_ARM_BASE_ABS", /* name */ 526 FALSE, /* partial_inplace */ 527 0xffffffff, /* src_mask */ 528 0xffffffff, /* dst_mask */ 529 FALSE), /* pcrel_offset */ 530 531 HOWTO (R_ARM_ALU_PCREL7_0, /* type */ 532 0, /* rightshift */ 533 2, /* size (0 = byte, 1 = short, 2 = long) */ 534 12, /* bitsize */ 535 TRUE, /* pc_relative */ 536 0, /* bitpos */ 537 complain_overflow_dont,/* complain_on_overflow */ 538 bfd_elf_generic_reloc, /* special_function */ 539 "R_ARM_ALU_PCREL_7_0", /* name */ 540 FALSE, /* partial_inplace */ 541 0x00000fff, /* src_mask */ 542 0x00000fff, /* dst_mask */ 543 TRUE), /* pcrel_offset */ 544 545 HOWTO (R_ARM_ALU_PCREL15_8, /* type */ 546 0, /* rightshift */ 547 2, /* size (0 = byte, 1 = short, 2 = long) */ 548 12, /* bitsize */ 549 TRUE, /* pc_relative */ 550 8, /* bitpos */ 551 complain_overflow_dont,/* complain_on_overflow */ 552 bfd_elf_generic_reloc, /* special_function */ 553 "R_ARM_ALU_PCREL_15_8",/* name */ 554 FALSE, /* partial_inplace */ 555 0x00000fff, /* src_mask */ 556 0x00000fff, /* dst_mask */ 557 TRUE), /* pcrel_offset */ 558 559 HOWTO (R_ARM_ALU_PCREL23_15, /* type */ 560 0, /* rightshift */ 561 2, /* size (0 = byte, 1 = short, 2 = long) */ 562 12, /* bitsize */ 563 TRUE, /* pc_relative */ 564 16, /* bitpos */ 565 complain_overflow_dont,/* complain_on_overflow */ 566 bfd_elf_generic_reloc, /* special_function */ 567 "R_ARM_ALU_PCREL_23_15",/* name */ 568 FALSE, /* partial_inplace */ 569 0x00000fff, /* src_mask */ 570 0x00000fff, /* dst_mask */ 571 TRUE), /* pcrel_offset */ 572 573 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */ 574 0, /* rightshift */ 575 2, /* size (0 = byte, 1 = short, 2 = long) */ 576 12, /* bitsize */ 577 FALSE, /* pc_relative */ 578 0, /* bitpos */ 579 complain_overflow_dont,/* complain_on_overflow */ 580 bfd_elf_generic_reloc, /* special_function */ 581 "R_ARM_LDR_SBREL_11_0",/* name */ 582 FALSE, /* partial_inplace */ 583 0x00000fff, /* src_mask */ 584 0x00000fff, /* dst_mask */ 585 FALSE), /* pcrel_offset */ 586 587 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */ 588 0, /* rightshift */ 589 2, /* size (0 = byte, 1 = short, 2 = long) */ 590 8, /* bitsize */ 591 FALSE, /* pc_relative */ 592 12, /* bitpos */ 593 complain_overflow_dont,/* complain_on_overflow */ 594 bfd_elf_generic_reloc, /* special_function */ 595 "R_ARM_ALU_SBREL_19_12",/* name */ 596 FALSE, /* partial_inplace */ 597 0x000ff000, /* src_mask */ 598 0x000ff000, /* dst_mask */ 599 FALSE), /* pcrel_offset */ 600 601 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */ 602 0, /* rightshift */ 603 2, /* size (0 = byte, 1 = short, 2 = long) */ 604 8, /* bitsize */ 605 FALSE, /* pc_relative */ 606 20, /* bitpos */ 607 complain_overflow_dont,/* complain_on_overflow */ 608 bfd_elf_generic_reloc, /* special_function */ 609 "R_ARM_ALU_SBREL_27_20",/* name */ 610 FALSE, /* partial_inplace */ 611 0x0ff00000, /* src_mask */ 612 0x0ff00000, /* dst_mask */ 613 FALSE), /* pcrel_offset */ 614 615 HOWTO (R_ARM_TARGET1, /* type */ 616 0, /* rightshift */ 617 2, /* size (0 = byte, 1 = short, 2 = long) */ 618 32, /* bitsize */ 619 FALSE, /* pc_relative */ 620 0, /* bitpos */ 621 complain_overflow_dont,/* complain_on_overflow */ 622 bfd_elf_generic_reloc, /* special_function */ 623 "R_ARM_TARGET1", /* name */ 624 FALSE, /* partial_inplace */ 625 0xffffffff, /* src_mask */ 626 0xffffffff, /* dst_mask */ 627 FALSE), /* pcrel_offset */ 628 629 HOWTO (R_ARM_ROSEGREL32, /* type */ 630 0, /* rightshift */ 631 2, /* size (0 = byte, 1 = short, 2 = long) */ 632 32, /* bitsize */ 633 FALSE, /* pc_relative */ 634 0, /* bitpos */ 635 complain_overflow_dont,/* complain_on_overflow */ 636 bfd_elf_generic_reloc, /* special_function */ 637 "R_ARM_ROSEGREL32", /* name */ 638 FALSE, /* partial_inplace */ 639 0xffffffff, /* src_mask */ 640 0xffffffff, /* dst_mask */ 641 FALSE), /* pcrel_offset */ 642 643 HOWTO (R_ARM_V4BX, /* type */ 644 0, /* rightshift */ 645 2, /* size (0 = byte, 1 = short, 2 = long) */ 646 32, /* bitsize */ 647 FALSE, /* pc_relative */ 648 0, /* bitpos */ 649 complain_overflow_dont,/* complain_on_overflow */ 650 bfd_elf_generic_reloc, /* special_function */ 651 "R_ARM_V4BX", /* name */ 652 FALSE, /* partial_inplace */ 653 0xffffffff, /* src_mask */ 654 0xffffffff, /* dst_mask */ 655 FALSE), /* pcrel_offset */ 656 657 HOWTO (R_ARM_TARGET2, /* type */ 658 0, /* rightshift */ 659 2, /* size (0 = byte, 1 = short, 2 = long) */ 660 32, /* bitsize */ 661 FALSE, /* pc_relative */ 662 0, /* bitpos */ 663 complain_overflow_signed,/* complain_on_overflow */ 664 bfd_elf_generic_reloc, /* special_function */ 665 "R_ARM_TARGET2", /* name */ 666 FALSE, /* partial_inplace */ 667 0xffffffff, /* src_mask */ 668 0xffffffff, /* dst_mask */ 669 TRUE), /* pcrel_offset */ 670 671 HOWTO (R_ARM_PREL31, /* type */ 672 0, /* rightshift */ 673 2, /* size (0 = byte, 1 = short, 2 = long) */ 674 31, /* bitsize */ 675 TRUE, /* pc_relative */ 676 0, /* bitpos */ 677 complain_overflow_signed,/* complain_on_overflow */ 678 bfd_elf_generic_reloc, /* special_function */ 679 "R_ARM_PREL31", /* name */ 680 FALSE, /* partial_inplace */ 681 0x7fffffff, /* src_mask */ 682 0x7fffffff, /* dst_mask */ 683 TRUE), /* pcrel_offset */ 684 685 HOWTO (R_ARM_MOVW_ABS_NC, /* type */ 686 0, /* rightshift */ 687 2, /* size (0 = byte, 1 = short, 2 = long) */ 688 16, /* bitsize */ 689 FALSE, /* pc_relative */ 690 0, /* bitpos */ 691 complain_overflow_dont,/* complain_on_overflow */ 692 bfd_elf_generic_reloc, /* special_function */ 693 "R_ARM_MOVW_ABS_NC", /* name */ 694 FALSE, /* partial_inplace */ 695 0x0000ffff, /* src_mask */ 696 0x0000ffff, /* dst_mask */ 697 FALSE), /* pcrel_offset */ 698 699 HOWTO (R_ARM_MOVT_ABS, /* type */ 700 0, /* rightshift */ 701 2, /* size (0 = byte, 1 = short, 2 = long) */ 702 16, /* bitsize */ 703 FALSE, /* pc_relative */ 704 0, /* bitpos */ 705 complain_overflow_bitfield,/* complain_on_overflow */ 706 bfd_elf_generic_reloc, /* special_function */ 707 "R_ARM_MOVT_ABS", /* name */ 708 FALSE, /* partial_inplace */ 709 0x0000ffff, /* src_mask */ 710 0x0000ffff, /* dst_mask */ 711 FALSE), /* pcrel_offset */ 712 713 HOWTO (R_ARM_MOVW_PREL_NC, /* type */ 714 0, /* rightshift */ 715 2, /* size (0 = byte, 1 = short, 2 = long) */ 716 16, /* bitsize */ 717 TRUE, /* pc_relative */ 718 0, /* bitpos */ 719 complain_overflow_dont,/* complain_on_overflow */ 720 bfd_elf_generic_reloc, /* special_function */ 721 "R_ARM_MOVW_PREL_NC", /* name */ 722 FALSE, /* partial_inplace */ 723 0x0000ffff, /* src_mask */ 724 0x0000ffff, /* dst_mask */ 725 TRUE), /* pcrel_offset */ 726 727 HOWTO (R_ARM_MOVT_PREL, /* type */ 728 0, /* rightshift */ 729 2, /* size (0 = byte, 1 = short, 2 = long) */ 730 16, /* bitsize */ 731 TRUE, /* pc_relative */ 732 0, /* bitpos */ 733 complain_overflow_bitfield,/* complain_on_overflow */ 734 bfd_elf_generic_reloc, /* special_function */ 735 "R_ARM_MOVT_PREL", /* name */ 736 FALSE, /* partial_inplace */ 737 0x0000ffff, /* src_mask */ 738 0x0000ffff, /* dst_mask */ 739 TRUE), /* pcrel_offset */ 740 741 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */ 742 0, /* rightshift */ 743 2, /* size (0 = byte, 1 = short, 2 = long) */ 744 16, /* bitsize */ 745 FALSE, /* pc_relative */ 746 0, /* bitpos */ 747 complain_overflow_dont,/* complain_on_overflow */ 748 bfd_elf_generic_reloc, /* special_function */ 749 "R_ARM_THM_MOVW_ABS_NC",/* name */ 750 FALSE, /* partial_inplace */ 751 0x040f70ff, /* src_mask */ 752 0x040f70ff, /* dst_mask */ 753 FALSE), /* pcrel_offset */ 754 755 HOWTO (R_ARM_THM_MOVT_ABS, /* type */ 756 0, /* rightshift */ 757 2, /* size (0 = byte, 1 = short, 2 = long) */ 758 16, /* bitsize */ 759 FALSE, /* pc_relative */ 760 0, /* bitpos */ 761 complain_overflow_bitfield,/* complain_on_overflow */ 762 bfd_elf_generic_reloc, /* special_function */ 763 "R_ARM_THM_MOVT_ABS", /* name */ 764 FALSE, /* partial_inplace */ 765 0x040f70ff, /* src_mask */ 766 0x040f70ff, /* dst_mask */ 767 FALSE), /* pcrel_offset */ 768 769 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */ 770 0, /* rightshift */ 771 2, /* size (0 = byte, 1 = short, 2 = long) */ 772 16, /* bitsize */ 773 TRUE, /* pc_relative */ 774 0, /* bitpos */ 775 complain_overflow_dont,/* complain_on_overflow */ 776 bfd_elf_generic_reloc, /* special_function */ 777 "R_ARM_THM_MOVW_PREL_NC",/* name */ 778 FALSE, /* partial_inplace */ 779 0x040f70ff, /* src_mask */ 780 0x040f70ff, /* dst_mask */ 781 TRUE), /* pcrel_offset */ 782 783 HOWTO (R_ARM_THM_MOVT_PREL, /* type */ 784 0, /* rightshift */ 785 2, /* size (0 = byte, 1 = short, 2 = long) */ 786 16, /* bitsize */ 787 TRUE, /* pc_relative */ 788 0, /* bitpos */ 789 complain_overflow_bitfield,/* complain_on_overflow */ 790 bfd_elf_generic_reloc, /* special_function */ 791 "R_ARM_THM_MOVT_PREL", /* name */ 792 FALSE, /* partial_inplace */ 793 0x040f70ff, /* src_mask */ 794 0x040f70ff, /* dst_mask */ 795 TRUE), /* pcrel_offset */ 796 797 HOWTO (R_ARM_THM_JUMP19, /* type */ 798 1, /* rightshift */ 799 2, /* size (0 = byte, 1 = short, 2 = long) */ 800 19, /* bitsize */ 801 TRUE, /* pc_relative */ 802 0, /* bitpos */ 803 complain_overflow_signed,/* complain_on_overflow */ 804 bfd_elf_generic_reloc, /* special_function */ 805 "R_ARM_THM_JUMP19", /* name */ 806 FALSE, /* partial_inplace */ 807 0x043f2fff, /* src_mask */ 808 0x043f2fff, /* dst_mask */ 809 TRUE), /* pcrel_offset */ 810 811 HOWTO (R_ARM_THM_JUMP6, /* type */ 812 1, /* rightshift */ 813 1, /* size (0 = byte, 1 = short, 2 = long) */ 814 6, /* bitsize */ 815 TRUE, /* pc_relative */ 816 0, /* bitpos */ 817 complain_overflow_unsigned,/* complain_on_overflow */ 818 bfd_elf_generic_reloc, /* special_function */ 819 "R_ARM_THM_JUMP6", /* name */ 820 FALSE, /* partial_inplace */ 821 0x02f8, /* src_mask */ 822 0x02f8, /* dst_mask */ 823 TRUE), /* pcrel_offset */ 824 825 /* These are declared as 13-bit signed relocations because we can 826 address -4095 .. 4095(base) by altering ADDW to SUBW or vice 827 versa. */ 828 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */ 829 0, /* rightshift */ 830 2, /* size (0 = byte, 1 = short, 2 = long) */ 831 13, /* bitsize */ 832 TRUE, /* pc_relative */ 833 0, /* bitpos */ 834 complain_overflow_dont,/* complain_on_overflow */ 835 bfd_elf_generic_reloc, /* special_function */ 836 "R_ARM_THM_ALU_PREL_11_0",/* name */ 837 FALSE, /* partial_inplace */ 838 0xffffffff, /* src_mask */ 839 0xffffffff, /* dst_mask */ 840 TRUE), /* pcrel_offset */ 841 842 HOWTO (R_ARM_THM_PC12, /* type */ 843 0, /* rightshift */ 844 2, /* size (0 = byte, 1 = short, 2 = long) */ 845 13, /* bitsize */ 846 TRUE, /* pc_relative */ 847 0, /* bitpos */ 848 complain_overflow_dont,/* complain_on_overflow */ 849 bfd_elf_generic_reloc, /* special_function */ 850 "R_ARM_THM_PC12", /* name */ 851 FALSE, /* partial_inplace */ 852 0xffffffff, /* src_mask */ 853 0xffffffff, /* dst_mask */ 854 TRUE), /* pcrel_offset */ 855 856 HOWTO (R_ARM_ABS32_NOI, /* type */ 857 0, /* rightshift */ 858 2, /* size (0 = byte, 1 = short, 2 = long) */ 859 32, /* bitsize */ 860 FALSE, /* pc_relative */ 861 0, /* bitpos */ 862 complain_overflow_dont,/* complain_on_overflow */ 863 bfd_elf_generic_reloc, /* special_function */ 864 "R_ARM_ABS32_NOI", /* name */ 865 FALSE, /* partial_inplace */ 866 0xffffffff, /* src_mask */ 867 0xffffffff, /* dst_mask */ 868 FALSE), /* pcrel_offset */ 869 870 HOWTO (R_ARM_REL32_NOI, /* type */ 871 0, /* rightshift */ 872 2, /* size (0 = byte, 1 = short, 2 = long) */ 873 32, /* bitsize */ 874 TRUE, /* pc_relative */ 875 0, /* bitpos */ 876 complain_overflow_dont,/* complain_on_overflow */ 877 bfd_elf_generic_reloc, /* special_function */ 878 "R_ARM_REL32_NOI", /* name */ 879 FALSE, /* partial_inplace */ 880 0xffffffff, /* src_mask */ 881 0xffffffff, /* dst_mask */ 882 FALSE), /* pcrel_offset */ 883 884 /* Group relocations. */ 885 886 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */ 887 0, /* rightshift */ 888 2, /* size (0 = byte, 1 = short, 2 = long) */ 889 32, /* bitsize */ 890 TRUE, /* pc_relative */ 891 0, /* bitpos */ 892 complain_overflow_dont,/* complain_on_overflow */ 893 bfd_elf_generic_reloc, /* special_function */ 894 "R_ARM_ALU_PC_G0_NC", /* name */ 895 FALSE, /* partial_inplace */ 896 0xffffffff, /* src_mask */ 897 0xffffffff, /* dst_mask */ 898 TRUE), /* pcrel_offset */ 899 900 HOWTO (R_ARM_ALU_PC_G0, /* type */ 901 0, /* rightshift */ 902 2, /* size (0 = byte, 1 = short, 2 = long) */ 903 32, /* bitsize */ 904 TRUE, /* pc_relative */ 905 0, /* bitpos */ 906 complain_overflow_dont,/* complain_on_overflow */ 907 bfd_elf_generic_reloc, /* special_function */ 908 "R_ARM_ALU_PC_G0", /* name */ 909 FALSE, /* partial_inplace */ 910 0xffffffff, /* src_mask */ 911 0xffffffff, /* dst_mask */ 912 TRUE), /* pcrel_offset */ 913 914 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */ 915 0, /* rightshift */ 916 2, /* size (0 = byte, 1 = short, 2 = long) */ 917 32, /* bitsize */ 918 TRUE, /* pc_relative */ 919 0, /* bitpos */ 920 complain_overflow_dont,/* complain_on_overflow */ 921 bfd_elf_generic_reloc, /* special_function */ 922 "R_ARM_ALU_PC_G1_NC", /* name */ 923 FALSE, /* partial_inplace */ 924 0xffffffff, /* src_mask */ 925 0xffffffff, /* dst_mask */ 926 TRUE), /* pcrel_offset */ 927 928 HOWTO (R_ARM_ALU_PC_G1, /* type */ 929 0, /* rightshift */ 930 2, /* size (0 = byte, 1 = short, 2 = long) */ 931 32, /* bitsize */ 932 TRUE, /* pc_relative */ 933 0, /* bitpos */ 934 complain_overflow_dont,/* complain_on_overflow */ 935 bfd_elf_generic_reloc, /* special_function */ 936 "R_ARM_ALU_PC_G1", /* name */ 937 FALSE, /* partial_inplace */ 938 0xffffffff, /* src_mask */ 939 0xffffffff, /* dst_mask */ 940 TRUE), /* pcrel_offset */ 941 942 HOWTO (R_ARM_ALU_PC_G2, /* type */ 943 0, /* rightshift */ 944 2, /* size (0 = byte, 1 = short, 2 = long) */ 945 32, /* bitsize */ 946 TRUE, /* pc_relative */ 947 0, /* bitpos */ 948 complain_overflow_dont,/* complain_on_overflow */ 949 bfd_elf_generic_reloc, /* special_function */ 950 "R_ARM_ALU_PC_G2", /* name */ 951 FALSE, /* partial_inplace */ 952 0xffffffff, /* src_mask */ 953 0xffffffff, /* dst_mask */ 954 TRUE), /* pcrel_offset */ 955 956 HOWTO (R_ARM_LDR_PC_G1, /* type */ 957 0, /* rightshift */ 958 2, /* size (0 = byte, 1 = short, 2 = long) */ 959 32, /* bitsize */ 960 TRUE, /* pc_relative */ 961 0, /* bitpos */ 962 complain_overflow_dont,/* complain_on_overflow */ 963 bfd_elf_generic_reloc, /* special_function */ 964 "R_ARM_LDR_PC_G1", /* name */ 965 FALSE, /* partial_inplace */ 966 0xffffffff, /* src_mask */ 967 0xffffffff, /* dst_mask */ 968 TRUE), /* pcrel_offset */ 969 970 HOWTO (R_ARM_LDR_PC_G2, /* type */ 971 0, /* rightshift */ 972 2, /* size (0 = byte, 1 = short, 2 = long) */ 973 32, /* bitsize */ 974 TRUE, /* pc_relative */ 975 0, /* bitpos */ 976 complain_overflow_dont,/* complain_on_overflow */ 977 bfd_elf_generic_reloc, /* special_function */ 978 "R_ARM_LDR_PC_G2", /* name */ 979 FALSE, /* partial_inplace */ 980 0xffffffff, /* src_mask */ 981 0xffffffff, /* dst_mask */ 982 TRUE), /* pcrel_offset */ 983 984 HOWTO (R_ARM_LDRS_PC_G0, /* type */ 985 0, /* rightshift */ 986 2, /* size (0 = byte, 1 = short, 2 = long) */ 987 32, /* bitsize */ 988 TRUE, /* pc_relative */ 989 0, /* bitpos */ 990 complain_overflow_dont,/* complain_on_overflow */ 991 bfd_elf_generic_reloc, /* special_function */ 992 "R_ARM_LDRS_PC_G0", /* name */ 993 FALSE, /* partial_inplace */ 994 0xffffffff, /* src_mask */ 995 0xffffffff, /* dst_mask */ 996 TRUE), /* pcrel_offset */ 997 998 HOWTO (R_ARM_LDRS_PC_G1, /* type */ 999 0, /* rightshift */ 1000 2, /* size (0 = byte, 1 = short, 2 = long) */ 1001 32, /* bitsize */ 1002 TRUE, /* pc_relative */ 1003 0, /* bitpos */ 1004 complain_overflow_dont,/* complain_on_overflow */ 1005 bfd_elf_generic_reloc, /* special_function */ 1006 "R_ARM_LDRS_PC_G1", /* name */ 1007 FALSE, /* partial_inplace */ 1008 0xffffffff, /* src_mask */ 1009 0xffffffff, /* dst_mask */ 1010 TRUE), /* pcrel_offset */ 1011 1012 HOWTO (R_ARM_LDRS_PC_G2, /* type */ 1013 0, /* rightshift */ 1014 2, /* size (0 = byte, 1 = short, 2 = long) */ 1015 32, /* bitsize */ 1016 TRUE, /* pc_relative */ 1017 0, /* bitpos */ 1018 complain_overflow_dont,/* complain_on_overflow */ 1019 bfd_elf_generic_reloc, /* special_function */ 1020 "R_ARM_LDRS_PC_G2", /* name */ 1021 FALSE, /* partial_inplace */ 1022 0xffffffff, /* src_mask */ 1023 0xffffffff, /* dst_mask */ 1024 TRUE), /* pcrel_offset */ 1025 1026 HOWTO (R_ARM_LDC_PC_G0, /* type */ 1027 0, /* rightshift */ 1028 2, /* size (0 = byte, 1 = short, 2 = long) */ 1029 32, /* bitsize */ 1030 TRUE, /* pc_relative */ 1031 0, /* bitpos */ 1032 complain_overflow_dont,/* complain_on_overflow */ 1033 bfd_elf_generic_reloc, /* special_function */ 1034 "R_ARM_LDC_PC_G0", /* name */ 1035 FALSE, /* partial_inplace */ 1036 0xffffffff, /* src_mask */ 1037 0xffffffff, /* dst_mask */ 1038 TRUE), /* pcrel_offset */ 1039 1040 HOWTO (R_ARM_LDC_PC_G1, /* type */ 1041 0, /* rightshift */ 1042 2, /* size (0 = byte, 1 = short, 2 = long) */ 1043 32, /* bitsize */ 1044 TRUE, /* pc_relative */ 1045 0, /* bitpos */ 1046 complain_overflow_dont,/* complain_on_overflow */ 1047 bfd_elf_generic_reloc, /* special_function */ 1048 "R_ARM_LDC_PC_G1", /* name */ 1049 FALSE, /* partial_inplace */ 1050 0xffffffff, /* src_mask */ 1051 0xffffffff, /* dst_mask */ 1052 TRUE), /* pcrel_offset */ 1053 1054 HOWTO (R_ARM_LDC_PC_G2, /* type */ 1055 0, /* rightshift */ 1056 2, /* size (0 = byte, 1 = short, 2 = long) */ 1057 32, /* bitsize */ 1058 TRUE, /* pc_relative */ 1059 0, /* bitpos */ 1060 complain_overflow_dont,/* complain_on_overflow */ 1061 bfd_elf_generic_reloc, /* special_function */ 1062 "R_ARM_LDC_PC_G2", /* name */ 1063 FALSE, /* partial_inplace */ 1064 0xffffffff, /* src_mask */ 1065 0xffffffff, /* dst_mask */ 1066 TRUE), /* pcrel_offset */ 1067 1068 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */ 1069 0, /* rightshift */ 1070 2, /* size (0 = byte, 1 = short, 2 = long) */ 1071 32, /* bitsize */ 1072 TRUE, /* pc_relative */ 1073 0, /* bitpos */ 1074 complain_overflow_dont,/* complain_on_overflow */ 1075 bfd_elf_generic_reloc, /* special_function */ 1076 "R_ARM_ALU_SB_G0_NC", /* name */ 1077 FALSE, /* partial_inplace */ 1078 0xffffffff, /* src_mask */ 1079 0xffffffff, /* dst_mask */ 1080 TRUE), /* pcrel_offset */ 1081 1082 HOWTO (R_ARM_ALU_SB_G0, /* type */ 1083 0, /* rightshift */ 1084 2, /* size (0 = byte, 1 = short, 2 = long) */ 1085 32, /* bitsize */ 1086 TRUE, /* pc_relative */ 1087 0, /* bitpos */ 1088 complain_overflow_dont,/* complain_on_overflow */ 1089 bfd_elf_generic_reloc, /* special_function */ 1090 "R_ARM_ALU_SB_G0", /* name */ 1091 FALSE, /* partial_inplace */ 1092 0xffffffff, /* src_mask */ 1093 0xffffffff, /* dst_mask */ 1094 TRUE), /* pcrel_offset */ 1095 1096 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */ 1097 0, /* rightshift */ 1098 2, /* size (0 = byte, 1 = short, 2 = long) */ 1099 32, /* bitsize */ 1100 TRUE, /* pc_relative */ 1101 0, /* bitpos */ 1102 complain_overflow_dont,/* complain_on_overflow */ 1103 bfd_elf_generic_reloc, /* special_function */ 1104 "R_ARM_ALU_SB_G1_NC", /* name */ 1105 FALSE, /* partial_inplace */ 1106 0xffffffff, /* src_mask */ 1107 0xffffffff, /* dst_mask */ 1108 TRUE), /* pcrel_offset */ 1109 1110 HOWTO (R_ARM_ALU_SB_G1, /* type */ 1111 0, /* rightshift */ 1112 2, /* size (0 = byte, 1 = short, 2 = long) */ 1113 32, /* bitsize */ 1114 TRUE, /* pc_relative */ 1115 0, /* bitpos */ 1116 complain_overflow_dont,/* complain_on_overflow */ 1117 bfd_elf_generic_reloc, /* special_function */ 1118 "R_ARM_ALU_SB_G1", /* name */ 1119 FALSE, /* partial_inplace */ 1120 0xffffffff, /* src_mask */ 1121 0xffffffff, /* dst_mask */ 1122 TRUE), /* pcrel_offset */ 1123 1124 HOWTO (R_ARM_ALU_SB_G2, /* type */ 1125 0, /* rightshift */ 1126 2, /* size (0 = byte, 1 = short, 2 = long) */ 1127 32, /* bitsize */ 1128 TRUE, /* pc_relative */ 1129 0, /* bitpos */ 1130 complain_overflow_dont,/* complain_on_overflow */ 1131 bfd_elf_generic_reloc, /* special_function */ 1132 "R_ARM_ALU_SB_G2", /* name */ 1133 FALSE, /* partial_inplace */ 1134 0xffffffff, /* src_mask */ 1135 0xffffffff, /* dst_mask */ 1136 TRUE), /* pcrel_offset */ 1137 1138 HOWTO (R_ARM_LDR_SB_G0, /* type */ 1139 0, /* rightshift */ 1140 2, /* size (0 = byte, 1 = short, 2 = long) */ 1141 32, /* bitsize */ 1142 TRUE, /* pc_relative */ 1143 0, /* bitpos */ 1144 complain_overflow_dont,/* complain_on_overflow */ 1145 bfd_elf_generic_reloc, /* special_function */ 1146 "R_ARM_LDR_SB_G0", /* name */ 1147 FALSE, /* partial_inplace */ 1148 0xffffffff, /* src_mask */ 1149 0xffffffff, /* dst_mask */ 1150 TRUE), /* pcrel_offset */ 1151 1152 HOWTO (R_ARM_LDR_SB_G1, /* type */ 1153 0, /* rightshift */ 1154 2, /* size (0 = byte, 1 = short, 2 = long) */ 1155 32, /* bitsize */ 1156 TRUE, /* pc_relative */ 1157 0, /* bitpos */ 1158 complain_overflow_dont,/* complain_on_overflow */ 1159 bfd_elf_generic_reloc, /* special_function */ 1160 "R_ARM_LDR_SB_G1", /* name */ 1161 FALSE, /* partial_inplace */ 1162 0xffffffff, /* src_mask */ 1163 0xffffffff, /* dst_mask */ 1164 TRUE), /* pcrel_offset */ 1165 1166 HOWTO (R_ARM_LDR_SB_G2, /* type */ 1167 0, /* rightshift */ 1168 2, /* size (0 = byte, 1 = short, 2 = long) */ 1169 32, /* bitsize */ 1170 TRUE, /* pc_relative */ 1171 0, /* bitpos */ 1172 complain_overflow_dont,/* complain_on_overflow */ 1173 bfd_elf_generic_reloc, /* special_function */ 1174 "R_ARM_LDR_SB_G2", /* name */ 1175 FALSE, /* partial_inplace */ 1176 0xffffffff, /* src_mask */ 1177 0xffffffff, /* dst_mask */ 1178 TRUE), /* pcrel_offset */ 1179 1180 HOWTO (R_ARM_LDRS_SB_G0, /* type */ 1181 0, /* rightshift */ 1182 2, /* size (0 = byte, 1 = short, 2 = long) */ 1183 32, /* bitsize */ 1184 TRUE, /* pc_relative */ 1185 0, /* bitpos */ 1186 complain_overflow_dont,/* complain_on_overflow */ 1187 bfd_elf_generic_reloc, /* special_function */ 1188 "R_ARM_LDRS_SB_G0", /* name */ 1189 FALSE, /* partial_inplace */ 1190 0xffffffff, /* src_mask */ 1191 0xffffffff, /* dst_mask */ 1192 TRUE), /* pcrel_offset */ 1193 1194 HOWTO (R_ARM_LDRS_SB_G1, /* type */ 1195 0, /* rightshift */ 1196 2, /* size (0 = byte, 1 = short, 2 = long) */ 1197 32, /* bitsize */ 1198 TRUE, /* pc_relative */ 1199 0, /* bitpos */ 1200 complain_overflow_dont,/* complain_on_overflow */ 1201 bfd_elf_generic_reloc, /* special_function */ 1202 "R_ARM_LDRS_SB_G1", /* name */ 1203 FALSE, /* partial_inplace */ 1204 0xffffffff, /* src_mask */ 1205 0xffffffff, /* dst_mask */ 1206 TRUE), /* pcrel_offset */ 1207 1208 HOWTO (R_ARM_LDRS_SB_G2, /* type */ 1209 0, /* rightshift */ 1210 2, /* size (0 = byte, 1 = short, 2 = long) */ 1211 32, /* bitsize */ 1212 TRUE, /* pc_relative */ 1213 0, /* bitpos */ 1214 complain_overflow_dont,/* complain_on_overflow */ 1215 bfd_elf_generic_reloc, /* special_function */ 1216 "R_ARM_LDRS_SB_G2", /* name */ 1217 FALSE, /* partial_inplace */ 1218 0xffffffff, /* src_mask */ 1219 0xffffffff, /* dst_mask */ 1220 TRUE), /* pcrel_offset */ 1221 1222 HOWTO (R_ARM_LDC_SB_G0, /* type */ 1223 0, /* rightshift */ 1224 2, /* size (0 = byte, 1 = short, 2 = long) */ 1225 32, /* bitsize */ 1226 TRUE, /* pc_relative */ 1227 0, /* bitpos */ 1228 complain_overflow_dont,/* complain_on_overflow */ 1229 bfd_elf_generic_reloc, /* special_function */ 1230 "R_ARM_LDC_SB_G0", /* name */ 1231 FALSE, /* partial_inplace */ 1232 0xffffffff, /* src_mask */ 1233 0xffffffff, /* dst_mask */ 1234 TRUE), /* pcrel_offset */ 1235 1236 HOWTO (R_ARM_LDC_SB_G1, /* type */ 1237 0, /* rightshift */ 1238 2, /* size (0 = byte, 1 = short, 2 = long) */ 1239 32, /* bitsize */ 1240 TRUE, /* pc_relative */ 1241 0, /* bitpos */ 1242 complain_overflow_dont,/* complain_on_overflow */ 1243 bfd_elf_generic_reloc, /* special_function */ 1244 "R_ARM_LDC_SB_G1", /* name */ 1245 FALSE, /* partial_inplace */ 1246 0xffffffff, /* src_mask */ 1247 0xffffffff, /* dst_mask */ 1248 TRUE), /* pcrel_offset */ 1249 1250 HOWTO (R_ARM_LDC_SB_G2, /* type */ 1251 0, /* rightshift */ 1252 2, /* size (0 = byte, 1 = short, 2 = long) */ 1253 32, /* bitsize */ 1254 TRUE, /* pc_relative */ 1255 0, /* bitpos */ 1256 complain_overflow_dont,/* complain_on_overflow */ 1257 bfd_elf_generic_reloc, /* special_function */ 1258 "R_ARM_LDC_SB_G2", /* name */ 1259 FALSE, /* partial_inplace */ 1260 0xffffffff, /* src_mask */ 1261 0xffffffff, /* dst_mask */ 1262 TRUE), /* pcrel_offset */ 1263 1264 /* End of group relocations. */ 1265 1266 HOWTO (R_ARM_MOVW_BREL_NC, /* type */ 1267 0, /* rightshift */ 1268 2, /* size (0 = byte, 1 = short, 2 = long) */ 1269 16, /* bitsize */ 1270 FALSE, /* pc_relative */ 1271 0, /* bitpos */ 1272 complain_overflow_dont,/* complain_on_overflow */ 1273 bfd_elf_generic_reloc, /* special_function */ 1274 "R_ARM_MOVW_BREL_NC", /* name */ 1275 FALSE, /* partial_inplace */ 1276 0x0000ffff, /* src_mask */ 1277 0x0000ffff, /* dst_mask */ 1278 FALSE), /* pcrel_offset */ 1279 1280 HOWTO (R_ARM_MOVT_BREL, /* type */ 1281 0, /* rightshift */ 1282 2, /* size (0 = byte, 1 = short, 2 = long) */ 1283 16, /* bitsize */ 1284 FALSE, /* pc_relative */ 1285 0, /* bitpos */ 1286 complain_overflow_bitfield,/* complain_on_overflow */ 1287 bfd_elf_generic_reloc, /* special_function */ 1288 "R_ARM_MOVT_BREL", /* name */ 1289 FALSE, /* partial_inplace */ 1290 0x0000ffff, /* src_mask */ 1291 0x0000ffff, /* dst_mask */ 1292 FALSE), /* pcrel_offset */ 1293 1294 HOWTO (R_ARM_MOVW_BREL, /* type */ 1295 0, /* rightshift */ 1296 2, /* size (0 = byte, 1 = short, 2 = long) */ 1297 16, /* bitsize */ 1298 FALSE, /* pc_relative */ 1299 0, /* bitpos */ 1300 complain_overflow_dont,/* complain_on_overflow */ 1301 bfd_elf_generic_reloc, /* special_function */ 1302 "R_ARM_MOVW_BREL", /* name */ 1303 FALSE, /* partial_inplace */ 1304 0x0000ffff, /* src_mask */ 1305 0x0000ffff, /* dst_mask */ 1306 FALSE), /* pcrel_offset */ 1307 1308 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */ 1309 0, /* rightshift */ 1310 2, /* size (0 = byte, 1 = short, 2 = long) */ 1311 16, /* bitsize */ 1312 FALSE, /* pc_relative */ 1313 0, /* bitpos */ 1314 complain_overflow_dont,/* complain_on_overflow */ 1315 bfd_elf_generic_reloc, /* special_function */ 1316 "R_ARM_THM_MOVW_BREL_NC",/* name */ 1317 FALSE, /* partial_inplace */ 1318 0x040f70ff, /* src_mask */ 1319 0x040f70ff, /* dst_mask */ 1320 FALSE), /* pcrel_offset */ 1321 1322 HOWTO (R_ARM_THM_MOVT_BREL, /* type */ 1323 0, /* rightshift */ 1324 2, /* size (0 = byte, 1 = short, 2 = long) */ 1325 16, /* bitsize */ 1326 FALSE, /* pc_relative */ 1327 0, /* bitpos */ 1328 complain_overflow_bitfield,/* complain_on_overflow */ 1329 bfd_elf_generic_reloc, /* special_function */ 1330 "R_ARM_THM_MOVT_BREL", /* name */ 1331 FALSE, /* partial_inplace */ 1332 0x040f70ff, /* src_mask */ 1333 0x040f70ff, /* dst_mask */ 1334 FALSE), /* pcrel_offset */ 1335 1336 HOWTO (R_ARM_THM_MOVW_BREL, /* type */ 1337 0, /* rightshift */ 1338 2, /* size (0 = byte, 1 = short, 2 = long) */ 1339 16, /* bitsize */ 1340 FALSE, /* pc_relative */ 1341 0, /* bitpos */ 1342 complain_overflow_dont,/* complain_on_overflow */ 1343 bfd_elf_generic_reloc, /* special_function */ 1344 "R_ARM_THM_MOVW_BREL", /* name */ 1345 FALSE, /* partial_inplace */ 1346 0x040f70ff, /* src_mask */ 1347 0x040f70ff, /* dst_mask */ 1348 FALSE), /* pcrel_offset */ 1349 1350 EMPTY_HOWTO (90), /* unallocated */ 1351 EMPTY_HOWTO (91), 1352 EMPTY_HOWTO (92), 1353 EMPTY_HOWTO (93), 1354 1355 HOWTO (R_ARM_PLT32_ABS, /* type */ 1356 0, /* rightshift */ 1357 2, /* size (0 = byte, 1 = short, 2 = long) */ 1358 32, /* bitsize */ 1359 FALSE, /* pc_relative */ 1360 0, /* bitpos */ 1361 complain_overflow_dont,/* complain_on_overflow */ 1362 bfd_elf_generic_reloc, /* special_function */ 1363 "R_ARM_PLT32_ABS", /* name */ 1364 FALSE, /* partial_inplace */ 1365 0xffffffff, /* src_mask */ 1366 0xffffffff, /* dst_mask */ 1367 FALSE), /* pcrel_offset */ 1368 1369 HOWTO (R_ARM_GOT_ABS, /* type */ 1370 0, /* rightshift */ 1371 2, /* size (0 = byte, 1 = short, 2 = long) */ 1372 32, /* bitsize */ 1373 FALSE, /* pc_relative */ 1374 0, /* bitpos */ 1375 complain_overflow_dont,/* complain_on_overflow */ 1376 bfd_elf_generic_reloc, /* special_function */ 1377 "R_ARM_GOT_ABS", /* name */ 1378 FALSE, /* partial_inplace */ 1379 0xffffffff, /* src_mask */ 1380 0xffffffff, /* dst_mask */ 1381 FALSE), /* pcrel_offset */ 1382 1383 HOWTO (R_ARM_GOT_PREL, /* type */ 1384 0, /* rightshift */ 1385 2, /* size (0 = byte, 1 = short, 2 = long) */ 1386 32, /* bitsize */ 1387 TRUE, /* pc_relative */ 1388 0, /* bitpos */ 1389 complain_overflow_dont, /* complain_on_overflow */ 1390 bfd_elf_generic_reloc, /* special_function */ 1391 "R_ARM_GOT_PREL", /* name */ 1392 FALSE, /* partial_inplace */ 1393 0xffffffff, /* src_mask */ 1394 0xffffffff, /* dst_mask */ 1395 TRUE), /* pcrel_offset */ 1396 1397 HOWTO (R_ARM_GOT_BREL12, /* type */ 1398 0, /* rightshift */ 1399 2, /* size (0 = byte, 1 = short, 2 = long) */ 1400 12, /* bitsize */ 1401 FALSE, /* pc_relative */ 1402 0, /* bitpos */ 1403 complain_overflow_bitfield,/* complain_on_overflow */ 1404 bfd_elf_generic_reloc, /* special_function */ 1405 "R_ARM_GOT_BREL12", /* name */ 1406 FALSE, /* partial_inplace */ 1407 0x00000fff, /* src_mask */ 1408 0x00000fff, /* dst_mask */ 1409 FALSE), /* pcrel_offset */ 1410 1411 HOWTO (R_ARM_GOTOFF12, /* type */ 1412 0, /* rightshift */ 1413 2, /* size (0 = byte, 1 = short, 2 = long) */ 1414 12, /* bitsize */ 1415 FALSE, /* pc_relative */ 1416 0, /* bitpos */ 1417 complain_overflow_bitfield,/* complain_on_overflow */ 1418 bfd_elf_generic_reloc, /* special_function */ 1419 "R_ARM_GOTOFF12", /* name */ 1420 FALSE, /* partial_inplace */ 1421 0x00000fff, /* src_mask */ 1422 0x00000fff, /* dst_mask */ 1423 FALSE), /* pcrel_offset */ 1424 1425 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */ 1426 1427 /* GNU extension to record C++ vtable member usage */ 1428 HOWTO (R_ARM_GNU_VTENTRY, /* type */ 1429 0, /* rightshift */ 1430 2, /* size (0 = byte, 1 = short, 2 = long) */ 1431 0, /* bitsize */ 1432 FALSE, /* pc_relative */ 1433 0, /* bitpos */ 1434 complain_overflow_dont, /* complain_on_overflow */ 1435 _bfd_elf_rel_vtable_reloc_fn, /* special_function */ 1436 "R_ARM_GNU_VTENTRY", /* name */ 1437 FALSE, /* partial_inplace */ 1438 0, /* src_mask */ 1439 0, /* dst_mask */ 1440 FALSE), /* pcrel_offset */ 1441 1442 /* GNU extension to record C++ vtable hierarchy */ 1443 HOWTO (R_ARM_GNU_VTINHERIT, /* type */ 1444 0, /* rightshift */ 1445 2, /* size (0 = byte, 1 = short, 2 = long) */ 1446 0, /* bitsize */ 1447 FALSE, /* pc_relative */ 1448 0, /* bitpos */ 1449 complain_overflow_dont, /* complain_on_overflow */ 1450 NULL, /* special_function */ 1451 "R_ARM_GNU_VTINHERIT", /* name */ 1452 FALSE, /* partial_inplace */ 1453 0, /* src_mask */ 1454 0, /* dst_mask */ 1455 FALSE), /* pcrel_offset */ 1456 1457 HOWTO (R_ARM_THM_JUMP11, /* type */ 1458 1, /* rightshift */ 1459 1, /* size (0 = byte, 1 = short, 2 = long) */ 1460 11, /* bitsize */ 1461 TRUE, /* pc_relative */ 1462 0, /* bitpos */ 1463 complain_overflow_signed, /* complain_on_overflow */ 1464 bfd_elf_generic_reloc, /* special_function */ 1465 "R_ARM_THM_JUMP11", /* name */ 1466 FALSE, /* partial_inplace */ 1467 0x000007ff, /* src_mask */ 1468 0x000007ff, /* dst_mask */ 1469 TRUE), /* pcrel_offset */ 1470 1471 HOWTO (R_ARM_THM_JUMP8, /* type */ 1472 1, /* rightshift */ 1473 1, /* size (0 = byte, 1 = short, 2 = long) */ 1474 8, /* bitsize */ 1475 TRUE, /* pc_relative */ 1476 0, /* bitpos */ 1477 complain_overflow_signed, /* complain_on_overflow */ 1478 bfd_elf_generic_reloc, /* special_function */ 1479 "R_ARM_THM_JUMP8", /* name */ 1480 FALSE, /* partial_inplace */ 1481 0x000000ff, /* src_mask */ 1482 0x000000ff, /* dst_mask */ 1483 TRUE), /* pcrel_offset */ 1484 1485 /* TLS relocations */ 1486 HOWTO (R_ARM_TLS_GD32, /* type */ 1487 0, /* rightshift */ 1488 2, /* size (0 = byte, 1 = short, 2 = long) */ 1489 32, /* bitsize */ 1490 FALSE, /* pc_relative */ 1491 0, /* bitpos */ 1492 complain_overflow_bitfield,/* complain_on_overflow */ 1493 NULL, /* special_function */ 1494 "R_ARM_TLS_GD32", /* name */ 1495 TRUE, /* partial_inplace */ 1496 0xffffffff, /* src_mask */ 1497 0xffffffff, /* dst_mask */ 1498 FALSE), /* pcrel_offset */ 1499 1500 HOWTO (R_ARM_TLS_LDM32, /* type */ 1501 0, /* rightshift */ 1502 2, /* size (0 = byte, 1 = short, 2 = long) */ 1503 32, /* bitsize */ 1504 FALSE, /* pc_relative */ 1505 0, /* bitpos */ 1506 complain_overflow_bitfield,/* complain_on_overflow */ 1507 bfd_elf_generic_reloc, /* special_function */ 1508 "R_ARM_TLS_LDM32", /* name */ 1509 TRUE, /* partial_inplace */ 1510 0xffffffff, /* src_mask */ 1511 0xffffffff, /* dst_mask */ 1512 FALSE), /* pcrel_offset */ 1513 1514 HOWTO (R_ARM_TLS_LDO32, /* type */ 1515 0, /* rightshift */ 1516 2, /* size (0 = byte, 1 = short, 2 = long) */ 1517 32, /* bitsize */ 1518 FALSE, /* pc_relative */ 1519 0, /* bitpos */ 1520 complain_overflow_bitfield,/* complain_on_overflow */ 1521 bfd_elf_generic_reloc, /* special_function */ 1522 "R_ARM_TLS_LDO32", /* name */ 1523 TRUE, /* partial_inplace */ 1524 0xffffffff, /* src_mask */ 1525 0xffffffff, /* dst_mask */ 1526 FALSE), /* pcrel_offset */ 1527 1528 HOWTO (R_ARM_TLS_IE32, /* type */ 1529 0, /* rightshift */ 1530 2, /* size (0 = byte, 1 = short, 2 = long) */ 1531 32, /* bitsize */ 1532 FALSE, /* pc_relative */ 1533 0, /* bitpos */ 1534 complain_overflow_bitfield,/* complain_on_overflow */ 1535 NULL, /* special_function */ 1536 "R_ARM_TLS_IE32", /* name */ 1537 TRUE, /* partial_inplace */ 1538 0xffffffff, /* src_mask */ 1539 0xffffffff, /* dst_mask */ 1540 FALSE), /* pcrel_offset */ 1541 1542 HOWTO (R_ARM_TLS_LE32, /* type */ 1543 0, /* rightshift */ 1544 2, /* size (0 = byte, 1 = short, 2 = long) */ 1545 32, /* bitsize */ 1546 FALSE, /* pc_relative */ 1547 0, /* bitpos */ 1548 complain_overflow_bitfield,/* complain_on_overflow */ 1549 bfd_elf_generic_reloc, /* special_function */ 1550 "R_ARM_TLS_LE32", /* name */ 1551 TRUE, /* partial_inplace */ 1552 0xffffffff, /* src_mask */ 1553 0xffffffff, /* dst_mask */ 1554 FALSE), /* pcrel_offset */ 1555 1556 HOWTO (R_ARM_TLS_LDO12, /* type */ 1557 0, /* rightshift */ 1558 2, /* size (0 = byte, 1 = short, 2 = long) */ 1559 12, /* bitsize */ 1560 FALSE, /* pc_relative */ 1561 0, /* bitpos */ 1562 complain_overflow_bitfield,/* complain_on_overflow */ 1563 bfd_elf_generic_reloc, /* special_function */ 1564 "R_ARM_TLS_LDO12", /* name */ 1565 FALSE, /* partial_inplace */ 1566 0x00000fff, /* src_mask */ 1567 0x00000fff, /* dst_mask */ 1568 FALSE), /* pcrel_offset */ 1569 1570 HOWTO (R_ARM_TLS_LE12, /* type */ 1571 0, /* rightshift */ 1572 2, /* size (0 = byte, 1 = short, 2 = long) */ 1573 12, /* bitsize */ 1574 FALSE, /* pc_relative */ 1575 0, /* bitpos */ 1576 complain_overflow_bitfield,/* complain_on_overflow */ 1577 bfd_elf_generic_reloc, /* special_function */ 1578 "R_ARM_TLS_LE12", /* name */ 1579 FALSE, /* partial_inplace */ 1580 0x00000fff, /* src_mask */ 1581 0x00000fff, /* dst_mask */ 1582 FALSE), /* pcrel_offset */ 1583 1584 HOWTO (R_ARM_TLS_IE12GP, /* type */ 1585 0, /* rightshift */ 1586 2, /* size (0 = byte, 1 = short, 2 = long) */ 1587 12, /* bitsize */ 1588 FALSE, /* pc_relative */ 1589 0, /* bitpos */ 1590 complain_overflow_bitfield,/* complain_on_overflow */ 1591 bfd_elf_generic_reloc, /* special_function */ 1592 "R_ARM_TLS_IE12GP", /* name */ 1593 FALSE, /* partial_inplace */ 1594 0x00000fff, /* src_mask */ 1595 0x00000fff, /* dst_mask */ 1596 FALSE), /* pcrel_offset */ 1597}; 1598 1599/* 112-127 private relocations 1600 128 R_ARM_ME_TOO, obsolete 1601 129-255 unallocated in AAELF. 1602 1603 249-255 extended, currently unused, relocations: */ 1604 1605static reloc_howto_type elf32_arm_howto_table_2[4] = 1606{ 1607 HOWTO (R_ARM_RREL32, /* type */ 1608 0, /* rightshift */ 1609 0, /* size (0 = byte, 1 = short, 2 = long) */ 1610 0, /* bitsize */ 1611 FALSE, /* pc_relative */ 1612 0, /* bitpos */ 1613 complain_overflow_dont,/* complain_on_overflow */ 1614 bfd_elf_generic_reloc, /* special_function */ 1615 "R_ARM_RREL32", /* name */ 1616 FALSE, /* partial_inplace */ 1617 0, /* src_mask */ 1618 0, /* dst_mask */ 1619 FALSE), /* pcrel_offset */ 1620 1621 HOWTO (R_ARM_RABS32, /* type */ 1622 0, /* rightshift */ 1623 0, /* size (0 = byte, 1 = short, 2 = long) */ 1624 0, /* bitsize */ 1625 FALSE, /* pc_relative */ 1626 0, /* bitpos */ 1627 complain_overflow_dont,/* complain_on_overflow */ 1628 bfd_elf_generic_reloc, /* special_function */ 1629 "R_ARM_RABS32", /* name */ 1630 FALSE, /* partial_inplace */ 1631 0, /* src_mask */ 1632 0, /* dst_mask */ 1633 FALSE), /* pcrel_offset */ 1634 1635 HOWTO (R_ARM_RPC24, /* type */ 1636 0, /* rightshift */ 1637 0, /* size (0 = byte, 1 = short, 2 = long) */ 1638 0, /* bitsize */ 1639 FALSE, /* pc_relative */ 1640 0, /* bitpos */ 1641 complain_overflow_dont,/* complain_on_overflow */ 1642 bfd_elf_generic_reloc, /* special_function */ 1643 "R_ARM_RPC24", /* name */ 1644 FALSE, /* partial_inplace */ 1645 0, /* src_mask */ 1646 0, /* dst_mask */ 1647 FALSE), /* pcrel_offset */ 1648 1649 HOWTO (R_ARM_RBASE, /* type */ 1650 0, /* rightshift */ 1651 0, /* size (0 = byte, 1 = short, 2 = long) */ 1652 0, /* bitsize */ 1653 FALSE, /* pc_relative */ 1654 0, /* bitpos */ 1655 complain_overflow_dont,/* complain_on_overflow */ 1656 bfd_elf_generic_reloc, /* special_function */ 1657 "R_ARM_RBASE", /* name */ 1658 FALSE, /* partial_inplace */ 1659 0, /* src_mask */ 1660 0, /* dst_mask */ 1661 FALSE) /* pcrel_offset */ 1662}; 1663 1664static reloc_howto_type * 1665elf32_arm_howto_from_type (unsigned int r_type) 1666{ 1667 if (r_type < NUM_ELEM (elf32_arm_howto_table_1)) 1668 return &elf32_arm_howto_table_1[r_type]; 1669 1670 if (r_type >= R_ARM_RREL32 1671 && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2)) 1672 return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32]; 1673 1674 return NULL; 1675} 1676 1677static void 1678elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc, 1679 Elf_Internal_Rela * elf_reloc) 1680{ 1681 unsigned int r_type; 1682 1683 r_type = ELF32_R_TYPE (elf_reloc->r_info); 1684 bfd_reloc->howto = elf32_arm_howto_from_type (r_type); 1685} 1686 1687struct elf32_arm_reloc_map 1688 { 1689 bfd_reloc_code_real_type bfd_reloc_val; 1690 unsigned char elf_reloc_val; 1691 }; 1692 1693/* All entries in this list must also be present in elf32_arm_howto_table. */ 1694static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] = 1695 { 1696 {BFD_RELOC_NONE, R_ARM_NONE}, 1697 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24}, 1698 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL}, 1699 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24}, 1700 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25}, 1701 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22}, 1702 {BFD_RELOC_32, R_ARM_ABS32}, 1703 {BFD_RELOC_32_PCREL, R_ARM_REL32}, 1704 {BFD_RELOC_8, R_ARM_ABS8}, 1705 {BFD_RELOC_16, R_ARM_ABS16}, 1706 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12}, 1707 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5}, 1708 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24}, 1709 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL}, 1710 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11}, 1711 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19}, 1712 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8}, 1713 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6}, 1714 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT}, 1715 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT}, 1716 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE}, 1717 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32}, 1718 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC}, 1719 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32}, 1720 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, 1721 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1}, 1722 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32}, 1723 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32}, 1724 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31}, 1725 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2}, 1726 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, 1727 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32}, 1728 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32}, 1729 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32}, 1730 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32}, 1731 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32}, 1732 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32}, 1733 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32}, 1734 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32}, 1735 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT}, 1736 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY}, 1737 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC}, 1738 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS}, 1739 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC}, 1740 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL}, 1741 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC}, 1742 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS}, 1743 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC}, 1744 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL}, 1745 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC}, 1746 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0}, 1747 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC}, 1748 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1}, 1749 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2}, 1750 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0}, 1751 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1}, 1752 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2}, 1753 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0}, 1754 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1}, 1755 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2}, 1756 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0}, 1757 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1}, 1758 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2}, 1759 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC}, 1760 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0}, 1761 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC}, 1762 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1}, 1763 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2}, 1764 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0}, 1765 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1}, 1766 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2}, 1767 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0}, 1768 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1}, 1769 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2}, 1770 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0}, 1771 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1}, 1772 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2} 1773 }; 1774 1775static reloc_howto_type * 1776elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1777 bfd_reloc_code_real_type code) 1778{ 1779 unsigned int i; 1780 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++) 1781 if (elf32_arm_reloc_map[i].bfd_reloc_val == code) 1782 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val); 1783 1784 return NULL; 1785} 1786 1787static reloc_howto_type * 1788elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1789 const char *r_name) 1790{ 1791 unsigned int i; 1792 1793 for (i = 0; 1794 i < (sizeof (elf32_arm_howto_table_1) 1795 / sizeof (elf32_arm_howto_table_1[0])); 1796 i++) 1797 if (elf32_arm_howto_table_1[i].name != NULL 1798 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0) 1799 return &elf32_arm_howto_table_1[i]; 1800 1801 for (i = 0; 1802 i < (sizeof (elf32_arm_howto_table_2) 1803 / sizeof (elf32_arm_howto_table_2[0])); 1804 i++) 1805 if (elf32_arm_howto_table_2[i].name != NULL 1806 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0) 1807 return &elf32_arm_howto_table_2[i]; 1808 1809 return NULL; 1810} 1811 1812/* Support for core dump NOTE sections */ 1813static bfd_boolean 1814elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) 1815{ 1816 int offset; 1817 size_t size; 1818 1819 switch (note->descsz) 1820 { 1821 default: 1822 return FALSE; 1823 1824 case 148: /* Linux/ARM 32-bit*/ 1825 /* pr_cursig */ 1826 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); 1827 1828 /* pr_pid */ 1829 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); 1830 1831 /* pr_reg */ 1832 offset = 72; 1833 size = 72; 1834 1835 break; 1836 1837 case 96: /* FreeBSD/ARM */ 1838 /* pr_cursig */ 1839 if (elf_tdata(abfd)->core_signal == 0) 1840 elf_tdata (abfd)->core_signal = ((int *)(note->descdata))[5]; 1841 1842 /* pr_pid */ 1843 elf_tdata (abfd)->core_pid = ((int *)(note->descdata))[6]; 1844 1845 /* pr_reg */ 1846 offset = 28; 1847 size = 68; 1848 break; 1849 } 1850 1851 /* Make a ".reg/999" section. */ 1852 return _bfd_elfcore_make_pseudosection (abfd, ".reg", 1853 size, note->descpos + offset); 1854} 1855 1856static bfd_boolean 1857elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) 1858{ 1859 switch (note->descsz) 1860 { 1861 default: 1862 return FALSE; 1863 1864 case 124: /* Linux/ARM elf_prpsinfo */ 1865 elf_tdata (abfd)->core_program 1866 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); 1867 elf_tdata (abfd)->core_command 1868 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); 1869 } 1870 1871 /* Note that for some reason, a spurious space is tacked 1872 onto the end of the args in some (at least one anyway) 1873 implementations, so strip it off if it exists. */ 1874 1875 { 1876 char *command = elf_tdata (abfd)->core_command; 1877 int n = strlen (command); 1878 1879 if (0 < n && command[n - 1] == ' ') 1880 command[n - 1] = '\0'; 1881 } 1882 1883 return TRUE; 1884} 1885 1886#define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec 1887#define TARGET_LITTLE_NAME "elf32-littlearm" 1888#define TARGET_BIG_SYM bfd_elf32_bigarm_vec 1889#define TARGET_BIG_NAME "elf32-bigarm" 1890 1891#define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus 1892#define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo 1893 1894typedef unsigned long int insn32; 1895typedef unsigned short int insn16; 1896 1897/* In lieu of proper flags, assume all EABIv4 or later objects are 1898 interworkable. */ 1899#define INTERWORK_FLAG(abfd) \ 1900 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \ 1901 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)) 1902 1903/* The linker script knows the section names for placement. 1904 The entry_names are used to do simple name mangling on the stubs. 1905 Given a function name, and its type, the stub can be found. The 1906 name can be changed. The only requirement is the %s be present. */ 1907#define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t" 1908#define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb" 1909 1910#define ARM2THUMB_GLUE_SECTION_NAME ".glue_7" 1911#define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm" 1912 1913#define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer" 1914#define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x" 1915 1916/* The name of the dynamic interpreter. This is put in the .interp 1917 section. */ 1918#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" 1919 1920#ifdef FOUR_WORD_PLT 1921 1922/* The first entry in a procedure linkage table looks like 1923 this. It is set up so that any shared library function that is 1924 called before the relocation has been set up calls the dynamic 1925 linker first. */ 1926static const bfd_vma elf32_arm_plt0_entry [] = 1927 { 1928 0xe52de004, /* str lr, [sp, #-4]! */ 1929 0xe59fe010, /* ldr lr, [pc, #16] */ 1930 0xe08fe00e, /* add lr, pc, lr */ 1931 0xe5bef008, /* ldr pc, [lr, #8]! */ 1932 }; 1933 1934/* Subsequent entries in a procedure linkage table look like 1935 this. */ 1936static const bfd_vma elf32_arm_plt_entry [] = 1937 { 1938 0xe28fc600, /* add ip, pc, #NN */ 1939 0xe28cca00, /* add ip, ip, #NN */ 1940 0xe5bcf000, /* ldr pc, [ip, #NN]! */ 1941 0x00000000, /* unused */ 1942 }; 1943 1944#else 1945 1946/* The first entry in a procedure linkage table looks like 1947 this. It is set up so that any shared library function that is 1948 called before the relocation has been set up calls the dynamic 1949 linker first. */ 1950static const bfd_vma elf32_arm_plt0_entry [] = 1951 { 1952 0xe52de004, /* str lr, [sp, #-4]! */ 1953 0xe59fe004, /* ldr lr, [pc, #4] */ 1954 0xe08fe00e, /* add lr, pc, lr */ 1955 0xe5bef008, /* ldr pc, [lr, #8]! */ 1956 0x00000000, /* &GOT[0] - . */ 1957 }; 1958 1959/* Subsequent entries in a procedure linkage table look like 1960 this. */ 1961static const bfd_vma elf32_arm_plt_entry [] = 1962 { 1963 0xe28fc600, /* add ip, pc, #0xNN00000 */ 1964 0xe28cca00, /* add ip, ip, #0xNN000 */ 1965 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */ 1966 }; 1967 1968#endif 1969 1970/* The format of the first entry in the procedure linkage table 1971 for a VxWorks executable. */ 1972static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] = 1973 { 1974 0xe52dc008, /* str ip,[sp,#-8]! */ 1975 0xe59fc000, /* ldr ip,[pc] */ 1976 0xe59cf008, /* ldr pc,[ip,#8] */ 1977 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */ 1978 }; 1979 1980/* The format of subsequent entries in a VxWorks executable. */ 1981static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] = 1982 { 1983 0xe59fc000, /* ldr ip,[pc] */ 1984 0xe59cf000, /* ldr pc,[ip] */ 1985 0x00000000, /* .long @got */ 1986 0xe59fc000, /* ldr ip,[pc] */ 1987 0xea000000, /* b _PLT */ 1988 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */ 1989 }; 1990 1991/* The format of entries in a VxWorks shared library. */ 1992static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] = 1993 { 1994 0xe59fc000, /* ldr ip,[pc] */ 1995 0xe79cf009, /* ldr pc,[ip,r9] */ 1996 0x00000000, /* .long @got */ 1997 0xe59fc000, /* ldr ip,[pc] */ 1998 0xe599f008, /* ldr pc,[r9,#8] */ 1999 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */ 2000 }; 2001 2002/* An initial stub used if the PLT entry is referenced from Thumb code. */ 2003#define PLT_THUMB_STUB_SIZE 4 2004static const bfd_vma elf32_arm_plt_thumb_stub [] = 2005 { 2006 0x4778, /* bx pc */ 2007 0x46c0 /* nop */ 2008 }; 2009 2010/* The entries in a PLT when using a DLL-based target with multiple 2011 address spaces. */ 2012static const bfd_vma elf32_arm_symbian_plt_entry [] = 2013 { 2014 0xe51ff004, /* ldr pc, [pc, #-4] */ 2015 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */ 2016 }; 2017 2018/* Used to build a map of a section. This is required for mixed-endian 2019 code/data. */ 2020 2021typedef struct elf32_elf_section_map 2022{ 2023 bfd_vma vma; 2024 char type; 2025} 2026elf32_arm_section_map; 2027 2028/* Information about a VFP11 erratum veneer, or a branch to such a veneer. */ 2029 2030typedef enum 2031{ 2032 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER, 2033 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER, 2034 VFP11_ERRATUM_ARM_VENEER, 2035 VFP11_ERRATUM_THUMB_VENEER 2036} 2037elf32_vfp11_erratum_type; 2038 2039typedef struct elf32_vfp11_erratum_list 2040{ 2041 struct elf32_vfp11_erratum_list *next; 2042 bfd_vma vma; 2043 union 2044 { 2045 struct 2046 { 2047 struct elf32_vfp11_erratum_list *veneer; 2048 unsigned int vfp_insn; 2049 } b; 2050 struct 2051 { 2052 struct elf32_vfp11_erratum_list *branch; 2053 unsigned int id; 2054 } v; 2055 } u; 2056 elf32_vfp11_erratum_type type; 2057} 2058elf32_vfp11_erratum_list; 2059 2060typedef struct _arm_elf_section_data 2061{ 2062 struct bfd_elf_section_data elf; 2063 unsigned int mapcount; 2064 unsigned int mapsize; 2065 elf32_arm_section_map *map; 2066 unsigned int erratumcount; 2067 elf32_vfp11_erratum_list *erratumlist; 2068} 2069_arm_elf_section_data; 2070 2071#define elf32_arm_section_data(sec) \ 2072 ((_arm_elf_section_data *) elf_section_data (sec)) 2073 2074/* The size of the thread control block. */ 2075#define TCB_SIZE 8 2076 2077struct elf32_arm_obj_tdata 2078{ 2079 struct elf_obj_tdata root; 2080 2081 /* tls_type for each local got entry. */ 2082 char *local_got_tls_type; 2083 2084 /* Zero to warn when linking objects with incompatible enum sizes. */ 2085 int no_enum_size_warning; 2086}; 2087 2088#define elf32_arm_tdata(abfd) \ 2089 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any) 2090 2091#define elf32_arm_local_got_tls_type(abfd) \ 2092 (elf32_arm_tdata (abfd)->local_got_tls_type) 2093 2094static bfd_boolean 2095elf32_arm_mkobject (bfd *abfd) 2096{ 2097 if (abfd->tdata.any == NULL) 2098 { 2099 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata); 2100 abfd->tdata.any = bfd_zalloc (abfd, amt); 2101 if (abfd->tdata.any == NULL) 2102 return FALSE; 2103 } 2104 return bfd_elf_mkobject (abfd); 2105} 2106 2107/* The ARM linker needs to keep track of the number of relocs that it 2108 decides to copy in check_relocs for each symbol. This is so that 2109 it can discard PC relative relocs if it doesn't need them when 2110 linking with -Bsymbolic. We store the information in a field 2111 extending the regular ELF linker hash table. */ 2112 2113/* This structure keeps track of the number of relocs we have copied 2114 for a given symbol. */ 2115struct elf32_arm_relocs_copied 2116 { 2117 /* Next section. */ 2118 struct elf32_arm_relocs_copied * next; 2119 /* A section in dynobj. */ 2120 asection * section; 2121 /* Number of relocs copied in this section. */ 2122 bfd_size_type count; 2123 /* Number of PC-relative relocs copied in this section. */ 2124 bfd_size_type pc_count; 2125 }; 2126 2127#define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent)) 2128 2129/* Arm ELF linker hash entry. */ 2130struct elf32_arm_link_hash_entry 2131 { 2132 struct elf_link_hash_entry root; 2133 2134 /* Number of PC relative relocs copied for this symbol. */ 2135 struct elf32_arm_relocs_copied * relocs_copied; 2136 2137 /* We reference count Thumb references to a PLT entry separately, 2138 so that we can emit the Thumb trampoline only if needed. */ 2139 bfd_signed_vma plt_thumb_refcount; 2140 2141 /* Since PLT entries have variable size if the Thumb prologue is 2142 used, we need to record the index into .got.plt instead of 2143 recomputing it from the PLT offset. */ 2144 bfd_signed_vma plt_got_offset; 2145 2146#define GOT_UNKNOWN 0 2147#define GOT_NORMAL 1 2148#define GOT_TLS_GD 2 2149#define GOT_TLS_IE 4 2150 unsigned char tls_type; 2151 2152 /* The symbol marking the real symbol location for exported thumb 2153 symbols with Arm stubs. */ 2154 struct elf_link_hash_entry *export_glue; 2155 }; 2156 2157/* Traverse an arm ELF linker hash table. */ 2158#define elf32_arm_link_hash_traverse(table, func, info) \ 2159 (elf_link_hash_traverse \ 2160 (&(table)->root, \ 2161 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ 2162 (info))) 2163 2164/* Get the ARM elf linker hash table from a link_info structure. */ 2165#define elf32_arm_hash_table(info) \ 2166 ((struct elf32_arm_link_hash_table *) ((info)->hash)) 2167 2168/* ARM ELF linker hash table. */ 2169struct elf32_arm_link_hash_table 2170 { 2171 /* The main hash table. */ 2172 struct elf_link_hash_table root; 2173 2174 /* The size in bytes of the section containing the Thumb-to-ARM glue. */ 2175 bfd_size_type thumb_glue_size; 2176 2177 /* The size in bytes of the section containing the ARM-to-Thumb glue. */ 2178 bfd_size_type arm_glue_size; 2179 2180 /* The size in bytes of the section containing glue for VFP11 erratum 2181 veneers. */ 2182 bfd_size_type vfp11_erratum_glue_size; 2183 2184 /* An arbitrary input BFD chosen to hold the glue sections. */ 2185 bfd * bfd_of_glue_owner; 2186 2187 /* Nonzero to output a BE8 image. */ 2188 int byteswap_code; 2189 2190 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32. 2191 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */ 2192 int target1_is_rel; 2193 2194 /* The relocation to use for R_ARM_TARGET2 relocations. */ 2195 int target2_reloc; 2196 2197 /* Nonzero to fix BX instructions for ARMv4 targets. */ 2198 int fix_v4bx; 2199 2200 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */ 2201 int use_blx; 2202 2203 /* What sort of code sequences we should look for which may trigger the 2204 VFP11 denorm erratum. */ 2205 bfd_arm_vfp11_fix vfp11_fix; 2206 2207 /* Global counter for the number of fixes we have emitted. */ 2208 int num_vfp11_fixes; 2209 2210 /* Nonzero to force PIC branch veneers. */ 2211 int pic_veneer; 2212 2213 /* The number of bytes in the initial entry in the PLT. */ 2214 bfd_size_type plt_header_size; 2215 2216 /* The number of bytes in the subsequent PLT etries. */ 2217 bfd_size_type plt_entry_size; 2218 2219 /* True if the target system is VxWorks. */ 2220 int vxworks_p; 2221 2222 /* True if the target system is Symbian OS. */ 2223 int symbian_p; 2224 2225 /* True if the target uses REL relocations. */ 2226 int use_rel; 2227 2228 /* Short-cuts to get to dynamic linker sections. */ 2229 asection *sgot; 2230 asection *sgotplt; 2231 asection *srelgot; 2232 asection *splt; 2233 asection *srelplt; 2234 asection *sdynbss; 2235 asection *srelbss; 2236 2237 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */ 2238 asection *srelplt2; 2239 2240 /* Data for R_ARM_TLS_LDM32 relocations. */ 2241 union { 2242 bfd_signed_vma refcount; 2243 bfd_vma offset; 2244 } tls_ldm_got; 2245 2246 /* Small local sym to section mapping cache. */ 2247 struct sym_sec_cache sym_sec; 2248 2249 /* For convenience in allocate_dynrelocs. */ 2250 bfd * obfd; 2251 }; 2252 2253/* Create an entry in an ARM ELF linker hash table. */ 2254 2255static struct bfd_hash_entry * 2256elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry, 2257 struct bfd_hash_table * table, 2258 const char * string) 2259{ 2260 struct elf32_arm_link_hash_entry * ret = 2261 (struct elf32_arm_link_hash_entry *) entry; 2262 2263 /* Allocate the structure if it has not already been allocated by a 2264 subclass. */ 2265 if (ret == (struct elf32_arm_link_hash_entry *) NULL) 2266 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry)); 2267 if (ret == NULL) 2268 return (struct bfd_hash_entry *) ret; 2269 2270 /* Call the allocation method of the superclass. */ 2271 ret = ((struct elf32_arm_link_hash_entry *) 2272 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, 2273 table, string)); 2274 if (ret != NULL) 2275 { 2276 ret->relocs_copied = NULL; 2277 ret->tls_type = GOT_UNKNOWN; 2278 ret->plt_thumb_refcount = 0; 2279 ret->plt_got_offset = -1; 2280 ret->export_glue = NULL; 2281 } 2282 2283 return (struct bfd_hash_entry *) ret; 2284} 2285 2286/* Return true if NAME is the name of the relocation section associated 2287 with S. */ 2288 2289static bfd_boolean 2290reloc_section_p (struct elf32_arm_link_hash_table *htab, 2291 const char *name, asection *s) 2292{ 2293 if (htab->use_rel) 2294 return CONST_STRNEQ (name, ".rel") && strcmp (s->name, name + 4) == 0; 2295 else 2296 return CONST_STRNEQ (name, ".rela") && strcmp (s->name, name + 5) == 0; 2297} 2298 2299/* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up 2300 shortcuts to them in our hash table. */ 2301 2302static bfd_boolean 2303create_got_section (bfd *dynobj, struct bfd_link_info *info) 2304{ 2305 struct elf32_arm_link_hash_table *htab; 2306 2307 htab = elf32_arm_hash_table (info); 2308 /* BPABI objects never have a GOT, or associated sections. */ 2309 if (htab->symbian_p) 2310 return TRUE; 2311 2312 if (! _bfd_elf_create_got_section (dynobj, info)) 2313 return FALSE; 2314 2315 htab->sgot = bfd_get_section_by_name (dynobj, ".got"); 2316 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); 2317 if (!htab->sgot || !htab->sgotplt) 2318 abort (); 2319 2320 htab->srelgot = bfd_make_section_with_flags (dynobj, 2321 RELOC_SECTION (htab, ".got"), 2322 (SEC_ALLOC | SEC_LOAD 2323 | SEC_HAS_CONTENTS 2324 | SEC_IN_MEMORY 2325 | SEC_LINKER_CREATED 2326 | SEC_READONLY)); 2327 if (htab->srelgot == NULL 2328 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) 2329 return FALSE; 2330 return TRUE; 2331} 2332 2333/* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and 2334 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our 2335 hash table. */ 2336 2337static bfd_boolean 2338elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) 2339{ 2340 struct elf32_arm_link_hash_table *htab; 2341 2342 htab = elf32_arm_hash_table (info); 2343 if (!htab->sgot && !create_got_section (dynobj, info)) 2344 return FALSE; 2345 2346 if (!_bfd_elf_create_dynamic_sections (dynobj, info)) 2347 return FALSE; 2348 2349 htab->splt = bfd_get_section_by_name (dynobj, ".plt"); 2350 htab->srelplt = bfd_get_section_by_name (dynobj, 2351 RELOC_SECTION (htab, ".plt")); 2352 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); 2353 if (!info->shared) 2354 htab->srelbss = bfd_get_section_by_name (dynobj, 2355 RELOC_SECTION (htab, ".bss")); 2356 2357 if (htab->vxworks_p) 2358 { 2359 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2)) 2360 return FALSE; 2361 2362 if (info->shared) 2363 { 2364 htab->plt_header_size = 0; 2365 htab->plt_entry_size 2366 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry); 2367 } 2368 else 2369 { 2370 htab->plt_header_size 2371 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry); 2372 htab->plt_entry_size 2373 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry); 2374 } 2375 } 2376 2377 if (!htab->splt 2378 || !htab->srelplt 2379 || !htab->sdynbss 2380 || (!info->shared && !htab->srelbss)) 2381 abort (); 2382 2383 return TRUE; 2384} 2385 2386/* Copy the extra info we tack onto an elf_link_hash_entry. */ 2387 2388static void 2389elf32_arm_copy_indirect_symbol (struct bfd_link_info *info, 2390 struct elf_link_hash_entry *dir, 2391 struct elf_link_hash_entry *ind) 2392{ 2393 struct elf32_arm_link_hash_entry *edir, *eind; 2394 2395 edir = (struct elf32_arm_link_hash_entry *) dir; 2396 eind = (struct elf32_arm_link_hash_entry *) ind; 2397 2398 if (eind->relocs_copied != NULL) 2399 { 2400 if (edir->relocs_copied != NULL) 2401 { 2402 struct elf32_arm_relocs_copied **pp; 2403 struct elf32_arm_relocs_copied *p; 2404 2405 /* Add reloc counts against the indirect sym to the direct sym 2406 list. Merge any entries against the same section. */ 2407 for (pp = &eind->relocs_copied; (p = *pp) != NULL; ) 2408 { 2409 struct elf32_arm_relocs_copied *q; 2410 2411 for (q = edir->relocs_copied; q != NULL; q = q->next) 2412 if (q->section == p->section) 2413 { 2414 q->pc_count += p->pc_count; 2415 q->count += p->count; 2416 *pp = p->next; 2417 break; 2418 } 2419 if (q == NULL) 2420 pp = &p->next; 2421 } 2422 *pp = edir->relocs_copied; 2423 } 2424 2425 edir->relocs_copied = eind->relocs_copied; 2426 eind->relocs_copied = NULL; 2427 } 2428 2429 if (ind->root.type == bfd_link_hash_indirect) 2430 { 2431 /* Copy over PLT info. */ 2432 edir->plt_thumb_refcount += eind->plt_thumb_refcount; 2433 eind->plt_thumb_refcount = 0; 2434 2435 if (dir->got.refcount <= 0) 2436 { 2437 edir->tls_type = eind->tls_type; 2438 eind->tls_type = GOT_UNKNOWN; 2439 } 2440 } 2441 2442 _bfd_elf_link_hash_copy_indirect (info, dir, ind); 2443} 2444 2445/* Create an ARM elf linker hash table. */ 2446 2447static struct bfd_link_hash_table * 2448elf32_arm_link_hash_table_create (bfd *abfd) 2449{ 2450 struct elf32_arm_link_hash_table *ret; 2451 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table); 2452 2453 ret = bfd_malloc (amt); 2454 if (ret == NULL) 2455 return NULL; 2456 2457 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd, 2458 elf32_arm_link_hash_newfunc, 2459 sizeof (struct elf32_arm_link_hash_entry))) 2460 { 2461 free (ret); 2462 return NULL; 2463 } 2464 2465 ret->sgot = NULL; 2466 ret->sgotplt = NULL; 2467 ret->srelgot = NULL; 2468 ret->splt = NULL; 2469 ret->srelplt = NULL; 2470 ret->sdynbss = NULL; 2471 ret->srelbss = NULL; 2472 ret->srelplt2 = NULL; 2473 ret->thumb_glue_size = 0; 2474 ret->arm_glue_size = 0; 2475 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE; 2476 ret->vfp11_erratum_glue_size = 0; 2477 ret->num_vfp11_fixes = 0; 2478 ret->bfd_of_glue_owner = NULL; 2479 ret->byteswap_code = 0; 2480 ret->target1_is_rel = 0; 2481 ret->target2_reloc = R_ARM_NONE; 2482#ifdef FOUR_WORD_PLT 2483 ret->plt_header_size = 16; 2484 ret->plt_entry_size = 16; 2485#else 2486 ret->plt_header_size = 20; 2487 ret->plt_entry_size = 12; 2488#endif 2489 ret->fix_v4bx = 0; 2490 ret->use_blx = 0; 2491 ret->vxworks_p = 0; 2492 ret->symbian_p = 0; 2493 ret->use_rel = 1; 2494 ret->sym_sec.abfd = NULL; 2495 ret->obfd = abfd; 2496 ret->tls_ldm_got.refcount = 0; 2497 2498 return &ret->root.root; 2499} 2500 2501/* Locate the Thumb encoded calling stub for NAME. */ 2502 2503static struct elf_link_hash_entry * 2504find_thumb_glue (struct bfd_link_info *link_info, 2505 const char *name, 2506 char **error_message) 2507{ 2508 char *tmp_name; 2509 struct elf_link_hash_entry *hash; 2510 struct elf32_arm_link_hash_table *hash_table; 2511 2512 /* We need a pointer to the armelf specific hash table. */ 2513 hash_table = elf32_arm_hash_table (link_info); 2514 2515 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) 2516 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); 2517 2518 BFD_ASSERT (tmp_name); 2519 2520 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); 2521 2522 hash = elf_link_hash_lookup 2523 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); 2524 2525 if (hash == NULL) 2526 asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"), 2527 tmp_name, name); 2528 2529 free (tmp_name); 2530 2531 return hash; 2532} 2533 2534/* Locate the ARM encoded calling stub for NAME. */ 2535 2536static struct elf_link_hash_entry * 2537find_arm_glue (struct bfd_link_info *link_info, 2538 const char *name, 2539 char **error_message) 2540{ 2541 char *tmp_name; 2542 struct elf_link_hash_entry *myh; 2543 struct elf32_arm_link_hash_table *hash_table; 2544 2545 /* We need a pointer to the elfarm specific hash table. */ 2546 hash_table = elf32_arm_hash_table (link_info); 2547 2548 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) 2549 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); 2550 2551 BFD_ASSERT (tmp_name); 2552 2553 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); 2554 2555 myh = elf_link_hash_lookup 2556 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); 2557 2558 if (myh == NULL) 2559 asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"), 2560 tmp_name, name); 2561 2562 free (tmp_name); 2563 2564 return myh; 2565} 2566 2567/* ARM->Thumb glue (static images): 2568 2569 .arm 2570 __func_from_arm: 2571 ldr r12, __func_addr 2572 bx r12 2573 __func_addr: 2574 .word func @ behave as if you saw a ARM_32 reloc. 2575 2576 (v5t static images) 2577 .arm 2578 __func_from_arm: 2579 ldr pc, __func_addr 2580 __func_addr: 2581 .word func @ behave as if you saw a ARM_32 reloc. 2582 2583 (relocatable images) 2584 .arm 2585 __func_from_arm: 2586 ldr r12, __func_offset 2587 add r12, r12, pc 2588 bx r12 2589 __func_offset: 2590 .word func - . 2591 */ 2592 2593#define ARM2THUMB_STATIC_GLUE_SIZE 12 2594static const insn32 a2t1_ldr_insn = 0xe59fc000; 2595static const insn32 a2t2_bx_r12_insn = 0xe12fff1c; 2596static const insn32 a2t3_func_addr_insn = 0x00000001; 2597 2598#define ARM2THUMB_V5_STATIC_GLUE_SIZE 8 2599static const insn32 a2t1v5_ldr_insn = 0xe51ff004; 2600static const insn32 a2t2v5_func_addr_insn = 0x00000001; 2601 2602#define ARM2THUMB_PIC_GLUE_SIZE 16 2603static const insn32 a2t1p_ldr_insn = 0xe59fc004; 2604static const insn32 a2t2p_add_pc_insn = 0xe08cc00f; 2605static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c; 2606 2607/* Thumb->ARM: Thumb->(non-interworking aware) ARM 2608 2609 .thumb .thumb 2610 .align 2 .align 2 2611 __func_from_thumb: __func_from_thumb: 2612 bx pc push {r6, lr} 2613 nop ldr r6, __func_addr 2614 .arm mov lr, pc 2615 __func_change_to_arm: bx r6 2616 b func .arm 2617 __func_back_to_thumb: 2618 ldmia r13! {r6, lr} 2619 bx lr 2620 __func_addr: 2621 .word func */ 2622 2623#define THUMB2ARM_GLUE_SIZE 8 2624static const insn16 t2a1_bx_pc_insn = 0x4778; 2625static const insn16 t2a2_noop_insn = 0x46c0; 2626static const insn32 t2a3_b_insn = 0xea000000; 2627 2628#define VFP11_ERRATUM_VENEER_SIZE 8 2629 2630#ifndef ELFARM_NABI_C_INCLUDED 2631bfd_boolean 2632bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info) 2633{ 2634 asection * s; 2635 bfd_byte * foo; 2636 struct elf32_arm_link_hash_table * globals; 2637 2638 globals = elf32_arm_hash_table (info); 2639 2640 BFD_ASSERT (globals != NULL); 2641 2642 if (globals->arm_glue_size != 0) 2643 { 2644 BFD_ASSERT (globals->bfd_of_glue_owner != NULL); 2645 2646 s = bfd_get_section_by_name (globals->bfd_of_glue_owner, 2647 ARM2THUMB_GLUE_SECTION_NAME); 2648 2649 BFD_ASSERT (s != NULL); 2650 2651 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size); 2652 2653 BFD_ASSERT (s->size == globals->arm_glue_size); 2654 s->contents = foo; 2655 } 2656 2657 if (globals->thumb_glue_size != 0) 2658 { 2659 BFD_ASSERT (globals->bfd_of_glue_owner != NULL); 2660 2661 s = bfd_get_section_by_name 2662 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); 2663 2664 BFD_ASSERT (s != NULL); 2665 2666 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size); 2667 2668 BFD_ASSERT (s->size == globals->thumb_glue_size); 2669 s->contents = foo; 2670 } 2671 2672 if (globals->vfp11_erratum_glue_size != 0) 2673 { 2674 BFD_ASSERT (globals->bfd_of_glue_owner != NULL); 2675 2676 s = bfd_get_section_by_name 2677 (globals->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME); 2678 2679 BFD_ASSERT (s != NULL); 2680 2681 foo = bfd_alloc (globals->bfd_of_glue_owner, 2682 globals->vfp11_erratum_glue_size); 2683 2684 BFD_ASSERT (s->size == globals->vfp11_erratum_glue_size); 2685 s->contents = foo; 2686 } 2687 2688 return TRUE; 2689} 2690 2691/* Allocate space and symbols for calling a Thumb function from Arm mode. 2692 returns the symbol identifying teh stub. */ 2693static struct elf_link_hash_entry * 2694record_arm_to_thumb_glue (struct bfd_link_info * link_info, 2695 struct elf_link_hash_entry * h) 2696{ 2697 const char * name = h->root.root.string; 2698 asection * s; 2699 char * tmp_name; 2700 struct elf_link_hash_entry * myh; 2701 struct bfd_link_hash_entry * bh; 2702 struct elf32_arm_link_hash_table * globals; 2703 bfd_vma val; 2704 bfd_size_type size; 2705 2706 globals = elf32_arm_hash_table (link_info); 2707 2708 BFD_ASSERT (globals != NULL); 2709 BFD_ASSERT (globals->bfd_of_glue_owner != NULL); 2710 2711 s = bfd_get_section_by_name 2712 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME); 2713 2714 BFD_ASSERT (s != NULL); 2715 2716 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); 2717 2718 BFD_ASSERT (tmp_name); 2719 2720 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); 2721 2722 myh = elf_link_hash_lookup 2723 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); 2724 2725 if (myh != NULL) 2726 { 2727 /* We've already seen this guy. */ 2728 free (tmp_name); 2729 return myh; 2730 } 2731 2732 /* The only trick here is using hash_table->arm_glue_size as the value. 2733 Even though the section isn't allocated yet, this is where we will be 2734 putting it. */ 2735 bh = NULL; 2736 val = globals->arm_glue_size + 1; 2737 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner, 2738 tmp_name, BSF_GLOBAL, s, val, 2739 NULL, TRUE, FALSE, &bh); 2740 2741 myh = (struct elf_link_hash_entry *) bh; 2742 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); 2743 myh->forced_local = 1; 2744 2745 free (tmp_name); 2746 2747 if (link_info->shared || globals->root.is_relocatable_executable 2748 || globals->pic_veneer) 2749 size = ARM2THUMB_PIC_GLUE_SIZE; 2750 else if (globals->use_blx) 2751 size = ARM2THUMB_V5_STATIC_GLUE_SIZE; 2752 else 2753 size = ARM2THUMB_STATIC_GLUE_SIZE; 2754 2755 s->size += size; 2756 globals->arm_glue_size += size; 2757 2758 return myh; 2759} 2760 2761static void 2762record_thumb_to_arm_glue (struct bfd_link_info *link_info, 2763 struct elf_link_hash_entry *h) 2764{ 2765 const char *name = h->root.root.string; 2766 asection *s; 2767 char *tmp_name; 2768 struct elf_link_hash_entry *myh; 2769 struct bfd_link_hash_entry *bh; 2770 struct elf32_arm_link_hash_table *hash_table; 2771 bfd_vma val; 2772 2773 hash_table = elf32_arm_hash_table (link_info); 2774 2775 BFD_ASSERT (hash_table != NULL); 2776 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); 2777 2778 s = bfd_get_section_by_name 2779 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); 2780 2781 BFD_ASSERT (s != NULL); 2782 2783 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) 2784 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); 2785 2786 BFD_ASSERT (tmp_name); 2787 2788 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); 2789 2790 myh = elf_link_hash_lookup 2791 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); 2792 2793 if (myh != NULL) 2794 { 2795 /* We've already seen this guy. */ 2796 free (tmp_name); 2797 return; 2798 } 2799 2800 bh = NULL; 2801 val = hash_table->thumb_glue_size + 1; 2802 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, 2803 tmp_name, BSF_GLOBAL, s, val, 2804 NULL, TRUE, FALSE, &bh); 2805 2806 /* If we mark it 'Thumb', the disassembler will do a better job. */ 2807 myh = (struct elf_link_hash_entry *) bh; 2808 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC); 2809 myh->forced_local = 1; 2810 2811 free (tmp_name); 2812 2813#define CHANGE_TO_ARM "__%s_change_to_arm" 2814#define BACK_FROM_ARM "__%s_back_from_arm" 2815 2816 /* Allocate another symbol to mark where we switch to Arm mode. */ 2817 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) 2818 + strlen (CHANGE_TO_ARM) + 1); 2819 2820 BFD_ASSERT (tmp_name); 2821 2822 sprintf (tmp_name, CHANGE_TO_ARM, name); 2823 2824 bh = NULL; 2825 val = hash_table->thumb_glue_size + 4, 2826 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, 2827 tmp_name, BSF_LOCAL, s, val, 2828 NULL, TRUE, FALSE, &bh); 2829 2830 free (tmp_name); 2831 2832 s->size += THUMB2ARM_GLUE_SIZE; 2833 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE; 2834 2835 return; 2836} 2837 2838 2839/* Add an entry to the code/data map for section SEC. */ 2840 2841static void 2842elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma) 2843{ 2844 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec); 2845 unsigned int newidx; 2846 2847 if (sec_data->map == NULL) 2848 { 2849 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map)); 2850 sec_data->mapcount = 0; 2851 sec_data->mapsize = 1; 2852 } 2853 2854 newidx = sec_data->mapcount++; 2855 2856 if (sec_data->mapcount > sec_data->mapsize) 2857 { 2858 sec_data->mapsize *= 2; 2859 sec_data->map = bfd_realloc (sec_data->map, sec_data->mapsize 2860 * sizeof (elf32_arm_section_map)); 2861 } 2862 2863 sec_data->map[newidx].vma = vma; 2864 sec_data->map[newidx].type = type; 2865} 2866 2867 2868/* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode 2869 veneers are handled for now. */ 2870 2871static bfd_vma 2872record_vfp11_erratum_veneer (struct bfd_link_info *link_info, 2873 elf32_vfp11_erratum_list *branch, 2874 bfd *branch_bfd, 2875 asection *branch_sec, 2876 unsigned int offset) 2877{ 2878 asection *s; 2879 struct elf32_arm_link_hash_table *hash_table; 2880 char *tmp_name; 2881 struct elf_link_hash_entry *myh; 2882 struct bfd_link_hash_entry *bh; 2883 bfd_vma val; 2884 struct _arm_elf_section_data *sec_data; 2885 int errcount; 2886 elf32_vfp11_erratum_list *newerr; 2887 2888 hash_table = elf32_arm_hash_table (link_info); 2889 2890 BFD_ASSERT (hash_table != NULL); 2891 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); 2892 2893 s = bfd_get_section_by_name 2894 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME); 2895 2896 sec_data = elf32_arm_section_data (s); 2897 2898 BFD_ASSERT (s != NULL); 2899 2900 tmp_name = bfd_malloc ((bfd_size_type) strlen 2901 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10); 2902 2903 BFD_ASSERT (tmp_name); 2904 2905 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME, 2906 hash_table->num_vfp11_fixes); 2907 2908 myh = elf_link_hash_lookup 2909 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE); 2910 2911 BFD_ASSERT (myh == NULL); 2912 2913 bh = NULL; 2914 val = hash_table->vfp11_erratum_glue_size; 2915 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, 2916 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val, 2917 NULL, TRUE, FALSE, &bh); 2918 2919 myh = (struct elf_link_hash_entry *) bh; 2920 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); 2921 myh->forced_local = 1; 2922 2923 /* Link veneer back to calling location. */ 2924 errcount = ++(sec_data->erratumcount); 2925 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list)); 2926 2927 newerr->type = VFP11_ERRATUM_ARM_VENEER; 2928 newerr->vma = -1; 2929 newerr->u.v.branch = branch; 2930 newerr->u.v.id = hash_table->num_vfp11_fixes; 2931 branch->u.b.veneer = newerr; 2932 2933 newerr->next = sec_data->erratumlist; 2934 sec_data->erratumlist = newerr; 2935 2936 /* A symbol for the return from the veneer. */ 2937 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r", 2938 hash_table->num_vfp11_fixes); 2939 2940 myh = elf_link_hash_lookup 2941 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE); 2942 2943 if (myh != NULL) 2944 abort (); 2945 2946 bh = NULL; 2947 val = offset + 4; 2948 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL, 2949 branch_sec, val, NULL, TRUE, FALSE, &bh); 2950 2951 myh = (struct elf_link_hash_entry *) bh; 2952 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); 2953 myh->forced_local = 1; 2954 2955 free (tmp_name); 2956 2957 /* Generate a mapping symbol for the veneer section, and explicitly add an 2958 entry for that symbol to the code/data map for the section. */ 2959 if (hash_table->vfp11_erratum_glue_size == 0) 2960 { 2961 bh = NULL; 2962 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it 2963 ever requires this erratum fix. */ 2964 _bfd_generic_link_add_one_symbol (link_info, 2965 hash_table->bfd_of_glue_owner, "$a", 2966 BSF_LOCAL, s, 0, NULL, 2967 TRUE, FALSE, &bh); 2968 2969 myh = (struct elf_link_hash_entry *) bh; 2970 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); 2971 myh->forced_local = 1; 2972 2973 /* The elf32_arm_init_maps function only cares about symbols from input 2974 BFDs. We must make a note of this generated mapping symbol 2975 ourselves so that code byteswapping works properly in 2976 elf32_arm_write_section. */ 2977 elf32_arm_section_map_add (s, 'a', 0); 2978 } 2979 2980 s->size += VFP11_ERRATUM_VENEER_SIZE; 2981 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE; 2982 hash_table->num_vfp11_fixes++; 2983 2984 /* The offset of the veneer. */ 2985 return val; 2986} 2987 2988/* Add the glue sections to ABFD. This function is called from the 2989 linker scripts in ld/emultempl/{armelf}.em. */ 2990 2991bfd_boolean 2992bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd, 2993 struct bfd_link_info *info) 2994{ 2995 flagword flags; 2996 asection *sec; 2997 2998 /* If we are only performing a partial 2999 link do not bother adding the glue. */ 3000 if (info->relocatable) 3001 return TRUE; 3002 3003 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME); 3004 3005 if (sec == NULL) 3006 { 3007 /* Note: we do not include the flag SEC_LINKER_CREATED, as this 3008 will prevent elf_link_input_bfd() from processing the contents 3009 of this section. */ 3010 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 3011 | SEC_CODE | SEC_READONLY); 3012 3013 sec = bfd_make_section_with_flags (abfd, 3014 ARM2THUMB_GLUE_SECTION_NAME, 3015 flags); 3016 3017 if (sec == NULL 3018 || !bfd_set_section_alignment (abfd, sec, 2)) 3019 return FALSE; 3020 3021 /* Set the gc mark to prevent the section from being removed by garbage 3022 collection, despite the fact that no relocs refer to this section. */ 3023 sec->gc_mark = 1; 3024 } 3025 3026 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME); 3027 3028 if (sec == NULL) 3029 { 3030 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 3031 | SEC_CODE | SEC_READONLY); 3032 3033 sec = bfd_make_section_with_flags (abfd, 3034 THUMB2ARM_GLUE_SECTION_NAME, 3035 flags); 3036 3037 if (sec == NULL 3038 || !bfd_set_section_alignment (abfd, sec, 2)) 3039 return FALSE; 3040 3041 sec->gc_mark = 1; 3042 } 3043 3044 sec = bfd_get_section_by_name (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME); 3045 3046 if (sec == NULL) 3047 { 3048 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 3049 | SEC_CODE | SEC_READONLY); 3050 3051 sec = bfd_make_section_with_flags (abfd, 3052 VFP11_ERRATUM_VENEER_SECTION_NAME, 3053 flags); 3054 3055 if (sec == NULL 3056 || !bfd_set_section_alignment (abfd, sec, 2)) 3057 return FALSE; 3058 3059 sec->gc_mark = 1; 3060 } 3061 3062 return TRUE; 3063} 3064 3065/* Select a BFD to be used to hold the sections used by the glue code. 3066 This function is called from the linker scripts in ld/emultempl/ 3067 {armelf/pe}.em */ 3068 3069bfd_boolean 3070bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info) 3071{ 3072 struct elf32_arm_link_hash_table *globals; 3073 3074 /* If we are only performing a partial link 3075 do not bother getting a bfd to hold the glue. */ 3076 if (info->relocatable) 3077 return TRUE; 3078 3079 /* Make sure we don't attach the glue sections to a dynamic object. */ 3080 BFD_ASSERT (!(abfd->flags & DYNAMIC)); 3081 3082 globals = elf32_arm_hash_table (info); 3083 3084 BFD_ASSERT (globals != NULL); 3085 3086 if (globals->bfd_of_glue_owner != NULL) 3087 return TRUE; 3088 3089 /* Save the bfd for later use. */ 3090 globals->bfd_of_glue_owner = abfd; 3091 3092 return TRUE; 3093} 3094 3095static void check_use_blx(struct elf32_arm_link_hash_table *globals) 3096{ 3097 if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC, 3098 Tag_CPU_arch) > 2) 3099 globals->use_blx = 1; 3100} 3101 3102bfd_boolean 3103bfd_elf32_arm_process_before_allocation (bfd *abfd, 3104 struct bfd_link_info *link_info) 3105{ 3106 Elf_Internal_Shdr *symtab_hdr; 3107 Elf_Internal_Rela *internal_relocs = NULL; 3108 Elf_Internal_Rela *irel, *irelend; 3109 bfd_byte *contents = NULL; 3110 3111 asection *sec; 3112 struct elf32_arm_link_hash_table *globals; 3113 3114 /* If we are only performing a partial link do not bother 3115 to construct any glue. */ 3116 if (link_info->relocatable) 3117 return TRUE; 3118 3119 /* Here we have a bfd that is to be included on the link. We have a hook 3120 to do reloc rummaging, before section sizes are nailed down. */ 3121 globals = elf32_arm_hash_table (link_info); 3122 check_use_blx (globals); 3123 3124 BFD_ASSERT (globals != NULL); 3125 BFD_ASSERT (globals->bfd_of_glue_owner != NULL); 3126 3127 if (globals->byteswap_code && !bfd_big_endian (abfd)) 3128 { 3129 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."), 3130 abfd); 3131 return FALSE; 3132 } 3133 3134 /* Rummage around all the relocs and map the glue vectors. */ 3135 sec = abfd->sections; 3136 3137 if (sec == NULL) 3138 return TRUE; 3139 3140 for (; sec != NULL; sec = sec->next) 3141 { 3142 if (sec->reloc_count == 0) 3143 continue; 3144 3145 if ((sec->flags & SEC_EXCLUDE) != 0) 3146 continue; 3147 3148 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 3149 3150 /* Load the relocs. */ 3151 internal_relocs 3152 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL, 3153 (Elf_Internal_Rela *) NULL, FALSE); 3154 3155 if (internal_relocs == NULL) 3156 goto error_return; 3157 3158 irelend = internal_relocs + sec->reloc_count; 3159 for (irel = internal_relocs; irel < irelend; irel++) 3160 { 3161 long r_type; 3162 unsigned long r_index; 3163 3164 struct elf_link_hash_entry *h; 3165 3166 r_type = ELF32_R_TYPE (irel->r_info); 3167 r_index = ELF32_R_SYM (irel->r_info); 3168 3169 /* These are the only relocation types we care about. */ 3170 if ( r_type != R_ARM_PC24 3171 && r_type != R_ARM_PLT32 3172 && r_type != R_ARM_CALL 3173 && r_type != R_ARM_JUMP24 3174 && r_type != R_ARM_THM_CALL) 3175 continue; 3176 3177 /* Get the section contents if we haven't done so already. */ 3178 if (contents == NULL) 3179 { 3180 /* Get cached copy if it exists. */ 3181 if (elf_section_data (sec)->this_hdr.contents != NULL) 3182 contents = elf_section_data (sec)->this_hdr.contents; 3183 else 3184 { 3185 /* Go get them off disk. */ 3186 if (! bfd_malloc_and_get_section (abfd, sec, &contents)) 3187 goto error_return; 3188 } 3189 } 3190 3191 /* If the relocation is not against a symbol it cannot concern us. */ 3192 h = NULL; 3193 3194 /* We don't care about local symbols. */ 3195 if (r_index < symtab_hdr->sh_info) 3196 continue; 3197 3198 /* This is an external symbol. */ 3199 r_index -= symtab_hdr->sh_info; 3200 h = (struct elf_link_hash_entry *) 3201 elf_sym_hashes (abfd)[r_index]; 3202 3203 /* If the relocation is against a static symbol it must be within 3204 the current section and so cannot be a cross ARM/Thumb relocation. */ 3205 if (h == NULL) 3206 continue; 3207 3208 /* If the call will go through a PLT entry then we do not need 3209 glue. */ 3210 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1) 3211 continue; 3212 3213 switch (r_type) 3214 { 3215 case R_ARM_PC24: 3216 case R_ARM_PLT32: 3217 case R_ARM_CALL: 3218 case R_ARM_JUMP24: 3219 /* This one is a call from arm code. We need to look up 3220 the target of the call. If it is a thumb target, we 3221 insert glue. */ 3222 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC 3223 && !(r_type == R_ARM_CALL && globals->use_blx)) 3224 record_arm_to_thumb_glue (link_info, h); 3225 break; 3226 3227 case R_ARM_THM_CALL: 3228 /* This one is a call from thumb code. We look 3229 up the target of the call. If it is not a thumb 3230 target, we insert glue. */ 3231 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx 3232 && h->root.type != bfd_link_hash_undefweak) 3233 record_thumb_to_arm_glue (link_info, h); 3234 break; 3235 3236 default: 3237 abort (); 3238 } 3239 } 3240 3241 if (contents != NULL 3242 && elf_section_data (sec)->this_hdr.contents != contents) 3243 free (contents); 3244 contents = NULL; 3245 3246 if (internal_relocs != NULL 3247 && elf_section_data (sec)->relocs != internal_relocs) 3248 free (internal_relocs); 3249 internal_relocs = NULL; 3250 } 3251 3252 return TRUE; 3253 3254error_return: 3255 if (contents != NULL 3256 && elf_section_data (sec)->this_hdr.contents != contents) 3257 free (contents); 3258 if (internal_relocs != NULL 3259 && elf_section_data (sec)->relocs != internal_relocs) 3260 free (internal_relocs); 3261 3262 return FALSE; 3263} 3264#endif 3265 3266 3267/* Initialise maps of ARM/Thumb/data for input BFDs. */ 3268 3269void 3270bfd_elf32_arm_init_maps (bfd *abfd) 3271{ 3272 Elf_Internal_Sym *isymbuf; 3273 Elf_Internal_Shdr *hdr; 3274 unsigned int i, localsyms; 3275 3276 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour || elf_tdata (abfd) == NULL) 3277 return; 3278 3279 if ((abfd->flags & DYNAMIC) != 0) 3280 return; 3281 3282 hdr = &elf_tdata (abfd)->symtab_hdr; 3283 localsyms = hdr->sh_info; 3284 3285 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field 3286 should contain the number of local symbols, which should come before any 3287 global symbols. Mapping symbols are always local. */ 3288 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, 3289 NULL); 3290 3291 /* No internal symbols read? Skip this BFD. */ 3292 if (isymbuf == NULL) 3293 return; 3294 3295 for (i = 0; i < localsyms; i++) 3296 { 3297 Elf_Internal_Sym *isym = &isymbuf[i]; 3298 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx); 3299 const char *name; 3300 3301 if (sec != NULL 3302 && ELF_ST_BIND (isym->st_info) == STB_LOCAL) 3303 { 3304 name = bfd_elf_string_from_elf_section (abfd, 3305 hdr->sh_link, isym->st_name); 3306 3307 if (bfd_is_arm_special_symbol_name (name, 3308 BFD_ARM_SPECIAL_SYM_TYPE_MAP)) 3309 elf32_arm_section_map_add (sec, name[1], isym->st_value); 3310 } 3311 } 3312} 3313 3314 3315void 3316bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info) 3317{ 3318 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info); 3319 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd); 3320 3321 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */ 3322 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7) 3323 { 3324 switch (globals->vfp11_fix) 3325 { 3326 case BFD_ARM_VFP11_FIX_DEFAULT: 3327 case BFD_ARM_VFP11_FIX_NONE: 3328 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE; 3329 break; 3330 3331 default: 3332 /* Give a warning, but do as the user requests anyway. */ 3333 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum " 3334 "workaround is not necessary for target architecture"), obfd); 3335 } 3336 } 3337 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT) 3338 /* For earlier architectures, we might need the workaround, but do not 3339 enable it by default. If users is running with broken hardware, they 3340 must enable the erratum fix explicitly. */ 3341 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE; 3342} 3343 3344 3345enum bfd_arm_vfp11_pipe { 3346 VFP11_FMAC, 3347 VFP11_LS, 3348 VFP11_DS, 3349 VFP11_BAD 3350}; 3351 3352/* Return a VFP register number. This is encoded as RX:X for single-precision 3353 registers, or X:RX for double-precision registers, where RX is the group of 3354 four bits in the instruction encoding and X is the single extension bit. 3355 RX and X fields are specified using their lowest (starting) bit. The return 3356 value is: 3357 3358 0...31: single-precision registers s0...s31 3359 32...63: double-precision registers d0...d31. 3360 3361 Although X should be zero for VFP11 (encoding d0...d15 only), we might 3362 encounter VFP3 instructions, so we allow the full range for DP registers. */ 3363 3364static unsigned int 3365bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx, 3366 unsigned int x) 3367{ 3368 if (is_double) 3369 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32; 3370 else 3371 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1); 3372} 3373 3374/* Set bits in *WMASK according to a register number REG as encoded by 3375 bfd_arm_vfp11_regno(). Ignore d16-d31. */ 3376 3377static void 3378bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg) 3379{ 3380 if (reg < 32) 3381 *wmask |= 1 << reg; 3382 else if (reg < 48) 3383 *wmask |= 3 << ((reg - 32) * 2); 3384} 3385 3386/* Return TRUE if WMASK overwrites anything in REGS. */ 3387 3388static bfd_boolean 3389bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs) 3390{ 3391 int i; 3392 3393 for (i = 0; i < numregs; i++) 3394 { 3395 unsigned int reg = regs[i]; 3396 3397 if (reg < 32 && (wmask & (1 << reg)) != 0) 3398 return TRUE; 3399 3400 reg -= 32; 3401 3402 if (reg >= 16) 3403 continue; 3404 3405 if ((wmask & (3 << (reg * 2))) != 0) 3406 return TRUE; 3407 } 3408 3409 return FALSE; 3410} 3411 3412/* In this function, we're interested in two things: finding input registers 3413 for VFP data-processing instructions, and finding the set of registers which 3414 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to 3415 hold the written set, so FLDM etc. are easy to deal with (we're only 3416 interested in 32 SP registers or 16 dp registers, due to the VFP version 3417 implemented by the chip in question). DP registers are marked by setting 3418 both SP registers in the write mask). */ 3419 3420static enum bfd_arm_vfp11_pipe 3421bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs, 3422 int *numregs) 3423{ 3424 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD; 3425 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0; 3426 3427 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */ 3428 { 3429 unsigned int pqrs; 3430 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22); 3431 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5); 3432 3433 pqrs = ((insn & 0x00800000) >> 20) 3434 | ((insn & 0x00300000) >> 19) 3435 | ((insn & 0x00000040) >> 6); 3436 3437 switch (pqrs) 3438 { 3439 case 0: /* fmac[sd]. */ 3440 case 1: /* fnmac[sd]. */ 3441 case 2: /* fmsc[sd]. */ 3442 case 3: /* fnmsc[sd]. */ 3443 pipe = VFP11_FMAC; 3444 bfd_arm_vfp11_write_mask (destmask, fd); 3445 regs[0] = fd; 3446 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */ 3447 regs[2] = fm; 3448 *numregs = 3; 3449 break; 3450 3451 case 4: /* fmul[sd]. */ 3452 case 5: /* fnmul[sd]. */ 3453 case 6: /* fadd[sd]. */ 3454 case 7: /* fsub[sd]. */ 3455 pipe = VFP11_FMAC; 3456 goto vfp_binop; 3457 3458 case 8: /* fdiv[sd]. */ 3459 pipe = VFP11_DS; 3460 vfp_binop: 3461 bfd_arm_vfp11_write_mask (destmask, fd); 3462 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */ 3463 regs[1] = fm; 3464 *numregs = 2; 3465 break; 3466 3467 case 15: /* extended opcode. */ 3468 { 3469 unsigned int extn = ((insn >> 15) & 0x1e) 3470 | ((insn >> 7) & 1); 3471 3472 switch (extn) 3473 { 3474 case 0: /* fcpy[sd]. */ 3475 case 1: /* fabs[sd]. */ 3476 case 2: /* fneg[sd]. */ 3477 case 8: /* fcmp[sd]. */ 3478 case 9: /* fcmpe[sd]. */ 3479 case 10: /* fcmpz[sd]. */ 3480 case 11: /* fcmpez[sd]. */ 3481 case 16: /* fuito[sd]. */ 3482 case 17: /* fsito[sd]. */ 3483 case 24: /* ftoui[sd]. */ 3484 case 25: /* ftouiz[sd]. */ 3485 case 26: /* ftosi[sd]. */ 3486 case 27: /* ftosiz[sd]. */ 3487 /* These instructions will not bounce due to underflow. */ 3488 *numregs = 0; 3489 pipe = VFP11_FMAC; 3490 break; 3491 3492 case 3: /* fsqrt[sd]. */ 3493 /* fsqrt cannot underflow, but it can (perhaps) overwrite 3494 registers to cause the erratum in previous instructions. */ 3495 bfd_arm_vfp11_write_mask (destmask, fd); 3496 pipe = VFP11_DS; 3497 break; 3498 3499 case 15: /* fcvt{ds,sd}. */ 3500 { 3501 int rnum = 0; 3502 3503 bfd_arm_vfp11_write_mask (destmask, fd); 3504 3505 /* Only FCVTSD can underflow. */ 3506 if ((insn & 0x100) != 0) 3507 regs[rnum++] = fm; 3508 3509 *numregs = rnum; 3510 3511 pipe = VFP11_FMAC; 3512 } 3513 break; 3514 3515 default: 3516 return VFP11_BAD; 3517 } 3518 } 3519 break; 3520 3521 default: 3522 return VFP11_BAD; 3523 } 3524 } 3525 /* Two-register transfer. */ 3526 else if ((insn & 0x0fe00ed0) == 0x0c400a10) 3527 { 3528 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5); 3529 3530 if ((insn & 0x100000) == 0) 3531 { 3532 if (is_double) 3533 bfd_arm_vfp11_write_mask (destmask, fm); 3534 else 3535 { 3536 bfd_arm_vfp11_write_mask (destmask, fm); 3537 bfd_arm_vfp11_write_mask (destmask, fm + 1); 3538 } 3539 } 3540 3541 pipe = VFP11_LS; 3542 } 3543 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */ 3544 { 3545 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22); 3546 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1); 3547 3548 switch (puw) 3549 { 3550 case 0: /* Two-reg transfer. We should catch these above. */ 3551 abort (); 3552 3553 case 2: /* fldm[sdx]. */ 3554 case 3: 3555 case 5: 3556 { 3557 unsigned int i, offset = insn & 0xff; 3558 3559 if (is_double) 3560 offset >>= 1; 3561 3562 for (i = fd; i < fd + offset; i++) 3563 bfd_arm_vfp11_write_mask (destmask, i); 3564 } 3565 break; 3566 3567 case 4: /* fld[sd]. */ 3568 case 6: 3569 bfd_arm_vfp11_write_mask (destmask, fd); 3570 break; 3571 3572 default: 3573 return VFP11_BAD; 3574 } 3575 3576 pipe = VFP11_LS; 3577 } 3578 /* Single-register transfer. Note L==0. */ 3579 else if ((insn & 0x0f100e10) == 0x0e000a10) 3580 { 3581 unsigned int opcode = (insn >> 21) & 7; 3582 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7); 3583 3584 switch (opcode) 3585 { 3586 case 0: /* fmsr/fmdlr. */ 3587 case 1: /* fmdhr. */ 3588 /* Mark fmdhr and fmdlr as writing to the whole of the DP 3589 destination register. I don't know if this is exactly right, 3590 but it is the conservative choice. */ 3591 bfd_arm_vfp11_write_mask (destmask, fn); 3592 break; 3593 3594 case 7: /* fmxr. */ 3595 break; 3596 } 3597 3598 pipe = VFP11_LS; 3599 } 3600 3601 return pipe; 3602} 3603 3604 3605static int elf32_arm_compare_mapping (const void * a, const void * b); 3606 3607 3608/* Look for potentially-troublesome code sequences which might trigger the 3609 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet 3610 (available from ARM) for details of the erratum. A short version is 3611 described in ld.texinfo. */ 3612 3613bfd_boolean 3614bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info) 3615{ 3616 asection *sec; 3617 bfd_byte *contents = NULL; 3618 int state = 0; 3619 int regs[3], numregs = 0; 3620 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info); 3621 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR); 3622 3623 /* We use a simple FSM to match troublesome VFP11 instruction sequences. 3624 The states transition as follows: 3625 3626 0 -> 1 (vector) or 0 -> 2 (scalar) 3627 A VFP FMAC-pipeline instruction has been seen. Fill 3628 regs[0]..regs[numregs-1] with its input operands. Remember this 3629 instruction in 'first_fmac'. 3630 3631 1 -> 2 3632 Any instruction, except for a VFP instruction which overwrites 3633 regs[*]. 3634 3635 1 -> 3 [ -> 0 ] or 3636 2 -> 3 [ -> 0 ] 3637 A VFP instruction has been seen which overwrites any of regs[*]. 3638 We must make a veneer! Reset state to 0 before examining next 3639 instruction. 3640 3641 2 -> 0 3642 If we fail to match anything in state 2, reset to state 0 and reset 3643 the instruction pointer to the instruction after 'first_fmac'. 3644 3645 If the VFP11 vector mode is in use, there must be at least two unrelated 3646 instructions between anti-dependent VFP11 instructions to properly avoid 3647 triggering the erratum, hence the use of the extra state 1. 3648 */ 3649 3650 /* If we are only performing a partial link do not bother 3651 to construct any glue. */ 3652 if (link_info->relocatable) 3653 return TRUE; 3654 3655 /* We should have chosen a fix type by the time we get here. */ 3656 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT); 3657 3658 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE) 3659 return TRUE; 3660 3661 /* Skip if this bfd does not correspond to an ELF image. */ 3662 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour) 3663 return TRUE; 3664 3665 for (sec = abfd->sections; sec != NULL; sec = sec->next) 3666 { 3667 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0; 3668 struct _arm_elf_section_data *sec_data; 3669 3670 /* If we don't have executable progbits, we're not interested in this 3671 section. Also skip if section is to be excluded. */ 3672 if (elf_section_type (sec) != SHT_PROGBITS 3673 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0 3674 || (sec->flags & SEC_EXCLUDE) != 0 3675 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0) 3676 continue; 3677 3678 sec_data = elf32_arm_section_data (sec); 3679 3680 if (sec_data->mapcount == 0) 3681 continue; 3682 3683 if (elf_section_data (sec)->this_hdr.contents != NULL) 3684 contents = elf_section_data (sec)->this_hdr.contents; 3685 else if (! bfd_malloc_and_get_section (abfd, sec, &contents)) 3686 goto error_return; 3687 3688 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map), 3689 elf32_arm_compare_mapping); 3690 3691 for (span = 0; span < sec_data->mapcount; span++) 3692 { 3693 unsigned int span_start = sec_data->map[span].vma; 3694 unsigned int span_end = (span == sec_data->mapcount - 1) 3695 ? sec->size : sec_data->map[span + 1].vma; 3696 char span_type = sec_data->map[span].type; 3697 3698 /* FIXME: Only ARM mode is supported at present. We may need to 3699 support Thumb-2 mode also at some point. */ 3700 if (span_type != 'a') 3701 continue; 3702 3703 for (i = span_start; i < span_end;) 3704 { 3705 unsigned int next_i = i + 4; 3706 unsigned int insn = bfd_big_endian (abfd) 3707 ? (contents[i] << 24) 3708 | (contents[i + 1] << 16) 3709 | (contents[i + 2] << 8) 3710 | contents[i + 3] 3711 : (contents[i + 3] << 24) 3712 | (contents[i + 2] << 16) 3713 | (contents[i + 1] << 8) 3714 | contents[i]; 3715 unsigned int writemask = 0; 3716 enum bfd_arm_vfp11_pipe pipe; 3717 3718 switch (state) 3719 { 3720 case 0: 3721 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs, 3722 &numregs); 3723 /* I'm assuming the VFP11 erratum can trigger with denorm 3724 operands on either the FMAC or the DS pipeline. This might 3725 lead to slightly overenthusiastic veneer insertion. */ 3726 if (pipe == VFP11_FMAC || pipe == VFP11_DS) 3727 { 3728 state = use_vector ? 1 : 2; 3729 first_fmac = i; 3730 veneer_of_insn = insn; 3731 } 3732 break; 3733 3734 case 1: 3735 { 3736 int other_regs[3], other_numregs; 3737 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, 3738 other_regs, 3739 &other_numregs); 3740 if (pipe != VFP11_BAD 3741 && bfd_arm_vfp11_antidependency (writemask, regs, 3742 numregs)) 3743 state = 3; 3744 else 3745 state = 2; 3746 } 3747 break; 3748 3749 case 2: 3750 { 3751 int other_regs[3], other_numregs; 3752 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, 3753 other_regs, 3754 &other_numregs); 3755 if (pipe != VFP11_BAD 3756 && bfd_arm_vfp11_antidependency (writemask, regs, 3757 numregs)) 3758 state = 3; 3759 else 3760 { 3761 state = 0; 3762 next_i = first_fmac + 4; 3763 } 3764 } 3765 break; 3766 3767 case 3: 3768 abort (); /* Should be unreachable. */ 3769 } 3770 3771 if (state == 3) 3772 { 3773 elf32_vfp11_erratum_list *newerr 3774 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list)); 3775 int errcount; 3776 3777 errcount = ++(elf32_arm_section_data (sec)->erratumcount); 3778 3779 newerr->u.b.vfp_insn = veneer_of_insn; 3780 3781 switch (span_type) 3782 { 3783 case 'a': 3784 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER; 3785 break; 3786 3787 default: 3788 abort (); 3789 } 3790 3791 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec, 3792 first_fmac); 3793 3794 newerr->vma = -1; 3795 3796 newerr->next = sec_data->erratumlist; 3797 sec_data->erratumlist = newerr; 3798 3799 state = 0; 3800 } 3801 3802 i = next_i; 3803 } 3804 } 3805 3806 if (contents != NULL 3807 && elf_section_data (sec)->this_hdr.contents != contents) 3808 free (contents); 3809 contents = NULL; 3810 } 3811 3812 return TRUE; 3813 3814error_return: 3815 if (contents != NULL 3816 && elf_section_data (sec)->this_hdr.contents != contents) 3817 free (contents); 3818 3819 return FALSE; 3820} 3821 3822/* Find virtual-memory addresses for VFP11 erratum veneers and return locations 3823 after sections have been laid out, using specially-named symbols. */ 3824 3825void 3826bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd, 3827 struct bfd_link_info *link_info) 3828{ 3829 asection *sec; 3830 struct elf32_arm_link_hash_table *globals; 3831 char *tmp_name; 3832 3833 if (link_info->relocatable) 3834 return; 3835 3836 /* Skip if this bfd does not correspond to an ELF image. */ 3837 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour) 3838 return; 3839 3840 globals = elf32_arm_hash_table (link_info); 3841 3842 tmp_name = bfd_malloc ((bfd_size_type) strlen 3843 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10); 3844 3845 for (sec = abfd->sections; sec != NULL; sec = sec->next) 3846 { 3847 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec); 3848 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist; 3849 3850 for (; errnode != NULL; errnode = errnode->next) 3851 { 3852 struct elf_link_hash_entry *myh; 3853 bfd_vma vma; 3854 3855 switch (errnode->type) 3856 { 3857 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER: 3858 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER: 3859 /* Find veneer symbol. */ 3860 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME, 3861 errnode->u.b.veneer->u.v.id); 3862 3863 myh = elf_link_hash_lookup 3864 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); 3865 3866 if (myh == NULL) 3867 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer " 3868 "`%s'"), abfd, tmp_name); 3869 3870 vma = myh->root.u.def.section->output_section->vma 3871 + myh->root.u.def.section->output_offset 3872 + myh->root.u.def.value; 3873 3874 errnode->u.b.veneer->vma = vma; 3875 break; 3876 3877 case VFP11_ERRATUM_ARM_VENEER: 3878 case VFP11_ERRATUM_THUMB_VENEER: 3879 /* Find return location. */ 3880 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r", 3881 errnode->u.v.id); 3882 3883 myh = elf_link_hash_lookup 3884 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); 3885 3886 if (myh == NULL) 3887 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer " 3888 "`%s'"), abfd, tmp_name); 3889 3890 vma = myh->root.u.def.section->output_section->vma 3891 + myh->root.u.def.section->output_offset 3892 + myh->root.u.def.value; 3893 3894 errnode->u.v.branch->vma = vma; 3895 break; 3896 3897 default: 3898 abort (); 3899 } 3900 } 3901 } 3902 3903 free (tmp_name); 3904} 3905 3906 3907/* Set target relocation values needed during linking. */ 3908 3909void 3910bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd, 3911 struct bfd_link_info *link_info, 3912 int target1_is_rel, 3913 char * target2_type, 3914 int fix_v4bx, 3915 int use_blx, 3916 bfd_arm_vfp11_fix vfp11_fix, 3917 int no_enum_warn, int pic_veneer) 3918{ 3919 struct elf32_arm_link_hash_table *globals; 3920 3921 globals = elf32_arm_hash_table (link_info); 3922 3923 globals->target1_is_rel = target1_is_rel; 3924 if (strcmp (target2_type, "rel") == 0) 3925 globals->target2_reloc = R_ARM_REL32; 3926 else if (strcmp (target2_type, "abs") == 0) 3927 globals->target2_reloc = R_ARM_ABS32; 3928 else if (strcmp (target2_type, "got-rel") == 0) 3929 globals->target2_reloc = R_ARM_GOT_PREL; 3930 else 3931 { 3932 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."), 3933 target2_type); 3934 } 3935 globals->fix_v4bx = fix_v4bx; 3936 globals->use_blx |= use_blx; 3937 globals->vfp11_fix = vfp11_fix; 3938 globals->pic_veneer = pic_veneer; 3939 3940 elf32_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn; 3941} 3942 3943/* The thumb form of a long branch is a bit finicky, because the offset 3944 encoding is split over two fields, each in it's own instruction. They 3945 can occur in any order. So given a thumb form of long branch, and an 3946 offset, insert the offset into the thumb branch and return finished 3947 instruction. 3948 3949 It takes two thumb instructions to encode the target address. Each has 3950 11 bits to invest. The upper 11 bits are stored in one (identified by 3951 H-0.. see below), the lower 11 bits are stored in the other (identified 3952 by H-1). 3953 3954 Combine together and shifted left by 1 (it's a half word address) and 3955 there you have it. 3956 3957 Op: 1111 = F, 3958 H-0, upper address-0 = 000 3959 Op: 1111 = F, 3960 H-1, lower address-0 = 800 3961 3962 They can be ordered either way, but the arm tools I've seen always put 3963 the lower one first. It probably doesn't matter. krk@cygnus.com 3964 3965 XXX: Actually the order does matter. The second instruction (H-1) 3966 moves the computed address into the PC, so it must be the second one 3967 in the sequence. The problem, however is that whilst little endian code 3968 stores the instructions in HI then LOW order, big endian code does the 3969 reverse. nickc@cygnus.com. */ 3970 3971#define LOW_HI_ORDER 0xF800F000 3972#define HI_LOW_ORDER 0xF000F800 3973 3974static insn32 3975insert_thumb_branch (insn32 br_insn, int rel_off) 3976{ 3977 unsigned int low_bits; 3978 unsigned int high_bits; 3979 3980 BFD_ASSERT ((rel_off & 1) != 1); 3981 3982 rel_off >>= 1; /* Half word aligned address. */ 3983 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */ 3984 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */ 3985 3986 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER) 3987 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits; 3988 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER) 3989 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits; 3990 else 3991 /* FIXME: abort is probably not the right call. krk@cygnus.com */ 3992 abort (); /* Error - not a valid branch instruction form. */ 3993 3994 return br_insn; 3995} 3996 3997 3998/* Store an Arm insn into an output section not processed by 3999 elf32_arm_write_section. */ 4000 4001static void 4002put_arm_insn (struct elf32_arm_link_hash_table *htab, 4003 bfd * output_bfd, bfd_vma val, void * ptr) 4004{ 4005 if (htab->byteswap_code != bfd_little_endian (output_bfd)) 4006 bfd_putl32 (val, ptr); 4007 else 4008 bfd_putb32 (val, ptr); 4009} 4010 4011 4012/* Store a 16-bit Thumb insn into an output section not processed by 4013 elf32_arm_write_section. */ 4014 4015static void 4016put_thumb_insn (struct elf32_arm_link_hash_table *htab, 4017 bfd * output_bfd, bfd_vma val, void * ptr) 4018{ 4019 if (htab->byteswap_code != bfd_little_endian (output_bfd)) 4020 bfd_putl16 (val, ptr); 4021 else 4022 bfd_putb16 (val, ptr); 4023} 4024 4025 4026/* Thumb code calling an ARM function. */ 4027 4028static int 4029elf32_thumb_to_arm_stub (struct bfd_link_info * info, 4030 const char * name, 4031 bfd * input_bfd, 4032 bfd * output_bfd, 4033 asection * input_section, 4034 bfd_byte * hit_data, 4035 asection * sym_sec, 4036 bfd_vma offset, 4037 bfd_signed_vma addend, 4038 bfd_vma val, 4039 char **error_message) 4040{ 4041 asection * s = 0; 4042 bfd_vma my_offset; 4043 unsigned long int tmp; 4044 long int ret_offset; 4045 struct elf_link_hash_entry * myh; 4046 struct elf32_arm_link_hash_table * globals; 4047 4048 myh = find_thumb_glue (info, name, error_message); 4049 if (myh == NULL) 4050 return FALSE; 4051 4052 globals = elf32_arm_hash_table (info); 4053 4054 BFD_ASSERT (globals != NULL); 4055 BFD_ASSERT (globals->bfd_of_glue_owner != NULL); 4056 4057 my_offset = myh->root.u.def.value; 4058 4059 s = bfd_get_section_by_name (globals->bfd_of_glue_owner, 4060 THUMB2ARM_GLUE_SECTION_NAME); 4061 4062 BFD_ASSERT (s != NULL); 4063 BFD_ASSERT (s->contents != NULL); 4064 BFD_ASSERT (s->output_section != NULL); 4065 4066 if ((my_offset & 0x01) == 0x01) 4067 { 4068 if (sym_sec != NULL 4069 && sym_sec->owner != NULL 4070 && !INTERWORK_FLAG (sym_sec->owner)) 4071 { 4072 (*_bfd_error_handler) 4073 (_("%B(%s): warning: interworking not enabled.\n" 4074 " first occurrence: %B: thumb call to arm"), 4075 sym_sec->owner, input_bfd, name); 4076 4077 return FALSE; 4078 } 4079 4080 --my_offset; 4081 myh->root.u.def.value = my_offset; 4082 4083 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn, 4084 s->contents + my_offset); 4085 4086 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn, 4087 s->contents + my_offset + 2); 4088 4089 ret_offset = 4090 /* Address of destination of the stub. */ 4091 ((bfd_signed_vma) val) 4092 - ((bfd_signed_vma) 4093 /* Offset from the start of the current section 4094 to the start of the stubs. */ 4095 (s->output_offset 4096 /* Offset of the start of this stub from the start of the stubs. */ 4097 + my_offset 4098 /* Address of the start of the current section. */ 4099 + s->output_section->vma) 4100 /* The branch instruction is 4 bytes into the stub. */ 4101 + 4 4102 /* ARM branches work from the pc of the instruction + 8. */ 4103 + 8); 4104 4105 put_arm_insn (globals, output_bfd, 4106 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF), 4107 s->contents + my_offset + 4); 4108 } 4109 4110 BFD_ASSERT (my_offset <= globals->thumb_glue_size); 4111 4112 /* Now go back and fix up the original BL insn to point to here. */ 4113 ret_offset = 4114 /* Address of where the stub is located. */ 4115 (s->output_section->vma + s->output_offset + my_offset) 4116 /* Address of where the BL is located. */ 4117 - (input_section->output_section->vma + input_section->output_offset 4118 + offset) 4119 /* Addend in the relocation. */ 4120 - addend 4121 /* Biassing for PC-relative addressing. */ 4122 - 8; 4123 4124 tmp = bfd_get_32 (input_bfd, hit_data 4125 - input_section->vma); 4126 4127 bfd_put_32 (output_bfd, 4128 (bfd_vma) insert_thumb_branch (tmp, ret_offset), 4129 hit_data - input_section->vma); 4130 4131 return TRUE; 4132} 4133 4134/* Populate an Arm to Thumb stub. Returns the stub symbol. */ 4135 4136static struct elf_link_hash_entry * 4137elf32_arm_create_thumb_stub (struct bfd_link_info * info, 4138 const char * name, 4139 bfd * input_bfd, 4140 bfd * output_bfd, 4141 asection * sym_sec, 4142 bfd_vma val, 4143 asection *s, 4144 char **error_message) 4145{ 4146 bfd_vma my_offset; 4147 long int ret_offset; 4148 struct elf_link_hash_entry * myh; 4149 struct elf32_arm_link_hash_table * globals; 4150 4151 myh = find_arm_glue (info, name, error_message); 4152 if (myh == NULL) 4153 return NULL; 4154 4155 globals = elf32_arm_hash_table (info); 4156 4157 BFD_ASSERT (globals != NULL); 4158 BFD_ASSERT (globals->bfd_of_glue_owner != NULL); 4159 4160 my_offset = myh->root.u.def.value; 4161 4162 if ((my_offset & 0x01) == 0x01) 4163 { 4164 if (sym_sec != NULL 4165 && sym_sec->owner != NULL 4166 && !INTERWORK_FLAG (sym_sec->owner)) 4167 { 4168 (*_bfd_error_handler) 4169 (_("%B(%s): warning: interworking not enabled.\n" 4170 " first occurrence: %B: arm call to thumb"), 4171 sym_sec->owner, input_bfd, name); 4172 } 4173 4174 --my_offset; 4175 myh->root.u.def.value = my_offset; 4176 4177 if (info->shared || globals->root.is_relocatable_executable 4178 || globals->pic_veneer) 4179 { 4180 /* For relocatable objects we can't use absolute addresses, 4181 so construct the address from a relative offset. */ 4182 /* TODO: If the offset is small it's probably worth 4183 constructing the address with adds. */ 4184 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn, 4185 s->contents + my_offset); 4186 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn, 4187 s->contents + my_offset + 4); 4188 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn, 4189 s->contents + my_offset + 8); 4190 /* Adjust the offset by 4 for the position of the add, 4191 and 8 for the pipeline offset. */ 4192 ret_offset = (val - (s->output_offset 4193 + s->output_section->vma 4194 + my_offset + 12)) 4195 | 1; 4196 bfd_put_32 (output_bfd, ret_offset, 4197 s->contents + my_offset + 12); 4198 } 4199 else if (globals->use_blx) 4200 { 4201 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn, 4202 s->contents + my_offset); 4203 4204 /* It's a thumb address. Add the low order bit. */ 4205 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn, 4206 s->contents + my_offset + 4); 4207 } 4208 else 4209 { 4210 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn, 4211 s->contents + my_offset); 4212 4213 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn, 4214 s->contents + my_offset + 4); 4215 4216 /* It's a thumb address. Add the low order bit. */ 4217 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn, 4218 s->contents + my_offset + 8); 4219 } 4220 } 4221 4222 BFD_ASSERT (my_offset <= globals->arm_glue_size); 4223 4224 return myh; 4225} 4226 4227/* Arm code calling a Thumb function. */ 4228 4229static int 4230elf32_arm_to_thumb_stub (struct bfd_link_info * info, 4231 const char * name, 4232 bfd * input_bfd, 4233 bfd * output_bfd, 4234 asection * input_section, 4235 bfd_byte * hit_data, 4236 asection * sym_sec, 4237 bfd_vma offset, 4238 bfd_signed_vma addend, 4239 bfd_vma val, 4240 char **error_message) 4241{ 4242 unsigned long int tmp; 4243 bfd_vma my_offset; 4244 asection * s; 4245 long int ret_offset; 4246 struct elf_link_hash_entry * myh; 4247 struct elf32_arm_link_hash_table * globals; 4248 4249 globals = elf32_arm_hash_table (info); 4250 4251 BFD_ASSERT (globals != NULL); 4252 BFD_ASSERT (globals->bfd_of_glue_owner != NULL); 4253 4254 s = bfd_get_section_by_name (globals->bfd_of_glue_owner, 4255 ARM2THUMB_GLUE_SECTION_NAME); 4256 BFD_ASSERT (s != NULL); 4257 BFD_ASSERT (s->contents != NULL); 4258 BFD_ASSERT (s->output_section != NULL); 4259 4260 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd, 4261 sym_sec, val, s, error_message); 4262 if (!myh) 4263 return FALSE; 4264 4265 my_offset = myh->root.u.def.value; 4266 tmp = bfd_get_32 (input_bfd, hit_data); 4267 tmp = tmp & 0xFF000000; 4268 4269 /* Somehow these are both 4 too far, so subtract 8. */ 4270 ret_offset = (s->output_offset 4271 + my_offset 4272 + s->output_section->vma 4273 - (input_section->output_offset 4274 + input_section->output_section->vma 4275 + offset + addend) 4276 - 8); 4277 4278 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF); 4279 4280 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma); 4281 4282 return TRUE; 4283} 4284 4285/* Populate Arm stub for an exported Thumb function. */ 4286 4287static bfd_boolean 4288elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf) 4289{ 4290 struct bfd_link_info * info = (struct bfd_link_info *) inf; 4291 asection * s; 4292 struct elf_link_hash_entry * myh; 4293 struct elf32_arm_link_hash_entry *eh; 4294 struct elf32_arm_link_hash_table * globals; 4295 asection *sec; 4296 bfd_vma val; 4297 char *error_message; 4298 4299 eh = elf32_arm_hash_entry(h); 4300 /* Allocate stubs for exported Thumb functions on v4t. */ 4301 if (eh->export_glue == NULL) 4302 return TRUE; 4303 4304 globals = elf32_arm_hash_table (info); 4305 4306 BFD_ASSERT (globals != NULL); 4307 BFD_ASSERT (globals->bfd_of_glue_owner != NULL); 4308 4309 s = bfd_get_section_by_name (globals->bfd_of_glue_owner, 4310 ARM2THUMB_GLUE_SECTION_NAME); 4311 BFD_ASSERT (s != NULL); 4312 BFD_ASSERT (s->contents != NULL); 4313 BFD_ASSERT (s->output_section != NULL); 4314 4315 sec = eh->export_glue->root.u.def.section; 4316 4317 BFD_ASSERT (sec->output_section != NULL); 4318 4319 val = eh->export_glue->root.u.def.value + sec->output_offset 4320 + sec->output_section->vma; 4321 myh = elf32_arm_create_thumb_stub (info, h->root.root.string, 4322 h->root.u.def.section->owner, 4323 globals->obfd, sec, val, s, 4324 &error_message); 4325 BFD_ASSERT (myh); 4326 return TRUE; 4327} 4328 4329/* Generate Arm stubs for exported Thumb symbols. */ 4330static void 4331elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED, 4332 struct bfd_link_info *link_info) 4333{ 4334 struct elf32_arm_link_hash_table * globals; 4335 4336 if (!link_info) 4337 return; 4338 4339 globals = elf32_arm_hash_table (link_info); 4340 /* If blx is available then exported Thumb symbols are OK and there is 4341 nothing to do. */ 4342 if (globals->use_blx) 4343 return; 4344 4345 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub, 4346 link_info); 4347} 4348 4349/* Some relocations map to different relocations depending on the 4350 target. Return the real relocation. */ 4351static int 4352arm_real_reloc_type (struct elf32_arm_link_hash_table * globals, 4353 int r_type) 4354{ 4355 switch (r_type) 4356 { 4357 case R_ARM_TARGET1: 4358 if (globals->target1_is_rel) 4359 return R_ARM_REL32; 4360 else 4361 return R_ARM_ABS32; 4362 4363 case R_ARM_TARGET2: 4364 return globals->target2_reloc; 4365 4366 default: 4367 return r_type; 4368 } 4369} 4370 4371/* Return the base VMA address which should be subtracted from real addresses 4372 when resolving @dtpoff relocation. 4373 This is PT_TLS segment p_vaddr. */ 4374 4375static bfd_vma 4376dtpoff_base (struct bfd_link_info *info) 4377{ 4378 /* If tls_sec is NULL, we should have signalled an error already. */ 4379 if (elf_hash_table (info)->tls_sec == NULL) 4380 return 0; 4381 return elf_hash_table (info)->tls_sec->vma; 4382} 4383 4384/* Return the relocation value for @tpoff relocation 4385 if STT_TLS virtual address is ADDRESS. */ 4386 4387static bfd_vma 4388tpoff (struct bfd_link_info *info, bfd_vma address) 4389{ 4390 struct elf_link_hash_table *htab = elf_hash_table (info); 4391 bfd_vma base; 4392 4393 /* If tls_sec is NULL, we should have signalled an error already. */ 4394 if (htab->tls_sec == NULL) 4395 return 0; 4396 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power); 4397 return address - htab->tls_sec->vma + base; 4398} 4399 4400/* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA. 4401 VALUE is the relocation value. */ 4402 4403static bfd_reloc_status_type 4404elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value) 4405{ 4406 if (value > 0xfff) 4407 return bfd_reloc_overflow; 4408 4409 value |= bfd_get_32 (abfd, data) & 0xfffff000; 4410 bfd_put_32 (abfd, value, data); 4411 return bfd_reloc_ok; 4412} 4413 4414/* For a given value of n, calculate the value of G_n as required to 4415 deal with group relocations. We return it in the form of an 4416 encoded constant-and-rotation, together with the final residual. If n is 4417 specified as less than zero, then final_residual is filled with the 4418 input value and no further action is performed. */ 4419 4420static bfd_vma 4421calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual) 4422{ 4423 int current_n; 4424 bfd_vma g_n; 4425 bfd_vma encoded_g_n = 0; 4426 bfd_vma residual = value; /* Also known as Y_n. */ 4427 4428 for (current_n = 0; current_n <= n; current_n++) 4429 { 4430 int shift; 4431 4432 /* Calculate which part of the value to mask. */ 4433 if (residual == 0) 4434 shift = 0; 4435 else 4436 { 4437 int msb; 4438 4439 /* Determine the most significant bit in the residual and 4440 align the resulting value to a 2-bit boundary. */ 4441 for (msb = 30; msb >= 0; msb -= 2) 4442 if (residual & (3 << msb)) 4443 break; 4444 4445 /* The desired shift is now (msb - 6), or zero, whichever 4446 is the greater. */ 4447 shift = msb - 6; 4448 if (shift < 0) 4449 shift = 0; 4450 } 4451 4452 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */ 4453 g_n = residual & (0xff << shift); 4454 encoded_g_n = (g_n >> shift) 4455 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8); 4456 4457 /* Calculate the residual for the next time around. */ 4458 residual &= ~g_n; 4459 } 4460 4461 *final_residual = residual; 4462 4463 return encoded_g_n; 4464} 4465 4466/* Given an ARM instruction, determine whether it is an ADD or a SUB. 4467 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */ 4468static int 4469identify_add_or_sub(bfd_vma insn) 4470{ 4471 int opcode = insn & 0x1e00000; 4472 4473 if (opcode == 1 << 23) /* ADD */ 4474 return 1; 4475 4476 if (opcode == 1 << 22) /* SUB */ 4477 return -1; 4478 4479 return 0; 4480} 4481 4482/* Determine if we're dealing with a Thumb-2 object. */ 4483 4484static int using_thumb2 (struct elf32_arm_link_hash_table *globals) 4485{ 4486 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC, 4487 Tag_CPU_arch); 4488 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7; 4489} 4490 4491/* Perform a relocation as part of a final link. */ 4492 4493static bfd_reloc_status_type 4494elf32_arm_final_link_relocate (reloc_howto_type * howto, 4495 bfd * input_bfd, 4496 bfd * output_bfd, 4497 asection * input_section, 4498 bfd_byte * contents, 4499 Elf_Internal_Rela * rel, 4500 bfd_vma value, 4501 struct bfd_link_info * info, 4502 asection * sym_sec, 4503 const char * sym_name, 4504 int sym_flags, 4505 struct elf_link_hash_entry * h, 4506 bfd_boolean * unresolved_reloc_p, 4507 char **error_message) 4508{ 4509 unsigned long r_type = howto->type; 4510 unsigned long r_symndx; 4511 bfd_byte * hit_data = contents + rel->r_offset; 4512 bfd * dynobj = NULL; 4513 Elf_Internal_Shdr * symtab_hdr; 4514 struct elf_link_hash_entry ** sym_hashes; 4515 bfd_vma * local_got_offsets; 4516 asection * sgot = NULL; 4517 asection * splt = NULL; 4518 asection * sreloc = NULL; 4519 bfd_vma addend; 4520 bfd_signed_vma signed_addend; 4521 struct elf32_arm_link_hash_table * globals; 4522 4523 globals = elf32_arm_hash_table (info); 4524 4525 /* Some relocation type map to different relocations depending on the 4526 target. We pick the right one here. */ 4527 r_type = arm_real_reloc_type (globals, r_type); 4528 if (r_type != howto->type) 4529 howto = elf32_arm_howto_from_type (r_type); 4530 4531 /* If the start address has been set, then set the EF_ARM_HASENTRY 4532 flag. Setting this more than once is redundant, but the cost is 4533 not too high, and it keeps the code simple. 4534 4535 The test is done here, rather than somewhere else, because the 4536 start address is only set just before the final link commences. 4537 4538 Note - if the user deliberately sets a start address of 0, the 4539 flag will not be set. */ 4540 if (bfd_get_start_address (output_bfd) != 0) 4541 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY; 4542 4543 dynobj = elf_hash_table (info)->dynobj; 4544 if (dynobj) 4545 { 4546 sgot = bfd_get_section_by_name (dynobj, ".got"); 4547 splt = bfd_get_section_by_name (dynobj, ".plt"); 4548 } 4549 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; 4550 sym_hashes = elf_sym_hashes (input_bfd); 4551 local_got_offsets = elf_local_got_offsets (input_bfd); 4552 r_symndx = ELF32_R_SYM (rel->r_info); 4553 4554 if (globals->use_rel) 4555 { 4556 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask; 4557 4558 if (addend & ((howto->src_mask + 1) >> 1)) 4559 { 4560 signed_addend = -1; 4561 signed_addend &= ~ howto->src_mask; 4562 signed_addend |= addend; 4563 } 4564 else 4565 signed_addend = addend; 4566 } 4567 else 4568 addend = signed_addend = rel->r_addend; 4569 4570 switch (r_type) 4571 { 4572 case R_ARM_NONE: 4573 /* We don't need to find a value for this symbol. It's just a 4574 marker. */ 4575 *unresolved_reloc_p = FALSE; 4576 return bfd_reloc_ok; 4577 4578 case R_ARM_ABS12: 4579 if (!globals->vxworks_p) 4580 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend); 4581 4582 case R_ARM_PC24: 4583 case R_ARM_ABS32: 4584 case R_ARM_ABS32_NOI: 4585 case R_ARM_REL32: 4586 case R_ARM_REL32_NOI: 4587 case R_ARM_CALL: 4588 case R_ARM_JUMP24: 4589 case R_ARM_XPC25: 4590 case R_ARM_PREL31: 4591 case R_ARM_PLT32: 4592 /* Handle relocations which should use the PLT entry. ABS32/REL32 4593 will use the symbol's value, which may point to a PLT entry, but we 4594 don't need to handle that here. If we created a PLT entry, all 4595 branches in this object should go to it. */ 4596 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32 4597 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI) 4598 && h != NULL 4599 && splt != NULL 4600 && h->plt.offset != (bfd_vma) -1) 4601 { 4602 /* If we've created a .plt section, and assigned a PLT entry to 4603 this function, it should not be known to bind locally. If 4604 it were, we would have cleared the PLT entry. */ 4605 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h)); 4606 4607 value = (splt->output_section->vma 4608 + splt->output_offset 4609 + h->plt.offset); 4610 *unresolved_reloc_p = FALSE; 4611 return _bfd_final_link_relocate (howto, input_bfd, input_section, 4612 contents, rel->r_offset, value, 4613 rel->r_addend); 4614 } 4615 4616 /* When generating a shared object or relocatable executable, these 4617 relocations are copied into the output file to be resolved at 4618 run time. */ 4619 if ((info->shared || globals->root.is_relocatable_executable) 4620 && (input_section->flags & SEC_ALLOC) 4621 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI) 4622 || !SYMBOL_CALLS_LOCAL (info, h)) 4623 && (h == NULL 4624 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT 4625 || h->root.type != bfd_link_hash_undefweak) 4626 && r_type != R_ARM_PC24 4627 && r_type != R_ARM_CALL 4628 && r_type != R_ARM_JUMP24 4629 && r_type != R_ARM_PREL31 4630 && r_type != R_ARM_PLT32) 4631 { 4632 Elf_Internal_Rela outrel; 4633 bfd_byte *loc; 4634 bfd_boolean skip, relocate; 4635 4636 *unresolved_reloc_p = FALSE; 4637 4638 if (sreloc == NULL) 4639 { 4640 const char * name; 4641 4642 name = (bfd_elf_string_from_elf_section 4643 (input_bfd, 4644 elf_elfheader (input_bfd)->e_shstrndx, 4645 elf_section_data (input_section)->rel_hdr.sh_name)); 4646 if (name == NULL) 4647 return bfd_reloc_notsupported; 4648 4649 BFD_ASSERT (reloc_section_p (globals, name, input_section)); 4650 4651 sreloc = bfd_get_section_by_name (dynobj, name); 4652 BFD_ASSERT (sreloc != NULL); 4653 } 4654 4655 skip = FALSE; 4656 relocate = FALSE; 4657 4658 outrel.r_addend = addend; 4659 outrel.r_offset = 4660 _bfd_elf_section_offset (output_bfd, info, input_section, 4661 rel->r_offset); 4662 if (outrel.r_offset == (bfd_vma) -1) 4663 skip = TRUE; 4664 else if (outrel.r_offset == (bfd_vma) -2) 4665 skip = TRUE, relocate = TRUE; 4666 outrel.r_offset += (input_section->output_section->vma 4667 + input_section->output_offset); 4668 4669 if (skip) 4670 memset (&outrel, 0, sizeof outrel); 4671 else if (h != NULL 4672 && h->dynindx != -1 4673 && (!info->shared 4674 || !info->symbolic 4675 || !h->def_regular)) 4676 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); 4677 else 4678 { 4679 int symbol; 4680 4681 /* This symbol is local, or marked to become local. */ 4682 if (sym_flags == STT_ARM_TFUNC) 4683 value |= 1; 4684 if (globals->symbian_p) 4685 { 4686 asection *osec; 4687 4688 /* On Symbian OS, the data segment and text segement 4689 can be relocated independently. Therefore, we 4690 must indicate the segment to which this 4691 relocation is relative. The BPABI allows us to 4692 use any symbol in the right segment; we just use 4693 the section symbol as it is convenient. (We 4694 cannot use the symbol given by "h" directly as it 4695 will not appear in the dynamic symbol table.) 4696 4697 Note that the dynamic linker ignores the section 4698 symbol value, so we don't subtract osec->vma 4699 from the emitted reloc addend. */ 4700 if (sym_sec) 4701 osec = sym_sec->output_section; 4702 else 4703 osec = input_section->output_section; 4704 symbol = elf_section_data (osec)->dynindx; 4705 if (symbol == 0) 4706 { 4707 struct elf_link_hash_table *htab = elf_hash_table (info); 4708 4709 if ((osec->flags & SEC_READONLY) == 0 4710 && htab->data_index_section != NULL) 4711 osec = htab->data_index_section; 4712 else 4713 osec = htab->text_index_section; 4714 symbol = elf_section_data (osec)->dynindx; 4715 } 4716 BFD_ASSERT (symbol != 0); 4717 } 4718 else 4719 /* On SVR4-ish systems, the dynamic loader cannot 4720 relocate the text and data segments independently, 4721 so the symbol does not matter. */ 4722 symbol = 0; 4723 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE); 4724 if (globals->use_rel) 4725 relocate = TRUE; 4726 else 4727 outrel.r_addend += value; 4728 } 4729 4730 loc = sreloc->contents; 4731 loc += sreloc->reloc_count++ * RELOC_SIZE (globals); 4732 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); 4733 4734 /* If this reloc is against an external symbol, we do not want to 4735 fiddle with the addend. Otherwise, we need to include the symbol 4736 value so that it becomes an addend for the dynamic reloc. */ 4737 if (! relocate) 4738 return bfd_reloc_ok; 4739 4740 return _bfd_final_link_relocate (howto, input_bfd, input_section, 4741 contents, rel->r_offset, value, 4742 (bfd_vma) 0); 4743 } 4744 else switch (r_type) 4745 { 4746 case R_ARM_ABS12: 4747 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend); 4748 4749 case R_ARM_XPC25: /* Arm BLX instruction. */ 4750 case R_ARM_CALL: 4751 case R_ARM_JUMP24: 4752 case R_ARM_PC24: /* Arm B/BL instruction */ 4753 case R_ARM_PLT32: 4754 if (r_type == R_ARM_XPC25) 4755 { 4756 /* Check for Arm calling Arm function. */ 4757 /* FIXME: Should we translate the instruction into a BL 4758 instruction instead ? */ 4759 if (sym_flags != STT_ARM_TFUNC) 4760 (*_bfd_error_handler) 4761 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."), 4762 input_bfd, 4763 h ? h->root.root.string : "(local)"); 4764 } 4765 else if (r_type != R_ARM_CALL || !globals->use_blx) 4766 { 4767 /* Check for Arm calling Thumb function. */ 4768 if (sym_flags == STT_ARM_TFUNC) 4769 { 4770 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd, 4771 output_bfd, input_section, 4772 hit_data, sym_sec, rel->r_offset, 4773 signed_addend, value, 4774 error_message)) 4775 return bfd_reloc_ok; 4776 else 4777 return bfd_reloc_dangerous; 4778 } 4779 } 4780 4781 /* The ARM ELF ABI says that this reloc is computed as: S - P + A 4782 where: 4783 S is the address of the symbol in the relocation. 4784 P is address of the instruction being relocated. 4785 A is the addend (extracted from the instruction) in bytes. 4786 4787 S is held in 'value'. 4788 P is the base address of the section containing the 4789 instruction plus the offset of the reloc into that 4790 section, ie: 4791 (input_section->output_section->vma + 4792 input_section->output_offset + 4793 rel->r_offset). 4794 A is the addend, converted into bytes, ie: 4795 (signed_addend * 4) 4796 4797 Note: None of these operations have knowledge of the pipeline 4798 size of the processor, thus it is up to the assembler to 4799 encode this information into the addend. */ 4800 value -= (input_section->output_section->vma 4801 + input_section->output_offset); 4802 value -= rel->r_offset; 4803 if (globals->use_rel) 4804 value += (signed_addend << howto->size); 4805 else 4806 /* RELA addends do not have to be adjusted by howto->size. */ 4807 value += signed_addend; 4808 4809 signed_addend = value; 4810 signed_addend >>= howto->rightshift; 4811 4812 /* A branch to an undefined weak symbol is turned into a jump to 4813 the next instruction. */ 4814 if (h && h->root.type == bfd_link_hash_undefweak) 4815 { 4816 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000) 4817 | 0x0affffff; 4818 } 4819 else 4820 { 4821 /* Perform a signed range check. */ 4822 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1)) 4823 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1))) 4824 return bfd_reloc_overflow; 4825 4826 addend = (value & 2); 4827 4828 value = (signed_addend & howto->dst_mask) 4829 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask)); 4830 4831 /* Set the H bit in the BLX instruction. */ 4832 if (sym_flags == STT_ARM_TFUNC) 4833 { 4834 if (addend) 4835 value |= (1 << 24); 4836 else 4837 value &= ~(bfd_vma)(1 << 24); 4838 } 4839 if (r_type == R_ARM_CALL) 4840 { 4841 /* Select the correct instruction (BL or BLX). */ 4842 if (sym_flags == STT_ARM_TFUNC) 4843 value |= (1 << 28); 4844 else 4845 { 4846 value &= ~(bfd_vma)(1 << 28); 4847 value |= (1 << 24); 4848 } 4849 } 4850 } 4851 break; 4852 4853 case R_ARM_ABS32: 4854 value += addend; 4855 if (sym_flags == STT_ARM_TFUNC) 4856 value |= 1; 4857 break; 4858 4859 case R_ARM_ABS32_NOI: 4860 value += addend; 4861 break; 4862 4863 case R_ARM_REL32: 4864 value += addend; 4865 if (sym_flags == STT_ARM_TFUNC) 4866 value |= 1; 4867 value -= (input_section->output_section->vma 4868 + input_section->output_offset + rel->r_offset); 4869 break; 4870 4871 case R_ARM_REL32_NOI: 4872 value += addend; 4873 value -= (input_section->output_section->vma 4874 + input_section->output_offset + rel->r_offset); 4875 break; 4876 4877 case R_ARM_PREL31: 4878 value -= (input_section->output_section->vma 4879 + input_section->output_offset + rel->r_offset); 4880 value += signed_addend; 4881 if (! h || h->root.type != bfd_link_hash_undefweak) 4882 { 4883 /* Check for overflow */ 4884 if ((value ^ (value >> 1)) & (1 << 30)) 4885 return bfd_reloc_overflow; 4886 } 4887 value &= 0x7fffffff; 4888 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000); 4889 if (sym_flags == STT_ARM_TFUNC) 4890 value |= 1; 4891 break; 4892 } 4893 4894 bfd_put_32 (input_bfd, value, hit_data); 4895 return bfd_reloc_ok; 4896 4897 case R_ARM_ABS8: 4898 value += addend; 4899 if ((long) value > 0x7f || (long) value < -0x80) 4900 return bfd_reloc_overflow; 4901 4902 bfd_put_8 (input_bfd, value, hit_data); 4903 return bfd_reloc_ok; 4904 4905 case R_ARM_ABS16: 4906 value += addend; 4907 4908 if ((long) value > 0x7fff || (long) value < -0x8000) 4909 return bfd_reloc_overflow; 4910 4911 bfd_put_16 (input_bfd, value, hit_data); 4912 return bfd_reloc_ok; 4913 4914 case R_ARM_THM_ABS5: 4915 /* Support ldr and str instructions for the thumb. */ 4916 if (globals->use_rel) 4917 { 4918 /* Need to refetch addend. */ 4919 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; 4920 /* ??? Need to determine shift amount from operand size. */ 4921 addend >>= howto->rightshift; 4922 } 4923 value += addend; 4924 4925 /* ??? Isn't value unsigned? */ 4926 if ((long) value > 0x1f || (long) value < -0x10) 4927 return bfd_reloc_overflow; 4928 4929 /* ??? Value needs to be properly shifted into place first. */ 4930 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f; 4931 bfd_put_16 (input_bfd, value, hit_data); 4932 return bfd_reloc_ok; 4933 4934 case R_ARM_THM_ALU_PREL_11_0: 4935 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */ 4936 { 4937 bfd_vma insn; 4938 bfd_signed_vma relocation; 4939 4940 insn = (bfd_get_16 (input_bfd, hit_data) << 16) 4941 | bfd_get_16 (input_bfd, hit_data + 2); 4942 4943 if (globals->use_rel) 4944 { 4945 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4) 4946 | ((insn & (1 << 26)) >> 15); 4947 if (insn & 0xf00000) 4948 signed_addend = -signed_addend; 4949 } 4950 4951 relocation = value + signed_addend; 4952 relocation -= (input_section->output_section->vma 4953 + input_section->output_offset 4954 + rel->r_offset); 4955 4956 value = llabs (relocation); 4957 4958 if (value >= 0x1000) 4959 return bfd_reloc_overflow; 4960 4961 insn = (insn & 0xfb0f8f00) | (value & 0xff) 4962 | ((value & 0x700) << 4) 4963 | ((value & 0x800) << 15); 4964 if (relocation < 0) 4965 insn |= 0xa00000; 4966 4967 bfd_put_16 (input_bfd, insn >> 16, hit_data); 4968 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2); 4969 4970 return bfd_reloc_ok; 4971 } 4972 4973 case R_ARM_THM_PC12: 4974 /* Corresponds to: ldr.w reg, [pc, #offset]. */ 4975 { 4976 bfd_vma insn; 4977 bfd_signed_vma relocation; 4978 4979 insn = (bfd_get_16 (input_bfd, hit_data) << 16) 4980 | bfd_get_16 (input_bfd, hit_data + 2); 4981 4982 if (globals->use_rel) 4983 { 4984 signed_addend = insn & 0xfff; 4985 if (!(insn & (1 << 23))) 4986 signed_addend = -signed_addend; 4987 } 4988 4989 relocation = value + signed_addend; 4990 relocation -= (input_section->output_section->vma 4991 + input_section->output_offset 4992 + rel->r_offset); 4993 4994 value = llabs (relocation); 4995 4996 if (value >= 0x1000) 4997 return bfd_reloc_overflow; 4998 4999 insn = (insn & 0xff7ff000) | value; 5000 if (relocation >= 0) 5001 insn |= (1 << 23); 5002 5003 bfd_put_16 (input_bfd, insn >> 16, hit_data); 5004 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2); 5005 5006 return bfd_reloc_ok; 5007 } 5008 5009 case R_ARM_THM_XPC22: 5010 case R_ARM_THM_CALL: 5011 /* Thumb BL (branch long instruction). */ 5012 { 5013 bfd_vma relocation; 5014 bfd_vma reloc_sign; 5015 bfd_boolean overflow = FALSE; 5016 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); 5017 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); 5018 bfd_signed_vma reloc_signed_max; 5019 bfd_signed_vma reloc_signed_min; 5020 bfd_vma check; 5021 bfd_signed_vma signed_check; 5022 int bitsize; 5023 int thumb2 = using_thumb2 (globals); 5024 5025 /* A branch to an undefined weak symbol is turned into a jump to 5026 the next instruction. */ 5027 if (h && h->root.type == bfd_link_hash_undefweak) 5028 { 5029 bfd_put_16 (input_bfd, 0xe000, hit_data); 5030 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2); 5031 return bfd_reloc_ok; 5032 } 5033 5034 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible 5035 with Thumb-1) involving the J1 and J2 bits. */ 5036 if (globals->use_rel) 5037 { 5038 bfd_vma s = (upper_insn & (1 << 10)) >> 10; 5039 bfd_vma upper = upper_insn & 0x3ff; 5040 bfd_vma lower = lower_insn & 0x7ff; 5041 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13; 5042 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11; 5043 bfd_vma i1 = j1 ^ s ? 0 : 1; 5044 bfd_vma i2 = j2 ^ s ? 0 : 1; 5045 5046 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1); 5047 /* Sign extend. */ 5048 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24); 5049 5050 signed_addend = addend; 5051 } 5052 5053 if (r_type == R_ARM_THM_XPC22) 5054 { 5055 /* Check for Thumb to Thumb call. */ 5056 /* FIXME: Should we translate the instruction into a BL 5057 instruction instead ? */ 5058 if (sym_flags == STT_ARM_TFUNC) 5059 (*_bfd_error_handler) 5060 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."), 5061 input_bfd, 5062 h ? h->root.root.string : "(local)"); 5063 } 5064 else 5065 { 5066 /* If it is not a call to Thumb, assume call to Arm. 5067 If it is a call relative to a section name, then it is not a 5068 function call at all, but rather a long jump. Calls through 5069 the PLT do not require stubs. */ 5070 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION 5071 && (h == NULL || splt == NULL 5072 || h->plt.offset == (bfd_vma) -1)) 5073 { 5074 if (globals->use_blx) 5075 { 5076 /* Convert BL to BLX. */ 5077 lower_insn = (lower_insn & ~0x1000) | 0x0800; 5078 } 5079 else if (elf32_thumb_to_arm_stub 5080 (info, sym_name, input_bfd, output_bfd, input_section, 5081 hit_data, sym_sec, rel->r_offset, signed_addend, value, 5082 error_message)) 5083 return bfd_reloc_ok; 5084 else 5085 return bfd_reloc_dangerous; 5086 } 5087 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx) 5088 { 5089 /* Make sure this is a BL. */ 5090 lower_insn |= 0x1800; 5091 } 5092 } 5093 5094 /* Handle calls via the PLT. */ 5095 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1) 5096 { 5097 value = (splt->output_section->vma 5098 + splt->output_offset 5099 + h->plt.offset); 5100 if (globals->use_blx) 5101 { 5102 /* If the Thumb BLX instruction is available, convert the 5103 BL to a BLX instruction to call the ARM-mode PLT entry. */ 5104 lower_insn = (lower_insn & ~0x1000) | 0x0800; 5105 } 5106 else 5107 /* Target the Thumb stub before the ARM PLT entry. */ 5108 value -= PLT_THUMB_STUB_SIZE; 5109 *unresolved_reloc_p = FALSE; 5110 } 5111 5112 relocation = value + signed_addend; 5113 5114 relocation -= (input_section->output_section->vma 5115 + input_section->output_offset 5116 + rel->r_offset); 5117 5118 check = relocation >> howto->rightshift; 5119 5120 /* If this is a signed value, the rightshift just dropped 5121 leading 1 bits (assuming twos complement). */ 5122 if ((bfd_signed_vma) relocation >= 0) 5123 signed_check = check; 5124 else 5125 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); 5126 5127 /* Calculate the permissable maximum and minimum values for 5128 this relocation according to whether we're relocating for 5129 Thumb-2 or not. */ 5130 bitsize = howto->bitsize; 5131 if (!thumb2) 5132 bitsize -= 2; 5133 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift; 5134 reloc_signed_min = ~reloc_signed_max; 5135 5136 /* Assumes two's complement. */ 5137 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) 5138 overflow = TRUE; 5139 5140 if ((lower_insn & 0x1800) == 0x0800) 5141 /* For a BLX instruction, make sure that the relocation is rounded up 5142 to a word boundary. This follows the semantics of the instruction 5143 which specifies that bit 1 of the target address will come from bit 5144 1 of the base address. */ 5145 relocation = (relocation + 2) & ~ 3; 5146 5147 /* Put RELOCATION back into the insn. Assumes two's complement. 5148 We use the Thumb-2 encoding, which is safe even if dealing with 5149 a Thumb-1 instruction by virtue of our overflow check above. */ 5150 reloc_sign = (signed_check < 0) ? 1 : 0; 5151 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) 5152 | ((relocation >> 12) & 0x3ff) 5153 | (reloc_sign << 10); 5154 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff) 5155 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13) 5156 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11) 5157 | ((relocation >> 1) & 0x7ff); 5158 5159 /* Put the relocated value back in the object file: */ 5160 bfd_put_16 (input_bfd, upper_insn, hit_data); 5161 bfd_put_16 (input_bfd, lower_insn, hit_data + 2); 5162 5163 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); 5164 } 5165 break; 5166 5167 case R_ARM_THM_JUMP24: 5168 /* Thumb32 unconditional branch instruction. */ 5169 { 5170 bfd_vma relocation; 5171 bfd_boolean overflow = FALSE; 5172 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); 5173 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); 5174 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; 5175 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; 5176 bfd_vma check; 5177 bfd_signed_vma signed_check; 5178 5179 /* Need to refetch the addend, reconstruct the top three bits, and glue the 5180 two pieces together. */ 5181 if (globals->use_rel) 5182 { 5183 bfd_vma S = (upper_insn & 0x0400) >> 10; 5184 bfd_vma hi = (upper_insn & 0x03ff); 5185 bfd_vma I1 = (lower_insn & 0x2000) >> 13; 5186 bfd_vma I2 = (lower_insn & 0x0800) >> 11; 5187 bfd_vma lo = (lower_insn & 0x07ff); 5188 5189 I1 = !(I1 ^ S); 5190 I2 = !(I2 ^ S); 5191 S = !S; 5192 5193 signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1); 5194 signed_addend -= (1 << 24); /* Sign extend. */ 5195 } 5196 5197 /* ??? Should handle interworking? GCC might someday try to 5198 use this for tail calls. */ 5199 5200 relocation = value + signed_addend; 5201 relocation -= (input_section->output_section->vma 5202 + input_section->output_offset 5203 + rel->r_offset); 5204 5205 check = relocation >> howto->rightshift; 5206 5207 /* If this is a signed value, the rightshift just dropped 5208 leading 1 bits (assuming twos complement). */ 5209 if ((bfd_signed_vma) relocation >= 0) 5210 signed_check = check; 5211 else 5212 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); 5213 5214 /* Assumes two's complement. */ 5215 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) 5216 overflow = TRUE; 5217 5218 /* Put RELOCATION back into the insn. */ 5219 { 5220 bfd_vma S = (relocation & 0x01000000) >> 24; 5221 bfd_vma I1 = (relocation & 0x00800000) >> 23; 5222 bfd_vma I2 = (relocation & 0x00400000) >> 22; 5223 bfd_vma hi = (relocation & 0x003ff000) >> 12; 5224 bfd_vma lo = (relocation & 0x00000ffe) >> 1; 5225 5226 I1 = !(I1 ^ S); 5227 I2 = !(I2 ^ S); 5228 5229 upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi; 5230 lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo; 5231 } 5232 5233 /* Put the relocated value back in the object file: */ 5234 bfd_put_16 (input_bfd, upper_insn, hit_data); 5235 bfd_put_16 (input_bfd, lower_insn, hit_data + 2); 5236 5237 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); 5238 } 5239 5240 case R_ARM_THM_JUMP19: 5241 /* Thumb32 conditional branch instruction. */ 5242 { 5243 bfd_vma relocation; 5244 bfd_boolean overflow = FALSE; 5245 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); 5246 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); 5247 bfd_signed_vma reloc_signed_max = 0xffffe; 5248 bfd_signed_vma reloc_signed_min = -0x100000; 5249 bfd_signed_vma signed_check; 5250 5251 /* Need to refetch the addend, reconstruct the top three bits, 5252 and squish the two 11 bit pieces together. */ 5253 if (globals->use_rel) 5254 { 5255 bfd_vma S = (upper_insn & 0x0400) >> 10; 5256 bfd_vma upper = (upper_insn & 0x003f); 5257 bfd_vma J1 = (lower_insn & 0x2000) >> 13; 5258 bfd_vma J2 = (lower_insn & 0x0800) >> 11; 5259 bfd_vma lower = (lower_insn & 0x07ff); 5260 5261 upper |= J1 << 6; 5262 upper |= J2 << 7; 5263 upper |= (!S) << 8; 5264 upper -= 0x0100; /* Sign extend. */ 5265 5266 addend = (upper << 12) | (lower << 1); 5267 signed_addend = addend; 5268 } 5269 5270 /* ??? Should handle interworking? GCC might someday try to 5271 use this for tail calls. */ 5272 5273 relocation = value + signed_addend; 5274 relocation -= (input_section->output_section->vma 5275 + input_section->output_offset 5276 + rel->r_offset); 5277 signed_check = (bfd_signed_vma) relocation; 5278 5279 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) 5280 overflow = TRUE; 5281 5282 /* Put RELOCATION back into the insn. */ 5283 { 5284 bfd_vma S = (relocation & 0x00100000) >> 20; 5285 bfd_vma J2 = (relocation & 0x00080000) >> 19; 5286 bfd_vma J1 = (relocation & 0x00040000) >> 18; 5287 bfd_vma hi = (relocation & 0x0003f000) >> 12; 5288 bfd_vma lo = (relocation & 0x00000ffe) >> 1; 5289 5290 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi; 5291 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo; 5292 } 5293 5294 /* Put the relocated value back in the object file: */ 5295 bfd_put_16 (input_bfd, upper_insn, hit_data); 5296 bfd_put_16 (input_bfd, lower_insn, hit_data + 2); 5297 5298 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); 5299 } 5300 5301 case R_ARM_THM_JUMP11: 5302 case R_ARM_THM_JUMP8: 5303 case R_ARM_THM_JUMP6: 5304 /* Thumb B (branch) instruction). */ 5305 { 5306 bfd_signed_vma relocation; 5307 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1; 5308 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; 5309 bfd_signed_vma signed_check; 5310 5311 /* CZB cannot jump backward. */ 5312 if (r_type == R_ARM_THM_JUMP6) 5313 reloc_signed_min = 0; 5314 5315 if (globals->use_rel) 5316 { 5317 /* Need to refetch addend. */ 5318 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; 5319 if (addend & ((howto->src_mask + 1) >> 1)) 5320 { 5321 signed_addend = -1; 5322 signed_addend &= ~ howto->src_mask; 5323 signed_addend |= addend; 5324 } 5325 else 5326 signed_addend = addend; 5327 /* The value in the insn has been right shifted. We need to 5328 undo this, so that we can perform the address calculation 5329 in terms of bytes. */ 5330 signed_addend <<= howto->rightshift; 5331 } 5332 relocation = value + signed_addend; 5333 5334 relocation -= (input_section->output_section->vma 5335 + input_section->output_offset 5336 + rel->r_offset); 5337 5338 relocation >>= howto->rightshift; 5339 signed_check = relocation; 5340 5341 if (r_type == R_ARM_THM_JUMP6) 5342 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3); 5343 else 5344 relocation &= howto->dst_mask; 5345 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask)); 5346 5347 bfd_put_16 (input_bfd, relocation, hit_data); 5348 5349 /* Assumes two's complement. */ 5350 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) 5351 return bfd_reloc_overflow; 5352 5353 return bfd_reloc_ok; 5354 } 5355 5356 case R_ARM_ALU_PCREL7_0: 5357 case R_ARM_ALU_PCREL15_8: 5358 case R_ARM_ALU_PCREL23_15: 5359 { 5360 bfd_vma insn; 5361 bfd_vma relocation; 5362 5363 insn = bfd_get_32 (input_bfd, hit_data); 5364 if (globals->use_rel) 5365 { 5366 /* Extract the addend. */ 5367 addend = (insn & 0xff) << ((insn & 0xf00) >> 7); 5368 signed_addend = addend; 5369 } 5370 relocation = value + signed_addend; 5371 5372 relocation -= (input_section->output_section->vma 5373 + input_section->output_offset 5374 + rel->r_offset); 5375 insn = (insn & ~0xfff) 5376 | ((howto->bitpos << 7) & 0xf00) 5377 | ((relocation >> howto->bitpos) & 0xff); 5378 bfd_put_32 (input_bfd, value, hit_data); 5379 } 5380 return bfd_reloc_ok; 5381 5382 case R_ARM_GNU_VTINHERIT: 5383 case R_ARM_GNU_VTENTRY: 5384 return bfd_reloc_ok; 5385 5386 case R_ARM_GOTOFF32: 5387 /* Relocation is relative to the start of the 5388 global offset table. */ 5389 5390 BFD_ASSERT (sgot != NULL); 5391 if (sgot == NULL) 5392 return bfd_reloc_notsupported; 5393 5394 /* If we are addressing a Thumb function, we need to adjust the 5395 address by one, so that attempts to call the function pointer will 5396 correctly interpret it as Thumb code. */ 5397 if (sym_flags == STT_ARM_TFUNC) 5398 value += 1; 5399 5400 /* Note that sgot->output_offset is not involved in this 5401 calculation. We always want the start of .got. If we 5402 define _GLOBAL_OFFSET_TABLE in a different way, as is 5403 permitted by the ABI, we might have to change this 5404 calculation. */ 5405 value -= sgot->output_section->vma; 5406 return _bfd_final_link_relocate (howto, input_bfd, input_section, 5407 contents, rel->r_offset, value, 5408 rel->r_addend); 5409 5410 case R_ARM_GOTPC: 5411 /* Use global offset table as symbol value. */ 5412 BFD_ASSERT (sgot != NULL); 5413 5414 if (sgot == NULL) 5415 return bfd_reloc_notsupported; 5416 5417 *unresolved_reloc_p = FALSE; 5418 value = sgot->output_section->vma; 5419 return _bfd_final_link_relocate (howto, input_bfd, input_section, 5420 contents, rel->r_offset, value, 5421 rel->r_addend); 5422 5423 case R_ARM_GOT32: 5424 case R_ARM_GOT_PREL: 5425 /* Relocation is to the entry for this symbol in the 5426 global offset table. */ 5427 if (sgot == NULL) 5428 return bfd_reloc_notsupported; 5429 5430 if (h != NULL) 5431 { 5432 bfd_vma off; 5433 bfd_boolean dyn; 5434 5435 off = h->got.offset; 5436 BFD_ASSERT (off != (bfd_vma) -1); 5437 dyn = globals->root.dynamic_sections_created; 5438 5439 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) 5440 || (info->shared 5441 && SYMBOL_REFERENCES_LOCAL (info, h)) 5442 || (ELF_ST_VISIBILITY (h->other) 5443 && h->root.type == bfd_link_hash_undefweak)) 5444 { 5445 /* This is actually a static link, or it is a -Bsymbolic link 5446 and the symbol is defined locally. We must initialize this 5447 entry in the global offset table. Since the offset must 5448 always be a multiple of 4, we use the least significant bit 5449 to record whether we have initialized it already. 5450 5451 When doing a dynamic link, we create a .rel(a).got relocation 5452 entry to initialize the value. This is done in the 5453 finish_dynamic_symbol routine. */ 5454 if ((off & 1) != 0) 5455 off &= ~1; 5456 else 5457 { 5458 /* If we are addressing a Thumb function, we need to 5459 adjust the address by one, so that attempts to 5460 call the function pointer will correctly 5461 interpret it as Thumb code. */ 5462 if (sym_flags == STT_ARM_TFUNC) 5463 value |= 1; 5464 5465 bfd_put_32 (output_bfd, value, sgot->contents + off); 5466 h->got.offset |= 1; 5467 } 5468 } 5469 else 5470 *unresolved_reloc_p = FALSE; 5471 5472 value = sgot->output_offset + off; 5473 } 5474 else 5475 { 5476 bfd_vma off; 5477 5478 BFD_ASSERT (local_got_offsets != NULL && 5479 local_got_offsets[r_symndx] != (bfd_vma) -1); 5480 5481 off = local_got_offsets[r_symndx]; 5482 5483 /* The offset must always be a multiple of 4. We use the 5484 least significant bit to record whether we have already 5485 generated the necessary reloc. */ 5486 if ((off & 1) != 0) 5487 off &= ~1; 5488 else 5489 { 5490 /* If we are addressing a Thumb function, we need to 5491 adjust the address by one, so that attempts to 5492 call the function pointer will correctly 5493 interpret it as Thumb code. */ 5494 if (sym_flags == STT_ARM_TFUNC) 5495 value |= 1; 5496 5497 if (globals->use_rel) 5498 bfd_put_32 (output_bfd, value, sgot->contents + off); 5499 5500 if (info->shared) 5501 { 5502 asection * srelgot; 5503 Elf_Internal_Rela outrel; 5504 bfd_byte *loc; 5505 5506 srelgot = (bfd_get_section_by_name 5507 (dynobj, RELOC_SECTION (globals, ".got"))); 5508 BFD_ASSERT (srelgot != NULL); 5509 5510 outrel.r_addend = addend + value; 5511 outrel.r_offset = (sgot->output_section->vma 5512 + sgot->output_offset 5513 + off); 5514 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); 5515 loc = srelgot->contents; 5516 loc += srelgot->reloc_count++ * RELOC_SIZE (globals); 5517 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); 5518 } 5519 5520 local_got_offsets[r_symndx] |= 1; 5521 } 5522 5523 value = sgot->output_offset + off; 5524 } 5525 if (r_type != R_ARM_GOT32) 5526 value += sgot->output_section->vma; 5527 5528 return _bfd_final_link_relocate (howto, input_bfd, input_section, 5529 contents, rel->r_offset, value, 5530 rel->r_addend); 5531 5532 case R_ARM_TLS_LDO32: 5533 value = value - dtpoff_base (info); 5534 5535 return _bfd_final_link_relocate (howto, input_bfd, input_section, 5536 contents, rel->r_offset, value, 5537 rel->r_addend); 5538 5539 case R_ARM_TLS_LDM32: 5540 { 5541 bfd_vma off; 5542 5543 if (globals->sgot == NULL) 5544 abort (); 5545 5546 off = globals->tls_ldm_got.offset; 5547 5548 if ((off & 1) != 0) 5549 off &= ~1; 5550 else 5551 { 5552 /* If we don't know the module number, create a relocation 5553 for it. */ 5554 if (info->shared) 5555 { 5556 Elf_Internal_Rela outrel; 5557 bfd_byte *loc; 5558 5559 if (globals->srelgot == NULL) 5560 abort (); 5561 5562 outrel.r_addend = 0; 5563 outrel.r_offset = (globals->sgot->output_section->vma 5564 + globals->sgot->output_offset + off); 5565 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32); 5566 5567 if (globals->use_rel) 5568 bfd_put_32 (output_bfd, outrel.r_addend, 5569 globals->sgot->contents + off); 5570 5571 loc = globals->srelgot->contents; 5572 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals); 5573 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); 5574 } 5575 else 5576 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off); 5577 5578 globals->tls_ldm_got.offset |= 1; 5579 } 5580 5581 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off 5582 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); 5583 5584 return _bfd_final_link_relocate (howto, input_bfd, input_section, 5585 contents, rel->r_offset, value, 5586 rel->r_addend); 5587 } 5588 5589 case R_ARM_TLS_GD32: 5590 case R_ARM_TLS_IE32: 5591 { 5592 bfd_vma off; 5593 int indx; 5594 char tls_type; 5595 5596 if (globals->sgot == NULL) 5597 abort (); 5598 5599 indx = 0; 5600 if (h != NULL) 5601 { 5602 bfd_boolean dyn; 5603 dyn = globals->root.dynamic_sections_created; 5604 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) 5605 && (!info->shared 5606 || !SYMBOL_REFERENCES_LOCAL (info, h))) 5607 { 5608 *unresolved_reloc_p = FALSE; 5609 indx = h->dynindx; 5610 } 5611 off = h->got.offset; 5612 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type; 5613 } 5614 else 5615 { 5616 if (local_got_offsets == NULL) 5617 abort (); 5618 off = local_got_offsets[r_symndx]; 5619 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx]; 5620 } 5621 5622 if (tls_type == GOT_UNKNOWN) 5623 abort (); 5624 5625 if ((off & 1) != 0) 5626 off &= ~1; 5627 else 5628 { 5629 bfd_boolean need_relocs = FALSE; 5630 Elf_Internal_Rela outrel; 5631 bfd_byte *loc = NULL; 5632 int cur_off = off; 5633 5634 /* The GOT entries have not been initialized yet. Do it 5635 now, and emit any relocations. If both an IE GOT and a 5636 GD GOT are necessary, we emit the GD first. */ 5637 5638 if ((info->shared || indx != 0) 5639 && (h == NULL 5640 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT 5641 || h->root.type != bfd_link_hash_undefweak)) 5642 { 5643 need_relocs = TRUE; 5644 if (globals->srelgot == NULL) 5645 abort (); 5646 loc = globals->srelgot->contents; 5647 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals); 5648 } 5649 5650 if (tls_type & GOT_TLS_GD) 5651 { 5652 if (need_relocs) 5653 { 5654 outrel.r_addend = 0; 5655 outrel.r_offset = (globals->sgot->output_section->vma 5656 + globals->sgot->output_offset 5657 + cur_off); 5658 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32); 5659 5660 if (globals->use_rel) 5661 bfd_put_32 (output_bfd, outrel.r_addend, 5662 globals->sgot->contents + cur_off); 5663 5664 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); 5665 globals->srelgot->reloc_count++; 5666 loc += RELOC_SIZE (globals); 5667 5668 if (indx == 0) 5669 bfd_put_32 (output_bfd, value - dtpoff_base (info), 5670 globals->sgot->contents + cur_off + 4); 5671 else 5672 { 5673 outrel.r_addend = 0; 5674 outrel.r_info = ELF32_R_INFO (indx, 5675 R_ARM_TLS_DTPOFF32); 5676 outrel.r_offset += 4; 5677 5678 if (globals->use_rel) 5679 bfd_put_32 (output_bfd, outrel.r_addend, 5680 globals->sgot->contents + cur_off + 4); 5681 5682 5683 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); 5684 globals->srelgot->reloc_count++; 5685 loc += RELOC_SIZE (globals); 5686 } 5687 } 5688 else 5689 { 5690 /* If we are not emitting relocations for a 5691 general dynamic reference, then we must be in a 5692 static link or an executable link with the 5693 symbol binding locally. Mark it as belonging 5694 to module 1, the executable. */ 5695 bfd_put_32 (output_bfd, 1, 5696 globals->sgot->contents + cur_off); 5697 bfd_put_32 (output_bfd, value - dtpoff_base (info), 5698 globals->sgot->contents + cur_off + 4); 5699 } 5700 5701 cur_off += 8; 5702 } 5703 5704 if (tls_type & GOT_TLS_IE) 5705 { 5706 if (need_relocs) 5707 { 5708 if (indx == 0) 5709 outrel.r_addend = value - dtpoff_base (info); 5710 else 5711 outrel.r_addend = 0; 5712 outrel.r_offset = (globals->sgot->output_section->vma 5713 + globals->sgot->output_offset 5714 + cur_off); 5715 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32); 5716 5717 if (globals->use_rel) 5718 bfd_put_32 (output_bfd, outrel.r_addend, 5719 globals->sgot->contents + cur_off); 5720 5721 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc); 5722 globals->srelgot->reloc_count++; 5723 loc += RELOC_SIZE (globals); 5724 } 5725 else 5726 bfd_put_32 (output_bfd, tpoff (info, value), 5727 globals->sgot->contents + cur_off); 5728 cur_off += 4; 5729 } 5730 5731 if (h != NULL) 5732 h->got.offset |= 1; 5733 else 5734 local_got_offsets[r_symndx] |= 1; 5735 } 5736 5737 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32) 5738 off += 8; 5739 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off 5740 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); 5741 5742 return _bfd_final_link_relocate (howto, input_bfd, input_section, 5743 contents, rel->r_offset, value, 5744 rel->r_addend); 5745 } 5746 5747 case R_ARM_TLS_LE32: 5748 if (info->shared) 5749 { 5750 (*_bfd_error_handler) 5751 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"), 5752 input_bfd, input_section, 5753 (long) rel->r_offset, howto->name); 5754 return FALSE; 5755 } 5756 else 5757 value = tpoff (info, value); 5758 5759 return _bfd_final_link_relocate (howto, input_bfd, input_section, 5760 contents, rel->r_offset, value, 5761 rel->r_addend); 5762 5763 case R_ARM_V4BX: 5764 if (globals->fix_v4bx) 5765 { 5766 bfd_vma insn = bfd_get_32 (input_bfd, hit_data); 5767 5768 /* Ensure that we have a BX instruction. */ 5769 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10); 5770 5771 /* Preserve Rm (lowest four bits) and the condition code 5772 (highest four bits). Other bits encode MOV PC,Rm. */ 5773 insn = (insn & 0xf000000f) | 0x01a0f000; 5774 5775 bfd_put_32 (input_bfd, insn, hit_data); 5776 } 5777 return bfd_reloc_ok; 5778 5779 case R_ARM_MOVW_ABS_NC: 5780 case R_ARM_MOVT_ABS: 5781 case R_ARM_MOVW_PREL_NC: 5782 case R_ARM_MOVT_PREL: 5783 /* Until we properly support segment-base-relative addressing then 5784 we assume the segment base to be zero, as for the group relocations. 5785 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC 5786 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */ 5787 case R_ARM_MOVW_BREL_NC: 5788 case R_ARM_MOVW_BREL: 5789 case R_ARM_MOVT_BREL: 5790 { 5791 bfd_vma insn = bfd_get_32 (input_bfd, hit_data); 5792 5793 if (globals->use_rel) 5794 { 5795 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff); 5796 signed_addend = (addend ^ 0x8000) - 0x8000; 5797 } 5798 5799 value += signed_addend; 5800 5801 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL) 5802 value -= (input_section->output_section->vma 5803 + input_section->output_offset + rel->r_offset); 5804 5805 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000) 5806 return bfd_reloc_overflow; 5807 5808 if (sym_flags == STT_ARM_TFUNC) 5809 value |= 1; 5810 5811 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL 5812 || r_type == R_ARM_MOVT_BREL) 5813 value >>= 16; 5814 5815 insn &= 0xfff0f000; 5816 insn |= value & 0xfff; 5817 insn |= (value & 0xf000) << 4; 5818 bfd_put_32 (input_bfd, insn, hit_data); 5819 } 5820 return bfd_reloc_ok; 5821 5822 case R_ARM_THM_MOVW_ABS_NC: 5823 case R_ARM_THM_MOVT_ABS: 5824 case R_ARM_THM_MOVW_PREL_NC: 5825 case R_ARM_THM_MOVT_PREL: 5826 /* Until we properly support segment-base-relative addressing then 5827 we assume the segment base to be zero, as for the above relocations. 5828 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as 5829 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics 5830 as R_ARM_THM_MOVT_ABS. */ 5831 case R_ARM_THM_MOVW_BREL_NC: 5832 case R_ARM_THM_MOVW_BREL: 5833 case R_ARM_THM_MOVT_BREL: 5834 { 5835 bfd_vma insn; 5836 5837 insn = bfd_get_16 (input_bfd, hit_data) << 16; 5838 insn |= bfd_get_16 (input_bfd, hit_data + 2); 5839 5840 if (globals->use_rel) 5841 { 5842 addend = ((insn >> 4) & 0xf000) 5843 | ((insn >> 15) & 0x0800) 5844 | ((insn >> 4) & 0x0700) 5845 | (insn & 0x00ff); 5846 signed_addend = (addend ^ 0x10000) - 0x10000; 5847 } 5848 5849 value += signed_addend; 5850 5851 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL) 5852 value -= (input_section->output_section->vma 5853 + input_section->output_offset + rel->r_offset); 5854 5855 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000) 5856 return bfd_reloc_overflow; 5857 5858 if (sym_flags == STT_ARM_TFUNC) 5859 value |= 1; 5860 5861 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL 5862 || r_type == R_ARM_THM_MOVT_BREL) 5863 value >>= 16; 5864 5865 insn &= 0xfbf08f00; 5866 insn |= (value & 0xf000) << 4; 5867 insn |= (value & 0x0800) << 15; 5868 insn |= (value & 0x0700) << 4; 5869 insn |= (value & 0x00ff); 5870 5871 bfd_put_16 (input_bfd, insn >> 16, hit_data); 5872 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2); 5873 } 5874 return bfd_reloc_ok; 5875 5876 case R_ARM_ALU_PC_G0_NC: 5877 case R_ARM_ALU_PC_G1_NC: 5878 case R_ARM_ALU_PC_G0: 5879 case R_ARM_ALU_PC_G1: 5880 case R_ARM_ALU_PC_G2: 5881 case R_ARM_ALU_SB_G0_NC: 5882 case R_ARM_ALU_SB_G1_NC: 5883 case R_ARM_ALU_SB_G0: 5884 case R_ARM_ALU_SB_G1: 5885 case R_ARM_ALU_SB_G2: 5886 { 5887 bfd_vma insn = bfd_get_32 (input_bfd, hit_data); 5888 bfd_vma pc = input_section->output_section->vma 5889 + input_section->output_offset + rel->r_offset; 5890 /* sb should be the origin of the *segment* containing the symbol. 5891 It is not clear how to obtain this OS-dependent value, so we 5892 make an arbitrary choice of zero. */ 5893 bfd_vma sb = 0; 5894 bfd_vma residual; 5895 bfd_vma g_n; 5896 bfd_signed_vma signed_value; 5897 int group = 0; 5898 5899 /* Determine which group of bits to select. */ 5900 switch (r_type) 5901 { 5902 case R_ARM_ALU_PC_G0_NC: 5903 case R_ARM_ALU_PC_G0: 5904 case R_ARM_ALU_SB_G0_NC: 5905 case R_ARM_ALU_SB_G0: 5906 group = 0; 5907 break; 5908 5909 case R_ARM_ALU_PC_G1_NC: 5910 case R_ARM_ALU_PC_G1: 5911 case R_ARM_ALU_SB_G1_NC: 5912 case R_ARM_ALU_SB_G1: 5913 group = 1; 5914 break; 5915 5916 case R_ARM_ALU_PC_G2: 5917 case R_ARM_ALU_SB_G2: 5918 group = 2; 5919 break; 5920 5921 default: 5922 abort(); 5923 } 5924 5925 /* If REL, extract the addend from the insn. If RELA, it will 5926 have already been fetched for us. */ 5927 if (globals->use_rel) 5928 { 5929 int negative; 5930 bfd_vma constant = insn & 0xff; 5931 bfd_vma rotation = (insn & 0xf00) >> 8; 5932 5933 if (rotation == 0) 5934 signed_addend = constant; 5935 else 5936 { 5937 /* Compensate for the fact that in the instruction, the 5938 rotation is stored in multiples of 2 bits. */ 5939 rotation *= 2; 5940 5941 /* Rotate "constant" right by "rotation" bits. */ 5942 signed_addend = (constant >> rotation) | 5943 (constant << (8 * sizeof (bfd_vma) - rotation)); 5944 } 5945 5946 /* Determine if the instruction is an ADD or a SUB. 5947 (For REL, this determines the sign of the addend.) */ 5948 negative = identify_add_or_sub (insn); 5949 if (negative == 0) 5950 { 5951 (*_bfd_error_handler) 5952 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"), 5953 input_bfd, input_section, 5954 (long) rel->r_offset, howto->name); 5955 return bfd_reloc_overflow; 5956 } 5957 5958 signed_addend *= negative; 5959 } 5960 5961 /* Compute the value (X) to go in the place. */ 5962 if (r_type == R_ARM_ALU_PC_G0_NC 5963 || r_type == R_ARM_ALU_PC_G1_NC 5964 || r_type == R_ARM_ALU_PC_G0 5965 || r_type == R_ARM_ALU_PC_G1 5966 || r_type == R_ARM_ALU_PC_G2) 5967 /* PC relative. */ 5968 signed_value = value - pc + signed_addend; 5969 else 5970 /* Section base relative. */ 5971 signed_value = value - sb + signed_addend; 5972 5973 /* If the target symbol is a Thumb function, then set the 5974 Thumb bit in the address. */ 5975 if (sym_flags == STT_ARM_TFUNC) 5976 signed_value |= 1; 5977 5978 /* Calculate the value of the relevant G_n, in encoded 5979 constant-with-rotation format. */ 5980 g_n = calculate_group_reloc_mask (llabs (signed_value), group, 5981 &residual); 5982 5983 /* Check for overflow if required. */ 5984 if ((r_type == R_ARM_ALU_PC_G0 5985 || r_type == R_ARM_ALU_PC_G1 5986 || r_type == R_ARM_ALU_PC_G2 5987 || r_type == R_ARM_ALU_SB_G0 5988 || r_type == R_ARM_ALU_SB_G1 5989 || r_type == R_ARM_ALU_SB_G2) && residual != 0) 5990 { 5991 (*_bfd_error_handler) 5992 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), 5993 input_bfd, input_section, 5994 (long) rel->r_offset, llabs (signed_value), howto->name); 5995 return bfd_reloc_overflow; 5996 } 5997 5998 /* Mask out the value and the ADD/SUB part of the opcode; take care 5999 not to destroy the S bit. */ 6000 insn &= 0xff1ff000; 6001 6002 /* Set the opcode according to whether the value to go in the 6003 place is negative. */ 6004 if (signed_value < 0) 6005 insn |= 1 << 22; 6006 else 6007 insn |= 1 << 23; 6008 6009 /* Encode the offset. */ 6010 insn |= g_n; 6011 6012 bfd_put_32 (input_bfd, insn, hit_data); 6013 } 6014 return bfd_reloc_ok; 6015 6016 case R_ARM_LDR_PC_G0: 6017 case R_ARM_LDR_PC_G1: 6018 case R_ARM_LDR_PC_G2: 6019 case R_ARM_LDR_SB_G0: 6020 case R_ARM_LDR_SB_G1: 6021 case R_ARM_LDR_SB_G2: 6022 { 6023 bfd_vma insn = bfd_get_32 (input_bfd, hit_data); 6024 bfd_vma pc = input_section->output_section->vma 6025 + input_section->output_offset + rel->r_offset; 6026 bfd_vma sb = 0; /* See note above. */ 6027 bfd_vma residual; 6028 bfd_signed_vma signed_value; 6029 int group = 0; 6030 6031 /* Determine which groups of bits to calculate. */ 6032 switch (r_type) 6033 { 6034 case R_ARM_LDR_PC_G0: 6035 case R_ARM_LDR_SB_G0: 6036 group = 0; 6037 break; 6038 6039 case R_ARM_LDR_PC_G1: 6040 case R_ARM_LDR_SB_G1: 6041 group = 1; 6042 break; 6043 6044 case R_ARM_LDR_PC_G2: 6045 case R_ARM_LDR_SB_G2: 6046 group = 2; 6047 break; 6048 6049 default: 6050 abort(); 6051 } 6052 6053 /* If REL, extract the addend from the insn. If RELA, it will 6054 have already been fetched for us. */ 6055 if (globals->use_rel) 6056 { 6057 int negative = (insn & (1 << 23)) ? 1 : -1; 6058 signed_addend = negative * (insn & 0xfff); 6059 } 6060 6061 /* Compute the value (X) to go in the place. */ 6062 if (r_type == R_ARM_LDR_PC_G0 6063 || r_type == R_ARM_LDR_PC_G1 6064 || r_type == R_ARM_LDR_PC_G2) 6065 /* PC relative. */ 6066 signed_value = value - pc + signed_addend; 6067 else 6068 /* Section base relative. */ 6069 signed_value = value - sb + signed_addend; 6070 6071 /* Calculate the value of the relevant G_{n-1} to obtain 6072 the residual at that stage. */ 6073 calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual); 6074 6075 /* Check for overflow. */ 6076 if (residual >= 0x1000) 6077 { 6078 (*_bfd_error_handler) 6079 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), 6080 input_bfd, input_section, 6081 (long) rel->r_offset, llabs (signed_value), howto->name); 6082 return bfd_reloc_overflow; 6083 } 6084 6085 /* Mask out the value and U bit. */ 6086 insn &= 0xff7ff000; 6087 6088 /* Set the U bit if the value to go in the place is non-negative. */ 6089 if (signed_value >= 0) 6090 insn |= 1 << 23; 6091 6092 /* Encode the offset. */ 6093 insn |= residual; 6094 6095 bfd_put_32 (input_bfd, insn, hit_data); 6096 } 6097 return bfd_reloc_ok; 6098 6099 case R_ARM_LDRS_PC_G0: 6100 case R_ARM_LDRS_PC_G1: 6101 case R_ARM_LDRS_PC_G2: 6102 case R_ARM_LDRS_SB_G0: 6103 case R_ARM_LDRS_SB_G1: 6104 case R_ARM_LDRS_SB_G2: 6105 { 6106 bfd_vma insn = bfd_get_32 (input_bfd, hit_data); 6107 bfd_vma pc = input_section->output_section->vma 6108 + input_section->output_offset + rel->r_offset; 6109 bfd_vma sb = 0; /* See note above. */ 6110 bfd_vma residual; 6111 bfd_signed_vma signed_value; 6112 int group = 0; 6113 6114 /* Determine which groups of bits to calculate. */ 6115 switch (r_type) 6116 { 6117 case R_ARM_LDRS_PC_G0: 6118 case R_ARM_LDRS_SB_G0: 6119 group = 0; 6120 break; 6121 6122 case R_ARM_LDRS_PC_G1: 6123 case R_ARM_LDRS_SB_G1: 6124 group = 1; 6125 break; 6126 6127 case R_ARM_LDRS_PC_G2: 6128 case R_ARM_LDRS_SB_G2: 6129 group = 2; 6130 break; 6131 6132 default: 6133 abort(); 6134 } 6135 6136 /* If REL, extract the addend from the insn. If RELA, it will 6137 have already been fetched for us. */ 6138 if (globals->use_rel) 6139 { 6140 int negative = (insn & (1 << 23)) ? 1 : -1; 6141 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf)); 6142 } 6143 6144 /* Compute the value (X) to go in the place. */ 6145 if (r_type == R_ARM_LDRS_PC_G0 6146 || r_type == R_ARM_LDRS_PC_G1 6147 || r_type == R_ARM_LDRS_PC_G2) 6148 /* PC relative. */ 6149 signed_value = value - pc + signed_addend; 6150 else 6151 /* Section base relative. */ 6152 signed_value = value - sb + signed_addend; 6153 6154 /* Calculate the value of the relevant G_{n-1} to obtain 6155 the residual at that stage. */ 6156 calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual); 6157 6158 /* Check for overflow. */ 6159 if (residual >= 0x100) 6160 { 6161 (*_bfd_error_handler) 6162 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), 6163 input_bfd, input_section, 6164 (long) rel->r_offset, llabs (signed_value), howto->name); 6165 return bfd_reloc_overflow; 6166 } 6167 6168 /* Mask out the value and U bit. */ 6169 insn &= 0xff7ff0f0; 6170 6171 /* Set the U bit if the value to go in the place is non-negative. */ 6172 if (signed_value >= 0) 6173 insn |= 1 << 23; 6174 6175 /* Encode the offset. */ 6176 insn |= ((residual & 0xf0) << 4) | (residual & 0xf); 6177 6178 bfd_put_32 (input_bfd, insn, hit_data); 6179 } 6180 return bfd_reloc_ok; 6181 6182 case R_ARM_LDC_PC_G0: 6183 case R_ARM_LDC_PC_G1: 6184 case R_ARM_LDC_PC_G2: 6185 case R_ARM_LDC_SB_G0: 6186 case R_ARM_LDC_SB_G1: 6187 case R_ARM_LDC_SB_G2: 6188 { 6189 bfd_vma insn = bfd_get_32 (input_bfd, hit_data); 6190 bfd_vma pc = input_section->output_section->vma 6191 + input_section->output_offset + rel->r_offset; 6192 bfd_vma sb = 0; /* See note above. */ 6193 bfd_vma residual; 6194 bfd_signed_vma signed_value; 6195 int group = 0; 6196 6197 /* Determine which groups of bits to calculate. */ 6198 switch (r_type) 6199 { 6200 case R_ARM_LDC_PC_G0: 6201 case R_ARM_LDC_SB_G0: 6202 group = 0; 6203 break; 6204 6205 case R_ARM_LDC_PC_G1: 6206 case R_ARM_LDC_SB_G1: 6207 group = 1; 6208 break; 6209 6210 case R_ARM_LDC_PC_G2: 6211 case R_ARM_LDC_SB_G2: 6212 group = 2; 6213 break; 6214 6215 default: 6216 abort(); 6217 } 6218 6219 /* If REL, extract the addend from the insn. If RELA, it will 6220 have already been fetched for us. */ 6221 if (globals->use_rel) 6222 { 6223 int negative = (insn & (1 << 23)) ? 1 : -1; 6224 signed_addend = negative * ((insn & 0xff) << 2); 6225 } 6226 6227 /* Compute the value (X) to go in the place. */ 6228 if (r_type == R_ARM_LDC_PC_G0 6229 || r_type == R_ARM_LDC_PC_G1 6230 || r_type == R_ARM_LDC_PC_G2) 6231 /* PC relative. */ 6232 signed_value = value - pc + signed_addend; 6233 else 6234 /* Section base relative. */ 6235 signed_value = value - sb + signed_addend; 6236 6237 /* Calculate the value of the relevant G_{n-1} to obtain 6238 the residual at that stage. */ 6239 calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual); 6240 6241 /* Check for overflow. (The absolute value to go in the place must be 6242 divisible by four and, after having been divided by four, must 6243 fit in eight bits.) */ 6244 if ((residual & 0x3) != 0 || residual >= 0x400) 6245 { 6246 (*_bfd_error_handler) 6247 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"), 6248 input_bfd, input_section, 6249 (long) rel->r_offset, llabs (signed_value), howto->name); 6250 return bfd_reloc_overflow; 6251 } 6252 6253 /* Mask out the value and U bit. */ 6254 insn &= 0xff7fff00; 6255 6256 /* Set the U bit if the value to go in the place is non-negative. */ 6257 if (signed_value >= 0) 6258 insn |= 1 << 23; 6259 6260 /* Encode the offset. */ 6261 insn |= residual >> 2; 6262 6263 bfd_put_32 (input_bfd, insn, hit_data); 6264 } 6265 return bfd_reloc_ok; 6266 6267 default: 6268 return bfd_reloc_notsupported; 6269 } 6270} 6271 6272/* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */ 6273static void 6274arm_add_to_rel (bfd * abfd, 6275 bfd_byte * address, 6276 reloc_howto_type * howto, 6277 bfd_signed_vma increment) 6278{ 6279 bfd_signed_vma addend; 6280 6281 if (howto->type == R_ARM_THM_CALL) 6282 { 6283 int upper_insn, lower_insn; 6284 int upper, lower; 6285 6286 upper_insn = bfd_get_16 (abfd, address); 6287 lower_insn = bfd_get_16 (abfd, address + 2); 6288 upper = upper_insn & 0x7ff; 6289 lower = lower_insn & 0x7ff; 6290 6291 addend = (upper << 12) | (lower << 1); 6292 addend += increment; 6293 addend >>= 1; 6294 6295 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff); 6296 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff); 6297 6298 bfd_put_16 (abfd, (bfd_vma) upper_insn, address); 6299 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2); 6300 } 6301 else 6302 { 6303 bfd_vma contents; 6304 6305 contents = bfd_get_32 (abfd, address); 6306 6307 /* Get the (signed) value from the instruction. */ 6308 addend = contents & howto->src_mask; 6309 if (addend & ((howto->src_mask + 1) >> 1)) 6310 { 6311 bfd_signed_vma mask; 6312 6313 mask = -1; 6314 mask &= ~ howto->src_mask; 6315 addend |= mask; 6316 } 6317 6318 /* Add in the increment, (which is a byte value). */ 6319 switch (howto->type) 6320 { 6321 default: 6322 addend += increment; 6323 break; 6324 6325 case R_ARM_PC24: 6326 case R_ARM_PLT32: 6327 case R_ARM_CALL: 6328 case R_ARM_JUMP24: 6329 addend <<= howto->size; 6330 addend += increment; 6331 6332 /* Should we check for overflow here ? */ 6333 6334 /* Drop any undesired bits. */ 6335 addend >>= howto->rightshift; 6336 break; 6337 } 6338 6339 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask); 6340 6341 bfd_put_32 (abfd, contents, address); 6342 } 6343} 6344 6345#define IS_ARM_TLS_RELOC(R_TYPE) \ 6346 ((R_TYPE) == R_ARM_TLS_GD32 \ 6347 || (R_TYPE) == R_ARM_TLS_LDO32 \ 6348 || (R_TYPE) == R_ARM_TLS_LDM32 \ 6349 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \ 6350 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \ 6351 || (R_TYPE) == R_ARM_TLS_TPOFF32 \ 6352 || (R_TYPE) == R_ARM_TLS_LE32 \ 6353 || (R_TYPE) == R_ARM_TLS_IE32) 6354 6355/* Relocate an ARM ELF section. */ 6356static bfd_boolean 6357elf32_arm_relocate_section (bfd * output_bfd, 6358 struct bfd_link_info * info, 6359 bfd * input_bfd, 6360 asection * input_section, 6361 bfd_byte * contents, 6362 Elf_Internal_Rela * relocs, 6363 Elf_Internal_Sym * local_syms, 6364 asection ** local_sections) 6365{ 6366 Elf_Internal_Shdr *symtab_hdr; 6367 struct elf_link_hash_entry **sym_hashes; 6368 Elf_Internal_Rela *rel; 6369 Elf_Internal_Rela *relend; 6370 const char *name; 6371 struct elf32_arm_link_hash_table * globals; 6372 6373 globals = elf32_arm_hash_table (info); 6374 6375 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; 6376 sym_hashes = elf_sym_hashes (input_bfd); 6377 6378 rel = relocs; 6379 relend = relocs + input_section->reloc_count; 6380 for (; rel < relend; rel++) 6381 { 6382 int r_type; 6383 reloc_howto_type * howto; 6384 unsigned long r_symndx; 6385 Elf_Internal_Sym * sym; 6386 asection * sec; 6387 struct elf_link_hash_entry * h; 6388 bfd_vma relocation; 6389 bfd_reloc_status_type r; 6390 arelent bfd_reloc; 6391 char sym_type; 6392 bfd_boolean unresolved_reloc = FALSE; 6393 char *error_message = NULL; 6394 6395 r_symndx = ELF32_R_SYM (rel->r_info); 6396 r_type = ELF32_R_TYPE (rel->r_info); 6397 r_type = arm_real_reloc_type (globals, r_type); 6398 6399 if ( r_type == R_ARM_GNU_VTENTRY 6400 || r_type == R_ARM_GNU_VTINHERIT) 6401 continue; 6402 6403 bfd_reloc.howto = elf32_arm_howto_from_type (r_type); 6404 howto = bfd_reloc.howto; 6405 6406 h = NULL; 6407 sym = NULL; 6408 sec = NULL; 6409 6410 if (r_symndx < symtab_hdr->sh_info) 6411 { 6412 sym = local_syms + r_symndx; 6413 sym_type = ELF32_ST_TYPE (sym->st_info); 6414 sec = local_sections[r_symndx]; 6415 if (globals->use_rel) 6416 { 6417 relocation = (sec->output_section->vma 6418 + sec->output_offset 6419 + sym->st_value); 6420 if (!info->relocatable 6421 && (sec->flags & SEC_MERGE) 6422 && ELF_ST_TYPE (sym->st_info) == STT_SECTION) 6423 { 6424 asection *msec; 6425 bfd_vma addend, value; 6426 6427 if (howto->rightshift) 6428 { 6429 (*_bfd_error_handler) 6430 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"), 6431 input_bfd, input_section, 6432 (long) rel->r_offset, howto->name); 6433 return FALSE; 6434 } 6435 6436 value = bfd_get_32 (input_bfd, contents + rel->r_offset); 6437 6438 /* Get the (signed) value from the instruction. */ 6439 addend = value & howto->src_mask; 6440 if (addend & ((howto->src_mask + 1) >> 1)) 6441 { 6442 bfd_signed_vma mask; 6443 6444 mask = -1; 6445 mask &= ~ howto->src_mask; 6446 addend |= mask; 6447 } 6448 msec = sec; 6449 addend = 6450 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) 6451 - relocation; 6452 addend += msec->output_section->vma + msec->output_offset; 6453 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask); 6454 bfd_put_32 (input_bfd, value, contents + rel->r_offset); 6455 } 6456 } 6457 else 6458 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); 6459 } 6460 else 6461 { 6462 bfd_boolean warned; 6463 6464 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 6465 r_symndx, symtab_hdr, sym_hashes, 6466 h, sec, relocation, 6467 unresolved_reloc, warned); 6468 6469 sym_type = h->type; 6470 } 6471 6472 if (sec != NULL && elf_discarded_section (sec)) 6473 { 6474 /* For relocs against symbols from removed linkonce sections, 6475 or sections discarded by a linker script, we just want the 6476 section contents zeroed. Avoid any special processing. */ 6477 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); 6478 rel->r_info = 0; 6479 rel->r_addend = 0; 6480 continue; 6481 } 6482 6483 if (info->relocatable) 6484 { 6485 /* This is a relocatable link. We don't have to change 6486 anything, unless the reloc is against a section symbol, 6487 in which case we have to adjust according to where the 6488 section symbol winds up in the output section. */ 6489 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION) 6490 { 6491 if (globals->use_rel) 6492 arm_add_to_rel (input_bfd, contents + rel->r_offset, 6493 howto, (bfd_signed_vma) sec->output_offset); 6494 else 6495 rel->r_addend += sec->output_offset; 6496 } 6497 continue; 6498 } 6499 6500 if (h != NULL) 6501 name = h->root.root.string; 6502 else 6503 { 6504 name = (bfd_elf_string_from_elf_section 6505 (input_bfd, symtab_hdr->sh_link, sym->st_name)); 6506 if (name == NULL || *name == '\0') 6507 name = bfd_section_name (input_bfd, sec); 6508 } 6509 6510 if (r_symndx != 0 6511 && r_type != R_ARM_NONE 6512 && (h == NULL 6513 || h->root.type == bfd_link_hash_defined 6514 || h->root.type == bfd_link_hash_defweak) 6515 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS)) 6516 { 6517 (*_bfd_error_handler) 6518 ((sym_type == STT_TLS 6519 ? _("%B(%A+0x%lx): %s used with TLS symbol %s") 6520 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")), 6521 input_bfd, 6522 input_section, 6523 (long) rel->r_offset, 6524 howto->name, 6525 name); 6526 } 6527 6528 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd, 6529 input_section, contents, rel, 6530 relocation, info, sec, name, 6531 (h ? ELF_ST_TYPE (h->type) : 6532 ELF_ST_TYPE (sym->st_info)), h, 6533 &unresolved_reloc, &error_message); 6534 6535 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections 6536 because such sections are not SEC_ALLOC and thus ld.so will 6537 not process them. */ 6538 if (unresolved_reloc 6539 && !((input_section->flags & SEC_DEBUGGING) != 0 6540 && h->def_dynamic)) 6541 { 6542 (*_bfd_error_handler) 6543 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), 6544 input_bfd, 6545 input_section, 6546 (long) rel->r_offset, 6547 howto->name, 6548 h->root.root.string); 6549 return FALSE; 6550 } 6551 6552 if (r != bfd_reloc_ok) 6553 { 6554 switch (r) 6555 { 6556 case bfd_reloc_overflow: 6557 /* If the overflowing reloc was to an undefined symbol, 6558 we have already printed one error message and there 6559 is no point complaining again. */ 6560 if ((! h || 6561 h->root.type != bfd_link_hash_undefined) 6562 && (!((*info->callbacks->reloc_overflow) 6563 (info, (h ? &h->root : NULL), name, howto->name, 6564 (bfd_vma) 0, input_bfd, input_section, 6565 rel->r_offset)))) 6566 return FALSE; 6567 break; 6568 6569 case bfd_reloc_undefined: 6570 if (!((*info->callbacks->undefined_symbol) 6571 (info, name, input_bfd, input_section, 6572 rel->r_offset, TRUE))) 6573 return FALSE; 6574 break; 6575 6576 case bfd_reloc_outofrange: 6577 error_message = _("out of range"); 6578 goto common_error; 6579 6580 case bfd_reloc_notsupported: 6581 error_message = _("unsupported relocation"); 6582 goto common_error; 6583 6584 case bfd_reloc_dangerous: 6585 /* error_message should already be set. */ 6586 goto common_error; 6587 6588 default: 6589 error_message = _("unknown error"); 6590 /* fall through */ 6591 6592 common_error: 6593 BFD_ASSERT (error_message != NULL); 6594 if (!((*info->callbacks->reloc_dangerous) 6595 (info, error_message, input_bfd, input_section, 6596 rel->r_offset))) 6597 return FALSE; 6598 break; 6599 } 6600 } 6601 } 6602 6603 return TRUE; 6604} 6605 6606/* Set the right machine number. */ 6607 6608static bfd_boolean 6609elf32_arm_object_p (bfd *abfd) 6610{ 6611 unsigned int mach; 6612 6613 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION); 6614 6615 if (mach != bfd_mach_arm_unknown) 6616 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); 6617 6618 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT) 6619 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312); 6620 6621 else 6622 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); 6623 6624 return TRUE; 6625} 6626 6627/* Function to keep ARM specific flags in the ELF header. */ 6628 6629static bfd_boolean 6630elf32_arm_set_private_flags (bfd *abfd, flagword flags) 6631{ 6632 if (elf_flags_init (abfd) 6633 && elf_elfheader (abfd)->e_flags != flags) 6634 { 6635 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN) 6636 { 6637 if (flags & EF_ARM_INTERWORK) 6638 (*_bfd_error_handler) 6639 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"), 6640 abfd); 6641 else 6642 _bfd_error_handler 6643 (_("Warning: Clearing the interworking flag of %B due to outside request"), 6644 abfd); 6645 } 6646 } 6647 else 6648 { 6649 elf_elfheader (abfd)->e_flags = flags; 6650 elf_flags_init (abfd) = TRUE; 6651 } 6652 6653 return TRUE; 6654} 6655 6656/* Copy backend specific data from one object module to another. */ 6657 6658static bfd_boolean 6659elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd) 6660{ 6661 flagword in_flags; 6662 flagword out_flags; 6663 6664 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour 6665 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 6666 return TRUE; 6667 6668 in_flags = elf_elfheader (ibfd)->e_flags; 6669 out_flags = elf_elfheader (obfd)->e_flags; 6670 6671 if (elf_flags_init (obfd) 6672 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN 6673 && in_flags != out_flags) 6674 { 6675 /* Cannot mix APCS26 and APCS32 code. */ 6676 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) 6677 return FALSE; 6678 6679 /* Cannot mix float APCS and non-float APCS code. */ 6680 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) 6681 return FALSE; 6682 6683 /* If the src and dest have different interworking flags 6684 then turn off the interworking bit. */ 6685 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) 6686 { 6687 if (out_flags & EF_ARM_INTERWORK) 6688 _bfd_error_handler 6689 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"), 6690 obfd, ibfd); 6691 6692 in_flags &= ~EF_ARM_INTERWORK; 6693 } 6694 6695 /* Likewise for PIC, though don't warn for this case. */ 6696 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC)) 6697 in_flags &= ~EF_ARM_PIC; 6698 } 6699 6700 elf_elfheader (obfd)->e_flags = in_flags; 6701 elf_flags_init (obfd) = TRUE; 6702 6703 /* Also copy the EI_OSABI field. */ 6704 elf_elfheader (obfd)->e_ident[EI_OSABI] = 6705 elf_elfheader (ibfd)->e_ident[EI_OSABI]; 6706 6707 /* Copy object attributes. */ 6708 _bfd_elf_copy_obj_attributes (ibfd, obfd); 6709 6710 return TRUE; 6711} 6712 6713/* Values for Tag_ABI_PCS_R9_use. */ 6714enum 6715{ 6716 AEABI_R9_V6, 6717 AEABI_R9_SB, 6718 AEABI_R9_TLS, 6719 AEABI_R9_unused 6720}; 6721 6722/* Values for Tag_ABI_PCS_RW_data. */ 6723enum 6724{ 6725 AEABI_PCS_RW_data_absolute, 6726 AEABI_PCS_RW_data_PCrel, 6727 AEABI_PCS_RW_data_SBrel, 6728 AEABI_PCS_RW_data_unused 6729}; 6730 6731/* Values for Tag_ABI_enum_size. */ 6732enum 6733{ 6734 AEABI_enum_unused, 6735 AEABI_enum_short, 6736 AEABI_enum_wide, 6737 AEABI_enum_forced_wide 6738}; 6739 6740/* Determine whether an object attribute tag takes an integer, a 6741 string or both. */ 6742static int 6743elf32_arm_obj_attrs_arg_type (int tag) 6744{ 6745 if (tag == Tag_compatibility) 6746 return 3; 6747 else if (tag == 4 || tag == 5) 6748 return 2; 6749 else if (tag < 32) 6750 return 1; 6751 else 6752 return (tag & 1) != 0 ? 2 : 1; 6753} 6754 6755/* Merge EABI object attributes from IBFD into OBFD. Raise an error if there 6756 are conflicting attributes. */ 6757static bfd_boolean 6758elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd) 6759{ 6760 obj_attribute *in_attr; 6761 obj_attribute *out_attr; 6762 obj_attribute_list *in_list; 6763 /* Some tags have 0 = don't care, 1 = strong requirement, 6764 2 = weak requirement. */ 6765 static const int order_312[3] = {3, 1, 2}; 6766 int i; 6767 6768 if (!elf_known_obj_attributes_proc (obfd)[0].i) 6769 { 6770 /* This is the first object. Copy the attributes. */ 6771 _bfd_elf_copy_obj_attributes (ibfd, obfd); 6772 6773 /* Use the Tag_null value to indicate the attributes have been 6774 initialized. */ 6775 elf_known_obj_attributes_proc (obfd)[0].i = 1; 6776 6777 return TRUE; 6778 } 6779 6780 in_attr = elf_known_obj_attributes_proc (ibfd); 6781 out_attr = elf_known_obj_attributes_proc (obfd); 6782 /* This needs to happen before Tag_ABI_FP_number_model is merged. */ 6783 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i) 6784 { 6785 /* Ignore mismatches if teh object doesn't use floating point. */ 6786 if (out_attr[Tag_ABI_FP_number_model].i == 0) 6787 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i; 6788 else if (in_attr[Tag_ABI_FP_number_model].i != 0) 6789 { 6790 bfd *hasbfd, *hasnotbfd; 6791 6792 if (in_attr[Tag_ABI_VFP_args].i) 6793 { 6794 hasbfd = ibfd; 6795 hasnotbfd = obfd; 6796 } 6797 else 6798 { 6799 hasbfd = obfd; 6800 hasnotbfd = ibfd; 6801 } 6802 6803 _bfd_error_handler 6804 (_("ERROR: %B uses VFP register arguments, %B does not"), 6805 hasbfd, hasnotbfd); 6806 return FALSE; 6807 } 6808 } 6809 6810 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++) 6811 { 6812 if (out_attr[i].type == 0) 6813 out_attr[i].type = in_attr[i].type; 6814 6815 /* Merge this attribute with existing attributes. */ 6816 switch (i) 6817 { 6818 case Tag_CPU_raw_name: 6819 case Tag_CPU_name: 6820 /* Use whichever has the greatest architecture requirements. We 6821 won't necessarily have both the above tags, so make sure input 6822 name is non-NULL. */ 6823 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i 6824 && in_attr[i].s) 6825 out_attr[i].s = _bfd_elf_attr_strdup (obfd, in_attr[i].s); 6826 break; 6827 6828 case Tag_ABI_optimization_goals: 6829 case Tag_ABI_FP_optimization_goals: 6830 /* Use the first value seen. */ 6831 break; 6832 6833 case Tag_CPU_arch: 6834 case Tag_ARM_ISA_use: 6835 case Tag_THUMB_ISA_use: 6836 case Tag_VFP_arch: 6837 case Tag_WMMX_arch: 6838 case Tag_NEON_arch: 6839 /* ??? Do NEON and WMMX conflict? */ 6840 case Tag_ABI_FP_rounding: 6841 case Tag_ABI_FP_denormal: 6842 case Tag_ABI_FP_exceptions: 6843 case Tag_ABI_FP_user_exceptions: 6844 case Tag_ABI_FP_number_model: 6845 case Tag_ABI_align8_preserved: 6846 case Tag_ABI_HardFP_use: 6847 case Tag_CPU_unaligned_access: 6848 case Tag_FP_HP_extension: 6849 /* Use the largest value specified. */ 6850 if (in_attr[i].i > out_attr[i].i) 6851 out_attr[i].i = in_attr[i].i; 6852 break; 6853 6854 case Tag_CPU_arch_profile: 6855 /* Warn if conflicting architecture profiles used. */ 6856 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i) 6857 { 6858 _bfd_error_handler 6859 (_("ERROR: %B: Conflicting architecture profiles %c/%c"), 6860 ibfd, in_attr[i].i, out_attr[i].i); 6861 return FALSE; 6862 } 6863 if (in_attr[i].i) 6864 out_attr[i].i = in_attr[i].i; 6865 break; 6866 case Tag_PCS_config: 6867 if (out_attr[i].i == 0) 6868 out_attr[i].i = in_attr[i].i; 6869 else if (in_attr[i].i != 0 && out_attr[i].i != 0) 6870 { 6871 /* It's sometimes ok to mix different configs, so this is only 6872 a warning. */ 6873 _bfd_error_handler 6874 (_("Warning: %B: Conflicting platform configuration"), ibfd); 6875 } 6876 break; 6877 case Tag_ABI_PCS_R9_use: 6878 if (in_attr[i].i != out_attr[i].i 6879 && out_attr[i].i != AEABI_R9_unused 6880 && in_attr[i].i != AEABI_R9_unused) 6881 { 6882 _bfd_error_handler 6883 (_("ERROR: %B: Conflicting use of R9"), ibfd); 6884 return FALSE; 6885 } 6886 if (out_attr[i].i == AEABI_R9_unused) 6887 out_attr[i].i = in_attr[i].i; 6888 break; 6889 case Tag_ABI_PCS_RW_data: 6890 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel 6891 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB 6892 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused) 6893 { 6894 _bfd_error_handler 6895 (_("ERROR: %B: SB relative addressing conflicts with use of R9"), 6896 ibfd); 6897 return FALSE; 6898 } 6899 /* Use the smallest value specified. */ 6900 if (in_attr[i].i < out_attr[i].i) 6901 out_attr[i].i = in_attr[i].i; 6902 break; 6903 case Tag_ABI_PCS_RO_data: 6904 /* Use the smallest value specified. */ 6905 if (in_attr[i].i < out_attr[i].i) 6906 out_attr[i].i = in_attr[i].i; 6907 break; 6908 case Tag_ABI_PCS_GOT_use: 6909 if (in_attr[i].i > 2 || out_attr[i].i > 2 6910 || order_312[in_attr[i].i] < order_312[out_attr[i].i]) 6911 out_attr[i].i = in_attr[i].i; 6912 break; 6913 case Tag_ABI_PCS_wchar_t: 6914 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i) 6915 { 6916 _bfd_error_handler 6917 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd); 6918 return FALSE; 6919 } 6920 if (in_attr[i].i) 6921 out_attr[i].i = in_attr[i].i; 6922 break; 6923 case Tag_ABI_align8_needed: 6924 /* ??? Check against Tag_ABI_align8_preserved. */ 6925 if (in_attr[i].i > 2 || out_attr[i].i > 2 6926 || order_312[in_attr[i].i] < order_312[out_attr[i].i]) 6927 out_attr[i].i = in_attr[i].i; 6928 break; 6929 case Tag_ABI_enum_size: 6930 if (in_attr[i].i != AEABI_enum_unused) 6931 { 6932 if (out_attr[i].i == AEABI_enum_unused 6933 || out_attr[i].i == AEABI_enum_forced_wide) 6934 { 6935 /* The existing object is compatible with anything. 6936 Use whatever requirements the new object has. */ 6937 out_attr[i].i = in_attr[i].i; 6938 } 6939 else if (in_attr[i].i != AEABI_enum_forced_wide 6940 && out_attr[i].i != in_attr[i].i 6941 && !elf32_arm_tdata (obfd)->no_enum_size_warning) 6942 { 6943 const char *aeabi_enum_names[] = 6944 { "", "variable-size", "32-bit", "" }; 6945 _bfd_error_handler 6946 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"), 6947 ibfd, aeabi_enum_names[in_attr[i].i], 6948 aeabi_enum_names[out_attr[i].i]); 6949 } 6950 } 6951 break; 6952 case Tag_ABI_VFP_args: 6953 /* Aready done. */ 6954 break; 6955 case Tag_ABI_WMMX_args: 6956 if (in_attr[i].i != out_attr[i].i) 6957 { 6958 _bfd_error_handler 6959 (_("ERROR: %B uses iWMMXt register arguments, %B does not"), 6960 ibfd, obfd); 6961 return FALSE; 6962 } 6963 break; 6964 default: /* All known attributes should be explicitly covered. */ 6965 /* XXX Not now */ 6966 /* abort (); */ 6967 break; 6968 } 6969 } 6970 6971 /* Merge Tag_compatibility attributes and any common GNU ones. */ 6972 _bfd_elf_merge_object_attributes (ibfd, obfd); 6973 6974 /* Check for any attributes not known on ARM. */ 6975 in_list = elf_other_obj_attributes_proc (ibfd); 6976 while (in_list && in_list->tag == Tag_compatibility) 6977 in_list = in_list->next; 6978 6979 for (; in_list; in_list = in_list->next) 6980 { 6981 if ((in_list->tag & 128) < 64 6982 && in_list->tag != Tag_Virtualization_use) 6983 { 6984 _bfd_error_handler 6985 (_("Warning: %B: Unknown EABI object attribute %d"), 6986 ibfd, in_list->tag); 6987 break; 6988 } 6989 } 6990 return TRUE; 6991} 6992 6993 6994/* Return TRUE if the two EABI versions are incompatible. */ 6995 6996static bfd_boolean 6997elf32_arm_versions_compatible (unsigned iver, unsigned over) 6998{ 6999 /* v4 and v5 are the same spec before and after it was released, 7000 so allow mixing them. */ 7001 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5) 7002 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4)) 7003 return TRUE; 7004 7005 return (iver == over); 7006} 7007 7008/* Merge backend specific data from an object file to the output 7009 object file when linking. */ 7010 7011static bfd_boolean 7012elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd) 7013{ 7014 flagword out_flags; 7015 flagword in_flags; 7016 bfd_boolean flags_compatible = TRUE; 7017 asection *sec; 7018 7019 /* Check if we have the same endianess. */ 7020 if (! _bfd_generic_verify_endian_match (ibfd, obfd)) 7021 return FALSE; 7022 7023 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour 7024 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 7025 return TRUE; 7026 7027 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd)) 7028 return FALSE; 7029 7030 /* The input BFD must have had its flags initialised. */ 7031 /* The following seems bogus to me -- The flags are initialized in 7032 the assembler but I don't think an elf_flags_init field is 7033 written into the object. */ 7034 /* BFD_ASSERT (elf_flags_init (ibfd)); */ 7035 7036 in_flags = elf_elfheader (ibfd)->e_flags; 7037 out_flags = elf_elfheader (obfd)->e_flags; 7038 7039 if (!elf_flags_init (obfd)) 7040 { 7041 /* If the input is the default architecture and had the default 7042 flags then do not bother setting the flags for the output 7043 architecture, instead allow future merges to do this. If no 7044 future merges ever set these flags then they will retain their 7045 uninitialised values, which surprise surprise, correspond 7046 to the default values. */ 7047 if (bfd_get_arch_info (ibfd)->the_default 7048 && elf_elfheader (ibfd)->e_flags == 0) 7049 return TRUE; 7050 7051 elf_flags_init (obfd) = TRUE; 7052 elf_elfheader (obfd)->e_flags = in_flags; 7053 7054 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) 7055 && bfd_get_arch_info (obfd)->the_default) 7056 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd)); 7057 7058 return TRUE; 7059 } 7060 7061 /* Determine what should happen if the input ARM architecture 7062 does not match the output ARM architecture. */ 7063 if (! bfd_arm_merge_machines (ibfd, obfd)) 7064 return FALSE; 7065 7066 /* Identical flags must be compatible. */ 7067 if (in_flags == out_flags) 7068 return TRUE; 7069 7070 /* Check to see if the input BFD actually contains any sections. If 7071 not, its flags may not have been initialised either, but it 7072 cannot actually cause any incompatiblity. Do not short-circuit 7073 dynamic objects; their section list may be emptied by 7074 elf_link_add_object_symbols. 7075 7076 Also check to see if there are no code sections in the input. 7077 In this case there is no need to check for code specific flags. 7078 XXX - do we need to worry about floating-point format compatability 7079 in data sections ? */ 7080 if (!(ibfd->flags & DYNAMIC)) 7081 { 7082 bfd_boolean null_input_bfd = TRUE; 7083 bfd_boolean only_data_sections = TRUE; 7084 7085 for (sec = ibfd->sections; sec != NULL; sec = sec->next) 7086 { 7087 /* Ignore synthetic glue sections. */ 7088 if (strcmp (sec->name, ".glue_7") 7089 && strcmp (sec->name, ".glue_7t")) 7090 { 7091 if ((bfd_get_section_flags (ibfd, sec) 7092 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) 7093 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) 7094 only_data_sections = FALSE; 7095 7096 null_input_bfd = FALSE; 7097 break; 7098 } 7099 } 7100 7101 if (null_input_bfd || only_data_sections) 7102 return TRUE; 7103 } 7104 7105 /* Complain about various flag mismatches. */ 7106 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags), 7107 EF_ARM_EABI_VERSION (out_flags))) 7108 { 7109 _bfd_error_handler 7110 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"), 7111 ibfd, obfd, 7112 (in_flags & EF_ARM_EABIMASK) >> 24, 7113 (out_flags & EF_ARM_EABIMASK) >> 24); 7114 return FALSE; 7115 } 7116 7117 /* Not sure what needs to be checked for EABI versions >= 1. */ 7118 /* VxWorks libraries do not use these flags. */ 7119 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed 7120 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed 7121 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN) 7122 { 7123 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) 7124 { 7125 _bfd_error_handler 7126 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"), 7127 ibfd, obfd, 7128 in_flags & EF_ARM_APCS_26 ? 26 : 32, 7129 out_flags & EF_ARM_APCS_26 ? 26 : 32); 7130 flags_compatible = FALSE; 7131 } 7132 7133 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) 7134 { 7135 if (in_flags & EF_ARM_APCS_FLOAT) 7136 _bfd_error_handler 7137 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"), 7138 ibfd, obfd); 7139 else 7140 _bfd_error_handler 7141 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"), 7142 ibfd, obfd); 7143 7144 flags_compatible = FALSE; 7145 } 7146 7147 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT)) 7148 { 7149 if (in_flags & EF_ARM_VFP_FLOAT) 7150 _bfd_error_handler 7151 (_("ERROR: %B uses VFP instructions, whereas %B does not"), 7152 ibfd, obfd); 7153 else 7154 _bfd_error_handler 7155 (_("ERROR: %B uses FPA instructions, whereas %B does not"), 7156 ibfd, obfd); 7157 7158 flags_compatible = FALSE; 7159 } 7160 7161 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT)) 7162 { 7163 if (in_flags & EF_ARM_MAVERICK_FLOAT) 7164 _bfd_error_handler 7165 (_("ERROR: %B uses Maverick instructions, whereas %B does not"), 7166 ibfd, obfd); 7167 else 7168 _bfd_error_handler 7169 (_("ERROR: %B does not use Maverick instructions, whereas %B does"), 7170 ibfd, obfd); 7171 7172 flags_compatible = FALSE; 7173 } 7174 7175#ifdef EF_ARM_SOFT_FLOAT 7176 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT)) 7177 { 7178 /* We can allow interworking between code that is VFP format 7179 layout, and uses either soft float or integer regs for 7180 passing floating point arguments and results. We already 7181 know that the APCS_FLOAT flags match; similarly for VFP 7182 flags. */ 7183 if ((in_flags & EF_ARM_APCS_FLOAT) != 0 7184 || (in_flags & EF_ARM_VFP_FLOAT) == 0) 7185 { 7186 if (in_flags & EF_ARM_SOFT_FLOAT) 7187 _bfd_error_handler 7188 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"), 7189 ibfd, obfd); 7190 else 7191 _bfd_error_handler 7192 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"), 7193 ibfd, obfd); 7194 7195 flags_compatible = FALSE; 7196 } 7197 } 7198#endif 7199 7200 /* Interworking mismatch is only a warning. */ 7201 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) 7202 { 7203 if (in_flags & EF_ARM_INTERWORK) 7204 { 7205 _bfd_error_handler 7206 (_("Warning: %B supports interworking, whereas %B does not"), 7207 ibfd, obfd); 7208 } 7209 else 7210 { 7211 _bfd_error_handler 7212 (_("Warning: %B does not support interworking, whereas %B does"), 7213 ibfd, obfd); 7214 } 7215 } 7216 } 7217 7218 return flags_compatible; 7219} 7220 7221/* Display the flags field. */ 7222 7223static bfd_boolean 7224elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr) 7225{ 7226 FILE * file = (FILE *) ptr; 7227 unsigned long flags; 7228 7229 BFD_ASSERT (abfd != NULL && ptr != NULL); 7230 7231 /* Print normal ELF private data. */ 7232 _bfd_elf_print_private_bfd_data (abfd, ptr); 7233 7234 flags = elf_elfheader (abfd)->e_flags; 7235 /* Ignore init flag - it may not be set, despite the flags field 7236 containing valid data. */ 7237 7238 /* xgettext:c-format */ 7239 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); 7240 7241 switch (EF_ARM_EABI_VERSION (flags)) 7242 { 7243 case EF_ARM_EABI_UNKNOWN: 7244 /* The following flag bits are GNU extensions and not part of the 7245 official ARM ELF extended ABI. Hence they are only decoded if 7246 the EABI version is not set. */ 7247 if (flags & EF_ARM_INTERWORK) 7248 fprintf (file, _(" [interworking enabled]")); 7249 7250 if (flags & EF_ARM_APCS_26) 7251 fprintf (file, " [APCS-26]"); 7252 else 7253 fprintf (file, " [APCS-32]"); 7254 7255 if (flags & EF_ARM_VFP_FLOAT) 7256 fprintf (file, _(" [VFP float format]")); 7257 else if (flags & EF_ARM_MAVERICK_FLOAT) 7258 fprintf (file, _(" [Maverick float format]")); 7259 else 7260 fprintf (file, _(" [FPA float format]")); 7261 7262 if (flags & EF_ARM_APCS_FLOAT) 7263 fprintf (file, _(" [floats passed in float registers]")); 7264 7265 if (flags & EF_ARM_PIC) 7266 fprintf (file, _(" [position independent]")); 7267 7268 if (flags & EF_ARM_NEW_ABI) 7269 fprintf (file, _(" [new ABI]")); 7270 7271 if (flags & EF_ARM_OLD_ABI) 7272 fprintf (file, _(" [old ABI]")); 7273 7274 if (flags & EF_ARM_SOFT_FLOAT) 7275 fprintf (file, _(" [software FP]")); 7276 7277 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT 7278 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI 7279 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT 7280 | EF_ARM_MAVERICK_FLOAT); 7281 break; 7282 7283 case EF_ARM_EABI_VER1: 7284 fprintf (file, _(" [Version1 EABI]")); 7285 7286 if (flags & EF_ARM_SYMSARESORTED) 7287 fprintf (file, _(" [sorted symbol table]")); 7288 else 7289 fprintf (file, _(" [unsorted symbol table]")); 7290 7291 flags &= ~ EF_ARM_SYMSARESORTED; 7292 break; 7293 7294 case EF_ARM_EABI_VER2: 7295 fprintf (file, _(" [Version2 EABI]")); 7296 7297 if (flags & EF_ARM_SYMSARESORTED) 7298 fprintf (file, _(" [sorted symbol table]")); 7299 else 7300 fprintf (file, _(" [unsorted symbol table]")); 7301 7302 if (flags & EF_ARM_DYNSYMSUSESEGIDX) 7303 fprintf (file, _(" [dynamic symbols use segment index]")); 7304 7305 if (flags & EF_ARM_MAPSYMSFIRST) 7306 fprintf (file, _(" [mapping symbols precede others]")); 7307 7308 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX 7309 | EF_ARM_MAPSYMSFIRST); 7310 break; 7311 7312 case EF_ARM_EABI_VER3: 7313 fprintf (file, _(" [Version3 EABI]")); 7314 break; 7315 7316 case EF_ARM_EABI_VER4: 7317 fprintf (file, _(" [Version4 EABI]")); 7318 goto eabi; 7319 7320 case EF_ARM_EABI_VER5: 7321 fprintf (file, _(" [Version5 EABI]")); 7322 eabi: 7323 if (flags & EF_ARM_BE8) 7324 fprintf (file, _(" [BE8]")); 7325 7326 if (flags & EF_ARM_LE8) 7327 fprintf (file, _(" [LE8]")); 7328 7329 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8); 7330 break; 7331 7332 default: 7333 fprintf (file, _(" <EABI version unrecognised>")); 7334 break; 7335 } 7336 7337 flags &= ~ EF_ARM_EABIMASK; 7338 7339 if (flags & EF_ARM_RELEXEC) 7340 fprintf (file, _(" [relocatable executable]")); 7341 7342 if (flags & EF_ARM_HASENTRY) 7343 fprintf (file, _(" [has entry point]")); 7344 7345 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY); 7346 7347 if (flags) 7348 fprintf (file, _("<Unrecognised flag bits set>")); 7349 7350 fputc ('\n', file); 7351 7352 return TRUE; 7353} 7354 7355static int 7356elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type) 7357{ 7358 switch (ELF_ST_TYPE (elf_sym->st_info)) 7359 { 7360 case STT_ARM_TFUNC: 7361 return ELF_ST_TYPE (elf_sym->st_info); 7362 7363 case STT_ARM_16BIT: 7364 /* If the symbol is not an object, return the STT_ARM_16BIT flag. 7365 This allows us to distinguish between data used by Thumb instructions 7366 and non-data (which is probably code) inside Thumb regions of an 7367 executable. */ 7368 if (type != STT_OBJECT && type != STT_TLS) 7369 return ELF_ST_TYPE (elf_sym->st_info); 7370 break; 7371 7372 default: 7373 break; 7374 } 7375 7376 return type; 7377} 7378 7379static asection * 7380elf32_arm_gc_mark_hook (asection *sec, 7381 struct bfd_link_info *info, 7382 Elf_Internal_Rela *rel, 7383 struct elf_link_hash_entry *h, 7384 Elf_Internal_Sym *sym) 7385{ 7386 if (h != NULL) 7387 switch (ELF32_R_TYPE (rel->r_info)) 7388 { 7389 case R_ARM_GNU_VTINHERIT: 7390 case R_ARM_GNU_VTENTRY: 7391 return NULL; 7392 } 7393 7394 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); 7395} 7396 7397/* Update the got entry reference counts for the section being removed. */ 7398 7399static bfd_boolean 7400elf32_arm_gc_sweep_hook (bfd * abfd, 7401 struct bfd_link_info * info, 7402 asection * sec, 7403 const Elf_Internal_Rela * relocs) 7404{ 7405 Elf_Internal_Shdr *symtab_hdr; 7406 struct elf_link_hash_entry **sym_hashes; 7407 bfd_signed_vma *local_got_refcounts; 7408 const Elf_Internal_Rela *rel, *relend; 7409 struct elf32_arm_link_hash_table * globals; 7410 7411 globals = elf32_arm_hash_table (info); 7412 7413 elf_section_data (sec)->local_dynrel = NULL; 7414 7415 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 7416 sym_hashes = elf_sym_hashes (abfd); 7417 local_got_refcounts = elf_local_got_refcounts (abfd); 7418 7419 relend = relocs + sec->reloc_count; 7420 for (rel = relocs; rel < relend; rel++) 7421 { 7422 unsigned long r_symndx; 7423 struct elf_link_hash_entry *h = NULL; 7424 int r_type; 7425 7426 r_symndx = ELF32_R_SYM (rel->r_info); 7427 if (r_symndx >= symtab_hdr->sh_info) 7428 { 7429 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 7430 while (h->root.type == bfd_link_hash_indirect 7431 || h->root.type == bfd_link_hash_warning) 7432 h = (struct elf_link_hash_entry *) h->root.u.i.link; 7433 } 7434 7435 r_type = ELF32_R_TYPE (rel->r_info); 7436 r_type = arm_real_reloc_type (globals, r_type); 7437 switch (r_type) 7438 { 7439 case R_ARM_GOT32: 7440 case R_ARM_GOT_PREL: 7441 case R_ARM_TLS_GD32: 7442 case R_ARM_TLS_IE32: 7443 if (h != NULL) 7444 { 7445 if (h->got.refcount > 0) 7446 h->got.refcount -= 1; 7447 } 7448 else if (local_got_refcounts != NULL) 7449 { 7450 if (local_got_refcounts[r_symndx] > 0) 7451 local_got_refcounts[r_symndx] -= 1; 7452 } 7453 break; 7454 7455 case R_ARM_TLS_LDM32: 7456 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1; 7457 break; 7458 7459 case R_ARM_ABS32: 7460 case R_ARM_ABS32_NOI: 7461 case R_ARM_REL32: 7462 case R_ARM_REL32_NOI: 7463 case R_ARM_PC24: 7464 case R_ARM_PLT32: 7465 case R_ARM_CALL: 7466 case R_ARM_JUMP24: 7467 case R_ARM_PREL31: 7468 case R_ARM_THM_CALL: 7469 case R_ARM_MOVW_ABS_NC: 7470 case R_ARM_MOVT_ABS: 7471 case R_ARM_MOVW_PREL_NC: 7472 case R_ARM_MOVT_PREL: 7473 case R_ARM_THM_MOVW_ABS_NC: 7474 case R_ARM_THM_MOVT_ABS: 7475 case R_ARM_THM_MOVW_PREL_NC: 7476 case R_ARM_THM_MOVT_PREL: 7477 /* Should the interworking branches be here also? */ 7478 7479 if (h != NULL) 7480 { 7481 struct elf32_arm_link_hash_entry *eh; 7482 struct elf32_arm_relocs_copied **pp; 7483 struct elf32_arm_relocs_copied *p; 7484 7485 eh = (struct elf32_arm_link_hash_entry *) h; 7486 7487 if (h->plt.refcount > 0) 7488 { 7489 h->plt.refcount -= 1; 7490 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL) 7491 eh->plt_thumb_refcount--; 7492 } 7493 7494 if (r_type == R_ARM_ABS32 7495 || r_type == R_ARM_REL32 7496 || r_type == R_ARM_ABS32_NOI 7497 || r_type == R_ARM_REL32_NOI) 7498 { 7499 for (pp = &eh->relocs_copied; (p = *pp) != NULL; 7500 pp = &p->next) 7501 if (p->section == sec) 7502 { 7503 p->count -= 1; 7504 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32 7505 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI) 7506 p->pc_count -= 1; 7507 if (p->count == 0) 7508 *pp = p->next; 7509 break; 7510 } 7511 } 7512 } 7513 break; 7514 7515 default: 7516 break; 7517 } 7518 } 7519 7520 return TRUE; 7521} 7522 7523/* Look through the relocs for a section during the first phase. */ 7524 7525static bfd_boolean 7526elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info, 7527 asection *sec, const Elf_Internal_Rela *relocs) 7528{ 7529 Elf_Internal_Shdr *symtab_hdr; 7530 struct elf_link_hash_entry **sym_hashes; 7531 struct elf_link_hash_entry **sym_hashes_end; 7532 const Elf_Internal_Rela *rel; 7533 const Elf_Internal_Rela *rel_end; 7534 bfd *dynobj; 7535 asection *sreloc; 7536 bfd_vma *local_got_offsets; 7537 struct elf32_arm_link_hash_table *htab; 7538 7539 if (info->relocatable) 7540 return TRUE; 7541 7542 htab = elf32_arm_hash_table (info); 7543 sreloc = NULL; 7544 7545 /* Create dynamic sections for relocatable executables so that we can 7546 copy relocations. */ 7547 if (htab->root.is_relocatable_executable 7548 && ! htab->root.dynamic_sections_created) 7549 { 7550 if (! _bfd_elf_link_create_dynamic_sections (abfd, info)) 7551 return FALSE; 7552 } 7553 7554 dynobj = elf_hash_table (info)->dynobj; 7555 local_got_offsets = elf_local_got_offsets (abfd); 7556 7557 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 7558 sym_hashes = elf_sym_hashes (abfd); 7559 sym_hashes_end = sym_hashes 7560 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); 7561 7562 if (!elf_bad_symtab (abfd)) 7563 sym_hashes_end -= symtab_hdr->sh_info; 7564 7565 rel_end = relocs + sec->reloc_count; 7566 for (rel = relocs; rel < rel_end; rel++) 7567 { 7568 struct elf_link_hash_entry *h; 7569 struct elf32_arm_link_hash_entry *eh; 7570 unsigned long r_symndx; 7571 int r_type; 7572 7573 r_symndx = ELF32_R_SYM (rel->r_info); 7574 r_type = ELF32_R_TYPE (rel->r_info); 7575 r_type = arm_real_reloc_type (htab, r_type); 7576 7577 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) 7578 { 7579 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd, 7580 r_symndx); 7581 return FALSE; 7582 } 7583 7584 if (r_symndx < symtab_hdr->sh_info) 7585 h = NULL; 7586 else 7587 { 7588 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 7589 while (h->root.type == bfd_link_hash_indirect 7590 || h->root.type == bfd_link_hash_warning) 7591 h = (struct elf_link_hash_entry *) h->root.u.i.link; 7592 } 7593 7594 eh = (struct elf32_arm_link_hash_entry *) h; 7595 7596 switch (r_type) 7597 { 7598 case R_ARM_GOT32: 7599 case R_ARM_GOT_PREL: 7600 case R_ARM_TLS_GD32: 7601 case R_ARM_TLS_IE32: 7602 /* This symbol requires a global offset table entry. */ 7603 { 7604 int tls_type, old_tls_type; 7605 7606 switch (r_type) 7607 { 7608 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break; 7609 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break; 7610 default: tls_type = GOT_NORMAL; break; 7611 } 7612 7613 if (h != NULL) 7614 { 7615 h->got.refcount++; 7616 old_tls_type = elf32_arm_hash_entry (h)->tls_type; 7617 } 7618 else 7619 { 7620 bfd_signed_vma *local_got_refcounts; 7621 7622 /* This is a global offset table entry for a local symbol. */ 7623 local_got_refcounts = elf_local_got_refcounts (abfd); 7624 if (local_got_refcounts == NULL) 7625 { 7626 bfd_size_type size; 7627 7628 size = symtab_hdr->sh_info; 7629 size *= (sizeof (bfd_signed_vma) + sizeof(char)); 7630 local_got_refcounts = bfd_zalloc (abfd, size); 7631 if (local_got_refcounts == NULL) 7632 return FALSE; 7633 elf_local_got_refcounts (abfd) = local_got_refcounts; 7634 elf32_arm_local_got_tls_type (abfd) 7635 = (char *) (local_got_refcounts + symtab_hdr->sh_info); 7636 } 7637 local_got_refcounts[r_symndx] += 1; 7638 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx]; 7639 } 7640 7641 /* We will already have issued an error message if there is a 7642 TLS / non-TLS mismatch, based on the symbol type. We don't 7643 support any linker relaxations. So just combine any TLS 7644 types needed. */ 7645 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL 7646 && tls_type != GOT_NORMAL) 7647 tls_type |= old_tls_type; 7648 7649 if (old_tls_type != tls_type) 7650 { 7651 if (h != NULL) 7652 elf32_arm_hash_entry (h)->tls_type = tls_type; 7653 else 7654 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type; 7655 } 7656 } 7657 /* Fall through */ 7658 7659 case R_ARM_TLS_LDM32: 7660 if (r_type == R_ARM_TLS_LDM32) 7661 htab->tls_ldm_got.refcount++; 7662 /* Fall through */ 7663 7664 case R_ARM_GOTOFF32: 7665 case R_ARM_GOTPC: 7666 if (htab->sgot == NULL) 7667 { 7668 if (htab->root.dynobj == NULL) 7669 htab->root.dynobj = abfd; 7670 if (!create_got_section (htab->root.dynobj, info)) 7671 return FALSE; 7672 } 7673 break; 7674 7675 case R_ARM_ABS12: 7676 /* VxWorks uses dynamic R_ARM_ABS12 relocations for 7677 ldr __GOTT_INDEX__ offsets. */ 7678 if (!htab->vxworks_p) 7679 break; 7680 /* Fall through */ 7681 7682 case R_ARM_ABS32: 7683 case R_ARM_ABS32_NOI: 7684 case R_ARM_REL32: 7685 case R_ARM_REL32_NOI: 7686 case R_ARM_PC24: 7687 case R_ARM_PLT32: 7688 case R_ARM_CALL: 7689 case R_ARM_JUMP24: 7690 case R_ARM_PREL31: 7691 case R_ARM_THM_CALL: 7692 case R_ARM_MOVW_ABS_NC: 7693 case R_ARM_MOVT_ABS: 7694 case R_ARM_MOVW_PREL_NC: 7695 case R_ARM_MOVT_PREL: 7696 case R_ARM_THM_MOVW_ABS_NC: 7697 case R_ARM_THM_MOVT_ABS: 7698 case R_ARM_THM_MOVW_PREL_NC: 7699 case R_ARM_THM_MOVT_PREL: 7700 /* Should the interworking branches be listed here? */ 7701 if (h != NULL) 7702 { 7703 /* If this reloc is in a read-only section, we might 7704 need a copy reloc. We can't check reliably at this 7705 stage whether the section is read-only, as input 7706 sections have not yet been mapped to output sections. 7707 Tentatively set the flag for now, and correct in 7708 adjust_dynamic_symbol. */ 7709 if (!info->shared) 7710 h->non_got_ref = 1; 7711 7712 /* We may need a .plt entry if the function this reloc 7713 refers to is in a different object. We can't tell for 7714 sure yet, because something later might force the 7715 symbol local. */ 7716 switch (r_type) 7717 { 7718 case R_ARM_ABS12: 7719 case R_ARM_ABS32: 7720 case R_ARM_ABS32_NOI: 7721 case R_ARM_REL32: 7722 case R_ARM_REL32_NOI: 7723 case R_ARM_MOVW_ABS_NC: 7724 case R_ARM_MOVT_ABS: 7725 case R_ARM_MOVW_PREL_NC: 7726 case R_ARM_MOVT_PREL: 7727 case R_ARM_THM_MOVW_ABS_NC: 7728 case R_ARM_THM_MOVT_ABS: 7729 case R_ARM_THM_MOVW_PREL_NC: 7730 case R_ARM_THM_MOVT_PREL: 7731 break; 7732 default: 7733 h->needs_plt = 1; 7734 break; 7735 } 7736 7737 /* If we create a PLT entry, this relocation will reference 7738 it, even if it's an ABS32 relocation. */ 7739 h->plt.refcount += 1; 7740 7741 if (r_type == R_ARM_THM_CALL) 7742 eh->plt_thumb_refcount += 1; 7743 } 7744 7745 /* If we are creating a shared library or relocatable executable, 7746 and this is a reloc against a global symbol, or a non PC 7747 relative reloc against a local symbol, then we need to copy 7748 the reloc into the shared library. However, if we are linking 7749 with -Bsymbolic, we do not need to copy a reloc against a 7750 global symbol which is defined in an object we are 7751 including in the link (i.e., DEF_REGULAR is set). At 7752 this point we have not seen all the input files, so it is 7753 possible that DEF_REGULAR is not set now but will be set 7754 later (it is never cleared). We account for that 7755 possibility below by storing information in the 7756 relocs_copied field of the hash table entry. */ 7757 if ((info->shared || htab->root.is_relocatable_executable) 7758 && (sec->flags & SEC_ALLOC) != 0 7759 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI) 7760 || (h != NULL && ! h->needs_plt 7761 && (! info->symbolic || ! h->def_regular)))) 7762 { 7763 struct elf32_arm_relocs_copied *p, **head; 7764 7765 /* When creating a shared object, we must copy these 7766 reloc types into the output file. We create a reloc 7767 section in dynobj and make room for this reloc. */ 7768 if (sreloc == NULL) 7769 { 7770 const char * name; 7771 7772 name = (bfd_elf_string_from_elf_section 7773 (abfd, 7774 elf_elfheader (abfd)->e_shstrndx, 7775 elf_section_data (sec)->rel_hdr.sh_name)); 7776 if (name == NULL) 7777 return FALSE; 7778 7779 BFD_ASSERT (reloc_section_p (htab, name, sec)); 7780 7781 sreloc = bfd_get_section_by_name (dynobj, name); 7782 if (sreloc == NULL) 7783 { 7784 flagword flags; 7785 7786 flags = (SEC_HAS_CONTENTS | SEC_READONLY 7787 | SEC_IN_MEMORY | SEC_LINKER_CREATED); 7788 if ((sec->flags & SEC_ALLOC) != 0 7789 /* BPABI objects never have dynamic 7790 relocations mapped. */ 7791 && !htab->symbian_p) 7792 flags |= SEC_ALLOC | SEC_LOAD; 7793 sreloc = bfd_make_section_with_flags (dynobj, 7794 name, 7795 flags); 7796 if (sreloc == NULL 7797 || ! bfd_set_section_alignment (dynobj, sreloc, 2)) 7798 return FALSE; 7799 } 7800 7801 elf_section_data (sec)->sreloc = sreloc; 7802 } 7803 7804 /* If this is a global symbol, we count the number of 7805 relocations we need for this symbol. */ 7806 if (h != NULL) 7807 { 7808 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied; 7809 } 7810 else 7811 { 7812 /* Track dynamic relocs needed for local syms too. 7813 We really need local syms available to do this 7814 easily. Oh well. */ 7815 7816 asection *s; 7817 void *vpp; 7818 7819 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, 7820 sec, r_symndx); 7821 if (s == NULL) 7822 return FALSE; 7823 7824 vpp = &elf_section_data (s)->local_dynrel; 7825 head = (struct elf32_arm_relocs_copied **) vpp; 7826 } 7827 7828 p = *head; 7829 if (p == NULL || p->section != sec) 7830 { 7831 bfd_size_type amt = sizeof *p; 7832 7833 p = bfd_alloc (htab->root.dynobj, amt); 7834 if (p == NULL) 7835 return FALSE; 7836 p->next = *head; 7837 *head = p; 7838 p->section = sec; 7839 p->count = 0; 7840 p->pc_count = 0; 7841 } 7842 7843 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI) 7844 p->pc_count += 1; 7845 p->count += 1; 7846 } 7847 break; 7848 7849 /* This relocation describes the C++ object vtable hierarchy. 7850 Reconstruct it for later use during GC. */ 7851 case R_ARM_GNU_VTINHERIT: 7852 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 7853 return FALSE; 7854 break; 7855 7856 /* This relocation describes which C++ vtable entries are actually 7857 used. Record for later use during GC. */ 7858 case R_ARM_GNU_VTENTRY: 7859 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) 7860 return FALSE; 7861 break; 7862 } 7863 } 7864 7865 return TRUE; 7866} 7867 7868/* Unwinding tables are not referenced directly. This pass marks them as 7869 required if the corresponding code section is marked. */ 7870 7871static bfd_boolean 7872elf32_arm_gc_mark_extra_sections(struct bfd_link_info *info, 7873 elf_gc_mark_hook_fn gc_mark_hook) 7874{ 7875 bfd *sub; 7876 Elf_Internal_Shdr **elf_shdrp; 7877 bfd_boolean again; 7878 7879 /* Marking EH data may cause additional code sections to be marked, 7880 requiring multiple passes. */ 7881 again = TRUE; 7882 while (again) 7883 { 7884 again = FALSE; 7885 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) 7886 { 7887 asection *o; 7888 7889 if (bfd_get_flavour (sub) != bfd_target_elf_flavour) 7890 continue; 7891 7892 elf_shdrp = elf_elfsections (sub); 7893 for (o = sub->sections; o != NULL; o = o->next) 7894 { 7895 Elf_Internal_Shdr *hdr; 7896 hdr = &elf_section_data (o)->this_hdr; 7897 if (hdr->sh_type == SHT_ARM_EXIDX && hdr->sh_link 7898 && !o->gc_mark 7899 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark) 7900 { 7901 again = TRUE; 7902 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook)) 7903 return FALSE; 7904 } 7905 } 7906 } 7907 } 7908 7909 return TRUE; 7910} 7911 7912/* Treat mapping symbols as special target symbols. */ 7913 7914static bfd_boolean 7915elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym) 7916{ 7917 return bfd_is_arm_special_symbol_name (sym->name, 7918 BFD_ARM_SPECIAL_SYM_TYPE_ANY); 7919} 7920 7921/* This is a copy of elf_find_function() from elf.c except that 7922 ARM mapping symbols are ignored when looking for function names 7923 and STT_ARM_TFUNC is considered to a function type. */ 7924 7925static bfd_boolean 7926arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED, 7927 asection * section, 7928 asymbol ** symbols, 7929 bfd_vma offset, 7930 const char ** filename_ptr, 7931 const char ** functionname_ptr) 7932{ 7933 const char * filename = NULL; 7934 asymbol * func = NULL; 7935 bfd_vma low_func = 0; 7936 asymbol ** p; 7937 7938 for (p = symbols; *p != NULL; p++) 7939 { 7940 elf_symbol_type *q; 7941 7942 q = (elf_symbol_type *) *p; 7943 7944 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info)) 7945 { 7946 default: 7947 break; 7948 case STT_FILE: 7949 filename = bfd_asymbol_name (&q->symbol); 7950 break; 7951 case STT_FUNC: 7952 case STT_ARM_TFUNC: 7953 case STT_NOTYPE: 7954 /* Skip mapping symbols. */ 7955 if ((q->symbol.flags & BSF_LOCAL) 7956 && bfd_is_arm_special_symbol_name (q->symbol.name, 7957 BFD_ARM_SPECIAL_SYM_TYPE_ANY)) 7958 continue; 7959 /* Fall through. */ 7960 if (bfd_get_section (&q->symbol) == section 7961 && q->symbol.value >= low_func 7962 && q->symbol.value <= offset) 7963 { 7964 func = (asymbol *) q; 7965 low_func = q->symbol.value; 7966 } 7967 break; 7968 } 7969 } 7970 7971 if (func == NULL) 7972 return FALSE; 7973 7974 if (filename_ptr) 7975 *filename_ptr = filename; 7976 if (functionname_ptr) 7977 *functionname_ptr = bfd_asymbol_name (func); 7978 7979 return TRUE; 7980} 7981 7982 7983/* Find the nearest line to a particular section and offset, for error 7984 reporting. This code is a duplicate of the code in elf.c, except 7985 that it uses arm_elf_find_function. */ 7986 7987static bfd_boolean 7988elf32_arm_find_nearest_line (bfd * abfd, 7989 asection * section, 7990 asymbol ** symbols, 7991 bfd_vma offset, 7992 const char ** filename_ptr, 7993 const char ** functionname_ptr, 7994 unsigned int * line_ptr) 7995{ 7996 bfd_boolean found = FALSE; 7997 7998 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */ 7999 8000 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, 8001 filename_ptr, functionname_ptr, 8002 line_ptr, 0, 8003 & elf_tdata (abfd)->dwarf2_find_line_info)) 8004 { 8005 if (!*functionname_ptr) 8006 arm_elf_find_function (abfd, section, symbols, offset, 8007 *filename_ptr ? NULL : filename_ptr, 8008 functionname_ptr); 8009 8010 return TRUE; 8011 } 8012 8013 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, 8014 & found, filename_ptr, 8015 functionname_ptr, line_ptr, 8016 & elf_tdata (abfd)->line_info)) 8017 return FALSE; 8018 8019 if (found && (*functionname_ptr || *line_ptr)) 8020 return TRUE; 8021 8022 if (symbols == NULL) 8023 return FALSE; 8024 8025 if (! arm_elf_find_function (abfd, section, symbols, offset, 8026 filename_ptr, functionname_ptr)) 8027 return FALSE; 8028 8029 *line_ptr = 0; 8030 return TRUE; 8031} 8032 8033static bfd_boolean 8034elf32_arm_find_inliner_info (bfd * abfd, 8035 const char ** filename_ptr, 8036 const char ** functionname_ptr, 8037 unsigned int * line_ptr) 8038{ 8039 bfd_boolean found; 8040 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr, 8041 functionname_ptr, line_ptr, 8042 & elf_tdata (abfd)->dwarf2_find_line_info); 8043 return found; 8044} 8045 8046/* Adjust a symbol defined by a dynamic object and referenced by a 8047 regular object. The current definition is in some section of the 8048 dynamic object, but we're not including those sections. We have to 8049 change the definition to something the rest of the link can 8050 understand. */ 8051 8052static bfd_boolean 8053elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, 8054 struct elf_link_hash_entry * h) 8055{ 8056 bfd * dynobj; 8057 asection * s; 8058 struct elf32_arm_link_hash_entry * eh; 8059 struct elf32_arm_link_hash_table *globals; 8060 8061 globals = elf32_arm_hash_table (info); 8062 dynobj = elf_hash_table (info)->dynobj; 8063 8064 /* Make sure we know what is going on here. */ 8065 BFD_ASSERT (dynobj != NULL 8066 && (h->needs_plt 8067 || h->u.weakdef != NULL 8068 || (h->def_dynamic 8069 && h->ref_regular 8070 && !h->def_regular))); 8071 8072 eh = (struct elf32_arm_link_hash_entry *) h; 8073 8074 /* If this is a function, put it in the procedure linkage table. We 8075 will fill in the contents of the procedure linkage table later, 8076 when we know the address of the .got section. */ 8077 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC 8078 || h->needs_plt) 8079 { 8080 if (h->plt.refcount <= 0 8081 || SYMBOL_CALLS_LOCAL (info, h) 8082 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 8083 && h->root.type == bfd_link_hash_undefweak)) 8084 { 8085 /* This case can occur if we saw a PLT32 reloc in an input 8086 file, but the symbol was never referred to by a dynamic 8087 object, or if all references were garbage collected. In 8088 such a case, we don't actually need to build a procedure 8089 linkage table, and we can just do a PC24 reloc instead. */ 8090 h->plt.offset = (bfd_vma) -1; 8091 eh->plt_thumb_refcount = 0; 8092 h->needs_plt = 0; 8093 } 8094 8095 return TRUE; 8096 } 8097 else 8098 { 8099 /* It's possible that we incorrectly decided a .plt reloc was 8100 needed for an R_ARM_PC24 or similar reloc to a non-function sym 8101 in check_relocs. We can't decide accurately between function 8102 and non-function syms in check-relocs; Objects loaded later in 8103 the link may change h->type. So fix it now. */ 8104 h->plt.offset = (bfd_vma) -1; 8105 eh->plt_thumb_refcount = 0; 8106 } 8107 8108 /* If this is a weak symbol, and there is a real definition, the 8109 processor independent code will have arranged for us to see the 8110 real definition first, and we can just use the same value. */ 8111 if (h->u.weakdef != NULL) 8112 { 8113 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined 8114 || h->u.weakdef->root.type == bfd_link_hash_defweak); 8115 h->root.u.def.section = h->u.weakdef->root.u.def.section; 8116 h->root.u.def.value = h->u.weakdef->root.u.def.value; 8117 return TRUE; 8118 } 8119 8120 /* If there are no non-GOT references, we do not need a copy 8121 relocation. */ 8122 if (!h->non_got_ref) 8123 return TRUE; 8124 8125 /* This is a reference to a symbol defined by a dynamic object which 8126 is not a function. */ 8127 8128 /* If we are creating a shared library, we must presume that the 8129 only references to the symbol are via the global offset table. 8130 For such cases we need not do anything here; the relocations will 8131 be handled correctly by relocate_section. Relocatable executables 8132 can reference data in shared objects directly, so we don't need to 8133 do anything here. */ 8134 if (info->shared || globals->root.is_relocatable_executable) 8135 return TRUE; 8136 8137 if (h->size == 0) 8138 { 8139 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), 8140 h->root.root.string); 8141 return TRUE; 8142 } 8143 8144 /* We must allocate the symbol in our .dynbss section, which will 8145 become part of the .bss section of the executable. There will be 8146 an entry for this symbol in the .dynsym section. The dynamic 8147 object will contain position independent code, so all references 8148 from the dynamic object to this symbol will go through the global 8149 offset table. The dynamic linker will use the .dynsym entry to 8150 determine the address it must put in the global offset table, so 8151 both the dynamic object and the regular object will refer to the 8152 same memory location for the variable. */ 8153 s = bfd_get_section_by_name (dynobj, ".dynbss"); 8154 BFD_ASSERT (s != NULL); 8155 8156 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to 8157 copy the initial value out of the dynamic object and into the 8158 runtime process image. We need to remember the offset into the 8159 .rel(a).bss section we are going to use. */ 8160 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) 8161 { 8162 asection *srel; 8163 8164 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss")); 8165 BFD_ASSERT (srel != NULL); 8166 srel->size += RELOC_SIZE (globals); 8167 h->needs_copy = 1; 8168 } 8169 8170 return _bfd_elf_adjust_dynamic_copy (h, s); 8171} 8172 8173/* Allocate space in .plt, .got and associated reloc sections for 8174 dynamic relocs. */ 8175 8176static bfd_boolean 8177allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) 8178{ 8179 struct bfd_link_info *info; 8180 struct elf32_arm_link_hash_table *htab; 8181 struct elf32_arm_link_hash_entry *eh; 8182 struct elf32_arm_relocs_copied *p; 8183 8184 eh = (struct elf32_arm_link_hash_entry *) h; 8185 8186 if (h->root.type == bfd_link_hash_indirect) 8187 return TRUE; 8188 8189 if (h->root.type == bfd_link_hash_warning) 8190 /* When warning symbols are created, they **replace** the "real" 8191 entry in the hash table, thus we never get to see the real 8192 symbol in a hash traversal. So look at it now. */ 8193 h = (struct elf_link_hash_entry *) h->root.u.i.link; 8194 8195 info = (struct bfd_link_info *) inf; 8196 htab = elf32_arm_hash_table (info); 8197 8198 if (htab->root.dynamic_sections_created 8199 && h->plt.refcount > 0) 8200 { 8201 /* Make sure this symbol is output as a dynamic symbol. 8202 Undefined weak syms won't yet be marked as dynamic. */ 8203 if (h->dynindx == -1 8204 && !h->forced_local) 8205 { 8206 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 8207 return FALSE; 8208 } 8209 8210 if (info->shared 8211 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) 8212 { 8213 asection *s = htab->splt; 8214 8215 /* If this is the first .plt entry, make room for the special 8216 first entry. */ 8217 if (s->size == 0) 8218 s->size += htab->plt_header_size; 8219 8220 h->plt.offset = s->size; 8221 8222 /* If we will insert a Thumb trampoline before this PLT, leave room 8223 for it. */ 8224 if (!htab->use_blx && eh->plt_thumb_refcount > 0) 8225 { 8226 h->plt.offset += PLT_THUMB_STUB_SIZE; 8227 s->size += PLT_THUMB_STUB_SIZE; 8228 } 8229 8230 /* If this symbol is not defined in a regular file, and we are 8231 not generating a shared library, then set the symbol to this 8232 location in the .plt. This is required to make function 8233 pointers compare as equal between the normal executable and 8234 the shared library. */ 8235 if (! info->shared 8236 && !h->def_regular) 8237 { 8238 h->root.u.def.section = s; 8239 h->root.u.def.value = h->plt.offset; 8240 8241 /* Make sure the function is not marked as Thumb, in case 8242 it is the target of an ABS32 relocation, which will 8243 point to the PLT entry. */ 8244 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC) 8245 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); 8246 } 8247 8248 /* Make room for this entry. */ 8249 s->size += htab->plt_entry_size; 8250 8251 if (!htab->symbian_p) 8252 { 8253 /* We also need to make an entry in the .got.plt section, which 8254 will be placed in the .got section by the linker script. */ 8255 eh->plt_got_offset = htab->sgotplt->size; 8256 htab->sgotplt->size += 4; 8257 } 8258 8259 /* We also need to make an entry in the .rel(a).plt section. */ 8260 htab->srelplt->size += RELOC_SIZE (htab); 8261 8262 /* VxWorks executables have a second set of relocations for 8263 each PLT entry. They go in a separate relocation section, 8264 which is processed by the kernel loader. */ 8265 if (htab->vxworks_p && !info->shared) 8266 { 8267 /* There is a relocation for the initial PLT entry: 8268 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */ 8269 if (h->plt.offset == htab->plt_header_size) 8270 htab->srelplt2->size += RELOC_SIZE (htab); 8271 8272 /* There are two extra relocations for each subsequent 8273 PLT entry: an R_ARM_32 relocation for the GOT entry, 8274 and an R_ARM_32 relocation for the PLT entry. */ 8275 htab->srelplt2->size += RELOC_SIZE (htab) * 2; 8276 } 8277 } 8278 else 8279 { 8280 h->plt.offset = (bfd_vma) -1; 8281 h->needs_plt = 0; 8282 } 8283 } 8284 else 8285 { 8286 h->plt.offset = (bfd_vma) -1; 8287 h->needs_plt = 0; 8288 } 8289 8290 if (h->got.refcount > 0) 8291 { 8292 asection *s; 8293 bfd_boolean dyn; 8294 int tls_type = elf32_arm_hash_entry (h)->tls_type; 8295 int indx; 8296 8297 /* Make sure this symbol is output as a dynamic symbol. 8298 Undefined weak syms won't yet be marked as dynamic. */ 8299 if (h->dynindx == -1 8300 && !h->forced_local) 8301 { 8302 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 8303 return FALSE; 8304 } 8305 8306 if (!htab->symbian_p) 8307 { 8308 s = htab->sgot; 8309 h->got.offset = s->size; 8310 8311 if (tls_type == GOT_UNKNOWN) 8312 abort (); 8313 8314 if (tls_type == GOT_NORMAL) 8315 /* Non-TLS symbols need one GOT slot. */ 8316 s->size += 4; 8317 else 8318 { 8319 if (tls_type & GOT_TLS_GD) 8320 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */ 8321 s->size += 8; 8322 if (tls_type & GOT_TLS_IE) 8323 /* R_ARM_TLS_IE32 needs one GOT slot. */ 8324 s->size += 4; 8325 } 8326 8327 dyn = htab->root.dynamic_sections_created; 8328 8329 indx = 0; 8330 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) 8331 && (!info->shared 8332 || !SYMBOL_REFERENCES_LOCAL (info, h))) 8333 indx = h->dynindx; 8334 8335 if (tls_type != GOT_NORMAL 8336 && (info->shared || indx != 0) 8337 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT 8338 || h->root.type != bfd_link_hash_undefweak)) 8339 { 8340 if (tls_type & GOT_TLS_IE) 8341 htab->srelgot->size += RELOC_SIZE (htab); 8342 8343 if (tls_type & GOT_TLS_GD) 8344 htab->srelgot->size += RELOC_SIZE (htab); 8345 8346 if ((tls_type & GOT_TLS_GD) && indx != 0) 8347 htab->srelgot->size += RELOC_SIZE (htab); 8348 } 8349 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT 8350 || h->root.type != bfd_link_hash_undefweak) 8351 && (info->shared 8352 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) 8353 htab->srelgot->size += RELOC_SIZE (htab); 8354 } 8355 } 8356 else 8357 h->got.offset = (bfd_vma) -1; 8358 8359 /* Allocate stubs for exported Thumb functions on v4t. */ 8360 if (!htab->use_blx && h->dynindx != -1 8361 && h->def_regular 8362 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC 8363 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) 8364 { 8365 struct elf_link_hash_entry * th; 8366 struct bfd_link_hash_entry * bh; 8367 struct elf_link_hash_entry * myh; 8368 char name[1024]; 8369 asection *s; 8370 bh = NULL; 8371 /* Create a new symbol to regist the real location of the function. */ 8372 s = h->root.u.def.section; 8373 sprintf(name, "__real_%s", h->root.root.string); 8374 _bfd_generic_link_add_one_symbol (info, s->owner, 8375 name, BSF_GLOBAL, s, 8376 h->root.u.def.value, 8377 NULL, TRUE, FALSE, &bh); 8378 8379 myh = (struct elf_link_hash_entry *) bh; 8380 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC); 8381 myh->forced_local = 1; 8382 eh->export_glue = myh; 8383 th = record_arm_to_thumb_glue (info, h); 8384 /* Point the symbol at the stub. */ 8385 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); 8386 h->root.u.def.section = th->root.u.def.section; 8387 h->root.u.def.value = th->root.u.def.value & ~1; 8388 } 8389 8390 if (eh->relocs_copied == NULL) 8391 return TRUE; 8392 8393 /* In the shared -Bsymbolic case, discard space allocated for 8394 dynamic pc-relative relocs against symbols which turn out to be 8395 defined in regular objects. For the normal shared case, discard 8396 space for pc-relative relocs that have become local due to symbol 8397 visibility changes. */ 8398 8399 if (info->shared || htab->root.is_relocatable_executable) 8400 { 8401 /* The only relocs that use pc_count are R_ARM_REL32 and 8402 R_ARM_REL32_NOI, which will appear on something like 8403 ".long foo - .". We want calls to protected symbols to resolve 8404 directly to the function rather than going via the plt. If people 8405 want function pointer comparisons to work as expected then they 8406 should avoid writing assembly like ".long foo - .". */ 8407 if (SYMBOL_CALLS_LOCAL (info, h)) 8408 { 8409 struct elf32_arm_relocs_copied **pp; 8410 8411 for (pp = &eh->relocs_copied; (p = *pp) != NULL; ) 8412 { 8413 p->count -= p->pc_count; 8414 p->pc_count = 0; 8415 if (p->count == 0) 8416 *pp = p->next; 8417 else 8418 pp = &p->next; 8419 } 8420 } 8421 8422 /* Also discard relocs on undefined weak syms with non-default 8423 visibility. */ 8424 if (eh->relocs_copied != NULL 8425 && h->root.type == bfd_link_hash_undefweak) 8426 { 8427 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) 8428 eh->relocs_copied = NULL; 8429 8430 /* Make sure undefined weak symbols are output as a dynamic 8431 symbol in PIEs. */ 8432 else if (h->dynindx == -1 8433 && !h->forced_local) 8434 { 8435 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 8436 return FALSE; 8437 } 8438 } 8439 8440 else if (htab->root.is_relocatable_executable && h->dynindx == -1 8441 && h->root.type == bfd_link_hash_new) 8442 { 8443 /* Output absolute symbols so that we can create relocations 8444 against them. For normal symbols we output a relocation 8445 against the section that contains them. */ 8446 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 8447 return FALSE; 8448 } 8449 8450 } 8451 else 8452 { 8453 /* For the non-shared case, discard space for relocs against 8454 symbols which turn out to need copy relocs or are not 8455 dynamic. */ 8456 8457 if (!h->non_got_ref 8458 && ((h->def_dynamic 8459 && !h->def_regular) 8460 || (htab->root.dynamic_sections_created 8461 && (h->root.type == bfd_link_hash_undefweak 8462 || h->root.type == bfd_link_hash_undefined)))) 8463 { 8464 /* Make sure this symbol is output as a dynamic symbol. 8465 Undefined weak syms won't yet be marked as dynamic. */ 8466 if (h->dynindx == -1 8467 && !h->forced_local) 8468 { 8469 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 8470 return FALSE; 8471 } 8472 8473 /* If that succeeded, we know we'll be keeping all the 8474 relocs. */ 8475 if (h->dynindx != -1) 8476 goto keep; 8477 } 8478 8479 eh->relocs_copied = NULL; 8480 8481 keep: ; 8482 } 8483 8484 /* Finally, allocate space. */ 8485 for (p = eh->relocs_copied; p != NULL; p = p->next) 8486 { 8487 asection *sreloc = elf_section_data (p->section)->sreloc; 8488 sreloc->size += p->count * RELOC_SIZE (htab); 8489 } 8490 8491 return TRUE; 8492} 8493 8494/* Find any dynamic relocs that apply to read-only sections. */ 8495 8496static bfd_boolean 8497elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf) 8498{ 8499 struct elf32_arm_link_hash_entry *eh; 8500 struct elf32_arm_relocs_copied *p; 8501 8502 if (h->root.type == bfd_link_hash_warning) 8503 h = (struct elf_link_hash_entry *) h->root.u.i.link; 8504 8505 eh = (struct elf32_arm_link_hash_entry *) h; 8506 for (p = eh->relocs_copied; p != NULL; p = p->next) 8507 { 8508 asection *s = p->section; 8509 8510 if (s != NULL && (s->flags & SEC_READONLY) != 0) 8511 { 8512 struct bfd_link_info *info = (struct bfd_link_info *) inf; 8513 8514 info->flags |= DF_TEXTREL; 8515 8516 /* Not an error, just cut short the traversal. */ 8517 return FALSE; 8518 } 8519 } 8520 return TRUE; 8521} 8522 8523void 8524bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info, 8525 int byteswap_code) 8526{ 8527 struct elf32_arm_link_hash_table *globals; 8528 8529 globals = elf32_arm_hash_table (info); 8530 globals->byteswap_code = byteswap_code; 8531} 8532 8533/* Set the sizes of the dynamic sections. */ 8534 8535static bfd_boolean 8536elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, 8537 struct bfd_link_info * info) 8538{ 8539 bfd * dynobj; 8540 asection * s; 8541 bfd_boolean plt; 8542 bfd_boolean relocs; 8543 bfd *ibfd; 8544 struct elf32_arm_link_hash_table *htab; 8545 8546 htab = elf32_arm_hash_table (info); 8547 dynobj = elf_hash_table (info)->dynobj; 8548 BFD_ASSERT (dynobj != NULL); 8549 check_use_blx (htab); 8550 8551 if (elf_hash_table (info)->dynamic_sections_created) 8552 { 8553 /* Set the contents of the .interp section to the interpreter. */ 8554 if (info->executable) 8555 { 8556 s = bfd_get_section_by_name (dynobj, ".interp"); 8557 BFD_ASSERT (s != NULL); 8558 s->size = sizeof ELF_DYNAMIC_INTERPRETER; 8559 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; 8560 } 8561 } 8562 8563 /* Set up .got offsets for local syms, and space for local dynamic 8564 relocs. */ 8565 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) 8566 { 8567 bfd_signed_vma *local_got; 8568 bfd_signed_vma *end_local_got; 8569 char *local_tls_type; 8570 bfd_size_type locsymcount; 8571 Elf_Internal_Shdr *symtab_hdr; 8572 asection *srel; 8573 8574 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) 8575 continue; 8576 8577 for (s = ibfd->sections; s != NULL; s = s->next) 8578 { 8579 struct elf32_arm_relocs_copied *p; 8580 8581 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) 8582 { 8583 if (!bfd_is_abs_section (p->section) 8584 && bfd_is_abs_section (p->section->output_section)) 8585 { 8586 /* Input section has been discarded, either because 8587 it is a copy of a linkonce section or due to 8588 linker script /DISCARD/, so we'll be discarding 8589 the relocs too. */ 8590 } 8591 else if (p->count != 0) 8592 { 8593 srel = elf_section_data (p->section)->sreloc; 8594 srel->size += p->count * RELOC_SIZE (htab); 8595 if ((p->section->output_section->flags & SEC_READONLY) != 0) 8596 info->flags |= DF_TEXTREL; 8597 } 8598 } 8599 } 8600 8601 local_got = elf_local_got_refcounts (ibfd); 8602 if (!local_got) 8603 continue; 8604 8605 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; 8606 locsymcount = symtab_hdr->sh_info; 8607 end_local_got = local_got + locsymcount; 8608 local_tls_type = elf32_arm_local_got_tls_type (ibfd); 8609 s = htab->sgot; 8610 srel = htab->srelgot; 8611 for (; local_got < end_local_got; ++local_got, ++local_tls_type) 8612 { 8613 if (*local_got > 0) 8614 { 8615 *local_got = s->size; 8616 if (*local_tls_type & GOT_TLS_GD) 8617 /* TLS_GD relocs need an 8-byte structure in the GOT. */ 8618 s->size += 8; 8619 if (*local_tls_type & GOT_TLS_IE) 8620 s->size += 4; 8621 if (*local_tls_type == GOT_NORMAL) 8622 s->size += 4; 8623 8624 if (info->shared || *local_tls_type == GOT_TLS_GD) 8625 srel->size += RELOC_SIZE (htab); 8626 } 8627 else 8628 *local_got = (bfd_vma) -1; 8629 } 8630 } 8631 8632 if (htab->tls_ldm_got.refcount > 0) 8633 { 8634 /* Allocate two GOT entries and one dynamic relocation (if necessary) 8635 for R_ARM_TLS_LDM32 relocations. */ 8636 htab->tls_ldm_got.offset = htab->sgot->size; 8637 htab->sgot->size += 8; 8638 if (info->shared) 8639 htab->srelgot->size += RELOC_SIZE (htab); 8640 } 8641 else 8642 htab->tls_ldm_got.offset = -1; 8643 8644 /* Allocate global sym .plt and .got entries, and space for global 8645 sym dynamic relocs. */ 8646 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info); 8647 8648 /* Here we rummage through the found bfds to collect glue information. */ 8649 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) 8650 { 8651 /* Initialise mapping tables for code/data. */ 8652 bfd_elf32_arm_init_maps (ibfd); 8653 8654 if (!bfd_elf32_arm_process_before_allocation (ibfd, info) 8655 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info)) 8656 /* xgettext:c-format */ 8657 _bfd_error_handler (_("Errors encountered processing file %s"), 8658 ibfd->filename); 8659 } 8660 8661 /* The check_relocs and adjust_dynamic_symbol entry points have 8662 determined the sizes of the various dynamic sections. Allocate 8663 memory for them. */ 8664 plt = FALSE; 8665 relocs = FALSE; 8666 for (s = dynobj->sections; s != NULL; s = s->next) 8667 { 8668 const char * name; 8669 8670 if ((s->flags & SEC_LINKER_CREATED) == 0) 8671 continue; 8672 8673 /* It's OK to base decisions on the section name, because none 8674 of the dynobj section names depend upon the input files. */ 8675 name = bfd_get_section_name (dynobj, s); 8676 8677 if (strcmp (name, ".plt") == 0) 8678 { 8679 /* Remember whether there is a PLT. */ 8680 plt = s->size != 0; 8681 } 8682 else if (CONST_STRNEQ (name, ".rel")) 8683 { 8684 if (s->size != 0) 8685 { 8686 /* Remember whether there are any reloc sections other 8687 than .rel(a).plt and .rela.plt.unloaded. */ 8688 if (s != htab->srelplt && s != htab->srelplt2) 8689 relocs = TRUE; 8690 8691 /* We use the reloc_count field as a counter if we need 8692 to copy relocs into the output file. */ 8693 s->reloc_count = 0; 8694 } 8695 } 8696 else if (! CONST_STRNEQ (name, ".got") 8697 && strcmp (name, ".dynbss") != 0) 8698 { 8699 /* It's not one of our sections, so don't allocate space. */ 8700 continue; 8701 } 8702 8703 if (s->size == 0) 8704 { 8705 /* If we don't need this section, strip it from the 8706 output file. This is mostly to handle .rel(a).bss and 8707 .rel(a).plt. We must create both sections in 8708 create_dynamic_sections, because they must be created 8709 before the linker maps input sections to output 8710 sections. The linker does that before 8711 adjust_dynamic_symbol is called, and it is that 8712 function which decides whether anything needs to go 8713 into these sections. */ 8714 s->flags |= SEC_EXCLUDE; 8715 continue; 8716 } 8717 8718 if ((s->flags & SEC_HAS_CONTENTS) == 0) 8719 continue; 8720 8721 /* Allocate memory for the section contents. */ 8722 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); 8723 if (s->contents == NULL) 8724 return FALSE; 8725 } 8726 8727 if (elf_hash_table (info)->dynamic_sections_created) 8728 { 8729 /* Add some entries to the .dynamic section. We fill in the 8730 values later, in elf32_arm_finish_dynamic_sections, but we 8731 must add the entries now so that we get the correct size for 8732 the .dynamic section. The DT_DEBUG entry is filled in by the 8733 dynamic linker and used by the debugger. */ 8734#define add_dynamic_entry(TAG, VAL) \ 8735 _bfd_elf_add_dynamic_entry (info, TAG, VAL) 8736 8737 if (info->executable) 8738 { 8739 if (!add_dynamic_entry (DT_DEBUG, 0)) 8740 return FALSE; 8741 } 8742 8743 if (plt) 8744 { 8745 if ( !add_dynamic_entry (DT_PLTGOT, 0) 8746 || !add_dynamic_entry (DT_PLTRELSZ, 0) 8747 || !add_dynamic_entry (DT_PLTREL, 8748 htab->use_rel ? DT_REL : DT_RELA) 8749 || !add_dynamic_entry (DT_JMPREL, 0)) 8750 return FALSE; 8751 } 8752 8753 if (relocs) 8754 { 8755 if (htab->use_rel) 8756 { 8757 if (!add_dynamic_entry (DT_REL, 0) 8758 || !add_dynamic_entry (DT_RELSZ, 0) 8759 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab))) 8760 return FALSE; 8761 } 8762 else 8763 { 8764 if (!add_dynamic_entry (DT_RELA, 0) 8765 || !add_dynamic_entry (DT_RELASZ, 0) 8766 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab))) 8767 return FALSE; 8768 } 8769 } 8770 8771 /* If any dynamic relocs apply to a read-only section, 8772 then we need a DT_TEXTREL entry. */ 8773 if ((info->flags & DF_TEXTREL) == 0) 8774 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs, 8775 (PTR) info); 8776 8777 if ((info->flags & DF_TEXTREL) != 0) 8778 { 8779 if (!add_dynamic_entry (DT_TEXTREL, 0)) 8780 return FALSE; 8781 } 8782 } 8783#undef add_dynamic_entry 8784 8785 return TRUE; 8786} 8787 8788/* Finish up dynamic symbol handling. We set the contents of various 8789 dynamic sections here. */ 8790 8791static bfd_boolean 8792elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info, 8793 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym) 8794{ 8795 bfd * dynobj; 8796 struct elf32_arm_link_hash_table *htab; 8797 struct elf32_arm_link_hash_entry *eh; 8798 8799 dynobj = elf_hash_table (info)->dynobj; 8800 htab = elf32_arm_hash_table (info); 8801 eh = (struct elf32_arm_link_hash_entry *) h; 8802 8803 if (h->plt.offset != (bfd_vma) -1) 8804 { 8805 asection * splt; 8806 asection * srel; 8807 bfd_byte *loc; 8808 bfd_vma plt_index; 8809 Elf_Internal_Rela rel; 8810 8811 /* This symbol has an entry in the procedure linkage table. Set 8812 it up. */ 8813 8814 BFD_ASSERT (h->dynindx != -1); 8815 8816 splt = bfd_get_section_by_name (dynobj, ".plt"); 8817 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt")); 8818 BFD_ASSERT (splt != NULL && srel != NULL); 8819 8820 /* Fill in the entry in the procedure linkage table. */ 8821 if (htab->symbian_p) 8822 { 8823 put_arm_insn (htab, output_bfd, 8824 elf32_arm_symbian_plt_entry[0], 8825 splt->contents + h->plt.offset); 8826 bfd_put_32 (output_bfd, 8827 elf32_arm_symbian_plt_entry[1], 8828 splt->contents + h->plt.offset + 4); 8829 8830 /* Fill in the entry in the .rel.plt section. */ 8831 rel.r_offset = (splt->output_section->vma 8832 + splt->output_offset 8833 + h->plt.offset + 4); 8834 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); 8835 8836 /* Get the index in the procedure linkage table which 8837 corresponds to this symbol. This is the index of this symbol 8838 in all the symbols for which we are making plt entries. The 8839 first entry in the procedure linkage table is reserved. */ 8840 plt_index = ((h->plt.offset - htab->plt_header_size) 8841 / htab->plt_entry_size); 8842 } 8843 else 8844 { 8845 bfd_vma got_offset, got_address, plt_address; 8846 bfd_vma got_displacement; 8847 asection * sgot; 8848 bfd_byte * ptr; 8849 8850 sgot = bfd_get_section_by_name (dynobj, ".got.plt"); 8851 BFD_ASSERT (sgot != NULL); 8852 8853 /* Get the offset into the .got.plt table of the entry that 8854 corresponds to this function. */ 8855 got_offset = eh->plt_got_offset; 8856 8857 /* Get the index in the procedure linkage table which 8858 corresponds to this symbol. This is the index of this symbol 8859 in all the symbols for which we are making plt entries. The 8860 first three entries in .got.plt are reserved; after that 8861 symbols appear in the same order as in .plt. */ 8862 plt_index = (got_offset - 12) / 4; 8863 8864 /* Calculate the address of the GOT entry. */ 8865 got_address = (sgot->output_section->vma 8866 + sgot->output_offset 8867 + got_offset); 8868 8869 /* ...and the address of the PLT entry. */ 8870 plt_address = (splt->output_section->vma 8871 + splt->output_offset 8872 + h->plt.offset); 8873 8874 ptr = htab->splt->contents + h->plt.offset; 8875 if (htab->vxworks_p && info->shared) 8876 { 8877 unsigned int i; 8878 bfd_vma val; 8879 8880 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4) 8881 { 8882 val = elf32_arm_vxworks_shared_plt_entry[i]; 8883 if (i == 2) 8884 val |= got_address - sgot->output_section->vma; 8885 if (i == 5) 8886 val |= plt_index * RELOC_SIZE (htab); 8887 if (i == 2 || i == 5) 8888 bfd_put_32 (output_bfd, val, ptr); 8889 else 8890 put_arm_insn (htab, output_bfd, val, ptr); 8891 } 8892 } 8893 else if (htab->vxworks_p) 8894 { 8895 unsigned int i; 8896 bfd_vma val; 8897 8898 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4) 8899 { 8900 val = elf32_arm_vxworks_exec_plt_entry[i]; 8901 if (i == 2) 8902 val |= got_address; 8903 if (i == 4) 8904 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2); 8905 if (i == 5) 8906 val |= plt_index * RELOC_SIZE (htab); 8907 if (i == 2 || i == 5) 8908 bfd_put_32 (output_bfd, val, ptr); 8909 else 8910 put_arm_insn (htab, output_bfd, val, ptr); 8911 } 8912 8913 loc = (htab->srelplt2->contents 8914 + (plt_index * 2 + 1) * RELOC_SIZE (htab)); 8915 8916 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation 8917 referencing the GOT for this PLT entry. */ 8918 rel.r_offset = plt_address + 8; 8919 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); 8920 rel.r_addend = got_offset; 8921 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); 8922 loc += RELOC_SIZE (htab); 8923 8924 /* Create the R_ARM_ABS32 relocation referencing the 8925 beginning of the PLT for this GOT entry. */ 8926 rel.r_offset = got_address; 8927 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32); 8928 rel.r_addend = 0; 8929 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); 8930 } 8931 else 8932 { 8933 /* Calculate the displacement between the PLT slot and the 8934 entry in the GOT. The eight-byte offset accounts for the 8935 value produced by adding to pc in the first instruction 8936 of the PLT stub. */ 8937 got_displacement = got_address - (plt_address + 8); 8938 8939 BFD_ASSERT ((got_displacement & 0xf0000000) == 0); 8940 8941 if (!htab->use_blx && eh->plt_thumb_refcount > 0) 8942 { 8943 put_thumb_insn (htab, output_bfd, 8944 elf32_arm_plt_thumb_stub[0], ptr - 4); 8945 put_thumb_insn (htab, output_bfd, 8946 elf32_arm_plt_thumb_stub[1], ptr - 2); 8947 } 8948 8949 put_arm_insn (htab, output_bfd, 8950 elf32_arm_plt_entry[0] 8951 | ((got_displacement & 0x0ff00000) >> 20), 8952 ptr + 0); 8953 put_arm_insn (htab, output_bfd, 8954 elf32_arm_plt_entry[1] 8955 | ((got_displacement & 0x000ff000) >> 12), 8956 ptr+ 4); 8957 put_arm_insn (htab, output_bfd, 8958 elf32_arm_plt_entry[2] 8959 | (got_displacement & 0x00000fff), 8960 ptr + 8); 8961#ifdef FOUR_WORD_PLT 8962 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12); 8963#endif 8964 } 8965 8966 /* Fill in the entry in the global offset table. */ 8967 bfd_put_32 (output_bfd, 8968 (splt->output_section->vma 8969 + splt->output_offset), 8970 sgot->contents + got_offset); 8971 8972 /* Fill in the entry in the .rel(a).plt section. */ 8973 rel.r_addend = 0; 8974 rel.r_offset = got_address; 8975 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT); 8976 } 8977 8978 loc = srel->contents + plt_index * RELOC_SIZE (htab); 8979 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); 8980 8981 if (!h->def_regular) 8982 { 8983 /* Mark the symbol as undefined, rather than as defined in 8984 the .plt section. Leave the value alone. */ 8985 sym->st_shndx = SHN_UNDEF; 8986 /* If the symbol is weak, we do need to clear the value. 8987 Otherwise, the PLT entry would provide a definition for 8988 the symbol even if the symbol wasn't defined anywhere, 8989 and so the symbol would never be NULL. */ 8990 if (!h->ref_regular_nonweak) 8991 sym->st_value = 0; 8992 } 8993 } 8994 8995 if (h->got.offset != (bfd_vma) -1 8996 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0 8997 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0) 8998 { 8999 asection * sgot; 9000 asection * srel; 9001 Elf_Internal_Rela rel; 9002 bfd_byte *loc; 9003 bfd_vma offset; 9004 9005 /* This symbol has an entry in the global offset table. Set it 9006 up. */ 9007 sgot = bfd_get_section_by_name (dynobj, ".got"); 9008 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got")); 9009 BFD_ASSERT (sgot != NULL && srel != NULL); 9010 9011 offset = (h->got.offset & ~(bfd_vma) 1); 9012 rel.r_addend = 0; 9013 rel.r_offset = (sgot->output_section->vma 9014 + sgot->output_offset 9015 + offset); 9016 9017 /* If this is a static link, or it is a -Bsymbolic link and the 9018 symbol is defined locally or was forced to be local because 9019 of a version file, we just want to emit a RELATIVE reloc. 9020 The entry in the global offset table will already have been 9021 initialized in the relocate_section function. */ 9022 if (info->shared 9023 && SYMBOL_REFERENCES_LOCAL (info, h)) 9024 { 9025 BFD_ASSERT((h->got.offset & 1) != 0); 9026 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); 9027 if (!htab->use_rel) 9028 { 9029 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset); 9030 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset); 9031 } 9032 } 9033 else 9034 { 9035 BFD_ASSERT((h->got.offset & 1) == 0); 9036 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset); 9037 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); 9038 } 9039 9040 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab); 9041 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); 9042 } 9043 9044 if (h->needs_copy) 9045 { 9046 asection * s; 9047 Elf_Internal_Rela rel; 9048 bfd_byte *loc; 9049 9050 /* This symbol needs a copy reloc. Set it up. */ 9051 BFD_ASSERT (h->dynindx != -1 9052 && (h->root.type == bfd_link_hash_defined 9053 || h->root.type == bfd_link_hash_defweak)); 9054 9055 s = bfd_get_section_by_name (h->root.u.def.section->owner, 9056 RELOC_SECTION (htab, ".bss")); 9057 BFD_ASSERT (s != NULL); 9058 9059 rel.r_addend = 0; 9060 rel.r_offset = (h->root.u.def.value 9061 + h->root.u.def.section->output_section->vma 9062 + h->root.u.def.section->output_offset); 9063 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY); 9064 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab); 9065 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc); 9066 } 9067 9068 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks, 9069 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative 9070 to the ".got" section. */ 9071 if (strcmp (h->root.root.string, "_DYNAMIC") == 0 9072 || (!htab->vxworks_p && h == htab->root.hgot)) 9073 sym->st_shndx = SHN_ABS; 9074 9075 return TRUE; 9076} 9077 9078/* Finish up the dynamic sections. */ 9079 9080static bfd_boolean 9081elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info) 9082{ 9083 bfd * dynobj; 9084 asection * sgot; 9085 asection * sdyn; 9086 9087 dynobj = elf_hash_table (info)->dynobj; 9088 9089 sgot = bfd_get_section_by_name (dynobj, ".got.plt"); 9090 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL); 9091 sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); 9092 9093 if (elf_hash_table (info)->dynamic_sections_created) 9094 { 9095 asection *splt; 9096 Elf32_External_Dyn *dyncon, *dynconend; 9097 struct elf32_arm_link_hash_table *htab; 9098 9099 htab = elf32_arm_hash_table (info); 9100 splt = bfd_get_section_by_name (dynobj, ".plt"); 9101 BFD_ASSERT (splt != NULL && sdyn != NULL); 9102 9103 dyncon = (Elf32_External_Dyn *) sdyn->contents; 9104 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); 9105 9106 for (; dyncon < dynconend; dyncon++) 9107 { 9108 Elf_Internal_Dyn dyn; 9109 const char * name; 9110 asection * s; 9111 9112 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); 9113 9114 switch (dyn.d_tag) 9115 { 9116 unsigned int type; 9117 9118 default: 9119 break; 9120 9121 case DT_HASH: 9122 name = ".hash"; 9123 goto get_vma_if_bpabi; 9124 case DT_STRTAB: 9125 name = ".dynstr"; 9126 goto get_vma_if_bpabi; 9127 case DT_SYMTAB: 9128 name = ".dynsym"; 9129 goto get_vma_if_bpabi; 9130 case DT_VERSYM: 9131 name = ".gnu.version"; 9132 goto get_vma_if_bpabi; 9133 case DT_VERDEF: 9134 name = ".gnu.version_d"; 9135 goto get_vma_if_bpabi; 9136 case DT_VERNEED: 9137 name = ".gnu.version_r"; 9138 goto get_vma_if_bpabi; 9139 9140 case DT_PLTGOT: 9141 name = ".got"; 9142 goto get_vma; 9143 case DT_JMPREL: 9144 name = RELOC_SECTION (htab, ".plt"); 9145 get_vma: 9146 s = bfd_get_section_by_name (output_bfd, name); 9147 BFD_ASSERT (s != NULL); 9148 if (!htab->symbian_p) 9149 dyn.d_un.d_ptr = s->vma; 9150 else 9151 /* In the BPABI, tags in the PT_DYNAMIC section point 9152 at the file offset, not the memory address, for the 9153 convenience of the post linker. */ 9154 dyn.d_un.d_ptr = s->filepos; 9155 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 9156 break; 9157 9158 get_vma_if_bpabi: 9159 if (htab->symbian_p) 9160 goto get_vma; 9161 break; 9162 9163 case DT_PLTRELSZ: 9164 s = bfd_get_section_by_name (output_bfd, 9165 RELOC_SECTION (htab, ".plt")); 9166 BFD_ASSERT (s != NULL); 9167 dyn.d_un.d_val = s->size; 9168 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 9169 break; 9170 9171 case DT_RELSZ: 9172 case DT_RELASZ: 9173 if (!htab->symbian_p) 9174 { 9175 /* My reading of the SVR4 ABI indicates that the 9176 procedure linkage table relocs (DT_JMPREL) should be 9177 included in the overall relocs (DT_REL). This is 9178 what Solaris does. However, UnixWare can not handle 9179 that case. Therefore, we override the DT_RELSZ entry 9180 here to make it not include the JMPREL relocs. Since 9181 the linker script arranges for .rel(a).plt to follow all 9182 other relocation sections, we don't have to worry 9183 about changing the DT_REL entry. */ 9184 s = bfd_get_section_by_name (output_bfd, 9185 RELOC_SECTION (htab, ".plt")); 9186 if (s != NULL) 9187 dyn.d_un.d_val -= s->size; 9188 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 9189 break; 9190 } 9191 /* Fall through */ 9192 9193 case DT_REL: 9194 case DT_RELA: 9195 /* In the BPABI, the DT_REL tag must point at the file 9196 offset, not the VMA, of the first relocation 9197 section. So, we use code similar to that in 9198 elflink.c, but do not check for SHF_ALLOC on the 9199 relcoation section, since relocations sections are 9200 never allocated under the BPABI. The comments above 9201 about Unixware notwithstanding, we include all of the 9202 relocations here. */ 9203 if (htab->symbian_p) 9204 { 9205 unsigned int i; 9206 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ) 9207 ? SHT_REL : SHT_RELA); 9208 dyn.d_un.d_val = 0; 9209 for (i = 1; i < elf_numsections (output_bfd); i++) 9210 { 9211 Elf_Internal_Shdr *hdr 9212 = elf_elfsections (output_bfd)[i]; 9213 if (hdr->sh_type == type) 9214 { 9215 if (dyn.d_tag == DT_RELSZ 9216 || dyn.d_tag == DT_RELASZ) 9217 dyn.d_un.d_val += hdr->sh_size; 9218 else if ((ufile_ptr) hdr->sh_offset 9219 <= dyn.d_un.d_val - 1) 9220 dyn.d_un.d_val = hdr->sh_offset; 9221 } 9222 } 9223 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 9224 } 9225 break; 9226 9227 /* Set the bottom bit of DT_INIT/FINI if the 9228 corresponding function is Thumb. */ 9229 case DT_INIT: 9230 name = info->init_function; 9231 goto get_sym; 9232 case DT_FINI: 9233 name = info->fini_function; 9234 get_sym: 9235 /* If it wasn't set by elf_bfd_final_link 9236 then there is nothing to adjust. */ 9237 if (dyn.d_un.d_val != 0) 9238 { 9239 struct elf_link_hash_entry * eh; 9240 9241 eh = elf_link_hash_lookup (elf_hash_table (info), name, 9242 FALSE, FALSE, TRUE); 9243 if (eh != (struct elf_link_hash_entry *) NULL 9244 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC) 9245 { 9246 dyn.d_un.d_val |= 1; 9247 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 9248 } 9249 } 9250 break; 9251 } 9252 } 9253 9254 /* Fill in the first entry in the procedure linkage table. */ 9255 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size) 9256 { 9257 const bfd_vma *plt0_entry; 9258 bfd_vma got_address, plt_address, got_displacement; 9259 9260 /* Calculate the addresses of the GOT and PLT. */ 9261 got_address = sgot->output_section->vma + sgot->output_offset; 9262 plt_address = splt->output_section->vma + splt->output_offset; 9263 9264 if (htab->vxworks_p) 9265 { 9266 /* The VxWorks GOT is relocated by the dynamic linker. 9267 Therefore, we must emit relocations rather than simply 9268 computing the values now. */ 9269 Elf_Internal_Rela rel; 9270 9271 plt0_entry = elf32_arm_vxworks_exec_plt0_entry; 9272 put_arm_insn (htab, output_bfd, plt0_entry[0], 9273 splt->contents + 0); 9274 put_arm_insn (htab, output_bfd, plt0_entry[1], 9275 splt->contents + 4); 9276 put_arm_insn (htab, output_bfd, plt0_entry[2], 9277 splt->contents + 8); 9278 bfd_put_32 (output_bfd, got_address, splt->contents + 12); 9279 9280 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */ 9281 rel.r_offset = plt_address + 12; 9282 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); 9283 rel.r_addend = 0; 9284 SWAP_RELOC_OUT (htab) (output_bfd, &rel, 9285 htab->srelplt2->contents); 9286 } 9287 else 9288 { 9289 got_displacement = got_address - (plt_address + 16); 9290 9291 plt0_entry = elf32_arm_plt0_entry; 9292 put_arm_insn (htab, output_bfd, plt0_entry[0], 9293 splt->contents + 0); 9294 put_arm_insn (htab, output_bfd, plt0_entry[1], 9295 splt->contents + 4); 9296 put_arm_insn (htab, output_bfd, plt0_entry[2], 9297 splt->contents + 8); 9298 put_arm_insn (htab, output_bfd, plt0_entry[3], 9299 splt->contents + 12); 9300 9301#ifdef FOUR_WORD_PLT 9302 /* The displacement value goes in the otherwise-unused 9303 last word of the second entry. */ 9304 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28); 9305#else 9306 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16); 9307#endif 9308 } 9309 } 9310 9311 /* UnixWare sets the entsize of .plt to 4, although that doesn't 9312 really seem like the right value. */ 9313 if (splt->output_section->owner == output_bfd) 9314 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; 9315 9316 if (htab->vxworks_p && !info->shared && htab->splt->size > 0) 9317 { 9318 /* Correct the .rel(a).plt.unloaded relocations. They will have 9319 incorrect symbol indexes. */ 9320 int num_plts; 9321 unsigned char *p; 9322 9323 num_plts = ((htab->splt->size - htab->plt_header_size) 9324 / htab->plt_entry_size); 9325 p = htab->srelplt2->contents + RELOC_SIZE (htab); 9326 9327 for (; num_plts; num_plts--) 9328 { 9329 Elf_Internal_Rela rel; 9330 9331 SWAP_RELOC_IN (htab) (output_bfd, p, &rel); 9332 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32); 9333 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p); 9334 p += RELOC_SIZE (htab); 9335 9336 SWAP_RELOC_IN (htab) (output_bfd, p, &rel); 9337 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32); 9338 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p); 9339 p += RELOC_SIZE (htab); 9340 } 9341 } 9342 } 9343 9344 /* Fill in the first three entries in the global offset table. */ 9345 if (sgot) 9346 { 9347 if (sgot->size > 0) 9348 { 9349 if (sdyn == NULL) 9350 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); 9351 else 9352 bfd_put_32 (output_bfd, 9353 sdyn->output_section->vma + sdyn->output_offset, 9354 sgot->contents); 9355 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); 9356 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); 9357 } 9358 9359 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; 9360 } 9361 9362 return TRUE; 9363} 9364 9365static void 9366elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED) 9367{ 9368 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ 9369 struct elf32_arm_link_hash_table *globals; 9370 9371 i_ehdrp = elf_elfheader (abfd); 9372 9373 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD; 9374 i_ehdrp->e_ident[EI_ABIVERSION] = 0; 9375 9376 if (link_info) 9377 { 9378 globals = elf32_arm_hash_table (link_info); 9379 if (globals->byteswap_code) 9380 i_ehdrp->e_flags |= EF_ARM_BE8; 9381 } 9382 9383 /* 9384 * For EABI 5, we have to tag dynamic binaries and execs as either 9385 * soft float or hard float. 9386 */ 9387 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_VER5 && 9388 (i_ehdrp->e_type == ET_DYN || i_ehdrp->e_type == ET_EXEC)) 9389 i_ehdrp->e_flags |= 9390 bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC, Tag_ABI_VFP_args) ? 9391 EF_ARM_VFP_FLOAT : EF_ARM_SOFT_FLOAT; 9392} 9393 9394static enum elf_reloc_type_class 9395elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela) 9396{ 9397 switch ((int) ELF32_R_TYPE (rela->r_info)) 9398 { 9399 case R_ARM_RELATIVE: 9400 return reloc_class_relative; 9401 case R_ARM_JUMP_SLOT: 9402 return reloc_class_plt; 9403 case R_ARM_COPY: 9404 return reloc_class_copy; 9405 default: 9406 return reloc_class_normal; 9407 } 9408} 9409 9410/* Set the right machine number for an Arm ELF file. */ 9411 9412static bfd_boolean 9413elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr) 9414{ 9415 if (hdr->sh_type == SHT_NOTE) 9416 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS; 9417 9418 return TRUE; 9419} 9420 9421static void 9422elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) 9423{ 9424 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION); 9425} 9426 9427/* Return TRUE if this is an unwinding table entry. */ 9428 9429static bfd_boolean 9430is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name) 9431{ 9432 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind) 9433 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once)); 9434} 9435 9436 9437/* Set the type and flags for an ARM section. We do this by 9438 the section name, which is a hack, but ought to work. */ 9439 9440static bfd_boolean 9441elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec) 9442{ 9443 const char * name; 9444 9445 name = bfd_get_section_name (abfd, sec); 9446 9447 if (is_arm_elf_unwind_section_name (abfd, name)) 9448 { 9449 hdr->sh_type = SHT_ARM_EXIDX; 9450 hdr->sh_flags |= SHF_LINK_ORDER; 9451 } 9452 return TRUE; 9453} 9454 9455/* Handle an ARM specific section when reading an object file. This is 9456 called when bfd_section_from_shdr finds a section with an unknown 9457 type. */ 9458 9459static bfd_boolean 9460elf32_arm_section_from_shdr (bfd *abfd, 9461 Elf_Internal_Shdr * hdr, 9462 const char *name, 9463 int shindex) 9464{ 9465 /* There ought to be a place to keep ELF backend specific flags, but 9466 at the moment there isn't one. We just keep track of the 9467 sections by their name, instead. Fortunately, the ABI gives 9468 names for all the ARM specific sections, so we will probably get 9469 away with this. */ 9470 switch (hdr->sh_type) 9471 { 9472 case SHT_ARM_EXIDX: 9473 case SHT_ARM_PREEMPTMAP: 9474 case SHT_ARM_ATTRIBUTES: 9475 break; 9476 9477 default: 9478 return FALSE; 9479 } 9480 9481 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) 9482 return FALSE; 9483 9484 return TRUE; 9485} 9486 9487/* A structure used to record a list of sections, independently 9488 of the next and prev fields in the asection structure. */ 9489typedef struct section_list 9490{ 9491 asection * sec; 9492 struct section_list * next; 9493 struct section_list * prev; 9494} 9495section_list; 9496 9497/* Unfortunately we need to keep a list of sections for which 9498 an _arm_elf_section_data structure has been allocated. This 9499 is because it is possible for functions like elf32_arm_write_section 9500 to be called on a section which has had an elf_data_structure 9501 allocated for it (and so the used_by_bfd field is valid) but 9502 for which the ARM extended version of this structure - the 9503 _arm_elf_section_data structure - has not been allocated. */ 9504static section_list * sections_with_arm_elf_section_data = NULL; 9505 9506static void 9507record_section_with_arm_elf_section_data (asection * sec) 9508{ 9509 struct section_list * entry; 9510 9511 entry = bfd_malloc (sizeof (* entry)); 9512 if (entry == NULL) 9513 return; 9514 entry->sec = sec; 9515 entry->next = sections_with_arm_elf_section_data; 9516 entry->prev = NULL; 9517 if (entry->next != NULL) 9518 entry->next->prev = entry; 9519 sections_with_arm_elf_section_data = entry; 9520} 9521 9522static struct section_list * 9523find_arm_elf_section_entry (asection * sec) 9524{ 9525 struct section_list * entry; 9526 static struct section_list * last_entry = NULL; 9527 9528 /* This is a short cut for the typical case where the sections are added 9529 to the sections_with_arm_elf_section_data list in forward order and 9530 then looked up here in backwards order. This makes a real difference 9531 to the ld-srec/sec64k.exp linker test. */ 9532 entry = sections_with_arm_elf_section_data; 9533 if (last_entry != NULL) 9534 { 9535 if (last_entry->sec == sec) 9536 entry = last_entry; 9537 else if (last_entry->next != NULL 9538 && last_entry->next->sec == sec) 9539 entry = last_entry->next; 9540 } 9541 9542 for (; entry; entry = entry->next) 9543 if (entry->sec == sec) 9544 break; 9545 9546 if (entry) 9547 /* Record the entry prior to this one - it is the entry we are most 9548 likely to want to locate next time. Also this way if we have been 9549 called from unrecord_section_with_arm_elf_section_data() we will not 9550 be caching a pointer that is about to be freed. */ 9551 last_entry = entry->prev; 9552 9553 return entry; 9554} 9555 9556static _arm_elf_section_data * 9557get_arm_elf_section_data (asection * sec) 9558{ 9559 struct section_list * entry; 9560 9561 entry = find_arm_elf_section_entry (sec); 9562 9563 if (entry) 9564 return elf32_arm_section_data (entry->sec); 9565 else 9566 return NULL; 9567} 9568 9569static void 9570unrecord_section_with_arm_elf_section_data (asection * sec) 9571{ 9572 struct section_list * entry; 9573 9574 entry = find_arm_elf_section_entry (sec); 9575 9576 if (entry) 9577 { 9578 if (entry->prev != NULL) 9579 entry->prev->next = entry->next; 9580 if (entry->next != NULL) 9581 entry->next->prev = entry->prev; 9582 if (entry == sections_with_arm_elf_section_data) 9583 sections_with_arm_elf_section_data = entry->next; 9584 free (entry); 9585 } 9586} 9587 9588 9589typedef struct 9590{ 9591 void *finfo; 9592 struct bfd_link_info *info; 9593 asection *sec; 9594 int sec_shndx; 9595 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *, 9596 asection *, struct elf_link_hash_entry *); 9597} output_arch_syminfo; 9598 9599enum map_symbol_type 9600{ 9601 ARM_MAP_ARM, 9602 ARM_MAP_THUMB, 9603 ARM_MAP_DATA 9604}; 9605 9606 9607/* Output a single PLT mapping symbol. */ 9608 9609static bfd_boolean 9610elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi, 9611 enum map_symbol_type type, 9612 bfd_vma offset) 9613{ 9614 static const char *names[3] = {"$a", "$t", "$d"}; 9615 struct elf32_arm_link_hash_table *htab; 9616 Elf_Internal_Sym sym; 9617 9618 htab = elf32_arm_hash_table (osi->info); 9619 sym.st_value = osi->sec->output_section->vma 9620 + osi->sec->output_offset 9621 + offset; 9622 sym.st_size = 0; 9623 sym.st_other = 0; 9624 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); 9625 sym.st_shndx = osi->sec_shndx; 9626 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL)) 9627 return FALSE; 9628 return TRUE; 9629} 9630 9631 9632/* Output mapping symbols for PLT entries associated with H. */ 9633 9634static bfd_boolean 9635elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf) 9636{ 9637 output_arch_syminfo *osi = (output_arch_syminfo *) inf; 9638 struct elf32_arm_link_hash_table *htab; 9639 struct elf32_arm_link_hash_entry *eh; 9640 bfd_vma addr; 9641 9642 htab = elf32_arm_hash_table (osi->info); 9643 9644 if (h->root.type == bfd_link_hash_indirect) 9645 return TRUE; 9646 9647 if (h->root.type == bfd_link_hash_warning) 9648 /* When warning symbols are created, they **replace** the "real" 9649 entry in the hash table, thus we never get to see the real 9650 symbol in a hash traversal. So look at it now. */ 9651 h = (struct elf_link_hash_entry *) h->root.u.i.link; 9652 9653 if (h->plt.offset == (bfd_vma) -1) 9654 return TRUE; 9655 9656 eh = (struct elf32_arm_link_hash_entry *) h; 9657 addr = h->plt.offset; 9658 if (htab->symbian_p) 9659 { 9660 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) 9661 return FALSE; 9662 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4)) 9663 return FALSE; 9664 } 9665 else if (htab->vxworks_p) 9666 { 9667 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) 9668 return FALSE; 9669 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8)) 9670 return FALSE; 9671 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12)) 9672 return FALSE; 9673 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20)) 9674 return FALSE; 9675 } 9676 else 9677 { 9678 bfd_boolean thumb_stub; 9679 9680 thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx; 9681 if (thumb_stub) 9682 { 9683 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4)) 9684 return FALSE; 9685 } 9686#ifdef FOUR_WORD_PLT 9687 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) 9688 return FALSE; 9689 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12)) 9690 return FALSE; 9691#else 9692 /* A three-word PLT with no Thumb thunk contains only Arm code, 9693 so only need to output a mapping symbol for the first PLT entry and 9694 entries with thumb thunks. */ 9695 if (thumb_stub || addr == 20) 9696 { 9697 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr)) 9698 return FALSE; 9699 } 9700#endif 9701 } 9702 9703 return TRUE; 9704} 9705 9706 9707/* Output mapping symbols for linker generated sections. */ 9708 9709static bfd_boolean 9710elf32_arm_output_arch_local_syms (bfd *output_bfd, 9711 struct bfd_link_info *info, 9712 void *finfo, bfd_boolean (*func) (void *, const char *, 9713 Elf_Internal_Sym *, 9714 asection *, 9715 struct elf_link_hash_entry *)) 9716{ 9717 output_arch_syminfo osi; 9718 struct elf32_arm_link_hash_table *htab; 9719 bfd_vma offset; 9720 bfd_size_type size; 9721 9722 htab = elf32_arm_hash_table (info); 9723 check_use_blx(htab); 9724 9725 osi.finfo = finfo; 9726 osi.info = info; 9727 osi.func = func; 9728 9729 /* ARM->Thumb glue. */ 9730 if (htab->arm_glue_size > 0) 9731 { 9732 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner, 9733 ARM2THUMB_GLUE_SECTION_NAME); 9734 9735 osi.sec_shndx = _bfd_elf_section_from_bfd_section 9736 (output_bfd, osi.sec->output_section); 9737 if (info->shared || htab->root.is_relocatable_executable 9738 || htab->pic_veneer) 9739 size = ARM2THUMB_PIC_GLUE_SIZE; 9740 else if (htab->use_blx) 9741 size = ARM2THUMB_V5_STATIC_GLUE_SIZE; 9742 else 9743 size = ARM2THUMB_STATIC_GLUE_SIZE; 9744 9745 for (offset = 0; offset < htab->arm_glue_size; offset += size) 9746 { 9747 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset); 9748 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, offset + size - 4); 9749 } 9750 } 9751 9752 /* Thumb->ARM glue. */ 9753 if (htab->thumb_glue_size > 0) 9754 { 9755 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner, 9756 THUMB2ARM_GLUE_SECTION_NAME); 9757 9758 osi.sec_shndx = _bfd_elf_section_from_bfd_section 9759 (output_bfd, osi.sec->output_section); 9760 size = THUMB2ARM_GLUE_SIZE; 9761 9762 for (offset = 0; offset < htab->thumb_glue_size; offset += size) 9763 { 9764 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_THUMB, offset); 9765 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset + 4); 9766 } 9767 } 9768 9769 /* Finally, output mapping symbols for the PLT. */ 9770 if (!htab->splt || htab->splt->size == 0) 9771 return TRUE; 9772 9773 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd, 9774 htab->splt->output_section); 9775 osi.sec = htab->splt; 9776 /* Output mapping symbols for the plt header. SymbianOS does not have a 9777 plt header. */ 9778 if (htab->vxworks_p) 9779 { 9780 /* VxWorks shared libraries have no PLT header. */ 9781 if (!info->shared) 9782 { 9783 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0)) 9784 return FALSE; 9785 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12)) 9786 return FALSE; 9787 } 9788 } 9789 else if (!htab->symbian_p) 9790 { 9791 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0)) 9792 return FALSE; 9793#ifndef FOUR_WORD_PLT 9794 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16)) 9795 return FALSE; 9796#endif 9797 } 9798 9799 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi); 9800 return TRUE; 9801} 9802 9803/* Allocate target specific section data. */ 9804 9805static bfd_boolean 9806elf32_arm_new_section_hook (bfd *abfd, asection *sec) 9807{ 9808 if (!sec->used_by_bfd) 9809 { 9810 _arm_elf_section_data *sdata; 9811 bfd_size_type amt = sizeof (*sdata); 9812 9813 sdata = bfd_zalloc (abfd, amt); 9814 if (sdata == NULL) 9815 return FALSE; 9816 sec->used_by_bfd = sdata; 9817 } 9818 9819 record_section_with_arm_elf_section_data (sec); 9820 9821 return _bfd_elf_new_section_hook (abfd, sec); 9822} 9823 9824 9825/* Used to order a list of mapping symbols by address. */ 9826 9827static int 9828elf32_arm_compare_mapping (const void * a, const void * b) 9829{ 9830 return ((const elf32_arm_section_map *) a)->vma 9831 > ((const elf32_arm_section_map *) b)->vma; 9832} 9833 9834 9835/* Do code byteswapping. Return FALSE afterwards so that the section is 9836 written out as normal. */ 9837 9838static bfd_boolean 9839elf32_arm_write_section (bfd *output_bfd, 9840 struct bfd_link_info *link_info, asection *sec, 9841 bfd_byte *contents) 9842{ 9843 int mapcount, errcount; 9844 _arm_elf_section_data *arm_data; 9845 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info); 9846 elf32_arm_section_map *map; 9847 elf32_vfp11_erratum_list *errnode; 9848 bfd_vma ptr; 9849 bfd_vma end; 9850 bfd_vma offset = sec->output_section->vma + sec->output_offset; 9851 bfd_byte tmp; 9852 int i; 9853 9854 /* If this section has not been allocated an _arm_elf_section_data 9855 structure then we cannot record anything. */ 9856 arm_data = get_arm_elf_section_data (sec); 9857 if (arm_data == NULL) 9858 return FALSE; 9859 9860 mapcount = arm_data->mapcount; 9861 map = arm_data->map; 9862 errcount = arm_data->erratumcount; 9863 9864 if (errcount != 0) 9865 { 9866 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0; 9867 9868 for (errnode = arm_data->erratumlist; errnode != 0; 9869 errnode = errnode->next) 9870 { 9871 bfd_vma index = errnode->vma - offset; 9872 9873 switch (errnode->type) 9874 { 9875 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER: 9876 { 9877 bfd_vma branch_to_veneer; 9878 /* Original condition code of instruction, plus bit mask for 9879 ARM B instruction. */ 9880 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000) 9881 | 0x0a000000; 9882 9883 /* The instruction is before the label. */ 9884 index -= 4; 9885 9886 /* Above offset included in -4 below. */ 9887 branch_to_veneer = errnode->u.b.veneer->vma 9888 - errnode->vma - 4; 9889 9890 if ((signed) branch_to_veneer < -(1 << 25) 9891 || (signed) branch_to_veneer >= (1 << 25)) 9892 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of " 9893 "range"), output_bfd); 9894 9895 insn |= (branch_to_veneer >> 2) & 0xffffff; 9896 contents[endianflip ^ index] = insn & 0xff; 9897 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff; 9898 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff; 9899 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff; 9900 } 9901 break; 9902 9903 case VFP11_ERRATUM_ARM_VENEER: 9904 { 9905 bfd_vma branch_from_veneer; 9906 unsigned int insn; 9907 9908 /* Take size of veneer into account. */ 9909 branch_from_veneer = errnode->u.v.branch->vma 9910 - errnode->vma - 12; 9911 9912 if ((signed) branch_from_veneer < -(1 << 25) 9913 || (signed) branch_from_veneer >= (1 << 25)) 9914 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of " 9915 "range"), output_bfd); 9916 9917 /* Original instruction. */ 9918 insn = errnode->u.v.branch->u.b.vfp_insn; 9919 contents[endianflip ^ index] = insn & 0xff; 9920 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff; 9921 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff; 9922 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff; 9923 9924 /* Branch back to insn after original insn. */ 9925 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff); 9926 contents[endianflip ^ (index + 4)] = insn & 0xff; 9927 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff; 9928 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff; 9929 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff; 9930 } 9931 break; 9932 9933 default: 9934 abort (); 9935 } 9936 } 9937 } 9938 9939 if (mapcount == 0) 9940 return FALSE; 9941 9942 if (globals->byteswap_code) 9943 { 9944 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping); 9945 9946 ptr = map[0].vma; 9947 for (i = 0; i < mapcount; i++) 9948 { 9949 if (i == mapcount - 1) 9950 end = sec->size; 9951 else 9952 end = map[i + 1].vma; 9953 9954 switch (map[i].type) 9955 { 9956 case 'a': 9957 /* Byte swap code words. */ 9958 while (ptr + 3 < end) 9959 { 9960 tmp = contents[ptr]; 9961 contents[ptr] = contents[ptr + 3]; 9962 contents[ptr + 3] = tmp; 9963 tmp = contents[ptr + 1]; 9964 contents[ptr + 1] = contents[ptr + 2]; 9965 contents[ptr + 2] = tmp; 9966 ptr += 4; 9967 } 9968 break; 9969 9970 case 't': 9971 /* Byte swap code halfwords. */ 9972 while (ptr + 1 < end) 9973 { 9974 tmp = contents[ptr]; 9975 contents[ptr] = contents[ptr + 1]; 9976 contents[ptr + 1] = tmp; 9977 ptr += 2; 9978 } 9979 break; 9980 9981 case 'd': 9982 /* Leave data alone. */ 9983 break; 9984 } 9985 ptr = end; 9986 } 9987 } 9988 9989 free (map); 9990 arm_data->mapcount = 0; 9991 arm_data->mapsize = 0; 9992 arm_data->map = NULL; 9993 unrecord_section_with_arm_elf_section_data (sec); 9994 9995 return FALSE; 9996} 9997 9998static void 9999unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED, 10000 asection * sec, 10001 void * ignore ATTRIBUTE_UNUSED) 10002{ 10003 unrecord_section_with_arm_elf_section_data (sec); 10004} 10005 10006static bfd_boolean 10007elf32_arm_close_and_cleanup (bfd * abfd) 10008{ 10009 if (abfd->sections) 10010 bfd_map_over_sections (abfd, 10011 unrecord_section_via_map_over_sections, 10012 NULL); 10013 10014 return _bfd_elf_close_and_cleanup (abfd); 10015} 10016 10017static bfd_boolean 10018elf32_arm_bfd_free_cached_info (bfd * abfd) 10019{ 10020 if (abfd->sections) 10021 bfd_map_over_sections (abfd, 10022 unrecord_section_via_map_over_sections, 10023 NULL); 10024 10025 return _bfd_free_cached_info (abfd); 10026} 10027 10028/* Display STT_ARM_TFUNC symbols as functions. */ 10029 10030static void 10031elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, 10032 asymbol *asym) 10033{ 10034 elf_symbol_type *elfsym = (elf_symbol_type *) asym; 10035 10036 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC) 10037 elfsym->symbol.flags |= BSF_FUNCTION; 10038} 10039 10040 10041/* Mangle thumb function symbols as we read them in. */ 10042 10043static bfd_boolean 10044elf32_arm_swap_symbol_in (bfd * abfd, 10045 const void *psrc, 10046 const void *pshn, 10047 Elf_Internal_Sym *dst) 10048{ 10049 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst)) 10050 return FALSE; 10051 10052 /* New EABI objects mark thumb function symbols by setting the low bit of 10053 the address. Turn these into STT_ARM_TFUNC. */ 10054 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC 10055 && (dst->st_value & 1)) 10056 { 10057 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC); 10058 dst->st_value &= ~(bfd_vma) 1; 10059 } 10060 return TRUE; 10061} 10062 10063 10064/* Mangle thumb function symbols as we write them out. */ 10065 10066static void 10067elf32_arm_swap_symbol_out (bfd *abfd, 10068 const Elf_Internal_Sym *src, 10069 void *cdst, 10070 void *shndx) 10071{ 10072 Elf_Internal_Sym newsym; 10073 10074 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit 10075 of the address set, as per the new EABI. We do this unconditionally 10076 because objcopy does not set the elf header flags until after 10077 it writes out the symbol table. */ 10078 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC) 10079 { 10080 newsym = *src; 10081 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC); 10082 if (newsym.st_shndx != SHN_UNDEF) 10083 { 10084 /* Do this only for defined symbols. At link type, the static 10085 linker will simulate the work of dynamic linker of resolving 10086 symbols and will carry over the thumbness of found symbols to 10087 the output symbol table. It's not clear how it happens, but 10088 the thumbness of undefined symbols can well be different at 10089 runtime, and writing '1' for them will be confusing for users 10090 and possibly for dynamic linker itself. 10091 */ 10092 newsym.st_value |= 1; 10093 } 10094 10095 src = &newsym; 10096 } 10097 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx); 10098} 10099 10100/* Add the PT_ARM_EXIDX program header. */ 10101 10102static bfd_boolean 10103elf32_arm_modify_segment_map (bfd *abfd, 10104 struct bfd_link_info *info ATTRIBUTE_UNUSED) 10105{ 10106 struct elf_segment_map *m; 10107 asection *sec; 10108 10109 sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); 10110 if (sec != NULL && (sec->flags & SEC_LOAD) != 0) 10111 { 10112 /* If there is already a PT_ARM_EXIDX header, then we do not 10113 want to add another one. This situation arises when running 10114 "strip"; the input binary already has the header. */ 10115 m = elf_tdata (abfd)->segment_map; 10116 while (m && m->p_type != PT_ARM_EXIDX) 10117 m = m->next; 10118 if (!m) 10119 { 10120 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map)); 10121 if (m == NULL) 10122 return FALSE; 10123 m->p_type = PT_ARM_EXIDX; 10124 m->count = 1; 10125 m->sections[0] = sec; 10126 10127 m->next = elf_tdata (abfd)->segment_map; 10128 elf_tdata (abfd)->segment_map = m; 10129 } 10130 } 10131 10132 return TRUE; 10133} 10134 10135/* We may add a PT_ARM_EXIDX program header. */ 10136 10137static int 10138elf32_arm_additional_program_headers (bfd *abfd, 10139 struct bfd_link_info *info ATTRIBUTE_UNUSED) 10140{ 10141 asection *sec; 10142 10143 sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); 10144 if (sec != NULL && (sec->flags & SEC_LOAD) != 0) 10145 return 1; 10146 else 10147 return 0; 10148} 10149 10150/* We have two function types: STT_FUNC and STT_ARM_TFUNC. */ 10151static bfd_boolean 10152elf32_arm_is_function_type (unsigned int type) 10153{ 10154 return (type == STT_FUNC) || (type == STT_ARM_TFUNC); 10155} 10156 10157/* We use this to override swap_symbol_in and swap_symbol_out. */ 10158const struct elf_size_info elf32_arm_size_info = { 10159 sizeof (Elf32_External_Ehdr), 10160 sizeof (Elf32_External_Phdr), 10161 sizeof (Elf32_External_Shdr), 10162 sizeof (Elf32_External_Rel), 10163 sizeof (Elf32_External_Rela), 10164 sizeof (Elf32_External_Sym), 10165 sizeof (Elf32_External_Dyn), 10166 sizeof (Elf_External_Note), 10167 4, 10168 1, 10169 32, 2, 10170 ELFCLASS32, EV_CURRENT, 10171 bfd_elf32_write_out_phdrs, 10172 bfd_elf32_write_shdrs_and_ehdr, 10173 bfd_elf32_write_relocs, 10174 elf32_arm_swap_symbol_in, 10175 elf32_arm_swap_symbol_out, 10176 bfd_elf32_slurp_reloc_table, 10177 bfd_elf32_slurp_symbol_table, 10178 bfd_elf32_swap_dyn_in, 10179 bfd_elf32_swap_dyn_out, 10180 bfd_elf32_swap_reloc_in, 10181 bfd_elf32_swap_reloc_out, 10182 bfd_elf32_swap_reloca_in, 10183 bfd_elf32_swap_reloca_out 10184}; 10185 10186#define ELF_ARCH bfd_arch_arm 10187#define ELF_MACHINE_CODE EM_ARM 10188#ifdef __QNXTARGET__ 10189#define ELF_MAXPAGESIZE 0x1000 10190#else 10191#define ELF_MAXPAGESIZE 0x8000 10192#endif 10193#define ELF_MINPAGESIZE 0x1000 10194#define ELF_COMMONPAGESIZE 0x1000 10195 10196#define bfd_elf32_mkobject elf32_arm_mkobject 10197 10198#define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data 10199#define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data 10200#define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags 10201#define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data 10202#define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create 10203#define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup 10204#define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup 10205#define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line 10206#define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info 10207#define bfd_elf32_new_section_hook elf32_arm_new_section_hook 10208#define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol 10209#define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup 10210#define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info 10211 10212#define elf_backend_get_symbol_type elf32_arm_get_symbol_type 10213#define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook 10214#define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections 10215#define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook 10216#define elf_backend_check_relocs elf32_arm_check_relocs 10217#define elf_backend_relocate_section elf32_arm_relocate_section 10218#define elf_backend_write_section elf32_arm_write_section 10219#define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol 10220#define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections 10221#define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol 10222#define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections 10223#define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections 10224#define elf_backend_init_index_section _bfd_elf_init_2_index_sections 10225#define elf_backend_post_process_headers elf32_arm_post_process_headers 10226#define elf_backend_reloc_type_class elf32_arm_reloc_type_class 10227#define elf_backend_object_p elf32_arm_object_p 10228#define elf_backend_section_flags elf32_arm_section_flags 10229#define elf_backend_fake_sections elf32_arm_fake_sections 10230#define elf_backend_section_from_shdr elf32_arm_section_from_shdr 10231#define elf_backend_final_write_processing elf32_arm_final_write_processing 10232#define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol 10233#define elf_backend_symbol_processing elf32_arm_symbol_processing 10234#define elf_backend_size_info elf32_arm_size_info 10235#define elf_backend_modify_segment_map elf32_arm_modify_segment_map 10236#define elf_backend_additional_program_headers \ 10237 elf32_arm_additional_program_headers 10238#define elf_backend_output_arch_local_syms \ 10239 elf32_arm_output_arch_local_syms 10240#define elf_backend_begin_write_processing \ 10241 elf32_arm_begin_write_processing 10242#define elf_backend_is_function_type elf32_arm_is_function_type 10243 10244#define elf_backend_can_refcount 1 10245#define elf_backend_can_gc_sections 1 10246#define elf_backend_plt_readonly 1 10247#define elf_backend_want_got_plt 1 10248#define elf_backend_want_plt_sym 0 10249#define elf_backend_may_use_rel_p 1 10250#define elf_backend_may_use_rela_p 0 10251#define elf_backend_default_use_rela_p 0 10252 10253#define elf_backend_got_header_size 12 10254 10255#undef elf_backend_obj_attrs_vendor 10256#define elf_backend_obj_attrs_vendor "aeabi" 10257#undef elf_backend_obj_attrs_section 10258#define elf_backend_obj_attrs_section ".ARM.attributes" 10259#undef elf_backend_obj_attrs_arg_type 10260#define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type 10261#undef elf_backend_obj_attrs_section_type 10262#define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES 10263 10264#include "elf32-target.h" 10265 10266/* VxWorks Targets */ 10267 10268#undef TARGET_LITTLE_SYM 10269#define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec 10270#undef TARGET_LITTLE_NAME 10271#define TARGET_LITTLE_NAME "elf32-littlearm-vxworks" 10272#undef TARGET_BIG_SYM 10273#define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec 10274#undef TARGET_BIG_NAME 10275#define TARGET_BIG_NAME "elf32-bigarm-vxworks" 10276 10277/* Like elf32_arm_link_hash_table_create -- but overrides 10278 appropriately for VxWorks. */ 10279static struct bfd_link_hash_table * 10280elf32_arm_vxworks_link_hash_table_create (bfd *abfd) 10281{ 10282 struct bfd_link_hash_table *ret; 10283 10284 ret = elf32_arm_link_hash_table_create (abfd); 10285 if (ret) 10286 { 10287 struct elf32_arm_link_hash_table *htab 10288 = (struct elf32_arm_link_hash_table *) ret; 10289 htab->use_rel = 0; 10290 htab->vxworks_p = 1; 10291 } 10292 return ret; 10293} 10294 10295static void 10296elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) 10297{ 10298 elf32_arm_final_write_processing (abfd, linker); 10299 elf_vxworks_final_write_processing (abfd, linker); 10300} 10301 10302#undef elf32_bed 10303#define elf32_bed elf32_arm_vxworks_bed 10304 10305#undef bfd_elf32_bfd_link_hash_table_create 10306#define bfd_elf32_bfd_link_hash_table_create \ 10307 elf32_arm_vxworks_link_hash_table_create 10308#undef elf_backend_add_symbol_hook 10309#define elf_backend_add_symbol_hook \ 10310 elf_vxworks_add_symbol_hook 10311#undef elf_backend_final_write_processing 10312#define elf_backend_final_write_processing \ 10313 elf32_arm_vxworks_final_write_processing 10314#undef elf_backend_emit_relocs 10315#define elf_backend_emit_relocs \ 10316 elf_vxworks_emit_relocs 10317 10318#undef elf_backend_may_use_rel_p 10319#define elf_backend_may_use_rel_p 0 10320#undef elf_backend_may_use_rela_p 10321#define elf_backend_may_use_rela_p 1 10322#undef elf_backend_default_use_rela_p 10323#define elf_backend_default_use_rela_p 1 10324#undef elf_backend_want_plt_sym 10325#define elf_backend_want_plt_sym 1 10326#undef ELF_MAXPAGESIZE 10327#define ELF_MAXPAGESIZE 0x1000 10328 10329#include "elf32-target.h" 10330 10331 10332/* Symbian OS Targets */ 10333 10334#undef TARGET_LITTLE_SYM 10335#define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec 10336#undef TARGET_LITTLE_NAME 10337#define TARGET_LITTLE_NAME "elf32-littlearm-symbian" 10338#undef TARGET_BIG_SYM 10339#define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec 10340#undef TARGET_BIG_NAME 10341#define TARGET_BIG_NAME "elf32-bigarm-symbian" 10342 10343/* Like elf32_arm_link_hash_table_create -- but overrides 10344 appropriately for Symbian OS. */ 10345static struct bfd_link_hash_table * 10346elf32_arm_symbian_link_hash_table_create (bfd *abfd) 10347{ 10348 struct bfd_link_hash_table *ret; 10349 10350 ret = elf32_arm_link_hash_table_create (abfd); 10351 if (ret) 10352 { 10353 struct elf32_arm_link_hash_table *htab 10354 = (struct elf32_arm_link_hash_table *)ret; 10355 /* There is no PLT header for Symbian OS. */ 10356 htab->plt_header_size = 0; 10357 /* The PLT entries are each three instructions. */ 10358 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry); 10359 htab->symbian_p = 1; 10360 /* Symbian uses armv5t or above, so use_blx is always true. */ 10361 htab->use_blx = 1; 10362 htab->root.is_relocatable_executable = 1; 10363 } 10364 return ret; 10365} 10366 10367static const struct bfd_elf_special_section 10368elf32_arm_symbian_special_sections[] = 10369{ 10370 /* In a BPABI executable, the dynamic linking sections do not go in 10371 the loadable read-only segment. The post-linker may wish to 10372 refer to these sections, but they are not part of the final 10373 program image. */ 10374 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 }, 10375 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 }, 10376 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 }, 10377 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 }, 10378 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 }, 10379 /* These sections do not need to be writable as the SymbianOS 10380 postlinker will arrange things so that no dynamic relocation is 10381 required. */ 10382 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC }, 10383 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC }, 10384 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC }, 10385 { NULL, 0, 0, 0, 0 } 10386}; 10387 10388static void 10389elf32_arm_symbian_begin_write_processing (bfd *abfd, 10390 struct bfd_link_info *link_info) 10391{ 10392 /* BPABI objects are never loaded directly by an OS kernel; they are 10393 processed by a postlinker first, into an OS-specific format. If 10394 the D_PAGED bit is set on the file, BFD will align segments on 10395 page boundaries, so that an OS can directly map the file. With 10396 BPABI objects, that just results in wasted space. In addition, 10397 because we clear the D_PAGED bit, map_sections_to_segments will 10398 recognize that the program headers should not be mapped into any 10399 loadable segment. */ 10400 abfd->flags &= ~D_PAGED; 10401 elf32_arm_begin_write_processing(abfd, link_info); 10402} 10403 10404static bfd_boolean 10405elf32_arm_symbian_modify_segment_map (bfd *abfd, 10406 struct bfd_link_info *info) 10407{ 10408 struct elf_segment_map *m; 10409 asection *dynsec; 10410 10411 /* BPABI shared libraries and executables should have a PT_DYNAMIC 10412 segment. However, because the .dynamic section is not marked 10413 with SEC_LOAD, the generic ELF code will not create such a 10414 segment. */ 10415 dynsec = bfd_get_section_by_name (abfd, ".dynamic"); 10416 if (dynsec) 10417 { 10418 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) 10419 if (m->p_type == PT_DYNAMIC) 10420 break; 10421 10422 if (m == NULL) 10423 { 10424 m = _bfd_elf_make_dynamic_segment (abfd, dynsec); 10425 m->next = elf_tdata (abfd)->segment_map; 10426 elf_tdata (abfd)->segment_map = m; 10427 } 10428 } 10429 10430 /* Also call the generic arm routine. */ 10431 return elf32_arm_modify_segment_map (abfd, info); 10432} 10433 10434#undef elf32_bed 10435#define elf32_bed elf32_arm_symbian_bed 10436 10437/* The dynamic sections are not allocated on SymbianOS; the postlinker 10438 will process them and then discard them. */ 10439#undef ELF_DYNAMIC_SEC_FLAGS 10440#define ELF_DYNAMIC_SEC_FLAGS \ 10441 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED) 10442 10443#undef bfd_elf32_bfd_link_hash_table_create 10444#define bfd_elf32_bfd_link_hash_table_create \ 10445 elf32_arm_symbian_link_hash_table_create 10446#undef elf_backend_add_symbol_hook 10447 10448#undef elf_backend_special_sections 10449#define elf_backend_special_sections elf32_arm_symbian_special_sections 10450 10451#undef elf_backend_begin_write_processing 10452#define elf_backend_begin_write_processing \ 10453 elf32_arm_symbian_begin_write_processing 10454#undef elf_backend_final_write_processing 10455#define elf_backend_final_write_processing \ 10456 elf32_arm_final_write_processing 10457#undef elf_backend_emit_relocs 10458 10459#undef elf_backend_modify_segment_map 10460#define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map 10461 10462/* There is no .got section for BPABI objects, and hence no header. */ 10463#undef elf_backend_got_header_size 10464#define elf_backend_got_header_size 0 10465 10466/* Similarly, there is no .got.plt section. */ 10467#undef elf_backend_want_got_plt 10468#define elf_backend_want_got_plt 0 10469 10470#undef elf_backend_may_use_rel_p 10471#define elf_backend_may_use_rel_p 1 10472#undef elf_backend_may_use_rela_p 10473#define elf_backend_may_use_rela_p 0 10474#undef elf_backend_default_use_rela_p 10475#define elf_backend_default_use_rela_p 0 10476#undef elf_backend_want_plt_sym 10477#define elf_backend_want_plt_sym 0 10478#undef ELF_MAXPAGESIZE 10479#define ELF_MAXPAGESIZE 0x8000 10480 10481#include "elf32-target.h" 10482