Deleted Added
full compact
elfxx-sparc.c (214157) elfxx-sparc.c (214634)
1/* SPARC-specific support for ELF
1/* SPARC-specific support for ELF
2 Copyright 2005, 2006 Free Software Foundation, Inc.
2 Copyright 2005, 2006, 2007 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 2 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, MA 02110-1301, USA. */
19
20/* This file handles functionality common to the different SPARC ABI's. */
21
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 2 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, MA 02110-1301, USA. */
19
20/* This file handles functionality common to the different SPARC ABI's. */
21
22#include "bfd.h"
23#include "sysdep.h"
22#include "sysdep.h"
23#include "bfd.h"
24#include "bfdlink.h"
25#include "libbfd.h"
26#include "libiberty.h"
27#include "elf-bfd.h"
28#include "elf/sparc.h"
29#include "opcode/sparc.h"
30#include "elfxx-sparc.h"
31#include "elf-vxworks.h"

--- 348 unchanged lines hidden (view full) ---

380 + (int) sparc_reloc_map[i].elf_reloc_val);
381 }
382 }
383 bfd_set_error (bfd_error_bad_value);
384 return NULL;
385}
386
387reloc_howto_type *
24#include "bfdlink.h"
25#include "libbfd.h"
26#include "libiberty.h"
27#include "elf-bfd.h"
28#include "elf/sparc.h"
29#include "opcode/sparc.h"
30#include "elfxx-sparc.h"
31#include "elf-vxworks.h"

--- 348 unchanged lines hidden (view full) ---

380 + (int) sparc_reloc_map[i].elf_reloc_val);
381 }
382 }
383 bfd_set_error (bfd_error_bad_value);
384 return NULL;
385}
386
387reloc_howto_type *
388_bfd_sparc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
389 const char *r_name)
390{
391 unsigned int i;
392
393 for (i = 0;
394 i < (sizeof (_bfd_sparc_elf_howto_table)
395 / sizeof (_bfd_sparc_elf_howto_table[0]));
396 i++)
397 if (_bfd_sparc_elf_howto_table[i].name != NULL
398 && strcasecmp (_bfd_sparc_elf_howto_table[i].name, r_name) == 0)
399 return &_bfd_sparc_elf_howto_table[i];
400
401 if (strcasecmp (sparc_vtinherit_howto.name, r_name) == 0)
402 return &sparc_vtinherit_howto;
403 if (strcasecmp (sparc_vtentry_howto.name, r_name) == 0)
404 return &sparc_vtentry_howto;
405 if (strcasecmp (sparc_rev32_howto.name, r_name) == 0)
406 return &sparc_rev32_howto;
407
408 return NULL;
409}
410
411reloc_howto_type *
388_bfd_sparc_elf_info_to_howto_ptr (unsigned int r_type)
389{
390 switch (r_type)
391 {
392 case R_SPARC_GNU_VTINHERIT:
393 return &sparc_vtinherit_howto;
394
395 case R_SPARC_GNU_VTENTRY:

--- 86 unchanged lines hidden (view full) ---

482 ((struct _bfd_sparc_elf_obj_tdata *) (abfd)->tdata.any)
483
484#define _bfd_sparc_elf_local_got_tls_type(abfd) \
485 (_bfd_sparc_elf_tdata (abfd)->local_got_tls_type)
486
487bfd_boolean
488_bfd_sparc_elf_mkobject (bfd *abfd)
489{
412_bfd_sparc_elf_info_to_howto_ptr (unsigned int r_type)
413{
414 switch (r_type)
415 {
416 case R_SPARC_GNU_VTINHERIT:
417 return &sparc_vtinherit_howto;
418
419 case R_SPARC_GNU_VTENTRY:

--- 86 unchanged lines hidden (view full) ---

506 ((struct _bfd_sparc_elf_obj_tdata *) (abfd)->tdata.any)
507
508#define _bfd_sparc_elf_local_got_tls_type(abfd) \
509 (_bfd_sparc_elf_tdata (abfd)->local_got_tls_type)
510
511bfd_boolean
512_bfd_sparc_elf_mkobject (bfd *abfd)
513{
490 bfd_size_type amt = sizeof (struct _bfd_sparc_elf_obj_tdata);
491 abfd->tdata.any = bfd_zalloc (abfd, amt);
492 if (abfd->tdata.any == NULL)
514 if (abfd->tdata.any == NULL)
493 return FALSE;
494 return TRUE;
515 {
516 bfd_size_type amt = sizeof (struct _bfd_sparc_elf_obj_tdata);
517 abfd->tdata.any = bfd_zalloc (abfd, amt);
518 if (abfd->tdata.any == NULL)
519 return FALSE;
520 }
521 return bfd_elf_mkobject (abfd);
495}
496
497static void
498sparc_put_word_32 (bfd *bfd, bfd_vma val, void *ptr)
499{
500 bfd_put_32 (bfd, val, ptr);
501}
502
503static void
504sparc_put_word_64 (bfd *bfd, bfd_vma val, void *ptr)
505{
506 bfd_put_64 (bfd, val, ptr);
507}
508
509static void
522}
523
524static void
525sparc_put_word_32 (bfd *bfd, bfd_vma val, void *ptr)
526{
527 bfd_put_32 (bfd, val, ptr);
528}
529
530static void
531sparc_put_word_64 (bfd *bfd, bfd_vma val, void *ptr)
532{
533 bfd_put_64 (bfd, val, ptr);
534}
535
536static void
510sparc_elf_append_rela_64 (bfd *abfd ATTRIBUTE_UNUSED,
511 asection *s ATTRIBUTE_UNUSED,
512 Elf_Internal_Rela *rel ATTRIBUTE_UNUSED)
537sparc_elf_append_rela (bfd *abfd, asection *s, Elf_Internal_Rela *rel)
513{
538{
514#ifdef BFD64
515 Elf64_External_Rela *loc64;
539 const struct elf_backend_data *bed;
540 bfd_byte *loc;
516
541
517 loc64 = (Elf64_External_Rela *) s->contents;
518 loc64 += s->reloc_count++;
519 bfd_elf64_swap_reloca_out (abfd, rel, (bfd_byte *) loc64);
520#endif
542 bed = get_elf_backend_data (abfd);
543 loc = s->contents + (s->reloc_count++ * bed->s->sizeof_rela);
544 bed->s->swap_reloca_out (abfd, rel, loc);
521}
522
545}
546
523static void
524sparc_elf_append_rela_32 (bfd *abfd, asection *s, Elf_Internal_Rela *rel)
525{
526 Elf32_External_Rela *loc32;
527
528 loc32 = (Elf32_External_Rela *) s->contents;
529 loc32 += s->reloc_count++;
530 bfd_elf32_swap_reloca_out (abfd, rel, (bfd_byte *) loc32);
531}
532
533static bfd_vma
534sparc_elf_r_info_64 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
535 bfd_vma index ATTRIBUTE_UNUSED,
536 bfd_vma type ATTRIBUTE_UNUSED)
537{
538 return ELF64_R_INFO (index,
539 (in_rel ?
540 ELF64_R_TYPE_INFO (ELF64_R_TYPE_DATA (in_rel->r_info),

--- 200 unchanged lines hidden (view full) ---

741 0x03000000, /* sethi %hi(f@pltindex), %g1 */
742 0x10800000, /* b _PLT_resolve */
743 0x82106000 /* or %g1, %lo(f@pltindex), %g1 */
744 };
745
746#define SPARC_ELF_PUT_WORD(htab, bfd, val, ptr) \
747 htab->put_word(bfd, val, ptr)
748
547static bfd_vma
548sparc_elf_r_info_64 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
549 bfd_vma index ATTRIBUTE_UNUSED,
550 bfd_vma type ATTRIBUTE_UNUSED)
551{
552 return ELF64_R_INFO (index,
553 (in_rel ?
554 ELF64_R_TYPE_INFO (ELF64_R_TYPE_DATA (in_rel->r_info),

--- 200 unchanged lines hidden (view full) ---

755 0x03000000, /* sethi %hi(f@pltindex), %g1 */
756 0x10800000, /* b _PLT_resolve */
757 0x82106000 /* or %g1, %lo(f@pltindex), %g1 */
758 };
759
760#define SPARC_ELF_PUT_WORD(htab, bfd, val, ptr) \
761 htab->put_word(bfd, val, ptr)
762
749#define SPARC_ELF_APPEND_RELA(htab, bfd, sec, rela) \
750 htab->append_rela(bfd, sec, rela)
751
752#define SPARC_ELF_R_INFO(htab, in_rel, index, type) \
753 htab->r_info(in_rel, index, type)
754
755#define SPARC_ELF_R_SYMNDX(htab, r_info) \
756 htab->r_symndx(r_info)
757
758#define SPARC_ELF_WORD_BYTES(htab) \
759 htab->bytes_per_word

--- 59 unchanged lines hidden (view full) ---

819
820 ret = (struct _bfd_sparc_elf_link_hash_table *) bfd_zmalloc (amt);
821 if (ret == NULL)
822 return NULL;
823
824 if (ABI_64_P (abfd))
825 {
826 ret->put_word = sparc_put_word_64;
763#define SPARC_ELF_R_INFO(htab, in_rel, index, type) \
764 htab->r_info(in_rel, index, type)
765
766#define SPARC_ELF_R_SYMNDX(htab, r_info) \
767 htab->r_symndx(r_info)
768
769#define SPARC_ELF_WORD_BYTES(htab) \
770 htab->bytes_per_word

--- 59 unchanged lines hidden (view full) ---

830
831 ret = (struct _bfd_sparc_elf_link_hash_table *) bfd_zmalloc (amt);
832 if (ret == NULL)
833 return NULL;
834
835 if (ABI_64_P (abfd))
836 {
837 ret->put_word = sparc_put_word_64;
827 ret->append_rela = sparc_elf_append_rela_64;
828 ret->r_info = sparc_elf_r_info_64;
829 ret->r_symndx = sparc_elf_r_symndx_64;
830 ret->dtpoff_reloc = R_SPARC_TLS_DTPOFF64;
831 ret->dtpmod_reloc = R_SPARC_TLS_DTPMOD64;
832 ret->tpoff_reloc = R_SPARC_TLS_TPOFF64;
833 ret->word_align_power = 3;
834 ret->align_power_max = 4;
835 ret->bytes_per_word = 8;
836 ret->bytes_per_rela = sizeof (Elf64_External_Rela);
837 ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
838 ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
839 }
840 else
841 {
842 ret->put_word = sparc_put_word_32;
838 ret->r_info = sparc_elf_r_info_64;
839 ret->r_symndx = sparc_elf_r_symndx_64;
840 ret->dtpoff_reloc = R_SPARC_TLS_DTPOFF64;
841 ret->dtpmod_reloc = R_SPARC_TLS_DTPMOD64;
842 ret->tpoff_reloc = R_SPARC_TLS_TPOFF64;
843 ret->word_align_power = 3;
844 ret->align_power_max = 4;
845 ret->bytes_per_word = 8;
846 ret->bytes_per_rela = sizeof (Elf64_External_Rela);
847 ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
848 ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
849 }
850 else
851 {
852 ret->put_word = sparc_put_word_32;
843 ret->append_rela = sparc_elf_append_rela_32;
844 ret->r_info = sparc_elf_r_info_32;
845 ret->r_symndx = sparc_elf_r_symndx_32;
846 ret->dtpoff_reloc = R_SPARC_TLS_DTPOFF32;
847 ret->dtpmod_reloc = R_SPARC_TLS_DTPMOD32;
848 ret->tpoff_reloc = R_SPARC_TLS_TPOFF32;
849 ret->word_align_power = 2;
850 ret->align_power_max = 3;
851 ret->bytes_per_word = 4;

--- 570 unchanged lines hidden (view full) ---

1422
1423 name = (bfd_elf_string_from_elf_section
1424 (abfd,
1425 elf_elfheader (abfd)->e_shstrndx,
1426 elf_section_data (sec)->rel_hdr.sh_name));
1427 if (name == NULL)
1428 return FALSE;
1429
853 ret->r_info = sparc_elf_r_info_32;
854 ret->r_symndx = sparc_elf_r_symndx_32;
855 ret->dtpoff_reloc = R_SPARC_TLS_DTPOFF32;
856 ret->dtpmod_reloc = R_SPARC_TLS_DTPMOD32;
857 ret->tpoff_reloc = R_SPARC_TLS_TPOFF32;
858 ret->word_align_power = 2;
859 ret->align_power_max = 3;
860 ret->bytes_per_word = 4;

--- 570 unchanged lines hidden (view full) ---

1431
1432 name = (bfd_elf_string_from_elf_section
1433 (abfd,
1434 elf_elfheader (abfd)->e_shstrndx,
1435 elf_section_data (sec)->rel_hdr.sh_name));
1436 if (name == NULL)
1437 return FALSE;
1438
1430 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1439 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
1431 && strcmp (bfd_get_section_name (abfd, sec),
1432 name + 5) == 0);
1433
1434 if (htab->elf.dynobj == NULL)
1435 htab->elf.dynobj = abfd;
1436 dynobj = htab->elf.dynobj;
1437
1438 sreloc = bfd_get_section_by_name (dynobj, name);

--- 85 unchanged lines hidden (view full) ---

1524asection *
1525_bfd_sparc_elf_gc_mark_hook (asection *sec,
1526 struct bfd_link_info *info,
1527 Elf_Internal_Rela *rel,
1528 struct elf_link_hash_entry *h,
1529 Elf_Internal_Sym *sym)
1530{
1531 if (h != NULL)
1440 && strcmp (bfd_get_section_name (abfd, sec),
1441 name + 5) == 0);
1442
1443 if (htab->elf.dynobj == NULL)
1444 htab->elf.dynobj = abfd;
1445 dynobj = htab->elf.dynobj;
1446
1447 sreloc = bfd_get_section_by_name (dynobj, name);

--- 85 unchanged lines hidden (view full) ---

1533asection *
1534_bfd_sparc_elf_gc_mark_hook (asection *sec,
1535 struct bfd_link_info *info,
1536 Elf_Internal_Rela *rel,
1537 struct elf_link_hash_entry *h,
1538 Elf_Internal_Sym *sym)
1539{
1540 if (h != NULL)
1532 {
1533 struct _bfd_sparc_elf_link_hash_table *htab;
1534
1535 htab = _bfd_sparc_elf_hash_table (info);
1536 switch (SPARC_ELF_R_TYPE (rel->r_info))
1541 switch (SPARC_ELF_R_TYPE (rel->r_info))
1537 {
1538 case R_SPARC_GNU_VTINHERIT:
1539 case R_SPARC_GNU_VTENTRY:
1542 {
1543 case R_SPARC_GNU_VTINHERIT:
1544 case R_SPARC_GNU_VTENTRY:
1540 break;
1541
1542 default:
1543 switch (h->root.type)
1544 {
1545 case bfd_link_hash_defined:
1546 case bfd_link_hash_defweak:
1547 return h->root.u.def.section;
1548
1549 case bfd_link_hash_common:
1550 return h->root.u.c.p->section;
1551
1552 default:
1553 break;
1554 }
1545 return NULL;
1555 }
1546 }
1556 }
1557 else
1558 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
1559
1547
1560 return NULL;
1548 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1561}
1562
1563/* Update the got entry reference counts for the section being removed. */
1564bfd_boolean
1565_bfd_sparc_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
1566 asection *sec, const Elf_Internal_Rela *relocs)
1567{
1568 struct _bfd_sparc_elf_link_hash_table *htab;

--- 139 unchanged lines hidden (view full) ---

1708bfd_boolean
1709_bfd_sparc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
1710 struct elf_link_hash_entry *h)
1711{
1712 struct _bfd_sparc_elf_link_hash_table *htab;
1713 struct _bfd_sparc_elf_link_hash_entry * eh;
1714 struct _bfd_sparc_elf_dyn_relocs *p;
1715 asection *s;
1549}
1550
1551/* Update the got entry reference counts for the section being removed. */
1552bfd_boolean
1553_bfd_sparc_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
1554 asection *sec, const Elf_Internal_Rela *relocs)
1555{
1556 struct _bfd_sparc_elf_link_hash_table *htab;

--- 139 unchanged lines hidden (view full) ---

1696bfd_boolean
1697_bfd_sparc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
1698 struct elf_link_hash_entry *h)
1699{
1700 struct _bfd_sparc_elf_link_hash_table *htab;
1701 struct _bfd_sparc_elf_link_hash_entry * eh;
1702 struct _bfd_sparc_elf_dyn_relocs *p;
1703 asection *s;
1716 unsigned int power_of_two;
1717
1718 htab = _bfd_sparc_elf_hash_table (info);
1719
1720 /* Make sure we know what is going on here. */
1721 BFD_ASSERT (htab->elf.dynobj != NULL
1722 && (h->needs_plt
1723 || h->u.weakdef != NULL
1724 || (h->def_dynamic

--- 100 unchanged lines hidden (view full) ---

1825 runtime process image. We need to remember the offset into the
1826 .rel.bss section we are going to use. */
1827 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1828 {
1829 htab->srelbss->size += SPARC_ELF_RELA_BYTES (htab);
1830 h->needs_copy = 1;
1831 }
1832
1704
1705 htab = _bfd_sparc_elf_hash_table (info);
1706
1707 /* Make sure we know what is going on here. */
1708 BFD_ASSERT (htab->elf.dynobj != NULL
1709 && (h->needs_plt
1710 || h->u.weakdef != NULL
1711 || (h->def_dynamic

--- 100 unchanged lines hidden (view full) ---

1812 runtime process image. We need to remember the offset into the
1813 .rel.bss section we are going to use. */
1814 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1815 {
1816 htab->srelbss->size += SPARC_ELF_RELA_BYTES (htab);
1817 h->needs_copy = 1;
1818 }
1819
1833 /* We need to figure out the alignment required for this symbol. I
1834 have no idea how ELF linkers handle this. */
1835 power_of_two = bfd_log2 (h->size);
1836 if (power_of_two > htab->align_power_max)
1837 power_of_two = htab->align_power_max;
1838
1839 /* Apply the required alignment. */
1840 s = htab->sdynbss;
1820 s = htab->sdynbss;
1841 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
1842 if (power_of_two > bfd_get_section_alignment (dynobj, s))
1843 {
1844 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
1845 return FALSE;
1846 }
1847
1821
1848 /* Define the symbol as being at this point in the section. */
1849 h->root.u.def.section = s;
1850 h->root.u.def.value = s->size;
1851
1852 /* Increment the section size to make room for the symbol. */
1853 s->size += h->size;
1854
1855 return TRUE;
1822 return _bfd_elf_adjust_dynamic_copy (h, s);
1856}
1857
1858/* Allocate space in .plt, .got and associated reloc sections for
1859 dynamic relocs. */
1860
1861static bfd_boolean
1862allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
1863{

--- 418 unchanged lines hidden (view full) ---

2282 if (s == htab->splt
2283 || s == htab->sgot
2284 || s == htab->sdynbss
2285 || s == htab->sgotplt)
2286 {
2287 /* Strip this section if we don't need it; see the
2288 comment below. */
2289 }
1823}
1824
1825/* Allocate space in .plt, .got and associated reloc sections for
1826 dynamic relocs. */
1827
1828static bfd_boolean
1829allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
1830{

--- 418 unchanged lines hidden (view full) ---

2249 if (s == htab->splt
2250 || s == htab->sgot
2251 || s == htab->sdynbss
2252 || s == htab->sgotplt)
2253 {
2254 /* Strip this section if we don't need it; see the
2255 comment below. */
2256 }
2290 else if (strncmp (s->name, ".rela", 5) == 0)
2257 else if (CONST_STRNEQ (s->name, ".rela"))
2291 {
2292 if (s->size != 0)
2293 {
2294 /* We use the reloc_count field as a counter if we need
2295 to copy relocs into the output file. */
2296 s->reloc_count = 0;
2297 }
2298 }

--- 130 unchanged lines hidden (view full) ---

2429#undef add_dynamic_entry
2430
2431 return TRUE;
2432}
2433
2434bfd_boolean
2435_bfd_sparc_elf_new_section_hook (bfd *abfd, asection *sec)
2436{
2258 {
2259 if (s->size != 0)
2260 {
2261 /* We use the reloc_count field as a counter if we need
2262 to copy relocs into the output file. */
2263 s->reloc_count = 0;
2264 }
2265 }

--- 130 unchanged lines hidden (view full) ---

2396#undef add_dynamic_entry
2397
2398 return TRUE;
2399}
2400
2401bfd_boolean
2402_bfd_sparc_elf_new_section_hook (bfd *abfd, asection *sec)
2403{
2437 struct _bfd_sparc_elf_section_data *sdata;
2438 bfd_size_type amt = sizeof (*sdata);
2404 if (!sec->used_by_bfd)
2405 {
2406 struct _bfd_sparc_elf_section_data *sdata;
2407 bfd_size_type amt = sizeof (*sdata);
2439
2408
2440 sdata = (struct _bfd_sparc_elf_section_data *) bfd_zalloc (abfd, amt);
2441 if (sdata == NULL)
2442 return FALSE;
2443 sec->used_by_bfd = (PTR) sdata;
2409 sdata = bfd_zalloc (abfd, amt);
2410 if (sdata == NULL)
2411 return FALSE;
2412 sec->used_by_bfd = sdata;
2413 }
2444
2445 return _bfd_elf_new_section_hook (abfd, sec);
2446}
2447
2448bfd_boolean
2449_bfd_sparc_elf_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
2450 struct bfd_section *section,
2451 struct bfd_link_info *link_info ATTRIBUTE_UNUSED,

--- 29 unchanged lines hidden (view full) ---

2481 if (htab->tls_sec == NULL)
2482 return 0;
2483 return address - htab->tls_size - htab->tls_sec->vma;
2484}
2485
2486/* Relocate a SPARC ELF section. */
2487
2488bfd_boolean
2414
2415 return _bfd_elf_new_section_hook (abfd, sec);
2416}
2417
2418bfd_boolean
2419_bfd_sparc_elf_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
2420 struct bfd_section *section,
2421 struct bfd_link_info *link_info ATTRIBUTE_UNUSED,

--- 29 unchanged lines hidden (view full) ---

2451 if (htab->tls_sec == NULL)
2452 return 0;
2453 return address - htab->tls_size - htab->tls_sec->vma;
2454}
2455
2456/* Relocate a SPARC ELF section. */
2457
2458bfd_boolean
2489_bfd_sparc_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
2490 bfd *input_bfd, asection *input_section,
2491 bfd_byte *contents, Elf_Internal_Rela *relocs,
2492 Elf_Internal_Sym *local_syms, asection **local_sections)
2459_bfd_sparc_elf_relocate_section (bfd *output_bfd,
2460 struct bfd_link_info *info,
2461 bfd *input_bfd,
2462 asection *input_section,
2463 bfd_byte *contents,
2464 Elf_Internal_Rela *relocs,
2465 Elf_Internal_Sym *local_syms,
2466 asection **local_sections)
2493{
2494 struct _bfd_sparc_elf_link_hash_table *htab;
2495 Elf_Internal_Shdr *symtab_hdr;
2496 struct elf_link_hash_entry **sym_hashes;
2497 bfd_vma *local_got_offsets;
2498 bfd_vma got_base;
2499 asection *sreloc;
2500 Elf_Internal_Rela *rel;
2501 Elf_Internal_Rela *relend;
2502 int num_relocs;
2503
2467{
2468 struct _bfd_sparc_elf_link_hash_table *htab;
2469 Elf_Internal_Shdr *symtab_hdr;
2470 struct elf_link_hash_entry **sym_hashes;
2471 bfd_vma *local_got_offsets;
2472 bfd_vma got_base;
2473 asection *sreloc;
2474 Elf_Internal_Rela *rel;
2475 Elf_Internal_Rela *relend;
2476 int num_relocs;
2477
2504 if (info->relocatable)
2505 return TRUE;
2506
2507 htab = _bfd_sparc_elf_hash_table (info);
2508 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2509 sym_hashes = elf_sym_hashes (input_bfd);
2510 local_got_offsets = elf_local_got_offsets (input_bfd);
2511
2512 if (elf_hash_table (info)->hgot == NULL)
2513 got_base = 0;
2514 else

--- 27 unchanged lines hidden (view full) ---

2542
2543 if (r_type < 0 || r_type >= (int) R_SPARC_max_std)
2544 {
2545 bfd_set_error (bfd_error_bad_value);
2546 return FALSE;
2547 }
2548 howto = _bfd_sparc_elf_howto_table + r_type;
2549
2478 htab = _bfd_sparc_elf_hash_table (info);
2479 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2480 sym_hashes = elf_sym_hashes (input_bfd);
2481 local_got_offsets = elf_local_got_offsets (input_bfd);
2482
2483 if (elf_hash_table (info)->hgot == NULL)
2484 got_base = 0;
2485 else

--- 27 unchanged lines hidden (view full) ---

2513
2514 if (r_type < 0 || r_type >= (int) R_SPARC_max_std)
2515 {
2516 bfd_set_error (bfd_error_bad_value);
2517 return FALSE;
2518 }
2519 howto = _bfd_sparc_elf_howto_table + r_type;
2520
2550 /* This is a final link. */
2551 r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
2552 h = NULL;
2553 sym = NULL;
2554 sec = NULL;
2555 unresolved_reloc = FALSE;
2556 if (r_symndx < symtab_hdr->sh_info)
2557 {
2558 sym = local_syms + r_symndx;

--- 15 unchanged lines hidden (view full) ---

2574 the start of this section. */
2575 if (input_section->output_section != NULL)
2576 relocation = input_section->output_section->vma;
2577 else
2578 relocation = 0;
2579 }
2580 }
2581
2521 r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
2522 h = NULL;
2523 sym = NULL;
2524 sec = NULL;
2525 unresolved_reloc = FALSE;
2526 if (r_symndx < symtab_hdr->sh_info)
2527 {
2528 sym = local_syms + r_symndx;

--- 15 unchanged lines hidden (view full) ---

2544 the start of this section. */
2545 if (input_section->output_section != NULL)
2546 relocation = input_section->output_section->vma;
2547 else
2548 relocation = 0;
2549 }
2550 }
2551
2552 if (sec != NULL && elf_discarded_section (sec))
2553 {
2554 /* For relocs against symbols from removed linkonce
2555 sections, or sections discarded by a linker script, we
2556 just want the section contents zeroed. Avoid any
2557 special processing. */
2558 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
2559 rel->r_info = 0;
2560 rel->r_addend = 0;
2561 continue;
2562 }
2563
2564 if (info->relocatable)
2565 continue;
2566
2582 switch (r_type)
2583 {
2584 case R_SPARC_GOT10:
2585 case R_SPARC_GOT13:
2586 case R_SPARC_GOT22:
2587 /* Relocation is to the entry for this symbol in the global
2588 offset table. */
2589 if (htab->sgot == NULL)

--- 65 unchanged lines hidden (view full) ---

2655
2656 outrel.r_offset = (htab->sgot->output_section->vma
2657 + htab->sgot->output_offset
2658 + off);
2659 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
2660 0, R_SPARC_RELATIVE);
2661 outrel.r_addend = relocation;
2662 relocation = 0;
2567 switch (r_type)
2568 {
2569 case R_SPARC_GOT10:
2570 case R_SPARC_GOT13:
2571 case R_SPARC_GOT22:
2572 /* Relocation is to the entry for this symbol in the global
2573 offset table. */
2574 if (htab->sgot == NULL)

--- 65 unchanged lines hidden (view full) ---

2640
2641 outrel.r_offset = (htab->sgot->output_section->vma
2642 + htab->sgot->output_offset
2643 + off);
2644 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
2645 0, R_SPARC_RELATIVE);
2646 outrel.r_addend = relocation;
2647 relocation = 0;
2663 SPARC_ELF_APPEND_RELA (htab, output_bfd, s, &outrel);
2648 sparc_elf_append_rela (output_bfd, s, &outrel);
2664 }
2665
2666 SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
2667 htab->sgot->contents + off);
2668 local_got_offsets[r_symndx] |= 1;
2669 }
2670 }
2671 relocation = htab->sgot->output_offset + off - got_base;

--- 90 unchanged lines hidden (view full) ---

2762 case R_SPARC_6:
2763 case R_SPARC_HIX22:
2764 case R_SPARC_LOX10:
2765 case R_SPARC_H44:
2766 case R_SPARC_M44:
2767 case R_SPARC_L44:
2768 case R_SPARC_UA64:
2769 r_sparc_plt32:
2649 }
2650
2651 SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
2652 htab->sgot->contents + off);
2653 local_got_offsets[r_symndx] |= 1;
2654 }
2655 }
2656 relocation = htab->sgot->output_offset + off - got_base;

--- 90 unchanged lines hidden (view full) ---

2747 case R_SPARC_6:
2748 case R_SPARC_HIX22:
2749 case R_SPARC_LOX10:
2750 case R_SPARC_H44:
2751 case R_SPARC_M44:
2752 case R_SPARC_L44:
2753 case R_SPARC_UA64:
2754 r_sparc_plt32:
2770 /* r_symndx will be zero only for relocs against symbols
2771 from removed linkonce sections, or sections discarded by
2772 a linker script. */
2773 if (r_symndx == 0
2774 || (input_section->flags & SEC_ALLOC) == 0)
2755 if ((input_section->flags & SEC_ALLOC) == 0)
2775 break;
2776
2777 if ((info->shared
2778 && (h == NULL
2779 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2780 || h->root.type != bfd_link_hash_undefweak)
2781 && (! howto->pc_relative
2782 || (h != NULL

--- 91 unchanged lines hidden (view full) ---

2874 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
2875 0, R_SPARC_RELATIVE);
2876 outrel.r_addend = relocation + rel->r_addend;
2877 }
2878 else
2879 {
2880 long indx;
2881
2756 break;
2757
2758 if ((info->shared
2759 && (h == NULL
2760 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2761 || h->root.type != bfd_link_hash_undefweak)
2762 && (! howto->pc_relative
2763 || (h != NULL

--- 91 unchanged lines hidden (view full) ---

2855 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
2856 0, R_SPARC_RELATIVE);
2857 outrel.r_addend = relocation + rel->r_addend;
2858 }
2859 else
2860 {
2861 long indx;
2862
2863 outrel.r_addend = relocation + rel->r_addend;
2864
2882 if (is_plt)
2883 sec = htab->splt;
2884
2885 if (bfd_is_abs_section (sec))
2886 indx = 0;
2887 else if (sec == NULL || sec->owner == NULL)
2888 {
2889 bfd_set_error (bfd_error_bad_value);
2890 return FALSE;
2891 }
2892 else
2893 {
2894 asection *osec;
2895
2865 if (is_plt)
2866 sec = htab->splt;
2867
2868 if (bfd_is_abs_section (sec))
2869 indx = 0;
2870 else if (sec == NULL || sec->owner == NULL)
2871 {
2872 bfd_set_error (bfd_error_bad_value);
2873 return FALSE;
2874 }
2875 else
2876 {
2877 asection *osec;
2878
2879 /* We are turning this relocation into one
2880 against a section symbol. It would be
2881 proper to subtract the symbol's value,
2882 osec->vma, from the emitted reloc addend,
2883 but ld.so expects buggy relocs. */
2896 osec = sec->output_section;
2897 indx = elf_section_data (osec)->dynindx;
2898
2884 osec = sec->output_section;
2885 indx = elf_section_data (osec)->dynindx;
2886
2887 if (indx == 0)
2888 {
2889 osec = htab->elf.text_index_section;
2890 indx = elf_section_data (osec)->dynindx;
2891 }
2892
2899 /* FIXME: we really should be able to link non-pic
2900 shared libraries. */
2901 if (indx == 0)
2902 {
2903 BFD_FAIL ();
2904 (*_bfd_error_handler)
2905 (_("%B: probably compiled without -fPIC?"),
2906 input_bfd);
2907 bfd_set_error (bfd_error_bad_value);
2908 return FALSE;
2909 }
2910 }
2911
2893 /* FIXME: we really should be able to link non-pic
2894 shared libraries. */
2895 if (indx == 0)
2896 {
2897 BFD_FAIL ();
2898 (*_bfd_error_handler)
2899 (_("%B: probably compiled without -fPIC?"),
2900 input_bfd);
2901 bfd_set_error (bfd_error_bad_value);
2902 return FALSE;
2903 }
2904 }
2905
2912 outrel.r_info = SPARC_ELF_R_INFO (htab, rel, indx, r_type);
2913 outrel.r_addend = relocation + rel->r_addend;
2906 outrel.r_info = SPARC_ELF_R_INFO (htab, rel, indx,
2907 r_type);
2914 }
2915 }
2916
2908 }
2909 }
2910
2917 SPARC_ELF_APPEND_RELA (htab, output_bfd, sreloc, &outrel);
2911 sparc_elf_append_rela (output_bfd, sreloc, &outrel);
2918
2919 /* This reloc will be computed at runtime, so there's no
2920 need to do anything now. */
2921 if (! relocate)
2922 continue;
2923 }
2924 break;
2925

--- 91 unchanged lines hidden (view full) ---

3017 dr_type = SPARC_ELF_TPOFF_RELOC (htab);
3018 else
3019 dr_type = SPARC_ELF_DTPMOD_RELOC (htab);
3020 if (dr_type == SPARC_ELF_TPOFF_RELOC (htab) && indx == 0)
3021 outrel.r_addend = relocation - dtpoff_base (info);
3022 else
3023 outrel.r_addend = 0;
3024 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, indx, dr_type);
2912
2913 /* This reloc will be computed at runtime, so there's no
2914 need to do anything now. */
2915 if (! relocate)
2916 continue;
2917 }
2918 break;
2919

--- 91 unchanged lines hidden (view full) ---

3011 dr_type = SPARC_ELF_TPOFF_RELOC (htab);
3012 else
3013 dr_type = SPARC_ELF_DTPMOD_RELOC (htab);
3014 if (dr_type == SPARC_ELF_TPOFF_RELOC (htab) && indx == 0)
3015 outrel.r_addend = relocation - dtpoff_base (info);
3016 else
3017 outrel.r_addend = 0;
3018 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, indx, dr_type);
3025 SPARC_ELF_APPEND_RELA (htab, output_bfd, htab->srelgot, &outrel);
3019 sparc_elf_append_rela (output_bfd, htab->srelgot, &outrel);
3026
3027 if (r_type == R_SPARC_TLS_GD_HI22
3028 || r_type == R_SPARC_TLS_GD_LO10)
3029 {
3030 if (indx == 0)
3031 {
3032 BFD_ASSERT (! unresolved_reloc);
3033 SPARC_ELF_PUT_WORD (htab, output_bfd,

--- 4 unchanged lines hidden (view full) ---

3038 else
3039 {
3040 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3041 (htab->sgot->contents + off
3042 + SPARC_ELF_WORD_BYTES (htab)));
3043 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, indx,
3044 SPARC_ELF_DTPOFF_RELOC (htab));
3045 outrel.r_offset += SPARC_ELF_WORD_BYTES (htab);
3020
3021 if (r_type == R_SPARC_TLS_GD_HI22
3022 || r_type == R_SPARC_TLS_GD_LO10)
3023 {
3024 if (indx == 0)
3025 {
3026 BFD_ASSERT (! unresolved_reloc);
3027 SPARC_ELF_PUT_WORD (htab, output_bfd,

--- 4 unchanged lines hidden (view full) ---

3032 else
3033 {
3034 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3035 (htab->sgot->contents + off
3036 + SPARC_ELF_WORD_BYTES (htab)));
3037 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, indx,
3038 SPARC_ELF_DTPOFF_RELOC (htab));
3039 outrel.r_offset += SPARC_ELF_WORD_BYTES (htab);
3046 SPARC_ELF_APPEND_RELA (htab, output_bfd, htab->srelgot, &outrel);
3040 sparc_elf_append_rela (output_bfd, htab->srelgot,
3041 &outrel);
3047 }
3048 }
3049 else if (dr_type == SPARC_ELF_DTPMOD_RELOC (htab))
3050 {
3051 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3052 (htab->sgot->contents + off
3053 + SPARC_ELF_WORD_BYTES (htab)));
3054 }

--- 52 unchanged lines hidden (view full) ---

3107 memset (&outrel, 0, sizeof outrel);
3108 else
3109 {
3110 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, r_type);
3111 outrel.r_addend = relocation - dtpoff_base (info)
3112 + rel->r_addend;
3113 }
3114
3042 }
3043 }
3044 else if (dr_type == SPARC_ELF_DTPMOD_RELOC (htab))
3045 {
3046 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3047 (htab->sgot->contents + off
3048 + SPARC_ELF_WORD_BYTES (htab)));
3049 }

--- 52 unchanged lines hidden (view full) ---

3102 memset (&outrel, 0, sizeof outrel);
3103 else
3104 {
3105 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, r_type);
3106 outrel.r_addend = relocation - dtpoff_base (info)
3107 + rel->r_addend;
3108 }
3109
3115 SPARC_ELF_APPEND_RELA (htab, output_bfd, sreloc, &outrel);
3110 sparc_elf_append_rela (output_bfd, sreloc, &outrel);
3116 continue;
3117 }
3118 relocation = tpoff (info, relocation);
3119 break;
3120
3121 case R_SPARC_TLS_LDM_CALL:
3122 if (! info->shared)
3123 {

--- 504 unchanged lines hidden (view full) ---

3628bfd_boolean
3629_bfd_sparc_elf_finish_dynamic_symbol (bfd *output_bfd,
3630 struct bfd_link_info *info,
3631 struct elf_link_hash_entry *h,
3632 Elf_Internal_Sym *sym)
3633{
3634 bfd *dynobj;
3635 struct _bfd_sparc_elf_link_hash_table *htab;
3111 continue;
3112 }
3113 relocation = tpoff (info, relocation);
3114 break;
3115
3116 case R_SPARC_TLS_LDM_CALL:
3117 if (! info->shared)
3118 {

--- 504 unchanged lines hidden (view full) ---

3623bfd_boolean
3624_bfd_sparc_elf_finish_dynamic_symbol (bfd *output_bfd,
3625 struct bfd_link_info *info,
3626 struct elf_link_hash_entry *h,
3627 Elf_Internal_Sym *sym)
3628{
3629 bfd *dynobj;
3630 struct _bfd_sparc_elf_link_hash_table *htab;
3631 const struct elf_backend_data *bed;
3636
3637 htab = _bfd_sparc_elf_hash_table (info);
3638 dynobj = htab->elf.dynobj;
3632
3633 htab = _bfd_sparc_elf_hash_table (info);
3634 dynobj = htab->elf.dynobj;
3635 bed = get_elf_backend_data (output_bfd);
3639
3640 if (h->plt.offset != (bfd_vma) -1)
3641 {
3642 asection *splt;
3643 asection *srela;
3644 Elf_Internal_Rela rela;
3645 bfd_byte *loc;
3646 bfd_vma r_offset, got_offset;

--- 53 unchanged lines hidden (view full) ---

3700 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_JMP_SLOT);
3701
3702 /* Adjust for the first 4 reserved elements in the .plt section
3703 when setting the offset in the .rela.plt section.
3704 Sun forgot to read their own ABI and copied elf32-sparc behaviour,
3705 thus .plt[4] has corresponding .rela.plt[0] and so on. */
3706
3707 loc = srela->contents;
3636
3637 if (h->plt.offset != (bfd_vma) -1)
3638 {
3639 asection *splt;
3640 asection *srela;
3641 Elf_Internal_Rela rela;
3642 bfd_byte *loc;
3643 bfd_vma r_offset, got_offset;

--- 53 unchanged lines hidden (view full) ---

3697 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_JMP_SLOT);
3698
3699 /* Adjust for the first 4 reserved elements in the .plt section
3700 when setting the offset in the .rela.plt section.
3701 Sun forgot to read their own ABI and copied elf32-sparc behaviour,
3702 thus .plt[4] has corresponding .rela.plt[0] and so on. */
3703
3704 loc = srela->contents;
3708#ifdef BFD64
3709 if (ABI_64_P (output_bfd))
3710 {
3711 loc += rela_index * sizeof (Elf64_External_Rela);
3712 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3713 }
3714 else
3715#endif
3716 {
3717 loc += rela_index * sizeof (Elf32_External_Rela);
3718 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3719 }
3705 loc += rela_index * bed->s->sizeof_rela;
3706 bed->s->swap_reloca_out (output_bfd, &rela, loc);
3720
3721 if (!h->def_regular)
3722 {
3723 /* Mark the symbol as undefined, rather than as defined in
3724 the .plt section. Leave the value alone. */
3725 sym->st_shndx = SHN_UNDEF;
3726 /* If the symbol is weak, we do need to clear the value.
3727 Otherwise, the PLT entry would provide a definition for

--- 40 unchanged lines hidden (view full) ---

3768 else
3769 {
3770 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_GLOB_DAT);
3771 rela.r_addend = 0;
3772 }
3773
3774 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3775 sgot->contents + (h->got.offset & ~(bfd_vma) 1));
3707
3708 if (!h->def_regular)
3709 {
3710 /* Mark the symbol as undefined, rather than as defined in
3711 the .plt section. Leave the value alone. */
3712 sym->st_shndx = SHN_UNDEF;
3713 /* If the symbol is weak, we do need to clear the value.
3714 Otherwise, the PLT entry would provide a definition for

--- 40 unchanged lines hidden (view full) ---

3755 else
3756 {
3757 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_GLOB_DAT);
3758 rela.r_addend = 0;
3759 }
3760
3761 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3762 sgot->contents + (h->got.offset & ~(bfd_vma) 1));
3776 SPARC_ELF_APPEND_RELA (htab, output_bfd, srela, &rela);
3763 sparc_elf_append_rela (output_bfd, srela, &rela);
3777 }
3778
3779 if (h->needs_copy)
3780 {
3781 asection *s;
3782 Elf_Internal_Rela rela;
3783
3784 /* This symbols needs a copy reloc. Set it up. */
3785 BFD_ASSERT (h->dynindx != -1);
3786
3787 s = bfd_get_section_by_name (h->root.u.def.section->owner,
3788 ".rela.bss");
3789 BFD_ASSERT (s != NULL);
3790
3791 rela.r_offset = (h->root.u.def.value
3792 + h->root.u.def.section->output_section->vma
3793 + h->root.u.def.section->output_offset);
3794 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_COPY);
3795 rela.r_addend = 0;
3764 }
3765
3766 if (h->needs_copy)
3767 {
3768 asection *s;
3769 Elf_Internal_Rela rela;
3770
3771 /* This symbols needs a copy reloc. Set it up. */
3772 BFD_ASSERT (h->dynindx != -1);
3773
3774 s = bfd_get_section_by_name (h->root.u.def.section->owner,
3775 ".rela.bss");
3776 BFD_ASSERT (s != NULL);
3777
3778 rela.r_offset = (h->root.u.def.value
3779 + h->root.u.def.section->output_section->vma
3780 + h->root.u.def.section->output_offset);
3781 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_COPY);
3782 rela.r_addend = 0;
3796 SPARC_ELF_APPEND_RELA (htab, output_bfd, s, &rela);
3783 sparc_elf_append_rela (output_bfd, s, &rela);
3797 }
3798
3799 /* Mark some specially defined symbols as absolute. On VxWorks,
3800 _GLOBAL_OFFSET_TABLE_ is not absolute: it is relative to the
3801 ".got" section. Likewise _PROCEDURE_LINKAGE_TABLE_ and ".plt". */
3802 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3803 || (!htab->is_vxworks
3804 && (h == htab->elf.hgot || h == htab->elf.hplt)))
3805 sym->st_shndx = SHN_ABS;
3806
3807 return TRUE;
3808}
3809
3810/* Finish up the dynamic sections. */
3811
3784 }
3785
3786 /* Mark some specially defined symbols as absolute. On VxWorks,
3787 _GLOBAL_OFFSET_TABLE_ is not absolute: it is relative to the
3788 ".got" section. Likewise _PROCEDURE_LINKAGE_TABLE_ and ".plt". */
3789 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3790 || (!htab->is_vxworks
3791 && (h == htab->elf.hgot || h == htab->elf.hplt)))
3792 sym->st_shndx = SHN_ABS;
3793
3794 return TRUE;
3795}
3796
3797/* Finish up the dynamic sections. */
3798
3812#ifdef BFD64
3813static bfd_boolean
3799static bfd_boolean
3814sparc64_finish_dyn (bfd *output_bfd, struct bfd_link_info *info,
3815 bfd *dynobj, asection *sdyn,
3816 asection *splt ATTRIBUTE_UNUSED)
3800sparc_finish_dyn (bfd *output_bfd, struct bfd_link_info *info,
3801 bfd *dynobj, asection *sdyn,
3802 asection *splt ATTRIBUTE_UNUSED)
3817{
3803{
3818 Elf64_External_Dyn *dyncon, *dynconend;
3804 struct _bfd_sparc_elf_link_hash_table *htab;
3805 const struct elf_backend_data *bed;
3806 bfd_byte *dyncon, *dynconend;
3807 size_t dynsize;
3819 int stt_regidx = -1;
3808 int stt_regidx = -1;
3809 bfd_boolean abi_64_p;
3820
3810
3821 dyncon = (Elf64_External_Dyn *) sdyn->contents;
3822 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
3823 for (; dyncon < dynconend; dyncon++)
3824 {
3825 Elf_Internal_Dyn dyn;
3826 const char *name;
3827 bfd_boolean size;
3828
3829 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3830
3831 switch (dyn.d_tag)
3832 {
3833 case DT_PLTGOT: name = ".plt"; size = FALSE; break;
3834 case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE; break;
3835 case DT_JMPREL: name = ".rela.plt"; size = FALSE; break;
3836 case DT_SPARC_REGISTER:
3837 if (stt_regidx == -1)
3838 {
3839 stt_regidx =
3840 _bfd_elf_link_lookup_local_dynindx (info, output_bfd, -1);
3841 if (stt_regidx == -1)
3842 return FALSE;
3843 }
3844 dyn.d_un.d_val = stt_regidx++;
3845 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3846 /* fallthrough */
3847 default: name = NULL; size = FALSE; break;
3848 }
3849
3850 if (name != NULL)
3851 {
3852 asection *s;
3853
3854 s = bfd_get_section_by_name (output_bfd, name);
3855 if (s == NULL)
3856 dyn.d_un.d_val = 0;
3857 else
3858 {
3859 if (! size)
3860 dyn.d_un.d_ptr = s->vma;
3861 else
3862 dyn.d_un.d_val = s->size;
3863 }
3864 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3865 }
3866 }
3867 return TRUE;
3868}
3869#endif
3870
3871static bfd_boolean
3872sparc32_finish_dyn (bfd *output_bfd, struct bfd_link_info *info,
3873 bfd *dynobj, asection *sdyn,
3874 asection *splt ATTRIBUTE_UNUSED)
3875{
3876 Elf32_External_Dyn *dyncon, *dynconend;
3877 struct _bfd_sparc_elf_link_hash_table *htab;
3878
3879 htab = _bfd_sparc_elf_hash_table (info);
3811 htab = _bfd_sparc_elf_hash_table (info);
3880 dyncon = (Elf32_External_Dyn *) sdyn->contents;
3881 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
3882 for (; dyncon < dynconend; dyncon++)
3812 bed = get_elf_backend_data (output_bfd);
3813 dynsize = bed->s->sizeof_dyn;
3814 dynconend = sdyn->contents + sdyn->size;
3815 abi_64_p = ABI_64_P (output_bfd);
3816 for (dyncon = sdyn->contents; dyncon < dynconend; dyncon += dynsize)
3883 {
3884 Elf_Internal_Dyn dyn;
3885 const char *name;
3886 bfd_boolean size;
3887
3817 {
3818 Elf_Internal_Dyn dyn;
3819 const char *name;
3820 bfd_boolean size;
3821
3888 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3822 bed->s->swap_dyn_in (dynobj, dyncon, &dyn);
3889
3890 if (htab->is_vxworks && dyn.d_tag == DT_RELASZ)
3891 {
3892 /* On VxWorks, DT_RELASZ should not include the relocations
3893 in .rela.plt. */
3894 if (htab->srelplt)
3895 {
3896 dyn.d_un.d_val -= htab->srelplt->size;
3823
3824 if (htab->is_vxworks && dyn.d_tag == DT_RELASZ)
3825 {
3826 /* On VxWorks, DT_RELASZ should not include the relocations
3827 in .rela.plt. */
3828 if (htab->srelplt)
3829 {
3830 dyn.d_un.d_val -= htab->srelplt->size;
3897 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3831 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
3898 }
3899 }
3900 else if (htab->is_vxworks && dyn.d_tag == DT_PLTGOT)
3901 {
3902 /* On VxWorks, DT_PLTGOT should point to the start of the GOT,
3903 not to the start of the PLT. */
3904 if (htab->sgotplt)
3905 {
3906 dyn.d_un.d_val = (htab->sgotplt->output_section->vma
3907 + htab->sgotplt->output_offset);
3832 }
3833 }
3834 else if (htab->is_vxworks && dyn.d_tag == DT_PLTGOT)
3835 {
3836 /* On VxWorks, DT_PLTGOT should point to the start of the GOT,
3837 not to the start of the PLT. */
3838 if (htab->sgotplt)
3839 {
3840 dyn.d_un.d_val = (htab->sgotplt->output_section->vma
3841 + htab->sgotplt->output_offset);
3908 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3842 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
3909 }
3910 }
3843 }
3844 }
3845 else if (abi_64_p && dyn.d_tag == DT_SPARC_REGISTER)
3846 {
3847 if (stt_regidx == -1)
3848 {
3849 stt_regidx =
3850 _bfd_elf_link_lookup_local_dynindx (info, output_bfd, -1);
3851 if (stt_regidx == -1)
3852 return FALSE;
3853 }
3854 dyn.d_un.d_val = stt_regidx++;
3855 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
3856 }
3911 else
3912 {
3913 switch (dyn.d_tag)
3914 {
3915 case DT_PLTGOT: name = ".plt"; size = FALSE; break;
3916 case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE; break;
3917 case DT_JMPREL: name = ".rela.plt"; size = FALSE; break;
3857 else
3858 {
3859 switch (dyn.d_tag)
3860 {
3861 case DT_PLTGOT: name = ".plt"; size = FALSE; break;
3862 case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE; break;
3863 case DT_JMPREL: name = ".rela.plt"; size = FALSE; break;
3918 default: name = NULL; size = FALSE; break;
3864 default: name = NULL; size = FALSE; break;
3919 }
3920
3921 if (name != NULL)
3922 {
3923 asection *s;
3924
3925 s = bfd_get_section_by_name (output_bfd, name);
3926 if (s == NULL)
3927 dyn.d_un.d_val = 0;
3928 else
3929 {
3930 if (! size)
3931 dyn.d_un.d_ptr = s->vma;
3932 else
3933 dyn.d_un.d_val = s->size;
3934 }
3865 }
3866
3867 if (name != NULL)
3868 {
3869 asection *s;
3870
3871 s = bfd_get_section_by_name (output_bfd, name);
3872 if (s == NULL)
3873 dyn.d_un.d_val = 0;
3874 else
3875 {
3876 if (! size)
3877 dyn.d_un.d_ptr = s->vma;
3878 else
3879 dyn.d_un.d_val = s->size;
3880 }
3935 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3881 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
3936 }
3937 }
3938 }
3939 return TRUE;
3940}
3941
3942/* Install the first PLT entry in a VxWorks executable and make sure that
3943 .rela.plt.unloaded relocations have the correct symbol indexes. */

--- 97 unchanged lines hidden (view full) ---

4041 htab = _bfd_sparc_elf_hash_table (info);
4042 dynobj = htab->elf.dynobj;
4043
4044 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4045
4046 if (elf_hash_table (info)->dynamic_sections_created)
4047 {
4048 asection *splt;
3882 }
3883 }
3884 }
3885 return TRUE;
3886}
3887
3888/* Install the first PLT entry in a VxWorks executable and make sure that
3889 .rela.plt.unloaded relocations have the correct symbol indexes. */

--- 97 unchanged lines hidden (view full) ---

3987 htab = _bfd_sparc_elf_hash_table (info);
3988 dynobj = htab->elf.dynobj;
3989
3990 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3991
3992 if (elf_hash_table (info)->dynamic_sections_created)
3993 {
3994 asection *splt;
4049 bfd_boolean ret;
4050
4051 splt = bfd_get_section_by_name (dynobj, ".plt");
4052 BFD_ASSERT (splt != NULL && sdyn != NULL);
4053
3995
3996 splt = bfd_get_section_by_name (dynobj, ".plt");
3997 BFD_ASSERT (splt != NULL && sdyn != NULL);
3998
4054#ifdef BFD64
4055 if (ABI_64_P (output_bfd))
4056 ret = sparc64_finish_dyn (output_bfd, info, dynobj, sdyn, splt);
4057 else
4058#endif
4059 ret = sparc32_finish_dyn (output_bfd, info, dynobj, sdyn, splt);
3999 if (!sparc_finish_dyn (output_bfd, info, dynobj, sdyn, splt))
4000 return FALSE;
4060
4001
4061 if (ret != TRUE)
4062 return ret;
4063
4064 /* Initialize the contents of the .plt section. */
4065 if (splt->size > 0)
4066 {
4067 if (htab->is_vxworks)
4068 {
4069 if (info->shared)
4070 sparc_vxworks_finish_shared_plt (output_bfd, info);
4071 else

--- 4 unchanged lines hidden (view full) ---

4076 memset (splt->contents, 0, htab->plt_header_size);
4077 if (!ABI_64_P (output_bfd))
4078 bfd_put_32 (output_bfd, (bfd_vma) SPARC_NOP,
4079 splt->contents + splt->size - 4);
4080 }
4081 }
4082
4083 elf_section_data (splt->output_section)->this_hdr.sh_entsize
4002 /* Initialize the contents of the .plt section. */
4003 if (splt->size > 0)
4004 {
4005 if (htab->is_vxworks)
4006 {
4007 if (info->shared)
4008 sparc_vxworks_finish_shared_plt (output_bfd, info);
4009 else

--- 4 unchanged lines hidden (view full) ---

4014 memset (splt->contents, 0, htab->plt_header_size);
4015 if (!ABI_64_P (output_bfd))
4016 bfd_put_32 (output_bfd, (bfd_vma) SPARC_NOP,
4017 splt->contents + splt->size - 4);
4018 }
4019 }
4020
4021 elf_section_data (splt->output_section)->this_hdr.sh_entsize
4084 = htab->plt_entry_size;
4022 = (htab->is_vxworks || !ABI_64_P (output_bfd))
4023 ? 0 : htab->plt_entry_size;
4085 }
4086
4087 /* Set the first entry in the global offset table to the address of
4088 the dynamic section. */
4089 if (htab->sgot && htab->sgot->size > 0)
4090 {
4091 bfd_vma val = (sdyn ?
4092 sdyn->output_section->vma + sdyn->output_offset :

--- 73 unchanged lines hidden ---
4024 }
4025
4026 /* Set the first entry in the global offset table to the address of
4027 the dynamic section. */
4028 if (htab->sgot && htab->sgot->size > 0)
4029 {
4030 bfd_vma val = (sdyn ?
4031 sdyn->output_section->vma + sdyn->output_offset :

--- 73 unchanged lines hidden ---