| 1 | /* 32-bit ELF support for ARM |
| 2 | Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 |
| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #include "elf/arm.h" |
| 22 | #include "bfd.h" |
| 23 | #include "sysdep.h" |
| 24 | #include "libbfd.h" |
| 25 | #include "elf-bfd.h" |
| 26 | |
| 27 | #ifndef NUM_ELEM |
| 28 | #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0])) |
| 29 | #endif |
| 30 | |
| 31 | #define elf_info_to_howto 0 |
| 32 | #define elf_info_to_howto_rel elf32_arm_info_to_howto |
| 33 | |
| 34 | #define ARM_ELF_ABI_VERSION 0 |
| 35 | #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM |
| 36 | |
| 37 | static reloc_howto_type * elf32_arm_reloc_type_lookup |
| 38 | PARAMS ((bfd * abfd, bfd_reloc_code_real_type code)); |
| 39 | static bfd_boolean elf32_arm_nabi_grok_prstatus |
| 40 | PARAMS ((bfd *abfd, Elf_Internal_Note *note)); |
| 41 | static bfd_boolean elf32_arm_nabi_grok_psinfo |
| 42 | PARAMS ((bfd *abfd, Elf_Internal_Note *note)); |
| 43 | |
| 44 | /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g. |
| 45 | R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO |
| 46 | in that slot. */ |
| 47 | |
| 48 | static reloc_howto_type elf32_arm_howto_table[] = |
| 49 | { |
| 50 | /* No relocation */ |
| 51 | HOWTO (R_ARM_NONE, /* type */ |
| 52 | 0, /* rightshift */ |
| 53 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 54 | 0, /* bitsize */ |
| 55 | FALSE, /* pc_relative */ |
| 56 | 0, /* bitpos */ |
| 57 | complain_overflow_dont,/* complain_on_overflow */ |
| 58 | bfd_elf_generic_reloc, /* special_function */ |
| 59 | "R_ARM_NONE", /* name */ |
| 60 | FALSE, /* partial_inplace */ |
| 61 | 0, /* src_mask */ |
| 62 | 0, /* dst_mask */ |
| 63 | FALSE), /* pcrel_offset */ |
| 64 | |
| 65 | HOWTO (R_ARM_PC24, /* type */ |
| 66 | 2, /* rightshift */ |
| 67 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 68 | 24, /* bitsize */ |
| 69 | TRUE, /* pc_relative */ |
| 70 | 0, /* bitpos */ |
| 71 | complain_overflow_signed,/* complain_on_overflow */ |
| 72 | bfd_elf_generic_reloc, /* special_function */ |
| 73 | "R_ARM_PC24", /* name */ |
| 74 | FALSE, /* partial_inplace */ |
| 75 | 0x00ffffff, /* src_mask */ |
| 76 | 0x00ffffff, /* dst_mask */ |
| 77 | TRUE), /* pcrel_offset */ |
| 78 | |
| 79 | /* 32 bit absolute */ |
| 80 | HOWTO (R_ARM_ABS32, /* type */ |
| 81 | 0, /* rightshift */ |
| 82 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 83 | 32, /* bitsize */ |
| 84 | FALSE, /* pc_relative */ |
| 85 | 0, /* bitpos */ |
| 86 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 87 | bfd_elf_generic_reloc, /* special_function */ |
| 88 | "R_ARM_ABS32", /* name */ |
| 89 | FALSE, /* partial_inplace */ |
| 90 | 0xffffffff, /* src_mask */ |
| 91 | 0xffffffff, /* dst_mask */ |
| 92 | FALSE), /* pcrel_offset */ |
| 93 | |
| 94 | /* standard 32bit pc-relative reloc */ |
| 95 | HOWTO (R_ARM_REL32, /* type */ |
| 96 | 0, /* rightshift */ |
| 97 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 98 | 32, /* bitsize */ |
| 99 | TRUE, /* pc_relative */ |
| 100 | 0, /* bitpos */ |
| 101 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 102 | bfd_elf_generic_reloc, /* special_function */ |
| 103 | "R_ARM_REL32", /* name */ |
| 104 | FALSE, /* partial_inplace */ |
| 105 | 0xffffffff, /* src_mask */ |
| 106 | 0xffffffff, /* dst_mask */ |
| 107 | TRUE), /* pcrel_offset */ |
| 108 | |
| 109 | /* 8 bit absolute */ |
| 110 | HOWTO (R_ARM_PC13, /* type */ |
| 111 | 0, /* rightshift */ |
| 112 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 113 | 8, /* bitsize */ |
| 114 | FALSE, /* pc_relative */ |
| 115 | 0, /* bitpos */ |
| 116 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 117 | bfd_elf_generic_reloc, /* special_function */ |
| 118 | "R_ARM_PC13", /* name */ |
| 119 | FALSE, /* partial_inplace */ |
| 120 | 0x000000ff, /* src_mask */ |
| 121 | 0x000000ff, /* dst_mask */ |
| 122 | FALSE), /* pcrel_offset */ |
| 123 | |
| 124 | /* 16 bit absolute */ |
| 125 | HOWTO (R_ARM_ABS16, /* type */ |
| 126 | 0, /* rightshift */ |
| 127 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 128 | 16, /* bitsize */ |
| 129 | FALSE, /* pc_relative */ |
| 130 | 0, /* bitpos */ |
| 131 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 132 | bfd_elf_generic_reloc, /* special_function */ |
| 133 | "R_ARM_ABS16", /* name */ |
| 134 | FALSE, /* partial_inplace */ |
| 135 | 0x0000ffff, /* src_mask */ |
| 136 | 0x0000ffff, /* dst_mask */ |
| 137 | FALSE), /* pcrel_offset */ |
| 138 | |
| 139 | /* 12 bit absolute */ |
| 140 | HOWTO (R_ARM_ABS12, /* type */ |
| 141 | 0, /* rightshift */ |
| 142 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 143 | 12, /* bitsize */ |
| 144 | FALSE, /* pc_relative */ |
| 145 | 0, /* bitpos */ |
| 146 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 147 | bfd_elf_generic_reloc, /* special_function */ |
| 148 | "R_ARM_ABS12", /* name */ |
| 149 | FALSE, /* partial_inplace */ |
| 150 | 0x000008ff, /* src_mask */ |
| 151 | 0x000008ff, /* dst_mask */ |
| 152 | FALSE), /* pcrel_offset */ |
| 153 | |
| 154 | HOWTO (R_ARM_THM_ABS5, /* type */ |
| 155 | 6, /* rightshift */ |
| 156 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 157 | 5, /* bitsize */ |
| 158 | FALSE, /* pc_relative */ |
| 159 | 0, /* bitpos */ |
| 160 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 161 | bfd_elf_generic_reloc, /* special_function */ |
| 162 | "R_ARM_THM_ABS5", /* name */ |
| 163 | FALSE, /* partial_inplace */ |
| 164 | 0x000007e0, /* src_mask */ |
| 165 | 0x000007e0, /* dst_mask */ |
| 166 | FALSE), /* pcrel_offset */ |
| 167 | |
| 168 | /* 8 bit absolute */ |
| 169 | HOWTO (R_ARM_ABS8, /* type */ |
| 170 | 0, /* rightshift */ |
| 171 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 172 | 8, /* bitsize */ |
| 173 | FALSE, /* pc_relative */ |
| 174 | 0, /* bitpos */ |
| 175 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 176 | bfd_elf_generic_reloc, /* special_function */ |
| 177 | "R_ARM_ABS8", /* name */ |
| 178 | FALSE, /* partial_inplace */ |
| 179 | 0x000000ff, /* src_mask */ |
| 180 | 0x000000ff, /* dst_mask */ |
| 181 | FALSE), /* pcrel_offset */ |
| 182 | |
| 183 | HOWTO (R_ARM_SBREL32, /* type */ |
| 184 | 0, /* rightshift */ |
| 185 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 186 | 32, /* bitsize */ |
| 187 | FALSE, /* pc_relative */ |
| 188 | 0, /* bitpos */ |
| 189 | complain_overflow_dont,/* complain_on_overflow */ |
| 190 | bfd_elf_generic_reloc, /* special_function */ |
| 191 | "R_ARM_SBREL32", /* name */ |
| 192 | FALSE, /* partial_inplace */ |
| 193 | 0xffffffff, /* src_mask */ |
| 194 | 0xffffffff, /* dst_mask */ |
| 195 | FALSE), /* pcrel_offset */ |
| 196 | |
| 197 | HOWTO (R_ARM_THM_PC22, /* type */ |
| 198 | 1, /* rightshift */ |
| 199 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 200 | 23, /* bitsize */ |
| 201 | TRUE, /* pc_relative */ |
| 202 | 0, /* bitpos */ |
| 203 | complain_overflow_signed,/* complain_on_overflow */ |
| 204 | bfd_elf_generic_reloc, /* special_function */ |
| 205 | "R_ARM_THM_PC22", /* name */ |
| 206 | FALSE, /* partial_inplace */ |
| 207 | 0x07ff07ff, /* src_mask */ |
| 208 | 0x07ff07ff, /* dst_mask */ |
| 209 | TRUE), /* pcrel_offset */ |
| 210 | |
| 211 | HOWTO (R_ARM_THM_PC8, /* type */ |
| 212 | 1, /* rightshift */ |
| 213 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 214 | 8, /* bitsize */ |
| 215 | TRUE, /* pc_relative */ |
| 216 | 0, /* bitpos */ |
| 217 | complain_overflow_signed,/* complain_on_overflow */ |
| 218 | bfd_elf_generic_reloc, /* special_function */ |
| 219 | "R_ARM_THM_PC8", /* name */ |
| 220 | FALSE, /* partial_inplace */ |
| 221 | 0x000000ff, /* src_mask */ |
| 222 | 0x000000ff, /* dst_mask */ |
| 223 | TRUE), /* pcrel_offset */ |
| 224 | |
| 225 | HOWTO (R_ARM_AMP_VCALL9, /* type */ |
| 226 | 1, /* rightshift */ |
| 227 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 228 | 8, /* bitsize */ |
| 229 | TRUE, /* pc_relative */ |
| 230 | 0, /* bitpos */ |
| 231 | complain_overflow_signed,/* complain_on_overflow */ |
| 232 | bfd_elf_generic_reloc, /* special_function */ |
| 233 | "R_ARM_AMP_VCALL9", /* name */ |
| 234 | FALSE, /* partial_inplace */ |
| 235 | 0x000000ff, /* src_mask */ |
| 236 | 0x000000ff, /* dst_mask */ |
| 237 | TRUE), /* pcrel_offset */ |
| 238 | |
| 239 | HOWTO (R_ARM_SWI24, /* type */ |
| 240 | 0, /* rightshift */ |
| 241 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 242 | 0, /* bitsize */ |
| 243 | FALSE, /* pc_relative */ |
| 244 | 0, /* bitpos */ |
| 245 | complain_overflow_signed,/* complain_on_overflow */ |
| 246 | bfd_elf_generic_reloc, /* special_function */ |
| 247 | "R_ARM_SWI24", /* name */ |
| 248 | FALSE, /* partial_inplace */ |
| 249 | 0x00000000, /* src_mask */ |
| 250 | 0x00000000, /* dst_mask */ |
| 251 | FALSE), /* pcrel_offset */ |
| 252 | |
| 253 | HOWTO (R_ARM_THM_SWI8, /* type */ |
| 254 | 0, /* rightshift */ |
| 255 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 256 | 0, /* bitsize */ |
| 257 | FALSE, /* pc_relative */ |
| 258 | 0, /* bitpos */ |
| 259 | complain_overflow_signed,/* complain_on_overflow */ |
| 260 | bfd_elf_generic_reloc, /* special_function */ |
| 261 | "R_ARM_SWI8", /* name */ |
| 262 | FALSE, /* partial_inplace */ |
| 263 | 0x00000000, /* src_mask */ |
| 264 | 0x00000000, /* dst_mask */ |
| 265 | FALSE), /* pcrel_offset */ |
| 266 | |
| 267 | /* BLX instruction for the ARM. */ |
| 268 | HOWTO (R_ARM_XPC25, /* type */ |
| 269 | 2, /* rightshift */ |
| 270 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 271 | 25, /* bitsize */ |
| 272 | TRUE, /* pc_relative */ |
| 273 | 0, /* bitpos */ |
| 274 | complain_overflow_signed,/* complain_on_overflow */ |
| 275 | bfd_elf_generic_reloc, /* special_function */ |
| 276 | "R_ARM_XPC25", /* name */ |
| 277 | FALSE, /* partial_inplace */ |
| 278 | 0x00ffffff, /* src_mask */ |
| 279 | 0x00ffffff, /* dst_mask */ |
| 280 | TRUE), /* pcrel_offset */ |
| 281 | |
| 282 | /* BLX instruction for the Thumb. */ |
| 283 | HOWTO (R_ARM_THM_XPC22, /* type */ |
| 284 | 2, /* rightshift */ |
| 285 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 286 | 22, /* bitsize */ |
| 287 | TRUE, /* pc_relative */ |
| 288 | 0, /* bitpos */ |
| 289 | complain_overflow_signed,/* complain_on_overflow */ |
| 290 | bfd_elf_generic_reloc, /* special_function */ |
| 291 | "R_ARM_THM_XPC22", /* name */ |
| 292 | FALSE, /* partial_inplace */ |
| 293 | 0x07ff07ff, /* src_mask */ |
| 294 | 0x07ff07ff, /* dst_mask */ |
| 295 | TRUE), /* pcrel_offset */ |
| 296 | |
| 297 | /* Dynamic TLS relocations. */ |
| 298 | |
| 299 | HOWTO (R_ARM_TLS_DTPMOD32, /* type */ |
| 300 | 0, /* rightshift */ |
| 301 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 302 | 32, /* bitsize */ |
| 303 | FALSE, /* pc_relative */ |
| 304 | 0, /* bitpos */ |
| 305 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 306 | bfd_elf_generic_reloc, /* special_function */ |
| 307 | "R_ARM_TLS_DTPMOD32", /* name */ |
| 308 | TRUE, /* partial_inplace */ |
| 309 | 0xffffffff, /* src_mask */ |
| 310 | 0xffffffff, /* dst_mask */ |
| 311 | FALSE), /* pcrel_offset */ |
| 312 | |
| 313 | HOWTO (R_ARM_TLS_DTPOFF32, /* type */ |
| 314 | 0, /* rightshift */ |
| 315 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 316 | 32, /* bitsize */ |
| 317 | FALSE, /* pc_relative */ |
| 318 | 0, /* bitpos */ |
| 319 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 320 | bfd_elf_generic_reloc, /* special_function */ |
| 321 | "R_ARM_TLS_DTPOFF32", /* name */ |
| 322 | TRUE, /* partial_inplace */ |
| 323 | 0xffffffff, /* src_mask */ |
| 324 | 0xffffffff, /* dst_mask */ |
| 325 | FALSE), /* pcrel_offset */ |
| 326 | |
| 327 | HOWTO (R_ARM_TLS_TPOFF32, /* type */ |
| 328 | 0, /* rightshift */ |
| 329 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 330 | 32, /* bitsize */ |
| 331 | FALSE, /* pc_relative */ |
| 332 | 0, /* bitpos */ |
| 333 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 334 | bfd_elf_generic_reloc, /* special_function */ |
| 335 | "R_ARM_TLS_TPOFF32", /* name */ |
| 336 | TRUE, /* partial_inplace */ |
| 337 | 0xffffffff, /* src_mask */ |
| 338 | 0xffffffff, /* dst_mask */ |
| 339 | FALSE), /* pcrel_offset */ |
| 340 | |
| 341 | /* Relocs used in ARM Linux */ |
| 342 | |
| 343 | HOWTO (R_ARM_COPY, /* type */ |
| 344 | 0, /* rightshift */ |
| 345 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 346 | 32, /* bitsize */ |
| 347 | FALSE, /* pc_relative */ |
| 348 | 0, /* bitpos */ |
| 349 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 350 | bfd_elf_generic_reloc, /* special_function */ |
| 351 | "R_ARM_COPY", /* name */ |
| 352 | TRUE, /* partial_inplace */ |
| 353 | 0xffffffff, /* src_mask */ |
| 354 | 0xffffffff, /* dst_mask */ |
| 355 | FALSE), /* pcrel_offset */ |
| 356 | |
| 357 | HOWTO (R_ARM_GLOB_DAT, /* type */ |
| 358 | 0, /* rightshift */ |
| 359 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 360 | 32, /* bitsize */ |
| 361 | FALSE, /* pc_relative */ |
| 362 | 0, /* bitpos */ |
| 363 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 364 | bfd_elf_generic_reloc, /* special_function */ |
| 365 | "R_ARM_GLOB_DAT", /* name */ |
| 366 | TRUE, /* partial_inplace */ |
| 367 | 0xffffffff, /* src_mask */ |
| 368 | 0xffffffff, /* dst_mask */ |
| 369 | FALSE), /* pcrel_offset */ |
| 370 | |
| 371 | HOWTO (R_ARM_JUMP_SLOT, /* type */ |
| 372 | 0, /* rightshift */ |
| 373 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 374 | 32, /* bitsize */ |
| 375 | FALSE, /* pc_relative */ |
| 376 | 0, /* bitpos */ |
| 377 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 378 | bfd_elf_generic_reloc, /* special_function */ |
| 379 | "R_ARM_JUMP_SLOT", /* name */ |
| 380 | TRUE, /* partial_inplace */ |
| 381 | 0xffffffff, /* src_mask */ |
| 382 | 0xffffffff, /* dst_mask */ |
| 383 | FALSE), /* pcrel_offset */ |
| 384 | |
| 385 | HOWTO (R_ARM_RELATIVE, /* type */ |
| 386 | 0, /* rightshift */ |
| 387 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 388 | 32, /* bitsize */ |
| 389 | FALSE, /* pc_relative */ |
| 390 | 0, /* bitpos */ |
| 391 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 392 | bfd_elf_generic_reloc, /* special_function */ |
| 393 | "R_ARM_RELATIVE", /* name */ |
| 394 | TRUE, /* partial_inplace */ |
| 395 | 0xffffffff, /* src_mask */ |
| 396 | 0xffffffff, /* dst_mask */ |
| 397 | FALSE), /* pcrel_offset */ |
| 398 | |
| 399 | HOWTO (R_ARM_GOTOFF, /* type */ |
| 400 | 0, /* rightshift */ |
| 401 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 402 | 32, /* bitsize */ |
| 403 | FALSE, /* pc_relative */ |
| 404 | 0, /* bitpos */ |
| 405 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 406 | bfd_elf_generic_reloc, /* special_function */ |
| 407 | "R_ARM_GOTOFF", /* name */ |
| 408 | TRUE, /* partial_inplace */ |
| 409 | 0xffffffff, /* src_mask */ |
| 410 | 0xffffffff, /* dst_mask */ |
| 411 | FALSE), /* pcrel_offset */ |
| 412 | |
| 413 | HOWTO (R_ARM_GOTPC, /* type */ |
| 414 | 0, /* rightshift */ |
| 415 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 416 | 32, /* bitsize */ |
| 417 | TRUE, /* pc_relative */ |
| 418 | 0, /* bitpos */ |
| 419 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 420 | bfd_elf_generic_reloc, /* special_function */ |
| 421 | "R_ARM_GOTPC", /* name */ |
| 422 | TRUE, /* partial_inplace */ |
| 423 | 0xffffffff, /* src_mask */ |
| 424 | 0xffffffff, /* dst_mask */ |
| 425 | TRUE), /* pcrel_offset */ |
| 426 | |
| 427 | HOWTO (R_ARM_GOT32, /* type */ |
| 428 | 0, /* rightshift */ |
| 429 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 430 | 32, /* bitsize */ |
| 431 | FALSE, /* pc_relative */ |
| 432 | 0, /* bitpos */ |
| 433 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 434 | bfd_elf_generic_reloc, /* special_function */ |
| 435 | "R_ARM_GOT32", /* name */ |
| 436 | TRUE, /* partial_inplace */ |
| 437 | 0xffffffff, /* src_mask */ |
| 438 | 0xffffffff, /* dst_mask */ |
| 439 | FALSE), /* pcrel_offset */ |
| 440 | |
| 441 | HOWTO (R_ARM_PLT32, /* type */ |
| 442 | 2, /* rightshift */ |
| 443 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 444 | 26, /* bitsize */ |
| 445 | TRUE, /* pc_relative */ |
| 446 | 0, /* bitpos */ |
| 447 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 448 | bfd_elf_generic_reloc, /* special_function */ |
| 449 | "R_ARM_PLT32", /* name */ |
| 450 | TRUE, /* partial_inplace */ |
| 451 | 0x00ffffff, /* src_mask */ |
| 452 | 0x00ffffff, /* dst_mask */ |
| 453 | TRUE), /* pcrel_offset */ |
| 454 | |
| 455 | HOWTO (R_ARM_CALL, /* type */ |
| 456 | 2, /* rightshift */ |
| 457 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 458 | 24, /* bitsize */ |
| 459 | TRUE, /* pc_relative */ |
| 460 | 0, /* bitpos */ |
| 461 | complain_overflow_signed,/* complain_on_overflow */ |
| 462 | bfd_elf_generic_reloc, /* special_function */ |
| 463 | "R_ARM_CALL", /* name */ |
| 464 | FALSE, /* partial_inplace */ |
| 465 | 0x00ffffff, /* src_mask */ |
| 466 | 0x00ffffff, /* dst_mask */ |
| 467 | TRUE), /* pcrel_offset */ |
| 468 | |
| 469 | HOWTO (R_ARM_JUMP24, /* type */ |
| 470 | 2, /* rightshift */ |
| 471 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 472 | 24, /* bitsize */ |
| 473 | TRUE, /* pc_relative */ |
| 474 | 0, /* bitpos */ |
| 475 | complain_overflow_signed,/* complain_on_overflow */ |
| 476 | bfd_elf_generic_reloc, /* special_function */ |
| 477 | "R_ARM_JUMP24", /* name */ |
| 478 | FALSE, /* partial_inplace */ |
| 479 | 0x00ffffff, /* src_mask */ |
| 480 | 0x00ffffff, /* dst_mask */ |
| 481 | TRUE), /* pcrel_offset */ |
| 482 | |
| 483 | HOWTO (R_ARM_NONE, /* type */ |
| 484 | 0, /* rightshift */ |
| 485 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 486 | 0, /* bitsize */ |
| 487 | FALSE, /* pc_relative */ |
| 488 | 0, /* bitpos */ |
| 489 | complain_overflow_dont,/* complain_on_overflow */ |
| 490 | bfd_elf_generic_reloc, /* special_function */ |
| 491 | "R_ARM_unknown_30", /* name */ |
| 492 | FALSE, /* partial_inplace */ |
| 493 | 0, /* src_mask */ |
| 494 | 0, /* dst_mask */ |
| 495 | FALSE), /* pcrel_offset */ |
| 496 | |
| 497 | HOWTO (R_ARM_NONE, /* type */ |
| 498 | 0, /* rightshift */ |
| 499 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 500 | 0, /* bitsize */ |
| 501 | FALSE, /* pc_relative */ |
| 502 | 0, /* bitpos */ |
| 503 | complain_overflow_dont,/* complain_on_overflow */ |
| 504 | bfd_elf_generic_reloc, /* special_function */ |
| 505 | "R_ARM_unknown_31", /* name */ |
| 506 | FALSE, /* partial_inplace */ |
| 507 | 0, /* src_mask */ |
| 508 | 0, /* dst_mask */ |
| 509 | FALSE), /* pcrel_offset */ |
| 510 | |
| 511 | HOWTO (R_ARM_ALU_PCREL7_0, /* type */ |
| 512 | 0, /* rightshift */ |
| 513 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 514 | 12, /* bitsize */ |
| 515 | TRUE, /* pc_relative */ |
| 516 | 0, /* bitpos */ |
| 517 | complain_overflow_dont,/* complain_on_overflow */ |
| 518 | bfd_elf_generic_reloc, /* special_function */ |
| 519 | "R_ARM_ALU_PCREL_7_0", /* name */ |
| 520 | FALSE, /* partial_inplace */ |
| 521 | 0x00000fff, /* src_mask */ |
| 522 | 0x00000fff, /* dst_mask */ |
| 523 | TRUE), /* pcrel_offset */ |
| 524 | |
| 525 | HOWTO (R_ARM_ALU_PCREL15_8, /* type */ |
| 526 | 0, /* rightshift */ |
| 527 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 528 | 12, /* bitsize */ |
| 529 | TRUE, /* pc_relative */ |
| 530 | 8, /* bitpos */ |
| 531 | complain_overflow_dont,/* complain_on_overflow */ |
| 532 | bfd_elf_generic_reloc, /* special_function */ |
| 533 | "R_ARM_ALU_PCREL_15_8",/* name */ |
| 534 | FALSE, /* partial_inplace */ |
| 535 | 0x00000fff, /* src_mask */ |
| 536 | 0x00000fff, /* dst_mask */ |
| 537 | TRUE), /* pcrel_offset */ |
| 538 | |
| 539 | HOWTO (R_ARM_ALU_PCREL23_15, /* type */ |
| 540 | 0, /* rightshift */ |
| 541 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 542 | 12, /* bitsize */ |
| 543 | TRUE, /* pc_relative */ |
| 544 | 16, /* bitpos */ |
| 545 | complain_overflow_dont,/* complain_on_overflow */ |
| 546 | bfd_elf_generic_reloc, /* special_function */ |
| 547 | "R_ARM_ALU_PCREL_23_15",/* name */ |
| 548 | FALSE, /* partial_inplace */ |
| 549 | 0x00000fff, /* src_mask */ |
| 550 | 0x00000fff, /* dst_mask */ |
| 551 | TRUE), /* pcrel_offset */ |
| 552 | |
| 553 | HOWTO (R_ARM_LDR_SBREL_11_0, /* type */ |
| 554 | 0, /* rightshift */ |
| 555 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 556 | 12, /* bitsize */ |
| 557 | FALSE, /* pc_relative */ |
| 558 | 0, /* bitpos */ |
| 559 | complain_overflow_dont,/* complain_on_overflow */ |
| 560 | bfd_elf_generic_reloc, /* special_function */ |
| 561 | "R_ARM_LDR_SBREL_11_0",/* name */ |
| 562 | FALSE, /* partial_inplace */ |
| 563 | 0x00000fff, /* src_mask */ |
| 564 | 0x00000fff, /* dst_mask */ |
| 565 | FALSE), /* pcrel_offset */ |
| 566 | |
| 567 | HOWTO (R_ARM_ALU_SBREL_19_12, /* type */ |
| 568 | 0, /* rightshift */ |
| 569 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 570 | 8, /* bitsize */ |
| 571 | FALSE, /* pc_relative */ |
| 572 | 12, /* bitpos */ |
| 573 | complain_overflow_dont,/* complain_on_overflow */ |
| 574 | bfd_elf_generic_reloc, /* special_function */ |
| 575 | "R_ARM_ALU_SBREL_19_12",/* name */ |
| 576 | FALSE, /* partial_inplace */ |
| 577 | 0x000ff000, /* src_mask */ |
| 578 | 0x000ff000, /* dst_mask */ |
| 579 | FALSE), /* pcrel_offset */ |
| 580 | |
| 581 | HOWTO (R_ARM_ALU_SBREL_27_20, /* type */ |
| 582 | 0, /* rightshift */ |
| 583 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 584 | 8, /* bitsize */ |
| 585 | FALSE, /* pc_relative */ |
| 586 | 20, /* bitpos */ |
| 587 | complain_overflow_dont,/* complain_on_overflow */ |
| 588 | bfd_elf_generic_reloc, /* special_function */ |
| 589 | "R_ARM_ALU_SBREL_27_20",/* name */ |
| 590 | FALSE, /* partial_inplace */ |
| 591 | 0x0ff00000, /* src_mask */ |
| 592 | 0x0ff00000, /* dst_mask */ |
| 593 | FALSE), /* pcrel_offset */ |
| 594 | |
| 595 | HOWTO (R_ARM_TARGET1, /* type */ |
| 596 | 0, /* rightshift */ |
| 597 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 598 | 32, /* bitsize */ |
| 599 | FALSE, /* pc_relative */ |
| 600 | 0, /* bitpos */ |
| 601 | complain_overflow_dont,/* complain_on_overflow */ |
| 602 | bfd_elf_generic_reloc, /* special_function */ |
| 603 | "R_ARM_TARGET1", /* name */ |
| 604 | FALSE, /* partial_inplace */ |
| 605 | 0xffffffff, /* src_mask */ |
| 606 | 0xffffffff, /* dst_mask */ |
| 607 | FALSE), /* pcrel_offset */ |
| 608 | |
| 609 | HOWTO (R_ARM_ROSEGREL32, /* type */ |
| 610 | 0, /* rightshift */ |
| 611 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 612 | 32, /* bitsize */ |
| 613 | FALSE, /* pc_relative */ |
| 614 | 0, /* bitpos */ |
| 615 | complain_overflow_dont,/* complain_on_overflow */ |
| 616 | bfd_elf_generic_reloc, /* special_function */ |
| 617 | "R_ARM_ROSEGREL32", /* name */ |
| 618 | FALSE, /* partial_inplace */ |
| 619 | 0xffffffff, /* src_mask */ |
| 620 | 0xffffffff, /* dst_mask */ |
| 621 | FALSE), /* pcrel_offset */ |
| 622 | |
| 623 | HOWTO (R_ARM_V4BX, /* type */ |
| 624 | 0, /* rightshift */ |
| 625 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 626 | 32, /* bitsize */ |
| 627 | FALSE, /* pc_relative */ |
| 628 | 0, /* bitpos */ |
| 629 | complain_overflow_dont,/* complain_on_overflow */ |
| 630 | bfd_elf_generic_reloc, /* special_function */ |
| 631 | "R_ARM_V4BX", /* name */ |
| 632 | FALSE, /* partial_inplace */ |
| 633 | 0xffffffff, /* src_mask */ |
| 634 | 0xffffffff, /* dst_mask */ |
| 635 | FALSE), /* pcrel_offset */ |
| 636 | |
| 637 | HOWTO (R_ARM_TARGET2, /* type */ |
| 638 | 0, /* rightshift */ |
| 639 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 640 | 32, /* bitsize */ |
| 641 | FALSE, /* pc_relative */ |
| 642 | 0, /* bitpos */ |
| 643 | complain_overflow_signed,/* complain_on_overflow */ |
| 644 | bfd_elf_generic_reloc, /* special_function */ |
| 645 | "R_ARM_TARGET2", /* name */ |
| 646 | FALSE, /* partial_inplace */ |
| 647 | 0xffffffff, /* src_mask */ |
| 648 | 0xffffffff, /* dst_mask */ |
| 649 | TRUE), /* pcrel_offset */ |
| 650 | |
| 651 | HOWTO (R_ARM_PREL31, /* type */ |
| 652 | 0, /* rightshift */ |
| 653 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 654 | 31, /* bitsize */ |
| 655 | TRUE, /* pc_relative */ |
| 656 | 0, /* bitpos */ |
| 657 | complain_overflow_signed,/* complain_on_overflow */ |
| 658 | bfd_elf_generic_reloc, /* special_function */ |
| 659 | "R_ARM_PREL31", /* name */ |
| 660 | FALSE, /* partial_inplace */ |
| 661 | 0x7fffffff, /* src_mask */ |
| 662 | 0x7fffffff, /* dst_mask */ |
| 663 | TRUE), /* pcrel_offset */ |
| 664 | }; |
| 665 | |
| 666 | static reloc_howto_type elf32_arm_tls_gd32_howto = |
| 667 | HOWTO (R_ARM_TLS_GD32, /* type */ |
| 668 | 0, /* rightshift */ |
| 669 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 670 | 32, /* bitsize */ |
| 671 | FALSE, /* pc_relative */ |
| 672 | 0, /* bitpos */ |
| 673 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 674 | NULL, /* special_function */ |
| 675 | "R_ARM_TLS_GD32", /* name */ |
| 676 | TRUE, /* partial_inplace */ |
| 677 | 0xffffffff, /* src_mask */ |
| 678 | 0xffffffff, /* dst_mask */ |
| 679 | FALSE); /* pcrel_offset */ |
| 680 | |
| 681 | static reloc_howto_type elf32_arm_tls_ldo32_howto = |
| 682 | HOWTO (R_ARM_TLS_LDO32, /* type */ |
| 683 | 0, /* rightshift */ |
| 684 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 685 | 32, /* bitsize */ |
| 686 | FALSE, /* pc_relative */ |
| 687 | 0, /* bitpos */ |
| 688 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 689 | bfd_elf_generic_reloc, /* special_function */ |
| 690 | "R_ARM_TLS_LDO32", /* name */ |
| 691 | TRUE, /* partial_inplace */ |
| 692 | 0xffffffff, /* src_mask */ |
| 693 | 0xffffffff, /* dst_mask */ |
| 694 | FALSE); /* pcrel_offset */ |
| 695 | |
| 696 | static reloc_howto_type elf32_arm_tls_ldm32_howto = |
| 697 | HOWTO (R_ARM_TLS_LDM32, /* type */ |
| 698 | 0, /* rightshift */ |
| 699 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 700 | 32, /* bitsize */ |
| 701 | FALSE, /* pc_relative */ |
| 702 | 0, /* bitpos */ |
| 703 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 704 | bfd_elf_generic_reloc, /* special_function */ |
| 705 | "R_ARM_TLS_LDM32", /* name */ |
| 706 | TRUE, /* partial_inplace */ |
| 707 | 0xffffffff, /* src_mask */ |
| 708 | 0xffffffff, /* dst_mask */ |
| 709 | FALSE); /* pcrel_offset */ |
| 710 | |
| 711 | static reloc_howto_type elf32_arm_tls_le32_howto = |
| 712 | HOWTO (R_ARM_TLS_LE32, /* type */ |
| 713 | 0, /* rightshift */ |
| 714 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 715 | 32, /* bitsize */ |
| 716 | FALSE, /* pc_relative */ |
| 717 | 0, /* bitpos */ |
| 718 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 719 | bfd_elf_generic_reloc, /* special_function */ |
| 720 | "R_ARM_TLS_LE32", /* name */ |
| 721 | TRUE, /* partial_inplace */ |
| 722 | 0xffffffff, /* src_mask */ |
| 723 | 0xffffffff, /* dst_mask */ |
| 724 | FALSE); /* pcrel_offset */ |
| 725 | |
| 726 | static reloc_howto_type elf32_arm_tls_ie32_howto = |
| 727 | HOWTO (R_ARM_TLS_IE32, /* type */ |
| 728 | 0, /* rightshift */ |
| 729 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 730 | 32, /* bitsize */ |
| 731 | FALSE, /* pc_relative */ |
| 732 | 0, /* bitpos */ |
| 733 | complain_overflow_bitfield,/* complain_on_overflow */ |
| 734 | NULL, /* special_function */ |
| 735 | "R_ARM_TLS_IE32", /* name */ |
| 736 | TRUE, /* partial_inplace */ |
| 737 | 0xffffffff, /* src_mask */ |
| 738 | 0xffffffff, /* dst_mask */ |
| 739 | FALSE); /* pcrel_offset */ |
| 740 | |
| 741 | /* GNU extension to record C++ vtable hierarchy */ |
| 742 | static reloc_howto_type elf32_arm_vtinherit_howto = |
| 743 | HOWTO (R_ARM_GNU_VTINHERIT, /* type */ |
| 744 | 0, /* rightshift */ |
| 745 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 746 | 0, /* bitsize */ |
| 747 | FALSE, /* pc_relative */ |
| 748 | 0, /* bitpos */ |
| 749 | complain_overflow_dont, /* complain_on_overflow */ |
| 750 | NULL, /* special_function */ |
| 751 | "R_ARM_GNU_VTINHERIT", /* name */ |
| 752 | FALSE, /* partial_inplace */ |
| 753 | 0, /* src_mask */ |
| 754 | 0, /* dst_mask */ |
| 755 | FALSE); /* pcrel_offset */ |
| 756 | |
| 757 | /* GNU extension to record C++ vtable member usage */ |
| 758 | static reloc_howto_type elf32_arm_vtentry_howto = |
| 759 | HOWTO (R_ARM_GNU_VTENTRY, /* type */ |
| 760 | 0, /* rightshift */ |
| 761 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 762 | 0, /* bitsize */ |
| 763 | FALSE, /* pc_relative */ |
| 764 | 0, /* bitpos */ |
| 765 | complain_overflow_dont, /* complain_on_overflow */ |
| 766 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ |
| 767 | "R_ARM_GNU_VTENTRY", /* name */ |
| 768 | FALSE, /* partial_inplace */ |
| 769 | 0, /* src_mask */ |
| 770 | 0, /* dst_mask */ |
| 771 | FALSE); /* pcrel_offset */ |
| 772 | |
| 773 | /* 12 bit pc relative */ |
| 774 | static reloc_howto_type elf32_arm_thm_pc11_howto = |
| 775 | HOWTO (R_ARM_THM_PC11, /* type */ |
| 776 | 1, /* rightshift */ |
| 777 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 778 | 11, /* bitsize */ |
| 779 | TRUE, /* pc_relative */ |
| 780 | 0, /* bitpos */ |
| 781 | complain_overflow_signed, /* complain_on_overflow */ |
| 782 | bfd_elf_generic_reloc, /* special_function */ |
| 783 | "R_ARM_THM_PC11", /* name */ |
| 784 | FALSE, /* partial_inplace */ |
| 785 | 0x000007ff, /* src_mask */ |
| 786 | 0x000007ff, /* dst_mask */ |
| 787 | TRUE); /* pcrel_offset */ |
| 788 | |
| 789 | /* 12 bit pc relative */ |
| 790 | static reloc_howto_type elf32_arm_thm_pc9_howto = |
| 791 | HOWTO (R_ARM_THM_PC9, /* type */ |
| 792 | 1, /* rightshift */ |
| 793 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
| 794 | 8, /* bitsize */ |
| 795 | TRUE, /* pc_relative */ |
| 796 | 0, /* bitpos */ |
| 797 | complain_overflow_signed, /* complain_on_overflow */ |
| 798 | bfd_elf_generic_reloc, /* special_function */ |
| 799 | "R_ARM_THM_PC9", /* name */ |
| 800 | FALSE, /* partial_inplace */ |
| 801 | 0x000000ff, /* src_mask */ |
| 802 | 0x000000ff, /* dst_mask */ |
| 803 | TRUE); /* pcrel_offset */ |
| 804 | |
| 805 | /* Place relative GOT-indirect. */ |
| 806 | static reloc_howto_type elf32_arm_got_prel = |
| 807 | HOWTO (R_ARM_GOT_PREL, /* type */ |
| 808 | 0, /* rightshift */ |
| 809 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 810 | 32, /* bitsize */ |
| 811 | TRUE, /* pc_relative */ |
| 812 | 0, /* bitpos */ |
| 813 | complain_overflow_dont, /* complain_on_overflow */ |
| 814 | bfd_elf_generic_reloc, /* special_function */ |
| 815 | "R_ARM_GOT_PREL", /* name */ |
| 816 | FALSE, /* partial_inplace */ |
| 817 | 0xffffffff, /* src_mask */ |
| 818 | 0xffffffff, /* dst_mask */ |
| 819 | TRUE); /* pcrel_offset */ |
| 820 | |
| 821 | /* Currently unused relocations. */ |
| 822 | static reloc_howto_type elf32_arm_r_howto[4] = |
| 823 | { |
| 824 | HOWTO (R_ARM_RREL32, /* type */ |
| 825 | 0, /* rightshift */ |
| 826 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 827 | 0, /* bitsize */ |
| 828 | FALSE, /* pc_relative */ |
| 829 | 0, /* bitpos */ |
| 830 | complain_overflow_dont,/* complain_on_overflow */ |
| 831 | bfd_elf_generic_reloc, /* special_function */ |
| 832 | "R_ARM_RREL32", /* name */ |
| 833 | FALSE, /* partial_inplace */ |
| 834 | 0, /* src_mask */ |
| 835 | 0, /* dst_mask */ |
| 836 | FALSE), /* pcrel_offset */ |
| 837 | |
| 838 | HOWTO (R_ARM_RABS32, /* type */ |
| 839 | 0, /* rightshift */ |
| 840 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 841 | 0, /* bitsize */ |
| 842 | FALSE, /* pc_relative */ |
| 843 | 0, /* bitpos */ |
| 844 | complain_overflow_dont,/* complain_on_overflow */ |
| 845 | bfd_elf_generic_reloc, /* special_function */ |
| 846 | "R_ARM_RABS32", /* name */ |
| 847 | FALSE, /* partial_inplace */ |
| 848 | 0, /* src_mask */ |
| 849 | 0, /* dst_mask */ |
| 850 | FALSE), /* pcrel_offset */ |
| 851 | |
| 852 | HOWTO (R_ARM_RPC24, /* type */ |
| 853 | 0, /* rightshift */ |
| 854 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 855 | 0, /* bitsize */ |
| 856 | FALSE, /* pc_relative */ |
| 857 | 0, /* bitpos */ |
| 858 | complain_overflow_dont,/* complain_on_overflow */ |
| 859 | bfd_elf_generic_reloc, /* special_function */ |
| 860 | "R_ARM_RPC24", /* name */ |
| 861 | FALSE, /* partial_inplace */ |
| 862 | 0, /* src_mask */ |
| 863 | 0, /* dst_mask */ |
| 864 | FALSE), /* pcrel_offset */ |
| 865 | |
| 866 | HOWTO (R_ARM_RBASE, /* type */ |
| 867 | 0, /* rightshift */ |
| 868 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 869 | 0, /* bitsize */ |
| 870 | FALSE, /* pc_relative */ |
| 871 | 0, /* bitpos */ |
| 872 | complain_overflow_dont,/* complain_on_overflow */ |
| 873 | bfd_elf_generic_reloc, /* special_function */ |
| 874 | "R_ARM_RBASE", /* name */ |
| 875 | FALSE, /* partial_inplace */ |
| 876 | 0, /* src_mask */ |
| 877 | 0, /* dst_mask */ |
| 878 | FALSE) /* pcrel_offset */ |
| 879 | }; |
| 880 | |
| 881 | static reloc_howto_type * |
| 882 | elf32_arm_howto_from_type (unsigned int r_type) |
| 883 | { |
| 884 | if (r_type < NUM_ELEM (elf32_arm_howto_table)) |
| 885 | return &elf32_arm_howto_table[r_type]; |
| 886 | |
| 887 | switch (r_type) |
| 888 | { |
| 889 | case R_ARM_GOT_PREL: |
| 890 | return &elf32_arm_got_prel; |
| 891 | |
| 892 | case R_ARM_GNU_VTINHERIT: |
| 893 | return &elf32_arm_vtinherit_howto; |
| 894 | |
| 895 | case R_ARM_GNU_VTENTRY: |
| 896 | return &elf32_arm_vtentry_howto; |
| 897 | |
| 898 | case R_ARM_THM_PC11: |
| 899 | return &elf32_arm_thm_pc11_howto; |
| 900 | |
| 901 | case R_ARM_THM_PC9: |
| 902 | return &elf32_arm_thm_pc9_howto; |
| 903 | |
| 904 | case R_ARM_TLS_GD32: |
| 905 | return &elf32_arm_tls_gd32_howto; |
| 906 | break; |
| 907 | |
| 908 | case R_ARM_TLS_LDO32: |
| 909 | return &elf32_arm_tls_ldo32_howto; |
| 910 | break; |
| 911 | |
| 912 | case R_ARM_TLS_LDM32: |
| 913 | return &elf32_arm_tls_ldm32_howto; |
| 914 | break; |
| 915 | |
| 916 | case R_ARM_TLS_IE32: |
| 917 | return &elf32_arm_tls_ie32_howto; |
| 918 | break; |
| 919 | |
| 920 | case R_ARM_TLS_LE32: |
| 921 | return &elf32_arm_tls_le32_howto; |
| 922 | break; |
| 923 | |
| 924 | case R_ARM_RREL32: |
| 925 | case R_ARM_RABS32: |
| 926 | case R_ARM_RPC24: |
| 927 | case R_ARM_RBASE: |
| 928 | return &elf32_arm_r_howto[r_type - R_ARM_RREL32]; |
| 929 | |
| 930 | default: |
| 931 | return NULL; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | static void |
| 936 | elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc, |
| 937 | Elf_Internal_Rela * elf_reloc) |
| 938 | { |
| 939 | unsigned int r_type; |
| 940 | |
| 941 | r_type = ELF32_R_TYPE (elf_reloc->r_info); |
| 942 | bfd_reloc->howto = elf32_arm_howto_from_type (r_type); |
| 943 | } |
| 944 | |
| 945 | struct elf32_arm_reloc_map |
| 946 | { |
| 947 | bfd_reloc_code_real_type bfd_reloc_val; |
| 948 | unsigned char elf_reloc_val; |
| 949 | }; |
| 950 | |
| 951 | /* All entries in this list must also be present in elf32_arm_howto_table. */ |
| 952 | static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] = |
| 953 | { |
| 954 | {BFD_RELOC_NONE, R_ARM_NONE}, |
| 955 | {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24}, |
| 956 | {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25}, |
| 957 | {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22}, |
| 958 | {BFD_RELOC_32, R_ARM_ABS32}, |
| 959 | {BFD_RELOC_32_PCREL, R_ARM_REL32}, |
| 960 | {BFD_RELOC_8, R_ARM_ABS8}, |
| 961 | {BFD_RELOC_16, R_ARM_ABS16}, |
| 962 | {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12}, |
| 963 | {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5}, |
| 964 | {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_PC22}, |
| 965 | {BFD_RELOC_ARM_COPY, R_ARM_COPY}, |
| 966 | {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT}, |
| 967 | {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT}, |
| 968 | {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE}, |
| 969 | {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF}, |
| 970 | {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC}, |
| 971 | {BFD_RELOC_ARM_GOT32, R_ARM_GOT32}, |
| 972 | {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, |
| 973 | {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1}, |
| 974 | {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32}, |
| 975 | {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32}, |
| 976 | {BFD_RELOC_ARM_PREL31, R_ARM_PREL31}, |
| 977 | {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2}, |
| 978 | {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, |
| 979 | {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32}, |
| 980 | {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32}, |
| 981 | {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32}, |
| 982 | {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32}, |
| 983 | {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32}, |
| 984 | {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32}, |
| 985 | {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32}, |
| 986 | {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32}, |
| 987 | }; |
| 988 | |
| 989 | static reloc_howto_type * |
| 990 | elf32_arm_reloc_type_lookup (abfd, code) |
| 991 | bfd *abfd ATTRIBUTE_UNUSED; |
| 992 | bfd_reloc_code_real_type code; |
| 993 | { |
| 994 | unsigned int i; |
| 995 | |
| 996 | switch (code) |
| 997 | { |
| 998 | case BFD_RELOC_VTABLE_INHERIT: |
| 999 | return & elf32_arm_vtinherit_howto; |
| 1000 | |
| 1001 | case BFD_RELOC_VTABLE_ENTRY: |
| 1002 | return & elf32_arm_vtentry_howto; |
| 1003 | |
| 1004 | case BFD_RELOC_THUMB_PCREL_BRANCH12: |
| 1005 | return & elf32_arm_thm_pc11_howto; |
| 1006 | |
| 1007 | case BFD_RELOC_THUMB_PCREL_BRANCH9: |
| 1008 | return & elf32_arm_thm_pc9_howto; |
| 1009 | |
| 1010 | case BFD_RELOC_ARM_TLS_GD32: |
| 1011 | return & elf32_arm_tls_gd32_howto; |
| 1012 | |
| 1013 | case BFD_RELOC_ARM_TLS_LDO32: |
| 1014 | return & elf32_arm_tls_ldo32_howto; |
| 1015 | |
| 1016 | case BFD_RELOC_ARM_TLS_LDM32: |
| 1017 | return & elf32_arm_tls_ldm32_howto; |
| 1018 | |
| 1019 | case BFD_RELOC_ARM_TLS_IE32: |
| 1020 | return & elf32_arm_tls_ie32_howto; |
| 1021 | |
| 1022 | case BFD_RELOC_ARM_TLS_LE32: |
| 1023 | return & elf32_arm_tls_le32_howto; |
| 1024 | |
| 1025 | default: |
| 1026 | for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++) |
| 1027 | if (elf32_arm_reloc_map[i].bfd_reloc_val == code) |
| 1028 | return & elf32_arm_howto_table[elf32_arm_reloc_map[i].elf_reloc_val]; |
| 1029 | |
| 1030 | return NULL; |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | /* Support for core dump NOTE sections */ |
| 1035 | static bfd_boolean |
| 1036 | elf32_arm_nabi_grok_prstatus (abfd, note) |
| 1037 | bfd *abfd; |
| 1038 | Elf_Internal_Note *note; |
| 1039 | { |
| 1040 | int offset; |
| 1041 | size_t size; |
| 1042 | |
| 1043 | switch (note->descsz) |
| 1044 | { |
| 1045 | default: |
| 1046 | return FALSE; |
| 1047 | |
| 1048 | case 148: /* Linux/ARM 32-bit*/ |
| 1049 | /* pr_cursig */ |
| 1050 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); |
| 1051 | |
| 1052 | /* pr_pid */ |
| 1053 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); |
| 1054 | |
| 1055 | /* pr_reg */ |
| 1056 | offset = 72; |
| 1057 | size = 72; |
| 1058 | |
| 1059 | break; |
| 1060 | } |
| 1061 | |
| 1062 | /* Make a ".reg/999" section. */ |
| 1063 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", |
| 1064 | size, note->descpos + offset); |
| 1065 | } |
| 1066 | |
| 1067 | static bfd_boolean |
| 1068 | elf32_arm_nabi_grok_psinfo (abfd, note) |
| 1069 | bfd *abfd; |
| 1070 | Elf_Internal_Note *note; |
| 1071 | { |
| 1072 | switch (note->descsz) |
| 1073 | { |
| 1074 | default: |
| 1075 | return FALSE; |
| 1076 | |
| 1077 | case 124: /* Linux/ARM elf_prpsinfo */ |
| 1078 | elf_tdata (abfd)->core_program |
| 1079 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); |
| 1080 | elf_tdata (abfd)->core_command |
| 1081 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); |
| 1082 | } |
| 1083 | |
| 1084 | /* Note that for some reason, a spurious space is tacked |
| 1085 | onto the end of the args in some (at least one anyway) |
| 1086 | implementations, so strip it off if it exists. */ |
| 1087 | |
| 1088 | { |
| 1089 | char *command = elf_tdata (abfd)->core_command; |
| 1090 | int n = strlen (command); |
| 1091 | |
| 1092 | if (0 < n && command[n - 1] == ' ') |
| 1093 | command[n - 1] = '\0'; |
| 1094 | } |
| 1095 | |
| 1096 | return TRUE; |
| 1097 | } |
| 1098 | |
| 1099 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec |
| 1100 | #define TARGET_LITTLE_NAME "elf32-littlearm" |
| 1101 | #define TARGET_BIG_SYM bfd_elf32_bigarm_vec |
| 1102 | #define TARGET_BIG_NAME "elf32-bigarm" |
| 1103 | |
| 1104 | #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus |
| 1105 | #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo |
| 1106 | |
| 1107 | typedef unsigned long int insn32; |
| 1108 | typedef unsigned short int insn16; |
| 1109 | |
| 1110 | /* In lieu of proper flags, assume all EABIv4 objects are interworkable. */ |
| 1111 | #define INTERWORK_FLAG(abfd) \ |
| 1112 | (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) == EF_ARM_EABI_VER4 \ |
| 1113 | || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)) |
| 1114 | |
| 1115 | /* The linker script knows the section names for placement. |
| 1116 | The entry_names are used to do simple name mangling on the stubs. |
| 1117 | Given a function name, and its type, the stub can be found. The |
| 1118 | name can be changed. The only requirement is the %s be present. */ |
| 1119 | #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t" |
| 1120 | #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb" |
| 1121 | |
| 1122 | #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7" |
| 1123 | #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm" |
| 1124 | |
| 1125 | /* The name of the dynamic interpreter. This is put in the .interp |
| 1126 | section. */ |
| 1127 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
| 1128 | |
| 1129 | #ifdef FOUR_WORD_PLT |
| 1130 | |
| 1131 | /* The first entry in a procedure linkage table looks like |
| 1132 | this. It is set up so that any shared library function that is |
| 1133 | called before the relocation has been set up calls the dynamic |
| 1134 | linker first. */ |
| 1135 | static const bfd_vma elf32_arm_plt0_entry [] = |
| 1136 | { |
| 1137 | 0xe52de004, /* str lr, [sp, #-4]! */ |
| 1138 | 0xe59fe010, /* ldr lr, [pc, #16] */ |
| 1139 | 0xe08fe00e, /* add lr, pc, lr */ |
| 1140 | 0xe5bef008, /* ldr pc, [lr, #8]! */ |
| 1141 | }; |
| 1142 | |
| 1143 | /* Subsequent entries in a procedure linkage table look like |
| 1144 | this. */ |
| 1145 | static const bfd_vma elf32_arm_plt_entry [] = |
| 1146 | { |
| 1147 | 0xe28fc600, /* add ip, pc, #NN */ |
| 1148 | 0xe28cca00, /* add ip, ip, #NN */ |
| 1149 | 0xe5bcf000, /* ldr pc, [ip, #NN]! */ |
| 1150 | 0x00000000, /* unused */ |
| 1151 | }; |
| 1152 | |
| 1153 | #else |
| 1154 | |
| 1155 | /* The first entry in a procedure linkage table looks like |
| 1156 | this. It is set up so that any shared library function that is |
| 1157 | called before the relocation has been set up calls the dynamic |
| 1158 | linker first. */ |
| 1159 | static const bfd_vma elf32_arm_plt0_entry [] = |
| 1160 | { |
| 1161 | 0xe52de004, /* str lr, [sp, #-4]! */ |
| 1162 | 0xe59fe004, /* ldr lr, [pc, #4] */ |
| 1163 | 0xe08fe00e, /* add lr, pc, lr */ |
| 1164 | 0xe5bef008, /* ldr pc, [lr, #8]! */ |
| 1165 | 0x00000000, /* &GOT[0] - . */ |
| 1166 | }; |
| 1167 | |
| 1168 | /* Subsequent entries in a procedure linkage table look like |
| 1169 | this. */ |
| 1170 | static const bfd_vma elf32_arm_plt_entry [] = |
| 1171 | { |
| 1172 | 0xe28fc600, /* add ip, pc, #0xNN00000 */ |
| 1173 | 0xe28cca00, /* add ip, ip, #0xNN000 */ |
| 1174 | 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */ |
| 1175 | }; |
| 1176 | |
| 1177 | #endif |
| 1178 | |
| 1179 | /* An initial stub used if the PLT entry is referenced from Thumb code. */ |
| 1180 | #define PLT_THUMB_STUB_SIZE 4 |
| 1181 | static const bfd_vma elf32_arm_plt_thumb_stub [] = |
| 1182 | { |
| 1183 | 0x4778, /* bx pc */ |
| 1184 | 0x46c0 /* nop */ |
| 1185 | }; |
| 1186 | |
| 1187 | /* The entries in a PLT when using a DLL-based target with multiple |
| 1188 | address spaces. */ |
| 1189 | static const bfd_vma elf32_arm_symbian_plt_entry [] = |
| 1190 | { |
| 1191 | 0xe51ff004, /* ldr pc, [pc, #-4] */ |
| 1192 | 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */ |
| 1193 | }; |
| 1194 | |
| 1195 | /* Used to build a map of a section. This is required for mixed-endian |
| 1196 | code/data. */ |
| 1197 | |
| 1198 | typedef struct elf32_elf_section_map |
| 1199 | { |
| 1200 | bfd_vma vma; |
| 1201 | char type; |
| 1202 | } |
| 1203 | elf32_arm_section_map; |
| 1204 | |
| 1205 | struct _arm_elf_section_data |
| 1206 | { |
| 1207 | struct bfd_elf_section_data elf; |
| 1208 | int mapcount; |
| 1209 | elf32_arm_section_map *map; |
| 1210 | }; |
| 1211 | |
| 1212 | #define elf32_arm_section_data(sec) \ |
| 1213 | ((struct _arm_elf_section_data *) elf_section_data (sec)) |
| 1214 | |
| 1215 | /* The size of the thread control block. */ |
| 1216 | #define TCB_SIZE 8 |
| 1217 | |
| 1218 | struct elf32_arm_obj_tdata |
| 1219 | { |
| 1220 | struct elf_obj_tdata root; |
| 1221 | |
| 1222 | /* tls_type for each local got entry. */ |
| 1223 | char *local_got_tls_type; |
| 1224 | }; |
| 1225 | |
| 1226 | #define elf32_arm_tdata(abfd) \ |
| 1227 | ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any) |
| 1228 | |
| 1229 | #define elf32_arm_local_got_tls_type(abfd) \ |
| 1230 | (elf32_arm_tdata (abfd)->local_got_tls_type) |
| 1231 | |
| 1232 | static bfd_boolean |
| 1233 | elf32_arm_mkobject (bfd *abfd) |
| 1234 | { |
| 1235 | bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata); |
| 1236 | abfd->tdata.any = bfd_zalloc (abfd, amt); |
| 1237 | if (abfd->tdata.any == NULL) |
| 1238 | return FALSE; |
| 1239 | return TRUE; |
| 1240 | } |
| 1241 | |
| 1242 | /* The ARM linker needs to keep track of the number of relocs that it |
| 1243 | decides to copy in check_relocs for each symbol. This is so that |
| 1244 | it can discard PC relative relocs if it doesn't need them when |
| 1245 | linking with -Bsymbolic. We store the information in a field |
| 1246 | extending the regular ELF linker hash table. */ |
| 1247 | |
| 1248 | /* This structure keeps track of the number of relocs we have copied |
| 1249 | for a given symbol. */ |
| 1250 | struct elf32_arm_relocs_copied |
| 1251 | { |
| 1252 | /* Next section. */ |
| 1253 | struct elf32_arm_relocs_copied * next; |
| 1254 | /* A section in dynobj. */ |
| 1255 | asection * section; |
| 1256 | /* Number of relocs copied in this section. */ |
| 1257 | bfd_size_type count; |
| 1258 | /* Number of PC-relative relocs copied in this section. */ |
| 1259 | bfd_size_type pc_count; |
| 1260 | }; |
| 1261 | |
| 1262 | #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent)) |
| 1263 | |
| 1264 | /* Arm ELF linker hash entry. */ |
| 1265 | struct elf32_arm_link_hash_entry |
| 1266 | { |
| 1267 | struct elf_link_hash_entry root; |
| 1268 | |
| 1269 | /* Number of PC relative relocs copied for this symbol. */ |
| 1270 | struct elf32_arm_relocs_copied * relocs_copied; |
| 1271 | |
| 1272 | /* We reference count Thumb references to a PLT entry separately, |
| 1273 | so that we can emit the Thumb trampoline only if needed. */ |
| 1274 | bfd_signed_vma plt_thumb_refcount; |
| 1275 | |
| 1276 | /* Since PLT entries have variable size if the Thumb prologue is |
| 1277 | used, we need to record the index into .got.plt instead of |
| 1278 | recomputing it from the PLT offset. */ |
| 1279 | bfd_signed_vma plt_got_offset; |
| 1280 | |
| 1281 | #define GOT_UNKNOWN 0 |
| 1282 | #define GOT_NORMAL 1 |
| 1283 | #define GOT_TLS_GD 2 |
| 1284 | #define GOT_TLS_IE 4 |
| 1285 | unsigned char tls_type; |
| 1286 | }; |
| 1287 | |
| 1288 | /* Traverse an arm ELF linker hash table. */ |
| 1289 | #define elf32_arm_link_hash_traverse(table, func, info) \ |
| 1290 | (elf_link_hash_traverse \ |
| 1291 | (&(table)->root, \ |
| 1292 | (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ |
| 1293 | (info))) |
| 1294 | |
| 1295 | /* Get the ARM elf linker hash table from a link_info structure. */ |
| 1296 | #define elf32_arm_hash_table(info) \ |
| 1297 | ((struct elf32_arm_link_hash_table *) ((info)->hash)) |
| 1298 | |
| 1299 | /* ARM ELF linker hash table. */ |
| 1300 | struct elf32_arm_link_hash_table |
| 1301 | { |
| 1302 | /* The main hash table. */ |
| 1303 | struct elf_link_hash_table root; |
| 1304 | |
| 1305 | /* The size in bytes of the section containing the Thumb-to-ARM glue. */ |
| 1306 | bfd_size_type thumb_glue_size; |
| 1307 | |
| 1308 | /* The size in bytes of the section containing the ARM-to-Thumb glue. */ |
| 1309 | bfd_size_type arm_glue_size; |
| 1310 | |
| 1311 | /* An arbitrary input BFD chosen to hold the glue sections. */ |
| 1312 | bfd * bfd_of_glue_owner; |
| 1313 | |
| 1314 | /* Nonzero to output a BE8 image. */ |
| 1315 | int byteswap_code; |
| 1316 | |
| 1317 | /* Zero if R_ARM_TARGET1 means R_ARM_ABS32. |
| 1318 | Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */ |
| 1319 | int target1_is_rel; |
| 1320 | |
| 1321 | /* The relocation to use for R_ARM_TARGET2 relocations. */ |
| 1322 | int target2_reloc; |
| 1323 | |
| 1324 | /* Nonzero to fix BX instructions for ARMv4 targets. */ |
| 1325 | int fix_v4bx; |
| 1326 | |
| 1327 | /* The number of bytes in the initial entry in the PLT. */ |
| 1328 | bfd_size_type plt_header_size; |
| 1329 | |
| 1330 | /* The number of bytes in the subsequent PLT etries. */ |
| 1331 | bfd_size_type plt_entry_size; |
| 1332 | |
| 1333 | /* True if the target system is Symbian OS. */ |
| 1334 | int symbian_p; |
| 1335 | |
| 1336 | /* True if the target uses REL relocations. */ |
| 1337 | int use_rel; |
| 1338 | |
| 1339 | /* Short-cuts to get to dynamic linker sections. */ |
| 1340 | asection *sgot; |
| 1341 | asection *sgotplt; |
| 1342 | asection *srelgot; |
| 1343 | asection *splt; |
| 1344 | asection *srelplt; |
| 1345 | asection *sdynbss; |
| 1346 | asection *srelbss; |
| 1347 | |
| 1348 | /* Data for R_ARM_TLS_LDM32 relocations. */ |
| 1349 | union { |
| 1350 | bfd_signed_vma refcount; |
| 1351 | bfd_vma offset; |
| 1352 | } tls_ldm_got; |
| 1353 | |
| 1354 | /* Small local sym to section mapping cache. */ |
| 1355 | struct sym_sec_cache sym_sec; |
| 1356 | |
| 1357 | /* For convenience in allocate_dynrelocs. */ |
| 1358 | bfd * obfd; |
| 1359 | }; |
| 1360 | |
| 1361 | /* Create an entry in an ARM ELF linker hash table. */ |
| 1362 | |
| 1363 | static struct bfd_hash_entry * |
| 1364 | elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry, |
| 1365 | struct bfd_hash_table * table, |
| 1366 | const char * string) |
| 1367 | { |
| 1368 | struct elf32_arm_link_hash_entry * ret = |
| 1369 | (struct elf32_arm_link_hash_entry *) entry; |
| 1370 | |
| 1371 | /* Allocate the structure if it has not already been allocated by a |
| 1372 | subclass. */ |
| 1373 | if (ret == (struct elf32_arm_link_hash_entry *) NULL) |
| 1374 | ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry)); |
| 1375 | if (ret == NULL) |
| 1376 | return (struct bfd_hash_entry *) ret; |
| 1377 | |
| 1378 | /* Call the allocation method of the superclass. */ |
| 1379 | ret = ((struct elf32_arm_link_hash_entry *) |
| 1380 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
| 1381 | table, string)); |
| 1382 | if (ret != NULL) |
| 1383 | { |
| 1384 | ret->relocs_copied = NULL; |
| 1385 | ret->tls_type = GOT_UNKNOWN; |
| 1386 | ret->plt_thumb_refcount = 0; |
| 1387 | ret->plt_got_offset = -1; |
| 1388 | } |
| 1389 | |
| 1390 | return (struct bfd_hash_entry *) ret; |
| 1391 | } |
| 1392 | |
| 1393 | /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up |
| 1394 | shortcuts to them in our hash table. */ |
| 1395 | |
| 1396 | static bfd_boolean |
| 1397 | create_got_section (bfd *dynobj, struct bfd_link_info *info) |
| 1398 | { |
| 1399 | struct elf32_arm_link_hash_table *htab; |
| 1400 | |
| 1401 | htab = elf32_arm_hash_table (info); |
| 1402 | /* BPABI objects never have a GOT, or associated sections. */ |
| 1403 | if (htab->symbian_p) |
| 1404 | return TRUE; |
| 1405 | |
| 1406 | if (! _bfd_elf_create_got_section (dynobj, info)) |
| 1407 | return FALSE; |
| 1408 | |
| 1409 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 1410 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 1411 | if (!htab->sgot || !htab->sgotplt) |
| 1412 | abort (); |
| 1413 | |
| 1414 | htab->srelgot = bfd_make_section (dynobj, ".rel.got"); |
| 1415 | if (htab->srelgot == NULL |
| 1416 | || ! bfd_set_section_flags (dynobj, htab->srelgot, |
| 1417 | (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS |
| 1418 | | SEC_IN_MEMORY | SEC_LINKER_CREATED |
| 1419 | | SEC_READONLY)) |
| 1420 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) |
| 1421 | return FALSE; |
| 1422 | return TRUE; |
| 1423 | } |
| 1424 | |
| 1425 | /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and |
| 1426 | .rel.bss sections in DYNOBJ, and set up shortcuts to them in our |
| 1427 | hash table. */ |
| 1428 | |
| 1429 | static bfd_boolean |
| 1430 | elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
| 1431 | { |
| 1432 | struct elf32_arm_link_hash_table *htab; |
| 1433 | |
| 1434 | htab = elf32_arm_hash_table (info); |
| 1435 | if (!htab->sgot && !create_got_section (dynobj, info)) |
| 1436 | return FALSE; |
| 1437 | |
| 1438 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
| 1439 | return FALSE; |
| 1440 | |
| 1441 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 1442 | htab->srelplt = bfd_get_section_by_name (dynobj, ".rel.plt"); |
| 1443 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); |
| 1444 | if (!info->shared) |
| 1445 | htab->srelbss = bfd_get_section_by_name (dynobj, ".rel.bss"); |
| 1446 | |
| 1447 | if (!htab->splt |
| 1448 | || !htab->srelplt |
| 1449 | || !htab->sdynbss |
| 1450 | || (!info->shared && !htab->srelbss)) |
| 1451 | abort (); |
| 1452 | |
| 1453 | return TRUE; |
| 1454 | } |
| 1455 | |
| 1456 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
| 1457 | |
| 1458 | static void |
| 1459 | elf32_arm_copy_indirect_symbol (const struct elf_backend_data *bed, |
| 1460 | struct elf_link_hash_entry *dir, |
| 1461 | struct elf_link_hash_entry *ind) |
| 1462 | { |
| 1463 | struct elf32_arm_link_hash_entry *edir, *eind; |
| 1464 | |
| 1465 | edir = (struct elf32_arm_link_hash_entry *) dir; |
| 1466 | eind = (struct elf32_arm_link_hash_entry *) ind; |
| 1467 | |
| 1468 | if (eind->relocs_copied != NULL) |
| 1469 | { |
| 1470 | if (edir->relocs_copied != NULL) |
| 1471 | { |
| 1472 | struct elf32_arm_relocs_copied **pp; |
| 1473 | struct elf32_arm_relocs_copied *p; |
| 1474 | |
| 1475 | if (ind->root.type == bfd_link_hash_indirect) |
| 1476 | abort (); |
| 1477 | |
| 1478 | /* Add reloc counts against the weak sym to the strong sym |
| 1479 | list. Merge any entries against the same section. */ |
| 1480 | for (pp = &eind->relocs_copied; (p = *pp) != NULL; ) |
| 1481 | { |
| 1482 | struct elf32_arm_relocs_copied *q; |
| 1483 | |
| 1484 | for (q = edir->relocs_copied; q != NULL; q = q->next) |
| 1485 | if (q->section == p->section) |
| 1486 | { |
| 1487 | q->pc_count += p->pc_count; |
| 1488 | q->count += p->count; |
| 1489 | *pp = p->next; |
| 1490 | break; |
| 1491 | } |
| 1492 | if (q == NULL) |
| 1493 | pp = &p->next; |
| 1494 | } |
| 1495 | *pp = edir->relocs_copied; |
| 1496 | } |
| 1497 | |
| 1498 | edir->relocs_copied = eind->relocs_copied; |
| 1499 | eind->relocs_copied = NULL; |
| 1500 | } |
| 1501 | |
| 1502 | /* If the direct symbol already has an associated PLT entry, the |
| 1503 | indirect symbol should not. If it doesn't, swap refcount information |
| 1504 | from the indirect symbol. */ |
| 1505 | if (edir->plt_thumb_refcount == 0) |
| 1506 | { |
| 1507 | edir->plt_thumb_refcount = eind->plt_thumb_refcount; |
| 1508 | eind->plt_thumb_refcount = 0; |
| 1509 | } |
| 1510 | else |
| 1511 | BFD_ASSERT (eind->plt_thumb_refcount == 0); |
| 1512 | |
| 1513 | if (ind->root.type == bfd_link_hash_indirect |
| 1514 | && dir->got.refcount <= 0) |
| 1515 | { |
| 1516 | edir->tls_type = eind->tls_type; |
| 1517 | eind->tls_type = GOT_UNKNOWN; |
| 1518 | } |
| 1519 | |
| 1520 | _bfd_elf_link_hash_copy_indirect (bed, dir, ind); |
| 1521 | } |
| 1522 | |
| 1523 | /* Create an ARM elf linker hash table. */ |
| 1524 | |
| 1525 | static struct bfd_link_hash_table * |
| 1526 | elf32_arm_link_hash_table_create (bfd *abfd) |
| 1527 | { |
| 1528 | struct elf32_arm_link_hash_table *ret; |
| 1529 | bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table); |
| 1530 | |
| 1531 | ret = bfd_malloc (amt); |
| 1532 | if (ret == NULL) |
| 1533 | return NULL; |
| 1534 | |
| 1535 | if (!_bfd_elf_link_hash_table_init (& ret->root, abfd, |
| 1536 | elf32_arm_link_hash_newfunc)) |
| 1537 | { |
| 1538 | free (ret); |
| 1539 | return NULL; |
| 1540 | } |
| 1541 | |
| 1542 | ret->sgot = NULL; |
| 1543 | ret->sgotplt = NULL; |
| 1544 | ret->srelgot = NULL; |
| 1545 | ret->splt = NULL; |
| 1546 | ret->srelplt = NULL; |
| 1547 | ret->sdynbss = NULL; |
| 1548 | ret->srelbss = NULL; |
| 1549 | ret->thumb_glue_size = 0; |
| 1550 | ret->arm_glue_size = 0; |
| 1551 | ret->bfd_of_glue_owner = NULL; |
| 1552 | ret->byteswap_code = 0; |
| 1553 | ret->target1_is_rel = 0; |
| 1554 | ret->target2_reloc = R_ARM_NONE; |
| 1555 | #ifdef FOUR_WORD_PLT |
| 1556 | ret->plt_header_size = 16; |
| 1557 | ret->plt_entry_size = 16; |
| 1558 | #else |
| 1559 | ret->plt_header_size = 20; |
| 1560 | ret->plt_entry_size = 12; |
| 1561 | #endif |
| 1562 | ret->symbian_p = 0; |
| 1563 | ret->use_rel = 1; |
| 1564 | ret->sym_sec.abfd = NULL; |
| 1565 | ret->obfd = abfd; |
| 1566 | ret->tls_ldm_got.refcount = 0; |
| 1567 | |
| 1568 | return &ret->root.root; |
| 1569 | } |
| 1570 | |
| 1571 | /* Locate the Thumb encoded calling stub for NAME. */ |
| 1572 | |
| 1573 | static struct elf_link_hash_entry * |
| 1574 | find_thumb_glue (struct bfd_link_info *link_info, |
| 1575 | const char *name, |
| 1576 | bfd *input_bfd) |
| 1577 | { |
| 1578 | char *tmp_name; |
| 1579 | struct elf_link_hash_entry *hash; |
| 1580 | struct elf32_arm_link_hash_table *hash_table; |
| 1581 | |
| 1582 | /* We need a pointer to the armelf specific hash table. */ |
| 1583 | hash_table = elf32_arm_hash_table (link_info); |
| 1584 | |
| 1585 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
| 1586 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); |
| 1587 | |
| 1588 | BFD_ASSERT (tmp_name); |
| 1589 | |
| 1590 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); |
| 1591 | |
| 1592 | hash = elf_link_hash_lookup |
| 1593 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
| 1594 | |
| 1595 | if (hash == NULL) |
| 1596 | /* xgettext:c-format */ |
| 1597 | (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"), |
| 1598 | input_bfd, tmp_name, name); |
| 1599 | |
| 1600 | free (tmp_name); |
| 1601 | |
| 1602 | return hash; |
| 1603 | } |
| 1604 | |
| 1605 | /* Locate the ARM encoded calling stub for NAME. */ |
| 1606 | |
| 1607 | static struct elf_link_hash_entry * |
| 1608 | find_arm_glue (struct bfd_link_info *link_info, |
| 1609 | const char *name, |
| 1610 | bfd *input_bfd) |
| 1611 | { |
| 1612 | char *tmp_name; |
| 1613 | struct elf_link_hash_entry *myh; |
| 1614 | struct elf32_arm_link_hash_table *hash_table; |
| 1615 | |
| 1616 | /* We need a pointer to the elfarm specific hash table. */ |
| 1617 | hash_table = elf32_arm_hash_table (link_info); |
| 1618 | |
| 1619 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
| 1620 | + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); |
| 1621 | |
| 1622 | BFD_ASSERT (tmp_name); |
| 1623 | |
| 1624 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); |
| 1625 | |
| 1626 | myh = elf_link_hash_lookup |
| 1627 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
| 1628 | |
| 1629 | if (myh == NULL) |
| 1630 | /* xgettext:c-format */ |
| 1631 | (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"), |
| 1632 | input_bfd, tmp_name, name); |
| 1633 | |
| 1634 | free (tmp_name); |
| 1635 | |
| 1636 | return myh; |
| 1637 | } |
| 1638 | |
| 1639 | /* ARM->Thumb glue: |
| 1640 | |
| 1641 | .arm |
| 1642 | __func_from_arm: |
| 1643 | ldr r12, __func_addr |
| 1644 | bx r12 |
| 1645 | __func_addr: |
| 1646 | .word func @ behave as if you saw a ARM_32 reloc. */ |
| 1647 | |
| 1648 | #define ARM2THUMB_GLUE_SIZE 12 |
| 1649 | static const insn32 a2t1_ldr_insn = 0xe59fc000; |
| 1650 | static const insn32 a2t2_bx_r12_insn = 0xe12fff1c; |
| 1651 | static const insn32 a2t3_func_addr_insn = 0x00000001; |
| 1652 | |
| 1653 | /* Thumb->ARM: Thumb->(non-interworking aware) ARM |
| 1654 | |
| 1655 | .thumb .thumb |
| 1656 | .align 2 .align 2 |
| 1657 | __func_from_thumb: __func_from_thumb: |
| 1658 | bx pc push {r6, lr} |
| 1659 | nop ldr r6, __func_addr |
| 1660 | .arm mov lr, pc |
| 1661 | __func_change_to_arm: bx r6 |
| 1662 | b func .arm |
| 1663 | __func_back_to_thumb: |
| 1664 | ldmia r13! {r6, lr} |
| 1665 | bx lr |
| 1666 | __func_addr: |
| 1667 | .word func */ |
| 1668 | |
| 1669 | #define THUMB2ARM_GLUE_SIZE 8 |
| 1670 | static const insn16 t2a1_bx_pc_insn = 0x4778; |
| 1671 | static const insn16 t2a2_noop_insn = 0x46c0; |
| 1672 | static const insn32 t2a3_b_insn = 0xea000000; |
| 1673 | |
| 1674 | #ifndef ELFARM_NABI_C_INCLUDED |
| 1675 | bfd_boolean |
| 1676 | bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info) |
| 1677 | { |
| 1678 | asection * s; |
| 1679 | bfd_byte * foo; |
| 1680 | struct elf32_arm_link_hash_table * globals; |
| 1681 | |
| 1682 | globals = elf32_arm_hash_table (info); |
| 1683 | |
| 1684 | BFD_ASSERT (globals != NULL); |
| 1685 | |
| 1686 | if (globals->arm_glue_size != 0) |
| 1687 | { |
| 1688 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); |
| 1689 | |
| 1690 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, |
| 1691 | ARM2THUMB_GLUE_SECTION_NAME); |
| 1692 | |
| 1693 | BFD_ASSERT (s != NULL); |
| 1694 | |
| 1695 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size); |
| 1696 | |
| 1697 | s->size = globals->arm_glue_size; |
| 1698 | s->contents = foo; |
| 1699 | } |
| 1700 | |
| 1701 | if (globals->thumb_glue_size != 0) |
| 1702 | { |
| 1703 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); |
| 1704 | |
| 1705 | s = bfd_get_section_by_name |
| 1706 | (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); |
| 1707 | |
| 1708 | BFD_ASSERT (s != NULL); |
| 1709 | |
| 1710 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size); |
| 1711 | |
| 1712 | s->size = globals->thumb_glue_size; |
| 1713 | s->contents = foo; |
| 1714 | } |
| 1715 | |
| 1716 | return TRUE; |
| 1717 | } |
| 1718 | |
| 1719 | static void |
| 1720 | record_arm_to_thumb_glue (struct bfd_link_info * link_info, |
| 1721 | struct elf_link_hash_entry * h) |
| 1722 | { |
| 1723 | const char * name = h->root.root.string; |
| 1724 | asection * s; |
| 1725 | char * tmp_name; |
| 1726 | struct elf_link_hash_entry * myh; |
| 1727 | struct bfd_link_hash_entry * bh; |
| 1728 | struct elf32_arm_link_hash_table * globals; |
| 1729 | bfd_vma val; |
| 1730 | |
| 1731 | globals = elf32_arm_hash_table (link_info); |
| 1732 | |
| 1733 | BFD_ASSERT (globals != NULL); |
| 1734 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); |
| 1735 | |
| 1736 | s = bfd_get_section_by_name |
| 1737 | (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME); |
| 1738 | |
| 1739 | BFD_ASSERT (s != NULL); |
| 1740 | |
| 1741 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); |
| 1742 | |
| 1743 | BFD_ASSERT (tmp_name); |
| 1744 | |
| 1745 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); |
| 1746 | |
| 1747 | myh = elf_link_hash_lookup |
| 1748 | (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); |
| 1749 | |
| 1750 | if (myh != NULL) |
| 1751 | { |
| 1752 | /* We've already seen this guy. */ |
| 1753 | free (tmp_name); |
| 1754 | return; |
| 1755 | } |
| 1756 | |
| 1757 | /* The only trick here is using hash_table->arm_glue_size as the value. |
| 1758 | Even though the section isn't allocated yet, this is where we will be |
| 1759 | putting it. */ |
| 1760 | bh = NULL; |
| 1761 | val = globals->arm_glue_size + 1; |
| 1762 | _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner, |
| 1763 | tmp_name, BSF_GLOBAL, s, val, |
| 1764 | NULL, TRUE, FALSE, &bh); |
| 1765 | |
| 1766 | myh = (struct elf_link_hash_entry *) bh; |
| 1767 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); |
| 1768 | myh->forced_local = 1; |
| 1769 | |
| 1770 | free (tmp_name); |
| 1771 | |
| 1772 | globals->arm_glue_size += ARM2THUMB_GLUE_SIZE; |
| 1773 | |
| 1774 | return; |
| 1775 | } |
| 1776 | |
| 1777 | static void |
| 1778 | record_thumb_to_arm_glue (struct bfd_link_info *link_info, |
| 1779 | struct elf_link_hash_entry *h) |
| 1780 | { |
| 1781 | const char *name = h->root.root.string; |
| 1782 | asection *s; |
| 1783 | char *tmp_name; |
| 1784 | struct elf_link_hash_entry *myh; |
| 1785 | struct bfd_link_hash_entry *bh; |
| 1786 | struct elf32_arm_link_hash_table *hash_table; |
| 1787 | bfd_vma val; |
| 1788 | |
| 1789 | hash_table = elf32_arm_hash_table (link_info); |
| 1790 | |
| 1791 | BFD_ASSERT (hash_table != NULL); |
| 1792 | BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); |
| 1793 | |
| 1794 | s = bfd_get_section_by_name |
| 1795 | (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); |
| 1796 | |
| 1797 | BFD_ASSERT (s != NULL); |
| 1798 | |
| 1799 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
| 1800 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); |
| 1801 | |
| 1802 | BFD_ASSERT (tmp_name); |
| 1803 | |
| 1804 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); |
| 1805 | |
| 1806 | myh = elf_link_hash_lookup |
| 1807 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
| 1808 | |
| 1809 | if (myh != NULL) |
| 1810 | { |
| 1811 | /* We've already seen this guy. */ |
| 1812 | free (tmp_name); |
| 1813 | return; |
| 1814 | } |
| 1815 | |
| 1816 | bh = NULL; |
| 1817 | val = hash_table->thumb_glue_size + 1; |
| 1818 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, |
| 1819 | tmp_name, BSF_GLOBAL, s, val, |
| 1820 | NULL, TRUE, FALSE, &bh); |
| 1821 | |
| 1822 | /* If we mark it 'Thumb', the disassembler will do a better job. */ |
| 1823 | myh = (struct elf_link_hash_entry *) bh; |
| 1824 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC); |
| 1825 | myh->forced_local = 1; |
| 1826 | |
| 1827 | free (tmp_name); |
| 1828 | |
| 1829 | #define CHANGE_TO_ARM "__%s_change_to_arm" |
| 1830 | #define BACK_FROM_ARM "__%s_back_from_arm" |
| 1831 | |
| 1832 | /* Allocate another symbol to mark where we switch to Arm mode. */ |
| 1833 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
| 1834 | + strlen (CHANGE_TO_ARM) + 1); |
| 1835 | |
| 1836 | BFD_ASSERT (tmp_name); |
| 1837 | |
| 1838 | sprintf (tmp_name, CHANGE_TO_ARM, name); |
| 1839 | |
| 1840 | bh = NULL; |
| 1841 | val = hash_table->thumb_glue_size + 4, |
| 1842 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, |
| 1843 | tmp_name, BSF_LOCAL, s, val, |
| 1844 | NULL, TRUE, FALSE, &bh); |
| 1845 | |
| 1846 | free (tmp_name); |
| 1847 | |
| 1848 | hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE; |
| 1849 | |
| 1850 | return; |
| 1851 | } |
| 1852 | |
| 1853 | /* Add the glue sections to ABFD. This function is called from the |
| 1854 | linker scripts in ld/emultempl/{armelf}.em. */ |
| 1855 | |
| 1856 | bfd_boolean |
| 1857 | bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd, |
| 1858 | struct bfd_link_info *info) |
| 1859 | { |
| 1860 | flagword flags; |
| 1861 | asection *sec; |
| 1862 | |
| 1863 | /* If we are only performing a partial |
| 1864 | link do not bother adding the glue. */ |
| 1865 | if (info->relocatable) |
| 1866 | return TRUE; |
| 1867 | |
| 1868 | sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME); |
| 1869 | |
| 1870 | if (sec == NULL) |
| 1871 | { |
| 1872 | /* Note: we do not include the flag SEC_LINKER_CREATED, as this |
| 1873 | will prevent elf_link_input_bfd() from processing the contents |
| 1874 | of this section. */ |
| 1875 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY; |
| 1876 | |
| 1877 | sec = bfd_make_section (abfd, ARM2THUMB_GLUE_SECTION_NAME); |
| 1878 | |
| 1879 | if (sec == NULL |
| 1880 | || !bfd_set_section_flags (abfd, sec, flags) |
| 1881 | || !bfd_set_section_alignment (abfd, sec, 2)) |
| 1882 | return FALSE; |
| 1883 | |
| 1884 | /* Set the gc mark to prevent the section from being removed by garbage |
| 1885 | collection, despite the fact that no relocs refer to this section. */ |
| 1886 | sec->gc_mark = 1; |
| 1887 | } |
| 1888 | |
| 1889 | sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME); |
| 1890 | |
| 1891 | if (sec == NULL) |
| 1892 | { |
| 1893 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
| 1894 | | SEC_CODE | SEC_READONLY; |
| 1895 | |
| 1896 | sec = bfd_make_section (abfd, THUMB2ARM_GLUE_SECTION_NAME); |
| 1897 | |
| 1898 | if (sec == NULL |
| 1899 | || !bfd_set_section_flags (abfd, sec, flags) |
| 1900 | || !bfd_set_section_alignment (abfd, sec, 2)) |
| 1901 | return FALSE; |
| 1902 | |
| 1903 | sec->gc_mark = 1; |
| 1904 | } |
| 1905 | |
| 1906 | return TRUE; |
| 1907 | } |
| 1908 | |
| 1909 | /* Select a BFD to be used to hold the sections used by the glue code. |
| 1910 | This function is called from the linker scripts in ld/emultempl/ |
| 1911 | {armelf/pe}.em */ |
| 1912 | |
| 1913 | bfd_boolean |
| 1914 | bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info) |
| 1915 | { |
| 1916 | struct elf32_arm_link_hash_table *globals; |
| 1917 | |
| 1918 | /* If we are only performing a partial link |
| 1919 | do not bother getting a bfd to hold the glue. */ |
| 1920 | if (info->relocatable) |
| 1921 | return TRUE; |
| 1922 | |
| 1923 | /* Make sure we don't attach the glue sections to a dynamic object. */ |
| 1924 | BFD_ASSERT (!(abfd->flags & DYNAMIC)); |
| 1925 | |
| 1926 | globals = elf32_arm_hash_table (info); |
| 1927 | |
| 1928 | BFD_ASSERT (globals != NULL); |
| 1929 | |
| 1930 | if (globals->bfd_of_glue_owner != NULL) |
| 1931 | return TRUE; |
| 1932 | |
| 1933 | /* Save the bfd for later use. */ |
| 1934 | globals->bfd_of_glue_owner = abfd; |
| 1935 | |
| 1936 | return TRUE; |
| 1937 | } |
| 1938 | |
| 1939 | bfd_boolean |
| 1940 | bfd_elf32_arm_process_before_allocation (bfd *abfd, |
| 1941 | struct bfd_link_info *link_info, |
| 1942 | int byteswap_code) |
| 1943 | { |
| 1944 | Elf_Internal_Shdr *symtab_hdr; |
| 1945 | Elf_Internal_Rela *internal_relocs = NULL; |
| 1946 | Elf_Internal_Rela *irel, *irelend; |
| 1947 | bfd_byte *contents = NULL; |
| 1948 | |
| 1949 | asection *sec; |
| 1950 | struct elf32_arm_link_hash_table *globals; |
| 1951 | |
| 1952 | /* If we are only performing a partial link do not bother |
| 1953 | to construct any glue. */ |
| 1954 | if (link_info->relocatable) |
| 1955 | return TRUE; |
| 1956 | |
| 1957 | /* Here we have a bfd that is to be included on the link. We have a hook |
| 1958 | to do reloc rummaging, before section sizes are nailed down. */ |
| 1959 | globals = elf32_arm_hash_table (link_info); |
| 1960 | |
| 1961 | BFD_ASSERT (globals != NULL); |
| 1962 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); |
| 1963 | |
| 1964 | if (byteswap_code && !bfd_big_endian (abfd)) |
| 1965 | { |
| 1966 | _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."), |
| 1967 | abfd); |
| 1968 | return FALSE; |
| 1969 | } |
| 1970 | globals->byteswap_code = byteswap_code; |
| 1971 | |
| 1972 | /* Rummage around all the relocs and map the glue vectors. */ |
| 1973 | sec = abfd->sections; |
| 1974 | |
| 1975 | if (sec == NULL) |
| 1976 | return TRUE; |
| 1977 | |
| 1978 | for (; sec != NULL; sec = sec->next) |
| 1979 | { |
| 1980 | if (sec->reloc_count == 0) |
| 1981 | continue; |
| 1982 | |
| 1983 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 1984 | |
| 1985 | /* Load the relocs. */ |
| 1986 | internal_relocs |
| 1987 | = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL, |
| 1988 | (Elf_Internal_Rela *) NULL, FALSE); |
| 1989 | |
| 1990 | if (internal_relocs == NULL) |
| 1991 | goto error_return; |
| 1992 | |
| 1993 | irelend = internal_relocs + sec->reloc_count; |
| 1994 | for (irel = internal_relocs; irel < irelend; irel++) |
| 1995 | { |
| 1996 | long r_type; |
| 1997 | unsigned long r_index; |
| 1998 | |
| 1999 | struct elf_link_hash_entry *h; |
| 2000 | |
| 2001 | r_type = ELF32_R_TYPE (irel->r_info); |
| 2002 | r_index = ELF32_R_SYM (irel->r_info); |
| 2003 | |
| 2004 | /* These are the only relocation types we care about. */ |
| 2005 | if ( r_type != R_ARM_PC24 |
| 2006 | && r_type != R_ARM_PLT32 |
| 2007 | #ifndef OLD_ARM_ABI |
| 2008 | && r_type != R_ARM_CALL |
| 2009 | && r_type != R_ARM_JUMP24 |
| 2010 | #endif |
| 2011 | && r_type != R_ARM_THM_PC22) |
| 2012 | continue; |
| 2013 | |
| 2014 | /* Get the section contents if we haven't done so already. */ |
| 2015 | if (contents == NULL) |
| 2016 | { |
| 2017 | /* Get cached copy if it exists. */ |
| 2018 | if (elf_section_data (sec)->this_hdr.contents != NULL) |
| 2019 | contents = elf_section_data (sec)->this_hdr.contents; |
| 2020 | else |
| 2021 | { |
| 2022 | /* Go get them off disk. */ |
| 2023 | if (! bfd_malloc_and_get_section (abfd, sec, &contents)) |
| 2024 | goto error_return; |
| 2025 | } |
| 2026 | } |
| 2027 | |
| 2028 | /* If the relocation is not against a symbol it cannot concern us. */ |
| 2029 | h = NULL; |
| 2030 | |
| 2031 | /* We don't care about local symbols. */ |
| 2032 | if (r_index < symtab_hdr->sh_info) |
| 2033 | continue; |
| 2034 | |
| 2035 | /* This is an external symbol. */ |
| 2036 | r_index -= symtab_hdr->sh_info; |
| 2037 | h = (struct elf_link_hash_entry *) |
| 2038 | elf_sym_hashes (abfd)[r_index]; |
| 2039 | |
| 2040 | /* If the relocation is against a static symbol it must be within |
| 2041 | the current section and so cannot be a cross ARM/Thumb relocation. */ |
| 2042 | if (h == NULL) |
| 2043 | continue; |
| 2044 | |
| 2045 | /* If the call will go through a PLT entry then we do not need |
| 2046 | glue. */ |
| 2047 | if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1) |
| 2048 | continue; |
| 2049 | |
| 2050 | switch (r_type) |
| 2051 | { |
| 2052 | case R_ARM_PC24: |
| 2053 | #ifndef OLD_ARM_ABI |
| 2054 | case R_ARM_CALL: |
| 2055 | case R_ARM_JUMP24: |
| 2056 | #endif |
| 2057 | /* This one is a call from arm code. We need to look up |
| 2058 | the target of the call. If it is a thumb target, we |
| 2059 | insert glue. */ |
| 2060 | if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC) |
| 2061 | record_arm_to_thumb_glue (link_info, h); |
| 2062 | break; |
| 2063 | |
| 2064 | case R_ARM_THM_PC22: |
| 2065 | /* This one is a call from thumb code. We look |
| 2066 | up the target of the call. If it is not a thumb |
| 2067 | target, we insert glue. */ |
| 2068 | if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC) |
| 2069 | record_thumb_to_arm_glue (link_info, h); |
| 2070 | break; |
| 2071 | |
| 2072 | default: |
| 2073 | break; |
| 2074 | } |
| 2075 | } |
| 2076 | |
| 2077 | if (contents != NULL |
| 2078 | && elf_section_data (sec)->this_hdr.contents != contents) |
| 2079 | free (contents); |
| 2080 | contents = NULL; |
| 2081 | |
| 2082 | if (internal_relocs != NULL |
| 2083 | && elf_section_data (sec)->relocs != internal_relocs) |
| 2084 | free (internal_relocs); |
| 2085 | internal_relocs = NULL; |
| 2086 | } |
| 2087 | |
| 2088 | return TRUE; |
| 2089 | |
| 2090 | error_return: |
| 2091 | if (contents != NULL |
| 2092 | && elf_section_data (sec)->this_hdr.contents != contents) |
| 2093 | free (contents); |
| 2094 | if (internal_relocs != NULL |
| 2095 | && elf_section_data (sec)->relocs != internal_relocs) |
| 2096 | free (internal_relocs); |
| 2097 | |
| 2098 | return FALSE; |
| 2099 | } |
| 2100 | #endif |
| 2101 | |
| 2102 | |
| 2103 | #ifndef OLD_ARM_ABI |
| 2104 | /* Set target relocation values needed during linking. */ |
| 2105 | |
| 2106 | void |
| 2107 | bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info, |
| 2108 | int target1_is_rel, |
| 2109 | char * target2_type, |
| 2110 | int fix_v4bx) |
| 2111 | { |
| 2112 | struct elf32_arm_link_hash_table *globals; |
| 2113 | |
| 2114 | globals = elf32_arm_hash_table (link_info); |
| 2115 | |
| 2116 | globals->target1_is_rel = target1_is_rel; |
| 2117 | if (strcmp (target2_type, "rel") == 0) |
| 2118 | globals->target2_reloc = R_ARM_REL32; |
| 2119 | else if (strcmp (target2_type, "abs") == 0) |
| 2120 | globals->target2_reloc = R_ARM_ABS32; |
| 2121 | else if (strcmp (target2_type, "got-rel") == 0) |
| 2122 | globals->target2_reloc = R_ARM_GOT_PREL; |
| 2123 | else |
| 2124 | { |
| 2125 | _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."), |
| 2126 | target2_type); |
| 2127 | } |
| 2128 | globals->fix_v4bx = fix_v4bx; |
| 2129 | } |
| 2130 | #endif |
| 2131 | |
| 2132 | /* The thumb form of a long branch is a bit finicky, because the offset |
| 2133 | encoding is split over two fields, each in it's own instruction. They |
| 2134 | can occur in any order. So given a thumb form of long branch, and an |
| 2135 | offset, insert the offset into the thumb branch and return finished |
| 2136 | instruction. |
| 2137 | |
| 2138 | It takes two thumb instructions to encode the target address. Each has |
| 2139 | 11 bits to invest. The upper 11 bits are stored in one (identified by |
| 2140 | H-0.. see below), the lower 11 bits are stored in the other (identified |
| 2141 | by H-1). |
| 2142 | |
| 2143 | Combine together and shifted left by 1 (it's a half word address) and |
| 2144 | there you have it. |
| 2145 | |
| 2146 | Op: 1111 = F, |
| 2147 | H-0, upper address-0 = 000 |
| 2148 | Op: 1111 = F, |
| 2149 | H-1, lower address-0 = 800 |
| 2150 | |
| 2151 | They can be ordered either way, but the arm tools I've seen always put |
| 2152 | the lower one first. It probably doesn't matter. krk@cygnus.com |
| 2153 | |
| 2154 | XXX: Actually the order does matter. The second instruction (H-1) |
| 2155 | moves the computed address into the PC, so it must be the second one |
| 2156 | in the sequence. The problem, however is that whilst little endian code |
| 2157 | stores the instructions in HI then LOW order, big endian code does the |
| 2158 | reverse. nickc@cygnus.com. */ |
| 2159 | |
| 2160 | #define LOW_HI_ORDER 0xF800F000 |
| 2161 | #define HI_LOW_ORDER 0xF000F800 |
| 2162 | |
| 2163 | static insn32 |
| 2164 | insert_thumb_branch (insn32 br_insn, int rel_off) |
| 2165 | { |
| 2166 | unsigned int low_bits; |
| 2167 | unsigned int high_bits; |
| 2168 | |
| 2169 | BFD_ASSERT ((rel_off & 1) != 1); |
| 2170 | |
| 2171 | rel_off >>= 1; /* Half word aligned address. */ |
| 2172 | low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */ |
| 2173 | high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */ |
| 2174 | |
| 2175 | if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER) |
| 2176 | br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits; |
| 2177 | else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER) |
| 2178 | br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits; |
| 2179 | else |
| 2180 | /* FIXME: abort is probably not the right call. krk@cygnus.com */ |
| 2181 | abort (); /* Error - not a valid branch instruction form. */ |
| 2182 | |
| 2183 | return br_insn; |
| 2184 | } |
| 2185 | |
| 2186 | /* Thumb code calling an ARM function. */ |
| 2187 | |
| 2188 | static int |
| 2189 | elf32_thumb_to_arm_stub (struct bfd_link_info * info, |
| 2190 | const char * name, |
| 2191 | bfd * input_bfd, |
| 2192 | bfd * output_bfd, |
| 2193 | asection * input_section, |
| 2194 | bfd_byte * hit_data, |
| 2195 | asection * sym_sec, |
| 2196 | bfd_vma offset, |
| 2197 | bfd_signed_vma addend, |
| 2198 | bfd_vma val) |
| 2199 | { |
| 2200 | asection * s = 0; |
| 2201 | bfd_vma my_offset; |
| 2202 | unsigned long int tmp; |
| 2203 | long int ret_offset; |
| 2204 | struct elf_link_hash_entry * myh; |
| 2205 | struct elf32_arm_link_hash_table * globals; |
| 2206 | |
| 2207 | myh = find_thumb_glue (info, name, input_bfd); |
| 2208 | if (myh == NULL) |
| 2209 | return FALSE; |
| 2210 | |
| 2211 | globals = elf32_arm_hash_table (info); |
| 2212 | |
| 2213 | BFD_ASSERT (globals != NULL); |
| 2214 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); |
| 2215 | |
| 2216 | my_offset = myh->root.u.def.value; |
| 2217 | |
| 2218 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, |
| 2219 | THUMB2ARM_GLUE_SECTION_NAME); |
| 2220 | |
| 2221 | BFD_ASSERT (s != NULL); |
| 2222 | BFD_ASSERT (s->contents != NULL); |
| 2223 | BFD_ASSERT (s->output_section != NULL); |
| 2224 | |
| 2225 | if ((my_offset & 0x01) == 0x01) |
| 2226 | { |
| 2227 | if (sym_sec != NULL |
| 2228 | && sym_sec->owner != NULL |
| 2229 | && !INTERWORK_FLAG (sym_sec->owner)) |
| 2230 | { |
| 2231 | (*_bfd_error_handler) |
| 2232 | (_("%B(%s): warning: interworking not enabled.\n" |
| 2233 | " first occurrence: %B: thumb call to arm"), |
| 2234 | sym_sec->owner, input_bfd, name); |
| 2235 | |
| 2236 | return FALSE; |
| 2237 | } |
| 2238 | |
| 2239 | --my_offset; |
| 2240 | myh->root.u.def.value = my_offset; |
| 2241 | |
| 2242 | bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn, |
| 2243 | s->contents + my_offset); |
| 2244 | |
| 2245 | bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn, |
| 2246 | s->contents + my_offset + 2); |
| 2247 | |
| 2248 | ret_offset = |
| 2249 | /* Address of destination of the stub. */ |
| 2250 | ((bfd_signed_vma) val) |
| 2251 | - ((bfd_signed_vma) |
| 2252 | /* Offset from the start of the current section |
| 2253 | to the start of the stubs. */ |
| 2254 | (s->output_offset |
| 2255 | /* Offset of the start of this stub from the start of the stubs. */ |
| 2256 | + my_offset |
| 2257 | /* Address of the start of the current section. */ |
| 2258 | + s->output_section->vma) |
| 2259 | /* The branch instruction is 4 bytes into the stub. */ |
| 2260 | + 4 |
| 2261 | /* ARM branches work from the pc of the instruction + 8. */ |
| 2262 | + 8); |
| 2263 | |
| 2264 | bfd_put_32 (output_bfd, |
| 2265 | (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF), |
| 2266 | s->contents + my_offset + 4); |
| 2267 | } |
| 2268 | |
| 2269 | BFD_ASSERT (my_offset <= globals->thumb_glue_size); |
| 2270 | |
| 2271 | /* Now go back and fix up the original BL insn to point to here. */ |
| 2272 | ret_offset = |
| 2273 | /* Address of where the stub is located. */ |
| 2274 | (s->output_section->vma + s->output_offset + my_offset) |
| 2275 | /* Address of where the BL is located. */ |
| 2276 | - (input_section->output_section->vma + input_section->output_offset |
| 2277 | + offset) |
| 2278 | /* Addend in the relocation. */ |
| 2279 | - addend |
| 2280 | /* Biassing for PC-relative addressing. */ |
| 2281 | - 8; |
| 2282 | |
| 2283 | tmp = bfd_get_32 (input_bfd, hit_data |
| 2284 | - input_section->vma); |
| 2285 | |
| 2286 | bfd_put_32 (output_bfd, |
| 2287 | (bfd_vma) insert_thumb_branch (tmp, ret_offset), |
| 2288 | hit_data - input_section->vma); |
| 2289 | |
| 2290 | return TRUE; |
| 2291 | } |
| 2292 | |
| 2293 | /* Arm code calling a Thumb function. */ |
| 2294 | |
| 2295 | static int |
| 2296 | elf32_arm_to_thumb_stub (struct bfd_link_info * info, |
| 2297 | const char * name, |
| 2298 | bfd * input_bfd, |
| 2299 | bfd * output_bfd, |
| 2300 | asection * input_section, |
| 2301 | bfd_byte * hit_data, |
| 2302 | asection * sym_sec, |
| 2303 | bfd_vma offset, |
| 2304 | bfd_signed_vma addend, |
| 2305 | bfd_vma val) |
| 2306 | { |
| 2307 | unsigned long int tmp; |
| 2308 | bfd_vma my_offset; |
| 2309 | asection * s; |
| 2310 | long int ret_offset; |
| 2311 | struct elf_link_hash_entry * myh; |
| 2312 | struct elf32_arm_link_hash_table * globals; |
| 2313 | |
| 2314 | myh = find_arm_glue (info, name, input_bfd); |
| 2315 | if (myh == NULL) |
| 2316 | return FALSE; |
| 2317 | |
| 2318 | globals = elf32_arm_hash_table (info); |
| 2319 | |
| 2320 | BFD_ASSERT (globals != NULL); |
| 2321 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); |
| 2322 | |
| 2323 | my_offset = myh->root.u.def.value; |
| 2324 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, |
| 2325 | ARM2THUMB_GLUE_SECTION_NAME); |
| 2326 | BFD_ASSERT (s != NULL); |
| 2327 | BFD_ASSERT (s->contents != NULL); |
| 2328 | BFD_ASSERT (s->output_section != NULL); |
| 2329 | |
| 2330 | if ((my_offset & 0x01) == 0x01) |
| 2331 | { |
| 2332 | if (sym_sec != NULL |
| 2333 | && sym_sec->owner != NULL |
| 2334 | && !INTERWORK_FLAG (sym_sec->owner)) |
| 2335 | { |
| 2336 | (*_bfd_error_handler) |
| 2337 | (_("%B(%s): warning: interworking not enabled.\n" |
| 2338 | " first occurrence: %B: arm call to thumb"), |
| 2339 | sym_sec->owner, input_bfd, name); |
| 2340 | } |
| 2341 | |
| 2342 | --my_offset; |
| 2343 | myh->root.u.def.value = my_offset; |
| 2344 | |
| 2345 | bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn, |
| 2346 | s->contents + my_offset); |
| 2347 | |
| 2348 | bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn, |
| 2349 | s->contents + my_offset + 4); |
| 2350 | |
| 2351 | /* It's a thumb address. Add the low order bit. */ |
| 2352 | bfd_put_32 (output_bfd, val | a2t3_func_addr_insn, |
| 2353 | s->contents + my_offset + 8); |
| 2354 | } |
| 2355 | |
| 2356 | BFD_ASSERT (my_offset <= globals->arm_glue_size); |
| 2357 | |
| 2358 | tmp = bfd_get_32 (input_bfd, hit_data); |
| 2359 | tmp = tmp & 0xFF000000; |
| 2360 | |
| 2361 | /* Somehow these are both 4 too far, so subtract 8. */ |
| 2362 | ret_offset = (s->output_offset |
| 2363 | + my_offset |
| 2364 | + s->output_section->vma |
| 2365 | - (input_section->output_offset |
| 2366 | + input_section->output_section->vma |
| 2367 | + offset + addend) |
| 2368 | - 8); |
| 2369 | |
| 2370 | tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF); |
| 2371 | |
| 2372 | bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma); |
| 2373 | |
| 2374 | return TRUE; |
| 2375 | } |
| 2376 | |
| 2377 | |
| 2378 | #ifndef OLD_ARM_ABI |
| 2379 | /* Some relocations map to different relocations depending on the |
| 2380 | target. Return the real relocation. */ |
| 2381 | static int |
| 2382 | arm_real_reloc_type (struct elf32_arm_link_hash_table * globals, |
| 2383 | int r_type) |
| 2384 | { |
| 2385 | switch (r_type) |
| 2386 | { |
| 2387 | case R_ARM_TARGET1: |
| 2388 | if (globals->target1_is_rel) |
| 2389 | return R_ARM_REL32; |
| 2390 | else |
| 2391 | return R_ARM_ABS32; |
| 2392 | |
| 2393 | case R_ARM_TARGET2: |
| 2394 | return globals->target2_reloc; |
| 2395 | |
| 2396 | default: |
| 2397 | return r_type; |
| 2398 | } |
| 2399 | } |
| 2400 | #endif /* OLD_ARM_ABI */ |
| 2401 | |
| 2402 | |
| 2403 | /* Return the base VMA address which should be subtracted from real addresses |
| 2404 | when resolving @dtpoff relocation. |
| 2405 | This is PT_TLS segment p_vaddr. */ |
| 2406 | |
| 2407 | static bfd_vma |
| 2408 | dtpoff_base (struct bfd_link_info *info) |
| 2409 | { |
| 2410 | /* If tls_sec is NULL, we should have signalled an error already. */ |
| 2411 | if (elf_hash_table (info)->tls_sec == NULL) |
| 2412 | return 0; |
| 2413 | return elf_hash_table (info)->tls_sec->vma; |
| 2414 | } |
| 2415 | |
| 2416 | /* Return the relocation value for @tpoff relocation |
| 2417 | if STT_TLS virtual address is ADDRESS. */ |
| 2418 | |
| 2419 | static bfd_vma |
| 2420 | tpoff (struct bfd_link_info *info, bfd_vma address) |
| 2421 | { |
| 2422 | struct elf_link_hash_table *htab = elf_hash_table (info); |
| 2423 | bfd_vma base; |
| 2424 | |
| 2425 | /* If tls_sec is NULL, we should have signalled an error already. */ |
| 2426 | if (htab->tls_sec == NULL) |
| 2427 | return 0; |
| 2428 | base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power); |
| 2429 | return address - htab->tls_sec->vma + base; |
| 2430 | } |
| 2431 | |
| 2432 | /* Perform a relocation as part of a final link. */ |
| 2433 | |
| 2434 | static bfd_reloc_status_type |
| 2435 | elf32_arm_final_link_relocate (reloc_howto_type * howto, |
| 2436 | bfd * input_bfd, |
| 2437 | bfd * output_bfd, |
| 2438 | asection * input_section, |
| 2439 | bfd_byte * contents, |
| 2440 | Elf_Internal_Rela * rel, |
| 2441 | bfd_vma value, |
| 2442 | struct bfd_link_info * info, |
| 2443 | asection * sym_sec, |
| 2444 | const char * sym_name, |
| 2445 | int sym_flags, |
| 2446 | struct elf_link_hash_entry * h, |
| 2447 | bfd_boolean * unresolved_reloc_p) |
| 2448 | { |
| 2449 | unsigned long r_type = howto->type; |
| 2450 | unsigned long r_symndx; |
| 2451 | bfd_byte * hit_data = contents + rel->r_offset; |
| 2452 | bfd * dynobj = NULL; |
| 2453 | Elf_Internal_Shdr * symtab_hdr; |
| 2454 | struct elf_link_hash_entry ** sym_hashes; |
| 2455 | bfd_vma * local_got_offsets; |
| 2456 | asection * sgot = NULL; |
| 2457 | asection * splt = NULL; |
| 2458 | asection * sreloc = NULL; |
| 2459 | bfd_vma addend; |
| 2460 | bfd_signed_vma signed_addend; |
| 2461 | struct elf32_arm_link_hash_table * globals; |
| 2462 | |
| 2463 | globals = elf32_arm_hash_table (info); |
| 2464 | |
| 2465 | #ifndef OLD_ARM_ABI |
| 2466 | /* Some relocation type map to different relocations depending on the |
| 2467 | target. We pick the right one here. */ |
| 2468 | r_type = arm_real_reloc_type (globals, r_type); |
| 2469 | if (r_type != howto->type) |
| 2470 | howto = elf32_arm_howto_from_type (r_type); |
| 2471 | #endif /* OLD_ARM_ABI */ |
| 2472 | |
| 2473 | /* If the start address has been set, then set the EF_ARM_HASENTRY |
| 2474 | flag. Setting this more than once is redundant, but the cost is |
| 2475 | not too high, and it keeps the code simple. |
| 2476 | |
| 2477 | The test is done here, rather than somewhere else, because the |
| 2478 | start address is only set just before the final link commences. |
| 2479 | |
| 2480 | Note - if the user deliberately sets a start address of 0, the |
| 2481 | flag will not be set. */ |
| 2482 | if (bfd_get_start_address (output_bfd) != 0) |
| 2483 | elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY; |
| 2484 | |
| 2485 | dynobj = elf_hash_table (info)->dynobj; |
| 2486 | if (dynobj) |
| 2487 | { |
| 2488 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 2489 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 2490 | } |
| 2491 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; |
| 2492 | sym_hashes = elf_sym_hashes (input_bfd); |
| 2493 | local_got_offsets = elf_local_got_offsets (input_bfd); |
| 2494 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 2495 | |
| 2496 | if (globals->use_rel) |
| 2497 | { |
| 2498 | addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask; |
| 2499 | |
| 2500 | if (addend & ((howto->src_mask + 1) >> 1)) |
| 2501 | { |
| 2502 | signed_addend = -1; |
| 2503 | signed_addend &= ~ howto->src_mask; |
| 2504 | signed_addend |= addend; |
| 2505 | } |
| 2506 | else |
| 2507 | signed_addend = addend; |
| 2508 | } |
| 2509 | else |
| 2510 | addend = signed_addend = rel->r_addend; |
| 2511 | |
| 2512 | switch (r_type) |
| 2513 | { |
| 2514 | case R_ARM_NONE: |
| 2515 | /* We don't need to find a value for this symbol. It's just a |
| 2516 | marker. */ |
| 2517 | *unresolved_reloc_p = FALSE; |
| 2518 | return bfd_reloc_ok; |
| 2519 | |
| 2520 | case R_ARM_PC24: |
| 2521 | case R_ARM_ABS32: |
| 2522 | case R_ARM_REL32: |
| 2523 | #ifndef OLD_ARM_ABI |
| 2524 | case R_ARM_CALL: |
| 2525 | case R_ARM_JUMP24: |
| 2526 | case R_ARM_XPC25: |
| 2527 | case R_ARM_PREL31: |
| 2528 | #endif |
| 2529 | case R_ARM_PLT32: |
| 2530 | /* r_symndx will be zero only for relocs against symbols |
| 2531 | from removed linkonce sections, or sections discarded by |
| 2532 | a linker script. */ |
| 2533 | if (r_symndx == 0) |
| 2534 | return bfd_reloc_ok; |
| 2535 | |
| 2536 | /* Handle relocations which should use the PLT entry. ABS32/REL32 |
| 2537 | will use the symbol's value, which may point to a PLT entry, but we |
| 2538 | don't need to handle that here. If we created a PLT entry, all |
| 2539 | branches in this object should go to it. */ |
| 2540 | if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32) |
| 2541 | && h != NULL |
| 2542 | && splt != NULL |
| 2543 | && h->plt.offset != (bfd_vma) -1) |
| 2544 | { |
| 2545 | /* If we've created a .plt section, and assigned a PLT entry to |
| 2546 | this function, it should not be known to bind locally. If |
| 2547 | it were, we would have cleared the PLT entry. */ |
| 2548 | BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h)); |
| 2549 | |
| 2550 | value = (splt->output_section->vma |
| 2551 | + splt->output_offset |
| 2552 | + h->plt.offset); |
| 2553 | *unresolved_reloc_p = FALSE; |
| 2554 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 2555 | contents, rel->r_offset, value, |
| 2556 | (bfd_vma) 0); |
| 2557 | } |
| 2558 | |
| 2559 | /* When generating a shared object or relocatable executable, these |
| 2560 | relocations are copied into the output file to be resolved at |
| 2561 | run time. */ |
| 2562 | if ((info->shared || globals->root.is_relocatable_executable) |
| 2563 | && (input_section->flags & SEC_ALLOC) |
| 2564 | && (r_type != R_ARM_REL32 |
| 2565 | || !SYMBOL_CALLS_LOCAL (info, h)) |
| 2566 | && (h == NULL |
| 2567 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
| 2568 | || h->root.type != bfd_link_hash_undefweak) |
| 2569 | && r_type != R_ARM_PC24 |
| 2570 | #ifndef OLD_ARM_ABI |
| 2571 | && r_type != R_ARM_CALL |
| 2572 | && r_type != R_ARM_JUMP24 |
| 2573 | && r_type != R_ARM_PREL31 |
| 2574 | #endif |
| 2575 | && r_type != R_ARM_PLT32) |
| 2576 | { |
| 2577 | Elf_Internal_Rela outrel; |
| 2578 | bfd_byte *loc; |
| 2579 | bfd_boolean skip, relocate; |
| 2580 | |
| 2581 | *unresolved_reloc_p = FALSE; |
| 2582 | |
| 2583 | if (sreloc == NULL) |
| 2584 | { |
| 2585 | const char * name; |
| 2586 | |
| 2587 | name = (bfd_elf_string_from_elf_section |
| 2588 | (input_bfd, |
| 2589 | elf_elfheader (input_bfd)->e_shstrndx, |
| 2590 | elf_section_data (input_section)->rel_hdr.sh_name)); |
| 2591 | if (name == NULL) |
| 2592 | return bfd_reloc_notsupported; |
| 2593 | |
| 2594 | BFD_ASSERT (strncmp (name, ".rel", 4) == 0 |
| 2595 | && strcmp (bfd_get_section_name (input_bfd, |
| 2596 | input_section), |
| 2597 | name + 4) == 0); |
| 2598 | |
| 2599 | sreloc = bfd_get_section_by_name (dynobj, name); |
| 2600 | BFD_ASSERT (sreloc != NULL); |
| 2601 | } |
| 2602 | |
| 2603 | skip = FALSE; |
| 2604 | relocate = FALSE; |
| 2605 | |
| 2606 | outrel.r_offset = |
| 2607 | _bfd_elf_section_offset (output_bfd, info, input_section, |
| 2608 | rel->r_offset); |
| 2609 | if (outrel.r_offset == (bfd_vma) -1) |
| 2610 | skip = TRUE; |
| 2611 | else if (outrel.r_offset == (bfd_vma) -2) |
| 2612 | skip = TRUE, relocate = TRUE; |
| 2613 | outrel.r_offset += (input_section->output_section->vma |
| 2614 | + input_section->output_offset); |
| 2615 | |
| 2616 | if (skip) |
| 2617 | memset (&outrel, 0, sizeof outrel); |
| 2618 | else if (h != NULL |
| 2619 | && h->dynindx != -1 |
| 2620 | && (!info->shared |
| 2621 | || !info->symbolic |
| 2622 | || !h->def_regular)) |
| 2623 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
| 2624 | else |
| 2625 | { |
| 2626 | int symbol; |
| 2627 | |
| 2628 | /* This symbol is local, or marked to become local. */ |
| 2629 | relocate = TRUE; |
| 2630 | if (sym_flags == STT_ARM_TFUNC) |
| 2631 | value |= 1; |
| 2632 | if (globals->symbian_p) |
| 2633 | { |
| 2634 | /* On Symbian OS, the data segment and text segement |
| 2635 | can be relocated independently. Therefore, we |
| 2636 | must indicate the segment to which this |
| 2637 | relocation is relative. The BPABI allows us to |
| 2638 | use any symbol in the right segment; we just use |
| 2639 | the section symbol as it is convenient. (We |
| 2640 | cannot use the symbol given by "h" directly as it |
| 2641 | will not appear in the dynamic symbol table.) */ |
| 2642 | symbol = elf_section_data (sym_sec->output_section)->dynindx; |
| 2643 | BFD_ASSERT (symbol != 0); |
| 2644 | } |
| 2645 | else |
| 2646 | /* On SVR4-ish systems, the dynamic loader cannot |
| 2647 | relocate the text and data segments independently, |
| 2648 | so the symbol does not matter. */ |
| 2649 | symbol = 0; |
| 2650 | outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE); |
| 2651 | } |
| 2652 | |
| 2653 | loc = sreloc->contents; |
| 2654 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel); |
| 2655 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); |
| 2656 | |
| 2657 | /* If this reloc is against an external symbol, we do not want to |
| 2658 | fiddle with the addend. Otherwise, we need to include the symbol |
| 2659 | value so that it becomes an addend for the dynamic reloc. */ |
| 2660 | if (! relocate) |
| 2661 | return bfd_reloc_ok; |
| 2662 | |
| 2663 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 2664 | contents, rel->r_offset, value, |
| 2665 | (bfd_vma) 0); |
| 2666 | } |
| 2667 | else switch (r_type) |
| 2668 | { |
| 2669 | #ifndef OLD_ARM_ABI |
| 2670 | case R_ARM_XPC25: /* Arm BLX instruction. */ |
| 2671 | case R_ARM_CALL: |
| 2672 | case R_ARM_JUMP24: |
| 2673 | #endif |
| 2674 | case R_ARM_PC24: /* Arm B/BL instruction */ |
| 2675 | case R_ARM_PLT32: |
| 2676 | #ifndef OLD_ARM_ABI |
| 2677 | if (r_type == R_ARM_XPC25) |
| 2678 | { |
| 2679 | /* Check for Arm calling Arm function. */ |
| 2680 | /* FIXME: Should we translate the instruction into a BL |
| 2681 | instruction instead ? */ |
| 2682 | if (sym_flags != STT_ARM_TFUNC) |
| 2683 | (*_bfd_error_handler) |
| 2684 | (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."), |
| 2685 | input_bfd, |
| 2686 | h ? h->root.root.string : "(local)"); |
| 2687 | } |
| 2688 | else |
| 2689 | #endif |
| 2690 | { |
| 2691 | /* Check for Arm calling Thumb function. */ |
| 2692 | if (sym_flags == STT_ARM_TFUNC) |
| 2693 | { |
| 2694 | elf32_arm_to_thumb_stub (info, sym_name, input_bfd, |
| 2695 | output_bfd, input_section, |
| 2696 | hit_data, sym_sec, rel->r_offset, |
| 2697 | signed_addend, value); |
| 2698 | return bfd_reloc_ok; |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | /* The ARM ELF ABI says that this reloc is computed as: S - P + A |
| 2703 | where: |
| 2704 | S is the address of the symbol in the relocation. |
| 2705 | P is address of the instruction being relocated. |
| 2706 | A is the addend (extracted from the instruction) in bytes. |
| 2707 | |
| 2708 | S is held in 'value'. |
| 2709 | P is the base address of the section containing the |
| 2710 | instruction plus the offset of the reloc into that |
| 2711 | section, ie: |
| 2712 | (input_section->output_section->vma + |
| 2713 | input_section->output_offset + |
| 2714 | rel->r_offset). |
| 2715 | A is the addend, converted into bytes, ie: |
| 2716 | (signed_addend * 4) |
| 2717 | |
| 2718 | Note: None of these operations have knowledge of the pipeline |
| 2719 | size of the processor, thus it is up to the assembler to |
| 2720 | encode this information into the addend. */ |
| 2721 | value -= (input_section->output_section->vma |
| 2722 | + input_section->output_offset); |
| 2723 | value -= rel->r_offset; |
| 2724 | if (globals->use_rel) |
| 2725 | value += (signed_addend << howto->size); |
| 2726 | else |
| 2727 | /* RELA addends do not have to be adjusted by howto->size. */ |
| 2728 | value += signed_addend; |
| 2729 | |
| 2730 | signed_addend = value; |
| 2731 | signed_addend >>= howto->rightshift; |
| 2732 | |
| 2733 | /* It is not an error for an undefined weak reference to be |
| 2734 | out of range. Any program that branches to such a symbol |
| 2735 | is going to crash anyway, so there is no point worrying |
| 2736 | about getting the destination exactly right. */ |
| 2737 | if (! h || h->root.type != bfd_link_hash_undefweak) |
| 2738 | { |
| 2739 | /* Perform a signed range check. */ |
| 2740 | if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1)) |
| 2741 | || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1))) |
| 2742 | return bfd_reloc_overflow; |
| 2743 | } |
| 2744 | |
| 2745 | #ifndef OLD_ARM_ABI |
| 2746 | /* If necessary set the H bit in the BLX instruction. */ |
| 2747 | if (r_type == R_ARM_XPC25 && ((value & 2) == 2)) |
| 2748 | value = (signed_addend & howto->dst_mask) |
| 2749 | | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask)) |
| 2750 | | (1 << 24); |
| 2751 | else |
| 2752 | #endif |
| 2753 | value = (signed_addend & howto->dst_mask) |
| 2754 | | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask)); |
| 2755 | break; |
| 2756 | |
| 2757 | case R_ARM_ABS32: |
| 2758 | value += addend; |
| 2759 | if (sym_flags == STT_ARM_TFUNC) |
| 2760 | value |= 1; |
| 2761 | break; |
| 2762 | |
| 2763 | case R_ARM_REL32: |
| 2764 | value -= (input_section->output_section->vma |
| 2765 | + input_section->output_offset + rel->r_offset); |
| 2766 | value += addend; |
| 2767 | break; |
| 2768 | |
| 2769 | #ifndef OLD_ARM_ABI |
| 2770 | case R_ARM_PREL31: |
| 2771 | value -= (input_section->output_section->vma |
| 2772 | + input_section->output_offset + rel->r_offset); |
| 2773 | value += signed_addend; |
| 2774 | if (! h || h->root.type != bfd_link_hash_undefweak) |
| 2775 | { |
| 2776 | /* Check for overflow */ |
| 2777 | if ((value ^ (value >> 1)) & (1 << 30)) |
| 2778 | return bfd_reloc_overflow; |
| 2779 | } |
| 2780 | value &= 0x7fffffff; |
| 2781 | value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000); |
| 2782 | if (sym_flags == STT_ARM_TFUNC) |
| 2783 | value |= 1; |
| 2784 | break; |
| 2785 | #endif |
| 2786 | } |
| 2787 | |
| 2788 | bfd_put_32 (input_bfd, value, hit_data); |
| 2789 | return bfd_reloc_ok; |
| 2790 | |
| 2791 | case R_ARM_ABS8: |
| 2792 | value += addend; |
| 2793 | if ((long) value > 0x7f || (long) value < -0x80) |
| 2794 | return bfd_reloc_overflow; |
| 2795 | |
| 2796 | bfd_put_8 (input_bfd, value, hit_data); |
| 2797 | return bfd_reloc_ok; |
| 2798 | |
| 2799 | case R_ARM_ABS16: |
| 2800 | value += addend; |
| 2801 | |
| 2802 | if ((long) value > 0x7fff || (long) value < -0x8000) |
| 2803 | return bfd_reloc_overflow; |
| 2804 | |
| 2805 | bfd_put_16 (input_bfd, value, hit_data); |
| 2806 | return bfd_reloc_ok; |
| 2807 | |
| 2808 | case R_ARM_ABS12: |
| 2809 | /* Support ldr and str instruction for the arm */ |
| 2810 | /* Also thumb b (unconditional branch). ??? Really? */ |
| 2811 | value += addend; |
| 2812 | |
| 2813 | if ((long) value > 0x7ff || (long) value < -0x800) |
| 2814 | return bfd_reloc_overflow; |
| 2815 | |
| 2816 | value |= (bfd_get_32 (input_bfd, hit_data) & 0xfffff000); |
| 2817 | bfd_put_32 (input_bfd, value, hit_data); |
| 2818 | return bfd_reloc_ok; |
| 2819 | |
| 2820 | case R_ARM_THM_ABS5: |
| 2821 | /* Support ldr and str instructions for the thumb. */ |
| 2822 | if (globals->use_rel) |
| 2823 | { |
| 2824 | /* Need to refetch addend. */ |
| 2825 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; |
| 2826 | /* ??? Need to determine shift amount from operand size. */ |
| 2827 | addend >>= howto->rightshift; |
| 2828 | } |
| 2829 | value += addend; |
| 2830 | |
| 2831 | /* ??? Isn't value unsigned? */ |
| 2832 | if ((long) value > 0x1f || (long) value < -0x10) |
| 2833 | return bfd_reloc_overflow; |
| 2834 | |
| 2835 | /* ??? Value needs to be properly shifted into place first. */ |
| 2836 | value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f; |
| 2837 | bfd_put_16 (input_bfd, value, hit_data); |
| 2838 | return bfd_reloc_ok; |
| 2839 | |
| 2840 | #ifndef OLD_ARM_ABI |
| 2841 | case R_ARM_THM_XPC22: |
| 2842 | #endif |
| 2843 | case R_ARM_THM_PC22: |
| 2844 | /* Thumb BL (branch long instruction). */ |
| 2845 | { |
| 2846 | bfd_vma relocation; |
| 2847 | bfd_boolean overflow = FALSE; |
| 2848 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); |
| 2849 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); |
| 2850 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; |
| 2851 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; |
| 2852 | bfd_vma check; |
| 2853 | bfd_signed_vma signed_check; |
| 2854 | |
| 2855 | /* Need to refetch the addend and squish the two 11 bit pieces |
| 2856 | together. */ |
| 2857 | if (globals->use_rel) |
| 2858 | { |
| 2859 | bfd_vma upper = upper_insn & 0x7ff; |
| 2860 | bfd_vma lower = lower_insn & 0x7ff; |
| 2861 | upper = (upper ^ 0x400) - 0x400; /* Sign extend. */ |
| 2862 | addend = (upper << 12) | (lower << 1); |
| 2863 | signed_addend = addend; |
| 2864 | } |
| 2865 | #ifndef OLD_ARM_ABI |
| 2866 | if (r_type == R_ARM_THM_XPC22) |
| 2867 | { |
| 2868 | /* Check for Thumb to Thumb call. */ |
| 2869 | /* FIXME: Should we translate the instruction into a BL |
| 2870 | instruction instead ? */ |
| 2871 | if (sym_flags == STT_ARM_TFUNC) |
| 2872 | (*_bfd_error_handler) |
| 2873 | (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."), |
| 2874 | input_bfd, |
| 2875 | h ? h->root.root.string : "(local)"); |
| 2876 | } |
| 2877 | else |
| 2878 | #endif |
| 2879 | { |
| 2880 | /* If it is not a call to Thumb, assume call to Arm. |
| 2881 | If it is a call relative to a section name, then it is not a |
| 2882 | function call at all, but rather a long jump. Calls through |
| 2883 | the PLT do not require stubs. */ |
| 2884 | if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION |
| 2885 | && (h == NULL || splt == NULL |
| 2886 | || h->plt.offset == (bfd_vma) -1)) |
| 2887 | { |
| 2888 | if (elf32_thumb_to_arm_stub |
| 2889 | (info, sym_name, input_bfd, output_bfd, input_section, |
| 2890 | hit_data, sym_sec, rel->r_offset, signed_addend, value)) |
| 2891 | return bfd_reloc_ok; |
| 2892 | else |
| 2893 | return bfd_reloc_dangerous; |
| 2894 | } |
| 2895 | } |
| 2896 | |
| 2897 | /* Handle calls via the PLT. */ |
| 2898 | if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1) |
| 2899 | { |
| 2900 | value = (splt->output_section->vma |
| 2901 | + splt->output_offset |
| 2902 | + h->plt.offset); |
| 2903 | /* Target the Thumb stub before the ARM PLT entry. */ |
| 2904 | value -= 4; |
| 2905 | *unresolved_reloc_p = FALSE; |
| 2906 | } |
| 2907 | |
| 2908 | relocation = value + signed_addend; |
| 2909 | |
| 2910 | relocation -= (input_section->output_section->vma |
| 2911 | + input_section->output_offset |
| 2912 | + rel->r_offset); |
| 2913 | |
| 2914 | check = relocation >> howto->rightshift; |
| 2915 | |
| 2916 | /* If this is a signed value, the rightshift just dropped |
| 2917 | leading 1 bits (assuming twos complement). */ |
| 2918 | if ((bfd_signed_vma) relocation >= 0) |
| 2919 | signed_check = check; |
| 2920 | else |
| 2921 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); |
| 2922 | |
| 2923 | /* Assumes two's complement. */ |
| 2924 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) |
| 2925 | overflow = TRUE; |
| 2926 | |
| 2927 | #ifndef OLD_ARM_ABI |
| 2928 | if (r_type == R_ARM_THM_XPC22 |
| 2929 | && ((lower_insn & 0x1800) == 0x0800)) |
| 2930 | /* For a BLX instruction, make sure that the relocation is rounded up |
| 2931 | to a word boundary. This follows the semantics of the instruction |
| 2932 | which specifies that bit 1 of the target address will come from bit |
| 2933 | 1 of the base address. */ |
| 2934 | relocation = (relocation + 2) & ~ 3; |
| 2935 | #endif |
| 2936 | /* Put RELOCATION back into the insn. */ |
| 2937 | upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff); |
| 2938 | lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff); |
| 2939 | |
| 2940 | /* Put the relocated value back in the object file: */ |
| 2941 | bfd_put_16 (input_bfd, upper_insn, hit_data); |
| 2942 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); |
| 2943 | |
| 2944 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); |
| 2945 | } |
| 2946 | break; |
| 2947 | |
| 2948 | case R_ARM_THM_PC11: |
| 2949 | case R_ARM_THM_PC9: |
| 2950 | /* Thumb B (branch) instruction). */ |
| 2951 | { |
| 2952 | bfd_signed_vma relocation; |
| 2953 | bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1; |
| 2954 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; |
| 2955 | bfd_signed_vma signed_check; |
| 2956 | |
| 2957 | if (globals->use_rel) |
| 2958 | { |
| 2959 | /* Need to refetch addend. */ |
| 2960 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; |
| 2961 | if (addend & ((howto->src_mask + 1) >> 1)) |
| 2962 | { |
| 2963 | signed_addend = -1; |
| 2964 | signed_addend &= ~ howto->src_mask; |
| 2965 | signed_addend |= addend; |
| 2966 | } |
| 2967 | else |
| 2968 | signed_addend = addend; |
| 2969 | /* The value in the insn has been right shifted. We need to |
| 2970 | undo this, so that we can perform the address calculation |
| 2971 | in terms of bytes. */ |
| 2972 | signed_addend <<= howto->rightshift; |
| 2973 | } |
| 2974 | relocation = value + signed_addend; |
| 2975 | |
| 2976 | relocation -= (input_section->output_section->vma |
| 2977 | + input_section->output_offset |
| 2978 | + rel->r_offset); |
| 2979 | |
| 2980 | relocation >>= howto->rightshift; |
| 2981 | signed_check = relocation; |
| 2982 | relocation &= howto->dst_mask; |
| 2983 | relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask)); |
| 2984 | |
| 2985 | bfd_put_16 (input_bfd, relocation, hit_data); |
| 2986 | |
| 2987 | /* Assumes two's complement. */ |
| 2988 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) |
| 2989 | return bfd_reloc_overflow; |
| 2990 | |
| 2991 | return bfd_reloc_ok; |
| 2992 | } |
| 2993 | |
| 2994 | #ifndef OLD_ARM_ABI |
| 2995 | case R_ARM_ALU_PCREL7_0: |
| 2996 | case R_ARM_ALU_PCREL15_8: |
| 2997 | case R_ARM_ALU_PCREL23_15: |
| 2998 | { |
| 2999 | bfd_vma insn; |
| 3000 | bfd_vma relocation; |
| 3001 | |
| 3002 | insn = bfd_get_32 (input_bfd, hit_data); |
| 3003 | if (globals->use_rel) |
| 3004 | { |
| 3005 | /* Extract the addend. */ |
| 3006 | addend = (insn & 0xff) << ((insn & 0xf00) >> 7); |
| 3007 | signed_addend = addend; |
| 3008 | } |
| 3009 | relocation = value + signed_addend; |
| 3010 | |
| 3011 | relocation -= (input_section->output_section->vma |
| 3012 | + input_section->output_offset |
| 3013 | + rel->r_offset); |
| 3014 | insn = (insn & ~0xfff) |
| 3015 | | ((howto->bitpos << 7) & 0xf00) |
| 3016 | | ((relocation >> howto->bitpos) & 0xff); |
| 3017 | bfd_put_32 (input_bfd, value, hit_data); |
| 3018 | } |
| 3019 | return bfd_reloc_ok; |
| 3020 | #endif |
| 3021 | |
| 3022 | case R_ARM_GNU_VTINHERIT: |
| 3023 | case R_ARM_GNU_VTENTRY: |
| 3024 | return bfd_reloc_ok; |
| 3025 | |
| 3026 | case R_ARM_COPY: |
| 3027 | return bfd_reloc_notsupported; |
| 3028 | |
| 3029 | case R_ARM_GLOB_DAT: |
| 3030 | return bfd_reloc_notsupported; |
| 3031 | |
| 3032 | case R_ARM_JUMP_SLOT: |
| 3033 | return bfd_reloc_notsupported; |
| 3034 | |
| 3035 | case R_ARM_RELATIVE: |
| 3036 | return bfd_reloc_notsupported; |
| 3037 | |
| 3038 | case R_ARM_GOTOFF: |
| 3039 | /* Relocation is relative to the start of the |
| 3040 | global offset table. */ |
| 3041 | |
| 3042 | BFD_ASSERT (sgot != NULL); |
| 3043 | if (sgot == NULL) |
| 3044 | return bfd_reloc_notsupported; |
| 3045 | |
| 3046 | /* If we are addressing a Thumb function, we need to adjust the |
| 3047 | address by one, so that attempts to call the function pointer will |
| 3048 | correctly interpret it as Thumb code. */ |
| 3049 | if (sym_flags == STT_ARM_TFUNC) |
| 3050 | value += 1; |
| 3051 | |
| 3052 | /* Note that sgot->output_offset is not involved in this |
| 3053 | calculation. We always want the start of .got. If we |
| 3054 | define _GLOBAL_OFFSET_TABLE in a different way, as is |
| 3055 | permitted by the ABI, we might have to change this |
| 3056 | calculation. */ |
| 3057 | value -= sgot->output_section->vma; |
| 3058 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 3059 | contents, rel->r_offset, value, |
| 3060 | (bfd_vma) 0); |
| 3061 | |
| 3062 | case R_ARM_GOTPC: |
| 3063 | /* Use global offset table as symbol value. */ |
| 3064 | BFD_ASSERT (sgot != NULL); |
| 3065 | |
| 3066 | if (sgot == NULL) |
| 3067 | return bfd_reloc_notsupported; |
| 3068 | |
| 3069 | *unresolved_reloc_p = FALSE; |
| 3070 | value = sgot->output_section->vma; |
| 3071 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 3072 | contents, rel->r_offset, value, |
| 3073 | (bfd_vma) 0); |
| 3074 | |
| 3075 | case R_ARM_GOT32: |
| 3076 | #ifndef OLD_ARM_ABI |
| 3077 | case R_ARM_GOT_PREL: |
| 3078 | #endif |
| 3079 | /* Relocation is to the entry for this symbol in the |
| 3080 | global offset table. */ |
| 3081 | if (sgot == NULL) |
| 3082 | return bfd_reloc_notsupported; |
| 3083 | |
| 3084 | if (h != NULL) |
| 3085 | { |
| 3086 | bfd_vma off; |
| 3087 | bfd_boolean dyn; |
| 3088 | |
| 3089 | off = h->got.offset; |
| 3090 | BFD_ASSERT (off != (bfd_vma) -1); |
| 3091 | dyn = globals->root.dynamic_sections_created; |
| 3092 | |
| 3093 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
| 3094 | || (info->shared |
| 3095 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
| 3096 | || (ELF_ST_VISIBILITY (h->other) |
| 3097 | && h->root.type == bfd_link_hash_undefweak)) |
| 3098 | { |
| 3099 | /* This is actually a static link, or it is a -Bsymbolic link |
| 3100 | and the symbol is defined locally. We must initialize this |
| 3101 | entry in the global offset table. Since the offset must |
| 3102 | always be a multiple of 4, we use the least significant bit |
| 3103 | to record whether we have initialized it already. |
| 3104 | |
| 3105 | When doing a dynamic link, we create a .rel.got relocation |
| 3106 | entry to initialize the value. This is done in the |
| 3107 | finish_dynamic_symbol routine. */ |
| 3108 | if ((off & 1) != 0) |
| 3109 | off &= ~1; |
| 3110 | else |
| 3111 | { |
| 3112 | /* If we are addressing a Thumb function, we need to |
| 3113 | adjust the address by one, so that attempts to |
| 3114 | call the function pointer will correctly |
| 3115 | interpret it as Thumb code. */ |
| 3116 | if (sym_flags == STT_ARM_TFUNC) |
| 3117 | value |= 1; |
| 3118 | |
| 3119 | bfd_put_32 (output_bfd, value, sgot->contents + off); |
| 3120 | h->got.offset |= 1; |
| 3121 | } |
| 3122 | } |
| 3123 | else |
| 3124 | *unresolved_reloc_p = FALSE; |
| 3125 | |
| 3126 | value = sgot->output_offset + off; |
| 3127 | } |
| 3128 | else |
| 3129 | { |
| 3130 | bfd_vma off; |
| 3131 | |
| 3132 | BFD_ASSERT (local_got_offsets != NULL && |
| 3133 | local_got_offsets[r_symndx] != (bfd_vma) -1); |
| 3134 | |
| 3135 | off = local_got_offsets[r_symndx]; |
| 3136 | |
| 3137 | /* The offset must always be a multiple of 4. We use the |
| 3138 | least significant bit to record whether we have already |
| 3139 | generated the necessary reloc. */ |
| 3140 | if ((off & 1) != 0) |
| 3141 | off &= ~1; |
| 3142 | else |
| 3143 | { |
| 3144 | /* If we are addressing a Thumb function, we need to |
| 3145 | adjust the address by one, so that attempts to |
| 3146 | call the function pointer will correctly |
| 3147 | interpret it as Thumb code. */ |
| 3148 | if (sym_flags == STT_ARM_TFUNC) |
| 3149 | value |= 1; |
| 3150 | |
| 3151 | bfd_put_32 (output_bfd, value, sgot->contents + off); |
| 3152 | |
| 3153 | if (info->shared) |
| 3154 | { |
| 3155 | asection * srelgot; |
| 3156 | Elf_Internal_Rela outrel; |
| 3157 | bfd_byte *loc; |
| 3158 | |
| 3159 | srelgot = bfd_get_section_by_name (dynobj, ".rel.got"); |
| 3160 | BFD_ASSERT (srelgot != NULL); |
| 3161 | |
| 3162 | outrel.r_offset = (sgot->output_section->vma |
| 3163 | + sgot->output_offset |
| 3164 | + off); |
| 3165 | outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); |
| 3166 | loc = srelgot->contents; |
| 3167 | loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rel); |
| 3168 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); |
| 3169 | } |
| 3170 | |
| 3171 | local_got_offsets[r_symndx] |= 1; |
| 3172 | } |
| 3173 | |
| 3174 | value = sgot->output_offset + off; |
| 3175 | } |
| 3176 | if (r_type != R_ARM_GOT32) |
| 3177 | value += sgot->output_section->vma; |
| 3178 | |
| 3179 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 3180 | contents, rel->r_offset, value, |
| 3181 | (bfd_vma) 0); |
| 3182 | |
| 3183 | case R_ARM_TLS_LDO32: |
| 3184 | value = value - dtpoff_base (info); |
| 3185 | |
| 3186 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 3187 | contents, rel->r_offset, value, (bfd_vma) 0); |
| 3188 | |
| 3189 | case R_ARM_TLS_LDM32: |
| 3190 | { |
| 3191 | bfd_vma off; |
| 3192 | |
| 3193 | if (globals->sgot == NULL) |
| 3194 | abort (); |
| 3195 | |
| 3196 | off = globals->tls_ldm_got.offset; |
| 3197 | |
| 3198 | if ((off & 1) != 0) |
| 3199 | off &= ~1; |
| 3200 | else |
| 3201 | { |
| 3202 | /* If we don't know the module number, create a relocation |
| 3203 | for it. */ |
| 3204 | if (info->shared) |
| 3205 | { |
| 3206 | Elf_Internal_Rela outrel; |
| 3207 | bfd_byte *loc; |
| 3208 | |
| 3209 | if (globals->srelgot == NULL) |
| 3210 | abort (); |
| 3211 | |
| 3212 | outrel.r_offset = (globals->sgot->output_section->vma |
| 3213 | + globals->sgot->output_offset + off); |
| 3214 | outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32); |
| 3215 | |
| 3216 | bfd_put_32 (output_bfd, 0, globals->sgot->contents + off); |
| 3217 | |
| 3218 | loc = globals->srelgot->contents; |
| 3219 | loc += globals->srelgot->reloc_count++ * sizeof (Elf32_External_Rel); |
| 3220 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); |
| 3221 | } |
| 3222 | else |
| 3223 | bfd_put_32 (output_bfd, 1, globals->sgot->contents + off); |
| 3224 | |
| 3225 | globals->tls_ldm_got.offset |= 1; |
| 3226 | } |
| 3227 | |
| 3228 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off |
| 3229 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); |
| 3230 | |
| 3231 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 3232 | contents, rel->r_offset, value, |
| 3233 | (bfd_vma) 0); |
| 3234 | } |
| 3235 | |
| 3236 | case R_ARM_TLS_GD32: |
| 3237 | case R_ARM_TLS_IE32: |
| 3238 | { |
| 3239 | bfd_vma off; |
| 3240 | int indx; |
| 3241 | char tls_type; |
| 3242 | |
| 3243 | if (globals->sgot == NULL) |
| 3244 | abort (); |
| 3245 | |
| 3246 | indx = 0; |
| 3247 | if (h != NULL) |
| 3248 | { |
| 3249 | bfd_boolean dyn; |
| 3250 | dyn = globals->root.dynamic_sections_created; |
| 3251 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
| 3252 | && (!info->shared |
| 3253 | || !SYMBOL_REFERENCES_LOCAL (info, h))) |
| 3254 | { |
| 3255 | *unresolved_reloc_p = FALSE; |
| 3256 | indx = h->dynindx; |
| 3257 | } |
| 3258 | off = h->got.offset; |
| 3259 | tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type; |
| 3260 | } |
| 3261 | else |
| 3262 | { |
| 3263 | if (local_got_offsets == NULL) |
| 3264 | abort (); |
| 3265 | off = local_got_offsets[r_symndx]; |
| 3266 | tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx]; |
| 3267 | } |
| 3268 | |
| 3269 | if (tls_type == GOT_UNKNOWN) |
| 3270 | abort (); |
| 3271 | |
| 3272 | if ((off & 1) != 0) |
| 3273 | off &= ~1; |
| 3274 | else |
| 3275 | { |
| 3276 | bfd_boolean need_relocs = FALSE; |
| 3277 | Elf_Internal_Rela outrel; |
| 3278 | bfd_byte *loc = NULL; |
| 3279 | int cur_off = off; |
| 3280 | |
| 3281 | /* The GOT entries have not been initialized yet. Do it |
| 3282 | now, and emit any relocations. If both an IE GOT and a |
| 3283 | GD GOT are necessary, we emit the GD first. */ |
| 3284 | |
| 3285 | if ((info->shared || indx != 0) |
| 3286 | && (h == NULL |
| 3287 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
| 3288 | || h->root.type != bfd_link_hash_undefweak)) |
| 3289 | { |
| 3290 | need_relocs = TRUE; |
| 3291 | if (globals->srelgot == NULL) |
| 3292 | abort (); |
| 3293 | loc = globals->srelgot->contents; |
| 3294 | loc += globals->srelgot->reloc_count * sizeof (Elf32_External_Rel); |
| 3295 | } |
| 3296 | |
| 3297 | if (tls_type & GOT_TLS_GD) |
| 3298 | { |
| 3299 | if (need_relocs) |
| 3300 | { |
| 3301 | outrel.r_offset = (globals->sgot->output_section->vma |
| 3302 | + globals->sgot->output_offset + cur_off); |
| 3303 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32); |
| 3304 | bfd_put_32 (output_bfd, 0, globals->sgot->contents + cur_off); |
| 3305 | |
| 3306 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); |
| 3307 | globals->srelgot->reloc_count++; |
| 3308 | loc += sizeof (Elf32_External_Rel); |
| 3309 | |
| 3310 | if (indx == 0) |
| 3311 | bfd_put_32 (output_bfd, value - dtpoff_base (info), |
| 3312 | globals->sgot->contents + cur_off + 4); |
| 3313 | else |
| 3314 | { |
| 3315 | bfd_put_32 (output_bfd, 0, |
| 3316 | globals->sgot->contents + cur_off + 4); |
| 3317 | |
| 3318 | outrel.r_info = ELF32_R_INFO (indx, |
| 3319 | R_ARM_TLS_DTPOFF32); |
| 3320 | outrel.r_offset += 4; |
| 3321 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); |
| 3322 | globals->srelgot->reloc_count++; |
| 3323 | loc += sizeof (Elf32_External_Rel); |
| 3324 | } |
| 3325 | } |
| 3326 | else |
| 3327 | { |
| 3328 | /* If we are not emitting relocations for a |
| 3329 | general dynamic reference, then we must be in a |
| 3330 | static link or an executable link with the |
| 3331 | symbol binding locally. Mark it as belonging |
| 3332 | to module 1, the executable. */ |
| 3333 | bfd_put_32 (output_bfd, 1, |
| 3334 | globals->sgot->contents + cur_off); |
| 3335 | bfd_put_32 (output_bfd, value - dtpoff_base (info), |
| 3336 | globals->sgot->contents + cur_off + 4); |
| 3337 | } |
| 3338 | |
| 3339 | cur_off += 8; |
| 3340 | } |
| 3341 | |
| 3342 | if (tls_type & GOT_TLS_IE) |
| 3343 | { |
| 3344 | if (need_relocs) |
| 3345 | { |
| 3346 | outrel.r_offset = (globals->sgot->output_section->vma |
| 3347 | + globals->sgot->output_offset |
| 3348 | + cur_off); |
| 3349 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32); |
| 3350 | |
| 3351 | if (indx == 0) |
| 3352 | bfd_put_32 (output_bfd, value - dtpoff_base (info), |
| 3353 | globals->sgot->contents + cur_off); |
| 3354 | else |
| 3355 | bfd_put_32 (output_bfd, 0, |
| 3356 | globals->sgot->contents + cur_off); |
| 3357 | |
| 3358 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); |
| 3359 | globals->srelgot->reloc_count++; |
| 3360 | loc += sizeof (Elf32_External_Rel); |
| 3361 | } |
| 3362 | else |
| 3363 | bfd_put_32 (output_bfd, tpoff (info, value), |
| 3364 | globals->sgot->contents + cur_off); |
| 3365 | cur_off += 4; |
| 3366 | } |
| 3367 | |
| 3368 | if (h != NULL) |
| 3369 | h->got.offset |= 1; |
| 3370 | else |
| 3371 | local_got_offsets[r_symndx] |= 1; |
| 3372 | } |
| 3373 | |
| 3374 | if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32) |
| 3375 | off += 8; |
| 3376 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off |
| 3377 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); |
| 3378 | |
| 3379 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 3380 | contents, rel->r_offset, value, |
| 3381 | (bfd_vma) 0); |
| 3382 | } |
| 3383 | |
| 3384 | case R_ARM_TLS_LE32: |
| 3385 | if (info->shared) |
| 3386 | { |
| 3387 | (*_bfd_error_handler) |
| 3388 | (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"), |
| 3389 | input_bfd, input_section, |
| 3390 | (long) rel->r_offset, howto->name); |
| 3391 | return FALSE; |
| 3392 | } |
| 3393 | else |
| 3394 | value = tpoff (info, value); |
| 3395 | |
| 3396 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 3397 | contents, rel->r_offset, value, (bfd_vma) 0); |
| 3398 | |
| 3399 | case R_ARM_SBREL32: |
| 3400 | return bfd_reloc_notsupported; |
| 3401 | |
| 3402 | case R_ARM_AMP_VCALL9: |
| 3403 | return bfd_reloc_notsupported; |
| 3404 | |
| 3405 | case R_ARM_RSBREL32: |
| 3406 | return bfd_reloc_notsupported; |
| 3407 | |
| 3408 | case R_ARM_THM_RPC22: |
| 3409 | return bfd_reloc_notsupported; |
| 3410 | |
| 3411 | case R_ARM_RREL32: |
| 3412 | return bfd_reloc_notsupported; |
| 3413 | |
| 3414 | case R_ARM_RABS32: |
| 3415 | return bfd_reloc_notsupported; |
| 3416 | |
| 3417 | case R_ARM_RPC24: |
| 3418 | return bfd_reloc_notsupported; |
| 3419 | |
| 3420 | case R_ARM_RBASE: |
| 3421 | return bfd_reloc_notsupported; |
| 3422 | |
| 3423 | case R_ARM_V4BX: |
| 3424 | if (globals->fix_v4bx) |
| 3425 | { |
| 3426 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); |
| 3427 | |
| 3428 | /* Ensure that we have a BX instruction. */ |
| 3429 | BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10); |
| 3430 | |
| 3431 | /* Preserve Rm (lowest four bits) and the condition code |
| 3432 | (highest four bits). Other bits encode MOV PC,Rm. */ |
| 3433 | insn = (insn & 0xf000000f) | 0x01a0f000; |
| 3434 | |
| 3435 | bfd_put_32 (input_bfd, insn, hit_data); |
| 3436 | } |
| 3437 | return bfd_reloc_ok; |
| 3438 | |
| 3439 | default: |
| 3440 | return bfd_reloc_notsupported; |
| 3441 | } |
| 3442 | } |
| 3443 | |
| 3444 | /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */ |
| 3445 | static void |
| 3446 | arm_add_to_rel (bfd * abfd, |
| 3447 | bfd_byte * address, |
| 3448 | reloc_howto_type * howto, |
| 3449 | bfd_signed_vma increment) |
| 3450 | { |
| 3451 | bfd_signed_vma addend; |
| 3452 | |
| 3453 | if (howto->type == R_ARM_THM_PC22) |
| 3454 | { |
| 3455 | int upper_insn, lower_insn; |
| 3456 | int upper, lower; |
| 3457 | |
| 3458 | upper_insn = bfd_get_16 (abfd, address); |
| 3459 | lower_insn = bfd_get_16 (abfd, address + 2); |
| 3460 | upper = upper_insn & 0x7ff; |
| 3461 | lower = lower_insn & 0x7ff; |
| 3462 | |
| 3463 | addend = (upper << 12) | (lower << 1); |
| 3464 | addend += increment; |
| 3465 | addend >>= 1; |
| 3466 | |
| 3467 | upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff); |
| 3468 | lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff); |
| 3469 | |
| 3470 | bfd_put_16 (abfd, (bfd_vma) upper_insn, address); |
| 3471 | bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2); |
| 3472 | } |
| 3473 | else |
| 3474 | { |
| 3475 | bfd_vma contents; |
| 3476 | |
| 3477 | contents = bfd_get_32 (abfd, address); |
| 3478 | |
| 3479 | /* Get the (signed) value from the instruction. */ |
| 3480 | addend = contents & howto->src_mask; |
| 3481 | if (addend & ((howto->src_mask + 1) >> 1)) |
| 3482 | { |
| 3483 | bfd_signed_vma mask; |
| 3484 | |
| 3485 | mask = -1; |
| 3486 | mask &= ~ howto->src_mask; |
| 3487 | addend |= mask; |
| 3488 | } |
| 3489 | |
| 3490 | /* Add in the increment, (which is a byte value). */ |
| 3491 | switch (howto->type) |
| 3492 | { |
| 3493 | default: |
| 3494 | addend += increment; |
| 3495 | break; |
| 3496 | |
| 3497 | case R_ARM_PC24: |
| 3498 | #ifndef OLD_ARM_ABI |
| 3499 | case R_ARM_CALL: |
| 3500 | case R_ARM_JUMP24: |
| 3501 | #endif |
| 3502 | addend <<= howto->size; |
| 3503 | addend += increment; |
| 3504 | |
| 3505 | /* Should we check for overflow here ? */ |
| 3506 | |
| 3507 | /* Drop any undesired bits. */ |
| 3508 | addend >>= howto->rightshift; |
| 3509 | break; |
| 3510 | } |
| 3511 | |
| 3512 | contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask); |
| 3513 | |
| 3514 | bfd_put_32 (abfd, contents, address); |
| 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | #define IS_ARM_TLS_RELOC(R_TYPE) \ |
| 3519 | ((R_TYPE) == R_ARM_TLS_GD32 \ |
| 3520 | || (R_TYPE) == R_ARM_TLS_LDO32 \ |
| 3521 | || (R_TYPE) == R_ARM_TLS_LDM32 \ |
| 3522 | || (R_TYPE) == R_ARM_TLS_DTPOFF32 \ |
| 3523 | || (R_TYPE) == R_ARM_TLS_DTPMOD32 \ |
| 3524 | || (R_TYPE) == R_ARM_TLS_TPOFF32 \ |
| 3525 | || (R_TYPE) == R_ARM_TLS_LE32 \ |
| 3526 | || (R_TYPE) == R_ARM_TLS_IE32) |
| 3527 | |
| 3528 | /* Relocate an ARM ELF section. */ |
| 3529 | static bfd_boolean |
| 3530 | elf32_arm_relocate_section (bfd * output_bfd, |
| 3531 | struct bfd_link_info * info, |
| 3532 | bfd * input_bfd, |
| 3533 | asection * input_section, |
| 3534 | bfd_byte * contents, |
| 3535 | Elf_Internal_Rela * relocs, |
| 3536 | Elf_Internal_Sym * local_syms, |
| 3537 | asection ** local_sections) |
| 3538 | { |
| 3539 | Elf_Internal_Shdr *symtab_hdr; |
| 3540 | struct elf_link_hash_entry **sym_hashes; |
| 3541 | Elf_Internal_Rela *rel; |
| 3542 | Elf_Internal_Rela *relend; |
| 3543 | const char *name; |
| 3544 | struct elf32_arm_link_hash_table * globals; |
| 3545 | |
| 3546 | globals = elf32_arm_hash_table (info); |
| 3547 | if (info->relocatable && !globals->use_rel) |
| 3548 | return TRUE; |
| 3549 | |
| 3550 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; |
| 3551 | sym_hashes = elf_sym_hashes (input_bfd); |
| 3552 | |
| 3553 | rel = relocs; |
| 3554 | relend = relocs + input_section->reloc_count; |
| 3555 | for (; rel < relend; rel++) |
| 3556 | { |
| 3557 | int r_type; |
| 3558 | reloc_howto_type * howto; |
| 3559 | unsigned long r_symndx; |
| 3560 | Elf_Internal_Sym * sym; |
| 3561 | asection * sec; |
| 3562 | struct elf_link_hash_entry * h; |
| 3563 | bfd_vma relocation; |
| 3564 | bfd_reloc_status_type r; |
| 3565 | arelent bfd_reloc; |
| 3566 | char sym_type; |
| 3567 | bfd_boolean unresolved_reloc = FALSE; |
| 3568 | |
| 3569 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 3570 | r_type = ELF32_R_TYPE (rel->r_info); |
| 3571 | r_type = arm_real_reloc_type (globals, r_type); |
| 3572 | |
| 3573 | if ( r_type == R_ARM_GNU_VTENTRY |
| 3574 | || r_type == R_ARM_GNU_VTINHERIT) |
| 3575 | continue; |
| 3576 | |
| 3577 | bfd_reloc.howto = elf32_arm_howto_from_type (r_type); |
| 3578 | howto = bfd_reloc.howto; |
| 3579 | |
| 3580 | if (info->relocatable && globals->use_rel) |
| 3581 | { |
| 3582 | /* This is a relocatable link. We don't have to change |
| 3583 | anything, unless the reloc is against a section symbol, |
| 3584 | in which case we have to adjust according to where the |
| 3585 | section symbol winds up in the output section. */ |
| 3586 | if (r_symndx < symtab_hdr->sh_info) |
| 3587 | { |
| 3588 | sym = local_syms + r_symndx; |
| 3589 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) |
| 3590 | { |
| 3591 | sec = local_sections[r_symndx]; |
| 3592 | arm_add_to_rel (input_bfd, contents + rel->r_offset, |
| 3593 | howto, |
| 3594 | (bfd_signed_vma) (sec->output_offset |
| 3595 | + sym->st_value)); |
| 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | continue; |
| 3600 | } |
| 3601 | |
| 3602 | /* This is a final link. */ |
| 3603 | h = NULL; |
| 3604 | sym = NULL; |
| 3605 | sec = NULL; |
| 3606 | |
| 3607 | if (r_symndx < symtab_hdr->sh_info) |
| 3608 | { |
| 3609 | sym = local_syms + r_symndx; |
| 3610 | sym_type = ELF32_ST_TYPE (sym->st_info); |
| 3611 | sec = local_sections[r_symndx]; |
| 3612 | if (globals->use_rel) |
| 3613 | { |
| 3614 | relocation = (sec->output_section->vma |
| 3615 | + sec->output_offset |
| 3616 | + sym->st_value); |
| 3617 | if ((sec->flags & SEC_MERGE) |
| 3618 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION) |
| 3619 | { |
| 3620 | asection *msec; |
| 3621 | bfd_vma addend, value; |
| 3622 | |
| 3623 | if (howto->rightshift) |
| 3624 | { |
| 3625 | (*_bfd_error_handler) |
| 3626 | (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"), |
| 3627 | input_bfd, input_section, |
| 3628 | (long) rel->r_offset, howto->name); |
| 3629 | return FALSE; |
| 3630 | } |
| 3631 | |
| 3632 | value = bfd_get_32 (input_bfd, contents + rel->r_offset); |
| 3633 | |
| 3634 | /* Get the (signed) value from the instruction. */ |
| 3635 | addend = value & howto->src_mask; |
| 3636 | if (addend & ((howto->src_mask + 1) >> 1)) |
| 3637 | { |
| 3638 | bfd_signed_vma mask; |
| 3639 | |
| 3640 | mask = -1; |
| 3641 | mask &= ~ howto->src_mask; |
| 3642 | addend |= mask; |
| 3643 | } |
| 3644 | msec = sec; |
| 3645 | addend = |
| 3646 | _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) |
| 3647 | - relocation; |
| 3648 | addend += msec->output_section->vma + msec->output_offset; |
| 3649 | value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask); |
| 3650 | bfd_put_32 (input_bfd, value, contents + rel->r_offset); |
| 3651 | } |
| 3652 | } |
| 3653 | else |
| 3654 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
| 3655 | } |
| 3656 | else |
| 3657 | { |
| 3658 | bfd_boolean warned; |
| 3659 | |
| 3660 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
| 3661 | r_symndx, symtab_hdr, sym_hashes, |
| 3662 | h, sec, relocation, |
| 3663 | unresolved_reloc, warned); |
| 3664 | |
| 3665 | sym_type = h->type; |
| 3666 | } |
| 3667 | |
| 3668 | if (h != NULL) |
| 3669 | name = h->root.root.string; |
| 3670 | else |
| 3671 | { |
| 3672 | name = (bfd_elf_string_from_elf_section |
| 3673 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); |
| 3674 | if (name == NULL || *name == '\0') |
| 3675 | name = bfd_section_name (input_bfd, sec); |
| 3676 | } |
| 3677 | |
| 3678 | if (r_symndx != 0 |
| 3679 | && r_type != R_ARM_NONE |
| 3680 | && (h == NULL |
| 3681 | || h->root.type == bfd_link_hash_defined |
| 3682 | || h->root.type == bfd_link_hash_defweak) |
| 3683 | && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS)) |
| 3684 | { |
| 3685 | (*_bfd_error_handler) |
| 3686 | ((sym_type == STT_TLS |
| 3687 | ? _("%B(%A+0x%lx): %s used with TLS symbol %s") |
| 3688 | : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")), |
| 3689 | input_bfd, |
| 3690 | input_section, |
| 3691 | (long) rel->r_offset, |
| 3692 | howto->name, |
| 3693 | name); |
| 3694 | } |
| 3695 | |
| 3696 | r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd, |
| 3697 | input_section, contents, rel, |
| 3698 | relocation, info, sec, name, |
| 3699 | (h ? ELF_ST_TYPE (h->type) : |
| 3700 | ELF_ST_TYPE (sym->st_info)), h, |
| 3701 | &unresolved_reloc); |
| 3702 | |
| 3703 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
| 3704 | because such sections are not SEC_ALLOC and thus ld.so will |
| 3705 | not process them. */ |
| 3706 | if (unresolved_reloc |
| 3707 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
| 3708 | && h->def_dynamic)) |
| 3709 | { |
| 3710 | (*_bfd_error_handler) |
| 3711 | (_("%B(%A+0x%lx): warning: unresolvable relocation %d against symbol `%s'"), |
| 3712 | input_bfd, input_section, (long) rel->r_offset, |
| 3713 | r_type, h->root.root.string); |
| 3714 | return FALSE; |
| 3715 | } |
| 3716 | |
| 3717 | if (r != bfd_reloc_ok) |
| 3718 | { |
| 3719 | const char * msg = (const char *) 0; |
| 3720 | |
| 3721 | switch (r) |
| 3722 | { |
| 3723 | case bfd_reloc_overflow: |
| 3724 | /* If the overflowing reloc was to an undefined symbol, |
| 3725 | we have already printed one error message and there |
| 3726 | is no point complaining again. */ |
| 3727 | if ((! h || |
| 3728 | h->root.type != bfd_link_hash_undefined) |
| 3729 | && (!((*info->callbacks->reloc_overflow) |
| 3730 | (info, (h ? &h->root : NULL), name, howto->name, |
| 3731 | (bfd_vma) 0, input_bfd, input_section, |
| 3732 | rel->r_offset)))) |
| 3733 | return FALSE; |
| 3734 | break; |
| 3735 | |
| 3736 | case bfd_reloc_undefined: |
| 3737 | if (!((*info->callbacks->undefined_symbol) |
| 3738 | (info, name, input_bfd, input_section, |
| 3739 | rel->r_offset, TRUE))) |
| 3740 | return FALSE; |
| 3741 | break; |
| 3742 | |
| 3743 | case bfd_reloc_outofrange: |
| 3744 | msg = _("internal error: out of range error"); |
| 3745 | goto common_error; |
| 3746 | |
| 3747 | case bfd_reloc_notsupported: |
| 3748 | msg = _("internal error: unsupported relocation error"); |
| 3749 | goto common_error; |
| 3750 | |
| 3751 | case bfd_reloc_dangerous: |
| 3752 | msg = _("internal error: dangerous error"); |
| 3753 | goto common_error; |
| 3754 | |
| 3755 | default: |
| 3756 | msg = _("internal error: unknown error"); |
| 3757 | /* fall through */ |
| 3758 | |
| 3759 | common_error: |
| 3760 | if (!((*info->callbacks->warning) |
| 3761 | (info, msg, name, input_bfd, input_section, |
| 3762 | rel->r_offset))) |
| 3763 | return FALSE; |
| 3764 | break; |
| 3765 | } |
| 3766 | } |
| 3767 | } |
| 3768 | |
| 3769 | return TRUE; |
| 3770 | } |
| 3771 | |
| 3772 | /* Set the right machine number. */ |
| 3773 | |
| 3774 | static bfd_boolean |
| 3775 | elf32_arm_object_p (bfd *abfd) |
| 3776 | { |
| 3777 | unsigned int mach; |
| 3778 | |
| 3779 | mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION); |
| 3780 | |
| 3781 | if (mach != bfd_mach_arm_unknown) |
| 3782 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); |
| 3783 | |
| 3784 | else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT) |
| 3785 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312); |
| 3786 | |
| 3787 | else |
| 3788 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); |
| 3789 | |
| 3790 | return TRUE; |
| 3791 | } |
| 3792 | |
| 3793 | /* Function to keep ARM specific flags in the ELF header. */ |
| 3794 | |
| 3795 | static bfd_boolean |
| 3796 | elf32_arm_set_private_flags (bfd *abfd, flagword flags) |
| 3797 | { |
| 3798 | if (elf_flags_init (abfd) |
| 3799 | && elf_elfheader (abfd)->e_flags != flags) |
| 3800 | { |
| 3801 | if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN) |
| 3802 | { |
| 3803 | if (flags & EF_ARM_INTERWORK) |
| 3804 | (*_bfd_error_handler) |
| 3805 | (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"), |
| 3806 | abfd); |
| 3807 | else |
| 3808 | _bfd_error_handler |
| 3809 | (_("Warning: Clearing the interworking flag of %B due to outside request"), |
| 3810 | abfd); |
| 3811 | } |
| 3812 | } |
| 3813 | else |
| 3814 | { |
| 3815 | elf_elfheader (abfd)->e_flags = flags; |
| 3816 | elf_flags_init (abfd) = TRUE; |
| 3817 | } |
| 3818 | |
| 3819 | return TRUE; |
| 3820 | } |
| 3821 | |
| 3822 | /* Copy backend specific data from one object module to another. */ |
| 3823 | |
| 3824 | static bfd_boolean |
| 3825 | elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd) |
| 3826 | { |
| 3827 | flagword in_flags; |
| 3828 | flagword out_flags; |
| 3829 | |
| 3830 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 3831 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 3832 | return TRUE; |
| 3833 | |
| 3834 | in_flags = elf_elfheader (ibfd)->e_flags; |
| 3835 | out_flags = elf_elfheader (obfd)->e_flags; |
| 3836 | |
| 3837 | if (elf_flags_init (obfd) |
| 3838 | && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN |
| 3839 | && in_flags != out_flags) |
| 3840 | { |
| 3841 | /* Cannot mix APCS26 and APCS32 code. */ |
| 3842 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
| 3843 | return FALSE; |
| 3844 | |
| 3845 | /* Cannot mix float APCS and non-float APCS code. */ |
| 3846 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
| 3847 | return FALSE; |
| 3848 | |
| 3849 | /* If the src and dest have different interworking flags |
| 3850 | then turn off the interworking bit. */ |
| 3851 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
| 3852 | { |
| 3853 | if (out_flags & EF_ARM_INTERWORK) |
| 3854 | _bfd_error_handler |
| 3855 | (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"), |
| 3856 | obfd, ibfd); |
| 3857 | |
| 3858 | in_flags &= ~EF_ARM_INTERWORK; |
| 3859 | } |
| 3860 | |
| 3861 | /* Likewise for PIC, though don't warn for this case. */ |
| 3862 | if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC)) |
| 3863 | in_flags &= ~EF_ARM_PIC; |
| 3864 | } |
| 3865 | |
| 3866 | elf_elfheader (obfd)->e_flags = in_flags; |
| 3867 | elf_flags_init (obfd) = TRUE; |
| 3868 | |
| 3869 | /* Also copy the EI_OSABI field. */ |
| 3870 | elf_elfheader (obfd)->e_ident[EI_OSABI] = |
| 3871 | elf_elfheader (ibfd)->e_ident[EI_OSABI]; |
| 3872 | |
| 3873 | return TRUE; |
| 3874 | } |
| 3875 | |
| 3876 | /* Merge backend specific data from an object file to the output |
| 3877 | object file when linking. */ |
| 3878 | |
| 3879 | static bfd_boolean |
| 3880 | elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd) |
| 3881 | { |
| 3882 | flagword out_flags; |
| 3883 | flagword in_flags; |
| 3884 | bfd_boolean flags_compatible = TRUE; |
| 3885 | asection *sec; |
| 3886 | |
| 3887 | /* Check if we have the same endianess. */ |
| 3888 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) |
| 3889 | return FALSE; |
| 3890 | |
| 3891 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 3892 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 3893 | return TRUE; |
| 3894 | |
| 3895 | /* The input BFD must have had its flags initialised. */ |
| 3896 | /* The following seems bogus to me -- The flags are initialized in |
| 3897 | the assembler but I don't think an elf_flags_init field is |
| 3898 | written into the object. */ |
| 3899 | /* BFD_ASSERT (elf_flags_init (ibfd)); */ |
| 3900 | |
| 3901 | in_flags = elf_elfheader (ibfd)->e_flags; |
| 3902 | out_flags = elf_elfheader (obfd)->e_flags; |
| 3903 | |
| 3904 | if (!elf_flags_init (obfd)) |
| 3905 | { |
| 3906 | /* If the input is the default architecture and had the default |
| 3907 | flags then do not bother setting the flags for the output |
| 3908 | architecture, instead allow future merges to do this. If no |
| 3909 | future merges ever set these flags then they will retain their |
| 3910 | uninitialised values, which surprise surprise, correspond |
| 3911 | to the default values. */ |
| 3912 | if (bfd_get_arch_info (ibfd)->the_default |
| 3913 | && elf_elfheader (ibfd)->e_flags == 0) |
| 3914 | return TRUE; |
| 3915 | |
| 3916 | elf_flags_init (obfd) = TRUE; |
| 3917 | elf_elfheader (obfd)->e_flags = in_flags; |
| 3918 | |
| 3919 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) |
| 3920 | && bfd_get_arch_info (obfd)->the_default) |
| 3921 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd)); |
| 3922 | |
| 3923 | return TRUE; |
| 3924 | } |
| 3925 | |
| 3926 | /* Determine what should happen if the input ARM architecture |
| 3927 | does not match the output ARM architecture. */ |
| 3928 | if (! bfd_arm_merge_machines (ibfd, obfd)) |
| 3929 | return FALSE; |
| 3930 | |
| 3931 | /* Identical flags must be compatible. */ |
| 3932 | if (in_flags == out_flags) |
| 3933 | return TRUE; |
| 3934 | |
| 3935 | /* Check to see if the input BFD actually contains any sections. If |
| 3936 | not, its flags may not have been initialised either, but it |
| 3937 | cannot actually cause any incompatibility. Do not short-circuit |
| 3938 | dynamic objects; their section list may be emptied by |
| 3939 | elf_link_add_object_symbols. |
| 3940 | |
| 3941 | Also check to see if there are no code sections in the input. |
| 3942 | In this case there is no need to check for code specific flags. |
| 3943 | XXX - do we need to worry about floating-point format compatability |
| 3944 | in data sections ? */ |
| 3945 | if (!(ibfd->flags & DYNAMIC)) |
| 3946 | { |
| 3947 | bfd_boolean null_input_bfd = TRUE; |
| 3948 | bfd_boolean only_data_sections = TRUE; |
| 3949 | |
| 3950 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
| 3951 | { |
| 3952 | /* Ignore synthetic glue sections. */ |
| 3953 | if (strcmp (sec->name, ".glue_7") |
| 3954 | && strcmp (sec->name, ".glue_7t")) |
| 3955 | { |
| 3956 | if ((bfd_get_section_flags (ibfd, sec) |
| 3957 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) |
| 3958 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) |
| 3959 | only_data_sections = FALSE; |
| 3960 | |
| 3961 | null_input_bfd = FALSE; |
| 3962 | break; |
| 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | if (null_input_bfd || only_data_sections) |
| 3967 | return TRUE; |
| 3968 | } |
| 3969 | |
| 3970 | /* Complain about various flag mismatches. */ |
| 3971 | if (EF_ARM_EABI_VERSION (in_flags) != EF_ARM_EABI_VERSION (out_flags)) |
| 3972 | { |
| 3973 | _bfd_error_handler |
| 3974 | (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"), |
| 3975 | ibfd, obfd, |
| 3976 | (in_flags & EF_ARM_EABIMASK) >> 24, |
| 3977 | (out_flags & EF_ARM_EABIMASK) >> 24); |
| 3978 | return FALSE; |
| 3979 | } |
| 3980 | |
| 3981 | /* Not sure what needs to be checked for EABI versions >= 1. */ |
| 3982 | if (EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN) |
| 3983 | { |
| 3984 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
| 3985 | { |
| 3986 | _bfd_error_handler |
| 3987 | (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"), |
| 3988 | ibfd, obfd, |
| 3989 | in_flags & EF_ARM_APCS_26 ? 26 : 32, |
| 3990 | out_flags & EF_ARM_APCS_26 ? 26 : 32); |
| 3991 | flags_compatible = FALSE; |
| 3992 | } |
| 3993 | |
| 3994 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
| 3995 | { |
| 3996 | if (in_flags & EF_ARM_APCS_FLOAT) |
| 3997 | _bfd_error_handler |
| 3998 | (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"), |
| 3999 | ibfd, obfd); |
| 4000 | else |
| 4001 | _bfd_error_handler |
| 4002 | (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"), |
| 4003 | ibfd, obfd); |
| 4004 | |
| 4005 | flags_compatible = FALSE; |
| 4006 | } |
| 4007 | |
| 4008 | if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT)) |
| 4009 | { |
| 4010 | if (in_flags & EF_ARM_VFP_FLOAT) |
| 4011 | _bfd_error_handler |
| 4012 | (_("ERROR: %B uses VFP instructions, whereas %B does not"), |
| 4013 | ibfd, obfd); |
| 4014 | else |
| 4015 | _bfd_error_handler |
| 4016 | (_("ERROR: %B uses FPA instructions, whereas %B does not"), |
| 4017 | ibfd, obfd); |
| 4018 | |
| 4019 | flags_compatible = FALSE; |
| 4020 | } |
| 4021 | |
| 4022 | if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT)) |
| 4023 | { |
| 4024 | if (in_flags & EF_ARM_MAVERICK_FLOAT) |
| 4025 | _bfd_error_handler |
| 4026 | (_("ERROR: %B uses Maverick instructions, whereas %B does not"), |
| 4027 | ibfd, obfd); |
| 4028 | else |
| 4029 | _bfd_error_handler |
| 4030 | (_("ERROR: %B does not use Maverick instructions, whereas %B does"), |
| 4031 | ibfd, obfd); |
| 4032 | |
| 4033 | flags_compatible = FALSE; |
| 4034 | } |
| 4035 | |
| 4036 | #ifdef EF_ARM_SOFT_FLOAT |
| 4037 | if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT)) |
| 4038 | { |
| 4039 | /* We can allow interworking between code that is VFP format |
| 4040 | layout, and uses either soft float or integer regs for |
| 4041 | passing floating point arguments and results. We already |
| 4042 | know that the APCS_FLOAT flags match; similarly for VFP |
| 4043 | flags. */ |
| 4044 | if ((in_flags & EF_ARM_APCS_FLOAT) != 0 |
| 4045 | || (in_flags & EF_ARM_VFP_FLOAT) == 0) |
| 4046 | { |
| 4047 | if (in_flags & EF_ARM_SOFT_FLOAT) |
| 4048 | _bfd_error_handler |
| 4049 | (_("ERROR: %B uses software FP, whereas %B uses hardware FP"), |
| 4050 | ibfd, obfd); |
| 4051 | else |
| 4052 | _bfd_error_handler |
| 4053 | (_("ERROR: %B uses hardware FP, whereas %B uses software FP"), |
| 4054 | ibfd, obfd); |
| 4055 | |
| 4056 | flags_compatible = FALSE; |
| 4057 | } |
| 4058 | } |
| 4059 | #endif |
| 4060 | |
| 4061 | /* Interworking mismatch is only a warning. */ |
| 4062 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
| 4063 | { |
| 4064 | if (in_flags & EF_ARM_INTERWORK) |
| 4065 | { |
| 4066 | _bfd_error_handler |
| 4067 | (_("Warning: %B supports interworking, whereas %B does not"), |
| 4068 | ibfd, obfd); |
| 4069 | } |
| 4070 | else |
| 4071 | { |
| 4072 | _bfd_error_handler |
| 4073 | (_("Warning: %B does not support interworking, whereas %B does"), |
| 4074 | ibfd, obfd); |
| 4075 | } |
| 4076 | } |
| 4077 | } |
| 4078 | |
| 4079 | return flags_compatible; |
| 4080 | } |
| 4081 | |
| 4082 | /* Display the flags field. */ |
| 4083 | |
| 4084 | static bfd_boolean |
| 4085 | elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr) |
| 4086 | { |
| 4087 | FILE * file = (FILE *) ptr; |
| 4088 | unsigned long flags; |
| 4089 | |
| 4090 | BFD_ASSERT (abfd != NULL && ptr != NULL); |
| 4091 | |
| 4092 | /* Print normal ELF private data. */ |
| 4093 | _bfd_elf_print_private_bfd_data (abfd, ptr); |
| 4094 | |
| 4095 | flags = elf_elfheader (abfd)->e_flags; |
| 4096 | /* Ignore init flag - it may not be set, despite the flags field |
| 4097 | containing valid data. */ |
| 4098 | |
| 4099 | /* xgettext:c-format */ |
| 4100 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); |
| 4101 | |
| 4102 | switch (EF_ARM_EABI_VERSION (flags)) |
| 4103 | { |
| 4104 | case EF_ARM_EABI_UNKNOWN: |
| 4105 | /* The following flag bits are GNU extensions and not part of the |
| 4106 | official ARM ELF extended ABI. Hence they are only decoded if |
| 4107 | the EABI version is not set. */ |
| 4108 | if (flags & EF_ARM_INTERWORK) |
| 4109 | fprintf (file, _(" [interworking enabled]")); |
| 4110 | |
| 4111 | if (flags & EF_ARM_APCS_26) |
| 4112 | fprintf (file, " [APCS-26]"); |
| 4113 | else |
| 4114 | fprintf (file, " [APCS-32]"); |
| 4115 | |
| 4116 | if (flags & EF_ARM_VFP_FLOAT) |
| 4117 | fprintf (file, _(" [VFP float format]")); |
| 4118 | else if (flags & EF_ARM_MAVERICK_FLOAT) |
| 4119 | fprintf (file, _(" [Maverick float format]")); |
| 4120 | else |
| 4121 | fprintf (file, _(" [FPA float format]")); |
| 4122 | |
| 4123 | if (flags & EF_ARM_APCS_FLOAT) |
| 4124 | fprintf (file, _(" [floats passed in float registers]")); |
| 4125 | |
| 4126 | if (flags & EF_ARM_PIC) |
| 4127 | fprintf (file, _(" [position independent]")); |
| 4128 | |
| 4129 | if (flags & EF_ARM_NEW_ABI) |
| 4130 | fprintf (file, _(" [new ABI]")); |
| 4131 | |
| 4132 | if (flags & EF_ARM_OLD_ABI) |
| 4133 | fprintf (file, _(" [old ABI]")); |
| 4134 | |
| 4135 | if (flags & EF_ARM_SOFT_FLOAT) |
| 4136 | fprintf (file, _(" [software FP]")); |
| 4137 | |
| 4138 | flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT |
| 4139 | | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI |
| 4140 | | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT |
| 4141 | | EF_ARM_MAVERICK_FLOAT); |
| 4142 | break; |
| 4143 | |
| 4144 | case EF_ARM_EABI_VER1: |
| 4145 | fprintf (file, _(" [Version1 EABI]")); |
| 4146 | |
| 4147 | if (flags & EF_ARM_SYMSARESORTED) |
| 4148 | fprintf (file, _(" [sorted symbol table]")); |
| 4149 | else |
| 4150 | fprintf (file, _(" [unsorted symbol table]")); |
| 4151 | |
| 4152 | flags &= ~ EF_ARM_SYMSARESORTED; |
| 4153 | break; |
| 4154 | |
| 4155 | case EF_ARM_EABI_VER2: |
| 4156 | fprintf (file, _(" [Version2 EABI]")); |
| 4157 | |
| 4158 | if (flags & EF_ARM_SYMSARESORTED) |
| 4159 | fprintf (file, _(" [sorted symbol table]")); |
| 4160 | else |
| 4161 | fprintf (file, _(" [unsorted symbol table]")); |
| 4162 | |
| 4163 | if (flags & EF_ARM_DYNSYMSUSESEGIDX) |
| 4164 | fprintf (file, _(" [dynamic symbols use segment index]")); |
| 4165 | |
| 4166 | if (flags & EF_ARM_MAPSYMSFIRST) |
| 4167 | fprintf (file, _(" [mapping symbols precede others]")); |
| 4168 | |
| 4169 | flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX |
| 4170 | | EF_ARM_MAPSYMSFIRST); |
| 4171 | break; |
| 4172 | |
| 4173 | case EF_ARM_EABI_VER3: |
| 4174 | fprintf (file, _(" [Version3 EABI]")); |
| 4175 | break; |
| 4176 | |
| 4177 | case EF_ARM_EABI_VER4: |
| 4178 | fprintf (file, _(" [Version4 EABI]")); |
| 4179 | |
| 4180 | if (flags & EF_ARM_BE8) |
| 4181 | fprintf (file, _(" [BE8]")); |
| 4182 | |
| 4183 | if (flags & EF_ARM_LE8) |
| 4184 | fprintf (file, _(" [LE8]")); |
| 4185 | |
| 4186 | flags &= ~(EF_ARM_LE8 | EF_ARM_BE8); |
| 4187 | break; |
| 4188 | |
| 4189 | default: |
| 4190 | fprintf (file, _(" <EABI version unrecognised>")); |
| 4191 | break; |
| 4192 | } |
| 4193 | |
| 4194 | flags &= ~ EF_ARM_EABIMASK; |
| 4195 | |
| 4196 | if (flags & EF_ARM_RELEXEC) |
| 4197 | fprintf (file, _(" [relocatable executable]")); |
| 4198 | |
| 4199 | if (flags & EF_ARM_HASENTRY) |
| 4200 | fprintf (file, _(" [has entry point]")); |
| 4201 | |
| 4202 | flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY); |
| 4203 | |
| 4204 | if (flags) |
| 4205 | fprintf (file, _("<Unrecognised flag bits set>")); |
| 4206 | |
| 4207 | fputc ('\n', file); |
| 4208 | |
| 4209 | return TRUE; |
| 4210 | } |
| 4211 | |
| 4212 | static int |
| 4213 | elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type) |
| 4214 | { |
| 4215 | switch (ELF_ST_TYPE (elf_sym->st_info)) |
| 4216 | { |
| 4217 | case STT_ARM_TFUNC: |
| 4218 | return ELF_ST_TYPE (elf_sym->st_info); |
| 4219 | |
| 4220 | case STT_ARM_16BIT: |
| 4221 | /* If the symbol is not an object, return the STT_ARM_16BIT flag. |
| 4222 | This allows us to distinguish between data used by Thumb instructions |
| 4223 | and non-data (which is probably code) inside Thumb regions of an |
| 4224 | executable. */ |
| 4225 | if (type != STT_OBJECT) |
| 4226 | return ELF_ST_TYPE (elf_sym->st_info); |
| 4227 | break; |
| 4228 | |
| 4229 | default: |
| 4230 | break; |
| 4231 | } |
| 4232 | |
| 4233 | return type; |
| 4234 | } |
| 4235 | |
| 4236 | static asection * |
| 4237 | elf32_arm_gc_mark_hook (asection * sec, |
| 4238 | struct bfd_link_info * info ATTRIBUTE_UNUSED, |
| 4239 | Elf_Internal_Rela * rel, |
| 4240 | struct elf_link_hash_entry * h, |
| 4241 | Elf_Internal_Sym * sym) |
| 4242 | { |
| 4243 | if (h != NULL) |
| 4244 | { |
| 4245 | switch (ELF32_R_TYPE (rel->r_info)) |
| 4246 | { |
| 4247 | case R_ARM_GNU_VTINHERIT: |
| 4248 | case R_ARM_GNU_VTENTRY: |
| 4249 | break; |
| 4250 | |
| 4251 | default: |
| 4252 | switch (h->root.type) |
| 4253 | { |
| 4254 | case bfd_link_hash_defined: |
| 4255 | case bfd_link_hash_defweak: |
| 4256 | return h->root.u.def.section; |
| 4257 | |
| 4258 | case bfd_link_hash_common: |
| 4259 | return h->root.u.c.p->section; |
| 4260 | |
| 4261 | default: |
| 4262 | break; |
| 4263 | } |
| 4264 | } |
| 4265 | } |
| 4266 | else |
| 4267 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
| 4268 | |
| 4269 | return NULL; |
| 4270 | } |
| 4271 | |
| 4272 | /* Update the got entry reference counts for the section being removed. */ |
| 4273 | |
| 4274 | static bfd_boolean |
| 4275 | elf32_arm_gc_sweep_hook (bfd * abfd, |
| 4276 | struct bfd_link_info * info, |
| 4277 | asection * sec, |
| 4278 | const Elf_Internal_Rela * relocs) |
| 4279 | { |
| 4280 | Elf_Internal_Shdr *symtab_hdr; |
| 4281 | struct elf_link_hash_entry **sym_hashes; |
| 4282 | bfd_signed_vma *local_got_refcounts; |
| 4283 | const Elf_Internal_Rela *rel, *relend; |
| 4284 | struct elf32_arm_link_hash_table * globals; |
| 4285 | |
| 4286 | globals = elf32_arm_hash_table (info); |
| 4287 | |
| 4288 | elf_section_data (sec)->local_dynrel = NULL; |
| 4289 | |
| 4290 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 4291 | sym_hashes = elf_sym_hashes (abfd); |
| 4292 | local_got_refcounts = elf_local_got_refcounts (abfd); |
| 4293 | |
| 4294 | relend = relocs + sec->reloc_count; |
| 4295 | for (rel = relocs; rel < relend; rel++) |
| 4296 | { |
| 4297 | unsigned long r_symndx; |
| 4298 | struct elf_link_hash_entry *h = NULL; |
| 4299 | int r_type; |
| 4300 | |
| 4301 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 4302 | if (r_symndx >= symtab_hdr->sh_info) |
| 4303 | { |
| 4304 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 4305 | while (h->root.type == bfd_link_hash_indirect |
| 4306 | || h->root.type == bfd_link_hash_warning) |
| 4307 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 4308 | } |
| 4309 | |
| 4310 | r_type = ELF32_R_TYPE (rel->r_info); |
| 4311 | #ifndef OLD_ARM_ABI |
| 4312 | r_type = arm_real_reloc_type (globals, r_type); |
| 4313 | #endif |
| 4314 | switch (r_type) |
| 4315 | { |
| 4316 | case R_ARM_GOT32: |
| 4317 | #ifndef OLD_ARM_ABI |
| 4318 | case R_ARM_GOT_PREL: |
| 4319 | #endif |
| 4320 | case R_ARM_TLS_GD32: |
| 4321 | case R_ARM_TLS_IE32: |
| 4322 | if (h != NULL) |
| 4323 | { |
| 4324 | if (h->got.refcount > 0) |
| 4325 | h->got.refcount -= 1; |
| 4326 | } |
| 4327 | else if (local_got_refcounts != NULL) |
| 4328 | { |
| 4329 | if (local_got_refcounts[r_symndx] > 0) |
| 4330 | local_got_refcounts[r_symndx] -= 1; |
| 4331 | } |
| 4332 | break; |
| 4333 | |
| 4334 | case R_ARM_TLS_LDM32: |
| 4335 | elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1; |
| 4336 | break; |
| 4337 | |
| 4338 | case R_ARM_ABS32: |
| 4339 | case R_ARM_REL32: |
| 4340 | case R_ARM_PC24: |
| 4341 | case R_ARM_PLT32: |
| 4342 | #ifndef OLD_ARM_ABI |
| 4343 | case R_ARM_CALL: |
| 4344 | case R_ARM_JUMP24: |
| 4345 | case R_ARM_PREL31: |
| 4346 | #endif |
| 4347 | case R_ARM_THM_PC22: |
| 4348 | /* Should the interworking branches be here also? */ |
| 4349 | |
| 4350 | if (h != NULL) |
| 4351 | { |
| 4352 | struct elf32_arm_link_hash_entry *eh; |
| 4353 | struct elf32_arm_relocs_copied **pp; |
| 4354 | struct elf32_arm_relocs_copied *p; |
| 4355 | |
| 4356 | eh = (struct elf32_arm_link_hash_entry *) h; |
| 4357 | |
| 4358 | if (h->plt.refcount > 0) |
| 4359 | { |
| 4360 | h->plt.refcount -= 1; |
| 4361 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_PC22) |
| 4362 | eh->plt_thumb_refcount--; |
| 4363 | } |
| 4364 | |
| 4365 | if (r_type == R_ARM_ABS32 |
| 4366 | || r_type == R_ARM_REL32) |
| 4367 | { |
| 4368 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; |
| 4369 | pp = &p->next) |
| 4370 | if (p->section == sec) |
| 4371 | { |
| 4372 | p->count -= 1; |
| 4373 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32) |
| 4374 | p->pc_count -= 1; |
| 4375 | if (p->count == 0) |
| 4376 | *pp = p->next; |
| 4377 | break; |
| 4378 | } |
| 4379 | } |
| 4380 | } |
| 4381 | break; |
| 4382 | |
| 4383 | default: |
| 4384 | break; |
| 4385 | } |
| 4386 | } |
| 4387 | |
| 4388 | return TRUE; |
| 4389 | } |
| 4390 | |
| 4391 | /* Look through the relocs for a section during the first phase. */ |
| 4392 | |
| 4393 | static bfd_boolean |
| 4394 | elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info, |
| 4395 | asection *sec, const Elf_Internal_Rela *relocs) |
| 4396 | { |
| 4397 | Elf_Internal_Shdr *symtab_hdr; |
| 4398 | struct elf_link_hash_entry **sym_hashes; |
| 4399 | struct elf_link_hash_entry **sym_hashes_end; |
| 4400 | const Elf_Internal_Rela *rel; |
| 4401 | const Elf_Internal_Rela *rel_end; |
| 4402 | bfd *dynobj; |
| 4403 | asection *sreloc; |
| 4404 | bfd_vma *local_got_offsets; |
| 4405 | struct elf32_arm_link_hash_table *htab; |
| 4406 | |
| 4407 | if (info->relocatable) |
| 4408 | return TRUE; |
| 4409 | |
| 4410 | htab = elf32_arm_hash_table (info); |
| 4411 | sreloc = NULL; |
| 4412 | |
| 4413 | /* Create dynamic sections for relocatable executables so that we can |
| 4414 | copy relocations. */ |
| 4415 | if (htab->root.is_relocatable_executable |
| 4416 | && ! htab->root.dynamic_sections_created) |
| 4417 | { |
| 4418 | if (! _bfd_elf_link_create_dynamic_sections (abfd, info)) |
| 4419 | return FALSE; |
| 4420 | } |
| 4421 | |
| 4422 | dynobj = elf_hash_table (info)->dynobj; |
| 4423 | local_got_offsets = elf_local_got_offsets (abfd); |
| 4424 | |
| 4425 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 4426 | sym_hashes = elf_sym_hashes (abfd); |
| 4427 | sym_hashes_end = sym_hashes |
| 4428 | + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); |
| 4429 | |
| 4430 | if (!elf_bad_symtab (abfd)) |
| 4431 | sym_hashes_end -= symtab_hdr->sh_info; |
| 4432 | |
| 4433 | rel_end = relocs + sec->reloc_count; |
| 4434 | for (rel = relocs; rel < rel_end; rel++) |
| 4435 | { |
| 4436 | struct elf_link_hash_entry *h; |
| 4437 | struct elf32_arm_link_hash_entry *eh; |
| 4438 | unsigned long r_symndx; |
| 4439 | int r_type; |
| 4440 | |
| 4441 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 4442 | r_type = ELF32_R_TYPE (rel->r_info); |
| 4443 | #ifndef OLD_ARM_ABI |
| 4444 | r_type = arm_real_reloc_type (htab, r_type); |
| 4445 | #endif |
| 4446 | |
| 4447 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) |
| 4448 | { |
| 4449 | (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd, |
| 4450 | r_symndx); |
| 4451 | return FALSE; |
| 4452 | } |
| 4453 | |
| 4454 | if (r_symndx < symtab_hdr->sh_info) |
| 4455 | h = NULL; |
| 4456 | else |
| 4457 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 4458 | |
| 4459 | eh = (struct elf32_arm_link_hash_entry *) h; |
| 4460 | |
| 4461 | switch (r_type) |
| 4462 | { |
| 4463 | case R_ARM_GOT32: |
| 4464 | #ifndef OLD_ARM_ABI |
| 4465 | case R_ARM_GOT_PREL: |
| 4466 | #endif |
| 4467 | case R_ARM_TLS_GD32: |
| 4468 | case R_ARM_TLS_IE32: |
| 4469 | /* This symbol requires a global offset table entry. */ |
| 4470 | { |
| 4471 | int tls_type, old_tls_type; |
| 4472 | |
| 4473 | switch (r_type) |
| 4474 | { |
| 4475 | case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break; |
| 4476 | case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break; |
| 4477 | default: tls_type = GOT_NORMAL; break; |
| 4478 | } |
| 4479 | |
| 4480 | if (h != NULL) |
| 4481 | { |
| 4482 | h->got.refcount++; |
| 4483 | old_tls_type = elf32_arm_hash_entry (h)->tls_type; |
| 4484 | } |
| 4485 | else |
| 4486 | { |
| 4487 | bfd_signed_vma *local_got_refcounts; |
| 4488 | |
| 4489 | /* This is a global offset table entry for a local symbol. */ |
| 4490 | local_got_refcounts = elf_local_got_refcounts (abfd); |
| 4491 | if (local_got_refcounts == NULL) |
| 4492 | { |
| 4493 | bfd_size_type size; |
| 4494 | |
| 4495 | size = symtab_hdr->sh_info; |
| 4496 | size *= (sizeof (bfd_signed_vma) + sizeof(char)); |
| 4497 | local_got_refcounts = bfd_zalloc (abfd, size); |
| 4498 | if (local_got_refcounts == NULL) |
| 4499 | return FALSE; |
| 4500 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
| 4501 | elf32_arm_local_got_tls_type (abfd) |
| 4502 | = (char *) (local_got_refcounts + symtab_hdr->sh_info); |
| 4503 | } |
| 4504 | local_got_refcounts[r_symndx] += 1; |
| 4505 | old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx]; |
| 4506 | } |
| 4507 | |
| 4508 | /* We will already have issued an error message if there is a |
| 4509 | TLS / non-TLS mismatch, based on the symbol type. We don't |
| 4510 | support any linker relaxations. So just combine any TLS |
| 4511 | types needed. */ |
| 4512 | if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL |
| 4513 | && tls_type != GOT_NORMAL) |
| 4514 | tls_type |= old_tls_type; |
| 4515 | |
| 4516 | if (old_tls_type != tls_type) |
| 4517 | { |
| 4518 | if (h != NULL) |
| 4519 | elf32_arm_hash_entry (h)->tls_type = tls_type; |
| 4520 | else |
| 4521 | elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type; |
| 4522 | } |
| 4523 | } |
| 4524 | /* Fall through */ |
| 4525 | |
| 4526 | case R_ARM_TLS_LDM32: |
| 4527 | if (r_type == R_ARM_TLS_LDM32) |
| 4528 | htab->tls_ldm_got.refcount++; |
| 4529 | /* Fall through */ |
| 4530 | |
| 4531 | case R_ARM_GOTOFF: |
| 4532 | case R_ARM_GOTPC: |
| 4533 | if (htab->sgot == NULL) |
| 4534 | { |
| 4535 | if (htab->root.dynobj == NULL) |
| 4536 | htab->root.dynobj = abfd; |
| 4537 | if (!create_got_section (htab->root.dynobj, info)) |
| 4538 | return FALSE; |
| 4539 | } |
| 4540 | break; |
| 4541 | |
| 4542 | case R_ARM_ABS32: |
| 4543 | case R_ARM_REL32: |
| 4544 | case R_ARM_PC24: |
| 4545 | case R_ARM_PLT32: |
| 4546 | #ifndef OLD_ARM_ABI |
| 4547 | case R_ARM_CALL: |
| 4548 | case R_ARM_JUMP24: |
| 4549 | case R_ARM_PREL31: |
| 4550 | #endif |
| 4551 | case R_ARM_THM_PC22: |
| 4552 | /* Should the interworking branches be listed here? */ |
| 4553 | if (h != NULL) |
| 4554 | { |
| 4555 | /* If this reloc is in a read-only section, we might |
| 4556 | need a copy reloc. We can't check reliably at this |
| 4557 | stage whether the section is read-only, as input |
| 4558 | sections have not yet been mapped to output sections. |
| 4559 | Tentatively set the flag for now, and correct in |
| 4560 | adjust_dynamic_symbol. */ |
| 4561 | if (!info->shared) |
| 4562 | h->non_got_ref = 1; |
| 4563 | |
| 4564 | /* We may need a .plt entry if the function this reloc |
| 4565 | refers to is in a different object. We can't tell for |
| 4566 | sure yet, because something later might force the |
| 4567 | symbol local. */ |
| 4568 | if (r_type == R_ARM_PC24 |
| 4569 | #ifndef OLD_ARM_ABI |
| 4570 | || r_type == R_ARM_CALL |
| 4571 | || r_type == R_ARM_JUMP24 |
| 4572 | || r_type == R_ARM_PREL31 |
| 4573 | #endif |
| 4574 | || r_type == R_ARM_PLT32 |
| 4575 | || r_type == R_ARM_THM_PC22) |
| 4576 | h->needs_plt = 1; |
| 4577 | |
| 4578 | /* If we create a PLT entry, this relocation will reference |
| 4579 | it, even if it's an ABS32 relocation. */ |
| 4580 | h->plt.refcount += 1; |
| 4581 | |
| 4582 | if (r_type == R_ARM_THM_PC22) |
| 4583 | eh->plt_thumb_refcount += 1; |
| 4584 | } |
| 4585 | |
| 4586 | /* If we are creating a shared library or relocatable executable, |
| 4587 | and this is a reloc against a global symbol, or a non PC |
| 4588 | relative reloc against a local symbol, then we need to copy |
| 4589 | the reloc into the shared library. However, if we are linking |
| 4590 | with -Bsymbolic, we do not need to copy a reloc against a |
| 4591 | global symbol which is defined in an object we are |
| 4592 | including in the link (i.e., DEF_REGULAR is set). At |
| 4593 | this point we have not seen all the input files, so it is |
| 4594 | possible that DEF_REGULAR is not set now but will be set |
| 4595 | later (it is never cleared). We account for that |
| 4596 | possibility below by storing information in the |
| 4597 | relocs_copied field of the hash table entry. */ |
| 4598 | if ((info->shared || htab->root.is_relocatable_executable) |
| 4599 | && (sec->flags & SEC_ALLOC) != 0 |
| 4600 | && (r_type == R_ARM_ABS32 |
| 4601 | || (h != NULL && ! h->needs_plt |
| 4602 | && (! info->symbolic || ! h->def_regular)))) |
| 4603 | { |
| 4604 | struct elf32_arm_relocs_copied *p, **head; |
| 4605 | |
| 4606 | /* When creating a shared object, we must copy these |
| 4607 | reloc types into the output file. We create a reloc |
| 4608 | section in dynobj and make room for this reloc. */ |
| 4609 | if (sreloc == NULL) |
| 4610 | { |
| 4611 | const char * name; |
| 4612 | |
| 4613 | name = (bfd_elf_string_from_elf_section |
| 4614 | (abfd, |
| 4615 | elf_elfheader (abfd)->e_shstrndx, |
| 4616 | elf_section_data (sec)->rel_hdr.sh_name)); |
| 4617 | if (name == NULL) |
| 4618 | return FALSE; |
| 4619 | |
| 4620 | BFD_ASSERT (strncmp (name, ".rel", 4) == 0 |
| 4621 | && strcmp (bfd_get_section_name (abfd, sec), |
| 4622 | name + 4) == 0); |
| 4623 | |
| 4624 | sreloc = bfd_get_section_by_name (dynobj, name); |
| 4625 | if (sreloc == NULL) |
| 4626 | { |
| 4627 | flagword flags; |
| 4628 | |
| 4629 | sreloc = bfd_make_section (dynobj, name); |
| 4630 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
| 4631 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); |
| 4632 | if ((sec->flags & SEC_ALLOC) != 0 |
| 4633 | /* BPABI objects never have dynamic |
| 4634 | relocations mapped. */ |
| 4635 | && !htab->symbian_p) |
| 4636 | flags |= SEC_ALLOC | SEC_LOAD; |
| 4637 | if (sreloc == NULL |
| 4638 | || ! bfd_set_section_flags (dynobj, sreloc, flags) |
| 4639 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) |
| 4640 | return FALSE; |
| 4641 | } |
| 4642 | |
| 4643 | elf_section_data (sec)->sreloc = sreloc; |
| 4644 | } |
| 4645 | |
| 4646 | /* If this is a global symbol, we count the number of |
| 4647 | relocations we need for this symbol. */ |
| 4648 | if (h != NULL) |
| 4649 | { |
| 4650 | head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied; |
| 4651 | } |
| 4652 | else |
| 4653 | { |
| 4654 | /* Track dynamic relocs needed for local syms too. |
| 4655 | We really need local syms available to do this |
| 4656 | easily. Oh well. */ |
| 4657 | |
| 4658 | asection *s; |
| 4659 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, |
| 4660 | sec, r_symndx); |
| 4661 | if (s == NULL) |
| 4662 | return FALSE; |
| 4663 | |
| 4664 | head = ((struct elf32_arm_relocs_copied **) |
| 4665 | &elf_section_data (s)->local_dynrel); |
| 4666 | } |
| 4667 | |
| 4668 | p = *head; |
| 4669 | if (p == NULL || p->section != sec) |
| 4670 | { |
| 4671 | bfd_size_type amt = sizeof *p; |
| 4672 | |
| 4673 | p = bfd_alloc (htab->root.dynobj, amt); |
| 4674 | if (p == NULL) |
| 4675 | return FALSE; |
| 4676 | p->next = *head; |
| 4677 | *head = p; |
| 4678 | p->section = sec; |
| 4679 | p->count = 0; |
| 4680 | p->pc_count = 0; |
| 4681 | } |
| 4682 | |
| 4683 | if (r_type == R_ARM_REL32) |
| 4684 | p->pc_count += 1; |
| 4685 | p->count += 1; |
| 4686 | } |
| 4687 | break; |
| 4688 | |
| 4689 | /* This relocation describes the C++ object vtable hierarchy. |
| 4690 | Reconstruct it for later use during GC. */ |
| 4691 | case R_ARM_GNU_VTINHERIT: |
| 4692 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
| 4693 | return FALSE; |
| 4694 | break; |
| 4695 | |
| 4696 | /* This relocation describes which C++ vtable entries are actually |
| 4697 | used. Record for later use during GC. */ |
| 4698 | case R_ARM_GNU_VTENTRY: |
| 4699 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) |
| 4700 | return FALSE; |
| 4701 | break; |
| 4702 | } |
| 4703 | } |
| 4704 | |
| 4705 | return TRUE; |
| 4706 | } |
| 4707 | |
| 4708 | static bfd_boolean |
| 4709 | is_arm_mapping_symbol_name (const char * name) |
| 4710 | { |
| 4711 | return (name != NULL) |
| 4712 | && (name[0] == '$') |
| 4713 | && ((name[1] == 'a') || (name[1] == 't') || (name[1] == 'd')) |
| 4714 | && (name[2] == 0); |
| 4715 | } |
| 4716 | |
| 4717 | /* Treat mapping symbols as special target symbols. */ |
| 4718 | |
| 4719 | static bfd_boolean |
| 4720 | elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym) |
| 4721 | { |
| 4722 | return is_arm_mapping_symbol_name (sym->name); |
| 4723 | } |
| 4724 | |
| 4725 | /* This is a copy of elf_find_function() from elf.c except that |
| 4726 | ARM mapping symbols are ignored when looking for function names |
| 4727 | and STT_ARM_TFUNC is considered to a function type. */ |
| 4728 | |
| 4729 | static bfd_boolean |
| 4730 | arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED, |
| 4731 | asection * section, |
| 4732 | asymbol ** symbols, |
| 4733 | bfd_vma offset, |
| 4734 | const char ** filename_ptr, |
| 4735 | const char ** functionname_ptr) |
| 4736 | { |
| 4737 | const char * filename = NULL; |
| 4738 | asymbol * func = NULL; |
| 4739 | bfd_vma low_func = 0; |
| 4740 | asymbol ** p; |
| 4741 | |
| 4742 | for (p = symbols; *p != NULL; p++) |
| 4743 | { |
| 4744 | elf_symbol_type *q; |
| 4745 | |
| 4746 | q = (elf_symbol_type *) *p; |
| 4747 | |
| 4748 | switch (ELF_ST_TYPE (q->internal_elf_sym.st_info)) |
| 4749 | { |
| 4750 | default: |
| 4751 | break; |
| 4752 | case STT_FILE: |
| 4753 | filename = bfd_asymbol_name (&q->symbol); |
| 4754 | break; |
| 4755 | case STT_FUNC: |
| 4756 | case STT_ARM_TFUNC: |
| 4757 | /* Skip $a and $t symbols. */ |
| 4758 | if ((q->symbol.flags & BSF_LOCAL) |
| 4759 | && is_arm_mapping_symbol_name (q->symbol.name)) |
| 4760 | continue; |
| 4761 | /* Fall through. */ |
| 4762 | case STT_NOTYPE: |
| 4763 | if (bfd_get_section (&q->symbol) == section |
| 4764 | && q->symbol.value >= low_func |
| 4765 | && q->symbol.value <= offset) |
| 4766 | { |
| 4767 | func = (asymbol *) q; |
| 4768 | low_func = q->symbol.value; |
| 4769 | } |
| 4770 | break; |
| 4771 | } |
| 4772 | } |
| 4773 | |
| 4774 | if (func == NULL) |
| 4775 | return FALSE; |
| 4776 | |
| 4777 | if (filename_ptr) |
| 4778 | *filename_ptr = filename; |
| 4779 | if (functionname_ptr) |
| 4780 | *functionname_ptr = bfd_asymbol_name (func); |
| 4781 | |
| 4782 | return TRUE; |
| 4783 | } |
| 4784 | |
| 4785 | |
| 4786 | /* Find the nearest line to a particular section and offset, for error |
| 4787 | reporting. This code is a duplicate of the code in elf.c, except |
| 4788 | that it uses arm_elf_find_function. */ |
| 4789 | |
| 4790 | static bfd_boolean |
| 4791 | elf32_arm_find_nearest_line (bfd * abfd, |
| 4792 | asection * section, |
| 4793 | asymbol ** symbols, |
| 4794 | bfd_vma offset, |
| 4795 | const char ** filename_ptr, |
| 4796 | const char ** functionname_ptr, |
| 4797 | unsigned int * line_ptr) |
| 4798 | { |
| 4799 | bfd_boolean found = FALSE; |
| 4800 | |
| 4801 | /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */ |
| 4802 | |
| 4803 | if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, |
| 4804 | filename_ptr, functionname_ptr, |
| 4805 | line_ptr, 0, |
| 4806 | & elf_tdata (abfd)->dwarf2_find_line_info)) |
| 4807 | { |
| 4808 | if (!*functionname_ptr) |
| 4809 | arm_elf_find_function (abfd, section, symbols, offset, |
| 4810 | *filename_ptr ? NULL : filename_ptr, |
| 4811 | functionname_ptr); |
| 4812 | |
| 4813 | return TRUE; |
| 4814 | } |
| 4815 | |
| 4816 | if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, |
| 4817 | & found, filename_ptr, |
| 4818 | functionname_ptr, line_ptr, |
| 4819 | & elf_tdata (abfd)->line_info)) |
| 4820 | return FALSE; |
| 4821 | |
| 4822 | if (found && (*functionname_ptr || *line_ptr)) |
| 4823 | return TRUE; |
| 4824 | |
| 4825 | if (symbols == NULL) |
| 4826 | return FALSE; |
| 4827 | |
| 4828 | if (! arm_elf_find_function (abfd, section, symbols, offset, |
| 4829 | filename_ptr, functionname_ptr)) |
| 4830 | return FALSE; |
| 4831 | |
| 4832 | *line_ptr = 0; |
| 4833 | return TRUE; |
| 4834 | } |
| 4835 | |
| 4836 | /* Adjust a symbol defined by a dynamic object and referenced by a |
| 4837 | regular object. The current definition is in some section of the |
| 4838 | dynamic object, but we're not including those sections. We have to |
| 4839 | change the definition to something the rest of the link can |
| 4840 | understand. */ |
| 4841 | |
| 4842 | static bfd_boolean |
| 4843 | elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, |
| 4844 | struct elf_link_hash_entry * h) |
| 4845 | { |
| 4846 | bfd * dynobj; |
| 4847 | asection * s; |
| 4848 | unsigned int power_of_two; |
| 4849 | struct elf32_arm_link_hash_entry * eh; |
| 4850 | struct elf32_arm_link_hash_table *globals; |
| 4851 | |
| 4852 | globals = elf32_arm_hash_table (info); |
| 4853 | dynobj = elf_hash_table (info)->dynobj; |
| 4854 | |
| 4855 | /* Make sure we know what is going on here. */ |
| 4856 | BFD_ASSERT (dynobj != NULL |
| 4857 | && (h->needs_plt |
| 4858 | || h->u.weakdef != NULL |
| 4859 | || (h->def_dynamic |
| 4860 | && h->ref_regular |
| 4861 | && !h->def_regular))); |
| 4862 | |
| 4863 | eh = (struct elf32_arm_link_hash_entry *) h; |
| 4864 | |
| 4865 | /* If this is a function, put it in the procedure linkage table. We |
| 4866 | will fill in the contents of the procedure linkage table later, |
| 4867 | when we know the address of the .got section. */ |
| 4868 | if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC |
| 4869 | || h->needs_plt) |
| 4870 | { |
| 4871 | if (h->plt.refcount <= 0 |
| 4872 | || SYMBOL_CALLS_LOCAL (info, h) |
| 4873 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
| 4874 | && h->root.type == bfd_link_hash_undefweak)) |
| 4875 | { |
| 4876 | /* This case can occur if we saw a PLT32 reloc in an input |
| 4877 | file, but the symbol was never referred to by a dynamic |
| 4878 | object, or if all references were garbage collected. In |
| 4879 | such a case, we don't actually need to build a procedure |
| 4880 | linkage table, and we can just do a PC24 reloc instead. */ |
| 4881 | h->plt.offset = (bfd_vma) -1; |
| 4882 | eh->plt_thumb_refcount = 0; |
| 4883 | h->needs_plt = 0; |
| 4884 | } |
| 4885 | |
| 4886 | return TRUE; |
| 4887 | } |
| 4888 | else |
| 4889 | { |
| 4890 | /* It's possible that we incorrectly decided a .plt reloc was |
| 4891 | needed for an R_ARM_PC24 or similar reloc to a non-function sym |
| 4892 | in check_relocs. We can't decide accurately between function |
| 4893 | and non-function syms in check-relocs; Objects loaded later in |
| 4894 | the link may change h->type. So fix it now. */ |
| 4895 | h->plt.offset = (bfd_vma) -1; |
| 4896 | eh->plt_thumb_refcount = 0; |
| 4897 | } |
| 4898 | |
| 4899 | /* If this is a weak symbol, and there is a real definition, the |
| 4900 | processor independent code will have arranged for us to see the |
| 4901 | real definition first, and we can just use the same value. */ |
| 4902 | if (h->u.weakdef != NULL) |
| 4903 | { |
| 4904 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
| 4905 | || h->u.weakdef->root.type == bfd_link_hash_defweak); |
| 4906 | h->root.u.def.section = h->u.weakdef->root.u.def.section; |
| 4907 | h->root.u.def.value = h->u.weakdef->root.u.def.value; |
| 4908 | return TRUE; |
| 4909 | } |
| 4910 | |
| 4911 | /* If there are no non-GOT references, we do not need a copy |
| 4912 | relocation. */ |
| 4913 | if (!h->non_got_ref) |
| 4914 | return TRUE; |
| 4915 | |
| 4916 | /* This is a reference to a symbol defined by a dynamic object which |
| 4917 | is not a function. */ |
| 4918 | |
| 4919 | /* If we are creating a shared library, we must presume that the |
| 4920 | only references to the symbol are via the global offset table. |
| 4921 | For such cases we need not do anything here; the relocations will |
| 4922 | be handled correctly by relocate_section. Relocatable executables |
| 4923 | can reference data in shared objects directly, so we don't need to |
| 4924 | do anything here. */ |
| 4925 | if (info->shared || globals->root.is_relocatable_executable) |
| 4926 | return TRUE; |
| 4927 | |
| 4928 | /* We must allocate the symbol in our .dynbss section, which will |
| 4929 | become part of the .bss section of the executable. There will be |
| 4930 | an entry for this symbol in the .dynsym section. The dynamic |
| 4931 | object will contain position independent code, so all references |
| 4932 | from the dynamic object to this symbol will go through the global |
| 4933 | offset table. The dynamic linker will use the .dynsym entry to |
| 4934 | determine the address it must put in the global offset table, so |
| 4935 | both the dynamic object and the regular object will refer to the |
| 4936 | same memory location for the variable. */ |
| 4937 | s = bfd_get_section_by_name (dynobj, ".dynbss"); |
| 4938 | BFD_ASSERT (s != NULL); |
| 4939 | |
| 4940 | /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to |
| 4941 | copy the initial value out of the dynamic object and into the |
| 4942 | runtime process image. We need to remember the offset into the |
| 4943 | .rel.bss section we are going to use. */ |
| 4944 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
| 4945 | { |
| 4946 | asection *srel; |
| 4947 | |
| 4948 | srel = bfd_get_section_by_name (dynobj, ".rel.bss"); |
| 4949 | BFD_ASSERT (srel != NULL); |
| 4950 | srel->size += sizeof (Elf32_External_Rel); |
| 4951 | h->needs_copy = 1; |
| 4952 | } |
| 4953 | |
| 4954 | /* We need to figure out the alignment required for this symbol. I |
| 4955 | have no idea how ELF linkers handle this. */ |
| 4956 | power_of_two = bfd_log2 (h->size); |
| 4957 | if (power_of_two > 3) |
| 4958 | power_of_two = 3; |
| 4959 | |
| 4960 | /* Apply the required alignment. */ |
| 4961 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
| 4962 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) |
| 4963 | { |
| 4964 | if (! bfd_set_section_alignment (dynobj, s, power_of_two)) |
| 4965 | return FALSE; |
| 4966 | } |
| 4967 | |
| 4968 | /* Define the symbol as being at this point in the section. */ |
| 4969 | h->root.u.def.section = s; |
| 4970 | h->root.u.def.value = s->size; |
| 4971 | |
| 4972 | /* Increment the section size to make room for the symbol. */ |
| 4973 | s->size += h->size; |
| 4974 | |
| 4975 | return TRUE; |
| 4976 | } |
| 4977 | |
| 4978 | /* Allocate space in .plt, .got and associated reloc sections for |
| 4979 | dynamic relocs. */ |
| 4980 | |
| 4981 | static bfd_boolean |
| 4982 | allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) |
| 4983 | { |
| 4984 | struct bfd_link_info *info; |
| 4985 | struct elf32_arm_link_hash_table *htab; |
| 4986 | struct elf32_arm_link_hash_entry *eh; |
| 4987 | struct elf32_arm_relocs_copied *p; |
| 4988 | |
| 4989 | eh = (struct elf32_arm_link_hash_entry *) h; |
| 4990 | |
| 4991 | if (h->root.type == bfd_link_hash_indirect) |
| 4992 | return TRUE; |
| 4993 | |
| 4994 | if (h->root.type == bfd_link_hash_warning) |
| 4995 | /* When warning symbols are created, they **replace** the "real" |
| 4996 | entry in the hash table, thus we never get to see the real |
| 4997 | symbol in a hash traversal. So look at it now. */ |
| 4998 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 4999 | |
| 5000 | info = (struct bfd_link_info *) inf; |
| 5001 | htab = elf32_arm_hash_table (info); |
| 5002 | |
| 5003 | if (htab->root.dynamic_sections_created |
| 5004 | && h->plt.refcount > 0) |
| 5005 | { |
| 5006 | /* Make sure this symbol is output as a dynamic symbol. |
| 5007 | Undefined weak syms won't yet be marked as dynamic. */ |
| 5008 | if (h->dynindx == -1 |
| 5009 | && !h->forced_local) |
| 5010 | { |
| 5011 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 5012 | return FALSE; |
| 5013 | } |
| 5014 | |
| 5015 | if (info->shared |
| 5016 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
| 5017 | { |
| 5018 | asection *s = htab->splt; |
| 5019 | |
| 5020 | /* If this is the first .plt entry, make room for the special |
| 5021 | first entry. */ |
| 5022 | if (s->size == 0) |
| 5023 | s->size += htab->plt_header_size; |
| 5024 | |
| 5025 | h->plt.offset = s->size; |
| 5026 | |
| 5027 | /* If we will insert a Thumb trampoline before this PLT, leave room |
| 5028 | for it. */ |
| 5029 | if (!htab->symbian_p && eh->plt_thumb_refcount > 0) |
| 5030 | { |
| 5031 | h->plt.offset += PLT_THUMB_STUB_SIZE; |
| 5032 | s->size += PLT_THUMB_STUB_SIZE; |
| 5033 | } |
| 5034 | |
| 5035 | /* If this symbol is not defined in a regular file, and we are |
| 5036 | not generating a shared library, then set the symbol to this |
| 5037 | location in the .plt. This is required to make function |
| 5038 | pointers compare as equal between the normal executable and |
| 5039 | the shared library. */ |
| 5040 | if (! info->shared |
| 5041 | && !h->def_regular) |
| 5042 | { |
| 5043 | h->root.u.def.section = s; |
| 5044 | h->root.u.def.value = h->plt.offset; |
| 5045 | |
| 5046 | /* Make sure the function is not marked as Thumb, in case |
| 5047 | it is the target of an ABS32 relocation, which will |
| 5048 | point to the PLT entry. */ |
| 5049 | if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC) |
| 5050 | h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); |
| 5051 | } |
| 5052 | |
| 5053 | /* Make room for this entry. */ |
| 5054 | s->size += htab->plt_entry_size; |
| 5055 | |
| 5056 | if (!htab->symbian_p) |
| 5057 | { |
| 5058 | /* We also need to make an entry in the .got.plt section, which |
| 5059 | will be placed in the .got section by the linker script. */ |
| 5060 | eh->plt_got_offset = htab->sgotplt->size; |
| 5061 | htab->sgotplt->size += 4; |
| 5062 | } |
| 5063 | |
| 5064 | /* We also need to make an entry in the .rel.plt section. */ |
| 5065 | htab->srelplt->size += sizeof (Elf32_External_Rel); |
| 5066 | } |
| 5067 | else |
| 5068 | { |
| 5069 | h->plt.offset = (bfd_vma) -1; |
| 5070 | h->needs_plt = 0; |
| 5071 | } |
| 5072 | } |
| 5073 | else |
| 5074 | { |
| 5075 | h->plt.offset = (bfd_vma) -1; |
| 5076 | h->needs_plt = 0; |
| 5077 | } |
| 5078 | |
| 5079 | if (h->got.refcount > 0) |
| 5080 | { |
| 5081 | asection *s; |
| 5082 | bfd_boolean dyn; |
| 5083 | int tls_type = elf32_arm_hash_entry (h)->tls_type; |
| 5084 | int indx; |
| 5085 | |
| 5086 | /* Make sure this symbol is output as a dynamic symbol. |
| 5087 | Undefined weak syms won't yet be marked as dynamic. */ |
| 5088 | if (h->dynindx == -1 |
| 5089 | && !h->forced_local) |
| 5090 | { |
| 5091 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 5092 | return FALSE; |
| 5093 | } |
| 5094 | |
| 5095 | if (!htab->symbian_p) |
| 5096 | { |
| 5097 | s = htab->sgot; |
| 5098 | h->got.offset = s->size; |
| 5099 | |
| 5100 | if (tls_type == GOT_UNKNOWN) |
| 5101 | abort (); |
| 5102 | |
| 5103 | if (tls_type == GOT_NORMAL) |
| 5104 | /* Non-TLS symbols need one GOT slot. */ |
| 5105 | s->size += 4; |
| 5106 | else |
| 5107 | { |
| 5108 | if (tls_type & GOT_TLS_GD) |
| 5109 | /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */ |
| 5110 | s->size += 8; |
| 5111 | if (tls_type & GOT_TLS_IE) |
| 5112 | /* R_ARM_TLS_IE32 needs one GOT slot. */ |
| 5113 | s->size += 4; |
| 5114 | } |
| 5115 | |
| 5116 | dyn = htab->root.dynamic_sections_created; |
| 5117 | |
| 5118 | indx = 0; |
| 5119 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
| 5120 | && (!info->shared |
| 5121 | || !SYMBOL_REFERENCES_LOCAL (info, h))) |
| 5122 | indx = h->dynindx; |
| 5123 | |
| 5124 | if (tls_type != GOT_NORMAL |
| 5125 | && (info->shared || indx != 0) |
| 5126 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
| 5127 | || h->root.type != bfd_link_hash_undefweak)) |
| 5128 | { |
| 5129 | if (tls_type & GOT_TLS_IE) |
| 5130 | htab->srelgot->size += sizeof (Elf32_External_Rel); |
| 5131 | |
| 5132 | if (tls_type & GOT_TLS_GD) |
| 5133 | htab->srelgot->size += sizeof (Elf32_External_Rel); |
| 5134 | |
| 5135 | if ((tls_type & GOT_TLS_GD) && indx != 0) |
| 5136 | htab->srelgot->size += sizeof (Elf32_External_Rel); |
| 5137 | } |
| 5138 | else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
| 5139 | || h->root.type != bfd_link_hash_undefweak) |
| 5140 | && (info->shared |
| 5141 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) |
| 5142 | htab->srelgot->size += sizeof (Elf32_External_Rel); |
| 5143 | } |
| 5144 | } |
| 5145 | else |
| 5146 | h->got.offset = (bfd_vma) -1; |
| 5147 | |
| 5148 | if (eh->relocs_copied == NULL) |
| 5149 | return TRUE; |
| 5150 | |
| 5151 | /* In the shared -Bsymbolic case, discard space allocated for |
| 5152 | dynamic pc-relative relocs against symbols which turn out to be |
| 5153 | defined in regular objects. For the normal shared case, discard |
| 5154 | space for pc-relative relocs that have become local due to symbol |
| 5155 | visibility changes. */ |
| 5156 | |
| 5157 | if (info->shared || htab->root.is_relocatable_executable) |
| 5158 | { |
| 5159 | /* The only reloc that uses pc_count is R_ARM_REL32, which will |
| 5160 | appear on something like ".long foo - .". We want calls to |
| 5161 | protected symbols to resolve directly to the function rather |
| 5162 | than going via the plt. If people want function pointer |
| 5163 | comparisons to work as expected then they should avoid |
| 5164 | writing assembly like ".long foo - .". */ |
| 5165 | if (SYMBOL_CALLS_LOCAL (info, h)) |
| 5166 | { |
| 5167 | struct elf32_arm_relocs_copied **pp; |
| 5168 | |
| 5169 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; ) |
| 5170 | { |
| 5171 | p->count -= p->pc_count; |
| 5172 | p->pc_count = 0; |
| 5173 | if (p->count == 0) |
| 5174 | *pp = p->next; |
| 5175 | else |
| 5176 | pp = &p->next; |
| 5177 | } |
| 5178 | } |
| 5179 | |
| 5180 | /* Also discard relocs on undefined weak syms with non-default |
| 5181 | visibility. */ |
| 5182 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
| 5183 | && h->root.type == bfd_link_hash_undefweak) |
| 5184 | eh->relocs_copied = NULL; |
| 5185 | else if (htab->root.is_relocatable_executable && h->dynindx == -1 |
| 5186 | && h->root.type == bfd_link_hash_new) |
| 5187 | { |
| 5188 | /* Output absolute symbols so that we can create relocations |
| 5189 | against them. For normal symbols we output a relocation |
| 5190 | against the section that contains them. */ |
| 5191 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 5192 | return FALSE; |
| 5193 | } |
| 5194 | |
| 5195 | } |
| 5196 | else |
| 5197 | { |
| 5198 | /* For the non-shared case, discard space for relocs against |
| 5199 | symbols which turn out to need copy relocs or are not |
| 5200 | dynamic. */ |
| 5201 | |
| 5202 | if (!h->non_got_ref |
| 5203 | && ((h->def_dynamic |
| 5204 | && !h->def_regular) |
| 5205 | || (htab->root.dynamic_sections_created |
| 5206 | && (h->root.type == bfd_link_hash_undefweak |
| 5207 | || h->root.type == bfd_link_hash_undefined)))) |
| 5208 | { |
| 5209 | /* Make sure this symbol is output as a dynamic symbol. |
| 5210 | Undefined weak syms won't yet be marked as dynamic. */ |
| 5211 | if (h->dynindx == -1 |
| 5212 | && !h->forced_local) |
| 5213 | { |
| 5214 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 5215 | return FALSE; |
| 5216 | } |
| 5217 | |
| 5218 | /* If that succeeded, we know we'll be keeping all the |
| 5219 | relocs. */ |
| 5220 | if (h->dynindx != -1) |
| 5221 | goto keep; |
| 5222 | } |
| 5223 | |
| 5224 | eh->relocs_copied = NULL; |
| 5225 | |
| 5226 | keep: ; |
| 5227 | } |
| 5228 | |
| 5229 | /* Finally, allocate space. */ |
| 5230 | for (p = eh->relocs_copied; p != NULL; p = p->next) |
| 5231 | { |
| 5232 | asection *sreloc = elf_section_data (p->section)->sreloc; |
| 5233 | sreloc->size += p->count * sizeof (Elf32_External_Rel); |
| 5234 | } |
| 5235 | |
| 5236 | return TRUE; |
| 5237 | } |
| 5238 | |
| 5239 | /* Find any dynamic relocs that apply to read-only sections. */ |
| 5240 | |
| 5241 | static bfd_boolean |
| 5242 | elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf) |
| 5243 | { |
| 5244 | struct elf32_arm_link_hash_entry *eh; |
| 5245 | struct elf32_arm_relocs_copied *p; |
| 5246 | |
| 5247 | if (h->root.type == bfd_link_hash_warning) |
| 5248 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 5249 | |
| 5250 | eh = (struct elf32_arm_link_hash_entry *) h; |
| 5251 | for (p = eh->relocs_copied; p != NULL; p = p->next) |
| 5252 | { |
| 5253 | asection *s = p->section; |
| 5254 | |
| 5255 | if (s != NULL && (s->flags & SEC_READONLY) != 0) |
| 5256 | { |
| 5257 | struct bfd_link_info *info = (struct bfd_link_info *) inf; |
| 5258 | |
| 5259 | info->flags |= DF_TEXTREL; |
| 5260 | |
| 5261 | /* Not an error, just cut short the traversal. */ |
| 5262 | return FALSE; |
| 5263 | } |
| 5264 | } |
| 5265 | return TRUE; |
| 5266 | } |
| 5267 | |
| 5268 | /* Set the sizes of the dynamic sections. */ |
| 5269 | |
| 5270 | static bfd_boolean |
| 5271 | elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, |
| 5272 | struct bfd_link_info * info) |
| 5273 | { |
| 5274 | bfd * dynobj; |
| 5275 | asection * s; |
| 5276 | bfd_boolean plt; |
| 5277 | bfd_boolean relocs; |
| 5278 | bfd *ibfd; |
| 5279 | struct elf32_arm_link_hash_table *htab; |
| 5280 | |
| 5281 | htab = elf32_arm_hash_table (info); |
| 5282 | dynobj = elf_hash_table (info)->dynobj; |
| 5283 | BFD_ASSERT (dynobj != NULL); |
| 5284 | |
| 5285 | if (elf_hash_table (info)->dynamic_sections_created) |
| 5286 | { |
| 5287 | /* Set the contents of the .interp section to the interpreter. */ |
| 5288 | if (info->executable) |
| 5289 | { |
| 5290 | s = bfd_get_section_by_name (dynobj, ".interp"); |
| 5291 | BFD_ASSERT (s != NULL); |
| 5292 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
| 5293 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
| 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | /* Set up .got offsets for local syms, and space for local dynamic |
| 5298 | relocs. */ |
| 5299 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
| 5300 | { |
| 5301 | bfd_signed_vma *local_got; |
| 5302 | bfd_signed_vma *end_local_got; |
| 5303 | char *local_tls_type; |
| 5304 | bfd_size_type locsymcount; |
| 5305 | Elf_Internal_Shdr *symtab_hdr; |
| 5306 | asection *srel; |
| 5307 | |
| 5308 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) |
| 5309 | continue; |
| 5310 | |
| 5311 | for (s = ibfd->sections; s != NULL; s = s->next) |
| 5312 | { |
| 5313 | struct elf32_arm_relocs_copied *p; |
| 5314 | |
| 5315 | for (p = *((struct elf32_arm_relocs_copied **) |
| 5316 | &elf_section_data (s)->local_dynrel); |
| 5317 | p != NULL; |
| 5318 | p = p->next) |
| 5319 | { |
| 5320 | if (!bfd_is_abs_section (p->section) |
| 5321 | && bfd_is_abs_section (p->section->output_section)) |
| 5322 | { |
| 5323 | /* Input section has been discarded, either because |
| 5324 | it is a copy of a linkonce section or due to |
| 5325 | linker script /DISCARD/, so we'll be discarding |
| 5326 | the relocs too. */ |
| 5327 | } |
| 5328 | else if (p->count != 0) |
| 5329 | { |
| 5330 | srel = elf_section_data (p->section)->sreloc; |
| 5331 | srel->size += p->count * sizeof (Elf32_External_Rel); |
| 5332 | if ((p->section->output_section->flags & SEC_READONLY) != 0) |
| 5333 | info->flags |= DF_TEXTREL; |
| 5334 | } |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | local_got = elf_local_got_refcounts (ibfd); |
| 5339 | if (!local_got) |
| 5340 | continue; |
| 5341 | |
| 5342 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
| 5343 | locsymcount = symtab_hdr->sh_info; |
| 5344 | end_local_got = local_got + locsymcount; |
| 5345 | local_tls_type = elf32_arm_local_got_tls_type (ibfd); |
| 5346 | s = htab->sgot; |
| 5347 | srel = htab->srelgot; |
| 5348 | for (; local_got < end_local_got; ++local_got, ++local_tls_type) |
| 5349 | { |
| 5350 | if (*local_got > 0) |
| 5351 | { |
| 5352 | *local_got = s->size; |
| 5353 | if (*local_tls_type & GOT_TLS_GD) |
| 5354 | /* TLS_GD relocs need an 8-byte structure in the GOT. */ |
| 5355 | s->size += 8; |
| 5356 | if (*local_tls_type & GOT_TLS_IE) |
| 5357 | s->size += 4; |
| 5358 | if (*local_tls_type == GOT_NORMAL) |
| 5359 | s->size += 4; |
| 5360 | |
| 5361 | if (info->shared || *local_tls_type == GOT_TLS_GD) |
| 5362 | srel->size += sizeof (Elf32_External_Rel); |
| 5363 | } |
| 5364 | else |
| 5365 | *local_got = (bfd_vma) -1; |
| 5366 | } |
| 5367 | } |
| 5368 | |
| 5369 | if (htab->tls_ldm_got.refcount > 0) |
| 5370 | { |
| 5371 | /* Allocate two GOT entries and one dynamic relocation (if necessary) |
| 5372 | for R_ARM_TLS_LDM32 relocations. */ |
| 5373 | htab->tls_ldm_got.offset = htab->sgot->size; |
| 5374 | htab->sgot->size += 8; |
| 5375 | if (info->shared) |
| 5376 | htab->srelgot->size += sizeof (Elf32_External_Rel); |
| 5377 | } |
| 5378 | else |
| 5379 | htab->tls_ldm_got.offset = -1; |
| 5380 | |
| 5381 | /* Allocate global sym .plt and .got entries, and space for global |
| 5382 | sym dynamic relocs. */ |
| 5383 | elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info); |
| 5384 | |
| 5385 | /* The check_relocs and adjust_dynamic_symbol entry points have |
| 5386 | determined the sizes of the various dynamic sections. Allocate |
| 5387 | memory for them. */ |
| 5388 | plt = FALSE; |
| 5389 | relocs = FALSE; |
| 5390 | for (s = dynobj->sections; s != NULL; s = s->next) |
| 5391 | { |
| 5392 | const char * name; |
| 5393 | bfd_boolean strip; |
| 5394 | |
| 5395 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
| 5396 | continue; |
| 5397 | |
| 5398 | /* It's OK to base decisions on the section name, because none |
| 5399 | of the dynobj section names depend upon the input files. */ |
| 5400 | name = bfd_get_section_name (dynobj, s); |
| 5401 | |
| 5402 | strip = FALSE; |
| 5403 | |
| 5404 | if (strcmp (name, ".plt") == 0) |
| 5405 | { |
| 5406 | if (s->size == 0) |
| 5407 | { |
| 5408 | /* Strip this section if we don't need it; see the |
| 5409 | comment below. */ |
| 5410 | strip = TRUE; |
| 5411 | } |
| 5412 | else |
| 5413 | { |
| 5414 | /* Remember whether there is a PLT. */ |
| 5415 | plt = TRUE; |
| 5416 | } |
| 5417 | } |
| 5418 | else if (strncmp (name, ".rel", 4) == 0) |
| 5419 | { |
| 5420 | if (s->size == 0) |
| 5421 | { |
| 5422 | /* If we don't need this section, strip it from the |
| 5423 | output file. This is mostly to handle .rel.bss and |
| 5424 | .rel.plt. We must create both sections in |
| 5425 | create_dynamic_sections, because they must be created |
| 5426 | before the linker maps input sections to output |
| 5427 | sections. The linker does that before |
| 5428 | adjust_dynamic_symbol is called, and it is that |
| 5429 | function which decides whether anything needs to go |
| 5430 | into these sections. */ |
| 5431 | strip = TRUE; |
| 5432 | } |
| 5433 | else |
| 5434 | { |
| 5435 | /* Remember whether there are any reloc sections other |
| 5436 | than .rel.plt. */ |
| 5437 | if (strcmp (name, ".rel.plt") != 0) |
| 5438 | relocs = TRUE; |
| 5439 | |
| 5440 | /* We use the reloc_count field as a counter if we need |
| 5441 | to copy relocs into the output file. */ |
| 5442 | s->reloc_count = 0; |
| 5443 | } |
| 5444 | } |
| 5445 | else if (strncmp (name, ".got", 4) != 0) |
| 5446 | { |
| 5447 | /* It's not one of our sections, so don't allocate space. */ |
| 5448 | continue; |
| 5449 | } |
| 5450 | |
| 5451 | if (strip) |
| 5452 | { |
| 5453 | _bfd_strip_section_from_output (info, s); |
| 5454 | continue; |
| 5455 | } |
| 5456 | |
| 5457 | /* Allocate memory for the section contents. */ |
| 5458 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
| 5459 | if (s->contents == NULL && s->size != 0) |
| 5460 | return FALSE; |
| 5461 | } |
| 5462 | |
| 5463 | if (elf_hash_table (info)->dynamic_sections_created) |
| 5464 | { |
| 5465 | /* Add some entries to the .dynamic section. We fill in the |
| 5466 | values later, in elf32_arm_finish_dynamic_sections, but we |
| 5467 | must add the entries now so that we get the correct size for |
| 5468 | the .dynamic section. The DT_DEBUG entry is filled in by the |
| 5469 | dynamic linker and used by the debugger. */ |
| 5470 | #define add_dynamic_entry(TAG, VAL) \ |
| 5471 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
| 5472 | |
| 5473 | if (!info->shared) |
| 5474 | { |
| 5475 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
| 5476 | return FALSE; |
| 5477 | } |
| 5478 | |
| 5479 | if (plt) |
| 5480 | { |
| 5481 | if ( !add_dynamic_entry (DT_PLTGOT, 0) |
| 5482 | || !add_dynamic_entry (DT_PLTRELSZ, 0) |
| 5483 | || !add_dynamic_entry (DT_PLTREL, DT_REL) |
| 5484 | || !add_dynamic_entry (DT_JMPREL, 0)) |
| 5485 | return FALSE; |
| 5486 | } |
| 5487 | |
| 5488 | if (relocs) |
| 5489 | { |
| 5490 | if ( !add_dynamic_entry (DT_REL, 0) |
| 5491 | || !add_dynamic_entry (DT_RELSZ, 0) |
| 5492 | || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel))) |
| 5493 | return FALSE; |
| 5494 | } |
| 5495 | |
| 5496 | /* If any dynamic relocs apply to a read-only section, |
| 5497 | then we need a DT_TEXTREL entry. */ |
| 5498 | if ((info->flags & DF_TEXTREL) == 0) |
| 5499 | elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs, |
| 5500 | (PTR) info); |
| 5501 | |
| 5502 | if ((info->flags & DF_TEXTREL) != 0) |
| 5503 | { |
| 5504 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
| 5505 | return FALSE; |
| 5506 | info->flags |= DF_TEXTREL; |
| 5507 | } |
| 5508 | } |
| 5509 | #undef add_synamic_entry |
| 5510 | |
| 5511 | return TRUE; |
| 5512 | } |
| 5513 | |
| 5514 | /* Finish up dynamic symbol handling. We set the contents of various |
| 5515 | dynamic sections here. */ |
| 5516 | |
| 5517 | static bfd_boolean |
| 5518 | elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info, |
| 5519 | struct elf_link_hash_entry * h, Elf_Internal_Sym * sym) |
| 5520 | { |
| 5521 | bfd * dynobj; |
| 5522 | struct elf32_arm_link_hash_table *htab; |
| 5523 | struct elf32_arm_link_hash_entry *eh; |
| 5524 | |
| 5525 | dynobj = elf_hash_table (info)->dynobj; |
| 5526 | htab = elf32_arm_hash_table (info); |
| 5527 | eh = (struct elf32_arm_link_hash_entry *) h; |
| 5528 | |
| 5529 | if (h->plt.offset != (bfd_vma) -1) |
| 5530 | { |
| 5531 | asection * splt; |
| 5532 | asection * srel; |
| 5533 | bfd_byte *loc; |
| 5534 | bfd_vma plt_index; |
| 5535 | Elf_Internal_Rela rel; |
| 5536 | |
| 5537 | /* This symbol has an entry in the procedure linkage table. Set |
| 5538 | it up. */ |
| 5539 | |
| 5540 | BFD_ASSERT (h->dynindx != -1); |
| 5541 | |
| 5542 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 5543 | srel = bfd_get_section_by_name (dynobj, ".rel.plt"); |
| 5544 | BFD_ASSERT (splt != NULL && srel != NULL); |
| 5545 | |
| 5546 | /* Fill in the entry in the procedure linkage table. */ |
| 5547 | if (htab->symbian_p) |
| 5548 | { |
| 5549 | unsigned i; |
| 5550 | for (i = 0; i < htab->plt_entry_size / 4; ++i) |
| 5551 | bfd_put_32 (output_bfd, |
| 5552 | elf32_arm_symbian_plt_entry[i], |
| 5553 | splt->contents + h->plt.offset + 4 * i); |
| 5554 | |
| 5555 | /* Fill in the entry in the .rel.plt section. */ |
| 5556 | rel.r_offset = (splt->output_section->vma |
| 5557 | + splt->output_offset |
| 5558 | + h->plt.offset + 4 * (i - 1)); |
| 5559 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); |
| 5560 | |
| 5561 | /* Get the index in the procedure linkage table which |
| 5562 | corresponds to this symbol. This is the index of this symbol |
| 5563 | in all the symbols for which we are making plt entries. The |
| 5564 | first entry in the procedure linkage table is reserved. */ |
| 5565 | plt_index = ((h->plt.offset - htab->plt_header_size) |
| 5566 | / htab->plt_entry_size); |
| 5567 | } |
| 5568 | else |
| 5569 | { |
| 5570 | bfd_vma got_offset; |
| 5571 | bfd_vma got_displacement; |
| 5572 | asection * sgot; |
| 5573 | |
| 5574 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 5575 | BFD_ASSERT (sgot != NULL); |
| 5576 | |
| 5577 | /* Get the offset into the .got.plt table of the entry that |
| 5578 | corresponds to this function. */ |
| 5579 | got_offset = eh->plt_got_offset; |
| 5580 | |
| 5581 | /* Get the index in the procedure linkage table which |
| 5582 | corresponds to this symbol. This is the index of this symbol |
| 5583 | in all the symbols for which we are making plt entries. The |
| 5584 | first three entries in .got.plt are reserved; after that |
| 5585 | symbols appear in the same order as in .plt. */ |
| 5586 | plt_index = (got_offset - 12) / 4; |
| 5587 | |
| 5588 | /* Calculate the displacement between the PLT slot and the |
| 5589 | entry in the GOT. The eight-byte offset accounts for the |
| 5590 | value produced by adding to pc in the first instruction |
| 5591 | of the PLT stub. */ |
| 5592 | got_displacement = (sgot->output_section->vma |
| 5593 | + sgot->output_offset |
| 5594 | + got_offset |
| 5595 | - splt->output_section->vma |
| 5596 | - splt->output_offset |
| 5597 | - h->plt.offset |
| 5598 | - 8); |
| 5599 | |
| 5600 | BFD_ASSERT ((got_displacement & 0xf0000000) == 0); |
| 5601 | |
| 5602 | if (eh->plt_thumb_refcount > 0) |
| 5603 | { |
| 5604 | bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[0], |
| 5605 | splt->contents + h->plt.offset - 4); |
| 5606 | bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[1], |
| 5607 | splt->contents + h->plt.offset - 2); |
| 5608 | } |
| 5609 | |
| 5610 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[0] | ((got_displacement & 0x0ff00000) >> 20), |
| 5611 | splt->contents + h->plt.offset + 0); |
| 5612 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[1] | ((got_displacement & 0x000ff000) >> 12), |
| 5613 | splt->contents + h->plt.offset + 4); |
| 5614 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[2] | (got_displacement & 0x00000fff), |
| 5615 | splt->contents + h->plt.offset + 8); |
| 5616 | #ifdef FOUR_WORD_PLT |
| 5617 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], |
| 5618 | splt->contents + h->plt.offset + 12); |
| 5619 | #endif |
| 5620 | |
| 5621 | /* Fill in the entry in the global offset table. */ |
| 5622 | bfd_put_32 (output_bfd, |
| 5623 | (splt->output_section->vma |
| 5624 | + splt->output_offset), |
| 5625 | sgot->contents + got_offset); |
| 5626 | |
| 5627 | /* Fill in the entry in the .rel.plt section. */ |
| 5628 | rel.r_offset = (sgot->output_section->vma |
| 5629 | + sgot->output_offset |
| 5630 | + got_offset); |
| 5631 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT); |
| 5632 | } |
| 5633 | |
| 5634 | loc = srel->contents + plt_index * sizeof (Elf32_External_Rel); |
| 5635 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
| 5636 | |
| 5637 | if (!h->def_regular) |
| 5638 | { |
| 5639 | /* Mark the symbol as undefined, rather than as defined in |
| 5640 | the .plt section. Leave the value alone. */ |
| 5641 | sym->st_shndx = SHN_UNDEF; |
| 5642 | /* If the symbol is weak, we do need to clear the value. |
| 5643 | Otherwise, the PLT entry would provide a definition for |
| 5644 | the symbol even if the symbol wasn't defined anywhere, |
| 5645 | and so the symbol would never be NULL. */ |
| 5646 | if (!h->ref_regular_nonweak) |
| 5647 | sym->st_value = 0; |
| 5648 | } |
| 5649 | } |
| 5650 | |
| 5651 | if (h->got.offset != (bfd_vma) -1 |
| 5652 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0 |
| 5653 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0) |
| 5654 | { |
| 5655 | asection * sgot; |
| 5656 | asection * srel; |
| 5657 | Elf_Internal_Rela rel; |
| 5658 | bfd_byte *loc; |
| 5659 | |
| 5660 | /* This symbol has an entry in the global offset table. Set it |
| 5661 | up. */ |
| 5662 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 5663 | srel = bfd_get_section_by_name (dynobj, ".rel.got"); |
| 5664 | BFD_ASSERT (sgot != NULL && srel != NULL); |
| 5665 | |
| 5666 | rel.r_offset = (sgot->output_section->vma |
| 5667 | + sgot->output_offset |
| 5668 | + (h->got.offset &~ (bfd_vma) 1)); |
| 5669 | |
| 5670 | /* If this is a static link, or it is a -Bsymbolic link and the |
| 5671 | symbol is defined locally or was forced to be local because |
| 5672 | of a version file, we just want to emit a RELATIVE reloc. |
| 5673 | The entry in the global offset table will already have been |
| 5674 | initialized in the relocate_section function. */ |
| 5675 | if (info->shared |
| 5676 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
| 5677 | { |
| 5678 | BFD_ASSERT((h->got.offset & 1) != 0); |
| 5679 | rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); |
| 5680 | } |
| 5681 | else |
| 5682 | { |
| 5683 | BFD_ASSERT((h->got.offset & 1) == 0); |
| 5684 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); |
| 5685 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); |
| 5686 | } |
| 5687 | |
| 5688 | loc = srel->contents + srel->reloc_count++ * sizeof (Elf32_External_Rel); |
| 5689 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
| 5690 | } |
| 5691 | |
| 5692 | if (h->needs_copy) |
| 5693 | { |
| 5694 | asection * s; |
| 5695 | Elf_Internal_Rela rel; |
| 5696 | bfd_byte *loc; |
| 5697 | |
| 5698 | /* This symbol needs a copy reloc. Set it up. */ |
| 5699 | BFD_ASSERT (h->dynindx != -1 |
| 5700 | && (h->root.type == bfd_link_hash_defined |
| 5701 | || h->root.type == bfd_link_hash_defweak)); |
| 5702 | |
| 5703 | s = bfd_get_section_by_name (h->root.u.def.section->owner, |
| 5704 | ".rel.bss"); |
| 5705 | BFD_ASSERT (s != NULL); |
| 5706 | |
| 5707 | rel.r_offset = (h->root.u.def.value |
| 5708 | + h->root.u.def.section->output_section->vma |
| 5709 | + h->root.u.def.section->output_offset); |
| 5710 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY); |
| 5711 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rel); |
| 5712 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); |
| 5713 | } |
| 5714 | |
| 5715 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ |
| 5716 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
| 5717 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
| 5718 | sym->st_shndx = SHN_ABS; |
| 5719 | |
| 5720 | return TRUE; |
| 5721 | } |
| 5722 | |
| 5723 | /* Finish up the dynamic sections. */ |
| 5724 | |
| 5725 | static bfd_boolean |
| 5726 | elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info) |
| 5727 | { |
| 5728 | bfd * dynobj; |
| 5729 | asection * sgot; |
| 5730 | asection * sdyn; |
| 5731 | |
| 5732 | dynobj = elf_hash_table (info)->dynobj; |
| 5733 | |
| 5734 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 5735 | BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL); |
| 5736 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
| 5737 | |
| 5738 | if (elf_hash_table (info)->dynamic_sections_created) |
| 5739 | { |
| 5740 | asection *splt; |
| 5741 | Elf32_External_Dyn *dyncon, *dynconend; |
| 5742 | struct elf32_arm_link_hash_table *htab; |
| 5743 | |
| 5744 | htab = elf32_arm_hash_table (info); |
| 5745 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 5746 | BFD_ASSERT (splt != NULL && sdyn != NULL); |
| 5747 | |
| 5748 | dyncon = (Elf32_External_Dyn *) sdyn->contents; |
| 5749 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
| 5750 | |
| 5751 | for (; dyncon < dynconend; dyncon++) |
| 5752 | { |
| 5753 | Elf_Internal_Dyn dyn; |
| 5754 | const char * name; |
| 5755 | asection * s; |
| 5756 | |
| 5757 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
| 5758 | |
| 5759 | switch (dyn.d_tag) |
| 5760 | { |
| 5761 | unsigned int type; |
| 5762 | |
| 5763 | default: |
| 5764 | break; |
| 5765 | |
| 5766 | case DT_HASH: |
| 5767 | name = ".hash"; |
| 5768 | goto get_vma_if_bpabi; |
| 5769 | case DT_STRTAB: |
| 5770 | name = ".dynstr"; |
| 5771 | goto get_vma_if_bpabi; |
| 5772 | case DT_SYMTAB: |
| 5773 | name = ".dynsym"; |
| 5774 | goto get_vma_if_bpabi; |
| 5775 | case DT_VERSYM: |
| 5776 | name = ".gnu.version"; |
| 5777 | goto get_vma_if_bpabi; |
| 5778 | case DT_VERDEF: |
| 5779 | name = ".gnu.version_d"; |
| 5780 | goto get_vma_if_bpabi; |
| 5781 | case DT_VERNEED: |
| 5782 | name = ".gnu.version_r"; |
| 5783 | goto get_vma_if_bpabi; |
| 5784 | |
| 5785 | case DT_PLTGOT: |
| 5786 | name = ".got"; |
| 5787 | goto get_vma; |
| 5788 | case DT_JMPREL: |
| 5789 | name = ".rel.plt"; |
| 5790 | get_vma: |
| 5791 | s = bfd_get_section_by_name (output_bfd, name); |
| 5792 | BFD_ASSERT (s != NULL); |
| 5793 | if (!htab->symbian_p) |
| 5794 | dyn.d_un.d_ptr = s->vma; |
| 5795 | else |
| 5796 | /* In the BPABI, tags in the PT_DYNAMIC section point |
| 5797 | at the file offset, not the memory address, for the |
| 5798 | convenience of the post linker. */ |
| 5799 | dyn.d_un.d_ptr = s->filepos; |
| 5800 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 5801 | break; |
| 5802 | |
| 5803 | get_vma_if_bpabi: |
| 5804 | if (htab->symbian_p) |
| 5805 | goto get_vma; |
| 5806 | break; |
| 5807 | |
| 5808 | case DT_PLTRELSZ: |
| 5809 | s = bfd_get_section_by_name (output_bfd, ".rel.plt"); |
| 5810 | BFD_ASSERT (s != NULL); |
| 5811 | dyn.d_un.d_val = s->size; |
| 5812 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 5813 | break; |
| 5814 | |
| 5815 | case DT_RELSZ: |
| 5816 | if (!htab->symbian_p) |
| 5817 | { |
| 5818 | /* My reading of the SVR4 ABI indicates that the |
| 5819 | procedure linkage table relocs (DT_JMPREL) should be |
| 5820 | included in the overall relocs (DT_REL). This is |
| 5821 | what Solaris does. However, UnixWare can not handle |
| 5822 | that case. Therefore, we override the DT_RELSZ entry |
| 5823 | here to make it not include the JMPREL relocs. Since |
| 5824 | the linker script arranges for .rel.plt to follow all |
| 5825 | other relocation sections, we don't have to worry |
| 5826 | about changing the DT_REL entry. */ |
| 5827 | s = bfd_get_section_by_name (output_bfd, ".rel.plt"); |
| 5828 | if (s != NULL) |
| 5829 | dyn.d_un.d_val -= s->size; |
| 5830 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 5831 | break; |
| 5832 | } |
| 5833 | /* Fall through */ |
| 5834 | |
| 5835 | case DT_REL: |
| 5836 | case DT_RELA: |
| 5837 | case DT_RELASZ: |
| 5838 | /* In the BPABI, the DT_REL tag must point at the file |
| 5839 | offset, not the VMA, of the first relocation |
| 5840 | section. So, we use code similar to that in |
| 5841 | elflink.c, but do not check for SHF_ALLOC on the |
| 5842 | relcoation section, since relocations sections are |
| 5843 | never allocated under the BPABI. The comments above |
| 5844 | about Unixware notwithstanding, we include all of the |
| 5845 | relocations here. */ |
| 5846 | if (htab->symbian_p) |
| 5847 | { |
| 5848 | unsigned int i; |
| 5849 | type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ) |
| 5850 | ? SHT_REL : SHT_RELA); |
| 5851 | dyn.d_un.d_val = 0; |
| 5852 | for (i = 1; i < elf_numsections (output_bfd); i++) |
| 5853 | { |
| 5854 | Elf_Internal_Shdr *hdr |
| 5855 | = elf_elfsections (output_bfd)[i]; |
| 5856 | if (hdr->sh_type == type) |
| 5857 | { |
| 5858 | if (dyn.d_tag == DT_RELSZ |
| 5859 | || dyn.d_tag == DT_RELASZ) |
| 5860 | dyn.d_un.d_val += hdr->sh_size; |
| 5861 | else if ((ufile_ptr) hdr->sh_offset |
| 5862 | <= dyn.d_un.d_val - 1) |
| 5863 | dyn.d_un.d_val = hdr->sh_offset; |
| 5864 | } |
| 5865 | } |
| 5866 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 5867 | } |
| 5868 | break; |
| 5869 | |
| 5870 | /* Set the bottom bit of DT_INIT/FINI if the |
| 5871 | corresponding function is Thumb. */ |
| 5872 | case DT_INIT: |
| 5873 | name = info->init_function; |
| 5874 | goto get_sym; |
| 5875 | case DT_FINI: |
| 5876 | name = info->fini_function; |
| 5877 | get_sym: |
| 5878 | /* If it wasn't set by elf_bfd_final_link |
| 5879 | then there is nothing to adjust. */ |
| 5880 | if (dyn.d_un.d_val != 0) |
| 5881 | { |
| 5882 | struct elf_link_hash_entry * eh; |
| 5883 | |
| 5884 | eh = elf_link_hash_lookup (elf_hash_table (info), name, |
| 5885 | FALSE, FALSE, TRUE); |
| 5886 | if (eh != (struct elf_link_hash_entry *) NULL |
| 5887 | && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC) |
| 5888 | { |
| 5889 | dyn.d_un.d_val |= 1; |
| 5890 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 5891 | } |
| 5892 | } |
| 5893 | break; |
| 5894 | } |
| 5895 | } |
| 5896 | |
| 5897 | /* Fill in the first entry in the procedure linkage table. */ |
| 5898 | if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size) |
| 5899 | { |
| 5900 | bfd_vma got_displacement; |
| 5901 | |
| 5902 | /* Calculate the displacement between the PLT slot and &GOT[0]. */ |
| 5903 | got_displacement = (sgot->output_section->vma |
| 5904 | + sgot->output_offset |
| 5905 | - splt->output_section->vma |
| 5906 | - splt->output_offset |
| 5907 | - 16); |
| 5908 | |
| 5909 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[0], splt->contents + 0); |
| 5910 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[1], splt->contents + 4); |
| 5911 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[2], splt->contents + 8); |
| 5912 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[3], splt->contents + 12); |
| 5913 | #ifdef FOUR_WORD_PLT |
| 5914 | /* The displacement value goes in the otherwise-unused last word of |
| 5915 | the second entry. */ |
| 5916 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 28); |
| 5917 | #else |
| 5918 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 16); |
| 5919 | #endif |
| 5920 | } |
| 5921 | |
| 5922 | /* UnixWare sets the entsize of .plt to 4, although that doesn't |
| 5923 | really seem like the right value. */ |
| 5924 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; |
| 5925 | } |
| 5926 | |
| 5927 | /* Fill in the first three entries in the global offset table. */ |
| 5928 | if (sgot) |
| 5929 | { |
| 5930 | if (sgot->size > 0) |
| 5931 | { |
| 5932 | if (sdyn == NULL) |
| 5933 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); |
| 5934 | else |
| 5935 | bfd_put_32 (output_bfd, |
| 5936 | sdyn->output_section->vma + sdyn->output_offset, |
| 5937 | sgot->contents); |
| 5938 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); |
| 5939 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); |
| 5940 | } |
| 5941 | |
| 5942 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
| 5943 | } |
| 5944 | |
| 5945 | return TRUE; |
| 5946 | } |
| 5947 | |
| 5948 | static void |
| 5949 | elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED) |
| 5950 | { |
| 5951 | Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ |
| 5952 | struct elf32_arm_link_hash_table *globals; |
| 5953 | |
| 5954 | i_ehdrp = elf_elfheader (abfd); |
| 5955 | |
| 5956 | if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN) |
| 5957 | i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM; |
| 5958 | else |
| 5959 | i_ehdrp->e_ident[EI_OSABI] = 0; |
| 5960 | i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION; |
| 5961 | |
| 5962 | if (link_info) |
| 5963 | { |
| 5964 | globals = elf32_arm_hash_table (link_info); |
| 5965 | if (globals->byteswap_code) |
| 5966 | i_ehdrp->e_flags |= EF_ARM_BE8; |
| 5967 | } |
| 5968 | } |
| 5969 | |
| 5970 | static enum elf_reloc_type_class |
| 5971 | elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela) |
| 5972 | { |
| 5973 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
| 5974 | { |
| 5975 | case R_ARM_RELATIVE: |
| 5976 | return reloc_class_relative; |
| 5977 | case R_ARM_JUMP_SLOT: |
| 5978 | return reloc_class_plt; |
| 5979 | case R_ARM_COPY: |
| 5980 | return reloc_class_copy; |
| 5981 | default: |
| 5982 | return reloc_class_normal; |
| 5983 | } |
| 5984 | } |
| 5985 | |
| 5986 | /* Set the right machine number for an Arm ELF file. */ |
| 5987 | |
| 5988 | static bfd_boolean |
| 5989 | elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr) |
| 5990 | { |
| 5991 | if (hdr->sh_type == SHT_NOTE) |
| 5992 | *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS; |
| 5993 | |
| 5994 | return TRUE; |
| 5995 | } |
| 5996 | |
| 5997 | static void |
| 5998 | elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) |
| 5999 | { |
| 6000 | bfd_arm_update_notes (abfd, ARM_NOTE_SECTION); |
| 6001 | } |
| 6002 | |
| 6003 | /* Return TRUE if this is an unwinding table entry. */ |
| 6004 | |
| 6005 | static bfd_boolean |
| 6006 | is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name) |
| 6007 | { |
| 6008 | size_t len1, len2; |
| 6009 | |
| 6010 | len1 = sizeof (ELF_STRING_ARM_unwind) - 1; |
| 6011 | len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1; |
| 6012 | return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0 |
| 6013 | || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0); |
| 6014 | } |
| 6015 | |
| 6016 | |
| 6017 | /* Set the type and flags for an ARM section. We do this by |
| 6018 | the section name, which is a hack, but ought to work. */ |
| 6019 | |
| 6020 | static bfd_boolean |
| 6021 | elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec) |
| 6022 | { |
| 6023 | const char * name; |
| 6024 | |
| 6025 | name = bfd_get_section_name (abfd, sec); |
| 6026 | |
| 6027 | if (is_arm_elf_unwind_section_name (abfd, name)) |
| 6028 | { |
| 6029 | hdr->sh_type = SHT_ARM_EXIDX; |
| 6030 | hdr->sh_flags |= SHF_LINK_ORDER; |
| 6031 | } |
| 6032 | return TRUE; |
| 6033 | } |
| 6034 | |
| 6035 | /* Handle an ARM specific section when reading an object file. This is |
| 6036 | called when bfd_section_from_shdr finds a section with an unknown |
| 6037 | type. */ |
| 6038 | |
| 6039 | static bfd_boolean |
| 6040 | elf32_arm_section_from_shdr (bfd *abfd, |
| 6041 | Elf_Internal_Shdr * hdr, |
| 6042 | const char *name, |
| 6043 | int shindex) |
| 6044 | { |
| 6045 | /* There ought to be a place to keep ELF backend specific flags, but |
| 6046 | at the moment there isn't one. We just keep track of the |
| 6047 | sections by their name, instead. Fortunately, the ABI gives |
| 6048 | names for all the ARM specific sections, so we will probably get |
| 6049 | away with this. */ |
| 6050 | switch (hdr->sh_type) |
| 6051 | { |
| 6052 | case SHT_ARM_EXIDX: |
| 6053 | break; |
| 6054 | |
| 6055 | default: |
| 6056 | return FALSE; |
| 6057 | } |
| 6058 | |
| 6059 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
| 6060 | return FALSE; |
| 6061 | |
| 6062 | return TRUE; |
| 6063 | } |
| 6064 | |
| 6065 | /* Called for each symbol. Builds a section map based on mapping symbols. |
| 6066 | Does not alter any of the symbols. */ |
| 6067 | |
| 6068 | static bfd_boolean |
| 6069 | elf32_arm_output_symbol_hook (struct bfd_link_info *info, |
| 6070 | const char *name, |
| 6071 | Elf_Internal_Sym *elfsym, |
| 6072 | asection *input_sec, |
| 6073 | struct elf_link_hash_entry *h ATTRIBUTE_UNUSED) |
| 6074 | { |
| 6075 | int mapcount; |
| 6076 | elf32_arm_section_map *map; |
| 6077 | struct elf32_arm_link_hash_table *globals; |
| 6078 | |
| 6079 | /* Only do this on final link. */ |
| 6080 | if (info->relocatable) |
| 6081 | return TRUE; |
| 6082 | |
| 6083 | /* Only build a map if we need to byteswap code. */ |
| 6084 | globals = elf32_arm_hash_table (info); |
| 6085 | if (!globals->byteswap_code) |
| 6086 | return TRUE; |
| 6087 | |
| 6088 | /* We only want mapping symbols. */ |
| 6089 | if (! is_arm_mapping_symbol_name (name)) |
| 6090 | return TRUE; |
| 6091 | |
| 6092 | mapcount = ++(elf32_arm_section_data (input_sec)->mapcount); |
| 6093 | map = elf32_arm_section_data (input_sec)->map; |
| 6094 | /* TODO: This may be inefficient, but we probably don't usually have many |
| 6095 | mapping symbols per section. */ |
| 6096 | map = bfd_realloc (map, mapcount * sizeof (elf32_arm_section_map)); |
| 6097 | elf32_arm_section_data (input_sec)->map = map; |
| 6098 | |
| 6099 | map[mapcount - 1].vma = elfsym->st_value; |
| 6100 | map[mapcount - 1].type = name[1]; |
| 6101 | return TRUE; |
| 6102 | } |
| 6103 | |
| 6104 | |
| 6105 | /* Allocate target specific section data. */ |
| 6106 | |
| 6107 | static bfd_boolean |
| 6108 | elf32_arm_new_section_hook (bfd *abfd, asection *sec) |
| 6109 | { |
| 6110 | struct _arm_elf_section_data *sdata; |
| 6111 | bfd_size_type amt = sizeof (*sdata); |
| 6112 | |
| 6113 | sdata = bfd_zalloc (abfd, amt); |
| 6114 | if (sdata == NULL) |
| 6115 | return FALSE; |
| 6116 | sec->used_by_bfd = sdata; |
| 6117 | |
| 6118 | return _bfd_elf_new_section_hook (abfd, sec); |
| 6119 | } |
| 6120 | |
| 6121 | |
| 6122 | /* Used to order a list of mapping symbols by address. */ |
| 6123 | |
| 6124 | static int |
| 6125 | elf32_arm_compare_mapping (const void * a, const void * b) |
| 6126 | { |
| 6127 | return ((const elf32_arm_section_map *) a)->vma |
| 6128 | > ((const elf32_arm_section_map *) b)->vma; |
| 6129 | } |
| 6130 | |
| 6131 | |
| 6132 | /* Do code byteswapping. Return FALSE afterwards so that the section is |
| 6133 | written out as normal. */ |
| 6134 | |
| 6135 | static bfd_boolean |
| 6136 | elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec, |
| 6137 | bfd_byte *contents) |
| 6138 | { |
| 6139 | int mapcount; |
| 6140 | elf32_arm_section_map *map; |
| 6141 | bfd_vma ptr; |
| 6142 | bfd_vma end; |
| 6143 | bfd_vma offset; |
| 6144 | bfd_byte tmp; |
| 6145 | int i; |
| 6146 | |
| 6147 | mapcount = elf32_arm_section_data (sec)->mapcount; |
| 6148 | map = elf32_arm_section_data (sec)->map; |
| 6149 | |
| 6150 | if (mapcount == 0) |
| 6151 | return FALSE; |
| 6152 | |
| 6153 | qsort (map, mapcount, sizeof (elf32_arm_section_map), |
| 6154 | elf32_arm_compare_mapping); |
| 6155 | |
| 6156 | offset = sec->output_section->vma + sec->output_offset; |
| 6157 | ptr = map[0].vma - offset; |
| 6158 | for (i = 0; i < mapcount; i++) |
| 6159 | { |
| 6160 | if (i == mapcount - 1) |
| 6161 | end = sec->size; |
| 6162 | else |
| 6163 | end = map[i + 1].vma - offset; |
| 6164 | |
| 6165 | switch (map[i].type) |
| 6166 | { |
| 6167 | case 'a': |
| 6168 | /* Byte swap code words. */ |
| 6169 | while (ptr + 3 < end) |
| 6170 | { |
| 6171 | tmp = contents[ptr]; |
| 6172 | contents[ptr] = contents[ptr + 3]; |
| 6173 | contents[ptr + 3] = tmp; |
| 6174 | tmp = contents[ptr + 1]; |
| 6175 | contents[ptr + 1] = contents[ptr + 2]; |
| 6176 | contents[ptr + 2] = tmp; |
| 6177 | ptr += 4; |
| 6178 | } |
| 6179 | break; |
| 6180 | |
| 6181 | case 't': |
| 6182 | /* Byte swap code halfwords. */ |
| 6183 | while (ptr + 1 < end) |
| 6184 | { |
| 6185 | tmp = contents[ptr]; |
| 6186 | contents[ptr] = contents[ptr + 1]; |
| 6187 | contents[ptr + 1] = tmp; |
| 6188 | ptr += 2; |
| 6189 | } |
| 6190 | break; |
| 6191 | |
| 6192 | case 'd': |
| 6193 | /* Leave data alone. */ |
| 6194 | break; |
| 6195 | } |
| 6196 | ptr = end; |
| 6197 | } |
| 6198 | free (map); |
| 6199 | return FALSE; |
| 6200 | } |
| 6201 | |
| 6202 | /* Display STT_ARM_TFUNC symbols as functions. */ |
| 6203 | |
| 6204 | static void |
| 6205 | elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, |
| 6206 | asymbol *asym) |
| 6207 | { |
| 6208 | elf_symbol_type *elfsym = (elf_symbol_type *) asym; |
| 6209 | |
| 6210 | if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC) |
| 6211 | elfsym->symbol.flags |= BSF_FUNCTION; |
| 6212 | } |
| 6213 | |
| 6214 | |
| 6215 | /* Mangle thumb function symbols as we read them in. */ |
| 6216 | |
| 6217 | static void |
| 6218 | elf32_arm_swap_symbol_in (bfd * abfd, |
| 6219 | const void *psrc, |
| 6220 | const void *pshn, |
| 6221 | Elf_Internal_Sym *dst) |
| 6222 | { |
| 6223 | bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst); |
| 6224 | |
| 6225 | /* New EABI objects mark thumb function symbols by setting the low bit of |
| 6226 | the address. Turn these into STT_ARM_TFUNC. */ |
| 6227 | if (ELF_ST_TYPE (dst->st_info) == STT_FUNC |
| 6228 | && (dst->st_value & 1)) |
| 6229 | { |
| 6230 | dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC); |
| 6231 | dst->st_value &= ~(bfd_vma) 1; |
| 6232 | } |
| 6233 | } |
| 6234 | |
| 6235 | |
| 6236 | /* Mangle thumb function symbols as we write them out. */ |
| 6237 | |
| 6238 | static void |
| 6239 | elf32_arm_swap_symbol_out (bfd *abfd, |
| 6240 | const Elf_Internal_Sym *src, |
| 6241 | void *cdst, |
| 6242 | void *shndx) |
| 6243 | { |
| 6244 | Elf_Internal_Sym newsym; |
| 6245 | |
| 6246 | /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit |
| 6247 | of the address set, as per the new EABI. We do this unconditionally |
| 6248 | because objcopy does not set the elf header flags until after |
| 6249 | it writes out the symbol table. */ |
| 6250 | if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC) |
| 6251 | { |
| 6252 | newsym = *src; |
| 6253 | newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC); |
| 6254 | newsym.st_value |= 1; |
| 6255 | |
| 6256 | src = &newsym; |
| 6257 | } |
| 6258 | bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx); |
| 6259 | } |
| 6260 | |
| 6261 | /* Add the PT_ARM_EXIDX program header. */ |
| 6262 | |
| 6263 | static bfd_boolean |
| 6264 | elf32_arm_modify_segment_map (bfd *abfd, |
| 6265 | struct bfd_link_info *info ATTRIBUTE_UNUSED) |
| 6266 | { |
| 6267 | struct elf_segment_map *m; |
| 6268 | asection *sec; |
| 6269 | |
| 6270 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); |
| 6271 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) |
| 6272 | { |
| 6273 | /* If there is already a PT_ARM_EXIDX header, then we do not |
| 6274 | want to add another one. This situation arises when running |
| 6275 | "strip"; the input binary already has the header. */ |
| 6276 | m = elf_tdata (abfd)->segment_map; |
| 6277 | while (m && m->p_type != PT_ARM_EXIDX) |
| 6278 | m = m->next; |
| 6279 | if (!m) |
| 6280 | { |
| 6281 | m = bfd_zalloc (abfd, sizeof (struct elf_segment_map)); |
| 6282 | if (m == NULL) |
| 6283 | return FALSE; |
| 6284 | m->p_type = PT_ARM_EXIDX; |
| 6285 | m->count = 1; |
| 6286 | m->sections[0] = sec; |
| 6287 | |
| 6288 | m->next = elf_tdata (abfd)->segment_map; |
| 6289 | elf_tdata (abfd)->segment_map = m; |
| 6290 | } |
| 6291 | } |
| 6292 | |
| 6293 | return TRUE; |
| 6294 | } |
| 6295 | |
| 6296 | /* We may add a PT_ARM_EXIDX program header. */ |
| 6297 | |
| 6298 | static int |
| 6299 | elf32_arm_additional_program_headers (bfd *abfd) |
| 6300 | { |
| 6301 | asection *sec; |
| 6302 | |
| 6303 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); |
| 6304 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) |
| 6305 | return 1; |
| 6306 | else |
| 6307 | return 0; |
| 6308 | } |
| 6309 | |
| 6310 | /* We use this to override swap_symbol_in and swap_symbol_out. */ |
| 6311 | const struct elf_size_info elf32_arm_size_info = { |
| 6312 | sizeof (Elf32_External_Ehdr), |
| 6313 | sizeof (Elf32_External_Phdr), |
| 6314 | sizeof (Elf32_External_Shdr), |
| 6315 | sizeof (Elf32_External_Rel), |
| 6316 | sizeof (Elf32_External_Rela), |
| 6317 | sizeof (Elf32_External_Sym), |
| 6318 | sizeof (Elf32_External_Dyn), |
| 6319 | sizeof (Elf_External_Note), |
| 6320 | 4, |
| 6321 | 1, |
| 6322 | 32, 2, |
| 6323 | ELFCLASS32, EV_CURRENT, |
| 6324 | bfd_elf32_write_out_phdrs, |
| 6325 | bfd_elf32_write_shdrs_and_ehdr, |
| 6326 | bfd_elf32_write_relocs, |
| 6327 | elf32_arm_swap_symbol_in, |
| 6328 | elf32_arm_swap_symbol_out, |
| 6329 | bfd_elf32_slurp_reloc_table, |
| 6330 | bfd_elf32_slurp_symbol_table, |
| 6331 | bfd_elf32_swap_dyn_in, |
| 6332 | bfd_elf32_swap_dyn_out, |
| 6333 | bfd_elf32_swap_reloc_in, |
| 6334 | bfd_elf32_swap_reloc_out, |
| 6335 | bfd_elf32_swap_reloca_in, |
| 6336 | bfd_elf32_swap_reloca_out |
| 6337 | }; |
| 6338 | |
| 6339 | #define ELF_ARCH bfd_arch_arm |
| 6340 | #define ELF_MACHINE_CODE EM_ARM |
| 6341 | #ifdef __QNXTARGET__ |
| 6342 | #define ELF_MAXPAGESIZE 0x1000 |
| 6343 | #else |
| 6344 | #define ELF_MAXPAGESIZE 0x8000 |
| 6345 | #endif |
| 6346 | #define ELF_MINPAGESIZE 0x1000 |
| 6347 | |
| 6348 | #define bfd_elf32_mkobject elf32_arm_mkobject |
| 6349 | |
| 6350 | #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data |
| 6351 | #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data |
| 6352 | #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags |
| 6353 | #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data |
| 6354 | #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create |
| 6355 | #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup |
| 6356 | #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line |
| 6357 | #define bfd_elf32_new_section_hook elf32_arm_new_section_hook |
| 6358 | #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol |
| 6359 | |
| 6360 | #define elf_backend_get_symbol_type elf32_arm_get_symbol_type |
| 6361 | #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook |
| 6362 | #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook |
| 6363 | #define elf_backend_check_relocs elf32_arm_check_relocs |
| 6364 | #define elf_backend_relocate_section elf32_arm_relocate_section |
| 6365 | #define elf_backend_write_section elf32_arm_write_section |
| 6366 | #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol |
| 6367 | #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections |
| 6368 | #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol |
| 6369 | #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections |
| 6370 | #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook |
| 6371 | #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections |
| 6372 | #define elf_backend_post_process_headers elf32_arm_post_process_headers |
| 6373 | #define elf_backend_reloc_type_class elf32_arm_reloc_type_class |
| 6374 | #define elf_backend_object_p elf32_arm_object_p |
| 6375 | #define elf_backend_section_flags elf32_arm_section_flags |
| 6376 | #define elf_backend_fake_sections elf32_arm_fake_sections |
| 6377 | #define elf_backend_section_from_shdr elf32_arm_section_from_shdr |
| 6378 | #define elf_backend_final_write_processing elf32_arm_final_write_processing |
| 6379 | #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol |
| 6380 | #define elf_backend_symbol_processing elf32_arm_symbol_processing |
| 6381 | #define elf_backend_size_info elf32_arm_size_info |
| 6382 | #define elf_backend_modify_segment_map elf32_arm_modify_segment_map |
| 6383 | #define elf_backend_additional_program_headers \ |
| 6384 | elf32_arm_additional_program_headers |
| 6385 | |
| 6386 | #define elf_backend_can_refcount 1 |
| 6387 | #define elf_backend_can_gc_sections 1 |
| 6388 | #define elf_backend_plt_readonly 1 |
| 6389 | #define elf_backend_want_got_plt 1 |
| 6390 | #define elf_backend_want_plt_sym 0 |
| 6391 | #define elf_backend_may_use_rel_p 1 |
| 6392 | #define elf_backend_may_use_rela_p 0 |
| 6393 | #define elf_backend_default_use_rela_p 0 |
| 6394 | #define elf_backend_rela_normal 0 |
| 6395 | |
| 6396 | #define elf_backend_got_header_size 12 |
| 6397 | |
| 6398 | #include "elf32-target.h" |
| 6399 | |
| 6400 | /* VxWorks Targets */ |
| 6401 | |
| 6402 | #undef TARGET_LITTLE_SYM |
| 6403 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec |
| 6404 | #undef TARGET_LITTLE_NAME |
| 6405 | #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks" |
| 6406 | #undef TARGET_BIG_SYM |
| 6407 | #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec |
| 6408 | #undef TARGET_BIG_NAME |
| 6409 | #define TARGET_BIG_NAME "elf32-bigarm-vxworks" |
| 6410 | |
| 6411 | /* Like elf32_arm_link_hash_table_create -- but overrides |
| 6412 | appropriately for VxWorks. */ |
| 6413 | static struct bfd_link_hash_table * |
| 6414 | elf32_arm_vxworks_link_hash_table_create (bfd *abfd) |
| 6415 | { |
| 6416 | struct bfd_link_hash_table *ret; |
| 6417 | |
| 6418 | ret = elf32_arm_link_hash_table_create (abfd); |
| 6419 | if (ret) |
| 6420 | { |
| 6421 | struct elf32_arm_link_hash_table *htab |
| 6422 | = (struct elf32_arm_link_hash_table *)ret; |
| 6423 | htab->use_rel = 0; |
| 6424 | } |
| 6425 | return ret; |
| 6426 | } |
| 6427 | |
| 6428 | #undef elf32_bed |
| 6429 | #define elf32_bed elf32_arm_vxworks_bed |
| 6430 | |
| 6431 | #undef bfd_elf32_bfd_link_hash_table_create |
| 6432 | #define bfd_elf32_bfd_link_hash_table_create \ |
| 6433 | elf32_arm_vxworks_link_hash_table_create |
| 6434 | |
| 6435 | #undef elf_backend_may_use_rel_p |
| 6436 | #define elf_backend_may_use_rel_p 0 |
| 6437 | #undef elf_backend_may_use_rela_p |
| 6438 | #define elf_backend_may_use_rela_p 1 |
| 6439 | #undef elf_backend_default_use_rela_p |
| 6440 | #define elf_backend_default_use_rela_p 1 |
| 6441 | #undef elf_backend_rela_normal |
| 6442 | #define elf_backend_rela_normal 1 |
| 6443 | |
| 6444 | #include "elf32-target.h" |
| 6445 | |
| 6446 | |
| 6447 | /* Symbian OS Targets */ |
| 6448 | |
| 6449 | #undef TARGET_LITTLE_SYM |
| 6450 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec |
| 6451 | #undef TARGET_LITTLE_NAME |
| 6452 | #define TARGET_LITTLE_NAME "elf32-littlearm-symbian" |
| 6453 | #undef TARGET_BIG_SYM |
| 6454 | #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec |
| 6455 | #undef TARGET_BIG_NAME |
| 6456 | #define TARGET_BIG_NAME "elf32-bigarm-symbian" |
| 6457 | |
| 6458 | /* Like elf32_arm_link_hash_table_create -- but overrides |
| 6459 | appropriately for Symbian OS. */ |
| 6460 | static struct bfd_link_hash_table * |
| 6461 | elf32_arm_symbian_link_hash_table_create (bfd *abfd) |
| 6462 | { |
| 6463 | struct bfd_link_hash_table *ret; |
| 6464 | |
| 6465 | ret = elf32_arm_link_hash_table_create (abfd); |
| 6466 | if (ret) |
| 6467 | { |
| 6468 | struct elf32_arm_link_hash_table *htab |
| 6469 | = (struct elf32_arm_link_hash_table *)ret; |
| 6470 | /* There is no PLT header for Symbian OS. */ |
| 6471 | htab->plt_header_size = 0; |
| 6472 | /* The PLT entries are each three instructions. */ |
| 6473 | htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry); |
| 6474 | htab->symbian_p = 1; |
| 6475 | htab->root.is_relocatable_executable = 1; |
| 6476 | } |
| 6477 | return ret; |
| 6478 | } |
| 6479 | |
| 6480 | static struct bfd_elf_special_section const |
| 6481 | elf32_arm_symbian_special_sections[]= |
| 6482 | { |
| 6483 | /* In a BPABI executable, the dynamic linking sections do not go in |
| 6484 | the loadable read-only segment. The post-linker may wish to |
| 6485 | refer to these sections, but they are not part of the final |
| 6486 | program image. */ |
| 6487 | { ".dynamic", 8, 0, SHT_DYNAMIC, 0 }, |
| 6488 | { ".dynstr", 7, 0, SHT_STRTAB, 0 }, |
| 6489 | { ".dynsym", 7, 0, SHT_DYNSYM, 0 }, |
| 6490 | { ".got", 4, 0, SHT_PROGBITS, 0 }, |
| 6491 | { ".hash", 5, 0, SHT_HASH, 0 }, |
| 6492 | /* These sections do not need to be writable as the SymbianOS |
| 6493 | postlinker will arrange things so that no dynamic relocation is |
| 6494 | required. */ |
| 6495 | { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC }, |
| 6496 | { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC }, |
| 6497 | { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC }, |
| 6498 | { NULL, 0, 0, 0, 0 } |
| 6499 | }; |
| 6500 | |
| 6501 | static void |
| 6502 | elf32_arm_symbian_begin_write_processing (bfd *abfd, |
| 6503 | struct bfd_link_info *link_info |
| 6504 | ATTRIBUTE_UNUSED) |
| 6505 | { |
| 6506 | /* BPABI objects are never loaded directly by an OS kernel; they are |
| 6507 | processed by a postlinker first, into an OS-specific format. If |
| 6508 | the D_PAGED bit is set on the file, BFD will align segments on |
| 6509 | page boundaries, so that an OS can directly map the file. With |
| 6510 | BPABI objects, that just results in wasted space. In addition, |
| 6511 | because we clear the D_PAGED bit, map_sections_to_segments will |
| 6512 | recognize that the program headers should not be mapped into any |
| 6513 | loadable segment. */ |
| 6514 | abfd->flags &= ~D_PAGED; |
| 6515 | } |
| 6516 | |
| 6517 | static bfd_boolean |
| 6518 | elf32_arm_symbian_modify_segment_map (bfd *abfd, |
| 6519 | struct bfd_link_info *info) |
| 6520 | { |
| 6521 | struct elf_segment_map *m; |
| 6522 | asection *dynsec; |
| 6523 | |
| 6524 | /* BPABI shared libraries and executables should have a PT_DYNAMIC |
| 6525 | segment. However, because the .dynamic section is not marked |
| 6526 | with SEC_LOAD, the generic ELF code will not create such a |
| 6527 | segment. */ |
| 6528 | dynsec = bfd_get_section_by_name (abfd, ".dynamic"); |
| 6529 | if (dynsec) |
| 6530 | { |
| 6531 | m = _bfd_elf_make_dynamic_segment (abfd, dynsec); |
| 6532 | m->next = elf_tdata (abfd)->segment_map; |
| 6533 | elf_tdata (abfd)->segment_map = m; |
| 6534 | } |
| 6535 | |
| 6536 | /* Also call the generic arm routine. */ |
| 6537 | return elf32_arm_modify_segment_map (abfd, info); |
| 6538 | } |
| 6539 | |
| 6540 | #undef elf32_bed |
| 6541 | #define elf32_bed elf32_arm_symbian_bed |
| 6542 | |
| 6543 | /* The dynamic sections are not allocated on SymbianOS; the postlinker |
| 6544 | will process them and then discard them. */ |
| 6545 | #undef ELF_DYNAMIC_SEC_FLAGS |
| 6546 | #define ELF_DYNAMIC_SEC_FLAGS \ |
| 6547 | (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED) |
| 6548 | |
| 6549 | #undef bfd_elf32_bfd_link_hash_table_create |
| 6550 | #define bfd_elf32_bfd_link_hash_table_create \ |
| 6551 | elf32_arm_symbian_link_hash_table_create |
| 6552 | |
| 6553 | #undef elf_backend_special_sections |
| 6554 | #define elf_backend_special_sections elf32_arm_symbian_special_sections |
| 6555 | |
| 6556 | #undef elf_backend_begin_write_processing |
| 6557 | #define elf_backend_begin_write_processing \ |
| 6558 | elf32_arm_symbian_begin_write_processing |
| 6559 | |
| 6560 | #undef elf_backend_modify_segment_map |
| 6561 | #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map |
| 6562 | |
| 6563 | /* There is no .got section for BPABI objects, and hence no header. */ |
| 6564 | #undef elf_backend_got_header_size |
| 6565 | #define elf_backend_got_header_size 0 |
| 6566 | |
| 6567 | /* Similarly, there is no .got.plt section. */ |
| 6568 | #undef elf_backend_want_got_plt |
| 6569 | #define elf_backend_want_got_plt 0 |
| 6570 | |
| 6571 | #undef elf_backend_may_use_rel_p |
| 6572 | #define elf_backend_may_use_rel_p 1 |
| 6573 | #undef elf_backend_may_use_rela_p |
| 6574 | #define elf_backend_may_use_rela_p 0 |
| 6575 | #undef elf_backend_default_use_rela_p |
| 6576 | #define elf_backend_default_use_rela_p 0 |
| 6577 | #undef elf_backend_rela_normal |
| 6578 | #define elf_backend_rela_normal 0 |
| 6579 | |
| 6580 | #include "elf32-target.h" |