1 /* SPARC-specific support for 32-bit ELF
2 Copyright (C) 1993, 1994, 1995, 1996 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 /* start-sanitize-v8plus */
26 #include "elf/sparc.h"
27 /* end-sanitize-v8plus */
29 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
30 PARAMS ((bfd *, bfd_reloc_code_real_type));
31 static void elf_info_to_howto
32 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
33 static boolean elf32_sparc_check_relocs
34 PARAMS ((bfd *, struct bfd_link_info *, asection *,
35 const Elf_Internal_Rela *));
36 static boolean elf32_sparc_adjust_dynamic_symbol
37 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
38 static boolean elf32_sparc_adjust_dynindx
39 PARAMS ((struct elf_link_hash_entry *, PTR));
40 static boolean elf32_sparc_size_dynamic_sections
41 PARAMS ((bfd *, struct bfd_link_info *));
42 static boolean elf32_sparc_relocate_section
43 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
44 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
45 static boolean elf32_sparc_finish_dynamic_symbol
46 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
48 static boolean elf32_sparc_finish_dynamic_sections
49 PARAMS ((bfd *, struct bfd_link_info *));
50 /* start-sanitize-v8plus */
51 static boolean elf32_sparc_set_private_flags PARAMS ((bfd *, flagword));
52 static boolean elf32_sparc_copy_private_bfd_data PARAMS ((bfd *, bfd *));
53 static boolean elf32_sparc_merge_private_bfd_data PARAMS ((bfd *, bfd *));
54 static boolean elf32_sparc_object_p
56 static void elf32_sparc_final_write_processing
57 PARAMS ((bfd *, boolean));
58 /* end-sanitize-v8plus */
63 R_SPARC_8, R_SPARC_16, R_SPARC_32,
64 R_SPARC_DISP8, R_SPARC_DISP16, R_SPARC_DISP32,
65 R_SPARC_WDISP30, R_SPARC_WDISP22,
66 R_SPARC_HI22, R_SPARC_22,
67 R_SPARC_13, R_SPARC_LO10,
68 R_SPARC_GOT10, R_SPARC_GOT13, R_SPARC_GOT22,
69 R_SPARC_PC10, R_SPARC_PC22,
72 R_SPARC_GLOB_DAT, R_SPARC_JMP_SLOT,
79 static CONST char *CONST reloc_type_names[] =
82 "R_SPARC_8", "R_SPARC_16", "R_SPARC_32",
83 "R_SPARC_DISP8", "R_SPARC_DISP16", "R_SPARC_DISP32",
84 "R_SPARC_WDISP30", "R_SPARC_WDISP22",
85 "R_SPARC_HI22", "R_SPARC_22",
86 "R_SPARC_13", "R_SPARC_LO10",
87 "R_SPARC_GOT10", "R_SPARC_GOT13", "R_SPARC_GOT22",
88 "R_SPARC_PC10", "R_SPARC_PC22",
91 "R_SPARC_GLOB_DAT", "R_SPARC_JMP_SLOT",
97 static reloc_howto_type elf_sparc_howto_table[] =
99 HOWTO(R_SPARC_NONE, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc,"R_SPARC_NONE", false,0,0x00000000,true),
100 HOWTO(R_SPARC_8, 0,0, 8,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_8", false,0,0x000000ff,true),
101 HOWTO(R_SPARC_16, 0,1,16,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_16", false,0,0x0000ffff,true),
102 HOWTO(R_SPARC_32, 0,2,32,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_32", false,0,0xffffffff,true),
103 HOWTO(R_SPARC_DISP8, 0,0, 8,true, 0,complain_overflow_signed, bfd_elf_generic_reloc,"R_SPARC_DISP8", false,0,0x000000ff,true),
104 HOWTO(R_SPARC_DISP16, 0,1,16,true, 0,complain_overflow_signed, bfd_elf_generic_reloc,"R_SPARC_DISP16", false,0,0x0000ffff,true),
105 HOWTO(R_SPARC_DISP32, 0,2,32,true, 0,complain_overflow_signed, bfd_elf_generic_reloc,"R_SPARC_DISP32", false,0,0x00ffffff,true),
106 HOWTO(R_SPARC_WDISP30, 2,2,30,true, 0,complain_overflow_signed, bfd_elf_generic_reloc,"R_SPARC_WDISP30", false,0,0x3fffffff,true),
107 HOWTO(R_SPARC_WDISP22, 2,2,22,true, 0,complain_overflow_signed, bfd_elf_generic_reloc,"R_SPARC_WDISP22", false,0,0x003fffff,true),
108 HOWTO(R_SPARC_HI22, 10,2,22,false,0,complain_overflow_dont, bfd_elf_generic_reloc,"R_SPARC_HI22", false,0,0x003fffff,true),
109 HOWTO(R_SPARC_22, 0,2,22,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_22", false,0,0x003fffff,true),
110 HOWTO(R_SPARC_13, 0,2,13,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_13", false,0,0x00001fff,true),
111 HOWTO(R_SPARC_LO10, 0,2,10,false,0,complain_overflow_dont, bfd_elf_generic_reloc,"R_SPARC_LO10", false,0,0x000003ff,true),
112 HOWTO(R_SPARC_GOT10, 0,2,10,false,0,complain_overflow_dont, bfd_elf_generic_reloc,"R_SPARC_GOT10", false,0,0x000003ff,true),
113 HOWTO(R_SPARC_GOT13, 0,2,13,false,0,complain_overflow_signed, bfd_elf_generic_reloc,"R_SPARC_GOT13", false,0,0x00001fff,true),
114 HOWTO(R_SPARC_GOT22, 10,2,22,false,0,complain_overflow_dont, bfd_elf_generic_reloc,"R_SPARC_GOT22", false,0,0x003fffff,true),
115 HOWTO(R_SPARC_PC10, 0,2,10,true, 0,complain_overflow_dont, bfd_elf_generic_reloc,"R_SPARC_PC10", false,0,0x000003ff,true),
116 HOWTO(R_SPARC_PC22, 10,2,22,true, 0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_PC22", false,0,0x003fffff,true),
117 HOWTO(R_SPARC_WPLT30, 2,2,30,true, 0,complain_overflow_signed, bfd_elf_generic_reloc,"R_SPARC_WPLT30", false,0,0x3fffffff,true),
118 HOWTO(R_SPARC_COPY, 0,0,00,false,0,complain_overflow_dont, bfd_elf_generic_reloc,"R_SPARC_COPY", false,0,0x00000000,true),
119 HOWTO(R_SPARC_GLOB_DAT,0,0,00,false,0,complain_overflow_dont, bfd_elf_generic_reloc,"R_SPARC_GLOB_DAT",false,0,0x00000000,true),
120 HOWTO(R_SPARC_JMP_SLOT,0,0,00,false,0,complain_overflow_dont, bfd_elf_generic_reloc,"R_SPARC_JMP_SLOT",false,0,0x00000000,true),
121 HOWTO(R_SPARC_RELATIVE,0,0,00,false,0,complain_overflow_dont, bfd_elf_generic_reloc,"R_SPARC_RELATIVE",false,0,0x00000000,true),
122 HOWTO(R_SPARC_UA32, 0,0,00,false,0,complain_overflow_dont, bfd_elf_generic_reloc,"R_SPARC_UA32", false,0,0x00000000,true),
125 struct elf_reloc_map {
126 unsigned char bfd_reloc_val;
127 unsigned char elf_reloc_val;
130 static CONST struct elf_reloc_map sparc_reloc_map[] =
132 { BFD_RELOC_NONE, R_SPARC_NONE, },
133 { BFD_RELOC_16, R_SPARC_16, },
134 { BFD_RELOC_8, R_SPARC_8 },
135 { BFD_RELOC_8_PCREL, R_SPARC_DISP8 },
136 { BFD_RELOC_CTOR, R_SPARC_32 }, /* @@ Assumes 32 bits. */
137 { BFD_RELOC_32, R_SPARC_32 },
138 { BFD_RELOC_32_PCREL, R_SPARC_DISP32 },
139 { BFD_RELOC_HI22, R_SPARC_HI22 },
140 { BFD_RELOC_LO10, R_SPARC_LO10, },
141 { BFD_RELOC_32_PCREL_S2, R_SPARC_WDISP30 },
142 { BFD_RELOC_SPARC22, R_SPARC_22 },
143 { BFD_RELOC_SPARC13, R_SPARC_13 },
144 { BFD_RELOC_SPARC_GOT10, R_SPARC_GOT10 },
145 { BFD_RELOC_SPARC_GOT13, R_SPARC_GOT13 },
146 { BFD_RELOC_SPARC_GOT22, R_SPARC_GOT22 },
147 { BFD_RELOC_SPARC_PC10, R_SPARC_PC10 },
148 { BFD_RELOC_SPARC_PC22, R_SPARC_PC22 },
149 { BFD_RELOC_SPARC_WPLT30, R_SPARC_WPLT30 },
150 { BFD_RELOC_SPARC_COPY, R_SPARC_COPY },
151 { BFD_RELOC_SPARC_GLOB_DAT, R_SPARC_GLOB_DAT },
152 { BFD_RELOC_SPARC_JMP_SLOT, R_SPARC_JMP_SLOT },
153 { BFD_RELOC_SPARC_RELATIVE, R_SPARC_RELATIVE },
154 { BFD_RELOC_SPARC_WDISP22, R_SPARC_WDISP22 },
155 /*{ BFD_RELOC_SPARC_UA32, R_SPARC_UA32 }, not used?? */
158 static reloc_howto_type *
159 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
161 bfd_reloc_code_real_type code;
164 for (i = 0; i < sizeof (sparc_reloc_map) / sizeof (struct elf_reloc_map); i++)
166 if (sparc_reloc_map[i].bfd_reloc_val == code)
167 return &elf_sparc_howto_table[(int) sparc_reloc_map[i].elf_reloc_val];
173 elf_info_to_howto (abfd, cache_ptr, dst)
176 Elf_Internal_Rela *dst;
178 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_SPARC_max);
179 cache_ptr->howto = &elf_sparc_howto_table[ELF32_R_TYPE(dst->r_info)];
183 /* Functions for the SPARC ELF linker. */
185 /* The name of the dynamic interpreter. This is put in the .interp
188 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
190 /* The nop opcode we use. */
192 #define SPARC_NOP 0x01000000
194 /* The size in bytes of an entry in the procedure linkage table. */
196 #define PLT_ENTRY_SIZE 12
198 /* The first four entries in a procedure linkage table are reserved,
199 and the initial contents are unimportant (we zero them out).
200 Subsequent entries look like this. See the SVR4 ABI SPARC
201 supplement to see how this works. */
203 /* sethi %hi(.-.plt0),%g1. We fill in the address later. */
204 #define PLT_ENTRY_WORD0 0x03000000
205 /* b,a .plt0. We fill in the offset later. */
206 #define PLT_ENTRY_WORD1 0x30800000
208 #define PLT_ENTRY_WORD2 SPARC_NOP
210 /* Look through the relocs for a section during the first phase, and
211 allocate space in the global offset table or procedure linkage
215 elf32_sparc_check_relocs (abfd, info, sec, relocs)
217 struct bfd_link_info *info;
219 const Elf_Internal_Rela *relocs;
222 Elf_Internal_Shdr *symtab_hdr;
223 struct elf_link_hash_entry **sym_hashes;
224 bfd_vma *local_got_offsets;
225 const Elf_Internal_Rela *rel;
226 const Elf_Internal_Rela *rel_end;
231 if (info->relocateable)
234 dynobj = elf_hash_table (info)->dynobj;
235 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
236 sym_hashes = elf_sym_hashes (abfd);
237 local_got_offsets = elf_local_got_offsets (abfd);
243 rel_end = relocs + sec->reloc_count;
244 for (rel = relocs; rel < rel_end; rel++)
246 unsigned long r_symndx;
247 struct elf_link_hash_entry *h;
249 r_symndx = ELF32_R_SYM (rel->r_info);
250 if (r_symndx < symtab_hdr->sh_info)
253 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
255 switch (ELF32_R_TYPE (rel->r_info))
260 /* This symbol requires a global offset table entry. */
264 /* Create the .got section. */
265 elf_hash_table (info)->dynobj = dynobj = abfd;
266 if (! _bfd_elf_create_got_section (dynobj, info))
272 sgot = bfd_get_section_by_name (dynobj, ".got");
273 BFD_ASSERT (sgot != NULL);
277 && (h != NULL || info->shared))
279 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
282 srelgot = bfd_make_section (dynobj, ".rela.got");
284 || ! bfd_set_section_flags (dynobj, srelgot,
290 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
297 if (h->got_offset != (bfd_vma) -1)
299 /* We have already allocated space in the .got. */
302 h->got_offset = sgot->_raw_size;
304 /* Make sure this symbol is output as a dynamic symbol. */
305 if (h->dynindx == -1)
307 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
311 srelgot->_raw_size += sizeof (Elf32_External_Rela);
315 /* This is a global offset table entry for a local
317 if (local_got_offsets == NULL)
320 register unsigned int i;
322 size = symtab_hdr->sh_info * sizeof (bfd_vma);
323 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
324 if (local_got_offsets == NULL)
326 elf_local_got_offsets (abfd) = local_got_offsets;
327 for (i = 0; i < symtab_hdr->sh_info; i++)
328 local_got_offsets[i] = (bfd_vma) -1;
330 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
332 /* We have already allocated space in the .got. */
335 local_got_offsets[r_symndx] = sgot->_raw_size;
339 /* If we are generating a shared object, we need to
340 output a R_SPARC_RELATIVE reloc so that the
341 dynamic linker can adjust this GOT entry. */
342 srelgot->_raw_size += sizeof (Elf32_External_Rela);
346 sgot->_raw_size += 4;
351 /* This symbol requires a procedure linkage table entry. We
352 actually build the entry in adjust_dynamic_symbol,
353 because this might be a case of linking PIC code without
354 linking in any dynamic objects, in which case we don't
355 need to generate a procedure linkage table after all. */
359 /* It does not make sense to have a procedure linkage
360 table entry for a local symbol. */
361 bfd_set_error (bfd_error_bad_value);
365 /* Make sure this symbol is output as a dynamic symbol. */
366 if (h->dynindx == -1)
368 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
372 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
379 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
385 case R_SPARC_WDISP30:
386 case R_SPARC_WDISP22:
399 && (sec->flags & SEC_ALLOC) != 0)
401 /* When creating a shared object, we must copy these
402 relocs into the output file. We create a reloc
403 section in dynobj and make room for the reloc. */
408 name = (bfd_elf_string_from_elf_section
410 elf_elfheader (abfd)->e_shstrndx,
411 elf_section_data (sec)->rel_hdr.sh_name));
415 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
416 && strcmp (bfd_get_section_name (abfd, sec),
419 sreloc = bfd_get_section_by_name (dynobj, name);
422 sreloc = bfd_make_section (dynobj, name);
424 || ! bfd_set_section_flags (dynobj, sreloc,
430 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
435 sreloc->_raw_size += sizeof (Elf32_External_Rela);
448 /* Adjust a symbol defined by a dynamic object and referenced by a
449 regular object. The current definition is in some section of the
450 dynamic object, but we're not including those sections. We have to
451 change the definition to something the rest of the link can
455 elf32_sparc_adjust_dynamic_symbol (info, h)
456 struct bfd_link_info *info;
457 struct elf_link_hash_entry *h;
461 unsigned int power_of_two;
463 dynobj = elf_hash_table (info)->dynobj;
465 /* Make sure we know what is going on here. */
466 BFD_ASSERT (dynobj != NULL
467 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
468 || h->weakdef != NULL
469 || ((h->elf_link_hash_flags
470 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
471 && (h->elf_link_hash_flags
472 & ELF_LINK_HASH_REF_REGULAR) != 0
473 && (h->elf_link_hash_flags
474 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
476 /* If this is a function, put it in the procedure linkage table. We
477 will fill in the contents of the procedure linkage table later
478 (although we could actually do it here). */
479 if (h->type == STT_FUNC
480 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
482 if (! elf_hash_table (info)->dynamic_sections_created)
484 /* This case can occur if we saw a WPLT30 reloc in an input
485 file, but none of the input files were dynamic objects.
486 In such a case, we don't actually need to build a
487 procedure linkage table, and we can just do a WDISP30
489 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
493 s = bfd_get_section_by_name (dynobj, ".plt");
494 BFD_ASSERT (s != NULL);
496 /* The first four entries in .plt are reserved. */
497 if (s->_raw_size == 0)
498 s->_raw_size = 4 * PLT_ENTRY_SIZE;
500 /* The procedure linkage table has a maximum size. */
501 if (s->_raw_size >= 0x400000)
503 bfd_set_error (bfd_error_bad_value);
507 /* If this symbol is not defined in a regular file, and we are
508 not generating a shared library, then set the symbol to this
509 location in the .plt. This is required to make function
510 pointers compare as equal between the normal executable and
511 the shared library. */
513 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
515 h->root.u.def.section = s;
516 h->root.u.def.value = s->_raw_size;
519 h->plt_offset = s->_raw_size;
521 /* Make room for this entry. */
522 s->_raw_size += PLT_ENTRY_SIZE;
524 /* We also need to make an entry in the .rela.plt section. */
526 s = bfd_get_section_by_name (dynobj, ".rela.plt");
527 BFD_ASSERT (s != NULL);
528 s->_raw_size += sizeof (Elf32_External_Rela);
533 /* If this is a weak symbol, and there is a real definition, the
534 processor independent code will have arranged for us to see the
535 real definition first, and we can just use the same value. */
536 if (h->weakdef != NULL)
538 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
539 || h->weakdef->root.type == bfd_link_hash_defweak);
540 h->root.u.def.section = h->weakdef->root.u.def.section;
541 h->root.u.def.value = h->weakdef->root.u.def.value;
545 /* This is a reference to a symbol defined by a dynamic object which
546 is not a function. */
548 /* If we are creating a shared library, we must presume that the
549 only references to the symbol are via the global offset table.
550 For such cases we need not do anything here; the relocations will
551 be handled correctly by relocate_section. */
555 /* We must allocate the symbol in our .dynbss section, which will
556 become part of the .bss section of the executable. There will be
557 an entry for this symbol in the .dynsym section. The dynamic
558 object will contain position independent code, so all references
559 from the dynamic object to this symbol will go through the global
560 offset table. The dynamic linker will use the .dynsym entry to
561 determine the address it must put in the global offset table, so
562 both the dynamic object and the regular object will refer to the
563 same memory location for the variable. */
565 s = bfd_get_section_by_name (dynobj, ".dynbss");
566 BFD_ASSERT (s != NULL);
568 /* If the symbol is currently defined in the .bss section of the
569 dynamic object, then it is OK to simply initialize it to zero.
570 If the symbol is in some other section, we must generate a
571 R_SPARC_COPY reloc to tell the dynamic linker to copy the initial
572 value out of the dynamic object and into the runtime process
573 image. We need to remember the offset into the .rel.bss section
574 we are going to use. */
575 if ((h->root.u.def.section->flags & SEC_LOAD) != 0)
579 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
580 BFD_ASSERT (srel != NULL);
581 srel->_raw_size += sizeof (Elf32_External_Rela);
582 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
585 /* We need to figure out the alignment required for this symbol. I
586 have no idea how ELF linkers handle this. */
587 power_of_two = bfd_log2 (h->size);
588 if (power_of_two > 3)
591 /* Apply the required alignment. */
592 s->_raw_size = BFD_ALIGN (s->_raw_size,
593 (bfd_size_type) (1 << power_of_two));
594 if (power_of_two > bfd_get_section_alignment (dynobj, s))
596 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
600 /* Define the symbol as being at this point in the section. */
601 h->root.u.def.section = s;
602 h->root.u.def.value = s->_raw_size;
604 /* Increment the section size to make room for the symbol. */
605 s->_raw_size += h->size;
610 /* Set the sizes of the dynamic sections. */
613 elf32_sparc_size_dynamic_sections (output_bfd, info)
615 struct bfd_link_info *info;
622 dynobj = elf_hash_table (info)->dynobj;
623 BFD_ASSERT (dynobj != NULL);
625 if (elf_hash_table (info)->dynamic_sections_created)
627 /* Set the contents of the .interp section to the interpreter. */
630 s = bfd_get_section_by_name (dynobj, ".interp");
631 BFD_ASSERT (s != NULL);
632 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
633 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
636 /* Make space for the trailing nop in .plt. */
637 s = bfd_get_section_by_name (dynobj, ".plt");
638 BFD_ASSERT (s != NULL);
639 if (s->_raw_size > 0)
644 /* We may have created entries in the .rela.got section.
645 However, if we are not creating the dynamic sections, we will
646 not actually use these entries. Reset the size of .rela.got,
647 which will cause it to get stripped from the output file
649 s = bfd_get_section_by_name (dynobj, ".rela.got");
654 /* The check_relocs and adjust_dynamic_symbol entry points have
655 determined the sizes of the various dynamic sections. Allocate
659 for (s = dynobj->sections; s != NULL; s = s->next)
664 if ((s->flags & SEC_IN_MEMORY) == 0)
667 /* It's OK to base decisions on the section name, because none
668 of the dynobj section names depend upon the input files. */
669 name = bfd_get_section_name (dynobj, s);
673 if (strncmp (name, ".rela", 5) == 0)
675 if (s->_raw_size == 0)
677 /* If we don't need this section, strip it from the
678 output file. This is to handle .rela.bss and
679 .rel.plt. We must create it in
680 create_dynamic_sections, because it must be created
681 before the linker maps input sections to output
682 sections. The linker does that before
683 adjust_dynamic_symbol is called, and it is that
684 function which decides whether anything needs to go
685 into these sections. */
692 /* If this relocation section applies to a read only
693 section, then we probably need a DT_TEXTREL entry. */
694 target = bfd_get_section_by_name (output_bfd, name + 5);
696 && (target->flags & SEC_READONLY) != 0)
699 if (strcmp (name, ".rela.plt") == 0)
702 /* We use the reloc_count field as a counter if we need
703 to copy relocs into the output file. */
707 else if (strcmp (name, ".plt") != 0
708 && strcmp (name, ".got") != 0)
710 /* It's not one of our sections, so don't allocate space. */
718 for (spp = &s->output_section->owner->sections;
719 *spp != s->output_section;
722 *spp = s->output_section->next;
723 --s->output_section->owner->section_count;
728 /* Allocate memory for the section contents. */
729 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
730 if (s->contents == NULL && s->_raw_size != 0)
734 if (elf_hash_table (info)->dynamic_sections_created)
736 /* Add some entries to the .dynamic section. We fill in the
737 values later, in elf32_sparc_finish_dynamic_sections, but we
738 must add the entries now so that we get the correct size for
739 the .dynamic section. The DT_DEBUG entry is filled in by the
740 dynamic linker and used by the debugger. */
743 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
747 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
752 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
753 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
754 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
758 if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
759 || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
760 || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
761 sizeof (Elf32_External_Rela)))
766 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
771 /* If we are generating a shared library, we generate a section
772 symbol for each output section. These are local symbols, which
773 means that they must come first in the dynamic symbol table.
774 That means we must increment the dynamic symbol index of every
775 other dynamic symbol. */
780 c = bfd_count_sections (output_bfd);
781 elf_link_hash_traverse (elf_hash_table (info),
782 elf32_sparc_adjust_dynindx,
784 elf_hash_table (info)->dynsymcount += c;
786 for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++)
788 elf_section_data (s)->dynindx = i;
789 /* These symbols will have no names, so we don't need to
790 fiddle with dynstr_index. */
797 /* Increment the index of a dynamic symbol by a given amount. Called
798 via elf_link_hash_traverse. */
801 elf32_sparc_adjust_dynindx (h, cparg)
802 struct elf_link_hash_entry *h;
805 int *cp = (int *) cparg;
807 if (h->dynindx != -1)
812 /* Relocate a SPARC ELF section. */
815 elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
816 contents, relocs, local_syms, local_sections)
818 struct bfd_link_info *info;
820 asection *input_section;
822 Elf_Internal_Rela *relocs;
823 Elf_Internal_Sym *local_syms;
824 asection **local_sections;
827 Elf_Internal_Shdr *symtab_hdr;
828 struct elf_link_hash_entry **sym_hashes;
829 bfd_vma *local_got_offsets;
833 Elf_Internal_Rela *rel;
834 Elf_Internal_Rela *relend;
836 dynobj = elf_hash_table (info)->dynobj;
837 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
838 sym_hashes = elf_sym_hashes (input_bfd);
839 local_got_offsets = elf_local_got_offsets (input_bfd);
846 relend = relocs + input_section->reloc_count;
847 for (; rel < relend; rel++)
850 reloc_howto_type *howto;
851 unsigned long r_symndx;
852 struct elf_link_hash_entry *h;
853 Elf_Internal_Sym *sym;
856 bfd_reloc_status_type r;
858 r_type = ELF32_R_TYPE (rel->r_info);
859 if (r_type < 0 || r_type >= (int) R_SPARC_max)
861 bfd_set_error (bfd_error_bad_value);
864 howto = elf_sparc_howto_table + r_type;
866 r_symndx = ELF32_R_SYM (rel->r_info);
868 if (info->relocateable)
870 /* This is a relocateable link. We don't have to change
871 anything, unless the reloc is against a section symbol,
872 in which case we have to adjust according to where the
873 section symbol winds up in the output section. */
874 if (r_symndx < symtab_hdr->sh_info)
876 sym = local_syms + r_symndx;
877 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
879 sec = local_sections[r_symndx];
880 rel->r_addend += sec->output_offset + sym->st_value;
887 /* This is a final link. */
891 if (r_symndx < symtab_hdr->sh_info)
893 sym = local_syms + r_symndx;
894 sec = local_sections[r_symndx];
895 relocation = (sec->output_section->vma
901 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
902 if (h->root.type == bfd_link_hash_defined
903 || h->root.type == bfd_link_hash_defweak)
905 sec = h->root.u.def.section;
906 if ((r_type == R_SPARC_WPLT30
907 && h->plt_offset != (bfd_vma) -1)
908 || ((r_type == R_SPARC_GOT10
909 || r_type == R_SPARC_GOT13
910 || r_type == R_SPARC_GOT22)
911 && elf_hash_table (info)->dynamic_sections_created
914 || (h->elf_link_hash_flags
915 & ELF_LINK_HASH_DEF_REGULAR) == 0))
917 && (input_section->flags & SEC_ALLOC) != 0
918 && (r_type == R_SPARC_8
919 || r_type == R_SPARC_16
920 || r_type == R_SPARC_32
921 || r_type == R_SPARC_DISP8
922 || r_type == R_SPARC_DISP16
923 || r_type == R_SPARC_DISP32
924 || r_type == R_SPARC_WDISP30
925 || r_type == R_SPARC_WDISP22
926 || r_type == R_SPARC_HI22
927 || r_type == R_SPARC_22
928 || r_type == R_SPARC_13
929 || r_type == R_SPARC_LO10
930 || r_type == R_SPARC_UA32
931 || ((r_type == R_SPARC_PC10
932 || r_type == R_SPARC_PC22)
933 && strcmp (h->root.root.string,
934 "_GLOBAL_OFFSET_TABLE_") != 0))))
936 /* In these cases, we don't need the relocation
937 value. We check specially because in some
938 obscure cases sec->output_section will be NULL. */
942 relocation = (h->root.u.def.value
943 + sec->output_section->vma
944 + sec->output_offset);
946 else if (h->root.type == bfd_link_hash_undefweak)
948 else if (info->shared && !info->symbolic)
952 if (! ((*info->callbacks->undefined_symbol)
953 (info, h->root.root.string, input_bfd,
954 input_section, rel->r_offset)))
965 /* Relocation is to the entry for this symbol in the global
969 sgot = bfd_get_section_by_name (dynobj, ".got");
970 BFD_ASSERT (sgot != NULL);
978 BFD_ASSERT (off != (bfd_vma) -1);
980 if (! elf_hash_table (info)->dynamic_sections_created
983 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
985 /* This is actually a static link, or it is a
986 -Bsymbolic link and the symbol is defined
987 locally. We must initialize this entry in the
988 global offset table. Since the offset must
989 always be a multiple of 4, we use the least
990 significant bit to record whether we have
991 initialized it already.
993 When doing a dynamic link, we create a .rela.got
994 relocation entry to initialize the value. This
995 is done in the finish_dynamic_symbol routine. */
1000 bfd_put_32 (output_bfd, relocation,
1001 sgot->contents + off);
1006 relocation = sgot->output_offset + off;
1012 BFD_ASSERT (local_got_offsets != NULL
1013 && local_got_offsets[r_symndx] != (bfd_vma) -1);
1015 off = local_got_offsets[r_symndx];
1017 /* The offset must always be a multiple of 4. We use
1018 the least significant bit to record whether we have
1019 already processed this entry. */
1024 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
1029 Elf_Internal_Rela outrel;
1031 /* We need to generate a R_SPARC_RELATIVE reloc
1032 for the dynamic linker. */
1033 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1034 BFD_ASSERT (srelgot != NULL);
1036 outrel.r_offset = (sgot->output_section->vma
1037 + sgot->output_offset
1039 outrel.r_info = ELF32_R_INFO (0, R_SPARC_RELATIVE);
1040 outrel.r_addend = 0;
1041 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1042 (((Elf32_External_Rela *)
1044 + srelgot->reloc_count));
1045 ++srelgot->reloc_count;
1048 local_got_offsets[r_symndx] |= 1;
1051 relocation = sgot->output_offset + off;
1056 case R_SPARC_WPLT30:
1057 /* Relocation is to the entry for this symbol in the
1058 procedure linkage table. */
1059 BFD_ASSERT (h != NULL);
1061 if (h->plt_offset == (bfd_vma) -1)
1063 /* We didn't make a PLT entry for this symbol. This
1064 happens when statically linking PIC code, or when
1065 using -Bsymbolic. */
1071 splt = bfd_get_section_by_name (dynobj, ".plt");
1072 BFD_ASSERT (splt != NULL);
1075 relocation = (splt->output_section->vma
1076 + splt->output_offset
1083 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1087 case R_SPARC_DISP16:
1088 case R_SPARC_DISP32:
1089 case R_SPARC_WDISP30:
1090 case R_SPARC_WDISP22:
1103 && (input_section->flags & SEC_ALLOC) != 0)
1105 Elf_Internal_Rela outrel;
1107 /* When generating a shared object, these relocations
1108 are copied into the output file to be resolved at run
1115 name = (bfd_elf_string_from_elf_section
1117 elf_elfheader (input_bfd)->e_shstrndx,
1118 elf_section_data (input_section)->rel_hdr.sh_name));
1122 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1123 && strcmp (bfd_get_section_name (input_bfd,
1127 sreloc = bfd_get_section_by_name (dynobj, name);
1128 BFD_ASSERT (sreloc != NULL);
1131 outrel.r_offset = (rel->r_offset
1132 + input_section->output_section->vma
1133 + input_section->output_offset);
1136 BFD_ASSERT (h->dynindx != -1);
1137 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1138 outrel.r_addend = rel->r_addend;
1142 if (r_type == R_SPARC_32)
1144 outrel.r_info = ELF32_R_INFO (0, R_SPARC_RELATIVE);
1145 outrel.r_addend = relocation + rel->r_addend;
1151 sym = local_syms + r_symndx;
1152 sec = local_sections[r_symndx];
1153 if (sec != NULL && bfd_is_abs_section (sec))
1155 else if (sec == NULL || sec->owner == NULL)
1157 bfd_set_error (bfd_error_bad_value);
1164 osec = sec->output_section;
1165 indx = elf_section_data (osec)->dynindx;
1170 outrel.r_info = ELF32_R_INFO (indx, r_type);
1171 outrel.r_addend = relocation + rel->r_addend;
1175 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1176 (((Elf32_External_Rela *)
1178 + sreloc->reloc_count));
1179 ++sreloc->reloc_count;
1181 /* This reloc will be computed at runtime, so there's no
1182 need to do anything now. */
1190 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1191 contents, rel->r_offset,
1192 relocation, rel->r_addend);
1194 if (r != bfd_reloc_ok)
1199 case bfd_reloc_outofrange:
1201 case bfd_reloc_overflow:
1206 name = h->root.root.string;
1209 name = bfd_elf_string_from_elf_section (input_bfd,
1210 symtab_hdr->sh_link,
1215 name = bfd_section_name (input_bfd, sec);
1217 if (! ((*info->callbacks->reloc_overflow)
1218 (info, name, howto->name, (bfd_vma) 0,
1219 input_bfd, input_section, rel->r_offset)))
1230 /* Finish up dynamic symbol handling. We set the contents of various
1231 dynamic sections here. */
1234 elf32_sparc_finish_dynamic_symbol (output_bfd, info, h, sym)
1236 struct bfd_link_info *info;
1237 struct elf_link_hash_entry *h;
1238 Elf_Internal_Sym *sym;
1242 dynobj = elf_hash_table (info)->dynobj;
1244 if (h->plt_offset != (bfd_vma) -1)
1248 Elf_Internal_Rela rela;
1250 /* This symbol has an entry in the procedure linkage table. Set
1253 BFD_ASSERT (h->dynindx != -1);
1255 splt = bfd_get_section_by_name (dynobj, ".plt");
1256 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1257 BFD_ASSERT (splt != NULL && srela != NULL);
1259 /* Fill in the entry in the procedure linkage table. */
1260 bfd_put_32 (output_bfd,
1261 PLT_ENTRY_WORD0 + h->plt_offset,
1262 splt->contents + h->plt_offset);
1263 bfd_put_32 (output_bfd,
1265 + (((- (h->plt_offset + 4)) >> 2) & 0x3fffff)),
1266 splt->contents + h->plt_offset + 4);
1267 bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
1268 splt->contents + h->plt_offset + 8);
1270 /* Fill in the entry in the .rela.plt section. */
1271 rela.r_offset = (splt->output_section->vma
1272 + splt->output_offset
1274 rela.r_info = ELF32_R_INFO (h->dynindx, R_SPARC_JMP_SLOT);
1276 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1277 ((Elf32_External_Rela *) srela->contents
1278 + h->plt_offset / PLT_ENTRY_SIZE - 4));
1280 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1282 /* Mark the symbol as undefined, rather than as defined in
1283 the .plt section. Leave the value alone. */
1284 sym->st_shndx = SHN_UNDEF;
1288 if (h->got_offset != (bfd_vma) -1)
1292 Elf_Internal_Rela rela;
1294 /* This symbol has an entry in the global offset table. Set it
1297 BFD_ASSERT (h->dynindx != -1);
1299 sgot = bfd_get_section_by_name (dynobj, ".got");
1300 srela = bfd_get_section_by_name (dynobj, ".rela.got");
1301 BFD_ASSERT (sgot != NULL && srela != NULL);
1303 rela.r_offset = (sgot->output_section->vma
1304 + sgot->output_offset
1305 + (h->got_offset &~ 1));
1307 /* If this is a -Bsymbolic link, and the symbol is defined
1308 locally, we just want to emit a RELATIVE reloc. The entry in
1309 the global offset table will already have been initialized in
1310 the relocate_section function. */
1313 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1314 rela.r_info = ELF32_R_INFO (0, R_SPARC_RELATIVE);
1317 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got_offset);
1318 rela.r_info = ELF32_R_INFO (h->dynindx, R_SPARC_GLOB_DAT);
1322 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1323 ((Elf32_External_Rela *) srela->contents
1324 + srela->reloc_count));
1325 ++srela->reloc_count;
1328 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
1331 Elf_Internal_Rela rela;
1333 /* This symbols needs a copy reloc. Set it up. */
1335 BFD_ASSERT (h->dynindx != -1);
1337 s = bfd_get_section_by_name (h->root.u.def.section->owner,
1339 BFD_ASSERT (s != NULL);
1341 rela.r_offset = (h->root.u.def.value
1342 + h->root.u.def.section->output_section->vma
1343 + h->root.u.def.section->output_offset);
1344 rela.r_info = ELF32_R_INFO (h->dynindx, R_SPARC_COPY);
1346 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1347 ((Elf32_External_Rela *) s->contents
1352 /* Mark some specially defined symbols as absolute. */
1353 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
1354 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
1355 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1356 sym->st_shndx = SHN_ABS;
1361 /* Finish up the dynamic sections. */
1364 elf32_sparc_finish_dynamic_sections (output_bfd, info)
1366 struct bfd_link_info *info;
1372 dynobj = elf_hash_table (info)->dynobj;
1374 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
1376 if (elf_hash_table (info)->dynamic_sections_created)
1379 Elf32_External_Dyn *dyncon, *dynconend;
1381 splt = bfd_get_section_by_name (dynobj, ".plt");
1382 BFD_ASSERT (splt != NULL && sdyn != NULL);
1384 dyncon = (Elf32_External_Dyn *) sdyn->contents;
1385 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
1386 for (; dyncon < dynconend; dyncon++)
1388 Elf_Internal_Dyn dyn;
1392 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
1396 case DT_PLTGOT: name = ".plt"; size = false; break;
1397 case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;
1398 case DT_JMPREL: name = ".rela.plt"; size = false; break;
1399 default: name = NULL; size = false; break;
1406 s = bfd_get_section_by_name (output_bfd, name);
1412 dyn.d_un.d_ptr = s->vma;
1415 if (s->_cooked_size != 0)
1416 dyn.d_un.d_val = s->_cooked_size;
1418 dyn.d_un.d_val = s->_raw_size;
1421 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1425 /* Clear the first four entries in the procedure linkage table,
1426 and put a nop in the last four bytes. */
1427 if (splt->_raw_size > 0)
1429 memset (splt->contents, 0, 4 * PLT_ENTRY_SIZE);
1430 bfd_put_32 (output_bfd, SPARC_NOP,
1431 splt->contents + splt->_raw_size - 4);
1434 elf_section_data (splt->output_section)->this_hdr.sh_entsize =
1438 /* Set the first entry in the global offset table to the address of
1439 the dynamic section. */
1440 sgot = bfd_get_section_by_name (dynobj, ".got");
1441 BFD_ASSERT (sgot != NULL);
1442 if (sgot->_raw_size > 0)
1445 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
1447 bfd_put_32 (output_bfd,
1448 sdyn->output_section->vma + sdyn->output_offset,
1452 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
1458 Elf_Internal_Sym sym;
1460 /* Set up the section symbols for the output sections. */
1462 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
1463 BFD_ASSERT (sdynsym != NULL);
1467 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
1470 for (s = output_bfd->sections; s != NULL; s = s->next)
1474 sym.st_value = s->vma;
1476 indx = elf_section_data (s)->this_idx;
1477 BFD_ASSERT (indx > 0);
1478 sym.st_shndx = indx;
1480 bfd_elf32_swap_symbol_out (output_bfd, &sym,
1481 (PTR) (((Elf32_External_Sym *)
1483 + elf_section_data (s)->dynindx));
1486 /* Set the sh_info field of the output .dynsym section to the
1487 index of the first global symbol. */
1488 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
1489 bfd_count_sections (output_bfd) + 1;
1494 /* start-sanitize-v8plus */
1496 /* Function to set e_flags. */
1499 elf32_sparc_set_private_flags (abfd, flags)
1503 /* Once the flags have been set, you (apparently) can't change them. */
1504 BFD_ASSERT (!elf_flags_init (abfd)
1505 || elf_elfheader (abfd)->e_flags == flags);
1507 elf_elfheader (abfd)->e_flags = flags;
1508 elf_flags_init (abfd) = true;
1512 /* Copy backend specific data from one object module to another. */
1515 elf32_sparc_copy_private_bfd_data (ibfd, obfd)
1519 /* This function is selected based on the input vector. We only
1520 want to copy information over if the output BFD also uses Elf
1522 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1525 /* Once the flags have been set, you (apparently) can't change them. */
1526 BFD_ASSERT (!elf_flags_init (obfd)
1527 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
1529 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
1530 elf_flags_init (obfd) = true;
1534 /* Merge backend specific data from an object file to the output
1535 object file when linking. */
1538 elf32_sparc_merge_private_bfd_data (ibfd, obfd)
1546 /* This function is selected based on the input vector. We only
1547 want to copy information over if the output BFD also uses Elf
1549 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1554 /* If the output machine is normal sparc, we can't allow v9 input files. */
1555 if (bfd_get_mach (obfd) == bfd_mach_sparc
1556 && (bfd_get_mach (ibfd) == bfd_mach_sparc_v8plus
1557 || bfd_get_mach (ibfd) == bfd_mach_sparc_v8plusa))
1560 (*_bfd_error_handler)
1561 ("%s: compiled for a v8plus system and target is v8",
1562 bfd_get_filename (ibfd));
1564 /* If the output machine is v9, we can't allow v9+vis input files. */
1565 if (bfd_get_mach (obfd) == bfd_mach_sparc_v8plus
1566 && bfd_get_mach (ibfd) == bfd_mach_sparc_v8plusa)
1569 (*_bfd_error_handler)
1570 ("%s: compiled for a v8plusa system and target is v8plus",
1571 bfd_get_filename (ibfd));
1574 new_flags = elf_elfheader (ibfd)->e_flags;
1575 old_flags = elf_elfheader (obfd)->e_flags;
1576 if (!elf_flags_init (obfd)) /* First call, no flags set */
1578 elf_flags_init (obfd) = true;
1579 elf_elfheader (obfd)->e_flags = new_flags;
1581 else if (new_flags == old_flags) /* Compatible flags are ok */
1583 else /* Potentially incompatible flags */
1585 new_flags &= ~ (EF_SPARC_32PLUS | EF_SPARC_SUN_US1);
1586 old_flags &= ~ (EF_SPARC_32PLUS | EF_SPARC_SUN_US1);
1588 /* Warn about any other mismatches */
1589 if (new_flags != old_flags)
1592 (*_bfd_error_handler)
1593 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1594 bfd_get_filename (ibfd), (long) new_flags, (long) old_flags);
1600 bfd_set_error (bfd_error_bad_value);
1607 /* Set the right machine number. */
1610 elf32_sparc_object_p (abfd)
1613 if (elf_elfheader (abfd)->e_machine == EM_SPARC32PLUS)
1614 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc_v8plus);
1616 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc);
1619 /* The final processing done just before writing out the object file.
1620 We need to set the e_machine field appropriately. */
1623 elf32_sparc_final_write_processing (abfd, linker)
1627 if (bfd_get_mach (abfd) == bfd_mach_sparc_v8plus)
1629 elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS;
1630 #if 0 /* FIXME: Not sure how to handle EF_SPARC_32PLUS_US1 */
1631 elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK;
1633 elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS;
1636 /* end-sanitize-v8plus */
1638 #define TARGET_BIG_SYM bfd_elf32_sparc_vec
1639 #define TARGET_BIG_NAME "elf32-sparc"
1640 #define ELF_ARCH bfd_arch_sparc
1641 #define ELF_MACHINE_CODE EM_SPARC
1642 /* start-sanitize-v8plus */
1643 #define ELF_MACHINE_ALT1 EM_SPARC32PLUS
1644 /* end-sanitize-v8plus */
1645 #define ELF_MAXPAGESIZE 0x10000
1646 #define elf_backend_create_dynamic_sections \
1647 _bfd_elf_create_dynamic_sections
1648 #define elf_backend_check_relocs elf32_sparc_check_relocs
1649 #define elf_backend_adjust_dynamic_symbol \
1650 elf32_sparc_adjust_dynamic_symbol
1651 #define elf_backend_size_dynamic_sections \
1652 elf32_sparc_size_dynamic_sections
1653 #define elf_backend_relocate_section elf32_sparc_relocate_section
1654 #define elf_backend_finish_dynamic_symbol \
1655 elf32_sparc_finish_dynamic_symbol
1656 #define elf_backend_finish_dynamic_sections \
1657 elf32_sparc_finish_dynamic_sections
1658 /* start-sanitize-v8plus */
1659 #define bfd_elf32_bfd_set_private_flags elf32_sparc_set_private_flags
1660 #define bfd_elf32_bfd_copy_private_bfd_data \
1661 elf32_sparc_copy_private_bfd_data
1662 #define bfd_elf32_bfd_merge_private_bfd_data \
1663 elf32_sparc_merge_private_bfd_data
1664 #define elf_backend_object_p elf32_sparc_object_p
1665 #define elf_backend_final_write_processing \
1666 elf32_sparc_final_write_processing
1667 /* end-sanitize-v8plus */
1668 #define elf_backend_want_got_plt 0
1669 #define elf_backend_plt_readonly 0
1670 #define elf_backend_want_plt_sym 1
1672 #include "elf32-target.h"