1 /* SPARC-specific support for 64-bit ELF
2 Copyright (C) 1993-2019 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
37 #if GCC_VERSION >= 4003
38 # pragma GCC diagnostic push
39 # pragma GCC diagnostic ignored "-Wtype-limits"
42 elf64_sparc_get_reloc_upper_bound (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
)
44 if (sec
->reloc_count
>= LONG_MAX
/ 2 / sizeof (arelent
*))
46 bfd_set_error (bfd_error_file_too_big
);
49 return (sec
->reloc_count
* 2 + 1) * sizeof (arelent
*);
51 #if GCC_VERSION >= 4003
52 # pragma GCC diagnostic pop
56 elf64_sparc_get_dynamic_reloc_upper_bound (bfd
*abfd
)
58 long ret
= _bfd_elf_get_dynamic_reloc_upper_bound (abfd
);
59 if (ret
> LONG_MAX
/ 2)
61 bfd_set_error (bfd_error_file_too_big
);
69 /* Read relocations for ASECT from REL_HDR. There are RELOC_COUNT of
70 them. We cannot use generic elf routines for this, because R_SPARC_OLO10
71 has secondary addend in ELF64_R_TYPE_DATA. We handle it as two relocations
72 for the same location, R_SPARC_LO10 and R_SPARC_13. */
75 elf64_sparc_slurp_one_reloc_table (bfd
*abfd
, asection
*asect
,
76 Elf_Internal_Shdr
*rel_hdr
,
77 asymbol
**symbols
, bfd_boolean dynamic
)
79 void * allocated
= NULL
;
80 bfd_byte
*native_relocs
;
87 allocated
= bfd_malloc (rel_hdr
->sh_size
);
88 if (allocated
== NULL
)
91 if (bfd_seek (abfd
, rel_hdr
->sh_offset
, SEEK_SET
) != 0
92 || bfd_bread (allocated
, rel_hdr
->sh_size
, abfd
) != rel_hdr
->sh_size
)
95 native_relocs
= (bfd_byte
*) allocated
;
97 relents
= asect
->relocation
+ canon_reloc_count (asect
);
99 entsize
= rel_hdr
->sh_entsize
;
100 BFD_ASSERT (entsize
== sizeof (Elf64_External_Rela
));
102 count
= rel_hdr
->sh_size
/ entsize
;
104 for (i
= 0, relent
= relents
; i
< count
;
105 i
++, relent
++, native_relocs
+= entsize
)
107 Elf_Internal_Rela rela
;
110 bfd_elf64_swap_reloca_in (abfd
, native_relocs
, &rela
);
112 /* The address of an ELF reloc is section relative for an object
113 file, and absolute for an executable file or shared library.
114 The address of a normal BFD reloc is always section relative,
115 and the address of a dynamic reloc is absolute.. */
116 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0 || dynamic
)
117 relent
->address
= rela
.r_offset
;
119 relent
->address
= rela
.r_offset
- asect
->vma
;
121 if (ELF64_R_SYM (rela
.r_info
) == STN_UNDEF
)
122 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
123 else if (/* PR 17512: file: 996185f8. */
124 (!dynamic
&& ELF64_R_SYM(rela
.r_info
) > bfd_get_symcount(abfd
))
126 && ELF64_R_SYM(rela
.r_info
) > bfd_get_dynamic_symcount(abfd
)))
129 /* xgettext:c-format */
130 (_("%pB(%pA): relocation %d has invalid symbol index %ld"),
131 abfd
, asect
, i
, (long) ELF64_R_SYM (rela
.r_info
));
132 bfd_set_error (bfd_error_bad_value
);
133 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
139 ps
= symbols
+ ELF64_R_SYM (rela
.r_info
) - 1;
142 /* Canonicalize ELF section symbols. FIXME: Why? */
143 if ((s
->flags
& BSF_SECTION_SYM
) == 0)
144 relent
->sym_ptr_ptr
= ps
;
146 relent
->sym_ptr_ptr
= s
->section
->symbol_ptr_ptr
;
149 relent
->addend
= rela
.r_addend
;
151 r_type
= ELF64_R_TYPE_ID (rela
.r_info
);
152 if (r_type
== R_SPARC_OLO10
)
154 relent
->howto
= _bfd_sparc_elf_info_to_howto_ptr (abfd
, R_SPARC_LO10
);
155 relent
[1].address
= relent
->address
;
157 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
158 relent
->addend
= ELF64_R_TYPE_DATA (rela
.r_info
);
159 relent
->howto
= _bfd_sparc_elf_info_to_howto_ptr (abfd
, R_SPARC_13
);
163 relent
->howto
= _bfd_sparc_elf_info_to_howto_ptr (abfd
, r_type
);
164 if (relent
->howto
== NULL
)
169 canon_reloc_count (asect
) += relent
- relents
;
171 if (allocated
!= NULL
)
177 if (allocated
!= NULL
)
182 /* Read in and swap the external relocs. */
185 elf64_sparc_slurp_reloc_table (bfd
*abfd
, asection
*asect
,
186 asymbol
**symbols
, bfd_boolean dynamic
)
188 struct bfd_elf_section_data
* const d
= elf_section_data (asect
);
189 Elf_Internal_Shdr
*rel_hdr
;
190 Elf_Internal_Shdr
*rel_hdr2
;
193 if (asect
->relocation
!= NULL
)
198 if ((asect
->flags
& SEC_RELOC
) == 0
199 || asect
->reloc_count
== 0)
202 rel_hdr
= d
->rel
.hdr
;
203 rel_hdr2
= d
->rela
.hdr
;
205 BFD_ASSERT ((rel_hdr
&& asect
->rel_filepos
== rel_hdr
->sh_offset
)
206 || (rel_hdr2
&& asect
->rel_filepos
== rel_hdr2
->sh_offset
));
210 /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
211 case because relocations against this section may use the
212 dynamic symbol table, and in that case bfd_section_from_shdr
213 in elf.c does not update the RELOC_COUNT. */
214 if (asect
->size
== 0)
217 rel_hdr
= &d
->this_hdr
;
218 asect
->reloc_count
= NUM_SHDR_ENTRIES (rel_hdr
);
222 amt
= asect
->reloc_count
;
223 amt
*= 2 * sizeof (arelent
);
224 asect
->relocation
= (arelent
*) bfd_alloc (abfd
, amt
);
225 if (asect
->relocation
== NULL
)
228 /* The elf64_sparc_slurp_one_reloc_table routine increments
229 canon_reloc_count. */
230 canon_reloc_count (asect
) = 0;
233 && !elf64_sparc_slurp_one_reloc_table (abfd
, asect
, rel_hdr
, symbols
,
238 && !elf64_sparc_slurp_one_reloc_table (abfd
, asect
, rel_hdr2
, symbols
,
245 /* Canonicalize the relocs. */
248 elf64_sparc_canonicalize_reloc (bfd
*abfd
, sec_ptr section
,
249 arelent
**relptr
, asymbol
**symbols
)
253 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
255 if (! bed
->s
->slurp_reloc_table (abfd
, section
, symbols
, FALSE
))
258 tblptr
= section
->relocation
;
259 for (i
= 0; i
< canon_reloc_count (section
); i
++)
260 *relptr
++ = tblptr
++;
264 return canon_reloc_count (section
);
268 /* Canonicalize the dynamic relocation entries. Note that we return
269 the dynamic relocations as a single block, although they are
270 actually associated with particular sections; the interface, which
271 was designed for SunOS style shared libraries, expects that there
272 is only one set of dynamic relocs. Any section that was actually
273 installed in the BFD, and has type SHT_REL or SHT_RELA, and uses
274 the dynamic symbol table, is considered to be a dynamic reloc
278 elf64_sparc_canonicalize_dynamic_reloc (bfd
*abfd
, arelent
**storage
,
284 if (elf_dynsymtab (abfd
) == 0)
286 bfd_set_error (bfd_error_invalid_operation
);
291 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
293 if (elf_section_data (s
)->this_hdr
.sh_link
== elf_dynsymtab (abfd
)
294 && (elf_section_data (s
)->this_hdr
.sh_type
== SHT_RELA
))
299 if (! elf64_sparc_slurp_reloc_table (abfd
, s
, syms
, TRUE
))
301 count
= canon_reloc_count (s
);
303 for (i
= 0; i
< count
; i
++)
314 /* Install a new set of internal relocs. */
317 elf64_sparc_set_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
322 asect
->orelocation
= location
;
323 canon_reloc_count (asect
) = count
;
326 /* Write out the relocs. */
329 elf64_sparc_write_relocs (bfd
*abfd
, asection
*sec
, void * data
)
331 bfd_boolean
*failedp
= (bfd_boolean
*) data
;
332 Elf_Internal_Shdr
*rela_hdr
;
334 Elf64_External_Rela
*outbound_relocas
, *src_rela
;
335 unsigned int idx
, count
;
336 asymbol
*last_sym
= 0;
337 int last_sym_idx
= 0;
339 /* If we have already failed, don't do anything. */
343 if ((sec
->flags
& SEC_RELOC
) == 0)
346 /* The linker backend writes the relocs out itself, and sets the
347 reloc_count field to zero to inhibit writing them here. Also,
348 sometimes the SEC_RELOC flag gets set even when there aren't any
350 if (canon_reloc_count (sec
) == 0)
353 /* We can combine two relocs that refer to the same address
354 into R_SPARC_OLO10 if first one is R_SPARC_LO10 and the
355 latter is R_SPARC_13 with no associated symbol. */
357 for (idx
= 0; idx
< canon_reloc_count (sec
); idx
++)
363 addr
= sec
->orelocation
[idx
]->address
;
364 if (sec
->orelocation
[idx
]->howto
->type
== R_SPARC_LO10
365 && idx
< canon_reloc_count (sec
) - 1)
367 arelent
*r
= sec
->orelocation
[idx
+ 1];
369 if (r
->howto
->type
== R_SPARC_13
370 && r
->address
== addr
371 && bfd_is_abs_section ((*r
->sym_ptr_ptr
)->section
)
372 && (*r
->sym_ptr_ptr
)->value
== 0)
377 rela_hdr
= elf_section_data (sec
)->rela
.hdr
;
379 rela_hdr
->sh_size
= rela_hdr
->sh_entsize
* count
;
380 rela_hdr
->contents
= bfd_alloc (abfd
, rela_hdr
->sh_size
);
381 if (rela_hdr
->contents
== NULL
)
387 /* Figure out whether the relocations are RELA or REL relocations. */
388 if (rela_hdr
->sh_type
!= SHT_RELA
)
391 /* The address of an ELF reloc is section relative for an object
392 file, and absolute for an executable file or shared library.
393 The address of a BFD reloc is always section relative. */
395 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
396 addr_offset
= sec
->vma
;
398 /* orelocation has the data, reloc_count has the count... */
399 outbound_relocas
= (Elf64_External_Rela
*) rela_hdr
->contents
;
400 src_rela
= outbound_relocas
;
402 for (idx
= 0; idx
< canon_reloc_count (sec
); idx
++)
404 Elf_Internal_Rela dst_rela
;
409 ptr
= sec
->orelocation
[idx
];
410 sym
= *ptr
->sym_ptr_ptr
;
413 else if (bfd_is_abs_section (sym
->section
) && sym
->value
== 0)
418 n
= _bfd_elf_symbol_from_bfd_symbol (abfd
, &sym
);
427 if ((*ptr
->sym_ptr_ptr
)->the_bfd
!= NULL
428 && (*ptr
->sym_ptr_ptr
)->the_bfd
->xvec
!= abfd
->xvec
429 && ! _bfd_elf_validate_reloc (abfd
, ptr
))
435 if (ptr
->howto
->type
== R_SPARC_LO10
436 && idx
< canon_reloc_count (sec
) - 1)
438 arelent
*r
= sec
->orelocation
[idx
+ 1];
440 if (r
->howto
->type
== R_SPARC_13
441 && r
->address
== ptr
->address
442 && bfd_is_abs_section ((*r
->sym_ptr_ptr
)->section
)
443 && (*r
->sym_ptr_ptr
)->value
== 0)
447 = ELF64_R_INFO (n
, ELF64_R_TYPE_INFO (r
->addend
,
451 dst_rela
.r_info
= ELF64_R_INFO (n
, R_SPARC_LO10
);
454 dst_rela
.r_info
= ELF64_R_INFO (n
, ptr
->howto
->type
);
456 dst_rela
.r_offset
= ptr
->address
+ addr_offset
;
457 dst_rela
.r_addend
= ptr
->addend
;
459 bfd_elf64_swap_reloca_out (abfd
, &dst_rela
, (bfd_byte
*) src_rela
);
464 /* Hook called by the linker routine which adds symbols from an object
465 file. We use it for STT_REGISTER symbols. */
468 elf64_sparc_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
469 Elf_Internal_Sym
*sym
, const char **namep
,
470 flagword
*flagsp ATTRIBUTE_UNUSED
,
471 asection
**secp ATTRIBUTE_UNUSED
,
472 bfd_vma
*valp ATTRIBUTE_UNUSED
)
474 static const char *const stt_types
[] = { "NOTYPE", "OBJECT", "FUNCTION" };
476 if (ELF_ST_TYPE (sym
->st_info
) == STT_REGISTER
)
479 struct _bfd_sparc_elf_app_reg
*p
;
481 reg
= (int)sym
->st_value
;
484 case 2: reg
-= 2; break;
485 case 6: reg
-= 4; break;
488 (_("%pB: only registers %%g[2367] can be declared using STT_REGISTER"),
493 if (info
->output_bfd
->xvec
!= abfd
->xvec
494 || (abfd
->flags
& DYNAMIC
) != 0)
496 /* STT_REGISTER only works when linking an elf64_sparc object.
497 If STT_REGISTER comes from a dynamic object, don't put it into
498 the output bfd. The dynamic linker will recheck it. */
503 p
= _bfd_sparc_elf_hash_table(info
)->app_regs
+ reg
;
505 if (p
->name
!= NULL
&& strcmp (p
->name
, *namep
))
508 /* xgettext:c-format */
509 (_("register %%g%d used incompatibly: %s in %pB,"
510 " previously %s in %pB"),
511 (int) sym
->st_value
, **namep
? *namep
: "#scratch", abfd
,
512 *p
->name
? p
->name
: "#scratch", p
->abfd
);
520 struct elf_link_hash_entry
*h
;
522 h
= (struct elf_link_hash_entry
*)
523 bfd_link_hash_lookup (info
->hash
, *namep
, FALSE
, FALSE
, FALSE
);
527 unsigned char type
= h
->type
;
532 /* xgettext:c-format */
533 (_("symbol `%s' has differing types: REGISTER in %pB,"
534 " previously %s in %pB"),
535 *namep
, abfd
, stt_types
[type
], p
->abfd
);
539 p
->name
= bfd_hash_allocate (&info
->hash
->table
,
540 strlen (*namep
) + 1);
544 strcpy (p
->name
, *namep
);
548 p
->bind
= ELF_ST_BIND (sym
->st_info
);
550 p
->shndx
= sym
->st_shndx
;
554 if (p
->bind
== STB_WEAK
555 && ELF_ST_BIND (sym
->st_info
) == STB_GLOBAL
)
557 p
->bind
= STB_GLOBAL
;
564 else if (*namep
&& **namep
565 && info
->output_bfd
->xvec
== abfd
->xvec
)
568 struct _bfd_sparc_elf_app_reg
*p
;
570 p
= _bfd_sparc_elf_hash_table(info
)->app_regs
;
571 for (i
= 0; i
< 4; i
++, p
++)
572 if (p
->name
!= NULL
&& ! strcmp (p
->name
, *namep
))
574 unsigned char type
= ELF_ST_TYPE (sym
->st_info
);
579 /* xgettext:c-format */
580 (_("Symbol `%s' has differing types: %s in %pB,"
581 " previously REGISTER in %pB"),
582 *namep
, stt_types
[type
], abfd
, p
->abfd
);
589 /* This function takes care of emitting STT_REGISTER symbols
590 which we cannot easily keep in the symbol hash table. */
593 elf64_sparc_output_arch_syms (bfd
*output_bfd ATTRIBUTE_UNUSED
,
594 struct bfd_link_info
*info
,
596 int (*func
) (void *, const char *,
599 struct elf_link_hash_entry
*))
602 struct _bfd_sparc_elf_app_reg
*app_regs
=
603 _bfd_sparc_elf_hash_table(info
)->app_regs
;
604 Elf_Internal_Sym sym
;
606 for (reg
= 0; reg
< 4; reg
++)
607 if (app_regs
[reg
].name
!= NULL
)
609 if (info
->strip
== strip_some
610 && bfd_hash_lookup (info
->keep_hash
,
612 FALSE
, FALSE
) == NULL
)
615 sym
.st_value
= reg
< 2 ? reg
+ 2 : reg
+ 4;
618 sym
.st_info
= ELF_ST_INFO (app_regs
[reg
].bind
, STT_REGISTER
);
619 sym
.st_shndx
= app_regs
[reg
].shndx
;
620 sym
.st_target_internal
= 0;
621 if ((*func
) (flaginfo
, app_regs
[reg
].name
, &sym
,
622 sym
.st_shndx
== SHN_ABS
623 ? bfd_abs_section_ptr
: bfd_und_section_ptr
,
632 elf64_sparc_get_symbol_type (Elf_Internal_Sym
*elf_sym
, int type
)
634 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_REGISTER
)
640 /* A STB_GLOBAL,STT_REGISTER symbol should be BSF_GLOBAL
641 even in SHN_UNDEF section. */
644 elf64_sparc_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*asym
)
646 elf_symbol_type
*elfsym
;
648 elfsym
= (elf_symbol_type
*) asym
;
649 if (elfsym
->internal_elf_sym
.st_info
650 == ELF_ST_INFO (STB_GLOBAL
, STT_REGISTER
))
652 asym
->flags
|= BSF_GLOBAL
;
657 /* Functions for dealing with the e_flags field. */
659 /* Merge backend specific data from an object file to the output
660 object file when linking. */
663 elf64_sparc_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
665 bfd
*obfd
= info
->output_bfd
;
667 flagword new_flags
, old_flags
;
670 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
671 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
674 new_flags
= elf_elfheader (ibfd
)->e_flags
;
675 old_flags
= elf_elfheader (obfd
)->e_flags
;
677 if (!elf_flags_init (obfd
)) /* First call, no flags set */
679 elf_flags_init (obfd
) = TRUE
;
680 elf_elfheader (obfd
)->e_flags
= new_flags
;
683 else if (new_flags
== old_flags
) /* Compatible flags are ok */
686 else /* Incompatible flags */
690 #define EF_SPARC_ISA_EXTENSIONS \
691 (EF_SPARC_SUN_US1 | EF_SPARC_SUN_US3 | EF_SPARC_HAL_R1)
693 if ((ibfd
->flags
& DYNAMIC
) != 0)
695 /* We don't want dynamic objects memory ordering and
696 architecture to have any role. That's what dynamic linker
698 new_flags
&= ~(EF_SPARCV9_MM
| EF_SPARC_ISA_EXTENSIONS
);
699 new_flags
|= (old_flags
700 & (EF_SPARCV9_MM
| EF_SPARC_ISA_EXTENSIONS
));
704 /* Choose the highest architecture requirements. */
705 old_flags
|= (new_flags
& EF_SPARC_ISA_EXTENSIONS
);
706 new_flags
|= (old_flags
& EF_SPARC_ISA_EXTENSIONS
);
707 if ((old_flags
& (EF_SPARC_SUN_US1
| EF_SPARC_SUN_US3
))
708 && (old_flags
& EF_SPARC_HAL_R1
))
712 (_("%pB: linking UltraSPARC specific with HAL specific code"),
715 /* Choose the most restrictive memory ordering. */
716 old_mm
= (old_flags
& EF_SPARCV9_MM
);
717 new_mm
= (new_flags
& EF_SPARCV9_MM
);
718 old_flags
&= ~EF_SPARCV9_MM
;
719 new_flags
&= ~EF_SPARCV9_MM
;
726 /* Warn about any other mismatches */
727 if (new_flags
!= old_flags
)
731 /* xgettext:c-format */
732 (_("%pB: uses different e_flags (%#x) fields than previous modules (%#x)"),
733 ibfd
, new_flags
, old_flags
);
736 elf_elfheader (obfd
)->e_flags
= old_flags
;
740 bfd_set_error (bfd_error_bad_value
);
744 return _bfd_sparc_elf_merge_private_bfd_data (ibfd
, info
);
747 /* MARCO: Set the correct entry size for the .stab section. */
750 elf64_sparc_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
751 Elf_Internal_Shdr
*hdr ATTRIBUTE_UNUSED
,
756 name
= bfd_get_section_name (abfd
, sec
);
758 if (strcmp (name
, ".stab") == 0)
760 /* Even in the 64bit case the stab entries are only 12 bytes long. */
761 elf_section_data (sec
)->this_hdr
.sh_entsize
= 12;
767 /* Print a STT_REGISTER symbol to file FILE. */
770 elf64_sparc_print_symbol_all (bfd
*abfd ATTRIBUTE_UNUSED
, void * filep
,
773 FILE *file
= (FILE *) filep
;
776 if (ELF_ST_TYPE (((elf_symbol_type
*) symbol
)->internal_elf_sym
.st_info
)
780 reg
= ((elf_symbol_type
*) symbol
)->internal_elf_sym
.st_value
;
781 type
= symbol
->flags
;
782 fprintf (file
, "REG_%c%c%11s%c%c R", "GOLI" [reg
/ 8], '0' + (reg
& 7), "",
784 ? (type
& BSF_GLOBAL
) ? '!' : 'l'
785 : (type
& BSF_GLOBAL
) ? 'g' : ' '),
786 (type
& BSF_WEAK
) ? 'w' : ' ');
787 if (symbol
->name
== NULL
|| symbol
->name
[0] == '\0')
793 /* Used to decide how to sort relocs in an optimal manner for the
794 dynamic linker, before writing them out. */
796 static enum elf_reloc_type_class
797 elf64_sparc_reloc_type_class (const struct bfd_link_info
*info
,
798 const asection
*rel_sec ATTRIBUTE_UNUSED
,
799 const Elf_Internal_Rela
*rela
)
801 bfd
*abfd
= info
->output_bfd
;
802 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
803 struct _bfd_sparc_elf_link_hash_table
*htab
804 = _bfd_sparc_elf_hash_table (info
);
805 BFD_ASSERT (htab
!= NULL
);
807 if (htab
->elf
.dynsym
!= NULL
808 && htab
->elf
.dynsym
->contents
!= NULL
)
810 /* Check relocation against STT_GNU_IFUNC symbol if there are
812 unsigned long r_symndx
= htab
->r_symndx (rela
->r_info
);
813 if (r_symndx
!= STN_UNDEF
)
815 Elf_Internal_Sym sym
;
816 if (!bed
->s
->swap_symbol_in (abfd
,
817 (htab
->elf
.dynsym
->contents
818 + r_symndx
* bed
->s
->sizeof_sym
),
822 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
823 return reloc_class_ifunc
;
827 switch ((int) ELF64_R_TYPE (rela
->r_info
))
829 case R_SPARC_IRELATIVE
:
830 return reloc_class_ifunc
;
831 case R_SPARC_RELATIVE
:
832 return reloc_class_relative
;
833 case R_SPARC_JMP_SLOT
:
834 return reloc_class_plt
;
836 return reloc_class_copy
;
838 return reloc_class_normal
;
842 /* Relocations in the 64 bit SPARC ELF ABI are more complex than in
843 standard ELF, because R_SPARC_OLO10 has secondary addend in
844 ELF64_R_TYPE_DATA field. This structure is used to redirect the
845 relocation handling routines. */
847 const struct elf_size_info elf64_sparc_size_info
=
849 sizeof (Elf64_External_Ehdr
),
850 sizeof (Elf64_External_Phdr
),
851 sizeof (Elf64_External_Shdr
),
852 sizeof (Elf64_External_Rel
),
853 sizeof (Elf64_External_Rela
),
854 sizeof (Elf64_External_Sym
),
855 sizeof (Elf64_External_Dyn
),
856 sizeof (Elf_External_Note
),
857 4, /* hash-table entry size. */
858 /* Internal relocations per external relocations.
859 For link purposes we use just 1 internal per
860 1 external, for assembly and slurp symbol table
864 3, /* log_file_align. */
867 bfd_elf64_write_out_phdrs
,
868 bfd_elf64_write_shdrs_and_ehdr
,
869 bfd_elf64_checksum_contents
,
870 elf64_sparc_write_relocs
,
871 bfd_elf64_swap_symbol_in
,
872 bfd_elf64_swap_symbol_out
,
873 elf64_sparc_slurp_reloc_table
,
874 bfd_elf64_slurp_symbol_table
,
875 bfd_elf64_swap_dyn_in
,
876 bfd_elf64_swap_dyn_out
,
877 bfd_elf64_swap_reloc_in
,
878 bfd_elf64_swap_reloc_out
,
879 bfd_elf64_swap_reloca_in
,
880 bfd_elf64_swap_reloca_out
883 #define TARGET_BIG_SYM sparc_elf64_vec
884 #define TARGET_BIG_NAME "elf64-sparc"
885 #define ELF_ARCH bfd_arch_sparc
886 #define ELF_MAXPAGESIZE 0x100000
887 #define ELF_COMMONPAGESIZE 0x2000
889 /* This is the official ABI value. */
890 #define ELF_MACHINE_CODE EM_SPARCV9
892 /* This is the value that we used before the ABI was released. */
893 #define ELF_MACHINE_ALT1 EM_OLD_SPARCV9
895 #define elf_backend_reloc_type_class \
896 elf64_sparc_reloc_type_class
897 #define bfd_elf64_get_reloc_upper_bound \
898 elf64_sparc_get_reloc_upper_bound
899 #define bfd_elf64_get_dynamic_reloc_upper_bound \
900 elf64_sparc_get_dynamic_reloc_upper_bound
901 #define bfd_elf64_canonicalize_reloc \
902 elf64_sparc_canonicalize_reloc
903 #define bfd_elf64_canonicalize_dynamic_reloc \
904 elf64_sparc_canonicalize_dynamic_reloc
905 #define bfd_elf64_set_reloc \
906 elf64_sparc_set_reloc
907 #define elf_backend_add_symbol_hook \
908 elf64_sparc_add_symbol_hook
909 #define elf_backend_get_symbol_type \
910 elf64_sparc_get_symbol_type
911 #define elf_backend_symbol_processing \
912 elf64_sparc_symbol_processing
913 #define elf_backend_print_symbol_all \
914 elf64_sparc_print_symbol_all
915 #define elf_backend_output_arch_syms \
916 elf64_sparc_output_arch_syms
917 #define bfd_elf64_bfd_merge_private_bfd_data \
918 elf64_sparc_merge_private_bfd_data
919 #define elf_backend_fake_sections \
920 elf64_sparc_fake_sections
921 #define elf_backend_size_info \
922 elf64_sparc_size_info
924 #define elf_backend_plt_sym_val \
925 _bfd_sparc_elf_plt_sym_val
926 #define bfd_elf64_bfd_link_hash_table_create \
927 _bfd_sparc_elf_link_hash_table_create
928 #define elf_info_to_howto \
929 _bfd_sparc_elf_info_to_howto
930 #define elf_backend_copy_indirect_symbol \
931 _bfd_sparc_elf_copy_indirect_symbol
932 #define bfd_elf64_bfd_reloc_type_lookup \
933 _bfd_sparc_elf_reloc_type_lookup
934 #define bfd_elf64_bfd_reloc_name_lookup \
935 _bfd_sparc_elf_reloc_name_lookup
936 #define bfd_elf64_bfd_relax_section \
937 _bfd_sparc_elf_relax_section
938 #define bfd_elf64_new_section_hook \
939 _bfd_sparc_elf_new_section_hook
941 #define elf_backend_create_dynamic_sections \
942 _bfd_sparc_elf_create_dynamic_sections
943 #define elf_backend_relocs_compatible \
944 _bfd_elf_relocs_compatible
945 #define elf_backend_check_relocs \
946 _bfd_sparc_elf_check_relocs
947 #define elf_backend_adjust_dynamic_symbol \
948 _bfd_sparc_elf_adjust_dynamic_symbol
949 #define elf_backend_omit_section_dynsym \
950 _bfd_sparc_elf_omit_section_dynsym
951 #define elf_backend_size_dynamic_sections \
952 _bfd_sparc_elf_size_dynamic_sections
953 #define elf_backend_relocate_section \
954 _bfd_sparc_elf_relocate_section
955 #define elf_backend_finish_dynamic_symbol \
956 _bfd_sparc_elf_finish_dynamic_symbol
957 #define elf_backend_finish_dynamic_sections \
958 _bfd_sparc_elf_finish_dynamic_sections
959 #define elf_backend_fixup_symbol \
960 _bfd_sparc_elf_fixup_symbol
962 #define bfd_elf64_mkobject \
963 _bfd_sparc_elf_mkobject
964 #define elf_backend_object_p \
965 _bfd_sparc_elf_object_p
966 #define elf_backend_gc_mark_hook \
967 _bfd_sparc_elf_gc_mark_hook
968 #define elf_backend_init_index_section \
969 _bfd_elf_init_1_index_section
971 #define elf_backend_can_gc_sections 1
972 #define elf_backend_can_refcount 1
973 #define elf_backend_want_got_plt 0
974 #define elf_backend_plt_readonly 0
975 #define elf_backend_want_plt_sym 1
976 #define elf_backend_got_header_size 8
977 #define elf_backend_want_dynrelro 1
978 #define elf_backend_rela_normal 1
980 /* Section 5.2.4 of the ABI specifies a 256-byte boundary for the table. */
981 #define elf_backend_plt_alignment 8
983 #include "elf64-target.h"
985 /* FreeBSD support */
986 #undef TARGET_BIG_SYM
987 #define TARGET_BIG_SYM sparc_elf64_fbsd_vec
988 #undef TARGET_BIG_NAME
989 #define TARGET_BIG_NAME "elf64-sparc-freebsd"
991 #define ELF_OSABI ELFOSABI_FREEBSD
994 #define elf64_bed elf64_sparc_fbsd_bed
996 #include "elf64-target.h"
1000 #undef TARGET_BIG_SYM
1001 #define TARGET_BIG_SYM sparc_elf64_sol2_vec
1002 #undef TARGET_BIG_NAME
1003 #define TARGET_BIG_NAME "elf64-sparc-sol2"
1005 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
1006 objects won't be recognized. */
1010 #define elf64_bed elf64_sparc_sol2_bed
1012 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
1014 #undef elf_backend_static_tls_alignment
1015 #define elf_backend_static_tls_alignment 16
1017 #include "elf64-target.h"