1 /* SPARC-specific support for 64-bit ELF
2 Copyright (C) 1993-2023 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
26 #include "elf/sparc.h"
27 #include "opcode/sparc.h"
28 #include "elfxx-sparc.h"
30 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
31 #define MINUS_ONE (~ (bfd_vma) 0)
33 /* Due to the way how we handle R_SPARC_OLO10, each entry in a SHT_RELA
34 section can represent up to two relocs, we must tell the user to allocate
38 elf64_sparc_get_reloc_upper_bound (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
)
42 count
= sec
->reloc_count
;
43 if (count
>= LONG_MAX
/ 2 / sizeof (arelent
*)
44 || _bfd_mul_overflow (count
, sizeof (Elf64_External_Rela
), &raw
))
46 bfd_set_error (bfd_error_file_too_big
);
49 if (!bfd_write_p (abfd
))
51 ufile_ptr filesize
= bfd_get_file_size (abfd
);
52 if (filesize
!= 0 && raw
> filesize
)
54 bfd_set_error (bfd_error_file_truncated
);
58 return (count
* 2 + 1) * sizeof (arelent
*);
62 elf64_sparc_get_dynamic_reloc_upper_bound (bfd
*abfd
)
64 long ret
= _bfd_elf_get_dynamic_reloc_upper_bound (abfd
);
65 if (ret
> LONG_MAX
/ 2)
67 bfd_set_error (bfd_error_file_too_big
);
75 /* Read relocations for ASECT from REL_HDR. There are RELOC_COUNT of
76 them. We cannot use generic elf routines for this, because R_SPARC_OLO10
77 has secondary addend in ELF64_R_TYPE_DATA. We handle it as two relocations
78 for the same location, R_SPARC_LO10 and R_SPARC_13. */
81 elf64_sparc_slurp_one_reloc_table (bfd
*abfd
, asection
*asect
,
82 Elf_Internal_Shdr
*rel_hdr
,
83 asymbol
**symbols
, bool dynamic
)
85 void * allocated
= NULL
;
86 bfd_byte
*native_relocs
;
93 if (bfd_seek (abfd
, rel_hdr
->sh_offset
, SEEK_SET
) != 0)
95 allocated
= _bfd_malloc_and_read (abfd
, rel_hdr
->sh_size
, rel_hdr
->sh_size
);
96 if (allocated
== NULL
)
99 native_relocs
= (bfd_byte
*) allocated
;
101 relents
= asect
->relocation
+ canon_reloc_count (asect
);
103 entsize
= rel_hdr
->sh_entsize
;
104 BFD_ASSERT (entsize
== sizeof (Elf64_External_Rela
));
106 count
= rel_hdr
->sh_size
/ entsize
;
108 for (i
= 0, relent
= relents
; i
< count
;
109 i
++, relent
++, native_relocs
+= entsize
)
111 Elf_Internal_Rela rela
;
114 bfd_elf64_swap_reloca_in (abfd
, native_relocs
, &rela
);
116 /* The address of an ELF reloc is section relative for an object
117 file, and absolute for an executable file or shared library.
118 The address of a normal BFD reloc is always section relative,
119 and the address of a dynamic reloc is absolute.. */
120 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0 || dynamic
)
121 relent
->address
= rela
.r_offset
;
123 relent
->address
= rela
.r_offset
- asect
->vma
;
125 if (ELF64_R_SYM (rela
.r_info
) == STN_UNDEF
)
126 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
127 else if (/* PR 17512: file: 996185f8. */
128 ELF64_R_SYM (rela
.r_info
) > (dynamic
129 ? bfd_get_dynamic_symcount (abfd
)
130 : bfd_get_symcount (abfd
)))
133 /* xgettext:c-format */
134 (_("%pB(%pA): relocation %d has invalid symbol index %ld"),
135 abfd
, asect
, i
, (long) ELF64_R_SYM (rela
.r_info
));
136 bfd_set_error (bfd_error_bad_value
);
137 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
143 ps
= symbols
+ ELF64_R_SYM (rela
.r_info
) - 1;
146 /* Canonicalize ELF section symbols. FIXME: Why? */
147 if ((s
->flags
& BSF_SECTION_SYM
) == 0)
148 relent
->sym_ptr_ptr
= ps
;
150 relent
->sym_ptr_ptr
= s
->section
->symbol_ptr_ptr
;
153 relent
->addend
= rela
.r_addend
;
155 r_type
= ELF64_R_TYPE_ID (rela
.r_info
);
156 if (r_type
== R_SPARC_OLO10
)
158 relent
->howto
= _bfd_sparc_elf_info_to_howto_ptr (abfd
, R_SPARC_LO10
);
159 relent
[1].address
= relent
->address
;
161 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
162 relent
->addend
= ELF64_R_TYPE_DATA (rela
.r_info
);
163 relent
->howto
= _bfd_sparc_elf_info_to_howto_ptr (abfd
, R_SPARC_13
);
167 relent
->howto
= _bfd_sparc_elf_info_to_howto_ptr (abfd
, r_type
);
168 if (relent
->howto
== NULL
)
173 canon_reloc_count (asect
) += relent
- relents
;
183 /* Read in and swap the external relocs. */
186 elf64_sparc_slurp_reloc_table (bfd
*abfd
, asection
*asect
,
187 asymbol
**symbols
, bool dynamic
)
189 struct bfd_elf_section_data
* const d
= elf_section_data (asect
);
190 Elf_Internal_Shdr
*rel_hdr
;
191 Elf_Internal_Shdr
*rel_hdr2
;
194 if (asect
->relocation
!= NULL
)
199 if ((asect
->flags
& SEC_RELOC
) == 0
200 || asect
->reloc_count
== 0)
203 rel_hdr
= d
->rel
.hdr
;
204 rel_hdr2
= d
->rela
.hdr
;
206 BFD_ASSERT ((rel_hdr
&& asect
->rel_filepos
== rel_hdr
->sh_offset
)
207 || (rel_hdr2
&& asect
->rel_filepos
== rel_hdr2
->sh_offset
));
211 /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
212 case because relocations against this section may use the
213 dynamic symbol table, and in that case bfd_section_from_shdr
214 in elf.c does not update the RELOC_COUNT. */
215 if (asect
->size
== 0)
218 rel_hdr
= &d
->this_hdr
;
219 asect
->reloc_count
= NUM_SHDR_ENTRIES (rel_hdr
);
223 amt
= asect
->reloc_count
;
224 amt
*= 2 * sizeof (arelent
);
225 asect
->relocation
= (arelent
*) bfd_alloc (abfd
, amt
);
226 if (asect
->relocation
== NULL
)
229 /* The elf64_sparc_slurp_one_reloc_table routine increments
230 canon_reloc_count. */
231 canon_reloc_count (asect
) = 0;
234 && !elf64_sparc_slurp_one_reloc_table (abfd
, asect
, rel_hdr
, symbols
,
239 && !elf64_sparc_slurp_one_reloc_table (abfd
, asect
, rel_hdr2
, symbols
,
246 /* Canonicalize the relocs. */
249 elf64_sparc_canonicalize_reloc (bfd
*abfd
, sec_ptr section
,
250 arelent
**relptr
, asymbol
**symbols
)
254 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
256 if (! bed
->s
->slurp_reloc_table (abfd
, section
, symbols
, false))
259 tblptr
= section
->relocation
;
260 for (i
= 0; i
< canon_reloc_count (section
); i
++)
261 *relptr
++ = tblptr
++;
265 return canon_reloc_count (section
);
269 /* Canonicalize the dynamic relocation entries. Note that we return
270 the dynamic relocations as a single block, although they are
271 actually associated with particular sections; the interface, which
272 was designed for SunOS style shared libraries, expects that there
273 is only one set of dynamic relocs. Any section that was actually
274 installed in the BFD, and has type SHT_REL or SHT_RELA, and uses
275 the dynamic symbol table, is considered to be a dynamic reloc
279 elf64_sparc_canonicalize_dynamic_reloc (bfd
*abfd
, arelent
**storage
,
285 if (elf_dynsymtab (abfd
) == 0)
287 bfd_set_error (bfd_error_invalid_operation
);
292 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
294 if (elf_section_data (s
)->this_hdr
.sh_link
== elf_dynsymtab (abfd
)
295 && (elf_section_data (s
)->this_hdr
.sh_type
== SHT_RELA
))
300 if (! elf64_sparc_slurp_reloc_table (abfd
, s
, syms
, true))
302 count
= canon_reloc_count (s
);
304 for (i
= 0; i
< count
; i
++)
315 /* Install a new set of internal relocs. */
318 elf64_sparc_set_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
323 asect
->orelocation
= location
;
324 canon_reloc_count (asect
) = count
;
326 asect
->flags
|= SEC_RELOC
;
328 asect
->flags
&= ~SEC_RELOC
;
331 /* Write out the relocs. */
334 elf64_sparc_write_relocs (bfd
*abfd
, asection
*sec
, void * data
)
336 bool *failedp
= (bool *) data
;
337 Elf_Internal_Shdr
*rela_hdr
;
339 Elf64_External_Rela
*outbound_relocas
, *src_rela
;
340 unsigned int idx
, count
;
341 asymbol
*last_sym
= 0;
342 int last_sym_idx
= 0;
344 /* If we have already failed, don't do anything. */
348 if ((sec
->flags
& SEC_RELOC
) == 0)
351 /* The linker backend writes the relocs out itself, and sets the
352 reloc_count field to zero to inhibit writing them here. Also,
353 sometimes the SEC_RELOC flag gets set even when there aren't any
355 if (canon_reloc_count (sec
) == 0)
358 /* We can combine two relocs that refer to the same address
359 into R_SPARC_OLO10 if first one is R_SPARC_LO10 and the
360 latter is R_SPARC_13 with no associated symbol. */
362 for (idx
= 0; idx
< canon_reloc_count (sec
); idx
++)
368 addr
= sec
->orelocation
[idx
]->address
;
369 if (sec
->orelocation
[idx
]->howto
->type
== R_SPARC_LO10
370 && idx
< canon_reloc_count (sec
) - 1)
372 arelent
*r
= sec
->orelocation
[idx
+ 1];
374 if (r
->howto
->type
== R_SPARC_13
375 && r
->address
== addr
376 && bfd_is_abs_section ((*r
->sym_ptr_ptr
)->section
)
377 && (*r
->sym_ptr_ptr
)->value
== 0)
382 rela_hdr
= elf_section_data (sec
)->rela
.hdr
;
384 rela_hdr
->sh_size
= rela_hdr
->sh_entsize
* count
;
385 rela_hdr
->contents
= bfd_alloc (abfd
, rela_hdr
->sh_size
);
386 if (rela_hdr
->contents
== NULL
)
392 /* Figure out whether the relocations are RELA or REL relocations. */
393 if (rela_hdr
->sh_type
!= SHT_RELA
)
396 /* The address of an ELF reloc is section relative for an object
397 file, and absolute for an executable file or shared library.
398 The address of a BFD reloc is always section relative. */
400 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
401 addr_offset
= sec
->vma
;
403 /* orelocation has the data, reloc_count has the count... */
404 outbound_relocas
= (Elf64_External_Rela
*) rela_hdr
->contents
;
405 src_rela
= outbound_relocas
;
407 for (idx
= 0; idx
< canon_reloc_count (sec
); idx
++)
409 Elf_Internal_Rela dst_rela
;
414 ptr
= sec
->orelocation
[idx
];
415 sym
= *ptr
->sym_ptr_ptr
;
418 else if (bfd_is_abs_section (sym
->section
) && sym
->value
== 0)
423 n
= _bfd_elf_symbol_from_bfd_symbol (abfd
, &sym
);
432 if ((*ptr
->sym_ptr_ptr
)->the_bfd
!= NULL
433 && (*ptr
->sym_ptr_ptr
)->the_bfd
->xvec
!= abfd
->xvec
434 && ! _bfd_elf_validate_reloc (abfd
, ptr
))
440 if (ptr
->howto
->type
== R_SPARC_LO10
441 && idx
< canon_reloc_count (sec
) - 1)
443 arelent
*r
= sec
->orelocation
[idx
+ 1];
445 if (r
->howto
->type
== R_SPARC_13
446 && r
->address
== ptr
->address
447 && bfd_is_abs_section ((*r
->sym_ptr_ptr
)->section
)
448 && (*r
->sym_ptr_ptr
)->value
== 0)
452 = ELF64_R_INFO (n
, ELF64_R_TYPE_INFO (r
->addend
,
456 dst_rela
.r_info
= ELF64_R_INFO (n
, R_SPARC_LO10
);
459 dst_rela
.r_info
= ELF64_R_INFO (n
, ptr
->howto
->type
);
461 dst_rela
.r_offset
= ptr
->address
+ addr_offset
;
462 dst_rela
.r_addend
= ptr
->addend
;
464 bfd_elf64_swap_reloca_out (abfd
, &dst_rela
, (bfd_byte
*) src_rela
);
469 /* Hook called by the linker routine which adds symbols from an object
470 file. We use it for STT_REGISTER symbols. */
473 elf64_sparc_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
474 Elf_Internal_Sym
*sym
, const char **namep
,
475 flagword
*flagsp ATTRIBUTE_UNUSED
,
476 asection
**secp ATTRIBUTE_UNUSED
,
477 bfd_vma
*valp ATTRIBUTE_UNUSED
)
479 static const char *const stt_types
[] = { "NOTYPE", "OBJECT", "FUNCTION" };
481 if (ELF_ST_TYPE (sym
->st_info
) == STT_REGISTER
)
484 struct _bfd_sparc_elf_app_reg
*p
;
486 reg
= (int)sym
->st_value
;
489 case 2: reg
-= 2; break;
490 case 6: reg
-= 4; break;
493 (_("%pB: only registers %%g[2367] can be declared using STT_REGISTER"),
498 if (info
->output_bfd
->xvec
!= abfd
->xvec
499 || (abfd
->flags
& DYNAMIC
) != 0)
501 /* STT_REGISTER only works when linking an elf64_sparc object.
502 If STT_REGISTER comes from a dynamic object, don't put it into
503 the output bfd. The dynamic linker will recheck it. */
508 p
= _bfd_sparc_elf_hash_table(info
)->app_regs
+ reg
;
510 if (p
->name
!= NULL
&& strcmp (p
->name
, *namep
))
513 /* xgettext:c-format */
514 (_("register %%g%d used incompatibly: %s in %pB,"
515 " previously %s in %pB"),
516 (int) sym
->st_value
, **namep
? *namep
: "#scratch", abfd
,
517 *p
->name
? p
->name
: "#scratch", p
->abfd
);
525 struct elf_link_hash_entry
*h
;
527 h
= (struct elf_link_hash_entry
*)
528 bfd_link_hash_lookup (info
->hash
, *namep
, false, false, false);
532 unsigned char type
= h
->type
;
537 /* xgettext:c-format */
538 (_("symbol `%s' has differing types: REGISTER in %pB,"
539 " previously %s in %pB"),
540 *namep
, abfd
, stt_types
[type
], p
->abfd
);
544 p
->name
= bfd_hash_allocate (&info
->hash
->table
,
545 strlen (*namep
) + 1);
549 strcpy (p
->name
, *namep
);
553 p
->bind
= ELF_ST_BIND (sym
->st_info
);
555 p
->shndx
= sym
->st_shndx
;
559 if (p
->bind
== STB_WEAK
560 && ELF_ST_BIND (sym
->st_info
) == STB_GLOBAL
)
562 p
->bind
= STB_GLOBAL
;
569 else if (*namep
&& **namep
570 && info
->output_bfd
->xvec
== abfd
->xvec
)
573 struct _bfd_sparc_elf_app_reg
*p
;
575 p
= _bfd_sparc_elf_hash_table(info
)->app_regs
;
576 for (i
= 0; i
< 4; i
++, p
++)
577 if (p
->name
!= NULL
&& ! strcmp (p
->name
, *namep
))
579 unsigned char type
= ELF_ST_TYPE (sym
->st_info
);
584 /* xgettext:c-format */
585 (_("Symbol `%s' has differing types: %s in %pB,"
586 " previously REGISTER in %pB"),
587 *namep
, stt_types
[type
], abfd
, p
->abfd
);
594 /* This function takes care of emitting STT_REGISTER symbols
595 which we cannot easily keep in the symbol hash table. */
598 elf64_sparc_output_arch_syms (bfd
*output_bfd ATTRIBUTE_UNUSED
,
599 struct bfd_link_info
*info
,
601 int (*func
) (void *, const char *,
604 struct elf_link_hash_entry
*))
607 struct _bfd_sparc_elf_app_reg
*app_regs
=
608 _bfd_sparc_elf_hash_table(info
)->app_regs
;
609 Elf_Internal_Sym sym
;
611 for (reg
= 0; reg
< 4; reg
++)
612 if (app_regs
[reg
].name
!= NULL
)
614 if (info
->strip
== strip_some
615 && bfd_hash_lookup (info
->keep_hash
,
617 false, false) == NULL
)
620 sym
.st_value
= reg
< 2 ? reg
+ 2 : reg
+ 4;
623 sym
.st_info
= ELF_ST_INFO (app_regs
[reg
].bind
, STT_REGISTER
);
624 sym
.st_shndx
= app_regs
[reg
].shndx
;
625 sym
.st_target_internal
= 0;
626 if ((*func
) (flaginfo
, app_regs
[reg
].name
, &sym
,
627 sym
.st_shndx
== SHN_ABS
628 ? bfd_abs_section_ptr
: bfd_und_section_ptr
,
637 elf64_sparc_get_symbol_type (Elf_Internal_Sym
*elf_sym
, int type
)
639 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_REGISTER
)
645 /* A STB_GLOBAL,STT_REGISTER symbol should be BSF_GLOBAL
646 even in SHN_UNDEF section. */
649 elf64_sparc_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*asym
)
651 elf_symbol_type
*elfsym
;
653 elfsym
= (elf_symbol_type
*) asym
;
654 if (elfsym
->internal_elf_sym
.st_info
655 == ELF_ST_INFO (STB_GLOBAL
, STT_REGISTER
))
657 asym
->flags
|= BSF_GLOBAL
;
662 /* Functions for dealing with the e_flags field. */
664 /* Merge backend specific data from an object file to the output
665 object file when linking. */
668 elf64_sparc_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
670 bfd
*obfd
= info
->output_bfd
;
672 flagword new_flags
, old_flags
;
675 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
676 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
679 new_flags
= elf_elfheader (ibfd
)->e_flags
;
680 old_flags
= elf_elfheader (obfd
)->e_flags
;
682 if (!elf_flags_init (obfd
)) /* First call, no flags set */
684 elf_flags_init (obfd
) = true;
685 elf_elfheader (obfd
)->e_flags
= new_flags
;
688 else if (new_flags
== old_flags
) /* Compatible flags are ok */
691 else /* Incompatible flags */
695 #define EF_SPARC_ISA_EXTENSIONS \
696 (EF_SPARC_SUN_US1 | EF_SPARC_SUN_US3 | EF_SPARC_HAL_R1)
698 if ((ibfd
->flags
& DYNAMIC
) != 0)
700 /* We don't want dynamic objects memory ordering and
701 architecture to have any role. That's what dynamic linker
703 new_flags
&= ~(EF_SPARCV9_MM
| EF_SPARC_ISA_EXTENSIONS
);
704 new_flags
|= (old_flags
705 & (EF_SPARCV9_MM
| EF_SPARC_ISA_EXTENSIONS
));
709 /* Choose the highest architecture requirements. */
710 old_flags
|= (new_flags
& EF_SPARC_ISA_EXTENSIONS
);
711 new_flags
|= (old_flags
& EF_SPARC_ISA_EXTENSIONS
);
712 if ((old_flags
& (EF_SPARC_SUN_US1
| EF_SPARC_SUN_US3
))
713 && (old_flags
& EF_SPARC_HAL_R1
))
717 (_("%pB: linking UltraSPARC specific with HAL specific code"),
720 /* Choose the most restrictive memory ordering. */
721 old_mm
= (old_flags
& EF_SPARCV9_MM
);
722 new_mm
= (new_flags
& EF_SPARCV9_MM
);
723 old_flags
&= ~EF_SPARCV9_MM
;
724 new_flags
&= ~EF_SPARCV9_MM
;
731 /* Warn about any other mismatches */
732 if (new_flags
!= old_flags
)
736 /* xgettext:c-format */
737 (_("%pB: uses different e_flags (%#x) fields than previous modules (%#x)"),
738 ibfd
, new_flags
, old_flags
);
741 elf_elfheader (obfd
)->e_flags
= old_flags
;
745 bfd_set_error (bfd_error_bad_value
);
749 return _bfd_sparc_elf_merge_private_bfd_data (ibfd
, info
);
752 /* MARCO: Set the correct entry size for the .stab section. */
755 elf64_sparc_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
756 Elf_Internal_Shdr
*hdr ATTRIBUTE_UNUSED
,
761 name
= bfd_section_name (sec
);
763 if (strcmp (name
, ".stab") == 0)
765 /* Even in the 64bit case the stab entries are only 12 bytes long. */
766 elf_section_data (sec
)->this_hdr
.sh_entsize
= 12;
772 /* Print a STT_REGISTER symbol to file FILE. */
775 elf64_sparc_print_symbol_all (bfd
*abfd ATTRIBUTE_UNUSED
, void * filep
,
778 FILE *file
= (FILE *) filep
;
781 if (ELF_ST_TYPE (((elf_symbol_type
*) symbol
)->internal_elf_sym
.st_info
)
785 reg
= ((elf_symbol_type
*) symbol
)->internal_elf_sym
.st_value
;
786 type
= symbol
->flags
;
787 fprintf (file
, "REG_%c%c%11s%c%c R", "GOLI" [reg
/ 8], '0' + (reg
& 7), "",
789 ? (type
& BSF_GLOBAL
) ? '!' : 'l'
790 : (type
& BSF_GLOBAL
) ? 'g' : ' '),
791 (type
& BSF_WEAK
) ? 'w' : ' ');
792 if (symbol
->name
== NULL
|| symbol
->name
[0] == '\0')
798 /* Used to decide how to sort relocs in an optimal manner for the
799 dynamic linker, before writing them out. */
801 static enum elf_reloc_type_class
802 elf64_sparc_reloc_type_class (const struct bfd_link_info
*info
,
803 const asection
*rel_sec ATTRIBUTE_UNUSED
,
804 const Elf_Internal_Rela
*rela
)
806 bfd
*abfd
= info
->output_bfd
;
807 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
808 struct _bfd_sparc_elf_link_hash_table
*htab
809 = _bfd_sparc_elf_hash_table (info
);
810 BFD_ASSERT (htab
!= NULL
);
812 if (htab
->elf
.dynsym
!= NULL
813 && htab
->elf
.dynsym
->contents
!= NULL
)
815 /* Check relocation against STT_GNU_IFUNC symbol if there are
817 unsigned long r_symndx
= htab
->r_symndx (rela
->r_info
);
818 if (r_symndx
!= STN_UNDEF
)
820 Elf_Internal_Sym sym
;
821 if (!bed
->s
->swap_symbol_in (abfd
,
822 (htab
->elf
.dynsym
->contents
823 + r_symndx
* bed
->s
->sizeof_sym
),
827 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
828 return reloc_class_ifunc
;
832 switch ((int) ELF64_R_TYPE (rela
->r_info
))
834 case R_SPARC_IRELATIVE
:
835 return reloc_class_ifunc
;
836 case R_SPARC_RELATIVE
:
837 return reloc_class_relative
;
838 case R_SPARC_JMP_SLOT
:
839 return reloc_class_plt
;
841 return reloc_class_copy
;
843 return reloc_class_normal
;
847 /* Relocations in the 64 bit SPARC ELF ABI are more complex than in
848 standard ELF, because R_SPARC_OLO10 has secondary addend in
849 ELF64_R_TYPE_DATA field. This structure is used to redirect the
850 relocation handling routines. */
852 const struct elf_size_info elf64_sparc_size_info
=
854 sizeof (Elf64_External_Ehdr
),
855 sizeof (Elf64_External_Phdr
),
856 sizeof (Elf64_External_Shdr
),
857 sizeof (Elf64_External_Rel
),
858 sizeof (Elf64_External_Rela
),
859 sizeof (Elf64_External_Sym
),
860 sizeof (Elf64_External_Dyn
),
861 sizeof (Elf_External_Note
),
862 4, /* hash-table entry size. */
863 /* Internal relocations per external relocations.
864 For link purposes we use just 1 internal per
865 1 external, for assembly and slurp symbol table
869 3, /* log_file_align. */
872 bfd_elf64_write_out_phdrs
,
873 bfd_elf64_write_shdrs_and_ehdr
,
874 bfd_elf64_checksum_contents
,
875 elf64_sparc_write_relocs
,
876 bfd_elf64_swap_symbol_in
,
877 bfd_elf64_swap_symbol_out
,
878 elf64_sparc_slurp_reloc_table
,
879 bfd_elf64_slurp_symbol_table
,
880 bfd_elf64_swap_dyn_in
,
881 bfd_elf64_swap_dyn_out
,
882 bfd_elf64_swap_reloc_in
,
883 bfd_elf64_swap_reloc_out
,
884 bfd_elf64_swap_reloca_in
,
885 bfd_elf64_swap_reloca_out
888 #define TARGET_BIG_SYM sparc_elf64_vec
889 #define TARGET_BIG_NAME "elf64-sparc"
890 #define ELF_ARCH bfd_arch_sparc
891 #define ELF_MAXPAGESIZE 0x100000
892 #define ELF_COMMONPAGESIZE 0x2000
894 /* This is the official ABI value. */
895 #define ELF_MACHINE_CODE EM_SPARCV9
897 /* This is the value that we used before the ABI was released. */
898 #define ELF_MACHINE_ALT1 EM_OLD_SPARCV9
900 #define elf_backend_reloc_type_class \
901 elf64_sparc_reloc_type_class
902 #define bfd_elf64_get_reloc_upper_bound \
903 elf64_sparc_get_reloc_upper_bound
904 #define bfd_elf64_get_dynamic_reloc_upper_bound \
905 elf64_sparc_get_dynamic_reloc_upper_bound
906 #define bfd_elf64_canonicalize_reloc \
907 elf64_sparc_canonicalize_reloc
908 #define bfd_elf64_canonicalize_dynamic_reloc \
909 elf64_sparc_canonicalize_dynamic_reloc
910 #define bfd_elf64_set_reloc \
911 elf64_sparc_set_reloc
912 #define elf_backend_add_symbol_hook \
913 elf64_sparc_add_symbol_hook
914 #define elf_backend_get_symbol_type \
915 elf64_sparc_get_symbol_type
916 #define elf_backend_symbol_processing \
917 elf64_sparc_symbol_processing
918 #define elf_backend_print_symbol_all \
919 elf64_sparc_print_symbol_all
920 #define elf_backend_output_arch_syms \
921 elf64_sparc_output_arch_syms
922 #define bfd_elf64_bfd_merge_private_bfd_data \
923 elf64_sparc_merge_private_bfd_data
924 #define elf_backend_fake_sections \
925 elf64_sparc_fake_sections
926 #define elf_backend_size_info \
927 elf64_sparc_size_info
929 #define elf_backend_plt_sym_val \
930 _bfd_sparc_elf_plt_sym_val
931 #define bfd_elf64_bfd_link_hash_table_create \
932 _bfd_sparc_elf_link_hash_table_create
933 #define elf_info_to_howto \
934 _bfd_sparc_elf_info_to_howto
935 #define elf_backend_copy_indirect_symbol \
936 _bfd_sparc_elf_copy_indirect_symbol
937 #define bfd_elf64_bfd_reloc_type_lookup \
938 _bfd_sparc_elf_reloc_type_lookup
939 #define bfd_elf64_bfd_reloc_name_lookup \
940 _bfd_sparc_elf_reloc_name_lookup
941 #define bfd_elf64_bfd_relax_section \
942 _bfd_sparc_elf_relax_section
943 #define bfd_elf64_new_section_hook \
944 _bfd_sparc_elf_new_section_hook
946 #define elf_backend_create_dynamic_sections \
947 _bfd_sparc_elf_create_dynamic_sections
948 #define elf_backend_relocs_compatible \
949 _bfd_elf_relocs_compatible
950 #define elf_backend_check_relocs \
951 _bfd_sparc_elf_check_relocs
952 #define elf_backend_adjust_dynamic_symbol \
953 _bfd_sparc_elf_adjust_dynamic_symbol
954 #define elf_backend_omit_section_dynsym \
955 _bfd_sparc_elf_omit_section_dynsym
956 #define elf_backend_size_dynamic_sections \
957 _bfd_sparc_elf_size_dynamic_sections
958 #define elf_backend_relocate_section \
959 _bfd_sparc_elf_relocate_section
960 #define elf_backend_finish_dynamic_symbol \
961 _bfd_sparc_elf_finish_dynamic_symbol
962 #define elf_backend_finish_dynamic_sections \
963 _bfd_sparc_elf_finish_dynamic_sections
964 #define elf_backend_fixup_symbol \
965 _bfd_sparc_elf_fixup_symbol
967 #define bfd_elf64_mkobject \
968 _bfd_sparc_elf_mkobject
969 #define elf_backend_object_p \
970 _bfd_sparc_elf_object_p
971 #define elf_backend_gc_mark_hook \
972 _bfd_sparc_elf_gc_mark_hook
973 #define elf_backend_init_index_section \
974 _bfd_elf_init_1_index_section
976 #define elf_backend_can_gc_sections 1
977 #define elf_backend_can_refcount 1
978 #define elf_backend_want_got_plt 0
979 #define elf_backend_plt_readonly 0
980 #define elf_backend_want_plt_sym 1
981 #define elf_backend_got_header_size 8
982 #define elf_backend_want_dynrelro 1
983 #define elf_backend_rela_normal 1
985 /* Section 5.2.4 of the ABI specifies a 256-byte boundary for the table. */
986 #define elf_backend_plt_alignment 8
988 #include "elf64-target.h"
990 /* FreeBSD support */
991 #undef TARGET_BIG_SYM
992 #define TARGET_BIG_SYM sparc_elf64_fbsd_vec
993 #undef TARGET_BIG_NAME
994 #define TARGET_BIG_NAME "elf64-sparc-freebsd"
996 #define ELF_OSABI ELFOSABI_FREEBSD
999 #define elf64_bed elf64_sparc_fbsd_bed
1001 #include "elf64-target.h"
1005 #undef TARGET_BIG_SYM
1006 #define TARGET_BIG_SYM sparc_elf64_sol2_vec
1007 #undef TARGET_BIG_NAME
1008 #define TARGET_BIG_NAME "elf64-sparc-sol2"
1010 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
1011 objects won't be recognized. */
1015 #define elf64_bed elf64_sparc_sol2_bed
1017 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
1019 #undef elf_backend_static_tls_alignment
1020 #define elf_backend_static_tls_alignment 16
1022 #undef elf_backend_strtab_flags
1023 #define elf_backend_strtab_flags SHF_STRINGS
1026 elf64_sparc_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
1027 bfd
*obfd ATTRIBUTE_UNUSED
,
1028 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
1029 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
1031 /* PR 19938: FIXME: Need to add code for setting the sh_info
1032 and sh_link fields of Solaris specific section types. */
1036 #undef elf_backend_copy_special_section_fields
1037 #define elf_backend_copy_special_section_fields elf64_sparc_copy_solaris_special_section_fields
1039 #include "elf64-target.h"
1041 #undef elf_backend_strtab_flags
1042 #undef elf_backend_copy_special_section_fields