1 /* FRV-specific support for 32-bit ELF. 2 Copyright (C) 2002-2014 Free Software Foundation, Inc. 3 4 This file is part of BFD, the Binary File Descriptor library. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19 MA 02110-1301, USA. */ 20 21 #include "sysdep.h" 22 #include "bfd.h" 23 #include "libbfd.h" 24 #include "elf-bfd.h" 25 #include "elf/frv.h" 26 #include "dwarf2.h" 27 #include "hashtab.h" 28 29 /* Forward declarations. */ 30 31 32 static reloc_howto_type elf32_frv_howto_table [] = 33 { 34 /* This reloc does nothing. */ 35 HOWTO (R_FRV_NONE, /* type */ 36 0, /* rightshift */ 37 2, /* size (0 = byte, 1 = short, 2 = long) */ 38 32, /* bitsize */ 39 FALSE, /* pc_relative */ 40 0, /* bitpos */ 41 complain_overflow_bitfield, /* complain_on_overflow */ 42 bfd_elf_generic_reloc, /* special_function */ 43 "R_FRV_NONE", /* name */ 44 FALSE, /* partial_inplace */ 45 0, /* src_mask */ 46 0, /* dst_mask */ 47 FALSE), /* pcrel_offset */ 48 49 /* A 32 bit absolute relocation. */ 50 HOWTO (R_FRV_32, /* type */ 51 0, /* rightshift */ 52 2, /* size (0 = byte, 1 = short, 2 = long) */ 53 32, /* bitsize */ 54 FALSE, /* pc_relative */ 55 0, /* bitpos */ 56 complain_overflow_bitfield, /* complain_on_overflow */ 57 bfd_elf_generic_reloc, /* special_function */ 58 "R_FRV_32", /* name */ 59 FALSE, /* partial_inplace */ 60 0xffffffff, /* src_mask */ 61 0xffffffff, /* dst_mask */ 62 FALSE), /* pcrel_offset */ 63 64 /* A 16 bit pc-relative relocation. */ 65 HOWTO (R_FRV_LABEL16, /* type */ 66 2, /* rightshift */ 67 2, /* size (0 = byte, 1 = short, 2 = long) */ 68 16, /* bitsize */ 69 TRUE, /* pc_relative */ 70 0, /* bitpos */ 71 complain_overflow_signed, /* complain_on_overflow */ 72 bfd_elf_generic_reloc, /* special_function */ 73 "R_FRV_LABEL16", /* name */ 74 FALSE, /* partial_inplace */ 75 0xffff, /* src_mask */ 76 0xffff, /* dst_mask */ 77 TRUE), /* pcrel_offset */ 78 79 /* A 24-bit pc-relative relocation. */ 80 HOWTO (R_FRV_LABEL24, /* type */ 81 2, /* rightshift */ 82 2, /* size (0 = byte, 1 = short, 2 = long) */ 83 26, /* bitsize */ 84 TRUE, /* pc_relative */ 85 0, /* bitpos */ 86 complain_overflow_bitfield, /* complain_on_overflow */ 87 bfd_elf_generic_reloc, /* special_function */ 88 "R_FRV_LABEL24", /* name */ 89 FALSE, /* partial_inplace */ 90 0x7e03ffff, /* src_mask */ 91 0x7e03ffff, /* dst_mask */ 92 TRUE), /* pcrel_offset */ 93 94 HOWTO (R_FRV_LO16, /* type */ 95 0, /* rightshift */ 96 2, /* size (0 = byte, 1 = short, 2 = long) */ 97 16, /* bitsize */ 98 FALSE, /* pc_relative */ 99 0, /* bitpos */ 100 complain_overflow_dont, /* complain_on_overflow */ 101 bfd_elf_generic_reloc, /* special_function */ 102 "R_FRV_LO16", /* name */ 103 FALSE, /* partial_inplace */ 104 0xffff, /* src_mask */ 105 0xffff, /* dst_mask */ 106 FALSE), /* pcrel_offset */ 107 108 HOWTO (R_FRV_HI16, /* type */ 109 0, /* rightshift */ 110 2, /* size (0 = byte, 1 = short, 2 = long) */ 111 16, /* bitsize */ 112 FALSE, /* pc_relative */ 113 0, /* bitpos */ 114 complain_overflow_dont, /* complain_on_overflow */ 115 bfd_elf_generic_reloc, /* special_function */ 116 "R_FRV_HI16", /* name */ 117 FALSE, /* partial_inplace */ 118 0xffff, /* src_mask */ 119 0xffff, /* dst_mask */ 120 FALSE), /* pcrel_offset */ 121 122 HOWTO (R_FRV_GPREL12, /* type */ 123 0, /* rightshift */ 124 2, /* size (0 = byte, 1 = short, 2 = long) */ 125 12, /* bitsize */ 126 FALSE, /* pc_relative */ 127 0, /* bitpos */ 128 complain_overflow_dont, /* complain_on_overflow */ 129 bfd_elf_generic_reloc, /* special_function */ 130 "R_FRV_GPREL12", /* name */ 131 FALSE, /* partial_inplace */ 132 0xfff, /* src_mask */ 133 0xfff, /* dst_mask */ 134 FALSE), /* pcrel_offset */ 135 136 HOWTO (R_FRV_GPRELU12, /* type */ 137 0, /* rightshift */ 138 2, /* size (0 = byte, 1 = short, 2 = long) */ 139 12, /* bitsize */ 140 FALSE, /* pc_relative */ 141 0, /* bitpos */ 142 complain_overflow_dont, /* complain_on_overflow */ 143 bfd_elf_generic_reloc, /* special_function */ 144 "R_FRV_GPRELU12", /* name */ 145 FALSE, /* partial_inplace */ 146 0xfff, /* src_mask */ 147 0x3f03f, /* dst_mask */ 148 FALSE), /* pcrel_offset */ 149 150 HOWTO (R_FRV_GPREL32, /* type */ 151 0, /* rightshift */ 152 2, /* size (0 = byte, 1 = short, 2 = long) */ 153 32, /* bitsize */ 154 FALSE, /* pc_relative */ 155 0, /* bitpos */ 156 complain_overflow_dont, /* complain_on_overflow */ 157 bfd_elf_generic_reloc, /* special_function */ 158 "R_FRV_GPREL32", /* name */ 159 FALSE, /* partial_inplace */ 160 0xffffffff, /* src_mask */ 161 0xffffffff, /* dst_mask */ 162 FALSE), /* pcrel_offset */ 163 164 HOWTO (R_FRV_GPRELHI, /* type */ 165 0, /* rightshift */ 166 2, /* size (0 = byte, 1 = short, 2 = long) */ 167 16, /* bitsize */ 168 FALSE, /* pc_relative */ 169 0, /* bitpos */ 170 complain_overflow_dont, /* complain_on_overflow */ 171 bfd_elf_generic_reloc, /* special_function */ 172 "R_FRV_GPRELHI", /* name */ 173 FALSE, /* partial_inplace */ 174 0xffff, /* src_mask */ 175 0xffff, /* dst_mask */ 176 FALSE), /* pcrel_offset */ 177 178 HOWTO (R_FRV_GPRELLO, /* type */ 179 0, /* rightshift */ 180 2, /* size (0 = byte, 1 = short, 2 = long) */ 181 16, /* bitsize */ 182 FALSE, /* pc_relative */ 183 0, /* bitpos */ 184 complain_overflow_dont, /* complain_on_overflow */ 185 bfd_elf_generic_reloc, /* special_function */ 186 "R_FRV_GPRELLO", /* name */ 187 FALSE, /* partial_inplace */ 188 0xffff, /* src_mask */ 189 0xffff, /* dst_mask */ 190 FALSE), /* pcrel_offset */ 191 192 /* A 12-bit signed operand with the GOT offset for the address of 193 the symbol. */ 194 HOWTO (R_FRV_GOT12, /* type */ 195 0, /* rightshift */ 196 2, /* size (0 = byte, 1 = short, 2 = long) */ 197 12, /* bitsize */ 198 FALSE, /* pc_relative */ 199 0, /* bitpos */ 200 complain_overflow_signed, /* complain_on_overflow */ 201 bfd_elf_generic_reloc, /* special_function */ 202 "R_FRV_GOT12", /* name */ 203 FALSE, /* partial_inplace */ 204 0xfff, /* src_mask */ 205 0xfff, /* dst_mask */ 206 FALSE), /* pcrel_offset */ 207 208 /* The upper 16 bits of the GOT offset for the address of the 209 symbol. */ 210 HOWTO (R_FRV_GOTHI, /* type */ 211 0, /* rightshift */ 212 2, /* size (0 = byte, 1 = short, 2 = long) */ 213 16, /* bitsize */ 214 FALSE, /* pc_relative */ 215 0, /* bitpos */ 216 complain_overflow_dont, /* complain_on_overflow */ 217 bfd_elf_generic_reloc, /* special_function */ 218 "R_FRV_GOTHI", /* name */ 219 FALSE, /* partial_inplace */ 220 0xffff, /* src_mask */ 221 0xffff, /* dst_mask */ 222 FALSE), /* pcrel_offset */ 223 224 /* The lower 16 bits of the GOT offset for the address of the 225 symbol. */ 226 HOWTO (R_FRV_GOTLO, /* type */ 227 0, /* rightshift */ 228 2, /* size (0 = byte, 1 = short, 2 = long) */ 229 16, /* bitsize */ 230 FALSE, /* pc_relative */ 231 0, /* bitpos */ 232 complain_overflow_dont, /* complain_on_overflow */ 233 bfd_elf_generic_reloc, /* special_function */ 234 "R_FRV_GOTLO", /* name */ 235 FALSE, /* partial_inplace */ 236 0xffff, /* src_mask */ 237 0xffff, /* dst_mask */ 238 FALSE), /* pcrel_offset */ 239 240 /* The 32-bit address of the canonical descriptor of a function. */ 241 HOWTO (R_FRV_FUNCDESC, /* type */ 242 0, /* rightshift */ 243 2, /* size (0 = byte, 1 = short, 2 = long) */ 244 32, /* bitsize */ 245 FALSE, /* pc_relative */ 246 0, /* bitpos */ 247 complain_overflow_bitfield, /* complain_on_overflow */ 248 bfd_elf_generic_reloc, /* special_function */ 249 "R_FRV_FUNCDESC", /* name */ 250 FALSE, /* partial_inplace */ 251 0xffffffff, /* src_mask */ 252 0xffffffff, /* dst_mask */ 253 FALSE), /* pcrel_offset */ 254 255 /* A 12-bit signed operand with the GOT offset for the address of 256 canonical descriptor of a function. */ 257 HOWTO (R_FRV_FUNCDESC_GOT12, /* type */ 258 0, /* rightshift */ 259 2, /* size (0 = byte, 1 = short, 2 = long) */ 260 12, /* bitsize */ 261 FALSE, /* pc_relative */ 262 0, /* bitpos */ 263 complain_overflow_signed, /* complain_on_overflow */ 264 bfd_elf_generic_reloc, /* special_function */ 265 "R_FRV_FUNCDESC_GOT12", /* name */ 266 FALSE, /* partial_inplace */ 267 0xfff, /* src_mask */ 268 0xfff, /* dst_mask */ 269 FALSE), /* pcrel_offset */ 270 271 /* The upper 16 bits of the GOT offset for the address of the 272 canonical descriptor of a function. */ 273 HOWTO (R_FRV_FUNCDESC_GOTHI, /* type */ 274 0, /* rightshift */ 275 2, /* size (0 = byte, 1 = short, 2 = long) */ 276 16, /* bitsize */ 277 FALSE, /* pc_relative */ 278 0, /* bitpos */ 279 complain_overflow_dont, /* complain_on_overflow */ 280 bfd_elf_generic_reloc, /* special_function */ 281 "R_FRV_FUNCDESC_GOTHI", /* name */ 282 FALSE, /* partial_inplace */ 283 0xffff, /* src_mask */ 284 0xffff, /* dst_mask */ 285 FALSE), /* pcrel_offset */ 286 287 /* The lower 16 bits of the GOT offset for the address of the 288 canonical descriptor of a function. */ 289 HOWTO (R_FRV_FUNCDESC_GOTLO, /* type */ 290 0, /* rightshift */ 291 2, /* size (0 = byte, 1 = short, 2 = long) */ 292 16, /* bitsize */ 293 FALSE, /* pc_relative */ 294 0, /* bitpos */ 295 complain_overflow_dont, /* complain_on_overflow */ 296 bfd_elf_generic_reloc, /* special_function */ 297 "R_FRV_FUNCDESC_GOTLO", /* name */ 298 FALSE, /* partial_inplace */ 299 0xffff, /* src_mask */ 300 0xffff, /* dst_mask */ 301 FALSE), /* pcrel_offset */ 302 303 /* The 64-bit descriptor of a function. */ 304 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */ 305 0, /* rightshift */ 306 2, /* size (0 = byte, 1 = short, 2 = long) */ 307 64, /* bitsize */ 308 FALSE, /* pc_relative */ 309 0, /* bitpos */ 310 complain_overflow_bitfield, /* complain_on_overflow */ 311 bfd_elf_generic_reloc, /* special_function */ 312 "R_FRV_FUNCDESC_VALUE", /* name */ 313 FALSE, /* partial_inplace */ 314 0xffffffff, /* src_mask */ 315 0xffffffff, /* dst_mask */ 316 FALSE), /* pcrel_offset */ 317 318 /* A 12-bit signed operand with the GOT offset for the address of 319 canonical descriptor of a function. */ 320 HOWTO (R_FRV_FUNCDESC_GOTOFF12, /* type */ 321 0, /* rightshift */ 322 2, /* size (0 = byte, 1 = short, 2 = long) */ 323 12, /* bitsize */ 324 FALSE, /* pc_relative */ 325 0, /* bitpos */ 326 complain_overflow_signed, /* complain_on_overflow */ 327 bfd_elf_generic_reloc, /* special_function */ 328 "R_FRV_FUNCDESC_GOTOFF12", /* name */ 329 FALSE, /* partial_inplace */ 330 0xfff, /* src_mask */ 331 0xfff, /* dst_mask */ 332 FALSE), /* pcrel_offset */ 333 334 /* The upper 16 bits of the GOT offset for the address of the 335 canonical descriptor of a function. */ 336 HOWTO (R_FRV_FUNCDESC_GOTOFFHI, /* type */ 337 0, /* rightshift */ 338 2, /* size (0 = byte, 1 = short, 2 = long) */ 339 16, /* bitsize */ 340 FALSE, /* pc_relative */ 341 0, /* bitpos */ 342 complain_overflow_dont, /* complain_on_overflow */ 343 bfd_elf_generic_reloc, /* special_function */ 344 "R_FRV_FUNCDESC_GOTOFFHI", /* name */ 345 FALSE, /* partial_inplace */ 346 0xffff, /* src_mask */ 347 0xffff, /* dst_mask */ 348 FALSE), /* pcrel_offset */ 349 350 /* The lower 16 bits of the GOT offset for the address of the 351 canonical descriptor of a function. */ 352 HOWTO (R_FRV_FUNCDESC_GOTOFFLO, /* type */ 353 0, /* rightshift */ 354 2, /* size (0 = byte, 1 = short, 2 = long) */ 355 16, /* bitsize */ 356 FALSE, /* pc_relative */ 357 0, /* bitpos */ 358 complain_overflow_dont, /* complain_on_overflow */ 359 bfd_elf_generic_reloc, /* special_function */ 360 "R_FRV_FUNCDESC_GOTOFFLO", /* name */ 361 FALSE, /* partial_inplace */ 362 0xffff, /* src_mask */ 363 0xffff, /* dst_mask */ 364 FALSE), /* pcrel_offset */ 365 366 /* A 12-bit signed operand with the GOT offset for the address of 367 the symbol. */ 368 HOWTO (R_FRV_GOTOFF12, /* type */ 369 0, /* rightshift */ 370 2, /* size (0 = byte, 1 = short, 2 = long) */ 371 12, /* bitsize */ 372 FALSE, /* pc_relative */ 373 0, /* bitpos */ 374 complain_overflow_signed, /* complain_on_overflow */ 375 bfd_elf_generic_reloc, /* special_function */ 376 "R_FRV_GOTOFF12", /* name */ 377 FALSE, /* partial_inplace */ 378 0xfff, /* src_mask */ 379 0xfff, /* dst_mask */ 380 FALSE), /* pcrel_offset */ 381 382 /* The upper 16 bits of the GOT offset for the address of the 383 symbol. */ 384 HOWTO (R_FRV_GOTOFFHI, /* type */ 385 0, /* rightshift */ 386 2, /* size (0 = byte, 1 = short, 2 = long) */ 387 16, /* bitsize */ 388 FALSE, /* pc_relative */ 389 0, /* bitpos */ 390 complain_overflow_dont, /* complain_on_overflow */ 391 bfd_elf_generic_reloc, /* special_function */ 392 "R_FRV_GOTOFFHI", /* name */ 393 FALSE, /* partial_inplace */ 394 0xffff, /* src_mask */ 395 0xffff, /* dst_mask */ 396 FALSE), /* pcrel_offset */ 397 398 /* The lower 16 bits of the GOT offset for the address of the 399 symbol. */ 400 HOWTO (R_FRV_GOTOFFLO, /* type */ 401 0, /* rightshift */ 402 2, /* size (0 = byte, 1 = short, 2 = long) */ 403 16, /* bitsize */ 404 FALSE, /* pc_relative */ 405 0, /* bitpos */ 406 complain_overflow_dont, /* complain_on_overflow */ 407 bfd_elf_generic_reloc, /* special_function */ 408 "R_FRV_GOTOFFLO", /* name */ 409 FALSE, /* partial_inplace */ 410 0xffff, /* src_mask */ 411 0xffff, /* dst_mask */ 412 FALSE), /* pcrel_offset */ 413 414 /* A 24-bit pc-relative relocation referencing the TLS PLT entry for 415 a thread-local symbol. If the symbol number is 0, it refers to 416 the module. */ 417 HOWTO (R_FRV_GETTLSOFF, /* type */ 418 2, /* rightshift */ 419 2, /* size (0 = byte, 1 = short, 2 = long) */ 420 26, /* bitsize */ 421 TRUE, /* pc_relative */ 422 0, /* bitpos */ 423 complain_overflow_bitfield, /* complain_on_overflow */ 424 bfd_elf_generic_reloc, /* special_function */ 425 "R_FRV_GETTLSOFF", /* name */ 426 FALSE, /* partial_inplace */ 427 0x7e03ffff, /* src_mask */ 428 0x7e03ffff, /* dst_mask */ 429 TRUE), /* pcrel_offset */ 430 431 /* A 64-bit TLS descriptor for a symbol. This relocation is only 432 valid as a REL, dynamic relocation. */ 433 HOWTO (R_FRV_TLSDESC_VALUE, /* type */ 434 0, /* rightshift */ 435 2, /* size (0 = byte, 1 = short, 2 = long) */ 436 64, /* bitsize */ 437 FALSE, /* pc_relative */ 438 0, /* bitpos */ 439 complain_overflow_bitfield, /* complain_on_overflow */ 440 bfd_elf_generic_reloc, /* special_function */ 441 "R_FRV_TLSDESC_VALUE", /* name */ 442 FALSE, /* partial_inplace */ 443 0xffffffff, /* src_mask */ 444 0xffffffff, /* dst_mask */ 445 FALSE), /* pcrel_offset */ 446 447 /* A 12-bit signed operand with the GOT offset for the TLS 448 descriptor of the symbol. */ 449 HOWTO (R_FRV_GOTTLSDESC12, /* type */ 450 0, /* rightshift */ 451 2, /* size (0 = byte, 1 = short, 2 = long) */ 452 12, /* bitsize */ 453 FALSE, /* pc_relative */ 454 0, /* bitpos */ 455 complain_overflow_signed, /* complain_on_overflow */ 456 bfd_elf_generic_reloc, /* special_function */ 457 "R_FRV_GOTTLSDESC12", /* name */ 458 FALSE, /* partial_inplace */ 459 0xfff, /* src_mask */ 460 0xfff, /* dst_mask */ 461 FALSE), /* pcrel_offset */ 462 463 /* The upper 16 bits of the GOT offset for the TLS descriptor of the 464 symbol. */ 465 HOWTO (R_FRV_GOTTLSDESCHI, /* type */ 466 0, /* rightshift */ 467 2, /* size (0 = byte, 1 = short, 2 = long) */ 468 16, /* bitsize */ 469 FALSE, /* pc_relative */ 470 0, /* bitpos */ 471 complain_overflow_dont, /* complain_on_overflow */ 472 bfd_elf_generic_reloc, /* special_function */ 473 "R_FRV_GOTTLSDESCHI", /* name */ 474 FALSE, /* partial_inplace */ 475 0xffff, /* src_mask */ 476 0xffff, /* dst_mask */ 477 FALSE), /* pcrel_offset */ 478 479 /* The lower 16 bits of the GOT offset for the TLS descriptor of the 480 symbol. */ 481 HOWTO (R_FRV_GOTTLSDESCLO, /* type */ 482 0, /* rightshift */ 483 2, /* size (0 = byte, 1 = short, 2 = long) */ 484 16, /* bitsize */ 485 FALSE, /* pc_relative */ 486 0, /* bitpos */ 487 complain_overflow_dont, /* complain_on_overflow */ 488 bfd_elf_generic_reloc, /* special_function */ 489 "R_FRV_GOTTLSDESCLO", /* name */ 490 FALSE, /* partial_inplace */ 491 0xffff, /* src_mask */ 492 0xffff, /* dst_mask */ 493 FALSE), /* pcrel_offset */ 494 495 /* A 12-bit signed operand with the offset from the module base 496 address to the thread-local symbol address. */ 497 HOWTO (R_FRV_TLSMOFF12, /* type */ 498 0, /* rightshift */ 499 2, /* size (0 = byte, 1 = short, 2 = long) */ 500 12, /* bitsize */ 501 FALSE, /* pc_relative */ 502 0, /* bitpos */ 503 complain_overflow_signed, /* complain_on_overflow */ 504 bfd_elf_generic_reloc, /* special_function */ 505 "R_FRV_TLSMOFF12", /* name */ 506 FALSE, /* partial_inplace */ 507 0xfff, /* src_mask */ 508 0xfff, /* dst_mask */ 509 FALSE), /* pcrel_offset */ 510 511 /* The upper 16 bits of the offset from the module base address to 512 the thread-local symbol address. */ 513 HOWTO (R_FRV_TLSMOFFHI, /* type */ 514 0, /* rightshift */ 515 2, /* size (0 = byte, 1 = short, 2 = long) */ 516 16, /* bitsize */ 517 FALSE, /* pc_relative */ 518 0, /* bitpos */ 519 complain_overflow_dont, /* complain_on_overflow */ 520 bfd_elf_generic_reloc, /* special_function */ 521 "R_FRV_TLSMOFFHI", /* name */ 522 FALSE, /* partial_inplace */ 523 0xffff, /* src_mask */ 524 0xffff, /* dst_mask */ 525 FALSE), /* pcrel_offset */ 526 527 /* The lower 16 bits of the offset from the module base address to 528 the thread-local symbol address. */ 529 HOWTO (R_FRV_TLSMOFFLO, /* type */ 530 0, /* rightshift */ 531 2, /* size (0 = byte, 1 = short, 2 = long) */ 532 16, /* bitsize */ 533 FALSE, /* pc_relative */ 534 0, /* bitpos */ 535 complain_overflow_dont, /* complain_on_overflow */ 536 bfd_elf_generic_reloc, /* special_function */ 537 "R_FRV_TLSMOFFLO", /* name */ 538 FALSE, /* partial_inplace */ 539 0xffff, /* src_mask */ 540 0xffff, /* dst_mask */ 541 FALSE), /* pcrel_offset */ 542 543 /* A 12-bit signed operand with the GOT offset for the TLSOFF entry 544 for a symbol. */ 545 HOWTO (R_FRV_GOTTLSOFF12, /* type */ 546 0, /* rightshift */ 547 2, /* size (0 = byte, 1 = short, 2 = long) */ 548 12, /* bitsize */ 549 FALSE, /* pc_relative */ 550 0, /* bitpos */ 551 complain_overflow_signed, /* complain_on_overflow */ 552 bfd_elf_generic_reloc, /* special_function */ 553 "R_FRV_GOTTLSOFF12", /* name */ 554 FALSE, /* partial_inplace */ 555 0xfff, /* src_mask */ 556 0xfff, /* dst_mask */ 557 FALSE), /* pcrel_offset */ 558 559 /* The upper 16 bits of the GOT offset for the TLSOFF entry for a 560 symbol. */ 561 HOWTO (R_FRV_GOTTLSOFFHI, /* type */ 562 0, /* rightshift */ 563 2, /* size (0 = byte, 1 = short, 2 = long) */ 564 16, /* bitsize */ 565 FALSE, /* pc_relative */ 566 0, /* bitpos */ 567 complain_overflow_dont, /* complain_on_overflow */ 568 bfd_elf_generic_reloc, /* special_function */ 569 "R_FRV_GOTTLSOFFHI", /* name */ 570 FALSE, /* partial_inplace */ 571 0xffff, /* src_mask */ 572 0xffff, /* dst_mask */ 573 FALSE), /* pcrel_offset */ 574 575 /* The lower 16 bits of the GOT offset for the TLSOFF entry for a 576 symbol. */ 577 HOWTO (R_FRV_GOTTLSOFFLO, /* type */ 578 0, /* rightshift */ 579 2, /* size (0 = byte, 1 = short, 2 = long) */ 580 16, /* bitsize */ 581 FALSE, /* pc_relative */ 582 0, /* bitpos */ 583 complain_overflow_dont, /* complain_on_overflow */ 584 bfd_elf_generic_reloc, /* special_function */ 585 "R_FRV_GOTTLSOFFLO", /* name */ 586 FALSE, /* partial_inplace */ 587 0xffff, /* src_mask */ 588 0xffff, /* dst_mask */ 589 FALSE), /* pcrel_offset */ 590 591 /* The 32-bit offset from the thread pointer (not the module base 592 address) to a thread-local symbol. */ 593 HOWTO (R_FRV_TLSOFF, /* type */ 594 0, /* rightshift */ 595 2, /* size (0 = byte, 1 = short, 2 = long) */ 596 32, /* bitsize */ 597 FALSE, /* pc_relative */ 598 0, /* bitpos */ 599 complain_overflow_dont, /* complain_on_overflow */ 600 bfd_elf_generic_reloc, /* special_function */ 601 "R_FRV_TLSOFF", /* name */ 602 FALSE, /* partial_inplace */ 603 0xffffffff, /* src_mask */ 604 0xffffffff, /* dst_mask */ 605 FALSE), /* pcrel_offset */ 606 607 /* An annotation for linker relaxation, that denotes the 608 symbol+addend whose TLS descriptor is referenced by the sum of 609 the two input registers of an ldd instruction. */ 610 HOWTO (R_FRV_TLSDESC_RELAX, /* type */ 611 0, /* rightshift */ 612 2, /* size (0 = byte, 1 = short, 2 = long) */ 613 0, /* bitsize */ 614 FALSE, /* pc_relative */ 615 0, /* bitpos */ 616 complain_overflow_dont, /* complain_on_overflow */ 617 bfd_elf_generic_reloc, /* special_function */ 618 "R_FRV_TLSDESC_RELAX", /* name */ 619 FALSE, /* partial_inplace */ 620 0, /* src_mask */ 621 0, /* dst_mask */ 622 FALSE), /* pcrel_offset */ 623 624 /* An annotation for linker relaxation, that denotes the 625 symbol+addend whose TLS resolver entry point is given by the sum 626 of the two register operands of an calll instruction. */ 627 HOWTO (R_FRV_GETTLSOFF_RELAX, /* type */ 628 0, /* rightshift */ 629 2, /* size (0 = byte, 1 = short, 2 = long) */ 630 0, /* bitsize */ 631 FALSE, /* pc_relative */ 632 0, /* bitpos */ 633 complain_overflow_dont, /* complain_on_overflow */ 634 bfd_elf_generic_reloc, /* special_function */ 635 "R_FRV_GETTLSOFF_RELAX", /* name */ 636 FALSE, /* partial_inplace */ 637 0, /* src_mask */ 638 0, /* dst_mask */ 639 FALSE), /* pcrel_offset */ 640 641 /* An annotation for linker relaxation, that denotes the 642 symbol+addend whose TLS offset GOT entry is given by the sum of 643 the two input registers of an ld instruction. */ 644 HOWTO (R_FRV_TLSOFF_RELAX, /* type */ 645 0, /* rightshift */ 646 2, /* size (0 = byte, 1 = short, 2 = long) */ 647 0, /* bitsize */ 648 FALSE, /* pc_relative */ 649 0, /* bitpos */ 650 complain_overflow_bitfield, /* complain_on_overflow */ 651 bfd_elf_generic_reloc, /* special_function */ 652 "R_FRV_TLSOFF_RELAX", /* name */ 653 FALSE, /* partial_inplace */ 654 0, /* src_mask */ 655 0, /* dst_mask */ 656 FALSE), /* pcrel_offset */ 657 658 /* A 32-bit offset from the module base address to 659 the thread-local symbol address. */ 660 HOWTO (R_FRV_TLSMOFF, /* type */ 661 0, /* rightshift */ 662 2, /* size (0 = byte, 1 = short, 2 = long) */ 663 32, /* bitsize */ 664 FALSE, /* pc_relative */ 665 0, /* bitpos */ 666 complain_overflow_dont, /* complain_on_overflow */ 667 bfd_elf_generic_reloc, /* special_function */ 668 "R_FRV_TLSMOFF", /* name */ 669 FALSE, /* partial_inplace */ 670 0xffffffff, /* src_mask */ 671 0xffffffff, /* dst_mask */ 672 FALSE), /* pcrel_offset */ 673 }; 674 675 /* GNU extension to record C++ vtable hierarchy. */ 676 static reloc_howto_type elf32_frv_vtinherit_howto = 677 HOWTO (R_FRV_GNU_VTINHERIT, /* type */ 678 0, /* rightshift */ 679 2, /* size (0 = byte, 1 = short, 2 = long) */ 680 0, /* bitsize */ 681 FALSE, /* pc_relative */ 682 0, /* bitpos */ 683 complain_overflow_dont, /* complain_on_overflow */ 684 NULL, /* special_function */ 685 "R_FRV_GNU_VTINHERIT", /* name */ 686 FALSE, /* partial_inplace */ 687 0, /* src_mask */ 688 0, /* dst_mask */ 689 FALSE); /* pcrel_offset */ 690 691 /* GNU extension to record C++ vtable member usage. */ 692 static reloc_howto_type elf32_frv_vtentry_howto = 693 HOWTO (R_FRV_GNU_VTENTRY, /* type */ 694 0, /* rightshift */ 695 2, /* size (0 = byte, 1 = short, 2 = long) */ 696 0, /* bitsize */ 697 FALSE, /* pc_relative */ 698 0, /* bitpos */ 699 complain_overflow_dont, /* complain_on_overflow */ 700 _bfd_elf_rel_vtable_reloc_fn, /* special_function */ 701 "R_FRV_GNU_VTENTRY", /* name */ 702 FALSE, /* partial_inplace */ 703 0, /* src_mask */ 704 0, /* dst_mask */ 705 FALSE); /* pcrel_offset */ 706 707 /* The following 3 relocations are REL. The only difference to the 708 entries in the table above are that partial_inplace is TRUE. */ 709 static reloc_howto_type elf32_frv_rel_32_howto = 710 HOWTO (R_FRV_32, /* type */ 711 0, /* rightshift */ 712 2, /* size (0 = byte, 1 = short, 2 = long) */ 713 32, /* bitsize */ 714 FALSE, /* pc_relative */ 715 0, /* bitpos */ 716 complain_overflow_bitfield, /* complain_on_overflow */ 717 bfd_elf_generic_reloc, /* special_function */ 718 "R_FRV_32", /* name */ 719 TRUE, /* partial_inplace */ 720 0xffffffff, /* src_mask */ 721 0xffffffff, /* dst_mask */ 722 FALSE); /* pcrel_offset */ 723 724 static reloc_howto_type elf32_frv_rel_funcdesc_howto = 725 HOWTO (R_FRV_FUNCDESC, /* type */ 726 0, /* rightshift */ 727 2, /* size (0 = byte, 1 = short, 2 = long) */ 728 32, /* bitsize */ 729 FALSE, /* pc_relative */ 730 0, /* bitpos */ 731 complain_overflow_bitfield, /* complain_on_overflow */ 732 bfd_elf_generic_reloc, /* special_function */ 733 "R_FRV_FUNCDESC", /* name */ 734 TRUE, /* partial_inplace */ 735 0xffffffff, /* src_mask */ 736 0xffffffff, /* dst_mask */ 737 FALSE); /* pcrel_offset */ 738 739 static reloc_howto_type elf32_frv_rel_funcdesc_value_howto = 740 HOWTO (R_FRV_FUNCDESC_VALUE, /* type */ 741 0, /* rightshift */ 742 2, /* size (0 = byte, 1 = short, 2 = long) */ 743 64, /* bitsize */ 744 FALSE, /* pc_relative */ 745 0, /* bitpos */ 746 complain_overflow_bitfield, /* complain_on_overflow */ 747 bfd_elf_generic_reloc, /* special_function */ 748 "R_FRV_FUNCDESC_VALUE", /* name */ 749 TRUE, /* partial_inplace */ 750 0xffffffff, /* src_mask */ 751 0xffffffff, /* dst_mask */ 752 FALSE); /* pcrel_offset */ 753 754 static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto = 755 /* A 64-bit TLS descriptor for a symbol. The first word resolves to 756 an entry point, and the second resolves to a special argument. 757 If the symbol turns out to be in static TLS, the entry point is a 758 return instruction, and the special argument is the TLS offset 759 for the symbol. If it's in dynamic TLS, the entry point is a TLS 760 offset resolver, and the special argument is a pointer to a data 761 structure allocated by the dynamic loader, containing the GOT 762 address for the offset resolver, the module id, the offset within 763 the module, and anything else the TLS offset resolver might need 764 to determine the TLS offset for the symbol in the running 765 thread. */ 766 HOWTO (R_FRV_TLSDESC_VALUE, /* type */ 767 0, /* rightshift */ 768 2, /* size (0 = byte, 1 = short, 2 = long) */ 769 64, /* bitsize */ 770 FALSE, /* pc_relative */ 771 0, /* bitpos */ 772 complain_overflow_bitfield, /* complain_on_overflow */ 773 bfd_elf_generic_reloc, /* special_function */ 774 "R_FRV_TLSDESC_VALUE", /* name */ 775 TRUE, /* partial_inplace */ 776 0xffffffff, /* src_mask */ 777 0xffffffff, /* dst_mask */ 778 FALSE); /* pcrel_offset */ 779 780 static reloc_howto_type elf32_frv_rel_tlsoff_howto = 781 /* The 32-bit offset from the thread pointer (not the module base 782 address) to a thread-local symbol. */ 783 HOWTO (R_FRV_TLSOFF, /* type */ 784 0, /* rightshift */ 785 2, /* size (0 = byte, 1 = short, 2 = long) */ 786 32, /* bitsize */ 787 FALSE, /* pc_relative */ 788 0, /* bitpos */ 789 complain_overflow_bitfield, /* complain_on_overflow */ 790 bfd_elf_generic_reloc, /* special_function */ 791 "R_FRV_TLSOFF", /* name */ 792 TRUE, /* partial_inplace */ 793 0xffffffff, /* src_mask */ 794 0xffffffff, /* dst_mask */ 795 FALSE); /* pcrel_offset */ 796 797 798 799 extern const bfd_target frv_elf32_fdpic_vec; 801 #define IS_FDPIC(bfd) ((bfd)->xvec == &frv_elf32_fdpic_vec) 802 803 /* An extension of the elf hash table data structure, containing some 804 additional FRV-specific data. */ 805 struct frvfdpic_elf_link_hash_table 806 { 807 struct elf_link_hash_table elf; 808 809 /* A pointer to the .got section. */ 810 asection *sgot; 811 /* A pointer to the .rel.got section. */ 812 asection *sgotrel; 813 /* A pointer to the .rofixup section. */ 814 asection *sgotfixup; 815 /* A pointer to the .plt section. */ 816 asection *splt; 817 /* A pointer to the .rel.plt section. */ 818 asection *spltrel; 819 /* GOT base offset. */ 820 bfd_vma got0; 821 /* Location of the first non-lazy PLT entry, i.e., the number of 822 bytes taken by lazy PLT entries. If locally-bound TLS 823 descriptors require a ret instruction, it will be placed at this 824 offset. */ 825 bfd_vma plt0; 826 /* A hash table holding information about which symbols were 827 referenced with which PIC-related relocations. */ 828 struct htab *relocs_info; 829 /* Summary reloc information collected by 830 _frvfdpic_count_got_plt_entries. */ 831 struct _frvfdpic_dynamic_got_info *g; 832 }; 833 834 /* Get the FRV ELF linker hash table from a link_info structure. */ 835 836 #define frvfdpic_hash_table(p) \ 837 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ 838 == FRV_ELF_DATA ? ((struct frvfdpic_elf_link_hash_table *) ((p)->hash)) : NULL) 839 840 #define frvfdpic_got_section(info) \ 841 (frvfdpic_hash_table (info)->sgot) 842 #define frvfdpic_gotrel_section(info) \ 843 (frvfdpic_hash_table (info)->sgotrel) 844 #define frvfdpic_gotfixup_section(info) \ 845 (frvfdpic_hash_table (info)->sgotfixup) 846 #define frvfdpic_plt_section(info) \ 847 (frvfdpic_hash_table (info)->splt) 848 #define frvfdpic_pltrel_section(info) \ 849 (frvfdpic_hash_table (info)->spltrel) 850 #define frvfdpic_relocs_info(info) \ 851 (frvfdpic_hash_table (info)->relocs_info) 852 #define frvfdpic_got_initial_offset(info) \ 853 (frvfdpic_hash_table (info)->got0) 854 #define frvfdpic_plt_initial_offset(info) \ 855 (frvfdpic_hash_table (info)->plt0) 856 #define frvfdpic_dynamic_got_plt_info(info) \ 857 (frvfdpic_hash_table (info)->g) 858 859 /* Currently it's the same, but if some day we have a reason to change 860 it, we'd better be using a different macro. 861 862 FIXME: if there's any TLS PLT entry that uses local-exec or 863 initial-exec models, we could use the ret at the end of any of them 864 instead of adding one more. */ 865 #define frvfdpic_plt_tls_ret_offset(info) \ 866 (frvfdpic_plt_initial_offset (info)) 867 868 /* The name of the dynamic interpreter. This is put in the .interp 869 section. */ 870 871 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" 872 873 #define DEFAULT_STACK_SIZE 0x20000 874 875 /* This structure is used to collect the number of entries present in 876 each addressable range of the got. */ 877 struct _frvfdpic_dynamic_got_info 878 { 879 /* Several bits of information about the current link. */ 880 struct bfd_link_info *info; 881 /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit 882 ranges. */ 883 bfd_vma got12, gotlos, gothilo; 884 /* Total GOT size needed for function descriptor entries within the 12-, 885 16- or 32-bit ranges. */ 886 bfd_vma fd12, fdlos, fdhilo; 887 /* Total GOT size needed by function descriptor entries referenced 888 in PLT entries, that would be profitable to place in offsets 889 close to the PIC register. */ 890 bfd_vma fdplt; 891 /* Total PLT size needed by lazy PLT entries. */ 892 bfd_vma lzplt; 893 /* Total GOT size needed for TLS descriptor entries within the 12-, 894 16- or 32-bit ranges. */ 895 bfd_vma tlsd12, tlsdlos, tlsdhilo; 896 /* Total GOT size needed by TLS descriptors referenced in PLT 897 entries, that would be profitable to place in offers close to the 898 PIC register. */ 899 bfd_vma tlsdplt; 900 /* Total PLT size needed by TLS lazy PLT entries. */ 901 bfd_vma tlslzplt; 902 /* Number of relocations carried over from input object files. */ 903 unsigned long relocs; 904 /* Number of fixups introduced by relocations in input object files. */ 905 unsigned long fixups; 906 /* The number of fixups that reference the ret instruction added to 907 the PLT for locally-resolved TLS descriptors. */ 908 unsigned long tls_ret_refs; 909 }; 910 911 /* This structure is used to assign offsets to got entries, function 912 descriptors, plt entries and lazy plt entries. */ 913 914 struct _frvfdpic_dynamic_got_plt_info 915 { 916 /* Summary information collected with _frvfdpic_count_got_plt_entries. */ 917 struct _frvfdpic_dynamic_got_info g; 918 919 /* For each addressable range, we record a MAX (positive) and MIN 920 (negative) value. CUR is used to assign got entries, and it's 921 incremented from an initial positive value to MAX, then from MIN 922 to FDCUR (unless FDCUR wraps around first). FDCUR is used to 923 assign function descriptors, and it's decreased from an initial 924 non-positive value to MIN, then from MAX down to CUR (unless CUR 925 wraps around first). All of MIN, MAX, CUR and FDCUR always point 926 to even words. ODD, if non-zero, indicates an odd word to be 927 used for the next got entry, otherwise CUR is used and 928 incremented by a pair of words, wrapping around when it reaches 929 MAX. FDCUR is decremented (and wrapped) before the next function 930 descriptor is chosen. FDPLT indicates the number of remaining 931 slots that can be used for function descriptors used only by PLT 932 entries. 933 934 TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR 935 starts as MAX, and grows up to TMAX, then wraps around to TMIN 936 and grows up to MIN. TLSDPLT indicates the number of remaining 937 slots that can be used for TLS descriptors used only by TLS PLT 938 entries. */ 939 struct _frvfdpic_dynamic_got_alloc_data 940 { 941 bfd_signed_vma max, cur, odd, fdcur, min; 942 bfd_signed_vma tmax, tcur, tmin; 943 bfd_vma fdplt, tlsdplt; 944 } got12, gotlos, gothilo; 945 }; 946 947 /* Create an FRV ELF linker hash table. */ 948 949 static struct bfd_link_hash_table * 950 frvfdpic_elf_link_hash_table_create (bfd *abfd) 951 { 952 struct frvfdpic_elf_link_hash_table *ret; 953 bfd_size_type amt = sizeof (struct frvfdpic_elf_link_hash_table); 954 955 ret = bfd_zmalloc (amt); 956 if (ret == NULL) 957 return NULL; 958 959 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, 960 _bfd_elf_link_hash_newfunc, 961 sizeof (struct elf_link_hash_entry), 962 FRV_ELF_DATA)) 963 { 964 free (ret); 965 return NULL; 966 } 967 968 return &ret->elf.root; 969 } 970 971 /* Decide whether a reference to a symbol can be resolved locally or 972 not. If the symbol is protected, we want the local address, but 973 its function descriptor must be assigned by the dynamic linker. */ 974 #define FRVFDPIC_SYM_LOCAL(INFO, H) \ 975 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \ 976 || ! elf_hash_table (INFO)->dynamic_sections_created) 977 #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \ 978 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created) 979 980 /* This structure collects information on what kind of GOT, PLT or 981 function descriptors are required by relocations that reference a 982 certain symbol. */ 983 struct frvfdpic_relocs_info 984 { 985 /* The index of the symbol, as stored in the relocation r_info, if 986 we have a local symbol; -1 otherwise. */ 987 long symndx; 988 union 989 { 990 /* The input bfd in which the symbol is defined, if it's a local 991 symbol. */ 992 bfd *abfd; 993 /* If symndx == -1, the hash table entry corresponding to a global 994 symbol (even if it turns out to bind locally, in which case it 995 should ideally be replaced with section's symndx + addend). */ 996 struct elf_link_hash_entry *h; 997 } d; 998 /* The addend of the relocation that references the symbol. */ 999 bfd_vma addend; 1000 1001 /* The fields above are used to identify an entry. The fields below 1002 contain information on how an entry is used and, later on, which 1003 locations it was assigned. */ 1004 /* The following 3 fields record whether the symbol+addend above was 1005 ever referenced with a GOT relocation. The 12 suffix indicates a 1006 GOT12 relocation; los is used for GOTLO relocations that are not 1007 matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI 1008 pairs. */ 1009 unsigned got12:1; 1010 unsigned gotlos:1; 1011 unsigned gothilo:1; 1012 /* Whether a FUNCDESC relocation references symbol+addend. */ 1013 unsigned fd:1; 1014 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */ 1015 unsigned fdgot12:1; 1016 unsigned fdgotlos:1; 1017 unsigned fdgothilo:1; 1018 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */ 1019 unsigned fdgoff12:1; 1020 unsigned fdgofflos:1; 1021 unsigned fdgoffhilo:1; 1022 /* Whether a GETTLSOFF relocation references symbol+addend. */ 1023 unsigned tlsplt:1; 1024 /* FIXME: we should probably add tlspltdesc, tlspltoff and 1025 tlspltimm, to tell what kind of TLS PLT entry we're generating. 1026 We might instead just pre-compute flags telling whether the 1027 object is suitable for local exec, initial exec or general 1028 dynamic addressing, and use that all over the place. We could 1029 also try to do a better job of merging TLSOFF and TLSDESC entries 1030 in main executables, but perhaps we can get rid of TLSDESC 1031 entirely in them instead. */ 1032 /* Whether a GOTTLSDESC relocation references symbol+addend. */ 1033 unsigned tlsdesc12:1; 1034 unsigned tlsdesclos:1; 1035 unsigned tlsdeschilo:1; 1036 /* Whether a GOTTLSOFF relocation references symbol+addend. */ 1037 unsigned tlsoff12:1; 1038 unsigned tlsofflos:1; 1039 unsigned tlsoffhilo:1; 1040 /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or 1041 GOTOFFHI relocations. The addend doesn't really matter, since we 1042 envision that this will only be used to check whether the symbol 1043 is mapped to the same segment as the got. */ 1044 unsigned gotoff:1; 1045 /* Whether symbol+addend is referenced by a LABEL24 relocation. */ 1046 unsigned call:1; 1047 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE 1048 relocation. */ 1049 unsigned sym:1; 1050 /* Whether we need a PLT entry for a symbol. Should be implied by 1051 something like: 1052 (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */ 1053 unsigned plt:1; 1054 /* Whether a function descriptor should be created in this link unit 1055 for symbol+addend. Should be implied by something like: 1056 (plt || fdgotoff12 || fdgotofflos || fdgotofflohi 1057 || ((fd || fdgot12 || fdgotlos || fdgothilo) 1058 && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */ 1059 unsigned privfd:1; 1060 /* Whether a lazy PLT entry is needed for this symbol+addend. 1061 Should be implied by something like: 1062 (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h) 1063 && ! (info->flags & DF_BIND_NOW)) */ 1064 unsigned lazyplt:1; 1065 /* Whether we've already emitted GOT relocations and PLT entries as 1066 needed for this symbol. */ 1067 unsigned done:1; 1068 1069 /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and 1070 R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing 1071 symbol+addend. */ 1072 unsigned relocs32, relocsfd, relocsfdv, relocstlsd, relocstlsoff; 1073 1074 /* The number of .rofixups entries and dynamic relocations allocated 1075 for this symbol, minus any that might have already been used. */ 1076 unsigned fixups, dynrelocs; 1077 1078 /* The offsets of the GOT entries assigned to symbol+addend, to the 1079 function descriptor's address, and to a function descriptor, 1080 respectively. Should be zero if unassigned. The offsets are 1081 counted from the value that will be assigned to the PIC register, 1082 not from the beginning of the .got section. */ 1083 bfd_signed_vma got_entry, fdgot_entry, fd_entry; 1084 /* The offsets of the PLT entries assigned to symbol+addend, 1085 non-lazy and lazy, respectively. If unassigned, should be 1086 (bfd_vma)-1. */ 1087 bfd_vma plt_entry, lzplt_entry; 1088 /* The offsets of the GOT entries for TLS offset and TLS descriptor. */ 1089 bfd_signed_vma tlsoff_entry, tlsdesc_entry; 1090 /* The offset of the TLS offset PLT entry. */ 1091 bfd_vma tlsplt_entry; 1092 }; 1093 1094 /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */ 1095 static hashval_t 1096 frvfdpic_relocs_info_hash (const void *entry_) 1097 { 1098 const struct frvfdpic_relocs_info *entry = entry_; 1099 1100 return (entry->symndx == -1 1101 ? (long) entry->d.h->root.root.hash 1102 : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend; 1103 } 1104 1105 /* Test whether the key fields of two frvfdpic_relocs_info entries are 1106 identical. */ 1107 static int 1108 frvfdpic_relocs_info_eq (const void *entry1, const void *entry2) 1109 { 1110 const struct frvfdpic_relocs_info *e1 = entry1; 1111 const struct frvfdpic_relocs_info *e2 = entry2; 1112 1113 return e1->symndx == e2->symndx && e1->addend == e2->addend 1114 && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd); 1115 } 1116 1117 /* Find or create an entry in a hash table HT that matches the key 1118 fields of the given ENTRY. If it's not found, memory for a new 1119 entry is allocated in ABFD's obstack. */ 1120 static struct frvfdpic_relocs_info * 1121 frvfdpic_relocs_info_find (struct htab *ht, 1122 bfd *abfd, 1123 const struct frvfdpic_relocs_info *entry, 1124 enum insert_option insert) 1125 { 1126 struct frvfdpic_relocs_info **loc = 1127 (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert); 1128 1129 if (! loc) 1130 return NULL; 1131 1132 if (*loc) 1133 return *loc; 1134 1135 *loc = bfd_zalloc (abfd, sizeof (**loc)); 1136 1137 if (! *loc) 1138 return *loc; 1139 1140 (*loc)->symndx = entry->symndx; 1141 (*loc)->d = entry->d; 1142 (*loc)->addend = entry->addend; 1143 (*loc)->plt_entry = (bfd_vma)-1; 1144 (*loc)->lzplt_entry = (bfd_vma)-1; 1145 (*loc)->tlsplt_entry = (bfd_vma)-1; 1146 1147 return *loc; 1148 } 1149 1150 /* Obtain the address of the entry in HT associated with H's symbol + 1151 addend, creating a new entry if none existed. ABFD is only used 1152 for memory allocation purposes. */ 1153 inline static struct frvfdpic_relocs_info * 1154 frvfdpic_relocs_info_for_global (struct htab *ht, 1155 bfd *abfd, 1156 struct elf_link_hash_entry *h, 1157 bfd_vma addend, 1158 enum insert_option insert) 1159 { 1160 struct frvfdpic_relocs_info entry; 1161 1162 entry.symndx = -1; 1163 entry.d.h = h; 1164 entry.addend = addend; 1165 1166 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert); 1167 } 1168 1169 /* Obtain the address of the entry in HT associated with the SYMNDXth 1170 local symbol of the input bfd ABFD, plus the addend, creating a new 1171 entry if none existed. */ 1172 inline static struct frvfdpic_relocs_info * 1173 frvfdpic_relocs_info_for_local (struct htab *ht, 1174 bfd *abfd, 1175 long symndx, 1176 bfd_vma addend, 1177 enum insert_option insert) 1178 { 1179 struct frvfdpic_relocs_info entry; 1180 1181 entry.symndx = symndx; 1182 entry.d.abfd = abfd; 1183 entry.addend = addend; 1184 1185 return frvfdpic_relocs_info_find (ht, abfd, &entry, insert); 1186 } 1187 1188 /* Merge fields set by check_relocs() of two entries that end up being 1189 mapped to the same (presumably global) symbol. */ 1190 1191 inline static void 1192 frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2, 1193 struct frvfdpic_relocs_info const *e1) 1194 { 1195 e2->got12 |= e1->got12; 1196 e2->gotlos |= e1->gotlos; 1197 e2->gothilo |= e1->gothilo; 1198 e2->fd |= e1->fd; 1199 e2->fdgot12 |= e1->fdgot12; 1200 e2->fdgotlos |= e1->fdgotlos; 1201 e2->fdgothilo |= e1->fdgothilo; 1202 e2->fdgoff12 |= e1->fdgoff12; 1203 e2->fdgofflos |= e1->fdgofflos; 1204 e2->fdgoffhilo |= e1->fdgoffhilo; 1205 e2->tlsplt |= e1->tlsplt; 1206 e2->tlsdesc12 |= e1->tlsdesc12; 1207 e2->tlsdesclos |= e1->tlsdesclos; 1208 e2->tlsdeschilo |= e1->tlsdeschilo; 1209 e2->tlsoff12 |= e1->tlsoff12; 1210 e2->tlsofflos |= e1->tlsofflos; 1211 e2->tlsoffhilo |= e1->tlsoffhilo; 1212 e2->gotoff |= e1->gotoff; 1213 e2->call |= e1->call; 1214 e2->sym |= e1->sym; 1215 } 1216 1217 /* Every block of 65535 lazy PLT entries shares a single call to the 1218 resolver, inserted in the 32768th lazy PLT entry (i.e., entry # 1219 32767, counting from 0). All other lazy PLT entries branch to it 1220 in a single instruction. */ 1221 1222 #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4) 1223 #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767) 1224 1225 /* Add a dynamic relocation to the SRELOC section. */ 1226 1227 inline static bfd_vma 1228 _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset, 1229 int reloc_type, long dynindx, bfd_vma addend, 1230 struct frvfdpic_relocs_info *entry) 1231 { 1232 Elf_Internal_Rela outrel; 1233 bfd_vma reloc_offset; 1234 1235 outrel.r_offset = offset; 1236 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type); 1237 outrel.r_addend = addend; 1238 1239 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel); 1240 BFD_ASSERT (reloc_offset < sreloc->size); 1241 bfd_elf32_swap_reloc_out (output_bfd, &outrel, 1242 sreloc->contents + reloc_offset); 1243 sreloc->reloc_count++; 1244 1245 /* If the entry's index is zero, this relocation was probably to a 1246 linkonce section that got discarded. We reserved a dynamic 1247 relocation, but it was for another entry than the one we got at 1248 the time of emitting the relocation. Unfortunately there's no 1249 simple way for us to catch this situation, since the relocation 1250 is cleared right before calling relocate_section, at which point 1251 we no longer know what the relocation used to point to. */ 1252 if (entry->symndx) 1253 { 1254 BFD_ASSERT (entry->dynrelocs > 0); 1255 entry->dynrelocs--; 1256 } 1257 1258 return reloc_offset; 1259 } 1260 1261 /* Add a fixup to the ROFIXUP section. */ 1262 1263 static bfd_vma 1264 _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset, 1265 struct frvfdpic_relocs_info *entry) 1266 { 1267 bfd_vma fixup_offset; 1268 1269 if (rofixup->flags & SEC_EXCLUDE) 1270 return -1; 1271 1272 fixup_offset = rofixup->reloc_count * 4; 1273 if (rofixup->contents) 1274 { 1275 BFD_ASSERT (fixup_offset < rofixup->size); 1276 bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset); 1277 } 1278 rofixup->reloc_count++; 1279 1280 if (entry && entry->symndx) 1281 { 1282 /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc 1283 above. */ 1284 BFD_ASSERT (entry->fixups > 0); 1285 entry->fixups--; 1286 } 1287 1288 return fixup_offset; 1289 } 1290 1291 /* Find the segment number in which OSEC, and output section, is 1292 located. */ 1293 1294 static unsigned 1295 _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec) 1296 { 1297 Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec); 1298 1299 return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1; 1300 } 1301 1302 inline static bfd_boolean 1303 _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec) 1304 { 1305 unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec); 1306 1307 return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W); 1308 } 1309 1310 #define FRVFDPIC_TLS_BIAS (2048 - 16) 1311 1312 /* Return the base VMA address which should be subtracted from real addresses 1313 when resolving TLSMOFF relocation. 1314 This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */ 1315 1316 static bfd_vma 1317 tls_biased_base (struct bfd_link_info *info) 1318 { 1319 /* If tls_sec is NULL, we should have signalled an error already. */ 1320 if (elf_hash_table (info)->tls_sec == NULL) 1321 return FRVFDPIC_TLS_BIAS; 1322 return elf_hash_table (info)->tls_sec->vma + FRVFDPIC_TLS_BIAS; 1323 } 1324 1325 /* Generate relocations for GOT entries, function descriptors, and 1326 code for PLT and lazy PLT entries. */ 1327 1328 inline static bfd_boolean 1329 _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry, 1330 bfd *output_bfd, 1331 struct bfd_link_info *info, 1332 asection *sec, 1333 Elf_Internal_Sym *sym, 1334 bfd_vma addend) 1335 1336 { 1337 bfd_vma fd_lazy_rel_offset = (bfd_vma)-1; 1338 int dynindx = -1; 1339 1340 if (entry->done) 1341 return TRUE; 1342 entry->done = 1; 1343 1344 if (entry->got_entry || entry->fdgot_entry || entry->fd_entry 1345 || entry->tlsoff_entry || entry->tlsdesc_entry) 1346 { 1347 /* If the symbol is dynamic, consider it for dynamic 1348 relocations, otherwise decay to section + offset. */ 1349 if (entry->symndx == -1 && entry->d.h->dynindx != -1) 1350 dynindx = entry->d.h->dynindx; 1351 else 1352 { 1353 if (sec 1354 && sec->output_section 1355 && ! bfd_is_abs_section (sec->output_section) 1356 && ! bfd_is_und_section (sec->output_section)) 1357 dynindx = elf_section_data (sec->output_section)->dynindx; 1358 else 1359 dynindx = 0; 1360 } 1361 } 1362 1363 /* Generate relocation for GOT entry pointing to the symbol. */ 1364 if (entry->got_entry) 1365 { 1366 int idx = dynindx; 1367 bfd_vma ad = addend; 1368 1369 /* If the symbol is dynamic but binds locally, use 1370 section+offset. */ 1371 if (sec && (entry->symndx != -1 1372 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1373 { 1374 if (entry->symndx == -1) 1375 ad += entry->d.h->root.u.def.value; 1376 else 1377 ad += sym->st_value; 1378 ad += sec->output_offset; 1379 if (sec->output_section && elf_section_data (sec->output_section)) 1380 idx = elf_section_data (sec->output_section)->dynindx; 1381 else 1382 idx = 0; 1383 } 1384 1385 /* If we're linking an executable at a fixed address, we can 1386 omit the dynamic relocation as long as the symbol is local to 1387 this module. */ 1388 if (info->executable && !info->pie 1389 && (entry->symndx != -1 1390 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1391 { 1392 if (sec) 1393 ad += sec->output_section->vma; 1394 if (entry->symndx != -1 1395 || entry->d.h->root.type != bfd_link_hash_undefweak) 1396 _frvfdpic_add_rofixup (output_bfd, 1397 frvfdpic_gotfixup_section (info), 1398 frvfdpic_got_section (info)->output_section 1399 ->vma 1400 + frvfdpic_got_section (info)->output_offset 1401 + frvfdpic_got_initial_offset (info) 1402 + entry->got_entry, entry); 1403 } 1404 else 1405 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), 1406 _bfd_elf_section_offset 1407 (output_bfd, info, 1408 frvfdpic_got_section (info), 1409 frvfdpic_got_initial_offset (info) 1410 + entry->got_entry) 1411 + frvfdpic_got_section (info) 1412 ->output_section->vma 1413 + frvfdpic_got_section (info)->output_offset, 1414 R_FRV_32, idx, ad, entry); 1415 1416 bfd_put_32 (output_bfd, ad, 1417 frvfdpic_got_section (info)->contents 1418 + frvfdpic_got_initial_offset (info) 1419 + entry->got_entry); 1420 } 1421 1422 /* Generate relocation for GOT entry pointing to a canonical 1423 function descriptor. */ 1424 if (entry->fdgot_entry) 1425 { 1426 int reloc, idx; 1427 bfd_vma ad = 0; 1428 1429 if (! (entry->symndx == -1 1430 && entry->d.h->root.type == bfd_link_hash_undefweak 1431 && FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1432 { 1433 /* If the symbol is dynamic and there may be dynamic symbol 1434 resolution because we are, or are linked with, a shared 1435 library, emit a FUNCDESC relocation such that the dynamic 1436 linker will allocate the function descriptor. If the 1437 symbol needs a non-local function descriptor but binds 1438 locally (e.g., its visibility is protected, emit a 1439 dynamic relocation decayed to section+offset. */ 1440 if (entry->symndx == -1 1441 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h) 1442 && FRVFDPIC_SYM_LOCAL (info, entry->d.h) 1443 && !(info->executable && !info->pie)) 1444 { 1445 reloc = R_FRV_FUNCDESC; 1446 idx = elf_section_data (entry->d.h->root.u.def.section 1447 ->output_section)->dynindx; 1448 ad = entry->d.h->root.u.def.section->output_offset 1449 + entry->d.h->root.u.def.value; 1450 } 1451 else if (entry->symndx == -1 1452 && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)) 1453 { 1454 reloc = R_FRV_FUNCDESC; 1455 idx = dynindx; 1456 ad = addend; 1457 if (ad) 1458 { 1459 (*info->callbacks->reloc_dangerous) 1460 (info, _("relocation requires zero addend"), 1461 elf_hash_table (info)->dynobj, 1462 frvfdpic_got_section (info), 1463 entry->fdgot_entry); 1464 return FALSE; 1465 } 1466 } 1467 else 1468 { 1469 /* Otherwise, we know we have a private function descriptor, 1470 so reference it directly. */ 1471 if (elf_hash_table (info)->dynamic_sections_created) 1472 BFD_ASSERT (entry->privfd); 1473 reloc = R_FRV_32; 1474 idx = elf_section_data (frvfdpic_got_section (info) 1475 ->output_section)->dynindx; 1476 ad = frvfdpic_got_section (info)->output_offset 1477 + frvfdpic_got_initial_offset (info) + entry->fd_entry; 1478 } 1479 1480 /* If there is room for dynamic symbol resolution, emit the 1481 dynamic relocation. However, if we're linking an 1482 executable at a fixed location, we won't have emitted a 1483 dynamic symbol entry for the got section, so idx will be 1484 zero, which means we can and should compute the address 1485 of the private descriptor ourselves. */ 1486 if (info->executable && !info->pie 1487 && (entry->symndx != -1 1488 || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))) 1489 { 1490 ad += frvfdpic_got_section (info)->output_section->vma; 1491 _frvfdpic_add_rofixup (output_bfd, 1492 frvfdpic_gotfixup_section (info), 1493 frvfdpic_got_section (info) 1494 ->output_section->vma 1495 + frvfdpic_got_section (info) 1496 ->output_offset 1497 + frvfdpic_got_initial_offset (info) 1498 + entry->fdgot_entry, entry); 1499 } 1500 else 1501 _frvfdpic_add_dyn_reloc (output_bfd, 1502 frvfdpic_gotrel_section (info), 1503 _bfd_elf_section_offset 1504 (output_bfd, info, 1505 frvfdpic_got_section (info), 1506 frvfdpic_got_initial_offset (info) 1507 + entry->fdgot_entry) 1508 + frvfdpic_got_section (info) 1509 ->output_section->vma 1510 + frvfdpic_got_section (info) 1511 ->output_offset, 1512 reloc, idx, ad, entry); 1513 } 1514 1515 bfd_put_32 (output_bfd, ad, 1516 frvfdpic_got_section (info)->contents 1517 + frvfdpic_got_initial_offset (info) 1518 + entry->fdgot_entry); 1519 } 1520 1521 /* Generate relocation to fill in a private function descriptor in 1522 the GOT. */ 1523 if (entry->fd_entry) 1524 { 1525 int idx = dynindx; 1526 bfd_vma ad = addend; 1527 bfd_vma ofst; 1528 long lowword, highword; 1529 1530 /* If the symbol is dynamic but binds locally, use 1531 section+offset. */ 1532 if (sec && (entry->symndx != -1 1533 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1534 { 1535 if (entry->symndx == -1) 1536 ad += entry->d.h->root.u.def.value; 1537 else 1538 ad += sym->st_value; 1539 ad += sec->output_offset; 1540 if (sec->output_section && elf_section_data (sec->output_section)) 1541 idx = elf_section_data (sec->output_section)->dynindx; 1542 else 1543 idx = 0; 1544 } 1545 1546 /* If we're linking an executable at a fixed address, we can 1547 omit the dynamic relocation as long as the symbol is local to 1548 this module. */ 1549 if (info->executable && !info->pie 1550 && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1551 { 1552 if (sec) 1553 ad += sec->output_section->vma; 1554 ofst = 0; 1555 if (entry->symndx != -1 1556 || entry->d.h->root.type != bfd_link_hash_undefweak) 1557 { 1558 _frvfdpic_add_rofixup (output_bfd, 1559 frvfdpic_gotfixup_section (info), 1560 frvfdpic_got_section (info) 1561 ->output_section->vma 1562 + frvfdpic_got_section (info) 1563 ->output_offset 1564 + frvfdpic_got_initial_offset (info) 1565 + entry->fd_entry, entry); 1566 _frvfdpic_add_rofixup (output_bfd, 1567 frvfdpic_gotfixup_section (info), 1568 frvfdpic_got_section (info) 1569 ->output_section->vma 1570 + frvfdpic_got_section (info) 1571 ->output_offset 1572 + frvfdpic_got_initial_offset (info) 1573 + entry->fd_entry + 4, entry); 1574 } 1575 } 1576 else 1577 { 1578 ofst = 1579 _frvfdpic_add_dyn_reloc (output_bfd, 1580 entry->lazyplt 1581 ? frvfdpic_pltrel_section (info) 1582 : frvfdpic_gotrel_section (info), 1583 _bfd_elf_section_offset 1584 (output_bfd, info, 1585 frvfdpic_got_section (info), 1586 frvfdpic_got_initial_offset (info) 1587 + entry->fd_entry) 1588 + frvfdpic_got_section (info) 1589 ->output_section->vma 1590 + frvfdpic_got_section (info) 1591 ->output_offset, 1592 R_FRV_FUNCDESC_VALUE, idx, ad, entry); 1593 } 1594 1595 /* If we've omitted the dynamic relocation, just emit the fixed 1596 addresses of the symbol and of the local GOT base offset. */ 1597 if (info->executable && !info->pie && sec && sec->output_section) 1598 { 1599 lowword = ad; 1600 highword = frvfdpic_got_section (info)->output_section->vma 1601 + frvfdpic_got_section (info)->output_offset 1602 + frvfdpic_got_initial_offset (info); 1603 } 1604 else if (entry->lazyplt) 1605 { 1606 if (ad) 1607 { 1608 (*info->callbacks->reloc_dangerous) 1609 (info, _("relocation requires zero addend"), 1610 elf_hash_table (info)->dynobj, 1611 frvfdpic_got_section (info), 1612 entry->fd_entry); 1613 return FALSE; 1614 } 1615 1616 fd_lazy_rel_offset = ofst; 1617 1618 /* A function descriptor used for lazy or local resolving is 1619 initialized such that its high word contains the output 1620 section index in which the PLT entries are located, and 1621 the low word contains the address of the lazy PLT entry 1622 entry point, that must be within the memory region 1623 assigned to that section. */ 1624 lowword = entry->lzplt_entry + 4 1625 + frvfdpic_plt_section (info)->output_offset 1626 + frvfdpic_plt_section (info)->output_section->vma; 1627 highword = _frvfdpic_osec_to_segment 1628 (output_bfd, frvfdpic_plt_section (info)->output_section); 1629 } 1630 else 1631 { 1632 /* A function descriptor for a local function gets the index 1633 of the section. For a non-local function, it's 1634 disregarded. */ 1635 lowword = ad; 1636 if (sec == NULL 1637 || (entry->symndx == -1 && entry->d.h->dynindx != -1 1638 && entry->d.h->dynindx == idx)) 1639 highword = 0; 1640 else 1641 highword = _frvfdpic_osec_to_segment 1642 (output_bfd, sec->output_section); 1643 } 1644 1645 bfd_put_32 (output_bfd, lowword, 1646 frvfdpic_got_section (info)->contents 1647 + frvfdpic_got_initial_offset (info) 1648 + entry->fd_entry); 1649 bfd_put_32 (output_bfd, highword, 1650 frvfdpic_got_section (info)->contents 1651 + frvfdpic_got_initial_offset (info) 1652 + entry->fd_entry + 4); 1653 } 1654 1655 /* Generate code for the PLT entry. */ 1656 if (entry->plt_entry != (bfd_vma) -1) 1657 { 1658 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents 1659 + entry->plt_entry; 1660 1661 BFD_ASSERT (entry->fd_entry); 1662 1663 /* Figure out what kind of PLT entry we need, depending on the 1664 location of the function descriptor within the GOT. */ 1665 if (entry->fd_entry >= -(1 << (12 - 1)) 1666 && entry->fd_entry < (1 << (12 - 1))) 1667 { 1668 /* lddi @(gr15, fd_entry), gr14 */ 1669 bfd_put_32 (output_bfd, 1670 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)), 1671 plt_code); 1672 plt_code += 4; 1673 } 1674 else 1675 { 1676 if (entry->fd_entry >= -(1 << (16 - 1)) 1677 && entry->fd_entry < (1 << (16 - 1))) 1678 { 1679 /* setlos lo(fd_entry), gr14 */ 1680 bfd_put_32 (output_bfd, 1681 0x9cfc0000 1682 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)), 1683 plt_code); 1684 plt_code += 4; 1685 } 1686 else 1687 { 1688 /* sethi.p hi(fd_entry), gr14 1689 setlo lo(fd_entry), gr14 */ 1690 bfd_put_32 (output_bfd, 1691 0x1cf80000 1692 | ((entry->fd_entry >> 16) 1693 & (((bfd_vma)1 << 16) - 1)), 1694 plt_code); 1695 plt_code += 4; 1696 bfd_put_32 (output_bfd, 1697 0x9cf40000 1698 | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)), 1699 plt_code); 1700 plt_code += 4; 1701 } 1702 /* ldd @(gr14,gr15),gr14 */ 1703 bfd_put_32 (output_bfd, 0x9c08e14f, plt_code); 1704 plt_code += 4; 1705 } 1706 /* jmpl @(gr14,gr0) */ 1707 bfd_put_32 (output_bfd, 0x8030e000, plt_code); 1708 } 1709 1710 /* Generate code for the lazy PLT entry. */ 1711 if (entry->lzplt_entry != (bfd_vma) -1) 1712 { 1713 bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents 1714 + entry->lzplt_entry; 1715 bfd_vma resolverStub_addr; 1716 1717 bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code); 1718 lzplt_code += 4; 1719 1720 resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE 1721 * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC; 1722 if (resolverStub_addr >= frvfdpic_plt_initial_offset (info)) 1723 resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12; 1724 1725 if (entry->lzplt_entry == resolverStub_addr) 1726 { 1727 /* This is a lazy PLT entry that includes a resolver call. */ 1728 /* ldd @(gr15,gr0), gr4 1729 jmpl @(gr4,gr0) */ 1730 bfd_put_32 (output_bfd, 0x8808f140, lzplt_code); 1731 bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4); 1732 } 1733 else 1734 { 1735 /* bra resolverStub */ 1736 bfd_put_32 (output_bfd, 1737 0xc01a0000 1738 | (((resolverStub_addr - entry->lzplt_entry) 1739 / 4) & (((bfd_vma)1 << 16) - 1)), 1740 lzplt_code); 1741 } 1742 } 1743 1744 /* Generate relocation for GOT entry holding the TLS offset. */ 1745 if (entry->tlsoff_entry) 1746 { 1747 int idx = dynindx; 1748 bfd_vma ad = addend; 1749 1750 if (entry->symndx != -1 1751 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)) 1752 { 1753 /* If the symbol is dynamic but binds locally, use 1754 section+offset. */ 1755 if (sec) 1756 { 1757 if (entry->symndx == -1) 1758 ad += entry->d.h->root.u.def.value; 1759 else 1760 ad += sym->st_value; 1761 ad += sec->output_offset; 1762 if (sec->output_section 1763 && elf_section_data (sec->output_section)) 1764 idx = elf_section_data (sec->output_section)->dynindx; 1765 else 1766 idx = 0; 1767 } 1768 } 1769 1770 /* *ABS*+addend is special for TLS relocations, use only the 1771 addend. */ 1772 if (info->executable 1773 && idx == 0 1774 && (bfd_is_abs_section (sec) 1775 || bfd_is_und_section (sec))) 1776 ; 1777 /* If we're linking an executable, we can entirely omit the 1778 dynamic relocation if the symbol is local to this module. */ 1779 else if (info->executable 1780 && (entry->symndx != -1 1781 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1782 { 1783 if (sec) 1784 ad += sec->output_section->vma - tls_biased_base (info); 1785 } 1786 else 1787 { 1788 if (idx == 0 1789 && (bfd_is_abs_section (sec) 1790 || bfd_is_und_section (sec))) 1791 { 1792 if (! elf_hash_table (info)->tls_sec) 1793 { 1794 (*info->callbacks->undefined_symbol) 1795 (info, "TLS section", elf_hash_table (info)->dynobj, 1796 frvfdpic_got_section (info), entry->tlsoff_entry, TRUE); 1797 return FALSE; 1798 } 1799 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx; 1800 ad += FRVFDPIC_TLS_BIAS; 1801 } 1802 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), 1803 _bfd_elf_section_offset 1804 (output_bfd, info, 1805 frvfdpic_got_section (info), 1806 frvfdpic_got_initial_offset (info) 1807 + entry->tlsoff_entry) 1808 + frvfdpic_got_section (info) 1809 ->output_section->vma 1810 + frvfdpic_got_section (info) 1811 ->output_offset, 1812 R_FRV_TLSOFF, idx, ad, entry); 1813 } 1814 1815 bfd_put_32 (output_bfd, ad, 1816 frvfdpic_got_section (info)->contents 1817 + frvfdpic_got_initial_offset (info) 1818 + entry->tlsoff_entry); 1819 } 1820 1821 if (entry->tlsdesc_entry) 1822 { 1823 int idx = dynindx; 1824 bfd_vma ad = addend; 1825 1826 /* If the symbol is dynamic but binds locally, use 1827 section+offset. */ 1828 if (sec && (entry->symndx != -1 1829 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1830 { 1831 if (entry->symndx == -1) 1832 ad += entry->d.h->root.u.def.value; 1833 else 1834 ad += sym->st_value; 1835 ad += sec->output_offset; 1836 if (sec->output_section && elf_section_data (sec->output_section)) 1837 idx = elf_section_data (sec->output_section)->dynindx; 1838 else 1839 idx = 0; 1840 } 1841 1842 /* If we didn't set up a TLS offset entry, but we're linking an 1843 executable and the symbol binds locally, we can use the 1844 module offset in the TLS descriptor in relaxations. */ 1845 if (info->executable && ! entry->tlsoff_entry) 1846 entry->tlsoff_entry = entry->tlsdesc_entry + 4; 1847 1848 if (info->executable && !info->pie 1849 && ((idx == 0 1850 && (bfd_is_abs_section (sec) 1851 || bfd_is_und_section (sec))) 1852 || entry->symndx != -1 1853 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1854 { 1855 /* *ABS*+addend is special for TLS relocations, use only the 1856 addend for the TLS offset, and take the module id as 1857 0. */ 1858 if (idx == 0 1859 && (bfd_is_abs_section (sec) 1860 || bfd_is_und_section (sec))) 1861 ; 1862 /* For other TLS symbols that bind locally, add the section 1863 TLS offset to the addend. */ 1864 else if (sec) 1865 ad += sec->output_section->vma - tls_biased_base (info); 1866 1867 bfd_put_32 (output_bfd, 1868 frvfdpic_plt_section (info)->output_section->vma 1869 + frvfdpic_plt_section (info)->output_offset 1870 + frvfdpic_plt_tls_ret_offset (info), 1871 frvfdpic_got_section (info)->contents 1872 + frvfdpic_got_initial_offset (info) 1873 + entry->tlsdesc_entry); 1874 1875 _frvfdpic_add_rofixup (output_bfd, 1876 frvfdpic_gotfixup_section (info), 1877 frvfdpic_got_section (info) 1878 ->output_section->vma 1879 + frvfdpic_got_section (info) 1880 ->output_offset 1881 + frvfdpic_got_initial_offset (info) 1882 + entry->tlsdesc_entry, entry); 1883 1884 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs); 1885 1886 /* We've used one of the reserved fixups, so discount it so 1887 that we can check at the end that we've used them 1888 all. */ 1889 frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs--; 1890 1891 /* While at that, make sure the ret instruction makes to the 1892 right location in the PLT. We could do it only when we 1893 got to 0, but since the check at the end will only print 1894 a warning, make sure we have the ret in place in case the 1895 warning is missed. */ 1896 bfd_put_32 (output_bfd, 0xc03a4000, 1897 frvfdpic_plt_section (info)->contents 1898 + frvfdpic_plt_tls_ret_offset (info)); 1899 } 1900 else 1901 { 1902 if (idx == 0 1903 && (bfd_is_abs_section (sec) 1904 || bfd_is_und_section (sec))) 1905 { 1906 if (! elf_hash_table (info)->tls_sec) 1907 { 1908 (*info->callbacks->undefined_symbol) 1909 (info, "TLS section", elf_hash_table (info)->dynobj, 1910 frvfdpic_got_section (info), entry->tlsdesc_entry, TRUE); 1911 return FALSE; 1912 } 1913 idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx; 1914 ad += FRVFDPIC_TLS_BIAS; 1915 } 1916 1917 _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info), 1918 _bfd_elf_section_offset 1919 (output_bfd, info, 1920 frvfdpic_got_section (info), 1921 frvfdpic_got_initial_offset (info) 1922 + entry->tlsdesc_entry) 1923 + frvfdpic_got_section (info) 1924 ->output_section->vma 1925 + frvfdpic_got_section (info) 1926 ->output_offset, 1927 R_FRV_TLSDESC_VALUE, idx, ad, entry); 1928 1929 bfd_put_32 (output_bfd, 0, 1930 frvfdpic_got_section (info)->contents 1931 + frvfdpic_got_initial_offset (info) 1932 + entry->tlsdesc_entry); 1933 } 1934 1935 bfd_put_32 (output_bfd, ad, 1936 frvfdpic_got_section (info)->contents 1937 + frvfdpic_got_initial_offset (info) 1938 + entry->tlsdesc_entry + 4); 1939 } 1940 1941 /* Generate code for the get-TLS-offset PLT entry. */ 1942 if (entry->tlsplt_entry != (bfd_vma) -1) 1943 { 1944 bfd_byte *plt_code = frvfdpic_plt_section (info)->contents 1945 + entry->tlsplt_entry; 1946 1947 if (info->executable 1948 && (entry->symndx != -1 1949 || FRVFDPIC_SYM_LOCAL (info, entry->d.h))) 1950 { 1951 int idx = dynindx; 1952 bfd_vma ad = addend; 1953 1954 /* sec may be NULL when referencing an undefweak symbol 1955 while linking a static executable. */ 1956 if (!sec) 1957 { 1958 BFD_ASSERT (entry->symndx == -1 1959 && entry->d.h->root.type == bfd_link_hash_undefweak); 1960 } 1961 else 1962 { 1963 if (entry->symndx == -1) 1964 ad += entry->d.h->root.u.def.value; 1965 else 1966 ad += sym->st_value; 1967 ad += sec->output_offset; 1968 if (sec->output_section 1969 && elf_section_data (sec->output_section)) 1970 idx = elf_section_data (sec->output_section)->dynindx; 1971 else 1972 idx = 0; 1973 } 1974 1975 /* *ABS*+addend is special for TLS relocations, use only the 1976 addend for the TLS offset, and take the module id as 1977 0. */ 1978 if (idx == 0 1979 && (bfd_is_abs_section (sec) 1980 || bfd_is_und_section (sec))) 1981 ; 1982 /* For other TLS symbols that bind locally, add the section 1983 TLS offset to the addend. */ 1984 else if (sec) 1985 ad += sec->output_section->vma - tls_biased_base (info); 1986 1987 if ((bfd_signed_vma)ad >= -(1 << (16 - 1)) 1988 && (bfd_signed_vma)ad < (1 << (16 - 1))) 1989 { 1990 /* setlos lo(ad), gr9 */ 1991 bfd_put_32 (output_bfd, 1992 0x92fc0000 1993 | (ad 1994 & (((bfd_vma)1 << 16) - 1)), 1995 plt_code); 1996 plt_code += 4; 1997 } 1998 else 1999 { 2000 /* sethi.p hi(ad), gr9 2001 setlo lo(ad), gr9 */ 2002 bfd_put_32 (output_bfd, 2003 0x12f80000 2004 | ((ad >> 16) 2005 & (((bfd_vma)1 << 16) - 1)), 2006 plt_code); 2007 plt_code += 4; 2008 bfd_put_32 (output_bfd, 2009 0x92f40000 2010 | (ad 2011 & (((bfd_vma)1 << 16) - 1)), 2012 plt_code); 2013 plt_code += 4; 2014 } 2015 /* ret */ 2016 bfd_put_32 (output_bfd, 0xc03a4000, plt_code); 2017 } 2018 else if (entry->tlsoff_entry) 2019 { 2020 /* Figure out what kind of PLT entry we need, depending on the 2021 location of the TLS descriptor within the GOT. */ 2022 if (entry->tlsoff_entry >= -(1 << (12 - 1)) 2023 && entry->tlsoff_entry < (1 << (12 - 1))) 2024 { 2025 /* ldi @(gr15, tlsoff_entry), gr9 */ 2026 bfd_put_32 (output_bfd, 2027 0x92c8f000 | (entry->tlsoff_entry 2028 & ((1 << 12) - 1)), 2029 plt_code); 2030 plt_code += 4; 2031 } 2032 else 2033 { 2034 if (entry->tlsoff_entry >= -(1 << (16 - 1)) 2035 && entry->tlsoff_entry < (1 << (16 - 1))) 2036 { 2037 /* setlos lo(tlsoff_entry), gr8 */ 2038 bfd_put_32 (output_bfd, 2039 0x90fc0000 2040 | (entry->tlsoff_entry 2041 & (((bfd_vma)1 << 16) - 1)), 2042 plt_code); 2043 plt_code += 4; 2044 } 2045 else 2046 { 2047 /* sethi.p hi(tlsoff_entry), gr8 2048 setlo lo(tlsoff_entry), gr8 */ 2049 bfd_put_32 (output_bfd, 2050 0x10f80000 2051 | ((entry->tlsoff_entry >> 16) 2052 & (((bfd_vma)1 << 16) - 1)), 2053 plt_code); 2054 plt_code += 4; 2055 bfd_put_32 (output_bfd, 2056 0x90f40000 2057 | (entry->tlsoff_entry 2058 & (((bfd_vma)1 << 16) - 1)), 2059 plt_code); 2060 plt_code += 4; 2061 } 2062 /* ld @(gr15,gr8),gr9 */ 2063 bfd_put_32 (output_bfd, 0x9008f108, plt_code); 2064 plt_code += 4; 2065 } 2066 /* ret */ 2067 bfd_put_32 (output_bfd, 0xc03a4000, plt_code); 2068 } 2069 else 2070 { 2071 BFD_ASSERT (entry->tlsdesc_entry); 2072 2073 /* Figure out what kind of PLT entry we need, depending on the 2074 location of the TLS descriptor within the GOT. */ 2075 if (entry->tlsdesc_entry >= -(1 << (12 - 1)) 2076 && entry->tlsdesc_entry < (1 << (12 - 1))) 2077 { 2078 /* lddi @(gr15, tlsdesc_entry), gr8 */ 2079 bfd_put_32 (output_bfd, 2080 0x90ccf000 | (entry->tlsdesc_entry 2081 & ((1 << 12) - 1)), 2082 plt_code); 2083 plt_code += 4; 2084 } 2085 else 2086 { 2087 if (entry->tlsdesc_entry >= -(1 << (16 - 1)) 2088 && entry->tlsdesc_entry < (1 << (16 - 1))) 2089 { 2090 /* setlos lo(tlsdesc_entry), gr8 */ 2091 bfd_put_32 (output_bfd, 2092 0x90fc0000 2093 | (entry->tlsdesc_entry 2094 & (((bfd_vma)1 << 16) - 1)), 2095 plt_code); 2096 plt_code += 4; 2097 } 2098 else 2099 { 2100 /* sethi.p hi(tlsdesc_entry), gr8 2101 setlo lo(tlsdesc_entry), gr8 */ 2102 bfd_put_32 (output_bfd, 2103 0x10f80000 2104 | ((entry->tlsdesc_entry >> 16) 2105 & (((bfd_vma)1 << 16) - 1)), 2106 plt_code); 2107 plt_code += 4; 2108 bfd_put_32 (output_bfd, 2109 0x90f40000 2110 | (entry->tlsdesc_entry 2111 & (((bfd_vma)1 << 16) - 1)), 2112 plt_code); 2113 plt_code += 4; 2114 } 2115 /* ldd @(gr15,gr8),gr8 */ 2116 bfd_put_32 (output_bfd, 0x9008f148, plt_code); 2117 plt_code += 4; 2118 } 2119 /* jmpl @(gr8,gr0) */ 2120 bfd_put_32 (output_bfd, 0x80308000, plt_code); 2121 } 2122 } 2123 2124 return TRUE; 2125 } 2126 2127 /* Handle an FRV small data reloc. */ 2128 2129 static bfd_reloc_status_type 2130 elf32_frv_relocate_gprel12 (struct bfd_link_info *info, 2131 bfd *input_bfd, 2132 asection *input_section, 2133 Elf_Internal_Rela *relocation, 2134 bfd_byte *contents, 2135 bfd_vma value) 2136 { 2137 bfd_vma insn; 2138 bfd_vma gp; 2139 struct bfd_link_hash_entry *h; 2140 2141 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); 2142 2143 gp = (h->u.def.value 2144 + h->u.def.section->output_section->vma 2145 + h->u.def.section->output_offset); 2146 2147 value -= input_section->output_section->vma; 2148 value -= (gp - input_section->output_section->vma); 2149 2150 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); 2151 2152 value += relocation->r_addend; 2153 2154 if ((long) value > 0x7ff || (long) value < -0x800) 2155 return bfd_reloc_overflow; 2156 2157 bfd_put_32 (input_bfd, 2158 (insn & 0xfffff000) | (value & 0xfff), 2159 contents + relocation->r_offset); 2160 2161 return bfd_reloc_ok; 2162 } 2163 2164 /* Handle an FRV small data reloc. for the u12 field. */ 2165 2166 static bfd_reloc_status_type 2167 elf32_frv_relocate_gprelu12 (struct bfd_link_info *info, 2168 bfd *input_bfd, 2169 asection *input_section, 2170 Elf_Internal_Rela *relocation, 2171 bfd_byte *contents, 2172 bfd_vma value) 2173 { 2174 bfd_vma insn; 2175 bfd_vma gp; 2176 struct bfd_link_hash_entry *h; 2177 bfd_vma mask; 2178 2179 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); 2180 2181 gp = (h->u.def.value 2182 + h->u.def.section->output_section->vma 2183 + h->u.def.section->output_offset); 2184 2185 value -= input_section->output_section->vma; 2186 value -= (gp - input_section->output_section->vma); 2187 2188 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); 2189 2190 value += relocation->r_addend; 2191 2192 if ((long) value > 0x7ff || (long) value < -0x800) 2193 return bfd_reloc_overflow; 2194 2195 /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */ 2196 mask = 0x3f03f; 2197 insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f); 2198 2199 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); 2200 2201 return bfd_reloc_ok; 2202 } 2203 2204 /* Handle an FRV ELF HI16 reloc. */ 2205 2206 static bfd_reloc_status_type 2207 elf32_frv_relocate_hi16 (bfd *input_bfd, 2208 Elf_Internal_Rela *relhi, 2209 bfd_byte *contents, 2210 bfd_vma value) 2211 { 2212 bfd_vma insn; 2213 2214 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset); 2215 2216 value += relhi->r_addend; 2217 value = ((value >> 16) & 0xffff); 2218 2219 insn = (insn & 0xffff0000) | value; 2220 2221 if ((long) value > 0xffff || (long) value < -0x10000) 2222 return bfd_reloc_overflow; 2223 2224 bfd_put_32 (input_bfd, insn, contents + relhi->r_offset); 2225 return bfd_reloc_ok; 2226 2227 } 2228 static bfd_reloc_status_type 2229 elf32_frv_relocate_lo16 (bfd *input_bfd, 2230 Elf_Internal_Rela *rello, 2231 bfd_byte *contents, 2232 bfd_vma value) 2233 { 2234 bfd_vma insn; 2235 2236 insn = bfd_get_32 (input_bfd, contents + rello->r_offset); 2237 2238 value += rello->r_addend; 2239 value = value & 0xffff; 2240 2241 insn = (insn & 0xffff0000) | value; 2242 2243 if ((long) value > 0xffff || (long) value < -0x10000) 2244 return bfd_reloc_overflow; 2245 2246 bfd_put_32 (input_bfd, insn, contents + rello->r_offset); 2247 return bfd_reloc_ok; 2248 } 2249 2250 /* Perform the relocation for the CALL label24 instruction. */ 2251 2252 static bfd_reloc_status_type 2253 elf32_frv_relocate_label24 (bfd *input_bfd, 2254 asection *input_section, 2255 Elf_Internal_Rela *rello, 2256 bfd_byte *contents, 2257 bfd_vma value) 2258 { 2259 bfd_vma insn; 2260 bfd_vma label6; 2261 bfd_vma label18; 2262 2263 /* The format for the call instruction is: 2264 2265 0 000000 0001111 000000000000000000 2266 label6 opcode label18 2267 2268 The branch calculation is: pc + (4*label24) 2269 where label24 is the concatenation of label6 and label18. */ 2270 2271 /* Grab the instruction. */ 2272 insn = bfd_get_32 (input_bfd, contents + rello->r_offset); 2273 2274 value -= input_section->output_section->vma + input_section->output_offset; 2275 value -= rello->r_offset; 2276 value += rello->r_addend; 2277 2278 value = value >> 2; 2279 2280 label6 = value & 0xfc0000; 2281 label6 = label6 << 7; 2282 2283 label18 = value & 0x3ffff; 2284 2285 insn = insn & 0x803c0000; 2286 insn = insn | label6; 2287 insn = insn | label18; 2288 2289 bfd_put_32 (input_bfd, insn, contents + rello->r_offset); 2290 2291 return bfd_reloc_ok; 2292 } 2293 2294 static bfd_reloc_status_type 2295 elf32_frv_relocate_gprelhi (struct bfd_link_info *info, 2296 bfd *input_bfd, 2297 asection *input_section, 2298 Elf_Internal_Rela *relocation, 2299 bfd_byte *contents, 2300 bfd_vma value) 2301 { 2302 bfd_vma insn; 2303 bfd_vma gp; 2304 struct bfd_link_hash_entry *h; 2305 2306 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); 2307 2308 gp = (h->u.def.value 2309 + h->u.def.section->output_section->vma 2310 + h->u.def.section->output_offset); 2311 2312 value -= input_section->output_section->vma; 2313 value -= (gp - input_section->output_section->vma); 2314 value += relocation->r_addend; 2315 value = ((value >> 16) & 0xffff); 2316 2317 if ((long) value > 0xffff || (long) value < -0x10000) 2318 return bfd_reloc_overflow; 2319 2320 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); 2321 insn = (insn & 0xffff0000) | value; 2322 2323 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); 2324 return bfd_reloc_ok; 2325 } 2326 2327 static bfd_reloc_status_type 2328 elf32_frv_relocate_gprello (struct bfd_link_info *info, 2329 bfd *input_bfd, 2330 asection *input_section, 2331 Elf_Internal_Rela *relocation, 2332 bfd_byte *contents, 2333 bfd_vma value) 2334 { 2335 bfd_vma insn; 2336 bfd_vma gp; 2337 struct bfd_link_hash_entry *h; 2338 2339 h = bfd_link_hash_lookup (info->hash, "_gp", FALSE, FALSE, TRUE); 2340 2341 gp = (h->u.def.value 2342 + h->u.def.section->output_section->vma 2343 + h->u.def.section->output_offset); 2344 2345 value -= input_section->output_section->vma; 2346 value -= (gp - input_section->output_section->vma); 2347 value += relocation->r_addend; 2348 value = value & 0xffff; 2349 2350 if ((long) value > 0xffff || (long) value < -0x10000) 2351 return bfd_reloc_overflow; 2352 2353 insn = bfd_get_32 (input_bfd, contents + relocation->r_offset); 2354 insn = (insn & 0xffff0000) | value; 2355 2356 bfd_put_32 (input_bfd, insn, contents + relocation->r_offset); 2357 2358 return bfd_reloc_ok; 2359 } 2360 2361 static reloc_howto_type * 2362 frv_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, 2363 bfd_reloc_code_real_type code) 2364 { 2365 switch (code) 2366 { 2367 default: 2368 break; 2369 2370 case BFD_RELOC_NONE: 2371 return &elf32_frv_howto_table[ (int) R_FRV_NONE]; 2372 2373 case BFD_RELOC_32: 2374 if (elf_elfheader (abfd)->e_type == ET_EXEC 2375 || elf_elfheader (abfd)->e_type == ET_DYN) 2376 return &elf32_frv_rel_32_howto; 2377 /* Fall through. */ 2378 case BFD_RELOC_CTOR: 2379 return &elf32_frv_howto_table[ (int) R_FRV_32]; 2380 2381 case BFD_RELOC_FRV_LABEL16: 2382 return &elf32_frv_howto_table[ (int) R_FRV_LABEL16]; 2383 2384 case BFD_RELOC_FRV_LABEL24: 2385 return &elf32_frv_howto_table[ (int) R_FRV_LABEL24]; 2386 2387 case BFD_RELOC_FRV_LO16: 2388 return &elf32_frv_howto_table[ (int) R_FRV_LO16]; 2389 2390 case BFD_RELOC_FRV_HI16: 2391 return &elf32_frv_howto_table[ (int) R_FRV_HI16]; 2392 2393 case BFD_RELOC_FRV_GPREL12: 2394 return &elf32_frv_howto_table[ (int) R_FRV_GPREL12]; 2395 2396 case BFD_RELOC_FRV_GPRELU12: 2397 return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12]; 2398 2399 case BFD_RELOC_FRV_GPREL32: 2400 return &elf32_frv_howto_table[ (int) R_FRV_GPREL32]; 2401 2402 case BFD_RELOC_FRV_GPRELHI: 2403 return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI]; 2404 2405 case BFD_RELOC_FRV_GPRELLO: 2406 return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO]; 2407 2408 case BFD_RELOC_FRV_GOT12: 2409 return &elf32_frv_howto_table[ (int) R_FRV_GOT12]; 2410 2411 case BFD_RELOC_FRV_GOTHI: 2412 return &elf32_frv_howto_table[ (int) R_FRV_GOTHI]; 2413 2414 case BFD_RELOC_FRV_GOTLO: 2415 return &elf32_frv_howto_table[ (int) R_FRV_GOTLO]; 2416 2417 case BFD_RELOC_FRV_FUNCDESC: 2418 if (elf_elfheader (abfd)->e_type == ET_EXEC 2419 || elf_elfheader (abfd)->e_type == ET_DYN) 2420 return &elf32_frv_rel_funcdesc_howto; 2421 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC]; 2422 2423 case BFD_RELOC_FRV_FUNCDESC_GOT12: 2424 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12]; 2425 2426 case BFD_RELOC_FRV_FUNCDESC_GOTHI: 2427 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI]; 2428 2429 case BFD_RELOC_FRV_FUNCDESC_GOTLO: 2430 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO]; 2431 2432 case BFD_RELOC_FRV_FUNCDESC_VALUE: 2433 if (elf_elfheader (abfd)->e_type == ET_EXEC 2434 || elf_elfheader (abfd)->e_type == ET_DYN) 2435 return &elf32_frv_rel_funcdesc_value_howto; 2436 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE]; 2437 2438 case BFD_RELOC_FRV_FUNCDESC_GOTOFF12: 2439 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12]; 2440 2441 case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI: 2442 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI]; 2443 2444 case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO: 2445 return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO]; 2446 2447 case BFD_RELOC_FRV_GOTOFF12: 2448 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12]; 2449 2450 case BFD_RELOC_FRV_GOTOFFHI: 2451 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI]; 2452 2453 case BFD_RELOC_FRV_GOTOFFLO: 2454 return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO]; 2455 2456 case BFD_RELOC_FRV_GETTLSOFF: 2457 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF]; 2458 2459 case BFD_RELOC_FRV_TLSDESC_VALUE: 2460 if (elf_elfheader (abfd)->e_type == ET_EXEC 2461 || elf_elfheader (abfd)->e_type == ET_DYN) 2462 return &elf32_frv_rel_tlsdesc_value_howto; 2463 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_VALUE]; 2464 2465 case BFD_RELOC_FRV_GOTTLSDESC12: 2466 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESC12]; 2467 2468 case BFD_RELOC_FRV_GOTTLSDESCHI: 2469 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCHI]; 2470 2471 case BFD_RELOC_FRV_GOTTLSDESCLO: 2472 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCLO]; 2473 2474 case BFD_RELOC_FRV_TLSMOFF12: 2475 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF12]; 2476 2477 case BFD_RELOC_FRV_TLSMOFFHI: 2478 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFHI]; 2479 2480 case BFD_RELOC_FRV_TLSMOFFLO: 2481 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFLO]; 2482 2483 case BFD_RELOC_FRV_GOTTLSOFF12: 2484 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFF12]; 2485 2486 case BFD_RELOC_FRV_GOTTLSOFFHI: 2487 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFHI]; 2488 2489 case BFD_RELOC_FRV_GOTTLSOFFLO: 2490 return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFLO]; 2491 2492 case BFD_RELOC_FRV_TLSOFF: 2493 if (elf_elfheader (abfd)->e_type == ET_EXEC 2494 || elf_elfheader (abfd)->e_type == ET_DYN) 2495 return &elf32_frv_rel_tlsoff_howto; 2496 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF]; 2497 2498 case BFD_RELOC_FRV_TLSDESC_RELAX: 2499 return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_RELAX]; 2500 2501 case BFD_RELOC_FRV_GETTLSOFF_RELAX: 2502 return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF_RELAX]; 2503 2504 case BFD_RELOC_FRV_TLSOFF_RELAX: 2505 return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF_RELAX]; 2506 2507 case BFD_RELOC_FRV_TLSMOFF: 2508 return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF]; 2509 2510 case BFD_RELOC_VTABLE_INHERIT: 2511 return &elf32_frv_vtinherit_howto; 2512 2513 case BFD_RELOC_VTABLE_ENTRY: 2514 return &elf32_frv_vtentry_howto; 2515 } 2516 2517 return NULL; 2518 } 2519 2520 static reloc_howto_type * 2521 frv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) 2522 { 2523 unsigned int i; 2524 2525 for (i = 0; 2526 i < sizeof (elf32_frv_howto_table) / sizeof (elf32_frv_howto_table[0]); 2527 i++) 2528 if (elf32_frv_howto_table[i].name != NULL 2529 && strcasecmp (elf32_frv_howto_table[i].name, r_name) == 0) 2530 return &elf32_frv_howto_table[i]; 2531 2532 if (strcasecmp (elf32_frv_vtinherit_howto.name, r_name) == 0) 2533 return &elf32_frv_vtinherit_howto; 2534 if (strcasecmp (elf32_frv_vtentry_howto.name, r_name) == 0) 2535 return &elf32_frv_vtentry_howto; 2536 2537 return NULL; 2538 } 2539 2540 /* Set the howto pointer for an FRV ELF reloc. */ 2541 2542 static void 2543 frv_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, 2544 arelent *cache_ptr, 2545 Elf_Internal_Rela *dst) 2546 { 2547 unsigned int r_type; 2548 2549 r_type = ELF32_R_TYPE (dst->r_info); 2550 switch (r_type) 2551 { 2552 case R_FRV_GNU_VTINHERIT: 2553 cache_ptr->howto = &elf32_frv_vtinherit_howto; 2554 break; 2555 2556 case R_FRV_GNU_VTENTRY: 2557 cache_ptr->howto = &elf32_frv_vtentry_howto; 2558 break; 2559 2560 default: 2561 cache_ptr->howto = & elf32_frv_howto_table [r_type]; 2562 break; 2563 } 2564 } 2565 2566 /* Set the howto pointer for an FRV ELF REL reloc. */ 2567 static void 2568 frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, 2569 arelent *cache_ptr, Elf_Internal_Rela *dst) 2570 { 2571 unsigned int r_type; 2572 2573 r_type = ELF32_R_TYPE (dst->r_info); 2574 switch (r_type) 2575 { 2576 case R_FRV_32: 2577 cache_ptr->howto = &elf32_frv_rel_32_howto; 2578 break; 2579 2580 case R_FRV_FUNCDESC: 2581 cache_ptr->howto = &elf32_frv_rel_funcdesc_howto; 2582 break; 2583 2584 case R_FRV_FUNCDESC_VALUE: 2585 cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto; 2586 break; 2587 2588 case R_FRV_TLSDESC_VALUE: 2589 cache_ptr->howto = &elf32_frv_rel_tlsdesc_value_howto; 2590 break; 2591 2592 case R_FRV_TLSOFF: 2593 cache_ptr->howto = &elf32_frv_rel_tlsoff_howto; 2594 break; 2595 2596 default: 2597 cache_ptr->howto = NULL; 2598 break; 2599 } 2600 } 2601 2602 /* Perform a single relocation. By default we use the standard BFD 2604 routines, but a few relocs, we have to do them ourselves. */ 2605 2606 static bfd_reloc_status_type 2607 frv_final_link_relocate (reloc_howto_type *howto, 2608 bfd *input_bfd, 2609 asection *input_section, 2610 bfd_byte *contents, 2611 Elf_Internal_Rela *rel, 2612 bfd_vma relocation) 2613 { 2614 return _bfd_final_link_relocate (howto, input_bfd, input_section, 2615 contents, rel->r_offset, relocation, 2616 rel->r_addend); 2617 } 2618 2619 2620 /* Relocate an FRV ELF section. 2622 2623 The RELOCATE_SECTION function is called by the new ELF backend linker 2624 to handle the relocations for a section. 2625 2626 The relocs are always passed as Rela structures; if the section 2627 actually uses Rel structures, the r_addend field will always be 2628 zero. 2629 2630 This function is responsible for adjusting the section contents as 2631 necessary, and (if using Rela relocs and generating a relocatable 2632 output file) adjusting the reloc addend as necessary. 2633 2634 This function does not have to worry about setting the reloc 2635 address or the reloc symbol index. 2636 2637 LOCAL_SYMS is a pointer to the swapped in local symbols. 2638 2639 LOCAL_SECTIONS is an array giving the section in the input file 2640 corresponding to the st_shndx field of each local symbol. 2641 2642 The global hash table entry for the global symbols can be found 2643 via elf_sym_hashes (input_bfd). 2644 2645 When generating relocatable output, this function must handle 2646 STB_LOCAL/STT_SECTION symbols specially. The output symbol is 2647 going to be the section symbol corresponding to the output 2648 section, which means that the addend must be adjusted 2649 accordingly. */ 2650 2651 static bfd_boolean 2652 elf32_frv_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, 2653 struct bfd_link_info *info, 2654 bfd *input_bfd, 2655 asection *input_section, 2656 bfd_byte *contents, 2657 Elf_Internal_Rela *relocs, 2658 Elf_Internal_Sym *local_syms, 2659 asection **local_sections) 2660 { 2661 Elf_Internal_Shdr *symtab_hdr; 2662 struct elf_link_hash_entry **sym_hashes; 2663 Elf_Internal_Rela *rel; 2664 Elf_Internal_Rela *relend; 2665 unsigned isec_segment, got_segment, plt_segment, gprel_segment, tls_segment, 2666 check_segment[2]; 2667 int silence_segment_error = !(info->shared || info->pie); 2668 unsigned long insn; 2669 2670 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; 2671 sym_hashes = elf_sym_hashes (input_bfd); 2672 relend = relocs + input_section->reloc_count; 2673 2674 isec_segment = _frvfdpic_osec_to_segment (output_bfd, 2675 input_section->output_section); 2676 if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info)) 2677 got_segment = _frvfdpic_osec_to_segment (output_bfd, 2678 frvfdpic_got_section (info) 2679 ->output_section); 2680 else 2681 got_segment = -1; 2682 if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info)) 2683 gprel_segment = _frvfdpic_osec_to_segment (output_bfd, 2684 frvfdpic_gotfixup_section (info) 2685 ->output_section); 2686 else 2687 gprel_segment = -1; 2688 if (IS_FDPIC (output_bfd) && frvfdpic_plt_section (info)) 2689 plt_segment = _frvfdpic_osec_to_segment (output_bfd, 2690 frvfdpic_plt_section (info) 2691 ->output_section); 2692 else 2693 plt_segment = -1; 2694 if (elf_hash_table (info)->tls_sec) 2695 tls_segment = _frvfdpic_osec_to_segment (output_bfd, 2696 elf_hash_table (info)->tls_sec); 2697 else 2698 tls_segment = -1; 2699 2700 for (rel = relocs; rel < relend; rel ++) 2701 { 2702 reloc_howto_type *howto; 2703 unsigned long r_symndx; 2704 Elf_Internal_Sym *sym; 2705 asection *sec; 2706 struct elf_link_hash_entry *h; 2707 bfd_vma relocation; 2708 bfd_reloc_status_type r; 2709 const char *name; 2710 int r_type; 2711 asection *osec; 2712 struct frvfdpic_relocs_info *picrel; 2713 bfd_vma orig_addend = rel->r_addend; 2714 2715 r_type = ELF32_R_TYPE (rel->r_info); 2716 2717 if ( r_type == R_FRV_GNU_VTINHERIT 2718 || r_type == R_FRV_GNU_VTENTRY) 2719 continue; 2720 2721 r_symndx = ELF32_R_SYM (rel->r_info); 2722 howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info); 2723 h = NULL; 2724 sym = NULL; 2725 sec = NULL; 2726 2727 if (r_symndx < symtab_hdr->sh_info) 2728 { 2729 sym = local_syms + r_symndx; 2730 osec = sec = local_sections [r_symndx]; 2731 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); 2732 2733 name = bfd_elf_string_from_elf_section 2734 (input_bfd, symtab_hdr->sh_link, sym->st_name); 2735 if (name == NULL || name[0] == 0) 2736 name = bfd_section_name (input_bfd, sec); 2737 } 2738 else 2739 { 2740 bfd_boolean warned, ignored; 2741 bfd_boolean unresolved_reloc; 2742 2743 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 2744 r_symndx, symtab_hdr, sym_hashes, 2745 h, sec, relocation, 2746 unresolved_reloc, warned, ignored); 2747 osec = sec; 2748 name = h->root.root.string; 2749 } 2750 2751 if (sec != NULL && discarded_section (sec)) 2752 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 2753 rel, 1, relend, howto, 0, contents); 2754 2755 if (info->relocatable) 2756 continue; 2757 2758 if (r_type != R_FRV_TLSMOFF 2759 && h != NULL 2760 && (h->root.type == bfd_link_hash_defined 2761 || h->root.type == bfd_link_hash_defweak) 2762 && !FRVFDPIC_SYM_LOCAL (info, h)) 2763 { 2764 osec = sec = NULL; 2765 relocation = 0; 2766 } 2767 2768 switch (r_type) 2769 { 2770 case R_FRV_LABEL24: 2771 case R_FRV_32: 2772 if (! IS_FDPIC (output_bfd)) 2773 goto non_fdpic; 2774 2775 case R_FRV_GOT12: 2776 case R_FRV_GOTHI: 2777 case R_FRV_GOTLO: 2778 case R_FRV_FUNCDESC_GOT12: 2779 case R_FRV_FUNCDESC_GOTHI: 2780 case R_FRV_FUNCDESC_GOTLO: 2781 case R_FRV_GOTOFF12: 2782 case R_FRV_GOTOFFHI: 2783 case R_FRV_GOTOFFLO: 2784 case R_FRV_FUNCDESC_GOTOFF12: 2785 case R_FRV_FUNCDESC_GOTOFFHI: 2786 case R_FRV_FUNCDESC_GOTOFFLO: 2787 case R_FRV_FUNCDESC: 2788 case R_FRV_FUNCDESC_VALUE: 2789 case R_FRV_GETTLSOFF: 2790 case R_FRV_TLSDESC_VALUE: 2791 case R_FRV_GOTTLSDESC12: 2792 case R_FRV_GOTTLSDESCHI: 2793 case R_FRV_GOTTLSDESCLO: 2794 case R_FRV_TLSMOFF12: 2795 case R_FRV_TLSMOFFHI: 2796 case R_FRV_TLSMOFFLO: 2797 case R_FRV_GOTTLSOFF12: 2798 case R_FRV_GOTTLSOFFHI: 2799 case R_FRV_GOTTLSOFFLO: 2800 case R_FRV_TLSOFF: 2801 case R_FRV_TLSDESC_RELAX: 2802 case R_FRV_GETTLSOFF_RELAX: 2803 case R_FRV_TLSOFF_RELAX: 2804 case R_FRV_TLSMOFF: 2805 if (h != NULL) 2806 picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info 2807 (info), input_bfd, h, 2808 orig_addend, INSERT); 2809 else 2810 /* In order to find the entry we created before, we must 2811 use the original addend, not the one that may have been 2812 modified by _bfd_elf_rela_local_sym(). */ 2813 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info 2814 (info), input_bfd, r_symndx, 2815 orig_addend, INSERT); 2816 if (! picrel) 2817 return FALSE; 2818 2819 if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info, 2820 osec, sym, 2821 rel->r_addend)) 2822 { 2823 info->callbacks->einfo 2824 (_("%H: relocation to `%s+%v'" 2825 " may have caused the error above\n"), 2826 input_bfd, input_section, rel->r_offset, name, rel->r_addend); 2827 return FALSE; 2828 } 2829 2830 break; 2831 2832 default: 2833 non_fdpic: 2834 picrel = NULL; 2835 if (h 2836 && ! FRVFDPIC_SYM_LOCAL (info, h) 2837 && _bfd_elf_section_offset (output_bfd, info, input_section, 2838 rel->r_offset) != (bfd_vma) -1) 2839 { 2840 info->callbacks->einfo 2841 (_("%H: relocation references symbol" 2842 " not defined in the module\n"), 2843 input_bfd, input_section, rel->r_offset); 2844 return FALSE; 2845 } 2846 break; 2847 } 2848 2849 switch (r_type) 2850 { 2851 case R_FRV_GETTLSOFF: 2852 case R_FRV_TLSDESC_VALUE: 2853 case R_FRV_GOTTLSDESC12: 2854 case R_FRV_GOTTLSDESCHI: 2855 case R_FRV_GOTTLSDESCLO: 2856 case R_FRV_TLSMOFF12: 2857 case R_FRV_TLSMOFFHI: 2858 case R_FRV_TLSMOFFLO: 2859 case R_FRV_GOTTLSOFF12: 2860 case R_FRV_GOTTLSOFFHI: 2861 case R_FRV_GOTTLSOFFLO: 2862 case R_FRV_TLSOFF: 2863 case R_FRV_TLSDESC_RELAX: 2864 case R_FRV_GETTLSOFF_RELAX: 2865 case R_FRV_TLSOFF_RELAX: 2866 case R_FRV_TLSMOFF: 2867 if (sec && (bfd_is_abs_section (sec) || bfd_is_und_section (sec))) 2868 relocation += tls_biased_base (info); 2869 break; 2870 2871 default: 2872 break; 2873 } 2874 2875 /* Try to apply TLS relaxations. */ 2876 if (1) 2877 switch (r_type) 2878 { 2879 2880 #define LOCAL_EXEC_P(info, picrel) \ 2881 ((info)->executable \ 2882 && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h))) 2883 #define INITIAL_EXEC_P(info, picrel) \ 2884 (((info)->executable || (info)->flags & DF_STATIC_TLS) \ 2885 && (picrel)->tlsoff_entry) 2886 2887 #define IN_RANGE_FOR_OFST12_P(value) \ 2888 ((bfd_vma)((value) + 2048) < (bfd_vma)4096) 2889 #define IN_RANGE_FOR_SETLOS_P(value) \ 2890 ((bfd_vma)((value) + 32768) < (bfd_vma)65536) 2891 #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \ 2892 (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info))) 2893 2894 #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \ 2895 (LOCAL_EXEC_P ((info), (picrel)) \ 2896 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info))) 2897 #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \ 2898 (INITIAL_EXEC_P ((info), (picrel)) \ 2899 && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry)) 2900 2901 #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \ 2902 (LOCAL_EXEC_P ((info), (picrel))) 2903 #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \ 2904 (INITIAL_EXEC_P ((info), (picrel))) 2905 2906 #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \ 2907 (LOCAL_EXEC_P ((info), (picrel)) \ 2908 && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info))) 2909 2910 case R_FRV_GETTLSOFF: 2911 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 2912 2913 /* Is this a call instruction? */ 2914 if ((insn & (unsigned long)0x01fc0000) != 0x003c0000) 2915 { 2916 info->callbacks->einfo 2917 (_("%H: R_FRV_GETTLSOFF not applied to a call instruction\n"), 2918 input_bfd, input_section, rel->r_offset); 2919 return FALSE; 2920 } 2921 2922 if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info, picrel, 2923 relocation + rel->r_addend)) 2924 { 2925 /* Replace the call instruction (except the packing bit) 2926 with setlos #tlsmofflo(symbol+offset), gr9. */ 2927 insn &= (unsigned long)0x80000000; 2928 insn |= (unsigned long)0x12fc0000; 2929 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 2930 2931 r_type = R_FRV_TLSMOFFLO; 2932 howto = elf32_frv_howto_table + r_type; 2933 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 2934 } 2935 2936 else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info, picrel)) 2937 { 2938 /* Replace the call instruction (except the packing bit) 2939 with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */ 2940 insn &= (unsigned long)0x80000000; 2941 insn |= (unsigned long)0x12c8f000; 2942 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 2943 2944 r_type = R_FRV_GOTTLSOFF12; 2945 howto = elf32_frv_howto_table + r_type; 2946 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 2947 } 2948 2949 break; 2950 2951 case R_FRV_GOTTLSDESC12: 2952 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 2953 2954 /* Is this an lddi instruction? */ 2955 if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000) 2956 { 2957 info->callbacks->einfo 2958 (_("%H: R_FRV_GOTTLSDESC12" 2959 " not applied to an lddi instruction\n"), 2960 input_bfd, input_section, rel->r_offset); 2961 return FALSE; 2962 } 2963 2964 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 2965 relocation + rel->r_addend) 2966 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, 2967 info)) 2968 { 2969 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC 2970 with setlos #tlsmofflo(symbol+offset), gr<C+1>. 2971 Preserve the packing bit. */ 2972 insn = (insn & (unsigned long)0x80000000) 2973 | ((insn + (unsigned long)0x02000000) 2974 & (unsigned long)0x7e000000); 2975 insn |= (unsigned long)0x00fc0000; 2976 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 2977 2978 r_type = R_FRV_TLSMOFFLO; 2979 howto = elf32_frv_howto_table + r_type; 2980 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 2981 } 2982 2983 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 2984 relocation + rel->r_addend)) 2985 { 2986 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC 2987 with sethi #tlsmoffhi(symbol+offset), gr<C+1>. 2988 Preserve the packing bit. */ 2989 insn = (insn & (unsigned long)0x80000000) 2990 | ((insn + (unsigned long)0x02000000) 2991 & (unsigned long)0x7e000000); 2992 insn |= (unsigned long)0x00f80000; 2993 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 2994 2995 r_type = R_FRV_TLSMOFFHI; 2996 howto = elf32_frv_howto_table + r_type; 2997 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 2998 } 2999 3000 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) 3001 { 3002 /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC 3003 with ldi @(grB, #gottlsoff12(symbol+offset), 3004 gr<C+1>. Preserve the packing bit. If gottlsoff12 3005 overflows, we'll error out, but that's sort-of ok, 3006 since we'd started with gottlsdesc12, that's actually 3007 more demanding. Compiling with -fPIE instead of 3008 -fpie would fix it; linking with --relax should fix 3009 it as well. */ 3010 insn = (insn & (unsigned long)0x80cbf000) 3011 | ((insn + (unsigned long)0x02000000) 3012 & (unsigned long)0x7e000000); 3013 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3014 3015 r_type = R_FRV_GOTTLSOFF12; 3016 howto = elf32_frv_howto_table + r_type; 3017 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3018 } 3019 3020 break; 3021 3022 case R_FRV_GOTTLSDESCHI: 3023 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3024 3025 /* Is this a sethi instruction? */ 3026 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) 3027 { 3028 info->callbacks->einfo 3029 (_("%H: R_FRV_GOTTLSDESCHI" 3030 " not applied to a sethi instruction\n"), 3031 input_bfd, input_section, rel->r_offset); 3032 return FALSE; 3033 } 3034 3035 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3036 relocation + rel->r_addend) 3037 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3038 && IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry))) 3039 { 3040 /* Replace sethi with a nop. Preserve the packing bit. */ 3041 insn &= (unsigned long)0x80000000; 3042 insn |= (unsigned long)0x00880000; 3043 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3044 3045 /* Nothing to relocate. */ 3046 continue; 3047 } 3048 3049 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) 3050 { 3051 /* Simply decay GOTTLSDESC to GOTTLSOFF. */ 3052 r_type = R_FRV_GOTTLSOFFHI; 3053 howto = elf32_frv_howto_table + r_type; 3054 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3055 } 3056 3057 break; 3058 3059 case R_FRV_GOTTLSDESCLO: 3060 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3061 3062 /* Is this a setlo or setlos instruction? */ 3063 if ((insn & (unsigned long)0x01f70000) != 0x00f40000) 3064 { 3065 info->callbacks->einfo 3066 (_("%H: R_FRV_GOTTLSDESCLO" 3067 " not applied to a setlo or setlos instruction\n"), 3068 input_bfd, input_section, rel->r_offset); 3069 return FALSE; 3070 } 3071 3072 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3073 relocation + rel->r_addend) 3074 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3075 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) 3076 { 3077 /* Replace setlo/setlos with a nop. Preserve the 3078 packing bit. */ 3079 insn &= (unsigned long)0x80000000; 3080 insn |= (unsigned long)0x00880000; 3081 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3082 3083 /* Nothing to relocate. */ 3084 continue; 3085 } 3086 3087 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) 3088 { 3089 /* If the corresponding sethi (if it exists) decayed 3090 to a nop, make sure this becomes (or already is) a 3091 setlos, not setlo. */ 3092 if (IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry)) 3093 { 3094 insn |= (unsigned long)0x00080000; 3095 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3096 } 3097 3098 /* Simply decay GOTTLSDESC to GOTTLSOFF. */ 3099 r_type = R_FRV_GOTTLSOFFLO; 3100 howto = elf32_frv_howto_table + r_type; 3101 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3102 } 3103 3104 break; 3105 3106 case R_FRV_TLSDESC_RELAX: 3107 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3108 3109 /* Is this an ldd instruction? */ 3110 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140) 3111 { 3112 info->callbacks->einfo 3113 (_("%H: R_FRV_TLSDESC_RELAX" 3114 " not applied to an ldd instruction\n"), 3115 input_bfd, input_section, rel->r_offset); 3116 return FALSE; 3117 } 3118 3119 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3120 relocation + rel->r_addend) 3121 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, 3122 info)) 3123 { 3124 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC 3125 with setlos #tlsmofflo(symbol+offset), gr<C+1>. 3126 Preserve the packing bit. */ 3127 insn = (insn & (unsigned long)0x80000000) 3128 | ((insn + (unsigned long)0x02000000) 3129 & (unsigned long)0x7e000000); 3130 insn |= (unsigned long)0x00fc0000; 3131 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3132 3133 r_type = R_FRV_TLSMOFFLO; 3134 howto = elf32_frv_howto_table + r_type; 3135 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3136 } 3137 3138 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3139 relocation + rel->r_addend)) 3140 { 3141 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC 3142 with sethi #tlsmoffhi(symbol+offset), gr<C+1>. 3143 Preserve the packing bit. */ 3144 insn = (insn & (unsigned long)0x80000000) 3145 | ((insn + (unsigned long)0x02000000) 3146 & (unsigned long)0x7e000000); 3147 insn |= (unsigned long)0x00f80000; 3148 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3149 3150 r_type = R_FRV_TLSMOFFHI; 3151 howto = elf32_frv_howto_table + r_type; 3152 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3153 } 3154 3155 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3156 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)) 3157 { 3158 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC 3159 with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>. 3160 Preserve the packing bit. */ 3161 insn = (insn & (unsigned long)0x8003f000) 3162 | (unsigned long)0x00c80000 3163 | ((insn + (unsigned long)0x02000000) 3164 & (unsigned long)0x7e000000); 3165 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3166 3167 r_type = R_FRV_GOTTLSOFF12; 3168 howto = elf32_frv_howto_table + r_type; 3169 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3170 } 3171 3172 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) 3173 { 3174 /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC 3175 with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>. 3176 Preserve the packing bit. */ 3177 insn = (insn & (unsigned long)0x81ffffbf) 3178 | ((insn + (unsigned long)0x02000000) 3179 & (unsigned long)0x7e000000); 3180 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3181 3182 /* #tlsoff(symbol+offset) is just a relaxation 3183 annotation, so there's nothing left to 3184 relocate. */ 3185 continue; 3186 } 3187 3188 break; 3189 3190 case R_FRV_GETTLSOFF_RELAX: 3191 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3192 3193 /* Is this a calll or callil instruction? */ 3194 if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000) 3195 { 3196 info->callbacks->einfo 3197 (_("%H: R_FRV_GETTLSOFF_RELAX" 3198 " not applied to a calll instruction\n"), 3199 input_bfd, input_section, rel->r_offset); 3200 return FALSE; 3201 } 3202 3203 if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3204 relocation + rel->r_addend) 3205 && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, 3206 info)) 3207 { 3208 /* Replace calll with a nop. Preserve the packing bit. */ 3209 insn &= (unsigned long)0x80000000; 3210 insn |= (unsigned long)0x00880000; 3211 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3212 3213 /* Nothing to relocate. */ 3214 continue; 3215 } 3216 3217 else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel, 3218 relocation + rel->r_addend)) 3219 { 3220 /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9. 3221 Preserve the packing bit. */ 3222 insn &= (unsigned long)0x80000000; 3223 insn |= (unsigned long)0x12f40000; 3224 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3225 3226 r_type = R_FRV_TLSMOFFLO; 3227 howto = elf32_frv_howto_table + r_type; 3228 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3229 } 3230 3231 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)) 3232 { 3233 /* Replace calll with a nop. Preserve the packing bit. */ 3234 insn &= (unsigned long)0x80000000; 3235 insn |= (unsigned long)0x00880000; 3236 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3237 3238 /* Nothing to relocate. */ 3239 continue; 3240 } 3241 3242 break; 3243 3244 case R_FRV_GOTTLSOFF12: 3245 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3246 3247 /* Is this an ldi instruction? */ 3248 if ((insn & (unsigned long)0x01fc0000) != 0x00c80000) 3249 { 3250 info->callbacks->einfo 3251 (_("%H: R_FRV_GOTTLSOFF12" 3252 " not applied to an ldi instruction\n"), 3253 input_bfd, input_section, rel->r_offset); 3254 return FALSE; 3255 } 3256 3257 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, 3258 relocation + rel->r_addend)) 3259 { 3260 /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC 3261 with setlos #tlsmofflo(symbol+offset), grC. 3262 Preserve the packing bit. */ 3263 insn &= (unsigned long)0xfe000000; 3264 insn |= (unsigned long)0x00fc0000; 3265 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3266 3267 r_type = R_FRV_TLSMOFFLO; 3268 howto = elf32_frv_howto_table + r_type; 3269 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3270 } 3271 3272 break; 3273 3274 case R_FRV_GOTTLSOFFHI: 3275 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3276 3277 /* Is this a sethi instruction? */ 3278 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) 3279 { 3280 info->callbacks->einfo 3281 (_("%H: R_FRV_GOTTLSOFFHI" 3282 " not applied to a sethi instruction\n"), 3283 input_bfd, input_section, rel->r_offset); 3284 return FALSE; 3285 } 3286 3287 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, 3288 relocation + rel->r_addend) 3289 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3290 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) 3291 { 3292 /* Replace sethi with a nop. Preserve the packing bit. */ 3293 insn &= (unsigned long)0x80000000; 3294 insn |= (unsigned long)0x00880000; 3295 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3296 3297 /* Nothing to relocate. */ 3298 continue; 3299 } 3300 3301 break; 3302 3303 case R_FRV_GOTTLSOFFLO: 3304 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3305 3306 /* Is this a setlo or setlos instruction? */ 3307 if ((insn & (unsigned long)0x01f70000) != 0x00f40000) 3308 { 3309 info->callbacks->einfo 3310 (_("%H: R_FRV_GOTTLSOFFLO" 3311 " not applied to a setlo or setlos instruction\n"), 3312 input_bfd, input_section, rel->r_offset); 3313 return FALSE; 3314 } 3315 3316 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, 3317 relocation + rel->r_addend) 3318 || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3319 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))) 3320 { 3321 /* Replace setlo/setlos with a nop. Preserve the 3322 packing bit. */ 3323 insn &= (unsigned long)0x80000000; 3324 insn |= (unsigned long)0x00880000; 3325 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3326 3327 /* Nothing to relocate. */ 3328 continue; 3329 } 3330 3331 break; 3332 3333 case R_FRV_TLSOFF_RELAX: 3334 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3335 3336 /* Is this an ld instruction? */ 3337 if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100) 3338 { 3339 info->callbacks->einfo 3340 (_("%H: R_FRV_TLSOFF_RELAX" 3341 " not applied to an ld instruction\n"), 3342 input_bfd, input_section, rel->r_offset); 3343 return FALSE; 3344 } 3345 3346 if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel, 3347 relocation + rel->r_addend)) 3348 { 3349 /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC 3350 with setlos #tlsmofflo(symbol+offset), grC. 3351 Preserve the packing bit. */ 3352 insn &= (unsigned long)0xfe000000; 3353 insn |= (unsigned long)0x00fc0000; 3354 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3355 3356 r_type = R_FRV_TLSMOFFLO; 3357 howto = elf32_frv_howto_table + r_type; 3358 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3359 } 3360 3361 else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel) 3362 && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)) 3363 { 3364 /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC 3365 with ldi @(grB, #gottlsoff12(symbol+offset), grC. 3366 Preserve the packing bit. */ 3367 insn = (insn & (unsigned long)0xfe03f000) 3368 | (unsigned long)0x00c80000; 3369 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3370 3371 r_type = R_FRV_GOTTLSOFF12; 3372 howto = elf32_frv_howto_table + r_type; 3373 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 3374 } 3375 3376 break; 3377 3378 case R_FRV_TLSMOFFHI: 3379 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3380 3381 /* Is this a sethi instruction? */ 3382 if ((insn & (unsigned long)0x01ff0000) != 0x00f80000) 3383 { 3384 info->callbacks->einfo 3385 (_("%H: R_FRV_TLSMOFFHI" 3386 " not applied to a sethi instruction\n"), 3387 input_bfd, input_section, rel->r_offset); 3388 return FALSE; 3389 } 3390 3391 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, 3392 info)) 3393 { 3394 /* Replace sethi with a nop. Preserve the packing bit. */ 3395 insn &= (unsigned long)0x80000000; 3396 insn |= (unsigned long)0x00880000; 3397 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3398 3399 /* Nothing to relocate. */ 3400 continue; 3401 } 3402 3403 break; 3404 3405 case R_FRV_TLSMOFFLO: 3406 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 3407 3408 /* Is this a setlo or setlos instruction? */ 3409 if ((insn & (unsigned long)0x01f70000) != 0x00f40000) 3410 { 3411 info->callbacks->einfo 3412 (_("R_FRV_TLSMOFFLO" 3413 " not applied to a setlo or setlos instruction\n"), 3414 input_bfd, input_section, rel->r_offset); 3415 return FALSE; 3416 } 3417 3418 if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend, 3419 info)) 3420 /* If the corresponding sethi (if it exists) decayed 3421 to a nop, make sure this becomes (or already is) a 3422 setlos, not setlo. */ 3423 { 3424 insn |= (unsigned long)0x00080000; 3425 bfd_put_32 (input_bfd, insn, contents + rel->r_offset); 3426 } 3427 3428 break; 3429 3430 /* 3431 There's nothing to relax in these: 3432 R_FRV_TLSDESC_VALUE 3433 R_FRV_TLSOFF 3434 R_FRV_TLSMOFF12 3435 R_FRV_TLSMOFFHI 3436 R_FRV_TLSMOFFLO 3437 R_FRV_TLSMOFF 3438 */ 3439 3440 default: 3441 break; 3442 } 3443 3444 switch (r_type) 3445 { 3446 case R_FRV_LABEL24: 3447 check_segment[0] = isec_segment; 3448 if (! IS_FDPIC (output_bfd)) 3449 check_segment[1] = isec_segment; 3450 else if (picrel->plt) 3451 { 3452 relocation = frvfdpic_plt_section (info)->output_section->vma 3453 + frvfdpic_plt_section (info)->output_offset 3454 + picrel->plt_entry; 3455 check_segment[1] = plt_segment; 3456 } 3457 /* We don't want to warn on calls to undefined weak symbols, 3458 as calls to them must be protected by non-NULL tests 3459 anyway, and unprotected calls would invoke undefined 3460 behavior. */ 3461 else if (picrel->symndx == -1 3462 && picrel->d.h->root.type == bfd_link_hash_undefweak) 3463 check_segment[1] = check_segment[0]; 3464 else 3465 check_segment[1] = sec 3466 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3467 : (unsigned)-1; 3468 break; 3469 3470 case R_FRV_GOT12: 3471 case R_FRV_GOTHI: 3472 case R_FRV_GOTLO: 3473 relocation = picrel->got_entry; 3474 check_segment[0] = check_segment[1] = got_segment; 3475 break; 3476 3477 case R_FRV_FUNCDESC_GOT12: 3478 case R_FRV_FUNCDESC_GOTHI: 3479 case R_FRV_FUNCDESC_GOTLO: 3480 relocation = picrel->fdgot_entry; 3481 check_segment[0] = check_segment[1] = got_segment; 3482 break; 3483 3484 case R_FRV_GOTOFFHI: 3485 case R_FRV_GOTOFF12: 3486 case R_FRV_GOTOFFLO: 3487 relocation -= frvfdpic_got_section (info)->output_section->vma 3488 + frvfdpic_got_section (info)->output_offset 3489 + frvfdpic_got_initial_offset (info); 3490 check_segment[0] = got_segment; 3491 check_segment[1] = sec 3492 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3493 : (unsigned)-1; 3494 break; 3495 3496 case R_FRV_FUNCDESC_GOTOFF12: 3497 case R_FRV_FUNCDESC_GOTOFFHI: 3498 case R_FRV_FUNCDESC_GOTOFFLO: 3499 relocation = picrel->fd_entry; 3500 check_segment[0] = check_segment[1] = got_segment; 3501 break; 3502 3503 case R_FRV_FUNCDESC: 3504 { 3505 int dynindx; 3506 bfd_vma addend = rel->r_addend; 3507 3508 if (! (h && h->root.type == bfd_link_hash_undefweak 3509 && FRVFDPIC_SYM_LOCAL (info, h))) 3510 { 3511 /* If the symbol is dynamic and there may be dynamic 3512 symbol resolution because we are or are linked with a 3513 shared library, emit a FUNCDESC relocation such that 3514 the dynamic linker will allocate the function 3515 descriptor. If the symbol needs a non-local function 3516 descriptor but binds locally (e.g., its visibility is 3517 protected, emit a dynamic relocation decayed to 3518 section+offset. */ 3519 if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h) 3520 && FRVFDPIC_SYM_LOCAL (info, h) 3521 && !(info->executable && !info->pie)) 3522 { 3523 dynindx = elf_section_data (h->root.u.def.section 3524 ->output_section)->dynindx; 3525 addend += h->root.u.def.section->output_offset 3526 + h->root.u.def.value; 3527 } 3528 else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)) 3529 { 3530 if (addend) 3531 { 3532 info->callbacks->einfo 3533 (_("%H: R_FRV_FUNCDESC references dynamic symbol" 3534 " with nonzero addend\n"), 3535 input_bfd, input_section, rel->r_offset); 3536 return FALSE; 3537 } 3538 dynindx = h->dynindx; 3539 } 3540 else 3541 { 3542 /* Otherwise, we know we have a private function 3543 descriptor, so reference it directly. */ 3544 BFD_ASSERT (picrel->privfd); 3545 r_type = R_FRV_32; 3546 dynindx = elf_section_data (frvfdpic_got_section (info) 3547 ->output_section)->dynindx; 3548 addend = frvfdpic_got_section (info)->output_offset 3549 + frvfdpic_got_initial_offset (info) 3550 + picrel->fd_entry; 3551 } 3552 3553 /* If there is room for dynamic symbol resolution, emit 3554 the dynamic relocation. However, if we're linking an 3555 executable at a fixed location, we won't have emitted a 3556 dynamic symbol entry for the got section, so idx will 3557 be zero, which means we can and should compute the 3558 address of the private descriptor ourselves. */ 3559 if (info->executable && !info->pie 3560 && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h))) 3561 { 3562 addend += frvfdpic_got_section (info)->output_section->vma; 3563 if ((bfd_get_section_flags (output_bfd, 3564 input_section->output_section) 3565 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 3566 { 3567 bfd_vma offset; 3568 3569 if (_frvfdpic_osec_readonly_p (output_bfd, 3570 input_section 3571 ->output_section)) 3572 { 3573 info->callbacks->einfo 3574 (_("%H: cannot emit fixups" 3575 " in read-only section\n"), 3576 input_bfd, input_section, rel->r_offset); 3577 return FALSE; 3578 } 3579 3580 offset = _bfd_elf_section_offset 3581 (output_bfd, info, 3582 input_section, rel->r_offset); 3583 3584 if (offset != (bfd_vma)-1) 3585 _frvfdpic_add_rofixup (output_bfd, 3586 frvfdpic_gotfixup_section 3587 (info), 3588 offset + input_section 3589 ->output_section->vma 3590 + input_section->output_offset, 3591 picrel); 3592 } 3593 } 3594 else if ((bfd_get_section_flags (output_bfd, 3595 input_section->output_section) 3596 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 3597 { 3598 bfd_vma offset; 3599 3600 if (_frvfdpic_osec_readonly_p (output_bfd, 3601 input_section 3602 ->output_section)) 3603 { 3604 info->callbacks->einfo 3605 (_("%H: cannot emit dynamic relocations" 3606 " in read-only section\n"), 3607 input_bfd, input_section, rel->r_offset); 3608 return FALSE; 3609 } 3610 3611 offset = _bfd_elf_section_offset 3612 (output_bfd, info, 3613 input_section, rel->r_offset); 3614 3615 if (offset != (bfd_vma)-1) 3616 _frvfdpic_add_dyn_reloc (output_bfd, 3617 frvfdpic_gotrel_section (info), 3618 offset + input_section 3619 ->output_section->vma 3620 + input_section->output_offset, 3621 r_type, dynindx, addend, picrel); 3622 } 3623 else 3624 addend += frvfdpic_got_section (info)->output_section->vma; 3625 } 3626 3627 /* We want the addend in-place because dynamic 3628 relocations are REL. Setting relocation to it should 3629 arrange for it to be installed. */ 3630 relocation = addend - rel->r_addend; 3631 } 3632 check_segment[0] = check_segment[1] = got_segment; 3633 break; 3634 3635 case R_FRV_32: 3636 if (! IS_FDPIC (output_bfd)) 3637 { 3638 check_segment[0] = check_segment[1] = -1; 3639 break; 3640 } 3641 /* Fall through. */ 3642 case R_FRV_FUNCDESC_VALUE: 3643 { 3644 int dynindx; 3645 bfd_vma addend = rel->r_addend; 3646 3647 /* If the symbol is dynamic but binds locally, use 3648 section+offset. */ 3649 if (h && ! FRVFDPIC_SYM_LOCAL (info, h)) 3650 { 3651 if (addend && r_type == R_FRV_FUNCDESC_VALUE) 3652 { 3653 info->callbacks->einfo 3654 (_("%H: R_FRV_FUNCDESC_VALUE" 3655 " references dynamic symbol with nonzero addend\n"), 3656 input_bfd, input_section, rel->r_offset); 3657 return FALSE; 3658 } 3659 dynindx = h->dynindx; 3660 } 3661 else 3662 { 3663 if (h) 3664 addend += h->root.u.def.value; 3665 else 3666 addend += sym->st_value; 3667 if (osec) 3668 addend += osec->output_offset; 3669 if (osec && osec->output_section 3670 && ! bfd_is_abs_section (osec->output_section) 3671 && ! bfd_is_und_section (osec->output_section)) 3672 dynindx = elf_section_data (osec->output_section)->dynindx; 3673 else 3674 dynindx = 0; 3675 } 3676 3677 /* If we're linking an executable at a fixed address, we 3678 can omit the dynamic relocation as long as the symbol 3679 is defined in the current link unit (which is implied 3680 by its output section not being NULL). */ 3681 if (info->executable && !info->pie 3682 && (!h || FRVFDPIC_SYM_LOCAL (info, h))) 3683 { 3684 if (osec) 3685 addend += osec->output_section->vma; 3686 if (IS_FDPIC (input_bfd) 3687 && (bfd_get_section_flags (output_bfd, 3688 input_section->output_section) 3689 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 3690 { 3691 if (_frvfdpic_osec_readonly_p (output_bfd, 3692 input_section 3693 ->output_section)) 3694 { 3695 info->callbacks->einfo 3696 (_("%H: cannot emit fixups in read-only section\n"), 3697 input_bfd, input_section, rel->r_offset); 3698 return FALSE; 3699 } 3700 if (!h || h->root.type != bfd_link_hash_undefweak) 3701 { 3702 bfd_vma offset = _bfd_elf_section_offset 3703 (output_bfd, info, 3704 input_section, rel->r_offset); 3705 3706 if (offset != (bfd_vma)-1) 3707 { 3708 _frvfdpic_add_rofixup (output_bfd, 3709 frvfdpic_gotfixup_section 3710 (info), 3711 offset + input_section 3712 ->output_section->vma 3713 + input_section->output_offset, 3714 picrel); 3715 if (r_type == R_FRV_FUNCDESC_VALUE) 3716 _frvfdpic_add_rofixup 3717 (output_bfd, 3718 frvfdpic_gotfixup_section (info), 3719 offset 3720 + input_section->output_section->vma 3721 + input_section->output_offset + 4, picrel); 3722 } 3723 } 3724 } 3725 } 3726 else 3727 { 3728 if ((bfd_get_section_flags (output_bfd, 3729 input_section->output_section) 3730 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 3731 { 3732 bfd_vma offset; 3733 3734 if (_frvfdpic_osec_readonly_p (output_bfd, 3735 input_section 3736 ->output_section)) 3737 { 3738 info->callbacks->einfo 3739 (_("%H: cannot emit dynamic relocations" 3740 " in read-only section\n"), 3741 input_bfd, input_section, rel->r_offset); 3742 return FALSE; 3743 } 3744 3745 offset = _bfd_elf_section_offset 3746 (output_bfd, info, 3747 input_section, rel->r_offset); 3748 3749 if (offset != (bfd_vma)-1) 3750 _frvfdpic_add_dyn_reloc (output_bfd, 3751 frvfdpic_gotrel_section (info), 3752 offset + input_section 3753 ->output_section->vma 3754 + input_section->output_offset, 3755 r_type, dynindx, addend, picrel); 3756 } 3757 else if (osec) 3758 addend += osec->output_section->vma; 3759 /* We want the addend in-place because dynamic 3760 relocations are REL. Setting relocation to it 3761 should arrange for it to be installed. */ 3762 relocation = addend - rel->r_addend; 3763 } 3764 3765 if (r_type == R_FRV_FUNCDESC_VALUE) 3766 { 3767 /* If we've omitted the dynamic relocation, just emit 3768 the fixed addresses of the symbol and of the local 3769 GOT base offset. */ 3770 if (info->executable && !info->pie 3771 && (!h || FRVFDPIC_SYM_LOCAL (info, h))) 3772 bfd_put_32 (output_bfd, 3773 frvfdpic_got_section (info)->output_section->vma 3774 + frvfdpic_got_section (info)->output_offset 3775 + frvfdpic_got_initial_offset (info), 3776 contents + rel->r_offset + 4); 3777 else 3778 /* A function descriptor used for lazy or local 3779 resolving is initialized such that its high word 3780 contains the output section index in which the 3781 PLT entries are located, and the low word 3782 contains the offset of the lazy PLT entry entry 3783 point into that section. */ 3784 bfd_put_32 (output_bfd, 3785 h && ! FRVFDPIC_SYM_LOCAL (info, h) 3786 ? 0 3787 : _frvfdpic_osec_to_segment (output_bfd, 3788 sec 3789 ->output_section), 3790 contents + rel->r_offset + 4); 3791 } 3792 } 3793 check_segment[0] = check_segment[1] = got_segment; 3794 break; 3795 3796 case R_FRV_GPREL12: 3797 case R_FRV_GPRELU12: 3798 case R_FRV_GPREL32: 3799 case R_FRV_GPRELHI: 3800 case R_FRV_GPRELLO: 3801 check_segment[0] = gprel_segment; 3802 check_segment[1] = sec 3803 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3804 : (unsigned)-1; 3805 break; 3806 3807 case R_FRV_GETTLSOFF: 3808 relocation = frvfdpic_plt_section (info)->output_section->vma 3809 + frvfdpic_plt_section (info)->output_offset 3810 + picrel->tlsplt_entry; 3811 BFD_ASSERT (picrel->tlsplt_entry != (bfd_vma)-1 3812 && picrel->tlsdesc_entry); 3813 check_segment[0] = isec_segment; 3814 check_segment[1] = plt_segment; 3815 break; 3816 3817 case R_FRV_GOTTLSDESC12: 3818 case R_FRV_GOTTLSDESCHI: 3819 case R_FRV_GOTTLSDESCLO: 3820 BFD_ASSERT (picrel->tlsdesc_entry); 3821 relocation = picrel->tlsdesc_entry; 3822 check_segment[0] = tls_segment; 3823 check_segment[1] = sec 3824 && ! bfd_is_abs_section (sec) 3825 && ! bfd_is_und_section (sec) 3826 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3827 : tls_segment; 3828 break; 3829 3830 case R_FRV_TLSMOFF12: 3831 case R_FRV_TLSMOFFHI: 3832 case R_FRV_TLSMOFFLO: 3833 case R_FRV_TLSMOFF: 3834 check_segment[0] = tls_segment; 3835 if (! sec) 3836 check_segment[1] = -1; 3837 else if (bfd_is_abs_section (sec) 3838 || bfd_is_und_section (sec)) 3839 { 3840 relocation = 0; 3841 check_segment[1] = tls_segment; 3842 } 3843 else if (sec->output_section) 3844 { 3845 relocation -= tls_biased_base (info); 3846 check_segment[1] = 3847 _frvfdpic_osec_to_segment (output_bfd, sec->output_section); 3848 } 3849 else 3850 check_segment[1] = -1; 3851 break; 3852 3853 case R_FRV_GOTTLSOFF12: 3854 case R_FRV_GOTTLSOFFHI: 3855 case R_FRV_GOTTLSOFFLO: 3856 BFD_ASSERT (picrel->tlsoff_entry); 3857 relocation = picrel->tlsoff_entry; 3858 check_segment[0] = tls_segment; 3859 check_segment[1] = sec 3860 && ! bfd_is_abs_section (sec) 3861 && ! bfd_is_und_section (sec) 3862 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3863 : tls_segment; 3864 break; 3865 3866 case R_FRV_TLSDESC_VALUE: 3867 case R_FRV_TLSOFF: 3868 /* These shouldn't be present in input object files. */ 3869 check_segment[0] = check_segment[1] = isec_segment; 3870 break; 3871 3872 case R_FRV_TLSDESC_RELAX: 3873 case R_FRV_GETTLSOFF_RELAX: 3874 case R_FRV_TLSOFF_RELAX: 3875 /* These are just annotations for relaxation, nothing to do 3876 here. */ 3877 continue; 3878 3879 default: 3880 check_segment[0] = isec_segment; 3881 check_segment[1] = sec 3882 ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section) 3883 : (unsigned)-1; 3884 break; 3885 } 3886 3887 if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd)) 3888 { 3889 /* If you take this out, remove the #error from fdpic-static-6.d 3890 in the ld testsuite. */ 3891 /* This helps catch problems in GCC while we can't do more 3892 than static linking. The idea is to test whether the 3893 input file basename is crt0.o only once. */ 3894 if (silence_segment_error == 1) 3895 silence_segment_error = 3896 (strlen (input_bfd->filename) == 6 3897 && filename_cmp (input_bfd->filename, "crt0.o") == 0) 3898 || (strlen (input_bfd->filename) > 6 3899 && filename_cmp (input_bfd->filename 3900 + strlen (input_bfd->filename) - 7, 3901 "/crt0.o") == 0) 3902 ? -1 : 0; 3903 if (!silence_segment_error 3904 /* We don't want duplicate errors for undefined 3905 symbols. */ 3906 && !(picrel && picrel->symndx == -1 3907 && picrel->d.h->root.type == bfd_link_hash_undefined)) 3908 { 3909 info->callbacks->einfo 3910 (_("%H: reloc against `%s' references a different segment\n"), 3911 input_bfd, input_section, rel->r_offset, name); 3912 } 3913 if (!silence_segment_error && (info->shared || info->pie)) 3914 return FALSE; 3915 elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC; 3916 } 3917 3918 switch (r_type) 3919 { 3920 case R_FRV_GOTOFFHI: 3921 case R_FRV_TLSMOFFHI: 3922 /* We need the addend to be applied before we shift the 3923 value right. */ 3924 relocation += rel->r_addend; 3925 /* Fall through. */ 3926 case R_FRV_GOTHI: 3927 case R_FRV_FUNCDESC_GOTHI: 3928 case R_FRV_FUNCDESC_GOTOFFHI: 3929 case R_FRV_GOTTLSOFFHI: 3930 case R_FRV_GOTTLSDESCHI: 3931 relocation >>= 16; 3932 /* Fall through. */ 3933 3934 case R_FRV_GOTLO: 3935 case R_FRV_FUNCDESC_GOTLO: 3936 case R_FRV_GOTOFFLO: 3937 case R_FRV_FUNCDESC_GOTOFFLO: 3938 case R_FRV_GOTTLSOFFLO: 3939 case R_FRV_GOTTLSDESCLO: 3940 case R_FRV_TLSMOFFLO: 3941 relocation &= 0xffff; 3942 break; 3943 3944 default: 3945 break; 3946 } 3947 3948 switch (r_type) 3949 { 3950 case R_FRV_LABEL24: 3951 if (! IS_FDPIC (output_bfd) || ! picrel->plt) 3952 break; 3953 /* Fall through. */ 3954 3955 /* When referencing a GOT entry, a function descriptor or a 3956 PLT, we don't want the addend to apply to the reference, 3957 but rather to the referenced symbol. The actual entry 3958 will have already been created taking the addend into 3959 account, so cancel it out here. */ 3960 case R_FRV_GOT12: 3961 case R_FRV_GOTHI: 3962 case R_FRV_GOTLO: 3963 case R_FRV_FUNCDESC_GOT12: 3964 case R_FRV_FUNCDESC_GOTHI: 3965 case R_FRV_FUNCDESC_GOTLO: 3966 case R_FRV_FUNCDESC_GOTOFF12: 3967 case R_FRV_FUNCDESC_GOTOFFHI: 3968 case R_FRV_FUNCDESC_GOTOFFLO: 3969 case R_FRV_GETTLSOFF: 3970 case R_FRV_GOTTLSDESC12: 3971 case R_FRV_GOTTLSDESCHI: 3972 case R_FRV_GOTTLSDESCLO: 3973 case R_FRV_GOTTLSOFF12: 3974 case R_FRV_GOTTLSOFFHI: 3975 case R_FRV_GOTTLSOFFLO: 3976 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12 3977 here, since we do want to apply the addend to the others. 3978 Note that we've applied the addend to GOTOFFHI before we 3979 shifted it right. */ 3980 case R_FRV_GOTOFFHI: 3981 case R_FRV_TLSMOFFHI: 3982 relocation -= rel->r_addend; 3983 break; 3984 3985 default: 3986 break; 3987 } 3988 3989 if (r_type == R_FRV_HI16) 3990 r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation); 3991 3992 else if (r_type == R_FRV_LO16) 3993 r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation); 3994 3995 else if (r_type == R_FRV_LABEL24 || r_type == R_FRV_GETTLSOFF) 3996 r = elf32_frv_relocate_label24 (input_bfd, input_section, rel, 3997 contents, relocation); 3998 3999 else if (r_type == R_FRV_GPREL12) 4000 r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel, 4001 contents, relocation); 4002 4003 else if (r_type == R_FRV_GPRELU12) 4004 r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel, 4005 contents, relocation); 4006 4007 else if (r_type == R_FRV_GPRELLO) 4008 r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel, 4009 contents, relocation); 4010 4011 else if (r_type == R_FRV_GPRELHI) 4012 r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel, 4013 contents, relocation); 4014 4015 else if (r_type == R_FRV_TLSOFF 4016 || r_type == R_FRV_TLSDESC_VALUE) 4017 r = bfd_reloc_notsupported; 4018 4019 else 4020 r = frv_final_link_relocate (howto, input_bfd, input_section, contents, 4021 rel, relocation); 4022 4023 if (r != bfd_reloc_ok) 4024 { 4025 const char * msg = (const char *) NULL; 4026 4027 switch (r) 4028 { 4029 case bfd_reloc_overflow: 4030 r = info->callbacks->reloc_overflow 4031 (info, (h ? &h->root : NULL), name, howto->name, 4032 (bfd_vma) 0, input_bfd, input_section, rel->r_offset); 4033 break; 4034 4035 case bfd_reloc_undefined: 4036 r = info->callbacks->undefined_symbol 4037 (info, name, input_bfd, input_section, rel->r_offset, TRUE); 4038 break; 4039 4040 case bfd_reloc_outofrange: 4041 msg = _("internal error: out of range error"); 4042 break; 4043 4044 case bfd_reloc_notsupported: 4045 msg = _("internal error: unsupported relocation error"); 4046 break; 4047 4048 case bfd_reloc_dangerous: 4049 msg = _("internal error: dangerous relocation"); 4050 break; 4051 4052 default: 4053 msg = _("internal error: unknown error"); 4054 break; 4055 } 4056 4057 if (msg) 4058 { 4059 info->callbacks->einfo 4060 (_("%H: reloc against `%s': %s\n"), 4061 input_bfd, input_section, rel->r_offset, name, msg); 4062 return FALSE; 4063 } 4064 4065 if (! r) 4066 return FALSE; 4067 } 4068 } 4069 4070 return TRUE; 4071 } 4072 4073 /* Return the section that should be marked against GC for a given 4075 relocation. */ 4076 4077 static asection * 4078 elf32_frv_gc_mark_hook (asection *sec, 4079 struct bfd_link_info *info, 4080 Elf_Internal_Rela *rel, 4081 struct elf_link_hash_entry *h, 4082 Elf_Internal_Sym *sym) 4083 { 4084 if (h != NULL) 4085 switch (ELF32_R_TYPE (rel->r_info)) 4086 { 4087 case R_FRV_GNU_VTINHERIT: 4088 case R_FRV_GNU_VTENTRY: 4089 return NULL; 4090 } 4091 4092 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); 4093 } 4094 4095 /* Hook called by the linker routine which adds symbols from an object 4097 file. We use it to put .comm items in .scomm, and not .comm. */ 4098 4099 static bfd_boolean 4100 elf32_frv_add_symbol_hook (bfd *abfd, 4101 struct bfd_link_info *info, 4102 Elf_Internal_Sym *sym, 4103 const char **namep ATTRIBUTE_UNUSED, 4104 flagword *flagsp ATTRIBUTE_UNUSED, 4105 asection **secp, 4106 bfd_vma *valp) 4107 { 4108 if (sym->st_shndx == SHN_COMMON 4109 && !info->relocatable 4110 && (int)sym->st_size <= (int)bfd_get_gp_size (abfd)) 4111 { 4112 /* Common symbols less than or equal to -G nn bytes are 4113 automatically put into .sbss. */ 4114 4115 asection *scomm = bfd_get_section_by_name (abfd, ".scommon"); 4116 4117 if (scomm == NULL) 4118 { 4119 scomm = bfd_make_section_with_flags (abfd, ".scommon", 4120 (SEC_ALLOC 4121 | SEC_IS_COMMON 4122 | SEC_LINKER_CREATED)); 4123 if (scomm == NULL) 4124 return FALSE; 4125 } 4126 4127 *secp = scomm; 4128 *valp = sym->st_size; 4129 } 4130 4131 return TRUE; 4132 } 4133 4134 /* We need dynamic symbols for every section, since segments can 4135 relocate independently. */ 4136 static bfd_boolean 4137 _frvfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED, 4138 struct bfd_link_info *info 4139 ATTRIBUTE_UNUSED, 4140 asection *p ATTRIBUTE_UNUSED) 4141 { 4142 switch (elf_section_data (p)->this_hdr.sh_type) 4143 { 4144 case SHT_PROGBITS: 4145 case SHT_NOBITS: 4146 /* If sh_type is yet undecided, assume it could be 4147 SHT_PROGBITS/SHT_NOBITS. */ 4148 case SHT_NULL: 4149 return FALSE; 4150 4151 /* There shouldn't be section relative relocations 4152 against any other section. */ 4153 default: 4154 return TRUE; 4155 } 4156 } 4157 4158 /* Create a .got section, as well as its additional info field. This 4159 is almost entirely copied from 4160 elflink.c:_bfd_elf_create_got_section(). */ 4161 4162 static bfd_boolean 4163 _frv_create_got_section (bfd *abfd, struct bfd_link_info *info) 4164 { 4165 flagword flags, pltflags; 4166 asection *s; 4167 struct elf_link_hash_entry *h; 4168 struct bfd_link_hash_entry *bh; 4169 const struct elf_backend_data *bed = get_elf_backend_data (abfd); 4170 int ptralign; 4171 int offset; 4172 4173 /* This function may be called more than once. */ 4174 s = bfd_get_linker_section (abfd, ".got"); 4175 if (s != NULL) 4176 return TRUE; 4177 4178 /* Machine specific: although pointers are 32-bits wide, we want the 4179 GOT to be aligned to a 64-bit boundary, such that function 4180 descriptors in it can be accessed with 64-bit loads and 4181 stores. */ 4182 ptralign = 3; 4183 4184 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 4185 | SEC_LINKER_CREATED); 4186 pltflags = flags; 4187 4188 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); 4189 if (s == NULL 4190 || !bfd_set_section_alignment (abfd, s, ptralign)) 4191 return FALSE; 4192 4193 if (bed->want_got_plt) 4194 { 4195 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags); 4196 if (s == NULL 4197 || !bfd_set_section_alignment (abfd, s, ptralign)) 4198 return FALSE; 4199 } 4200 4201 if (bed->want_got_sym) 4202 { 4203 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got 4204 (or .got.plt) section. We don't do this in the linker script 4205 because we don't want to define the symbol if we are not creating 4206 a global offset table. */ 4207 h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_"); 4208 elf_hash_table (info)->hgot = h; 4209 if (h == NULL) 4210 return FALSE; 4211 4212 /* Machine-specific: we want the symbol for executables as 4213 well. */ 4214 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 4215 return FALSE; 4216 } 4217 4218 /* The first bit of the global offset table is the header. */ 4219 s->size += bed->got_header_size; 4220 4221 /* This is the machine-specific part. Create and initialize section 4222 data for the got. */ 4223 if (IS_FDPIC (abfd)) 4224 { 4225 frvfdpic_got_section (info) = s; 4226 frvfdpic_relocs_info (info) = htab_try_create (1, 4227 frvfdpic_relocs_info_hash, 4228 frvfdpic_relocs_info_eq, 4229 (htab_del) NULL); 4230 if (! frvfdpic_relocs_info (info)) 4231 return FALSE; 4232 4233 s = bfd_make_section_anyway_with_flags (abfd, ".rel.got", 4234 (flags | SEC_READONLY)); 4235 if (s == NULL 4236 || ! bfd_set_section_alignment (abfd, s, 2)) 4237 return FALSE; 4238 4239 frvfdpic_gotrel_section (info) = s; 4240 4241 /* Machine-specific. */ 4242 s = bfd_make_section_anyway_with_flags (abfd, ".rofixup", 4243 (flags | SEC_READONLY)); 4244 if (s == NULL 4245 || ! bfd_set_section_alignment (abfd, s, 2)) 4246 return FALSE; 4247 4248 frvfdpic_gotfixup_section (info) = s; 4249 offset = -2048; 4250 flags = BSF_GLOBAL; 4251 } 4252 else 4253 { 4254 offset = 2048; 4255 flags = BSF_GLOBAL | BSF_WEAK; 4256 } 4257 4258 /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it 4259 turns out that we're linking with a different linker script, the 4260 linker script will override it. */ 4261 bh = NULL; 4262 if (!(_bfd_generic_link_add_one_symbol 4263 (info, abfd, "_gp", flags, s, offset, (const char *) NULL, FALSE, 4264 bed->collect, &bh))) 4265 return FALSE; 4266 h = (struct elf_link_hash_entry *) bh; 4267 h->def_regular = 1; 4268 h->type = STT_OBJECT; 4269 /* h->other = STV_HIDDEN; */ /* Should we? */ 4270 4271 /* Machine-specific: we want the symbol for executables as well. */ 4272 if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h)) 4273 return FALSE; 4274 4275 if (!IS_FDPIC (abfd)) 4276 return TRUE; 4277 4278 /* FDPIC supports Thread Local Storage, and this may require a 4279 procedure linkage table for TLS PLT entries. */ 4280 4281 /* This is mostly copied from 4282 elflink.c:_bfd_elf_create_dynamic_sections(). */ 4283 4284 flags = pltflags; 4285 pltflags |= SEC_CODE; 4286 if (bed->plt_not_loaded) 4287 pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS); 4288 if (bed->plt_readonly) 4289 pltflags |= SEC_READONLY; 4290 4291 s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags); 4292 if (s == NULL 4293 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) 4294 return FALSE; 4295 /* FRV-specific: remember it. */ 4296 frvfdpic_plt_section (info) = s; 4297 4298 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the 4299 .plt section. */ 4300 if (bed->want_plt_sym) 4301 { 4302 h = _bfd_elf_define_linkage_sym (abfd, info, s, 4303 "_PROCEDURE_LINKAGE_TABLE_"); 4304 elf_hash_table (info)->hplt = h; 4305 if (h == NULL) 4306 return FALSE; 4307 } 4308 4309 /* FRV-specific: we want rel relocations for the plt. */ 4310 s = bfd_make_section_anyway_with_flags (abfd, ".rel.plt", 4311 flags | SEC_READONLY); 4312 if (s == NULL 4313 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) 4314 return FALSE; 4315 /* FRV-specific: remember it. */ 4316 frvfdpic_pltrel_section (info) = s; 4317 4318 return TRUE; 4319 } 4320 4321 /* Make sure the got and plt sections exist, and that our pointers in 4322 the link hash table point to them. */ 4323 4324 static bfd_boolean 4325 elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) 4326 { 4327 /* This is mostly copied from 4328 elflink.c:_bfd_elf_create_dynamic_sections(). */ 4329 flagword flags; 4330 asection *s; 4331 const struct elf_backend_data *bed = get_elf_backend_data (abfd); 4332 4333 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 4334 | SEC_LINKER_CREATED); 4335 4336 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and 4337 .rel[a].bss sections. */ 4338 4339 /* FRV-specific: we want to create the GOT and the PLT in the FRV 4340 way. */ 4341 if (! _frv_create_got_section (abfd, info)) 4342 return FALSE; 4343 4344 /* FRV-specific: make sure we created everything we wanted. */ 4345 BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info) 4346 && frvfdpic_gotfixup_section (info) 4347 && frvfdpic_plt_section (info) 4348 && frvfdpic_pltrel_section (info)); 4349 4350 if (bed->want_dynbss) 4351 { 4352 /* The .dynbss section is a place to put symbols which are defined 4353 by dynamic objects, are referenced by regular objects, and are 4354 not functions. We must allocate space for them in the process 4355 image and use a R_*_COPY reloc to tell the dynamic linker to 4356 initialize them at run time. The linker script puts the .dynbss 4357 section into the .bss section of the final image. */ 4358 s = bfd_make_section_anyway_with_flags (abfd, ".dynbss", 4359 SEC_ALLOC | SEC_LINKER_CREATED); 4360 if (s == NULL) 4361 return FALSE; 4362 4363 /* The .rel[a].bss section holds copy relocs. This section is not 4364 normally needed. We need to create it here, though, so that the 4365 linker will map it to an output section. We can't just create it 4366 only if we need it, because we will not know whether we need it 4367 until we have seen all the input files, and the first time the 4368 main linker code calls BFD after examining all the input files 4369 (size_dynamic_sections) the input sections have already been 4370 mapped to the output sections. If the section turns out not to 4371 be needed, we can discard it later. We will never need this 4372 section when generating a shared object, since they do not use 4373 copy relocs. */ 4374 if (! info->shared) 4375 { 4376 s = bfd_make_section_anyway_with_flags (abfd, 4377 (bed->default_use_rela_p 4378 ? ".rela.bss" : ".rel.bss"), 4379 flags | SEC_READONLY); 4380 if (s == NULL 4381 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) 4382 return FALSE; 4383 } 4384 } 4385 4386 return TRUE; 4387 } 4388 4389 /* Compute the total GOT and PLT size required by each symbol in each 4390 range. Symbols may require up to 4 words in the GOT: an entry 4391 pointing to the symbol, an entry pointing to its function 4392 descriptor, and a private function descriptors taking two 4393 words. */ 4394 4395 static void 4396 _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info *entry, 4397 struct _frvfdpic_dynamic_got_info *dinfo) 4398 { 4399 /* Allocate space for a GOT entry pointing to the symbol. */ 4400 if (entry->got12) 4401 dinfo->got12 += 4; 4402 else if (entry->gotlos) 4403 dinfo->gotlos += 4; 4404 else if (entry->gothilo) 4405 dinfo->gothilo += 4; 4406 else 4407 entry->relocs32--; 4408 entry->relocs32++; 4409 4410 /* Allocate space for a GOT entry pointing to the function 4411 descriptor. */ 4412 if (entry->fdgot12) 4413 dinfo->got12 += 4; 4414 else if (entry->fdgotlos) 4415 dinfo->gotlos += 4; 4416 else if (entry->fdgothilo) 4417 dinfo->gothilo += 4; 4418 else 4419 entry->relocsfd--; 4420 entry->relocsfd++; 4421 4422 /* Decide whether we need a PLT entry, a function descriptor in the 4423 GOT, and a lazy PLT entry for this symbol. */ 4424 entry->plt = entry->call 4425 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) 4426 && elf_hash_table (dinfo->info)->dynamic_sections_created; 4427 entry->privfd = entry->plt 4428 || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo 4429 || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo) 4430 && (entry->symndx != -1 4431 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))); 4432 entry->lazyplt = entry->privfd 4433 && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) 4434 && ! (dinfo->info->flags & DF_BIND_NOW) 4435 && elf_hash_table (dinfo->info)->dynamic_sections_created; 4436 4437 /* Allocate space for a function descriptor. */ 4438 if (entry->fdgoff12) 4439 dinfo->fd12 += 8; 4440 else if (entry->fdgofflos) 4441 dinfo->fdlos += 8; 4442 else if (entry->privfd && entry->plt) 4443 dinfo->fdplt += 8; 4444 else if (entry->privfd) 4445 dinfo->fdhilo += 8; 4446 else 4447 entry->relocsfdv--; 4448 entry->relocsfdv++; 4449 4450 if (entry->lazyplt) 4451 dinfo->lzplt += 8; 4452 } 4453 4454 /* Compute the total GOT size required by each TLS symbol in each 4455 range. Symbols may require up to 5 words in the GOT: an entry 4456 holding the TLS offset for the symbol, and an entry with a full TLS 4457 descriptor taking 4 words. */ 4458 4459 static void 4460 _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info *entry, 4461 struct _frvfdpic_dynamic_got_info *dinfo, 4462 bfd_boolean subtract) 4463 { 4464 const int l = subtract ? -1 : 1; 4465 4466 /* Allocate space for a GOT entry with the TLS offset of the 4467 symbol. */ 4468 if (entry->tlsoff12) 4469 dinfo->got12 += 4 * l; 4470 else if (entry->tlsofflos) 4471 dinfo->gotlos += 4 * l; 4472 else if (entry->tlsoffhilo) 4473 dinfo->gothilo += 4 * l; 4474 else 4475 entry->relocstlsoff -= l; 4476 entry->relocstlsoff += l; 4477 4478 /* If there's any TLSOFF relocation, mark the output file as not 4479 suitable for dlopening. This mark will remain even if we relax 4480 all such relocations, but this is not a problem, since we'll only 4481 do so for executables, and we definitely don't want anyone 4482 dlopening executables. */ 4483 if (entry->relocstlsoff) 4484 dinfo->info->flags |= DF_STATIC_TLS; 4485 4486 /* Allocate space for a TLS descriptor. */ 4487 if (entry->tlsdesc12) 4488 dinfo->tlsd12 += 8 * l; 4489 else if (entry->tlsdesclos) 4490 dinfo->tlsdlos += 8 * l; 4491 else if (entry->tlsplt) 4492 dinfo->tlsdplt += 8 * l; 4493 else if (entry->tlsdeschilo) 4494 dinfo->tlsdhilo += 8 * l; 4495 else 4496 entry->relocstlsd -= l; 4497 entry->relocstlsd += l; 4498 } 4499 4500 /* Compute the number of dynamic relocations and fixups that a symbol 4501 requires, and add (or subtract) from the grand and per-symbol 4502 totals. */ 4503 4504 static void 4505 _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info *entry, 4506 struct _frvfdpic_dynamic_got_info *dinfo, 4507 bfd_boolean subtract) 4508 { 4509 bfd_vma relocs = 0, fixups = 0, tlsrets = 0; 4510 4511 if (!dinfo->info->executable || dinfo->info->pie) 4512 { 4513 relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv 4514 + entry->relocstlsd; 4515 4516 /* In the executable, TLS relocations to symbols that bind 4517 locally (including those that resolve to global TLS offsets) 4518 are resolved immediately, without any need for fixups or 4519 dynamic relocations. In shared libraries, however, we must 4520 emit dynamic relocations even for local symbols, because we 4521 don't know the module id the library is going to get at 4522 run-time, nor its TLS base offset. */ 4523 if (!dinfo->info->executable 4524 || (entry->symndx == -1 4525 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))) 4526 relocs += entry->relocstlsoff; 4527 } 4528 else 4529 { 4530 if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)) 4531 { 4532 if (entry->symndx != -1 4533 || entry->d.h->root.type != bfd_link_hash_undefweak) 4534 fixups += entry->relocs32 + 2 * entry->relocsfdv; 4535 fixups += entry->relocstlsd; 4536 tlsrets += entry->relocstlsd; 4537 } 4538 else 4539 { 4540 relocs += entry->relocs32 + entry->relocsfdv 4541 + entry->relocstlsoff + entry->relocstlsd; 4542 } 4543 4544 if (entry->symndx != -1 4545 || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)) 4546 { 4547 if (entry->symndx != -1 4548 || entry->d.h->root.type != bfd_link_hash_undefweak) 4549 fixups += entry->relocsfd; 4550 } 4551 else 4552 relocs += entry->relocsfd; 4553 } 4554 4555 if (subtract) 4556 { 4557 relocs = - relocs; 4558 fixups = - fixups; 4559 tlsrets = - tlsrets; 4560 } 4561 4562 entry->dynrelocs += relocs; 4563 entry->fixups += fixups; 4564 dinfo->relocs += relocs; 4565 dinfo->fixups += fixups; 4566 dinfo->tls_ret_refs += tlsrets; 4567 } 4568 4569 /* Look for opportunities to relax TLS relocations. We can assume 4570 we're linking the main executable or a static-tls library, since 4571 otherwise we wouldn't have got here. When relaxing, we have to 4572 first undo any previous accounting of TLS uses of fixups, dynamic 4573 relocations, GOT and PLT entries. */ 4574 4575 static void 4576 _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info *entry, 4577 struct _frvfdpic_dynamic_got_info *dinfo, 4578 bfd_boolean relaxing) 4579 { 4580 bfd_boolean changed = ! relaxing; 4581 4582 BFD_ASSERT (dinfo->info->executable 4583 || (dinfo->info->flags & DF_STATIC_TLS)); 4584 4585 if (entry->tlsdesc12 || entry->tlsdesclos || entry->tlsdeschilo) 4586 { 4587 if (! changed) 4588 { 4589 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE); 4590 _frvfdpic_count_tls_entries (entry, dinfo, TRUE); 4591 changed = TRUE; 4592 } 4593 4594 /* When linking an executable, we can always decay GOTTLSDESC to 4595 TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise. 4596 When linking a static-tls shared library, using TLSMOFF is 4597 not an option, but we can still use GOTTLSOFF. When decaying 4598 to GOTTLSOFF, we must keep the GOT entry in range. We know 4599 it has to fit because we'll be trading the 4 words of hte TLS 4600 descriptor for a single word in the same range. */ 4601 if (! dinfo->info->executable 4602 || (entry->symndx == -1 4603 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))) 4604 { 4605 entry->tlsoff12 |= entry->tlsdesc12; 4606 entry->tlsofflos |= entry->tlsdesclos; 4607 entry->tlsoffhilo |= entry->tlsdeschilo; 4608 } 4609 4610 entry->tlsdesc12 = entry->tlsdesclos = entry->tlsdeschilo = 0; 4611 } 4612 4613 /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the 4614 main executable. We have to check whether the symbol's TLSOFF is 4615 in range for a setlos. For symbols with a hash entry, we can 4616 determine exactly what to do; for others locals, we don't have 4617 addresses handy, so we use the size of the TLS section as an 4618 approximation. If we get it wrong, we'll retain a GOT entry 4619 holding the TLS offset (without dynamic relocations or fixups), 4620 but we'll still optimize away the loads from it. Since TLS sizes 4621 are generally very small, it's probably not worth attempting to 4622 do better than this. */ 4623 if ((entry->tlsplt 4624 || entry->tlsoff12 || entry->tlsofflos || entry->tlsoffhilo) 4625 && dinfo->info->executable && relaxing 4626 && ((entry->symndx == -1 4627 && FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h) 4628 /* The above may hold for an undefweak TLS symbol, so make 4629 sure we don't have this case before accessing def.value 4630 and def.section. */ 4631 && (entry->d.h->root.type == bfd_link_hash_undefweak 4632 || (bfd_vma)(entry->d.h->root.u.def.value 4633 + (entry->d.h->root.u.def.section 4634 ->output_section->vma) 4635 + entry->d.h->root.u.def.section->output_offset 4636 + entry->addend 4637 - tls_biased_base (dinfo->info) 4638 + 32768) < (bfd_vma)65536)) 4639 || (entry->symndx != -1 4640 && (elf_hash_table (dinfo->info)->tls_sec->size 4641 + abs (entry->addend) < 32768 + FRVFDPIC_TLS_BIAS)))) 4642 { 4643 if (! changed) 4644 { 4645 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE); 4646 _frvfdpic_count_tls_entries (entry, dinfo, TRUE); 4647 changed = TRUE; 4648 } 4649 4650 entry->tlsplt = 4651 entry->tlsoff12 = entry->tlsofflos = entry->tlsoffhilo = 0; 4652 } 4653 4654 /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already 4655 have a #gottlsoff12 relocation for this entry, or if we can fit 4656 one more in the 12-bit (and 16-bit) ranges. */ 4657 if (entry->tlsplt 4658 && (entry->tlsoff12 4659 || (relaxing 4660 && dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 <= 4096 - 12 - 4 4661 && (dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 4662 + dinfo->gotlos + dinfo->fdlos + dinfo->tlsdlos 4663 <= 65536 - 12 - 4)))) 4664 { 4665 if (! changed) 4666 { 4667 _frvfdpic_count_relocs_fixups (entry, dinfo, TRUE); 4668 _frvfdpic_count_tls_entries (entry, dinfo, TRUE); 4669 changed = TRUE; 4670 } 4671 4672 entry->tlsoff12 = 1; 4673 entry->tlsplt = 0; 4674 } 4675 4676 if (changed) 4677 { 4678 _frvfdpic_count_tls_entries (entry, dinfo, FALSE); 4679 _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE); 4680 } 4681 4682 return; 4683 } 4684 4685 /* Compute the total GOT and PLT size required by each symbol in each range. * 4686 Symbols may require up to 4 words in the GOT: an entry pointing to 4687 the symbol, an entry pointing to its function descriptor, and a 4688 private function descriptors taking two words. */ 4689 4690 static int 4691 _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_) 4692 { 4693 struct frvfdpic_relocs_info *entry = *entryp; 4694 struct _frvfdpic_dynamic_got_info *dinfo = dinfo_; 4695 4696 _frvfdpic_count_nontls_entries (entry, dinfo); 4697 4698 if (dinfo->info->executable || (dinfo->info->flags & DF_STATIC_TLS)) 4699 _frvfdpic_relax_tls_entries (entry, dinfo, FALSE); 4700 else 4701 { 4702 _frvfdpic_count_tls_entries (entry, dinfo, FALSE); 4703 _frvfdpic_count_relocs_fixups (entry, dinfo, FALSE); 4704 } 4705 4706 return 1; 4707 } 4708 4709 /* Determine the positive and negative ranges to be used by each 4710 offset range in the GOT. FDCUR and CUR, that must be aligned to a 4711 double-word boundary, are the minimum (negative) and maximum 4712 (positive) GOT offsets already used by previous ranges, except for 4713 an ODD entry that may have been left behind. GOT and FD indicate 4714 the size of GOT entries and function descriptors that must be 4715 placed within the range from -WRAP to WRAP. If there's room left, 4716 up to FDPLT bytes should be reserved for additional function 4717 descriptors. */ 4718 4719 inline static bfd_signed_vma 4720 _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad, 4721 bfd_signed_vma fdcur, 4722 bfd_signed_vma odd, 4723 bfd_signed_vma cur, 4724 bfd_vma got, 4725 bfd_vma fd, 4726 bfd_vma fdplt, 4727 bfd_vma tlsd, 4728 bfd_vma tlsdplt, 4729 bfd_vma wrap) 4730 { 4731 bfd_signed_vma wrapmin = -wrap; 4732 const bfd_vma tdescsz = 8; 4733 4734 /* Start at the given initial points. */ 4735 gad->fdcur = fdcur; 4736 gad->cur = cur; 4737 4738 /* If we had an incoming odd word and we have any got entries that 4739 are going to use it, consume it, otherwise leave gad->odd at 4740 zero. We might force gad->odd to zero and return the incoming 4741 odd such that it is used by the next range, but then GOT entries 4742 might appear to be out of order and we wouldn't be able to 4743 shorten the GOT by one word if it turns out to end with an 4744 unpaired GOT entry. */ 4745 if (odd && got) 4746 { 4747 gad->odd = odd; 4748 got -= 4; 4749 odd = 0; 4750 } 4751 else 4752 gad->odd = 0; 4753 4754 /* If we're left with an unpaired GOT entry, compute its location 4755 such that we can return it. Otherwise, if got doesn't require an 4756 odd number of words here, either odd was already zero in the 4757 block above, or it was set to zero because got was non-zero, or 4758 got was already zero. In the latter case, we want the value of 4759 odd to carry over to the return statement, so we don't want to 4760 reset odd unless the condition below is true. */ 4761 if (got & 4) 4762 { 4763 odd = cur + got; 4764 got += 4; 4765 } 4766 4767 /* Compute the tentative boundaries of this range. */ 4768 gad->max = cur + got; 4769 gad->min = fdcur - fd; 4770 gad->fdplt = 0; 4771 4772 /* If function descriptors took too much space, wrap some of them 4773 around. */ 4774 if (gad->min < wrapmin) 4775 { 4776 gad->max += wrapmin - gad->min; 4777 gad->tmin = gad->min = wrapmin; 4778 } 4779 4780 /* If GOT entries took too much space, wrap some of them around. 4781 This may well cause gad->min to become lower than wrapmin. This 4782 will cause a relocation overflow later on, so we don't have to 4783 report it here . */ 4784 if ((bfd_vma) gad->max > wrap) 4785 { 4786 gad->min -= gad->max - wrap; 4787 gad->max = wrap; 4788 } 4789 4790 /* Add TLS descriptors. */ 4791 gad->tmax = gad->max + tlsd; 4792 gad->tmin = gad->min; 4793 gad->tlsdplt = 0; 4794 4795 /* If TLS descriptors took too much space, wrap an integral number 4796 of them around. */ 4797 if ((bfd_vma) gad->tmax > wrap) 4798 { 4799 bfd_vma wrapsize = gad->tmax - wrap; 4800 4801 wrapsize += tdescsz / 2; 4802 wrapsize &= ~ tdescsz / 2; 4803 4804 gad->tmin -= wrapsize; 4805 gad->tmax -= wrapsize; 4806 } 4807 4808 /* If there is space left and we have function descriptors 4809 referenced in PLT entries that could take advantage of shorter 4810 offsets, place them now. */ 4811 if (fdplt && gad->tmin > wrapmin) 4812 { 4813 bfd_vma fds; 4814 4815 if ((bfd_vma) (gad->tmin - wrapmin) < fdplt) 4816 fds = gad->tmin - wrapmin; 4817 else 4818 fds = fdplt; 4819 4820 fdplt -= fds; 4821 gad->min -= fds; 4822 gad->tmin -= fds; 4823 gad->fdplt += fds; 4824 } 4825 4826 /* If there is more space left, try to place some more function 4827 descriptors for PLT entries. */ 4828 if (fdplt && (bfd_vma) gad->tmax < wrap) 4829 { 4830 bfd_vma fds; 4831 4832 if ((bfd_vma) (wrap - gad->tmax) < fdplt) 4833 fds = wrap - gad->tmax; 4834 else 4835 fds = fdplt; 4836 4837 fdplt -= fds; 4838 gad->max += fds; 4839 gad->tmax += fds; 4840 gad->fdplt += fds; 4841 } 4842 4843 /* If there is space left and we have TLS descriptors referenced in 4844 PLT entries that could take advantage of shorter offsets, place 4845 them now. */ 4846 if (tlsdplt && gad->tmin > wrapmin) 4847 { 4848 bfd_vma tlsds; 4849 4850 if ((bfd_vma) (gad->tmin - wrapmin) < tlsdplt) 4851 tlsds = (gad->tmin - wrapmin) & ~ (tdescsz / 2); 4852 else 4853 tlsds = tlsdplt; 4854 4855 tlsdplt -= tlsds; 4856 gad->tmin -= tlsds; 4857 gad->tlsdplt += tlsds; 4858 } 4859 4860 /* If there is more space left, try to place some more TLS 4861 descriptors for PLT entries. Although we could try to fit an 4862 additional TLS descriptor with half of it just before before the 4863 wrap point and another right past the wrap point, this might 4864 cause us to run out of space for the next region, so don't do 4865 it. */ 4866 if (tlsdplt && (bfd_vma) gad->tmax < wrap - tdescsz / 2) 4867 { 4868 bfd_vma tlsds; 4869 4870 if ((bfd_vma) (wrap - gad->tmax) < tlsdplt) 4871 tlsds = (wrap - gad->tmax) & ~ (tdescsz / 2); 4872 else 4873 tlsds = tlsdplt; 4874 4875 tlsdplt -= tlsds; 4876 gad->tmax += tlsds; 4877 gad->tlsdplt += tlsds; 4878 } 4879 4880 /* If odd was initially computed as an offset past the wrap point, 4881 wrap it around. */ 4882 if (odd > gad->max) 4883 odd = gad->min + odd - gad->max; 4884 4885 /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed 4886 before returning, so do it here too. This guarantees that, 4887 should cur and fdcur meet at the wrap point, they'll both be 4888 equal to min. */ 4889 if (gad->cur == gad->max) 4890 gad->cur = gad->min; 4891 4892 /* Ditto for _frvfdpic_get_tlsdesc_entry(). */ 4893 gad->tcur = gad->max; 4894 if (gad->tcur == gad->tmax) 4895 gad->tcur = gad->tmin; 4896 4897 return odd; 4898 } 4899 4900 /* Compute the location of the next GOT entry, given the allocation 4901 data for a range. */ 4902 4903 inline static bfd_signed_vma 4904 _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) 4905 { 4906 bfd_signed_vma ret; 4907 4908 if (gad->odd) 4909 { 4910 /* If there was an odd word left behind, use it. */ 4911 ret = gad->odd; 4912 gad->odd = 0; 4913 } 4914 else 4915 { 4916 /* Otherwise, use the word pointed to by cur, reserve the next 4917 as an odd word, and skip to the next pair of words, possibly 4918 wrapping around. */ 4919 ret = gad->cur; 4920 gad->odd = gad->cur + 4; 4921 gad->cur += 8; 4922 if (gad->cur == gad->max) 4923 gad->cur = gad->min; 4924 } 4925 4926 return ret; 4927 } 4928 4929 /* Compute the location of the next function descriptor entry in the 4930 GOT, given the allocation data for a range. */ 4931 4932 inline static bfd_signed_vma 4933 _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) 4934 { 4935 /* If we're at the bottom, wrap around, and only then allocate the 4936 next pair of words. */ 4937 if (gad->fdcur == gad->min) 4938 gad->fdcur = gad->max; 4939 return gad->fdcur -= 8; 4940 } 4941 4942 /* Compute the location of the next TLS descriptor entry in the GOT, 4943 given the allocation data for a range. */ 4944 inline static bfd_signed_vma 4945 _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data *gad) 4946 { 4947 bfd_signed_vma ret; 4948 4949 ret = gad->tcur; 4950 4951 gad->tcur += 8; 4952 4953 /* If we're at the top of the region, wrap around to the bottom. */ 4954 if (gad->tcur == gad->tmax) 4955 gad->tcur = gad->tmin; 4956 4957 return ret; 4958 } 4959 4960 /* Assign GOT offsets for every GOT entry and function descriptor. 4961 Doing everything in a single pass is tricky. */ 4962 4963 static int 4964 _frvfdpic_assign_got_entries (void **entryp, void *info_) 4965 { 4966 struct frvfdpic_relocs_info *entry = *entryp; 4967 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_; 4968 4969 if (entry->got12) 4970 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12); 4971 else if (entry->gotlos) 4972 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); 4973 else if (entry->gothilo) 4974 entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); 4975 4976 if (entry->fdgot12) 4977 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12); 4978 else if (entry->fdgotlos) 4979 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); 4980 else if (entry->fdgothilo) 4981 entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); 4982 4983 if (entry->fdgoff12) 4984 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12); 4985 else if (entry->plt && dinfo->got12.fdplt) 4986 { 4987 dinfo->got12.fdplt -= 8; 4988 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12); 4989 } 4990 else if (entry->fdgofflos) 4991 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos); 4992 else if (entry->plt && dinfo->gotlos.fdplt) 4993 { 4994 dinfo->gotlos.fdplt -= 8; 4995 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos); 4996 } 4997 else if (entry->plt) 4998 { 4999 dinfo->gothilo.fdplt -= 8; 5000 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo); 5001 } 5002 else if (entry->privfd) 5003 entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo); 5004 5005 if (entry->tlsoff12) 5006 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->got12); 5007 else if (entry->tlsofflos) 5008 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gotlos); 5009 else if (entry->tlsoffhilo) 5010 entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gothilo); 5011 5012 if (entry->tlsdesc12) 5013 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12); 5014 else if (entry->tlsplt && dinfo->got12.tlsdplt) 5015 { 5016 dinfo->got12.tlsdplt -= 8; 5017 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12); 5018 } 5019 else if (entry->tlsdesclos) 5020 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos); 5021 else if (entry->tlsplt && dinfo->gotlos.tlsdplt) 5022 { 5023 dinfo->gotlos.tlsdplt -= 8; 5024 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos); 5025 } 5026 else if (entry->tlsplt) 5027 { 5028 dinfo->gothilo.tlsdplt -= 8; 5029 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo); 5030 } 5031 else if (entry->tlsdeschilo) 5032 entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo); 5033 5034 return 1; 5035 } 5036 5037 /* Assign GOT offsets to private function descriptors used by PLT 5038 entries (or referenced by 32-bit offsets), as well as PLT entries 5039 and lazy PLT entries. */ 5040 5041 static int 5042 _frvfdpic_assign_plt_entries (void **entryp, void *info_) 5043 { 5044 struct frvfdpic_relocs_info *entry = *entryp; 5045 struct _frvfdpic_dynamic_got_plt_info *dinfo = info_; 5046 5047 if (entry->privfd) 5048 BFD_ASSERT (entry->fd_entry); 5049 5050 if (entry->plt) 5051 { 5052 int size; 5053 5054 /* We use the section's raw size to mark the location of the 5055 next PLT entry. */ 5056 entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->size; 5057 5058 /* Figure out the length of this PLT entry based on the 5059 addressing mode we need to reach the function descriptor. */ 5060 BFD_ASSERT (entry->fd_entry); 5061 if (entry->fd_entry >= -(1 << (12 - 1)) 5062 && entry->fd_entry < (1 << (12 - 1))) 5063 size = 8; 5064 else if (entry->fd_entry >= -(1 << (16 - 1)) 5065 && entry->fd_entry < (1 << (16 - 1))) 5066 size = 12; 5067 else 5068 size = 16; 5069 5070 frvfdpic_plt_section (dinfo->g.info)->size += size; 5071 } 5072 5073 if (entry->lazyplt) 5074 { 5075 entry->lzplt_entry = dinfo->g.lzplt; 5076 dinfo->g.lzplt += 8; 5077 /* If this entry is the one that gets the resolver stub, account 5078 for the additional instruction. */ 5079 if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE 5080 == FRVFDPIC_LZPLT_RESOLV_LOC) 5081 dinfo->g.lzplt += 4; 5082 } 5083 5084 if (entry->tlsplt) 5085 { 5086 int size; 5087 5088 entry->tlsplt_entry 5089 = frvfdpic_plt_section (dinfo->g.info)->size; 5090 5091 if (dinfo->g.info->executable 5092 && (entry->symndx != -1 5093 || FRVFDPIC_SYM_LOCAL (dinfo->g.info, entry->d.h))) 5094 { 5095 if ((bfd_signed_vma)entry->addend >= -(1 << (16 - 1)) 5096 /* FIXME: here we use the size of the TLS section 5097 as an upper bound for the value of the TLS 5098 symbol, because we may not know the exact value 5099 yet. If we get it wrong, we'll just waste a 5100 word in the PLT, and we should never get even 5101 close to 32 KiB of TLS anyway. */ 5102 && elf_hash_table (dinfo->g.info)->tls_sec 5103 && (elf_hash_table (dinfo->g.info)->tls_sec->size 5104 + (bfd_signed_vma)(entry->addend) <= (1 << (16 - 1)))) 5105 size = 8; 5106 else 5107 size = 12; 5108 } 5109 else if (entry->tlsoff_entry) 5110 { 5111 if (entry->tlsoff_entry >= -(1 << (12 - 1)) 5112 && entry->tlsoff_entry < (1 << (12 - 1))) 5113 size = 8; 5114 else if (entry->tlsoff_entry >= -(1 << (16 - 1)) 5115 && entry->tlsoff_entry < (1 << (16 - 1))) 5116 size = 12; 5117 else 5118 size = 16; 5119 } 5120 else 5121 { 5122 BFD_ASSERT (entry->tlsdesc_entry); 5123 5124 if (entry->tlsdesc_entry >= -(1 << (12 - 1)) 5125 && entry->tlsdesc_entry < (1 << (12 - 1))) 5126 size = 8; 5127 else if (entry->tlsdesc_entry >= -(1 << (16 - 1)) 5128 && entry->tlsdesc_entry < (1 << (16 - 1))) 5129 size = 12; 5130 else 5131 size = 16; 5132 } 5133 5134 frvfdpic_plt_section (dinfo->g.info)->size += size; 5135 } 5136 5137 return 1; 5138 } 5139 5140 /* Cancel out any effects of calling _frvfdpic_assign_got_entries and 5141 _frvfdpic_assign_plt_entries. */ 5142 5143 static int 5144 _frvfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED) 5145 { 5146 struct frvfdpic_relocs_info *entry = *entryp; 5147 5148 entry->got_entry = 0; 5149 entry->fdgot_entry = 0; 5150 entry->fd_entry = 0; 5151 entry->plt_entry = (bfd_vma)-1; 5152 entry->lzplt_entry = (bfd_vma)-1; 5153 entry->tlsoff_entry = 0; 5154 entry->tlsdesc_entry = 0; 5155 entry->tlsplt_entry = (bfd_vma)-1; 5156 5157 return 1; 5158 } 5159 5160 /* Follow indirect and warning hash entries so that each got entry 5161 points to the final symbol definition. P must point to a pointer 5162 to the hash table we're traversing. Since this traversal may 5163 modify the hash table, we set this pointer to NULL to indicate 5164 we've made a potentially-destructive change to the hash table, so 5165 the traversal must be restarted. */ 5166 static int 5167 _frvfdpic_resolve_final_relocs_info (void **entryp, void *p) 5168 { 5169 struct frvfdpic_relocs_info *entry = *entryp; 5170 htab_t *htab = p; 5171 5172 if (entry->symndx == -1) 5173 { 5174 struct elf_link_hash_entry *h = entry->d.h; 5175 struct frvfdpic_relocs_info *oentry; 5176 5177 while (h->root.type == bfd_link_hash_indirect 5178 || h->root.type == bfd_link_hash_warning) 5179 h = (struct elf_link_hash_entry *)h->root.u.i.link; 5180 5181 if (entry->d.h == h) 5182 return 1; 5183 5184 oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend, 5185 NO_INSERT); 5186 5187 if (oentry) 5188 { 5189 /* Merge the two entries. */ 5190 frvfdpic_pic_merge_early_relocs_info (oentry, entry); 5191 htab_clear_slot (*htab, entryp); 5192 return 1; 5193 } 5194 5195 entry->d.h = h; 5196 5197 /* If we can't find this entry with the new bfd hash, re-insert 5198 it, and get the traversal restarted. */ 5199 if (! htab_find (*htab, entry)) 5200 { 5201 htab_clear_slot (*htab, entryp); 5202 entryp = htab_find_slot (*htab, entry, INSERT); 5203 if (! *entryp) 5204 *entryp = entry; 5205 /* Abort the traversal, since the whole table may have 5206 moved, and leave it up to the parent to restart the 5207 process. */ 5208 *(htab_t *)p = NULL; 5209 return 0; 5210 } 5211 } 5212 5213 return 1; 5214 } 5215 5216 /* Compute the total size of the GOT, the PLT, the dynamic relocations 5217 section and the rofixup section. Assign locations for GOT and PLT 5218 entries. */ 5219 5220 static bfd_boolean 5221 _frvfdpic_size_got_plt (bfd *output_bfd, 5222 struct _frvfdpic_dynamic_got_plt_info *gpinfop) 5223 { 5224 bfd_signed_vma odd; 5225 bfd_vma limit, tlslimit; 5226 struct bfd_link_info *info = gpinfop->g.info; 5227 bfd *dynobj = elf_hash_table (info)->dynobj; 5228 5229 memcpy (frvfdpic_dynamic_got_plt_info (info), &gpinfop->g, 5230 sizeof (gpinfop->g)); 5231 5232 odd = 12; 5233 /* Compute the total size taken by entries in the 12-bit and 16-bit 5234 ranges, to tell how many PLT function descriptors we can bring 5235 into the 12-bit range without causing the 16-bit range to 5236 overflow. */ 5237 limit = odd + gpinfop->g.got12 + gpinfop->g.gotlos 5238 + gpinfop->g.fd12 + gpinfop->g.fdlos 5239 + gpinfop->g.tlsd12 + gpinfop->g.tlsdlos; 5240 if (limit < (bfd_vma)1 << 16) 5241 limit = ((bfd_vma)1 << 16) - limit; 5242 else 5243 limit = 0; 5244 if (gpinfop->g.fdplt < limit) 5245 { 5246 tlslimit = (limit - gpinfop->g.fdplt) & ~ (bfd_vma) 8; 5247 limit = gpinfop->g.fdplt; 5248 } 5249 else 5250 tlslimit = 0; 5251 if (gpinfop->g.tlsdplt < tlslimit) 5252 tlslimit = gpinfop->g.tlsdplt; 5253 5254 /* Determine the ranges of GOT offsets that we can use for each 5255 range of addressing modes. */ 5256 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->got12, 5257 0, 5258 odd, 5259 16, 5260 gpinfop->g.got12, 5261 gpinfop->g.fd12, 5262 limit, 5263 gpinfop->g.tlsd12, 5264 tlslimit, 5265 (bfd_vma)1 << (12-1)); 5266 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gotlos, 5267 gpinfop->got12.tmin, 5268 odd, 5269 gpinfop->got12.tmax, 5270 gpinfop->g.gotlos, 5271 gpinfop->g.fdlos, 5272 gpinfop->g.fdplt 5273 - gpinfop->got12.fdplt, 5274 gpinfop->g.tlsdlos, 5275 gpinfop->g.tlsdplt 5276 - gpinfop->got12.tlsdplt, 5277 (bfd_vma)1 << (16-1)); 5278 odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gothilo, 5279 gpinfop->gotlos.tmin, 5280 odd, 5281 gpinfop->gotlos.tmax, 5282 gpinfop->g.gothilo, 5283 gpinfop->g.fdhilo, 5284 gpinfop->g.fdplt 5285 - gpinfop->got12.fdplt 5286 - gpinfop->gotlos.fdplt, 5287 gpinfop->g.tlsdhilo, 5288 gpinfop->g.tlsdplt 5289 - gpinfop->got12.tlsdplt 5290 - gpinfop->gotlos.tlsdplt, 5291 (bfd_vma)1 << (32-1)); 5292 5293 /* Now assign (most) GOT offsets. */ 5294 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries, 5295 gpinfop); 5296 5297 frvfdpic_got_section (info)->size = gpinfop->gothilo.tmax 5298 - gpinfop->gothilo.tmin 5299 /* If an odd word is the last word of the GOT, we don't need this 5300 word to be part of the GOT. */ 5301 - (odd + 4 == gpinfop->gothilo.tmax ? 4 : 0); 5302 if (frvfdpic_got_section (info)->size == 0) 5303 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE; 5304 else if (frvfdpic_got_section (info)->size == 12 5305 && ! elf_hash_table (info)->dynamic_sections_created) 5306 { 5307 frvfdpic_got_section (info)->flags |= SEC_EXCLUDE; 5308 frvfdpic_got_section (info)->size = 0; 5309 } 5310 /* This will be non-NULL during relaxation. The assumption is that 5311 the size of one of these sections will never grow, only shrink, 5312 so we can use the larger buffer we allocated before. */ 5313 else if (frvfdpic_got_section (info)->contents == NULL) 5314 { 5315 frvfdpic_got_section (info)->contents = 5316 (bfd_byte *) bfd_zalloc (dynobj, 5317 frvfdpic_got_section (info)->size); 5318 if (frvfdpic_got_section (info)->contents == NULL) 5319 return FALSE; 5320 } 5321 5322 if (frvfdpic_gotrel_section (info)) 5323 /* Subtract the number of lzplt entries, since those will generate 5324 relocations in the pltrel section. */ 5325 frvfdpic_gotrel_section (info)->size = 5326 (gpinfop->g.relocs - gpinfop->g.lzplt / 8) 5327 * get_elf_backend_data (output_bfd)->s->sizeof_rel; 5328 else 5329 BFD_ASSERT (gpinfop->g.relocs == 0); 5330 if (frvfdpic_gotrel_section (info)->size == 0) 5331 frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE; 5332 else if (frvfdpic_gotrel_section (info)->contents == NULL) 5333 { 5334 frvfdpic_gotrel_section (info)->contents = 5335 (bfd_byte *) bfd_zalloc (dynobj, 5336 frvfdpic_gotrel_section (info)->size); 5337 if (frvfdpic_gotrel_section (info)->contents == NULL) 5338 return FALSE; 5339 } 5340 5341 frvfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4; 5342 if (frvfdpic_gotfixup_section (info)->size == 0) 5343 frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE; 5344 else if (frvfdpic_gotfixup_section (info)->contents == NULL) 5345 { 5346 frvfdpic_gotfixup_section (info)->contents = 5347 (bfd_byte *) bfd_zalloc (dynobj, 5348 frvfdpic_gotfixup_section (info)->size); 5349 if (frvfdpic_gotfixup_section (info)->contents == NULL) 5350 return FALSE; 5351 } 5352 5353 if (frvfdpic_pltrel_section (info)) 5354 { 5355 frvfdpic_pltrel_section (info)->size = 5356 gpinfop->g.lzplt / 8 5357 * get_elf_backend_data (output_bfd)->s->sizeof_rel; 5358 if (frvfdpic_pltrel_section (info)->size == 0) 5359 frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE; 5360 else if (frvfdpic_pltrel_section (info)->contents == NULL) 5361 { 5362 frvfdpic_pltrel_section (info)->contents = 5363 (bfd_byte *) bfd_zalloc (dynobj, 5364 frvfdpic_pltrel_section (info)->size); 5365 if (frvfdpic_pltrel_section (info)->contents == NULL) 5366 return FALSE; 5367 } 5368 } 5369 5370 /* Add 4 bytes for every block of at most 65535 lazy PLT entries, 5371 such that there's room for the additional instruction needed to 5372 call the resolver. Since _frvfdpic_assign_got_entries didn't 5373 account for them, our block size is 4 bytes smaller than the real 5374 block size. */ 5375 if (frvfdpic_plt_section (info)) 5376 { 5377 frvfdpic_plt_section (info)->size = gpinfop->g.lzplt 5378 + ((gpinfop->g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8) 5379 / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4); 5380 } 5381 5382 /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to 5383 actually assign lazy PLT entries addresses. */ 5384 gpinfop->g.lzplt = 0; 5385 5386 /* Save information that we're going to need to generate GOT and PLT 5387 entries. */ 5388 frvfdpic_got_initial_offset (info) = -gpinfop->gothilo.tmin; 5389 5390 if (get_elf_backend_data (output_bfd)->want_got_sym) 5391 elf_hash_table (info)->hgot->root.u.def.value 5392 = frvfdpic_got_initial_offset (info); 5393 5394 if (frvfdpic_plt_section (info)) 5395 frvfdpic_plt_initial_offset (info) = 5396 frvfdpic_plt_section (info)->size; 5397 5398 /* Allocate a ret statement at plt_initial_offset, to be used by 5399 locally-resolved TLS descriptors. */ 5400 if (gpinfop->g.tls_ret_refs) 5401 frvfdpic_plt_section (info)->size += 4; 5402 5403 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries, 5404 gpinfop); 5405 5406 /* Allocate the PLT section contents only after 5407 _frvfdpic_assign_plt_entries has a chance to add the size of the 5408 non-lazy PLT entries. */ 5409 if (frvfdpic_plt_section (info)) 5410 { 5411 if (frvfdpic_plt_section (info)->size == 0) 5412 frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE; 5413 else if (frvfdpic_plt_section (info)->contents == NULL) 5414 { 5415 frvfdpic_plt_section (info)->contents = 5416 (bfd_byte *) bfd_zalloc (dynobj, 5417 frvfdpic_plt_section (info)->size); 5418 if (frvfdpic_plt_section (info)->contents == NULL) 5419 return FALSE; 5420 } 5421 } 5422 5423 return TRUE; 5424 } 5425 5426 /* Set the sizes of the dynamic sections. */ 5427 5428 static bfd_boolean 5429 elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd, 5430 struct bfd_link_info *info) 5431 { 5432 bfd *dynobj; 5433 asection *s; 5434 struct _frvfdpic_dynamic_got_plt_info gpinfo; 5435 5436 dynobj = elf_hash_table (info)->dynobj; 5437 BFD_ASSERT (dynobj != NULL); 5438 5439 if (elf_hash_table (info)->dynamic_sections_created) 5440 { 5441 /* Set the contents of the .interp section to the interpreter. */ 5442 if (info->executable) 5443 { 5444 s = bfd_get_linker_section (dynobj, ".interp"); 5445 BFD_ASSERT (s != NULL); 5446 s->size = sizeof ELF_DYNAMIC_INTERPRETER; 5447 s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER; 5448 } 5449 } 5450 5451 memset (&gpinfo, 0, sizeof (gpinfo)); 5452 gpinfo.g.info = info; 5453 5454 for (;;) 5455 { 5456 htab_t relocs = frvfdpic_relocs_info (info); 5457 5458 htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs); 5459 5460 if (relocs == frvfdpic_relocs_info (info)) 5461 break; 5462 } 5463 5464 htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries, 5465 &gpinfo.g); 5466 5467 /* Allocate space to save the summary information, we're going to 5468 use it if we're doing relaxations. */ 5469 frvfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g)); 5470 5471 if (!_frvfdpic_size_got_plt (output_bfd, &gpinfo)) 5472 return FALSE; 5473 5474 if (elf_hash_table (info)->dynamic_sections_created) 5475 { 5476 if (frvfdpic_got_section (info)->size) 5477 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)) 5478 return FALSE; 5479 5480 if (frvfdpic_pltrel_section (info)->size) 5481 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0) 5482 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL) 5483 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0)) 5484 return FALSE; 5485 5486 if (frvfdpic_gotrel_section (info)->size) 5487 if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0) 5488 || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0) 5489 || !_bfd_elf_add_dynamic_entry (info, DT_RELENT, 5490 sizeof (Elf32_External_Rel))) 5491 return FALSE; 5492 } 5493 5494 return TRUE; 5495 } 5496 5497 static bfd_boolean 5498 elf32_frvfdpic_always_size_sections (bfd *output_bfd, 5499 struct bfd_link_info *info) 5500 { 5501 if (!info->relocatable 5502 && !bfd_elf_stack_segment_size (output_bfd, info, 5503 "__stacksize", DEFAULT_STACK_SIZE)) 5504 return FALSE; 5505 5506 return TRUE; 5507 } 5508 5509 /* Check whether any of the relocations was optimized away, and 5510 subtract it from the relocation or fixup count. */ 5511 static bfd_boolean 5512 _frvfdpic_check_discarded_relocs (bfd *abfd, asection *sec, 5513 struct bfd_link_info *info, 5514 5515 bfd_boolean *changed) 5516 { 5517 Elf_Internal_Shdr *symtab_hdr; 5518 struct elf_link_hash_entry **sym_hashes; 5519 Elf_Internal_Rela *rel, *erel; 5520 5521 if ((sec->flags & SEC_RELOC) == 0 5522 || sec->reloc_count == 0) 5523 return TRUE; 5524 5525 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 5526 sym_hashes = elf_sym_hashes (abfd); 5527 5528 rel = elf_section_data (sec)->relocs; 5529 5530 /* Now examine each relocation. */ 5531 for (erel = rel + sec->reloc_count; rel < erel; rel++) 5532 { 5533 struct elf_link_hash_entry *h; 5534 unsigned long r_symndx; 5535 struct frvfdpic_relocs_info *picrel; 5536 struct _frvfdpic_dynamic_got_info *dinfo; 5537 5538 if (ELF32_R_TYPE (rel->r_info) != R_FRV_32 5539 && ELF32_R_TYPE (rel->r_info) != R_FRV_FUNCDESC) 5540 continue; 5541 5542 if (_bfd_elf_section_offset (sec->output_section->owner, 5543 info, sec, rel->r_offset) 5544 != (bfd_vma)-1) 5545 continue; 5546 5547 r_symndx = ELF32_R_SYM (rel->r_info); 5548 if (r_symndx < symtab_hdr->sh_info) 5549 h = NULL; 5550 else 5551 { 5552 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 5553 while (h->root.type == bfd_link_hash_indirect 5554 || h->root.type == bfd_link_hash_warning) 5555 h = (struct elf_link_hash_entry *)h->root.u.i.link; 5556 } 5557 5558 if (h != NULL) 5559 picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info), 5560 abfd, h, 5561 rel->r_addend, NO_INSERT); 5562 else 5563 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info), 5564 abfd, r_symndx, 5565 rel->r_addend, NO_INSERT); 5566 5567 if (! picrel) 5568 return FALSE; 5569 5570 *changed = TRUE; 5571 dinfo = frvfdpic_dynamic_got_plt_info (info); 5572 5573 _frvfdpic_count_relocs_fixups (picrel, dinfo, TRUE); 5574 if (ELF32_R_TYPE (rel->r_info) == R_FRV_32) 5575 picrel->relocs32--; 5576 else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */ 5577 picrel->relocsfd--; 5578 _frvfdpic_count_relocs_fixups (picrel, dinfo, FALSE); 5579 } 5580 5581 return TRUE; 5582 } 5583 5584 static bfd_boolean 5585 frvfdpic_elf_discard_info (bfd *ibfd, 5586 struct elf_reloc_cookie *cookie ATTRIBUTE_UNUSED, 5587 struct bfd_link_info *info) 5588 { 5589 bfd_boolean changed = FALSE; 5590 asection *s; 5591 bfd *obfd = NULL; 5592 5593 /* Account for relaxation of .eh_frame section. */ 5594 for (s = ibfd->sections; s; s = s->next) 5595 if (s->sec_info_type == SEC_INFO_TYPE_EH_FRAME) 5596 { 5597 if (!_frvfdpic_check_discarded_relocs (ibfd, s, info, &changed)) 5598 return FALSE; 5599 obfd = s->output_section->owner; 5600 } 5601 5602 if (changed) 5603 { 5604 struct _frvfdpic_dynamic_got_plt_info gpinfo; 5605 5606 memset (&gpinfo, 0, sizeof (gpinfo)); 5607 memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), 5608 sizeof (gpinfo.g)); 5609 5610 /* Clear GOT and PLT assignments. */ 5611 htab_traverse (frvfdpic_relocs_info (info), 5612 _frvfdpic_reset_got_plt_entries, 5613 NULL); 5614 5615 if (!_frvfdpic_size_got_plt (obfd, &gpinfo)) 5616 return FALSE; 5617 } 5618 5619 return TRUE; 5620 } 5621 5622 /* Look for opportunities to relax TLS relocations. We can assume 5623 we're linking the main executable or a static-tls library, since 5624 otherwise we wouldn't have got here. */ 5625 5626 static int 5627 _frvfdpic_relax_got_plt_entries (void **entryp, void *dinfo_) 5628 { 5629 struct frvfdpic_relocs_info *entry = *entryp; 5630 struct _frvfdpic_dynamic_got_info *dinfo = dinfo_; 5631 5632 _frvfdpic_relax_tls_entries (entry, dinfo, TRUE); 5633 5634 return 1; 5635 } 5636 5637 static bfd_boolean 5638 elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, 5639 struct bfd_link_info *info, bfd_boolean *again) 5640 { 5641 struct _frvfdpic_dynamic_got_plt_info gpinfo; 5642 5643 if (info->relocatable) 5644 (*info->callbacks->einfo) 5645 (_("%P%F: --relax and -r may not be used together\n")); 5646 5647 /* If we return early, we didn't change anything. */ 5648 *again = FALSE; 5649 5650 /* We'll do our thing when requested to relax the GOT section. */ 5651 if (sec != frvfdpic_got_section (info)) 5652 return TRUE; 5653 5654 /* We can only relax when linking the main executable or a library 5655 that can't be dlopened. */ 5656 if (! info->executable && ! (info->flags & DF_STATIC_TLS)) 5657 return TRUE; 5658 5659 /* If there isn't a TLS section for this binary, we can't do 5660 anything about its TLS relocations (it probably doesn't have 5661 any. */ 5662 if (elf_hash_table (info)->tls_sec == NULL) 5663 return TRUE; 5664 5665 memset (&gpinfo, 0, sizeof (gpinfo)); 5666 memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), sizeof (gpinfo.g)); 5667 5668 /* Now look for opportunities to relax, adjusting the GOT usage 5669 as needed. */ 5670 htab_traverse (frvfdpic_relocs_info (info), 5671 _frvfdpic_relax_got_plt_entries, 5672 &gpinfo.g); 5673 5674 /* If we changed anything, reset and re-assign GOT and PLT entries. */ 5675 if (memcmp (frvfdpic_dynamic_got_plt_info (info), 5676 &gpinfo.g, sizeof (gpinfo.g)) != 0) 5677 { 5678 /* Clear GOT and PLT assignments. */ 5679 htab_traverse (frvfdpic_relocs_info (info), 5680 _frvfdpic_reset_got_plt_entries, 5681 NULL); 5682 5683 /* The owner of the TLS section is the output bfd. There should 5684 be a better way to get to it. */ 5685 if (!_frvfdpic_size_got_plt (elf_hash_table (info)->tls_sec->owner, 5686 &gpinfo)) 5687 return FALSE; 5688 5689 /* Repeat until we don't make any further changes. We could fail to 5690 introduce changes in a round if, for example, the 12-bit range is 5691 full, but we later release some space by getting rid of TLS 5692 descriptors in it. We have to repeat the whole process because 5693 we might have changed the size of a section processed before this 5694 one. */ 5695 *again = TRUE; 5696 } 5697 5698 return TRUE; 5699 } 5700 5701 /* Fill in code and data in dynamic sections. */ 5702 5703 static bfd_boolean 5704 elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, 5705 struct bfd_link_info *info ATTRIBUTE_UNUSED) 5706 { 5707 /* Nothing to be done for non-FDPIC. */ 5708 return TRUE; 5709 } 5710 5711 static bfd_boolean 5712 elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd, 5713 struct bfd_link_info *info) 5714 { 5715 bfd *dynobj; 5716 asection *sdyn; 5717 5718 dynobj = elf_hash_table (info)->dynobj; 5719 5720 if (frvfdpic_dynamic_got_plt_info (info)) 5721 { 5722 BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs == 0); 5723 } 5724 if (frvfdpic_got_section (info)) 5725 { 5726 BFD_ASSERT (frvfdpic_gotrel_section (info)->size 5727 == (frvfdpic_gotrel_section (info)->reloc_count 5728 * sizeof (Elf32_External_Rel))); 5729 5730 if (frvfdpic_gotfixup_section (info)) 5731 { 5732 struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot; 5733 bfd_vma got_value = hgot->root.u.def.value 5734 + hgot->root.u.def.section->output_section->vma 5735 + hgot->root.u.def.section->output_offset; 5736 struct bfd_link_hash_entry *hend; 5737 5738 _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info), 5739 got_value, 0); 5740 5741 if (frvfdpic_gotfixup_section (info)->size 5742 != (frvfdpic_gotfixup_section (info)->reloc_count * 4)) 5743 { 5744 error: 5745 info->callbacks->einfo 5746 ("LINKER BUG: .rofixup section size mismatch\n"); 5747 return FALSE; 5748 } 5749 5750 hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__", 5751 FALSE, FALSE, TRUE); 5752 if (hend 5753 && (hend->type == bfd_link_hash_defined 5754 || hend->type == bfd_link_hash_defweak) 5755 && hend->u.def.section->output_section != NULL) 5756 { 5757 bfd_vma value = 5758 frvfdpic_gotfixup_section (info)->output_section->vma 5759 + frvfdpic_gotfixup_section (info)->output_offset 5760 + frvfdpic_gotfixup_section (info)->size 5761 - hend->u.def.section->output_section->vma 5762 - hend->u.def.section->output_offset; 5763 BFD_ASSERT (hend->u.def.value == value); 5764 if (hend->u.def.value != value) 5765 goto error; 5766 } 5767 } 5768 } 5769 if (frvfdpic_pltrel_section (info)) 5770 { 5771 BFD_ASSERT (frvfdpic_pltrel_section (info)->size 5772 == (frvfdpic_pltrel_section (info)->reloc_count 5773 * sizeof (Elf32_External_Rel))); 5774 } 5775 5776 5777 if (elf_hash_table (info)->dynamic_sections_created) 5778 { 5779 Elf32_External_Dyn * dyncon; 5780 Elf32_External_Dyn * dynconend; 5781 5782 sdyn = bfd_get_linker_section (dynobj, ".dynamic"); 5783 5784 BFD_ASSERT (sdyn != NULL); 5785 5786 dyncon = (Elf32_External_Dyn *) sdyn->contents; 5787 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); 5788 5789 for (; dyncon < dynconend; dyncon++) 5790 { 5791 Elf_Internal_Dyn dyn; 5792 5793 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); 5794 5795 switch (dyn.d_tag) 5796 { 5797 default: 5798 break; 5799 5800 case DT_PLTGOT: 5801 dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma 5802 + frvfdpic_got_section (info)->output_offset 5803 + frvfdpic_got_initial_offset (info); 5804 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 5805 break; 5806 5807 case DT_JMPREL: 5808 dyn.d_un.d_ptr = frvfdpic_pltrel_section (info) 5809 ->output_section->vma 5810 + frvfdpic_pltrel_section (info)->output_offset; 5811 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 5812 break; 5813 5814 case DT_PLTRELSZ: 5815 dyn.d_un.d_val = frvfdpic_pltrel_section (info)->size; 5816 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 5817 break; 5818 } 5819 } 5820 } 5821 5822 return TRUE; 5823 } 5824 5825 /* Adjust a symbol defined by a dynamic object and referenced by a 5826 regular object. */ 5827 5828 static bfd_boolean 5829 elf32_frvfdpic_adjust_dynamic_symbol 5830 (struct bfd_link_info *info ATTRIBUTE_UNUSED, 5831 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED) 5832 { 5833 bfd * dynobj; 5834 5835 dynobj = elf_hash_table (info)->dynobj; 5836 5837 /* Make sure we know what is going on here. */ 5838 BFD_ASSERT (dynobj != NULL 5839 && (h->u.weakdef != NULL 5840 || (h->def_dynamic 5841 && h->ref_regular 5842 && !h->def_regular))); 5843 5844 /* If this is a weak symbol, and there is a real definition, the 5845 processor independent code will have arranged for us to see the 5846 real definition first, and we can just use the same value. */ 5847 if (h->u.weakdef != NULL) 5848 { 5849 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined 5850 || h->u.weakdef->root.type == bfd_link_hash_defweak); 5851 h->root.u.def.section = h->u.weakdef->root.u.def.section; 5852 h->root.u.def.value = h->u.weakdef->root.u.def.value; 5853 } 5854 5855 return TRUE; 5856 } 5857 5858 /* Perform any actions needed for dynamic symbols. */ 5859 5860 static bfd_boolean 5861 elf32_frvfdpic_finish_dynamic_symbol 5862 (bfd *output_bfd ATTRIBUTE_UNUSED, 5863 struct bfd_link_info *info ATTRIBUTE_UNUSED, 5864 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED, 5865 Elf_Internal_Sym *sym ATTRIBUTE_UNUSED) 5866 { 5867 return TRUE; 5868 } 5869 5870 /* Decide whether to attempt to turn absptr or lsda encodings in 5871 shared libraries into pcrel within the given input section. */ 5872 5873 static bfd_boolean 5874 frvfdpic_elf_use_relative_eh_frame 5875 (bfd *input_bfd ATTRIBUTE_UNUSED, 5876 struct bfd_link_info *info ATTRIBUTE_UNUSED, 5877 asection *eh_frame_section ATTRIBUTE_UNUSED) 5878 { 5879 /* We can't use PC-relative encodings in FDPIC binaries, in general. */ 5880 return FALSE; 5881 } 5882 5883 /* Adjust the contents of an eh_frame_hdr section before they're output. */ 5884 5885 static bfd_byte 5886 frvfdpic_elf_encode_eh_address (bfd *abfd, 5887 struct bfd_link_info *info, 5888 asection *osec, bfd_vma offset, 5889 asection *loc_sec, bfd_vma loc_offset, 5890 bfd_vma *encoded) 5891 { 5892 struct elf_link_hash_entry *h; 5893 5894 h = elf_hash_table (info)->hgot; 5895 BFD_ASSERT (h && h->root.type == bfd_link_hash_defined); 5896 5897 if (! h || (_frvfdpic_osec_to_segment (abfd, osec) 5898 == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section))) 5899 return _bfd_elf_encode_eh_address (abfd, info, osec, offset, 5900 loc_sec, loc_offset, encoded); 5901 5902 BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec) 5903 == (_frvfdpic_osec_to_segment 5904 (abfd, h->root.u.def.section->output_section))); 5905 5906 *encoded = osec->vma + offset 5907 - (h->root.u.def.value 5908 + h->root.u.def.section->output_section->vma 5909 + h->root.u.def.section->output_offset); 5910 5911 return DW_EH_PE_datarel | DW_EH_PE_sdata4; 5912 } 5913 5914 /* Look through the relocs for a section during the first phase. 5915 5916 Besides handling virtual table relocs for gc, we have to deal with 5917 all sorts of PIC-related relocations. We describe below the 5918 general plan on how to handle such relocations, even though we only 5919 collect information at this point, storing them in hash tables for 5920 perusal of later passes. 5921 5922 32 relocations are propagated to the linker output when creating 5923 position-independent output. LO16 and HI16 relocations are not 5924 supposed to be encountered in this case. 5925 5926 LABEL16 should always be resolvable by the linker, since it's only 5927 used by branches. 5928 5929 LABEL24, on the other hand, is used by calls. If it turns out that 5930 the target of a call is a dynamic symbol, a PLT entry must be 5931 created for it, which triggers the creation of a private function 5932 descriptor and, unless lazy binding is disabled, a lazy PLT entry. 5933 5934 GPREL relocations require the referenced symbol to be in the same 5935 segment as _gp, but this can only be checked later. 5936 5937 All GOT, GOTOFF and FUNCDESC relocations require a .got section to 5938 exist. LABEL24 might as well, since it may require a PLT entry, 5939 that will require a got. 5940 5941 Non-FUNCDESC GOT relocations require a GOT entry to be created 5942 regardless of whether the symbol is dynamic. However, since a 5943 global symbol that turns out to not be exported may have the same 5944 address of a non-dynamic symbol, we don't assign GOT entries at 5945 this point, such that we can share them in this case. A relocation 5946 for the GOT entry always has to be created, be it to offset a 5947 private symbol by the section load address, be it to get the symbol 5948 resolved dynamically. 5949 5950 FUNCDESC GOT relocations require a GOT entry to be created, and 5951 handled as if a FUNCDESC relocation was applied to the GOT entry in 5952 an object file. 5953 5954 FUNCDESC relocations referencing a symbol that turns out to NOT be 5955 dynamic cause a private function descriptor to be created. The 5956 FUNCDESC relocation then decays to a 32 relocation that points at 5957 the private descriptor. If the symbol is dynamic, the FUNCDESC 5958 relocation is propagated to the linker output, such that the 5959 dynamic linker creates the canonical descriptor, pointing to the 5960 dynamically-resolved definition of the function. 5961 5962 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic 5963 symbols that are assigned to the same segment as the GOT, but we 5964 can only check this later, after we know the complete set of 5965 symbols defined and/or exported. 5966 5967 FUNCDESC GOTOFF relocations require a function descriptor to be 5968 created and, unless lazy binding is disabled or the symbol is not 5969 dynamic, a lazy PLT entry. Since we can't tell at this point 5970 whether a symbol is going to be dynamic, we have to decide later 5971 whether to create a lazy PLT entry or bind the descriptor directly 5972 to the private function. 5973 5974 FUNCDESC_VALUE relocations are not supposed to be present in object 5975 files, but they may very well be simply propagated to the linker 5976 output, since they have no side effect. 5977 5978 5979 A function descriptor always requires a FUNCDESC_VALUE relocation. 5980 Whether it's in .plt.rel or not depends on whether lazy binding is 5981 enabled and on whether the referenced symbol is dynamic. 5982 5983 The existence of a lazy PLT requires the resolverStub lazy PLT 5984 entry to be present. 5985 5986 5987 As for assignment of GOT, PLT and lazy PLT entries, and private 5988 descriptors, we might do them all sequentially, but we can do 5989 better than that. For example, we can place GOT entries and 5990 private function descriptors referenced using 12-bit operands 5991 closer to the PIC register value, such that these relocations don't 5992 overflow. Those that are only referenced with LO16 relocations 5993 could come next, but we may as well place PLT-required function 5994 descriptors in the 12-bit range to make them shorter. Symbols 5995 referenced with LO16/HI16 may come next, but we may place 5996 additional function descriptors in the 16-bit range if we can 5997 reliably tell that we've already placed entries that are ever 5998 referenced with only LO16. PLT entries are therefore generated as 5999 small as possible, while not introducing relocation overflows in 6000 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be 6001 generated before or after PLT entries, but not intermingled with 6002 them, such that we can have more lazy PLT entries in range for a 6003 branch to the resolverStub. The resolverStub should be emitted at 6004 the most distant location from the first lazy PLT entry such that 6005 it's still in range for a branch, or closer, if there isn't a need 6006 for so many lazy PLT entries. Additional lazy PLT entries may be 6007 emitted after the resolverStub, as long as branches are still in 6008 range. If the branch goes out of range, longer lazy PLT entries 6009 are emitted. 6010 6011 We could further optimize PLT and lazy PLT entries by giving them 6012 priority in assignment to closer-to-gr17 locations depending on the 6013 number of occurrences of references to them (assuming a function 6014 that's called more often is more important for performance, so its 6015 PLT entry should be faster), or taking hints from the compiler. 6016 Given infinite time and money... :-) */ 6017 6018 static bfd_boolean 6019 elf32_frv_check_relocs (bfd *abfd, 6020 struct bfd_link_info *info, 6021 asection *sec, 6022 const Elf_Internal_Rela *relocs) 6023 { 6024 Elf_Internal_Shdr *symtab_hdr; 6025 struct elf_link_hash_entry **sym_hashes; 6026 const Elf_Internal_Rela *rel; 6027 const Elf_Internal_Rela *rel_end; 6028 bfd *dynobj; 6029 struct frvfdpic_relocs_info *picrel; 6030 6031 if (info->relocatable) 6032 return TRUE; 6033 6034 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 6035 sym_hashes = elf_sym_hashes (abfd); 6036 6037 dynobj = elf_hash_table (info)->dynobj; 6038 rel_end = relocs + sec->reloc_count; 6039 for (rel = relocs; rel < rel_end; rel++) 6040 { 6041 struct elf_link_hash_entry *h; 6042 unsigned long r_symndx; 6043 6044 r_symndx = ELF32_R_SYM (rel->r_info); 6045 if (r_symndx < symtab_hdr->sh_info) 6046 h = NULL; 6047 else 6048 { 6049 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 6050 while (h->root.type == bfd_link_hash_indirect 6051 || h->root.type == bfd_link_hash_warning) 6052 h = (struct elf_link_hash_entry *) h->root.u.i.link; 6053 6054 /* PR15323, ref flags aren't set for references in the same 6055 object. */ 6056 h->root.non_ir_ref = 1; 6057 } 6058 6059 switch (ELF32_R_TYPE (rel->r_info)) 6060 { 6061 case R_FRV_GETTLSOFF: 6062 case R_FRV_TLSDESC_VALUE: 6063 case R_FRV_GOTTLSDESC12: 6064 case R_FRV_GOTTLSDESCHI: 6065 case R_FRV_GOTTLSDESCLO: 6066 case R_FRV_GOTTLSOFF12: 6067 case R_FRV_GOTTLSOFFHI: 6068 case R_FRV_GOTTLSOFFLO: 6069 case R_FRV_TLSOFF: 6070 case R_FRV_GOT12: 6071 case R_FRV_GOTHI: 6072 case R_FRV_GOTLO: 6073 case R_FRV_FUNCDESC_GOT12: 6074 case R_FRV_FUNCDESC_GOTHI: 6075 case R_FRV_FUNCDESC_GOTLO: 6076 case R_FRV_GOTOFF12: 6077 case R_FRV_GOTOFFHI: 6078 case R_FRV_GOTOFFLO: 6079 case R_FRV_FUNCDESC_GOTOFF12: 6080 case R_FRV_FUNCDESC_GOTOFFHI: 6081 case R_FRV_FUNCDESC_GOTOFFLO: 6082 case R_FRV_FUNCDESC: 6083 case R_FRV_FUNCDESC_VALUE: 6084 case R_FRV_TLSMOFF12: 6085 case R_FRV_TLSMOFFHI: 6086 case R_FRV_TLSMOFFLO: 6087 case R_FRV_TLSMOFF: 6088 if (! IS_FDPIC (abfd)) 6089 goto bad_reloc; 6090 /* Fall through. */ 6091 case R_FRV_GPREL12: 6092 case R_FRV_GPRELU12: 6093 case R_FRV_GPRELHI: 6094 case R_FRV_GPRELLO: 6095 case R_FRV_LABEL24: 6096 case R_FRV_32: 6097 if (! dynobj) 6098 { 6099 elf_hash_table (info)->dynobj = dynobj = abfd; 6100 if (! _frv_create_got_section (abfd, info)) 6101 return FALSE; 6102 } 6103 if (! IS_FDPIC (abfd)) 6104 { 6105 picrel = NULL; 6106 break; 6107 } 6108 if (h != NULL) 6109 { 6110 if (h->dynindx == -1) 6111 switch (ELF_ST_VISIBILITY (h->other)) 6112 { 6113 case STV_INTERNAL: 6114 case STV_HIDDEN: 6115 break; 6116 default: 6117 bfd_elf_link_record_dynamic_symbol (info, h); 6118 break; 6119 } 6120 picrel 6121 = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info), 6122 abfd, h, 6123 rel->r_addend, INSERT); 6124 } 6125 else 6126 picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info 6127 (info), abfd, r_symndx, 6128 rel->r_addend, INSERT); 6129 if (! picrel) 6130 return FALSE; 6131 break; 6132 6133 default: 6134 picrel = NULL; 6135 break; 6136 } 6137 6138 switch (ELF32_R_TYPE (rel->r_info)) 6139 { 6140 case R_FRV_LABEL24: 6141 if (IS_FDPIC (abfd)) 6142 picrel->call = 1; 6143 break; 6144 6145 case R_FRV_FUNCDESC_VALUE: 6146 picrel->relocsfdv++; 6147 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) 6148 picrel->relocs32--; 6149 /* Fall through. */ 6150 6151 case R_FRV_32: 6152 if (! IS_FDPIC (abfd)) 6153 break; 6154 6155 picrel->sym = 1; 6156 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) 6157 picrel->relocs32++; 6158 break; 6159 6160 case R_FRV_GOT12: 6161 picrel->got12 = 1; 6162 break; 6163 6164 case R_FRV_GOTHI: 6165 case R_FRV_GOTLO: 6166 picrel->gothilo = 1; 6167 break; 6168 6169 case R_FRV_FUNCDESC_GOT12: 6170 picrel->fdgot12 = 1; 6171 break; 6172 6173 case R_FRV_FUNCDESC_GOTHI: 6174 case R_FRV_FUNCDESC_GOTLO: 6175 picrel->fdgothilo = 1; 6176 break; 6177 6178 case R_FRV_GOTOFF12: 6179 case R_FRV_GOTOFFHI: 6180 case R_FRV_GOTOFFLO: 6181 picrel->gotoff = 1; 6182 break; 6183 6184 case R_FRV_FUNCDESC_GOTOFF12: 6185 picrel->fdgoff12 = 1; 6186 break; 6187 6188 case R_FRV_FUNCDESC_GOTOFFHI: 6189 case R_FRV_FUNCDESC_GOTOFFLO: 6190 picrel->fdgoffhilo = 1; 6191 break; 6192 6193 case R_FRV_FUNCDESC: 6194 picrel->fd = 1; 6195 picrel->relocsfd++; 6196 break; 6197 6198 case R_FRV_GETTLSOFF: 6199 picrel->tlsplt = 1; 6200 break; 6201 6202 case R_FRV_TLSDESC_VALUE: 6203 picrel->relocstlsd++; 6204 goto bad_reloc; 6205 6206 case R_FRV_GOTTLSDESC12: 6207 picrel->tlsdesc12 = 1; 6208 break; 6209 6210 case R_FRV_GOTTLSDESCHI: 6211 case R_FRV_GOTTLSDESCLO: 6212 picrel->tlsdeschilo = 1; 6213 break; 6214 6215 case R_FRV_TLSMOFF12: 6216 case R_FRV_TLSMOFFHI: 6217 case R_FRV_TLSMOFFLO: 6218 case R_FRV_TLSMOFF: 6219 break; 6220 6221 case R_FRV_GOTTLSOFF12: 6222 picrel->tlsoff12 = 1; 6223 info->flags |= DF_STATIC_TLS; 6224 break; 6225 6226 case R_FRV_GOTTLSOFFHI: 6227 case R_FRV_GOTTLSOFFLO: 6228 picrel->tlsoffhilo = 1; 6229 info->flags |= DF_STATIC_TLS; 6230 break; 6231 6232 case R_FRV_TLSOFF: 6233 picrel->relocstlsoff++; 6234 info->flags |= DF_STATIC_TLS; 6235 goto bad_reloc; 6236 6237 /* This relocation describes the C++ object vtable hierarchy. 6238 Reconstruct it for later use during GC. */ 6239 case R_FRV_GNU_VTINHERIT: 6240 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 6241 return FALSE; 6242 break; 6243 6244 /* This relocation describes which C++ vtable entries are actually 6245 used. Record for later use during GC. */ 6246 case R_FRV_GNU_VTENTRY: 6247 BFD_ASSERT (h != NULL); 6248 if (h != NULL 6249 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 6250 return FALSE; 6251 break; 6252 6253 case R_FRV_LABEL16: 6254 case R_FRV_LO16: 6255 case R_FRV_HI16: 6256 case R_FRV_GPREL12: 6257 case R_FRV_GPRELU12: 6258 case R_FRV_GPREL32: 6259 case R_FRV_GPRELHI: 6260 case R_FRV_GPRELLO: 6261 case R_FRV_TLSDESC_RELAX: 6262 case R_FRV_GETTLSOFF_RELAX: 6263 case R_FRV_TLSOFF_RELAX: 6264 break; 6265 6266 default: 6267 bad_reloc: 6268 info->callbacks->einfo 6269 (_("%B: unsupported relocation type %i\n"), 6270 abfd, ELF32_R_TYPE (rel->r_info)); 6271 return FALSE; 6272 } 6273 } 6274 6275 return TRUE; 6276 } 6277 6278 6279 /* Return the machine subcode from the ELF e_flags header. */ 6281 6282 static int 6283 elf32_frv_machine (bfd *abfd) 6284 { 6285 switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK) 6286 { 6287 default: break; 6288 case EF_FRV_CPU_FR550: return bfd_mach_fr550; 6289 case EF_FRV_CPU_FR500: return bfd_mach_fr500; 6290 case EF_FRV_CPU_FR450: return bfd_mach_fr450; 6291 case EF_FRV_CPU_FR405: return bfd_mach_fr400; 6292 case EF_FRV_CPU_FR400: return bfd_mach_fr400; 6293 case EF_FRV_CPU_FR300: return bfd_mach_fr300; 6294 case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple; 6295 case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat; 6296 } 6297 6298 return bfd_mach_frv; 6299 } 6300 6301 /* Set the right machine number for a FRV ELF file. */ 6302 6303 static bfd_boolean 6304 elf32_frv_object_p (bfd *abfd) 6305 { 6306 bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd)); 6307 return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0) 6308 == (IS_FDPIC (abfd))); 6309 } 6310 6311 /* Function to set the ELF flag bits. */ 6313 6314 static bfd_boolean 6315 frv_elf_set_private_flags (bfd *abfd, flagword flags) 6316 { 6317 elf_elfheader (abfd)->e_flags = flags; 6318 elf_flags_init (abfd) = TRUE; 6319 return TRUE; 6320 } 6321 6322 /* Return true if the architecture described by elf header flag 6323 EXTENSION is an extension of the architecture described by BASE. */ 6324 6325 static bfd_boolean 6326 frv_elf_arch_extension_p (flagword base, flagword extension) 6327 { 6328 if (base == extension) 6329 return TRUE; 6330 6331 /* CPU_GENERIC code can be merged with code for a specific 6332 architecture, in which case the result is marked as being 6333 for the specific architecture. Everything is therefore 6334 an extension of CPU_GENERIC. */ 6335 if (base == EF_FRV_CPU_GENERIC) 6336 return TRUE; 6337 6338 if (extension == EF_FRV_CPU_FR450) 6339 if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405) 6340 return TRUE; 6341 6342 if (extension == EF_FRV_CPU_FR405) 6343 if (base == EF_FRV_CPU_FR400) 6344 return TRUE; 6345 6346 return FALSE; 6347 } 6348 6349 /* Merge backend specific data from an object file to the output 6350 object file when linking. */ 6351 6352 static bfd_boolean 6353 frv_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) 6354 { 6355 flagword old_flags, old_partial; 6356 flagword new_flags, new_partial; 6357 bfd_boolean error = FALSE; 6358 char new_opt[80]; 6359 char old_opt[80]; 6360 6361 new_opt[0] = old_opt[0] = '\0'; 6362 new_flags = elf_elfheader (ibfd)->e_flags; 6363 old_flags = elf_elfheader (obfd)->e_flags; 6364 6365 if (new_flags & EF_FRV_FDPIC) 6366 new_flags &= ~EF_FRV_PIC; 6367 6368 #ifdef DEBUG 6369 (*_bfd_error_handler) ("old_flags = 0x%.8lx, new_flags = 0x%.8lx, init = %s, filename = %s", 6370 old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no", 6371 bfd_get_filename (ibfd)); 6372 #endif 6373 6374 if (!elf_flags_init (obfd)) /* First call, no flags set. */ 6375 { 6376 elf_flags_init (obfd) = TRUE; 6377 old_flags = new_flags; 6378 } 6379 6380 else if (new_flags == old_flags) /* Compatible flags are ok. */ 6381 ; 6382 6383 else /* Possibly incompatible flags. */ 6384 { 6385 /* Warn if different # of gprs are used. Note, 0 means nothing is 6386 said about the size of gprs. */ 6387 new_partial = (new_flags & EF_FRV_GPR_MASK); 6388 old_partial = (old_flags & EF_FRV_GPR_MASK); 6389 if (new_partial == old_partial) 6390 ; 6391 6392 else if (new_partial == 0) 6393 ; 6394 6395 else if (old_partial == 0) 6396 old_flags |= new_partial; 6397 6398 else 6399 { 6400 switch (new_partial) 6401 { 6402 default: strcat (new_opt, " -mgpr-??"); break; 6403 case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break; 6404 case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break; 6405 } 6406 6407 switch (old_partial) 6408 { 6409 default: strcat (old_opt, " -mgpr-??"); break; 6410 case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break; 6411 case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break; 6412 } 6413 } 6414 6415 /* Warn if different # of fprs are used. Note, 0 means nothing is 6416 said about the size of fprs. */ 6417 new_partial = (new_flags & EF_FRV_FPR_MASK); 6418 old_partial = (old_flags & EF_FRV_FPR_MASK); 6419 if (new_partial == old_partial) 6420 ; 6421 6422 else if (new_partial == 0) 6423 ; 6424 6425 else if (old_partial == 0) 6426 old_flags |= new_partial; 6427 6428 else 6429 { 6430 switch (new_partial) 6431 { 6432 default: strcat (new_opt, " -mfpr-?"); break; 6433 case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break; 6434 case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break; 6435 case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break; 6436 } 6437 6438 switch (old_partial) 6439 { 6440 default: strcat (old_opt, " -mfpr-?"); break; 6441 case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break; 6442 case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break; 6443 case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break; 6444 } 6445 } 6446 6447 /* Warn if different dword support was used. Note, 0 means nothing is 6448 said about the dword support. */ 6449 new_partial = (new_flags & EF_FRV_DWORD_MASK); 6450 old_partial = (old_flags & EF_FRV_DWORD_MASK); 6451 if (new_partial == old_partial) 6452 ; 6453 6454 else if (new_partial == 0) 6455 ; 6456 6457 else if (old_partial == 0) 6458 old_flags |= new_partial; 6459 6460 else 6461 { 6462 switch (new_partial) 6463 { 6464 default: strcat (new_opt, " -mdword-?"); break; 6465 case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break; 6466 case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break; 6467 } 6468 6469 switch (old_partial) 6470 { 6471 default: strcat (old_opt, " -mdword-?"); break; 6472 case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break; 6473 case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break; 6474 } 6475 } 6476 6477 /* Or in flags that accumulate (ie, if one module uses it, mark that the 6478 feature is used. */ 6479 old_flags |= new_flags & (EF_FRV_DOUBLE 6480 | EF_FRV_MEDIA 6481 | EF_FRV_MULADD 6482 | EF_FRV_NON_PIC_RELOCS); 6483 6484 /* If any module was compiled without -G0, clear the G0 bit. */ 6485 old_flags = ((old_flags & ~ EF_FRV_G0) 6486 | (old_flags & new_flags & EF_FRV_G0)); 6487 6488 /* If any module was compiled without -mnopack, clear the mnopack bit. */ 6489 old_flags = ((old_flags & ~ EF_FRV_NOPACK) 6490 | (old_flags & new_flags & EF_FRV_NOPACK)); 6491 6492 /* We don't have to do anything if the pic flags are the same, or the new 6493 module(s) were compiled with -mlibrary-pic. */ 6494 new_partial = (new_flags & EF_FRV_PIC_FLAGS); 6495 old_partial = (old_flags & EF_FRV_PIC_FLAGS); 6496 if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0)) 6497 ; 6498 6499 /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic 6500 flags if any from the new module. */ 6501 else if ((old_partial & EF_FRV_LIBPIC) != 0) 6502 old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial; 6503 6504 /* If we have mixtures of -fpic and -fPIC, or in both bits. */ 6505 else if (new_partial != 0 && old_partial != 0) 6506 old_flags |= new_partial; 6507 6508 /* One module was compiled for pic and the other was not, see if we have 6509 had any relocations that are not pic-safe. */ 6510 else 6511 { 6512 if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0) 6513 old_flags |= new_partial; 6514 else 6515 { 6516 old_flags &= ~ EF_FRV_PIC_FLAGS; 6517 #ifndef FRV_NO_PIC_ERROR 6518 error = TRUE; 6519 (*_bfd_error_handler) 6520 (_("%s: compiled with %s and linked with modules that use non-pic relocations"), 6521 bfd_get_filename (ibfd), 6522 (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic"); 6523 #endif 6524 } 6525 } 6526 6527 /* Warn if different cpu is used (allow a specific cpu to override 6528 the generic cpu). */ 6529 new_partial = (new_flags & EF_FRV_CPU_MASK); 6530 old_partial = (old_flags & EF_FRV_CPU_MASK); 6531 if (frv_elf_arch_extension_p (new_partial, old_partial)) 6532 ; 6533 6534 else if (frv_elf_arch_extension_p (old_partial, new_partial)) 6535 old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial; 6536 6537 else 6538 { 6539 switch (new_partial) 6540 { 6541 default: strcat (new_opt, " -mcpu=?"); break; 6542 case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break; 6543 case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break; 6544 case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break; 6545 case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break; 6546 case EF_FRV_CPU_FR450: strcat (new_opt, " -mcpu=fr450"); break; 6547 case EF_FRV_CPU_FR405: strcat (new_opt, " -mcpu=fr405"); break; 6548 case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break; 6549 case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break; 6550 case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break; 6551 } 6552 6553 switch (old_partial) 6554 { 6555 default: strcat (old_opt, " -mcpu=?"); break; 6556 case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break; 6557 case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break; 6558 case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break; 6559 case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break; 6560 case EF_FRV_CPU_FR450: strcat (old_opt, " -mcpu=fr450"); break; 6561 case EF_FRV_CPU_FR405: strcat (old_opt, " -mcpu=fr405"); break; 6562 case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break; 6563 case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break; 6564 case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break; 6565 } 6566 } 6567 6568 /* Print out any mismatches from above. */ 6569 if (new_opt[0]) 6570 { 6571 error = TRUE; 6572 (*_bfd_error_handler) 6573 (_("%s: compiled with %s and linked with modules compiled with %s"), 6574 bfd_get_filename (ibfd), new_opt, old_opt); 6575 } 6576 6577 /* Warn about any other mismatches */ 6578 new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS); 6579 old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS); 6580 if (new_partial != old_partial) 6581 { 6582 old_flags |= new_partial; 6583 error = TRUE; 6584 (*_bfd_error_handler) 6585 (_("%s: uses different unknown e_flags (0x%lx) fields than previous modules (0x%lx)"), 6586 bfd_get_filename (ibfd), (long)new_partial, (long)old_partial); 6587 } 6588 } 6589 6590 /* If the cpu is -mcpu=simple, then set the -mnopack bit. */ 6591 if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE) 6592 old_flags |= EF_FRV_NOPACK; 6593 6594 /* Update the old flags now with changes made above. */ 6595 old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK; 6596 elf_elfheader (obfd)->e_flags = old_flags; 6597 if (old_partial != (old_flags & EF_FRV_CPU_MASK)) 6598 bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd)); 6599 6600 if (((new_flags & EF_FRV_FDPIC) == 0) 6601 != (! IS_FDPIC (ibfd))) 6602 { 6603 error = TRUE; 6604 if (IS_FDPIC (obfd)) 6605 (*_bfd_error_handler) 6606 (_("%s: cannot link non-fdpic object file into fdpic executable"), 6607 bfd_get_filename (ibfd)); 6608 else 6609 (*_bfd_error_handler) 6610 (_("%s: cannot link fdpic object file into non-fdpic executable"), 6611 bfd_get_filename (ibfd)); 6612 } 6613 6614 if (error) 6615 bfd_set_error (bfd_error_bad_value); 6616 6617 return !error; 6618 } 6619 6620 6621 static bfd_boolean 6623 frv_elf_print_private_bfd_data (bfd *abfd, void * ptr) 6624 { 6625 FILE *file = (FILE *) ptr; 6626 flagword flags; 6627 6628 BFD_ASSERT (abfd != NULL && ptr != NULL); 6629 6630 /* Print normal ELF private data. */ 6631 _bfd_elf_print_private_bfd_data (abfd, ptr); 6632 6633 flags = elf_elfheader (abfd)->e_flags; 6634 fprintf (file, _("private flags = 0x%lx:"), (unsigned long) flags); 6635 6636 switch (flags & EF_FRV_CPU_MASK) 6637 { 6638 default: break; 6639 case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break; 6640 case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break; 6641 case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break; 6642 case EF_FRV_CPU_FR450: fprintf (file, " -mcpu=fr450"); break; 6643 case EF_FRV_CPU_FR405: fprintf (file, " -mcpu=fr405"); break; 6644 case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break; 6645 case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break; 6646 case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break; 6647 } 6648 6649 switch (flags & EF_FRV_GPR_MASK) 6650 { 6651 default: break; 6652 case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break; 6653 case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break; 6654 } 6655 6656 switch (flags & EF_FRV_FPR_MASK) 6657 { 6658 default: break; 6659 case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break; 6660 case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break; 6661 case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break; 6662 } 6663 6664 switch (flags & EF_FRV_DWORD_MASK) 6665 { 6666 default: break; 6667 case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break; 6668 case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break; 6669 } 6670 6671 if (flags & EF_FRV_DOUBLE) 6672 fprintf (file, " -mdouble"); 6673 6674 if (flags & EF_FRV_MEDIA) 6675 fprintf (file, " -mmedia"); 6676 6677 if (flags & EF_FRV_MULADD) 6678 fprintf (file, " -mmuladd"); 6679 6680 if (flags & EF_FRV_PIC) 6681 fprintf (file, " -fpic"); 6682 6683 if (flags & EF_FRV_BIGPIC) 6684 fprintf (file, " -fPIC"); 6685 6686 if (flags & EF_FRV_LIBPIC) 6687 fprintf (file, " -mlibrary-pic"); 6688 6689 if (flags & EF_FRV_FDPIC) 6690 fprintf (file, " -mfdpic"); 6691 6692 if (flags & EF_FRV_NON_PIC_RELOCS) 6693 fprintf (file, " non-pic relocations"); 6694 6695 if (flags & EF_FRV_G0) 6696 fprintf (file, " -G0"); 6697 6698 fputc ('\n', file); 6699 return TRUE; 6700 } 6701 6702 6703 /* Support for core dump NOTE sections. */ 6705 6706 static bfd_boolean 6707 elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) 6708 { 6709 int offset; 6710 unsigned int raw_size; 6711 6712 switch (note->descsz) 6713 { 6714 default: 6715 return FALSE; 6716 6717 /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other 6718 hardcoded offsets and sizes listed below (and contained within 6719 this lexical block) refer to fields in the target's elf_prstatus 6720 struct. */ 6721 case 268: 6722 /* `pr_cursig' is at offset 12. */ 6723 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); 6724 6725 /* `pr_pid' is at offset 24. */ 6726 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24); 6727 6728 /* `pr_reg' is at offset 72. */ 6729 offset = 72; 6730 6731 /* Most grok_prstatus implementations set `raw_size' to the size 6732 of the pr_reg field. For Linux/FRV, we set `raw_size' to be 6733 the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap' 6734 and `pr_interp_fdpic_loadmap', both of which (by design) 6735 immediately follow `pr_reg'. This will allow these fields to 6736 be viewed by GDB as registers. 6737 6738 `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and 6739 `pr_interp_fdpic_loadmap' are 4 bytes each. */ 6740 raw_size = 184 + 4 + 4; 6741 6742 break; 6743 } 6744 6745 /* Make a ".reg/999" section. */ 6746 return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size, 6747 note->descpos + offset); 6748 } 6749 6750 static bfd_boolean 6751 elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) 6752 { 6753 switch (note->descsz) 6754 { 6755 default: 6756 return FALSE; 6757 6758 /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */ 6759 case 124: 6760 6761 /* `pr_fname' is found at offset 28 and is 16 bytes long. */ 6762 elf_tdata (abfd)->core->program 6763 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); 6764 6765 /* `pr_psargs' is found at offset 44 and is 80 bytes long. */ 6766 elf_tdata (abfd)->core->command 6767 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); 6768 } 6769 6770 /* Note that for some reason, a spurious space is tacked 6771 onto the end of the args in some (at least one anyway) 6772 implementations, so strip it off if it exists. */ 6773 6774 { 6775 char *command = elf_tdata (abfd)->core->command; 6776 int n = strlen (command); 6777 6778 if (0 < n && command[n - 1] == ' ') 6779 command[n - 1] = '\0'; 6780 } 6781 6782 return TRUE; 6783 } 6784 #define ELF_ARCH bfd_arch_frv 6785 #define ELF_TARGET_ID FRV_ELF_DATA 6786 #define ELF_MACHINE_CODE EM_CYGNUS_FRV 6787 #define ELF_MAXPAGESIZE 0x1000 6788 6789 #define TARGET_BIG_SYM frv_elf32_vec 6790 #define TARGET_BIG_NAME "elf32-frv" 6791 6792 #define elf_info_to_howto frv_info_to_howto_rela 6793 #define elf_backend_relocate_section elf32_frv_relocate_section 6794 #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook 6795 #define elf_backend_check_relocs elf32_frv_check_relocs 6796 #define elf_backend_object_p elf32_frv_object_p 6797 #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook 6798 6799 #define elf_backend_stack_align 8 6800 #define elf_backend_can_gc_sections 1 6801 #define elf_backend_rela_normal 1 6802 6803 #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup 6804 #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup 6805 #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags 6806 #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data 6807 #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data 6808 6809 #define elf_backend_want_got_sym 1 6810 #define elf_backend_got_header_size 0 6811 #define elf_backend_want_got_plt 0 6812 #define elf_backend_plt_readonly 1 6813 #define elf_backend_want_plt_sym 0 6814 #define elf_backend_plt_header_size 0 6815 6816 #define elf_backend_finish_dynamic_sections \ 6817 elf32_frv_finish_dynamic_sections 6818 6819 #define elf_backend_grok_prstatus elf32_frv_grok_prstatus 6820 #define elf_backend_grok_psinfo elf32_frv_grok_psinfo 6821 6822 #include "elf32-target.h" 6823 6824 #undef ELF_MAXPAGESIZE 6825 #define ELF_MAXPAGESIZE 0x4000 6826 6827 #undef TARGET_BIG_SYM 6828 #define TARGET_BIG_SYM frv_elf32_fdpic_vec 6829 #undef TARGET_BIG_NAME 6830 #define TARGET_BIG_NAME "elf32-frvfdpic" 6831 #undef elf32_bed 6832 #define elf32_bed elf32_frvfdpic_bed 6833 6834 #undef elf_info_to_howto_rel 6835 #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel 6836 6837 #undef bfd_elf32_bfd_link_hash_table_create 6838 #define bfd_elf32_bfd_link_hash_table_create \ 6839 frvfdpic_elf_link_hash_table_create 6840 #undef elf_backend_always_size_sections 6841 #define elf_backend_always_size_sections \ 6842 elf32_frvfdpic_always_size_sections 6843 6844 #undef elf_backend_create_dynamic_sections 6845 #define elf_backend_create_dynamic_sections \ 6846 elf32_frvfdpic_create_dynamic_sections 6847 #undef elf_backend_adjust_dynamic_symbol 6848 #define elf_backend_adjust_dynamic_symbol \ 6849 elf32_frvfdpic_adjust_dynamic_symbol 6850 #undef elf_backend_size_dynamic_sections 6851 #define elf_backend_size_dynamic_sections \ 6852 elf32_frvfdpic_size_dynamic_sections 6853 #undef bfd_elf32_bfd_relax_section 6854 #define bfd_elf32_bfd_relax_section \ 6855 elf32_frvfdpic_relax_section 6856 #undef elf_backend_finish_dynamic_symbol 6857 #define elf_backend_finish_dynamic_symbol \ 6858 elf32_frvfdpic_finish_dynamic_symbol 6859 #undef elf_backend_finish_dynamic_sections 6860 #define elf_backend_finish_dynamic_sections \ 6861 elf32_frvfdpic_finish_dynamic_sections 6862 6863 #undef elf_backend_discard_info 6864 #define elf_backend_discard_info \ 6865 frvfdpic_elf_discard_info 6866 #undef elf_backend_can_make_relative_eh_frame 6867 #define elf_backend_can_make_relative_eh_frame \ 6868 frvfdpic_elf_use_relative_eh_frame 6869 #undef elf_backend_can_make_lsda_relative_eh_frame 6870 #define elf_backend_can_make_lsda_relative_eh_frame \ 6871 frvfdpic_elf_use_relative_eh_frame 6872 #undef elf_backend_encode_eh_address 6873 #define elf_backend_encode_eh_address \ 6874 frvfdpic_elf_encode_eh_address 6875 6876 #undef elf_backend_may_use_rel_p 6877 #define elf_backend_may_use_rel_p 1 6878 #undef elf_backend_may_use_rela_p 6879 #define elf_backend_may_use_rela_p 1 6880 /* We use REL for dynamic relocations only. */ 6881 #undef elf_backend_default_use_rela_p 6882 #define elf_backend_default_use_rela_p 1 6883 6884 #undef elf_backend_omit_section_dynsym 6885 #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym 6886 6887 #include "elf32-target.h" 6888