OLD | NEW |
1 /* Matsushita 10300 specific support for 32-bit ELF | 1 /* Matsushita 10300 specific support for 32-bit ELF |
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, | 2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, |
3 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. | 3 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of BFD, the Binary File Descriptor library. | 5 This file is part of BFD, the Binary File Descriptor library. |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify | 7 This program is free software; you can redistribute it and/or modify |
8 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
9 the Free Software Foundation; either version 3 of the License, or | 9 the Free Software Foundation; either version 3 of the License, or |
10 (at your option) any later version. | 10 (at your option) any later version. |
11 | 11 |
12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 instructions. */ | 62 instructions. */ |
63 #define MN10300_CONVERT_CALL_TO_CALLS 0x1 | 63 #define MN10300_CONVERT_CALL_TO_CALLS 0x1 |
64 | 64 |
65 /* Used to mark functions which have had redundant parts of their | 65 /* Used to mark functions which have had redundant parts of their |
66 prologue deleted. */ | 66 prologue deleted. */ |
67 #define MN10300_DELETED_PROLOGUE_BYTES 0x2 | 67 #define MN10300_DELETED_PROLOGUE_BYTES 0x2 |
68 unsigned char flags; | 68 unsigned char flags; |
69 | 69 |
70 /* Calculated value. */ | 70 /* Calculated value. */ |
71 bfd_vma value; | 71 bfd_vma value; |
| 72 |
| 73 #define GOT_UNKNOWN 0 |
| 74 #define GOT_NORMAL 1 |
| 75 #define GOT_TLS_GD 2 |
| 76 #define GOT_TLS_LD 3 |
| 77 #define GOT_TLS_IE 4 |
| 78 /* Used to distinguish GOT entries for TLS types from normal GOT entries. */ |
| 79 unsigned char tls_type; |
72 }; | 80 }; |
73 | 81 |
74 /* We derive a hash table from the main elf linker hash table so | 82 /* We derive a hash table from the main elf linker hash table so |
75 we can store state variables and a secondary hash table without | 83 we can store state variables and a secondary hash table without |
76 resorting to global variables. */ | 84 resorting to global variables. */ |
77 struct elf32_mn10300_link_hash_table | 85 struct elf32_mn10300_link_hash_table |
78 { | 86 { |
79 /* The main hash table. */ | 87 /* The main hash table. */ |
80 struct elf_link_hash_table root; | 88 struct elf_link_hash_table root; |
81 | 89 |
82 /* A hash table for static functions. We could derive a new hash table | 90 /* A hash table for static functions. We could derive a new hash table |
83 instead of using the full elf32_mn10300_link_hash_table if we wanted | 91 instead of using the full elf32_mn10300_link_hash_table if we wanted |
84 to save some memory. */ | 92 to save some memory. */ |
85 struct elf32_mn10300_link_hash_table *static_hash_table; | 93 struct elf32_mn10300_link_hash_table *static_hash_table; |
86 | 94 |
87 /* Random linker state flags. */ | 95 /* Random linker state flags. */ |
88 #define MN10300_HASH_ENTRIES_INITIALIZED 0x1 | 96 #define MN10300_HASH_ENTRIES_INITIALIZED 0x1 |
89 char flags; | 97 char flags; |
| 98 struct |
| 99 { |
| 100 bfd_signed_vma refcount; |
| 101 bfd_vma offset; |
| 102 char got_allocated; |
| 103 char rel_emitted; |
| 104 } tls_ldm_got; |
90 }; | 105 }; |
91 | 106 |
| 107 #define elf_mn10300_hash_entry(ent) ((struct elf32_mn10300_link_hash_entry *)(en
t)) |
| 108 |
| 109 struct elf_mn10300_obj_tdata |
| 110 { |
| 111 struct elf_obj_tdata root; |
| 112 |
| 113 /* tls_type for each local got entry. */ |
| 114 char * local_got_tls_type; |
| 115 }; |
| 116 |
| 117 #define elf_mn10300_tdata(abfd) \ |
| 118 ((struct elf_mn10300_obj_tdata *) (abfd)->tdata.any) |
| 119 |
| 120 #define elf_mn10300_local_got_tls_type(abfd) \ |
| 121 (elf_mn10300_tdata (abfd)->local_got_tls_type) |
| 122 |
92 #ifndef streq | 123 #ifndef streq |
93 #define streq(a, b) (strcmp ((a),(b)) == 0) | 124 #define streq(a, b) (strcmp ((a),(b)) == 0) |
94 #endif | 125 #endif |
95 | 126 |
96 /* For MN10300 linker hash table. */ | 127 /* For MN10300 linker hash table. */ |
97 | 128 |
98 /* Get the MN10300 ELF linker hash table from a link_info structure. */ | 129 /* Get the MN10300 ELF linker hash table from a link_info structure. */ |
99 | 130 |
100 #define elf32_mn10300_hash_table(p) \ | 131 #define elf32_mn10300_hash_table(p) \ |
101 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ | 132 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 FALSE, /* pc_relative */ | 472 FALSE, /* pc_relative */ |
442 0, /* bitpos */ | 473 0, /* bitpos */ |
443 complain_overflow_bitfield, /* complain_on_overflow */ | 474 complain_overflow_bitfield, /* complain_on_overflow */ |
444 bfd_elf_generic_reloc, /* */ | 475 bfd_elf_generic_reloc, /* */ |
445 "R_MN10300_RELATIVE", /* name */ | 476 "R_MN10300_RELATIVE", /* name */ |
446 FALSE, /* partial_inplace */ | 477 FALSE, /* partial_inplace */ |
447 0xffffffff, /* src_mask */ | 478 0xffffffff, /* src_mask */ |
448 0xffffffff, /* dst_mask */ | 479 0xffffffff, /* dst_mask */ |
449 FALSE), /* pcrel_offset */ | 480 FALSE), /* pcrel_offset */ |
450 | 481 |
451 EMPTY_HOWTO (24), | 482 HOWTO (R_MN10300_TLS_GD,» /* type */ |
452 EMPTY_HOWTO (25), | 483 » 0,» » » /* rightshift */ |
453 EMPTY_HOWTO (26), | 484 » 2,» » » /* size (0 = byte, 1 = short, 2 = long) */ |
454 EMPTY_HOWTO (27), | 485 » 32,» » » /* bitsize */ |
455 EMPTY_HOWTO (28), | 486 » FALSE,»» » /* pc_relative */ |
456 EMPTY_HOWTO (29), | 487 » 0,» » » /* bitpos */ |
457 EMPTY_HOWTO (30), | 488 » complain_overflow_bitfield, /* complain_on_overflow */ |
458 EMPTY_HOWTO (31), | 489 » bfd_elf_generic_reloc, /* */ |
459 EMPTY_HOWTO (32), | 490 » "R_MN10300_TLS_GD",» /* name */ |
| 491 » FALSE,»» » /* partial_inplace */ |
| 492 » 0xffffffff,» » /* src_mask */ |
| 493 » 0xffffffff,» » /* dst_mask */ |
| 494 » FALSE),» » /* pcrel_offset */ |
| 495 |
| 496 HOWTO (R_MN10300_TLS_LD,» /* type */ |
| 497 » 0,» » » /* rightshift */ |
| 498 » 2,» » » /* size (0 = byte, 1 = short, 2 = long) */ |
| 499 » 32,» » » /* bitsize */ |
| 500 » FALSE,»» » /* pc_relative */ |
| 501 » 0,» » » /* bitpos */ |
| 502 » complain_overflow_bitfield, /* complain_on_overflow */ |
| 503 » bfd_elf_generic_reloc, /* */ |
| 504 » "R_MN10300_TLS_LD",» /* name */ |
| 505 » FALSE,»» » /* partial_inplace */ |
| 506 » 0xffffffff,» » /* src_mask */ |
| 507 » 0xffffffff,» » /* dst_mask */ |
| 508 » FALSE),» » /* pcrel_offset */ |
| 509 |
| 510 HOWTO (R_MN10300_TLS_LDO,» /* type */ |
| 511 » 0,» » » /* rightshift */ |
| 512 » 2,» » » /* size (0 = byte, 1 = short, 2 = long) */ |
| 513 » 32,» » » /* bitsize */ |
| 514 » FALSE,»» » /* pc_relative */ |
| 515 » 0,» » » /* bitpos */ |
| 516 » complain_overflow_bitfield, /* complain_on_overflow */ |
| 517 » bfd_elf_generic_reloc, /* */ |
| 518 » "R_MN10300_TLS_LDO",» /* name */ |
| 519 » FALSE,»» » /* partial_inplace */ |
| 520 » 0xffffffff,» » /* src_mask */ |
| 521 » 0xffffffff,» » /* dst_mask */ |
| 522 » FALSE),» » /* pcrel_offset */ |
| 523 |
| 524 HOWTO (R_MN10300_TLS_GOTIE,» /* type */ |
| 525 » 0,» » » /* rightshift */ |
| 526 » 2,» » » /* size (0 = byte, 1 = short, 2 = long) */ |
| 527 » 32,» » » /* bitsize */ |
| 528 » FALSE,»» » /* pc_relative */ |
| 529 » 0,» » » /* bitpos */ |
| 530 » complain_overflow_bitfield, /* complain_on_overflow */ |
| 531 » bfd_elf_generic_reloc, /* */ |
| 532 » "R_MN10300_TLS_GOTIE",»/* name */ |
| 533 » FALSE,»» » /* partial_inplace */ |
| 534 » 0xffffffff,» » /* src_mask */ |
| 535 » 0xffffffff,» » /* dst_mask */ |
| 536 » FALSE),» » /* pcrel_offset */ |
| 537 |
| 538 HOWTO (R_MN10300_TLS_IE,» /* type */ |
| 539 » 0,» » » /* rightshift */ |
| 540 » 2,» » » /* size (0 = byte, 1 = short, 2 = long) */ |
| 541 » 32,» » » /* bitsize */ |
| 542 » FALSE,»» » /* pc_relative */ |
| 543 » 0,» » » /* bitpos */ |
| 544 » complain_overflow_bitfield, /* complain_on_overflow */ |
| 545 » bfd_elf_generic_reloc, /* */ |
| 546 » "R_MN10300_TLS_IE",» /* name */ |
| 547 » FALSE,»» » /* partial_inplace */ |
| 548 » 0xffffffff,» » /* src_mask */ |
| 549 » 0xffffffff,» » /* dst_mask */ |
| 550 » FALSE),» » /* pcrel_offset */ |
| 551 |
| 552 HOWTO (R_MN10300_TLS_LE,» /* type */ |
| 553 » 0,» » » /* rightshift */ |
| 554 » 2,» » » /* size (0 = byte, 1 = short, 2 = long) */ |
| 555 » 32,» » » /* bitsize */ |
| 556 » FALSE,»» » /* pc_relative */ |
| 557 » 0,» » » /* bitpos */ |
| 558 » complain_overflow_bitfield, /* complain_on_overflow */ |
| 559 » bfd_elf_generic_reloc, /* */ |
| 560 » "R_MN10300_TLS_LE",» /* name */ |
| 561 » FALSE,»» » /* partial_inplace */ |
| 562 » 0xffffffff,» » /* src_mask */ |
| 563 » 0xffffffff,» » /* dst_mask */ |
| 564 » FALSE),» » /* pcrel_offset */ |
| 565 |
| 566 HOWTO (R_MN10300_TLS_DTPMOD,» /* type */ |
| 567 » 0,» » » /* rightshift */ |
| 568 » 2,» » » /* size (0 = byte, 1 = short, 2 = long) */ |
| 569 » 32,» » » /* bitsize */ |
| 570 » FALSE,»» » /* pc_relative */ |
| 571 » 0,» » » /* bitpos */ |
| 572 » complain_overflow_bitfield, /* complain_on_overflow */ |
| 573 » bfd_elf_generic_reloc, /* */ |
| 574 » "R_MN10300_TLS_DTPMOD",» /* name */ |
| 575 » FALSE,»» » /* partial_inplace */ |
| 576 » 0xffffffff,» » /* src_mask */ |
| 577 » 0xffffffff,» » /* dst_mask */ |
| 578 » FALSE),» » /* pcrel_offset */ |
| 579 |
| 580 HOWTO (R_MN10300_TLS_DTPOFF,» /* type */ |
| 581 » 0,» » » /* rightshift */ |
| 582 » 2,» » » /* size (0 = byte, 1 = short, 2 = long) */ |
| 583 » 32,» » » /* bitsize */ |
| 584 » FALSE,»» » /* pc_relative */ |
| 585 » 0,» » » /* bitpos */ |
| 586 » complain_overflow_bitfield, /* complain_on_overflow */ |
| 587 » bfd_elf_generic_reloc, /* */ |
| 588 » "R_MN10300_TLS_DTPOFF",» /* name */ |
| 589 » FALSE,»» » /* partial_inplace */ |
| 590 » 0xffffffff,» » /* src_mask */ |
| 591 » 0xffffffff,» » /* dst_mask */ |
| 592 » FALSE),» » /* pcrel_offset */ |
| 593 |
| 594 HOWTO (R_MN10300_TLS_TPOFF,» /* type */ |
| 595 » 0,» » » /* rightshift */ |
| 596 » 2,» » » /* size (0 = byte, 1 = short, 2 = long) */ |
| 597 » 32,» » » /* bitsize */ |
| 598 » FALSE,»» » /* pc_relative */ |
| 599 » 0,» » » /* bitpos */ |
| 600 » complain_overflow_bitfield, /* complain_on_overflow */ |
| 601 » bfd_elf_generic_reloc, /* */ |
| 602 » "R_MN10300_TLS_TPOFF",»/* name */ |
| 603 » FALSE,»» » /* partial_inplace */ |
| 604 » 0xffffffff,» » /* src_mask */ |
| 605 » 0xffffffff,» » /* dst_mask */ |
| 606 » FALSE),» » /* pcrel_offset */ |
460 | 607 |
461 HOWTO (R_MN10300_SYM_DIFF, /* type */ | 608 HOWTO (R_MN10300_SYM_DIFF, /* type */ |
462 0, /* rightshift */ | 609 0, /* rightshift */ |
463 2, /* size (0 = byte, 1 = short, 2 = long) */ | 610 2, /* size (0 = byte, 1 = short, 2 = long) */ |
464 32, /* bitsize */ | 611 32, /* bitsize */ |
465 FALSE, /* pc_relative */ | 612 FALSE, /* pc_relative */ |
466 0, /* bitpos */ | 613 0, /* bitpos */ |
467 complain_overflow_dont,/* complain_on_overflow */ | 614 complain_overflow_dont,/* complain_on_overflow */ |
468 NULL, /* special handler. */ | 615 NULL, /* special handler. */ |
469 "R_MN10300_SYM_DIFF", /* name */ | 616 "R_MN10300_SYM_DIFF", /* name */ |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 { BFD_RELOC_16_GOTOFF, R_MN10300_GOTOFF16 }, | 659 { BFD_RELOC_16_GOTOFF, R_MN10300_GOTOFF16 }, |
513 { BFD_RELOC_32_PLT_PCREL, R_MN10300_PLT32 }, | 660 { BFD_RELOC_32_PLT_PCREL, R_MN10300_PLT32 }, |
514 { BFD_RELOC_16_PLT_PCREL, R_MN10300_PLT16 }, | 661 { BFD_RELOC_16_PLT_PCREL, R_MN10300_PLT16 }, |
515 { BFD_RELOC_MN10300_GOT32, R_MN10300_GOT32 }, | 662 { BFD_RELOC_MN10300_GOT32, R_MN10300_GOT32 }, |
516 { BFD_RELOC_MN10300_GOT24, R_MN10300_GOT24 }, | 663 { BFD_RELOC_MN10300_GOT24, R_MN10300_GOT24 }, |
517 { BFD_RELOC_MN10300_GOT16, R_MN10300_GOT16 }, | 664 { BFD_RELOC_MN10300_GOT16, R_MN10300_GOT16 }, |
518 { BFD_RELOC_MN10300_COPY, R_MN10300_COPY }, | 665 { BFD_RELOC_MN10300_COPY, R_MN10300_COPY }, |
519 { BFD_RELOC_MN10300_GLOB_DAT, R_MN10300_GLOB_DAT }, | 666 { BFD_RELOC_MN10300_GLOB_DAT, R_MN10300_GLOB_DAT }, |
520 { BFD_RELOC_MN10300_JMP_SLOT, R_MN10300_JMP_SLOT }, | 667 { BFD_RELOC_MN10300_JMP_SLOT, R_MN10300_JMP_SLOT }, |
521 { BFD_RELOC_MN10300_RELATIVE, R_MN10300_RELATIVE }, | 668 { BFD_RELOC_MN10300_RELATIVE, R_MN10300_RELATIVE }, |
| 669 { BFD_RELOC_MN10300_TLS_GD, R_MN10300_TLS_GD }, |
| 670 { BFD_RELOC_MN10300_TLS_LD, R_MN10300_TLS_LD }, |
| 671 { BFD_RELOC_MN10300_TLS_LDO, R_MN10300_TLS_LDO }, |
| 672 { BFD_RELOC_MN10300_TLS_GOTIE, R_MN10300_TLS_GOTIE }, |
| 673 { BFD_RELOC_MN10300_TLS_IE, R_MN10300_TLS_IE }, |
| 674 { BFD_RELOC_MN10300_TLS_LE, R_MN10300_TLS_LE }, |
| 675 { BFD_RELOC_MN10300_TLS_DTPMOD, R_MN10300_TLS_DTPMOD }, |
| 676 { BFD_RELOC_MN10300_TLS_DTPOFF, R_MN10300_TLS_DTPOFF }, |
| 677 { BFD_RELOC_MN10300_TLS_TPOFF, R_MN10300_TLS_TPOFF }, |
522 { BFD_RELOC_MN10300_SYM_DIFF, R_MN10300_SYM_DIFF }, | 678 { BFD_RELOC_MN10300_SYM_DIFF, R_MN10300_SYM_DIFF }, |
523 { BFD_RELOC_MN10300_ALIGN, R_MN10300_ALIGN } | 679 { BFD_RELOC_MN10300_ALIGN, R_MN10300_ALIGN } |
524 }; | 680 }; |
525 | 681 |
526 /* Create the GOT section. */ | 682 /* Create the GOT section. */ |
527 | 683 |
528 static bfd_boolean | 684 static bfd_boolean |
529 _bfd_mn10300_elf_create_got_section (bfd * abfd, | 685 _bfd_mn10300_elf_create_got_section (bfd * abfd, |
530 struct bfd_link_info * info) | 686 struct bfd_link_info * info) |
531 { | 687 { |
532 flagword flags; | 688 flagword flags; |
533 flagword pltflags; | 689 flagword pltflags; |
534 asection * s; | 690 asection * s; |
535 struct elf_link_hash_entry * h; | 691 struct elf_link_hash_entry * h; |
536 const struct elf_backend_data * bed = get_elf_backend_data (abfd); | 692 const struct elf_backend_data * bed = get_elf_backend_data (abfd); |
| 693 struct elf_link_hash_table *htab; |
537 int ptralign; | 694 int ptralign; |
538 | 695 |
539 /* This function may be called more than once. */ | 696 /* This function may be called more than once. */ |
540 if (bfd_get_section_by_name (abfd, ".got") != NULL) | 697 htab = elf_hash_table (info); |
| 698 if (htab->sgot != NULL) |
541 return TRUE; | 699 return TRUE; |
542 | 700 |
543 switch (bed->s->arch_size) | 701 switch (bed->s->arch_size) |
544 { | 702 { |
545 case 32: | 703 case 32: |
546 ptralign = 2; | 704 ptralign = 2; |
547 break; | 705 break; |
548 | 706 |
549 case 64: | 707 case 64: |
550 ptralign = 3; | 708 ptralign = 3; |
551 break; | 709 break; |
552 | 710 |
553 default: | 711 default: |
554 bfd_set_error (bfd_error_bad_value); | 712 bfd_set_error (bfd_error_bad_value); |
555 return FALSE; | 713 return FALSE; |
556 } | 714 } |
557 | 715 |
558 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | 716 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
559 | SEC_LINKER_CREATED); | 717 | SEC_LINKER_CREATED); |
560 | 718 |
561 pltflags = flags; | 719 pltflags = flags; |
562 pltflags |= SEC_CODE; | 720 pltflags |= SEC_CODE; |
563 if (bed->plt_not_loaded) | 721 if (bed->plt_not_loaded) |
564 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS); | 722 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS); |
565 if (bed->plt_readonly) | 723 if (bed->plt_readonly) |
566 pltflags |= SEC_READONLY; | 724 pltflags |= SEC_READONLY; |
567 | 725 |
568 s = bfd_make_section_with_flags (abfd, ".plt", pltflags); | 726 s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags); |
| 727 htab->splt = s; |
569 if (s == NULL | 728 if (s == NULL |
570 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) | 729 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) |
571 return FALSE; | 730 return FALSE; |
572 | 731 |
573 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the | 732 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the |
574 .plt section. */ | 733 .plt section. */ |
575 if (bed->want_plt_sym) | 734 if (bed->want_plt_sym) |
576 { | 735 { |
577 h = _bfd_elf_define_linkage_sym (abfd, info, s, | 736 h = _bfd_elf_define_linkage_sym (abfd, info, s, |
578 "_PROCEDURE_LINKAGE_TABLE_"); | 737 "_PROCEDURE_LINKAGE_TABLE_"); |
579 elf_hash_table (info)->hplt = h; | 738 htab->hplt = h; |
580 if (h == NULL) | 739 if (h == NULL) |
581 return FALSE; | 740 return FALSE; |
582 } | 741 } |
583 | 742 |
584 s = bfd_make_section_with_flags (abfd, ".got", flags); | 743 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); |
| 744 htab->sgot = s; |
585 if (s == NULL | 745 if (s == NULL |
586 || ! bfd_set_section_alignment (abfd, s, ptralign)) | 746 || ! bfd_set_section_alignment (abfd, s, ptralign)) |
587 return FALSE; | 747 return FALSE; |
588 | 748 |
589 if (bed->want_got_plt) | 749 if (bed->want_got_plt) |
590 { | 750 { |
591 s = bfd_make_section_with_flags (abfd, ".got.plt", flags); | 751 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags); |
| 752 htab->sgotplt = s; |
592 if (s == NULL | 753 if (s == NULL |
593 || ! bfd_set_section_alignment (abfd, s, ptralign)) | 754 || ! bfd_set_section_alignment (abfd, s, ptralign)) |
594 return FALSE; | 755 return FALSE; |
595 } | 756 } |
596 | 757 |
597 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got | 758 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got |
598 (or .got.plt) section. We don't do this in the linker script | 759 (or .got.plt) section. We don't do this in the linker script |
599 because we don't want to define the symbol if we are not creating | 760 because we don't want to define the symbol if we are not creating |
600 a global offset table. */ | 761 a global offset table. */ |
601 h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_"); | 762 h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_"); |
602 elf_hash_table (info)->hgot = h; | 763 htab->hgot = h; |
603 if (h == NULL) | 764 if (h == NULL) |
604 return FALSE; | 765 return FALSE; |
605 | 766 |
606 /* The first bit of the global offset table is the header. */ | 767 /* The first bit of the global offset table is the header. */ |
607 s->size += bed->got_header_size; | 768 s->size += bed->got_header_size; |
608 | 769 |
609 return TRUE; | 770 return TRUE; |
610 } | 771 } |
611 | 772 |
612 static reloc_howto_type * | 773 static reloc_howto_type * |
(...skipping 30 matching lines...) Expand all Loading... |
643 arelent *cache_ptr, | 804 arelent *cache_ptr, |
644 Elf_Internal_Rela *dst) | 805 Elf_Internal_Rela *dst) |
645 { | 806 { |
646 unsigned int r_type; | 807 unsigned int r_type; |
647 | 808 |
648 r_type = ELF32_R_TYPE (dst->r_info); | 809 r_type = ELF32_R_TYPE (dst->r_info); |
649 BFD_ASSERT (r_type < (unsigned int) R_MN10300_MAX); | 810 BFD_ASSERT (r_type < (unsigned int) R_MN10300_MAX); |
650 cache_ptr->howto = elf_mn10300_howto_table + r_type; | 811 cache_ptr->howto = elf_mn10300_howto_table + r_type; |
651 } | 812 } |
652 | 813 |
| 814 static int |
| 815 elf_mn10300_tls_transition (struct bfd_link_info * info, |
| 816 int r_type, |
| 817 struct elf_link_hash_entry * h, |
| 818 asection * sec, |
| 819 bfd_boolean counting) |
| 820 { |
| 821 bfd_boolean is_local; |
| 822 |
| 823 if (r_type == R_MN10300_TLS_GD |
| 824 && h != NULL |
| 825 && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_IE) |
| 826 return R_MN10300_TLS_GOTIE; |
| 827 |
| 828 if (info->shared) |
| 829 return r_type; |
| 830 |
| 831 if (! (sec->flags & SEC_CODE)) |
| 832 return r_type; |
| 833 |
| 834 if (! counting && h != NULL && ! elf_hash_table (info)->dynamic_sections_creat
ed) |
| 835 is_local = TRUE; |
| 836 else |
| 837 is_local = SYMBOL_CALLS_LOCAL (info, h); |
| 838 |
| 839 /* For the main program, these are the transitions we do. */ |
| 840 switch (r_type) |
| 841 { |
| 842 case R_MN10300_TLS_GD: return is_local ? R_MN10300_TLS_LE : R_MN10300_TLS_GO
TIE; |
| 843 case R_MN10300_TLS_LD: return R_MN10300_NONE; |
| 844 case R_MN10300_TLS_LDO: return R_MN10300_TLS_LE; |
| 845 case R_MN10300_TLS_IE: |
| 846 case R_MN10300_TLS_GOTIE: return is_local ? R_MN10300_TLS_LE : r_type; |
| 847 } |
| 848 |
| 849 return r_type; |
| 850 } |
| 851 |
| 852 /* Return the relocation value for @tpoff relocation |
| 853 if STT_TLS virtual address is ADDRESS. */ |
| 854 |
| 855 static bfd_vma |
| 856 dtpoff (struct bfd_link_info * info, bfd_vma address) |
| 857 { |
| 858 struct elf_link_hash_table *htab = elf_hash_table (info); |
| 859 |
| 860 /* If tls_sec is NULL, we should have signalled an error already. */ |
| 861 if (htab->tls_sec == NULL) |
| 862 return 0; |
| 863 return address - htab->tls_sec->vma; |
| 864 } |
| 865 |
| 866 /* Return the relocation value for @tpoff relocation |
| 867 if STT_TLS virtual address is ADDRESS. */ |
| 868 |
| 869 static bfd_vma |
| 870 tpoff (struct bfd_link_info * info, bfd_vma address) |
| 871 { |
| 872 struct elf_link_hash_table *htab = elf_hash_table (info); |
| 873 |
| 874 /* If tls_sec is NULL, we should have signalled an error already. */ |
| 875 if (htab->tls_sec == NULL) |
| 876 return 0; |
| 877 return address - (htab->tls_size + htab->tls_sec->vma); |
| 878 } |
| 879 |
| 880 /* Returns nonzero if there's a R_MN10300_PLT32 reloc that we now need |
| 881 to skip, after this one. The actual value is the offset between |
| 882 this reloc and the PLT reloc. */ |
| 883 |
| 884 static int |
| 885 mn10300_do_tls_transition (bfd * input_bfd, |
| 886 unsigned int r_type, |
| 887 unsigned int tls_r_type, |
| 888 bfd_byte * contents, |
| 889 bfd_vma offset) |
| 890 { |
| 891 bfd_byte *op = contents + offset; |
| 892 int gotreg = 0; |
| 893 |
| 894 #define TLS_PAIR(r1,r2) ((r1) * R_MN10300_MAX + (r2)) |
| 895 |
| 896 /* This is common to all GD/LD transitions, so break it out. */ |
| 897 if (r_type == R_MN10300_TLS_GD |
| 898 || r_type == R_MN10300_TLS_LD) |
| 899 { |
| 900 op -= 2; |
| 901 /* mov imm,d0. */ |
| 902 BFD_ASSERT (bfd_get_8 (input_bfd, op) == 0xFC); |
| 903 BFD_ASSERT (bfd_get_8 (input_bfd, op + 1) == 0xCC); |
| 904 /* add aN,d0. */ |
| 905 BFD_ASSERT (bfd_get_8 (input_bfd, op + 6) == 0xF1); |
| 906 gotreg = (bfd_get_8 (input_bfd, op + 7) & 0x0c) >> 2; |
| 907 /* Call. */ |
| 908 BFD_ASSERT (bfd_get_8 (input_bfd, op + 8) == 0xDD); |
| 909 } |
| 910 |
| 911 switch (TLS_PAIR (r_type, tls_r_type)) |
| 912 { |
| 913 case TLS_PAIR (R_MN10300_TLS_GD, R_MN10300_TLS_GOTIE): |
| 914 { |
| 915 /* Keep track of which register we put GOTptr in. */ |
| 916 /* mov (_x@indntpoff,a2),a0. */ |
| 917 memcpy (op, "\xFC\x20\x00\x00\x00\x00", 6); |
| 918 op[1] |= gotreg; |
| 919 /* add e2,a0. */ |
| 920 memcpy (op+6, "\xF9\x78\x28", 3); |
| 921 /* or 0x00000000, d0 - six byte nop. */ |
| 922 memcpy (op+9, "\xFC\xE4\x00\x00\x00\x00", 6); |
| 923 } |
| 924 return 7; |
| 925 |
| 926 case TLS_PAIR (R_MN10300_TLS_GD, R_MN10300_TLS_LE): |
| 927 { |
| 928 /* Register is *always* a0. */ |
| 929 /* mov _x@tpoff,a0. */ |
| 930 memcpy (op, "\xFC\xDC\x00\x00\x00\x00", 6); |
| 931 /* add e2,a0. */ |
| 932 memcpy (op+6, "\xF9\x78\x28", 3); |
| 933 /* or 0x00000000, d0 - six byte nop. */ |
| 934 memcpy (op+9, "\xFC\xE4\x00\x00\x00\x00", 6); |
| 935 } |
| 936 return 7; |
| 937 case TLS_PAIR (R_MN10300_TLS_LD, R_MN10300_NONE): |
| 938 { |
| 939 /* Register is *always* a0. */ |
| 940 /* mov e2,a0. */ |
| 941 memcpy (op, "\xF5\x88", 2); |
| 942 /* or 0x00000000, d0 - six byte nop. */ |
| 943 memcpy (op+2, "\xFC\xE4\x00\x00\x00\x00", 6); |
| 944 /* or 0x00000000, e2 - seven byte nop. */ |
| 945 memcpy (op+8, "\xFE\x19\x22\x00\x00\x00\x00", 7); |
| 946 } |
| 947 return 7; |
| 948 |
| 949 case TLS_PAIR (R_MN10300_TLS_LDO, R_MN10300_TLS_LE): |
| 950 /* No changes needed, just the reloc change. */ |
| 951 return 0; |
| 952 |
| 953 /* These are a little tricky, because we have to detect which |
| 954 opcode is being used (they're different sizes, with the reloc |
| 955 at different offsets within the opcode) and convert each |
| 956 accordingly, copying the operands as needed. The conversions |
| 957 we do are as follows (IE,GOTIE,LE): |
| 958 |
| 959 1111 1100 1010 01Dn [-- abs32 --] MOV (x@indntpoff),Dn |
| 960 1111 1100 0000 DnAm [-- abs32 --] MOV (x@gotntpoff,Am),Dn |
| 961 1111 1100 1100 11Dn [-- abs32 --] MOV x@tpoff,Dn |
| 962 |
| 963 1111 1100 1010 00An [-- abs32 --] MOV (x@indntpoff),An |
| 964 1111 1100 0010 AnAm [-- abs32 --] MOV (x@gotntpoff,Am),An |
| 965 1111 1100 1101 11An [-- abs32 --] MOV x@tpoff,An |
| 966 |
| 967 1111 1110 0000 1110 Rnnn Xxxx [-- abs32 --] MOV (x@indntpoff),Rn |
| 968 1111 1110 0000 1010 Rnnn Rmmm [-- abs32 --] MOV (x@indntpoff,Rm),Rn |
| 969 1111 1110 0000 1000 Rnnn Xxxx [-- abs32 --] MOV x@tpoff,Rn |
| 970 |
| 971 Since the GOT pointer is always $a2, we assume the last |
| 972 normally won't happen, but let's be paranoid and plan for the |
| 973 day that GCC optimizes it somewhow. */ |
| 974 |
| 975 case TLS_PAIR (R_MN10300_TLS_IE, R_MN10300_TLS_LE): |
| 976 if (op[-2] == 0xFC) |
| 977 { |
| 978 op -= 2; |
| 979 if ((op[1] & 0xFC) == 0xA4) /* Dn */ |
| 980 { |
| 981 op[1] &= 0x03; /* Leaves Dn. */ |
| 982 op[1] |= 0xCC; |
| 983 } |
| 984 else /* An */ |
| 985 { |
| 986 op[1] &= 0x03; /* Leaves An. */ |
| 987 op[1] |= 0xDC; |
| 988 } |
| 989 } |
| 990 else if (op[-3] == 0xFE) |
| 991 op[-2] = 0x08; |
| 992 else |
| 993 abort (); |
| 994 break; |
| 995 |
| 996 case TLS_PAIR (R_MN10300_TLS_GOTIE, R_MN10300_TLS_LE): |
| 997 if (op[-2] == 0xFC) |
| 998 { |
| 999 op -= 2; |
| 1000 if ((op[1] & 0xF0) == 0x00) /* Dn */ |
| 1001 { |
| 1002 op[1] &= 0x0C; /* Leaves Dn. */ |
| 1003 op[1] >>= 2; |
| 1004 op[1] |= 0xCC; |
| 1005 } |
| 1006 else /* An */ |
| 1007 { |
| 1008 op[1] &= 0x0C; /* Leaves An. */ |
| 1009 op[1] >>= 2; |
| 1010 op[1] |= 0xDC; |
| 1011 } |
| 1012 } |
| 1013 else if (op[-3] == 0xFE) |
| 1014 op[-2] = 0x08; |
| 1015 else |
| 1016 abort (); |
| 1017 break; |
| 1018 |
| 1019 default: |
| 1020 (*_bfd_error_handler) |
| 1021 (_("%s: Unsupported transition from %s to %s"), |
| 1022 bfd_get_filename (input_bfd), |
| 1023 elf_mn10300_howto_table[r_type].name, |
| 1024 elf_mn10300_howto_table[tls_r_type].name); |
| 1025 break; |
| 1026 } |
| 1027 #undef TLS_PAIR |
| 1028 return 0; |
| 1029 } |
| 1030 |
653 /* Look through the relocs for a section during the first phase. | 1031 /* Look through the relocs for a section during the first phase. |
654 Since we don't do .gots or .plts, we just need to consider the | 1032 Since we don't do .gots or .plts, we just need to consider the |
655 virtual table relocs for gc. */ | 1033 virtual table relocs for gc. */ |
656 | 1034 |
657 static bfd_boolean | 1035 static bfd_boolean |
658 mn10300_elf_check_relocs (bfd *abfd, | 1036 mn10300_elf_check_relocs (bfd *abfd, |
659 struct bfd_link_info *info, | 1037 struct bfd_link_info *info, |
660 asection *sec, | 1038 asection *sec, |
661 const Elf_Internal_Rela *relocs) | 1039 const Elf_Internal_Rela *relocs) |
662 { | 1040 { |
| 1041 struct elf32_mn10300_link_hash_table * htab = elf32_mn10300_hash_table (info); |
663 bfd_boolean sym_diff_reloc_seen; | 1042 bfd_boolean sym_diff_reloc_seen; |
664 Elf_Internal_Shdr *symtab_hdr; | 1043 Elf_Internal_Shdr *symtab_hdr; |
665 Elf_Internal_Sym * isymbuf = NULL; | 1044 Elf_Internal_Sym * isymbuf = NULL; |
666 struct elf_link_hash_entry **sym_hashes; | 1045 struct elf_link_hash_entry **sym_hashes; |
667 const Elf_Internal_Rela *rel; | 1046 const Elf_Internal_Rela *rel; |
668 const Elf_Internal_Rela *rel_end; | 1047 const Elf_Internal_Rela *rel_end; |
669 bfd * dynobj; | 1048 bfd * dynobj; |
670 bfd_vma * local_got_offsets; | 1049 bfd_vma * local_got_offsets; |
671 asection * sgot; | 1050 asection * sgot; |
672 asection * srelgot; | 1051 asection * srelgot; |
(...skipping 14 matching lines...) Expand all Loading... |
687 dynobj = elf_hash_table (info)->dynobj; | 1066 dynobj = elf_hash_table (info)->dynobj; |
688 local_got_offsets = elf_local_got_offsets (abfd); | 1067 local_got_offsets = elf_local_got_offsets (abfd); |
689 rel_end = relocs + sec->reloc_count; | 1068 rel_end = relocs + sec->reloc_count; |
690 sym_diff_reloc_seen = FALSE; | 1069 sym_diff_reloc_seen = FALSE; |
691 | 1070 |
692 for (rel = relocs; rel < rel_end; rel++) | 1071 for (rel = relocs; rel < rel_end; rel++) |
693 { | 1072 { |
694 struct elf_link_hash_entry *h; | 1073 struct elf_link_hash_entry *h; |
695 unsigned long r_symndx; | 1074 unsigned long r_symndx; |
696 unsigned int r_type; | 1075 unsigned int r_type; |
| 1076 int tls_type = GOT_NORMAL; |
697 | 1077 |
698 r_symndx = ELF32_R_SYM (rel->r_info); | 1078 r_symndx = ELF32_R_SYM (rel->r_info); |
699 if (r_symndx < symtab_hdr->sh_info) | 1079 if (r_symndx < symtab_hdr->sh_info) |
700 h = NULL; | 1080 h = NULL; |
701 else | 1081 else |
702 { | 1082 { |
703 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | 1083 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
704 while (h->root.type == bfd_link_hash_indirect | 1084 while (h->root.type == bfd_link_hash_indirect |
705 || h->root.type == bfd_link_hash_warning) | 1085 || h->root.type == bfd_link_hash_warning) |
706 h = (struct elf_link_hash_entry *) h->root.u.i.link; | 1086 h = (struct elf_link_hash_entry *) h->root.u.i.link; |
707 } | 1087 } |
708 | 1088 |
709 r_type = ELF32_R_TYPE (rel->r_info); | 1089 r_type = ELF32_R_TYPE (rel->r_info); |
| 1090 r_type = elf_mn10300_tls_transition (info, r_type, h, sec, TRUE); |
710 | 1091 |
711 /* Some relocs require a global offset table. */ | 1092 /* Some relocs require a global offset table. */ |
712 if (dynobj == NULL) | 1093 if (dynobj == NULL) |
713 { | 1094 { |
714 switch (r_type) | 1095 switch (r_type) |
715 { | 1096 { |
716 case R_MN10300_GOT32: | 1097 case R_MN10300_GOT32: |
717 case R_MN10300_GOT24: | 1098 case R_MN10300_GOT24: |
718 case R_MN10300_GOT16: | 1099 case R_MN10300_GOT16: |
719 case R_MN10300_GOTOFF32: | 1100 case R_MN10300_GOTOFF32: |
720 case R_MN10300_GOTOFF24: | 1101 case R_MN10300_GOTOFF24: |
721 case R_MN10300_GOTOFF16: | 1102 case R_MN10300_GOTOFF16: |
722 case R_MN10300_GOTPC32: | 1103 case R_MN10300_GOTPC32: |
723 case R_MN10300_GOTPC16: | 1104 case R_MN10300_GOTPC16: |
| 1105 case R_MN10300_TLS_GD: |
| 1106 case R_MN10300_TLS_LD: |
| 1107 case R_MN10300_TLS_GOTIE: |
| 1108 case R_MN10300_TLS_IE: |
724 elf_hash_table (info)->dynobj = dynobj = abfd; | 1109 elf_hash_table (info)->dynobj = dynobj = abfd; |
725 if (! _bfd_mn10300_elf_create_got_section (dynobj, info)) | 1110 if (! _bfd_mn10300_elf_create_got_section (dynobj, info)) |
726 goto fail; | 1111 goto fail; |
727 break; | 1112 break; |
728 | 1113 |
729 default: | 1114 default: |
730 break; | 1115 break; |
731 } | 1116 } |
732 } | 1117 } |
733 | 1118 |
734 switch (r_type) | 1119 switch (r_type) |
735 { | 1120 { |
736 /* This relocation describes the C++ object vtable hierarchy. | 1121 /* This relocation describes the C++ object vtable hierarchy. |
737 Reconstruct it for later use during GC. */ | 1122 Reconstruct it for later use during GC. */ |
738 case R_MN10300_GNU_VTINHERIT: | 1123 case R_MN10300_GNU_VTINHERIT: |
739 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | 1124 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
740 goto fail; | 1125 goto fail; |
741 break; | 1126 break; |
742 | 1127 |
743 /* This relocation describes which C++ vtable entries are actually | 1128 /* This relocation describes which C++ vtable entries are actually |
744 used. Record for later use during GC. */ | 1129 used. Record for later use during GC. */ |
745 case R_MN10300_GNU_VTENTRY: | 1130 case R_MN10300_GNU_VTENTRY: |
746 BFD_ASSERT (h != NULL); | 1131 BFD_ASSERT (h != NULL); |
747 if (h != NULL | 1132 if (h != NULL |
748 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | 1133 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
749 goto fail; | 1134 goto fail; |
750 break; | 1135 break; |
751 | 1136 |
| 1137 case R_MN10300_TLS_LD: |
| 1138 htab->tls_ldm_got.refcount ++; |
| 1139 tls_type = GOT_TLS_LD; |
| 1140 |
| 1141 if (htab->tls_ldm_got.got_allocated) |
| 1142 break; |
| 1143 goto create_got; |
| 1144 |
| 1145 case R_MN10300_TLS_IE: |
| 1146 case R_MN10300_TLS_GOTIE: |
| 1147 if (info->shared) |
| 1148 info->flags |= DF_STATIC_TLS; |
| 1149 /* Fall through */ |
| 1150 |
| 1151 case R_MN10300_TLS_GD: |
752 case R_MN10300_GOT32: | 1152 case R_MN10300_GOT32: |
753 case R_MN10300_GOT24: | 1153 case R_MN10300_GOT24: |
754 case R_MN10300_GOT16: | 1154 case R_MN10300_GOT16: |
| 1155 create_got: |
755 /* This symbol requires a global offset table entry. */ | 1156 /* This symbol requires a global offset table entry. */ |
756 | 1157 |
| 1158 switch (r_type) |
| 1159 { |
| 1160 case R_MN10300_TLS_IE: |
| 1161 case R_MN10300_TLS_GOTIE: tls_type = GOT_TLS_IE; break; |
| 1162 case R_MN10300_TLS_GD: tls_type = GOT_TLS_GD; break; |
| 1163 default: tls_type = GOT_NORMAL; break; |
| 1164 } |
| 1165 |
757 if (sgot == NULL) | 1166 if (sgot == NULL) |
758 { | 1167 { |
759 » sgot = bfd_get_section_by_name (dynobj, ".got"); | 1168 » sgot = htab->root.sgot; |
760 BFD_ASSERT (sgot != NULL); | 1169 BFD_ASSERT (sgot != NULL); |
761 } | 1170 } |
762 | 1171 |
763 if (srelgot == NULL | 1172 if (srelgot == NULL |
764 && (h != NULL || info->shared)) | 1173 && (h != NULL || info->shared)) |
765 { | 1174 { |
766 » srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | 1175 » srelgot = bfd_get_linker_section (dynobj, ".rela.got"); |
767 if (srelgot == NULL) | 1176 if (srelgot == NULL) |
768 { | 1177 { |
769 » » srelgot = bfd_make_section_with_flags (dynobj, | 1178 » » flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS |
770 » » » » » » » ".rela.got", | 1179 » » » » | SEC_IN_MEMORY | SEC_LINKER_CREATED |
771 » » » » » » » (SEC_ALLOC | 1180 » » » » | SEC_READONLY); |
772 » » » » » » » | SEC_LOAD | 1181 » » srelgot = bfd_make_section_anyway_with_flags (dynobj, |
773 » » » » » » » | SEC_HAS_CONTENTS | 1182 » » » » » » » » ".rela.got", |
774 » » » » » » » | SEC_IN_MEMORY | 1183 » » » » » » » » flags); |
775 » » » » » » » | SEC_LINKER_CREATED | |
776 » » » » » » » | SEC_READONLY)); | |
777 if (srelgot == NULL | 1184 if (srelgot == NULL |
778 || ! bfd_set_section_alignment (dynobj, srelgot, 2)) | 1185 || ! bfd_set_section_alignment (dynobj, srelgot, 2)) |
779 goto fail; | 1186 goto fail; |
780 } | 1187 } |
781 } | 1188 } |
782 | 1189 |
783 » if (h != NULL) | 1190 » if (r_type == R_MN10300_TLS_LD) |
784 { | 1191 { |
| 1192 htab->tls_ldm_got.offset = sgot->size; |
| 1193 htab->tls_ldm_got.got_allocated ++; |
| 1194 } |
| 1195 else if (h != NULL) |
| 1196 { |
| 1197 if (elf_mn10300_hash_entry (h)->tls_type != tls_type |
| 1198 && elf_mn10300_hash_entry (h)->tls_type != GOT_UNKNOWN) |
| 1199 { |
| 1200 if (tls_type == GOT_TLS_IE |
| 1201 && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_GD) |
| 1202 /* No change - this is ok. */; |
| 1203 else if (tls_type == GOT_TLS_GD |
| 1204 && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_IE) |
| 1205 /* Transition GD->IE. */ |
| 1206 tls_type = GOT_TLS_IE; |
| 1207 else |
| 1208 (*_bfd_error_handler) |
| 1209 (_("%B: %s' accessed both as normal and thread local symbo
l"), |
| 1210 abfd, h ? h->root.root.string : "<local>"); |
| 1211 } |
| 1212 |
| 1213 elf_mn10300_hash_entry (h)->tls_type = tls_type; |
| 1214 |
785 if (h->got.offset != (bfd_vma) -1) | 1215 if (h->got.offset != (bfd_vma) -1) |
786 /* We have already allocated space in the .got. */ | 1216 /* We have already allocated space in the .got. */ |
787 break; | 1217 break; |
788 | 1218 |
789 h->got.offset = sgot->size; | 1219 h->got.offset = sgot->size; |
790 | 1220 |
791 » /* Make sure this symbol is output as a dynamic symbol. */ | 1221 » if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL |
792 » if (h->dynindx == -1) | 1222 » » /* Make sure this symbol is output as a dynamic symbol. */ |
| 1223 » » && h->dynindx == -1) |
793 { | 1224 { |
794 if (! bfd_elf_link_record_dynamic_symbol (info, h)) | 1225 if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
795 goto fail; | 1226 goto fail; |
796 } | 1227 } |
797 | 1228 |
798 srelgot->size += sizeof (Elf32_External_Rela); | 1229 srelgot->size += sizeof (Elf32_External_Rela); |
| 1230 if (r_type == R_MN10300_TLS_GD) |
| 1231 srelgot->size += sizeof (Elf32_External_Rela); |
799 } | 1232 } |
800 else | 1233 else |
801 { | 1234 { |
802 /* This is a global offset table entry for a local | 1235 /* This is a global offset table entry for a local |
803 symbol. */ | 1236 symbol. */ |
804 if (local_got_offsets == NULL) | 1237 if (local_got_offsets == NULL) |
805 { | 1238 { |
806 size_t size; | 1239 size_t size; |
807 unsigned int i; | 1240 unsigned int i; |
808 | 1241 |
809 » » size = symtab_hdr->sh_info * sizeof (bfd_vma); | 1242 » » size = symtab_hdr->sh_info * (sizeof (bfd_vma) + sizeof (char)
); |
810 local_got_offsets = bfd_alloc (abfd, size); | 1243 local_got_offsets = bfd_alloc (abfd, size); |
811 | 1244 |
812 if (local_got_offsets == NULL) | 1245 if (local_got_offsets == NULL) |
813 goto fail; | 1246 goto fail; |
814 | 1247 |
815 elf_local_got_offsets (abfd) = local_got_offsets; | 1248 elf_local_got_offsets (abfd) = local_got_offsets; |
| 1249 elf_mn10300_local_got_tls_type (abfd) |
| 1250 = (char *) (local_got_offsets + symtab_hdr->sh_info); |
816 | 1251 |
817 for (i = 0; i < symtab_hdr->sh_info; i++) | 1252 for (i = 0; i < symtab_hdr->sh_info; i++) |
818 local_got_offsets[i] = (bfd_vma) -1; | 1253 local_got_offsets[i] = (bfd_vma) -1; |
819 } | 1254 } |
820 | 1255 |
821 if (local_got_offsets[r_symndx] != (bfd_vma) -1) | 1256 if (local_got_offsets[r_symndx] != (bfd_vma) -1) |
822 /* We have already allocated space in the .got. */ | 1257 /* We have already allocated space in the .got. */ |
823 break; | 1258 break; |
824 | 1259 |
825 local_got_offsets[r_symndx] = sgot->size; | 1260 local_got_offsets[r_symndx] = sgot->size; |
826 | 1261 |
827 if (info->shared) | 1262 if (info->shared) |
828 » » /* If we are generating a shared object, we need to | 1263 » » { |
829 » » output a R_MN10300_RELATIVE reloc so that the dynamic | 1264 » » /* If we are generating a shared object, we need to |
830 » » linker can adjust this GOT entry. */ | 1265 » » output a R_MN10300_RELATIVE reloc so that the dynamic |
831 » » srelgot->size += sizeof (Elf32_External_Rela); | 1266 » » linker can adjust this GOT entry. */ |
| 1267 » » srelgot->size += sizeof (Elf32_External_Rela); |
| 1268 |
| 1269 » » if (r_type == R_MN10300_TLS_GD) |
| 1270 » » /* And a R_MN10300_TLS_DTPOFF reloc as well. */ |
| 1271 » » srelgot->size += sizeof (Elf32_External_Rela); |
| 1272 » » } |
| 1273 |
| 1274 » elf_mn10300_local_got_tls_type (abfd) [r_symndx] = tls_type; |
832 } | 1275 } |
833 | 1276 |
834 sgot->size += 4; | 1277 sgot->size += 4; |
835 » break; | 1278 » if (r_type == R_MN10300_TLS_GD |
| 1279 » || r_type == R_MN10300_TLS_LD) |
| 1280 » sgot->size += 4; |
| 1281 |
| 1282 » goto need_shared_relocs; |
836 | 1283 |
837 case R_MN10300_PLT32: | 1284 case R_MN10300_PLT32: |
838 case R_MN10300_PLT16: | 1285 case R_MN10300_PLT16: |
839 /* This symbol requires a procedure linkage table entry. We | 1286 /* This symbol requires a procedure linkage table entry. We |
840 actually build the entry in adjust_dynamic_symbol, | 1287 actually build the entry in adjust_dynamic_symbol, |
841 because this might be a case of linking PIC code which is | 1288 because this might be a case of linking PIC code which is |
842 never referenced by a dynamic object, in which case we | 1289 never referenced by a dynamic object, in which case we |
843 don't need to generate a procedure linkage table entry | 1290 don't need to generate a procedure linkage table entry |
844 after all. */ | 1291 after all. */ |
845 | 1292 |
(...skipping 20 matching lines...) Expand all Loading... |
866 break; | 1313 break; |
867 | 1314 |
868 case R_MN10300_SYM_DIFF: | 1315 case R_MN10300_SYM_DIFF: |
869 sym_diff_reloc_seen = TRUE; | 1316 sym_diff_reloc_seen = TRUE; |
870 break; | 1317 break; |
871 | 1318 |
872 case R_MN10300_32: | 1319 case R_MN10300_32: |
873 if (h != NULL) | 1320 if (h != NULL) |
874 h->non_got_ref = 1; | 1321 h->non_got_ref = 1; |
875 | 1322 |
| 1323 need_shared_relocs: |
876 /* If we are creating a shared library, then we | 1324 /* If we are creating a shared library, then we |
877 need to copy the reloc into the shared library. */ | 1325 need to copy the reloc into the shared library. */ |
878 if (info->shared | 1326 if (info->shared |
879 && (sec->flags & SEC_ALLOC) != 0 | 1327 && (sec->flags & SEC_ALLOC) != 0 |
880 /* Do not generate a dynamic reloc for a | 1328 /* Do not generate a dynamic reloc for a |
881 reloc associated with a SYM_DIFF operation. */ | 1329 reloc associated with a SYM_DIFF operation. */ |
882 && ! sym_diff_reloc_seen) | 1330 && ! sym_diff_reloc_seen) |
883 { | 1331 { |
884 asection * sym_section = NULL; | 1332 asection * sym_section = NULL; |
885 | 1333 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 bfd_byte *contents, | 1422 bfd_byte *contents, |
975 bfd_vma offset, | 1423 bfd_vma offset, |
976 bfd_vma value, | 1424 bfd_vma value, |
977 bfd_vma addend, | 1425 bfd_vma addend, |
978 struct elf_link_hash_entry * h, | 1426 struct elf_link_hash_entry * h, |
979 unsigned long symndx, | 1427 unsigned long symndx, |
980 struct bfd_link_info *info, | 1428 struct bfd_link_info *info, |
981 asection *sym_sec ATTRIBUTE_UNUSED, | 1429 asection *sym_sec ATTRIBUTE_UNUSED, |
982 int is_local ATTRIBUTE_UNUSED) | 1430 int is_local ATTRIBUTE_UNUSED) |
983 { | 1431 { |
| 1432 struct elf32_mn10300_link_hash_table * htab = elf32_mn10300_hash_table (info); |
984 static asection * sym_diff_section; | 1433 static asection * sym_diff_section; |
985 static bfd_vma sym_diff_value; | 1434 static bfd_vma sym_diff_value; |
986 bfd_boolean is_sym_diff_reloc; | 1435 bfd_boolean is_sym_diff_reloc; |
987 unsigned long r_type = howto->type; | 1436 unsigned long r_type = howto->type; |
988 bfd_byte * hit_data = contents + offset; | 1437 bfd_byte * hit_data = contents + offset; |
989 bfd * dynobj; | 1438 bfd * dynobj; |
990 asection * sgot; | 1439 asection * sgot; |
991 asection * splt; | 1440 asection * splt; |
992 asection * sreloc; | 1441 asection * sreloc; |
993 | 1442 |
(...skipping 11 matching lines...) Expand all Loading... |
1005 case R_MN10300_PCREL16: | 1454 case R_MN10300_PCREL16: |
1006 case R_MN10300_PCREL32: | 1455 case R_MN10300_PCREL32: |
1007 case R_MN10300_GOTOFF32: | 1456 case R_MN10300_GOTOFF32: |
1008 case R_MN10300_GOTOFF24: | 1457 case R_MN10300_GOTOFF24: |
1009 case R_MN10300_GOTOFF16: | 1458 case R_MN10300_GOTOFF16: |
1010 if (info->shared | 1459 if (info->shared |
1011 && (input_section->flags & SEC_ALLOC) != 0 | 1460 && (input_section->flags & SEC_ALLOC) != 0 |
1012 && h != NULL | 1461 && h != NULL |
1013 && ! SYMBOL_REFERENCES_LOCAL (info, h)) | 1462 && ! SYMBOL_REFERENCES_LOCAL (info, h)) |
1014 return bfd_reloc_dangerous; | 1463 return bfd_reloc_dangerous; |
| 1464 case R_MN10300_GOT32: |
| 1465 /* Issue 2052223: |
| 1466 Taking the address of a protected function in a shared library |
| 1467 is illegal. Issue an error message here. */ |
| 1468 if (info->shared |
| 1469 && (input_section->flags & SEC_ALLOC) != 0 |
| 1470 && h != NULL |
| 1471 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED |
| 1472 && (h->type == STT_FUNC || h->type == STT_GNU_IFUNC) |
| 1473 && ! SYMBOL_REFERENCES_LOCAL (info, h)) |
| 1474 return bfd_reloc_dangerous; |
1015 } | 1475 } |
1016 | 1476 |
1017 is_sym_diff_reloc = FALSE; | 1477 is_sym_diff_reloc = FALSE; |
1018 if (sym_diff_section != NULL) | 1478 if (sym_diff_section != NULL) |
1019 { | 1479 { |
1020 BFD_ASSERT (sym_diff_section == input_section); | 1480 BFD_ASSERT (sym_diff_section == input_section); |
1021 | 1481 |
1022 switch (r_type) | 1482 switch (r_type) |
1023 { | 1483 { |
1024 case R_MN10300_32: | 1484 case R_MN10300_32: |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 value += addend; | 1661 value += addend; |
1202 | 1662 |
1203 bfd_put_32 (input_bfd, value, hit_data); | 1663 bfd_put_32 (input_bfd, value, hit_data); |
1204 return bfd_reloc_ok; | 1664 return bfd_reloc_ok; |
1205 | 1665 |
1206 case R_MN10300_GNU_VTINHERIT: | 1666 case R_MN10300_GNU_VTINHERIT: |
1207 case R_MN10300_GNU_VTENTRY: | 1667 case R_MN10300_GNU_VTENTRY: |
1208 return bfd_reloc_ok; | 1668 return bfd_reloc_ok; |
1209 | 1669 |
1210 case R_MN10300_GOTPC32: | 1670 case R_MN10300_GOTPC32: |
| 1671 if (dynobj == NULL) |
| 1672 return bfd_reloc_dangerous; |
| 1673 |
1211 /* Use global offset table as symbol value. */ | 1674 /* Use global offset table as symbol value. */ |
1212 value = bfd_get_section_by_name (dynobj, | 1675 value = htab->root.sgot->output_section->vma; |
1213 » » » » ".got")->output_section->vma; | |
1214 value -= (input_section->output_section->vma | 1676 value -= (input_section->output_section->vma |
1215 + input_section->output_offset); | 1677 + input_section->output_offset); |
1216 value -= offset; | 1678 value -= offset; |
1217 value += addend; | 1679 value += addend; |
1218 | 1680 |
1219 bfd_put_32 (input_bfd, value, hit_data); | 1681 bfd_put_32 (input_bfd, value, hit_data); |
1220 return bfd_reloc_ok; | 1682 return bfd_reloc_ok; |
1221 | 1683 |
1222 case R_MN10300_GOTPC16: | 1684 case R_MN10300_GOTPC16: |
| 1685 if (dynobj == NULL) |
| 1686 return bfd_reloc_dangerous; |
| 1687 |
1223 /* Use global offset table as symbol value. */ | 1688 /* Use global offset table as symbol value. */ |
1224 value = bfd_get_section_by_name (dynobj, | 1689 value = htab->root.sgot->output_section->vma; |
1225 » » » » ".got")->output_section->vma; | |
1226 value -= (input_section->output_section->vma | 1690 value -= (input_section->output_section->vma |
1227 + input_section->output_offset); | 1691 + input_section->output_offset); |
1228 value -= offset; | 1692 value -= offset; |
1229 value += addend; | 1693 value += addend; |
1230 | 1694 |
1231 if ((long) value > 0x7fff || (long) value < -0x8000) | 1695 if ((long) value > 0x7fff || (long) value < -0x8000) |
1232 return bfd_reloc_overflow; | 1696 return bfd_reloc_overflow; |
1233 | 1697 |
1234 bfd_put_16 (input_bfd, value, hit_data); | 1698 bfd_put_16 (input_bfd, value, hit_data); |
1235 return bfd_reloc_ok; | 1699 return bfd_reloc_ok; |
1236 | 1700 |
1237 case R_MN10300_GOTOFF32: | 1701 case R_MN10300_GOTOFF32: |
1238 value -= bfd_get_section_by_name (dynobj, | 1702 if (dynobj == NULL) |
1239 » » » » » ".got")->output_section->vma; | 1703 » return bfd_reloc_dangerous; |
| 1704 |
| 1705 value -= htab->root.sgot->output_section->vma; |
1240 value += addend; | 1706 value += addend; |
1241 | 1707 |
1242 bfd_put_32 (input_bfd, value, hit_data); | 1708 bfd_put_32 (input_bfd, value, hit_data); |
1243 return bfd_reloc_ok; | 1709 return bfd_reloc_ok; |
1244 | 1710 |
1245 case R_MN10300_GOTOFF24: | 1711 case R_MN10300_GOTOFF24: |
1246 value -= bfd_get_section_by_name (dynobj, | 1712 if (dynobj == NULL) |
1247 » » » » » ".got")->output_section->vma; | 1713 » return bfd_reloc_dangerous; |
| 1714 |
| 1715 value -= htab->root.sgot->output_section->vma; |
1248 value += addend; | 1716 value += addend; |
1249 | 1717 |
1250 if ((long) value > 0x7fffff || (long) value < -0x800000) | 1718 if ((long) value > 0x7fffff || (long) value < -0x800000) |
1251 return bfd_reloc_overflow; | 1719 return bfd_reloc_overflow; |
1252 | 1720 |
1253 bfd_put_8 (input_bfd, value, hit_data); | 1721 bfd_put_8 (input_bfd, value, hit_data); |
1254 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1); | 1722 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1); |
1255 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2); | 1723 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2); |
1256 return bfd_reloc_ok; | 1724 return bfd_reloc_ok; |
1257 | 1725 |
1258 case R_MN10300_GOTOFF16: | 1726 case R_MN10300_GOTOFF16: |
1259 value -= bfd_get_section_by_name (dynobj, | 1727 if (dynobj == NULL) |
1260 » » » » » ".got")->output_section->vma; | 1728 » return bfd_reloc_dangerous; |
| 1729 |
| 1730 value -= htab->root.sgot->output_section->vma; |
1261 value += addend; | 1731 value += addend; |
1262 | 1732 |
1263 if ((long) value > 0x7fff || (long) value < -0x8000) | 1733 if ((long) value > 0x7fff || (long) value < -0x8000) |
1264 return bfd_reloc_overflow; | 1734 return bfd_reloc_overflow; |
1265 | 1735 |
1266 bfd_put_16 (input_bfd, value, hit_data); | 1736 bfd_put_16 (input_bfd, value, hit_data); |
1267 return bfd_reloc_ok; | 1737 return bfd_reloc_ok; |
1268 | 1738 |
1269 case R_MN10300_PLT32: | 1739 case R_MN10300_PLT32: |
1270 if (h != NULL | 1740 if (h != NULL |
1271 && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL | 1741 && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL |
1272 && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN | 1742 && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN |
1273 && h->plt.offset != (bfd_vma) -1) | 1743 && h->plt.offset != (bfd_vma) -1) |
1274 { | 1744 { |
1275 » splt = bfd_get_section_by_name (dynobj, ".plt"); | 1745 » if (dynobj == NULL) |
| 1746 » return bfd_reloc_dangerous; |
1276 | 1747 |
| 1748 splt = htab->root.splt; |
1277 value = (splt->output_section->vma | 1749 value = (splt->output_section->vma |
1278 + splt->output_offset | 1750 + splt->output_offset |
1279 + h->plt.offset) - value; | 1751 + h->plt.offset) - value; |
1280 } | 1752 } |
1281 | 1753 |
1282 value -= (input_section->output_section->vma | 1754 value -= (input_section->output_section->vma |
1283 + input_section->output_offset); | 1755 + input_section->output_offset); |
1284 value -= offset; | 1756 value -= offset; |
1285 value += addend; | 1757 value += addend; |
1286 | 1758 |
1287 bfd_put_32 (input_bfd, value, hit_data); | 1759 bfd_put_32 (input_bfd, value, hit_data); |
1288 return bfd_reloc_ok; | 1760 return bfd_reloc_ok; |
1289 | 1761 |
1290 case R_MN10300_PLT16: | 1762 case R_MN10300_PLT16: |
1291 if (h != NULL | 1763 if (h != NULL |
1292 && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL | 1764 && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL |
1293 && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN | 1765 && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN |
1294 && h->plt.offset != (bfd_vma) -1) | 1766 && h->plt.offset != (bfd_vma) -1) |
1295 { | 1767 { |
1296 » splt = bfd_get_section_by_name (dynobj, ".plt"); | 1768 » if (dynobj == NULL) |
| 1769 » return bfd_reloc_dangerous; |
1297 | 1770 |
| 1771 splt = htab->root.splt; |
1298 value = (splt->output_section->vma | 1772 value = (splt->output_section->vma |
1299 + splt->output_offset | 1773 + splt->output_offset |
1300 + h->plt.offset) - value; | 1774 + h->plt.offset) - value; |
1301 } | 1775 } |
1302 | 1776 |
1303 value -= (input_section->output_section->vma | 1777 value -= (input_section->output_section->vma |
1304 + input_section->output_offset); | 1778 + input_section->output_offset); |
1305 value -= offset; | 1779 value -= offset; |
1306 value += addend; | 1780 value += addend; |
1307 | 1781 |
1308 if ((long) value > 0x7fff || (long) value < -0x8000) | 1782 if ((long) value > 0x7fff || (long) value < -0x8000) |
1309 return bfd_reloc_overflow; | 1783 return bfd_reloc_overflow; |
1310 | 1784 |
1311 bfd_put_16 (input_bfd, value, hit_data); | 1785 bfd_put_16 (input_bfd, value, hit_data); |
1312 return bfd_reloc_ok; | 1786 return bfd_reloc_ok; |
1313 | 1787 |
| 1788 case R_MN10300_TLS_LDO: |
| 1789 value = dtpoff (info, value); |
| 1790 bfd_put_32 (input_bfd, value + addend, hit_data); |
| 1791 return bfd_reloc_ok; |
| 1792 |
| 1793 case R_MN10300_TLS_LE: |
| 1794 value = tpoff (info, value); |
| 1795 bfd_put_32 (input_bfd, value + addend, hit_data); |
| 1796 return bfd_reloc_ok; |
| 1797 |
| 1798 case R_MN10300_TLS_LD: |
| 1799 if (dynobj == NULL) |
| 1800 return bfd_reloc_dangerous; |
| 1801 |
| 1802 sgot = htab->root.sgot; |
| 1803 BFD_ASSERT (sgot != NULL); |
| 1804 value = htab->tls_ldm_got.offset + sgot->output_offset; |
| 1805 bfd_put_32 (input_bfd, value, hit_data); |
| 1806 |
| 1807 if (!htab->tls_ldm_got.rel_emitted) |
| 1808 { |
| 1809 asection * srelgot = bfd_get_linker_section (dynobj, ".rela.got"); |
| 1810 Elf_Internal_Rela rel; |
| 1811 |
| 1812 BFD_ASSERT (srelgot != NULL); |
| 1813 htab->tls_ldm_got.rel_emitted ++; |
| 1814 rel.r_offset = (sgot->output_section->vma |
| 1815 + sgot->output_offset |
| 1816 + htab->tls_ldm_got.offset); |
| 1817 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + htab->tls_ldm_go
t.offset); |
| 1818 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + htab->tls_ldm_go
t.offset+4); |
| 1819 rel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPMOD); |
| 1820 rel.r_addend = 0; |
| 1821 bfd_elf32_swap_reloca_out (output_bfd, & rel, |
| 1822 (bfd_byte *) ((Elf32_External_Rela *) srelg
ot->contents |
| 1823 + srelgot->reloc_count)); |
| 1824 ++ srelgot->reloc_count; |
| 1825 } |
| 1826 |
| 1827 return bfd_reloc_ok; |
| 1828 |
| 1829 case R_MN10300_TLS_GOTIE: |
| 1830 value = tpoff (info, value); |
| 1831 /* Fall Through. */ |
| 1832 |
| 1833 case R_MN10300_TLS_GD: |
| 1834 case R_MN10300_TLS_IE: |
1314 case R_MN10300_GOT32: | 1835 case R_MN10300_GOT32: |
1315 case R_MN10300_GOT24: | 1836 case R_MN10300_GOT24: |
1316 case R_MN10300_GOT16: | 1837 case R_MN10300_GOT16: |
1317 { | 1838 if (dynobj == NULL) |
1318 » sgot = bfd_get_section_by_name (dynobj, ".got"); | 1839 » return bfd_reloc_dangerous; |
1319 | 1840 |
1320 » if (h != NULL) | 1841 sgot = htab->root.sgot; |
1321 » { | 1842 if (r_type == R_MN10300_TLS_GD) |
1322 » bfd_vma off; | 1843 » value = dtpoff (info, value); |
1323 | 1844 |
1324 » off = h->got.offset; | 1845 if (h != NULL) |
1325 » BFD_ASSERT (off != (bfd_vma) -1); | 1846 » { |
| 1847 » bfd_vma off; |
1326 | 1848 |
1327 » if (! elf_hash_table (info)->dynamic_sections_created | 1849 » off = h->got.offset; |
1328 » » || SYMBOL_REFERENCES_LOCAL (info, h)) | 1850 » /* Offsets in the GOT are allocated in check_relocs |
1329 » » /* This is actually a static link, or it is a | 1851 » which is not called for shared libraries... */ |
1330 » » -Bsymbolic link and the symbol is defined | 1852 » if (off == (bfd_vma) -1) |
1331 » » locally, or the symbol was forced to be local | 1853 » off = 0; |
1332 » » because of a version file. We must initialize | |
1333 » » this entry in the global offset table. | |
1334 | 1854 |
1335 » » When doing a dynamic link, we create a .rela.got | 1855 » if (sgot->contents != NULL |
1336 » » relocation entry to initialize the value. This | 1856 » && (! elf_hash_table (info)->dynamic_sections_created |
1337 » » is done in the finish_dynamic_symbol routine. */ | 1857 » » || SYMBOL_REFERENCES_LOCAL (info, h))) |
1338 » » bfd_put_32 (output_bfd, value, | 1858 » /* This is actually a static link, or it is a |
1339 » » » sgot->contents + off); | 1859 » -Bsymbolic link and the symbol is defined |
| 1860 » locally, or the symbol was forced to be local |
| 1861 » because of a version file. We must initialize |
| 1862 » this entry in the global offset table. |
1340 | 1863 |
1341 » value = sgot->output_offset + off; | 1864 » When doing a dynamic link, we create a .rela.got |
1342 » } | 1865 » relocation entry to initialize the value. This |
| 1866 » is done in the finish_dynamic_symbol routine. */ |
| 1867 » bfd_put_32 (output_bfd, value, |
| 1868 » » » sgot->contents + off); |
| 1869 |
| 1870 » value = sgot->output_offset + off; |
| 1871 » } |
| 1872 else |
| 1873 » { |
| 1874 » bfd_vma off; |
| 1875 |
| 1876 » off = elf_local_got_offsets (input_bfd)[symndx]; |
| 1877 |
| 1878 » if (off & 1) |
| 1879 » bfd_put_32 (output_bfd, value, sgot->contents + (off & ~ 1)); |
1343 else | 1880 else |
1344 { | 1881 { |
1345 bfd_vma off; | |
1346 | |
1347 off = elf_local_got_offsets (input_bfd)[symndx]; | |
1348 | |
1349 bfd_put_32 (output_bfd, value, sgot->contents + off); | 1882 bfd_put_32 (output_bfd, value, sgot->contents + off); |
1350 | 1883 |
1351 if (info->shared) | 1884 if (info->shared) |
1352 { | 1885 { |
1353 asection * srelgot; | 1886 asection * srelgot; |
1354 Elf_Internal_Rela outrel; | 1887 Elf_Internal_Rela outrel; |
1355 | 1888 |
1356 » » srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | 1889 » » srelgot = bfd_get_linker_section (dynobj, ".rela.got"); |
1357 BFD_ASSERT (srelgot != NULL); | 1890 BFD_ASSERT (srelgot != NULL); |
1358 | 1891 |
1359 outrel.r_offset = (sgot->output_section->vma | 1892 outrel.r_offset = (sgot->output_section->vma |
1360 + sgot->output_offset | 1893 + sgot->output_offset |
1361 + off); | 1894 + off); |
1362 » » outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE); | 1895 » » switch (r_type) |
| 1896 » » { |
| 1897 » » case R_MN10300_TLS_GD: |
| 1898 » » outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPOFF); |
| 1899 » » outrel.r_offset = (sgot->output_section->vma |
| 1900 » » » » » + sgot->output_offset |
| 1901 » » » » » + off + 4); |
| 1902 » » bfd_elf32_swap_reloca_out (output_bfd, & outrel, |
| 1903 » » » » » » (bfd_byte *) (((Elf32_External_
Rela *) |
| 1904 » » » » » » » » srelgot->content
s) |
| 1905 » » » » » » » + srelgot->reloc_
count)); |
| 1906 » » ++ srelgot->reloc_count; |
| 1907 » » outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_DTPMOD); |
| 1908 » » break; |
| 1909 » » case R_MN10300_TLS_GOTIE: |
| 1910 » » case R_MN10300_TLS_IE: |
| 1911 » » outrel.r_info = ELF32_R_INFO (0, R_MN10300_TLS_TPOFF); |
| 1912 » » break; |
| 1913 » » default: |
| 1914 » » outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE); |
| 1915 » » break; |
| 1916 » » } |
| 1917 |
1363 outrel.r_addend = value; | 1918 outrel.r_addend = value; |
1364 bfd_elf32_swap_reloca_out (output_bfd, &outrel, | 1919 bfd_elf32_swap_reloca_out (output_bfd, &outrel, |
1365 (bfd_byte *) (((Elf32_External_Rela
*) | 1920 (bfd_byte *) (((Elf32_External_Rela
*) |
1366 srelgot->contents) | 1921 srelgot->contents) |
1367 + srelgot->reloc_coun
t)); | 1922 + srelgot->reloc_coun
t)); |
1368 ++ srelgot->reloc_count; | 1923 ++ srelgot->reloc_count; |
| 1924 elf_local_got_offsets (input_bfd)[symndx] |= 1; |
1369 } | 1925 } |
1370 | 1926 |
1371 » value = sgot->output_offset + off; | 1927 » value = sgot->output_offset + (off & ~(bfd_vma) 1); |
1372 } | 1928 } |
1373 } | 1929 » } |
1374 | 1930 |
1375 value += addend; | 1931 value += addend; |
1376 | 1932 |
1377 if (r_type == R_MN10300_GOT32) | 1933 if (r_type == R_MN10300_TLS_IE) |
| 1934 » { |
| 1935 » value += sgot->output_section->vma; |
| 1936 » bfd_put_32 (input_bfd, value, hit_data); |
| 1937 » return bfd_reloc_ok; |
| 1938 » } |
| 1939 else if (r_type == R_MN10300_TLS_GOTIE |
| 1940 » || r_type == R_MN10300_TLS_GD |
| 1941 » || r_type == R_MN10300_TLS_LD) |
1378 { | 1942 { |
1379 bfd_put_32 (input_bfd, value, hit_data); | 1943 bfd_put_32 (input_bfd, value, hit_data); |
1380 return bfd_reloc_ok; | 1944 return bfd_reloc_ok; |
| 1945 } |
| 1946 else if (r_type == R_MN10300_GOT32) |
| 1947 { |
| 1948 bfd_put_32 (input_bfd, value, hit_data); |
| 1949 return bfd_reloc_ok; |
1381 } | 1950 } |
1382 else if (r_type == R_MN10300_GOT24) | 1951 else if (r_type == R_MN10300_GOT24) |
1383 { | 1952 { |
1384 if ((long) value > 0x7fffff || (long) value < -0x800000) | 1953 if ((long) value > 0x7fffff || (long) value < -0x800000) |
1385 return bfd_reloc_overflow; | 1954 return bfd_reloc_overflow; |
1386 | 1955 |
1387 bfd_put_8 (input_bfd, value & 0xff, hit_data); | 1956 bfd_put_8 (input_bfd, value & 0xff, hit_data); |
1388 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1); | 1957 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1); |
1389 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2); | 1958 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2); |
1390 return bfd_reloc_ok; | 1959 return bfd_reloc_ok; |
(...skipping 18 matching lines...) Expand all Loading... |
1409 | 1978 |
1410 static bfd_boolean | 1979 static bfd_boolean |
1411 mn10300_elf_relocate_section (bfd *output_bfd, | 1980 mn10300_elf_relocate_section (bfd *output_bfd, |
1412 struct bfd_link_info *info, | 1981 struct bfd_link_info *info, |
1413 bfd *input_bfd, | 1982 bfd *input_bfd, |
1414 asection *input_section, | 1983 asection *input_section, |
1415 bfd_byte *contents, | 1984 bfd_byte *contents, |
1416 Elf_Internal_Rela *relocs, | 1985 Elf_Internal_Rela *relocs, |
1417 Elf_Internal_Sym *local_syms, | 1986 Elf_Internal_Sym *local_syms, |
1418 asection **local_sections) | 1987 asection **local_sections) |
error: old chunk mismatch |
None
OLD | NEW |