merge from gcc
[binutils.git] / bfd / elf32-sparc.c
blob031b3034a8b60ce3200d47d840619d15c8c7843d
1 /* SPARC-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "bfdlink.h"
24 #include "libbfd.h"
25 #include "elf-bfd.h"
26 #include "elf/sparc.h"
27 #include "opcode/sparc.h"
28 #include "elfxx-sparc.h"
30 /* Support for core dump NOTE sections. */
32 static bfd_boolean
33 elf32_sparc_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
35 switch (note->descsz)
37 default:
38 return FALSE;
40 case 260: /* Solaris prpsinfo_t. */
41 elf_tdata (abfd)->core_program
42 = _bfd_elfcore_strndup (abfd, note->descdata + 84, 16);
43 elf_tdata (abfd)->core_command
44 = _bfd_elfcore_strndup (abfd, note->descdata + 100, 80);
45 break;
47 case 336: /* Solaris psinfo_t. */
48 elf_tdata (abfd)->core_program
49 = _bfd_elfcore_strndup (abfd, note->descdata + 88, 16);
50 elf_tdata (abfd)->core_command
51 = _bfd_elfcore_strndup (abfd, note->descdata + 104, 80);
52 break;
55 return TRUE;
58 /* Functions for dealing with the e_flags field.
60 We don't define set_private_flags or copy_private_bfd_data because
61 the only currently defined values are based on the bfd mach number,
62 so we use the latter instead and defer setting e_flags until the
63 file is written out. */
65 /* Merge backend specific data from an object file to the output
66 object file when linking. */
68 static bfd_boolean
69 elf32_sparc_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
71 bfd_boolean error;
72 unsigned long ibfd_mach;
73 /* FIXME: This should not be static. */
74 static unsigned long previous_ibfd_e_flags = (unsigned long) -1;
76 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
77 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
78 return TRUE;
80 error = FALSE;
82 ibfd_mach = bfd_get_mach (ibfd);
83 if (bfd_mach_sparc_64bit_p (ibfd_mach))
85 error = TRUE;
86 (*_bfd_error_handler)
87 (_("%B: compiled for a 64 bit system and target is 32 bit"), ibfd);
89 else if ((ibfd->flags & DYNAMIC) == 0)
91 if (bfd_get_mach (obfd) < ibfd_mach)
92 bfd_set_arch_mach (obfd, bfd_arch_sparc, ibfd_mach);
95 if (((elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA)
96 != previous_ibfd_e_flags)
97 && previous_ibfd_e_flags != (unsigned long) -1)
99 (*_bfd_error_handler)
100 (_("%B: linking little endian files with big endian files"), ibfd);
101 error = TRUE;
103 previous_ibfd_e_flags = elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA;
105 if (error)
107 bfd_set_error (bfd_error_bad_value);
108 return FALSE;
111 return TRUE;
114 /* The final processing done just before writing out the object file.
115 We need to set the e_machine field appropriately. */
117 static void
118 elf32_sparc_final_write_processing (bfd *abfd,
119 bfd_boolean linker ATTRIBUTE_UNUSED)
121 switch (bfd_get_mach (abfd))
123 case bfd_mach_sparc :
124 case bfd_mach_sparc_sparclet :
125 case bfd_mach_sparc_sparclite :
126 break; /* nothing to do */
127 case bfd_mach_sparc_v8plus :
128 elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS;
129 elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK;
130 elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS;
131 break;
132 case bfd_mach_sparc_v8plusa :
133 elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS;
134 elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK;
135 elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS | EF_SPARC_SUN_US1;
136 break;
137 case bfd_mach_sparc_v8plusb :
138 elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS;
139 elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK;
140 elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS | EF_SPARC_SUN_US1
141 | EF_SPARC_SUN_US3;
142 break;
143 case bfd_mach_sparc_sparclite_le :
144 elf_elfheader (abfd)->e_flags |= EF_SPARC_LEDATA;
145 break;
146 default :
147 abort ();
148 break;
152 static enum elf_reloc_type_class
153 elf32_sparc_reloc_type_class (const Elf_Internal_Rela *rela)
155 switch ((int) ELF32_R_TYPE (rela->r_info))
157 case R_SPARC_RELATIVE:
158 return reloc_class_relative;
159 case R_SPARC_JMP_SLOT:
160 return reloc_class_plt;
161 case R_SPARC_COPY:
162 return reloc_class_copy;
163 default:
164 return reloc_class_normal;
168 #define TARGET_BIG_SYM bfd_elf32_sparc_vec
169 #define TARGET_BIG_NAME "elf32-sparc"
170 #define ELF_ARCH bfd_arch_sparc
171 #define ELF_MACHINE_CODE EM_SPARC
172 #define ELF_MACHINE_ALT1 EM_SPARC32PLUS
173 #define ELF_MAXPAGESIZE 0x10000
175 #define bfd_elf32_bfd_merge_private_bfd_data \
176 elf32_sparc_merge_private_bfd_data
177 #define elf_backend_final_write_processing \
178 elf32_sparc_final_write_processing
179 #define elf_backend_grok_psinfo elf32_sparc_grok_psinfo
180 #define elf_backend_reloc_type_class elf32_sparc_reloc_type_class
182 #define elf_info_to_howto _bfd_sparc_elf_info_to_howto
183 #define bfd_elf32_bfd_reloc_type_lookup _bfd_sparc_elf_reloc_type_lookup
184 #define bfd_elf32_bfd_link_hash_table_create \
185 _bfd_sparc_elf_link_hash_table_create
186 #define bfd_elf32_bfd_relax_section _bfd_sparc_elf_relax_section
187 #define bfd_elf32_new_section_hook _bfd_sparc_elf_new_section_hook
188 #define elf_backend_copy_indirect_symbol \
189 _bfd_sparc_elf_copy_indirect_symbol
190 #define elf_backend_create_dynamic_sections \
191 _bfd_sparc_elf_create_dynamic_sections
192 #define elf_backend_check_relocs _bfd_sparc_elf_check_relocs
193 #define elf_backend_adjust_dynamic_symbol \
194 _bfd_sparc_elf_adjust_dynamic_symbol
195 #define elf_backend_omit_section_dynsym _bfd_sparc_elf_omit_section_dynsym
196 #define elf_backend_size_dynamic_sections \
197 _bfd_sparc_elf_size_dynamic_sections
198 #define elf_backend_relocate_section _bfd_sparc_elf_relocate_section
199 #define elf_backend_finish_dynamic_symbol \
200 _bfd_sparc_elf_finish_dynamic_symbol
201 #define elf_backend_finish_dynamic_sections \
202 _bfd_sparc_elf_finish_dynamic_sections
203 #define bfd_elf32_mkobject _bfd_sparc_elf_mkobject
204 #define elf_backend_object_p _bfd_sparc_elf_object_p
205 #define elf_backend_gc_mark_hook _bfd_sparc_elf_gc_mark_hook
206 #define elf_backend_gc_sweep_hook _bfd_sparc_elf_gc_sweep_hook
207 #define elf_backend_plt_sym_val _bfd_sparc_elf_plt_sym_val
209 #define elf_backend_can_gc_sections 1
210 #define elf_backend_can_refcount 1
211 #define elf_backend_want_got_plt 0
212 #define elf_backend_plt_readonly 0
213 #define elf_backend_want_plt_sym 1
214 #define elf_backend_got_header_size 4
215 #define elf_backend_rela_normal 1
217 #include "elf32-target.h"